[hackers] [sbase] Support reading checksums from stdin || Daniel Bainton
commit c323f6f2331512003bd53a7da18e1250c2cb5c9c
Author: Daniel Bainton <dpb_AT_driftaway.org>
Date: Mon May 5 11:11:37 2014 +0300
Support reading checksums from stdin
diff --git a/md5sum.c b/md5sum.c
index 19babd6..b1d90a6 100644
--- a/md5sum.c
+++ b/md5sum.c
_AT_@ -1,4 +1,5 @@
/* See LICENSE file for copyright and license details. */
+#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
_AT_@ -25,16 +26,18 @@ main(int argc, char *argv[])
{
uint8_t md[MD5_DIGEST_LENGTH];
char *checkfile = NULL;
+ bool cflag = false;
ARGBEGIN {
case 'c':
- checkfile = EARGF(usage());
+ cflag = true;
+ checkfile = ARGF();
break;
default:
usage();
} ARGEND;
- if(checkfile)
+ if(cflag)
return cryptcheck(checkfile, argc, argv, &md5_ops, md, sizeof(md));
return cryptmain(argc, argv, &md5_ops, md, sizeof(md));
}
diff --git a/sha1sum.c b/sha1sum.c
index 68fec73..b497f10 100644
--- a/sha1sum.c
+++ b/sha1sum.c
_AT_@ -1,4 +1,5 @@
/* See LICENSE file for copyright and license details. */
+#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
_AT_@ -25,16 +26,18 @@ main(int argc, char *argv[])
{
uint8_t md[SHA1_DIGEST_LENGTH];
char *checkfile = NULL;
+ bool cflag = false;
ARGBEGIN {
case 'c':
- checkfile = EARGF(usage());
+ cflag = true;
+ checkfile = ARGF();
break;
default:
usage();
} ARGEND;
- if(checkfile)
+ if(cflag)
return cryptcheck(checkfile, argc, argv, &sha1_ops, md, sizeof(md));
return cryptmain(argc, argv, &sha1_ops, md, sizeof(md));
}
diff --git a/sha256sum.c b/sha256sum.c
index 673ab47..d8fefad 100644
--- a/sha256sum.c
+++ b/sha256sum.c
_AT_@ -1,4 +1,5 @@
/* See LICENSE file for copyright and license details. */
+#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
_AT_@ -25,16 +26,18 @@ main(int argc, char *argv[])
{
uint8_t md[SHA256_DIGEST_LENGTH];
char *checkfile = NULL;
+ bool cflag = false;
ARGBEGIN {
case 'c':
- checkfile = EARGF(usage());
+ cflag = true;
+ checkfile = ARGF();
break;
default:
usage();
} ARGEND;
- if(checkfile)
+ if(cflag)
return cryptcheck(checkfile, argc, argv, &sha256_ops, md, sizeof(md));
return cryptmain(argc, argv, &sha256_ops, md, sizeof(md));
}
diff --git a/sha512sum.c b/sha512sum.c
index d7ee473..896515a 100644
--- a/sha512sum.c
+++ b/sha512sum.c
_AT_@ -1,4 +1,5 @@
/* See LICENSE file for copyright and license details. */
+#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
_AT_@ -25,16 +26,18 @@ main(int argc, char *argv[])
{
uint8_t md[SHA512_DIGEST_LENGTH];
char *checkfile = NULL;
+ bool cflag = false;
ARGBEGIN {
case 'c':
- checkfile = EARGF(usage());
+ cflag = true;
+ checkfile = ARGF();
break;
default:
usage();
} ARGEND;
- if(checkfile)
+ if(cflag)
return cryptcheck(checkfile, argc, argv, &sha512_ops, md, sizeof(md));
return cryptmain(argc, argv, &sha512_ops, md, sizeof(md));
}
diff --git a/util/crypt.c b/util/crypt.c
index fffdd55..589104b 100644
--- a/util/crypt.c
+++ b/util/crypt.c
_AT_@ -45,7 +45,9 @@ cryptcheck(char *sumfile, int argc, char *argv[],
int r, nonmatch = 0, formatsucks = 0, noread = 0, ret = EXIT_SUCCESS;
size_t bufsiz = 0;
- if(!(cfp = fopen(sumfile, "r")))
+ if(sumfile == NULL)
+ cfp = stdin;
+ else if(!(cfp = fopen(sumfile, "r")))
eprintf("fopen %s:", sumfile);
while(afgets(&line, &bufsiz, cfp)) {
_AT_@ -78,7 +80,8 @@ cryptcheck(char *sumfile, int argc, char *argv[],
}
fclose(fp);
}
- fclose(cfp);
+ if(sumfile != NULL)
+ fclose(cfp);
free(line);
if(formatsucks > 0) {
weprintf("%d lines are improperly formatted
", formatsucks);
Received on Mon May 05 2014 - 11:05:52 CEST
This archive was generated by hypermail 2.3.0
: Mon May 05 2014 - 11:12:12 CEST