void approveConnection(bool accept, const char* reason=0);
+ // Methods to terminate the connection
+
+ // close() shuts down the connection to the client and awaits
+ // cleanup of the SConnection object by the server
+ virtual void close(const char* reason);
+
+
// Overridden from SMsgHandler
virtual void setEncodings(int nEncodings, const rdr::S32* encodings);
virtual void enableContinuousUpdates(bool enable,
int x, int y, int w, int h);
+ // Other methods
+
// setAccessRights() allows a security package to limit the access rights
- // of a VNCSConnectionST to the server. How the access rights are treated
+ // of a SConnection to the server. How the access rights are treated
// is up to the derived class.
typedef rdr::U16 AccessRights;
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) = 0;
-
- // Other methods
+ virtual void setAccessRights(AccessRights ar);
+ virtual bool accessCheck(AccessRights ar) const;
// authenticated() returns true if the client has authenticated
// successfully.
SSecurity* ssecurity;
stateEnum state_;
rdr::S32 preferredEncoding;
+ AccessRights accessRights;
};
}
#endif
losslessTimer(this), server(server_), updates(false),
updateRenderedCursor(false), removeRenderedCursor(false),
continuousUpdates(false), encodeManager(this), pointerEventTime(0),
- clientHasCursor(false),
- accessRights(AccessDefault), startTime(time(0))
+ clientHasCursor(false), startTime(time(0))
{
setStreams(&sock->inStream(), &sock->outStream());
peerEndpoint.buf = sock->getPeerEndpoint();
}
-// Methods called from VNCServerST
+// SConnection methods
-bool VNCSConnectionST::init()
+bool VNCSConnectionST::accessCheck(AccessRights ar) const
{
- try {
- initialiseProtocol();
- } catch (rdr::Exception& e) {
- close(e.str());
- return false;
- }
- return true;
+ // Reverse connections are user initiated, so they are implicitly
+ // allowed to bypass the query
+ if (reverseConnection)
+ ar &= ~AccessNoQuery;
+
+ return SConnection::accessCheck(ar);
}
void VNCSConnectionST::close(const char* reason)
// calling code will call VNCServerST's removeSocket() method causing us to
// be deleted.
sock->shutdown();
- setState(RFBSTATE_CLOSING);
+
+ SConnection::close(reason);
+}
+
+
+// Methods called from VNCServerST
+
+bool VNCSConnectionST::init()
+{
+ try {
+ initialiseProtocol();
+ } catch (rdr::Exception& e) {
+ close(e.str());
+ return false;
+ }
+ return true;
}
void VNCSConnectionST::serverCutTextOrClose(const char *str, int len)
{
try {
- if (!(accessRights & AccessCutText)) return;
+ if (!accessCheck(AccessCutText)) return;
if (!rfb::Server::sendCutText) return;
if (state() == RFBSTATE_NORMAL)
writer()->writeServerCutText(str, len);
}
// - Does the client have the right to bypass the query?
- if (reverseConnection ||
- !(rfb::Server::queryConnect || sock->requiresQuery()) ||
- (accessRights & AccessNoQuery))
+ if (!(rfb::Server::queryConnect || sock->requiresQuery()) ||
+ accessCheck(AccessNoQuery))
{
approveConnection(true);
return;
{
lastEventTime = time(0);
if (rfb::Server::alwaysShared || reverseConnection) shared = true;
- if (!(accessRights & AccessNonShared)) shared = true;
+ if (!accessCheck(AccessNonShared)) shared = true;
if (rfb::Server::neverShared) shared = false;
if (!shared) {
- if (rfb::Server::disconnectClients && (accessRights & AccessNonShared)) {
+ if (rfb::Server::disconnectClients && accessCheck(AccessNonShared)) {
// - Close all the other connected clients
vlog.debug("non-shared connection - closing clients");
server->closeClients("Non-shared connection requested", getSock());
void VNCSConnectionST::pointerEvent(const Point& pos, int buttonMask)
{
pointerEventTime = lastEventTime = time(0);
- if (!(accessRights & AccessPtrEvents)) return;
+ if (!accessCheck(AccessPtrEvents)) return;
if (!rfb::Server::acceptPointerEvents) return;
pointerEventPos = pos;
server->pointerEvent(this, pointerEventPos, buttonMask);
rdr::U32 lookup;
lastEventTime = time(0);
- if (!(accessRights & AccessKeyEvents)) return;
+ if (!accessCheck(AccessKeyEvents)) return;
if (!rfb::Server::acceptKeyEvents) return;
if (down)
void VNCSConnectionST::clientCutText(const char* str, int len)
{
- if (!(accessRights & AccessCutText)) return;
+ if (!accessCheck(AccessCutText)) return;
if (!rfb::Server::acceptCutText) return;
server->clientCutText(str, len);
}
{
Rect safeRect;
- if (!(accessRights & AccessView)) return;
+ if (!accessCheck(AccessView)) return;
SConnection::framebufferUpdateRequest(r, incremental);
{
unsigned int result;
- if (!(accessRights & AccessSetDesktopSize)) return;
+ if (!accessCheck(AccessSetDesktopSize)) return;
if (!rfb::Server::acceptSetDesktopSize) return;
result = server->setDesktopSize(this, fb_width, fb_height, layout);
void VNCSConnectionST::setStatus(int status)
{
+ AccessRights ar;
+
+ ar = AccessDefault;
+
switch (status) {
case 0:
- accessRights = accessRights | AccessPtrEvents | AccessKeyEvents | AccessView;
+ ar |= AccessPtrEvents | AccessKeyEvents | AccessView;
break;
case 1:
- accessRights = (accessRights & ~(AccessPtrEvents | AccessKeyEvents)) | AccessView;
+ ar |= rfb::SConnection::AccessView;
+ ar &= ~(AccessPtrEvents | AccessKeyEvents);
break;
case 2:
- accessRights = accessRights & ~(AccessPtrEvents | AccessKeyEvents | AccessView);
+ ar &= ~(AccessPtrEvents | AccessKeyEvents | AccessView);
break;
}
+
+ setAccessRights(ar);
+
framebufferUpdateRequest(server->getPixelBuffer()->getRect(), false);
}
int VNCSConnectionST::getStatus()
{
- if ((accessRights & (AccessPtrEvents | AccessKeyEvents | AccessView)) == 0x0007)
+ if (accessCheck(AccessPtrEvents | AccessKeyEvents | AccessView))
return 0;
- if ((accessRights & (AccessPtrEvents | AccessKeyEvents | AccessView)) == 0x0001)
+ else if (accessCheck(AccessView))
return 1;
- if ((accessRights & (AccessPtrEvents | AccessKeyEvents | AccessView)) == 0x0000)
+ else
return 2;
- return 4;
}
VNCSConnectionST(VNCServerST* server_, network::Socket* s, bool reverse);
virtual ~VNCSConnectionST();
+ // SConnection methods
+
+ virtual bool accessCheck(AccessRights ar) const;
+ virtual void close(const char* reason);
+
// Methods called from VNCServerST. None of these methods ever knowingly
// throw an exception.
// returns false, and close() will have been called.
bool init();
- // close() shuts down the socket to the client and deletes the
- // SConnectionST object.
- void close(const char* reason);
-
// processMessages() processes incoming messages from the client, invoking
// various callbacks as a result. It continues to process messages until
// reading might block. shutdown() will be called on the connection's
virtual void supportsContinuousUpdates();
virtual void supportsLEDState();
- // setAccessRights() allows a security package to limit the access rights
- // of a VNCSConnectioST to the server. These access rights are applied
- // such that the actual rights granted are the minimum of the server's
- // default access settings and the connection's access settings.
- virtual void setAccessRights(AccessRights ar) {accessRights=ar;}
-
// Timer callbacks
virtual bool handleTimeout(Timer* t);
Point pointerEventPos;
bool clientHasCursor;
- AccessRights accessRights;
-
CharArray closeReason;
time_t startTime;
};