Hi I would like to add support for tunneling over a socks connection.
This is a first draft to show how it could be used.
I have not done any work (yet) on argument passing since this needs to
be discussed how it should look.

This is only tested on OSX but should work fine on any unix.
Might work on windows but I doubt it (how to get username there?).
Rest of it should work there to.

Usage steps:

first start ssh like this

ssh -D 1234 relay_host
or in putty configure a "dynamic" ssh forwarding

next
in bash:
RDPDEST=realdest RDPPORT=3389 xfreerdp localhost:1234

tcsh
env RDPDEST=realdest RDPPORT=3389 xfreerdp rdpoptions localhost:1234

where realdest is the rdpserver you want to reach
RDPPORT the port on the rdp server defaults to 3389
localhost where the socks4 server is, in this case localhost
1234 the socks port

Now your rdp session will go via a sshtunnel and hopefully be on right
side of firewall rules.


Patch attached this only affects tcp.c in libfreerdp

Bengt-Arne Fjellner
Luleå University of Technology



--- tcp.c.org   2011-04-18 21:37:01.000000000 +0200
+++ tcp.c       2011-04-19 12:38:47.000000000 +0200
@@ -27,6 +27,7 @@
 #include <arpa/inet.h>         /* inet_addr */
 #include <errno.h>             /* errno */
 #include <fcntl.h>             /* fcntl F_GETFL F_SETFL O_NONBLOCK */
+#include <pwd.h>               /* getpwuid (socks4) */
 #endif
 
 #include <freerdp/utils.h>
@@ -264,6 +265,52 @@
        return s;
 }
 
+/* initialize socks4 connection */
+static int
+init_socks4(rdpTcp * tcp,int sock,char *server,int port)
+{
+       struct hostent *nslookup;
+       struct sockaddr_in servaddr;
+       char buff[100] = {4,1,0};
+       struct passwd *pwent = getpwuid(getuid());
+       strcpy(buff+8,pwent->pw_name);
+
+       printf("connecting socks4 to %s:%d\n", server, port);
+
+       if ((nslookup = gethostbyname(server)) != NULL)
+       {
+               memcpy(&servaddr.sin_addr, nslookup->h_addr, 
sizeof(servaddr.sin_addr));
+       }
+               else if ((servaddr.sin_addr.s_addr = inet_addr(server)) == 
INADDR_NONE)
+       {
+               ui_error(tcp->iso->mcs->sec->rdp->inst, "%s: unable to resolve 
host\n", server);
+               return False;
+       }
+       /*
+       socks 4 definition from wikipedia: http://en.wikipedia.org/wiki/SOCKS
+          send:
+          4,1,port,ip,user id,0
+
+          return value:
+          0,0x5a,skip 6 more bytes
+       */
+       *(int *)(buff+2) = htons((uint16) port);
+       memcpy((int *)(buff+4), nslookup->h_addr, sizeof(servaddr.sin_addr));
+       int i=0;
+       int messlen=strlen(buff+8)+9;
+
+       printf("socks4 message to send ");
+       for(;i<messlen;i++){
+         printf("0x%02x ",*((unsigned char *)buff+i));
+       }
+       printf("\n");
+       send(sock, buff, messlen,0);
+       recv(sock, buff, 8,0);
+       printf("OK if 0x5a %x\n",buff[1]); // should be 5a if OK
+       return 0;
+
+}
+
 /* Establish a connection on the TCP layer */
 RD_BOOL
 tcp_connect(rdpTcp * tcp, char * server, int port)
@@ -349,6 +396,14 @@
 
 #endif /* IPv6 */
 
+       char *rdpdest = getenv("RDPDEST");
+       char *rdpport = getenv("RDPPORT");
+       if(rdpdest){
+               int rdpnum = 3389;
+               if(rdpport)
+                       rdpnum = atoi(rdpport);
+               init_socks4(tcp,sock,rdpdest,rdpnum);
+       }
        tcp->sock = sock;
 
        /* set socket as non blocking */
------------------------------------------------------------------------------
Benefiting from Server Virtualization: Beyond Initial Workload 
Consolidation -- Increasing the use of server virtualization is a top
priority.Virtualization can reduce costs, simplify management, and improve 
application availability and disaster protection. Learn more about boosting 
the value of server virtualization. http://p.sf.net/sfu/vmware-sfdev2dev
_______________________________________________
Freerdp-devel mailing list
Freerdp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/freerdp-devel

Reply via email to