~ubuntu-branches/ubuntu/saucy/apparmor/saucy

« back to all changes in this revision

Viewing changes to .pc/0054-libaalogparse-Parse-dbus-daemon-audit-messages.patch/libraries/libapparmor/src/grammar.y

  • Committer: Package Import Robot
  • Author(s): Tyler Hicks, Tyler Hicks, Jamie Strandboge
  • Date: 2013-08-26 15:32:12 UTC
  • mfrom: (49.1.6 saucy-proposed)
  • Revision ID: package-import@ubuntu.com-20130826153212-5oehf9eda64lkpze
Tags: 2.8.0-0ubuntu25
[ Tyler Hicks ]
* Add support for mediation of D-Bus messages and services. AppArmor D-Bus
  rules are described in the apparmor.d(5) man page. dbus-daemon will use
  libapparmor to perform queries against the AppArmor policies to determine
  if a connection should be able to send messages to another connection, if
  a connection should be able to receive messages from another connection,
  and if a connection should be able to bind to a well-known name.
  - 0042-Fix-mount-rule-preprocessor-output.patch,
    0043-libapparmor-Safeguard-aa_getpeercon-buffer-reallocat.patch,
    0044-libapparmor-fix-return-value-of-aa_getpeercon_raw.patch,
    0045-libapparmor-Move-mode-parsing-into-separate-function.patch,
    0046-libapparmor-Parse-mode-from-confinement-string-in-ge.patch,
    0047-libapparmor-Make-aa_getpeercon_raw-similar-to-aa_get.patch,
    0048-libapparmor-Update-aa_getcon-man-page-to-reflect-get.patch:
    Backport parser and libapparmor pre-requisites for D-Bus mediation
  - 0049-parser-Update-man-page-for-DBus-rules.patch: Update apparmor.d man
    page
  - 0050-parser-Add-support-for-DBus-rules.patch,
    0051-parser-Regression-tests-for-DBus-rules.patch,
    0052-parser-Binary-profile-equality-tests-for-DBus-rules.patch: Add
    apparmor_parser support for D-Bus mediation rules
  - 0053-libapparmor-Export-a-label-based-query-interface.patch,
    debian/libapparmor1.symbols: Provide the libapparmor interface necessary
    for trusted helpers to make security decisions based upon AppArmor
    policy
  - 0054-libaalogparse-Parse-dbus-daemon-audit-messages.patch,
    0055-libaalogparse-Regression-tests-for-dbus-daemon-audit.patch: Allow
    applications to parse denials, generated by dbus-daemon, using
    libaalogparse and add a set of regression tests
  - 0056-tests-Add-an-optional-final-check-to-checktestfg.patch,
    0057-tests-Add-required-features-check.patch,
    0058-tests-Add-regression-tests-for-dbus.patch: Add regression tests
    which start their own dbus-daemon, load profiles containing D-Bus rules,
    and confine simple D-Bus service and client applications
  - 0059-dbus-rules-for-dbus-abstractions.patch: Add bus-specific, but
    otherwise permissive, D-Bus rules to the dbus and dbus-session
    abstractions. Confined applications that use D-Bus should already be
    including these abstractions in their profiles so this should be a
    seamless transition for those profiles.
* 0060-utils-make_clean_fixup.patch: Clean up the Python cache in the
  AppArmor tests directory
* 0061-profiles-dnsmasq-needs-dbus-abstraction.patch: Dnsmasq uses the
  system D-Bus when it is started with --enable-dbus, so its AppArmor
  profile needs to include the system bus abstraction
* 0062-fix-clone-test-on-arm.patch: Fix compiler error when building
  regression tests on ARM
* 0063-utils-ignore-unsupported-rules.patch: Utilities that use the
  Immunix::AppArmor perl module, such as aa-logprof and aa-genprof, error
  out when they encounter rules unsupported by the perl module. This patch
  ignores unsupported rules.

[ Jamie Strandboge ]
* debian/control: don't have easyprof Depends on apparmor-easyprof-ubuntu

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (c) 1999-2008 NOVELL (All rights reserved)
 
3
 * Copyright (c) 2010, Canonical, Ltd.
 
4
 *
 
5
 * This program is free software; you can redistribute it and/or
 
6
 * modify it under the terms of version 2.1 of the GNU Lesser General
 
7
 * Public 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 Lesser General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU Lesser General Public License
 
