Asterisk - The Open Source Telephony Project GIT-master-8f1982c
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Modules Pages
Macros | 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 "asterisk/vector.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.

Macros

#define MD5_DIGEST_LENGTH   16
 
#define SHA256_DIGEST_LENGTH   32
 

Functions

static int ami_show_auths (struct mansession *s, const struct message *m)
 
int ast_sip_auth_digest_algorithms_vector_init (const char *id, struct pjsip_auth_algorithm_type_vector *algorithms, const char *agent_type, const char *value)
 Populate a vector of algorithm types from a string. More...
 
int ast_sip_auth_digest_algorithms_vector_to_str (const struct pjsip_auth_algorithm_type_vector *algorithms, char **buf)
 Dump a vector of algorithm types to a string. More...
 
const pjsip_auth_algorithmast_sip_auth_get_algorithm_by_iana_name (const pj_str_t *iana_name)
 Get algorithm by IANA name. More...
 
const pjsip_auth_algorithmast_sip_auth_get_algorithm_by_type (pjsip_auth_algorithm_type algorithm_type)
 Get algorithm by algorithm type. More...
 
const char * ast_sip_auth_get_creds (const struct ast_sip_auth *auth, const pjsip_auth_algorithm_type algorithm_type, int *cred_type)
 Get the plain text or digest password from an auth object. More...
 
int ast_sip_auth_is_algorithm_available (const struct ast_sip_auth *auth, const struct pjsip_auth_algorithm_type_vector *algorithms, pjsip_auth_algorithm_type algorithm_type)
 Checks an pjsip_auth_algorithm_type_vector to see if it contains an algorithm. More...
 
pj_bool_t ast_sip_auth_is_algorithm_supported (pjsip_auth_algorithm_type algorithm_type)
 Is algorithm supported by OpenSSL and pjproject? More...
 
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 int check_algorithm (const struct ast_sip_auth *auth, const pjsip_auth_algorithm_type algorithm_type, const char *which_supported)
 
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 void global_loaded (const char *object_type)
 
static int md5cred_to_str (const void *obj, const intptr_t *args, char **buf)
 
static int password_digest_handler (const struct aco_option *opt, struct ast_variable *var, void *obj)
 
static int password_digest_to_str (const void *obj, const intptr_t *args, char **buf)
 
static int sip_auth_to_ami (const struct ast_sip_auth *auth, struct ast_str **buf)
 
static int uac_algorithms_handler (const struct aco_option *opt, struct ast_variable *var, void *obj)
 
static int uac_algorithms_to_str (const void *obj, const intptr_t *args, char **buf)
 
static int uas_algorithms_handler (const struct aco_option *opt, struct ast_variable *var, void *obj)
 
static int uas_algorithms_to_str (const void *obj, const intptr_t *args, char **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
 
static struct ast_sorcery_observer global_observer
 Observer which is used to update our interval and default_realm when the global setting changes. More...
 
const pjsip_auth_algorithm pjsip_auth_algorithms []
 

Macro Definition Documentation

◆ MD5_DIGEST_LENGTH

#define MD5_DIGEST_LENGTH   16

Definition at line 42 of file config_auth.c.

◆ SHA256_DIGEST_LENGTH

#define SHA256_DIGEST_LENGTH   32

Definition at line 43 of file config_auth.c.

Function Documentation

◆ ami_show_auths()

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

Definition at line 596 of file config_auth.c.

597{
598 struct ast_sip_ami ami = { .s = s, .m = m, .action_id = astman_get_header(m, "ActionID"), };
599 struct ao2_container *auths;
600
601 auths = cli_get_auths();
602 if (!auths) {
603 astman_send_error(s, m, "Could not get Auths\n");
604 return 0;
605 }
606
607 if (!ao2_container_count(auths)) {
608 astman_send_error(s, m, "No Auths found\n");
609 ao2_ref(auths, -1);
610 return 0;
611 }
612
613 astman_send_listack(s, m, "A listing of Auths follows, presented as AuthList events",
614 "start");
615
617
618 astman_send_list_complete_start(s, m, "AuthListComplete", ami.count);
620
621 ao2_ref(auths, -1);
622
623 return 0;
624}
#define ao2_callback(c, flags, cb_fn, arg)
ao2_callback() is a generic function that applies cb_fn() to all objects in a container,...
Definition: astobj2.h:1693
int ao2_container_count(struct ao2_container *c)
Returns the number of elements in a container.
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
@ OBJ_NODATA
Definition: astobj2.h:1044
static int format_ami_authlist_handler(void *obj, void *arg, int flags)
Definition: config_auth.c:575
static struct ao2_container * cli_get_auths(void)
Definition: config_auth.c:565
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:2028
void astman_send_error(struct mansession *s, const struct message *m, char *error)
Send error in manager transaction.
Definition: manager.c:1986
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:2064
const char * astman_get_header(const struct message *m, char *var)
Get header from manager transaction.
Definition: manager.c:1647
void astman_send_list_complete_end(struct mansession *s)
End the list complete event.
Definition: manager.c:2072
Generic container type.
AMI variable container.
Definition: res_pjsip.h:3200
struct mansession * s
Definition: res_pjsip.h:3202
const struct message * m
Definition: res_pjsip.h:3204

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().

◆ ast_sip_auth_digest_algorithms_vector_init()

int ast_sip_auth_digest_algorithms_vector_init ( const char *  id,
struct pjsip_auth_algorithm_type_vector algorithms,
const char *  agent_type,
const char *  value 
)

Populate a vector of algorithm types from a string.

Parameters
idThe object id to use in error messages
algorithmsThe initialized but empty vector to populate
agent_typeThe type of agent to use in error messages ("UAC" or "UAS")
valueThe comma-separated string to parse for algorithms
Return values
0Success
non-zeroFailure

Definition at line 192 of file config_auth.c.

195{
196 char *iana_names = ast_strdupa(value);
197 pj_str_t val;
198 int res = 0;
199
200 ast_assert(algorithms != NULL);
201
202 while ((val.ptr = ast_strip(strsep(&iana_names, ",")))) {
203 const pjsip_auth_algorithm *algo;
204
205 if (ast_strlen_zero(val.ptr)) {
206 continue;
207 }
208 val.slen = strlen(val.ptr);
209
211 if (!algo) {
212 ast_log(LOG_WARNING, "%s: Unknown %s digest algorithm '%s' specified\n",
213 id, agent_type, val.ptr);
214 res = -1;
215 continue;
216 }
218 ast_log(LOG_WARNING, "%s: %s digest algorithm '%s' is not supported by the version of OpenSSL in use\n",
219 id, agent_type, val.ptr);
220 res = -1;
221 continue;
222 }
223
224 if (AST_VECTOR_APPEND(algorithms, algo->algorithm_type)) {
225 AST_VECTOR_FREE(algorithms);
226 return -1;
227 }
228 }
229 return res;
230}
static struct aco_type agent_type
char * strsep(char **str, const char *delims)
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:298
#define ast_log
Definition: astobj2.c:42
const pjsip_auth_algorithm * ast_sip_auth_get_algorithm_by_iana_name(const pj_str_t *iana_name)
Get algorithm by IANA name.
Definition: config_auth.c:83
pj_bool_t ast_sip_auth_is_algorithm_supported(pjsip_auth_algorithm_type algorithm_type)
Is algorithm supported by OpenSSL and pjproject?
Definition: config_auth.c:104
#define LOG_WARNING
#define NULL
Definition: resample.c:96
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
char * ast_strip(char *s)
Strip leading/trailing whitespace from a string.
Definition: strings.h:223
pjsip_auth_algorithm_type algorithm_type
Definition: res_pjsip.h:618
Definition: ast_expr2.c:325
int value
Definition: syslog.c:37
#define ast_assert(a)
Definition: utils.h:739
#define AST_VECTOR_FREE(vec)
Deallocates this vector.
Definition: vector.h:174
#define AST_VECTOR_APPEND(vec, elem)
Append an element to a vector, growing the vector if needed.
Definition: vector.h:256

