Date: Sun, 23 Jun 2002 11:32:54 -0700 (PDT) From: Paul Herman <pherman@frenchfries.net> To: "Matthew D. Fuller" <fullermd@over-yonder.net> Cc: "Geoffrey C. Speicher" <geoff@sea-incorporated.com>, <freebsd-hackers@FreeBSD.ORG> Subject: Re: bug in pw, -STABLE [patch] Message-ID: <20020623111412.V38509-100000@mammoth.eat.frenchfries.net> In-Reply-To: <20020623170452.GG81018@over-yonder.net>
next in thread | previous in thread | raw e-mail | index | archive | help
On Sun, 23 Jun 2002, Matthew D. Fuller wrote: > On Sun, Jun 23, 2002 at 09:59:10AM -0700 I heard the voice of > Paul Herman, and lo! it spake thus: > > > > I can't imagine it would be too extensive of a rewrite. The temp > > file code could be kept, and in fileupd.c:fileupdate() instead of > > rename("/etc/master.passwd.new", "/etc/master.passwd"), it just > > copies the contents of the .new file into the original file (that > > has the O_EXLOCK.) > > Yes, but that would open up the problem that cause the rename(2) to be > used in the first place; i.e., rename() is atomic; read(2)/write(2)'ing a > bunch of data isn't, so a system crash at the wrong time would leave you > with a partial master.passwd. Fine, then lock them both, and use rename(). Patch attached. In fact, if you look at fileupdate(), you see that it already gains an exclusive lock on the temp file, but not the original "/etc/master.passwd" (if you will.) I think this is a bug, because the original is getting modified (at least in name space), so that should be locked while pw(8) is operating. What do you think? -Paul. Index: fileupd.c =================================================================== RCS file: /u02/ncvs/src/usr.sbin/pw/fileupd.c,v retrieving revision 1.9 diff -u -r1.9 fileupd.c --- fileupd.c 26 Oct 1999 04:27:13 -0000 1.9 +++ fileupd.c 23 Jun 2002 18:30:16 -0000 @@ -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 | O_NONBLOCK, fmode); if (infd == -1) rc = errno; To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020623111412.V38509-100000>