diff -ruN httptunnel-3.0.5/htc.c httptunnel-3.0.5-DR/htc.c --- httptunnel-3.0.5/htc.c Thu Aug 31 11:43:40 2000 +++ httptunnel-3.0.5-DR/htc.c Tue Oct 25 12:58:02 2005 @@ -23,6 +23,7 @@ typedef struct { + char *cgi; char *me; char *device; char *host_name; @@ -37,6 +38,7 @@ int keep_alive; int max_connection_age; char *proxy_authorization; + char *authorization; char *user_agent; } Arguments; @@ -55,6 +57,7 @@ "When a connection is made, I/O is redirected from the source specified\n" "by the --device or --forward-port switch to the tunnel.\n" "\n" +" -a, --authorization USER:PASSWORD HTTP Basic authorization\n" " -A, --proxy-authorization USER:PASSWORD proxy authorization\n" " --proxy-authorization-file FILE proxy authorization file\n" " -B, --proxy-buffer-size BYTES assume a proxy buffer size of BYTES bytes\n" @@ -75,6 +78,7 @@ " -M, --max-connection-age SEC maximum time a connection will stay\n" " open is SEC seconds (default is %d)\n" " -P, --proxy HOSTNAME[:PORT] use a HTTP proxy (default port is %d)\n" +" -C, --cgi /path/to/cgi use a HTTP cgi-bin proxy\n" " -S, --strict-content-length always write Content-Length bytes in requests\n" " -T, --timeout TIME timeout, in milliseconds, before sending\n" " padding to a buffering proxy\n" @@ -109,6 +113,7 @@ /* defaults */ + arg->cgi = NULL; arg->me = argv[0]; arg->device = NULL; arg->forward_port = -1; @@ -123,6 +128,7 @@ arg->keep_alive = DEFAULT_KEEP_ALIVE; arg->max_connection_age = DEFAULT_CONNECTION_MAX_TIME; arg->proxy_authorization = NULL; + arg->authorization = NULL; arg->user_agent = NULL; for (;;) @@ -141,17 +147,19 @@ { "timeout", required_argument, 0, 'T' }, { "keep-alive", required_argument, 0, 'k' }, { "user-agent", required_argument, 0, 'U' }, + { "cgi", required_argument, 0, 'C' }, { "forward-port", required_argument, 0, 'F' }, { "content-length", required_argument, 0, 'c' }, { "strict-content-length", no_argument, 0, 'S' }, { "proxy-buffer-size", required_argument, 0, 'B' }, { "proxy-authorization", required_argument, 0, 'A' }, + { "authorization", required_argument, 0, 'a' }, { "max-connection-age", required_argument, 0, 'M' }, { "proxy-authorization-file", required_argument, 0, 'z' }, { 0, 0, 0, 0 } }; - static const char *short_options = "A:B:c:d:F:hk:M:P:ST:U:Vz:" + static const char *short_options = "a:A:B:c:C:d:F:hk:M:P:ST:U:Vz:" #ifdef DEBUG_MODE "D:l:" #endif @@ -175,6 +183,10 @@ arg->proxy_authorization = optarg; break; + case 'a': + arg->authorization = optarg; + break; + case 'B': arg->proxy_buffer_size = atoi_with_postfix (optarg); break; @@ -229,6 +241,10 @@ if (arg->proxy_buffer_timeout == -1) arg->proxy_buffer_timeout = DEFAULT_PROXY_BUFFER_TIMEOUT; break; + + case 'C': + arg->cgi = optarg; + break; case 'S': arg->strict_content_length = TRUE; @@ -411,7 +427,10 @@ log_notice (" keep_alive = %d", arg.keep_alive); log_notice (" proxy_authorization = %s", arg.proxy_authorization ? arg.proxy_authorization : "(null)"); + log_notice (" authorization = %s", + arg.authorization ? arg.authorization : "(null)"); log_notice (" user_agent = %s", arg.user_agent ? arg.user_agent : "(null)"); + log_notice (" cgi = %s", arg.cgi ? arg.cgi : "(null)"); log_notice (" debug_level = %d", debug_level); @@ -484,6 +503,42 @@ log_debug ("tunnel_setopt max_connection_age error: %s", strerror (errno)); + if (arg.authorization != NULL) + { + ssize_t len; + char *auth; + + len = encode_base64 (arg.authorization, + strlen (arg.authorization), + &auth); + if (len == -1) + { + log_error ("encode_base64 error: %s", strerror (errno)); + } + else + { + char *str = malloc (len + 7); + + if (str == NULL) + { + log_error ("out of memory when encoding " + "authorization string"); + log_exit (1); + } + + strcpy (str, "Basic "); + strcat (str, auth); + free (auth); + + if (tunnel_setopt (tunnel, "authorization", str) == -1) + log_error ("tunnel_setopt authorization error: %s", + strerror (errno)); + + free (str); + } + } + + if (arg.proxy_authorization != NULL) { ssize_t len; @@ -526,6 +581,13 @@ strerror (errno)); } + if (arg.cgi != NULL) + { + if (tunnel_setopt (tunnel, "cgi", arg.cgi) == -1) + log_error ("tunnel_setopt cgi error: %s", + strerror (errno)); + } + if (tunnel_connect (tunnel) == -1) { log_error ("couldn't open tunnel: %s", strerror (errno)); diff -ruN httptunnel-3.0.5/hts.c httptunnel-3.0.5-DR/hts.c --- httptunnel-3.0.5/hts.c Thu Aug 31 11:43:40 2000 +++ httptunnel-3.0.5-DR/hts.c Tue Oct 25 12:21:11 2005 @@ -22,6 +22,7 @@ char *device; int port; char *forward_host; + int cgi; int forward_port; size_t content_length; char *pid_filename; @@ -50,6 +51,7 @@ #endif " -F, --forward-port HOST:PORT connect to PORT at HOST and use it for \n" " input and output\n" +" -C, --cgi CGI mode (don't send HTTP status code)\n" " -h, --help display this help and exit\n" " -k, --keep-alive SECONDS send keepalive bytes every SECONDS seconds\n" " (default is %d)\n" @@ -79,6 +81,7 @@ arg->device = NULL; arg->forward_host = NULL; arg->forward_port = -1; + arg->cgi = 0; arg->content_length = DEFAULT_CONTENT_LENGTH; arg->pid_filename = NULL; arg->strict_content_length = FALSE; @@ -101,12 +104,13 @@ { "pid-file", required_argument, 0, 'p' }, { "keep-alive", required_argument, 0, 'k' }, { "forward-port", required_argument, 0, 'F' }, + { "cgi", no_argument, 0, 'C' }, { "content-length", required_argument, 0, 'c' }, { "max-connection-age", required_argument, 0, 'M' }, { 0, 0, 0, 0 } }; - static const char *short_options = "c:d:F:hk:M:p:SV" + static const char *short_options = "Cc:d:F:hk:M:p:SV" #ifdef DEBUG_MODE "D:l:" #endif @@ -164,6 +168,10 @@ } break; + case 'C': + arg->cgi = 1; + break; + case 'h': usage (stdout, arg->me); exit (0); @@ -263,6 +271,7 @@ log_notice (" device = %s", arg.device ? arg.device : "(null)"); log_notice (" port = %d", arg.port); log_notice (" forward_port = %d", arg.forward_port); + log_notice (" cgi = %d", arg.cgi); log_notice (" forward_host = %s", arg.forward_host ? arg.forward_host : "(null)"); log_notice (" content_length = %d", arg.content_length); @@ -277,6 +286,16 @@ log_exit (1); } + + if (arg.cgi) + { + if (tunnel_setopt (tunnel, "cgi", "C") == -1) + { + log_error ("tunnel_setopt cgi error: %s", + strerror (errno)); + } + } + if (tunnel_setopt (tunnel, "strict_content_length", &arg.strict_content_length) == -1) log_debug ("tunnel_setopt strict_content_length error: %s", diff -ruN httptunnel-3.0.5/http.c httptunnel-3.0.5-DR/http.c --- httptunnel-3.0.5/http.c Tue Jul 11 11:37:48 2000 +++ httptunnel-3.0.5-DR/http.c Tue Oct 25 09:37:50 2005 @@ -4,6 +4,9 @@ bug alert: parse_header() doesn't handle header fields that are extended over multiple lines. + +Modified by David ROBERT david@ombrepixel.com to support CGI + */ #include @@ -31,7 +34,13 @@ n = 0; if (dest->proxy_name != NULL) n = sprintf (str, "http://%s:%d", dest->host_name, dest->host_port); - sprintf (str + n, "/index.html?crap=%ld", time (NULL)); + if (dest->cgi != NULL) + { + sprintf (str + n, "%s", dest->cgi); + } else + { + sprintf (str + n, "/index.html?crap=%ld", time (NULL)); + } request = http_create_request (method, str, 1, 1); if (request == NULL) @@ -55,6 +64,13 @@ dest->proxy_authorization); } + if (dest->authorization) + { + http_add_header (&request->header, + "Authorization", + dest->authorization); + } + if (dest->user_agent) { http_add_header (&request->header, diff -ruN httptunnel-3.0.5/http.h httptunnel-3.0.5-DR/http.h --- httptunnel-3.0.5/http.h Tue May 18 19:12:47 1999 +++ httptunnel-3.0.5-DR/http.h Tue Oct 25 09:47:50 2005 @@ -51,8 +51,10 @@ int host_port; const char *proxy_name; int proxy_port; + const char *authorization; const char *proxy_authorization; const char *user_agent; + const char *cgi; } Http_destination; extern ssize_t http_get (int fd, Http_destination *dest); diff -ruN httptunnel-3.0.5/tunnel.c httptunnel-3.0.5-DR/tunnel.c --- httptunnel-3.0.5/tunnel.c Thu Sep 14 12:27:27 2000 +++ httptunnel-3.0.5-DR/tunnel.c Tue Oct 25 12:53:51 2005 @@ -1160,18 +1160,17 @@ if (tunnel->out_fd == -1) { char str[1024]; + ssize_t offset = 0; tunnel->out_fd = s; tunnel_out_setsockopts (tunnel->out_fd); + if ( tunnel->dest.cgi == NULL ) + { + offset = sprintf(str, "HTTP/1.1 200 OK\r\n"); + } - sprintf (str, -"HTTP/1.1 200 OK\r\n" -/* "Date: %s\r\n" */ -/* "Server: %s\r\n" */ -/* "Last-Modified: %s\r\n" */ -/* "ETag: %s\r\n" */ -/* "Accept-Ranges: %s\r\n" */ + sprintf (str + offset, "Content-Length: %d\r\n" "Connection: close\r\n" "Pragma: no-cache\r\n" @@ -1179,8 +1178,8 @@ "Expires: 0\r\n" /* FIXME: "0" is not a legitimate HTTP date. */ "Content-Type: text/html\r\n" "\r\n", - /* +1 to allow for TUNNEL_DISCONNECT */ - tunnel->content_length + 1); + /* +1 to allow for TUNNEL_DISCONNECT */ + tunnel->content_length + 1); if (write_all (tunnel->out_fd, str, strlen (str)) <= 0) { log_error ("tunnel_accept: couldn't write GET header: %s", @@ -1373,6 +1372,24 @@ else tunnel->max_connection_age = *(int *)data; } + else if (strcmp (opt, "authorization") == 0) + { + if (get_flag) + { + if (tunnel->dest.authorization == NULL) + *(char **)data = NULL; + else + *(char **)data = strdup (tunnel->dest.authorization); + } + else + { + if (tunnel->dest.authorization != NULL) + free ((char *)tunnel->dest.authorization); + tunnel->dest.authorization = strdup ((char *)data); + if (tunnel->dest.authorization == NULL) + return -1; + } + } else if (strcmp (opt, "proxy_authorization") == 0) { if (get_flag) @@ -1409,6 +1426,24 @@ return -1; } } + else if (strcmp (opt, "cgi") == 0) + { + if (get_flag) + { + if (tunnel->dest.cgi == NULL) + *(char **)data = NULL; + else + *(char **)data = strdup (tunnel->dest.cgi); + } + else + { + if (tunnel->dest.cgi != NULL) + free ((char *)tunnel->dest.cgi); + tunnel->dest.cgi = strdup ((char *)data); + if (tunnel->dest.cgi == NULL) + return -1; + } + } else { errno = EINVAL;