]> Pileus Git - ~andy/fetchmail/blobdiff - rcfile_l.l
Note Earl's regression fix for SSL_CTX_clear_options() on older OpenSSL.
[~andy/fetchmail] / rcfile_l.l
index 25e4308b40ef61ad97800e7e6ddc0ed900069b2f..c7e49fea6999c97e6a17982940f19a8255838937 100644 (file)
@@ -1,7 +1,7 @@
 %{
 
 /*
- * rcfile_l.l -- lexer for the run control file
+ * rcfile_l.l -- lexer for the run control file, to be used with GNU flex.
  *
  * For license terms, see the file COPYING in this directory.
  */
@@ -9,6 +9,7 @@
 
 #include "config.h"
 #include "fetchmail.h"
+#include "xmalloc.h"
 #include "rcfile_y.h"
 
 int prc_lineno = 1;
@@ -18,57 +19,40 @@ int prc_lineno = 1;
 #else
 #define SETSTATE(n)    BEGIN(n)
 #endif /* LEXDEBUG */
+
+#define YY_NO_INPUT
+
 %}
 
-/* this doesn't work with Linux lex, see the INSTALL file */
-%o 7000
-%a 4000
-%p 3000
-%option nounput
+%option nounput noyywrap
+%option warn nodefault
+%option 8bit batch
 
 %s NAME AUTH
 
 %%
 
-\"[^\"]*\"     {
-                       yytext[yyleng-1] = '\0';
-                       escapes(yytext+1, yytext);
-                       yyleng = strlen(yytext);
-                       yylval.sval = yytext;
-                        SETSTATE(0);
-                       return STRING;
-               }
+\"[^\"]*\"     |
 \'[^\']*\'     {
-                       yytext[yyleng-1] = '\0';
-                       escapes(yytext+1, yytext);
-                       yyleng = strlen(yytext);
-                       yylval.sval = yytext;
-                        SETSTATE(0);
+                       char *in = xstrndup(yytext+1, yyleng-2);
+                       escapes(in, in);
+                       yylval.sval = in;
+                       SETSTATE(0);
                        return STRING;
                }
 
-"*"            { BEGIN(0); return WILDCARD; }
-
 <NAME>[^=;:, \t\r\n]+  {
-                       static char *in;
-                       static size_t ins;
-
-                       if (yyleng + 1 > ins) {
-                           ins = yyleng + 1;
-                           in = xrealloc(in, ins);
-                       }
-                       memcpy(in, yytext, yyleng);
-                       in[yyleng] = '\0';
+                       char *in = xstrdup(yytext);
                        escapes(in, in);
-                       yyleng = strlen(in);
                        yylval.sval = in;
-                        SETSTATE(0);
+                       SETSTATE(0);
                        return STRING;
                }
 
 set            { return SET; }
 logfile                { return LOGFILE; }
 idfile         { return IDFILE; }
+pidfile                { return PIDFILE; }
 daemon         { return DAEMON; }
 syslog         { return SYSLOG; }
 invisible      { return INVISIBLE; }
@@ -76,6 +60,7 @@ showdots      { return SHOWDOTS; }
 postmaster     { return POSTMASTER; }
 bouncemail     { return BOUNCEMAIL; }
 spambounce     { return SPAMBOUNCE; }
+softbounce     { return SOFTBOUNCE; }
 warnings       { return WARNINGS; }
 tracepolls     { return TRACEPOLLS; }
 
@@ -85,7 +70,7 @@ poll          { return POLL; }
 skip           { return SKIP; }
 via            { return VIA; }
 aka            { return AKA; }
-local(domains) { return LOCALDOMAINS; }
+local(domains)?        { return LOCALDOMAINS; }
 proto(col)?    { return PROTOCOL; }
 service                { return SERVICE; }
 port           { return PORT; }
@@ -98,8 +83,10 @@ kerberos(_v)?4       { SETSTATE(0); yylval.proto = A_KERBEROS_V4; return AUTHTYPE;}
 kerberos(_v)?5 { SETSTATE(0); yylval.proto = A_KERBEROS_V5; return AUTHTYPE;}
 kerberos       { SETSTATE(0); yylval.proto = A_KERBEROS_V4; return AUTHTYPE;}
 ssh            { SETSTATE(0); yylval.proto = A_SSH; return AUTHTYPE;}
+external       { SETSTATE(0); yylval.proto = A_EXTERNAL; return AUTHTYPE;}
 (otp|opie)     { SETSTATE(0); yylval.proto = A_OTP; return AUTHTYPE;}
 cram(-md5)?    { SETSTATE(0); yylval.proto = A_CRAM_MD5; return AUTHTYPE;}
+msn            { SETSTATE(0); yylval.proto = A_MSN; return AUTHTYPE;}
 ntlm           { SETSTATE(0); yylval.proto = A_NTLM; return AUTHTYPE;}
 <AUTH>password { SETSTATE(0); yylval.proto = A_PASSWORD; return AUTHTYPE;}
 timeout                { return TIMEOUT;}
