config_file.h revision 295691
1295011Sandrew/* 2295011Sandrew * util/config_file.h - reads and stores the config file for unbound. 3295011Sandrew * 4295011Sandrew * Copyright (c) 2007, NLnet Labs. All rights reserved. 5295011Sandrew * 6295011Sandrew * This software is open source. 7295011Sandrew * 8295011Sandrew * Redistribution and use in source and binary forms, with or without 9295011Sandrew * modification, are permitted provided that the following conditions 10295011Sandrew * are met: 11295011Sandrew * 12295011Sandrew * Redistributions of source code must retain the above copyright notice, 13295011Sandrew * this list of conditions and the following disclaimer. 14295011Sandrew * 15295011Sandrew * Redistributions in binary form must reproduce the above copyright notice, 16295011Sandrew * this list of conditions and the following disclaimer in the documentation 17295011Sandrew * and/or other materials provided with the distribution. 18295011Sandrew * 19295011Sandrew * Neither the name of the NLNET LABS nor the names of its contributors may 20295011Sandrew * be used to endorse or promote products derived from this software without 21295011Sandrew * specific prior written permission. 22295011Sandrew * 23295011Sandrew * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24295011Sandrew * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25295011Sandrew * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26295011Sandrew * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 27295011Sandrew * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28295011Sandrew * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 29295011Sandrew * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30295011Sandrew * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31295011Sandrew * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32295011Sandrew * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33295011Sandrew * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34295011Sandrew */ 35295011Sandrew 36295011Sandrew/** 37295011Sandrew * \file 38295011Sandrew * 39295011Sandrew * This file contains functions for the config file. 40295011Sandrew */ 41295011Sandrew 42295011Sandrew#ifndef UTIL_CONFIG_FILE_H 43295011Sandrew#define UTIL_CONFIG_FILE_H 44295011Sandrewstruct config_stub; 45295011Sandrewstruct config_strlist; 46295011Sandrewstruct config_str2list; 47295011Sandrewstruct module_qstate; 48295011Sandrewstruct sock_list; 49295011Sandrewstruct ub_packed_rrset_key; 50295011Sandrew 51295011Sandrew/** 52295011Sandrew * The configuration options. 53 * Strings are malloced. 54 */ 55struct config_file { 56 /** verbosity level as specified in the config file */ 57 int verbosity; 58 59 /** statistics interval (in seconds) */ 60 int stat_interval; 61 /** if false, statistics values are reset after printing them */ 62 int stat_cumulative; 63 /** if true, the statistics are kept in greater detail */ 64 int stat_extended; 65 66 /** number of threads to create */ 67 int num_threads; 68 69 /** port on which queries are answered. */ 70 int port; 71 /** do ip4 query support. */ 72 int do_ip4; 73 /** do ip6 query support. */ 74 int do_ip6; 75 /** do udp query support. */ 76 int do_udp; 77 /** do tcp query support. */ 78 int do_tcp; 79 /** tcp upstream queries (no UDP upstream queries) */ 80 int tcp_upstream; 81 82 /** private key file for dnstcp-ssl service (enabled if not NULL) */ 83 char* ssl_service_key; 84 /** public key file for dnstcp-ssl service */ 85 char* ssl_service_pem; 86 /** port on which to provide ssl service */ 87 int ssl_port; 88 /** if outgoing tcp connections use SSL */ 89 int ssl_upstream; 90 91 /** outgoing port range number of ports (per thread) */ 92 int outgoing_num_ports; 93 /** number of outgoing tcp buffers per (per thread) */ 94 size_t outgoing_num_tcp; 95 /** number of incoming tcp buffers per (per thread) */ 96 size_t incoming_num_tcp; 97 /** allowed udp port numbers, array with 0 if not allowed */ 98 int* outgoing_avail_ports; 99 100 /** EDNS buffer size to use */ 101 size_t edns_buffer_size; 102 /** number of bytes buffer size for DNS messages */ 103 size_t msg_buffer_size; 104 /** size of the message cache */ 105 size_t msg_cache_size; 106 /** slabs in the message cache. */ 107 size_t msg_cache_slabs; 108 /** number of queries every thread can service */ 109 size_t num_queries_per_thread; 110 /** number of msec to wait before items can be jostled out */ 111 size_t jostle_time; 112 /** size of the rrset cache */ 113 size_t rrset_cache_size; 114 /** slabs in the rrset cache */ 115 size_t rrset_cache_slabs; 116 /** host cache ttl in seconds */ 117 int host_ttl; 118 /** number of slabs in the infra host cache */ 119 size_t infra_cache_slabs; 120 /** max number of hosts in the infra cache */ 121 size_t infra_cache_numhosts; 122 /** min value for infra cache rtt */ 123 int infra_cache_min_rtt; 124 /** delay close of udp-timeouted ports, if 0 no delayclose. in msec */ 125 int delay_close; 126 127 /** the target fetch policy for the iterator */ 128 char* target_fetch_policy; 129 130 /** automatic interface for incoming messages. Uses ipv6 remapping, 131 * and recvmsg/sendmsg ancillary data to detect interfaces, boolean */ 132 int if_automatic; 133 /** SO_RCVBUF size to set on port 53 UDP socket */ 134 size_t so_rcvbuf; 135 /** SO_SNDBUF size to set on port 53 UDP socket */ 136 size_t so_sndbuf; 137 /** SO_REUSEPORT requested on port 53 sockets */ 138 int so_reuseport; 139 /** IP_TRANSPARENT socket option requested on port 53 sockets */ 140 int ip_transparent; 141 142 /** number of interfaces to open. If 0 default all interfaces. */ 143 int num_ifs; 144 /** interface description strings (IP addresses) */ 145 char **ifs; 146 147 /** number of outgoing interfaces to open. 148 * If 0 default all interfaces. */ 149 int num_out_ifs; 150 /** outgoing interface description strings (IP addresses) */ 151 char **out_ifs; 152 153 /** the root hints */ 154 struct config_strlist* root_hints; 155 /** the stub definitions, linked list */ 156 struct config_stub* stubs; 157 /** the forward zone definitions, linked list */ 158 struct config_stub* forwards; 159 /** list of donotquery addresses, linked list */ 160 struct config_strlist* donotqueryaddrs; 161 /** list of access control entries, linked list */ 162 struct config_str2list* acls; 163 /** use default localhost donotqueryaddr entries */ 164 int donotquery_localhost; 165 166 /** harden against very small edns buffer sizes */ 167 int harden_short_bufsize; 168 /** harden against very large query sizes */ 169 int harden_large_queries; 170 /** harden against spoofed glue (out of zone data) */ 171 int harden_glue; 172 /** harden against receiving no DNSSEC data for trust anchor */ 173 int harden_dnssec_stripped; 174 /** harden against queries that fall under known nxdomain names */ 175 int harden_below_nxdomain; 176 /** harden the referral path, query for NS,A,AAAA and validate */ 177 int harden_referral_path; 178 /** harden against algorithm downgrade */ 179 int harden_algo_downgrade; 180 /** use 0x20 bits in query as random ID bits */ 181 int use_caps_bits_for_id; 182 /** 0x20 whitelist, domains that do not use capsforid */ 183 struct config_strlist* caps_whitelist; 184 /** strip away these private addrs from answers, no DNS Rebinding */ 185 struct config_strlist* private_address; 186 /** allow domain (and subdomains) to use private address space */ 187 struct config_strlist* private_domain; 188 /** what threshold for unwanted action. */ 189 size_t unwanted_threshold; 190 /** the number of seconds maximal TTL used for RRsets and messages */ 191 int max_ttl; 192 /** the number of seconds minimum TTL used for RRsets and messages */ 193 int min_ttl; 194 /** the number of seconds maximal negative TTL for SOA in auth */ 195 int max_negative_ttl; 196 /** if prefetching of messages should be performed. */ 197 int prefetch; 198 /** if prefetching of DNSKEYs should be performed. */ 199 int prefetch_key; 200 201 /** chrootdir, if not "" or chroot will be done */ 202 char* chrootdir; 203 /** username to change to, if not "". */ 204 char* username; 205 /** working directory */ 206 char* directory; 207 /** filename to log to. */ 208 char* logfile; 209 /** pidfile to write pid to. */ 210 char* pidfile; 211 212 /** should log messages be sent to syslogd */ 213 int use_syslog; 214 /** log timestamp in ascii UTC */ 215 int log_time_ascii; 216 /** log queries with one line per query */ 217 int log_queries; 218 219 /** do not report identity (id.server, hostname.bind) */ 220 int hide_identity; 221 /** do not report version (version.server, version.bind) */ 222 int hide_version; 223 /** identity, hostname is returned if "". */ 224 char* identity; 225 /** version, package version returned if "". */ 226 char* version; 227 228 /** the module configuration string */ 229 char* module_conf; 230 231 /** files with trusted DS and DNSKEYs in zonefile format, list */ 232 struct config_strlist* trust_anchor_file_list; 233 /** list of trustanchor keys, linked list */ 234 struct config_strlist* trust_anchor_list; 235 /** files with 5011 autotrust tracked keys */ 236 struct config_strlist* auto_trust_anchor_file_list; 237 /** files with trusted DNSKEYs in named.conf format, list */ 238 struct config_strlist* trusted_keys_file_list; 239 /** DLV anchor file */ 240 char* dlv_anchor_file; 241 /** DLV anchor inline */ 242 struct config_strlist* dlv_anchor_list; 243 /** insecure domain list */ 244 struct config_strlist* domain_insecure; 245 246 /** if not 0, this value is the validation date for RRSIGs */ 247 int32_t val_date_override; 248 /** the minimum for signature clock skew */ 249 int32_t val_sig_skew_min; 250 /** the maximum for signature clock skew */ 251 int32_t val_sig_skew_max; 252 /** this value sets the number of seconds before revalidating bogus */ 253 int bogus_ttl; 254 /** should validator clean additional section for secure msgs */ 255 int val_clean_additional; 256 /** log bogus messages by the validator */ 257 int val_log_level; 258 /** squelch val_log_level to log - this is library goes to callback */ 259 int val_log_squelch; 260 /** should validator allow bogus messages to go through */ 261 int val_permissive_mode; 262 /** ignore the CD flag in incoming queries and refuse them bogus data */ 263 int ignore_cd; 264 /** nsec3 maximum iterations per key size, string */ 265 char* val_nsec3_key_iterations; 266 /** autotrust add holddown time, in seconds */ 267 unsigned int add_holddown; 268 /** autotrust del holddown time, in seconds */ 269 unsigned int del_holddown; 270 /** autotrust keep_missing time, in seconds. 0 is forever. */ 271 unsigned int keep_missing; 272 /** permit small holddown values, allowing 5011 rollover very fast */ 273 int permit_small_holddown; 274 275 /** size of the key cache */ 276 size_t key_cache_size; 277 /** slabs in the key cache. */ 278 size_t key_cache_slabs; 279 /** size of the neg cache */ 280 size_t neg_cache_size; 281 282 /** local zones config */ 283 struct config_str2list* local_zones; 284 /** local zones nodefault list */ 285 struct config_strlist* local_zones_nodefault; 286 /** local data RRs configured */ 287 struct config_strlist* local_data; 288 /** unblock lan zones (reverse lookups for AS112 zones) */ 289 int unblock_lan_zones; 290 /** insecure lan zones (don't validate AS112 zones) */ 291 int insecure_lan_zones; 292 293 /** remote control section. enable toggle. */ 294 int remote_control_enable; 295 /** the interfaces the remote control should listen on */ 296 struct config_strlist* control_ifs; 297 /** port number for the control port */ 298 int control_port; 299 /** use certificates for remote control */ 300 int remote_control_use_cert; 301 /** private key file for server */ 302 char* server_key_file; 303 /** certificate file for server */ 304 char* server_cert_file; 305 /** private key file for unbound-control */ 306 char* control_key_file; 307 /** certificate file for unbound-control */ 308 char* control_cert_file; 309 310 /** Python script file */ 311 char* python_script; 312 313 /** daemonize, i.e. fork into the background. */ 314 int do_daemonize; 315 316 /* minimal response when positive answer */ 317 int minimal_responses; 318 319 /* RRSet roundrobin */ 320 int rrset_roundrobin; 321 322 /* maximum UDP response size */ 323 size_t max_udp_size; 324 325 /* DNS64 prefix */ 326 char* dns64_prefix; 327 328 /* Synthetize all AAAA record despite the presence of an authoritative one */ 329 int dns64_synthall; 330 331 /** true to enable dnstap support */ 332 int dnstap; 333 /** dnstap socket path */ 334 char* dnstap_socket_path; 335 /** true to send "identity" via dnstap */ 336 int dnstap_send_identity; 337 /** true to send "version" via dnstap */ 338 int dnstap_send_version; 339 /** dnstap "identity", hostname is used if "". */ 340 char* dnstap_identity; 341 /** dnstap "version", package version is used if "". */ 342 char* dnstap_version; 343 344 /** true to log dnstap RESOLVER_QUERY message events */ 345 int dnstap_log_resolver_query_messages; 346 /** true to log dnstap RESOLVER_RESPONSE message events */ 347 int dnstap_log_resolver_response_messages; 348 /** true to log dnstap CLIENT_QUERY message events */ 349 int dnstap_log_client_query_messages; 350 /** true to log dnstap CLIENT_RESPONSE message events */ 351 int dnstap_log_client_response_messages; 352 /** true to log dnstap FORWARDER_QUERY message events */ 353 int dnstap_log_forwarder_query_messages; 354 /** true to log dnstap FORWARDER_RESPONSE message events */ 355 int dnstap_log_forwarder_response_messages; 356 357 /** ratelimit 0 is off, otherwise qps (unless overridden) */ 358 int ratelimit; 359 /** number of slabs for ratelimit cache */ 360 size_t ratelimit_slabs; 361 /** memory size in bytes for ratelimit cache */ 362 size_t ratelimit_size; 363 /** ratelimits for domain (exact match) */ 364 struct config_str2list* ratelimit_for_domain; 365 /** ratelimits below domain */ 366 struct config_str2list* ratelimit_below_domain; 367 /** ratelimit factor, 0 blocks all, 10 allows 1/10 of traffic */ 368 int ratelimit_factor; 369 /** minimise outgoing QNAME and hide original QTYPE if possible */ 370 int qname_minimisation; 371}; 372 373/** from cfg username, after daemonise setup performed */ 374extern uid_t cfg_uid; 375/** from cfg username, after daemonise setup performed */ 376extern gid_t cfg_gid; 377/** debug and enable small timeouts */ 378extern int autr_permit_small_holddown; 379 380/** 381 * Stub config options 382 */ 383struct config_stub { 384 /** next in list */ 385 struct config_stub* next; 386 /** domain name (in text) of the stub apex domain */ 387 char* name; 388 /** list of stub nameserver hosts (domain name) */ 389 struct config_strlist* hosts; 390 /** list of stub nameserver addresses (IP address) */ 391 struct config_strlist* addrs; 392 /** if stub-prime is set */ 393 int isprime; 394 /** if forward-first is set (failover to without if fails) */ 395 int isfirst; 396}; 397 398/** 399 * List of strings for config options 400 */ 401struct config_strlist { 402 /** next item in list */ 403 struct config_strlist* next; 404 /** config option string */ 405 char* str; 406}; 407 408/** 409 * List of two strings for config options 410 */ 411struct config_str2list { 412 /** next item in list */ 413 struct config_str2list* next; 414 /** first string */ 415 char* str; 416 /** second string */ 417 char* str2; 418}; 419 420/** List head for strlist processing, used for append operation. */ 421struct config_strlist_head { 422 /** first in list of text items */ 423 struct config_strlist* first; 424 /** last in list of text items */ 425 struct config_strlist* last; 426}; 427 428/** 429 * Create config file structure. Filled with default values. 430 * @return: the new structure or NULL on memory error. 431 */ 432struct config_file* config_create(void); 433 434/** 435 * Create config file structure for library use. Filled with default values. 436 * @return: the new structure or NULL on memory error. 437 */ 438struct config_file* config_create_forlib(void); 439 440/** 441 * Read the config file from the specified filename. 442 * @param config: where options are stored into, must be freshly created. 443 * @param filename: name of configfile. If NULL nothing is done. 444 * @param chroot: if not NULL, the chroot dir currently in use (for include). 445 * @return: false on error. In that case errno is set, ENOENT means 446 * file not found. 447 */ 448int config_read(struct config_file* config, const char* filename, 449 const char* chroot); 450 451/** 452 * Destroy the config file structure. 453 * @param config: to delete. 454 */ 455void config_delete(struct config_file* config); 456 457/** 458 * Apply config to global constants; this routine is called in single thread. 459 * @param config: to apply. Side effect: global constants change. 460 */ 461void config_apply(struct config_file* config); 462 463/** 464 * Find username, sets cfg_uid and cfg_gid. 465 * @param config: the config structure. 466 */ 467void config_lookup_uid(struct config_file* config); 468 469/** 470 * Set the given keyword to the given value. 471 * @param config: where to store config 472 * @param option: option name, including the ':' character. 473 * @param value: value, this string is copied if needed, or parsed. 474 * The caller owns the value string. 475 * @return 0 on error (malloc or syntax error). 476 */ 477int config_set_option(struct config_file* config, const char* option, 478 const char* value); 479 480/** 481 * Call print routine for the given option. 482 * @param cfg: config. 483 * @param opt: option name without trailing :. 484 * This is different from config_set_option. 485 * @param func: print func, called as (str, arg) for every data element. 486 * @param arg: user argument for print func. 487 * @return false if the option name is not supported (syntax error). 488 */ 489int config_get_option(struct config_file* cfg, const char* opt, 490 void (*func)(char*,void*), void* arg); 491 492/** 493 * Get an option and return strlist 494 * @param cfg: config file 495 * @param opt: option name. 496 * @param list: list is returned here. malloced, caller must free it. 497 * @return 0=OK, 1=syntax error, 2=malloc failed. 498 */ 499int config_get_option_list(struct config_file* cfg, const char* opt, 500 struct config_strlist** list); 501 502/** 503 * Get an option and collate results into string 504 * @param cfg: config file 505 * @param opt: option name. 506 * @param str: string. malloced, caller must free it. 507 * @return 0=OK, 1=syntax error, 2=malloc failed. 508 */ 509int config_get_option_collate(struct config_file* cfg, const char* opt, 510 char** str); 511 512/** 513 * function to print to a file, use as func with config_get_option. 514 * @param line: text to print. \n appended. 515 * @param arg: pass a FILE*, like stdout. 516 */ 517void config_print_func(char* line, void* arg); 518 519/** 520 * function to collate the text strings into a strlist_head. 521 * @param line: text to append. 522 * @param arg: pass a strlist_head structure. zeroed on start. 523 */ 524void config_collate_func(char* line, void* arg); 525 526/** 527 * take a strlist_head list and return a malloc string. separated with newline. 528 * @param list: strlist first to collate. zeroes return "". 529 * @return NULL on malloc failure. Or if malloc failure happened in strlist. 530 */ 531char* config_collate_cat(struct config_strlist* list); 532 533/** 534 * Append text at end of list. 535 * @param list: list head. zeroed at start. 536 * @param item: new item. malloced by caller. if NULL the insertion fails. 537 * @return true on success. 538 */ 539int cfg_strlist_append(struct config_strlist_head* list, char* item); 540 541/** 542 * Insert string into strlist. 543 * @param head: pointer to strlist head variable. 544 * @param item: new item. malloced by caller. If NULL the insertion fails. 545 * @return: true on success. 546 */ 547int cfg_strlist_insert(struct config_strlist** head, char* item); 548 549/** 550 * Insert string into str2list. 551 * @param head: pointer to str2list head variable. 552 * @param item: new item. malloced by caller. If NULL the insertion fails. 553 * @param i2: 2nd string, malloced by caller. If NULL the insertion fails. 554 * @return: true on success. 555 */ 556int cfg_str2list_insert(struct config_str2list** head, char* item, char* i2); 557 558/** 559 * Delete items in config string list. 560 * @param list: list. 561 */ 562void config_delstrlist(struct config_strlist* list); 563 564/** 565 * Delete items in config double string list. 566 * @param list: list. 567 */ 568void config_deldblstrlist(struct config_str2list* list); 569 570/** 571 * Delete items in config stub list. 572 * @param list: list. 573 */ 574void config_delstubs(struct config_stub* list); 575 576/** 577 * Convert 14digit to time value 578 * @param str: string of 14 digits 579 * @return time value or 0 for error. 580 */ 581time_t cfg_convert_timeval(const char* str); 582 583/** 584 * Count number of values in the string. 585 * format ::= (sp num)+ sp 586 * num ::= [-](0-9)+ 587 * sp ::= (space|tab)* 588 * 589 * @param str: string 590 * @return: 0 on parse error, or empty string, else 591 * number of integer values in the string. 592 */ 593int cfg_count_numbers(const char* str); 594 595/** 596 * Convert a 'nice' memory or file size into a bytecount 597 * From '100k' to 102400. and so on. Understands kKmMgG. 598 * k=1024, m=1024*1024, g=1024*1024*1024. 599 * @param str: string 600 * @param res: result is stored here, size in bytes. 601 * @return: true if parsed correctly, or 0 on a parse error (and an error 602 * is logged). 603 */ 604int cfg_parse_memsize(const char* str, size_t* res); 605 606/** 607 * Parse local-zone directive into two strings and register it in the config. 608 * @param cfg: to put it in. 609 * @param val: argument strings to local-zone, "example.com nodefault". 610 * @return: false on failure 611 */ 612int cfg_parse_local_zone(struct config_file* cfg, const char* val); 613 614/** 615 * Mark "number" or "low-high" as available or not in ports array. 616 * @param str: string in input 617 * @param allow: give true if this range is permitted. 618 * @param avail: the array from cfg. 619 * @param num: size of the array (65536). 620 * @return: true if parsed correctly, or 0 on a parse error (and an error 621 * is logged). 622 */ 623int cfg_mark_ports(const char* str, int allow, int* avail, int num); 624 625/** 626 * Get a condensed list of ports returned. allocated. 627 * @param cfg: config file. 628 * @param avail: the available ports array is returned here. 629 * @return: number of ports in array or 0 on error. 630 */ 631int cfg_condense_ports(struct config_file* cfg, int** avail); 632 633/** 634 * Scan ports available 635 * @param avail: the array from cfg. 636 * @param num: size of the array (65536). 637 * @return the number of ports available for use. 638 */ 639int cfg_scan_ports(int* avail, int num); 640 641/** 642 * Convert a filename to full pathname in original filesys 643 * @param fname: the path name to convert. 644 * Must not be null or empty. 645 * @param cfg: config struct for chroot and chdir (if set). 646 * @param use_chdir: if false, only chroot is applied. 647 * @return pointer to malloced buffer which is: [chroot][chdir]fname 648 * or NULL on malloc failure. 649 */ 650char* fname_after_chroot(const char* fname, struct config_file* cfg, 651 int use_chdir); 652 653/** 654 * Convert a ptr shorthand into a full reverse-notation PTR record. 655 * @param str: input string, "IP name" 656 * @return: malloced string "reversed-ip-name PTR name" 657 */ 658char* cfg_ptr_reverse(char* str); 659 660/** 661 * Append text to the error info for validation. 662 * @param qstate: query state. 663 * @param str: copied into query region and appended. 664 * Failures to allocate are logged. 665 */ 666void errinf(struct module_qstate* qstate, const char* str); 667 668/** 669 * Append text to error info: from 1.2.3.4 670 * @param qstate: query state. 671 * @param origin: sock list with origin of trouble. 672 * Every element added. 673 * If NULL: nothing is added. 674 * if 0len element: 'from cache' is added. 675 */ 676void errinf_origin(struct module_qstate* qstate, struct sock_list *origin); 677 678/** 679 * Append text to error info: for RRset name type class 680 * @param qstate: query state. 681 * @param rr: rrset_key. 682 */ 683void errinf_rrset(struct module_qstate* qstate, struct ub_packed_rrset_key *rr); 684 685/** 686 * Append text to error info: str dname 687 * @param qstate: query state. 688 * @param str: explanation string 689 * @param dname: the dname. 690 */ 691void errinf_dname(struct module_qstate* qstate, const char* str, 692 uint8_t* dname); 693 694/** 695 * Create error info in string 696 * @param qstate: query state. 697 * @return string or NULL on malloc failure (already logged). 698 * This string is malloced and has to be freed by caller. 699 */ 700char* errinf_to_str(struct module_qstate* qstate); 701 702/** 703 * Used during options parsing 704 */ 705struct config_parser_state { 706 /** name of file being parser */ 707 char* filename; 708 /** line number in the file, starts at 1 */ 709 int line; 710 /** number of errors encountered */ 711 int errors; 712 /** the result of parsing is stored here. */ 713 struct config_file* cfg; 714 /** the current chroot dir (or NULL if none) */ 715 const char* chroot; 716}; 717 718/** global config parser object used during config parsing */ 719extern struct config_parser_state* cfg_parser; 720/** init lex state */ 721void init_cfg_parse(void); 722/** lex in file */ 723extern FILE* ub_c_in; 724/** lex out file */ 725extern FILE* ub_c_out; 726/** the yacc lex generated parse function */ 727int ub_c_parse(void); 728/** the lexer function */ 729int ub_c_lex(void); 730/** wrap function */ 731int ub_c_wrap(void); 732/** parsing helpers: print error with file and line numbers */ 733void ub_c_error(const char* msg); 734/** parsing helpers: print error with file and line numbers */ 735void ub_c_error_msg(const char* fmt, ...) ATTR_FORMAT(printf, 1, 2); 736 737#ifdef UB_ON_WINDOWS 738/** 739 * Obtain registry string (if it exists). 740 * @param key: key string 741 * @param name: name of value to fetch. 742 * @return malloced string with the result or NULL if it did not 743 * exist on an error (logged with log_err) was encountered. 744 */ 745char* w_lookup_reg_str(const char* key, const char* name); 746 747/** Modify directory in options for module file name */ 748void w_config_adjust_directory(struct config_file* cfg); 749#endif /* UB_ON_WINDOWS */ 750 751#endif /* UTIL_CONFIG_FILE_H */ 752