References agent_type, pjsip_auth_algorithm::algorithm_type, ast_assert, ast_log, ast_sip_auth_get_algorithm_by_iana_name(), ast_sip_auth_is_algorithm_supported(), ast_strdupa, ast_strip(), ast_strlen_zero(), AST_VECTOR_APPEND, AST_VECTOR_FREE, LOG_WARNING, NULL, strsep(), and value.

Referenced by alloc_artificial_auth(), auth_apply(), global_apply(), uac_algorithms_handler(), and uas_algorithms_handler().

◆ ast_sip_auth_digest_algorithms_vector_to_str()

int ast_sip_auth_digest_algorithms_vector_to_str ( const struct pjsip_auth_algorithm_type_vector algorithms,
char **  buf 
)

Dump a vector of algorithm types to a string.

Parameters
algorithmsThe vector to dump
[out]bufPointer to the buffer to dump the algorithms to Must be freed by the caller.
Return values
0Success
non-zeroFailure

Definition at line 248 of file config_auth.c.

250{
251 struct ast_str *str = NULL;
252 int i = 0;
253
254 if (!algorithms || !AST_VECTOR_SIZE(algorithms)) {
255 return 0;
256 }
257
258 str = ast_str_alloca(256);
259 if (!str) {
260 return -1;
261 }
262
263 for (i = 0; i < AST_VECTOR_SIZE(algorithms); ++i) {
265 AST_VECTOR_GET(algorithms, i));
266 ast_str_append(&str, 0, "%s" PJSTR_PRINTF_SPEC, i > 0 ? "," : "",
268 }
269
271
272 return *buf ? 0 : -1;
273}
const char * str
Definition: app_jack.c:150
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:241
const pjsip_auth_algorithm * ast_sip_auth_get_algorithm_by_type(pjsip_auth_algorithm_type algorithm_type)
Get algorithm by algorithm type.
Definition: config_auth.c:66
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
#define PJSTR_PRINTF_VAR(_v)
Definition: res_pjsip.h:72
#define PJSTR_PRINTF_SPEC
Definition: res_pjsip.h:71
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:1139
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:761
#define ast_str_alloca(init_len)
Definition: strings.h:848
Support for dynamic strings.
Definition: strings.h:623
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
Definition: vector.h:609
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
Definition: vector.h:680

References ast_sip_auth_get_algorithm_by_type(), ast_str_alloca, ast_str_append(), ast_str_buffer(), ast_strdup, AST_VECTOR_GET, AST_VECTOR_SIZE, buf, pjsip_auth_algorithm::iana_name, NULL, PJSTR_PRINTF_SPEC, PJSTR_PRINTF_VAR, and str.

Referenced by uac_algorithms_to_str(), and uas_algorithms_to_str().

◆ ast_sip_auth_get_algorithm_by_iana_name()

const pjsip_auth_algorithm * ast_sip_auth_get_algorithm_by_iana_name ( const pj_str_t *  iana_name)

Get algorithm by IANA name.

Parameters
iana_nameThe algorithm IANA name
Return values
Thealgorithm or NULL if not found

Definition at line 83 of file config_auth.c.

85{
86#ifdef HAVE_PJSIP_AUTH_NEW_DIGESTS
87 return pjsip_auth_get_algorithm_by_iana_name(iana_name);
88#else
89 if (!iana_name) {
90 return NULL;
91 }
92 /*
93 * If we don't have a pjproject with the new algorithms, the
94 * only one we support is MD5. If iana_name is empty (but not NULL),
95 * the default is MD5.
96 */
97 if (iana_name->slen == 0 || pj_stricmp2(iana_name, "MD5") == 0) {
99 }
100 return NULL;
101#endif
102}
const pjsip_auth_algorithm pjsip_auth_algorithms[]
Definition: config_auth.c:46
@ PJSIP_AUTH_ALGORITHM_MD5
Definition: res_pjsip.h:609

References NULL, PJSIP_AUTH_ALGORITHM_MD5, and pjsip_auth_algorithms.

Referenced by ast_sip_auth_digest_algorithms_vector_init(), digest_lookup(), get_supported_algorithm(), and password_digest_handler().

◆ ast_sip_auth_get_algorithm_by_type()

const pjsip_auth_algorithm * ast_sip_auth_get_algorithm_by_type ( pjsip_auth_algorithm_type  algorithm_type)

Get algorithm by algorithm type.

Parameters
algorithm_typeThe algorithm type
Return values
Thealgorithm or NULL if not found

Definition at line 66 of file config_auth.c.

68{
69#ifdef HAVE_PJSIP_AUTH_NEW_DIGESTS
70 return pjsip_auth_get_algorithm_by_type(algorithm_type);
71#else
72 /*
73 * If we don't have a pjproject with the new algorithms, the
74 * only one we support is MD5.
75 */
76 if (algorithm_type == PJSIP_AUTH_ALGORITHM_MD5) {
77 return &pjsip_auth_algorithms[algorithm_type];
78 }
79 return NULL;
80#endif
81}

