How can I pipe into passwd?

andre andre at targon.UUCP
Sat Aug 26 00:52:06 AEST 1989


Sorry, but uunet bounced my mail with a 'host unknown'.

In article <20704 at adm.BRL.MIL> you write:
>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). 

I think it is easier to make a program that does this for you,
the crypt function is in your libc, and if you have root permission
you can insert the crypted passwords into the passwd file.

the code could look like;

/* usage: mksed <user+passwords >sed_script */
/* user_passwords has lines as 'user:passwd'*/
main()
{
	char user[64];
	char passwd[64];
	char salt[8];
	extern char *crypt();

	printf("sed \\\n");

	strcpy(salt, "dAy");    /* or choose a random one */

	while (scanf("%s:%s\n", user, passwd))
	{
		printf("-e 's/^%s::/%s:%s:/' \\\n", user, user,
			crypt(passwd, salt));
	}

	printf(" /etc/passwd \n");
}

This will take a file that tells you which users should have what
password and generates a sed script that will give the new version
of /etc/passwd on stdout. You can then become root and apply it.

	Hope this help, Andre van Dalen.

PS: No flames about the code please, it is only meant to give an idea
    for a quick solution and untested.

-- 
    \---|    AAA         DDDD  It's not the kill, but the thrill of the chase.
     \  |   AA AAvv   vvDD  DD        Ketchup is a vegetable.
  /\  \ |  AAAAAAAvv vvDD  DD                    {nixbur|nixtor}!adalen.via
_/__\__\| AAA   AAAvvvDDDDDD    Andre van Dalen, uunet!hp4nl!targon!andre



More information about the Comp.unix.questions mailing list