Arbitrary group length restriction in chkname.c

Gordon Rowell <[email protected]>
Newsgroups gmane.linux.pld.shadow.general
Message-ID <[email protected]>
Hi there,

[ See also https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=56850 ]

The code in libmisc/chkname.c has this for validating group names:

int
check_group_name(const char *name)
{
         /*
          * Arbitrary limit for group names - max 16
          * characters (same as on HP-UX 10).
          */
         if (strlen(name) > 16)
                 return 0;
[...]

Whereas the code for validating user names is:

int
check_user_name(const char *name)
{
#if HAVE_UTMPX_H
         struct utmpx ut;
#else
         struct utmp ut;
#endif

         /*
          * User names are limited by whatever utmp can
          * handle (usually max 8 characters).
          */
         if (strlen(name) > sizeof(ut.ut_user))
                 return 0;

[...]

Where (on RH7.3):

struct utmpx
{
...
   char ut_user[__UT_NAMESIZE];  /* Username.  */
...
};

and

#define __UT_NAMESIZE   32

The patch below changes the the group code to use the same length
as for users. It seems to work nicely for me on RH 7.3 and I can
happily add both users and groups up to 32 characters.

Is there a good reason to have the constant 16, or could that
be conditional for HP-UX?

Thanks,

Gordon
--
  Gordon Rowell [email protected]  http://www.gormand.com.au
  Gormand Pty Ltd  PO Box 239 St Pauls NSW 2031 Australia
   "The test of our progress is not whether we add more to the abundance
   of those who have much; it is whether we provide enough for those who
   have too little." Franklin D Roosevelt, Second Inaugural Address, 1937

---CUT HERE------CUT HERE------CUT HERE------CUT HERE------CUT HERE---
diff -rNu shadow-20000902.orig/libmisc/chkname.c 
shadow-20000902/libmisc/chkname.c
--- shadow-20000902.orig/libmisc/chkname.c	Thu Apr 16 15:57:43 1998
+++ shadow-20000902/libmisc/chkname.c	Thu Oct 14 06:32:30 2004
@@ -62,11 +62,17 @@
  int
  check_group_name(const char *name)
  {
+#if HAVE_UTMPX_H
+        struct utmpx ut;
+#else
+        struct utmp ut;
+#endif
+
  	/*
  	 * Arbitrary limit for group names - max 16
  	 * characters (same as on HP-UX 10).
  	 */
-	if (strlen(name) > 16)
+	if (strlen(name) > sizeof(ut.ut_user))
  		return 0;

  	return good_name(name);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.