diff --git a/proxy/proxy.go b/proxy/proxy.go index 7651197..11d272a 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -25,7 +25,7 @@ type VncProxy struct { sessionManager *SessionManager } -func (vp *VncProxy) createClientConnection(target string, vncPass string) (*client.ClientConn, error) { +func (vp *VncProxy) createClientConnection(target string, vncPass string, shared bool) (*client.ClientConn, error) { var ( nc net.Conn err error @@ -48,7 +48,7 @@ func (vp *VncProxy) createClientConnection(target string, vncPass string) (*clie clientConn, err := client.NewClientConn(nc, &client.ClientConfig{ Auth: authArr, - Exclusive: true, + Exclusive: !shared, // Use the shared flag from the client }) if err != nil { @@ -100,7 +100,7 @@ func (vp *VncProxy) newServerConnHandler(cfg *server.ServerConfig, sconn *server target = session.TargetHostname + ":" + session.TargetPort } - cconn, err := vp.createClientConnection(target, session.TargetPassword) + cconn, err := vp.createClientConnection(target, session.TargetPassword, sconn.IsShared()) if err != nil { session.Status = SessionStatusError logger.Errorf("Proxy.newServerConnHandler error creating connection: %s", err) diff --git a/server/handlers.go b/server/handlers.go index 03c73e5..51db82f 100644 --- a/server/handlers.go +++ b/server/handlers.go @@ -346,10 +346,7 @@ func ServerClientInitHandler(cfg *ServerConfig, c *ServerConn) error { if err := binary.Read(c, binary.BigEndian, &shared); err != nil { return err } - /* TODO - if shared != 1 { - c.SetShared(false) - } - */ + isShared := (shared & 1) != 0 + c.SetShared(isShared) return nil } diff --git a/server/server-conn.go b/server/server-conn.go index d69b0d4..6f0661c 100644 --- a/server/server-conn.go +++ b/server/server-conn.go @@ -33,6 +33,9 @@ type ServerConn struct { // Width of the frame buffer in pixels, sent to the client. fbWidth uint16 + // Flag indicating if the connection is shared with other clients + shared bool + // The pixel format associated with the connection. This shouldn't // be modified. If you wish to set a new pixel format, use the // SetPixelFormat method. @@ -147,6 +150,14 @@ func (c *ServerConn) SetHeight(h uint16) { c.fbHeight = h } +func (c *ServerConn) SetShared(shared bool) { + c.shared = shared +} + +func (c *ServerConn) IsShared() bool { + return c.shared +} + func (c *ServerConn) handle() error { defer func() { diff --git a/server/server.go b/server/server.go index f90b7d9..1b1d3a2 100644 --- a/server/server.go +++ b/server/server.go @@ -89,6 +89,11 @@ func attachNewServerConn(c io.ReadWriter, cfg *ServerConfig, sessionId string) e return err } + if err := ServerClientInitHandler(cfg, conn); err != nil { + conn.Close() + return err + } + //run the handler for this new incoming connection from a vnc-client //this is done before the init sequence to allow listening to server-init messages (and maybe even interception in the future) err = cfg.NewConnHandler(cfg, conn) @@ -97,10 +102,6 @@ func attachNewServerConn(c io.ReadWriter, cfg *ServerConfig, sessionId string) e return err } - if err := ServerClientInitHandler(cfg, conn); err != nil { - conn.Close() - return err - } if err := ServerServerInitHandler(cfg, conn); err != nil { conn.Close()