bugzilla 231: print option from config file. Useful for scripting.

git-svn-id: file:///svn/unbound/trunk@1469 be551aaa-1e26-0410-a405-d3ace91eadb9
This commit is contained in:
Wouter Wijngaards 2009-02-06 15:15:15 +00:00
parent e00e0ddd2f
commit 36b3f6e254
3 changed files with 147 additions and 6 deletions

View file

@ -11,6 +11,7 @@
- new option log-time-ascii: yes if you enable it prints timestamps - new option log-time-ascii: yes if you enable it prints timestamps
in the log file as Feb 06 13:45:26 (like syslog does). in the log file as Feb 06 13:45:26 (like syslog does).
- detect event_base_new in libevent-1.4.1 and later and use it. - detect event_base_new in libevent-1.4.1 and later and use it.
- #231 unbound-checkconf -o option prints that value from config file.
5 February 2009: Wouter 5 February 2009: Wouter
- ldns 1.5.0 rc as tarball included. - ldns 1.5.0 rc as tarball included.

View file

@ -14,7 +14,9 @@ unbound-checkconf
.SH "SYNOPSIS" .SH "SYNOPSIS"
.B unbound-checkconf .B unbound-checkconf
.RB [ \-h ] .RB [ \-h ]
.IR cfgfile .RB [ \-o
.IR option ]
.RI [ cfgfile ]
.SH "DESCRIPTION" .SH "DESCRIPTION"
.B Unbound-checkconf .B Unbound-checkconf
checks the configuration file for the checks the configuration file for the
@ -28,6 +30,10 @@ The available options are:
.B \-h .B \-h
Show the version and commandline option help. Show the version and commandline option help.
.TP .TP
.B \-o\fI option
If given, after checking the config file the value of this option is
printed to stdout. For "" (disabled) options an empty line is printed.
.TP
.I cfgfile .I cfgfile
The config file to read with settings for unbound. It is checked. The config file to read with settings for unbound. It is checked.
If omitted, the config file at the default location is checked. If omitted, the config file at the default location is checked.

View file

