Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 11 Dec 1999 20:45:04 +0100 (CET)
From:      tobez@plab.ku.dk
To:        FreeBSD-gnats-submit@freebsd.org
Subject:   misc/15421: initgroups(3) spits out messages to stderr;  it probably shouldn't
Message-ID:  <199912111945.UAA51696@lion.plab.ku.dk>

next in thread | raw e-mail | index | archive | help


>Number:         15421
>Category:       misc
>Synopsis:       initgroups(3) spits out messages to stderr;  it probably shouldn't
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Dec 11 11:50:02 PST 1999
>Closed-Date:
>Last-Modified:
>Originator:     Anton Berezin
>Release:        FreeBSD 4.0-CURRENT i386
>Organization:
The Protein Laboratory, University of Copenhagen
>Environment:

src/lib/libc/gen/initgroups.c since 1994.

>Description:

On two occasions, initgroups(3) uses warn()/warnx() to print messages on
the standard error.  The first one might be justified (`user is in too
many groups'), the second one, which reports the failure of the call to
setgroups(2), is definitely not:  in this case initgroups(3) returns -1,
and errno will be set by setgroups(2), so the caller is able to perform
a check on its own.

This warning bites, for example, when CVS in pserver mode is run as
non-root:  the warning gets printed due to EPERM, and the CVS client
gets confused by unexpected output.

If, for whatever reasons, you decide to keep this warning, please do fix
the manpage, which does not say a thing about such behavior.  A good
example is the getbsize(3) manpage, it clearly states the possibility of
writing warning messages.

>How-To-Repeat:

Compile and run as non-root this program:

   #include <errno.h>
   #include <unistd.h>
   #include <sys/types.h>
   #include <pwd.h>

   int
   main( void)
   {
      struct passwd *pw = getpwuid( getuid());

      if (!pw)
         errc( 1, errno, "getpwuid() failed");
      if ( initgroups( pw-> pw_name, pw-> pw_gid) < 0)
         errc( 1, errno, "initgroups(3) failed");
      return 0;
   }

You should get this:

   initg: setgroups: Operation not permitted
   initg: initgroups(3) failed: Operation not permitted

>Fix:

The fix I prefer (note that the first warning stays where it is):

--- /usr/src/lib/libc/gen/initgroups.c	Fri Jul 12 20:53:56 1996
+++ initgroups.c	Sat Dec 11 20:30:54 1999
@@ -53,7 +53,6 @@
 		warnx("%s is in too many groups, using first %d",
 		    uname, ngroups);
 	if (setgroups(ngroups, groups) < 0) {
-		warn("setgroups");
 		return (-1);
 	}
 	return (0);
--- /usr/src/lib/libc/gen/initgroups.3	Sun Aug 29 12:40:15 1999
+++ initgroups.3	Sat Dec 11 20:42:03 1999
@@ -58,6 +58,13 @@
 is automatically included in the groups list.
 Typically this value is given as
 the group number from the password file.
+.Pp
+If the user is in too many groups, a warning message is written
+to standard error and the first
+.Dv NGROUPS ,
+as defined in 
+.Ao Pa sys/param.h Ac ,
+are used.
 .Sh RETURN VALUES
 The
 .Fn initgroups


Cheers, Anton.


>Release-Note:
>Audit-Trail:
>Unformatted:


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199912111945.UAA51696>