Commit graph

5328 commits

Author SHA1 Message Date
Christian Boltz
ed0f2fe505
aa-mergeprof: simplify internal parameter handover
Instead of stuffing two variables into a list and split them again, hand
them over as plain separate variables.
2020-05-14 23:29:31 +02:00
Christian Boltz
e0f9b7cb07 Merge branch 'cboltz-fail-verbose' into 'master'
read_profile(): don't fail silently

See merge request apparmor/apparmor!530

Acked-by: Steve Beattie <steve.beattie@canonical.com> for 2.11..master
2020-05-12 19:43:44 +00:00
John Johansen
d1dca1f2d4 Merge ProfileList: add __repr__() with list of filenames
Even if incomplete (it doesn't print the whole ProfileList content), this should make debugging easier.

PR: https://gitlab.com/apparmor/apparmor/-/merge_requests/531
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-05-12 07:44:12 +00:00
Christian Boltz
e841c866d3
ProfileList: add __repr__() with list of filenames
Even if incomplete (it doesn't print the whole ProfileList content),
this should make debugging easier.
2020-05-11 22:46:29 +02:00
Christian Boltz
af8b9dc5bb
read_profile(): don't fail silently
If a profile file can't be read, print a warning so that the user is
aware of the problem.
2020-05-11 22:23:20 +02:00
Steve Beattie
da2ce3ac67 utils: Use ProfileList to handle aliases
Merge branch 'cboltz-alias' into 'master'

Acked-by: Steve Beattie <steve.beattie@canonical.com>
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/526
2020-05-11 08:51:42 +00:00
Christian Boltz
cb44e6d47d Merge branch 'cboltz-drop-is-active-profile' into 'master'
Drop is_active_profile()

See merge request apparmor/apparmor!529

Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-05-11 08:37:16 +00:00
Christian Boltz
a5434e562d Merge branch 'cboltz-drop-write-rules' into 'master'
Drop / inline write_rules()

See merge request apparmor/apparmor!528

Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-05-10 23:03:47 +00:00
Christian Boltz
ae70ecfbaa Merge branch 'cboltz-vim-alias' into 'master'
apparmor.vim: allow leading whitespace for alias rules

See merge request apparmor/apparmor!527

Acked-by: Steve Beattie <steve.beattie@canonical.com> for 2.11..master
2020-05-10 22:54:34 +00:00
Christian Boltz
710d5ae466
Drop is_active_profile()
... and inline it at the only place that uses it
2020-05-10 23:49:16 +02:00
Christian Boltz
5c48eb7aa7
Drop / inline write_rules()
The TODO in write_rules() was long solved - remove the safety net type
check, it's no longer needed.

Without this, the function becomes a simple .get_rules_clean() call
which can easily be inlined into write_piece() at the two places where
it's called.
2020-05-10 18:09:14 +02:00
Christian Boltz
3c9c162951
write_alias(): drop depth parameter
... which is always '0' anyways, and therefore superfluous
2020-05-10 17:42:55 +02:00
Christian Boltz
8855c60f23
move write_alias to ProfileList
It's only needed in the preamble, which makes ProfileList the perfect
place.
2020-05-10 17:40:53 +02:00
Christian Boltz
fc6bd72781
Drop alias handling from ProfileStorage
ProfileStorage handles the profile content, but not the preamble. This
also means it will never see any aliases.
2020-05-10 17:39:02 +02:00
Christian Boltz
c636580f18
apparmor.vim: allow leading whitespace for alias rules 2020-05-10 17:24:09 +02:00
Christian Boltz
c0da20cf2c
Use ProfileList to handle aliases 2020-05-10 13:37:05 +02:00
Christian Boltz
77a22979ed
ProfileList: Add support for alias rules
... and also some tests
2020-05-10 13:37:05 +02:00
John Johansen
13bea6f4a7 Merge Introduce and use AbiRule to handle abi rules
See the individual commits for details.

PR: https://gitlab.com/apparmor/apparmor/-/merge_requests/525
Acked-by: John Johansen <john.johansen@canonical.com>
2020-05-10 02:24:01 +00:00
John Johansen
676df24182 Merge Replace filelist[file_name]['profiles'] with using ProfileList
Replace usage of filelist\[file_name\]\['profiles'\] with the `active_profiles` ProfileList which already has the same data.

Add `profiles_in_file()` to ProfileList as a nice interface to get the list of profiles in a file.

For more details, check the individual commits.

PR: https://gitlab.com/apparmor/apparmor/-/merge_requests/523
Avked-by: John Johansen <john.johansen>
2020-05-09 19:16:54 +00:00
Christian Boltz
66d3d92de3
Use AbiRule in ProfileStorage (for abi rules inside profiles)
This also drops the last usage of write_abi(), drop it.
2020-05-09 21:02:06 +02:00
Christian Boltz
d003cf814c
Use AbiRule for profile preamble 2020-05-09 21:02:06 +02:00
Christian Boltz
5efccd146e
ProfileList: Use AbiRuleset and add add_abi()
... and also tests for it
2020-05-09 21:02:06 +02:00
Christian Boltz
50d896705f
Add AbiRule and testsuite
This is probably the shortest rule class we'll ever have because it can
inherit most things from IncludeRule.
2020-05-09 21:02:06 +02:00
Christian Boltz
3d13ddb30a
Un-hardcode 'include' and 'IncludeRule' in IncludeRule
... as a preparation to recycle the class
2020-05-09 21:02:06 +02:00
Christian Boltz
e9557284a3
re_match_include_parse() raise bug exceptions only for include
... but not for abi rules, which (according to the simple_tests
profiles) do not share these bugs)

For unquoted paths, make sure that the path doesn't include whitespace.
2020-05-09 21:02:06 +02:00
Christian Boltz
8ca486715f
extend re_match_include_parse() to also match abi rules
... and add some tests
2020-05-09 20:08:48 +02:00
Christian Boltz
b96fd81184
split out common parts of RE_INCLUDE and RE_ABI
... into RE_MAGIC_OR_QUOTED_PATH
2020-05-09 18:57:25 +02:00
John Johansen
28cdd08131 Merge add binutils/aa-status compiled files to .gitignore
Make so git ignores the generated files that result from building aa-status.

https://gitlab.com/apparmor/apparmor/-/merge_requests/524
Acked-by: John Johansen <john.johansen@canical.com>
2020-05-09 15:53:45 +00:00
Christian Boltz
c9ce3d3ab4
add binutils/aa-status compiled files to .gitignore 2020-05-09 13:29:24 +02:00
Steve Beattie
5574af0390
parser tests: convert makefile error tests to python script
Make the error and warning message tests a first class test script; in
gitlab CI, failures would not necessarily result in output being
captured.

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
Acked-by: John Johansen <john.johansen@canonical.com>
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/522
2020-05-08 15:44:41 -07:00
Steve Beattie
500cbf89a7
parser testlib: restructure command run functions
Don't commingle stderr and stdout by default, and provide a
function that provides the exit value, stderr, and stdout as a
tuple. Also, expect UTF-8 output by default from the commands (with
universal_newlines), rather than bytes.

(Nifty commands like subprocess.run() weren't added to python until
python 3.5.)

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
Acked-by: John Johansen <john.johansen@canonical.com>
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/522
2020-05-08 15:43:34 -07:00
Christian Boltz
874d3385a3
Stop writing to filelist[file]['profiles']
... because after the previous three commits, nothing reads/needs this
anymore

Note: file_name in ask_exec() was only used in the (dropped) filelist
usage.
2020-05-08 23:00:35 +02:00
Christian Boltz
4e09f315c3
Use active_profiles.profiles_in_file()
... instead of filelist[file_name]['profiles']
2020-05-08 22:40:38 +02:00
Christian Boltz
01e46ab453
Add profiles_in_file() to ProfileList
... and some tests for it.
2020-05-08 22:37:45 +02:00
Christian Boltz
34a0457090
parse_profile_data(): better way to check for duplicate hats
Instead of checking filelist[file]['profiles'] for duplicate hats, check
profile_data[profile][hat].

With this, the duplicate hat check is done in the same way as the check
for duplicate profiles and child profiles.

Also add tests for duplicate child profiles and duplicate hats.
2020-05-08 22:15:10 +02:00
Christian Boltz
6b55794074 Merge branch 'cboltz-less-shell' into 'master'
less shell ;-)

