From owner-freebsd-hackers Sun Jun 23 10: 4:59 2002 Delivered-To: freebsd-hackers@freebsd.org Received: from hardtime.linuxman.net (hardtime.linuxman.net [66.147.26.65]) by hub.freebsd.org (Postfix) with ESMTP id DC9D237B400 for ; Sun, 23 Jun 2002 10:04:54 -0700 (PDT) Received: from mortis.over-yonder.net (localhost [127.0.0.1]) by hardtime.linuxman.net (8.11.6/8.11.6) with ESMTP id g5NGAQB30960; Sun, 23 Jun 2002 11:10:26 -0500 Received: by mortis.over-yonder.net (Postfix, from userid 100) id C95A01F05; Sun, 23 Jun 2002 12:04:52 -0500 (CDT) Date: Sun, 23 Jun 2002 12:04:52 -0500 From: "Matthew D. Fuller" To: Paul Herman Cc: "Geoffrey C. Speicher" , freebsd-hackers@FreeBSD.ORG Subject: Re: bug in pw, -STABLE [patch] Message-ID: <20020623170452.GG81018@over-yonder.net> References: <20020623160439.GE81018@over-yonder.net> <20020623094323.F38369-100000@mammoth.eat.frenchfries.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20020623094323.F38369-100000@mammoth.eat.frenchfries.net> User-Agent: Mutt/1.4i-fullermd.1 X-Editor: vi X-OS: FreeBSD 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, 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. It wouldn't be the end of the world, of course, since you'd still have the [s]pwd.db, so you could login, and you'd have the master.passwd.new, so you could recover, but you'd have to notice it and catch it before pw(8) or friends ran again. rename(2)'s guarantee is what saves you there. From the manpage: int rename(const char *from, const char *to); [...] Rename() guarantees that if to already exists, an instance of to will always exist, even if the system should crash in the middle of the opera- tion. -- Matthew Fuller (MF4839) | fullermd@over-yonder.net Systems/Network Administrator | http://www.over-yonder.net/~fullermd/ "The only reason I'm burning my candle at both ends, is because I haven't figured out how to light the middle yet" To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message