about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTanaka Akira <akr@users.sourceforge.net>1999-10-31 06:44:41 +0000
committerTanaka Akira <akr@users.sourceforge.net>1999-10-31 06:44:41 +0000
commit8f35520cb3ef271407d73404a59d51a6b815e8f7 (patch)
treeb0ce1a322a5f80f19f6121a556a00310e70527b7
parentbeaf69f4283ba80c5b9b8251c7116e22b0a65e82 (diff)
downloadzsh-8f35520cb3ef271407d73404a59d51a6b815e8f7.tar.gz
zsh-8f35520cb3ef271407d73404a59d51a6b815e8f7.tar.xz
zsh-8f35520cb3ef271407d73404a59d51a6b815e8f7.zip
zsh-workers/8474
-rw-r--r--Src/Modules/parameter.c30
-rw-r--r--Src/hashtable.c58
2 files changed, 59 insertions, 29 deletions
diff --git a/Src/Modules/parameter.c b/Src/Modules/parameter.c
index af2d400ea..624d33933 100644
--- a/Src/Modules/parameter.c
+++ b/Src/Modules/parameter.c
@@ -182,7 +182,8 @@ scanpmparameters(HashTable ht, ScanFunc func, int flags)
 	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 @@ scanpmcommands(HashTable ht, ScanFunc func, int flags)
 	    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 @@ scanfunctions(HashTable ht, ScanFunc func, int flags, int dis)
 	    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 @@ scanbuiltins(HashTable ht, ScanFunc func, int flags, int dis)
 	    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 @@ scanpmhistory(HashTable ht, ScanFunc func, int flags)
 
     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 @@ scanpmjobtexts(HashTable ht, ScanFunc func, int flags)
 	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 @@ scanpmjobstates(HashTable ht, ScanFunc func, int flags)
 	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 @@ scanpmnameddirs(HashTable ht, ScanFunc func, int flags)
 	    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 @@ scanpmuserdirs(HashTable ht, ScanFunc func, int flags)
 	    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 @@ scanaliases(HashTable ht, ScanFunc func, int flags, int global, int dis)
 		(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 --git a/Src/hashtable.c b/Src/hashtable.c
index d4c832f16..24c23e423 100644
--- a/Src/hashtable.c
+++ b/Src/hashtable.c
@@ -1232,7 +1232,7 @@ fillnameddirtable(HashTable ht)
 #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 @@ fillnameddirtable(HashTable ht)
 	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