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