Commit graph

647 commits

Author SHA1 Message Date
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
Steve Beattie
55fe4c4a4e Merge from launchpad translations branch.
What a great lot of gratuitous changes just to get one new translated
Italian string.
2014-04-24 10:26:16 -07:00
Tyler Hicks
876e30a3c5 utils: Simplify newly added test-regex_matches tests
Remove duplicated test code by adding a simple way for regex test
classes to declare a regex to use and a list of tuples consisting of
(line, expected_result). The setup_regex_tests() method generates test
methods for each tuple in a classes list. The test methods are based on
the regex_test() method, which performs the regex search and compares
the results to the expected_result.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2014-04-23 16:41:44 -05:00
Tyler Hicks
f8f3d16d4c utils: Remove unnecessary regex groups
The regexes for signal, ptrace, and pivot_root rules each had an extra
grouping around the terms 'signal', 'ptrace', and 'pivot_root'. Those
extra groupings can be safely removed.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2014-04-23 16:28:34 -05:00
Tyler Hicks
bd129145ad utils: Clean up file rule parsing
This patch backs out most of the changes from r2448 in favor of a better
approach.

The optional "file" keyword is handled under the pre-existing
RE_PROFILE_PATH_ENTRY regex and a new regex, RE_PROFILE_BARE_FILE_ENTRY,
is created for handling bare file rules.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2014-04-23 16:28:17 -05:00
Tyler Hicks
6b85a158e9 utils: Clean up str_to_mode()
The first conditional around string being set is not needed. If string
is not set, the while loop will be skipped and mode will be returned.

The variable tmp was being overloaded by being the regex search result
and then being reassigned to be the first match group in the regex
search result. This patch keeps tmp as the regex search result and then
uses mode_char to represent the first match group of the search.

Group the search and replace actions together at the beginning of the
loop and group the mode character processing at the end of the loop.

Finally, remove the unnecessary check of tmp (now mode_char) before
calling MODE_HASH.get(tmp, False). If tmp is None or '', get() will
do the right thing and return False.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2014-04-23 15:46:42 -05:00
Tyler Hicks
ddf977faf5 utils: Fix infinite loop when converting an unrecognized mode string
Bug: https://bugs.launchpad.net/bugs/1307665

When str_to_mode() was given a string containing unknown mode
characters, it entered an infinite loop. The case of the MODE_MAP_RE
regex string not matching the mode string was being ignored.

This patch makes it so that the loop breaks when MODE_MAP_RE no longer
matches the mode string. This occurs when all of the valid mode
characters have been processed and only invalid mode characters remain.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2014-04-23 15:46:03 -05:00
Tyler Hicks
432bf597ae utils: Basic support for pivot_root rules
Bug: https://bugs.launchpad.net/bugs/1298678

This patch does bare bones parsing of pivot_root rules and stores the raw
strings for writing them out later. It is meant to be a simple change to
prevent aa.py from emitting a traceback when encountering pivot_root rules.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: Steve Beattie <steve@nxnw.org>
Acked-By: Christian Boltz <apparmor@cboltz.de>
2014-04-23 15:41:03 -05:00
Tyler Hicks
496502b150 utils: Basic support for ptrace rules
Bug: https://bugs.launchpad.net/bugs/1300317

This patch does bare bones parsing of ptrace rules and stores the raw
strings for writing them out later. It is meant to be a simple change to
prevent aa.py from emitting a traceback when encountering ptrace rules.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: Steve Beattie <steve@nxnw.org>
Acked-By: Christian Boltz <apparmor@cboltz.de>
2014-04-23 15:40:20 -05:00
Tyler Hicks
81c6fc9ff1 utils: Basic support for signal rules
Bug: https://bugs.launchpad.net/bugs/1300316

This patch does bare bones parsing of signal rules and stores the raw
strings for writing them out later. It is meant to be a simple change to
prevent aa.py from emitting a traceback when encountering signal rules.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: Steve Beattie <steve@nxnw.org>
Acked-By: Christian Boltz <apparmor@cboltz.de>
2014-04-23 15:39:14 -05:00
Tyler Hicks
54a24c2b6a utils: Basic support for file prefix in path rules
Bug: https://bugs.launchpad.net/bugs/1295346

Add the ability to read and write path rules containing the file prefix.
This also includes bare "file," rules.

