aboutsummaryrefslogtreecommitdiffstats
path: root/driver.c
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>1996-09-26 15:33:47 +0000
committerEric S. Raymond <esr@thyrsus.com>1996-09-26 15:33:47 +0000
commit1ddaf1a4b0c05fcae0584b28b0a93c61f92bcde7 (patch)
treeb50368f415b7ffbcccc8d7774d59e26e65dca57f /driver.c
parente84a6b4c80b6c06136e04e52c29f33454574eeb4 (diff)
downloadfetchmail-1ddaf1a4b0c05fcae0584b28b0a93c61f92bcde7.tar.gz
fetchmail-1ddaf1a4b0c05fcae0584b28b0a93c61f92bcde7.tar.bz2
fetchmail-1ddaf1a4b0c05fcae0584b28b0a93c61f92bcde7.zip
Add code to bind to privileged port as needed for RPOP.
svn path=/trunk/; revision=160
Diffstat (limited to 'driver.c')
-rw-r--r--driver.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/driver.c b/driver.c
index ef2ef878..9c75a706 100644
--- a/driver.c
+++ b/driver.c
@@ -16,6 +16,9 @@
#include <malloc.h>
#include <varargs.h>
#include <sys/time.h>
+#ifdef HAVE_RRESVPORT_H
+#include <netinet/in.h>
+#endif /* HAVE_RRESVPORT_H */
#include "socket.h"
#include "fetchmail.h"
@@ -543,11 +546,31 @@ struct method *proto;
int mboxfd = -1;
char buf [POPBUFSIZE+1], host[HOSTLEN+1];
int socket;
+#ifdef HAVE_RRESVPORT_H
+ int privport = -1;
+#endif /* HAVE_RRESVPORT_H */
int first,number,count;
tagnum = 0;
protocol = proto;
+#ifdef HAVE_RRESVPORT_H
+ /*
+ * If we're trying to bind to a reserved port on the remote system,
+ * do likewise on the local one so the remote will know we're privileged.
+ * (This is most likely to happen in connection with RPOP.)
+ */
+ if (queryctl->port < IPPORT_RESERVED)
+ {
+ ok = IPPORT_RESERVED - 1;
+ if ((privport = rresvport(&ok)) == -1)
+ {
+ perror("fetchmail, binding to reserved port");
+ return(PS_SOCKET);
+ }
+ }
+#endif /* HAVE_RRESVPORT_H */
+
/* open a socket to the mail server */
if ((socket = Socket(queryctl->servername,
queryctl->port ? queryctl->port : protocol->port))<0)
@@ -705,6 +728,11 @@ cleanUp:
close(socket);
}
+#ifdef HAVE_RRESVPORT_H
+ if (privport != -1)
+ close(privport); /* no big deal if this fails */
+#endif /* HAVE_RRESVPORT_H */
+
closeUp:
if (queryctl->output == TO_FOLDER)
{