~ubuntu-branches/ubuntu/hardy/apparmor/hardy-proposed

« back to all changes in this revision

Viewing changes to changehat/libapparmor/src/grammar.y

  • Committer: Bazaar Package Importer
  • Author(s): Mathias Gug
  • Date: 2007-09-11 10:44:56 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20070911104456-2a2vwe4wb0hxbc53
Tags: 2.1+961-0ubuntu1
* New upstream version.
  * Support resolvconf. Fix LP: #132468.
* Move package maintainance to bzr:
  * Apply all patches directly into the tree with dpatch apply-all.
  * debian/patches/: remove all patches as they are applied inline now.
  * debian/control, debian/control.modules.in: remove dpatch from
    Build Depends.
  * debian/rules:
    * remove dpatch include.
    * remove patch and unpatch dependencies
* debian/control:
  * Rename libapparmor-dev to libapparmor1-dev.
    Add Provides: and Conflict: tags.
  * Remove universe component in Section tag.
  * Remove apparmor-utils depends on bsdutils.
  * Update apparmor-modules Recommends to apparmor-modules-2.1.
* utils/:
  * Add audit man page.
* Fix mod_appamor library: remove rpath info.
  * debian/rules: remove rpath info.
  * debian/control: add chrpath as a build dependency.
* Remove apparmor-modules-source package:
  * debian/conrol: remove apparmor-modules-source package.
  * debian/apparmor.postinst, debian/apparmor.preinst,
    debian/apparmor.prerm: remove error_handler function.
  * debian/rules: remove error_handler option from dh_installinit.
  * debian/apparmor-modules-_KVERS_.postinst.modules.in,
    debian/control.modules.in: remove control and postinst files.

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
 *
 
5
 *   This program is free software; you can redistribute it and/or
 
6
 *   modify it under the terms of version 2 of the GNU General Public
 
7
 *   License published by the Free Software Foundation.
 
8
 *
 
9
 *   This program 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
 
12
 *   GNU General Public License for more details.
 
13
 *
 
14
 *   You should have received a copy of the GNU General Public License
 
15
 *   along with this program; if not, contact Novell, Inc.
 
16
 */
 
17
 
 
18
 
 
19
%{
 
20
 
 
21
#define YYDEBUG 0
 
22
#include <string.h>
 
23
#include "aalogparse.h"
 
24
#include "parser.h"
 
25
#include "grammar.h"
 
26
#include "scanner.h"
 
27
 
 
28
aa_log_record *ret_record;
 
29
void aalogparse_error(void *scanner, char const *s)
 
30
{
 
31
        printf("Error: %s\n", s);
 
32
}
 
33
%}
 
34
 
 
35
%defines
 
36
%pure_parser
 
37
%lex-param{void *scanner}
 
38
%parse-param{void *scanner}
 
39
 
 
40
%union
 
41
{
 
42
        char    *t_str;
 
43
        long    t_long;
 
44
}
 
45
 
 
46
%type <t_str> old_profile;
 
47
%token <t_long> TOK_DIGITS
 
48
%token <t_str> TOK_QUOTED_STRING TOK_PATH TOK_ID TOK_NULL_COMPLAIN TOK_MODE TOK_SINGLE_QUOTED_STRING TOK_AUDIT_DIGITS
 
49
 
 
50
%token TOK_EQUALS
 
51
%token TOK_COLON
 
52
%token TOK_OPEN_PAREN
 
53
%token TOK_CLOSE_PAREN
 
54
%token TOK_PERIOD
 
55
 
 
56
%token TOK_TYPE_REJECT
 
57
%token TOK_TYPE_AUDIT
 
58
%token TOK_TYPE_COMPLAIN
 
59
%token TOK_TYPE_HINT
 
60
%token TOK_TYPE_STATUS
 
61
%token TOK_TYPE_ERROR
 
62
%token TOK_OLD_TYPE_APPARMOR
 
63
%token TOK_OLD_APPARMOR_REJECT
 
64
%token TOK_OLD_APPARMOR_PERMIT
 
65
%token TOK_OLD_APPARMOR_LOGPROF_HINT
 
66
%token TOK_OLD_UNKNOWN_HAT
 
