functions.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  1. /*
  2. * functions.c Implementation of exported functions
  3. *
  4. * Copyright (C) 2004 FhG Fokus
  5. * Copyright (C) 2008 Juha Heinanen <[email protected]>
  6. *
  7. * This file is part of Kamailio, a free SIP server.
  8. *
  9. * Kamailio is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version
  13. *
  14. * Kamailio is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22. *
  23. */
  24. #include "../../mod_fix.h"
  25. #include "../../ut.h"
  26. #include "../../dprint.h"
  27. #include "../../usr_avp.h"
  28. #include "../../lib/kcore/radius.h"
  29. #include "../../parser/parse_uri.h"
  30. #include "misc_radius.h"
  31. #include "extra.h"
  32. /* Array for extra attribute values */
  33. static str val_arr[MAX_EXTRA];
  34. /* Extract one reply item value to AVP flags, name and value */
  35. static inline int extract_avp(VALUE_PAIR* vp, unsigned short *flags,
  36. int_str *name, int_str *value)
  37. {
  38. static str names, values;
  39. unsigned int r;
  40. char *p;
  41. char *end;
  42. /* empty? */
  43. if (vp->lvalue==0 || vp->strvalue==0)
  44. goto error;
  45. p = vp->strvalue;
  46. end = vp->strvalue + vp->lvalue;
  47. /* get name */
  48. if (*p!='#') {
  49. /* name AVP */
  50. *flags |= AVP_NAME_STR;
  51. names.s = p;
  52. } else {
  53. names.s = ++p;
  54. }
  55. names.len = 0;
  56. while( p<end && *p!=':' && *p!='#')
  57. p++;
  58. if (names.s==p || p==end) {
  59. LM_ERR("empty AVP name\n");
  60. goto error;
  61. }
  62. names.len = p - names.s;
  63. /* get value */
  64. if (*p!='#') {
  65. /* string value */
  66. *flags |= AVP_VAL_STR;
  67. }
  68. values.s = ++p;
  69. values.len = end-values.s;
  70. if (values.len==0) {
  71. LM_ERR("empty AVP value\n");
  72. goto error;
  73. }
  74. if ( !((*flags)&AVP_NAME_STR) ) {
  75. /* convert name to id*/
  76. if (str2int(&names,&r)!=0 ) {
  77. LM_ERR("invalid AVP ID '%.*s'\n", names.len,names.s);
  78. goto error;
  79. }
  80. name->n = (int)r;
  81. } else {
  82. name->s = names;
  83. }
  84. if ( !((*flags)&AVP_VAL_STR) ) {
  85. /* convert value to integer */
  86. if (str2int(&values,&r)!=0 ) {
  87. LM_ERR("invalid AVP numrical value '%.*s'\n", values.len,values.s);
  88. goto error;
  89. }
  90. value->n = (int)r;
  91. } else {
  92. value->s = values;
  93. }
  94. return 0;
  95. error:
  96. return -1;
  97. }
  98. /* Generate AVPs from Radius reply items */
  99. static void generate_avps(struct attr *attrs, VALUE_PAIR* received)
  100. {
  101. int_str name, val;
  102. unsigned short flags;
  103. VALUE_PAIR *vp;
  104. vp = received;
  105. for( ; (vp=rc_avpair_get(vp,attrs[SA_SIP_AVP].v,0)) ; vp=vp->next) {
  106. flags = 0;
  107. if (extract_avp( vp, &flags, &name, &val)!=0 )
  108. continue;
  109. if (add_avp( flags, name, val) < 0) {
  110. LM_ERR("unable to create a new AVP\n");
  111. } else {
  112. LM_DBG("AVP '%.*s'/%d='%.*s'/%d has been added\n",
  113. (flags&AVP_NAME_STR)?name.s.len:4,
  114. (flags&AVP_NAME_STR)?name.s.s:"null",
  115. (flags&AVP_NAME_STR)?0:name.n,
  116. (flags&AVP_VAL_STR)?val.s.len:4,
  117. (flags&AVP_VAL_STR)?val.s.s:"null",
  118. (flags&AVP_VAL_STR)?0:val.n );
  119. }
  120. }
  121. return;
  122. }
  123. /* Macro to add extra attribute */
  124. #define ADD_EXTRA_AVPAIR(_attrs, _attr, _val, _len) \
  125. do { \
  126. if ((_len) != 0) { \
  127. if ((_len) == -1) { \
  128. if (_attrs[_attr].t != PW_TYPE_INTEGER) { \
  129. LM_ERR("attribute %d is not of type integer\n", \
  130. _attrs[_attr].v); \
  131. goto error; \
  132. } \
  133. } \
  134. if (!rc_avpair_add( rh, &send, _attrs[_attr].v, _val, _len, 0)) { \
  135. LM_ERR("failed to add %s, %d\n", _attrs[_attr].n, _attr); \
  136. goto error; \
  137. } \
  138. } \
  139. }while(0)
  140. /*
  141. * Loads from Radius caller's AVPs based on pvar argument.
  142. * Returns 1 if Radius request succeeded and -1 otherwise.
  143. */
  144. int radius_load_caller_avps(struct sip_msg* _m, char* _caller, char* _s2)
  145. {
  146. str user;
  147. VALUE_PAIR *send, *received;
  148. uint32_t service;
  149. static char msg[4096];
  150. int extra_cnt, offset, i, res;
  151. if ((_caller == NULL) ||
  152. (fixup_get_svalue(_m, (gparam_p)_caller, &user) != 0)) {
  153. LM_ERR("invalid caller parameter");
  154. return -1;
  155. }
  156. send = received = 0;
  157. if (!rc_avpair_add(rh, &send, caller_attrs[SA_USER_NAME].v,
  158. user.s, user.len, 0)) {
  159. LM_ERR("in adding SA_USER_NAME\n");
  160. return -1;
  161. }
  162. service = caller_vals[RV_SIP_CALLER_AVPS].v;
  163. if (!rc_avpair_add(rh, &send, caller_attrs[SA_SERVICE_TYPE].v,
  164. &service, -1, 0)) {
  165. LM_ERR("error adding SA_SERVICE_TYPE <%u>\n", service);
  166. goto error;
  167. }
  168. /* Add extra attributes */
  169. extra_cnt = extra2strar(caller_extra, _m, val_arr);
  170. if (extra_cnt == -1) {
  171. LM_ERR("in getting values of caller extra attributes\n");
  172. goto error;
  173. }
  174. offset = SA_STATIC_MAX;
  175. for (i = 0; i < extra_cnt; i++) {
  176. if (val_arr[i].len == -1) {
  177. /* Add integer attribute */
  178. ADD_EXTRA_AVPAIR(caller_attrs, offset+i,
  179. &(val_arr[i].s), val_arr[i].len );
  180. } else {
  181. /* Add string attribute */
  182. ADD_EXTRA_AVPAIR(caller_attrs, offset+i,
  183. val_arr[i].s, val_arr[i].len );
  184. }
  185. }
  186. if ((res = rc_auth(rh, 0, send, &received, msg)) == OK_RC) {
  187. LM_DBG("success\n");
  188. rc_avpair_free(send);
  189. generate_avps(caller_attrs, received);
  190. rc_avpair_free(received);
  191. return 1;
  192. } else {
  193. rc_avpair_free(send);
  194. rc_avpair_free(received);
  195. #ifdef REJECT_RC
  196. if (res == REJECT_RC) {
  197. LM_DBG("rejected\n");
  198. return -1;
  199. } else {
  200. LM_ERR("failure\n");
  201. return -2;
  202. }
  203. #else
  204. LM_DBG("failure\n");
  205. return -1;
  206. #endif
  207. }
  208. error:
  209. rc_avpair_free(send);
  210. return -1;
  211. }
  212. /*
  213. * Loads from Radius callee's AVPs based on pvar argument.
  214. * Returns 1 if Radius request succeeded and -1 otherwise.
  215. */
  216. int radius_load_callee_avps(struct sip_msg* _m, char* _callee, char* _s2)
  217. {
  218. str user;
  219. VALUE_PAIR *send, *received;
  220. uint32_t service;
  221. static char msg[4096];
  222. int extra_cnt, offset, i, res;
  223. send = received = 0;
  224. if ((_callee == NULL) ||
  225. (fixup_get_svalue(_m, (gparam_p)_callee, &user) != 0)) {
  226. LM_ERR("invalid callee parameter");
  227. return -1;
  228. }
  229. if (!rc_avpair_add(rh, &send, callee_attrs[SA_USER_NAME].v,
  230. user.s, user.len, 0)) {
  231. LM_ERR("in adding SA_USER_NAME\n");
  232. return -1;
  233. }
  234. service = callee_vals[EV_SIP_CALLEE_AVPS].v;
  235. if (!rc_avpair_add(rh, &send, callee_attrs[SA_SERVICE_TYPE].v,
  236. &service, -1, 0)) {
  237. LM_ERR("in adding SA_SERVICE_TYPE <%u>\n", service);
  238. goto error;
  239. }
  240. /* Add extra attributes */
  241. extra_cnt = extra2strar(callee_extra, _m, val_arr);
  242. if (extra_cnt == -1) {
  243. LM_ERR("in getting values of callee extra attributes\n");
  244. goto error;
  245. }
  246. offset = SA_STATIC_MAX;
  247. for (i = 0; i < extra_cnt; i++) {
  248. if (val_arr[i].len == -1) {
  249. /* Add integer attribute */
  250. ADD_EXTRA_AVPAIR(callee_attrs, offset+i,
  251. &(val_arr[i].s), val_arr[i].len );
  252. } else {
  253. /* Add string attribute */
  254. ADD_EXTRA_AVPAIR(callee_attrs, offset+i,
  255. val_arr[i].s, val_arr[i].len );
  256. }
  257. }
  258. if ((res = rc_auth(rh, 0, send, &received, msg)) == OK_RC) {
  259. LM_DBG("success\n");
  260. rc_avpair_free(send);
  261. generate_avps(callee_attrs, received);
  262. rc_avpair_free(received);
  263. return 1;
  264. } else {
  265. rc_avpair_free(send);
  266. rc_avpair_free(received);
  267. #ifdef REJECT_RC
  268. if (res == REJECT_RC) {
  269. LM_DBG("rejected\n");
  270. return -1;
  271. } else {
  272. LM_ERR("failure\n");
  273. return -2;
  274. }
  275. #else
  276. LM_DBG("failure\n");
  277. return -1;
  278. #endif
  279. }
  280. error:
  281. rc_avpair_free(send);
  282. return -1;
  283. }
  284. /*
  285. * Check from Radius if a user belongs to a group. User-Name is given in
  286. * first string argment that may contain pseudo variables. SIP-Group is
  287. * given in second string variable that may not contain pseudo variables.
  288. * Service-Type is Group-Check.
  289. */
  290. int radius_is_user_in(struct sip_msg* _m, char* _user, char* _group)
  291. {
  292. str user, *group;
  293. VALUE_PAIR *send, *received;
  294. uint32_t service;
  295. static char msg[4096];
  296. int extra_cnt, offset, i, res;
  297. send = received = 0;
  298. if ((_user == NULL) ||
  299. (fixup_get_svalue(_m, (gparam_p)_user, &user) != 0)) {
  300. LM_ERR("invalid user parameter");
  301. return -1;
  302. }
  303. if (!rc_avpair_add(rh, &send, group_attrs[SA_USER_NAME].v,
  304. user.s, user.len, 0)) {
  305. LM_ERR("in adding SA_USER_NAME\n");
  306. return -1;
  307. }
  308. group = (str*)_group;
  309. if ((group == NULL) || (group->len == 0)) {
  310. LM_ERR("invalid group parameter");
  311. goto error;
  312. }
  313. if (!rc_avpair_add(rh, &send, group_attrs[SA_SIP_GROUP].v,
  314. group->s, group->len, 0)) {
  315. LM_ERR("in adding SA_SIP_GROUP\n");
  316. goto error;
  317. }
  318. service = group_vals[GV_GROUP_CHECK].v;
  319. if (!rc_avpair_add(rh, &send, group_attrs[SA_SERVICE_TYPE].v,
  320. &service, -1, 0)) {
  321. LM_ERR("in adding SA_SERVICE_TYPE <%u>\n", service);
  322. goto error;
  323. }
  324. /* Add extra attributes */
  325. extra_cnt = extra2strar(group_extra, _m, val_arr);
  326. if (extra_cnt == -1) {
  327. LM_ERR("in getting values of group extra attributes\n");
  328. goto error;
  329. }
  330. offset = SA_STATIC_MAX;
  331. for (i = 0; i < extra_cnt; i++) {
  332. if (val_arr[i].len == -1) {
  333. /* Add integer attribute */
  334. ADD_EXTRA_AVPAIR(group_attrs, offset+i,
  335. &(val_arr[i].s), val_arr[i].len );
  336. } else {
  337. /* Add string attribute */
  338. ADD_EXTRA_AVPAIR(group_attrs, offset+i,
  339. val_arr[i].s, val_arr[i].len );
  340. }
  341. }
  342. if ((res = rc_auth(rh, 0, send, &received, msg)) == OK_RC) {
  343. LM_DBG("success\n");
  344. rc_avpair_free(send);
  345. generate_avps(group_attrs, received);
  346. rc_avpair_free(received);
  347. return 1;
  348. } else {
  349. rc_avpair_free(send);
  350. rc_avpair_free(received);
  351. #ifdef REJECT_RC
  352. if (res == REJECT_RC) {
  353. LM_DBG("rejected\n");
  354. return -1;
  355. } else {
  356. LM_ERR("failure\n");
  357. return -2;
  358. }
  359. #else
  360. LM_DBG("failure\n");
  361. return -1;
  362. #endif
  363. }
  364. error:
  365. rc_avpair_free(send);
  366. return -1;
  367. }
  368. /*
  369. * Check from Radius if URI, whose user and host parts are given as
  370. * arguments, exists. If so, loads AVPs based on reply items returned
  371. * from Radius. If use_sip_uri_host module parameter has non-zero value,
  372. * user is send in SA_USER_NAME attribute and host in SA_SIP_URI_HOST
  373. * attribute. If is has zero value, user@host is send in SA_USER_NAME
  374. * attribute.
  375. */
  376. int radius_does_uri_user_host_exist(struct sip_msg* _m, str user, str host)
  377. {
  378. char* at, *user_host;
  379. VALUE_PAIR *send, *received;
  380. uint32_t service;
  381. static char msg[4096];
  382. int extra_cnt, offset, i, res;
  383. send = received = 0;
  384. user_host = 0;
  385. if (!use_sip_uri_host) {
  386. /* Send user@host in SA_USER_NAME attr */
  387. user_host = (char*)pkg_malloc(user.len + host.len + 2);
  388. if (!user_host) {
  389. LM_ERR("no more pkg memory\n");
  390. return -1;
  391. }
  392. at = user_host;
  393. memcpy(at, user.s, user.len);
  394. at += user.len;
  395. *at = '@';
  396. at++;
  397. memcpy(at , host.s, host.len);
  398. at += host.len;
  399. *at = '\0';
  400. if (!rc_avpair_add(rh, &send, uri_attrs[SA_USER_NAME].v, user_host,
  401. -1, 0)) {
  402. LM_ERR("in adding SA_USER_NAME\n");
  403. pkg_free(user_host);
  404. return -1;
  405. }
  406. } else {
  407. /* Send user in SA_USER_NAME attribute and host in SA_SIP_URI_HOST
  408. attribute */
  409. if (!rc_avpair_add(rh, &send, uri_attrs[SA_USER_NAME].v,
  410. user.s, user.len, 0)) {
  411. LM_ERR("adding User-Name failed\n");
  412. return -1;
  413. }
  414. if (!rc_avpair_add(rh, &send, uri_attrs[SA_SIP_URI_HOST].v,
  415. host.s, host.len, 0)) {
  416. LM_ERR("adding SIP-URI-Host failed\n");
  417. goto error;
  418. }
  419. }
  420. service = uri_vals[UV_CALL_CHECK].v;
  421. if (!rc_avpair_add(rh, &send, uri_attrs[SA_SERVICE_TYPE].v,
  422. &service, -1, 0)) {
  423. LM_ERR("in adding SA_SERVICE_TYPE <%u>\n", service);
  424. goto error;
  425. }
  426. /* Add extra attributes */
  427. extra_cnt = extra2strar(uri_extra, _m, val_arr);
  428. if (extra_cnt == -1) {
  429. LM_ERR("in getting values of group extra attributes\n");
  430. goto error;
  431. }
  432. offset = SA_STATIC_MAX;
  433. for (i = 0; i < extra_cnt; i++) {
  434. if (val_arr[i].len == -1) {
  435. /* Add integer attribute */
  436. ADD_EXTRA_AVPAIR(uri_attrs, offset+i,
  437. &(val_arr[i].s), val_arr[i].len );
  438. } else {
  439. /* Add string attribute */
  440. ADD_EXTRA_AVPAIR(uri_attrs, offset+i,
  441. val_arr[i].s, val_arr[i].len );
  442. }
  443. }
  444. if ((res = rc_auth(rh, 0, send, &received, msg)) == OK_RC) {
  445. LM_DBG("success\n");
  446. if (user_host) pkg_free(user_host);
  447. rc_avpair_free(send);
  448. generate_avps(uri_attrs, received);
  449. rc_avpair_free(received);
  450. return 1;
  451. } else {
  452. if (user_host) pkg_free(user_host);
  453. rc_avpair_free(send);
  454. rc_avpair_free(received);
  455. #ifdef REJECT_RC
  456. if (res == REJECT_RC) {
  457. LM_DBG("rejected\n");
  458. return -1;
  459. } else {
  460. LM_ERR("failure\n");
  461. return -2;
  462. }
  463. #else
  464. LM_DBG("failure\n");
  465. return -1;
  466. #endif
  467. }
  468. error:
  469. rc_avpair_free(send);
  470. if (user_host) pkg_free(user_host);
  471. return -1;
  472. }
  473. /*
  474. * Check from Radius if Request URI belongs to a local user.
  475. * If so, loads AVPs based on reply items returned from Radius.
  476. */
  477. int radius_does_uri_exist_0(struct sip_msg* _m, char* _s1, char* _s2)
  478. {
  479. if (parse_sip_msg_uri(_m) < 0) {
  480. LM_ERR("parsing Request-URI failed\n");
  481. return -1;
  482. }
  483. return radius_does_uri_user_host_exist(_m, _m->parsed_uri.user,
  484. _m->parsed_uri.host);
  485. }
  486. /*
  487. * Check from Radius if URI given in pvar argument belongs to a local user.
  488. * If so, loads AVPs based on reply items returned from Radius.
  489. */
  490. int radius_does_uri_exist_1(struct sip_msg* _m, char* _sp, char* _s2)
  491. {
  492. pv_spec_t *sp;
  493. pv_value_t pv_val;
  494. struct sip_uri parsed_uri;
  495. sp = (pv_spec_t *)_sp;
  496. if (sp && (pv_get_spec_value(_m, sp, &pv_val) == 0)) {
  497. if (pv_val.flags & PV_VAL_STR) {
  498. if (pv_val.rs.len == 0 || pv_val.rs.s == NULL) {
  499. LM_ERR("pvar argument is empty\n");
  500. return -1;
  501. }
  502. } else {
  503. LM_ERR("pvar value is not string\n");
  504. return -1;
  505. }
  506. } else {
  507. LM_ERR("cannot get pvar value\n");
  508. return -1;
  509. }
  510. if (parse_uri(pv_val.rs.s, pv_val.rs.len, &parsed_uri) < 0) {
  511. LM_ERR("parsing of URI in pvar failed\n");
  512. return -1;
  513. }
  514. return radius_does_uri_user_host_exist(_m, parsed_uri.user,
  515. parsed_uri.host);
  516. }
  517. /*
  518. * Check from Radius if URI user given as argument belongs to a local user.
  519. * If so, loads AVPs based on reply items returned from Radius.
  520. */
  521. int radius_does_uri_user_exist(struct sip_msg* _m, str user)
  522. {
  523. static char msg[4096];
  524. VALUE_PAIR *send, *received;
  525. uint32_t service;
  526. int res, extra_cnt, offset, i;
  527. send = received = 0;
  528. if (!rc_avpair_add(rh, &send, uri_attrs[SA_USER_NAME].v,
  529. user.s, user.len, 0)) {
  530. LM_ERR("in adding SA_USER_NAME\n");
  531. return -1;
  532. }
  533. service = uri_vals[UV_CALL_CHECK].v;
  534. if (!rc_avpair_add(rh, &send, uri_attrs[SA_SERVICE_TYPE].v,
  535. &service, -1, 0)) {
  536. LM_ERR("in adding SA_SERVICE_TYPE <%u>\n", service);
  537. goto error;
  538. }
  539. /* Add extra attributes */
  540. extra_cnt = extra2strar(uri_extra, _m, val_arr);
  541. if (extra_cnt == -1) {
  542. LM_ERR("in getting values of group extra attributes\n");
  543. goto error;
  544. }
  545. offset = SA_STATIC_MAX;
  546. for (i = 0; i < extra_cnt; i++) {
  547. if (val_arr[i].len == -1) {
  548. /* Add integer attribute */
  549. ADD_EXTRA_AVPAIR(uri_attrs, offset+i,
  550. &(val_arr[i].s), val_arr[i].len );
  551. } else {
  552. /* Add string attribute */
  553. ADD_EXTRA_AVPAIR(uri_attrs, offset+i,
  554. val_arr[i].s, val_arr[i].len );
  555. }
  556. }
  557. if ((res = rc_auth(rh, 0, send, &received, msg)) == OK_RC) {
  558. LM_DBG("success\n");
  559. rc_avpair_free(send);
  560. generate_avps(uri_attrs, received);
  561. rc_avpair_free(received);
  562. return 1;
  563. } else {
  564. rc_avpair_free(send);
  565. rc_avpair_free(received);
  566. #ifdef REJECT_RC
  567. if (res == REJECT_RC) {
  568. LM_DBG("rejected\n");
  569. return -1;
  570. } else {
  571. LM_ERR("failure\n");
  572. return -2;
  573. }
  574. #else
  575. LM_DBG("failure\n");
  576. return -1;
  577. #endif
  578. }
  579. error:
  580. rc_avpair_free(send);
  581. return -1;
  582. }
  583. /*
  584. * Check from Radius if Request URI user belongs to a local user.
  585. * If so, loads AVPs based on reply items returned from Radius.
  586. */
  587. int radius_does_uri_user_exist_0(struct sip_msg* _m, char* _s1, char* _s2)
  588. {
  589. if (parse_sip_msg_uri(_m) < 0) {
  590. LM_ERR("parsing Request-URI failed\n");
  591. return -1;
  592. }
  593. return radius_does_uri_user_exist(_m, _m->parsed_uri.user);
  594. }
  595. /*
  596. * Check from Radius if URI user given in pvar argument belongs
  597. * to a local user. If so, loads AVPs based on reply items returned
  598. * from Radius.
  599. */
  600. int radius_does_uri_user_exist_1(struct sip_msg* _m, char* _sp, char* _s2)
  601. {
  602. pv_spec_t *sp;
  603. pv_value_t pv_val;
  604. sp = (pv_spec_t *)_sp;
  605. if (sp && (pv_get_spec_value(_m, sp, &pv_val) == 0)) {
  606. if (pv_val.flags & PV_VAL_STR) {
  607. if (pv_val.rs.len == 0 || pv_val.rs.s == NULL) {
  608. LM_ERR("pvar argument is empty\n");
  609. return -1;
  610. }
  611. } else {
  612. LM_ERR("pvar value is not string\n");
  613. return -1;
  614. }
  615. } else {
  616. LM_ERR("cannot get pvar value\n");
  617. return -1;
  618. }
  619. return radius_does_uri_user_exist(_m, pv_val.rs);
  620. }