NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

misc/39658: improve options management in cksum, sum, md2, md4, md5, sha and rmd160



>Number:         39658
>Category:       misc
>Synopsis:       improve options management in cksum, sum, md2, md4, md5, sha 
>and rmd160
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    misc-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Sep 30 11:25:00 +0000 2008
>Originator:     Igor Sobrado
>Release:        NetBSD 3.1
>Organization:
University of Oviedo
>Environment:
NetBSD wwwdos.geol.uniovi.es 3.1 NetBSD 3.1 (GENERIC) #0: Tue Oct 31 04:27:07 
UTC 2006  
builds%b0.netbsd.org@localhost:/home/builds/ab/netbsd-3-1-RELEASE/i386/200610302053Z-obj/home/builds/ab/netbsd-3-1-RELEASE/src/sys/arch/i386/compile/GENERIC
 i386
>Description:
this diff improves options management in the checksum utilities:

- the sum utility is identical to the cksum utility, but it
  defaults to algorithm 1;
- there are some options that are available on a subset of
  the checksum utilities only;
- each checksum utility must have its own usage.
>How-To-Repeat:
there are options that should not be available in some checksum utilities 
(e.g., "-p" on cksum(1) and sum(1)); all the checksum utilities share the same 
set of options.
>Fix:
--- cksum/cksum.1       2006-09-03 01:27:45.000000000 +0200
+++ cksum/cksum.1       2008-09-30 12:26:13.000000000 +0200
@@ -54,8 +54,12 @@
 .Oc
 .Op Ar
 .Nm sum
-.Op Fl w
-.Op Fl c Op Ar file
+.Op Fl nw
+.Oo
+.Fl a Ar algorithm |
+.Fl c Oo Ar file Oc |
+.Op Fl o Ar 1 | Ar 2
+.Oc
 .Op Ar
 .Nm md2
 .Op Fl nw

--- cksum/cksum.c       2008-07-21 16:19:21.000000000 +0200
+++ cksum/cksum.c       2008-09-30 13:15:22.000000000 +0200
@@ -110,6 +110,16 @@
 #define HASH_SHA1      3
 #define HASH_RMD160    4
 
+enum program_mode {
+       MODE_CKSUM,
+       MODE_SUM,
+       MODE_MD2,
+       MODE_MD4,
+       MODE_MD5,
+       MODE_SHA1,
+       MODE_RMD160
+} pmode;
+
 typedef char *(*_filefunc)(const char *, char *);
 
 struct hash {
@@ -176,6 +186,32 @@
 
        progname = getprogname();
 
+       static const char *optstr[7] = {
+               "a:cno:w",
+               "a:cno:w",
+               "cnps:twx",
+               "cnps:twx",
+               "cnps:twx",
+               "cnps:twx",
+               "cnps:twx"
+       };
+
+       pmode = MODE_CKSUM;
+       if (strcmp(progname, "cksum") == 0)
+               pmode = MODE_CKSUM;
+       else if (strcmp(progname, "sum") == 0)
+               pmode = MODE_SUM;
+       else if (strcmp(progname, "md2") == 0)
+               pmode = MODE_MD2;
+       else if (strcmp(progname, "md4") == 0)
+               pmode = MODE_MD4;
+       else 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;
+
        for (hash = hashes; hash->hashname != NULL; hash++)
                if (strcmp(progname, hash->progname) == 0)
                        break;
@@ -193,7 +229,7 @@
                }
        }
 
-       while ((ch = getopt(argc, argv, "a:cno:ps:twx")) != -1)
+       while ((ch = getopt(argc, argv, optstr[pmode])) != -1)
                switch(ch) {
                case 'a':
                        if (hash != NULL || dosum) {
@@ -533,18 +569,22 @@
 void
 usage(void)
 {
-
-       (void)fprintf(stderr, "usage: cksum [-nw] [-a algorithm | -c file 
]\n\t\t| [-o 1 | 2]] [file ...]\n");
-       (void)fprintf(stderr, "       sum [-c] [file ...]\n");
-       (void)fprintf(stderr,
-           "       md2 [-n] [-p | -t | -x | -s string] [file ...]\n");
-       (void)fprintf(stderr,
-           "       md4 [-n] [-p | -t | -x | -s string] [file ...]\n");
-       (void)fprintf(stderr,
-           "       md5 [-n] [-p | -t | -x | -s string] [file ...]\n");
-       (void)fprintf(stderr,
-           "       sha1 [-n] [-p | -t | -x | -s string] [file ...]\n");
-       (void)fprintf(stderr,
-           "       rmd160 [-n] [-p | -t | -x | -s string] [file ...]\n");
+       switch (pmode) {
+       case MODE_CKSUM:
+       case MODE_SUM:
+       (void)fprintf(stderr, "usage: "
+           "%s [-nw] [-a algorithm | -c [file] | [-o 1 | 2]] [file ...]\n",
+           getprogname());
+       break;
+       case MODE_MD2:
+       case MODE_MD4:
+       case MODE_MD5:
+       case MODE_SHA1:
+       case MODE_RMD160:
+       (void)fprintf(stderr, "usage: "
+           "%s [-nw] [-c [file] | -p | -t | -x | -s string] [file ...]\n",
+           getprogname());
+       break;
+       }
        exit(1);
 }



Home | Main Index | Thread Index | Old Index