httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From traw...@locus.apache.org
Subject cvs commit: apache-2.0/src/modules/proxy proxy_ftp.c
Date Sun, 19 Nov 2000 14:24:20 GMT
trawick     00/11/19 06:24:20

  Modified:    src      CHANGES
               src/lib/apr/include apr_network_io.h
               src/lib/apr/network_io/os2 sockets.c
               src/lib/apr/network_io/unix sockets.c
               src/lib/apr/network_io/win32 sockets.c
               src/lib/apr/test server.c testsf.c
               src/main listen.c rfc1413.c
               src/modules/proxy proxy_ftp.c
  Log:
  Change apr_bind() to take apr_sockaddr_t.
  
  Revision  Changes    Path
  1.342     +2 -2      apache-2.0/src/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/CHANGES,v
  retrieving revision 1.341
  retrieving revision 1.342
  diff -u -r1.341 -r1.342
  --- CHANGES	2000/11/18 20:52:28	1.341
  +++ CHANGES	2000/11/19 14:24:16	1.342
  @@ -24,8 +24,8 @@
        Add generic apr_create_socket().  Add apr_getaddrinfo() for doing
        hostname resolution/address string parsing and building
        apr_sockaddr_t.  Add apr_get_sockaddr() for getting the address
  -     of one of the apr_sockaddr_t structures for a socket.
  -     [David Reid and Jeff Trawick]
  +     of one of the apr_sockaddr_t structures for a socket.  Change
  +     apr_bind() to take apr_sockaddr_t.  [David Reid and Jeff Trawick]
   
     *) Remove the BUFF from the HTTP proxy.  This is still a bit ugly, but
        I have proxied pages with it, cleanup will commence soon.
  
  
  
  1.76      +3 -2      apache-2.0/src/lib/apr/include/apr_network_io.h
  
  Index: apr_network_io.h
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/include/apr_network_io.h,v
  retrieving revision 1.75
  retrieving revision 1.76
  diff -u -r1.75 -r1.76
  --- apr_network_io.h	2000/11/18 20:52:28	1.75
  +++ apr_network_io.h	2000/11/19 14:24:17	1.76
  @@ -245,10 +245,11 @@
   /**
    * Bind the socket to its associated port
    * @param sock The socket to bind 
  - * @tip This is where we will find out if there is any other process
  + * @param sa The socket address to bind to
  + * @tip This may be where we will find out if there is any other process
    *      using the selected port.
    */
  -apr_status_t apr_bind(apr_socket_t *sock);
  +apr_status_t apr_bind(apr_socket_t *sock, apr_sockaddr_t *sa);
   
   /**
    * Listen to a bound socket for connections.
  
  
  
  1.33      +6 -4      apache-2.0/src/lib/apr/network_io/os2/sockets.c
  
  Index: sockets.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/network_io/os2/sockets.c,v
  retrieving revision 1.32
  retrieving revision 1.33
  diff -u -r1.32 -r1.33
  --- sockets.c	2000/11/17 03:45:03	1.32
  +++ sockets.c	2000/11/19 14:24:17	1.33
  @@ -189,14 +189,16 @@
   
   
   
  -apr_status_t apr_bind(apr_socket_t *sock)
  +apr_status_t apr_bind(apr_socket_t *sock, apr_sockaddr_t *sa)
   {
       if (bind(sock->socketdes, 
  -             (struct sockaddr *)&sock->local_addr->sa,
  -             sock->local_addr->sa_len) == -1)
  +             (struct sockaddr *)&sa->sa,
  +             sa->sa_len) == -1)
           return APR_OS2_STATUS(sock_errno());
  -    else
  +    else {
  +        sock->local_sa = sa;
           return APR_SUCCESS;
  +    }
   }
   
   apr_status_t apr_listen(apr_socket_t *sock, apr_int32_t backlog)
  
  
  
  1.63      +4 -2      apache-2.0/src/lib/apr/network_io/unix/sockets.c
  
  Index: sockets.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/network_io/unix/sockets.c,v
  retrieving revision 1.62
  retrieving revision 1.63
  diff -u -r1.62 -r1.63
  --- sockets.c	2000/11/19 03:02:37	1.62
  +++ sockets.c	2000/11/19 14:24:17	1.63
  @@ -167,12 +167,14 @@
       return socket_cleanup(thesocket);
   }
   
  -apr_status_t apr_bind(apr_socket_t *sock)
  +apr_status_t apr_bind(apr_socket_t *sock, apr_sockaddr_t *sa)
   {
       if (bind(sock->socketdes, 
  -             (struct sockaddr *)&sock->local_addr->sa, sock->local_addr->sa_len)
== -1)
  +             (struct sockaddr *)&sa->sa, sa->sa_len) == -1) {
           return errno;
  +    }
       else {
  +        sock->local_addr = sa;
           /* XXX IPv6 - this assumes sin_port and sin6_port at same offset */
           if (sock->local_addr->sa.sin.sin_port == 0) { /* no need for ntohs() when
comparing w/ 0 */
               sock->local_port_unknown = 1; /* kernel got us an ephemeral port */
  
  
  
  1.43      +4 -3      apache-2.0/src/lib/apr/network_io/win32/sockets.c
  
  Index: sockets.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/network_io/win32/sockets.c,v
  retrieving revision 1.42
  retrieving revision 1.43
  diff -u -r1.42 -r1.43
  --- sockets.c	2000/11/17 03:45:03	1.42
  +++ sockets.c	2000/11/19 14:24:18	1.43
  @@ -196,14 +196,15 @@
       return socket_cleanup(thesocket);
   }
   
  -apr_status_t apr_bind(apr_socket_t *sock)
  +apr_status_t apr_bind(apr_socket_t *sock, apr_sockaddr_t *sa)
   {
       if (bind(sock->sock, 
  -             (struct sockaddr *)&sock->local_addr->sa, 
  -             sock->local_addr->sa_len) == -1) {
  +             (struct sockaddr *)&sa->sa, 
  +             sa->sa_len) == -1) {
           return apr_get_netos_error();
       }
       else {
  +        sock->local_addr = sa;
           if (sock->local_addr->sa.sin.sin_port == 0) {
               sock->local_port_unknown = 1; /* ephemeral port */
           }
  
  
  
  1.20      +52 -10    apache-2.0/src/lib/apr/test/server.c
  
  Index: server.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/test/server.c,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- server.c	2000/11/18 15:46:45	1.19
  +++ server.c	2000/11/19 14:24:18	1.20
  @@ -56,10 +56,11 @@
   #include "apr_network_io.h"
   #include "apr_errno.h"
   #include "apr_general.h"
  +#include "apr_getopt.h"
   
   #define STRLEN 15
   
  -int main(int argc, char *argv[])
  +int main(int argc, char * const argv[])
   {
       apr_pool_t *context;
       apr_socket_t *sock;
  @@ -69,8 +70,16 @@
       apr_pollfd_t *sdset;
       char datasend[STRLEN];
       char datarecv[STRLEN] = "Recv data test";
  +    const char *bind_to_ipaddr = NULL;
       char *local_ipaddr, *remote_ipaddr;
       apr_port_t local_port, remote_port;
  +    apr_sockaddr_t *localsa = NULL;
  +    apr_status_t stat;
  +    int family = APR_UNSPEC;
  +    char buf[128];
  +    apr_getopt_t *opt;
  +    const char *optarg;
  +    char optchar;
   
       fprintf(stdout, "Initializing.........");
       if (apr_initialize() != APR_SUCCESS) {
  @@ -87,8 +96,43 @@
       }
       fprintf(stdout, "OK\n");
   
  +    if (apr_initopt(&opt, context, argc, argv)) {
  +        fprintf(stderr, "failed to initialize opts\n");
  +        exit(-1);
  +    }
  +
  +    while ((stat = apr_getopt(opt, "i:", &optchar, &optarg)) == APR_SUCCESS) {
  +        switch(optchar) {
  +        case 'i':
  +            bind_to_ipaddr = optarg;
  +            break;
  +        }
  +    }
  +    if (stat != APR_EOF) {
  +        fprintf(stderr,
  +                "usage: %s [-i local-interface-address]\n",
  +                argv[0]);
  +        exit(-1);
  +    }
  +
  +    if (bind_to_ipaddr) {
  +        /* First, parse/resolve ipaddr so we know what address family of
  +         * socket we need.  We'll use the returned sockaddr later when
  +         * we bind.
  +         */
  +        stat = apr_getaddrinfo(&localsa, bind_to_ipaddr, APR_UNSPEC, 8021, 0,
  +                               context);
  +        if (stat != APR_SUCCESS) {
  +            fprintf(stderr,
  +                    "Couldn't build the socket address correctly: %s\n",
  +                    apr_strerror(stat, buf, sizeof buf));
  +            exit(-1);
  +        }
  +        family = localsa->sa.sin.sin_family;
  +    }
  +
       fprintf(stdout, "\tServer:  Creating new socket.......");
  -    if (apr_create_socket(&sock, APR_UNSPEC, SOCK_STREAM, context) != APR_SUCCESS)
{
  +    if (apr_create_socket(&sock, family, SOCK_STREAM, context) != APR_SUCCESS) {
           fprintf(stderr, "Couldn't create socket\n");
           exit(-1);
       }
  @@ -110,18 +154,16 @@
       }
       fprintf(stdout, "OK\n");
   
  -    fprintf(stdout, "\tServer:  Setting port for socket.......");
  -    if (apr_set_port(sock, APR_LOCAL, 8021) != APR_SUCCESS) {
  -        apr_close_socket(sock);
  -        fprintf(stderr, "Couldn't set the port correctly\n");
  -        exit(-1);
  +    if (!localsa) {
  +        apr_set_port(sock, APR_LOCAL, 8021);
  +        apr_get_sockaddr(&localsa, APR_LOCAL, sock);
       }
  -    fprintf(stdout, "OK\n");
   
       fprintf(stdout, "\tServer:  Binding socket to port.......");
  -    if (apr_bind(sock) != APR_SUCCESS) {
  +    if ((stat = apr_bind(sock, localsa)) != APR_SUCCESS) {
           apr_close_socket(sock);
  -        fprintf(stderr, "Could not bind\n");
  +        fprintf(stderr, "Could not bind: %s\n",
  +                apr_strerror(stat, buf, sizeof buf));
           exit(-1);
       }
       fprintf(stdout, "OK\n");
  
  
  
  1.16      +29 -11    apache-2.0/src/lib/apr/test/testsf.c
  
  Index: testsf.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/test/testsf.c,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- testsf.c	2000/11/18 15:46:45	1.15
  +++ testsf.c	2000/11/19 14:24:19	1.16
  @@ -90,7 +90,7 @@
   
   typedef enum {BLK, NONBLK, TIMEOUT} client_socket_mode_t;
   
  -static void apr_setup(apr_pool_t **p, apr_socket_t **sock)
  +static void apr_setup(apr_pool_t **p, apr_socket_t **sock, int *family)
   {
       char buf[120];
       apr_status_t rv;
  @@ -114,13 +114,26 @@
       }
   
       *sock = NULL;
  -    rv = apr_create_tcp_socket(sock, *p);
  +    rv = apr_create_socket(sock, *family, SOCK_STREAM, *p);
       if (rv != APR_SUCCESS) {
  -        fprintf(stderr, "apr_create_tcp_socket()->%d/%s\n",
  +        fprintf(stderr, "apr_create_socket()->%d/%s\n",
                   rv,
                   apr_strerror(rv, buf, sizeof buf));
           exit(1);
       }
  +
  +    if (*family == APR_UNSPEC) {
  +        apr_sockaddr_t *localsa;
  +
  +        rv = apr_get_sockaddr(&localsa, APR_LOCAL, *sock);
  +        if (rv != APR_SUCCESS) {
  +            fprintf(stderr, "apr_get_sockaddr()->%d/%s\n",
  +                    rv,
  +                    apr_strerror(rv, buf, sizeof buf));
  +            exit(1);
  +        }
  +        *family = localsa->sa.sin.sin_family;
  +    }
   }
   
   static void create_testfile(apr_pool_t *p, const char *fname)
  @@ -205,9 +218,11 @@
       apr_pollfd_t *pfd;
       apr_int32_t nsocks;
       int i;
  +    int family;
       apr_sockaddr_t *destsa;
   
  -    apr_setup(&p, &sock);
  +    family = APR_INET;
  +    apr_setup(&p, &sock, &family);
       create_testfile(p, TESTFILE);
   
       rv = apr_open(&f, TESTFILE, APR_READ, 0, p);
  @@ -218,7 +233,7 @@
           exit(1);
       }
   
  -    rv = apr_getaddrinfo(&destsa, "127.0.0.1", APR_INET, TESTSF_PORT, 0, p);
  +    rv = apr_getaddrinfo(&destsa, "127.0.0.1", family, TESTSF_PORT, 0, p);
       if (rv != APR_SUCCESS) {
           fprintf(stderr, "apr_getaddrinfo()->%d/%s\n",
                   rv,
  @@ -493,26 +508,29 @@
       int i;
       apr_socket_t *newsock = NULL;
       apr_ssize_t bytes_read;
  +    apr_sockaddr_t *localsa;
  +    int family;
   
  -    apr_setup(&p, &sock);
  +    family = APR_UNSPEC;
  +    apr_setup(&p, &sock, &family);
   
  -    rv = apr_set_port(sock, APR_LOCAL, TESTSF_PORT);
  +    rv = apr_setsocketopt(sock, APR_SO_REUSEADDR, 1);
       if (rv != APR_SUCCESS) {
  -        fprintf(stderr, "apr_set_local_port()->%d/%s\n",
  +        fprintf(stderr, "apr_setsocketopt()->%d/%s\n",
                   rv,
   		apr_strerror(rv, buf, sizeof buf));
           exit(1);
       }
   
  -    rv = apr_setsocketopt(sock, APR_SO_REUSEADDR, 1);
  +    rv = apr_getaddrinfo(&localsa, NULL, family, TESTSF_PORT, 0, p);
       if (rv != APR_SUCCESS) {
  -        fprintf(stderr, "apr_setsocketopt()->%d/%s\n",
  +        fprintf(stderr, "apr_getaddrinfo()->%d/%s\n",
                   rv,
   		apr_strerror(rv, buf, sizeof buf));
           exit(1);
       }
   
  -    rv = apr_bind(sock);
  +    rv = apr_bind(sock, localsa);
       if (rv != APR_SUCCESS) {
           fprintf(stderr, "apr_bind()->%d/%s\n",
                   rv,
  
  
  
  1.37      +13 -2     apache-2.0/src/main/listen.c
  
  Index: listen.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/main/listen.c,v
  retrieving revision 1.36
  retrieving revision 1.37
  diff -u -r1.36 -r1.37
  --- listen.c	2000/11/09 19:38:26	1.36
  +++ listen.c	2000/11/19 14:24:19	1.37
  @@ -85,12 +85,22 @@
       apr_status_t stat;
       apr_port_t port;
       char *ipaddr;
  +    apr_sockaddr_t *localsa;
   
       apr_get_port(&port, APR_LOCAL, s);
       apr_get_ipaddr(&ipaddr, APR_LOCAL, s);
       apr_snprintf(addr, sizeof(addr), "address %s port %u", ipaddr,
   		(unsigned) port);
   
  +    stat = apr_getaddrinfo(&localsa, ipaddr, APR_INET, port, 0, p);
  +    if (stat != APR_SUCCESS) {
  +        ap_log_error(APLOG_MARK, APLOG_CRIT, stat, NULL,
  +                     "make_sock: for %s/%hu, apr_getaddrinfo() failed", 
  +                     ipaddr, port);
  +        apr_close_socket(s);
  +        return stat;
  +    }
  +
       stat = apr_setsocketopt(s, APR_SO_REUSEADDR, one);
       if (stat != APR_SUCCESS && stat != APR_ENOTIMPL) {
   	ap_log_error(APLOG_MARK, APLOG_CRIT, stat, NULL,
  @@ -140,7 +150,7 @@
       ap_sock_disable_nagle(s);
   #endif
   
  -    if ((stat = apr_bind(s)) != APR_SUCCESS) {
  +    if ((stat = apr_bind(s, localsa)) != APR_SUCCESS) {
   	ap_log_error(APLOG_MARK, APLOG_CRIT, stat, NULL,
   	    "make_sock: could not bind to %s", addr);
   	apr_close_socket(s);
  @@ -197,7 +207,8 @@
       /* this has to survive restarts */
       new = apr_palloc(process->pool, sizeof(ap_listen_rec));
       new->active = 0;
  -    if ((status = apr_create_tcp_socket(&new->sd, process->pool)) != APR_SUCCESS)
{
  +    if ((status = apr_create_socket(&new->sd, APR_INET, SOCK_STREAM, 
  +                                    process->pool)) != APR_SUCCESS) {
           ap_log_error(APLOG_MARK, APLOG_CRIT, status, NULL,
                    "make_sock: failed to get a socket for %s", addr);
           return;
  
  
  
  1.32      +12 -5     apache-2.0/src/main/rfc1413.c
  
  Index: rfc1413.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/main/rfc1413.c,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- rfc1413.c	2000/11/18 16:04:06	1.31
  +++ rfc1413.c	2000/11/19 14:24:19	1.32
  @@ -119,7 +119,7 @@
       char *cp;
       char buffer[RFC1413_MAXDATA + 1];
       int buflen;
  -    apr_sockaddr_t *destsa;
  +    apr_sockaddr_t *localsa, *destsa;
   
       /*
        * Bind the local and remote ends of the query socket to the same
  @@ -130,10 +130,16 @@
        * addresses from the query socket.
        */
   
  -    apr_set_port(sock, APR_LOCAL, ANY_PORT);
  -    apr_set_ipaddr(sock, APR_LOCAL, local_ip);
  +    if ((status = apr_getaddrinfo(&localsa, local_ip, APR_INET, 0, 0, p)) 
  +        != APR_SUCCESS) {
  +        /* This should not fail since we have a numeric address string
  +         * as the host. */
  +        ap_log_error(APLOG_MARK, APLOG_CRIT, status, srv,
  +                     "rfc1413: apr_getaddrinfo() failed");
  +        return -1;
  +    }
   
  -    if ((status = apr_bind(sock)) != APR_SUCCESS) {
  +    if ((status = apr_bind(sock, localsa)) != APR_SUCCESS) {
   	ap_log_error(APLOG_MARK, APLOG_CRIT, status, srv,
   		    "bind: rfc1413: Error binding to local port");
   	return -1;
  @@ -235,7 +241,8 @@
   
       result = FROM_UNKNOWN;
   
  -    if ((status = apr_create_tcp_socket(&sock, conn->pool)) != APR_SUCCESS) {
  +    if ((status = apr_create_socket(&sock, APR_INET, SOCK_STREAM, 
  +                                    conn->pool)) != APR_SUCCESS) {
   	ap_log_error(APLOG_MARK, APLOG_CRIT, status, srv,
   		    "socket: rfc1413: error creating socket");
   	conn->remote_logname = result;
  
  
  
  1.24      +13 -6     apache-2.0/src/modules/proxy/proxy_ftp.c
  
  Index: proxy_ftp.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/modules/proxy/proxy_ftp.c,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- proxy_ftp.c	2000/11/16 01:57:46	1.23
  +++ proxy_ftp.c	2000/11/19 14:24:20	1.24
  @@ -486,6 +486,7 @@
       (proxy_server_conf *) ap_get_module_config(sconf, &proxy_module);
       struct noproxy_entry *npent = (struct noproxy_entry *) conf->noproxies->elts;
       struct nocache_entry *ncent = (struct nocache_entry *) conf->nocaches->elts;
  +    apr_sockaddr_t *localsa;
   
   /* stuff for PASV mode */
       unsigned int presult, h0, h1, h2, h3, p0, p1;
  @@ -566,7 +567,7 @@
       if (parms != NULL)
   	*(parms++) = '\0';
   
  -    if ((apr_create_tcp_socket(&sock, r->pool)) != APR_SUCCESS) {
  +    if ((apr_create_socket(&sock, APR_INET, SOCK_STREAM, r->pool)) != APR_SUCCESS)
{
           ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
                         "proxy: error creating socket");
           return HTTP_INTERNAL_SERVER_ERROR;
  @@ -787,7 +788,7 @@
       }
   
   /* try to set up PASV data connection first */
  -    if ((apr_create_tcp_socket(&dsock, r->pool)) != APR_SUCCESS) {
  +    if ((apr_create_socket(&dsock, APR_INET, SOCK_STREAM, r->pool)) != APR_SUCCESS)
{
   	ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
   		     "proxy: error creating PASV socket");
   	ap_bclose(f);
  @@ -865,7 +866,7 @@
       }
   
       if (!pasvmode) {		/* set up data connection */
  -	if ((apr_create_tcp_socket(&dsock, r->pool)) != APR_SUCCESS) {
  +	if ((apr_create_socket(&dsock, APR_INET, SOCK_STREAM, r->pool)) != APR_SUCCESS)
{
   	    ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
   			 "proxy: error creating socket");
   	    ap_bclose(f);
  @@ -873,8 +874,6 @@
   	}
           apr_get_port(&npport, APR_LOCAL, sock);
           apr_get_ipaddr(&npaddr, APR_LOCAL, sock);
  -        apr_set_port(dsock, APR_LOCAL, npport);
  -        apr_set_ipaddr(dsock, APR_LOCAL, npaddr);
   
   	if (apr_setsocketopt(dsock, APR_SO_REUSEADDR, one) != APR_SUCCESS) {
   #ifndef _OSD_POSIX /* BS2000 has this option "always on" */
  @@ -886,7 +885,15 @@
   #endif /*_OSD_POSIX*/
   	}
   
  -	if (apr_bind(dsock) != APR_SUCCESS) {
  +        if (apr_getaddrinfo(&localsa, npaddr, APR_INET, npport, 0, r->pool) 
  +            != APR_SUCCESS) {
  +            ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
  +                          "proxy: error creating local socket address");
  +            ap_bclose(f);
  +            return HTTP_INTERNAL_SERVER_ERROR;
  +        }
  +
  +	if (apr_bind(dsock, localsa) != APR_SUCCESS) {
   	    char buff[22];
   
   	    apr_snprintf(buff, sizeof(buff), "%s:%d", npaddr, npport);
  
  
  

Mime
View raw message