The attached patch is intended to allow xrdp to be told to bind only to a single IP address and not to all ip addresses on the local host.

Again part of my attempts for rdp to rdp proxy.

Lawrence
Index: common/os_calls.c
===================================================================
--- common/os_calls.c   (revision 3807)
+++ common/os_calls.c   (working copy)
@@ -425,12 +425,23 @@
 int APP_CC
 g_tcp_bind(int sck, char* port)
 {
+  return g_tcp_bind_address(sck, port, "0.0.0.0");
+}
+
+/*****************************************************************************/
+/* returns error, zero is good */
+int APP_CC
+g_tcp_bind_address(int sck, char* port, const char *address)
+{
   struct sockaddr_in s;
 
   memset(&s, 0, sizeof(struct sockaddr_in));
   s.sin_family = AF_INET;
   s.sin_port = htons((tui16)atoi(port));
-  s.sin_addr.s_addr = INADDR_ANY;
+  if ( inet_aton(address, &s.sin_addr) < 0 )
+  {
+    return -1;  // bad address
+  }
   return bind(sck, (struct sockaddr*)&s, sizeof(struct sockaddr_in));
 }
 
Index: common/os_calls.h
===================================================================
--- common/os_calls.h   (revision 3807)
+++ common/os_calls.h   (working copy)
@@ -72,6 +72,8 @@
 int APP_CC
 g_tcp_set_non_blocking(int sck);
 int APP_CC
+g_tcp_bind_address(int sck, char* port, const char *address);
+int APP_CC
 g_tcp_bind(int sck, char* port);
 int APP_CC
 g_tcp_local_bind(int sck, char* port);
Index: common/trans.c
===================================================================
--- common/trans.c      (revision 3807)
+++ common/trans.c      (working copy)
@@ -342,7 +342,7 @@
 
 /*****************************************************************************/
 int APP_CC
-trans_listen(struct trans* self, char* port)
+trans_listen_address(struct trans* self, char* port, char* address)
 {
   if (self->sck != 0)
   {
@@ -352,7 +352,7 @@
   {
     self->sck = g_tcp_socket();
     g_tcp_set_non_blocking(self->sck);
-    if (g_tcp_bind(self->sck, port) == 0)
+    if (g_tcp_bind_address(self->sck, port, address) == 0)
     {
       if (g_tcp_listen(self->sck) == 0)
       {
@@ -383,6 +383,12 @@
   }
   return 1;
 }
+/*****************************************************************************/
+int APP_CC
+trans_listen(struct trans* self, char* port)
+{
+    return trans_listen_address(self,port,"0.0.0.0");
+}
 
 /*****************************************************************************/
 struct stream* APP_CC
Index: common/trans.h
===================================================================
--- common/trans.h      (revision 3807)
+++ common/trans.h      (working copy)
@@ -80,6 +80,8 @@
               int timeout);
 int APP_CC
 trans_listen(struct trans* self, char* port);
+int APP_CC
+trans_listen_address(struct trans* self, char* port, char* address);
 struct stream* APP_CC
 trans_get_in_s(struct trans* self);
 struct stream* APP_CC
Index: xrdp/xrdp_listen.c
===================================================================
--- xrdp/xrdp_listen.c  (revision 3809)
+++ xrdp/xrdp_listen.c  (working copy)
@@ -119,7 +119,7 @@
 
 /*****************************************************************************/
 static int
-xrdp_listen_get_port(char* port, int port_bytes)
+xrdp_listen_get_port_address(char* port, int port_bytes, char* address, int 
address_bytes )
 {
   int fd;
   int error;
@@ -131,6 +131,8 @@
 
   /* default to port 3389 */
   g_strncpy(port, "3389", port_bytes - 1);
+  /* Default to all */
+  g_strncpy(address, "0.0.0.0", address_bytes - 1);
   /* see if port is in xrdp.ini file */
   file_config_name("xrdp.ini", cfg_file, 255);
   fd = g_file_open(cfg_file);
@@ -155,8 +157,16 @@
             {
               g_strncpy(port, val, port_bytes - 1);
             }
-            break;
           }
+          if (g_strcasecmp(val, "address") == 0)
+          {
+            val = (char*)list_get_item(values, index);
+            error = g_atoi(val);
+            if ((error > 0) && (error < 65000))
+            {
+              g_strncpy(address, val, address_bytes - 1);
+            }
+          }
         }
       }
     }
@@ -203,6 +213,7 @@
   int cont;
   int timeout;
   char port[8];
+  char address[256];
   tbus robjs[8];
   tbus term_obj;
   tbus sync_obj;
@@ -210,13 +221,13 @@
   tbus done_obj;
 
   self->status = 1;
-  if (xrdp_listen_get_port(port, sizeof(port)) != 0)
+  if (xrdp_listen_get_port_address(port, sizeof(port), address, 
sizeof(address)) != 0)
   {
     g_writeln("xrdp_listen_main_loop: xrdp_listen_get_port failed");
     self->status = -1;
     return 1;
   }
-  error = trans_listen(self->listen_trans, port);
+  error = trans_listen_address(self->listen_trans, port,address);
   if (error == 0)
   {
     self->listen_trans->trans_conn_in = xrdp_listen_conn_in;
------------------------------------------------------------------------------
Beautiful is writing same markup. Internet Explorer 9 supports
standards for HTML5, CSS3, SVG 1.1,  ECMAScript5, and DOM L2 & L3.
Spend less time writing and  rewriting code and more time creating great
experiences on the web. Be a part of the beta today.
http://p.sf.net/sfu/beautyoftheweb
_______________________________________________
xrdp-devel mailing list
xrdp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/xrdp-devel

Reply via email to