References NULL, PJSIP_AUTH_ALGORITHM_MD5, and pjsip_auth_algorithms.

Referenced by ast_sip_auth_digest_algorithms_vector_to_str(), check_algorithm(), digest_check_auth(), and password_digest_to_str().

◆ ast_sip_auth_get_creds()

const char * ast_sip_auth_get_creds ( const struct ast_sip_auth auth,
const pjsip_auth_algorithm_type  algorithm_type,
int *  cred_type 
)

Get the plain text or digest password from an auth object.

Parameters
authThe auth object
algorithm_typeThe algorithm type to retrieve the password for
cred_type[out]Pointer to an int to receive the credential type
Note
cred_type will contain one of the following values:
  • PJSIP_CRED_DATA_DIGEST
  • PJSIP_CRED_DATA_PLAIN_PASSWD

If a password digest is available for the algorithm type it will be returned, otherwise if a plain text password is available that will be returned instead.

Return values
Theplain text or digest password or NULL if not found for the algorithm type

Definition at line 407 of file config_auth.c.

409{
410 struct ast_sip_auth_password_digest *pw_digest =
412
413 if (pw_digest) {
414 *cred_type = PJSIP_CRED_DATA_DIGEST;
415 return pw_digest->digest;
416 }
417
418 *cred_type = PJSIP_CRED_DATA_PLAIN_PASSWD;
419 return auth->auth_pass;
420}
pjsip_auth_algorithm_type algorithm_type
Definition: res_pjsip.h:656
struct ast_sip_auth_password_digest * password_digests[PJSIP_AUTH_ALGORITHM_COUNT]
Definition: res_pjsip.h:691
const ast_string_field auth_pass
Definition: res_pjsip.h:681

References ast_sip_auth_password_digest::algorithm_type, ast_sip_auth::auth_pass, ast_sip_auth_password_digest::digest, and ast_sip_auth::password_digests.

Referenced by digest_lookup(), and get_creds_for_header().

◆ ast_sip_auth_is_algorithm_available()

int ast_sip_auth_is_algorithm_available ( const struct ast_sip_auth auth,
const struct pjsip_auth_algorithm_type_vector algorithms,
pjsip_auth_algorithm_type  algorithm_type 
)

Checks an pjsip_auth_algorithm_type_vector to see if it contains an algorithm.

Parameters
authThe auth object
algorithmsThe auth object's supported_algorithms_uac or supported_algorithms_uas
algorithm_typeThe algorithm_type to check
Return values
1The algorithm-type is in the vector
0The algorithm-type is not in the vector

Definition at line 386 of file config_auth.c.

389{
390 int i;
391
392 if (!algorithms) {
393 return 0;
394 }
395
396 for (i = 0; i < AST_VECTOR_SIZE(algorithms); ++i) {
397 if (AST_VECTOR_GET(algorithms, i) == algorithm_type) {
398 if (auth->password_digests[algorithm_type] || !ast_strlen_zero(auth->auth_pass)) {
399 return 1;
400 }
401 }
402 }
403
404 return 0;
405}

References ast_strlen_zero(), AST_VECTOR_GET, AST_VECTOR_SIZE, ast_sip_auth::auth_pass, and ast_sip_auth::password_digests.

Referenced by digest_lookup(), and get_creds_for_header().

◆ ast_sip_auth_is_algorithm_supported()

pj_bool_t ast_sip_auth_is_algorithm_supported ( pjsip_auth_algorithm_type  algorithm_type)

Is algorithm supported by OpenSSL and pjproject?

Parameters
algorithm_typeThe algorithm IANA name
Return values
Thealgorithm or NULL if not found

Definition at line 104 of file config_auth.c.

106{
107#ifdef HAVE_PJSIP_AUTH_NEW_DIGESTS
108 return pjsip_auth_is_algorithm_supported(algorithm_type);
109#else
110 return algorithm_type == PJSIP_AUTH_ALGORITHM_MD5;
111#endif
112}

References PJSIP_AUTH_ALGORITHM_MD5.

Referenced by ast_sip_auth_digest_algorithms_vector_init(), get_supported_algorithm(), and password_digest_handler().

◆ 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 179 of file config_auth.c.

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

References ARRAY_IN_BOUNDS, auth_types_map, and type.

Referenced by auth_type_to_str().

◆ ast_sip_destroy_sorcery_auth()

int ast_sip_destroy_sorcery_auth ( void  )

Definition at line 792 of file config_auth.c.

793{
795
799
800 ast_manager_unregister("PJSIPShowAuths");
801
802 return 0;
803}
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
Definition: clicompat.c:30
static struct ast_sorcery_observer global_observer
Observer which is used to update our interval and default_realm when the global setting changes.
Definition: config_auth.c:724
static struct ast_cli_entry cli_commands[]
Definition: config_auth.c:699
static struct ast_sip_endpoint_formatter endpoint_auth_formatter
Definition: config_auth.c:561
static struct ast_sip_cli_formatter_entry * cli_formatter
Definition: config_auth.c:716
int ast_manager_unregister(const char *action)
Unregister a registered manager command.
Definition: manager.c:7697
void ast_sip_unregister_endpoint_formatter(struct ast_sip_endpoint_formatter *obj)
Unregister an endpoint formatter.
Definition: res_pjsip.c:487
struct ast_sorcery * ast_sip_get_sorcery(void)
Get a pointer to the SIP sorcery structure.
int ast_sip_unregister_cli_formatter(struct ast_sip_cli_formatter_entry *formatter)
Unregisters a CLI formatter.
Definition: pjsip_cli.c:326
void ast_sorcery_observer_remove(const struct ast_sorcery *sorcery, const char *type, const struct ast_sorcery_observer *callbacks)
Remove an observer from a specific object type.
Definition: sorcery.c:2423
#define ARRAY_LEN(a)
Definition: utils.h:666

References ARRAY_LEN, ast_cli_unregister_multiple(), ast_manager_unregister(), ast_sip_get_sorcery(), ast_sip_unregister_cli_formatter(), ast_sip_unregister_endpoint_formatter(), ast_sorcery_observer_remove(), cli_commands, cli_formatter, endpoint_auth_formatter, and global_observer.

Referenced by ast_res_pjsip_destroy_configuration().

◆ 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 484 of file config_auth.c.

