Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vncconfig: add option to force view-only remote client connections #1670

Merged
merged 3 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 0 additions & 35 deletions common/network/Socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,41 +111,6 @@ namespace network {
SocketException(const char* text, int err_) : rdr::SystemException(text, err_) {}
};

class SocketServer {
public:
virtual ~SocketServer() {}

// addSocket() tells the server to serve the Socket. The caller
// retains ownership of the Socket - the only way for the server
// to discard a Socket is by calling shutdown() on it.
// outgoing is set to true if the socket was created by connecting out
// to another host, or false if the socket was created by accept()ing
// an incoming connection.
virtual void addSocket(network::Socket* sock, bool outgoing=false) = 0;

// removeSocket() tells the server to stop serving the Socket. The
// caller retains ownership of the Socket - the server must NOT
// delete the Socket! This call is used mainly to cause per-Socket
// resources to be freed.
virtual void removeSocket(network::Socket* sock) = 0;

// getSockets() gets a list of sockets. This can be used to generate an
// fd_set for calling select().
virtual void getSockets(std::list<network::Socket*>* sockets) = 0;

// processSocketReadEvent() tells the server there is a Socket read event.
// The implementation can indicate that the Socket is no longer active
// by calling shutdown() on it. The caller will then call removeSocket()
// soon after processSocketEvent returns, to allow any pre-Socket
// resources to be tidied up.
virtual void processSocketReadEvent(network::Socket* sock) = 0;

// processSocketReadEvent() tells the server there is a Socket write event.
// This is only necessary if the Socket has been put in non-blocking
// mode and needs this callback to flush the buffer.
virtual void processSocketWriteEvent(network::Socket* sock) = 0;
};

}

#endif // __NETWORK_SOCKET_H__
36 changes: 36 additions & 0 deletions common/rfb/AccessRights.cxx
Original file line number Diff line number Diff line change
@@ -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 */
41 changes: 41 additions & 0 deletions common/rfb/AccessRights.h
Original file line number Diff line number Diff line change
@@ -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_ */
1 change: 1 addition & 0 deletions common/rfb/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
add_library(rfb STATIC
AccessRights.cxx
Blacklist.cxx
Congestion.cxx
CConnection.cxx
Expand Down
18 changes: 3 additions & 15 deletions common/rfb/SConnection.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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()
SConnection::SConnection(AccessRights accessRights)
: 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(accessRights), hasRemoteClipboard(false),
hasLocalClipboard(false),
unsolicitedClipboardAttempt(false)
{
Expand Down Expand Up @@ -254,7 +242,7 @@ bool SConnection::processSecurityMsg()
}

state_ = RFBSTATE_QUERYING;
setAccessRights(ssecurity->getAccessRights());
setAccessRights(accessRights & ssecurity->getAccessRights());
queryConnection(ssecurity->getUserName());

// If the connection got approved right away then we can continue
Expand Down
17 changes: 5 additions & 12 deletions common/rfb/SConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -42,7 +43,7 @@ namespace rfb {
class SConnection : public SMsgHandler {
public:

SConnection();
SConnection(AccessRights accessRights);
virtual ~SConnection();

// Methods to initialise the connection
Expand Down Expand Up @@ -175,20 +176,12 @@ namespace rfb {
// clipboard via handleClipboardRequest().
virtual void sendClipboardData(const char* data);

// getAccessRights() returns the access rights of a SConnection to the server.
AccessRights getAccessRights() { return accessRights; }

// 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;

Expand Down
2 changes: 1 addition & 1 deletion common/rfb/SSecurity.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions common/rfb/SSecurityRSAAES.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions common/rfb/SSecurityRSAAES.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -82,7 +82,7 @@ namespace rfb {

char username[256];
char password[256];
SConnection::AccessRights accessRights;
AccessRights accessRights;

rdr::InStream* rais;
rdr::OutStream* raos;
Expand Down
6 changes: 3 additions & 3 deletions common/rfb/SSecurityStack.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion common/rfb/SSecurityStack.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion common/rfb/SSecurityVeNCrypt.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion common/rfb/SSecurityVeNCrypt.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions common/rfb/SSecurityVncAuth.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ VncAuthPasswdParameter SSecurityVncAuth::vncAuthPasswd

SSecurityVncAuth::SSecurityVncAuth(SConnection* sc)
: SSecurity(sc), sentChallenge(false),
pg(&vncAuthPasswd), accessRights(0)
pg(&vncAuthPasswd), accessRights(AccessNone)
{
}

Expand Down Expand Up @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions common/rfb/SSecurityVncAuth.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -65,7 +65,7 @@ namespace rfb {
uint8_t response[vncAuthChallengeSize];
bool sentChallenge;
VncAuthPasswdGetter* pg;
SConnection::AccessRights accessRights;
AccessRights accessRights;
};
}
#endif
5 changes: 3 additions & 2 deletions common/rfb/VNCSConnectionST.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ static LogWriter vlog("VNCSConnST");
static Cursor emptyCursor(0, 0, Point(0, 0), NULL);

VNCSConnectionST::VNCSConnectionST(VNCServerST* server_, network::Socket *s,
bool reverse)
: sock(s), reverseConnection(reverse),
bool reverse, AccessRights ar)
: SConnection(ar),
sock(s), reverseConnection(reverse),
inProcessMessages(false),
pendingSyncFence(false), syncFence(false), fenceFlags(0),
fenceDataLen(0), fenceData(NULL), congestionTimer(this),
Expand Down
3 changes: 2 additions & 1 deletion common/rfb/VNCSConnectionST.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ namespace rfb {
class VNCSConnectionST : private SConnection,
public Timer::Callback {
public:
VNCSConnectionST(VNCServerST* server_, network::Socket* s, bool reverse);
VNCSConnectionST(VNCServerST* server_, network::Socket* s, bool reverse,
AccessRights ar);
virtual ~VNCSConnectionST();

// SConnection methods
Expand Down
Loading