mirror of
https://github.com/opnsense/src.git
synced 2026-06-11 01:30:30 -04:00
md5: Improve compatibility with coreutils and format fix
The previous changes that added support for the coreutils -c option
modified the output generated by passing -r to match that of the
coreutils versions. The difference is that coreutils separates the
hash from the file name by two blanks " " (or a blank followed by
an asterisk " *" with the -b option denoting).
While most scripts or users will not notice the difference, it might
be considered a violation of POLA and this commit reverts the change
for the non-sum programs. These will print a single blank " " as the
separator, as they die before the previous commit.
In order to still generate output that is identical to that of the
coreutils programs, this commit generates the " " or " *" separator
used by them for the -sum versions, depending on the presence of the
-b option.
(cherry picked from commit b33d1898c1)
This commit is contained in:
parent
3a96a25da8
commit
185dcb1072
2 changed files with 25 additions and 10 deletions
|
|
@ -1,5 +1,5 @@
|
|||
.\" $FreeBSD$
|
||||
.Dd June 24, 2021
|
||||
.Dd June 29, 2021
|
||||
.Dt MD5 1
|
||||
.Os
|
||||
.Sh NAME
|
||||
|
|
@ -77,9 +77,11 @@ The hexadecimal checksum of each file listed on the command line is printed
|
|||
after the options are processed.
|
||||
.Bl -tag -width indent
|
||||
.It Fl b
|
||||
Ignored for compatibility with the coreutils
|
||||
Make the
|
||||
.Nm -sum
|
||||
programs.
|
||||
programs separate hash and digest with a blank followed by an asterisk instead
|
||||
of by 2 blank characters for full compatibility with the output generated by the
|
||||
coreutils versions of these programs.
|
||||
.It Fl c Ar string
|
||||
If the program was called with a name that does not end in
|
||||
.Nm sum ,
|
||||
|
|
@ -88,13 +90,13 @@ compare the digest of the file against this string.
|
|||
.It Fl c Ar file
|
||||
If the program was called with a name that does end in
|
||||
.Nm sum ,
|
||||
the file passed as argument must contain digest lines generated by the same digest algorithm
|
||||
with or without the
|
||||
the file passed as argument must contain digest lines generated by the same
|
||||
digest algorithm with or without the
|
||||
.Fl r
|
||||
option
|
||||
.Pq i.e. in either classical BSD format or in GNU coreutils format .
|
||||
A line with file name followed by
|
||||
.Dq :
|
||||
A line with the file name followed by a colon
|
||||
.Dq ":"
|
||||
and either OK or FAILED is written for each well-formed line in the digest file.
|
||||
If applicable, the number of failed comparisons and the number of lines that were
|
||||
skipped since they were not well-formed are printed at the end.
|
||||
|
|
@ -157,8 +159,13 @@ $ echo -n Hello | md5
|
|||
Calculate the checksum of multiple files reversing the output:
|
||||
.Bd -literal -offset indent
|
||||
$ md5 -r /boot/loader.conf /etc/rc.conf
|
||||
ada5f60f23af88ff95b8091d6d67bef6 /boot/loader.conf
|
||||
d80bf36c332dc0fdc479366ec3fa44cd /etc/rc.conf
|
||||
ada5f60f23af88ff95b8091d6d67bef6 /boot/loader.conf
|
||||
d80bf36c332dc0fdc479366ec3fa44cd /etc/rc.conf
|
||||
.Pd
|
||||
The
|
||||
.Nm -sum
|
||||
variants put 2 blank characters between hash and file name for full compatibilty
|
||||
with the coreutils versions of these commands.
|
||||
.Ed
|
||||
.Pp
|
||||
Write the digest for
|
||||
|
|
|
|||
|
|
@ -54,6 +54,7 @@ __FBSDID("$FreeBSD$");
|
|||
#define TEST_BLOCK_COUNT 100000
|
||||
#define MDTESTCOUNT 8
|
||||
|
||||
static int bflag;
|
||||
static int cflag;
|
||||
static int pflag;
|
||||
static int qflag;
|
||||
|
|
@ -301,6 +302,7 @@ main(int argc, char *argv[])
|
|||
while ((ch = getopt(argc, argv, "bc:pqrs:tx")) != -1)
|
||||
switch (ch) {
|
||||
case 'b':
|
||||
bflag = 1;
|
||||
break;
|
||||
case 'c':
|
||||
cflag = 1;
|
||||
|
|
@ -436,7 +438,13 @@ MDOutput(const Algorithm_t *alg, char *p, char *argv[])
|
|||
printf("%s\n", p);
|
||||
} else {
|
||||
if (rflag)
|
||||
printf("%s %s", p, *argv);
|
||||
if (gnu_emu)
|
||||
if (bflag)
|
||||
printf("%s *%s", p, *argv);
|
||||
else
|
||||
printf("%s %s", p, *argv);
|
||||
else
|
||||
printf("%s %s", p, *argv);
|
||||
else
|
||||
printf("%s (%s) = %s", alg->name, *argv, p);
|
||||
if (checkAgainst) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue