]> source.dussan.org Git - tigervnc.git/commitdiff
Move the AccessRights type and constants to the rfb namespace
authorCarlos Santos <casantos@redhat.com>
Tue, 28 Nov 2023 21:11:13 +0000 (18:11 -0300)
committerCarlos Santos <casantos@redhat.com>
Tue, 23 Apr 2024 20:41:01 +0000 (17:41 -0300)
They must belong to the rfb namespace, not to the SConnection class.

Also add an AccessNone constant, since it's better to use a mnemonic
symbol rather than zero to initialize the accessRights members.

Signed-off-by: Carlos Santos <casantos@redhat.com>
17 files changed:
common/rfb/AccessRights.cxx [new file with mode: 0644]
common/rfb/AccessRights.h [new file with mode: 0644]
common/rfb/CMakeLists.txt
common/rfb/SConnection.cxx
common/rfb/SConnection.h
common/rfb/SSecurity.h
common/rfb/SSecurityRSAAES.cxx
common/rfb/SSecurityRSAAES.h
common/rfb/SSecurityStack.cxx
common/rfb/SSecurityStack.h
common/rfb/SSecurityVeNCrypt.cxx
common/rfb/SSecurityVeNCrypt.h
common/rfb/SSecurityVncAuth.cxx
common/rfb/SSecurityVncAuth.h
common/rfb/VNCServerST.cxx
tests/perf/encperf.cxx
win/winvnc/VNCServerWin32.cxx

