Subject: Re: Fwd: libc without YP
To: Luke Mewburn <lukem@NetBSD.org>
From: Greg A. Woods <woods@weird.com>
List: tech-toolchain
Date: 11/27/2003 01:45:35
[ On Wednesday, November 26, 2003 at 11:50:24 (+1100), Luke Mewburn wrote: ]
> Subject: Re: Fwd: libc without YP
>
> I've fixed gen/getpwent.c when compiling with -UYP -DHESIOD
> (AKA 'make MKYP=no MKHESIOD=yes')

I've not looked at your changes in -current yet (and won't have time for
many weeks I'm afraid), but while I'm skimming through these messages to
get caught up to date I will note that in netbsd-1-6 there are some
other minor changes necessary (over and above what I initially found to
be necessary just to get the compile to work) in order to actually
eliminated all the unnecessary code.  There may be some other changes
necessary outside of getpwent.c too, but if so I forget where.  :-)

BTW, I also remove /etc/nsswitch.conf as opening and reading it just
slows things down even more and the default is now effectively the only
valid configuration.

Index: lib/libc/gen/getpwent.c
===================================================================
RCS file: /cvs/master/m-NetBSD/main/src/lib/libc/gen/getpwent.c,v
retrieving revision 1.50
diff -u -r1.50 getpwent.c
--- lib/libc/gen/getpwent.c	16 Apr 2002 19:10:07 -0000	1.50
+++ lib/libc/gen/getpwent.c	24 Jul 2003 20:26:24 -0000
@@ -107,11 +107,21 @@
 static int __hashpw __P((DBT *));
 static int __initdb __P((void));
 
-const char __yp_token[] = "__YP!";	/* Let pwd_mkdb pull this in. */
+
+#ifndef _PASSWD_COMPAT
+
+static const ns_src compatsrc[] = {
+	{ NSSRC_FILES, NS_SUCCESS },
+	{ 0 }
+};
+
+#else
+
 static const ns_src compatsrc[] = {
 	{ NSSRC_COMPAT, NS_SUCCESS },
 	{ 0 }
 };
+const char __yp_token[] = "__YP!";	/* Let pwd_mkdb pull this in. */
 
 #ifdef YP
 static char     *__ypcurrent, *__ypdomain;
@@ -123,7 +133,6 @@
 static int	_pw_hesnum;		/* hes counter. no more records if -1 */
 #endif
 
-#ifdef _PASSWD_COMPAT
 enum _pwmode { PWMODE_NONE, PWMODE_FULL, PWMODE_USER, PWMODE_NETGRP };
 static enum _pwmode __pwmode;
 
@@ -141,11 +150,13 @@
 static int	__ypmaptype __P((void));
 static int	__pwparse __P((struct passwd *, char *));
 
+#ifdef YP
 	/* macros for deciding which YP maps to use. */
-#define PASSWD_BYNAME	(__ypmaptype() == YPMAP_MASTER \
+# define PASSWD_BYNAME	(__ypmaptype() == YPMAP_MASTER \
 			    ? "master.passwd.byname" : "passwd.byname")
-#define PASSWD_BYUID	(__ypmaptype() == YPMAP_MASTER \
+# define PASSWD_BYUID	(__ypmaptype() == YPMAP_MASTER \
 			    ? "master.passwd.byuid" : "passwd.byuid")
+#endif
 
 /*
  * add a name to the compat mode exclude list
@@ -288,6 +299,7 @@
 	__pwproto_flags = _pw_flags;
 }
 
+#ifdef YP
 static int
 __ypmaptype()
 {
@@ -329,6 +341,7 @@
 
 	return (maptype);
 }
+#endif /* YP */
 
 /*
  * parse a passwd file line (from NIS or HESIOD).
@@ -733,7 +746,6 @@
 		/*NOTREACHED*/
 	}
 }
