Commit graph

6348 commits

Author SHA1 Message Date
Mark Grassi
b1c2aeaa76 Be consistent with return statements when only returning None. 2022-08-21 11:15:07 -04:00
Mark Grassi
091c6ad59d Use string startswith() and endswith() methods instead of slicing to check for prefixes and suffixes. 2022-08-21 11:15:07 -04:00
Mark Grassi
854602c0d9 Use the fact that empty sequences are false. 2022-08-21 11:15:07 -04:00
Mark Grassi
68e3f12c2c Avoid escaping quotation marks where possible. 2022-08-21 11:15:07 -04:00
Mark Grassi
c57138f255 Order imports and module-level dunder name assignments. 2022-08-21 11:15:07 -04:00
Mark Grassi
ea3fb60007 Break lines before binary operators. 2022-08-21 11:15:07 -04:00
Mark Grassi
ef2e6c62e7 Ensure variables inside functions are lower_case_with_underscores. 2022-08-21 11:15:07 -04:00
Mark Grassi
dc384c48a8 Use triple double-quoted strings for docstrings. 2022-08-21 11:15:07 -04:00
Mark Grassi
de3aa3c5f0 Correct misspelling. 2022-08-21 11:15:07 -04:00
Mark Grassi
f590a66e50 Remove redundant backslashes, and unnecessary semicolons and pass statements. 2022-08-21 11:15:07 -04:00
Mark Grassi
813c831468 Ensure non-membership tests are "not in". 2022-08-21 11:15:07 -04:00
Mark Grassi
96f7121944 Fix most PEP 8 whitespace, indentation, and major line length violations. 2022-08-21 11:15:07 -04:00
Mark Grassi
e4f88cc3a8 Indent line continuations per PEP 8. 2022-08-21 11:15:07 -04:00
Mark Grassi
aff9bb8f81 Ensure no bool comparisons use equality comparisons. 2022-08-21 11:15:07 -04:00
Mark Grassi
62f99465e9 Ensure all None comparisons use is or is not. 2022-08-21 11:15:07 -04:00
Mark Grassi
0375ea1257 Change tabs to spaces in Python files. 2022-08-21 11:15:07 -04:00
Christian Boltz
c06ea77445 Merge Set (instead of compare) exresult
Interestingly this accidentally worked because `if exresult` is true for
both a non-empty string ("PASS") as well as a real `True` value.

Found by Mark Grassi as part of
https://gitlab.com/apparmor/apparmor/-/merge_requests/906

I propose this patch for all branches.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/907
Approved-by: Jon Tourville <jon.tourville@canonical.com>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2022-08-16 19:25:49 +00:00
Christian Boltz
5a2fb8569c
Set (instead of compare) exresult
Interestingly this accidentally worked because `if exresult` is true for
both a non-empty string ("PASS") as well as a real `True` value.

Found by Mark Grassi as part of
https://gitlab.com/apparmor/apparmor/-/merge_requests/906
2022-08-14 12:33:56 +02:00
Christian Boltz
c9c5208f77
dnsmasq: Add missing r permissions for libvirt_leaseshelper
Note: This was reported for /usr/libexec/libvirt_leaseshelper, but since
this is probably unrelated to the path or a path change, this commit
also adds r permissions for the previous path.

Fixes: https://bugzilla.opensuse.org/show_bug.cgi?id=1202161
2022-08-08 20:48:58 +02:00
Georgia Garcia
a555ccd9f4 Merge Fix setuptools version detection in buildpath.py
libraries/libapparmor/swig/python/test/buildpath.py:
The changes introduced in
cc7f549665
targetted a wrong setuptools version (61.2).
The change in build directory naming has been introduced with 62.0.

Fixes #259 
Fixes #39

