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_parser_state
 Used during options parsing. More...

Functions

struct config_fileconfig_create ()
 Create config file structure.
struct config_fileconfig_create_forlib ()
 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 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 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 (  )  [read]

Create config file structure.

Filled with default values.

Returns:
: the new structure or NULL on memory error.

References config_file::acls, 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::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, error_exit(), config_file::forwards, 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::incoming_num_tcp, config_file::infra_cache_lame_size, config_file::infra_cache_numhosts, config_file::infra_cache_slabs, init_outgoing_availports(), config_file::jostle_time, config_file::key_cache_size, config_file::key_cache_slabs, config_file::lame_ttl, config_file::local_data, config_file::local_zones, config_file::local_zones_nodefault, 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::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::stat_cumulative, config_file::stat_extended, config_file::stat_interval, 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::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_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 (  )  [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 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  ) 

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 log_set_time_asc(), config_file::log_time_ascii, config_file::max_ttl, MAX_TTL, config_file::min_ttl, and 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.

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::bogus_ttl, cfg_convert_timeval(), cfg_mark_ports(), cfg_parse_local_zone(), cfg_parse_memsize(), cfg_strlist_insert(), config_file::control_cert_file, config_file::control_ifs, config_file::control_key_file, config_file::control_port, config_file::dlv_anchor_file, config_file::dlv_anchor_list, 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::harden_dnssec_stripped, config_file::harden_glue, config_file::harden_large_queries, config_file::harden_referral_path, config_file::harden_short_bufsize, config_file::host_ttl, config_file::incoming_num_tcp, config_file::infra_cache_lame_size, config_file::infra_cache_numhosts, config_file::infra_cache_slabs, IS_NONZERO_NUMBER, IS_NUMBER_OR_ZERO, IS_POW2_NUMBER, IS_YES_OR_NO, config_file::jostle_time, config_file::key_cache_size, config_file::key_cache_slabs, config_file::lame_ttl, config_file::local_data, 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::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::stat_extended, config_file::stat_interval, config_file::target_fetch_policy, config_file::trust_anchor_file_list, config_file::trust_anchor_list, config_file::trusted_keys_file_list, config_file::unwanted_threshold, config_file::use_syslog, config_file::val_clean_additional, config_file::val_date_override, config_file::val_log_level, config_file::val_nsec3_key_iterations, config_file::val_permissive_mode, and config_file::verbosity.

Referenced by ub_ctx_set_option().

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(), 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  ) 

Delete items in config string list.

Parameters:
list,: list.

References config_strlist::next, and config_strlist::str.

Referenced by config_delete(), config_delstubs(), and lz_freeup_cfg().

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

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

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)*

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(), config_set_option(), 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().


Generated on Mon Nov 16 11:51:37 2009 for unbound by  doxygen 1.5.9