]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
journal: add logging of effective capabilities _CAP_EFFECTIVE
authorShawn Landden <shawnlandden@gmail.com>
Tue, 16 Jul 2013 01:10:56 +0000 (18:10 -0700)
committerLennart Poettering <lennart@poettering.net>
Tue, 16 Jul 2013 02:27:04 +0000 (04:27 +0200)
I think this is the most important of the capabilities bitmasks to log.

TODO
man/systemd.journal-fields.xml
src/journal/journald-server.c
src/shared/util.c
src/shared/util.h

diff --git a/TODO b/TODO
index 08626ec5c4c5381916495ab8399fed42e015f9dd..3621ce32a5e2b0438065d3868957dca05922e53b 100644 (file)
--- a/TODO
+++ b/TODO
@@ -220,8 +220,6 @@ Features:
 
 * teach ConditionKernelCommandLine= globs or regexes (in order to match foobar={no,0,off})
 
-* we should log capabilities too
-
 * Support SO_REUSEPORT with socket activation:
   - Let systemd maintain a pool of servers.
   - Use for seamless upgrades, by running the new server before stopping the
index ed62edc8494f5f98c888505faf033bb967430f49..452406c676f2c04c7f870b3e80d4268d7d9ae370 100644 (file)
                                 </listitem>
                         </varlistentry>
 
+                        <varlistentry>
+                                <term><varname>_CAP_EFFECTIVE=</varname></term>
+                                <listitem>
+                                        <para>The effective <citerefentry><refentrytitle>capabilities</refentrytitle><manvolnum>7</manvolnum></citerefentry> of
+                                        the process the journal entry
+                                        originates from.</para>
+                                </listitem>
+                        </varlistentry>
+
                         <varlistentry>
                                 <term><varname>_AUDIT_SESSION=</varname></term>
                                 <term><varname>_AUDIT_LOGINUID=</varname></term>
index 6beaa8a72932da5170407007f0d2ed5016bfd0f6..332ba41363e842293bf99b590f31daa87ca78cb2 100644 (file)
@@ -578,6 +578,13 @@ static void dispatch_message_real(
                         IOVEC_SET_STRING(iovec[n++], x);
                 }
 
+                r = get_process_capeff(ucred->pid, &t);
+                if (r >= 0) {
+                        x = strappenda("_CAP_EFFECTIVE=", t);
+                        free(t);
+                        IOVEC_SET_STRING(iovec[n++], x);
+                }
+
 #ifdef HAVE_AUDIT
                 r = audit_session_from_pid(ucred->pid, &audit);
                 if (r >= 0) {
index 5c7204a567b48a7e35048979d7c958d6d3207e70..19ca8ad1358f68f5733cdea1d1a9ec4855f122d2 100644 (file)
@@ -726,6 +726,40 @@ int is_kernel_thread(pid_t pid) {
         return 0;
 }
 
+int get_process_capeff(pid_t pid, char **capeff) {
+        const char *p;
+        _cleanup_free_ char *status = NULL;
+        char *t = NULL;
+        int r;
+
+        assert(capeff);
+        assert(pid >= 0);
+
+        if (pid == 0)
+                p = "/proc/self/status";
+        else
+                p = procfs_file_alloca(pid, "status");
+
+        r = read_full_file(p, &status, NULL);
+        if (r < 0)
+                return r;
+
+        t = strstr(status, "\nCapEff:\t");
+        if (!t)
+                return -ENOENT;
+
+        for (t += strlen("\nCapEff:\t"); t[0] == '0'; t++)
+                continue;
+
+        if (t[0] == '\n')
+                t--;
+
+        *capeff = strndup(t, strchr(t, '\n') - t);
+        if (!*capeff)
+                return -ENOMEM;
+
+        return 0;
+}
 
 int get_process_exe(pid_t pid, char **name) {
         const char *p;
index ddb21b4a9c596b52edf3dc0ea41e70cc0a791c33..fac08ca43c1b4e96ddf5db4be5da340f05cc657d 100644 (file)
@@ -210,6 +210,7 @@ int get_process_cmdline(pid_t pid, size_t max_length, bool comm_fallback, char *
 int get_process_exe(pid_t pid, char **name);
 int get_process_uid(pid_t pid, uid_t *uid);
 int get_process_gid(pid_t pid, gid_t *gid);
+int get_process_capeff(pid_t pid, char **capeff);
 
 char hexchar(int x) _const_;
 int unhexchar(char c) _const_;