~ubuntu-branches/ubuntu/oneiric/syslog-ng/oneiric

« back to all changes in this revision

Viewing changes to modules/afstreams/afstreams-grammar.y

  • Committer: Bazaar Package Importer
  • Author(s): Laszlo Boszormenyi (GCS)
  • Date: 2011-05-16 22:02:46 UTC
  • mfrom: (26.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20110516220246-nknmeu831n49bx1z
Tags: 3.2.4-1
* New upstream release, fixing infinite loop via PCRE and global. No CVE
  number yet, Vigil@nce id is 10648.
* Remove all patches, they were applied upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (c) 2002-2010 BalaBit IT Ltd, Budapest, Hungary
 
3
 * Copyright (c) 1998-2010 Balázs Scheidler
 
4
 *
 
5
 * This program is free software; you can redistribute it and/or modify it
 
6
 * under the terms of the GNU General Public License version 2 as published
 
7
 * by the Free Software Foundation, or (at your option) any later version.
 
8
 *
 
9
 * This library is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
12
 * Lesser General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU Lesser General Public
 
15
 * License along with this library; if not, write to the Free Software
 
16
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
17
 *
 
18
 * As an additional exemption you are allowed to compile & link against the
 
19
 * OpenSSL libraries as published by the OpenSSL project. See the file
 
20
 * COPYING for details.
 
21
 *
 
22
 */
 
23
 
 
24
%code top {
 
25
#include "afstreams-parser.h"
 
26
 
 
27
}
 
28
 
 
29
 
 
30
%code {
 
31
 
 
32
#include "afstreams.h"
 
33
#include "cfg-parser.h"
 
34
#include "afstreams-grammar.h"
 
35
#include "messages.h"
 
36
 
 
37
}
 
38
 
 
39
%name-prefix "afstreams_"
 
40
 
 
41
/* this parameter is needed in order to instruct bison to use a complete
 
42
 * argument list for yylex/yyerror */
 
43
 
 
44
%lex-param {CfgLexer *lexer}
 
45
%parse-param {CfgLexer *lexer}
 
46
%parse-param {LogDriver **last_driver}
 
47
 
 
48
 
 
49
 
 
50
%require "2.4.1"
 
51
%locations
 
52
%define api.pure
 
53
%pure-parser
 
54
%error-verbose
 
55
 
 
56
%code {
 
57
 
 
58
# define YYLLOC_DEFAULT(Current, Rhs, N)                                \
 
59
  do {                                                                  \
 
60
    if (YYID (N))                                                       \
 
61
      {                                                                 \
 
62
        (Current).level = YYRHSLOC(Rhs, 1).level;                       \
 
63
        (Current).first_line   = YYRHSLOC (Rhs, 1).first_line;          \
 
64
        (Current).first_column = YYRHSLOC (Rhs, 1).first_column;        \
 
65
        (Current).last_line    = YYRHSLOC (Rhs, N).last_line;           \
 
66
        (Current).last_column  = YYRHSLOC (Rhs, N).last_column;         \
 
67
      }                                                                 \
 
68
    else                                                                \
 
69
      {                                                                 \
 
70
        (Current).level = YYRHSLOC(Rhs, 0).level;                       \
 
71
        (Current).first_line   = (Current).last_line   =                \
 
72
          YYRHSLOC (Rhs, 0).last_line;                                  \
 
73
        (Current).first_column = (Current).last_column =                \
 
74
          YYRHSLOC (Rhs, 0).last_column;                                \
 
75
      }                                                                 \
 
76
  } while (YYID (0))
 
77
 
 
78
#define CHECK_ERROR(val, token, errorfmt, ...) do {                     \
 
79
    if (!(val))                                                         \
 
80
      {                                                                 \
 
81
        if (errorfmt)                                                   \
 
82
          {                                                             \
 
83
            gchar __buf[256];                                           \
 
84
            g_snprintf(__buf, sizeof(__buf), errorfmt ? errorfmt : "x", ## __VA_ARGS__); \
 
85
            yyerror(& (token), lexer, NULL, __buf);                     \
 
86
          }                                                             \
 
87
        YYERROR;                                                        \
 
88
      }                                                                 \
 
89
  } while (0)
 
90
 
 
91
#define YYMAXDEPTH 20000
 
92
 
 
93
 
 
94
}
 
95
 
 
96
/* plugin types, must be equal to the numerical values of the plugin type in plugin.h */
 
97
 
 
98
%token LL_CONTEXT_ROOT                1
 
99
%token LL_CONTEXT_DESTINATION         2
 
100
%token LL_CONTEXT_SOURCE              3
 
101
%token LL_CONTEXT_PARSER              4
 
102
%token LL_CONTEXT_REWRITE             5
 
103
%token LL_CONTEXT_FILTER              6
 
104
%token LL_CONTEXT_LOG                 7
 
105
%token LL_CONTEXT_BLOCK_DEF           8
 
106
%token LL_CONTEXT_BLOCK_REF           9
 
107
%token LL_CONTEXT_BLOCK_CONTENT       10
 
108
%token LL_CONTEXT_PRAGMA              11
 
109
%token LL_CONTEXT_FORMAT              12
 
110
%token LL_CONTEXT_TEMPLATE_FUNC       13
 
111
 
 
112
/* statements */
 
113
%token KW_SOURCE                      10000
 
114
%token KW_FILTER                      10001
 
115
%token KW_PARSER                      10002
 
116
%token KW_DESTINATION                 10003
 
117
%token KW_LOG                         10004
 
118
%token KW_OPTIONS                     10005
 
119
%token KW_INCLUDE                     10006
 
120
%token KW_BLOCK                       10007
 
121
 
 
122
/* source & destination items */
 
123
%token KW_INTERNAL                    10010
 
124
%token KW_FILE                        10011
 
125
 
 
126
%token KW_SQL                         10030
 
127
%token KW_TYPE                        10031
 
128
%token KW_COLUMNS                     10032
 
129
%token KW_INDEXES                     10033
 
130
%token KW_VALUES                      10034
 
131
%token KW_PASSWORD                    10035
 
132
%token KW_DATABASE                    10036
 
133
%token KW_USERNAME                    10037
 
134
%token KW_TABLE                       10038
 
135
%token KW_ENCODING                    10039
 
136
%token KW_SESSION_STATEMENTS          10040
 
137
 
 
138
%token KW_DELIMITERS                  10050
 
139
%token KW_QUOTES                      10051
 
140
%token KW_QUOTE_PAIRS                 10052
 
141
%token KW_NULL                        10053
 
142
 
 
143
%token KW_SYSLOG                      10060
 
144
 
 
145
 
 
146
/* option items */
 
147
%token KW_MARK_FREQ                   10071
 
148
%token KW_STATS_FREQ                  10072
 
149
%token KW_STATS_LEVEL                 10073
 
150
%token KW_FLUSH_LINES                 10074
 
151
%token KW_SUPPRESS                    10075
 
152
%token KW_FLUSH_TIMEOUT               10076
 
153
%token KW_LOG_MSG_SIZE                10077
 
154
%token KW_FILE_TEMPLATE               10078
 
155
%token KW_PROTO_TEMPLATE              10079
 
156
 
 
157
%token KW_CHAIN_HOSTNAMES             10090
 
158
%token KW_NORMALIZE_HOSTNAMES         10091
 
159
%token KW_KEEP_HOSTNAME               10092
 
160
%token KW_CHECK_HOSTNAME              10093
 
161
%token KW_BAD_HOSTNAME                10094
 
162
 
 
163
%token KW_KEEP_TIMESTAMP              10100
 
164
 
 
165
%token KW_USE_DNS                     10110
 
166
%token KW_USE_FQDN                    10111
 
167
 
 
168
%token KW_DNS_CACHE                   10120
 
169
%token KW_DNS_CACHE_SIZE              10121
 
170
 
 
171
%token KW_DNS_CACHE_EXPIRE            10130
 
172
%token KW_DNS_CACHE_EXPIRE_FAILED     10131
 
173
%token KW_DNS_CACHE_HOSTS             10132
 
174
 
 
175
%token KW_PERSIST_ONLY                10140
 
176
 
 
177
%token KW_TZ_CONVERT                  10150
 
178
%token KW_TS_FORMAT                   10151
 
179
%token KW_FRAC_DIGITS                 10152
 
180
 
 
181
%token KW_LOG_FIFO_SIZE               10160
 
182
%token KW_LOG_FETCH_LIMIT             10162
 
183
%token KW_LOG_IW_SIZE                 10163
 
184
%token KW_LOG_PREFIX                  10164
 
185
%token KW_PROGRAM_OVERRIDE            10165
 
186
%token KW_HOST_OVERRIDE               10166
 
187
 
 
188
%token KW_THROTTLE                    10170
 
189
 
 
190
/* log statement options */
 
191
%token KW_FLAGS                       10190
 
192
 
 
193
/* reader options */
 
194
%token KW_PAD_SIZE                    10200
 
195
%token KW_TIME_ZONE                   10201
 
196
%token KW_RECV_TIME_ZONE              10202
 
197
%token KW_SEND_TIME_ZONE              10203
 
198
%token KW_LOCAL_TIME_ZONE             10204
 
199
%token KW_FORMAT                      10205
 
200
 
 
201
/* timers */
 
202
%token KW_TIME_REOPEN                 10210
 
203
%token KW_TIME_REAP                   10211
 
204
%token KW_TIME_SLEEP                  10212
 
205
 
 
206
/* destination options */
 
207
%token KW_TMPL_ESCAPE                 10220
 
208
 
 
209
/* driver specific options */
 
210
%token KW_OPTIONAL                    10230
 
211
 
 
212
/* file related options */
 
213
%token KW_CREATE_DIRS                 10240
 
214
 
 
215
%token KW_OWNER                       10250
 
216
%token KW_GROUP                       10251
 
217
%token KW_PERM                        10252
 
218
 
 
219
%token KW_DIR_OWNER                   10260
 
220
%token KW_DIR_GROUP                   10261
 
221
%token KW_DIR_PERM                    10262
 
222
 
 
223
%token KW_TEMPLATE                    10270
 
224
%token KW_TEMPLATE_ESCAPE             10271
 
225
 
 
226
%token KW_DEFAULT_FACILITY            10300
 
227
%token KW_DEFAULT_LEVEL               10301
 
228
 
 
229
%token KW_PORT                        10323
 
230
/* misc options */
 
231
 
 
232
%token KW_USE_TIME_RECVD              10340
 
233
 
 
234
/* filter items*/
 
235
%token KW_FACILITY                    10350
 
236
%token KW_LEVEL                       10351
 
237
%token KW_HOST                        10352
 
238
%token KW_MATCH                       10353
 
239
%token KW_MESSAGE                     10354
 
240
%token KW_NETMASK                     10355
 
241
%token KW_TAGS                        10356
 
242
 
 
243
/* parser items */
 
244
 
 
245
%token KW_VALUE                       10361
 
246
 
 
247
/* rewrite items */
 
248
 
 
249
%token KW_REWRITE                     10370
 
250
%token KW_SET                         10371
 
251
%token KW_SUBST                       10372
 
252
 
 
253
/* yes/no switches */
 
254
 
 
255
%token KW_YES                         10380
 
256
%token KW_NO                          10381
 
257
 
 
258
%token KW_IFDEF                       10410
 
259
%token KW_ENDIF                       10411
 
260
 
 
261
%token LL_DOTDOT                      10420
 
262
 
 
263
%token <cptr> LL_IDENTIFIER           10421
 
264
%token <num>  LL_NUMBER               10422
 
265
%token <fnum> LL_FLOAT                10423
 
266
%token <cptr> LL_STRING               10424
 
267
%token <token> LL_TOKEN               10425
 
268
%token <cptr> LL_BLOCK                10426
 
269
%token LL_PRAGMA                      10427
 
270
%token LL_EOL                         10428
 
271
%token LL_ERROR                       10429
 
272
 
 
273
 
 
274
%type   <num> yesno
 
275
%type   <num> dnsmode
 
276
%type   <num> regexp_option_flags
 
277
%type   <num> dest_writer_options_flags
 
278
 
 
279
%type   <cptr> string
 
280
%type   <cptr> string_or_number
 
281
%type   <ptr> string_list
 
282
%type   <ptr> string_list_build
 
283
%type   <num> facility_string
 
284
%type   <num> level_string
 
285
 
 
286
 
 
287
%token KW_DOOR                        10020
 
288
%token KW_SUN_STREAMS                 10021
 
289
 
 
290
 
 
291
%type   <ptr> source_afstreams
 
292
%type   <ptr> source_afstreams_params
 
293
 
 
294
%%
 
295
 
 
296
start
 
297
        : LL_CONTEXT_SOURCE source_afstreams                        { YYACCEPT; }
 
298
        ;
 
299
 
 
300
 
 
301
source_afstreams
 
302
        : KW_IFDEF {
 
303
#if ENABLE_SUN_STREAMS
 
304
}
 
305
        | KW_SUN_STREAMS '(' source_afstreams_params ')'        { $$ = $3; }
 
306
        | KW_ENDIF {
 
307
#endif
 
308
}
 
309
        ;
 
310
 
 
311
source_afstreams_params
 
312
        : string
 
313
          {
 
314
#if ENABLE_SUN_STREAMS
 
315
            (*last_driver) = afstreams_sd_new($1);
 
316
            free($1);
 
317
#endif
 
318
          }
 
319
          source_afstreams_options              { $$ = (*last_driver); }
 
320
        ;
 
321
 
 
322
source_afstreams_options
 
323
        : source_afstreams_option source_afstreams_options
 
324
        |
 
325
        ;
 
326
 
 
327
source_afstreams_option
 
328
        : KW_IFDEF {
 
329
#if ENABLE_SUN_STREAMS
 
330
}
 
331
        | KW_DOOR '(' string ')'                { afstreams_sd_set_sundoor((*last_driver), $3); free($3); }
 
332
        | KW_ENDIF {
 
333
#endif
 
334
}
 
335
        ;
 
336
 
 
337
 
 
338
 
 
339
string
 
340
        : LL_IDENTIFIER
 
341
        | LL_STRING
 
342
        ;
 
343
 
 
344
yesno
 
345
        : KW_YES                                { $$ = 1; }
 
346
        | KW_NO                                 { $$ = 0; }
 
347
        | LL_NUMBER                             { $$ = $1; }
 
348
        ;
 
349
 
 
350
dnsmode
 
351
        : yesno                                 { $$ = $1; }
 
352
        | KW_PERSIST_ONLY                       { $$ = 2; }
 
353
        ;
 
354
 
 
355
string_or_number
 
356
        : string                                { $$ = $1; }
 
357
        | LL_NUMBER                             { $$ = strdup(lexer->token_text->str); }
 
358
        | LL_FLOAT                              { $$ = strdup(lexer->token_text->str); }
 
359
        ;
 
360
 
 
361
string_list
 
362
        : string_list_build                     { $$ = g_list_reverse($1); }
 
363
        ;
 
364
 
 
365
string_list_build
 
366
        : string string_list_build              { $$ = g_list_append($2, g_strdup($1)); free($1); }
 
367
        |                                       { $$ = NULL; }
 
368
        ;
 
369
 
 
370
level_string
 
371
        : string
 
372
          {
 
373
            /* return the numeric value of the "level" */
 
374
            int n = syslog_name_lookup_level_by_name($1);
 
375
            CHECK_ERROR((n != -1), @1, "Unknown priority level\"%s\"", $1);
 
376
            free($1);
 
377
            $$ = n;
 
378
          }
 
379
        ;
 
380
 
 
381
facility_string
 
382
        : string
 
383
          {
 
384
            /* return the numeric value of facility */
 
385
            int n = syslog_name_lookup_facility_by_name($1);
 
386
            CHECK_ERROR((n != -1), @1, "Unknown facility \"%s\"", $1);
 
387
            free($1);
 
388
            $$ = n;
 
389
          }
 
390
        | KW_SYSLOG                             { $$ = LOG_SYSLOG; }
 
391
        ;
 
392
 
 
393
regexp_option_flags
 
394
        : string regexp_option_flags            { $$ = log_matcher_lookup_flag($1) | $2; free($1); }
 
395
        |                                       { $$ = 0; }
 
396
        ;
 
397
 
 
398
 
 
399
source_reader_options
 
400
        : source_reader_option source_reader_options
 
401
        |
 
402
        ;
 
403
 
 
404
source_reader_option
 
405
        : KW_LOG_IW_SIZE '(' LL_NUMBER ')'              { last_reader_options->super.init_window_size = $3; }
 
406
        | KW_CHAIN_HOSTNAMES '(' yesno ')'      { last_reader_options->super.chain_hostnames = $3; }
 
407
        | KW_NORMALIZE_HOSTNAMES '(' yesno ')'  { last_reader_options->super.normalize_hostnames = $3; }
 
408
        | KW_KEEP_HOSTNAME '(' yesno ')'        { last_reader_options->super.keep_hostname = $3; }
 
409
        | KW_USE_FQDN '(' yesno ')'             { last_reader_options->super.use_fqdn = $3; }
 
410
        | KW_USE_DNS '(' dnsmode ')'            { last_reader_options->super.use_dns = $3; }
 
411
        | KW_DNS_CACHE '(' yesno ')'            { last_reader_options->super.use_dns_cache = $3; }
 
412
        | KW_PROGRAM_OVERRIDE '(' string ')'    { last_reader_options->super.program_override = g_strdup($3); free($3); }
 
413
        | KW_HOST_OVERRIDE '(' string ')'       { last_reader_options->super.host_override = g_strdup($3); free($3); }
 
414
        | KW_LOG_PREFIX '(' string ')'          { gchar *p = strrchr($3, ':'); if (p) *p = 0; last_reader_options->super.program_override = g_strdup($3); free($3); }
 
415
        | KW_TIME_ZONE '(' string ')'           { last_reader_options->parse_options.recv_time_zone = g_strdup($3); free($3); }
 
416
        | KW_CHECK_HOSTNAME '(' yesno ')'       { last_reader_options->check_hostname = $3; }
 
417
        | KW_FLAGS '(' source_reader_option_flags ')'
 
418
        | KW_LOG_MSG_SIZE '(' LL_NUMBER ')'     { last_reader_options->msg_size = $3; }
 
419
        | KW_LOG_FETCH_LIMIT '(' LL_NUMBER ')'  { last_reader_options->fetch_limit = $3; }
 
420
        | KW_PAD_SIZE '(' LL_NUMBER ')'         { last_reader_options->padding = $3; }
 
421
        | KW_KEEP_TIMESTAMP '(' yesno ')'       { last_reader_options->super.keep_timestamp = $3; }
 
422
        | KW_ENCODING '(' string ')'            { last_reader_options->text_encoding = g_strdup($3); free($3); }
 
423
        | KW_TAGS '(' string_list ')'           { log_reader_options_set_tags(last_reader_options, $3); }
 
424
        | KW_FORMAT '(' string ')'              { last_reader_options->parse_options.format = g_strdup($3); free($3); }
 
425
        | KW_DEFAULT_LEVEL '(' level_string ')'
 
426
          {
 
427
            if (last_reader_options->parse_options.default_pri == 0xFFFF)
 
428
              last_reader_options->parse_options.default_pri = LOG_USER;
 
429
            last_reader_options->parse_options.default_pri = (last_reader_options->parse_options.default_pri & ~7) | $3;
 
430
          }
 
431
        | KW_DEFAULT_FACILITY '(' facility_string ')'
 
432
          {
 
433
            if (last_reader_options->parse_options.default_pri == 0xFFFF)
 
434
              last_reader_options->parse_options.default_pri = LOG_NOTICE;
 
435
            last_reader_options->parse_options.default_pri = (last_reader_options->parse_options.default_pri & 7) | $3;
 
436
          }
 
437
        ;
 
438
 
 
439
source_reader_option_flags
 
440
        : string source_reader_option_flags     { CHECK_ERROR(log_reader_options_process_flag(last_reader_options, $1), @1, "Unknown flag %s", $1); free($1); }
 
441
        |
 
442
        ;
 
443
 
 
444
dest_writer_options
 
445
        : dest_writer_option dest_writer_options
 
446
        |
 
447
        ;
 
448
 
 
449
dest_writer_option
 
450
        : KW_FLAGS '(' dest_writer_options_flags ')' { last_writer_options->options = $3; }
 
451
        | KW_LOG_FIFO_SIZE '(' LL_NUMBER ')'    { last_writer_options->mem_fifo_size = $3; }
 
452
        | KW_FLUSH_LINES '(' LL_NUMBER ')'              { last_writer_options->flush_lines = $3; }
 
453
        | KW_FLUSH_TIMEOUT '(' LL_NUMBER ')'    { last_writer_options->flush_timeout = $3; }
 
454
        | KW_SUPPRESS '(' LL_NUMBER ')'            { last_writer_options->suppress = $3; }
 
455
        | KW_TEMPLATE '(' string ')'            {
 
456
                                                  GError *error = NULL;
 
457
 
 
458
                                                  last_writer_options->template = cfg_check_inline_template(configuration, $3);
 
459
                                                  CHECK_ERROR(log_template_compile(last_writer_options->template, &error), @3, "Error compiling template (%s)", error->message);
 
460
                                                  free($3);
 
461
                                                }
 
462
        | KW_TEMPLATE_ESCAPE '(' yesno ')'      { log_writer_options_set_template_escape(last_writer_options, $3); }
 
463
        | KW_TIME_ZONE '(' string ')'           { last_writer_options->template_options.time_zone[LTZ_SEND] = g_strdup($3); free($3); }
 
464
        | KW_TS_FORMAT '(' string ')'           { last_writer_options->template_options.ts_format = cfg_ts_format_value($3); free($3); }
 
465
        | KW_FRAC_DIGITS '(' LL_NUMBER ')'      { last_writer_options->template_options.frac_digits = $3; }
 
466
        | KW_THROTTLE '(' LL_NUMBER ')'         { last_writer_options->throttle = $3; }
 
467
        ;
 
468
 
 
469
dest_writer_options_flags
 
470
        : string dest_writer_options_flags      { $$ = log_writer_options_lookup_flag($1) | $2; free($1); }
 
471
        |                                       { $$ = 0; }
 
472
        ;
 
473
 
 
474
 
 
475
%%