diff options
author | Eric S. Raymond <esr@thyrsus.com> | 1997-07-04 05:05:23 +0000 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 1997-07-04 05:05:23 +0000 |
commit | 2afc40a88856ba00c517ca9d58ec834a3492aa91 (patch) | |
tree | 91a1adb2293e3468da140cfb2031568eca886928 | |
parent | d2fa025b2f64bd04e19d192051463d336bb8fdd1 (diff) | |
download | fetchmail-2afc40a88856ba00c517ca9d58ec834a3492aa91.tar.gz fetchmail-2afc40a88856ba00c517ca9d58ec834a3492aa91.tar.bz2 fetchmail-2afc40a88856ba00c517ca9d58ec834a3492aa91.zip |
Remodularize so the parser is more self-contained.
svn path=/trunk/; revision=1150
-rw-r--r-- | fetchmail.c | 54 | ||||
-rw-r--r-- | fetchmail.h | 2 | ||||
-rw-r--r-- | rcfile_l.l | 47 | ||||
-rw-r--r-- | rcfile_y.y | 22 |
4 files changed, 65 insertions, 60 deletions
diff --git a/fetchmail.c b/fetchmail.c index 665f82f8..e6e27151 100644 --- a/fetchmail.c +++ b/fetchmail.c @@ -55,17 +55,13 @@ static char *visbuf(const char *); int outlevel; /* see the O_.* constants above */ /* daemon mode control */ -int poll_interval; /* poll interval in seconds */ bool nodetach; /* if TRUE, don't detach daemon process */ -char *logfile; /* log file for daemon mode */ -bool use_syslog; /* if --syslog was set */ bool quitmode; /* if --quit was set */ bool check_only; /* if --probe was set */ char *cmd_logfile; /* if --logfile was set */ int cmd_daemon; /* if --daemon was set */ /* miscellaneous global controls */ -char *rcfile; /* path name of rc file */ char *idfile; /* UID list file */ bool versioninfo; /* emit only version info */ char *user; /* the name of the invoking user */ @@ -539,7 +535,7 @@ static int load_params(int argc, char **argv, int optind) save_str(&def_opts.smtphunt, -1, fetchmailhost); /* this builds the host list */ - if (prc_parse_file(rcfile) != 0) + if (prc_parse_file(rcfile, !versioninfo) != 0) exit(PS_SYNTAX); if ((implicitmode = (optind >= argc))) @@ -677,7 +673,7 @@ static int load_params(int argc, char **argv, int optind) } /* initialize UID handling */ - if ((st = prc_filecheck(idfile)) != 0) + if (!versioninfo && (st = prc_filecheck(idfile)) != 0) exit(st); else initialize_saved_lists(querylist, idfile); @@ -1012,52 +1008,6 @@ void dump_params (struct query *ctl) } } -/* helper functions for string interpretation and display */ - -void escapes(cp, tp) -/* process standard C-style escape sequences in a string */ -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])) - { - char *dp, *hex = "00112233445566778899aAbBcCdDeEfF"; - int dcount = 0; - - if (*++cp == 'x' || *cp == 'X') - for (++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)) - cval = (cval * 8) + (*cp++ - '0'); - else - while ((strchr("0123456789",*cp)!=(char*)NULL)&&(dcount++ < 3)) - cval = (cval * 10) + (*cp++ - '0'); - } - else if (*cp == '\\') /* C-style character escapes */ - { - switch (*++cp) - { - case '\\': cval = '\\'; break; - case 'n': cval = '\n'; break; - case 't': cval = '\t'; break; - case 'b': cval = '\b'; break; - case 'r': cval = '\r'; break; - default: cval = *cp; - } - cp++; - } - else - cval = *cp++; - *tp++ = cval; - } - *tp = '\0'; -} - static char *visbuf(const char *buf) /* visibilize a given string */ { diff --git a/fetchmail.h b/fetchmail.h index 8ebc0e43..a903134c 100644 --- a/fetchmail.h +++ b/fetchmail.h @@ -239,7 +239,7 @@ void optmerge(struct query *, struct query *); char *MD5Digest (char *); int daemonize(const char *, void (*)(int)); -int prc_parse_file(const char *); +int prc_parse_file(const char *, bool); int prc_filecheck(const char *); void interface_parse(char *, struct hostdata *); @@ -115,5 +115,50 @@ remote(folder)? { [ \t\r]+ ; /* whitespace */ - +%% +#include <string.h> + +void escapes(cp, tp) +/* process standard C-style escape sequences in a string */ +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])) + { + char *dp, *hex = "00112233445566778899aAbBcCdDeEfF"; + int dcount = 0; + + if (*++cp == 'x' || *cp == 'X') + for (++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)) + cval = (cval * 8) + (*cp++ - '0'); + else + while ((strchr("0123456789",*cp)!=(char*)NULL)&&(dcount++ < 3)) + cval = (cval * 10) + (*cp++ - '0'); + } + else if (*cp == '\\') /* C-style character escapes */ + { + switch (*++cp) + { + case '\\': cval = '\\'; break; + case 'n': cval = '\n'; break; + case 't': cval = '\t'; break; + case 'b': cval = '\b'; break; + case 'r': cval = '\r'; break; + default: cval = *cp; + } + cp++; + } + else + cval = *cp++; + *tp++ = cval; + } + *tp = '\0'; +} @@ -22,12 +22,19 @@ #include "fetchmail.h" -struct query cmd_opts; /* where to put command-line info */ +/* parser reads these */ +char *rcfile; /* path name of rc file */ +struct query cmd_opts; /* where to put command-line info */ + +/* parser sets these */ +int poll_interval; /* poll interval in seconds */ +char *logfile; /* log file for daemon mode */ +bool use_syslog; /* if syslog was set */ struct query *querylist; /* head of server list (globally visible) */ -int yydebug; /* in case we didn't generate with -- debug */ +int yydebug; /* in case we didn't generate with -- debug */ -static struct query current; /* current server record */ +static struct query current; /* current server record */ static int prc_errflag; static void record_current(); @@ -256,7 +263,7 @@ const char *pathname; /* pathname for the configuration file */ errno = 0; /* special cases useful for debugging purposes */ - if (strcmp("/dev/null", pathname) == 0 || versioninfo) + if (strcmp("/dev/null", pathname) == 0) return(0); /* the run control file must have the same uid as the REAL uid of this @@ -291,15 +298,18 @@ const char *pathname; /* pathname for the configuration file */ return(0); } -int prc_parse_file (pathname) +int prc_parse_file (pathname, securecheck) /* digest the configuration into a linked list of host records */ const char *pathname; /* pathname for the configuration file */ +const bool securecheck; /* check for a secure rc file? */ { prc_errflag = 0; querylist = hosttail = (struct query *)NULL; + errno = 0; + /* Check that the file is secure */ - if ((prc_errflag = prc_filecheck(pathname)) != 0) + if (securecheck && (prc_errflag = prc_filecheck(pathname)) != 0) return(prc_errflag); if (errno == ENOENT) |