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

File cvs-proxy-1.11.17-1.patch, 6.5 KB (added by hallow@…, 19 years ago)

patch for cvs-proxy-1.11.17-1

  • src/client.c

    old new  
    144144
    145145static size_t try_read_from_server PROTO ((char *, size_t));
    146146
     147static void proxy_connect PROTO ((cvsroot_t *, int));
    147148static void auth_server PROTO ((cvsroot_t *, struct buffer *, struct buffer *,
    148149                                int, int, struct hostent *));
    149150
     
    37623763    int port_number;
    37633764    struct sockaddr_in client_sai;
    37643765    struct hostent *hostinfo;
    3765     struct buffer *to_server, *from_server;
     3766    struct buffer *local_to_server, *local_from_server;
    37663767
    37673768    sock = socket (AF_INET, SOCK_STREAM, 0);
    37683769    if (sock == -1)
     
    37703771        error (1, 0, "cannot create socket: %s", SOCK_STRERROR (SOCK_ERRNO));
    37713772    }
    37723773    port_number = get_cvs_port_number (root);
     3774
     3775    /* if we have a proxy connect to that instead */
     3776    if(root->proxy)
     3777    {
     3778      hostinfo = init_sockaddr (&client_sai, root->proxy, root->proxy_port);
     3779    }
     3780    else
     3781    {
    37733782    hostinfo = init_sockaddr (&client_sai, root->hostname, port_number);
     3783    }
     3784   
    37743785    if (trace)
    37753786    {
    37763787        fprintf (stderr, " -> Connecting to %s(%s):%d\n",
     
    37803791    if (connect (sock, (struct sockaddr *) &client_sai, sizeof (client_sai))
    37813792        < 0)
    37823793        error (1, 0, "connect to %s(%s):%d failed: %s",
    3783                root->hostname,
     3794               root->proxy ? root->proxy : root->hostname,
    37843795               inet_ntoa (client_sai.sin_addr),
    3785                port_number, SOCK_STRERROR (SOCK_ERRNO));
     3796               root->proxy ? root->proxy_port : port_number,
     3797               SOCK_STRERROR (SOCK_ERRNO));
    37863798
    3787     make_bufs_from_fds (sock, sock, 0, &to_server, &from_server, 1);
     3799    make_bufs_from_fds (sock, sock, 0, &local_to_server, &local_from_server, 1);
    37883800
    3789     auth_server (root, to_server, from_server, verify_only, do_gssapi, hostinfo);
     3801    if(root->proxy)
     3802    {
     3803      // REALLY ugly hack to allow proxy_connect() to use send_to_server().
     3804      // The proper fix would be to remove the global to_server & from_server
     3805      // variables, and instead let send_to_server() etc. take the target
     3806      // server struct as a paramter.
     3807      to_server = local_to_server;
     3808      from_server = local_from_server;
     3809      proxy_connect (root, port_number);
     3810   }
     3811
     3812    auth_server (root, local_to_server, local_from_server, verify_only, do_gssapi, hostinfo);
    37903813
    37913814    if (verify_only)
    37923815    {
    37933816        int status;
    37943817
    3795         status = buf_shutdown (to_server);
     3818        status = buf_shutdown (local_to_server);
    37963819        if (status != 0)
    37973820            error (0, status, "shutting down buffer to server");
    3798         buf_free (to_server);
    3799         to_server = NULL;
     3821        buf_free (local_to_server);
     3822        local_to_server = NULL;
    38003823
    3801         status = buf_shutdown (from_server);
     3824        status = buf_shutdown (local_from_server);
    38023825        if (status != 0)
    38033826            error (0, status, "shutting down buffer from server");
    3804         buf_free (from_server);
    3805         from_server = NULL;
     3827        buf_free (local_from_server);
     3828        local_from_server = NULL;
    38063829
    38073830        /* Don't need to set server_started = 0 since we don't set it to 1
    38083831         * until returning from this call.
     
    38103833    }
    38113834    else
    38123835    {
    3813         *to_server_p = to_server;
    3814         *from_server_p = from_server;
     3836        *to_server_p = local_to_server;
     3837        *from_server_p = local_from_server;
    38153838    }
    38163839
    38173840    return;
     3841}
     3842
     3843
     3844
     3845static void
     3846proxy_connect (root, port_number)
     3847    cvsroot_t *root;
     3848    int port_number;
     3849{
     3850#define CONNECT_STRING "CONNECT %s:%d HTTP/1.0\r\n\r\n"
     3851    /* Send a "CONNECT" command to proxy: */
     3852    char* read_buf;
     3853    int codenum, count;
     3854   
     3855    /* 4 characters for port covered by the length of %s & %d */
     3856    char* write_buf = xmalloc (strlen (CONNECT_STRING) + strlen (root->hostname
     3857) + 20 + 1);
     3858    int len = sprintf (write_buf, CONNECT_STRING, root->hostname, port_number);
     3859
     3860    send_to_server (write_buf, len);
     3861   
     3862    /* Wait for HTTP status code, bail out if you don't get back a 2xx code.*/
     3863    count = read_line (&read_buf);
     3864    sscanf (read_buf, "%s %d", write_buf, &codenum);
     3865   
     3866    if ((codenum / 100) != 2)
     3867       error (1, 0, "proxy server %s:%d does not support http tunnelling",
     3868              root->proxy, root->proxy_port);
     3869    free (read_buf);
     3870    free (write_buf);
     3871   
     3872    /* Skip through remaining part of MIME header, recv_line
     3873       consumes the trailing \n */
     3874    while(read_line (&read_buf) > 0)
     3875    {
     3876       if (read_buf[0] == '\r' || read_buf[0] == 0)
     3877       {
     3878           free (read_buf);
     3879           break;
     3880       }
     3881       free (read_buf);
     3882    }
    38183883}
    38193884
    38203885
  • src/client.h

    old new  
    6969#   ifndef CVS_AUTH_PORT
    7070#     define CVS_AUTH_PORT 2401
    7171#   endif /* CVS_AUTH_PORT */
     72#   ifndef CVS_PROXY_PORT
     73#     define CVS_PROXY_PORT 80
     74#   endif /* CVS_PROXY_PORT */
    7275# endif /* (AUTH_CLIENT_SUPPORT) || defined (HAVE_GSSAPI) */
    7376
    7477# if HAVE_KERBEROS
  • src/root.c

    old new  
    303303    newroot->proxy_port = 0;
    304304    newroot->isremote = 0;
    305305#endif /* CLIENT_SUPPORT */
     306    newroot->proxy = NULL;
     307    newroot->proxy_port = CVS_PROXY_PORT;
    306308
    307309    return newroot;
    308310}
     
    332334    if (root->proxy_hostname != NULL)
    333335        free (root->proxy_hostname);
    334336#endif /* CLIENT_SUPPORT */
     337    if (root->proxy != NULL)
     338        free (root->proxy);
    335339    free (root);
    336340}
    337341
     
    375379#ifdef CLIENT_SUPPORT
    376380    int check_hostname, no_port, no_password;
    377381#endif /* CLIENT_SUPPORT */
     382    const char *env_var;
    378383
    379384    /* allocate some space */
    380385    newroot = new_cvsroot_t();
     
    555560        /* restore the '/' */
    556561        cvsroot_copy = firstslash;
    557562        *cvsroot_copy = '/';
     563
     564       
     565       /* Determine proxy */
     566       env_var = getenv("CVS_PROXY");
     567       if (!env_var)
     568           env_var = getenv("HTTP_PROXY");
     569       /* Check if a proxy was specified, and if it is a HTTP proxy */
     570       if (env_var && !memcmp(env_var, "http://", 7))
     571       {
     572           char *port_str;
     573           
     574           /* Try to parse the proxy data */
     575           env_var += 7;
     576           /* TODO - parse username/password data, too */
     577           port_str = strchr(env_var, ':');
     578           if (port_str)
     579           {
     580               *port_str++ = 0;
     581               newroot->proxy_port = atoi(port_str);
     582           }
     583           newroot->proxy = xstrdup(env_var);
     584       }
     585
    558586#endif /* CLIENT_SUPPORT */
    559587    }
    560588
  • src/root.h

    old new  
    3939    int proxy_port;             /* The port of the proxy or zero, as above. */
    4040    unsigned char isremote;     /* Nonzero if we are doing remote access. */
    4141#endif /* CLIENT_SUPPORT */
     42    char *proxy;       
    4243} cvsroot_t;