]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sysusers: make sure to reset errno before calling fget*ent() 8499/head
authorFranck Bui <fbui@suse.com>
Tue, 20 Mar 2018 10:38:00 +0000 (11:38 +0100)
committerFranck Bui <fbui@suse.com>
Tue, 20 Mar 2018 10:38:39 +0000 (11:38 +0100)
Due to the glibc interface we have to test errno in various places to detect if
an error occured after calling fget*ent() helpers.

src/sysusers/sysusers.c

index 0af4af06aadd6a25a8e441254a9e43362dfb258f..43952e5f194d76b66aeb96150766d0fdf5278d5c 100644 (file)
@@ -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))