zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: Re: bugs in 3.0.6 (at least on Solaris 8)
@ 1999-10-28  9:28 Sven Wischnowsky
  0 siblings, 0 replies; only message in thread
From: Sven Wischnowsky @ 1999-10-28  9:28 UTC (permalink / raw)
  To: zsh-workers


Mike Sullivan wrote:

> And one more thing - the #define'ing of HAVE_NIS or HAVE_NIS_PLUS based on
> what the machine you're compiling on is running. Is that wise? At least around
> here, you may be trying to use the same binary from /usr/local on machines
> running different name services, and that breaks if it's trying to do NIS
> calls on a NIS+ machine. I turned those off, so we fall back to getpwent. 
> Direct nameservice calls are indeed faster, but this seems more portable in
> light of the variety of nameservices around, and the various ways you can
> order them.

This makes it fall back to getpwent() when using NIS or NIS+ didn't
add any directories (for 3.1.6++ only, sorry, don't have a 3.0.x
anymore).

And then I have to apologise for 8472: I didn't realise that the flags 
may not have SCANPM_WANTVALS set even though the values are wanted. So 
this patch fixes this, too.

Bye
 Sven

diff -u -r oldsrc/Modules/parameter.c Src/Modules/parameter.c
--- oldsrc/Modules/parameter.c	Thu Oct 28 10:27:33 1999
+++ Src/Modules/parameter.c	Thu Oct 28 11:24:44 1999
@@ -182,7 +182,8 @@
 	for (hn = realparamtab->nodes[i]; hn; hn = hn->next) {
 	    pm.nam = hn->nam;
 	    if (func != scancountparams &&
-		(flags & (SCANPM_WANTVALS|SCANPM_MATCHVAL)))
+		((flags & (SCANPM_WANTVALS|SCANPM_MATCHVAL)) ||
+		 !(flags & SCANPM_WANTKEYS)))
 		pm.u.str = paramtypestr((Param) hn);
 	    func((HashNode) &pm, flags);
 	}
