support shared flag in 7.3.1 ClientInit message handler. This fix that vncproxy can not support multiple clients connecting at the same time.

This commit is contained in:
chinshou 2024-12-07 09:23:18 +09:00
parent ea8f9b5109
commit 70a32ad4e0
4 changed files with 21 additions and 12 deletions

View File

@ -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)

View File

@ -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
}

View File

@ -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() {

View File

@ -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()