From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <96075317506331.tru64-unix-managers.marc@archive.invalid> From: berrigan () sun ! kent ! wednet ! edu (Bob Berrigan) Date: Wed, 01 Feb 1995 02:35:55 +0000 To: tru64-unix-managers Subject: SUMMARY: setting passwords via a script X-MARC-Message: https://marc.info/?l=tru64-unix-managers&m=96075317506331 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 \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. -- 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));