Data Structures | Functions | Variables
config_file.h File Reference

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_fileconfig_create (void)
 Create config file structure. More...
 
struct config_fileconfig_create_forlib (void)
 Create config file structure for library use. More...
 
int config_read (struct config_file *config, const char *filename, const char *chroot)
 Read the config file from the specified filename. More...
 
void config_delete (struct config_file *config)
 Destroy the config file structure. More...
 
void config_apply (struct config_file *config)
 Apply config to global constants; this routine is called in single thread. More...
 
int config_set_option (struct config_file *config, const char *option, const char *value)
 Set the given keyword to the given value. More...
 
int config_get_option (struct config_file *cfg, const char *opt, void(*func)(char *, void *), void *arg)
 Call print routine for the given option. More...
 
int config_get_option_list (struct config_file *cfg, const char *opt, struct config_strlist **list)
 Get an option and return strlist. More...
 
int config_get_option_collate (struct config_file *cfg, const char *opt, char **str)
 Get an option and collate results into string. More...
 
void config_print_func (char *line, void *arg)
 function to print to a file, use as func with config_get_option. More...
 
void config_collate_func (char *line, void *arg)
 function to collate the text strings into a strlist_head. More...
 
char * config_collate_cat (struct config_strlist *list)
 take a strlist_head list and return a malloc string. More...
 
int cfg_strlist_append (struct config_strlist_head *list, char *item)
 Append text at end of list. More...
 
int cfg_strlist_insert (struct config_strlist **head, char *item)
 Insert string into strlist. More...
 
int cfg_str2list_insert (struct config_str2list **head, char *item, char *i2)
 Insert string into str2list. More...
 
void config_delstrlist (struct config_strlist *list)
 Delete items in config string list. More...
 
void config_deldblstrlist (struct config_str2list *list)
 Delete items in config double string list. More...
 
void config_delstubs (struct config_stub *list)
 Delete items in config stub list. More...
 
time_t cfg_convert_timeval (const char *str)
 Convert 14digit to time value. More...
 
int cfg_count_numbers (const char *str)
 Count number of values in the string. More...
 
int cfg_parse_memsize (const char *str, size_t *res)
 Convert a 'nice' memory or file size into a bytecount From '100k' to 102400. More...
 
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. More...
 
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. More...
 
int cfg_condense_ports (struct config_file *cfg, int **avail)
 Get a condensed list of ports returned. More...
 
int cfg_scan_ports (int *avail, int num)
 Scan ports available. More...
 
char * fname_after_chroot (const char *fname, struct config_file *cfg, int use_chdir)
 Convert a filename to full pathname in original filesys. More...
 
char * cfg_ptr_reverse (char *str)
 Convert a ptr shorthand into a full reverse-notation PTR record. More...
 
void errinf (struct module_qstate *qstate, const char *str)
 Append text to the error info for validation. More...
 
void errinf_origin (struct module_qstate *qstate, struct sock_list *origin)
 Append text to error info: from 1.2.3.4. More...
 
void errinf_rrset (struct module_qstate *qstate, struct ub_packed_rrset_key *rr)
 Append text to error info: for RRset name type class. More...
 
void errinf_dname (struct module_qstate *qstate, const char *str, uint8_t *dname)
 Append text to error info: str dname. More...
 
char * errinf_to_str (struct module_qstate *qstate)
 Create error info in string. More...
 
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_statecfg_parser
 global config parser object used during config parsing
 

Detailed Description

This file contains functions for the config file.

Function Documentation

struct config_file* config_create ( void  )
read

Create config file structure.

Filled with default values.

Returns
: the new structure or NULL on memory error.

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::delay_close, 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::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_reuseport, 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
int config_read ( struct config_file config,
const char *  filename,
const char *  chroot 
)

Read the config file from the specified filename.

Parameters
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).
Returns
: false on error. In that case errno is set, ENOENT means file not found.

References config_read(), create_cfg_parser(), config_parser_state::errors, config_parser_state::filename, log_err(), ub_c_in, ub_c_parse(), VERB_QUERY, and verbose().

Referenced by checkconf(), config_read(), go(), run_daemon(), service_init(), and ub_ctx_config().

void config_delete ( struct config_file config)
void config_apply ( struct config_file config)

