GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: usr.sbin/sasyncd/conf.c Lines: 0 190 0.0 %
Date: 2017-11-07 Branches: 0 159 0.0 %

Line Branch Exec Source
1
#include <stdlib.h>
2
#include <string.h>
3
#define YYBYACC 1
4
#define YYMAJOR 1
5
#define YYMINOR 9
6
#define YYLEX yylex()
7
#define YYEMPTY -1
8
#define yyclearin (yychar=(YYEMPTY))
9
#define yyerrok (yyerrflag=0)
10
#define YYRECOVERING() (yyerrflag!=0)
11
#define YYPREFIX "yy"
12
#line 30 "conf.y"
13
#include <sys/types.h>
14
#include <sys/stat.h>
15
#include <sys/socket.h>
16
#include <ctype.h>
17
#include <fcntl.h>
18
#include <stdio.h>
19
#include <stdlib.h>
20
#include <string.h>
21
#include <unistd.h>
22
#include <pwd.h>
23
24
#include "sasyncd.h"
25
#include "net.h"
26
27
/* Global configuration context.  */
28
struct cfgstate	cfgstate;
29
30
/* Local variables */
31
int	conflen = 0;
32
char	*confbuf, *confptr;
33
34
int	yyparse(void);
35
int	yylex(void);
36
void	yyerror(const char *);
37
unsigned char x2i(unsigned char *);
38
#line 57 "conf.y"
39
#ifndef YYSTYPE_DEFINED
40
#define YYSTYPE_DEFINED
41
typedef union {
42
	char	*string;
43
	int	 val;
44
	struct {
45
		unsigned char	*data;
46
		int	 len;
47
	} hex;
48
} YYSTYPE;
49
#endif /* YYSTYPE_DEFINED */
50
#line 51 "conf.c"
51
#define MODE 257
52
#define INTERFACE 258
53
#define INTERVAL 259
54
#define LISTEN 260
55
#define ON 261
56
#define PORT 262
57
#define PEER 263
58
#define SHAREDKEY 264
59
#define Y_SLAVE 265
60
#define Y_MASTER 266
61
#define INET 267
62
#define INET6 268
63
#define FLUSHMODE 269
64
#define STARTUP 270
65
#define NEVER 271
66
#define SYNC 272
67
#define GROUP 273
68
#define SKIPSLAVE 274
69
#define CONTROL 275
70
#define STRING 276
71
#define HEX 277
72
#define VALUE 278
73
#define YYERRCODE 256
74
const short yylhs[] =
75
	{                                        -1,
76
    0,    0,    1,    1,    1,    2,    2,    3,    3,    7,
77
    7,    4,    4,    4,    8,    8,    5,    6,    6,    6,
78
    6,    6,    6,    6,    6,
79
};
80
const short yylen[] =
81
	{                                         2,
82
    0,    2,    0,    1,    1,    0,    2,    1,    1,    1,
83
    1,    1,    1,    1,    1,    1,    1,    2,    2,    2,
84
    2,    5,    2,    2,    2,
85
};
86
const short yydefred[] =
87
	{                                      1,
88
    0,    0,    0,    0,    0,    0,    0,    0,    0,    2,
89
    9,    8,   10,   11,   23,   18,    0,   21,   15,   16,
90
   24,   12,   13,   14,   20,   19,   17,   25,    0,    4,
91
    5,    0,    0,   22,    7,
92
};
93
const short yydgoto[] =
94
	{                                       1,
95
   32,   34,   14,   25,   28,   10,   15,   21,
96
};
97
const short yysindex[] =
98
	{                                      0,
99
 -253, -251, -276, -244, -270, -274, -246, -268, -258,    0,
100
    0,    0,    0,    0,    0,    0, -257,    0,    0,    0,
101
    0,    0,    0,    0,    0,    0,    0,    0, -255,    0,
102
    0, -241, -250,    0,    0,};
103
const short yyrindex[] =
104
	{                                      0,
105
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
106
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
107
    0,    0,    0,    0,    0,    0,    0,    0,    1,    0,
108
    0,    9,    0,    0,    0,};
