This repository has been archived by the owner on Oct 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.y
1885 lines (1625 loc) · 47.7 KB
/
config.y
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$
*
* This program 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.
*
* This program 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 St, Fifth Floor, Boston, MA 02110-1301, USA
*
* For alternative licensing terms, contact licensing@tri-dsystems.com.
*
* Copyright 2006-2008 TRI-D Systems, Inc.
*/
#include "ident.h"
RCSID("$Id$")
extern int yylex(void);
int yyerror(const char *);
int yywrap(void);
#if 0
/* need this first, like LFS; should really be in CPPFLAGS but it's hard */
#if defined(__linux__) && !defined(_GNU_SOURCE)
#define _GNU_SOURCE /* RTLD_DEFAULT */
#endif
#include <dlfcn.h>
#endif
#include "extern.h" /* need EMODE_* early */
#define BACKEND_FILE 0
#define BACKEND_LDAP 1
static void set_user(char *, int);
static void set_log_facility(char *);
static void set_log_level(char *, int);
static void set_plugin_rp(char *, int);
/* the rest of these could be done more elegantly, but whatever */
static void set_backend(char *);
static void set_auth_timeout(int);
static void set_prepend_pin(int);
static void set_hardfail(int);
static void set_softfail(int);
static void set_ewindow_size(int);
static void set_rwindow_size(int);
static void set_site_transform(int);
static void set_file_passwd(char *);
static void set_file_encrypt(int, int);
static void set_file_server(char *);
static void set_ldap_host(char *);
static void set_ldap_port(int);
static void set_ldap_binddn(char *);
static void set_ldap_bindpw(char *);
static void set_ldap_basedn(char *);
static void set_ldap_filter(char *);
static void set_ldap_scope(char *);
static void set_tls_mode(char *);
static void set_tls_verify_cert(char *);
static void set_tls_cacertfile(char *);
static void set_tls_cacertdir(char *);
static void set_tls_certfile(char *);
static void set_tls_keyfile(char *);
static void set_passwd_keyid(int);
static void set_passwd_key(char *);
static void set_state_mode(char *);
static void set_state_filemode(char *);
static void set_statedir(char *);
static void set_state_timeout(int);
static void set_state_gport(int);
static void finish_server(void);
static void set_server_name(char *);
static void set_server_primary(char *);
static void set_server_backup(char *);
static void set_server_timeout(int);
static void set_server_gport(int);
static void set_server_key(char *);
static void finish_file(void);
static void finish_ldap(void);
static void finish_tls(void);
static void finish_key(void);
static void finish_state(void);
static void finish_config(void);
static void userops_init(void);
%}
%union {
int ival;
char *sval;
}
/* ignore shift/reduce conflicts we know of */
%expect 16
%token OTPD
%token USER LOG_FACILITY LOG_LEVEL PLUGIN_RP BACKEND TIMEOUT
%token PREPEND_PIN HARDFAIL SOFTFAIL
%token EWINDOW_SIZE RWINDOW_SIZE SITE_TRANSFORM
%token USER_FILE PASSWD ENCRYPT CLEAR PIN PINMD5 STATE_SERVER
%token USER_LDAP HOST PORT BINDDN BINDPW BASEDN FILTER SCOPE
%token LDAP_TLS MODE VERIFY_CERT CACERTFILE CACERTDIR CERTFILE KEYFILE
%token PASSWDKEY KEYID KEY
%token STATE STATEDIR GPORT SERVER NAME PRIMARY BACKUP FILEMODE
%token <ival> YES NO
%token <sval> WORD
%token <ival> INTEGER
%type <ival> yesno
%%
otpd_section: /* empty */
| OTPD '{' '}'
| OTPD '{' config '}'
config: config_item
| config config_item
config_item: USER '=' WORD { set_user($3, 1); }
| LOG_FACILITY '=' WORD { set_log_facility($3); }
| LOG_LEVEL '=' WORD { set_log_level($3, 1); }
| PLUGIN_RP '=' WORD { set_plugin_rp($3, 1); }
| BACKEND '=' WORD { set_backend($3); }
| TIMEOUT '=' INTEGER { set_auth_timeout($3); }
| PREPEND_PIN '=' yesno { set_prepend_pin($3); }
| HARDFAIL '=' INTEGER { set_hardfail($3); }
| SOFTFAIL '=' INTEGER { set_softfail($3); }
| EWINDOW_SIZE '=' INTEGER { set_ewindow_size($3); }
| RWINDOW_SIZE '=' INTEGER { set_rwindow_size($3); }
| SITE_TRANSFORM '=' yesno { set_site_transform($3); }
| USER_FILE '{' file_config '}' { finish_file(); }
| USER_LDAP '{' ldap_config '}' { finish_ldap(); }
| PASSWDKEY '{' key_config '}' { finish_key(); }
| STATE '{' state_config '}' { finish_state(); }
file_config: /* empty */
| file_config_item
| file_config file_config_item
file_config_item: PASSWD '=' WORD { set_file_passwd($3); }
| ENCRYPT '=' CLEAR { set_file_encrypt(EMODE_CLEAR, 0); }
| ENCRYPT '=' PIN { set_file_encrypt(EMODE_PIN, 0); }
| ENCRYPT '=' PINMD5 { set_file_encrypt(EMODE_PINMD5, 0); }
| ENCRYPT '=' INTEGER { set_file_encrypt(EMODE_KEYID, $3); }
| STATE_SERVER '=' WORD { set_file_server($3); }
ldap_config: ldap_config_item
| ldap_config ldap_config_item
ldap_config_item: HOST '=' WORD { set_ldap_host($3); }
| PORT '=' INTEGER { set_ldap_port($3); }
| BINDDN '=' WORD { set_ldap_binddn($3); }
| BINDPW '=' WORD { set_ldap_bindpw($3); }
| BASEDN '=' WORD { set_ldap_basedn($3); }
| FILTER '=' WORD { set_ldap_filter($3); }
| SCOPE '=' WORD { set_ldap_scope($3); }
| LDAP_TLS '{' tls_config '}' { finish_tls(); }
tls_config: /* empty */
| tls_config_item
| tls_config tls_config_item
tls_config_item: MODE '=' WORD { set_tls_mode($3); }
| VERIFY_CERT '=' WORD { set_tls_verify_cert($3); }
| CACERTFILE '=' WORD { set_tls_cacertfile($3); }
| CACERTDIR '=' WORD { set_tls_cacertdir($3); }
| CERTFILE '=' WORD { set_tls_certfile($3); }
| KEYFILE '=' WORD { set_tls_keyfile($3); }
key_config: key_config_item
| key_config key_config_item
key_config_item: KEYID '=' INTEGER { set_passwd_keyid($3); }
| KEY '=' WORD { set_passwd_key($3); }
state_config: /* empty */
| state_config_item
| state_config state_config_item
state_config_item: MODE '=' WORD { set_state_mode($3); }
| STATEDIR '=' WORD { set_statedir($3); }
| TIMEOUT '=' INTEGER { set_state_timeout($3); }
| GPORT '=' INTEGER { set_state_gport($3); }
| PORT '=' INTEGER { set_state_gport($3); }
| SERVER '{' server_config '}' { finish_server(); }
| FILEMODE '=' WORD { set_state_filemode($3); }
server_config: server_config_item
| server_config server_config_item
server_config_item: NAME '=' WORD { set_server_name($3); }
| PRIMARY '=' WORD { set_server_primary($3); }
| BACKUP '=' WORD { set_server_backup($3); }
| TIMEOUT '=' INTEGER { set_server_timeout($3); }
| GPORT '=' INTEGER { set_server_gport($3); }
| KEY '=' WORD { set_server_key($3); }
yesno: YES | NO
%%
#include <ctype.h>
#include <errno.h>
#include <inttypes.h>
#include <limits.h>
#include <locale.h>
#include <netdb.h>
#include <netinet/in.h>
#include <arpa/nameser.h> /* hstrerror(), must be after netinet/in.h */
#include <pthread.h>
#include <pwd.h>
#include <resolv.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/un.h> /* sockaddr_un */
#include <sys/types.h>
#include <unistd.h>
#include <grp.h>
#include "gsm.h"
extern FILE *yyin;
extern int yylineno;
#ifdef USE_SOCKET
static size_t rp_maxlen = sizeof(((struct sockaddr_un *) 0)->sun_path) - 1;
#endif
static config_t config;
static int seen_user; /* seen user option? */
static int seen_log_facility; /* seen log_facility option? */
static int seen_log_level; /* seen log_level option? */
static char *seen_plugin_rp; /* doubles as seen value */
static int seen_backend; /* seen backend option? */
static int backend; /* backend in use */
static int seen_auth_timeout; /* seen timeout option? */
static int seen_prepend_pin; /* seen prepend_pin option? */
static int seen_hardfail; /* seen hardfail option? */
static int seen_softfail; /* seen softfail option? */
static int seen_ewindow_size; /* seen ewindow_size option? */
static int seen_rwindow_size; /* seen rwindow_size option? */
static int seen_site_transform; /* seen site_transform option? */
static int seen_file; /* seen file section? */
static int seen_ldap; /* seen ldap section? */
static int seen_file_passwd; /* seen file passwd option? */
static int seen_file_encrypt; /* seen file encrypt option? */
static int seen_file_server; /* seen file server option? */
static char *seen_ldap_host; /* doubles as seen value */
static int seen_ldap_port; /* doubles as seen value */
static int seen_ldap_binddn; /* seen ldap binddn option? */
static int seen_ldap_bindpw; /* seen ldap bindpw option? */
static int seen_ldap_basedn; /* seen ldap basedn option? */
static int seen_ldap_filter; /* seen ldap filter option? */
static int seen_ldap_scope; /* seen ldap scope option? */
static int seen_tls_mode; /* seen tls mode option? */
static int seen_tls_verify_cert; /* seen tls verify_cert option? */
static int seen_tls_cacertfile; /* seen tls cacertfile option? */
static int seen_tls_cacertdir; /* seen tls cacertdir option? */
static int seen_tls_certfile; /* seen tls certfile option? */
static int seen_tls_keyfile; /* seen tls keyfile option? */
static int seen_passwd_keyid; /* seen keyid option? */
static int seen_passwd_key; /* seen key option? */
static int seen_state_mode; /* seen state mode option? */
static int seen_statedir; /* seen state statedir option? */
static int64_t seen_gtimeout; /* doubles as current value */
static int seen_gport; /* seen state port option? */
static int seen_state_filemode; /* seen state file mode ? */
static char *seen_server_name; /* doubles as current value */
static char *seen_server_primary; /* doubles as current value */
static char *seen_server_backup; /* doubles as current value */
static int seen_server_timeout; /* doubles as current value */
static int seen_server_gport; /* doubles as current value */
static char *seen_server_key; /* doubles as current value */
static int filekeylineno; /* deferred error reporting */
static int gtimeoutlineno; /* deferred error reporting */
static int primarylineno; /* deferred error reporting */
static int backuplineno; /* deferred error reporting */
static int timeoutlineno; /* deferred error reporting */
static int gsmdkeylineno; /* deferred error reporting */
static int gport; /* default gsmd port, network order */
static struct {
char *name;
char *primary;
char *backup;
int64_t timeout;
int primarylineno; /* deferred error reporting */
int backuplineno; /* deferred error reporting */
int timeoutlineno; /* deferred error reporting */
int gport; /* holding space until port is known */
char *key; /* holding space until port is known */
int keylineno; /* deferred error reporting */
} **gsmd;
static int ngsmd; /* number of gsmd's */
static int using_tls; /* using tls config */
static int passwd_keyid;
static int passwd_keylen;
static unsigned char *passwd_key;
static int using_state; /* state configured */
userops_t userops[OTPD_USEROPS_MAX]; /* initialized by userops ctors */
/*
* parse the config file and validate command line options
* returns an allocated config_t
*/
config_t *
config_init(void)
{
static int once = 0; /* runs in main thread only, no lock needed */
if (!once) {
(void) setlocale(LC_ALL, ""); /* required for yyparse() */
if (rp_maxlen > PATH_MAX)
rp_maxlen = PATH_MAX;
/*
* verify command line options and set defaults
* done here to keep it (validation) all in one place
*/
if (!opt_c)
opt_c = xstrdup(OTPD_DEFAULT_CF);
if (opt_d)
set_log_level(opt_d, 0);
if (opt_u)
set_user(opt_u, 0);
if (opt_p)
set_plugin_rp(xstrdup(opt_p), 0);
userops_init();
once = 1;
} /* if (!once) */
/* open config file */
if (!(yyin = fopen(opt_c, "r"))) {
mlog(LOG_CRIT, "%s: fopen(%s): %s", __func__, opt_c, strerror(errno));
exit(1);
}
/* initialize defaults */
(void) strcpy(config.file.passwd, OTPD_PASSWD);
config.file.encryptmode = EMODE_CLEAR;
config.file.gsmd[0] = '\0';
config.ldap.url = NULL;
config.ldap.binddn = NULL;
config.ldap.bindpw.val = NULL;
config.ldap.basedn = NULL;
config.ldap.filter.val = NULL;
config.ldap.scope = NULL;
config.ldap.tls.mode = 0;
config.ldap.tls.verify_cert = 0;
config.ldap.tls.cacertfile = NULL;
config.ldap.tls.cacertdir = NULL;
config.ldap.tls.certfile = NULL;
config.state.mode = SMODE_LOCAL;
(void) strcpy(config.state.statedir, OTPD_STATEDIR);
config.state.filemode = S_IRUSR|S_IWUSR;
config.timeout = 11700000000LL; /* 11.7s */
config.prepend_pin = 1;
config.hardfail = 0;
config.softfail = 5;
config.ewindow_size = 5;
config.rwindow_size = 25;
config.site_transform = 1;
config.userops = NULL;
{
struct servent *sp;
sp = getservbyname("gsmd", "udp");
if (sp)
gport = sp->s_port;
else
gport = htons(GSM_DEFAULT_GPORT);
}
/* parse config */
seen_user = 0;
seen_log_facility = 0;
seen_log_level = 0;
seen_plugin_rp = NULL;
seen_backend = 0;
backend = BACKEND_FILE;
seen_auth_timeout = 0;
seen_prepend_pin = 0;
seen_hardfail = 0;
seen_softfail = 0;
seen_ewindow_size = 0;
seen_rwindow_size = 0;
seen_site_transform = 0;
seen_file = 0;
seen_ldap = 0;
using_tls = 0;
using_state = 0;
seen_file_passwd = 0;
seen_file_encrypt = 0;
seen_file_server = 0;
seen_ldap_host = NULL;
seen_ldap_port = 0;
seen_ldap_binddn = 0;
seen_ldap_bindpw = 0;
seen_ldap_basedn = 0;
seen_ldap_filter = 0;
seen_ldap_scope = 0;
seen_tls_mode = TLSMODE_OFF;
seen_tls_verify_cert = 0;
seen_tls_cacertfile = 0;
seen_tls_cacertdir = 0;
seen_tls_certfile = 0;
seen_tls_keyfile = 0;
seen_passwd_keyid = 0;
seen_passwd_key = 0;
seen_state_mode = 0;
seen_statedir = 0;
seen_gport = 0;
seen_server_name = NULL;
seen_server_primary = NULL;
seen_server_backup = NULL;
seen_server_gport = 0;
seen_server_timeout = 0;
seen_server_key = NULL;
gsmd = NULL;
ngsmd = 0;
(void) yyparse();
finish_config();
/* validate interdependent parameters */
if (config.hardfail && config.hardfail <= config.softfail) {
/*
* This is noise if the admin leaves softfail alone, so it gets
* the default value of 5, and sets hardfail <= to that ... but
* in practice that will never happen. Anyway, it is easily
* overcome with a softfail setting of 0.
*
* This is because we can't be bothered to tell the difference
* between a default [softfail] value and an admin-configured one.
*/
mlog(LOG_ERR, "%s: hardfail (%d) is less than softfail (%d), "
"effectively disabling softfail",
opt_c, config.hardfail, config.softfail);
}
if (config.rwindow_size && (config.rwindow_size < config.ewindow_size)) {
config.rwindow_size = 0;
mlog(LOG_ERR, "%s: rwindow_size must be at least as large as "
"ewindow_size, disabling", opt_c);
}
/* config is ok */
{
config_t *inst;
inst = xmalloc(sizeof(config));
(void) memcpy(inst, &config, sizeof(config));
return inst;
}
} /* config_init() */
static void
set_user(char *arg, int config_file)
{
unsigned i;
int isuid = 1; /* is this a uid (or name) */
struct passwd *pw;
if (config_file) {
if (seen_user) {
mlog(LOG_NOTICE,
"%s:%d: user option already set, ignoring", opt_c, yylineno);
free(arg);
return;
}
seen_user = 1;
}
if (config_file && opt_u) {
mlog(LOG_INFO, "%s:%d: -u given on command line, ignoring user option",
opt_c, yylineno);
free(arg);
return;
}
/* if arg is all digits, this is a uid */
for (i = 0; i < strlen(arg); ++i) {
if (!isdigit(arg[i])) {
isuid = 0;
break;
}
}
errno = 0; /* getpw* returns NULL on both not found and error */
if (isuid)
pw = getpwuid(atoi(arg));
else
pw = getpwnam(arg);
if (!pw) {
if (errno) {
if (config_file)
mlog(LOG_CRIT, "%s:%d: user lookup error: %s",
opt_c, yylineno, strerror(errno));
else
mlog(LOG_CRIT, "-u: user lookup error: %s", strerror(errno));
} else {
if (config_file)
mlog(LOG_CRIT, "%s:%d: user unknown", opt_c, yylineno);
else
mlog(LOG_CRIT, "-u: user unknown");
}
exit(1);
}
if (config_file)
free(arg);
/* setgid() first, while we have privs */
xsetgid(pw->pw_gid);
(void) setgroups(0, NULL);
xsetuid(pw->pw_uid);
}
#ifndef LOG_AUTHPRIV
#define LOG_AUTHPRIV LOG_AUTH
#endif
#ifndef LOG_FTP
#define LOG_FTP LOG_DAEMON
#endif
#ifndef LOG_AUDIT
#define LOG_AUDIT LOG_AUTH
#endif
static struct {
const char *name;
int facility;
} fac_names[] = {
{ .name = "user", .facility = LOG_USER },
{ .name = "mail", .facility = LOG_MAIL },
{ .name = "daemon", .facility = LOG_DAEMON },
{ .name = "ftp", .facility = LOG_FTP },
{ .name = "auth", .facility = LOG_AUTH },
{ .name = "authpriv", .facility = LOG_AUTHPRIV },
{ .name = "lpr", .facility = LOG_LPR },
{ .name = "news", .facility = LOG_NEWS },
{ .name = "uucp", .facility = LOG_UUCP },
{ .name = "cron", .facility = LOG_CRON },
{ .name = "audit", .facility = LOG_AUDIT },
{ .name = "local0", .facility = LOG_LOCAL0 },
{ .name = "local1", .facility = LOG_LOCAL1 },
{ .name = "local2", .facility = LOG_LOCAL2 },
{ .name = "local3", .facility = LOG_LOCAL3 },
{ .name = "local4", .facility = LOG_LOCAL4 },
{ .name = "local5", .facility = LOG_LOCAL5 },
{ .name = "local6", .facility = LOG_LOCAL6 },
{ .name = "local7", .facility = LOG_LOCAL7 },
{ .name = NULL, .facility = 0 }
};
/* set log_facility option */
static void
set_log_facility(char *arg)
{
int i, facility = -1;
if (seen_log_facility) {
mlog(LOG_NOTICE,
"%s:%d: log_facility option already set, ignoring", opt_c, yylineno);
return;
}
seen_log_facility = 1;
/* convert facility name to int */
for (i = 0; fac_names[i].name; ++i) {
if (!strcmp(fac_names[i].name, arg)) {
facility = fac_names[i].facility;
break;
}
}
if (facility >= 0) {
log_facility = facility;
return;
}
/* no match */
mlog(LOG_CRIT, "%s:%d: invalid log_facility", opt_c, yylineno);
exit(1);
}
static struct {
const char *name;
int priority;
} pri_names[] = {
{ .name = "emerg", .priority = LOG_EMERG },
{ .name = "alert", .priority = LOG_ALERT },
{ .name = "crit", .priority = LOG_CRIT },
{ .name = "err", .priority = LOG_ERR },
{ .name = "warning", .priority = LOG_WARNING },
{ .name = "notice", .priority = LOG_NOTICE },
{ .name = "info", .priority = LOG_INFO },
{ .name = "debug", .priority = LOG_DEBUG },
{ .name = "debug0", .priority = LOG_DEBUG0 },
{ .name = "debug1", .priority = LOG_DEBUG1 },
{ .name = "debug2", .priority = LOG_DEBUG2 },
{ .name = "debug3", .priority = LOG_DEBUG3 },
{ .name = "debug4", .priority = LOG_DEBUG4 },
{ .name = "debug5", .priority = LOG_DEBUG5 },
{ .name = "debug6", .priority = LOG_DEBUG6 },
{ .name = "debug7", .priority = LOG_DEBUG7 },
{ .name = "debug8", .priority = LOG_DEBUG8 },
{ .name = NULL, .priority = 0 }
};
/* set log_level option */
static void
set_log_level(char *arg, int config_file)
{
int i, level = -1;
if (config_file) {
if (seen_log_level) {
mlog(LOG_NOTICE,
"%s:%d: log_level option already set, ignoring", opt_c, yylineno);
free(arg);
return;
}
seen_log_level = 1;
}
/* convert priority name to int */
for (i = 0; pri_names[i].name; ++i) {
if (!strcmp(pri_names[i].name, arg)) {
level = pri_names[i].priority;
break;
}
}
if (config_file)
free(arg);
if (level >= 0) {
if (config_file && opt_d)
mlog(LOG_INFO,
"%s:%d: -d given on command line, ignoring log_level option",
opt_c, yylineno);
else
log_level = level;
return;
}
/* no match */
if (config_file)
mlog(LOG_CRIT, "%s:%d: invalid log_level", opt_c, yylineno);
else
mlog(LOG_CRIT, "-d: invalid log_level");
exit(1);
}
/* set plugin_rp option */
static void
set_plugin_rp(char *arg, int config_file)
{
if (config_file) {
if (seen_plugin_rp) {
mlog(LOG_NOTICE,
"%s:%d: plugin_rp option already set, ignoring", opt_c, yylineno);
free(arg);
return;
}
}
if (arg[0] != '/') {
mlog(LOG_CRIT, "%s:%d: plugin_rp name not absolute", opt_c, yylineno);
exit(1);
}
if (strlen(arg) > rp_maxlen) {
if (config_file)
mlog(LOG_CRIT, "%s:%d: plugin_rp name too long", opt_c, yylineno);
else
mlog(LOG_CRIT, "-p: plugin_rp name too long");
exit(1);
}
/* could have done this earlier, but we always want the sanity checks */
if (config_file && opt_p) {
mlog(LOG_INFO, "%s:%d: -p given on command line, ignoring plugin_rp option",
opt_c, yylineno);
free(arg);
return;
}
seen_plugin_rp = arg;
}
static void
set_backend(char *arg)
{
if (seen_backend) {
mlog(LOG_NOTICE,
"%s:%d: backend option already set, ignoring", opt_c, yylineno);
return;
}
seen_backend = 1;
if (!strcmp(arg, "file")) {
backend = BACKEND_FILE;
} else if (!strcmp(arg, "ldap")) {
backend = BACKEND_LDAP;
} else {
mlog(LOG_CRIT, "%s:%d: invalid backend option", opt_c, yylineno);
exit(1);
}
}
/* set timeout option */
static void
set_auth_timeout(int arg)
{
if (seen_auth_timeout) {
mlog(LOG_NOTICE,
"%s:%d: timeout option already set, ignoring", opt_c, yylineno);
return;
}
seen_auth_timeout = 1;
if (arg < 3000) {
mlog(LOG_CRIT, "%s:%d: minimum timeout is 3000", opt_c, yylineno);
exit(1);
}
config.timeout = arg * 1000000; /* arg is in ms, timeout is in ns */
}
/* set prepend_pin option */
static void
set_prepend_pin(int arg)
{
if (seen_prepend_pin) {
mlog(LOG_NOTICE,
"%s:%d: prepend_pin option already set, ignoring", opt_c, yylineno);
return;
}
seen_prepend_pin = 1;
config.prepend_pin = arg;
}
/* set hardfail option */
static void
set_hardfail(int arg)
{
if (seen_hardfail) {
mlog(LOG_NOTICE,
"%s:%d: hardfail option already set, ignoring", opt_c, yylineno);
return;
}
seen_hardfail = 1;
config.hardfail = arg;
}
/* set softfail option */
static void
set_softfail(int arg)
{
if (seen_softfail) {
mlog(LOG_NOTICE,
"%s:%d: softfail option already set, ignoring", opt_c, yylineno);
return;
}
seen_softfail = 1;
config.softfail = arg;
}
/* set ewindow_size option */
static void
set_ewindow_size(int arg)
{
if (seen_ewindow_size) {
mlog(LOG_NOTICE,
"%s:%d: ewindow_size option already set, ignoring", opt_c, yylineno);
return;
}
seen_ewindow_size = 1;
config.ewindow_size = arg;
}
/* set rwindow_size option */
static void
set_rwindow_size(int arg)
{
if (seen_rwindow_size) {
mlog(LOG_NOTICE,
"%s:%d: rwindow_size option already set, ignoring", opt_c, yylineno);
return;
}
seen_rwindow_size = 1;
config.rwindow_size = arg;
}
/* set site_transform option */
static void
set_site_transform(int arg)
{
if (seen_site_transform) {
mlog(LOG_NOTICE,
"%s:%d: site_transform option already set, ignoring", opt_c, yylineno);
return;
}
seen_site_transform = 1;
config.site_transform = arg;
}
/* set file passwd option */
static void
set_file_passwd(char *arg)
{
if (seen_file_passwd) {
mlog(LOG_NOTICE,
"%s:%d: file passwd option already set, ignoring", opt_c, yylineno);
free(arg);
return;
}
seen_file_passwd = 1;
if (arg[0] != '/') {
mlog(LOG_CRIT, "%s:%d: file passwd name not absolute", opt_c, yylineno);
exit(1);
}
if (access(arg, F_OK) == -1) {
mlog(LOG_CRIT, "%s:%d: %s: %s", opt_c, yylineno, arg, strerror(errno));
exit(1);
}
(void) strcpy(config.file.passwd, arg);
free(arg);
}
/* set file encrypt option */
static void
set_file_encrypt(int mode, int id)
{
if (seen_file_encrypt) {
mlog(LOG_NOTICE,
"%s:%d: file encrypt option already set, ignoring", opt_c, yylineno);
return;
}
seen_file_encrypt = 1;
/* see finish_key() */
if (id > 127) {
mlog(LOG_CRIT, "%s:%d: key id %d too large", opt_c, yylineno, id);
exit(1);
}
config.file.encryptmode = mode;
config.file.keyid = id;
filekeylineno = yylineno;
}
/* set file server option */
static void
set_file_server(char *arg)
{
if (seen_file_server) {
mlog(LOG_NOTICE,
"%s:%d: file server option already set, ignoring", opt_c, yylineno);
return;
}
seen_file_server = 1;
if (strlen(arg) > GSM_MAX_NAME_LEN) {
mlog(LOG_CRIT, "%s:%d: file server name too long", opt_c, yylineno);
exit(1);
}
(void) strcpy(config.file.gsmd, arg);
}
/* set ldap host option */
static void
set_ldap_host(char *arg)
{
if (seen_ldap_host) {
mlog(LOG_NOTICE,
"%s:%d: ldap host option already set, ignoring", opt_c, yylineno);
free(arg);
return;
}
/*
* Attempt to validate the hostname.
* We can't be 100% sure that ldap_initialize() (which doesn't actually
* connect()) does the same thing, but it's hard to imagine much different.
*/
{
struct hostent *hp;
if ((hp = gethostbyname(arg)) == NULL) {
mlog(LOG_CRIT, "%s:%d: ldap host name is invalid: %s",
opt_c, yylineno, hstrerror(h_errno));
exit(1);
}
}
seen_ldap_host = arg;
}
/* set ldap port option */
static void
set_ldap_port(int arg)
{
if (seen_ldap_port) {
mlog(LOG_NOTICE,
"%s:%d: ldap port option already set, ignoring", opt_c, yylineno);
return;
}
if (arg == 0 || arg > 65535) {
mlog(LOG_CRIT, "%s:%d: invalid ldap port", opt_c, yylineno);
exit(1);
}
seen_ldap_port = arg;
}
/* set ldap binddn option */
static void
set_ldap_binddn(char *arg)
{
if (seen_ldap_binddn) {
mlog(LOG_NOTICE,
"%s:%d: ldap binddn option already set, ignoring", opt_c, yylineno);
free(arg);
return;
}
seen_ldap_binddn = 1;
config.ldap.binddn = arg;
}
/* set ldap bindpw option */
static void
set_ldap_bindpw(char *arg)
{
if (seen_ldap_bindpw) {
mlog(LOG_NOTICE,
"%s:%d: ldap bindpw option already set, ignoring", opt_c, yylineno);
free(arg);
return;
}
seen_ldap_bindpw = 1;