diff options
author | Alex Feldman <alex@cvs.openbsd.org> | 1999-05-20 00:05:40 +0000 |
---|---|---|
committer | Alex Feldman <alex@cvs.openbsd.org> | 1999-05-20 00:05:40 +0000 |
commit | 3488b849b4bcd67c5bbb3fd11f818fa18c598400 (patch) | |
tree | 1bc9121820964bedcc2ce7618d468cb188e0a9b4 | |
parent | 9be4087c3d281c023bde5e2b725d757df9c87bcf (diff) |
Add -p flag, prompt for a string with echo off.
-rw-r--r-- | usr.bin/encrypt/encrypt.1 | 8 | ||||
-rw-r--r-- | usr.bin/encrypt/encrypt.c | 48 |
2 files changed, 37 insertions, 19 deletions
diff --git a/usr.bin/encrypt/encrypt.1 b/usr.bin/encrypt/encrypt.1 index a38a252ffc0..851d8b3c5a4 100644 --- a/usr.bin/encrypt/encrypt.1 +++ b/usr.bin/encrypt/encrypt.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: encrypt.1,v 1.9 1998/11/11 23:01:42 aaron Exp $ +.\" $OpenBSD: encrypt.1,v 1.10 1999/05/20 00:05:39 alex Exp $ .\" .\" Copyright (c) 1996, Jason Downs. All rights reserved. .\" @@ -23,7 +23,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd August 7, 1996 +.Dd May 18, 1999 .Dt ENCRYPT 1 .Os OpenBSD .Sh NAME @@ -35,7 +35,7 @@ .Op Fl b Ar rounds .Op Fl m .Op Fl s Ar salt -.Op Ar string +.Op Fl p | Ar string .Nm makekey .Sh DESCRIPTION .Nm encrypt @@ -57,6 +57,8 @@ Encrypt the string using Blowfish hashing with the specified .Ar rounds . .It Fl m Encrypt the string using MD5. +.It Fl p +Prompt for a single string with echo turned off. .It Fl s Ar salt Encrypt the string using DES, with the specified .Ar salt . diff --git a/usr.bin/encrypt/encrypt.c b/usr.bin/encrypt/encrypt.c index a9c6ced3595..397d93252dd 100644 --- a/usr.bin/encrypt/encrypt.c +++ b/usr.bin/encrypt/encrypt.c @@ -1,4 +1,4 @@ -/* $OpenBSD: encrypt.c,v 1.8 1999/05/19 03:17:15 alex Exp $ */ +/* $OpenBSD: encrypt.c,v 1.9 1999/05/20 00:05:39 alex Exp $ */ /* * Copyright (c) 1996, Jason Downs. All rights reserved. @@ -52,7 +52,7 @@ char buffer[_PASSWORD_LEN]; void usage() { - fprintf(stderr, "usage: %s [-k] [-b rounds] [-m] [-s salt] [string]\n", + fprintf(stderr, "usage: %s [-k] [-b rounds] [-m] [-s salt] [-p | string]\n", progname); exit(1); } @@ -127,6 +127,7 @@ int main(argc, argv) { int opt; int operation = -1; + int prompt = 0; int rounds; void *extra; /* Store salt or number of rounds */ @@ -138,7 +139,7 @@ int main(argc, argv) if (strcmp(progname, "makekey") == 0) operation = DO_MAKEKEY; - while ((opt = getopt(argc, argv, "kms:b:")) != -1) { + while ((opt = getopt(argc, argv, "kmps:b:")) != -1) { switch (opt) { case 'k': /* Stdin/Stdout Unix crypt */ if (operation != -1) @@ -146,10 +147,15 @@ int main(argc, argv) operation = DO_MAKEKEY; break; case 'm': /* MD5 password hash */ - if (operation != -1) + 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,24 +179,34 @@ int main(argc, argv) 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; - + if (prompt) { + string = getpass("Enter string: "); print_passwd(string, operation, extra); - - if (operation == DO_MAKEKEY) { - fflush(stdout); - break; - } 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]); if (string == NULL) |