[asterisk-commits] mmichelson: branch mmichelson/authenticate r380833 - in /team/mmichelson/auth...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Feb 4 14:30:18 CST 2013


Author: mmichelson
Date: Mon Feb  4 14:30:16 2013
New Revision: 380833

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=380833
Log:
Add some verification to auth section handling.

This adds some integrity checking to auth handling after the
sorcery objectset has been applied.

In order to do this, I changed the sorcery API's apply handler
callback to return an int so that it is possible to indicate
a failure to apply. This meant having to change the two places
where an apply handler is used to return a failure result
if need be.


Modified:
    team/mmichelson/authenticate/include/asterisk/sorcery.h
    team/mmichelson/authenticate/main/sorcery.c
    team/mmichelson/authenticate/res/res_sip/config_transport.c
    team/mmichelson/authenticate/tests/test_sorcery.c

Modified: team/mmichelson/authenticate/include/asterisk/sorcery.h
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/authenticate/include/asterisk/sorcery.h?view=diff&rev=380833&r1=380832&r2=380833
==============================================================================
--- team/mmichelson/authenticate/include/asterisk/sorcery.h (original)
+++ team/mmichelson/authenticate/include/asterisk/sorcery.h Mon Feb  4 14:30:16 2013
@@ -148,8 +148,10 @@
  *
  * \param sorcery Sorcery structure in use
  * \param obj The object itself
- */
-typedef void (*sorcery_apply_handler)(const struct ast_sorcery *sorcery, void *obj);
+ * \retval 0 Success
+ * \retval non-zero Failure
+ */
+typedef int (*sorcery_apply_handler)(const struct ast_sorcery *sorcery, void *obj);
 
 /*! \brief Interface for a sorcery wizard */
 struct ast_sorcery_wizard {

Modified: team/mmichelson/authenticate/main/sorcery.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/authenticate/main/sorcery.c?view=diff&rev=380833&r1=380832&r2=380833
==============================================================================
--- team/mmichelson/authenticate/main/sorcery.c (original)
+++ team/mmichelson/authenticate/main/sorcery.c Mon Feb  4 14:30:16 2013
@@ -659,7 +659,7 @@
 	}
 
 	if (!res && object_type->apply) {
-		object_type->apply(sorcery, object);
+		res = object_type->apply(sorcery, object);
 	}
 
 	return res;

Modified: team/mmichelson/authenticate/res/res_sip/config_transport.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/authenticate/res/res_sip/config_transport.c?view=diff&rev=380833&r1=380832&r2=380833
==============================================================================
--- team/mmichelson/authenticate/res/res_sip/config_transport.c (original)
+++ team/mmichelson/authenticate/res/res_sip/config_transport.c Mon Feb  4 14:30:16 2013
@@ -68,7 +68,7 @@
 }
 
 /*! \brief Apply handler for transports */
-static void transport_apply(const struct ast_sorcery *sorcery, void *obj)
+static int transport_apply(const struct ast_sorcery *sorcery, void *obj)
 {
 	struct ast_sip_transport *transport = obj;
 	RAII_VAR(struct ast_sip_transport *, existing, ast_sorcery_retrieve_by_id(sorcery, "transport", ast_sorcery_object_get_id(obj)), ao2_cleanup);
@@ -77,7 +77,7 @@
 	if (!existing || !existing->state) {
 		if (!(transport->state = ao2_alloc(sizeof(*transport->state), transport_state_destroy))) {
 			ast_log(LOG_ERROR, "Transport state for '%s' could not be allocated\n", ast_sorcery_object_get_id(obj));
-			return;
+			return -1;
 		}
 	} else {
 		transport->state = existing->state;
@@ -86,7 +86,7 @@
 
 	/* Once active a transport can not be reconfigured */
 	if (transport->state->transport || transport->state->factory) {
-		return;
+		return -1;
 	}
 
 	/* Set default port if not present */
@@ -121,7 +121,9 @@
 
 		pjsip_strerror(res, msg, sizeof(msg));
 		ast_log(LOG_ERROR, "Transport '%s' could not be started: %s\n", ast_sorcery_object_get_id(obj), msg);
-	}
+		return -1;
+	}
+	return 0;
 }
 
 /*! \brief Custom handler for turning a string protocol into an enum */

Modified: team/mmichelson/authenticate/tests/test_sorcery.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/authenticate/tests/test_sorcery.c?view=diff&rev=380833&r1=380832&r2=380833
==============================================================================
--- team/mmichelson/authenticate/tests/test_sorcery.c (original)
+++ team/mmichelson/authenticate/tests/test_sorcery.c Mon Feb  4 14:30:16 2013
@@ -96,9 +96,10 @@
 static int apply_handler_called;
 
 /*! \brief Simple apply handler which sets global scope integer to 1 if called */
-static void test_apply_handler(const struct ast_sorcery *sorcery, void *obj)
+static int test_apply_handler(const struct ast_sorcery *sorcery, void *obj)
 {
 	apply_handler_called = 1;
+	return 0;
 }
 
 /*! \brief Global scope caching structure for testing */




More information about the asterisk-commits mailing list