15
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
16
 */
 
17
 
 
18
 
 
19
%{
 
20
 
 
21
/* set the following to non-zero to get bison to emit debugging
 
22
 * information about tokens given and rules matched. */
 
23
#define YYDEBUG 0
 
24
#include <string.h>
 
25
#include "aalogparse.h"
 
26
#include "parser.h"
 
27
#include "grammar.h"
 
28
#include "scanner.h"
 
29
 
 
30
aa_log_record *ret_record;
 
31
 
 
32
/* Since we're a library, on any errors we don't want to print out any
 
33
 * error messages. We should probably add a debug interface that does
 
34
 * emit messages when asked for. */
 
35
void aalogparse_error(void *scanner, char const *s)
 
36
{
 
37
        //printf("ERROR: %s\n", s);
 
38
        ret_record->event = AA_RECORD_INVALID;
 
39
}
 
40
 
 
41
struct aa_type_table {
 
42
        unsigned int audit_type;
 
43
        aa_record_event_type event;
 
44
};
 
45
 
 
46
static struct aa_type_table aa_type_table[] = {
 
47
        {AUDIT_APPARMOR_AUDIT,   AA_RECORD_AUDIT},
 
48
        {AUDIT_APPARMOR_ALLOWED, AA_RECORD_ALLOWED},
 
49
        {AUDIT_APPARMOR_DENIED,  AA_RECORD_DENIED},
 
50
        {AUDIT_APPARMOR_HINT,    AA_RECORD_HINT},
 
51
        {AUDIT_APPARMOR_STATUS,  AA_RECORD_STATUS},
 
52
        {AUDIT_APPARMOR_ERROR,   AA_RECORD_ERROR},
 
53
        {0,                      AA_RECORD_INVALID},
 
54
};
 
55
 
 
56
aa_record_event_type lookup_aa_event(unsigned int type)
 
57
{
 
58
        int i;
 
59
 
 
60
        for (i = 0; aa_type_table[i].audit_type != 0; i++)
 
61
                if (type == aa_type_table[i].audit_type)
 
62
                        break;
 
63
 
 
64
        return aa_type_table[i].event;
 
65
}
 
66
 
 
67
 
 
68
%}
 
69
 
 
70
%defines
 
71
%pure_parser
 
72
%lex-param{void *scanner}
 
73
%parse-param{void *scanner}
 
74
 
 
75
%union
 
76
{
 
77
        char    *t_str;
 
78
        long    t_long;
 
79
}
 
80
 
 
81
%type <t_str> safe_string protocol
 
82
%token <t_long> TOK_DIGITS TOK_TYPE_UNKNOWN
 
83
%token <t_str> TOK_QUOTED_STRING TOK_ID TOK_MODE TOK_DMESG_STAMP
 
84
%token <t_str> TOK_AUDIT_DIGITS TOK_DATE_MONTH TOK_DATE_TIME
 
85
%token <t_str> TOK_HEXSTRING TOK_TYPE_OTHER TOK_MSG_REST
 
86
%token <t_str> TOK_IP_ADDR
 
87
 
 
88
%token TOK_EQUALS
 
89
%token TOK_COLON
 
90
%token TOK_MINUS
 
91
%token TOK_OPEN_PAREN
 
92
%token TOK_CLOSE_PAREN
 
93
%token TOK_PERIOD
 
94
 
 
95
%token TOK_TYPE_REJECT
 
96
%token TOK_TYPE_AUDIT
 
97
%token TOK_TYPE_COMPLAIN
 
98
%token TOK_TYPE_HINT
 
99
%token TOK_TYPE_STATUS
 
100
%token TOK_TYPE_ERROR
 
101
%token TOK_TYPE_AA_REJECT
 
102
%token TOK_TYPE_AA_AUDIT
 
103
%token TOK_TYPE_AA_COMPLAIN
 
104
%token TOK_TYPE_AA_HINT
 
105
%token TOK_TYPE_AA_STATUS
 
106
%token TOK_TYPE_AA_ERROR
 
107
%token TOK_TYPE_LSM_AVC
 
108
 
 
109
%token TOK_KEY_APPARMOR
 
110
%token TOK_KEY_TYPE
 
111
%token TOK_KEY_MSG
 
112
%token TOK_KEY_OPERATION
 
113
%token TOK_KEY_NAME
 
114
%token TOK_KEY_NAME2
 