486{
487 int i;
488
489 if (!vector || !AST_VECTOR_SIZE(vector)) {
490 return 0;
491 }
492
493 for (i = 0; i < AST_VECTOR_SIZE(vector); ++i) {
494 /* AST_VECTOR_GET is safe to use since the vector is immutable */
497 AST_VECTOR_GET(vector,i)), ao2_cleanup);
498
499 if (!auth) {
500 continue;
501 }
502
503 if (on_auth(auth, arg, 0)) {
504 return -1;
505 }
506 }
507
508 return 0;
509}
#define ao2_cleanup(obj)
Definition: astobj2.h:1934
#define SIP_SORCERY_AUTH_TYPE
Definition: res_pjsip.h:597
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:941

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

Referenced by ast_sip_format_auths_ami(), and cli_iterator().

◆ 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 544 of file config_auth.c.

546{
548}
static int format_ami_auth_handler(void *obj, void *arg, int flags)
Definition: config_auth.c:517
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.
Definition: config_auth.c:484

References ast_sip_for_each_auth(), and format_ami_auth_handler().

Referenced by ami_outbound_registration_task(), and format_ami_endpoint_auth().

◆ ast_sip_initialize_sorcery_auth()

int ast_sip_initialize_sorcery_auth ( void  )

Initialize sorcery with auth support.

Definition at line 729 of file config_auth.c.

730{
732
733 ast_sorcery_apply_default(sorcery, SIP_SORCERY_AUTH_TYPE, "config", "pjsip.conf,criteria=type=auth");
734
736 return -1;
737 }
738
740 OPT_NOOP_T, 0, 0);
742 "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_auth, auth_user));
744 "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_auth, auth_pass));
746 "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_auth, refresh_token));
748 "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_auth, oauth_clientid));
750 "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_auth, oauth_secret));
754 "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_auth, realm));
756 "32", OPT_UINT_T, 0, FLDSET(struct ast_sip_auth, nonce_lifetime));
758 "userpass", auth_type_handler, auth_type_to_str, NULL, 0, 0);
765
767
769 if (!cli_formatter) {
770 ast_log(LOG_ERROR, "Unable to allocate memory for cli formatter\n");
771 return -1;
772 }
780
783
785 return -1;
786 }
787
789 return 0;
790}
#define ao2_alloc(data_size, destructor_fn)
Definition: astobj2.h:409
#define ast_cli_register_multiple(e, len)
Register multiple commands.
Definition: cli.h:265
static int cli_print_header(void *obj, void *arg, int flags)
Definition: config_auth.c:660
static int cli_iterator(void *container, ao2_callback_fn callback, void *args)
Definition: config_auth.c:650
static int md5cred_to_str(const void *obj, const intptr_t *args, char **buf)
Definition: config_auth.c:375
static int password_digest_to_str(const void *obj, const intptr_t *args, char **buf)
Definition: config_auth.c:347
static void * auth_alloc(const char *name)
Definition: config_auth.c:129
static void * cli_retrieve_by_id(const char *id)
Definition: config_auth.c:655
static int auth_type_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
Definition: config_auth.c:148
static int uac_algorithms_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
Definition: config_auth.c:232
static int auth_apply(const struct ast_sorcery *sorcery, void *obj)
Definition: config_auth.c:439
static struct ao2_container * cli_get_container(const char *regex)
Definition: config_auth.c:626
static int password_digest_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
Definition: config_auth.c:287
static int cli_print_body(void *obj, void *arg, int flags)
Definition: config_auth.c:675
static int ami_show_auths(struct mansession *s, const struct message *m)
Definition: config_auth.c:596
static int uas_algorithms_to_str(const void *obj, const intptr_t *args, char **buf)
Definition: config_auth.c:281
static int uas_algorithms_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
Definition: config_auth.c:240
static int auth_type_to_str(const void *obj, const intptr_t *args, char **buf)
Definition: config_auth.c:185
static int uac_algorithms_to_str(const void *obj, const intptr_t *args, char **buf)
Definition: config_auth.c:275
#define STRFLDSET(type,...)
Convert a struct and a list of stringfield fields to an argument list of field offsets.
#define FLDSET(type,...)
Convert a struct and list of fields to an argument list of field offsets.
@ OPT_UINT_T
Type for default option handler for unsigned integers.
@ OPT_NOOP_T
Type for a default handler that should do nothing.
@ OPT_STRINGFIELD_T
Type for default option handler for stringfields.
#define LOG_ERROR
#define EVENT_FLAG_SYSTEM
Definition: manager.h:75
#define ast_manager_register_xml(action, authority, func)
Register a manager callback using XML documentation to describe the manager.
Definition: manager.h:192
void ast_sip_register_endpoint_formatter(struct ast_sip_endpoint_formatter *obj)
Register an endpoint formatter.
Definition: res_pjsip.c:481
int ast_sip_register_cli_formatter(struct ast_sip_cli_formatter_entry *formatter)
Registers a CLI formatter.
Definition: pjsip_cli.c:310
static struct ast_sorcery * sorcery
const char * ast_sorcery_object_get_id(const void *object)
Get the unique identifier of a sorcery object.
Definition: sorcery.c:2317
#define ast_sorcery_object_register(sorcery, type, alloc, transform, apply)
Register an object type.
Definition: sorcery.h:837
int ast_sorcery_observer_add(const struct ast_sorcery *sorcery, const char *type, const struct ast_sorcery_observer *callbacks)
Add an observer to a specific object type.
Definition: sorcery.c:2391
#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 ast_sorcery_object_field_register(sorcery, type, name, default_val, opt_type, flags,...)
Register a field within an object.
Definition: sorcery.h:955
#define ast_sorcery_apply_default(sorcery, type, name, data)
Definition: sorcery.h:476
CLI Formatter Registry Entry.
Definition: res_pjsip_cli.h:52
int(* iterate)(void *container, ao2_callback_fn callback, void *args)
Definition: res_pjsip_cli.h:66
ao2_callback_fn * print_header
Definition: res_pjsip_cli.h:60
void *(* retrieve_by_id)(const char *id)
Definition: res_pjsip_cli.h:68
const char *(* get_id)(const void *obj)
Definition: res_pjsip_cli.h:70
const char * name
Definition: res_pjsip_cli.h:58
ao2_callback_fn * print_body
Definition: res_pjsip_cli.h:62
struct ao2_container *(* get_container)(const char *regex)
Definition: res_pjsip_cli.h:64
Full structure for sorcery.
Definition: sorcery.c:230

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, ast_sorcery_observer_add(), auth_alloc(), auth_apply(), auth_type_handler(), auth_type_to_str(), cli_commands, cli_formatter, cli_get_container(), cli_iterator(), cli_print_body(), cli_print_header(), cli_retrieve_by_id(), endpoint_auth_formatter, EVENT_FLAG_SYSTEM, FLDSET, ast_sip_cli_formatter_entry::get_container, ast_sip_cli_formatter_entry::get_id, global_observer, ast_sip_cli_formatter_entry::iterate, LOG_ERROR, md5cred_to_str(), ast_sip_cli_formatter_entry::name, NULL, OPT_NOOP_T, OPT_STRINGFIELD_T, OPT_UINT_T, password_digest_handler(), password_digest_to_str(), ast_sip_cli_formatter_entry::print_body, ast_sip_cli_formatter_entry::print_header, ast_sip_cli_formatter_entry::retrieve_by_id, SIP_SORCERY_AUTH_TYPE, sorcery, STRFLDSET, uac_algorithms_handler(), uac_algorithms_to_str(), uas_algorithms_handler(), and uas_algorithms_to_str().

