Asterisk - The Open Source Telephony Project  18.5.0
Functions | Variables
config_auth.c File Reference
#include "asterisk.h"
#include <pjsip.h>
#include <pjlib.h>
#include "asterisk/res_pjsip.h"
#include "asterisk/logger.h"
#include "asterisk/sorcery.h"
#include "asterisk/cli.h"
#include "include/res_pjsip_private.h"
#include "asterisk/res_pjsip_cli.h"
Include dependency graph for config_auth.c:

Go to the source code of this file.

Functions

static int ami_show_auths (struct mansession *s, const struct message *m)
 
const char * ast_sip_auth_type_to_str (enum ast_sip_auth_type type)
 Converts the given auth type to a string. More...
 
int ast_sip_destroy_sorcery_auth (void)
 
int ast_sip_for_each_auth (const struct ast_sip_auth_vector *vector, ao2_callback_fn on_auth, void *arg)
 For every auth in the array call the given 'on_auth' handler. More...
 
int ast_sip_format_auths_ami (const struct ast_sip_auth_vector *auths, struct ast_sip_ami *ami)
 Format auth details for AMI. More...
 
int ast_sip_initialize_sorcery_auth (void)
 Initialize sorcery with auth support. More...
 
static void * auth_alloc (const char *name)
 
static int auth_apply (const struct ast_sorcery *sorcery, void *obj)
 
static void auth_destroy (void *obj)
 
static int auth_type_handler (const struct aco_option *opt, struct ast_variable *var, void *obj)
 
static int auth_type_to_str (const void *obj, const intptr_t *args, char **buf)
 
static struct ao2_containercli_get_auths (void)
 
static struct ao2_containercli_get_container (const char *regex)
 
static int cli_iterator (void *container, ao2_callback_fn callback, void *args)
 
static int cli_print_body (void *obj, void *arg, int flags)
 
static int cli_print_header (void *obj, void *arg, int flags)
 
static void * cli_retrieve_by_id (const char *id)
 
static int format_ami_auth_handler (void *obj, void *arg, int flags)
 
static int format_ami_authlist_handler (void *obj, void *arg, int flags)
 
static int format_ami_endpoint_auth (const struct ast_sip_endpoint *endpoint, struct ast_sip_ami *ami)
 
static int sip_auth_to_ami (const struct ast_sip_auth *auth, struct ast_str **buf)
 

Variables

static const char * auth_types_map []
 
static struct ast_cli_entry cli_commands []
 
static struct ast_sip_cli_formatter_entrycli_formatter
 
static struct ast_sip_endpoint_formatter endpoint_auth_formatter
 

Function Documentation

◆ ami_show_auths()

static int ami_show_auths ( struct mansession s,
const struct message m 
)
static

Definition at line 247 of file config_auth.c.

References ao2_callback, ao2_container_count(), ao2_ref, astman_get_header(), astman_send_error(), astman_send_list_complete_end(), astman_send_list_complete_start(), astman_send_listack(), cli_get_auths(), ast_sip_ami::count, format_ami_authlist_handler(), ast_sip_ami::m, OBJ_NODATA, and ast_sip_ami::s.

Referenced by ast_sip_initialize_sorcery_auth().

248 {
249  struct ast_sip_ami ami = { .s = s, .m = m, .action_id = astman_get_header(m, "ActionID"), };
250  struct ao2_container *auths;
251 
252  auths = cli_get_auths();
253  if (!auths) {
254  astman_send_error(s, m, "Could not get Auths\n");
255  return 0;
256  }
257 
258  if (!ao2_container_count(auths)) {
259  astman_send_error(s, m, "No Auths found\n");
260  ao2_ref(auths, -1);
261  return 0;
262  }
263 
264  astman_send_listack(s, m, "A listing of Auths follows, presented as AuthList events",
265  "start");
266 
268 
269  astman_send_list_complete_start(s, m, "AuthListComplete", ami.count);
271 
272  ao2_ref(auths, -1);
273 
274  return 0;
275 }
int ao2_container_count(struct ao2_container *c)
Returns the number of elements in a container.
const struct message * m
Definition: res_pjsip.h:2741
void astman_send_list_complete_start(struct mansession *s, const struct message *m, const char *event_name, int count)
Start the list complete event.
Definition: manager.c:3237
#define ao2_callback(c, flags, cb_fn, arg)
Definition: astobj2.h:1716
AMI variable container.
Definition: res_pjsip.h:2737
static int format_ami_authlist_handler(void *obj, void *arg, int flags)
Definition: config_auth.c:226
const char * astman_get_header(const struct message *m, char *var)
Get header from mananger transaction.
Definition: manager.c:2820
void astman_send_list_complete_end(struct mansession *s)
End the list complete event.
Definition: manager.c:3245
#define ao2_ref(o, delta)
Definition: astobj2.h:464
struct mansession * s
Definition: res_pjsip.h:2739
static struct ao2_container * cli_get_auths(void)
Definition: config_auth.c:216
Generic container type.
void astman_send_error(struct mansession *s, const struct message *m, char *error)
Send error in manager transaction.
Definition: manager.c:3159
void astman_send_listack(struct mansession *s, const struct message *m, char *msg, char *listflag)
Send ack in manager transaction to begin a list.
Definition: manager.c:3201