115
%token TOK_KEY_DENIED_MASK
 
116
%token TOK_KEY_REQUESTED_MASK
 
117
%token TOK_KEY_ATTRIBUTE
 
118
%token TOK_KEY_TASK
 
119
%token TOK_KEY_PARENT
 
120
%token TOK_KEY_MAGIC_TOKEN
 
121
%token TOK_KEY_INFO
 
122
%token TOK_KEY_PID
 
123
%token TOK_KEY_PROFILE
 
124
%token TOK_AUDIT
 
125
%token TOK_KEY_FAMILY
 
126
%token TOK_KEY_SOCK_TYPE
 
127
%token TOK_KEY_PROTOCOL
 
128
%token TOK_KEY_NAMESPACE
 
129
%token TOK_KEY_ERROR
 
130
%token TOK_KEY_FSUID
 
131
%token TOK_KEY_OUID
 
132
%token TOK_KEY_COMM
 
133
%token TOK_KEY_CAPABILITY
 
134
%token TOK_KEY_CAPNAME
 
135
%token TOK_KEY_OFFSET
 
136
%token TOK_KEY_TARGET
 
137
%token TOK_KEY_LADDR
 
138
%token TOK_KEY_FADDR
 
139
%token TOK_KEY_LPORT
 
140
%token TOK_KEY_FPORT
 
141
 
 
142
%token TOK_SYSLOG_KERNEL
 
143
 
 
144
%%
 
145
 
 
146
log_message: audit_type
 
147
        | syslog_type
 
148
        | audit_dispatch
 
149
        ;
 
150
 
 
151
audit_type: TOK_KEY_TYPE TOK_EQUALS type_syntax ;
 
152
 
 
153
type_syntax: new_syntax { ret_record->version = AA_RECORD_SYNTAX_V2; }
 
154
        | other_audit
 
155
        ;
 
156
 
 
157
new_syntax:
 
158
          TOK_TYPE_AA_REJECT audit_msg key_list { ret_record->event = AA_RECORD_DENIED; }
 
159
        | TOK_TYPE_AA_AUDIT audit_msg key_list { ret_record->event = AA_RECORD_AUDIT; }
 
160
        | TOK_TYPE_AA_COMPLAIN audit_msg key_list { ret_record->event = AA_RECORD_ALLOWED; }
 
161
        | TOK_TYPE_AA_HINT audit_msg key_list { ret_record->event = AA_RECORD_HINT; }
 
162
        | TOK_TYPE_AA_STATUS audit_msg key_list { ret_record->event = AA_RECORD_STATUS; }
 
163
        | TOK_TYPE_AA_ERROR audit_msg key_list { ret_record->event = AA_RECORD_ERROR; }
 
164
        | TOK_TYPE_UNKNOWN audit_msg key_list { ret_record->event = lookup_aa_event($1); }
 
165
        | TOK_TYPE_LSM_AVC audit_msg key_list
 
166
        ;
 
167
 
 
168
other_audit: TOK_TYPE_OTHER audit_msg TOK_MSG_REST
 
169
        {
 
170
                ret_record->operation = $1;
 
171
                ret_record->event = AA_RECORD_INVALID;
 
172
                ret_record->info = $3;
 
173
        }
 
174
        ;
 
175
 
 
176
syslog_type:
 
177
          syslog_date TOK_ID TOK_SYSLOG_KERNEL audit_id key_list
 
178
          { ret_record->version = AA_RECORD_SYNTAX_V2; }
 
179
        | syslog_date TOK_ID TOK_SYSLOG_KERNEL key_type audit_id key_list
 
180
          { ret_record->version = AA_RECORD_SYNTAX_V2; }
 
181
        | syslog_date TOK_ID TOK_SYSLOG_KERNEL TOK_DMESG_STAMP audit_id key_list
 
182
          { ret_record->version = AA_RECORD_SYNTAX_V2; }
 
183
        | syslog_date TOK_ID TOK_SYSLOG_KERNEL TOK_DMESG_STAMP key_type audit_id key_list
 
184
          { ret_record->version = AA_RECORD_SYNTAX_V2; }
 
185
        ;
 
186
 
 
187
/* when audit dispatches a message it doesn't prepend the audit type string */
 
188
audit_dispatch:
 
189
        audit_msg key_list { ret_record->version = AA_RECORD_SYNTAX_V2; }
 
190
        ;
 
