ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/conf_lexer.l
Revision: 9692
Committed: Sat Oct 31 19:05:15 2020 UTC (5 years, 9 months ago) by michael
File size: 19248 byte(s)
Log Message:
- For consistency, the `general::network_desc` configuration directive has been renamed to `general::network_description`

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 *
4 * Copyright (c) 2000-2020 ircd-hybrid development team
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19 * USA
20 */
21
22 /*! \file conf_lexer.l
23 * \brief Scans the ircd configuration file for tokens.
24 * \version $Id$
25 */
26
27 %option case-insensitive
28 %option noyywrap
29 %option nounput
30 %option never-interactive
31
32 %{
33 #include "stdinc.h"
34 #include "irc_string.h"
35 #include "conf.h"
36 #include "conf_parser.h" /* autogenerated header file */
37 #include "log.h"
38
39 #undef YY_INPUT
40 #define YY_FATAL_ERROR(msg) conf_yy_fatal_error(msg)
41 #define YY_INPUT(buf,result,max_size) \
42 if ((result = conf_yy_input(buf, max_size)) == 0) \
43 YY_FATAL_ERROR("input in flex scanner failed");
44 #define MAX_INCLUDE_DEPTH 10
45
46
47 unsigned int lineno = 1;
48 char linebuf[IRCD_BUFSIZE];
49 char conffilebuf[IRCD_BUFSIZE];
50
51 static struct included_file
52 {
53 YY_BUFFER_STATE state;
54 unsigned int lineno;
55 FILE *file;
56 char conffile[IRCD_BUFSIZE];
57 } include_stack[MAX_INCLUDE_DEPTH];
58
59 static unsigned int include_stack_ptr;
60
61 static void ccomment(void);
62 static void cinclude(void);
63 static bool ieof(void);
64
65 static int
66 conf_yy_input(char *lbuf, unsigned int max_size)
67 {
68 return fgets(lbuf, max_size, conf_parser_ctx.conf_file) == NULL ? 0 : strlen(lbuf);
69 }
70
71 static int
72 conf_yy_fatal_error(const char *msg)
73 {
74 return 0;
75 }
76
77 %}
78
79 WS [[:blank:]]*
80 DIGIT [[:digit:]]+
81 COMMENT ("//"|"#").*
82 qstring \"[^\"\n]*[\"\n]
83 include \.include{WS}(\<.*\>|\".*\")
84
85 %%
86 {include} { cinclude(); }
87 "/*" { ccomment(); }
88 \n.* { strlcpy(linebuf, yytext + 1, sizeof(linebuf)); ++lineno; yyless(1); }
89 {WS} ;
90 {COMMENT} ;
91 {DIGIT} { yylval.number = atoi(yytext); return NUMBER; }
92 {qstring} { if (yytext[yyleng - 2] == '\\')
93 {
94 yyless(yyleng - 1); /* Return last quote */
95 yymore(); /* Append next string */
96 }
97 else
98 {
99 yylval.string = yytext + 1;
100
101 if (yylval.string[yyleng - 2] != '"')
102 ilog(LOG_TYPE_IRCD, "Unterminated character string");
103 else
104 {
105 unsigned int i = 0, j = 0;
106
107 yylval.string[yyleng - 2] = '\0'; /* Remove close quote */
108
109 for (; yylval.string[i] != '\0'; ++i, ++j)
110 {
111 if (yylval.string[i] != '\\')
112 yylval.string[j] = yylval.string[i];
113 else
114 {
115 ++i;
116
117 if (yylval.string[i] == '\0') /* XXX: should not happen */
118 {
119 ilog(LOG_TYPE_IRCD, "Unterminated character string");
120 break;
121 }
122
123 yylval.string[j] = yylval.string[i];
124 }
125 }
126
127 yylval.string[j] = '\0';
128 return QSTRING;
129 }
130 }
131 }
132
133 accept_password { return ACCEPT_PASSWORD; }
134 admin { return ADMIN; }
135 administrator { return ADMIN; }
136 aftype { return AFTYPE; }
137 all { return T_ALL; }
138 anti_nick_flood { return ANTI_NICK_FLOOD; }
139 anti_spam_exit_message_time { return ANTI_SPAM_EXIT_MESSAGE_TIME; }
140 auth { return IRCD_AUTH; }
141 autoconn { return AUTOCONN; }
142 away_count { return AWAY_COUNT; }
143 away_time { return AWAY_TIME; }
144 bind { return T_BIND; }
145 caller_id_wait { return CALLER_ID_WAIT; }
146 callerid { return T_CALLERID; }
147 can_flood { return CAN_FLOOD; }
148 cconn { return T_CCONN; }
149 channel { return CHANNEL; }
150 cidr_bitlen_ipv4 { return CIDR_BITLEN_IPV4; }
151 cidr_bitlen_ipv6 { return CIDR_BITLEN_IPV6; }
152 class { return CLASS; }
153 client { return CLIENT; }
154 close { return CLOSE; }
155 cluster { return T_CLUSTER; }
156 command { return T_COMMAND; }
157 connect { return CONNECT; }
158 connectfreq { return CONNECTFREQ; }
159 cycle_on_host_change { return CYCLE_ON_HOST_CHANGE; }
160 deaf { return T_DEAF; }
161 debug { return T_DEBUG; }
162 default_floodcount { return DEFAULT_FLOODCOUNT; }
163 default_floodtime { return DEFAULT_FLOODTIME; }
164 default_join_flood_count { return DEFAULT_JOIN_FLOOD_COUNT; }
165 default_join_flood_time { return DEFAULT_JOIN_FLOOD_TIME; }
166 default_max_clients { return DEFAULT_MAX_CLIENTS; }
167 defer { return DEFER; }
168 deny { return DENY; }
169 description { return DESCRIPTION; }
170 die { return DIE; }
171 disable_auth { return DISABLE_AUTH; }
172 disable_fake_channels { return DISABLE_FAKE_CHANNELS; }
173 disable_remote_commands { return DISABLE_REMOTE_COMMANDS; }
174 dline { return T_DLINE; }
175 dline_min_cidr { return DLINE_MIN_CIDR; }
176 dline_min_cidr6 { return DLINE_MIN_CIDR6; }
177 dots_in_ident { return DOTS_IN_IDENT; }
178 email { return EMAIL; }
179 enable_extbans { return ENABLE_EXTBANS; }
180 encrypted { return ENCRYPTED; }
181 exceed_limit { return EXCEED_LIMIT; }
182 exempt { return EXEMPT; }
183 expiration { return EXPIRATION; }
184 external { return T_EXTERNAL; }
185 failed_oper_notice { return FAILED_OPER_NOTICE; }
186 farconnect { return T_FARCONNECT; }
187 file { return T_FILE; }
188 flags { return IRCD_FLAGS; }
189 flatten_links { return FLATTEN_LINKS; }
190 flatten_links_delay { return FLATTEN_LINKS_DELAY; }
191 flatten_links_file { return FLATTEN_LINKS_FILE; }
192 flood { return T_FLOOD; }
193 gecos { return GECOS; }
194 general { return GENERAL; }
195 kline_min_cidr { return KLINE_MIN_CIDR; }
196 kline_min_cidr6 { return KLINE_MIN_CIDR6; }
197 globops { return T_GLOBOPS; }
198 have_ident { return NEED_IDENT; }
199 hidden { return HIDDEN; }
200 hidden_name { return HIDDEN_NAME; }
201 hidechans { return HIDE_CHANS; }
202 hideidle { return HIDE_IDLE; }
203 hide_idle_from_opers { return HIDE_IDLE_FROM_OPERS; }
204 hide_server_ips { return HIDE_SERVER_IPS; }
205 hide_servers { return HIDE_SERVERS; }
206 hide_services { return HIDE_SERVICES; }
207 host { return HOST; }
208 hub { return HUB; }
209 hub_mask { return HUB_MASK; }
210 invisible { return T_INVISIBLE; }
211 invisible_on_connect { return INVISIBLE_ON_CONNECT; }
212 invite_client_count { return INVITE_CLIENT_COUNT; }
213 invite_client_time { return INVITE_CLIENT_TIME; }
214 invite_delay_channel { return INVITE_DELAY_CHANNEL; }
215 invite_expire_time { return INVITE_EXPIRE_TIME; }
216 ip { return IP; }
217 ipv4 { return T_IPV4; }
218 ipv6 { return T_IPV6; }
219 join { return JOIN; }
220 kill { return KILL; }
221 kill_chase_time_limit { return KILL_CHASE_TIME_LIMIT; }
222 kline { return KLINE; }
223 kline_exempt { return KLINE_EXEMPT; }
224 knock_client_count { return KNOCK_CLIENT_COUNT; }
225 knock_client_time { return KNOCK_CLIENT_TIME; }
226 knock_delay_channel { return KNOCK_DELAY_CHANNEL; }
227 leaf_mask { return LEAF_MASK; }
228 listen { return LISTEN; }
229 locops { return T_LOCOPS; }
230 log { return T_LOG; }
231 mask { return MASK; }
232 max_accept { return MAX_ACCEPT; }
233 max_bans { return MAX_BANS; }
234 max_bans_large { return MAX_BANS_LARGE; }
235 max_channels { return MAX_CHANNELS; }
236 max_idle { return MAX_IDLE; }
237 max_invites { return MAX_INVITES; }
238 max_nick_changes { return MAX_NICK_CHANGES; }
239 max_nick_length { return MAX_NICK_LENGTH; }
240 max_nick_time { return MAX_NICK_TIME; }
241 max_number { return MAX_NUMBER; }
242 max_targets { return MAX_TARGETS; }
243 max_topic_length { return MAX_TOPIC_LENGTH; }
244 max_watch { return MAX_WATCH; }
245 min_idle { return MIN_IDLE; }
246 min_nonwildcard { return MIN_NONWILDCARD; }
247 min_nonwildcard_simple { return MIN_NONWILDCARD_SIMPLE; }
248 module { return MODULE; }
249 modules { return MODULES; }
250 motd { return MOTD; }
251 name { return NAME; }
252 nchange { return T_NCHANGE; }
253 need_ident { return NEED_IDENT; }
254 need_password { return NEED_PASSWORD; }
255 network_description { return NETWORK_DESCRIPTION; }
256 network_name { return NETWORK_NAME; }
257 nick { return NICK; }
258 no_oper_flood { return NO_OPER_FLOOD; }
259 no_tilde { return NO_TILDE; }
260 nononreg { return T_NONONREG; }
261 number_per_cidr { return NUMBER_PER_CIDR; }
262 number_per_ip_global { return NUMBER_PER_IP_GLOBAL; }
263 number_per_ip_local { return NUMBER_PER_IP_LOCAL; }
264 oper { return OPERATOR; }
265 oper_only_umodes { return OPER_ONLY_UMODES; }
266 oper_umodes { return OPER_UMODES; }
267 operator { return OPERATOR; }
268 opers_bypass_callerid { return OPERS_BYPASS_CALLERID; }
269 opme { return T_OPME; }
270 pace_wait { return PACE_WAIT; }
271 pace_wait_simple { return PACE_WAIT_SIMPLE; }
272 password { return PASSWORD; }
273 path { return PATH; }
274 ping_cookie { return PING_COOKIE; }
275 ping_time { return PING_TIME; }
276 port { return PORT; }
277 prepend { return T_PREPEND; }
278 pseudo { return T_PSEUDO; }
279 random_idle { return RANDOM_IDLE; }
280 reason { return REASON; }
281 recvq { return T_RECVQ; }
282 redirport { return REDIRPORT; }
283 redirserv { return REDIRSERV; }
284 rehash { return REHASH; }
285 rej { return T_REJ; }
286 remote { return REMOTE; }
287 remoteban { return REMOTEBAN; }
288 restart { return T_RESTART; }
289 resv { return RESV; }
290 resv_exempt { return RESV_EXEMPT; }
291 rsa_private_key_file { return RSA_PRIVATE_KEY_FILE; }
292 send_password { return SEND_PASSWORD; }
293 sendq { return SENDQ; }
294 server { return T_SERVER; }
295 serverhide { return SERVERHIDE; }
296 serverinfo { return SERVERINFO; }
297 service { return T_SERVICE; }
298 servnotice { return T_SERVNOTICE; }
299 set { return T_SET; }
300 shared { return T_SHARED; }
301 short_motd { return SHORT_MOTD; }
302 sid { return IRCD_SID; }
303 size { return T_SIZE; }
304 skill { return T_SKILL; }
305 softcallerid { return T_SOFTCALLERID; }
306 spoof { return SPOOF; }
307 spy { return T_SPY; }
308 squit { return SQUIT; }
309 ssl { return T_TLS; }
310 stats_e_disabled { return STATS_E_DISABLED; }
311 stats_i_oper_only { return STATS_I_OPER_ONLY; }
312 stats_k_oper_only { return STATS_K_OPER_ONLY; }
313 stats_m_oper_only { return STATS_M_OPER_ONLY; }
314 stats_o_oper_only { return STATS_O_OPER_ONLY; }
315 stats_P_oper_only { return STATS_P_OPER_ONLY; }
316 stats_u_oper_only { return STATS_U_OPER_ONLY; }
317 target { return T_TARGET; }
318 throttle_count { return THROTTLE_COUNT; }
319 throttle_time { return THROTTLE_TIME; }
320 timeout { return TIMEOUT; }
321 tls { return T_TLS; }
322 tls_certificate_file { return TLS_CERTIFICATE_FILE; }
323 tls_certificate_fingerprint { return TLS_CERTIFICATE_FINGERPRINT; }
324 tls_cipher_list { return TLS_CIPHER_LIST; }
325 tls_cipher_suites { return TLS_CIPHER_SUITES; }
326 tls_connection_required { return TLS_CONNECTION_REQUIRED; }
327 tls_dh_param_file { return TLS_DH_PARAM_FILE; }
328 tls_message_digest_algorithm { return TLS_MESSAGE_DIGEST_ALGORITHM; }
329 tls_supported_groups { return TLS_SUPPORTED_GROUPS; }
330 ts_max_delta { return TS_MAX_DELTA; }
331 ts_warn_delta { return TS_WARN_DELTA; }
332 type { return TYPE; }
333 umodes { return T_UMODES; }
334 undline { return T_UNDLINE; }
335 unkline { return UNKLINE; }
336 unlimited { return T_UNLIMITED; }
337 unresv { return T_UNRESV; }
338 unxline { return T_UNXLINE; }
339 use_logging { return USE_LOGGING; }
340 user { return USER; }
341 wallop { return T_WALLOP; }
342 wallops { return T_WALLOPS; }
343 warn_no_connect_block { return WARN_NO_CONNECT_BLOCK; }
344 webirc { return T_WEBIRC; }
345 whois { return WHOIS; }
346 whowas_history_length { return WHOWAS_HISTORY_LENGTH; }
347 xline { return XLINE; }
348 xline_exempt { return XLINE_EXEMPT; }
349
350 yes { yylval.number = 1; return TBOOL; }
351 no { yylval.number = 0; return TBOOL; }
352
353 years { return YEARS; }
354 year { return YEARS; }
355 months { return MONTHS; }
356 month { return MONTHS; }
357 weeks { return WEEKS; }
358 week { return WEEKS; }
359 days { return DAYS; }
360 day { return DAYS; }
361 hours { return HOURS; }
362 hour { return HOURS; }
363 minutes { return MINUTES; }
364 minute { return MINUTES; }
365 seconds { return SECONDS; }
366 second { return SECONDS; }
367
368 bytes { return BYTES; }
369 byte { return BYTES; }
370 kilobytes { return KBYTES; }
371 kilobyte { return KBYTES; }
372 kbytes { return KBYTES; }
373 kbyte { return KBYTES; }
374 kb { return KBYTES; }
375 megabytes { return MBYTES; }
376 megabyte { return MBYTES; }
377 mbytes { return MBYTES; }
378 mbyte { return MBYTES; }
379 mb { return MBYTES; }
380 \.\. { return TWODOTS; }
381
382 . { return yytext[0]; }
383 <<EOF>> { if (ieof() == true) yyterminate(); }
384
385 %%
386
387 /* C-comment ignoring routine -kre*/
388 static void
389 ccomment(void)
390 {
391 int c = 0;
392
393 /* log(L_NOTICE, "got comment"); */
394 while (1)
395 {
396 while ((c = input()) != '*' && c != EOF)
397 if (c == '\n')
398 ++lineno;
399
400 if (c == '*')
401 {
402 while ((c = input()) == '*')
403 /* Nothing */ ;
404 if (c == '/')
405 break;
406 else if (c == '\n')
407 ++lineno;
408 }
409
410 if (c == EOF)
411 {
412 YY_FATAL_ERROR("EOF in comment");
413 /* XXX hack alert this disables
414 * the stupid unused function warning
415 * gcc generates
416 */
417 if (1 == 0)
418 yy_fatal_error("EOF in comment");
419 break;
420 }
421 }
422 }
423
424 /* C-style .includes. This function will properly swap input conf buffers,
425 * and lineno -kre */
426 static void
427 cinclude(void)
428 {
429 char *p;
430 char filenamebuf[IRCD_BUFSIZE];
431
432 if ((p = strchr(yytext, '<')) == NULL)
433 *strchr(p = strchr(yytext, '"') + 1, '"') = '\0';
434 else
435 *strchr(++p, '>') = '\0';
436
437 /* do stacking and co. */
438 if (include_stack_ptr >= MAX_INCLUDE_DEPTH)
439 {
440 ilog(LOG_TYPE_IRCD, "Includes nested too deep in %s", p);
441 return;
442 }
443
444 if (*p == '/') /* if it is an absolute path */
445 snprintf(filenamebuf, sizeof(filenamebuf), "%s", p);
446 else
447 snprintf(filenamebuf, sizeof(filenamebuf), "%s/%s", ETCPATH, p);
448
449 FILE *tmp_fbfile_in = fopen(filenamebuf, "r");
450 if (tmp_fbfile_in == NULL)
451 {
452 ilog(LOG_TYPE_IRCD, "Unable to read configuration file '%s': %s",
453 filenamebuf, strerror(errno));
454 return;
455 }
456
457 struct included_file *file = &include_stack[include_stack_ptr++];
458 file->lineno = lineno;
459 file->file = conf_parser_ctx.conf_file;
460 file->state = YY_CURRENT_BUFFER;
461 strlcpy(file->conffile, conffilebuf, sizeof(file->conffile));
462
463 lineno = 1;
464 conf_parser_ctx.conf_file = tmp_fbfile_in;
465 strlcpy(conffilebuf, filenamebuf, sizeof(conffilebuf));
466
467 yy_switch_to_buffer(yy_create_buffer(NULL, YY_BUF_SIZE));
468 }
469
470 /* This is function that will be called on EOF in conf file. It will
471 * apropriately close conf if it not main conf and swap input buffers -kre
472 * */
473 static bool
474 ieof(void)
475 {
476 if (include_stack_ptr == 0)
477 {
478 lineno = 1;
479 return true;
480 }
481
482 /* switch buffer */
483 struct included_file *file = &include_stack[--include_stack_ptr];
484
485 /* close current file */
486 fclose(conf_parser_ctx.conf_file);
487
488 /* switch buffers */
489 yy_delete_buffer(YY_CURRENT_BUFFER);
490 yy_switch_to_buffer(file->state);
491
492 /* switch lineno */
493 lineno = file->lineno;
494
495 /* switch file */
496 conf_parser_ctx.conf_file = file->file;
497
498 strlcpy(conffilebuf, file->conffile, sizeof(conffilebuf));
499 return false;
500 }

Properties

Name Value
svn:eol-style native
svn:keywords Id