X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fsysusers%2Fsysusers.c;h=845a307ae71d912984ff76d36ddcaf806b15d918;hb=8d3d7072e609ef0e0fb37e1d19a29307d58146c3;hp=04e973ac17bf784520257ec7b51c3bc0304fc9c4;hpb=fff19499605924251d037073f47665419b669400;p=elogind.git diff --git a/src/sysusers/sysusers.c b/src/sysusers/sysusers.c index 04e973ac1..845a307ae 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; @@ -927,10 +919,8 @@ static int add_user(Item *i) { /* Try to use the suggested numeric uid */ if (i->uid_set) { r = uid_is_ok(i->uid, i->name); - if (r < 0) { - log_error("Failed to verify uid " UID_FMT ": %s", i->uid, strerror(-r)); - return r; - } + if (r < 0) + return log_error_errno(r, "Failed to verify uid " UID_FMT ": %m", i->uid); if (r == 0) { log_debug("Suggested user ID " UID_FMT " for %s already used.", i->uid, i->name); i->uid_set = false; @@ -947,10 +937,9 @@ static int add_user(Item *i) { log_debug("User ID " UID_FMT " of file not suitable for %s.", c, i->name); else { r = uid_is_ok(c, i->name); - if (r < 0) { - log_error("Failed to verify uid " UID_FMT ": %s", i->uid, strerror(-r)); - return r; - } else if (r > 0) { + if (r < 0) + return log_error_errno(r, "Failed to verify uid " UID_FMT ": %m", i->uid); + else if (r > 0) { i->uid = c; i->uid_set = true; } else @@ -962,10 +951,8 @@ static int add_user(Item *i) { /* Otherwise try to reuse the group ID */ if (!i->uid_set && i->gid_set) { r = uid_is_ok((uid_t) i->gid, i->name); - if (r < 0) { - log_error("Failed to verify uid " UID_FMT ": %s", i->uid, strerror(-r)); - return r; - } + if (r < 0) + return log_error_errno(r, "Failed to verify uid " UID_FMT ": %m", i->uid); if (r > 0) { i->uid = (uid_t) i->gid; i->uid_set = true; @@ -982,10 +969,9 @@ static int add_user(Item *i) { } r = uid_is_ok(search_uid, i->name); - if (r < 0) { - log_error("Failed to verify uid " UID_FMT ": %s", i->uid, strerror(-r)); - return r; - } else if (r > 0) + if (r < 0) + return log_error_errno(r, "Failed to verify uid " UID_FMT ": %m", i->uid); + else if (r > 0) break; } @@ -1079,10 +1065,8 @@ static int add_group(Item *i) { /* Try to use the suggested numeric gid */ if (i->gid_set) { r = gid_is_ok(i->gid); - if (r < 0) { - log_error("Failed to verify gid " GID_FMT ": %s", i->gid, strerror(-r)); - return r; - } + if (r < 0) + return log_error_errno(r, "Failed to verify gid " GID_FMT ": %m", i->gid); if (r == 0) { log_debug("Suggested group ID " GID_FMT " for %s already used.", i->gid, i->name); i->gid_set = false; @@ -1092,10 +1076,8 @@ static int add_group(Item *i) { /* Try to reuse the numeric uid, if there's one */ if (!i->gid_set && i->uid_set) { r = gid_is_ok((gid_t) i->uid); - if (r < 0) { - log_error("Failed to verify gid " GID_FMT ": %s", i->gid, strerror(-r)); - return r; - } + if (r < 0) + return log_error_errno(r, "Failed to verify gid " GID_FMT ": %m", i->gid); if (r > 0) { i->gid = (gid_t) i->uid; i->gid_set = true; @@ -1112,10 +1094,9 @@ static int add_group(Item *i) { log_debug("Group ID " GID_FMT " of file not suitable for %s.", c, i->name); else { r = gid_is_ok(c); - if (r < 0) { - log_error("Failed to verify gid " GID_FMT ": %s", i->gid, strerror(-r)); - return r; - } else if (r > 0) { + if (r < 0) + return log_error_errno(r, "Failed to verify gid " GID_FMT ": %m", i->gid); + else if (r > 0) { i->gid = c; i->gid_set = true; } else @@ -1135,10 +1116,9 @@ static int add_group(Item *i) { } r = gid_is_ok(search_uid); - if (r < 0) { - log_error("Failed to verify gid " GID_FMT ": %s", i->gid, strerror(-r)); - return r; - } else if (r > 0) + if (r < 0) + return log_error_errno(r, "Failed to verify gid " GID_FMT ": %m", i->gid); + else if (r > 0) break; } @@ -1729,8 +1709,7 @@ static int read_config_file(const char *fn, bool ignore_enoent) { if (ignore_enoent && r == -ENOENT) return 0; - log_error("Failed to open '%s', ignoring: %s", fn, strerror(-r)); - return r; + return log_error_errno(r, "Failed to open '%s', ignoring: %m", fn); } f = rf; @@ -1861,7 +1840,7 @@ int main(int argc, char *argv[]) { r = mac_selinux_init(NULL); if (r < 0) { - log_error("SELinux setup failed: %s", strerror(-r)); + log_error_errno(r, "SELinux setup failed: %m"); goto finish; } @@ -1879,7 +1858,7 @@ int main(int argc, char *argv[]) { r = conf_files_list_nulstr(&files, ".conf", arg_root, conf_file_dirs); if (r < 0) { - log_error("Failed to enumerate sysusers.d files: %s", strerror(-r)); + log_error_errno(r, "Failed to enumerate sysusers.d files: %m"); goto finish; } @@ -1905,19 +1884,19 @@ int main(int argc, char *argv[]) { lock = take_password_lock(arg_root); if (lock < 0) { - log_error("Failed to take lock: %s", strerror(-lock)); + log_error_errno(lock, "Failed to take lock: %m"); goto finish; } r = load_user_database(); if (r < 0) { - log_error("Failed to load user database: %s", strerror(-r)); + log_error_errno(r, "Failed to load user database: %m"); goto finish; } r = load_group_database(); if (r < 0) { - log_error("Failed to read group database: %s", strerror(-r)); + log_error_errno(r, "Failed to read group database: %m"); goto finish; } @@ -1929,7 +1908,7 @@ int main(int argc, char *argv[]) { r = write_files(); if (r < 0) - log_error("Failed to write files: %s", strerror(-r)); + log_error_errno(r, "Failed to write files: %m"); finish: while ((i = hashmap_steal_first(groups)))