1824925 Members
3909 Online
109677 Solutions
New Discussion юеВ

Passwd lock

 
Shondra Eppinger
Occasional Advisor

Passwd lock

I want to lock the /etc/passwd file when I or some other local SA is in it.

I also have a third party application for passwd synchronization that will require the password be locked at different times.

Does anyone know of any scripts that have already been written that will help me.

R-
3 REPLIES 3
Victor BERRIDGE
Honored Contributor

Re: Passwd lock

Hi,
If you use vipw (like most of us) you should have to worry about it for vipw when invoked creates a lock if my memory serves me..., as /etc/.pwd.lock ...
So 2 admins cannot be editing /etc/passwd at the same time...

All the best
Victor
A. Clay Stephenson
Acclaimed Contributor

Re: Passwd lock

Hi Rick,

I'm not quite sure what you mean by 'lock'. Does that mean that no users can login? Does that mean than no one else can alter the file but it can still be read?

One point to keep in mind, since anyone with UID 0 (i.e. root) and always do anything to any file any scheme you come up with will be advisory only. I would do something like this:
When you are about to alter the passwd file, test for the existence of a directory '/var/tmp/pw_lock'.

e.g.
LOCKDIR=/var/tmp/pw_lock
LOCKFILE=${LOCKDIR}/lock
if [ ! -d ${LOCKDIR} ]
then
mkdir ${LOCKDIR}
echo "${LOGNAME}" > ${LOCKFILE}
chmod 644 ${LOCKFILE}
...
do your edit stuff
rmdir -rf ${LOCKDIR}
else
echo "Passwd file is locked\c"
if [ -f ${LOCKFILE} -a -r ${LOCKFILE} ]
then
echo "by user \c"
cat ${LOCKFILE}
fi
echo
fi

------------------------
Regards, Clay
If it ain't broke, I can fix that.
James R. Ferguson
Acclaimed Contributor

Re: Passwd lock

Hi Rick:

Victor is correct. Take a look at the man pages for 'vipw' for further information.

...JRF...