From: deraadt Date: Wed, 8 Jan 2014 14:15:54 +0000 (+0000) Subject: Add support for -h hashfile. This is very useful with with -p, in a pipeline, X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=043177f7e23b1016b546b44053e0728b160dc3be;p=openbsd Add support for -h hashfile. This is very useful with with -p, in a pipeline, to deliver the hash output to a different location. ok millert --- diff --git a/bin/md5/cksum.1 b/bin/md5/cksum.1 index 085af5f26eb..b6993761de3 100644 --- a/bin/md5/cksum.1 +++ b/bin/md5/cksum.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: cksum.1,v 1.25 2013/12/29 21:19:11 jmc Exp $ +.\" $OpenBSD: cksum.1,v 1.26 2014/01/08 14:15:54 deraadt 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: December 29 2013 $ +.Dd $Mdocdate: January 8 2014 $ .Dt CKSUM 1 .Os .Sh NAME @@ -46,6 +46,7 @@ .Op Fl a Ar algorithms .Op Fl c Op Ar checklist ... .Op Fl o Ar 1 | 2 +.Op Fl h Ar hashfile .Op Fl s Ar string .Op Ar .Ek @@ -54,6 +55,7 @@ .Op Fl a Ar algorithms .Op Fl c Op Ar checklist ... .Op Fl o Ar 1 | 2 +.Op Fl h Ar hashfile .Op Fl s Ar string .Op Ar .Sh DESCRIPTION @@ -176,6 +178,10 @@ flag, only print the failed cases. .It Fl r Reverse the format of the hash algorithm output, making it match the checksum output format. +.It Fl h Ar hashfile +Place the checksum into +.Ar hashfile +instead of stdout. .It Fl s Ar string Prints a checksum of the given .Ar string . diff --git a/bin/md5/md5.1 b/bin/md5/md5.1 index a0596d009b8..199439a7ba3 100644 --- a/bin/md5/md5.1 +++ b/bin/md5/md5.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: md5.1,v 1.34 2013/12/29 21:19:11 jmc Exp $ +.\" $OpenBSD: md5.1,v 1.35 2014/01/08 14:15:54 deraadt Exp $ .\" .\" Copyright (c) 2003, 2004, 2006 Todd C. Miller .\" @@ -18,7 +18,7 @@ .\" Agency (DARPA) and Air Force Research Laboratory, Air Force .\" Materiel Command, USAF, under agreement number F39502-99-1-0512. .\" -.Dd $Mdocdate: December 29 2013 $ +.Dd $Mdocdate: January 8 2014 $ .Dt MD5 1 .Os .Sh NAME @@ -28,6 +28,7 @@ .Nm md5 .Op Fl bpqrtx .Op Fl c Op Ar checklist ... +.Op Fl h Ar hashfile .Op Fl s Ar string .Op Ar .Sh DESCRIPTION @@ -69,6 +70,10 @@ Only print the checksum (quiet mode). Reverse the format of the hash algorithm output, making it match the output format used by .Xr cksum 1 . +.It Fl h Ar hashfile +Place the checksum into +.Ar hashfile +instead of stdout. .It Fl s Ar string Prints a checksum of the given .Ar string . diff --git a/bin/md5/md5.c b/bin/md5/md5.c index 56228e37ede..bf5a7e7af92 100644 --- a/bin/md5/md5.c +++ b/bin/md5/md5.c @@ -1,4 +1,4 @@ -/* $OpenBSD: md5.c,v 1.58 2013/12/23 23:00:38 tedu Exp $ */ +/* $OpenBSD: md5.c,v 1.59 2014/01/08 14:15:54 deraadt Exp $ */ /* * Copyright (c) 2001,2003,2005-2006 Todd C. Miller @@ -213,6 +213,7 @@ void usage(void) __attribute__((__noreturn__)); extern char *__progname; int qflag = 0; +FILE *ofile = NULL; int main(int argc, char **argv) @@ -225,8 +226,8 @@ main(int argc, char **argv) int bflag, cflag, pflag, rflag, tflag, xflag; static const char *optstr[2] = { - "bcpqrs:tx", - "a:bco:pqrs:tx" + "bch:pqrs:tx", + "a:bch:o:pqrs:tx" }; TAILQ_INIT(&hl); @@ -315,6 +316,11 @@ main(int argc, char **argv) if (hftmp == TAILQ_END(&hl)) hash_insert(&hl, hf, 0); break; + case 'h': + ofile = fopen(optarg, "w+"); + if (ofile == NULL) + errx(1, "%s", optarg); + break; case 'p': pflag = 1; break; @@ -340,6 +346,9 @@ main(int argc, char **argv) argc -= optind; argv += optind; + if (ofile == NULL) + ofile = stdout; + /* Most arguments are mutually exclusive */ fl = pflag + (tflag ? 1 : 0) + xflag + cflag + (input_string != NULL); if (fl > 1 || (fl && argc && cflag == 0) || (rflag && qflag)) @@ -444,13 +453,13 @@ digest_print(const struct hash_function *hf, const char *what, { switch (*hf->style) { case STYLE_NORMAL: - (void)printf("%s (%s) = %s\n", hf->name, what, digest); + (void)fprintf(ofile, "%s (%s) = %s\n", hf->name, what, digest); break; case STYLE_REVERSE: - (void)printf("%s %s\n", digest, what); + (void)fprintf(ofile, "%s %s\n", digest, what); break; case STYLE_TERSE: - (void)printf("%s\n", digest); + (void)fprintf(ofile,"%s\n", digest); break; } } @@ -461,13 +470,13 @@ digest_printstr(const struct hash_function *hf, const char *what, { switch (*hf->style) { case STYLE_NORMAL: - (void)printf("%s (\"%s\") = %s\n", hf->name, what, digest); + (void)fprintf(ofile, "%s (\"%s\") = %s\n", hf->name, what, digest); break; case STYLE_REVERSE: - (void)printf("%s %s\n", digest, what); + (void)fprintf(ofile, "%s %s\n", digest, what); break; case STYLE_TERSE: - (void)printf("%s\n", digest); + (void)fprintf(ofile, "%s\n", digest); break; } } @@ -515,7 +524,7 @@ digest_file(const char *file, struct hash_list *hl, int echo) free(hf->ctx); hf->ctx = NULL; if (fp == stdin) - (void)puts(digest); + fprintf(ofile, "%s\n", digest); else digest_print(hf, file, digest); } @@ -789,11 +798,11 @@ usage(void) switch (pmode) { case MODE_MD5: fprintf(stderr, "usage: %s [-bpqrtx] [-c [checklist ...]] " - "[-s string] [file ...]\n", __progname); + "[-h hashfile] [-s string] [file ...]\n", __progname); break; case MODE_CKSUM: fprintf(stderr, "usage: %s [-bpqrtx] [-a algorithms] " - "[-c [checklist ...]] [-o 1 | 2]\n" + "[-c [checklist ...]] [-h hashfile] [-o 1 | 2]\n" " %*s [-s string] [file ...]\n", __progname, (int)strlen(__progname), ""); break; diff --git a/bin/md5/sha1.1 b/bin/md5/sha1.1 index d2d4fd0a7c4..1b2ea80a861 100644 --- a/bin/md5/sha1.1 +++ b/bin/md5/sha1.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: sha1.1,v 1.32 2013/12/29 21:19:11 jmc Exp $ +.\" $OpenBSD: sha1.1,v 1.33 2014/01/08 14:15:54 deraadt Exp $ .\" .\" Copyright (c) 2003, 2004, 2006 Todd C. Miller .\" @@ -18,7 +18,7 @@ .\" Agency (DARPA) and Air Force Research Laboratory, Air Force .\" Materiel Command, USAF, under agreement number F39502-99-1-0512. .\" -.Dd $Mdocdate: December 29 2013 $ +.Dd $Mdocdate: January 8 2014 $ .Dt SHA1 1 .Os .Sh NAME @@ -28,6 +28,7 @@ .Nm sha1 .Op Fl bpqrtx .Op Fl c Op Ar checklist ... +.Op Fl h Ar hashfile .Op Fl s Ar string .Op Ar .Sh DESCRIPTION @@ -70,6 +71,10 @@ Only print the checksum (quiet mode). Reverse the format of the hash algorithm output, making it match the output format used by .Xr cksum 1 . +.It Fl h Ar hashfile +Place the checksum into +.Ar hashfile +instead of stdout. .It Fl s Ar string Prints a checksum of the given .Ar string . diff --git a/bin/md5/sha256.1 b/bin/md5/sha256.1 index 8a8549e0e8f..9701aa9159c 100644 --- a/bin/md5/sha256.1 +++ b/bin/md5/sha256.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: sha256.1,v 1.7 2013/12/29 21:19:11 jmc Exp $ +.\" $OpenBSD: sha256.1,v 1.8 2014/01/08 14:15:54 deraadt Exp $ .\" .\" Copyright (c) 2003, 2004, 2006 Todd C. Miller .\" @@ -18,7 +18,7 @@ .\" Agency (DARPA) and Air Force Research Laboratory, Air Force .\" Materiel Command, USAF, under agreement number F39502-99-1-0512. .\" -.Dd $Mdocdate: December 29 2013 $ +.Dd $Mdocdate: January 8 2014 $ .Dt SHA256 1 .Os .Sh NAME @@ -29,11 +29,13 @@ .Nm sha256 .Op Fl bpqrtx .Op Fl c Op Ar checklist ... +.Op Fl h Ar hashfile .Op Fl s Ar string .Op Ar .Nm sha512 .Op Fl bpqrtx .Op Fl c Op Ar checklist ... +.Op Fl h Ar hashfile .Op Fl s Ar string .Op Ar .Sh DESCRIPTION @@ -75,6 +77,10 @@ Only print the checksum (quiet mode). Reverse the format of the hash algorithm output, making it match the output format used by .Xr cksum 1 . +.It Fl h Ar hashfile +Place the checksum into +.Ar hashfile +instead of stdout. .It Fl s Ar string Prints a checksum of the given .Ar string .