=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/encrypt/encrypt.c,v retrieving revision 1.8 retrieving revision 1.9 diff -c -r1.8 -r1.9 *** src/usr.bin/encrypt/encrypt.c 1999/05/19 03:17:15 1.8 --- src/usr.bin/encrypt/encrypt.c 1999/05/20 00:05:39 1.9 *************** *** 1,4 **** ! /* $OpenBSD: encrypt.c,v 1.8 1999/05/19 03:17:15 alex Exp $ */ /* * Copyright (c) 1996, Jason Downs. All rights reserved. --- 1,4 ---- ! /* $OpenBSD: encrypt.c,v 1.9 1999/05/20 00:05:39 alex Exp $ */ /* * Copyright (c) 1996, Jason Downs. All rights reserved. *************** *** 52,58 **** void usage() { ! fprintf(stderr, "usage: %s [-k] [-b rounds] [-m] [-s salt] [string]\n", progname); exit(1); } --- 52,58 ---- void usage() { ! fprintf(stderr, "usage: %s [-k] [-b rounds] [-m] [-s salt] [-p | string]\n", progname); exit(1); } *************** *** 127,132 **** --- 127,133 ---- { int opt; int operation = -1; + int prompt = 0; int rounds; void *extra; /* Store salt or number of rounds */ *************** *** 138,144 **** if (strcmp(progname, "makekey") == 0) operation = DO_MAKEKEY; ! while ((opt = getopt(argc, argv, "kms:b:")) != -1) { switch (opt) { case 'k': /* Stdin/Stdout Unix crypt */ if (operation != -1) --- 139,145 ---- if (strcmp(progname, "makekey") == 0) operation = DO_MAKEKEY; ! while ((opt = getopt(argc, argv, "kmps:b:")) != -1) { switch (opt) { case 'k': /* Stdin/Stdout Unix crypt */ if (operation != -1) *************** *** 146,155 **** operation = DO_MAKEKEY; break; case 'm': /* MD5 password hash */ ! if (operation != -1) usage(); operation = DO_MD5; break; case 's': /* Unix crypt (DES) */ if (operation != -1) usage(); --- 147,161 ---- operation = DO_MAKEKEY; break; case 'm': /* MD5 password hash */ ! if (operation != -1 || prompt) usage(); operation = DO_MD5; break; + case 'p': + if (operation != -1) + usage(); + prompt = 1; + break; case 's': /* Unix crypt (DES) */ if (operation != -1) usage(); *************** *** 173,195 **** if (((argc - optind) < 1) || operation == DO_MAKEKEY) { char line[BUFSIZ], *string; ! /* Encrypt stdin to stdout. */ ! while (!feof(stdin) && (fgets(line, sizeof(line), stdin) != NULL)) { ! /* Kill the whitesapce. */ ! string = trim(line); ! if (*string == '\0') ! continue; ! print_passwd(string, operation, extra); ! if (operation == DO_MAKEKEY) { ! fflush(stdout); ! break; } - fputc('\n', stdout); } } else { char *string; /* Perhaps it isn't worth worrying about, but... */ string = strdup(argv[optind]); --- 179,211 ---- if (((argc - optind) < 1) || operation == DO_MAKEKEY) { char line[BUFSIZ], *string; ! if (prompt) { ! string = getpass("Enter string: "); print_passwd(string, operation, extra); + fputc('\n', stdout); + } else { + /* Encrypt stdin to stdout. */ + while (!feof(stdin) && (fgets(line, sizeof(line), stdin) != NULL)) { + /* Kill the whitesapce. */ + string = trim(line); + if (*string == '\0') + continue; + + print_passwd(string, operation, extra); ! if (operation == DO_MAKEKEY) { ! fflush(stdout); ! break; ! } ! fputc('\n', stdout); } } } else { char *string; + + /* can't combine -p with a supplied string */ + if (prompt) + usage(); /* Perhaps it isn't worth worrying about, but... */ string = strdup(argv[optind]);