summaryrefslogtreecommitdiff
path: root/src/sysusers
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2021-05-24 09:15:39 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2021-05-24 21:39:04 +0200
commit62d1c93a0260286f9114ee7ab59df026d93be19d (patch)
tree6d2778a7edb3213e194a9c3c6df4022cd1a2a0ec /src/sysusers
parent341d883ad69bab3f0c2772302118497eaf7798ff (diff)
downloadsystemd-62d1c93a0260286f9114ee7ab59df026d93be19d.tar.gz
sysusers: reduce scope of variables and drop unnecessary initializations
Diffstat (limited to 'src/sysusers')
-rw-r--r--src/sysusers/sysusers.c21
1 files 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;
}