ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/conf_lexer.l
Revision: 1549
Committed: Mon Oct 1 18:11:11 2012 UTC (14 years ago) by michael
Original Path: ircd-hybrid-8/src/conf_lexer.l
File size: 15277 byte(s)
Error occurred while calculating annotation data.
Log Message:
- Removed general::kline_with_reason configuration options. It's now enabled
  by default
- Removed remnants of the broken reject holding code

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 * conf_lexer.l: Scans the ircd configuration file for tokens.
4 *
5 * Copyright (C) 2002 by the past and present ircd coders, and others.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 * USA
21 *
22 * $Id$
23 */
24
25 %option case-insensitive
26 %option noyywrap
27 %option nounput
28 %option never-interactive
29
30 %{
31 #include "stdinc.h"
32 #include "irc_string.h"
33 #include "conf.h"
34 #include "conf_parser.h" /* autogenerated header file */
35 #include "memory.h"
36 #include "hostmask.h"
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))) \
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 int include_stack_ptr = 0;
52 static YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH];
53 static unsigned int lineno_stack[MAX_INCLUDE_DEPTH];
54 static FILE *inc_fbfile_in[MAX_INCLUDE_DEPTH];
55 static char conffile_stack[MAX_INCLUDE_DEPTH][IRCD_BUFSIZE];
56 static void ccomment(void);
57 static void cinclude(void);
58 static int ieof(void);
59
60 static int
61 conf_yy_input(char *lbuf, unsigned int max_size)
62 {
63 return !fgets(lbuf, max_size, conf_parser_ctx.conf_file) ? 0 : strlen(lbuf);
64 }
65
66 static int
67 conf_yy_fatal_error(const char *msg)
68 {
69 return 0;
70 }
71
72 %}
73
74 WS [[:blank:]]*
75 DIGIT [[:digit:]]+
76 COMMENT ("//"|"#").*
77 qstring \"[^\"\n]*[\"\n]
78 include \.include{WS}(\<.*\>|\".*\")
79
80 %%
81 {include} { cinclude(); }
82 "/*" { ccomment(); }
83
84 \n.* { strlcpy(linebuf, yytext+1, sizeof(linebuf)); ++lineno; yyless(1); }
85
86 {WS} ;
87 {COMMENT} ;
88
89 {DIGIT} { yylval.number = atoi(yytext); return NUMBER; }
90
91 {qstring} { if (yytext[yyleng-2] == '\\')
92 {
93 yyless(yyleng-1); /* return last quote */
94 yymore(); /* append next string */
95 }
96 else
97 {
98 yylval.string = yytext+1;
99 if(yylval.string[yyleng-2] != '"')
100 ilog(LOG_TYPE_IRCD, "Unterminated character string");
101 else
102 {
103 int i,j;
104
105 yylval.string[yyleng-2] = '\0'; /* remove close
106 * quote
107 */
108
109 for (j=i=0 ;yylval.string[i] != '\0'; i++,j++)
110 {
111 if (yylval.string[i] != '\\')
112 {
113 yylval.string[j] = yylval.string[i];
114 }
115 else
116 {
117 i++;
118 if (yylval.string[i] == '\0') /* XXX
119 * should not
120 * happen
121 */
122 {
123 ilog(LOG_TYPE_IRCD,
124 "Unterminated character string");
125 break;
126 }
127 yylval.string[j] = yylval.string[i];
128 }
129 }
130 yylval.string[j] = '\0';
131 return QSTRING;
132 }
133 }
134 }
135
136 accept_password { return ACCEPT_PASSWORD; }
137 admin { return ADMIN; }
138 administrator { return ADMIN; }
139 aftype { return AFTYPE; }
140 all { return T_ALL; }
141 auth { return IRCD_AUTH; }
142 autoconn { return AUTOCONN; }
143 can_flood { return CAN_FLOOD; }
144 caller_id_wait { return CALLER_ID_WAIT; }
145 opers_bypass_callerid { return OPERS_BYPASS_CALLERID; }
146 channel { return CHANNEL; }
147 cidr_bitlen_ipv4 { return CIDR_BITLEN_IPV4; }
148 cidr_bitlen_ipv6 { return CIDR_BITLEN_IPV6; }
149 class { return CLASS; }
150 cluster { return T_CLUSTER; }
151 connect { return CONNECT; }
152 connectfreq { return CONNECTFREQ; }
153 default_floodcount { return DEFAULT_FLOODCOUNT; }
154 default_split_server_count { return DEFAULT_SPLIT_SERVER_COUNT; }
155 default_split_user_count { return DEFAULT_SPLIT_USER_COUNT; }
156 deny { return DENY; }
157 description { return DESCRIPTION; }
158 die { return DIE; }
159 disable_auth { return DISABLE_AUTH; }
160 disable_fake_channels { return DISABLE_FAKE_CHANNELS; }
161 disable_remote_commands { return DISABLE_REMOTE_COMMANDS; }
162 dline { return T_DLINE; }
163 dots_in_ident { return DOTS_IN_IDENT; }
164 egdpool_path { return EGDPOOL_PATH; }
165 email { return EMAIL; }
166 encrypted { return ENCRYPTED; }
167 exceed_limit { return EXCEED_LIMIT; }
168 exempt { return EXEMPT; }
169 file { return T_FILE; }
170 flags { return IRCD_FLAGS; }
171 flatten_links { return FLATTEN_LINKS; }
172 gecos { return GECOS; }
173 general { return GENERAL; }
174 gline { return GLINE; }
175 gline_enable { return GLINE_ENABLE; }
176 gline_exempt { return GLINE_EXEMPT; }
177 gline_duration { return GLINE_DURATION; }
178 gline_request_duration { return GLINE_REQUEST_DURATION; }
179 gline_min_cidr { return GLINE_MIN_CIDR; }
180 gline_min_cidr6 { return GLINE_MIN_CIDR6; }
181 globops { return T_GLOBOPS; }
182 global_kill { return GLOBAL_KILL; }
183 have_ident { return NEED_IDENT; }
184 need_ident { return NEED_IDENT; }
185 havent_read_conf { return HAVENT_READ_CONF; }
186 hidden { return HIDDEN; }
187 hidden_name { return HIDDEN_NAME; }
188 hide_server_ips { return HIDE_SERVER_IPS; }
189 hide_servers { return HIDE_SERVERS; }
190 hide_spoof_ips { return HIDE_SPOOF_IPS; }
191 host { return HOST; }
192 hub { return HUB; }
193 hub_mask { return HUB_MASK; }
194 ignore_bogus_ts { return IGNORE_BOGUS_TS; }
195 invisible_on_connect { return INVISIBLE_ON_CONNECT; }
196 ip { return IP; }
197 ipv4 { return T_IPV4; }
198 ipv6 { return T_IPV6; }
199 join_flood_count { return JOIN_FLOOD_COUNT; }
200 join_flood_time { return JOIN_FLOOD_TIME; }
201 kill { return KILL; }
202 kill_chase_time_limit { return KILL_CHASE_TIME_LIMIT; }
203 kline { return KLINE; }
204 kline_exempt { return KLINE_EXEMPT; }
205 leaf_mask { return LEAF_MASK; }
206 listen { return LISTEN; }
207 log { return T_LOG; }
208 masked { return TMASKED; }
209 max_clients { return T_MAX_CLIENTS; }
210 max_ident { return MAX_IDENT; }
211 max_local { return MAX_LOCAL; }
212 max_global { return MAX_GLOBAL; }
213 max_number { return MAX_NUMBER; }
214 max_watch { return MAX_WATCH; }
215 message_locale { return MESSAGE_LOCALE; }
216 min_nonwildcard { return MIN_NONWILDCARD; }
217 min_nonwildcard_simple { return MIN_NONWILDCARD_SIMPLE; }
218 name { return NAME; }
219 need_password { return NEED_PASSWORD; }
220 network_desc { return NETWORK_DESC; }
221 network_name { return NETWORK_NAME; }
222 nick { return NICK; }
223 nick_changes { return NICK_CHANGES; }
224 no { yylval.number = 0; return TBOOL; }
225 no_create_on_split { return NO_CREATE_ON_SPLIT; }
226 no_join_on_split { return NO_JOIN_ON_SPLIT; }
227 no_oper_flood { return NO_OPER_FLOOD; }
228 no_tilde { return NO_TILDE; }
229 number_per_cidr { return NUMBER_PER_CIDR; }
230 number_per_ip { return NUMBER_PER_IP; }
231 oper { return OPERATOR; }
232 oper_pass_resv { return OPER_PASS_RESV; }
233 operator { return OPERATOR; }
234 passwd { return PASSWORD; }
235 password { return PASSWORD; }
236 ping_cookie { return PING_COOKIE; }
237 ping_time { return PING_TIME; }
238 ping_warning { return PING_WARNING; }
239 port { return PORT; }
240 quarantine { return RESV; }
241 quiet_on_ban { return QUIET_ON_BAN; }
242 reason { return REASON; }
243 recvq { return T_RECVQ; }
244 redirport { return REDIRPORT; }
245 redirserv { return REDIRSERV; }
246 regex { return REGEX_T; }
247 rehash { return REHASH; }
248 remote { return REMOTE; }
249 remoteban { return REMOTEBAN; }
250 restart { return T_RESTART; }
251 restrict_channels { return RESTRICT_CHANNELS; }
252 resv { return RESV; }
253 resv_exempt { return RESV_EXEMPT; }
254 rsa_private_key_file { return RSA_PRIVATE_KEY_FILE; }
255 rsa_public_key_file { return RSA_PUBLIC_KEY_FILE; }
256 ssl { return T_SSL; }
257 ssl_certificate_file { return SSL_CERTIFICATE_FILE; }
258 ssl_client_method { return T_SSL_CLIENT_METHOD; }
259 ssl_server_method { return T_SSL_SERVER_METHOD; }
260 ssl_dh_param_file { return SSL_DH_PARAM_FILE; }
261 ssl_cipher_list { return T_SSL_CIPHER_LIST; }
262 sslv3 { return T_SSLV3; }
263 tlsv1 { return T_TLSV1; }
264 send_password { return SEND_PASSWORD; }
265 sendq { return SENDQ; }
266 server { return T_SERVER; }
267 serverhide { return SERVERHIDE; }
268 serverinfo { return SERVERINFO; }
269 service { return T_SERVICE; }
270 services_name { return T_SERVICES_NAME; }
271 set { return T_SET; }
272 shared { return T_SHARED; }
273 short_motd { return SHORT_MOTD; }
274 sid { return IRCD_SID; }
275 size { return T_SIZE; }
276 spoof { return SPOOF; }
277 spoof_notice { return SPOOF_NOTICE; }
278 tkline_expire_notices { return TKLINE_EXPIRE_NOTICES; }
279 type { return TYPE; }
280 true_no_oper_flood { return TRUE_NO_OPER_FLOOD; }
281 umodes { return T_UMODES; }
282 unkline { return UNKLINE; }
283 undline { return T_UNDLINE; }
284 unlimited { return T_UNLIMITED; }
285 use_egd { return USE_EGD; }
286 use_logging { return USE_LOGGING; }
287 throttle_time { return THROTTLE_TIME; }
288 user { return USER; }
289 vhost { return VHOST; }
290 vhost6 { return VHOST6; }
291 xline { return XLINE; }
292 yes { yylval.number = 1; return TBOOL; }
293
294 failed_oper_notice { return FAILED_OPER_NOTICE; }
295 max_accept { return MAX_ACCEPT; }
296 max_nick_changes { return MAX_NICK_CHANGES; }
297 max_chans_per_oper { return MAX_CHANS_PER_OPER; }
298 max_chans_per_user { return MAX_CHANS_PER_USER; }
299 max_nick_time { return MAX_NICK_TIME; }
300 anti_nick_flood { return ANTI_NICK_FLOOD; }
301 anti_spam_exit_message_time { return ANTI_SPAM_EXIT_MESSAGE_TIME; }
302 ts_max_delta { return TS_MAX_DELTA; }
303 ts_warn_delta { return TS_WARN_DELTA; }
304 links_delay { return LINKS_DELAY; }
305 warn_no_nline { return WARN_NO_NLINE; }
306
307 stats_e_disabled { return STATS_E_DISABLED; }
308 stats_o_oper_only { return STATS_O_OPER_ONLY; }
309 stats_k_oper_only { return STATS_K_OPER_ONLY; }
310 stats_i_oper_only { return STATS_I_OPER_ONLY; }
311 stats_P_oper_only { return STATS_P_OPER_ONLY; }
312 pace_wait { return PACE_WAIT; }
313 pace_wait_simple { return PACE_WAIT_SIMPLE; }
314 knock_delay { return KNOCK_DELAY; }
315 knock_delay_channel { return KNOCK_DELAY_CHANNEL; }
316 max_bans { return MAX_BANS; }
317 modules { return MODULES; }
318 module { return MODULE; }
319 path { return PATH; }
320 max_targets { return MAX_TARGETS; }
321
322 unxline { return T_UNXLINE; }
323 unresv { return T_UNRESV; }
324
325 oper_only_umodes { return OPER_ONLY_UMODES; }
326 oper_umodes { return OPER_UMODES; }
327 bots { return T_BOTS; }
328 cconn { return T_CCONN; }
329 cconn_full { return T_CCONN_FULL; }
330 deaf { return T_DEAF; }
331 debug { return T_DEBUG; }
332 full { return T_FULL; }
333 skill { return T_SKILL; }
334 nchange { return T_NCHANGE; }
335 rej { return T_REJ; }
336 unauth { return T_UNAUTH; }
337 spy { return T_SPY; }
338 external { return T_EXTERNAL; }
339 operwall { return T_OPERWALL; }
340 servnotice { return T_SERVNOTICE; }
341 invisible { return T_INVISIBLE; }
342 wallop { return T_WALLOP; }
343 callerid { return T_CALLERID; }
344 softcallerid { return T_SOFTCALLERID; }
345 locops { return T_LOCOPS; }
346
347 weeks { return WEEKS; }
348 week { return WEEKS; }
349 days { return DAYS; }
350 day { return DAYS; }
351 hours { return HOURS; }
352 hour { return HOURS; }
353 minutes { return MINUTES; }
354 minute { return MINUTES; }
355 seconds { return SECONDS; }
356 second { return SECONDS; }
357
358 bytes { return BYTES; }
359 byte { return BYTES; }
360 kilobytes { return KBYTES; }
361 kilobyte { return KBYTES; }
362 kbytes { return KBYTES; }
363 kbyte { return KBYTES; }
364 kb { return KBYTES; }
365 megabytes { return MBYTES; }
366 megabyte { return MBYTES; }
367 mbytes { return MBYTES; }
368 mbyte { return MBYTES; }
369 mb { return MBYTES; }
370 \.\. { return TWODOTS; }
371
372 . { return yytext[0]; }
373 <<EOF>> { if (ieof()) yyterminate(); }
374
375 %%
376
377 /* C-comment ignoring routine -kre*/
378 static void
379 ccomment(void)
380 {
381 int c = 0;
382
383 /* log(L_NOTICE, "got comment"); */
384 while (1)
385 {
386 while ((c = input()) != '*' && c != EOF)
387 if (c == '\n')
388 ++lineno;
389
390 if (c == '*')
391 {
392 while ((c = input()) == '*')
393 /* Nothing */ ;
394 if (c == '/')
395 break;
396 else if (c == '\n')
397 ++lineno;
398 }
399
400 if (c == EOF)
401 {
402 YY_FATAL_ERROR("EOF in comment");
403 /* XXX hack alert this disables
404 * the stupid unused function warning
405 * gcc generates
406 */
407 if (1 == 0)
408 yy_fatal_error("EOF in comment");
409 break;
410 }
411 }
412 }
413
414 /* C-style .includes. This function will properly swap input conf buffers,
415 * and lineno -kre */
416 static void
417 cinclude(void)
418 {
419 char *p = NULL;
420
421 if ((p = strchr(yytext, '<')) == NULL)
422 *strchr(p = strchr(yytext, '"') + 1, '"') = '\0';
423 else
424 *strchr(++p, '>') = '\0';
425
426 /* log(L_NOTICE, "got include %s!", c); */
427
428 /* do stacking and co. */
429 if (include_stack_ptr >= MAX_INCLUDE_DEPTH)
430 ilog(LOG_TYPE_IRCD, "Includes nested too deep in %s", p);
431 else
432 {
433 FILE *tmp_fbfile_in = NULL;
434 char filenamebuf[IRCD_BUFSIZE];
435
436 if (*p == '/') /* if it is an absolute path */
437 snprintf(filenamebuf, sizeof(filenamebuf), "%s", p);
438 else
439 snprintf(filenamebuf, sizeof(filenamebuf), "%s/%s", ETCPATH, p);
440
441 tmp_fbfile_in = fopen(filenamebuf, "r");
442
443 if (tmp_fbfile_in == NULL)
444 {
445 ilog(LOG_TYPE_IRCD, "Unable to read configuration file '%s': %s",
446 filenamebuf, strerror(errno));
447 return;
448 }
449
450 lineno_stack[include_stack_ptr] = lineno;
451 lineno = 1;
452 inc_fbfile_in[include_stack_ptr] = conf_parser_ctx.conf_file;
453 strlcpy(conffile_stack[include_stack_ptr], conffilebuf, IRCD_BUFSIZE);
454 include_stack[include_stack_ptr++] = YY_CURRENT_BUFFER;
455 conf_parser_ctx.conf_file = tmp_fbfile_in;
456 snprintf(conffilebuf, sizeof(conffilebuf), "%s", filenamebuf);
457 yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
458 }
459 }
460
461 /* This is function that will be called on EOF in conf file. It will
462 * apropriately close conf if it not main conf and swap input buffers -kre
463 * */
464 static int
465 ieof(void)
466 {
467 /* log(L_NOTICE, "return from include stack!"); */
468 if (include_stack_ptr)
469 fclose(conf_parser_ctx.conf_file);
470 if (--include_stack_ptr < 0)
471 {
472 /* log(L_NOTICE, "terminating lexer"); */
473 /* We will now exit the lexer - restore init values if we get /rehash
474 * later and reenter lexer -kre */
475 include_stack_ptr = 0;
476 lineno = 1;
477 return 1;
478 }
479
480 /* switch buffer */
481 /* log(L_NOTICE, "deleting include_stack_ptr=%d", include_stack_ptr); */
482 yy_delete_buffer(YY_CURRENT_BUFFER);
483 lineno = lineno_stack[include_stack_ptr];
484 conf_parser_ctx.conf_file = inc_fbfile_in[include_stack_ptr];
485 strlcpy(conffilebuf, conffile_stack[include_stack_ptr], sizeof(conffilebuf));
486 yy_switch_to_buffer(include_stack[include_stack_ptr]);
487
488 return 0;
489 }

Properties

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