From owner-freebsd-hackers Sun Jun 23 11:34:26 2002 Delivered-To: freebsd-hackers@freebsd.org Received: from mail.deltanet.com (mail.deltanet.com [216.237.144.132]) by hub.freebsd.org (Postfix) with ESMTP id 8D49137B400 for ; Sun, 23 Jun 2002 11:34:19 -0700 (PDT) Received: from mammoth.eat.frenchfries.net (da001d0437.lax-ca.osd.concentric.net [64.0.145.182]) by mail.deltanet.com (8.11.6/8.11.6) with ESMTP id g5NIABO17525 for ; Sun, 23 Jun 2002 11:10:13 -0700 Received: by mammoth.eat.frenchfries.net (Postfix, from userid 1000) id 6CB7B5183; Sun, 23 Jun 2002 11:32:54 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by mammoth.eat.frenchfries.net (Postfix) with ESMTP id 69EC75159; Sun, 23 Jun 2002 11:32:54 -0700 (PDT) Date: Sun, 23 Jun 2002 11:32:54 -0700 (PDT) From: Paul Herman X-X-Sender: pherman@mammoth.eat.frenchfries.net To: "Matthew D. Fuller" Cc: "Geoffrey C. Speicher" , Subject: Re: bug in pw, -STABLE [patch] In-Reply-To: <20020623170452.GG81018@over-yonder.net> Message-ID: <20020623111412.V38509-100000@mammoth.eat.frenchfries.net> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG 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