Commit graph

1020 commits

Author SHA1 Message Date
Christian Boltz
6bc1b6ef43 replace copy_netrules_other with list(netrules_other[...]) in
delete_net_duplicates()

Also remove the now unused "import copy".

Acked-by: Kshitij Gupta <kgupta8592@gmail.com>.
2014-09-05 23:21:00 +02:00
Christian Boltz
826e9d998b fix "dictionary changed size during iteration" in cleanprof.py
delete_net_duplicates()

Acked-by: Seth Arnold <seth.arnold@canonical.com>
2014-09-04 13:19:39 +02:00
Steve Beattie
3a5106527c utils tests: restructure signal parse tests
Convert the signal parse tests to use common AAParseTest super class in
common_test.py.

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2014-09-03 18:36:11 -07:00
Steve Beattie
b05cc0f36f utils tests: restructure ptrace parse tests
Convert the ptrace parse tests to use common AAParseTest super class
in common_test.py.

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2014-09-03 18:32:59 -07:00
Steve Beattie
e8d7dcd321 utils tests: restructure pivotroot parse tests
Convert the pivotroot parse tests to use common AAParseTest super
class in common_test.py.

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2014-09-03 18:31:09 -07:00
Steve Beattie
37adff769c utils tests: restructure mount parse tests
Convert the mount parse tests to use common AAParseTest super class in
common_test.py.

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2014-09-03 18:28:18 -07:00
Steve Beattie
59b5b8bab6 Subject: utils tests: restructure DBUS parse tests
Convert the DBUS parse tests to use common AAParseTest super class in
common_test.py.

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2014-09-03 18:26:19 -07:00
Steve Beattie
365b6d603c utils tests: restructure Unix Parse tests
This patch abstracts out parse tests into a super class to inherit from
and converts the af_unix parse tests to use the super class.

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2014-09-03 18:24:57 -07:00
Steve Beattie
74da13e7a3 utils: convert raw rules classes to subclass from _Raw_Rule
The patch that adds support for af_unix rules added a _Raw_Rule base
class to inherit from in rules.py. This patch converts the rest of the
raw rules classes to use the same.

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2014-09-03 18:23:38 -07:00
Steve Beattie
b86d83759a Subject: utils tests: assign regex function at test setup
This patch moves the assignment of the regex function into the unittest
setUp() function rather than at script load time. If for some reason
the python utils library does not define the relevant function, without
this patch the script fails entirely; with it, each individual test
class that depends on the missing regex will fail each test case.

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2014-09-03 18:22:04 -07:00
Steve Beattie
6d34893d4d utils: add limited support for af_unix rules
This patch adds limited support for af_unix rules in the python
utilities, of the "don't touch them, but don't throw a python backtrace
when coming across them, either" variety. Testcases are added as well.

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2014-09-03 18:18:33 -07:00
Christian Boltz
9e4c01f8d3 Add a warning to aa-mergeprof --help that the syntax will change in the
future. Also remove --auto, which is not implemented yet.
2014-09-04 01:49:47 +02:00
Steve Beattie
72cde9a4f4 utils/tests: fix bashisms in runtests-py2.sh
Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
2014-09-03 13:00:33 -07:00
Kshitij Gupta
9e37c3278e Fix the value being set in nt_name when allowed path exist
The patch:
- sets nt_name to the path, if it is allowed.

Acked-by: Christian Boltz <apparmor@cboltz.de>

(acked on IRC based on a link to the ML archive[1])

[1] https://lists.ubuntu.com/archives/apparmor/2014-August/006194.html
2014-08-26 03:13:42 +05:30
Christian Boltz
a620f18cf0 aa.py / ask_the_question() - simplify duplicate option prevention
add a add_to_options() helper function to aa.py which
- adds newpath to options if it's not already there
- returns the updated options and the index of newpath

This removes duplicated code for CMD_GLOB and CMD_GLOBEXT in 
ask_the_question()

It also adds duplicate prevention to CMD_NEW.


Acked-by: Kshitij Gupta <kgupta8592@gmail.com>
2014-08-25 22:49:29 +02:00
Christian Boltz
4608322da9 better error message in aa.py when reaching EOF unexpectedly
When reaching EOF while still in a profile (syntax-wise), there are two
possible reasons:
- missing "}"
- missing "," in the last rule (which means that, thanks to multiline 
  rule handling, the "}" is considered to be part of the last rule)

This patch improves the error message in aa.py to cover a missing ","


Acked-by: Kshitij Gupta <kgupta8592@gmail.com>.
2014-08-25 22:05:45 +02:00
Jamie Strandboge
502e992c42 Update perl abstraction, logprof.conf, severity.db and tests for Debian/Ubuntu
perl multiarch paths