Apply config to global constants; this routine is called in single thread.

Parameters
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, config_file::min_ttl, MINIMAL_RESPONSES, and RRSET_ROUNDROBIN.

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.

Parameters
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.
Returns
0 on error (malloc or syntax error).

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::delay_close, 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, IS_NUMBER_OR_ZERO, IS_YES_OR_NO, 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, log_set_time_asc(), config_file::log_time_ascii, config_file::logfile, MAX_TTL, config_file::max_ttl, MIN_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_out_ifs, config_file::num_queries_per_thread, 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, 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_reuseport, 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, config_file::val_sig_skew_max, config_file::val_sig_skew_min, 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.

Parameters
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.
Returns
false if the option name is not supported (syntax error).

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.

Parameters
cfg,:config file
opt,:option name.
list,:list is returned here. malloced, caller must free it.
Returns
0=OK, 1=syntax error, 2=malloc failed.

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.

Parameters
cfg,:config file
opt,:option name.
str,:string. malloced, caller must free it.
Returns
0=OK, 1=syntax error, 2=malloc failed.

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.

Parameters
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.

Parameters
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.

Parameters
list,:strlist first to collate. zeroes return "".
Returns
NULL on malloc failure. Or if malloc failure happened in strlist.

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.

Parameters
list,:list head. zeroed at start.
item,:new item. malloced by caller. if NULL the insertion fails.
Returns
true on success.

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.

Parameters
head,:pointer to strlist head variable.
item,:new item. malloced by caller. If NULL the insertion fails.
Returns
: true on success.

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.

Parameters
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.
Returns
: true on success.

References config_str2list::next, config_str2list::str, and config_str2list::str2.

Referenced by cfg_parse_local_zone().

void config_delstrlist ( struct config_strlist list)
void config_deldblstrlist ( struct config_str2list list)

Delete items in config double string list.

Parameters
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.

Parameters
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().

time_t cfg_convert_timeval ( const char *  str)

Convert 14digit to time value.

Parameters
str,:string of 14 digits
Returns
time value or 0 for error.

References sldns_mktime_from_utc().

Referenced by config_set_option(), 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)*

Parameters
str,:string
Returns
: 0 on parse error, or empty string, else number of integer values in the 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.

Parameters
str,:string
res,:result is stored here, size in bytes.
Returns
: true if parsed correctly, or 0 on a parse error (and an error is logged).

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.

Parameters
cfg,:to put it in.
val,:argument strings to local-zone, "example.com nodefault".
Returns
: false on failure

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.

Parameters
str,:string in input
allow,:give true if this range is permitted.
avail,:the array from cfg.
num,:size of the array (65536).
Returns
: true if parsed correctly, or 0 on a parse error (and an error is logged).

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.

Parameters
cfg,:config file.
avail,:the available ports array is returned here.
Returns
: number of ports in array or 0 on error.

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.

Parameters
avail,:the array from cfg.
num,:size of the array (65536).
Returns
the number of ports available for use.

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.

Parameters
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.
Returns
pointer to malloced buffer which is: [chroot][chdir]fname or NULL on malloc failure.

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.

Parameters
str,:input string, "IP name"
Returns
: malloced string "reversed-ip-name PTR 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 
)
void errinf_origin ( struct module_qstate qstate,
struct sock_list origin 
)

Append text to error info: from 1.2.3.4.

Parameters
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 
)
void errinf_dname ( struct module_qstate qstate,
const char *  str,
uint8_t *  dname 
)

Append text to error info: str dname.

Parameters
qstate,:query state.
str,:explanation string
dname,:the dname.

References module_env::cfg, dname_str(), module_qstate::env, errinf(), LDNS_MAX_DOMAINLEN, 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.

Parameters
qstate,:query state.
Returns
string or NULL on malloc failure (already logged). This string is malloced and has to be freed by caller.

References dname_str(), module_qstate::errinf, LDNS_MAX_DOMAINLEN, log_err(), config_strlist::next, query_info::qclass, module_qstate::qinfo, query_info::qname, query_info::qtype, sldns_wire2str_class_buf(), sldns_wire2str_type_buf(), and config_strlist::str.

Referenced by key_cache_insert(), mesh_do_callback(), and processFinished().