109
const short yygindex[] =
110
	{                                      0,
111
    0,    0,    0,    0,    0,    0,    0,    0,
112
};
113
#define YYTABLESIZE 284
114
const short yytable[] =
115
	{                                      16,
116
    3,   19,   20,    2,    3,   18,    4,   26,    6,    5,
117
    6,   30,   31,   11,   12,    7,   17,   27,   29,    8,
118
   33,    9,   13,   22,   23,   24,    0,   35,    0,    0,
119
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
120
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
121
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
122
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
123
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
124
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
125
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
126
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
127
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
128
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
129
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
130
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
131
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
132
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
133
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
134
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
135
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
136
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
137
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
138
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
139
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
140
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
141
    0,    0,    0,    0,    0,    0,    0,    3,    3,    0,
142
    3,    0,    3,    3,    3,    6,    6,    0,    6,    3,
143
    0,    6,    6,    3,    0,    3,    0,    6,    0,    0,
144
    0,    6,    0,    6,
145
};
146
const short yycheck[] =
147
	{                                     276,
148
    0,  276,  277,  257,  258,  276,  260,  276,    0,  263,
149
  264,  267,  268,  265,  266,  269,  261,  276,  276,  273,
150
  262,  275,  274,  270,  271,  272,   -1,  278,   -1,   -1,
151
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
152
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
153
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
154
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
155
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
156
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
157
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
158
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
159
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
160
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
161
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
162
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
163
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
164
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
165
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
166
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
167
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
168
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
169
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
170
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
171
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
172
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
173
   -1,   -1,   -1,   -1,   -1,   -1,   -1,  257,  258,   -1,
174
  260,   -1,  262,  263,  264,  257,  258,   -1,  260,  269,
175
   -1,  263,  264,  273,   -1,  275,   -1,  269,   -1,   -1,
176
   -1,  273,   -1,  275,
177
};
178
#define YYFINAL 1
179
#ifndef YYDEBUG
180
#define YYDEBUG 0
181
#endif
182
#define YYMAXTOKEN 278
183
#if YYDEBUG
184
const char * const yyname[] =
185
	{
186
"end-of-file",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
187
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
188
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
189
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
190
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
191
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
192
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"MODE","INTERFACE","INTERVAL",
193
"LISTEN","ON","PORT","PEER","SHAREDKEY","Y_SLAVE","Y_MASTER","INET","INET6",
194
"FLUSHMODE","STARTUP","NEVER","SYNC","GROUP","SKIPSLAVE","CONTROL","STRING",
195
"HEX","VALUE",
196
};
197
const char * const yyrule[] =
198
	{"$accept : settings",
199
"settings :",
200
"settings : settings setting",
201
"af :",
202
"af : INET",
203
"af : INET6",
204
"port :",
205
"port : PORT VALUE",
206
"mode : Y_MASTER",
207
"mode : Y_SLAVE",
208
"modes : SKIPSLAVE",
209
"modes : mode",
210
"flushmode : STARTUP",
211
"flushmode : NEVER",
212
"flushmode : SYNC",
213
"key : STRING",
214
"key : HEX",
215
"ctlmode : STRING",
216
"setting : INTERFACE STRING",
217
"setting : GROUP STRING",
218
"setting : FLUSHMODE flushmode",
219
"setting : PEER STRING",
220
"setting : LISTEN ON STRING af port",
221
"setting : MODE modes",
222
"setting : SHAREDKEY key",
223
"setting : CONTROL ctlmode",
224
};
225
#endif
226
#ifdef YYSTACKSIZE
227
#undef YYMAXDEPTH
228
#define YYMAXDEPTH YYSTACKSIZE
229
#else
230
#ifdef YYMAXDEPTH
231
#define YYSTACKSIZE YYMAXDEPTH
232
#else
233
#define YYSTACKSIZE 10000
234
#define YYMAXDEPTH 10000
235
#endif
236
#endif
237
#define YYINITSTACKSIZE 200
238
/* LINTUSED */
239
int yydebug;
240
int yynerrs;
241
int yyerrflag;
242
int yychar;
243
short *yyssp;
244
YYSTYPE *yyvsp;
245
YYSTYPE yyval;
246
YYSTYPE yylval;
247
short *yyss;
248
short *yysslim;
249
YYSTYPE *yyvs;
250
unsigned int yystacksize;
251
int yyparse(void);
252
#line 241 "conf.y"
253
/* Program */
254
255
struct keyword {
256
	char *name;
257
	int   value;
258
};
259
260
static int
261
match_cmp(const void *a, const void *b)
262
{
263
	return strcmp(a, ((const struct keyword *)b)->name);
264
}
265
266
static int
267
match(char *token)
268
{
269
	/* Sorted */
270
	static const struct keyword keywords[] = {
271
		{ "control", CONTROL },
272
		{ "flushmode", FLUSHMODE },
273
		{ "group", GROUP },
274
		{ "inet", INET },
275
		{ "inet6", INET6 },
276
		{ "interface", INTERFACE },
277
		{ "listen", LISTEN },
278
		{ "master", Y_MASTER },
279
		{ "mode", MODE },
280
		{ "never", NEVER },
281
		{ "on", ON },
282
		{ "peer", PEER },
283
		{ "port", PORT },
284
		{ "sharedkey", SHAREDKEY },
285
		{ "skipslave", SKIPSLAVE },
286
		{ "slave", Y_SLAVE },
287
		{ "startup", STARTUP },
288
		{ "sync", SYNC },
289
	};
290
	const struct keyword *k;
291
292
	k = bsearch(token, keywords, sizeof keywords / sizeof keywords[0],
293
	    sizeof keywords[0], match_cmp);
294
295
	return k ? k->value : STRING;
296
}
297
298
int
299
yylex(void)
300
{
301
	char *p;
302
	int v, i, len;
303
304
	/* Locate next token */
305
	if (!confptr)
306
		confptr = confbuf;
307
	else {
308
		for (p = confptr; p < confbuf + conflen && *p; p++)
309
			;
310
		if (p == confbuf + conflen)
311
			return 0;
312
		p++;
313
		if (!*p)
314
			return 0;
315
		confptr = p;
316
	}
317
318
	/* Hex token? */
319
	p = confptr;
320
	if (!strncmp(p, "0x", 2)) {
321
		for (p = confptr + 2; *p; p++)
322
			if (!isxdigit(*p))
323
				goto is_string;
324
		p = confptr + 2;
325
		len = strlen(p) / 2;
326
		if ((yylval.hex.data = calloc(len, sizeof(unsigned char)))
327
		    == NULL) {
328
			log_err("yylex: calloc()");
329
			exit(1);
330
		}
331
		for (i = 0; i < len; i++)
332
			yylval.hex.data[i] = x2i(p + 2 * i);
333
		yylval.hex.len = len;
334
		return HEX;
335
	}
336
337
	/* Numerical token? */
338
	if (isdigit(*confptr)) {
339
		for (p = confptr; *p; p++)
340
			if (*p == '.') /* IP address, or bad input */
341
				goto is_string;
342
		v = (int)strtol(confptr, (char **)NULL, 10);
343
		yylval.val = v;
344
		return VALUE;
345
	}
346
347
  is_string:
348
	v = match(confptr);
349
	if (v == STRING) {
350
		yylval.string = strdup(confptr);
351
		if (!yylval.string) {
352
			log_err("yylex: strdup()");
353
			exit(1);
354
		}
355
	}
356
	return v;
357
}
358
359
int
360
conf_parse_file(char *cfgfile)
361
{
362
	struct stat	st;
363
	int		fd, r;
364
	char		*buf, *s, *d;
365
	struct passwd	*pw;
366
367
	if (stat(cfgfile, &st) != 0)
368
		goto bad;
369
370
	pw = getpwnam(SASYNCD_USER);
371
	if (pw == NULL) {
372
		log_err("getpwnam(%s) failed", SASYNCD_USER);
373
		return 1;
374
	}
375
376
	/* Valid file? */
377
	if ((st.st_uid && st.st_uid != pw->pw_uid) ||
378
	    ((st.st_mode & S_IFMT) != S_IFREG) ||
379
	    ((st.st_mode & (S_IRWXG | S_IRWXO)) != 0)) {
380
		log_msg(0, "configuration file has bad owner, type or mode");
381
		goto bad;
382
	}
383
384
	fd = open(cfgfile, O_RDONLY, 0);
385
	if (fd < 0)
386
		goto bad;
387
388
	conflen = st.st_size;
389
	buf = malloc(conflen + 1);
390
	if (!buf) {
391
		log_err("malloc(%d) failed", conflen + 1);
392
		close(fd);
393
		return 1;
394
	}
395
396
	if (read(fd, buf, conflen) != conflen) {
397
		log_err("read() failed");
398
		free(buf);
399
		close(fd);
400
		return 1;
401
	}
402
	close(fd);
403
404
	/* Prepare the buffer somewhat in the way of strsep() */
405
	buf[conflen] = (char)0;
406
	for (s = buf, d = s; s < buf + conflen && *s; s++) {
407
		if (isspace(*s) && isspace(*(s+1)))
408
			continue;
409
		if (*s == '#') {
410
			while (*s != '\n' && s < buf + conflen)
411
				s++;
412
			continue;
413
		}
414
		if (d == buf && isspace(*s))
415
			continue;
416
		*d++ = *s;
417
	}
418
	*d = (char)0;
419
	for (s = buf; s <= d; s++)
420
		if (isspace(*s))
421
			*s = (char)0;
422
423
	confbuf = buf;
424
	confptr = NULL;
425
	r = yyparse();
426
	free(buf);
427
428
	if (!cfgstate.carp_ifgroup)
429
		cfgstate.carp_ifgroup = strdup("carp");
430
431
	return r;
432
433
  bad:
434
	log_msg(0, "failed to open \"%s\"", cfgfile);
435
	return 1;
436
}
437
438
unsigned char
439
x2i(unsigned char *s)
440
{
441
        char    ss[3];
442
443
        ss[0] = s[0];
444
        ss[1] = s[1];
445
        ss[2] = 0;
446
447
        return ((unsigned char)strtoul(ss, NULL, 16));
448
}
449
450
void
451
yyerror(const char *s)
452
{
453
	fprintf(stderr, "config: %s\n", s);
454
}
455
#line 448 "conf.c"
456
/* allocate initial stack or double stack size, up to YYMAXDEPTH */
457
static int yygrowstack(void)
458
{
459
    unsigned int newsize;
460
    long sslen;
461
    short *newss;
462
    YYSTYPE *newvs;
463
464
    if ((newsize = yystacksize) == 0)
465
        newsize = YYINITSTACKSIZE;
466
    else if (newsize >= YYMAXDEPTH)
467
        return -1;
468
    else if ((newsize *= 2) > YYMAXDEPTH)
469
        newsize = YYMAXDEPTH;
470
    sslen = yyssp - yyss;
471
#ifdef SIZE_MAX
472
#define YY_SIZE_MAX SIZE_MAX
473
#else
474
#define YY_SIZE_MAX 0xffffffffU
475
#endif
476
    if (newsize && YY_SIZE_MAX / newsize < sizeof *newss)
477
        goto bail;
478
    newss = yyss ? (short *)realloc(yyss, newsize * sizeof *newss) :
479
      (short *)malloc(newsize * sizeof *newss); /* overflow check above */
480
    if (newss == NULL)
481
        goto bail;
482
    yyss = newss;
483
    yyssp = newss + sslen;
484
    if (newsize && YY_SIZE_MAX / newsize < sizeof *newvs)
485
        goto bail;
486
    newvs = yyvs ? (YYSTYPE *)realloc(yyvs, newsize * sizeof *newvs) :
487
      (YYSTYPE *)malloc(newsize * sizeof *newvs); /* overflow check above */
488
    if (newvs == NULL)
489
        goto bail;
490
    yyvs = newvs;
491
    yyvsp = newvs + sslen;
492
    yystacksize = newsize;
493
    yysslim = yyss + newsize - 1;
494
    return 0;
495
bail:
496
    if (yyss)
497
            free(yyss);
498
    if (yyvs)
499
            free(yyvs);
500
    yyss = yyssp = NULL;
501
    yyvs = yyvsp = NULL;
502
    yystacksize = 0;
503
    return -1;
504
}
505
506
#define YYABORT goto yyabort
507
#define YYREJECT goto yyabort
508
#define YYACCEPT goto yyaccept
509
#define YYERROR goto yyerrlab
510
int
511
yyparse(void)
512
{
513
    int yym, yyn, yystate;
514
#if YYDEBUG
515
    const char *yys;
516
517
    if ((yys = getenv("YYDEBUG")))
518
    {
519
        yyn = *yys;
520
        if (yyn >= '0' && yyn <= '9')
521
            yydebug = yyn - '0';
522
    }
523
#endif /* YYDEBUG */
524
525
    yynerrs = 0;
526
    yyerrflag = 0;
527
    yychar = (-1);
528
529
    if (yyss == NULL && yygrowstack()) goto yyoverflow;
530
    yyssp = yyss;
531
    yyvsp = yyvs;
532
    *yyssp = yystate = 0;
533
534
yyloop:
535
    if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
536
    if (yychar < 0)
537
    {
538
        if ((yychar = yylex()) < 0) yychar = 0;
539
#if YYDEBUG
540
        if (yydebug)
541
        {
542
            yys = 0;
543
            if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
544
            if (!yys) yys = "illegal-symbol";
545
            printf("%sdebug: state %d, reading %d (%s)\n",
546
                    YYPREFIX, yystate, yychar, yys);
547
        }
548
#endif
549
    }
550
    if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
551
            yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
552
    {
553
#if YYDEBUG
554
        if (yydebug)
555
            printf("%sdebug: state %d, shifting to state %d\n",
556
                    YYPREFIX, yystate, yytable[yyn]);
557
#endif
558
        if (yyssp >= yysslim && yygrowstack())
559
        {
560
            goto yyoverflow;
561
        }
562
        *++yyssp = yystate = yytable[yyn];
563
        *++yyvsp = yylval;
564
        yychar = (-1);
565
        if (yyerrflag > 0)  --yyerrflag;
566
        goto yyloop;
567
    }
568
    if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
569
            yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
570
    {
571
        yyn = yytable[yyn];
572
        goto yyreduce;
573
    }
574
    if (yyerrflag) goto yyinrecovery;
575
#if defined(__GNUC__)
576
    goto yynewerror;
577
#endif
578
yynewerror:
579
    yyerror("syntax error");
580
#if defined(__GNUC__)
581
    goto yyerrlab;
582
#endif
583
yyerrlab:
584
    ++yynerrs;
585
yyinrecovery:
586
    if (yyerrflag < 3)
587
    {
588
        yyerrflag = 3;
589
        for (;;)
590
        {
591
            if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 &&
592
                    yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
593
            {
594
#if YYDEBUG
595
                if (yydebug)
596
                    printf("%sdebug: state %d, error recovery shifting\
597
 to state %d\n", YYPREFIX, *yyssp, yytable[yyn]);
598
#endif
599
                if (yyssp >= yysslim && yygrowstack())
600
                {
601
                    goto yyoverflow;
602
                }
603
                *++yyssp = yystate = yytable[yyn];
604
                *++yyvsp = yylval;
605
                goto yyloop;
606
            }
607
            else
608
            {
609
#if YYDEBUG
610
                if (yydebug)
611
                    printf("%sdebug: error recovery discarding state %d\n",
612
                            YYPREFIX, *yyssp);
613
#endif
614
                if (yyssp <= yyss) goto yyabort;
615
                --yyssp;
616
                --yyvsp;
617
            }
618
        }
619
    }
620
    else
621
    {
622
        if (yychar == 0) goto yyabort;
623
#if YYDEBUG
624
        if (yydebug)
625
        {
626
            yys = 0;
627
            if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
628
            if (!yys) yys = "illegal-symbol";
629
            printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
630
                    YYPREFIX, yystate, yychar, yys);
631
        }
632
#endif
633
        yychar = (-1);
634
        goto yyloop;
635
    }
636
yyreduce:
637
#if YYDEBUG
638
    if (yydebug)
639
        printf("%sdebug: state %d, reducing by rule %d (%s)\n",
640
                YYPREFIX, yystate, yyn, yyrule[yyn]);
641
#endif
642
    yym = yylen[yyn];
643
    if (yym)
644
        yyval = yyvsp[1-yym];
645
    else
646
        memset(&yyval, 0, sizeof yyval);
647
    switch (yyn)
648
    {
649
case 3:
650
#line 81 "conf.y"
651
{ yyval.val = AF_UNSPEC; }
652
break;
653
case 4:
654
#line 82 "conf.y"
655
{ yyval.val = AF_INET; }
656
break;
657
case 5:
658
#line 83 "conf.y"
659
{ yyval.val = AF_INET6; }
660
break;
661
case 6:
662
#line 86 "conf.y"
663
{ yyval.val = SASYNCD_DEFAULT_PORT; }
664
break;
665
case 7:
666
#line 87 "conf.y"
667
{ yyval.val = yyvsp[0].val; }
668
break;
669
case 8:
670
#line 90 "conf.y"
671
{ yyval.val = MASTER; }
672
break;
673
case 9:
674
#line 91 "conf.y"
675
{ yyval.val = SLAVE; }
676
break;
677
case 10:
678
#line 95 "conf.y"
679
{
680
			cfgstate.flags |= SKIP_LOCAL_SAS;
681
			log_msg(2, "config: not syncing SA to peers");
682
		}
683
break;
684
case 11:
685
#line 100 "conf.y"
686
{
687
			const char *m[] = CARPSTATES;
688
			cfgstate.lockedstate = yyvsp[0].val;
689
			log_msg(2, "config: mode set to %s", m[yyvsp[0].val]);
690
		}
691
break;
692
case 12:
693
#line 107 "conf.y"
694
{ yyval.val = FM_STARTUP; }
695
break;
696
case 13:
697
#line 108 "conf.y"
698
{ yyval.val = FM_NEVER; }
699
break;
700
case 14:
701
#line 109 "conf.y"
702
{ yyval.val = FM_SYNC; }
703
break;
704
case 15:
705
#line 113 "conf.y"
706
{
707
			if (cfgstate.sharedkey)
708
				free(cfgstate.sharedkey);
709
			cfgstate.sharedkey = yyvsp[0].string;
710
			cfgstate.sharedkey_len = strlen(yyvsp[0].string) * 8;
711
			log_msg(2, "config: shared ascii key");
712
		}
713
break;
714
case 16:
715
#line 121 "conf.y"
716
{
717
			if (cfgstate.sharedkey)
718
				free(cfgstate.sharedkey);
719
			cfgstate.sharedkey = yyvsp[0].hex.data;
720
			cfgstate.sharedkey_len = yyvsp[0].hex.len * 8;
721
			log_msg(2, "config: %d byte shared hex key", yyvsp[0].hex.len);
722
		}
723
break;
724
case 17:
725
#line 130 "conf.y"
726
{
727
			/* Compare strings to avoid keywords for daemons */
728
			if (strcmp("isakmpd", yyvsp[0].string) == 0)
729
				yyval.val = CTL_ISAKMPD;
730
			else if (strcmp("iked", yyvsp[0].string) == 0)
731
				yyval.val = CTL_IKED;
732
			else if (strcmp("all", yyvsp[0].string) == 0)
733
				yyval.val = CTL_MASK;
734
			else if (strcmp("none", yyvsp[0].string) == 0)
735
				yyval.val = CTL_NONE;
736
			else {
737
				log_err("config: invalid control mode");
738
				free(yyvsp[0].string);
739
				YYERROR;
740
			}
741
			log_msg(2, "config: control mode set to %s", yyvsp[0].string);
742
			free(yyvsp[0].string);
743
		}
744
break;
745
case 18:
746
#line 151 "conf.y"
747
{
748
			if (cfgstate.carp_ifname)
749
				free(cfgstate.carp_ifname);
750
			cfgstate.carp_ifname = yyvsp[0].string;
751
			log_msg(2, "config: interface %s",
752
			    cfgstate.carp_ifname);
753
		}
754
break;
755
case 19:
756
#line 159 "conf.y"
757
{
758
			if (cfgstate.carp_ifgroup)
759
				free(cfgstate.carp_ifgroup);
760
			cfgstate.carp_ifgroup = yyvsp[0].string;
761
			log_msg(2, "config: group %s",
762
			    cfgstate.carp_ifgroup);
763
		}
764
break;
765
case 20:
766
#line 167 "conf.y"
767
{
768
			const char *fm[] = { "STARTUP", "NEVER", "SYNC" };
769
			cfgstate.flags |= yyvsp[0].val;
770
			log_msg(2, "config: flush mode set to %s", fm[yyvsp[0].val]);
771
		}
772
break;
773
case 21:
774
#line 173 "conf.y"
775
{
776
			struct syncpeer	*peer;
777
			int		 duplicate = 0;
778
779
			for (peer = LIST_FIRST(&cfgstate.peerlist); peer;
780
			     peer = LIST_NEXT(peer, link))
781
				if (strcmp(yyvsp[0].string, peer->name) == 0) {
782
					duplicate++;
783
					break;
784
				}
785
			if (duplicate)
786
				free(yyvsp[0].string);
787
			else {
788
				peer = calloc(1, sizeof *peer);
789
				if (!peer) {
790
					log_err("config: calloc(1, %lu) "
791
					    "failed", sizeof *peer);
792
					free(yyvsp[0].string);
793
					YYERROR;
794
				}
795
				peer->name = yyvsp[0].string;
796
			}
797
			LIST_INSERT_HEAD(&cfgstate.peerlist, peer, link);
798
			cfgstate.peercnt++;
799
			log_msg(2, "config: add peer %s", peer->name);
800
		}
801
break;
802
case 22:
803
#line 200 "conf.y"
804
{
805
			char pstr[20];
806
807
			if (cfgstate.listen_on)
808
				free(cfgstate.listen_on);
809
			cfgstate.listen_on = yyvsp[-2].string;
810
			cfgstate.listen_family = yyvsp[-1].val;
811
			cfgstate.listen_port = yyvsp[0].val;
812
			if (yyvsp[0].val < 1 || yyvsp[0].val > IPPORT_HILASTAUTO) {
813
				cfgstate.listen_port = SASYNCD_DEFAULT_PORT;
814
				log_msg(0, "config: bad port, listen-port "
815
				    "reset to %u", SASYNCD_DEFAULT_PORT);
816
			}
817
			if (yyvsp[0].val != SASYNCD_DEFAULT_PORT)
818
				snprintf(pstr, sizeof pstr, "port %d",yyvsp[0].val);
819
			log_msg(2, "config: listen on %s %s%s",
820
			    cfgstate.listen_on, yyvsp[-1].val == AF_INET6 ? "(IPv6) " :
821
			    (yyvsp[-1].val == AF_INET ? "(IPv4) " : ""),
822
			    yyvsp[0].val != SASYNCD_DEFAULT_PORT ? pstr : "");
823
		}
824
break;
825
case 24:
826
#line 222 "conf.y"
827
{
828
			int bits;
829
830
			bits = cfgstate.sharedkey_len;
831
			if (bits != 128 && bits != 192 && bits != 256) {
832
				log_err("config: bad shared key length %d, "
833
				    "should be 128, 192 or 256 bits\n", bits);
834
				YYERROR;
835
			}
836
			log_msg(2, "config: shared key set");
837
		}
838
break;
839
case 25:
840
#line 234 "conf.y"
841
{
842
			cfgstate.flags &= ~CTL_MASK;
843
			cfgstate.flags |= yyvsp[0].val;
844
		}
845
break;
846
#line 839 "conf.c"
847
    }
848
    yyssp -= yym;
849
    yystate = *yyssp;
850
    yyvsp -= yym;
851
    yym = yylhs[yyn];
852
    if (yystate == 0 && yym == 0)
853
    {
854
#if YYDEBUG
855
        if (yydebug)
856
            printf("%sdebug: after reduction, shifting from state 0 to\
857
 state %d\n", YYPREFIX, YYFINAL);
858
#endif
859
        yystate = YYFINAL;
860
        *++yyssp = YYFINAL;
861
        *++yyvsp = yyval;
862
        if (yychar < 0)
863
        {
864
            if ((yychar = yylex()) < 0) yychar = 0;
865
#if YYDEBUG
866
            if (yydebug)
867
            {
868
                yys = 0;
869
                if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
870
                if (!yys) yys = "illegal-symbol";
871
                printf("%sdebug: state %d, reading %d (%s)\n",
872
                        YYPREFIX, YYFINAL, yychar, yys);
873
            }
874
#endif
875
        }
876
        if (yychar == 0) goto yyaccept;
877
        goto yyloop;
878
    }
879
    if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
880
            yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
881
        yystate = yytable[yyn];
882
    else
883
        yystate = yydgoto[yym];
884
#if YYDEBUG
885
    if (yydebug)
886
        printf("%sdebug: after reduction, shifting from state %d \
887
to state %d\n", YYPREFIX, *yyssp, yystate);
888
#endif
889
    if (yyssp >= yysslim && yygrowstack())
890
    {
891
        goto yyoverflow;
892
    }
893
    *++yyssp = yystate;
894
    *++yyvsp = yyval;
895
    goto yyloop;
896
yyoverflow:
897
    yyerror("yacc stack overflow");
898
yyabort:
899
    if (yyss)
900
            free(yyss);
901
    if (yyvs)
902
            free(yyvs);
903
    yyss = yyssp = NULL;
904
    yyvs = yyvsp = NULL;
905
    yystacksize = 0;
906
    return (1);
907
yyaccept:
908
    if (yyss)
909
            free(yyss);
910
    if (yyvs)
911
            free(yyvs);
912
    yyss = yyssp = NULL;
913
    yyvs = yyvsp = NULL;
914
    yystacksize = 0;
915
    return (0);
916
}