diff --git a/common/rfb/AccessRights.cxx b/common/rfb/AccessRights.cxx
new file mode 100644 (file)
index 0000000..65e6ce2
--- /dev/null
@@ -0,0 +1,36 @@
+/* Copyright 2024 TigerVNC Team
+ *
+ * This is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this software; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
+ * USA.
+ */
+
+#include "AccessRights.h"
+
+namespace rfb
+{
+
+  // AccessRights values
+  const AccessRights AccessNone           = 0x0000;
+  const AccessRights AccessView           = 0x0001;
+  const AccessRights AccessKeyEvents      = 0x0002;
+  const AccessRights AccessPtrEvents      = 0x0004;
+  const AccessRights AccessCutText        = 0x0008;
+  const AccessRights AccessSetDesktopSize = 0x0010;
+  const AccessRights AccessNonShared      = 0x0020;
+  const AccessRights AccessDefault        = 0x03ff;
+  const AccessRights AccessNoQuery        = 0x0400;
+  const AccessRights AccessFull           = 0xffff;
+
+} /* namespace rfb */
diff --git a/common/rfb/AccessRights.h b/common/rfb/AccessRights.h
new file mode 100644 (file)
index 0000000..adf4393
--- /dev/null
@@ -0,0 +1,41 @@
+/* Copyright 2024 TigerVNC Team
+ *
+ * This is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this software; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
+ * USA.
+ */
+
+#ifndef COMMON_RFB_ACCESSRIGHTS_H_
+#define COMMON_RFB_ACCESSRIGHTS_H_
+
+#include <stdint.h>
+
+namespace rfb
+{
+
+  typedef uint16_t AccessRights;
+  extern const AccessRights AccessNone;           // No rights at all
+  extern const AccessRights AccessView;           // View display contents
+  extern const AccessRights AccessKeyEvents;      // Send key events
+  extern const AccessRights AccessPtrEvents;      // Send pointer events
+  extern const AccessRights AccessCutText;        // Send/receive clipboard events
+  extern const AccessRights AccessSetDesktopSize; // Change desktop size
+  extern const AccessRights AccessNonShared;      // Exclusive access to the server
+  extern const AccessRights AccessDefault;        // The default rights, INCLUDING FUTURE ONES
+  extern const AccessRights AccessNoQuery;        // Connect without local user accepting
+  extern const AccessRights AccessFull;           // All of the available AND FUTURE rights
+
+} /* namespace rfb */
+
+#endif /* COMMON_RFB_ACCESSRIGHTS_H_ */
index 2cae2356c84f5224d028232d5f4e0fe9efed38d7..360434a9f1b4ba11b2b86805339a2e14d065585b 100644 (file)
@@ -1,4 +1,5 @@
 add_library(rfb STATIC
+  AccessRights.cxx
   Blacklist.cxx
   Congestion.cxx
   CConnection.cxx
index 33b2d850e601fa315a79d391956c622e5aac9b71..462c34c2e6813282402d38ecd223f2ce98aac468 100644 (file)
@@ -43,24 +43,12 @@ using namespace rfb;
 
 static LogWriter vlog("SConnection");
 
-// AccessRights values
-const SConnection::AccessRights SConnection::AccessView           = 0x0001;
-const SConnection::AccessRights SConnection::AccessKeyEvents      = 0x0002;
-const SConnection::AccessRights SConnection::AccessPtrEvents      = 0x0004;
-const SConnection::AccessRights SConnection::AccessCutText        = 0x0008;
-const SConnection::AccessRights SConnection::AccessSetDesktopSize = 0x0010;
-const SConnection::AccessRights SConnection::AccessNonShared      = 0x0020;
-const SConnection::AccessRights SConnection::AccessDefault        = 0x03ff;
-const SConnection::AccessRights SConnection::AccessNoQuery        = 0x0400;
-const SConnection::AccessRights SConnection::AccessFull           = 0xffff;
-
-
 SConnection::SConnection()
   : readyForSetColourMapEntries(false),
     is(0), os(0), reader_(0), writer_(0), ssecurity(0),
     authFailureTimer(this, &SConnection::handleAuthFailureTimeout),
     state_(RFBSTATE_UNINITIALISED), preferredEncoding(encodingRaw),
-    accessRights(0x0000), hasRemoteClipboard(false),
+    accessRights(AccessNone), hasRemoteClipboard(false),
     hasLocalClipboard(false),
     unsolicitedClipboardAttempt(false)
 {
index b163d6273edb3cb6abf49f438874e02d303153e6..fb8b0b4cb08222f9b04364fd0d4be295201544d8 100644 (file)
@@ -29,6 +29,7 @@
 #include <rdr/InStream.h>
 #include <rdr/OutStream.h>
 
+#include <rfb/AccessRights.h>
 #include <rfb/SMsgHandler.h>
 #include <rfb/SecurityServer.h>
 #include <rfb/Timer.h>
@@ -178,17 +179,6 @@ namespace rfb {
     // setAccessRights() allows a security package to limit the access rights
     // of a SConnection to the server.  How the access rights are treated
     // is up to the derived class.
-
-    typedef uint16_t AccessRights;
-    static const AccessRights AccessView;           // View display contents
-    static const AccessRights AccessKeyEvents;      // Send key events
-    static const AccessRights AccessPtrEvents;      // Send pointer events
-    static const AccessRights AccessCutText;        // Send/receive clipboard events
-    static const AccessRights AccessSetDesktopSize; // Change desktop size
-    static const AccessRights AccessNonShared;      // Exclusive access to the server
-    static const AccessRights AccessDefault;        // The default rights, INCLUDING FUTURE ONES
-    static const AccessRights AccessNoQuery;        // Connect without local user accepting
-    static const AccessRights AccessFull;           // All of the available AND FUTURE rights
     virtual void setAccessRights(AccessRights ar);
     virtual bool accessCheck(AccessRights ar) const;
 
index fbc3de6f97e1ce361ac32fff62788589a8612d68..8e296c5ac91ca0d70eff0cb84c81863b2a78043c 100644 (file)
@@ -62,7 +62,7 @@ namespace rfb {
     // for this security type.
     virtual const char* getUserName() const = 0;
 
-    virtual SConnection::AccessRights getAccessRights() const { return SConnection::AccessDefault; }
+    virtual AccessRights getAccessRights() const { return AccessDefault; }
 
   protected:
     SConnection* sc;
index 2a8dfa3eb7b406dc62b2d22f7227448ead551831..cea62644119e3439c8783fec04f4647106177a48 100644 (file)
@@ -76,7 +76,7 @@ SSecurityRSAAES::SSecurityRSAAES(SConnection* sc, uint32_t _secType,
     keySize(_keySize), isAllEncrypted(_isAllEncrypted), secType(_secType),
     serverKey(), clientKey(),
     serverKeyN(NULL), serverKeyE(NULL), clientKeyN(NULL), clientKeyE(NULL),
-    accessRights(SConnection::AccessDefault),
+    accessRights(AccessDefault),
     rais(NULL), raos(NULL), rawis(NULL), rawos(NULL)
 {
   assert(keySize == 128 || keySize == 256);
@@ -578,12 +578,12 @@ void SSecurityRSAAES::verifyPass()
     throw AuthFailureException("No password configured for VNC Auth");
 
   if (password == passwd) {
-    accessRights = SConnection::AccessDefault;
+    accessRights = AccessDefault;
     return;
   }
 
   if (!passwdReadOnly.empty() && password == passwdReadOnly) {
-    accessRights = SConnection::AccessView;
+    accessRights = AccessView;
     return;
   }
 
index eaeb13a17cfee54ed201446e64bebb89a5a577ee..0c4fc85258137615b3e5d06f56f1d9b951774d2d 100644 (file)
@@ -39,7 +39,7 @@ namespace rfb {
     virtual bool processMsg();
     virtual const char* getUserName() const;
     virtual int getType() const { return secType; }
-    virtual SConnection::AccessRights getAccessRights() const
+    virtual AccessRights getAccessRights() const
     {
       return accessRights;
     }
@@ -82,7 +82,7 @@ namespace rfb {
 
     char username[256];
     char password[256];
-    SConnection::AccessRights accessRights;
+    AccessRights accessRights;
 
     rdr::InStream* rais;
     rdr::OutStream* raos;
index 8b1c2a47b16026185751e3b801086884bcb32ad1..9c0321d421d8e2ac8e414e473ac8a1404774a3e7 100644 (file)
@@ -71,14 +71,14 @@ const char* SSecurityStack::getUserName() const
   return c;
 }
 
-SConnection::AccessRights SSecurityStack::getAccessRights() const
+AccessRights SSecurityStack::getAccessRights() const
 {
-  SConnection::AccessRights accessRights;
+  AccessRights accessRights;
 
   if (!state0 && !state1)
     return SSecurity::getAccessRights();
 
-  accessRights = SConnection::AccessFull;
+  accessRights = AccessFull;
 
   if (state0)
     accessRights &= state0->getAccessRights();
index 8b412bdf733d1091adf76f27d25844819722d88c..cf7b10d0e1d5357470800d044770f306a8886548 100644 (file)
@@ -32,7 +32,7 @@ namespace rfb {
     virtual bool processMsg();
     virtual int getType() const { return type; };
     virtual const char* getUserName() const;
-    virtual SConnection::AccessRights getAccessRights() const;
+    virtual AccessRights getAccessRights() const;
   protected:
     short state;
     SSecurity* state0;
index c126d82fdc9908feb53b86e07434c8bec606b32d..2813f299710bc04ea9f614b18c3301a13e7bcbed 100644 (file)
@@ -180,7 +180,7 @@ const char* SSecurityVeNCrypt::getUserName() const
   return ssecurity->getUserName();
 }
 
-SConnection::AccessRights SSecurityVeNCrypt::getAccessRights() const
+AccessRights SSecurityVeNCrypt::getAccessRights() const
 {
   if (ssecurity == NULL)
     return SSecurity::getAccessRights();
index 86cf420a7f047ae0acc5fe92ff23eea238152b92..91713f890223defed274ffd8c1ba9b106ccf8e4b 100644 (file)
@@ -37,7 +37,7 @@ namespace rfb {
     virtual bool processMsg();
     virtual int getType() const { return chosenType; }
     virtual const char* getUserName() const;
-    virtual SConnection::AccessRights getAccessRights() const;
+    virtual AccessRights getAccessRights() const;
 
   protected:
     SSecurity *ssecurity;
index cbd0ccd2f9a297b07525984b731d150d885bfe09..c1ef1f1c0420959a3037a7663302e9ffc7280b7e 100644 (file)
@@ -54,7 +54,7 @@ VncAuthPasswdParameter SSecurityVncAuth::vncAuthPasswd
 
 SSecurityVncAuth::SSecurityVncAuth(SConnection* sc)
   : SSecurity(sc), sentChallenge(false),
-    pg(&vncAuthPasswd), accessRights(0)
+    pg(&vncAuthPasswd), accessRights(AccessNone)
 {
 }
 
@@ -103,13 +103,13 @@ bool SSecurityVncAuth::processMsg()
     throw AuthFailureException("No password configured for VNC Auth");
 
   if (verifyResponse(passwd.c_str())) {
-    accessRights = SConnection::AccessDefault;
+    accessRights = AccessDefault;
     return true;
   }
 
   if (!passwdReadOnly.empty() &&
       verifyResponse(passwdReadOnly.c_str())) {
-    accessRights = SConnection::AccessView;
+    accessRights = AccessView;
     return true;
   }
 
index 2bd27791f7aeec6f7562d1c2e7e3392422f48c32..7f27b02bfadc53934d57cf18a6d83f98e4fdd4c5 100644 (file)
@@ -55,7 +55,7 @@ namespace rfb {
     virtual bool processMsg();
     virtual int getType() const {return secTypeVncAuth;}
     virtual const char* getUserName() const {return 0;}
-    virtual SConnection::AccessRights getAccessRights() const { return accessRights; }
+    virtual AccessRights getAccessRights() const { return accessRights; }
     static StringParameter vncAuthPasswdFile;
     static VncAuthPasswdParameter vncAuthPasswd;
   private:
@@ -65,7 +65,7 @@ namespace rfb {
     uint8_t response[vncAuthChallengeSize];
     bool sentChallenge;
     VncAuthPasswdGetter* pg;
-    SConnection::AccessRights accessRights;
+    AccessRights accessRights;
   };
 }
 #endif
index 560a0ffadf5bcb7ddaa81b5f4d5454e87ce03cbb..c97b07357526b4a998c724be59d7bd2a35962008 100644 (file)
@@ -680,7 +680,7 @@ void VNCServerST::queryConnection(VNCSConnectionST* client,
   }
 
   // - Does the client have the right to bypass the query?
-  if (client->accessCheck(SConnection::AccessNoQuery))
+  if (client->accessCheck(AccessNoQuery))
   {
     approveConnection(client->getSock(), true, NULL);
     return;
@@ -693,7 +693,7 @@ void VNCServerST::clientReady(VNCSConnectionST* client, bool shared)
 {
   if (!shared) {
     if (rfb::Server::disconnectClients &&
-        client->accessCheck(SConnection::AccessNonShared)) {
+        client->accessCheck(AccessNonShared)) {
       // - Close all the other connected clients
       slog.debug("non-shared connection - closing clients");
       closeClients("Non-shared connection requested", client->getSock());
index 40e3abfc1e642e2ade0b11088176c189164cfecd..55fa386eb155e2c21afb985c0b57db624c223d13 100644 (file)
@@ -134,7 +134,7 @@ public:
 
   void getStats(double&, unsigned long long&, unsigned long long&);
 
-  virtual void setAccessRights(AccessRights ar);
+  virtual void setAccessRights(rfb::AccessRights ar);
 
   virtual void setDesktopSize(int fb_width, int fb_height,
                               const rfb::ScreenSet& layout);
@@ -329,7 +329,7 @@ void SConn::getStats(double& ratio, unsigned long long& bytes,
   manager->getStats(ratio, bytes, rawEquivalent);
 }
 
-void SConn::setAccessRights(AccessRights)
+void SConn::setAccessRights(rfb::AccessRights)
 {
 }
 
index a243d95e19877da420abb1ef1bcb4c288fb7fc18..38b2ef16ede1a46654c449e85e9fbc6e15ddc25f 100644 (file)
@@ -363,11 +363,11 @@ void VNCServerWin32::getConnInfo(ListConnInfo * listConn)
 
     if (!conn->authenticated())
       status = 3;
-    else if (conn->accessCheck(rfb::SConnection::AccessPtrEvents |
-                               rfb::SConnection::AccessKeyEvents |
-                               rfb::SConnection::AccessView))
+    else if (conn->accessCheck(rfb::AccessPtrEvents |
+                               rfb::AccessKeyEvents |
+                               rfb::AccessView))
       status = 0;
-    else if (conn->accessCheck(rfb::SConnection::AccessView))
+    else if (conn->accessCheck(rfb::AccessView))
       status = 1;
     else
       status = 2;
@@ -398,25 +398,25 @@ void VNCServerWin32::setConnStatus(ListConnInfo* listConn)
     if (status == 3) {
       conn->close(0);
     } else {
-      rfb::SConnection::AccessRights ar;
+      rfb::AccessRights ar;
 
-      ar = rfb::SConnection::AccessDefault;
+      ar = rfb::AccessDefault;
 
       switch (status) {
       case 0:
-        ar |= rfb::SConnection::AccessPtrEvents |
-              rfb::SConnection::AccessKeyEvents |
-              rfb::SConnection::AccessView;
+        ar |= rfb::AccessPtrEvents |
+              rfb::AccessKeyEvents |
+              rfb::AccessView;
         break;
       case 1:
-        ar |= rfb::SConnection::AccessView;
-        ar &= ~(rfb::SConnection::AccessPtrEvents |
-                rfb::SConnection::AccessKeyEvents);
+        ar |= rfb::AccessView;
+        ar &= ~(rfb::AccessPtrEvents |
+                rfb::AccessKeyEvents);
         break;
       case 2:
-        ar &= ~(rfb::SConnection::AccessPtrEvents |
-                rfb::SConnection::AccessKeyEvents |
-                rfb::SConnection::AccessView);
+        ar &= ~(rfb::AccessPtrEvents |
+                rfb::AccessKeyEvents |
+                rfb::AccessView);
         break;
       }
       conn->setAccessRights(ar);