Asterisk - The Open Source Telephony Project GIT-master-754dea3
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Modules Pages
config_auth.c
Go to the documentation of this file.
1/*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 2013, Digium, Inc.
5 *
6 * Mark Michelson <mmichelson@digium.com>
7 *
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
13 *
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
17 */
18
19#include "asterisk.h"
20
21#include <pjsip.h>
22#include <pjlib.h>
23#include "asterisk/res_pjsip.h"
24#include "asterisk/logger.h"
25#include "asterisk/sorcery.h"
26#include "asterisk/cli.h"
27#include "asterisk/vector.h"
30
31#ifndef HAVE_PJSIP_AUTH_NEW_DIGESTS
32/*
33 * These are needed if the version of pjproject in use
34 * does not have the new digests.
35 * NOTE: We don't support AKA but we need to specify
36 * it to be compatible with the pjproject definition.
37 */
38#ifdef HAVE_OPENSSL
39#include "openssl/md5.h"
40#include "openssl/sha.h"
41#else
42#define MD5_DIGEST_LENGTH 16
43#define SHA256_DIGEST_LENGTH 32
44#endif
45
47/* TYPE IANA name OpenSSL name */
48/* Raw digest byte length Hex representation length */
49 { PJSIP_AUTH_ALGORITHM_NOT_SET, {"", 0}, "",
50 0, 0},
51 { PJSIP_AUTH_ALGORITHM_MD5, {"MD5", 3}, "MD5",
53 { PJSIP_AUTH_ALGORITHM_SHA256, {"SHA-256", 7}, "SHA256",
55 { PJSIP_AUTH_ALGORITHM_SHA512_256, {"SHA-512-256", 11}, "SHA512-256",
57 { PJSIP_AUTH_ALGORITHM_AKAV1_MD5, {"AKAv1-MD5", 9}, "",
59 { PJSIP_AUTH_ALGORITHM_AKAV1_MD5, {"AKAv2-MD5", 9}, "",
61 { PJSIP_AUTH_ALGORITHM_COUNT, {"", 0}, "",
62 0, 0},
63};
64#endif
65
67 pjsip_auth_algorithm_type algorithm_type)
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}
82
84 const pj_str_t *iana_name)
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}
103
105 pjsip_auth_algorithm_type algorithm_type)
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}
113
114static void auth_destroy(void *obj)
115{
116 struct ast_sip_auth *auth = obj;
117 int i = 0;
118
120
122 ast_free(auth->password_digests[i]);
123 }
124
127}
128
129static void *auth_alloc(const char *name)
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}
147
148static int auth_type_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
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}
171
172static const char *auth_types_map[] = {
173 [AST_SIP_AUTH_TYPE_USER_PASS] = "userpass",
174 [AST_SIP_AUTH_TYPE_MD5] = "md5",
175 [AST_SIP_AUTH_TYPE_DIGEST] = "digest",
176 [AST_SIP_AUTH_TYPE_GOOGLE_OAUTH] = "google_oauth"
177};
178
180{
182 auth_types_map[type] : "";
183}
184
185static int auth_type_to_str(const void *obj, const intptr_t *args, char **buf)
186{
187 const struct ast_sip_auth *auth = obj;
189 return 0;
190}
191
193 struct pjsip_auth_algorithm_type_vector *algorithms, const char *agent_type,
194 const char *value)
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}
231
232static int uac_algorithms_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
233{
234 struct ast_sip_auth *auth = obj;
235
237 &auth->supported_algorithms_uac, "UAC", var->value);
238}
239
240static int uas_algorithms_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
241{
242 struct ast_sip_auth *auth = obj;
243
245 &auth->supported_algorithms_uas, "UAS", var->value);
246}
247
249 const struct pjsip_auth_algorithm_type_vector *algorithms, char **buf)
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}
274
275static int uac_algorithms_to_str(const void *obj, const intptr_t *args, char **buf)
276{
277 const struct ast_sip_auth *auth = obj;
279}
280
281static int uas_algorithms_to_str(const void *obj, const intptr_t *args, char **buf)
282{
283 const struct ast_sip_auth *auth = obj;
285}
286
287static int password_digest_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
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}
346
347static int password_digest_to_str(const void *obj, const intptr_t *args, char **buf)
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}
374
375static int md5cred_to_str(const void *obj, const intptr_t *args, char **buf)
376{
377 const struct ast_sip_auth *auth = obj;
378
381 }
382
383 return 0;
384}
385
387 const struct pjsip_auth_algorithm_type_vector *algorithms,
388 pjsip_auth_algorithm_type algorithm_type)
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}
406
407const char *ast_sip_auth_get_creds(const struct ast_sip_auth *auth,
408 const pjsip_auth_algorithm_type algorithm_type, int *cred_type)
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}
421
422static int check_algorithm(const struct ast_sip_auth *auth,
423 const pjsip_auth_algorithm_type algorithm_type, const char *which_supported)
424{
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}
438
439static int auth_apply(const struct ast_sorcery *sorcery, void *obj)
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}
483
485 ao2_callback_fn on_auth, void *arg)
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}
510
511static int sip_auth_to_ami(const struct ast_sip_auth *auth,
512 struct ast_str **buf)
513{
515}
516
517static int format_ami_auth_handler(void *obj, void *arg, int flags)
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}
543
545 struct ast_sip_ami *ami)
546{
548}
549
550static int format_ami_endpoint_auth(const struct ast_sip_endpoint *endpoint,
551 struct ast_sip_ami *ami)
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}
560
563};
564
565static struct ao2_container *cli_get_auths(void)
566{
567 struct ao2_container *auths;
568
571
572 return auths;
573}
574
575static int format_ami_authlist_handler(void *obj, void *arg, int flags)
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}
595
596static int ami_show_auths(struct mansession *s, const struct message *m)
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}
625
626static struct ao2_container *cli_get_container(const char *regex)
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}
649
650static int cli_iterator(void *container, ao2_callback_fn callback, void *args)
651{
652 return ast_sip_for_each_auth(container, callback, args);
653}
654
655static void *cli_retrieve_by_id(const char *id)
656{
658}
659
660static int cli_print_header(void *obj, void *arg, int flags)
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}
674
675static int cli_print_body(void *obj, void *arg, int flags)
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}
698
699static struct ast_cli_entry cli_commands[] = {
701 .command = "pjsip list auths",
702 .usage = "Usage: pjsip list auths [ like <pattern> ]\n"
703 " List the configured PJSIP Auths\n"
704 " Optional regular expression pattern is used to filter the list.\n"),
706 .command = "pjsip show auths",
707 .usage = "Usage: pjsip show auths [ like <pattern> ]\n"
708 " Show the configured PJSIP Auths\n"
709 " Optional regular expression pattern is used to filter the list.\n"),
711 .command = "pjsip show auth",
712 .usage = "Usage: pjsip show auth <id>\n"
713 " Show the configured PJSIP Auth\n"),
714};
715
717
718static void global_loaded(const char *object_type)
719{
721}
722
723/*! \brief Observer which is used to update our interval and default_realm when the global setting changes */
726};
727
728/*! \brief Initialize sorcery with auth support */
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}
791
793{
795
799
800 ast_manager_unregister("PJSIPShowAuths");
801
802 return 0;
803}
static struct aco_type agent_type
const char * str
Definition: app_jack.c:150
#define var
Definition: ast_expr2f.c:605
char * strsep(char **str, const char *delims)
Asterisk main include file. File version handling, generic pbx functions.
#define ast_alloca(size)
call __builtin_alloca to ensure we get gcc builtin semantics
Definition: astmm.h:288
#define ast_free(a)
Definition: astmm.h:180
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:241
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:298
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:202
#define ast_log
Definition: astobj2.c:42
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.
@ CMP_STOP
Definition: astobj2.h:1028
@ AO2_ALLOC_OPT_LOCK_NOLOCK
Definition: astobj2.h:367
#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_cleanup(obj)
Definition: astobj2.h:1934
int() ao2_callback_fn(void *obj, void *arg, int flags)
Type of a generic callback function.
Definition: astobj2.h:1226
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
@ OBJ_NODATA
Definition: astobj2.h:1044
#define ao2_container_alloc_list(ao2_options, container_options, sort_fn, cmp_fn)
Allocate and initialize a list container.
Definition: astobj2.h:1327
#define ao2_alloc(data_size, destructor_fn)
Definition: astobj2.h:409
static const char type[]
Definition: chan_ooh323.c:109
Standard Command Line Interface.
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
Definition: clicompat.c:30
#define AST_CLI_DEFINE(fn, txt,...)
Definition: cli.h:197
#define ast_cli_register_multiple(e, len)
Register multiple commands.
Definition: cli.h:265
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
#define MD5_DIGEST_LENGTH
Definition: config_auth.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
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
static struct ast_cli_entry cli_commands[]
Definition: config_auth.c:699
static void global_loaded(const char *object_type)
Definition: config_auth.c:718
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
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
static int sip_auth_to_ami(const struct ast_sip_auth *auth, struct ast_str **buf)
Definition: config_auth.c:511
static const char * auth_types_map[]
Definition: config_auth.c:172
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 format_ami_authlist_handler(void *obj, void *arg, int flags)
Definition: config_auth.c:575
static struct ast_sip_endpoint_formatter endpoint_auth_formatter
Definition: config_auth.c:561
static int password_digest_to_str(const void *obj, const intptr_t *args, char **buf)
Definition: config_auth.c:347
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
static void * auth_alloc(const char *name)
Definition: config_auth.c:129
static struct ao2_container * cli_get_auths(void)
Definition: config_auth.c:565
static int format_ami_auth_handler(void *obj, void *arg, int flags)
Definition: config_auth.c:517
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
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
#define SHA256_DIGEST_LENGTH
Definition: config_auth.c:43
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 format_ami_endpoint_auth(const struct ast_sip_endpoint *endpoint, struct ast_sip_ami *ami)
Definition: config_auth.c:550
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
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
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.
Definition: config_auth.c:407
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.
Definition: config_auth.c:386
static int auth_type_to_str(const void *obj, const intptr_t *args, char **buf)
Definition: config_auth.c:185
int ast_sip_destroy_sorcery_auth(void)
Definition: config_auth.c:792
const pjsip_auth_algorithm pjsip_auth_algorithms[]
Definition: config_auth.c:46
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
static struct ast_sip_cli_formatter_entry * cli_formatter
Definition: config_auth.c:716
static int uac_algorithms_to_str(const void *obj, const intptr_t *args, char **buf)
Definition: config_auth.c:275
int ast_sip_initialize_sorcery_auth(void)
Initialize sorcery with auth support.
Definition: config_auth.c:729
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
static void auth_destroy(void *obj)
Definition: config_auth.c:114
#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.
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
static const char name[]
Definition: format_mp3.c:68
static int regex(struct ast_channel *chan, const char *cmd, char *parse, char *buf, size_t len)
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
void astman_append(struct mansession *s, const char *fmt,...)
Definition: manager.c:1907
int ast_manager_unregister(const char *action)
Unregister a registered manager command.
Definition: manager.c:7697
Support for logging to various files, console and syslog Configuration in file logger....
#define LOG_ERROR
#define LOG_WARNING
#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
struct ao2_container * container
Definition: res_fax.c:531
pjsip_auth_algorithm_type
Definition: res_pjsip.h:607
@ PJSIP_AUTH_ALGORITHM_COUNT
Definition: res_pjsip.h:613
@ PJSIP_AUTH_ALGORITHM_AKAV1_MD5
Definition: res_pjsip.h:612
@ PJSIP_AUTH_ALGORITHM_NOT_SET
Definition: res_pjsip.h:608
@ PJSIP_AUTH_ALGORITHM_SHA512_256
Definition: res_pjsip.h:611
@ PJSIP_AUTH_ALGORITHM_SHA256
Definition: res_pjsip.h:610
@ PJSIP_AUTH_ALGORITHM_MD5
Definition: res_pjsip.h:609
void ast_sip_register_endpoint_formatter(struct ast_sip_endpoint_formatter *obj)
Register an endpoint formatter.
Definition: res_pjsip.c:481
void ast_sip_unregister_endpoint_formatter(struct ast_sip_endpoint_formatter *obj)
Unregister an endpoint formatter.
Definition: res_pjsip.c:487
int ast_sip_sorcery_object_to_ami(const void *obj, struct ast_str **buf)
Converts a sorcery object to a string of object properties.
ast_sip_auth_type
Authentication methods.
Definition: res_pjsip.h:570
@ AST_SIP_AUTH_TYPE_GOOGLE_OAUTH
Definition: res_pjsip.h:583
@ 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
#define AST_SIP_AUTH_MAX_SUPPORTED_ALGORITHMS_LENGTH
Definition: res_pjsip.h:75
#define SIP_SORCERY_AUTH_TYPE
Definition: res_pjsip.h:597
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.
struct ast_sorcery * ast_sip_get_sorcery(void)
Get a pointer to the SIP sorcery structure.
#define PJSTR_PRINTF_VAR(_v)
Definition: res_pjsip.h:72
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.
#define PJSTR_PRINTF_SPEC
Definition: res_pjsip.h:71
int ast_sip_unregister_cli_formatter(struct ast_sip_cli_formatter_entry *formatter)
Unregisters a CLI formatter.
Definition: pjsip_cli.c:326
#define CLI_HEADER_FILLER
Definition: res_pjsip_cli.h:24
#define CLI_MAX_WIDTH
Definition: res_pjsip_cli.h:26
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
char * ast_sip_cli_traverse_objects(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
Definition: pjsip_cli.c:109
#define CLI_INDENT_TO_SPACES(x)
Definition: res_pjsip_cli.h:29
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
#define NULL
Definition: resample.c:96
Sorcery Data Access Layer API.
const char * ast_sorcery_object_get_id(const void *object)
Get the unique identifier of a sorcery object.
Definition: sorcery.c:2317
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
@ 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_id(const struct ast_sorcery *sorcery, const char *type, const char *id)
Retrieve an object using its unique identifier.
Definition: sorcery.c:1853
#define ast_sorcery_object_register(sorcery, type, alloc, transform, apply)
Register an object type.
Definition: sorcery.h:837
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_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
void * ast_sorcery_generic_alloc(size_t size, ao2_destructor_fn destructor)
Allocate a generic sorcery capable object.
Definition: sorcery.c:1728
int ast_sorcery_object_id_compare(void *obj, void *arg, int flags)
ao2 object comparator based on sorcery id.
Definition: sorcery.c:2464
#define ast_sorcery_object_field_register(sorcery, type, name, default_val, opt_type, flags,...)
Register a field within an object.
Definition: sorcery.h:955
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
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
#define ast_sorcery_apply_default(sorcery, type, name, data)
Definition: sorcery.h:476
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
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
Definition: stringfields.h:359
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
Definition: stringfields.h:374
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
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
@ AST_STRSEP_TRIM
Definition: strings.h:256
#define ast_str_alloca(init_len)
Definition: strings.h:848
char * ast_strip(char *s)
Strip leading/trailing whitespace from a string.
Definition: strings.h:223
char * ast_strsep(char **s, const char sep, uint32_t flags)
Act like strsep but ignore separators inside quotes.
Definition: utils.c:1835
Generic container type.
descriptor for a cli entry.
Definition: cli.h:171
char * command
Definition: cli.h:186
AMI variable container.
Definition: res_pjsip.h:3200
struct mansession * s
Definition: res_pjsip.h:3202
void * arg
Definition: res_pjsip.h:3208
const struct message * m
Definition: res_pjsip.h:3204
pjsip_auth_algorithm_type algorithm_type
Definition: res_pjsip.h:656
struct pjsip_auth_algorithm_type_vector supported_algorithms_uac
Definition: res_pjsip.h:687
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
struct ast_sip_auth_password_digest * password_digests[PJSIP_AUTH_ALGORITHM_COUNT]
Definition: res_pjsip.h:691
struct pjsip_auth_algorithm_type_vector supported_algorithms_uas
Definition: res_pjsip.h:689
const ast_string_field refresh_token
Definition: res_pjsip.h:681
const ast_string_field auth_pass
Definition: res_pjsip.h:681
enum ast_sip_auth_type type
Definition: res_pjsip.h:685
CLI Formatter Context passed to all formatters.
Definition: res_pjsip_cli.h:34
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
An entity responsible formatting endpoint information.
Definition: res_pjsip.h:3226
int(* format_ami)(const struct ast_sip_endpoint *endpoint, struct ast_sip_ami *ami)
Callback used to format endpoint information over AMI.
Definition: res_pjsip.h:3230
An entity with which Asterisk communicates.
Definition: res_pjsip.h:1051
struct ast_sip_auth_vector outbound_auths
Definition: res_pjsip.h:1098
struct ast_sip_auth_vector inbound_auths
Definition: res_pjsip.h:1096
Interface for a sorcery object type observer.
Definition: sorcery.h:332
void(* loaded)(const char *object_type)
Callback for when an object type is loaded/reloaded.
Definition: sorcery.h:343
Full structure for sorcery.
Definition: sorcery.c:230
Support for dynamic strings.
Definition: strings.h:623
Structure for variables, used for configurations and for channel variables.
In case you didn't read that giant block of text above the mansession_session struct,...
Definition: manager.c:327
pjsip_auth_algorithm_type algorithm_type
Definition: res_pjsip.h:618
unsigned digest_str_length
Definition: res_pjsip.h:622
Definition: ast_expr2.c:325
int value
Definition: syslog.c:37
const char * args
char * usage
Definition: utils/frame.c:37
#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
#define ast_assert(a)
Definition: utils.h:739
#define ARRAY_IN_BOUNDS(v, a)
Checks to see if value is within the bounds of the given array.
Definition: utils.h:687
#define ARRAY_LEN(a)
Definition: utils.h:666
Vector container support.
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
Definition: vector.h:609
#define AST_VECTOR_FREE(vec)
Deallocates this vector.
Definition: vector.h:174
#define AST_VECTOR_INIT(vec, size)
Initialize a vector.
Definition: vector.h:113
#define AST_VECTOR_APPEND(vec, elem)
Append an element to a vector, growing the vector if needed.
Definition: vector.h:256
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
Definition: vector.h:680