From 1ddaf1a4b0c05fcae0584b28b0a93c61f92bcde7 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Thu, 26 Sep 1996 15:33:47 +0000 Subject: Add code to bind to privileged port as needed for RPOP. svn path=/trunk/; revision=160 --- driver.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'driver.c') diff --git a/driver.c b/driver.c index ef2ef878..9c75a706 100644 --- a/driver.c +++ b/driver.c @@ -16,6 +16,9 @@ #include #include #include +#ifdef HAVE_RRESVPORT_H +#include +#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) { -- cgit v1.2.3