ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/conf_lexer.l
Revision: 1301
Committed: Sat Mar 10 21:47:17 2012 UTC (14 years, 4 months ago) by michael
Original Path: ircd-hybrid-8/src/ircd_lexer.l
File size: 16134 byte(s)
Log Message:
- add 'dline' and 'undline' operator flags
- implement remote dlines mainly for services purposes, but can be used
  by operators as well
- update example configuration files; remove invalid shared::flags entries

File Contents

# User Rev Content
1 adx 30 /*
2     * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3     * ircd_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 knight 31 * $Id$
23 adx 30 */
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 "s_conf.h"
34     #include "memory.h"
35     #include "hostmask.h"
36     #include "s_log.h"
37    
38 stu 908 #include "ircd_parser.h"
39 adx 30
40     #undef YY_INPUT
41     #define YY_FATAL_ERROR(msg) conf_yy_fatal_error(msg)
42     #define YY_INPUT(buf,result,max_size) \
43 michael 967 if (!(result = conf_fbgets(buf, max_size, conf_parser_ctx.conf_file))) \
44 adx 30 YY_FATAL_ERROR("input in flex scanner failed");
45     #define MAX_INCLUDE_DEPTH 10
46    
47    
48     unsigned int lineno = 1;
49     char linebuf[IRCD_BUFSIZE];
50     char conffilebuf[IRCD_BUFSIZE];
51    
52     static int include_stack_ptr = 0;
53     static YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH];
54     static unsigned int lineno_stack[MAX_INCLUDE_DEPTH];
55     static FBFILE *inc_fbfile_in[MAX_INCLUDE_DEPTH];
56     static char conffile_stack[MAX_INCLUDE_DEPTH][IRCD_BUFSIZE];
57     static void ccomment(void);
58     static void cinclude(void);
59     static int ieof(void);
60     %}
61    
62     WS [[:blank:]]*
63     DIGIT [[:digit:]]+
64     COMMENT ("//"|"#").*
65     qstring \"[^\"\n]*[\"\n]
66     include \.include{WS}(\<.*\>|\".*\")
67    
68     %%
69     {include} { cinclude(); }
70     "/*" { ccomment(); }
71    
72     \n.* { strcpy(linebuf, yytext+1); ++lineno; yyless(1); }
73    
74     {WS} ;
75     {COMMENT} ;
76    
77     {DIGIT} { yylval.number = atoi(yytext); return NUMBER; }
78    
79     {qstring} { if (yytext[yyleng-2] == '\\')
80     {
81     yyless(yyleng-1); /* return last quote */
82     yymore(); /* append next string */
83     }
84     else
85     {
86     yylval.string = yytext+1;
87     if(yylval.string[yyleng-2] != '"')
88 michael 1247 ilog(LOG_TYPE_IRCD, "Unterminated character string");
89 adx 30 else
90     {
91     int i,j;
92    
93     yylval.string[yyleng-2] = '\0'; /* remove close
94     * quote
95     */
96    
97     for (j=i=0 ;yylval.string[i] != '\0'; i++,j++)
98     {
99     if (yylval.string[i] != '\\')
100     {
101     yylval.string[j] = yylval.string[i];
102     }
103     else
104     {
105     i++;
106     if (yylval.string[i] == '\0') /* XXX
107     * should not
108     * happen
109     */
110     {
111 michael 1247 ilog(LOG_TYPE_IRCD,
112 adx 30 "Unterminated character string");
113     break;
114     }
115     yylval.string[j] = yylval.string[i];
116     }
117     }
118     yylval.string[j] = '\0';
119     return QSTRING;
120     }
121     }
122     }
123    
124     accept_password { return ACCEPT_PASSWORD; }
125     action { return ACTION; }
126     admin { return ADMIN; }
127     administrator { return ADMIN; }
128     aftype { return AFTYPE; }
129     all { return T_ALL; }
130     allow { return T_ALLOW; }
131     auth { return IRCD_AUTH; }
132     autoconn { return AUTOCONN; }
133     block { return T_BLOCK; }
134     burst_away { return BURST_AWAY; }
135     burst_topicwho { return BURST_TOPICWHO; }
136     can_flood { return CAN_FLOOD; }
137     caller_id_wait { return CALLER_ID_WAIT; }
138     opers_bypass_callerid { return OPERS_BYPASS_CALLERID; }
139     channel { return CHANNEL; }
140     cidr_bitlen_ipv4 { return CIDR_BITLEN_IPV4; }
141     cidr_bitlen_ipv6 { return CIDR_BITLEN_IPV6; }
142     cipher_preference { return CIPHER_PREFERENCE; }
143     class { return CLASS; }
144     client_flood { return T_CLIENT_FLOOD; }
145     cluster { return T_CLUSTER; }
146     compressed { return COMPRESSED; }
147     compression_level { return COMPRESSION_LEVEL; }
148     connect { return CONNECT; }
149     connectfreq { return CONNECTFREQ; }
150     cryptlink { return CRYPTLINK; }
151     default_cipher_preference { return DEFAULT_CIPHER_PREFERENCE; }
152     default_floodcount { return DEFAULT_FLOODCOUNT; }
153     default_split_server_count { return DEFAULT_SPLIT_SERVER_COUNT; }
154     default_split_user_count { return DEFAULT_SPLIT_USER_COUNT; }
155     deny { return DENY; }
156     description { return DESCRIPTION; }
157     die { return DIE; }
158     disable_auth { return DISABLE_AUTH; }
159 michael 632 disable_fake_channels { return DISABLE_FAKE_CHANNELS; }
160 adx 30 disable_hidden { return DISABLE_HIDDEN; }
161     disable_local_channels { return DISABLE_LOCAL_CHANNELS; }
162     disable_remote_commands { return DISABLE_REMOTE_COMMANDS; }
163 michael 1250 dline { return T_DLINE; }
164 adx 30 dots_in_ident { return DOTS_IN_IDENT; }
165     duration { return DURATION; }
166     egdpool_path { return EGDPOOL_PATH; }
167     email { return EMAIL; }
168     enable { return ENABLE; }
169     encrypted { return ENCRYPTED; }
170     exceed_limit { return EXCEED_LIMIT; }
171     exempt { return EXEMPT; }
172 michael 1247 file { return T_FILE; }
173 adx 30 flags { return IRCD_FLAGS; }
174     flatten_links { return FLATTEN_LINKS; }
175     gecos { return GECOS; }
176     general { return GENERAL; }
177     gline { return GLINE; }
178     glines { return GLINES; }
179     gline_exempt { return GLINE_EXEMPT; }
180     gline_min_cidr { return GLINE_MIN_CIDR; }
181     gline_min_cidr6 { return GLINE_MIN_CIDR6; }
182 michael 1216 globops { return T_GLOBOPS; }
183 adx 30 global_kill { return GLOBAL_KILL; }
184     have_ident { return NEED_IDENT; }
185     need_ident { return NEED_IDENT; }
186     havent_read_conf { return HAVENT_READ_CONF; }
187     hidden { return HIDDEN; }
188     hidden_name { return HIDDEN_NAME; }
189     hide_server_ips { return HIDE_SERVER_IPS; }
190     hide_servers { return HIDE_SERVERS; }
191     hide_spoof_ips { return HIDE_SPOOF_IPS; }
192     host { return HOST; }
193     hub { return HUB; }
194     hub_mask { return HUB_MASK; }
195     ignore_bogus_ts { return IGNORE_BOGUS_TS; }
196     invisible_on_connect { return INVISIBLE_ON_CONNECT; }
197     ip { return IP; }
198     ipv4 { return T_IPV4; }
199     ipv6 { return T_IPV6; }
200     join_flood_count { return JOIN_FLOOD_COUNT; }
201     join_flood_time { return JOIN_FLOOD_TIME; }
202     kill { return KILL; }
203     kill_chase_time_limit { return KILL_CHASE_TIME_LIMIT; }
204     kline { return KLINE; }
205     kline_exempt { return KLINE_EXEMPT; }
206     leaf_mask { return LEAF_MASK; }
207     listen { return LISTEN; }
208 michael 1247 log { return T_LOG; }
209 adx 30 masked { return TMASKED; }
210     max_clients { return T_MAX_CLIENTS; }
211     max_ident { return MAX_IDENT; }
212     max_local { return MAX_LOCAL; }
213     max_global { return MAX_GLOBAL; }
214     max_number { return MAX_NUMBER; }
215 michael 876 max_watch { return MAX_WATCH; }
216 adx 30 message_locale { return MESSAGE_LOCALE; }
217     min_nonwildcard { return MIN_NONWILDCARD; }
218     min_nonwildcard_simple { return MIN_NONWILDCARD_SIMPLE; }
219     name { return NAME; }
220     need_password { return NEED_PASSWORD; }
221     network_desc { return NETWORK_DESC; }
222     network_name { return NETWORK_NAME; }
223     nick { return NICK; }
224     nick_changes { return NICK_CHANGES; }
225 michael 1243 no { yylval.number = 0; return TBOOL; }
226 adx 30 no_create_on_split { return NO_CREATE_ON_SPLIT; }
227     no_join_on_split { return NO_JOIN_ON_SPLIT; }
228     no_oper_flood { return NO_OPER_FLOOD; }
229     no_tilde { return NO_TILDE; }
230     number_per_cidr { return NUMBER_PER_CIDR; }
231     number_per_ip { return NUMBER_PER_IP; }
232     oper { return OPERATOR; }
233     oper_pass_resv { return OPER_PASS_RESV; }
234     operator { return OPERATOR; }
235     passwd { return PASSWORD; }
236     password { return PASSWORD; }
237     ping_cookie { return PING_COOKIE; }
238     ping_time { return PING_TIME; }
239     ping_warning { return PING_WARNING; }
240     port { return PORT; }
241     quarantine { return RESV; }
242     quiet_on_ban { return QUIET_ON_BAN; }
243     reason { return REASON; }
244     redirport { return REDIRPORT; }
245     redirserv { return REDIRSERV; }
246     regex { return REGEX_T; }
247     rehash { return REHASH; }
248     reject { return T_REJECT; }
249     reject_hold_time { return TREJECT_HOLD_TIME; }
250     remote { return REMOTE; }
251     remoteban { return REMOTEBAN; }
252 michael 1228 restart { return T_RESTART; }
253 adx 30 restrict_channels { return RESTRICT_CHANNELS; }
254     resv { return RESV; }
255     resv_exempt { return RESV_EXEMPT; }
256     rsa_private_key_file { return RSA_PRIVATE_KEY_FILE; }
257     rsa_public_key_file { return RSA_PUBLIC_KEY_FILE; }
258     ssl { return T_SSL; }
259     ssl_certificate_file { return SSL_CERTIFICATE_FILE; }
260 michael 967 ssl_server_protocol { return T_SSL_CONNECTION_METHOD; }
261     sslv3 { return T_SSLV3; }
262     tlsv1 { return T_TLSV1; }
263 adx 30 send_password { return SEND_PASSWORD; }
264     sendq { return SENDQ; }
265 michael 900 server { return T_SERVER; }
266 adx 30 serverhide { return SERVERHIDE; }
267     serverinfo { return SERVERINFO; }
268 michael 1175 service { return T_SERVICE; }
269 michael 1176 services_name { return T_SERVICES_NAME; }
270 adx 30 servlink_path { return SERVLINK_PATH; }
271     shared { return T_SHARED; }
272     short_motd { return SHORT_MOTD; }
273     sid { return IRCD_SID; }
274     silent { return SILENT; }
275 michael 1247 size { return T_SIZE; }
276 adx 30 spoof { return SPOOF; }
277     spoof_notice { return SPOOF_NOTICE; }
278 michael 1247 timestamp { return T_TIMESTAMP; }
279 adx 30 tkline_expire_notices { return TKLINE_EXPIRE_NOTICES; }
280     type { return TYPE; }
281     true_no_oper_flood { return TRUE_NO_OPER_FLOOD; }
282 michael 56 umodes { return T_UMODES; }
283 adx 30 unkline { return UNKLINE; }
284 michael 1301 undline { return T_UNDLINE; }
285 michael 1250 unlimited { return T_UNLIMITED; }
286 adx 30 use_egd { return USE_EGD; }
287     use_except { return USE_EXCEPT; }
288     use_invex { return USE_INVEX; }
289     use_knock { return USE_KNOCK; }
290     use_logging { return USE_LOGGING; }
291     use_whois_actually { return USE_WHOIS_ACTUALLY; }
292     throttle_time { return THROTTLE_TIME; }
293     user { return USER; }
294     tkline { return TKLINE; }
295     txline { return TXLINE; }
296     tresv { return TRESV; }
297     vhost { return VHOST; }
298     vhost6 { return VHOST6; }
299     warn { return WARN; }
300     xline { return XLINE; }
301 michael 1243 yes { yylval.number = 1; return TBOOL; }
302 adx 30
303     failed_oper_notice { return FAILED_OPER_NOTICE; }
304     max_accept { return MAX_ACCEPT; }
305     max_nick_changes { return MAX_NICK_CHANGES; }
306     max_chans_per_user { return MAX_CHANS_PER_USER; }
307     max_nick_time { return MAX_NICK_TIME; }
308     anti_nick_flood { return ANTI_NICK_FLOOD; }
309     anti_spam_exit_message_time { return ANTI_SPAM_EXIT_MESSAGE_TIME; }
310     ts_max_delta { return TS_MAX_DELTA; }
311     ts_warn_delta { return TS_WARN_DELTA; }
312     links_delay { return LINKS_DELAY; }
313     kline_reason { return KLINE_REASON; }
314     kline_with_reason { return KLINE_WITH_REASON; }
315     warn_no_nline { return WARN_NO_NLINE; }
316    
317 michael 584 stats_e_disabled { return STATS_E_DISABLED; }
318 adx 30 stats_o_oper_only { return STATS_O_OPER_ONLY; }
319     stats_k_oper_only { return STATS_K_OPER_ONLY; }
320     stats_i_oper_only { return STATS_I_OPER_ONLY; }
321     stats_P_oper_only { return STATS_P_OPER_ONLY; }
322     pace_wait { return PACE_WAIT; }
323     pace_wait_simple { return PACE_WAIT_SIMPLE; }
324     knock_delay { return KNOCK_DELAY; }
325     knock_delay_channel { return KNOCK_DELAY_CHANNEL; }
326     max_bans { return MAX_BANS; }
327     modules { return MODULES; }
328     module { return MODULE; }
329     path { return PATH; }
330     max_targets { return MAX_TARGETS; }
331    
332     unxline { return T_UNXLINE; }
333     unresv { return T_UNRESV; }
334    
335     oper_only_umodes { return OPER_ONLY_UMODES; }
336     oper_umodes { return OPER_UMODES; }
337     bots { return T_BOTS; }
338     cconn { return T_CCONN; }
339 db 849 cconn_full { return T_CCONN_FULL; }
340 adx 30 deaf { return T_DEAF; }
341     debug { return T_DEBUG; }
342     full { return T_FULL; }
343     skill { return T_SKILL; }
344     nchange { return T_NCHANGE; }
345     rej { return T_REJ; }
346     unauth { return T_UNAUTH; }
347     spy { return T_SPY; }
348     external { return T_EXTERNAL; }
349     operwall { return T_OPERWALL; }
350     servnotice { return T_SERVNOTICE; }
351     invisible { return T_INVISIBLE; }
352     wallop { return T_WALLOP; }
353     callerid { return T_CALLERID; }
354     softcallerid { return T_SOFTCALLERID; }
355     drone { return T_DRONE; }
356     locops { return T_LOCOPS; }
357     topicburst { return TOPICBURST; }
358    
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     gigabytes { return GBYTES; }
383     gigabyte { return GBYTES; }
384     gbytes { return GBYTES; }
385     gbyte { return GBYTES; }
386     gb { return GBYTES; }
387     terabytes { return TBYTES; }
388     terabyte { return TBYTES; }
389     tbytes { return TBYTES; }
390     tbyte { return TBYTES; }
391     tb { return TBYTES; }
392     \.\. { return TWODOTS; }
393    
394     . { return yytext[0]; }
395     <<EOF>> { if (ieof()) yyterminate(); }
396    
397     %%
398    
399     /* C-comment ignoring routine -kre*/
400     static void
401     ccomment(void)
402     {
403     int c = 0;
404    
405     /* log(L_NOTICE, "got comment"); */
406     while (1)
407     {
408     while ((c = input()) != '*' && c != EOF)
409     if (c == '\n')
410     ++lineno;
411    
412     if (c == '*')
413     {
414     while ((c = input()) == '*')
415     /* Nothing */ ;
416     if (c == '/')
417     break;
418     else if (c == '\n')
419     ++lineno;
420     }
421    
422     if (c == EOF)
423     {
424     YY_FATAL_ERROR("EOF in comment");
425     /* XXX hack alert this disables
426     * the stupid unused function warning
427     * gcc generates
428     */
429     if (1 == 0)
430     yy_fatal_error("EOF in comment");
431     break;
432     }
433     }
434     }
435    
436     /* C-style .includes. This function will properly swap input conf buffers,
437     * and lineno -kre */
438     static void
439     cinclude(void)
440     {
441     char *p = NULL;
442    
443     if ((p = strchr(yytext, '<')) == NULL)
444     *strchr(p = strchr(yytext, '"') + 1, '"') = '\0';
445     else
446     *strchr(++p, '>') = '\0';
447    
448     /* log(L_NOTICE, "got include %s!", c); */
449    
450     /* do stacking and co. */
451     if (include_stack_ptr >= MAX_INCLUDE_DEPTH)
452 michael 1247 ilog(LOG_TYPE_IRCD, "Includes nested too deep in %s", p);
453 adx 30 else
454     {
455     FBFILE *tmp_fbfile_in = NULL;
456     char filenamebuf[IRCD_BUFSIZE];
457    
458     if (*p == '/') /* if it is an absolute path */
459     snprintf(filenamebuf, sizeof(filenamebuf), "%s", p);
460     else
461     snprintf(filenamebuf, sizeof(filenamebuf), "%s/%s", ETCPATH, p);
462    
463     tmp_fbfile_in = fbopen(filenamebuf, "r");
464    
465     if (tmp_fbfile_in == NULL)
466     {
467 michael 1247 ilog(LOG_TYPE_IRCD, "Unable to read configuration file '%s': %s",
468 adx 30 filenamebuf, strerror(errno));
469     return;
470     }
471    
472     lineno_stack[include_stack_ptr] = lineno;
473     lineno = 1;
474 michael 967 inc_fbfile_in[include_stack_ptr] = conf_parser_ctx.conf_file;
475 adx 30 strlcpy(conffile_stack[include_stack_ptr], conffilebuf, IRCD_BUFSIZE);
476     include_stack[include_stack_ptr++] = YY_CURRENT_BUFFER;
477 michael 967 conf_parser_ctx.conf_file = tmp_fbfile_in;
478 michael 711 snprintf(conffilebuf, sizeof(conffilebuf), "%s", filenamebuf);
479 adx 30 yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
480     }
481     }
482    
483     /* This is function that will be called on EOF in conf file. It will
484     * apropriately close conf if it not main conf and swap input buffers -kre
485     * */
486     static int
487     ieof(void)
488     {
489     /* log(L_NOTICE, "return from include stack!"); */
490     if (include_stack_ptr)
491 michael 967 fbclose(conf_parser_ctx.conf_file);
492 adx 30 if (--include_stack_ptr < 0)
493     {
494     /* log(L_NOTICE, "terminating lexer"); */
495     /* We will now exit the lexer - restore init values if we get /rehash
496     * later and reenter lexer -kre */
497     include_stack_ptr = 0;
498     lineno = 1;
499     return 1;
500     }
501    
502     /* switch buffer */
503     /* log(L_NOTICE, "deleting include_stack_ptr=%d", include_stack_ptr); */
504     yy_delete_buffer(YY_CURRENT_BUFFER);
505     lineno = lineno_stack[include_stack_ptr];
506 michael 967 conf_parser_ctx.conf_file = inc_fbfile_in[include_stack_ptr];
507 adx 30 strlcpy(conffilebuf, conffile_stack[include_stack_ptr], sizeof(conffilebuf));
508     yy_switch_to_buffer(include_stack[include_stack_ptr]);
509    
510     return 0;
511     }

Properties

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