Acked-By: Jamie Strandboge <jamie@canonical.com>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
2014-08-20 19:14:24 -05:00
Christian Boltz
5006abbbb2 Fix "Invalid mode found: AUDITING" in aa-logprof. Actually the fix is
done in logparser.py which contained "AUDITING" instead of "AUDIT" at
one place.

References: https://bugs.launchpad.net/apparmor/+bug/1358705


Acked-by: Steve Beattie <steve@nxnw.org>
2014-08-21 00:55:44 +02:00
Christian Boltz
427258d07a remove unused REs in logparser.py
Those REs also exist (and are used) in aa.py.


Acked-by: Steve Beattie <steve@nxnw.org>
2014-08-18 21:01:38 +02:00
Christian Boltz
784837301b Fix a bug in logparser.py add_event_to_tree(). It looked for '\\null-/'
but should look for '//null-' instead.

Also remove some code duplication by merging with the next condition, 
which executes the same self.add_to_tree code.


Acked-by: Kshitij Gupta <kgupta8592@gmail.com>.
2014-08-17 21:50:15 +02:00
Christian Boltz
51eb1bd69c fix a crash in aa.py / check_for_LD_XXX():
File "/home/cb/apparmor/HEAD-CLEAN/utils/apparmor/aa.py", line 126, in check_for_LD_XXX
  for line in f_in:
  [...]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xf8 in position 40: ordinal not in range(128)

While on it, also replace usage of the "found" variable by "return" 
statements, which should bring a small performance improvement - if we 
have a match, it's superfluous to continue searching.

The patch also adds me to the copyright header ;-)


Acked-by: Kshitij Gupta <kgupta8592@gmail.com>.
2014-08-17 18:16:33 +02:00
Seth Arnold
0ba4c8cd7e Ensure the that the {**,} and {,**} regexs are being properly parsed by
the Python tools.

Signed-off-by: Seth Arnold <seth.arnold@canonical.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2014-08-14 10:51:42 -07:00
Christian Boltz
d5e6058370 apparmor:vim: add mediate_deleted and delegate_deleted flags
Acked-by: Steve Beattie <steve@nxnw.org>
2014-08-11 23:13:55 +02:00
Christian Boltz
c814443a83 Set the currently selected path as (editable) default when using "(N)ew"
in aa-logprof or aa-genprof.

Acked-by: Kshitij Gupta <kgupta8592@gmail.com>
2014-08-06 19:07:41 +02:00
Christian Boltz
356e7cb199 aa-mergeprof: honor -d parameter
(it was ignored until now)

Acked-by: Kshitij Gupta <kgupta8592@gmail.com>.
2014-08-04 20:19:08 +02:00
Christian Boltz
241544ad8a modify aa-mergeprof to:
- allow users to merge two profiles (2-way merge) using aa-mergeprof by
  making the third profile optional
- re-enable code that cleaned up base and other profile and using it in
  deleted count (was disabled due to pyflakes thinking it was unused)

Patch by Kshitij Gupta <kgupta8592@gmail.com>


Acked-by: Christian Boltz <apparmor@cboltz.de>
2014-07-29 12:39:12 +02:00
Christian Boltz
37ca3dd556 add some more globbing tests for globs with extension, including
filenames that contain a * wildcard and a .* regex wildcard.

Acked-by: Seth Arnold <seth.arnold@canonical.com>
2014-07-28 20:16:04 +02:00
Christian Boltz
be6cb6724d fix aa-mergeprof to
- import apparmor.ui as aaui
- call aaui.UI_*() instead of apparmor.aa.UI_*()
- use apparmor.aamode.AA_MAY_EXEC instead of apparmor.aa.AA_MAY_EXEC


Acked-by: Kshitij Gupta <kgupta8592@gmail.com>.
2014-07-28 00:24:26 +02:00
Steve Beattie
ab2ac92ecf utils: make all tests consistent in verbosity
This patch adjusts the verbosity of several of the utils tests,
to make them all consistently verbose.

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
2014-07-25 17:49:06 -07:00
Launchpad Translations on behalf of apparmor-dev
3ec7f81dcc Launchpad automatic translations update. 2014-07-24 05:40:28 +00:00
Christian Boltz
dd3b6a8d4a Set PYTHONPATH=.. in runtests-py3.sh to make sure the tests use the in-
tree python modules.

Also remove "sys.path.append('../')" (and now-unused "import sys") from 
all tests that contain it for consistency and to make testing with the 
installed modules possible (even if we don't have a USE_SYSTEM option 
yet).


