Hi!

----

Attached (as "astksh20130913_md5sum_compat1.diff.txt") is a patch
which fixes an incompatibility between AST md5sum(1)&&co. and GNU
coreutils md5sum(1)&&co. fixes.

There are three major differences which caused hiccups for 3rd-party scripts:
- GNU coreutils md5sum/sha1sum/sha224sum/sha256sum default to text mode
- GNU coreutils use a " *" before the file name to indicate binary
mode and "  " to indicate text mode... the AST hash utilities used
only a single blank " " instead.
- "-t" means "text mode" for GNU coreutils while AST used this for "total"

* Notes:
- GNU and AST *sum(1) utilities now have identical output and seem to
be 100% compatible with each other
- On platforms which do not implement |O_BINARY| and |O_TEXT| the
change only affects the seperator ("  "/" *"(=new) vs. " "(=old)).
Portable applications can use [[:space:]]+ in egrep(1) to make sure
they can match the hashes against both the old and new versions of AST
*sum(1)
- The output *intentionally* changes only for utilities matching the
shell pattern "*@(md5|sha@(1|224|256|384|512))sum". This is done to
maintain compatibility for cksum(1) and sum(1)
- AST does not have a sha224sum(1) utility (yet) ... need to talk to
Glenn about this

----

Bye,
Roland

-- 
  __ .  . __
 (o.\ \/ /.o) [email protected]
  \__\/\/__/  MPEG specialist, C&&JAVA&&Sun&&Unix programmer
  /O /==\ O\  TEL +49 641 3992797
 (;O/ \/ \O;)
diff -r -u original/src/lib/libcmd/cksum.c 
build_md5sumfix/src/lib/libcmd/cksum.c
--- src/lib/libcmd/cksum.c      2012-04-20 08:06:55.000000000 +0200
+++ src/lib/libcmd/cksum.c      2013-09-24 23:20:16.311386131 +0200
@@ -26,8 +26,10 @@
  * sum -- list file checksum and size
  */
 
+#define MD5SUMLIKEPATTERN "*@(md5|sha@(1|224|256|384|512))sum"
+
 static const char usage[] =
-"[-?\n@(#)$Id: sum (AT&T Research) 2012-04-20 $\n]"
+"[-?\n@(#)$Id: sum (AT&T Research) 2013-09-23 $\n]"
 USAGE_LICENSE
 "[+NAME?cksum,md5sum,sum - print file checksum and block count]"
 "[+DESCRIPTION?\bsum\b lists the checksum, and for most methods the block"
@@ -49,7 +51,9 @@
 
 "[a:all?List the checksum for all files. Use with \b--total\b to list both"
 "      individual and total checksums and block counts.]"
-"[b:binary?Read files in binary mode. This is the default.]"
+"[b:binary?Read files in binary mode. This is the default for all utilities "
+       "whose name does not match " MD5SUMLIKEPATTERN ". See "
+       "option \b--text\b.]"
 "[B:scale?Block count scale (bytes per block) override for methods that"
 "      include size in the output.  The default is method specific.]#[scale]"
 "[c:check?Each \afile\a is interpreted as the output from a previous \bsum\b."
@@ -80,12 +84,14 @@
 "[S:silent|status?No output for \b--check\b; 0 exit status means all sums"
 "      matched, non-0 means at least one sum failed to match. Ignored for"
 "      \b--permissions\b.]"
-"[t:total?List only the total checksum and block count of all files."
+"[T:total?List only the total checksum and block count of all files."
 "      \b--all\b \b--total\b lists each checksum and the total. The"
 "      total checksum and block count may be different from the checksum"
 "      and block count of the catenation of all files due to partial"
 "      blocks that may occur when the files are treated separately.]"
-"[T:text?Read files in text mode (i.e., treat \b\\r\\n\b as \b\\n\b).]"
+"[t:text?Read files in text mode (i.e., treat \b\\r\\n\b as \b\\n\b). "
+       "This is the default for all utilities whose name matches "
+       MD5SUMLIKEPATTERN ".]"
 "[w!:warn?Warn about invalid \b--check\b lines.]"
 "[x:method|algorithm?Specifies the checksum \amethod\a to"
 "      apply. Parenthesized method options are readonly implementation"