Referenced by ast_res_pjsip_initialize_configuration().

◆ auth_alloc()

static void * auth_alloc ( const char *  name)
static

Definition at line 129 of file config_auth.c.

130{
131 struct ast_sip_auth *auth = ast_sorcery_generic_alloc(sizeof(*auth), auth_destroy);
132
133 if (!auth) {
134 return NULL;
135 }
136
137 if (ast_string_field_init(auth, 64)) {
138 ao2_cleanup(auth);
139 return NULL;
140 }
141
144
145 return auth;
146}
static void auth_destroy(void *obj)
Definition: config_auth.c:114
void * ast_sorcery_generic_alloc(size_t size, ao2_destructor_fn destructor)
Allocate a generic sorcery capable object.
Definition: sorcery.c:1728
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
Definition: stringfields.h:359
struct pjsip_auth_algorithm_type_vector supported_algorithms_uac
Definition: res_pjsip.h:687
struct pjsip_auth_algorithm_type_vector supported_algorithms_uas
Definition: res_pjsip.h:689
#define AST_VECTOR_INIT(vec, size)
Initialize a vector.
Definition: vector.h:113

References ao2_cleanup, ast_sorcery_generic_alloc(), ast_string_field_init, AST_VECTOR_INIT, auth_destroy(), NULL, ast_sip_auth::supported_algorithms_uac, and ast_sip_auth::supported_algorithms_uas.

Referenced by ast_sip_initialize_sorcery_auth().

◆ auth_apply()

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

Definition at line 439 of file config_auth.c.

440{
441 struct ast_sip_auth *auth = obj;
442 const char *id = ast_sorcery_object_get_id(auth);
443 int i = 0;
444 int res = 0;
445
446 if (ast_strlen_zero(auth->auth_user)) {
447 ast_log(LOG_ERROR, "%s: No authentication username\n", id);
448 return -1;
449 }
450
454 || ast_strlen_zero(auth->oauth_secret)) {
455 ast_log(LOG_ERROR, "%s: 'google_oauth' authentication specified but refresh_token,"
456 " oauth_clientid, or oauth_secret not specified\n", id);
457 res = -1;
458 }
459 return res;
460 }
461
462 if (AST_VECTOR_SIZE(&auth->supported_algorithms_uas) == 0) {
463 char *default_algo_uas = ast_alloca(AST_SIP_AUTH_MAX_SUPPORTED_ALGORITHMS_LENGTH + 1);
465 ast_sip_auth_digest_algorithms_vector_init(id, &auth->supported_algorithms_uas, "UAS", default_algo_uas);
466 }
467 if (AST_VECTOR_SIZE(&auth->supported_algorithms_uac) == 0) {
468 char *default_algo_uac = ast_alloca(AST_SIP_AUTH_MAX_SUPPORTED_ALGORITHMS_LENGTH + 1);
470 ast_sip_auth_digest_algorithms_vector_init(id, &auth->supported_algorithms_uac, "UAC", default_algo_uac);
471 }
472
473 for (i = 0; i < AST_VECTOR_SIZE(&auth->supported_algorithms_uas); i++) {
474 res += check_algorithm(auth, AST_VECTOR_GET(&auth->supported_algorithms_uas, i), "uas");
475 }
476
477 for (i = 0; i < AST_VECTOR_SIZE(&auth->supported_algorithms_uac); i++) {
478 res += check_algorithm(auth, AST_VECTOR_GET(&auth->supported_algorithms_uac, i), "uac");
479 }
480
481 return res;
482}
#define ast_alloca(size)
call __builtin_alloca to ensure we get gcc builtin semantics
Definition: astmm.h:288
int ast_sip_auth_digest_algorithms_vector_init(const char *id, struct pjsip_auth_algorithm_type_vector *algorithms, const char *agent_type, const char *value)
Populate a vector of algorithm types from a string.
Definition: config_auth.c:192
static int check_algorithm(const struct ast_sip_auth *auth, const pjsip_auth_algorithm_type algorithm_type, const char *which_supported)
Definition: config_auth.c:422
@ AST_SIP_AUTH_TYPE_GOOGLE_OAUTH
Definition: res_pjsip.h:583
#define AST_SIP_AUTH_MAX_SUPPORTED_ALGORITHMS_LENGTH
Definition: res_pjsip.h:75
void ast_sip_get_default_auth_algorithms_uac(char *default_auth_algorithms_uac, size_t size)
Retrieve the global auth algorithms for UAC.
void ast_sip_get_default_auth_algorithms_uas(char *default_auth_algorithms_uas, size_t size)
Retrieve the global auth algorithms for UAS.
const ast_string_field oauth_clientid
Definition: res_pjsip.h:681
const ast_string_field oauth_secret
Definition: res_pjsip.h:681
const ast_string_field auth_user
Definition: res_pjsip.h:681
const ast_string_field refresh_token
Definition: res_pjsip.h:681
enum ast_sip_auth_type type
Definition: res_pjsip.h:685

