Subject: bin/5703: yppasswd doesn't like NetBSD YP servers
To: None <gnats-bugs@gnats.netbsd.org>
From: None <mason@primenet.com.au>
List: netbsd-bugs
Date: 07/04/1998 17:43:35
>Number:         5703
>Category:       bin
>Synopsis:       yppasswd doesn't understand NetBSD YP servers
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Jul  4 10:50:00 1998
>Last-Modified:
>Originator:     Geoff C. Wing
>Organization:
Geoff Wing   <gcw@pobox.com>            Mobile : 0412 162 441
Work URL: http://www.primenet.com.au/   Ego URL: http://pobox.com/~gcw/
>Release:        June/July 1998
>Environment:
System: NetBSD coral.primenet.com.au 1.3F NetBSD 1.3F (CORAL) #12: Mon Jun 29 14:30:17 EST 1998 mason@coral.primenet.com.au:/src/netbsd/src/sys/arch/i386/compile/CORAL i386


>Description:
	{yp,}passwd doesn't query master.passwd via YP so if YP is serving
	from a NetBSD box you can't change your password.  Then it needs to
	interpret it as a master.passwd style entry if appropriate.
>How-To-Repeat:
	make a NetBSD box a master server.  fail to change your password.
>Fix:
	first query on master.passwd.byname then on passwd.byname ;
	interpret them differently accordingly - you're going to lose the
	extra information anyway (pw_change, pw_class, pw_expire) since it
	won't be sent to the yppasswdd but interpret anyway (for the future?)
	(BTW, the flag I used (_PASSWORD_OLDFMT) sounded good but I have no
	idea if it is being used appropriately)

	Any better fixes or workarounds?

*** src/usr.bin/passwd/yp_passwd.c	Wed Jan 14 01:52:41 1998
--- obj/usr.bin/passwd/yp_passwd.c	Sun Jul  5 03:26:58 1998
***************
*** 74,80 ****
  extern	int yflag, yppwd;
  
  static	char		*getnewpasswd __P((struct passwd *, char **));
! static	struct passwd	*interpret __P((struct passwd *, char *));
  static	struct passwd	*ypgetpwnam __P((char *));
  static	void		 pw_error __P((char *, int, int));
  static	void		 test_local __P((char *));
--- 74,80 ----
  extern	int yflag, yppwd;
  
  static	char		*getnewpasswd __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 *));
***************
*** 269,277 ****
  }
  
  static struct passwd *
! interpret(pwent, line)
  	struct passwd *pwent;
  	char *line;
  {
  	char	*p = line;
  
--- 269,278 ----
  }
  
  static struct passwd *
! interpret(pwent, line, ptype)
  	struct passwd *pwent;
  	char *line;
+ 	int ptype;
  {
  	char	*p = line;
  
***************
*** 296,301 ****
--- 297,310 ----
  	pwent->pw_uid = (uid_t)strtoul(p, NULL, 10);
  	p = pwskip(p);
  	pwent->pw_gid = (gid_t)strtoul(p, NULL, 10);
+ 	if ((ptype & _PASSWORD_OLDFMT) == 0) {
+ 		p = pwskip(p);
+ 		pwent->pw_change = (time_t)strtol(p, NULL, 10);
+ 		p = pwskip(p);
+ 		pwent->pw_class = p;
+ 		p = pwskip(p);
+ 		pwent->pw_expire = (time_t)strtol(p, NULL, 10);
+ 	}
  	p = pwskip(p);
  	pwent->pw_gecos = p;
  	p = pwskip(p);
***************
*** 315,325 ****
  	static struct passwd pwent;
  	static char line[1024];
  	char *val;
! 	int reason, vallen;
  	
  	val = NULL;
! 	reason = yp_match(domain, "passwd.byname", nam, strlen(nam),
  			  &val, &vallen);
  	if (reason != 0) {
  		if (val != NULL)
  			free(val);
--- 324,344 ----
  	static struct passwd pwent;
  	static char line[1024];
  	char *val;
! 	int reason, vallen, ptype;
  	
+ 	ptype = 0;
  	val = NULL;
! 	reason = yp_match(domain, "master.passwd.byname", nam, strlen(nam),
  			  &val, &vallen);
+ 	if (reason == YPERR_MAP) {
+ 		if (val != NULL) {
+ 			free(val);
+ 			val = NULL;
+ 		}
+ 		reason = yp_match(domain, "passwd.byname", nam, strlen(nam),
+ 				  &val, &vallen);
+ 		ptype = _PASSWORD_OLDFMT;
+ 	}
  	if (reason != 0) {
  		if (val != NULL)
  			free(val);
***************
*** 329,335 ****
  	(void)strncpy(line, val, sizeof(line) - 1);
  	free(val);
  
! 	return(interpret(&pwent, line));
  }
  
  #endif	/* YP */
--- 348,354 ----
  	(void)strncpy(line, val, sizeof(line) - 1);
  	free(val);
  
! 	return(interpret(&pwent, line, ptype));
  }
  
  #endif	/* YP */
>Audit-Trail:
>Unformatted: