diff --git a/TODO b/TODO index 048270bf51..383b45af54 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. diff --git a/src/test/test-user-util.c b/src/test/test-user-util.c index 17a8520741..3a943bf10f 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,14 +29,26 @@ 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)); + 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)); } 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)); + 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)); } @@ -43,6 +56,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 +70,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 +80,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 +108,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 +139,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 +150,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("")); @@ -146,12 +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; - assert_se(get_user_creds(&id, &ruid, &rgid, &rhome, &rshell) >= 0); + log_info("/* %s(\"%s\", \"%s\", "UID_FMT", "GID_FMT", \"%s\", \"%s\") */", + __func__, id, name, uid, gid, home, shell); + + 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); @@ -160,15 +193,23 @@ 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; - assert_se(get_group_creds(&id, &rgid) >= 0); + log_info("/* %s(\"%s\", \"%s\", "GID_FMT") */", __func__, id, name, gid); + + 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); } 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");