191
 
 
192
audit_msg: TOK_KEY_MSG TOK_EQUALS audit_id
 
193
        ;
 
194
 
 
195
audit_id: TOK_AUDIT TOK_OPEN_PAREN TOK_AUDIT_DIGITS TOK_PERIOD TOK_AUDIT_DIGITS TOK_COLON TOK_AUDIT_DIGITS TOK_CLOSE_PAREN TOK_COLON
 
196
        {
 
197
                if (!asprintf(&ret_record->audit_id, "%s.%s:%s", $3, $5, $7))
 
198
                        yyerror(scanner, YY_("Out of memory"));
 
199
                ret_record->epoch = atol($3);
 
200
                ret_record->audit_sub_id = atoi($7);
 
201
                free($3);
 
202
                free($5);
 
203
                free($7);
 
204
        } ;
 
205
 
 
206
syslog_date: TOK_DATE_MONTH TOK_DIGITS TOK_DATE_TIME { /* do nothing? */ }
 
207
        ;
 
208
 
 
209
key_list: key
 
210
        | key_list key
 
211
        ;
 
212
 
 
213
key: TOK_KEY_OPERATION TOK_EQUALS TOK_QUOTED_STRING
 
214
        { ret_record->operation = $3;}
 
215
        | TOK_KEY_NAME TOK_EQUALS safe_string
 
216
        { ret_record->name = $3;}
 
217
        | TOK_KEY_NAMESPACE TOK_EQUALS safe_string
 
218
        { ret_record->namespace = $3;}
 
219
        | TOK_KEY_NAME2 TOK_EQUALS safe_string
 
220
        { ret_record->name2 = $3;}
 
221
        | TOK_KEY_DENIED_MASK TOK_EQUALS TOK_QUOTED_STRING
 
222
        { ret_record->denied_mask = $3;}
 
223
        | TOK_KEY_REQUESTED_MASK TOK_EQUALS TOK_QUOTED_STRING
 
224
        { ret_record->requested_mask = $3;}
 
225
        | TOK_KEY_ATTRIBUTE TOK_EQUALS TOK_QUOTED_STRING
 
226
        { ret_record->attribute = $3;}
 
227
        | TOK_KEY_TASK TOK_EQUALS TOK_DIGITS
 
228
        { ret_record->task = $3;}
 
229
        | TOK_KEY_PARENT TOK_EQUALS TOK_DIGITS
 
230
        { ret_record->parent = $3;}
 
231
        | TOK_KEY_MAGIC_TOKEN TOK_EQUALS TOK_DIGITS
 
232
        { ret_record->magic_token = $3;}
 
233
        | TOK_KEY_INFO TOK_EQUALS TOK_QUOTED_STRING
 
234
        { ret_record->info = $3;}
 
235
        | key_pid
 
236
        | TOK_KEY_PROFILE TOK_EQUALS safe_string
 
237
        { ret_record->profile = $3;}
 
238
        | TOK_KEY_FAMILY TOK_EQUALS TOK_QUOTED_STRING
 
239
        { ret_record->net_family = $3;}
 
240
        | TOK_KEY_SOCK_TYPE TOK_EQUALS TOK_QUOTED_STRING
 
241
        { ret_record->net_sock_type = $3;}
 
242
        | TOK_KEY_PROTOCOL TOK_EQUALS protocol
 
243
        { ret_record->net_protocol = $3;}
 
244
        | TOK_KEY_TYPE TOK_EQUALS TOK_DIGITS
 
245
        { ret_record->event = lookup_aa_event($3);}
 
246
        | TOK_KEY_ERROR TOK_EQUALS TOK_DIGITS
 
247
        { ret_record->error_code = $3;}
 
248
        | TOK_KEY_ERROR TOK_EQUALS TOK_MINUS TOK_DIGITS
 
249
        { ret_record->error_code = $4;}
 
250
        | TOK_KEY_FSUID TOK_EQUALS TOK_DIGITS
 
251
        { ret_record->fsuid = $3;}
 
252
        | TOK_KEY_OUID TOK_EQUALS TOK_DIGITS
 
253
        { ret_record->ouid = $3;}
 
254
        | TOK_KEY_COMM TOK_EQUALS safe_string
 
255
        { ret_record->comm = $3;}
 
256
        | TOK_KEY_APPARMOR TOK_EQUALS apparmor_event
 
