File: | src/usr.sbin/ntpd/obj/parse.c |
Warning: | line 729, column 12 Use of zero-allocated 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 23 "/usr/src/usr.sbin/ntpd/parse.y" | |||
13 | #include <sys/types.h> | |||
14 | #include <sys/socket.h> | |||
15 | #include <netinet/in.h> | |||
16 | #include <arpa/inet.h> | |||
17 | ||||
18 | #include <ctype.h> | |||
19 | #include <errno(*__errno()).h> | |||
20 | #include <limits.h> | |||
21 | #include <stdarg.h> | |||
22 | #include <stdio.h> | |||
23 | #include <stdlib.h> | |||
24 | #include <string.h> | |||
25 | #include <syslog.h> | |||
26 | ||||
27 | #include "ntpd.h" | |||
28 | ||||
29 | TAILQ_HEAD(files, file)struct files { struct file *tqh_first; struct file **tqh_last ; } files = TAILQ_HEAD_INITIALIZER(files){ ((void *)0), &(files).tqh_first }; | |||
30 | static struct file { | |||
31 | TAILQ_ENTRY(file)struct { struct file *tqe_next; struct file **tqe_prev; } entry; | |||
32 | FILE *stream; | |||
33 | char *name; | |||
34 | int lineno; | |||
35 | int errors; | |||
36 | } *file, *topfile; | |||
37 | struct file *pushfile(const char *); | |||
38 | int popfile(void); | |||
39 | int yyparse(void); | |||
40 | int yylex(void); | |||
41 | int yyerror(const char *, ...) | |||
42 | __attribute__((__format__ (printf, 1, 2))) | |||
43 | __attribute__((__nonnull__ (1))); | |||
44 | int kw_cmp(const void *, const void *); | |||
45 | int lookup(char *); | |||
46 | int lgetc(int); | |||
47 | int lungetc(int); | |||
48 | int findeol(void); | |||
49 | ||||
50 | struct sockaddr_in query_addr4; | |||
51 | struct sockaddr_in6 query_addr6; | |||
52 | int poolseqnum; | |||
53 | ||||
54 | struct opts { | |||
55 | int weight; | |||
56 | int correction; | |||
57 | int stratum; | |||
58 | int rtable; | |||
59 | int trusted; | |||
60 | char *refstr; | |||
61 | } opts; | |||
62 | void opts_default(void); | |||
63 | ||||
64 | typedef struct { | |||
65 | union { | |||
66 | int64_t number; | |||
67 | char *string; | |||
68 | struct ntp_addr_wrap *addr; | |||
69 | struct opts opts; | |||
70 | } v; | |||
71 | int lineno; | |||
72 | } YYSTYPE; | |||
73 | ||||
74 | #line 75 "parse.c" | |||
75 | #define LISTEN257 257 | |||
76 | #define ON258 258 | |||
77 | #define CONSTRAINT259 259 | |||
78 | #define CONSTRAINTS260 260 | |||
79 | #define FROM261 261 | |||
80 | #define QUERY262 262 | |||
81 | #define TRUSTED263 263 | |||
82 | #define SERVER264 264 | |||
83 | #define SERVERS265 265 | |||
84 | #define SENSOR266 266 | |||
85 | #define CORRECTION267 267 | |||
86 | #define RTABLE268 268 | |||
87 | #define REFID269 269 | |||
88 | #define STRATUM270 270 | |||
89 | #define WEIGHT271 271 | |||
90 | #define ERROR272 272 | |||
91 | #define STRING273 273 | |||
92 | #define NUMBER274 274 | |||
93 | #define YYERRCODE256 256 | |||
94 | const short yylhs[] = | |||
95 | { -1, | |||
96 | 0, 0, 0, 0, 19, 19, 19, 19, 19, 19, | |||
97 | 19, 1, 3, 3, 2, 20, 4, 4, 5, 5, | |||
98 | 6, 21, 7, 7, 8, 8, 9, 9, 22, 10, | |||
99 | 10, 11, 11, 12, 12, 12, 12, 12, 13, 15, | |||
100 | 16, 17, 14, 18, | |||
101 | }; | |||
102 | const short yylen[] = | |||
103 | { 2, | |||
104 | 0, 2, 3, 3, 4, 3, 3, 3, 3, 3, | |||
105 | 3, 1, 2, 1, 1, 0, 2, 0, 2, 1, | |||
106 | 1, 0, 2, 0, 2, 1, 1, 1, 0, 2, | |||
107 | 0, 2, 1, 1, 1, 1, 1, 1, 2, 2, | |||
108 | 2, 2, 2, 1, | |||
109 | }; | |||
110 | const short yydefred[] = | |||
111 | { 1, | |||
112 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, | |||
113 | 0, 4, 0, 0, 0, 0, 12, 0, 0, 0, | |||
114 | 3, 0, 15, 14, 0, 9, 6, 8, 0, 7, | |||
115 | 11, 0, 5, 0, 13, 44, 0, 0, 26, 27, | |||
116 | 28, 0, 0, 0, 0, 33, 34, 35, 36, 37, | |||
117 | 38, 0, 0, 20, 21, 42, 25, 39, 40, 41, | |||
118 | 32, 43, 19, | |||
119 | }; | |||
120 | const short yydgoto[] = | |||
121 | { 1, | |||
122 | 18, 24, 25, 33, 53, 54, 28, 38, 39, 31, | |||
123 | 45, 46, 47, 55, 48, 49, 40, 41, 11, 34, | |||
124 | 29, 32, | |||
125 | }; | |||
126 | const short yysindex[] = | |||
127 | { 0, | |||
128 | 8, -2, -249, -250, -241, -240, -251, -251, -247, 0, | |||
129 | 14, 0, -251, -246, -246, -245, 0, 0, 0, 0, | |||
130 | 0, 0, 0, 0, -251, 0, 0, 0, -248, 0, | |||
131 | 0, -257, 0, -243, 0, 0, -244, -248, 0, 0, | |||
132 | 0, -242, -239, -238, -257, 0, 0, 0, 0, 0, | |||
133 | 0, -237, -243, 0, 0, 0, 0, 0, 0, 0, | |||
134 | 0, 0, 0,}; | |||
135 | const short yyrindex[] = | |||
136 | { 0, | |||
137 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |||
138 | 0, 0, 0, 0, 0, 0, 0, -9, -9, -10, | |||
139 | 0, -5, 0, 0, 19, 0, 0, 0, 0, 0, | |||
140 | 0, 0, 0, 0, 0, 0, 0, 21, 0, 0, | |||
141 | 0, 0, 0, 0, 23, 0, 0, 0, 0, 0, | |||
142 | 0, 0, 25, 0, 0, 0, 0, 0, 0, 0, | |||
143 | 0, 0, 0,}; | |||
144 | const short yygindex[] = | |||
145 | { 0, | |||
146 | -6, 24, 0, 0, 0, -15, 22, 0, 2, 0, | |||
147 | 0, -3, 0, 0, 0, 0, -29, -28, 0, 0, | |||
148 | 0, 0, | |||
149 | }; | |||
150 | #define YYTABLESIZE274 274 | |||
151 | const short yytable[] = | |||
152 | { 31, | |||
153 | 24, 19, 50, 51, 18, 36, 22, 12, 13, 42, | |||
154 | 14, 43, 44, 37, 36, 50, 51, 10, 35, 15, | |||
155 | 16, 17, 37, 21, 52, 20, 23, 27, 10, 56, | |||
156 | 23, 58, 30, 59, 17, 60, 62, 63, 26, 57, | |||
157 | 30, 61, 0, 0, 0, 0, 0, 0, 0, 0, | |||
158 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |||
159 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |||
160 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |||
161 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |||
162 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |||
163 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, | |||
174 | 0, 0, 0, 0, 0, 0, 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, 29, 22, 0, 0, 29, 0, 29, 29, | |||
179 | 29, 22, 16, 2, 3, 0, 4, 5, 0, 6, | |||
180 | 0, 7, 8, 9, | |||
181 | }; | |||
182 | const short yycheck[] = | |||
183 | { 10, | |||
184 | 10, 8, 32, 32, 10, 263, 13, 10, 258, 267, | |||
185 | 261, 269, 270, 271, 263, 45, 45, 10, 25, 261, | |||
186 | 261, 273, 271, 10, 268, 273, 273, 273, 10, 274, | |||
187 | 10, 274, 10, 273, 10, 274, 274, 53, 15, 38, | |||
188 | 19, 45, -1, -1, -1, -1, -1, -1, -1, -1, | |||
189 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | |||
190 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | |||
191 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | |||
192 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | |||
193 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -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, -1, -1, -1, -1, -1, -1, | |||
204 | -1, -1, -1, -1, -1, -1, -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, 263, 263, -1, -1, 267, -1, 269, 270, | |||
210 | 271, 271, 268, 256, 257, -1, 259, 260, -1, 262, | |||
211 | -1, 264, 265, 266, | |||
212 | }; | |||
213 | #define YYFINAL1 1 | |||
214 | #ifndef YYDEBUG0 | |||
215 | #define YYDEBUG0 0 | |||
216 | #endif | |||
217 | #define YYMAXTOKEN274 274 | |||
218 | #if YYDEBUG0 | |||
219 | const char * const yyname[] = | |||
220 | { | |||
221 | "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, | |||
222 | 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, | |||
223 | 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, | |||
224 | 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, | |||
225 | 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, | |||
226 | 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, | |||
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,"LISTEN","ON","CONSTRAINT", | |||
228 | "CONSTRAINTS","FROM","QUERY","TRUSTED","SERVER","SERVERS","SENSOR","CORRECTION", | |||
229 | "RTABLE","REFID","STRATUM","WEIGHT","ERROR","STRING","NUMBER", | |||
230 | }; | |||
231 | const char * const yyrule[] = | |||
232 | {"$accept : grammar", | |||
233 | "grammar :", | |||
234 | "grammar : grammar '\\n'", | |||
235 | "grammar : grammar main '\\n'", | |||
236 | "grammar : grammar error '\\n'", | |||
237 | "main : LISTEN ON address listen_opts", | |||
238 | "main : QUERY FROM STRING", | |||
239 | "main : SERVERS address server_opts", | |||
240 | "main : SERVER address server_opts", | |||
241 | "main : CONSTRAINTS FROM url", | |||
242 | "main : CONSTRAINT FROM urllist", | |||
243 | "main : SENSOR STRING sensor_opts", | |||
244 | "address : STRING", | |||
245 | "urllist : urllist address", | |||
246 | "urllist : url", | |||
247 | "url : STRING", | |||
248 | "$$1 :", | |||
249 | "listen_opts : $$1 listen_opts_l", | |||
250 | "listen_opts :", | |||
251 | "listen_opts_l : listen_opts_l listen_opt", | |||
252 | "listen_opts_l : listen_opt", | |||
253 | "listen_opt : rtable", | |||
254 | "$$2 :", | |||
255 | "server_opts : $$2 server_opts_l", | |||
256 | "server_opts :", | |||
257 | "server_opts_l : server_opts_l server_opt", | |||
258 | "server_opts_l : server_opt", | |||
259 | "server_opt : weight", | |||
260 | "server_opt : trusted", | |||
261 | "$$3 :", | |||
262 | "sensor_opts : $$3 sensor_opts_l", | |||
263 | "sensor_opts :", | |||
264 | "sensor_opts_l : sensor_opts_l sensor_opt", | |||
265 | "sensor_opts_l : sensor_opt", | |||
266 | "sensor_opt : correction", | |||
267 | "sensor_opt : refid", | |||
268 | "sensor_opt : stratum", | |||
269 | "sensor_opt : weight", | |||
270 | "sensor_opt : trusted", | |||
271 | "correction : CORRECTION NUMBER", | |||
272 | "refid : REFID STRING", | |||
273 | "stratum : STRATUM NUMBER", | |||
274 | "weight : WEIGHT NUMBER", | |||
275 | "rtable : RTABLE NUMBER", | |||
276 | "trusted : TRUSTED", | |||
277 | }; | |||
278 | #endif | |||
279 | #ifdef YYSTACKSIZE10000 | |||
280 | #undef YYMAXDEPTH10000 | |||
281 | #define YYMAXDEPTH10000 YYSTACKSIZE10000 | |||
282 | #else | |||
283 | #ifdef YYMAXDEPTH10000 | |||
284 | #define YYSTACKSIZE10000 YYMAXDEPTH10000 | |||
285 | #else | |||
286 | #define YYSTACKSIZE10000 10000 | |||
287 | #define YYMAXDEPTH10000 10000 | |||
288 | #endif | |||
289 | #endif | |||
290 | #define YYINITSTACKSIZE200 200 | |||
291 | /* LINTUSED */ | |||
292 | int yydebug; | |||
293 | int yynerrs; | |||
294 | int yyerrflag; | |||
295 | int yychar; | |||
296 | short *yyssp; | |||
297 | YYSTYPE *yyvsp; | |||
298 | YYSTYPE yyval; | |||
299 | YYSTYPE yylval; | |||
300 | short *yyss; | |||
301 | short *yysslim; | |||
302 | YYSTYPE *yyvs; | |||
303 | unsigned int yystacksize; | |||
304 | int yyparse(void); | |||
305 | #line 494 "/usr/src/usr.sbin/ntpd/parse.y" | |||
306 | ||||
307 | void | |||
308 | opts_default(void) | |||
309 | { | |||
310 | memset(&opts, 0, sizeof opts); | |||
311 | opts.weight = 1; | |||
312 | opts.stratum = 1; | |||
313 | } | |||
314 | ||||
315 | struct keywords { | |||
316 | const char *k_name; | |||
317 | int k_val; | |||
318 | }; | |||
319 | ||||
320 | int | |||
321 | yyerror(const char *fmt, ...) | |||
322 | { | |||
323 | va_list ap; | |||
324 | char *msg; | |||
325 | ||||
326 | file->errors++; | |||
327 | va_start(ap, fmt)__builtin_va_start(ap, fmt); | |||
328 | if (vasprintf(&msg, fmt, ap) == -1) | |||
329 | fatalx("yyerror vasprintf"); | |||
330 | va_end(ap)__builtin_va_end(ap); | |||
331 | log_warnx("%s:%d: %s", file->name, yylval.lineno, msg); | |||
332 | free(msg); | |||
333 | return (0); | |||
334 | } | |||
335 | ||||
336 | int | |||
337 | kw_cmp(const void *k, const void *e) | |||
338 | { | |||
339 | return (strcmp(k, ((const struct keywords *)e)->k_name)); | |||
340 | } | |||
341 | ||||
342 | int | |||
343 | lookup(char *s) | |||
344 | { | |||
345 | /* this has to be sorted always */ | |||
346 | static const struct keywords keywords[] = { | |||
347 | { "constraint", CONSTRAINT259}, | |||
348 | { "constraints", CONSTRAINTS260}, | |||
349 | { "correction", CORRECTION267}, | |||
350 | { "from", FROM261}, | |||
351 | { "listen", LISTEN257}, | |||
352 | { "on", ON258}, | |||
353 | { "query", QUERY262}, | |||
354 | { "refid", REFID269}, | |||
355 | { "rtable", RTABLE268}, | |||
356 | { "sensor", SENSOR266}, | |||
357 | { "server", SERVER264}, | |||
358 | { "servers", SERVERS265}, | |||
359 | { "stratum", STRATUM270}, | |||
360 | { "trusted", TRUSTED263}, | |||
361 | { "weight", WEIGHT271} | |||
362 | }; | |||
363 | const struct keywords *p; | |||
364 | ||||
365 | p = bsearch(s, keywords, sizeof(keywords)/sizeof(keywords[0]), | |||
366 | sizeof(keywords[0]), kw_cmp); | |||
367 | ||||
368 | if (p) | |||
369 | return (p->k_val); | |||
370 | else | |||
371 | return (STRING273); | |||
372 | } | |||
373 | ||||
374 | #define MAXPUSHBACK128 128 | |||
375 | ||||
376 | char *parsebuf; | |||
377 | int parseindex; | |||
378 | char pushback_buffer[MAXPUSHBACK128]; | |||
379 | int pushback_index = 0; | |||
380 | ||||
381 | int | |||
382 | lgetc(int quotec) | |||
383 | { | |||
384 | int c, next; | |||
385 | ||||
386 | if (parsebuf) { | |||
387 | /* Read character from the parsebuffer instead of input. */ | |||
388 | if (parseindex >= 0) { | |||
389 | c = (unsigned char)parsebuf[parseindex++]; | |||
390 | if (c != '\0') | |||
391 | return (c); | |||
392 | parsebuf = NULL((void *)0); | |||
393 | } else | |||
394 | parseindex++; | |||
395 | } | |||
396 | ||||
397 | if (pushback_index) | |||
398 | return ((unsigned char)pushback_buffer[--pushback_index]); | |||
399 | ||||
400 | if (quotec) { | |||
401 | if ((c = getc(file->stream)(!__isthreaded ? (--(file->stream)->_r < 0 ? __srget (file->stream) : (int)(*(file->stream)->_p++)) : (getc )(file->stream))) == EOF(-1)) { | |||
402 | yyerror("reached end of file while parsing " | |||
403 | "quoted string"); | |||
404 | if (file == topfile || popfile() == EOF(-1)) | |||
405 | return (EOF(-1)); | |||
406 | return (quotec); | |||
407 | } | |||
408 | return (c); | |||
409 | } | |||
410 | ||||
411 | while ((c = getc(file->stream)(!__isthreaded ? (--(file->stream)->_r < 0 ? __srget (file->stream) : (int)(*(file->stream)->_p++)) : (getc )(file->stream))) == '\\') { | |||
412 | next = getc(file->stream)(!__isthreaded ? (--(file->stream)->_r < 0 ? __srget (file->stream) : (int)(*(file->stream)->_p++)) : (getc )(file->stream)); | |||
413 | if (next != '\n') { | |||
414 | c = next; | |||
415 | break; | |||
416 | } | |||
417 | yylval.lineno = file->lineno; | |||
418 | file->lineno++; | |||
419 | } | |||
420 | ||||
421 | while (c == EOF(-1)) { | |||
422 | if (file == topfile || popfile() == EOF(-1)) | |||
423 | return (EOF(-1)); | |||
424 | c = getc(file->stream)(!__isthreaded ? (--(file->stream)->_r < 0 ? __srget (file->stream) : (int)(*(file->stream)->_p++)) : (getc )(file->stream)); | |||
425 | } | |||
426 | return (c); | |||
427 | } | |||
428 | ||||
429 | int | |||
430 | lungetc(int c) | |||
431 | { | |||
432 | if (c == EOF(-1)) | |||
433 | return (EOF(-1)); | |||
434 | if (parsebuf) { | |||
435 | parseindex--; | |||
436 | if (parseindex >= 0) | |||
437 | return (c); | |||
438 | } | |||
439 | if (pushback_index + 1 >= MAXPUSHBACK128) | |||
440 | return (EOF(-1)); | |||
441 | pushback_buffer[pushback_index++] = c; | |||
442 | return (c); | |||
443 | } | |||
444 | ||||
445 | int | |||
446 | findeol(void) | |||
447 | { | |||
448 | int c; | |||
449 | ||||
450 | parsebuf = NULL((void *)0); | |||
451 | ||||
452 | /* skip to either EOF or the first real EOL */ | |||
453 | while (1) { | |||
454 | if (pushback_index) | |||
455 | c = (unsigned char)pushback_buffer[--pushback_index]; | |||
456 | else | |||
457 | c = lgetc(0); | |||
458 | if (c == '\n') { | |||
459 | file->lineno++; | |||
460 | break; | |||
461 | } | |||
462 | if (c == EOF(-1)) | |||
463 | break; | |||
464 | } | |||
465 | return (ERROR272); | |||
466 | } | |||
467 | ||||
468 | int | |||
469 | yylex(void) | |||
470 | { | |||
471 | char buf[8096]; | |||
472 | char *p; | |||
473 | int quotec, next, c; | |||
474 | int token; | |||
475 | ||||
476 | p = buf; | |||
477 | while ((c = lgetc(0)) == ' ' || c == '\t') | |||
478 | ; /* nothing */ | |||
479 | ||||
480 | yylval.lineno = file->lineno; | |||
481 | if (c == '#') | |||
482 | while ((c = lgetc(0)) != '\n' && c != EOF(-1)) | |||
483 | ; /* nothing */ | |||
484 | ||||
485 | switch (c) { | |||
486 | case '\'': | |||
487 | case '"': | |||
488 | quotec = c; | |||
489 | while (1) { | |||
490 | if ((c = lgetc(quotec)) == EOF(-1)) | |||
491 | return (0); | |||
492 | if (c == '\n') { | |||
493 | file->lineno++; | |||
494 | continue; | |||
495 | } else if (c == '\\') { | |||
496 | if ((next = lgetc(quotec)) == EOF(-1)) | |||
497 | return (0); | |||
498 | if (next == quotec || next == ' ' || | |||
499 | next == '\t') | |||
500 | c = next; | |||
501 | else if (next == '\n') { | |||
502 | file->lineno++; | |||
503 | continue; | |||
504 | } else | |||
505 | lungetc(next); | |||
506 | } else if (c == quotec) { | |||
507 | *p = '\0'; | |||
508 | break; | |||
509 | } else if (c == '\0') { | |||
510 | yyerror("syntax error"); | |||
511 | return (findeol()); | |||
512 | } | |||
513 | if (p + 1 >= buf + sizeof(buf) - 1) { | |||
514 | yyerror("string too long"); | |||
515 | return (findeol()); | |||
516 | } | |||
517 | *p++ = c; | |||
518 | } | |||
519 | yylval.v.string = strdup(buf); | |||
520 | if (yylval.v.string == NULL((void *)0)) | |||
521 | fatal("yylex: strdup"); | |||
522 | return (STRING273); | |||
523 | } | |||
524 | ||||
525 | #define allowed_to_end_number(x)(isspace(x) || x == ')' || x ==',' || x == '/' || x == '}' || x == '=') \ | |||
526 | (isspace(x) || x == ')' || x ==',' || x == '/' || x == '}' || x == '=') | |||
527 | ||||
528 | if (c == '-' || isdigit(c)) { | |||
529 | do { | |||
530 | *p++ = c; | |||
531 | if ((size_t)(p-buf) >= sizeof(buf)) { | |||
532 | yyerror("string too long"); | |||
533 | return (findeol()); | |||
534 | } | |||
535 | } while ((c = lgetc(0)) != EOF(-1) && isdigit(c)); | |||
536 | lungetc(c); | |||
537 | if (p == buf + 1 && buf[0] == '-') | |||
538 | goto nodigits; | |||
539 | if (c == EOF(-1) || allowed_to_end_number(c)(isspace(c) || c == ')' || c ==',' || c == '/' || c == '}' || c == '=')) { | |||
540 | const char *errstr = NULL((void *)0); | |||
541 | ||||
542 | *p = '\0'; | |||
543 | yylval.v.number = strtonum(buf, LLONG_MIN(-9223372036854775807LL -1LL), | |||
544 | LLONG_MAX9223372036854775807LL, &errstr); | |||
545 | if (errstr) { | |||
546 | yyerror("\"%s\" invalid number: %s", | |||
547 | buf, errstr); | |||
548 | return (findeol()); | |||
549 | } | |||
550 | return (NUMBER274); | |||
551 | } else { | |||
552 | nodigits: | |||
553 | while (p > buf + 1) | |||
554 | lungetc((unsigned char)*--p); | |||
555 | c = (unsigned char)*--p; | |||
556 | if (c == '-') | |||
557 | return (c); | |||
558 | } | |||
559 | } | |||
560 | ||||
561 | #define allowed_in_string(x)(isalnum(x) || (ispunct(x) && x != '(' && x != ')' && x != '{' && x != '}' && x != '<' && x != '>' && x != '!' && x != '=' && x != '/' && x != '#' && x != ',') ) \ | |||
562 | (isalnum(x) || (ispunct(x) && x != '(' && x != ')' && \ | |||
563 | x != '{' && x != '}' && x != '<' && x != '>' && \ | |||
564 | x != '!' && x != '=' && x != '/' && x != '#' && \ | |||
565 | x != ',')) | |||
566 | ||||
567 | if (isalnum(c) || c == ':' || c == '_' || c == '*') { | |||
568 | do { | |||
569 | *p++ = c; | |||
570 | if ((size_t)(p-buf) >= sizeof(buf)) { | |||
571 | yyerror("string too long"); | |||
572 | return (findeol()); | |||
573 | } | |||
574 | } while ((c = lgetc(0)) != EOF(-1) && (allowed_in_string(c)(isalnum(c) || (ispunct(c) && c != '(' && c != ')' && c != '{' && c != '}' && c != '<' && c != '>' && c != '!' && c != '=' && c != '/' && c != '#' && c != ',') ))); | |||
575 | lungetc(c); | |||
576 | *p = '\0'; | |||
577 | if ((token = lookup(buf)) == STRING273) | |||
578 | if ((yylval.v.string = strdup(buf)) == NULL((void *)0)) | |||
579 | fatal("yylex: strdup"); | |||
580 | return (token); | |||
581 | } | |||
582 | if (c == '\n') { | |||
583 | yylval.lineno = file->lineno; | |||
584 | file->lineno++; | |||
585 | } | |||
586 | if (c == EOF(-1)) | |||
587 | return (0); | |||
588 | return (c); | |||
589 | } | |||
590 | ||||
591 | struct file * | |||
592 | pushfile(const char *name) | |||
593 | { | |||
594 | struct file *nfile; | |||
595 | ||||
596 | if ((nfile = calloc(1, sizeof(struct file))) == NULL((void *)0)) { | |||
597 | log_warn("%s", __func__); | |||
598 | return (NULL((void *)0)); | |||
599 | } | |||
600 | if ((nfile->name = strdup(name)) == NULL((void *)0)) { | |||
601 | log_warn("%s", __func__); | |||
602 | free(nfile); | |||
603 | return (NULL((void *)0)); | |||
604 | } | |||
605 | if ((nfile->stream = fopen(nfile->name, "r")) == NULL((void *)0)) { | |||
606 | log_warn("%s: %s", __func__, nfile->name); | |||
607 | free(nfile->name); | |||
608 | free(nfile); | |||
609 | return (NULL((void *)0)); | |||
610 | } | |||
611 | nfile->lineno = 1; | |||
612 | 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); | |||
613 | return (nfile); | |||
614 | } | |||
615 | ||||
616 | int | |||
617 | popfile(void) | |||
618 | { | |||
619 | struct file *prev; | |||
620 | ||||
621 | if ((prev = TAILQ_PREV(file, files, entry)(*(((struct files *)((file)->entry.tqe_prev))->tqh_last ))) != NULL((void *)0)) | |||
622 | prev->errors += file->errors; | |||
623 | ||||
624 | 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); | |||
625 | fclose(file->stream); | |||
626 | free(file->name); | |||
627 | free(file); | |||
628 | file = prev; | |||
629 | return (file ? 0 : EOF(-1)); | |||
630 | } | |||
631 | ||||
632 | int | |||
633 | parse_config(const char *filename, struct ntpd_conf *xconf) | |||
634 | { | |||
635 | int errors = 0; | |||
636 | ||||
637 | conf = xconf; | |||
638 | TAILQ_INIT(&conf->listen_addrs)do { (&conf->listen_addrs)->tqh_first = ((void *)0) ; (&conf->listen_addrs)->tqh_last = &(&conf ->listen_addrs)->tqh_first; } while (0); | |||
639 | TAILQ_INIT(&conf->ntp_peers)do { (&conf->ntp_peers)->tqh_first = ((void *)0); ( &conf->ntp_peers)->tqh_last = &(&conf->ntp_peers )->tqh_first; } while (0); | |||
640 | TAILQ_INIT(&conf->ntp_conf_sensors)do { (&conf->ntp_conf_sensors)->tqh_first = ((void * )0); (&conf->ntp_conf_sensors)->tqh_last = &(& conf->ntp_conf_sensors)->tqh_first; } while (0); | |||
641 | TAILQ_INIT(&conf->constraints)do { (&conf->constraints)->tqh_first = ((void *)0); (&conf->constraints)->tqh_last = &(&conf-> constraints)->tqh_first; } while (0); | |||
642 | ||||
643 | if ((file = pushfile(filename)) == NULL((void *)0)) { | |||
644 | return (-1); | |||
645 | } | |||
646 | topfile = file; | |||
647 | ||||
648 | yyparse(); | |||
649 | errors = file->errors; | |||
650 | popfile(); | |||
651 | ||||
652 | return (errors ? -1 : 0); | |||
653 | } | |||
654 | #line 647 "parse.c" | |||
655 | /* allocate initial stack or double stack size, up to YYMAXDEPTH */ | |||
656 | static int yygrowstack(void) | |||
657 | { | |||
658 | unsigned int newsize; | |||
659 | long sslen; | |||
660 | short *newss; | |||
661 | YYSTYPE *newvs; | |||
662 | ||||
663 | if ((newsize = yystacksize) == 0) | |||
664 | newsize = YYINITSTACKSIZE200; | |||
665 | else if (newsize >= YYMAXDEPTH10000) | |||
666 | return -1; | |||
667 | else if ((newsize *= 2) > YYMAXDEPTH10000) | |||
668 | newsize = YYMAXDEPTH10000; | |||
669 | sslen = yyssp - yyss; | |||
670 | #ifdef SIZE_MAX0xffffffffffffffffUL | |||
671 | #define YY_SIZE_MAX0xffffffffffffffffUL SIZE_MAX0xffffffffffffffffUL | |||
672 | #else | |||
673 | #define YY_SIZE_MAX0xffffffffffffffffUL 0xffffffffU | |||
674 | #endif | |||
675 | if (newsize && YY_SIZE_MAX0xffffffffffffffffUL / newsize < sizeof *newss) | |||
676 | goto bail; | |||
677 | newss = (short *)realloc(yyss, newsize * sizeof *newss); | |||
678 | if (newss == NULL((void *)0)) | |||
679 | goto bail; | |||
680 | yyss = newss; | |||
681 | yyssp = newss + sslen; | |||
682 | if (newsize
| |||
683 | goto bail; | |||
684 | newvs = (YYSTYPE *)realloc(yyvs, newsize * sizeof *newvs); | |||
685 | if (newvs == NULL((void *)0)) | |||
686 | goto bail; | |||
687 | yyvs = newvs; | |||
688 | yyvsp = newvs + sslen; | |||
689 | yystacksize = newsize; | |||
690 | yysslim = yyss + newsize - 1; | |||
691 | return 0; | |||
692 | bail: | |||
693 | if (yyss) | |||
694 | free(yyss); | |||
695 | if (yyvs) | |||
696 | free(yyvs); | |||
697 | yyss = yyssp = NULL((void *)0); | |||
698 | yyvs = yyvsp = NULL((void *)0); | |||
699 | yystacksize = 0; | |||
700 | return -1; | |||
701 | } | |||
702 | ||||
703 | #define YYABORTgoto yyabort goto yyabort | |||
704 | #define YYREJECTgoto yyabort goto yyabort | |||
705 | #define YYACCEPTgoto yyaccept goto yyaccept | |||
706 | #define YYERRORgoto yyerrlab goto yyerrlab | |||
707 | int | |||
708 | yyparse(void) | |||
709 | { | |||
710 | int yym, yyn, yystate; | |||
711 | #if YYDEBUG0 | |||
712 | const char *yys; | |||
713 | ||||
714 | if ((yys = getenv("YYDEBUG"))) | |||
715 | { | |||
716 | yyn = *yys; | |||
717 | if (yyn >= '0' && yyn <= '9') | |||
718 | yydebug = yyn - '0'; | |||
719 | } | |||
720 | #endif /* YYDEBUG */ | |||
721 | ||||
722 | yynerrs = 0; | |||
723 | yyerrflag = 0; | |||
724 | yychar = (-1); | |||
725 | ||||
726 | if (yyss == NULL((void *)0) && yygrowstack()) goto yyoverflow; | |||
| ||||
727 | yyssp = yyss; | |||
728 | yyvsp = yyvs; | |||
729 | *yyssp = yystate = 0; | |||
| ||||
730 | ||||
731 | yyloop: | |||
732 | if ((yyn = yydefred[yystate]) != 0) goto yyreduce; | |||
733 | if (yychar < 0) | |||
734 | { | |||
735 | if ((yychar = yylex()) < 0) yychar = 0; | |||
736 | #if YYDEBUG0 | |||
737 | if (yydebug) | |||
738 | { | |||
739 | yys = 0; | |||
740 | if (yychar <= YYMAXTOKEN274) yys = yyname[yychar]; | |||
741 | if (!yys) yys = "illegal-symbol"; | |||
742 | printf("%sdebug: state %d, reading %d (%s)\n", | |||
743 | YYPREFIX"yy", yystate, yychar, yys); | |||
744 | } | |||
745 | #endif | |||
746 | } | |||
747 | if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 && | |||
748 | yyn <= YYTABLESIZE274 && yycheck[yyn] == yychar) | |||
749 | { | |||
750 | #if YYDEBUG0 | |||
751 | if (yydebug) | |||
752 | printf("%sdebug: state %d, shifting to state %d\n", | |||
753 | YYPREFIX"yy", yystate, yytable[yyn]); | |||
754 | #endif | |||
755 | if (yyssp >= yysslim && yygrowstack()) | |||
756 | { | |||
757 | goto yyoverflow; | |||
758 | } | |||
759 | *++yyssp = yystate = yytable[yyn]; | |||
760 | *++yyvsp = yylval; | |||
761 | yychar = (-1); | |||
762 | if (yyerrflag > 0) --yyerrflag; | |||
763 | goto yyloop; | |||
764 | } | |||
765 | if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 && | |||
766 | yyn <= YYTABLESIZE274 && yycheck[yyn] == yychar) | |||
767 | { | |||
768 | yyn = yytable[yyn]; | |||
769 | goto yyreduce; | |||
770 | } | |||
771 | if (yyerrflag) goto yyinrecovery; | |||
772 | #if defined(__GNUC__4) | |||
773 | goto yynewerror; | |||
774 | #endif | |||
775 | yynewerror: | |||
776 | yyerror("syntax error"); | |||
777 | #if defined(__GNUC__4) | |||
778 | goto yyerrlab; | |||
779 | #endif | |||
780 | yyerrlab: | |||
781 | ++yynerrs; | |||
782 | yyinrecovery: | |||
783 | if (yyerrflag < 3) | |||
784 | { | |||
785 | yyerrflag = 3; | |||
786 | for (;;) | |||
787 | { | |||
788 | if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE256) >= 0 && | |||
789 | yyn <= YYTABLESIZE274 && yycheck[yyn] == YYERRCODE256) | |||
790 | { | |||
791 | #if YYDEBUG0 | |||
792 | if (yydebug) | |||
793 | printf("%sdebug: state %d, error recovery shifting\ | |||
794 | to state %d\n", YYPREFIX"yy", *yyssp, yytable[yyn]); | |||
795 | #endif | |||
796 | if (yyssp >= yysslim && yygrowstack()) | |||
797 | { | |||
798 | goto yyoverflow; | |||
799 | } | |||
800 | *++yyssp = yystate = yytable[yyn]; | |||
801 | *++yyvsp = yylval; | |||
802 | goto yyloop; | |||
803 | } | |||
804 | else | |||
805 | { | |||
806 | #if YYDEBUG0 | |||
807 | if (yydebug) | |||
808 | printf("%sdebug: error recovery discarding state %d\n", | |||
809 | YYPREFIX"yy", *yyssp); | |||
810 | #endif | |||
811 | if (yyssp <= yyss) goto yyabort; | |||
812 | --yyssp; | |||
813 | --yyvsp; | |||
814 | } | |||
815 | } | |||
816 | } | |||
817 | else | |||
818 | { | |||
819 | if (yychar == 0) goto yyabort; | |||
820 | #if YYDEBUG0 | |||
821 | if (yydebug) | |||
822 | { | |||
823 | yys = 0; | |||
824 | if (yychar <= YYMAXTOKEN274) yys = yyname[yychar]; | |||
825 | if (!yys) yys = "illegal-symbol"; | |||
826 | printf("%sdebug: state %d, error recovery discards token %d (%s)\n", | |||
827 | YYPREFIX"yy", yystate, yychar, yys); | |||
828 | } | |||
829 | #endif | |||
830 | yychar = (-1); | |||
831 | goto yyloop; | |||
832 | } | |||
833 | yyreduce: | |||
834 | #if YYDEBUG0 | |||
835 | if (yydebug) | |||
836 | printf("%sdebug: state %d, reducing by rule %d (%s)\n", | |||
837 | YYPREFIX"yy", yystate, yyn, yyrule[yyn]); | |||
838 | #endif | |||
839 | yym = yylen[yyn]; | |||
840 | if (yym) | |||
841 | yyval = yyvsp[1-yym]; | |||
842 | else | |||
843 | memset(&yyval, 0, sizeof yyval); | |||
844 | switch (yyn) | |||
845 | { | |||
846 | case 4: | |||
847 | #line 106 "/usr/src/usr.sbin/ntpd/parse.y" | |||
848 | { file->errors++; } | |||
849 | break; | |||
850 | case 5: | |||
851 | #line 109 "/usr/src/usr.sbin/ntpd/parse.y" | |||
852 | { | |||
853 | struct listen_addr *la; | |||
854 | struct ntp_addr *h, *next; | |||
855 | ||||
856 | if ((h = yyvsp[-1].v.addr->a) == NULL((void *)0) && | |||
857 | (host_dns(yyvsp[-1].v.addr->name, 0, &h) == -1 || !h)) { | |||
858 | yyerror("could not resolve \"%s\"", yyvsp[-1].v.addr->name); | |||
859 | free(yyvsp[-1].v.addr->name); | |||
860 | free(yyvsp[-1].v.addr); | |||
861 | YYERRORgoto yyerrlab; | |||
862 | } | |||
863 | ||||
864 | for (; h != NULL((void *)0); h = next) { | |||
865 | next = h->next; | |||
866 | la = calloc(1, sizeof(struct listen_addr)); | |||
867 | if (la == NULL((void *)0)) | |||
868 | fatal("listen on calloc"); | |||
869 | la->fd = -1; | |||
870 | la->rtable = yyvsp[0].v.opts.rtable; | |||
871 | memcpy(&la->sa, &h->ss, | |||
872 | sizeof(struct sockaddr_storage)); | |||
873 | TAILQ_INSERT_TAIL(&conf->listen_addrs, la,do { (la)->entry.tqe_next = ((void *)0); (la)->entry.tqe_prev = (&conf->listen_addrs)->tqh_last; *(&conf-> listen_addrs)->tqh_last = (la); (&conf->listen_addrs )->tqh_last = &(la)->entry.tqe_next; } while (0) | |||
874 | entry)do { (la)->entry.tqe_next = ((void *)0); (la)->entry.tqe_prev = (&conf->listen_addrs)->tqh_last; *(&conf-> listen_addrs)->tqh_last = (la); (&conf->listen_addrs )->tqh_last = &(la)->entry.tqe_next; } while (0); | |||
875 | free(h); | |||
876 | } | |||
877 | free(yyvsp[-1].v.addr->name); | |||
878 | free(yyvsp[-1].v.addr); | |||
879 | } | |||
880 | break; | |||
881 | case 6: | |||
882 | #line 137 "/usr/src/usr.sbin/ntpd/parse.y" | |||
883 | { | |||
884 | struct sockaddr_in sin4; | |||
885 | struct sockaddr_in6 sin6; | |||
886 | ||||
887 | memset(&sin4, 0, sizeof(sin4)); | |||
888 | sin4.sin_family = AF_INET2; | |||
889 | sin4.sin_len = sizeof(struct sockaddr_in); | |||
890 | memset(&sin6, 0, sizeof(sin6)); | |||
891 | sin6.sin6_family = AF_INET624; | |||
892 | sin6.sin6_len = sizeof(struct sockaddr_in6); | |||
893 | ||||
894 | if (inet_pton(AF_INET2, yyvsp[0].v.string, &sin4.sin_addr) == 1) | |||
895 | memcpy(&query_addr4, &sin4, sin4.sin_len); | |||
896 | else if (inet_pton(AF_INET624, yyvsp[0].v.string, &sin6.sin6_addr) == 1) | |||
897 | memcpy(&query_addr6, &sin6, sin6.sin6_len); | |||
898 | else { | |||
899 | yyerror("invalid IPv4 or IPv6 address: %s\n", | |||
900 | yyvsp[0].v.string); | |||
901 | free(yyvsp[0].v.string); | |||
902 | YYERRORgoto yyerrlab; | |||
903 | } | |||
904 | ||||
905 | free(yyvsp[0].v.string); | |||
906 | } | |||
907 | break; | |||
908 | case 7: | |||
909 | #line 161 "/usr/src/usr.sbin/ntpd/parse.y" | |||
910 | { | |||
911 | struct ntp_peer *p; | |||
912 | struct ntp_addr *h, *next; | |||
913 | ||||
914 | h = yyvsp[-1].v.addr->a; | |||
915 | do { | |||
916 | if (h != NULL((void *)0)) { | |||
917 | next = h->next; | |||
918 | if (h->ss.ss_family != AF_INET2 && | |||
919 | h->ss.ss_family != AF_INET624) { | |||
920 | yyerror("IPv4 or IPv6 address " | |||
921 | "or hostname expected"); | |||
922 | free(h); | |||
923 | free(yyvsp[-1].v.addr->name); | |||
924 | free(yyvsp[-1].v.addr); | |||
925 | YYERRORgoto yyerrlab; | |||
926 | } | |||
927 | h->next = NULL((void *)0); | |||
928 | } else | |||
929 | next = NULL((void *)0); | |||
930 | ||||
931 | p = new_peer(); | |||
932 | p->weight = yyvsp[0].v.opts.weight; | |||
933 | p->trusted = yyvsp[0].v.opts.trusted; | |||
934 | conf->trusted_peers = conf->trusted_peers || | |||
935 | yyvsp[0].v.opts.trusted; | |||
936 | p->query_addr4 = query_addr4; | |||
937 | p->query_addr6 = query_addr6; | |||
938 | p->addr = h; | |||
939 | p->addr_head.a = h; | |||
940 | p->addr_head.pool = ++poolseqnum; | |||
941 | p->addr_head.name = strdup(yyvsp[-1].v.addr->name); | |||
942 | if (p->addr_head.name == NULL((void *)0)) | |||
943 | fatal(NULL((void *)0)); | |||
944 | if (p->addr != NULL((void *)0)) | |||
945 | p->state = STATE_DNS_DONE; | |||
946 | TAILQ_INSERT_TAIL(&conf->ntp_peers, p, entry)do { (p)->entry.tqe_next = ((void *)0); (p)->entry.tqe_prev = (&conf->ntp_peers)->tqh_last; *(&conf->ntp_peers )->tqh_last = (p); (&conf->ntp_peers)->tqh_last = &(p)->entry.tqe_next; } while (0); | |||
947 | h = next; | |||
948 | } while (h != NULL((void *)0)); | |||
949 | ||||
950 | free(yyvsp[-1].v.addr->name); | |||
951 | free(yyvsp[-1].v.addr); | |||
952 | } | |||
953 | break; | |||
954 | case 8: | |||
955 | #line 204 "/usr/src/usr.sbin/ntpd/parse.y" | |||
956 | { | |||
957 | struct ntp_peer *p; | |||
958 | struct ntp_addr *h, *next; | |||
959 | ||||
960 | p = new_peer(); | |||
961 | for (h = yyvsp[-1].v.addr->a; h != NULL((void *)0); h = next) { | |||
962 | next = h->next; | |||
963 | if (h->ss.ss_family != AF_INET2 && | |||
964 | h->ss.ss_family != AF_INET624) { | |||
965 | yyerror("IPv4 or IPv6 address " | |||
966 | "or hostname expected"); | |||
967 | free(h); | |||
968 | free(p); | |||
969 | free(yyvsp[-1].v.addr->name); | |||
970 | free(yyvsp[-1].v.addr); | |||
971 | YYERRORgoto yyerrlab; | |||
972 | } | |||
973 | h->next = p->addr; | |||
974 | p->addr = h; | |||
975 | } | |||
976 | ||||
977 | p->weight = yyvsp[0].v.opts.weight; | |||
978 | p->trusted = yyvsp[0].v.opts.trusted; | |||
979 | conf->trusted_peers = conf->trusted_peers || | |||
980 | yyvsp[0].v.opts.trusted; | |||
981 | p->query_addr4 = query_addr4; | |||
982 | p->query_addr6 = query_addr6; | |||
983 | p->addr_head.a = p->addr; | |||
984 | p->addr_head.pool = 0; | |||
985 | p->addr_head.name = strdup(yyvsp[-1].v.addr->name); | |||
986 | if (p->addr_head.name == NULL((void *)0)) | |||
987 | fatal(NULL((void *)0)); | |||
988 | if (p->addr != NULL((void *)0)) | |||
989 | p->state = STATE_DNS_DONE; | |||
990 | TAILQ_INSERT_TAIL(&conf->ntp_peers, p, entry)do { (p)->entry.tqe_next = ((void *)0); (p)->entry.tqe_prev = (&conf->ntp_peers)->tqh_last; *(&conf->ntp_peers )->tqh_last = (p); (&conf->ntp_peers)->tqh_last = &(p)->entry.tqe_next; } while (0); | |||
991 | free(yyvsp[-1].v.addr->name); | |||
992 | free(yyvsp[-1].v.addr); | |||
993 | } | |||
994 | break; | |||
995 | case 9: | |||
996 | #line 242 "/usr/src/usr.sbin/ntpd/parse.y" | |||
997 | { | |||
998 | struct constraint *p; | |||
999 | struct ntp_addr *h, *next; | |||
1000 | ||||
1001 | h = yyvsp[0].v.addr->a; | |||
1002 | do { | |||
1003 | if (h != NULL((void *)0)) { | |||
1004 | next = h->next; | |||
1005 | if (h->ss.ss_family != AF_INET2 && | |||
1006 | h->ss.ss_family != AF_INET624) { | |||
1007 | yyerror("IPv4 or IPv6 address " | |||
1008 | "or hostname expected"); | |||
1009 | free(h); | |||
1010 | free(yyvsp[0].v.addr->name); | |||
1011 | free(yyvsp[0].v.addr->path); | |||
1012 | free(yyvsp[0].v.addr); | |||
1013 | YYERRORgoto yyerrlab; | |||
1014 | } | |||
1015 | h->next = NULL((void *)0); | |||
1016 | } else | |||
1017 | next = NULL((void *)0); | |||
1018 | ||||
1019 | p = new_constraint(); | |||
1020 | p->addr = h; | |||
1021 | p->addr_head.a = h; | |||
1022 | p->addr_head.pool = ++poolseqnum; | |||
1023 | p->addr_head.name = strdup(yyvsp[0].v.addr->name); | |||
1024 | p->addr_head.path = strdup(yyvsp[0].v.addr->path); | |||
1025 | if (p->addr_head.name == NULL((void *)0) || | |||
1026 | p->addr_head.path == NULL((void *)0)) | |||
1027 | fatal(NULL((void *)0)); | |||
1028 | if (p->addr != NULL((void *)0)) | |||
1029 | p->state = STATE_DNS_DONE; | |||
1030 | constraint_add(p); | |||
1031 | h = next; | |||
1032 | } while (h != NULL((void *)0)); | |||
1033 | ||||
1034 | free(yyvsp[0].v.addr->name); | |||
1035 | free(yyvsp[0].v.addr); | |||
1036 | } | |||
1037 | break; | |||
1038 | case 10: | |||
1039 | #line 282 "/usr/src/usr.sbin/ntpd/parse.y" | |||
1040 | { | |||
1041 | struct constraint *p; | |||
1042 | struct ntp_addr *h, *next; | |||
1043 | ||||
1044 | p = new_constraint(); | |||
1045 | for (h = yyvsp[0].v.addr->a; h != NULL((void *)0); h = next) { | |||
1046 | next = h->next; | |||
1047 | if (h->ss.ss_family != AF_INET2 && | |||
1048 | h->ss.ss_family != AF_INET624) { | |||
1049 | yyerror("IPv4 or IPv6 address " | |||
1050 | "or hostname expected"); | |||
1051 | free(h); | |||
1052 | free(p); | |||
1053 | free(yyvsp[0].v.addr->name); | |||
1054 | free(yyvsp[0].v.addr->path); | |||
1055 | free(yyvsp[0].v.addr); | |||
1056 | YYERRORgoto yyerrlab; | |||
1057 | } | |||
1058 | h->next = p->addr; | |||
1059 | p->addr = h; | |||
1060 | } | |||
1061 | ||||
1062 | p->addr_head.a = p->addr; | |||
1063 | p->addr_head.pool = 0; | |||
1064 | p->addr_head.name = strdup(yyvsp[0].v.addr->name); | |||
1065 | p->addr_head.path = strdup(yyvsp[0].v.addr->path); | |||
1066 | if (p->addr_head.name == NULL((void *)0) || | |||
1067 | p->addr_head.path == NULL((void *)0)) | |||
1068 | fatal(NULL((void *)0)); | |||
1069 | if (p->addr != NULL((void *)0)) | |||
1070 | p->state = STATE_DNS_DONE; | |||
1071 | constraint_add(p); | |||
1072 | free(yyvsp[0].v.addr->name); | |||
1073 | free(yyvsp[0].v.addr); | |||
1074 | } | |||
1075 | break; | |||
1076 | case 11: | |||
1077 | #line 317 "/usr/src/usr.sbin/ntpd/parse.y" | |||
1078 | { | |||
1079 | struct ntp_conf_sensor *s; | |||
1080 | ||||
1081 | s = new_sensor(yyvsp[-1].v.string); | |||
1082 | s->weight = yyvsp[0].v.opts.weight; | |||
1083 | s->correction = yyvsp[0].v.opts.correction; | |||
1084 | s->refstr = yyvsp[0].v.opts.refstr; | |||
1085 | s->stratum = yyvsp[0].v.opts.stratum; | |||
1086 | s->trusted = yyvsp[0].v.opts.trusted; | |||
1087 | conf->trusted_sensors = conf->trusted_sensors || | |||
1088 | yyvsp[0].v.opts.trusted; | |||
1089 | free(yyvsp[-1].v.string); | |||
1090 | TAILQ_INSERT_TAIL(&conf->ntp_conf_sensors, s, entry)do { (s)->entry.tqe_next = ((void *)0); (s)->entry.tqe_prev = (&conf->ntp_conf_sensors)->tqh_last; *(&conf ->ntp_conf_sensors)->tqh_last = (s); (&conf->ntp_conf_sensors )->tqh_last = &(s)->entry.tqe_next; } while (0); | |||
1091 | } | |||
1092 | break; | |||
1093 | case 12: | |||
1094 | #line 333 "/usr/src/usr.sbin/ntpd/parse.y" | |||
1095 | { | |||
1096 | if ((yyval.v.addr = calloc(1, sizeof(struct ntp_addr_wrap))) == | |||
1097 | NULL((void *)0)) | |||
1098 | fatal(NULL((void *)0)); | |||
1099 | host(yyvsp[0].v.string, &yyval.v.addr->a); | |||
1100 | yyval.v.addr->name = yyvsp[0].v.string; | |||
1101 | } | |||
1102 | break; | |||
1103 | case 13: | |||
1104 | #line 342 "/usr/src/usr.sbin/ntpd/parse.y" | |||
1105 | { | |||
1106 | struct ntp_addr *p, *q = NULL((void *)0); | |||
1107 | struct in_addr ina; | |||
1108 | struct in6_addr in6a; | |||
1109 | ||||
1110 | if (inet_pton(AF_INET2, yyvsp[0].v.addr->name, &ina) != 1 && | |||
1111 | inet_pton(AF_INET624, yyvsp[0].v.addr->name, &in6a) != 1) { | |||
1112 | yyerror("url can only be followed by IP " | |||
1113 | "addresses"); | |||
1114 | free(yyvsp[0].v.addr->name); | |||
1115 | free(yyvsp[0].v.addr); | |||
1116 | YYERRORgoto yyerrlab; | |||
1117 | } | |||
1118 | p = yyvsp[0].v.addr->a; | |||
1119 | while (p != NULL((void *)0)) { | |||
1120 | q = p; | |||
1121 | p = p->next; | |||
1122 | } | |||
1123 | if (q != NULL((void *)0)) { | |||
1124 | q->next = yyvsp[-1].v.addr->a; | |||
1125 | yyvsp[-1].v.addr->a = yyvsp[0].v.addr->a; | |||
1126 | free(yyvsp[0].v.addr); | |||
1127 | } | |||
1128 | yyval.v.addr = yyvsp[-1].v.addr; | |||
1129 | } | |||
1130 | break; | |||
1131 | case 14: | |||
1132 | #line 367 "/usr/src/usr.sbin/ntpd/parse.y" | |||
1133 | { | |||
1134 | yyval.v.addr = yyvsp[0].v.addr; | |||
1135 | } | |||
1136 | break; | |||
1137 | case 15: | |||
1138 | #line 372 "/usr/src/usr.sbin/ntpd/parse.y" | |||
1139 | { | |||
1140 | char *hname, *path; | |||
1141 | ||||
1142 | if ((yyval.v.addr = calloc(1, sizeof(struct ntp_addr_wrap))) == | |||
1143 | NULL((void *)0)) | |||
1144 | fatal("calloc"); | |||
1145 | ||||
1146 | if (strncmp("https://", yyvsp[0].v.string, | |||
1147 | strlen("https://")) != 0) { | |||
1148 | host(yyvsp[0].v.string, &yyval.v.addr->a); | |||
1149 | yyval.v.addr->name = yyvsp[0].v.string; | |||
1150 | } else { | |||
1151 | hname = yyvsp[0].v.string + strlen("https://"); | |||
1152 | ||||
1153 | path = hname + strcspn(hname, "/\\"); | |||
1154 | if (*path != '\0') { | |||
1155 | if ((yyval.v.addr->path = strdup(path)) == NULL((void *)0)) | |||
1156 | fatal("strdup"); | |||
1157 | *path = '\0'; | |||
1158 | } | |||
1159 | host(hname, &yyval.v.addr->a); | |||
1160 | if ((yyval.v.addr->name = strdup(hname)) == NULL((void *)0)) | |||
1161 | fatal("strdup"); | |||
1162 | } | |||
1163 | if (yyval.v.addr->path == NULL((void *)0) && | |||
1164 | (yyval.v.addr->path = strdup("/")) == NULL((void *)0)) | |||
1165 | fatal("strdup"); | |||
1166 | } | |||
1167 | break; | |||
1168 | case 16: | |||
1169 | #line 402 "/usr/src/usr.sbin/ntpd/parse.y" | |||
1170 | { opts_default(); } | |||
1171 | break; | |||
1172 | case 17: | |||
1173 | #line 404 "/usr/src/usr.sbin/ntpd/parse.y" | |||
1174 | { yyval.v.opts = opts; } | |||
1175 | break; | |||
1176 | case 18: | |||
1177 | #line 405 "/usr/src/usr.sbin/ntpd/parse.y" | |||
1178 | { opts_default(); yyval.v.opts = opts; } | |||
1179 | break; | |||
1180 | case 22: | |||
1181 | #line 413 "/usr/src/usr.sbin/ntpd/parse.y" | |||
1182 | { opts_default(); } | |||
1183 | break; | |||
1184 | case 23: | |||
1185 | #line 415 "/usr/src/usr.sbin/ntpd/parse.y" | |||
1186 | { yyval.v.opts = opts; } | |||
1187 | break; | |||
1188 | case 24: | |||
1189 | #line 416 "/usr/src/usr.sbin/ntpd/parse.y" | |||
1190 | { opts_default(); yyval.v.opts = opts; } | |||
1191 | break; | |||
1192 | case 29: | |||
1193 | #line 425 "/usr/src/usr.sbin/ntpd/parse.y" | |||
1194 | { opts_default(); } | |||
1195 | break; | |||
1196 | case 30: | |||
1197 | #line 427 "/usr/src/usr.sbin/ntpd/parse.y" | |||
1198 | { yyval.v.opts = opts; } | |||
1199 | break; | |||
1200 | case 31: | |||
1201 | #line 428 "/usr/src/usr.sbin/ntpd/parse.y" | |||
1202 | { opts_default(); yyval.v.opts = opts; } | |||
1203 | break; | |||
1204 | case 39: | |||
1205 | #line 440 "/usr/src/usr.sbin/ntpd/parse.y" | |||
1206 | { | |||
1207 | if (yyvsp[0].v.number < -127000000 || yyvsp[0].v.number > 127000000) { | |||
1208 | yyerror("correction must be between " | |||
1209 | "-127000000 and 127000000 microseconds"); | |||
1210 | YYERRORgoto yyerrlab; | |||
1211 | } | |||
1212 | opts.correction = yyvsp[0].v.number; | |||
1213 | } | |||
1214 | break; | |||
1215 | case 40: | |||
1216 | #line 450 "/usr/src/usr.sbin/ntpd/parse.y" | |||
1217 | { | |||
1218 | size_t l = strlen(yyvsp[0].v.string); | |||
1219 | ||||
1220 | if (l < 1 || l > 4) { | |||
1221 | yyerror("refid must be 1 to 4 characters"); | |||
1222 | free(yyvsp[0].v.string); | |||
1223 | YYERRORgoto yyerrlab; | |||
1224 | } | |||
1225 | opts.refstr = yyvsp[0].v.string; | |||
1226 | } | |||
1227 | break; | |||
1228 | case 41: | |||
1229 | #line 462 "/usr/src/usr.sbin/ntpd/parse.y" | |||
1230 | { | |||
1231 | if (yyvsp[0].v.number < 1 || yyvsp[0].v.number > 15) { | |||
1232 | yyerror("stratum must be between " | |||
1233 | "1 and 15"); | |||
1234 | YYERRORgoto yyerrlab; | |||
1235 | } | |||
1236 | opts.stratum = yyvsp[0].v.number; | |||
1237 | } | |||
1238 | break; | |||
1239 | case 42: | |||
1240 | #line 472 "/usr/src/usr.sbin/ntpd/parse.y" | |||
1241 | { | |||
1242 | if (yyvsp[0].v.number < 1 || yyvsp[0].v.number > 10) { | |||
1243 | yyerror("weight must be between 1 and 10"); | |||
1244 | YYERRORgoto yyerrlab; | |||
1245 | } | |||
1246 | opts.weight = yyvsp[0].v.number; | |||
1247 | } | |||
1248 | break; | |||
1249 | case 43: | |||
1250 | #line 479 "/usr/src/usr.sbin/ntpd/parse.y" | |||
1251 | { | |||
1252 | if (yyvsp[0].v.number < 0 || yyvsp[0].v.number > RT_TABLEID_MAX255) { | |||
1253 | yyerror("rtable must be between 1" | |||
1254 | " and RT_TABLEID_MAX"); | |||
1255 | YYERRORgoto yyerrlab; | |||
1256 | } | |||
1257 | opts.rtable = yyvsp[0].v.number; | |||
1258 | } | |||
1259 | break; | |||
1260 | case 44: | |||
1261 | #line 489 "/usr/src/usr.sbin/ntpd/parse.y" | |||
1262 | { | |||
1263 | opts.trusted = 1; | |||
1264 | } | |||
1265 | break; | |||
1266 | #line 1259 "parse.c" | |||
1267 | } | |||
1268 | yyssp -= yym; | |||
1269 | yystate = *yyssp; | |||
1270 | yyvsp -= yym; | |||
1271 | yym = yylhs[yyn]; | |||
1272 | if (yystate == 0 && yym == 0) | |||
1273 | { | |||
1274 | #if YYDEBUG0 | |||
1275 | if (yydebug) | |||
1276 | printf("%sdebug: after reduction, shifting from state 0 to\ | |||
1277 | state %d\n", YYPREFIX"yy", YYFINAL1); | |||
1278 | #endif | |||
1279 | yystate = YYFINAL1; | |||
1280 | *++yyssp = YYFINAL1; | |||
1281 | *++yyvsp = yyval; | |||
1282 | if (yychar < 0) | |||
1283 | { | |||
1284 | if ((yychar = yylex()) < 0) yychar = 0; | |||
1285 | #if YYDEBUG0 | |||
1286 | if (yydebug) | |||
1287 | { | |||
1288 | yys = 0; | |||
1289 | if (yychar <= YYMAXTOKEN274) yys = yyname[yychar]; | |||
1290 | if (!yys) yys = "illegal-symbol"; | |||
1291 | printf("%sdebug: state %d, reading %d (%s)\n", | |||
1292 | YYPREFIX"yy", YYFINAL1, yychar, yys); | |||
1293 | } | |||
1294 | #endif | |||
1295 | } | |||
1296 | if (yychar == 0) goto yyaccept; | |||
1297 | goto yyloop; | |||
1298 | } | |||
1299 | if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 && | |||
1300 | yyn <= YYTABLESIZE274 && yycheck[yyn] == yystate) | |||
1301 | yystate = yytable[yyn]; | |||
1302 | else | |||
1303 | yystate = yydgoto[yym]; | |||
1304 | #if YYDEBUG0 | |||
1305 | if (yydebug) | |||
1306 | printf("%sdebug: after reduction, shifting from state %d \ | |||
1307 | to state %d\n", YYPREFIX"yy", *yyssp, yystate); | |||
1308 | #endif | |||
1309 | if (yyssp >= yysslim && yygrowstack()) | |||
1310 | { | |||
1311 | goto yyoverflow; | |||
1312 | } | |||
1313 | *++yyssp = yystate; | |||
1314 | *++yyvsp = yyval; | |||
1315 | goto yyloop; | |||
1316 | yyoverflow: | |||
1317 | yyerror("yacc stack overflow"); | |||
1318 | yyabort: | |||
1319 | if (yyss) | |||
1320 | free(yyss); | |||
1321 | if (yyvs) | |||
1322 | free(yyvs); | |||
1323 | yyss = yyssp = NULL((void *)0); | |||
1324 | yyvs = yyvsp = NULL((void *)0); | |||
1325 | yystacksize = 0; | |||
1326 | return (1); | |||
1327 | yyaccept: | |||
1328 | if (yyss) | |||
1329 | free(yyss); | |||
1330 | if (yyvs) | |||
1331 | free(yyvs); | |||
1332 | yyss = yyssp = NULL((void *)0); | |||
1333 | yyvs = yyvsp = NULL((void *)0); | |||
1334 | yystacksize = 0; | |||
1335 | return (0); | |||
1336 | } |