home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.admin
- Path: sparky!uunet!cs.utexas.edu!zaphod.mps.ohio-state.edu!uwm.edu!linac!uchinews!machine!gagme!gagme!greg
- From: greg@serveme.chi.il.us (Gregory Gulik)
- Subject: Re: Set a password from a shell script?
- Message-ID: <1993Jan23.071016.11651@serveme.chi.il.us>
- Organization: Gagme Public Access Unix, Chicago, Illinois
- References: <1993Jan19.230306.12818@wl.com>
- Date: Sat, 23 Jan 1993 07:10:16 GMT
- Lines: 56
-
- In article <1993Jan19.230306.12818@wl.com> duffiem@wl.com (Mark Duffield) writes:
- >G'day!
- >
- >I am looking for a program (c, shell, perl) that will allow me to
- >set a users password from a shell script. This program will only be run from
- >root. As you probably know, passwd(1) won't let you do this. I have alot
- >of users to create and I don't want to:
- >
- > 1)Not set passwords for them initially.
- > 2)Give them all the same password
- > 3)Make a typo while typing them all in.
- >
- >Any ideas on where to find this program would be appreciated. I have a couple
- >of things that when desperate will work, but it ain't pretty.
-
- This is how I currently do it. This is the function that does
- the work. It's part of a much bigger program. Basically, one
- of the things it does is read the password from standard input
- and spits out the encrypted password on standard output. This
- makes it easy to use in shell scripts:
-
- char *crypt ();
- char valid_seeds[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
- .
- .
- .
- /*
- * cryptpw()
- * This is the actual function that does the work.
- */
-
- char *
- cryptpw (password)
- char *password;
- {
- char seed[3];
-
- srand (time (0));
- seed[2] = (char) 0;
- seed[0] = valid_seeds[rand () % strlen (valid_seeds)];
- seed[1] = valid_seeds[rand () % strlen (valid_seeds)];
-
- return (crypt (password, seed));
- }
-
-
- It's short, sweet, and works on both my 3B2 Running System V
- and my Sun running SunOS 4.1.1
-
- -greg
-
- --
- Gregory A. Gulik Call Gagme, a public access
- greg@serveme.chi.il.us UNIX system at 312-282-8606
- || gulik@rtsg.mot.com For information, drop a note
- to info@gagme.chi.il.us
-