Hi,

Found some listener related stuff in init_wm() and also some mis-aligned
 statements.

The list has been very quiet of late. Is anyone else reading / using this?
Shall I bother sending my patches at all?

Cheers
Antoine
diff -urN parti-all-0.0.5-vanilla/xpra/scripts/main.py parti-all-0.0.5-current/xpra/scripts/main.py
--- parti-all-0.0.5-vanilla/xpra/scripts/main.py	2008-11-02 15:29:13.000000000 +0700
+++ parti-all-0.0.5-current/xpra/scripts/main.py	2009-03-19 12:42:15.000000000 +0700
@@ -44,6 +44,9 @@
     parser.add_option("--no-daemon", action="store_false",
                       dest="daemon", default=True,
                       help="Don't daemonize when running as a server")
+    parser.add_option("--bind-tcp", action="store",
+                      dest="bind_tcp", default=None,
+                      help="Enable the TCP socket listener")
     parser.add_option("--remote-xpra", action="store",
                       dest="remote_xpra", default=None, metavar="CMD",
                       help="How to run 'xpra' on the remote host")
@@ -123,11 +126,22 @@
                              stdin=b.fileno(), stdout=b.fileno(),
                              bufsize=0)
         return a, False
-    else:
+    elif display_name.startswith(":"):
         sockdir = DotXpra()
         sock = socket.socket(socket.AF_UNIX)
         sock.connect(sockdir.socket_path(display_name))
         return sock, True
+    elif display_name.startswith("tcp:"):
+        host_spec = display_name[4:]
+        (host, port) = host_spec.split(":", 1)
+        if host == "":
+            host = "127.0.0.1"
+        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+        sock.connect((host, int(port)))
+        return sock, True
+    else:
+        parser.error("unknown format for display name")
+        
 
 def run_client(parser, opts, extra_args):
     from xpra.client import XpraClient
diff -urN parti-all-0.0.5-vanilla/xpra/scripts/server.py parti-all-0.0.5-current/xpra/scripts/server.py
--- parti-all-0.0.5-vanilla/xpra/scripts/server.py	2008-11-02 15:29:13.000000000 +0700
+++ parti-all-0.0.5-current/xpra/scripts/server.py	2009-03-19 12:42:15.000000000 +0700
@@ -8,6 +8,7 @@
 import atexit
 import signal
 import time
+import socket
 
 from xpra.wait_for_x_server import wait_for_x_server
 from xpra.dotxpra import DotXpra