◆ ast_sip_auth_type_to_str()

const char* ast_sip_auth_type_to_str ( enum ast_sip_auth_type  type)

Converts the given auth type to a string.

Parameters
typethe auth type to convert
Return values
astring representative of the auth type

Definition at line 80 of file config_auth.c.

References ARRAY_IN_BOUNDS, auth_types_map, and type.

Referenced by auth_type_to_str().

81 {
83  auth_types_map[type] : "";
84 }
static const char type[]
Definition: chan_ooh323.c:109
#define ARRAY_IN_BOUNDS(v, a)
Checks to see if value is within the bounds of the given array.
Definition: utils.h:658
static const char * auth_types_map[]
Definition: config_auth.c:74

◆ ast_sip_destroy_sorcery_auth()

int ast_sip_destroy_sorcery_auth ( void  )

Definition at line 426 of file config_auth.c.

References ARRAY_LEN, ast_cli_unregister_multiple(), ast_manager_unregister(), ast_sip_unregister_cli_formatter(), and ast_sip_unregister_endpoint_formatter().

Referenced by ast_res_pjsip_destroy_configuration().

427 {
431 
432  ast_manager_unregister("PJSIPShowAuths");
433 
434  return 0;
435 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
Definition: clicompat.c:30
void ast_sip_unregister_endpoint_formatter(struct ast_sip_endpoint_formatter *obj)
Unregister an endpoint formatter.
Definition: res_pjsip.c:3685
int ast_sip_unregister_cli_formatter(struct ast_sip_cli_formatter_entry *formatter)
Unregisters a CLI formatter.
Definition: pjsip_cli.c:326
static struct ast_sip_endpoint_formatter endpoint_auth_formatter
Definition: config_auth.c:212
int ast_manager_unregister(const char *action)
Unregister a registered manager command.
Definition: manager.c:7258
static struct ast_sip_cli_formatter_entry * cli_formatter
Definition: config_auth.c:367
static struct ast_cli_entry cli_commands[]
Definition: config_auth.c:350

◆ ast_sip_for_each_auth()

int ast_sip_for_each_auth ( const struct ast_sip_auth_vector array,
ao2_callback_fn  on_auth,
void *  arg 
)

For every auth in the array call the given 'on_auth' handler.

Parameters
arrayan array of auths
on_authcallback for each auth
arguser data passed to handler
Return values
0Success, non-zero on failure

Definition at line 135 of file config_auth.c.

References ao2_cleanup, ast_sip_get_sorcery(), ast_sorcery_retrieve_by_id(), AST_VECTOR_GET, AST_VECTOR_SIZE, and RAII_VAR.

Referenced by ast_sip_format_auths_ami(), and cli_iterator().

137 {
138  int i;
139 
140  if (!vector || !AST_VECTOR_SIZE(vector)) {
141  return 0;
142  }
143 
144  for (i = 0; i < AST_VECTOR_SIZE(vector); ++i) {
145  /* AST_VECTOR_GET is safe to use since the vector is immutable */
147  ast_sip_get_sorcery(), SIP_SORCERY_AUTH_TYPE,
148  AST_VECTOR_GET(vector,i)), ao2_cleanup);
149 
150  if (!auth) {
151  continue;
152  }
153 
154  if (on_auth(auth, arg, 0)) {
155  return -1;
156  }
157  }
158 
159  return 0;
160 }
void * ast_sorcery_retrieve_by_id(const struct ast_sorcery *sorcery, const char *type, const char *id)
Retrieve an object using its unique identifier.
Definition: sorcery.c:1853
#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:911
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
Definition: vector.h:682
struct ast_sorcery * ast_sip_get_sorcery(void)
Get a pointer to the SIP sorcery structure.
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
Definition: vector.h:611

◆ ast_sip_format_auths_ami()

int ast_sip_format_auths_ami ( const struct ast_sip_auth_vector auths,
struct ast_sip_ami ami 
)

Format auth details for AMI.

Parameters
authsan auth array
amiami variable container
Return values
0Success, non-zero on failure

Definition at line 195 of file config_auth.c.

References ast_sip_for_each_auth(), and format_ami_auth_handler().

Referenced by ami_outbound_registration_task(), and format_ami_endpoint_auth().