See merge request apparmor/apparmor!520

Acked-by: John Johansen <john.johansen@canonical.com>
2020-05-07 17:59:06 +00:00
Christian Boltz
48bae9e3b0
less shell ;-)
Using a list as parameter for subprocess.call is more secure, and avoids
funny problems if the filename to display contains spaces or other funny
characters.
2020-05-07 19:45:39 +02:00
John Johansen
74c90c797c Merge drop unused get_pager()
The only usage was dropped/replaced when switching to `UI_ShowFile()` in https://gitlab.com/apparmor/apparmor/-/merge_requests/514

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/515
Acked-by: John Johansen <john.johansen@canonical.com>
2020-05-07 17:40:36 +00:00
Christian Boltz
d459cbf0f4
drop unused get_pager()
The only usage was dropped/replaced when switching to UI_ShowFile() in
https://gitlab.com/apparmor/apparmor/-/merge_requests/514
2020-05-07 12:13:20 +02:00
Steve Beattie
aca65e8d3c
aa-status: fix exposed compiler warnings
Fix signed/unsigned comparison warnings, and silence unused parameter
warnings due to the "cleverness" of the function pointer array and
wanting to print out the command as invoked in the usage statement.

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
Acked-by: John Johansen <john.johansen@canonical.com>
https://gitlab.com/apparmor/apparmor/-/merge_requests/517
2020-05-07 01:12:38 -07:00
Steve Beattie
05747a9e1d
binutils: actually use listed compiler warning flags
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
Acked-by: John Johansen <john.johansen@canonical.com>
https://gitlab.com/apparmor/apparmor/-/merge_requests/517
2020-05-07 01:12:38 -07:00
Steve Beattie
5fc2cb5524
bintutils: delete the tools on make clean
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
Acked-by: John Johansen <john.johansen@canonical.com>
https://gitlab.com/apparmor/apparmor/-/merge_requests/517
2020-05-07 01:12:37 -07:00
Steve Beattie
3d0d0c69bc
aa_status: separate out version info
Separate out the aa-status json version info out from being a magic
element embedded in a string in the middle of the json emitter, and move
it to an early location, along with a comment to edit it whenthe format
changes.

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
Acked-by: John Johansen <john.johansen@canonical.com>
https://gitlab.com/apparmor/apparmor/-/merge_requests/517
2020-05-07 01:12:37 -07:00
John Johansen
2acb93c21a
aa-status: add json pretty printing using cJSON
This restores aa-status ability to pretty print json by using
DaveGamble's cJSON: https://github.com/DaveGamble/cJSON

Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve.beattie@canonical.com>
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/493
2020-05-07 01:12:28 -07:00
Christian Boltz
986b4f2b72 Merge branch 'cboltz-fix-genprof-json' into 'master'
Fix showing the local inactive profile in json mode

