From b2e878e79e81ada96605d4b3546713c9314ac4c7 Mon Sep 17 00:00:00 2001 From: Matthew McClaskey Date: Tue, 5 Apr 2022 12:52:38 +0000 Subject: [PATCH] Log and send clipboard op ids --- common/rfb/SConnection.cxx | 4 +++- common/rfb/SConnection.h | 3 ++- common/rfb/SMsgHandler.cxx | 2 +- common/rfb/SMsgHandler.h | 2 +- common/rfb/SMsgReader.cxx | 2 +- common/rfb/SMsgWriter.cxx | 3 +++ common/rfb/VNCSConnectionST.cxx | 25 ++++++++++++++++++------- common/rfb/VNCSConnectionST.h | 2 +- common/rfb/VNCServerST.cxx | 7 +++++-- common/rfb/VNCServerST.h | 2 ++ 10 files changed, 37 insertions(+), 15 deletions(-) diff --git a/common/rfb/SConnection.cxx b/common/rfb/SConnection.cxx index 1dde043..0203917 100644 --- a/common/rfb/SConnection.cxx +++ b/common/rfb/SConnection.cxx @@ -292,7 +292,7 @@ void SConnection::clearBinaryClipboard() } void SConnection::addBinaryClipboard(const char mime[], const rdr::U8 *data, - const rdr::U32 len) + const rdr::U32 len, const rdr::U32 id) { binaryClipboard_t bin; strncpy(bin.mime, mime, sizeof(bin.mime)); @@ -301,6 +301,8 @@ void SConnection::addBinaryClipboard(const char mime[], const rdr::U8 *data, bin.data.resize(len); memcpy(&bin.data[0], data, len); + bin.id = id; + binaryClipboard.push_back(bin); } diff --git a/common/rfb/SConnection.h b/common/rfb/SConnection.h index 515fa9b..0e831c8 100644 --- a/common/rfb/SConnection.h +++ b/common/rfb/SConnection.h @@ -76,7 +76,7 @@ namespace rfb { virtual void clearBinaryClipboard(); virtual void addBinaryClipboard(const char mime[], const rdr::U8 *data, - const rdr::U32 len); + const rdr::U32 len, const rdr::U32 id); virtual void supportsQEMUKeyEvent(); @@ -193,6 +193,7 @@ namespace rfb { struct binaryClipboard_t { char mime[32]; + rdr::U32 id; std::vector data; }; diff --git a/common/rfb/SMsgHandler.cxx b/common/rfb/SMsgHandler.cxx index 07499bc..c9275aa 100644 --- a/common/rfb/SMsgHandler.cxx +++ b/common/rfb/SMsgHandler.cxx @@ -73,7 +73,7 @@ void SMsgHandler::clearBinaryClipboard() } void SMsgHandler::addBinaryClipboard(const char mime[], const rdr::U8 *data, - const rdr::U32 len) + const rdr::U32 len, const rdr::U32 id) { } diff --git a/common/rfb/SMsgHandler.h b/common/rfb/SMsgHandler.h index d9d852a..053b215 100644 --- a/common/rfb/SMsgHandler.h +++ b/common/rfb/SMsgHandler.h @@ -57,7 +57,7 @@ namespace rfb { virtual void handleClipboardAnnounceBinary(const unsigned num, const char mimes[][32]); virtual void clearBinaryClipboard(); virtual void addBinaryClipboard(const char mime[], const rdr::U8 *data, - const rdr::U32 len); + const rdr::U32 len, const rdr::U32 id); virtual void sendStats(const bool toClient = true) = 0; virtual void handleFrameStats(rdr::U32 all, rdr::U32 render) = 0; diff --git a/common/rfb/SMsgReader.cxx b/common/rfb/SMsgReader.cxx index 3719756..fc01884 100644 --- a/common/rfb/SMsgReader.cxx +++ b/common/rfb/SMsgReader.cxx @@ -276,7 +276,7 @@ void SMsgReader::readBinaryClipboard() vlog.debug("Received binary clipboard, type %s, %u bytes", mime, len); - handler->addBinaryClipboard(mime, (rdr::U8 *) ca.buf, len); + handler->addBinaryClipboard(mime, (rdr::U8 *) ca.buf, len, 0); valid++; } diff --git a/common/rfb/SMsgWriter.cxx b/common/rfb/SMsgWriter.cxx index a0a9df0..5c5562c 100644 --- a/common/rfb/SMsgWriter.cxx +++ b/common/rfb/SMsgWriter.cxx @@ -92,6 +92,9 @@ void SMsgWriter::writeBinaryClipboard(const std::vectorwriteU8(b.size()); rdr::U8 i; for (i = 0; i < b.size(); i++) { + const rdr::U32 id = b[i].id; + os->writeU32(id); + const rdr::U8 mimelen = strlen(b[i].mime); os->writeU8(mimelen); os->writeBytes(b[i].mime, mimelen); diff --git a/common/rfb/VNCSConnectionST.cxx b/common/rfb/VNCSConnectionST.cxx index 84e48e9..c6affa5 100644 --- a/common/rfb/VNCSConnectionST.cxx +++ b/common/rfb/VNCSConnectionST.cxx @@ -367,17 +367,18 @@ char *percentEncode4(const uint16_t *str, const unsigned len) { } static void cliplog(const char *str, const int len, const int origlen, - const char *dir, const char *client) { + const char *dir, const char *client, const unsigned id) { if (Server::DLP_ClipLog[0] == 'o') return; if (Server::DLP_ClipLog[0] == 'i') { - vlog.info("DLP: client %s: %s %u (%u requested) clipboard bytes", client, dir, len, origlen); + vlog.info("DLP: client %s: %s %u (%u requested) clipboard bytes, id %u", client, dir, + len, origlen, id); } else { // URL-encode it char *enc = percentEncode(str, len); - vlog.info("DLP: client %s: %s %u (%u requested) clipboard bytes: '%s'", - client, dir, len, origlen, enc); + vlog.info("DLP: client %s: %s %u (%u requested) clipboard bytes, id %u: '%s'", + client, dir, len, origlen, id, enc); free(enc); } } @@ -439,7 +440,8 @@ void VNCSConnectionST::clearBinaryClipboardData() void VNCSConnectionST::sendBinaryClipboardDataOrClose(const char* mime, const unsigned char *data, - const unsigned len) + const unsigned len, + const unsigned id) { try { if (!(accessRights & AccessCutText)) return; @@ -450,10 +452,11 @@ void VNCSConnectionST::sendBinaryClipboardDataOrClose(const char* mime, return; } - cliplog((const char *) data, len, len, "sent", sock->getPeerAddress()); + cliplog((const char *) data, len, len, "sent", sock->getPeerAddress(), + id); if (state() != RFBSTATE_NORMAL) return; - addBinaryClipboard(mime, data, len); + addBinaryClipboard(mime, data, len, id); binclipTimer.start(100); } catch(rdr::Exception& e) { close(e.str()); @@ -1049,6 +1052,14 @@ void VNCSConnectionST::handleClipboardAnnounceBinary(const unsigned num, const c if (!(accessRights & AccessCutText)) return; if (!rfb::Server::acceptCutText) return; server->handleClipboardAnnounceBinary(this, num, mimes); + + const unsigned tolog = server->clipboardId++; + + if (Server::DLP_ClipLog[0] == 'o') + return; + vlog.info("DLP: client %s: %s %u clipboard mimes, id %u", + sock->getPeerAddress(), "received", + num, tolog); } // supportsLocalCursor() is called whenever the status of diff --git a/common/rfb/VNCSConnectionST.h b/common/rfb/VNCSConnectionST.h index 813281c..e088c10 100644 --- a/common/rfb/VNCSConnectionST.h +++ b/common/rfb/VNCSConnectionST.h @@ -80,7 +80,7 @@ namespace rfb { void announceClipboardOrClose(bool available); void clearBinaryClipboardData(); void sendBinaryClipboardDataOrClose(const char* mime, const unsigned char *data, - const unsigned len); + const unsigned len, const unsigned id); void getBinaryClipboardData(const char* mime, const unsigned char **data, unsigned *len); diff --git a/common/rfb/VNCServerST.cxx b/common/rfb/VNCServerST.cxx index e66f956..f440894 100644 --- a/common/rfb/VNCServerST.cxx +++ b/common/rfb/VNCServerST.cxx @@ -131,7 +131,8 @@ VNCServerST::VNCServerST(const char* name_, SDesktop* desktop_) renderedCursorInvalid(false), queryConnectionHandler(0), keyRemapper(&KeyRemapper::defInstance), lastConnectionTime(0), disableclients(false), - frameTimer(this), apimessager(NULL), trackingFrameStats(0) + frameTimer(this), apimessager(NULL), trackingFrameStats(0), + clipboardId(0) { lastUserInputTime = lastDisconnectTime = time(0); slog.debug("creating single-threaded server %s", name.buf); @@ -539,8 +540,10 @@ void VNCServerST::sendBinaryClipboardData(const char* mime, const unsigned char std::list::iterator ci, ci_next; for (ci = clients.begin(); ci != clients.end(); ci = ci_next) { ci_next = ci; ci_next++; - (*ci)->sendBinaryClipboardDataOrClose(mime, data, len); + (*ci)->sendBinaryClipboardDataOrClose(mime, data, len, clipboardId); } + + clipboardId++; } void VNCServerST::getBinaryClipboardData(const char* mime, const unsigned char **data, diff --git a/common/rfb/VNCServerST.h b/common/rfb/VNCServerST.h index 0eff2d1..21ce5a9 100644 --- a/common/rfb/VNCServerST.h +++ b/common/rfb/VNCServerST.h @@ -281,6 +281,8 @@ namespace rfb { } DLPRegion; void translateDLPRegion(rdr::U16 &x1, rdr::U16 &y1, rdr::U16 &x2, rdr::U16 &y2) const; + + rdr::U32 clipboardId; }; };