197 {
199 }
static int format_ami_auth_handler(void *obj, void *arg, int flags)
Definition: config_auth.c:168
int ast_sip_for_each_auth(const struct ast_sip_auth_vector *vector, ao2_callback_fn on_auth, void *arg)
For every auth in the array call the given &#39;on_auth&#39; handler.
Definition: config_auth.c:135

◆ ast_sip_initialize_sorcery_auth()

int ast_sip_initialize_sorcery_auth ( void  )

Initialize sorcery with auth support.

Definition at line 370 of file config_auth.c.

References ami_show_auths(), ao2_alloc, ARRAY_LEN, ast_cli_register_multiple, ast_log, ast_manager_register_xml, ast_sip_get_sorcery(), ast_sip_register_cli_formatter(), ast_sip_register_endpoint_formatter(), ast_sorcery_apply_default, ast_sorcery_object_field_register, ast_sorcery_object_field_register_custom, ast_sorcery_object_get_id(), ast_sorcery_object_register, auth_alloc(), auth_apply(), auth_type_handler(), auth_type_to_str(), cli_get_container(), cli_iterator(), cli_print_body(), cli_print_header(), cli_retrieve_by_id(), EVENT_FLAG_SYSTEM, FLDSET, ast_sip_cli_formatter_entry::get_container, ast_sip_cli_formatter_entry::get_id, ast_sip_cli_formatter_entry::iterate, LOG_ERROR, ast_sip_cli_formatter_entry::name, NULL, OPT_NOOP_T, OPT_STRINGFIELD_T, OPT_UINT_T, ast_sip_cli_formatter_entry::print_body, ast_sip_cli_formatter_entry::print_header, ast_sip_cli_formatter_entry::retrieve_by_id, sorcery, and STRFLDSET.

Referenced by ast_res_pjsip_initialize_configuration().

