diff options
Diffstat (limited to 'common/rfb/VNCServerST.cxx')
-rw-r--r-- | common/rfb/VNCServerST.cxx | 96 |
1 files changed, 67 insertions, 29 deletions
diff --git a/common/rfb/VNCServerST.cxx b/common/rfb/VNCServerST.cxx index b99d33b0..77d652b9 100644 --- a/common/rfb/VNCServerST.cxx +++ b/common/rfb/VNCServerST.cxx @@ -55,24 +55,28 @@ #include <assert.h> #include <stdlib.h> +#include <core/LogWriter.h> +#include <core/time.h> + +#include <rdr/FdOutStream.h> + #include <network/Socket.h> #include <rfb/ComparingUpdateTracker.h> #include <rfb/KeyRemapper.h> #include <rfb/KeysymStr.h> -#include <rfb/LogWriter.h> +#include <rfb/SDesktop.h> #include <rfb/Security.h> #include <rfb/ServerCore.h> #include <rfb/VNCServerST.h> #include <rfb/VNCSConnectionST.h> -#include <rfb/util.h> #include <rfb/ledStates.h> using namespace rfb; -static LogWriter slog("VNCServerST"); -static LogWriter connectionsLog("Connections"); +static core::LogWriter slog("VNCServerST"); +static core::LogWriter connectionsLog("Connections"); // // -=- VNCServerST Implementation @@ -85,7 +89,7 @@ VNCServerST::VNCServerST(const char* name_, SDesktop* desktop_) blockCounter(0), pb(nullptr), ledState(ledUnknown), name(name_), pointerClient(nullptr), clipboardClient(nullptr), pointerClientTime(0), - comparer(nullptr), cursor(new Cursor(0, 0, Point(), nullptr)), + comparer(nullptr), cursor(new Cursor(0, 0, {}, nullptr)), renderedCursorInvalid(false), keyRemapper(&KeyRemapper::defInstance), idleTimer(this), disconnectTimer(this), connectTimer(this), @@ -97,9 +101,9 @@ VNCServerST::VNCServerST(const char* name_, SDesktop* desktop_) // FIXME: Do we really want to kick off these right away? if (rfb::Server::maxIdleTime) - idleTimer.start(secsToMillis(rfb::Server::maxIdleTime)); + idleTimer.start(core::secsToMillis(rfb::Server::maxIdleTime)); if (rfb::Server::maxDisconnectionTime) - disconnectTimer.start(secsToMillis(rfb::Server::maxDisconnectionTime)); + disconnectTimer.start(core::secsToMillis(rfb::Server::maxDisconnectionTime)); } VNCServerST::~VNCServerST() @@ -161,12 +165,18 @@ void VNCServerST::addSocket(network::Socket* sock, bool outgoing, AccessRights a // Adjust the exit timers if (rfb::Server::maxConnectionTime && clients.empty()) - connectTimer.start(secsToMillis(rfb::Server::maxConnectionTime)); + connectTimer.start(core::secsToMillis(rfb::Server::maxConnectionTime)); disconnectTimer.stop(); - VNCSConnectionST* client = new VNCSConnectionST(this, sock, outgoing, accessRights); - clients.push_front(client); - client->init(); + try { + VNCSConnectionST* client = new VNCSConnectionST(this, sock, outgoing, accessRights); + clients.push_front(client); + client->init(); + } catch (std::exception& e) { + connectionsLog.error("Error accepting client: %s", e.what()); + sock->shutdown(); + closingSockets.push_back(sock); + } } void VNCServerST::removeSocket(network::Socket* sock) { @@ -203,7 +213,7 @@ void VNCServerST::removeSocket(network::Socket* sock) { // Adjust the exit timers connectTimer.stop(); if (rfb::Server::maxDisconnectionTime && clients.empty()) - disconnectTimer.start(secsToMillis(rfb::Server::maxDisconnectionTime)); + disconnectTimer.start(core::secsToMillis(rfb::Server::maxDisconnectionTime)); return; } @@ -313,7 +323,7 @@ void VNCServerST::setPixelBuffer(PixelBuffer* pb_) // Check that the screen layout is still valid if (pb_ && !layout.validate(pb_->width(), pb_->height())) { - Rect fbRect; + core::Rect fbRect; ScreenSet::iterator iter, iter_next; fbRect.setXYWH(0, 0, pb_->width(), pb_->height()); @@ -354,6 +364,9 @@ void VNCServerST::setScreenLayout(const ScreenSet& layout) void VNCServerST::requestClipboard() { + if (!rfb::Server::acceptCutText) + return; + if (clipboardClient == nullptr) { slog.debug("Got request for client clipboard but no client currently owns the clipboard"); return; @@ -368,6 +381,9 @@ void VNCServerST::announceClipboard(bool available) clipboardRequestors.clear(); + if (!rfb::Server::sendCutText) + return; + for (ci = clients.begin(); ci != clients.end(); ++ci) (*ci)->announceClipboardOrClose(available); } @@ -376,6 +392,9 @@ void VNCServerST::sendClipboardData(const char* data) { std::list<VNCSConnectionST*>::iterator ci; + if (!rfb::Server::sendCutText) + return; + if (strchr(data, '\r') != nullptr) throw std::invalid_argument("Invalid carriage return in clipboard data"); @@ -401,7 +420,7 @@ void VNCServerST::setName(const char* name_) (*ci)->setDesktopNameOrClose(name_); } -void VNCServerST::add_changed(const Region& region) +void VNCServerST::add_changed(const core::Region& region) { if (comparer == nullptr) return; @@ -410,7 +429,8 @@ void VNCServerST::add_changed(const Region& region) startFrameClock(); } -void VNCServerST::add_copied(const Region& dest, const Point& delta) +void VNCServerST::add_copied(const core::Region& dest, + const core::Point& delta) { if (comparer == nullptr) return; @@ -419,7 +439,8 @@ void VNCServerST::add_copied(const Region& dest, const Point& delta) startFrameClock(); } -void VNCServerST::setCursor(int width, int height, const Point& newHotspot, +void VNCServerST::setCursor(int width, int height, + const core::Point& newHotspot, const uint8_t* data) { delete cursor; @@ -435,7 +456,7 @@ void VNCServerST::setCursor(int width, int height, const Point& newHotspot, } } -void VNCServerST::setCursorPos(const Point& pos, bool warped) +void VNCServerST::setCursorPos(const core::Point& pos, bool warped) { if (cursorPos != pos) { cursorPos = pos; @@ -466,8 +487,11 @@ void VNCServerST::setLEDState(unsigned int state) void VNCServerST::keyEvent(uint32_t keysym, uint32_t keycode, bool down) { + if (!rfb::Server::acceptKeyEvents) + return; + if (rfb::Server::maxIdleTime) - idleTimer.start(secsToMillis(rfb::Server::maxIdleTime)); + idleTimer.start(core::secsToMillis(rfb::Server::maxIdleTime)); // Remap the key if required if (keyRemapper) { @@ -484,11 +508,16 @@ void VNCServerST::keyEvent(uint32_t keysym, uint32_t keycode, bool down) } void VNCServerST::pointerEvent(VNCSConnectionST* client, - const Point& pos, uint16_t buttonMask) + const core::Point& pos, + uint16_t buttonMask) { time_t now = time(nullptr); + + if (!rfb::Server::acceptPointerEvents) + return; + if (rfb::Server::maxIdleTime) - idleTimer.start(secsToMillis(rfb::Server::maxIdleTime)); + idleTimer.start(core::secsToMillis(rfb::Server::maxIdleTime)); // Let one client own the cursor whilst buttons are pressed in order // to provide a bit more sane user experience. But limit the time to @@ -516,9 +545,11 @@ void VNCServerST::handleClipboardRequest(VNCSConnectionST* client) void VNCServerST::handleClipboardAnnounce(VNCSConnectionST* client, bool available) { - if (available) + if (available) { + if (!rfb::Server::acceptCutText) + return; clipboardClient = client; - else { + } else { if (client != clipboardClient) return; clipboardClient = nullptr; @@ -529,6 +560,8 @@ void VNCServerST::handleClipboardAnnounce(VNCSConnectionST* client, void VNCServerST::handleClipboardData(VNCSConnectionST* client, const char* data) { + if (!rfb::Server::acceptCutText) + return; if (client != clipboardClient) { slog.debug("Ignoring unexpected clipboard data"); return; @@ -543,6 +576,11 @@ unsigned int VNCServerST::setDesktopSize(VNCSConnectionST* requester, unsigned int result; std::list<VNCSConnectionST*>::iterator ci; + if (!rfb::Server::acceptSetDesktopSize) { + slog.debug("Rejecting unauthorized framebuffer resize request"); + return resultProhibited; + } + // We can't handle a framebuffer larger than this, so don't let a // client set one (see PixelBuffer.cxx) if ((fb_width > 16384) || (fb_height > 16384)) { @@ -622,7 +660,7 @@ SConnection* VNCServerST::getConnection(network::Socket* sock) { return nullptr; } -void VNCServerST::handleTimeout(Timer* t) +void VNCServerST::handleTimeout(core::Timer* t) { if (t == &frameTimer) { int timeout; @@ -822,7 +860,7 @@ int VNCServerST::msToNextUpdate() void VNCServerST::writeUpdate() { UpdateInfo ui; - Region toCheck; + core::Region toCheck; std::list<VNCSConnectionST*>::iterator ci; @@ -834,9 +872,9 @@ void VNCServerST::writeUpdate() toCheck = ui.changed.union_(ui.copied); if (needRenderedCursor()) { - Rect clippedCursorRect = Rect(0, 0, cursor->width(), cursor->height()) - .translate(cursorPos.subtract(cursor->hotspot())) - .intersect(pb->getRect()); + core::Rect clippedCursorRect = core::Rect(0, 0, cursor->width(), cursor->height()) + .translate(cursorPos.subtract(cursor->hotspot())) + .intersect(pb->getRect()); if (!toCheck.intersect(clippedCursorRect).is_empty()) renderedCursorInvalid = true; @@ -864,7 +902,7 @@ void VNCServerST::writeUpdate() // checkUpdate() is called by clients to see if it is safe to read from // the framebuffer at this time. -Region VNCServerST::getPendingRegion() +core::Region VNCServerST::getPendingRegion() { UpdateInfo ui; @@ -876,7 +914,7 @@ Region VNCServerST::getPendingRegion() // Block client from updating if there are pending updates if (comparer->is_empty()) - return Region(); + return {}; comparer->getUpdateInfo(&ui, pb->getRect()); |