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.
This commit is contained in:
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user