*BSD News Article 85578


Return to BSD News archive

Path: euryale.cc.adfa.oz.au!newshost.carno.net.au!harbinger.cc.monash.edu.au!news.rmit.EDU.AU!news.unimelb.EDU.AU!munnari.OZ.AU!spool.mu.edu!newspump.sol.net!www.nntp.primenet.com!nntp.primenet.com!newsxfer2.itd.umich.edu!uunet!in1.uu.net!205.173.251.8!news1.iamerica.net!xavier.varmm.com!not-for-mail
From: AJ Musgrove <musgrove@xavier.varmm.com>
Newsgroups: comp.unix.bsd.freebsd.misc
Subject: Re: Locking master.passwd correctly
Date: 26 Dec 1996 19:52:00 GMT
Organization: LDS I-America
Lines: 42
Message-ID: <59ul10$r1t@news1.iamerica.net>
References: <59sro8$l1a@atlas.jcpenney.com>
NNTP-Posting-Host: 206.81.50.10
X-Newsreader: TIN [UNIX 1.3 unoff BETA release 960917]
Xref: euryale.cc.adfa.oz.au comp.unix.bsd.freebsd.misc:33068

drown <drown@chaos.taylored.com> wrote:
: Hi folks,

: I've had some weird problems lately with chfn stomping over my account
: creation software.  It seems that chfn doesn't "see" my lock on the 
: master.passwd file sometimes, even though at other times it does.  It seems 
: to be a race condition.  Here's the relivant perl code for locking the
: password file:

: open(MPW, "</etc/master.passwd") || die "cant locate $masterpw?!?!\n";
: if (!flock(MPW, 6)) {
:         close(MPW);
:         while(1) {
:                 open(MPW, "</etc/master.passwd");
:                 if (flock(MPW, 6)) { # Got it
:                        last;
:                 }
:                 close(MPW);
:                 sleep(5);
:         }
: }

: Seems like it should work.  The strange thing is that it usually _does_ work,
: it's just that every so often a user edits their info via chfn and boom,
: problems.  I've confirmed this by patching pwd_mkdb to log when it's called.

: Any ideas what could be causing this?  Am I locking the file incorrectly?

You are probably using advisory file locking on the master.passwd, and chfn
isn't checking for the lock.

Try turning on the setgid bit of master.passwd (which activates mandatory
locking on non-execute files). That may help.

-- 
AJ Musgrove

----------------------------------------------------------------
My opinions do not necessarily reflect those of my employer, or 
anyone else for that matter. O-
----------------------------------------------------------------