Module: sip-router Branch: master Commit: 6af810edde27d087c86432f42d9aec0636b3a740 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=6af810ed...
Author: Richard Good richard.good@smilecoms.com Committer: Richard Good richard.good@smilecoms.com Date: Tue Jun 25 14:07:12 2013 +0200
modules/ims_auth: execute route block on async reply on REG MAR - changed this to make the use of async CDP cleaner - Fixes inconsistencies we are experiencing with async TM and not using route blocks - Note this fix is for REG MAR called from ims_www_challenge()
---
modules/ims_auth/authims_mod.c | 51 +++++++++++++++++++++++++-------------- modules/ims_auth/authorize.c | 32 ++++++++++++++++++------ modules/ims_auth/authorize.h | 4 +- modules/ims_auth/cxdx_mar.h | 6 ---- 4 files changed, 59 insertions(+), 34 deletions(-)
diff --git a/modules/ims_auth/authims_mod.c b/modules/ims_auth/authims_mod.c index 0e94f69..a23e7ce 100644 --- a/modules/ims_auth/authims_mod.c +++ b/modules/ims_auth/authims_mod.c @@ -67,7 +67,8 @@ static void destroy(void); static int mod_init(void);
static int auth_fixup(void** param, int param_no); -static int challenge_fixup(void** param, int param_no); +static int auth_fixup_async(void** param, int param_no); +static int challenge_fixup_async(void** param, int param_no);
struct cdp_binds cdpb;
@@ -117,9 +118,9 @@ int ignore_failed_auth = 0; */ static cmd_export_t cmds[] = { {"ims_www_authenticate", (cmd_function) www_authenticate, 1, auth_fixup, 0, REQUEST_ROUTE}, - {"ims_www_challenge", (cmd_function) www_challenge, 1, challenge_fixup, 0, REQUEST_ROUTE}, + {"ims_www_challenge", (cmd_function) www_challenge, 2, challenge_fixup_async, 0, REQUEST_ROUTE}, {"ims_proxy_authenticate", (cmd_function) proxy_authenticate, 1, auth_fixup, 0, REQUEST_ROUTE}, - {"ims_proxy_challenge", (cmd_function) proxy_challenge, 1, auth_fixup, 0, REQUEST_ROUTE}, + {"ims_proxy_challenge", (cmd_function) proxy_challenge, 2, auth_fixup_async, 0, REQUEST_ROUTE}, {"bind_ims_auth", (cmd_function) bind_ims_auth, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0} }; @@ -268,30 +269,22 @@ static void destroy(void) { /* * Convert the char* parameters */ -static int challenge_fixup(void** param, int param_no) { +static int challenge_fixup_async(void** param, int param_no) {
if (strlen((char*) *param) <= 0) { LM_ERR("empty parameter %d not allowed\n", param_no); return -1; }
- if (param_no == 1) { + if (param_no == 1) { //route name - static or dynamic string (config vars) + if (fixup_spve_null(param, param_no) < 0) + return -1; + return 0; + } else if (param_no == 2) { if (fixup_var_str_12(param, 1) == -1) { LM_ERR("Erroring doing fixup on challenge"); return -1; } - mar_param_t *ap; - ap = (mar_param_t*) pkg_malloc(sizeof (mar_param_t)); - if (ap == NULL) { - LM_ERR("no more pkg\n"); - return -1; - } - memset(ap, 0, sizeof (mar_param_t)); - ap->paction = get_action_from_param(param, param_no); - - ap->param = (char*) *param; - - *param = (void*) ap; }
return 0; @@ -307,7 +300,29 @@ static int auth_fixup(void** param, int param_no) { }
if (param_no == 1) { - //return fixup_var_str_12(param, 1); + if (fixup_var_str_12(param, 1) == -1) { + LM_ERR("Erroring doing fixup on auth"); + return -1; + } + } + + return 0; +} + +/* + * Convert the char* parameters + */ +static int auth_fixup_async(void** param, int param_no) { + if (strlen((char*) *param) <= 0) { + LM_ERR("empty parameter %d not allowed\n", param_no); + return -1; + } + + if (param_no == 1) { //route name - static or dynamic string (config vars) + if (fixup_spve_null(param, param_no) < 0) + return -1; + return 0; + } else if (param_no == 2) { if (fixup_var_str_12(param, 1) == -1) { LM_ERR("Erroring doing fixup on auth"); return -1; diff --git a/modules/ims_auth/authorize.c b/modules/ims_auth/authorize.c index 7f3e753..9f58554 100644 --- a/modules/ims_auth/authorize.c +++ b/modules/ims_auth/authorize.c @@ -270,22 +270,38 @@ int proxy_authenticate(struct sip_msg* _m, char* _realm, char* _table) { return digest_authenticate(_m, &srealm, &stable, HDR_PROXYAUTH_T); } */ -int challenge(struct sip_msg* msg, char* str1, char* str2, int is_proxy_auth) { +int challenge(struct sip_msg* msg, char* str1, char* str2, int is_proxy_auth, char *route) {
str realm = {0, 0}; unsigned int aud_hash; str private_identity, public_identity, auts = {0, 0}, nonce = {0, 0}; auth_vector *av = 0; int algo_type; + + str route_name;
saved_transaction_t* saved_t; tm_cell_t *t = 0; cfg_action_t* cfg_action;
- mar_param_t* ap = (mar_param_t*) str1; - cfg_action = ap->paction->next; + if (fixup_get_svalue(msg, (gparam_t*) route, &route_name) != 0) { + LM_ERR("no async route block for assign_server_unreg\n"); + return -1; + } + + LM_DBG("Looking for route block [%.*s]\n", route_name.len, route_name.s); + int ri = route_get(&main_rt, route_name.s); + if (ri < 0) { + LM_ERR("unable to find route block [%.*s]\n", route_name.len, route_name.s); + return -1; + } + cfg_action = main_rt.rlist[ri]; + if (cfg_action == NULL) { + LM_ERR("empty action lists in route block [%.*s]\n", route_name.len, route_name.s); + return -1; + }
- if (get_str_fparam(&realm, msg, (fparam_t*) ap->param) < 0) { + if (get_str_fparam(&realm, msg, (fparam_t*) str1) < 0) { LM_ERR("failed to get realm value\n"); return CSCF_RETURN_ERROR; } @@ -455,12 +471,12 @@ int challenge(struct sip_msg* msg, char* str1, char* str2, int is_proxy_auth) { return CSCF_RETURN_BREAK; }
-int www_challenge(struct sip_msg* msg, char* str1, char* str2) { - return challenge(msg, str1, str2, 0); +int www_challenge(struct sip_msg* msg, char* _route, char* str1, char* str2) { + return challenge(msg, str1, str2, 0, _route); }
-int proxy_challenge(struct sip_msg* msg, char* str1, char* str2) { - return challenge(msg, str1, str2, 1); +int proxy_challenge(struct sip_msg* msg, char* _route, char* str1, char* str2) { + return challenge(msg, str1, str2, 1, _route); }
/** diff --git a/modules/ims_auth/authorize.h b/modules/ims_auth/authorize.h index 084fe60..7f4beef 100644 --- a/modules/ims_auth/authorize.h +++ b/modules/ims_auth/authorize.h @@ -133,13 +133,13 @@ void auth_db_close(void); * Authorize using Proxy-Authorization header field */ int proxy_authenticate(struct sip_msg* _msg, char* _realm, char* _table); -int proxy_challenge(struct sip_msg* msg, char* _realm, char* str2); +int proxy_challenge(struct sip_msg* msg, char* route, char* _realm, char* str2);
/* * Authorize using WWW-Authorization header field */ int www_authenticate(struct sip_msg* _msg, char* _realm, char* _table); -int www_challenge(struct sip_msg* msg, char* _realm, char* str2); +int www_challenge(struct sip_msg* msg, char* route, char* _realm, char* str2);
/* diff --git a/modules/ims_auth/cxdx_mar.h b/modules/ims_auth/cxdx_mar.h index 7f1733a..9a930ec 100644 --- a/modules/ims_auth/cxdx_mar.h +++ b/modules/ims_auth/cxdx_mar.h @@ -57,12 +57,6 @@ extern str cxdx_forced_peer; /**< FQDN of the Diameter peer to send requests to extern str cxdx_dest_realm; extern struct tm_binds tmb;
-typedef struct mar_param { - int type; - char* param; - cfg_action_t *paction; -} mar_param_t; - typedef struct saved_transaction { unsigned int tindex; unsigned int tlabel;