]> Pileus Git - ~andy/fetchmail/blob - rcfile_l.l
Remove static string buffers, use xstrndup().
[~andy/fetchmail] / rcfile_l.l
1 %{
2
3 /*
4  * rcfile_l.l -- lexer for the run control file, to be used with GNU flex.
5  *
6  * For license terms, see the file COPYING in this directory.
7  */
8 #include <string.h>
9
10 #include "config.h"
11 #include "fetchmail.h"
12 #include "xmalloc.h"
13 #include "rcfile_y.h"
14
15 int prc_lineno = 1;
16
17 #ifdef LEXDEBUG
18 #define SETSTATE(n)     do {BEGIN(n); if (yydebug) fprintf(stderr, "Entering lexer state %d\n", n);} while (0)
19 #else
20 #define SETSTATE(n)     BEGIN(n)
21 #endif /* LEXDEBUG */
22
23 #define YY_NO_INPUT
24
25 %}
26
27 %option nounput noyywrap
28 %option warn nodefault
29 %option 8bit batch
30
31 %s NAME AUTH
32
33 %%
34
35 \"[^\"]*\"      |
36 \'[^\']*\'      {
37                         char *in = xstrndup(yytext+1, yyleng-2);
38                         escapes(in, in);
39                         yylval.sval = in;
40                         SETSTATE(0);
41                         return STRING;
42                 }
43
44 "*"             { BEGIN(0); return WILDCARD; }
45
46 <NAME>[^=;:, \t\r\n]+   {
47                         char *in = xstrdup(yytext);
48                         escapes(in, in);
49                         yylval.sval = in;
50                         SETSTATE(0);
51                         return STRING;
52                 }
53
54 set             { return SET; }
55 logfile         { return LOGFILE; }
56 idfile          { return IDFILE; }
57 pidfile         { return PIDFILE; }
58 daemon          { return DAEMON; }
59 syslog          { return SYSLOG; }
60 invisible       { return INVISIBLE; }
61 showdots        { return SHOWDOTS; }
62 postmaster      { return POSTMASTER; }
63 bouncemail      { return BOUNCEMAIL; }
64 spambounce      { return SPAMBOUNCE; }
65 softbounce      { return SOFTBOUNCE; }
66 warnings        { return WARNINGS; }
67 tracepolls      { return TRACEPOLLS; }
68
69 defaults        { return DEFAULTS; }
70 server          { return POLL; }
71 poll            { return POLL; }
72 skip            { return SKIP; }
73 via             { return VIA; }
74 aka             { return AKA; }
75 local(domains)? { return LOCALDOMAINS; }
76 proto(col)?     { return PROTOCOL; }
77 service         { return SERVICE; }
78 port            { return PORT; }
79 interval        { return INTERVAL; }
80 preauth(enticate)?      { SETSTATE(AUTH); return AUTHENTICATE; }
81 auth(enticate)? { SETSTATE(AUTH); return AUTHENTICATE; }
82 any             { SETSTATE(0); yylval.proto = A_ANY; return AUTHTYPE;}
83 gssapi          { SETSTATE(0); yylval.proto = A_GSSAPI; return AUTHTYPE;}
84 kerberos(_v)?4  { SETSTATE(0); yylval.proto = A_KERBEROS_V4; return AUTHTYPE;}
85 kerberos(_v)?5  { SETSTATE(0); yylval.proto = A_KERBEROS_V5; return AUTHTYPE;}
86 kerberos        { SETSTATE(0); yylval.proto = A_KERBEROS_V4; return AUTHTYPE;}
87 ssh             { SETSTATE(0); yylval.proto = A_SSH; return AUTHTYPE;}
88 external        { SETSTATE(0); yylval.proto = A_EXTERNAL; return AUTHTYPE;}
89 (otp|opie)      { SETSTATE(0); yylval.proto = A_OTP; return AUTHTYPE;}
90 cram(-md5)?     { SETSTATE(0); yylval.proto = A_CRAM_MD5; return AUTHTYPE;}
91 msn             { SETSTATE(0); yylval.proto = A_MSN; return AUTHTYPE;}
92 ntlm            { SETSTATE(0); yylval.proto = A_NTLM; return AUTHTYPE;}
93 <AUTH>password  { SETSTATE(0); yylval.proto = A_PASSWORD; return AUTHTYPE;}
94 timeout         { return TIMEOUT;}
95 envelope        { return ENVELOPE; }
96 qvirtual        { return QVIRTUAL; }
97 principal       { return PRINCIPAL; }
98 esmtpname       { return ESMTPNAME; }
99 esmtppassword   { return ESMTPPASSWORD; }
100 bad-header      { return BADHEADER; }
101 accept          { return ACCEPT; }
102 reject          { return REJECT_; }
103
104 user(name)?     {SETSTATE(NAME); return USERNAME; }
105 <INITIAL,NAME>pass(word)?       {SETSTATE(NAME); return PASSWORD; }
106 folder(s)?      { return FOLDER; }
107 smtp(host)?     { return SMTPHOST; }
108 fetchdomains    { return FETCHDOMAINS; }
109 smtpaddress     { return SMTPADDRESS; }
110 smtpname        { return SMTPNAME; }
111 antispam        { return SPAMRESPONSE; }
112 mda             { return MDA; }
113 bsmtp           { return BSMTP; }
114 lmtp            { return LMTP; }
115 pre(connect)?   { return PRECONNECT; }
116 post(connect)?  { return POSTCONNECT; }
117 interface       { return INTERFACE; }
118 monitor         { return MONITOR; }
119 plugin          { return PLUGIN; }
120 plugout         { return PLUGOUT; }
121 batchlimit      { return BATCHLIMIT; }
122 fetchlimit      { return FETCHLIMIT; }
123 fetchsizelimit  { return FETCHSIZELIMIT; }
124 fastuidl        { return FASTUIDL; }
125 expunge         { return EXPUNGE; }
126 properties      { return PROPERTIES; }
127
128 is              { SETSTATE(NAME); return IS; }
129 here            { return HERE; }
130 there           { return THERE; }
131 to              { SETSTATE(NAME); return TO; }
132 =               { SETSTATE(NAME); return MAP; }
133
134 nobouncemail    |
135 nouidl          |
136 nocheckalias    |
137 nodns           |
138 noenvelope      |
139 nokeep          |
140 noflush         |
141 nolimitflush    |
142 nofetchall      |
143 norewrite       |
144 noforcecr       |
145 nostripcr       |
146 nopass8(bits)?  |
147 nodropstatus    |
148 nodropdelivered |
149 nomimedec(ode)? |
150 nospambounce    |
151 noidle          {
152                    yyless(2);
153                    return NO;
154                 }
155
156 no              {return NO;}
157
158 keep            { return KEEP; }
159 flush           { return FLUSH; }
160 limitflush      { return LIMITFLUSH; }
161 fetchall        { return FETCHALL; }
162 rewrite         { return REWRITE; }
163 forcecr         { return FORCECR; }
164 stripcr         { return STRIPCR; }
165 pass8(bits)?    { return PASS8BITS; }
166 dropstatus      { return DROPSTATUS; }
167 dropdelivered   { return DROPDELIVERED; }
168 mimedec(ode)?   { return MIMEDECODE; }
169 idle            { return IDLE; }
170 dns             { return DNS; }
171 uidl            { return UIDL; }
172 ssl             { return SSL; }
173 sslkey          { return SSLKEY; }
174 sslcert         { return SSLCERT; }
175 sslproto        { return SSLPROTO; }
176 sslcertck       { return SSLCERTCK; }
177 sslcertpath     { return SSLCERTPATH; }
178 sslcommonname   { return SSLCOMMONNAME; }
179 sslfingerprint  { return SSLFINGERPRINT; }
180 checkalias      { return CHECKALIAS; }
181
182 limit           { return LIMIT; }
183
184 with            {/* EMPTY */}
185 and             {/* EMPTY */}
186 has             {/* EMPTY */}
187 wants           {/* EMPTY */}
188 options         {/* EMPTY */}
189 [;:,]           {/* EMPTY */}
190
191 (auto)|(AUTO)   { yylval.proto = P_AUTO;  return PROTO; }
192 (pop2)|(POP2)   { yylval.proto = P_POP2;  return PROTO; }
193 (sdps)|(SDPS)   { return SDPS; }
194 (pop3)|(POP3)   { yylval.proto = P_POP3;  return PROTO; }
195 (imap)|(IMAP)   { yylval.proto = P_IMAP;  return PROTO; }
196 (apop)|(APOP)   { yylval.proto = P_APOP;  return PROTO; }
197 (rpop)|(RPOP)   { yylval.proto = P_RPOP;  return PROTO; }
198 (etrn)|(ETRN)   { yylval.proto = P_ETRN;  return PROTO; }
199 (odmr)|(ODMR)   { yylval.proto = P_ODMR;  return PROTO; }
200 (kpop)|(KPOP)   { return KPOP; }
201
202 (#.*)?\\?\n     { prc_lineno++; }   /* newline is ignored */
203
204 -?[0-9]+        { yylval.number = atoi(yytext); return NUMBER; }
205
206 [^=;:, \t\r\n]+ {
207                         char *in = xstrdup(yytext);
208                         escapes(in, in);
209                         yylval.sval = in;
210                         return STRING;
211                 }
212
213 [ \t\r]+        ;       /* whitespace */
214
215 %%
216
217 /** process standard C-style escape sequences in a string,
218  * this can never lengthen the output, so cp and tp may overlap as long
219  * as cp >= tp. */
220 void escapes(const char *cp /** source string with escapes */,
221              char       *tp /** target buffer for digested string */)
222 {
223     while (*cp)
224     {
225         int     cval = 0;
226
227         /* we MUST check for NUL explicitly, as strchr(string, 0) will
228          * always succeed! */
229         if (*cp == '\\' && cp[1] && strchr("0123456789xX", cp[1]))
230         {
231             const char *dp;
232             const char *hex = "00112233445566778899aAbBcCdDeEfF";
233             int dcount = 0;
234
235             if (*++cp == 'x' || *cp == 'X')
236                 for (++cp; *cp && (dp = strchr(hex, *cp)) && (dcount++ < 2); cp++)
237                     cval = (cval * 16) + (dp - hex) / 2;
238             else if (*cp == '0')
239                 while (*cp && strchr("01234567",*cp) != (char*)NULL && (dcount++ < 3))
240                     cval = (cval * 8) + (*cp++ - '0');
241             else
242                 while (*cp && (strchr("0123456789",*cp)!=(char*)NULL)&&(dcount++ < 3))
243                     cval = (cval * 10) + (*cp++ - '0');
244         }
245         else if (*cp == '\\')           /* C-style character escapes */
246         {
247             switch (*++cp)
248             {
249             case '\n': cp++; continue;  /* backslash before LF to join lines */
250             case '\0': goto done;          /* ignore backslash at file end */
251             case '\\': cval = '\\'; break;
252             case 'n': cval = '\n'; break;
253             case 't': cval = '\t'; break;
254             case 'b': cval = '\b'; break;
255             case 'r': cval = '\r'; break;
256             default: cval = *cp;
257             }
258             cp++;
259         }
260         else
261             cval = *cp++;
262         *tp++ = cval;
263     }
264 done:
265     *tp = '\0';
266 }