Skip to content
This repository has been archived by the owner on Aug 6, 2020. It is now read-only.

Commit

Permalink
core: fix gid when DynamicUser=yes with static User=
Browse files Browse the repository at this point in the history
When DynamicUser=yes and static User= are set, and the user has
different uid and gid, then as the storage socket for the dynamic
user does not contains gid, we need to obtain gid.

Follow-up for 9ec655c.

Fixes systemd#9702.

(cherry picked from commit 25a1df7)
  • Loading branch information
yuwata authored and keszybz committed Oct 29, 2018
1 parent 193fa92 commit 7b21067
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/core/dynamic-user.c
Expand Up @@ -525,6 +525,16 @@ static int dynamic_user_realize(
num = new_uid;
uid_lock_fd = new_uid_lock_fd;
}
} else if (is_user && !uid_is_dynamic(num)) {
struct passwd *p;

/* Statically allocated user may have different uid and gid. So, let's obtain the gid. */
errno = 0;
p = getpwuid(num);
if (!p)
return errno > 0 ? -errno : -ESRCH;

gid = p->pw_gid;
}

/* If the UID/GID was already allocated dynamically, push the data we popped out back in. If it was already
Expand Down

0 comments on commit 7b21067

Please sign in to comment.