From owner-freebsd-stable Fri Nov 5 12: 7:36 1999 Delivered-To: freebsd-stable@freebsd.org Received: from astral.elitenet.com.br (astral.elitenet.com.br [200.254.27.8]) by hub.freebsd.org (Postfix) with ESMTP id CF72814E98 for ; Fri, 5 Nov 1999 12:07:27 -0800 (PST) (envelope-from duwde@elitenet.com.br) Received: from elitenet.com.br (spacecowboy.noc.elitenet.com.br [200.254.27.20]) by astral.elitenet.com.br (8.9.3p/8.9.3/ASTRAL-4.2c) with ESMTP id SAA25031; Fri, 5 Nov 1999 18:13:59 -0200 (EDT) Message-ID: <38231D04.AD517B79@elitenet.com.br> Date: Fri, 05 Nov 1999 16:08:04 -0200 From: Fabio Dias X-Mailer: Mozilla 4.61 [en] (X11; I; FreeBSD 3.3-STABLE i386) X-Accept-Language: en MIME-Version: 1.0 To: Philip Inglesant Cc: freebsd-stable@FreeBSD.ORG Subject: Re: Password file updating References: <000501bf27bf$95b706a0$f12170c2@desktop97.dircon.co.uk> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-freebsd-stable@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Philip Inglesant wrote: > When the server end of this password update system gets a request, it > flock()s master.password, makes a temporary copy of /etc/master.passwd, > /etc/passwd, /etc/pwd.db, and /etc/spwd.db, and uses ordinary write() to the > update passwd and master.passwd copies and dbopen() etc to update these > temporary copies of pwd.db and spwd.db. I copied this source from the > standard pwd_mkdb FreeeBSD source, with minor modifications. I think you should update only a temporary copy of master.passwd, and them call pwd_mkdb(8), as does chpass(1), passwd(1), vipw(8) and all others. > But once the update to the temporary files is done, of course my program has > to update the real live files. It does this using rename(). > > I am pretty sure that it is during the tiny period of time that the rename() > is happening that the problem occurs. quoting from pwd_mkdb(8) man page : -- Because of the necessity for atomic update of the password files, pwd_mkdb uses rename(2) to install them. This, however, requires that the file specified on the command line live on the same file system as the /etc directory. There are the obvious races with multiple people running pwd_mkdb on dif- ferent password files at the same time. The front-ends to pwd_mkdb, chpass(1), passwd(1) and vipw(8), handle the locking necessary to avoid this problem. -- rename(2) does a atomic update, your problem seems to rely on the front-end you're using, not on rename(2) itself. As I said before, update only a temporary copy of master.passwd (as all password programs does) but take care of the locking scheme utilized by those programs, and them call pwd_mkdb(8). Check out chpass/passwd/vipw sources. Fabio Dias duwde@elitenet.com.br To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-stable" in the body of the message