1 /* 2 * Copyright (c) 2005 Novell, Inc. 3 * All Rights Reserved. 4 * 5 * This program is free software; you can redistribute it and/or 6 * modify it under the terms of version 2 of the GNU General Public License as 7 * published by the Free Software Foundation. 8 * 9 * This program 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 program; if not, contact Novell, Inc. 16 * 17 * To contact Novell about this file by physical or electronic mail, 18 * you may find current contact information at www.novell.com 19 * 20 * Author : Rohit Kumar 21 * Email ID : rokumar@novell.com 22 * Date : 25th August 2005 23 */ 24 25 #ifndef RFBTIGHTPROTO_H 26 #define RFBTIGHTPROTO_H 27 28 #include <rfb/rfb.h> 29 #include <limits.h> 30 31 /* PATH_MAX is not defined in limits.h on some platforms */ 32 #ifndef PATH_MAX 33 #define PATH_MAX 4096 34 #endif 35 36 37 #define rfbSecTypeTight 16 38 39 void rfbTightUsage(void); 40 int rfbTightProcessArgs(int argc, char *argv[]); 41 42 /*----------------------------------------------------------------------------- 43 * Negotiation of Tunneling Capabilities (protocol version 3.7t) 44 * 45 * If the chosen security type is rfbSecTypeTight, the server sends a list of 46 * supported tunneling methods ("tunneling" refers to any additional layer of 47 * data transformation, such as encryption or external compression.) 48 * 49 * nTunnelTypes specifies the number of following rfbCapabilityInfo structures 50 * that list all supported tunneling methods in the order of preference. 51 * 52 * NOTE: If nTunnelTypes is 0, that tells the client that no tunneling can be 53 * used, and the client should not send a response requesting a tunneling 54 * method. 55 */ 56 57 typedef struct _rfbTunnelingCapsMsg { 58 uint32_t nTunnelTypes; 59 /* followed by nTunnelTypes * rfbCapabilityInfo structures */ 60 } rfbTunnelingCapsMsg; 61 62 #define sz_rfbTunnelingCapsMsg 4 63 64 /*----------------------------------------------------------------------------- 65 * Tunneling Method Request (protocol version 3.7t) 66 * 67 * If the list of tunneling capabilities sent by the server was not empty, the 68 * client should reply with a 32-bit code specifying a particular tunneling 69 * method. The following code should be used for no tunneling. 70 */ 71 72 #define rfbNoTunneling 0 73 #define sig_rfbNoTunneling "NOTUNNEL" 74 75 76 /*----------------------------------------------------------------------------- 77 * Negotiation of Authentication Capabilities (protocol version 3.7t) 78 * 79 * After setting up tunneling, the server sends a list of supported 80 * authentication schemes. 81 * 82 * nAuthTypes specifies the number of following rfbCapabilityInfo structures 83 * that list all supported authentication schemes in the order of preference. 84 * 85 * NOTE: If nAuthTypes is 0, that tells the client that no authentication is 86 * necessary, and the client should not send a response requesting an 87 * authentication scheme. 88 */ 89 90 typedef struct _rfbAuthenticationCapsMsg { 91 uint32_t nAuthTypes; 92 /* followed by nAuthTypes * rfbCapabilityInfo structures */ 93 } rfbAuthenticationCapsMsg; 94 95 #define sz_rfbAuthenticationCapsMsg 4 96 97 /*----------------------------------------------------------------------------- 98 * Authentication Scheme Request (protocol version 3.7t) 99 * 100 * If the list of authentication capabilities sent by the server was not empty, 101 * the client should reply with a 32-bit code specifying a particular 102 * authentication scheme. The following codes are supported. 103 */ 104 105 #define rfbAuthNone 1 106 #define rfbAuthVNC 2 107 #define rfbAuthUnixLogin 129 108 #define rfbAuthExternal 130 109 110 #define sig_rfbAuthNone "NOAUTH__" 111 #define sig_rfbAuthVNC "VNCAUTH_" 112 #define sig_rfbAuthUnixLogin "ULGNAUTH" 113 #define sig_rfbAuthExternal "XTRNAUTH" 114 115 /*----------------------------------------------------------------------------- 116 * Structure used to describe protocol options such as tunneling methods, 117 * authentication schemes and message types (protocol version 3.7t). 118 */ 119 120 typedef struct _rfbCapabilityInfo { 121 122 uint32_t code; /* numeric identifier */ 123 uint8_t vendorSignature[4]; /* vendor identification */ 124 uint8_t nameSignature[8]; /* abbreviated option name */ 125 126 } rfbCapabilityInfo; 127 128 #define sz_rfbCapabilityInfoVendor 4 129 #define sz_rfbCapabilityInfoName 8 130 #define sz_rfbCapabilityInfo 16 131 132 /* 133 * Vendors known by TightVNC: standard VNC/RealVNC, TridiaVNC, and TightVNC. 134 */ 135 136 #define rfbStandardVendor "STDV" 137 #define rfbTridiaVncVendor "TRDV" 138 #define rfbTightVncVendor "TGHT" 139 140 141 /* It's a good idea to keep these values a bit greater than required. */ 142 #define MAX_TIGHT_ENCODINGS 10 143 #define MAX_TUNNELING_CAPS 16 144 #define MAX_AUTH_CAPS 16 145 146 typedef struct _rfbClientFileDownload { 147 char fName[PATH_MAX]; 148 int downloadInProgress; 149 unsigned long mTime; 150 int downloadFD; 151 } rfbClientFileDownload ; 152 153 typedef struct _rfbClientFileUpload { 154 char fName[PATH_MAX]; 155 int uploadInProgress; 156 unsigned long mTime; 157 unsigned long fSize; 158 int uploadFD; 159 } rfbClientFileUpload ; 160 161 typedef struct _rfbClientFileTransfer { 162 rfbClientFileDownload rcfd; 163 rfbClientFileUpload rcfu; 164 } rfbClientFileTransfer; 165 166 167 typedef struct _rfbTightClientRec { 168 169 /* Lists of capability codes sent to clients. We remember these 170 lists to restrict clients from choosing those tunneling and 171 authentication types that were not advertised. */ 172 173 int nAuthCaps; 174 uint32_t authCaps[MAX_AUTH_CAPS]; 175 176 /* This is not useful while we don't support tunneling: 177 int nTunnelingCaps; 178 uint32_t tunnelingCaps[MAX_TUNNELING_CAPS]; */ 179 180 rfbClientFileTransfer rcft; 181 182 } rfbTightClientRec, *rfbTightClientPtr; 183 184 /* 185 * Macro to fill in an rfbCapabilityInfo structure (protocol 3.7t). 186 * Normally, using macros is no good, but this macro saves us from 187 * writing constants twice -- it constructs signature names from codes. 188 * Note that "code_sym" argument should be a single symbol, not an expression. 189 */ 190 191 #define SetCapInfo(cap_ptr, code_sym, vendor) \ 192 { \ 193 rfbCapabilityInfo *pcap; \ 194 pcap = (cap_ptr); \ 195 pcap->code = Swap32IfLE(code_sym); \ 196 memcpy(pcap->vendorSignature, (vendor), \ 197 sz_rfbCapabilityInfoVendor); \ 198 memcpy(pcap->nameSignature, sig_##code_sym, \ 199 sz_rfbCapabilityInfoName); \ 200 } 201 202 void rfbHandleSecTypeTight(rfbClientPtr cl); 203 204 205 /*----------------------------------------------------------------------------- 206 * Server Interaction Capabilities Message (protocol version 3.7t) 207 * 208 * In the protocol version 3.7t, the server informs the client what message 209 * types it supports in addition to ones defined in the protocol version 3.7. 210 * Also, the server sends the list of all supported encodings (note that it's 211 * not necessary to advertise the "raw" encoding sinse it MUST be supported in 212 * RFB 3.x protocols). 213 * 214 * This data immediately follows the server initialisation message. 215 */ 216 217 typedef struct _rfbInteractionCapsMsg { 218 uint16_t nServerMessageTypes; 219 uint16_t nClientMessageTypes; 220 uint16_t nEncodingTypes; 221 uint16_t pad; /* reserved, must be 0 */ 222 /* followed by nServerMessageTypes * rfbCapabilityInfo structures */ 223 /* followed by nClientMessageTypes * rfbCapabilityInfo structures */ 224 } rfbInteractionCapsMsg; 225 226 #define sz_rfbInteractionCapsMsg 8 227 228 #define rfbFileListData 130 229 #define rfbFileDownloadData 131 230 #define rfbFileUploadCancel 132 231 #define rfbFileDownloadFailed 133 232 233 /* signatures for non-standard messages */ 234 #define sig_rfbFileListData "FTS_LSDT" 235 #define sig_rfbFileDownloadData "FTS_DNDT" 236 #define sig_rfbFileUploadCancel "FTS_UPCN" 237 #define sig_rfbFileDownloadFailed "FTS_DNFL" 238 239 240 241 #define rfbFileListRequest 130 242 #define rfbFileDownloadRequest 131 243 #define rfbFileUploadRequest 132 244 #define rfbFileUploadData 133 245 #define rfbFileDownloadCancel 134 246 #define rfbFileUploadFailed 135 247 #define rfbFileCreateDirRequest 136 248 249 /* signatures for non-standard messages */ 250 #define sig_rfbFileListRequest "FTC_LSRQ" 251 #define sig_rfbFileDownloadRequest "FTC_DNRQ" 252 #define sig_rfbFileUploadRequest "FTC_UPRQ" 253 #define sig_rfbFileUploadData "FTC_UPDT" 254 #define sig_rfbFileDownloadCancel "FTC_DNCN" 255 #define sig_rfbFileUploadFailed "FTC_UPFL" 256 #define sig_rfbFileCreateDirRequest "FTC_FCDR" 257 258 259 /* signatures for basic encoding types */ 260 #define sig_rfbEncodingRaw "RAW_____" 261 #define sig_rfbEncodingCopyRect "COPYRECT" 262 #define sig_rfbEncodingRRE "RRE_____" 263 #define sig_rfbEncodingCoRRE "CORRE___" 264 #define sig_rfbEncodingHextile "HEXTILE_" 265 #define sig_rfbEncodingZlib "ZLIB____" 266 #define sig_rfbEncodingTight "TIGHT___" 267 #define sig_rfbEncodingZlibHex "ZLIBHEX_" 268 269 270 /* signatures for "fake" encoding types */ 271 #define sig_rfbEncodingCompressLevel0 "COMPRLVL" 272 #define sig_rfbEncodingXCursor "X11CURSR" 273 #define sig_rfbEncodingRichCursor "RCHCURSR" 274 #define sig_rfbEncodingPointerPos "POINTPOS" 275 #define sig_rfbEncodingLastRect "LASTRECT" 276 #define sig_rfbEncodingNewFBSize "NEWFBSIZ" 277 #define sig_rfbEncodingQualityLevel0 "JPEGQLVL" 278 279 280 /*----------------------------------------------------------------------------- 281 * FileListRequest 282 */ 283 284 typedef struct _rfbFileListRequestMsg { 285 uint8_t type; 286 uint8_t flags; 287 uint16_t dirNameSize; 288 /* Followed by char Dirname[dirNameSize] */ 289 } rfbFileListRequestMsg; 290 291 #define sz_rfbFileListRequestMsg 4 292 293 /*----------------------------------------------------------------------------- 294 * FileDownloadRequest 295 */ 296 297 typedef struct _rfbFileDownloadRequestMsg { 298 uint8_t type; 299 uint8_t compressedLevel; 300 uint16_t fNameSize; 301 uint32_t position; 302 /* Followed by char Filename[fNameSize] */ 303 } rfbFileDownloadRequestMsg; 304 305 #define sz_rfbFileDownloadRequestMsg 8 306 307 /*----------------------------------------------------------------------------- 308 * FileUploadRequest 309 */ 310 311 typedef struct _rfbFileUploadRequestMsg { 312 uint8_t type; 313 uint8_t compressedLevel; 314 uint16_t fNameSize; 315 uint32_t position; 316 /* Followed by char Filename[fNameSize] */ 317 } rfbFileUploadRequestMsg; 318 319 #define sz_rfbFileUploadRequestMsg 8 320 321 322 /*----------------------------------------------------------------------------- 323 * FileUploadData 324 */ 325 326 typedef struct _rfbFileUploadDataMsg { 327 uint8_t type; 328 uint8_t compressedLevel; 329 uint16_t realSize; 330 uint16_t compressedSize; 331 /* Followed by File[compressedSize], 332 but if (realSize = compressedSize = 0) followed by uint32_t modTime */ 333 } rfbFileUploadDataMsg; 334 335 #define sz_rfbFileUploadDataMsg 6 336 337 /*----------------------------------------------------------------------------- 338 * FileDownloadCancel 339 */ 340 341 typedef struct _rfbFileDownloadCancelMsg { 342 uint8_t type; 343 uint8_t unused; 344 uint16_t reasonLen; 345 /* Followed by reason[reasonLen] */ 346 } rfbFileDownloadCancelMsg; 347 348 #define sz_rfbFileDownloadCancelMsg 4 349 350 /*----------------------------------------------------------------------------- 351 * FileUploadFailed 352 */ 353 354 typedef struct _rfbFileUploadFailedMsg { 355 uint8_t type; 356 uint8_t unused; 357 uint16_t reasonLen; 358 /* Followed by reason[reasonLen] */ 359 } rfbFileUploadFailedMsg; 360 361 #define sz_rfbFileUploadFailedMsg 4 362 363 /*----------------------------------------------------------------------------- 364 * FileCreateDirRequest 365 */ 366 367 typedef struct _rfbFileCreateDirRequestMsg { 368 uint8_t type; 369 uint8_t unused; 370 uint16_t dNameLen; 371 /* Followed by dName[dNameLen] */ 372 } rfbFileCreateDirRequestMsg; 373 374 #define sz_rfbFileCreateDirRequestMsg 4 375 376 377 /*----------------------------------------------------------------------------- 378 * Union of all client->server messages. 379 */ 380 381 typedef union _rfbClientToServerTightMsg { 382 rfbFileListRequestMsg flr; 383 rfbFileDownloadRequestMsg fdr; 384 rfbFileUploadRequestMsg fupr; 385 rfbFileUploadDataMsg fud; 386 rfbFileDownloadCancelMsg fdc; 387 rfbFileUploadFailedMsg fuf; 388 rfbFileCreateDirRequestMsg fcdr; 389 } rfbClientToServerTightMsg; 390 391 392 393 /*----------------------------------------------------------------------------- 394 * FileListData 395 */ 396 397 typedef struct _rfbFileListDataMsg { 398 uint8_t type; 399 uint8_t flags; 400 uint16_t numFiles; 401 uint16_t dataSize; 402 uint16_t compressedSize; 403 /* Followed by SizeData[numFiles] */ 404 /* Followed by Filenames[compressedSize] */ 405 } rfbFileListDataMsg; 406 407 #define sz_rfbFileListDataMsg 8 408 409 /*----------------------------------------------------------------------------- 410 * FileDownloadData 411 */ 412 413 typedef struct _rfbFileDownloadDataMsg { 414 uint8_t type; 415 uint8_t compressLevel; 416 uint16_t realSize; 417 uint16_t compressedSize; 418 /* Followed by File[copressedSize], 419 but if (realSize = compressedSize = 0) followed by uint32_t modTime */ 420 } rfbFileDownloadDataMsg; 421 422 #define sz_rfbFileDownloadDataMsg 6 423 424 425 /*----------------------------------------------------------------------------- 426 * FileUploadCancel 427 */ 428 429 typedef struct _rfbFileUploadCancelMsg { 430 uint8_t type; 431 uint8_t unused; 432 uint16_t reasonLen; 433 /* Followed by reason[reasonLen] */ 434 } rfbFileUploadCancelMsg; 435 436 #define sz_rfbFileUploadCancelMsg 4 437 438 /*----------------------------------------------------------------------------- 439 * FileDownloadFailed 440 */ 441 442 typedef struct _rfbFileDownloadFailedMsg { 443 uint8_t type; 444 uint8_t unused; 445 uint16_t reasonLen; 446 /* Followed by reason[reasonLen] */ 447 } rfbFileDownloadFailedMsg; 448 449 #define sz_rfbFileDownloadFailedMsg 4 450 451 452 453 454 #endif 455 456 457