chiark / gitweb /
util: make use of get_user_creds() and get_group_creds() wherever applicable
[elogind.git] / src / tmpfiles.c
index a1b2f8b..3a1985a 100644 (file)
@@ -757,18 +757,11 @@ static int parse_line(const char *fname, unsigned line, const char *buffer) {
         }
 
         if (user && !streq(user, "-")) {
-                uid_t uid;
-                struct passwd *p;
-
-                if (streq(user, "root") || streq(user, "0"))
-                        i->uid = 0;
-                else if (parse_uid(user, &uid) >= 0)
-                        i->uid = uid;
-                else if ((p = getpwnam(user)))
-                        i->uid = p->pw_uid;
-                else {
+                const char *u = user;
+
+                r = get_user_creds(&u, &i->uid, NULL, NULL);
+                if (r < 0) {
                         log_error("[%s:%u] Unknown user '%s'.", fname, line, user);
-                        r = -ENOENT;
                         goto finish;
                 }
 
@@ -776,18 +769,11 @@ static int parse_line(const char *fname, unsigned line, const char *buffer) {
         }
 
         if (group && !streq(group, "-")) {
-                gid_t gid;
-                struct group *g;
-
-                if (streq(group, "root") || streq(group, "0"))
-                        i->gid = 0;
-                else if (parse_gid(group, &gid) >= 0)
-                        i->gid = gid;
-                else if ((g = getgrnam(group)))
-                        i->gid = g->gr_gid;
-                else {
+                const char *g = group;
+
+                r = get_group_creds(&g, &i->gid);
+                if (r < 0) {
                         log_error("[%s:%u] Unknown group '%s'.", fname, line, group);
-                        r = -ENOENT;
                         goto finish;
                 }