]> asedeno.scripts.mit.edu Git - PuTTY.git/blobdiff - unix/uxproxy.c
Handle packets with no type byte by returning SSH_MSG_UNIMPLEMENTED.
[PuTTY.git] / unix / uxproxy.c
index f808a67796c66cf3f6c37e99fdd241b788eac582..8c916dc99d7111eb8b898b4b14827555c048c0f5 100644 (file)
@@ -30,8 +30,6 @@ struct Socket_localproxy_tag {
     bufchain pending_output_data;
     bufchain pending_input_data;
     enum { EOF_NO, EOF_PENDING, EOF_SENT } outgoingeof;
-
-    void *privptr;
 };
 
 static int localproxy_select_result(int fd, int event);
@@ -186,18 +184,6 @@ static void sk_localproxy_flush (Socket s)
     /* do nothing */
 }
 
-static void sk_localproxy_set_private_ptr (Socket s, void *ptr)
-{
-    Local_Proxy_Socket ps = (Local_Proxy_Socket) s;
-    ps->privptr = ptr;
-}
-
-static void * sk_localproxy_get_private_ptr (Socket s)
-{
-    Local_Proxy_Socket ps = (Local_Proxy_Socket) s;
-    return ps->privptr;
-}
-
 static void sk_localproxy_set_frozen (Socket s, int is_frozen)
 {
     Local_Proxy_Socket ps = (Local_Proxy_Socket) s;
@@ -244,7 +230,7 @@ static int localproxy_select_result(int fd, int event)
     return 1;
 }
 
-Socket platform_new_connection(SockAddr addr, char *hostname,
+Socket platform_new_connection(SockAddr addr, const char *hostname,
                               int port, int privport,
                               int oobinline, int nodelay, int keepalive,
                               Plug plug, Conf *conf)
@@ -258,20 +244,18 @@ Socket platform_new_connection(SockAddr addr, char *hostname,
        sk_localproxy_write_oob,
        sk_localproxy_write_eof,
        sk_localproxy_flush,
-       sk_localproxy_set_private_ptr,
-       sk_localproxy_get_private_ptr,
        sk_localproxy_set_frozen,
-       sk_localproxy_socket_error
+       sk_localproxy_socket_error,
+        NULL, /* peer_info */
     };
 
     Local_Proxy_Socket ret;
-    int to_cmd_pipe[2], from_cmd_pipe[2], pid;
+    int to_cmd_pipe[2], from_cmd_pipe[2], pid, proxytype;
 
-    if (conf_get_int(conf, CONF_proxy_type) != PROXY_CMD)
+    proxytype = conf_get_int(conf, CONF_proxy_type);
+    if (proxytype != PROXY_CMD && proxytype != PROXY_FUZZ)
        return NULL;
 
-    cmd = format_telnet_command(addr, port, conf);
-
     ret = snew(struct Socket_localproxy_tag);
     ret->fn = &socket_fn_table;
     ret->plug = plug;
@@ -281,45 +265,64 @@ Socket platform_new_connection(SockAddr addr, char *hostname,
     bufchain_init(&ret->pending_input_data);
     bufchain_init(&ret->pending_output_data);
 
-    /*
-     * Create the pipes to the proxy command, and spawn the proxy
-     * command process.
-     */
-    if (pipe(to_cmd_pipe) < 0 ||
-       pipe(from_cmd_pipe) < 0) {
-       ret->error = dupprintf("pipe: %s", strerror(errno));
-        sfree(cmd);
-       return (Socket)ret;
-    }
-    cloexec(to_cmd_pipe[1]);
-    cloexec(from_cmd_pipe[0]);
-
-    pid = fork();
-
-    if (pid < 0) {
-       ret->error = dupprintf("fork: %s", strerror(errno));
-        sfree(cmd);
-       return (Socket)ret;
-    } else if (pid == 0) {
-       close(0);
-       close(1);
-       dup2(to_cmd_pipe[0], 0);
-       dup2(from_cmd_pipe[1], 1);
-       close(to_cmd_pipe[0]);
-       close(from_cmd_pipe[1]);
-       noncloexec(0);
-       noncloexec(1);
-       execl("/bin/sh", "sh", "-c", cmd, (void *)NULL);
-       _exit(255);
-    }
+    if (proxytype == PROXY_CMD) {
+       cmd = format_telnet_command(addr, port, conf);
+
+       /*
+        * Create the pipes to the proxy command, and spawn the proxy
+        * command process.
+        */
+       if (pipe(to_cmd_pipe) < 0 ||
+           pipe(from_cmd_pipe) < 0) {
+           ret->error = dupprintf("pipe: %s", strerror(errno));
+           sfree(cmd);
+           return (Socket)ret;
+       }
+       cloexec(to_cmd_pipe[1]);
+       cloexec(from_cmd_pipe[0]);
+
+       pid = fork();
+
+       if (pid < 0) {
+           ret->error = dupprintf("fork: %s", strerror(errno));
+           sfree(cmd);
+           return (Socket)ret;
+       } else if (pid == 0) {
+           close(0);
+           close(1);
+           dup2(to_cmd_pipe[0], 0);
+           dup2(from_cmd_pipe[1], 1);
+           close(to_cmd_pipe[0]);
+           close(from_cmd_pipe[1]);
+           noncloexec(0);
+           noncloexec(1);
+           execl("/bin/sh", "sh", "-c", cmd, (void *)NULL);
+           _exit(255);
+       }
 
-    sfree(cmd);
+       sfree(cmd);
 
-    close(to_cmd_pipe[0]);
-    close(from_cmd_pipe[1]);
+       close(to_cmd_pipe[0]);
+       close(from_cmd_pipe[1]);
 
-    ret->to_cmd = to_cmd_pipe[1];
-    ret->from_cmd = from_cmd_pipe[0];
+       ret->to_cmd = to_cmd_pipe[1];
+       ret->from_cmd = from_cmd_pipe[0];
+    } else {
+       cmd = format_telnet_command(addr, port, conf);
+       ret->to_cmd = open("/dev/null", O_WRONLY);
+       if (ret->to_cmd == -1) {
+           ret->error = dupprintf("/dev/null: %s", strerror(errno));
+           sfree(cmd);
+           return (Socket)ret;
+       }
+       ret->from_cmd = open(cmd, O_RDONLY);
+       if (ret->from_cmd == -1) {
+           ret->error = dupprintf("%s: %s", cmd, strerror(errno));
+           sfree(cmd);
+           return (Socket)ret;
+       }
+       sfree(cmd);
+    }
 
     if (!localproxy_by_fromfd)
        localproxy_by_fromfd = newtree234(localproxy_fromfd_cmp);