FreeBSD Bugzilla – Attachment 126537 Details for
Bug 170278
[patch] [request] Add --check option to md5(1)
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
patch.txt
patch.txt (text/plain; charset=US-ASCII), 4.98 KB, created by
apyhalov
on 2012-08-30 21:55:21 UTC
(
hide
)
Description:
patch.txt
Filename:
MIME Type:
Creator:
apyhalov
Created:
2012-08-30 21:55:21 UTC
Size:
4.98 KB
patch
obsolete
>--- /usr/src/sbin/md5/md5.c 2012-06-06 21:42:10.901208101 +0400 >+++ md5.c 2012-08-31 00:49:19.423799998 +0400 >@@ -20,10 +20,12 @@ > #include <sys/cdefs.h> > __FBSDID("$FreeBSD$"); > >+#include <sys/param.h> > #include <sys/types.h> > #include <sys/time.h> > #include <sys/resource.h> > #include <err.h> >+#include <getopt.h> > #include <md5.h> > #include <ripemd.h> > #include <sha.h> >@@ -41,6 +43,7 @@ > #define TEST_BLOCK_COUNT 100000 > #define MDTESTCOUNT 8 > >+int fflag; > int qflag; > int rflag; > int sflag; >@@ -73,6 +76,7 @@ > static void MDTestSuite(Algorithm_t *); > static void MDFilter(Algorithm_t *, int); > static void usage(Algorithm_t *); >+static void ProcessCheckAgainstFile(char *filename, int *failed, int digest); > > typedef union { > MD5_CTX md5; >@@ -85,6 +89,10 @@ > SHA256_DIGEST_LENGTH, RIPEMD160_DIGEST_LENGTH)*2+1 */ > #define HEX_DIGEST_LENGTH 65 > >+/* maximum length of string in controlsum file - digest plus file path >+ plus some dilimiters */ >+#define MAX_STRING_LENGTH (HEX_DIGEST_LENGTH+MAXPATHLEN+64) >+ > /* algorithm function table */ > > struct Algorithm_t Algorithm[] = { >@@ -126,6 +134,9 @@ > int failed; > unsigned digest; > const char* progname; >+ struct option longopts[] = { >+ { "check",no_argument,NULL,'f'} >+ }; > > if ((progname = strrchr(argv[0], '/')) == NULL) > progname = argv[0]; >@@ -142,11 +153,14 @@ > failed = 0; > checkAgainst = NULL; > checksFailed = 0; >- while ((ch = getopt(argc, argv, "c:pqrs:tx")) != -1) >+ while ((ch = getopt_long(argc, argv, "c:pfqrs:tx",longopts,NULL)) != -1) > switch (ch) { > case 'c': > checkAgainst = optarg; > break; >+ case 'f': >+ fflag = 1; >+ break; > case 'p': > MDFilter(&Algorithm[digest], 1); > break; >@@ -174,29 +188,35 @@ > > if (*argv) { > do { >- p = Algorithm[digest].File(*argv, buf); >- if (!p) { >- warn("%s", *argv); >- failed++; >+ if (fflag){ >+ ProcessCheckAgainstFile(*argv,&failed,digest); > } else { >- if (qflag) >- printf("%s", p); >- else if (rflag) >- printf("%s %s", p, *argv); >- else >- printf("%s (%s) = %s", >- Algorithm[digest].name, *argv, p); >- if (checkAgainst && strcmp(checkAgainst,p)) >- { >- checksFailed++; >- if (!qflag) >- printf(" [ Failed ]"); >+ p = Algorithm[digest].File(*argv, buf); >+ if (!p) { >+ warn("%s", *argv); >+ failed++; >+ } else { >+ if (qflag) >+ printf("%s", p); >+ else if (rflag) >+ printf("%s %s", p, *argv); >+ else >+ printf("%s (%s) = %s", >+ Algorithm[digest].name, *argv, p); >+ if (checkAgainst && strcmp(checkAgainst,p)) >+ { >+ checksFailed++; >+ if (!qflag) >+ printf(" [ Failed ]"); >+ } >+ printf("\n"); > } >- printf("\n"); > } > } while (*++argv); >- } else if (!sflag && (optind == 1 || qflag || rflag)) >+ } else if (!fflag && !sflag && (optind == 1 || qflag || rflag)) > MDFilter(&Algorithm[digest], 0); >+ else if (fflag) >+ ProcessCheckAgainstFile(NULL,&failed,digest); > > if (failed != 0) > return (1); >@@ -205,6 +225,75 @@ > > return (0); > } >+ >+/* >+ * Reads a file with control sums and filenames and checks them >+ */ >+static void >+ProcessCheckAgainstFile(char *filename, int *failed, int digest){ >+ char buf[HEX_DIGEST_LENGTH]; >+ char checkAgainstCur[HEX_DIGEST_LENGTH]; >+ char strar[MAX_STRING_LENGTH+1]; >+ char *str; >+ char curfname[MAXPATHLEN+1]; >+ char *p; >+ FILE *fl; >+ int first,len; >+ >+ if(filename) >+ fl=fopen(filename,"r"); >+ else { >+ fl=stdin; >+ } >+ if(fl){ >+ str=&strar[0]; >+ bzero(str,MAX_STRING_LENGTH); >+ while(fgets(str,MAX_STRING_LENGTH,fl)){ >+ while((*str==' '|| *str=='\t')&& *str!='\0') >+ str++; >+ first=strcspn(str,"\t "); >+ if(first && first<HEX_DIGEST_LENGTH){ >+ strncpy(checkAgainstCur,str,first); >+ checkAgainstCur[first]='\0'; >+ >+ str=&(str[first]); >+ while((*str==' '|| *str=='\t')&&*str!='\0') >+ str++; >+ len=strlen(str); >+ if(len>MAXPATHLEN) >+ len=MAXPATHLEN; >+ strncpy(curfname,str,len); >+ curfname[len-1]='\0'; >+ p = Algorithm[digest].File(curfname, buf); >+ if (!p) { >+ warn("%s", curfname); >+ failed++; >+ } else { >+ if (qflag) >+ printf("%s", p); >+ else if (rflag) >+ printf("%s %s", p, curfname); >+ else >+ printf("%s (%s) = %s", >+ Algorithm[digest].name, curfname, p); >+ if (strcmp(checkAgainstCur,p)) { >+ checksFailed++; >+ if (!qflag) >+ printf(" [ Failed ]"); >+ } >+ putchar('\n'); >+ } >+ } else { >+ (*failed)++; >+ } >+ bzero(str,MAX_STRING_LENGTH); >+ } >+ fclose(fl); >+ } else { >+ (*failed)++; >+ } >+} >+ > /* > * Digests a string and prints the result. > */
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 170278
: 126537 |
126538