[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: add user ?



On Fri, 21 Feb 1997, Michael K. Johnson wrote:

> 
> if [ -f $PLOCK ]; then
> 	echo "$PASSWD is locked.  Try again later." ; exit 1
> fi
> touch $PLOCK ;

There is still a race condition here, a small window of opportunity
between the test for PLOCK and the setting of PLOCK. While this script
wont corrupt a passwd or group file it could easily lose information and
give unpredictable results should two people happen to be using it at the
same time (how likely that is is really besides the point). 

Consider users A and B using this, user A does the test for PLOCK, doesn't
find it but gets swapped out before the touch. User B then does the test
and it doesn't exist either so falls through. They both believe they have
the lock and barrel along. They will both pick the same `next' uid and gid
but clearly only one will win. You will have two directories created under
the same UID (but only one login name). It is even possible that
/etc/group, /etc/passwd and /etc/shadow contain different ideas of who
owns a UID.

Not the end of the world but not the right thing either. The ln trick
Sasha pointed out (probably) gets around this problem.

I don't see how this script addresses his concerns re: /etc/group but then
I don't think anything can (unless I misunderstand his concerns). There is
always some point at which a read on /etc/group or /etc/passwd could fail
to give the right answer, what is one to do? You can't make this whole
script atomic.

cheers, kinch






[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index] []