@@ -108,7 +95,9 @@ qvirtual     { return QVIRTUAL; }
 principal      { return PRINCIPAL; }
 esmtpname      { return ESMTPNAME; }
 esmtppassword  { return ESMTPPASSWORD; }
-
+bad-header     { return BADHEADER; }
+accept         { return ACCEPT; }
+reject         { return REJECT_; }
 
 user(name)?    {SETSTATE(NAME); return USERNAME; }
 <INITIAL,NAME>pass(word)?      {SETSTATE(NAME); return PASSWORD; }
@@ -123,7 +112,6 @@ bsmtp               { return BSMTP; }
 lmtp           { return LMTP; }
 pre(connect)?  { return PRECONNECT; }
 post(connect)? { return POSTCONNECT; }
-netsec         { return NETSEC; }
 interface      { return INTERFACE; }
 monitor                { return MONITOR; }
 plugin         { return PLUGIN; }
@@ -148,6 +136,7 @@ nodns               |
 noenvelope     |
 nokeep         |
 noflush                |
+nolimitflush   |
 nofetchall     |
 norewrite      |
 noforcecr      |
@@ -166,6 +155,7 @@ no          {return NO;}
 
 keep           { return KEEP; }
 flush          { return FLUSH; }
+limitflush     { return LIMITFLUSH; }
 fetchall       { return FETCHALL; }
 rewrite                { return REWRITE; }
 forcecr                { return FORCECR; }
@@ -182,7 +172,9 @@ sslkey              { return SSLKEY; }
 sslcert                { return SSLCERT; }
 sslproto       { return SSLPROTO; }
 sslcertck      { return SSLCERTCK; }
+sslcertfile    { return SSLCERTFILE; }
 sslcertpath    { return SSLCERTPATH; }
+sslcommonname  { return SSLCOMMONNAME; }
 sslfingerprint { return SSLFINGERPRINT; }
 checkalias     { return CHECKALIAS; }
 
@@ -211,9 +203,9 @@ options             {/* EMPTY */}
 -?[0-9]+       { yylval.number = atoi(yytext); return NUMBER; }
 
 [^=;:, \t\r\n]+        {
-                       escapes(yytext, yytext);
-                       yyleng = strlen(yytext);
-                       yylval.sval = yytext;
+                       char *in = xstrdup(yytext);
+                       escapes(in, in);
+                       yylval.sval = in;
                        return STRING;
                }
 
@@ -221,37 +213,40 @@ options           {/* EMPTY */}
 
 %%
 
-void escapes(cp, tp)
-/* process standard C-style escape sequences in a string,
+/** process standard C-style escape sequences in a string,
  * this can never lengthen the output, so cp and tp may overlap as long
  * as cp >= tp. */
-const char     *cp;    /* source string with escapes */
-char           *tp;    /* target buffer for digested string */
+void escapes(const char *cp /** source string with escapes */,
+            char       *tp /** target buffer for digested string */)
 {
     while (*cp)
     {
        int     cval = 0;
 
-       if (*cp == '\\' && strchr("0123456789xX", cp[1]))
+       /* we MUST check for NUL explicitly, as strchr(string, 0) will
+        * always succeed! */
+       if (*cp == '\\' && cp[1] && strchr("0123456789xX", cp[1]))
        {
-           char *dp;
+           const char *dp;
            const char *hex = "00112233445566778899aAbBcCdDeEfF";
            int dcount = 0;
 
            if (*++cp == 'x' || *cp == 'X')
-               for (++cp; (dp = strchr(hex, *cp)) && (dcount++ < 2); cp++)
+               for (++cp; *cp && (dp = strchr(hex, *cp)) && (dcount++ < 2); cp++)
                    cval = (cval * 16) + (dp - hex) / 2;
            else if (*cp == '0')
-               while (strchr("01234567",*cp) != (char*)NULL && (dcount++ < 3))
+               while (*cp && strchr("01234567",*cp) != (char*)NULL && (dcount++ < 3))
                    cval = (cval * 8) + (*cp++ - '0');
            else
-               while ((strchr("0123456789",*cp)!=(char*)NULL)&&(dcount++ < 3))
+               while (*cp && (strchr("0123456789",*cp)!=(char*)NULL)&&(dcount++ < 3))
                    cval = (cval * 10) + (*cp++ - '0');
        }
        else if (*cp == '\\')           /* C-style character escapes */
        {
            switch (*++cp)
            {
+           case '\n': cp++; continue;  /* backslash before LF to join lines */
+           case '\0': goto done;          /* ignore backslash at file end */
            case '\\': cval = '\\'; break;
            case 'n': cval = '\n'; break;
            case 't': cval = '\t'; break;
@@ -265,5 +260,6 @@ char                *tp;    /* target buffer for digested string */
            cval = *cp++;
        *tp++ = cval;
     }
+done:
     *tp = '\0';
 }