-#endif /* _PASSWD_COMPAT */
 
 /*
  * compat implementation of getpwent()
@@ -752,16 +764,13 @@
 	DBT		 key;
 	int		 rval;
 	char		 bf[sizeof(_pw_keynum) + 1];
-#ifdef _PASSWD_COMPAT
 	static char	*name = NULL;
 	const char	*user, *host, *dom;
 	int		 has_compatpw;
-#endif
 
 	if (!_pw_db && !__initdb())
 		return NS_UNAVAIL;
 
-#ifdef _PASSWD_COMPAT
 	has_compatpw = __has_compatpw();
 
 again:
@@ -807,7 +816,6 @@
 		}
 		goto again;
 	}
-#endif
 
 	if (_pw_keynum == -1)
 		return NS_NOTFOUND;	/* no more local records */
@@ -820,7 +828,6 @@
 	if (rval == NS_NOTFOUND)
 		_pw_keynum = -1;	/* flag `no more local records' */
 	else if (rval == NS_SUCCESS) {
-#ifdef _PASSWD_COMPAT
 		/* if we don't have YP at all, don't bother. */
 		if (has_compatpw) {
 			if(_pw_passwd.pw_name[0] == '+') {
@@ -862,7 +869,6 @@
 				goto again;
 			}
 		}
-#endif
 	}
 	return (rval);
 }
@@ -879,13 +885,11 @@
 	void	*cb_data;
 	va_list	 ap;
 {
-#ifdef _PASSWD_COMPAT
 	DBT		key;
 	int		search, rval, r, s, keynum;
 	uid_t		uid;
 	char		bf[sizeof(keynum) + 1];
 	const char	*name, *host, *user, *dom;
-#endif
 
 	if (!_pw_db && !__initdb())
 		return NS_UNAVAIL;
@@ -893,12 +897,9 @@
 		/*
 		 * If there isn't a compat token in the database, use files.
 		 */
-#ifdef _PASSWD_COMPAT
 	if (! __has_compatpw())
-#endif
 		return (_local_getpw(rv, cb_data, ap));
 
-#ifdef _PASSWD_COMPAT
 	search = va_arg(ap, int);
 	uid = 0;
 	name = NULL;
@@ -1019,8 +1020,9 @@
 			__pwexclude = (DB *)NULL;
 	}
 	return rval;
-#endif /* _PASSWD_COMPAT */
 }
+#endif /* _PASSWD_COMPAT */
+
 
 struct passwd *
 getpwent()
@@ -1028,9 +1030,13 @@
 	int		r;
 	static const ns_dtab dtab[] = {
 		NS_FILES_CB(_local_getpw, NULL)
+#ifdef HESIOD
 		NS_DNS_CB(_dns_getpw, NULL)
+#endif
+#ifdef YP
 		NS_NIS_CB(_nis_getpw, NULL)
 		NS_COMPAT_CB(_compat_getpwent, NULL)
+#endif
 		{ 0 }
 	};
 
@@ -1048,9 +1054,13 @@
 	int		r;
 	static const ns_dtab dtab[] = {
 		NS_FILES_CB(_local_getpw, NULL)
+#ifdef HESIOD
 		NS_DNS_CB(_dns_getpw, NULL)
+#endif
+#ifdef YP
 		NS_NIS_CB(_nis_getpw, NULL)
 		NS_COMPAT_CB(_compat_getpw, NULL)
+#endif
 		{ 0 }
 	};
 
@@ -1069,9 +1079,13 @@
 	int		r;
 	static const ns_dtab dtab[] = {
 		NS_FILES_CB(_local_getpw, NULL)
+#ifdef HESIOD
 		NS_DNS_CB(_dns_getpw, NULL)
+#endif
+#ifdef YP
 		NS_NIS_CB(_nis_getpw, NULL)
 		NS_COMPAT_CB(_compat_getpw, NULL)
+#endif
 		{ 0 }
 	};
 


-- 
						Greg A. Woods

+1 416 218-0098                  VE3TCP            RoboHack <woods@robohack.ca>
Planix, Inc. <woods@planix.com>          Secrets of the Weird <woods@weird.com>