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