[svn-commits] mmichelson: branch mmichelson/authenticate r381215 - /team/mmichelson/authent...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Mon Feb 11 14:39:46 CST 2013


Author: mmichelson
Date: Mon Feb 11 14:39:43 2013
New Revision: 381215

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=381215
Log:
Reconstruct the entity ID on module reload.

I replaced the static character array with a global ao2 object.
I did this partially for thread-safety since the entity_id has
become more volatile than it once was. However, this also may
pave the way for entity-id rotation should we desire it.


Modified:
    team/mmichelson/authenticate/res/res_sip_authenticator_digest.c

Modified: team/mmichelson/authenticate/res/res_sip_authenticator_digest.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/authenticate/res/res_sip_authenticator_digest.c?view=diff&rev=381215&r1=381214&r2=381215
==============================================================================
--- team/mmichelson/authenticate/res/res_sip_authenticator_digest.c (original)
+++ team/mmichelson/authenticate/res/res_sip_authenticator_digest.c Mon Feb 11 14:39:43 2013
@@ -31,7 +31,7 @@
 	<support_level>core</support_level>
  ***/
 
-static char entity_id[AST_UUID_STR_LEN];
+AO2_GLOBAL_OBJ_STATIC(entity_id);
 
 /*!
  * \brief Determine if authentication is required
@@ -193,12 +193,13 @@
 static int build_nonce(struct ast_str **nonce, const char *timestamp, const pjsip_rx_data *rdata, const char *realm)
 {
 	struct ast_str *str = ast_str_create(64);
+	RAII_VAR(char *, eid, ao2_global_obj_ref(entity_id), ao2_cleanup);
 	char hash[32];
 
 	ast_str_append(&str, 0, "%s", timestamp);
 	ast_str_append(&str, 0, ":%s", rdata->pkt_info.src_name);
 	ast_str_append(&str, 0, ":%d", rdata->pkt_info.src_port);
-	ast_str_append(&str, 0, ":%s", entity_id);
+	ast_str_append(&str, 0, ":%s", eid);
 	ast_str_append(&str, 0, ":%s", realm);
 	ast_md5_hash(hash, ast_str_buffer(str));
 
@@ -430,12 +431,23 @@
 
 static int build_entity_id(void)
 {
-	struct ast_uuid *uu = ast_uuid_generate();
-	if (!uu) {
+	RAII_VAR(struct ast_uuid *, uu, ast_uuid_generate(), ast_free_ptr);
+	RAII_VAR(char *, eid, ao2_alloc(AST_UUID_STR_LEN, NULL), ao2_cleanup);
+
+	if (!uu || !eid) {
 		return -1;
 	}
-	ast_uuid_to_str(uu, entity_id, sizeof(entity_id));
-	ast_free(uu);
+
+	ast_uuid_to_str(uu, eid, sizeof(eid));
+	ao2_global_obj_replace_unref(entity_id, eid);
+	return 0;
+}
+
+static int reload_module(void)
+{
+	if (build_entity_id()) {
+		return -1;
+	}
 	return 0;
 }
 
@@ -445,6 +457,7 @@
 		return AST_MODULE_LOAD_DECLINE;
 	}
 	if (ast_sip_register_authenticator(&digest_authenticator)) {
+		ao2_global_obj_release(entity_id);
 		return AST_MODULE_LOAD_DECLINE;
 	}
 	return AST_MODULE_LOAD_SUCCESS;
@@ -453,11 +466,13 @@
 static int unload_module(void)
 {
 	ast_sip_unregister_authenticator(&digest_authenticator);
+	ao2_global_obj_release(entity_id);
 	return 0;
 }
 
 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "SIP authentication resource",
 		.load = load_module,
 		.unload = unload_module,
+		.reload = reload_module,
 		.load_pri = AST_MODPRI_CHANNEL_DEPEND,
 );




More information about the svn-commits mailing list