Subject: Suggestion to improve getgrent.c
To: None <netbsd-bugs@sun-lamp.cs.berkeley.edu>
From: Rolf Grossmann <grossman@informatik.tu-muenchen.de>
List: netbsd-bugs
Date: 07/29/1994 22:48:04
Hi,

I suggest the following 2 changes to /usr/src/lib/libc/gen/getgrent.c:

The first one makes the checking for YP less strict (and compatible to
the SunOS implementation).

The second one fixes a kind of a bug, that makes login (and probably some
other programs) dump core, when an incomplete group entry is encountered.

I've hit those problems, when I simply copied our SunOS /etc/groups file
to the NetBSD/sparc I'm setting up. The last line was 
+:
which works fine on SunOS, but prevented me from logging into the NetBSD
system.

Ok, here are is the diff listing:

*** getgrent.c.orig     Fri Jul 29 22:26:45 1994
--- getgrent.c  Fri Jul 29 22:25:57 1994
***************
*** 223,229 ****
                        continue;
                }
  #ifdef YP
!               if ((strcmp("+\n", line) == 0) || (strncmp("+:*:0:", line, 5) == 0)) {
                        if(_yp_check(NULL)) {
                                __ypmode = 1;
                                continue;
--- 223,229 ----
                        continue;
                }
  #ifdef YP
!               if ((strcmp("+\n", line) == 0) || (strncmp("+:", line, 2) == 0)) {
                        if(_yp_check(NULL)) {
                                __ypmode = 1;
                                continue;
***************
*** 235,241 ****
                if (search && name && strcmp(_gr_group.gr_name, name))
                        continue;
                _gr_group.gr_passwd = strsep(&bp, ":\n");
!               if (!(cp = strsep(&bp, ":\n")))
                        continue;
                _gr_group.gr_gid = atoi(cp);
                if (search && name == NULL && _gr_group.gr_gid != gid)
--- 235,241 ----
                if (search && name && strcmp(_gr_group.gr_name, name))
                        continue;
                _gr_group.gr_passwd = strsep(&bp, ":\n");
!               if (!(cp = strsep(&bp, ":\n")) || !bp)
                        continue;
                _gr_group.gr_gid = atoi(cp);
                if (search && name == NULL && _gr_group.gr_gid != gid)

Bye, Rolf

------------------------------------------------------------------------------