X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fsysusers%2Fsysusers.c;h=e47bcb4dca53853d68f55124e72ecfb7705302cf;hb=eef46c372f64f40dd75415b2c504c73138719c8d;hp=e69a5f58ad82d9195f8cfc77b17a443672d1c0c5;hpb=56f64d95763a799ba4475daf44d8e9f72a1bd474;p=elogind.git diff --git a/src/sysusers/sysusers.c b/src/sysusers/sysusers.c index e69a5f58a..e47bcb4dc 100644 --- a/src/sysusers/sysusers.c +++ b/src/sysusers/sysusers.c @@ -39,6 +39,7 @@ #include "label.h" #include "fileio-label.h" #include "uid-range.h" +#include "selinux-util.h" typedef enum ItemType { ADD_USER = 'u', @@ -76,17 +77,11 @@ static Hashmap *members = NULL; static Hashmap *database_uid = NULL, *database_user = NULL; static Hashmap *database_gid = NULL, *database_group = NULL; -static uid_t search_uid = (uid_t) -1; +static uid_t search_uid = UID_INVALID; static UidRange *uid_range = NULL; static unsigned n_uid_range = 0; -#define UID_TO_PTR(u) (ULONG_TO_PTR(u+1)) -#define PTR_TO_UID(u) ((uid_t) (PTR_TO_ULONG(u)-1)) - -#define GID_TO_PTR(g) (ULONG_TO_PTR(g+1)) -#define PTR_TO_GID(g) ((gid_t) (PTR_TO_ULONG(g)-1)) - -#define fix_root(x) (arg_root ? strappenda(arg_root, x) : x) +#define fix_root(x) (arg_root ? strjoina(arg_root, x) : x) static int load_user_database(void) { _cleanup_fclose_ FILE *f = NULL; @@ -215,14 +210,14 @@ static int make_backup(const char *target, const char *x) { if (r < 0) return r; - r = copy_bytes(src, fileno(dst), (off_t) -1); + r = copy_bytes(src, fileno(dst), (off_t) -1, true); if (r < 0) goto fail; /* Don't fail on chmod() or chown(). If it stays owned by us * and/or unreadable by others, then it isn't too bad... */ - backup = strappenda(x, "-"); + backup = strjoina(x, "-"); /* Copy over the access mask */ if (fchmod(fileno(dst), st.st_mode & 07777) < 0) @@ -898,10 +893,8 @@ static int add_user(Item *i) { i->description = strdup(p->pw_gecos); return 0; } - if (!IN_SET(errno, 0, ENOENT)) { - log_error_errno(errno, "Failed to check if user %s already exists: %m", i->name); - return -errno; - } + if (!IN_SET(errno, 0, ENOENT)) + return log_error_errno(errno, "Failed to check if user %s already exists: %m", i->name); /* And shadow too, just to be sure */ errno = 0; @@ -910,10 +903,8 @@ static int add_user(Item *i) { log_error("User %s already exists in shadow database, but not in user database.", i->name); return -EBADMSG; } - if (!IN_SET(errno, 0, ENOENT)) { - log_error_errno(errno, "Failed to check if user %s already exists in shadow database: %m", i->name); - return -errno; - } + if (!IN_SET(errno, 0, ENOENT)) + return log_error_errno(errno, "Failed to check if user %s already exists in shadow database: %m", i->name); } /* Try to use the suggested numeric uid */ @@ -1056,10 +1047,8 @@ static int add_group(Item *i) { i->gid_set = true; return 0; } - if (!IN_SET(errno, 0, ENOENT)) { - log_error_errno(errno, "Failed to check if group %s already exists: %m", i->name); - return -errno; - } + if (!IN_SET(errno, 0, ENOENT)) + return log_error_errno(errno, "Failed to check if group %s already exists: %m", i->name); } /* Try to use the suggested numeric gid */