[systemd-commits] 2 commits - Makefile.am src/test

Lennart Poettering lennart at kemper.freedesktop.org
Fri Dec 12 09:42:47 PST 2014


 Makefile.am              |    2 +-
 src/test/test-cap-list.c |   21 +++++++++++++++++++++
 2 files changed, 22 insertions(+), 1 deletion(-)

New commits:
commit 4b7c1d5d6a006088910bac42ab3b777be9cf3cc1
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Dec 12 18:42:19 2014 +0100

    test-cap-list: always check libcap comes to the same names as we do, for the names it knows

diff --git a/src/test/test-cap-list.c b/src/test/test-cap-list.c
index a536522..238f876 100644
--- a/src/test/test-cap-list.c
+++ b/src/test/test-cap-list.c
@@ -45,5 +45,24 @@ int main(int argc, char *argv[]) {
         assert_se(capability_from_name("15") == 15);
         assert_se(capability_from_name("-1") == -EINVAL);
 
+        for (i = 0; i <= (int) cap_last_cap(); i++) {
+                _cleanup_cap_free_charp_ char *a = NULL;
+                const char *b;
+                unsigned u;
+
+                assert_se(a = cap_to_name(i));
+
+                /* quite the loop as soon as libcap only returns
+                 * numeric ids, formatted as string */
+                if (safe_atou(a, &u) >= 0)
+                        break;
+
+                assert_se(b = capability_to_name(i));
+
+                printf("%s vs. %s\n", a, b);
+
+                assert_se(streq(a, b));
+        }
+
         return 0;
 }

commit 34a3e4ecad5fd2042eb83ffcbf30379a536cc3ee
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Dec 12 18:37:25 2014 +0100

    cap-list: return lower-case capability names, similar to libcap's cap_to_name(), for compat reasons

diff --git a/Makefile.am b/Makefile.am
index 4170749..4545cfe 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1252,7 +1252,7 @@ src/shared/cap-list.txt:
 	$(AM_V_GEN)$(CPP) $(CFLAGS) $(AM_CPPFLAGS) $(CPPFLAGS) -dM -include linux/capability.h -include missing.h - </dev/null | $(AWK) '/^#define[ \t]+CAP_[A-Z_]+[ \t]+/ { print $$2; }' | grep -v CAP_LAST_CAP >$@
 
 src/shared/cap-to-name.h: src/shared/cap-list.txt
-	$(AM_V_GEN)$(AWK) 'BEGIN{ print "static const char* const capability_names[] = { "} { printf "[%s] = \"%s\",\n", $$1, $$1 } END{print "};"}' <$< >$@
+	$(AM_V_GEN)$(AWK) 'BEGIN{ print "static const char* const capability_names[] = { "} { printf "[%s] = \"%s\",\n", $$1, tolower($$1) } END{print "};"}' <$< >$@
 
 src/shared/cap-from-name.gperf: src/shared/cap-list.txt
 	$(AM_V_GEN)$(AWK) 'BEGIN{ print "struct capability_name { const char* name; int id; };"; print "%null-strings"; print "%%";} { printf "%s, %s\n", $$1, $$1 }' <$< >$@
diff --git a/src/test/test-cap-list.c b/src/test/test-cap-list.c
index dfa9a06..a536522 100644
--- a/src/test/test-cap-list.c
+++ b/src/test/test-cap-list.c
@@ -39,6 +39,8 @@ int main(int argc, char *argv[]) {
 
         assert_se(capability_from_name("asdfbsd") == -EINVAL);
         assert_se(capability_from_name("CAP_AUDIT_READ") == CAP_AUDIT_READ);
+        assert_se(capability_from_name("cap_audit_read") == CAP_AUDIT_READ);
+        assert_se(capability_from_name("cAp_aUdIt_rEAd") == CAP_AUDIT_READ);
         assert_se(capability_from_name("0") == 0);
         assert_se(capability_from_name("15") == 15);
         assert_se(capability_from_name("-1") == -EINVAL);



More information about the systemd-commits mailing list