Ticket #2340: cvs-proxy-1.11.5-1.patch

File cvs-proxy-1.11.5-1.patch, 6.7 KB (added by hallow@…, 20 years ago)

patch for cvs-proxy-1.11.5-1

  • src/client.c

    diff -ru src/client.c src/client.c
     
    134134
    135135static size_t try_read_from_server PROTO ((char *, size_t));
    136136
     137static void proxy_connect PROTO ((cvsroot_t *, int));
    137138static void auth_server PROTO ((cvsroot_t *, struct buffer *, struct buffer *,
    138139                                int, int, struct hostent *));
    139140
     
    38843885    int port_number;
    38853886    struct sockaddr_in client_sai;
    38863887    struct hostent *hostinfo;
    3887     struct buffer *to_server, *from_server;
     3888    struct buffer *local_to_server, *local_from_server;
    38883889
    38893890    sock = socket (AF_INET, SOCK_STREAM, 0);
    38903891    if (sock == -1)
     
    38923893        error (1, 0, "cannot create socket: %s", SOCK_STRERROR (SOCK_ERRNO));
    38933894    }
    38943895    port_number = get_cvs_port_number (root);
    3895     hostinfo = init_sockaddr (&client_sai, root->hostname, port_number);
     3896
     3897    /* if we have a proxy connect to that instead */
     3898    if (root->proxy)
     3899    {
     3900        hostinfo = init_sockaddr (&client_sai, root->proxy, root->proxy_port);
     3901    }
     3902    else
     3903    {
     3904        hostinfo = init_sockaddr (&client_sai, root->hostname, port_number);
     3905    }
     3906
    38963907    if (trace)
    38973908    {
    38983909        fprintf (stderr, " -> Connecting to %s(%s):%d\n",
     
    39023913    if (connect (sock, (struct sockaddr *) &client_sai, sizeof (client_sai))
    39033914        < 0)
    39043915        error (1, 0, "connect to %s(%s):%d failed: %s",
    3905                root->hostname,
     3916               root->proxy ? root->proxy : root->hostname,
    39063917               inet_ntoa (client_sai.sin_addr),
    3907                port_number, SOCK_STRERROR (SOCK_ERRNO));
     3918               root->proxy ? root->proxy_port : port_number,
     3919               SOCK_STRERROR (SOCK_ERRNO));
    39083920
    3909     make_bufs_from_fds (sock, sock, 0, &to_server, &from_server, 1);
     3921    make_bufs_from_fds (sock, sock, 0, &local_to_server, &local_from_server, 1);
    39103922
    3911     auth_server (root, to_server, from_server, verify_only, do_gssapi, hostinfo);
     3923    if (root->proxy)
     3924    {
     3925        // REALLY ugly hack to allow proxy_connect() to use send_to_server().
     3926        // The proper fix would be to remove the global to_server & from_server
     3927        // variables, and instead let send_to_server() etc. take the target
     3928        // server struct as a paramter.
     3929        to_server = local_to_server;
     3930        from_server = local_from_server;
     3931        proxy_connect (root, port_number);
     3932    }
     3933
     3934    auth_server (root, local_to_server, local_from_server, verify_only, do_gssapi, hostinfo);
    39123935
    39133936    if (verify_only)
    39143937    {
    39153938        int status;
    39163939
    3917         status = buf_shutdown (to_server);
     3940        status = buf_shutdown (local_to_server);
    39183941        if (status != 0)
    39193942            error (0, status, "shutting down buffer to server");
    3920         buf_free (to_server);
    3921         to_server = NULL;
     3943        buf_free (local_to_server);
     3944        local_to_server = NULL;
    39223945
    3923         status = buf_shutdown (from_server);
     3946        status = buf_shutdown (local_from_server);
    39243947        if (status != 0)
    39253948            error (0, status, "shutting down buffer from server");
    3926         buf_free (from_server);
    3927         from_server = NULL;
     3949        buf_free (local_from_server);
     3950        local_from_server = NULL;
    39283951
    39293952        /* Don't need to set server_started = 0 since we don't set it to 1
    39303953         * until returning from this call.
     
    39323955    }
    39333956    else
    39343957    {
    3935         *to_server_p = to_server;
    3936         *from_server_p = from_server;
     3958        *to_server_p = local_to_server;
     3959        *from_server_p = local_from_server;
    39373960    }
    39383961
    39393962    return;
     
    39423965
    39433966
    39443967static void
     3968proxy_connect (root, port_number)
     3969    cvsroot_t *root;
     3970    int port_number;
     3971{
     3972#define CONNECT_STRING "CONNECT %s:%d HTTP/1.0\r\n\r\n"
     3973    /* Send a "CONNECT" command to proxy: */
     3974    char* read_buf;
     3975    int codenum, count;
     3976   
     3977    /* 4 characters for port covered by the length of %s & %d */
     3978    char* write_buf = xmalloc (strlen (CONNECT_STRING) + strlen (root->hostname) + 20 + 1);
     3979    int len = sprintf (write_buf, CONNECT_STRING, root->hostname, port_number);
     3980    send_to_server (write_buf, len);
     3981   
     3982    /* Wait for HTTP status code, bail out if you don't get back a 2xx code.*/
     3983    count = read_line (&read_buf);
     3984    sscanf (read_buf, "%s %d", write_buf, &codenum);
     3985   
     3986    if ((codenum / 100) != 2)
     3987        error (1, 0, "proxy server %s:%d does not support http tunnelling",
     3988               root->proxy, root->proxy_port);
     3989    free (read_buf);
     3990    free (write_buf);
     3991   
     3992    /* Skip through remaining part of MIME header, recv_line
     3993       consumes the trailing \n */
     3994    while(read_line (&read_buf) > 0)
     3995    {
     3996        if (read_buf[0] == '\r' || read_buf[0] == 0)
     3997        {
     3998            free (read_buf);
     3999            break;
     4000        }
     4001        free (read_buf);
     4002    }
     4003}
     4004
     4005
     4006
     4007static void
    39454008auth_server (root, lto_server, lfrom_server, verify_only, do_gssapi, hostinfo)
    39464009    cvsroot_t *root;
    39474010    struct buffer *lto_server;
  • src/client.h

    diff -ru src/client.h src/client.h
     
    6767#   ifndef CVS_AUTH_PORT
    6868#     define CVS_AUTH_PORT 2401
    6969#   endif /* CVS_AUTH_PORT */
     70#   ifndef CVS_PROXY_PORT
     71#     define CVS_PROXY_PORT 80
     72#   endif /* CVS_PROXY_PORT */
    7073# endif /* AUTH_CLIENT_SUPPORT */
    7174
    7275# if HAVE_KERBEROS
  • src/root.c

    diff -ru src/root.c src/root.c
     
    295295#ifdef CLIENT_SUPPORT
    296296    newroot->isremote = 0;
    297297#endif /* CLIENT_SUPPORT */
     298    newroot->proxy = NULL;
     299    newroot->proxy_port = CVS_PROXY_PORT;
    298300
    299301    return newroot;
    300302}
     
    320322        free (root->hostname);
    321323    if (root->directory != NULL)
    322324        free (root->directory);
     325    if (root->proxy != NULL)
     326        free (root->proxy);
    323327    free (root);
    324328}
    325329
     
    361365                                         */
    362366    char *cvsroot_copy, *p, *q;         /* temporary pointers for parsing */
    363367    int check_hostname, no_port, no_password;
     368    const char *env_var;
    364369
    365370    /* allocate some space */
    366371    newroot = new_cvsroot_t();
     
    514519        /* restore the '/' */
    515520        cvsroot_copy = firstslash;
    516521        *cvsroot_copy = '/';
     522
     523       
     524        /* Determine proxy */
     525        env_var = getenv("CVS_PROXY");
     526        if (!env_var)
     527            env_var = getenv("HTTP_PROXY");
     528        /* Check if a proxy was specified, and if it is a HTTP proxy */
     529        if (env_var && !memcmp(env_var, "http://", 7))
     530        {
     531            char *port_str;
     532           
     533            /* Try to parse the proxy data */
     534            env_var += 7;
     535            /* TODO - parse username/password data, too */
     536            port_str = strchr(env_var, ':');
     537            if (port_str)
     538            {
     539                *port_str++ = 0;
     540                newroot->proxy_port = atoi(port_str);
     541            }
     542            newroot->proxy = xstrdup(env_var);
     543        }
    517544    }
    518545
    519546    /* parse the path for all methods */
  • src/root.h

    diff -ru src/root.h src/root.h
     
    3434#ifdef CLIENT_SUPPORT
    3535    unsigned char isremote;     /* nonzero if we are doing remote access */
    3636#endif /* CLIENT_SUPPORT */
     37        char *proxy;
     38        int proxy_port;
    3739} cvsroot_t;