Closes #39 and #259
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/904
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: Georgia Garcia <georgia.garcia@canonical.com>
2022-08-03 17:21:50 +00:00
David Runge
1ff0c2c7d6
Use basepath.py in profiles Makefile
profiles/Makefile:
Set PYTHON_DIST_BUILD_PATH using
libraries/libapparmor/swig/python/test/buildpath.py as it solves the
problem of setting the build directory generically.
2022-08-03 10:56:51 +02:00
David Runge
fda390983f
Fix setuptools version detection in buildpath.py
libraries/libapparmor/swig/python/test/buildpath.py:
The changes introduced in
cc7f549665
targetted a wrong setuptools version (61.2).
The change in build directory naming has been introduced with 62.1
(1c23f5e1e4).
2022-08-03 10:56:47 +02:00
John Johansen
b65fbf5fbd Sync Library version from 3.0.5 release
See v3.0.5 704c82c574

Signed-off-by: John Johansen <john.johansen@canonical.com>
2022-07-25 15:29:12 -07:00
Georgia Garcia
0afc2cbb84 parser: fix LTO build
The previous fix for LTO builds in b6d3daa7 did not take into
consideration that LTO support could be added through CFLAGS,in which
case the fix would not be applied.

This patch applied the fix -flto-partition=none even if CFLAGS is
already defined.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
Closes #214
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/901
Acked-by: John Johansen <john@jjmx.net>
Merged-by: Georgia Garcia <georgia.garcia@canonical.com>
2022-07-25 17:34:27 -03:00
Christian Boltz
1f3a817c11 Merge dirtest.sh: don't rely on apparmor_parser -N's output sort order to be deterministic
I've seen this test fail because "apparmor_parser -N" returned the expected
lines, but in a different order than what's expected (dirtest.out).

To fix this, sort both the expected and actual output.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/900
Approved-by: Jon Tourville <jon.tourville@canonical.com>
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2022-07-25 20:09:16 +00:00
intrigeri
c0815d0e0f dirtest.sh: don't rely on apparmor_parser -N's output sort order to be deterministic
I've seen this test fail because "apparmor_parser -N" returned the expected
lines, but in a different order than what's expected (dirtest.out).

To fix this, sort both the expected and actual output.
2022-07-25 10:14:31 +00:00
Christian Boltz
c0b5d90848 Merge Resolve "Python: Ensure opened files are closed."
This MR closes #239. In the temporary file commit, `tempfile.NamedTemporaryFile` is preferred over `tempfile.mkstemp` because it allows for simpler use of context managers and lets you choose what mode to open the file in. Also in this commit, note that in `aa.py` and `easyprof.py` destination files are now written directly, instead of writing to temp files and then renaming them.

Closes #239
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/898
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2022-07-20 19:34:16 +00:00
Mark Grassi
e6cbdef4ab Implement code review comments. 2022-07-19 20:32:03 -04:00
Christian Boltz
ea0dc96050 Merge Support setuptools >= 61.2 in Python tests
Fix for #253, by mirroring the change from 1c23f5e1e4

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/897
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2022-07-19 20:29:38 +00:00
Ben Greiner
d442584a0a reviewed edits 2022-07-19 21:47:02 +02:00
Mark Grassi
cf6606d380 Ensure opened temporary files are closed. 2022-07-17 21:52:55 -04:00
Ben Greiner
85734c3bac add setuptools to test-utils CI job 2022-07-16 20:42:07 +02:00
Ben Greiner
47d68dac0f use new build_platlib path with setuptools >= 61.2 2022-07-16 17:47:18 +02:00
Mark Grassi
0c1eb3ec92 Ensure opened files are closed. 2022-07-12 18:34:29 -04:00
Christian Boltz
97bd86c7c6 Merge Remove Python 2 support.
Per the discussion in #243, this MR removes Python 2 compatibility. Namely, this merge request:
- removes code behind `sys` and `platform` interpreter version checks
- removes `unicode` vs. `str` handling
- removes unnecessary `__future__` imports
- removes unnecessary `object` inheritance
- removes unnecessary `super()` arguments
- uncomments commented-out code with "uncomment when python3 only" notes or some variant of that message

Regarding the `unicode` vs. `str` handling, it's arguably more Pythonic to check `isinstance(x, str)` as opposed to `type(x) is str`, but I didn't want to alter code behavior.

