How to validate alias/map files?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

How to validate alias/map files?

Dan Mahoney (Gushi)
Hey all,

I'm using procedurally-generated alias files from a database, and
distributing them with puppet, and would like to have postalias check the
files for duplicate entries and/or other errors before I install them.
I'd like to use the same program used to install the DB, rather than
hacking a validator together with perl or something.

As an example, an empty left-hand

foo:

would be an error I want to catch.  I want to catch duplicate items, as
well.  I'd rather not parse stderr for this.

There seem to be two obvious missing features:

First, the ability to not output a file, but just parse the existing one.

Second, the abiity to generate errors (as in, exit code errors) rather
than warnings.  This could be added to postfix without changing existing
behavior.

Is there any good way that people would recommend parsing alias and map
files?  The closest I've come would be counting the number of lines of
output to stderr, rather than looking at exit code, but that still seems
contrived.

Perhaps this is best for the manpage: what errors *will* cause actual
non-zero exit codes?

-Dan

--

--------Dan Mahoney--------
Techie,  Sysadmin,  WebGeek
Gushi on efnet/undernet IRC
FB:  fb.com/DanielMahoneyIV
LI:   linkedin.com/in/gushi
Site:  http://www.gushi.org
---------------------------

Reply | Threaded
Open this post in threaded view
|

Re: How to validate alias/map files?

Viktor Dukhovni
On Thu, Jun 27, 2019 at 05:39:14PM -0700, Dan Mahoney (Gushi) wrote:

> Is there any good way that people would recommend parsing alias and map
> files?  The closest I've come would be counting the number of lines of
> output to stderr, rather than looking at exit code, but that still seems
> contrived.

One possible work-around is:

    ln -f foo foo.tmp
    postalias hash:foo.tmp
    gotkeys=$(postmap -s hash:foo.tmp | pcregrep -c '^[^\s#]')
    wanted=$( (cat foo.tmp; echo "@ @") | pcregrep -c '^[^\s#]' )

    if [ "$gotkeys" -eq "$wanted" ]; then
        /bin/mv foo.tmp.db foo.db
    else
        # Error ...
        /bin/rm -f foo.tmp foo.tmp.db
        exit 1
    fi

--
        Viktor.