From gpalmer@orion.webspan.net  Mon Feb 10 00:18:05 1997
Received: from who.cdrom.com (who.cdrom.com [204.216.27.3])
          by freefall.freebsd.org (8.8.5/8.8.5) with ESMTP id AAA17939
          for <freebsd-gnats-submit@freebsd.org>; Mon, 10 Feb 1997 00:18:03 -0800 (PST)
Received: from orion.webspan.net (orion.webspan.net [206.154.70.5])
          by who.cdrom.com (8.7.5/8.6.11) with ESMTP id XAA27690
          for <freebsd-gnats-submit@freebsd.org>; Sun, 9 Feb 1997 23:57:07 -0800 (PST)
Received: from orion.webspan.net (localhost [127.0.0.1]) 
          by orion.webspan.net (WEBSPN/970116) with ESMTP id CAA15715
          for <freebsd-gnats-submit@freebsd.org>; Mon, 10 Feb 1997 02:57:05 -0500 (EST)
Received: from freefall.freebsd.org (freefall.FreeBSD.ORG [204.216.27.18]) 
          by mail.webspan.net (WEBSPAN/970116) with ESMTP id UAA28156
          for <gpalmer@webspan.net>; Sat, 8 Feb 1997 20:50:50 -0500 (EST)
Received: from hydrogen.nike.efn.org (resnet.uoregon.edu [128.223.170.28])
          by freefall.freebsd.org (8.8.5/8.8.5) with ESMTP id RAA14787
          for <FreeBSD-gnats@freefall.FreeBSD.org>; Sat, 8 Feb 1997 17:50:23 -0800 (PST)
Received: (from jmg@localhost)
          by hydrogen.nike.efn.org (8.8.4/8.8.4)
	  id RAA13366; Sat, 8 Feb 1997 17:50:22 -0800 (PST)
Message-Id: <199702090150.RAA13366@hydrogen.nike.efn.org>
Date: Sat, 8 Feb 1997 17:50:22 -0800 (PST)
From: John-Mark Gurney <jmg@hydrogen.nike.efn.org>
Reply-To: gurney_j@efn.org
To: FreeBSD-gnats@freefall.freebsd.org
Subject: vipw doesn't allow you to edit master.passwd in another dir
X-Send-Pr-Version: 3.2

>Number:         2703
>Category:       bin
>Synopsis:       vipw doesn't allow you to edit master.passwd in another dir
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    sheldonh
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Mon Feb 10 00:20:02 PST 1997
>Closed-Date:    Sat Jun 26 00:37:48 PDT 1999
>Last-Modified:  Sat Jun 26 00:41:18 PDT 1999
>Originator:     John-Mark Gurney
>Release:        FreeBSD 2.2-960801-SNAP i386
>Organization:
Cu Networking
>Environment:

pretty much any FreeBSD box...
	

>Description:

if you have a diskless machine and you don't want to stick pwd_mkdb on the machine...  you can just manually make the new database files for the machine or you can now use vipw -d /diskless/machine/root/etc

hmm... just relized it would be nice to be able to turn off the passwd making..  plus allow you to keep the master.passwd in a different location :)
	

>How-To-Repeat:

vipw -d /diskless/machine/root/etc
returns the usage info
	

>Fix:
	
apply this patch (patch to do more of above to follow :) ):

Index: pw_util.c
===================================================================
RCS file: /usr/cvs/src/usr.sbin/vipw/pw_util.c,v
retrieving revision 1.5
diff -c -r1.5 pw_util.c
*** pw_util.c	1996/07/01 19:38:45	1.5
--- pw_util.c	1997/02/08 09:15:38
***************
*** 62,67 ****
--- 62,69 ----
  extern char *tempname;
  static pid_t editpid = -1;
  static int lockfd;
+ char *mppath = _PATH_PWD;
+ char *masterpasswd = _PATH_MASTERPASSWD;
  
  void
  pw_cont(sig)