See merge request apparmor/apparmor!514

Acked-by: John Johansen <john.johansen@canonical.com> for 2.11..master
2020-05-06 22:43:35 +00:00
Christian Boltz
7b8f7d645e Merge branch 'cboltz-utils-cleanup' into 'master'
cleanup get_profile()

See merge request apparmor/apparmor!513

Acked-by: John Johansen <john.johansen@canonical.com>
2020-05-06 22:42:48 +00:00
Christian Boltz
68a258b006
Fix showing the local inactive profile in json mode
When aa-genprof proposes a local inactive profile, it had a hardcoded
call to 'less' to display that profile.

Unsurprisingly, this doesn't work in JSON mode and breaks YaST (luckily
it's only a case of "the button doesn't work").

References: https://bugzilla.opensuse.org/show_bug.cgi?id=1171315
2020-05-06 23:20:07 +02:00
Christian Boltz
bb3803b931
Split off UI_ShowFile() from UI_Changes
UI_ShowFile() is more generic and can be used to display various (text)
files, not only diffs.
2020-05-06 23:16:47 +02:00
Christian Boltz
4906bbf965
get_profile(): get rid of profile_type
It's always set to 'INACTIVE_LOCAL' - no need to set and later check it.

Also add a TODO note ;-)
2020-05-06 22:53:57 +02:00
Christian Boltz
f96304fe33
get_profile(): get rid of profile_data variable
... which also makes the code easier to understand
2020-05-06 22:53:22 +02:00