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_auth; 46 struct config_view; 47 struct config_strlist; 48 struct config_str2list; 49 struct config_str3list; 50 struct config_strbytelist; 51 struct module_qstate; 52 struct sock_list; 53 struct ub_packed_rrset_key; 54 struct regional; 55 56 /** List head for strlist processing, used for append operation. */ 57 struct config_strlist_head { 58 /** first in list of text items */ 59 struct config_strlist* first; 60 /** last in list of text items */ 61 struct config_strlist* last; 62 }; 63 64 /** 65 * The configuration options. 66 * Strings are malloced. 67 */ 68 struct config_file { 69 /** verbosity level as specified in the config file */ 70 int verbosity; 71 72 /** statistics interval (in seconds) */ 73 int stat_interval; 74 /** if false, statistics values are reset after printing them */ 75 int stat_cumulative; 76 /** if true, the statistics are kept in greater detail */ 77 int stat_extended; 78 79 /** number of threads to create */ 80 int num_threads; 81 82 /** port on which queries are answered. */ 83 int port; 84 /** do ip4 query support. */ 85 int do_ip4; 86 /** do ip6 query support. */ 87 int do_ip6; 88 /** prefer ip4 upstream queries. */ 89 int prefer_ip4; 90 /** prefer ip6 upstream queries. */ 91 int prefer_ip6; 92 /** do udp query support. */ 93 int do_udp; 94 /** do tcp query support. */ 95 int do_tcp; 96 /** tcp upstream queries (no UDP upstream queries) */ 97 int tcp_upstream; 98 /** udp upstream enabled when no UDP downstream is enabled (do_udp no)*/ 99 int udp_upstream_without_downstream; 100 /** maximum segment size of tcp socket which queries are answered */ 101 int tcp_mss; 102 /** maximum segment size of tcp socket for outgoing queries */ 103 int outgoing_tcp_mss; 104 /** tcp idle timeout, in msec */ 105 int tcp_idle_timeout; 106 /** do edns tcp keepalive */ 107 int do_tcp_keepalive; 108 /** tcp keepalive timeout, in msec */ 109 int tcp_keepalive_timeout; 110 111 /** private key file for dnstcp-ssl service (enabled if not NULL) */ 112 char* ssl_service_key; 113 /** public key file for dnstcp-ssl service */ 114 char* ssl_service_pem; 115 /** port on which to provide ssl service */ 116 int ssl_port; 117 /** if outgoing tcp connections use SSL */ 118 int ssl_upstream; 119 /** cert bundle for outgoing connections */ 120 char* tls_cert_bundle; 121 /** should the system certificate store get added to the cert bundle */ 122 int tls_win_cert; 123 /** additional tls ports */ 124 struct config_strlist* tls_additional_port; 125 /** secret key used to encrypt and decrypt TLS session ticket */ 126 struct config_strlist_head tls_session_ticket_keys; 127 /** TLS ciphers */ 128 char* tls_ciphers; 129 /** TLS chiphersuites (TLSv1.3) */ 130 char* tls_ciphersuites; 131 /** if SNI is to be used */ 132 int tls_use_sni; 133 134 /** outgoing port range number of ports (per thread) */ 135 int outgoing_num_ports; 136 /** number of outgoing tcp buffers per (per thread) */ 137 size_t outgoing_num_tcp; 138 /** number of incoming tcp buffers per (per thread) */ 139 size_t incoming_num_tcp; 140 /** allowed udp port numbers, array with 0 if not allowed */ 141 int* outgoing_avail_ports; 142 143 /** EDNS buffer size to use */ 144 size_t edns_buffer_size; 145 /** size of the stream wait buffers, max */ 146 size_t stream_wait_size; 147 /** number of bytes buffer size for DNS messages */ 148 size_t msg_buffer_size; 149 /** size of the message cache */ 150 size_t msg_cache_size; 151 /** slabs in the message cache. */ 152 size_t msg_cache_slabs; 153 /** number of queries every thread can service */ 154 size_t num_queries_per_thread; 155 /** number of msec to wait before items can be jostled out */ 156 size_t jostle_time; 157 /** size of the rrset cache */ 158 size_t rrset_cache_size; 159 /** slabs in the rrset cache */ 160 size_t rrset_cache_slabs; 161 /** host cache ttl in seconds */ 162 int host_ttl; 163 /** number of slabs in the infra host cache */ 164 size_t infra_cache_slabs; 165 /** max number of hosts in the infra cache */ 166 size_t infra_cache_numhosts; 167 /** min value for infra cache rtt */ 168 int infra_cache_min_rtt; 169 /** delay close of udp-timeouted ports, if 0 no delayclose. in msec */ 170 int delay_close; 171 172 /** the target fetch policy for the iterator */ 173 char* target_fetch_policy; 174 /** percent*10, how many times in 1000 to pick from the fastest 175 * destinations */ 176 int fast_server_permil; 177 /** number of fastest server to select from */ 178 size_t fast_server_num; 179 180 /** automatic interface for incoming messages. Uses ipv6 remapping, 181 * and recvmsg/sendmsg ancillary data to detect interfaces, boolean */ 182 int if_automatic; 183 /** SO_RCVBUF size to set on port 53 UDP socket */ 184 size_t so_rcvbuf; 185 /** SO_SNDBUF size to set on port 53 UDP socket */ 186 size_t so_sndbuf; 187 /** SO_REUSEPORT requested on port 53 sockets */ 188 int so_reuseport; 189 /** IP_TRANSPARENT socket option requested on port 53 sockets */ 190 int ip_transparent; 191 /** IP_FREEBIND socket option request on port 53 sockets */ 192 int ip_freebind; 193 /** IP_TOS socket option requested on port 53 sockets */ 194 int ip_dscp; 195 196 /** number of interfaces to open. If 0 default all interfaces. */ 197 int num_ifs; 198 /** interface description strings (IP addresses) */ 199 char **ifs; 200 201 /** number of outgoing interfaces to open. 202 * If 0 default all interfaces. */ 203 int num_out_ifs; 204 /** outgoing interface description strings (IP addresses) */ 205 char **out_ifs; 206 207 /** the root hints */ 208 struct config_strlist* root_hints; 209 /** the stub definitions, linked list */ 210 struct config_stub* stubs; 211 /** the forward zone definitions, linked list */ 212 struct config_stub* forwards; 213 /** the auth zone definitions, linked list */ 214 struct config_auth* auths; 215 /** the views definitions, linked list */ 216 struct config_view* views; 217 /** list of donotquery addresses, linked list */ 218 struct config_strlist* donotqueryaddrs; 219 #ifdef CLIENT_SUBNET 220 /** list of servers we send edns-client-subnet option to and 221 * accept option from, linked list */ 222 struct config_strlist* client_subnet; 223 /** list of zones we send edns-client-subnet option for */ 224 struct config_strlist* client_subnet_zone; 225 /** opcode assigned by IANA for edns0-client-subnet option */ 226 uint16_t client_subnet_opcode; 227 /** Do not check whitelist if incoming query contains an ECS record */ 228 int client_subnet_always_forward; 229 /** Subnet length we are willing to give up privacy for */ 230 uint8_t max_client_subnet_ipv4; 231 uint8_t max_client_subnet_ipv6; 232 /** Minimum subnet length we are willing to answer */ 233 uint8_t min_client_subnet_ipv4; 234 uint8_t min_client_subnet_ipv6; 235 /** Max number of nodes in the ECS radix tree */ 236 uint32_t max_ecs_tree_size_ipv4; 237 uint32_t max_ecs_tree_size_ipv6; 238 #endif 239 /** list of access control entries, linked list */ 240 struct config_str2list* acls; 241 /** use default localhost donotqueryaddr entries */ 242 int donotquery_localhost; 243 244 /** list of tcp connection limitss, linked list */ 245 struct config_str2list* tcp_connection_limits; 246 247 /** harden against very small edns buffer sizes */ 248 int harden_short_bufsize; 249 /** harden against very large query sizes */ 250 int harden_large_queries; 251 /** harden against spoofed glue (out of zone data) */ 252 int harden_glue; 253 /** harden against receiving no DNSSEC data for trust anchor */ 254 int harden_dnssec_stripped; 255 /** harden against queries that fall under known nxdomain names */ 256 int harden_below_nxdomain; 257 /** harden the referral path, query for NS,A,AAAA and validate */ 258 int harden_referral_path; 259 /** harden against algorithm downgrade */ 260 int harden_algo_downgrade; 261 /** use 0x20 bits in query as random ID bits */ 262 int use_caps_bits_for_id; 263 /** 0x20 whitelist, domains that do not use capsforid */ 264 struct config_strlist* caps_whitelist; 265 /** strip away these private addrs from answers, no DNS Rebinding */ 266 struct config_strlist* private_address; 267 /** allow domain (and subdomains) to use private address space */ 268 struct config_strlist* private_domain; 269 /** what threshold for unwanted action. */ 270 size_t unwanted_threshold; 271 /** the number of seconds maximal TTL used for RRsets and messages */ 272 int max_ttl; 273 /** the number of seconds minimum TTL used for RRsets and messages */ 274 int min_ttl; 275 /** the number of seconds maximal negative TTL for SOA in auth */ 276 int max_negative_ttl; 277 /** if prefetching of messages should be performed. */ 278 int prefetch; 279 /** if prefetching of DNSKEYs should be performed. */ 280 int prefetch_key; 281 /** deny queries of type ANY with an empty answer */ 282 int deny_any; 283 284 /** chrootdir, if not "" or chroot will be done */ 285 char* chrootdir; 286 /** username to change to, if not "". */ 287 char* username; 288 /** working directory */ 289 char* directory; 290 /** filename to log to. */ 291 char* logfile; 292 /** pidfile to write pid to. */ 293 char* pidfile; 294 295 /** should log messages be sent to syslogd */ 296 int use_syslog; 297 /** log timestamp in ascii UTC */ 298 int log_time_ascii; 299 /** log queries with one line per query */ 300 int log_queries; 301 /** log replies with one line per reply */ 302 int log_replies; 303 /** tag log_queries and log_replies for filtering */ 304 int log_tag_queryreply; 305 /** log every local-zone hit **/ 306 int log_local_actions; 307 /** log servfails with a reason */ 308 int log_servfail; 309 /** log identity to report */ 310 char* log_identity; 311 312 /** do not report identity (id.server, hostname.bind) */ 313 int hide_identity; 314 /** do not report version (version.server, version.bind) */ 315 int hide_version; 316 /** do not report trustanchor (trustanchor.unbound) */ 317 int hide_trustanchor; 318 /** identity, hostname is returned if "". */ 319 char* identity; 320 /** version, package version returned if "". */ 321 char* version; 322 323 /** the module configuration string */ 324 char* module_conf; 325 326 /** files with trusted DS and DNSKEYs in zonefile format, list */ 327 struct config_strlist* trust_anchor_file_list; 328 /** list of trustanchor keys, linked list */ 329 struct config_strlist* trust_anchor_list; 330 /** files with 5011 autotrust tracked keys */ 331 struct config_strlist* auto_trust_anchor_file_list; 332 /** files with trusted DNSKEYs in named.conf format, list */ 333 struct config_strlist* trusted_keys_file_list; 334 /** DLV anchor file */ 335 char* dlv_anchor_file; 336 /** DLV anchor inline */ 337 struct config_strlist* dlv_anchor_list; 338 /** insecure domain list */ 339 struct config_strlist* domain_insecure; 340 /** send key tag query */ 341 int trust_anchor_signaling; 342 /** enable root key sentinel */ 343 int root_key_sentinel; 344 345 /** if not 0, this value is the validation date for RRSIGs */ 346 int32_t val_date_override; 347 /** the minimum for signature clock skew */ 348 int32_t val_sig_skew_min; 349 /** the maximum for signature clock skew */ 350 int32_t val_sig_skew_max; 351 /** this value sets the number of seconds before revalidating bogus */ 352 int bogus_ttl; 353 /** should validator clean additional section for secure msgs */ 354 int val_clean_additional; 355 /** log bogus messages by the validator */ 356 int val_log_level; 357 /** squelch val_log_level to log - this is library goes to callback */ 358 int val_log_squelch; 359 /** should validator allow bogus messages to go through */ 360 int val_permissive_mode; 361 /** use cached NSEC records to synthesise (negative) answers */ 362 int aggressive_nsec; 363 /** ignore the CD flag in incoming queries and refuse them bogus data */ 364 int ignore_cd; 365 /** serve expired entries and prefetch them */ 366 int serve_expired; 367 /** serve expired entries until TTL after expiration */ 368 int serve_expired_ttl; 369 /** reset serve expired TTL after failed update attempt */ 370 int serve_expired_ttl_reset; 371 /** TTL for the serve expired replies */ 372 int serve_expired_reply_ttl; 373 /** serve expired entries only after trying to update the entries and this 374 * timeout (in milliseconds) is reached */ 375 int serve_expired_client_timeout; 376 /** nsec3 maximum iterations per key size, string */ 377 char* val_nsec3_key_iterations; 378 /** autotrust add holddown time, in seconds */ 379 unsigned int add_holddown; 380 /** autotrust del holddown time, in seconds */ 381 unsigned int del_holddown; 382 /** autotrust keep_missing time, in seconds. 0 is forever. */ 383 unsigned int keep_missing; 384 /** permit small holddown values, allowing 5011 rollover very fast */ 385 int permit_small_holddown; 386 387 /** size of the key cache */ 388 size_t key_cache_size; 389 /** slabs in the key cache. */ 390 size_t key_cache_slabs; 391 /** size of the neg cache */ 392 size_t neg_cache_size; 393 394 /** local zones config */ 395 struct config_str2list* local_zones; 396 /** local zones nodefault list */ 397 struct config_strlist* local_zones_nodefault; 398 #ifdef USE_IPSET 399 /** local zones ipset list */ 400 struct config_strlist* local_zones_ipset; 401 #endif 402 /** do not add any default local zone */ 403 int local_zones_disable_default; 404 /** local data RRs configured */ 405 struct config_strlist* local_data; 406 /** local zone override types per netblock */ 407 struct config_str3list* local_zone_overrides; 408 /** unblock lan zones (reverse lookups for AS112 zones) */ 409 int unblock_lan_zones; 410 /** insecure lan zones (don't validate AS112 zones) */ 411 int insecure_lan_zones; 412 /** list of zonename, tagbitlist */ 413 struct config_strbytelist* local_zone_tags; 414 /** list of aclname, tagbitlist */ 415 struct config_strbytelist* acl_tags; 416 /** list of aclname, tagname, localzonetype */ 417 struct config_str3list* acl_tag_actions; 418 /** list of aclname, tagname, redirectdata */ 419 struct config_str3list* acl_tag_datas; 420 /** list of aclname, view*/ 421 struct config_str2list* acl_view; 422 /** list of IP-netblock, tagbitlist */ 423 struct config_strbytelist* respip_tags; 424 /** list of response-driven access control entries, linked list */ 425 struct config_str2list* respip_actions; 426 /** RRs configured for response-driven access controls */ 427 struct config_str2list* respip_data; 428 /** tag list, array with tagname[i] is malloced string */ 429 char** tagname; 430 /** number of items in the taglist */ 431 int num_tags; 432 433 /** remote control section. enable toggle. */ 434 int remote_control_enable; 435 /** the interfaces the remote control should listen on */ 436 struct config_strlist_head control_ifs; 437 /** if the use-cert option is set */ 438 int control_use_cert; 439 /** port number for the control port */ 440 int control_port; 441 /** private key file for server */ 442 char* server_key_file; 443 /** certificate file for server */ 444 char* server_cert_file; 445 /** private key file for unbound-control */ 446 char* control_key_file; 447 /** certificate file for unbound-control */ 448 char* control_cert_file; 449 450 /** Python script file */ 451 struct config_strlist* python_script; 452 453 /** Dynamic library file */ 454 struct config_strlist* dynlib_file; 455 456 /** Use systemd socket activation. */ 457 int use_systemd; 458 459 /** daemonize, i.e. fork into the background. */ 460 int do_daemonize; 461 462 /* minimal response when positive answer */ 463 int minimal_responses; 464 465 /* RRSet roundrobin */ 466 int rrset_roundrobin; 467 468 /* wait time for unknown server in msec */ 469 int unknown_server_time_limit; 470 471 /* maximum UDP response size */ 472 size_t max_udp_size; 473 474 /* DNS64 prefix */ 475 char* dns64_prefix; 476 477 /* Synthetize all AAAA record despite the presence of an authoritative one */ 478 int dns64_synthall; 479 /** ignore AAAAs for these domain names and use A record anyway */ 480 struct config_strlist* dns64_ignore_aaaa; 481 482 /** true to enable dnstap support */ 483 int dnstap; 484 /** using bidirectional frame streams if true */ 485 int dnstap_bidirectional; 486 /** dnstap socket path */ 487 char* dnstap_socket_path; 488 /** dnstap IP */ 489 char* dnstap_ip; 490 /** dnstap TLS enable */ 491 int dnstap_tls; 492 /** dnstap tls server authentication name */ 493 char* dnstap_tls_server_name; 494 /** dnstap server cert bundle */ 495 char* dnstap_tls_cert_bundle; 496 /** dnstap client key for client authentication */ 497 char* dnstap_tls_client_key_file; 498 /** dnstap client cert for client authentication */ 499 char* dnstap_tls_client_cert_file; 500 /** true to send "identity" via dnstap */ 501 int dnstap_send_identity; 502 /** true to send "version" via dnstap */ 503 int dnstap_send_version; 504 /** dnstap "identity", hostname is used if "". */ 505 char* dnstap_identity; 506 /** dnstap "version", package version is used if "". */ 507 char* dnstap_version; 508 509 /** true to log dnstap RESOLVER_QUERY message events */ 510 int dnstap_log_resolver_query_messages; 511 /** true to log dnstap RESOLVER_RESPONSE message events */ 512 int dnstap_log_resolver_response_messages; 513 /** true to log dnstap CLIENT_QUERY message events */ 514 int dnstap_log_client_query_messages; 515 /** true to log dnstap CLIENT_RESPONSE message events */ 516 int dnstap_log_client_response_messages; 517 /** true to log dnstap FORWARDER_QUERY message events */ 518 int dnstap_log_forwarder_query_messages; 519 /** true to log dnstap FORWARDER_RESPONSE message events */ 520 int dnstap_log_forwarder_response_messages; 521 522 /** true to disable DNSSEC lameness check in iterator */ 523 int disable_dnssec_lame_check; 524 525 /** ratelimit for ip addresses. 0 is off, otherwise qps (unless overridden) */ 526 int ip_ratelimit; 527 /** number of slabs for ip_ratelimit cache */ 528 size_t ip_ratelimit_slabs; 529 /** memory size in bytes for ip_ratelimit cache */ 530 size_t ip_ratelimit_size; 531 /** ip_ratelimit factor, 0 blocks all, 10 allows 1/10 of traffic */ 532 int ip_ratelimit_factor; 533 534 /** ratelimit for domains. 0 is off, otherwise qps (unless overridden) */ 535 int ratelimit; 536 /** number of slabs for ratelimit cache */ 537 size_t ratelimit_slabs; 538 /** memory size in bytes for ratelimit cache */ 539 size_t ratelimit_size; 540 /** ratelimits for domain (exact match) */ 541 struct config_str2list* ratelimit_for_domain; 542 /** ratelimits below domain */ 543 struct config_str2list* ratelimit_below_domain; 544 /** ratelimit factor, 0 blocks all, 10 allows 1/10 of traffic */ 545 int ratelimit_factor; 546 /** minimise outgoing QNAME and hide original QTYPE if possible */ 547 int qname_minimisation; 548 /** minimise QNAME in strict mode, minimise according to RFC. 549 * Do not apply fallback */ 550 int qname_minimisation_strict; 551 /** SHM data - true if shm is enabled */ 552 int shm_enable; 553 /** SHM data - key for the shm */ 554 int shm_key; 555 556 /** DNSCrypt */ 557 /** true to enable dnscrypt */ 558 int dnscrypt; 559 /** port on which to provide dnscrypt service */ 560 int dnscrypt_port; 561 /** provider name 2.dnscrypt-cert.example.com */ 562 char* dnscrypt_provider; 563 /** dnscrypt secret keys 1.key */ 564 struct config_strlist* dnscrypt_secret_key; 565 /** dnscrypt provider certs 1.cert */ 566 struct config_strlist* dnscrypt_provider_cert; 567 /** dnscrypt provider certs 1.cert which have been rotated and should not be 568 * advertised through DNS's providername TXT record but are required to be 569 * able to handle existing traffic using the old cert. */ 570 struct config_strlist* dnscrypt_provider_cert_rotated; 571 /** memory size in bytes for dnscrypt shared secrets cache */ 572 size_t dnscrypt_shared_secret_cache_size; 573 /** number of slabs for dnscrypt shared secrets cache */ 574 size_t dnscrypt_shared_secret_cache_slabs; 575 /** memory size in bytes for dnscrypt nonces cache */ 576 size_t dnscrypt_nonce_cache_size; 577 /** number of slabs for dnscrypt nonces cache */ 578 size_t dnscrypt_nonce_cache_slabs; 579 /** IPsec module */ 580 #ifdef USE_IPSECMOD 581 /** false to bypass the IPsec module */ 582 int ipsecmod_enabled; 583 /** whitelisted domains for ipsecmod */ 584 struct config_strlist* ipsecmod_whitelist; 585 /** path to external hook */ 586 char* ipsecmod_hook; 587 /** true to proceed even with a bogus IPSECKEY */ 588 int ipsecmod_ignore_bogus; 589 /** max TTL for the A/AAAA records that call the hook */ 590 int ipsecmod_max_ttl; 591 /** false to proceed even when ipsecmod_hook fails */ 592 int ipsecmod_strict; 593 #endif 594 595 /* cachedb module */ 596 #ifdef USE_CACHEDB 597 /** backend DB name */ 598 char* cachedb_backend; 599 /** secret seed for hash key calculation */ 600 char* cachedb_secret; 601 #ifdef USE_REDIS 602 /** redis server's IP address or host name */ 603 char* redis_server_host; 604 /** redis server's TCP port */ 605 int redis_server_port; 606 /** timeout (in ms) for communication with the redis server */ 607 int redis_timeout; 608 /** set timeout on redis records based on DNS response ttl */ 609 int redis_expire_records; 610 #endif 611 #endif 612 613 /* ipset module */ 614 #ifdef USE_IPSET 615 char* ipset_name_v4; 616 char* ipset_name_v6; 617 #endif 618 }; 619 620 /** from cfg username, after daemonize setup performed */ 621 extern uid_t cfg_uid; 622 /** from cfg username, after daemonize setup performed */ 623 extern gid_t cfg_gid; 624 /** debug and enable small timeouts */ 625 extern int autr_permit_small_holddown; 626 /** size (in bytes) of stream wait buffers max */ 627 extern size_t stream_wait_max; 628 629 /** 630 * Stub config options 631 */ 632 struct config_stub { 633 /** next in list */ 634 struct config_stub* next; 635 /** domain name (in text) of the stub apex domain */ 636 char* name; 637 /** list of stub nameserver hosts (domain name) */ 638 struct config_strlist* hosts; 639 /** list of stub nameserver addresses (IP address) */ 640 struct config_strlist* addrs; 641 /** if stub-prime is set */ 642 int isprime; 643 /** if forward-first is set (failover to without if fails) */ 644 int isfirst; 645 /** use SSL for queries to this stub */ 646 int ssl_upstream; 647 /*** no cache */ 648 int no_cache; 649 }; 650 651 /** 652 * Auth config options 653 */ 654 struct config_auth { 655 /** next in list */ 656 struct config_auth* next; 657 /** domain name (in text) of the auth apex domain */ 658 char* name; 659 /** list of masters */ 660 struct config_strlist* masters; 661 /** list of urls */ 662 struct config_strlist* urls; 663 /** list of allow-notify */ 664 struct config_strlist* allow_notify; 665 /** zonefile (or NULL) */ 666 char* zonefile; 667 /** provide downstream answers */ 668 int for_downstream; 669 /** provide upstream answers */ 670 int for_upstream; 671 /** fallback to recursion to authorities if zone expired and other 672 * reasons perhaps (like, query bogus) */ 673 int fallback_enabled; 674 /** this zone is used to create local-zone policies */ 675 int isrpz; 676 /** rpz tags (or NULL) */ 677 uint8_t* rpz_taglist; 678 /** length of the taglist (in bytes) */ 679 size_t rpz_taglistlen; 680 /** Override RPZ action for this zone, regardless of zone content */ 681 char* rpz_action_override; 682 /** Log when this RPZ policy is applied */ 683 int rpz_log; 684 /** Display this name in the log when RPZ policy is applied */ 685 char* rpz_log_name; 686 /** Always reply with this CNAME target if the cname override action is 687 * used */ 688 char* rpz_cname; 689 }; 690 691 /** 692 * View config options 693 */ 694 struct config_view { 695 /** next in list */ 696 struct config_view* next; 697 /** view name */ 698 char* name; 699 /** local zones */ 700 struct config_str2list* local_zones; 701 /** local data RRs */ 702 struct config_strlist* local_data; 703 /** local zones nodefault list */ 704 struct config_strlist* local_zones_nodefault; 705 #ifdef USE_IPSET 706 /** local zones ipset list */ 707 struct config_strlist* local_zones_ipset; 708 #endif 709 /** Fallback to global local_zones when there is no match in the view 710 * view specific tree. 1 for yes, 0 for no */ 711 int isfirst; 712 /** predefined actions for particular IP address responses */ 713 struct config_str2list* respip_actions; 714 /** data complementing the 'redirect' response IP actions */ 715 struct config_str2list* respip_data; 716 }; 717 718 /** 719 * List of strings for config options 720 */ 721 struct config_strlist { 722 /** next item in list */ 723 struct config_strlist* next; 724 /** config option string */ 725 char* str; 726 }; 727 728 /** 729 * List of two strings for config options 730 */ 731 struct config_str2list { 732 /** next item in list */ 733 struct config_str2list* next; 734 /** first string */ 735 char* str; 736 /** second string */ 737 char* str2; 738 }; 739 740 /** 741 * List of three strings for config options 742 */ 743 struct config_str3list { 744 /** next item in list */ 745 struct config_str3list* next; 746 /** first string */ 747 char* str; 748 /** second string */ 749 char* str2; 750 /** third string */ 751 char* str3; 752 }; 753 754 755 /** 756 * List of string, bytestring for config options 757 */ 758 struct config_strbytelist { 759 /** next item in list */ 760 struct config_strbytelist* next; 761 /** first string */ 762 char* str; 763 /** second bytestring */ 764 uint8_t* str2; 765 size_t str2len; 766 }; 767 768 /** 769 * Create config file structure. Filled with default values. 770 * @return: the new structure or NULL on memory error. 771 */ 772 struct config_file* config_create(void); 773 774 /** 775 * Create config file structure for library use. Filled with default values. 776 * @return: the new structure or NULL on memory error. 777 */ 778 struct config_file* config_create_forlib(void); 779 780 /** 781 * Read the config file from the specified filename. 782 * @param config: where options are stored into, must be freshly created. 783 * @param filename: name of configfile. If NULL nothing is done. 784 * @param chroot: if not NULL, the chroot dir currently in use (for include). 785 * @return: false on error. In that case errno is set, ENOENT means 786 * file not found. 787 */ 788 int config_read(struct config_file* config, const char* filename, 789 const char* chroot); 790 791 /** 792 * Destroy the config file structure. 793 * @param config: to delete. 794 */ 795 void config_delete(struct config_file* config); 796 797 /** 798 * Apply config to global constants; this routine is called in single thread. 799 * @param config: to apply. Side effect: global constants change. 800 */ 801 void config_apply(struct config_file* config); 802 803 /** 804 * Find username, sets cfg_uid and cfg_gid. 805 * @param config: the config structure. 806 */ 807 void config_lookup_uid(struct config_file* config); 808 809 /** 810 * Set the given keyword to the given value. 811 * @param config: where to store config 812 * @param option: option name, including the ':' character. 813 * @param value: value, this string is copied if needed, or parsed. 814 * The caller owns the value string. 815 * @return 0 on error (malloc or syntax error). 816 */ 817 int config_set_option(struct config_file* config, const char* option, 818 const char* value); 819 820 /** 821 * Call print routine for the given option. 822 * @param cfg: config. 823 * @param opt: option name without trailing :. 824 * This is different from config_set_option. 825 * @param func: print func, called as (str, arg) for every data element. 826 * @param arg: user argument for print func. 827 * @return false if the option name is not supported (syntax error). 828 */ 829 int config_get_option(struct config_file* cfg, const char* opt, 830 void (*func)(char*,void*), void* arg); 831 832 /** 833 * Get an option and return strlist 834 * @param cfg: config file 835 * @param opt: option name. 836 * @param list: list is returned here. malloced, caller must free it. 837 * @return 0=OK, 1=syntax error, 2=malloc failed. 838 */ 839 int config_get_option_list(struct config_file* cfg, const char* opt, 840 struct config_strlist** list); 841 842 /** 843 * Get an option and collate results into string 844 * @param cfg: config file 845 * @param opt: option name. 846 * @param str: string. malloced, caller must free it. 847 * @return 0=OK, 1=syntax error, 2=malloc failed. 848 */ 849 int config_get_option_collate(struct config_file* cfg, const char* opt, 850 char** str); 851 852 /** 853 * function to print to a file, use as func with config_get_option. 854 * @param line: text to print. \n appended. 855 * @param arg: pass a FILE*, like stdout. 856 */ 857 void config_print_func(char* line, void* arg); 858 859 /** 860 * function to collate the text strings into a strlist_head. 861 * @param line: text to append. 862 * @param arg: pass a strlist_head structure. zeroed on start. 863 */ 864 void config_collate_func(char* line, void* arg); 865 866 /** 867 * take a strlist_head list and return a malloc string. separated with newline. 868 * @param list: strlist first to collate. zeroes return "". 869 * @return NULL on malloc failure. Or if malloc failure happened in strlist. 870 */ 871 char* config_collate_cat(struct config_strlist* list); 872 873 /** 874 * Append text at end of list. 875 * @param list: list head. zeroed at start. 876 * @param item: new item. malloced by caller. if NULL the insertion fails. 877 * @return true on success. 878 * on fail the item is free()ed. 879 */ 880 int cfg_strlist_append(struct config_strlist_head* list, char* item); 881 882 /** 883 * Searches the end of a string list and appends the given text. 884 * @param head: pointer to strlist head variable. 885 * @param item: new item. malloced by caller. if NULL the insertion fails. 886 * @return true on success. 887 */ 888 int cfg_strlist_append_ex(struct config_strlist** head, char* item); 889 890 /** 891 * Find string in strlist. 892 * @param head: pointer to strlist head variable. 893 * @param item: the item to search for. 894 * @return: the element in the list when found, NULL otherwise. 895 */ 896 struct config_strlist* cfg_strlist_find(struct config_strlist* head, 897 const char* item); 898 899 /** 900 * Insert string into strlist. 901 * @param head: pointer to strlist head variable. 902 * @param item: new item. malloced by caller. If NULL the insertion fails. 903 * @return: true on success. 904 * on fail, the item is free()d. 905 */ 906 int cfg_strlist_insert(struct config_strlist** head, char* item); 907 908 /** insert with region for allocation. */ 909 int cfg_region_strlist_insert(struct regional* region, 910 struct config_strlist** head, char* item); 911 912 /** 913 * Insert string into str2list. 914 * @param head: pointer to str2list head variable. 915 * @param item: new item. malloced by caller. If NULL the insertion fails. 916 * @param i2: 2nd string, malloced by caller. If NULL the insertion fails. 917 * @return: true on success. 918 * on fail, the item and i2 are free()d. 919 */ 920 int cfg_str2list_insert(struct config_str2list** head, char* item, char* i2); 921 922 /** 923 * Insert string into str3list. 924 * @param head: pointer to str3list head variable. 925 * @param item: new item. malloced by caller. If NULL the insertion fails. 926 * @param i2: 2nd string, malloced by caller. If NULL the insertion fails. 927 * @param i3: 3rd string, malloced by caller. If NULL the insertion fails. 928 * @return: true on success. 929 */ 930 int cfg_str3list_insert(struct config_str3list** head, char* item, char* i2, 931 char* i3); 932 933 /** 934 * Insert string into strbytelist. 935 * @param head: pointer to strbytelist head variable. 936 * @param item: new item. malloced by caller. If NULL the insertion fails. 937 * @param i2: 2nd string, malloced by caller. If NULL the insertion fails. 938 * @param i2len: length of the i2 bytestring. 939 * @return: true on success. 940 */ 941 int cfg_strbytelist_insert(struct config_strbytelist** head, char* item, 942 uint8_t* i2, size_t i2len); 943 944 /** 945 * Find stub in config list, also returns prevptr (for deletion). 946 * @param pp: call routine with pointer to a pointer to the start of the list, 947 * if the stub is found, on exit, the value contains a pointer to the 948 * next pointer that points to the found element (or to the list start 949 * pointer if it is the first element). 950 * @param nm: name of stub to find. 951 * @return: pointer to config_stub if found, or NULL if not found. 952 */ 953 struct config_stub* cfg_stub_find(struct config_stub*** pp, const char* nm); 954 955 /** 956 * Delete items in config string list. 957 * @param list: list. 958 */ 959 void config_delstrlist(struct config_strlist* list); 960 961 /** 962 * Delete items in config double string list. 963 * @param list: list. 964 */ 965 void config_deldblstrlist(struct config_str2list* list); 966 967 /** 968 * Delete items in config triple string list. 969 * @param list: list. 970 */ 971 void config_deltrplstrlist(struct config_str3list* list); 972 973 /** delete stringbytelist */ 974 void config_del_strbytelist(struct config_strbytelist* list); 975 976 /** 977 * Delete a stub item 978 * @param p: stub item 979 */ 980 void config_delstub(struct config_stub* p); 981 982 /** 983 * Delete items in config stub list. 984 * @param list: list. 985 */ 986 void config_delstubs(struct config_stub* list); 987 988 /** 989 * Delete an auth item 990 * @param p: auth item 991 */ 992 void config_delauth(struct config_auth* p); 993 994 /** 995 * Delete items in config auth list. 996 * @param list: list. 997 */ 998 void config_delauths(struct config_auth* list); 999 1000 /** 1001 * Delete a view item 1002 * @param p: view item 1003 */ 1004 void config_delview(struct config_view* p); 1005 1006 /** 1007 * Delete items in config view list. 1008 * @param list: list. 1009 */ 1010 void config_delviews(struct config_view* list); 1011 1012 /** check if config for remote control turns on IP-address interface 1013 * with certificates or a named pipe without certificates. */ 1014 int options_remote_is_address(struct config_file* cfg); 1015 1016 /** 1017 * Convert 14digit to time value 1018 * @param str: string of 14 digits 1019 * @return time value or 0 for error. 1020 */ 1021 time_t cfg_convert_timeval(const char* str); 1022 1023 /** 1024 * Count number of values in the string. 1025 * format ::= (sp num)+ sp 1026 * num ::= [-](0-9)+ 1027 * sp ::= (space|tab)* 1028 * 1029 * @param str: string 1030 * @return: 0 on parse error, or empty string, else 1031 * number of integer values in the string. 1032 */ 1033 int cfg_count_numbers(const char* str); 1034 1035 /** 1036 * Convert a 'nice' memory or file size into a bytecount 1037 * From '100k' to 102400. and so on. Understands kKmMgG. 1038 * k=1024, m=1024*1024, g=1024*1024*1024. 1039 * @param str: string 1040 * @param res: result is stored here, size in bytes. 1041 * @return: true if parsed correctly, or 0 on a parse error (and an error 1042 * is logged). 1043 */ 1044 int cfg_parse_memsize(const char* str, size_t* res); 1045 1046 /** 1047 * Add a tag name to the config. It is added at the end with a new ID value. 1048 * @param cfg: the config structure. 1049 * @param tag: string (which is copied) with the name. 1050 * @return: false on alloc failure. 1051 */ 1052 int config_add_tag(struct config_file* cfg, const char* tag); 1053 1054 /** 1055 * Find tag ID in the tag list. 1056 * @param cfg: the config structure. 1057 * @param tag: string with tag name to search for. 1058 * @return: 0..(num_tags-1) with tag ID, or -1 if tagname is not found. 1059 */ 1060 int find_tag_id(struct config_file* cfg, const char* tag); 1061 1062 /** 1063 * parse taglist from string into bytestring with bitlist. 1064 * @param cfg: the config structure (with tagnames) 1065 * @param str: the string to parse. Parse puts 0 bytes in string. 1066 * @param listlen: returns length of in bytes. 1067 * @return malloced bytes with a bitlist of the tags. or NULL on parse error 1068 * or malloc failure. 1069 */ 1070 uint8_t* config_parse_taglist(struct config_file* cfg, char* str, 1071 size_t* listlen); 1072 1073 /** 1074 * convert tag bitlist to a malloced string with tag names. For debug output. 1075 * @param cfg: the config structure (with tagnames) 1076 * @param taglist: the tag bitlist. 1077 * @param len: length of the tag bitlist. 1078 * @return malloced string or NULL. 1079 */ 1080 char* config_taglist2str(struct config_file* cfg, uint8_t* taglist, 1081 size_t len); 1082 1083 /** 1084 * see if two taglists intersect (have tags in common). 1085 * @param list1: first tag bitlist. 1086 * @param list1len: length in bytes of first list. 1087 * @param list2: second tag bitlist. 1088 * @param list2len: length in bytes of second list. 1089 * @return true if there are tags in common, 0 if not. 1090 */ 1091 int taglist_intersect(uint8_t* list1, size_t list1len, const uint8_t* list2, 1092 size_t list2len); 1093 1094 /** 1095 * Parse local-zone directive into two strings and register it in the config. 1096 * @param cfg: to put it in. 1097 * @param val: argument strings to local-zone, "example.com nodefault". 1098 * @return: false on failure 1099 */ 1100 int cfg_parse_local_zone(struct config_file* cfg, const char* val); 1101 1102 /** 1103 * Mark "number" or "low-high" as available or not in ports array. 1104 * @param str: string in input 1105 * @param allow: give true if this range is permitted. 1106 * @param avail: the array from cfg. 1107 * @param num: size of the array (65536). 1108 * @return: true if parsed correctly, or 0 on a parse error (and an error 1109 * is logged). 1110 */ 1111 int cfg_mark_ports(const char* str, int allow, int* avail, int num); 1112 1113 /** 1114 * Get a condensed list of ports returned. allocated. 1115 * @param cfg: config file. 1116 * @param avail: the available ports array is returned here. 1117 * @return: number of ports in array or 0 on error. 1118 */ 1119 int cfg_condense_ports(struct config_file* cfg, int** avail); 1120 1121 /** 1122 * Scan ports available 1123 * @param avail: the array from cfg. 1124 * @param num: size of the array (65536). 1125 * @return the number of ports available for use. 1126 */ 1127 int cfg_scan_ports(int* avail, int num); 1128 1129 /** 1130 * Convert a filename to full pathname in original filesys 1131 * @param fname: the path name to convert. 1132 * Must not be null or empty. 1133 * @param cfg: config struct for chroot and chdir (if set). 1134 * @param use_chdir: if false, only chroot is applied. 1135 * @return pointer to malloced buffer which is: [chroot][chdir]fname 1136 * or NULL on malloc failure. 1137 */ 1138 char* fname_after_chroot(const char* fname, struct config_file* cfg, 1139 int use_chdir); 1140 1141 /** 1142 * Convert a ptr shorthand into a full reverse-notation PTR record. 1143 * @param str: input string, "IP name" 1144 * @return: malloced string "reversed-ip-name PTR name" 1145 */ 1146 char* cfg_ptr_reverse(char* str); 1147 1148 /** 1149 * Append text to the error info for validation. 1150 * @param qstate: query state. 1151 * @param str: copied into query region and appended. 1152 * Failures to allocate are logged. 1153 */ 1154 void errinf(struct module_qstate* qstate, const char* str); 1155 1156 /** 1157 * Append text to error info: from 1.2.3.4 1158 * @param qstate: query state. 1159 * @param origin: sock list with origin of trouble. 1160 * Every element added. 1161 * If NULL: nothing is added. 1162 * if 0len element: 'from cache' is added. 1163 */ 1164 void errinf_origin(struct module_qstate* qstate, struct sock_list *origin); 1165 1166 /** 1167 * Append text to error info: for RRset name type class 1168 * @param qstate: query state. 1169 * @param rr: rrset_key. 1170 */ 1171 void errinf_rrset(struct module_qstate* qstate, struct ub_packed_rrset_key *rr); 1172 1173 /** 1174 * Append text to error info: str dname 1175 * @param qstate: query state. 1176 * @param str: explanation string 1177 * @param dname: the dname. 1178 */ 1179 void errinf_dname(struct module_qstate* qstate, const char* str, 1180 uint8_t* dname); 1181 1182 /** 1183 * Create error info in string. For validation failures. 1184 * @param qstate: query state. 1185 * @return string or NULL on malloc failure (already logged). 1186 * This string is malloced and has to be freed by caller. 1187 */ 1188 char* errinf_to_str_bogus(struct module_qstate* qstate); 1189 1190 /** 1191 * Create error info in string. For other servfails. 1192 * @param qstate: query state. 1193 * @return string or NULL on malloc failure (already logged). 1194 * This string is malloced and has to be freed by caller. 1195 */ 1196 char* errinf_to_str_servfail(struct module_qstate* qstate); 1197 1198 /** 1199 * Used during options parsing 1200 */ 1201 struct config_parser_state { 1202 /** name of file being parser */ 1203 char* filename; 1204 /** line number in the file, starts at 1 */ 1205 int line; 1206 /** number of errors encountered */ 1207 int errors; 1208 /** the result of parsing is stored here. */ 1209 struct config_file* cfg; 1210 /** the current chroot dir (or NULL if none) */ 1211 const char* chroot; 1212 }; 1213 1214 /** global config parser object used during config parsing */ 1215 extern struct config_parser_state* cfg_parser; 1216 /** init lex state */ 1217 void init_cfg_parse(void); 1218 /** lex in file */ 1219 extern FILE* ub_c_in; 1220 /** lex out file */ 1221 extern FILE* ub_c_out; 1222 /** the yacc lex generated parse function */ 1223 int ub_c_parse(void); 1224 /** the lexer function */ 1225 int ub_c_lex(void); 1226 /** wrap function */ 1227 int ub_c_wrap(void); 1228 /** parsing helpers: print error with file and line numbers */ 1229 void ub_c_error(const char* msg); 1230 /** parsing helpers: print error with file and line numbers */ 1231 void ub_c_error_msg(const char* fmt, ...) ATTR_FORMAT(printf, 1, 2); 1232 1233 #ifdef UB_ON_WINDOWS 1234 /** 1235 * Obtain registry string (if it exists). 1236 * @param key: key string 1237 * @param name: name of value to fetch. 1238 * @return malloced string with the result or NULL if it did not 1239 * exist on an error (logged with log_err) was encountered. 1240 */ 1241 char* w_lookup_reg_str(const char* key, const char* name); 1242 1243 /** Modify directory in options for module file name */ 1244 void w_config_adjust_directory(struct config_file* cfg); 1245 #endif /* UB_ON_WINDOWS */ 1246 1247 /** debug option for unit tests. */ 1248 extern int fake_dsa, fake_sha1; 1249 1250 #endif /* UTIL_CONFIG_FILE_H */ 1251 1252