Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 15 Jan 2001 06:40:04 -0800 (PST)
From:      Alex Kapranoff <alex@kapran.bitmcnit.bryansk.su>
To:        freebsd-bugs@FreeBSD.org
Subject:   Re: bin/23501: pw destroy /etc/master.passwd when pw executing at the
Message-ID:  <200101151440.f0FEe4f02199@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help
The following reply was made to PR bin/23501; it has been noted by GNATS.

From: Alex Kapranoff <alex@kapran.bitmcnit.bryansk.su>
To: akimoto@xephion.ne.jp
Cc: dhagan@colltech.com, freebsd-gnats-submit@freebsd.org
Subject: Re: bin/23501: pw destroy /etc/master.passwd when pw executing at the
Date: Fri, 12 Jan 2001 20:47:34 +0300

 >  If anyone knows how to modify concretely,
 >  please tell me that.
 >  
 >  On Thu, 04 Jan 2001 16:13:50 -0500
 >  Daniel Hagan <dhagan@colltech.com> wrote:
 >  
 >  > This is almost certainly the fault of fileupdate() in fileupd.c:72.  The
 >  > logic is too byzantine for me to figure out right now, but the comment
 >  > at line 181 seems worrisome.
 >  > 
 >  > Daniel
 
 Tomonobo,
 try the following patch and see if it helps.
 
 diff -ru /usr/src/usr.sbin/pw/edgroup.c ./edgroup.c
 --- /usr/src/usr.sbin/pw/edgroup.c	Thu Dec 14 22:13:45 2000
 +++ ./edgroup.c	Fri Jan 12 20:21:42 2001
 @@ -68,7 +68,7 @@
  	strcpy(grouptmp, groupfile);
  	strcat(grouptmp, ".new");
  
 -	if ((infd = open(groupfile, O_RDWR | O_CREAT, 0644)) != -1) {
 +	if ((infd = open(groupfile, O_RDWR | O_CREAT | O_EXLOCK, 0644)) != -1) {
  		FILE           *infp;
  
  		if ((infp = fdopen(infd, "r+")) == NULL)
 @@ -76,7 +76,7 @@
  		else {
  			int             outfd;
  
 -			if ((outfd = open(grouptmp, O_RDWR | O_CREAT | O_TRUNC | O_EXLOCK, 0644)) != -1) {
 +			if ((outfd = open(grouptmp, O_RDWR | O_CREAT | O_TRUNC, 0644)) != -1) {
  				FILE           *outfp;
  
  				if ((outfp = fdopen(outfd, "w+")) == NULL)
 @@ -207,8 +207,7 @@
  
  							/*
  							 * This is a gross hack, but we may have corrupted the
 -							 * original file. Unfortunately, it will lose preservation
 -							 * of the inode.
 +							 * original file.
  							 */
  							if (fflush(infp) == EOF || ferror(infp))
  								rc = rename(grouptmp, groupfile) == 0;
 diff -ru /usr/src/usr.sbin/pw/fileupd.c ./fileupd.c
 --- /usr/src/usr.sbin/pw/fileupd.c	Thu Dec 14 22:13:45 2000
 +++ ./fileupd.c	Fri Jan 12 20:20:44 2001
 @@ -76,7 +76,7 @@
  	if (pfxlen <= 1)
  		rc = EINVAL;
  	else {
 -		int    infd = open(filename, O_RDWR | O_CREAT, fmode);
 +		int    infd = open(filename, O_RDWR | O_CREAT | O_EXLOCK, fmode);
  
  		if (infd == -1)
  			rc = errno;
 @@ -92,7 +92,7 @@
  
  				strcpy(file, filename);
  				strcat(file, ".new");
 -				outfd = open(file, O_RDWR | O_CREAT | O_TRUNC | O_EXLOCK, fmode);
 +				outfd = open(file, O_RDWR | O_CREAT | O_TRUNC, fmode);
  				if (outfd == -1)
  					rc = errno;
  				else {
 @@ -183,8 +183,6 @@
  								 * to 'file'.
  								 * This is a gross hack, but we may have
  								 * corrupted the original file
 -								 * Unfortunately, it will lose the inode
 -								 * and hence the lock.
  								 */
  								if (fflush(infp) == EOF || ferror(infp))
  									rename(file, filename);
 
 -- 
 Alex Kapranoff,                              Voice: +7(0832)791845
 We've lived 11 days in the brand new millenium...
 


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




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