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