67
%token TOK_OLD_ACTIVE
 
68
%token TOK_OLD_UNKNOWN_PROFILE
 
69
%token TOK_OLD_MISSING_PROFILE
 
70
%token TOK_OLD_ACCESS
 
71
%token TOK_OLD_TO
 
72
%token TOK_OLD_PIPE
 
73
%token TOK_OLD_EXTENDED
 
74
%token TOK_OLD_ATTRIBUTE
 
75
%token TOK_OLD_ON
 
76
%token TOK_OLD_MKDIR
 
77
%token TOK_OLD_RMDIR
 
78
%token TOK_OLD_XATTR
 
79
%token TOK_OLD_CHANGE
 
80
%token TOK_OLD_CAPABILITY
 
81
%token TOK_OLD_FORK
 
82
%token TOK_OLD_CHILD
 
83
 
 
84
%token TOK_KEY_TYPE
 
85
%token TOK_KEY_MSG
 
86
%token TOK_KEY_OPERATION
 
87
%token TOK_KEY_NAME
 
88
%token TOK_KEY_NAME2
 
89
%token TOK_KEY_DENIED_MASK
 
90
%token TOK_KEY_REQUESTED_MASK
 
91
%token TOK_KEY_ATTRIBUTE
 
92
%token TOK_KEY_TASK
 
93
%token TOK_KEY_PARENT
 
94
%token TOK_KEY_MAGIC_TOKEN
 
95
%token TOK_KEY_INFO
 
96
%token TOK_KEY_PID
 
97
%token TOK_KEY_PROFILE
 
98
%token TOK_AUDIT
 
99
%token TOK_KEY_IMAGE
 
100
%token TOK_KEY_FAMILY
 
101
%token TOK_KEY_SOCK_TYPE
 
102
%token TOK_KEY_PROTOCOL
 
103
 
 
104
%%
 
105
 
 
106
type: TOK_KEY_TYPE TOK_EQUALS type_syntax ;
 
107
 
 
108
type_syntax: old_syntax { ret_record->version = AA_RECORD_SYNTAX_V1; }
 
109
         | new_syntax { ret_record->version = AA_RECORD_SYNTAX_V2; }
 
110
        ;
 
111
 
 
112
old_syntax: TOK_OLD_TYPE_APPARMOR audit_msg old_msg ;
 
113
 
 
114
new_syntax: 
 
115
          TOK_TYPE_REJECT audit_msg key { ret_record->event = AA_RECORD_DENIED; }
 
116
        | TOK_TYPE_AUDIT audit_msg key { ret_record->event = AA_RECORD_AUDIT; }
 
117
        | TOK_TYPE_COMPLAIN audit_msg key { ret_record->event = AA_RECORD_ALLOWED; }
 
118
        | TOK_TYPE_HINT audit_msg key { ret_record->event = AA_RECORD_HINT; }
 
119
        | TOK_TYPE_STATUS audit_msg key { ret_record->event = AA_RECORD_STATUS; }
 
120
        | TOK_TYPE_ERROR audit_msg key { ret_record->event = AA_RECORD_ERROR; }
 
121
        ;
 
122
 
 
123
old_msg:
 
124
          old_permit_reject_syntax old_permit_reject_syntax2
 
125
        | TOK_OLD_APPARMOR_LOGPROF_HINT old_logprof_syntax { ret_record->event = AA_RECORD_HINT; }
 
126
        ;
 
127
 
 
128
old_permit_reject_syntax:
 
129
          TOK_OLD_APPARMOR_REJECT { ret_record->event = AA_RECORD_DENIED; }
 
130
        | TOK_OLD_APPARMOR_PERMIT { ret_record->event = AA_RECORD_ALLOWED; }
 
131
        ;
 
132
 
 
133
old_permit_reject_syntax2:
 
134
          TOK_MODE TOK_OLD_ACCESS old_permit_reject_path_pipe_extended
 
135
                TOK_OPEN_PAREN TOK_ID TOK_OPEN_PAREN TOK_ID TOK_CLOSE_PAREN
 
136
                TOK_KEY_PROFILE old_profile TOK_OLD_ACTIVE old_profile TOK_CLOSE_PAREN
 
