This is the mail archive of the libc-hacker@sources.redhat.com mailing list for the glibc project.

Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] putgrent/putpwent and +/- entries


Hi,

putpwent and putgrent should not write a '0' as user/group id if an
entry starting with + or - is written. We have a check in the get*
code to ignore this, but it is better to not write the values and
let the fields empty.

  Thorsten

2005-01-11  Thorsten Kukuk <kukuk@suse.de>

	* 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 -.

--- grp/putgrent.c
+++ grp/putgrent.c	2003/10/15 11:14:18
@@ -44,8 +44,13 @@
 
   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);
--- pwd/putpwent.c
+++ pwd/putpwent.c	2003/10/15 11:10:20
@@ -35,11 +35,21 @@
       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;
 }

-- 
Thorsten Kukuk         http://www.suse.de/~kukuk/      kukuk@suse.de
SuSE Linux Products GmbH       Maxfeldstr. 5       D-90409 Nuernberg
--------------------------------------------------------------------    
Key fingerprint = A368 676B 5E1B 3E46 CFCE  2D97 F8FD 4E23 56C6 FB4B


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]