1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
|
--- parseconf.y.orig Tue Aug 26 10:53:30 2003
+++ parseconf.y Thu Dec 28 13:31:06 2006
@@ -13,6 +13,7 @@
#endif
#include <sys/types.h>
+#include <sys/limits.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>
@@ -117,6 +118,7 @@
first_save = NULL;
global_var_list = 0;
+ config.compatibility_flag = 1;
}
static char *
@@ -197,11 +199,37 @@
BGP_AS *bgp;
ENV_MON *env;
char *cp, buf[1024];
+ struct passwd *pwentry;
+ struct group *grentry;
if (!config.rootdir) {
report(LOG_ERR, "%s: rootdir unspecified", config_file);
return NULL;
}
+ compatibility_flag = config.compatibility_flag;
+ if (!config.srcaddress)
+ bzero(&config.ip_srcaddr, sizeof(struct in_addr));
+ if (!config.ns_address)
+ bzero(&config.ns_ip_addr, sizeof(struct in_addr));
+ if (!config.trap_address)
+ bzero(&config.trap_ip_addr, sizeof(struct in_addr));
+
+ if(!config.username) {
+ config.username = strdup(USERNAME);
+ if ((pwentry = getpwnam(USERNAME)) == (struct passwd *) NULL) {
+ report(LOG_ERR, "Bad default username: %s.",config.username);
+ return NULL;
+ }
+ config.uid = pwentry->pw_uid;
+ }
+ if(!config.groupname) {
+ config.groupname = strdup(GROUPNAME);
+ if ((grentry = getgrnam(GROUPNAME)) == (struct group *) NULL) {
+ report(LOG_ERR, "Bad default groupname: %s.",config.groupname);
+ return NULL;
+ }
+ config.gid = (gid_t)grentry->gr_gid;
+ }
if (config.polling) {
if (!config.timeout)
config.timeout = TIMEOUT_DEFAULT;
@@ -273,6 +301,7 @@
for (service = target->service; service; service = service->next) {
service->ip_addr = target->ip_addr;
+ service->ip_srcaddr = target->ip_srcaddr;
service->parent = target;
(void)strcpy(cp, "/");
@@ -329,6 +358,8 @@
METHOD *method;
CHATSCRIPT *cs;
REFERENCE *ref;
+ char *buf;
+ ssize_t buf_len;
/* sanity check */
if (!chain || !item) {
@@ -362,6 +393,16 @@
yyerror("Out of memory");
return 0;
}
+ buf_len = strlen(method->name)+4 ;
+ buf = malloc( buf_len );
+ if (buf)
+ snprintf(buf,buf_len,"%s.ok",method->name);
+ if (!buf || !add_var(&curr->var_list, buf)) {
+ yyerror("Out of memory");
+ return 0;
+ }
+ free(buf);
+
/* bind variable references */
for (cs = method->chatscript; cs; cs = cs->next) {
for (ref = cs->var_ref; ref; ref = ref->next) {
@@ -854,7 +895,7 @@
}
/* check for duplicates */
for (curr = *chain; curr; curr = curr->next) {
- if (!strcasecmp(curr->name, item->name)) {
+ if ( chain == &first_save && !strcasecmp(curr->name, item->name)) {
yyerror("save name \"%s\" duplicated", item->name);
return 0;
}
@@ -901,7 +942,9 @@
char *argument;
{
METHOD *new;
-
+ char arg_list[1024], *av[MAX_ARGS+2];
+ int ac = 0;
+
if ((new = (METHOD *)malloc(sizeof(METHOD))) == NULL) {
yyerror("Out of memory");
return NULL;
@@ -915,10 +958,24 @@
yyerror("Out of memory");
return 0;
}
- if (argument)
+ if (argument) {
new->argument = argument;
- else if (new->argument)
+ (void)strncpy(arg_list, argument, sizeof(arg_list));
+ arg_list[sizeof(arg_list)-1] = '\0';
+ } else if (new->argument) {
new->argument = strdup(new->argument);
+ (void)strncpy(arg_list, new->argument, sizeof(arg_list));
+ arg_list[sizeof(arg_list)-1] = '\0';
+ } else arg_list[0] = '\0';
+ av[ac++] = new->name;
+ ac += make_argv(arg_list, (char ***)&av[ac], MAX_ARGS);
+ av[ac] = NULL;
+
+ if (new->when && (new->when = insert_args(new->when, av, ac)) == NULL)
+ return NULL;
+ if (new->when_fmt && (new->when_fmt = insert_args(new->when_fmt, av, ac)) == NULL)
+ return NULL;
+
if (new->chatscript) {
new->chatscript = dup_chatscript(new->name, new->argument, new->chatscript);
if (!new->chatscript) return NULL;
@@ -1342,11 +1399,15 @@
/* Lexical analyzer return values */
%token TOKEN_ROOTDIR
+%token TOKEN_CHROOTDIR
+%token TOKEN_USERNAME
+%token TOKEN_GROUPNAME
%token TOKEN_TIMEFMT
%token TOKEN_POLLING
%token TOKEN_SAVING
%token TOKEN_TIMEOUT
%token TOKEN_RETRIES
+%token TOKEN_OMULSTATES
%token TOKEN_GROUP
%token TOKEN_PERMIT
@@ -1354,6 +1415,7 @@
%token TOKEN_NETSTATE
%token TOKEN_PORT
+%token TOKEN_BINDADDRESS
%token TOKEN_SAVE
%token TOKEN_FILE
@@ -1365,6 +1427,7 @@
%token TOKEN_OBJECT
%token TOKEN_ADDRESS
+%token TOKEN_SRCADDRESS
%token TOKEN_DESCRIPTION
%token TOKEN_SERVICE
%token TOKEN_INTERFACE
@@ -1398,11 +1461,13 @@
%token TOKEN_V2
%token TOKEN_TRAP
+%token TOKEN_TRAPBINDADDRESS
%token TOKEN_SOURCECHECK
%token TOKEN_COMMUNITY
%token TOKEN_ENTERPRISE
%token TOKEN_SPECIFIC
%token TRAP_GENERIC
+%token TOKEN_IGNORESTATE
%token <number> TOKEN_NUMBER
%token <string> TOKEN_STRING
@@ -1410,7 +1475,7 @@
%token <string> VAR_OID
%type <number> optional_number
-%type <string> optional_string quoted_string legal_string multiline_string
+%type <string> optional_string quoted_string legal_string multiline_string optional_multiline_string
%type <save> get_save
%type <method> get_method
%type <trap> get_trap
@@ -1442,6 +1507,60 @@
YYABORT;
}
}
+ | TOKEN_CHROOTDIR quoted_string
+ {
+ if (config.chrootdir) {
+ yyerror("ChRootDir statement duplicated");
+ YYABORT;
+ }
+ config.chrootdir = $2;
+ }
+ | TOKEN_USERNAME quoted_string
+ {
+ struct passwd *pwentry;
+
+ if (config.username) {
+ yyerror("UserName statement duplicated");
+ YYABORT;
+ }
+ if ((pwentry = getpwnam($2)) == (struct passwd *)NULL) {
+ yyerror("UserName %s unknown.", $2);
+ YYABORT;
+ }
+ config.uid = pwentry->pw_uid;
+ config.username = $2;
+ }
+
+ | TOKEN_GROUPNAME quoted_string
+ {
+ struct group *grentry;
+
+ if (config.groupname) {
+ yyerror("GroupName statement duplicated");
+ YYABORT;
+ }
+ if ((grentry = getgrnam($2)) == (struct group *)NULL) {
+ yyerror("GroupName %s unknown.", $2);
+ YYABORT;
+ }
+ config.gid = grentry->gr_gid;
+ config.groupname = $2;
+ }
+
+ | TOKEN_SRCADDRESS quoted_string
+ {
+ struct in_addr ip_srcaddr;
+
+ if (config.srcaddress) {
+ yyerror("config source address duplicated");
+ YYABORT;
+ }
+ if (!gethostaddr(&ip_srcaddr, $2)) {
+ YYABORT;
+ }
+ config.srcaddress = $2;
+ memcpy(&config.ip_srcaddr, &ip_srcaddr, sizeof(struct in_addr));
+ }
| TOKEN_TIMEFMT quoted_string
{
if (config.timefmt) {
@@ -1485,6 +1604,10 @@
}
config.retries = $2;
}
+ | TOKEN_OMULSTATES
+ {
+ config.compatibility_flag = 0;
+ }
| TOKEN_NETSTATE '{' netstate_config '}'
{
if (!config.ns_port) {
@@ -1531,6 +1654,17 @@
{
config.source_traps = 1;
}
+ | TOKEN_TRAPBINDADDRESS quoted_string
+ {
+ if (config.trap_address) {
+ yyerror("bindaddress duplicated");
+ YYABORT;
+ }
+ if (!gethostaddr(&config.trap_ip_addr, $2)) {
+ YYABORT;
+ }
+ config.trap_address = $2;
+ }
| TOKEN_TRAP legal_string '{' trap_config '}'
{
trap.name = $2;
@@ -1556,6 +1690,13 @@
yyerror("object address unspecified");
YYABORT;
}
+ if (!object.srcaddress) {
+ if (!config.srcaddress) {
+ bzero(&object.ip_srcaddr, sizeof(struct in_addr));
+ } else {
+ memcpy(&object.ip_srcaddr, &config.ip_srcaddr, sizeof(struct in_addr));
+ }
+ }
/* if ((object.interface || object.ifgroup ||
object.bgp || object.env) &&
!find_method(object.method_list, "ROUTER")) {
@@ -1637,6 +1778,17 @@
YYABORT;
}
}
+ | TOKEN_BINDADDRESS quoted_string
+ {
+ if (config.ns_address) {
+ yyerror("bindaddress duplicated");
+ YYABORT;
+ }
+ if (!gethostaddr(&config.ns_ip_addr, $2)) {
+ YYABORT;
+ }
+ config.ns_address = $2;
+ }
| TOKEN_PERMIT quoted_string
{
/* for backward compatibility */
@@ -1701,7 +1853,7 @@
}
save.state = $2;
}
- | TOKEN_WHEN multiline_string TOKEN_NUMBER optional_string
+ | TOKEN_WHEN multiline_string TOKEN_NUMBER optional_multiline_string
{
if (save.when) {
yyerror("save when condition duplicated");
@@ -1763,6 +1915,19 @@
method.start = echo_start;
method.stop = echo_stop;
}
+ | TOKEN_PIPE quoted_string
+ {
+ if (method.protocol) {
+ yyerror("method protocol duplicated");
+ YYABORT;
+ }
+ method.protocol = PIPE_PROTO;
+ method.when = $2;
+ method.init = pipe_init;
+ method.start = pipe_start;
+ method.stop = tcp_stop;
+ method.retries = 1;
+ }
| TOKEN_PORT TOKEN_NUMBER
{
if (method.protocol &&
@@ -1808,12 +1973,30 @@
}
}
}
+ | TOKEN_WHEN multiline_string TOKEN_NUMBER optional_multiline_string
+ {
+ method.protocol = WHEN_PROTO;
+ if (method.when) {
+ yyerror("Method 'when condition' duplicated");
+ YYABORT;
+ }
+ method.init = when_init;
+ method.start = when_start;
+ method.stop = when_stop;
+ method.when = $2;
+ method.timeout = $3;
+ method.when_fmt = $4;
+ }
| TOKEN_TIMEOUT TOKEN_NUMBER
{
if (method.timeout) {
yyerror("timeout statement duplicated");
YYABORT;
}
+ if (method.protocol == WHEN_PROTO) {
+ yyerror("timeout was defined in WHEN statement");
+ YYABORT;
+ }
if ($2 < 1 || $2 > POLLING_MIN) {
yyerror("invalid timeout value (min 1 max %d sec.)",
POLLING_MIN);
@@ -1827,6 +2010,10 @@
yyerror("retries statement duplicated");
YYABORT;
}
+ if (method.protocol == PIPE_PROTO) {
+ yyerror("no retries possible in PIPE method");
+ YYABORT;
+ }
if ($2 < 1 || $2 > POLLING_MIN) {
yyerror("invalid retries number (min 1 max %d)",
POLLING_MIN);
@@ -1838,7 +2025,8 @@
{
if (method.protocol &&
method.protocol != IPPROTO_TCP &&
- method.protocol != IPPROTO_UDP) {
+ method.protocol != IPPROTO_UDP &&
+ method.protocol != PIPE_PROTO) {
yyerror("no suitable method protocol");
YYABORT;
}
@@ -2095,6 +2283,18 @@
}
object.address = $2;
}
+ | TOKEN_SRCADDRESS quoted_string
+ {
+ if (object.srcaddress) {
+ yyerror("object source address duplicated");
+ YYABORT;
+ }
+ if (!gethostaddr(&object.ip_srcaddr, $2)) {
+ YYABORT;
+ }
+ object.srcaddress = $2;
+ }
+
| TOKEN_POLLING TOKEN_NUMBER
{
if (object.polling) {
@@ -2241,7 +2441,7 @@
}
| TOKEN_INTERFACE TOKEN_NUMBER
{
- if ($2 < 1 || $2 > 65535) {
+ if ($2 < 1 || $2 > INT_MAX) {
yyerror("interface index out of range");
YYABORT;
}
@@ -2252,7 +2452,7 @@
}
| TOKEN_INTERFACE TOKEN_NUMBER '{' interface_config '}'
{
- if ($2 < 1 || $2 > 65535) {
+ if ($2 < 1 || $2 > INT_MAX ) {
yyerror("interface index out of range");
YYABORT;
}
@@ -2473,6 +2673,10 @@
YYABORT;
}
}
+ | TOKEN_IGNORESTATE
+ {
+ subobject.ignore_state = 1;
+ }
;
interface_config: /* empty */
@@ -2530,6 +2734,10 @@
YYABORT;
}
}
+ | TOKEN_IGNORESTATE
+ {
+ interface.ignore_state = 1;
+ }
;
bgp_config: /* empty */
@@ -2580,6 +2788,10 @@
}
free($2);
}
+ | TOKEN_IGNORESTATE
+ {
+ bgp_as.ignore_state = 1;
+ }
;
env_config: /* empty */
@@ -2629,6 +2841,10 @@
YYABORT;
}
}
+ | TOKEN_IGNORESTATE
+ {
+ env_mon.ignore_state = 1;
+ }
;
get_save: legal_string optional_string
@@ -2918,6 +3134,12 @@
$$ = NULL;
}
| quoted_string
+ ;
+optional_multiline_string:
+ {
+ $$ = NULL;
+ }
+ | multiline_string
;
%%
|