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;
57 * The configuration options.
58 * Strings are malloced.
61 /** verbosity level as specified in the config file */
64 /** statistics interval (in seconds) */
66 /** if false, statistics values are reset after printing them */
68 /** if true, the statistics are kept in greater detail */
71 /** number of threads to create */
74 /** port on which queries are answered. */
76 /** do ip4 query support. */
78 /** do ip6 query support. */
80 /** prefer ip6 upstream queries. */
82 /** do udp query support. */
84 /** do tcp query support. */
86 /** tcp upstream queries (no UDP upstream queries) */
88 /** udp upstream enabled when no UDP downstream is enabled (do_udp no)*/
89 int udp_upstream_without_downstream;
90 /** maximum segment size of tcp socket which queries are answered */
92 /** maximum segment size of tcp socket for outgoing queries */
95 /** private key file for dnstcp-ssl service (enabled if not NULL) */
96 char* ssl_service_key;
97 /** public key file for dnstcp-ssl service */
98 char* ssl_service_pem;
99 /** port on which to provide ssl service */
101 /** if outgoing tcp connections use SSL */
103 /** cert bundle for outgoing connections */
104 char* tls_cert_bundle;
105 /** additional tls ports */
106 struct config_strlist* additional_tls_port;
108 /** outgoing port range number of ports (per thread) */
109 int outgoing_num_ports;
110 /** number of outgoing tcp buffers per (per thread) */
111 size_t outgoing_num_tcp;
112 /** number of incoming tcp buffers per (per thread) */
113 size_t incoming_num_tcp;
114 /** allowed udp port numbers, array with 0 if not allowed */
115 int* outgoing_avail_ports;
117 /** EDNS buffer size to use */
118 size_t edns_buffer_size;
119 /** number of bytes buffer size for DNS messages */
120 size_t msg_buffer_size;
121 /** size of the message cache */
122 size_t msg_cache_size;
123 /** slabs in the message cache. */
124 size_t msg_cache_slabs;
125 /** number of queries every thread can service */
126 size_t num_queries_per_thread;
127 /** number of msec to wait before items can be jostled out */
129 /** size of the rrset cache */
130 size_t rrset_cache_size;
131 /** slabs in the rrset cache */
132 size_t rrset_cache_slabs;
133 /** host cache ttl in seconds */
135 /** number of slabs in the infra host cache */
136 size_t infra_cache_slabs;
137 /** max number of hosts in the infra cache */
138 size_t infra_cache_numhosts;
139 /** min value for infra cache rtt */
140 int infra_cache_min_rtt;
141 /** delay close of udp-timeouted ports, if 0 no delayclose. in msec */
144 /** the target fetch policy for the iterator */
145 char* target_fetch_policy;
146 /** percent*10, how many times in 1000 to pick low rtt destinations */
148 /** what time in msec is a low rtt destination */
151 /** automatic interface for incoming messages. Uses ipv6 remapping,
152 * and recvmsg/sendmsg ancillary data to detect interfaces, boolean */
154 /** SO_RCVBUF size to set on port 53 UDP socket */
156 /** SO_SNDBUF size to set on port 53 UDP socket */
158 /** SO_REUSEPORT requested on port 53 sockets */
160 /** IP_TRANSPARENT socket option requested on port 53 sockets */
162 /** IP_FREEBIND socket option request on port 53 sockets */
165 /** number of interfaces to open. If 0 default all interfaces. */
167 /** interface description strings (IP addresses) */
170 /** number of outgoing interfaces to open.
171 * If 0 default all interfaces. */
173 /** outgoing interface description strings (IP addresses) */
176 /** the root hints */
177 struct config_strlist* root_hints;
178 /** the stub definitions, linked list */
179 struct config_stub* stubs;
180 /** the forward zone definitions, linked list */
181 struct config_stub* forwards;
182 /** the auth zone definitions, linked list */
183 struct config_auth* auths;
184 /** the views definitions, linked list */
185 struct config_view* views;
186 /** list of donotquery addresses, linked list */
187 struct config_strlist* donotqueryaddrs;
189 /** list of servers we send edns-client-subnet option to and
190 * accept option from, linked list */
191 struct config_strlist* client_subnet;
192 /** list of zones we send edns-client-subnet option for */
193 struct config_strlist* client_subnet_zone;
194 /** opcode assigned by IANA for edns0-client-subnet option */
195 uint16_t client_subnet_opcode;
196 /** Do not check whitelist if incoming query contains an ECS record */
197 int client_subnet_always_forward;
198 /** Subnet length we are willing to give up privacy for */
199 uint8_t max_client_subnet_ipv4;
200 uint8_t max_client_subnet_ipv6;
202 /** list of access control entries, linked list */
203 struct config_str2list* acls;
204 /** use default localhost donotqueryaddr entries */
205 int donotquery_localhost;
207 /** harden against very small edns buffer sizes */
208 int harden_short_bufsize;
209 /** harden against very large query sizes */
210 int harden_large_queries;
211 /** harden against spoofed glue (out of zone data) */
213 /** harden against receiving no DNSSEC data for trust anchor */
214 int harden_dnssec_stripped;
215 /** harden against queries that fall under known nxdomain names */
216 int harden_below_nxdomain;
217 /** harden the referral path, query for NS,A,AAAA and validate */
218 int harden_referral_path;
219 /** harden against algorithm downgrade */
220 int harden_algo_downgrade;
221 /** use 0x20 bits in query as random ID bits */
222 int use_caps_bits_for_id;
223 /** 0x20 whitelist, domains that do not use capsforid */
224 struct config_strlist* caps_whitelist;
225 /** strip away these private addrs from answers, no DNS Rebinding */
226 struct config_strlist* private_address;
227 /** allow domain (and subdomains) to use private address space */
228 struct config_strlist* private_domain;
229 /** what threshold for unwanted action. */
230 size_t unwanted_threshold;
231 /** the number of seconds maximal TTL used for RRsets and messages */
233 /** the number of seconds minimum TTL used for RRsets and messages */
235 /** the number of seconds maximal negative TTL for SOA in auth */
236 int max_negative_ttl;
237 /** if prefetching of messages should be performed. */
239 /** if prefetching of DNSKEYs should be performed. */
242 /** chrootdir, if not "" or chroot will be done */
244 /** username to change to, if not "". */
246 /** working directory */
248 /** filename to log to. */
250 /** pidfile to write pid to. */
253 /** should log messages be sent to syslogd */
255 /** log timestamp in ascii UTC */
257 /** log queries with one line per query */
259 /** log replies with one line per reply */
261 /** log identity to report */
264 /** do not report identity (id.server, hostname.bind) */
266 /** do not report version (version.server, version.bind) */
268 /** do not report trustanchor (trustanchor.unbound) */
269 int hide_trustanchor;
270 /** identity, hostname is returned if "". */
272 /** version, package version returned if "". */
275 /** the module configuration string */
278 /** files with trusted DS and DNSKEYs in zonefile format, list */
279 struct config_strlist* trust_anchor_file_list;
280 /** list of trustanchor keys, linked list */
281 struct config_strlist* trust_anchor_list;
282 /** files with 5011 autotrust tracked keys */
283 struct config_strlist* auto_trust_anchor_file_list;
284 /** files with trusted DNSKEYs in named.conf format, list */
285 struct config_strlist* trusted_keys_file_list;
286 /** DLV anchor file */
287 char* dlv_anchor_file;
288 /** DLV anchor inline */
289 struct config_strlist* dlv_anchor_list;
290 /** insecure domain list */
291 struct config_strlist* domain_insecure;
292 /** send key tag query */
293 int trust_anchor_signaling;
294 /** enable root key sentinel */
295 int root_key_sentinel;
297 /** if not 0, this value is the validation date for RRSIGs */
298 int32_t val_date_override;
299 /** the minimum for signature clock skew */
300 int32_t val_sig_skew_min;
301 /** the maximum for signature clock skew */
302 int32_t val_sig_skew_max;
303 /** this value sets the number of seconds before revalidating bogus */
305 /** should validator clean additional section for secure msgs */
306 int val_clean_additional;
307 /** log bogus messages by the validator */
309 /** squelch val_log_level to log - this is library goes to callback */
311 /** should validator allow bogus messages to go through */
312 int val_permissive_mode;
313 /** use cached NSEC records to synthesise (negative) answers */
315 /** ignore the CD flag in incoming queries and refuse them bogus data */
317 /** serve expired entries and prefetch them */
319 /** nsec3 maximum iterations per key size, string */
320 char* val_nsec3_key_iterations;
321 /** autotrust add holddown time, in seconds */
322 unsigned int add_holddown;
323 /** autotrust del holddown time, in seconds */
324 unsigned int del_holddown;
325 /** autotrust keep_missing time, in seconds. 0 is forever. */
326 unsigned int keep_missing;
327 /** permit small holddown values, allowing 5011 rollover very fast */
328 int permit_small_holddown;
330 /** size of the key cache */
331 size_t key_cache_size;
332 /** slabs in the key cache. */
333 size_t key_cache_slabs;
334 /** size of the neg cache */
335 size_t neg_cache_size;
337 /** local zones config */
338 struct config_str2list* local_zones;
339 /** local zones nodefault list */
340 struct config_strlist* local_zones_nodefault;
341 /** do not add any default local zone */
342 int local_zones_disable_default;
343 /** local data RRs configured */
344 struct config_strlist* local_data;
345 /** local zone override types per netblock */
346 struct config_str3list* local_zone_overrides;
347 /** unblock lan zones (reverse lookups for AS112 zones) */
348 int unblock_lan_zones;
349 /** insecure lan zones (don't validate AS112 zones) */
350 int insecure_lan_zones;
351 /** list of zonename, tagbitlist */
352 struct config_strbytelist* local_zone_tags;
353 /** list of aclname, tagbitlist */
354 struct config_strbytelist* acl_tags;
355 /** list of aclname, tagname, localzonetype */
356 struct config_str3list* acl_tag_actions;
357 /** list of aclname, tagname, redirectdata */
358 struct config_str3list* acl_tag_datas;
359 /** list of aclname, view*/
360 struct config_str2list* acl_view;
361 /** list of IP-netblock, tagbitlist */
362 struct config_strbytelist* respip_tags;
363 /** list of response-driven access control entries, linked list */
364 struct config_str2list* respip_actions;
365 /** RRs configured for response-driven access controls */
366 struct config_str2list* respip_data;
367 /** tag list, array with tagname[i] is malloced string */
369 /** number of items in the taglist */
372 /** remote control section. enable toggle. */
373 int remote_control_enable;
374 /** the interfaces the remote control should listen on */
375 struct config_strlist* control_ifs;
376 /** port number for the control port */
378 /** use certificates for remote control */
379 int remote_control_use_cert;
380 /** private key file for server */
381 char* server_key_file;
382 /** certificate file for server */
383 char* server_cert_file;
384 /** private key file for unbound-control */
385 char* control_key_file;
386 /** certificate file for unbound-control */
387 char* control_cert_file;
389 /** Python script file */
392 /** Use systemd socket activation. */
395 /** daemonize, i.e. fork into the background. */
398 /* minimal response when positive answer */
399 int minimal_responses;
401 /* RRSet roundrobin */
402 int rrset_roundrobin;
404 /* maximum UDP response size */
410 /* Synthetize all AAAA record despite the presence of an authoritative one */
413 /** true to enable dnstap support */
415 /** dnstap socket path */
416 char* dnstap_socket_path;
417 /** true to send "identity" via dnstap */
418 int dnstap_send_identity;
419 /** true to send "version" via dnstap */
420 int dnstap_send_version;
421 /** dnstap "identity", hostname is used if "". */
422 char* dnstap_identity;
423 /** dnstap "version", package version is used if "". */
424 char* dnstap_version;
426 /** true to log dnstap RESOLVER_QUERY message events */
427 int dnstap_log_resolver_query_messages;
428 /** true to log dnstap RESOLVER_RESPONSE message events */
429 int dnstap_log_resolver_response_messages;
430 /** true to log dnstap CLIENT_QUERY message events */
431 int dnstap_log_client_query_messages;
432 /** true to log dnstap CLIENT_RESPONSE message events */
433 int dnstap_log_client_response_messages;
434 /** true to log dnstap FORWARDER_QUERY message events */
435 int dnstap_log_forwarder_query_messages;
436 /** true to log dnstap FORWARDER_RESPONSE message events */
437 int dnstap_log_forwarder_response_messages;
439 /** true to disable DNSSEC lameness check in iterator */
440 int disable_dnssec_lame_check;
442 /** ratelimit for ip addresses. 0 is off, otherwise qps (unless overridden) */
444 /** number of slabs for ip_ratelimit cache */
445 size_t ip_ratelimit_slabs;
446 /** memory size in bytes for ip_ratelimit cache */
447 size_t ip_ratelimit_size;
448 /** ip_ratelimit factor, 0 blocks all, 10 allows 1/10 of traffic */
449 int ip_ratelimit_factor;
451 /** ratelimit for domains. 0 is off, otherwise qps (unless overridden) */
453 /** number of slabs for ratelimit cache */
454 size_t ratelimit_slabs;
455 /** memory size in bytes for ratelimit cache */
456 size_t ratelimit_size;
457 /** ratelimits for domain (exact match) */
458 struct config_str2list* ratelimit_for_domain;
459 /** ratelimits below domain */
460 struct config_str2list* ratelimit_below_domain;
461 /** ratelimit factor, 0 blocks all, 10 allows 1/10 of traffic */
462 int ratelimit_factor;
463 /** minimise outgoing QNAME and hide original QTYPE if possible */
464 int qname_minimisation;
465 /** minimise QNAME in strict mode, minimise according to RFC.
466 * Do not apply fallback */
467 int qname_minimisation_strict;
468 /** SHM data - true if shm is enabled */
470 /** SHM data - key for the shm */
474 /** true to enable dnscrypt */
476 /** port on which to provide dnscrypt service */
478 /** provider name 2.dnscrypt-cert.example.com */
479 char* dnscrypt_provider;
480 /** dnscrypt secret keys 1.key */
481 struct config_strlist* dnscrypt_secret_key;
482 /** dnscrypt provider certs 1.cert */
483 struct config_strlist* dnscrypt_provider_cert;
484 /** dnscrypt provider certs 1.cert which have been rotated and should not be
485 * advertised through DNS's providername TXT record but are required to be
486 * able to handle existing traffic using the old cert. */
487 struct config_strlist* dnscrypt_provider_cert_rotated;
488 /** memory size in bytes for dnscrypt shared secrets cache */
489 size_t dnscrypt_shared_secret_cache_size;
490 /** number of slabs for dnscrypt shared secrets cache */
491 size_t dnscrypt_shared_secret_cache_slabs;
492 /** memory size in bytes for dnscrypt nonces cache */
493 size_t dnscrypt_nonce_cache_size;
494 /** number of slabs for dnscrypt nonces cache */
495 size_t dnscrypt_nonce_cache_slabs;
498 /** false to bypass the IPsec module */
499 int ipsecmod_enabled;
500 /** whitelisted domains for ipsecmod */
501 struct config_strlist* ipsecmod_whitelist;
502 /** path to external hook */
504 /** true to proceed even with a bogus IPSECKEY */
505 int ipsecmod_ignore_bogus;
506 /** max TTL for the A/AAAA records that call the hook */
507 int ipsecmod_max_ttl;
508 /** false to proceed even when ipsecmod_hook fails */
514 /** backend DB name */
515 char* cachedb_backend;
516 /** secret seed for hash key calculation */
517 char* cachedb_secret;
519 /** redis server's IP address or host name */
520 char* redis_server_host;
521 /** redis server's TCP port */
522 int redis_server_port;
523 /** timeout (in ms) for communication with the redis server */
529 /** from cfg username, after daemonize setup performed */
530 extern uid_t cfg_uid;
531 /** from cfg username, after daemonize setup performed */
532 extern gid_t cfg_gid;
533 /** debug and enable small timeouts */
534 extern int autr_permit_small_holddown;
537 * Stub config options
541 struct config_stub* next;
542 /** domain name (in text) of the stub apex domain */
544 /** list of stub nameserver hosts (domain name) */
545 struct config_strlist* hosts;
546 /** list of stub nameserver addresses (IP address) */
547 struct config_strlist* addrs;
548 /** if stub-prime is set */
550 /** if forward-first is set (failover to without if fails) */
552 /** use SSL for queries to this stub */
557 * Auth config options
561 struct config_auth* next;
562 /** domain name (in text) of the auth apex domain */
564 /** list of masters */
565 struct config_strlist* masters;
567 struct config_strlist* urls;
568 /** list of allow-notify */
569 struct config_strlist* allow_notify;
570 /** zonefile (or NULL) */
572 /** provide downstream answers */
574 /** provide upstream answers */
576 /** fallback to recursion to authorities if zone expired and other
577 * reasons perhaps (like, query bogus) */
578 int fallback_enabled;
582 * View config options
586 struct config_view* next;
590 struct config_str2list* local_zones;
591 /** local data RRs */
592 struct config_strlist* local_data;
593 /** local zones nodefault list */
594 struct config_strlist* local_zones_nodefault;
595 /** Fallback to global local_zones when there is no match in the view
596 * view specific tree. 1 for yes, 0 for no */
598 /** predefined actions for particular IP address responses */
599 struct config_str2list* respip_actions;
600 /** data complementing the 'redirect' response IP actions */
601 struct config_str2list* respip_data;
605 * List of strings for config options
607 struct config_strlist {
608 /** next item in list */
609 struct config_strlist* next;
610 /** config option string */
615 * List of two strings for config options
617 struct config_str2list {
618 /** next item in list */
619 struct config_str2list* next;
627 * List of three strings for config options
629 struct config_str3list {
630 /** next item in list */
631 struct config_str3list* next;
642 * List of string, bytestring for config options
644 struct config_strbytelist {
645 /** next item in list */
646 struct config_strbytelist* next;
649 /** second bytestring */
654 /** List head for strlist processing, used for append operation. */
655 struct config_strlist_head {
656 /** first in list of text items */
657 struct config_strlist* first;
658 /** last in list of text items */
659 struct config_strlist* last;
663 * Create config file structure. Filled with default values.
664 * @return: the new structure or NULL on memory error.
666 struct config_file* config_create(void);
669 * Create config file structure for library use. Filled with default values.
670 * @return: the new structure or NULL on memory error.
672 struct config_file* config_create_forlib(void);
675 * Read the config file from the specified filename.
676 * @param config: where options are stored into, must be freshly created.
677 * @param filename: name of configfile. If NULL nothing is done.
678 * @param chroot: if not NULL, the chroot dir currently in use (for include).
679 * @return: false on error. In that case errno is set, ENOENT means
682 int config_read(struct config_file* config, const char* filename,
686 * Destroy the config file structure.
687 * @param config: to delete.
689 void config_delete(struct config_file* config);
692 * Apply config to global constants; this routine is called in single thread.
693 * @param config: to apply. Side effect: global constants change.
695 void config_apply(struct config_file* config);
698 * Find username, sets cfg_uid and cfg_gid.
699 * @param config: the config structure.
701 void config_lookup_uid(struct config_file* config);
704 * Set the given keyword to the given value.
705 * @param config: where to store config
706 * @param option: option name, including the ':' character.
707 * @param value: value, this string is copied if needed, or parsed.
708 * The caller owns the value string.
709 * @return 0 on error (malloc or syntax error).
711 int config_set_option(struct config_file* config, const char* option,
715 * Call print routine for the given option.
716 * @param cfg: config.
717 * @param opt: option name without trailing :.
718 * This is different from config_set_option.
719 * @param func: print func, called as (str, arg) for every data element.
720 * @param arg: user argument for print func.
721 * @return false if the option name is not supported (syntax error).
723 int config_get_option(struct config_file* cfg, const char* opt,
724 void (*func)(char*,void*), void* arg);
727 * Get an option and return strlist
728 * @param cfg: config file
729 * @param opt: option name.
730 * @param list: list is returned here. malloced, caller must free it.
731 * @return 0=OK, 1=syntax error, 2=malloc failed.
733 int config_get_option_list(struct config_file* cfg, const char* opt,
734 struct config_strlist** list);
737 * Get an option and collate results into string
738 * @param cfg: config file
739 * @param opt: option name.
740 * @param str: string. malloced, caller must free it.
741 * @return 0=OK, 1=syntax error, 2=malloc failed.
743 int config_get_option_collate(struct config_file* cfg, const char* opt,
747 * function to print to a file, use as func with config_get_option.
748 * @param line: text to print. \n appended.
749 * @param arg: pass a FILE*, like stdout.
751 void config_print_func(char* line, void* arg);
754 * function to collate the text strings into a strlist_head.
755 * @param line: text to append.
756 * @param arg: pass a strlist_head structure. zeroed on start.
758 void config_collate_func(char* line, void* arg);
761 * take a strlist_head list and return a malloc string. separated with newline.
762 * @param list: strlist first to collate. zeroes return "".
763 * @return NULL on malloc failure. Or if malloc failure happened in strlist.
765 char* config_collate_cat(struct config_strlist* list);
768 * Append text at end of list.
769 * @param list: list head. zeroed at start.
770 * @param item: new item. malloced by caller. if NULL the insertion fails.
771 * @return true on success.
773 int cfg_strlist_append(struct config_strlist_head* list, char* item);
776 * Find string in strlist.
777 * @param head: pointer to strlist head variable.
778 * @param item: the item to search for.
779 * @return: the element in the list when found, NULL otherwise.
781 struct config_strlist* cfg_strlist_find(struct config_strlist* head,
785 * Insert string into strlist.
786 * @param head: pointer to strlist head variable.
787 * @param item: new item. malloced by caller. If NULL the insertion fails.
788 * @return: true on success.
790 int cfg_strlist_insert(struct config_strlist** head, char* item);
792 /** insert with region for allocation. */
793 int cfg_region_strlist_insert(struct regional* region,
794 struct config_strlist** head, char* item);
797 * Insert string into str2list.
798 * @param head: pointer to str2list head variable.
799 * @param item: new item. malloced by caller. If NULL the insertion fails.
800 * @param i2: 2nd string, malloced by caller. If NULL the insertion fails.
801 * @return: true on success.
803 int cfg_str2list_insert(struct config_str2list** head, char* item, char* i2);
806 * Insert string into str3list.
807 * @param head: pointer to str3list head variable.
808 * @param item: new item. malloced by caller. If NULL the insertion fails.
809 * @param i2: 2nd string, malloced by caller. If NULL the insertion fails.
810 * @param i3: 3rd string, malloced by caller. If NULL the insertion fails.
811 * @return: true on success.
813 int cfg_str3list_insert(struct config_str3list** head, char* item, char* i2,
817 * Insert string into strbytelist.
818 * @param head: pointer to strbytelist head variable.
819 * @param item: new item. malloced by caller. If NULL the insertion fails.
820 * @param i2: 2nd string, malloced by caller. If NULL the insertion fails.
821 * @param i2len: length of the i2 bytestring.
822 * @return: true on success.
824 int cfg_strbytelist_insert(struct config_strbytelist** head, char* item,
825 uint8_t* i2, size_t i2len);
828 * Find stub in config list, also returns prevptr (for deletion).
829 * @param pp: call routine with pointer to a pointer to the start of the list,
830 * if the stub is found, on exit, the value contains a pointer to the
831 * next pointer that points to the found element (or to the list start
832 * pointer if it is the first element).
833 * @param nm: name of stub to find.
834 * @return: pointer to config_stub if found, or NULL if not found.
836 struct config_stub* cfg_stub_find(struct config_stub*** pp, const char* nm);
839 * Delete items in config string list.
842 void config_delstrlist(struct config_strlist* list);
845 * Delete items in config double string list.
848 void config_deldblstrlist(struct config_str2list* list);
851 * Delete items in config triple string list.
854 void config_deltrplstrlist(struct config_str3list* list);
856 /** delete stringbytelist */
857 void config_del_strbytelist(struct config_strbytelist* list);
861 * @param p: stub item
863 void config_delstub(struct config_stub* p);
866 * Delete items in config stub list.
869 void config_delstubs(struct config_stub* list);
872 * Delete an auth item
873 * @param p: auth item
875 void config_delauth(struct config_auth* p);
878 * Delete items in config auth list.
881 void config_delauths(struct config_auth* list);
885 * @param p: view item
887 void config_delview(struct config_view* p);
890 * Delete items in config view list.
893 void config_delviews(struct config_view* list);
896 * Convert 14digit to time value
897 * @param str: string of 14 digits
898 * @return time value or 0 for error.
900 time_t cfg_convert_timeval(const char* str);
903 * Count number of values in the string.
904 * format ::= (sp num)+ sp
906 * sp ::= (space|tab)*
909 * @return: 0 on parse error, or empty string, else
910 * number of integer values in the string.
912 int cfg_count_numbers(const char* str);
915 * Convert a 'nice' memory or file size into a bytecount
916 * From '100k' to 102400. and so on. Understands kKmMgG.
917 * k=1024, m=1024*1024, g=1024*1024*1024.
919 * @param res: result is stored here, size in bytes.
920 * @return: true if parsed correctly, or 0 on a parse error (and an error
923 int cfg_parse_memsize(const char* str, size_t* res);
926 * Add a tag name to the config. It is added at the end with a new ID value.
927 * @param cfg: the config structure.
928 * @param tag: string (which is copied) with the name.
929 * @return: false on alloc failure.
931 int config_add_tag(struct config_file* cfg, const char* tag);
934 * Find tag ID in the tag list.
935 * @param cfg: the config structure.
936 * @param tag: string with tag name to search for.
937 * @return: 0..(num_tags-1) with tag ID, or -1 if tagname is not found.
939 int find_tag_id(struct config_file* cfg, const char* tag);
942 * parse taglist from string into bytestring with bitlist.
943 * @param cfg: the config structure (with tagnames)
944 * @param str: the string to parse. Parse puts 0 bytes in string.
945 * @param listlen: returns length of in bytes.
946 * @return malloced bytes with a bitlist of the tags. or NULL on parse error
949 uint8_t* config_parse_taglist(struct config_file* cfg, char* str,
953 * convert tag bitlist to a malloced string with tag names. For debug output.
954 * @param cfg: the config structure (with tagnames)
955 * @param taglist: the tag bitlist.
956 * @param len: length of the tag bitlist.
957 * @return malloced string or NULL.
959 char* config_taglist2str(struct config_file* cfg, uint8_t* taglist,
963 * see if two taglists intersect (have tags in common).
964 * @param list1: first tag bitlist.
965 * @param list1len: length in bytes of first list.
966 * @param list2: second tag bitlist.
967 * @param list2len: length in bytes of second list.
968 * @return true if there are tags in common, 0 if not.
970 int taglist_intersect(uint8_t* list1, size_t list1len, uint8_t* list2,
974 * Parse local-zone directive into two strings and register it in the config.
975 * @param cfg: to put it in.
976 * @param val: argument strings to local-zone, "example.com nodefault".
977 * @return: false on failure
979 int cfg_parse_local_zone(struct config_file* cfg, const char* val);
982 * Mark "number" or "low-high" as available or not in ports array.
983 * @param str: string in input
984 * @param allow: give true if this range is permitted.
985 * @param avail: the array from cfg.
986 * @param num: size of the array (65536).
987 * @return: true if parsed correctly, or 0 on a parse error (and an error
990 int cfg_mark_ports(const char* str, int allow, int* avail, int num);
993 * Get a condensed list of ports returned. allocated.
994 * @param cfg: config file.
995 * @param avail: the available ports array is returned here.
996 * @return: number of ports in array or 0 on error.
998 int cfg_condense_ports(struct config_file* cfg, int** avail);
1001 * Scan ports available
1002 * @param avail: the array from cfg.
1003 * @param num: size of the array (65536).
1004 * @return the number of ports available for use.
1006 int cfg_scan_ports(int* avail, int num);
1009 * Convert a filename to full pathname in original filesys
1010 * @param fname: the path name to convert.
1011 * Must not be null or empty.
1012 * @param cfg: config struct for chroot and chdir (if set).
1013 * @param use_chdir: if false, only chroot is applied.
1014 * @return pointer to malloced buffer which is: [chroot][chdir]fname
1015 * or NULL on malloc failure.
1017 char* fname_after_chroot(const char* fname, struct config_file* cfg,
1021 * Convert a ptr shorthand into a full reverse-notation PTR record.
1022 * @param str: input string, "IP name"
1023 * @return: malloced string "reversed-ip-name PTR name"
1025 char* cfg_ptr_reverse(char* str);
1028 * Append text to the error info for validation.
1029 * @param qstate: query state.
1030 * @param str: copied into query region and appended.
1031 * Failures to allocate are logged.
1033 void errinf(struct module_qstate* qstate, const char* str);
1036 * Append text to error info: from 1.2.3.4
1037 * @param qstate: query state.
1038 * @param origin: sock list with origin of trouble.
1039 * Every element added.
1040 * If NULL: nothing is added.
1041 * if 0len element: 'from cache' is added.
1043 void errinf_origin(struct module_qstate* qstate, struct sock_list *origin);
1046 * Append text to error info: for RRset name type class
1047 * @param qstate: query state.
1048 * @param rr: rrset_key.
1050 void errinf_rrset(struct module_qstate* qstate, struct ub_packed_rrset_key *rr);
1053 * Append text to error info: str dname
1054 * @param qstate: query state.
1055 * @param str: explanation string
1056 * @param dname: the dname.
1058 void errinf_dname(struct module_qstate* qstate, const char* str,
1062 * Create error info in string
1063 * @param qstate: query state.
1064 * @return string or NULL on malloc failure (already logged).
1065 * This string is malloced and has to be freed by caller.
1067 char* errinf_to_str(struct module_qstate* qstate);
1070 * Used during options parsing
1072 struct config_parser_state {
1073 /** name of file being parser */
1075 /** line number in the file, starts at 1 */
1077 /** number of errors encountered */
1079 /** the result of parsing is stored here. */
1080 struct config_file* cfg;
1081 /** the current chroot dir (or NULL if none) */
1085 /** global config parser object used during config parsing */
1086 extern struct config_parser_state* cfg_parser;
1087 /** init lex state */
1088 void init_cfg_parse(void);
1090 extern FILE* ub_c_in;
1092 extern FILE* ub_c_out;
1093 /** the yacc lex generated parse function */
1094 int ub_c_parse(void);
1095 /** the lexer function */
1097 /** wrap function */
1098 int ub_c_wrap(void);
1099 /** parsing helpers: print error with file and line numbers */
1100 void ub_c_error(const char* msg);
1101 /** parsing helpers: print error with file and line numbers */
1102 void ub_c_error_msg(const char* fmt, ...) ATTR_FORMAT(printf, 1, 2);
1104 #ifdef UB_ON_WINDOWS
1106 * Obtain registry string (if it exists).
1107 * @param key: key string
1108 * @param name: name of value to fetch.
1109 * @return malloced string with the result or NULL if it did not
1110 * exist on an error (logged with log_err) was encountered.
1112 char* w_lookup_reg_str(const char* key, const char* name);
1114 /** Modify directory in options for module file name */
1115 void w_config_adjust_directory(struct config_file* cfg);
1116 #endif /* UB_ON_WINDOWS */
1118 /** debug option for unit tests. */
1119 extern int fake_dsa, fake_sha1;
1121 #endif /* UTIL_CONFIG_FILE_H */