ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid-8/src/ircd_lexer.l
Revision: 1228
Committed: Mon Sep 19 09:38:38 2011 UTC (15 years ago) by michael
File size: 16795 byte(s)
Log Message:
- add 'restart'/'module' operator flags which allows better fine tuning
  whether or not an operator may have access to RESTART/MOD* commands
- ircd_parser.y: (oper{}): ensure yy_aconf->port is set to zero, before
  setting any privilege bits. Fixes odd behaviour with multiple 'flags'
  entries.
  Also removed ability to negate operator flags with a tilde '~'. Pretty
  useless since all operator privilege flags are set to zero by default.

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

Properties

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