xref: /freebsd/contrib/unbound/util/config_file.h (revision acc1a9ef8333c798c210fa94be6af4d5fe2dd794)
1 /*
2  * util/config_file.h - reads and stores the config file for unbound.
3  *
4  * Copyright (c) 2007, NLnet Labs. All rights reserved.
5  *
6  * This software is open source.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * Redistributions of source code must retain the above copyright notice,
13  * this list of conditions and the following disclaimer.
14  *
15  * Redistributions in binary form must reproduce the above copyright notice,
16  * this list of conditions and the following disclaimer in the documentation
17  * and/or other materials provided with the distribution.
18  *
19  * Neither the name of the NLNET LABS nor the names of its contributors may
20  * be used to endorse or promote products derived from this software without
21  * specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
29  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34  */
35 
36 /**
37  * \file
38  *
39  * This file contains functions for the config file.
40  */
41 
42 #ifndef UTIL_CONFIG_FILE_H
43 #define UTIL_CONFIG_FILE_H
44 struct config_stub;
45 struct config_strlist;
46 struct config_str2list;
47 struct module_qstate;
48 struct sock_list;
49 struct ub_packed_rrset_key;
50 
51 /**
52  * The configuration options.
53  * Strings are malloced.
54  */
55 struct config_file {
56 	/** verbosity level as specified in the config file */
57 	int verbosity;
58 
59 	/** statistics interval (in seconds) */
60 	int stat_interval;
61 	/** if false, statistics values are reset after printing them */
62 	int stat_cumulative;
63 	/** if true, the statistics are kept in greater detail */
64 	int stat_extended;
65 
66 	/** number of threads to create */
67 	int num_threads;
68 
69 	/** port on which queries are answered. */
70 	int port;
71 	/** do ip4 query support. */
72 	int do_ip4;
73 	/** do ip6 query support. */
74 	int do_ip6;
75 	/** do udp query support. */
76 	int do_udp;
77 	/** do tcp query support. */
78 	int do_tcp;
79 	/** tcp upstream queries (no UDP upstream queries) */
80 	int tcp_upstream;
81 	/** maximum segment size of tcp socket which queries are answered */
82 	int tcp_mss;
83 	/** maximum segment size of tcp socket for outgoing queries */
84 	int outgoing_tcp_mss;
85 
86 	/** private key file for dnstcp-ssl service (enabled if not NULL) */
87 	char* ssl_service_key;
88 	/** public key file for dnstcp-ssl service */
89 	char* ssl_service_pem;
90 	/** port on which to provide ssl service */
91 	int ssl_port;
92 	/** if outgoing tcp connections use SSL */
93 	int ssl_upstream;
94 
95 	/** outgoing port range number of ports (per thread) */
96 	int outgoing_num_ports;
97 	/** number of outgoing tcp buffers per (per thread) */
98 	size_t outgoing_num_tcp;
99 	/** number of incoming tcp buffers per (per thread) */
100 	size_t incoming_num_tcp;
101 	/** allowed udp port numbers, array with 0 if not allowed */
102 	int* outgoing_avail_ports;
103 
104 	/** EDNS buffer size to use */
105 	size_t edns_buffer_size;
106 	/** number of bytes buffer size for DNS messages */
107 	size_t msg_buffer_size;
108 	/** size of the message cache */
109 	size_t msg_cache_size;
110 	/** slabs in the message cache. */
111 	size_t msg_cache_slabs;
112 	/** number of queries every thread can service */
113 	size_t num_queries_per_thread;
114 	/** number of msec to wait before items can be jostled out */
115 	size_t jostle_time;
116 	/** size of the rrset cache */
117 	size_t rrset_cache_size;
118 	/** slabs in the rrset cache */
119 	size_t rrset_cache_slabs;
120 	/** host cache ttl in seconds */
121 	int host_ttl;
122 	/** number of slabs in the infra host cache */
123 	size_t infra_cache_slabs;
124 	/** max number of hosts in the infra cache */
125 	size_t infra_cache_numhosts;
126 	/** min value for infra cache rtt */
127 	int infra_cache_min_rtt;
128 	/** delay close of udp-timeouted ports, if 0 no delayclose. in msec */
129 	int delay_close;
130 
131 	/** the target fetch policy for the iterator */
132 	char* target_fetch_policy;
133 
134 	/** automatic interface for incoming messages. Uses ipv6 remapping,
135 	 * and recvmsg/sendmsg ancillary data to detect interfaces, boolean */
136 	int if_automatic;
137 	/** SO_RCVBUF size to set on port 53 UDP socket */
138 	size_t so_rcvbuf;
139 	/** SO_SNDBUF size to set on port 53 UDP socket */
140 	size_t so_sndbuf;
141 	/** SO_REUSEPORT requested on port 53 sockets */
142 	int so_reuseport;
143 	/** IP_TRANSPARENT socket option requested on port 53 sockets */
144 	int ip_transparent;
145 
146 	/** number of interfaces to open. If 0 default all interfaces. */
147 	int num_ifs;
148 	/** interface description strings (IP addresses) */
149 	char **ifs;
150 
151 	/** number of outgoing interfaces to open.
152 	 * If 0 default all interfaces. */
153 	int num_out_ifs;
154 	/** outgoing interface description strings (IP addresses) */
155 	char **out_ifs;
156 
157 	/** the root hints */
158 	struct config_strlist* root_hints;
159 	/** the stub definitions, linked list */
160 	struct config_stub* stubs;
161 	/** the forward zone definitions, linked list */
162 	struct config_stub* forwards;
163 	/** list of donotquery addresses, linked list */
164 	struct config_strlist* donotqueryaddrs;
165 	/** list of access control entries, linked list */
166 	struct config_str2list* acls;
167 	/** use default localhost donotqueryaddr entries */
168 	int donotquery_localhost;
169 
170 	/** harden against very small edns buffer sizes */
171 	int harden_short_bufsize;
172 	/** harden against very large query sizes */
173 	int harden_large_queries;
174 	/** harden against spoofed glue (out of zone data) */
175 	int harden_glue;
176 	/** harden against receiving no DNSSEC data for trust anchor */
177 	int harden_dnssec_stripped;
178 	/** harden against queries that fall under known nxdomain names */
179 	int harden_below_nxdomain;
180 	/** harden the referral path, query for NS,A,AAAA and validate */
181 	int harden_referral_path;
182 	/** harden against algorithm downgrade */
183 	int harden_algo_downgrade;
184 	/** use 0x20 bits in query as random ID bits */
185 	int use_caps_bits_for_id;
186 	/** 0x20 whitelist, domains that do not use capsforid */
187 	struct config_strlist* caps_whitelist;
188 	/** strip away these private addrs from answers, no DNS Rebinding */
189 	struct config_strlist* private_address;
190 	/** allow domain (and subdomains) to use private address space */
191 	struct config_strlist* private_domain;
192 	/** what threshold for unwanted action. */
193 	size_t unwanted_threshold;
194 	/** the number of seconds maximal TTL used for RRsets and messages */
195 	int max_ttl;
196 	/** the number of seconds minimum TTL used for RRsets and messages */
197 	int min_ttl;
198 	/** the number of seconds maximal negative TTL for SOA in auth */
199 	int max_negative_ttl;
200 	/** if prefetching of messages should be performed. */
201 	int prefetch;
202 	/** if prefetching of DNSKEYs should be performed. */
203 	int prefetch_key;
204 
205 	/** chrootdir, if not "" or chroot will be done */
206 	char* chrootdir;
207 	/** username to change to, if not "". */
208 	char* username;
209 	/** working directory */
210 	char* directory;
211 	/** filename to log to. */
212 	char* logfile;
213 	/** pidfile to write pid to. */
214 	char* pidfile;
215 
216 	/** should log messages be sent to syslogd */
217 	int use_syslog;
218 	/** log timestamp in ascii UTC */
219 	int log_time_ascii;
220 	/** log queries with one line per query */
221 	int log_queries;
222 
223 	/** do not report identity (id.server, hostname.bind) */
224 	int hide_identity;
225 	/** do not report version (version.server, version.bind) */
226 	int hide_version;
227 	/** identity, hostname is returned if "". */
228 	char* identity;
229 	/** version, package version returned if "". */
230 	char* version;
231 
232 	/** the module configuration string */
233 	char* module_conf;
234 
235 	/** files with trusted DS and DNSKEYs in zonefile format, list */
236 	struct config_strlist* trust_anchor_file_list;
237 	/** list of trustanchor keys, linked list */
238 	struct config_strlist* trust_anchor_list;
239 	/** files with 5011 autotrust tracked keys */
240 	struct config_strlist* auto_trust_anchor_file_list;
241 	/** files with trusted DNSKEYs in named.conf format, list */
242 	struct config_strlist* trusted_keys_file_list;
243 	/** DLV anchor file */
244 	char* dlv_anchor_file;
245 	/** DLV anchor inline */
246 	struct config_strlist* dlv_anchor_list;
247 	/** insecure domain list */
248 	struct config_strlist* domain_insecure;
249 
250 	/** if not 0, this value is the validation date for RRSIGs */
251 	int32_t val_date_override;
252 	/** the minimum for signature clock skew */
253 	int32_t val_sig_skew_min;
254 	/** the maximum for signature clock skew */
255 	int32_t val_sig_skew_max;
256 	/** this value sets the number of seconds before revalidating bogus */
257 	int bogus_ttl;
258 	/** should validator clean additional section for secure msgs */
259 	int val_clean_additional;
260 	/** log bogus messages by the validator */
261 	int val_log_level;
262 	/** squelch val_log_level to log - this is library goes to callback */
263 	int val_log_squelch;
264 	/** should validator allow bogus messages to go through */
265 	int val_permissive_mode;
266 	/** ignore the CD flag in incoming queries and refuse them bogus data */
267 	int ignore_cd;
268 	/** nsec3 maximum iterations per key size, string */
269 	char* val_nsec3_key_iterations;
270 	/** autotrust add holddown time, in seconds */
271 	unsigned int add_holddown;
272 	/** autotrust del holddown time, in seconds */
273 	unsigned int del_holddown;
274 	/** autotrust keep_missing time, in seconds. 0 is forever. */
275 	unsigned int keep_missing;
276 	/** permit small holddown values, allowing 5011 rollover very fast */
277 	int permit_small_holddown;
278 
279 	/** size of the key cache */
280 	size_t key_cache_size;
281 	/** slabs in the key cache. */
282 	size_t key_cache_slabs;
283 	/** size of the neg cache */
284 	size_t neg_cache_size;
285 
286 	/** local zones config */
287 	struct config_str2list* local_zones;
288 	/** local zones nodefault list */
289 	struct config_strlist* local_zones_nodefault;
290 	/** local data RRs configured */
291 	struct config_strlist* local_data;
292 	/** unblock lan zones (reverse lookups for AS112 zones) */
293 	int unblock_lan_zones;
294 	/** insecure lan zones (don't validate AS112 zones) */
295 	int insecure_lan_zones;
296 
297 	/** remote control section. enable toggle. */
298 	int remote_control_enable;
299 	/** the interfaces the remote control should listen on */
300 	struct config_strlist* control_ifs;
301 	/** port number for the control port */
302 	int control_port;
303 	/** use certificates for remote control */
304 	int remote_control_use_cert;
305 	/** private key file for server */
306 	char* server_key_file;
307 	/** certificate file for server */
308 	char* server_cert_file;
309 	/** private key file for unbound-control */
310 	char* control_key_file;
311 	/** certificate file for unbound-control */
312 	char* control_cert_file;
313 
314 	/** Python script file */
315 	char* python_script;
316 
317 	/** daemonize, i.e. fork into the background. */
318 	int do_daemonize;
319 
320 	/* minimal response when positive answer */
321 	int minimal_responses;
322 
323 	/* RRSet roundrobin */
324 	int rrset_roundrobin;
325 
326 	/* maximum UDP response size */
327 	size_t max_udp_size;
328 
329 	/* DNS64 prefix */
330 	char* dns64_prefix;
331 
332 	/* Synthetize all AAAA record despite the presence of an authoritative one */
333 	int dns64_synthall;
334 
335 	/** true to enable dnstap support */
336 	int dnstap;
337 	/** dnstap socket path */
338 	char* dnstap_socket_path;
339 	/** true to send "identity" via dnstap */
340 	int dnstap_send_identity;
341 	/** true to send "version" via dnstap */
342 	int dnstap_send_version;
343 	/** dnstap "identity", hostname is used if "". */
344 	char* dnstap_identity;
345 	/** dnstap "version", package version is used if "". */
346 	char* dnstap_version;
347 
348 	/** true to log dnstap RESOLVER_QUERY message events */
349 	int dnstap_log_resolver_query_messages;
350 	/** true to log dnstap RESOLVER_RESPONSE message events */
351 	int dnstap_log_resolver_response_messages;
352 	/** true to log dnstap CLIENT_QUERY message events */
353 	int dnstap_log_client_query_messages;
354 	/** true to log dnstap CLIENT_RESPONSE message events */
355 	int dnstap_log_client_response_messages;
356 	/** true to log dnstap FORWARDER_QUERY message events */
357 	int dnstap_log_forwarder_query_messages;
358 	/** true to log dnstap FORWARDER_RESPONSE message events */
359 	int dnstap_log_forwarder_response_messages;
360 
361 	/** ratelimit 0 is off, otherwise qps (unless overridden) */
362 	int ratelimit;
363 	/** number of slabs for ratelimit cache */
364 	size_t ratelimit_slabs;
365 	/** memory size in bytes for ratelimit cache */
366 	size_t ratelimit_size;
367 	/** ratelimits for domain (exact match) */
368 	struct config_str2list* ratelimit_for_domain;
369 	/** ratelimits below domain */
370 	struct config_str2list* ratelimit_below_domain;
371 	/** ratelimit factor, 0 blocks all, 10 allows 1/10 of traffic */
372 	int ratelimit_factor;
373 	/** minimise outgoing QNAME and hide original QTYPE if possible */
374 	int qname_minimisation;
375 };
376 
377 /** from cfg username, after daemonise setup performed */
378 extern uid_t cfg_uid;
379 /** from cfg username, after daemonise setup performed */
380 extern gid_t cfg_gid;
381 /** debug and enable small timeouts */
382 extern int autr_permit_small_holddown;
383 
384 /**
385  * Stub config options
386  */
387 struct config_stub {
388 	/** next in list */
389 	struct config_stub* next;
390 	/** domain name (in text) of the stub apex domain */
391 	char* name;
392 	/** list of stub nameserver hosts (domain name) */
393 	struct config_strlist* hosts;
394 	/** list of stub nameserver addresses (IP address) */
395 	struct config_strlist* addrs;
396 	/** if stub-prime is set */
397 	int isprime;
398 	/** if forward-first is set (failover to without if fails) */
399 	int isfirst;
400 };
401 
402 /**
403  * List of strings for config options
404  */
405 struct config_strlist {
406 	/** next item in list */
407 	struct config_strlist* next;
408 	/** config option string */
409 	char* str;
410 };
411 
412 /**
413  * List of two strings for config options
414  */
415 struct config_str2list {
416 	/** next item in list */
417 	struct config_str2list* next;
418 	/** first string */
419 	char* str;
420 	/** second string */
421 	char* str2;
422 };
423 
424 /** List head for strlist processing, used for append operation. */
425 struct config_strlist_head {
426 	/** first in list of text items */
427 	struct config_strlist* first;
428 	/** last in list of text items */
429 	struct config_strlist* last;
430 };
431 
432 /**
433  * Create config file structure. Filled with default values.
434  * @return: the new structure or NULL on memory error.
435  */
436 struct config_file* config_create(void);
437 
438 /**
439  * Create config file structure for library use. Filled with default values.
440  * @return: the new structure or NULL on memory error.
441  */
442 struct config_file* config_create_forlib(void);
443 
444 /**
445  * Read the config file from the specified filename.
446  * @param config: where options are stored into, must be freshly created.
447  * @param filename: name of configfile. If NULL nothing is done.
448  * @param chroot: if not NULL, the chroot dir currently in use (for include).
449  * @return: false on error. In that case errno is set, ENOENT means
450  * 	file not found.
451  */
452 int config_read(struct config_file* config, const char* filename,
453 	const char* chroot);
454 
455 /**
456  * Destroy the config file structure.
457  * @param config: to delete.
458  */
459 void config_delete(struct config_file* config);
460 
461 /**
462  * Apply config to global constants; this routine is called in single thread.
463  * @param config: to apply. Side effect: global constants change.
464  */
465 void config_apply(struct config_file* config);
466 
467 /**
468  * Find username, sets cfg_uid and cfg_gid.
469  * @param config: the config structure.
470  */
471 void config_lookup_uid(struct config_file* config);
472 
473 /**
474  * Set the given keyword to the given value.
475  * @param config: where to store config
476  * @param option: option name, including the ':' character.
477  * @param value: value, this string is copied if needed, or parsed.
478  * 	The caller owns the value string.
479  * @return 0 on error (malloc or syntax error).
480  */
481 int config_set_option(struct config_file* config, const char* option,
482 	const char* value);
483 
484 /**
485  * Call print routine for the given option.
486  * @param cfg: config.
487  * @param opt: option name without trailing :.
488  *	This is different from config_set_option.
489  * @param func: print func, called as (str, arg) for every data element.
490  * @param arg: user argument for print func.
491  * @return false if the option name is not supported (syntax error).
492  */
493 int config_get_option(struct config_file* cfg, const char* opt,
494 	void (*func)(char*,void*), void* arg);
495 
496 /**
497  * Get an option and return strlist
498  * @param cfg: config file
499  * @param opt: option name.
500  * @param list: list is returned here. malloced, caller must free it.
501  * @return 0=OK, 1=syntax error, 2=malloc failed.
502  */
503 int config_get_option_list(struct config_file* cfg, const char* opt,
504 	struct config_strlist** list);
505 
506 /**
507  * Get an option and collate results into string
508  * @param cfg: config file
509  * @param opt: option name.
510  * @param str: string. malloced, caller must free it.
511  * @return 0=OK, 1=syntax error, 2=malloc failed.
512  */
513 int config_get_option_collate(struct config_file* cfg, const char* opt,
514 	char** str);
515 
516 /**
517  * function to print to a file, use as func with config_get_option.
518  * @param line: text to print. \n appended.
519  * @param arg: pass a FILE*, like stdout.
520  */
521 void config_print_func(char* line, void* arg);
522 
523 /**
524  * function to collate the text strings into a strlist_head.
525  * @param line: text to append.
526  * @param arg: pass a strlist_head structure. zeroed on start.
527  */
528 void config_collate_func(char* line, void* arg);
529 
530 /**
531  * take a strlist_head list and return a malloc string. separated with newline.
532  * @param list: strlist first to collate. zeroes return "".
533  * @return NULL on malloc failure. Or if malloc failure happened in strlist.
534  */
535 char* config_collate_cat(struct config_strlist* list);
536 
537 /**
538  * Append text at end of list.
539  * @param list: list head. zeroed at start.
540  * @param item: new item. malloced by caller. if NULL the insertion fails.
541  * @return true on success.
542  */
543 int cfg_strlist_append(struct config_strlist_head* list, char* item);
544 
545 /**
546  * Insert string into strlist.
547  * @param head: pointer to strlist head variable.
548  * @param item: new item. malloced by caller. If NULL the insertion fails.
549  * @return: true on success.
550  */
551 int cfg_strlist_insert(struct config_strlist** head, char* item);
552 
553 /**
554  * Insert string into str2list.
555  * @param head: pointer to str2list head variable.
556  * @param item: new item. malloced by caller. If NULL the insertion fails.
557  * @param i2: 2nd string, malloced by caller. If NULL the insertion fails.
558  * @return: true on success.
559  */
560 int cfg_str2list_insert(struct config_str2list** head, char* item, char* i2);
561 
562 /**
563  * Find stub in config list, also returns prevptr (for deletion).
564  * @param pp: call routine with pointer to a pointer to the start of the list,
565  * 	if the stub is found, on exit, the value contains a pointer to the
566  * 	next pointer that points to the found element (or to the list start
567  * 	pointer if it is the first element).
568  * @param nm: name of stub to find.
569  * @return: pointer to config_stub if found, or NULL if not found.
570  */
571 struct config_stub* cfg_stub_find(struct config_stub*** pp, const char* nm);
572 
573 /**
574  * Delete items in config string list.
575  * @param list: list.
576  */
577 void config_delstrlist(struct config_strlist* list);
578 
579 /**
580  * Delete items in config double string list.
581  * @param list: list.
582  */
583 void config_deldblstrlist(struct config_str2list* list);
584 
585 /**
586  * Delete a stub item
587  * @param p: stub item
588  */
589 void config_delstub(struct config_stub* p);
590 
591 /**
592  * Delete items in config stub list.
593  * @param list: list.
594  */
595 void config_delstubs(struct config_stub* list);
596 
597 /**
598  * Convert 14digit to time value
599  * @param str: string of 14 digits
600  * @return time value or 0 for error.
601  */
602 time_t cfg_convert_timeval(const char* str);
603 
604 /**
605  * Count number of values in the string.
606  * format ::= (sp num)+ sp
607  * num ::= [-](0-9)+
608  * sp ::= (space|tab)*
609  *
610  * @param str: string
611  * @return: 0 on parse error, or empty string, else
612  *	number of integer values in the string.
613  */
614 int cfg_count_numbers(const char* str);
615 
616 /**
617  * Convert a 'nice' memory or file size into a bytecount
618  * From '100k' to 102400. and so on. Understands kKmMgG.
619  * k=1024, m=1024*1024, g=1024*1024*1024.
620  * @param str: string
621  * @param res: result is stored here, size in bytes.
622  * @return: true if parsed correctly, or 0 on a parse error (and an error
623  * is logged).
624  */
625 int cfg_parse_memsize(const char* str, size_t* res);
626 
627 /**
628  * Parse local-zone directive into two strings and register it in the config.
629  * @param cfg: to put it in.
630  * @param val: argument strings to local-zone, "example.com nodefault".
631  * @return: false on failure
632  */
633 int cfg_parse_local_zone(struct config_file* cfg, const char* val);
634 
635 /**
636  * Mark "number" or "low-high" as available or not in ports array.
637  * @param str: string in input
638  * @param allow: give true if this range is permitted.
639  * @param avail: the array from cfg.
640  * @param num: size of the array (65536).
641  * @return: true if parsed correctly, or 0 on a parse error (and an error
642  * is logged).
643  */
644 int cfg_mark_ports(const char* str, int allow, int* avail, int num);
645 
646 /**
647  * Get a condensed list of ports returned. allocated.
648  * @param cfg: config file.
649  * @param avail: the available ports array is returned here.
650  * @return: number of ports in array or 0 on error.
651  */
652 int cfg_condense_ports(struct config_file* cfg, int** avail);
653 
654 /**
655  * Scan ports available
656  * @param avail: the array from cfg.
657  * @param num: size of the array (65536).
658  * @return the number of ports available for use.
659  */
660 int cfg_scan_ports(int* avail, int num);
661 
662 /**
663  * Convert a filename to full pathname in original filesys
664  * @param fname: the path name to convert.
665  *      Must not be null or empty.
666  * @param cfg: config struct for chroot and chdir (if set).
667  * @param use_chdir: if false, only chroot is applied.
668  * @return pointer to malloced buffer which is: [chroot][chdir]fname
669  *      or NULL on malloc failure.
670  */
671 char* fname_after_chroot(const char* fname, struct config_file* cfg,
672 	int use_chdir);
673 
674 /**
675  * Convert a ptr shorthand into a full reverse-notation PTR record.
676  * @param str: input string, "IP name"
677  * @return: malloced string "reversed-ip-name PTR name"
678  */
679 char* cfg_ptr_reverse(char* str);
680 
681 /**
682  * Append text to the error info for validation.
683  * @param qstate: query state.
684  * @param str: copied into query region and appended.
685  * Failures to allocate are logged.
686  */
687 void errinf(struct module_qstate* qstate, const char* str);
688 
689 /**
690  * Append text to error info:  from 1.2.3.4
691  * @param qstate: query state.
692  * @param origin: sock list with origin of trouble.
693  *	Every element added.
694  *	If NULL: nothing is added.
695  *	if 0len element: 'from cache' is added.
696  */
697 void errinf_origin(struct module_qstate* qstate, struct sock_list *origin);
698 
699 /**
700  * Append text to error info:  for RRset name type class
701  * @param qstate: query state.
702  * @param rr: rrset_key.
703  */
704 void errinf_rrset(struct module_qstate* qstate, struct ub_packed_rrset_key *rr);
705 
706 /**
707  * Append text to error info:  str dname
708  * @param qstate: query state.
709  * @param str: explanation string
710  * @param dname: the dname.
711  */
712 void errinf_dname(struct module_qstate* qstate, const char* str,
713 	uint8_t* dname);
714 
715 /**
716  * Create error info in string
717  * @param qstate: query state.
718  * @return string or NULL on malloc failure (already logged).
719  *    This string is malloced and has to be freed by caller.
720  */
721 char* errinf_to_str(struct module_qstate* qstate);
722 
723 /**
724  * Used during options parsing
725  */
726 struct config_parser_state {
727 	/** name of file being parser */
728 	char* filename;
729 	/** line number in the file, starts at 1 */
730 	int line;
731 	/** number of errors encountered */
732 	int errors;
733 	/** the result of parsing is stored here. */
734 	struct config_file* cfg;
735 	/** the current chroot dir (or NULL if none) */
736 	const char* chroot;
737 };
738 
739 /** global config parser object used during config parsing */
740 extern struct config_parser_state* cfg_parser;
741 /** init lex state */
742 void init_cfg_parse(void);
743 /** lex in file */
744 extern FILE* ub_c_in;
745 /** lex out file */
746 extern FILE* ub_c_out;
747 /** the yacc lex generated parse function */
748 int ub_c_parse(void);
749 /** the lexer function */
750 int ub_c_lex(void);
751 /** wrap function */
752 int ub_c_wrap(void);
753 /** parsing helpers: print error with file and line numbers */
754 void ub_c_error(const char* msg);
755 /** parsing helpers: print error with file and line numbers */
756 void ub_c_error_msg(const char* fmt, ...) ATTR_FORMAT(printf, 1, 2);
757 
758 #ifdef UB_ON_WINDOWS
759 /**
760  * Obtain registry string (if it exists).
761  * @param key: key string
762  * @param name: name of value to fetch.
763  * @return malloced string with the result or NULL if it did not
764  * 	exist on an error (logged with log_err) was encountered.
765  */
766 char* w_lookup_reg_str(const char* key, const char* name);
767 
768 /** Modify directory in options for module file name */
769 void w_config_adjust_directory(struct config_file* cfg);
770 #endif /* UB_ON_WINDOWS */
771 
772 #endif /* UTIL_CONFIG_FILE_H */
773