michael@377: Index: modules/lcr/lcr_mod.c michael@377: diff -Nau modules/lcr/lcr_mod.c.orig modules/lcr/lcr_mod.c michael@377: --- modules/lcr/lcr_mod.c.orig 2009-03-09 14:42:46.000000000 +0100 michael@377: +++ modules/lcr/lcr_mod.c 2009-03-24 22:50:37.363366116 +0100 michael@377: @@ -114,9 +114,18 @@ michael@377: michael@377: #define PRIORITY_COL "priority" michael@377: michael@377: +#define USER_COL "usid" michael@377: + michael@377: +#define REALM_COL "realm" michael@377: + michael@377: +#define PASSWD_COL "passwd" michael@377: + michael@377: #define MAX_NO_OF_GWS 32 michael@377: #define MAX_NO_OF_LCRS 256 michael@377: #define MAX_PREFIX_LEN 256 michael@377: +#define MAX_USER_LEN 64 michael@377: +#define MAX_REALM_LEN 64 michael@377: +#define MAX_PASSWD_LEN 64 michael@377: #define MAX_TAG_LEN 16 michael@377: #define MAX_FROM_URI_LEN 256 michael@377: michael@377: @@ -141,6 +150,12 @@ michael@377: char tag[MAX_TAG_LEN + 1]; michael@377: unsigned short tag_len; michael@377: unsigned int flags; michael@377: + char user[MAX_USER_LEN]; michael@377: + unsigned short user_len; michael@377: + char realm[MAX_REALM_LEN]; michael@377: + unsigned short realm_len; michael@377: + char passwd[MAX_PASSWD_LEN]; michael@377: + unsigned short passwd_len; michael@377: }; michael@377: michael@377: struct lcr_info { michael@377: @@ -196,6 +211,9 @@ michael@377: static str prefix_col = str_init(PREFIX_COL); michael@377: static str from_uri_col = str_init(FROM_URI_COL); michael@377: static str priority_col = str_init(PRIORITY_COL); michael@377: +static str user_col = str_init(USER_COL); michael@377: +static str realm_col = str_init(REALM_COL); michael@377: +static str passwd_col = str_init(PASSWD_COL); michael@377: michael@377: /* timer */ michael@377: int fr_inv_timer = DEF_FR_INV_TIMER; michael@377: @@ -208,6 +226,9 @@ michael@377: static char *contact_avp_param = NULL; michael@377: static char *rpid_avp_param = NULL; michael@377: static char *flags_avp_param = NULL; michael@377: +static char *user_avp_param = NULL; michael@377: +static char *realm_avp_param = NULL; michael@377: +static char *passwd_avp_param = NULL; michael@377: michael@377: /* prefix mode */ michael@377: int prefix_mode_param = DEF_PREFIX_MODE; michael@377: @@ -239,6 +260,12 @@ michael@377: static int_str rpid_avp; michael@377: static int flags_avp_type; michael@377: static int_str flags_avp; michael@377: +static int user_avp_type; michael@377: +static int_str user_avp; michael@377: +static int realm_avp_type; michael@377: +static int_str realm_avp; michael@377: +static int passwd_avp_type; michael@377: +static int_str passwd_avp; michael@377: michael@377: struct gw_info **gws; /* Pointer to current gw table pointer */ michael@377: struct gw_info *gws_1; /* Pointer to gw table 1 */ michael@377: @@ -327,6 +354,12 @@ michael@377: {"fr_inv_timer", INT_PARAM, &fr_inv_timer }, michael@377: {"fr_inv_timer_next", INT_PARAM, &fr_inv_timer_next }, michael@377: {"prefix_mode", INT_PARAM, &prefix_mode_param }, michael@377: + {"user_column", STR_PARAM, &user_col.s }, michael@377: + {"realm_column", STR_PARAM, &realm_col.s }, michael@377: + {"passwd_column", STR_PARAM, &passwd_col.s }, michael@377: + {"auth_username_avp", STR_PARAM, &user_avp_param }, michael@377: + {"auth_realm_avp", STR_PARAM, &realm_avp_param }, michael@377: + {"auth_password_avp", STR_PARAM, &passwd_avp_param }, michael@377: {0, 0, 0} michael@377: }; michael@377: michael@377: @@ -438,6 +471,9 @@ michael@377: prefix_col.len = strlen(prefix_col.s); michael@377: from_uri_col.len = strlen(from_uri_col.s); michael@377: priority_col.len = strlen(priority_col.s); michael@377: + user_col.len = strlen(user_col.s); michael@377: + realm_col.len = strlen(realm_col.s); michael@377: + passwd_col.len = strlen(passwd_col.s); michael@377: michael@377: /* Bind database */ michael@377: if (lcr_db_bind(&db_url)) { michael@377: @@ -563,6 +599,60 @@ michael@377: return -1; michael@377: } michael@377: michael@377: + if (user_avp_param && *user_avp_param) { michael@377: + s.s = user_avp_param; s.len = strlen(s.s); michael@377: + if (pv_parse_spec(&s, &avp_spec)==0 michael@377: + || avp_spec.type!=PVT_AVP) { michael@377: + LM_ERR("Malformed or non AVP definition <%s>\n", user_avp_param); michael@377: + return -1; michael@377: + } michael@377: + michael@377: + if(pv_get_avp_name(0, &(avp_spec.pvp), &user_avp, &avp_flags)!=0) { michael@377: + LM_ERR("Invalid AVP definition <%s>\n", user_avp_param); michael@377: + return -1; michael@377: + } michael@377: + user_avp_type = avp_flags; michael@377: + } else { michael@377: + LM_ERR("AVP user_avp has not been defined\n"); michael@377: + return -1; michael@377: + } michael@377: + michael@377: + if (realm_avp_param && *realm_avp_param) { michael@377: + s.s = realm_avp_param; s.len = strlen(s.s); michael@377: + if (pv_parse_spec(&s, &avp_spec)==0 michael@377: + || avp_spec.type!=PVT_AVP) { michael@377: + LM_ERR("Malformed or non AVP definition <%s>\n", realm_avp_param); michael@377: + return -1; michael@377: + } michael@377: + michael@377: + if(pv_get_avp_name(0, &(avp_spec.pvp), &realm_avp, &avp_flags)!=0) { michael@377: + LM_ERR("Invalid AVP definition <%s>\n", realm_avp_param); michael@377: + return -1; michael@377: + } michael@377: + realm_avp_type = avp_flags; michael@377: + } else { michael@377: + LM_ERR("AVP realm_avp has not been defined\n"); michael@377: + return -1; michael@377: + } michael@377: + michael@377: + if (passwd_avp_param && *passwd_avp_param) { michael@377: + s.s = passwd_avp_param; s.len = strlen(s.s); michael@377: + if (pv_parse_spec(&s, &avp_spec)==0 michael@377: + || avp_spec.type!=PVT_AVP) { michael@377: + LM_ERR("Malformed or non AVP definition <%s>\n", passwd_avp_param); michael@377: + return -1; michael@377: + } michael@377: + michael@377: + if(pv_get_avp_name(0, &(avp_spec.pvp), &passwd_avp, &avp_flags)!=0) { michael@377: + LM_ERR("Invalid AVP definition <%s>\n", passwd_avp_param); michael@377: + return -1; michael@377: + } michael@377: + passwd_avp_type = avp_flags; michael@377: + } else { michael@377: + LM_ERR("AVP passwd_avp has not been defined\n"); michael@377: + return -1; michael@377: + } michael@377: + michael@377: /* Check table version */ michael@377: db_con_t* dbh; michael@377: if (lcr_dbf.init==0){ michael@377: @@ -801,16 +891,17 @@ michael@377: int reload_gws(void) michael@377: { michael@377: unsigned int i, port, strip, tag_len, prefix_len, from_uri_len, michael@377: - grp_id, priority; michael@377: + user_len, realm_len, passwd_len, grp_id, priority; michael@377: struct in_addr ip_addr; michael@377: unsigned int flags; michael@377: uri_type scheme; michael@377: uri_transport transport; michael@377: db_con_t* dbh; michael@377: char *tag, *prefix, *from_uri; michael@377: + char *user, *realm, *passwd; michael@377: db_res_t* res = NULL; michael@377: db_row_t* row; michael@377: - db_key_t gw_cols[8]; michael@377: + db_key_t gw_cols[11]; michael@377: db_key_t lcr_cols[4]; michael@377: michael@377: gw_cols[0] = &ip_addr_col; michael@377: @@ -823,6 +914,9 @@ michael@377: in the two tables? (ge vw lcr) */ michael@377: gw_cols[6] = &grp_id_col; michael@377: gw_cols[7] = &flags_col; michael@377: + gw_cols[8] = &user_col; michael@377: + gw_cols[9] = &realm_col; michael@377: + gw_cols[10] = &passwd_col; michael@377: michael@377: lcr_cols[0] = &prefix_col; michael@377: lcr_cols[1] = &from_uri_col; michael@377: @@ -846,7 +940,7 @@ michael@377: return -1; michael@377: } michael@377: michael@377: - if (lcr_dbf.query(dbh, NULL, 0, NULL, gw_cols, 0, 8, 0, &res) < 0) { michael@377: + if (lcr_dbf.query(dbh, NULL, 0, NULL, gw_cols, 0, 11, 0, &res) < 0) { michael@377: LM_ERR("Failed to query gw data\n"); michael@377: lcr_dbf.close(dbh); michael@377: return -1; michael@377: @@ -938,6 +1032,45 @@ michael@377: lcr_dbf.close(dbh); michael@377: return -1; michael@377: } michael@377: + if (VAL_NULL(ROW_VALUES(row) + 8) == 1) { michael@377: + user_len = 0; michael@377: + user = (char *)0; michael@377: + } else { michael@377: + user = (char *)VAL_STRING(ROW_VALUES(row) + 8); michael@377: + user_len = strlen(user); michael@377: + if (user_len > MAX_USER_LEN) { michael@377: + LM_ERR("Too long gw user <%u>\n", user_len); michael@377: + lcr_dbf.free_result(dbh, res); michael@377: + lcr_dbf.close(dbh); michael@377: + return -1; michael@377: + } michael@377: + } michael@377: + if (VAL_NULL(ROW_VALUES(row) + 9) == 1) { michael@377: + realm_len = 0; michael@377: + realm = (char *)0; michael@377: + } else { michael@377: + realm = (char *)VAL_STRING(ROW_VALUES(row) + 9); michael@377: + realm_len = strlen(realm); michael@377: + if (realm_len > MAX_REALM_LEN) { michael@377: + LM_ERR("Too long gw realm <%u>\n", realm_len); michael@377: + lcr_dbf.free_result(dbh, res); michael@377: + lcr_dbf.close(dbh); michael@377: + return -1; michael@377: + } michael@377: + } michael@377: + if (VAL_NULL(ROW_VALUES(row) + 10) == 1) { michael@377: + passwd_len = 0; michael@377: + passwd = (char *)0; michael@377: + } else { michael@377: + passwd = (char *)VAL_STRING(ROW_VALUES(row) + 10); michael@377: + passwd_len = strlen(passwd); michael@377: + if (passwd_len > MAX_PASSWD_LEN) { michael@377: + LM_ERR("Too long gw passwd <%u>\n", passwd_len); michael@377: + lcr_dbf.free_result(dbh, res); michael@377: + lcr_dbf.close(dbh); michael@377: + return -1; michael@377: + } michael@377: + } michael@377: if (*gws == gws_1) { michael@377: gws_2[i].ip_addr = (unsigned int)ip_addr.s_addr; michael@377: gws_2[i].port = port; michael@377: @@ -949,6 +1082,15 @@ michael@377: gws_2[i].tag_len = tag_len; michael@377: if (tag_len) michael@377: memcpy(&(gws_2[i].tag[0]), tag, tag_len); michael@377: + gws_2[i].user_len = user_len; michael@377: + if (user_len) michael@377: + memcpy(&(gws_2[i].user[0]), user, user_len); michael@377: + gws_2[i].realm_len = realm_len; michael@377: + if (realm_len) michael@377: + memcpy(&(gws_2[i].realm[0]), realm, realm_len); michael@377: + gws_2[i].passwd_len = passwd_len; michael@377: + if (passwd_len) michael@377: + memcpy(&(gws_2[i].passwd[0]), passwd, passwd_len); michael@377: } else { michael@377: gws_1[i].ip_addr = (unsigned int)ip_addr.s_addr; michael@377: gws_1[i].port = port; michael@377: @@ -960,6 +1102,15 @@ michael@377: gws_1[i].tag_len = tag_len; michael@377: if (tag_len) michael@377: memcpy(&(gws_1[i].tag[0]), tag, tag_len); michael@377: + gws_1[i].user_len = user_len; michael@377: + if (user_len) michael@377: + memcpy(&(gws_1[i].user[0]), user, user_len); michael@377: + gws_1[i].realm_len = realm_len; michael@377: + if (realm_len) michael@377: + memcpy(&(gws_1[i].realm[0]), realm, realm_len); michael@377: + gws_1[i].passwd_len = passwd_len; michael@377: + if (passwd_len) michael@377: + memcpy(&(gws_1[i].passwd[0]), passwd, passwd_len); michael@377: } michael@377: } michael@377: michael@377: @@ -1141,6 +1292,21 @@ michael@377: attr = add_mi_attr(node, MI_DUP_VALUE, "FLAGS", 5, p, len); michael@377: if(attr == NULL) michael@377: return -1; michael@377: + michael@377: + attr = add_mi_attr(node, MI_DUP_VALUE, "USER", 6, michael@377: + (*gws)[i].user, (*gws)[i].user_len ); michael@377: + if(attr == NULL) michael@377: + return -1; michael@377: + michael@377: + attr = add_mi_attr(node, MI_DUP_VALUE, "REALM", 6, michael@377: + (*gws)[i].realm, (*gws)[i].realm_len ); michael@377: + if(attr == NULL) michael@377: + return -1; michael@377: + michael@377: + attr = add_mi_attr(node, MI_DUP_VALUE, "PASSWD", 6, michael@377: + (*gws)[i].passwd, (*gws)[i].passwd_len ); michael@377: + if(attr == NULL) michael@377: + return -1; michael@377: } michael@377: michael@377: for (i = 0; i < MAX_NO_OF_LCRS; i++) { michael@377: @@ -1184,6 +1350,9 @@ michael@377: char ruri[MAX_URI_SIZE]; michael@377: unsigned int i, j, k, index, addr, port, strip, gw_index, michael@377: duplicated_gw, flags, have_rpid_avp; michael@377: + char *user; michael@377: + char *realm; michael@377: + char *passwd; michael@377: uri_type scheme; michael@377: uri_transport transport; michael@377: struct ip_addr address; michael@377: @@ -1407,6 +1576,9 @@ michael@377: transport = (*gws)[index].transport; michael@377: flags = (*gws)[index].flags; michael@377: strip = (*gws)[index].strip; michael@377: + user = (*gws)[index].user; michael@377: + realm = (*gws)[index].realm; michael@377: + passwd = (*gws)[index].passwd; michael@377: if (strip > ruri_user.len) { michael@377: LM_ERR("Strip count of gw is too large <%u>\n", strip); michael@377: goto skip; michael@377: @@ -1476,6 +1648,25 @@ michael@377: val.s = value; michael@377: add_avp(gw_uri_avp_type|AVP_VAL_STR, gw_uri_avp, val); michael@377: LM_DBG("Added gw_uri_avp <%.*s>\n", value.len, value.s); michael@377: + michael@377: + value.s = user; michael@377: + value.len = strlen(value.s); michael@377: + val.s = value; michael@377: + add_avp(user_avp_type|AVP_VAL_STR, user_avp, val); michael@377: + LM_DBG("Added user_avp <%.*s>\n", value.len, value.s); michael@377: + michael@377: + value.s = realm; michael@377: + value.len = strlen(value.s); michael@377: + val.s = value; michael@377: + add_avp(realm_avp_type|AVP_VAL_STR, realm_avp, val); michael@377: + LM_DBG("Added realm_avp <%.*s>\n", value.len, value.s); michael@377: + michael@377: + value.s = passwd; michael@377: + value.len = strlen(value.s); michael@377: + val.s = value; michael@377: + add_avp(passwd_avp_type|AVP_VAL_STR, passwd_avp, val); michael@377: + LM_DBG("Added passwd_avp <%.*s>\n", value.len, value.s); michael@377: + michael@377: skip: michael@377: continue; michael@377: } michael@377: @@ -1558,7 +1749,8 @@ michael@377: static int next_gw(struct sip_msg* _m, char* _s1, char* _s2) michael@377: { michael@377: int_str gw_uri_val, ruri_user_val, val; michael@377: - struct usr_avp *gu_avp, *ru_avp; michael@377: + int_str user_val, realm_val, passwd_val; michael@377: + struct usr_avp *gu_avp, *ru_avp, *usr_avp, *rlm_avp, *pwd_avp; michael@377: int rval; michael@377: str new_ruri; michael@377: char *at, *at_char, *strip_char, *endptr; michael@377: @@ -1575,6 +1767,35 @@ michael@377: gw_uri_val.s.len = gw_uri_val.s.len - (at - gw_uri_val.s.s); michael@377: gw_uri_val.s.s = at; michael@377: michael@377: + /* Save gateway AVPs for use in script */ michael@377: + usr_avp = search_first_avp(user_avp_type, user_avp, &user_val, 0); michael@377: + rlm_avp = search_first_avp(realm_avp_type, realm_avp, &realm_val, 0); michael@377: + pwd_avp = search_first_avp(passwd_avp_type, passwd_avp, &passwd_val, 0); michael@377: + if (!usr_avp) { michael@377: + LM_DBG("User AVP no set\n"); michael@377: + return -1; michael@377: + } michael@377: + else { michael@377: + add_avp(user_avp_type|AVP_VAL_STR, user_avp, user_val); michael@377: + LM_DBG("Added user_avp <%.*s>\n", user_val.s.len, user_val.s.s); michael@377: + } michael@377: + if (!rlm_avp) { michael@377: + LM_DBG("Realm AVP no set\n"); michael@377: + return -1; michael@377: + } michael@377: + else { michael@377: + add_avp(realm_avp_type|AVP_VAL_STR, realm_avp, realm_val); michael@377: + LM_DBG("Added realm_avp <%.*s>\n", realm_val.s.len, realm_val.s.s); michael@377: + } michael@377: + if (!pwd_avp) { michael@377: + LM_DBG("Passwd AVP no set\n"); michael@377: + return -1; michael@377: + } michael@377: + else { michael@377: + add_avp(passwd_avp_type|AVP_VAL_STR, passwd_avp, passwd_val); michael@377: + LM_DBG("Added passwd_avp <%.*s>\n", passwd_val.s.len, passwd_val.s.s); michael@377: + } michael@377: + michael@377: /* Create new Request-URI taking URI user from ruri_user AVP michael@377: and other parts of from gateway URI AVP. */ michael@377: ru_avp = search_first_avp(ruri_user_avp_type, ruri_user_avp,