From 62d1c93a0260286f9114ee7ab59df026d93be19d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Mon, 24 May 2021 09:15:39 +0200 Subject: [PATCH 1/4] sysusers: reduce scope of variables and drop unnecessary initializations --- src/sysusers/sysusers.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/sysusers/sysusers.c b/src/sysusers/sysusers.c index dd55360ee5..92f969db0f 100644 --- a/src/sysusers/sysusers.c +++ b/src/sysusers/sysusers.c @@ -401,7 +401,6 @@ static int write_temporary_passwd(const char *passwd_path, FILE **tmpfile, char return r; while ((r = fgetpwent_sane(original, &pw)) > 0) { - i = ordered_hashmap_get(users, pw->pw_name); if (i && i->todo_user) return log_error_errno(SYNTHETIC_ERRNO(EEXIST), @@ -784,16 +783,14 @@ static int write_temporary_gshadow(const char * gshadow_path, FILE **tmpfile, ch *tmpfile = TAKE_PTR(gshadow); *tmpfile_path = TAKE_PTR(gshadow_tmp); } - return 0; -#else - return 0; #endif + return 0; } static int write_files(void) { _cleanup_fclose_ FILE *passwd = NULL, *group = NULL, *shadow = NULL, *gshadow = NULL; _cleanup_(unlink_and_freep) char *passwd_tmp = NULL, *group_tmp = NULL, *shadow_tmp = NULL, *gshadow_tmp = NULL; - const char *passwd_path = NULL, *group_path = NULL, *shadow_path = NULL, *gshadow_path = NULL; + const char *passwd_path, *shadow_path, *group_path, *gshadow_path; int r; passwd_path = prefix_roota(arg_root, "/etc/passwd"); @@ -881,10 +878,6 @@ static int write_files(void) { } static int uid_is_ok(uid_t uid, const char *name, bool check_with_gid) { - struct passwd *p; - struct group *g; - const char *n; - Item *i; /* Let's see if we already have assigned the UID a second time */ if (ordered_hashmap_get(todo_uids, UID_TO_PTR(uid))) @@ -893,6 +886,8 @@ static int uid_is_ok(uid_t uid, const char *name, bool check_with_gid) { /* Try to avoid using uids that are already used by a group * that doesn't have the same name as our new user. */ if (check_with_gid) { + Item *i; + i = ordered_hashmap_get(todo_gids, GID_TO_PTR(uid)); if (i && !streq(i->name, name)) return 0; @@ -903,6 +898,8 @@ static int uid_is_ok(uid_t uid, const char *name, bool check_with_gid) { return 0; if (check_with_gid) { + const char *n; + n = hashmap_get(database_by_gid, GID_TO_PTR(uid)); if (n && !streq(n, name)) return 0; @@ -910,6 +907,9 @@ static int uid_is_ok(uid_t uid, const char *name, bool check_with_gid) { /* Let's also check via NSS, to avoid UID clashes over LDAP and such, just in case */ if (!arg_root) { + struct passwd *p; + struct group *g; + errno = 0; p = getpwuid(uid); if (p) @@ -1109,7 +1109,8 @@ static int add_user(Item *i) { i->name, i->uid, i->gid); i->todo_user = true; - log_info("Creating user %s (%s) with uid " UID_FMT " and gid " GID_FMT ".", i->name, strna(i->description), i->uid, i->gid); + log_info("Creating user %s (%s) with uid " UID_FMT " and gid " GID_FMT ".", + i->name, strna(i->description), i->uid, i->gid); return 0; } From 335f6ab4f13abcd8073fe84f2a3c70c67271126e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Mon, 24 May 2021 10:35:13 +0200 Subject: [PATCH 2/4] sysusers: add debug lines to failing getent/putent operations I'm trying to use systemd-sysusers for systemd.rpm itself, and the invocation in dnf chroot is failing like this: ... Creating group input with gid 999. Creating group kvm with gid 36. Creating group render with gid 998. Creating group sgx with gid 997. Creating group systemd-journal with gid 190. Creating group systemd-network with gid 192. Creating user systemd-network (systemd Network Management) with uid 192 and gid 192. Creating group systemd-oom with gid 996. Creating user systemd-oom (systemd Userspace OOM Killer) with uid 996 and gid 996. Creating group systemd-resolve with gid 193. Creating user systemd-resolve (systemd Resolver) with uid 193 and gid 193. Creating group systemd-timesync with gid 995. Creating user systemd-timesync (systemd Time Synchronization) with uid 995 and gid 995. Creating group systemd-coredump with gid 994. Creating user systemd-coredump (systemd Core Dumper) with uid 994 and gid 994. Failed to write files: Function not implemented Let's add more info to make such failures easier to debug. --- src/sysusers/sysusers.c | 112 +++++++++++++++++++++++----------------- 1 file changed, 65 insertions(+), 47 deletions(-) diff --git a/src/sysusers/sysusers.c b/src/sysusers/sysusers.c index 92f969db0f..8e0d76ef46 100644 --- a/src/sysusers/sysusers.c +++ b/src/sysusers/sysusers.c @@ -391,14 +391,15 @@ static int write_temporary_passwd(const char *passwd_path, FILE **tmpfile, char r = fopen_temporary_label("/etc/passwd", passwd_path, &passwd, &passwd_tmp); if (r < 0) - return r; + return log_debug_errno(r, "Failed to open temporary copy of %s: %m", passwd_path); original = fopen(passwd_path, "re"); if (original) { r = copy_rights(fileno(original), fileno(passwd)); if (r < 0) - return r; + return log_debug_errno(r, "Failed to copy permissions from %s to %s: %m", + passwd_path, passwd_tmp); while ((r = fgetpwent_sane(original, &pw)) > 0) { i = ordered_hashmap_get(users, pw->pw_name); @@ -418,16 +419,17 @@ static int write_temporary_passwd(const char *passwd_path, FILE **tmpfile, char r = putpwent_sane(pw, passwd); if (r < 0) - return r; + return log_debug_errno(r, "Failed to add existing user \"%s\" to temporary passwd file: %m", + pw->pw_name); } if (r < 0) - return r; + return log_debug_errno(r, "Failed to read %s: %m", passwd_path); } else { if (errno != ENOENT) - return -errno; + return log_debug_errno(errno, "Failed to open %s: %m", passwd_path); if (fchmod(fileno(passwd), 0644) < 0) - return -errno; + return log_debug_errno(errno, "Failed to fchmod %s: %m", passwd_tmp); } ORDERED_HASHMAP_FOREACH(i, todo_uids) { @@ -463,25 +465,27 @@ static int write_temporary_passwd(const char *passwd_path, FILE **tmpfile, char r = putpwent_sane(&n, passwd); if (r < 0) - return r; + return log_debug_errno(r, "Failed to add new user \"%s\" to temporary passwd file: %m", + pw->pw_name); } /* Append the remaining NIS entries if any */ while (pw) { r = putpwent_sane(pw, passwd); if (r < 0) - return r; + return log_debug_errno(r, "Failed to add existing user \"%s\" to temporary passwd file: %m", + pw->pw_name); r = fgetpwent_sane(original, &pw); if (r < 0) - return r; + return log_debug_errno(r, "Failed to read %s: %m", passwd_path); if (r == 0) break; } r = fflush_and_check(passwd); if (r < 0) - return r; + return log_debug_errno(r, "Failed to flush %s: %m", passwd_tmp); *tmpfile = TAKE_PTR(passwd); *tmpfile_path = TAKE_PTR(passwd_tmp); @@ -502,7 +506,7 @@ static int write_temporary_shadow(const char *shadow_path, FILE **tmpfile, char r = fopen_temporary_label("/etc/shadow", shadow_path, &shadow, &shadow_tmp); if (r < 0) - return r; + return log_debug_errno(r, "Failed to open temporary copy of %s: %m", shadow_path); lstchg = (long) (now(CLOCK_REALTIME) / USEC_PER_DAY); @@ -511,10 +515,10 @@ static int write_temporary_shadow(const char *shadow_path, FILE **tmpfile, char r = copy_rights(fileno(original), fileno(shadow)); if (r < 0) - return r; + return log_debug_errno(r, "Failed to copy permissions from %s to %s: %m", + shadow_path, shadow_tmp); while ((r = fgetspent_sane(original, &sp)) > 0) { - i = ordered_hashmap_get(users, sp->sp_namp); if (i && i->todo_user) { /* we will update the existing entry */ @@ -532,16 +536,18 @@ static int write_temporary_shadow(const char *shadow_path, FILE **tmpfile, char r = putspent_sane(sp, shadow); if (r < 0) - return r; + return log_debug_errno(r, "Failed to add existing user \"%s\" to temporary shadow file: %m", + sp->sp_namp); + } if (r < 0) - return r; + return log_debug_errno(r, "Failed to read %s: %m", shadow_path); } else { if (errno != ENOENT) - return -errno; + return log_debug_errno(errno, "Failed to open %s: %m", shadow_path); if (fchmod(fileno(shadow), 0000) < 0) - return -errno; + return log_debug_errno(errno, "Failed to fchmod %s: %m", shadow_tmp); } ORDERED_HASHMAP_FOREACH(i, todo_uids) { @@ -590,18 +596,20 @@ static int write_temporary_shadow(const char *shadow_path, FILE **tmpfile, char r = putspent_sane(&n, shadow); if (r < 0) - return r; + return log_debug_errno(r, "Failed to add new user \"%s\" to temporary shadow file: %m", + sp->sp_namp); } /* Append the remaining NIS entries if any */ while (sp) { r = putspent_sane(sp, shadow); if (r < 0) - return r; + return log_debug_errno(r, "Failed to add existing user \"%s\" to temporary shadow file: %m", + sp->sp_namp); r = fgetspent_sane(original, &sp); if (r < 0) - return r; + return log_debug_errno(r, "Failed to read %s: %m", shadow_path); if (r == 0) break; } @@ -610,7 +618,7 @@ static int write_temporary_shadow(const char *shadow_path, FILE **tmpfile, char r = fflush_sync_and_check(shadow); if (r < 0) - return r; + return log_debug_errno(r, "Failed to flush %s: %m", shadow_tmp); *tmpfile = TAKE_PTR(shadow); *tmpfile_path = TAKE_PTR(shadow_tmp); @@ -631,14 +639,15 @@ static int write_temporary_group(const char *group_path, FILE **tmpfile, char ** r = fopen_temporary_label("/etc/group", group_path, &group, &group_tmp); if (r < 0) - return r; + return log_debug_errno(r, "Failed to open temporary copy of %s: %m", group_path); original = fopen(group_path, "re"); if (original) { r = copy_rights(fileno(original), fileno(group)); if (r < 0) - return r; + return log_debug_errno(r, "Failed to copy permissions from %s to %s: %m", + group_path, group_tmp); while ((r = fgetgrent_sane(original, &gr)) > 0) { /* Safety checks against name and GID collisions. Normally, @@ -663,18 +672,19 @@ static int write_temporary_group(const char *group_path, FILE **tmpfile, char ** r = putgrent_with_members(gr, group); if (r < 0) - return r; + return log_debug_errno(r, "Failed to add existing group \"%s\" to temporary group file: %m", + gr->gr_name); if (r > 0) group_changed = true; } if (r < 0) - return r; + return log_debug_errno(r, "Failed to read %s: %m", group_path); } else { if (errno != ENOENT) - return -errno; + return log_debug_errno(errno, "Failed to open %s: %m", group_path); if (fchmod(fileno(group), 0644) < 0) - return -errno; + return log_debug_errno(errno, "Failed to fchmod %s: %m", group_tmp); } ORDERED_HASHMAP_FOREACH(i, todo_gids) { @@ -686,7 +696,8 @@ static int write_temporary_group(const char *group_path, FILE **tmpfile, char ** r = putgrent_with_members(&n, group); if (r < 0) - return r; + return log_debug_errno(r, "Failed to add new group \"%s\" to temporary group file: %m", + gr->gr_name); group_changed = true; } @@ -695,18 +706,19 @@ static int write_temporary_group(const char *group_path, FILE **tmpfile, char ** while (gr) { r = putgrent_sane(gr, group); if (r < 0) - return r; + return log_debug_errno(r, "Failed to add existing group \"%s\" to temporary group file: %m", + gr->gr_name); r = fgetgrent_sane(original, &gr); if (r < 0) - return r; + return log_debug_errno(r, "Failed to read %s: %m", group_path); if (r == 0) break; } r = fflush_sync_and_check(group); if (r < 0) - return r; + return log_debug_errno(r, "Failed to flush %s: %m", group_tmp); if (group_changed) { *tmpfile = TAKE_PTR(group); @@ -728,7 +740,7 @@ static int write_temporary_gshadow(const char * gshadow_path, FILE **tmpfile, ch r = fopen_temporary_label("/etc/gshadow", gshadow_path, &gshadow, &gshadow_tmp); if (r < 0) - return r; + return log_debug_errno(r, "Failed to open temporary copy of %s: %m", gshadow_path); original = fopen(gshadow_path, "re"); if (original) { @@ -736,7 +748,8 @@ static int write_temporary_gshadow(const char * gshadow_path, FILE **tmpfile, ch r = copy_rights(fileno(original), fileno(gshadow)); if (r < 0) - return r; + return log_debug_errno(r, "Failed to copy permissions from %s to %s: %m", + gshadow_path, gshadow_tmp); while ((r = fgetsgent_sane(original, &sg)) > 0) { @@ -748,7 +761,8 @@ static int write_temporary_gshadow(const char * gshadow_path, FILE **tmpfile, ch r = putsgent_with_members(sg, gshadow); if (r < 0) - return r; + return log_debug_errno(r, "Failed to add existing group \"%s\" to temporary gshadow file: %m", + sg->sg_namp); if (r > 0) group_changed = true; } @@ -757,9 +771,9 @@ static int write_temporary_gshadow(const char * gshadow_path, FILE **tmpfile, ch } else { if (errno != ENOENT) - return -errno; + return log_debug_errno(errno, "Failed to open %s: %m", gshadow_path); if (fchmod(fileno(gshadow), 0000) < 0) - return -errno; + return log_debug_errno(errno, "Failed to fchmod %s: %m", gshadow_tmp); } ORDERED_HASHMAP_FOREACH(i, todo_gids) { @@ -770,14 +784,15 @@ static int write_temporary_gshadow(const char * gshadow_path, FILE **tmpfile, ch r = putsgent_with_members(&n, gshadow); if (r < 0) - return r; + return log_debug_errno(r, "Failed to add new group \"%s\" to temporary gshadow file: %m", + n.sg_namp); group_changed = true; } r = fflush_sync_and_check(gshadow); if (r < 0) - return r; + return log_debug_errno(r, "Failed to flush %s: %m", gshadow_tmp); if (group_changed) { *tmpfile = TAKE_PTR(gshadow); @@ -818,31 +833,31 @@ static int write_files(void) { if (group) { r = make_backup("/etc/group", group_path); if (r < 0) - return r; + return log_debug_errno(r, "Failed to make backup %s: %m", group_path); } if (gshadow) { r = make_backup("/etc/gshadow", gshadow_path); if (r < 0) - return r; + return log_debug_errno(r, "Failed to make backup %s: %m", gshadow_path); } if (passwd) { r = make_backup("/etc/passwd", passwd_path); if (r < 0) - return r; + return log_debug_errno(r, "Failed to make backup %s: %m", passwd_path); } if (shadow) { r = make_backup("/etc/shadow", shadow_path); if (r < 0) - return r; + return log_debug_errno(r, "Failed to make backup %s: %m", shadow_path); } /* And make the new files count */ if (group) { r = rename_and_apply_smack_floor_label(group_tmp, group_path); if (r < 0) - return r; - + return log_debug_errno(r, "Failed to rename %s to %s: %m", + group_tmp, group_path); group_tmp = mfree(group_tmp); if (!arg_root && !arg_image) @@ -851,7 +866,8 @@ static int write_files(void) { if (gshadow) { r = rename_and_apply_smack_floor_label(gshadow_tmp, gshadow_path); if (r < 0) - return r; + return log_debug_errno(r, "Failed to rename %s to %s: %m", + gshadow_tmp, gshadow_path); gshadow_tmp = mfree(gshadow_tmp); } @@ -859,7 +875,8 @@ static int write_files(void) { if (passwd) { r = rename_and_apply_smack_floor_label(passwd_tmp, passwd_path); if (r < 0) - return r; + return log_debug_errno(r, "Failed to rename %s to %s: %m", + passwd_tmp, passwd_path); passwd_tmp = mfree(passwd_tmp); @@ -869,7 +886,8 @@ static int write_files(void) { if (shadow) { r = rename_and_apply_smack_floor_label(shadow_tmp, shadow_path); if (r < 0) - return r; + return log_debug_errno(r, "Failed to rename %s to %s: %m", + shadow_tmp, shadow_path); shadow_tmp = mfree(shadow_tmp); } From 0520564dcf3e0adc8eb140f149c93351481c446c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Mon, 24 May 2021 11:33:50 +0200 Subject: [PATCH 3/4] basic: allow copy_rights() to work without mounted /proc This will be used in sysusers later on. --- src/basic/copy.c | 4 ++-- src/basic/copy.h | 5 ++++- src/basic/fs-util.c | 28 ++++++++++++++++++++++------ src/basic/fs-util.h | 5 ++++- 4 files changed, 32 insertions(+), 10 deletions(-) diff --git a/src/basic/copy.c b/src/basic/copy.c index af9ac842a1..ed9f2ba3ff 100644 --- a/src/basic/copy.c +++ b/src/basic/copy.c @@ -1243,7 +1243,7 @@ int copy_access(int fdf, int fdt) { return 0; } -int copy_rights(int fdf, int fdt) { +int copy_rights_with_fallback(int fdf, int fdt, const char *patht) { struct stat st; assert(fdf >= 0); @@ -1254,7 +1254,7 @@ int copy_rights(int fdf, int fdt) { if (fstat(fdf, &st) < 0) return -errno; - return fchmod_and_chown(fdt, st.st_mode & 07777, st.st_uid, st.st_gid); + return fchmod_and_chown_with_fallback(fdt, patht, st.st_mode & 07777, st.st_uid, st.st_gid); } int copy_xattr(int fdf, int fdt) { diff --git a/src/basic/copy.h b/src/basic/copy.h index da3ba07ad2..b36ddfcb01 100644 --- a/src/basic/copy.h +++ b/src/basic/copy.h @@ -64,5 +64,8 @@ static inline int copy_bytes(int fdf, int fdt, uint64_t max_bytes, CopyFlags cop int copy_times(int fdf, int fdt, CopyFlags flags); int copy_access(int fdf, int fdt); -int copy_rights(int fdf, int fdt); +int copy_rights_with_fallback(int fdf, int fdt, const char *patht); +static inline int copy_rights(int fdf, int fdt) { + return copy_rights_with_fallback(fdf, fdt, NULL); /* no fallback */ +} int copy_xattr(int fdf, int fdt); diff --git a/src/basic/fs-util.c b/src/basic/fs-util.c index e8435cab2c..a4d772777e 100644 --- a/src/basic/fs-util.c +++ b/src/basic/fs-util.c @@ -227,7 +227,7 @@ int chmod_and_chown(const char *path, mode_t mode, uid_t uid, gid_t gid) { return fchmod_and_chown(fd, mode, uid, gid); } -int fchmod_and_chown(int fd, mode_t mode, uid_t uid, gid_t gid) { +int fchmod_and_chown_with_fallback(int fd, const char *path, mode_t mode, uid_t uid, gid_t gid) { bool do_chown, do_chmod; struct stat st; int r; @@ -238,7 +238,11 @@ int fchmod_and_chown(int fd, mode_t mode, uid_t uid, gid_t gid) { * unaffected if the uid/gid is changed, i.e. it undoes implicit suid/sgid dropping the kernel does * on chown(). * - * This call is happy with O_PATH fds. */ + * This call is happy with O_PATH fds. + * + * If path is given, allow a fallback path which does not use /proc/self/fd/. On any normal system + * /proc will be mounted, but in certain improperly assembled environments it might not be. This is + * less secure (potential TOCTOU), so should only be used after consideration. */ if (fstat(fd, &st) < 0) return -errno; @@ -263,8 +267,14 @@ int fchmod_and_chown(int fd, mode_t mode, uid_t uid, gid_t gid) { if (((minimal ^ st.st_mode) & 07777) != 0) { r = fchmod_opath(fd, minimal & 07777); - if (r < 0) - return r; + if (r < 0) { + if (!path || r != -ENOSYS) + return r; + + /* Fallback path which doesn't use /proc/self/fd/. */ + if (chmod(path, minimal & 07777) < 0) + return -errno; + } } } @@ -274,8 +284,14 @@ int fchmod_and_chown(int fd, mode_t mode, uid_t uid, gid_t gid) { if (do_chmod) { r = fchmod_opath(fd, mode & 07777); - if (r < 0) - return r; + if (r < 0) { + if (!path || r != -ENOSYS) + return r; + + /* Fallback path which doesn't use /proc/self/fd/. */ + if (chmod(path, mode & 07777) < 0) + return -errno; + } } return do_chown || do_chmod; diff --git a/src/basic/fs-util.h b/src/basic/fs-util.h index 027037f7a7..7bac25704f 100644 --- a/src/basic/fs-util.h +++ b/src/basic/fs-util.h @@ -34,7 +34,10 @@ int readlink_value(const char *p, char **ret); int readlink_and_make_absolute(const char *p, char **r); int chmod_and_chown(const char *path, mode_t mode, uid_t uid, gid_t gid); -int fchmod_and_chown(int fd, mode_t mode, uid_t uid, gid_t gid); +int fchmod_and_chown_with_fallback(int fd, const char *path, mode_t mode, uid_t uid, gid_t gid); +static inline int fchmod_and_chown(int fd, mode_t mode, uid_t uid, gid_t gid) { + return fchmod_and_chown_with_fallback(fd, NULL, mode, uid, gid); /* no fallback */ +} int fchmod_umask(int fd, mode_t mode); int fchmod_opath(int fd, mode_t m); From 82855aa610510ddacf72bec03629839a7829e3b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Mon, 24 May 2021 11:34:16 +0200 Subject: [PATCH 4/4] sysusers: make sysusers work with dnf --installroot This is not very pretty, but the code in fs-util.c already provisions for missing /proc. We ourselves are careful to set up /proc, but not everybody is and it is important for sysusers to also work where shadow-utils would: I would like to replace calls to useradd and groupadd in Fedora systemd rpm scriptlets with a call to sysusers. It has a number of advantages: - dogfooding - we don't need to manually duplicate the information from our sysusers files to scriptlets - a dependency on shadow-utils is dropped, which transitively drops dependencies on setup and fedora-repos and bunch of other stuff. We could try to get 'dnf' and 'rpm --root' and such to be reworked, but not in any reasonable timeframe. And even if this was done, we'd still want to support older rpm/dnf versions. --- src/sysusers/sysusers.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/sysusers/sysusers.c b/src/sysusers/sysusers.c index 8e0d76ef46..5aa3531012 100644 --- a/src/sysusers/sysusers.c +++ b/src/sysusers/sysusers.c @@ -396,7 +396,11 @@ static int write_temporary_passwd(const char *passwd_path, FILE **tmpfile, char original = fopen(passwd_path, "re"); if (original) { - r = copy_rights(fileno(original), fileno(passwd)); + /* Allow fallback path for when /proc is not mounted. On any normal system /proc will be + * mounted, but e.g. when 'dnf --installroot' is used, it might not be. There is no security + * relevance here, since the environment is ultimately trusted, and not requiring /proc makes + * it easier to depend on sysusers in packaging scripts and suchlike. */ + r = copy_rights_with_fallback(fileno(original), fileno(passwd), passwd_tmp); if (r < 0) return log_debug_errno(r, "Failed to copy permissions from %s to %s: %m", passwd_path, passwd_tmp); @@ -513,7 +517,7 @@ static int write_temporary_shadow(const char *shadow_path, FILE **tmpfile, char original = fopen(shadow_path, "re"); if (original) { - r = copy_rights(fileno(original), fileno(shadow)); + r = copy_rights_with_fallback(fileno(original), fileno(shadow), shadow_tmp); if (r < 0) return log_debug_errno(r, "Failed to copy permissions from %s to %s: %m", shadow_path, shadow_tmp); @@ -644,7 +648,7 @@ static int write_temporary_group(const char *group_path, FILE **tmpfile, char ** original = fopen(group_path, "re"); if (original) { - r = copy_rights(fileno(original), fileno(group)); + r = copy_rights_with_fallback(fileno(original), fileno(group), group_tmp); if (r < 0) return log_debug_errno(r, "Failed to copy permissions from %s to %s: %m", group_path, group_tmp); @@ -746,7 +750,7 @@ static int write_temporary_gshadow(const char * gshadow_path, FILE **tmpfile, ch if (original) { struct sgrp *sg; - r = copy_rights(fileno(original), fileno(gshadow)); + r = copy_rights_with_fallback(fileno(original), fileno(gshadow), gshadow_tmp); if (r < 0) return log_debug_errno(r, "Failed to copy permissions from %s to %s: %m", gshadow_path, gshadow_tmp);