1 /* 2 * util/config_file.h - reads and stores the config file for unbound. 3 * 4 * Copyright (c) 2007, NLnet Labs. All rights reserved. 5 * 6 * This software is open source. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 12 * Redistributions of source code must retain the above copyright notice, 13 * this list of conditions and the following disclaimer. 14 * 15 * Redistributions in binary form must reproduce the above copyright notice, 16 * this list of conditions and the following disclaimer in the documentation 17 * and/or other materials provided with the distribution. 18 * 19 * Neither the name of the NLNET LABS nor the names of its contributors may 20 * be used to endorse or promote products derived from this software without 21 * specific prior written permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 27 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 29 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 */ 35 36 /** 37 * \file 38 * 39 * This file contains functions for the config file. 40 */ 41 42 #ifndef UTIL_CONFIG_FILE_H 43 #define UTIL_CONFIG_FILE_H 44 struct config_stub; 45 struct config_strlist; 46 struct config_str2list; 47 struct module_qstate; 48 struct sock_list; 49 struct ub_packed_rrset_key; 50 51 /** 52 * The configuration options. 53 * Strings are malloced. 54 */ 55 struct 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 273 /** size of the key cache */ 274 size_t key_cache_size; 275 /** slabs in the key cache. */ 276 size_t key_cache_slabs; 277 /** size of the neg cache */ 278 size_t neg_cache_size; 279 280 /** local zones config */ 281 struct config_str2list* local_zones; 282 /** local zones nodefault list */ 283 struct config_strlist* local_zones_nodefault; 284 /** local data RRs configged */ 285 struct config_strlist* local_data; 286 /** unblock lan zones (reverse lookups for 10/8 and so on) */ 287 int unblock_lan_zones; 288 289 /** remote control section. enable toggle. */ 290 int remote_control_enable; 291 /** the interfaces the remote control should listen on */ 292 struct config_strlist* control_ifs; 293 /** port number for the control port */ 294 int control_port; 295 /** use certificates for remote control */ 296 int remote_control_use_cert; 297 /** private key file for server */ 298 char* server_key_file; 299 /** certificate file for server */ 300 char* server_cert_file; 301 /** private key file for unbound-control */ 302 char* control_key_file; 303 /** certificate file for unbound-control */ 304 char* control_cert_file; 305 306 /** Python script file */ 307 char* python_script; 308 309 /** daemonize, i.e. fork into the background. */ 310 int do_daemonize; 311 312 /* minimal response when positive answer */ 313 int minimal_responses; 314 315 /* RRSet roundrobin */ 316 int rrset_roundrobin; 317 318 /* maximum UDP response size */ 319 size_t max_udp_size; 320 321 /* DNS64 prefix */ 322 char* dns64_prefix; 323 324 /* Synthetize all AAAA record despite the presence of an authoritative one */ 325 int dns64_synthall; 326 327 /** true to enable dnstap support */ 328 int dnstap; 329 /** dnstap socket path */ 330 char* dnstap_socket_path; 331 /** true to send "identity" via dnstap */ 332 int dnstap_send_identity; 333 /** true to send "version" via dnstap */ 334 int dnstap_send_version; 335 /** dnstap "identity", hostname is used if "". */ 336 char* dnstap_identity; 337 /** dnstap "version", package version is used if "". */ 338 char* dnstap_version; 339 340 /** true to log dnstap RESOLVER_QUERY message events */ 341 int dnstap_log_resolver_query_messages; 342 /** true to log dnstap RESOLVER_RESPONSE message events */ 343 int dnstap_log_resolver_response_messages; 344 /** true to log dnstap CLIENT_QUERY message events */ 345 int dnstap_log_client_query_messages; 346 /** true to log dnstap CLIENT_RESPONSE message events */ 347 int dnstap_log_client_response_messages; 348 /** true to log dnstap FORWARDER_QUERY message events */ 349 int dnstap_log_forwarder_query_messages; 350 /** true to log dnstap FORWARDER_RESPONSE message events */ 351 int dnstap_log_forwarder_response_messages; 352 353 /** ratelimit 0 is off, otherwise qps (unless overridden) */ 354 int ratelimit; 355 /** number of slabs for ratelimit cache */ 356 size_t ratelimit_slabs; 357 /** memory size in bytes for ratelimit cache */ 358 size_t ratelimit_size; 359 /** ratelimits for domain (exact match) */ 360 struct config_str2list* ratelimit_for_domain; 361 /** ratelimits below domain */ 362 struct config_str2list* ratelimit_below_domain; 363 /** ratelimit factor, 0 blocks all, 10 allows 1/10 of traffic */ 364 int ratelimit_factor; 365 }; 366 367 /** from cfg username, after daemonise setup performed */ 368 extern uid_t cfg_uid; 369 /** from cfg username, after daemonise setup performed */ 370 extern gid_t cfg_gid; 371 372 /** 373 * Stub config options 374 */ 375 struct config_stub { 376 /** next in list */ 377 struct config_stub* next; 378 /** domain name (in text) of the stub apex domain */ 379 char* name; 380 /** list of stub nameserver hosts (domain name) */ 381 struct config_strlist* hosts; 382 /** list of stub nameserver addresses (IP address) */ 383 struct config_strlist* addrs; 384 /** if stub-prime is set */ 385 int isprime; 386 /** if forward-first is set (failover to without if fails) */ 387 int isfirst; 388 }; 389 390 /** 391 * List of strings for config options 392 */ 393 struct config_strlist { 394 /** next item in list */ 395 struct config_strlist* next; 396 /** config option string */ 397 char* str; 398 }; 399 400 /** 401 * List of two strings for config options 402 */ 403 struct config_str2list { 404 /** next item in list */ 405 struct config_str2list* next; 406 /** first string */ 407 char* str; 408 /** second string */ 409 char* str2; 410 }; 411 412 /** List head for strlist processing, used for append operation. */ 413 struct config_strlist_head { 414 /** first in list of text items */ 415 struct config_strlist* first; 416 /** last in list of text items */ 417 struct config_strlist* last; 418 }; 419 420 /** 421 * Create config file structure. Filled with default values. 422 * @return: the new structure or NULL on memory error. 423 */ 424 struct config_file* config_create(void); 425 426 /** 427 * Create config file structure for library use. Filled with default values. 428 * @return: the new structure or NULL on memory error. 429 */ 430 struct config_file* config_create_forlib(void); 431 432 /** 433 * Read the config file from the specified filename. 434 * @param config: where options are stored into, must be freshly created. 435 * @param filename: name of configfile. If NULL nothing is done. 436 * @param chroot: if not NULL, the chroot dir currently in use (for include). 437 * @return: false on error. In that case errno is set, ENOENT means 438 * file not found. 439 */ 440 int config_read(struct config_file* config, const char* filename, 441 const char* chroot); 442 443 /** 444 * Destroy the config file structure. 445 * @param config: to delete. 446 */ 447 void config_delete(struct config_file* config); 448 449 /** 450 * Apply config to global constants; this routine is called in single thread. 451 * @param config: to apply. Side effect: global constants change. 452 */ 453 void config_apply(struct config_file* config); 454 455 /** 456 * Find username, sets cfg_uid and cfg_gid. 457 * @param config: the config structure. 458 */ 459 void config_lookup_uid(struct config_file* config); 460 461 /** 462 * Set the given keyword to the given value. 463 * @param config: where to store config 464 * @param option: option name, including the ':' character. 465 * @param value: value, this string is copied if needed, or parsed. 466 * The caller owns the value string. 467 * @return 0 on error (malloc or syntax error). 468 */ 469 int config_set_option(struct config_file* config, const char* option, 470 const char* value); 471 472 /** 473 * Call print routine for the given option. 474 * @param cfg: config. 475 * @param opt: option name without trailing :. 476 * This is different from config_set_option. 477 * @param func: print func, called as (str, arg) for every data element. 478 * @param arg: user argument for print func. 479 * @return false if the option name is not supported (syntax error). 480 */ 481 int config_get_option(struct config_file* cfg, const char* opt, 482 void (*func)(char*,void*), void* arg); 483 484 /** 485 * Get an option and return strlist 486 * @param cfg: config file 487 * @param opt: option name. 488 * @param list: list is returned here. malloced, caller must free it. 489 * @return 0=OK, 1=syntax error, 2=malloc failed. 490 */ 491 int config_get_option_list(struct config_file* cfg, const char* opt, 492 struct config_strlist** list); 493 494 /** 495 * Get an option and collate results into string 496 * @param cfg: config file 497 * @param opt: option name. 498 * @param str: string. malloced, caller must free it. 499 * @return 0=OK, 1=syntax error, 2=malloc failed. 500 */ 501 int config_get_option_collate(struct config_file* cfg, const char* opt, 502 char** str); 503 504 /** 505 * function to print to a file, use as func with config_get_option. 506 * @param line: text to print. \n appended. 507 * @param arg: pass a FILE*, like stdout. 508 */ 509 void config_print_func(char* line, void* arg); 510 511 /** 512 * function to collate the text strings into a strlist_head. 513 * @param line: text to append. 514 * @param arg: pass a strlist_head structure. zeroed on start. 515 */ 516 void config_collate_func(char* line, void* arg); 517 518 /** 519 * take a strlist_head list and return a malloc string. separated with newline. 520 * @param list: strlist first to collate. zeroes return "". 521 * @return NULL on malloc failure. Or if malloc failure happened in strlist. 522 */ 523 char* config_collate_cat(struct config_strlist* list); 524 525 /** 526 * Append text at end of list. 527 * @param list: list head. zeroed at start. 528 * @param item: new item. malloced by caller. if NULL the insertion fails. 529 * @return true on success. 530 */ 531 int cfg_strlist_append(struct config_strlist_head* list, char* item); 532 533 /** 534 * Insert string into strlist. 535 * @param head: pointer to strlist head variable. 536 * @param item: new item. malloced by caller. If NULL the insertion fails. 537 * @return: true on success. 538 */ 539 int cfg_strlist_insert(struct config_strlist** head, char* item); 540 541 /** 542 * Insert string into str2list. 543 * @param head: pointer to str2list head variable. 544 * @param item: new item. malloced by caller. If NULL the insertion fails. 545 * @param i2: 2nd string, malloced by caller. If NULL the insertion fails. 546 * @return: true on success. 547 */ 548 int cfg_str2list_insert(struct config_str2list** head, char* item, char* i2); 549 550 /** 551 * Delete items in config string list. 552 * @param list: list. 553 */ 554 void config_delstrlist(struct config_strlist* list); 555 556 /** 557 * Delete items in config double string list. 558 * @param list: list. 559 */ 560 void config_deldblstrlist(struct config_str2list* list); 561 562 /** 563 * Delete items in config stub list. 564 * @param list: list. 565 */ 566 void config_delstubs(struct config_stub* list); 567 568 /** 569 * Convert 14digit to time value 570 * @param str: string of 14 digits 571 * @return time value or 0 for error. 572 */ 573 time_t cfg_convert_timeval(const char* str); 574 575 /** 576 * Count number of values in the string. 577 * format ::= (sp num)+ sp 578 * num ::= [-](0-9)+ 579 * sp ::= (space|tab)* 580 * 581 * @param str: string 582 * @return: 0 on parse error, or empty string, else 583 * number of integer values in the string. 584 */ 585 int cfg_count_numbers(const char* str); 586 587 /** 588 * Convert a 'nice' memory or file size into a bytecount 589 * From '100k' to 102400. and so on. Understands kKmMgG. 590 * k=1024, m=1024*1024, g=1024*1024*1024. 591 * @param str: string 592 * @param res: result is stored here, size in bytes. 593 * @return: true if parsed correctly, or 0 on a parse error (and an error 594 * is logged). 595 */ 596 int cfg_parse_memsize(const char* str, size_t* res); 597 598 /** 599 * Parse local-zone directive into two strings and register it in the config. 600 * @param cfg: to put it in. 601 * @param val: argument strings to local-zone, "example.com nodefault". 602 * @return: false on failure 603 */ 604 int cfg_parse_local_zone(struct config_file* cfg, const char* val); 605 606 /** 607 * Mark "number" or "low-high" as available or not in ports array. 608 * @param str: string in input 609 * @param allow: give true if this range is permitted. 610 * @param avail: the array from cfg. 611 * @param num: size of the array (65536). 612 * @return: true if parsed correctly, or 0 on a parse error (and an error 613 * is logged). 614 */ 615 int cfg_mark_ports(const char* str, int allow, int* avail, int num); 616 617 /** 618 * Get a condensed list of ports returned. allocated. 619 * @param cfg: config file. 620 * @param avail: the available ports array is returned here. 621 * @return: number of ports in array or 0 on error. 622 */ 623 int cfg_condense_ports(struct config_file* cfg, int** avail); 624 625 /** 626 * Scan ports available 627 * @param avail: the array from cfg. 628 * @param num: size of the array (65536). 629 * @return the number of ports available for use. 630 */ 631 int cfg_scan_ports(int* avail, int num); 632 633 /** 634 * Convert a filename to full pathname in original filesys 635 * @param fname: the path name to convert. 636 * Must not be null or empty. 637 * @param cfg: config struct for chroot and chdir (if set). 638 * @param use_chdir: if false, only chroot is applied. 639 * @return pointer to malloced buffer which is: [chroot][chdir]fname 640 * or NULL on malloc failure. 641 */ 642 char* fname_after_chroot(const char* fname, struct config_file* cfg, 643 int use_chdir); 644 645 /** 646 * Convert a ptr shorthand into a full reverse-notation PTR record. 647 * @param str: input string, "IP name" 648 * @return: malloced string "reversed-ip-name PTR name" 649 */ 650 char* cfg_ptr_reverse(char* str); 651 652 /** 653 * Append text to the error info for validation. 654 * @param qstate: query state. 655 * @param str: copied into query region and appended. 656 * Failures to allocate are logged. 657 */ 658 void errinf(struct module_qstate* qstate, const char* str); 659 660 /** 661 * Append text to error info: from 1.2.3.4 662 * @param qstate: query state. 663 * @param origin: sock list with origin of trouble. 664 * Every element added. 665 * If NULL: nothing is added. 666 * if 0len element: 'from cache' is added. 667 */ 668 void errinf_origin(struct module_qstate* qstate, struct sock_list *origin); 669 670 /** 671 * Append text to error info: for RRset name type class 672 * @param qstate: query state. 673 * @param rr: rrset_key. 674 */ 675 void errinf_rrset(struct module_qstate* qstate, struct ub_packed_rrset_key *rr); 676 677 /** 678 * Append text to error info: str dname 679 * @param qstate: query state. 680 * @param str: explanation string 681 * @param dname: the dname. 682 */ 683 void errinf_dname(struct module_qstate* qstate, const char* str, 684 uint8_t* dname); 685 686 /** 687 * Create error info in string 688 * @param qstate: query state. 689 * @return string or NULL on malloc failure (already logged). 690 * This string is malloced and has to be freed by caller. 691 */ 692 char* errinf_to_str(struct module_qstate* qstate); 693 694 /** 695 * Used during options parsing 696 */ 697 struct config_parser_state { 698 /** name of file being parser */ 699 char* filename; 700 /** line number in the file, starts at 1 */ 701 int line; 702 /** number of errors encountered */ 703 int errors; 704 /** the result of parsing is stored here. */ 705 struct config_file* cfg; 706 /** the current chroot dir (or NULL if none) */ 707 const char* chroot; 708 }; 709 710 /** global config parser object used during config parsing */ 711 extern struct config_parser_state* cfg_parser; 712 /** init lex state */ 713 void init_cfg_parse(void); 714 /** lex in file */ 715 extern FILE* ub_c_in; 716 /** lex out file */ 717 extern FILE* ub_c_out; 718 /** the yacc lex generated parse function */ 719 int ub_c_parse(void); 720 /** the lexer function */ 721 int ub_c_lex(void); 722 /** wrap function */ 723 int ub_c_wrap(void); 724 /** parsing helpers: print error with file and line numbers */ 725 void ub_c_error(const char* msg); 726 /** parsing helpers: print error with file and line numbers */ 727 void ub_c_error_msg(const char* fmt, ...) ATTR_FORMAT(printf, 1, 2); 728 729 #ifdef UB_ON_WINDOWS 730 /** 731 * Obtain registry string (if it exists). 732 * @param key: key string 733 * @param name: name of value to fetch. 734 * @return malloced string with the result or NULL if it did not 735 * exist on an error (logged with log_err) was encountered. 736 */ 737 char* w_lookup_reg_str(const char* key, const char* name); 738 #endif /* UB_ON_WINDOWS */ 739 740 #endif /* UTIL_CONFIG_FILE_H */ 741