version 1.8, 1999/05/19 03:17:15 |
version 1.9, 1999/05/20 00:05:39 |
|
|
|
|
void usage() |
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); |
progname); |
exit(1); |
exit(1); |
} |
} |
|
|
{ |
{ |
int opt; |
int opt; |
int operation = -1; |
int operation = -1; |
|
int prompt = 0; |
int rounds; |
int rounds; |
void *extra; /* Store salt or number of rounds */ |
void *extra; /* Store salt or number of rounds */ |
|
|
|
|
if (strcmp(progname, "makekey") == 0) |
if (strcmp(progname, "makekey") == 0) |
operation = DO_MAKEKEY; |
operation = DO_MAKEKEY; |
|
|
while ((opt = getopt(argc, argv, "kms:b:")) != -1) { |
while ((opt = getopt(argc, argv, "kmps:b:")) != -1) { |
switch (opt) { |
switch (opt) { |
case 'k': /* Stdin/Stdout Unix crypt */ |
case 'k': /* Stdin/Stdout Unix crypt */ |
if (operation != -1) |
if (operation != -1) |
|
|
operation = DO_MAKEKEY; |
operation = DO_MAKEKEY; |
break; |
break; |
case 'm': /* MD5 password hash */ |
case 'm': /* MD5 password hash */ |
if (operation != -1) |
if (operation != -1 || prompt) |
usage(); |
usage(); |
operation = DO_MD5; |
operation = DO_MD5; |
break; |
break; |
|
case 'p': |
|
if (operation != -1) |
|
usage(); |
|
prompt = 1; |
|
break; |
case 's': /* Unix crypt (DES) */ |
case 's': /* Unix crypt (DES) */ |
if (operation != -1) |
if (operation != -1) |
usage(); |
usage(); |
|
|
if (((argc - optind) < 1) || operation == DO_MAKEKEY) { |
if (((argc - optind) < 1) || operation == DO_MAKEKEY) { |
char line[BUFSIZ], *string; |
char line[BUFSIZ], *string; |
|
|
/* Encrypt stdin to stdout. */ |
if (prompt) { |
while (!feof(stdin) && (fgets(line, sizeof(line), stdin) != NULL)) { |
string = getpass("Enter string: "); |
/* Kill the whitesapce. */ |
|
string = trim(line); |
|
if (*string == '\0') |
|
continue; |
|
|
|
print_passwd(string, operation, extra); |
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) { |
if (operation == DO_MAKEKEY) { |
fflush(stdout); |
fflush(stdout); |
break; |
break; |
|
} |
|
fputc('\n', stdout); |
} |
} |
fputc('\n', stdout); |
|
} |
} |
} else { |
} else { |
char *string; |
char *string; |
|
|
|
/* can't combine -p with a supplied string */ |
|
if (prompt) |
|
usage(); |
|
|
/* Perhaps it isn't worth worrying about, but... */ |
/* Perhaps it isn't worth worrying about, but... */ |
string = strdup(argv[optind]); |
string = strdup(argv[optind]); |