X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fsysusers%2Fsysusers.c;h=7820e849839079488e886cef61a2bd9f7b87478c;hp=c133dc5f1036b61b3dc2a8c8b22d5b1806ba5db8;hb=7f0a55d4325f7df91f91b3b818f61f97d78df14a;hpb=e3c72c21d62aadabf4df436c3e2c7219eeeccc1c diff --git a/src/sysusers/sysusers.c b/src/sysusers/sysusers.c index c133dc5f1..7820e8498 100644 --- a/src/sysusers/sysusers.c +++ b/src/sysusers/sysusers.c @@ -67,15 +67,7 @@ typedef struct Item { static char *arg_root = NULL; -static const char conf_file_dirs[] = - "/etc/sysusers.d\0" - "/run/sysusers.d\0" - "/usr/local/lib/sysusers.d\0" - "/usr/lib/sysusers.d\0" -#ifdef HAVE_SPLIT_USR - "/lib/sysusers.d\0" -#endif - ; +static const char conf_file_dirs[] = CONF_DIRS_NULSTR("sysusers"); static Hashmap *users = NULL, *groups = NULL; static Hashmap *todo_uids = NULL, *todo_gids = NULL; @@ -241,7 +233,8 @@ static int make_backup(const char *target, const char *x) { ts[0] = st.st_atim; ts[1] = st.st_mtim; - futimens(fileno(dst), ts); + if (futimens(fileno(dst), ts) < 0) + log_warning("Failed to fix access and modification time of %s: %m", backup); if (rename(temp, backup) < 0) goto fail; @@ -353,12 +346,26 @@ static int putsgent_with_members(const struct sgrp *sg, FILE *gshadow) { return 0; } +static int sync_rights(FILE *from, FILE *to) { + struct stat st; + + if (fstat(fileno(from), &st) < 0) + return -errno; + + if (fchmod(fileno(to), st.st_mode & 07777) < 0) + return -errno; + + if (fchown(fileno(to), st.st_uid, st.st_gid) < 0) + return -errno; + + return 0; +} + static int write_files(void) { _cleanup_fclose_ FILE *passwd = NULL, *group = NULL, *shadow = NULL, *gshadow = NULL; _cleanup_free_ 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; - struct stat st; bool group_changed = false; Iterator iterator; Item *i; @@ -377,12 +384,9 @@ static int write_files(void) { if (original) { struct group *gr; - if (fstat(fileno(original), &st) < 0 || - fchmod(fileno(group), st.st_mode & 07777) < 0 || - fchown(fileno(group), st.st_uid, st.st_gid) < 0) { - r = -errno; + r = sync_rights(original, group); + if (r < 0) goto finish; - } errno = 0; while ((gr = fgetgrent(original))) { @@ -459,12 +463,9 @@ static int write_files(void) { if (original) { struct sgrp *sg; - if (fstat(fileno(original), &st) < 0 || - fchmod(fileno(gshadow), st.st_mode & 07777) < 0 || - fchown(fileno(gshadow), st.st_uid, st.st_gid) < 0) { - r = -errno; + r = sync_rights(original, gshadow); + if (r < 0) goto finish; - } errno = 0; while ((sg = fgetsgent(original))) { @@ -528,12 +529,9 @@ static int write_files(void) { if (original) { struct passwd *pw; - if (fstat(fileno(original), &st) < 0 || - fchmod(fileno(passwd), st.st_mode & 07777) < 0 || - fchown(fileno(passwd), st.st_uid, st.st_gid) < 0) { - r = -errno; + r = sync_rights(original, passwd); + if (r < 0) goto finish; - } errno = 0; while ((pw = fgetpwent(original))) { @@ -616,12 +614,9 @@ static int write_files(void) { if (original) { struct spwd *sp; - if (fstat(fileno(original), &st) < 0 || - fchmod(fileno(shadow), st.st_mode & 07777) < 0 || - fchown(fileno(shadow), st.st_uid, st.st_gid) < 0) { - r = -errno; + r = sync_rights(original, shadow); + if (r < 0) goto finish; - } errno = 0; while ((sp = fgetspent(original))) {