Acked-by: Steve Beattie <steve@nxnw.org>
2014-07-22 21:25:25 +02:00
Christian Boltz
95ef7cabcb Fix a crash in aa-logprof (to be exact: save_profiles() in aa.py) when
saving the remaining profile after using "save selected profile".

When using "save selected profile", write_profile() (called by 
write_profile_ui_feedback()) does "changed.pop(profile_name)". 
However, saving the remaining profiles in save_profiles() uses a cached 
version of changed.keys() and therefore tries to save a profile that 
was already saved and is no longer part of "changed".


Also remove two commented lines we'll never need again:
- #changed.pop is done in write_profile()
- q['options'] is set some lines above

References: https://bugs.launchpad.net/apparmor/+bug/1341178

Acked-by: Steve Beattie <steve@nxnw.org>
2014-07-22 12:56:37 +02:00
Steve Beattie
aeebd69555 utils: add CAP_AUDIT_READ to severity.db
This patch adds the new capability CAP_AUDIT_READ, added in the 3.16
kernel, to the utils severity.db. I set the severity level at 7,
since it seemed to offer less exposure than CAP_AUDIT_CONTROL and
CAP_AUDIT_WRITE, which are both considered severity 8.

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
2014-07-21 22:54:14 -07:00
Christian Boltz
a04a6bfdaf change severity_test.py and minitools_test.py to use the in-tree
profiles instead of the system profiles in /etc/apparmor.d/