References ast_alloca, ast_log, ast_sip_auth_digest_algorithms_vector_init(), AST_SIP_AUTH_MAX_SUPPORTED_ALGORITHMS_LENGTH, AST_SIP_AUTH_TYPE_GOOGLE_OAUTH, ast_sip_get_default_auth_algorithms_uac(), ast_sip_get_default_auth_algorithms_uas(), ast_sorcery_object_get_id(), ast_strlen_zero(), AST_VECTOR_GET, AST_VECTOR_SIZE, ast_sip_auth::auth_user, check_algorithm(), LOG_ERROR, ast_sip_auth::oauth_clientid, ast_sip_auth::oauth_secret, ast_sip_auth::refresh_token, ast_sip_auth::supported_algorithms_uac, ast_sip_auth::supported_algorithms_uas, and ast_sip_auth::type.

Referenced by ast_sip_initialize_sorcery_auth().

◆ auth_destroy()

static void auth_destroy ( void *  obj)
static

Definition at line 114 of file config_auth.c.

115{
116 struct ast_sip_auth *auth = obj;
117 int i = 0;
118
120
122 ast_free(auth->password_digests[i]);
123 }
124
127}
#define ast_free(a)
Definition: astmm.h:180
@ PJSIP_AUTH_ALGORITHM_COUNT
Definition: res_pjsip.h:613
@ PJSIP_AUTH_ALGORITHM_NOT_SET
Definition: res_pjsip.h:608
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
Definition: stringfields.h:374

References ast_free, ast_string_field_free_memory, AST_VECTOR_FREE, ast_sip_auth::password_digests, PJSIP_AUTH_ALGORITHM_COUNT, PJSIP_AUTH_ALGORITHM_NOT_SET, ast_sip_auth::supported_algorithms_uac, and ast_sip_auth::supported_algorithms_uas.

Referenced by auth_alloc().

◆ auth_type_handler()

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

Definition at line 148 of file config_auth.c.

149{
150 struct ast_sip_auth *auth = obj;
151 if (!strcasecmp(var->value, "userpass")) {
153 } else if (!strcasecmp(var->value, "md5")) {
155 } else if (!strcasecmp(var->value, "digest")) {
157 } else if (!strcasecmp(var->value, "google_oauth")) {
158#ifdef HAVE_PJSIP_OAUTH_AUTHENTICATION
160#else
161 ast_log(LOG_WARNING, "OAuth support is not available in the version of PJSIP in use\n");
162 return -1;
163#endif
164 } else {
165 ast_log(LOG_WARNING, "Unknown authentication storage type '%s' specified for %s\n",
166 var->value, var->name);
167 return -1;
168 }
169 return 0;
170}
#define var
Definition: ast_expr2f.c:605
@ AST_SIP_AUTH_TYPE_DIGEST
Definition: res_pjsip.h:587
@ AST_SIP_AUTH_TYPE_MD5
Definition: res_pjsip.h:581
@ AST_SIP_AUTH_TYPE_USER_PASS
Definition: res_pjsip.h:576

References ast_log, AST_SIP_AUTH_TYPE_DIGEST, AST_SIP_AUTH_TYPE_GOOGLE_OAUTH, AST_SIP_AUTH_TYPE_MD5, AST_SIP_AUTH_TYPE_USER_PASS, LOG_WARNING, ast_sip_auth::type, and var.

Referenced by ast_sip_initialize_sorcery_auth().

◆ auth_type_to_str()

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

Definition at line 185 of file config_auth.c.

186{
187 const struct ast_sip_auth *auth = obj;
189 return 0;
190}
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:179

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

Referenced by ast_sip_initialize_sorcery_auth().

◆ check_algorithm()

static int check_algorithm ( const struct ast_sip_auth auth,
const pjsip_auth_algorithm_type  algorithm_type,
const char *  which_supported 
)
static

Definition at line 422 of file config_auth.c.

424{
425 const pjsip_auth_algorithm *algo = ast_sip_auth_get_algorithm_by_type(algorithm_type);
426 struct ast_sip_auth_password_digest *pw_digest =
428
429 if (!pw_digest && ast_strlen_zero(auth->auth_pass)) {
430 ast_log(LOG_ERROR, "%s: No plain text or digest password found for algorithm "
431 PJSTR_PRINTF_SPEC " in supported_algorithms_%s\n",
432 ast_sorcery_object_get_id(auth), PJSTR_PRINTF_VAR(algo->iana_name), which_supported);
433 return -1;
434 }
435
436 return 0;
437}

References ast_sip_auth_password_digest::algorithm_type, ast_log, ast_sip_auth_get_algorithm_by_type(), ast_sorcery_object_get_id(), ast_strlen_zero(), ast_sip_auth::auth_pass, pjsip_auth_algorithm::iana_name, LOG_ERROR, ast_sip_auth::password_digests, PJSTR_PRINTF_SPEC, and PJSTR_PRINTF_VAR.

Referenced by auth_apply().

◆ cli_get_auths()

static struct ao2_container * cli_get_auths ( void  )
static

Definition at line 565 of file config_auth.c.

566{
567 struct ao2_container *auths;
568
571
572 return auths;
573}
@ AST_RETRIEVE_FLAG_MULTIPLE
Return all matching objects.
Definition: sorcery.h:120
@ AST_RETRIEVE_FLAG_ALL
Perform no matching, return all objects.
Definition: sorcery.h:123
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

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().

◆ cli_get_container()

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

Definition at line 626 of file config_auth.c.

627{
629 struct ao2_container *s_container;
630
632 if (!container) {
633 return NULL;
634 }
635
638 if (!s_container) {
639 return NULL;
640 }
641
642 if (ao2_container_dup(s_container, container, 0)) {
643 ao2_ref(s_container, -1);
644 return NULL;
645 }
646
647 return s_container;
648}
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.
@ AO2_ALLOC_OPT_LOCK_NOLOCK
Definition: astobj2.h:367
#define ao2_container_alloc_list(ao2_options, container_options, sort_fn, cmp_fn)
Allocate and initialize a list container.
Definition: astobj2.h:1327
static int regex(struct ast_channel *chan, const char *cmd, char *parse, char *buf, size_t len)
struct ao2_container * container
Definition: res_fax.c:531
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:1954
int ast_sorcery_object_id_compare(void *obj, void *arg, int flags)
ao2 object comparator based on sorcery id.
Definition: sorcery.c:2464
int ast_sorcery_object_id_sort(const void *obj, const void *arg, int flags)
ao2 object sorter based on sorcery id.
Definition: sorcery.c:2440

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, RAII_VAR, and regex().

Referenced by ast_sip_initialize_sorcery_auth().

◆ cli_iterator()

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

Definition at line 650 of file config_auth.c.

