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) |
---|
-
src/client.c
diff -ru src/client.c src/client.c
134 134 135 135 static size_t try_read_from_server PROTO ((char *, size_t)); 136 136 137 static void proxy_connect PROTO ((cvsroot_t *, int)); 137 138 static void auth_server PROTO ((cvsroot_t *, struct buffer *, struct buffer *, 138 139 int, int, struct hostent *)); 139 140 … … 3884 3885 int port_number; 3885 3886 struct sockaddr_in client_sai; 3886 3887 struct hostent *hostinfo; 3887 struct buffer * to_server, *from_server;3888 struct buffer *local_to_server, *local_from_server; 3888 3889 3889 3890 sock = socket (AF_INET, SOCK_STREAM, 0); 3890 3891 if (sock == -1) … … 3892 3893 error (1, 0, "cannot create socket: %s", SOCK_STRERROR (SOCK_ERRNO)); 3893 3894 } 3894 3895 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 3896 3907 if (trace) 3897 3908 { 3898 3909 fprintf (stderr, " -> Connecting to %s(%s):%d\n", … … 3902 3913 if (connect (sock, (struct sockaddr *) &client_sai, sizeof (client_sai)) 3903 3914 < 0) 3904 3915 error (1, 0, "connect to %s(%s):%d failed: %s", 3905 root-> hostname,3916 root->proxy ? root->proxy : root->hostname, 3906 3917 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)); 3908 3920 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); 3910 3922 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); 3912 3935 3913 3936 if (verify_only) 3914 3937 { 3915 3938 int status; 3916 3939 3917 status = buf_shutdown ( to_server);3940 status = buf_shutdown (local_to_server); 3918 3941 if (status != 0) 3919 3942 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; 3922 3945 3923 status = buf_shutdown ( from_server);3946 status = buf_shutdown (local_from_server); 3924 3947 if (status != 0) 3925 3948 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; 3928 3951 3929 3952 /* Don't need to set server_started = 0 since we don't set it to 1 3930 3953 * until returning from this call. … … 3932 3955 } 3933 3956 else 3934 3957 { 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; 3937 3960 } 3938 3961 3939 3962 return; … … 3942 3965 3943 3966 3944 3967 static void 3968 proxy_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 4007 static void 3945 4008 auth_server (root, lto_server, lfrom_server, verify_only, do_gssapi, hostinfo) 3946 4009 cvsroot_t *root; 3947 4010 struct buffer *lto_server; -
src/client.h
diff -ru src/client.h src/client.h
67 67 # ifndef CVS_AUTH_PORT 68 68 # define CVS_AUTH_PORT 2401 69 69 # endif /* CVS_AUTH_PORT */ 70 # ifndef CVS_PROXY_PORT 71 # define CVS_PROXY_PORT 80 72 # endif /* CVS_PROXY_PORT */ 70 73 # endif /* AUTH_CLIENT_SUPPORT */ 71 74 72 75 # if HAVE_KERBEROS -
src/root.c
diff -ru src/root.c src/root.c
295 295 #ifdef CLIENT_SUPPORT 296 296 newroot->isremote = 0; 297 297 #endif /* CLIENT_SUPPORT */ 298 newroot->proxy = NULL; 299 newroot->proxy_port = CVS_PROXY_PORT; 298 300 299 301 return newroot; 300 302 } … … 320 322 free (root->hostname); 321 323 if (root->directory != NULL) 322 324 free (root->directory); 325 if (root->proxy != NULL) 326 free (root->proxy); 323 327 free (root); 324 328 } 325 329 … … 361 365 */ 362 366 char *cvsroot_copy, *p, *q; /* temporary pointers for parsing */ 363 367 int check_hostname, no_port, no_password; 368 const char *env_var; 364 369 365 370 /* allocate some space */ 366 371 newroot = new_cvsroot_t(); … … 514 519 /* restore the '/' */ 515 520 cvsroot_copy = firstslash; 516 521 *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 } 517 544 } 518 545 519 546 /* parse the path for all methods */ -
src/root.h
diff -ru src/root.h src/root.h
34 34 #ifdef CLIENT_SUPPORT 35 35 unsigned char isremote; /* nonzero if we are doing remote access */ 36 36 #endif /* CLIENT_SUPPORT */ 37 char *proxy; 38 int proxy_port; 37 39 } cvsroot_t;