2 * util/config_file.h - reads and stores the config file for unbound.
4 * Copyright (c) 2007, NLnet Labs. All rights reserved.
6 * This software is open source.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
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.
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.
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.
39 * This file contains functions for the config file.
42 #ifndef UTIL_CONFIG_FILE_H
43 #define UTIL_CONFIG_FILE_H
47 struct config_strlist;
48 struct config_str2list;
49 struct config_str3list;
50 struct config_strbytelist;
53 struct ub_packed_rrset_key;
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;
65 * The configuration options.
66 * Strings are malloced.
69 /** verbosity level as specified in the config file */
72 /** statistics interval (in seconds) */
74 /** if false, statistics values are reset after printing them */
76 /** if true, the statistics are kept in greater detail */
79 /** number of threads to create */
82 /** port on which queries are answered. */
84 /** do ip4 query support. */
86 /** do ip6 query support. */
88 /** prefer ip6 upstream queries. */
90 /** do udp query support. */
92 /** do tcp query support. */
94 /** tcp upstream queries (no UDP upstream queries) */
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 */
100 /** maximum segment size of tcp socket for outgoing queries */
101 int outgoing_tcp_mss;
103 /** private key file for dnstcp-ssl service (enabled if not NULL) */
104 char* ssl_service_key;
105 /** public key file for dnstcp-ssl service */
106 char* ssl_service_pem;
107 /** port on which to provide ssl service */
109 /** if outgoing tcp connections use SSL */
111 /** cert bundle for outgoing connections */
112 char* tls_cert_bundle;
113 /** should the system certificate store get added to the cert bundle */
115 /** additional tls ports */
116 struct config_strlist* tls_additional_port;
118 /** outgoing port range number of ports (per thread) */
119 int outgoing_num_ports;
120 /** number of outgoing tcp buffers per (per thread) */
121 size_t outgoing_num_tcp;
122 /** number of incoming tcp buffers per (per thread) */
123 size_t incoming_num_tcp;
124 /** allowed udp port numbers, array with 0 if not allowed */
125 int* outgoing_avail_ports;
127 /** EDNS buffer size to use */
128 size_t edns_buffer_size;
129 /** number of bytes buffer size for DNS messages */
130 size_t msg_buffer_size;
131 /** size of the message cache */
132 size_t msg_cache_size;
133 /** slabs in the message cache. */
134 size_t msg_cache_slabs;
135 /** number of queries every thread can service */
136 size_t num_queries_per_thread;
137 /** number of msec to wait before items can be jostled out */
139 /** size of the rrset cache */
140 size_t rrset_cache_size;
141 /** slabs in the rrset cache */
142 size_t rrset_cache_slabs;
143 /** host cache ttl in seconds */
145 /** number of slabs in the infra host cache */
146 size_t infra_cache_slabs;
147 /** max number of hosts in the infra cache */
148 size_t infra_cache_numhosts;
149 /** min value for infra cache rtt */
150 int infra_cache_min_rtt;
151 /** delay close of udp-timeouted ports, if 0 no delayclose. in msec */
154 /** the target fetch policy for the iterator */
155 char* target_fetch_policy;
156 /** percent*10, how many times in 1000 to pick low rtt destinations */
158 /** what time in msec is a low rtt destination */
161 /** automatic interface for incoming messages. Uses ipv6 remapping,
162 * and recvmsg/sendmsg ancillary data to detect interfaces, boolean */
164 /** SO_RCVBUF size to set on port 53 UDP socket */
166 /** SO_SNDBUF size to set on port 53 UDP socket */
168 /** SO_REUSEPORT requested on port 53 sockets */
170 /** IP_TRANSPARENT socket option requested on port 53 sockets */
172 /** IP_FREEBIND socket option request on port 53 sockets */
175 /** number of interfaces to open. If 0 default all interfaces. */
177 /** interface description strings (IP addresses) */
180 /** number of outgoing interfaces to open.
181 * If 0 default all interfaces. */
183 /** outgoing interface description strings (IP addresses) */
186 /** the root hints */
187 struct config_strlist* root_hints;
188 /** the stub definitions, linked list */
189 struct config_stub* stubs;
190 /** the forward zone definitions, linked list */
191 struct config_stub* forwards;
192 /** the auth zone definitions, linked list */
193 struct config_auth* auths;
194 /** the views definitions, linked list */
195 struct config_view* views;
196 /** list of donotquery addresses, linked list */
197 struct config_strlist* donotqueryaddrs;
199 /** list of servers we send edns-client-subnet option to and
200 * accept option from, linked list */
201 struct config_strlist* client_subnet;
202 /** list of zones we send edns-client-subnet option for */
203 struct config_strlist* client_subnet_zone;
204 /** opcode assigned by IANA for edns0-client-subnet option */
205 uint16_t client_subnet_opcode;
206 /** Do not check whitelist if incoming query contains an ECS record */
207 int client_subnet_always_forward;
208 /** Subnet length we are willing to give up privacy for */
209 uint8_t max_client_subnet_ipv4;
210 uint8_t max_client_subnet_ipv6;
212 /** list of access control entries, linked list */
213 struct config_str2list* acls;
214 /** use default localhost donotqueryaddr entries */
215 int donotquery_localhost;
217 /** harden against very small edns buffer sizes */
218 int harden_short_bufsize;
219 /** harden against very large query sizes */
220 int harden_large_queries;
221 /** harden against spoofed glue (out of zone data) */
223 /** harden against receiving no DNSSEC data for trust anchor */
224 int harden_dnssec_stripped;
225 /** harden against queries that fall under known nxdomain names */
226 int harden_below_nxdomain;
227 /** harden the referral path, query for NS,A,AAAA and validate */
228 int harden_referral_path;
229 /** harden against algorithm downgrade */
230 int harden_algo_downgrade;
231 /** use 0x20 bits in query as random ID bits */
232 int use_caps_bits_for_id;
233 /** 0x20 whitelist, domains that do not use capsforid */
234 struct config_strlist* caps_whitelist;
235 /** strip away these private addrs from answers, no DNS Rebinding */
236 struct config_strlist* private_address;
237 /** allow domain (and subdomains) to use private address space */
238 struct config_strlist* private_domain;
239 /** what threshold for unwanted action. */
240 size_t unwanted_threshold;
241 /** the number of seconds maximal TTL used for RRsets and messages */
243 /** the number of seconds minimum TTL used for RRsets and messages */
245 /** the number of seconds maximal negative TTL for SOA in auth */
246 int max_negative_ttl;
247 /** if prefetching of messages should be performed. */
249 /** if prefetching of DNSKEYs should be performed. */
252 /** chrootdir, if not "" or chroot will be done */
254 /** username to change to, if not "". */
256 /** working directory */
258 /** filename to log to. */
260 /** pidfile to write pid to. */
263 /** should log messages be sent to syslogd */
265 /** log timestamp in ascii UTC */
267 /** log queries with one line per query */
269 /** log replies with one line per reply */
271 /** log identity to report */
274 /** do not report identity (id.server, hostname.bind) */
276 /** do not report version (version.server, version.bind) */
278 /** do not report trustanchor (trustanchor.unbound) */
279 int hide_trustanchor;
280 /** identity, hostname is returned if "". */
282 /** version, package version returned if "". */
285 /** the module configuration string */
288 /** files with trusted DS and DNSKEYs in zonefile format, list */
289 struct config_strlist* trust_anchor_file_list;
290 /** list of trustanchor keys, linked list */
291 struct config_strlist* trust_anchor_list;
292 /** files with 5011 autotrust tracked keys */
293 struct config_strlist* auto_trust_anchor_file_list;
294 /** files with trusted DNSKEYs in named.conf format, list */
295 struct config_strlist* trusted_keys_file_list;
296 /** DLV anchor file */
297 char* dlv_anchor_file;
298 /** DLV anchor inline */
299 struct config_strlist* dlv_anchor_list;
300 /** insecure domain list */
301 struct config_strlist* domain_insecure;
302 /** send key tag query */
303 int trust_anchor_signaling;
304 /** enable root key sentinel */
305 int root_key_sentinel;
307 /** if not 0, this value is the validation date for RRSIGs */
308 int32_t val_date_override;
309 /** the minimum for signature clock skew */
310 int32_t val_sig_skew_min;
311 /** the maximum for signature clock skew */
312 int32_t val_sig_skew_max;
313 /** this value sets the number of seconds before revalidating bogus */
315 /** should validator clean additional section for secure msgs */
316 int val_clean_additional;
317 /** log bogus messages by the validator */
319 /** squelch val_log_level to log - this is library goes to callback */
321 /** should validator allow bogus messages to go through */
322 int val_permissive_mode;
323 /** use cached NSEC records to synthesise (negative) answers */
325 /** ignore the CD flag in incoming queries and refuse them bogus data */
327 /** serve expired entries and prefetch them */
329 /** nsec3 maximum iterations per key size, string */
330 char* val_nsec3_key_iterations;
331 /** autotrust add holddown time, in seconds */
332 unsigned int add_holddown;
333 /** autotrust del holddown time, in seconds */
334 unsigned int del_holddown;
335 /** autotrust keep_missing time, in seconds. 0 is forever. */
336 unsigned int keep_missing;
337 /** permit small holddown values, allowing 5011 rollover very fast */
338 int permit_small_holddown;
340 /** size of the key cache */
341 size_t key_cache_size;
342 /** slabs in the key cache. */
343 size_t key_cache_slabs;
344 /** size of the neg cache */
345 size_t neg_cache_size;
347 /** local zones config */
348 struct config_str2list* local_zones;
349 /** local zones nodefault list */
350 struct config_strlist* local_zones_nodefault;
351 /** do not add any default local zone */
352 int local_zones_disable_default;
353 /** local data RRs configured */
354 struct config_strlist* local_data;
355 /** local zone override types per netblock */
356 struct config_str3list* local_zone_overrides;
357 /** unblock lan zones (reverse lookups for AS112 zones) */
358 int unblock_lan_zones;
359 /** insecure lan zones (don't validate AS112 zones) */
360 int insecure_lan_zones;
361 /** list of zonename, tagbitlist */
362 struct config_strbytelist* local_zone_tags;
363 /** list of aclname, tagbitlist */
364 struct config_strbytelist* acl_tags;
365 /** list of aclname, tagname, localzonetype */
366 struct config_str3list* acl_tag_actions;
367 /** list of aclname, tagname, redirectdata */
368 struct config_str3list* acl_tag_datas;
369 /** list of aclname, view*/
370 struct config_str2list* acl_view;
371 /** list of IP-netblock, tagbitlist */
372 struct config_strbytelist* respip_tags;
373 /** list of response-driven access control entries, linked list */
374 struct config_str2list* respip_actions;
375 /** RRs configured for response-driven access controls */
376 struct config_str2list* respip_data;
377 /** tag list, array with tagname[i] is malloced string */
379 /** number of items in the taglist */
382 /** remote control section. enable toggle. */
383 int remote_control_enable;
384 /** the interfaces the remote control should listen on */
385 struct config_strlist_head control_ifs;
386 /** if the use-cert option is set */
387 int control_use_cert;
388 /** port number for the control port */
390 /** private key file for server */
391 char* server_key_file;
392 /** certificate file for server */
393 char* server_cert_file;
394 /** private key file for unbound-control */
395 char* control_key_file;
396 /** certificate file for unbound-control */
397 char* control_cert_file;
399 /** Python script file */
402 /** Use systemd socket activation. */
405 /** daemonize, i.e. fork into the background. */
408 /* minimal response when positive answer */
409 int minimal_responses;
411 /* RRSet roundrobin */
412 int rrset_roundrobin;
414 /* maximum UDP response size */
420 /* Synthetize all AAAA record despite the presence of an authoritative one */
423 /** true to enable dnstap support */
425 /** dnstap socket path */
426 char* dnstap_socket_path;
427 /** true to send "identity" via dnstap */
428 int dnstap_send_identity;
429 /** true to send "version" via dnstap */
430 int dnstap_send_version;
431 /** dnstap "identity", hostname is used if "". */
432 char* dnstap_identity;
433 /** dnstap "version", package version is used if "". */
434 char* dnstap_version;
436 /** true to log dnstap RESOLVER_QUERY message events */
437 int dnstap_log_resolver_query_messages;
438 /** true to log dnstap RESOLVER_RESPONSE message events */
439 int dnstap_log_resolver_response_messages;
440 /** true to log dnstap CLIENT_QUERY message events */
441 int dnstap_log_client_query_messages;
442 /** true to log dnstap CLIENT_RESPONSE message events */
443 int dnstap_log_client_response_messages;
444 /** true to log dnstap FORWARDER_QUERY message events */
445 int dnstap_log_forwarder_query_messages;
446 /** true to log dnstap FORWARDER_RESPONSE message events */
447 int dnstap_log_forwarder_response_messages;
449 /** true to disable DNSSEC lameness check in iterator */
450 int disable_dnssec_lame_check;
452 /** ratelimit for ip addresses. 0 is off, otherwise qps (unless overridden) */
454 /** number of slabs for ip_ratelimit cache */
455 size_t ip_ratelimit_slabs;
456 /** memory size in bytes for ip_ratelimit cache */
457 size_t ip_ratelimit_size;
458 /** ip_ratelimit factor, 0 blocks all, 10 allows 1/10 of traffic */
459 int ip_ratelimit_factor;
461 /** ratelimit for domains. 0 is off, otherwise qps (unless overridden) */
463 /** number of slabs for ratelimit cache */
464 size_t ratelimit_slabs;
465 /** memory size in bytes for ratelimit cache */
466 size_t ratelimit_size;
467 /** ratelimits for domain (exact match) */
468 struct config_str2list* ratelimit_for_domain;
469 /** ratelimits below domain */
470 struct config_str2list* ratelimit_below_domain;
471 /** ratelimit factor, 0 blocks all, 10 allows 1/10 of traffic */
472 int ratelimit_factor;
473 /** minimise outgoing QNAME and hide original QTYPE if possible */
474 int qname_minimisation;
475 /** minimise QNAME in strict mode, minimise according to RFC.
476 * Do not apply fallback */
477 int qname_minimisation_strict;
478 /** SHM data - true if shm is enabled */
480 /** SHM data - key for the shm */
484 /** true to enable dnscrypt */
486 /** port on which to provide dnscrypt service */
488 /** provider name 2.dnscrypt-cert.example.com */
489 char* dnscrypt_provider;
490 /** dnscrypt secret keys 1.key */
491 struct config_strlist* dnscrypt_secret_key;
492 /** dnscrypt provider certs 1.cert */
493 struct config_strlist* dnscrypt_provider_cert;
494 /** dnscrypt provider certs 1.cert which have been rotated and should not be
495 * advertised through DNS's providername TXT record but are required to be
496 * able to handle existing traffic using the old cert. */
497 struct config_strlist* dnscrypt_provider_cert_rotated;
498 /** memory size in bytes for dnscrypt shared secrets cache */
499 size_t dnscrypt_shared_secret_cache_size;
500 /** number of slabs for dnscrypt shared secrets cache */
501 size_t dnscrypt_shared_secret_cache_slabs;
502 /** memory size in bytes for dnscrypt nonces cache */
503 size_t dnscrypt_nonce_cache_size;
504 /** number of slabs for dnscrypt nonces cache */
505 size_t dnscrypt_nonce_cache_slabs;
508 /** false to bypass the IPsec module */
509 int ipsecmod_enabled;
510 /** whitelisted domains for ipsecmod */
511 struct config_strlist* ipsecmod_whitelist;
512 /** path to external hook */
514 /** true to proceed even with a bogus IPSECKEY */
515 int ipsecmod_ignore_bogus;
516 /** max TTL for the A/AAAA records that call the hook */
517 int ipsecmod_max_ttl;
518 /** false to proceed even when ipsecmod_hook fails */
524 /** backend DB name */
525 char* cachedb_backend;
526 /** secret seed for hash key calculation */
527 char* cachedb_secret;
529 /** redis server's IP address or host name */
530 char* redis_server_host;
531 /** redis server's TCP port */
532 int redis_server_port;
533 /** timeout (in ms) for communication with the redis server */
539 /** from cfg username, after daemonize setup performed */
540 extern uid_t cfg_uid;
541 /** from cfg username, after daemonize setup performed */
542 extern gid_t cfg_gid;
543 /** debug and enable small timeouts */
544 extern int autr_permit_small_holddown;
547 * Stub config options
551 struct config_stub* next;
552 /** domain name (in text) of the stub apex domain */
554 /** list of stub nameserver hosts (domain name) */
555 struct config_strlist* hosts;
556 /** list of stub nameserver addresses (IP address) */
557 struct config_strlist* addrs;
558 /** if stub-prime is set */
560 /** if forward-first is set (failover to without if fails) */
562 /** use SSL for queries to this stub */
567 * Auth config options
571 struct config_auth* next;
572 /** domain name (in text) of the auth apex domain */
574 /** list of masters */
575 struct config_strlist* masters;
577 struct config_strlist* urls;
578 /** list of allow-notify */
579 struct config_strlist* allow_notify;
580 /** zonefile (or NULL) */
582 /** provide downstream answers */
584 /** provide upstream answers */
586 /** fallback to recursion to authorities if zone expired and other
587 * reasons perhaps (like, query bogus) */
588 int fallback_enabled;
592 * View config options
596 struct config_view* next;
600 struct config_str2list* local_zones;
601 /** local data RRs */
602 struct config_strlist* local_data;
603 /** local zones nodefault list */
604 struct config_strlist* local_zones_nodefault;
605 /** Fallback to global local_zones when there is no match in the view
606 * view specific tree. 1 for yes, 0 for no */
608 /** predefined actions for particular IP address responses */
609 struct config_str2list* respip_actions;
610 /** data complementing the 'redirect' response IP actions */
611 struct config_str2list* respip_data;
615 * List of strings for config options
617 struct config_strlist {
618 /** next item in list */
619 struct config_strlist* next;
620 /** config option string */
625 * List of two strings for config options
627 struct config_str2list {
628 /** next item in list */
629 struct config_str2list* next;
637 * List of three strings for config options
639 struct config_str3list {
640 /** next item in list */
641 struct config_str3list* next;
652 * List of string, bytestring for config options
654 struct config_strbytelist {
655 /** next item in list */
656 struct config_strbytelist* next;
659 /** second bytestring */
665 * Create config file structure. Filled with default values.
666 * @return: the new structure or NULL on memory error.
668 struct config_file* config_create(void);
671 * Create config file structure for library use. Filled with default values.
672 * @return: the new structure or NULL on memory error.
674 struct config_file* config_create_forlib(void);
677 * Read the config file from the specified filename.
678 * @param config: where options are stored into, must be freshly created.
679 * @param filename: name of configfile. If NULL nothing is done.
680 * @param chroot: if not NULL, the chroot dir currently in use (for include).
681 * @return: false on error. In that case errno is set, ENOENT means
684 int config_read(struct config_file* config, const char* filename,
688 * Destroy the config file structure.
689 * @param config: to delete.
691 void config_delete(struct config_file* config);
694 * Apply config to global constants; this routine is called in single thread.
695 * @param config: to apply. Side effect: global constants change.
697 void config_apply(struct config_file* config);
700 * Find username, sets cfg_uid and cfg_gid.
701 * @param config: the config structure.
703 void config_lookup_uid(struct config_file* config);
706 * Set the given keyword to the given value.
707 * @param config: where to store config
708 * @param option: option name, including the ':' character.
709 * @param value: value, this string is copied if needed, or parsed.
710 * The caller owns the value string.
711 * @return 0 on error (malloc or syntax error).
713 int config_set_option(struct config_file* config, const char* option,
717 * Call print routine for the given option.
718 * @param cfg: config.
719 * @param opt: option name without trailing :.
720 * This is different from config_set_option.
721 * @param func: print func, called as (str, arg) for every data element.
722 * @param arg: user argument for print func.
723 * @return false if the option name is not supported (syntax error).
725 int config_get_option(struct config_file* cfg, const char* opt,
726 void (*func)(char*,void*), void* arg);
729 * Get an option and return strlist
730 * @param cfg: config file
731 * @param opt: option name.
732 * @param list: list is returned here. malloced, caller must free it.
733 * @return 0=OK, 1=syntax error, 2=malloc failed.
735 int config_get_option_list(struct config_file* cfg, const char* opt,
736 struct config_strlist** list);
739 * Get an option and collate results into string
740 * @param cfg: config file
741 * @param opt: option name.
742 * @param str: string. malloced, caller must free it.
743 * @return 0=OK, 1=syntax error, 2=malloc failed.
745 int config_get_option_collate(struct config_file* cfg, const char* opt,
749 * function to print to a file, use as func with config_get_option.
750 * @param line: text to print. \n appended.
751 * @param arg: pass a FILE*, like stdout.
753 void config_print_func(char* line, void* arg);
756 * function to collate the text strings into a strlist_head.
757 * @param line: text to append.
758 * @param arg: pass a strlist_head structure. zeroed on start.
760 void config_collate_func(char* line, void* arg);
763 * take a strlist_head list and return a malloc string. separated with newline.
764 * @param list: strlist first to collate. zeroes return "".
765 * @return NULL on malloc failure. Or if malloc failure happened in strlist.
767 char* config_collate_cat(struct config_strlist* list);
770 * Append text at end of list.
771 * @param list: list head. zeroed at start.
772 * @param item: new item. malloced by caller. if NULL the insertion fails.
773 * @return true on success.
775 int cfg_strlist_append(struct config_strlist_head* list, char* item);
778 * Find string in strlist.
779 * @param head: pointer to strlist head variable.
780 * @param item: the item to search for.
781 * @return: the element in the list when found, NULL otherwise.
783 struct config_strlist* cfg_strlist_find(struct config_strlist* head,
787 * Insert string into strlist.
788 * @param head: pointer to strlist head variable.
789 * @param item: new item. malloced by caller. If NULL the insertion fails.
790 * @return: true on success.
792 int cfg_strlist_insert(struct config_strlist** head, char* item);
794 /** insert with region for allocation. */
795 int cfg_region_strlist_insert(struct regional* region,
796 struct config_strlist** head, char* item);
799 * Insert string into str2list.
800 * @param head: pointer to str2list head variable.
801 * @param item: new item. malloced by caller. If NULL the insertion fails.
802 * @param i2: 2nd string, malloced by caller. If NULL the insertion fails.
803 * @return: true on success.
805 int cfg_str2list_insert(struct config_str2list** head, char* item, char* i2);
808 * Insert string into str3list.
809 * @param head: pointer to str3list head variable.
810 * @param item: new item. malloced by caller. If NULL the insertion fails.
811 * @param i2: 2nd string, malloced by caller. If NULL the insertion fails.
812 * @param i3: 3rd string, malloced by caller. If NULL the insertion fails.
813 * @return: true on success.
815 int cfg_str3list_insert(struct config_str3list** head, char* item, char* i2,
819 * Insert string into strbytelist.
820 * @param head: pointer to strbytelist head variable.
821 * @param item: new item. malloced by caller. If NULL the insertion fails.
822 * @param i2: 2nd string, malloced by caller. If NULL the insertion fails.
823 * @param i2len: length of the i2 bytestring.
824 * @return: true on success.
826 int cfg_strbytelist_insert(struct config_strbytelist** head, char* item,
827 uint8_t* i2, size_t i2len);
830 * Find stub in config list, also returns prevptr (for deletion).
831 * @param pp: call routine with pointer to a pointer to the start of the list,
832 * if the stub is found, on exit, the value contains a pointer to the
833 * next pointer that points to the found element (or to the list start
834 * pointer if it is the first element).
835 * @param nm: name of stub to find.
836 * @return: pointer to config_stub if found, or NULL if not found.
838 struct config_stub* cfg_stub_find(struct config_stub*** pp, const char* nm);
841 * Delete items in config string list.
844 void config_delstrlist(struct config_strlist* list);
847 * Delete items in config double string list.
850 void config_deldblstrlist(struct config_str2list* list);
853 * Delete items in config triple string list.
856 void config_deltrplstrlist(struct config_str3list* list);
858 /** delete stringbytelist */
859 void config_del_strbytelist(struct config_strbytelist* list);
863 * @param p: stub item
865 void config_delstub(struct config_stub* p);
868 * Delete items in config stub list.
871 void config_delstubs(struct config_stub* list);
874 * Delete an auth item
875 * @param p: auth item
877 void config_delauth(struct config_auth* p);
880 * Delete items in config auth list.
883 void config_delauths(struct config_auth* list);
887 * @param p: view item
889 void config_delview(struct config_view* p);
892 * Delete items in config view list.
895 void config_delviews(struct config_view* list);
897 /** check if config for remote control turns on IP-address interface
898 * with certificates or a named pipe without certificates. */
899 int options_remote_is_address(struct config_file* cfg);
902 * Convert 14digit to time value
903 * @param str: string of 14 digits
904 * @return time value or 0 for error.
906 time_t cfg_convert_timeval(const char* str);
909 * Count number of values in the string.
910 * format ::= (sp num)+ sp
912 * sp ::= (space|tab)*
915 * @return: 0 on parse error, or empty string, else
916 * number of integer values in the string.
918 int cfg_count_numbers(const char* str);
921 * Convert a 'nice' memory or file size into a bytecount
922 * From '100k' to 102400. and so on. Understands kKmMgG.
923 * k=1024, m=1024*1024, g=1024*1024*1024.
925 * @param res: result is stored here, size in bytes.
926 * @return: true if parsed correctly, or 0 on a parse error (and an error
929 int cfg_parse_memsize(const char* str, size_t* res);
932 * Add a tag name to the config. It is added at the end with a new ID value.
933 * @param cfg: the config structure.
934 * @param tag: string (which is copied) with the name.
935 * @return: false on alloc failure.
937 int config_add_tag(struct config_file* cfg, const char* tag);
940 * Find tag ID in the tag list.
941 * @param cfg: the config structure.
942 * @param tag: string with tag name to search for.
943 * @return: 0..(num_tags-1) with tag ID, or -1 if tagname is not found.
945 int find_tag_id(struct config_file* cfg, const char* tag);
948 * parse taglist from string into bytestring with bitlist.
949 * @param cfg: the config structure (with tagnames)
950 * @param str: the string to parse. Parse puts 0 bytes in string.
951 * @param listlen: returns length of in bytes.
952 * @return malloced bytes with a bitlist of the tags. or NULL on parse error
955 uint8_t* config_parse_taglist(struct config_file* cfg, char* str,
959 * convert tag bitlist to a malloced string with tag names. For debug output.
960 * @param cfg: the config structure (with tagnames)
961 * @param taglist: the tag bitlist.
962 * @param len: length of the tag bitlist.
963 * @return malloced string or NULL.
965 char* config_taglist2str(struct config_file* cfg, uint8_t* taglist,
969 * see if two taglists intersect (have tags in common).
970 * @param list1: first tag bitlist.
971 * @param list1len: length in bytes of first list.
972 * @param list2: second tag bitlist.
973 * @param list2len: length in bytes of second list.
974 * @return true if there are tags in common, 0 if not.
976 int taglist_intersect(uint8_t* list1, size_t list1len, uint8_t* list2,
980 * Parse local-zone directive into two strings and register it in the config.
981 * @param cfg: to put it in.
982 * @param val: argument strings to local-zone, "example.com nodefault".
983 * @return: false on failure
985 int cfg_parse_local_zone(struct config_file* cfg, const char* val);
988 * Mark "number" or "low-high" as available or not in ports array.
989 * @param str: string in input
990 * @param allow: give true if this range is permitted.
991 * @param avail: the array from cfg.
992 * @param num: size of the array (65536).
993 * @return: true if parsed correctly, or 0 on a parse error (and an error
996 int cfg_mark_ports(const char* str, int allow, int* avail, int num);
999 * Get a condensed list of ports returned. allocated.
1000 * @param cfg: config file.
1001 * @param avail: the available ports array is returned here.
1002 * @return: number of ports in array or 0 on error.
1004 int cfg_condense_ports(struct config_file* cfg, int** avail);
1007 * Scan ports available
1008 * @param avail: the array from cfg.
1009 * @param num: size of the array (65536).
1010 * @return the number of ports available for use.
1012 int cfg_scan_ports(int* avail, int num);
1015 * Convert a filename to full pathname in original filesys
1016 * @param fname: the path name to convert.
1017 * Must not be null or empty.
1018 * @param cfg: config struct for chroot and chdir (if set).
1019 * @param use_chdir: if false, only chroot is applied.
1020 * @return pointer to malloced buffer which is: [chroot][chdir]fname
1021 * or NULL on malloc failure.
1023 char* fname_after_chroot(const char* fname, struct config_file* cfg,
1027 * Convert a ptr shorthand into a full reverse-notation PTR record.
1028 * @param str: input string, "IP name"
1029 * @return: malloced string "reversed-ip-name PTR name"
1031 char* cfg_ptr_reverse(char* str);
1034 * Append text to the error info for validation.
1035 * @param qstate: query state.
1036 * @param str: copied into query region and appended.
1037 * Failures to allocate are logged.
1039 void errinf(struct module_qstate* qstate, const char* str);
1042 * Append text to error info: from 1.2.3.4
1043 * @param qstate: query state.
1044 * @param origin: sock list with origin of trouble.
1045 * Every element added.
1046 * If NULL: nothing is added.
1047 * if 0len element: 'from cache' is added.
1049 void errinf_origin(struct module_qstate* qstate, struct sock_list *origin);
1052 * Append text to error info: for RRset name type class
1053 * @param qstate: query state.
1054 * @param rr: rrset_key.
1056 void errinf_rrset(struct module_qstate* qstate, struct ub_packed_rrset_key *rr);
1059 * Append text to error info: str dname
1060 * @param qstate: query state.
1061 * @param str: explanation string
1062 * @param dname: the dname.
1064 void errinf_dname(struct module_qstate* qstate, const char* str,
1068 * Create error info in string
1069 * @param qstate: query state.
1070 * @return string or NULL on malloc failure (already logged).
1071 * This string is malloced and has to be freed by caller.
1073 char* errinf_to_str(struct module_qstate* qstate);
1076 * Used during options parsing
1078 struct config_parser_state {
1079 /** name of file being parser */
1081 /** line number in the file, starts at 1 */
1083 /** number of errors encountered */
1085 /** the result of parsing is stored here. */
1086 struct config_file* cfg;
1087 /** the current chroot dir (or NULL if none) */
1091 /** global config parser object used during config parsing */
1092 extern struct config_parser_state* cfg_parser;
1093 /** init lex state */
1094 void init_cfg_parse(void);
1096 extern FILE* ub_c_in;
1098 extern FILE* ub_c_out;
1099 /** the yacc lex generated parse function */
1100 int ub_c_parse(void);
1101 /** the lexer function */
1103 /** wrap function */
1104 int ub_c_wrap(void);
1105 /** parsing helpers: print error with file and line numbers */
1106 void ub_c_error(const char* msg);
1107 /** parsing helpers: print error with file and line numbers */
1108 void ub_c_error_msg(const char* fmt, ...) ATTR_FORMAT(printf, 1, 2);
1110 #ifdef UB_ON_WINDOWS
1112 * Obtain registry string (if it exists).
1113 * @param key: key string
1114 * @param name: name of value to fetch.
1115 * @return malloced string with the result or NULL if it did not
1116 * exist on an error (logged with log_err) was encountered.
1118 char* w_lookup_reg_str(const char* key, const char* name);
1120 /** Modify directory in options for module file name */
1121 void w_config_adjust_directory(struct config_file* cfg);
1122 #endif /* UB_ON_WINDOWS */
1124 /** debug option for unit tests. */
1125 extern int fake_dsa, fake_sha1;
1127 #endif /* UTIL_CONFIG_FILE_H */