Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 8 Feb 1997 17:50:22 -0800 (PST)
From:      John-Mark Gurney <jmg@hydrogen.nike.efn.org>
To:        FreeBSD-gnats@freefall.FreeBSD.org
Subject:   bin/2703: vipw doesn't allow you to edit master.passwd in another dir
Message-ID:  <199702090150.RAA13366@hydrogen.nike.efn.org>
Resent-Message-ID: <199702100820.AAA18060@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>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:    freebsd-bugs
>State:          open
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Mon Feb 10 00:20:02 PST 1997
>Last-Modified:
>Originator:     John-Mark Gurney
>Organization:
Cu Networking
>Release:        FreeBSD 2.2-960801-SNAP i386
>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);
  }
	

>Audit-Trail:
>Unformatted:
John-Mark Gurney



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199702090150.RAA13366>