diff options
-rw-r--r-- | conf.c | 10 | ||||
-rw-r--r-- | driver.c | 17 | ||||
-rw-r--r-- | etrn.c | 5 | ||||
-rw-r--r-- | fetchmail.c | 47 | ||||
-rw-r--r-- | fetchmail.h | 25 | ||||
-rwxr-xr-x | fetchmailconf | 48 | ||||
-rw-r--r-- | imap.c | 5 | ||||
-rw-r--r-- | odmr.c | 9 | ||||
-rw-r--r-- | options.c | 8 | ||||
-rw-r--r-- | pop2.c | 5 | ||||
-rw-r--r-- | pop3.c | 9 | ||||
-rw-r--r-- | rcfile_y.y | 12 | ||||
-rw-r--r-- | sink.c | 8 | ||||
-rw-r--r-- | socket.c | 18 | ||||
-rw-r--r-- | socket.h | 10 | ||||
-rw-r--r-- | transact.c | 8 |
16 files changed, 76 insertions, 168 deletions
@@ -246,11 +246,7 @@ void dump_config(struct runctl *runp, struct query *querylist) using_kpop = (ctl->server.protocol == P_POP3 && -#ifndef INET6_ENABLE - ctl->server.port == KPOP_PORT && -#else ctl->server.service && !strcmp(ctl->server.service, KPOP_PORT ) && -#endif ctl->server.authenticate == A_KERBEROS_V4); stringdump("pollname", ctl->server.pollname); @@ -258,11 +254,7 @@ void dump_config(struct runctl *runp, struct query *querylist) stringdump("via", ctl->server.via); stringdump("protocol", using_kpop ? "KPOP" : showproto(ctl->server.protocol)); -#ifndef INET6_ENABLE - numdump("port", ctl->server.port); -#else - stringdump("port", ctl->server.service); -#endif + stringdump("service", ctl->server.service); numdump("timeout", ctl->server.timeout); numdump("interval", ctl->server.interval); @@ -939,11 +939,7 @@ static int do_session( /* setjmp returned zero -> normal operation */ char buf[MSGBUFSIZE+1], *realhost; int count, new, bytes; -#ifdef INET6_ENABLE int fetches, dispatches, oldphase; -#else /* INET6_ENABLE */ - int port, fetches, dispatches, oldphase; -#endif /* INET6_ENABLE */ struct idlist *idp; /* execute pre-initialization command, if any */ @@ -959,13 +955,6 @@ static int do_session( oldphase = phase; phase = OPEN_WAIT; set_timeout(mytimeout); -#ifndef INET6_ENABLE -#ifdef SSL_ENABLE - port = ctl->server.port ? ctl->server.port : ( ctl->use_ssl ? ctl->server.base_protocol->sslport : ctl->server.base_protocol->port ); -#else - port = ctl->server.port ? ctl->server.port : ctl->server.base_protocol->port; -#endif -#endif /* !INET6_ENABLE */ #ifdef HAVE_PKG_hesiod /* If either the pollname or vianame are "hesiod" we want to @@ -1081,13 +1070,9 @@ static int do_session( /* allow time for the port to be set up if we have a plugin */ if (ctl->server.plugin) (void)sleep(1); -#ifdef INET6_ENABLE if ((mailserver_socket = SockOpen(realhost, ctl->server.service ? ctl->server.service : ( ctl->use_ssl ? ctl->server.base_protocol->sslservice : ctl->server.base_protocol->service ), ctl->server.plugin)) == -1) -#else /* INET6_ENABLE */ - if ((mailserver_socket = SockOpen(realhost, port, ctl->server.plugin)) == -1) -#endif /* INET6_ENABLE */ { char errbuf[BUFSIZ]; #ifndef INET6_ENABLE @@ -1574,7 +1559,7 @@ is restored.")); break; } if (msg) { - char *stem; + const char *stem; if (phase == FORWARDING_WAIT || phase == LISTENER_WAIT) stem = GT_("%s error while delivering to SMTP host %s\n"); @@ -122,13 +122,8 @@ static int etrn_logout(int sock, struct query *ctl) static const struct method etrn = { "ETRN", /* ESMTP ETRN extension */ -#ifdef INET6_ENABLE "smtp", /* standard SMTP port */ "smtps", /* ssl SMTP port */ -#else /* INET6_ENABLE */ - 25, /* standard SMTP port */ - 465, /* ssl SMTP port */ -#endif /* INET6_ENABLE */ FALSE, /* this is not a tagged protocol */ FALSE, /* this does not use a message delimiter */ etrn_ok, /* parse command response */ diff --git a/fetchmail.c b/fetchmail.c index 54ba2a81..84fed2c4 100644 --- a/fetchmail.c +++ b/fetchmail.c @@ -840,11 +840,7 @@ static void optmerge(struct query *h2, struct query *h1, int force) #define FLAG_MERGE(fld) if (force ? !!h1->fld : !h2->fld) h2->fld = h1->fld FLAG_MERGE(server.via); FLAG_MERGE(server.protocol); -#ifdef INET6_ENABLE FLAG_MERGE(server.service); -#else /* INET6_ENABLE */ - FLAG_MERGE(server.port); -#endif /* INET6_ENABLE */ FLAG_MERGE(server.interval); FLAG_MERGE(server.authenticate); FLAG_MERGE(server.timeout); @@ -1180,24 +1176,27 @@ static int load_params(int argc, char **argv, int optind) save_str(&ctl->mailboxes, (char *)NULL, 0); /* maybe user overrode timeout on command line? */ - if (ctl->server.timeout == -1) + if (ctl->server.timeout == -1) ctl->server.timeout = CLIENT_TIMEOUT; #ifndef INET6_ENABLE /* sanity checks */ - if (ctl->server.port < 0) - { - (void) fprintf(stderr, - GT_("%s configuration invalid, port number cannot be negative\n"), - ctl->server.pollname); - exit(PS_SYNTAX); - } - if (ctl->server.protocol == P_RPOP && ctl->server.port >= 1024) - { - (void) fprintf(stderr, - GT_("%s configuration invalid, RPOP requires a privileged port\n"), - ctl->server.pollname); - exit(PS_SYNTAX); + if (ctl->server.service) { + int port = servport(ctl->server.service); + if (port < 0) + { + (void) fprintf(stderr, + GT_("%s configuration invalid, port number cannot be negative\n"), + ctl->server.pollname); + exit(PS_SYNTAX); + } + if (ctl->server.protocol == P_RPOP && port >= 1024) + { + (void) fprintf(stderr, + GT_("%s configuration invalid, RPOP requires a privileged port\n"), + ctl->server.pollname); + exit(PS_SYNTAX); + } } if (ctl->listener == LMTP_MODE) { @@ -1208,7 +1207,8 @@ static int load_params(int argc, char **argv, int optind) char *cp; if (!(cp = strrchr(idp->id, '/')) || - (atoi(++cp) == SMTP_PORT)) + ++cp, (0 == strcmp(cp, SMTP_PORT)) + || servport(cp) == SMTP_PORT_NUM) { (void) fprintf(stderr, GT_("%s configuration invalid, LMTP can't use default SMTP port\n"), @@ -1528,24 +1528,15 @@ static void dump_params (struct runctl *runp, } if (ctl->server.protocol == P_POP3 -#ifdef INET6_ENABLE && ctl->server.service && !strcmp(ctl->server.service, KPOP_PORT) -#else /* INET6_ENABLE */ - && ctl->server.port == KPOP_PORT -#endif /* INET6_ENABLE */ && (ctl->server.authenticate == A_KERBEROS_V4 || ctl->server.authenticate == A_KERBEROS_V5)) printf(GT_(" Protocol is KPOP with Kerberos %s authentication"), ctl->server.authenticate == A_KERBEROS_V5 ? "V" : "IV"); else printf(GT_(" Protocol is %s"), showproto(ctl->server.protocol)); -#ifdef INET6_ENABLE if (ctl->server.service) printf(GT_(" (using service %s)"), ctl->server.service); -#else /* INET6_ENABLE */ - if (ctl->server.port) - printf(GT_(" (using port %d)"), ctl->server.port); -#endif /* INET6_ENABLE */ else if (outlevel >= O_VERBOSE) printf(GT_(" (using default port)")); if (ctl->server.uidl && MAILBOX_PROTOCOL(ctl)) diff --git a/fetchmail.h b/fetchmail.h index eede713a..7b2076d6 100644 --- a/fetchmail.h +++ b/fetchmail.h @@ -42,13 +42,9 @@ char *strstr(const char *, const char *); #define P_ETRN 7 #define P_ODMR 8 -#ifdef INET6_ENABLE #define SMTP_PORT "smtp" +#define SMTP_PORT_NUM 25 #define KPOP_PORT "kpop" -#else /* INET6_ENABLE */ -#define SMTP_PORT 25 -#define KPOP_PORT 1109 -#endif /* INET6_ENABLE */ #ifdef SSL_ENABLE #define SIMAP_PORT 993 @@ -189,13 +185,8 @@ struct query; struct method /* describe methods for protocol state machine */ { const char *name; /* protocol name */ -#ifdef INET6_ENABLE - const char *service; - const char *sslservice; -#else /* INET6_ENABLE */ - int port; /* service port */ - int sslport; /* service port for ssl */ -#endif /* INET6_ENABLE */ + const char *service; /* service port (unencrypted) */ + const char *sslservice; /* service port (SSL) */ flag tagged; /* if true, generate & expect command tags */ flag delimited; /* if true, accept "." message delimiter */ int (*parse_response)(int, char *); @@ -233,11 +224,7 @@ struct hostdata /* shared among all user connections to given server */ struct idlist *akalist; /* server name first, then akas */ struct idlist *localdomains; /* list of pass-through domains */ int protocol; /* protocol type */ -#ifdef INET6_ENABLE - char *service; /* IPv6 service name */ -#else /* INET6_ENABLE */ - int port; /* TCP/IP service port number */ -#endif /* INET6_ENABLE */ + char *service; /* service name */ int interval; /* # cycles to skip between polls */ int authenticate; /* authentication mode to try */ int timeout; /* inactivity timout in seconds */ @@ -716,4 +703,8 @@ size_t strlcpy(char *dst, const char *src, size_t siz); #endif +/** Resolve the a TCP service name or a string containing only a decimal + * positive integer to a port number. Returns -1 for error. */ +int servport(const char *service); + /* fetchmail.h ends here */ diff --git a/fetchmailconf b/fetchmailconf index 36bc99fd..4a014036 100755 --- a/fetchmailconf +++ b/fetchmailconf @@ -79,7 +79,7 @@ class Server: self.active = TRUE # Poll status self.interval = 0 # Skip interval self.protocol = 'auto' # Default to auto protocol - self.port = 0 # Port number to use + self.service = None # Service name to use self.uidl = FALSE # Don't use RFC1725 UIDLs by default self.auth = 'any' # Default to password authentication self.timeout = 300 # 5-minute timeout @@ -104,7 +104,7 @@ class Server: ('active', 'Boolean'), ('interval', 'Int'), ('protocol', 'String'), - ('port', 'Int'), + ('service', 'String'), ('uidl', 'Boolean'), ('auth', 'String'), ('timeout', 'Int'), @@ -132,8 +132,8 @@ class Server: res = res + (" via " + str(self.via) + "\n"); if self.protocol != ServerDefaults.protocol: res = res + " with proto " + self.protocol - if self.port != defaultports[self.protocol] and self.port: - res = res + " port " + `self.port` + if self.service and self.service != defaultports[self.protocol] and self.service != ianaservices[defaultports[self.protocol]]: + res = res + " service " + self.service if self.timeout != ServerDefaults.timeout: res = res + " timeout " + `self.timeout` if self.interval != ServerDefaults.interval: @@ -410,14 +410,23 @@ class User: # Helper code # -defaultports = {"auto":0, - "POP2":109, - "POP3":110, - "APOP":110, - "KPOP":1109, - "IMAP":143, - "ETRN":25, - "ODMR":366} +# IANA port assignments and bogus 1109 entry +ianaservices = {"pop2":109, + "pop3":110, + "1109":1109, + "imap":143, + "smtp":25, + "odmr":366} + +# fetchmail protocol to IANA service name +defaultports = {"auto":None, + "POP2":"pop2", + "POP3":"pop3", + "APOP":"pop3", + "KPOP":"1109", + "IMAP":"imap", + "ETRN":"smtp", + "ODMR":"odmr"} authlist = ("any", "password", "gssapi", "kerberos", "ssh", "otp") @@ -944,9 +953,9 @@ ports for POP3 and IMAP to see if either is available. Normally the TCP/IP service port to use is -dictated by the protocol choice. The `Port' +dictated by the protocol choice. The `Service' field (only present in expert mode) lets you -set a non-standard port. +set a non-standard service (port). """} sechelp = { @@ -1055,7 +1064,7 @@ class ServerEdit(Frame, MyWidget): # Now we reset unconditionally on the theory that if you're setting # a custom port number you should be in expert mode and playing # close enough attention to notice this... - self.port.set(defaultports[proto]) + self.service.set(defaultports[proto]) if not proto in ("POP3", "APOP", "KPOP"): self.uidl.state = DISABLED def user_edit(self, username, mode): @@ -1107,8 +1116,8 @@ class ServerEdit(Frame, MyWidget): self.protocol, protolist, 2, self.defaultPort) if mode != 'novice': - LabeledEntry(protwin, 'On server TCP/IP port:', - self.port, leftwidth).pack(side=TOP, fill=X) + LabeledEntry(protwin, 'On server TCP/IP service:', + self.service, leftwidth).pack(side=TOP, fill=X) self.defaultPort() Checkbutton(protwin, text="POP3: track `seen' with client-side UIDLs?", @@ -1186,10 +1195,11 @@ class ServerEdit(Frame, MyWidget): else: realhost = self.server.pollname greetline = None - for (protocol, port) in (("IMAP",143), ("POP3",110), ("POP2",109)): + for protocol in ("IMAP","POP3","POP2"): + service = defaultports[protocol] sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: - sock.connect((realhost, port)) + sock.connect((realhost, ianaservices[service])) greetline = sock.recv(1024) sock.close() except: @@ -1124,13 +1124,8 @@ static int imap_logout(int sock, struct query *ctl) static const struct method imap = { "IMAP", /* Internet Message Access Protocol */ -#ifdef INET6_ENABLE "imap", "imaps", -#else /* INET6_ENABLE */ - 143, /* standard IMAP2bis/IMAP4 port */ - 993, /* ssl IMAP2bis/IMAP4 port */ -#endif /* INET6_ENABLE */ TRUE, /* this is a tagged protocol */ FALSE, /* no message delimiter */ imap_ok, /* parse command response */ @@ -211,13 +211,8 @@ static int odmr_logout(int sock, struct query *ctl) static const struct method odmr = { "ODMR", /* ODMR protocol */ -#ifdef INET6_ENABLE - "odmr", /* standard SMTP port */ - "odmrs", /* ssl SMTP port */ -#else /* INET6_ENABLE */ - 366, /* standard SMTP port */ - 2366, /* ssl SMTP port (BOGUS! RANDOM VALUE) */ -#endif /* INET6_ENABLE */ + "odmr", /* standard ODMR port */ + "odmrs", /* ssl ODMR port */ FALSE, /* this is not a tagged protocol */ FALSE, /* this does not use a message delimiter */ odmr_ok, /* parse command response */ @@ -358,11 +358,7 @@ struct query *ctl; /* option record to be initialized */ else if (strcasecmp(optarg,"kpop") == 0) { ctl->server.protocol = P_POP3; -#ifdef INET6_ENABLE ctl->server.service = KPOP_PORT; -#else /* INET6_ENABLE */ - ctl->server.port = KPOP_PORT; -#endif /* INET6_ENABLE */ #ifdef KERBEROS_V5 ctl->server.authenticate = A_KERBEROS_V5; #else @@ -386,11 +382,7 @@ struct query *ctl; /* option record to be initialized */ break; case 'P': case LA_PORT: -#ifdef INET6_ENABLE ctl->server.service = optarg; -#else /* INET6_ENABLE */ - ctl->server.port = xatoi(optarg, &errflag); -#endif /* INET6_ENABLE */ break; case LA_AUTH: if (strcmp(optarg, "password") == 0) @@ -132,13 +132,8 @@ static int pop2_logout(int sock, struct query *ctl) static const struct method pop2 = { "POP2", /* Post Office Protocol v2 */ -#if INET6_ENABLE - "pop2", /* standard POP2 port */ - "pop2", /* ssl POP2 port */ -#else /* INET6_ENABLE */ 109, /* standard POP2 port */ 109, /* ssl POP2 port - not */ -#endif /* INET6_ENABLE */ FALSE, /* this is not a tagged protocol */ FALSE, /* does not use message delimiter */ pop2_ok, /* parse command response */ @@ -449,11 +449,7 @@ static int pop3_getauth(int sock, struct query *ctl, char *greeting) * rather than doing SASL. */ if (has_kerberos && -#ifdef INET6_ENABLE ctl->server.service && (strcmp(ctl->server.service, KPOP_PORT)!=0) -#else /* INET6_ENABLE */ - ctl->server.port != KPOP_PORT -#endif /* INET6_ENABLE */ && (ctl->server.authenticate == A_KERBEROS_V4 || ctl->server.authenticate == A_KERBEROS_V5 || ctl->server.authenticate == A_ANY)) @@ -1243,13 +1239,8 @@ static int pop3_logout(int sock, struct query *ctl) static const struct method pop3 = { "POP3", /* Post Office Protocol v3 */ -#ifdef INET6_ENABLE "pop3", /* standard POP3 port */ "pop3s", /* ssl POP3 port */ -#else /* INET6_ENABLE */ - 110, /* standard POP3 port */ - 995, /* ssl POP3 port */ -#endif /* INET6_ENABLE */ FALSE, /* this is not a tagged protocol */ TRUE, /* this uses a message delimiter */ pop3_ok, /* parse command response */ @@ -153,11 +153,7 @@ serv_option : AKA alias_list #else current.server.authenticate = A_KERBEROS_V4; #endif /* KERBEROS_V5 */ -#ifdef INET6_ENABLE current.server.service = KPOP_PORT; -#else /* INET6_ENABLE */ - current.server.port = KPOP_PORT; -#endif /* INET6_ENABLE */ } | PRINCIPAL STRING {current.server.principal = xstrdup($2);} | ESMTPNAME STRING {current.server.esmtp_name = xstrdup($2);} @@ -175,19 +171,13 @@ serv_option : AKA alias_list | CHECKALIAS {current.server.checkalias = FLAG_TRUE;} | NO CHECKALIAS {current.server.checkalias = FLAG_FALSE;} | SERVICE STRING { -#ifdef INET6_ENABLE current.server.service = $2; -#endif /* INET6_ENABLE */ } | PORT NUMBER { -#ifdef INET6_ENABLE int port = $2; char buf[10]; - sprintf(buf, "%d", port); + snprintf(buf, sizeof buf, "%d", port); current.server.service = xstrdup(buf); -#else - current.server.port = $2; -#endif /* INET6_ENABLE */ } | INTERVAL NUMBER {current.server.interval = $2;} @@ -121,11 +121,7 @@ int smtp_open(struct query *ctl) for (idp = ctl->smtphunt; idp; idp = idp->next) { char *cp; -#ifdef INET6_ENABLE char *portnum = SMTP_PORT; -#else - int portnum = SMTP_PORT; -#endif /* INET6_ENABLE */ ctl->smtphost = idp->id; /* remember last host tried. */ if(ctl->smtphost[0]=='/') @@ -136,11 +132,7 @@ int smtp_open(struct query *ctl) if ((cp = strrchr(parsed_host, '/'))) { *cp++ = 0; -#ifdef INET6_ENABLE portnum = cp; -#else - portnum = atoi(cp); -#endif /* INET6_ENABLE */ } if (ctl->smtphost[0]=='/'){ @@ -319,7 +319,7 @@ int SockOpen(const char *host, const char *service, #endif #endif /* HAVE_INET_ATON */ -int SockOpen(const char *host, int clientPort, +int SockOpen(const char *host, const char *service, const char *plugin) { int sock = -1; /* pacify -Wall */ @@ -328,6 +328,7 @@ int SockOpen(const char *host, int clientPort, #endif /* HAVE_INET_ATON */ struct sockaddr_in ad, **pptr; struct hostent *hp; + int clientPort = servport(service); #ifdef HAVE_SOCKETPAIR if (plugin) { @@ -337,6 +338,9 @@ int SockOpen(const char *host, int clientPort, } #endif /* HAVE_SOCKETPAIR */ + if (clientPort < 0) + return sock; + memset(&ad, 0, sizeof(ad)); ad.sin_family = AF_INET; @@ -359,11 +363,11 @@ int SockOpen(const char *host, int clientPort, return -1; } - /* Socket opened saved. Usefull if connect timeout because - * it can be closed - */ - mailserver_socket_temp = sock; - + /* Socket opened saved. Usefull if connect timeout because + * it can be closed + */ + mailserver_socket_temp = sock; + if (connect(sock, (struct sockaddr *) &ad, sizeof(ad)) < 0) { int olderr = errno; @@ -1072,7 +1076,7 @@ static ssize_t cygwin_read(int sock, void *buf, size_t count) * inetd.conf (and then SIGHUP inetd) for this to work. */ main() { - int sock = SockOpen("localhost", 19, NULL); + int sock = SockOpen("localhost", "chargen", NULL); char buf[80]; while (SockRead(sock, buf, sizeof(buf)-1)) @@ -7,14 +7,8 @@ #ifndef SOCKET__ #define SOCKET__ -/* Create a new client socket; returns (FILE *)NULL on error */ -#ifdef INET6_ENABLE -int SockOpen(const char *host, const char *service, - const char *plugin); -#else /* INET6_ENABLE */ -int SockOpen(const char *host, int clientPort, - const char *plugin); -#endif /* INET6_ENABLE */ +/* Create a new client socket; returns -1 on error */ +int SockOpen(const char *host, const char *service, const char *plugin); /* Returns 1 if this socket is OK, 0 if it isn't select()able * on - probably because it's been closed. You should @@ -611,15 +611,11 @@ int readheaders(int sock, #ifdef POP2_ENABLE /* * We disable this check under POP2 because there's no way to - * prevent deletion of the message. So at least we ought to + * prevent deletion of the message. So at least we ought to * forward it to the user so he or she will have some clue * that things have gone awry. */ -#if INET6_ENABLE - if (strncmp(protocol->service, "pop2", 4)) -#else /* INET6_ENABLE */ - if (protocol->port != 109) -#endif /* INET6_ENABLE */ + if (servport("pop2") != servport(protocol->service)) #endif /* POP2_ENABLE */ if (num == 1 && !strncasecmp(line, "X-IMAP:", 7)) { free(line); |