#999578 dmarc-cat: Please make it accept data via STDIN

Package:
dmarc-cat
Source:
dmarc-cat
Description:
decode DMARC reports
Submitter:
Gunnar Wolf
Date:
2022-11-14 17:36:10 UTC
Severity:
wishlist
Tags:
#999578#5
Date:
2021-11-12 18:38:13 UTC
From:
To:
dmarc-cat insists AFAICT to work on existing files. I tried to get it
to process the reports I found attached to received mails; for this, I
would love to be able to ask my MTA to pipe the attachment to
dmarc-cat. However, I could not get it to work, either with the
convention of using '-' or even with capturing via <( ... )

So, please, could you add an option for dmarc-cat to work on reports
from STDIN?

Thanks!

#999578#10
Date:
2022-11-08 14:13:01 UTC
From:
To:
Control: forwarded -1 https://github.com/keltia/dmarc-cat/issues/14
Control: tags -1 +pending

It *looks* like this is fixed upstream, according to:

https://github.com/keltia/dmarc-cat/issues/14

I'm going to upload 0.15 soon-ish, maybe you can confirm it's fixed
there? In any case, I'll marked this as fixed there because it looks
like upstream assumes it's fixed, so it must have happened after 0.14...

a.

#999578#19
Date:
2022-11-08 14:49:15 UTC
From:
To:
We believe that the bug you reported is fixed in the latest version of
dmarc-cat, which is due to be installed in the Debian FTP archive.

A summary of the changes between this version and the previous one is
attached.

Thank you for reporting the bug, which will now be closed.  If you
have further comments please address them to 999578@bugs.debian.org,
and the maintainer will reopen the bug report if appropriate.

Debian distribution maintenance software
pp.
Antoine Beaupré <anarcat@debian.org> (supplier of updated dmarc-cat package)