651{
653}
static struct ast_channel * callback(struct ast_channelstorage_instance *driver, ao2_callback_data_fn *cb_fn, void *arg, void *data, int ao2_flags)
const char * args

References args, ast_sip_for_each_auth(), callback(), and container.

Referenced by ast_sip_initialize_sorcery_auth().

◆ cli_print_body()

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

Definition at line 675 of file config_auth.c.

676{
677 struct ast_sip_auth *auth = obj;
678 struct ast_sip_cli_context *context = arg;
679 char title[32];
680
681 ast_assert(context->output_buffer != NULL);
682
683 snprintf(title, sizeof(title), "%sAuth",
684 context->auth_direction ? context->auth_direction : "");
685
686 ast_str_append(&context->output_buffer, 0, "%*s: %s/%s\n",
687 CLI_INDENT_TO_SPACES(context->indent_level), title,
689
690 if (context->show_details
691 || (context->show_details_only_level_0 && context->indent_level == 0)) {
692 ast_str_append(&context->output_buffer, 0, "\n");
694 }
695
696 return 0;
697}
int ast_sip_cli_print_sorcery_objectset(void *obj, void *arg, int flags)
Prints a sorcery object's ast_variable list.
Definition: pjsip_cli.c:36
#define CLI_INDENT_TO_SPACES(x)
Definition: res_pjsip_cli.h:29
CLI Formatter Context passed to all formatters.
Definition: res_pjsip_cli.h:34

References ast_assert, ast_sip_cli_print_sorcery_objectset(), ast_sorcery_object_get_id(), ast_str_append(), ast_sip_auth::auth_user, CLI_INDENT_TO_SPACES, voicemailpwcheck::context, and NULL.

Referenced by ast_sip_initialize_sorcery_auth().

◆ cli_print_header()

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

Definition at line 660 of file config_auth.c.

661{
662 struct ast_sip_cli_context *context = arg;
663 int indent = CLI_INDENT_TO_SPACES(context->indent_level);
664 int filler = CLI_MAX_WIDTH - indent - 20;
665
666 ast_assert(context->output_buffer != NULL);
667
668 ast_str_append(&context->output_buffer, 0,
669 "%*s: <AuthId/UserName%*.*s>\n", indent, "I/OAuth", filler, filler,
671
672 return 0;
673}
#define CLI_HEADER_FILLER
Definition: res_pjsip_cli.h:24
#define CLI_MAX_WIDTH
Definition: res_pjsip_cli.h:26

References ast_assert, ast_str_append(), CLI_HEADER_FILLER, CLI_INDENT_TO_SPACES, CLI_MAX_WIDTH, voicemailpwcheck::context, and NULL.

Referenced by ast_sip_initialize_sorcery_auth().

◆ cli_retrieve_by_id()

static void * cli_retrieve_by_id ( const char *  id)
static

◆ format_ami_auth_handler()

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

Definition at line 517 of file config_auth.c.

518{
519 const struct ast_sip_auth *auth = obj;
520 struct ast_sip_ami *ami = arg;
521 const struct ast_sip_endpoint *endpoint = ami->arg;
522 RAII_VAR(struct ast_str *, buf,
523 ast_sip_create_ami_event("AuthDetail", ami), ast_free);
524
525 if (!buf) {
526 return -1;
527 }
528
529 if (sip_auth_to_ami(auth, &buf)) {
530 return -1;
531 }
532
533 if (endpoint) {
534 ast_str_append(&buf, 0, "EndpointName: %s\r\n",
535 ast_sorcery_object_get_id(endpoint));
536 }
537
538 astman_append(ami->s, "%s\r\n", ast_str_buffer(buf));
539 ami->count++;
540
541 return 0;
542}
static int sip_auth_to_ami(const struct ast_sip_auth *auth, struct ast_str **buf)
Definition: config_auth.c:511
void astman_append(struct mansession *s, const char *fmt,...)
Definition: manager.c:1907
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.
void * arg
Definition: res_pjsip.h:3208
An entity with which Asterisk communicates.
Definition: res_pjsip.h:1051

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().

◆ format_ami_authlist_handler()

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

Definition at line 575 of file config_auth.c.

576{
577 struct ast_sip_auth *auth = obj;
578 struct ast_sip_ami *ami = arg;
579 struct ast_str *buf;
580
581 buf = ast_sip_create_ami_event("AuthList", ami);
582 if (!buf) {
583 return CMP_STOP;
584 }
585
586 sip_auth_to_ami(auth, &buf);
587
588 astman_append(ami->s, "%s\r\n", ast_str_buffer(buf));
589 ami->count++;
590
591 ast_free(buf);
592
593 return 0;
594}
@ CMP_STOP
Definition: astobj2.h:1028

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().

◆ 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 550 of file config_auth.c.

552{
553 ami->arg = (void *)endpoint;
554 if (ast_sip_format_auths_ami(&endpoint->inbound_auths, ami)) {
555 return -1;
556 }
557
558 return ast_sip_format_auths_ami(&endpoint->outbound_auths, ami);
559}
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:544
struct ast_sip_auth_vector outbound_auths
Definition: res_pjsip.h:1098
struct ast_sip_auth_vector inbound_auths
Definition: res_pjsip.h:1096

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

◆ global_loaded()

static void global_loaded ( const char *  object_type)
static

Definition at line 718 of file config_auth.c.

719{
721}
void ast_sorcery_force_reload_object(const struct ast_sorcery *sorcery, const char *type)
Inform any wizards of a specific object type to reload persistent objects even if no changes determin...
Definition: sorcery.c:1457

References ast_sip_get_sorcery(), and ast_sorcery_force_reload_object().

◆ md5cred_to_str()

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

Definition at line 375 of file config_auth.c.

376{
377 const struct ast_sip_auth *auth = obj;
378
381 }
382
383 return 0;
384}

References ast_strdup, buf, ast_sip_auth_password_digest::digest, ast_sip_auth::password_digests, and PJSIP_AUTH_ALGORITHM_MD5.

Referenced by ast_sip_initialize_sorcery_auth().

◆ password_digest_handler()

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

Definition at line 287 of file config_auth.c.

288{
289 struct ast_sip_auth *auth = obj;
290 const char *auth_name = ast_sorcery_object_get_id(auth);
291 char *value = ast_strdupa(var->value);
292 char *unparsed_digest = NULL;
293
294 while ((unparsed_digest = ast_strsep(&value, ',', AST_STRSEP_TRIM))) {
295 const pjsip_auth_algorithm *algo;
296 char *iana_name;
297 char *digest;
299 pj_str_t pj_iana_name;
300
301 if (ast_strlen_zero(unparsed_digest)) {
302 continue;
303 }
304
305 if (strchr(unparsed_digest, ':') != NULL) {
306 iana_name = ast_strsep(&unparsed_digest, ':', AST_STRSEP_TRIM);
307 } else {
308 /*
309 * md5_cred doesn't have the algorithm name in front
310 * so we need to force it.
311 */
312 iana_name = "MD5";
313 }
314 digest = unparsed_digest;
315
316 pj_iana_name = pj_str(iana_name);
317
318 algo = ast_sip_auth_get_algorithm_by_iana_name(&pj_iana_name);
319 if (!algo) {
320 ast_log(LOG_WARNING, "%s: Unknown password_digest algorithm '%s' specified\n",
321 auth_name, iana_name);
322 return -1;
323 }
325 ast_log(LOG_WARNING, "%s: password_digest algorithm '%s' is not supported by the version of OpenSSL in use\n",
326 auth_name, iana_name);
327 return -1;
328 }
329 if (strlen(digest) != algo->digest_str_length) {
330 ast_log(LOG_WARNING, "%s: password_digest algorithm '%s' length (%d) must be %d\n",
331 auth_name, iana_name, (int)strlen(digest), (int)algo->digest_str_length);
332 return -1;
333 }
334
335 pw = ast_calloc(1, sizeof(*pw) + strlen(digest) + 1);
336 if (!pw) {
337 return -1;
338 }
339 pw->algorithm_type = algo->algorithm_type;
340 strcpy(pw->digest, digest); /* Safe */
341 auth->password_digests[pw->algorithm_type] = pw;
342 }
343
344 return 0;
345}
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:202
@ AST_STRSEP_TRIM
Definition: strings.h:256
char * ast_strsep(char **s, const char sep, uint32_t flags)
Act like strsep but ignore separators inside quotes.
Definition: utils.c:1835
unsigned digest_str_length
Definition: res_pjsip.h:622

