]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
Merge pull request #6902 from keszybz/two-property-printing-fixes
authorLennart Poettering <lennart@poettering.net>
Tue, 26 Sep 2017 16:09:23 +0000 (18:09 +0200)
committerGitHub <noreply@github.com>
Tue, 26 Sep 2017 16:09:23 +0000 (18:09 +0200)
Two property printing fixes

src/basic/cap-list.c
src/shared/bus-util.c
src/test/test-cap-list.c

index 124641f940bf25577f9c314bd0af0100e9c492c3..2e9b2d9a550c5be5a90c3230552a6003d504e1a3 100644 (file)
@@ -86,15 +86,17 @@ int capability_set_to_string_alloc(uint64_t set, char **s) {
 
                         add = strlen(p);
 
-                        if (!GREEDY_REALLOC0(str, allocated, n + add + 2))
+                        if (!GREEDY_REALLOC(str, allocated, n + add + 2))
                                 return -ENOMEM;
 
                         strcpy(mempcpy(str + n, p, add), " ");
                         n += add + 1;
                 }
 
-        if (n != 0)
-                str[n - 1] = '\0';
+        if (!GREEDY_REALLOC(str, allocated, n + 1))
+                return -ENOMEM;
+
+        str[n > 0 ? n - 1 : 0] = '\0'; /* truncate the last space, if it's there */
 
         *s = str;
         str = NULL;
index 48752c5fea4a3c7c5b8cf21ec00db741b786581c..a9a763c1cabecca5a7b74125a56cef3d12ad8ca9 100644 (file)
@@ -809,7 +809,17 @@ int bus_print_property(const char *name, sd_bus_message *property, bool value, b
 
                 if (strstr(name, "UMask") || strstr(name, "Mode"))
                         print_property(name, "%04o", u);
-                else
+                else if (streq(name, "UID")) {
+                        if (u == UID_INVALID)
+                                print_property(name, "%s", "[not set]");
+                        else
+                                print_property(name, "%"PRIu32, u);
+                } else if (streq(name, "GID")) {
+                        if (u == GID_INVALID)
+                                print_property(name, "%s", "[not set]");
+                        else
+                                print_property(name, "%"PRIu32, u);
+                } else
                         print_property(name, "%"PRIu32, u);
 
                 return 1;
index 4132ec56fd01887805fe22bcb512dd922f4d70fd..c1af277f34e9e44d5b9948132c1a7b824c314563 100644 (file)
@@ -24,6 +24,7 @@
 #include "capability-util.h"
 #include "fileio.h"
 #include "parse-util.h"
+#include "string-util.h"
 #include "util.h"
 
 /* verify the capability parser */
@@ -102,10 +103,24 @@ static void test_last_cap_probe(void) {
         assert_se(p == cap_last_cap());
 }
 
+static void test_capability_set_to_string_alloc(void) {
+        _cleanup_free_ char *t1 = NULL, *t2 = NULL, *t3 = NULL;
+
+        assert_se(capability_set_to_string_alloc(0u, &t1) == 0);
+        assert_se(streq(t1, ""));
+
+        assert_se(capability_set_to_string_alloc(1u<<CAP_DAC_OVERRIDE, &t2) == 0);
+        assert_se(streq(t2, "cap_dac_override"));
+
+        assert_se(capability_set_to_string_alloc(UINT64_C(1)<<CAP_CHOWN | UINT64_C(1)<<CAP_DAC_OVERRIDE | UINT64_C(1)<<CAP_DAC_READ_SEARCH | UINT64_C(1)<<CAP_FOWNER | UINT64_C(1)<<CAP_SETGID | UINT64_C(1)<<CAP_SETUID | UINT64_C(1)<<CAP_SYS_PTRACE | UINT64_C(1)<<CAP_SYS_ADMIN | UINT64_C(1)<<CAP_AUDIT_CONTROL | UINT64_C(1)<<CAP_MAC_OVERRIDE | UINT64_C(1)<<CAP_SYSLOG, &t3) == 0);
+        assert_se(streq(t3, "cap_chown cap_dac_override cap_dac_read_search cap_fowner cap_setgid cap_setuid cap_sys_ptrace cap_sys_admin cap_audit_control cap_mac_override cap_syslog"));
+}
+
 int main(int argc, char *argv[]) {
         test_cap_list();
         test_last_cap_file();
         test_last_cap_probe();
+        test_capability_set_to_string_alloc();
 
         return 0;
 }