***************
*** 111,119 ****
  	 * that users can't get at the encrypted passwords while editing.
  	 * Open should allow flock'ing the file; see 4.4BSD.	XXX
  	 */
! 	lockfd = open(_PATH_MASTERPASSWD, O_RDONLY, 0);
  	if (lockfd < 0 || fcntl(lockfd, F_SETFD, 1) == -1)
! 		err(1, "%s", _PATH_MASTERPASSWD);
  	if (flock(lockfd, LOCK_EX|LOCK_NB))
  		errx(1, "the password db file is busy");
  	return (lockfd);
--- 113,121 ----
  	 * that users can't get at the encrypted passwords while editing.
  	 * Open should allow flock'ing the file; see 4.4BSD.	XXX
  	 */
! 	lockfd = open(masterpasswd, O_RDONLY, 0);
  	if (lockfd < 0 || fcntl(lockfd, F_SETFD, 1) == -1)
! 		err(1, "%s", masterpasswd);
  	if (flock(lockfd, LOCK_EX|LOCK_NB))
  		errx(1, "the password db file is busy");
  	return (lockfd);
***************
*** 122,131 ****
  int
  pw_tmp()
  {
! 	static char path[MAXPATHLEN] = _PATH_MASTERPASSWD;
  	int fd;
  	char *p;
  
  	if (p = strrchr(path, '/'))
  		++p;
  	else
--- 124,136 ----
  int
  pw_tmp()
  {
! 	static char path[MAXPATHLEN];
  	int fd;
  	char *p;
  
+ 	strncpy(path, masterpasswd, MAXPATHLEN-1);
+ 	path[MAXPATHLEN - 1] = 0;
+ 
  	if (p = strrchr(path, '/'))
  		++p;
  	else
***************
*** 148,157 ****
  	(void)fflush(stderr);
  	if (!(pid = vfork())) {
  		if(!username) {
! 			execl(_PATH_PWD_MKDB, "pwd_mkdb", "-p", tempname, NULL);
  		} else {
! 			execl(_PATH_PWD_MKDB, "pwd_mkdb", "-p", "-u", 
! 					username, tempname, NULL);
  		}
  		pw_error(_PATH_PWD_MKDB, 1, 1);
  	}
--- 153,163 ----
  	(void)fflush(stderr);
  	if (!(pid = vfork())) {
  		if(!username) {
! 			execl(_PATH_PWD_MKDB, "pwd_mkdb", "-p", "-d", mppath,
! 			    tempname, NULL);
  		} else {
! 			execl(_PATH_PWD_MKDB, "pwd_mkdb", "-p", "-d", mppath,
! 			    "-u", username, tempname, NULL);
  		}
  		pw_error(_PATH_PWD_MKDB, 1, 1);
  	}
***************
*** 227,233 ****
  		warnx("NIS information unchanged");
  	else
  #endif /* YP */
! 	warnx("%s: unchanged", _PATH_MASTERPASSWD);
  	(void)unlink(tempname);
  	exit(eval);
  }
--- 233,239 ----
  		warnx("NIS information unchanged");
  	else
  #endif /* YP */
! 	warnx("%s: unchanged", masterpasswd);
  	(void)unlink(tempname);
  	exit(eval);
  }
Index: vipw.8
===================================================================
RCS file: /usr/cvs/src/usr.sbin/vipw/vipw.8,v
retrieving revision 1.1.1.1
diff -c -r1.1.1.1 vipw.8
*** vipw.8	1994/05/26 05:23:31	1.1.1.1
--- vipw.8	1997/02/08 09:20:56
***************
*** 39,44 ****
--- 39,45 ----
  .Nd edit the password file
  .Sh SYNOPSIS
  .Nm vipw
+ .Op Fl d Ar directory
  .Sh DESCRIPTION
  .Nm Vipw
  edits the password file after setting the appropriate locks,