Acked-by: Steve Beattie <steve@nxnw.org>
2014-07-17 15:59:57 +02:00
Christian Boltz
5f8b035a71 change runtests-py*.sh (scripts for manually running the utils/test/*.py
testcases) to
- sleep 10 seconds after each failed test to make failures more annoying
  ^W^W^W^Wgive people a chance to read failure details
- print a list of failed tests at the end

Also avoid duplicate code by letting runtests-py2.sh call runtests-py3.sh.


Acked-by: Steve Beattie <steve@nxnw.org>
2014-07-17 15:47:18 +02:00
Steve Beattie
0c64863c97 Merge from launchpad translations branch:
* updates to Bosnian, Suomi, and Malay parser translations
* added stub Turkish translation for utils
2014-07-16 11:28:08 -07:00
Christian Boltz
43b128473d logparser.py defines LOG_MODE_RE, but doesn't use it.
LOG_MODE_RE is also defined (and used) in aamode.py.

This patch removes the superfluous definition from logparser.py.


Acked-by: Seth Arnold <seth.arnold@canonical.com>
2014-07-14 21:01:15 +02:00
Christian Boltz
abf92ecf67 fix two issues in LOG_MODE_RE in aamode.py:
- remove "Ix" (only valid as lowercase "ix")
- add "pux" (was missing before)

Acked-by: Seth Arnold <seth.arnold@canonical.com>
2014-07-14 20:56:26 +02:00
Christian Boltz
f77d5666d4 better error messages in aa.py store_list_var()
This patch improves the error messages in aa.py store_list_var() to make
debugging of profile syntax problems easier. It also adds an additional
parameter for the profile filename (used in the error message)

Acked-by: Steve Beattie <steve@nxnw.org>
2014-06-20 13:36:35 +02:00
Christian Boltz
b917e30c35 fix aa-complain to work with quoted profile names
This patch fixes a crash in aa-complain when a profile name is quoted. 
It also makes sure aa-complain actually adds the complain flag in such 
cases. (aa-enforce etc. will also benefit from this fix.)

Note: superfluous quotes will be removed when saving the profile (for 
example with aa-cleanprof), but they are kept if needed, like in
    profile "/bin/foo bar"
(tested with aa-complain and aa-cleanprof - and also with "rcapparmor 
reload", where the initscript bailed out because my profile filename 
contained a space...)

The patch also adds some TODO notes.

References: https://bugs.launchpad.net/apparmor/+bug/1296218


Acked-by: Steve Beattie <steve@nxnw.org>.
2014-06-19 20:44:57 +02:00
Christian Boltz
a79453fb1f fix save_profile() by fixing some other code
When creating a child profile while using genprof, I get a backtrace:

Traceback (most recent call last):
  File "aa-genprof", line 160, in <module>
      lp_ret = apparmor.do_logprof_pass(logmark, passno)
    File "/home/cb/apparmor/HEAD-CLEAN/utils/apparmor/aa.py", line 2291, in do_logprof_pass
      save_profiles()
    File "/home/cb/apparmor/HEAD-CLEAN/utils/apparmor/aa.py", line 2309, in save_profiles
      for prof_name in changed.keys():
RuntimeError: dictionary changed size during iteration

(See https://bugs.launchpad.net/apparmor/+bug/1014304 for more details.)


After digging into the code, it seems for some reason the child profile 
is added to "changed" - I doubt this is correct (guess why it's removed 
later... ;-)

After digging a bit more, I found out that create_new_profile() is 
(ab)used to create a new stub profile to be used as child profile. 
create_new_profile then adds the new child (which looks like a normal 
profile to it) to "changed".

This patch most probably makes the cleanup round in save_profile() 
superfluous by adding a is_stub parameter to create_new_profile(). If
this parameter is set, the new (child) profile is not added to "created" 
and "changed".

I intentionally added the two print() lines in safe_profile because
a) I think they will never be displayed
b) I want to know if a) is wrong ;-)
c) it's always nice to have a "nice" error message before displaying
   a backtrace ;-)


Acked-by: Steve Beattie <steve@nxnw.org>
2014-06-10 00:44:59 +02:00
Christian Boltz
0d4257462d aa-genprof failed to set /proc/sys/kernel/printk_ratelimit to 0
(unlimited) because the "if not value:" check matches 0.

This patch replaces the check with "... is None".

It also prints a warning if the old value is None (could in theory 
happen if reading the old value failed).

Acked-by: Steve Beattie <steve@nxnw.org>. Thanks.
2014-06-09 23:47:36 +02:00
Jamie Strandboge
f8ed2e1d0d Description: use -QTK instead of -p in verify_policy(). '-p' only runs the
preprocessor and is not as thorough as -QTK (--skip-kernel-load,
 --skip-read-cache, --skip-cache). Like with '-p', '-QTK' can be run without
 privilege but it will catch things like conflictings 'x' modifiers.

Acked-By: Jamie Strandboge <jamie@canonical.com>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
2014-06-09 13:38:35 -05:00
Tyler Hicks
d2b62fff47 utils: Handle unmount rules
Bug: https://bugs.launchpad.net/bugs/1325109

The parser will accept rules with either umount or unmount rule types.
The utils should follow suite.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2014-06-03 16:23:30 -05:00
Christian Boltz
4bff5778e0 handle_children() tried to read a profile from the binary instead of
the binary's profile

Patch by timdaman 
Bug: https://bugs.launchpad.net/ubuntu/+source/apparmor/+bug/1324154

Acked-By: Christian Boltz <apparmor@cboltz.de>
2014-05-29 16:53:02 +02:00
Christian Boltz
5ffb6eb26b fix autodep() in aa.py which fills filelist[] with a wrong structure
(one nesting level missing), which then causes aa-genprof to crash 
when pressing "s" for "scan".

References: https://bugs.launchpad.net/ubuntu/+source/apparmor/+bug/1319829


Acked-by: Seth Arnold <seth.arnold@canonical.com>
2014-05-22 19:43:10 +02:00
Launchpad Translations on behalf of apparmor-dev
5cde820d4c Launchpad automatic translations update. 2014-05-22 05:31:07 +00:00
Christian Boltz
b2c4934bc1 fix two issues in aa-genprof's last_audit_entry_time():
- convert "tail" result from byte to string to avoid TypeError crash
- use apparmor.filename instead of hardcoded /var/log/audit/audit.log

Acked-by: Kshitij Gupta <kgupta8592@gmail.com>
2014-05-21 21:42:43 +02:00
Christian Boltz
e83d05e521 test the mountains and pay the dbusdriver a pivot_rootbeer
(in a more serious version: add some tests for dbus, *mount, signal, 
ptrace and pivot_root and make sure a space after the keyword is enforced.
The tools shouldn't accept a "dbusdriver" or "pivot_rootbeer" rule. ;-)

Acked-by: Tyler Hicks <tyhicks@canonical.com>
2014-04-26 13:10:44 +02:00
Christian Boltz
6aab291185 Fix regular expressions in aa.py to enforce a space after some keywords
(dbus, *mount, signal, ptrace, pivot_root) except if the line only 
contains the bare keyword.

Note that in most cases (except *mount) I used an alternation - this has 
the advantage that it doesn't change the match group numbering, with the
small disadvantage of having to mention the keyword twice in the regex.
I chose this way to avoid that I have to change lots of other places and
possibly introduce bugs by overlooking something.

For the *mount rules, I read the code - it shouldn't need any changes 
because it uses only matches[0..2] 

Acked-by: Tyler Hicks <tyhicks@canonical.com>
2014-04-26 13:05:55 +02:00