Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 05 Nov 1999 16:08:04 -0200
From:      Fabio Dias <duwde@elitenet.com.br>
To:        Philip Inglesant <philip@dircon.net>
Cc:        freebsd-stable@FreeBSD.ORG
Subject:   Re: Password file updating
Message-ID:  <38231D04.AD517B79@elitenet.com.br>
References:  <000501bf27bf$95b706a0$f12170c2@desktop97.dircon.co.uk>

next in thread | previous in thread | raw e-mail | index | archive | help
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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?38231D04.AD517B79>