Commit graph

31 commits

Author SHA1 Message Date
Christian Boltz
f72c001643
aa-status: Fix malformed json output
In some cases (if profiles in complain and enforce mode are loaded), the
`i` loop runs more than once, which also means `j == 0` is true in the
middle of the json. This causes invalid json.

This patch fixes this.

This is a regression related to 22aa9b6161
/ https://gitlab.com/apparmor/apparmor/-/merge_requests/964 /
https://gitlab.com/apparmor/apparmor/-/issues/295
which fixed another case of invalid json if a process was unconfined
while having a profile defined.

Note: I also tested this patch for the "unconfined, but has a profile
defined" case to ensure it doesn't break what
22aa9b6161 fixed.
2023-05-19 22:25:05 +02:00
John Johansen
5ff6686ea7 aa-status: rename filters so they have the filters. prefix
To emphasize that the
  --mode
  --processs
  --profiles
  --pid

options are filters rename them to
  --filter.mode
  --filter.processs
  --filter.profiles
  --filter.pid

Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-05-02 03:06:36 -07:00
John Johansen
5453f985ba aa-status: add support for prompt mode
Support prompt mode. Note that the kernel uses "user" instead of
"prompt" that policy uses.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-05-02 02:57:11 -07:00
John Johansen
c065570c6f aa-status: Add filter for the executable
Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-05-02 02:57:09 -07:00
John Johansen
a5852c41df aa-status: add ability to filter on pid
Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-05-02 02:55:45 -07:00
John Johansen
195877b732 fixup profile filter 2023-05-02 02:53:51 -07:00
John Johansen
016183cbf4 aa-status: add profile filter
Extend filtering to be able to screen for different profiles by name

Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-05-02 02:45:49 -07:00
John Johansen
ee66319d0b aa-status: Make filtering more generic
In preparation for more filters than just mode prepare a basic filtering
infrastructure.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-05-02 02:45:01 -07:00
John Johansen
33464a7a3f aa-status: allow filtering processes and profiles based on mode
Add the basic infrastructure for adding regex based filters and
allow filtering process and profiles by mode based on a user supplied
filter.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-05-02 02:38:50 -07:00
John Johansen
840807cacc aa-status: add a --show flag
So that the user can control the set of data being shown add a --show
flag. Currently it allows showing
  all
  profiles
  processes

Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-05-02 02:38:50 -07:00
John Johansen
6b902047c9 aa-status: add --count flag
In prepartaion for greater control over dispaly and counting add a
count flag.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-05-02 02:38:50 -07:00
John Johansen
ed62eeba75 aa-status: convert to using options instead of directly calling fns
In preparation for new options and controls, split detailed_output()
into detailed_profiles() and detailed_processes() and This switch the
output processing to one larger pass that uses option flags.

This doesn't change current behavior and is in not as clean as the
current code for the current option set. However it will allow us to
easily add new options in one place and have them apply correctly
every where.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-05-02 02:38:43 -07:00
John Johansen
a455b50c66 aa-status: allow profile/process counts to go to a file
Make it so the output options that count profiles and processes can
be output to a file.

This does not add a user option to do so

Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-04-27 01:45:59 -07:00
John Johansen
66279ea1c7 aa-status: allow pretty printed json to go to somewhere other than stdout
Add basic enablement (but no option yet) to send pretty printed json
to a specified file.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-04-27 01:45:59 -07:00
John Johansen
508f9184ea aa-status: split file output from whether json is being produced
For detailed output split up where output is going from whether json
is being produced.

This also allows none json output to go to a file.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-04-27 01:45:59 -07:00
John Johansen
4858110480 aa-status: fix indentation
Make sure indentation conforms to the linux kernel style guide that
we use.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-04-27 01:45:59 -07:00
John Johansen
ce13b28154 aa-status: switch commands dispatch to get_opt_long
To allow for a richer command set switch arg handling to use
get_opt_long.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-04-27 01:45:59 -07:00
Alex Murray
22aa9b6161
aa-status: Fix malformed json output with unconfined processes
As reported in issue #295, the json output from aa-status would be invalid if
there were profiles defined for processes that were unconfined. Fix this by
ensuring the json for the processes array is closed properly.

Signed-off-by: Alex Murray <alex.murray@canonical.com>
2023-01-04 12:32:59 +10:30
John Johansen
457ab38b93 aa-status: fix crash due to \n in profile name
This fixes a crash when a profile name contains a \n character which
breaks profile name parsing. The fix is minimal in that it ignores
the bad profile name and continues processing.

Ideally this name would not exist and is indicative of a bug in the kernel.

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/211
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/824
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2022-01-20 13:40:02 -08:00
Armin Kuster
a2a0d14b9c aa_status: Fix build issue with musl
add limits.h

aa_status.c:269:22: error: 'PATH_MAX' undeclared (first use in this function); did you mean 'AF_MAX'?
|   269 |    real_exe = calloc(PATH_MAX + 1, sizeof(char));

Signed-off-by: Armin Kuster <akuster808@gmail.com>
2020-10-07 09:10:43 -07:00
John Johansen
1de9768180 binutils: Fix unused var warning in aa_status.c
aa_status.c: In function ‘get_processes’:
aa_status.c:236:10: warning: unused variable ‘len’ [-Wunused-variable]
   size_t len = 0;
          ^~~

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/561
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <sbeattie@ubuntu.com>
2020-06-03 16:29:51 -07:00
Christian Boltz
0b8839932a
aa-status: append \n to --json and --pretty-json output
... so that - if someone calls aa-status from the commandline - the next
prompt doesn't get displayed in the same line as the json output.
2020-05-21 17:52:23 +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
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
John Johansen
65f1d33a88 aa-status: bump the json version that aa-status outputs
aa-status output has changed slightly to account for the newer profile
modes. This means the json version needs to be bumped so consumers
can detect the change.

PR: https://gitlab.com/apparmor/apparmor/-/merge_requests/508
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-05-05 00:14:36 -07:00
John Johansen
69a0c80a40 aa-status: reindent from spaces to tabs
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-04-29 16:56:58 -07:00
John Johansen
de8f1ba17d aa-status: add support for kill and unconfined profile modes
AppArmor 3 exposes kernel support for the kill and unconfined profile
modes. Make sure aa-status has basic support for these modes.

Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-04-29 16:56:58 -07:00
John Johansen
e3185cadf3 aa-status: add output for for stacked processes in mixed mode
Processes that are confined by multiple profiles in a stack can have
more than one profile mode applied. Allow aa-status to report
processes that are in a mixed profile confinement mode.

Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-04-29 16:56:58 -07:00
John Johansen
68811fa42b aa-status: switch aa-status to use libapparmor proc accessor and splitcon
Switch aa-status over to using the libapparmor proc accessor. This
will ensure that aa-status works correctly under LSM stacking kernels,
and if other new interfaces are added in the future.

Also at the same time switch over the splitting of context's to
the library provided aa_splitcon() fn.

Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-04-29 16:56:58 -07:00
Alex Murray
8f9046b1b1 Merge Port aa-status from python to C
This allows aa-status to be used without a python runtime to support things like https://bugs.launchpad.net/bugs/1865519

Fixes: https://bugs.launchpad.net/bugs/1865519
PR: https://gitlab.com/apparmor/apparmor/-/merge_requests/473
Acked-by: John Johansen <john.johansen@canonical.com>
2020-04-24 05:43:47 +00:00