Bug Summary

File:src/usr.sbin/snmpd/obj/parse.c
Warning:line 1268, column 12
Use of zero-allocated memory

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple amd64-unknown-openbsd7.0 -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name parse.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 1 -pic-is-pie -mframe-pointer=all -relaxed-aliasing -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -target-feature +retpoline-indirect-calls -target-feature +retpoline-indirect-branches -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/usr/src/usr.sbin/snmpd/obj -resource-dir /usr/local/lib/clang/13.0.0 -I /usr/src/usr.sbin/snmpd -internal-isystem /usr/local/lib/clang/13.0.0/include -internal-externc-isystem /usr/include -O2 -fdebug-compilation-dir=/usr/src/usr.sbin/snmpd/obj -ferror-limit 19 -fwrapv -D_RET_PROTECTOR -ret-protector -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-valloc -fno-builtin-free -fno-builtin-strdup -fno-builtin-strndup -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /home/ben/Projects/vmm/scan-build/2022-01-12-194120-40624-1 -x c parse.c
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/usr.sbin/snmpd/parse.y"
13#include <sys/types.h>
14#include <sys/socket.h>
15#include <sys/stat.h>
16#include <sys/queue.h>
17#include <sys/tree.h>
18
19#include <netinet/in.h>
20#include <net/if.h>
21
22#include <arpa/inet.h>
23
24#include <openssl/sha.h>
25
26#include <ctype.h>
27#include <unistd.h>
28#include <err.h>
29#include <errno(*__errno()).h>
30#include <event.h>
31#include <inttypes.h>
32#include <limits.h>
33#include <stdint.h>
34#include <stdarg.h>
35#include <stdlib.h>
36#include <stdio.h>
37#include <netdb.h>
38#include <string.h>
39#include <syslog.h>
40
41#include "snmpd.h"
42#include "mib.h"
43
44TAILQ_HEAD(files, file)struct files { struct file *tqh_first; struct file **tqh_last
; }
files = TAILQ_HEAD_INITIALIZER(files){ ((void*)0), &(files).tqh_first };
45static struct file {
46 TAILQ_ENTRY(file)struct { struct file *tqe_next; struct file **tqe_prev; } entry;
47 FILE *stream;
48 char *name;
49 size_t ungetpos;
50 size_t ungetsize;
51 u_char *ungetbuf;
52 int eof_reached;
53 int lineno;
54 int errors;
55} *file, *topfile;
56struct file *pushfile(const char *, int);
57int popfile(void);
58int check_file_secrecy(int, const char *);
59int yyparse(void);
60int yylex(void);
61int yyerror(const char *, ...)
62 __attribute__((__format__ (printf, 1, 2)))
63 __attribute__((__nonnull__ (1)));
64int kw_cmp(const void *, const void *);
65int lookup(char *);
66int igetc(void);
67int lgetc(int);
68void lungetc(int);
69int findeol(void);
70
71TAILQ_HEAD(symhead, sym)struct symhead { struct sym *tqh_first; struct sym **tqh_last
; }
symhead = TAILQ_HEAD_INITIALIZER(symhead){ ((void*)0), &(symhead).tqh_first };
72struct sym {
73 TAILQ_ENTRY(sym)struct { struct sym *tqe_next; struct sym **tqe_prev; } entry;
74 int used;
75 int persist;
76 char *nam;
77 char *val;
78};
79int symset(const char *, const char *, int);
80char *symget(const char *);
81
82struct snmpd *conf = NULL((void*)0);
83static int errors = 0;
84static struct usmuser *user = NULL((void*)0);
85
86static uint8_t engineid[SNMPD_MAXENGINEIDLEN32];
87static int32_t enginepen;
88static size_t engineidlen;
89
90int host(const char *, const char *, int,
91 struct sockaddr_storage *, int);
92int listen_add(struct sockaddr_storage *, int, int);
93
94typedef struct {
95 union {
96 int64_t number;
97 char *string;
98 struct host *host;
99 struct timeval tv;
100 struct ber_oid *oid;
101 struct {
102 int type;
103 void *data;
104 long long value;
105 } data;
106 enum usmauth auth;
107 enum usmpriv enc;
108 } v;
109 int lineno;
110} YYSTYPE;
111
112#line 113 "parse.c"
113#define INCLUDE257 257
114#define LISTEN258 258
115#define ON259 259
116#define READ260 260
117#define WRITE261 261
118#define NOTIFY262 262
119#define SNMPV1263 263
120#define SNMPV2264 264
121#define SNMPV3265 265
122#define ENGINEID266 266
123#define PEN267 267
124#define OPENBSD268 268
125#define IP4269 269
126#define IP6270 270
127#define MAC271 271
128#define TEXT272 272
129#define OCTETS273 273
130#define AGENTID274 274
131#define HOSTHASH275 275
132#define SYSTEM276 276
133#define CONTACT277 277
134#define DESCR278 278
135#define LOCATION279 279
136#define NAME280 280
137#define OBJECTID281 281
138#define SERVICES282 282
139#define RTFILTER283 283
140#define READONLY284 284
141#define READWRITE285 285
142#define OCTETSTRING286 286
143#define INTEGER287 287
144#define COMMUNITY288 288
145#define TRAP289 289
146#define RECEIVER290 290
147#define SECLEVEL291 291
148#define NONE292 292
149#define AUTH293 293
150#define ENC294 294
151#define USER295 295
152#define AUTHKEY296 296
153#define ENCKEY297 297
154#define ERROR298 298
155#define HANDLE299 299
156#define DEFAULT300 300
157#define SRCADDR301 301
158#define TCP302 302
159#define UDP303 303
160#define PFADDRFILTER304 304
161#define PORT305 305
162#define STRING306 306
163#define NUMBER307 307
164#define YYERRCODE256 256
165const short yylhs[] =
166 { -1,
167 0, 0, 0, 0, 0, 0, 0, 0, 23, 24,
168 10, 25, 25, 25, 25, 25, 25, 25, 25, 25,
169 25, 32, 25, 4, 4, 4, 6, 6, 5, 5,
170 5, 5, 5, 5, 28, 8, 8, 8, 33, 33,
171 33, 33, 33, 33, 33, 33, 34, 34, 35, 35,
172 35, 36, 29, 26, 37, 37, 37, 37, 37, 37,
173 27, 12, 12, 9, 9, 18, 20, 20, 19, 19,
174 1, 2, 3, 3, 17, 17, 16, 16, 15, 14,
175 14, 14, 7, 7, 38, 39, 39, 30, 30, 40,
176 40, 11, 11, 11, 31, 31, 41, 41, 41, 41,
177 21, 22, 13,
178};
179const short yylen[] =
180 { 2,
181 0, 3, 2, 3, 3, 3, 3, 3, 2, 3,
182 1, 3, 1, 3, 3, 3, 3, 4, 2, 2,
183 1, 0, 4, 0, 1, 1, 0, 2, 1, 1,
184 1, 1, 1, 1, 4, 0, 2, 2, 2, 2,
185 2, 2, 2, 2, 2, 2, 1, 1, 0, 2,
186 2, 0, 4, 2, 2, 2, 2, 2, 2, 2,
187 6, 2, 2, 1, 1, 1, 1, 1, 0, 2,
188 2, 2, 0, 1, 1, 1, 0, 2, 1, 1,
189 2, 2, 0, 2, 4, 0, 3, 1, 3, 0,
190 1, 2, 2, 2, 0, 2, 2, 2, 2, 2,
191 1, 1, 1,
192};
193const short yydefred[] =
194 { 1,
195 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
196 0, 0, 0, 0, 0, 3, 21, 0, 0, 0,
197 0, 0, 13, 8, 9, 0, 0, 52, 0, 0,
198 0, 0, 0, 0, 54, 66, 0, 11, 19, 0,
199 0, 0, 0, 0, 92, 93, 94, 22, 20, 0,
200 2, 4, 5, 6, 7, 26, 25, 0, 12, 51,
201 50, 0, 55, 56, 57, 58, 59, 60, 0, 14,
202 15, 16, 0, 86, 17, 88, 68, 67, 0, 95,
203 10, 0, 0, 0, 0, 0, 0, 0, 0, 0,
204 47, 53, 0, 0, 0, 0, 103, 18, 0, 0,
205 27, 39, 40, 41, 42, 43, 44, 45, 46, 64,
206 65, 0, 70, 0, 77, 0, 80, 0, 89, 91,
207 0, 0, 0, 0, 0, 96, 37, 38, 0, 0,
208 0, 61, 0, 74, 81, 82, 0, 85, 0, 75,
209 76, 78, 87, 101, 98, 102, 100, 97, 99, 29,
210 30, 31, 32, 33, 34, 28, 63, 62, 72, 84,
211 71,
212};
213const short yydgoto[] =
214 { 1,
215 140, 134, 135, 58, 156, 129, 138, 101, 112, 39,
216 17, 132, 98, 116, 117, 118, 142, 37, 95, 79,
217 145, 147, 18, 19, 20, 21, 22, 59, 23, 75,
218 99, 80, 91, 92, 28, 62, 35, 76, 96, 121,
219 126,
220};
221const short yysindex[] =
222 { 0,
223 -10, 3, -270, -208, -215, -212, -252, -243, -211, -210,
224 -256, -282, -227, -243, 19, 0, 0, 71, 72, 74,
225 75, 76, 0, 0, 0, -272, -259, 0, -219, -217,
226 -216, -214, -252, -213, 0, 0, -192, 0, 0, -209,
227 -207, -206, -122, -271, 0, 0, 0, 0, 0, -205,
228 0, 0, 0, 0, 0, 0, 0, -204, 0, 0,
229 0, -254, 0, 0, 0, 0, 0, 0, -203, 0,
230 0, 0, -190, 0, 0, 0, 0, 0, -202, 0,
231 0, -200, -199, -198, -197, -196, -195, -194, -193, -191,
232 0, 0, -240, -252, -218, -42, 0, 0, -235, -257,
233 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
234 0, -230, 0, -182, 0, -187, 0, -258, 0, 0,
235 -188, -181, -180, -179, -178, 0, 0, 0, -189, -177,
236 -183, 0, -176, 0, 0, 0, -175, 0, -174, 0,
237 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
238 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
239 0,};
240const short yyrindex[] =
241 { 0,
242 0, 0, 0, 0, -247, 0, 0, 0, 0, 0,
243 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
244 0, 0, 0, 0, 0, -173, 0, 0, 0, 0,
245 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
246 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
247 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
248 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
249 0, 0, -4, 0, 0, 0, 0, 0, 0, 0,
250 0, 45, 0, 0, 0, 0, 0, 0, 83, 0,
251 0, 0, 0, 0, -3, -172, 0, 0, 85, 0,
252 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
253 0, 0, 0, -6, 0, -5, 0, -2, 0, 0,
254 0, 0, 0, 0, 0, 0, 0, 0, 86, 0,
255 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
256 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
257 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
258 0,};
259const short yygindex[] =
260 { 0,
261 0, 0, 0, 0, 0, 0, 0, 0, 0, 84,
262 -1, 0, 0, 0, 1, 0, 0, -30, 0, 0,
263 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
264 0, 0, 0, 0, 0, 0, 0, 14, 0, 0,
265 0,
266};
267#define YYTABLESIZE310 310
268const short yytable[] =
269 { 16,
270 74, 120, 67, 73, 83, 69, 77, 79, 60, 45,
271 46, 47, 24, 78, 83, 84, 85, 86, 87, 88,
272 89, 49, 49, 49, 49, 49, 49, 49, 77, 56,
273 57, 42, 12, 43, 36, 25, 139, 73, 83, 69,
274 77, 79, 44, 110, 111, 114, 115, 61, 127, 128,
275 26, 27, 90, 36, 36, 130, 131, 122, 123, 49,
276 124, 125, 38, 113, 29, 30, 31, 32, 33, 34,
277 150, 151, 152, 153, 154, 155, 40, 41, 48, 50,
278 51, 52, 119, 53, 54, 55, 63, 69, 64, 65,
279 94, 66, 48, 68, 23, 35, 70, 49, 71, 72,
280 81, 82, 93, 97, 100, 133, 102, 103, 104, 105,
281 106, 107, 108, 137, 109, 136, 141, 73, 73, 83,
282 69, 77, 79, 158, 144, 146, 148, 149, 157, 159,
283 160, 161, 24, 90, 143, 0, 0, 0, 0, 0,
284 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
285 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
286 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
287 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
288 0, 0, 0, 73, 0, 0, 0, 0, 0, 0,
289 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
290 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
291 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
292 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
293 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
294 0, 0, 0, 0, 0, 2, 3, 4, 0, 0,
295 0, 0, 0, 0, 0, 5, 0, 0, 0, 69,
296 69, 0, 0, 0, 0, 6, 0, 0, 0, 0,
297 7, 0, 8, 9, 10, 0, 0, 0, 11, 0,
298 12, 0, 0, 0, 13, 0, 69, 77, 0, 0,
299 69, 77, 0, 14, 73, 15, 69, 77, 79, 73,
300 83, 69, 77, 79, 36, 36, 36, 36, 36, 36,
301};
302const short yycheck[] =
303 { 10,
304 123, 44, 33, 10, 10, 10, 10, 10, 268, 292,
305 293, 294, 10, 44, 269, 270, 271, 272, 273, 274,
306 275, 269, 270, 271, 272, 273, 274, 275, 300, 302,
307 303, 288, 291, 290, 306, 306, 295, 44, 44, 44,
308 44, 44, 299, 284, 285, 264, 265, 307, 306, 307,
309 259, 267, 307, 306, 10, 286, 287, 293, 294, 307,
310 296, 297, 306, 94, 277, 278, 279, 280, 281, 282,
311 260, 261, 262, 263, 264, 265, 288, 288, 306, 61,
312 10, 10, 125, 10, 10, 10, 306, 280, 306, 306,
313 281, 306, 10, 307, 10, 10, 306, 14, 306, 306,
314 306, 306, 306, 306, 305, 288, 306, 306, 306, 306,
315 306, 306, 306, 301, 306, 115, 118, 306, 125, 125,
316 125, 125, 125, 307, 306, 306, 306, 306, 306, 306,
317 306, 306, 306, 306, 121, -1, -1, -1, -1, -1,
318 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
319 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
320 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
321 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
322 -1, -1, -1, 306, -1, -1, -1, -1, -1, -1,
323 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
324 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
325 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
326 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
327 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
328 -1, -1, -1, -1, -1, 256, 257, 258, -1, -1,
329 -1, -1, -1, -1, -1, 266, -1, -1, -1, 264,
330 265, -1, -1, -1, -1, 276, -1, -1, -1, -1,
331 281, -1, 283, 284, 285, -1, -1, -1, 289, -1,
332 291, -1, -1, -1, 295, -1, 291, 291, -1, -1,
333 295, 295, -1, 304, 301, 306, 301, 301, 301, 306,
334 306, 306, 306, 306, 260, 261, 262, 263, 264, 265,
335};
336#define YYFINAL1 1
337#ifndef YYDEBUG0
338#define YYDEBUG0 0
339#endif
340#define YYMAXTOKEN307 307
341#if YYDEBUG0
342const char * const yyname[] =
343 {
344"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,
3450,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,
3460,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,
3470,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,
3480,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,
3490,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,
3500,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,"INCLUDE",
351"LISTEN","ON","READ","WRITE","NOTIFY","SNMPV1","SNMPV2","SNMPV3","ENGINEID",
352"PEN","OPENBSD","IP4","IP6","MAC","TEXT","OCTETS","AGENTID","HOSTHASH","SYSTEM",
353"CONTACT","DESCR","LOCATION","NAME","OBJECTID","SERVICES","RTFILTER","READONLY",
354"READWRITE","OCTETSTRING","INTEGER","COMMUNITY","TRAP","RECEIVER","SECLEVEL",
355"NONE","AUTH","ENC","USER","AUTHKEY","ENCKEY","ERROR","HANDLE","DEFAULT",
356"SRCADDR","TCP","UDP","PFADDRFILTER","PORT","STRING","NUMBER",
357};
358const char * const yyrule[] =
359 {"$accept : grammar",
360"grammar :",
361"grammar : grammar include '\\n'",
362"grammar : grammar '\\n'",
363"grammar : grammar varset '\\n'",
364"grammar : grammar main '\\n'",
365"grammar : grammar system '\\n'",
366"grammar : grammar mib '\\n'",
367"grammar : grammar error '\\n'",
368"include : INCLUDE STRING",
369"varset : STRING '=' STRING",
370"yesno : STRING",
371"main : LISTEN ON listen_udptcp",
372"main : engineid_local",
373"main : READONLY COMMUNITY STRING",
374"main : READWRITE COMMUNITY STRING",
375"main : TRAP COMMUNITY STRING",
376"main : TRAP RECEIVER host",
377"main : TRAP HANDLE trapoid cmd",
378"main : RTFILTER yesno",
379"main : PFADDRFILTER yesno",
380"main : seclevel",
381"$$1 :",
382"main : USER STRING $$1 userspecs",
383"listenproto :",
384"listenproto : UDP",
385"listenproto : TCP",
386"listenflags :",
387"listenflags : listenflags listenflag",
388"listenflag : READ",
389"listenflag : WRITE",
390"listenflag : NOTIFY",
391"listenflag : SNMPV1",
392"listenflag : SNMPV2",
393"listenflag : SNMPV3",
394"listen_udptcp : listenproto STRING port listenflags",
395"port :",
396"port : PORT STRING",
397"port : PORT NUMBER",
398"enginefmt : IP4 STRING",
399"enginefmt : IP6 STRING",
400"enginefmt : MAC STRING",
401"enginefmt : TEXT STRING",
402"enginefmt : OCTETS STRING",
403"enginefmt : AGENTID STRING",
404"enginefmt : HOSTHASH STRING",
405"enginefmt : NUMBER STRING",
406"enginefmt_local : enginefmt",
407"enginefmt_local : HOSTHASH",
408"pen :",
409"pen : PEN NUMBER",
410"pen : PEN OPENBSD",
411"$$2 :",
412"engineid_local : ENGINEID pen $$2 enginefmt_local",
413"system : SYSTEM sysmib",
414"sysmib : CONTACT STRING",
415"sysmib : DESCR STRING",
416"sysmib : LOCATION STRING",
417"sysmib : NAME STRING",
418"sysmib : OBJECTID oid",
419"sysmib : SERVICES NUMBER",
420"mib : OBJECTID oid NAME STRING optwrite objtype",
421"objtype : INTEGER NUMBER",
422"objtype : OCTETSTRING STRING",
423"optwrite : READONLY",
424"optwrite : READWRITE",
425"oid : STRING",
426"trapoid : oid",
427"trapoid : DEFAULT",
428"hostoid :",
429"hostoid : OBJECTID oid",
430"usmuser : USER STRING",
431"community : COMMUNITY STRING",
432"optcommunity :",
433"optcommunity : community",
434"usmauthopt : usmuser",
435"usmauthopt : seclevel",
436"usmauthopts :",
437"usmauthopts : usmauthopts usmauthopt",
438"hostauthv3 : usmauthopts",
439"hostauth : hostauthv3",
440"hostauth : SNMPV2 optcommunity",
441"hostauth : SNMPV3 hostauthv3",
442"srcaddr :",
443"srcaddr : SRCADDR STRING",
444"hostdef : STRING hostoid hostauth srcaddr",
445"hostlist :",
446"hostlist : hostlist comma hostdef",
447"host : hostdef",
448"host : '{' hostlist '}'",
449"comma :",
450"comma : ','",
451"seclevel : SECLEVEL NONE",
452"seclevel : SECLEVEL AUTH",
453"seclevel : SECLEVEL ENC",
454"userspecs :",
455"userspecs : userspecs userspec",
456"userspec : AUTHKEY STRING",
457"userspec : AUTH auth",
458"userspec : ENCKEY STRING",
459"userspec : ENC enc",
460"auth : STRING",
461"enc : STRING",
462"cmd : STRING",
463};
464#endif
465#ifdef YYSTACKSIZE10000
466#undef YYMAXDEPTH10000
467#define YYMAXDEPTH10000 YYSTACKSIZE10000
468#else
469#ifdef YYMAXDEPTH10000
470#define YYSTACKSIZE10000 YYMAXDEPTH10000
471#else
472#define YYSTACKSIZE10000 10000
473#define YYMAXDEPTH10000 10000
474#endif
475#endif
476#define YYINITSTACKSIZE200 200
477/* LINTUSED */
478int yydebug;
479int yynerrs;
480int yyerrflag;
481int yychar;
482short *yyssp;
483YYSTYPE *yyvsp;
484YYSTYPE yyval;
485YYSTYPE yylval;
486short *yyss;
487short *yysslim;
488YYSTYPE *yyvs;
489unsigned int yystacksize;
490int yyparse(void);
491#line 963 "/usr/src/usr.sbin/snmpd/parse.y"
492
493struct keywords {
494 const char *k_name;
495 int k_val;
496};
497
498int
499yyerror(const char *fmt, ...)
500{
501 va_list ap;
502 char *msg;
503
504 file->errors++;
505 va_start(ap, fmt)__builtin_va_start(ap, fmt);
506 if (vasprintf(&msg, fmt, ap) == -1)
507 fatalx("yyerror vasprintf");
508 va_end(ap)__builtin_va_end(ap);
509 logit(LOG_CRIT2, "%s:%d: %s", file->name, yylval.lineno, msg);
510 free(msg);
511 return (0);
512}
513
514int
515kw_cmp(const void *k, const void *e)
516{
517 return (strcmp(k, ((const struct keywords *)e)->k_name));
518}
519
520int
521lookup(char *s)
522{
523 /* this has to be sorted always */
524 static const struct keywords keywords[] = {
525 { "agentid", AGENTID274 },
526 { "auth", AUTH293 },
527 { "authkey", AUTHKEY296 },
528 { "community", COMMUNITY288 },
529 { "contact", CONTACT277 },
530 { "default", DEFAULT300 },
531 { "description", DESCR278 },
532 { "enc", ENC294 },
533 { "enckey", ENCKEY297 },
534 { "engineid", ENGINEID266 },
535 { "filter-pf-addresses", PFADDRFILTER304 },
536 { "filter-routes", RTFILTER283 },
537 { "handle", HANDLE299 },
538 { "hosthash", HOSTHASH275 },
539 { "include", INCLUDE257 },
540 { "integer", INTEGER287 },
541 { "ipv4", IP4269 },
542 { "ipv6", IP6270 },
543 { "listen", LISTEN258 },
544 { "location", LOCATION279 },
545 { "mac", MAC271 },
546 { "name", NAME280 },
547 { "none", NONE292 },
548 { "notify", NOTIFY262 },
549 { "octets", OCTETS273 },
550 { "oid", OBJECTID281 },
551 { "on", ON259 },
552 { "openbsd", OPENBSD268 },
553 { "pen", PEN267 },
554 { "port", PORT305 },
555 { "read", READ260 },
556 { "read-only", READONLY284 },
557 { "read-write", READWRITE285 },
558 { "receiver", RECEIVER290 },
559 { "seclevel", SECLEVEL291 },
560 { "services", SERVICES282 },
561 { "snmpv1", SNMPV1263 },
562 { "snmpv2c", SNMPV2264 },
563 { "snmpv3", SNMPV3265 },
564 { "source-address", SRCADDR301 },
565 { "string", OCTETSTRING286 },
566 { "system", SYSTEM276 },
567 { "tcp", TCP302 },
568 { "text", TEXT272 },
569 { "trap", TRAP289 },
570 { "udp", UDP303 },
571 { "user", USER295 },
572 { "write", WRITE261 }
573 };
574 const struct keywords *p;
575
576 p = bsearch(s, keywords, sizeof(keywords)/sizeof(keywords[0]),
577 sizeof(keywords[0]), kw_cmp);
578
579 if (p)
580 return (p->k_val);
581 else
582 return (STRING306);
583}
584
585#define START_EXPAND1 1
586#define DONE_EXPAND2 2
587
588static int expanding;
589
590int
591igetc(void)
592{
593 int c;
594
595 while (1) {
596 if (file->ungetpos > 0)
597 c = file->ungetbuf[--file->ungetpos];
598 else c = getc(file->stream)(!__isthreaded ? (--(file->stream)->_r < 0 ? __srget
(file->stream) : (int)(*(file->stream)->_p++)) : (getc
)(file->stream))
;
599
600 if (c == START_EXPAND1)
601 expanding = 1;
602 else if (c == DONE_EXPAND2)
603 expanding = 0;
604 else
605 break;
606 }
607 return (c);
608}
609
610int
611lgetc(int quotec)
612{
613 int c, next;
614
615 if (quotec) {
616 if ((c = igetc()) == EOF(-1)) {
617 yyerror("reached end of file while parsing quoted string");
618 if (file == topfile || popfile() == EOF(-1))
619 return (EOF(-1));
620 return (quotec);
621 }
622 return (c);
623 }
624
625 while ((c = igetc()) == '\\') {
626 next = igetc();
627 if (next != '\n') {
628 c = next;
629 break;
630 }
631 yylval.lineno = file->lineno;
632 file->lineno++;
633 }
634 if (c == '\t' || c == ' ') {
635 /* Compress blanks to a single space. */
636 do {
637 c = getc(file->stream)(!__isthreaded ? (--(file->stream)->_r < 0 ? __srget
(file->stream) : (int)(*(file->stream)->_p++)) : (getc
)(file->stream))
;
638 } while (c == '\t' || c == ' ');
639 ungetc(c, file->stream);
640 c = ' ';
641 }
642
643 if (c == EOF(-1)) {
644 /*
645 * Fake EOL when hit EOF for the first time. This gets line
646 * count right if last line in included file is syntactically
647 * invalid and has no newline.
648 */
649 if (file->eof_reached == 0) {
650 file->eof_reached = 1;
651 return ('\n');
652 }
653 while (c == EOF(-1)) {
654 if (file == topfile || popfile() == EOF(-1))
655 return (EOF(-1));
656 c = igetc();
657 }
658 }
659 return (c);
660}
661
662void
663lungetc(int c)
664{
665 if (c == EOF(-1))
666 return;
667
668 if (file->ungetpos >= file->ungetsize) {
669 void *p = reallocarray(file->ungetbuf, file->ungetsize, 2);
670 if (p == NULL((void*)0))
671 err(1, "%s", __func__);
672 file->ungetbuf = p;
673 file->ungetsize *= 2;
674 }
675 file->ungetbuf[file->ungetpos++] = c;
676}
677
678int
679findeol(void)
680{
681 int c;
682
683 /* skip to either EOF or the first real EOL */
684 while (1) {
685 c = lgetc(0);
686 if (c == '\n') {
687 file->lineno++;
688 break;
689 }
690 if (c == EOF(-1))
691 break;
692 }
693 return (ERROR298);
694}
695
696int
697yylex(void)
698{
699 char buf[8096];
700 char *p, *val;
701 int quotec, next, c;
702 int token;
703
704top:
705 p = buf;
706 while ((c = lgetc(0)) == ' ' || c == '\t')
707 ; /* nothing */
708
709 yylval.lineno = file->lineno;
710 if (c == '#')
711 while ((c = lgetc(0)) != '\n' && c != EOF(-1))
712 ; /* nothing */
713 if (c == '$' && !expanding) {
714 while (1) {
715 if ((c = lgetc(0)) == EOF(-1))
716 return (0);
717
718 if (p + 1 >= buf + sizeof(buf) - 1) {
719 yyerror("string too long");
720 return (findeol());
721 }
722 if (isalnum(c) || c == '_') {
723 *p++ = c;
724 continue;
725 }
726 *p = '\0';
727 lungetc(c);
728 break;
729 }
730 val = symget(buf);
731 if (val == NULL((void*)0)) {
732 yyerror("macro '%s' not defined", buf);
733 return (findeol());
734 }
735 p = val + strlen(val) - 1;
736 lungetc(DONE_EXPAND2);
737 while (p >= val) {
738 lungetc((unsigned char)*p);
739 p--;
740 }
741 lungetc(START_EXPAND1);
742 goto top;
743 }
744
745 switch (c) {
746 case '\'':
747 case '"':
748 quotec = c;
749 while (1) {
750 if ((c = lgetc(quotec)) == EOF(-1))
751 return (0);
752 if (c == '\n') {
753 file->lineno++;
754 continue;
755 } else if (c == '\\') {
756 if ((next = lgetc(quotec)) == EOF(-1))
757 return (0);
758 if (next == quotec || next == ' ' ||
759 next == '\t')
760 c = next;
761 else if (next == '\n') {
762 file->lineno++;
763 continue;
764 } else
765 lungetc(next);
766 } else if (c == quotec) {
767 *p = '\0';
768 break;
769 } else if (c == '\0') {
770 yyerror("syntax error");
771 return (findeol());
772 }
773 if (p + 1 >= buf + sizeof(buf) - 1) {
774 yyerror("string too long");
775 return (findeol());
776 }
777 *p++ = c;
778 }
779 yylval.v.string = strdup(buf);
780 if (yylval.v.string == NULL((void*)0))
781 err(1, "%s", __func__);
782 return (STRING306);
783 }
784
785#define allowed_to_end_number(x)(isspace(x) || x == ')' || x ==',' || x == '/' || x == '}' ||
x == '=')
\
786 (isspace(x) || x == ')' || x ==',' || x == '/' || x == '}' || x == '=')
787
788 if (c == '-' || isdigit(c)) {
789 do {
790 *p++ = c;
791 if ((size_t)(p-buf) >= sizeof(buf)) {
792 yyerror("string too long");
793 return (findeol());
794 }
795 } while ((c = lgetc(0)) != EOF(-1) && isdigit(c));
796 lungetc(c);
797 if (p == buf + 1 && buf[0] == '-')
798 goto nodigits;
799 if (c == EOF(-1) || allowed_to_end_number(c)(isspace(c) || c == ')' || c ==',' || c == '/' || c == '}' ||
c == '=')
) {
800 const char *errstr = NULL((void*)0);
801
802 *p = '\0';
803 yylval.v.number = strtonum(buf, LLONG_MIN(-9223372036854775807LL -1LL),
804 LLONG_MAX9223372036854775807LL, &errstr);
805 if (errstr) {
806 yyerror("\"%s\" invalid number: %s",
807 buf, errstr);
808 return (findeol());
809 }
810 return (NUMBER307);
811 } else {
812nodigits:
813 while (p > buf + 1)
814 lungetc((unsigned char)*--p);
815 c = (unsigned char)*--p;
816 if (c == '-')
817 return (c);
818 }
819 }
820
821#define allowed_in_string(x)(isalnum(x) || (ispunct(x) && x != '(' && x !=
')' && x != '{' && x != '}' && x != '!'
&& x != '=' && x != '#' && x != ',')
)
\
822 (isalnum(x) || (ispunct(x) && x != '(' && x != ')' && \
823 x != '{' && x != '}' && \
824 x != '!' && x != '=' && x != '#' && \
825 x != ','))
826
827 if (isalnum(c) || c == ':' || c == '_') {
828 do {
829 *p++ = c;
830 if ((size_t)(p-buf) >= sizeof(buf)) {
831 yyerror("string too long");
832 return (findeol());
833 }
834 } while ((c = lgetc(0)) != EOF(-1) && (allowed_in_string(c)(isalnum(c) || (ispunct(c) && c != '(' && c !=
')' && c != '{' && c != '}' && c != '!'
&& c != '=' && c != '#' && c != ',')
)
));
835 lungetc(c);
836 *p = '\0';
837 if ((token = lookup(buf)) == STRING306)
838 if ((yylval.v.string = strdup(buf)) == NULL((void*)0))
839 err(1, "%s", __func__);
840 return (token);
841 }
842 if (c == '\n') {
843 yylval.lineno = file->lineno;
844 file->lineno++;
845 }
846 if (c == EOF(-1))
847 return (0);
848 return (c);
849}
850
851int
852check_file_secrecy(int fd, const char *fname)
853{
854 struct stat st;
855
856 if (fstat(fd, &st)) {
857 log_warn("cannot stat %s", fname);
858 return (-1);
859 }
860 if (st.st_uid != 0 && st.st_uid != getuid()) {
861 log_warnx("%s: owner not root or current user", fname);
862 return (-1);
863 }
864 if (st.st_mode & (S_IWGRP0000020 | S_IXGRP0000010 | S_IRWXO0000007)) {
865 log_warnx("%s: group writable or world read/writable", fname);
866 return (-1);
867 }
868 return (0);
869}
870
871struct file *
872pushfile(const char *name, int secret)
873{
874 struct file *nfile;
875
876 if ((nfile = calloc(1, sizeof(struct file))) == NULL((void*)0)) {
877 log_warn("%s", __func__);
878 return (NULL((void*)0));
879 }
880 if ((nfile->name = strdup(name)) == NULL((void*)0)) {
881 log_warn("%s", __func__);
882 free(nfile);
883 return (NULL((void*)0));
884 }
885 if ((nfile->stream = fopen(nfile->name, "r")) == NULL((void*)0)) {
886 log_warn("%s: %s", __func__, nfile->name);
887 free(nfile->name);
888 free(nfile);
889 return (NULL((void*)0));
890 } else if (secret &&
891 check_file_secrecy(fileno(nfile->stream)(!__isthreaded ? ((nfile->stream)->_file) : (fileno)(nfile
->stream))
, nfile->name)) {
892 fclose(nfile->stream);
893 free(nfile->name);
894 free(nfile);
895 return (NULL((void*)0));
896 }
897 nfile->lineno = TAILQ_EMPTY(&files)(((&files)->tqh_first) == ((void*)0)) ? 1 : 0;
898 nfile->ungetsize = 16;
899 nfile->ungetbuf = malloc(nfile->ungetsize);
900 if (nfile->ungetbuf == NULL((void*)0)) {
901 log_warn("%s", __func__);
902 fclose(nfile->stream);
903 free(nfile->name);
904 free(nfile);
905 return (NULL((void*)0));
906 }
907 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)
;
908 return (nfile);
909}
910
911int
912popfile(void)
913{
914 struct file *prev;
915
916 if ((prev = TAILQ_PREV(file, files, entry)(*(((struct files *)((file)->entry.tqe_prev))->tqh_last
))
) != NULL((void*)0))
917 prev->errors += file->errors;
918
919 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)
;
920 fclose(file->stream);
921 free(file->name);
922 free(file->ungetbuf);
923 free(file);
924 file = prev;
925 return (file ? 0 : EOF(-1));
926}
927
928struct snmpd *
929parse_config(const char *filename, u_int flags)
930{
931 struct sockaddr_storage ss;
932 struct sym *sym, *next;
933 struct address *h;
934 struct trap_address *tr;
935 const struct usmuser *up;
936 const char *errstr;
937 char hostname[HOST_NAME_MAX255 + 1];
938 int found;
939 uint32_t npen = htonl(PEN_OPENBSD)(__uint32_t)(__builtin_constant_p(30155) ? (__uint32_t)(((__uint32_t
)(30155) & 0xff) << 24 | ((__uint32_t)(30155) &
0xff00) << 8 | ((__uint32_t)(30155) & 0xff0000) >>
8 | ((__uint32_t)(30155) & 0xff000000) >> 24) : __swap32md
(30155))
;
940
941 if ((conf = calloc(1, sizeof(*conf))) == NULL((void*)0)) {
942 log_warn("%s", __func__);
943 return (NULL((void*)0));
944 }
945
946 conf->sc_flags = flags;
947 conf->sc_confpath = filename;
948 TAILQ_INIT(&conf->sc_addresses)do { (&conf->sc_addresses)->tqh_first = ((void*)0);
(&conf->sc_addresses)->tqh_last = &(&conf->
sc_addresses)->tqh_first; } while (0)
;
949 TAILQ_INIT(&conf->sc_trapreceivers)do { (&conf->sc_trapreceivers)->tqh_first = ((void*
)0); (&conf->sc_trapreceivers)->tqh_last = &(&
conf->sc_trapreceivers)->tqh_first; } while (0)
;
950 conf->sc_min_seclevel = SNMP_MSGFLAG_AUTH0x01 | SNMP_MSGFLAG_PRIV0x02;
951
952 if ((file = pushfile(filename, 0)) == NULL((void*)0)) {
953 free(conf);
954 return (NULL((void*)0));
955 }
956 topfile = file;
957 setservent(1);
958
959 yyparse();
960 errors = file->errors;
961 popfile();
962
963 endservent();
964
965 /* Must be identical to enginefmt_local:HOSTHASH */
966 if (conf->sc_engineid_len == 0) {
967 if (gethostname(hostname, sizeof(hostname)) == -1)
968 fatal("gethostname");
969 memcpy(conf->sc_engineid, &npen, sizeof(npen));
970 conf->sc_engineid_len += sizeof(npen);
971 conf->sc_engineid[conf->sc_engineid_len++] |=
972 SNMP_ENGINEID_FMT_HH129;
973 memcpy(conf->sc_engineid + conf->sc_engineid_len,
974 SHA256(hostname, strlen(hostname), NULL((void*)0)),
975 sizeof(conf->sc_engineid) - conf->sc_engineid_len);
976 conf->sc_engineid_len = sizeof(conf->sc_engineid);
977 conf->sc_engineid[0] |= SNMP_ENGINEID_NEW0x80;
978 }
979
980 /* Setup default listen addresses */
981 if (TAILQ_EMPTY(&conf->sc_addresses)(((&conf->sc_addresses)->tqh_first) == ((void*)0))) {
982 if (host("0.0.0.0", SNMP_PORT"161", SOCK_DGRAM2, &ss, 1) != 1)
983 fatal("Unexpected resolving of 0.0.0.0");
984 if (listen_add(&ss, SOCK_DGRAM2, 0) == -1)
985 fatal("calloc");
986 if (host("::", SNMP_PORT"161", SOCK_DGRAM2, &ss, 1) != 1)
987 fatal("Unexpected resolving of ::");
988 if (listen_add(&ss, SOCK_DGRAM2, 0) == -1)
989 fatal("calloc");
990 }
991
992 if ((up = usm_check_mincred(conf->sc_min_seclevel, &errstr)) != NULL((void*)0))
993 fatalx("user '%s': %s", up->uu_name, errstr);
994
995 found = 0;
996 TAILQ_FOREACH(h, &conf->sc_addresses, entry)for((h) = ((&conf->sc_addresses)->tqh_first); (h) !=
((void*)0); (h) = ((h)->entry.tqe_next))
{
997 if (h->flags & ADDRESS_FLAG_NOTIFY0x04)
998 found = 1;
999 }
1000 if (conf->sc_traphandler && !found) {
1001 log_warnx("trap handler needs at least one notify listener");
1002 free(conf);
1003 return (NULL((void*)0));
1004 }
1005 if (!conf->sc_traphandler && found) {
1006 log_warnx("notify listener needs at least one trap handler");
1007 free(conf);
1008 return (NULL((void*)0));
1009 }
1010
1011 TAILQ_FOREACH(tr, &conf->sc_trapreceivers, entry)for((tr) = ((&conf->sc_trapreceivers)->tqh_first); (
tr) != ((void*)0); (tr) = ((tr)->entry.tqe_next))
{
1012 if (tr->ta_version == SNMP_V2 &&
1013 tr->ta_community[0] == '\0' &&
1014 conf->sc_trcommunity[0] == '\0') {
1015 log_warnx("trap receiver: missing community");
1016 free(conf);
1017 return (NULL((void*)0));
1018 }
1019 if (tr->ta_version == SNMP_V3) {
1020 tr->ta_usmuser = usm_finduser(tr->ta_usmusername);
1021 if (tr->ta_usmuser == NULL((void*)0)) {
1022 log_warnx("trap receiver: user not defined: %s",
1023 tr->ta_usmusername);
1024 free(conf);
1025 return (NULL((void*)0));
1026 }
1027 }
1028 }
1029
1030 /* Free macros and check which have not been used. */
1031 TAILQ_FOREACH_SAFE(sym, &symhead, entry, next)for ((sym) = ((&symhead)->tqh_first); (sym) != ((void*
)0) && ((next) = ((sym)->entry.tqe_next), 1); (sym
) = (next))
{
1032 if ((conf->sc_flags & SNMPD_F_VERBOSE0x01) && !sym->used)
1033 fprintf(stderr(&__sF[2]), "warning: macro '%s' not "
1034 "used\n", sym->nam);
1035 if (!sym->persist) {
1036 free(sym->nam);
1037 free(sym->val);
1038 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)
;
1039 free(sym);
1040 }
1041 }
1042
1043 if (errors) {
1044 free(conf);
1045 return (NULL((void*)0));
1046 }
1047
1048 return (conf);
1049}
1050
1051int
1052symset(const char *nam, const char *val, int persist)
1053{
1054 struct sym *sym;
1055
1056 TAILQ_FOREACH(sym, &symhead, entry)for((sym) = ((&symhead)->tqh_first); (sym) != ((void*)
0); (sym) = ((sym)->entry.tqe_next))
{
1057 if (strcmp(nam, sym->nam) == 0)
1058 break;
1059 }
1060
1061 if (sym != NULL((void*)0)) {
1062 if (sym->persist == 1)
1063 return (0);
1064 else {
1065 free(sym->nam);
1066 free(sym->val);
1067 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)
;
1068 free(sym);
1069 }
1070 }
1071 if ((sym = calloc(1, sizeof(*sym))) == NULL((void*)0))
1072 return (-1);
1073
1074 sym->nam = strdup(nam);
1075 if (sym->nam == NULL((void*)0)) {
1076 free(sym);
1077 return (-1);
1078 }
1079 sym->val = strdup(val);
1080 if (sym->val == NULL((void*)0)) {
1081 free(sym->nam);
1082 free(sym);
1083 return (-1);
1084 }
1085 sym->used = 0;
1086 sym->persist = persist;
1087 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)
;
1088 return (0);
1089}
1090
1091int
1092cmdline_symset(char *s)
1093{
1094 char *sym, *val;
1095 int ret;
1096
1097 if ((val = strrchr(s, '=')) == NULL((void*)0))
1098 return (-1);
1099 sym = strndup(s, val - s);
1100 if (sym == NULL((void*)0))
1101 errx(1, "%s: strndup", __func__);
1102 ret = symset(sym, val + 1, 1);
1103 free(sym);
1104
1105 return (ret);
1106}
1107
1108char *
1109symget(const char *nam)
1110{
1111 struct sym *sym;
1112
1113 TAILQ_FOREACH(sym, &symhead, entry)for((sym) = ((&symhead)->tqh_first); (sym) != ((void*)
0); (sym) = ((sym)->entry.tqe_next))
{
1114 if (strcmp(nam, sym->nam) == 0) {
1115 sym->used = 1;
1116 return (sym->val);
1117 }
1118 }
1119 return (NULL((void*)0));
1120}
1121
1122int
1123host(const char *s, const char *port, int type, struct sockaddr_storage *ss,
1124 int max)
1125{
1126 struct addrinfo hints, *res0, *res;
1127 int error, i;
1128
1129 bzero(&hints, sizeof(hints));
1130 hints.ai_family = PF_UNSPEC0;
1131 hints.ai_socktype = type;
1132 /*
1133 * Without AI_NUMERICHOST getaddrinfo might not resolve ip addresses
1134 * for families not specified in the "family" statement in resolv.conf.
1135 */
1136 hints.ai_flags = AI_NUMERICHOST4;
1137 error = getaddrinfo(s, port, &hints, &res0);
1138 if (error == EAI_NONAME-2) {
1139 hints.ai_flags = 0;
1140 error = getaddrinfo(s, port, &hints, &res0);
1141 }
1142 if (error == EAI_AGAIN-3 || error == EAI_NODATA-5 || error == EAI_NONAME-2)
1143 return 0;
1144 if (error) {
1145 log_warnx("Could not parse \"%s\": %s", s, gai_strerror(error));
1146 return -1;
1147 }
1148
1149 for (i = 0, res = res0; res; res = res->ai_next, i++) {
1150 if (res->ai_family != AF_INET2 &&
1151 res->ai_family != AF_INET624)
1152 continue;
1153 if (i >= max)
1154 continue;
1155
1156 bcopy(res->ai_addr, &(ss[i]), res->ai_addrlen);
1157 }
1158 freeaddrinfo(res0);
1159
1160 return i;
1161}
1162
1163int
1164listen_add(struct sockaddr_storage *ss, int type, int flags)
1165{
1166 struct sockaddr_in *sin;
1167 struct sockaddr_in6 *sin6;
1168 struct address *h;
1169
1170 if ((h = calloc(1, sizeof(*h))) == NULL((void*)0))
1171 return -1;
1172 bcopy(ss, &(h->ss), sizeof(*ss));
1173 if (ss->ss_family == AF_INET2) {
1174 sin = (struct sockaddr_in *)ss;
1175 h->port = ntohs(sin->sin_port)(__uint16_t)(__builtin_constant_p(sin->sin_port) ? (__uint16_t
)(((__uint16_t)(sin->sin_port) & 0xffU) << 8 | (
(__uint16_t)(sin->sin_port) & 0xff00U) >> 8) : __swap16md
(sin->sin_port))
;
1176 } else {
1177 sin6 = (struct sockaddr_in6*)ss;
1178 h->port = ntohs(sin6->sin6_port)(__uint16_t)(__builtin_constant_p(sin6->sin6_port) ? (__uint16_t
)(((__uint16_t)(sin6->sin6_port) & 0xffU) << 8 |
((__uint16_t)(sin6->sin6_port) & 0xff00U) >> 8)
: __swap16md(sin6->sin6_port))
;
1179 }
1180 h->type = type;
1181 if (((h->flags = flags) & ADDRESS_FLAG_PERM(0x01 | 0x02 | 0x04)) == 0) {
1182 if (h->port == 162)
1183 h->flags |= ADDRESS_FLAG_NOTIFY0x04;
1184 else
1185 h->flags |= ADDRESS_FLAG_READ0x01 | ADDRESS_FLAG_WRITE0x02;
1186 }
1187 if ((h->flags & ADDRESS_FLAG_MPS(0x10 | 0x20 | 0x40)) == 0)
1188 h->flags |= ADDRESS_FLAG_SNMPV30x40;
1189 TAILQ_INSERT_TAIL(&(conf->sc_addresses), h, entry)do { (h)->entry.tqe_next = ((void*)0); (h)->entry.tqe_prev
= (&(conf->sc_addresses))->tqh_last; *(&(conf->
sc_addresses))->tqh_last = (h); (&(conf->sc_addresses
))->tqh_last = &(h)->entry.tqe_next; } while (0)
;
1190
1191 return 0;
1192}
1193#line 1186 "parse.c"
1194/* allocate initial stack or double stack size, up to YYMAXDEPTH */
1195static int yygrowstack(void)
1196{
1197 unsigned int newsize;
1198 long sslen;
1199 short *newss;
1200 YYSTYPE *newvs;
1201
1202 if ((newsize = yystacksize) == 0)
3
Assuming the condition is false
4
Taking false branch
1203 newsize = YYINITSTACKSIZE200;
1204 else if (newsize >= YYMAXDEPTH10000)
5
Assuming 'newsize' is < YYMAXDEPTH
6
Taking false branch
1205 return -1;
1206 else if ((newsize *= 2) > YYMAXDEPTH10000)
7
Assuming the condition is false
8
Taking false branch
1207 newsize = YYMAXDEPTH10000;
1208 sslen = yyssp - yyss;
1209#ifdef SIZE_MAX0xffffffffffffffffUL
1210#define YY_SIZE_MAX0xffffffffffffffffUL SIZE_MAX0xffffffffffffffffUL
1211#else
1212#define YY_SIZE_MAX0xffffffffffffffffUL 0xffffffffU
1213#endif
1214 if (newsize && YY_SIZE_MAX0xffffffffffffffffUL / newsize < sizeof *newss)
9
Assuming 'newsize' is 0
1215 goto bail;
1216 newss = (short *)realloc(yyss, newsize * sizeof *newss);
1217 if (newss == NULL((void*)0))
10
Assuming 'newss' is not equal to NULL
11
Taking false branch
1218 goto bail;
1219 yyss = newss;
1220 yyssp = newss + sslen;
1221 if (newsize
11.1
'newsize' is 0
&& YY_SIZE_MAX0xffffffffffffffffUL / newsize < sizeof *newvs)
1222 goto bail;
1223 newvs = (YYSTYPE *)realloc(yyvs, newsize * sizeof *newvs);
1224 if (newvs == NULL((void*)0))
12
Assuming 'newvs' is not equal to NULL
13
Taking false branch
1225 goto bail;
1226 yyvs = newvs;
1227 yyvsp = newvs + sslen;
1228 yystacksize = newsize;
1229 yysslim = yyss + newsize - 1;
1230 return 0;
1231bail:
1232 if (yyss)
1233 free(yyss);
1234 if (yyvs)
1235 free(yyvs);
1236 yyss = yyssp = NULL((void*)0);
1237 yyvs = yyvsp = NULL((void*)0);
1238 yystacksize = 0;
1239 return -1;
1240}
1241
1242#define YYABORTgoto yyabort goto yyabort
1243#define YYREJECTgoto yyabort goto yyabort
1244#define YYACCEPTgoto yyaccept goto yyaccept
1245#define YYERRORgoto yyerrlab goto yyerrlab
1246int
1247yyparse(void)
1248{
1249 int yym, yyn, yystate;
1250#if YYDEBUG0
1251 const char *yys;
1252
1253 if ((yys = getenv("YYDEBUG")))
1254 {
1255 yyn = *yys;
1256 if (yyn >= '0' && yyn <= '9')
1257 yydebug = yyn - '0';
1258 }
1259#endif /* YYDEBUG */
1260
1261 yynerrs = 0;
1262 yyerrflag = 0;
1263 yychar = (-1);
1264
1265 if (yyss == NULL((void*)0) && yygrowstack()) goto yyoverflow;
1
Assuming 'yyss' is equal to NULL
2
Calling 'yygrowstack'
14
Returning from 'yygrowstack'
15
Taking false branch
1266 yyssp = yyss;
1267 yyvsp = yyvs;
1268 *yyssp = yystate = 0;
16
Use of zero-allocated memory
1269
1270yyloop:
1271 if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
1272 if (yychar < 0)
1273 {
1274 if ((yychar = yylex()) < 0) yychar = 0;
1275#if YYDEBUG0
1276 if (yydebug)
1277 {
1278 yys = 0;
1279 if (yychar <= YYMAXTOKEN307) yys = yyname[yychar];
1280 if (!yys) yys = "illegal-symbol";
1281 printf("%sdebug: state %d, reading %d (%s)\n",
1282 YYPREFIX"yy", yystate, yychar, yys);
1283 }
1284#endif
1285 }
1286 if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
1287 yyn <= YYTABLESIZE310 && yycheck[yyn] == yychar)
1288 {
1289#if YYDEBUG0
1290 if (yydebug)
1291 printf("%sdebug: state %d, shifting to state %d\n",
1292 YYPREFIX"yy", yystate, yytable[yyn]);
1293#endif
1294 if (yyssp >= yysslim && yygrowstack())
1295 {
1296 goto yyoverflow;
1297 }
1298 *++yyssp = yystate = yytable[yyn];
1299 *++yyvsp = yylval;
1300 yychar = (-1);
1301 if (yyerrflag > 0) --yyerrflag;
1302 goto yyloop;
1303 }
1304 if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
1305 yyn <= YYTABLESIZE310 && yycheck[yyn] == yychar)
1306 {
1307 yyn = yytable[yyn];
1308 goto yyreduce;
1309 }
1310 if (yyerrflag) goto yyinrecovery;
1311#if defined(__GNUC__4)
1312 goto yynewerror;
1313#endif
1314yynewerror:
1315 yyerror("syntax error");
1316#if defined(__GNUC__4)
1317 goto yyerrlab;
1318#endif
1319yyerrlab:
1320 ++yynerrs;
1321yyinrecovery:
1322 if (yyerrflag < 3)
1323 {
1324 yyerrflag = 3;
1325 for (;;)
1326 {
1327 if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE256) >= 0 &&
1328 yyn <= YYTABLESIZE310 && yycheck[yyn] == YYERRCODE256)
1329 {
1330#if YYDEBUG0
1331 if (yydebug)
1332 printf("%sdebug: state %d, error recovery shifting\
1333 to state %d\n", YYPREFIX"yy", *yyssp, yytable[yyn]);
1334#endif
1335 if (yyssp >= yysslim && yygrowstack())
1336 {
1337 goto yyoverflow;
1338 }
1339 *++yyssp = yystate = yytable[yyn];
1340 *++yyvsp = yylval;
1341 goto yyloop;
1342 }
1343 else
1344 {
1345#if YYDEBUG0
1346 if (yydebug)
1347 printf("%sdebug: error recovery discarding state %d\n",
1348 YYPREFIX"yy", *yyssp);
1349#endif
1350 if (yyssp <= yyss) goto yyabort;
1351 --yyssp;
1352 --yyvsp;
1353 }
1354 }
1355 }
1356 else
1357 {
1358 if (yychar == 0) goto yyabort;
1359#if YYDEBUG0
1360 if (yydebug)
1361 {
1362 yys = 0;
1363 if (yychar <= YYMAXTOKEN307) yys = yyname[yychar];
1364 if (!yys) yys = "illegal-symbol";
1365 printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
1366 YYPREFIX"yy", yystate, yychar, yys);
1367 }
1368#endif
1369 yychar = (-1);
1370 goto yyloop;
1371 }
1372yyreduce:
1373#if YYDEBUG0
1374 if (yydebug)
1375 printf("%sdebug: state %d, reducing by rule %d (%s)\n",
1376 YYPREFIX"yy", yystate, yyn, yyrule[yyn]);
1377#endif
1378 yym = yylen[yyn];
1379 if (yym)
1380 yyval = yyvsp[1-yym];
1381 else
1382 memset(&yyval, 0, sizeof yyval);
1383 switch (yyn)
1384 {
1385case 8:
1386#line 154 "/usr/src/usr.sbin/snmpd/parse.y"
1387{ file->errors++; }
1388break;
1389case 9:
1390#line 157 "/usr/src/usr.sbin/snmpd/parse.y"
1391{
1392 struct file *nfile;
1393
1394 if ((nfile = pushfile(yyvsp[0].v.string, 0)) == NULL((void*)0)) {
1395 yyerror("failed to include file %s", yyvsp[0].v.string);
1396 free(yyvsp[0].v.string);
1397 YYERRORgoto yyerrlab;
1398 }
1399 free(yyvsp[0].v.string);
1400
1401 file = nfile;
1402 lungetc('\n');
1403 }
1404break;
1405case 10:
1406#line 172 "/usr/src/usr.sbin/snmpd/parse.y"
1407{
1408 char *s = yyvsp[-2].v.string;
1409 while (*s++) {
1410 if (isspace((unsigned char)*s)) {
1411 yyerror("macro name cannot contain "
1412 "whitespace");
1413 free(yyvsp[-2].v.string);
1414 free(yyvsp[0].v.string);
1415 YYERRORgoto yyerrlab;
1416 }
1417 }
1418 if (symset(yyvsp[-2].v.string, yyvsp[0].v.string, 0) == -1)
1419 fatal("cannot store variable");
1420 free(yyvsp[-2].v.string);
1421 free(yyvsp[0].v.string);
1422 }
1423break;
1424case 11:
1425#line 190 "/usr/src/usr.sbin/snmpd/parse.y"
1426{
1427 if (!strcmp(yyvsp[0].v.string, "yes"))
1428 yyval.v.number = 1;
1429 else if (!strcmp(yyvsp[0].v.string, "no"))
1430 yyval.v.number = 0;
1431 else {
1432 yyerror("syntax error, "
1433 "either yes or no expected");
1434 free(yyvsp[0].v.string);
1435 YYERRORgoto yyerrlab;
1436 }
1437 free(yyvsp[0].v.string);
1438 }
1439break;
1440case 13:
1441#line 206 "/usr/src/usr.sbin/snmpd/parse.y"
1442{
1443 if (conf->sc_engineid_len != 0) {
1444 yyerror("Redefinition of engineid");
1445 YYERRORgoto yyerrlab;
1446 }
1447 memcpy(conf->sc_engineid, engineid, engineidlen);
1448 conf->sc_engineid_len = engineidlen;
1449 }
1450break;
1451case 14:
1452#line 214 "/usr/src/usr.sbin/snmpd/parse.y"
1453{
1454 if (strlcpy(conf->sc_rdcommunity, yyvsp[0].v.string,
1455 sizeof(conf->sc_rdcommunity)) >=
1456 sizeof(conf->sc_rdcommunity)) {
1457 yyerror("r/o community name too long");
1458 free(yyvsp[0].v.string);
1459 YYERRORgoto yyerrlab;
1460 }
1461 free(yyvsp[0].v.string);
1462 }
1463break;
1464case 15:
1465#line 224 "/usr/src/usr.sbin/snmpd/parse.y"
1466{
1467 if (strlcpy(conf->sc_rwcommunity, yyvsp[0].v.string,
1468 sizeof(conf->sc_rwcommunity)) >=
1469 sizeof(conf->sc_rwcommunity)) {
1470 yyerror("r/w community name too long");
1471 free(yyvsp[0].v.string);
1472 YYERRORgoto yyerrlab;
1473 }
1474 free(yyvsp[0].v.string);
1475 }
1476break;
1477case 16:
1478#line 234 "/usr/src/usr.sbin/snmpd/parse.y"
1479{
1480 if (strlcpy(conf->sc_trcommunity, yyvsp[0].v.string,
1481 sizeof(conf->sc_trcommunity)) >=
1482 sizeof(conf->sc_trcommunity)) {
1483 yyerror("trap community name too long");
1484 free(yyvsp[0].v.string);
1485 YYERRORgoto yyerrlab;
1486 }
1487 free(yyvsp[0].v.string);
1488 }
1489break;
1490case 18:
1491#line 245 "/usr/src/usr.sbin/snmpd/parse.y"
1492{
1493 struct trapcmd *cmd = yyvsp[0].v.data.data;
1494
1495 cmd->cmd_oid = yyvsp[-1].v.oid;
1496
1497 if (trapcmd_add(cmd) != 0) {
1498 free(yyvsp[-1].v.oid);
1499 free(cmd);
1500 yyerror("duplicate oid");
1501 YYERRORgoto yyerrlab;
1502 }
1503 conf->sc_traphandler = 1;
1504 }
1505break;
1506case 19:
1507#line 258 "/usr/src/usr.sbin/snmpd/parse.y"
1508{
1509 if (yyvsp[0].v.number == 1)
1510 conf->sc_rtfilter = ROUTE_FILTER(RTM_NEWADDR)(1 << (0xc)) |
1511 ROUTE_FILTER(RTM_DELADDR)(1 << (0xd)) |
1512 ROUTE_FILTER(RTM_IFINFO)(1 << (0xe)) |
1513 ROUTE_FILTER(RTM_IFANNOUNCE)(1 << (0xf));
1514 else
1515 conf->sc_rtfilter = 0;
1516 }
1517break;
1518case 20:
1519#line 267 "/usr/src/usr.sbin/snmpd/parse.y"
1520{
1521 conf->sc_pfaddrfilter = yyvsp[0].v.number;
1522 }
1523break;
1524case 21:
1525#line 270 "/usr/src/usr.sbin/snmpd/parse.y"
1526{
1527 conf->sc_min_seclevel = yyvsp[0].v.number;
1528 }
1529break;
1530case 22:
1531#line 273 "/usr/src/usr.sbin/snmpd/parse.y"
1532{
1533 const char *errstr;
1534 user = usm_newuser(yyvsp[0].v.string, &errstr);
1535 if (user == NULL((void*)0)) {
1536 yyerror("%s", errstr);
1537 free(yyvsp[0].v.string);
1538 YYERRORgoto yyerrlab;
1539 }
1540 }
1541break;
1542case 23:
1543#line 281 "/usr/src/usr.sbin/snmpd/parse.y"
1544{
1545 const char *errstr;
1546 if (usm_checkuser(user, &errstr) < 0) {
1547 yyerror("%s", errstr);
1548 YYERRORgoto yyerrlab;
1549 }
1550 user = NULL((void*)0);
1551 }
1552break;
1553case 24:
1554#line 291 "/usr/src/usr.sbin/snmpd/parse.y"
1555{ yyval.v.number = SOCK_DGRAM2; }
1556break;
1557case 25:
1558#line 292 "/usr/src/usr.sbin/snmpd/parse.y"
1559{ yyval.v.number = SOCK_DGRAM2; }
1560break;
1561case 26:
1562#line 293 "/usr/src/usr.sbin/snmpd/parse.y"
1563{ yyval.v.number = SOCK_STREAM1; }
1564break;
1565case 27:
1566#line 296 "/usr/src/usr.sbin/snmpd/parse.y"
1567{ yyval.v.number = 0; }
1568break;
1569case 28:
1570#line 297 "/usr/src/usr.sbin/snmpd/parse.y"
1571{ yyval.v.number |= yyvsp[0].v.number; }
1572break;
1573case 29:
1574#line 300 "/usr/src/usr.sbin/snmpd/parse.y"
1575{ yyval.v.number = ADDRESS_FLAG_READ0x01; }
1576break;
1577case 30:
1578#line 301 "/usr/src/usr.sbin/snmpd/parse.y"
1579{ yyval.v.number = ADDRESS_FLAG_WRITE0x02; }
1580break;
1581case 31:
1582#line 302 "/usr/src/usr.sbin/snmpd/parse.y"
1583{ yyval.v.number = ADDRESS_FLAG_NOTIFY0x04; }
1584break;
1585case 32:
1586#line 303 "/usr/src/usr.sbin/snmpd/parse.y"
1587{ yyval.v.number = ADDRESS_FLAG_SNMPV10x10; }
1588break;
1589case 33:
1590#line 304 "/usr/src/usr.sbin/snmpd/parse.y"
1591{ yyval.v.number = ADDRESS_FLAG_SNMPV20x20; }
1592break;
1593case 34:
1594#line 305 "/usr/src/usr.sbin/snmpd/parse.y"
1595{ yyval.v.number = ADDRESS_FLAG_SNMPV30x40; }
1596break;
1597case 35:
1598#line 308 "/usr/src/usr.sbin/snmpd/parse.y"
1599{
1600 struct sockaddr_storage ss[16];
1601 int nhosts, j;
1602 char *address[2], *port = yyvsp[-1].v.string;
1603 size_t addresslen = 1, i;
1604
1605 if (port == NULL((void*)0)) {
1606 if ((yyvsp[0].v.number & ADDRESS_FLAG_PERM(0x01 | 0x02 | 0x04)) ==
1607 ADDRESS_FLAG_NOTIFY0x04)
1608 port = SNMPTRAP_PORT"162";
1609 else
1610 port = SNMP_PORT"161";
1611 }
1612
1613 if (strcmp(yyvsp[-2].v.string, "any") == 0) {
1614 addresslen = 2;
1615 address[0] = "0.0.0.0";
1616 address[1] = "::";
1617 } else {
1618 addresslen = 1;
1619 address[0] = yyvsp[-2].v.string;
1620 }
1621
1622 for (i = 0; i < addresslen; i++) {
1623 nhosts = host(address[i], port, yyvsp[-3].v.number, ss, nitems(ss)(sizeof((ss)) / sizeof((ss)[0])));
1624 if (nhosts < 1) {
1625 yyerror("invalid address: %s", yyvsp[-2].v.string);
1626 free(yyvsp[-2].v.string);
1627 free(yyvsp[-1].v.string);
1628 YYERRORgoto yyerrlab;
1629 }
1630 if (nhosts > (int)nitems(ss)(sizeof((ss)) / sizeof((ss)[0])))
1631 log_warn("%s:%s resolves to more than "
1632 "%zu hosts", yyvsp[-2].v.string, port, nitems(ss)(sizeof((ss)) / sizeof((ss)[0])));
1633
1634 for (j = 0; j < nhosts; j++) {
1635 if (listen_add(&(ss[j]), yyvsp[-3].v.number, yyvsp[0].v.number) == -1) {
1636 yyerror("calloc");
1637 YYERRORgoto yyerrlab;
1638 }
1639 }
1640 }
1641 free(yyvsp[-2].v.string);
1642 free(yyvsp[-1].v.string);
1643 }
1644break;
1645case 36:
1646#line 355 "/usr/src/usr.sbin/snmpd/parse.y"
1647{
1648 yyval.v.string = NULL((void*)0);
1649 }
1650break;
1651case 37:
1652#line 358 "/usr/src/usr.sbin/snmpd/parse.y"
1653{
1654 yyval.v.string = yyvsp[0].v.string;
1655 }
1656break;
1657case 38:
1658#line 361 "/usr/src/usr.sbin/snmpd/parse.y"
1659{
1660 char *number;
1661
1662 if (yyvsp[0].v.number > UINT16_MAX0xffff) {
1663 yyerror("port number too large");
1664 YYERRORgoto yyerrlab;
1665 }
1666 if (yyvsp[0].v.number < 1) {
1667 yyerror("port number too small");
1668 YYERRORgoto yyerrlab;
1669 }
1670 if (asprintf(&number, "%"PRId64"lld", yyvsp[0].v.number) == -1) {
1671 yyerror("malloc");
1672 YYERRORgoto yyerrlab;
1673 }
1674 yyval.v.string = number;
1675 }
1676break;
1677case 39:
1678#line 380 "/usr/src/usr.sbin/snmpd/parse.y"
1679{
1680 struct in_addr addr;
1681
1682 engineid[engineidlen++] = SNMP_ENGINEID_FMT_IPv41;
1683 if (inet_pton(AF_INET2, yyvsp[0].v.string, &addr) != 1) {
1684 yyerror("Invalid ipv4 address: %s", yyvsp[0].v.string);
1685 free(yyvsp[0].v.string);
1686 YYERRORgoto yyerrlab;
1687 }
1688 memcpy(engineid + engineidlen, &addr,
1689 sizeof(engineid) - engineidlen);
1690 engineid[0] |= SNMP_ENGINEID_NEW0x80;
1691 engineidlen += sizeof(addr);
1692 free(yyvsp[0].v.string);
1693 }
1694break;
1695case 40:
1696#line 395 "/usr/src/usr.sbin/snmpd/parse.y"
1697{
1698 struct in6_addr addr;
1699
1700 engineid[engineidlen++] = SNMP_ENGINEID_FMT_IPv62;
1701 if (inet_pton(AF_INET624, yyvsp[0].v.string, &addr) != 1) {
1702 yyerror("Invalid ipv6 address: %s", yyvsp[0].v.string);
1703 free(yyvsp[0].v.string);
1704 YYERRORgoto yyerrlab;
1705 }
1706 memcpy(engineid + engineidlen, &addr,
1707 sizeof(engineid) - engineidlen);
1708 engineid[0] |= SNMP_ENGINEID_NEW0x80;
1709 engineidlen += sizeof(addr);
1710 free(yyvsp[0].v.string);
1711 }
1712break;
1713case 41:
1714#line 410 "/usr/src/usr.sbin/snmpd/parse.y"
1715{
1716 size_t i;
1717
1718 if (strlen(yyvsp[0].v.string) != 5 * 3 + 2) {
1719 yyerror("Invalid mac address: %s", yyvsp[0].v.string);
1720 free(yyvsp[0].v.string);
1721 YYERRORgoto yyerrlab;
1722 }
1723 engineid[engineidlen++] = SNMP_ENGINEID_FMT_MAC3;
1724 for (i = 0; i < 6; i++) {
1725 if (fromhexstr(engineid + engineidlen + i,
1726 yyvsp[0].v.string + (i * 3), 2) == NULL((void*)0) ||
1727 yyvsp[0].v.string[i * 3 + 2] != (i < 5 ? ':' : '\0')) {
1728 yyerror("Invalid mac address: %s", yyvsp[0].v.string);
1729 free(yyvsp[0].v.string);
1730 YYERRORgoto yyerrlab;
1731 }
1732 }
1733 engineid[0] |= SNMP_ENGINEID_NEW0x80;
1734 engineidlen += 6;
1735 free(yyvsp[0].v.string);
1736 }
1737break;
1738case 42:
1739#line 432 "/usr/src/usr.sbin/snmpd/parse.y"
1740{
1741 size_t i, fmtstart;
1742
1743 engineid[engineidlen++] = SNMP_ENGINEID_FMT_TEXT4;
1744 for (i = 0, fmtstart = engineidlen;
1745 i < sizeof(engineid) - engineidlen && yyvsp[0].v.string[i] != '\0';
1746 i++) {
1747 if (!isprint(yyvsp[0].v.string[i])) {
1748 yyerror("invalid text character");
1749 free(yyvsp[0].v.string);
1750 YYERRORgoto yyerrlab;
1751 }
1752 engineid[fmtstart + i] = yyvsp[0].v.string[i];
1753 engineidlen++;
1754 }
1755 if (i == 0 || yyvsp[0].v.string[i] != '\0') {
1756 yyerror("Invalid text length: %s", yyvsp[0].v.string);
1757 free(yyvsp[0].v.string);
1758 YYERRORgoto yyerrlab;
1759 }
1760 engineid[0] |= SNMP_ENGINEID_NEW0x80;
1761 free(yyvsp[0].v.string);
1762 }
1763break;
1764case 43:
1765#line 455 "/usr/src/usr.sbin/snmpd/parse.y"
1766{
1767 if (strlen(yyvsp[0].v.string) / 2 > sizeof(engineid) - 1) {
1768 yyerror("Invalid octets length: %s", yyvsp[0].v.string);
1769 free(yyvsp[0].v.string);
1770 YYERRORgoto yyerrlab;
1771 }
1772
1773 engineid[engineidlen++] = SNMP_ENGINEID_FMT_OCT5;
1774 if (fromhexstr(engineid + engineidlen, yyvsp[0].v.string,
1775 strlen(yyvsp[0].v.string)) == NULL((void*)0)) {
1776 yyerror("Invalid octets: %s", yyvsp[0].v.string);
1777 free(yyvsp[0].v.string);
1778 YYERRORgoto yyerrlab;
1779 }
1780 engineidlen += strlen(yyvsp[0].v.string) / 2;
1781 engineid[0] |= SNMP_ENGINEID_NEW0x80;
1782 free(yyvsp[0].v.string);
1783 }
1784break;
1785case 44:
1786#line 473 "/usr/src/usr.sbin/snmpd/parse.y"
1787{
1788 if (strlen(yyvsp[0].v.string) / 2 != 8) {
1789 yyerror("Invalid agentid length: %s", yyvsp[0].v.string);
1790 free(yyvsp[0].v.string);
1791 YYERRORgoto yyerrlab;
1792 }
1793
1794 if (fromhexstr(engineid + engineidlen, yyvsp[0].v.string,
1795 strlen(yyvsp[0].v.string)) == NULL((void*)0)) {
1796 yyerror("Invalid agentid: %s", yyvsp[0].v.string);
1797 free(yyvsp[0].v.string);
1798 YYERRORgoto yyerrlab;
1799 }
1800 engineidlen += 8;
1801 engineid[0] |= SNMP_ENGINEID_OLD0x00;
1802 free(yyvsp[0].v.string);
1803 }
1804break;
1805case 45:
1806#line 490 "/usr/src/usr.sbin/snmpd/parse.y"
1807{
1808 if (enginepen != PEN_OPENBSD30155) {
1809 yyerror("hosthash only allowed for pen "
1810 "openbsd");
1811 YYERRORgoto yyerrlab;
1812 }
1813 engineid[engineidlen++] = SNMP_ENGINEID_FMT_HH129;
1814 memcpy(engineid + engineidlen,
1815 SHA256(yyvsp[0].v.string, strlen(yyvsp[0].v.string), NULL((void*)0)),
1816 sizeof(engineid) - engineidlen);
1817 engineidlen = sizeof(engineid);
1818 engineid[0] |= SNMP_ENGINEID_NEW0x80;
1819 free(yyvsp[0].v.string);
1820 }
1821break;
1822case 46:
1823#line 504 "/usr/src/usr.sbin/snmpd/parse.y"
1824{
1825 if (enginepen == PEN_OPENBSD30155) {
1826 yyerror("%lld is only allowed when pen is not "
1827 "openbsd", yyvsp[-1].v.number);
1828 YYERRORgoto yyerrlab;
1829 }
1830
1831 if (yyvsp[-1].v.number < 128 || yyvsp[-1].v.number > 255) {
1832 yyerror("Invalid format number: %lld\n", yyvsp[-1].v.number);
1833 YYERRORgoto yyerrlab;
1834 }
1835 if (strlen(yyvsp[0].v.string) / 2 > sizeof(engineid) - 1) {
1836 yyerror("Invalid octets length: %s", yyvsp[0].v.string);
1837 free(yyvsp[0].v.string);
1838 YYERRORgoto yyerrlab;
1839 }
1840
1841 engineid[engineidlen++] = (uint8_t)yyvsp[-1].v.number;
1842 if (fromhexstr(engineid + engineidlen, yyvsp[0].v.string,
1843 strlen(yyvsp[0].v.string)) == NULL((void*)0)) {
1844 yyerror("Invalid octets: %s", yyvsp[0].v.string);
1845 free(yyvsp[0].v.string);
1846 YYERRORgoto yyerrlab;
1847 }
1848 engineidlen += strlen(yyvsp[0].v.string) / 2;
1849 engineid[0] |= SNMP_ENGINEID_NEW0x80;
1850 free(yyvsp[0].v.string);
1851 }
1852break;
1853case 48:
1854#line 535 "/usr/src/usr.sbin/snmpd/parse.y"
1855{
1856 char hostname[HOST_NAME_MAX255 + 1];
1857
1858 if (enginepen != PEN_OPENBSD30155) {
1859 yyerror("hosthash only allowed for pen "
1860 "openbsd");
1861 YYERRORgoto yyerrlab;
1862 }
1863
1864 if (gethostname(hostname, sizeof(hostname)) == -1) {
1865 yyerror("gethostname: %s", strerror(errno(*__errno())));
1866 YYERRORgoto yyerrlab;
1867 }
1868
1869 engineid[engineidlen++] = SNMP_ENGINEID_FMT_HH129;
1870 memcpy(engineid + engineidlen,
1871 SHA256(hostname, strlen(hostname), NULL((void*)0)),
1872 sizeof(engineid) - engineidlen);
1873 engineidlen = sizeof(engineid);
1874 engineid[0] |= SNMP_ENGINEID_NEW0x80;
1875 }
1876break;
1877case 49:
1878#line 558 "/usr/src/usr.sbin/snmpd/parse.y"
1879{
1880 enginepen = PEN_OPENBSD30155;
1881 }
1882break;
1883case 50:
1884#line 561 "/usr/src/usr.sbin/snmpd/parse.y"
1885{
1886 if (yyvsp[0].v.number > INT32_MAX0x7fffffff) {
1887 yyerror("pen number too large");
1888 YYERRORgoto yyerrlab;
1889 }
1890 if (yyvsp[0].v.number <= 0) {
1891 yyerror("pen number too small");
1892 YYERRORgoto yyerrlab;
1893 }
1894 enginepen = yyvsp[0].v.number;
1895 }
1896break;
1897case 51:
1898#line 572 "/usr/src/usr.sbin/snmpd/parse.y"
1899{
1900 enginepen = PEN_OPENBSD30155;
1901 }
1902break;
1903case 52:
1904#line 577 "/usr/src/usr.sbin/snmpd/parse.y"
1905{
1906 uint32_t npen = htonl(enginepen)(__uint32_t)(__builtin_constant_p(enginepen) ? (__uint32_t)((
(__uint32_t)(enginepen) & 0xff) << 24 | ((__uint32_t
)(enginepen) & 0xff00) << 8 | ((__uint32_t)(enginepen
) & 0xff0000) >> 8 | ((__uint32_t)(enginepen) &
0xff000000) >> 24) : __swap32md(enginepen))
;
1907
1908 memcpy(engineid, &npen, sizeof(enginepen));
1909 engineidlen = sizeof(enginepen);
1910 }
1911break;
1912case 55:
1913#line 587 "/usr/src/usr.sbin/snmpd/parse.y"
1914{
1915 struct ber_oid o = OID(MIB_sysContact){ { 1, 3, 6, 1, 2, 1, 1, 4 } };
1916 mps_set(&o, yyvsp[0].v.string, strlen(yyvsp[0].v.string));
1917 }
1918break;
1919case 56:
1920#line 591 "/usr/src/usr.sbin/snmpd/parse.y"
1921{
1922 struct ber_oid o = OID(MIB_sysDescr){ { 1, 3, 6, 1, 2, 1, 1, 1 } };
1923 mps_set(&o, yyvsp[0].v.string, strlen(yyvsp[0].v.string));
1924 }
1925break;
1926case 57:
1927#line 595 "/usr/src/usr.sbin/snmpd/parse.y"
1928{
1929 struct ber_oid o = OID(MIB_sysLocation){ { 1, 3, 6, 1, 2, 1, 1, 6 } };
1930 mps_set(&o, yyvsp[0].v.string, strlen(yyvsp[0].v.string));
1931 }
1932break;
1933case 58:
1934#line 599 "/usr/src/usr.sbin/snmpd/parse.y"
1935{
1936 struct ber_oid o = OID(MIB_sysName){ { 1, 3, 6, 1, 2, 1, 1, 5 } };
1937 mps_set(&o, yyvsp[0].v.string, strlen(yyvsp[0].v.string));
1938 }
1939break;
1940case 59:
1941#line 603 "/usr/src/usr.sbin/snmpd/parse.y"
1942{
1943 struct ber_oid o = OID(MIB_sysOID){ { 1, 3, 6, 1, 2, 1, 1, 2 } };
1944 mps_set(&o, yyvsp[0].v.oid, sizeof(struct ber_oid));
1945 }
1946break;
1947case 60:
1948#line 607 "/usr/src/usr.sbin/snmpd/parse.y"
1949{
1950 struct ber_oid o = OID(MIB_sysServices){ { 1, 3, 6, 1, 2, 1, 1, 7 } };
1951 mps_set(&o, NULL((void*)0), yyvsp[0].v.number);
1952 }
1953break;
1954case 61:
1955#line 613 "/usr/src/usr.sbin/snmpd/parse.y"
1956{
1957 struct oid *oid;
1958 if ((oid = (struct oid *)
1959 calloc(1, sizeof(*oid))) == NULL((void*)0)) {
1960 yyerror("calloc");
1961 free(yyvsp[-4].v.oid);
1962 free(yyvsp[0].v.data.data);
1963 YYERRORgoto yyerrlab;
1964 }
1965
1966 smi_oidlen(yyvsp[-4].v.oid);
1967 bcopy(yyvsp[-4].v.oid, &oid->o_id, sizeof(struct ber_oid));
1968 free(yyvsp[-4].v.oid);
1969 oid->o_name = yyvsp[-2].v.string;
1970 oid->o_data = yyvsp[0].v.data.data;
1971 oid->o_val = yyvsp[0].v.data.value;
1972 switch (yyvsp[0].v.data.type) {
1973 case 1:
1974 oid->o_get = mps_getint;
1975 oid->o_set = mps_setint;
1976 break;
1977 case 2:
1978 oid->o_get = mps_getstr;
1979 oid->o_set = mps_setstr;
1980 break;
1981 }
1982 oid->o_flags = OID_RD0x01|OID_DYNAMIC0x08;
1983 if (yyvsp[-1].v.number)
1984 oid->o_flags |= OID_WR0x02;
1985
1986 if (smi_insert(oid) == -1) {
1987 yyerror("duplicate oid");
1988 free(oid->o_name);
1989 free(oid->o_data);
1990 YYERRORgoto yyerrlab;
1991 }
1992 }
1993break;
1994case 62:
1995#line 652 "/usr/src/usr.sbin/snmpd/parse.y"
1996{
1997 yyval.v.data.type = 1;
1998 yyval.v.data.data = NULL((void*)0);
1999 yyval.v.data.value = yyvsp[0].v.number;
2000 }
2001break;
2002case 63:
2003#line 657 "/usr/src/usr.sbin/snmpd/parse.y"
2004{
2005 yyval.v.data.type = 2;
2006 yyval.v.data.data = yyvsp[0].v.string;
2007 yyval.v.data.value = strlen(yyvsp[0].v.string);
2008 }
2009break;
2010case 64:
2011#line 664 "/usr/src/usr.sbin/snmpd/parse.y"
2012{ yyval.v.number = 0; }
2013break;
2014case 65:
2015#line 665 "/usr/src/usr.sbin/snmpd/parse.y"
2016{ yyval.v.number = 1; }
2017break;
2018case 66:
2019#line 668 "/usr/src/usr.sbin/snmpd/parse.y"
2020{
2021 struct ber_oid *sysoid;
2022 if ((sysoid =
2023 calloc(1, sizeof(*sysoid))) == NULL((void*)0)) {
2024 yyerror("calloc");
2025 free(yyvsp[0].v.string);
2026 YYERRORgoto yyerrlab;
2027 }
2028 if (ober_string2oid(yyvsp[0].v.string, sysoid) == -1) {
2029 yyerror("invalid OID: %s", yyvsp[0].v.string);
2030 free(sysoid);
2031 free(yyvsp[0].v.string);
2032 YYERRORgoto yyerrlab;
2033 }
2034 free(yyvsp[0].v.string);
2035 yyval.v.oid = sysoid;
2036 }
2037break;
2038case 67:
2039#line 687 "/usr/src/usr.sbin/snmpd/parse.y"
2040{ yyval.v.oid = yyvsp[0].v.oid; }
2041break;
2042case 68:
2043#line 688 "/usr/src/usr.sbin/snmpd/parse.y"
2044{
2045 struct ber_oid *sysoid;
2046 if ((sysoid =
2047 calloc(1, sizeof(*sysoid))) == NULL((void*)0)) {
2048 yyerror("calloc");
2049 YYERRORgoto yyerrlab;
2050 }
2051 ober_string2oid("1.3", sysoid);
2052 yyval.v.oid = sysoid;
2053 }
2054break;
2055case 69:
2056#line 700 "/usr/src/usr.sbin/snmpd/parse.y"
2057{ yyval.v.oid = NULL((void*)0); }
2058break;
2059case 70:
2060#line 701 "/usr/src/usr.sbin/snmpd/parse.y"
2061{ yyval.v.oid = yyvsp[0].v.oid; }
2062break;
2063case 71:
2064#line 704 "/usr/src/usr.sbin/snmpd/parse.y"
2065{
2066 if (strlen(yyvsp[0].v.string) > SNMPD_MAXUSERNAMELEN32) {
2067 yyerror("User name too long: %s", yyvsp[0].v.string);
2068 free(yyvsp[0].v.string);
2069 YYERRORgoto yyerrlab;
2070 }
2071 yyval.v.string = yyvsp[0].v.string;
2072 }
2073break;
2074case 72:
2075#line 714 "/usr/src/usr.sbin/snmpd/parse.y"
2076{
2077 if (strlen(yyvsp[0].v.string) > SNMPD_MAXCOMMUNITYLEN484) {
2078 yyerror("Community too long: %s", yyvsp[0].v.string);
2079 free(yyvsp[0].v.string);
2080 YYERRORgoto yyerrlab;
2081 }
2082 yyval.v.string = yyvsp[0].v.string;
2083 }
2084break;
2085case 73:
2086#line 724 "/usr/src/usr.sbin/snmpd/parse.y"
2087{ yyval.v.string = NULL((void*)0); }
2088break;
2089case 74:
2090#line 725 "/usr/src/usr.sbin/snmpd/parse.y"
2091{ yyval.v.string = yyvsp[0].v.string; }
2092break;
2093case 75:
2094#line 728 "/usr/src/usr.sbin/snmpd/parse.y"
2095{
2096 yyval.v.data.data = yyvsp[0].v.string;
2097 yyval.v.data.value = -1;
2098 }
2099break;
2100case 76:
2101#line 732 "/usr/src/usr.sbin/snmpd/parse.y"
2102{
2103 yyval.v.data.data = 0;
2104 yyval.v.data.value = yyvsp[0].v.number;
2105 }
2106break;
2107case 77:
2108#line 738 "/usr/src/usr.sbin/snmpd/parse.y"
2109{
2110 yyval.v.data.data = NULL((void*)0);
2111 yyval.v.data.value = -1;
2112 }
2113break;
2114case 78:
2115#line 742 "/usr/src/usr.sbin/snmpd/parse.y"
2116{
2117 if (yyvsp[0].v.data.data != NULL((void*)0)) {
2118 if (yyval.v.data.data != NULL((void*)0)) {
2119 yyerror("user redefined");
2120 free(yyvsp[0].v.data.data);
2121 YYERRORgoto yyerrlab;
2122 }
2123 yyval.v.data.data = yyvsp[0].v.data.data;
2124 } else {
2125 if (yyval.v.data.value != -1) {
2126 yyerror("seclevel redefined");
2127 YYERRORgoto yyerrlab;
2128 }
2129 yyval.v.data.value = yyvsp[0].v.data.value;
2130 }
2131 }
2132break;
2133case 79:
2134#line 760 "/usr/src/usr.sbin/snmpd/parse.y"
2135{
2136 if (yyvsp[0].v.data.data == NULL((void*)0)) {
2137 yyerror("user missing");
2138 YYERRORgoto yyerrlab;
2139 }
2140 yyval.v.data.data = yyvsp[0].v.data.data;
2141 yyval.v.data.value = yyvsp[0].v.data.value;
2142 }
2143break;
2144case 80:
2145#line 770 "/usr/src/usr.sbin/snmpd/parse.y"
2146{
2147 yyval.v.data.type = SNMP_V3;
2148 yyval.v.data.data = yyvsp[0].v.data.data;
2149 yyval.v.data.value = yyvsp[0].v.data.value;
2150 }
2151break;
2152case 81:
2153#line 775 "/usr/src/usr.sbin/snmpd/parse.y"
2154{
2155 yyval.v.data.type = SNMP_V2;
2156 yyval.v.data.data = yyvsp[0].v.string;
2157 }
2158break;
2159case 82:
2160#line 779 "/usr/src/usr.sbin/snmpd/parse.y"
2161{
2162 yyval.v.data.type = SNMP_V3;
2163 yyval.v.data.data = yyvsp[0].v.data.data;
2164 yyval.v.data.value = yyvsp[0].v.data.value;
2165 }
2166break;
2167case 83:
2168#line 786 "/usr/src/usr.sbin/snmpd/parse.y"
2169{ yyval.v.string = NULL((void*)0); }
2170break;
2171case 84:
2172#line 787 "/usr/src/usr.sbin/snmpd/parse.y"
2173{ yyval.v.string = yyvsp[0].v.string; }
2174break;
2175case 85:
2176#line 790 "/usr/src/usr.sbin/snmpd/parse.y"
2177{
2178 struct sockaddr_storage ss;
2179 struct trap_address *tr;
2180
2181 if ((tr = calloc(1, sizeof(*tr))) == NULL((void*)0)) {
2182 yyerror("calloc");
2183 YYERRORgoto yyerrlab;
2184 }
2185
2186 if (host(yyvsp[-3].v.string, SNMPTRAP_PORT"162", SOCK_DGRAM2, &ss, 1) <= 0) {
2187 yyerror("invalid host: %s", yyvsp[-3].v.string);
2188 free(yyvsp[-3].v.string);
2189 free(yyvsp[-2].v.oid);
2190 free(yyvsp[-1].v.data.data);
2191 free(yyvsp[0].v.string);
2192 free(tr);
2193 YYERRORgoto yyerrlab;
2194 }
2195 free(yyvsp[-3].v.string);
2196 memcpy(&(tr->ta_ss), &ss, sizeof(ss));
2197 if (yyvsp[0].v.string != NULL((void*)0)) {
2198 if (host(yyvsp[-3].v.string, "0", SOCK_DGRAM2, &ss, 1) <= 0) {
2199 yyerror("invalid host: %s", yyvsp[-3].v.string);
2200 free(yyvsp[-2].v.oid);
2201 free(yyvsp[-1].v.data.data);
2202 free(yyvsp[0].v.string);
2203 free(tr);
2204 YYERRORgoto yyerrlab;
2205 }
2206 free(yyvsp[0].v.string);
2207 memcpy(&(tr->ta_sslocal), &ss, sizeof(ss));
2208 }
2209 tr->ta_oid = yyvsp[-2].v.oid;
2210 tr->ta_version = yyvsp[-1].v.data.type;
2211 if (yyvsp[-1].v.data.type == SNMP_V2) {
2212 (void)strlcpy(tr->ta_community, yyvsp[-1].v.data.data,
2213 sizeof(tr->ta_community));
2214 free(yyvsp[-1].v.data.data);
2215 } else {
2216 tr->ta_usmusername = yyvsp[-1].v.data.data;
2217 tr->ta_seclevel = yyvsp[-1].v.data.value;
2218 }
2219 TAILQ_INSERT_TAIL(&(conf->sc_trapreceivers), tr, entry)do { (tr)->entry.tqe_next = ((void*)0); (tr)->entry.tqe_prev
= (&(conf->sc_trapreceivers))->tqh_last; *(&(conf
->sc_trapreceivers))->tqh_last = (tr); (&(conf->
sc_trapreceivers))->tqh_last = &(tr)->entry.tqe_next
; } while (0)
;
2220 }
2221break;
2222case 92:
2223#line 848 "/usr/src/usr.sbin/snmpd/parse.y"
2224{ yyval.v.number = 0; }
2225break;
2226case 93:
2227#line 849 "/usr/src/usr.sbin/snmpd/parse.y"
2228{ yyval.v.number = SNMP_MSGFLAG_AUTH0x01; }
2229break;
2230case 94:
2231#line 850 "/usr/src/usr.sbin/snmpd/parse.y"
2232{ yyval.v.number = SNMP_MSGFLAG_AUTH0x01 | SNMP_MSGFLAG_PRIV0x02; }
2233break;
2234case 97:
2235#line 857 "/usr/src/usr.sbin/snmpd/parse.y"
2236{
2237 user->uu_authkey = yyvsp[0].v.string;
2238 }
2239break;
2240case 98:
2241#line 860 "/usr/src/usr.sbin/snmpd/parse.y"
2242{
2243 user->uu_auth = yyvsp[0].v.auth;
2244 }
2245break;
2246case 99:
2247#line 863 "/usr/src/usr.sbin/snmpd/parse.y"
2248{
2249 user->uu_privkey = yyvsp[0].v.string;
2250 }
2251break;
2252case 100:
2253#line 866 "/usr/src/usr.sbin/snmpd/parse.y"
2254{
2255 user->uu_priv = yyvsp[0].v.enc;
2256 }
2257break;
2258case 101:
2259#line 871 "/usr/src/usr.sbin/snmpd/parse.y"
2260{
2261 if (strcasecmp(yyvsp[0].v.string, "hmac-md5") == 0 ||
2262 strcasecmp(yyvsp[0].v.string, "hmac-md5-96") == 0)
2263 yyval.v.auth = AUTH_MD5;
2264 else if (strcasecmp(yyvsp[0].v.string, "hmac-sha1") == 0 ||
2265 strcasecmp(yyvsp[0].v.string, "hmac-sha1-96") == 0)
2266 yyval.v.auth = AUTH_SHA1;
2267 else if (strcasecmp(yyvsp[0].v.string, "hmac-sha224") == 0 ||
2268 strcasecmp(yyvsp[0].v.string, "usmHMAC128SHA224AuthProtocol") == 0)
2269 yyval.v.auth = AUTH_SHA224;
2270 else if (strcasecmp(yyvsp[0].v.string, "hmac-sha256") == 0 ||
2271 strcasecmp(yyvsp[0].v.string, "usmHMAC192SHA256AuthProtocol") == 0)
2272 yyval.v.auth = AUTH_SHA256;
2273 else if (strcasecmp(yyvsp[0].v.string, "hmac-sha384") == 0 ||
2274 strcasecmp(yyvsp[0].v.string, "usmHMAC256SHA384AuthProtocol") == 0)
2275 yyval.v.auth = AUTH_SHA384;
2276 else if (strcasecmp(yyvsp[0].v.string, "hmac-sha512") == 0 ||
2277 strcasecmp(yyvsp[0].v.string, "usmHMAC384SHA512AuthProtocol") == 0)
2278 yyval.v.auth = AUTH_SHA512;
2279 else {
2280 yyerror("syntax error, bad auth hmac");
2281 free(yyvsp[0].v.string);
2282 YYERRORgoto yyerrlab;
2283 }
2284 free(yyvsp[0].v.string);
2285 }
2286break;
2287case 102:
2288#line 899 "/usr/src/usr.sbin/snmpd/parse.y"
2289{
2290 if (strcasecmp(yyvsp[0].v.string, "des") == 0 ||
2291 strcasecmp(yyvsp[0].v.string, "cbc-des") == 0)
2292 yyval.v.enc = PRIV_DES;
2293 else if (strcasecmp(yyvsp[0].v.string, "aes") == 0 ||
2294 strcasecmp(yyvsp[0].v.string, "cfb128-aes-128") == 0)
2295 yyval.v.enc = PRIV_AES;
2296 else {
2297 yyerror("syntax error, bad encryption cipher");
2298 free(yyvsp[0].v.string);
2299 YYERRORgoto yyerrlab;
2300 }
2301 free(yyvsp[0].v.string);
2302
2303 }
2304break;
2305case 103:
2306#line 916 "/usr/src/usr.sbin/snmpd/parse.y"
2307{
2308 struct trapcmd *cmd;
2309 size_t span, limit;
2310 char *pos, **args, **args2;
2311 int nargs = 32; /* XXX */
2312
2313 if ((cmd = calloc(1, sizeof(*cmd))) == NULL((void*)0) ||
2314 (args = calloc(nargs, sizeof(char *))) == NULL((void*)0)) {
2315 free(cmd);
2316 free(yyvsp[0].v.string);
2317 YYERRORgoto yyerrlab;
2318 }
2319
2320 pos = yyvsp[0].v.string;
2321 limit = strlen(yyvsp[0].v.string);
2322
2323 while (pos < yyvsp[0].v.string + limit &&
2324 (span = strcspn(pos, " \t")) != 0) {
2325 pos[span] = '\0';
2326 args[cmd->cmd_argc] = strdup(pos);
2327 if (args[cmd->cmd_argc] == NULL((void*)0)) {
2328 trapcmd_free(cmd);
2329 free(args);
2330 free(yyvsp[0].v.string);
2331 YYERRORgoto yyerrlab;
2332 }
2333 cmd->cmd_argc++;
2334 if (cmd->cmd_argc >= nargs - 1) {
2335 nargs *= 2;
2336 args2 = calloc(nargs, sizeof(char *));
2337 if (args2 == NULL((void*)0)) {
2338 trapcmd_free(cmd);
2339 free(args);
2340 free(yyvsp[0].v.string);
2341 YYERRORgoto yyerrlab;
2342 }
2343 args = args2;
2344 }
2345 pos += span + 1;
2346 }
2347 free(yyvsp[0].v.string);
2348 cmd->cmd_argv = args;
2349 yyval.v.data.data = cmd;
2350 }
2351break;
2352#line 2345 "parse.c"
2353 }
2354 yyssp -= yym;
2355 yystate = *yyssp;
2356 yyvsp -= yym;
2357 yym = yylhs[yyn];
2358 if (yystate == 0 && yym == 0)
2359 {
2360#if YYDEBUG0
2361 if (yydebug)
2362 printf("%sdebug: after reduction, shifting from state 0 to\
2363 state %d\n", YYPREFIX"yy", YYFINAL1);
2364#endif
2365 yystate = YYFINAL1;
2366 *++yyssp = YYFINAL1;
2367 *++yyvsp = yyval;
2368 if (yychar < 0)
2369 {
2370 if ((yychar = yylex()) < 0) yychar = 0;
2371#if YYDEBUG0
2372 if (yydebug)
2373 {
2374 yys = 0;
2375 if (yychar <= YYMAXTOKEN307) yys = yyname[yychar];
2376 if (!yys) yys = "illegal-symbol";
2377 printf("%sdebug: state %d, reading %d (%s)\n",
2378 YYPREFIX"yy", YYFINAL1, yychar, yys);
2379 }
2380#endif
2381 }
2382 if (yychar == 0) goto yyaccept;
2383 goto yyloop;
2384 }
2385 if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
2386 yyn <= YYTABLESIZE310 && yycheck[yyn] == yystate)
2387 yystate = yytable[yyn];
2388 else
2389 yystate = yydgoto[yym];
2390#if YYDEBUG0
2391 if (yydebug)
2392 printf("%sdebug: after reduction, shifting from state %d \
2393to state %d\n", YYPREFIX"yy", *yyssp, yystate);
2394#endif
2395 if (yyssp >= yysslim && yygrowstack())
2396 {
2397 goto yyoverflow;
2398 }
2399 *++yyssp = yystate;
2400 *++yyvsp = yyval;
2401 goto yyloop;
2402yyoverflow:
2403 yyerror("yacc stack overflow");
2404yyabort:
2405 if (yyss)
2406 free(yyss);
2407 if (yyvs)
2408 free(yyvs);
2409 yyss = yyssp = NULL((void*)0);
2410 yyvs = yyvsp = NULL((void*)0);
2411 yystacksize = 0;
2412 return (1);
2413yyaccept:
2414 if (yyss)
2415 free(yyss);
2416 if (yyvs)
2417 free(yyvs);
2418 yyss = yyssp = NULL((void*)0);
2419 yyvs = yyvsp = NULL((void*)0);
2420 yystacksize = 0;
2421 return (0);
2422}