about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRoland McGrath <roland@gnu.org>2005-07-18 03:08:46 +0000
committerRoland McGrath <roland@gnu.org>2005-07-18 03:08:46 +0000
commit79e7ba1611c2002e376f972131e705f30142ef68 (patch)
treed8d95a6c258b919eb08def2c74005638c7d91a46
parenta8f2e5659fe008d2c38e349ed5315e43fbd0e0d5 (diff)
downloadglibc-79e7ba1611c2002e376f972131e705f30142ef68.tar.gz
glibc-79e7ba1611c2002e376f972131e705f30142ef68.tar.xz
glibc-79e7ba1611c2002e376f972131e705f30142ef68.zip
2005-01-11 Thorsten Kukuk <kukuk@suse.de>
	[BZ #1099]
	* grp/putgrent.c (putgrent): Don't write 0 as group
	ID if groupname starts with + or -.
	* pwd/putpwent.c (putpwent): Don't write 0 as user or
	group ID if user name starts with + or -.
-rw-r--r--grp/putgrent.c9
-rw-r--r--pwd/putpwent.c24
2 files changed, 24 insertions, 9 deletions
diff --git a/grp/putgrent.c b/grp/putgrent.c
index cb9b6b1f79..8280b0cb2f 100644
--- a/grp/putgrent.c
+++ b/grp/putgrent.c
@@ -44,8 +44,13 @@ putgrent (gr, stream)
 
   flockfile (stream);
 
-  retval = fprintf (stream, "%s:%s:%u:",
-		    gr->gr_name, _S (gr->gr_passwd), gr->gr_gid);
+  if (gr->gr_name[0] == '+' || gr->gr_name[0] == '-')
+    retval = fprintf (stream, "%s:%s::",
+		      gr->gr_name, _S (gr->gr_passwd));
+  else
+    retval = fprintf (stream, "%s:%s:%lu:",
+		      gr->gr_name, _S (gr->gr_passwd),
+		      (unsigned long int) gr->gr_gid);
   if (__builtin_expect (retval, 0) < 0)
     {
       funlockfile (stream);
diff --git a/pwd/putpwent.c b/pwd/putpwent.c
index 8b7767bd4a..a265719d36 100644
--- a/pwd/putpwent.c
+++ b/pwd/putpwent.c
@@ -20,7 +20,7 @@
 #include <stdio.h>
 #include <pwd.h>
 
-#define _S(x)	x ? x : ""
+#define _S(x)	x ?: ""
 
 /* Write an entry to the given stream.
    This must know the format of the password file.  */
@@ -35,11 +35,21 @@ putpwent (p, stream)
       return -1;
     }
 
-  if (fprintf (stream, "%s:%s:%lu:%lu:%s:%s:%s\n",
-	       p->pw_name, _S (p->pw_passwd),
-	       (unsigned long int) p->pw_uid, (unsigned long int) p->pw_gid,
-	       _S (p->pw_gecos), _S (p->pw_dir), _S (p->pw_shell)) < 0)
-    return -1;
-
+  if (p->pw_name[0] == '+' || p->pw_name[0] == '-')
+    {
+      if (fprintf (stream, "%s:%s:::%s:%s:%s\n",
+		   p->pw_name, _S (p->pw_passwd),
+		   _S (p->pw_gecos), _S (p->pw_dir), _S (p->pw_shell)) < 0)
+	return -1;
+    }
+  else
+    {
+      if (fprintf (stream, "%s:%s:%lu:%lu:%s:%s:%s\n",
+		   p->pw_name, _S (p->pw_passwd),
+		   (unsigned long int) p->pw_uid,
+		   (unsigned long int) p->pw_gid,
+		   _S (p->pw_gecos), _S (p->pw_dir), _S (p->pw_shell)) < 0)
+	return -1;
+    }
   return 0;
 }