xref: /freebsd/contrib/unbound/util/configlexer.lex (revision 3416500aef140042c64bc149cb1ec6620483bc44)
1 %{
2 /*
3  * configlexer.lex - lexical analyzer for unbound config file
4  *
5  * Copyright (c) 2001-2006, NLnet Labs. All rights reserved
6  *
7  * See LICENSE for the license.
8  *
9  */
10 #include "config.h"
11 
12 /* because flex keeps having sign-unsigned compare problems that are unfixed*/
13 #pragma GCC diagnostic ignored "-Wsign-compare"
14 
15 #include <ctype.h>
16 #include <string.h>
17 #include <strings.h>
18 #ifdef HAVE_GLOB_H
19 # include <glob.h>
20 #endif
21 
22 #include "util/config_file.h"
23 #include "configparser.h"
24 void ub_c_error(const char *message);
25 
26 #if 0
27 #define LEXOUT(s)  printf s /* used ONLY when debugging */
28 #else
29 #define LEXOUT(s)
30 #endif
31 
32 /** avoid warning in about fwrite return value */
33 #define ECHO ub_c_error_msg("syntax error at text: %s", ub_c_text)
34 
35 /** A parser variable, this is a statement in the config file which is
36  * of the form variable: value1 value2 ...  nargs is the number of values. */
37 #define YDVAR(nargs, var) \
38 	num_args=(nargs); \
39 	LEXOUT(("v(%s%d) ", ub_c_text, num_args)); \
40 	if(num_args > 0) { BEGIN(val); } \
41 	return (var);
42 
43 struct inc_state {
44 	char* filename;
45 	int line;
46 	YY_BUFFER_STATE buffer;
47 	struct inc_state* next;
48 };
49 static struct inc_state* config_include_stack = NULL;
50 static int inc_depth = 0;
51 static int inc_prev = 0;
52 static int num_args = 0;
53 
54 void init_cfg_parse(void)
55 {
56 	config_include_stack = NULL;
57 	inc_depth = 0;
58 	inc_prev = 0;
59 	num_args = 0;
60 }
61 
62 static void config_start_include(const char* filename)
63 {
64 	FILE *input;
65 	struct inc_state* s;
66 	char* nm;
67 	if(inc_depth++ > 100000) {
68 		ub_c_error_msg("too many include files");
69 		return;
70 	}
71 	if(*filename == '\0') {
72 		ub_c_error_msg("empty include file name");
73 		return;
74 	}
75 	s = (struct inc_state*)malloc(sizeof(*s));
76 	if(!s) {
77 		ub_c_error_msg("include %s: malloc failure", filename);
78 		return;
79 	}
80 	if(cfg_parser->chroot && strncmp(filename, cfg_parser->chroot,
81 		strlen(cfg_parser->chroot)) == 0) {
82 		filename += strlen(cfg_parser->chroot);
83 	}
84 	nm = strdup(filename);
85 	if(!nm) {
86 		ub_c_error_msg("include %s: strdup failure", filename);
87 		free(s);
88 		return;
89 	}
90 	input = fopen(filename, "r");
91 	if(!input) {
92 		ub_c_error_msg("cannot open include file '%s': %s",
93 			filename, strerror(errno));
94 		free(s);
95 		free(nm);
96 		return;
97 	}
98 	LEXOUT(("switch_to_include_file(%s)\n", filename));
99 	s->filename = cfg_parser->filename;
100 	s->line = cfg_parser->line;
101 	s->buffer = YY_CURRENT_BUFFER;
102 	s->next = config_include_stack;
103 	config_include_stack = s;
104 	cfg_parser->filename = nm;
105 	cfg_parser->line = 1;
106 	yy_switch_to_buffer(yy_create_buffer(input, YY_BUF_SIZE));
107 }
108 
109 static void config_start_include_glob(const char* filename)
110 {
111 
112 	/* check for wildcards */
113 #ifdef HAVE_GLOB
114 	glob_t g;
115 	size_t i;
116 	int r, flags;
117 	if(!(!strchr(filename, '*') && !strchr(filename, '?') && !strchr(filename, '[') &&
118 		!strchr(filename, '{') && !strchr(filename, '~'))) {
119 		flags = 0
120 #ifdef GLOB_ERR
121 			| GLOB_ERR
122 #endif
123 #ifdef GLOB_NOSORT
124 			| GLOB_NOSORT
125 #endif
126 #ifdef GLOB_BRACE
127 			| GLOB_BRACE
128 #endif
129 #ifdef GLOB_TILDE
130 			| GLOB_TILDE
131 #endif
132 		;
133 		memset(&g, 0, sizeof(g));
134 		if(cfg_parser->chroot && strncmp(filename, cfg_parser->chroot,
135 			strlen(cfg_parser->chroot)) == 0) {
136 			filename += strlen(cfg_parser->chroot);
137 		}
138 		r = glob(filename, flags, NULL, &g);
139 		if(r) {
140 			/* some error */
141 			globfree(&g);
142 			if(r == GLOB_NOMATCH)
143 				return; /* no matches for pattern */
144 			config_start_include(filename); /* let original deal with it */
145 			return;
146 		}
147 		/* process files found, if any */
148 		for(i=0; i<(size_t)g.gl_pathc; i++) {
149 			config_start_include(g.gl_pathv[i]);
150 		}
151 		globfree(&g);
152 		return;
153 	}
154 #endif /* HAVE_GLOB */
155 
156 	config_start_include(filename);
157 }
158 
159 static void config_end_include(void)
160 {
161 	struct inc_state* s = config_include_stack;
162 	--inc_depth;
163 	if(!s) return;
164 	free(cfg_parser->filename);
165 	cfg_parser->filename = s->filename;
166 	cfg_parser->line = s->line;
167 	yy_delete_buffer(YY_CURRENT_BUFFER);
168 	yy_switch_to_buffer(s->buffer);
169 	config_include_stack = s->next;
170 	free(s);
171 }
172 
173 #ifndef yy_set_bol /* compat definition, for flex 2.4.6 */
174 #define yy_set_bol(at_bol) \
175         { \
176 	        if ( ! yy_current_buffer ) \
177 	                yy_current_buffer = yy_create_buffer( ub_c_in, YY_BUF_SIZE ); \
178 	        yy_current_buffer->yy_ch_buf[0] = ((at_bol)?'\n':' '); \
179         }
180 #endif
181 
182 %}
183 %option noinput
184 %option nounput
185 %{
186 #ifndef YY_NO_UNPUT
187 #define YY_NO_UNPUT 1
188 #endif
189 #ifndef YY_NO_INPUT
190 #define YY_NO_INPUT 1
191 #endif
192 %}
193 
194 SPACE   [ \t]
195 LETTER  [a-zA-Z]
196 UNQUOTEDLETTER [^\'\"\n\r \t\\]|\\.
197 UNQUOTEDLETTER_NOCOLON [^\:\'\"\n\r \t\\]|\\.
198 NEWLINE [\r\n]
199 COMMENT \#
200 COLON 	\:
201 DQANY     [^\"\n\r\\]|\\.
202 SQANY     [^\'\n\r\\]|\\.
203 
204 %x	quotedstring singlequotedstr include include_quoted val
205 
206 %%
207 <INITIAL,val>{SPACE}*	{
208 	LEXOUT(("SP ")); /* ignore */ }
209 <INITIAL,val>{SPACE}*{COMMENT}.*	{
210 	/* note that flex makes the longest match and '.' is any but not nl */
211 	LEXOUT(("comment(%s) ", ub_c_text)); /* ignore */ }
212 server{COLON}			{ YDVAR(0, VAR_SERVER) }
213 qname-minimisation{COLON}	{ YDVAR(1, VAR_QNAME_MINIMISATION) }
214 num-threads{COLON}		{ YDVAR(1, VAR_NUM_THREADS) }
215 verbosity{COLON}		{ YDVAR(1, VAR_VERBOSITY) }
216 port{COLON}			{ YDVAR(1, VAR_PORT) }
217 outgoing-range{COLON}		{ YDVAR(1, VAR_OUTGOING_RANGE) }
218 outgoing-port-permit{COLON}	{ YDVAR(1, VAR_OUTGOING_PORT_PERMIT) }
219 outgoing-port-avoid{COLON}	{ YDVAR(1, VAR_OUTGOING_PORT_AVOID) }
220 outgoing-num-tcp{COLON}		{ YDVAR(1, VAR_OUTGOING_NUM_TCP) }
221 incoming-num-tcp{COLON}		{ YDVAR(1, VAR_INCOMING_NUM_TCP) }
222 do-ip4{COLON}			{ YDVAR(1, VAR_DO_IP4) }
223 do-ip6{COLON}			{ YDVAR(1, VAR_DO_IP6) }
224 prefer-ip6{COLON}		{ YDVAR(1, VAR_PREFER_IP6) }
225 do-udp{COLON}			{ YDVAR(1, VAR_DO_UDP) }
226 do-tcp{COLON}			{ YDVAR(1, VAR_DO_TCP) }
227 tcp-upstream{COLON}		{ YDVAR(1, VAR_TCP_UPSTREAM) }
228 tcp-mss{COLON}			{ YDVAR(1, VAR_TCP_MSS) }
229 outgoing-tcp-mss{COLON}		{ YDVAR(1, VAR_OUTGOING_TCP_MSS) }
230 ssl-upstream{COLON}		{ YDVAR(1, VAR_SSL_UPSTREAM) }
231 ssl-service-key{COLON}		{ YDVAR(1, VAR_SSL_SERVICE_KEY) }
232 ssl-service-pem{COLON}		{ YDVAR(1, VAR_SSL_SERVICE_PEM) }
233 ssl-port{COLON}			{ YDVAR(1, VAR_SSL_PORT) }
234 do-daemonize{COLON}		{ YDVAR(1, VAR_DO_DAEMONIZE) }
235 interface{COLON}		{ YDVAR(1, VAR_INTERFACE) }
236 ip-address{COLON}		{ YDVAR(1, VAR_INTERFACE) }
237 outgoing-interface{COLON}	{ YDVAR(1, VAR_OUTGOING_INTERFACE) }
238 interface-automatic{COLON}	{ YDVAR(1, VAR_INTERFACE_AUTOMATIC) }
239 so-rcvbuf{COLON}		{ YDVAR(1, VAR_SO_RCVBUF) }
240 so-sndbuf{COLON}		{ YDVAR(1, VAR_SO_SNDBUF) }
241 so-reuseport{COLON}		{ YDVAR(1, VAR_SO_REUSEPORT) }
242 ip-transparent{COLON}		{ YDVAR(1, VAR_IP_TRANSPARENT) }
243 ip-freebind{COLON}		{ YDVAR(1, VAR_IP_FREEBIND) }
244 chroot{COLON}			{ YDVAR(1, VAR_CHROOT) }
245 username{COLON}			{ YDVAR(1, VAR_USERNAME) }
246 directory{COLON}		{ YDVAR(1, VAR_DIRECTORY) }
247 logfile{COLON}			{ YDVAR(1, VAR_LOGFILE) }
248 pidfile{COLON}			{ YDVAR(1, VAR_PIDFILE) }
249 root-hints{COLON}		{ YDVAR(1, VAR_ROOT_HINTS) }
250 edns-buffer-size{COLON}		{ YDVAR(1, VAR_EDNS_BUFFER_SIZE) }
251 msg-buffer-size{COLON}		{ YDVAR(1, VAR_MSG_BUFFER_SIZE) }
252 msg-cache-size{COLON}		{ YDVAR(1, VAR_MSG_CACHE_SIZE) }
253 msg-cache-slabs{COLON}		{ YDVAR(1, VAR_MSG_CACHE_SLABS) }
254 rrset-cache-size{COLON}		{ YDVAR(1, VAR_RRSET_CACHE_SIZE) }
255 rrset-cache-slabs{COLON}	{ YDVAR(1, VAR_RRSET_CACHE_SLABS) }
256 cache-max-ttl{COLON}     	{ YDVAR(1, VAR_CACHE_MAX_TTL) }
257 cache-max-negative-ttl{COLON}   { YDVAR(1, VAR_CACHE_MAX_NEGATIVE_TTL) }
258 cache-min-ttl{COLON}     	{ YDVAR(1, VAR_CACHE_MIN_TTL) }
259 infra-host-ttl{COLON}		{ YDVAR(1, VAR_INFRA_HOST_TTL) }
260 infra-lame-ttl{COLON}		{ YDVAR(1, VAR_INFRA_LAME_TTL) }
261 infra-cache-slabs{COLON}	{ YDVAR(1, VAR_INFRA_CACHE_SLABS) }
262 infra-cache-numhosts{COLON}	{ YDVAR(1, VAR_INFRA_CACHE_NUMHOSTS) }
263 infra-cache-lame-size{COLON}	{ YDVAR(1, VAR_INFRA_CACHE_LAME_SIZE) }
264 infra-cache-min-rtt{COLON}	{ YDVAR(1, VAR_INFRA_CACHE_MIN_RTT) }
265 num-queries-per-thread{COLON}	{ YDVAR(1, VAR_NUM_QUERIES_PER_THREAD) }
266 jostle-timeout{COLON}		{ YDVAR(1, VAR_JOSTLE_TIMEOUT) }
267 delay-close{COLON}		{ YDVAR(1, VAR_DELAY_CLOSE) }
268 target-fetch-policy{COLON}	{ YDVAR(1, VAR_TARGET_FETCH_POLICY) }
269 harden-short-bufsize{COLON}	{ YDVAR(1, VAR_HARDEN_SHORT_BUFSIZE) }
270 harden-large-queries{COLON}	{ YDVAR(1, VAR_HARDEN_LARGE_QUERIES) }
271 harden-glue{COLON}		{ YDVAR(1, VAR_HARDEN_GLUE) }
272 harden-dnssec-stripped{COLON}	{ YDVAR(1, VAR_HARDEN_DNSSEC_STRIPPED) }
273 harden-below-nxdomain{COLON}	{ YDVAR(1, VAR_HARDEN_BELOW_NXDOMAIN) }
274 harden-referral-path{COLON}	{ YDVAR(1, VAR_HARDEN_REFERRAL_PATH) }
275 harden-algo-downgrade{COLON}	{ YDVAR(1, VAR_HARDEN_ALGO_DOWNGRADE) }
276 use-caps-for-id{COLON}		{ YDVAR(1, VAR_USE_CAPS_FOR_ID) }
277 caps-whitelist{COLON}		{ YDVAR(1, VAR_CAPS_WHITELIST) }
278 unwanted-reply-threshold{COLON}	{ YDVAR(1, VAR_UNWANTED_REPLY_THRESHOLD) }
279 private-address{COLON}		{ YDVAR(1, VAR_PRIVATE_ADDRESS) }
280 private-domain{COLON}		{ YDVAR(1, VAR_PRIVATE_DOMAIN) }
281 prefetch-key{COLON}		{ YDVAR(1, VAR_PREFETCH_KEY) }
282 prefetch{COLON}			{ YDVAR(1, VAR_PREFETCH) }
283 stub-zone{COLON}		{ YDVAR(0, VAR_STUB_ZONE) }
284 name{COLON}			{ YDVAR(1, VAR_NAME) }
285 stub-addr{COLON}		{ YDVAR(1, VAR_STUB_ADDR) }
286 stub-host{COLON}		{ YDVAR(1, VAR_STUB_HOST) }
287 stub-prime{COLON}		{ YDVAR(1, VAR_STUB_PRIME) }
288 stub-first{COLON}		{ YDVAR(1, VAR_STUB_FIRST) }
289 forward-zone{COLON}		{ YDVAR(0, VAR_FORWARD_ZONE) }
290 forward-addr{COLON}		{ YDVAR(1, VAR_FORWARD_ADDR) }
291 forward-host{COLON}		{ YDVAR(1, VAR_FORWARD_HOST) }
292 forward-first{COLON}		{ YDVAR(1, VAR_FORWARD_FIRST) }
293 do-not-query-address{COLON}	{ YDVAR(1, VAR_DO_NOT_QUERY_ADDRESS) }
294 do-not-query-localhost{COLON}	{ YDVAR(1, VAR_DO_NOT_QUERY_LOCALHOST) }
295 access-control{COLON}		{ YDVAR(2, VAR_ACCESS_CONTROL) }
296 hide-identity{COLON}		{ YDVAR(1, VAR_HIDE_IDENTITY) }
297 hide-version{COLON}		{ YDVAR(1, VAR_HIDE_VERSION) }
298 identity{COLON}			{ YDVAR(1, VAR_IDENTITY) }
299 version{COLON}			{ YDVAR(1, VAR_VERSION) }
300 module-config{COLON}     	{ YDVAR(1, VAR_MODULE_CONF) }
301 dlv-anchor{COLON}		{ YDVAR(1, VAR_DLV_ANCHOR) }
302 dlv-anchor-file{COLON}		{ YDVAR(1, VAR_DLV_ANCHOR_FILE) }
303 trust-anchor-file{COLON}	{ YDVAR(1, VAR_TRUST_ANCHOR_FILE) }
304 auto-trust-anchor-file{COLON}	{ YDVAR(1, VAR_AUTO_TRUST_ANCHOR_FILE) }
305 trusted-keys-file{COLON}	{ YDVAR(1, VAR_TRUSTED_KEYS_FILE) }
306 trust-anchor{COLON}		{ YDVAR(1, VAR_TRUST_ANCHOR) }
307 val-override-date{COLON}	{ YDVAR(1, VAR_VAL_OVERRIDE_DATE) }
308 val-sig-skew-min{COLON}		{ YDVAR(1, VAR_VAL_SIG_SKEW_MIN) }
309 val-sig-skew-max{COLON}		{ YDVAR(1, VAR_VAL_SIG_SKEW_MAX) }
310 val-bogus-ttl{COLON}		{ YDVAR(1, VAR_BOGUS_TTL) }
311 val-clean-additional{COLON}	{ YDVAR(1, VAR_VAL_CLEAN_ADDITIONAL) }
312 val-permissive-mode{COLON}	{ YDVAR(1, VAR_VAL_PERMISSIVE_MODE) }
313 ignore-cd-flag{COLON}		{ YDVAR(1, VAR_IGNORE_CD_FLAG) }
314 val-log-level{COLON}		{ YDVAR(1, VAR_VAL_LOG_LEVEL) }
315 key-cache-size{COLON}		{ YDVAR(1, VAR_KEY_CACHE_SIZE) }
316 key-cache-slabs{COLON}		{ YDVAR(1, VAR_KEY_CACHE_SLABS) }
317 neg-cache-size{COLON}		{ YDVAR(1, VAR_NEG_CACHE_SIZE) }
318 val-nsec3-keysize-iterations{COLON}	{
319 				  YDVAR(1, VAR_VAL_NSEC3_KEYSIZE_ITERATIONS) }
320 add-holddown{COLON}		{ YDVAR(1, VAR_ADD_HOLDDOWN) }
321 del-holddown{COLON}		{ YDVAR(1, VAR_DEL_HOLDDOWN) }
322 keep-missing{COLON}		{ YDVAR(1, VAR_KEEP_MISSING) }
323 permit-small-holddown{COLON}	{ YDVAR(1, VAR_PERMIT_SMALL_HOLDDOWN) }
324 use-syslog{COLON}		{ YDVAR(1, VAR_USE_SYSLOG) }
325 log-time-ascii{COLON}		{ YDVAR(1, VAR_LOG_TIME_ASCII) }
326 log-queries{COLON}		{ YDVAR(1, VAR_LOG_QUERIES) }
327 local-zone{COLON}		{ YDVAR(2, VAR_LOCAL_ZONE) }
328 local-data{COLON}		{ YDVAR(1, VAR_LOCAL_DATA) }
329 local-data-ptr{COLON}		{ YDVAR(1, VAR_LOCAL_DATA_PTR) }
330 unblock-lan-zones{COLON}	{ YDVAR(1, VAR_UNBLOCK_LAN_ZONES) }
331 insecure-lan-zones{COLON}	{ YDVAR(1, VAR_INSECURE_LAN_ZONES) }
332 statistics-interval{COLON}	{ YDVAR(1, VAR_STATISTICS_INTERVAL) }
333 statistics-cumulative{COLON}	{ YDVAR(1, VAR_STATISTICS_CUMULATIVE) }
334 extended-statistics{COLON}	{ YDVAR(1, VAR_EXTENDED_STATISTICS) }
335 remote-control{COLON}		{ YDVAR(0, VAR_REMOTE_CONTROL) }
336 control-enable{COLON}		{ YDVAR(1, VAR_CONTROL_ENABLE) }
337 control-interface{COLON}	{ YDVAR(1, VAR_CONTROL_INTERFACE) }
338 control-port{COLON}		{ YDVAR(1, VAR_CONTROL_PORT) }
339 control-use-cert{COLON}		{ YDVAR(1, VAR_CONTROL_USE_CERT) }
340 server-key-file{COLON}		{ YDVAR(1, VAR_SERVER_KEY_FILE) }
341 server-cert-file{COLON}		{ YDVAR(1, VAR_SERVER_CERT_FILE) }
342 control-key-file{COLON}		{ YDVAR(1, VAR_CONTROL_KEY_FILE) }
343 control-cert-file{COLON}	{ YDVAR(1, VAR_CONTROL_CERT_FILE) }
344 python-script{COLON}		{ YDVAR(1, VAR_PYTHON_SCRIPT) }
345 python{COLON}			{ YDVAR(0, VAR_PYTHON) }
346 domain-insecure{COLON}		{ YDVAR(1, VAR_DOMAIN_INSECURE) }
347 minimal-responses{COLON}	{ YDVAR(1, VAR_MINIMAL_RESPONSES) }
348 rrset-roundrobin{COLON}		{ YDVAR(1, VAR_RRSET_ROUNDROBIN) }
349 max-udp-size{COLON}		{ YDVAR(1, VAR_MAX_UDP_SIZE) }
350 dns64-prefix{COLON}		{ YDVAR(1, VAR_DNS64_PREFIX) }
351 dns64-synthall{COLON}		{ YDVAR(1, VAR_DNS64_SYNTHALL) }
352 define-tag{COLON}		{ YDVAR(1, VAR_DEFINE_TAG) }
353 local-zone-tag{COLON}		{ YDVAR(2, VAR_LOCAL_ZONE_TAG) }
354 access-control-tag{COLON}	{ YDVAR(2, VAR_ACCESS_CONTROL_TAG) }
355 access-control-tag-action{COLON} { YDVAR(3, VAR_ACCESS_CONTROL_TAG_ACTION) }
356 access-control-tag-data{COLON}	{ YDVAR(3, VAR_ACCESS_CONTROL_TAG_DATA) }
357 local-zone-override{COLON}	{ YDVAR(3, VAR_LOCAL_ZONE_OVERRIDE) }
358 dnstap{COLON}			{ YDVAR(0, VAR_DNSTAP) }
359 dnstap-enable{COLON}		{ YDVAR(1, VAR_DNSTAP_ENABLE) }
360 dnstap-socket-path{COLON}	{ YDVAR(1, VAR_DNSTAP_SOCKET_PATH) }
361 dnstap-send-identity{COLON}	{ YDVAR(1, VAR_DNSTAP_SEND_IDENTITY) }
362 dnstap-send-version{COLON}	{ YDVAR(1, VAR_DNSTAP_SEND_VERSION) }
363 dnstap-identity{COLON}		{ YDVAR(1, VAR_DNSTAP_IDENTITY) }
364 dnstap-version{COLON}		{ YDVAR(1, VAR_DNSTAP_VERSION) }
365 dnstap-log-resolver-query-messages{COLON}	{
366 		YDVAR(1, VAR_DNSTAP_LOG_RESOLVER_QUERY_MESSAGES) }
367 dnstap-log-resolver-response-messages{COLON}	{
368 		YDVAR(1, VAR_DNSTAP_LOG_RESOLVER_RESPONSE_MESSAGES) }
369 dnstap-log-client-query-messages{COLON}		{
370 		YDVAR(1, VAR_DNSTAP_LOG_CLIENT_QUERY_MESSAGES) }
371 dnstap-log-client-response-messages{COLON}	{
372 		YDVAR(1, VAR_DNSTAP_LOG_CLIENT_RESPONSE_MESSAGES) }
373 dnstap-log-forwarder-query-messages{COLON}	{
374 		YDVAR(1, VAR_DNSTAP_LOG_FORWARDER_QUERY_MESSAGES) }
375 dnstap-log-forwarder-response-messages{COLON}	{
376 		YDVAR(1, VAR_DNSTAP_LOG_FORWARDER_RESPONSE_MESSAGES) }
377 disable-dnssec-lame-check{COLON} { YDVAR(1, VAR_DISABLE_DNSSEC_LAME_CHECK) }
378 ratelimit{COLON}		{ YDVAR(1, VAR_RATELIMIT) }
379 ratelimit-slabs{COLON}		{ YDVAR(1, VAR_RATELIMIT_SLABS) }
380 ratelimit-size{COLON}		{ YDVAR(1, VAR_RATELIMIT_SIZE) }
381 ratelimit-for-domain{COLON}	{ YDVAR(2, VAR_RATELIMIT_FOR_DOMAIN) }
382 ratelimit-below-domain{COLON}	{ YDVAR(2, VAR_RATELIMIT_BELOW_DOMAIN) }
383 ratelimit-factor{COLON}		{ YDVAR(1, VAR_RATELIMIT_FACTOR) }
384 <INITIAL,val>{NEWLINE}		{ LEXOUT(("NL\n")); cfg_parser->line++; }
385 
386 	/* Quoted strings. Strip leading and ending quotes */
387 <val>\"			{ BEGIN(quotedstring); LEXOUT(("QS ")); }
388 <quotedstring><<EOF>>   {
389         ub_c_error("EOF inside quoted string");
390 	if(--num_args == 0) { BEGIN(INITIAL); }
391 	else		    { BEGIN(val); }
392 }
393 <quotedstring>{DQANY}*  { LEXOUT(("STR(%s) ", ub_c_text)); yymore(); }
394 <quotedstring>{NEWLINE} { ub_c_error("newline inside quoted string, no end \"");
395 			  cfg_parser->line++; BEGIN(INITIAL); }
396 <quotedstring>\" {
397         LEXOUT(("QE "));
398 	if(--num_args == 0) { BEGIN(INITIAL); }
399 	else		    { BEGIN(val); }
400         ub_c_text[ub_c_leng - 1] = '\0';
401 	ub_c_lval.str = strdup(ub_c_text);
402 	if(!ub_c_lval.str)
403 		ub_c_error("out of memory");
404         return STRING_ARG;
405 }
406 
407 	/* Single Quoted strings. Strip leading and ending quotes */
408 <val>\'			{ BEGIN(singlequotedstr); LEXOUT(("SQS ")); }
409 <singlequotedstr><<EOF>>   {
410         ub_c_error("EOF inside quoted string");
411 	if(--num_args == 0) { BEGIN(INITIAL); }
412 	else		    { BEGIN(val); }
413 }
414 <singlequotedstr>{SQANY}*  { LEXOUT(("STR(%s) ", ub_c_text)); yymore(); }
415 <singlequotedstr>{NEWLINE} { ub_c_error("newline inside quoted string, no end '");
416 			     cfg_parser->line++; BEGIN(INITIAL); }
417 <singlequotedstr>\' {
418         LEXOUT(("SQE "));
419 	if(--num_args == 0) { BEGIN(INITIAL); }
420 	else		    { BEGIN(val); }
421         ub_c_text[ub_c_leng - 1] = '\0';
422 	ub_c_lval.str = strdup(ub_c_text);
423 	if(!ub_c_lval.str)
424 		ub_c_error("out of memory");
425         return STRING_ARG;
426 }
427 
428 	/* include: directive */
429 <INITIAL,val>include{COLON}	{
430 	LEXOUT(("v(%s) ", ub_c_text)); inc_prev = YYSTATE; BEGIN(include); }
431 <include><<EOF>>	{
432         ub_c_error("EOF inside include directive");
433         BEGIN(inc_prev);
434 }
435 <include>{SPACE}*	{ LEXOUT(("ISP ")); /* ignore */ }
436 <include>{NEWLINE}	{ LEXOUT(("NL\n")); cfg_parser->line++;}
437 <include>\"		{ LEXOUT(("IQS ")); BEGIN(include_quoted); }
438 <include>{UNQUOTEDLETTER}*	{
439 	LEXOUT(("Iunquotedstr(%s) ", ub_c_text));
440 	config_start_include_glob(ub_c_text);
441 	BEGIN(inc_prev);
442 }
443 <include_quoted><<EOF>>	{
444         ub_c_error("EOF inside quoted string");
445         BEGIN(inc_prev);
446 }
447 <include_quoted>{DQANY}*	{ LEXOUT(("ISTR(%s) ", ub_c_text)); yymore(); }
448 <include_quoted>{NEWLINE}	{ ub_c_error("newline before \" in include name");
449 				  cfg_parser->line++; BEGIN(inc_prev); }
450 <include_quoted>\"	{
451 	LEXOUT(("IQE "));
452 	ub_c_text[ub_c_leng - 1] = '\0';
453 	config_start_include_glob(ub_c_text);
454 	BEGIN(inc_prev);
455 }
456 <INITIAL,val><<EOF>>	{
457 	LEXOUT(("LEXEOF "));
458 	yy_set_bol(1); /* Set beginning of line, so "^" rules match.  */
459 	if (!config_include_stack) {
460 		yyterminate();
461 	} else {
462 		fclose(ub_c_in);
463 		config_end_include();
464 	}
465 }
466 
467 <val>{UNQUOTEDLETTER}*	{ LEXOUT(("unquotedstr(%s) ", ub_c_text));
468 			if(--num_args == 0) { BEGIN(INITIAL); }
469 			ub_c_lval.str = strdup(ub_c_text); return STRING_ARG; }
470 
471 {UNQUOTEDLETTER_NOCOLON}*	{
472 	ub_c_error_msg("unknown keyword '%s'", ub_c_text);
473 	}
474 
475 <*>.	{
476 	ub_c_error_msg("stray '%s'", ub_c_text);
477 	}
478 
479 %%
480