@ -68,13 +68,142 @@ usage()
printf("Usage: unbound-checkconf [file]\n"); printf("Usage: unbound-checkconf [file]\n");
printf(" Checks unbound configuration file for errors.\n"); printf(" Checks unbound configuration file for errors.\n");
printf("file if omitted %s is used.\n", CONFIGFILE); printf("file if omitted %s is used.\n", CONFIGFILE);
printf("-h show this usage help.\n"); printf("-o option print value of option to stdout.\n");
printf("-h show this usage help.\n");
printf("Version %s\n", PACKAGE_VERSION); printf("Version %s\n", PACKAGE_VERSION);
printf("BSD licensed, see LICENSE in source package for details.\n"); printf("BSD licensed, see LICENSE in source package for details.\n");
printf("Report bugs to %s\n", PACKAGE_BUGREPORT); printf("Report bugs to %s\n", PACKAGE_BUGREPORT);
exit(1); exit(1);
} }
/** compare and print decimal option */
#define O_DEC(opt, str, var) if(strcmp(opt, str)==0) \
{printf("%d\n", (int)cfg->var);}
/** compare and print unsigned option */
#define O_UNS(opt, str, var) if(strcmp(opt, str)==0) \
{printf("%u\n", (unsigned)cfg->var);}
/** compare and print yesno option */
#define O_YNO(opt, str, var) if(strcmp(opt, str)==0) \
{printf("%s\n", cfg->var?"yes":"no");}
/** compare and print string option */
#define O_STR(opt, str, var) if(strcmp(opt, str)==0) \
{printf("%s\n", cfg->var?cfg->var:"");}
/** compare and print array option */
#define O_IFC(opt, str, num, arr) if(strcmp(opt, str)==0) \
{int i; for(i=0; i<cfg->num; i++) printf("%s\n", cfg->arr[i]);}
/** compare and print memorysize option */
#define O_MEM(opt, str, var) if(strcmp(opt, str)==0) { \
if(cfg->var > 1024*1024*1024) { \
size_t f=cfg->var/(size_t)1000000, b=cfg->var%(size_t)1000000; \
printf("%u%6.6u\n", (unsigned)f, (unsigned)b); \
} else printf("%u\n", (unsigned)cfg->var);}
/** compare and print list option */
#define O_LST(opt, name, lst) if(strcmp(opt, name)==0) { \
struct config_strlist* p = cfg->lst; \
for(p = cfg->lst; p; p = p->next) \
printf("%s\n", p->str); \
}
/** compare and print list option */
#define O_LS2(opt, name, lst) if(strcmp(opt, name)==0) { \
struct config_str2list* p = cfg->lst; \
for(p = cfg->lst; p; p = p->next) \
printf("%s %s\n", p->str, p->str2); \
}
/**
* Print given option to stdout
* @param cfg: config
* @param opt: option name without trailing :.
* This is different from config_set_option.
*/
static void
print_option(struct config_file* cfg, const char* opt)
{
O_DEC(opt, "verbosity", verbosity)
else O_DEC(opt, "statistics-interval", stat_interval)
else O_YNO(opt, "statistics-cumulative", stat_interval)
else O_YNO(opt, "extended-statistics", stat_extended)
else O_DEC(opt, "num-threads", num_threads)
else O_IFC(opt, "interface", num_ifs, ifs)
else O_IFC(opt, "outgoing-interface", num_out_ifs, out_ifs)
else O_YNO(opt, "interface-automatic", if_automatic)
else O_DEC(opt, "port", port)
else O_DEC(opt, "outgoing-range", outgoing_num_ports)
else O_DEC(opt, "outgoing-num-tcp", outgoing_num_tcp)
else O_DEC(opt, "incoming-num-tcp", incoming_num_tcp)
else O_DEC(opt, "msg-buffer-size", msg_buffer_size)
else O_MEM(opt, "msg-cache-size", msg_cache_size)
else O_DEC(opt, "msg-cache-slabs", msg_cache_slabs)
else O_DEC(opt, "num-queries-per-thread", num_queries_per_thread)
else O_UNS(opt, "jostle-timeout", jostle_time)
else O_MEM(opt, "rrset-cache-size", rrset_cache_size)
else O_DEC(opt, "rrset-cache-slabs", rrset_cache_slabs)
else O_DEC(opt, "cache-max-ttl", max_ttl)
else O_DEC(opt, "infra-host-ttl", host_ttl)
else O_DEC(opt, "infra-lame-ttl", lame_ttl)
else O_DEC(opt, "infra-cache-slabs", infra_cache_slabs)
else O_MEM(opt, "infra-cache-numhosts", infra_cache_numhosts)
else O_MEM(opt, "infra-cache-lame-size", infra_cache_lame_size)
else O_YNO(opt, "do-ip4", do_ip4)
else O_YNO(opt, "do-ip6", do_ip6)
else O_YNO(opt, "do-udp", do_udp)
else O_YNO(opt, "do-tcp", do_tcp)
else O_YNO(opt, "do-daemonize", do_daemonize)
else O_STR(opt, "chroot", chrootdir)
else O_STR(opt, "username", username)
else O_STR(opt, "directory", directory)
else O_STR(opt, "logfile", logfile)
else O_STR(opt, "pidfile", pidfile)
else O_YNO(opt, "hide-identity", hide_identity)
else O_YNO(opt, "hide-version", hide_version)
else O_STR(opt, "identity", identity)
else O_STR(opt, "version", version)
else O_STR(opt, "target-fetch-policy", target_fetch_policy)
else O_YNO(opt, "harden-short-bufsize", harden_short_bufsize)
else O_YNO(opt, "harden-large-queries", harden_large_queries)
else O_YNO(opt, "harden-glue", harden_glue)
else O_YNO(opt, "harden-dnssec-stripped", harden_dnssec_stripped)
else O_YNO(opt, "harden-referral-path", harden_referral_path)
else O_YNO(opt, "use-caps-for-id", use_caps_bits_for_id)
else O_DEC(opt, "unwanted-reply-threshold", unwanted_threshold)
else O_YNO(opt, "do-not-query-localhost", donotquery_localhost)
else O_STR(opt, "module-config", module_conf)
else O_STR(opt, "dlv-anchor-file", dlv_anchor_file)
else O_DEC(opt, "val-bogus-ttl", bogus_ttl)
else O_YNO(opt, "val-clean-additional", val_clean_additional)
else O_YNO(opt, "val-permissive-mode", val_permissive_mode)
else O_STR(opt, "val-nsec3-keysize-iterations",val_nsec3_key_iterations)
else O_MEM(opt, "key-cache-size", key_cache_size)
else O_DEC(opt, "key-cache-slabs", key_cache_slabs)
else O_MEM(opt, "neg-cache-size", neg_cache_size)
else O_YNO(opt, "control-enable", remote_control_enable)
else O_DEC(opt, "control-port", control_port)
else O_STR(opt, "server-key-file", server_key_file)
else O_STR(opt, "server-cert-file", server_cert_file)
else O_STR(opt, "control-key-file", control_key_file)
else O_STR(opt, "control-cert-file", control_cert_file)
else O_LST(opt, "root-hints", root_hints)
else O_LS2(opt, "access-control", acls)
else O_LST(opt, "do-not-query-address", donotqueryaddrs)
else O_LST(opt, "private-address", private_address)
else O_LST(opt, "private-domain", private_domain)
else O_LST(opt, "trust-anchor-file", trust_anchor_file_list)
else O_LST(opt, "trust-anchor", trust_anchor_list)
else O_LST(opt, "trusted-keys-file", trusted_keys_file_list)
else O_LST(opt, "dlv-anchor", dlv_anchor_list)
else O_LST(opt, "control-interface", control_ifs)
else O_UNS(opt, "val-override-date", val_date_override)
/* not here:
* outgoing-permit, outgoing-avoid - have list of ports
* local-zone - zones and nodefault variables
* local-data - see below
* local-data-ptr - converted to local-data entries
* stub-zone, name, stub-addr, stub-host, stub-prime
* forward-zone, name, forward-addr, forward-host
*/
else fatal_exit("cannot print option '%s'", opt);
}
/** check if module works with config */ /** check if module works with config */
static void static void
check_mod(struct config_file* cfg, struct module_func_block* fb) check_mod(struct config_file* cfg, struct module_func_block* fb)
@ -393,7 +522,7 @@ morechecks(struct config_file* cfg, const char* fname)
/** check config file */ /** check config file */
static void static void
checkconf(const char* cfgfile) checkconf(const char* cfgfile, const char* opt)
{ {
struct config_file* cfg = config_create(); struct config_file* cfg = config_create();
if(!cfg) if(!cfg)
@ -406,8 +535,9 @@ checkconf(const char* cfgfile)
morechecks(cfg, cfgfile); morechecks(cfg, cfgfile);
check_mod(cfg, iter_get_funcblock()); check_mod(cfg, iter_get_funcblock());
check_mod(cfg, val_get_funcblock()); check_mod(cfg, val_get_funcblock());
if(opt) print_option(cfg, opt);
else printf("unbound-checkconf: no errors in %s\n", cfgfile);
config_delete(cfg); config_delete(cfg);
printf("unbound-checkconf: no errors in %s\n", cfgfile);
} }
/** getopt global, in case header files fail to declare it. */ /** getopt global, in case header files fail to declare it. */
@ -420,12 +550,16 @@ int main(int argc, char* argv[])
{ {
int c; int c;
const char* f; const char* f;
const char* opt = NULL;
log_ident_set("unbound-checkconf"); log_ident_set("unbound-checkconf");
log_init(NULL, 0, NULL); log_init(NULL, 0, NULL);
checklock_start(); checklock_start();
/* parse the options */ /* parse the options */
while( (c=getopt(argc, argv, "h")) != -1) { while( (c=getopt(argc, argv, "ho:")) != -1) {
switch(c) { switch(c) {
case 'o':
opt = optarg;
break;
case '?': case '?':
case 'h': case 'h':
default: default:
@ -439,7 +573,7 @@ int main(int argc, char* argv[])
if(argc == 1) if(argc == 1)
f = argv[0]; f = argv[0];
else f = CONFIGFILE; else f = CONFIGFILE;
checkconf(f); checkconf(f, opt);
checklock_stop(); checklock_stop();
return 0; return 0;
} }