257
        | TOK_KEY_CAPABILITY TOK_EQUALS TOK_DIGITS
 
258
        { /* need to reverse map number to string, need to figure out
 
259
           * how to get auto generation of reverse mapping table into
 
260
           * autotools Makefile.  For now just drop assumming capname is
 
261
           * present which it should be with current kernels */
 
262
        }
 
263
        | TOK_KEY_CAPNAME TOK_EQUALS TOK_QUOTED_STRING
 
264
        { /* capname used to be reported in name */
 
265
          ret_record->name = $3;
 
266
        }
 
267
        | TOK_KEY_OFFSET TOK_EQUALS TOK_DIGITS
 
268
        { /* offset is used for reporting where an error occured unpacking
 
269
           * loaded policy.  We can just drop this currently
 
270
           */
 
271
        }
 
272
        | TOK_KEY_TARGET TOK_EQUALS safe_string
 
273
        { /* target was always name2 in the past */
 
274
          ret_record->name2 = $3;
 
275
        }
 
276
        | TOK_KEY_LADDR TOK_EQUALS TOK_IP_ADDR
 
277
        { ret_record->net_local_addr = $3;}
 
278
        | TOK_KEY_FADDR TOK_EQUALS TOK_IP_ADDR
 
279
        { ret_record->net_foreign_addr = $3;}
 
280
        | TOK_KEY_LPORT TOK_EQUALS TOK_DIGITS
 
281
        { ret_record->net_local_port = $3;}
 
282
        | TOK_KEY_FPORT TOK_EQUALS TOK_DIGITS
 
283
        { ret_record->net_foreign_port = $3;}
 
284
        | TOK_MSG_REST
 
285
        {
 
286
                ret_record->event = AA_RECORD_INVALID;
 
287
                ret_record->info = $1;
 
288
        }
 
289
        ;
 
290
 
 
291
apparmor_event:
 
292
          TOK_TYPE_REJECT       { ret_record->event = AA_RECORD_DENIED; }
 
293
        | TOK_TYPE_AUDIT        { ret_record->event = AA_RECORD_AUDIT; }
 
294
        | TOK_TYPE_COMPLAIN     { ret_record->event = AA_RECORD_ALLOWED; }
 
295
        | TOK_TYPE_HINT         { ret_record->event = AA_RECORD_HINT; }
 
296
        | TOK_TYPE_STATUS       { ret_record->event = AA_RECORD_STATUS; }
 
297
        | TOK_TYPE_ERROR        { ret_record->event = AA_RECORD_ERROR; }
 
298
        ;
 
299
 
 
300
key_pid: TOK_KEY_PID TOK_EQUALS TOK_DIGITS { ret_record->pid = $3; }
 
301
        ;
 
302
 
 
303
key_type: TOK_KEY_TYPE TOK_EQUALS TOK_DIGITS { ret_record->event = lookup_aa_event($3); }
 
304
        ;
 
305
 
 
306
safe_string: TOK_QUOTED_STRING
 
307
        | TOK_HEXSTRING
 
308
        ;
 
309
 
 
310
protocol: TOK_QUOTED_STRING
 
311
        | TOK_DIGITS
 
312
        { /* FIXME: this should probably convert back to a string proto name */
 
313
          $$ = ipproto_to_string($1);
 
314
        }
 
315
        ;
 
316
%%
 
317
 
 
318
aa_log_record *
 
319
_parse_yacc(char *str)
 
320
{
 
321
        /* yydebug = 1;  */
 
322
        YY_BUFFER_STATE lex_buf;
 
323
        yyscan_t scanner;
 
324
        int parser_return;
 
325
 
 
326
        ret_record = NULL;
 
327
        ret_record = (aa_log_record *) malloc(sizeof(aa_log_record));
 
328
 
 
329
        _init_log_record(ret_record);
 
330
 
 
331
        if (ret_record == NULL)
 
332
                return NULL;
 
333
 
 
334
#if (YYDEBUG != 0)
 
335
        yydebug = 1;
 
336
#endif
 
337
 
 
338
        aalogparse_lex_init(&scanner);
 
339
        lex_buf = aalogparse__scan_string(str, scanner);
 
340
        parser_return = aalogparse_parse(scanner);
 
341
        aalogparse__delete_buffer(lex_buf, scanner);
 
342
        aalogparse_lex_destroy(scanner);
 
343
        return ret_record;
 
344
}