SUMMARY: setting passwords via a script

From: Bob Berrigan <berrigan_at_sun.kent.wednet.edu>
Date: Wed, 1 Feb 1995 10:35:55 +0800

I got lots of prompt responses from the kind people out there who had
answers to my problem. Thanks for taking your valuable time to help me out.

PROBLEM:
The passwd command can't be used in a script making it difficult for
automatic email account creation.

SOLUTIONS:
First of all, I was warned not to do this from a script because shell
scripts are not secure. Shell scripts display their activity in the process
table and thus can be seen by the 'ps' command. The better solution is to
write a C program.

The following solutions were suggested:

1) Use 'expect' & TCL (to build 'expect') [ or TK which is TCL for X11
windowing]

expect source: ftp.cme.nist.gov /pub/expect
TCL source: ftp.cs.berkeley.edu /ucb/tcl
 
If you are unfamiliar with TCL, look at the TCL-faq first:

  http://www.cis.ohio-state.edu/hypertext/faq/usenet/tcl-faq/top.html .

2) Use a perl script
        It has a subroutine for entering passwords which it encrypts and then
inserts into the password file.

3) Write a simple C program to create the encrypted password, several
suggestions (I haven't tried any yet):

     a) Call getpass(3).
              Call crypt(3) with a clear ascii password string to encrypt the password.

     b) This program:

/* crypt3.c */
  void
  main(argc, argv)
  int argc;
  char *argv[];
  {
          if (argc!=3) { printf("Usage: %s <key> <salt>\n",argv[0]); exit(1); }
        puts(crypt(argv[1],argv[2]));
        exit(0);
  }

When called as 'crypt3 xyzzy Ax' it will generate the encryption for
'xyzzy' using the salt 'Ax' (The salt is just a random two character
sequence - however not all characters are allowed here - letters are safe)

     c) This program.

this is C code to generate the encrypted string that you'd put in the
second field of the passwd file.
--<snip>
 char *p; /* pointer to plaintext passwd */
 long salt;
 int c,i;
 char saltc[2];

 (void) time(&salt);
 salt += getpid();
 saltc[0] = salt & 077;
 saltc[1] = (salt >> 6) & 077;
 for (i = 0; i < 2; i++) {
     c = saltc[i] + '.';
     if (c >= '9')
        c += 7;
     if (c > 'Z')
        c += 6;
     saltc[i] = c;
  }
 printf("%s\n",crypt(p, saltc));
Received on Wed Feb 01 1995 - 13:36:16 NZDT

This archive was generated by hypermail 2.4.0 : Wed Nov 08 2023 - 11:53:45 NZDT