A change needs to be made to the `INCOMPLETE_COVERAGE` setting in `utils/test/Makefile` to get the pipeline to pass. I didn't get anywhere tweaking the setting myself, so someone else with more AppArmor experience will have to make that change.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/894
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2022-07-12 18:26:29 +00:00
Jon Tourville
421223c757 Add test for nfs file access
Add test to verify that file access on a mounted NFS share is determined
by file rules and not network rules. This relies on a kernel patch, so
the tests are marked xpass.

https://bugs.launchpad.net/ubuntu/+source/apparmor/+bug/1784499
2022-07-12 16:49:46 +00:00
Steve Beattie
0859b42ba2 profiles: merge Update syslogd for inetutils-syslogd
The inetutils syslogd implementation integrates the kmsg support in the
main server, it has support for syslog.d configuration fragment files.
and it uses a slightly different pid filename.

Signed-off-by: Guillem Jover <guillem@hadrons.org>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/888
Approved-by: Steve Beattie <gitlab@nxnw.org>
Merged-by: Steve Beattie <gitlab@nxnw.org>
2022-07-08 05:12:46 +00:00
Christian Boltz
e1011d646d Merge rc.apparmor.functions: only use systemd-detect-virt if it's present
This is a follow-up on !812, which added a call to systemd-detect-virt.
Everywhere else we don't assume that program is present,
and first check if it's there before we run it.
Let's do the same here.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/896
Approved-by: Christian Boltz <apparmor@cboltz.de>
Approved-by: Jon Tourville <jon.tourville@canonical.com>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2022-07-06 21:45:39 +00:00
Mark Grassi
db4939cf6a Improve variable name. 2022-07-06 13:51:57 -04:00
Mark Grassi
44c814e76c Update code coverage settings. 2022-07-06 13:29:32 -04:00
intrigeri
06f86e2a02 rc.apparmor.functions: only use systemd-detect-virt if it's present
This is a follow-up on !812, which added a call to systemd-detect-virt.
Everywhere else we don't assume that program is present,
and first check if it's there before we run it.
Let's do the same here.
2022-07-06 06:41:35 +00:00
Mark Grassi
df97cf89bd Remove Python 2 support. 2022-06-29 20:41:38 -04:00
Christian Boltz
57eebd6cdb Merge zgrep: allow executing egrep and fgrep
egrep and fgrep also need to execute grep and write to /dev/tty in the
helper child profile.

Fixes: https://progress.opensuse.org/issues/113108

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/892
Approved-by: Jon Tourville <jon.tourville@canonical.com>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2022-06-29 13:25:14 +00:00
Christian Boltz
df37c299e1
zgrep: allow executing egrep and fgrep
egrep and fgrep also need to execute grep and write to /dev/tty in the
helper child profile.

Fixes: https://progress.opensuse.org/issues/113108
2022-06-28 23:27:10 +02:00
Christian Boltz
08da556e4e Merge Fix inconsistent return length.
Correct issue discussed in !889.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/890
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2022-06-28 18:59:37 +00:00
Mark Grassi
728dbde5e4 Fix inconsistent return length. 2022-06-28 08:30:31 -04:00
Christian Boltz
43f419458e Merge Speed up list creations, and change lists to tuples where appropriate.
Tuples [are quite a bit faster than lists](https://stackoverflow.com/a/22140115). If you don't need mutability, a tuple is almost always the better collection to choose. This merge request changes lists to tuples where appropriate, and speeds up some list creations by changing `list()` calls into `[]` literals. It also changes a few function calls to use tuple unpacking, i.e. `func(*tup)`, as opposed to `func(tup[0], tup[1], ...)`. This yields yet another performance improvement, as well as a readability improvement.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/889
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2022-06-27 18:56:10 +00:00
Mark Grassi
7581c9e113 Speed up list creations, and change lists to tuples where appropriate.. 2022-06-26 22:18:56 -04:00
Christian Boltz
36c704ce04 Merge Avoid unnecessary memory copies when enlarging lists.
This merge request addresses issue #240.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/886
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2022-06-26 12:06:22 +00:00
Mark Grassi
ca9920cf92 Avoid unnecessary memory copies when enlarging lists. 2022-06-26 12:06:22 +00:00