opensips/opensips.patch.lcr

Wed, 21 Sep 2011 14:04:16 +0200

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 21 Sep 2011 14:04:16 +0200
changeset 377
67e813202d53
permissions
-rw-r--r--

Introduce severe but necessary corrections and update to new vendor version.

michael@377 1 Index: modules/lcr/lcr_mod.c
michael@377 2 diff -Nau modules/lcr/lcr_mod.c.orig modules/lcr/lcr_mod.c
michael@377 3 --- modules/lcr/lcr_mod.c.orig 2009-03-09 14:42:46.000000000 +0100
michael@377 4 +++ modules/lcr/lcr_mod.c 2009-03-24 22:50:37.363366116 +0100
michael@377 5 @@ -114,9 +114,18 @@
michael@377 6
michael@377 7 #define PRIORITY_COL "priority"
michael@377 8
michael@377 9 +#define USER_COL "usid"
michael@377 10 +
michael@377 11 +#define REALM_COL "realm"
michael@377 12 +
michael@377 13 +#define PASSWD_COL "passwd"
michael@377 14 +
michael@377 15 #define MAX_NO_OF_GWS 32
michael@377 16 #define MAX_NO_OF_LCRS 256
michael@377 17 #define MAX_PREFIX_LEN 256
michael@377 18 +#define MAX_USER_LEN 64
michael@377 19 +#define MAX_REALM_LEN 64
michael@377 20 +#define MAX_PASSWD_LEN 64
michael@377 21 #define MAX_TAG_LEN 16
michael@377 22 #define MAX_FROM_URI_LEN 256
michael@377 23
michael@377 24 @@ -141,6 +150,12 @@
michael@377 25 char tag[MAX_TAG_LEN + 1];
michael@377 26 unsigned short tag_len;
michael@377 27 unsigned int flags;
michael@377 28 + char user[MAX_USER_LEN];
michael@377 29 + unsigned short user_len;
michael@377 30 + char realm[MAX_REALM_LEN];
michael@377 31 + unsigned short realm_len;
michael@377 32 + char passwd[MAX_PASSWD_LEN];
michael@377 33 + unsigned short passwd_len;
michael@377 34 };
michael@377 35
michael@377 36 struct lcr_info {
michael@377 37 @@ -196,6 +211,9 @@
michael@377 38 static str prefix_col = str_init(PREFIX_COL);
michael@377 39 static str from_uri_col = str_init(FROM_URI_COL);
michael@377 40 static str priority_col = str_init(PRIORITY_COL);
michael@377 41 +static str user_col = str_init(USER_COL);
michael@377 42 +static str realm_col = str_init(REALM_COL);
michael@377 43 +static str passwd_col = str_init(PASSWD_COL);
michael@377 44
michael@377 45 /* timer */
michael@377 46 int fr_inv_timer = DEF_FR_INV_TIMER;
michael@377 47 @@ -208,6 +226,9 @@
michael@377 48 static char *contact_avp_param = NULL;
michael@377 49 static char *rpid_avp_param = NULL;
michael@377 50 static char *flags_avp_param = NULL;
michael@377 51 +static char *user_avp_param = NULL;
michael@377 52 +static char *realm_avp_param = NULL;
michael@377 53 +static char *passwd_avp_param = NULL;
michael@377 54
michael@377 55 /* prefix mode */
michael@377 56 int prefix_mode_param = DEF_PREFIX_MODE;
michael@377 57 @@ -239,6 +260,12 @@
michael@377 58 static int_str rpid_avp;
michael@377 59 static int flags_avp_type;
michael@377 60 static int_str flags_avp;
michael@377 61 +static int user_avp_type;
michael@377 62 +static int_str user_avp;
michael@377 63 +static int realm_avp_type;
michael@377 64 +static int_str realm_avp;
michael@377 65 +static int passwd_avp_type;
michael@377 66 +static int_str passwd_avp;
michael@377 67
michael@377 68 struct gw_info **gws; /* Pointer to current gw table pointer */
michael@377 69 struct gw_info *gws_1; /* Pointer to gw table 1 */
michael@377 70 @@ -327,6 +354,12 @@
michael@377 71 {"fr_inv_timer", INT_PARAM, &fr_inv_timer },
michael@377 72 {"fr_inv_timer_next", INT_PARAM, &fr_inv_timer_next },
michael@377 73 {"prefix_mode", INT_PARAM, &prefix_mode_param },
michael@377 74 + {"user_column", STR_PARAM, &user_col.s },
michael@377 75 + {"realm_column", STR_PARAM, &realm_col.s },
michael@377 76 + {"passwd_column", STR_PARAM, &passwd_col.s },
michael@377 77 + {"auth_username_avp", STR_PARAM, &user_avp_param },
michael@377 78 + {"auth_realm_avp", STR_PARAM, &realm_avp_param },
michael@377 79 + {"auth_password_avp", STR_PARAM, &passwd_avp_param },
michael@377 80 {0, 0, 0}
michael@377 81 };
michael@377 82
michael@377 83 @@ -438,6 +471,9 @@
michael@377 84 prefix_col.len = strlen(prefix_col.s);
michael@377 85 from_uri_col.len = strlen(from_uri_col.s);
michael@377 86 priority_col.len = strlen(priority_col.s);
michael@377 87 + user_col.len = strlen(user_col.s);
michael@377 88 + realm_col.len = strlen(realm_col.s);
michael@377 89 + passwd_col.len = strlen(passwd_col.s);
michael@377 90
michael@377 91 /* Bind database */
michael@377 92 if (lcr_db_bind(&db_url)) {
michael@377 93 @@ -563,6 +599,60 @@
michael@377 94 return -1;
michael@377 95 }
michael@377 96
michael@377 97 + if (user_avp_param && *user_avp_param) {
michael@377 98 + s.s = user_avp_param; s.len = strlen(s.s);
michael@377 99 + if (pv_parse_spec(&s, &avp_spec)==0
michael@377 100 + || avp_spec.type!=PVT_AVP) {
michael@377 101 + LM_ERR("Malformed or non AVP definition <%s>\n", user_avp_param);
michael@377 102 + return -1;
michael@377 103 + }
michael@377 104 +
michael@377 105 + if(pv_get_avp_name(0, &(avp_spec.pvp), &user_avp, &avp_flags)!=0) {
michael@377 106 + LM_ERR("Invalid AVP definition <%s>\n", user_avp_param);
michael@377 107 + return -1;
michael@377 108 + }
michael@377 109 + user_avp_type = avp_flags;
michael@377 110 + } else {
michael@377 111 + LM_ERR("AVP user_avp has not been defined\n");
michael@377 112 + return -1;
michael@377 113 + }
michael@377 114 +
michael@377 115 + if (realm_avp_param && *realm_avp_param) {
michael@377 116 + s.s = realm_avp_param; s.len = strlen(s.s);
michael@377 117 + if (pv_parse_spec(&s, &avp_spec)==0
michael@377 118 + || avp_spec.type!=PVT_AVP) {
michael@377 119 + LM_ERR("Malformed or non AVP definition <%s>\n", realm_avp_param);
michael@377 120 + return -1;
michael@377 121 + }
michael@377 122 +
michael@377 123 + if(pv_get_avp_name(0, &(avp_spec.pvp), &realm_avp, &avp_flags)!=0) {
michael@377 124 + LM_ERR("Invalid AVP definition <%s>\n", realm_avp_param);
michael@377 125 + return -1;
michael@377 126 + }
michael@377 127 + realm_avp_type = avp_flags;
michael@377 128 + } else {
michael@377 129 + LM_ERR("AVP realm_avp has not been defined\n");
michael@377 130 + return -1;
michael@377 131 + }
michael@377 132 +
michael@377 133 + if (passwd_avp_param && *passwd_avp_param) {
michael@377 134 + s.s = passwd_avp_param; s.len = strlen(s.s);
michael@377 135 + if (pv_parse_spec(&s, &avp_spec)==0
michael@377 136 + || avp_spec.type!=PVT_AVP) {
michael@377 137 + LM_ERR("Malformed or non AVP definition <%s>\n", passwd_avp_param);
michael@377 138 + return -1;
michael@377 139 + }
michael@377 140 +
michael@377 141 + if(pv_get_avp_name(0, &(avp_spec.pvp), &passwd_avp, &avp_flags)!=0) {
michael@377 142 + LM_ERR("Invalid AVP definition <%s>\n", passwd_avp_param);
michael@377 143 + return -1;
michael@377 144 + }
michael@377 145 + passwd_avp_type = avp_flags;
michael@377 146 + } else {
michael@377 147 + LM_ERR("AVP passwd_avp has not been defined\n");
michael@377 148 + return -1;
michael@377 149 + }
michael@377 150 +
michael@377 151 /* Check table version */
michael@377 152 db_con_t* dbh;
michael@377 153 if (lcr_dbf.init==0){
michael@377 154 @@ -801,16 +891,17 @@
michael@377 155 int reload_gws(void)
michael@377 156 {
michael@377 157 unsigned int i, port, strip, tag_len, prefix_len, from_uri_len,
michael@377 158 - grp_id, priority;
michael@377 159 + user_len, realm_len, passwd_len, grp_id, priority;
michael@377 160 struct in_addr ip_addr;
michael@377 161 unsigned int flags;
michael@377 162 uri_type scheme;
michael@377 163 uri_transport transport;
michael@377 164 db_con_t* dbh;
michael@377 165 char *tag, *prefix, *from_uri;
michael@377 166 + char *user, *realm, *passwd;
michael@377 167 db_res_t* res = NULL;
michael@377 168 db_row_t* row;
michael@377 169 - db_key_t gw_cols[8];
michael@377 170 + db_key_t gw_cols[11];
michael@377 171 db_key_t lcr_cols[4];
michael@377 172
michael@377 173 gw_cols[0] = &ip_addr_col;
michael@377 174 @@ -823,6 +914,9 @@
michael@377 175 in the two tables? (ge vw lcr) */
michael@377 176 gw_cols[6] = &grp_id_col;
michael@377 177 gw_cols[7] = &flags_col;
michael@377 178 + gw_cols[8] = &user_col;
michael@377 179 + gw_cols[9] = &realm_col;
michael@377 180 + gw_cols[10] = &passwd_col;
michael@377 181
michael@377 182 lcr_cols[0] = &prefix_col;
michael@377 183 lcr_cols[1] = &from_uri_col;
michael@377 184 @@ -846,7 +940,7 @@
michael@377 185 return -1;
michael@377 186 }
michael@377 187
michael@377 188 - if (lcr_dbf.query(dbh, NULL, 0, NULL, gw_cols, 0, 8, 0, &res) < 0) {
michael@377 189 + if (lcr_dbf.query(dbh, NULL, 0, NULL, gw_cols, 0, 11, 0, &res) < 0) {
michael@377 190 LM_ERR("Failed to query gw data\n");
michael@377 191 lcr_dbf.close(dbh);
michael@377 192 return -1;
michael@377 193 @@ -938,6 +1032,45 @@
michael@377 194 lcr_dbf.close(dbh);
michael@377 195 return -1;
michael@377 196 }
michael@377 197 + if (VAL_NULL(ROW_VALUES(row) + 8) == 1) {
michael@377 198 + user_len = 0;
michael@377 199 + user = (char *)0;
michael@377 200 + } else {
michael@377 201 + user = (char *)VAL_STRING(ROW_VALUES(row) + 8);
michael@377 202 + user_len = strlen(user);
michael@377 203 + if (user_len > MAX_USER_LEN) {
michael@377 204 + LM_ERR("Too long gw user <%u>\n", user_len);
michael@377 205 + lcr_dbf.free_result(dbh, res);
michael@377 206 + lcr_dbf.close(dbh);
michael@377 207 + return -1;
michael@377 208 + }
michael@377 209 + }
michael@377 210 + if (VAL_NULL(ROW_VALUES(row) + 9) == 1) {
michael@377 211 + realm_len = 0;
michael@377 212 + realm = (char *)0;
michael@377 213 + } else {
michael@377 214 + realm = (char *)VAL_STRING(ROW_VALUES(row) + 9);
michael@377 215 + realm_len = strlen(realm);
michael@377 216 + if (realm_len > MAX_REALM_LEN) {
michael@377 217 + LM_ERR("Too long gw realm <%u>\n", realm_len);
michael@377 218 + lcr_dbf.free_result(dbh, res);
michael@377 219 + lcr_dbf.close(dbh);
michael@377 220 + return -1;
michael@377 221 + }
michael@377 222 + }
michael@377 223 + if (VAL_NULL(ROW_VALUES(row) + 10) == 1) {
michael@377 224 + passwd_len = 0;
michael@377 225 + passwd = (char *)0;
michael@377 226 + } else {
michael@377 227 + passwd = (char *)VAL_STRING(ROW_VALUES(row) + 10);
michael@377 228 + passwd_len = strlen(passwd);
michael@377 229 + if (passwd_len > MAX_PASSWD_LEN) {
michael@377 230 + LM_ERR("Too long gw passwd <%u>\n", passwd_len);
michael@377 231 + lcr_dbf.free_result(dbh, res);
michael@377 232 + lcr_dbf.close(dbh);
michael@377 233 + return -1;
michael@377 234 + }
michael@377 235 + }
michael@377 236 if (*gws == gws_1) {
michael@377 237 gws_2[i].ip_addr = (unsigned int)ip_addr.s_addr;
michael@377 238 gws_2[i].port = port;
michael@377 239 @@ -949,6 +1082,15 @@
michael@377 240 gws_2[i].tag_len = tag_len;
michael@377 241 if (tag_len)
michael@377 242 memcpy(&(gws_2[i].tag[0]), tag, tag_len);
michael@377 243 + gws_2[i].user_len = user_len;
michael@377 244 + if (user_len)
michael@377 245 + memcpy(&(gws_2[i].user[0]), user, user_len);
michael@377 246 + gws_2[i].realm_len = realm_len;
michael@377 247 + if (realm_len)
michael@377 248 + memcpy(&(gws_2[i].realm[0]), realm, realm_len);
michael@377 249 + gws_2[i].passwd_len = passwd_len;
michael@377 250 + if (passwd_len)
michael@377 251 + memcpy(&(gws_2[i].passwd[0]), passwd, passwd_len);
michael@377 252 } else {
michael@377 253 gws_1[i].ip_addr = (unsigned int)ip_addr.s_addr;
michael@377 254 gws_1[i].port = port;
michael@377 255 @@ -960,6 +1102,15 @@
michael@377 256 gws_1[i].tag_len = tag_len;
michael@377 257 if (tag_len)
michael@377 258 memcpy(&(gws_1[i].tag[0]), tag, tag_len);
michael@377 259 + gws_1[i].user_len = user_len;
michael@377 260 + if (user_len)
michael@377 261 + memcpy(&(gws_1[i].user[0]), user, user_len);
michael@377 262 + gws_1[i].realm_len = realm_len;
michael@377 263 + if (realm_len)
michael@377 264 + memcpy(&(gws_1[i].realm[0]), realm, realm_len);
michael@377 265 + gws_1[i].passwd_len = passwd_len;
michael@377 266 + if (passwd_len)
michael@377 267 + memcpy(&(gws_1[i].passwd[0]), passwd, passwd_len);
michael@377 268 }
michael@377 269 }
michael@377 270
michael@377 271 @@ -1141,6 +1292,21 @@
michael@377 272 attr = add_mi_attr(node, MI_DUP_VALUE, "FLAGS", 5, p, len);
michael@377 273 if(attr == NULL)
michael@377 274 return -1;
michael@377 275 +
michael@377 276 + attr = add_mi_attr(node, MI_DUP_VALUE, "USER", 6,
michael@377 277 + (*gws)[i].user, (*gws)[i].user_len );
michael@377 278 + if(attr == NULL)
michael@377 279 + return -1;
michael@377 280 +
michael@377 281 + attr = add_mi_attr(node, MI_DUP_VALUE, "REALM", 6,
michael@377 282 + (*gws)[i].realm, (*gws)[i].realm_len );
michael@377 283 + if(attr == NULL)
michael@377 284 + return -1;
michael@377 285 +
michael@377 286 + attr = add_mi_attr(node, MI_DUP_VALUE, "PASSWD", 6,
michael@377 287 + (*gws)[i].passwd, (*gws)[i].passwd_len );
michael@377 288 + if(attr == NULL)
michael@377 289 + return -1;
michael@377 290 }
michael@377 291
michael@377 292 for (i = 0; i < MAX_NO_OF_LCRS; i++) {
michael@377 293 @@ -1184,6 +1350,9 @@
michael@377 294 char ruri[MAX_URI_SIZE];
michael@377 295 unsigned int i, j, k, index, addr, port, strip, gw_index,
michael@377 296 duplicated_gw, flags, have_rpid_avp;
michael@377 297 + char *user;
michael@377 298 + char *realm;
michael@377 299 + char *passwd;
michael@377 300 uri_type scheme;
michael@377 301 uri_transport transport;
michael@377 302 struct ip_addr address;
michael@377 303 @@ -1407,6 +1576,9 @@
michael@377 304 transport = (*gws)[index].transport;
michael@377 305 flags = (*gws)[index].flags;
michael@377 306 strip = (*gws)[index].strip;
michael@377 307 + user = (*gws)[index].user;
michael@377 308 + realm = (*gws)[index].realm;
michael@377 309 + passwd = (*gws)[index].passwd;
michael@377 310 if (strip > ruri_user.len) {
michael@377 311 LM_ERR("Strip count of gw is too large <%u>\n", strip);
michael@377 312 goto skip;
michael@377 313 @@ -1476,6 +1648,25 @@
michael@377 314 val.s = value;
michael@377 315 add_avp(gw_uri_avp_type|AVP_VAL_STR, gw_uri_avp, val);
michael@377 316 LM_DBG("Added gw_uri_avp <%.*s>\n", value.len, value.s);
michael@377 317 +
michael@377 318 + value.s = user;
michael@377 319 + value.len = strlen(value.s);
michael@377 320 + val.s = value;
michael@377 321 + add_avp(user_avp_type|AVP_VAL_STR, user_avp, val);
michael@377 322 + LM_DBG("Added user_avp <%.*s>\n", value.len, value.s);
michael@377 323 +
michael@377 324 + value.s = realm;
michael@377 325 + value.len = strlen(value.s);
michael@377 326 + val.s = value;
michael@377 327 + add_avp(realm_avp_type|AVP_VAL_STR, realm_avp, val);
michael@377 328 + LM_DBG("Added realm_avp <%.*s>\n", value.len, value.s);
michael@377 329 +
michael@377 330 + value.s = passwd;
michael@377 331 + value.len = strlen(value.s);
michael@377 332 + val.s = value;
michael@377 333 + add_avp(passwd_avp_type|AVP_VAL_STR, passwd_avp, val);
michael@377 334 + LM_DBG("Added passwd_avp <%.*s>\n", value.len, value.s);
michael@377 335 +
michael@377 336 skip:
michael@377 337 continue;
michael@377 338 }
michael@377 339 @@ -1558,7 +1749,8 @@
michael@377 340 static int next_gw(struct sip_msg* _m, char* _s1, char* _s2)
michael@377 341 {
michael@377 342 int_str gw_uri_val, ruri_user_val, val;
michael@377 343 - struct usr_avp *gu_avp, *ru_avp;
michael@377 344 + int_str user_val, realm_val, passwd_val;
michael@377 345 + struct usr_avp *gu_avp, *ru_avp, *usr_avp, *rlm_avp, *pwd_avp;
michael@377 346 int rval;
michael@377 347 str new_ruri;
michael@377 348 char *at, *at_char, *strip_char, *endptr;
michael@377 349 @@ -1575,6 +1767,35 @@
michael@377 350 gw_uri_val.s.len = gw_uri_val.s.len - (at - gw_uri_val.s.s);
michael@377 351 gw_uri_val.s.s = at;
michael@377 352
michael@377 353 + /* Save gateway AVPs for use in script */
michael@377 354 + usr_avp = search_first_avp(user_avp_type, user_avp, &user_val, 0);
michael@377 355 + rlm_avp = search_first_avp(realm_avp_type, realm_avp, &realm_val, 0);
michael@377 356 + pwd_avp = search_first_avp(passwd_avp_type, passwd_avp, &passwd_val, 0);
michael@377 357 + if (!usr_avp) {
michael@377 358 + LM_DBG("User AVP no set\n");
michael@377 359 + return -1;
michael@377 360 + }
michael@377 361 + else {
michael@377 362 + add_avp(user_avp_type|AVP_VAL_STR, user_avp, user_val);
michael@377 363 + LM_DBG("Added user_avp <%.*s>\n", user_val.s.len, user_val.s.s);
michael@377 364 + }
michael@377 365 + if (!rlm_avp) {
michael@377 366 + LM_DBG("Realm AVP no set\n");
michael@377 367 + return -1;
michael@377 368 + }
michael@377 369 + else {
michael@377 370 + add_avp(realm_avp_type|AVP_VAL_STR, realm_avp, realm_val);
michael@377 371 + LM_DBG("Added realm_avp <%.*s>\n", realm_val.s.len, realm_val.s.s);
michael@377 372 + }
michael@377 373 + if (!pwd_avp) {
michael@377 374 + LM_DBG("Passwd AVP no set\n");
michael@377 375 + return -1;
michael@377 376 + }
michael@377 377 + else {
michael@377 378 + add_avp(passwd_avp_type|AVP_VAL_STR, passwd_avp, passwd_val);
michael@377 379 + LM_DBG("Added passwd_avp <%.*s>\n", passwd_val.s.len, passwd_val.s.s);
michael@377 380 + }
michael@377 381 +
michael@377 382 /* Create new Request-URI taking URI user from ruri_user AVP
michael@377 383 and other parts of from gateway URI AVP. */
michael@377 384 ru_avp = search_first_avp(ruri_user_avp_type, ruri_user_avp,

mercurial