From owner-freebsd-bugs Mon Jan 15 6:40:26 2001 Delivered-To: freebsd-bugs@hub.freebsd.org Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21]) by hub.freebsd.org (Postfix) with ESMTP id 8134337B69E for ; Mon, 15 Jan 2001 06:40:05 -0800 (PST) Received: (from gnats@localhost) by freefall.freebsd.org (8.11.1/8.11.1) id f0FEe4f02199; Mon, 15 Jan 2001 06:40:04 -0800 (PST) (envelope-from gnats) Date: Mon, 15 Jan 2001 06:40:04 -0800 (PST) Message-Id: <200101151440.f0FEe4f02199@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org Cc: From: Alex Kapranoff Subject: Re: bin/23501: pw destroy /etc/master.passwd when pw executing at the Reply-To: Alex Kapranoff Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org The following reply was made to PR bin/23501; it has been noted by GNATS. From: Alex Kapranoff 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 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