Merge "res_pjsip: Update artificial auth whenever default_realm changes."

changes/58/5058/1
zuul 8 years ago committed by Gerrit Code Review
commit 1774f778f6

@ -43,7 +43,6 @@ struct ast_sched_context *prune_context;
/* From the auth/realm realtime column size */ /* From the auth/realm realtime column size */
#define MAX_REALM_LENGTH 40 #define MAX_REALM_LENGTH 40
static char default_realm[MAX_REALM_LENGTH + 1];
#define DEFAULT_SUSPECTS_BUCKETS 53 #define DEFAULT_SUSPECTS_BUCKETS 53
@ -455,35 +454,54 @@ static pj_bool_t distributor(pjsip_rx_data *rdata)
return PJ_TRUE; return PJ_TRUE;
} }
static struct ast_sip_auth *artificial_auth; static struct ast_sip_auth *alloc_artificial_auth(char *default_realm)
{
struct ast_sip_auth *fake_auth;
fake_auth = ast_sorcery_alloc(ast_sip_get_sorcery(), SIP_SORCERY_AUTH_TYPE,
"artificial");
if (!fake_auth) {
return NULL;
}
ast_string_field_set(fake_auth, realm, default_realm);
ast_string_field_set(fake_auth, auth_user, "");
ast_string_field_set(fake_auth, auth_pass, "");
fake_auth->type = AST_SIP_AUTH_TYPE_ARTIFICIAL;
return fake_auth;
}
static AO2_GLOBAL_OBJ_STATIC(artificial_auth);
static int create_artificial_auth(void) static int create_artificial_auth(void)
{ {
if (!(artificial_auth = ast_sorcery_alloc( char default_realm[MAX_REALM_LENGTH + 1];
ast_sip_get_sorcery(), SIP_SORCERY_AUTH_TYPE, "artificial"))) { struct ast_sip_auth *fake_auth;
ast_sip_get_default_realm(default_realm, sizeof(default_realm));
fake_auth = alloc_artificial_auth(default_realm);
if (!fake_auth) {
ast_log(LOG_ERROR, "Unable to create artificial auth\n"); ast_log(LOG_ERROR, "Unable to create artificial auth\n");
return -1; return -1;
} }
ast_string_field_set(artificial_auth, realm, default_realm); ao2_global_obj_replace_unref(artificial_auth, fake_auth);
ast_string_field_set(artificial_auth, auth_user, ""); ao2_ref(fake_auth, -1);
ast_string_field_set(artificial_auth, auth_pass, "");
artificial_auth->type = AST_SIP_AUTH_TYPE_ARTIFICIAL;
return 0; return 0;
} }
struct ast_sip_auth *ast_sip_get_artificial_auth(void) struct ast_sip_auth *ast_sip_get_artificial_auth(void)
{ {
ao2_ref(artificial_auth, +1); return ao2_global_obj_ref(artificial_auth);
return artificial_auth;
} }
static struct ast_sip_endpoint *artificial_endpoint = NULL; static struct ast_sip_endpoint *artificial_endpoint = NULL;
static int create_artificial_endpoint(void) static int create_artificial_endpoint(void)
{ {
if (!(artificial_endpoint = ast_sorcery_alloc( artificial_endpoint = ast_sorcery_alloc(ast_sip_get_sorcery(), "endpoint", NULL);
ast_sip_get_sorcery(), "endpoint", NULL))) { if (!artificial_endpoint) {
return -1; return -1;
} }
@ -961,20 +979,40 @@ static int clean_task(const void *data)
static void global_loaded(const char *object_type) static void global_loaded(const char *object_type)
{ {
char *identifier_order = ast_sip_get_endpoint_identifier_order(); char default_realm[MAX_REALM_LENGTH + 1];
char *io_copy = identifier_order ? ast_strdupa(identifier_order) : NULL; struct ast_sip_auth *fake_auth;
char *identifier_order;
/* Update using_auth_username */
identifier_order = ast_sip_get_endpoint_identifier_order();
if (identifier_order) {
char *identify_method; char *identify_method;
char *io_copy = ast_strdupa(identifier_order);
int new_using = 0;
ast_free(identifier_order); ast_free(identifier_order);
using_auth_username = 0;
while ((identify_method = ast_strip(strsep(&io_copy, ",")))) { while ((identify_method = ast_strip(strsep(&io_copy, ",")))) {
if (!strcmp(identify_method, "auth_username")) { if (!strcmp(identify_method, "auth_username")) {
using_auth_username = 1; new_using = 1;
break; break;
} }
} }
using_auth_username = new_using;
}
/* Update default_realm of artificial_auth */
ast_sip_get_default_realm(default_realm, sizeof(default_realm)); ast_sip_get_default_realm(default_realm, sizeof(default_realm));
fake_auth = ast_sip_get_artificial_auth();
if (!fake_auth || strcmp(fake_auth->realm, default_realm)) {
ao2_cleanup(fake_auth);
fake_auth = alloc_artificial_auth(default_realm);
if (fake_auth) {
ao2_global_obj_replace_unref(artificial_auth, fake_auth);
ao2_ref(fake_auth, -1);
}
}
ast_sip_get_unidentified_request_thresholds(&unidentified_count, &unidentified_period, &unidentified_prune_interval); ast_sip_get_unidentified_request_thresholds(&unidentified_count, &unidentified_period, &unidentified_prune_interval);
/* Clean out the old task, if any */ /* Clean out the old task, if any */
@ -1107,7 +1145,7 @@ void ast_sip_destroy_distributor(void)
internal_sip_unregister_service(&endpoint_mod); internal_sip_unregister_service(&endpoint_mod);
internal_sip_unregister_service(&distributor_mod); internal_sip_unregister_service(&distributor_mod);
ao2_cleanup(artificial_auth); ao2_global_obj_release(artificial_auth);
ao2_cleanup(artificial_endpoint); ao2_cleanup(artificial_endpoint);
ast_sorcery_observer_remove(ast_sip_get_sorcery(), "global", &global_observer); ast_sorcery_observer_remove(ast_sip_get_sorcery(), "global", &global_observer);

Loading…
Cancel
Save