File: | src/sbin/dhcpleased/obj/parse.c |
Warning: | line 1026, column 5 Attempt to free released memory |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | #include <stdlib.h> | ||||
2 | #include <string.h> | ||||
3 | #define YYBYACC1 1 | ||||
4 | #define YYMAJOR1 1 | ||||
5 | #define YYMINOR9 9 | ||||
6 | #define YYLEXyylex() yylex() | ||||
7 | #define YYEMPTY-1 -1 | ||||
8 | #define yyclearin(yychar=(-1)) (yychar=(YYEMPTY-1)) | ||||
9 | #define yyerrok(yyerrflag=0) (yyerrflag=0) | ||||
10 | #define YYRECOVERING()(yyerrflag!=0) (yyerrflag!=0) | ||||
11 | #define YYPREFIX"yy" "yy" | ||||
12 | #line 26 "/usr/src/sbin/dhcpleased/parse.y" | ||||
13 | #include <sys/types.h> | ||||
14 | #include <sys/queue.h> | ||||
15 | #include <sys/socket.h> | ||||
16 | #include <sys/stat.h> | ||||
17 | |||||
18 | #include <net/if.h> | ||||
19 | |||||
20 | #include <netinet/in.h> | ||||
21 | #include <netinet/if_ether.h> | ||||
22 | |||||
23 | #include <arpa/inet.h> | ||||
24 | |||||
25 | #include <ctype.h> | ||||
26 | #include <err.h> | ||||
27 | #include <errno(*__errno()).h> | ||||
28 | #include <event.h> | ||||
29 | #include <imsg.h> | ||||
30 | #include <limits.h> | ||||
31 | #include <stdarg.h> | ||||
32 | #include <stdio.h> | ||||
33 | #include <string.h> | ||||
34 | #include <syslog.h> | ||||
35 | #include <unistd.h> | ||||
36 | #include <vis.h> | ||||
37 | |||||
38 | #include "log.h" | ||||
39 | #include "dhcpleased.h" | ||||
40 | #include "frontend.h" | ||||
41 | |||||
42 | TAILQ_HEAD(files, file)struct files { struct file *tqh_first; struct file **tqh_last ; } files = TAILQ_HEAD_INITIALIZER(files){ ((void *)0), &(files).tqh_first }; | ||||
43 | static struct file { | ||||
44 | TAILQ_ENTRY(file)struct { struct file *tqe_next; struct file **tqe_prev; } entry; | ||||
45 | FILE *stream; | ||||
46 | char *name; | ||||
47 | size_t ungetpos; | ||||
48 | size_t ungetsize; | ||||
49 | u_char *ungetbuf; | ||||
50 | int eof_reached; | ||||
51 | int lineno; | ||||
52 | int errors; | ||||
53 | } *file, *topfile; | ||||
54 | struct file *pushfile(const char *, int); | ||||
55 | int popfile(void); | ||||
56 | int check_file_secrecy(int, const char *); | ||||
57 | int yyparse(void); | ||||
58 | int yylex(void); | ||||
59 | int yyerror(const char *, ...) | ||||
60 | __attribute__((__format__ (printf, 1, 2))) | ||||
61 | __attribute__((__nonnull__ (1))); | ||||
62 | int kw_cmp(const void *, const void *); | ||||
63 | int lookup(char *); | ||||
64 | int igetc(void); | ||||
65 | int lgetc(int); | ||||
66 | void lungetc(int); | ||||
67 | int findeol(void); | ||||
68 | |||||
69 | TAILQ_HEAD(symhead, sym)struct symhead { struct sym *tqh_first; struct sym **tqh_last ; } symhead = TAILQ_HEAD_INITIALIZER(symhead){ ((void *)0), &(symhead).tqh_first }; | ||||
70 | struct sym { | ||||
71 | TAILQ_ENTRY(sym)struct { struct sym *tqe_next; struct sym **tqe_prev; } entry; | ||||
72 | int used; | ||||
73 | int persist; | ||||
74 | char *nam; | ||||
75 | char *val; | ||||
76 | }; | ||||
77 | |||||
78 | int symset(const char *, const char *, int); | ||||
79 | char *symget(const char *); | ||||
80 | |||||
81 | static struct dhcpleased_conf *conf; | ||||
82 | static int errors; | ||||
83 | |||||
84 | static struct iface_conf *iface_conf; | ||||
85 | |||||
86 | struct iface_conf *conf_get_iface(char *); | ||||
87 | |||||
88 | typedef struct { | ||||
89 | union { | ||||
90 | int64_t number; | ||||
91 | char *string; | ||||
92 | } v; | ||||
93 | int lineno; | ||||
94 | } YYSTYPE; | ||||
95 | |||||
96 | #line 97 "parse.c" | ||||
97 | #define DHCP_IFACE257 257 | ||||
98 | #define ERROR258 258 | ||||
99 | #define SEND259 259 | ||||
100 | #define VENDOR260 260 | ||||
101 | #define CLASS261 261 | ||||
102 | #define ID262 262 | ||||
103 | #define CLIENT263 263 | ||||
104 | #define IGNORE264 264 | ||||
105 | #define DNS265 265 | ||||
106 | #define ROUTES266 266 | ||||
107 | #define HOST267 267 | ||||
108 | #define NAME268 268 | ||||
109 | #define NO269 269 | ||||
110 | #define PREFER270 270 | ||||
111 | #define IPV6271 271 | ||||
112 | #define STRING272 272 | ||||
113 | #define NUMBER273 273 | ||||
114 | #define YYERRCODE256 256 | ||||
115 | const short yylhs[] = | ||||
116 | { -1, | ||||
117 | 0, 0, 0, 0, 0, 1, 1, 2, 4, 4, | ||||
118 | 5, 6, 3, 7, 7, 8, 8, 9, 9, 9, | ||||
119 | 9, 9, 9, 9, 9, | ||||
120 | }; | ||||
121 | const short yylen[] = | ||||
122 | { 2, | ||||
123 | 0, 2, 3, 3, 3, 2, 1, 3, 2, 0, | ||||
124 | 2, 0, 6, 2, 1, 3, 2, 5, 4, 4, | ||||
125 | 4, 2, 2, 2, 2, | ||||
126 | }; | ||||
127 | const short yydefred[] = | ||||
128 | { 1, | ||||
129 | 0, 0, 0, 0, 2, 0, 0, 5, 12, 0, | ||||
130 | 3, 4, 0, 7, 0, 0, 6, 0, 0, 0, | ||||
131 | 9, 0, 0, 0, 0, 0, 13, 0, 0, 0, | ||||
132 | 0, 23, 22, 24, 25, 0, 17, 0, 0, 0, | ||||
133 | 0, 0, 16, 0, 19, 20, 21, 11, 18, | ||||
134 | }; | ||||
135 | const short yydgoto[] = | ||||
136 | { 1, | ||||
137 | 15, 6, 7, 19, 43, 13, 20, 25, 26, | ||||
138 | }; | ||||
139 | const short yysindex[] = | ||||
140 | { 0, | ||||
141 | -10, -3, -260, -45, 0, 7, 8, 0, 0, -253, | ||||
142 | 0, 0, -103, 0, -251, 12, 0, 12, -256, -102, | ||||
143 | 0, -254, -261, -247, -256, 12, 0, -236, -235, -240, | ||||
144 | -238, 0, 0, 0, 0, 20, 0, -231, -239, -237, | ||||
145 | -234, 12, 0, -233, 0, 0, 0, 0, 0,}; | ||||
146 | const short yyrindex[] = | ||||
147 | { 0, | ||||
148 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||||
149 | 0, 0, 0, 0, -3, -124, 0, -124, -93, 0, | ||||
150 | 0, 0, 0, 0, -89, -124, 0, 0, 0, 0, | ||||
151 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||||
152 | 0, -124, 0, 0, 0, 0, 0, 0, 0,}; | ||||
153 | const short yygindex[] = | ||||
154 | { 0, | ||||
155 | 0, 0, 0, -16, 0, 0, 0, 0, 13, | ||||
156 | }; | ||||
157 | #define YYTABLESIZE262 262 | ||||
158 | const short yytable[] = | ||||
159 | { 5, | ||||
160 | 10, 21, 22, 32, 33, 28, 8, 23, 29, 37, | ||||
161 | 34, 9, 30, 24, 31, 10, 11, 12, 14, 16, | ||||
162 | 17, 18, 27, 35, 38, 48, 39, 40, 41, 42, | ||||
163 | 44, 15, 45, 47, 46, 14, 0, 36, 49, 0, | ||||
164 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||||
165 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||||
166 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||||
167 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||||
168 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||||
169 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||||
170 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||||
171 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||||
172 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||||
173 | 0, 0, 0, 0, 10, 0, 0, 0, 0, 10, | ||||
174 | 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, | ||||
175 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||||
176 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||||
177 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||||
178 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||||
179 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||||
180 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||||
181 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||||
182 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||||
183 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||||
184 | 0, 0, 0, 0, 0, 2, 3, 0, 0, 0, | ||||
185 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||||
186 | 0, 4, | ||||
187 | }; | ||||
188 | const short yycheck[] = | ||||
189 | { 10, | ||||
190 | 125, 18, 259, 265, 266, 260, 10, 264, 263, 26, | ||||
191 | 272, 272, 267, 270, 269, 61, 10, 10, 272, 123, | ||||
192 | 272, 10, 125, 271, 261, 42, 262, 268, 267, 10, | ||||
193 | 262, 125, 272, 268, 272, 125, -1, 25, 272, -1, | ||||
194 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||||
195 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||||
196 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||||
197 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||||
198 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||||
199 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||||
200 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||||
201 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||||
202 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||||
203 | -1, -1, -1, -1, 259, -1, -1, -1, -1, 264, | ||||
204 | -1, -1, -1, -1, -1, 270, -1, -1, -1, -1, | ||||
205 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||||
206 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||||
207 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||||
208 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||||
209 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||||
210 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||||
211 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||||
212 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||||
213 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||||
214 | -1, -1, -1, -1, -1, 256, 257, -1, -1, -1, | ||||
215 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||||
216 | -1, 272, | ||||
217 | }; | ||||
218 | #define YYFINAL1 1 | ||||
219 | #ifndef YYDEBUG0 | ||||
220 | #define YYDEBUG0 0 | ||||
221 | #endif | ||||
222 | #define YYMAXTOKEN273 273 | ||||
223 | #if YYDEBUG0 | ||||
224 | const char * const yyname[] = | ||||
225 | { | ||||
226 | "end-of-file",0,0,0,0,0,0,0,0,0,"'\\n'",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||||
227 | 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, | ||||
228 | 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, | ||||
229 | 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, | ||||
230 | 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, | ||||
231 | 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, | ||||
232 | 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,"DHCP_IFACE", | ||||
233 | "ERROR","SEND","VENDOR","CLASS","ID","CLIENT","IGNORE","DNS","ROUTES","HOST", | ||||
234 | "NAME","NO","PREFER","IPV6","STRING","NUMBER", | ||||
235 | }; | ||||
236 | const char * const yyrule[] = | ||||
237 | {"$accept : grammar", | ||||
238 | "grammar :", | ||||
239 | "grammar : grammar '\\n'", | ||||
240 | "grammar : grammar varset '\\n'", | ||||
241 | "grammar : grammar dhcp_iface '\\n'", | ||||
242 | "grammar : grammar error '\\n'", | ||||
243 | "string : string STRING", | ||||
244 | "string : STRING", | ||||
245 | "varset : STRING '=' string", | ||||
246 | "optnl : '\\n' optnl", | ||||
247 | "optnl :", | ||||
248 | "nl : '\\n' optnl", | ||||
249 | "$$1 :", | ||||
250 | "dhcp_iface : DHCP_IFACE STRING $$1 '{' iface_block '}'", | ||||
251 | "iface_block : optnl ifaceopts_l", | ||||
252 | "iface_block : optnl", | ||||
253 | "ifaceopts_l : ifaceopts_l ifaceoptsl nl", | ||||
254 | "ifaceopts_l : ifaceoptsl optnl", | ||||
255 | "ifaceoptsl : SEND VENDOR CLASS ID STRING", | ||||
256 | "ifaceoptsl : SEND CLIENT ID STRING", | ||||
257 | "ifaceoptsl : SEND HOST NAME STRING", | ||||
258 | "ifaceoptsl : SEND NO HOST NAME", | ||||
259 | "ifaceoptsl : IGNORE ROUTES", | ||||
260 | "ifaceoptsl : IGNORE DNS", | ||||
261 | "ifaceoptsl : IGNORE STRING", | ||||
262 | "ifaceoptsl : PREFER IPV6", | ||||
263 | }; | ||||
264 | #endif | ||||
265 | #ifdef YYSTACKSIZE10000 | ||||
266 | #undef YYMAXDEPTH10000 | ||||
267 | #define YYMAXDEPTH10000 YYSTACKSIZE10000 | ||||
268 | #else | ||||
269 | #ifdef YYMAXDEPTH10000 | ||||
270 | #define YYSTACKSIZE10000 YYMAXDEPTH10000 | ||||
271 | #else | ||||
272 | #define YYSTACKSIZE10000 10000 | ||||
273 | #define YYMAXDEPTH10000 10000 | ||||
274 | #endif | ||||
275 | #endif | ||||
276 | #define YYINITSTACKSIZE200 200 | ||||
277 | /* LINTUSED */ | ||||
278 | int yydebug; | ||||
279 | int yynerrs; | ||||
280 | int yyerrflag; | ||||
281 | int yychar; | ||||
282 | short *yyssp; | ||||
283 | YYSTYPE *yyvsp; | ||||
284 | YYSTYPE yyval; | ||||
285 | YYSTYPE yylval; | ||||
286 | short *yyss; | ||||
287 | short *yysslim; | ||||
288 | YYSTYPE *yyvs; | ||||
289 | unsigned int yystacksize; | ||||
290 | int yyparse(void); | ||||
291 | #line 332 "/usr/src/sbin/dhcpleased/parse.y" | ||||
292 | |||||
293 | struct keywords { | ||||
294 | const char *k_name; | ||||
295 | int k_val; | ||||
296 | }; | ||||
297 | |||||
298 | int | ||||
299 | yyerror(const char *fmt, ...) | ||||
300 | { | ||||
301 | va_list ap; | ||||
302 | char *msg; | ||||
303 | |||||
304 | file->errors++; | ||||
305 | va_start(ap, fmt)__builtin_va_start((ap), fmt); | ||||
306 | if (vasprintf(&msg, fmt, ap) == -1) | ||||
307 | fatalx("yyerror vasprintf"); | ||||
308 | va_end(ap)__builtin_va_end((ap)); | ||||
309 | logit(LOG_CRIT2, "%s:%d: %s", file->name, yylval.lineno, msg); | ||||
310 | free(msg); | ||||
311 | return (0); | ||||
312 | } | ||||
313 | |||||
314 | int | ||||
315 | kw_cmp(const void *k, const void *e) | ||||
316 | { | ||||
317 | return (strcmp(k, ((const struct keywords *)e)->k_name)); | ||||
318 | } | ||||
319 | |||||
320 | int | ||||
321 | lookup(char *s) | ||||
322 | { | ||||
323 | /* This has to be sorted always. */ | ||||
324 | static const struct keywords keywords[] = { | ||||
325 | {"class", CLASS261}, | ||||
326 | {"client", CLIENT263}, | ||||
327 | {"dns", DNS265}, | ||||
328 | {"host", HOST267}, | ||||
329 | {"id", ID262}, | ||||
330 | {"ignore", IGNORE264}, | ||||
331 | {"interface", DHCP_IFACE257}, | ||||
332 | {"ipv6", IPV6271}, | ||||
333 | {"name", NAME268}, | ||||
334 | {"no", NO269}, | ||||
335 | {"prefer", PREFER270}, | ||||
336 | {"routes", ROUTES266}, | ||||
337 | {"send", SEND259}, | ||||
338 | {"vendor", VENDOR260}, | ||||
339 | }; | ||||
340 | const struct keywords *p; | ||||
341 | |||||
342 | p = bsearch(s, keywords, sizeof(keywords)/sizeof(keywords[0]), | ||||
343 | sizeof(keywords[0]), kw_cmp); | ||||
344 | |||||
345 | if (p) | ||||
346 | return (p->k_val); | ||||
347 | else | ||||
348 | return (STRING272); | ||||
349 | } | ||||
350 | |||||
351 | #define START_EXPAND1 1 | ||||
352 | #define DONE_EXPAND2 2 | ||||
353 | |||||
354 | static int expanding; | ||||
355 | |||||
356 | int | ||||
357 | igetc(void) | ||||
358 | { | ||||
359 | int c; | ||||
360 | |||||
361 | while (1) { | ||||
362 | if (file->ungetpos > 0) | ||||
363 | c = file->ungetbuf[--file->ungetpos]; | ||||
364 | else | ||||
365 | c = getc(file->stream)(!__isthreaded ? (--(file->stream)->_r < 0 ? __srget (file->stream) : (int)(*(file->stream)->_p++)) : (getc )(file->stream)); | ||||
366 | |||||
367 | if (c == START_EXPAND1) | ||||
368 | expanding = 1; | ||||
369 | else if (c == DONE_EXPAND2) | ||||
370 | expanding = 0; | ||||
371 | else | ||||
372 | break; | ||||
373 | } | ||||
374 | return (c); | ||||
375 | } | ||||
376 | |||||
377 | int | ||||
378 | lgetc(int quotec) | ||||
379 | { | ||||
380 | int c, next; | ||||
381 | |||||
382 | if (quotec) { | ||||
383 | if ((c = igetc()) == EOF(-1)) { | ||||
384 | yyerror("reached end of file while parsing " | ||||
385 | "quoted string"); | ||||
386 | if (file == topfile || popfile() == EOF(-1)) | ||||
387 | return (EOF(-1)); | ||||
388 | return (quotec); | ||||
389 | } | ||||
390 | return (c); | ||||
391 | } | ||||
392 | |||||
393 | while ((c = igetc()) == '\\') { | ||||
394 | next = igetc(); | ||||
395 | if (next != '\n') { | ||||
396 | c = next; | ||||
397 | break; | ||||
398 | } | ||||
399 | yylval.lineno = file->lineno; | ||||
400 | file->lineno++; | ||||
401 | } | ||||
402 | |||||
403 | if (c == EOF(-1)) { | ||||
404 | /* | ||||
405 | * Fake EOL when hit EOF for the first time. This gets line | ||||
406 | * count right if last line in included file is syntactically | ||||
407 | * invalid and has no newline. | ||||
408 | */ | ||||
409 | if (file->eof_reached == 0) { | ||||
410 | file->eof_reached = 1; | ||||
411 | return ('\n'); | ||||
412 | } | ||||
413 | while (c == EOF(-1)) { | ||||
414 | if (file == topfile || popfile() == EOF(-1)) | ||||
415 | return (EOF(-1)); | ||||
416 | c = igetc(); | ||||
417 | } | ||||
418 | } | ||||
419 | return (c); | ||||
420 | } | ||||
421 | |||||
422 | void | ||||
423 | lungetc(int c) | ||||
424 | { | ||||
425 | if (c == EOF(-1)) | ||||
426 | return; | ||||
427 | |||||
428 | if (file->ungetpos >= file->ungetsize) { | ||||
429 | void *p = reallocarray(file->ungetbuf, file->ungetsize, 2); | ||||
430 | if (p == NULL((void *)0)) | ||||
431 | err(1, "lungetc"); | ||||
432 | file->ungetbuf = p; | ||||
433 | file->ungetsize *= 2; | ||||
434 | } | ||||
435 | file->ungetbuf[file->ungetpos++] = c; | ||||
436 | } | ||||
437 | |||||
438 | int | ||||
439 | findeol(void) | ||||
440 | { | ||||
441 | int c; | ||||
442 | |||||
443 | /* Skip to either EOF or the first real EOL. */ | ||||
444 | while (1) { | ||||
445 | c = lgetc(0); | ||||
446 | if (c == '\n') { | ||||
447 | file->lineno++; | ||||
448 | break; | ||||
449 | } | ||||
450 | if (c == EOF(-1)) | ||||
451 | break; | ||||
452 | } | ||||
453 | return (ERROR258); | ||||
454 | } | ||||
455 | |||||
456 | int | ||||
457 | yylex(void) | ||||
458 | { | ||||
459 | char buf[8096]; | ||||
460 | char *p, *val; | ||||
461 | int quotec, next, c; | ||||
462 | int token; | ||||
463 | |||||
464 | top: | ||||
465 | p = buf; | ||||
466 | while ((c = lgetc(0)) == ' ' || c == '\t') | ||||
467 | ; /* nothing */ | ||||
468 | |||||
469 | yylval.lineno = file->lineno; | ||||
470 | if (c == '#') | ||||
471 | while ((c = lgetc(0)) != '\n' && c != EOF(-1)) | ||||
472 | ; /* nothing */ | ||||
473 | if (c == '$' && !expanding) { | ||||
474 | while (1) { | ||||
475 | if ((c = lgetc(0)) == EOF(-1)) | ||||
476 | return (0); | ||||
477 | |||||
478 | if (p + 1 >= buf + sizeof(buf) - 1) { | ||||
479 | yyerror("string too long"); | ||||
480 | return (findeol()); | ||||
481 | } | ||||
482 | if (isalnum(c) || c == '_') { | ||||
483 | *p++ = c; | ||||
484 | continue; | ||||
485 | } | ||||
486 | *p = '\0'; | ||||
487 | lungetc(c); | ||||
488 | break; | ||||
489 | } | ||||
490 | val = symget(buf); | ||||
491 | if (val == NULL((void *)0)) { | ||||
492 | yyerror("macro '%s' not defined", buf); | ||||
493 | return (findeol()); | ||||
494 | } | ||||
495 | p = val + strlen(val) - 1; | ||||
496 | lungetc(DONE_EXPAND2); | ||||
497 | while (p >= val) { | ||||
498 | lungetc((unsigned char)*p); | ||||
499 | p--; | ||||
500 | } | ||||
501 | lungetc(START_EXPAND1); | ||||
502 | goto top; | ||||
503 | } | ||||
504 | |||||
505 | switch (c) { | ||||
506 | case '\'': | ||||
507 | case '"': | ||||
508 | quotec = c; | ||||
509 | while (1) { | ||||
510 | if ((c = lgetc(quotec)) == EOF(-1)) | ||||
511 | return (0); | ||||
512 | if (c == '\n') { | ||||
513 | file->lineno++; | ||||
514 | continue; | ||||
515 | } else if (c == '\\') { | ||||
516 | if ((next = lgetc(quotec)) == EOF(-1)) | ||||
517 | return (0); | ||||
518 | if (next == quotec || next == ' ' || | ||||
519 | next == '\t') | ||||
520 | c = next; | ||||
521 | else if (next == '\n') { | ||||
522 | file->lineno++; | ||||
523 | continue; | ||||
524 | } else | ||||
525 | lungetc(next); | ||||
526 | } else if (c == quotec) { | ||||
527 | *p = '\0'; | ||||
528 | break; | ||||
529 | } else if (c == '\0') { | ||||
530 | yyerror("syntax error"); | ||||
531 | return (findeol()); | ||||
532 | } | ||||
533 | if (p + 1 >= buf + sizeof(buf) - 1) { | ||||
534 | yyerror("string too long"); | ||||
535 | return (findeol()); | ||||
536 | } | ||||
537 | *p++ = c; | ||||
538 | } | ||||
539 | yylval.v.string = strdup(buf); | ||||
540 | if (yylval.v.string == NULL((void *)0)) | ||||
541 | err(1, "yylex: strdup"); | ||||
542 | return (STRING272); | ||||
543 | } | ||||
544 | |||||
545 | #define allowed_to_end_number(x)(isspace(x) || x == ')' || x ==',' || x == '/' || x == '}' || x == '=') \ | ||||
546 | (isspace(x) || x == ')' || x ==',' || x == '/' || x == '}' || x == '=') | ||||
547 | |||||
548 | if (c == '-' || isdigit(c)) { | ||||
549 | do { | ||||
550 | *p++ = c; | ||||
551 | if ((size_t)(p-buf) >= sizeof(buf)) { | ||||
552 | yyerror("string too long"); | ||||
553 | return (findeol()); | ||||
554 | } | ||||
555 | } while ((c = lgetc(0)) != EOF(-1) && isdigit(c)); | ||||
556 | lungetc(c); | ||||
557 | if (p == buf + 1 && buf[0] == '-') | ||||
558 | goto nodigits; | ||||
559 | if (c == EOF(-1) || allowed_to_end_number(c)(isspace(c) || c == ')' || c ==',' || c == '/' || c == '}' || c == '=')) { | ||||
560 | const char *errstr = NULL((void *)0); | ||||
561 | |||||
562 | *p = '\0'; | ||||
563 | yylval.v.number = strtonum(buf, LLONG_MIN(-0x7fffffffffffffffLL-1), | ||||
564 | LLONG_MAX0x7fffffffffffffffLL, &errstr); | ||||
565 | if (errstr) { | ||||
566 | yyerror("\"%s\" invalid number: %s", | ||||
567 | buf, errstr); | ||||
568 | return (findeol()); | ||||
569 | } | ||||
570 | return (NUMBER273); | ||||
571 | } else { | ||||
572 | nodigits: | ||||
573 | while (p > buf + 1) | ||||
574 | lungetc((unsigned char)*--p); | ||||
575 | c = (unsigned char)*--p; | ||||
576 | if (c == '-') | ||||
577 | return (c); | ||||
578 | } | ||||
579 | } | ||||
580 | |||||
581 | #define allowed_in_string(x)(isalnum(x) || (ispunct(x) && x != '(' && x != ')' && x != '{' && x != '}' && x != '!' && x != '=' && x != '#' && x != ',') ) \ | ||||
582 | (isalnum(x) || (ispunct(x) && x != '(' && x != ')' && \ | ||||
583 | x != '{' && x != '}' && \ | ||||
584 | x != '!' && x != '=' && x != '#' && \ | ||||
585 | x != ',')) | ||||
586 | |||||
587 | if (isalnum(c) || c == ':' || c == '_') { | ||||
588 | do { | ||||
589 | *p++ = c; | ||||
590 | if ((size_t)(p-buf) >= sizeof(buf)) { | ||||
591 | yyerror("string too long"); | ||||
592 | return (findeol()); | ||||
593 | } | ||||
594 | } while ((c = lgetc(0)) != EOF(-1) && (allowed_in_string(c)(isalnum(c) || (ispunct(c) && c != '(' && c != ')' && c != '{' && c != '}' && c != '!' && c != '=' && c != '#' && c != ',') ))); | ||||
595 | lungetc(c); | ||||
596 | *p = '\0'; | ||||
597 | if ((token = lookup(buf)) == STRING272) | ||||
598 | if ((yylval.v.string = strdup(buf)) == NULL((void *)0)) | ||||
599 | err(1, "yylex: strdup"); | ||||
600 | return (token); | ||||
601 | } | ||||
602 | if (c == '\n') { | ||||
603 | yylval.lineno = file->lineno; | ||||
604 | file->lineno++; | ||||
605 | } | ||||
606 | if (c == EOF(-1)) | ||||
607 | return (0); | ||||
608 | return (c); | ||||
609 | } | ||||
610 | |||||
611 | int | ||||
612 | check_file_secrecy(int fd, const char *fname) | ||||
613 | { | ||||
614 | struct stat st; | ||||
615 | |||||
616 | if (fstat(fd, &st)) { | ||||
617 | log_warn("cannot stat %s", fname); | ||||
618 | return (-1); | ||||
619 | } | ||||
620 | if (st.st_uid != 0 && st.st_uid != getuid()) { | ||||
621 | log_warnx("%s: owner not root or current user", fname); | ||||
622 | return (-1); | ||||
623 | } | ||||
624 | if (st.st_mode & (S_IWGRP0000020 | S_IXGRP0000010 | S_IRWXO0000007)) { | ||||
625 | log_warnx("%s: group writable or world read/writable", fname); | ||||
626 | return (-1); | ||||
627 | } | ||||
628 | return (0); | ||||
629 | } | ||||
630 | |||||
631 | struct file * | ||||
632 | pushfile(const char *name, int secret) | ||||
633 | { | ||||
634 | struct file *nfile; | ||||
635 | |||||
636 | if ((nfile = calloc(1, sizeof(struct file))) == NULL((void *)0)) { | ||||
637 | log_warn("calloc"); | ||||
638 | return (NULL((void *)0)); | ||||
639 | } | ||||
640 | if ((nfile->name = strdup(name)) == NULL((void *)0)) { | ||||
641 | log_warn("strdup"); | ||||
642 | free(nfile); | ||||
643 | return (NULL((void *)0)); | ||||
644 | } | ||||
645 | if ((nfile->stream = fopen(nfile->name, "r")) == NULL((void *)0)) { | ||||
646 | free(nfile->name); | ||||
647 | free(nfile); | ||||
648 | return (NULL((void *)0)); | ||||
649 | } else if (secret && | ||||
650 | check_file_secrecy(fileno(nfile->stream)(!__isthreaded ? ((nfile->stream)->_file) : (fileno)(nfile ->stream)), nfile->name)) { | ||||
651 | fclose(nfile->stream); | ||||
652 | free(nfile->name); | ||||
653 | free(nfile); | ||||
654 | return (NULL((void *)0)); | ||||
655 | } | ||||
656 | nfile->lineno = TAILQ_EMPTY(&files)(((&files)->tqh_first) == ((void *)0)) ? 1 : 0; | ||||
657 | nfile->ungetsize = 16; | ||||
658 | nfile->ungetbuf = malloc(nfile->ungetsize); | ||||
659 | if (nfile->ungetbuf == NULL((void *)0)) { | ||||
660 | log_warn("malloc"); | ||||
661 | fclose(nfile->stream); | ||||
662 | free(nfile->name); | ||||
663 | free(nfile); | ||||
664 | return (NULL((void *)0)); | ||||
665 | } | ||||
666 | TAILQ_INSERT_TAIL(&files, nfile, entry)do { (nfile)->entry.tqe_next = ((void *)0); (nfile)->entry .tqe_prev = (&files)->tqh_last; *(&files)->tqh_last = (nfile); (&files)->tqh_last = &(nfile)->entry .tqe_next; } while (0); | ||||
667 | return (nfile); | ||||
668 | } | ||||
669 | |||||
670 | int | ||||
671 | popfile(void) | ||||
672 | { | ||||
673 | struct file *prev; | ||||
674 | |||||
675 | if ((prev = TAILQ_PREV(file, files, entry)(*(((struct files *)((file)->entry.tqe_prev))->tqh_last ))) != NULL((void *)0)) | ||||
676 | prev->errors += file->errors; | ||||
677 | |||||
678 | TAILQ_REMOVE(&files, file, entry)do { if (((file)->entry.tqe_next) != ((void *)0)) (file)-> entry.tqe_next->entry.tqe_prev = (file)->entry.tqe_prev ; else (&files)->tqh_last = (file)->entry.tqe_prev; *(file)->entry.tqe_prev = (file)->entry.tqe_next; ; ; } while (0); | ||||
679 | fclose(file->stream); | ||||
680 | free(file->name); | ||||
681 | free(file->ungetbuf); | ||||
682 | free(file); | ||||
683 | file = prev; | ||||
684 | return (file ? 0 : EOF(-1)); | ||||
685 | } | ||||
686 | |||||
687 | struct dhcpleased_conf * | ||||
688 | parse_config(const char *filename) | ||||
689 | { | ||||
690 | extern const char default_conffile[]; | ||||
691 | struct sym *sym, *next; | ||||
692 | |||||
693 | conf = config_new_empty(); | ||||
694 | |||||
695 | file = pushfile(filename, 0); | ||||
696 | if (file == NULL((void *)0)) { | ||||
697 | /* no default config file is fine */ | ||||
698 | if (errno(*__errno()) == ENOENT2 && filename == default_conffile) | ||||
699 | return (conf); | ||||
700 | log_warn("%s", filename); | ||||
701 | free(conf); | ||||
702 | return (NULL((void *)0)); | ||||
703 | } | ||||
704 | topfile = file; | ||||
705 | |||||
706 | yyparse(); | ||||
707 | errors = file->errors; | ||||
708 | popfile(); | ||||
709 | |||||
710 | /* Free macros and check which have not been used. */ | ||||
711 | TAILQ_FOREACH_SAFE(sym, &symhead, entry, next)for ((sym) = ((&symhead)->tqh_first); (sym) != ((void * )0) && ((next) = ((sym)->entry.tqe_next), 1); (sym ) = (next)) { | ||||
712 | if ((log_getverbose() == 2) && !sym->used) | ||||
713 | fprintf(stderr(&__sF[2]), "warning: macro '%s' not used\n", | ||||
714 | sym->nam); | ||||
715 | if (!sym->persist) { | ||||
716 | free(sym->nam); | ||||
717 | free(sym->val); | ||||
718 | TAILQ_REMOVE(&symhead, sym, entry)do { if (((sym)->entry.tqe_next) != ((void *)0)) (sym)-> entry.tqe_next->entry.tqe_prev = (sym)->entry.tqe_prev; else (&symhead)->tqh_last = (sym)->entry.tqe_prev; *(sym)->entry.tqe_prev = (sym)->entry.tqe_next; ; ; } while (0); | ||||
719 | free(sym); | ||||
720 | } | ||||
721 | } | ||||
722 | |||||
723 | if (errors) { | ||||
724 | config_clear(conf); | ||||
725 | return (NULL((void *)0)); | ||||
726 | } | ||||
727 | |||||
728 | return (conf); | ||||
729 | } | ||||
730 | |||||
731 | int | ||||
732 | symset(const char *nam, const char *val, int persist) | ||||
733 | { | ||||
734 | struct sym *sym; | ||||
735 | |||||
736 | TAILQ_FOREACH(sym, &symhead, entry)for((sym) = ((&symhead)->tqh_first); (sym) != ((void * )0); (sym) = ((sym)->entry.tqe_next)) { | ||||
737 | if (strcmp(nam, sym->nam) == 0) | ||||
738 | break; | ||||
739 | } | ||||
740 | |||||
741 | if (sym != NULL((void *)0)) { | ||||
742 | if (sym->persist == 1) | ||||
743 | return (0); | ||||
744 | else { | ||||
745 | free(sym->nam); | ||||
746 | free(sym->val); | ||||
747 | TAILQ_REMOVE(&symhead, sym, entry)do { if (((sym)->entry.tqe_next) != ((void *)0)) (sym)-> entry.tqe_next->entry.tqe_prev = (sym)->entry.tqe_prev; else (&symhead)->tqh_last = (sym)->entry.tqe_prev; *(sym)->entry.tqe_prev = (sym)->entry.tqe_next; ; ; } while (0); | ||||
748 | free(sym); | ||||
749 | } | ||||
750 | } | ||||
751 | if ((sym = calloc(1, sizeof(*sym))) == NULL((void *)0)) | ||||
752 | return (-1); | ||||
753 | |||||
754 | sym->nam = strdup(nam); | ||||
755 | if (sym->nam == NULL((void *)0)) { | ||||
756 | free(sym); | ||||
757 | return (-1); | ||||
758 | } | ||||
759 | sym->val = strdup(val); | ||||
760 | if (sym->val == NULL((void *)0)) { | ||||
761 | free(sym->nam); | ||||
762 | free(sym); | ||||
763 | return (-1); | ||||
764 | } | ||||
765 | sym->used = 0; | ||||
766 | sym->persist = persist; | ||||
767 | TAILQ_INSERT_TAIL(&symhead, sym, entry)do { (sym)->entry.tqe_next = ((void *)0); (sym)->entry. tqe_prev = (&symhead)->tqh_last; *(&symhead)->tqh_last = (sym); (&symhead)->tqh_last = &(sym)->entry. tqe_next; } while (0); | ||||
768 | return (0); | ||||
769 | } | ||||
770 | |||||
771 | int | ||||
772 | cmdline_symset(char *s) | ||||
773 | { | ||||
774 | char *sym, *val; | ||||
775 | int ret; | ||||
776 | |||||
777 | if ((val = strrchr(s, '=')) == NULL((void *)0)) | ||||
778 | return (-1); | ||||
779 | sym = strndup(s, val - s); | ||||
780 | if (sym == NULL((void *)0)) | ||||
781 | errx(1, "%s: strndup", __func__); | ||||
782 | ret = symset(sym, val + 1, 1); | ||||
783 | free(sym); | ||||
784 | |||||
785 | return (ret); | ||||
786 | } | ||||
787 | |||||
788 | char * | ||||
789 | symget(const char *nam) | ||||
790 | { | ||||
791 | struct sym *sym; | ||||
792 | |||||
793 | TAILQ_FOREACH(sym, &symhead, entry)for((sym) = ((&symhead)->tqh_first); (sym) != ((void * )0); (sym) = ((sym)->entry.tqe_next)) { | ||||
794 | if (strcmp(nam, sym->nam) == 0) { | ||||
795 | sym->used = 1; | ||||
796 | return (sym->val); | ||||
797 | } | ||||
798 | } | ||||
799 | return (NULL((void *)0)); | ||||
800 | } | ||||
801 | |||||
802 | struct iface_conf * | ||||
803 | conf_get_iface(char *name) | ||||
804 | { | ||||
805 | struct iface_conf *iface; | ||||
806 | size_t n; | ||||
807 | |||||
808 | SIMPLEQ_FOREACH(iface, &conf->iface_list, entry)for((iface) = ((&conf->iface_list)->sqh_first); (iface ) != ((void *)0); (iface) = ((iface)->entry.sqe_next)) { | ||||
809 | if (strcmp(name, iface->name) == 0) | ||||
810 | return (iface); | ||||
811 | } | ||||
812 | |||||
813 | iface = calloc(1, sizeof(*iface)); | ||||
814 | if (iface == NULL((void *)0)) | ||||
815 | errx(1, "%s: calloc", __func__); | ||||
816 | n = strlcpy(iface->name, name, sizeof(iface->name)); | ||||
817 | if (n >= sizeof(iface->name)) | ||||
818 | errx(1, "%s: name too long", __func__); | ||||
819 | |||||
820 | |||||
821 | SIMPLEQ_INSERT_TAIL(&conf->iface_list, iface, entry)do { (iface)->entry.sqe_next = ((void *)0); *(&conf-> iface_list)->sqh_last = (iface); (&conf->iface_list )->sqh_last = &(iface)->entry.sqe_next; } while (0); | ||||
822 | |||||
823 | return (iface); | ||||
824 | } | ||||
825 | #line 818 "parse.c" | ||||
826 | /* allocate initial stack or double stack size, up to YYMAXDEPTH */ | ||||
827 | static int yygrowstack(void) | ||||
828 | { | ||||
829 | unsigned int newsize; | ||||
830 | long sslen; | ||||
831 | short *newss; | ||||
832 | YYSTYPE *newvs; | ||||
833 | |||||
834 | if ((newsize = yystacksize) == 0) | ||||
835 | newsize = YYINITSTACKSIZE200; | ||||
836 | else if (newsize >= YYMAXDEPTH10000) | ||||
837 | return -1; | ||||
838 | else if ((newsize *= 2) > YYMAXDEPTH10000) | ||||
839 | newsize = YYMAXDEPTH10000; | ||||
840 | sslen = yyssp - yyss; | ||||
841 | #ifdef SIZE_MAX0xffffffffffffffffUL | ||||
842 | #define YY_SIZE_MAX0xffffffffffffffffUL SIZE_MAX0xffffffffffffffffUL | ||||
843 | #else | ||||
844 | #define YY_SIZE_MAX0xffffffffffffffffUL 0xffffffffU | ||||
845 | #endif | ||||
846 | if (newsize && YY_SIZE_MAX0xffffffffffffffffUL / newsize < sizeof *newss) | ||||
847 | goto bail; | ||||
848 | newss = (short *)realloc(yyss, newsize * sizeof *newss); | ||||
849 | if (newss == NULL((void *)0)) | ||||
850 | goto bail; | ||||
851 | yyss = newss; | ||||
852 | yyssp = newss + sslen; | ||||
853 | if (newsize && YY_SIZE_MAX0xffffffffffffffffUL / newsize < sizeof *newvs) | ||||
854 | goto bail; | ||||
855 | newvs = (YYSTYPE *)realloc(yyvs, newsize * sizeof *newvs); | ||||
856 | if (newvs == NULL((void *)0)) | ||||
857 | goto bail; | ||||
858 | yyvs = newvs; | ||||
859 | yyvsp = newvs + sslen; | ||||
860 | yystacksize = newsize; | ||||
861 | yysslim = yyss + newsize - 1; | ||||
862 | return 0; | ||||
863 | bail: | ||||
864 | if (yyss) | ||||
865 | free(yyss); | ||||
866 | if (yyvs) | ||||
867 | free(yyvs); | ||||
868 | yyss = yyssp = NULL((void *)0); | ||||
869 | yyvs = yyvsp = NULL((void *)0); | ||||
870 | yystacksize = 0; | ||||
871 | return -1; | ||||
872 | } | ||||
873 | |||||
874 | #define YYABORTgoto yyabort goto yyabort | ||||
875 | #define YYREJECTgoto yyabort goto yyabort | ||||
876 | #define YYACCEPTgoto yyaccept goto yyaccept | ||||
877 | #define YYERRORgoto yyerrlab goto yyerrlab | ||||
878 | int | ||||
879 | yyparse(void) | ||||
880 | { | ||||
881 | int yym, yyn, yystate; | ||||
882 | #if YYDEBUG0 | ||||
883 | const char *yys; | ||||
884 | |||||
885 | if ((yys = getenv("YYDEBUG"))) | ||||
886 | { | ||||
887 | yyn = *yys; | ||||
888 | if (yyn >= '0' && yyn <= '9') | ||||
889 | yydebug = yyn - '0'; | ||||
890 | } | ||||
891 | #endif /* YYDEBUG */ | ||||
892 | |||||
893 | yynerrs = 0; | ||||
894 | yyerrflag = 0; | ||||
895 | yychar = (-1); | ||||
896 | |||||
897 | if (yyss == NULL((void *)0) && yygrowstack()) goto yyoverflow; | ||||
| |||||
898 | yyssp = yyss; | ||||
899 | yyvsp = yyvs; | ||||
900 | *yyssp = yystate = 0; | ||||
901 | |||||
902 | yyloop: | ||||
903 | if ((yyn = yydefred[yystate]) != 0) goto yyreduce; | ||||
904 | if (yychar
| ||||
905 | { | ||||
906 | if ((yychar = yylex()) < 0) yychar = 0; | ||||
907 | #if YYDEBUG0 | ||||
908 | if (yydebug) | ||||
909 | { | ||||
910 | yys = 0; | ||||
911 | if (yychar <= YYMAXTOKEN273) yys = yyname[yychar]; | ||||
912 | if (!yys) yys = "illegal-symbol"; | ||||
913 | printf("%sdebug: state %d, reading %d (%s)\n", | ||||
914 | YYPREFIX"yy", yystate, yychar, yys); | ||||
915 | } | ||||
916 | #endif | ||||
917 | } | ||||
918 | if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 && | ||||
919 | yyn <= YYTABLESIZE262 && yycheck[yyn] == yychar) | ||||
920 | { | ||||
921 | #if YYDEBUG0 | ||||
922 | if (yydebug) | ||||
923 | printf("%sdebug: state %d, shifting to state %d\n", | ||||
924 | YYPREFIX"yy", yystate, yytable[yyn]); | ||||
925 | #endif | ||||
926 | if (yyssp >= yysslim && yygrowstack()) | ||||
927 | { | ||||
928 | goto yyoverflow; | ||||
929 | } | ||||
930 | *++yyssp = yystate = yytable[yyn]; | ||||
931 | *++yyvsp = yylval; | ||||
932 | yychar = (-1); | ||||
933 | if (yyerrflag
| ||||
934 | goto yyloop; | ||||
935 | } | ||||
936 | if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 && | ||||
937 | yyn <= YYTABLESIZE262 && yycheck[yyn] == yychar) | ||||
938 | { | ||||
939 | yyn = yytable[yyn]; | ||||
940 | goto yyreduce; | ||||
941 | } | ||||
942 | if (yyerrflag) goto yyinrecovery; | ||||
943 | #if defined(__GNUC__4) | ||||
944 | goto yynewerror; | ||||
945 | #endif | ||||
946 | yynewerror: | ||||
947 | yyerror("syntax error"); | ||||
948 | #if defined(__GNUC__4) | ||||
949 | goto yyerrlab; | ||||
950 | #endif | ||||
951 | yyerrlab: | ||||
952 | ++yynerrs; | ||||
953 | yyinrecovery: | ||||
954 | if (yyerrflag < 3) | ||||
955 | { | ||||
956 | yyerrflag = 3; | ||||
957 | for (;;) | ||||
958 | { | ||||
959 | if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE256) >= 0 && | ||||
960 | yyn <= YYTABLESIZE262 && yycheck[yyn] == YYERRCODE256) | ||||
961 | { | ||||
962 | #if YYDEBUG0 | ||||
963 | if (yydebug) | ||||
964 | printf("%sdebug: state %d, error recovery shifting\ | ||||
965 | to state %d\n", YYPREFIX"yy", *yyssp, yytable[yyn]); | ||||
966 | #endif | ||||
967 | if (yyssp >= yysslim && yygrowstack()) | ||||
968 | { | ||||
969 | goto yyoverflow; | ||||
970 | } | ||||
971 | *++yyssp = yystate = yytable[yyn]; | ||||
972 | *++yyvsp = yylval; | ||||
973 | goto yyloop; | ||||
974 | } | ||||
975 | else | ||||
976 | { | ||||
977 | #if YYDEBUG0 | ||||
978 | if (yydebug) | ||||
979 | printf("%sdebug: error recovery discarding state %d\n", | ||||
980 | YYPREFIX"yy", *yyssp); | ||||
981 | #endif | ||||
982 | if (yyssp <= yyss) goto yyabort; | ||||
983 | --yyssp; | ||||
984 | --yyvsp; | ||||
985 | } | ||||
986 | } | ||||
987 | } | ||||
988 | else | ||||
989 | { | ||||
990 | if (yychar == 0) goto yyabort; | ||||
991 | #if YYDEBUG0 | ||||
992 | if (yydebug) | ||||
993 | { | ||||
994 | yys = 0; | ||||
995 | if (yychar <= YYMAXTOKEN273) yys = yyname[yychar]; | ||||
996 | if (!yys) yys = "illegal-symbol"; | ||||
997 | printf("%sdebug: state %d, error recovery discards token %d (%s)\n", | ||||
998 | YYPREFIX"yy", yystate, yychar, yys); | ||||
999 | } | ||||
1000 | #endif | ||||
1001 | yychar = (-1); | ||||
1002 | goto yyloop; | ||||
1003 | } | ||||
1004 | yyreduce: | ||||
1005 | #if YYDEBUG0 | ||||
1006 | if (yydebug) | ||||
1007 | printf("%sdebug: state %d, reducing by rule %d (%s)\n", | ||||
1008 | YYPREFIX"yy", yystate, yyn, yyrule[yyn]); | ||||
1009 | #endif | ||||
1010 | yym = yylen[yyn]; | ||||
1011 | if (yym
| ||||
1012 | yyval = yyvsp[1-yym]; | ||||
1013 | else | ||||
1014 | memset(&yyval, 0, sizeof yyval); | ||||
1015 | switch (yyn) | ||||
1016 | { | ||||
1017 | case 5: | ||||
1018 | #line 124 "/usr/src/sbin/dhcpleased/parse.y" | ||||
1019 | { file->errors++; } | ||||
1020 | break; | ||||
1021 | case 6: | ||||
1022 | #line 127 "/usr/src/sbin/dhcpleased/parse.y" | ||||
1023 | { | ||||
1024 | if (asprintf(&yyval.v.string, "%s %s", yyvsp[-1].v.string, yyvsp[0].v.string) == -1) { | ||||
1025 | free(yyvsp[-1].v.string); | ||||
1026 | free(yyvsp[0].v.string); | ||||
| |||||
1027 | yyerror("string: asprintf"); | ||||
1028 | YYERRORgoto yyerrlab; | ||||
1029 | } | ||||
1030 | free(yyvsp[-1].v.string); | ||||
1031 | free(yyvsp[0].v.string); | ||||
1032 | } | ||||
1033 | break; | ||||
1034 | case 8: | ||||
1035 | #line 140 "/usr/src/sbin/dhcpleased/parse.y" | ||||
1036 | { | ||||
1037 | char *s = yyvsp[-2].v.string; | ||||
1038 | if (log_getverbose() == 1) | ||||
1039 | printf("%s = \"%s\"\n", yyvsp[-2].v.string, yyvsp[0].v.string); | ||||
1040 | while (*s++) { | ||||
1041 | if (isspace((unsigned char)*s)) { | ||||
1042 | yyerror("macro name cannot contain " | ||||
1043 | "whitespace"); | ||||
1044 | free(yyvsp[-2].v.string); | ||||
1045 | free(yyvsp[0].v.string); | ||||
1046 | YYERRORgoto yyerrlab; | ||||
1047 | } | ||||
1048 | } | ||||
1049 | if (symset(yyvsp[-2].v.string, yyvsp[0].v.string, 0) == -1) | ||||
1050 | fatal("cannot store variable"); | ||||
1051 | free(yyvsp[-2].v.string); | ||||
1052 | free(yyvsp[0].v.string); | ||||
1053 | } | ||||
1054 | break; | ||||
1055 | case 12: | ||||
1056 | #line 167 "/usr/src/sbin/dhcpleased/parse.y" | ||||
1057 | { | ||||
1058 | iface_conf = conf_get_iface(yyvsp[0].v.string); | ||||
1059 | } | ||||
1060 | break; | ||||
1061 | case 13: | ||||
1062 | #line 169 "/usr/src/sbin/dhcpleased/parse.y" | ||||
1063 | { | ||||
1064 | iface_conf = NULL((void *)0); | ||||
1065 | } | ||||
1066 | break; | ||||
1067 | case 18: | ||||
1068 | #line 182 "/usr/src/sbin/dhcpleased/parse.y" | ||||
1069 | { | ||||
1070 | ssize_t len; | ||||
1071 | char buf[256]; | ||||
1072 | |||||
1073 | if (iface_conf->vc_id != NULL((void *)0)) { | ||||
1074 | yyerror("vendor class id already set"); | ||||
1075 | YYERRORgoto yyerrlab; | ||||
1076 | } | ||||
1077 | |||||
1078 | len = strnunvis(buf, yyvsp[0].v.string, sizeof(buf)); | ||||
1079 | free(yyvsp[0].v.string); | ||||
1080 | |||||
1081 | if (len == -1) { | ||||
1082 | yyerror("invalid vendor class id"); | ||||
1083 | YYERRORgoto yyerrlab; | ||||
1084 | } | ||||
1085 | if ((size_t)len >= sizeof(buf)) { | ||||
1086 | yyerror("vendor class id too long"); | ||||
1087 | YYERRORgoto yyerrlab; | ||||
1088 | } | ||||
1089 | |||||
1090 | iface_conf->vc_id_len = 2 + strlen(buf); | ||||
1091 | iface_conf->vc_id = malloc(iface_conf->vc_id_len); | ||||
1092 | if (iface_conf->vc_id == NULL((void *)0)) { | ||||
1093 | yyerror("malloc"); | ||||
1094 | YYERRORgoto yyerrlab; | ||||
1095 | } | ||||
1096 | iface_conf->vc_id[0] = DHO_DHCP_CLASS_IDENTIFIER60; | ||||
1097 | iface_conf->vc_id[1] = iface_conf->vc_id_len - 2; | ||||
1098 | memcpy(&iface_conf->vc_id[2], buf, | ||||
1099 | iface_conf->vc_id_len - 2); | ||||
1100 | } | ||||
1101 | break; | ||||
1102 | case 19: | ||||
1103 | #line 214 "/usr/src/sbin/dhcpleased/parse.y" | ||||
1104 | { | ||||
1105 | size_t i; | ||||
1106 | ssize_t len; | ||||
1107 | int not_hex = 0, val; | ||||
1108 | char buf[256], *hex, *p, excess; | ||||
1109 | |||||
1110 | if (iface_conf->c_id != NULL((void *)0)) { | ||||
1111 | yyerror("client-id already set"); | ||||
1112 | YYERRORgoto yyerrlab; | ||||
1113 | } | ||||
1114 | |||||
1115 | /* parse as hex string including the type byte */ | ||||
1116 | if ((hex = strdup(yyvsp[0].v.string)) == NULL((void *)0)) { | ||||
1117 | free(yyvsp[0].v.string); | ||||
1118 | yyerror("malloc"); | ||||
1119 | YYERRORgoto yyerrlab; | ||||
1120 | } | ||||
1121 | for (i = 0; (p = strsep(&hex, ":")) != NULL((void *)0) && i < | ||||
1122 | sizeof(buf); ) { | ||||
1123 | if (sscanf(p, "%x%c", &val, &excess) != 1 || | ||||
1124 | val < 0 || val > 0xff) { | ||||
1125 | not_hex = 1; | ||||
1126 | break; | ||||
1127 | } | ||||
1128 | buf[i++] = (val & 0xff); | ||||
1129 | } | ||||
1130 | if (p != NULL((void *)0) && i == sizeof(buf)) | ||||
1131 | not_hex = 1; | ||||
1132 | free(hex); | ||||
1133 | |||||
1134 | if (not_hex) { | ||||
1135 | len = strnunvis(buf, yyvsp[0].v.string, sizeof(buf)); | ||||
1136 | free(yyvsp[0].v.string); | ||||
1137 | |||||
1138 | if (len == -1) { | ||||
1139 | yyerror("invalid client-id"); | ||||
1140 | YYERRORgoto yyerrlab; | ||||
1141 | } | ||||
1142 | if ((size_t)len >= sizeof(buf)) { | ||||
1143 | yyerror("client-id too long"); | ||||
1144 | YYERRORgoto yyerrlab; | ||||
1145 | } | ||||
1146 | iface_conf->c_id_len = 2 + len; | ||||
1147 | iface_conf->c_id = malloc(iface_conf->c_id_len); | ||||
1148 | if (iface_conf->c_id == NULL((void *)0)) { | ||||
1149 | yyerror("malloc"); | ||||
1150 | YYERRORgoto yyerrlab; | ||||
1151 | } | ||||
1152 | memcpy(&iface_conf->c_id[2], buf, | ||||
1153 | iface_conf->c_id_len - 2); | ||||
1154 | } else { | ||||
1155 | free(yyvsp[0].v.string); | ||||
1156 | iface_conf->c_id_len = 2 + i; | ||||
1157 | iface_conf->c_id = malloc(iface_conf->c_id_len); | ||||
1158 | if (iface_conf->c_id == NULL((void *)0)) { | ||||
1159 | yyerror("malloc"); | ||||
1160 | YYERRORgoto yyerrlab; | ||||
1161 | } | ||||
1162 | memcpy(&iface_conf->c_id[2], buf, | ||||
1163 | iface_conf->c_id_len - 2); | ||||
1164 | } | ||||
1165 | iface_conf->c_id[0] = DHO_DHCP_CLIENT_IDENTIFIER61; | ||||
1166 | iface_conf->c_id[1] = iface_conf->c_id_len - 2; | ||||
1167 | } | ||||
1168 | break; | ||||
1169 | case 20: | ||||
1170 | #line 278 "/usr/src/sbin/dhcpleased/parse.y" | ||||
1171 | { | ||||
1172 | if (iface_conf->h_name != NULL((void *)0)) { | ||||
1173 | free(yyvsp[0].v.string); | ||||
1174 | yyerror("host name already set"); | ||||
1175 | YYERRORgoto yyerrlab; | ||||
1176 | } | ||||
1177 | if (strlen(yyvsp[0].v.string) > 255) { | ||||
1178 | free(yyvsp[0].v.string); | ||||
1179 | yyerror("host name too long"); | ||||
1180 | YYERRORgoto yyerrlab; | ||||
1181 | } | ||||
1182 | iface_conf->h_name = yyvsp[0].v.string; | ||||
1183 | } | ||||
1184 | break; | ||||
1185 | case 21: | ||||
1186 | #line 291 "/usr/src/sbin/dhcpleased/parse.y" | ||||
1187 | { | ||||
1188 | if (iface_conf->h_name != NULL((void *)0)) { | ||||
1189 | yyerror("host name already set"); | ||||
1190 | YYERRORgoto yyerrlab; | ||||
1191 | } | ||||
1192 | |||||
1193 | if ((iface_conf->h_name = strdup("")) == NULL((void *)0)) { | ||||
1194 | yyerror("malloc"); | ||||
1195 | YYERRORgoto yyerrlab; | ||||
1196 | } | ||||
1197 | } | ||||
1198 | break; | ||||
1199 | case 22: | ||||
1200 | #line 302 "/usr/src/sbin/dhcpleased/parse.y" | ||||
1201 | { | ||||
1202 | iface_conf->ignore |= IGN_ROUTES1; | ||||
1203 | } | ||||
1204 | break; | ||||
1205 | case 23: | ||||
1206 | #line 305 "/usr/src/sbin/dhcpleased/parse.y" | ||||
1207 | { | ||||
1208 | iface_conf->ignore |= IGN_DNS2; | ||||
1209 | } | ||||
1210 | break; | ||||
1211 | case 24: | ||||
1212 | #line 308 "/usr/src/sbin/dhcpleased/parse.y" | ||||
1213 | { | ||||
1214 | int res; | ||||
1215 | |||||
1216 | if (iface_conf->ignore_servers_len >= MAX_SERVERS16) { | ||||
1217 | yyerror("too many servers to ignore"); | ||||
1218 | free(yyvsp[0].v.string); | ||||
1219 | YYERRORgoto yyerrlab; | ||||
1220 | } | ||||
1221 | res = inet_pton(AF_INET2, yyvsp[0].v.string, | ||||
1222 | &iface_conf->ignore_servers[ | ||||
1223 | iface_conf->ignore_servers_len++]); | ||||
1224 | |||||
1225 | if (res != 1) { | ||||
1226 | yyerror("Invalid server IP %s", yyvsp[0].v.string); | ||||
1227 | free(yyvsp[0].v.string); | ||||
1228 | YYERRORgoto yyerrlab; | ||||
1229 | } | ||||
1230 | free(yyvsp[0].v.string); | ||||
1231 | } | ||||
1232 | break; | ||||
1233 | case 25: | ||||
1234 | #line 327 "/usr/src/sbin/dhcpleased/parse.y" | ||||
1235 | { | ||||
1236 | iface_conf->prefer_ipv6 = 1; | ||||
1237 | } | ||||
1238 | break; | ||||
1239 | #line 1232 "parse.c" | ||||
1240 | } | ||||
1241 | yyssp -= yym; | ||||
1242 | yystate = *yyssp; | ||||
1243 | yyvsp -= yym; | ||||
1244 | yym = yylhs[yyn]; | ||||
1245 | if (yystate
| ||||
1246 | { | ||||
1247 | #if YYDEBUG0 | ||||
1248 | if (yydebug) | ||||
1249 | printf("%sdebug: after reduction, shifting from state 0 to\ | ||||
1250 | state %d\n", YYPREFIX"yy", YYFINAL1); | ||||
1251 | #endif | ||||
1252 | yystate = YYFINAL1; | ||||
1253 | *++yyssp = YYFINAL1; | ||||
1254 | *++yyvsp = yyval; | ||||
1255 | if (yychar
| ||||
1256 | { | ||||
1257 | if ((yychar = yylex()) < 0) yychar = 0; | ||||
1258 | #if YYDEBUG0 | ||||
1259 | if (yydebug) | ||||
1260 | { | ||||
1261 | yys = 0; | ||||
1262 | if (yychar <= YYMAXTOKEN273) yys = yyname[yychar]; | ||||
1263 | if (!yys) yys = "illegal-symbol"; | ||||
1264 | printf("%sdebug: state %d, reading %d (%s)\n", | ||||
1265 | YYPREFIX"yy", YYFINAL1, yychar, yys); | ||||
1266 | } | ||||
1267 | #endif | ||||
1268 | } | ||||
1269 | if (yychar == 0) goto yyaccept; | ||||
1270 | goto yyloop; | ||||
1271 | } | ||||
1272 | if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 && | ||||
1273 | yyn <= YYTABLESIZE262 && yycheck[yyn] == yystate) | ||||
1274 | yystate = yytable[yyn]; | ||||
1275 | else | ||||
1276 | yystate = yydgoto[yym]; | ||||
1277 | #if YYDEBUG0 | ||||
1278 | if (yydebug) | ||||
1279 | printf("%sdebug: after reduction, shifting from state %d \ | ||||
1280 | to state %d\n", YYPREFIX"yy", *yyssp, yystate); | ||||
1281 | #endif | ||||
1282 | if (yyssp >= yysslim && yygrowstack()) | ||||
1283 | { | ||||
1284 | goto yyoverflow; | ||||
1285 | } | ||||
1286 | *++yyssp = yystate; | ||||
1287 | *++yyvsp = yyval; | ||||
1288 | goto yyloop; | ||||
1289 | yyoverflow: | ||||
1290 | yyerror("yacc stack overflow"); | ||||
1291 | yyabort: | ||||
1292 | if (yyss) | ||||
1293 | free(yyss); | ||||
1294 | if (yyvs) | ||||
1295 | free(yyvs); | ||||
1296 | yyss = yyssp = NULL((void *)0); | ||||
1297 | yyvs = yyvsp = NULL((void *)0); | ||||
1298 | yystacksize = 0; | ||||
1299 | return (1); | ||||
1300 | yyaccept: | ||||
1301 | if (yyss) | ||||
1302 | free(yyss); | ||||
1303 | if (yyvs) | ||||
1304 | free(yyvs); | ||||
1305 | yyss = yyssp = NULL((void *)0); | ||||
1306 | yyvs = yyvsp = NULL((void *)0); | ||||
1307 | yystacksize = 0; | ||||
1308 | return (0); | ||||
1309 | } |