Ticket #2340: cvs-proxy-1.11.17-1.patch
File cvs-proxy-1.11.17-1.patch, 6.5 KB (added by hallow@…, 20 years ago) |
---|
-
src/client.c
old new 144 144 145 145 static size_t try_read_from_server PROTO ((char *, size_t)); 146 146 147 static void proxy_connect PROTO ((cvsroot_t *, int)); 147 148 static void auth_server PROTO ((cvsroot_t *, struct buffer *, struct buffer *, 148 149 int, int, struct hostent *)); 149 150 … … 3762 3763 int port_number; 3763 3764 struct sockaddr_in client_sai; 3764 3765 struct hostent *hostinfo; 3765 struct buffer * to_server, *from_server;3766 struct buffer *local_to_server, *local_from_server; 3766 3767 3767 3768 sock = socket (AF_INET, SOCK_STREAM, 0); 3768 3769 if (sock == -1) … … 3770 3771 error (1, 0, "cannot create socket: %s", SOCK_STRERROR (SOCK_ERRNO)); 3771 3772 } 3772 3773 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 { 3773 3782 hostinfo = init_sockaddr (&client_sai, root->hostname, port_number); 3783 } 3784 3774 3785 if (trace) 3775 3786 { 3776 3787 fprintf (stderr, " -> Connecting to %s(%s):%d\n", … … 3780 3791 if (connect (sock, (struct sockaddr *) &client_sai, sizeof (client_sai)) 3781 3792 < 0) 3782 3793 error (1, 0, "connect to %s(%s):%d failed: %s", 3783 root-> hostname,3794 root->proxy ? root->proxy : root->hostname, 3784 3795 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)); 3786 3798 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); 3788 3800 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); 3790 3813 3791 3814 if (verify_only) 3792 3815 { 3793 3816 int status; 3794 3817 3795 status = buf_shutdown ( to_server);3818 status = buf_shutdown (local_to_server); 3796 3819 if (status != 0) 3797 3820 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; 3800 3823 3801 status = buf_shutdown ( from_server);3824 status = buf_shutdown (local_from_server); 3802 3825 if (status != 0) 3803 3826 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; 3806 3829 3807 3830 /* Don't need to set server_started = 0 since we don't set it to 1 3808 3831 * until returning from this call. … … 3810 3833 } 3811 3834 else 3812 3835 { 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; 3815 3838 } 3816 3839 3817 3840 return; 3841 } 3842 3843 3844 3845 static void 3846 proxy_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 } 3818 3883 } 3819 3884 3820 3885 -
src/client.h
old new 69 69 # ifndef CVS_AUTH_PORT 70 70 # define CVS_AUTH_PORT 2401 71 71 # endif /* CVS_AUTH_PORT */ 72 # ifndef CVS_PROXY_PORT 73 # define CVS_PROXY_PORT 80 74 # endif /* CVS_PROXY_PORT */ 72 75 # endif /* (AUTH_CLIENT_SUPPORT) || defined (HAVE_GSSAPI) */ 73 76 74 77 # if HAVE_KERBEROS -
src/root.c
old new 303 303 newroot->proxy_port = 0; 304 304 newroot->isremote = 0; 305 305 #endif /* CLIENT_SUPPORT */ 306 newroot->proxy = NULL; 307 newroot->proxy_port = CVS_PROXY_PORT; 306 308 307 309 return newroot; 308 310 } … … 332 334 if (root->proxy_hostname != NULL) 333 335 free (root->proxy_hostname); 334 336 #endif /* CLIENT_SUPPORT */ 337 if (root->proxy != NULL) 338 free (root->proxy); 335 339 free (root); 336 340 } 337 341 … … 375 379 #ifdef CLIENT_SUPPORT 376 380 int check_hostname, no_port, no_password; 377 381 #endif /* CLIENT_SUPPORT */ 382 const char *env_var; 378 383 379 384 /* allocate some space */ 380 385 newroot = new_cvsroot_t(); … … 555 560 /* restore the '/' */ 556 561 cvsroot_copy = firstslash; 557 562 *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 558 586 #endif /* CLIENT_SUPPORT */ 559 587 } 560 588 -
src/root.h
old new 39 39 int proxy_port; /* The port of the proxy or zero, as above. */ 40 40 unsigned char isremote; /* Nonzero if we are doing remote access. */ 41 41 #endif /* CLIENT_SUPPORT */ 42 char *proxy; 42 43 } cvsroot_t;