***************
*** 70,75 ****
--- 71,83 ----
  at very large sites could take several minutes.  Until this update
  is completed, the password file is unavailable for other updates
  and the new information is not available to programs.
+ .Pp
+ If the
+ .Fl d Ar directory
+ option is provided it will user the password files in
+ .Ar directory
+ instead of the default of
+ .Pa /etc .
  .Sh ENVIRONMENT
  If the following environment variable exists it will be utilized by
  .Nm vipw :
Index: vipw.c
===================================================================
RCS file: /usr/cvs/src/usr.sbin/vipw/vipw.c,v
retrieving revision 1.3
diff -c -r1.3 vipw.c
*** vipw.c	1996/07/01 19:38:50	1.3
--- vipw.c	1997/02/08 09:11:11
***************
*** 53,58 ****
--- 53,61 ----
  
  #include "pw_util.h"
  
+ extern char *mppath;
+ extern char *masterpasswd;
+ 
  char *tempname;
  
  void	copyfile __P((int, int));
***************
*** 67,74 ****
  	struct stat begin, end;
  	int ch;
  
! 	while ((ch = getopt(argc, argv, "")) != EOF)
  		switch (ch) {
  		case '?':
  		default:
  			usage();
--- 70,91 ----
  	struct stat begin, end;
  	int ch;
  
! 	while ((ch = getopt(argc, argv, "d:")) != EOF)
  		switch (ch) {
+ 		case 'd':
+ 			masterpasswd = malloc(strlen(optarg) +
+ 			    strlen(_MASTERPASSWD) + 2);
+ 			strcpy(masterpasswd, optarg);
+ 
+ 			if(masterpasswd[strlen(masterpasswd) - 1] != '/')
+ 				masterpasswd[strlen(masterpasswd)] = '/';
+ 			strcat(masterpasswd, _MASTERPASSWD);
+ 
+ 			mppath = strdup(optarg);
+ 			if(mppath[strlen(mppath) - 1] == '/')
+ 				mppath[strlen(mppath) - 1] = 0;
+ 
+ 			break;
  		case '?':
  		default:
  			usage();
***************
*** 122,127 ****
  usage()
  {
  
! 	(void)fprintf(stderr, "usage: vipw\n");
  	exit(1);
  }
--- 139,144 ----
  usage()
  {
  
! 	(void)fprintf(stderr, "usage: vipw [ -d directory]\n");
  	exit(1);
  }
	

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->jmg 
Responsible-Changed-By: jmg 
Responsible-Changed-When: Sun Apr 12 15:24:04 PDT 1998 
Responsible-Changed-Why:  
now that I'm a committer, I'll take care of this... 

From: Sheldon Hearn <sheldonh@uunet.co.za>
To: jmg@freebsd.org
Cc: freebsd-gnats-submit@freebsd.org
Subject: Re: bin/2703: vipw doesn't allow you to edit master.passwd in another dir
Date: Tue, 01 Jun 1999 12:48:59 +0200

 Hi John-Mark,
 
 Did you ever look at the diffs submitted in '97 for teaching vipw to
 look at a master.passwd somewhere other than /etc ? You took them on in
 '98 and then fell very silent on the mater. Was there something wrong
 with the diffs?
 
 Ciao,
 Sheldon.
 
Responsible-Changed-From-To: jmg->sheldonh 
Responsible-Changed-By: sheldonh 
Responsible-Changed-When: Tue Jun 15 11:28:14 PDT 1999 
Responsible-Changed-Why:  
Handed over to me in private mail. 
State-Changed-From-To: open->closed 
State-Changed-By: sheldonh 
State-Changed-When: Sat Jun 26 00:37:48 PDT 1999 
State-Changed-Why:  
Committed with a few changes: 
* Keep consistent with the existing code's tendency to keep  
blank lines to a minimum. 

* Changed the manual page entry for clarity. 

* Die with the appropriate error message when either malloc() or 
strdup() fails. 
>Unformatted:
John-Mark Gurney