The ALL global is updated to include a preceding NUL char to eliminate
possibilities of a real file path colliding with the ALL global.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: Steve Beattie <steve@nxnw.org>
2014-04-03 21:58:59 -05:00
Launchpad Translations on behalf of apparmor-dev
29208310a9 Launchpad automatic translations update. 2014-03-26 05:41:51 +00:00
Steve Beattie
74b523f248 utils: don't install two copies of aa-easyprof
With the conversion of the python utils, aa-easyprof got added to the
list of tools to be installed (in /usr/sbin/), but is already installed
(in /usr/bin) by the python-tools-setup.py distutils script, leaving two
copies of the tool in place. This patch filters out aa-easyprof from the
list of tools for the makefile to install itself, leaving it to
(continue to) be installed by the distutils script.

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
2014-03-25 15:04:37 -07:00
Steve Beattie
3ecb969a12 utils: add simple capability regex tests
This patch adds some simple tests of the capability regex in
apparmor/aa.py.

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: Tyler Hicks <tyhicks@canonical.com>
2014-03-20 12:38:37 -07:00
Tyler Hicks
62ea36073b utils: Basic support for bare capability rules
Bug: https://bugs.launchpad.net/bugs/1294819

This patch as minimal support for bare capability rules ("capability,").
It prevents aa.py from emitting a traceback when encountering such a
rule.

It only adds the ability to parse and write the bare rule. It doesn't
attempt to be clever when deleting duplicate rules, such as realizing
that "capability audit_control," can be deleted if "capability," is also
present.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: Steve Beattie <steve@nxnw.org>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2014-03-20 14:27:24 -05:00
Tyler Hicks
e5d9d541f6 utils: Add very limited support for mount rules
Bug: https://bugs.launchpad.net/bugs/1294825

This patch is inspired by sbeattie's patch to add limited dbus rule
support. It adds does very dumb parsing of mount rules. Basically, it
stores mount, remount, and umount rules as raw strings wrapped in a
class.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: Steve Beattie <steve@nxnw.org>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2014-03-20 14:25:42 -05:00
Tyler Hicks
5dce40c97f utils: Fix typo in write_dbus()
Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: Steve Beattie <steve@nxnw.org>
2014-03-20 14:19:40 -05:00
Steve Beattie
d0edb879b8 utils/easyprof: fix regression test when apparmor-easyprof is not installed
Bug: https://bugs.launchpad.net/bugs/1294848

This patch fixes the testsuite for aa-easyprof when the easyprof
utilities and configuration files are not installed in the system.
What was happening was that verify_manifest was calling parse_args()
without the synthetic arguments created by the test case and passing
the result to AppArmorEasyProfile(). Because parse_args() didn't
have the synthetic arguments, it would parse the actual command line
arguments passed to the testscript, which of course didn't specify the
alternate configuration file location. This would work when easyprof
had been installed in the system, because the fallback configuration
file in /etc/apparmor/easyprof.conf would exist and specify template
and policy group locations. Without that, though, the tests would abort
due to not knowing the location of the templates and policy groups.

This patch fixes the issue by passing the synthetic argument list
to verify_manifest, which uses that when calling parse_args(). A
debugging statement that states which conffile is being used when
AppArmorEasyProfile is being instantiated.

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: Tyler Hicks <tyhicks@canonical.com>
2014-03-19 22:02:53 -07:00
Christian Boltz
5f3fc904b5 aa-genprof: fix last_audit_entry_time()
last_audit_entry_time() was waiting forever because 
subprocess.check_output() started tail without any parameters.
Fixed by removing shell=True (default is shell=False).

Also fix the regex ("^.*", the dot was missing)


Acked-by: Steve Beattie <steve@nxnw.org>
2014-03-20 00:10:13 +01:00
Steve Beattie
ad2973e89f Merge from launchpad translations:
- added beginning of utils translations for Polish and Swedish
- Some rejiggering of existing utils translations; I don't think any
  existing translations got lost, but there are new missing entries
- A whole bunch of comment updating for the parser translations

Acked-by: Steve Beattie <steve@nxnw.org>
2014-03-18 10:14:24 -07:00
Steve Beattie
19cf0fd89d merge from trunk 2014-03-18 10:02:27 -07:00
Launchpad Translations on behalf of apparmor-dev
12d13a4a33 Launchpad automatic translations update. 2014-03-18 05:31:37 +00:00
Kshitij Gupta
d9deb90953 Fix comments when multiple profiles in a single file
Signed-off-by: Kshitij Gupta <kgupta8592@gmail.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2014-03-16 20:36:42 +05:30
Launchpad Translations on behalf of apparmor-dev
7d96d41f8e Launchpad automatic translations update. 2014-03-11 05:30:43 +00:00