Subject: Re: yppasswd fix (please review)
To: David Brownlee <abs@mono.org>
From: Hubert Feyrer <feyrer@rfhs8012.fh-regensburg.de>
List: tech-userlevel
Date: 12/10/1999 21:41:16
On Fri, 10 Dec 1999, David Brownlee wrote:
> 	I prefer a), except if it might cause spurious syslog output on
> 	some systems.

OK, next round, please see the patch below.
This tries master.passwd first, and falls back to passwd.

I've tested this with secure (NetBSD default), insecure (NetBSD) and
Solaris (passwd) NIS.


> 	Hmm - a command line switch to override one way or the other
> 	is probably also a good idea...

Maybe, but I don't really see a reason for it. It would be needed when
you wanted to take the passwd map while master.passwd is still available. 
As the only circumstance this could help is out of sync maps, I won't try
to assist such a situation here.

BTW with NetBSD NIS set to NISECURE, this will still use the master.passwd
map, as it's available. 


 - Hubert

-- 
NetBSD - Better for your uptime than Viagra

Index: yp_passwd.c
===================================================================
RCS file: /cvsroot/basesrc/usr.bin/passwd/yp_passwd.c,v
retrieving revision 1.19
diff -u -r1.19 yp_passwd.c
--- yp_passwd.c	1998/07/26 22:15:38	1.19
+++ yp_passwd.c	1999/12/10 20:36:06
@@ -74,7 +74,7 @@
 extern	int yflag, yppwd;
 
 static	char		*getnewpasswd __P((struct passwd *, char **));
-static	struct passwd	*interpret __P((struct passwd *, char *));
+static	struct passwd	*interpret __P((struct passwd *, char *, int));
 static	struct passwd	*ypgetpwnam __P((char *));
 static	void		 pw_error __P((char *, int, int));
 static	void		 test_local __P((char *));
@@ -275,9 +275,10 @@
 }
 
 static struct passwd *
-interpret(pwent, line)
+interpret(pwent, line, secure)
 	struct passwd *pwent;
 	char *line;
+	int secure;
 {
 	char	*p = line;
 
@@ -300,6 +301,12 @@
 	pwent->pw_passwd = p;
 	p = pwskip(p);
 	pwent->pw_uid = (uid_t)strtoul(p, NULL, 10);
+	if (secure) {
+		/* Given line is in master.passwd format */
+		p = pwskip(p); 	/* skip class */
+		p = pwskip(p); 	/* skip change */
+		p = pwskip(p); 	/* skip expire */
+	}
 	p = pwskip(p);
 	pwent->pw_gid = (gid_t)strtoul(p, NULL, 10);
 	p = pwskip(p);
@@ -322,21 +329,32 @@
 	static char line[1024];
 	char *val;
 	int reason, vallen;
+	int secure = 1;
 	
 	val = NULL;
-	reason = yp_match(domain, "passwd.byname", nam, strlen(nam),
+	reason = yp_match(domain, "master.passwd.byname", nam, strlen(nam),
 			  &val, &vallen);
 	if (reason != 0) {
 		if (val != NULL)
 			free(val);
-		return (NULL);
+
+		val = NULL;
+		reason = yp_match(domain, "passwd.byname", nam, strlen(nam),
+			  	  &val, &vallen);
+		if (reason != 0) {
+			if (val != NULL)
+				free(val);
+			return (NULL);
+		}
+
+		secure=0;
 	}
 	val[vallen] = '\0';
 	(void)strncpy(line, val, sizeof(line) - 1);
 	line[sizeof(line) - 1] = '\0';
 	free(val);
 
-	return (interpret(&pwent, line));
+	return (interpret(&pwent, line, secure));
 }
 
 #endif	/* YP */