>>Of course, you also find out what the necessary locking convention is,
>>so that your changes don't get blown away just because someone happened
>>to run passwd(1) at the same time.
>Would you enlighten me?
>I think the steps are..
>1. Copy /etc/passwd to /etc/passwd.new, changing it along the way
>2. rm /etc/passwd
>3. mv /etc/passwd.new /etc/passwd
>Tho I may be able to modify the directory entry directly, to point to
>the new file, instead of steps 2 & 3. That way there would not be a
>gap in time in which /etc/passwd doesn't exist.
That is certainly true, but you wouldn't know what data finally ends up in
Quote:>But I am ignorant of the "locking convention" .
Suppose two persons change their password at (almost) the same time.
The first one is going somewhere along step 1 when the second one begins,
creating (empty!) passwd.new while the first one was still writing it.
The steps 2 and 3 most possibly write an incomplete copy of the passwd
file when the first pass goes through - and at best the second pass only
has some duplicates and misses the changed data from the first use - at
worst you'd be looking at a severely corrupt passwd file.
One thing I've seen used as the lock to prevent multiple simultaneous edits
on passwd is to use the passwd.new itself as lock - don't proceed while
it exists. Naturally, here come some more problems; f.ex. the process that
created the passwd.new might have been killed before it finished so the
passwd.new never gets removed and no new changes can be committed.
One more problem will be to be compatible with the system "passwd"
command locking - you have also to prevent it from running while your
editing system is making changes. The problem here is that the passwd
command locking mechanism is often not documented, so you have to
make some educated guesses here (run passwd under "truss" or "strace",
run "strings" on the passwd binary to find out the locking mechanism).
Wolf a.k.a. Juha Laiho Espoo, Finland
(GC 3.0) GIT d- s+: a- C++ UH++++$ UL++++ P+ L+++ E-(---) W+ N+++ !K w !O
!M V PS(+) PE Y+ PGP(+) t- 5? !X R tv--- b+ DI? D+ G e+ h--- r++ y+
"...cancel my subscription to the resurrection!" (Jim Morrison)