ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/conf_lexer.l
Revision: 9610
Committed: Sun Sep 6 07:28:30 2020 UTC (5 years, 10 months ago) by michael
File size: 19336 byte(s)
Log Message:
- Implement accept() deferring. Closes github issue #4

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 bots { return T_BOTS; }
146 caller_id_wait { return CALLER_ID_WAIT; }
147 callerid { return T_CALLERID; }
148 can_flood { return CAN_FLOOD; }
149 cconn { return T_CCONN; }
150 channel { return CHANNEL; }
151 cidr_bitlen_ipv4 { return CIDR_BITLEN_IPV4; }
152 cidr_bitlen_ipv6 { return CIDR_BITLEN_IPV6; }
153 class { return CLASS; }
154 client { return CLIENT; }
155 close { return CLOSE; }
156 cluster { return T_CLUSTER; }
157 command { return T_COMMAND; }
158 connect { return CONNECT; }
159 connectfreq { return CONNECTFREQ; }
160 cycle_on_host_change { return CYCLE_ON_HOST_CHANGE; }
161 deaf { return T_DEAF; }
162 debug { return T_DEBUG; }
163 default_floodcount { return DEFAULT_FLOODCOUNT; }
164 default_floodtime { return DEFAULT_FLOODTIME; }
165 default_join_flood_count { return DEFAULT_JOIN_FLOOD_COUNT; }
166 default_join_flood_time { return DEFAULT_JOIN_FLOOD_TIME; }
167 default_max_clients { return DEFAULT_MAX_CLIENTS; }
168 defer { return DEFER; }
169 deny { return DENY; }
170 description { return DESCRIPTION; }
171 die { return DIE; }
172 disable_auth { return DISABLE_AUTH; }
173 disable_fake_channels { return DISABLE_FAKE_CHANNELS; }
174 disable_remote_commands { return DISABLE_REMOTE_COMMANDS; }
175 dline { return T_DLINE; }
176 dline_min_cidr { return DLINE_MIN_CIDR; }
177 dline_min_cidr6 { return DLINE_MIN_CIDR6; }
178 dots_in_ident { return DOTS_IN_IDENT; }
179 email { return EMAIL; }
180 enable_extbans { return ENABLE_EXTBANS; }
181 encrypted { return ENCRYPTED; }
182 exceed_limit { return EXCEED_LIMIT; }
183 exempt { return EXEMPT; }
184 expiration { return EXPIRATION; }
185 external { return T_EXTERNAL; }
186 failed_oper_notice { return FAILED_OPER_NOTICE; }
187 farconnect { return T_FARCONNECT; }
188 file { return T_FILE; }
189 flags { return IRCD_FLAGS; }
190 flatten_links { return FLATTEN_LINKS; }
191 flatten_links_delay { return FLATTEN_LINKS_DELAY; }
192 flatten_links_file { return FLATTEN_LINKS_FILE; }
193 full { return T_FULL; }
194 gecos { return GECOS; }
195 general { return GENERAL; }
196 kline_min_cidr { return KLINE_MIN_CIDR; }
197 kline_min_cidr6 { return KLINE_MIN_CIDR6; }
198 globops { return T_GLOBOPS; }
199 have_ident { return NEED_IDENT; }
200 hidden { return HIDDEN; }
201 hidden_name { return HIDDEN_NAME; }
202 hidechans { return HIDE_CHANS; }
203 hideidle { return HIDE_IDLE; }
204 hide_idle_from_opers { return HIDE_IDLE_FROM_OPERS; }
205 hide_server_ips { return HIDE_SERVER_IPS; }
206 hide_servers { return HIDE_SERVERS; }
207 hide_services { return HIDE_SERVICES; }
208 host { return HOST; }
209 hub { return HUB; }
210 hub_mask { return HUB_MASK; }
211 invisible { return T_INVISIBLE; }
212 invisible_on_connect { return INVISIBLE_ON_CONNECT; }
213 invite_client_count { return INVITE_CLIENT_COUNT; }
214 invite_client_time { return INVITE_CLIENT_TIME; }
215 invite_delay_channel { return INVITE_DELAY_CHANNEL; }
216 invite_expire_time { return INVITE_EXPIRE_TIME; }
217 ip { return IP; }
218 ipv4 { return T_IPV4; }
219 ipv6 { return T_IPV6; }
220 join { return JOIN; }
221 kill { return KILL; }
222 kill_chase_time_limit { return KILL_CHASE_TIME_LIMIT; }
223 kline { return KLINE; }
224 kline_exempt { return KLINE_EXEMPT; }
225 knock_client_count { return KNOCK_CLIENT_COUNT; }
226 knock_client_time { return KNOCK_CLIENT_TIME; }
227 knock_delay_channel { return KNOCK_DELAY_CHANNEL; }
228 leaf_mask { return LEAF_MASK; }
229 listen { return LISTEN; }
230 locops { return T_LOCOPS; }
231 log { return T_LOG; }
232 mask { return MASK; }
233 max_accept { return MAX_ACCEPT; }
234 max_bans { return MAX_BANS; }
235 max_bans_large { return MAX_BANS_LARGE; }
236 max_channels { return MAX_CHANNELS; }
237 max_idle { return MAX_IDLE; }
238 max_invites { return MAX_INVITES; }
239 max_nick_changes { return MAX_NICK_CHANGES; }
240 max_nick_length { return MAX_NICK_LENGTH; }
241 max_nick_time { return MAX_NICK_TIME; }
242 max_number { return MAX_NUMBER; }
243 max_targets { return MAX_TARGETS; }
244 max_topic_length { return MAX_TOPIC_LENGTH; }
245 max_watch { return MAX_WATCH; }
246 min_idle { return MIN_IDLE; }
247 min_nonwildcard { return MIN_NONWILDCARD; }
248 min_nonwildcard_simple { return MIN_NONWILDCARD_SIMPLE; }
249 module { return MODULE; }
250 modules { return MODULES; }
251 motd { return MOTD; }
252 name { return NAME; }
253 nchange { return T_NCHANGE; }
254 need_ident { return NEED_IDENT; }
255 need_password { return NEED_PASSWORD; }
256 network_desc { return NETWORK_DESC; }
257 network_name { return NETWORK_NAME; }
258 nick { return NICK; }
259 no_oper_flood { return NO_OPER_FLOOD; }
260 no_tilde { return NO_TILDE; }
261 nononreg { return T_NONONREG; }
262 number_per_cidr { return NUMBER_PER_CIDR; }
263 number_per_ip_global { return NUMBER_PER_IP_GLOBAL; }
264 number_per_ip_local { return NUMBER_PER_IP_LOCAL; }
265 oper { return OPERATOR; }
266 oper_only_umodes { return OPER_ONLY_UMODES; }
267 oper_umodes { return OPER_UMODES; }
268 operator { return OPERATOR; }
269 opers_bypass_callerid { return OPERS_BYPASS_CALLERID; }
270 opme { return T_OPME; }
271 pace_wait { return PACE_WAIT; }
272 pace_wait_simple { return PACE_WAIT_SIMPLE; }
273 password { return PASSWORD; }
274 path { return PATH; }
275 ping_cookie { return PING_COOKIE; }
276 ping_time { return PING_TIME; }
277 port { return PORT; }
278 prepend { return T_PREPEND; }
279 pseudo { return T_PSEUDO; }
280 random_idle { return RANDOM_IDLE; }
281 reason { return REASON; }
282 recvq { return T_RECVQ; }
283 redirport { return REDIRPORT; }
284 redirserv { return REDIRSERV; }
285 rehash { return REHASH; }
286 rej { return T_REJ; }
287 remote { return REMOTE; }
288 remoteban { return REMOTEBAN; }
289 restart { return T_RESTART; }
290 resv { return RESV; }
291 resv_exempt { return RESV_EXEMPT; }
292 rsa_private_key_file { return RSA_PRIVATE_KEY_FILE; }
293 send_password { return SEND_PASSWORD; }
294 sendq { return SENDQ; }
295 server { return T_SERVER; }
296 serverhide { return SERVERHIDE; }
297 serverinfo { return SERVERINFO; }
298 service { return T_SERVICE; }
299 servnotice { return T_SERVNOTICE; }
300 set { return T_SET; }
301 shared { return T_SHARED; }
302 short_motd { return SHORT_MOTD; }
303 sid { return IRCD_SID; }
304 size { return T_SIZE; }
305 skill { return T_SKILL; }
306 softcallerid { return T_SOFTCALLERID; }
307 spoof { return SPOOF; }
308 spy { return T_SPY; }
309 squit { return SQUIT; }
310 ssl { return T_TLS; }
311 stats_e_disabled { return STATS_E_DISABLED; }
312 stats_i_oper_only { return STATS_I_OPER_ONLY; }
313 stats_k_oper_only { return STATS_K_OPER_ONLY; }
314 stats_m_oper_only { return STATS_M_OPER_ONLY; }
315 stats_o_oper_only { return STATS_O_OPER_ONLY; }
316 stats_P_oper_only { return STATS_P_OPER_ONLY; }
317 stats_u_oper_only { return STATS_U_OPER_ONLY; }
318 target { return T_TARGET; }
319 throttle_count { return THROTTLE_COUNT; }
320 throttle_time { return THROTTLE_TIME; }
321 timeout { return TIMEOUT; }
322 tls { return T_TLS; }
323 tls_certificate_file { return TLS_CERTIFICATE_FILE; }
324 tls_certificate_fingerprint { return TLS_CERTIFICATE_FINGERPRINT; }
325 tls_cipher_list { return TLS_CIPHER_LIST; }
326 tls_cipher_suites { return TLS_CIPHER_SUITES; }
327 tls_connection_required { return TLS_CONNECTION_REQUIRED; }
328 tls_dh_param_file { return TLS_DH_PARAM_FILE; }
329 tls_message_digest_algorithm { return TLS_MESSAGE_DIGEST_ALGORITHM; }
330 tls_supported_groups { return TLS_SUPPORTED_GROUPS; }
331 ts_max_delta { return TS_MAX_DELTA; }
332 ts_warn_delta { return TS_WARN_DELTA; }
333 type { return TYPE; }
334 umodes { return T_UMODES; }
335 unauth { return T_UNAUTH; }
336 undline { return T_UNDLINE; }
337 unkline { return UNKLINE; }
338 unlimited { return T_UNLIMITED; }
339 unresv { return T_UNRESV; }
340 unxline { return T_UNXLINE; }
341 use_logging { return USE_LOGGING; }
342 user { return USER; }
343 wallop { return T_WALLOP; }
344 wallops { return T_WALLOPS; }
345 warn_no_connect_block { return WARN_NO_CONNECT_BLOCK; }
346 webirc { return T_WEBIRC; }
347 whois { return WHOIS; }
348 whowas_history_length { return WHOWAS_HISTORY_LENGTH; }
349 xline { return XLINE; }
350 xline_exempt { return XLINE_EXEMPT; }
351
352 yes { yylval.number = 1; return TBOOL; }
353 no { yylval.number = 0; return TBOOL; }
354
355 years { return YEARS; }
356 year { return YEARS; }
357 months { return MONTHS; }
358 month { return MONTHS; }
359 weeks { return WEEKS; }
360 week { return WEEKS; }
361 days { return DAYS; }
362 day { return DAYS; }
363 hours { return HOURS; }
364 hour { return HOURS; }
365 minutes { return MINUTES; }
366 minute { return MINUTES; }
367 seconds { return SECONDS; }
368 second { return SECONDS; }
369
370 bytes { return BYTES; }
371 byte { return BYTES; }
372 kilobytes { return KBYTES; }
373 kilobyte { return KBYTES; }
374 kbytes { return KBYTES; }
375 kbyte { return KBYTES; }
376 kb { return KBYTES; }
377 megabytes { return MBYTES; }
378 megabyte { return MBYTES; }
379 mbytes { return MBYTES; }
380 mbyte { return MBYTES; }
381 mb { return MBYTES; }
382 \.\. { return TWODOTS; }
383
384 . { return yytext[0]; }
385 <<EOF>> { if (ieof() == true) yyterminate(); }
386
387 %%
388
389 /* C-comment ignoring routine -kre*/
390 static void
391 ccomment(void)
392 {
393 int c = 0;
394
395 /* log(L_NOTICE, "got comment"); */
396 while (1)
397 {
398 while ((c = input()) != '*' && c != EOF)
399 if (c == '\n')
400 ++lineno;
401
402 if (c == '*')
403 {
404 while ((c = input()) == '*')
405 /* Nothing */ ;
406 if (c == '/')
407 break;
408 else if (c == '\n')
409 ++lineno;
410 }
411
412 if (c == EOF)
413 {
414 YY_FATAL_ERROR("EOF in comment");
415 /* XXX hack alert this disables
416 * the stupid unused function warning
417 * gcc generates
418 */
419 if (1 == 0)
420 yy_fatal_error("EOF in comment");
421 break;
422 }
423 }
424 }
425
426 /* C-style .includes. This function will properly swap input conf buffers,
427 * and lineno -kre */
428 static void
429 cinclude(void)
430 {
431 char *p;
432 char filenamebuf[IRCD_BUFSIZE];
433
434 if ((p = strchr(yytext, '<')) == NULL)
435 *strchr(p = strchr(yytext, '"') + 1, '"') = '\0';
436 else
437 *strchr(++p, '>') = '\0';
438
439 /* do stacking and co. */
440 if (include_stack_ptr >= MAX_INCLUDE_DEPTH)
441 {
442 ilog(LOG_TYPE_IRCD, "Includes nested too deep in %s", p);
443 return;
444 }
445
446 if (*p == '/') /* if it is an absolute path */
447 snprintf(filenamebuf, sizeof(filenamebuf), "%s", p);
448 else
449 snprintf(filenamebuf, sizeof(filenamebuf), "%s/%s", ETCPATH, p);
450
451 FILE *tmp_fbfile_in = fopen(filenamebuf, "r");
452 if (tmp_fbfile_in == NULL)
453 {
454 ilog(LOG_TYPE_IRCD, "Unable to read configuration file '%s': %s",
455 filenamebuf, strerror(errno));
456 return;
457 }
458
459 struct included_file *file = &include_stack[include_stack_ptr++];
460 file->lineno = lineno;
461 file->file = conf_parser_ctx.conf_file;
462 file->state = YY_CURRENT_BUFFER;
463 strlcpy(file->conffile, conffilebuf, sizeof(file->conffile));
464
465 lineno = 1;
466 conf_parser_ctx.conf_file = tmp_fbfile_in;
467 strlcpy(conffilebuf, filenamebuf, sizeof(conffilebuf));
468
469 yy_switch_to_buffer(yy_create_buffer(NULL, YY_BUF_SIZE));
470 }
471
472 /* This is function that will be called on EOF in conf file. It will
473 * apropriately close conf if it not main conf and swap input buffers -kre
474 * */
475 static bool
476 ieof(void)
477 {
478 if (include_stack_ptr == 0)
479 {
480 lineno = 1;
481 return true;
482 }
483
484 /* switch buffer */
485 struct included_file *file = &include_stack[--include_stack_ptr];
486
487 /* close current file */
488 fclose(conf_parser_ctx.conf_file);
489
490 /* switch buffers */
491 yy_delete_buffer(YY_CURRENT_BUFFER);
492 yy_switch_to_buffer(file->state);
493
494 /* switch lineno */
495 lineno = file->lineno;
496
497 /* switch file */
498 conf_parser_ctx.conf_file = file->file;
499
500 strlcpy(conffilebuf, file->conffile, sizeof(conffilebuf));
501 return false;
502 }

Properties

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