[Bug 217571] [Feature suggestion] make md5 print the checksum to stderr

bugzilla-noreply at freebsd.org bugzilla-noreply at freebsd.org
Sun Mar 5 22:43:38 UTC 2017


https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=217571

            Bug ID: 217571
           Summary: [Feature suggestion] make md5 print the checksum to
                    stderr
           Product: Base System
           Version: 11.0-STABLE
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Some People
          Priority: ---
         Component: bin
          Assignee: freebsd-bugs at FreeBSD.org
          Reporter: manon at manon.de

Hi, 

the following patch patch adds  option -P to md5/sha[1/256..] to print the
digest to stderr when operating in filter mode. this is usefull when  printing
the digest while redirecting stdout. eg: sha512 -P < tarfile | tar -xf- -C
/test/dir 

hope this makes sense.

Kind regards,
Manon

diff -ur /usr/src/sbin/md5/md5.1 ./md5.1
--- /usr/src/sbin/md5/md5.1     2016-10-15 22:19:31.346635000 +0200
+++ ./md5.1     2017-03-05 23:05:31.938946000 +0100
@@ -7,37 +7,37 @@
 .Nd calculate a message-digest fingerprint (checksum) for a file
 .Sh SYNOPSIS
 .Nm md5
-.Op Fl pqrtx
+.Op Fl Ppqrtx
 .Op Fl c Ar string
 .Op Fl s Ar string
 .Op Ar
 .Nm sha1
-.Op Fl pqrtx
+.Op Fl Ppqrtx
 .Op Fl c Ar string
 .Op Fl s Ar string
 .Op Ar
 .Nm sha256
-.Op Fl pqrtx
+.Op Fl Ppqrtx
 .Op Fl c Ar string
 .Op Fl s Ar string
 .Op Ar
 .Nm sha384
-.Op Fl pqrtx
+.Op Fl Ppqrtx
 .Op Fl c Ar string
 .Op Fl s Ar string
 .Op Ar
 .Nm sha512
-.Op Fl pqrtx
+.Op Fl Ppqrtx
 .Op Fl c Ar string
 .Op Fl s Ar string
 .Op Ar
 .Nm sha512t256
-.Op Fl pqrtx
+.Op Fl Ppqrtx
 .Op Fl c Ar string
 .Op Fl s Ar string
 .Op Ar
 .Nm rmd160
-.Op Fl pqrtx
+.Op Fl Ppqrtx
 .Op Fl c Ar string
 .Op Fl s Ar string
 .Op Ar
@@ -109,6 +109,8 @@
 .Ar string .
 .It Fl p
 Echo stdin to stdout and append the checksum to stdout.
+.It Fl P
+Echo stdin to stdout and write the checksum to stderr.
 .It Fl q
 Quiet mode \(em only the checksum is printed out.
 Overrides the
diff -ur /usr/src/sbin/md5/md5.c ./md5.c
--- /usr/src/sbin/md5/md5.c     2016-10-15 22:19:31.349312000 +0200
+++ ./md5.c     2017-03-05 23:07:54.742808000 +0100
@@ -176,7 +176,7 @@
        failed = 0;
        checkAgainst = NULL;
        checksFailed = 0;
-       while ((ch = getopt(argc, argv, "c:pqrs:tx")) != -1)
+       while ((ch = getopt(argc, argv, "c:Ppqrs:tx")) != -1)
                switch (ch) {
                case 'c':
                        checkAgainst = optarg;
@@ -184,6 +184,9 @@
                case 'p':
                        MDFilter(&Algorithm[digest], 1);
                        break;
+               case 'P':
+                       MDFilter(&Algorithm[digest], 2);
+                       break;
                case 'q':
                        qflag = 1;
                        break;
@@ -456,6 +459,7 @@
 {
        DIGEST_CTX context;
        unsigned int len;
+       FILE *filehandle;
        unsigned char buffer[BUFSIZ];
        char buf[HEX_DIGEST_LENGTH];

@@ -465,13 +469,17 @@
                        err(1, "stdout");
                alg->Update(&context, buffer, len);
        }
-       printf("%s\n", alg->End(&context, buf));
+       
+       filehandle = stdin;
+       if (tee > 1) 
+               filehandle = stderr;
+       fprintf(filehandle, "%s\n", alg->End(&context, buf));
 }

 static void
 usage(const Algorithm_t *alg)
 {

-       fprintf(stderr, "usage: %s [-pqrtx] [-c string] [-s string] [files
...]\n", alg->progname);
+       fprintf(stderr, "usage: %s [-Ppqrtx] [-c string] [-s string] [files
...]\n", alg->progname);
        exit(1);
 }

-- 
You are receiving this mail because:
You are the assignee for the bug.


More information about the freebsd-bugs mailing list