From f54a7004818905702fdcac7b69e9795a3ea67ce4 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Wed, 21 Oct 2020 14:11:14 -0400 Subject: [PATCH] Show only a usage summary when -h is passed. There was a long "usage" string contained within the program itself that is now contained within the man page. The long usage would be shown with "valtz -h", and a shorter one would be shown with simply "valtz", which is an error by itself. This commit also unifies those two: if you try to run valtz with no arguments, the "valtz -h" output is shown but the exit code will be non-zero. --- valtz | 156 +++++++++++--------------------------------------------- valtz.1 | 9 ++-- 2 files changed, 35 insertions(+), 130 deletions(-) diff --git a/valtz b/valtz index 5ee3750..12d22c9 100755 --- a/valtz +++ b/valtz @@ -895,147 +895,49 @@ sub do_filterfile ($$) my $files = funiq(@ARGV); +sub usage { + print <<"--EOT"; +valtz $VERSION - validate tinydns-data files -if ($opt{h} || $opt{H} || $opt{'?'}) -{ - print <<"--EOT"; -valtz $VERSION -validates tinydns-data zone files Usage: - $0 [-hfFqrRiItT] - - -h shows this help. - - - -f filter (don't just validate) file and output accepted lines to STDOUT. - - - -F treat files as filter configuration files for more advanced filtering. - These filterfiles one or several of the following filter directives: - - zonefile - zonefile file: - Defines the file(s) to be filtered. Can be a globbed value, like - /var/zones/external/* - - extralog - Defines an extra logfile that the STDERR output will be copied for - this specific filterfile. Useful if you have a lot of filterfiles - and want to separate the logs. - - deny - deny file: - Defines a zonepattern to explicitly DENY after implicitly allowing all. - (cannot be combined with allow) - - allow - allow file: - Defines a zonepattern to explicitly ALLOW after implicitly denying all. - - allowtype - Explicitly sets the allowed recordtypes. Note that even comments - has to be allowed (but these will not result in errors unless -t) - to be copied to the output. - - Multiple zonefile, allow- and deny-lines are allowed, but also the - alternative file:-line that points to a textfile containing one - value per line. - - - -r allows fqdn to be empty thus denoting the root. - This is also allowed per default when doing implict allow - see deny, - or when specifying 'allow .', i.e. explictly allowing root as such. - (cannot be combined with deny) - - - -R relaxes the validation and allows empty mname and p-fields.xi - This is probably not very useful. - - - -i allows the ip-fields to be empty as well. These will then not generate any - records. - - - -I Include rejected lines as comments in output (valid when filtering). + $0 [-r] [-R] [-i] tinydns-file1 [tinydns-file2...] + $0 [-HiIqrRst] [-T types] -f tinydns-file1 [tinydns-file2 ...] - -q Do not echo valid lines to STDOUT. + $0 valtz [-fHiIqrRst] [-T types] -F filter-file1 [filter-file2 ...] - -s DO NOT ignore files ending with ,v ~ .bak .log .old .swp .tmp - which is done per default. +Flags: + -h print usage information + -f filter invalid lines (filter mode) + -F filter using configuration files (advanced filter mode) + -r allow "fqdn" fields to be empty + -R allow "mname" and "p" fields to be empty + -i allow "ip" fields to be empty + -I include rejected lines as comments (filtering only) + -q don't print valid lines to standard out (filtering only) + -s don't skip temporary and backup files + -t don't ignore comment lines (filtering only) + -T allow additional record types (advanced filtering only) - - -t Give error even on #comment-lines when they are not allowed. - (These errors are silently ignored per default) - - - -T - A commandline way to explicitly set the allowed recordtypes. - This is _concatenated_ to the allowtype-allowed recordtypes. - - - -All errors in the zonefiles are sent to STDERR. - - Example; simple use: - valtz zone-bodin-org - - Example; simple filter-use; - valtz -f /etc/zones/zone-* \ - >/etc/tinydns/data.filtered \ - 2>/var/log/tinydns/valtz.log - - Example; filterfile use; - valtz -F /etc/zones/filter/zones-otto \ - >/etc/tinydns/data.otto \ - 2>/var/log/tinydns/valtz.log - - - Example filterfile for using as import from primary (as above): - zonefile /var/zones/external/otto/zone-* - deny bodin.org - deny x42.com - extralog /var/log/tinydns/external-otto.log - - Example #2, strict filter for a certain user editing just A-records - - zonefile /home/felix/zones/zone-fl3x-net - allow fl3x.net - allowtype + - extralog /var/log/tinydns/fl3x-net.log - - Example #3, export filter to secondary - - zonefile /var/zones/primary/zone-* - # just allow OUR zones to be exported, not to annoy secondary partner - allow file:/var/zones/primary-zones.txt - # don't allow any other types than this; e.g. comments won't be exported - allowtype Z + @ . C - extralog /var/log/tinydns/primary-export.log +Errors are generally printed to standard error, and the exit code +shall reflect the presense of both usage and validation errors. See +the man page for details. --EOT - exit 0; } -elsif (@{$files} == 0) -{ - print <<"--EOT"; -valtz $VERSION -validates tinydns-data zone files -Usage: - Simple validation: - $0 [-qrRix] - Simple filtering: - $0 -f[qrRiItTx] - Extensive filtering: - $0 -F[qrRiItTx] - More help and information about options: - $0 -h +if ($opt{h} || $opt{H} || $opt{'?'}) { + usage(); ---EOT + # If they asked for help, ignore whatever else they may have done + # wrong. exit 0; } +if (@{$files} == 0) { + usage(); + exit 4; +} if ($opt{F}) { diff --git a/valtz.1 b/valtz.1 index 5fd6ec7..8eade8f 100644 --- a/valtz.1 +++ b/valtz.1 @@ -59,9 +59,12 @@ printed to standard error. When filtering, the acceptable lines are printed to standard out. .SH EXIT CODE -The exit code will be 0 if nothing has gone wrong. If a validation -error occurs, the return value is incremented by 1. If a disallowed -record type is encountered, the return value is incremented by 2. +The exit code will be 0 if nothing has gone wrong. If any validation +error occured, the return value is incremented by 1. If a disallowed +record type was encountered, the return value is incremented by 2. +If you forgot to pass the required filename arguments (either the +tinydns-data files or the filter configuration files), then we exit +immediately with code 4. .SH ADVANCED FILTERING When the \fB-F\fR flag is used, valtz performs "advanced filtering" -- 2.44.2