diff options
-rw-r--r-- | bin/md5/cksum.1 | 9 | ||||
-rw-r--r-- | bin/md5/md5.c | 68 |
2 files changed, 63 insertions, 14 deletions
diff --git a/bin/md5/cksum.1 b/bin/md5/cksum.1 index 8423d694dbe..e1ad4b05957 100644 --- a/bin/md5/cksum.1 +++ b/bin/md5/cksum.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: cksum.1,v 1.17 2007/05/31 19:19:15 jmc Exp $ +.\" $OpenBSD: cksum.1,v 1.18 2008/07/29 18:24:31 sobrado Exp $ .\" .\" Copyright (c) 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -32,7 +32,7 @@ .\" .\" @(#)cksum.1 8.2 (Berkeley) 4/28/95 .\" -.Dd $Mdocdate: May 31 2007 $ +.Dd $Mdocdate: July 29 2008 $ .Dt CKSUM 1 .Os .Sh NAME @@ -50,6 +50,11 @@ .Op Ar file ... .Ek .Nm sum +.Op Fl bpqrtx +.Op Fl a Ar algorithms +.Op Fl c Op Ar checklist ... +.Op Fl o Ar 1 | 2 +.Op Fl s Ar string .Op Ar file ... .Sh DESCRIPTION The diff --git a/bin/md5/md5.c b/bin/md5/md5.c index d26900e99f1..d429e8201d6 100644 --- a/bin/md5/md5.c +++ b/bin/md5/md5.c @@ -1,4 +1,4 @@ -/* $OpenBSD: md5.c,v 1.48 2007/11/07 09:52:25 chl Exp $ */ +/* $OpenBSD: md5.c,v 1.49 2008/07/29 18:24:31 sobrado Exp $ */ /* * Copyright (c) 2001,2003,2005-2006 Todd C. Miller <Todd.Miller@courtesan.com> @@ -46,6 +46,14 @@ #define MAX_DIGEST_LEN 128 +enum program_mode { + MODE_MD5, + MODE_SHA1, + MODE_RMD160, + MODE_CKSUM, + MODE_SUM +} pmode; + union ANY_CTX { CKSUM_CTX cksum; MD4_CTX md4; @@ -197,8 +205,6 @@ void usage(void) __attribute__((__noreturn__)); extern char *__progname; int qflag = 0; -#define OPTSTRING "a:bco:pqrs:tx" - int main(int argc, char **argv) { @@ -209,18 +215,43 @@ main(int argc, char **argv) int fl, error, base64; int bflag, cflag, pflag, rflag, tflag, xflag; + static const char *optstr[5] = { + "bcpqrs:tx", + "bcpqrs:tx", + "bcpqrs:tx", + "a:bco:pqrs:tx", + "a:bco:pqrs:tx" + }; + TAILQ_INIT(&hl); input_string = NULL; error = bflag = cflag = pflag = qflag = rflag = tflag = xflag = 0; + pmode = MODE_MD5; + if (strcmp(__progname, "md5") == 0) + pmode = MODE_MD5; + else if (strcmp(__progname, "sha1") == 0) + pmode = MODE_SHA1; + else if (strcmp(__progname, "rmd160") == 0) + pmode = MODE_RMD160; + else if (strcmp(__progname, "cksum") == 0) + pmode = MODE_CKSUM; + else if (strcmp(__progname, "sum") == 0) + pmode = MODE_SUM; + /* Check for -b option early since it changes behavior. */ - while ((fl = getopt(argc, argv, ":" OPTSTRING)) != -1) { - if (fl == 'b') + while ((fl = getopt(argc, argv, optstr[pmode])) != -1) { + switch (fl) { + case 'b': bflag = 1; + break; + case '?': + usage(); + } } optind = 1; optreset = 1; - while ((fl = getopt(argc, argv, OPTSTRING)) != -1) { + while ((fl = getopt(argc, argv, optstr[pmode])) != -1) { switch (fl) { case 'a': while ((cp = strsep(&optarg, " \t,")) != NULL) { @@ -249,7 +280,8 @@ main(int argc, char **argv) } if (hf->base64 == -1 && base64 != -1) { warnx("%s doesn't support %s", - hf->name, base64 ? "base64" : "hex"); + hf->name, + base64 ? "base64" : "hex"); usage(); } /* Check for dupes. */ @@ -649,7 +681,8 @@ digest_filelist(const char *file, struct hash_function *defhash) cmp = strcasecmp(checksum, digest); if (cmp == 0) { if (qflag == 0) - (void)printf("(%s) %s: OK\n", algorithm, filename); + (void)printf("(%s) %s: OK\n", algorithm, + filename); } else { (void)printf("(%s) %s: FAILED\n", algorithm, filename); error = 1; @@ -754,10 +787,21 @@ digest_test(struct hash_list *hl) void usage(void) { - fprintf(stderr, "usage: %s [-bpqrtx] [-c [checklist ...]] " - "[-s string] [file ...]\n", __progname); - if (strcmp(__progname, "cksum") == 0) - fprintf(stderr, " [-a algorithms]] [-o 1 | 2]\n"); + switch (pmode) { + case MODE_MD5: + case MODE_SHA1: + case MODE_RMD160: + fprintf(stderr, "usage: %s [-bpqrtx] [-c [checklist ...]] " + "[-s string] [file ...]\n", __progname); + break; + case MODE_CKSUM: + case MODE_SUM: + fprintf(stderr, "usage: %s [-bpqrtx] [-a algorithms] " + "[-c [checklist ...]] [-o 1 | 2]\n" + " %*s [-s string] [file ...]\n", + __progname, (int)strlen(__progname), ""); + break; + } exit(EXIT_FAILURE); } |