@@ -120,6 +121,24 @@
 """)
     return "".join(script)
 
+def create_tcp_socket(spec):
+    if not spec:
+        return None
+    (host, port) = spec.split(":", 1)
+    if host == "":
+        host = "127.0.0.1"
+    listener = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+    listener.bind((host, int(port)))
+    return listener;
+
+def create_local_ipc_socket(display_name, upgrading):
+    dotxpra = DotXpra()
+    sockpath = dotxpra.server_socket_path(display_name, upgrading)
+    listener = socket.socket(socket.AF_UNIX)
+    listener.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
+    listener.bind(sockpath)
+    return listener;
+
 def run_server(parser, opts, mode, xpra_file, extra_args):
     if len(extra_args) != 1:
         parser.error("need exactly 1 extra argument")
@@ -135,9 +154,6 @@
 
     assert mode in ("start", "upgrade")
     upgrading = (mode == "upgrade")
-    sockdir = DotXpra()
-    sockpath = sockdir.server_socket_path(display_name, upgrading)
-    logpath = sockpath + ".log"
     # This used to be given a display-specific name, but now we give it a
     # single fixed name and if multiple servers are started then the last one
     # will clobber the rest.  This isn't great, but the tradeoff is that it
@@ -146,10 +162,12 @@
     # is running on the remote host.  Might need to revisit this later if
     # people run into problems or autodiscovery turns out to be less useful
     # than expected.
-    scriptpath = os.path.join(sockdir.dir(), "run-xpra")
+    dotxpra = DotXpra()
+    scriptpath = os.path.join(dotxpra.dir(), "run-xpra")
 
     # Daemonize:
     if opts.daemon:
+        logpath = dotxpra.server_socket_path(display_name, upgrading) + ".log"
         # Do some work up front, so any errors don't get lost.
         if os.path.exists(logpath):
             os.unlink(logpath)
@@ -241,16 +259,26 @@
     if xvfb_pid is not None:
         save_pid(xvfb_pid)
 
+    sockets = [create_local_ipc_socket(display_name, upgrading)]
+    tcp_socket = create_tcp_socket(opts.bind_tcp)
+    if tcp_socket:
+        sockets += [tcp_socket]
+
     # This import is delayed because the module depends on gtk:
     import xpra.server
-    app = xpra.server.XpraServer(sockpath, upgrading)
-    def cleanup_socket(self):
-        print "removing socket"
+    app = xpra.server.XpraServer(upgrading, sockets)
+    def cleanup_sockets(self):
+        print "removing socket(s)"
         try:
             os.unlink(sockpath)
         except:
             pass
-    _cleanups.append(cleanup_socket)
+        if tcp_socket:
+            try:
+                tcp_socket.close()
+            except:
+                pass
+    _cleanups.append(cleanup_sockets)
 
     child_reaper = ChildReaper(app, opts.exit_with_children)
     # Always register the child reaper, because even if exit_with_children is
diff -urN parti-all-0.0.5-vanilla/xpra/server.py parti-all-0.0.5-current/xpra/server.py
--- parti-all-0.0.5-vanilla/xpra/server.py	2008-11-02 15:29:13.000000000 +0700
+++ parti-all-0.0.5-current/xpra/server.py	2009-03-19 12:53:52.000000000 +0700
@@ -10,7 +10,6 @@
 import gobject
 import os
 import os.path
-import socket
 import subprocess
 
 from wimpiggy.wm import Wm
@@ -199,7 +198,19 @@
         "wimpiggy-child-map-event": one_arg_signal,
         }
 
-    def __init__(self, socketpath, clobber):
+    def __init__(self, clobber, sockets):
+        self.init_wm(clobber)
+        self.init_keymap()
+        self.init_sockets()
+
+   def init_sockets(self):
+        for socket in sockets:
+            socket.listen(5)
+            gobject.io_add_watch(socket, gobject.IO_IN, self._new_connection, socket)
+        self._protocol = None
+        self._potential_protocols = []
+
+    def init_wm(self, clobber):
         gobject.GObject.__init__(self)
         
         # Do this before creating the Wm object, to avoid clobbering its
@@ -221,9 +232,6 @@
         # Window id 0 is reserved for "not a window"
         self._max_window_id = 1
 
-        self._protocol = None
-        self._potential_protocols = []
-
         for window in self._wm.get_property("windows"):
             self._add_new_window(window)
 
@@ -231,14 +239,8 @@
             if (is_override_redirect(window) and is_mapped(window)):
                 self._add_new_or_window(window)
 
-        self._socketpath = socketpath
-        self._listener = socket.socket(socket.AF_UNIX)
-        self._listener.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
-        self._listener.bind(self._socketpath)
-        self._listener.listen(5)
-        gobject.io_add_watch(self._listener, gobject.IO_IN,
-                             self._new_connection)
 
+    def init_keymap(self):
         self._keymap = gtk.gdk.keymap_get_default()
         self._keymap.connect("keys-changed", self._keys_changed)
         self._keys_changed()
@@ -288,9 +290,9 @@
         gtk.main()
         return self._upgrading
 
-    def _new_connection(self, *args):
+    def _new_connection(self, listener, *args):
         log.info("New connection received")
-        sock, addr = self._listener.accept()
+        sock, addr = listener.accept()
         self._potential_protocols.append(Protocol(sock, self.process_packet))
         return True
 
diff -urN parti-all-0.0.5-vanilla/xpra.1 parti-all-0.0.5-current/xpra.1
--- parti-all-0.0.5-vanilla/xpra.1	2008-11-02 15:29:13.000000000 +0700
+++ parti-all-0.0.5-current/xpra.1	2009-03-19 12:42:15.000000000 +0700
@@ -172,6 +172,14 @@
 prevents that behavior (useful mostly for debugging).
 .SS Options for attach, stop
 .TP
+\fB\-\-bind\-tcp=\fP\fIhost:port\fP
+This enables the TCP socket listener.
+The host portion may be omitted, in which case 127.0.0.1 will be
+used.
+Note that this mode is insecure as any local user may be able to
+attach to this socket.
+.SS Options for start
+.TP
 \fB\-\-remote\-xpra=\fP\fICMD\fP
 When connecting to a remote server over ssh, xpra needs to be able to
 find and run the xpra executable on the remote host.  If this

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
Parti-discuss mailing list
[email protected]
http://lists.partiwm.org/cgi-bin/mailman/listinfo/parti-discuss

Reply via email to