137
        {
 
138
                ret_record->requested_mask = strdup($1);
 
139
                free($1);
 
140
                ret_record->info = strdup($5);
 
141
                free($5);
 
142
                ret_record->pid = atol($7);
 
143
                free($7);
 
144
                ret_record->profile = strdup($10);
 
145
                free($10);
 
146
                ret_record->active_hat = strdup($12);
 
147
                free($12);
 
148
                ret_record->operation = strdup("access");
 
149
        }
 
150
        | mkdir_or_rmdir TOK_OLD_ON TOK_PATH
 
151
                TOK_OPEN_PAREN TOK_ID TOK_OPEN_PAREN TOK_ID TOK_CLOSE_PAREN
 
152
                TOK_KEY_PROFILE old_profile TOK_OLD_ACTIVE old_profile TOK_CLOSE_PAREN
 
153
        {
 
154
                ret_record->name = strdup($3);
 
155
                free($3);
 
156
                ret_record->info = strdup($5);
 
157
                free($5);
 
158
                ret_record->pid = atol($7);
 
159
                free($7);
 
160
                ret_record->profile = strdup($10);
 
161
                free($10);
 
162
                ret_record->active_hat = strdup($12);
 
163
                free($12);
 
164
        }
 
165
        | TOK_OLD_XATTR TOK_ID TOK_OLD_ON TOK_PATH
 
166
                TOK_OPEN_PAREN TOK_ID TOK_OPEN_PAREN TOK_ID TOK_CLOSE_PAREN
 
167
                TOK_KEY_PROFILE old_profile TOK_OLD_ACTIVE old_profile TOK_CLOSE_PAREN
 
168
        {
 
169
                ret_record->operation = strdup("xattr");
 
170
                ret_record->attribute = strdup($2);
 
171
                free($2);
 
172
                ret_record->name = strdup($4);
 
173
                free($4);
 
174
                ret_record->info = strdup($6);
 
175
                free($6);
 
176
                ret_record->pid = atol($8);
 
177
                free($8);
 
178
                ret_record->profile = strdup($11);
 
179
                free($11);
 
180
                ret_record->active_hat = strdup($13);
 
181
                free($13);
 
182
        }
 
183
        | TOK_KEY_ATTRIBUTE TOK_OPEN_PAREN TOK_ID TOK_CLOSE_PAREN
 
184
                TOK_OLD_CHANGE TOK_OLD_TO TOK_PATH
 
185
                TOK_OPEN_PAREN TOK_ID TOK_OPEN_PAREN TOK_ID TOK_CLOSE_PAREN
 
186
                TOK_KEY_PROFILE old_profile TOK_OLD_ACTIVE old_profile TOK_CLOSE_PAREN
 
187
        {
 
188
                ret_record->operation = strdup("setattr");
 
189
                ret_record->attribute = strdup($3);
 
190
                free($3);
 
191
                ret_record->name = strdup($7);
 
192
                free($7);
 
193
                ret_record->info = strdup($9);
 
194
                free($9);
 
195
                ret_record->pid = atol($11);
 
196
                free($11);
 
197
                ret_record->profile = strdup($14);
 
198
                free($14);
 
199
                ret_record->active_hat = strdup($16);
 
200
                free($16);
 
201
        }
 
202
        | TOK_OLD_ACCESS TOK_OLD_TO TOK_OLD_CAPABILITY TOK_SINGLE_QUOTED_STRING
 
203
                TOK_OPEN_PAREN TOK_ID TOK_OPEN_PAREN TOK_ID TOK_CLOSE_PAREN
 
204
                TOK_KEY_PROFILE old_profile TOK_OLD_ACTIVE old_profile TOK_CLOSE_PAREN
 
205
        {
 
206
                ret_record->operation = strdup("capability");
 
207
                ret_record->name = strdup($4);
 
208
                free($4);
 
209
                ret_record->info = strdup($6);
 
210
                free($6);
 
211
                ret_record->pid = atol($8);
 
212
                free($8);
 
213
                ret_record->profile = strdup($11);
 
214
                free($11);
 
215
                ret_record->active_hat = strdup($13);
 
216
                free($13);
 
217
        }
 
218
        ;
 
219
 
 
220
mkdir_or_rmdir:
 
