summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKenneth R Westerback <krw@cvs.openbsd.org>2007-07-14 21:26:39 +0000
committerKenneth R Westerback <krw@cvs.openbsd.org>2007-07-14 21:26:39 +0000
commitc5c868433a3b868da4621122aab81330ed6bff49 (patch)
tree52d2fb33d12b07254a5621270946bdb51356ef9a
parent0d58ef99ab74d4e11c50f5af762cacc123afcbd6 (diff)
Don't trim whitespace from stdin. Encrypt it the same as other
input sources. Feedback and fixes from ray@ and fgsch@. ok millert@ (six years ago) ray@ fgsch@
-rw-r--r--usr.bin/encrypt/encrypt.c35
1 files changed, 8 insertions, 27 deletions
diff --git a/usr.bin/encrypt/encrypt.c b/usr.bin/encrypt/encrypt.c
index e243d34441d..08d97c373fe 100644
--- a/usr.bin/encrypt/encrypt.c
+++ b/usr.bin/encrypt/encrypt.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: encrypt.c,v 1.27 2007/05/01 01:26:25 jdixon Exp $ */
+/* $OpenBSD: encrypt.c,v 1.28 2007/07/14 21:26:38 krw Exp $ */
/*
* Copyright (c) 1996, Jason Downs. All rights reserved.
@@ -51,7 +51,6 @@ extern char *__progname;
char buffer[_PASSWORD_LEN];
void usage(void);
-char *trim(char *);
void print_passwd(char *, int, void *);
void
@@ -64,26 +63,6 @@ usage(void)
exit(1);
}
-char *
-trim(char *line)
-{
- char *ptr;
-
- if (line[0] == '\0')
- return (line);
-
- for (ptr = &line[strlen(line)-1]; ptr > line; ptr--) {
- if (!isspace(*ptr))
- break;
- }
- ptr[1] = '\0';
-
- for (ptr = line; isspace(*ptr); ptr++)
- ;
-
- return(ptr);
-}
-
void
print_passwd(char *string, int operation, void *extra)
{
@@ -206,15 +185,17 @@ main(int argc, char **argv)
print_passwd(string, operation, extra);
(void)fputc('\n', stdout);
} else {
+ size_t len;
/* Encrypt stdin to stdout. */
while (!feof(stdin) &&
(fgets(line, sizeof(line), stdin) != NULL)) {
- /* Kill the whitesapce. */
- string = trim(line);
- if (*string == '\0')
+ len = strlen(line);
+ if (len == 0 || line[0] == '\n')
continue;
-
- print_passwd(string, operation, extra);
+ if (line[len - 1] == '\n')
+ line[len - 1] = '\0';
+
+ print_passwd(line, operation, extra);
if (operation == DO_MAKEKEY) {
fflush(stdout);