home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / unix / admin / 7216 < prev    next >
Encoding:
Text File  |  1993-01-23  |  2.2 KB  |  67 lines

  1. Newsgroups: comp.unix.admin
  2. Path: sparky!uunet!cs.utexas.edu!zaphod.mps.ohio-state.edu!uwm.edu!linac!uchinews!machine!gagme!gagme!greg
  3. From: greg@serveme.chi.il.us (Gregory Gulik)
  4. Subject: Re: Set a password from a shell script?
  5. Message-ID: <1993Jan23.071016.11651@serveme.chi.il.us>
  6. Organization: Gagme Public Access Unix, Chicago, Illinois
  7. References: <1993Jan19.230306.12818@wl.com>
  8. Date: Sat, 23 Jan 1993 07:10:16 GMT
  9. Lines: 56
  10.  
  11. In article <1993Jan19.230306.12818@wl.com> duffiem@wl.com (Mark Duffield) writes:
  12. >G'day!
  13. >
  14. >I am looking for a program (c, shell, perl) that will allow me to
  15. >set a users password from a shell script.  This program will only be run from
  16. >root.  As you probably know, passwd(1) won't let you do this.  I have alot
  17. >of users to create and I don't want to:
  18. >
  19. >    1)Not set passwords for them initially.
  20. >    2)Give them all the same password
  21. >    3)Make a typo while typing them all in.
  22. >
  23. >Any ideas on where to find this program would be appreciated.  I have a couple
  24. >of things that when desperate will work, but it ain't pretty.
  25.  
  26. This is how I currently do it.  This is the function that does
  27. the work.  It's part of a much bigger program.  Basically, one
  28. of the things it does is read the password from standard input
  29. and spits out the encrypted password on standard output.  This
  30. makes it easy to use in shell scripts:
  31.  
  32. char *crypt ();
  33. char valid_seeds[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
  34.     .
  35.     .
  36.     .
  37. /*
  38.  * cryptpw()
  39.  * This is the actual function that does the work.
  40.  */
  41.  
  42. char *
  43. cryptpw (password)
  44.      char *password;
  45. {
  46.   char seed[3];
  47.  
  48.   srand (time (0));
  49.   seed[2] = (char) 0;
  50.   seed[0] = valid_seeds[rand () % strlen (valid_seeds)];
  51.   seed[1] = valid_seeds[rand () % strlen (valid_seeds)];
  52.  
  53.   return (crypt (password, seed));
  54. }
  55.  
  56.  
  57. It's short, sweet, and works on both my 3B2 Running System V
  58. and my Sun running SunOS 4.1.1
  59.  
  60. -greg
  61.  
  62. -- 
  63. Gregory A. Gulik                                 Call Gagme, a public access
  64.        greg@serveme.chi.il.us                    UNIX system at 312-282-8606
  65.    ||  gulik@rtsg.mot.com                        For information, drop a note
  66.                                                  to info@gagme.chi.il.us
  67.