]> source.dussan.org Git - tigervnc.git/commitdiff
Force common flow of connection queries
authorPierre Ossman <ossman@cendio.se>
Fri, 5 Oct 2018 14:59:22 +0000 (16:59 +0200)
committerPierre Ossman <ossman@cendio.se>
Tue, 9 Oct 2018 15:22:17 +0000 (17:22 +0200)
Force queryConnection() to always call back to approveConnection()
rather than return special values. This makes the flow easier to
follow as it will be the same in all cases.

common/rfb/VNCSConnectionST.cxx
common/rfb/VNCSConnectionST.h
common/rfb/VNCServerST.h
unix/x0vncserver/x0vncserver.cxx
unix/xserver/hw/vnc/XserverDesktop.cc
unix/xserver/hw/vnc/XserverDesktop.h
win/winvnc/VNCServerWin32.cxx
win/winvnc/VNCServerWin32.h

index f1591f4c2939f4c7d7e3731c2edbf2c05aeb90e9..cfefcca1bb4e4e2fcfbf3c067e7fbdaaffb602d6 100644 (file)
@@ -457,16 +457,7 @@ void VNCSConnectionST::queryConnection(const char* userName)
   }
 
   // - Get the server to display an Accept/Reject dialog, if required
-  //   If a dialog is displayed, the result will be PENDING, and the
-  //   server will call approveConnection at a later time
-  CharArray reason;
-  VNCServerST::queryResult qr = server->queryConnection(sock, userName,
-                                                        &reason.buf);
-  if (qr == VNCServerST::PENDING)
-    return;
-
-  // - If server returns ACCEPT/REJECT then pass result to SConnection
-  approveConnection(qr == VNCServerST::ACCEPT, reason.buf);
+  server->queryConnection(sock, userName);
 }
 
 void VNCSConnectionST::clientInit(bool shared)