221
          TOK_OLD_MKDIR { ret_record->operation = strdup("mkdir"); }
 
222
        | TOK_OLD_RMDIR { ret_record->operation = strdup("rmdir"); }
 
223
        ;
 
224
 
 
225
old_permit_reject_path_pipe_extended:
 
226
          TOK_OLD_TO TOK_PATH
 
227
                {
 
228
                        ret_record->name = strdup($2);
 
229
                        free($2);
 
230
                }
 
231
        | TOK_OLD_TO TOK_OLD_PIPE /* Frankly, I don't think this is used */
 
232
                {
 
233
                        ret_record->info = strdup("pipe");
 
234
                }
 
235
        | TOK_OLD_EXTENDED TOK_KEY_ATTRIBUTE /* Nor this */
 
236
                {
 
237
                        ret_record->info = strdup("extended attribute");
 
238
                }
 
239
        ;
 
240
old_logprof_syntax:
 
241
                  old_logprof_syntax2 TOK_KEY_PID TOK_EQUALS TOK_DIGITS 
 
242
                        TOK_KEY_PROFILE TOK_EQUALS old_profile TOK_OLD_ACTIVE TOK_EQUALS old_profile
 
243
                        {
 
244
                                ret_record->pid = $4;
 
245
                                ret_record->profile = strdup($7);
 
246
                                free($7);
 
247
                                ret_record->active_hat = strdup($10);
 
248
                                free($10);
 
249
                        }
 
250
                | old_logprof_fork_syntax
 
251
                ;
 
252
 
 
253
old_logprof_syntax2:
 
254
          TOK_OLD_UNKNOWN_PROFILE TOK_KEY_IMAGE TOK_EQUALS TOK_ID
 
255
                {
 
256
                        ret_record->operation = strdup("profile_set");
 
257
                        ret_record->info = strdup("unknown profile");
 
258
                        ret_record->name = strdup($4);
 
259
                        free($4);
 
260
                }
 
261
        | TOK_OLD_MISSING_PROFILE TOK_KEY_IMAGE TOK_EQUALS TOK_ID 
 
262
                {
 
263
                        ret_record->operation = strdup("exec");
 
264
                        ret_record->info = strdup("mandatory profile missing");
 
265
                        ret_record->name = strdup($4);
 
266
                        free($4);
 
267
                }
 
268
        | TOK_OLD_UNKNOWN_HAT TOK_ID
 
269
                {
 
270
                        ret_record->operation = strdup("change_hat");
 
271
                        ret_record->name = strdup($2); 
 
272
                        free($2);
 
273
                        ret_record->info = strdup("unknown_hat");
 
274
                }
 
275
        ;
 
276
 
 
277
/* TODO: Clean this up */
 
278
old_logprof_fork_syntax:
 
279
          TOK_OLD_FORK TOK_KEY_PID TOK_EQUALS TOK_DIGITS
 
280
                TOK_OLD_CHILD TOK_EQUALS TOK_DIGITS old_logprof_fork_addition
 
281
        {
 
282
                ret_record->operation = strdup("clone");
 
283
                ret_record->task = $7;
 
284
                ret_record->pid = $4;
 
285
        }
 
286
        ;
 
287
 
 
288
old_logprof_fork_addition:
 
289
        /* Nothin */
 
290
        | TOK_KEY_PROFILE TOK_EQUALS old_profile TOK_OLD_ACTIVE TOK_EQUALS old_profile
 
291
        {
 
292
                ret_record->profile = strdup($3);
 
293
                free($3);
 
294
                ret_record->active_hat = strdup($6);
 
295
                free($6);
 
296
        }
 
297
        ;
 
298
 
 
299
old_profile:
 
300
          TOK_PATH
 
301
                {
 
302
                        $$ = strdup($1);
 
303
                        free($1);
 
304
                }
 
305
        | TOK_NULL_COMPLAIN
 
306
                {
 
307
                        $$ = strdup("null-complain-profile");
 
308
                }
 
309
        ;
 
310
 
 
311
audit_msg: TOK_KEY_MSG TOK_EQUALS TOK_AUDIT TOK_OPEN_PAREN TOK_AUDIT_DIGITS TOK_PERIOD TOK_AUDIT_DIGITS TOK_COLON TOK_AUDIT_DIGITS TOK_CLOSE_PAREN TOK_COLON
 
