From 8f7cbe730a03765a0f0456cd1577be0566634ddc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 20 Feb 2018 14:53:09 +0100 Subject: [PATCH 1/3] TODO: drop one item C.f. 7cb609115c532c3591d43a604d67d72e508ba5d9. --- TODO | 3 --- 1 file changed, 3 deletions(-) diff --git a/TODO b/TODO index 048270bf513..383b45af547 100644 --- a/TODO +++ b/TODO @@ -41,9 +41,6 @@ Features: the entire system, with the exception of one specific service. See: https://lists.freedesktop.org/archives/systemd-devel/2018-February/040369.html -* check what setting the login shell to /bin/false vs. /sbin/nologin means and - do the right thing in get_user_creds_clean() with it. - * maybe rework get_user_creds() to query the user database if $SHELL is used for root, but only then. From 52c6e6a8a0221530659c65090f18b16c45a9fc04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 20 Feb 2018 22:10:45 +0100 Subject: [PATCH 2/3] test-user-util: print function delimiters This makes it easier to see what is going on. Crashes may happen in a nested test_{uid,gid}_to_name_one() function, and the default backtrace doesn't show the actual string being tested. --- src/test/test-user-util.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/test/test-user-util.c b/src/test/test-user-util.c index 17a85207416..2af282d0758 100644 --- a/src/test/test-user-util.c +++ b/src/test/test-user-util.c @@ -19,6 +19,7 @@ ***/ #include "alloc-util.h" +#include "log.h" #include "macro.h" #include "string-util.h" #include "user-util.h" @@ -28,6 +29,8 @@ static void test_uid_to_name_one(uid_t uid, const char *name) { _cleanup_free_ char *t = NULL; + log_info("/* %s("UID_FMT", \"%s\") */", __func__, uid, name); + assert_se(t = uid_to_name(uid)); assert_se(streq_ptr(t, name)); } @@ -35,6 +38,8 @@ static void test_uid_to_name_one(uid_t uid, const char *name) { static void test_gid_to_name_one(gid_t gid, const char *name) { _cleanup_free_ char *t = NULL; + log_info("/* %s("GID_FMT", \"%s\") */", __func__, gid, name); + assert_se(t = gid_to_name(gid)); assert_se(streq_ptr(t, name)); } @@ -43,6 +48,8 @@ static void test_parse_uid(void) { int r; uid_t uid; + log_info("/* %s */", __func__); + r = parse_uid("100", &uid); assert_se(r == 0); assert_se(uid == 100); @@ -55,6 +62,7 @@ static void test_parse_uid(void) { } static void test_uid_ptr(void) { + log_info("/* %s */", __func__); assert_se(UID_TO_PTR(0) != NULL); assert_se(UID_TO_PTR(1000) != NULL); @@ -64,6 +72,8 @@ static void test_uid_ptr(void) { } static void test_valid_user_group_name(void) { + log_info("/* %s */", __func__); + assert_se(!valid_user_group_name(NULL)); assert_se(!valid_user_group_name("")); assert_se(!valid_user_group_name("1")); @@ -90,6 +100,8 @@ static void test_valid_user_group_name(void) { } static void test_valid_user_group_name_or_id(void) { + log_info("/* %s */", __func__); + assert_se(!valid_user_group_name_or_id(NULL)); assert_se(!valid_user_group_name_or_id("")); assert_se(valid_user_group_name_or_id("0")); @@ -119,6 +131,7 @@ static void test_valid_user_group_name_or_id(void) { } static void test_valid_gecos(void) { + log_info("/* %s */", __func__); assert_se(!valid_gecos(NULL)); assert_se(valid_gecos("")); @@ -129,6 +142,7 @@ static void test_valid_gecos(void) { } static void test_valid_home(void) { + log_info("/* %s */", __func__); assert_se(!valid_home(NULL)); assert_se(!valid_home("")); @@ -151,7 +165,12 @@ static void test_get_user_creds_one(const char *id, const char *name, uid_t uid, uid_t ruid; gid_t rgid; + log_info("/* %s(\"%s\", \"%s\", "UID_FMT", "GID_FMT", \"%s\", \"%s\") */", + __func__, id, name, uid, gid, home, shell); + assert_se(get_user_creds(&id, &ruid, &rgid, &rhome, &rshell) >= 0); + log_info("got \"%s\", "UID_FMT", "GID_FMT", \"%s\", \"%s\"", + id, ruid, rgid, rhome, rshell); assert_se(streq_ptr(id, name)); assert_se(ruid == uid); assert_se(rgid == gid); @@ -162,13 +181,15 @@ static void test_get_user_creds_one(const char *id, const char *name, uid_t uid, static void test_get_group_creds_one(const char *id, const char *name, gid_t gid) { gid_t rgid; + log_info("/* %s(\"%s\", \"%s\", "GID_FMT") */", __func__, id, name, gid); + assert_se(get_group_creds(&id, &rgid) >= 0); + log_info("got \"%s\", "GID_FMT, id, rgid); assert_se(streq_ptr(id, name)); assert_se(rgid == gid); } int main(int argc, char*argv[]) { - test_uid_to_name_one(0, "root"); test_uid_to_name_one(UID_NOBODY, NOBODY_USER_NAME); test_uid_to_name_one(0xFFFF, "65535"); From 7559b2da10b1513849f22312d09a2381569b4f06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 20 Feb 2018 17:13:41 +0100 Subject: [PATCH 3/3] test-user-util: skip most tests for nobody if synthentization is off When synthetisation is turned off, there's just too many ways those tests can go wrong. We are not interested in verifying that the db on disk is correct, let's just skip all checks. In the first version of this patch, I recorded if we detected a mismatch during configuration and only skipped tests in that case, but actually it is possible to change the host configuration between our configuration phase and running of the tests. It's just more robust to skip always. (This is particularly true if tests are installed.) --- src/test/test-user-util.c | 40 +++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/src/test/test-user-util.c b/src/test/test-user-util.c index 2af282d0758..3a943bf10f0 100644 --- a/src/test/test-user-util.c +++ b/src/test/test-user-util.c @@ -32,6 +32,10 @@ static void test_uid_to_name_one(uid_t uid, const char *name) { log_info("/* %s("UID_FMT", \"%s\") */", __func__, uid, name); assert_se(t = uid_to_name(uid)); + if (!synthesize_nobody() && streq(name, NOBODY_USER_NAME)) { + log_info("(skipping detailed tests because nobody is not synthesized)"); + return; + } assert_se(streq_ptr(t, name)); } @@ -41,6 +45,10 @@ static void test_gid_to_name_one(gid_t gid, const char *name) { log_info("/* %s("GID_FMT", \"%s\") */", __func__, gid, name); assert_se(t = gid_to_name(gid)); + if (!synthesize_nobody() && streq(name, NOBODY_GROUP_NAME)) { + log_info("(skipping detailed tests because nobody is not synthesized)"); + return; + } assert_se(streq_ptr(t, name)); } @@ -160,17 +168,23 @@ static void test_valid_home(void) { } static void test_get_user_creds_one(const char *id, const char *name, uid_t uid, gid_t gid, const char *home, const char *shell) { - const char *rhome; - const char *rshell; - uid_t ruid; - gid_t rgid; + const char *rhome = NULL; + const char *rshell = NULL; + uid_t ruid = UID_INVALID; + gid_t rgid = GID_INVALID; + int r; log_info("/* %s(\"%s\", \"%s\", "UID_FMT", "GID_FMT", \"%s\", \"%s\") */", __func__, id, name, uid, gid, home, shell); - assert_se(get_user_creds(&id, &ruid, &rgid, &rhome, &rshell) >= 0); - log_info("got \"%s\", "UID_FMT", "GID_FMT", \"%s\", \"%s\"", - id, ruid, rgid, rhome, rshell); + r = get_user_creds(&id, &ruid, &rgid, &rhome, &rshell); + log_info_errno(r, "got \"%s\", "UID_FMT", "GID_FMT", \"%s\", \"%s\": %m", + id, ruid, rgid, strnull(rhome), strnull(rshell)); + if (!synthesize_nobody() && streq(name, NOBODY_USER_NAME)) { + log_info("(skipping detailed tests because nobody is not synthesized)"); + return; + } + assert_se(r == 0); assert_se(streq_ptr(id, name)); assert_se(ruid == uid); assert_se(rgid == gid); @@ -179,12 +193,18 @@ static void test_get_user_creds_one(const char *id, const char *name, uid_t uid, } static void test_get_group_creds_one(const char *id, const char *name, gid_t gid) { - gid_t rgid; + gid_t rgid = GID_INVALID; + int r; log_info("/* %s(\"%s\", \"%s\", "GID_FMT") */", __func__, id, name, gid); - assert_se(get_group_creds(&id, &rgid) >= 0); - log_info("got \"%s\", "GID_FMT, id, rgid); + r = get_group_creds(&id, &rgid); + log_info_errno(r, "got \"%s\", "GID_FMT": %m", id, rgid); + if (!synthesize_nobody() && streq(name, NOBODY_GROUP_NAME)) { + log_info("(skipping detailed tests because nobody is not synthesized)"); + return; + } + assert_se(r == 0); assert_se(streq_ptr(id, name)); assert_se(rgid == gid); }