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