312
        {
 
313
                asprintf(&ret_record->audit_id, "%s.%s:%s", $5, $7, $9);
 
314
                ret_record->epoch = atol($5);
 
315
                ret_record->audit_sub_id = atoi($9);
 
316
                free($5);
 
317
                free($7);
 
318
                free($9);
 
319
        } ;
 
320
 
 
321
key:
 
322
          key_list
 
323
        | key key_list
 
324
        ;
 
325
 
 
326
key_list: TOK_KEY_OPERATION TOK_EQUALS TOK_QUOTED_STRING
 
327
        { ret_record->operation = strdup($3); free($3); }
 
328
        | TOK_KEY_NAME TOK_EQUALS TOK_QUOTED_STRING
 
329
        { ret_record->name = strdup($3); free($3); }
 
330
        | TOK_KEY_NAME2 TOK_EQUALS TOK_QUOTED_STRING
 
331
        { ret_record->name2 = strdup($3); free($3); }
 
332
        | TOK_KEY_DENIED_MASK TOK_EQUALS TOK_QUOTED_STRING
 
333
        { ret_record->denied_mask = strdup($3); free($3);}
 
334
        | TOK_KEY_REQUESTED_MASK TOK_EQUALS TOK_QUOTED_STRING
 
335
        { ret_record->requested_mask = strdup($3); free($3);}
 
336
        | TOK_KEY_ATTRIBUTE TOK_EQUALS TOK_QUOTED_STRING 
 
337
        { ret_record->attribute = strdup($3); free($3);}
 
338
        | TOK_KEY_TASK TOK_EQUALS TOK_QUOTED_STRING
 
339
        { ret_record->task = atol($3); free($3);}
 
340
        | TOK_KEY_PARENT TOK_EQUALS TOK_QUOTED_STRING
 
341
        { ret_record->parent = strdup($3); free($3);}
 
342
        | TOK_KEY_MAGIC_TOKEN TOK_EQUALS TOK_DIGITS
 
343
        { ret_record->magic_token = $3;}
 
344
        | TOK_KEY_INFO TOK_EQUALS TOK_QUOTED_STRING
 
345
        { ret_record->info = strdup($3); free($3);}
 
346
        | TOK_KEY_PID TOK_EQUALS TOK_DIGITS
 
347
        { ret_record->pid = $3;}
 
348
        | TOK_KEY_PROFILE TOK_EQUALS TOK_QUOTED_STRING
 
349
        { ret_record->profile = strdup($3); free($3);}
 
350
        | TOK_KEY_FAMILY TOK_EQUALS TOK_QUOTED_STRING
 
351
        { ret_record->net_family = strdup($3); free($3);}
 
352
        | TOK_KEY_SOCK_TYPE TOK_EQUALS TOK_QUOTED_STRING
 
353
        { ret_record->net_sock_type = strdup($3); free($3); }
 
354
        | TOK_KEY_PROTOCOL TOK_EQUALS TOK_QUOTED_STRING
 
355
        { ret_record->net_protocol = strdup($3); free($3);}
 
356
        ;
 
357
 
 
358
%%
 
359
 
 
360
aa_log_record *
 
361
_parse_yacc(char *str)
 
362
{
 
363
        /* yydebug = 1;  */
 
364
        YY_BUFFER_STATE lex_buf;
 
365
        yyscan_t scanner;
 
366
        int parser_return;
 
367
 
 
368
        ret_record = NULL;
 
369
        ret_record = (aa_log_record *) malloc(sizeof(aa_log_record));
 
370
 
 
371
        _init_log_record(ret_record);
 
372
 
 
373
        if (ret_record == NULL)
 
374
                return NULL;
 
375
 
 
376
        aalogparse_lex_init(&scanner);
 
377
        lex_buf = aalogparse__scan_string(str, scanner);
 
378
        parser_return = aalogparse_parse(scanner);
 
379
        aalogparse__delete_buffer(lex_buf, scanner);
 
380
        aalogparse_lex_destroy(scanner);
 
381
        return ret_record;
 
382
}