unbound
0.1
|
This file contains functions for the config file. More...
Data Structures | |
struct | config_file |
The configuration options. More... | |
struct | config_stub |
Stub config options. More... | |
struct | config_strlist |
List of strings for config options. More... | |
struct | config_str2list |
List of two strings for config options. More... | |
struct | config_strlist_head |
List head for strlist processing, used for append operation. More... | |
struct | config_parser_state |
Used during options parsing. More... | |
Functions | |
struct config_file * | config_create (void) |
Create config file structure. | |
struct config_file * | config_create_forlib (void) |
Create config file structure for library use. | |
int | config_read (struct config_file *config, const char *filename, const char *chroot) |
Read the config file from the specified filename. | |
void | config_delete (struct config_file *config) |
Destroy the config file structure. | |
void | config_apply (struct config_file *config) |
Apply config to global constants; this routine is called in single thread. | |
int | config_set_option (struct config_file *config, const char *option, const char *value) |
Set the given keyword to the given value. | |
int | config_get_option (struct config_file *cfg, const char *opt, void(*func)(char *, void *), void *arg) |
Call print routine for the given option. | |
int | config_get_option_list (struct config_file *cfg, const char *opt, struct config_strlist **list) |
Get an option and return strlist. | |
int | config_get_option_collate (struct config_file *cfg, const char *opt, char **str) |
Get an option and collate results into string. | |
void | config_print_func (char *line, void *arg) |
function to print to a file, use as func with config_get_option. | |
void | config_collate_func (char *line, void *arg) |
function to collate the text strings into a strlist_head. | |
char * | config_collate_cat (struct config_strlist *list) |
take a strlist_head list and return a malloc string. | |
int | cfg_strlist_append (struct config_strlist_head *list, char *item) |
Append text at end of list. | |
int | cfg_strlist_insert (struct config_strlist **head, char *item) |
Insert string into strlist. | |
int | cfg_str2list_insert (struct config_str2list **head, char *item, char *i2) |
Insert string into str2list. | |
void | config_delstrlist (struct config_strlist *list) |
Delete items in config string list. | |
void | config_deldblstrlist (struct config_str2list *list) |
Delete items in config double string list. | |
void | config_delstubs (struct config_stub *list) |
Delete items in config stub list. | |
uint32_t | cfg_convert_timeval (const char *str) |
Convert 14digit to time value. | |
int | cfg_count_numbers (const char *str) |
Count number of values in the string. | |
int | cfg_parse_memsize (const char *str, size_t *res) |
Convert a 'nice' memory or file size into a bytecount From '100k' to 102400. | |
int | cfg_parse_local_zone (struct config_file *cfg, const char *val) |
Parse local-zone directive into two strings and register it in the config. | |
int | cfg_mark_ports (const char *str, int allow, int *avail, int num) |
Mark "number" or "low-high" as available or not in ports array. | |
int | cfg_condense_ports (struct config_file *cfg, int **avail) |
Get a condensed list of ports returned. | |
int | cfg_scan_ports (int *avail, int num) |
Scan ports available. | |
char * | fname_after_chroot (const char *fname, struct config_file *cfg, int use_chdir) |
Convert a filename to full pathname in original filesys. | |
char * | cfg_ptr_reverse (char *str) |
Convert a ptr shorthand into a full reverse-notation PTR record. | |
void | errinf (struct module_qstate *qstate, const char *str) |
Append text to the error info for validation. | |
void | errinf_origin (struct module_qstate *qstate, struct sock_list *origin) |
Append text to error info: from 1.2.3.4. | |
void | errinf_rrset (struct module_qstate *qstate, struct ub_packed_rrset_key *rr) |
Append text to error info: for RRset name type class. | |
void | errinf_dname (struct module_qstate *qstate, const char *str, uint8_t *dname) |
Append text to error info: str dname. | |
char * | errinf_to_str (struct module_qstate *qstate) |
Create error info in string. | |
void | ub_c_error (const char *msg) |
parsing helpers: print error with file and line numbers | |
void | ub_c_error_msg (const char *fmt,...) ATTR_FORMAT(printf |
parsing helpers: print error with file and line numbers | |
Variables | |
struct config_parser_state * | cfg_parser |
global config parser object used during config parsing |
This file contains functions for the config file.
struct config_file* config_create | ( | void | ) | [read] |
Create config file structure.
Filled with default values.
References config_file::acls, config_file::add_holddown, config_file::auto_trust_anchor_file_list, config_file::bogus_ttl, config_file::chrootdir, config_delete(), config_file::control_cert_file, config_file::control_ifs, config_file::control_key_file, config_file::control_port, config_file::del_holddown, config_file::directory, config_file::dlv_anchor_file, config_file::dlv_anchor_list, config_file::do_daemonize, config_file::do_ip4, config_file::do_ip6, config_file::do_tcp, config_file::do_udp, config_file::domain_insecure, config_file::donotquery_localhost, config_file::donotqueryaddrs, config_file::edns_buffer_size, error_exit(), config_file::forwards, config_file::harden_below_nxdomain, config_file::harden_dnssec_stripped, config_file::harden_glue, config_file::harden_large_queries, config_file::harden_referral_path, config_file::harden_short_bufsize, config_file::hide_identity, config_file::hide_version, config_file::host_ttl, config_file::identity, config_file::if_automatic, config_file::ifs, config_file::ignore_cd, config_file::incoming_num_tcp, config_file::infra_cache_numhosts, config_file::infra_cache_slabs, init_outgoing_availports(), config_file::jostle_time, config_file::keep_missing, config_file::key_cache_size, config_file::key_cache_slabs, config_file::local_data, config_file::local_zones, config_file::local_zones_nodefault, config_file::log_queries, config_file::log_time_ascii, config_file::logfile, config_file::max_ttl, config_file::min_ttl, config_file::module_conf, config_file::msg_buffer_size, config_file::msg_cache_size, config_file::msg_cache_slabs, config_file::neg_cache_size, config_file::num_ifs, config_file::num_out_ifs, config_file::num_queries_per_thread, config_file::num_threads, config_file::out_ifs, config_file::outgoing_avail_ports, config_file::outgoing_num_ports, config_file::outgoing_num_tcp, config_file::pidfile, config_file::port, config_file::prefetch, config_file::prefetch_key, config_file::private_address, config_file::private_domain, config_file::python_script, config_file::remote_control_enable, config_file::root_hints, config_file::rrset_cache_size, config_file::rrset_cache_slabs, config_file::server_cert_file, config_file::server_key_file, config_file::so_rcvbuf, config_file::so_sndbuf, config_file::ssl_port, config_file::ssl_service_key, config_file::ssl_service_pem, config_file::ssl_upstream, config_file::stat_cumulative, config_file::stat_extended, config_file::stat_interval, config_file::stubs, config_file::target_fetch_policy, config_file::tcp_upstream, config_file::trust_anchor_file_list, config_file::trust_anchor_list, config_file::trusted_keys_file_list, config_file::unwanted_threshold, config_file::use_caps_bits_for_id, config_file::use_syslog, config_file::username, config_file::val_clean_additional, config_file::val_date_override, config_file::val_log_level, config_file::val_log_squelch, config_file::val_nsec3_key_iterations, config_file::val_permissive_mode, config_file::val_sig_skew_max, config_file::val_sig_skew_min, config_file::verbosity, and config_file::version.
Referenced by checkconf(), config_create_forlib(), go(), infra_test(), run_daemon(), and service_init().
struct config_file* config_create_forlib | ( | void | ) | [read] |
Create config file structure for library use.
Filled with default values.
References config_file::chrootdir, config_create(), config_file::donotquery_localhost, config_file::infra_cache_slabs, config_file::key_cache_size, config_file::key_cache_slabs, config_file::msg_cache_size, config_file::msg_cache_slabs, config_file::neg_cache_size, config_file::outgoing_num_ports, config_file::outgoing_num_tcp, config_file::rrset_cache_size, config_file::rrset_cache_slabs, config_file::use_syslog, config_file::val_log_level, config_file::val_log_squelch, and config_file::verbosity.
Referenced by ub_ctx_create().
int config_read | ( | struct config_file * | config, |
const char * | filename, | ||
const char * | chroot | ||
) |
Read the config file from the specified filename.
config,: | where options are stored into, must be freshly created. |
filename,: | name of configfile. If NULL nothing is done. |
chroot,: | if not NULL, the chroot dir currently in use (for include). |
References create_cfg_parser(), config_parser_state::errors, config_parser_state::filename, log_err(), ub_c_in, and ub_c_parse().
Referenced by checkconf(), go(), run_daemon(), service_init(), and ub_ctx_config().
void config_delete | ( | struct config_file * | config | ) |
Destroy the config file structure.
config,: | to delete. |
References config_file::acls, config_file::auto_trust_anchor_file_list, config_file::chrootdir, config_deldblstrlist(), config_delstrlist(), config_delstubs(), config_file::control_cert_file, config_file::control_ifs, config_file::control_key_file, config_file::directory, config_file::dlv_anchor_file, config_file::dlv_anchor_list, config_file::domain_insecure, config_file::donotqueryaddrs, config_file::forwards, config_file::identity, config_file::ifs, config_file::local_data, config_file::local_zones, config_file::local_zones_nodefault, config_file::logfile, config_file::module_conf, config_file::num_ifs, config_file::num_out_ifs, config_file::out_ifs, config_file::outgoing_avail_ports, config_file::pidfile, config_file::private_address, config_file::private_domain, config_file::root_hints, config_file::server_cert_file, config_file::server_key_file, config_file::ssl_service_key, config_file::ssl_service_pem, config_file::stubs, config_file::target_fetch_policy, config_file::trust_anchor_file_list, config_file::trust_anchor_list, config_file::trusted_keys_file_list, config_file::username, config_file::val_nsec3_key_iterations, and config_file::version.
Referenced by checkconf(), config_create(), go(), infra_test(), run_daemon(), service_deinit(), service_init(), service_main(), and ub_ctx_delete().
void config_apply | ( | struct config_file * | config | ) |
Apply config to global constants; this routine is called in single thread.
config,: | to apply. Side effect: global constants change. |
References EDNS_ADVERTISED_SIZE, config_file::edns_buffer_size, log_set_time_asc(), config_file::log_time_ascii, MAX_TTL, config_file::max_ttl, MIN_TTL, and config_file::min_ttl.
Referenced by context_finalize(), and daemon_apply_cfg().
int config_set_option | ( | struct config_file * | config, |
const char * | option, | ||
const char * | value | ||
) |
Set the given keyword to the given value.
config,: | where to store config |
option,: | option name, including the ':' character. |
value,: | value, this string is copied if needed, or parsed. The caller owns the value string. |
References config_file::add_holddown, config_file::auto_trust_anchor_file_list, config_file::bogus_ttl, cfg_convert_timeval(), cfg_mark_ports(), cfg_parse_local_zone(), cfg_ptr_reverse(), cfg_strlist_insert(), config_file::chrootdir, config_file::control_cert_file, config_file::control_ifs, config_file::control_key_file, config_file::control_port, config_file::del_holddown, config_file::directory, config_file::dlv_anchor_file, config_file::dlv_anchor_list, config_file::do_daemonize, config_file::do_ip4, config_file::do_ip6, config_file::do_tcp, config_file::do_udp, config_file::domain_insecure, config_file::donotquery_localhost, config_file::donotqueryaddrs, config_file::edns_buffer_size, config_file::harden_below_nxdomain, config_file::harden_dnssec_stripped, config_file::harden_glue, config_file::harden_large_queries, config_file::harden_referral_path, config_file::harden_short_bufsize, config_file::hide_identity, config_file::hide_version, config_file::host_ttl, config_file::identity, config_file::if_automatic, config_file::ignore_cd, config_file::incoming_num_tcp, config_file::infra_cache_numhosts, config_file::infra_cache_slabs, config_file::jostle_time, config_file::keep_missing, config_file::key_cache_size, config_file::key_cache_slabs, config_file::local_data, config_file::log_queries, config_file::logfile, config_file::max_ttl, config_file::module_conf, config_file::msg_buffer_size, config_file::msg_cache_size, config_file::msg_cache_slabs, config_file::neg_cache_size, config_file::num_queries_per_thread, config_file::outgoing_avail_ports, config_file::outgoing_num_ports, config_file::outgoing_num_tcp, config_file::pidfile, config_file::port, config_file::prefetch, config_file::prefetch_key, config_file::private_address, config_file::private_domain, config_file::python_script, config_file::remote_control_enable, config_file::root_hints, config_file::rrset_cache_size, config_file::rrset_cache_slabs, S_MEMSIZE, S_NUMBER_NONZERO, S_NUMBER_OR_ZERO, S_POW2, S_SIZET_NONZERO, S_SIZET_OR_ZERO, S_STR, S_STRLIST, S_UNSIGNED_OR_ZERO, S_YNO, config_file::server_cert_file, config_file::server_key_file, config_file::so_rcvbuf, config_file::so_sndbuf, config_file::ssl_port, config_file::ssl_service_key, config_file::ssl_service_pem, config_file::ssl_upstream, config_file::stat_cumulative, config_file::stat_extended, config_file::stat_interval, config_file::target_fetch_policy, config_file::tcp_upstream, config_file::trust_anchor_file_list, config_file::trust_anchor_list, config_file::trusted_keys_file_list, config_file::unwanted_threshold, config_file::use_caps_bits_for_id, config_file::use_syslog, config_file::username, config_file::val_clean_additional, config_file::val_date_override, config_file::val_log_level, config_file::val_log_squelch, config_file::val_nsec3_key_iterations, config_file::val_permissive_mode, verbosity, and config_file::version.
Referenced by do_set_option(), and ub_ctx_set_option().
int config_get_option | ( | struct config_file * | cfg, |
const char * | opt, | ||
void(*)(char *, void *) | func, | ||
void * | arg | ||
) |
Call print routine for the given option.
cfg,: | config. |
opt,: | option name without trailing :. This is different from config_set_option. |
func,: | print func, called as (str, arg) for every data element. |
arg,: | user argument for print func. |
References fptr_ok, fptr_whitelist_print_func(), logfile, O_DEC, O_IFC, O_LS2, O_LST, O_MEM, O_STR, O_UNS, O_YNO, and verbosity.
Referenced by config_get_option_list(), do_get_option(), and print_option().
int config_get_option_list | ( | struct config_file * | cfg, |
const char * | opt, | ||
struct config_strlist ** | list | ||
) |
Get an option and return strlist.
cfg,: | config file |
opt,: | option name. |
list,: | list is returned here. malloced, caller must free it. |
References config_collate_func(), config_delstrlist(), config_get_option(), config_strlist_head::first, config_collate_arg::list, and config_collate_arg::status.
Referenced by config_get_option_collate().
int config_get_option_collate | ( | struct config_file * | cfg, |
const char * | opt, | ||
char ** | str | ||
) |
Get an option and collate results into string.
cfg,: | config file |
opt,: | option name. |
str,: | string. malloced, caller must free it. |
References config_collate_cat(), config_delstrlist(), and config_get_option_list().
Referenced by ub_ctx_get_option().
void config_print_func | ( | char * | line, |
void * | arg | ||
) |
function to print to a file, use as func with config_get_option.
line,: | text to print. appended. |
arg,: | pass a FILE*, like stdout. |
Referenced by fptr_whitelist_print_func(), and print_option().
void config_collate_func | ( | char * | line, |
void * | arg | ||
) |
function to collate the text strings into a strlist_head.
line,: | text to append. |
arg,: | pass a strlist_head structure. zeroed on start. |
References cfg_strlist_append(), config_collate_arg::list, and config_collate_arg::status.
Referenced by config_get_option_list(), and fptr_whitelist_print_func().
char* config_collate_cat | ( | struct config_strlist * | list | ) |
take a strlist_head list and return a malloc string.
separated with newline.
list,: | strlist first to collate. zeroes return "". |
References config_strlist::next, and config_strlist::str.
Referenced by config_get_option_collate().
int cfg_strlist_append | ( | struct config_strlist_head * | list, |
char * | item | ||
) |
Append text at end of list.
list,: | list head. zeroed at start. |
item,: | new item. malloced by caller. if NULL the insertion fails. |
References config_strlist_head::first, config_strlist_head::last, config_strlist::next, and config_strlist::str.
Referenced by config_collate_func().
int cfg_strlist_insert | ( | struct config_strlist ** | head, |
char * | item | ||
) |
Insert string into strlist.
head,: | pointer to strlist head variable. |
item,: | new item. malloced by caller. If NULL the insertion fails. |
References config_strlist::next, and config_strlist::str.
Referenced by cfg_parse_local_zone(), config_set_option(), read_file_content(), setup_config(), spool_auto_file(), ub_ctx_add_ta(), ub_ctx_add_ta_file(), ub_ctx_hosts(), ub_ctx_set_fwd(), and ub_ctx_trustedkeys().
int cfg_str2list_insert | ( | struct config_str2list ** | head, |
char * | item, | ||
char * | i2 | ||
) |
Insert string into str2list.
head,: | pointer to str2list head variable. |
item,: | new item. malloced by caller. If NULL the insertion fails. |
i2,: | 2nd string, malloced by caller. If NULL the insertion fails. |
References config_str2list::next, config_str2list::str, and config_str2list::str2.
Referenced by cfg_parse_local_zone().
void config_delstrlist | ( | struct config_strlist * | list | ) |
Delete items in config string list.
list,: | list. |
References config_strlist::next, and config_strlist::str.
Referenced by config_delete(), config_delstubs(), config_get_option_collate(), config_get_option_list(), lz_freeup_cfg(), remove_configfile(), and replay_moment_delete().
void config_deldblstrlist | ( | struct config_str2list * | list | ) |
Delete items in config double string list.
list,: | list. |
References config_str2list::next, config_str2list::str, and config_str2list::str2.
Referenced by config_delete(), and lz_freeup_cfg().
void config_delstubs | ( | struct config_stub * | list | ) |
Delete items in config stub list.
list,: | list. |
References config_stub::addrs, config_delstrlist(), config_stub::hosts, config_stub::name, and config_stub::next.
Referenced by config_delete(), and ub_ctx_set_fwd().
uint32_t cfg_convert_timeval | ( | const char * | str | ) |
Convert 14digit to time value.
str,: | string of 14 digits |
Referenced by config_set_option(), parse_cmdline(), and verifytest_file().
int cfg_count_numbers | ( | const char * | str | ) |
Count number of values in the string.
format ::= (sp num)+ sp num ::= [-](0-9)+ sp ::= (space|tab)*
str,: | string |
Referenced by read_fetch_policy(), and val_apply_cfg().
int cfg_parse_memsize | ( | const char * | str, |
size_t * | res | ||
) |
Convert a 'nice' memory or file size into a bytecount From '100k' to 102400.
and so on. Understands kKmMgG. k=1024, m=1024*1024, g=1024*1024*1024.
str,: | string |
res,: | result is stored here, size in bytes. |
References isalldigit(), and log_err().
Referenced by config_memsize_test(), and main().
int cfg_parse_local_zone | ( | struct config_file * | cfg, |
const char * | val | ||
) |
Parse local-zone directive into two strings and register it in the config.
cfg,: | to put it in. |
val,: | argument strings to local-zone, "example.com nodefault". |
References cfg_str2list_insert(), cfg_strlist_insert(), last_space_pos(), config_file::local_zones, config_file::local_zones_nodefault, log_err(), and next_space_pos().
Referenced by config_set_option().
int cfg_mark_ports | ( | const char * | str, |
int | allow, | ||
int * | avail, | ||
int | num | ||
) |
Mark "number" or "low-high" as available or not in ports array.
str,: | string in input |
allow,: | give true if this range is permitted. |
avail,: | the array from cfg. |
num,: | size of the array (65536). |
References log_err().
Referenced by config_set_option().
int cfg_condense_ports | ( | struct config_file * | cfg, |
int ** | avail | ||
) |
Get a condensed list of ports returned.
allocated.
cfg,: | config file. |
avail,: | the available ports array is returned here. |
References cfg_scan_ports(), log_assert, and config_file::outgoing_avail_ports.
Referenced by libworker_setup().
int cfg_scan_ports | ( | int * | avail, |
int | num | ||
) |
Scan ports available.
avail,: | the array from cfg. |
num,: | size of the array (65536). |
Referenced by cfg_condense_ports().
char* fname_after_chroot | ( | const char * | fname, |
struct config_file * | cfg, | ||
int | use_chdir | ||
) |
Convert a filename to full pathname in original filesys.
fname,: | the path name to convert. Must not be null or empty. |
cfg,: | config struct for chroot and chdir (if set). |
use_chdir,: | if false, only chroot is applied. |
References config_file::chrootdir, config_file::directory, and strlen_after_chroot().
Referenced by check_chroot_filelist_wild(), check_chroot_string(), daemon_remote_create(), morechecks(), perform_setup(), and setup_ctx().
char* cfg_ptr_reverse | ( | char * | str | ) |
Convert a ptr shorthand into a full reverse-notation PTR record.
str,: | input string, "IP name" |
References addr_is_ip6(), ipstrtoaddr(), last_space_pos(), log_err(), and next_space_pos().
Referenced by config_set_option().
void errinf | ( | struct module_qstate * | qstate, |
const char * | str | ||
) |
Append text to the error info for validation.
qstate,: | query state. |
str,: | copied into query region and appended. Failures to allocate are logged. |
References module_env::cfg, module_qstate::env, module_qstate::errinf, log_err(), config_strlist::next, module_qstate::region, regional_alloc(), regional_strdup(), config_strlist::str, and config_file::val_log_level.
Referenced by ds_response_to_ke(), errinf_dname(), errinf_origin(), errinf_rrset(), primeResponseToKE(), process_dnskey_response(), processFindKey(), processInit(), processValidate(), and validate_msg_signatures().
void errinf_origin | ( | struct module_qstate * | qstate, |
struct sock_list * | origin | ||
) |
Append text to error info: from 1.2.3.4.
qstate,: | query state. |
origin,: | sock list with origin of trouble. Every element added. If NULL: nothing is added. if 0len element: 'from cache' is added. |
References sock_list::addr, addr_to_str(), module_env::cfg, module_qstate::env, errinf(), sock_list::len, sock_list::next, and config_file::val_log_level.
Referenced by process_dnskey_response(), process_ds_response(), process_prime_response(), processFindKey(), processValidate(), and validate_msg_signatures().
void errinf_rrset | ( | struct module_qstate * | qstate, |
struct ub_packed_rrset_key * | rr | ||
) |
Append text to error info: for RRset name type class.
qstate,: | query state. |
rr,: | rrset_key. |
References module_env::cfg, packed_rrset_key::dname, dname_str(), module_qstate::env, errinf(), log_err(), ub_packed_rrset_key::rk, packed_rrset_key::rrset_class, packed_rrset_key::type, and config_file::val_log_level.
Referenced by validate_msg_signatures().
void errinf_dname | ( | struct module_qstate * | qstate, |
const char * | str, | ||
uint8_t * | dname | ||
) |
Append text to error info: str dname.
qstate,: | query state. |
str,: | explanation string |
dname,: | the dname. |
References module_env::cfg, dname_str(), module_qstate::env, errinf(), and config_file::val_log_level.
Referenced by process_dnskey_response(), process_ds_response(), process_prime_response(), and processInit().
char* errinf_to_str | ( | struct module_qstate * | qstate | ) |
Create error info in string.
qstate,: | query state. |
References dname_str(), module_qstate::errinf, log_err(), config_strlist::next, query_info::qclass, module_qstate::qinfo, query_info::qname, query_info::qtype, and config_strlist::str.
Referenced by key_cache_insert(), mesh_do_callback(), and processFinished().