]> git.pld-linux.org Git - packages/apparmor-parser.git/blob - apparmor-parser-bzr.patch
- rel 4; bzr fixes
[packages/apparmor-parser.git] / apparmor-parser-bzr.patch
1 === modified file 'libraries/libapparmor/swig/perl/Makefile.am'
2 --- libraries/libapparmor/swig/perl/Makefile.am 2009-05-12 21:56:56 +0000
3 +++ libraries/libapparmor/swig/perl/Makefile.am 2010-03-16 22:00:26 +0000
4 @@ -1,7 +1,8 @@
5  EXTRA_DIST =Makefile.PL libapparmor_wrap.c LibAppArmor.pm examples/*.pl
6 +
7 +if HAVE_PERL
8  noinst_DATA =LibAppArmor.so
9  
10 -if HAVE_PERL
11  libapparmor_wrap.c: $(srcdir)/../SWIG/libapparmor.i
12         $(SWIG) -perl -I$(srcdir)/../../src -module LibAppArmor -o $@ $(srcdir)/../SWIG/libapparmor.i
13  
14 @@ -27,4 +28,4 @@
15  #rm -f Makefile.perl Makefile.perl.old
16         rm -f *.so # *.o
17  
18 -endif
19 \ No newline at end of file
20 +endif
21
22 === modified file 'parser/Makefile'
23 --- parser/Makefile     2009-11-11 18:58:57 +0000
24 +++ parser/Makefile     2010-03-16 22:18:55 +0000
25 @@ -125,9 +125,20 @@
26  techdoc.txt: techdoc/index.html
27         w3m -dump $< > $@
28  
29 -all:   $(TOOLS) $(MANPAGES) ${HTMLMANPAGES} techdoc.pdf
30 +# targets arranged this way so that people who don't want full docs can
31 +# pick specific targets they want.
32 +main:  $(TOOLS)
33         $(Q)make -C po all
34 -       $(Q)make -s tests
35 +
36 +manpages:      $(MANPAGES)
37 +
38 +htmlmanpages:  $(HTMLMANPAGES)
39 +
40 +pdf:   techdoc.pdf
41 +
42 +docs:  manpages htmlmanpages pdf
43 +
44 +all:   main docs tests
45  
46  apparmor_parser: $(OBJECTS) $(PCREOBJECTS) $(AAREOBJECTS)
47         rm -f ./libstdc++.a
48 @@ -191,7 +202,7 @@
49  af_names.h: /usr/include/bits/socket.h
50         LC_ALL=C sed -n -e '/$(__FILTER)/d' -e "s/^\#define[ \\t]\\+PF_\\([A-Z0-9_]\\+\\)[ \\t]\\+\\([0-9]\\+\\)\\(.*\\)\$$/#ifndef AF_\\1\\n#  define AF_\\1 \\2\\n#endif\\nAA_GEN_NET_ENT(\"\\L\\1\", \\UAF_\\1)\\n/p" $< > $@
51         LC_ALL=C sed -n -e "s/^\#define[ \\t]\\+PF_MAX[ \\t]\\+\\([0-9]\\+\\)[ \\t]\\+.*/#define AA_AF_MAX \\1\n/p" $< >> $@
52 -       cat $@
53 +       # cat $@
54  
55  cap_names.h: /usr/include/linux/capability.h
56         LC_ALL=C sed -n -e "/CAP_EMPTY_SET/d" -e "s/^\#define[ \\t]\\+CAP_\\([A-Z0-9_]\\+\\)[ \\t]\\+\\([0-9xa-f]\\+\\)\\(.*\\)\$$/\{\"\\L\\1\", \\UCAP_\\1\},/p" $< > $@
57 @@ -214,7 +225,7 @@
58  
59  .SILENT: tests
60  tests: ${TESTS}
61 -       for test in ${TESTS} ; do echo "*** running $${test}" && ./$${test} $(BUILD_OUTPUT) ; done
62 +       sh -e -c 'for test in ${TESTS} ; do echo "*** running $${test}" && ./$${test} $(BUILD_OUTPUT) ; done'
63         $(Q)make -s -C tst tests
64  
65  .SILENT: check
66
67 === modified file 'parser/apparmor_parser.pod'
68 --- parser/apparmor_parser.pod  2010-01-07 18:03:49 +0000
69 +++ parser/apparmor_parser.pod  2010-04-03 23:24:06 +0000
70 @@ -154,6 +154,33 @@
71  Given once, only checks the profiles to ensure syntactic correctness.
72  Given twice, dumps its interpretation of the profile for checking.
73  
74 +=item -D n, --dump=n
75 +
76 +Debug flag for dumping various structures and passes of policy compilation.
77 +A single dump flag can be specified per --dump option, but the dump flag
78 +can be passed multiple times.  Note progress flags tend to also imply
79 +the matching stats flag.
80 +
81 +  apparmor_parser --dump=dfa-stats --dump=trans-stats <file>
82 +
83 +Use --help=dump to see a full list of which dump flags are supported
84 +
85 +=item -O n, --optimize=n
86 +
87 +Set the optimization flags used by policy compilation.  A sinlge optimization
88 +flag can be toggled per -O option, but the optimize flag can be passed
89 +multiple times.  Turning off some phases of the optimization can make
90 +it so that policy can't complete compilation due to size constraints
91 +(it is entirely possible to create a dfa with millions of states that will
92 +take days or longer to compile).
93 +
94 +Note: The parser is set to use a balanced default set of flags, that
95 +will result in resonable compression but not take excessive amounts
96 +of time to complete.
97 +
98 +Use --help=optimize to see a full list of which optimization flags are
99 +supported.
100 +
101  =item -h, --help
102  
103  Give a quick reference guide.
104
105 === modified file 'parser/libapparmor_re/regexp.y'
106 --- parser/libapparmor_re/regexp.y      2010-02-01 07:21:00 +0000
107 +++ parser/libapparmor_re/regexp.y      2010-03-13 10:23:23 +0000
108 @@ -1715,7 +1715,9 @@
109                         Trans::iterator j = trans.find(*i);
110                         if (j != trans.end())
111                                 trans.erase(j);
112 +                       State *s = *i;
113                         states.erase(*i);
114 +                       delete(s);
115                 }
116         }
117  
118
119 === modified file 'parser/parser.h'
120 --- parser/parser.h     2010-02-17 20:21:52 +0000
121 +++ parser/parser.h     2010-03-12 23:26:32 +0000
122 @@ -4,6 +4,9 @@
123   *   Copyright (c) 1999, 2000, 2001, 2002, 2004, 2005, 2006, 2007
124   *   NOVELL (All rights reserved)
125   *
126 + *   Copyright (c) 2010
127 + *   Canonical, Ltd. (All rights reserved)
128 + *
129   *   This program is free software; you can redistribute it and/or
130   *   modify it under the terms of version 2 of the GNU General Public
131   *   License published by the Free Software Foundation.
132 @@ -14,7 +17,8 @@
133   *   GNU General Public License for more details.
134   *
135   *   You should have received a copy of the GNU General Public License
136 - *   along with this program; if not, contact Novell, Inc.
137 + *   along with this program; if not, contact Novell, Inc. or Canonical
138 + *   Ltd.
139   */
140  
141  #include <netinet/in.h>
142 @@ -280,12 +284,16 @@
143  extern void free_cod_entries(struct cod_entry *list);
144  
145  /* parser_symtab.c */
146 +struct set_value {;
147 +       char *val;
148 +       struct set_value *next;
149 +};
150  extern int add_boolean_var(const char *var, int boolean);
151  extern int get_boolean_var(const char *var);
152  extern int new_set_var(const char *var, const char *value);
153  extern int add_set_value(const char *var, const char *value);
154 -extern void *get_set_var(const char *var);
155 -extern char *get_next_set_value(void **context);
156 +extern struct set_value *get_set_var(const char *var);
157 +extern char *get_next_set_value(struct set_value **context);
158  extern void dump_symtab(void);
159  extern void dump_expanded_symtab(void);
160  void free_symtabs(void);
161 @@ -312,7 +320,7 @@
162  extern void add_hat_to_policy(struct codomain *policy, struct codomain *hat);
163  extern void add_entry_to_policy(struct codomain *policy, struct cod_entry *entry);
164  extern void post_process_nt_entries(struct codomain *cod);
165 -extern int post_process_policy(void);
166 +extern int post_process_policy(int debug_only);
167  extern int process_hat_regex(struct codomain *cod);
168  extern int process_hat_variables(struct codomain *cod);
169  extern int post_merge_rules(void);
170
171 === modified file 'parser/parser_lex.l'
172 --- parser/parser_lex.l 2010-03-09 05:49:16 +0000
173 +++ parser/parser_lex.l 2010-03-12 09:50:26 +0000
174 @@ -227,6 +227,7 @@
175  }
176  
177  <<EOF>> {
178 +       fclose(yyin);
179         yypop_buffer_state();
180         if ( !YY_CURRENT_BUFFER ) yyterminate();
181  }
182
183 === modified file 'parser/parser_main.c'
184 --- parser/parser_main.c        2010-01-28 01:20:13 +0000
185 +++ parser/parser_main.c        2010-04-03 22:41:40 +0000
186 @@ -4,6 +4,9 @@
187   *   Copyright (c) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
188   *   NOVELL (All rights reserved)
189   *
190 + *   Copyright (c) 2010
191 + *   Canonical, Ltd. (All rights reserved)
192 + *
193   *   This program is free software; you can redistribute it and/or
194   *   modify it under the terms of version 2 of the GNU General Public
195   *   License published by the Free Software Foundation.
196 @@ -14,7 +17,8 @@
197   *   GNU General Public License for more details.
198   *
199   *   You should have received a copy of the GNU General Public License
200 - *   along with this program; if not, contact Novell, Inc.
201 + *   along with this program; if not, contact Novell, Inc. or Canonical,
202 + *   Ltd.
203   */
204  
205  #include <stdio.h>
206 @@ -258,7 +262,7 @@
207                         break;
208                 case 'd':
209                         debug++;
210 -                       skip_cache = 1;
211 +                       skip_read_cache = 1;
212                         break;
213                 case 'h':
214                         if (!optarg) {
215 @@ -316,7 +320,7 @@
216                         subdomainbase = strndup(optarg, PATH_MAX);
217                         break;
218                 case 'D':
219 -                       skip_cache = 1;
220 +                       skip_read_cache = 1;
221                         if (!optarg) {
222                                 dump_vars = 1;
223                         } else if (strcmp(optarg, "variables") == 0) {
224 @@ -359,7 +363,7 @@
225                         }
226                         break;
227                 case 'O':
228 -                       skip_cache = 1;
229 +                       skip_read_cache = 1;
230                         if (strcmp(optarg, "0") == 0) {
231                                 dfaflags |= DFA_CONTROL_NO_TREE_NORMAL |
232                                         DFA_CONTROL_NO_TREE_SIMPLE |
233 @@ -812,7 +816,7 @@
234                 goto out;
235         }
236  
237 -       retval = post_process_policy();
238 +       retval = post_process_policy(debug);
239         if (retval != 0) {
240                 PERROR(_("%s: Errors found in file. Aborting.\n"), progname);
241                 goto out;
242
243 === modified file 'parser/parser_policy.c'
244 --- parser/parser_policy.c      2009-08-20 15:27:12 +0000
245 +++ parser/parser_policy.c      2010-03-12 23:26:32 +0000
246 @@ -4,6 +4,9 @@
247   *   Copyright (c) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
248   *   NOVELL (All rights reserved)
249   *
250 + *   Copyright (c) 2010
251 + *   Canonical, Ltd. (All rights reserved)
252 + *
253   *   This program is free software; you can redistribute it and/or
254   *   modify it under the terms of version 2 of the GNU General Public
255   *   License published by the Free Software Foundation.
256 @@ -14,7 +17,8 @@
257   *   GNU General Public License for more details.
258   *
259   *   You should have received a copy of the GNU General Public License
260 - *   along with this program; if not, contact Novell, Inc.
261 + *   along with this program; if not, contact Novell, Inc. or Canonical,
262 + *   Ltd.
263   */
264  
265  #include <stdio.h>
266 @@ -664,7 +668,7 @@
267         return ret;
268  }
269  
270 -int post_process_policy(void)
271 +int post_process_policy(int debug_only)
272  {
273         int retval = 0;
274  
275 @@ -696,11 +700,13 @@
276                 return retval;
277         }
278  
279 -       retval = post_process_regex();
280 -       if (retval != 0) {
281 -               PERROR(_("%s: Errors found during regex postprocess.  Aborting.\n"),
282 -                      progname);
283 -               return retval;
284 +       if (!debug_only) {
285 +               retval = post_process_regex();
286 +               if (retval != 0) {
287 +                       PERROR(_("%s: Errors found during regex postprocess.  Aborting.\n"),
288 +                              progname);
289 +                       return retval;
290 +               }
291         }
292  
293         return retval;
294
295 === modified file 'parser/parser_symtab.c'
296 --- parser/parser_symtab.c      2009-07-24 13:24:53 +0000
297 +++ parser/parser_symtab.c      2010-03-12 22:41:58 +0000
298 @@ -33,11 +33,6 @@
299         sd_set,
300  };
301  
302 -struct set_value {
303 -       char *val;
304 -       struct set_value *next;
305 -};
306 -
307  struct symtab {
308         char *var_name;
309         enum var_type type;
310 @@ -288,7 +283,7 @@
311  
312  /* returns a pointer to the value list, which should be used as the
313   * argument to the get_next_set_value() function. */
314 -void *get_set_var(const char *var)
315 +struct set_value *get_set_var(const char *var)
316  {
317         struct symtab *result;
318         struct set_value *valuelist = NULL;
319 @@ -321,16 +316,17 @@
320  }
321  
322  /* iterator to walk the list of set values */
323 -char *get_next_set_value(void **list)
324 +char *get_next_set_value(struct set_value **list)
325  {
326 -       struct set_value **valuelist = (struct set_value **) list;
327 +       struct set_value *next;
328         char *ret;
329  
330 -       if (!valuelist || !(*valuelist))
331 +       if (!list || !(*list))
332                 return NULL;
333  
334 -       ret = (*valuelist)->val;
335 -       (*valuelist) = (*valuelist)->next;
336 +       ret = (*list)->val;
337 +       next = (*list)->next;
338 +       (*list) = next;
339  
340         return ret;
341  }
342 @@ -569,7 +565,7 @@
343  {
344         int rc = 0;
345         int retval;
346 -       void *retptr;
347 +       struct set_value *retptr;
348         struct symtab *a, *b;
349  
350         a = new_symtab_entry("blah");
351
352 === modified file 'parser/parser_variable.c'
353 --- parser/parser_variable.c    2009-07-24 23:47:46 +0000
354 +++ parser/parser_variable.c    2010-03-12 23:20:22 +0000
355 @@ -124,7 +124,7 @@
356  
357  static int expand_entry_variables(struct cod_entry *entry)
358  {
359 -       void *valuelist;
360 +       struct set_value *valuelist;
361         int ret = TRUE;
362         char *value;
363         struct var_string *split_var;
364
365 === added file 'profiles/apparmor.d/abstractions/dbus-session'
366 --- profiles/apparmor.d/abstractions/dbus-session       1970-01-01 00:00:00 +0000
367 +++ profiles/apparmor.d/abstractions/dbus-session       2010-04-19 17:38:17 +0000
368 @@ -0,0 +1,14 @@
369 +# vim:syntax=apparmor
370 +# $Id$
371 +# ------------------------------------------------------------------
372 +#
373 +#    Copyright (C) 2010 Canonical Ltd.
374 +#
375 +#    This program is free software; you can redistribute it and/or
376 +#    modify it under the terms of version 2 of the GNU General Public
377 +#    License published by the Free Software Foundation.
378 +#
379 +# ------------------------------------------------------------------
380 +
381 +  #include <abstractions/dbus>
382 +  /usr/bin/dbus-launch Uxr,
383
384 === modified file 'profiles/apparmor.d/abstractions/php5'
385 --- profiles/apparmor.d/abstractions/php5       2010-01-03 21:16:38 +0000
386 +++ profiles/apparmor.d/abstractions/php5       2010-03-30 17:34:32 +0000
387 @@ -2,7 +2,7 @@
388  # ------------------------------------------------------------------
389  #
390  #    Copyright (C) 2002-2006 Novell/SUSE
391 -#    Copyright (C) 2009 Canonical, Ltd.
392 +#    Copyright (C) 2009-2010 Canonical Ltd.
393  #
394  #    This program is free software; you can redistribute it and/or
395  #    modify it under the terms of version 2 of the GNU General Public
396 @@ -11,13 +11,13 @@
397  # ------------------------------------------------------------------
398  
399    # shared snippets for config files
400 -  /etc/php5/{conf.d,apache2,cli,fastcgi}/ r,
401 -  /etc/php5/{conf.d,apache2,cli,fastcgi}/*.ini r,
402 +  /etc/php5/{conf.d,apache2,cli,fastcgi,cgi}/ r,
403 +  /etc/php5/{conf.d,apache2,cli,fastcgi,cgi}/*.ini r,
404  
405    # Xlibs
406    /usr/X11R6/lib{,32,64}/lib*.so* mr,
407    # php extensions
408 -  /usr/lib{64,}/php5/{libexec,extensions}/*.so mr,
409 +  /usr/lib{64,}/php5/*/*.so mr,
410  
411    # php5 session mmap socket
412    /var/lib/php5/session_mm_* rwlk,
413
414 === modified file 'profiles/apparmor.d/abstractions/samba'
415 --- profiles/apparmor.d/abstractions/samba      2009-11-04 20:25:42 +0000
416 +++ profiles/apparmor.d/abstractions/samba      2010-03-25 23:13:00 +0000
417 @@ -2,7 +2,7 @@
418  # $Id$
419  # ------------------------------------------------------------------
420  #
421 -#    Copyright (C) 2009 Canonical Ltd.
422 +#    Copyright (C) 2009-2010 Canonical Ltd.
423  #
424  #    This program is free software; you can redistribute it and/or
425  #    modify it under the terms of version 2 of the GNU General Public
426 @@ -12,7 +12,7 @@
427  
428    /etc/samba/smb.conf r,
429    /usr/share/samba/*.dat r,
430 -  /var/lib/samba/**.tdb rw,
431 +  /var/lib/samba/**.tdb rwk,
432    /var/log/samba/cores/* w,
433    /var/log/samba/log.* w,
434    /var/run/samba/*.tdb rw,
435
436 === modified file 'profiles/apparmor.d/abstractions/user-tmp'
437 --- profiles/apparmor.d/abstractions/user-tmp   2009-11-04 20:25:42 +0000
438 +++ profiles/apparmor.d/abstractions/user-tmp   2010-05-12 08:52:23 +0000
439 @@ -2,7 +2,7 @@
440  # ------------------------------------------------------------------
441  #
442  #    Copyright (C) 2002-2009 Novell/SUSE
443 -#    Copyright (C) 2009 Canonical Ltd.
444 +#    Copyright (C) 2009-2010 Canonical Ltd.
445  #
446  #    This program is free software; you can redistribute it and/or
447  #    modify it under the terms of version 2 of the GNU General Public
448 @@ -11,11 +11,11 @@
449  # ------------------------------------------------------------------
450  
451    # per-user tmp directories
452 -  @{HOME}/tmp/**  rwkl,
453 -  @{HOME}/tmp/    rw,
454 +  owner @{HOME}/tmp/**  rwkl,
455 +  owner @{HOME}/tmp/    rw,
456  
457    # global tmp directories
458 -  /var/tmp/**     rwkl,
459 -  /var/tmp/       rw,
460 -  /tmp/**         rwkl,
461 -  /tmp/           rw,
462 +  owner /var/tmp/**     rwkl,
463 +  owner /var/tmp/       rw,
464 +  owner /tmp/**         rwkl,
465 +  owner /tmp/           rw,
466
467 === modified file 'tests/regression/subdomain/prologue.inc'
468 --- tests/regression/subdomain/prologue.inc     2010-02-07 07:04:57 +0000
469 +++ tests/regression/subdomain/prologue.inc     2010-04-27 09:37:30 +0000
470 @@ -93,8 +93,10 @@
471  
472         while [ -h ${link} ]
473         do
474 -               if [ -x /usr/bin/readlink ] ; then 
475 -                       target=$(/usr/bin/readlink ${link})
476 +               if [ -x /usr/bin/readlink ] ; then
477 +                       target=$(/usr/bin/readlink -f ${link})
478 +               elif [ -x /bin/readlink ] ; then
479 +                       target=$(/bin/readlink -f ${link})
480                 else 
481                         # I'm sure there's a more perlish way to do this
482                         target=$( perl -e "printf (\"%s\n\", readlink(\"${link}\"));") 
483
484 === modified file 'tests/stress/parser/stress.rb'
485 --- tests/stress/parser/stress.rb       2008-11-26 22:16:48 +0000
486 +++ tests/stress/parser/stress.rb       2010-03-15 18:31:38 +0000
487 @@ -14,10 +14,27 @@
488    return sprintf("%0#{len}x", rand(2 ** (4 * len)))
489  end
490  
491 +def get_random_regex()
492 +  case rand(10)
493 +    when 0..3
494 +      return "{#{get_random_name(rand(8) + 2)},#{get_random_name(rand(8) + 2)},#{get_random_name(rand(8) + 2)}}"
495 +    when 4..5
496 +      return "[#{get_random_name(rand(5) + 1)}]"
497 +    when 6..7
498 +      return "*"
499 +    when 8..9
500 +      return "**"
501 +  end
502 +end
503 +
504  def get_random_path()
505    out = ""
506 -  0.upto(rand(20)) do
507 -    out = "#{out}/#{get_random_name(4)}"
508 +  0.upto(rand(20) + 2) do
509 +    if rand(4) == 0
510 +      out = "#{out}/#{get_random_regex}"
511 +    else
512 +      out = "#{out}/#{get_random_name(rand(10) + 4)}"
513 +    end
514    end
515    return out
516  end
517 @@ -83,7 +100,10 @@
518      "mknod",
519      "lease",
520      "audit_write",
521 -    "audit_control"
522 +    "audit_control",
523 +    "setfcap",
524 +    "mac_override",
525 +    "mac_admin"
526    ]
527  
528    def initialize()
529 @@ -95,6 +115,93 @@
530    end
531  end
532  
533 +class NetRule < Rule
534 +  # XXX Fill me in
535 +end
536 +
537 +class RlimitRule < Rule
538 +  RLIMIT_LIST = [
539 +#"cpu",                # cpu rlimit not supported
540 +    "fsize",
541 +    "data",
542 +    "stack",
543 +    "core",
544 +    "rss",
545 +    "nofile",
546 +    "ofile",
547 +    "as",
548 +    "nproc",
549 +    "memlock",
550 +    "locks",
551 +    "sigpending",
552 +    "msgqueue",
553 +    "nice",
554 +    "rtprio"
555 +  ]
556 +
557 +  def initialize()
558 +    @rlimit = RLIMIT_LIST[rand(RLIMIT_LIST.length)]
559 +    if rand(20) == 0
560 +      @limit = "infinity"
561 +    elsif @rlimit == "nice"
562 +      @limit = rand(40) - 20
563 +    else
564 +      @limit = rand(2 ** 31)
565 +    end
566 +  end
567 +
568 +  def to_s
569 +    return "  set rlimit #{@rlimit} <= #{@limit},"
570 +  end
571 +end
572 +
573 +class Flags
574 +  FLAG_LIST = [
575 +    "complain",
576 +    "audit",
577 +    "chroot_relative",
578 +    "namespace_relative",
579 +    "mediate_deleted",
580 +    "delegate_deleted",
581 +    "attach_disconnected",
582 +    "no_attach_disconnected",
583 +    "chroot_attach",
584 +    "chroot_no_attach"
585 +  ]
586 +
587 +  FLAG_CONFLICTS = [
588 +    ["chroot_relative", "namespace_relative"],
589 +    ["mediate_deleted", "delegate_deleted"],
590 +    ["attach_disconnected", "no_attach_disconnected"],
591 +    ["chroot_attach", "chroot_no_attach"]
592 +  ]
593 +
594 +  def initialize()
595 +    @flags = []
596 +    if rand(2) == 1
597 +      return
598 +    end
599 +
600 +    0.upto(4 - Math.log(rand(32) + 1).to_int) do |x|
601 +      @flags << FLAG_LIST[rand(FLAG_LIST.length)]
602 +    end
603 +
604 +    FLAG_CONFLICTS.each do |c|
605 +      if @flags.include?(c[0]) and @flags.include?(c[1])
606 +        @flags.delete(c[rand(2)])
607 +      end
608 +    end
609 +  end
610 +
611 +  def to_s
612 +    if @flags.empty?
613 +      return ""
614 +    end
615 +    out = @flags.join(",")
616 +    return "flags=(#{out})"
617 +  end
618 +end
619 +
620  def prefix_to_s(name)
621    out = []
622    out << "#"
623 @@ -112,16 +219,19 @@
624      @rvalue = get_random_name()
625      @name = "/does/not/exist/#{@rvalue}"
626      @rules = []
627 +    @flags = Flags.new()
628    end
629  
630    def generate_rules
631 -    @rules << FileRule.new(@name, "rm")
632 +    @rules << FileRule.new(@name, "rm").to_s
633      0.upto(rand($max_rules - $min_rules) + $min_rules) do |x|
634        case rand(100)
635 -        when 0..19
636 -          @rules << CapRule.new
637 -        when 19..100
638 -          @rules << FileRule.new
639 +        when 0..14
640 +          @rules << CapRule.new.to_s
641 +        when 15..24
642 +          @rules << RlimitRule.new.to_s
643 +        when 25..100
644 +          @rules << FileRule.new.to_s
645        end
646      end
647    end
648 @@ -132,10 +242,10 @@
649      out << "# profile for #{@name}"
650      out << "# generated by #{__FILE__} #{$my_version}"
651      out << "#"
652 -    out << "#{@name} {"
653 +    out << "#{@name} #{@flags} {"
654      out << "  #include <abstractions/base>"
655      out << ""
656 -    @rules.each { |r| out << r.to_s }
657 +    @rules.sort.each { |r| out << "  #{r}" }
658      out << "}"
659      out << ""
660    end
661
662 === modified file 'utils/SubDomain.pm'
663 --- utils/SubDomain.pm  2010-03-10 23:30:06 +0000
664 +++ utils/SubDomain.pm  2010-03-26 13:51:21 +0000
665 @@ -6612,10 +6612,14 @@
666      LibAppArmor::free_record($event);
667  
668      #map new c and d to w as logprof doesn't support them yet
669 -    $rmask =~ s/c/w/g;
670 -    $rmask =~ s/d/w/g;
671 -    $dmask =~ s/c/w/g;
672 -    $dmask =~ s/d/w/g;
673 +    if ($rmask) {
674 +        $rmask =~ s/c/w/g;
675 +        $rmask =~ s/d/w/g;
676 +    }
677 +    if ($dmask) {
678 +        $dmask =~ s/c/w/g;
679 +        $dmask =~ s/d/w/g;
680 +    }
681  
682      if ($rmask && !validate_log_mode(hide_log_mode($rmask))) {
683          fatal_error(sprintf(gettext('Log contains unknown mode %s.'),
684
685 === modified file 'utils/apparmor_notify'
686 --- utils/apparmor_notify       2010-03-10 16:11:26 +0000
687 +++ utils/apparmor_notify       2010-05-27 14:08:12 +0000
688 @@ -30,8 +30,7 @@
689  require Time::Local;
690  require File::Basename;
691  
692 -use vars qw($opt_p $opt_s $opt_l $opt_h $opt_v $opt_d $opt_w);
693 -use Getopt::Std;
694 +use Getopt::Long;
695  
696  my %prefs;
697  my $conf = "/etc/apparmor/notify.conf";
698 @@ -67,7 +66,6 @@
699  $ENV{SHELL} = "/bin/sh";
700  defined($ENV{IFS}) and $ENV{IFS} = ' \t\n';
701  
702 -print $0 . "\n";
703  my $prog = File::Basename::basename($0);
704  
705  if ($prog !~ /^[a-zA-Z0-9_\-]+$/) {
706 @@ -75,32 +73,66 @@
707      exitscript(1);
708  }
709  
710 -my $logfile = "/var/log/kern.log";
711 --e "/var/run/auditd.pid" and $logfile = "/var/log/audit/audit.log";
712 -
713  $> == $< or die "Cannot be suid\n";
714  $) == $( or die "Cannot be sgid\n";
715  
716  my $login;
717 +our $orig_euid = $>;
718  
719 -getopts('dhlpvs:w:');
720 +my $opt_d = '';
721 +my $opt_h = '';
722 +my $opt_l = '';
723 +my $opt_p = '';
724 +my $opt_v = '';
725 +my $opt_f = '';
726 +my $opt_s = 0;
727 +my $opt_u = '';
728 +my $opt_w = 0;
729 +GetOptions(
730 +    'debug|d'        => \$opt_d,
731 +    'help|h'         => \$opt_h,
732 +    'since-last|l'   => \$opt_l,
733 +    'poll|p'         => \$opt_p,
734 +    'verbose|v'      => \$opt_v,
735 +    'file|f=s'       => \$opt_f,
736 +    'since-days|s=n' => \$opt_s,
737 +    'user|u=s'       => \$opt_u,
738 +    'wait|w=n'       => \$opt_w,
739 +);
740  if ($opt_h) {
741      usage;
742      exitscript(0);
743  }
744  
745 +# monitor file specified with -f, else use audit.log if auditd is running,
746 +# otherwise kern.log
747 +our $logfile = "/var/log/kern.log";
748 +if ($opt_f) {
749 +    -f $opt_f or die "'$opt_f' does not exist. Aborting\n";
750 +    $logfile = $opt_f;
751 +} else {
752 +    -e "/var/run/auditd.pid" and $logfile = "/var/log/audit/audit.log";
753 +}
754 +
755 +-r $logfile or die "Cannot read '$logfile'\n";
756 +our $logfile_inode = get_logfile_inode($logfile);
757 +our $logfile_size = get_logfile_size($logfile);
758  open (LOGFILE, "<$logfile") or die "Could not open '$logfile'\n";
759  # Drop priviliges, if running as root
760  if ($< == 0) {
761      $login = "root";
762      if (defined($ENV{SUDO_UID}) and defined($ENV{SUDO_GID})) {
763          POSIX::setgid($ENV{SUDO_GID}) or _error("Could not change gid");
764 -        POSIX::setuid($ENV{SUDO_UID}) or _error("Could not change uid");
765 +        $> = $ENV{SUDO_UID} or _error("Could not change euid");
766          defined($ENV{SUDO_USER}) and $login = $ENV{SUDO_USER};
767      } else {
768 +        my $drop_to = $nobody_user;
769 +        if ($opt_u) {
770 +            $drop_to = $opt_u;
771 +        }
772          # nobody/nogroup
773 -        POSIX::setgid(scalar(getpwnam($nobody_group))) or _error("Could not change gid to '$nobody_group'");
774 -        POSIX::setuid(scalar(getpwnam($nobody_user))) or _error("Could not change uid to '$nobody_user'");
775 +        POSIX::setgid(scalar(getgrnam($nobody_group))) or _error("Could not change gid to '$nobody_group'");
776 +        $> = scalar(getpwnam($drop_to)) or _error("Could not change euid to '$drop_to'");
777      }
778  } else {
779      $login = getlogin();
780 @@ -111,7 +143,7 @@
781      readconf($conf);
782      if (defined($prefs{use_group})) {
783          my ($name, $passwd, $gid, $members) = getgrnam($prefs{use_group});
784 -        if (not defined($members) or not defined($login) or not grep { $_ eq $login } split(/ /, $members)) {
785 +        if (not defined($members) or not defined($login) or (not grep { $_ eq $login } split(/ /, $members) and $login ne "root")) {
786              _error("'$login' must be in '$prefs{use_group}' group. Aborting");
787          }
788      }
789 @@ -220,7 +252,6 @@
790      defined($name) and $formatted .= "Name: $name\n";
791      defined($denied) and $formatted .= "Denied: $denied\n";
792      defined($family) and defined ($sock_type) and $formatted .= "Family: $family\nSocket type: $sock_type\n";
793 -    #defined($date) and $since > 0 and $formatted .= "Date: ". scalar(localtime($date)) ."\n";
794      $formatted .= "Logfile: $logfile\n";
795  
796      return $formatted;
797 @@ -259,6 +290,26 @@
798      close(PS);
799  }
800  
801 +sub send_message {
802 +    my $msg = $_[0];
803 +
804 +    my $pid = fork();
805 +    if ($pid == 0) {   # child
806 +        # notify-send needs $< to be the unprivileged user
807 +        $< = $>;
808 +
809 +        # 'system' uses execvp() so no shell metacharacters here.
810 +        # $notify_exe is an absolute path so execvp won't search PATH.
811 +        system "$notify_exe", "-i", "gtk-dialog-warning", "-u", "critical", "--", "AppArmor Message", "$msg";
812 +        my $exit_code = $? >> 8;
813 +        exit($exit_code);
814 +    }
815 +
816 +    # parent
817 +    waitpid($pid, 0);
818 +    return $?;
819 +}
820 +
821  sub do_notify {
822      my %seen;
823      my $seconds = 5;
824 @@ -273,7 +324,7 @@
825          umask 0;
826          open STDIN, '/dev/null' or die "Can't read /dev/null: $!";
827          open STDOUT, '>/dev/null' or die "Can't write to /dev/null: $!";
828 -        open STDERR, '>/dev/null' or die "Can't write to /dev/null: $!";
829 +        #open STDERR, '>/dev/null' or die "Can't write to /dev/null: $!";
830          my $pid = fork();
831          exit if $pid;
832          die "Couldn't fork: $!" unless defined($pid);
833 @@ -293,12 +344,24 @@
834      my $count = 0;
835      my $footer = "For more information, please see:\n$url";
836      my $first_run = 1;
837 -    my $since = $now - (int($opt_s) * 60 * 60 * 24);
838 +    my $since = $now;
839 +    if ($opt_s and int($opt_s) > 0) {
840 +       $since = $since - (int($opt_s) * 60 * 60 * 24);
841 +    }
842      for (my $i=0; $time_to_die == 0; $i++) {
843 +        if ($logfile_inode != get_logfile_inode($logfile)) {
844 +            _warn("$logfile changed inodes, reopening");
845 +            reopen_logfile();
846 +        } elsif (get_logfile_size($logfile) < $logfile_size) {
847 +            _warn("$logfile is smaller, reopening");
848 +            reopen_logfile();
849 +        }
850          while(my $msg = <LOGFILE>) {
851              my @attrib;
852 -            if ($first_run == 1 and $opt_s) {
853 -                @attrib = parse_message($msg, $since);
854 +            if ($first_run == 1) {
855 +                if ($since != $now) {
856 +                    @attrib = parse_message($msg, $since);
857 +                }
858              } else {
859                  @attrib = parse_message($msg);
860              }
861 @@ -340,12 +403,9 @@
862  
863              $m .= $footer;
864  
865 -           # 'system' uses execvp() so no shell metacharacters here.
866 -            # $notify_exe is an absolute path so execvp won't search PATH.
867 -            system "$notify_exe", "-i", "gtk-dialog-warning", "-u", "critical", "--", "AppArmor Message", "$m";
868 -            my $exit_code = $? >> 8;
869 -            if ($exit_code != 0) {
870 -                _warn("'$notify_exe' exited with '$exit_code'");
871 +            my $rc = send_message($m);
872 +            if ($rc != 0) {
873 +                _warn("'$notify_exe' exited with error '$rc'");
874                  $time_to_die = 1;
875                  last;
876              }
877 @@ -356,7 +416,7 @@
878  
879          if ($first_run) {
880              if ($count > 0) {
881 -                my $m = "$logfile contains $count existing denied message";
882 +                my $m = "$logfile contains $count denied message";
883                  $count > 1 and $m .= "s";
884                  if ($opt_s) {
885                      $m .= " in the last ";
886 @@ -368,7 +428,7 @@
887                  }
888                  $m .= ". ";
889                  $m .= $footer;
890 -                system "$notify_exe", "-i", "gtk-dialog-warning", "-u", "critical", "--", "AppArmor Message", "$m";
891 +                send_message($m);
892              }
893              $first_run = 0;
894          }
895 @@ -390,6 +450,9 @@
896  }
897  
898  sub show_since {
899 +    my %msg_hash;
900 +    my %last_date;
901 +    my @msg_list;
902      my $count = 0;
903      while(my $msg = <LOGFILE>) {
904          my @attrib = parse_message($msg, $_[0]);
905 @@ -397,10 +460,31 @@
906  
907          my $m = format_message(@attrib);
908          $m ne "" or next;
909 -
910 -        $opt_v and print "$m\n";
911 +        my $date = $attrib[6];
912 +        if ($opt_v) {
913 +            if (exists($msg_hash{$m})) {
914 +                $msg_hash{$m}++;
915 +                defined($date) and $last_date{$m} = scalar(localtime($date));
916 +            } else {
917 +                $msg_hash{$m} = 1;
918 +                push(@msg_list, $m);
919 +            }
920 +        }
921          $count++;
922      }
923 +    if ($opt_v) {
924 +        foreach my $m (@msg_list) {
925 +            print "$m";
926 +            if ($msg_hash{$m} gt 1) {
927 +                print "($msg_hash{$m} found";
928 +                if (exists($last_date{$m})) {
929 +                    print ", most recent from '$last_date{$m}'";
930 +                }
931 +                print ")\n";
932 +            }
933 +            print "\n";
934 +        }
935 +    }
936      return $count;
937  }
938  
939 @@ -452,19 +536,63 @@
940  sub usage {
941      my $s = <<'EOF';
942  USAGE: apparmor_notify [OPTIONS]
943 +
944  Display AppArmor notifications or messages for DENIED entries.
945  
946  OPTIONS:
947 -  -p           poll AppArmor logs and display notifications
948 -  -l           display stats since last login
949 -  -s NUM       show stats for last NUM days (can be used alone or with -p)
950 -  -v           show messages with stats
951 -  -h           display this help
952 -  -w NUM       wait NUM seconds before displaying notifications (with -p)
953 +  -p, --poll                   poll AppArmor logs and display notifications
954 +  -f FILE, --file=FILE         search FILE for AppArmor messages
955 +  -l, --since-last             display stats since last login
956 +  -s NUM, --since-days=NUM     show stats for last NUM days (can be used alone
957 +                               or with -p)
958 +  -v, --verbose                        show messages with stats
959 +  -h, --help                   display this help
960 +  -u USER, --user=USER         user to drop privileges to when not using sudo
961 +  -w NUM, --wait=NUM           wait NUM seconds before displaying
962 +                               notifications (with -p)
963  EOF
964      print $s;
965  }
966  
967 +sub reopen_logfile {
968 +    # reopen the logfile, temporarily switching back to starting euid for
969 +    # file permissions.
970 +    close(LOGFILE);
971 +
972 +    my $old_euid = $>;
973 +    my $change_euid = 0;
974 +    if ($> != $<) {
975 +        _debug("raising privileges to '$orig_euid' in reopen_logfile()");
976 +        $change_euid = 1;
977 +        $> = $orig_euid;
978 +        $> == $orig_euid or die "Could not raise privileges\n";
979 +    }
980 +
981 +    $logfile_inode = get_logfile_inode($logfile);
982 +    $logfile_size = get_logfile_size($logfile);
983 +    open (LOGFILE, "<$logfile") or die "Could not open '$logfile'\n";
984 +
985 +    if ($change_euid) {
986 +        _debug("dropping privileges to '$old_euid' in reopen_logfile()");
987 +        $> = $old_euid;
988 +        $> == $old_euid or die "Could not drop privileges\n";
989 +    }
990 +}
991 +
992 +sub get_logfile_size {
993 +    my $fn = $_[0];
994 +    my $size;
995 +    defined(($size = (stat($fn))[7])) or (sleep(10) and defined(($size = (stat($fn))[7])) or die "'$fn' disappeared. Aborting\n");
996 +    return $size;
997 +}
998 +
999 +sub get_logfile_inode {
1000 +    my $fn = $_[0];
1001 +    my $inode;
1002 +    defined(($inode = (stat($fn))[1])) or (sleep(10) and defined(($inode = (stat($fn))[1])) or die "'$fn' disappeared. Aborting\n");
1003 +    return $inode;
1004 +}
1005 +
1006  #
1007  # end Subroutines
1008  #
1009
1010 === modified file 'utils/apparmor_notify.pod'
1011 --- utils/apparmor_notify.pod   2010-02-12 16:25:02 +0000
1012 +++ utils/apparmor_notify.pod   2010-05-12 08:46:22 +0000
1013 @@ -40,24 +40,37 @@
1014  
1015  =over 4
1016  
1017 -=item -p
1018 +=item -p, --poll
1019  
1020  poll AppArmor logs and display desktop notifications. Can be used with '-s'
1021  option to display a summary on startup.
1022  
1023 -=item -l
1024 +=item -f FILE, --file=FILE
1025 +
1026 +search FILE for AppArmor messages
1027 +
1028 +=item -l, --since-last
1029  
1030  show summary since last login.
1031  
1032 -=item -s NUM
1033 +=item -s NUM, --since-days=NUM
1034  
1035  show summary for last NUM of days.
1036  
1037 -=item -v
1038 +=item -u USER, --user=USER
1039 +
1040 +user to drop privileges to when running privileged. This has no effect when
1041 +running under sudo.
1042 +
1043 +=item -w NUM, --wait=NUM
1044 +
1045 +wait NUM seconds before displaying notifications (for use with -p)
1046 +
1047 +=item -v, --verbose
1048  
1049  show messages with summaries.
1050  
1051 -=item -h
1052 +=item -h, --help
1053  
1054  displays a short usage statement.
1055  
1056
This page took 0.143724 seconds and 3 git commands to generate.