@@ -118,7 +124,7 @@
 
 typedef struct State_s                 /* program state                */
 {
-       int             all;            /* list all items               */
+       bool            all;            /* list all items               */
        Sfio_t*         check;          /* check previous output        */
        int             flags;          /* sumprint() SUM_* flags       */
        gid_t           gid;            /* caller gid                   */
@@ -133,10 +139,11 @@
        int             silent;         /* silent check, 0 exit if ok   */
        int             (*sort)(FTSENT* const*, FTSENT* const*);
        Sum_t*          sum;            /* sum method                   */
-       int             text;           /* \r\n == \n                   */
-       int             total;          /* list totals only             */
+       bool            text;           /* \r\n == \n                   */
+       bool            total;          /* list totals only             */
        uid_t           uid;            /* caller uid                   */
        int             warn;           /* invalid check line warnings  */
+       bool            md5sumlike;     /* md5sum-like output           */
 } State_t;
 
 static void    verify(State_t*, char*, char*, Sfio_t*);
@@ -244,9 +251,18 @@
                                                (st->st_gid != state->gid && 
((st->st_mode & S_ISGID) || (st->st_mode & S_IRGRP) && !(st->st_mode & S_IROTH) 
|| (st->st_mode & S_IXGRP) && !(st->st_mode & S_IXOTH))) ? fmtgid(st->st_gid) : 
"-");
                        }
                        if (ip != sfstdin)
-                               sfprintf(op, " %s", file);
+                       {
+                               if (state->md5sumlike)
+                                       sfprintf(op, " %c%s", (state->text?' 
':'*'), file);
+                               else
+                                       sfprintf(op, " %s", file);
+                       }
+else
+       sfprintf(op, "#{stdin}");
                        sfputc(op, '\n');
                }
+else
+       sfprintf(op, "#{noperm}\n");
        }
 }
 
@@ -447,7 +463,7 @@
        Sfio_t*         sp;
        FTS*            fts;
        FTSENT*         ent;
-       int             logical;
+       bool            logical;
        Optdisc_t       optdisc;
        State_t         state;
 
@@ -456,7 +472,9 @@
        flags = fts_flags() | FTS_META | FTS_TOP | FTS_NOPOSTORDER;
        state.flags = SUM_SIZE;
        state.warn = 1;
-       logical = 1;
+       state.md5sumlike        = strmatch(argv[0], 
MD5SUMLIKEPATTERN)?true:false;
+       state.text              = (state.md5sumlike)?true:false;
+       logical = true;
        method = 0;
        optinit(&optdisc, optinfo);
        for (;;)
@@ -464,10 +482,10 @@
                switch (optget(argv, usage))
                {
                case 'a':
-                       state.all = 1;
+                       state.all = true;
                        continue;
                case 'b':
-                       state.text = 0;
+                       state.text = false;
                        continue;
                case 'B':
                        state.scale = opt_info.num;
@@ -494,7 +512,7 @@
                        flags &= ~FTS_TOP;
                        state.recursive = 1;
                        state.sort = order;
-                       logical = 0;
+                       logical = false;
                        continue;
                case 's':
                        method = "sys5";
@@ -503,7 +521,7 @@
                        state.silent = opt_info.num;
                        continue;
                case 't':
-                       state.total = 1;
+                       state.text = true;
                        continue;
                case 'w':
                        state.warn = opt_info.num;
@@ -513,19 +531,19 @@
                        continue;
                case 'H':
                        flags |= FTS_META|FTS_PHYSICAL;
-                       logical = 0;
+                       logical = false;
                        continue;
                case 'L':
                        flags &= ~(FTS_META|FTS_PHYSICAL);
-                       logical = 0;
+                       logical = false;
                        continue;
                case 'P':
                        flags &= ~FTS_META;
                        flags |= FTS_PHYSICAL;
-                       logical = 0;
+                       logical = false;
                        continue;
                case 'T':
-                       state.text = 1;
+                       state.total = true;
                        continue;
                case '?':
                        error(ERROR_USAGE|4, "%s", opt_info.arg);
diff -r -u original/src/lib/libcmd/md5sum.c 
build_md5sumfix/src/lib/libcmd/md5sum.c
--- src/lib/libcmd/md5sum.c     2012-01-10 19:54:41.000000000 +0100
+++ src/lib/libcmd/md5sum.c     2013-09-24 23:45:24.470027070 +0200
@@ -33,3 +33,27 @@
 {
        return b_cksum(argc, argv, context);
 }
+
+int
+b_sha1sum(int argc, register char** argv, Shbltin_t* context)
+{
+       return b_cksum(argc, argv, context);
+}
+
+int
+b_sha256sum(int argc, register char** argv, Shbltin_t* context)
+{
+       return b_cksum(argc, argv, context);
+}
+
+int
+b_sha384sum(int argc, register char** argv, Shbltin_t* context)
+{
+       return b_cksum(argc, argv, context);
+}
+
+int
+b_sha512sum(int argc, register char** argv, Shbltin_t* context)
+{
+       return b_cksum(argc, argv, context);
+}
_______________________________________________
ast-developers mailing list
[email protected]
http://lists.research.att.com/mailman/listinfo/ast-developers

Reply via email to