From e5e70efc37ef88118710c75db9458dedda2920ac Mon Sep 17 00:00:00 2001 From: Christian Kellner Date: Tue, 29 Nov 2022 15:09:08 +0000 Subject: [PATCH] stages/users: accept identical uid for existing users Accept a `uid` option for an existing user if it is the existing one. This allows to have the same options for existing as well as new users, which in turn allows for the same blueprint in Composer for new and upgrade OSTree commits. In the latter we pre-fill the password database from a previous commit, which is needed to make sure that uids do not change. Since Composer can't know which of the specified users in the blueprint are new ones or existing ones it cannot easily omit the corresponding stage options. Thus the stage options have to be the same for new and existing users. --- stages/org.osbuild.users | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/stages/org.osbuild.users b/stages/org.osbuild.users index f7449a93..01f46929 100755 --- a/stages/org.osbuild.users +++ b/stages/org.osbuild.users @@ -151,7 +151,8 @@ def main(tree, options): passwd = getpwnam(tree, name) if passwd is not None: - if uid is not None: + # `pw_uid` is the third field of `struct passwd` see `getpwnam(3)` + if uid is not None and passwd[2] != str(uid): print(f"Error: can't set uid of existing user '{name}'") return 1 usermod(tree, name, gid, groups, description, home, shell, password)