[comp.unix.questions] can i read new passwords from a file?

mkhaw@teknowledge-vaxc.ARPA (Mike Khaw) (10/05/87)

Sorry to post to the net, we couldn't mail to bingvaxu.cc.binghamton.edu:

> Is there a simple way that I can read a set of userids & passwords from
> a file and have them change in /etc/passwd.  I'm trying to automate
> setting up accounts.  I've looked at the source for passwd.c which calls

I assume you mean that you have a list of usernames that are already in
/etc/passwd, paired up with unencrypted passwords, and you want to use the
list to change these users' passwords in /etc/passwd.

You can convert the unencrypted passwords to encrypted ones by using
/usr/lib/makekey.  It reads 10 characters from standard input (8 characters
to encrypt, plus a 2 character "salt" suffix from the set [0-9A-Za-z/.]),
and writes a 13 character encrypted result on standard output whose first
2 characters are the encryption salt.

So, you can write a shell script that reads your list and returns
effectively a list of commands for ex (or ed).  Feed these commands to ex
via a pipe to modify the passwd file:

	sh_script < cleartext_list | ex /etc/passwd

Of course, you ought to be a little more elaborate and use the same file
locking convention that vipw, chfn, and passwd obey:  check that /etc/ptmp
doesn't exist, create /etc/ptmp, modify /etc/passwd, remove /etc/ptmp.

You might also consider that keeping a list with cleartext passwords is
risky, even if the file is readable only to root.  DEC supplies Ultrix
with an /etc/adduser shell script that you can customize for your site.
I don't recall what they do about setting passwords (probably nothing),
but you can easily add that feature using makekey.

Mike Khaw

-- 
internet:  mkhaw@teknowledge-vaxc.arpa
usenet:	   {uunet|sun|ucbvax|decwrl|uw-beaver}!mkhaw%teknowledge-vaxc.arpa
USnail:	   Teknowledge Inc, 1850 Embarcadero Rd, POB 10119, Palo Alto, CA 94303