Subject: Re: strange nis behaviour
To: Antoine Reilles <Antoine.Reilles@loria.fr>
From: Luke Mewburn <lukem@NetBSD.org>
List: current-users
Date: 02/20/2005 18:51:58
--wwSFAA0Com6UqrPP
Content-Type: multipart/mixed; boundary="ONmcTkPhtkbQYSLg"
Content-Disposition: inline


--ONmcTkPhtkbQYSLg
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Sat, Feb 19, 2005 at 02:24:49PM +0100, Antoine Reilles wrote:
  | On Mon, Feb 07, 2005 at 11:33:14AM +1100, Luke Mewburn wrote:
  | > I've examined the getpwent.c (and getgrent.c) code, and the behaviour
  | > in 2.0 was to skip "dodgy" (un-parseable) entries in getpwent() and
  | > getgrent().
  | > When I overhauled this code recently in -current, I changed the
  | > behaviour to fail the getXXent() lookup when an entry couldn't be
  | > parsed.  This change is causing your problem.
  | >=20
  | > I will look at the getpwent.c (and getgrent.c) code and make it more
  | > robust in the event of "corrupt" entries.
  | >=20
  | > Could you please submit a PR about this problem?
  |=20
  | Oh, i forgot to note i sent the pr a while ago
  | http://www.netbsd.org/cgi-bin/query-pr-single.pl?number=3D29272
  | however, it is probably not really acurate

Could you test the attached diff against -current sources?

I've had it ready to commit for a while but haven't had a
chance to setup a test NIS environment to confirm that
it works correctly.

Thanks,
Luke.

--ONmcTkPhtkbQYSLg
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="getpwent-nisfix.diff"
Content-Transfer-Encoding: quoted-printable

Index: gen/getpwent.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvsroot/src/lib/libc/gen/getpwent.c,v
retrieving revision 1.65
diff -p -p -u -r1.65 getpwent.c
--- gen/getpwent.c	10 Nov 2004 12:57:32 -0000	1.65
+++ gen/getpwent.c	20 Feb 2005 07:50:31 -0000
@@ -1,7 +1,7 @@
 /*	$NetBSD: getpwent.c,v 1.65 2004/11/10 12:57:32 lukem Exp $	*/
=20
 /*-
- * Copyright (c) 1997-2000, 2004 The NetBSD Foundation, Inc.
+ * Copyright (c) 1997-2000, 2004-2005 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -836,6 +836,7 @@ _dns_getpwent(void *nsrv, void *nscb, va
 	hp =3D NULL;
 	rv =3D NS_NOTFOUND;
=20
+ next_dns_entry:
 							/* find passwd-NNN */
 	snprintf(_dns_passwdbuf, sizeof(_dns_passwdbuf),
 	    "passwd-%u", _dns_state.num);
@@ -854,8 +855,10 @@ _dns_getpwent(void *nsrv, void *nscb, va
 		if (_pw_parse(hp[0], &_dns_passwd,
 		    _dns_passwdbuf, sizeof(_dns_passwdbuf), 1))
 			rv =3D NS_SUCCESS;
-		else
-			rv =3D NS_UNAVAIL;
+		else {				/* dodgy entry, try again */
+			hesiod_free_list(_dns_state.context, hp);
+			goto next_dns_entry;
+		}
 	}
=20
 	if (hp)
@@ -1249,6 +1252,7 @@ _nis_getpwent(void *nsrv, void *nscb, va
 			return rv;
 	}
=20
+ next_nis_entry:
 	key =3D NULL;
 	data =3D NULL;
 	rv =3D NS_NOTFOUND;
@@ -1286,8 +1290,12 @@ _nis_getpwent(void *nsrv, void *nscb, va
 	if (_nis_parse(data, &_nis_passwd,
 	    _nis_passwdbuf, sizeof(_nis_passwdbuf), &_nis_state))
 		rv =3D NS_SUCCESS;
-	else
-		rv =3D NS_UNAVAIL;
+	else {					/* dodgy entry, try again */
+		if (key)
+			free(key);
+		free(data);
+		goto next_nis_entry;
+	}
=20
  nisent_out:
 	if (key)

--ONmcTkPhtkbQYSLg--

--wwSFAA0Com6UqrPP
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (NetBSD)

iD8DBQFCGEGepBhtmn8zJHIRApHXAJwLy+huA399sQ4aWjstC6S1ZV4k2wCgn5Mp
PgAKMQu7GauNNKCYFOzswUs=
=MPoN
-----END PGP SIGNATURE-----

--wwSFAA0Com6UqrPP--