diff options
author | Jason Downs <downsj@cvs.openbsd.org> | 1996-08-08 04:37:03 +0000 |
---|---|---|
committer | Jason Downs <downsj@cvs.openbsd.org> | 1996-08-08 04:37:03 +0000 |
commit | 152428c1e14402073534e5a6f5a9273dd6c31de4 (patch) | |
tree | 05d7185f5800a4f43c9a564bc623e35aa4033b37 | |
parent | 5884e42160d357130edf290ebb3ca2c80c984d19 (diff) |
Slightly cleaner.
-rw-r--r-- | usr.bin/encrypt/encrypt.1 | 6 | ||||
-rw-r--r-- | usr.bin/encrypt/encrypt.c | 30 |
2 files changed, 27 insertions, 9 deletions
diff --git a/usr.bin/encrypt/encrypt.1 b/usr.bin/encrypt/encrypt.1 index ec8d06c26b3..d0a82d5fb23 100644 --- a/usr.bin/encrypt/encrypt.1 +++ b/usr.bin/encrypt/encrypt.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: encrypt.1,v 1.2 1996/08/08 02:10:20 downsj Exp $ +.\" $OpenBSD: encrypt.1,v 1.3 1996/08/08 04:37:01 downsj Exp $ .\" .\" Copyright (c) 1996, Jason Downs. All rights reserved. .\" @@ -58,6 +58,10 @@ is specified, reads one string per line from standard input, encrypting each one with the same .Ar salt . +Specifing the +.Ar string +on the command line should be discouraged; using the +standard input is more secure. .Sh SEE ALSO .Xr crypt 3 , .Xr adduser 8 diff --git a/usr.bin/encrypt/encrypt.c b/usr.bin/encrypt/encrypt.c index ac593c38ae4..9fa98117bae 100644 --- a/usr.bin/encrypt/encrypt.c +++ b/usr.bin/encrypt/encrypt.c @@ -1,4 +1,4 @@ -/* $OpenBSD: encrypt.c,v 1.1 1996/08/08 02:07:22 downsj Exp $ */ +/* $OpenBSD: encrypt.c,v 1.2 1996/08/08 04:37:02 downsj Exp $ */ /* * Copyright (c) 1996, Jason Downs. All rights reserved. @@ -45,6 +45,22 @@ void usage() errx(1, "usage: %s [-m] [-s salt] [string]", __progname); } +char *trim(line) + char *line; +{ + char *ptr; + + for (ptr = &line[strlen(line)-1]; ptr > line; ptr--) { + if (!isspace(*ptr)) + break; + } + ptr[1] = '\0'; + + for (ptr = line; *ptr && isspace(*ptr); ptr++); + + return(ptr); +} + int main(argc, argv) int argc; char *argv[]; @@ -73,18 +89,16 @@ int main(argc, argv) usage(); if ((argc - optind) < 1) { - char line[BUFSIZ]; + char line[BUFSIZ], *string; /* Encrypt stdin to stdout. */ while (!feof(stdin) && (fgets(line, sizeof(line), stdin) != NULL)) { - if ((line[0] == '\0') || (line[0] == '\n')) + /* Kill the whitesapce. */ + string = trim(line); + if (*string == '\0') continue; - /* Kill the newline. */ - if (line[strlen(line)] == '\n') - line[strlen(line)] = '\0'; - - fputs(crypt(line, (do_md5 ? "$1$" : salt)), stdout); + fputs(crypt(string, (do_md5 ? "$1$" : salt)), stdout); fputc('\n', stdout); } } else { |