Asterisk - The Open Source Telephony Project  21.4.1
Macros | Functions | Variables
res/ari/config.c File Reference

Config framework stuffz for ARI. More...

#include "asterisk.h"
#include "asterisk/config_options.h"
#include "asterisk/http_websocket.h"
#include "asterisk/app.h"
#include "asterisk/channel.h"
#include "internal.h"

Go to the source code of this file.

Macros

#define CONF_FILENAME   "ari.conf"
 
#define MAX_VARS   128
 

Functions

static AO2_GLOBAL_OBJ_STATIC (confs)
 Locking container for safe configuration access.
 
void ast_ari_config_destroy (void)
 Destroy the ARI configuration.
 
struct ast_ari_confast_ari_config_get (void)
 Get the current ARI configuration. More...
 
int ast_ari_config_init (void)
 Initialize the ARI configuration.
 
int ast_ari_config_reload (void)
 Reload the ARI configuration.
 
struct ast_ari_conf_userast_ari_config_validate_user (const char *username, const char *password)
 Validated a user's credentials. More...
 
static int channelvars_handler (const struct aco_option *opt, struct ast_variable *var, void *obj)
 
static void * conf_alloc (void)
 Allocate an ast_ari_conf for config parsing.
 
static void conf_destructor (void *obj)
 ast_ari_conf destructor.
 
static void conf_general_dtor (void *obj)
 
 CONFIG_INFO_STANDARD (cfg_info, confs, conf_alloc,.files=ACO_FILES(&conf_file))
 
static int encoding_format_handler (const struct aco_option *opt, struct ast_variable *var, void *obj)
 Encoding format handler converts from boolean to enum.
 
static int password_format_handler (const struct aco_option *opt, struct ast_variable *var, void *obj)
 Parses the ast_ari_password_format enum from a config file.
 
static int process_config (int reload)
 Load (or reload) configuration.
 
static void * user_alloc (const char *cat)
 Allocate an ast_ari_conf_user for config parsing.
 
static void user_dtor (void *obj)
 Destructor for ast_ari_conf_user.
 
static void * user_find (struct ao2_container *tmp_container, const char *cat)
 aco_type item_find function
 
static int user_sort_cmp (const void *obj_left, const void *obj_right, int flags)
 Sorting function for use with red/black tree.
 
static int validate_user_cb (void *obj, void *arg, int flags)
 Callback to validate a user object.
 

Variables

static struct aco_file conf_file
 The conf file that's processed for the module.
 
static struct aco_type general_option
 Mapping of the ARI conf struct's globals to the general context in the config file.
 
static struct aco_typegeneral_options [] = ACO_TYPES(&general_option)
 
static struct aco_typeglobal_user [] = ACO_TYPES(&user_option)
 
static struct aco_type user_option
 

Detailed Description

Config framework stuffz for ARI.

Author
David M. Lee, II dlee@.nosp@m.digi.nosp@m.um.co.nosp@m.m

Definition in file res/ari/config.c.

Function Documentation

struct ast_ari_conf* ast_ari_config_get ( void  )

Get the current ARI configuration.

This is an immutable object, so don't modify it. It is AO2 managed, so ao2_cleanup() when you're done with it.

Returns
ARI configuration object.
Return values
NULLon error.

Definition at line 227 of file res/ari/config.c.

References ao2_global_obj_ref.

Referenced by ast_ari_config_validate_user(), ast_ari_json_format(), ast_ari_websocket_session_create(), is_enabled(), and process_config().

228 {
229  struct ast_ari_conf *res = ao2_global_obj_ref(confs);
230  if (!res) {
231  ast_log(LOG_ERROR,
232  "Error obtaining config from " CONF_FILENAME "\n");
233  }
234  return res;
235 }
All configuration options for ARI.
Definition: internal.h:54
#define ao2_global_obj_ref(holder)
Get a reference to the object stored in the global holder.
Definition: astobj2.h:918
struct ast_ari_conf_user* ast_ari_config_validate_user ( const char *  username,
const char *  password 
)

Validated a user's credentials.

Parameters
usernameName of the user.
passwordUser's password.
Returns
User object.
Return values
NULLif username or password is invalid.

Definition at line 237 of file res/ari/config.c.

References ao2_ref, ARI_PASSWORD_FORMAT_CRYPT, ARI_PASSWORD_FORMAT_PLAIN, ast_ari_config_get(), ast_crypt_validate(), OBJ_SEARCH_KEY, and RAII_VAR.

Referenced by authenticate_api_key(), and authenticate_user().

239 {
240  RAII_VAR(struct ast_ari_conf *, conf, NULL, ao2_cleanup);
241  RAII_VAR(struct ast_ari_conf_user *, user, NULL, ao2_cleanup);
242  int is_valid = 0;
243 
245  if (!conf) {
246  return NULL;
247  }
248 
249  user = ao2_find(conf->users, username, OBJ_SEARCH_KEY);
250  if (!user) {
251  return NULL;
252  }
253 
254  if (ast_strlen_zero(user->password)) {
255  ast_log(LOG_WARNING,
256  "User '%s' missing password; authentication failed\n",
257  user->username);
258  return NULL;
259  }
260 
261  switch (user->password_format) {
263  is_valid = strcmp(password, user->password) == 0;
264  break;
266  is_valid = ast_crypt_validate(password, user->password);
267  break;
268  }
269 
270  if (!is_valid) {
271  return NULL;
272  }
273 
274  ao2_ref(user, +1);
275  return user;
276 }
struct ast_ari_conf * ast_ari_config_get(void)
Get the current ARI configuration.
The arg parameter is a search key, but is not an object.
Definition: astobj2.h:1101
All configuration options for ARI.
Definition: internal.h:54
Plaintext password.
Definition: internal.h:83
All configuration options for http media cache.
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
Per-user configuration options.
Definition: internal.h:96
structure to hold users read from users.conf
int ast_crypt_validate(const char *key, const char *expected)
Asterisk wrapper around crypt(3) for validating passwords.
Definition: crypt.c:136
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:941