Subject: Strange behaviour of innetgr(3)
To: None <current-users@NetBSD.ORG, rhialto@polder.ubc.kun.nl>
From: Olaf Seibert <rhialto@polder.ubc.kun.nl>
List: current-users
Date: 06/06/1997 17:15:47
(This is with 1.2 but I expect that -current behaves the same)

It seems that innetgr() behaves different than I expect. I wonder
if I misunderstand things, or if this is actually a bug.

The following re-implementation of innetgr is part of Samba.
Note that it looks suspiciously like the implementation that NetBSD
used in 1.0 (except that it doesn't crash with NULL pointers).

#ifdef REPLACE_INNETGR
/*
 * Search for a match in a netgroup. This replaces it on broken systems.
 */
int InNetGr(char *group,char *host,char *user,char *dom)
{
  char *hst, *usr, *dm;
  
  DEBUG(3, ("InNetGr: group: %s, host: %s, user: %s, dom: %s\n",
	              group    , host    , user    , dom));
#undef innetgr
  DEBUG(3, ("InNetGr: innetgr would return %d\n",
	  innetgr(group, host, user, dom)));

  setnetgrent(group);
  while (getnetgrent(&hst, &usr, &dm))
    if (((host == 0) || (hst == 0) || !strcmp(host, hst)) &&
	((user == 0) || (usr == 0) || !strcmp(user, usr)) &&
	((dom == 0) || (dm == 0) || !strcmp(dom, dm))) {
      endnetgrent();
      return (1);
    }
  endnetgrent();
  return (0);
}
#endif

My debugging logs show cases where this version returns 1,
where innetgr() returns 0:

InNetGr: group: polders, host: wiering.ubc.kun.nl, user: (null), dom: ubc.kun.nl
InNetGr: innetgr would return 0

This is (part of) the netgroup file:

# Polderland netgroups file
# Don't forget to run netgroup_mkdb after editing this...
polders	(polder.ubc.kun.nl,,) ixpolders polpcs 
ixpolders (purmer.ubc.kun.nl,,) \
	(schermer.ubc.kun.nl,,)
polpcs	(wormer.ubc.kun.nl,,) \
	(wiering.ubc.kun.nl,,) \
	(haarlem.ubc.kun.nl,,)
nfspolders	(wormer.ubc.kun.nl,,)

The only way to get NetBSD 1.2's innetgr() to return 1 for these parameters,
is to add (wiering.ubc.kun.nl,,ubc.kun.nl) directly to the ixpolders line.
Anything less won't do.

Bug?

-Olaf.
--
___ Olaf 'Rhialto' Seibert      D787B44DFC896063 4CBB95A5BD1DAA96 
\X/ It's not easy having a good time    rhialto@polder.ubc.kun.nl