(This message was generated automatically at their request; if you
believe that there is a problem with it please contact the archive
administrators by mailing ftpmaster@ftp-master.debian.org)
Format: 1.8
Date: Tue, 08 Nov 2022 09:05:27 -0500
Source: dmarc-cat
Architecture: source
Version: 0.15.0-1
Distribution: unstable
Urgency: medium
Maintainer: Debian Go Packaging Team <team+pkg-go@tracker.debian.org>
Changed-By: Antoine Beaupré <anarcat@debian.org>
Closes: 923551 965967 971994 999578
Changes:
 dmarc-cat (0.15.0-1) unstable; urgency=medium
 .
   [ Antoine Beaupré ]
   * New upstream version 0.15.0 (Closes: #971994, #923551, #965967,
     #999578)
 .
   [ Aloïs Micard ]
   * Run standard Salsa CI tools from the Golang team
Checksums-Sha1:
 8536fd2df9592e6a36ded655d84f295923246aa6 1937 dmarc-cat_0.15.0-1.dsc
 45e50e8b119d20d42a1256effffb203e221ae96a 14867 dmarc-cat_0.15.0.orig.tar.gz
 8d5ba83a8f2c67340ee871e2851c3f90f114ebf0 2996 dmarc-cat_0.15.0-1.debian.tar.xz
 b3f5455779ae61314bdd42f274ad5cb1ec9a4452 7604 dmarc-cat_0.15.0-1_amd64.buildinfo
Checksums-Sha256:
 63ecf2f70692c7871429b34d75118fc27961a600d6d7a7216fcb6f12ae7d86f8 1937 dmarc-cat_0.15.0-1.dsc
 886bf33ba60d601de74a1e9d437a8e09eea5c03a05b09c0f685fa02d1c174bba 14867 dmarc-cat_0.15.0.orig.tar.gz
 59b016a4ab5e05f5ec1a8e902d6cf5f0c3d4f49667b8812d7a2ce14bb507cd62 2996 dmarc-cat_0.15.0-1.debian.tar.xz
 b2baec525ccd0c52776f910c16cc68c084655690f997d54255f16e354e75a046 7604 dmarc-cat_0.15.0-1_amd64.buildinfo
Files:
 e4c2edbb6de926442be328a9b581c22a 1937 devel optional dmarc-cat_0.15.0-1.dsc
 5363cab5ddade9b69c925fe8452f033e 14867 devel optional dmarc-cat_0.15.0.orig.tar.gz
 31a780b370d2a7354c811bc77a856098 2996 devel optional dmarc-cat_0.15.0-1.debian.tar.xz
 71032610d867cfd771948843eb16e137 7604 devel optional dmarc-cat_0.15.0-1_amd64.buildinfo
-----BEGIN PGP SIGNATURE-----

iQEzBAEBCAAdFiEEexZCBNCWcjsBljWrPqHd3bJh2XsFAmNqac4ACgkQPqHd3bJh
2XthBwf/U0EzHOcpy62QP7LT0lpKZNerKP0Tch7rFO4W5nqpyiPNS1qyl6b8UQPN
nmnk4iehMWYq557jLRWJtF16UlbxV5nhtgu4RTzwoM4Jt9r5IHEvlINrcCq6qWbV
Ufsd3H1JgdgLe7V1HI/scmpbx265zxQl349a1DXYv9/XC1+ASiptJ63m83Gy5aD+
R8eENQpSpuD7wgMuyDDXrVub1S84vXexMh0Rb5Rrf3OANzhC1yEoqsppOJCBo6jh
wIwAYcBimkDcz07FpfXPfaH9uRjsQM1tlacAtiRhidDNVInSw2rqnFZhpG8fduHT
xHbQGWu87C6srsvqCFGefhnGbNndWQ==
=UYWW
-----END PGP SIGNATURE-----

#999578#24
Date:
2022-11-09 19:08:06 UTC
From:
To:
Hello Antoine,

Antoine Beaupré dijo [Tue, Nov 08, 2022 at 09:13:01AM -0500]:

Thanks for following up on this. I see it does now _say to_ accept
files via STDIN, but...

    $ dmarc-cat -h
    Usage of dmarc-cat:
      -D	Debug mode
      -N	Do not resolve IPs
      -S string
        	Sort results (default "\"Count\" \"dsc\"")
      -j int
        	Parallel jobs (default 8)
      -t string
        	File type for stdin mode
      -v	Verbose mode
      -version
        	Display version
    $ dmarc-cat
    2022/11/09 12:27:08 Error: realmain: You must specify at least one file.
    $ dmarc-cat -
    2022/11/09 12:27:10 Error: SelectInput: Wrong file type, use -t

It really lacks documentation! :-( I don't know where to get the
filetype from.

Took a quick dive in dmarc-cat's source, and found only two probable
strings as file types: ".zip" and ".xml". It was not a very scientific
test, but:

    $ grep -ri ftype .
    ./file.go:		debug("%d %s", typ, fType)
    ./main.go:	fType     string
    ./main.go:	flag.StringVar(&fType, "t", "", "File type for stdin mode")
    ./main.go:		if fType == "" {
    ./main.go:	var fType = filepath.Ext(file)
    ./main.go:	if strings.ToLower(fType) == ".zip" {
    ./main.go:		typ := archive.Ext2Type(fType)
    ./main_test.go:	fType = ".xml"
    ./main_test.go:	fType = ""
    $

But handling it as .zip does not seem to work:

    $ cat report.zip | dmarc-cat -t .zip -
    2022/11/09 12:34:38 Error: file -:: unmarshall: XML syntax error on line 2: illegal character code U+0003

However, it does work when I give it the uncompressed XML:

    $ unzip -p file.zip  | dmarc-cat -t .zip -
    dmarc-cat 0.15.0,parallel/j8 by Ollivier Robert

    Reporting by: google.com — noreply-dmarc-support@google.com
    From 2022-03-28 18:00:00 -0600 CST to 2022-03-29 17:59:59 -0600 CST

    Domain: gwolf.org
    Policy: p=none; dkim=r; spf=r

    Reports(1):
    IP                 Count   From      RFrom     RDKIM   RSPF
    mail.iiec.unam.mx. 2       gwolf.org gwolf.org pass    pass

Given that file.go has the needed bits to handle a .zip file, I'd
still consider a bug to be present (albeit a different one).

I was able to find two spots in the code where this was not correctly
handled. First, in main.go, fType is clobbered even if specificed; it
should only be replaced if not specified:

diff --git a/main.go b/main.go
index 736a8e7..e6d4e98 100644
--- a/main.go
+++ b/main.go
@@ -115,7 +115,9 @@ func realmain(args []string) error {

 	verbose("Analyzing %s", file)

-	var fType = filepath.Ext(file)
+	if fType == "" {
+		fType = filepath.Ext(file)
+	}

 	if strings.ToLower(fType) == ".zip" {
 		txt, err = HandleZipFile(ctx, file)

The other point is in file.go. It seems trivial to fix, but I've never
worked with Go before; function HandleZipFile is failing to open a
file named "-"; it should just read it if so speficied. I tried to
copy the differing logic from HandleSingleFile, but failed and decided
to throw the ball back at you ;-)

Anyway, besides getting dmarc-cat to work with piped zip files, it
should at least be minimally documented!

Thanks,

     - Gunnar.