[comp.unix.wizards] New user .login file && a question

mesard@bbn.com (Wayne Mesard) (08/23/88)

When adding new users to my system I give them a ~/.login file which
forces them to change their password the first time they login.  After
they do this, the ~/.login modifes itself to strip out the first-time-
only stuff.  I.e. all the lines containing the string "FIRST_LOGIN" get
removed.  This is all straight forward, but pretty useful nonetheless,
so I've included it below for all who are interested.

Now, my question is that I originally, had the self-modifying stuff (the
grep and cp) in the middle of the file (immediately after the while loop)
thinking that the shell would keep the file open until it was done
reading it.  Well, no such luck.  It only got a few lines past the
cp (presumably to the end of the disk block?).

What gives?  Why would csh lose it's place in what I expected to be an
unlink'ed but not yet forgotten file?

Thanks in advance for enlightening me.

---CLIP---------------------------SNIP----------------------------CLIP---
onintr -                                                     #FIRST_LOGIN
   < SYS ADMINS:  Put the commands that you want everyone to have >
   < in their default ~/.login files here.  E.g. setenv PATH,     >
   < terminal-type setting, etc.                                  >
echo  -----                                                  #FIRST_LOGIN
echo Since this is your first time logging onto $HOST,       #FIRST_LOGIN
echo you should change your password to something which      #FIRST_LOGIN
echo you will remember and that others are not likely to     #FIRST_LOGIN
echo discover.  The security of this machine is your         #FIRST_LOGIN
echo responsibility!                                         #FIRST_LOGIN
echo  -----                                                  #FIRST_LOGIN
set oldenpw = `grep $user /etc/passwd | cut -d: -f2`         #FIRST_LOGIN
passwd                                                       #FIRST_LOGIN
while ($oldenpw == `grep $user /etc/passwd | cut -d: -f2`)   #FIRST_LOGIN
    echo Try again.  You MUST change your password.          #FIRST_LOGIN
    passwd                                                   #FIRST_LOGIN
end                                                          #FIRST_LOGIN
echo  -----                                                  #FIRST_LOGIN
echo Thank you for your cooperation.  If you forget your     #FIRST_LOGIN
echo password in the future, your system administrator       #FIRST_LOGIN
echo can assign you a new one.  Welcome aboard.              #FIRST_LOGIN
echo  -----                                                  #FIRST_LOGIN
echo                                                         #FIRST_LOGIN
onintr                                                       #FIRST_LOGIN

/usr/games/fortune
grep -v "FIRST_LOGIN" ~/.login > /tmp/$user.login            #FIRST_LOGIN
cp /tmp/$user.login ~/.login                                 #FIRST_LOGIN
---CLIP---------------------------SNIP----------------------------CLIP---

-- 
unsigned *Wayne_Mesard();        MESARD@BBN.COM           BBN, Cambridge, MA

           I can't imitate the President.
                                          -George Bush

barmar@think.COM (Barry Margolin) (08/24/88)

In article <28862@bbn.COM> mesard@BBN.COM () writes:
>What gives?  Why would csh lose it's place in what I expected to be an
>unlink'ed but not yet forgotten file?

Because I don't think that "cp file existing_file" ever actually
unlinks existing_file.  It simply overwrites it.  What you should have
done is:

grep -v "FIRST_LOGIN" ~/.login > /tmp/$user.login
rm ~/.login
mv /tmp/$user.login ~/.login

Barry Margolin
Thinking Machines Corp.

barmar@think.com
{uunet,harvard}!think!barmar

ditto@cbmvax.UUCP (Michael "Ford" Ditto) (08/25/88)

In article <28862@bbn.COM> mesard@BBN.COM () writes:
>grep -v "FIRST_LOGIN" ~/.login > /tmp/$user.login            #FIRST_LOGIN
>cp /tmp/$user.login ~/.login                                 #FIRST_LOGIN

>What gives?  Why would csh lose it's place in what I expected to be an
>unlink'ed but not yet forgotten file?
 ^^^^^^

You never unlinked the file.  Put a "rm ~/.login" in between the grep
and the cp.  Remember that this will lose the mode settings of ~/.login,

A better way would be something like:

	if ( -f ~/.firstlogin ) source ~/.firstlogin

and ~/.firstlogin could remove itself any time it saw fit.
-- 
					-=] Ford [=-

	.		.		(In Real Life: Mike Ditto)
.	    :	       ,		ford@kenobi.cts.com
This space under construction,		...!ucsd!elgar!ford
pardon our dust.			ditto@cbmvax.commodore.com

bzs@encore.UUCP (Barry Shein) (08/27/88)

Having a new user .login which changes itself into a not-new user
.login seems like a fine idea. What I don't understand is why do you
use all that grepping etc to a tmp file to build the other, why not
just have two .logins (.login and .login.2) and just mv the second
over the first and avoid the fancy dancing (I dunno, someday you'll
hit a full /tmp/ or something.) Seems a mv is a simpler thing, who
cares if they have a bunch of lines in common (in fact, on the first
entry the new-user .login could source the second if that's what you
want, I'd just duplicate them to avoid stuff like having the file
open.)

Occam's lektra-shave or some such.

	-Barry Shein, ||Encore||