chiark / gitweb /
tree-wide: remove Lennart's copyright lines
[elogind.git] / src / test / test-user-util.c
index 799065cdadeec7f657cab44a8911c9274237c8fa..bf8dfd0deb900ba8517ad54060ddd53142bc2161 100644 (file)
@@ -1,22 +1,4 @@
 /* SPDX-License-Identifier: LGPL-2.1+ */
-/***
-  This file is part of systemd.
-
-  Copyright 2015 Lennart Poettering
-
-  systemd is free software; you can redistribute it and/or modify it
-  under the terms of the GNU Lesser General Public License as published by
-  the Free Software Foundation; either version 2.1 of the License, or
-  (at your option) any later version.
-
-  systemd is distributed in the hope that it will be useful, but
-  WITHOUT ANY WARRANTY; without even the implied warranty of
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-  Lesser General Public License for more details.
-
-  You should have received a copy of the GNU Lesser General Public License
-  along with systemd; If not, see <http://www.gnu.org/licenses/>.
-***/
 
 #include "alloc-util.h"
 //#include "log.h"
@@ -32,6 +14,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 +27,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 +150,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);
@@ -180,12 +176,18 @@ static void test_get_user_creds_one(const char *id, const char *name, uid_t uid,
 
 #if 0 /// UNNEEDED by elogind
 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);
 }