Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 1 | /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved. |
Pierre Ossman | c754cce | 2011-11-14 15:44:11 +0000 | [diff] [blame] | 2 | * Copyright 2011 Pierre Ossman for Cendio AB |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 3 | * |
| 4 | * This is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation; either version 2 of the License, or |
| 7 | * (at your option) any later version. |
| 8 | * |
| 9 | * This software is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this software; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
| 17 | * USA. |
| 18 | */ |
| 19 | #include <stdio.h> |
| 20 | #include <string.h> |
| 21 | #include <rfb/Exception.h> |
Adam Tkac | 5a0caed | 2010-04-23 13:58:10 +0000 | [diff] [blame] | 22 | #include <rfb/Security.h> |
Constantin Kaplinsky | dafbb01 | 2007-04-05 08:43:25 +0000 | [diff] [blame] | 23 | #include <rfb/msgTypes.h> |
Pierre Ossman | c754cce | 2011-11-14 15:44:11 +0000 | [diff] [blame] | 24 | #include <rfb/fenceTypes.h> |
Pierre Ossman | 7638e9c | 2014-01-16 13:12:40 +0100 | [diff] [blame] | 25 | #include <rfb/SMsgReader.h> |
| 26 | #include <rfb/SMsgWriter.h> |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 27 | #include <rfb/SConnection.h> |
| 28 | #include <rfb/ServerCore.h> |
Pierre Ossman | 4870081 | 2014-09-17 17:11:56 +0200 | [diff] [blame] | 29 | #include <rfb/encodings.h> |
| 30 | #include <rfb/EncodeManager.h> |
Michal Srb | 8d1ee00 | 2014-11-10 09:15:41 +0200 | [diff] [blame] | 31 | #include <rfb/SSecurity.h> |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 32 | |
| 33 | #include <rfb/LogWriter.h> |
| 34 | |
| 35 | using namespace rfb; |
| 36 | |
| 37 | static LogWriter vlog("SConnection"); |
| 38 | |
| 39 | // AccessRights values |
Michal Srb | b318b8f | 2014-11-24 13:18:28 +0200 | [diff] [blame] | 40 | const SConnection::AccessRights SConnection::AccessView = 0x0001; |
| 41 | const SConnection::AccessRights SConnection::AccessKeyEvents = 0x0002; |
| 42 | const SConnection::AccessRights SConnection::AccessPtrEvents = 0x0004; |
| 43 | const SConnection::AccessRights SConnection::AccessCutText = 0x0008; |
| 44 | const SConnection::AccessRights SConnection::AccessSetDesktopSize = 0x0010; |
Pierre Ossman | e7be49b | 2014-12-02 14:33:17 +0100 | [diff] [blame] | 45 | const SConnection::AccessRights SConnection::AccessNonShared = 0x0020; |
Michal Srb | b318b8f | 2014-11-24 13:18:28 +0200 | [diff] [blame] | 46 | const SConnection::AccessRights SConnection::AccessDefault = 0x03ff; |
| 47 | const SConnection::AccessRights SConnection::AccessNoQuery = 0x0400; |
| 48 | const SConnection::AccessRights SConnection::AccessFull = 0xffff; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 49 | |
| 50 | |
Pierre Ossman | 7069bdd | 2015-02-06 14:41:58 +0100 | [diff] [blame] | 51 | SConnection::SConnection() |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 52 | : readyForSetColourMapEntries(false), |
| 53 | is(0), os(0), reader_(0), writer_(0), |
Michal Srb | dccb5f7 | 2017-03-27 13:55:46 +0300 | [diff] [blame] | 54 | ssecurity(0), state_(RFBSTATE_UNINITIALISED), |
Pierre Ossman | 4870081 | 2014-09-17 17:11:56 +0200 | [diff] [blame] | 55 | preferredEncoding(encodingRaw) |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 56 | { |
| 57 | defaultMajorVersion = 3; |
| 58 | defaultMinorVersion = 8; |
| 59 | if (rfb::Server::protocol3_3) |
| 60 | defaultMinorVersion = 3; |
| 61 | |
Pierre Ossman | 0d3ce87 | 2018-06-18 15:59:00 +0200 | [diff] [blame^] | 62 | client.setVersion(defaultMajorVersion, defaultMinorVersion); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | SConnection::~SConnection() |
| 66 | { |
Pierre Ossman | 82d22e6 | 2018-09-21 15:26:37 +0200 | [diff] [blame] | 67 | if (ssecurity) |
| 68 | delete ssecurity; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 69 | delete reader_; |
| 70 | reader_ = 0; |
| 71 | delete writer_; |
| 72 | writer_ = 0; |
| 73 | } |
| 74 | |
| 75 | void SConnection::setStreams(rdr::InStream* is_, rdr::OutStream* os_) |
| 76 | { |
| 77 | is = is_; |
| 78 | os = os_; |
| 79 | } |
| 80 | |
| 81 | void SConnection::initialiseProtocol() |
| 82 | { |
Pierre Ossman | ea7ede9 | 2018-06-18 16:51:53 +0200 | [diff] [blame] | 83 | char str[13]; |
| 84 | |
| 85 | sprintf(str, "RFB %03d.%03d\n", defaultMajorVersion, defaultMinorVersion); |
| 86 | os->writeBytes(str, 12); |
| 87 | os->flush(); |
| 88 | |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 89 | state_ = RFBSTATE_PROTOCOL_VERSION; |
| 90 | } |
| 91 | |
| 92 | void SConnection::processMsg() |
| 93 | { |
| 94 | switch (state_) { |
| 95 | case RFBSTATE_PROTOCOL_VERSION: processVersionMsg(); break; |
| 96 | case RFBSTATE_SECURITY_TYPE: processSecurityTypeMsg(); break; |
| 97 | case RFBSTATE_SECURITY: processSecurityMsg(); break; |
| 98 | case RFBSTATE_INITIALISATION: processInitMsg(); break; |
| 99 | case RFBSTATE_NORMAL: reader_->readMsg(); break; |
| 100 | case RFBSTATE_QUERYING: |
| 101 | throw Exception("SConnection::processMsg: bogus data from client while " |
| 102 | "querying"); |
| 103 | case RFBSTATE_UNINITIALISED: |
| 104 | throw Exception("SConnection::processMsg: not initialised yet?"); |
| 105 | default: |
| 106 | throw Exception("SConnection::processMsg: invalid state"); |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | void SConnection::processVersionMsg() |
| 111 | { |
Pierre Ossman | ea7ede9 | 2018-06-18 16:51:53 +0200 | [diff] [blame] | 112 | char verStr[13]; |
| 113 | int majorVersion; |
| 114 | int minorVersion; |
| 115 | |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 116 | vlog.debug("reading protocol version"); |
Pierre Ossman | ea7ede9 | 2018-06-18 16:51:53 +0200 | [diff] [blame] | 117 | |
| 118 | if (!is->checkNoWait(12)) |
| 119 | return; |
| 120 | |
| 121 | is->readBytes(verStr, 12); |
| 122 | verStr[12] = '\0'; |
| 123 | |
| 124 | if (sscanf(verStr, "RFB %03d.%03d\n", |
| 125 | &majorVersion, &minorVersion) != 2) { |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 126 | state_ = RFBSTATE_INVALID; |
| 127 | throw Exception("reading version failed: not an RFB client?"); |
| 128 | } |
Pierre Ossman | ea7ede9 | 2018-06-18 16:51:53 +0200 | [diff] [blame] | 129 | |
Pierre Ossman | 0d3ce87 | 2018-06-18 15:59:00 +0200 | [diff] [blame^] | 130 | client.setVersion(majorVersion, minorVersion); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 131 | |
| 132 | vlog.info("Client needs protocol version %d.%d", |
Pierre Ossman | 0d3ce87 | 2018-06-18 15:59:00 +0200 | [diff] [blame^] | 133 | client.majorVersion, client.minorVersion); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 134 | |
Pierre Ossman | 0d3ce87 | 2018-06-18 15:59:00 +0200 | [diff] [blame^] | 135 | if (client.majorVersion != 3) { |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 136 | // unknown protocol version |
Pierre Ossman | 1922550 | 2017-10-12 15:05:07 +0200 | [diff] [blame] | 137 | throwConnFailedException("Client needs protocol version %d.%d, server has %d.%d", |
Pierre Ossman | 0d3ce87 | 2018-06-18 15:59:00 +0200 | [diff] [blame^] | 138 | client.majorVersion, client.minorVersion, |
Pierre Ossman | 1922550 | 2017-10-12 15:05:07 +0200 | [diff] [blame] | 139 | defaultMajorVersion, defaultMinorVersion); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 140 | } |
| 141 | |
Pierre Ossman | 0d3ce87 | 2018-06-18 15:59:00 +0200 | [diff] [blame^] | 142 | if (client.minorVersion != 3 && client.minorVersion != 7 && client.minorVersion != 8) { |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 143 | vlog.error("Client uses unofficial protocol version %d.%d", |
Pierre Ossman | 0d3ce87 | 2018-06-18 15:59:00 +0200 | [diff] [blame^] | 144 | client.majorVersion,client.minorVersion); |
| 145 | if (client.minorVersion >= 8) |
| 146 | client.minorVersion = 8; |
| 147 | else if (client.minorVersion == 7) |
| 148 | client.minorVersion = 7; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 149 | else |
Pierre Ossman | 0d3ce87 | 2018-06-18 15:59:00 +0200 | [diff] [blame^] | 150 | client.minorVersion = 3; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 151 | vlog.error("Assuming compatibility with version %d.%d", |
Pierre Ossman | 0d3ce87 | 2018-06-18 15:59:00 +0200 | [diff] [blame^] | 152 | client.majorVersion,client.minorVersion); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | versionReceived(); |
| 156 | |
| 157 | std::list<rdr::U8> secTypes; |
| 158 | std::list<rdr::U8>::iterator i; |
Michal Srb | dccb5f7 | 2017-03-27 13:55:46 +0300 | [diff] [blame] | 159 | secTypes = security.GetEnabledSecTypes(); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 160 | |
Pierre Ossman | 0d3ce87 | 2018-06-18 15:59:00 +0200 | [diff] [blame^] | 161 | if (client.isVersion(3,3)) { |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 162 | |
| 163 | // cope with legacy 3.3 client only if "no authentication" or "vnc |
| 164 | // authentication" is supported. |
| 165 | for (i=secTypes.begin(); i!=secTypes.end(); i++) { |
| 166 | if (*i == secTypeNone || *i == secTypeVncAuth) break; |
| 167 | } |
| 168 | if (i == secTypes.end()) { |
Pierre Ossman | 1922550 | 2017-10-12 15:05:07 +0200 | [diff] [blame] | 169 | throwConnFailedException("No supported security type for %d.%d client", |
Pierre Ossman | 0d3ce87 | 2018-06-18 15:59:00 +0200 | [diff] [blame^] | 170 | client.majorVersion, client.minorVersion); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | os->writeU32(*i); |
| 174 | if (*i == secTypeNone) os->flush(); |
| 175 | state_ = RFBSTATE_SECURITY; |
Pierre Ossman | ad2b3c4 | 2018-09-21 15:31:11 +0200 | [diff] [blame] | 176 | ssecurity = security.GetSSecurity(this, *i); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 177 | processSecurityMsg(); |
| 178 | return; |
| 179 | } |
| 180 | |
| 181 | // list supported security types for >=3.7 clients |
| 182 | |
| 183 | if (secTypes.empty()) |
| 184 | throwConnFailedException("No supported security types"); |
| 185 | |
| 186 | os->writeU8(secTypes.size()); |
| 187 | for (i=secTypes.begin(); i!=secTypes.end(); i++) |
| 188 | os->writeU8(*i); |
| 189 | os->flush(); |
| 190 | state_ = RFBSTATE_SECURITY_TYPE; |
| 191 | } |
| 192 | |
| 193 | |
| 194 | void SConnection::processSecurityTypeMsg() |
| 195 | { |
| 196 | vlog.debug("processing security type message"); |
| 197 | int secType = is->readU8(); |
| 198 | |
Constantin Kaplinsky | 5fa9d22 | 2006-09-06 10:32:06 +0000 | [diff] [blame] | 199 | processSecurityType(secType); |
| 200 | } |
| 201 | |
| 202 | void SConnection::processSecurityType(int secType) |
| 203 | { |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 204 | // Verify that the requested security type should be offered |
| 205 | std::list<rdr::U8> secTypes; |
| 206 | std::list<rdr::U8>::iterator i; |
Adam Tkac | a6578bf | 2010-04-23 14:07:41 +0000 | [diff] [blame] | 207 | |
Michal Srb | dccb5f7 | 2017-03-27 13:55:46 +0300 | [diff] [blame] | 208 | secTypes = security.GetEnabledSecTypes(); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 209 | for (i=secTypes.begin(); i!=secTypes.end(); i++) |
| 210 | if (*i == secType) break; |
| 211 | if (i == secTypes.end()) |
| 212 | throw Exception("Requested security type not available"); |
| 213 | |
| 214 | vlog.info("Client requests security type %s(%d)", |
| 215 | secTypeName(secType),secType); |
| 216 | |
| 217 | try { |
| 218 | state_ = RFBSTATE_SECURITY; |
Pierre Ossman | ad2b3c4 | 2018-09-21 15:31:11 +0200 | [diff] [blame] | 219 | ssecurity = security.GetSSecurity(this, secType); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 220 | } catch (rdr::Exception& e) { |
Pierre Ossman | 1922550 | 2017-10-12 15:05:07 +0200 | [diff] [blame] | 221 | throwConnFailedException("%s", e.str()); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | processSecurityMsg(); |
| 225 | } |
| 226 | |
| 227 | void SConnection::processSecurityMsg() |
| 228 | { |
| 229 | vlog.debug("processing security message"); |
| 230 | try { |
Pierre Ossman | ad2b3c4 | 2018-09-21 15:31:11 +0200 | [diff] [blame] | 231 | bool done = ssecurity->processMsg(); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 232 | if (done) { |
| 233 | state_ = RFBSTATE_QUERYING; |
Michal Srb | 8d1ee00 | 2014-11-10 09:15:41 +0200 | [diff] [blame] | 234 | setAccessRights(ssecurity->getAccessRights()); |
Henrik Andersson | c1cbc70 | 2016-01-27 14:00:44 +0100 | [diff] [blame] | 235 | queryConnection(ssecurity->getUserName()); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 236 | } |
| 237 | } catch (AuthFailureException& e) { |
| 238 | vlog.error("AuthFailureException: %s", e.str()); |
| 239 | os->writeU32(secResultFailed); |
Pierre Ossman | 0d3ce87 | 2018-06-18 15:59:00 +0200 | [diff] [blame^] | 240 | if (!client.beforeVersion(3,8)) // 3.8 onwards have failure message |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 241 | os->writeString(e.str()); |
| 242 | os->flush(); |
| 243 | throw; |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | void SConnection::processInitMsg() |
| 248 | { |
| 249 | vlog.debug("reading client initialisation"); |
| 250 | reader_->readClientInit(); |
| 251 | } |
| 252 | |
Pierre Ossman | 1922550 | 2017-10-12 15:05:07 +0200 | [diff] [blame] | 253 | void SConnection::throwConnFailedException(const char* format, ...) |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 254 | { |
Pierre Ossman | 1922550 | 2017-10-12 15:05:07 +0200 | [diff] [blame] | 255 | va_list ap; |
| 256 | char str[256]; |
| 257 | |
| 258 | va_start(ap, format); |
| 259 | (void) vsnprintf(str, sizeof(str), format, ap); |
| 260 | va_end(ap); |
| 261 | |
| 262 | vlog.info("Connection failed: %s", str); |
| 263 | |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 264 | if (state_ == RFBSTATE_PROTOCOL_VERSION) { |
Pierre Ossman | 0d3ce87 | 2018-06-18 15:59:00 +0200 | [diff] [blame^] | 265 | if (client.majorVersion == 3 && client.minorVersion == 3) { |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 266 | os->writeU32(0); |
Pierre Ossman | 1922550 | 2017-10-12 15:05:07 +0200 | [diff] [blame] | 267 | os->writeString(str); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 268 | os->flush(); |
| 269 | } else { |
| 270 | os->writeU8(0); |
Pierre Ossman | 1922550 | 2017-10-12 15:05:07 +0200 | [diff] [blame] | 271 | os->writeString(str); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 272 | os->flush(); |
| 273 | } |
| 274 | } |
Pierre Ossman | 1922550 | 2017-10-12 15:05:07 +0200 | [diff] [blame] | 275 | |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 276 | state_ = RFBSTATE_INVALID; |
Pierre Ossman | 1922550 | 2017-10-12 15:05:07 +0200 | [diff] [blame] | 277 | throw ConnFailedException(str); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | void SConnection::writeConnFailedFromScratch(const char* msg, |
| 281 | rdr::OutStream* os) |
| 282 | { |
| 283 | os->writeBytes("RFB 003.003\n", 12); |
| 284 | os->writeU32(0); |
| 285 | os->writeString(msg); |
| 286 | os->flush(); |
| 287 | } |
| 288 | |
Pierre Ossman | f38e243 | 2015-02-11 13:47:58 +0100 | [diff] [blame] | 289 | void SConnection::setEncodings(int nEncodings, const rdr::S32* encodings) |
Pierre Ossman | 4870081 | 2014-09-17 17:11:56 +0200 | [diff] [blame] | 290 | { |
| 291 | int i; |
| 292 | |
| 293 | preferredEncoding = encodingRaw; |
| 294 | for (i = 0;i < nEncodings;i++) { |
| 295 | if (EncodeManager::supported(encodings[i])) { |
| 296 | preferredEncoding = encodings[i]; |
| 297 | break; |
| 298 | } |
| 299 | } |
| 300 | |
| 301 | SMsgHandler::setEncodings(nEncodings, encodings); |
| 302 | } |
| 303 | |
Pierre Ossman | 5ae2821 | 2017-05-16 14:30:38 +0200 | [diff] [blame] | 304 | void SConnection::supportsQEMUKeyEvent() |
| 305 | { |
| 306 | writer()->writeQEMUKeyEvent(); |
| 307 | } |
| 308 | |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 309 | void SConnection::versionReceived() |
| 310 | { |
| 311 | } |
| 312 | |
| 313 | void SConnection::authSuccess() |
| 314 | { |
| 315 | } |
| 316 | |
| 317 | void SConnection::queryConnection(const char* userName) |
| 318 | { |
| 319 | approveConnection(true); |
| 320 | } |
| 321 | |
| 322 | void SConnection::approveConnection(bool accept, const char* reason) |
| 323 | { |
| 324 | if (state_ != RFBSTATE_QUERYING) |
| 325 | throw Exception("SConnection::approveConnection: invalid state"); |
| 326 | |
Pierre Ossman | 0d3ce87 | 2018-06-18 15:59:00 +0200 | [diff] [blame^] | 327 | if (!client.beforeVersion(3,8) || ssecurity->getType() != secTypeNone) { |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 328 | if (accept) { |
| 329 | os->writeU32(secResultOK); |
| 330 | } else { |
| 331 | os->writeU32(secResultFailed); |
Pierre Ossman | 0d3ce87 | 2018-06-18 15:59:00 +0200 | [diff] [blame^] | 332 | if (!client.beforeVersion(3,8)) { // 3.8 onwards have failure message |
Pierre Ossman | 1922550 | 2017-10-12 15:05:07 +0200 | [diff] [blame] | 333 | if (reason) |
| 334 | os->writeString(reason); |
| 335 | else |
| 336 | os->writeString("Authentication failure"); |
| 337 | } |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 338 | } |
| 339 | os->flush(); |
| 340 | } |
| 341 | |
| 342 | if (accept) { |
| 343 | state_ = RFBSTATE_INITIALISATION; |
Pierre Ossman | 7638e9c | 2014-01-16 13:12:40 +0100 | [diff] [blame] | 344 | reader_ = new SMsgReader(this, is); |
Pierre Ossman | 0d3ce87 | 2018-06-18 15:59:00 +0200 | [diff] [blame^] | 345 | writer_ = new SMsgWriter(&client, os); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 346 | authSuccess(); |
| 347 | } else { |
| 348 | state_ = RFBSTATE_INVALID; |
Pierre Ossman | 1922550 | 2017-10-12 15:05:07 +0200 | [diff] [blame] | 349 | if (reason) |
| 350 | throw AuthFailureException(reason); |
| 351 | else |
| 352 | throw AuthFailureException(); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 353 | } |
| 354 | } |
| 355 | |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 356 | void SConnection::clientInit(bool shared) |
| 357 | { |
| 358 | writer_->writeServerInit(); |
| 359 | state_ = RFBSTATE_NORMAL; |
| 360 | } |
| 361 | |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 362 | void SConnection::setPixelFormat(const PixelFormat& pf) |
| 363 | { |
| 364 | SMsgHandler::setPixelFormat(pf); |
| 365 | readyForSetColourMapEntries = true; |
Pierre Ossman | b6b4dc6 | 2014-01-20 15:05:21 +0100 | [diff] [blame] | 366 | if (!pf.trueColour) |
| 367 | writeFakeColourMap(); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | void SConnection::framebufferUpdateRequest(const Rect& r, bool incremental) |
| 371 | { |
| 372 | if (!readyForSetColourMapEntries) { |
| 373 | readyForSetColourMapEntries = true; |
Pierre Ossman | 0d3ce87 | 2018-06-18 15:59:00 +0200 | [diff] [blame^] | 374 | if (!client.pf().trueColour) { |
Pierre Ossman | b6b4dc6 | 2014-01-20 15:05:21 +0100 | [diff] [blame] | 375 | writeFakeColourMap(); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 376 | } |
| 377 | } |
| 378 | } |
Pierre Ossman | c754cce | 2011-11-14 15:44:11 +0000 | [diff] [blame] | 379 | |
| 380 | void SConnection::fence(rdr::U32 flags, unsigned len, const char data[]) |
| 381 | { |
| 382 | if (!(flags & fenceFlagRequest)) |
| 383 | return; |
| 384 | |
| 385 | // We cannot guarantee any synchronisation at this level |
| 386 | flags = 0; |
| 387 | |
| 388 | writer()->writeFence(flags, len, data); |
| 389 | } |
Pierre Ossman | c898d9a | 2011-11-14 16:22:23 +0000 | [diff] [blame] | 390 | |
| 391 | void SConnection::enableContinuousUpdates(bool enable, |
| 392 | int x, int y, int w, int h) |
| 393 | { |
| 394 | } |
Pierre Ossman | b6b4dc6 | 2014-01-20 15:05:21 +0100 | [diff] [blame] | 395 | |
| 396 | void SConnection::writeFakeColourMap(void) |
| 397 | { |
| 398 | int i; |
| 399 | rdr::U16 red[256], green[256], blue[256]; |
| 400 | |
| 401 | for (i = 0;i < 256;i++) |
Pierre Ossman | 0d3ce87 | 2018-06-18 15:59:00 +0200 | [diff] [blame^] | 402 | client.pf().rgbFromPixel(i, &red[i], &green[i], &blue[i]); |
Pierre Ossman | b6b4dc6 | 2014-01-20 15:05:21 +0100 | [diff] [blame] | 403 | |
| 404 | writer()->writeSetColourMapEntries(0, 256, red, green, blue); |
| 405 | } |