~ubuntu-branches/ubuntu/precise/apparmor/precise-security

« back to all changes in this revision

Viewing changes to .pc/0009-apparmor-lp959560-part1.patch/parser/parser_lex.l

  • Committer: Package Import Robot
  • Author(s): Steve Beattie, Jamie Strandboge, Serge Hallyn, Steve Beattie
  • Date: 2012-04-12 06:17:42 UTC
  • Revision ID: package-import@ubuntu.com-20120412061742-9v75hjko2mjtbewv
Tags: 2.7.102-0ubuntu3
[ Jamie Strandboge ]
* debian/patches/0007-ubuntu-manpage-updates.patch: update apparmor(5)
  to describe Ubuntu's two-stage policy load and how to add utilize it
  when developing policy (LP: #974089)

[ Serge Hallyn ]
* debian/apparmor.init: do nothing in a container.  This can be
  removed once stacked profiles are supported and used by lxc.
  (LP: #978297)

[ Steve Beattie ]
* debian/patches/0008-apparmor-lp963756.patch: Fix permission mapping
  for change_profile onexec (LP: #963756)
* debian/patches/0009-apparmor-lp959560-part1.patch,
  debian/patches/0010-apparmor-lp959560-part2.patch: Update the parser
  to support the 'in' keyword for value lists, and make mount
  operations aware of 'in' keyword so they can affect the flags build
  list (LP: #959560)
* debian/patches/0011-apparmor-lp872446.patch: fix logprof missing
  exec events in complain mode (LP: #872446)
* debian/patches/0012-apparmor-lp978584.patch: allow inet6 access in
  dovecot imap-login profile (LP: #978584)
* debian/patches/0013-apparmor-lp800826.patch: fix libapparmor
  log parsing library from dropping apparmor network events that
  contain ip addresses or ports in them (LP: #800826)
* debian/patches/0014-apparmor-lp979095.patch: document new mount rule
  syntax and usage in apparmor.d(5) manpage (LP: #979095)
* debian/patches/0015-apparmor-lp963756.patch: Fix change_onexec
  for profiles without attachment specification (LP: #963756,
  LP: #978038)
* debian/patches/0016-apparmor-lp968956.patch: Fix protocol error when
  loading policy to kernels without compat patches (LP: #968956)
* debian/patches/0017-apparmor-lp979135.patch: Fix change_profile to
  grant access to /proc/attr api (LP: #979135)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *   Copyright (c) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
 
3
 *   NOVELL (All rights reserved)
 
4
 *   Copyright (c) 2010 - 2012
 
5
 *   Canonical Ltd.
 
6
 *
 
7
 *   This program is free software; you can redistribute it and/or
 
8
 *   modify it under the terms of version 2 of the GNU General Public
 
9
 *   License published by the Free Software Foundation.
 
10
 *
 
11
 *   This program is distributed in the hope that it will be useful,
 
12
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 *   GNU General Public License for more details.
 
15
 *
 
16
 *   You should have received a copy of the GNU General Public License
 
17
 *   along with this program; if not, contact Canonical, Ltd.
 
18
 */
 
19
 
 
20
/* Definitions section */
 
21
/* %option main */
 
22
 
 
23
/* eliminates need to link with libfl */
 
24
%option noyywrap
 
25
%option nounput
 
26
%option stack
 
27
 
 
28
%{
 
29
#include <stdio.h>
 
30
#include <stdlib.h>
 
31
#include <string.h>
 
32
#include <libintl.h>
 
33
#include <sys/types.h>
 
34
#include <sys/stat.h>
 
35
#include <unistd.h>
 
36
#include <dirent.h>
 
37
#define _(s) gettext(s)
 
38
 
 
39
#include "parser.h"
 
40
#include "parser_include.h"
 
41
#include "parser_yacc.h"
 
42
 
 
43
#ifdef PDEBUG
 
44
#undef PDEBUG
 
45
#endif
 
46
/* #define DEBUG */
 
47
#ifdef DEBUG
 
48
#define PDEBUG(fmt, args...) printf("Lexer (state %d): " fmt, YY_START, ## args)
 
49
#else
 
50
#define PDEBUG(fmt, args...)    /* Do nothing */
 
51
#endif
 
52
#define NPDEBUG(fmt, args...)   /* Do nothing */
 
53
 
 
54
#define DUMP_PREPROCESS do { if (preprocess_only) ECHO; } while (0)
 
55
 
 
56
#define YY_NO_INPUT
 
57
 
 
58
struct ignored_suffix_t {
 
59
        char * text;
 
60
        int len;
 
61
        int silent;
 
62
};
 
63
 
 
64
struct ignored_suffix_t ignored_suffixes[] = {
 
65
        /* Debian packging files, which are in flux during install
 
66
           should be silently ignored. */
 
67
        { ".dpkg-new", 9, 1 },
 
68
        { ".dpkg-old", 9, 1 },
 
69
        { ".dpkg-dist", 10, 1 },
 
70
        { ".dpkg-bak", 9, 1 },
 
71
        /* RPM packaging files have traditionally not been silently
 
72
           ignored */
 
73
        { ".rpmnew", 7, 0 },
 
74
        { ".rpmsave", 8, 0 },
 
75
        /* Backup files should be mentioned */
 
76
        { "~", 1, 0 },
 
77
        { NULL, 0, 0 }
 
78
};
 
79
 
 
80
void include_filename(char *filename, int search)
 
81
{
 
82
        FILE *include_file = NULL;
 
83
        struct stat my_stat;
 
84
        char *fullpath = NULL;
 
85
 
 
86
        if (search) {
 
87
                if (preprocess_only)
 
88
                        fprintf(yyout, "\n\n##included <%s>\n", filename);
 
89
                include_file = search_path(filename, &fullpath);
 
90
        } else {
 
91
                if (preprocess_only)
 
92
                        fprintf(yyout, "\n\n##included \"%s\"\n", filename);
 
93
                fullpath = strdup(filename);
 
94
                include_file = fopen(fullpath, "r");
 
95
        }
 
96
 
 
97
        if (!include_file)
 
98
                yyerror(_("Could not open '%s'"),
 
99
                        fullpath ? fullpath: filename);
 
100
 
 
101
        if (fstat(fileno(include_file), &my_stat))
 
102
                yyerror(_("fstat failed for '%s'"), fullpath);
 
103
 
 
104
        if (S_ISREG(my_stat.st_mode)) {
 
105
                yyin = include_file;
 
106
                update_mru_tstamp(include_file);
 
107
                PDEBUG("Opened include \"%s\"\n", fullpath);
 
108
                push_include_stack(fullpath);
 
109
                yypush_buffer_state(yy_create_buffer( yyin, YY_BUF_SIZE ));
 
110
        }
 
111
 
 
112
        if (S_ISDIR(my_stat.st_mode)) {
 
113
                DIR *dir = NULL;
 
114
                char *dirent_path = NULL;
 
115
                struct dirent *dirent;
 
116
 
 
117
                PDEBUG("Opened include directory \"%s\"\n", fullpath);
 
118
                if (!(dir = opendir(fullpath)))
 
119
                        yyerror(_("opendir failed '%s'"), fullpath);
 
120
                fclose(include_file);
 
121
                include_file = NULL;
 
122
 
 
123
                while ((dirent = readdir(dir)) != NULL) {
 
124
                        int name_len;
 
125
                        struct ignored_suffix_t *suffix;
 
126
                        /* skip dotfiles silently. */
 
127
                        if (dirent->d_name[0] == '.')
 
128
                                continue;
 
129
 
 
130
                        if (dirent_path)
 
131
                                free(dirent_path);
 
132
                        if (asprintf(&dirent_path, "%s/%s", fullpath, dirent->d_name) < 0)
 
133
                                yyerror("Out of memory");
 
134
 
 
135
                        name_len = strlen(dirent->d_name);
 
136
                        /* skip blacklisted suffixes */
 
137
                        for (suffix = ignored_suffixes; suffix->text; suffix++) {
 
138
                                char *found;
 
139
                                if ( (found = strstr(dirent->d_name, suffix->text)) &&
 
140
                                     found - dirent->d_name + suffix->len == name_len ) {
 
141
                                        name_len = 0;
 
142
                                        if (!suffix->silent)
 
143
                                                PERROR("Ignoring: '%s'\n", dirent_path);
 
144
                                        break;
 
145
                                }
 
146
                        }
 
147
                        if (!name_len) continue;
 
148
 
 
149
                        if (stat(dirent_path, &my_stat))
 
150
                                yyerror(_("stat failed for '%s'"), dirent_path);
 
151
                        if (S_ISREG(my_stat.st_mode)) {
 
152
                                if (!(yyin = fopen(dirent_path,"r")))
 
153
                                        yyerror(_("Could not open '%s' in '%s'"), dirent_path, filename);
 
154
                                PDEBUG("Opened include \"%s\" in \"%s\"\n", dirent_path, filename);
 
155
                                update_mru_tstamp(yyin);
 
156
                                push_include_stack(dirent_path);
 
157
                                yypush_buffer_state(yy_create_buffer(yyin, YY_BUF_SIZE));
 
158
                        }
 
159
                }
 
160
                if (dirent_path)
 
161
                        free(dirent_path);
 
162
                closedir(dir);
 
163
        }
 
164
 
 
165
        if (fullpath)
 
166
                free(fullpath);
 
167
}
 
168
 
 
169
%}
 
170
 
 
171
CARET           "^"
 
172
OPEN_BRACE      \{
 
173
CLOSE_BRACE     \}
 
174
SLASH           \/
 
175
COLON           :
 
176
END_OF_RULE     [,]
 
177
RANGE           -
 
178
MODE_CHARS      ([RrWwaLlMmkXx])|(([Pp]|[Cc])[Xx])|(([Pp]|[Cc])?([IiUu])[Xx])
 
179
MODES           {MODE_CHARS}+
 
180
WS              [[:blank:]]
 
181
NUMBER          [[:digit:]]+
 
182
 
 
183
ID_CHARS        [^ \t\n"!,]
 
184
ID              {ID_CHARS}|(,{ID_CHARS})
 
185
IDS             {ID}+
 
186
POST_VAR_ID_CHARS       [^ \t\n"!,]{-}[=\+]
 
187
POST_VAR_ID     {POST_VAR_ID_CHARS}|(,{POST_VAR_ID_CHARS})
 
188
LIST_VALUE_ID_CHARS     [^ \t\n"!,]{-}[()]
 
189
LIST_VALUE_ID   {LIST_VALUE_ID_CHARS}+
 
190
ID_CHARS_NOEQ   [^ \t\n"!,]{-}[=]
 
191
ID_NOEQ         {ID_CHARS_NOEQ}|(,{ID_CHARS_NOEQ})
 
192
IDS_NOEQ        {ID_NOEQ}+
 
193
ALLOWED_QUOTED_ID       [^\0"]|\\\"
 
194
QUOTED_ID       \"{ALLOWED_QUOTED_ID}*\"
 
195
 
 
196
IP              {NUMBER}\.{NUMBER}\.{NUMBER}\.{NUMBER}
 
197
 
 
198
HAT             hat{WS}*
 
199
PROFILE         profile{WS}*
 
200
KEYWORD         [[:alpha:]_]+
 
201
VARIABLE_NAME   [[:alpha:]][[:alnum:]_]*
 
202
SET_VAR_PREFIX  @
 
203
SET_VARIABLE    {SET_VAR_PREFIX}(\{{VARIABLE_NAME}\}|{VARIABLE_NAME})
 
204
BOOL_VARIABLE   $(\{{VARIABLE_NAME}\}|{VARIABLE_NAME})
 
205
 
 
206
PATHNAME        (\/|{SET_VARIABLE}{POST_VAR_ID}){ID}*
 
207
QPATHNAME       \"(\/|{SET_VAR_PREFIX})([^\0"]|\\\")*\"
 
208
 
 
209
OPEN_PAREN      \(
 
210
CLOSE_PAREN     \)
 
211
COMMA           \,
 
212
EQUALS          =
 
213
ADD_ASSIGN      \+=
 
214
ARROW           ->
 
215
LT_EQUAL        <=
 
216
 
 
217
%x SUB_ID
 
218
%x SUB_VALUE
 
219
%x EXTCOND_MODE
 
220
%x NETWORK_MODE
 
221
%x LIST_VAL_MODE
 
222
%x ASSIGN_MODE
 
223
%x RLIMIT_MODE
 
224
%x MOUNT_MODE
 
225
%x CHANGE_PROFILE_MODE
 
226
%x INCLUDE
 
227
 
 
228
%%
 
229
 
 
230
%{
 
231
/* Copied directly into yylex function */
 
232
        if (parser_token) {
 
233
                int t = parser_token;
 
234
                parser_token = 0;
 
235
                return t;
 
236
        }
 
237
%}
 
238
 
 
239
<INCLUDE>{
 
240
        {WS}+   { /* Eat whitespace */ }
 
241
        \<([^\> \t\n]+)\>       {       /* <filename> */
 
242
                char *filename = strdup(yytext);
 
243
                filename[strlen(filename) - 1] = '\0';
 
244
                include_filename(filename + 1, 1);
 
245
                free(filename);
 
246
                yy_pop_state();
 
247
                }
 
248
 
 
249
        \"([^\" \t\n]+)\"       {       /* "filename" */
 
250
                char *filename = strdup(yytext);
 
251
                filename[strlen(filename) - 1] = '\0';
 
252
                include_filename(filename + 1, 0);
 
253
                free(filename);
 
254
                yy_pop_state();
 
255
                }
 
256
 
 
257
        [^\<\>\"{WS}]+ {        /* filename */
 
258
                include_filename(yytext, 0);
 
259
                yy_pop_state();
 
260
                }
 
261
}
 
262
 
 
263
<<EOF>> {
 
264
        fclose(yyin);
 
265
        pop_include_stack();
 
266
        yypop_buffer_state();
 
267
        if ( !YY_CURRENT_BUFFER ) yyterminate();
 
268
}
 
269
 
 
270
<INITIAL,MOUNT_MODE>{
 
271
        {VARIABLE_NAME}/{WS}*=  {
 
272
                                /* we match to the = in the lexer so that
 
273
                                 * can switch scanner state.  By the time
 
274
                                 * the parser see the = it may be to late
 
275
                                 * as bison may have requested the next
 
276
                                 * token from the scanner
 
277
                                 */
 
278
                                PDEBUG("conditional %s=\n", yytext);
 
279
                                yylval.id = processid(yytext, yyleng);
 
280
                                yy_push_state(EXTCOND_MODE);
 
281
                                return TOK_CONDID;
 
282
                        }
 
283
}
 
284
 
 
285
<SUB_ID>{
 
286
        ({IDS}|{QUOTED_ID})     {
 
287
                          /* Ugh, this is a gross hack. I used to use
 
288
                           * {IDS} to match all TOK_IDs, but that would
 
289
                           * also match TOK_MODE + TOK_END_OF_RULE
 
290
                           * without any spaces in between (because it's
 
291
                           * a longer match). So now, when I want to
 
292
                           * match any random string, I go into a
 
293
                           * separate state. */
 
294
                        DUMP_PREPROCESS;
 
295
                        yylval.id =  processid(yytext, yyleng);
 
296
                        PDEBUG("Found sub name: \"%s\"\n",  yylval.id);
 
297
                        yy_pop_state();
 
298
                        return TOK_ID;
 
299
                }
 
300
 
 
301
        [^\n]   {
 
302
                        DUMP_PREPROCESS;
 
303
                        /* Something we didn't expect */
 
304
                        yyerror(_("Found unexpected character: '%s'"), yytext);
 
305
                }
 
306
}
 
307
 
 
308
<SUB_VALUE>{
 
309
        ({IDS}|{QUOTED_ID})     {
 
310
                          /* Ugh, this is a gross hack. I used to use
 
311
                           * {IDS} to match all TOK_IDs, but that would
 
312
                           * also match TOK_MODE + TOK_END_OF_RULE
 
313
                           * without any spaces in between (because it's
 
314
                           * a longer match). So now, when I want to
 
315
                           * match any random string, I go into a
 
316
                           * separate state. */
 
317
                        DUMP_PREPROCESS;
 
318
                        yylval.id =  processid(yytext, yyleng);
 
319
                        PDEBUG("Found sub value: \"%s\"\n",  yylval.id);
 
320
                        yy_pop_state();
 
321
                        return TOK_VALUE;
 
322
                }
 
323
 
 
324
        [^\n]   {
 
325
                        DUMP_PREPROCESS;
 
326
                        /* Something we didn't expect */
 
327
                        yyerror(_("Found unexpected character: '%s'"), yytext);
 
328
                }
 
329
}
 
330
 
 
331
<LIST_VAL_MODE>{
 
332
        {CLOSE_PAREN}   {
 
333
                        DUMP_PREPROCESS;
 
334
                        PDEBUG("listval: )\n");
 
335
                        yy_pop_state();
 
336
                        return TOK_CLOSEPAREN;
 
337
                        }
 
338
 
 
339
        {WS}+           { DUMP_PREPROCESS; /* Eat whitespace */ }
 
340
 
 
341
        {COMMA} {
 
342
                        DUMP_PREPROCESS;
 
343
                        PDEBUG("listval: , \n");
 
344
                        /* East comma, its an optional separator */
 
345
                        }
 
346
 
 
347
        ({LIST_VALUE_ID}|{QUOTED_ID})   {
 
348
                        DUMP_PREPROCESS;
 
349
                        yylval.id = processid(yytext, yyleng);
 
350
                        PDEBUG("listval: \"%s\"\n", yylval.id);
 
351
                        return TOK_VALUE;
 
352
                        }
 
353
 
 
354
        [^\n]           {
 
355
                        DUMP_PREPROCESS;
 
356
                        /* Something we didn't expect */
 
357
                        yyerror(_("Found unexpected character: '%s'"), yytext);
 
358
                        }
 
359
}
 
360
 
 
361
<EXTCOND_MODE>{
 
362
        {WS}+           { DUMP_PREPROCESS; /* Eat whitespace */ }
 
363
 
 
364
        {EQUALS}{WS}*/[^(\n]{-}{WS}     {
 
365
                        DUMP_PREPROCESS;
 
366
                        BEGIN(SUB_VALUE);
 
367
                        return TOK_EQUALS;
 
368
                }
 
369
 
 
370
        {EQUALS}        {
 
371
                        DUMP_PREPROCESS;
 
372
                        return TOK_EQUALS;
 
373
                }
 
374
 
 
375
        {OPEN_PAREN}    {
 
376
                        DUMP_PREPROCESS;
 
377
                        PDEBUG("extcond listv\n");
 
378
                        /* Don't push state here as this is a transition
 
379
                         * start condition and we want to return to the start
 
380
                         * condition that invoked <EXTCOND_MODE> when
 
381
                         * LIST_VAL_ID is done
 
382
                         */
 
383
                        BEGIN(LIST_VAL_MODE);
 
384
                        return TOK_OPENPAREN;
 
385
                }
 
386
 
 
387
        [^\n]   {
 
388
                        DUMP_PREPROCESS;
 
389
                        /* Something we didn't expect */
 
390
                        yyerror(_("Found unexpected character: '%s' %d"), yytext, *yytext);
 
391
                }
 
392
 
 
393
}
 
394
 
 
395
<ASSIGN_MODE>{
 
396
        {WS}+           { DUMP_PREPROCESS; /* Eat whitespace */ }
 
397
 
 
398
        ({IDS}|{QUOTED_ID})             {
 
399
                        DUMP_PREPROCESS;
 
400
                        yylval.var_val = processid(yytext, yyleng);
 
401
                        PDEBUG("Found assignment value: \"%s\"\n", yylval.var_val);
 
402
                        return TOK_VALUE;
 
403
                        }
 
404
 
 
405
        {END_OF_RULE}   {
 
406
                        DUMP_PREPROCESS;
 
407
                        yylval.id = strdup(yytext);
 
408
                        yyerror(_("Variable declarations do not accept trailing commas"));
 
409
                        }
 
410
 
 
411
        \\\n            { DUMP_PREPROCESS; current_lineno++ ; }
 
412
 
 
413
        \r?\n           {
 
414
                        DUMP_PREPROCESS;
 
415
                        current_lineno++;
 
416
                        yy_pop_state();
 
417
                        }
 
418
        [^\n]           {
 
419
                        DUMP_PREPROCESS;
 
420
                        /* Something we didn't expect */
 
421
                        yyerror(_("Found unexpected character: '%s'"), yytext);
 
422
                        }
 
423
}
 
424
 
 
425
<NETWORK_MODE>{
 
426
        {WS}+           { DUMP_PREPROCESS; /* Eat whitespace */ }
 
427
 
 
428
        {IDS}           {
 
429
                        DUMP_PREPROCESS;
 
430
                        yylval.id = strdup(yytext);
 
431
                        return TOK_ID;
 
432
                        }
 
433
        {END_OF_RULE}   {
 
434
                        DUMP_PREPROCESS;
 
435
                        yy_pop_state();
 
436
                        return TOK_END_OF_RULE;
 
437
                }
 
438
        [^\n]           {
 
439
                        DUMP_PREPROCESS;
 
440
                          /* Something we didn't expect */
 
441
                        yylval.id = strdup(yytext);
 
442
                        yyerror(_("(network_mode) Found unexpected character: '%s'"), yylval.id);
 
443
                        }
 
444
 
 
445
        \r?\n           {
 
446
                        DUMP_PREPROCESS;
 
447
                        current_lineno++;
 
448
                        }
 
449
}
 
450
 
 
451
<CHANGE_PROFILE_MODE>{
 
452
        {ARROW}         {
 
453
                        DUMP_PREPROCESS;
 
454
                        PDEBUG("Matched a change profile arrow\n");
 
455
                        return TOK_ARROW;
 
456
                        }
 
457
 
 
458
        ({IDS}|{QUOTED_ID})     {
 
459
                          /* Ugh, this is a gross hack. I used to use
 
460
                           * {IDS} to match all TOK_IDs, but that would
 
461
                           * also match TOK_MODE + TOK_END_OF_RULE
 
462
                           * without any spaces in between (because it's
 
463
                           * a longer match). So now, when I want to
 
464
                           * match any random string, I go into a
 
465
                           * separate state. */
 
466
                        DUMP_PREPROCESS;
 
467
                        yylval.id = processid(yytext, yyleng);
 
468
                        PDEBUG("Found change profile name: \"%s\"\n", yylval.id);
 
469
                        yy_pop_state();
 
470
                        return TOK_ID;
 
471
                }
 
472
 
 
473
        {WS}+                   {  DUMP_PREPROCESS; /* Ignoring whitespace */ }
 
474
        [^\n]   {
 
475
                        DUMP_PREPROCESS;
 
476
                        /* Something we didn't expect */
 
477
                        yyerror(_("Found unexpected character: '%s'"), yytext);
 
478
                }
 
479
}
 
480
 
 
481
<RLIMIT_MODE>{
 
482
        {WS}+           { DUMP_PREPROCESS; /* Eat whitespace */ }
 
483
 
 
484
 
 
485
        -?{NUMBER}[[:alpha:]]*  {
 
486
                        DUMP_PREPROCESS;
 
487
                        yylval.var_val = strdup(yytext);
 
488
                        return TOK_VALUE;
 
489
                        }
 
490
 
 
491
        {KEYWORD}       {
 
492
                        DUMP_PREPROCESS;
 
493
                        yylval.id = strdup(yytext);
 
494
                        if (strcmp(yytext, "infinity") == 0)
 
495
                                return TOK_VALUE;
 
496
                        return TOK_ID;
 
497
                        }
 
498
 
 
499
        {LT_EQUAL}      { DUMP_PREPROCESS; return TOK_LE; }
 
500
 
 
501
        {END_OF_RULE}   {
 
502
                        DUMP_PREPROCESS;
 
503
                        yy_pop_state();
 
504
                        return TOK_END_OF_RULE;
 
505
                        }
 
506
 
 
507
        \\\n            {
 
508
                        DUMP_PREPROCESS;
 
509
                        current_lineno++;
 
510
                        yy_pop_state();
 
511
                        }
 
512
 
 
513
        \r?\n           {
 
514
                        DUMP_PREPROCESS;
 
515
                        current_lineno++;
 
516
                        yy_pop_state();
 
517
                        }
 
518
}
 
519
 
 
520
<MOUNT_MODE>{
 
521
        {WS}+           {  DUMP_PREPROCESS; /* Ignoring whitespace */ }
 
522
 
 
523
        {ARROW}         {
 
524
                        DUMP_PREPROCESS;
 
525
                        PDEBUG("Matched arrow\n");
 
526
                        return TOK_ARROW;
 
527
                        }
 
528
 
 
529
        ({IDS_NOEQ}|{PATHNAME}|{QUOTED_ID})     {
 
530
                        DUMP_PREPROCESS;
 
531
                        yylval.id = processid(yytext, yyleng);
 
532
                        PDEBUG("Found ID: \"%s\"\n", yylval.id);
 
533
                        return TOK_ID;
 
534
                        }
 
535
 
 
536
        {END_OF_RULE}   {
 
537
                        DUMP_PREPROCESS;
 
538
                        yy_pop_state();
 
539
                        return TOK_END_OF_RULE;
 
540
                        }
 
541
 
 
542
        [^\n]           {
 
543
                        DUMP_PREPROCESS;
 
544
                        /* Something we didn't expect */
 
545
                        yyerror(_("Found unexpected character: '%s'"), yytext);
 
546
                        }
 
547
 
 
548
        \r?\n           {
 
549
                        DUMP_PREPROCESS;
 
550
                        current_lineno++;
 
551
                        yy_pop_state();
 
552
                        }
 
553
}
 
554
 
 
555
#include/.*\r?\n         { /* include */
 
556
                        PDEBUG("Matched #include\n");
 
557
                        yy_push_state(INCLUDE);
 
558
                        }
 
559
 
 
560
#.*\r?\n                { /* normal comment */
 
561
                        DUMP_PREPROCESS;
 
562
                        PDEBUG("comment(%d): %s\n", current_lineno, yytext);
 
563
                        current_lineno++;
 
564
                        }
 
565
 
 
566
{END_OF_RULE}           { DUMP_PREPROCESS; return TOK_END_OF_RULE; }
 
567
 
 
568
{CARET}                 {
 
569
                        DUMP_PREPROCESS;
 
570
                        PDEBUG("Matched hat ^\n");
 
571
                        yy_push_state(SUB_ID);
 
572
                        return TOK_CARET;
 
573
                        }
 
574
{ARROW}                 {
 
575
                        DUMP_PREPROCESS;
 
576
                        PDEBUG("Matched a arrow\n");
 
577
                        return TOK_ARROW;
 
578
                        }
 
579
{EQUALS}                {
 
580
                        DUMP_PREPROCESS;
 
581
                        PDEBUG("Matched equals for assignment\n");
 
582
                        yy_push_state(ASSIGN_MODE);
 
583
                        return TOK_EQUALS;
 
584
                        }
 
585
{ADD_ASSIGN}            {
 
586
                        DUMP_PREPROCESS;
 
587
                        PDEBUG("Matched additive value assignment\n");
 
588
                        yy_push_state(ASSIGN_MODE);
 
589
                        return TOK_ADD_ASSIGN;
 
590
                        }
 
591
{SET_VARIABLE}          {
 
592
                        DUMP_PREPROCESS;
 
593
                        yylval.set_var = strdup(yytext);
 
594
                        PDEBUG("Found set variable %s\n", yylval.set_var);
 
595
                        return TOK_SET_VAR;
 
596
                        }
 
597
 
 
598
{BOOL_VARIABLE}         {
 
599
                        DUMP_PREPROCESS;
 
600
                        yylval.bool_var = strdup(yytext);
 
601
                        PDEBUG("Found boolean variable %s\n", yylval.bool_var);
 
602
                        return TOK_BOOL_VAR;
 
603
                        }
 
604
 
 
605
{OPEN_BRACE}            {
 
606
                        DUMP_PREPROCESS;
 
607
                        PDEBUG("Open Brace\n");
 
608
                        return TOK_OPEN;
 
609
                        }
 
610
{CLOSE_BRACE}           {
 
611
                        DUMP_PREPROCESS;
 
612
                        PDEBUG("Close Brace\n");
 
613
                        return TOK_CLOSE;
 
614
                        }
 
615
 
 
616
({PATHNAME}|{QPATHNAME})                {
 
617
                        DUMP_PREPROCESS;
 
618
                        yylval.id = processid(yytext, yyleng);
 
619
                        PDEBUG("Found id: \"%s\"\n", yylval.id);
 
620
                        return TOK_ID;
 
621
                        }
 
622
 
 
623
({MODES})/([[:space:],])        {
 
624
                        DUMP_PREPROCESS;
 
625
                        yylval.mode = strdup(yytext);
 
626
                        PDEBUG("Found modes: %s\n", yylval.mode);
 
627
                        return TOK_MODE;
 
628
                        }
 
629
 
 
630
{HAT}                   {
 
631
                        DUMP_PREPROCESS;
 
632
                        yy_push_state(SUB_ID);
 
633
                        return TOK_HAT;
 
634
                        }
 
635
 
 
636
{PROFILE}               {
 
637
                        DUMP_PREPROCESS;
 
638
                        yy_push_state(SUB_ID);
 
639
                        return TOK_PROFILE;
 
640
                        }
 
641
 
 
642
{COLON}                 {
 
643
                        DUMP_PREPROCESS;
 
644
                        PDEBUG("Found a colon\n");
 
645
                        return TOK_COLON;
 
646
                        }
 
647
 
 
648
{OPEN_PAREN}    {
 
649
                        DUMP_PREPROCESS;
 
650
                        PDEBUG("listval (\n");
 
651
                        yy_push_state(LIST_VAL_MODE);
 
652
                        return TOK_OPENPAREN;
 
653
                        }
 
654
 
 
655
{VARIABLE_NAME}         {
 
656
                        DUMP_PREPROCESS;
 
657
                        int token = get_keyword_token(yytext);
 
658
 
 
659
                        /* special cases */
 
660
                        switch (token) {
 
661
                        case -1:
 
662
                                /* no token found */
 
663
                                yylval.id = processunquoted(yytext, yyleng);
 
664
                                PDEBUG("Found (var) id: \"%s\"\n", yylval.id);
 
665
                                return TOK_ID;
 
666
                                break;
 
667
                        case TOK_RLIMIT:
 
668
                                yy_push_state(RLIMIT_MODE);
 
669
                                break;
 
670
                        case TOK_NETWORK:
 
671
                                yy_push_state(NETWORK_MODE);
 
672
                                break;
 
673
                        case TOK_CHANGE_PROFILE:
 
674
                                yy_push_state(CHANGE_PROFILE_MODE);
 
675
                                break;
 
676
                        case TOK_MOUNT:
 
677
                        case TOK_REMOUNT:
 
678
                        case TOK_UMOUNT:
 
679
                                DUMP_PREPROCESS;
 
680
                                PDEBUG("Entering mount\n");
 
681
                                yy_push_state(MOUNT_MODE);
 
682
                                break;
 
683
                        default: /* nothing */
 
684
                                break;
 
685
                        }
 
686
                        return token;
 
687
                        }
 
688
 
 
689
{WS}+                   {  DUMP_PREPROCESS; /* Ignoring whitespace */ }
 
690
 
 
691
\r?\n                   { DUMP_PREPROCESS; current_lineno++ ; }
 
692
 
 
693
[^\n]                   {
 
694
                        DUMP_PREPROCESS;
 
695
 
 
696
                          /* Something we didn't expect */
 
697
                        yyerror(_("Found unexpected character: '%s'"), yytext);
 
698
                        }
 
699
 
 
700
%%