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