summaryrefslogtreecommitdiff
path: root/src/sysusers
diff options
context:
space:
mode:
authorFranck Bui <fbui@suse.com>2018-03-20 11:38:00 +0100
committerFranck Bui <fbui@suse.com>2018-03-20 11:38:39 +0100
commit8c1b45aa9cc0241bdf2c143df493ddf2596ae8b1 (patch)
tree1ce4a2313c6f189ddc0c46e3a58c4d415f0abf0d /src/sysusers
parent19ec7de2d65ad01a76a2f8672363e72c43607934 (diff)
downloadsystemd-8c1b45aa9cc0241bdf2c143df493ddf2596ae8b1.tar.gz
sysusers: make sure to reset errno before calling fget*ent()
Due to the glibc interface we have to test errno in various places to detect if an error occured after calling fget*ent() helpers.
Diffstat (limited to 'src/sysusers')
-rw-r--r--src/sysusers/sysusers.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/sysusers/sysusers.c b/src/sysusers/sysusers.c
index 0af4af06aa..43952e5f19 100644
--- a/src/sysusers/sysusers.c
+++ b/src/sysusers/sysusers.c
@@ -429,11 +429,12 @@ static int write_temporary_passwd(const char *passwd_path, FILE **tmpfile, char
return -EEXIST;
}
+ errno = 0;
+
/* Make sure we keep the NIS entries (if any) at the end. */
if (IN_SET(pw->pw_name[0], '+', '-'))
break;
- errno = 0;
if (putpwent(pw, passwd) < 0)
return errno ? -errno : -EIO;
@@ -471,6 +472,7 @@ static int write_temporary_passwd(const char *passwd_path, FILE **tmpfile, char
if (putpwent(&n, passwd) != 0)
return errno ? -errno : -EIO;
}
+ errno = 0;
/* Append the remaining NIS entries if any */
while (pw) {
@@ -478,6 +480,7 @@ static int write_temporary_passwd(const char *passwd_path, FILE **tmpfile, char
if (putpwent(pw, passwd) < 0)
return errno ? -errno : -EIO;
+ errno = 0;
pw = fgetpwent(original);
}
if (!IN_SET(errno, 0, ENOENT))
@@ -637,6 +640,8 @@ static int write_temporary_group(const char *group_path, FILE **tmpfile, char **
return -EEXIST;
}
+ errno = 0;
+
/* Make sure we keep the NIS entries (if any) at the end. */
if (IN_SET(gr->gr_name[0], '+', '-'))
break;
@@ -672,6 +677,7 @@ static int write_temporary_group(const char *group_path, FILE **tmpfile, char **
group_changed = true;
}
+ errno = 0;
/* Append the remaining NIS entries if any */
while (gr) {
@@ -679,6 +685,7 @@ static int write_temporary_group(const char *group_path, FILE **tmpfile, char **
if (putgrent(gr, group) != 0)
return errno > 0 ? -errno : -EIO;
+ errno = 0;
gr = fgetgrent(original);
}
if (!IN_SET(errno, 0, ENOENT))