index dfc8bcb58e61778787813a2735a51833b53ac52d..faa0479317daf78cbcee7ba73b286424934d7014 100644 (file)
@@ -78,6 +78,7 @@ namespace rfb {
     void serverCutTextOrClose(const char *str, int len);
     void setDesktopNameOrClose(const char *name);
     void setLEDStateOrClose(unsigned int state);
+    void approveConnectionOrClose(bool accept, const char* reason);
 
     // checkIdleTimeout() returns the number of milliseconds left until the
     // idle timeout expires.  If it has expired, the connection is closed and
@@ -110,14 +111,6 @@ namespace rfb {
 
     const char* getPeerEndpoint() const {return peerEndpoint.buf;}
 
-    // approveConnectionOrClose() is called some time after
-    // VNCServerST::queryConnection() has returned with PENDING to accept or
-    // reject the connection.  The accept argument should be true for
-    // acceptance, or false for rejection, in which case a string reason may
-    // also be given.
-
-    void approveConnectionOrClose(bool accept, const char* reason);
-
     char* getStartTime();
 
     void setStatus(int status);
index b7845ddd0595d79e67cdeaf0ddd9a80ccb4e38a5..30a9c9ff4e7e6480016832869db90e2e0b7ae083 100644 (file)
@@ -133,19 +133,13 @@ namespace rfb {
     //
     // queryConnection() is called when a connection has been
     // successfully authenticated.  The sock and userName arguments identify
-    // the socket and the name of the authenticated user, if any.  It should
-    // return ACCEPT if the connection should be accepted, REJECT if it should
-    // be rejected, or PENDING if a decision cannot yet be reached.  If REJECT
-    // is returned, *reason can be set to a string describing the reason - this
-    // will be delete[]ed when it is finished with.  If PENDING is returned,
+    // the socket and the name of the authenticated user, if any.
     // approveConnection() must be called some time later to accept or reject
     // the connection.
-    enum queryResult { ACCEPT, REJECT, PENDING };
     struct QueryConnectionHandler {
       virtual ~QueryConnectionHandler() {}
-      virtual queryResult queryConnection(network::Socket* sock,
-                                          const char* userName,
-                                          char** reason) = 0;
+      virtual void queryConnection(network::Socket* sock,
+                                   const char* userName) = 0;
     };
     void setQueryConnectionHandler(QueryConnectionHandler* qch) {
       queryConnectionHandler = qch;
@@ -154,12 +148,13 @@ namespace rfb {
     // queryConnection is called as described above, and either passes the
     // request on to the registered handler, or accepts the connection if
     // no handler has been specified.
-    virtual queryResult queryConnection(network::Socket* sock,
-                                        const char* userName,
-                                        char** reason) {
-      return queryConnectionHandler
-        ? queryConnectionHandler->queryConnection(sock, userName, reason)
-        : ACCEPT;
+    virtual void queryConnection(network::Socket* sock,
+                                 const char* userName) {
+      if (queryConnectionHandler) {
+        queryConnectionHandler->queryConnection(sock, userName);
+        return;
+      }
+      approveConnection(sock, true, NULL);
     }
 
     // approveConnection() is called by the active QueryConnectionHandler,
index c08572be7b956a7794090a7a082b4f60613eacf3..9b84ca29c6bf4c37b549e924154b25e08775fa1a 100644 (file)
@@ -87,12 +87,11 @@ public:
   ~QueryConnHandler() { delete queryConnectDialog; }
 
   // -=- VNCServerST::QueryConnectionHandler interface
-  virtual VNCServerST::queryResult queryConnection(network::Socket* sock,
-                                                   const char* userName,
-                                                   char** reason) {
+  virtual void queryConnection(network::Socket* sock,
+                               const char* userName) {
     if (queryConnectSock) {
-      *reason = strDup("Another connection is currently being queried.");
-      return VNCServerST::REJECT;
+      server->approveConnection(sock, false, "Another connection is currently being queried.");
+      return;
     }
     if (!userName) userName = "(anonymous)";
     queryConnectSock = sock;
@@ -102,7 +101,6 @@ public:
                                                 userName, queryConnectTimeout,
                                                 this);
     queryConnectDialog->map();
-    return VNCServerST::PENDING;
   }
 
   // -=- QueryResultCallback interface
index 04107dcb2410211a68ccb7c929060a63f03ef0ca..89b55e69caa8812f7db5da817dfa10dd6c6a5a19 100644 (file)
@@ -145,22 +145,20 @@ void XserverDesktop::refreshScreenLayout()
   server->setScreenLayout(::computeScreenLayout(&outputIdMap));
 }
 
-rfb::VNCServerST::queryResult
-XserverDesktop::queryConnection(network::Socket* sock,
-                                const char* userName,
-                                char** reason)
+void XserverDesktop::queryConnection(network::Socket* sock,
+                                     const char* userName)
 {
   int count;
 
   if (queryConnectTimer.isStarted()) {
-    *reason = strDup("Another connection is currently being queried.");
-    return rfb::VNCServerST::REJECT;
+    server->approveConnection(sock, false, "Another connection is currently being queried.");
+    return;
   }
 
   count = vncNotifyQueryConnect();
   if (count == 0) {
-    *reason = strDup("Unable to query the local user to accept the connection.");
-    return rfb::VNCServerST::REJECT;
+    server->approveConnection(sock, false, "Unable to query the local user to accept the connection.");
+    return;
   }
 
   queryConnectAddress.replaceBuf(sock->getPeerAddress());
@@ -171,8 +169,6 @@ XserverDesktop::queryConnection(network::Socket* sock,
   queryConnectSocket = sock;
 
   queryConnectTimer.start(queryConnectTimeout * 1000);
-
-  return rfb::VNCServerST::PENDING;
 }
 
 void XserverDesktop::bell()
index 014fcb5f533371c0ebe738f59f203d732e7f8ba9..6ea6104fcb5777c1473acc733843ef6a436d962d 100644 (file)
@@ -96,9 +96,8 @@ public:
   virtual void grabRegion(const rfb::Region& r);
 
   // rfb::VNCServerST::QueryConnectionHandler callback
-  virtual rfb::VNCServerST::queryResult queryConnection(network::Socket* sock,
-                                                        const char* userName,
-                                                        char** reason);
+  virtual void queryConnection(network::Socket* sock,
+                               const char* userName);
 
 protected:
   bool handleListenerEvent(int fd,
index 9f6a954da0926b2dfe0e0e8c2f366599a7b4b190..93bf5c0ab8e40bb7832e6f8b17bb5f93b2d3dc73 100644 (file)
@@ -249,19 +249,19 @@ bool VNCServerWin32::setClientsStatus(rfb::ListConnInfo* LCInfo) {
   return queueCommand(SetClientsStatus, LCInfo, 0);
 }
 
-VNCServerST::queryResult VNCServerWin32::queryConnection(network::Socket* sock,
-                                            const char* userName,
-                                            char** reason)
+void VNCServerWin32::queryConnection(network::Socket* sock,
+                                     const char* userName)
 {
-  if (queryOnlyIfLoggedOn && CurrentUserToken().noUserLoggedOn())
-    return VNCServerST::ACCEPT;
+  if (queryOnlyIfLoggedOn && CurrentUserToken().noUserLoggedOn()) {
+    vncServer.approveConnection(sock, true, NULL);
+    return;
+  }
   if (queryConnectDialog) {
-    *reason = rfb::strDup("Another connection is currently being queried.");
-    return VNCServerST::REJECT;
+    vncServer.approveConnection(sock, false, "Another connection is currently being queried.");
+    return;
   }
   queryConnectDialog = new QueryConnectDialog(sock, userName, this);
   queryConnectDialog->startDialog();
-  return VNCServerST::PENDING;
 }
 
 void VNCServerWin32::queryConnectionComplete() {
index 271cb76a9926ee9fc09049fdf1a9cf3e7975e09e..58c3f6c6f80f7e5807c1acc7b616545a3f28b250 100644 (file)
@@ -81,9 +81,8 @@ namespace winvnc {
     // VNCServerST::QueryConnectionHandler interface
     // Callback used to prompt user to accept or reject a connection.
     // CALLBACK IN VNCServerST "HOST" THREAD
-    virtual rfb::VNCServerST::queryResult queryConnection(network::Socket* sock,
-                                                          const char* userName,
-                                                          char** reason);
+    virtual void queryConnection(network::Socket* sock,
+                                 const char* userName);
 
     // SocketManager::AddressChangeNotifier interface
     // Used to keep tray icon up to date