-
Notifications
You must be signed in to change notification settings - Fork 0
/
do_author.c
1212 lines (1050 loc) · 30.3 KB
/
do_author.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
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* $Id: do_author.c,v 1.14 2009-03-17 18:38:12 heas Exp $
*
* Copyright (c) 1995-1998 by Cisco systems, Inc.
*
* Permission to use, copy, modify, and distribute this software for
* any purpose and without fee is hereby granted, provided that this
* copyright and permission notice appear on all copies of the
* software and supporting documentation, the name of Cisco Systems,
* Inc. not be used in advertising or publicity pertaining to
* distribution of the program without specific prior permission, and
* notice be given in supporting documentation that modification,
* copying and distribution is by permission of Cisco Systems, Inc.
*
* Cisco Systems, Inc. makes no representations about the suitability
* of this software for any purpose. THIS SOFTWARE IS PROVIDED ``AS
* IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE.
*/
#include "tac_plus.h"
#include <regex.h>
#ifndef REG_OK
# ifdef REG_NOERROR
# define REG_OK REG_NOERROR
# else
# define REG_OK 0
# endif
#endif
static int arg_ok(char *);
static char *assemble_args(struct author_data *);
static int authorize_cmd(char *, char *, struct author_data *);
static int authorize_exec(char *, struct author_data *);
static int authorize_svc(char *, int, char *, char *, struct author_data *);
static int get_nas_svc(struct author_data *, char **, char **, char **);
static int is_separator(char);
static int mandatory(char *);
static int match_attrs(char *, char *);
static int match_values(char *, char *);
static int optional(char *);
static void post_authorization(char *, struct author_data *);
static int ppp_lcp_allowed(int, char *, char *);
static int pre_authorization(char *, struct author_data *);
static char *value(char *);
/* Return 0 is data->status is valid */
int
do_author(struct author_data *data)
{
char *username = data->id->username;
int status;
int svc;
char *cmd, *protocol, *svcname;
status = 0;
protocol = NULL;
data->status = AUTHOR_STATUS_FAIL; /* for safety */
data->output_args = NULL;
data->num_out_args = 0;
if (debug & DEBUG_AUTHOR_FLAG)
report(LOG_DEBUG, "do_author: user='%s'", username);
if (!cfg_user_exists(username) && cfg_user_exists(DEFAULT_USERNAME)) {
if (debug & DEBUG_AUTHOR_FLAG) {
report(LOG_DEBUG, "Authorizing user '%s' instead of '%s'",
DEFAULT_USERNAME, username);
}
username = DEFAULT_USERNAME;
}
/* See if there's a program defined which will do authorization for us */
if (pre_authorization(username, data))
return(0);
/*
* Decide what kind of authorization request this is. Currently
* one of: exec, cmd, slip, arap, ppp or <string>
*
* If it's a command typed to the exec, return its text in cmd.
*
* If it's a ppp request, return the protocol name in protocol.
*/
svc = get_nas_svc(data, &cmd, &protocol, &svcname);
if (!svc) {
/* if we can't identify the service in the request it's an error */
data->status = AUTHOR_STATUS_ERROR;
data->admin_msg =
tac_strdup("No identifiable service/protocol in authorization request");
if (debug & DEBUG_AUTHOR_FLAG) {
report(LOG_DEBUG, "user %s %s", username, data->admin_msg);
}
return(0);
}
if (debug & DEBUG_AUTHOR_FLAG)
report(LOG_DEBUG, "user '%s' found", username);
#ifdef MAXSESS
/* Never permit if they're going over their session limit */
switch (svc) {
case N_svc_arap:
case N_svc_ppp:
case N_svc_slip:
case N_svc_exec:
/* case N_svc: */
if (maxsess_check_count(username, data)) {
return(0);
}
default:
break;
}
#endif /* MAXSESS */
switch(svc) {
/* XXX
default:
report(LOG_ERR, "%s: Bad service type %d", session.peer, svc);
data->status = AUTHOR_STATUS_FAIL;
return(0);*/
case N_svc_cmd:
/* A command authorisation request */
status = authorize_cmd(username, cmd, data);
break;
case N_svc_exec:
if (authorize_exec(username, data))
return(0);
/* FALLTHRU */
case N_svc_arap:
case N_svc_ppp:
case N_svc_slip:
status = authorize_svc(username, svc, protocol, NULL, data);
break;
case N_svc:
status = authorize_svc(username, svc, protocol, svcname, data);
break;
}
post_authorization(username, data);
return(status);
}
/*
* If an before-authorization program has been specified, call it.
*
* A return value of 1 means no further authorization is required
*/
static int
pre_authorization(char *username, struct author_data *data)
{
int status;
char **out_args;
int out_cnt, i;
char *cmd;
char error_str[255];
int error_len = 255;
out_cnt = 0;
out_args = NULL;
/*
* If a before-authorization program exists, call it to see how to
* proceed
*/
cmd = cfg_get_pvalue(username, TAC_IS_USER,
S_before, TAC_PLUS_RECURSE);
if (!cmd)
return(0);
if (debug & DEBUG_AUTHOR_FLAG)
report(LOG_DEBUG, "Before authorization call: %s", cmd);
status = call_pre_process(cmd, data, &out_args, &out_cnt, error_str,
error_len);
switch (status) {
default:
if (debug & DEBUG_AUTHOR_FLAG)
report(LOG_DEBUG, "cmd %s returns %d (unrecognised value)",
cmd, status);
data->status = AUTHOR_STATUS_ERROR;
data->admin_msg =
tac_strdup("Illegal return status from pre-authorization command");
data->msg = tac_strdup(error_str);
data->num_out_args = 0;
data->output_args = NULL;
/* throw away out_args */
for (i = 0; i < out_cnt; i++) {
free(out_args[i]);
}
if (out_args) {
free(out_args);
}
return(1);
case 0: /* Permit */
if (debug & DEBUG_AUTHOR_FLAG)
report(LOG_DEBUG, "cmd %s returns 0 (unconditional permit)", cmd);
data->status = AUTHOR_STATUS_PASS_ADD;
data->num_out_args = 0;
data->output_args = NULL;
/* throw away out_args */
for (i = 0; i < out_cnt; i++) {
free(out_args[i]);
}
if (out_args) {
free(out_args);
}
return(1);
case 1: /* Deny */
if (debug & DEBUG_AUTHOR_FLAG)
report(LOG_DEBUG, "cmd %s returns %d (unconditional deny)",
cmd, status);
data->status = AUTHOR_STATUS_FAIL;
data->msg = tac_strdup(error_str);
data->num_out_args = 0;
data->output_args = NULL;
/* throw away out_args */
for (i = 0; i < out_cnt; i++) {
free(out_args[i]);
}
if (out_args) {
free(out_args);
}
return(1);
case 2: /* Use replacement AV pairs from program as final result */
if (debug & DEBUG_AUTHOR_FLAG) {
report(LOG_DEBUG, "cmd %s returns %d (permitted, args replaced)",
cmd, status);
for (i = 0; i < out_cnt; i++)
report(LOG_DEBUG, "%s", out_args[i]);
}
/* and install the new set of AV pairs as output */
data->output_args = out_args;
data->num_out_args = out_cnt;
data->status = AUTHOR_STATUS_PASS_REPL;
return(1); /* no more processing required */
case 3: /* deny, but return attributes and server-msg to NAS */
if (debug & DEBUG_AUTHOR_FLAG) {
report(LOG_DEBUG, "cmd %s returns %d (deny, args replaced)",
cmd, status);
for (i = 0; i < out_cnt; i++)
report(LOG_DEBUG, "%s", out_args[i]);
}
/* and install the new set of AV pairs as output */
data->output_args = out_args;
data->num_out_args = out_cnt;
data->msg = tac_strdup(error_str);
data->status = AUTHOR_STATUS_FAIL;
return(1); /* no more processing required */
}
}
/* If an after-authorization program has been specified, call it. It
* can rewrite the output arguments in the authorization data, or
* change the authorization status by calling an external program.
*/
static void
post_authorization(char *username, struct author_data *data)
{
char **out_args;
int out_cnt, i;
int status;
char *after = cfg_get_pvalue(username, TAC_IS_USER,
S_after, TAC_PLUS_RECURSE);
if (!after)
return;
if (debug & DEBUG_AUTHOR_FLAG)
report(LOG_DEBUG, "After authorization call: %s", after);
status = call_post_process(after, data, &out_args, &out_cnt);
if (status != 2) {
/* throw away out_args */
for (i = 0; i < out_cnt; i++) {
free(out_args[i]);
}
free(out_args);
}
switch (status) {
default:
if (debug & DEBUG_AUTHOR_FLAG)
report(LOG_DEBUG,
"cmd %s returns %d (Error)", after, status);
data->status = AUTHOR_STATUS_ERROR;
return;
case 0: /* Permit */
if (debug & DEBUG_AUTHOR_FLAG)
report(LOG_DEBUG, "cmd %s returns 0 (no change)", after);
return;
case 1: /* Deny */
if (debug & DEBUG_AUTHOR_FLAG)
report(LOG_DEBUG, "cmd %s returns %d (unconditional deny)",
after, status);
data->status = AUTHOR_STATUS_FAIL;
return;
case 2:
/* Use replacement AV pairs from program */
if (debug & DEBUG_AUTHOR_FLAG)
report(LOG_DEBUG, "cmd %s returns 2 (replace & continue)",
after);
/* Free any existing AV output pairs */
if (data->num_out_args) {
for (i = 0; i < data->num_out_args; i++) {
free(data->output_args[i]);
}
free(data->output_args);
data->output_args = NULL;
}
if (debug & DEBUG_AUTHOR_FLAG) {
report(LOG_DEBUG, "status is now AUTHOR_STATUS_PASS_REPL");
}
data->status = AUTHOR_STATUS_PASS_REPL;
data->output_args = out_args;
data->num_out_args = out_cnt;
return;
}
}
/* Return a pointer to the value part of an attr=value string */
static char *
value(char *s)
{
while (*s && *s != '=' && *s != '*')
s++;
if (*s)
return(++s);
return(NULL);
}
/*
* Reassemble the command arguments as typed by the user, out of the
* array of args we received. Return "" if there are no arguments.
*/
static char *
assemble_args(struct author_data *data)
{
char *buf;
int i;
char *nas_arg, *v;
int len;
len = 0;
for (i = 0; i < data->num_in_args; i++) {
nas_arg = data->input_args[i];
if (strncmp(nas_arg, "cmd-arg", strlen("cmd-arg"))==0)
len += strlen(value(nas_arg)) + 1;
}
if (len <= 0) {
return(tac_strdup(""));
}
buf = tac_malloc(len);
buf[0] = '\0';
for (i = 0; i < data->num_in_args; i++) {
nas_arg = data->input_args[i];
if (strncmp(nas_arg, "cmd-arg", strlen("cmd-arg")))
continue;
v = value(nas_arg);
if (!v) {
free(buf);
return(NULL);
}
strcat(buf, v);
if (i < (data->num_in_args - 1))
strcat(buf, " ");
}
return(buf);
}
/* See if an exec is authorized. Either the user has explicitly
* authorized the exec, or she has authorized some commands (which
* implicitly authorizes an exec), or the default is permit.
*
* If she has explicitly authorized an exec, we need to process its
* attribute=value pairs. We indicate this by returning zero to the
* caller.
*
* Otherwise, we return 1, indicating no further processing is
* required for this request.
*/
static int
authorize_exec(char *user, struct author_data *data)
{
NODE *svc;
if (debug & DEBUG_AUTHOR_FLAG)
report(LOG_DEBUG, "exec authorization request for %s", user);
/*
* Is an exec explicitly configured? If so, return 0 so we know to process
* its attributes
*/
svc = cfg_get_svc_node(user, N_svc_exec, NULL, NULL, TAC_PLUS_RECURSE);
if (svc) {
if (debug & DEBUG_AUTHOR_FLAG)
report(LOG_DEBUG, "exec is explicitly permitted by line %d",
svc->line);
return(0);
}
/* No exec is configured. Are any commands configured? */
svc = cfg_get_svc_node(user, N_svc_cmd, NULL, NULL, TAC_PLUS_RECURSE);
if (svc) {
if (debug & DEBUG_AUTHOR_FLAG)
report(LOG_DEBUG, "exec permitted because commands are configured");
data->status = AUTHOR_STATUS_PASS_ADD;
data->output_args = NULL;
data->num_out_args = 0;
return(1);
}
/* No exec or commands configured. What's the default? */
if (cfg_user_svc_default_is_permit(user)) {
if (debug & DEBUG_AUTHOR_FLAG)
report(LOG_DEBUG, "exec permitted by default");
data->status = AUTHOR_STATUS_PASS_ADD;
data->output_args = NULL;
data->num_out_args = 0;
return(1);
}
if (debug & DEBUG_AUTHOR_FLAG)
report(LOG_DEBUG, "exec denied by default");
data->status = AUTHOR_STATUS_FAIL;
data->num_out_args = 0;
return(1);
}
/*
* Is an exec command authorized per our database(s)? Return 0 if status is
* valid.
*/
static int
authorize_cmd(char *user, char *cmd, struct author_data *data)
{
char buf[256];
NODE *node;
char *args;
int match;
args = assemble_args(data);
if (!cmd) {
data->status = AUTHOR_STATUS_ERROR;
data->admin_msg = tac_strdup("No command found");
report(LOG_ERR, "%s: %s %s", session.peer, cmd, data->admin_msg);
data->num_out_args = 0;
return(0);
}
if (debug & DEBUG_AUTHOR_FLAG)
report(LOG_DEBUG, "authorize_cmd: user=%s, cmd=%s", user, cmd);
node = cfg_get_cmd_node(user, cmd, TAC_PLUS_RECURSE);
/* The command does not exist. Do the default */
if (!node) {
if (cfg_user_svc_default_is_permit(user)) {
if (debug & DEBUG_AUTHOR_FLAG)
report(LOG_DEBUG, "cmd %s does not exist, permitted by default",
cmd);
data->status = AUTHOR_STATUS_PASS_ADD;
data->num_out_args = 0;
if (args)
free(args);
return(0);
}
if (debug & DEBUG_AUTHOR_FLAG)
report(LOG_DEBUG, "cmd %s does not exist, denied by default",
cmd);
data->status = AUTHOR_STATUS_FAIL;
data->num_out_args = 0;
if (args)
free(args);
return(0);
}
/* The command exists. The default if nothing matches is DENY */
data->status = AUTHOR_STATUS_FAIL;
data->num_out_args = 0;
for (node = node->value1; node && args; node = node->next) {
match = regexec((regex_t *)node->value1, args, 0, NULL, 0);
if (debug & DEBUG_AUTHOR_FLAG) {
report(LOG_INFO, "line %d compare %s %s '%s' & '%s' %smatch",
node->line, cmd,
node->type == N_permit ? "permit" : "deny",
node->value, args, (match ? "" : "no "));
}
if (match == REG_NOMATCH)
continue;
if (match != REG_OK) {
regerror(match, (regex_t *)node->value1, buf, 256);
report(LOG_INFO, "regexec error: %s on line %d: %s",
(char *)node->value, node->line, buf);
continue;
}
switch (node->type) {
case N_permit:
if (debug & DEBUG_AUTHOR_FLAG) {
report(LOG_DEBUG, "%s %s permitted by line %d",
cmd, args, node->line);
}
data->status = AUTHOR_STATUS_PASS_ADD;
data->num_out_args = 0;
break;
case N_deny:
if (debug & DEBUG_AUTHOR_FLAG) {
report(LOG_DEBUG, "%s %s denied by line %d",
cmd, args, node->line);
}
data->status = AUTHOR_STATUS_FAIL;
data->num_out_args = 0;
break;
default:
data->status = AUTHOR_STATUS_ERROR;
data->admin_msg = tac_strdup("Server error illegal configuration "
"node");
report(LOG_ERR, "%s: %s %s %s",
session.peer, cmd, args, data->admin_msg);
break;
}
if (args)
free(args);
args = NULL;
return(0);
}
if (args)
free(args);
return(0);
}
static int
is_separator(char ch)
{
return(ch == '=' || ch == '*');
}
/* check an attr=value pair for well-formedness */
static int
arg_ok(char *arg)
{
char *p = arg;
/* It must contain an attribute */
if (!*p)
return(0);
for (p = arg; *p; p++) {
if (is_separator(*p)) {
if (p == arg) /* no attribute */
return(0);
return(1);
}
}
/* no separator */
return(0);
}
/* return 1 if attrs match, 0 otherwise */
static int
match_attrs(char *nas_arg, char *server_arg)
{
while (*nas_arg && *server_arg) {
if (is_separator(*nas_arg) && is_separator(*server_arg)) {
return(1);
}
if (*nas_arg != *server_arg)
return(0);
nas_arg++;
server_arg++;
}
return(0);
}
/* return 1 if values match, 0 otherwise */
static int
match_values(char *nas_arg, char *server_arg)
{
while (*nas_arg &&
*server_arg &&
!is_separator(*nas_arg)) {
nas_arg++;
server_arg++;
}
if (!*nas_arg)
return(0);
/* skip separator */
nas_arg++;
if (*server_arg)
server_arg++;
/* compare values */
return(STREQ(nas_arg, server_arg));
}
/* Return 1 if arg is mandatory, 0 otherwise */
static int
mandatory(char *arg)
{
char *p = arg;
while (*p && !is_separator(*p))
p++;
/* if we're not at the end, this must be the separator */
if (*p && !is_separator(*p)) {
report(LOG_ERR, "%s: Error on arg %s cannot find separator",
session.peer, arg);
return(0);
}
return(*p == '=');
}
static int
optional(char *arg)
{
return(!mandatory(arg));
}
/*
* PPP-LCP requests are a special case. If they are not explicitly configured,
* but there are other ppp services explicitly configured, we admit (return 0)
* any PPP-LCP request.
*/
static int
ppp_lcp_allowed(int svc, char *protocol, char *user)
{
/* This is not a ppp/lcp request. Just Say No */
if (!(svc == N_svc_ppp &&
protocol &&
STREQ(protocol, "lcp")))
return(0);
/* It is an LCP request. Are there PPP services configured */
if (cfg_ppp_is_configured(user, TAC_PLUS_RECURSE)) {
if (debug & DEBUG_AUTHOR_FLAG) {
report(LOG_DEBUG,
"ppp/lcp request permitted (ppp is configured for %s)",
user);
}
return(1);
}
/* It is an LCP request but no PPP services are configured */
if (debug & DEBUG_AUTHOR_FLAG) {
report(LOG_DEBUG, "ppp/lcp request denied (ppp not configured for %s)",
user);
}
return(0);
}
/*
* Return 0 means data->status is valid.
* protocol is only valid if svc == ppp.
*/
static int
authorize_svc(char *user, int svc, char *protocol, char *svcname,
struct author_data *data)
{
int max_args;
char **out_args, **outp;
char *nas_arg, *cfg_arg;
int i, j;
char **cfg_args;
char **cfg_argp;
int deny_by_default;
NODE *node;
int replaced = 0;
int added = 0;
int cfg_cnt;
/* Does this service exist? */
node = cfg_get_svc_node(user, svc, protocol, svcname, TAC_PLUS_RECURSE);
if (!node) {
/* Service not found. If the default is permit, or this is an
* PPP/LCP request and other ppp services are configured,
* we'll allow it. */
if (cfg_user_svc_default_is_permit(user)) {
if (debug & DEBUG_AUTHOR_FLAG)
report(LOG_DEBUG, "svc=%s protocol=%s svcname=%s not found, "
"permitted by default", cfg_nodestring(svc),
protocol ? protocol : "", svcname ? svcname : "");
data->status = AUTHOR_STATUS_PASS_ADD;
data->num_out_args = 0;
data->output_args = NULL;
return(0);
}
if (ppp_lcp_allowed(svc, protocol, user)) {
data->status = AUTHOR_STATUS_PASS_ADD;
data->num_out_args = 0;
data->output_args = NULL;
return(0);
}
if (debug & DEBUG_AUTHOR_FLAG)
report(LOG_DEBUG, "svc=%s protocol=%s not found, denied by default",
cfg_nodestring(svc), protocol ? protocol : "");
data->status = AUTHOR_STATUS_FAIL;
data->num_out_args = 0;
data->output_args = NULL;
return(0);
}
/* Get server args configured in the config file. */
cfg_args = cfg_get_svc_attrs(node, &deny_by_default);
/* Check the nas args for well-formedness */
for (i = 0; i < data->num_in_args; i++) {
if (!arg_ok(data->input_args[i])) {
char buf[MAX_INPUT_LINE_LEN+50];
snprintf(buf, sizeof(buf), "Illegal arg %s from NAS",
data->input_args[i]);
data->status = AUTHOR_STATUS_ERROR;
data->admin_msg = tac_strdup(buf);
report(LOG_ERR, "%s: Error %s", session.peer, buf);
/* free any server arguments */
for (cfg_argp = cfg_args; cfg_args && *cfg_argp; cfg_argp++)
free(*cfg_argp);
free(cfg_args);
return(0);
}
}
/* How many configured AV pairs are there ? */
for (cfg_cnt = 0; cfg_args && cfg_args[cfg_cnt];)
cfg_cnt++;
/* Allocate space for in + out args */
max_args = cfg_cnt + data->num_in_args;
out_args = (char **)tac_malloc((max_args + 1) * sizeof(char *));
outp = out_args;
data->num_out_args = 0;
memset(out_args, 0, (max_args + 1) * sizeof(char *));
for (i = 0; i < data->num_in_args; i++) {
nas_arg = data->input_args[i];
/* always pass these pairs through unchanged */
if (match_attrs(nas_arg, "service=") ||
match_attrs(nas_arg, "protocol=") ||
match_attrs(nas_arg, "cmd=")) {
if (debug & DEBUG_AUTHOR_FLAG) {
report(LOG_DEBUG, "nas:%s (passed thru)", nas_arg);
}
*outp++ = tac_strdup(nas_arg);
data->num_out_args++;
continue;
}
/* NAS AV pair is mandatory */
if (mandatory(nas_arg)) {
/*
* a). look for an exact attribute,value match in the daemon's
* mandatory list. If found, add the AV pair to the output
*/
for (j = 0; j < cfg_cnt; j++) {
cfg_arg = cfg_args[j];
if (optional(cfg_arg))
continue;
if (STREQ(nas_arg, cfg_arg)) {
if (debug & DEBUG_AUTHOR_FLAG) {
report(LOG_DEBUG, "nas:%s, svr:%s -> add %s (a)",
nas_arg, cfg_arg, nas_arg);
}
*outp++ = tac_strdup(nas_arg);
data->num_out_args++;
goto next_nas_arg;
}
}
/*
* b). If an exact match doesn't exist, look in the daemon's
* optional list for the first attribute match. If found, add the
* NAS AV pair to the output
*/
for (j = 0; j < cfg_cnt; j++) {
cfg_arg = cfg_args[j];
if (mandatory(cfg_arg))
continue;
if (match_attrs(nas_arg, cfg_arg)) {
if (debug & DEBUG_AUTHOR_FLAG) {
report(LOG_DEBUG, "nas:%s, svr:%s -> add %s (b)",
nas_arg, cfg_arg, nas_arg);
}
*outp++ = tac_strdup(nas_arg);
data->num_out_args++;
goto next_nas_arg;
}
}
/*
* c). If no attribute match exists, deny the command if the
* default is to deny
*/
if (deny_by_default) {
data->status = AUTHOR_STATUS_FAIL;
if (debug & DEBUG_AUTHOR_FLAG) {
report(LOG_DEBUG, "nas:%s svr:absent, default=deny -> "
"denied (c)", nas_arg);
}
if (out_args) {
for (i = 0; i < data->num_out_args; i++)
free(out_args[i]);
free(out_args);
}
data->num_out_args = 0;
data->output_args = NULL;
/* free the server arguments */
for (cfg_argp = cfg_args; *cfg_argp; cfg_argp++)
free(*cfg_argp);
free(cfg_args);
return(0);
}
/*
* d). If the default is permit, add the NAS AV pair to the output
*/
if (debug & DEBUG_AUTHOR_FLAG) {
report(LOG_DEBUG,
"nas:%s, svr:absent, default=permit -> add %s (d)",
nas_arg, nas_arg);
}
*outp++ = tac_strdup(nas_arg);
data->num_out_args++;
goto next_nas_arg;
} else {
/*
* NAS AV pair is Optional
*
* e). look for an exact attribute,value match in the mandatory
* list. If found, add DAEMON's AV pair to output
*/
for (j = 0; j < cfg_cnt; j++) {
cfg_arg = cfg_args[j];
if (optional(cfg_arg))
continue;
if (match_attrs(nas_arg, cfg_arg) &&
match_values(nas_arg, cfg_arg)) {
if (debug & DEBUG_AUTHOR_FLAG) {
report(LOG_DEBUG, "nas:%s svr:%s -> replace with %s "
"(e)", nas_arg, cfg_arg, cfg_arg);
}
*outp++ = tac_strdup(cfg_arg);
data->num_out_args++;
replaced++;
goto next_nas_arg;
}
}
/*
* f). If not found, look for the first attribute match in the
* mandatory list. If found, add DAEMONS's AV pair to output
*/
for (j = 0; j < cfg_cnt; j++) {
cfg_arg = cfg_args[j];
if (optional(cfg_arg))
continue;
if (match_attrs(nas_arg, cfg_arg)) {
if (debug & DEBUG_AUTHOR_FLAG) {
report(LOG_DEBUG, "nas:%s svr:%s -> replace with %s "
"(f)", nas_arg, cfg_arg, cfg_arg);
}
*outp++ = tac_strdup(cfg_arg);
data->num_out_args++;
replaced++;
goto next_nas_arg;
}
}
/*
* g). If no mandatory match exists, look for an exact
* attribute,value pair match among the daemon's optional AV
* pairs. If found add the DAEMON's matching AV pair to the
* output.
*/
for (j = 0; j < cfg_cnt; j++) {
cfg_arg = cfg_args[j];
if (!optional(cfg_arg))
continue;
if (match_attrs(nas_arg, cfg_arg) &&
match_values(nas_arg, cfg_arg)) {
if (debug & DEBUG_AUTHOR_FLAG) {
report(LOG_DEBUG, "nas:%s svr:%s -> replace with %s "
"(g)", nas_arg, cfg_arg, cfg_arg);
}
*outp++ = tac_strdup(cfg_arg);
data->num_out_args++;
replaced++;
goto next_nas_arg;
}
}
/*
* h). If no exact match exists, locate the first attribute match
* among the daemon's optional AV pairs. If found add the DAEMON's
* matching AV pair to the output
*/
for (j = 0; j < cfg_cnt; j++) {
cfg_arg = cfg_args[j];
if (!optional(cfg_arg))
continue;
if (match_attrs(nas_arg, cfg_arg)) {
if (debug & DEBUG_AUTHOR_FLAG) {
report(LOG_DEBUG, "nas:%s svr:%s -> replace with %s "
"(h)", nas_arg, cfg_arg, cfg_arg);
}
*outp++ = tac_strdup(cfg_arg);
data->num_out_args++;
replaced++;
goto next_nas_arg;
}
}
/*
* i). If no match is found, delete the AV pair if default is deny
*/
if (deny_by_default) {
if (debug & DEBUG_AUTHOR_FLAG) {
report(LOG_DEBUG, "nas:%s svr:absent/deny -> delete %s (i)",
nas_arg, nas_arg);
}
replaced++;
goto next_nas_arg;
}
/* j). If the default is permit add the NAS AV pair to the output */
if (debug & DEBUG_AUTHOR_FLAG) {
report(LOG_DEBUG, "nas:%s svr:absent/permit -> add %s (j)",
nas_arg, nas_arg);
}
*outp++ = tac_strdup(nas_arg);
data->num_out_args++;
goto next_nas_arg;
}
next_nas_arg:;
}