@@ -314,7 +315,8 @@
 	    pm.nam = hn->nam;
 	    cmd = (Cmdnam) hn;
 	    if (func != scancountparams &&
-		(flags & (SCANPM_WANTVALS|SCANPM_MATCHVAL))) {
+		((flags & (SCANPM_WANTVALS|SCANPM_MATCHVAL)) ||
+		 !(flags & SCANPM_WANTKEYS))) {
 		if (cmd->flags & HASHED)
 		    pm.u.str = cmd->u.cmd;
 		else {
@@ -516,7 +518,8 @@
 	    if (dis ? (hn->flags & DISABLED) : !(hn->flags & DISABLED)) {
 		pm.nam = hn->nam;
 		if (func != scancountparams &&
-		    (flags & (SCANPM_WANTVALS|SCANPM_MATCHVAL))) {
+		    ((flags & (SCANPM_WANTVALS|SCANPM_MATCHVAL)) ||
+		     !(flags & SCANPM_WANTKEYS))) {
 		    if (((Shfunc) hn)->flags & PM_UNDEFINED) {
 			Shfunc shf = (Shfunc) hn;
 			pm.u.str =
@@ -625,7 +628,8 @@
 	    if (dis ? (hn->flags & DISABLED) : !(hn->flags & DISABLED)) {
 		pm.nam = hn->nam;
 		if (func != scancountparams &&
-		    (flags & (SCANPM_WANTVALS|SCANPM_MATCHVAL))) {
+		    ((flags & (SCANPM_WANTVALS|SCANPM_MATCHVAL)) ||
+		     !(flags & SCANPM_WANTKEYS))) {
 		    char *t = ((((Builtin) hn)->handlerfunc ||
 				(hn->flags & BINF_PREFIX)) ?
 			       "defined" : "undefined");
@@ -1059,7 +1063,8 @@
 
     while (he) {
 	if (func != scancountparams &&
-	    (flags & (SCANPM_WANTVALS|SCANPM_MATCHVAL))) {
+	    ((flags & (SCANPM_WANTVALS|SCANPM_MATCHVAL)) ||
+	     !(flags & SCANPM_WANTKEYS))) {
 	    sprintf(buf, "%d", he->histnum);
 	    pm.nam = dupstring(buf);
 	    pm.u.str = dupstring(he->text);
@@ -1181,7 +1186,8 @@
 	if (jobtab[job].stat && jobtab[job].procs &&
 	    !(jobtab[job].stat & STAT_NOPRINT)) {
 	    if (func != scancountparams &&
-		(flags & (SCANPM_WANTVALS|SCANPM_MATCHVAL))) {
+		((flags & (SCANPM_WANTVALS|SCANPM_MATCHVAL)) ||
+		 !(flags & SCANPM_WANTKEYS))) {
 		sprintf(buf, "%d", job);
 		pm.nam = dupstring(buf);
 		pm.u.str = pmjobtext(job);
@@ -1286,7 +1292,8 @@
 	if (jobtab[job].stat && jobtab[job].procs &&
 	    !(jobtab[job].stat & STAT_NOPRINT)) {
 	    if (func != scancountparams &&
-		(flags & (SCANPM_WANTVALS|SCANPM_MATCHVAL))) {
+		((flags & (SCANPM_WANTVALS|SCANPM_MATCHVAL)) ||
+		 !(flags & SCANPM_WANTKEYS))) {
 		sprintf(buf, "%d", job);
 		pm.nam = dupstring(buf);
 		pm.u.str = pmjobstate(job);
@@ -1418,7 +1425,8 @@
 	    if (!((nd = (Nameddir) hn)->flags & ND_USERNAME)) {
 		pm.nam = hn->nam;
 		if (func != scancountparams &&
-		    (flags & (SCANPM_WANTVALS|SCANPM_MATCHVAL)))
+		    ((flags & (SCANPM_WANTVALS|SCANPM_MATCHVAL)) ||
+		     !(flags & SCANPM_WANTKEYS)))
 		    pm.u.str = dupstring(nd->dir);
 		func((HashNode) &pm, flags);
 	    }
@@ -1486,7 +1494,8 @@
 	    if ((nd = (Nameddir) hn)->flags & ND_USERNAME) {
 		pm.nam = hn->nam;
 		if (func != scancountparams &&
-		    (flags & (SCANPM_WANTVALS|SCANPM_MATCHVAL)))
+		    ((flags & (SCANPM_WANTVALS|SCANPM_MATCHVAL)) ||
+		     !(flags & SCANPM_WANTKEYS)))
 		    pm.u.str = dupstring(nd->dir);
 		func((HashNode) &pm, flags);
 	    }
@@ -1703,7 +1712,8 @@
 		(dis ? (al->flags & DISABLED) : !(al->flags & DISABLED))) {
 		pm.nam = hn->nam;
 		if (func != scancountparams &&
-		    (flags & (SCANPM_WANTVALS|SCANPM_MATCHVAL)))
+		    ((flags & (SCANPM_WANTVALS|SCANPM_MATCHVAL)) ||
+		     !(flags & SCANPM_WANTKEYS)))
 		    pm.u.str = dupstring(al->text);
 		func((HashNode) &pm, flags);
 	    }
diff -u -r oldsrc/hashtable.c Src/hashtable.c
--- oldsrc/hashtable.c	Thu Oct 28 10:12:46 1999
+++ Src/hashtable.c	Thu Oct 28 11:15:45 1999
@@ -1232,7 +1232,7 @@
 #if defined(HAVE_NIS) || defined(HAVE_NIS_PLUS)
 	FILE *pwf;
 	char buf[BUFSIZ], *p, *d, *de;
-	int skipping;
+	int skipping, oldct = nameddirtab->ct, usepwf = 1;
 
 # ifndef HAVE_NIS_PLUS
 	char domain[YPMAXDOMAIN];
@@ -1250,28 +1250,48 @@
 	nis_list("passwd.org_dir", EXPAND_NAME|ALL_RESULTS|FOLLOW_LINKS|FOLLOW_PATH,
 		 add_userdir, 0);
 # endif
-	/* Don't forget the non-NIS matches from the flat passwd file */
-	if ((pwf = fopen(PASSWD_FILE, "r")) != NULL) {
-	    skipping = 0;
-	    while (fgets(buf, BUFSIZ, pwf) != NULL) {
-		if (strchr(buf, '\n') != NULL) {
-		    if (!skipping) {
-			if ((p = strchr(buf, ':')) != NULL) {
-			    *p++ = '\0';
-			    if ((de = strrchr(p, ':'))) {
-				*de = '\0';
-				if ((d = strrchr(p, ':'))) {
-				    if (*++d && buf[0])
-					adduserdir(buf, d, ND_USERNAME, 1);
+	if (nameddirtab->ct == oldct) {
+	    /* Using NIS or NIS+ didn't add any user directories. This seems
+	     * fishy, so we fall back to using getpwent(). If we don't have
+	     * that, we only use the passwd file. */
+#ifdef HAVE_GETPWENT
+	    struct passwd *pw;
+ 
+	    setpwent();
+ 
+	    /* loop through the password file/database *
+	     * and add all entries returned.           */
+	    while ((pw = getpwent()) && !errflag)
+		adduserdir(pw->pw_name, pw->pw_dir, ND_USERNAME, 1);
+ 
+	    endpwent();
+	    usepwf = 0;
+#endif /* HAVE_GETPWENT */
+	}
+	if (usepwf) {
+	    /* Don't forget the non-NIS matches from the flat passwd file */
+	    if ((pwf = fopen(PASSWD_FILE, "r")) != NULL) {
+		skipping = 0;
+		while (fgets(buf, BUFSIZ, pwf) != NULL) {
+		    if (strchr(buf, '\n') != NULL) {
+			if (!skipping) {
+			    if ((p = strchr(buf, ':')) != NULL) {
+				*p++ = '\0';
+				if ((de = strrchr(p, ':'))) {
+				    *de = '\0';
+				    if ((d = strrchr(p, ':'))) {
+					if (*++d && buf[0])
+					    adduserdir(buf, d, ND_USERNAME, 1);
+				    }
 				}
 			    }
-			}
+			} else
+			    skipping = 0;
 		    } else
-			skipping = 0;
-		} else
-		    skipping = 1;
+			skipping = 1;
+		}
+		fclose(pwf);
 	    }
-	    fclose(pwf);
 	}
 #else  /* no NIS or NIS_PLUS */
 #ifdef HAVE_GETPWENT

--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1999-10-28  9:28 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-10-28  9:28 PATCH: Re: bugs in 3.0.6 (at least on Solaris 8) Sven Wischnowsky

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).