[comp.unix.questions] How can I pipe input into passwd?

00499@vax1.acs.udel.edu (WEAVERLING) (08/25/89)

I administrate a UNIX sys at the college I work at.  They gave me this
box last year. At that time I had never touched UNIX before, even as a
user! 

I've been doing OK so far, but I'm stumped on one thing. Each quarter I
have to generate 500 user IDs for students. I build a script that 
does this (by piping into sysadm) from student registration data from
our administrative mainframe (Unisys A5). 

THE PROBLEM! How can I easily enter passwords for each account auto-
magically. I can't pipe into passwd cause he goes after /dev/tty. I'd
use makekey, but Prime (in their infinite wisdom) doesn't include it
with their unix (or crypt). 

Details... Box is Prime EXL 316 running Microport's UNIX V/386 3.0  
(3.1 is "in the mail").  Bourne shell is all we have. I *do* know
C but am still learning the myriad of UNIX routines available.

Any help appreciated. Please no flames, I've read all of the *fine*
manuals I got.  E-mail to me and I'll summarise and post. Thx :-)

Ken Weaverling
Delaware Technical & Community College
+1 302 573 5460
 
Internet: 00499@vax1.acs.udel.edu    (one day my box will be on the net :-)

danl@midget.towson.edu (08/28/89)

>I've been doing OK so far, but I'm stumped on one thing. Each quarter I
>have to generate 500 user IDs for students. I build a script that
>does this (by piping into sysadm) from student registration data from
>our administrative mainframe (Unisys A5).
> 
>THE PROBLEM! How can I easily enter passwords for each account auto-
>magically. I can't pipe into passwd cause he goes after /dev/tty. I'd
>use makekey, but Prime (in their infinite wisdom) doesn't include it
>with their unix (or crypt).
> 
>Ken Weaverling
>Delaware Technical & Community College
>+1 302 573 5460

I have the same problem more or less.  You can't pipe to passwd because it
flushes the buffer before reading.

I solved it by writing a C program to do the complete generation of user
accounts - creation of the directory, password file entry, null mailbox,
and copying of a skeleton .login, .cshrc, and .profile.  The trick with the
password is with the crypt() function.  I assume from your message that you
are missing the crypt command and not the crypt function.  The password field
of the password entry is generated via crypt().  I generate random passwords,
and random two character salts for the crypt function, and feed crypt()
these salts and a random password.  The returned string is the password
field of the password entry.  A log is generated containing the user names
and passwords for distribution to classes.

The program is four years old and needs some cleaning up (I've learned much
since then), but it still works.  Anyone who wants it, let me know and i'll
send you a copy.  If I get enough response, I'll make it available via ftp
and VMSserv (BITNET).

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dan Gosner				Internet: danl@midget.towson.edu
Operations Manager				  DGosner@TOE.TOWSON.EDU 
Towson State University			Bitnet:   DGosner@TOWSONVX
Towson, Maryland  21204
   %% VMS pays the bills, but Unix is where my real work gets done. %%
***************************************************************************