References pjsip_auth_algorithm::algorithm_type, ast_sip_auth_password_digest::algorithm_type, ast_calloc, ast_log, ast_sip_auth_get_algorithm_by_iana_name(), ast_sip_auth_is_algorithm_supported(), ast_sorcery_object_get_id(), ast_strdupa, ast_strlen_zero(), ast_strsep(), AST_STRSEP_TRIM, ast_sip_auth_password_digest::digest, pjsip_auth_algorithm::digest_str_length, LOG_WARNING, NULL, ast_sip_auth::password_digests, value, and var.

Referenced by ast_sip_initialize_sorcery_auth().

◆ password_digest_to_str()

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

Definition at line 347 of file config_auth.c.

348{
349 const struct ast_sip_auth *auth = obj;
350 struct ast_str *str = ast_str_alloca(256);
351 int i = 0;
352 int count = 0;
353
356 auth->password_digests[i];
357 const pjsip_auth_algorithm *algorithm;
358
359 if (!pw) {
360 continue;
361 }
362
364
365 ast_str_append(&str, 0, "%s" PJSTR_PRINTF_SPEC ":%s", count > 0 ? "," : "",
366 PJSTR_PRINTF_VAR(algorithm->iana_name), pw->digest);
367 count++;
368 }
369
371
372 return 0;
373}

References ast_sip_auth_password_digest::algorithm_type, ast_sip_auth_get_algorithm_by_type(), ast_str_alloca, ast_str_append(), ast_str_buffer(), ast_strdup, buf, ast_sip_auth_password_digest::digest, pjsip_auth_algorithm::iana_name, ast_sip_auth::password_digests, PJSIP_AUTH_ALGORITHM_COUNT, PJSIP_AUTH_ALGORITHM_NOT_SET, PJSTR_PRINTF_SPEC, PJSTR_PRINTF_VAR, and str.

Referenced by ast_sip_initialize_sorcery_auth().

◆ sip_auth_to_ami()

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

Definition at line 511 of file config_auth.c.

513{
515}
int ast_sip_sorcery_object_to_ami(const void *obj, struct ast_str **buf)
Converts a sorcery object to a string of object properties.

References ast_sip_sorcery_object_to_ami(), and buf.

Referenced by format_ami_auth_handler(), and format_ami_authlist_handler().

◆ uac_algorithms_handler()

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

◆ uac_algorithms_to_str()

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

Definition at line 275 of file config_auth.c.

276{
277 const struct ast_sip_auth *auth = obj;
279}
int ast_sip_auth_digest_algorithms_vector_to_str(const struct pjsip_auth_algorithm_type_vector *algorithms, char **buf)
Dump a vector of algorithm types to a string.
Definition: config_auth.c:248

References ast_sip_auth_digest_algorithms_vector_to_str(), buf, and ast_sip_auth::supported_algorithms_uac.

Referenced by ast_sip_initialize_sorcery_auth().

◆ uas_algorithms_handler()

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

◆ uas_algorithms_to_str()

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

Variable Documentation

◆ auth_types_map

const char* auth_types_map[]
static

Definition at line 172 of file config_auth.c.

Referenced by ast_sip_auth_type_to_str().

◆ cli_commands

struct ast_cli_entry cli_commands[]
static

Definition at line 699 of file config_auth.c.

Referenced by ast_sip_destroy_sorcery_auth(), and ast_sip_initialize_sorcery_auth().

◆ cli_formatter

struct ast_sip_cli_formatter_entry* cli_formatter
static

Definition at line 716 of file config_auth.c.

Referenced by ast_sip_destroy_sorcery_auth(), and ast_sip_initialize_sorcery_auth().

◆ 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:550

Definition at line 561 of file config_auth.c.

Referenced by ast_sip_destroy_sorcery_auth(), and ast_sip_initialize_sorcery_auth().

◆ global_observer

struct ast_sorcery_observer global_observer
static
Initial value:
= {
.loaded = global_loaded,
}
static void global_loaded(const char *object_type)
Definition: config_auth.c:718

Observer which is used to update our interval and default_realm when the global setting changes.

Definition at line 724 of file config_auth.c.

Referenced by ast_sip_destroy_sorcery_auth(), and ast_sip_initialize_sorcery_auth().

◆ pjsip_auth_algorithms

const pjsip_auth_algorithm pjsip_auth_algorithms[]