371 {
373 
374  ast_sorcery_apply_default(sorcery, SIP_SORCERY_AUTH_TYPE, "config", "pjsip.conf,criteria=type=auth");
375 
376  if (ast_sorcery_object_register(sorcery, SIP_SORCERY_AUTH_TYPE, auth_alloc, NULL, auth_apply)) {
377  return -1;
378  }
379 
380  ast_sorcery_object_field_register(sorcery, SIP_SORCERY_AUTH_TYPE, "type", "",
381  OPT_NOOP_T, 0, 0);
382  ast_sorcery_object_field_register(sorcery, SIP_SORCERY_AUTH_TYPE, "username",
383  "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_auth, auth_user));
384  ast_sorcery_object_field_register(sorcery, SIP_SORCERY_AUTH_TYPE, "password",
385  "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_auth, auth_pass));
386  ast_sorcery_object_field_register(sorcery, SIP_SORCERY_AUTH_TYPE, "refresh_token",
387  "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_auth, refresh_token));
388  ast_sorcery_object_field_register(sorcery, SIP_SORCERY_AUTH_TYPE, "oauth_clientid",
389  "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_auth, oauth_clientid));
390  ast_sorcery_object_field_register(sorcery, SIP_SORCERY_AUTH_TYPE, "oauth_secret",
391  "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_auth, oauth_secret));
392  ast_sorcery_object_field_register(sorcery, SIP_SORCERY_AUTH_TYPE, "md5_cred",
393  "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_auth, md5_creds));
394  ast_sorcery_object_field_register(sorcery, SIP_SORCERY_AUTH_TYPE, "realm",
395  "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_auth, realm));
396  ast_sorcery_object_field_register(sorcery, SIP_SORCERY_AUTH_TYPE, "nonce_lifetime",
397  "32", OPT_UINT_T, 0, FLDSET(struct ast_sip_auth, nonce_lifetime));
398  ast_sorcery_object_field_register_custom(sorcery, SIP_SORCERY_AUTH_TYPE, "auth_type",
399  "userpass", auth_type_handler, auth_type_to_str, NULL, 0, 0);
400 
402 
404  if (!cli_formatter) {
405  ast_log(LOG_ERROR, "Unable to allocate memory for cli formatter\n");
406  return -1;
407  }
408  cli_formatter->name = SIP_SORCERY_AUTH_TYPE;
415 
418 
420  return -1;
421  }
422 
423  return 0;
424 }
struct ao2_container *(* get_container)(const char *regex)
Definition: res_pjsip_cli.h:64
static int auth_type_to_str(const void *obj, const intptr_t *args, char **buf)
Definition: config_auth.c:86
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
Definition: res_pjsip_cli.h:52
static int cli_iterator(void *container, ao2_callback_fn callback, void *args)
Definition: config_auth.c:301
static int auth_type_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
Definition: config_auth.c:52
Full structure for sorcery.
Definition: sorcery.c:230
int(* iterate)(void *container, ao2_callback_fn callback, void *args)
Definition: res_pjsip_cli.h:66
Type for a default handler that should do nothing.
#define ast_cli_register_multiple(e, len)
Register multiple commands.
Definition: cli.h:265
static struct ao2_container * cli_get_container(const char *regex)
Definition: config_auth.c:277
#define NULL
Definition: resample.c:96
int ast_sip_register_cli_formatter(struct ast_sip_cli_formatter_entry *formatter)
Registers a CLI formatter.
Definition: pjsip_cli.c:310
static void * cli_retrieve_by_id(const char *id)
Definition: config_auth.c:306
void ast_sip_register_endpoint_formatter(struct ast_sip_endpoint_formatter *obj)
Register an endpoint formatter.
Definition: res_pjsip.c:3679
#define EVENT_FLAG_SYSTEM
Definition: manager.h:71
#define ast_log
Definition: astobj2.c:42
#define ast_sorcery_object_field_register_custom(sorcery, type, name, default_val, config_handler, sorcery_handler, multiple_handler, flags,...)
Register a field within an object with custom handlers.
Definition: sorcery.h:1005
#define FLDSET(type,...)
Convert a struct and list of fields to an argument list of field offsets.
Type for default option handler for unsigned integers.
const char * ast_sorcery_object_get_id(const void *object)
Get the unique identifier of a sorcery object.
Definition: sorcery.c:2312
void *(* retrieve_by_id)(const char *id)
Definition: res_pjsip_cli.h:68
#define ast_sorcery_object_register(sorcery, type, alloc, transform, apply)
Register an object type.
Definition: sorcery.h:838
static int cli_print_header(void *obj, void *arg, int flags)
Definition: config_auth.c:311
static void * auth_alloc(const char *name)
Definition: config_auth.c:36
static struct ast_sip_endpoint_formatter endpoint_auth_formatter
Definition: config_auth.c:212
#define LOG_ERROR
Definition: logger.h:285
#define ast_sorcery_apply_default(sorcery, type, name, data)
Definition: sorcery.h:477
#define ao2_alloc(data_size, destructor_fn)
Definition: astobj2.h:411
#define STRFLDSET(type,...)
Convert a struct and a list of stringfield fields to an argument list of field offsets.
static struct ast_sip_cli_formatter_entry * cli_formatter
Definition: config_auth.c:367
const char *(* get_id)(const void *obj)
Definition: res_pjsip_cli.h:70
#define ast_sorcery_object_field_register(sorcery, type, name, default_val, opt_type, flags,...)
Register a field within an object.
Definition: sorcery.h:955
static struct ast_cli_entry cli_commands[]
Definition: config_auth.c:350
static struct ast_sorcery * sorcery
struct ast_sorcery * ast_sip_get_sorcery(void)
Get a pointer to the SIP sorcery structure.
static int ami_show_auths(struct mansession *s, const struct message *m)
Definition: config_auth.c:247
Type for default option handler for stringfields.
ao2_callback_fn * print_header
Definition: res_pjsip_cli.h:60
#define ast_manager_register_xml(action, authority, func)
Register a manager callback using XML documentation to describe the manager.
Definition: manager.h:186
ao2_callback_fn * print_body
Definition: res_pjsip_cli.h:62
const char * name
Definition: res_pjsip_cli.h:58
static int cli_print_body(void *obj, void *arg, int flags)
Definition: config_auth.c:326
static int auth_apply(const struct ast_sorcery *sorcery, void *obj)
Definition: config_auth.c:93

◆ auth_alloc()

static void* auth_alloc ( const char *  name)
static

Definition at line 36 of file config_auth.c.

References ao2_cleanup, ast_sorcery_generic_alloc(), ast_string_field_init, auth_destroy(), and NULL.

Referenced by ast_sip_initialize_sorcery_auth().

37 {
38  struct ast_sip_auth *auth = ast_sorcery_generic_alloc(sizeof(*auth), auth_destroy);
39 
40  if (!auth) {
41  return NULL;
42  }
43 
44  if (ast_string_field_init(auth, 64)) {
45  ao2_cleanup(auth);
46  return NULL;
47  }
48 
49  return auth;
50 }
#define NULL
Definition: resample.c:96
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
Definition: stringfields.h:353
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
void * ast_sorcery_generic_alloc(size_t size, ao2_destructor_fn destructor)
Allocate a generic sorcery capable object.
Definition: sorcery.c:1728
static void auth_destroy(void *obj)
Definition: config_auth.c:30

◆ auth_apply()

static int auth_apply ( const struct ast_sorcery sorcery,
void *  obj 
)
static

Definition at line 93 of file config_auth.c.

References ast_log, AST_SIP_AUTH_TYPE_ARTIFICIAL, AST_SIP_AUTH_TYPE_GOOGLE_OAUTH, AST_SIP_AUTH_TYPE_MD5, AST_SIP_AUTH_TYPE_USER_PASS, ast_sorcery_object_get_id(), ast_strlen_zero, ast_sip_auth::auth_user, LOG_ERROR, ast_sip_auth::md5_creds, ast_sip_auth::oauth_clientid, ast_sip_auth::oauth_secret, ast_sip_auth::refresh_token, and ast_sip_auth::type.

Referenced by ast_sip_initialize_sorcery_auth().

94 {
95  struct ast_sip_auth *auth = obj;
96  int res = 0;
97 
98  if (ast_strlen_zero(auth->auth_user)) {
99  ast_log(LOG_ERROR, "No authentication username for auth '%s'\n",
101  return -1;
102  }
103 
104  switch (auth->type) {
106  if (ast_strlen_zero(auth->md5_creds)) {
107  ast_log(LOG_ERROR, "'md5' authentication specified but no md5_cred "
108  "specified for auth '%s'\n", ast_sorcery_object_get_id(auth));
109  res = -1;
110  } else if (strlen(auth->md5_creds) != PJSIP_MD5STRLEN) {
111  ast_log(LOG_ERROR, "'md5' authentication requires digest of size '%d', but "
112  "digest is '%d' in size for auth '%s'\n", PJSIP_MD5STRLEN, (int)strlen(auth->md5_creds),
114  res = -1;
115  }
116  break;
118  if (ast_strlen_zero(auth->refresh_token)
120  || ast_strlen_zero(auth->oauth_secret)) {
121  ast_log(LOG_ERROR, "'google_oauth' authentication specified but refresh_token,"
122  " oauth_clientid, or oauth_secret not specified for auth '%s'\n",
124  res = -1;
125  }
126  break;
129  break;
130  }
131 
132  return res;
133 }
const ast_string_field oauth_secret
Definition: res_pjsip.h:460
const ast_string_field md5_creds
Definition: res_pjsip.h:454
const ast_string_field oauth_clientid
Definition: res_pjsip.h:458
#define ast_strlen_zero(foo)
Definition: strings.h:52
#define ast_log
Definition: astobj2.c:42
const char * ast_sorcery_object_get_id(const void *object)
Get the unique identifier of a sorcery object.
Definition: sorcery.c:2312
#define LOG_ERROR
Definition: logger.h:285
enum ast_sip_auth_type type
Definition: res_pjsip.h:464
const ast_string_field refresh_token
Definition: res_pjsip.h:456
const ast_string_field auth_user
Definition: res_pjsip.h:450

◆ auth_destroy()

static void auth_destroy ( void *  obj)
static

Definition at line 30 of file config_auth.c.

References ast_string_field_free_memory.

Referenced by auth_alloc().

31 {
32  struct ast_sip_auth *auth = obj;
34 }
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
Definition: stringfields.h:368

◆ auth_type_handler()

static int auth_type_handler ( const struct aco_option opt,
struct ast_variable var,
void *  obj 
)
static

Definition at line 52 of file config_auth.c.

References ast_log, AST_SIP_AUTH_TYPE_GOOGLE_OAUTH, AST_SIP_AUTH_TYPE_MD5, AST_SIP_AUTH_TYPE_USER_PASS, LOG_WARNING, ast_variable::name, ast_sip_auth::type, and ast_variable::value.

Referenced by ast_sip_initialize_sorcery_auth().

53 {
54  struct ast_sip_auth *auth = obj;
55  if (!strcasecmp(var->value, "userpass")) {
57  } else if (!strcasecmp(var->value, "md5")) {
59  } else if (!strcasecmp(var->value, "google_oauth")) {
60 #ifdef HAVE_PJSIP_OAUTH_AUTHENTICATION
62 #else
63  ast_log(LOG_WARNING, "OAuth support is not available in the version of PJSIP in use\n");
64  return -1;
65 #endif
66  } else {
67  ast_log(LOG_WARNING, "Unknown authentication storage type '%s' specified for %s\n",
68  var->value, var->name);
69  return -1;
70  }
71  return 0;
72 }
#define LOG_WARNING
Definition: logger.h:274
#define ast_log
Definition: astobj2.c:42
enum ast_sip_auth_type type
Definition: res_pjsip.h:464

◆ auth_type_to_str()

static int auth_type_to_str ( const void *  obj,
const intptr_t *  args,
char **  buf 
)
static

Definition at line 86 of file config_auth.c.

References ast_sip_auth_type_to_str(), ast_strdup, and ast_sip_auth::type.

Referenced by ast_sip_initialize_sorcery_auth().

87 {
88  const struct ast_sip_auth *auth = obj;
90  return 0;
91 }
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
const char * ast_sip_auth_type_to_str(enum ast_sip_auth_type type)
Converts the given auth type to a string.
Definition: config_auth.c:80
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:243
enum ast_sip_auth_type type
Definition: res_pjsip.h:464

◆ cli_get_auths()

static struct ao2_container* cli_get_auths ( void  )
static

Definition at line 216 of file config_auth.c.

References AST_RETRIEVE_FLAG_ALL, AST_RETRIEVE_FLAG_MULTIPLE, ast_sip_get_sorcery(), ast_sorcery_retrieve_by_fields(), and NULL.

Referenced by ami_show_auths().

217 {
218  struct ao2_container *auths;
219 
222 
223  return auths;
224 }
Perform no matching, return all objects.
Definition: sorcery.h:123
Return all matching objects.
Definition: sorcery.h:120
#define NULL
Definition: resample.c:96
void * ast_sorcery_retrieve_by_fields(const struct ast_sorcery *sorcery, const char *type, unsigned int flags, struct ast_variable *fields)
Retrieve an object or multiple objects using specific fields.
Definition: sorcery.c:1897
struct ast_sorcery * ast_sip_get_sorcery(void)
Get a pointer to the SIP sorcery structure.
Generic container type.

◆ cli_get_container()

static struct ao2_container* cli_get_container ( const char *  regex)
static

Definition at line 277 of file config_auth.c.

References AO2_ALLOC_OPT_LOCK_NOLOCK, ao2_cleanup, ao2_container_alloc_list, ao2_container_dup(), ao2_ref, ast_sip_get_sorcery(), ast_sorcery_object_id_compare(), ast_sorcery_object_id_sort(), ast_sorcery_retrieve_by_regex(), container, NULL, and RAII_VAR.

Referenced by ast_sip_initialize_sorcery_auth().

278 {
280  struct ao2_container *s_container;
281 
283  if (!container) {
284  return NULL;
285  }
286 
289  if (!s_container) {
290  return NULL;
291  }
292 
293  if (ao2_container_dup(s_container, container, 0)) {
294  ao2_ref(s_container, -1);
295  return NULL;
296  }
297 
298  return s_container;
299 }
#define ao2_container_alloc_list(ao2_options, container_options, sort_fn, cmp_fn)
Definition: astobj2.h:1335
int ast_sorcery_object_id_compare(void *obj, void *arg, int flags)
ao2 object comparator based on sorcery id.
Definition: sorcery.c:2459
#define NULL
Definition: resample.c:96
struct ao2_container * ast_sorcery_retrieve_by_regex(const struct ast_sorcery *sorcery, const char *type, const char *regex)
Retrieve multiple objects using a regular expression on their id.
Definition: sorcery.c:1949
#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:911
#define ao2_ref(o, delta)
Definition: astobj2.h:464
int ast_sorcery_object_id_sort(const void *obj, const void *arg, int flags)
ao2 object sorter based on sorcery id.
Definition: sorcery.c:2435
struct ao2_container * container
Definition: res_fax.c:502
int ao2_container_dup(struct ao2_container *dest, struct ao2_container *src, enum search_flags flags)
Copy all object references in the src container into the dest container.
static int regex(struct ast_channel *chan, const char *cmd, char *parse, char *buf, size_t len)
Definition: func_strings.c:948
struct ast_sorcery * ast_sip_get_sorcery(void)
Get a pointer to the SIP sorcery structure.
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
Generic container type.

◆ cli_iterator()

static int cli_iterator ( void *  container,
ao2_callback_fn  callback,
void *  args 
)
static

Definition at line 301 of file config_auth.c.

References ast_sip_for_each_auth().

Referenced by ast_sip_initialize_sorcery_auth().

302 {
303  return ast_sip_for_each_auth(container, callback, args);
304 }
const char * args
struct ao2_container * container
Definition: res_fax.c:502
int ast_sip_for_each_auth(const struct ast_sip_auth_vector *vector, ao2_callback_fn on_auth, void *arg)
For every auth in the array call the given &#39;on_auth&#39; handler.
Definition: config_auth.c:135

◆ cli_print_body()

static int cli_print_body ( void *  obj,
void *  arg,
int  flags 
)
static

Definition at line 326 of file config_auth.c.

References ast_assert, ast_sip_cli_print_sorcery_objectset(), ast_sorcery_object_get_id(), ast_str_append(), ast_sip_cli_context::auth_direction, ast_sip_auth::auth_user, CLI_INDENT_TO_SPACES, context, ast_sip_cli_context::indent_level, NULL, ast_sip_cli_context::output_buffer, ast_sip_cli_context::show_details, and ast_sip_cli_context::show_details_only_level_0.

Referenced by ast_sip_initialize_sorcery_auth().

327 {
328  struct ast_sip_auth *auth = obj;
329  struct ast_sip_cli_context *context = arg;
330  char title[32];
331 
332  ast_assert(context->output_buffer != NULL);
333 
334  snprintf(title, sizeof(title), "%sAuth",
335  context->auth_direction ? context->auth_direction : "");
336 
337  ast_str_append(&context->output_buffer, 0, "%*s: %s/%s\n",
338  CLI_INDENT_TO_SPACES(context->indent_level), title,
339  ast_sorcery_object_get_id(auth), auth->auth_user);
340 
341  if (context->show_details
342  || (context->show_details_only_level_0 && context->indent_level == 0)) {
343  ast_str_append(&context->output_buffer, 0, "\n");
344  ast_sip_cli_print_sorcery_objectset(auth, context, 0);
345  }
346 
347  return 0;
348 }
struct ast_str * output_buffer
Definition: res_pjsip_cli.h:36
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
Definition: strings.h:1091
#define ast_assert(a)
Definition: utils.h:695
#define NULL
Definition: resample.c:96
#define CLI_INDENT_TO_SPACES(x)
Definition: res_pjsip_cli.h:29
const char * ast_sorcery_object_get_id(const void *object)
Get the unique identifier of a sorcery object.
Definition: sorcery.c:2312
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:116
int ast_sip_cli_print_sorcery_objectset(void *obj, void *arg, int flags)
Prints a sorcery object&#39;s ast_variable list.
Definition: pjsip_cli.c:36
const ast_string_field auth_user
Definition: res_pjsip.h:450
unsigned show_details_only_level_0
Definition: res_pjsip_cli.h:46

◆ cli_print_header()

static int cli_print_header ( void *  obj,
void *  arg,
int  flags 
)
static

Definition at line 311 of file config_auth.c.

References ast_assert, ast_str_append(), CLI_HEADER_FILLER, CLI_INDENT_TO_SPACES, CLI_MAX_WIDTH, context, ast_sip_cli_context::indent_level, NULL, and ast_sip_cli_context::output_buffer.

Referenced by ast_sip_initialize_sorcery_auth().

312 {
313  struct ast_sip_cli_context *context = arg;
314  int indent = CLI_INDENT_TO_SPACES(context->indent_level);
315  int filler = CLI_MAX_WIDTH - indent - 20;
316 
317  ast_assert(context->output_buffer != NULL);
318 
319  ast_str_append(&context->output_buffer, 0,
320  "%*s: <AuthId/UserName%*.*s>\n", indent, "I/OAuth", filler, filler,
322 
323  return 0;
324 }
struct ast_str * output_buffer
Definition: res_pjsip_cli.h:36
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
Definition: strings.h:1091
#define ast_assert(a)
Definition: utils.h:695
#define NULL
Definition: resample.c:96
#define CLI_INDENT_TO_SPACES(x)
Definition: res_pjsip_cli.h:29
#define CLI_MAX_WIDTH
Definition: res_pjsip_cli.h:26
#define CLI_HEADER_FILLER
Definition: res_pjsip_cli.h:24
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:116

◆ cli_retrieve_by_id()

static void* cli_retrieve_by_id ( const char *  id)
static

Definition at line 306 of file config_auth.c.

References ast_sip_get_sorcery(), and ast_sorcery_retrieve_by_id().

Referenced by ast_sip_initialize_sorcery_auth().

307 {
308  return ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), SIP_SORCERY_AUTH_TYPE, id);
309 }
void * ast_sorcery_retrieve_by_id(const struct ast_sorcery *sorcery, const char *type, const char *id)
Retrieve an object using its unique identifier.
Definition: sorcery.c:1853
struct ast_sorcery * ast_sip_get_sorcery(void)
Get a pointer to the SIP sorcery structure.

◆ format_ami_auth_handler()

static int format_ami_auth_handler ( void *  obj,
void *  arg,
int  flags 
)
static

Definition at line 168 of file config_auth.c.

References ast_sip_ami::arg, ast_free, ast_sip_create_ami_event(), ast_sorcery_object_get_id(), ast_str_append(), ast_str_buffer(), astman_append(), buf, ast_sip_ami::count, RAII_VAR, ast_sip_ami::s, and sip_auth_to_ami().

Referenced by ast_sip_format_auths_ami().

169 {
170  const struct ast_sip_auth *auth = obj;
171  struct ast_sip_ami *ami = arg;
172  const struct ast_sip_endpoint *endpoint = ami->arg;
173  RAII_VAR(struct ast_str *, buf,
174  ast_sip_create_ami_event("AuthDetail", ami), ast_free);
175 
176  if (!buf) {
177  return -1;
178  }
179 
180  if (sip_auth_to_ami(auth, &buf)) {
181  return -1;
182  }
183 
184  if (endpoint) {
185  ast_str_append(&buf, 0, "EndpointName: %s\r\n",
186  ast_sorcery_object_get_id(endpoint));
187  }
188 
189  astman_append(ami->s, "%s\r\n", ast_str_buffer(buf));
190  ami->count++;
191 
192  return 0;
193 }
void astman_append(struct mansession *s, const char *fmt,...)
Definition: manager.c:3080
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
void * arg
Definition: res_pjsip.h:2745
AMI variable container.
Definition: res_pjsip.h:2737
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
Definition: strings.h:1091
#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:911
const char * ast_sorcery_object_get_id(const void *object)
Get the unique identifier of a sorcery object.
Definition: sorcery.c:2312
struct mansession * s
Definition: res_pjsip.h:2739
An entity with which Asterisk communicates.
Definition: res_pjsip.h:812
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
#define ast_free(a)
Definition: astmm.h:182
struct ast_str * ast_sip_create_ami_event(const char *event, struct ast_sip_ami *ami)
Creates a string to store AMI event data in.
static int sip_auth_to_ami(const struct ast_sip_auth *auth, struct ast_str **buf)
Definition: config_auth.c:162

◆ format_ami_authlist_handler()

static int format_ami_authlist_handler ( void *  obj,
void *  arg,
int  flags 
)
static

Definition at line 226 of file config_auth.c.

References ast_sip_ami::arg, ast_free, ast_sip_create_ami_event(), ast_str_buffer(), astman_append(), buf, CMP_STOP, ast_sip_ami::count, ast_sip_ami::s, and sip_auth_to_ami().

Referenced by ami_show_auths().

227 {
228  struct ast_sip_auth *auth = obj;
229  struct ast_sip_ami *ami = arg;
230  struct ast_str *buf;
231 
232  buf = ast_sip_create_ami_event("AuthList", ami);
233  if (!buf) {
234  return CMP_STOP;
235  }
236 
237  sip_auth_to_ami(auth, &buf);
238 
239  astman_append(ami->s, "%s\r\n", ast_str_buffer(buf));
240  ami->count++;
241 
242  ast_free(buf);
243 
244  return 0;
245 }
void astman_append(struct mansession *s, const char *fmt,...)
Definition: manager.c:3080
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
void * arg
Definition: res_pjsip.h:2745
AMI variable container.
Definition: res_pjsip.h:2737
struct mansession * s
Definition: res_pjsip.h:2739
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
#define ast_free(a)
Definition: astmm.h:182
struct ast_str * ast_sip_create_ami_event(const char *event, struct ast_sip_ami *ami)
Creates a string to store AMI event data in.
static int sip_auth_to_ami(const struct ast_sip_auth *auth, struct ast_str **buf)
Definition: config_auth.c:162

◆ format_ami_endpoint_auth()

static int format_ami_endpoint_auth ( const struct ast_sip_endpoint endpoint,
struct ast_sip_ami ami 
)
static

Definition at line 201 of file config_auth.c.

References ast_sip_ami::arg, ast_sip_format_auths_ami(), ast_sip_endpoint::inbound_auths, and ast_sip_endpoint::outbound_auths.

203 {
204  ami->arg = (void *)endpoint;
205  if (ast_sip_format_auths_ami(&endpoint->inbound_auths, ami)) {
206  return -1;
207  }
208 
209  return ast_sip_format_auths_ami(&endpoint->outbound_auths, ami);
210 }
void * arg
Definition: res_pjsip.h:2745
struct ast_sip_auth_vector outbound_auths
Definition: res_pjsip.h:855
int ast_sip_format_auths_ami(const struct ast_sip_auth_vector *auths, struct ast_sip_ami *ami)
Format auth details for AMI.
Definition: config_auth.c:195
struct ast_sip_auth_vector inbound_auths
Definition: res_pjsip.h:853

◆ sip_auth_to_ami()

static int sip_auth_to_ami ( const struct ast_sip_auth auth,
struct ast_str **  buf 
)
static

Definition at line 162 of file config_auth.c.

References ast_sip_sorcery_object_to_ami().

Referenced by format_ami_auth_handler(), and format_ami_authlist_handler().

164 {
165  return ast_sip_sorcery_object_to_ami(auth, buf);
166 }
int ast_sip_sorcery_object_to_ami(const void *obj, struct ast_str **buf)
Converts a sorcery object to a string of object properties.

Variable Documentation

◆ auth_types_map

const char* auth_types_map[]
static

◆ cli_commands

struct ast_cli_entry cli_commands[]
static

Definition at line 350 of file config_auth.c.

◆ cli_formatter

struct ast_sip_cli_formatter_entry* cli_formatter
static

Definition at line 367 of file config_auth.c.

◆ endpoint_auth_formatter

struct ast_sip_endpoint_formatter endpoint_auth_formatter
static
Initial value:
= {
}
static int format_ami_endpoint_auth(const struct ast_sip_endpoint *endpoint, struct ast_sip_ami *ami)
Definition: config_auth.c:201

Definition at line 212 of file config_auth.c.