mirror of
https://github.com/openbsd/src.git
synced 2025-01-10 06:47:55 -08:00
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@
This commit is contained in:
parent
b23b74b3a9
commit
da731e2410
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user