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
46 struct config_strlist;
47 struct config_str2list;
48 struct config_str3list;
49 struct config_strbytelist;
52 struct ub_packed_rrset_key;
56 * The configuration options.
57 * Strings are malloced.
60 /** verbosity level as specified in the config file */
63 /** statistics interval (in seconds) */
65 /** if false, statistics values are reset after printing them */
67 /** if true, the statistics are kept in greater detail */
70 /** number of threads to create */
73 /** port on which queries are answered. */
75 /** do ip4 query support. */
77 /** do ip6 query support. */
79 /** prefer ip6 upstream queries. */
81 /** do udp query support. */
83 /** do tcp query support. */
85 /** tcp upstream queries (no UDP upstream queries) */
87 /** maximum segment size of tcp socket which queries are answered */
89 /** maximum segment size of tcp socket for outgoing queries */
92 /** private key file for dnstcp-ssl service (enabled if not NULL) */
93 char* ssl_service_key;
94 /** public key file for dnstcp-ssl service */
95 char* ssl_service_pem;
96 /** port on which to provide ssl service */
98 /** if outgoing tcp connections use SSL */
101 /** outgoing port range number of ports (per thread) */
102 int outgoing_num_ports;
103 /** number of outgoing tcp buffers per (per thread) */
104 size_t outgoing_num_tcp;
105 /** number of incoming tcp buffers per (per thread) */
106 size_t incoming_num_tcp;
107 /** allowed udp port numbers, array with 0 if not allowed */
108 int* outgoing_avail_ports;
110 /** EDNS buffer size to use */
111 size_t edns_buffer_size;
112 /** number of bytes buffer size for DNS messages */
113 size_t msg_buffer_size;
114 /** size of the message cache */
115 size_t msg_cache_size;
116 /** slabs in the message cache. */
117 size_t msg_cache_slabs;
118 /** number of queries every thread can service */
119 size_t num_queries_per_thread;
120 /** number of msec to wait before items can be jostled out */
122 /** size of the rrset cache */
123 size_t rrset_cache_size;
124 /** slabs in the rrset cache */
125 size_t rrset_cache_slabs;
126 /** host cache ttl in seconds */
128 /** number of slabs in the infra host cache */
129 size_t infra_cache_slabs;
130 /** max number of hosts in the infra cache */
131 size_t infra_cache_numhosts;
132 /** min value for infra cache rtt */
133 int infra_cache_min_rtt;
134 /** delay close of udp-timeouted ports, if 0 no delayclose. in msec */
137 /** the target fetch policy for the iterator */
138 char* target_fetch_policy;
140 /** automatic interface for incoming messages. Uses ipv6 remapping,
141 * and recvmsg/sendmsg ancillary data to detect interfaces, boolean */
143 /** SO_RCVBUF size to set on port 53 UDP socket */
145 /** SO_SNDBUF size to set on port 53 UDP socket */
147 /** SO_REUSEPORT requested on port 53 sockets */
149 /** IP_TRANSPARENT socket option requested on port 53 sockets */
151 /** IP_FREEBIND socket option request on port 53 sockets */
154 /** number of interfaces to open. If 0 default all interfaces. */
156 /** interface description strings (IP addresses) */
159 /** number of outgoing interfaces to open.
160 * If 0 default all interfaces. */
162 /** outgoing interface description strings (IP addresses) */
165 /** the root hints */
166 struct config_strlist* root_hints;
167 /** the stub definitions, linked list */
168 struct config_stub* stubs;
169 /** the forward zone definitions, linked list */
170 struct config_stub* forwards;
171 /** the views definitions, linked list */
172 struct config_view* views;
173 /** list of donotquery addresses, linked list */
174 struct config_strlist* donotqueryaddrs;
176 /** list of servers we send edns-client-subnet option to and
177 * accept option from, linked list */
178 struct config_strlist* client_subnet;
179 /** opcode assigned by IANA for edns0-client-subnet option */
180 uint16_t client_subnet_opcode;
181 /** Do not check whitelist if incoming query contains an ECS record */
182 int client_subnet_always_forward;
183 /** Subnet length we are willing to give up privacy for */
184 uint8_t max_client_subnet_ipv4;
185 uint8_t max_client_subnet_ipv6;
187 /** list of access control entries, linked list */
188 struct config_str2list* acls;
189 /** use default localhost donotqueryaddr entries */
190 int donotquery_localhost;
192 /** harden against very small edns buffer sizes */
193 int harden_short_bufsize;
194 /** harden against very large query sizes */
195 int harden_large_queries;
196 /** harden against spoofed glue (out of zone data) */
198 /** harden against receiving no DNSSEC data for trust anchor */
199 int harden_dnssec_stripped;
200 /** harden against queries that fall under known nxdomain names */
201 int harden_below_nxdomain;
202 /** harden the referral path, query for NS,A,AAAA and validate */
203 int harden_referral_path;
204 /** harden against algorithm downgrade */
205 int harden_algo_downgrade;
206 /** use 0x20 bits in query as random ID bits */
207 int use_caps_bits_for_id;
208 /** 0x20 whitelist, domains that do not use capsforid */
209 struct config_strlist* caps_whitelist;
210 /** strip away these private addrs from answers, no DNS Rebinding */
211 struct config_strlist* private_address;
212 /** allow domain (and subdomains) to use private address space */
213 struct config_strlist* private_domain;
214 /** what threshold for unwanted action. */
215 size_t unwanted_threshold;
216 /** the number of seconds maximal TTL used for RRsets and messages */
218 /** the number of seconds minimum TTL used for RRsets and messages */
220 /** the number of seconds maximal negative TTL for SOA in auth */
221 int max_negative_ttl;
222 /** if prefetching of messages should be performed. */
224 /** if prefetching of DNSKEYs should be performed. */
227 /** chrootdir, if not "" or chroot will be done */
229 /** username to change to, if not "". */
231 /** working directory */
233 /** filename to log to. */
235 /** pidfile to write pid to. */
238 /** should log messages be sent to syslogd */
240 /** log timestamp in ascii UTC */
242 /** log queries with one line per query */
244 /** log replies with one line per reply */
246 /** log identity to report */
249 /** do not report identity (id.server, hostname.bind) */
251 /** do not report version (version.server, version.bind) */
253 /** do not report trustanchor (trustanchor.unbound) */
254 int hide_trustanchor;
255 /** identity, hostname is returned if "". */
257 /** version, package version returned if "". */
260 /** the module configuration string */
263 /** files with trusted DS and DNSKEYs in zonefile format, list */
264 struct config_strlist* trust_anchor_file_list;
265 /** list of trustanchor keys, linked list */
266 struct config_strlist* trust_anchor_list;
267 /** files with 5011 autotrust tracked keys */
268 struct config_strlist* auto_trust_anchor_file_list;
269 /** files with trusted DNSKEYs in named.conf format, list */
270 struct config_strlist* trusted_keys_file_list;
271 /** DLV anchor file */
272 char* dlv_anchor_file;
273 /** DLV anchor inline */
274 struct config_strlist* dlv_anchor_list;
275 /** insecure domain list */
276 struct config_strlist* domain_insecure;
278 /** if not 0, this value is the validation date for RRSIGs */
279 int32_t val_date_override;
280 /** the minimum for signature clock skew */
281 int32_t val_sig_skew_min;
282 /** the maximum for signature clock skew */
283 int32_t val_sig_skew_max;
284 /** this value sets the number of seconds before revalidating bogus */
286 /** should validator clean additional section for secure msgs */
287 int val_clean_additional;
288 /** log bogus messages by the validator */
290 /** squelch val_log_level to log - this is library goes to callback */
292 /** should validator allow bogus messages to go through */
293 int val_permissive_mode;
294 /** ignore the CD flag in incoming queries and refuse them bogus data */
296 /** serve expired entries and prefetch them */
298 /** nsec3 maximum iterations per key size, string */
299 char* val_nsec3_key_iterations;
300 /** autotrust add holddown time, in seconds */
301 unsigned int add_holddown;
302 /** autotrust del holddown time, in seconds */
303 unsigned int del_holddown;
304 /** autotrust keep_missing time, in seconds. 0 is forever. */
305 unsigned int keep_missing;
306 /** permit small holddown values, allowing 5011 rollover very fast */
307 int permit_small_holddown;
309 /** size of the key cache */
310 size_t key_cache_size;
311 /** slabs in the key cache. */
312 size_t key_cache_slabs;
313 /** size of the neg cache */
314 size_t neg_cache_size;
316 /** local zones config */
317 struct config_str2list* local_zones;
318 /** local zones nodefault list */
319 struct config_strlist* local_zones_nodefault;
320 /** local data RRs configured */
321 struct config_strlist* local_data;
322 /** local zone override types per netblock */
323 struct config_str3list* local_zone_overrides;
324 /** unblock lan zones (reverse lookups for AS112 zones) */
325 int unblock_lan_zones;
326 /** insecure lan zones (don't validate AS112 zones) */
327 int insecure_lan_zones;
328 /** list of zonename, tagbitlist */
329 struct config_strbytelist* local_zone_tags;
330 /** list of aclname, tagbitlist */
331 struct config_strbytelist* acl_tags;
332 /** list of aclname, tagname, localzonetype */
333 struct config_str3list* acl_tag_actions;
334 /** list of aclname, tagname, redirectdata */
335 struct config_str3list* acl_tag_datas;
336 /** list of aclname, view*/
337 struct config_str2list* acl_view;
338 /** list of IP-netblock, tagbitlist */
339 struct config_strbytelist* respip_tags;
340 /** list of response-driven access control entries, linked list */
341 struct config_str2list* respip_actions;
342 /** RRs configured for response-driven access controls */
343 struct config_str2list* respip_data;
344 /** tag list, array with tagname[i] is malloced string */
346 /** number of items in the taglist */
349 /** remote control section. enable toggle. */
350 int remote_control_enable;
351 /** the interfaces the remote control should listen on */
352 struct config_strlist* control_ifs;
353 /** port number for the control port */
355 /** use certificates for remote control */
356 int remote_control_use_cert;
357 /** private key file for server */
358 char* server_key_file;
359 /** certificate file for server */
360 char* server_cert_file;
361 /** private key file for unbound-control */
362 char* control_key_file;
363 /** certificate file for unbound-control */
364 char* control_cert_file;
366 /** Python script file */
369 /** Use systemd socket activation. */
372 /** daemonize, i.e. fork into the background. */
375 /* minimal response when positive answer */
376 int minimal_responses;
378 /* RRSet roundrobin */
379 int rrset_roundrobin;
381 /* maximum UDP response size */
387 /* Synthetize all AAAA record despite the presence of an authoritative one */
390 /** true to enable dnstap support */
392 /** dnstap socket path */
393 char* dnstap_socket_path;
394 /** true to send "identity" via dnstap */
395 int dnstap_send_identity;
396 /** true to send "version" via dnstap */
397 int dnstap_send_version;
398 /** dnstap "identity", hostname is used if "". */
399 char* dnstap_identity;
400 /** dnstap "version", package version is used if "". */
401 char* dnstap_version;
403 /** true to log dnstap RESOLVER_QUERY message events */
404 int dnstap_log_resolver_query_messages;
405 /** true to log dnstap RESOLVER_RESPONSE message events */
406 int dnstap_log_resolver_response_messages;
407 /** true to log dnstap CLIENT_QUERY message events */
408 int dnstap_log_client_query_messages;
409 /** true to log dnstap CLIENT_RESPONSE message events */
410 int dnstap_log_client_response_messages;
411 /** true to log dnstap FORWARDER_QUERY message events */
412 int dnstap_log_forwarder_query_messages;
413 /** true to log dnstap FORWARDER_RESPONSE message events */
414 int dnstap_log_forwarder_response_messages;
416 /** true to disable DNSSEC lameness check in iterator */
417 int disable_dnssec_lame_check;
419 /** ratelimit for ip addresses. 0 is off, otherwise qps (unless overridden) */
421 /** number of slabs for ip_ratelimit cache */
422 size_t ip_ratelimit_slabs;
423 /** memory size in bytes for ip_ratelimit cache */
424 size_t ip_ratelimit_size;
425 /** ip_ratelimit factor, 0 blocks all, 10 allows 1/10 of traffic */
426 int ip_ratelimit_factor;
428 /** ratelimit for domains. 0 is off, otherwise qps (unless overridden) */
430 /** number of slabs for ratelimit cache */
431 size_t ratelimit_slabs;
432 /** memory size in bytes for ratelimit cache */
433 size_t ratelimit_size;
434 /** ratelimits for domain (exact match) */
435 struct config_str2list* ratelimit_for_domain;
436 /** ratelimits below domain */
437 struct config_str2list* ratelimit_below_domain;
438 /** ratelimit factor, 0 blocks all, 10 allows 1/10 of traffic */
439 int ratelimit_factor;
440 /** minimise outgoing QNAME and hide original QTYPE if possible */
441 int qname_minimisation;
442 /** minimise QNAME in strict mode, minimise according to RFC.
443 * Do not apply fallback */
444 int qname_minimisation_strict;
445 /** SHM data - true if shm is enabled */
447 /** SHM data - key for the shm */
451 /** true to enable dnscrypt */
453 /** port on which to provide dnscrypt service */
455 /** provider name 2.dnscrypt-cert.example.com */
456 char* dnscrypt_provider;
457 /** dnscrypt secret keys 1.key */
458 struct config_strlist* dnscrypt_secret_key;
459 /** dnscrypt provider certs 1.cert */
460 struct config_strlist* dnscrypt_provider_cert;
463 /** from cfg username, after daemonise setup performed */
464 extern uid_t cfg_uid;
465 /** from cfg username, after daemonise setup performed */
466 extern gid_t cfg_gid;
467 /** debug and enable small timeouts */
468 extern int autr_permit_small_holddown;
471 * Stub config options
475 struct config_stub* next;
476 /** domain name (in text) of the stub apex domain */
478 /** list of stub nameserver hosts (domain name) */
479 struct config_strlist* hosts;
480 /** list of stub nameserver addresses (IP address) */
481 struct config_strlist* addrs;
482 /** if stub-prime is set */
484 /** if forward-first is set (failover to without if fails) */
486 /** use SSL for queries to this stub */
491 * View config options
495 struct config_view* next;
499 struct config_str2list* local_zones;
500 /** local data RRs */
501 struct config_strlist* local_data;
502 /** local zones nodefault list */
503 struct config_strlist* local_zones_nodefault;
504 /** Fallback to global local_zones when there is no match in the view
505 * view specific tree. 1 for yes, 0 for no */
507 /** predefined actions for particular IP address responses */
508 struct config_str2list* respip_actions;
509 /** data complementing the 'redirect' response IP actions */
510 struct config_str2list* respip_data;
514 * List of strings for config options
516 struct config_strlist {
517 /** next item in list */
518 struct config_strlist* next;
519 /** config option string */
524 * List of two strings for config options
526 struct config_str2list {
527 /** next item in list */
528 struct config_str2list* next;
536 * List of three strings for config options
538 struct config_str3list {
539 /** next item in list */
540 struct config_str3list* next;
551 * List of string, bytestring for config options
553 struct config_strbytelist {
554 /** next item in list */
555 struct config_strbytelist* next;
558 /** second bytestring */
563 /** List head for strlist processing, used for append operation. */
564 struct config_strlist_head {
565 /** first in list of text items */
566 struct config_strlist* first;
567 /** last in list of text items */
568 struct config_strlist* last;
572 * Create config file structure. Filled with default values.
573 * @return: the new structure or NULL on memory error.
575 struct config_file* config_create(void);
578 * Create config file structure for library use. Filled with default values.
579 * @return: the new structure or NULL on memory error.
581 struct config_file* config_create_forlib(void);
584 * Read the config file from the specified filename.
585 * @param config: where options are stored into, must be freshly created.
586 * @param filename: name of configfile. If NULL nothing is done.
587 * @param chroot: if not NULL, the chroot dir currently in use (for include).
588 * @return: false on error. In that case errno is set, ENOENT means
591 int config_read(struct config_file* config, const char* filename,
595 * Destroy the config file structure.
596 * @param config: to delete.
598 void config_delete(struct config_file* config);
601 * Apply config to global constants; this routine is called in single thread.
602 * @param config: to apply. Side effect: global constants change.
604 void config_apply(struct config_file* config);
607 * Find username, sets cfg_uid and cfg_gid.
608 * @param config: the config structure.
610 void config_lookup_uid(struct config_file* config);
613 * Set the given keyword to the given value.
614 * @param config: where to store config
615 * @param option: option name, including the ':' character.
616 * @param value: value, this string is copied if needed, or parsed.
617 * The caller owns the value string.
618 * @return 0 on error (malloc or syntax error).
620 int config_set_option(struct config_file* config, const char* option,
624 * Call print routine for the given option.
625 * @param cfg: config.
626 * @param opt: option name without trailing :.
627 * This is different from config_set_option.
628 * @param func: print func, called as (str, arg) for every data element.
629 * @param arg: user argument for print func.
630 * @return false if the option name is not supported (syntax error).
632 int config_get_option(struct config_file* cfg, const char* opt,
633 void (*func)(char*,void*), void* arg);
636 * Get an option and return strlist
637 * @param cfg: config file
638 * @param opt: option name.
639 * @param list: list is returned here. malloced, caller must free it.
640 * @return 0=OK, 1=syntax error, 2=malloc failed.
642 int config_get_option_list(struct config_file* cfg, const char* opt,
643 struct config_strlist** list);
646 * Get an option and collate results into string
647 * @param cfg: config file
648 * @param opt: option name.
649 * @param str: string. malloced, caller must free it.
650 * @return 0=OK, 1=syntax error, 2=malloc failed.
652 int config_get_option_collate(struct config_file* cfg, const char* opt,
656 * function to print to a file, use as func with config_get_option.
657 * @param line: text to print. \n appended.
658 * @param arg: pass a FILE*, like stdout.
660 void config_print_func(char* line, void* arg);
663 * function to collate the text strings into a strlist_head.
664 * @param line: text to append.
665 * @param arg: pass a strlist_head structure. zeroed on start.
667 void config_collate_func(char* line, void* arg);
670 * take a strlist_head list and return a malloc string. separated with newline.
671 * @param list: strlist first to collate. zeroes return "".
672 * @return NULL on malloc failure. Or if malloc failure happened in strlist.
674 char* config_collate_cat(struct config_strlist* list);
677 * Append text at end of list.
678 * @param list: list head. zeroed at start.
679 * @param item: new item. malloced by caller. if NULL the insertion fails.
680 * @return true on success.
682 int cfg_strlist_append(struct config_strlist_head* list, char* item);
685 * Insert string into strlist.
686 * @param head: pointer to strlist head variable.
687 * @param item: new item. malloced by caller. If NULL the insertion fails.
688 * @return: true on success.
690 int cfg_strlist_insert(struct config_strlist** head, char* item);
692 /** insert with region for allocation. */
693 int cfg_region_strlist_insert(struct regional* region,
694 struct config_strlist** head, char* item);
697 * Insert string into str2list.
698 * @param head: pointer to str2list head variable.
699 * @param item: new item. malloced by caller. If NULL the insertion fails.
700 * @param i2: 2nd string, malloced by caller. If NULL the insertion fails.
701 * @return: true on success.
703 int cfg_str2list_insert(struct config_str2list** head, char* item, char* i2);
706 * Insert string into str3list.
707 * @param head: pointer to str3list head variable.
708 * @param item: new item. malloced by caller. If NULL the insertion fails.
709 * @param i2: 2nd string, malloced by caller. If NULL the insertion fails.
710 * @param i3: 3rd string, malloced by caller. If NULL the insertion fails.
711 * @return: true on success.
713 int cfg_str3list_insert(struct config_str3list** head, char* item, char* i2,
717 * Insert string into strbytelist.
718 * @param head: pointer to strbytelist head variable.
719 * @param item: new item. malloced by caller. If NULL the insertion fails.
720 * @param i2: 2nd string, malloced by caller. If NULL the insertion fails.
721 * @param i2len: length of the i2 bytestring.
722 * @return: true on success.
724 int cfg_strbytelist_insert(struct config_strbytelist** head, char* item,
725 uint8_t* i2, size_t i2len);
728 * Find stub in config list, also returns prevptr (for deletion).
729 * @param pp: call routine with pointer to a pointer to the start of the list,
730 * if the stub is found, on exit, the value contains a pointer to the
731 * next pointer that points to the found element (or to the list start
732 * pointer if it is the first element).
733 * @param nm: name of stub to find.
734 * @return: pointer to config_stub if found, or NULL if not found.
736 struct config_stub* cfg_stub_find(struct config_stub*** pp, const char* nm);
739 * Delete items in config string list.
742 void config_delstrlist(struct config_strlist* list);
745 * Delete items in config double string list.
748 void config_deldblstrlist(struct config_str2list* list);
751 * Delete items in config triple string list.
754 void config_deltrplstrlist(struct config_str3list* list);
756 /** delete stringbytelist */
757 void config_del_strbytelist(struct config_strbytelist* list);
761 * @param p: stub item
763 void config_delstub(struct config_stub* p);
766 * Delete items in config stub list.
769 void config_delstubs(struct config_stub* list);
773 * @param p: view item
775 void config_delview(struct config_view* p);
778 * Delete items in config view list.
781 void config_delviews(struct config_view* list);
784 * Convert 14digit to time value
785 * @param str: string of 14 digits
786 * @return time value or 0 for error.
788 time_t cfg_convert_timeval(const char* str);
791 * Count number of values in the string.
792 * format ::= (sp num)+ sp
794 * sp ::= (space|tab)*
797 * @return: 0 on parse error, or empty string, else
798 * number of integer values in the string.
800 int cfg_count_numbers(const char* str);
803 * Convert a 'nice' memory or file size into a bytecount
804 * From '100k' to 102400. and so on. Understands kKmMgG.
805 * k=1024, m=1024*1024, g=1024*1024*1024.
807 * @param res: result is stored here, size in bytes.
808 * @return: true if parsed correctly, or 0 on a parse error (and an error
811 int cfg_parse_memsize(const char* str, size_t* res);
814 * Add a tag name to the config. It is added at the end with a new ID value.
815 * @param cfg: the config structure.
816 * @param tag: string (which is copied) with the name.
817 * @return: false on alloc failure.
819 int config_add_tag(struct config_file* cfg, const char* tag);
822 * Find tag ID in the tag list.
823 * @param cfg: the config structure.
824 * @param tag: string with tag name to search for.
825 * @return: 0..(num_tags-1) with tag ID, or -1 if tagname is not found.
827 int find_tag_id(struct config_file* cfg, const char* tag);
830 * parse taglist from string into bytestring with bitlist.
831 * @param cfg: the config structure (with tagnames)
832 * @param str: the string to parse. Parse puts 0 bytes in string.
833 * @param listlen: returns length of in bytes.
834 * @return malloced bytes with a bitlist of the tags. or NULL on parse error
837 uint8_t* config_parse_taglist(struct config_file* cfg, char* str,
841 * convert tag bitlist to a malloced string with tag names. For debug output.
842 * @param cfg: the config structure (with tagnames)
843 * @param taglist: the tag bitlist.
844 * @param len: length of the tag bitlist.
845 * @return malloced string or NULL.
847 char* config_taglist2str(struct config_file* cfg, uint8_t* taglist,
851 * see if two taglists intersect (have tags in common).
852 * @param list1: first tag bitlist.
853 * @param list1len: length in bytes of first list.
854 * @param list2: second tag bitlist.
855 * @param list2len: length in bytes of second list.
856 * @return true if there are tags in common, 0 if not.
858 int taglist_intersect(uint8_t* list1, size_t list1len, uint8_t* list2,
862 * Parse local-zone directive into two strings and register it in the config.
863 * @param cfg: to put it in.
864 * @param val: argument strings to local-zone, "example.com nodefault".
865 * @return: false on failure
867 int cfg_parse_local_zone(struct config_file* cfg, const char* val);
870 * Mark "number" or "low-high" as available or not in ports array.
871 * @param str: string in input
872 * @param allow: give true if this range is permitted.
873 * @param avail: the array from cfg.
874 * @param num: size of the array (65536).
875 * @return: true if parsed correctly, or 0 on a parse error (and an error
878 int cfg_mark_ports(const char* str, int allow, int* avail, int num);
881 * Get a condensed list of ports returned. allocated.
882 * @param cfg: config file.
883 * @param avail: the available ports array is returned here.
884 * @return: number of ports in array or 0 on error.
886 int cfg_condense_ports(struct config_file* cfg, int** avail);
889 * Scan ports available
890 * @param avail: the array from cfg.
891 * @param num: size of the array (65536).
892 * @return the number of ports available for use.
894 int cfg_scan_ports(int* avail, int num);
897 * Convert a filename to full pathname in original filesys
898 * @param fname: the path name to convert.
899 * Must not be null or empty.
900 * @param cfg: config struct for chroot and chdir (if set).
901 * @param use_chdir: if false, only chroot is applied.
902 * @return pointer to malloced buffer which is: [chroot][chdir]fname
903 * or NULL on malloc failure.
905 char* fname_after_chroot(const char* fname, struct config_file* cfg,
909 * Convert a ptr shorthand into a full reverse-notation PTR record.
910 * @param str: input string, "IP name"
911 * @return: malloced string "reversed-ip-name PTR name"
913 char* cfg_ptr_reverse(char* str);
916 * Append text to the error info for validation.
917 * @param qstate: query state.
918 * @param str: copied into query region and appended.
919 * Failures to allocate are logged.
921 void errinf(struct module_qstate* qstate, const char* str);
924 * Append text to error info: from 1.2.3.4
925 * @param qstate: query state.
926 * @param origin: sock list with origin of trouble.
927 * Every element added.
928 * If NULL: nothing is added.
929 * if 0len element: 'from cache' is added.
931 void errinf_origin(struct module_qstate* qstate, struct sock_list *origin);
934 * Append text to error info: for RRset name type class
935 * @param qstate: query state.
936 * @param rr: rrset_key.
938 void errinf_rrset(struct module_qstate* qstate, struct ub_packed_rrset_key *rr);
941 * Append text to error info: str dname
942 * @param qstate: query state.
943 * @param str: explanation string
944 * @param dname: the dname.
946 void errinf_dname(struct module_qstate* qstate, const char* str,
950 * Create error info in string
951 * @param qstate: query state.
952 * @return string or NULL on malloc failure (already logged).
953 * This string is malloced and has to be freed by caller.
955 char* errinf_to_str(struct module_qstate* qstate);
958 * Used during options parsing
960 struct config_parser_state {
961 /** name of file being parser */
963 /** line number in the file, starts at 1 */
965 /** number of errors encountered */
967 /** the result of parsing is stored here. */
968 struct config_file* cfg;
969 /** the current chroot dir (or NULL if none) */
973 /** global config parser object used during config parsing */
974 extern struct config_parser_state* cfg_parser;
975 /** init lex state */
976 void init_cfg_parse(void);
978 extern FILE* ub_c_in;
980 extern FILE* ub_c_out;
981 /** the yacc lex generated parse function */
982 int ub_c_parse(void);
983 /** the lexer function */
987 /** parsing helpers: print error with file and line numbers */
988 void ub_c_error(const char* msg);
989 /** parsing helpers: print error with file and line numbers */
990 void ub_c_error_msg(const char* fmt, ...) ATTR_FORMAT(printf, 1, 2);
994 * Obtain registry string (if it exists).
995 * @param key: key string
996 * @param name: name of value to fetch.
997 * @return malloced string with the result or NULL if it did not
998 * exist on an error (logged with log_err) was encountered.
1000 char* w_lookup_reg_str(const char* key, const char* name);
1002 /** Modify directory in options for module file name */
1003 void w_config_adjust_directory(struct config_file* cfg);
1004 #endif /* UB_ON_WINDOWS */
1006 /** debug option for unit tests. */
1007 extern int fake_dsa, fake_sha1;
1009 #endif /* UTIL_CONFIG_FILE_H */