Add files using upload-large-folder tool
Browse files- local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/aad.c +1012 -0
- local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/childsession.c +552 -0
- local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/display.h +30 -0
- local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/errinfo.h +36 -0
- local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gcc.h +40 -0
- local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/graphics.h +30 -0
- local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/heartbeat.h +43 -0
- local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/info.c +1578 -0
- local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/input.h +68 -0
- local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/nla.h +82 -0
- local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/peer.h +31 -0
- local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/rdp.h +305 -0
- local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/server.c +1974 -0
- local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/settings.c +1764 -0
- local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/state.c +85 -0
- local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/surface.c +333 -0
- local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/tcp.c +1545 -0
- local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/timezone.c +281 -0
- local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/tpkt.h +37 -0
- local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/transport.h +175 -0
local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/aad.c
ADDED
|
@@ -0,0 +1,1012 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* FreeRDP: A Remote Desktop Protocol Implementation
|
| 3 |
+
* Network Level Authentication (NLA)
|
| 4 |
+
*
|
| 5 |
+
* Copyright 2023 Isaac Klein <[email protected]>
|
| 6 |
+
*
|
| 7 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 8 |
+
* you may not use this file except in compliance with the License.
|
| 9 |
+
* You may obtain a copy of the License at
|
| 10 |
+
*
|
| 11 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
+
*
|
| 13 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 14 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 15 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 16 |
+
* See the License for the specific language governing permissions and
|
| 17 |
+
* limitations under the License.
|
| 18 |
+
*/
|
| 19 |
+
|
| 20 |
+
#include <freerdp/config.h>
|
| 21 |
+
|
| 22 |
+
#include <stdio.h>
|
| 23 |
+
#include <string.h>
|
| 24 |
+
|
| 25 |
+
#include <freerdp/crypto/crypto.h>
|
| 26 |
+
#include <freerdp/crypto/privatekey.h>
|
| 27 |
+
#include "../crypto/privatekey.h"
|
| 28 |
+
#include <freerdp/utils/http.h>
|
| 29 |
+
#include <freerdp/utils/aad.h>
|
| 30 |
+
|
| 31 |
+
#include <winpr/crypto.h>
|
| 32 |
+
#include <winpr/json.h>
|
| 33 |
+
|
| 34 |
+
#include "transport.h"
|
| 35 |
+
#include "rdp.h"
|
| 36 |
+
|
| 37 |
+
#include "aad.h"
|
| 38 |
+
|
| 39 |
+
struct rdp_aad
|
| 40 |
+
{
|
| 41 |
+
AAD_STATE state;
|
| 42 |
+
rdpContext* rdpcontext;
|
| 43 |
+
rdpTransport* transport;
|
| 44 |
+
char* access_token;
|
| 45 |
+
rdpPrivateKey* key;
|
| 46 |
+
char* kid;
|
| 47 |
+
char* nonce;
|
| 48 |
+
char* hostname;
|
| 49 |
+
char* scope;
|
| 50 |
+
wLog* log;
|
| 51 |
+
};
|
| 52 |
+
|
| 53 |
+
#ifdef WITH_AAD
|
| 54 |
+
|
| 55 |
+
static BOOL aad_fetch_wellknown(rdpAad* aad);
|
| 56 |
+
static BOOL get_encoded_rsa_params(wLog* wlog, rdpPrivateKey* key, char** e, char** n);
|
| 57 |
+
static BOOL generate_pop_key(rdpAad* aad);
|
| 58 |
+
|
| 59 |
+
WINPR_ATTR_FORMAT_ARG(2, 3)
|
| 60 |
+
static SSIZE_T stream_sprintf(wStream* s, WINPR_FORMAT_ARG const char* fmt, ...)
|
| 61 |
+
{
|
| 62 |
+
va_list ap = { 0 };
|
| 63 |
+
va_start(ap, fmt);
|
| 64 |
+
const int rc = vsnprintf(NULL, 0, fmt, ap);
|
| 65 |
+
va_end(ap);
|
| 66 |
+
|
| 67 |
+
if (rc < 0)
|
| 68 |
+
return rc;
|
| 69 |
+
|
| 70 |
+
if (!Stream_EnsureRemainingCapacity(s, (size_t)rc + 1))
|
| 71 |
+
return -1;
|
| 72 |
+
|
| 73 |
+
char* ptr = Stream_PointerAs(s, char);
|
| 74 |
+
va_start(ap, fmt);
|
| 75 |
+
const int rc2 = vsnprintf(ptr, WINPR_ASSERTING_INT_CAST(size_t, rc) + 1, fmt, ap);
|
| 76 |
+
va_end(ap);
|
| 77 |
+
if (rc != rc2)
|
| 78 |
+
return -23;
|
| 79 |
+
if (!Stream_SafeSeek(s, (size_t)rc2))
|
| 80 |
+
return -3;
|
| 81 |
+
return rc2;
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
static BOOL json_get_object(wLog* wlog, WINPR_JSON* json, const char* key, WINPR_JSON** obj)
|
| 85 |
+
{
|
| 86 |
+
WINPR_ASSERT(json);
|
| 87 |
+
WINPR_ASSERT(key);
|
| 88 |
+
|
| 89 |
+
if (!WINPR_JSON_HasObjectItem(json, key))
|
| 90 |
+
{
|
| 91 |
+
WLog_Print(wlog, WLOG_ERROR, "[json] does not contain a key '%s'", key);
|
| 92 |
+
return FALSE;
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
WINPR_JSON* prop = WINPR_JSON_GetObjectItem(json, key);
|
| 96 |
+
if (!prop)
|
| 97 |
+
{
|
| 98 |
+
WLog_Print(wlog, WLOG_ERROR, "[json] object for key '%s' is NULL", key);
|
| 99 |
+
return FALSE;
|
| 100 |
+
}
|
| 101 |
+
*obj = prop;
|
| 102 |
+
return TRUE;
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
static BOOL json_get_number(wLog* wlog, WINPR_JSON* json, const char* key, double* result)
|
| 106 |
+
{
|
| 107 |
+
BOOL rc = FALSE;
|
| 108 |
+
WINPR_JSON* prop = NULL;
|
| 109 |
+
if (!json_get_object(wlog, json, key, &prop))
|
| 110 |
+
return FALSE;
|
| 111 |
+
|
| 112 |
+
if (!WINPR_JSON_IsNumber(prop))
|
| 113 |
+
{
|
| 114 |
+
WLog_Print(wlog, WLOG_ERROR, "[json] object for key '%s' is NOT a NUMBER", key);
|
| 115 |
+
goto fail;
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
*result = WINPR_JSON_GetNumberValue(prop);
|
| 119 |
+
|
| 120 |
+
rc = TRUE;
|
| 121 |
+
fail:
|
| 122 |
+
return rc;
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
static BOOL json_get_const_string(wLog* wlog, WINPR_JSON* json, const char* key,
|
| 126 |
+
const char** result)
|
| 127 |
+
{
|
| 128 |
+
BOOL rc = FALSE;
|
| 129 |
+
WINPR_ASSERT(result);
|
| 130 |
+
|
| 131 |
+
*result = NULL;
|
| 132 |
+
|
| 133 |
+
WINPR_JSON* prop = NULL;
|
| 134 |
+
if (!json_get_object(wlog, json, key, &prop))
|
| 135 |
+
return FALSE;
|
| 136 |
+
|
| 137 |
+
if (!WINPR_JSON_IsString(prop))
|
| 138 |
+
{
|
| 139 |
+
WLog_Print(wlog, WLOG_ERROR, "[json] object for key '%s' is NOT a STRING", key);
|
| 140 |
+
goto fail;
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
const char* str = WINPR_JSON_GetStringValue(prop);
|
| 144 |
+
if (!str)
|
| 145 |
+
WLog_Print(wlog, WLOG_ERROR, "[json] object for key '%s' is NULL", key);
|
| 146 |
+
*result = str;
|
| 147 |
+
rc = str != NULL;
|
| 148 |
+
|
| 149 |
+
fail:
|
| 150 |
+
return rc;
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
+
static BOOL json_get_string_alloc(wLog* wlog, WINPR_JSON* json, const char* key, char** result)
|
| 154 |
+
{
|
| 155 |
+
const char* str = NULL;
|
| 156 |
+
if (!json_get_const_string(wlog, json, key, &str))
|
| 157 |
+
return FALSE;
|
| 158 |
+
free(*result);
|
| 159 |
+
*result = _strdup(str);
|
| 160 |
+
if (!*result)
|
| 161 |
+
WLog_Print(wlog, WLOG_ERROR, "[json] object for key '%s' strdup is NULL", key);
|
| 162 |
+
return *result != NULL;
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
static INLINE const char* aad_auth_result_to_string(DWORD code)
|
| 166 |
+
{
|
| 167 |
+
#define ERROR_CASE(cd, x) \
|
| 168 |
+
if ((cd) == (DWORD)(x)) \
|
| 169 |
+
return #x;
|
| 170 |
+
|
| 171 |
+
ERROR_CASE(code, S_OK)
|
| 172 |
+
ERROR_CASE(code, SEC_E_INVALID_TOKEN)
|
| 173 |
+
ERROR_CASE(code, E_ACCESSDENIED)
|
| 174 |
+
ERROR_CASE(code, STATUS_LOGON_FAILURE)
|
| 175 |
+
ERROR_CASE(code, STATUS_NO_LOGON_SERVERS)
|
| 176 |
+
ERROR_CASE(code, STATUS_INVALID_LOGON_HOURS)
|
| 177 |
+
ERROR_CASE(code, STATUS_INVALID_WORKSTATION)
|
| 178 |
+
ERROR_CASE(code, STATUS_PASSWORD_EXPIRED)
|
| 179 |
+
ERROR_CASE(code, STATUS_ACCOUNT_DISABLED)
|
| 180 |
+
return "Unknown error";
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
static BOOL aad_get_nonce(rdpAad* aad)
|
| 184 |
+
{
|
| 185 |
+
BOOL ret = FALSE;
|
| 186 |
+
BYTE* response = NULL;
|
| 187 |
+
long resp_code = 0;
|
| 188 |
+
size_t response_length = 0;
|
| 189 |
+
WINPR_JSON* json = NULL;
|
| 190 |
+
|
| 191 |
+
WINPR_ASSERT(aad);
|
| 192 |
+
WINPR_ASSERT(aad->rdpcontext);
|
| 193 |
+
|
| 194 |
+
rdpRdp* rdp = aad->rdpcontext->rdp;
|
| 195 |
+
WINPR_ASSERT(rdp);
|
| 196 |
+
|
| 197 |
+
WINPR_JSON* obj = WINPR_JSON_GetObjectItem(rdp->wellknown, "token_endpoint");
|
| 198 |
+
if (!obj)
|
| 199 |
+
{
|
| 200 |
+
WLog_Print(aad->log, WLOG_ERROR, "wellknown does not have 'token_endpoint', aborting");
|
| 201 |
+
return FALSE;
|
| 202 |
+
}
|
| 203 |
+
const char* url = WINPR_JSON_GetStringValue(obj);
|
| 204 |
+
if (!url)
|
| 205 |
+
{
|
| 206 |
+
WLog_Print(aad->log, WLOG_ERROR,
|
| 207 |
+
"wellknown does have 'token_endpoint=NULL' value, aborting");
|
| 208 |
+
return FALSE;
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
if (!freerdp_http_request(url, "grant_type=srv_challenge", &resp_code, &response,
|
| 212 |
+
&response_length))
|
| 213 |
+
{
|
| 214 |
+
WLog_Print(aad->log, WLOG_ERROR, "nonce request failed");
|
| 215 |
+
goto fail;
|
| 216 |
+
}
|
| 217 |
+
|
| 218 |
+
if (resp_code != HTTP_STATUS_OK)
|
| 219 |
+
{
|
| 220 |
+
WLog_Print(aad->log, WLOG_ERROR,
|
| 221 |
+
"Server unwilling to provide nonce; returned status code %li", resp_code);
|
| 222 |
+
if (response_length > 0)
|
| 223 |
+
WLog_Print(aad->log, WLOG_ERROR, "[status message] %s", response);
|
| 224 |
+
goto fail;
|
| 225 |
+
}
|
| 226 |
+
|
| 227 |
+
json = WINPR_JSON_ParseWithLength((const char*)response, response_length);
|
| 228 |
+
if (!json)
|
| 229 |
+
{
|
| 230 |
+
WLog_Print(aad->log, WLOG_ERROR, "Failed to parse nonce response");
|
| 231 |
+
goto fail;
|
| 232 |
+
}
|
| 233 |
+
|
| 234 |
+
if (!json_get_string_alloc(aad->log, json, "Nonce", &aad->nonce))
|
| 235 |
+
goto fail;
|
| 236 |
+
|
| 237 |
+
ret = TRUE;
|
| 238 |
+
|
| 239 |
+
fail:
|
| 240 |
+
free(response);
|
| 241 |
+
WINPR_JSON_Delete(json);
|
| 242 |
+
return ret;
|
| 243 |
+
}
|
| 244 |
+
|
| 245 |
+
int aad_client_begin(rdpAad* aad)
|
| 246 |
+
{
|
| 247 |
+
size_t size = 0;
|
| 248 |
+
|
| 249 |
+
WINPR_ASSERT(aad);
|
| 250 |
+
WINPR_ASSERT(aad->rdpcontext);
|
| 251 |
+
|
| 252 |
+
rdpSettings* settings = aad->rdpcontext->settings;
|
| 253 |
+
WINPR_ASSERT(settings);
|
| 254 |
+
|
| 255 |
+
freerdp* instance = aad->rdpcontext->instance;
|
| 256 |
+
WINPR_ASSERT(instance);
|
| 257 |
+
|
| 258 |
+
/* Get the host part of the hostname */
|
| 259 |
+
const char* hostname = freerdp_settings_get_string(settings, FreeRDP_AadServerHostname);
|
| 260 |
+
if (!hostname)
|
| 261 |
+
hostname = freerdp_settings_get_string(settings, FreeRDP_ServerHostname);
|
| 262 |
+
if (!hostname)
|
| 263 |
+
{
|
| 264 |
+
WLog_Print(aad->log, WLOG_ERROR, "FreeRDP_ServerHostname == NULL");
|
| 265 |
+
return -1;
|
| 266 |
+
}
|
| 267 |
+
|
| 268 |
+
aad->hostname = _strdup(hostname);
|
| 269 |
+
if (!aad->hostname)
|
| 270 |
+
{
|
| 271 |
+
WLog_Print(aad->log, WLOG_ERROR, "_strdup(FreeRDP_ServerHostname) == NULL");
|
| 272 |
+
return -1;
|
| 273 |
+
}
|
| 274 |
+
|
| 275 |
+
char* p = strchr(aad->hostname, '.');
|
| 276 |
+
if (p)
|
| 277 |
+
*p = '\0';
|
| 278 |
+
|
| 279 |
+
if (winpr_asprintf(&aad->scope, &size,
|
| 280 |
+
"ms-device-service%%3A%%2F%%2Ftermsrv.wvd.microsoft.com%%2Fname%%2F%s%%"
|
| 281 |
+
"2Fuser_impersonation",
|
| 282 |
+
aad->hostname) <= 0)
|
| 283 |
+
return -1;
|
| 284 |
+
|
| 285 |
+
if (!generate_pop_key(aad))
|
| 286 |
+
return -1;
|
| 287 |
+
|
| 288 |
+
/* Obtain an oauth authorization code */
|
| 289 |
+
if (!instance->GetAccessToken)
|
| 290 |
+
{
|
| 291 |
+
WLog_Print(aad->log, WLOG_ERROR, "instance->GetAccessToken == NULL");
|
| 292 |
+
return -1;
|
| 293 |
+
}
|
| 294 |
+
|
| 295 |
+
if (!aad_fetch_wellknown(aad))
|
| 296 |
+
return -1;
|
| 297 |
+
|
| 298 |
+
const BOOL arc = instance->GetAccessToken(instance, ACCESS_TOKEN_TYPE_AAD, &aad->access_token,
|
| 299 |
+
2, aad->scope, aad->kid);
|
| 300 |
+
if (!arc)
|
| 301 |
+
{
|
| 302 |
+
WLog_Print(aad->log, WLOG_ERROR, "Unable to obtain access token");
|
| 303 |
+
return -1;
|
| 304 |
+
}
|
| 305 |
+
|
| 306 |
+
/* Send the nonce request message */
|
| 307 |
+
if (!aad_get_nonce(aad))
|
| 308 |
+
{
|
| 309 |
+
WLog_Print(aad->log, WLOG_ERROR, "Unable to obtain nonce");
|
| 310 |
+
return -1;
|
| 311 |
+
}
|
| 312 |
+
|
| 313 |
+
return 1;
|
| 314 |
+
}
|
| 315 |
+
|
| 316 |
+
static char* aad_create_jws_header(rdpAad* aad)
|
| 317 |
+
{
|
| 318 |
+
WINPR_ASSERT(aad);
|
| 319 |
+
|
| 320 |
+
/* Construct the base64url encoded JWS header */
|
| 321 |
+
char* buffer = NULL;
|
| 322 |
+
size_t bufferlen = 0;
|
| 323 |
+
const int length =
|
| 324 |
+
winpr_asprintf(&buffer, &bufferlen, "{\"alg\":\"RS256\",\"kid\":\"%s\"}", aad->kid);
|
| 325 |
+
if (length < 0)
|
| 326 |
+
return NULL;
|
| 327 |
+
|
| 328 |
+
char* jws_header = crypto_base64url_encode((const BYTE*)buffer, bufferlen);
|
| 329 |
+
free(buffer);
|
| 330 |
+
return jws_header;
|
| 331 |
+
}
|
| 332 |
+
|
| 333 |
+
static char* aad_create_jws_payload(rdpAad* aad, const char* ts_nonce)
|
| 334 |
+
{
|
| 335 |
+
const time_t ts = time(NULL);
|
| 336 |
+
|
| 337 |
+
WINPR_ASSERT(aad);
|
| 338 |
+
|
| 339 |
+
char* e = NULL;
|
| 340 |
+
char* n = NULL;
|
| 341 |
+
if (!get_encoded_rsa_params(aad->log, aad->key, &e, &n))
|
| 342 |
+
return NULL;
|
| 343 |
+
|
| 344 |
+
/* Construct the base64url encoded JWS payload */
|
| 345 |
+
char* buffer = NULL;
|
| 346 |
+
size_t bufferlen = 0;
|
| 347 |
+
const int length =
|
| 348 |
+
winpr_asprintf(&buffer, &bufferlen,
|
| 349 |
+
"{"
|
| 350 |
+
"\"ts\":\"%li\","
|
| 351 |
+
"\"at\":\"%s\","
|
| 352 |
+
"\"u\":\"ms-device-service://termsrv.wvd.microsoft.com/name/%s\","
|
| 353 |
+
"\"nonce\":\"%s\","
|
| 354 |
+
"\"cnf\":{\"jwk\":{\"kty\":\"RSA\",\"e\":\"%s\",\"n\":\"%s\"}},"
|
| 355 |
+
"\"client_claims\":\"{\\\"aad_nonce\\\":\\\"%s\\\"}\""
|
| 356 |
+
"}",
|
| 357 |
+
ts, aad->access_token, aad->hostname, ts_nonce, e, n, aad->nonce);
|
| 358 |
+
free(e);
|
| 359 |
+
free(n);
|
| 360 |
+
|
| 361 |
+
if (length < 0)
|
| 362 |
+
return NULL;
|
| 363 |
+
|
| 364 |
+
char* jws_payload = crypto_base64url_encode((BYTE*)buffer, bufferlen);
|
| 365 |
+
free(buffer);
|
| 366 |
+
return jws_payload;
|
| 367 |
+
}
|
| 368 |
+
|
| 369 |
+
static BOOL aad_update_digest(rdpAad* aad, WINPR_DIGEST_CTX* ctx, const char* what)
|
| 370 |
+
{
|
| 371 |
+
WINPR_ASSERT(aad);
|
| 372 |
+
WINPR_ASSERT(ctx);
|
| 373 |
+
WINPR_ASSERT(what);
|
| 374 |
+
|
| 375 |
+
const BOOL dsu1 = winpr_DigestSign_Update(ctx, what, strlen(what));
|
| 376 |
+
if (!dsu1)
|
| 377 |
+
{
|
| 378 |
+
WLog_Print(aad->log, WLOG_ERROR, "winpr_DigestSign_Update [%s] failed", what);
|
| 379 |
+
return FALSE;
|
| 380 |
+
}
|
| 381 |
+
return TRUE;
|
| 382 |
+
}
|
| 383 |
+
|
| 384 |
+
static char* aad_final_digest(rdpAad* aad, WINPR_DIGEST_CTX* ctx)
|
| 385 |
+
{
|
| 386 |
+
char* jws_signature = NULL;
|
| 387 |
+
|
| 388 |
+
WINPR_ASSERT(aad);
|
| 389 |
+
WINPR_ASSERT(ctx);
|
| 390 |
+
|
| 391 |
+
size_t siglen = 0;
|
| 392 |
+
const int dsf = winpr_DigestSign_Final(ctx, NULL, &siglen);
|
| 393 |
+
if (dsf <= 0)
|
| 394 |
+
{
|
| 395 |
+
WLog_Print(aad->log, WLOG_ERROR, "winpr_DigestSign_Final failed with %d", dsf);
|
| 396 |
+
return FALSE;
|
| 397 |
+
}
|
| 398 |
+
|
| 399 |
+
char* buffer = calloc(siglen + 1, sizeof(char));
|
| 400 |
+
if (!buffer)
|
| 401 |
+
{
|
| 402 |
+
WLog_Print(aad->log, WLOG_ERROR, "calloc %" PRIuz " bytes failed", siglen + 1);
|
| 403 |
+
goto fail;
|
| 404 |
+
}
|
| 405 |
+
|
| 406 |
+
size_t fsiglen = siglen;
|
| 407 |
+
const int dsf2 = winpr_DigestSign_Final(ctx, (BYTE*)buffer, &fsiglen);
|
| 408 |
+
if (dsf2 <= 0)
|
| 409 |
+
{
|
| 410 |
+
WLog_Print(aad->log, WLOG_ERROR, "winpr_DigestSign_Final failed with %d", dsf2);
|
| 411 |
+
goto fail;
|
| 412 |
+
}
|
| 413 |
+
|
| 414 |
+
if (siglen != fsiglen)
|
| 415 |
+
{
|
| 416 |
+
WLog_Print(aad->log, WLOG_ERROR,
|
| 417 |
+
"winpr_DigestSignFinal returned different sizes, first %" PRIuz " then %" PRIuz,
|
| 418 |
+
siglen, fsiglen);
|
| 419 |
+
goto fail;
|
| 420 |
+
}
|
| 421 |
+
jws_signature = crypto_base64url_encode((const BYTE*)buffer, fsiglen);
|
| 422 |
+
fail:
|
| 423 |
+
free(buffer);
|
| 424 |
+
return jws_signature;
|
| 425 |
+
}
|
| 426 |
+
|
| 427 |
+
static char* aad_create_jws_signature(rdpAad* aad, const char* jws_header, const char* jws_payload)
|
| 428 |
+
{
|
| 429 |
+
char* jws_signature = NULL;
|
| 430 |
+
|
| 431 |
+
WINPR_ASSERT(aad);
|
| 432 |
+
|
| 433 |
+
WINPR_DIGEST_CTX* md_ctx = freerdp_key_digest_sign(aad->key, WINPR_MD_SHA256);
|
| 434 |
+
if (!md_ctx)
|
| 435 |
+
{
|
| 436 |
+
WLog_Print(aad->log, WLOG_ERROR, "winpr_Digest_New failed");
|
| 437 |
+
goto fail;
|
| 438 |
+
}
|
| 439 |
+
|
| 440 |
+
if (!aad_update_digest(aad, md_ctx, jws_header))
|
| 441 |
+
goto fail;
|
| 442 |
+
if (!aad_update_digest(aad, md_ctx, "."))
|
| 443 |
+
goto fail;
|
| 444 |
+
if (!aad_update_digest(aad, md_ctx, jws_payload))
|
| 445 |
+
goto fail;
|
| 446 |
+
|
| 447 |
+
jws_signature = aad_final_digest(aad, md_ctx);
|
| 448 |
+
fail:
|
| 449 |
+
winpr_Digest_Free(md_ctx);
|
| 450 |
+
return jws_signature;
|
| 451 |
+
}
|
| 452 |
+
|
| 453 |
+
static int aad_send_auth_request(rdpAad* aad, const char* ts_nonce)
|
| 454 |
+
{
|
| 455 |
+
int ret = -1;
|
| 456 |
+
char* jws_header = NULL;
|
| 457 |
+
char* jws_payload = NULL;
|
| 458 |
+
char* jws_signature = NULL;
|
| 459 |
+
|
| 460 |
+
WINPR_ASSERT(aad);
|
| 461 |
+
WINPR_ASSERT(ts_nonce);
|
| 462 |
+
|
| 463 |
+
wStream* s = Stream_New(NULL, 1024);
|
| 464 |
+
if (!s)
|
| 465 |
+
goto fail;
|
| 466 |
+
|
| 467 |
+
/* Construct the base64url encoded JWS header */
|
| 468 |
+
jws_header = aad_create_jws_header(aad);
|
| 469 |
+
if (!jws_header)
|
| 470 |
+
goto fail;
|
| 471 |
+
|
| 472 |
+
/* Construct the base64url encoded JWS payload */
|
| 473 |
+
jws_payload = aad_create_jws_payload(aad, ts_nonce);
|
| 474 |
+
if (!jws_payload)
|
| 475 |
+
goto fail;
|
| 476 |
+
|
| 477 |
+
/* Sign the JWS with the pop key */
|
| 478 |
+
jws_signature = aad_create_jws_signature(aad, jws_header, jws_payload);
|
| 479 |
+
if (!jws_signature)
|
| 480 |
+
goto fail;
|
| 481 |
+
|
| 482 |
+
/* Construct the Authentication Request PDU with the JWS as the RDP Assertion */
|
| 483 |
+
if (stream_sprintf(s, "{\"rdp_assertion\":\"%s.%s.%s\"}", jws_header, jws_payload,
|
| 484 |
+
jws_signature) < 0)
|
| 485 |
+
goto fail;
|
| 486 |
+
|
| 487 |
+
/* Include null terminator in PDU */
|
| 488 |
+
Stream_Write_UINT8(s, 0);
|
| 489 |
+
|
| 490 |
+
Stream_SealLength(s);
|
| 491 |
+
|
| 492 |
+
if (transport_write(aad->transport, s) < 0)
|
| 493 |
+
{
|
| 494 |
+
WLog_Print(aad->log, WLOG_ERROR, "transport_write [%" PRIdz " bytes] failed",
|
| 495 |
+
Stream_Length(s));
|
| 496 |
+
}
|
| 497 |
+
else
|
| 498 |
+
{
|
| 499 |
+
ret = 1;
|
| 500 |
+
aad->state = AAD_STATE_AUTH;
|
| 501 |
+
}
|
| 502 |
+
fail:
|
| 503 |
+
Stream_Free(s, TRUE);
|
| 504 |
+
free(jws_header);
|
| 505 |
+
free(jws_payload);
|
| 506 |
+
free(jws_signature);
|
| 507 |
+
|
| 508 |
+
return ret;
|
| 509 |
+
}
|
| 510 |
+
|
| 511 |
+
static int aad_parse_state_initial(rdpAad* aad, wStream* s)
|
| 512 |
+
{
|
| 513 |
+
const char* jstr = Stream_PointerAs(s, char);
|
| 514 |
+
const size_t jlen = Stream_GetRemainingLength(s);
|
| 515 |
+
const char* ts_nonce = NULL;
|
| 516 |
+
int ret = -1;
|
| 517 |
+
WINPR_JSON* json = NULL;
|
| 518 |
+
|
| 519 |
+
if (!Stream_SafeSeek(s, jlen))
|
| 520 |
+
goto fail;
|
| 521 |
+
|
| 522 |
+
json = WINPR_JSON_ParseWithLength(jstr, jlen);
|
| 523 |
+
if (!json)
|
| 524 |
+
goto fail;
|
| 525 |
+
|
| 526 |
+
if (!json_get_const_string(aad->log, json, "ts_nonce", &ts_nonce))
|
| 527 |
+
goto fail;
|
| 528 |
+
|
| 529 |
+
ret = aad_send_auth_request(aad, ts_nonce);
|
| 530 |
+
fail:
|
| 531 |
+
WINPR_JSON_Delete(json);
|
| 532 |
+
return ret;
|
| 533 |
+
}
|
| 534 |
+
|
| 535 |
+
static int aad_parse_state_auth(rdpAad* aad, wStream* s)
|
| 536 |
+
{
|
| 537 |
+
int rc = -1;
|
| 538 |
+
double result = 0;
|
| 539 |
+
DWORD error_code = 0;
|
| 540 |
+
WINPR_JSON* json = NULL;
|
| 541 |
+
const char* jstr = Stream_PointerAs(s, char);
|
| 542 |
+
const size_t jlength = Stream_GetRemainingLength(s);
|
| 543 |
+
|
| 544 |
+
if (!Stream_SafeSeek(s, jlength))
|
| 545 |
+
goto fail;
|
| 546 |
+
|
| 547 |
+
json = WINPR_JSON_ParseWithLength(jstr, jlength);
|
| 548 |
+
if (!json)
|
| 549 |
+
goto fail;
|
| 550 |
+
|
| 551 |
+
if (!json_get_number(aad->log, json, "authentication_result", &result))
|
| 552 |
+
goto fail;
|
| 553 |
+
error_code = (DWORD)result;
|
| 554 |
+
|
| 555 |
+
if (error_code != S_OK)
|
| 556 |
+
{
|
| 557 |
+
WLog_Print(aad->log, WLOG_ERROR, "Authentication result: %s (0x%08" PRIx32 ")",
|
| 558 |
+
aad_auth_result_to_string(error_code), error_code);
|
| 559 |
+
goto fail;
|
| 560 |
+
}
|
| 561 |
+
aad->state = AAD_STATE_FINAL;
|
| 562 |
+
rc = 1;
|
| 563 |
+
fail:
|
| 564 |
+
WINPR_JSON_Delete(json);
|
| 565 |
+
return rc;
|
| 566 |
+
}
|
| 567 |
+
|
| 568 |
+
int aad_recv(rdpAad* aad, wStream* s)
|
| 569 |
+
{
|
| 570 |
+
WINPR_ASSERT(aad);
|
| 571 |
+
WINPR_ASSERT(s);
|
| 572 |
+
|
| 573 |
+
switch (aad->state)
|
| 574 |
+
{
|
| 575 |
+
case AAD_STATE_INITIAL:
|
| 576 |
+
return aad_parse_state_initial(aad, s);
|
| 577 |
+
case AAD_STATE_AUTH:
|
| 578 |
+
return aad_parse_state_auth(aad, s);
|
| 579 |
+
case AAD_STATE_FINAL:
|
| 580 |
+
default:
|
| 581 |
+
WLog_Print(aad->log, WLOG_ERROR, "Invalid AAD_STATE %d", aad->state);
|
| 582 |
+
return -1;
|
| 583 |
+
}
|
| 584 |
+
}
|
| 585 |
+
|
| 586 |
+
static BOOL generate_rsa_2048(rdpAad* aad)
|
| 587 |
+
{
|
| 588 |
+
WINPR_ASSERT(aad);
|
| 589 |
+
return freerdp_key_generate(aad->key, 2048);
|
| 590 |
+
}
|
| 591 |
+
|
| 592 |
+
static char* generate_rsa_digest_base64_str(rdpAad* aad, const char* input, size_t ilen)
|
| 593 |
+
{
|
| 594 |
+
char* b64 = NULL;
|
| 595 |
+
WINPR_DIGEST_CTX* digest = winpr_Digest_New();
|
| 596 |
+
if (!digest)
|
| 597 |
+
{
|
| 598 |
+
WLog_Print(aad->log, WLOG_ERROR, "winpr_Digest_New failed");
|
| 599 |
+
goto fail;
|
| 600 |
+
}
|
| 601 |
+
|
| 602 |
+
if (!winpr_Digest_Init(digest, WINPR_MD_SHA256))
|
| 603 |
+
{
|
| 604 |
+
WLog_Print(aad->log, WLOG_ERROR, "winpr_Digest_Init(WINPR_MD_SHA256) failed");
|
| 605 |
+
goto fail;
|
| 606 |
+
}
|
| 607 |
+
|
| 608 |
+
if (!winpr_Digest_Update(digest, (const BYTE*)input, ilen))
|
| 609 |
+
{
|
| 610 |
+
WLog_Print(aad->log, WLOG_ERROR, "winpr_Digest_Update(%" PRIuz ") failed", ilen);
|
| 611 |
+
goto fail;
|
| 612 |
+
}
|
| 613 |
+
|
| 614 |
+
BYTE hash[WINPR_SHA256_DIGEST_LENGTH] = { 0 };
|
| 615 |
+
if (!winpr_Digest_Final(digest, hash, sizeof(hash)))
|
| 616 |
+
{
|
| 617 |
+
WLog_Print(aad->log, WLOG_ERROR, "winpr_Digest_Final(%" PRIuz ") failed", sizeof(hash));
|
| 618 |
+
goto fail;
|
| 619 |
+
}
|
| 620 |
+
|
| 621 |
+
/* Base64url encode the hash */
|
| 622 |
+
b64 = crypto_base64url_encode(hash, sizeof(hash));
|
| 623 |
+
|
| 624 |
+
fail:
|
| 625 |
+
winpr_Digest_Free(digest);
|
| 626 |
+
return b64;
|
| 627 |
+
}
|
| 628 |
+
|
| 629 |
+
static BOOL generate_json_base64_str(rdpAad* aad, const char* b64_hash)
|
| 630 |
+
{
|
| 631 |
+
WINPR_ASSERT(aad);
|
| 632 |
+
|
| 633 |
+
char* buffer = NULL;
|
| 634 |
+
size_t blen = 0;
|
| 635 |
+
const int length = winpr_asprintf(&buffer, &blen, "{\"kid\":\"%s\"}", b64_hash);
|
| 636 |
+
if (length < 0)
|
| 637 |
+
return FALSE;
|
| 638 |
+
|
| 639 |
+
/* Finally, base64url encode the JSON text to form the kid */
|
| 640 |
+
free(aad->kid);
|
| 641 |
+
aad->kid = crypto_base64url_encode((const BYTE*)buffer, (size_t)length);
|
| 642 |
+
free(buffer);
|
| 643 |
+
|
| 644 |
+
if (!aad->kid)
|
| 645 |
+
{
|
| 646 |
+
return FALSE;
|
| 647 |
+
}
|
| 648 |
+
return TRUE;
|
| 649 |
+
}
|
| 650 |
+
|
| 651 |
+
BOOL generate_pop_key(rdpAad* aad)
|
| 652 |
+
{
|
| 653 |
+
BOOL ret = FALSE;
|
| 654 |
+
char* buffer = NULL;
|
| 655 |
+
char* b64_hash = NULL;
|
| 656 |
+
char* e = NULL;
|
| 657 |
+
char* n = NULL;
|
| 658 |
+
|
| 659 |
+
WINPR_ASSERT(aad);
|
| 660 |
+
|
| 661 |
+
/* Generate a 2048-bit RSA key pair */
|
| 662 |
+
if (!generate_rsa_2048(aad))
|
| 663 |
+
goto fail;
|
| 664 |
+
|
| 665 |
+
/* Encode the public key as a JWK */
|
| 666 |
+
if (!get_encoded_rsa_params(aad->log, aad->key, &e, &n))
|
| 667 |
+
goto fail;
|
| 668 |
+
|
| 669 |
+
size_t blen = 0;
|
| 670 |
+
const int alen =
|
| 671 |
+
winpr_asprintf(&buffer, &blen, "{\"e\":\"%s\",\"kty\":\"RSA\",\"n\":\"%s\"}", e, n);
|
| 672 |
+
if (alen < 0)
|
| 673 |
+
goto fail;
|
| 674 |
+
|
| 675 |
+
/* Hash the encoded public key */
|
| 676 |
+
b64_hash = generate_rsa_digest_base64_str(aad, buffer, blen);
|
| 677 |
+
if (!b64_hash)
|
| 678 |
+
goto fail;
|
| 679 |
+
|
| 680 |
+
/* Encode a JSON object with a single property "kid" whose value is the encoded hash */
|
| 681 |
+
ret = generate_json_base64_str(aad, b64_hash);
|
| 682 |
+
|
| 683 |
+
fail:
|
| 684 |
+
free(b64_hash);
|
| 685 |
+
free(buffer);
|
| 686 |
+
free(e);
|
| 687 |
+
free(n);
|
| 688 |
+
return ret;
|
| 689 |
+
}
|
| 690 |
+
|
| 691 |
+
static char* bn_to_base64_url(wLog* wlog, rdpPrivateKey* key, enum FREERDP_KEY_PARAM param)
|
| 692 |
+
{
|
| 693 |
+
WINPR_ASSERT(wlog);
|
| 694 |
+
WINPR_ASSERT(key);
|
| 695 |
+
|
| 696 |
+
size_t len = 0;
|
| 697 |
+
BYTE* bn = freerdp_key_get_param(key, param, &len);
|
| 698 |
+
if (!bn)
|
| 699 |
+
return NULL;
|
| 700 |
+
|
| 701 |
+
char* b64 = crypto_base64url_encode(bn, len);
|
| 702 |
+
free(bn);
|
| 703 |
+
|
| 704 |
+
if (!b64)
|
| 705 |
+
WLog_Print(wlog, WLOG_ERROR, "failed base64 url encode BIGNUM");
|
| 706 |
+
|
| 707 |
+
return b64;
|
| 708 |
+
}
|
| 709 |
+
|
| 710 |
+
BOOL get_encoded_rsa_params(wLog* wlog, rdpPrivateKey* key, char** pe, char** pn)
|
| 711 |
+
{
|
| 712 |
+
BOOL rc = FALSE;
|
| 713 |
+
char* e = NULL;
|
| 714 |
+
char* n = NULL;
|
| 715 |
+
|
| 716 |
+
WINPR_ASSERT(wlog);
|
| 717 |
+
WINPR_ASSERT(key);
|
| 718 |
+
WINPR_ASSERT(pe);
|
| 719 |
+
WINPR_ASSERT(pn);
|
| 720 |
+
|
| 721 |
+
*pe = NULL;
|
| 722 |
+
*pn = NULL;
|
| 723 |
+
|
| 724 |
+
e = bn_to_base64_url(wlog, key, FREERDP_KEY_PARAM_RSA_E);
|
| 725 |
+
if (!e)
|
| 726 |
+
{
|
| 727 |
+
WLog_Print(wlog, WLOG_ERROR, "failed base64 url encode RSA E");
|
| 728 |
+
goto fail;
|
| 729 |
+
}
|
| 730 |
+
|
| 731 |
+
n = bn_to_base64_url(wlog, key, FREERDP_KEY_PARAM_RSA_N);
|
| 732 |
+
if (!n)
|
| 733 |
+
{
|
| 734 |
+
WLog_Print(wlog, WLOG_ERROR, "failed base64 url encode RSA N");
|
| 735 |
+
goto fail;
|
| 736 |
+
}
|
| 737 |
+
|
| 738 |
+
rc = TRUE;
|
| 739 |
+
fail:
|
| 740 |
+
if (!rc)
|
| 741 |
+
{
|
| 742 |
+
free(e);
|
| 743 |
+
free(n);
|
| 744 |
+
}
|
| 745 |
+
else
|
| 746 |
+
{
|
| 747 |
+
*pe = e;
|
| 748 |
+
*pn = n;
|
| 749 |
+
}
|
| 750 |
+
return rc;
|
| 751 |
+
}
|
| 752 |
+
#else
|
| 753 |
+
int aad_client_begin(rdpAad* aad)
|
| 754 |
+
{
|
| 755 |
+
WINPR_ASSERT(aad);
|
| 756 |
+
WLog_Print(aad->log, WLOG_ERROR, "AAD security not compiled in, aborting!");
|
| 757 |
+
return -1;
|
| 758 |
+
}
|
| 759 |
+
int aad_recv(rdpAad* aad, wStream* s)
|
| 760 |
+
{
|
| 761 |
+
WINPR_ASSERT(aad);
|
| 762 |
+
WLog_Print(aad->log, WLOG_ERROR, "AAD security not compiled in, aborting!");
|
| 763 |
+
return -1;
|
| 764 |
+
}
|
| 765 |
+
#endif
|
| 766 |
+
|
| 767 |
+
rdpAad* aad_new(rdpContext* context, rdpTransport* transport)
|
| 768 |
+
{
|
| 769 |
+
WINPR_ASSERT(transport);
|
| 770 |
+
WINPR_ASSERT(context);
|
| 771 |
+
|
| 772 |
+
rdpAad* aad = (rdpAad*)calloc(1, sizeof(rdpAad));
|
| 773 |
+
|
| 774 |
+
if (!aad)
|
| 775 |
+
return NULL;
|
| 776 |
+
|
| 777 |
+
aad->log = WLog_Get(FREERDP_TAG("aad"));
|
| 778 |
+
aad->key = freerdp_key_new();
|
| 779 |
+
if (!aad->key)
|
| 780 |
+
goto fail;
|
| 781 |
+
aad->rdpcontext = context;
|
| 782 |
+
aad->transport = transport;
|
| 783 |
+
|
| 784 |
+
return aad;
|
| 785 |
+
fail:
|
| 786 |
+
WINPR_PRAGMA_DIAG_PUSH
|
| 787 |
+
WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
|
| 788 |
+
aad_free(aad);
|
| 789 |
+
WINPR_PRAGMA_DIAG_POP
|
| 790 |
+
return NULL;
|
| 791 |
+
}
|
| 792 |
+
|
| 793 |
+
void aad_free(rdpAad* aad)
|
| 794 |
+
{
|
| 795 |
+
if (!aad)
|
| 796 |
+
return;
|
| 797 |
+
|
| 798 |
+
free(aad->hostname);
|
| 799 |
+
free(aad->scope);
|
| 800 |
+
free(aad->nonce);
|
| 801 |
+
free(aad->access_token);
|
| 802 |
+
free(aad->kid);
|
| 803 |
+
freerdp_key_free(aad->key);
|
| 804 |
+
|
| 805 |
+
free(aad);
|
| 806 |
+
}
|
| 807 |
+
|
| 808 |
+
AAD_STATE aad_get_state(rdpAad* aad)
|
| 809 |
+
{
|
| 810 |
+
WINPR_ASSERT(aad);
|
| 811 |
+
return aad->state;
|
| 812 |
+
}
|
| 813 |
+
|
| 814 |
+
BOOL aad_is_supported(void)
|
| 815 |
+
{
|
| 816 |
+
#ifdef WITH_AAD
|
| 817 |
+
return TRUE;
|
| 818 |
+
#else
|
| 819 |
+
return FALSE;
|
| 820 |
+
#endif
|
| 821 |
+
}
|
| 822 |
+
|
| 823 |
+
char* freerdp_utils_aad_get_access_token(wLog* log, const char* data, size_t length)
|
| 824 |
+
{
|
| 825 |
+
char* token = NULL;
|
| 826 |
+
WINPR_JSON* access_token_prop = NULL;
|
| 827 |
+
const char* access_token_str = NULL;
|
| 828 |
+
|
| 829 |
+
WINPR_JSON* json = WINPR_JSON_ParseWithLength(data, length);
|
| 830 |
+
if (!json)
|
| 831 |
+
{
|
| 832 |
+
WLog_Print(log, WLOG_ERROR, "Failed to parse access token response [got %" PRIuz " bytes",
|
| 833 |
+
length);
|
| 834 |
+
goto cleanup;
|
| 835 |
+
}
|
| 836 |
+
|
| 837 |
+
access_token_prop = WINPR_JSON_GetObjectItem(json, "access_token");
|
| 838 |
+
if (!access_token_prop)
|
| 839 |
+
{
|
| 840 |
+
WLog_Print(log, WLOG_ERROR, "Response has no \"access_token\" property");
|
| 841 |
+
goto cleanup;
|
| 842 |
+
}
|
| 843 |
+
|
| 844 |
+
access_token_str = WINPR_JSON_GetStringValue(access_token_prop);
|
| 845 |
+
if (!access_token_str)
|
| 846 |
+
{
|
| 847 |
+
WLog_Print(log, WLOG_ERROR, "Invalid value for \"access_token\"");
|
| 848 |
+
goto cleanup;
|
| 849 |
+
}
|
| 850 |
+
|
| 851 |
+
token = _strdup(access_token_str);
|
| 852 |
+
|
| 853 |
+
cleanup:
|
| 854 |
+
WINPR_JSON_Delete(json);
|
| 855 |
+
return token;
|
| 856 |
+
}
|
| 857 |
+
|
| 858 |
+
BOOL aad_fetch_wellknown(rdpAad* aad)
|
| 859 |
+
{
|
| 860 |
+
WINPR_ASSERT(aad);
|
| 861 |
+
WINPR_ASSERT(aad->rdpcontext);
|
| 862 |
+
|
| 863 |
+
rdpRdp* rdp = aad->rdpcontext->rdp;
|
| 864 |
+
WINPR_ASSERT(rdp);
|
| 865 |
+
|
| 866 |
+
if (rdp->wellknown)
|
| 867 |
+
return TRUE;
|
| 868 |
+
|
| 869 |
+
const char* base =
|
| 870 |
+
freerdp_settings_get_string(aad->rdpcontext->settings, FreeRDP_GatewayAzureActiveDirectory);
|
| 871 |
+
const BOOL useTenant =
|
| 872 |
+
freerdp_settings_get_bool(aad->rdpcontext->settings, FreeRDP_GatewayAvdUseTenantid);
|
| 873 |
+
const char* tenantid = "common";
|
| 874 |
+
if (useTenant)
|
| 875 |
+
tenantid =
|
| 876 |
+
freerdp_settings_get_string(aad->rdpcontext->settings, FreeRDP_GatewayAvdAadtenantid);
|
| 877 |
+
rdp->wellknown = freerdp_utils_aad_get_wellknown(aad->log, base, tenantid);
|
| 878 |
+
return rdp->wellknown ? TRUE : FALSE;
|
| 879 |
+
}
|
| 880 |
+
|
| 881 |
+
const char* freerdp_utils_aad_get_wellknown_string(rdpContext* context, AAD_WELLKNOWN_VALUES which)
|
| 882 |
+
{
|
| 883 |
+
return freerdp_utils_aad_get_wellknown_custom_string(
|
| 884 |
+
context, freerdp_utils_aad_wellknwon_value_name(which));
|
| 885 |
+
}
|
| 886 |
+
|
| 887 |
+
const char* freerdp_utils_aad_get_wellknown_custom_string(rdpContext* context, const char* which)
|
| 888 |
+
{
|
| 889 |
+
WINPR_ASSERT(context);
|
| 890 |
+
WINPR_ASSERT(context->rdp);
|
| 891 |
+
|
| 892 |
+
if (!context->rdp->wellknown)
|
| 893 |
+
return NULL;
|
| 894 |
+
|
| 895 |
+
WINPR_JSON* obj = WINPR_JSON_GetObjectItem(context->rdp->wellknown, which);
|
| 896 |
+
if (!obj)
|
| 897 |
+
return NULL;
|
| 898 |
+
|
| 899 |
+
return WINPR_JSON_GetStringValue(obj);
|
| 900 |
+
}
|
| 901 |
+
|
| 902 |
+
const char* freerdp_utils_aad_wellknwon_value_name(AAD_WELLKNOWN_VALUES which)
|
| 903 |
+
{
|
| 904 |
+
switch (which)
|
| 905 |
+
{
|
| 906 |
+
case AAD_WELLKNOWN_token_endpoint:
|
| 907 |
+
return "token_endpoint";
|
| 908 |
+
case AAD_WELLKNOWN_token_endpoint_auth_methods_supported:
|
| 909 |
+
return "token_endpoint_auth_methods_supported";
|
| 910 |
+
case AAD_WELLKNOWN_jwks_uri:
|
| 911 |
+
return "jwks_uri";
|
| 912 |
+
case AAD_WELLKNOWN_response_modes_supported:
|
| 913 |
+
return "response_modes_supported";
|
| 914 |
+
case AAD_WELLKNOWN_subject_types_supported:
|
| 915 |
+
return "subject_types_supported";
|
| 916 |
+
case AAD_WELLKNOWN_id_token_signing_alg_values_supported:
|
| 917 |
+
return "id_token_signing_alg_values_supported";
|
| 918 |
+
case AAD_WELLKNOWN_response_types_supported:
|
| 919 |
+
return "response_types_supported";
|
| 920 |
+
case AAD_WELLKNOWN_scopes_supported:
|
| 921 |
+
return "scopes_supported";
|
| 922 |
+
case AAD_WELLKNOWN_issuer:
|
| 923 |
+
return "issuer";
|
| 924 |
+
case AAD_WELLKNOWN_request_uri_parameter_supported:
|
| 925 |
+
return "request_uri_parameter_supported";
|
| 926 |
+
case AAD_WELLKNOWN_userinfo_endpoint:
|
| 927 |
+
return "userinfo_endpoint";
|
| 928 |
+
case AAD_WELLKNOWN_authorization_endpoint:
|
| 929 |
+
return "authorization_endpoint";
|
| 930 |
+
case AAD_WELLKNOWN_device_authorization_endpoint:
|
| 931 |
+
return "device_authorization_endpoint";
|
| 932 |
+
case AAD_WELLKNOWN_http_logout_supported:
|
| 933 |
+
return "http_logout_supported";
|
| 934 |
+
case AAD_WELLKNOWN_frontchannel_logout_supported:
|
| 935 |
+
return "frontchannel_logout_supported";
|
| 936 |
+
case AAD_WELLKNOWN_end_session_endpoint:
|
| 937 |
+
return "end_session_endpoint";
|
| 938 |
+
case AAD_WELLKNOWN_claims_supported:
|
| 939 |
+
return "claims_supported";
|
| 940 |
+
case AAD_WELLKNOWN_kerberos_endpoint:
|
| 941 |
+
return "kerberos_endpoint";
|
| 942 |
+
case AAD_WELLKNOWN_tenant_region_scope:
|
| 943 |
+
return "tenant_region_scope";
|
| 944 |
+
case AAD_WELLKNOWN_cloud_instance_name:
|
| 945 |
+
return "cloud_instance_name";
|
| 946 |
+
case AAD_WELLKNOWN_cloud_graph_host_name:
|
| 947 |
+
return "cloud_graph_host_name";
|
| 948 |
+
case AAD_WELLKNOWN_msgraph_host:
|
| 949 |
+
return "msgraph_host";
|
| 950 |
+
case AAD_WELLKNOWN_rbac_url:
|
| 951 |
+
return "rbac_url";
|
| 952 |
+
default:
|
| 953 |
+
return "UNKNOWN";
|
| 954 |
+
}
|
| 955 |
+
}
|
| 956 |
+
|
| 957 |
+
WINPR_JSON* freerdp_utils_aad_get_wellknown_object(rdpContext* context, AAD_WELLKNOWN_VALUES which)
|
| 958 |
+
{
|
| 959 |
+
return freerdp_utils_aad_get_wellknown_custom_object(
|
| 960 |
+
context, freerdp_utils_aad_wellknwon_value_name(which));
|
| 961 |
+
}
|
| 962 |
+
|
| 963 |
+
WINPR_JSON* freerdp_utils_aad_get_wellknown_custom_object(rdpContext* context, const char* which)
|
| 964 |
+
{
|
| 965 |
+
WINPR_ASSERT(context);
|
| 966 |
+
WINPR_ASSERT(context->rdp);
|
| 967 |
+
|
| 968 |
+
if (!context->rdp->wellknown)
|
| 969 |
+
return NULL;
|
| 970 |
+
|
| 971 |
+
return WINPR_JSON_GetObjectItem(context->rdp->wellknown, which);
|
| 972 |
+
}
|
| 973 |
+
|
| 974 |
+
WINPR_ATTR_MALLOC(WINPR_JSON_Delete, 1)
|
| 975 |
+
WINPR_JSON* freerdp_utils_aad_get_wellknown(wLog* log, const char* base, const char* tenantid)
|
| 976 |
+
{
|
| 977 |
+
WINPR_ASSERT(base);
|
| 978 |
+
WINPR_ASSERT(tenantid);
|
| 979 |
+
|
| 980 |
+
char* str = NULL;
|
| 981 |
+
size_t len = 0;
|
| 982 |
+
winpr_asprintf(&str, &len, "https://%s/%s/v2.0/.well-known/openid-configuration", base,
|
| 983 |
+
tenantid);
|
| 984 |
+
|
| 985 |
+
if (!str)
|
| 986 |
+
{
|
| 987 |
+
WLog_Print(log, WLOG_ERROR, "failed to create request URL for tenantid='%s'", tenantid);
|
| 988 |
+
return NULL;
|
| 989 |
+
}
|
| 990 |
+
|
| 991 |
+
BYTE* response = NULL;
|
| 992 |
+
long resp_code = 0;
|
| 993 |
+
size_t response_length = 0;
|
| 994 |
+
const BOOL rc = freerdp_http_request(str, NULL, &resp_code, &response, &response_length);
|
| 995 |
+
if (!rc || (resp_code != HTTP_STATUS_OK))
|
| 996 |
+
{
|
| 997 |
+
WLog_Print(log, WLOG_ERROR, "request for '%s' failed with: %s", str,
|
| 998 |
+
freerdp_http_status_string(resp_code));
|
| 999 |
+
free(str);
|
| 1000 |
+
free(response);
|
| 1001 |
+
return NULL;
|
| 1002 |
+
}
|
| 1003 |
+
free(str);
|
| 1004 |
+
|
| 1005 |
+
WINPR_JSON* json = WINPR_JSON_ParseWithLength((const char*)response, response_length);
|
| 1006 |
+
free(response);
|
| 1007 |
+
|
| 1008 |
+
if (!json)
|
| 1009 |
+
WLog_Print(log, WLOG_ERROR, "failed to parse response as JSON");
|
| 1010 |
+
|
| 1011 |
+
return json;
|
| 1012 |
+
}
|
local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/childsession.c
ADDED
|
@@ -0,0 +1,552 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* FreeRDP: A Remote Desktop Protocol Implementation
|
| 3 |
+
* Named pipe transport
|
| 4 |
+
*
|
| 5 |
+
* Copyright 2023-2024 David Fort <[email protected]>
|
| 6 |
+
*
|
| 7 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 8 |
+
* you may not use this file except in compliance with the License.
|
| 9 |
+
* You may obtain a copy of the License at
|
| 10 |
+
*
|
| 11 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
+
*
|
| 13 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 14 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 15 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 16 |
+
* See the License for the specific language governing permissions and
|
| 17 |
+
* limitations under the License.
|
| 18 |
+
*/
|
| 19 |
+
|
| 20 |
+
#include "tcp.h"
|
| 21 |
+
|
| 22 |
+
#include <winpr/library.h>
|
| 23 |
+
#include <winpr/assert.h>
|
| 24 |
+
#include <winpr/print.h>
|
| 25 |
+
#include <winpr/sysinfo.h>
|
| 26 |
+
|
| 27 |
+
#include <freerdp/utils/ringbuffer.h>
|
| 28 |
+
|
| 29 |
+
#include "childsession.h"
|
| 30 |
+
|
| 31 |
+
#define TAG FREERDP_TAG("childsession")
|
| 32 |
+
|
| 33 |
+
typedef struct
|
| 34 |
+
{
|
| 35 |
+
OVERLAPPED readOverlapped;
|
| 36 |
+
HANDLE hFile;
|
| 37 |
+
BOOL opInProgress;
|
| 38 |
+
BOOL lastOpClosed;
|
| 39 |
+
RingBuffer readBuffer;
|
| 40 |
+
BOOL blocking;
|
| 41 |
+
BYTE tmpReadBuffer[4096];
|
| 42 |
+
|
| 43 |
+
HANDLE readEvent;
|
| 44 |
+
} WINPR_BIO_NAMED;
|
| 45 |
+
|
| 46 |
+
static int transport_bio_named_uninit(BIO* bio);
|
| 47 |
+
|
| 48 |
+
static int transport_bio_named_write(BIO* bio, const char* buf, int size)
|
| 49 |
+
{
|
| 50 |
+
WINPR_ASSERT(bio);
|
| 51 |
+
WINPR_ASSERT(buf);
|
| 52 |
+
|
| 53 |
+
WINPR_BIO_NAMED* ptr = (WINPR_BIO_NAMED*)BIO_get_data(bio);
|
| 54 |
+
|
| 55 |
+
if (!buf)
|
| 56 |
+
return 0;
|
| 57 |
+
|
| 58 |
+
BIO_clear_flags(bio, BIO_FLAGS_WRITE);
|
| 59 |
+
DWORD written = 0;
|
| 60 |
+
|
| 61 |
+
UINT64 start = GetTickCount64();
|
| 62 |
+
BOOL ret = WriteFile(ptr->hFile, buf, WINPR_ASSERTING_INT_CAST(uint32_t, size), &written, NULL);
|
| 63 |
+
// winpr_HexDump(TAG, WLOG_DEBUG, buf, size);
|
| 64 |
+
|
| 65 |
+
if (!ret)
|
| 66 |
+
{
|
| 67 |
+
WLog_VRB(TAG, "error or deferred");
|
| 68 |
+
return 0;
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
WLog_VRB(TAG, "(%d)=%d written=%d duration=%d", size, ret, written, GetTickCount64() - start);
|
| 72 |
+
|
| 73 |
+
if (written == 0)
|
| 74 |
+
{
|
| 75 |
+
WLog_VRB(TAG, "closed on write");
|
| 76 |
+
return 0;
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
WINPR_ASSERT(written <= INT32_MAX);
|
| 80 |
+
return (int)written;
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
static BOOL treatReadResult(WINPR_BIO_NAMED* ptr, DWORD readBytes)
|
| 84 |
+
{
|
| 85 |
+
WLog_VRB(TAG, "treatReadResult(readBytes=%" PRIu32 ")", readBytes);
|
| 86 |
+
ptr->opInProgress = FALSE;
|
| 87 |
+
if (readBytes == 0)
|
| 88 |
+
{
|
| 89 |
+
WLog_VRB(TAG, "readBytes == 0");
|
| 90 |
+
return TRUE;
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
if (!ringbuffer_write(&ptr->readBuffer, ptr->tmpReadBuffer, readBytes))
|
| 94 |
+
{
|
| 95 |
+
WLog_VRB(TAG, "ringbuffer_write()");
|
| 96 |
+
return FALSE;
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
return SetEvent(ptr->readEvent);
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
static BOOL doReadOp(WINPR_BIO_NAMED* ptr)
|
| 103 |
+
{
|
| 104 |
+
DWORD readBytes = 0;
|
| 105 |
+
|
| 106 |
+
if (!ResetEvent(ptr->readEvent))
|
| 107 |
+
return FALSE;
|
| 108 |
+
|
| 109 |
+
ptr->opInProgress = TRUE;
|
| 110 |
+
if (!ReadFile(ptr->hFile, ptr->tmpReadBuffer, sizeof(ptr->tmpReadBuffer), &readBytes,
|
| 111 |
+
&ptr->readOverlapped))
|
| 112 |
+
{
|
| 113 |
+
DWORD error = GetLastError();
|
| 114 |
+
switch (error)
|
| 115 |
+
{
|
| 116 |
+
case ERROR_NO_DATA:
|
| 117 |
+
WLog_VRB(TAG, "No Data, unexpected");
|
| 118 |
+
return TRUE;
|
| 119 |
+
case ERROR_IO_PENDING:
|
| 120 |
+
WLog_VRB(TAG, "ERROR_IO_PENDING");
|
| 121 |
+
return TRUE;
|
| 122 |
+
case ERROR_BROKEN_PIPE:
|
| 123 |
+
WLog_VRB(TAG, "broken pipe");
|
| 124 |
+
ptr->lastOpClosed = TRUE;
|
| 125 |
+
return TRUE;
|
| 126 |
+
default:
|
| 127 |
+
return FALSE;
|
| 128 |
+
}
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
return treatReadResult(ptr, readBytes);
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
static int transport_bio_named_read(BIO* bio, char* buf, int size)
|
| 135 |
+
{
|
| 136 |
+
WINPR_ASSERT(bio);
|
| 137 |
+
WINPR_ASSERT(buf);
|
| 138 |
+
|
| 139 |
+
WINPR_BIO_NAMED* ptr = (WINPR_BIO_NAMED*)BIO_get_data(bio);
|
| 140 |
+
if (!buf)
|
| 141 |
+
return 0;
|
| 142 |
+
|
| 143 |
+
BIO_clear_flags(bio, BIO_FLAGS_SHOULD_RETRY | BIO_FLAGS_READ);
|
| 144 |
+
|
| 145 |
+
if (ptr->blocking)
|
| 146 |
+
{
|
| 147 |
+
while (!ringbuffer_used(&ptr->readBuffer))
|
| 148 |
+
{
|
| 149 |
+
if (ptr->lastOpClosed)
|
| 150 |
+
return 0;
|
| 151 |
+
|
| 152 |
+
if (ptr->opInProgress)
|
| 153 |
+
{
|
| 154 |
+
DWORD status = WaitForSingleObjectEx(ptr->readEvent, 500, TRUE);
|
| 155 |
+
switch (status)
|
| 156 |
+
{
|
| 157 |
+
case WAIT_TIMEOUT:
|
| 158 |
+
case WAIT_IO_COMPLETION:
|
| 159 |
+
continue;
|
| 160 |
+
case WAIT_OBJECT_0:
|
| 161 |
+
break;
|
| 162 |
+
default:
|
| 163 |
+
return -1;
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
DWORD readBytes = 0;
|
| 167 |
+
if (!GetOverlappedResult(ptr->hFile, &ptr->readOverlapped, &readBytes, FALSE))
|
| 168 |
+
{
|
| 169 |
+
WLog_ERR(TAG, "GetOverlappedResult blocking(lastError=%" PRIu32 ")",
|
| 170 |
+
GetLastError());
|
| 171 |
+
return -1;
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
if (!treatReadResult(ptr, readBytes))
|
| 175 |
+
{
|
| 176 |
+
WLog_ERR(TAG, "treatReadResult blocking");
|
| 177 |
+
return -1;
|
| 178 |
+
}
|
| 179 |
+
}
|
| 180 |
+
}
|
| 181 |
+
}
|
| 182 |
+
else
|
| 183 |
+
{
|
| 184 |
+
if (ptr->opInProgress)
|
| 185 |
+
{
|
| 186 |
+
DWORD status = WaitForSingleObject(ptr->readEvent, 0);
|
| 187 |
+
switch (status)
|
| 188 |
+
{
|
| 189 |
+
case WAIT_OBJECT_0:
|
| 190 |
+
break;
|
| 191 |
+
case WAIT_TIMEOUT:
|
| 192 |
+
BIO_set_flags(bio, (BIO_FLAGS_SHOULD_RETRY | BIO_FLAGS_READ));
|
| 193 |
+
return -1;
|
| 194 |
+
default:
|
| 195 |
+
WLog_ERR(TAG, "error WaitForSingleObject(readEvent)=0x%" PRIx32 "", status);
|
| 196 |
+
return -1;
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
DWORD readBytes = 0;
|
| 200 |
+
if (!GetOverlappedResult(ptr->hFile, &ptr->readOverlapped, &readBytes, FALSE))
|
| 201 |
+
{
|
| 202 |
+
WLog_ERR(TAG, "GetOverlappedResult non blocking(lastError=%" PRIu32 ")",
|
| 203 |
+
GetLastError());
|
| 204 |
+
return -1;
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
if (!treatReadResult(ptr, readBytes))
|
| 208 |
+
{
|
| 209 |
+
WLog_ERR(TAG, "error treatReadResult non blocking");
|
| 210 |
+
return -1;
|
| 211 |
+
}
|
| 212 |
+
}
|
| 213 |
+
}
|
| 214 |
+
|
| 215 |
+
SSIZE_T ret = -1;
|
| 216 |
+
if (size >= 0)
|
| 217 |
+
{
|
| 218 |
+
size_t rsize = ringbuffer_used(&ptr->readBuffer);
|
| 219 |
+
if (rsize <= SSIZE_MAX)
|
| 220 |
+
ret = MIN(size, (SSIZE_T)rsize);
|
| 221 |
+
}
|
| 222 |
+
if ((size >= 0) && ret)
|
| 223 |
+
{
|
| 224 |
+
DataChunk chunks[2] = { 0 };
|
| 225 |
+
const int nchunks =
|
| 226 |
+
ringbuffer_peek(&ptr->readBuffer, chunks, WINPR_ASSERTING_INT_CAST(size_t, ret));
|
| 227 |
+
for (int i = 0; i < nchunks; i++)
|
| 228 |
+
{
|
| 229 |
+
memcpy(buf, chunks[i].data, chunks[i].size);
|
| 230 |
+
buf += chunks[i].size;
|
| 231 |
+
}
|
| 232 |
+
|
| 233 |
+
ringbuffer_commit_read_bytes(&ptr->readBuffer, WINPR_ASSERTING_INT_CAST(size_t, ret));
|
| 234 |
+
|
| 235 |
+
WLog_VRB(TAG, "(%d)=%" PRIdz " nchunks=%d", size, ret, nchunks);
|
| 236 |
+
}
|
| 237 |
+
|
| 238 |
+
if (!ringbuffer_used(&ptr->readBuffer))
|
| 239 |
+
{
|
| 240 |
+
if (!ptr->opInProgress && !doReadOp(ptr))
|
| 241 |
+
{
|
| 242 |
+
WLog_ERR(TAG, "error rearming read");
|
| 243 |
+
return -1;
|
| 244 |
+
}
|
| 245 |
+
}
|
| 246 |
+
|
| 247 |
+
if (ret <= 0)
|
| 248 |
+
BIO_set_flags(bio, (BIO_FLAGS_SHOULD_RETRY | BIO_FLAGS_READ));
|
| 249 |
+
|
| 250 |
+
WINPR_ASSERT(ret <= INT32_MAX);
|
| 251 |
+
return (int)ret;
|
| 252 |
+
}
|
| 253 |
+
|
| 254 |
+
static int transport_bio_named_puts(BIO* bio, const char* str)
|
| 255 |
+
{
|
| 256 |
+
WINPR_ASSERT(bio);
|
| 257 |
+
WINPR_ASSERT(str);
|
| 258 |
+
|
| 259 |
+
return transport_bio_named_write(bio, str, (int)strnlen(str, INT32_MAX));
|
| 260 |
+
}
|
| 261 |
+
|
| 262 |
+
static int transport_bio_named_gets(BIO* bio, char* str, int size)
|
| 263 |
+
{
|
| 264 |
+
WINPR_ASSERT(bio);
|
| 265 |
+
WINPR_ASSERT(str);
|
| 266 |
+
|
| 267 |
+
return transport_bio_named_read(bio, str, size);
|
| 268 |
+
}
|
| 269 |
+
|
| 270 |
+
static long transport_bio_named_ctrl(BIO* bio, int cmd, long arg1, void* arg2)
|
| 271 |
+
{
|
| 272 |
+
WINPR_ASSERT(bio);
|
| 273 |
+
|
| 274 |
+
int status = -1;
|
| 275 |
+
WINPR_BIO_NAMED* ptr = (WINPR_BIO_NAMED*)BIO_get_data(bio);
|
| 276 |
+
|
| 277 |
+
switch (cmd)
|
| 278 |
+
{
|
| 279 |
+
case BIO_C_SET_SOCKET:
|
| 280 |
+
case BIO_C_GET_SOCKET:
|
| 281 |
+
return -1;
|
| 282 |
+
case BIO_C_GET_EVENT:
|
| 283 |
+
if (!BIO_get_init(bio) || !arg2)
|
| 284 |
+
return 0;
|
| 285 |
+
|
| 286 |
+
*((HANDLE*)arg2) = ptr->readEvent;
|
| 287 |
+
return 1;
|
| 288 |
+
case BIO_C_SET_HANDLE:
|
| 289 |
+
BIO_set_init(bio, 1);
|
| 290 |
+
if (!BIO_get_init(bio) || !arg2)
|
| 291 |
+
return 0;
|
| 292 |
+
|
| 293 |
+
ptr->hFile = (HANDLE)arg2;
|
| 294 |
+
ptr->blocking = TRUE;
|
| 295 |
+
if (!doReadOp(ptr))
|
| 296 |
+
return -1;
|
| 297 |
+
return 1;
|
| 298 |
+
case BIO_C_SET_NONBLOCK:
|
| 299 |
+
{
|
| 300 |
+
WLog_DBG(TAG, "BIO_C_SET_NONBLOCK");
|
| 301 |
+
ptr->blocking = FALSE;
|
| 302 |
+
return 1;
|
| 303 |
+
}
|
| 304 |
+
case BIO_C_WAIT_READ:
|
| 305 |
+
{
|
| 306 |
+
WLog_DBG(TAG, "BIO_C_WAIT_READ");
|
| 307 |
+
return 1;
|
| 308 |
+
}
|
| 309 |
+
|
| 310 |
+
case BIO_C_WAIT_WRITE:
|
| 311 |
+
{
|
| 312 |
+
WLog_DBG(TAG, "BIO_C_WAIT_WRITE");
|
| 313 |
+
return 1;
|
| 314 |
+
}
|
| 315 |
+
|
| 316 |
+
default:
|
| 317 |
+
break;
|
| 318 |
+
}
|
| 319 |
+
|
| 320 |
+
switch (cmd)
|
| 321 |
+
{
|
| 322 |
+
case BIO_CTRL_GET_CLOSE:
|
| 323 |
+
status = BIO_get_shutdown(bio);
|
| 324 |
+
break;
|
| 325 |
+
|
| 326 |
+
case BIO_CTRL_SET_CLOSE:
|
| 327 |
+
BIO_set_shutdown(bio, (int)arg1);
|
| 328 |
+
status = 1;
|
| 329 |
+
break;
|
| 330 |
+
|
| 331 |
+
case BIO_CTRL_DUP:
|
| 332 |
+
status = 1;
|
| 333 |
+
break;
|
| 334 |
+
|
| 335 |
+
case BIO_CTRL_FLUSH:
|
| 336 |
+
status = 1;
|
| 337 |
+
break;
|
| 338 |
+
|
| 339 |
+
default:
|
| 340 |
+
status = 0;
|
| 341 |
+
break;
|
| 342 |
+
}
|
| 343 |
+
|
| 344 |
+
return status;
|
| 345 |
+
}
|
| 346 |
+
|
| 347 |
+
static void BIO_NAMED_free(WINPR_BIO_NAMED* ptr)
|
| 348 |
+
{
|
| 349 |
+
if (!ptr)
|
| 350 |
+
return;
|
| 351 |
+
|
| 352 |
+
if (ptr->hFile)
|
| 353 |
+
{
|
| 354 |
+
(void)CloseHandle(ptr->hFile);
|
| 355 |
+
ptr->hFile = NULL;
|
| 356 |
+
}
|
| 357 |
+
|
| 358 |
+
if (ptr->readEvent)
|
| 359 |
+
{
|
| 360 |
+
(void)CloseHandle(ptr->readEvent);
|
| 361 |
+
ptr->readEvent = NULL;
|
| 362 |
+
}
|
| 363 |
+
|
| 364 |
+
ringbuffer_destroy(&ptr->readBuffer);
|
| 365 |
+
free(ptr);
|
| 366 |
+
}
|
| 367 |
+
|
| 368 |
+
static int transport_bio_named_uninit(BIO* bio)
|
| 369 |
+
{
|
| 370 |
+
WINPR_ASSERT(bio);
|
| 371 |
+
WINPR_BIO_NAMED* ptr = (WINPR_BIO_NAMED*)BIO_get_data(bio);
|
| 372 |
+
|
| 373 |
+
BIO_NAMED_free(ptr);
|
| 374 |
+
|
| 375 |
+
BIO_set_init(bio, 0);
|
| 376 |
+
BIO_set_flags(bio, 0);
|
| 377 |
+
return 1;
|
| 378 |
+
}
|
| 379 |
+
|
| 380 |
+
static int transport_bio_named_new(BIO* bio)
|
| 381 |
+
{
|
| 382 |
+
WINPR_ASSERT(bio);
|
| 383 |
+
|
| 384 |
+
WINPR_BIO_NAMED* ptr = (WINPR_BIO_NAMED*)calloc(1, sizeof(WINPR_BIO_NAMED));
|
| 385 |
+
if (!ptr)
|
| 386 |
+
return 0;
|
| 387 |
+
|
| 388 |
+
if (!ringbuffer_init(&ptr->readBuffer, 0xfffff))
|
| 389 |
+
goto error;
|
| 390 |
+
|
| 391 |
+
ptr->readEvent = CreateEventA(NULL, TRUE, FALSE, NULL);
|
| 392 |
+
if (!ptr->readEvent || ptr->readEvent == INVALID_HANDLE_VALUE)
|
| 393 |
+
goto error;
|
| 394 |
+
|
| 395 |
+
ptr->readOverlapped.hEvent = ptr->readEvent;
|
| 396 |
+
|
| 397 |
+
BIO_set_data(bio, ptr);
|
| 398 |
+
BIO_set_flags(bio, BIO_FLAGS_SHOULD_RETRY);
|
| 399 |
+
return 1;
|
| 400 |
+
|
| 401 |
+
error:
|
| 402 |
+
BIO_NAMED_free(ptr);
|
| 403 |
+
return 0;
|
| 404 |
+
}
|
| 405 |
+
|
| 406 |
+
static int transport_bio_named_free(BIO* bio)
|
| 407 |
+
{
|
| 408 |
+
WINPR_BIO_NAMED* ptr = NULL;
|
| 409 |
+
|
| 410 |
+
if (!bio)
|
| 411 |
+
return 0;
|
| 412 |
+
|
| 413 |
+
transport_bio_named_uninit(bio);
|
| 414 |
+
|
| 415 |
+
ptr = (WINPR_BIO_NAMED*)BIO_get_data(bio);
|
| 416 |
+
if (ptr)
|
| 417 |
+
BIO_set_data(bio, NULL);
|
| 418 |
+
|
| 419 |
+
return 1;
|
| 420 |
+
}
|
| 421 |
+
|
| 422 |
+
static BIO_METHOD* BIO_s_namedpipe(void)
|
| 423 |
+
{
|
| 424 |
+
static BIO_METHOD* bio_methods = NULL;
|
| 425 |
+
|
| 426 |
+
if (bio_methods == NULL)
|
| 427 |
+
{
|
| 428 |
+
if (!(bio_methods = BIO_meth_new(BIO_TYPE_NAMEDPIPE, "NamedPipe")))
|
| 429 |
+
return NULL;
|
| 430 |
+
|
| 431 |
+
BIO_meth_set_write(bio_methods, transport_bio_named_write);
|
| 432 |
+
BIO_meth_set_read(bio_methods, transport_bio_named_read);
|
| 433 |
+
BIO_meth_set_puts(bio_methods, transport_bio_named_puts);
|
| 434 |
+
BIO_meth_set_gets(bio_methods, transport_bio_named_gets);
|
| 435 |
+
BIO_meth_set_ctrl(bio_methods, transport_bio_named_ctrl);
|
| 436 |
+
BIO_meth_set_create(bio_methods, transport_bio_named_new);
|
| 437 |
+
BIO_meth_set_destroy(bio_methods, transport_bio_named_free);
|
| 438 |
+
}
|
| 439 |
+
|
| 440 |
+
return bio_methods;
|
| 441 |
+
}
|
| 442 |
+
|
| 443 |
+
typedef NTSTATUS (*WinStationCreateChildSessionTransportFn)(WCHAR* path, DWORD len);
|
| 444 |
+
static BOOL createChildSessionTransport(HANDLE* pFile)
|
| 445 |
+
{
|
| 446 |
+
WINPR_ASSERT(pFile);
|
| 447 |
+
|
| 448 |
+
HANDLE hModule = NULL;
|
| 449 |
+
BOOL ret = FALSE;
|
| 450 |
+
*pFile = INVALID_HANDLE_VALUE;
|
| 451 |
+
|
| 452 |
+
BOOL childEnabled = 0;
|
| 453 |
+
if (!WTSIsChildSessionsEnabled(&childEnabled))
|
| 454 |
+
{
|
| 455 |
+
WLog_ERR(TAG, "error when calling WTSIsChildSessionsEnabled");
|
| 456 |
+
goto out;
|
| 457 |
+
}
|
| 458 |
+
|
| 459 |
+
if (!childEnabled)
|
| 460 |
+
{
|
| 461 |
+
WLog_INFO(TAG, "child sessions aren't enabled");
|
| 462 |
+
if (!WTSEnableChildSessions(TRUE))
|
| 463 |
+
{
|
| 464 |
+
WLog_ERR(TAG, "error when calling WTSEnableChildSessions");
|
| 465 |
+
goto out;
|
| 466 |
+
}
|
| 467 |
+
WLog_INFO(TAG, "successfully enabled child sessions");
|
| 468 |
+
}
|
| 469 |
+
|
| 470 |
+
hModule = LoadLibraryA("winsta.dll");
|
| 471 |
+
if (!hModule)
|
| 472 |
+
return FALSE;
|
| 473 |
+
WCHAR pipePath[0x80] = { 0 };
|
| 474 |
+
char pipePathA[0x80] = { 0 };
|
| 475 |
+
|
| 476 |
+
WinStationCreateChildSessionTransportFn createChildSessionFn = GetProcAddressAs(
|
| 477 |
+
hModule, "WinStationCreateChildSessionTransport", WinStationCreateChildSessionTransportFn);
|
| 478 |
+
if (!createChildSessionFn)
|
| 479 |
+
{
|
| 480 |
+
WLog_ERR(TAG, "unable to retrieve WinStationCreateChildSessionTransport function");
|
| 481 |
+
goto out;
|
| 482 |
+
}
|
| 483 |
+
|
| 484 |
+
HRESULT hStatus = createChildSessionFn(pipePath, 0x80);
|
| 485 |
+
if (!SUCCEEDED(hStatus))
|
| 486 |
+
{
|
| 487 |
+
WLog_ERR(TAG, "error 0x%x when creating childSessionTransport", hStatus);
|
| 488 |
+
goto out;
|
| 489 |
+
}
|
| 490 |
+
|
| 491 |
+
const BYTE startOfPath[] = { '\\', 0, '\\', 0, '.', 0, '\\', 0 };
|
| 492 |
+
if (_wcsncmp(pipePath, (const WCHAR*)startOfPath, 4))
|
| 493 |
+
{
|
| 494 |
+
/* when compiled under 32 bits, the path may miss "\\.\" at the beginning of the string
|
| 495 |
+
* so add it if it's not there
|
| 496 |
+
*/
|
| 497 |
+
size_t len = _wcslen(pipePath);
|
| 498 |
+
if (len > 0x80 - (4 + 1))
|
| 499 |
+
{
|
| 500 |
+
WLog_ERR(TAG, "pipePath is too long to be adjusted");
|
| 501 |
+
goto out;
|
| 502 |
+
}
|
| 503 |
+
|
| 504 |
+
memmove(pipePath + 4, pipePath, (len + 1) * sizeof(WCHAR));
|
| 505 |
+
memcpy(pipePath, startOfPath, 8);
|
| 506 |
+
}
|
| 507 |
+
|
| 508 |
+
(void)ConvertWCharNToUtf8(pipePath, 0x80, pipePathA, sizeof(pipePathA));
|
| 509 |
+
WLog_DBG(TAG, "child session is at '%s'", pipePathA);
|
| 510 |
+
|
| 511 |
+
HANDLE f = CreateFileW(pipePath, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING,
|
| 512 |
+
FILE_FLAG_OVERLAPPED, NULL);
|
| 513 |
+
if (f == INVALID_HANDLE_VALUE)
|
| 514 |
+
{
|
| 515 |
+
WLog_ERR(TAG, "error when connecting to local named pipe");
|
| 516 |
+
goto out;
|
| 517 |
+
}
|
| 518 |
+
|
| 519 |
+
*pFile = f;
|
| 520 |
+
ret = TRUE;
|
| 521 |
+
|
| 522 |
+
out:
|
| 523 |
+
FreeLibrary(hModule);
|
| 524 |
+
return ret;
|
| 525 |
+
}
|
| 526 |
+
|
| 527 |
+
BIO* createChildSessionBio(void)
|
| 528 |
+
{
|
| 529 |
+
HANDLE f = INVALID_HANDLE_VALUE;
|
| 530 |
+
if (!createChildSessionTransport(&f))
|
| 531 |
+
return NULL;
|
| 532 |
+
|
| 533 |
+
BIO* lowLevelBio = BIO_new(BIO_s_namedpipe());
|
| 534 |
+
if (!lowLevelBio)
|
| 535 |
+
{
|
| 536 |
+
(void)CloseHandle(f);
|
| 537 |
+
return NULL;
|
| 538 |
+
}
|
| 539 |
+
|
| 540 |
+
BIO_set_handle(lowLevelBio, &f);
|
| 541 |
+
BIO* bufferedBio = BIO_new(BIO_s_buffered_socket());
|
| 542 |
+
|
| 543 |
+
if (!bufferedBio)
|
| 544 |
+
{
|
| 545 |
+
BIO_free_all(lowLevelBio);
|
| 546 |
+
return FALSE;
|
| 547 |
+
}
|
| 548 |
+
|
| 549 |
+
bufferedBio = BIO_push(bufferedBio, lowLevelBio);
|
| 550 |
+
|
| 551 |
+
return bufferedBio;
|
| 552 |
+
}
|
local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/display.h
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* FreeRDP: A Remote Desktop Protocol Implementation
|
| 3 |
+
* Display update notifications
|
| 4 |
+
*
|
| 5 |
+
* Copyright 2019 Kobi Mizrachi <[email protected]>
|
| 6 |
+
*
|
| 7 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 8 |
+
* you may not use this file except in compliance with the License.
|
| 9 |
+
* You may obtain a copy of the License at
|
| 10 |
+
*
|
| 11 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
+
*
|
| 13 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 14 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 15 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 16 |
+
* See the License for the specific language governing permissions and
|
| 17 |
+
* limitations under the License.
|
| 18 |
+
*/
|
| 19 |
+
|
| 20 |
+
#ifndef FREERDP_LIB_CORE_DISPLAY_H
|
| 21 |
+
#define FREERDP_LIB_CORE_DISPLAY_H
|
| 22 |
+
|
| 23 |
+
#include <freerdp/display.h>
|
| 24 |
+
#include "rdp.h"
|
| 25 |
+
|
| 26 |
+
FREERDP_LOCAL BOOL display_convert_rdp_monitor_to_monitor_def(UINT32 monitorCount,
|
| 27 |
+
const rdpMonitor* monitorDefArray,
|
| 28 |
+
MONITOR_DEF** result);
|
| 29 |
+
|
| 30 |
+
#endif /* FREERDP_LIB_CORE_DISPLAY_H */
|
local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/errinfo.h
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* FreeRDP: A Remote Desktop Protocol Implementation
|
| 3 |
+
* Error Info
|
| 4 |
+
*
|
| 5 |
+
* Copyright 2011 Marc-Andre Moreau <[email protected]>
|
| 6 |
+
*
|
| 7 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 8 |
+
* you may not use this file except in compliance with the License.
|
| 9 |
+
* You may obtain a copy of the License at
|
| 10 |
+
*
|
| 11 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
+
*
|
| 13 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 14 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 15 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 16 |
+
* See the License for the specific language governing permissions and
|
| 17 |
+
* limitations under the License.
|
| 18 |
+
*/
|
| 19 |
+
|
| 20 |
+
#ifndef FREERDP_LIB_CORE_ERRINFO_H
|
| 21 |
+
#define FREERDP_LIB_CORE_ERRINFO_H
|
| 22 |
+
|
| 23 |
+
#include <freerdp/freerdp.h>
|
| 24 |
+
#include <freerdp/api.h>
|
| 25 |
+
|
| 26 |
+
typedef struct
|
| 27 |
+
{
|
| 28 |
+
UINT32 code;
|
| 29 |
+
const char* name;
|
| 30 |
+
const char* info;
|
| 31 |
+
const char* category;
|
| 32 |
+
} ERRINFO;
|
| 33 |
+
|
| 34 |
+
FREERDP_LOCAL void rdp_print_errinfo(UINT32 code);
|
| 35 |
+
|
| 36 |
+
#endif /* FREERDP_LIB_CORE_ERRINFO_H */
|
local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gcc.h
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* FreeRDP: A Remote Desktop Protocol Implementation
|
| 3 |
+
* T.124 Generic Conference Control (GCC)
|
| 4 |
+
*
|
| 5 |
+
* Copyright 2011 Marc-Andre Moreau <[email protected]>
|
| 6 |
+
*
|
| 7 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 8 |
+
* you may not use this file except in compliance with the License.
|
| 9 |
+
* You may obtain a copy of the License at
|
| 10 |
+
*
|
| 11 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
+
*
|
| 13 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 14 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 15 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 16 |
+
* See the License for the specific language governing permissions and
|
| 17 |
+
* limitations under the License.
|
| 18 |
+
*/
|
| 19 |
+
|
| 20 |
+
#ifndef FREERDP_LIB_CORE_GCC_H
|
| 21 |
+
#define FREERDP_LIB_CORE_GCC_H
|
| 22 |
+
|
| 23 |
+
#include "mcs.h"
|
| 24 |
+
|
| 25 |
+
#include <freerdp/crypto/per.h>
|
| 26 |
+
|
| 27 |
+
#include <freerdp/freerdp.h>
|
| 28 |
+
#include <freerdp/settings.h>
|
| 29 |
+
#include <freerdp/api.h>
|
| 30 |
+
|
| 31 |
+
#include <winpr/stream.h>
|
| 32 |
+
|
| 33 |
+
FREERDP_LOCAL BOOL gcc_read_conference_create_request(wStream* s, rdpMcs* mcs);
|
| 34 |
+
FREERDP_LOCAL BOOL gcc_write_conference_create_request(wStream* s, wStream* userData);
|
| 35 |
+
FREERDP_LOCAL BOOL gcc_read_conference_create_response(wStream* s, rdpMcs* mcs);
|
| 36 |
+
FREERDP_LOCAL BOOL gcc_write_conference_create_response(wStream* s, wStream* userData);
|
| 37 |
+
FREERDP_LOCAL BOOL gcc_write_client_data_blocks(wStream* s, const rdpMcs* mcs);
|
| 38 |
+
FREERDP_LOCAL BOOL gcc_write_server_data_blocks(wStream* s, rdpMcs* mcs);
|
| 39 |
+
|
| 40 |
+
#endif /* FREERDP_LIB_CORE_GCC_H */
|
local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/graphics.h
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* FreeRDP: A Remote Desktop Protocol Implementation
|
| 3 |
+
* Client Channels
|
| 4 |
+
*
|
| 5 |
+
* Copyright 2016 Armin Novak <[email protected]>
|
| 6 |
+
* Copyright 2016 Thinast Technologies GmbH
|
| 7 |
+
*
|
| 8 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 9 |
+
* you may not use this file except in compliance with the License.
|
| 10 |
+
* You may obtain a copy of the License at
|
| 11 |
+
*
|
| 12 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 13 |
+
*
|
| 14 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 15 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 16 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 17 |
+
* See the License for the specific language governing permissions and
|
| 18 |
+
* limitations under the License.
|
| 19 |
+
*/
|
| 20 |
+
|
| 21 |
+
#ifndef FREERDP_LIB_CORE_GRAPHICS_H
|
| 22 |
+
#define FREERDP_LIB_CORE_GRAPHICS_H
|
| 23 |
+
|
| 24 |
+
#include <freerdp/api.h>
|
| 25 |
+
#include <freerdp/freerdp.h>
|
| 26 |
+
#include <freerdp/graphics.h>
|
| 27 |
+
|
| 28 |
+
FREERDP_LOCAL void Bitmap_Free(rdpContext* context, rdpBitmap* bitmap);
|
| 29 |
+
|
| 30 |
+
#endif /* FREERDP_LIB_CORE_GRAPHICS_H */
|
local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/heartbeat.h
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* FreeRDP: A Remote Desktop Protocol Implementation
|
| 3 |
+
* Heartbeat PDUs
|
| 4 |
+
*
|
| 5 |
+
* Copyright 2014 Dell Software <[email protected]>
|
| 6 |
+
*
|
| 7 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 8 |
+
* you may not use this file except in compliance with the License.
|
| 9 |
+
* You may obtain a copy of the License at
|
| 10 |
+
*
|
| 11 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
+
*
|
| 13 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 14 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 15 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 16 |
+
* See the License for the specific language governing permissions and
|
| 17 |
+
* limitations under the License.
|
| 18 |
+
*/
|
| 19 |
+
|
| 20 |
+
#ifndef FREERDP_LIB_CORE_HEARTBEET_H
|
| 21 |
+
#define FREERDP_LIB_CORE_HEARTBEET_H
|
| 22 |
+
|
| 23 |
+
#include "rdp.h"
|
| 24 |
+
|
| 25 |
+
#include <freerdp/heartbeat.h>
|
| 26 |
+
#include <freerdp/freerdp.h>
|
| 27 |
+
#include <freerdp/log.h>
|
| 28 |
+
#include <freerdp/api.h>
|
| 29 |
+
|
| 30 |
+
#include <winpr/stream.h>
|
| 31 |
+
|
| 32 |
+
#include "state.h"
|
| 33 |
+
|
| 34 |
+
FREERDP_LOCAL state_run_t rdp_recv_heartbeat_packet(rdpRdp* rdp, wStream* s);
|
| 35 |
+
|
| 36 |
+
FREERDP_LOCAL void heartbeat_free(rdpHeartbeat* heartbeat);
|
| 37 |
+
|
| 38 |
+
WINPR_ATTR_MALLOC(heartbeat_free, 1)
|
| 39 |
+
FREERDP_LOCAL rdpHeartbeat* heartbeat_new(void);
|
| 40 |
+
|
| 41 |
+
#define HEARTBEAT_TAG FREERDP_TAG("core.heartbeat")
|
| 42 |
+
|
| 43 |
+
#endif /* FREERDP_LIB_CORE_HEARTBEET_H */
|
local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/info.c
ADDED
|
@@ -0,0 +1,1578 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* FreeRDP: A Remote Desktop Protocol Implementation
|
| 3 |
+
* RDP Client Info
|
| 4 |
+
*
|
| 5 |
+
* Copyright 2011 Marc-Andre Moreau <[email protected]>
|
| 6 |
+
* Copyright 2015 Thincast Technologies GmbH
|
| 7 |
+
* Copyright 2015 DI (FH) Martin Haimberger <[email protected]>
|
| 8 |
+
*
|
| 9 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 10 |
+
* you may not use this file except in compliance with the License.
|
| 11 |
+
* You may obtain a copy of the License at
|
| 12 |
+
*
|
| 13 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 14 |
+
*
|
| 15 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 16 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 17 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 18 |
+
* See the License for the specific language governing permissions and
|
| 19 |
+
* limitations under the License.
|
| 20 |
+
*/
|
| 21 |
+
|
| 22 |
+
#include <freerdp/config.h>
|
| 23 |
+
|
| 24 |
+
#include "settings.h"
|
| 25 |
+
|
| 26 |
+
#include <winpr/crt.h>
|
| 27 |
+
#include <winpr/assert.h>
|
| 28 |
+
|
| 29 |
+
#include <freerdp/crypto/crypto.h>
|
| 30 |
+
#include <freerdp/log.h>
|
| 31 |
+
#include <freerdp/session.h>
|
| 32 |
+
#include <stdio.h>
|
| 33 |
+
|
| 34 |
+
#include "timezone.h"
|
| 35 |
+
|
| 36 |
+
#include "info.h"
|
| 37 |
+
|
| 38 |
+
#define TAG FREERDP_TAG("core.info")
|
| 39 |
+
|
| 40 |
+
#define logonInfoV2Size (2 + 4 + 4 + 4 + 4)
|
| 41 |
+
#define logonInfoV2ReservedSize 558
|
| 42 |
+
#define logonInfoV2TotalSize (logonInfoV2Size + logonInfoV2ReservedSize)
|
| 43 |
+
|
| 44 |
+
static const char* INFO_TYPE_LOGON_STRINGS[4] = { "Logon Info V1", "Logon Info V2",
|
| 45 |
+
"Logon Plain Notify", "Logon Extended Info" };
|
| 46 |
+
|
| 47 |
+
/* This define limits the length of the strings in the label field. */
|
| 48 |
+
#define MAX_LABEL_LENGTH 40
|
| 49 |
+
struct info_flags_t
|
| 50 |
+
{
|
| 51 |
+
UINT32 flag;
|
| 52 |
+
const char* label;
|
| 53 |
+
};
|
| 54 |
+
|
| 55 |
+
static const struct info_flags_t info_flags[] = {
|
| 56 |
+
{ INFO_MOUSE, "INFO_MOUSE" },
|
| 57 |
+
{ INFO_DISABLECTRLALTDEL, "INFO_DISABLECTRLALTDEL" },
|
| 58 |
+
{ INFO_AUTOLOGON, "INFO_AUTOLOGON" },
|
| 59 |
+
{ INFO_UNICODE, "INFO_UNICODE" },
|
| 60 |
+
{ INFO_MAXIMIZESHELL, "INFO_MAXIMIZESHELL" },
|
| 61 |
+
{ INFO_LOGONNOTIFY, "INFO_LOGONNOTIFY" },
|
| 62 |
+
{ INFO_COMPRESSION, "INFO_COMPRESSION" },
|
| 63 |
+
{ INFO_ENABLEWINDOWSKEY, "INFO_ENABLEWINDOWSKEY" },
|
| 64 |
+
{ INFO_REMOTECONSOLEAUDIO, "INFO_REMOTECONSOLEAUDIO" },
|
| 65 |
+
{ INFO_FORCE_ENCRYPTED_CS_PDU, "INFO_FORCE_ENCRYPTED_CS_PDU" },
|
| 66 |
+
{ INFO_RAIL, "INFO_RAIL" },
|
| 67 |
+
{ INFO_LOGONERRORS, "INFO_LOGONERRORS" },
|
| 68 |
+
{ INFO_MOUSE_HAS_WHEEL, "INFO_MOUSE_HAS_WHEEL" },
|
| 69 |
+
{ INFO_PASSWORD_IS_SC_PIN, "INFO_PASSWORD_IS_SC_PIN" },
|
| 70 |
+
{ INFO_NOAUDIOPLAYBACK, "INFO_NOAUDIOPLAYBACK" },
|
| 71 |
+
{ INFO_USING_SAVED_CREDS, "INFO_USING_SAVED_CREDS" },
|
| 72 |
+
{ INFO_AUDIOCAPTURE, "INFO_AUDIOCAPTURE" },
|
| 73 |
+
{ INFO_VIDEO_DISABLE, "INFO_VIDEO_DISABLE" },
|
| 74 |
+
{ INFO_HIDEF_RAIL_SUPPORTED, "INFO_HIDEF_RAIL_SUPPORTED" },
|
| 75 |
+
};
|
| 76 |
+
|
| 77 |
+
static BOOL rdp_read_info_null_string(rdpSettings* settings, FreeRDP_Settings_Keys_String id,
|
| 78 |
+
const char* what, UINT32 flags, wStream* s, size_t cbLen,
|
| 79 |
+
size_t max)
|
| 80 |
+
{
|
| 81 |
+
const BOOL unicode = (flags & INFO_UNICODE) ? TRUE : FALSE;
|
| 82 |
+
|
| 83 |
+
if (!freerdp_settings_set_string(settings, id, NULL))
|
| 84 |
+
return FALSE;
|
| 85 |
+
|
| 86 |
+
if (!Stream_CheckAndLogRequiredLength(TAG, s, (size_t)(cbLen)))
|
| 87 |
+
return FALSE;
|
| 88 |
+
|
| 89 |
+
if (cbLen > 0)
|
| 90 |
+
{
|
| 91 |
+
if ((cbLen > max) || (unicode && ((cbLen % 2) != 0)))
|
| 92 |
+
{
|
| 93 |
+
WLog_ERR(TAG, "protocol error: %s has invalid value: %" PRIuz "", what, cbLen);
|
| 94 |
+
return FALSE;
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
if (unicode)
|
| 98 |
+
{
|
| 99 |
+
const WCHAR* domain = Stream_PointerAs(s, WCHAR);
|
| 100 |
+
if (!freerdp_settings_set_string_from_utf16N(settings, id, domain,
|
| 101 |
+
cbLen / sizeof(WCHAR)))
|
| 102 |
+
{
|
| 103 |
+
WLog_ERR(TAG, "protocol error: no data to read for %s [expected %" PRIuz "]", what,
|
| 104 |
+
cbLen);
|
| 105 |
+
return FALSE;
|
| 106 |
+
}
|
| 107 |
+
}
|
| 108 |
+
else
|
| 109 |
+
{
|
| 110 |
+
const char* domain = Stream_ConstPointer(s);
|
| 111 |
+
if (!freerdp_settings_set_string_len(settings, id, domain, cbLen))
|
| 112 |
+
return FALSE;
|
| 113 |
+
}
|
| 114 |
+
}
|
| 115 |
+
Stream_Seek(s, cbLen);
|
| 116 |
+
|
| 117 |
+
return TRUE;
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
static char* rdp_info_package_flags_description(UINT32 flags)
|
| 121 |
+
{
|
| 122 |
+
char* result = NULL;
|
| 123 |
+
size_t maximum_size = 1 + MAX_LABEL_LENGTH * ARRAYSIZE(info_flags);
|
| 124 |
+
|
| 125 |
+
result = calloc(maximum_size, sizeof(char));
|
| 126 |
+
|
| 127 |
+
if (!result)
|
| 128 |
+
return 0;
|
| 129 |
+
|
| 130 |
+
for (size_t i = 0; i < ARRAYSIZE(info_flags); i++)
|
| 131 |
+
{
|
| 132 |
+
const struct info_flags_t* cur = &info_flags[i];
|
| 133 |
+
if (cur->flag & flags)
|
| 134 |
+
{
|
| 135 |
+
winpr_str_append(cur->label, result, maximum_size, "|");
|
| 136 |
+
}
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
return result;
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
static BOOL rdp_compute_client_auto_reconnect_cookie(rdpRdp* rdp)
|
| 143 |
+
{
|
| 144 |
+
BYTE ClientRandom[CLIENT_RANDOM_LENGTH] = { 0 };
|
| 145 |
+
BYTE AutoReconnectRandom[32] = { 0 };
|
| 146 |
+
ARC_SC_PRIVATE_PACKET* serverCookie = NULL;
|
| 147 |
+
ARC_CS_PRIVATE_PACKET* clientCookie = NULL;
|
| 148 |
+
|
| 149 |
+
WINPR_ASSERT(rdp);
|
| 150 |
+
rdpSettings* settings = rdp->settings;
|
| 151 |
+
WINPR_ASSERT(settings);
|
| 152 |
+
|
| 153 |
+
serverCookie = settings->ServerAutoReconnectCookie;
|
| 154 |
+
clientCookie = settings->ClientAutoReconnectCookie;
|
| 155 |
+
clientCookie->cbLen = 28;
|
| 156 |
+
clientCookie->version = serverCookie->version;
|
| 157 |
+
clientCookie->logonId = serverCookie->logonId;
|
| 158 |
+
ZeroMemory(clientCookie->securityVerifier, sizeof(clientCookie->securityVerifier));
|
| 159 |
+
CopyMemory(AutoReconnectRandom, serverCookie->arcRandomBits,
|
| 160 |
+
sizeof(serverCookie->arcRandomBits));
|
| 161 |
+
|
| 162 |
+
if (settings->SelectedProtocol == PROTOCOL_RDP)
|
| 163 |
+
CopyMemory(ClientRandom, settings->ClientRandom, settings->ClientRandomLength);
|
| 164 |
+
|
| 165 |
+
/* SecurityVerifier = HMAC_MD5(AutoReconnectRandom, ClientRandom) */
|
| 166 |
+
|
| 167 |
+
if (!winpr_HMAC(WINPR_MD_MD5, AutoReconnectRandom, 16, ClientRandom, sizeof(ClientRandom),
|
| 168 |
+
clientCookie->securityVerifier, sizeof(clientCookie->securityVerifier)))
|
| 169 |
+
return FALSE;
|
| 170 |
+
|
| 171 |
+
return TRUE;
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
/**
|
| 175 |
+
* Read Server Auto Reconnect Cookie (ARC_SC_PRIVATE_PACKET).
|
| 176 |
+
* msdn{cc240540}
|
| 177 |
+
*/
|
| 178 |
+
|
| 179 |
+
static BOOL rdp_read_server_auto_reconnect_cookie(rdpRdp* rdp, wStream* s, logon_info_ex* info)
|
| 180 |
+
{
|
| 181 |
+
BYTE* p = NULL;
|
| 182 |
+
ARC_SC_PRIVATE_PACKET* autoReconnectCookie = NULL;
|
| 183 |
+
rdpSettings* settings = rdp->settings;
|
| 184 |
+
autoReconnectCookie = settings->ServerAutoReconnectCookie;
|
| 185 |
+
|
| 186 |
+
if (!Stream_CheckAndLogRequiredLength(TAG, s, 28))
|
| 187 |
+
return FALSE;
|
| 188 |
+
|
| 189 |
+
Stream_Read_UINT32(s, autoReconnectCookie->cbLen); /* cbLen (4 bytes) */
|
| 190 |
+
|
| 191 |
+
if (autoReconnectCookie->cbLen != 28)
|
| 192 |
+
{
|
| 193 |
+
WLog_ERR(TAG, "ServerAutoReconnectCookie.cbLen != 28");
|
| 194 |
+
return FALSE;
|
| 195 |
+
}
|
| 196 |
+
|
| 197 |
+
Stream_Read_UINT32(s, autoReconnectCookie->version); /* Version (4 bytes) */
|
| 198 |
+
Stream_Read_UINT32(s, autoReconnectCookie->logonId); /* LogonId (4 bytes) */
|
| 199 |
+
Stream_Read(s, autoReconnectCookie->arcRandomBits, 16); /* ArcRandomBits (16 bytes) */
|
| 200 |
+
p = autoReconnectCookie->arcRandomBits;
|
| 201 |
+
WLog_DBG(TAG,
|
| 202 |
+
"ServerAutoReconnectCookie: Version: %" PRIu32 " LogonId: %" PRIu32
|
| 203 |
+
" SecurityVerifier: "
|
| 204 |
+
"%02" PRIX8 "%02" PRIX8 "%02" PRIX8 "%02" PRIX8 "%02" PRIX8 "%02" PRIX8 "%02" PRIX8
|
| 205 |
+
"%02" PRIX8 ""
|
| 206 |
+
"%02" PRIX8 "%02" PRIX8 "%02" PRIX8 "%02" PRIX8 "%02" PRIX8 "%02" PRIX8 "%02" PRIX8
|
| 207 |
+
"%02" PRIX8 "",
|
| 208 |
+
autoReconnectCookie->version, autoReconnectCookie->logonId, p[0], p[1], p[2], p[3],
|
| 209 |
+
p[4], p[5], p[6], p[7], p[8], p[9], p[10], p[11], p[12], p[13], p[14], p[15]);
|
| 210 |
+
info->LogonId = autoReconnectCookie->logonId;
|
| 211 |
+
CopyMemory(info->ArcRandomBits, p, 16);
|
| 212 |
+
|
| 213 |
+
if ((settings->PrintReconnectCookie))
|
| 214 |
+
{
|
| 215 |
+
char* base64 = NULL;
|
| 216 |
+
base64 = crypto_base64_encode((BYTE*)autoReconnectCookie, sizeof(ARC_SC_PRIVATE_PACKET));
|
| 217 |
+
WLog_INFO(TAG, "Reconnect-cookie: %s", base64);
|
| 218 |
+
free(base64);
|
| 219 |
+
}
|
| 220 |
+
|
| 221 |
+
return TRUE;
|
| 222 |
+
}
|
| 223 |
+
|
| 224 |
+
/**
|
| 225 |
+
* Read Client Auto Reconnect Cookie (ARC_CS_PRIVATE_PACKET).
|
| 226 |
+
* msdn{cc240541}
|
| 227 |
+
*/
|
| 228 |
+
|
| 229 |
+
static BOOL rdp_read_client_auto_reconnect_cookie(rdpRdp* rdp, wStream* s)
|
| 230 |
+
{
|
| 231 |
+
ARC_CS_PRIVATE_PACKET* autoReconnectCookie = NULL;
|
| 232 |
+
rdpSettings* settings = rdp->settings;
|
| 233 |
+
autoReconnectCookie = settings->ClientAutoReconnectCookie;
|
| 234 |
+
|
| 235 |
+
if (!Stream_CheckAndLogRequiredLength(TAG, s, 28))
|
| 236 |
+
return FALSE;
|
| 237 |
+
|
| 238 |
+
Stream_Read_UINT32(s, autoReconnectCookie->cbLen); /* cbLen (4 bytes) */
|
| 239 |
+
Stream_Read_UINT32(s, autoReconnectCookie->version); /* version (4 bytes) */
|
| 240 |
+
Stream_Read_UINT32(s, autoReconnectCookie->logonId); /* LogonId (4 bytes) */
|
| 241 |
+
Stream_Read(s, autoReconnectCookie->securityVerifier, 16); /* SecurityVerifier */
|
| 242 |
+
return TRUE;
|
| 243 |
+
}
|
| 244 |
+
|
| 245 |
+
/**
|
| 246 |
+
* Write Client Auto Reconnect Cookie (ARC_CS_PRIVATE_PACKET).
|
| 247 |
+
* msdn{cc240541}
|
| 248 |
+
*/
|
| 249 |
+
|
| 250 |
+
static BOOL rdp_write_client_auto_reconnect_cookie(rdpRdp* rdp, wStream* s)
|
| 251 |
+
{
|
| 252 |
+
BYTE* p = NULL;
|
| 253 |
+
ARC_CS_PRIVATE_PACKET* autoReconnectCookie = NULL;
|
| 254 |
+
rdpSettings* settings = NULL;
|
| 255 |
+
|
| 256 |
+
WINPR_ASSERT(rdp);
|
| 257 |
+
|
| 258 |
+
settings = rdp->settings;
|
| 259 |
+
WINPR_ASSERT(settings);
|
| 260 |
+
|
| 261 |
+
autoReconnectCookie = settings->ClientAutoReconnectCookie;
|
| 262 |
+
WINPR_ASSERT(autoReconnectCookie);
|
| 263 |
+
|
| 264 |
+
p = autoReconnectCookie->securityVerifier;
|
| 265 |
+
WINPR_ASSERT(p);
|
| 266 |
+
|
| 267 |
+
WLog_DBG(TAG,
|
| 268 |
+
"ClientAutoReconnectCookie: Version: %" PRIu32 " LogonId: %" PRIu32 " ArcRandomBits: "
|
| 269 |
+
"%02" PRIX8 "%02" PRIX8 "%02" PRIX8 "%02" PRIX8 "%02" PRIX8 "%02" PRIX8 "%02" PRIX8
|
| 270 |
+
"%02" PRIX8 ""
|
| 271 |
+
"%02" PRIX8 "%02" PRIX8 "%02" PRIX8 "%02" PRIX8 "%02" PRIX8 "%02" PRIX8 "%02" PRIX8
|
| 272 |
+
"%02" PRIX8 "",
|
| 273 |
+
autoReconnectCookie->version, autoReconnectCookie->logonId, p[0], p[1], p[2], p[3],
|
| 274 |
+
p[4], p[5], p[6], p[7], p[8], p[9], p[10], p[11], p[12], p[13], p[14], p[15]);
|
| 275 |
+
if (!Stream_EnsureRemainingCapacity(s, 12ull + 16ull))
|
| 276 |
+
return FALSE;
|
| 277 |
+
Stream_Write_UINT32(s, autoReconnectCookie->cbLen); /* cbLen (4 bytes) */
|
| 278 |
+
Stream_Write_UINT32(s, autoReconnectCookie->version); /* version (4 bytes) */
|
| 279 |
+
Stream_Write_UINT32(s, autoReconnectCookie->logonId); /* LogonId (4 bytes) */
|
| 280 |
+
Stream_Write(s, autoReconnectCookie->securityVerifier, 16); /* SecurityVerifier (16 bytes) */
|
| 281 |
+
return TRUE;
|
| 282 |
+
}
|
| 283 |
+
|
| 284 |
+
/*
|
| 285 |
+
* Get the cbClientAddress size limit
|
| 286 |
+
* see [MS-RDPBCGR] 2.2.1.11.1.1.1 Extended Info Packet (TS_EXTENDED_INFO_PACKET)
|
| 287 |
+
*/
|
| 288 |
+
|
| 289 |
+
static size_t rdp_get_client_address_max_size(const rdpRdp* rdp)
|
| 290 |
+
{
|
| 291 |
+
UINT32 version = 0;
|
| 292 |
+
rdpSettings* settings = NULL;
|
| 293 |
+
|
| 294 |
+
WINPR_ASSERT(rdp);
|
| 295 |
+
|
| 296 |
+
settings = rdp->settings;
|
| 297 |
+
WINPR_ASSERT(settings);
|
| 298 |
+
|
| 299 |
+
version = freerdp_settings_get_uint32(settings, FreeRDP_RdpVersion);
|
| 300 |
+
if (version < RDP_VERSION_10_0)
|
| 301 |
+
return 64;
|
| 302 |
+
return 80;
|
| 303 |
+
}
|
| 304 |
+
|
| 305 |
+
/**
|
| 306 |
+
* Read Extended Info Packet (TS_EXTENDED_INFO_PACKET).
|
| 307 |
+
* msdn{cc240476}
|
| 308 |
+
*/
|
| 309 |
+
|
| 310 |
+
static BOOL rdp_read_extended_info_packet(rdpRdp* rdp, wStream* s)
|
| 311 |
+
{
|
| 312 |
+
UINT16 clientAddressFamily = 0;
|
| 313 |
+
UINT16 cbClientAddress = 0;
|
| 314 |
+
UINT16 cbClientDir = 0;
|
| 315 |
+
UINT16 cbAutoReconnectLen = 0;
|
| 316 |
+
|
| 317 |
+
WINPR_ASSERT(rdp);
|
| 318 |
+
|
| 319 |
+
rdpSettings* settings = rdp->settings;
|
| 320 |
+
WINPR_ASSERT(settings);
|
| 321 |
+
|
| 322 |
+
if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
|
| 323 |
+
return FALSE;
|
| 324 |
+
|
| 325 |
+
Stream_Read_UINT16(s, clientAddressFamily); /* clientAddressFamily (2 bytes) */
|
| 326 |
+
Stream_Read_UINT16(s, cbClientAddress); /* cbClientAddress (2 bytes) */
|
| 327 |
+
|
| 328 |
+
settings->IPv6Enabled = (clientAddressFamily == ADDRESS_FAMILY_INET6 ? TRUE : FALSE);
|
| 329 |
+
|
| 330 |
+
if (!rdp_read_info_null_string(settings, FreeRDP_ClientAddress, "cbClientAddress", INFO_UNICODE,
|
| 331 |
+
s, cbClientAddress, rdp_get_client_address_max_size(rdp)))
|
| 332 |
+
return FALSE;
|
| 333 |
+
|
| 334 |
+
if (!Stream_CheckAndLogRequiredLength(TAG, s, 2))
|
| 335 |
+
return FALSE;
|
| 336 |
+
|
| 337 |
+
Stream_Read_UINT16(s, cbClientDir); /* cbClientDir (2 bytes) */
|
| 338 |
+
|
| 339 |
+
/* cbClientDir is the size in bytes of the character data in the clientDir field.
|
| 340 |
+
* This size includes the length of the mandatory null terminator.
|
| 341 |
+
* The maximum allowed value is 512 bytes.
|
| 342 |
+
* Note: Although according to [MS-RDPBCGR 2.2.1.11.1.1.1] the null terminator
|
| 343 |
+
* is mandatory the Microsoft Android client (starting with version 8.1.31.44)
|
| 344 |
+
* sets cbClientDir to 0.
|
| 345 |
+
*/
|
| 346 |
+
|
| 347 |
+
if (!rdp_read_info_null_string(settings, FreeRDP_ClientDir, "cbClientDir", INFO_UNICODE, s,
|
| 348 |
+
cbClientDir, 512))
|
| 349 |
+
return FALSE;
|
| 350 |
+
|
| 351 |
+
/**
|
| 352 |
+
* down below all fields are optional but if one field is not present,
|
| 353 |
+
* then all of the subsequent fields also MUST NOT be present.
|
| 354 |
+
*/
|
| 355 |
+
|
| 356 |
+
/* optional: clientTimeZone (172 bytes) */
|
| 357 |
+
if (Stream_GetRemainingLength(s) == 0)
|
| 358 |
+
goto end;
|
| 359 |
+
|
| 360 |
+
if (!rdp_read_client_time_zone(s, settings))
|
| 361 |
+
return FALSE;
|
| 362 |
+
|
| 363 |
+
/* optional: clientSessionId (4 bytes), should be set to 0 */
|
| 364 |
+
if (Stream_GetRemainingLength(s) == 0)
|
| 365 |
+
goto end;
|
| 366 |
+
if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
|
| 367 |
+
return FALSE;
|
| 368 |
+
|
| 369 |
+
Stream_Read_UINT32(s, settings->ClientSessionId);
|
| 370 |
+
|
| 371 |
+
/* optional: performanceFlags (4 bytes) */
|
| 372 |
+
if (Stream_GetRemainingLength(s) == 0)
|
| 373 |
+
goto end;
|
| 374 |
+
|
| 375 |
+
if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
|
| 376 |
+
return FALSE;
|
| 377 |
+
|
| 378 |
+
Stream_Read_UINT32(s, settings->PerformanceFlags);
|
| 379 |
+
freerdp_performance_flags_split(settings);
|
| 380 |
+
|
| 381 |
+
/* optional: cbAutoReconnectLen (2 bytes) */
|
| 382 |
+
if (Stream_GetRemainingLength(s) == 0)
|
| 383 |
+
goto end;
|
| 384 |
+
|
| 385 |
+
if (!Stream_CheckAndLogRequiredLength(TAG, s, 2))
|
| 386 |
+
return FALSE;
|
| 387 |
+
|
| 388 |
+
Stream_Read_UINT16(s, cbAutoReconnectLen);
|
| 389 |
+
|
| 390 |
+
/* optional: autoReconnectCookie (28 bytes) */
|
| 391 |
+
/* must be present if cbAutoReconnectLen is > 0 */
|
| 392 |
+
if (cbAutoReconnectLen > 0)
|
| 393 |
+
{
|
| 394 |
+
if (!rdp_read_client_auto_reconnect_cookie(rdp, s))
|
| 395 |
+
return FALSE;
|
| 396 |
+
}
|
| 397 |
+
|
| 398 |
+
/* skip reserved1 and reserved2 fields */
|
| 399 |
+
if (Stream_GetRemainingLength(s) == 0)
|
| 400 |
+
goto end;
|
| 401 |
+
|
| 402 |
+
if (!Stream_SafeSeek(s, 2))
|
| 403 |
+
return FALSE;
|
| 404 |
+
|
| 405 |
+
if (Stream_GetRemainingLength(s) == 0)
|
| 406 |
+
goto end;
|
| 407 |
+
|
| 408 |
+
if (!Stream_SafeSeek(s, 2))
|
| 409 |
+
return FALSE;
|
| 410 |
+
|
| 411 |
+
if (Stream_GetRemainingLength(s) == 0)
|
| 412 |
+
goto end;
|
| 413 |
+
|
| 414 |
+
if (!Stream_CheckAndLogRequiredLength(TAG, s, 2))
|
| 415 |
+
return FALSE;
|
| 416 |
+
|
| 417 |
+
if (freerdp_settings_get_bool(settings, FreeRDP_SupportDynamicTimeZone))
|
| 418 |
+
{
|
| 419 |
+
UINT16 cbDynamicDSTTimeZoneKeyName = 0;
|
| 420 |
+
|
| 421 |
+
Stream_Read_UINT16(s, cbDynamicDSTTimeZoneKeyName);
|
| 422 |
+
|
| 423 |
+
if (!rdp_read_info_null_string(settings, FreeRDP_DynamicDSTTimeZoneKeyName,
|
| 424 |
+
"cbDynamicDSTTimeZoneKeyName", INFO_UNICODE, s,
|
| 425 |
+
cbDynamicDSTTimeZoneKeyName, 254))
|
| 426 |
+
return FALSE;
|
| 427 |
+
|
| 428 |
+
if (Stream_GetRemainingLength(s) == 0)
|
| 429 |
+
goto end;
|
| 430 |
+
|
| 431 |
+
if (!Stream_CheckAndLogRequiredLength(TAG, s, 2))
|
| 432 |
+
return FALSE;
|
| 433 |
+
UINT16 DynamicDaylightTimeDisabled = 0;
|
| 434 |
+
Stream_Read_UINT16(s, DynamicDaylightTimeDisabled);
|
| 435 |
+
if (DynamicDaylightTimeDisabled > 1)
|
| 436 |
+
{
|
| 437 |
+
WLog_WARN(TAG,
|
| 438 |
+
"[MS-RDPBCGR] 2.2.1.11.1.1.1 Extended Info Packet "
|
| 439 |
+
"(TS_EXTENDED_INFO_PACKET)::dynamicDaylightTimeDisabled value %" PRIu16
|
| 440 |
+
" not allowed in [0,1]",
|
| 441 |
+
settings->DynamicDaylightTimeDisabled);
|
| 442 |
+
return FALSE;
|
| 443 |
+
}
|
| 444 |
+
if (!freerdp_settings_set_bool(settings, FreeRDP_DynamicDaylightTimeDisabled,
|
| 445 |
+
DynamicDaylightTimeDisabled != 0))
|
| 446 |
+
return FALSE;
|
| 447 |
+
DEBUG_TIMEZONE("DynamicTimeZone=%s [%s]",
|
| 448 |
+
freerdp_settings_get_string(settings, FreeRDP_DynamicDSTTimeZoneKeyName),
|
| 449 |
+
freerdp_settings_get_bool(settings, FreeRDP_DynamicDaylightTimeDisabled)
|
| 450 |
+
? "no-DST"
|
| 451 |
+
: "DST");
|
| 452 |
+
}
|
| 453 |
+
|
| 454 |
+
end:
|
| 455 |
+
return TRUE;
|
| 456 |
+
}
|
| 457 |
+
|
| 458 |
+
/**
|
| 459 |
+
* Write Extended Info Packet (TS_EXTENDED_INFO_PACKET).
|
| 460 |
+
* msdn{cc240476}
|
| 461 |
+
*/
|
| 462 |
+
|
| 463 |
+
static BOOL rdp_write_extended_info_packet(rdpRdp* rdp, wStream* s)
|
| 464 |
+
{
|
| 465 |
+
BOOL ret = FALSE;
|
| 466 |
+
size_t cbClientAddress = 0;
|
| 467 |
+
const size_t cbClientAddressMax = rdp_get_client_address_max_size(rdp);
|
| 468 |
+
WCHAR* clientDir = NULL;
|
| 469 |
+
size_t cbClientDir = 0;
|
| 470 |
+
const size_t cbClientDirMax = 512;
|
| 471 |
+
UINT16 cbAutoReconnectCookie = 0;
|
| 472 |
+
|
| 473 |
+
WINPR_ASSERT(rdp);
|
| 474 |
+
|
| 475 |
+
rdpSettings* settings = rdp->settings;
|
| 476 |
+
WINPR_ASSERT(settings);
|
| 477 |
+
|
| 478 |
+
UINT16 clientAddressFamily = ADDRESS_FAMILY_INET;
|
| 479 |
+
if (settings->ConnectChildSession)
|
| 480 |
+
clientAddressFamily = 0x0000;
|
| 481 |
+
else if (settings->IPv6Enabled)
|
| 482 |
+
clientAddressFamily = ADDRESS_FAMILY_INET6;
|
| 483 |
+
|
| 484 |
+
WCHAR* clientAddress = ConvertUtf8ToWCharAlloc(settings->ClientAddress, &cbClientAddress);
|
| 485 |
+
|
| 486 |
+
if (cbClientAddress > (UINT16_MAX / sizeof(WCHAR)))
|
| 487 |
+
{
|
| 488 |
+
WLog_ERR(TAG, "cbClientAddress > UINT16_MAX");
|
| 489 |
+
goto fail;
|
| 490 |
+
}
|
| 491 |
+
|
| 492 |
+
if (cbClientAddress > 0)
|
| 493 |
+
{
|
| 494 |
+
cbClientAddress = (UINT16)(cbClientAddress + 1) * sizeof(WCHAR);
|
| 495 |
+
if (cbClientAddress > cbClientAddressMax)
|
| 496 |
+
{
|
| 497 |
+
WLog_WARN(TAG,
|
| 498 |
+
"the client address %s [%" PRIuz "] exceeds the limit of %" PRIuz
|
| 499 |
+
", truncating.",
|
| 500 |
+
settings->ClientAddress, cbClientAddress, cbClientAddressMax);
|
| 501 |
+
|
| 502 |
+
clientAddress[(cbClientAddressMax / sizeof(WCHAR)) - 1] = '\0';
|
| 503 |
+
cbClientAddress = cbClientAddressMax;
|
| 504 |
+
}
|
| 505 |
+
}
|
| 506 |
+
|
| 507 |
+
clientDir = ConvertUtf8ToWCharAlloc(settings->ClientDir, &cbClientDir);
|
| 508 |
+
if (cbClientDir > (UINT16_MAX / sizeof(WCHAR)))
|
| 509 |
+
{
|
| 510 |
+
WLog_ERR(TAG, "cbClientDir > UINT16_MAX");
|
| 511 |
+
goto fail;
|
| 512 |
+
}
|
| 513 |
+
|
| 514 |
+
if (cbClientDir > 0)
|
| 515 |
+
{
|
| 516 |
+
cbClientDir = (UINT16)(cbClientDir + 1) * sizeof(WCHAR);
|
| 517 |
+
if (cbClientDir > cbClientDirMax)
|
| 518 |
+
{
|
| 519 |
+
WLog_WARN(TAG,
|
| 520 |
+
"the client dir %s [%" PRIuz "] exceeds the limit of %" PRIuz ", truncating.",
|
| 521 |
+
settings->ClientDir, cbClientDir, cbClientDirMax);
|
| 522 |
+
|
| 523 |
+
clientDir[(cbClientDirMax / sizeof(WCHAR)) - 1] = '\0';
|
| 524 |
+
cbClientDir = cbClientDirMax;
|
| 525 |
+
}
|
| 526 |
+
}
|
| 527 |
+
|
| 528 |
+
if (settings->ServerAutoReconnectCookie->cbLen > UINT16_MAX)
|
| 529 |
+
{
|
| 530 |
+
WLog_ERR(TAG, "ServerAutoreconnectCookie::cbLen > UINT16_MAX");
|
| 531 |
+
goto fail;
|
| 532 |
+
}
|
| 533 |
+
|
| 534 |
+
cbAutoReconnectCookie = (UINT16)settings->ServerAutoReconnectCookie->cbLen;
|
| 535 |
+
|
| 536 |
+
if (!Stream_EnsureRemainingCapacity(s, 4ull + cbClientAddress + 2ull + cbClientDir))
|
| 537 |
+
goto fail;
|
| 538 |
+
|
| 539 |
+
Stream_Write_UINT16(s, clientAddressFamily); /* clientAddressFamily (2 bytes) */
|
| 540 |
+
Stream_Write_UINT16(s, (UINT16)cbClientAddress); /* cbClientAddress (2 bytes) */
|
| 541 |
+
|
| 542 |
+
Stream_Write(s, clientAddress, cbClientAddress); /* clientAddress */
|
| 543 |
+
|
| 544 |
+
Stream_Write_UINT16(s, (UINT16)cbClientDir); /* cbClientDir (2 bytes) */
|
| 545 |
+
|
| 546 |
+
Stream_Write(s, clientDir, cbClientDir); /* clientDir */
|
| 547 |
+
|
| 548 |
+
if (!rdp_write_client_time_zone(s, settings)) /* clientTimeZone (172 bytes) */
|
| 549 |
+
goto fail;
|
| 550 |
+
|
| 551 |
+
if (!Stream_EnsureRemainingCapacity(s, 10ull))
|
| 552 |
+
goto fail;
|
| 553 |
+
|
| 554 |
+
/* clientSessionId (4 bytes), should be set to 0 */
|
| 555 |
+
Stream_Write_UINT32(s, settings->ClientSessionId);
|
| 556 |
+
freerdp_performance_flags_make(settings);
|
| 557 |
+
Stream_Write_UINT32(s, settings->PerformanceFlags); /* performanceFlags (4 bytes) */
|
| 558 |
+
Stream_Write_UINT16(s, cbAutoReconnectCookie); /* cbAutoReconnectCookie (2 bytes) */
|
| 559 |
+
|
| 560 |
+
if (cbAutoReconnectCookie > 0)
|
| 561 |
+
{
|
| 562 |
+
if (!rdp_compute_client_auto_reconnect_cookie(rdp))
|
| 563 |
+
goto fail;
|
| 564 |
+
if (!rdp_write_client_auto_reconnect_cookie(rdp, s)) /* autoReconnectCookie */
|
| 565 |
+
goto fail;
|
| 566 |
+
}
|
| 567 |
+
|
| 568 |
+
if (freerdp_settings_get_bool(settings, FreeRDP_SupportDynamicTimeZone))
|
| 569 |
+
{
|
| 570 |
+
if (!Stream_EnsureRemainingCapacity(s, 8 + 254 * sizeof(WCHAR)))
|
| 571 |
+
goto fail;
|
| 572 |
+
|
| 573 |
+
Stream_Write_UINT16(s, 0); /* reserved1 (2 bytes) */
|
| 574 |
+
Stream_Write_UINT16(s, 0); /* reserved2 (2 bytes) */
|
| 575 |
+
|
| 576 |
+
size_t rlen = 0;
|
| 577 |
+
const char* tz = freerdp_settings_get_string(settings, FreeRDP_DynamicDSTTimeZoneKeyName);
|
| 578 |
+
if (tz)
|
| 579 |
+
rlen = strnlen(tz, 254);
|
| 580 |
+
Stream_Write_UINT16(s, (UINT16)rlen * sizeof(WCHAR));
|
| 581 |
+
if (Stream_Write_UTF16_String_From_UTF8(s, rlen, tz, rlen, FALSE) < 0)
|
| 582 |
+
goto fail;
|
| 583 |
+
Stream_Write_UINT16(s, settings->DynamicDaylightTimeDisabled ? 0x01 : 0x00);
|
| 584 |
+
}
|
| 585 |
+
|
| 586 |
+
ret = TRUE;
|
| 587 |
+
fail:
|
| 588 |
+
free(clientAddress);
|
| 589 |
+
free(clientDir);
|
| 590 |
+
return ret;
|
| 591 |
+
}
|
| 592 |
+
|
| 593 |
+
static BOOL rdp_read_info_string(rdpSettings* settings, FreeRDP_Settings_Keys_String id,
|
| 594 |
+
UINT32 flags, wStream* s, size_t cbLenNonNull, size_t max)
|
| 595 |
+
{
|
| 596 |
+
union
|
| 597 |
+
{
|
| 598 |
+
char c;
|
| 599 |
+
WCHAR w;
|
| 600 |
+
BYTE b[2];
|
| 601 |
+
} terminator;
|
| 602 |
+
|
| 603 |
+
const BOOL unicode = (flags & INFO_UNICODE) ? TRUE : FALSE;
|
| 604 |
+
const size_t nullSize = unicode ? sizeof(WCHAR) : sizeof(CHAR);
|
| 605 |
+
|
| 606 |
+
if (!freerdp_settings_set_string(settings, id, NULL))
|
| 607 |
+
return FALSE;
|
| 608 |
+
|
| 609 |
+
if (!Stream_CheckAndLogRequiredLength(TAG, s, (size_t)(cbLenNonNull + nullSize)))
|
| 610 |
+
return FALSE;
|
| 611 |
+
|
| 612 |
+
if (cbLenNonNull > 0)
|
| 613 |
+
{
|
| 614 |
+
/* cbDomain is the size in bytes of the character data in the Domain field.
|
| 615 |
+
* This size excludes (!) the length of the mandatory null terminator.
|
| 616 |
+
* Maximum value including the mandatory null terminator: 512
|
| 617 |
+
*/
|
| 618 |
+
if ((cbLenNonNull % 2) || (cbLenNonNull > (max - nullSize)))
|
| 619 |
+
{
|
| 620 |
+
WLog_ERR(TAG, "protocol error: invalid value: %" PRIuz "", cbLenNonNull);
|
| 621 |
+
return FALSE;
|
| 622 |
+
}
|
| 623 |
+
|
| 624 |
+
if (unicode)
|
| 625 |
+
{
|
| 626 |
+
const WCHAR* domain = Stream_PointerAs(s, WCHAR);
|
| 627 |
+
if (!freerdp_settings_set_string_from_utf16N(settings, id, domain,
|
| 628 |
+
cbLenNonNull / sizeof(WCHAR)))
|
| 629 |
+
return FALSE;
|
| 630 |
+
}
|
| 631 |
+
else
|
| 632 |
+
{
|
| 633 |
+
const char* domain = Stream_PointerAs(s, char);
|
| 634 |
+
if (!freerdp_settings_set_string_len(settings, id, domain, cbLenNonNull))
|
| 635 |
+
return FALSE;
|
| 636 |
+
}
|
| 637 |
+
}
|
| 638 |
+
|
| 639 |
+
Stream_Seek(s, cbLenNonNull);
|
| 640 |
+
|
| 641 |
+
terminator.w = L'\0';
|
| 642 |
+
Stream_Read(s, terminator.b, nullSize);
|
| 643 |
+
|
| 644 |
+
if (terminator.w != L'\0')
|
| 645 |
+
{
|
| 646 |
+
WLog_ERR(TAG, "protocol error: Domain must be null terminated");
|
| 647 |
+
(void)freerdp_settings_set_string(settings, id, NULL);
|
| 648 |
+
return FALSE;
|
| 649 |
+
}
|
| 650 |
+
|
| 651 |
+
return TRUE;
|
| 652 |
+
}
|
| 653 |
+
|
| 654 |
+
/**
|
| 655 |
+
* Read Info Packet (TS_INFO_PACKET).
|
| 656 |
+
* msdn{cc240475}
|
| 657 |
+
*/
|
| 658 |
+
|
| 659 |
+
static BOOL rdp_read_info_packet(rdpRdp* rdp, wStream* s, UINT16 tpktlength)
|
| 660 |
+
{
|
| 661 |
+
BOOL smallsize = FALSE;
|
| 662 |
+
UINT32 flags = 0;
|
| 663 |
+
UINT16 cbDomain = 0;
|
| 664 |
+
UINT16 cbUserName = 0;
|
| 665 |
+
UINT16 cbPassword = 0;
|
| 666 |
+
UINT16 cbAlternateShell = 0;
|
| 667 |
+
UINT16 cbWorkingDir = 0;
|
| 668 |
+
UINT32 CompressionLevel = 0;
|
| 669 |
+
rdpSettings* settings = rdp->settings;
|
| 670 |
+
|
| 671 |
+
if (!Stream_CheckAndLogRequiredLength(TAG, s, 18))
|
| 672 |
+
return FALSE;
|
| 673 |
+
|
| 674 |
+
Stream_Read_UINT32(s, settings->KeyboardCodePage); /* CodePage (4 bytes ) */
|
| 675 |
+
Stream_Read_UINT32(s, flags); /* flags (4 bytes) */
|
| 676 |
+
settings->AudioCapture = ((flags & INFO_AUDIOCAPTURE) ? TRUE : FALSE);
|
| 677 |
+
settings->AudioPlayback = ((flags & INFO_NOAUDIOPLAYBACK) ? FALSE : TRUE);
|
| 678 |
+
settings->AutoLogonEnabled = ((flags & INFO_AUTOLOGON) ? TRUE : FALSE);
|
| 679 |
+
settings->RemoteApplicationMode = ((flags & INFO_RAIL) ? TRUE : FALSE);
|
| 680 |
+
settings->HiDefRemoteApp = ((flags & INFO_HIDEF_RAIL_SUPPORTED) ? TRUE : FALSE);
|
| 681 |
+
settings->RemoteConsoleAudio = ((flags & INFO_REMOTECONSOLEAUDIO) ? TRUE : FALSE);
|
| 682 |
+
settings->CompressionEnabled = ((flags & INFO_COMPRESSION) ? TRUE : FALSE);
|
| 683 |
+
settings->LogonNotify = ((flags & INFO_LOGONNOTIFY) ? TRUE : FALSE);
|
| 684 |
+
settings->MouseHasWheel = ((flags & INFO_MOUSE_HAS_WHEEL) ? TRUE : FALSE);
|
| 685 |
+
settings->DisableCtrlAltDel = ((flags & INFO_DISABLECTRLALTDEL) ? TRUE : FALSE);
|
| 686 |
+
settings->ForceEncryptedCsPdu = ((flags & INFO_FORCE_ENCRYPTED_CS_PDU) ? TRUE : FALSE);
|
| 687 |
+
settings->PasswordIsSmartcardPin = ((flags & INFO_PASSWORD_IS_SC_PIN) ? TRUE : FALSE);
|
| 688 |
+
|
| 689 |
+
if (flags & INFO_COMPRESSION)
|
| 690 |
+
{
|
| 691 |
+
CompressionLevel = ((flags & 0x00001E00) >> 9);
|
| 692 |
+
settings->CompressionLevel = CompressionLevel;
|
| 693 |
+
}
|
| 694 |
+
else
|
| 695 |
+
{
|
| 696 |
+
settings->CompressionLevel = 0;
|
| 697 |
+
}
|
| 698 |
+
|
| 699 |
+
/* RDP 4 and 5 have smaller credential limits */
|
| 700 |
+
if (settings->RdpVersion < RDP_VERSION_5_PLUS)
|
| 701 |
+
smallsize = TRUE;
|
| 702 |
+
|
| 703 |
+
Stream_Read_UINT16(s, cbDomain); /* cbDomain (2 bytes) */
|
| 704 |
+
Stream_Read_UINT16(s, cbUserName); /* cbUserName (2 bytes) */
|
| 705 |
+
Stream_Read_UINT16(s, cbPassword); /* cbPassword (2 bytes) */
|
| 706 |
+
Stream_Read_UINT16(s, cbAlternateShell); /* cbAlternateShell (2 bytes) */
|
| 707 |
+
Stream_Read_UINT16(s, cbWorkingDir); /* cbWorkingDir (2 bytes) */
|
| 708 |
+
|
| 709 |
+
if (!rdp_read_info_string(settings, FreeRDP_Domain, flags, s, cbDomain, smallsize ? 52 : 512))
|
| 710 |
+
return FALSE;
|
| 711 |
+
|
| 712 |
+
if (!rdp_read_info_string(settings, FreeRDP_Username, flags, s, cbUserName,
|
| 713 |
+
smallsize ? 44 : 512))
|
| 714 |
+
return FALSE;
|
| 715 |
+
|
| 716 |
+
if (!rdp_read_info_string(settings, FreeRDP_Password, flags, s, cbPassword,
|
| 717 |
+
smallsize ? 32 : 512))
|
| 718 |
+
return FALSE;
|
| 719 |
+
|
| 720 |
+
if (!rdp_read_info_string(settings, FreeRDP_AlternateShell, flags, s, cbAlternateShell, 512))
|
| 721 |
+
return FALSE;
|
| 722 |
+
|
| 723 |
+
if (!rdp_read_info_string(settings, FreeRDP_ShellWorkingDirectory, flags, s, cbWorkingDir, 512))
|
| 724 |
+
return FALSE;
|
| 725 |
+
|
| 726 |
+
if (settings->RdpVersion >= RDP_VERSION_5_PLUS)
|
| 727 |
+
{
|
| 728 |
+
if (!rdp_read_extended_info_packet(rdp, s)) /* extraInfo */
|
| 729 |
+
return FALSE;
|
| 730 |
+
}
|
| 731 |
+
|
| 732 |
+
const size_t xrem = Stream_GetRemainingLength(s);
|
| 733 |
+
if (!tpkt_ensure_stream_consumed(s, tpktlength))
|
| 734 |
+
Stream_Seek(s, xrem);
|
| 735 |
+
return TRUE;
|
| 736 |
+
}
|
| 737 |
+
|
| 738 |
+
/**
|
| 739 |
+
* Write Info Packet (TS_INFO_PACKET).
|
| 740 |
+
* msdn{cc240475}
|
| 741 |
+
*/
|
| 742 |
+
|
| 743 |
+
static BOOL rdp_write_info_packet(rdpRdp* rdp, wStream* s)
|
| 744 |
+
{
|
| 745 |
+
BOOL ret = FALSE;
|
| 746 |
+
UINT32 flags = 0;
|
| 747 |
+
WCHAR* domainW = NULL;
|
| 748 |
+
size_t cbDomain = 0;
|
| 749 |
+
WCHAR* userNameW = NULL;
|
| 750 |
+
size_t cbUserName = 0;
|
| 751 |
+
WCHAR* passwordW = NULL;
|
| 752 |
+
size_t cbPassword = 0;
|
| 753 |
+
WCHAR* alternateShellW = NULL;
|
| 754 |
+
size_t cbAlternateShell = 0;
|
| 755 |
+
WCHAR* workingDirW = NULL;
|
| 756 |
+
size_t cbWorkingDir = 0;
|
| 757 |
+
BOOL usedPasswordCookie = FALSE;
|
| 758 |
+
rdpSettings* settings = NULL;
|
| 759 |
+
|
| 760 |
+
WINPR_ASSERT(rdp);
|
| 761 |
+
settings = rdp->settings;
|
| 762 |
+
WINPR_ASSERT(settings);
|
| 763 |
+
|
| 764 |
+
flags = INFO_MOUSE | INFO_UNICODE | INFO_LOGONERRORS | INFO_MAXIMIZESHELL |
|
| 765 |
+
INFO_ENABLEWINDOWSKEY | INFO_DISABLECTRLALTDEL | INFO_MOUSE_HAS_WHEEL |
|
| 766 |
+
INFO_FORCE_ENCRYPTED_CS_PDU;
|
| 767 |
+
|
| 768 |
+
if (settings->SmartcardLogon)
|
| 769 |
+
{
|
| 770 |
+
flags |= INFO_AUTOLOGON;
|
| 771 |
+
flags |= INFO_PASSWORD_IS_SC_PIN;
|
| 772 |
+
}
|
| 773 |
+
|
| 774 |
+
if (settings->AudioCapture)
|
| 775 |
+
flags |= INFO_AUDIOCAPTURE;
|
| 776 |
+
|
| 777 |
+
if (!settings->AudioPlayback)
|
| 778 |
+
flags |= INFO_NOAUDIOPLAYBACK;
|
| 779 |
+
|
| 780 |
+
if (settings->VideoDisable)
|
| 781 |
+
flags |= INFO_VIDEO_DISABLE;
|
| 782 |
+
|
| 783 |
+
if (settings->AutoLogonEnabled)
|
| 784 |
+
flags |= INFO_AUTOLOGON;
|
| 785 |
+
|
| 786 |
+
if (settings->RemoteApplicationMode)
|
| 787 |
+
{
|
| 788 |
+
if (settings->HiDefRemoteApp)
|
| 789 |
+
flags |= INFO_HIDEF_RAIL_SUPPORTED;
|
| 790 |
+
|
| 791 |
+
flags |= INFO_RAIL;
|
| 792 |
+
}
|
| 793 |
+
|
| 794 |
+
if (settings->RemoteConsoleAudio)
|
| 795 |
+
flags |= INFO_REMOTECONSOLEAUDIO;
|
| 796 |
+
|
| 797 |
+
if (settings->CompressionEnabled)
|
| 798 |
+
{
|
| 799 |
+
flags |= INFO_COMPRESSION;
|
| 800 |
+
flags |= ((settings->CompressionLevel << 9) & 0x00001E00);
|
| 801 |
+
}
|
| 802 |
+
|
| 803 |
+
if (settings->LogonNotify)
|
| 804 |
+
flags |= INFO_LOGONNOTIFY;
|
| 805 |
+
|
| 806 |
+
if (settings->PasswordIsSmartcardPin)
|
| 807 |
+
flags |= INFO_PASSWORD_IS_SC_PIN;
|
| 808 |
+
|
| 809 |
+
{
|
| 810 |
+
char* flags_description = rdp_info_package_flags_description(flags);
|
| 811 |
+
|
| 812 |
+
if (flags_description)
|
| 813 |
+
{
|
| 814 |
+
WLog_DBG(TAG, "Client Info Packet Flags = %s", flags_description);
|
| 815 |
+
free(flags_description);
|
| 816 |
+
}
|
| 817 |
+
}
|
| 818 |
+
|
| 819 |
+
domainW = freerdp_settings_get_string_as_utf16(settings, FreeRDP_Domain, &cbDomain);
|
| 820 |
+
if (cbDomain > UINT16_MAX / sizeof(WCHAR))
|
| 821 |
+
{
|
| 822 |
+
WLog_ERR(TAG, "cbDomain > UINT16_MAX");
|
| 823 |
+
goto fail;
|
| 824 |
+
}
|
| 825 |
+
cbDomain *= sizeof(WCHAR);
|
| 826 |
+
|
| 827 |
+
/* user name provided by the expert for connecting to the novice computer */
|
| 828 |
+
userNameW = freerdp_settings_get_string_as_utf16(settings, FreeRDP_Username, &cbUserName);
|
| 829 |
+
if (cbUserName > UINT16_MAX / sizeof(WCHAR))
|
| 830 |
+
{
|
| 831 |
+
WLog_ERR(TAG, "cbUserName > UINT16_MAX");
|
| 832 |
+
goto fail;
|
| 833 |
+
}
|
| 834 |
+
cbUserName *= sizeof(WCHAR);
|
| 835 |
+
|
| 836 |
+
const char* pin = "*";
|
| 837 |
+
if (!settings->RemoteAssistanceMode)
|
| 838 |
+
{
|
| 839 |
+
/* Ignore redirection password if we´re using smartcard and have the pin as password */
|
| 840 |
+
if (((flags & INFO_PASSWORD_IS_SC_PIN) == 0) && settings->RedirectionPassword &&
|
| 841 |
+
(settings->RedirectionPasswordLength > 0))
|
| 842 |
+
{
|
| 843 |
+
union
|
| 844 |
+
{
|
| 845 |
+
BYTE* bp;
|
| 846 |
+
WCHAR* wp;
|
| 847 |
+
} ptrconv;
|
| 848 |
+
|
| 849 |
+
if (settings->RedirectionPasswordLength > UINT16_MAX)
|
| 850 |
+
{
|
| 851 |
+
WLog_ERR(TAG, "RedirectionPasswordLength > UINT16_MAX");
|
| 852 |
+
goto fail;
|
| 853 |
+
}
|
| 854 |
+
usedPasswordCookie = TRUE;
|
| 855 |
+
|
| 856 |
+
ptrconv.bp = settings->RedirectionPassword;
|
| 857 |
+
passwordW = ptrconv.wp;
|
| 858 |
+
cbPassword = (UINT16)settings->RedirectionPasswordLength;
|
| 859 |
+
}
|
| 860 |
+
else
|
| 861 |
+
pin = freerdp_settings_get_string(settings, FreeRDP_Password);
|
| 862 |
+
}
|
| 863 |
+
|
| 864 |
+
if (!usedPasswordCookie && pin)
|
| 865 |
+
{
|
| 866 |
+
passwordW = ConvertUtf8ToWCharAlloc(pin, &cbPassword);
|
| 867 |
+
if (cbPassword > UINT16_MAX / sizeof(WCHAR))
|
| 868 |
+
{
|
| 869 |
+
WLog_ERR(TAG, "cbPassword > UINT16_MAX");
|
| 870 |
+
goto fail;
|
| 871 |
+
}
|
| 872 |
+
cbPassword = (UINT16)cbPassword * sizeof(WCHAR);
|
| 873 |
+
}
|
| 874 |
+
|
| 875 |
+
const char* altShell = NULL;
|
| 876 |
+
if (!settings->RemoteAssistanceMode)
|
| 877 |
+
altShell = freerdp_settings_get_string(settings, FreeRDP_AlternateShell);
|
| 878 |
+
else if (settings->RemoteAssistancePassStub)
|
| 879 |
+
altShell = "*"; /* This field MUST be filled with "*" */
|
| 880 |
+
else
|
| 881 |
+
altShell = freerdp_settings_get_string(settings, FreeRDP_RemoteAssistancePassword);
|
| 882 |
+
|
| 883 |
+
if (altShell && strlen(altShell) > 0)
|
| 884 |
+
{
|
| 885 |
+
alternateShellW = ConvertUtf8ToWCharAlloc(altShell, &cbAlternateShell);
|
| 886 |
+
if (!alternateShellW)
|
| 887 |
+
{
|
| 888 |
+
WLog_ERR(TAG, "alternateShellW == NULL");
|
| 889 |
+
goto fail;
|
| 890 |
+
}
|
| 891 |
+
if (cbAlternateShell > (UINT16_MAX / sizeof(WCHAR)))
|
| 892 |
+
{
|
| 893 |
+
WLog_ERR(TAG, "cbAlternateShell > UINT16_MAX");
|
| 894 |
+
goto fail;
|
| 895 |
+
}
|
| 896 |
+
cbAlternateShell = (UINT16)cbAlternateShell * sizeof(WCHAR);
|
| 897 |
+
}
|
| 898 |
+
|
| 899 |
+
FreeRDP_Settings_Keys_String inputId = FreeRDP_RemoteAssistanceSessionId;
|
| 900 |
+
if (!freerdp_settings_get_bool(settings, FreeRDP_RemoteAssistanceMode))
|
| 901 |
+
inputId = FreeRDP_ShellWorkingDirectory;
|
| 902 |
+
|
| 903 |
+
workingDirW = freerdp_settings_get_string_as_utf16(settings, inputId, &cbWorkingDir);
|
| 904 |
+
if (cbWorkingDir > (UINT16_MAX / sizeof(WCHAR)))
|
| 905 |
+
{
|
| 906 |
+
WLog_ERR(TAG, "cbWorkingDir > UINT16_MAX");
|
| 907 |
+
goto fail;
|
| 908 |
+
}
|
| 909 |
+
cbWorkingDir = (UINT16)cbWorkingDir * sizeof(WCHAR);
|
| 910 |
+
|
| 911 |
+
if (!Stream_EnsureRemainingCapacity(s, 18ull + cbDomain + cbUserName + cbPassword +
|
| 912 |
+
cbAlternateShell + cbWorkingDir + 5 * sizeof(WCHAR)))
|
| 913 |
+
goto fail;
|
| 914 |
+
|
| 915 |
+
Stream_Write_UINT32(s, settings->KeyboardCodePage); /* CodePage (4 bytes) */
|
| 916 |
+
Stream_Write_UINT32(s, flags); /* flags (4 bytes) */
|
| 917 |
+
Stream_Write_UINT16(s, (UINT16)cbDomain); /* cbDomain (2 bytes) */
|
| 918 |
+
Stream_Write_UINT16(s, (UINT16)cbUserName); /* cbUserName (2 bytes) */
|
| 919 |
+
Stream_Write_UINT16(s, (UINT16)cbPassword); /* cbPassword (2 bytes) */
|
| 920 |
+
Stream_Write_UINT16(s, (UINT16)cbAlternateShell); /* cbAlternateShell (2 bytes) */
|
| 921 |
+
Stream_Write_UINT16(s, (UINT16)cbWorkingDir); /* cbWorkingDir (2 bytes) */
|
| 922 |
+
|
| 923 |
+
Stream_Write(s, domainW, cbDomain);
|
| 924 |
+
|
| 925 |
+
/* the mandatory null terminator */
|
| 926 |
+
Stream_Write_UINT16(s, 0);
|
| 927 |
+
|
| 928 |
+
Stream_Write(s, userNameW, cbUserName);
|
| 929 |
+
|
| 930 |
+
/* the mandatory null terminator */
|
| 931 |
+
Stream_Write_UINT16(s, 0);
|
| 932 |
+
|
| 933 |
+
Stream_Write(s, passwordW, cbPassword);
|
| 934 |
+
|
| 935 |
+
/* the mandatory null terminator */
|
| 936 |
+
Stream_Write_UINT16(s, 0);
|
| 937 |
+
|
| 938 |
+
Stream_Write(s, alternateShellW, cbAlternateShell);
|
| 939 |
+
|
| 940 |
+
/* the mandatory null terminator */
|
| 941 |
+
Stream_Write_UINT16(s, 0);
|
| 942 |
+
|
| 943 |
+
Stream_Write(s, workingDirW, cbWorkingDir);
|
| 944 |
+
|
| 945 |
+
/* the mandatory null terminator */
|
| 946 |
+
Stream_Write_UINT16(s, 0);
|
| 947 |
+
ret = TRUE;
|
| 948 |
+
fail:
|
| 949 |
+
free(domainW);
|
| 950 |
+
free(userNameW);
|
| 951 |
+
free(alternateShellW);
|
| 952 |
+
free(workingDirW);
|
| 953 |
+
|
| 954 |
+
if (!usedPasswordCookie)
|
| 955 |
+
free(passwordW);
|
| 956 |
+
|
| 957 |
+
if (!ret)
|
| 958 |
+
return FALSE;
|
| 959 |
+
|
| 960 |
+
if (settings->RdpVersion >= RDP_VERSION_5_PLUS)
|
| 961 |
+
ret = rdp_write_extended_info_packet(rdp, s); /* extraInfo */
|
| 962 |
+
|
| 963 |
+
return ret;
|
| 964 |
+
}
|
| 965 |
+
|
| 966 |
+
/**
|
| 967 |
+
* Read Client Info PDU (CLIENT_INFO_PDU).
|
| 968 |
+
* msdn{cc240474}
|
| 969 |
+
* @param rdp RDP module
|
| 970 |
+
* @param s stream
|
| 971 |
+
*/
|
| 972 |
+
|
| 973 |
+
BOOL rdp_recv_client_info(rdpRdp* rdp, wStream* s)
|
| 974 |
+
{
|
| 975 |
+
UINT16 length = 0;
|
| 976 |
+
UINT16 channelId = 0;
|
| 977 |
+
UINT16 securityFlags = 0;
|
| 978 |
+
|
| 979 |
+
WINPR_ASSERT(rdp_get_state(rdp) == CONNECTION_STATE_SECURE_SETTINGS_EXCHANGE);
|
| 980 |
+
|
| 981 |
+
if (!rdp_read_header(rdp, s, &length, &channelId))
|
| 982 |
+
return FALSE;
|
| 983 |
+
|
| 984 |
+
if (!rdp_read_security_header(rdp, s, &securityFlags, &length))
|
| 985 |
+
return FALSE;
|
| 986 |
+
|
| 987 |
+
if ((securityFlags & SEC_INFO_PKT) == 0)
|
| 988 |
+
return FALSE;
|
| 989 |
+
|
| 990 |
+
if (rdp->settings->UseRdpSecurityLayer)
|
| 991 |
+
{
|
| 992 |
+
if (securityFlags & SEC_REDIRECTION_PKT)
|
| 993 |
+
{
|
| 994 |
+
WLog_ERR(TAG, "Error: SEC_REDIRECTION_PKT unsupported");
|
| 995 |
+
return FALSE;
|
| 996 |
+
}
|
| 997 |
+
|
| 998 |
+
if (securityFlags & SEC_ENCRYPT)
|
| 999 |
+
{
|
| 1000 |
+
if (!rdp_decrypt(rdp, s, &length, securityFlags))
|
| 1001 |
+
return FALSE;
|
| 1002 |
+
}
|
| 1003 |
+
}
|
| 1004 |
+
|
| 1005 |
+
return rdp_read_info_packet(rdp, s, length);
|
| 1006 |
+
}
|
| 1007 |
+
|
| 1008 |
+
/**
|
| 1009 |
+
* Send Client Info PDU (CLIENT_INFO_PDU).
|
| 1010 |
+
* msdn{cc240474}
|
| 1011 |
+
* @param rdp RDP module
|
| 1012 |
+
*/
|
| 1013 |
+
|
| 1014 |
+
BOOL rdp_send_client_info(rdpRdp* rdp)
|
| 1015 |
+
{
|
| 1016 |
+
wStream* s = NULL;
|
| 1017 |
+
WINPR_ASSERT(rdp);
|
| 1018 |
+
rdp->sec_flags |= SEC_INFO_PKT;
|
| 1019 |
+
s = rdp_send_stream_init(rdp);
|
| 1020 |
+
|
| 1021 |
+
if (!s)
|
| 1022 |
+
{
|
| 1023 |
+
WLog_ERR(TAG, "Stream_New failed!");
|
| 1024 |
+
return FALSE;
|
| 1025 |
+
}
|
| 1026 |
+
|
| 1027 |
+
if (!rdp_write_info_packet(rdp, s))
|
| 1028 |
+
{
|
| 1029 |
+
Stream_Release(s);
|
| 1030 |
+
return FALSE;
|
| 1031 |
+
}
|
| 1032 |
+
return rdp_send(rdp, s, MCS_GLOBAL_CHANNEL_ID);
|
| 1033 |
+
}
|
| 1034 |
+
|
| 1035 |
+
static void rdp_free_logon_info(logon_info* info)
|
| 1036 |
+
{
|
| 1037 |
+
if (!info)
|
| 1038 |
+
return;
|
| 1039 |
+
free(info->domain);
|
| 1040 |
+
free(info->username);
|
| 1041 |
+
|
| 1042 |
+
const logon_info empty = { 0 };
|
| 1043 |
+
*info = empty;
|
| 1044 |
+
}
|
| 1045 |
+
|
| 1046 |
+
static BOOL rdp_info_read_string(const char* what, wStream* s, size_t size, size_t max,
|
| 1047 |
+
BOOL skipMax, char** dst)
|
| 1048 |
+
{
|
| 1049 |
+
WINPR_ASSERT(dst);
|
| 1050 |
+
*dst = NULL;
|
| 1051 |
+
|
| 1052 |
+
if (size == 0)
|
| 1053 |
+
{
|
| 1054 |
+
if (skipMax)
|
| 1055 |
+
return Stream_SafeSeek(s, max);
|
| 1056 |
+
return TRUE;
|
| 1057 |
+
}
|
| 1058 |
+
|
| 1059 |
+
if (((size % sizeof(WCHAR)) != 0) || (size > max))
|
| 1060 |
+
{
|
| 1061 |
+
WLog_ERR(TAG, "protocol error: invalid %s value: %" PRIu32 "", what, size);
|
| 1062 |
+
return FALSE;
|
| 1063 |
+
}
|
| 1064 |
+
|
| 1065 |
+
const WCHAR* str = Stream_ConstPointer(s);
|
| 1066 |
+
if (!Stream_SafeSeek(s, skipMax ? max : size))
|
| 1067 |
+
return FALSE;
|
| 1068 |
+
|
| 1069 |
+
if (str[size / sizeof(WCHAR) - 1])
|
| 1070 |
+
{
|
| 1071 |
+
WLog_ERR(TAG, "protocol error: %s must be null terminated", what);
|
| 1072 |
+
return FALSE;
|
| 1073 |
+
}
|
| 1074 |
+
|
| 1075 |
+
size_t len = 0;
|
| 1076 |
+
char* rc = ConvertWCharNToUtf8Alloc(str, size / sizeof(WCHAR), &len);
|
| 1077 |
+
if (!rc)
|
| 1078 |
+
{
|
| 1079 |
+
WLog_ERR(TAG, "failed to convert the %s string", what);
|
| 1080 |
+
free(rc);
|
| 1081 |
+
return FALSE;
|
| 1082 |
+
}
|
| 1083 |
+
|
| 1084 |
+
*dst = rc;
|
| 1085 |
+
return TRUE;
|
| 1086 |
+
}
|
| 1087 |
+
|
| 1088 |
+
static BOOL rdp_recv_logon_info_v1(rdpRdp* rdp, wStream* s, logon_info* info)
|
| 1089 |
+
{
|
| 1090 |
+
UINT32 cbDomain = 0;
|
| 1091 |
+
UINT32 cbUserName = 0;
|
| 1092 |
+
|
| 1093 |
+
WINPR_UNUSED(rdp);
|
| 1094 |
+
WINPR_ASSERT(info);
|
| 1095 |
+
|
| 1096 |
+
if (!Stream_CheckAndLogRequiredLength(TAG, s, 576))
|
| 1097 |
+
return FALSE;
|
| 1098 |
+
|
| 1099 |
+
Stream_Read_UINT32(s, cbDomain); /* cbDomain (4 bytes) */
|
| 1100 |
+
|
| 1101 |
+
/* cbDomain is the size of the Unicode character data (including the mandatory
|
| 1102 |
+
* null terminator) in bytes present in the fixed-length (52 bytes) Domain field
|
| 1103 |
+
*/
|
| 1104 |
+
if (!rdp_info_read_string("Domain", s, cbDomain, 52, TRUE, &info->domain))
|
| 1105 |
+
goto fail;
|
| 1106 |
+
|
| 1107 |
+
Stream_Read_UINT32(s, cbUserName); /* cbUserName (4 bytes) */
|
| 1108 |
+
|
| 1109 |
+
/* cbUserName is the size of the Unicode character data (including the mandatory
|
| 1110 |
+
* null terminator) in bytes present in the fixed-length (512 bytes) UserName field.
|
| 1111 |
+
*/
|
| 1112 |
+
if (!rdp_info_read_string("UserName", s, cbUserName, 512, TRUE, &info->username))
|
| 1113 |
+
goto fail;
|
| 1114 |
+
|
| 1115 |
+
Stream_Read_UINT32(s, info->sessionId); /* SessionId (4 bytes) */
|
| 1116 |
+
WLog_DBG(TAG, "LogonInfoV1: SessionId: 0x%08" PRIX32 " UserName: [%s] Domain: [%s]",
|
| 1117 |
+
info->sessionId, info->username, info->domain);
|
| 1118 |
+
return TRUE;
|
| 1119 |
+
fail:
|
| 1120 |
+
return FALSE;
|
| 1121 |
+
}
|
| 1122 |
+
|
| 1123 |
+
static BOOL rdp_recv_logon_info_v2(rdpRdp* rdp, wStream* s, logon_info* info)
|
| 1124 |
+
{
|
| 1125 |
+
UINT16 Version = 0;
|
| 1126 |
+
UINT32 Size = 0;
|
| 1127 |
+
UINT32 cbDomain = 0;
|
| 1128 |
+
UINT32 cbUserName = 0;
|
| 1129 |
+
|
| 1130 |
+
WINPR_ASSERT(rdp);
|
| 1131 |
+
WINPR_ASSERT(s);
|
| 1132 |
+
WINPR_ASSERT(info);
|
| 1133 |
+
|
| 1134 |
+
WINPR_UNUSED(rdp);
|
| 1135 |
+
|
| 1136 |
+
if (!Stream_CheckAndLogRequiredLength(TAG, s, logonInfoV2TotalSize))
|
| 1137 |
+
return FALSE;
|
| 1138 |
+
|
| 1139 |
+
Stream_Read_UINT16(s, Version); /* Version (2 bytes) */
|
| 1140 |
+
if (Version != SAVE_SESSION_PDU_VERSION_ONE)
|
| 1141 |
+
{
|
| 1142 |
+
WLog_WARN(TAG, "LogonInfoV2::Version expected %" PRIu16 " bytes, got %" PRIu16,
|
| 1143 |
+
SAVE_SESSION_PDU_VERSION_ONE, Version);
|
| 1144 |
+
return FALSE;
|
| 1145 |
+
}
|
| 1146 |
+
|
| 1147 |
+
Stream_Read_UINT32(s, Size); /* Size (4 bytes) */
|
| 1148 |
+
|
| 1149 |
+
/* [MS-RDPBCGR] 2.2.10.1.1.2 Logon Info Version 2 (TS_LOGON_INFO_VERSION_2)
|
| 1150 |
+
* should be logonInfoV2TotalSize
|
| 1151 |
+
* but even MS server 2019 sends logonInfoV2Size
|
| 1152 |
+
*/
|
| 1153 |
+
if (Size != logonInfoV2TotalSize)
|
| 1154 |
+
{
|
| 1155 |
+
if (Size != logonInfoV2Size)
|
| 1156 |
+
{
|
| 1157 |
+
WLog_WARN(TAG, "LogonInfoV2::Size expected %" PRIu32 " bytes, got %" PRIu32,
|
| 1158 |
+
logonInfoV2TotalSize, Size);
|
| 1159 |
+
return FALSE;
|
| 1160 |
+
}
|
| 1161 |
+
}
|
| 1162 |
+
|
| 1163 |
+
Stream_Read_UINT32(s, info->sessionId); /* SessionId (4 bytes) */
|
| 1164 |
+
Stream_Read_UINT32(s, cbDomain); /* cbDomain (4 bytes) */
|
| 1165 |
+
Stream_Read_UINT32(s, cbUserName); /* cbUserName (4 bytes) */
|
| 1166 |
+
Stream_Seek(s, logonInfoV2ReservedSize); /* pad (558 bytes) */
|
| 1167 |
+
|
| 1168 |
+
/* cbDomain is the size in bytes of the Unicode character data in the Domain field.
|
| 1169 |
+
* The size of the mandatory null terminator is include in this value.
|
| 1170 |
+
* Note: Since MS-RDPBCGR 2.2.10.1.1.2 does not mention any size limits we assume
|
| 1171 |
+
* that the maximum value is 52 bytes, according to the fixed size of the
|
| 1172 |
+
* Domain field in the Logon Info Version 1 (TS_LOGON_INFO) structure.
|
| 1173 |
+
*/
|
| 1174 |
+
if (!rdp_info_read_string("Domain", s, cbDomain, 52, FALSE, &info->domain))
|
| 1175 |
+
goto fail;
|
| 1176 |
+
|
| 1177 |
+
/* cbUserName is the size in bytes of the Unicode character data in the UserName field.
|
| 1178 |
+
* The size of the mandatory null terminator is include in this value.
|
| 1179 |
+
* Note: Since MS-RDPBCGR 2.2.10.1.1.2 does not mention any size limits we assume
|
| 1180 |
+
* that the maximum value is 512 bytes, according to the fixed size of the
|
| 1181 |
+
* Username field in the Logon Info Version 1 (TS_LOGON_INFO) structure.
|
| 1182 |
+
*/
|
| 1183 |
+
if (!rdp_info_read_string("UserName", s, cbUserName, 512, FALSE, &info->username))
|
| 1184 |
+
goto fail;
|
| 1185 |
+
|
| 1186 |
+
/* We´ve seen undocumented padding with windows 11 here.
|
| 1187 |
+
* unless it has actual data in it ignore it.
|
| 1188 |
+
* if there is unexpected data, print a warning and dump the contents
|
| 1189 |
+
*/
|
| 1190 |
+
const size_t rem = Stream_GetRemainingLength(s);
|
| 1191 |
+
if (rem > 0)
|
| 1192 |
+
{
|
| 1193 |
+
BOOL warn = FALSE;
|
| 1194 |
+
const char* str = Stream_ConstPointer(s);
|
| 1195 |
+
for (size_t x = 0; x < rem; x++)
|
| 1196 |
+
{
|
| 1197 |
+
if (str[x] != '\0')
|
| 1198 |
+
warn = TRUE;
|
| 1199 |
+
}
|
| 1200 |
+
if (warn)
|
| 1201 |
+
{
|
| 1202 |
+
WLog_WARN(TAG, "unexpected padding of %" PRIuz " bytes, data not '\0'", rem);
|
| 1203 |
+
winpr_HexDump(TAG, WLOG_TRACE, str, rem);
|
| 1204 |
+
}
|
| 1205 |
+
|
| 1206 |
+
if (!Stream_SafeSeek(s, rem))
|
| 1207 |
+
goto fail;
|
| 1208 |
+
}
|
| 1209 |
+
|
| 1210 |
+
WLog_DBG(TAG, "LogonInfoV2: SessionId: 0x%08" PRIX32 " UserName: [%s] Domain: [%s]",
|
| 1211 |
+
info->sessionId, info->username, info->domain);
|
| 1212 |
+
return TRUE;
|
| 1213 |
+
fail:
|
| 1214 |
+
return FALSE;
|
| 1215 |
+
}
|
| 1216 |
+
|
| 1217 |
+
static BOOL rdp_recv_logon_plain_notify(rdpRdp* rdp, wStream* s)
|
| 1218 |
+
{
|
| 1219 |
+
WINPR_UNUSED(rdp);
|
| 1220 |
+
if (!Stream_CheckAndLogRequiredLength(TAG, s, 576))
|
| 1221 |
+
return FALSE;
|
| 1222 |
+
|
| 1223 |
+
Stream_Seek(s, 576); /* pad (576 bytes) */
|
| 1224 |
+
WLog_DBG(TAG, "LogonPlainNotify");
|
| 1225 |
+
return TRUE;
|
| 1226 |
+
}
|
| 1227 |
+
|
| 1228 |
+
static BOOL rdp_recv_logon_error_info(rdpRdp* rdp, wStream* s, logon_info_ex* info)
|
| 1229 |
+
{
|
| 1230 |
+
freerdp* instance = NULL;
|
| 1231 |
+
UINT32 errorNotificationType = 0;
|
| 1232 |
+
UINT32 errorNotificationData = 0;
|
| 1233 |
+
|
| 1234 |
+
WINPR_ASSERT(rdp);
|
| 1235 |
+
WINPR_ASSERT(rdp->context);
|
| 1236 |
+
WINPR_ASSERT(s);
|
| 1237 |
+
WINPR_ASSERT(info);
|
| 1238 |
+
|
| 1239 |
+
instance = rdp->context->instance;
|
| 1240 |
+
WINPR_ASSERT(instance);
|
| 1241 |
+
|
| 1242 |
+
if (!Stream_CheckAndLogRequiredLength(TAG, s, 8))
|
| 1243 |
+
return FALSE;
|
| 1244 |
+
|
| 1245 |
+
Stream_Read_UINT32(s, errorNotificationType); /* errorNotificationType (4 bytes) */
|
| 1246 |
+
Stream_Read_UINT32(s, errorNotificationData); /* errorNotificationData (4 bytes) */
|
| 1247 |
+
WLog_DBG(TAG, "LogonErrorInfo: Data: 0x%08" PRIX32 " Type: 0x%08" PRIX32 "",
|
| 1248 |
+
errorNotificationData, errorNotificationType);
|
| 1249 |
+
IFCALL(instance->LogonErrorInfo, instance, errorNotificationData, errorNotificationType);
|
| 1250 |
+
info->ErrorNotificationType = errorNotificationType;
|
| 1251 |
+
info->ErrorNotificationData = errorNotificationData;
|
| 1252 |
+
return TRUE;
|
| 1253 |
+
}
|
| 1254 |
+
|
| 1255 |
+
static BOOL rdp_recv_logon_info_extended(rdpRdp* rdp, wStream* s, logon_info_ex* info)
|
| 1256 |
+
{
|
| 1257 |
+
UINT32 cbFieldData = 0;
|
| 1258 |
+
UINT32 fieldsPresent = 0;
|
| 1259 |
+
UINT16 Length = 0;
|
| 1260 |
+
|
| 1261 |
+
WINPR_ASSERT(rdp);
|
| 1262 |
+
WINPR_ASSERT(s);
|
| 1263 |
+
WINPR_ASSERT(info);
|
| 1264 |
+
|
| 1265 |
+
if (!Stream_CheckAndLogRequiredLength(TAG, s, 6))
|
| 1266 |
+
{
|
| 1267 |
+
WLog_WARN(TAG, "received short logon info extended, need 6 bytes, got %" PRIuz,
|
| 1268 |
+
Stream_GetRemainingLength(s));
|
| 1269 |
+
return FALSE;
|
| 1270 |
+
}
|
| 1271 |
+
|
| 1272 |
+
Stream_Read_UINT16(s, Length); /* Length (2 bytes) */
|
| 1273 |
+
Stream_Read_UINT32(s, fieldsPresent); /* fieldsPresent (4 bytes) */
|
| 1274 |
+
|
| 1275 |
+
if ((Length < 6) || (!Stream_CheckAndLogRequiredLength(TAG, s, (Length - 6U))))
|
| 1276 |
+
{
|
| 1277 |
+
WLog_WARN(TAG,
|
| 1278 |
+
"received short logon info extended, need %" PRIu16 " - 6 bytes, got %" PRIuz,
|
| 1279 |
+
Length, Stream_GetRemainingLength(s));
|
| 1280 |
+
return FALSE;
|
| 1281 |
+
}
|
| 1282 |
+
|
| 1283 |
+
WLog_DBG(TAG, "LogonInfoExtended: fieldsPresent: 0x%08" PRIX32 "", fieldsPresent);
|
| 1284 |
+
|
| 1285 |
+
/* logonFields */
|
| 1286 |
+
|
| 1287 |
+
if (fieldsPresent & LOGON_EX_AUTORECONNECTCOOKIE)
|
| 1288 |
+
{
|
| 1289 |
+
if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
|
| 1290 |
+
return FALSE;
|
| 1291 |
+
|
| 1292 |
+
info->haveCookie = TRUE;
|
| 1293 |
+
Stream_Read_UINT32(s, cbFieldData); /* cbFieldData (4 bytes) */
|
| 1294 |
+
|
| 1295 |
+
if (!Stream_CheckAndLogRequiredLength(TAG, s, cbFieldData))
|
| 1296 |
+
return FALSE;
|
| 1297 |
+
|
| 1298 |
+
if (!rdp_read_server_auto_reconnect_cookie(rdp, s, info))
|
| 1299 |
+
return FALSE;
|
| 1300 |
+
}
|
| 1301 |
+
|
| 1302 |
+
if (fieldsPresent & LOGON_EX_LOGONERRORS)
|
| 1303 |
+
{
|
| 1304 |
+
info->haveErrorInfo = TRUE;
|
| 1305 |
+
|
| 1306 |
+
if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
|
| 1307 |
+
return FALSE;
|
| 1308 |
+
|
| 1309 |
+
Stream_Read_UINT32(s, cbFieldData); /* cbFieldData (4 bytes) */
|
| 1310 |
+
|
| 1311 |
+
if (!Stream_CheckAndLogRequiredLength(TAG, s, cbFieldData))
|
| 1312 |
+
return FALSE;
|
| 1313 |
+
|
| 1314 |
+
if (!rdp_recv_logon_error_info(rdp, s, info))
|
| 1315 |
+
return FALSE;
|
| 1316 |
+
}
|
| 1317 |
+
|
| 1318 |
+
if (!Stream_CheckAndLogRequiredLength(TAG, s, 570))
|
| 1319 |
+
return FALSE;
|
| 1320 |
+
|
| 1321 |
+
Stream_Seek(s, 570); /* pad (570 bytes) */
|
| 1322 |
+
return TRUE;
|
| 1323 |
+
}
|
| 1324 |
+
|
| 1325 |
+
BOOL rdp_recv_save_session_info(rdpRdp* rdp, wStream* s)
|
| 1326 |
+
{
|
| 1327 |
+
UINT32 infoType = 0;
|
| 1328 |
+
BOOL status = 0;
|
| 1329 |
+
logon_info logonInfo = { 0 };
|
| 1330 |
+
logon_info_ex logonInfoEx = { 0 };
|
| 1331 |
+
rdpContext* context = rdp->context;
|
| 1332 |
+
rdpUpdate* update = rdp->context->update;
|
| 1333 |
+
|
| 1334 |
+
if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
|
| 1335 |
+
return FALSE;
|
| 1336 |
+
|
| 1337 |
+
Stream_Read_UINT32(s, infoType); /* infoType (4 bytes) */
|
| 1338 |
+
|
| 1339 |
+
switch (infoType)
|
| 1340 |
+
{
|
| 1341 |
+
case INFO_TYPE_LOGON:
|
| 1342 |
+
status = rdp_recv_logon_info_v1(rdp, s, &logonInfo);
|
| 1343 |
+
|
| 1344 |
+
if (status && update->SaveSessionInfo)
|
| 1345 |
+
status = update->SaveSessionInfo(context, infoType, &logonInfo);
|
| 1346 |
+
|
| 1347 |
+
rdp_free_logon_info(&logonInfo);
|
| 1348 |
+
break;
|
| 1349 |
+
|
| 1350 |
+
case INFO_TYPE_LOGON_LONG:
|
| 1351 |
+
status = rdp_recv_logon_info_v2(rdp, s, &logonInfo);
|
| 1352 |
+
|
| 1353 |
+
if (status && update->SaveSessionInfo)
|
| 1354 |
+
status = update->SaveSessionInfo(context, infoType, &logonInfo);
|
| 1355 |
+
|
| 1356 |
+
rdp_free_logon_info(&logonInfo);
|
| 1357 |
+
break;
|
| 1358 |
+
|
| 1359 |
+
case INFO_TYPE_LOGON_PLAIN_NOTIFY:
|
| 1360 |
+
status = rdp_recv_logon_plain_notify(rdp, s);
|
| 1361 |
+
|
| 1362 |
+
if (status && update->SaveSessionInfo)
|
| 1363 |
+
status = update->SaveSessionInfo(context, infoType, NULL);
|
| 1364 |
+
|
| 1365 |
+
break;
|
| 1366 |
+
|
| 1367 |
+
case INFO_TYPE_LOGON_EXTENDED_INF:
|
| 1368 |
+
status = rdp_recv_logon_info_extended(rdp, s, &logonInfoEx);
|
| 1369 |
+
|
| 1370 |
+
if (status && update->SaveSessionInfo)
|
| 1371 |
+
status = update->SaveSessionInfo(context, infoType, &logonInfoEx);
|
| 1372 |
+
|
| 1373 |
+
break;
|
| 1374 |
+
|
| 1375 |
+
default:
|
| 1376 |
+
WLog_ERR(TAG, "Unhandled saveSessionInfo type 0x%" PRIx32 "", infoType);
|
| 1377 |
+
status = TRUE;
|
| 1378 |
+
break;
|
| 1379 |
+
}
|
| 1380 |
+
|
| 1381 |
+
if (!status)
|
| 1382 |
+
{
|
| 1383 |
+
WLog_DBG(TAG, "SaveSessionInfo error: infoType: %s (%" PRIu32 ")",
|
| 1384 |
+
infoType < 4 ? INFO_TYPE_LOGON_STRINGS[infoType % 4] : "Unknown", infoType);
|
| 1385 |
+
}
|
| 1386 |
+
|
| 1387 |
+
return status;
|
| 1388 |
+
}
|
| 1389 |
+
|
| 1390 |
+
static BOOL rdp_write_logon_info_v1(wStream* s, logon_info* info)
|
| 1391 |
+
{
|
| 1392 |
+
const size_t charLen = 52 / sizeof(WCHAR);
|
| 1393 |
+
const size_t userCharLen = 512 / sizeof(WCHAR);
|
| 1394 |
+
|
| 1395 |
+
size_t sz = 4 + 52 + 4 + 512 + 4;
|
| 1396 |
+
|
| 1397 |
+
if (!Stream_EnsureRemainingCapacity(s, sz))
|
| 1398 |
+
return FALSE;
|
| 1399 |
+
|
| 1400 |
+
/* domain */
|
| 1401 |
+
{
|
| 1402 |
+
WINPR_ASSERT(info);
|
| 1403 |
+
if (!info->domain || !info->username)
|
| 1404 |
+
return FALSE;
|
| 1405 |
+
const size_t len = strnlen(info->domain, charLen + 1);
|
| 1406 |
+
if (len > charLen)
|
| 1407 |
+
return FALSE;
|
| 1408 |
+
|
| 1409 |
+
const size_t wlen = len * sizeof(WCHAR);
|
| 1410 |
+
if (wlen > UINT32_MAX)
|
| 1411 |
+
return FALSE;
|
| 1412 |
+
|
| 1413 |
+
Stream_Write_UINT32(s, (UINT32)wlen);
|
| 1414 |
+
if (Stream_Write_UTF16_String_From_UTF8(s, charLen, info->domain, len, TRUE) < 0)
|
| 1415 |
+
return FALSE;
|
| 1416 |
+
}
|
| 1417 |
+
|
| 1418 |
+
/* username */
|
| 1419 |
+
{
|
| 1420 |
+
const size_t len = strnlen(info->username, userCharLen + 1);
|
| 1421 |
+
if (len > userCharLen)
|
| 1422 |
+
return FALSE;
|
| 1423 |
+
|
| 1424 |
+
const size_t wlen = len * sizeof(WCHAR);
|
| 1425 |
+
if (wlen > UINT32_MAX)
|
| 1426 |
+
return FALSE;
|
| 1427 |
+
|
| 1428 |
+
Stream_Write_UINT32(s, (UINT32)wlen);
|
| 1429 |
+
|
| 1430 |
+
if (Stream_Write_UTF16_String_From_UTF8(s, userCharLen, info->username, len, TRUE) < 0)
|
| 1431 |
+
return FALSE;
|
| 1432 |
+
}
|
| 1433 |
+
|
| 1434 |
+
/* sessionId */
|
| 1435 |
+
Stream_Write_UINT32(s, info->sessionId);
|
| 1436 |
+
return TRUE;
|
| 1437 |
+
}
|
| 1438 |
+
|
| 1439 |
+
static BOOL rdp_write_logon_info_v2(wStream* s, logon_info* info)
|
| 1440 |
+
{
|
| 1441 |
+
size_t domainLen = 0;
|
| 1442 |
+
size_t usernameLen = 0;
|
| 1443 |
+
|
| 1444 |
+
if (!Stream_EnsureRemainingCapacity(s, logonInfoV2TotalSize))
|
| 1445 |
+
return FALSE;
|
| 1446 |
+
|
| 1447 |
+
Stream_Write_UINT16(s, SAVE_SESSION_PDU_VERSION_ONE);
|
| 1448 |
+
/* [MS-RDPBCGR] 2.2.10.1.1.2 Logon Info Version 2 (TS_LOGON_INFO_VERSION_2)
|
| 1449 |
+
* should be logonInfoV2TotalSize
|
| 1450 |
+
* but even MS server 2019 sends logonInfoV2Size
|
| 1451 |
+
*/
|
| 1452 |
+
Stream_Write_UINT32(s, logonInfoV2Size);
|
| 1453 |
+
Stream_Write_UINT32(s, info->sessionId);
|
| 1454 |
+
domainLen = strnlen(info->domain, UINT32_MAX);
|
| 1455 |
+
if (domainLen >= UINT32_MAX / sizeof(WCHAR))
|
| 1456 |
+
return FALSE;
|
| 1457 |
+
Stream_Write_UINT32(s, (UINT32)(domainLen + 1) * sizeof(WCHAR));
|
| 1458 |
+
usernameLen = strnlen(info->username, UINT32_MAX);
|
| 1459 |
+
if (usernameLen >= UINT32_MAX / sizeof(WCHAR))
|
| 1460 |
+
return FALSE;
|
| 1461 |
+
Stream_Write_UINT32(s, (UINT32)(usernameLen + 1) * sizeof(WCHAR));
|
| 1462 |
+
Stream_Seek(s, logonInfoV2ReservedSize);
|
| 1463 |
+
if (Stream_Write_UTF16_String_From_UTF8(s, domainLen + 1, info->domain, domainLen, TRUE) < 0)
|
| 1464 |
+
return FALSE;
|
| 1465 |
+
if (Stream_Write_UTF16_String_From_UTF8(s, usernameLen + 1, info->username, usernameLen, TRUE) <
|
| 1466 |
+
0)
|
| 1467 |
+
return FALSE;
|
| 1468 |
+
return TRUE;
|
| 1469 |
+
}
|
| 1470 |
+
|
| 1471 |
+
static BOOL rdp_write_logon_info_plain(wStream* s)
|
| 1472 |
+
{
|
| 1473 |
+
if (!Stream_EnsureRemainingCapacity(s, 576))
|
| 1474 |
+
return FALSE;
|
| 1475 |
+
|
| 1476 |
+
Stream_Seek(s, 576);
|
| 1477 |
+
return TRUE;
|
| 1478 |
+
}
|
| 1479 |
+
|
| 1480 |
+
static BOOL rdp_write_logon_info_ex(wStream* s, logon_info_ex* info)
|
| 1481 |
+
{
|
| 1482 |
+
UINT32 FieldsPresent = 0;
|
| 1483 |
+
UINT16 Size = 2 + 4 + 570;
|
| 1484 |
+
|
| 1485 |
+
if (info->haveCookie)
|
| 1486 |
+
{
|
| 1487 |
+
FieldsPresent |= LOGON_EX_AUTORECONNECTCOOKIE;
|
| 1488 |
+
Size += 28;
|
| 1489 |
+
}
|
| 1490 |
+
|
| 1491 |
+
if (info->haveErrorInfo)
|
| 1492 |
+
{
|
| 1493 |
+
FieldsPresent |= LOGON_EX_LOGONERRORS;
|
| 1494 |
+
Size += 8;
|
| 1495 |
+
}
|
| 1496 |
+
|
| 1497 |
+
if (!Stream_EnsureRemainingCapacity(s, Size))
|
| 1498 |
+
return FALSE;
|
| 1499 |
+
|
| 1500 |
+
Stream_Write_UINT16(s, Size);
|
| 1501 |
+
Stream_Write_UINT32(s, FieldsPresent);
|
| 1502 |
+
|
| 1503 |
+
if (info->haveCookie)
|
| 1504 |
+
{
|
| 1505 |
+
Stream_Write_UINT32(s, 28); /* cbFieldData (4 bytes) */
|
| 1506 |
+
Stream_Write_UINT32(s, 28); /* cbLen (4 bytes) */
|
| 1507 |
+
Stream_Write_UINT32(s, AUTO_RECONNECT_VERSION_1); /* Version (4 bytes) */
|
| 1508 |
+
Stream_Write_UINT32(s, info->LogonId); /* LogonId (4 bytes) */
|
| 1509 |
+
Stream_Write(s, info->ArcRandomBits, 16); /* ArcRandomBits (16 bytes) */
|
| 1510 |
+
}
|
| 1511 |
+
|
| 1512 |
+
if (info->haveErrorInfo)
|
| 1513 |
+
{
|
| 1514 |
+
Stream_Write_UINT32(s, 8); /* cbFieldData (4 bytes) */
|
| 1515 |
+
Stream_Write_UINT32(s, info->ErrorNotificationType); /* ErrorNotificationType (4 bytes) */
|
| 1516 |
+
Stream_Write_UINT32(s, info->ErrorNotificationData); /* ErrorNotificationData (4 bytes) */
|
| 1517 |
+
}
|
| 1518 |
+
|
| 1519 |
+
Stream_Seek(s, 570);
|
| 1520 |
+
return TRUE;
|
| 1521 |
+
}
|
| 1522 |
+
|
| 1523 |
+
BOOL rdp_send_save_session_info(rdpContext* context, UINT32 type, void* data)
|
| 1524 |
+
{
|
| 1525 |
+
wStream* s = NULL;
|
| 1526 |
+
BOOL status = 0;
|
| 1527 |
+
rdpRdp* rdp = context->rdp;
|
| 1528 |
+
s = rdp_data_pdu_init(rdp);
|
| 1529 |
+
|
| 1530 |
+
if (!s)
|
| 1531 |
+
return FALSE;
|
| 1532 |
+
|
| 1533 |
+
Stream_Write_UINT32(s, type);
|
| 1534 |
+
|
| 1535 |
+
switch (type)
|
| 1536 |
+
{
|
| 1537 |
+
case INFO_TYPE_LOGON:
|
| 1538 |
+
status = rdp_write_logon_info_v1(s, (logon_info*)data);
|
| 1539 |
+
break;
|
| 1540 |
+
|
| 1541 |
+
case INFO_TYPE_LOGON_LONG:
|
| 1542 |
+
status = rdp_write_logon_info_v2(s, (logon_info*)data);
|
| 1543 |
+
break;
|
| 1544 |
+
|
| 1545 |
+
case INFO_TYPE_LOGON_PLAIN_NOTIFY:
|
| 1546 |
+
status = rdp_write_logon_info_plain(s);
|
| 1547 |
+
break;
|
| 1548 |
+
|
| 1549 |
+
case INFO_TYPE_LOGON_EXTENDED_INF:
|
| 1550 |
+
status = rdp_write_logon_info_ex(s, (logon_info_ex*)data);
|
| 1551 |
+
break;
|
| 1552 |
+
|
| 1553 |
+
default:
|
| 1554 |
+
WLog_ERR(TAG, "saveSessionInfo type 0x%" PRIx32 " not handled", type);
|
| 1555 |
+
status = FALSE;
|
| 1556 |
+
break;
|
| 1557 |
+
}
|
| 1558 |
+
|
| 1559 |
+
if (status)
|
| 1560 |
+
status = rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_SAVE_SESSION_INFO, rdp->mcs->userId);
|
| 1561 |
+
else
|
| 1562 |
+
Stream_Release(s);
|
| 1563 |
+
|
| 1564 |
+
return status;
|
| 1565 |
+
}
|
| 1566 |
+
|
| 1567 |
+
BOOL rdp_send_server_status_info(rdpContext* context, UINT32 status)
|
| 1568 |
+
{
|
| 1569 |
+
wStream* s = NULL;
|
| 1570 |
+
rdpRdp* rdp = context->rdp;
|
| 1571 |
+
s = rdp_data_pdu_init(rdp);
|
| 1572 |
+
|
| 1573 |
+
if (!s)
|
| 1574 |
+
return FALSE;
|
| 1575 |
+
|
| 1576 |
+
Stream_Write_UINT32(s, status);
|
| 1577 |
+
return rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_STATUS_INFO, rdp->mcs->userId);
|
| 1578 |
+
}
|
local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/input.h
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* FreeRDP: A Remote Desktop Protocol Implementation
|
| 3 |
+
* Input PDUs
|
| 4 |
+
*
|
| 5 |
+
* Copyright 2011 Marc-Andre Moreau <[email protected]>
|
| 6 |
+
*
|
| 7 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 8 |
+
* you may not use this file except in compliance with the License.
|
| 9 |
+
* You may obtain a copy of the License at
|
| 10 |
+
*
|
| 11 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
+
*
|
| 13 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 14 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 15 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 16 |
+
* See the License for the specific language governing permissions and
|
| 17 |
+
* limitations under the License.
|
| 18 |
+
*/
|
| 19 |
+
|
| 20 |
+
#ifndef FREERDP_LIB_CORE_INPUT_H
|
| 21 |
+
#define FREERDP_LIB_CORE_INPUT_H
|
| 22 |
+
|
| 23 |
+
#include "rdp.h"
|
| 24 |
+
#include "fastpath.h"
|
| 25 |
+
#include "message.h"
|
| 26 |
+
|
| 27 |
+
#include <freerdp/input.h>
|
| 28 |
+
#include <freerdp/freerdp.h>
|
| 29 |
+
#include <freerdp/api.h>
|
| 30 |
+
|
| 31 |
+
#include <winpr/stream.h>
|
| 32 |
+
|
| 33 |
+
typedef struct
|
| 34 |
+
{
|
| 35 |
+
rdpInput common;
|
| 36 |
+
/* Internal */
|
| 37 |
+
|
| 38 |
+
rdpInputProxy* proxy;
|
| 39 |
+
wMessageQueue* queue;
|
| 40 |
+
|
| 41 |
+
UINT64 lastInputTimestamp;
|
| 42 |
+
UINT16 lastX;
|
| 43 |
+
UINT16 lastY;
|
| 44 |
+
} rdp_input_internal;
|
| 45 |
+
|
| 46 |
+
static INLINE rdp_input_internal* input_cast(rdpInput* input)
|
| 47 |
+
{
|
| 48 |
+
union
|
| 49 |
+
{
|
| 50 |
+
rdpInput* pub;
|
| 51 |
+
rdp_input_internal* internal;
|
| 52 |
+
} cnv;
|
| 53 |
+
|
| 54 |
+
WINPR_ASSERT(input);
|
| 55 |
+
cnv.pub = input;
|
| 56 |
+
return cnv.internal;
|
| 57 |
+
}
|
| 58 |
+
FREERDP_LOCAL BOOL input_recv(rdpInput* input, wStream* s);
|
| 59 |
+
|
| 60 |
+
FREERDP_LOCAL int input_process_events(rdpInput* input);
|
| 61 |
+
FREERDP_LOCAL BOOL input_register_client_callbacks(rdpInput* input);
|
| 62 |
+
|
| 63 |
+
FREERDP_LOCAL void input_free(rdpInput* input);
|
| 64 |
+
|
| 65 |
+
WINPR_ATTR_MALLOC(input_free, 1)
|
| 66 |
+
FREERDP_LOCAL rdpInput* input_new(rdpRdp* rdp);
|
| 67 |
+
|
| 68 |
+
#endif /* FREERDP_LIB_CORE_INPUT_H */
|
local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/nla.h
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* FreeRDP: A Remote Desktop Protocol Implementation
|
| 3 |
+
* Network Level Authentication (NLA)
|
| 4 |
+
*
|
| 5 |
+
* Copyright 2010-2012 Marc-Andre Moreau <[email protected]>
|
| 6 |
+
*
|
| 7 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 8 |
+
* you may not use this file except in compliance with the License.
|
| 9 |
+
* You may obtain a copy of the License at
|
| 10 |
+
*
|
| 11 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
+
*
|
| 13 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 14 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 15 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 16 |
+
* See the License for the specific language governing permissions and
|
| 17 |
+
* limitations under the License.
|
| 18 |
+
*/
|
| 19 |
+
|
| 20 |
+
#ifndef FREERDP_LIB_CORE_NLA_H
|
| 21 |
+
#define FREERDP_LIB_CORE_NLA_H
|
| 22 |
+
|
| 23 |
+
typedef struct rdp_nla rdpNla;
|
| 24 |
+
|
| 25 |
+
#include <freerdp/api.h>
|
| 26 |
+
#include <freerdp/freerdp.h>
|
| 27 |
+
|
| 28 |
+
#include <winpr/sspi.h>
|
| 29 |
+
#include <winpr/stream.h>
|
| 30 |
+
#include <winpr/crypto.h>
|
| 31 |
+
|
| 32 |
+
#include <freerdp/crypto/ber.h>
|
| 33 |
+
#include <freerdp/crypto/der.h>
|
| 34 |
+
#include <freerdp/crypto/crypto.h>
|
| 35 |
+
|
| 36 |
+
#include "transport.h"
|
| 37 |
+
|
| 38 |
+
typedef enum
|
| 39 |
+
{
|
| 40 |
+
NLA_STATE_INITIAL,
|
| 41 |
+
NLA_STATE_NEGO_TOKEN,
|
| 42 |
+
NLA_STATE_PUB_KEY_AUTH,
|
| 43 |
+
NLA_STATE_EARLY_USER_AUTH,
|
| 44 |
+
NLA_STATE_AUTH_INFO,
|
| 45 |
+
NLA_STATE_POST_NEGO,
|
| 46 |
+
NLA_STATE_FINAL
|
| 47 |
+
} NLA_STATE;
|
| 48 |
+
|
| 49 |
+
FREERDP_LOCAL int nla_authenticate(rdpNla* nla);
|
| 50 |
+
|
| 51 |
+
FREERDP_LOCAL int nla_client_begin(rdpNla* nla);
|
| 52 |
+
FREERDP_LOCAL int nla_recv_pdu(rdpNla* nla, wStream* s);
|
| 53 |
+
|
| 54 |
+
FREERDP_LOCAL SEC_WINNT_AUTH_IDENTITY* nla_get_identity(rdpNla* nla);
|
| 55 |
+
|
| 56 |
+
FREERDP_LOCAL NLA_STATE nla_get_state(rdpNla* nla);
|
| 57 |
+
FREERDP_LOCAL BOOL nla_set_state(rdpNla* nla, NLA_STATE state);
|
| 58 |
+
FREERDP_LOCAL const char* nla_get_state_str(NLA_STATE state);
|
| 59 |
+
|
| 60 |
+
FREERDP_LOCAL DWORD nla_get_error(rdpNla* nla);
|
| 61 |
+
FREERDP_LOCAL INT32 nla_get_sspi_error(rdpNla* nla);
|
| 62 |
+
|
| 63 |
+
FREERDP_LOCAL BOOL nla_set_service_principal(rdpNla* nla, const char* service,
|
| 64 |
+
const char* hostname);
|
| 65 |
+
|
| 66 |
+
FREERDP_LOCAL BOOL nla_set_sspi_module(rdpNla* nla, const char* sspiModule);
|
| 67 |
+
FREERDP_LOCAL BOOL nla_sspi_module_init(rdpNla* nla);
|
| 68 |
+
|
| 69 |
+
FREERDP_LOCAL BOOL nla_impersonate(rdpNla* nla);
|
| 70 |
+
FREERDP_LOCAL BOOL nla_revert_to_self(rdpNla* nla);
|
| 71 |
+
|
| 72 |
+
FREERDP_LOCAL void nla_free(rdpNla* nla);
|
| 73 |
+
|
| 74 |
+
WINPR_ATTR_MALLOC(nla_free, 1)
|
| 75 |
+
FREERDP_LOCAL rdpNla* nla_new(rdpContext* context, rdpTransport* transport);
|
| 76 |
+
|
| 77 |
+
FREERDP_LOCAL void nla_set_early_user_auth(rdpNla* nla, BOOL earlyUserAuth);
|
| 78 |
+
FREERDP_LOCAL BOOL nla_encrypt(rdpNla* nla, const SecBuffer* inBuffer, SecBuffer* outBuffer);
|
| 79 |
+
FREERDP_LOCAL BOOL nla_decrypt(rdpNla* nla, const SecBuffer* inBuffer, SecBuffer* outBuffer);
|
| 80 |
+
FREERDP_LOCAL SECURITY_STATUS nla_QueryContextAttributes(rdpNla* nla, DWORD ulAttr, PVOID pBuffer);
|
| 81 |
+
|
| 82 |
+
#endif /* FREERDP_LIB_CORE_NLA_H */
|
local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/peer.h
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* FreeRDP: A Remote Desktop Protocol Implementation
|
| 3 |
+
* RDP Server Peer
|
| 4 |
+
*
|
| 5 |
+
* Copyright 2011 Vic Lee
|
| 6 |
+
*
|
| 7 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 8 |
+
* you may not use this file except in compliance with the License.
|
| 9 |
+
* You may obtain a copy of the License at
|
| 10 |
+
*
|
| 11 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
+
*
|
| 13 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 14 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 15 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 16 |
+
* See the License for the specific language governing permissions and
|
| 17 |
+
* limitations under the License.
|
| 18 |
+
*/
|
| 19 |
+
|
| 20 |
+
#ifndef FREERDP_LIB_CORE_PEER_H
|
| 21 |
+
#define FREERDP_LIB_CORE_PEER_H
|
| 22 |
+
|
| 23 |
+
#include "rdp.h"
|
| 24 |
+
#include "mcs.h"
|
| 25 |
+
#include "server.h"
|
| 26 |
+
|
| 27 |
+
#include <freerdp/peer.h>
|
| 28 |
+
|
| 29 |
+
FREERDP_LOCAL state_run_t rdp_peer_handle_state_demand_active(freerdp_peer* client);
|
| 30 |
+
|
| 31 |
+
#endif /* FREERDP_LIB_CORE_PEER_H */
|
local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/rdp.h
ADDED
|
@@ -0,0 +1,305 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* FreeRDP: A Remote Desktop Protocol Implementation
|
| 3 |
+
* RDP Core
|
| 4 |
+
*
|
| 5 |
+
* Copyright 2011 Marc-Andre Moreau <[email protected]>
|
| 6 |
+
* Copyright 2014 DI (FH) Martin Haimberger <[email protected]>
|
| 7 |
+
*
|
| 8 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 9 |
+
* you may not use this file except in compliance with the License.
|
| 10 |
+
* You may obtain a copy of the License at
|
| 11 |
+
*
|
| 12 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 13 |
+
*
|
| 14 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 15 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 16 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 17 |
+
* See the License for the specific language governing permissions and
|
| 18 |
+
* limitations under the License.
|
| 19 |
+
*/
|
| 20 |
+
|
| 21 |
+
#ifndef FREERDP_LIB_CORE_RDP_H
|
| 22 |
+
#define FREERDP_LIB_CORE_RDP_H
|
| 23 |
+
|
| 24 |
+
#include <winpr/json.h>
|
| 25 |
+
#include <freerdp/config.h>
|
| 26 |
+
|
| 27 |
+
#include "nla.h"
|
| 28 |
+
#include "aad.h"
|
| 29 |
+
#include "mcs.h"
|
| 30 |
+
#include "tpkt.h"
|
| 31 |
+
#include "../codec/bulk.h"
|
| 32 |
+
#include "fastpath.h"
|
| 33 |
+
#include "tpdu.h"
|
| 34 |
+
#include "nego.h"
|
| 35 |
+
#include "input.h"
|
| 36 |
+
#include "update.h"
|
| 37 |
+
#include "license.h"
|
| 38 |
+
#include "errinfo.h"
|
| 39 |
+
#include "autodetect.h"
|
| 40 |
+
#include "heartbeat.h"
|
| 41 |
+
#include "multitransport.h"
|
| 42 |
+
#include "security.h"
|
| 43 |
+
#include "transport.h"
|
| 44 |
+
#include "connection.h"
|
| 45 |
+
#include "redirection.h"
|
| 46 |
+
#include "capabilities.h"
|
| 47 |
+
#include "channels.h"
|
| 48 |
+
|
| 49 |
+
#include <freerdp/freerdp.h>
|
| 50 |
+
#include <freerdp/settings.h>
|
| 51 |
+
#include <freerdp/log.h>
|
| 52 |
+
#include <freerdp/api.h>
|
| 53 |
+
|
| 54 |
+
#include <winpr/stream.h>
|
| 55 |
+
#include <winpr/crypto.h>
|
| 56 |
+
|
| 57 |
+
/* Security Header Flags */
|
| 58 |
+
#define SEC_EXCHANGE_PKT 0x0001
|
| 59 |
+
#define SEC_TRANSPORT_REQ 0x0002
|
| 60 |
+
#define SEC_TRANSPORT_RSP 0x0004
|
| 61 |
+
#define SEC_ENCRYPT 0x0008
|
| 62 |
+
#define SEC_RESET_SEQNO 0x0010
|
| 63 |
+
#define SEC_IGNORE_SEQNO 0x0020
|
| 64 |
+
#define SEC_INFO_PKT 0x0040
|
| 65 |
+
#define SEC_LICENSE_PKT 0x0080
|
| 66 |
+
#define SEC_LICENSE_ENCRYPT_CS 0x0200
|
| 67 |
+
#define SEC_LICENSE_ENCRYPT_SC 0x0200
|
| 68 |
+
#define SEC_REDIRECTION_PKT 0x0400
|
| 69 |
+
#define SEC_SECURE_CHECKSUM 0x0800
|
| 70 |
+
#define SEC_AUTODETECT_REQ 0x1000
|
| 71 |
+
#define SEC_AUTODETECT_RSP 0x2000
|
| 72 |
+
#define SEC_HEARTBEAT 0x4000
|
| 73 |
+
#define SEC_FLAGSHI_VALID 0x8000
|
| 74 |
+
|
| 75 |
+
#define SEC_PKT_CS_MASK (SEC_EXCHANGE_PKT | SEC_INFO_PKT)
|
| 76 |
+
#define SEC_PKT_SC_MASK (SEC_LICENSE_PKT | SEC_REDIRECTION_PKT)
|
| 77 |
+
#define SEC_PKT_MASK (SEC_PKT_CS_MASK | SEC_PKT_SC_MASK)
|
| 78 |
+
|
| 79 |
+
#define RDP_SECURITY_HEADER_LENGTH 4
|
| 80 |
+
#define RDP_SHARE_CONTROL_HEADER_LENGTH 6
|
| 81 |
+
#define RDP_SHARE_DATA_HEADER_LENGTH 12
|
| 82 |
+
#define RDP_PACKET_HEADER_MAX_LENGTH (TPDU_DATA_LENGTH + MCS_SEND_DATA_HEADER_MAX_LENGTH)
|
| 83 |
+
|
| 84 |
+
#define PDU_TYPE_DEMAND_ACTIVE 0x1
|
| 85 |
+
#define PDU_TYPE_CONFIRM_ACTIVE 0x3
|
| 86 |
+
#define PDU_TYPE_DEACTIVATE_ALL 0x6
|
| 87 |
+
#define PDU_TYPE_DATA 0x7
|
| 88 |
+
#define PDU_TYPE_SERVER_REDIRECTION 0xA
|
| 89 |
+
|
| 90 |
+
#define PDU_TYPE_FLOW_TEST 0x41
|
| 91 |
+
#define PDU_TYPE_FLOW_RESPONSE 0x42
|
| 92 |
+
#define PDU_TYPE_FLOW_STOP 0x43
|
| 93 |
+
|
| 94 |
+
typedef enum
|
| 95 |
+
{
|
| 96 |
+
FINALIZE_SC_SYNCHRONIZE_PDU = 0x01,
|
| 97 |
+
FINALIZE_SC_CONTROL_COOPERATE_PDU = 0x02,
|
| 98 |
+
FINALIZE_SC_CONTROL_GRANTED_PDU = 0x04,
|
| 99 |
+
FINALIZE_SC_FONT_MAP_PDU = 0x08,
|
| 100 |
+
|
| 101 |
+
FINALIZE_CS_SYNCHRONIZE_PDU = 0x10,
|
| 102 |
+
FINALIZE_CS_CONTROL_COOPERATE_PDU = 0x20,
|
| 103 |
+
FINALIZE_CS_CONTROL_REQUEST_PDU = 0x40,
|
| 104 |
+
FINALIZE_CS_PERSISTENT_KEY_LIST_PDU = 0x80,
|
| 105 |
+
FINALIZE_CS_FONT_LIST_PDU = 0x100,
|
| 106 |
+
|
| 107 |
+
FINALIZE_DEACTIVATE_REACTIVATE = 0x200
|
| 108 |
+
} rdpFinalizePduType;
|
| 109 |
+
|
| 110 |
+
/* Data PDU Types */
|
| 111 |
+
typedef enum
|
| 112 |
+
{
|
| 113 |
+
DATA_PDU_TYPE_UPDATE = 0x02,
|
| 114 |
+
DATA_PDU_TYPE_CONTROL = 0x14,
|
| 115 |
+
DATA_PDU_TYPE_POINTER = 0x1B,
|
| 116 |
+
DATA_PDU_TYPE_INPUT = 0x1C,
|
| 117 |
+
DATA_PDU_TYPE_SYNCHRONIZE = 0x1F,
|
| 118 |
+
DATA_PDU_TYPE_REFRESH_RECT = 0x21,
|
| 119 |
+
DATA_PDU_TYPE_PLAY_SOUND = 0x22,
|
| 120 |
+
DATA_PDU_TYPE_SUPPRESS_OUTPUT = 0x23,
|
| 121 |
+
DATA_PDU_TYPE_SHUTDOWN_REQUEST = 0x24,
|
| 122 |
+
DATA_PDU_TYPE_SHUTDOWN_DENIED = 0x25,
|
| 123 |
+
DATA_PDU_TYPE_SAVE_SESSION_INFO = 0x26,
|
| 124 |
+
DATA_PDU_TYPE_FONT_LIST = 0x27,
|
| 125 |
+
DATA_PDU_TYPE_FONT_MAP = 0x28,
|
| 126 |
+
DATA_PDU_TYPE_SET_KEYBOARD_INDICATORS = 0x29,
|
| 127 |
+
DATA_PDU_TYPE_BITMAP_CACHE_PERSISTENT_LIST = 0x2B,
|
| 128 |
+
DATA_PDU_TYPE_BITMAP_CACHE_ERROR = 0x2C,
|
| 129 |
+
DATA_PDU_TYPE_SET_KEYBOARD_IME_STATUS = 0x2D,
|
| 130 |
+
DATA_PDU_TYPE_OFFSCREEN_CACHE_ERROR = 0x2E,
|
| 131 |
+
DATA_PDU_TYPE_SET_ERROR_INFO = 0x2F,
|
| 132 |
+
DATA_PDU_TYPE_DRAW_NINEGRID_ERROR = 0x30,
|
| 133 |
+
DATA_PDU_TYPE_DRAW_GDIPLUS_ERROR = 0x31,
|
| 134 |
+
DATA_PDU_TYPE_ARC_STATUS = 0x32,
|
| 135 |
+
DATA_PDU_TYPE_STATUS_INFO = 0x36,
|
| 136 |
+
DATA_PDU_TYPE_MONITOR_LAYOUT = 0x37,
|
| 137 |
+
DATA_PDU_TYPE_FRAME_ACKNOWLEDGE = 0x38
|
| 138 |
+
} rdpPduType;
|
| 139 |
+
|
| 140 |
+
/* Stream Identifiers */
|
| 141 |
+
#define STREAM_UNDEFINED 0x00
|
| 142 |
+
#define STREAM_LOW 0x01
|
| 143 |
+
#define STREAM_MED 0x02
|
| 144 |
+
#define STREAM_HI 0x04
|
| 145 |
+
|
| 146 |
+
struct rdp_rdp
|
| 147 |
+
{
|
| 148 |
+
CONNECTION_STATE state;
|
| 149 |
+
rdpContext* context;
|
| 150 |
+
rdpNla* nla;
|
| 151 |
+
rdpAad* aad;
|
| 152 |
+
rdpMcs* mcs;
|
| 153 |
+
rdpNego* nego;
|
| 154 |
+
rdpBulk* bulk;
|
| 155 |
+
rdpInput* input;
|
| 156 |
+
rdpUpdate* update;
|
| 157 |
+
rdpFastPath* fastpath;
|
| 158 |
+
rdpLicense* license;
|
| 159 |
+
rdpRedirection* redirection;
|
| 160 |
+
rdpSettings* settings;
|
| 161 |
+
rdpSettings* originalSettings;
|
| 162 |
+
rdpSettings* remoteSettings;
|
| 163 |
+
rdpTransport* transport;
|
| 164 |
+
rdpAutoDetect* autodetect;
|
| 165 |
+
rdpHeartbeat* heartbeat;
|
| 166 |
+
rdpMultitransport* multitransport;
|
| 167 |
+
WINPR_RC4_CTX* rc4_decrypt_key;
|
| 168 |
+
UINT32 decrypt_use_count;
|
| 169 |
+
UINT32 decrypt_checksum_use_count;
|
| 170 |
+
WINPR_RC4_CTX* rc4_encrypt_key;
|
| 171 |
+
UINT32 encrypt_use_count;
|
| 172 |
+
UINT32 encrypt_checksum_use_count;
|
| 173 |
+
WINPR_CIPHER_CTX* fips_encrypt;
|
| 174 |
+
WINPR_CIPHER_CTX* fips_decrypt;
|
| 175 |
+
UINT32 sec_flags;
|
| 176 |
+
BOOL do_crypt;
|
| 177 |
+
BOOL do_crypt_license;
|
| 178 |
+
BOOL do_secure_checksum;
|
| 179 |
+
BYTE sign_key[16];
|
| 180 |
+
BYTE decrypt_key[16];
|
| 181 |
+
BYTE encrypt_key[16];
|
| 182 |
+
BYTE decrypt_update_key[16];
|
| 183 |
+
BYTE encrypt_update_key[16];
|
| 184 |
+
size_t rc4_key_len;
|
| 185 |
+
BYTE fips_sign_key[20];
|
| 186 |
+
BYTE fips_encrypt_key[24];
|
| 187 |
+
BYTE fips_decrypt_key[24];
|
| 188 |
+
UINT32 errorInfo;
|
| 189 |
+
UINT32 finalize_sc_pdus;
|
| 190 |
+
BOOL resendFocus;
|
| 191 |
+
|
| 192 |
+
UINT64 inBytes;
|
| 193 |
+
UINT64 inPackets;
|
| 194 |
+
UINT64 outBytes;
|
| 195 |
+
UINT64 outPackets;
|
| 196 |
+
CRITICAL_SECTION critical;
|
| 197 |
+
rdpTransportIo* io;
|
| 198 |
+
void* ioContext;
|
| 199 |
+
HANDLE abortEvent;
|
| 200 |
+
|
| 201 |
+
wPubSub* pubSub;
|
| 202 |
+
|
| 203 |
+
BOOL monitor_layout_pdu;
|
| 204 |
+
BOOL was_deactivated;
|
| 205 |
+
UINT32 deactivated_width;
|
| 206 |
+
UINT32 deactivated_height;
|
| 207 |
+
|
| 208 |
+
wLog* log;
|
| 209 |
+
char log_context[64];
|
| 210 |
+
WINPR_JSON* wellknown;
|
| 211 |
+
};
|
| 212 |
+
|
| 213 |
+
FREERDP_LOCAL BOOL rdp_read_security_header(rdpRdp* rdp, wStream* s, UINT16* flags, UINT16* length);
|
| 214 |
+
FREERDP_LOCAL BOOL rdp_write_security_header(rdpRdp* rdp, wStream* s, UINT16 flags);
|
| 215 |
+
|
| 216 |
+
FREERDP_LOCAL BOOL rdp_read_share_control_header(rdpRdp* rdp, wStream* s, UINT16* tpktLength,
|
| 217 |
+
UINT16* remainingLength, UINT16* type,
|
| 218 |
+
UINT16* channel_id);
|
| 219 |
+
|
| 220 |
+
FREERDP_LOCAL BOOL rdp_read_share_data_header(rdpRdp* rdp, wStream* s, UINT16* length, BYTE* type,
|
| 221 |
+
UINT32* share_id, BYTE* compressed_type,
|
| 222 |
+
UINT16* compressed_len);
|
| 223 |
+
|
| 224 |
+
FREERDP_LOCAL wStream* rdp_send_stream_init(rdpRdp* rdp);
|
| 225 |
+
FREERDP_LOCAL wStream* rdp_send_stream_pdu_init(rdpRdp* rdp);
|
| 226 |
+
|
| 227 |
+
FREERDP_LOCAL BOOL rdp_read_header(rdpRdp* rdp, wStream* s, UINT16* length, UINT16* channel_id);
|
| 228 |
+
FREERDP_LOCAL BOOL rdp_write_header(rdpRdp* rdp, wStream* s, size_t length, UINT16 channel_id);
|
| 229 |
+
|
| 230 |
+
FREERDP_LOCAL BOOL rdp_send_pdu(rdpRdp* rdp, wStream* s, UINT16 type, UINT16 channel_id);
|
| 231 |
+
|
| 232 |
+
FREERDP_LOCAL wStream* rdp_data_pdu_init(rdpRdp* rdp);
|
| 233 |
+
FREERDP_LOCAL BOOL rdp_send_data_pdu(rdpRdp* rdp, wStream* s, BYTE type, UINT16 channel_id);
|
| 234 |
+
FREERDP_LOCAL state_run_t rdp_recv_data_pdu(rdpRdp* rdp, wStream* s);
|
| 235 |
+
|
| 236 |
+
FREERDP_LOCAL BOOL rdp_send(rdpRdp* rdp, wStream* s, UINT16 channelId);
|
| 237 |
+
|
| 238 |
+
FREERDP_LOCAL BOOL rdp_send_channel_data(rdpRdp* rdp, UINT16 channelId, const BYTE* data,
|
| 239 |
+
size_t size);
|
| 240 |
+
FREERDP_LOCAL BOOL rdp_channel_send_packet(rdpRdp* rdp, UINT16 channelId, size_t totalSize,
|
| 241 |
+
UINT32 flags, const BYTE* data, size_t chunkSize);
|
| 242 |
+
|
| 243 |
+
FREERDP_LOCAL wStream* rdp_message_channel_pdu_init(rdpRdp* rdp);
|
| 244 |
+
FREERDP_LOCAL BOOL rdp_send_message_channel_pdu(rdpRdp* rdp, wStream* s, UINT16 sec_flags);
|
| 245 |
+
FREERDP_LOCAL state_run_t rdp_recv_message_channel_pdu(rdpRdp* rdp, wStream* s,
|
| 246 |
+
UINT16 securityFlags);
|
| 247 |
+
|
| 248 |
+
FREERDP_LOCAL state_run_t rdp_recv_out_of_sequence_pdu(rdpRdp* rdp, wStream* s, UINT16 pduType,
|
| 249 |
+
UINT16 length);
|
| 250 |
+
|
| 251 |
+
FREERDP_LOCAL state_run_t rdp_recv_callback(rdpTransport* transport, wStream* s, void* extra);
|
| 252 |
+
|
| 253 |
+
FREERDP_LOCAL int rdp_check_fds(rdpRdp* rdp);
|
| 254 |
+
|
| 255 |
+
FREERDP_LOCAL void rdp_free(rdpRdp* rdp);
|
| 256 |
+
|
| 257 |
+
WINPR_ATTR_MALLOC(rdp_free, 1)
|
| 258 |
+
FREERDP_LOCAL rdpRdp* rdp_new(rdpContext* context);
|
| 259 |
+
FREERDP_LOCAL BOOL rdp_reset(rdpRdp* rdp);
|
| 260 |
+
|
| 261 |
+
FREERDP_LOCAL BOOL rdp_io_callback_set_event(rdpRdp* rdp, BOOL reset);
|
| 262 |
+
|
| 263 |
+
FREERDP_LOCAL const rdpTransportIo* rdp_get_io_callbacks(rdpRdp* rdp);
|
| 264 |
+
FREERDP_LOCAL BOOL rdp_set_io_callbacks(rdpRdp* rdp, const rdpTransportIo* io_callbacks);
|
| 265 |
+
|
| 266 |
+
FREERDP_LOCAL BOOL rdp_set_io_callback_context(rdpRdp* rdp, void* usercontext);
|
| 267 |
+
FREERDP_LOCAL void* rdp_get_io_callback_context(rdpRdp* rdp);
|
| 268 |
+
|
| 269 |
+
#define RDP_TAG FREERDP_TAG("core.rdp")
|
| 270 |
+
#ifdef WITH_DEBUG_RDP
|
| 271 |
+
#define DEBUG_RDP(rdp, ...) WLog_Print(rdp->log, WLOG_DEBUG, __VA_ARGS__)
|
| 272 |
+
#else
|
| 273 |
+
#define DEBUG_RDP(rdp, ...) \
|
| 274 |
+
do \
|
| 275 |
+
{ \
|
| 276 |
+
} while (0)
|
| 277 |
+
#endif
|
| 278 |
+
|
| 279 |
+
const char* data_pdu_type_to_string(UINT8 type);
|
| 280 |
+
const char* pdu_type_to_str(UINT16 pduType, char* buffer, size_t length);
|
| 281 |
+
|
| 282 |
+
BOOL rdp_finalize_reset_flags(rdpRdp* rdp, BOOL clearAll);
|
| 283 |
+
BOOL rdp_finalize_set_flag(rdpRdp* rdp, UINT32 flag);
|
| 284 |
+
BOOL rdp_finalize_is_flag_set(rdpRdp* rdp, UINT32 flag);
|
| 285 |
+
const char* rdp_finalize_flags_to_str(UINT32 flags, char* buffer, size_t size);
|
| 286 |
+
|
| 287 |
+
BOOL rdp_decrypt(rdpRdp* rdp, wStream* s, UINT16* pLength, UINT16 securityFlags);
|
| 288 |
+
|
| 289 |
+
BOOL rdp_set_error_info(rdpRdp* rdp, UINT32 errorInfo);
|
| 290 |
+
BOOL rdp_send_error_info(rdpRdp* rdp);
|
| 291 |
+
|
| 292 |
+
void rdp_free_rc4_encrypt_keys(rdpRdp* rdp);
|
| 293 |
+
BOOL rdp_reset_rc4_encrypt_keys(rdpRdp* rdp);
|
| 294 |
+
|
| 295 |
+
void rdp_free_rc4_decrypt_keys(rdpRdp* rdp);
|
| 296 |
+
BOOL rdp_reset_rc4_decrypt_keys(rdpRdp* rdp);
|
| 297 |
+
|
| 298 |
+
const char* rdp_security_flag_string(UINT32 securityFlags, char* buffer, size_t size);
|
| 299 |
+
|
| 300 |
+
BOOL rdp_set_backup_settings(rdpRdp* rdp);
|
| 301 |
+
BOOL rdp_reset_runtime_settings(rdpRdp* rdp);
|
| 302 |
+
|
| 303 |
+
void rdp_log_build_warnings(rdpRdp* rdp);
|
| 304 |
+
|
| 305 |
+
#endif /* FREERDP_LIB_CORE_RDP_H */
|
local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/server.c
ADDED
|
@@ -0,0 +1,1974 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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2015 DI (FH) Martin Haimberger <[email protected]>
|
| 8 |
+
*
|
| 9 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 10 |
+
* you may not use this file except in compliance with the License.
|
| 11 |
+
* You may obtain a copy of the License at
|
| 12 |
+
*
|
| 13 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 14 |
+
*
|
| 15 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 16 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 17 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 18 |
+
* See the License for the specific language governing permissions and
|
| 19 |
+
* limitations under the License.
|
| 20 |
+
*/
|
| 21 |
+
|
| 22 |
+
#include <freerdp/config.h>
|
| 23 |
+
|
| 24 |
+
#include <stdio.h>
|
| 25 |
+
#include <stdlib.h>
|
| 26 |
+
#include <string.h>
|
| 27 |
+
#include <stdint.h>
|
| 28 |
+
|
| 29 |
+
#include <winpr/wtypes.h>
|
| 30 |
+
#include <winpr/crt.h>
|
| 31 |
+
#include <winpr/synch.h>
|
| 32 |
+
#include <winpr/stream.h>
|
| 33 |
+
#include <winpr/assert.h>
|
| 34 |
+
#include <winpr/cast.h>
|
| 35 |
+
|
| 36 |
+
#include <freerdp/log.h>
|
| 37 |
+
#include <freerdp/constants.h>
|
| 38 |
+
#include <freerdp/server/channels.h>
|
| 39 |
+
#include <freerdp/channels/drdynvc.h>
|
| 40 |
+
#include <freerdp/utils/drdynvc.h>
|
| 41 |
+
|
| 42 |
+
#include "rdp.h"
|
| 43 |
+
|
| 44 |
+
#include "server.h"
|
| 45 |
+
|
| 46 |
+
#define TAG FREERDP_TAG("core.server")
|
| 47 |
+
#ifdef WITH_DEBUG_DVC
|
| 48 |
+
#define DEBUG_DVC(...) WLog_DBG(TAG, __VA_ARGS__)
|
| 49 |
+
#else
|
| 50 |
+
#define DEBUG_DVC(...) \
|
| 51 |
+
do \
|
| 52 |
+
{ \
|
| 53 |
+
} while (0)
|
| 54 |
+
#endif
|
| 55 |
+
|
| 56 |
+
#define DVC_MAX_DATA_PDU_SIZE 1600
|
| 57 |
+
|
| 58 |
+
typedef struct
|
| 59 |
+
{
|
| 60 |
+
UINT16 channelId;
|
| 61 |
+
UINT16 reserved;
|
| 62 |
+
UINT32 length;
|
| 63 |
+
UINT32 offset;
|
| 64 |
+
} wtsChannelMessage;
|
| 65 |
+
|
| 66 |
+
static DWORD g_SessionId = 1;
|
| 67 |
+
static wHashTable* g_ServerHandles = NULL;
|
| 68 |
+
|
| 69 |
+
static rdpPeerChannel* wts_get_dvc_channel_by_id(WTSVirtualChannelManager* vcm, UINT32 ChannelId)
|
| 70 |
+
{
|
| 71 |
+
WINPR_ASSERT(vcm);
|
| 72 |
+
return HashTable_GetItemValue(vcm->dynamicVirtualChannels, &ChannelId);
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
static BOOL wts_queue_receive_data(rdpPeerChannel* channel, const BYTE* Buffer, UINT32 Length)
|
| 76 |
+
{
|
| 77 |
+
BYTE* buffer = NULL;
|
| 78 |
+
wtsChannelMessage* messageCtx = NULL;
|
| 79 |
+
|
| 80 |
+
WINPR_ASSERT(channel);
|
| 81 |
+
messageCtx = (wtsChannelMessage*)malloc(sizeof(wtsChannelMessage) + Length);
|
| 82 |
+
|
| 83 |
+
if (!messageCtx)
|
| 84 |
+
return FALSE;
|
| 85 |
+
|
| 86 |
+
WINPR_ASSERT(channel->channelId <= UINT16_MAX);
|
| 87 |
+
messageCtx->channelId = (UINT16)channel->channelId;
|
| 88 |
+
messageCtx->length = Length;
|
| 89 |
+
messageCtx->offset = 0;
|
| 90 |
+
buffer = (BYTE*)(messageCtx + 1);
|
| 91 |
+
CopyMemory(buffer, Buffer, Length);
|
| 92 |
+
return MessageQueue_Post(channel->queue, messageCtx, 0, NULL, NULL);
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
static BOOL wts_queue_send_item(rdpPeerChannel* channel, BYTE* Buffer, UINT32 Length)
|
| 96 |
+
{
|
| 97 |
+
BYTE* buffer = NULL;
|
| 98 |
+
UINT32 length = 0;
|
| 99 |
+
|
| 100 |
+
WINPR_ASSERT(channel);
|
| 101 |
+
WINPR_ASSERT(channel->vcm);
|
| 102 |
+
buffer = Buffer;
|
| 103 |
+
length = Length;
|
| 104 |
+
|
| 105 |
+
WINPR_ASSERT(channel->channelId <= UINT16_MAX);
|
| 106 |
+
const UINT16 channelId = (UINT16)channel->channelId;
|
| 107 |
+
return MessageQueue_Post(channel->vcm->queue, (void*)(UINT_PTR)channelId, 0, (void*)buffer,
|
| 108 |
+
(void*)(UINT_PTR)length);
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
static unsigned wts_read_variable_uint(wStream* s, int cbLen, UINT32* val)
|
| 112 |
+
{
|
| 113 |
+
WINPR_ASSERT(s);
|
| 114 |
+
WINPR_ASSERT(val);
|
| 115 |
+
switch (cbLen)
|
| 116 |
+
{
|
| 117 |
+
case 0:
|
| 118 |
+
if (!Stream_CheckAndLogRequiredLength(TAG, s, 1))
|
| 119 |
+
return 0;
|
| 120 |
+
|
| 121 |
+
Stream_Read_UINT8(s, *val);
|
| 122 |
+
return 1;
|
| 123 |
+
|
| 124 |
+
case 1:
|
| 125 |
+
if (!Stream_CheckAndLogRequiredLength(TAG, s, 2))
|
| 126 |
+
return 0;
|
| 127 |
+
|
| 128 |
+
Stream_Read_UINT16(s, *val);
|
| 129 |
+
return 2;
|
| 130 |
+
|
| 131 |
+
case 2:
|
| 132 |
+
if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
|
| 133 |
+
return 0;
|
| 134 |
+
|
| 135 |
+
Stream_Read_UINT32(s, *val);
|
| 136 |
+
return 4;
|
| 137 |
+
|
| 138 |
+
default:
|
| 139 |
+
WLog_ERR(TAG, "invalid wts variable uint len %d", cbLen);
|
| 140 |
+
return 0;
|
| 141 |
+
}
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
static BOOL wts_read_drdynvc_capabilities_response(rdpPeerChannel* channel, UINT32 length)
|
| 145 |
+
{
|
| 146 |
+
UINT16 Version = 0;
|
| 147 |
+
|
| 148 |
+
WINPR_ASSERT(channel);
|
| 149 |
+
WINPR_ASSERT(channel->vcm);
|
| 150 |
+
if (length < 3)
|
| 151 |
+
return FALSE;
|
| 152 |
+
|
| 153 |
+
Stream_Seek_UINT8(channel->receiveData); /* Pad (1 byte) */
|
| 154 |
+
Stream_Read_UINT16(channel->receiveData, Version);
|
| 155 |
+
DEBUG_DVC("Version: %" PRIu16 "", Version);
|
| 156 |
+
|
| 157 |
+
if (Version < 1)
|
| 158 |
+
{
|
| 159 |
+
WLog_ERR(TAG, "invalid version %" PRIu16 " for DRDYNVC", Version);
|
| 160 |
+
return FALSE;
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
WTSVirtualChannelManager* vcm = channel->vcm;
|
| 164 |
+
vcm->drdynvc_state = DRDYNVC_STATE_READY;
|
| 165 |
+
|
| 166 |
+
/* we only support version 1 for now (no compression yet) */
|
| 167 |
+
vcm->dvc_spoken_version = MAX(Version, 1);
|
| 168 |
+
|
| 169 |
+
return SetEvent(MessageQueue_Event(vcm->queue));
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
static BOOL wts_read_drdynvc_create_response(rdpPeerChannel* channel, wStream* s, UINT32 length)
|
| 173 |
+
{
|
| 174 |
+
UINT32 CreationStatus = 0;
|
| 175 |
+
BOOL status = TRUE;
|
| 176 |
+
|
| 177 |
+
WINPR_ASSERT(channel);
|
| 178 |
+
WINPR_ASSERT(s);
|
| 179 |
+
if (length < 4)
|
| 180 |
+
return FALSE;
|
| 181 |
+
|
| 182 |
+
Stream_Read_UINT32(s, CreationStatus);
|
| 183 |
+
|
| 184 |
+
if ((INT32)CreationStatus < 0)
|
| 185 |
+
{
|
| 186 |
+
DEBUG_DVC("ChannelId %" PRIu32 " creation failed (%" PRId32 ")", channel->channelId,
|
| 187 |
+
(INT32)CreationStatus);
|
| 188 |
+
channel->dvc_open_state = DVC_OPEN_STATE_FAILED;
|
| 189 |
+
}
|
| 190 |
+
else
|
| 191 |
+
{
|
| 192 |
+
DEBUG_DVC("ChannelId %" PRIu32 " creation succeeded", channel->channelId);
|
| 193 |
+
channel->dvc_open_state = DVC_OPEN_STATE_SUCCEEDED;
|
| 194 |
+
}
|
| 195 |
+
|
| 196 |
+
channel->creationStatus = (INT32)CreationStatus;
|
| 197 |
+
IFCALLRET(channel->vcm->dvc_creation_status, status, channel->vcm->dvc_creation_status_userdata,
|
| 198 |
+
channel->channelId, (INT32)CreationStatus);
|
| 199 |
+
if (!status)
|
| 200 |
+
WLog_ERR(TAG, "vcm->dvc_creation_status failed!");
|
| 201 |
+
|
| 202 |
+
return status;
|
| 203 |
+
}
|
| 204 |
+
|
| 205 |
+
static BOOL wts_read_drdynvc_data_first(rdpPeerChannel* channel, wStream* s, int cbLen,
|
| 206 |
+
UINT32 length)
|
| 207 |
+
{
|
| 208 |
+
WINPR_ASSERT(channel);
|
| 209 |
+
WINPR_ASSERT(s);
|
| 210 |
+
const UINT32 value = wts_read_variable_uint(s, cbLen, &channel->dvc_total_length);
|
| 211 |
+
|
| 212 |
+
if (value == 0)
|
| 213 |
+
return FALSE;
|
| 214 |
+
if (value > length)
|
| 215 |
+
length = 0;
|
| 216 |
+
else
|
| 217 |
+
length -= value;
|
| 218 |
+
|
| 219 |
+
if (length > channel->dvc_total_length)
|
| 220 |
+
return FALSE;
|
| 221 |
+
|
| 222 |
+
Stream_SetPosition(channel->receiveData, 0);
|
| 223 |
+
|
| 224 |
+
if (!Stream_EnsureRemainingCapacity(channel->receiveData, channel->dvc_total_length))
|
| 225 |
+
return FALSE;
|
| 226 |
+
|
| 227 |
+
Stream_Write(channel->receiveData, Stream_ConstPointer(s), length);
|
| 228 |
+
return TRUE;
|
| 229 |
+
}
|
| 230 |
+
|
| 231 |
+
static BOOL wts_read_drdynvc_data(rdpPeerChannel* channel, wStream* s, UINT32 length)
|
| 232 |
+
{
|
| 233 |
+
BOOL ret = FALSE;
|
| 234 |
+
|
| 235 |
+
WINPR_ASSERT(channel);
|
| 236 |
+
WINPR_ASSERT(s);
|
| 237 |
+
if (channel->dvc_total_length > 0)
|
| 238 |
+
{
|
| 239 |
+
if (Stream_GetPosition(channel->receiveData) + length > channel->dvc_total_length)
|
| 240 |
+
{
|
| 241 |
+
channel->dvc_total_length = 0;
|
| 242 |
+
WLog_ERR(TAG, "incorrect fragment data, discarded.");
|
| 243 |
+
return FALSE;
|
| 244 |
+
}
|
| 245 |
+
|
| 246 |
+
Stream_Write(channel->receiveData, Stream_ConstPointer(s), length);
|
| 247 |
+
|
| 248 |
+
if (Stream_GetPosition(channel->receiveData) >= channel->dvc_total_length)
|
| 249 |
+
{
|
| 250 |
+
ret = wts_queue_receive_data(channel, Stream_Buffer(channel->receiveData),
|
| 251 |
+
channel->dvc_total_length);
|
| 252 |
+
channel->dvc_total_length = 0;
|
| 253 |
+
}
|
| 254 |
+
else
|
| 255 |
+
ret = TRUE;
|
| 256 |
+
}
|
| 257 |
+
else
|
| 258 |
+
{
|
| 259 |
+
ret = wts_queue_receive_data(channel, Stream_ConstPointer(s), length);
|
| 260 |
+
}
|
| 261 |
+
|
| 262 |
+
return ret;
|
| 263 |
+
}
|
| 264 |
+
|
| 265 |
+
static void wts_read_drdynvc_close_response(rdpPeerChannel* channel)
|
| 266 |
+
{
|
| 267 |
+
WINPR_ASSERT(channel);
|
| 268 |
+
DEBUG_DVC("ChannelId %" PRIu32 " close response", channel->channelId);
|
| 269 |
+
channel->dvc_open_state = DVC_OPEN_STATE_CLOSED;
|
| 270 |
+
MessageQueue_PostQuit(channel->queue, 0);
|
| 271 |
+
}
|
| 272 |
+
|
| 273 |
+
static BOOL wts_read_drdynvc_pdu(rdpPeerChannel* channel)
|
| 274 |
+
{
|
| 275 |
+
UINT8 Cmd = 0;
|
| 276 |
+
UINT8 Sp = 0;
|
| 277 |
+
UINT8 cbChId = 0;
|
| 278 |
+
UINT32 ChannelId = 0;
|
| 279 |
+
rdpPeerChannel* dvc = NULL;
|
| 280 |
+
|
| 281 |
+
WINPR_ASSERT(channel);
|
| 282 |
+
WINPR_ASSERT(channel->vcm);
|
| 283 |
+
|
| 284 |
+
size_t length = Stream_GetPosition(channel->receiveData);
|
| 285 |
+
|
| 286 |
+
if ((length < 1) || (length > UINT32_MAX))
|
| 287 |
+
return FALSE;
|
| 288 |
+
|
| 289 |
+
Stream_SetPosition(channel->receiveData, 0);
|
| 290 |
+
const UINT8 value = Stream_Get_UINT8(channel->receiveData);
|
| 291 |
+
length--;
|
| 292 |
+
Cmd = (value & 0xf0) >> 4;
|
| 293 |
+
Sp = (value & 0x0c) >> 2;
|
| 294 |
+
cbChId = (value & 0x03) >> 0;
|
| 295 |
+
|
| 296 |
+
if (Cmd == CAPABILITY_REQUEST_PDU)
|
| 297 |
+
return wts_read_drdynvc_capabilities_response(channel, (UINT32)length);
|
| 298 |
+
|
| 299 |
+
if (channel->vcm->drdynvc_state == DRDYNVC_STATE_READY)
|
| 300 |
+
{
|
| 301 |
+
BOOL haveChannelId = 0;
|
| 302 |
+
switch (Cmd)
|
| 303 |
+
{
|
| 304 |
+
case SOFT_SYNC_REQUEST_PDU:
|
| 305 |
+
case SOFT_SYNC_RESPONSE_PDU:
|
| 306 |
+
haveChannelId = FALSE;
|
| 307 |
+
break;
|
| 308 |
+
default:
|
| 309 |
+
haveChannelId = TRUE;
|
| 310 |
+
break;
|
| 311 |
+
}
|
| 312 |
+
|
| 313 |
+
if (haveChannelId)
|
| 314 |
+
{
|
| 315 |
+
const unsigned val = wts_read_variable_uint(channel->receiveData, cbChId, &ChannelId);
|
| 316 |
+
if (val == 0)
|
| 317 |
+
return FALSE;
|
| 318 |
+
|
| 319 |
+
length -= val;
|
| 320 |
+
|
| 321 |
+
DEBUG_DVC("Cmd %s ChannelId %" PRIu32 " length %" PRIuz "",
|
| 322 |
+
drdynvc_get_packet_type(Cmd), ChannelId, length);
|
| 323 |
+
dvc = wts_get_dvc_channel_by_id(channel->vcm, ChannelId);
|
| 324 |
+
if (!dvc)
|
| 325 |
+
{
|
| 326 |
+
DEBUG_DVC("ChannelId %" PRIu32 " does not exist.", ChannelId);
|
| 327 |
+
return TRUE;
|
| 328 |
+
}
|
| 329 |
+
}
|
| 330 |
+
|
| 331 |
+
switch (Cmd)
|
| 332 |
+
{
|
| 333 |
+
case CREATE_REQUEST_PDU:
|
| 334 |
+
return wts_read_drdynvc_create_response(dvc, channel->receiveData, (UINT32)length);
|
| 335 |
+
|
| 336 |
+
case DATA_FIRST_PDU:
|
| 337 |
+
if (dvc->dvc_open_state != DVC_OPEN_STATE_SUCCEEDED)
|
| 338 |
+
{
|
| 339 |
+
WLog_ERR(TAG,
|
| 340 |
+
"ChannelId %" PRIu32 " did not open successfully. "
|
| 341 |
+
"Ignoring DYNVC_DATA_FIRST PDU",
|
| 342 |
+
ChannelId);
|
| 343 |
+
return TRUE;
|
| 344 |
+
}
|
| 345 |
+
|
| 346 |
+
return wts_read_drdynvc_data_first(dvc, channel->receiveData, Sp, (UINT32)length);
|
| 347 |
+
|
| 348 |
+
case DATA_PDU:
|
| 349 |
+
if (dvc->dvc_open_state != DVC_OPEN_STATE_SUCCEEDED)
|
| 350 |
+
{
|
| 351 |
+
WLog_ERR(TAG,
|
| 352 |
+
"ChannelId %" PRIu32 " did not open successfully. "
|
| 353 |
+
"Ignoring DYNVC_DATA PDU",
|
| 354 |
+
ChannelId);
|
| 355 |
+
return TRUE;
|
| 356 |
+
}
|
| 357 |
+
|
| 358 |
+
return wts_read_drdynvc_data(dvc, channel->receiveData, (UINT32)length);
|
| 359 |
+
|
| 360 |
+
case CLOSE_REQUEST_PDU:
|
| 361 |
+
wts_read_drdynvc_close_response(dvc);
|
| 362 |
+
break;
|
| 363 |
+
|
| 364 |
+
case DATA_FIRST_COMPRESSED_PDU:
|
| 365 |
+
case DATA_COMPRESSED_PDU:
|
| 366 |
+
WLog_ERR(TAG, "Compressed data not handled");
|
| 367 |
+
break;
|
| 368 |
+
|
| 369 |
+
case SOFT_SYNC_RESPONSE_PDU:
|
| 370 |
+
WLog_ERR(TAG, "SoftSync response not handled yet(and rather strange to receive "
|
| 371 |
+
"that packet as our code doesn't send SoftSync requests");
|
| 372 |
+
break;
|
| 373 |
+
|
| 374 |
+
case SOFT_SYNC_REQUEST_PDU:
|
| 375 |
+
WLog_ERR(TAG, "Not expecting a SoftSyncRequest on the server");
|
| 376 |
+
return FALSE;
|
| 377 |
+
|
| 378 |
+
default:
|
| 379 |
+
WLog_ERR(TAG, "Cmd %d not recognized.", Cmd);
|
| 380 |
+
break;
|
| 381 |
+
}
|
| 382 |
+
}
|
| 383 |
+
else
|
| 384 |
+
{
|
| 385 |
+
WLog_ERR(TAG, "received Cmd %d but channel is not ready.", Cmd);
|
| 386 |
+
}
|
| 387 |
+
|
| 388 |
+
return TRUE;
|
| 389 |
+
}
|
| 390 |
+
|
| 391 |
+
static int wts_write_variable_uint(wStream* s, UINT32 val)
|
| 392 |
+
{
|
| 393 |
+
int cb = 0;
|
| 394 |
+
|
| 395 |
+
WINPR_ASSERT(s);
|
| 396 |
+
if (val <= 0xFF)
|
| 397 |
+
{
|
| 398 |
+
cb = 0;
|
| 399 |
+
Stream_Write_UINT8(s, WINPR_ASSERTING_INT_CAST(uint8_t, val));
|
| 400 |
+
}
|
| 401 |
+
else if (val <= 0xFFFF)
|
| 402 |
+
{
|
| 403 |
+
cb = 1;
|
| 404 |
+
Stream_Write_UINT16(s, WINPR_ASSERTING_INT_CAST(uint16_t, val));
|
| 405 |
+
}
|
| 406 |
+
else
|
| 407 |
+
{
|
| 408 |
+
cb = 2;
|
| 409 |
+
Stream_Write_UINT32(s, val);
|
| 410 |
+
}
|
| 411 |
+
|
| 412 |
+
return cb;
|
| 413 |
+
}
|
| 414 |
+
|
| 415 |
+
static void wts_write_drdynvc_header(wStream* s, BYTE Cmd, UINT32 ChannelId)
|
| 416 |
+
{
|
| 417 |
+
BYTE* bm = NULL;
|
| 418 |
+
int cbChId = 0;
|
| 419 |
+
|
| 420 |
+
WINPR_ASSERT(s);
|
| 421 |
+
|
| 422 |
+
Stream_GetPointer(s, bm);
|
| 423 |
+
Stream_Seek_UINT8(s);
|
| 424 |
+
cbChId = wts_write_variable_uint(s, ChannelId);
|
| 425 |
+
*bm = (((Cmd & 0x0F) << 4) | cbChId) & 0xFF;
|
| 426 |
+
}
|
| 427 |
+
|
| 428 |
+
static BOOL wts_write_drdynvc_create_request(wStream* s, UINT32 ChannelId, const char* ChannelName)
|
| 429 |
+
{
|
| 430 |
+
size_t len = 0;
|
| 431 |
+
|
| 432 |
+
WINPR_ASSERT(s);
|
| 433 |
+
WINPR_ASSERT(ChannelName);
|
| 434 |
+
|
| 435 |
+
wts_write_drdynvc_header(s, CREATE_REQUEST_PDU, ChannelId);
|
| 436 |
+
len = strlen(ChannelName) + 1;
|
| 437 |
+
|
| 438 |
+
if (!Stream_EnsureRemainingCapacity(s, len))
|
| 439 |
+
return FALSE;
|
| 440 |
+
|
| 441 |
+
Stream_Write(s, ChannelName, len);
|
| 442 |
+
return TRUE;
|
| 443 |
+
}
|
| 444 |
+
|
| 445 |
+
static BOOL WTSProcessChannelData(rdpPeerChannel* channel, UINT16 channelId, const BYTE* data,
|
| 446 |
+
size_t s, UINT32 flags, size_t t)
|
| 447 |
+
{
|
| 448 |
+
BOOL ret = TRUE;
|
| 449 |
+
const size_t size = s;
|
| 450 |
+
const size_t totalSize = t;
|
| 451 |
+
|
| 452 |
+
WINPR_ASSERT(channel);
|
| 453 |
+
WINPR_ASSERT(channel->vcm);
|
| 454 |
+
WINPR_UNUSED(channelId);
|
| 455 |
+
|
| 456 |
+
if (flags & CHANNEL_FLAG_FIRST)
|
| 457 |
+
{
|
| 458 |
+
Stream_SetPosition(channel->receiveData, 0);
|
| 459 |
+
}
|
| 460 |
+
|
| 461 |
+
if (!Stream_EnsureRemainingCapacity(channel->receiveData, size))
|
| 462 |
+
return FALSE;
|
| 463 |
+
|
| 464 |
+
Stream_Write(channel->receiveData, data, size);
|
| 465 |
+
|
| 466 |
+
if (flags & CHANNEL_FLAG_LAST)
|
| 467 |
+
{
|
| 468 |
+
if (Stream_GetPosition(channel->receiveData) != totalSize)
|
| 469 |
+
{
|
| 470 |
+
WLog_ERR(TAG, "read error");
|
| 471 |
+
}
|
| 472 |
+
|
| 473 |
+
if (channel == channel->vcm->drdynvc_channel)
|
| 474 |
+
{
|
| 475 |
+
ret = wts_read_drdynvc_pdu(channel);
|
| 476 |
+
}
|
| 477 |
+
else
|
| 478 |
+
{
|
| 479 |
+
const size_t pos = Stream_GetPosition(channel->receiveData);
|
| 480 |
+
if (pos > UINT32_MAX)
|
| 481 |
+
ret = FALSE;
|
| 482 |
+
else
|
| 483 |
+
ret = wts_queue_receive_data(channel, Stream_Buffer(channel->receiveData),
|
| 484 |
+
(UINT32)pos);
|
| 485 |
+
}
|
| 486 |
+
|
| 487 |
+
Stream_SetPosition(channel->receiveData, 0);
|
| 488 |
+
}
|
| 489 |
+
|
| 490 |
+
return ret;
|
| 491 |
+
}
|
| 492 |
+
|
| 493 |
+
static BOOL WTSReceiveChannelData(freerdp_peer* client, UINT16 channelId, const BYTE* data,
|
| 494 |
+
size_t size, UINT32 flags, size_t totalSize)
|
| 495 |
+
{
|
| 496 |
+
rdpMcs* mcs = NULL;
|
| 497 |
+
|
| 498 |
+
WINPR_ASSERT(client);
|
| 499 |
+
WINPR_ASSERT(client->context);
|
| 500 |
+
WINPR_ASSERT(client->context->rdp);
|
| 501 |
+
|
| 502 |
+
mcs = client->context->rdp->mcs;
|
| 503 |
+
WINPR_ASSERT(mcs);
|
| 504 |
+
|
| 505 |
+
for (UINT32 i = 0; i < mcs->channelCount; i++)
|
| 506 |
+
{
|
| 507 |
+
rdpMcsChannel* cur = &mcs->channels[i];
|
| 508 |
+
if (cur->ChannelId == channelId)
|
| 509 |
+
{
|
| 510 |
+
rdpPeerChannel* channel = (rdpPeerChannel*)cur->handle;
|
| 511 |
+
|
| 512 |
+
if (channel)
|
| 513 |
+
return WTSProcessChannelData(channel, channelId, data, size, flags, totalSize);
|
| 514 |
+
}
|
| 515 |
+
}
|
| 516 |
+
|
| 517 |
+
WLog_WARN(TAG, "unknown channelId %" PRIu16 " ignored", channelId);
|
| 518 |
+
|
| 519 |
+
return TRUE;
|
| 520 |
+
}
|
| 521 |
+
|
| 522 |
+
#if defined(WITH_FREERDP_DEPRECATED)
|
| 523 |
+
void WTSVirtualChannelManagerGetFileDescriptor(HANDLE hServer, void** fds, int* fds_count)
|
| 524 |
+
{
|
| 525 |
+
void* fd = NULL;
|
| 526 |
+
WTSVirtualChannelManager* vcm = (WTSVirtualChannelManager*)hServer;
|
| 527 |
+
WINPR_ASSERT(vcm);
|
| 528 |
+
WINPR_ASSERT(fds);
|
| 529 |
+
WINPR_ASSERT(fds_count);
|
| 530 |
+
|
| 531 |
+
fd = GetEventWaitObject(MessageQueue_Event(vcm->queue));
|
| 532 |
+
|
| 533 |
+
if (fd)
|
| 534 |
+
{
|
| 535 |
+
fds[*fds_count] = fd;
|
| 536 |
+
(*fds_count)++;
|
| 537 |
+
}
|
| 538 |
+
|
| 539 |
+
#if 0
|
| 540 |
+
|
| 541 |
+
if (vcm->drdynvc_channel)
|
| 542 |
+
{
|
| 543 |
+
fd = GetEventWaitObject(vcm->drdynvc_channel->receiveEvent);
|
| 544 |
+
|
| 545 |
+
if (fd)
|
| 546 |
+
{
|
| 547 |
+
fds[*fds_count] = fd;
|
| 548 |
+
(*fds_count)++;
|
| 549 |
+
}
|
| 550 |
+
}
|
| 551 |
+
|
| 552 |
+
#endif
|
| 553 |
+
}
|
| 554 |
+
#endif
|
| 555 |
+
|
| 556 |
+
BOOL WTSVirtualChannelManagerOpen(HANDLE hServer)
|
| 557 |
+
{
|
| 558 |
+
WTSVirtualChannelManager* vcm = (WTSVirtualChannelManager*)hServer;
|
| 559 |
+
|
| 560 |
+
if (!vcm)
|
| 561 |
+
return FALSE;
|
| 562 |
+
|
| 563 |
+
if (vcm->drdynvc_state == DRDYNVC_STATE_NONE)
|
| 564 |
+
{
|
| 565 |
+
rdpPeerChannel* channel = NULL;
|
| 566 |
+
|
| 567 |
+
/* Initialize drdynvc channel once and only once. */
|
| 568 |
+
vcm->drdynvc_state = DRDYNVC_STATE_INITIALIZED;
|
| 569 |
+
channel = (rdpPeerChannel*)WTSVirtualChannelOpen((HANDLE)vcm, WTS_CURRENT_SESSION,
|
| 570 |
+
DRDYNVC_SVC_CHANNEL_NAME);
|
| 571 |
+
|
| 572 |
+
if (channel)
|
| 573 |
+
{
|
| 574 |
+
BYTE capaBuffer[12] = { 0 };
|
| 575 |
+
wStream staticS = { 0 };
|
| 576 |
+
wStream* s = Stream_StaticInit(&staticS, capaBuffer, sizeof(capaBuffer));
|
| 577 |
+
|
| 578 |
+
vcm->drdynvc_channel = channel;
|
| 579 |
+
vcm->dvc_spoken_version = 1;
|
| 580 |
+
Stream_Write_UINT8(s, 0x50); /* Cmd=5 sp=0 cbId=0 */
|
| 581 |
+
Stream_Write_UINT8(s, 0x00); /* Pad */
|
| 582 |
+
Stream_Write_UINT16(s, 0x0001); /* Version */
|
| 583 |
+
|
| 584 |
+
/* TODO: shall implement version 2 and 3 */
|
| 585 |
+
|
| 586 |
+
const size_t pos = Stream_GetPosition(s);
|
| 587 |
+
WINPR_ASSERT(pos <= UINT32_MAX);
|
| 588 |
+
ULONG written = 0;
|
| 589 |
+
if (!WTSVirtualChannelWrite(channel, (PCHAR)capaBuffer, (UINT32)pos, &written))
|
| 590 |
+
return FALSE;
|
| 591 |
+
}
|
| 592 |
+
}
|
| 593 |
+
|
| 594 |
+
return TRUE;
|
| 595 |
+
}
|
| 596 |
+
|
| 597 |
+
BOOL WTSVirtualChannelManagerCheckFileDescriptorEx(HANDLE hServer, BOOL autoOpen)
|
| 598 |
+
{
|
| 599 |
+
wMessage message = { 0 };
|
| 600 |
+
BOOL status = TRUE;
|
| 601 |
+
WTSVirtualChannelManager* vcm = NULL;
|
| 602 |
+
|
| 603 |
+
if (!hServer || hServer == INVALID_HANDLE_VALUE)
|
| 604 |
+
return FALSE;
|
| 605 |
+
|
| 606 |
+
vcm = (WTSVirtualChannelManager*)hServer;
|
| 607 |
+
|
| 608 |
+
if (autoOpen)
|
| 609 |
+
{
|
| 610 |
+
if (!WTSVirtualChannelManagerOpen(hServer))
|
| 611 |
+
return FALSE;
|
| 612 |
+
}
|
| 613 |
+
|
| 614 |
+
while (MessageQueue_Peek(vcm->queue, &message, TRUE))
|
| 615 |
+
{
|
| 616 |
+
BYTE* buffer = NULL;
|
| 617 |
+
UINT32 length = 0;
|
| 618 |
+
UINT16 channelId = 0;
|
| 619 |
+
channelId = (UINT16)(UINT_PTR)message.context;
|
| 620 |
+
buffer = (BYTE*)message.wParam;
|
| 621 |
+
length = (UINT32)(UINT_PTR)message.lParam;
|
| 622 |
+
|
| 623 |
+
WINPR_ASSERT(vcm->client);
|
| 624 |
+
WINPR_ASSERT(vcm->client->SendChannelData);
|
| 625 |
+
if (!vcm->client->SendChannelData(vcm->client, channelId, buffer, length))
|
| 626 |
+
{
|
| 627 |
+
status = FALSE;
|
| 628 |
+
}
|
| 629 |
+
|
| 630 |
+
free(buffer);
|
| 631 |
+
|
| 632 |
+
if (!status)
|
| 633 |
+
break;
|
| 634 |
+
}
|
| 635 |
+
|
| 636 |
+
return status;
|
| 637 |
+
}
|
| 638 |
+
|
| 639 |
+
BOOL WTSVirtualChannelManagerCheckFileDescriptor(HANDLE hServer)
|
| 640 |
+
{
|
| 641 |
+
return WTSVirtualChannelManagerCheckFileDescriptorEx(hServer, TRUE);
|
| 642 |
+
}
|
| 643 |
+
|
| 644 |
+
HANDLE WTSVirtualChannelManagerGetEventHandle(HANDLE hServer)
|
| 645 |
+
{
|
| 646 |
+
WTSVirtualChannelManager* vcm = (WTSVirtualChannelManager*)hServer;
|
| 647 |
+
WINPR_ASSERT(vcm);
|
| 648 |
+
return MessageQueue_Event(vcm->queue);
|
| 649 |
+
}
|
| 650 |
+
|
| 651 |
+
static rdpMcsChannel* wts_get_joined_channel_by_name(rdpMcs* mcs, const char* channel_name)
|
| 652 |
+
{
|
| 653 |
+
if (!mcs || !channel_name || !strnlen(channel_name, CHANNEL_NAME_LEN + 1))
|
| 654 |
+
return NULL;
|
| 655 |
+
|
| 656 |
+
for (UINT32 index = 0; index < mcs->channelCount; index++)
|
| 657 |
+
{
|
| 658 |
+
rdpMcsChannel* mchannel = &mcs->channels[index];
|
| 659 |
+
if (mchannel->joined)
|
| 660 |
+
{
|
| 661 |
+
if (_strnicmp(mchannel->Name, channel_name, CHANNEL_NAME_LEN + 1) == 0)
|
| 662 |
+
return mchannel;
|
| 663 |
+
}
|
| 664 |
+
}
|
| 665 |
+
|
| 666 |
+
return NULL;
|
| 667 |
+
}
|
| 668 |
+
|
| 669 |
+
static rdpMcsChannel* wts_get_joined_channel_by_id(rdpMcs* mcs, const UINT16 channel_id)
|
| 670 |
+
{
|
| 671 |
+
if (!mcs || !channel_id)
|
| 672 |
+
return NULL;
|
| 673 |
+
|
| 674 |
+
WINPR_ASSERT(mcs->channels);
|
| 675 |
+
for (UINT32 index = 0; index < mcs->channelCount; index++)
|
| 676 |
+
{
|
| 677 |
+
rdpMcsChannel* mchannel = &mcs->channels[index];
|
| 678 |
+
if (mchannel->joined)
|
| 679 |
+
{
|
| 680 |
+
if (mchannel->ChannelId == channel_id)
|
| 681 |
+
return &mcs->channels[index];
|
| 682 |
+
}
|
| 683 |
+
}
|
| 684 |
+
|
| 685 |
+
return NULL;
|
| 686 |
+
}
|
| 687 |
+
|
| 688 |
+
BOOL WTSIsChannelJoinedByName(freerdp_peer* client, const char* channel_name)
|
| 689 |
+
{
|
| 690 |
+
if (!client || !client->context || !client->context->rdp)
|
| 691 |
+
return FALSE;
|
| 692 |
+
|
| 693 |
+
return wts_get_joined_channel_by_name(client->context->rdp->mcs, channel_name) == NULL ? FALSE
|
| 694 |
+
: TRUE;
|
| 695 |
+
}
|
| 696 |
+
|
| 697 |
+
BOOL WTSIsChannelJoinedById(freerdp_peer* client, const UINT16 channel_id)
|
| 698 |
+
{
|
| 699 |
+
if (!client || !client->context || !client->context->rdp)
|
| 700 |
+
return FALSE;
|
| 701 |
+
|
| 702 |
+
return wts_get_joined_channel_by_id(client->context->rdp->mcs, channel_id) == NULL ? FALSE
|
| 703 |
+
: TRUE;
|
| 704 |
+
}
|
| 705 |
+
|
| 706 |
+
BOOL WTSVirtualChannelManagerIsChannelJoined(HANDLE hServer, const char* name)
|
| 707 |
+
{
|
| 708 |
+
WTSVirtualChannelManager* vcm = (WTSVirtualChannelManager*)hServer;
|
| 709 |
+
|
| 710 |
+
if (!vcm || !vcm->rdp)
|
| 711 |
+
return FALSE;
|
| 712 |
+
|
| 713 |
+
return wts_get_joined_channel_by_name(vcm->rdp->mcs, name) == NULL ? FALSE : TRUE;
|
| 714 |
+
}
|
| 715 |
+
|
| 716 |
+
BYTE WTSVirtualChannelManagerGetDrdynvcState(HANDLE hServer)
|
| 717 |
+
{
|
| 718 |
+
WTSVirtualChannelManager* vcm = (WTSVirtualChannelManager*)hServer;
|
| 719 |
+
WINPR_ASSERT(vcm);
|
| 720 |
+
return vcm->drdynvc_state;
|
| 721 |
+
}
|
| 722 |
+
|
| 723 |
+
void WTSVirtualChannelManagerSetDVCCreationCallback(HANDLE hServer, psDVCCreationStatusCallback cb,
|
| 724 |
+
void* userdata)
|
| 725 |
+
{
|
| 726 |
+
WTSVirtualChannelManager* vcm = hServer;
|
| 727 |
+
|
| 728 |
+
WINPR_ASSERT(vcm);
|
| 729 |
+
|
| 730 |
+
vcm->dvc_creation_status = cb;
|
| 731 |
+
vcm->dvc_creation_status_userdata = userdata;
|
| 732 |
+
}
|
| 733 |
+
|
| 734 |
+
UINT16 WTSChannelGetId(freerdp_peer* client, const char* channel_name)
|
| 735 |
+
{
|
| 736 |
+
rdpMcsChannel* channel = NULL;
|
| 737 |
+
|
| 738 |
+
WINPR_ASSERT(channel_name);
|
| 739 |
+
if (!client || !client->context || !client->context->rdp)
|
| 740 |
+
return 0;
|
| 741 |
+
|
| 742 |
+
channel = wts_get_joined_channel_by_name(client->context->rdp->mcs, channel_name);
|
| 743 |
+
|
| 744 |
+
if (!channel)
|
| 745 |
+
return 0;
|
| 746 |
+
|
| 747 |
+
return channel->ChannelId;
|
| 748 |
+
}
|
| 749 |
+
|
| 750 |
+
UINT32 WTSChannelGetIdByHandle(HANDLE hChannelHandle)
|
| 751 |
+
{
|
| 752 |
+
rdpPeerChannel* channel = hChannelHandle;
|
| 753 |
+
|
| 754 |
+
WINPR_ASSERT(channel);
|
| 755 |
+
|
| 756 |
+
return channel->channelId;
|
| 757 |
+
}
|
| 758 |
+
|
| 759 |
+
BOOL WTSChannelSetHandleByName(freerdp_peer* client, const char* channel_name, void* handle)
|
| 760 |
+
{
|
| 761 |
+
rdpMcsChannel* channel = NULL;
|
| 762 |
+
|
| 763 |
+
WINPR_ASSERT(channel_name);
|
| 764 |
+
if (!client || !client->context || !client->context->rdp)
|
| 765 |
+
return FALSE;
|
| 766 |
+
|
| 767 |
+
channel = wts_get_joined_channel_by_name(client->context->rdp->mcs, channel_name);
|
| 768 |
+
|
| 769 |
+
if (!channel)
|
| 770 |
+
return FALSE;
|
| 771 |
+
|
| 772 |
+
channel->handle = handle;
|
| 773 |
+
return TRUE;
|
| 774 |
+
}
|
| 775 |
+
|
| 776 |
+
BOOL WTSChannelSetHandleById(freerdp_peer* client, const UINT16 channel_id, void* handle)
|
| 777 |
+
{
|
| 778 |
+
rdpMcsChannel* channel = NULL;
|
| 779 |
+
|
| 780 |
+
if (!client || !client->context || !client->context->rdp)
|
| 781 |
+
return FALSE;
|
| 782 |
+
|
| 783 |
+
channel = wts_get_joined_channel_by_id(client->context->rdp->mcs, channel_id);
|
| 784 |
+
|
| 785 |
+
if (!channel)
|
| 786 |
+
return FALSE;
|
| 787 |
+
|
| 788 |
+
channel->handle = handle;
|
| 789 |
+
return TRUE;
|
| 790 |
+
}
|
| 791 |
+
|
| 792 |
+
void* WTSChannelGetHandleByName(freerdp_peer* client, const char* channel_name)
|
| 793 |
+
{
|
| 794 |
+
rdpMcsChannel* channel = NULL;
|
| 795 |
+
|
| 796 |
+
WINPR_ASSERT(channel_name);
|
| 797 |
+
if (!client || !client->context || !client->context->rdp)
|
| 798 |
+
return NULL;
|
| 799 |
+
|
| 800 |
+
channel = wts_get_joined_channel_by_name(client->context->rdp->mcs, channel_name);
|
| 801 |
+
|
| 802 |
+
if (!channel)
|
| 803 |
+
return NULL;
|
| 804 |
+
|
| 805 |
+
return channel->handle;
|
| 806 |
+
}
|
| 807 |
+
|
| 808 |
+
void* WTSChannelGetHandleById(freerdp_peer* client, const UINT16 channel_id)
|
| 809 |
+
{
|
| 810 |
+
rdpMcsChannel* channel = NULL;
|
| 811 |
+
|
| 812 |
+
if (!client || !client->context || !client->context->rdp)
|
| 813 |
+
return NULL;
|
| 814 |
+
|
| 815 |
+
channel = wts_get_joined_channel_by_id(client->context->rdp->mcs, channel_id);
|
| 816 |
+
|
| 817 |
+
if (!channel)
|
| 818 |
+
return NULL;
|
| 819 |
+
|
| 820 |
+
return channel->handle;
|
| 821 |
+
}
|
| 822 |
+
|
| 823 |
+
const char* WTSChannelGetName(freerdp_peer* client, UINT16 channel_id)
|
| 824 |
+
{
|
| 825 |
+
rdpMcsChannel* channel = NULL;
|
| 826 |
+
|
| 827 |
+
if (!client || !client->context || !client->context->rdp)
|
| 828 |
+
return NULL;
|
| 829 |
+
|
| 830 |
+
channel = wts_get_joined_channel_by_id(client->context->rdp->mcs, channel_id);
|
| 831 |
+
|
| 832 |
+
if (!channel)
|
| 833 |
+
return NULL;
|
| 834 |
+
|
| 835 |
+
return (const char*)channel->Name;
|
| 836 |
+
}
|
| 837 |
+
|
| 838 |
+
char** WTSGetAcceptedChannelNames(freerdp_peer* client, size_t* count)
|
| 839 |
+
{
|
| 840 |
+
rdpMcs* mcs = NULL;
|
| 841 |
+
char** names = NULL;
|
| 842 |
+
|
| 843 |
+
if (!client || !client->context || !count)
|
| 844 |
+
return NULL;
|
| 845 |
+
|
| 846 |
+
WINPR_ASSERT(client->context->rdp);
|
| 847 |
+
mcs = client->context->rdp->mcs;
|
| 848 |
+
WINPR_ASSERT(mcs);
|
| 849 |
+
*count = mcs->channelCount;
|
| 850 |
+
|
| 851 |
+
names = (char**)calloc(mcs->channelCount, sizeof(char*));
|
| 852 |
+
if (!names)
|
| 853 |
+
return NULL;
|
| 854 |
+
|
| 855 |
+
for (UINT32 index = 0; index < mcs->channelCount; index++)
|
| 856 |
+
{
|
| 857 |
+
rdpMcsChannel* mchannel = &mcs->channels[index];
|
| 858 |
+
names[index] = mchannel->Name;
|
| 859 |
+
}
|
| 860 |
+
|
| 861 |
+
return names;
|
| 862 |
+
}
|
| 863 |
+
|
| 864 |
+
INT64 WTSChannelGetOptions(freerdp_peer* client, UINT16 channel_id)
|
| 865 |
+
{
|
| 866 |
+
rdpMcsChannel* channel = NULL;
|
| 867 |
+
|
| 868 |
+
if (!client || !client->context || !client->context->rdp)
|
| 869 |
+
return -1;
|
| 870 |
+
|
| 871 |
+
channel = wts_get_joined_channel_by_id(client->context->rdp->mcs, channel_id);
|
| 872 |
+
|
| 873 |
+
if (!channel)
|
| 874 |
+
return -1;
|
| 875 |
+
|
| 876 |
+
return (INT64)channel->options;
|
| 877 |
+
}
|
| 878 |
+
|
| 879 |
+
BOOL WINAPI FreeRDP_WTSStartRemoteControlSessionW(LPWSTR pTargetServerName, ULONG TargetLogonId,
|
| 880 |
+
BYTE HotkeyVk, USHORT HotkeyModifiers)
|
| 881 |
+
{
|
| 882 |
+
return FALSE;
|
| 883 |
+
}
|
| 884 |
+
|
| 885 |
+
BOOL WINAPI FreeRDP_WTSStartRemoteControlSessionA(LPSTR pTargetServerName, ULONG TargetLogonId,
|
| 886 |
+
BYTE HotkeyVk, USHORT HotkeyModifiers)
|
| 887 |
+
{
|
| 888 |
+
return FALSE;
|
| 889 |
+
}
|
| 890 |
+
|
| 891 |
+
BOOL WINAPI FreeRDP_WTSStartRemoteControlSessionExW(LPWSTR pTargetServerName, ULONG TargetLogonId,
|
| 892 |
+
BYTE HotkeyVk, USHORT HotkeyModifiers,
|
| 893 |
+
DWORD flags)
|
| 894 |
+
{
|
| 895 |
+
return FALSE;
|
| 896 |
+
}
|
| 897 |
+
|
| 898 |
+
BOOL WINAPI FreeRDP_WTSStartRemoteControlSessionExA(LPSTR pTargetServerName, ULONG TargetLogonId,
|
| 899 |
+
BYTE HotkeyVk, USHORT HotkeyModifiers,
|
| 900 |
+
DWORD flags)
|
| 901 |
+
{
|
| 902 |
+
return FALSE;
|
| 903 |
+
}
|
| 904 |
+
|
| 905 |
+
BOOL WINAPI FreeRDP_WTSStopRemoteControlSession(ULONG LogonId)
|
| 906 |
+
{
|
| 907 |
+
return FALSE;
|
| 908 |
+
}
|
| 909 |
+
|
| 910 |
+
BOOL WINAPI FreeRDP_WTSConnectSessionW(ULONG LogonId, ULONG TargetLogonId, PWSTR pPassword,
|
| 911 |
+
BOOL bWait)
|
| 912 |
+
{
|
| 913 |
+
return FALSE;
|
| 914 |
+
}
|
| 915 |
+
|
| 916 |
+
BOOL WINAPI FreeRDP_WTSConnectSessionA(ULONG LogonId, ULONG TargetLogonId, PSTR pPassword,
|
| 917 |
+
BOOL bWait)
|
| 918 |
+
{
|
| 919 |
+
return FALSE;
|
| 920 |
+
}
|
| 921 |
+
|
| 922 |
+
BOOL WINAPI FreeRDP_WTSEnumerateServersW(LPWSTR pDomainName, DWORD Reserved, DWORD Version,
|
| 923 |
+
PWTS_SERVER_INFOW* ppServerInfo, DWORD* pCount)
|
| 924 |
+
{
|
| 925 |
+
return FALSE;
|
| 926 |
+
}
|
| 927 |
+
|
| 928 |
+
BOOL WINAPI FreeRDP_WTSEnumerateServersA(LPSTR pDomainName, DWORD Reserved, DWORD Version,
|
| 929 |
+
PWTS_SERVER_INFOA* ppServerInfo, DWORD* pCount)
|
| 930 |
+
{
|
| 931 |
+
return FALSE;
|
| 932 |
+
}
|
| 933 |
+
|
| 934 |
+
HANDLE WINAPI FreeRDP_WTSOpenServerW(LPWSTR pServerName)
|
| 935 |
+
{
|
| 936 |
+
return INVALID_HANDLE_VALUE;
|
| 937 |
+
}
|
| 938 |
+
|
| 939 |
+
static void wts_virtual_channel_manager_free_message(void* obj)
|
| 940 |
+
{
|
| 941 |
+
wMessage* msg = (wMessage*)obj;
|
| 942 |
+
|
| 943 |
+
if (msg)
|
| 944 |
+
{
|
| 945 |
+
BYTE* buffer = (BYTE*)msg->wParam;
|
| 946 |
+
|
| 947 |
+
if (buffer)
|
| 948 |
+
free(buffer);
|
| 949 |
+
}
|
| 950 |
+
}
|
| 951 |
+
|
| 952 |
+
static void channel_free(rdpPeerChannel* channel)
|
| 953 |
+
{
|
| 954 |
+
server_channel_common_free(channel);
|
| 955 |
+
}
|
| 956 |
+
|
| 957 |
+
static void array_channel_free(void* ptr)
|
| 958 |
+
{
|
| 959 |
+
rdpPeerChannel* channel = ptr;
|
| 960 |
+
channel_free(channel);
|
| 961 |
+
}
|
| 962 |
+
|
| 963 |
+
static BOOL dynChannelMatch(const void* v1, const void* v2)
|
| 964 |
+
{
|
| 965 |
+
const UINT32* p1 = (const UINT32*)v1;
|
| 966 |
+
const UINT32* p2 = (const UINT32*)v2;
|
| 967 |
+
return *p1 == *p2;
|
| 968 |
+
}
|
| 969 |
+
|
| 970 |
+
static UINT32 channelId_Hash(const void* key)
|
| 971 |
+
{
|
| 972 |
+
const UINT32* v = (const UINT32*)key;
|
| 973 |
+
return *v;
|
| 974 |
+
}
|
| 975 |
+
|
| 976 |
+
HANDLE WINAPI FreeRDP_WTSOpenServerA(LPSTR pServerName)
|
| 977 |
+
{
|
| 978 |
+
rdpContext* context = NULL;
|
| 979 |
+
freerdp_peer* client = NULL;
|
| 980 |
+
WTSVirtualChannelManager* vcm = NULL;
|
| 981 |
+
HANDLE hServer = INVALID_HANDLE_VALUE;
|
| 982 |
+
wObject queueCallbacks = { 0 };
|
| 983 |
+
|
| 984 |
+
context = (rdpContext*)pServerName;
|
| 985 |
+
|
| 986 |
+
if (!context)
|
| 987 |
+
return INVALID_HANDLE_VALUE;
|
| 988 |
+
|
| 989 |
+
client = context->peer;
|
| 990 |
+
|
| 991 |
+
if (!client)
|
| 992 |
+
{
|
| 993 |
+
SetLastError(ERROR_INVALID_DATA);
|
| 994 |
+
return INVALID_HANDLE_VALUE;
|
| 995 |
+
}
|
| 996 |
+
|
| 997 |
+
vcm = (WTSVirtualChannelManager*)calloc(1, sizeof(WTSVirtualChannelManager));
|
| 998 |
+
|
| 999 |
+
if (!vcm)
|
| 1000 |
+
goto error_vcm_alloc;
|
| 1001 |
+
|
| 1002 |
+
vcm->client = client;
|
| 1003 |
+
vcm->rdp = context->rdp;
|
| 1004 |
+
vcm->SessionId = g_SessionId++;
|
| 1005 |
+
|
| 1006 |
+
if (!g_ServerHandles)
|
| 1007 |
+
{
|
| 1008 |
+
g_ServerHandles = HashTable_New(TRUE);
|
| 1009 |
+
|
| 1010 |
+
if (!g_ServerHandles)
|
| 1011 |
+
goto error_free;
|
| 1012 |
+
}
|
| 1013 |
+
|
| 1014 |
+
if (!HashTable_Insert(g_ServerHandles, (void*)(UINT_PTR)vcm->SessionId, (void*)vcm))
|
| 1015 |
+
goto error_free;
|
| 1016 |
+
|
| 1017 |
+
queueCallbacks.fnObjectFree = wts_virtual_channel_manager_free_message;
|
| 1018 |
+
vcm->queue = MessageQueue_New(&queueCallbacks);
|
| 1019 |
+
|
| 1020 |
+
if (!vcm->queue)
|
| 1021 |
+
goto error_queue;
|
| 1022 |
+
|
| 1023 |
+
vcm->dvc_channel_id_seq = 0;
|
| 1024 |
+
vcm->dynamicVirtualChannels = HashTable_New(TRUE);
|
| 1025 |
+
|
| 1026 |
+
if (!vcm->dynamicVirtualChannels)
|
| 1027 |
+
goto error_dynamicVirtualChannels;
|
| 1028 |
+
|
| 1029 |
+
if (!HashTable_SetHashFunction(vcm->dynamicVirtualChannels, channelId_Hash))
|
| 1030 |
+
goto error_hashFunction;
|
| 1031 |
+
|
| 1032 |
+
{
|
| 1033 |
+
wObject* obj = HashTable_ValueObject(vcm->dynamicVirtualChannels);
|
| 1034 |
+
WINPR_ASSERT(obj);
|
| 1035 |
+
obj->fnObjectFree = array_channel_free;
|
| 1036 |
+
|
| 1037 |
+
obj = HashTable_KeyObject(vcm->dynamicVirtualChannels);
|
| 1038 |
+
obj->fnObjectEquals = dynChannelMatch;
|
| 1039 |
+
}
|
| 1040 |
+
client->ReceiveChannelData = WTSReceiveChannelData;
|
| 1041 |
+
hServer = (HANDLE)vcm;
|
| 1042 |
+
return hServer;
|
| 1043 |
+
|
| 1044 |
+
error_hashFunction:
|
| 1045 |
+
HashTable_Free(vcm->dynamicVirtualChannels);
|
| 1046 |
+
error_dynamicVirtualChannels:
|
| 1047 |
+
MessageQueue_Free(vcm->queue);
|
| 1048 |
+
error_queue:
|
| 1049 |
+
HashTable_Remove(g_ServerHandles, (void*)(UINT_PTR)vcm->SessionId);
|
| 1050 |
+
error_free:
|
| 1051 |
+
free(vcm);
|
| 1052 |
+
error_vcm_alloc:
|
| 1053 |
+
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
| 1054 |
+
return INVALID_HANDLE_VALUE;
|
| 1055 |
+
}
|
| 1056 |
+
|
| 1057 |
+
HANDLE WINAPI FreeRDP_WTSOpenServerExW(LPWSTR pServerName)
|
| 1058 |
+
{
|
| 1059 |
+
return INVALID_HANDLE_VALUE;
|
| 1060 |
+
}
|
| 1061 |
+
|
| 1062 |
+
HANDLE WINAPI FreeRDP_WTSOpenServerExA(LPSTR pServerName)
|
| 1063 |
+
{
|
| 1064 |
+
return FreeRDP_WTSOpenServerA(pServerName);
|
| 1065 |
+
}
|
| 1066 |
+
|
| 1067 |
+
VOID WINAPI FreeRDP_WTSCloseServer(HANDLE hServer)
|
| 1068 |
+
{
|
| 1069 |
+
WTSVirtualChannelManager* vcm = NULL;
|
| 1070 |
+
vcm = (WTSVirtualChannelManager*)hServer;
|
| 1071 |
+
|
| 1072 |
+
if (vcm && (vcm != INVALID_HANDLE_VALUE))
|
| 1073 |
+
{
|
| 1074 |
+
HashTable_Remove(g_ServerHandles, (void*)(UINT_PTR)vcm->SessionId);
|
| 1075 |
+
|
| 1076 |
+
HashTable_Free(vcm->dynamicVirtualChannels);
|
| 1077 |
+
|
| 1078 |
+
if (vcm->drdynvc_channel)
|
| 1079 |
+
{
|
| 1080 |
+
(void)WTSVirtualChannelClose(vcm->drdynvc_channel);
|
| 1081 |
+
vcm->drdynvc_channel = NULL;
|
| 1082 |
+
}
|
| 1083 |
+
|
| 1084 |
+
MessageQueue_Free(vcm->queue);
|
| 1085 |
+
free(vcm);
|
| 1086 |
+
}
|
| 1087 |
+
}
|
| 1088 |
+
|
| 1089 |
+
BOOL WINAPI FreeRDP_WTSEnumerateSessionsW(HANDLE hServer, DWORD Reserved, DWORD Version,
|
| 1090 |
+
PWTS_SESSION_INFOW* ppSessionInfo, DWORD* pCount)
|
| 1091 |
+
{
|
| 1092 |
+
return FALSE;
|
| 1093 |
+
}
|
| 1094 |
+
|
| 1095 |
+
BOOL WINAPI FreeRDP_WTSEnumerateSessionsA(HANDLE hServer, DWORD Reserved, DWORD Version,
|
| 1096 |
+
PWTS_SESSION_INFOA* ppSessionInfo, DWORD* pCount)
|
| 1097 |
+
{
|
| 1098 |
+
return FALSE;
|
| 1099 |
+
}
|
| 1100 |
+
|
| 1101 |
+
BOOL WINAPI FreeRDP_WTSEnumerateSessionsExW(HANDLE hServer, DWORD* pLevel, DWORD Filter,
|
| 1102 |
+
PWTS_SESSION_INFO_1W* ppSessionInfo, DWORD* pCount)
|
| 1103 |
+
{
|
| 1104 |
+
return FALSE;
|
| 1105 |
+
}
|
| 1106 |
+
|
| 1107 |
+
BOOL WINAPI FreeRDP_WTSEnumerateSessionsExA(HANDLE hServer, DWORD* pLevel, DWORD Filter,
|
| 1108 |
+
PWTS_SESSION_INFO_1A* ppSessionInfo, DWORD* pCount)
|
| 1109 |
+
{
|
| 1110 |
+
return FALSE;
|
| 1111 |
+
}
|
| 1112 |
+
|
| 1113 |
+
BOOL WINAPI FreeRDP_WTSEnumerateProcessesW(HANDLE hServer, DWORD Reserved, DWORD Version,
|
| 1114 |
+
PWTS_PROCESS_INFOW* ppProcessInfo, DWORD* pCount)
|
| 1115 |
+
{
|
| 1116 |
+
return FALSE;
|
| 1117 |
+
}
|
| 1118 |
+
|
| 1119 |
+
BOOL WINAPI FreeRDP_WTSEnumerateProcessesA(HANDLE hServer, DWORD Reserved, DWORD Version,
|
| 1120 |
+
PWTS_PROCESS_INFOA* ppProcessInfo, DWORD* pCount)
|
| 1121 |
+
{
|
| 1122 |
+
return FALSE;
|
| 1123 |
+
}
|
| 1124 |
+
|
| 1125 |
+
BOOL WINAPI FreeRDP_WTSTerminateProcess(HANDLE hServer, DWORD ProcessId, DWORD ExitCode)
|
| 1126 |
+
{
|
| 1127 |
+
return FALSE;
|
| 1128 |
+
}
|
| 1129 |
+
|
| 1130 |
+
BOOL WINAPI FreeRDP_WTSQuerySessionInformationW(HANDLE hServer, DWORD SessionId,
|
| 1131 |
+
WTS_INFO_CLASS WTSInfoClass, LPWSTR* ppBuffer,
|
| 1132 |
+
DWORD* pBytesReturned)
|
| 1133 |
+
{
|
| 1134 |
+
return FALSE;
|
| 1135 |
+
}
|
| 1136 |
+
|
| 1137 |
+
BOOL WINAPI FreeRDP_WTSQuerySessionInformationA(HANDLE hServer, DWORD SessionId,
|
| 1138 |
+
WTS_INFO_CLASS WTSInfoClass, LPSTR* ppBuffer,
|
| 1139 |
+
DWORD* pBytesReturned)
|
| 1140 |
+
{
|
| 1141 |
+
DWORD BytesReturned = 0;
|
| 1142 |
+
WTSVirtualChannelManager* vcm = NULL;
|
| 1143 |
+
vcm = (WTSVirtualChannelManager*)hServer;
|
| 1144 |
+
|
| 1145 |
+
if (!vcm)
|
| 1146 |
+
return FALSE;
|
| 1147 |
+
|
| 1148 |
+
if (WTSInfoClass == WTSSessionId)
|
| 1149 |
+
{
|
| 1150 |
+
ULONG* pBuffer = NULL;
|
| 1151 |
+
BytesReturned = sizeof(ULONG);
|
| 1152 |
+
pBuffer = (ULONG*)malloc(sizeof(BytesReturned));
|
| 1153 |
+
|
| 1154 |
+
if (!pBuffer)
|
| 1155 |
+
{
|
| 1156 |
+
SetLastError(E_OUTOFMEMORY);
|
| 1157 |
+
return FALSE;
|
| 1158 |
+
}
|
| 1159 |
+
|
| 1160 |
+
*pBuffer = vcm->SessionId;
|
| 1161 |
+
*ppBuffer = (LPSTR)pBuffer;
|
| 1162 |
+
*pBytesReturned = BytesReturned;
|
| 1163 |
+
return TRUE;
|
| 1164 |
+
}
|
| 1165 |
+
|
| 1166 |
+
return FALSE;
|
| 1167 |
+
}
|
| 1168 |
+
|
| 1169 |
+
BOOL WINAPI FreeRDP_WTSQueryUserConfigW(LPWSTR pServerName, LPWSTR pUserName,
|
| 1170 |
+
WTS_CONFIG_CLASS WTSConfigClass, LPWSTR* ppBuffer,
|
| 1171 |
+
DWORD* pBytesReturned)
|
| 1172 |
+
{
|
| 1173 |
+
return FALSE;
|
| 1174 |
+
}
|
| 1175 |
+
|
| 1176 |
+
BOOL WINAPI FreeRDP_WTSQueryUserConfigA(LPSTR pServerName, LPSTR pUserName,
|
| 1177 |
+
WTS_CONFIG_CLASS WTSConfigClass, LPSTR* ppBuffer,
|
| 1178 |
+
DWORD* pBytesReturned)
|
| 1179 |
+
{
|
| 1180 |
+
return FALSE;
|
| 1181 |
+
}
|
| 1182 |
+
|
| 1183 |
+
BOOL WINAPI FreeRDP_WTSSetUserConfigW(LPWSTR pServerName, LPWSTR pUserName,
|
| 1184 |
+
WTS_CONFIG_CLASS WTSConfigClass, LPWSTR pBuffer,
|
| 1185 |
+
DWORD DataLength)
|
| 1186 |
+
{
|
| 1187 |
+
return FALSE;
|
| 1188 |
+
}
|
| 1189 |
+
|
| 1190 |
+
BOOL WINAPI FreeRDP_WTSSetUserConfigA(LPSTR pServerName, LPSTR pUserName,
|
| 1191 |
+
WTS_CONFIG_CLASS WTSConfigClass, LPSTR pBuffer,
|
| 1192 |
+
DWORD DataLength)
|
| 1193 |
+
{
|
| 1194 |
+
return FALSE;
|
| 1195 |
+
}
|
| 1196 |
+
|
| 1197 |
+
BOOL WINAPI FreeRDP_WTSSendMessageW(HANDLE hServer, DWORD SessionId, LPWSTR pTitle,
|
| 1198 |
+
DWORD TitleLength, LPWSTR pMessage, DWORD MessageLength,
|
| 1199 |
+
DWORD Style, DWORD Timeout, DWORD* pResponse, BOOL bWait)
|
| 1200 |
+
{
|
| 1201 |
+
return FALSE;
|
| 1202 |
+
}
|
| 1203 |
+
|
| 1204 |
+
BOOL WINAPI FreeRDP_WTSSendMessageA(HANDLE hServer, DWORD SessionId, LPSTR pTitle,
|
| 1205 |
+
DWORD TitleLength, LPSTR pMessage, DWORD MessageLength,
|
| 1206 |
+
DWORD Style, DWORD Timeout, DWORD* pResponse, BOOL bWait)
|
| 1207 |
+
{
|
| 1208 |
+
return FALSE;
|
| 1209 |
+
}
|
| 1210 |
+
|
| 1211 |
+
BOOL WINAPI FreeRDP_WTSDisconnectSession(HANDLE hServer, DWORD SessionId, BOOL bWait)
|
| 1212 |
+
{
|
| 1213 |
+
return FALSE;
|
| 1214 |
+
}
|
| 1215 |
+
|
| 1216 |
+
BOOL WINAPI FreeRDP_WTSLogoffSession(HANDLE hServer, DWORD SessionId, BOOL bWait)
|
| 1217 |
+
{
|
| 1218 |
+
return FALSE;
|
| 1219 |
+
}
|
| 1220 |
+
|
| 1221 |
+
BOOL WINAPI FreeRDP_WTSShutdownSystem(HANDLE hServer, DWORD ShutdownFlag)
|
| 1222 |
+
{
|
| 1223 |
+
return FALSE;
|
| 1224 |
+
}
|
| 1225 |
+
|
| 1226 |
+
BOOL WINAPI FreeRDP_WTSWaitSystemEvent(HANDLE hServer, DWORD EventMask, DWORD* pEventFlags)
|
| 1227 |
+
{
|
| 1228 |
+
return FALSE;
|
| 1229 |
+
}
|
| 1230 |
+
|
| 1231 |
+
static void peer_channel_queue_free_message(void* obj)
|
| 1232 |
+
{
|
| 1233 |
+
wMessage* msg = (wMessage*)obj;
|
| 1234 |
+
if (!msg)
|
| 1235 |
+
return;
|
| 1236 |
+
|
| 1237 |
+
free(msg->context);
|
| 1238 |
+
msg->context = NULL;
|
| 1239 |
+
}
|
| 1240 |
+
|
| 1241 |
+
static rdpPeerChannel* channel_new(WTSVirtualChannelManager* vcm, freerdp_peer* client,
|
| 1242 |
+
UINT32 ChannelId, UINT16 index, UINT16 type, size_t chunkSize,
|
| 1243 |
+
const char* name)
|
| 1244 |
+
{
|
| 1245 |
+
wObject queueCallbacks = { 0 };
|
| 1246 |
+
queueCallbacks.fnObjectFree = peer_channel_queue_free_message;
|
| 1247 |
+
|
| 1248 |
+
rdpPeerChannel* channel =
|
| 1249 |
+
server_channel_common_new(client, index, ChannelId, chunkSize, &queueCallbacks, name);
|
| 1250 |
+
|
| 1251 |
+
WINPR_ASSERT(vcm);
|
| 1252 |
+
WINPR_ASSERT(client);
|
| 1253 |
+
|
| 1254 |
+
if (!channel)
|
| 1255 |
+
goto fail;
|
| 1256 |
+
|
| 1257 |
+
channel->vcm = vcm;
|
| 1258 |
+
channel->channelType = type;
|
| 1259 |
+
channel->creationStatus =
|
| 1260 |
+
(type == RDP_PEER_CHANNEL_TYPE_SVC) ? ERROR_SUCCESS : ERROR_OPERATION_IN_PROGRESS;
|
| 1261 |
+
|
| 1262 |
+
return channel;
|
| 1263 |
+
fail:
|
| 1264 |
+
channel_free(channel);
|
| 1265 |
+
return NULL;
|
| 1266 |
+
}
|
| 1267 |
+
|
| 1268 |
+
HANDLE WINAPI FreeRDP_WTSVirtualChannelOpen(HANDLE hServer, DWORD SessionId, LPSTR pVirtualName)
|
| 1269 |
+
{
|
| 1270 |
+
size_t length = 0;
|
| 1271 |
+
rdpMcs* mcs = NULL;
|
| 1272 |
+
rdpMcsChannel* joined_channel = NULL;
|
| 1273 |
+
freerdp_peer* client = NULL;
|
| 1274 |
+
rdpPeerChannel* channel = NULL;
|
| 1275 |
+
WTSVirtualChannelManager* vcm = NULL;
|
| 1276 |
+
HANDLE hChannelHandle = NULL;
|
| 1277 |
+
rdpContext* context = NULL;
|
| 1278 |
+
vcm = (WTSVirtualChannelManager*)hServer;
|
| 1279 |
+
|
| 1280 |
+
if (!vcm)
|
| 1281 |
+
{
|
| 1282 |
+
SetLastError(ERROR_INVALID_DATA);
|
| 1283 |
+
return NULL;
|
| 1284 |
+
}
|
| 1285 |
+
|
| 1286 |
+
client = vcm->client;
|
| 1287 |
+
WINPR_ASSERT(client);
|
| 1288 |
+
|
| 1289 |
+
context = client->context;
|
| 1290 |
+
WINPR_ASSERT(context);
|
| 1291 |
+
WINPR_ASSERT(context->rdp);
|
| 1292 |
+
WINPR_ASSERT(context->settings);
|
| 1293 |
+
|
| 1294 |
+
mcs = context->rdp->mcs;
|
| 1295 |
+
WINPR_ASSERT(mcs);
|
| 1296 |
+
|
| 1297 |
+
length = strnlen(pVirtualName, CHANNEL_NAME_LEN + 1);
|
| 1298 |
+
|
| 1299 |
+
if (length > CHANNEL_NAME_LEN)
|
| 1300 |
+
{
|
| 1301 |
+
SetLastError(ERROR_NOT_FOUND);
|
| 1302 |
+
return NULL;
|
| 1303 |
+
}
|
| 1304 |
+
|
| 1305 |
+
UINT32 index = 0;
|
| 1306 |
+
for (; index < mcs->channelCount; index++)
|
| 1307 |
+
{
|
| 1308 |
+
rdpMcsChannel* mchannel = &mcs->channels[index];
|
| 1309 |
+
if (mchannel->joined && (strncmp(mchannel->Name, pVirtualName, length) == 0))
|
| 1310 |
+
{
|
| 1311 |
+
joined_channel = mchannel;
|
| 1312 |
+
break;
|
| 1313 |
+
}
|
| 1314 |
+
}
|
| 1315 |
+
|
| 1316 |
+
if (!joined_channel)
|
| 1317 |
+
{
|
| 1318 |
+
SetLastError(ERROR_NOT_FOUND);
|
| 1319 |
+
return NULL;
|
| 1320 |
+
}
|
| 1321 |
+
|
| 1322 |
+
channel = (rdpPeerChannel*)joined_channel->handle;
|
| 1323 |
+
|
| 1324 |
+
if (!channel)
|
| 1325 |
+
{
|
| 1326 |
+
const UINT32 VCChunkSize =
|
| 1327 |
+
freerdp_settings_get_uint32(context->settings, FreeRDP_VCChunkSize);
|
| 1328 |
+
|
| 1329 |
+
WINPR_ASSERT(index <= UINT16_MAX);
|
| 1330 |
+
channel = channel_new(vcm, client, joined_channel->ChannelId, (UINT16)index,
|
| 1331 |
+
RDP_PEER_CHANNEL_TYPE_SVC, VCChunkSize, pVirtualName);
|
| 1332 |
+
|
| 1333 |
+
if (!channel)
|
| 1334 |
+
goto fail;
|
| 1335 |
+
|
| 1336 |
+
joined_channel->handle = channel;
|
| 1337 |
+
}
|
| 1338 |
+
|
| 1339 |
+
hChannelHandle = (HANDLE)channel;
|
| 1340 |
+
return hChannelHandle;
|
| 1341 |
+
fail:
|
| 1342 |
+
channel_free(channel);
|
| 1343 |
+
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
| 1344 |
+
return NULL;
|
| 1345 |
+
}
|
| 1346 |
+
|
| 1347 |
+
HANDLE WINAPI FreeRDP_WTSVirtualChannelOpenEx(DWORD SessionId, LPSTR pVirtualName, DWORD flags)
|
| 1348 |
+
{
|
| 1349 |
+
wStream* s = NULL;
|
| 1350 |
+
rdpMcs* mcs = NULL;
|
| 1351 |
+
BOOL joined = FALSE;
|
| 1352 |
+
freerdp_peer* client = NULL;
|
| 1353 |
+
rdpPeerChannel* channel = NULL;
|
| 1354 |
+
ULONG written = 0;
|
| 1355 |
+
WTSVirtualChannelManager* vcm = NULL;
|
| 1356 |
+
|
| 1357 |
+
if (SessionId == WTS_CURRENT_SESSION)
|
| 1358 |
+
return NULL;
|
| 1359 |
+
|
| 1360 |
+
vcm = (WTSVirtualChannelManager*)HashTable_GetItemValue(g_ServerHandles,
|
| 1361 |
+
(void*)(UINT_PTR)SessionId);
|
| 1362 |
+
|
| 1363 |
+
if (!vcm)
|
| 1364 |
+
return NULL;
|
| 1365 |
+
|
| 1366 |
+
if (!(flags & WTS_CHANNEL_OPTION_DYNAMIC))
|
| 1367 |
+
{
|
| 1368 |
+
return FreeRDP_WTSVirtualChannelOpen((HANDLE)vcm, SessionId, pVirtualName);
|
| 1369 |
+
}
|
| 1370 |
+
|
| 1371 |
+
client = vcm->client;
|
| 1372 |
+
mcs = client->context->rdp->mcs;
|
| 1373 |
+
|
| 1374 |
+
for (UINT32 index = 0; index < mcs->channelCount; index++)
|
| 1375 |
+
{
|
| 1376 |
+
rdpMcsChannel* mchannel = &mcs->channels[index];
|
| 1377 |
+
if (mchannel->joined &&
|
| 1378 |
+
(strncmp(mchannel->Name, DRDYNVC_SVC_CHANNEL_NAME, CHANNEL_NAME_LEN + 1) == 0))
|
| 1379 |
+
{
|
| 1380 |
+
joined = TRUE;
|
| 1381 |
+
break;
|
| 1382 |
+
}
|
| 1383 |
+
}
|
| 1384 |
+
|
| 1385 |
+
if (!joined)
|
| 1386 |
+
{
|
| 1387 |
+
SetLastError(ERROR_NOT_FOUND);
|
| 1388 |
+
return NULL;
|
| 1389 |
+
}
|
| 1390 |
+
|
| 1391 |
+
if (!vcm->drdynvc_channel || (vcm->drdynvc_state != DRDYNVC_STATE_READY))
|
| 1392 |
+
{
|
| 1393 |
+
SetLastError(ERROR_NOT_READY);
|
| 1394 |
+
return NULL;
|
| 1395 |
+
}
|
| 1396 |
+
|
| 1397 |
+
WINPR_ASSERT(client);
|
| 1398 |
+
WINPR_ASSERT(client->context);
|
| 1399 |
+
WINPR_ASSERT(client->context->settings);
|
| 1400 |
+
|
| 1401 |
+
const UINT32 VCChunkSize =
|
| 1402 |
+
freerdp_settings_get_uint32(client->context->settings, FreeRDP_VCChunkSize);
|
| 1403 |
+
channel = channel_new(vcm, client, 0, 0, RDP_PEER_CHANNEL_TYPE_DVC, VCChunkSize, pVirtualName);
|
| 1404 |
+
|
| 1405 |
+
if (!channel)
|
| 1406 |
+
{
|
| 1407 |
+
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
| 1408 |
+
return NULL;
|
| 1409 |
+
}
|
| 1410 |
+
|
| 1411 |
+
const LONG hdl = InterlockedIncrement(&vcm->dvc_channel_id_seq);
|
| 1412 |
+
channel->channelId = WINPR_ASSERTING_INT_CAST(uint32_t, hdl);
|
| 1413 |
+
|
| 1414 |
+
if (!HashTable_Insert(vcm->dynamicVirtualChannels, &channel->channelId, channel))
|
| 1415 |
+
{
|
| 1416 |
+
channel_free(channel);
|
| 1417 |
+
channel = NULL;
|
| 1418 |
+
goto fail;
|
| 1419 |
+
}
|
| 1420 |
+
s = Stream_New(NULL, 64);
|
| 1421 |
+
|
| 1422 |
+
if (!s)
|
| 1423 |
+
goto fail;
|
| 1424 |
+
|
| 1425 |
+
if (!wts_write_drdynvc_create_request(s, channel->channelId, pVirtualName))
|
| 1426 |
+
goto fail;
|
| 1427 |
+
|
| 1428 |
+
const size_t pos = Stream_GetPosition(s);
|
| 1429 |
+
WINPR_ASSERT(pos <= UINT32_MAX);
|
| 1430 |
+
if (!WTSVirtualChannelWrite(vcm->drdynvc_channel, Stream_BufferAs(s, char), (UINT32)pos,
|
| 1431 |
+
&written))
|
| 1432 |
+
goto fail;
|
| 1433 |
+
|
| 1434 |
+
Stream_Free(s, TRUE);
|
| 1435 |
+
return channel;
|
| 1436 |
+
fail:
|
| 1437 |
+
Stream_Free(s, TRUE);
|
| 1438 |
+
if (channel)
|
| 1439 |
+
HashTable_Remove(vcm->dynamicVirtualChannels, &channel->channelId);
|
| 1440 |
+
|
| 1441 |
+
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
| 1442 |
+
return NULL;
|
| 1443 |
+
}
|
| 1444 |
+
|
| 1445 |
+
BOOL WINAPI FreeRDP_WTSVirtualChannelClose(HANDLE hChannelHandle)
|
| 1446 |
+
{
|
| 1447 |
+
wStream* s = NULL;
|
| 1448 |
+
rdpMcs* mcs = NULL;
|
| 1449 |
+
|
| 1450 |
+
rdpPeerChannel* channel = (rdpPeerChannel*)hChannelHandle;
|
| 1451 |
+
BOOL ret = TRUE;
|
| 1452 |
+
|
| 1453 |
+
if (channel)
|
| 1454 |
+
{
|
| 1455 |
+
WTSVirtualChannelManager* vcm = channel->vcm;
|
| 1456 |
+
|
| 1457 |
+
WINPR_ASSERT(vcm);
|
| 1458 |
+
WINPR_ASSERT(vcm->client);
|
| 1459 |
+
WINPR_ASSERT(vcm->client->context);
|
| 1460 |
+
WINPR_ASSERT(vcm->client->context->rdp);
|
| 1461 |
+
mcs = vcm->client->context->rdp->mcs;
|
| 1462 |
+
|
| 1463 |
+
if (channel->channelType == RDP_PEER_CHANNEL_TYPE_SVC)
|
| 1464 |
+
{
|
| 1465 |
+
if (channel->index < mcs->channelCount)
|
| 1466 |
+
{
|
| 1467 |
+
rdpMcsChannel* cur = &mcs->channels[channel->index];
|
| 1468 |
+
rdpPeerChannel* peerChannel = (rdpPeerChannel*)cur->handle;
|
| 1469 |
+
channel_free(peerChannel);
|
| 1470 |
+
cur->handle = NULL;
|
| 1471 |
+
}
|
| 1472 |
+
}
|
| 1473 |
+
else
|
| 1474 |
+
{
|
| 1475 |
+
if (channel->dvc_open_state == DVC_OPEN_STATE_SUCCEEDED)
|
| 1476 |
+
{
|
| 1477 |
+
ULONG written = 0;
|
| 1478 |
+
s = Stream_New(NULL, 8);
|
| 1479 |
+
|
| 1480 |
+
if (!s)
|
| 1481 |
+
{
|
| 1482 |
+
WLog_ERR(TAG, "Stream_New failed!");
|
| 1483 |
+
ret = FALSE;
|
| 1484 |
+
}
|
| 1485 |
+
else
|
| 1486 |
+
{
|
| 1487 |
+
wts_write_drdynvc_header(s, CLOSE_REQUEST_PDU, channel->channelId);
|
| 1488 |
+
|
| 1489 |
+
const size_t pos = Stream_GetPosition(s);
|
| 1490 |
+
WINPR_ASSERT(pos <= UINT32_MAX);
|
| 1491 |
+
ret = WTSVirtualChannelWrite(vcm->drdynvc_channel, Stream_BufferAs(s, char),
|
| 1492 |
+
(UINT32)pos, &written);
|
| 1493 |
+
Stream_Free(s, TRUE);
|
| 1494 |
+
}
|
| 1495 |
+
}
|
| 1496 |
+
HashTable_Remove(vcm->dynamicVirtualChannels, &channel->channelId);
|
| 1497 |
+
}
|
| 1498 |
+
}
|
| 1499 |
+
|
| 1500 |
+
return ret;
|
| 1501 |
+
}
|
| 1502 |
+
|
| 1503 |
+
BOOL WINAPI FreeRDP_WTSVirtualChannelRead(HANDLE hChannelHandle, ULONG TimeOut, PCHAR Buffer,
|
| 1504 |
+
ULONG BufferSize, PULONG pBytesRead)
|
| 1505 |
+
{
|
| 1506 |
+
BYTE* buffer = NULL;
|
| 1507 |
+
wMessage message = { 0 };
|
| 1508 |
+
wtsChannelMessage* messageCtx = NULL;
|
| 1509 |
+
rdpPeerChannel* channel = (rdpPeerChannel*)hChannelHandle;
|
| 1510 |
+
|
| 1511 |
+
WINPR_ASSERT(channel);
|
| 1512 |
+
|
| 1513 |
+
if (!MessageQueue_Peek(channel->queue, &message, FALSE))
|
| 1514 |
+
{
|
| 1515 |
+
SetLastError(ERROR_NO_DATA);
|
| 1516 |
+
*pBytesRead = 0;
|
| 1517 |
+
return FALSE;
|
| 1518 |
+
}
|
| 1519 |
+
|
| 1520 |
+
messageCtx = message.context;
|
| 1521 |
+
|
| 1522 |
+
if (messageCtx == NULL)
|
| 1523 |
+
return FALSE;
|
| 1524 |
+
|
| 1525 |
+
buffer = (BYTE*)(messageCtx + 1);
|
| 1526 |
+
*pBytesRead = messageCtx->length - messageCtx->offset;
|
| 1527 |
+
|
| 1528 |
+
if (Buffer == NULL || BufferSize == 0)
|
| 1529 |
+
{
|
| 1530 |
+
return TRUE;
|
| 1531 |
+
}
|
| 1532 |
+
|
| 1533 |
+
if (*pBytesRead > BufferSize)
|
| 1534 |
+
*pBytesRead = BufferSize;
|
| 1535 |
+
|
| 1536 |
+
CopyMemory(Buffer, buffer + messageCtx->offset, *pBytesRead);
|
| 1537 |
+
messageCtx->offset += *pBytesRead;
|
| 1538 |
+
|
| 1539 |
+
if (messageCtx->offset >= messageCtx->length)
|
| 1540 |
+
{
|
| 1541 |
+
(void)MessageQueue_Peek(channel->queue, &message, TRUE);
|
| 1542 |
+
peer_channel_queue_free_message(&message);
|
| 1543 |
+
}
|
| 1544 |
+
|
| 1545 |
+
return TRUE;
|
| 1546 |
+
}
|
| 1547 |
+
|
| 1548 |
+
BOOL WINAPI FreeRDP_WTSVirtualChannelWrite(HANDLE hChannelHandle, PCHAR Buffer, ULONG Length,
|
| 1549 |
+
PULONG pBytesWritten)
|
| 1550 |
+
{
|
| 1551 |
+
wStream* s = NULL;
|
| 1552 |
+
int cbLen = 0;
|
| 1553 |
+
int cbChId = 0;
|
| 1554 |
+
int first = 0;
|
| 1555 |
+
BYTE* buffer = NULL;
|
| 1556 |
+
UINT32 totalWritten = 0;
|
| 1557 |
+
rdpPeerChannel* channel = (rdpPeerChannel*)hChannelHandle;
|
| 1558 |
+
BOOL ret = FALSE;
|
| 1559 |
+
|
| 1560 |
+
if (!channel)
|
| 1561 |
+
return FALSE;
|
| 1562 |
+
|
| 1563 |
+
EnterCriticalSection(&channel->writeLock);
|
| 1564 |
+
WINPR_ASSERT(channel->vcm);
|
| 1565 |
+
if (channel->channelType == RDP_PEER_CHANNEL_TYPE_SVC)
|
| 1566 |
+
{
|
| 1567 |
+
const ULONG length = Length;
|
| 1568 |
+
buffer = (BYTE*)malloc(length);
|
| 1569 |
+
|
| 1570 |
+
if (!buffer)
|
| 1571 |
+
{
|
| 1572 |
+
SetLastError(E_OUTOFMEMORY);
|
| 1573 |
+
goto fail;
|
| 1574 |
+
}
|
| 1575 |
+
|
| 1576 |
+
CopyMemory(buffer, Buffer, length);
|
| 1577 |
+
totalWritten = Length;
|
| 1578 |
+
if (!wts_queue_send_item(channel, buffer, length))
|
| 1579 |
+
goto fail;
|
| 1580 |
+
}
|
| 1581 |
+
else if (!channel->vcm->drdynvc_channel || (channel->vcm->drdynvc_state != DRDYNVC_STATE_READY))
|
| 1582 |
+
{
|
| 1583 |
+
DEBUG_DVC("drdynvc not ready");
|
| 1584 |
+
goto fail;
|
| 1585 |
+
}
|
| 1586 |
+
else
|
| 1587 |
+
{
|
| 1588 |
+
rdpContext* context = NULL;
|
| 1589 |
+
|
| 1590 |
+
first = TRUE;
|
| 1591 |
+
WINPR_ASSERT(channel->client);
|
| 1592 |
+
context = channel->client->context;
|
| 1593 |
+
WINPR_ASSERT(context);
|
| 1594 |
+
while (Length > 0)
|
| 1595 |
+
{
|
| 1596 |
+
s = Stream_New(NULL, DVC_MAX_DATA_PDU_SIZE);
|
| 1597 |
+
|
| 1598 |
+
if (!s)
|
| 1599 |
+
{
|
| 1600 |
+
WLog_ERR(TAG, "Stream_New failed!");
|
| 1601 |
+
SetLastError(E_OUTOFMEMORY);
|
| 1602 |
+
goto fail;
|
| 1603 |
+
}
|
| 1604 |
+
|
| 1605 |
+
buffer = Stream_Buffer(s);
|
| 1606 |
+
Stream_Seek_UINT8(s);
|
| 1607 |
+
cbChId = wts_write_variable_uint(s, channel->channelId);
|
| 1608 |
+
|
| 1609 |
+
if (first && (Length > Stream_GetRemainingLength(s)))
|
| 1610 |
+
{
|
| 1611 |
+
cbLen = wts_write_variable_uint(s, Length);
|
| 1612 |
+
buffer[0] = ((DATA_FIRST_PDU << 4) | (cbLen << 2) | cbChId) & 0xFF;
|
| 1613 |
+
}
|
| 1614 |
+
else
|
| 1615 |
+
{
|
| 1616 |
+
buffer[0] = ((DATA_PDU << 4) | cbChId) & 0xFF;
|
| 1617 |
+
}
|
| 1618 |
+
|
| 1619 |
+
first = FALSE;
|
| 1620 |
+
size_t written = Stream_GetRemainingLength(s);
|
| 1621 |
+
|
| 1622 |
+
if (written > Length)
|
| 1623 |
+
written = Length;
|
| 1624 |
+
|
| 1625 |
+
Stream_Write(s, Buffer, written);
|
| 1626 |
+
const size_t length = Stream_GetPosition(s);
|
| 1627 |
+
Stream_Free(s, FALSE);
|
| 1628 |
+
if (length > UINT32_MAX)
|
| 1629 |
+
goto fail;
|
| 1630 |
+
Length -= written;
|
| 1631 |
+
Buffer += written;
|
| 1632 |
+
totalWritten += written;
|
| 1633 |
+
if (!wts_queue_send_item(channel->vcm->drdynvc_channel, buffer, (UINT32)length))
|
| 1634 |
+
goto fail;
|
| 1635 |
+
}
|
| 1636 |
+
}
|
| 1637 |
+
|
| 1638 |
+
if (pBytesWritten)
|
| 1639 |
+
*pBytesWritten = totalWritten;
|
| 1640 |
+
|
| 1641 |
+
ret = TRUE;
|
| 1642 |
+
fail:
|
| 1643 |
+
LeaveCriticalSection(&channel->writeLock);
|
| 1644 |
+
return ret;
|
| 1645 |
+
}
|
| 1646 |
+
|
| 1647 |
+
BOOL WINAPI FreeRDP_WTSVirtualChannelPurgeInput(HANDLE hChannelHandle)
|
| 1648 |
+
{
|
| 1649 |
+
return TRUE;
|
| 1650 |
+
}
|
| 1651 |
+
|
| 1652 |
+
BOOL WINAPI FreeRDP_WTSVirtualChannelPurgeOutput(HANDLE hChannelHandle)
|
| 1653 |
+
{
|
| 1654 |
+
return TRUE;
|
| 1655 |
+
}
|
| 1656 |
+
|
| 1657 |
+
BOOL WINAPI FreeRDP_WTSVirtualChannelQuery(HANDLE hChannelHandle, WTS_VIRTUAL_CLASS WtsVirtualClass,
|
| 1658 |
+
PVOID* ppBuffer, DWORD* pBytesReturned)
|
| 1659 |
+
{
|
| 1660 |
+
void* pfd = NULL;
|
| 1661 |
+
BOOL bval = 0;
|
| 1662 |
+
void* fds[10] = { 0 };
|
| 1663 |
+
HANDLE hEvent = NULL;
|
| 1664 |
+
int fds_count = 0;
|
| 1665 |
+
BOOL status = FALSE;
|
| 1666 |
+
rdpPeerChannel* channel = (rdpPeerChannel*)hChannelHandle;
|
| 1667 |
+
|
| 1668 |
+
WINPR_ASSERT(channel);
|
| 1669 |
+
|
| 1670 |
+
switch ((UINT32)WtsVirtualClass)
|
| 1671 |
+
{
|
| 1672 |
+
case WTSVirtualFileHandle:
|
| 1673 |
+
hEvent = MessageQueue_Event(channel->queue);
|
| 1674 |
+
pfd = GetEventWaitObject(hEvent);
|
| 1675 |
+
|
| 1676 |
+
if (pfd)
|
| 1677 |
+
{
|
| 1678 |
+
fds[fds_count] = pfd;
|
| 1679 |
+
(fds_count)++;
|
| 1680 |
+
}
|
| 1681 |
+
|
| 1682 |
+
*ppBuffer = malloc(sizeof(void*));
|
| 1683 |
+
|
| 1684 |
+
if (!*ppBuffer)
|
| 1685 |
+
{
|
| 1686 |
+
SetLastError(E_OUTOFMEMORY);
|
| 1687 |
+
}
|
| 1688 |
+
else
|
| 1689 |
+
{
|
| 1690 |
+
CopyMemory(*ppBuffer, (void*)&fds[0], sizeof(void*));
|
| 1691 |
+
*pBytesReturned = sizeof(void*);
|
| 1692 |
+
status = TRUE;
|
| 1693 |
+
}
|
| 1694 |
+
|
| 1695 |
+
break;
|
| 1696 |
+
|
| 1697 |
+
case WTSVirtualEventHandle:
|
| 1698 |
+
hEvent = MessageQueue_Event(channel->queue);
|
| 1699 |
+
|
| 1700 |
+
*ppBuffer = malloc(sizeof(HANDLE));
|
| 1701 |
+
|
| 1702 |
+
if (!*ppBuffer)
|
| 1703 |
+
{
|
| 1704 |
+
SetLastError(E_OUTOFMEMORY);
|
| 1705 |
+
}
|
| 1706 |
+
else
|
| 1707 |
+
{
|
| 1708 |
+
CopyMemory(*ppBuffer, (void*)&hEvent, sizeof(HANDLE));
|
| 1709 |
+
*pBytesReturned = sizeof(void*);
|
| 1710 |
+
status = TRUE;
|
| 1711 |
+
}
|
| 1712 |
+
|
| 1713 |
+
break;
|
| 1714 |
+
|
| 1715 |
+
case WTSVirtualChannelReady:
|
| 1716 |
+
if (channel->channelType == RDP_PEER_CHANNEL_TYPE_SVC)
|
| 1717 |
+
{
|
| 1718 |
+
bval = TRUE;
|
| 1719 |
+
status = TRUE;
|
| 1720 |
+
}
|
| 1721 |
+
else
|
| 1722 |
+
{
|
| 1723 |
+
switch (channel->dvc_open_state)
|
| 1724 |
+
{
|
| 1725 |
+
case DVC_OPEN_STATE_NONE:
|
| 1726 |
+
bval = FALSE;
|
| 1727 |
+
status = TRUE;
|
| 1728 |
+
break;
|
| 1729 |
+
|
| 1730 |
+
case DVC_OPEN_STATE_SUCCEEDED:
|
| 1731 |
+
bval = TRUE;
|
| 1732 |
+
status = TRUE;
|
| 1733 |
+
break;
|
| 1734 |
+
|
| 1735 |
+
default:
|
| 1736 |
+
*ppBuffer = NULL;
|
| 1737 |
+
*pBytesReturned = 0;
|
| 1738 |
+
return FALSE;
|
| 1739 |
+
}
|
| 1740 |
+
}
|
| 1741 |
+
|
| 1742 |
+
*ppBuffer = malloc(sizeof(BOOL));
|
| 1743 |
+
|
| 1744 |
+
if (!*ppBuffer)
|
| 1745 |
+
{
|
| 1746 |
+
SetLastError(E_OUTOFMEMORY);
|
| 1747 |
+
status = FALSE;
|
| 1748 |
+
}
|
| 1749 |
+
else
|
| 1750 |
+
{
|
| 1751 |
+
CopyMemory(*ppBuffer, &bval, sizeof(BOOL));
|
| 1752 |
+
*pBytesReturned = sizeof(BOOL);
|
| 1753 |
+
}
|
| 1754 |
+
|
| 1755 |
+
break;
|
| 1756 |
+
case WTSVirtualChannelOpenStatus:
|
| 1757 |
+
{
|
| 1758 |
+
INT32 value = channel->creationStatus;
|
| 1759 |
+
status = TRUE;
|
| 1760 |
+
|
| 1761 |
+
*ppBuffer = malloc(sizeof(value));
|
| 1762 |
+
if (!*ppBuffer)
|
| 1763 |
+
{
|
| 1764 |
+
SetLastError(E_OUTOFMEMORY);
|
| 1765 |
+
status = FALSE;
|
| 1766 |
+
}
|
| 1767 |
+
else
|
| 1768 |
+
{
|
| 1769 |
+
CopyMemory(*ppBuffer, &value, sizeof(value));
|
| 1770 |
+
*pBytesReturned = sizeof(value);
|
| 1771 |
+
}
|
| 1772 |
+
break;
|
| 1773 |
+
}
|
| 1774 |
+
default:
|
| 1775 |
+
break;
|
| 1776 |
+
}
|
| 1777 |
+
|
| 1778 |
+
return status;
|
| 1779 |
+
}
|
| 1780 |
+
|
| 1781 |
+
VOID WINAPI FreeRDP_WTSFreeMemory(PVOID pMemory)
|
| 1782 |
+
{
|
| 1783 |
+
free(pMemory);
|
| 1784 |
+
}
|
| 1785 |
+
|
| 1786 |
+
BOOL WINAPI FreeRDP_WTSFreeMemoryExW(WTS_TYPE_CLASS WTSTypeClass, PVOID pMemory,
|
| 1787 |
+
ULONG NumberOfEntries)
|
| 1788 |
+
{
|
| 1789 |
+
return FALSE;
|
| 1790 |
+
}
|
| 1791 |
+
|
| 1792 |
+
BOOL WINAPI FreeRDP_WTSFreeMemoryExA(WTS_TYPE_CLASS WTSTypeClass, PVOID pMemory,
|
| 1793 |
+
ULONG NumberOfEntries)
|
| 1794 |
+
{
|
| 1795 |
+
return FALSE;
|
| 1796 |
+
}
|
| 1797 |
+
|
| 1798 |
+
BOOL WINAPI FreeRDP_WTSRegisterSessionNotification(HWND hWnd, DWORD dwFlags)
|
| 1799 |
+
{
|
| 1800 |
+
return FALSE;
|
| 1801 |
+
}
|
| 1802 |
+
|
| 1803 |
+
BOOL WINAPI FreeRDP_WTSUnRegisterSessionNotification(HWND hWnd)
|
| 1804 |
+
{
|
| 1805 |
+
return FALSE;
|
| 1806 |
+
}
|
| 1807 |
+
|
| 1808 |
+
BOOL WINAPI FreeRDP_WTSRegisterSessionNotificationEx(HANDLE hServer, HWND hWnd, DWORD dwFlags)
|
| 1809 |
+
{
|
| 1810 |
+
return FALSE;
|
| 1811 |
+
}
|
| 1812 |
+
|
| 1813 |
+
BOOL WINAPI FreeRDP_WTSUnRegisterSessionNotificationEx(HANDLE hServer, HWND hWnd)
|
| 1814 |
+
{
|
| 1815 |
+
return FALSE;
|
| 1816 |
+
}
|
| 1817 |
+
|
| 1818 |
+
BOOL WINAPI FreeRDP_WTSQueryUserToken(ULONG SessionId, PHANDLE phToken)
|
| 1819 |
+
{
|
| 1820 |
+
return FALSE;
|
| 1821 |
+
}
|
| 1822 |
+
|
| 1823 |
+
BOOL WINAPI FreeRDP_WTSEnumerateProcessesExW(HANDLE hServer, DWORD* pLevel, DWORD SessionId,
|
| 1824 |
+
LPWSTR* ppProcessInfo, DWORD* pCount)
|
| 1825 |
+
{
|
| 1826 |
+
return FALSE;
|
| 1827 |
+
}
|
| 1828 |
+
|
| 1829 |
+
BOOL WINAPI FreeRDP_WTSEnumerateProcessesExA(HANDLE hServer, DWORD* pLevel, DWORD SessionId,
|
| 1830 |
+
LPSTR* ppProcessInfo, DWORD* pCount)
|
| 1831 |
+
{
|
| 1832 |
+
return FALSE;
|
| 1833 |
+
}
|
| 1834 |
+
|
| 1835 |
+
BOOL WINAPI FreeRDP_WTSEnumerateListenersW(HANDLE hServer, PVOID pReserved, DWORD Reserved,
|
| 1836 |
+
PWTSLISTENERNAMEW pListeners, DWORD* pCount)
|
| 1837 |
+
{
|
| 1838 |
+
return FALSE;
|
| 1839 |
+
}
|
| 1840 |
+
|
| 1841 |
+
BOOL WINAPI FreeRDP_WTSEnumerateListenersA(HANDLE hServer, PVOID pReserved, DWORD Reserved,
|
| 1842 |
+
PWTSLISTENERNAMEA pListeners, DWORD* pCount)
|
| 1843 |
+
{
|
| 1844 |
+
return FALSE;
|
| 1845 |
+
}
|
| 1846 |
+
|
| 1847 |
+
BOOL WINAPI FreeRDP_WTSQueryListenerConfigW(HANDLE hServer, PVOID pReserved, DWORD Reserved,
|
| 1848 |
+
LPWSTR pListenerName, PWTSLISTENERCONFIGW pBuffer)
|
| 1849 |
+
{
|
| 1850 |
+
return FALSE;
|
| 1851 |
+
}
|
| 1852 |
+
|
| 1853 |
+
BOOL WINAPI FreeRDP_WTSQueryListenerConfigA(HANDLE hServer, PVOID pReserved, DWORD Reserved,
|
| 1854 |
+
LPSTR pListenerName, PWTSLISTENERCONFIGA pBuffer)
|
| 1855 |
+
{
|
| 1856 |
+
return FALSE;
|
| 1857 |
+
}
|
| 1858 |
+
|
| 1859 |
+
BOOL WINAPI FreeRDP_WTSCreateListenerW(HANDLE hServer, PVOID pReserved, DWORD Reserved,
|
| 1860 |
+
LPWSTR pListenerName, PWTSLISTENERCONFIGW pBuffer,
|
| 1861 |
+
DWORD flag)
|
| 1862 |
+
{
|
| 1863 |
+
return FALSE;
|
| 1864 |
+
}
|
| 1865 |
+
|
| 1866 |
+
BOOL WINAPI FreeRDP_WTSCreateListenerA(HANDLE hServer, PVOID pReserved, DWORD Reserved,
|
| 1867 |
+
LPSTR pListenerName, PWTSLISTENERCONFIGA pBuffer, DWORD flag)
|
| 1868 |
+
{
|
| 1869 |
+
return FALSE;
|
| 1870 |
+
}
|
| 1871 |
+
|
| 1872 |
+
BOOL WINAPI FreeRDP_WTSSetListenerSecurityW(HANDLE hServer, PVOID pReserved, DWORD Reserved,
|
| 1873 |
+
LPWSTR pListenerName,
|
| 1874 |
+
SECURITY_INFORMATION SecurityInformation,
|
| 1875 |
+
PSECURITY_DESCRIPTOR pSecurityDescriptor)
|
| 1876 |
+
{
|
| 1877 |
+
return FALSE;
|
| 1878 |
+
}
|
| 1879 |
+
|
| 1880 |
+
BOOL WINAPI FreeRDP_WTSSetListenerSecurityA(HANDLE hServer, PVOID pReserved, DWORD Reserved,
|
| 1881 |
+
LPSTR pListenerName,
|
| 1882 |
+
SECURITY_INFORMATION SecurityInformation,
|
| 1883 |
+
PSECURITY_DESCRIPTOR pSecurityDescriptor)
|
| 1884 |
+
{
|
| 1885 |
+
return FALSE;
|
| 1886 |
+
}
|
| 1887 |
+
|
| 1888 |
+
BOOL WINAPI FreeRDP_WTSGetListenerSecurityW(HANDLE hServer, PVOID pReserved, DWORD Reserved,
|
| 1889 |
+
LPWSTR pListenerName,
|
| 1890 |
+
SECURITY_INFORMATION SecurityInformation,
|
| 1891 |
+
PSECURITY_DESCRIPTOR pSecurityDescriptor, DWORD nLength,
|
| 1892 |
+
LPDWORD lpnLengthNeeded)
|
| 1893 |
+
{
|
| 1894 |
+
return FALSE;
|
| 1895 |
+
}
|
| 1896 |
+
|
| 1897 |
+
BOOL WINAPI FreeRDP_WTSGetListenerSecurityA(HANDLE hServer, PVOID pReserved, DWORD Reserved,
|
| 1898 |
+
LPSTR pListenerName,
|
| 1899 |
+
SECURITY_INFORMATION SecurityInformation,
|
| 1900 |
+
PSECURITY_DESCRIPTOR pSecurityDescriptor, DWORD nLength,
|
| 1901 |
+
LPDWORD lpnLengthNeeded)
|
| 1902 |
+
{
|
| 1903 |
+
return FALSE;
|
| 1904 |
+
}
|
| 1905 |
+
|
| 1906 |
+
BOOL CDECL FreeRDP_WTSEnableChildSessions(BOOL bEnable)
|
| 1907 |
+
{
|
| 1908 |
+
return FALSE;
|
| 1909 |
+
}
|
| 1910 |
+
|
| 1911 |
+
BOOL CDECL FreeRDP_WTSIsChildSessionsEnabled(PBOOL pbEnabled)
|
| 1912 |
+
{
|
| 1913 |
+
return FALSE;
|
| 1914 |
+
}
|
| 1915 |
+
|
| 1916 |
+
BOOL CDECL FreeRDP_WTSGetChildSessionId(PULONG pSessionId)
|
| 1917 |
+
{
|
| 1918 |
+
return FALSE;
|
| 1919 |
+
}
|
| 1920 |
+
|
| 1921 |
+
DWORD WINAPI FreeRDP_WTSGetActiveConsoleSessionId(void)
|
| 1922 |
+
{
|
| 1923 |
+
return 0xFFFFFFFF;
|
| 1924 |
+
}
|
| 1925 |
+
BOOL WINAPI FreeRDP_WTSLogoffUser(HANDLE hServer)
|
| 1926 |
+
{
|
| 1927 |
+
return FALSE;
|
| 1928 |
+
}
|
| 1929 |
+
|
| 1930 |
+
BOOL WINAPI FreeRDP_WTSLogonUser(HANDLE hServer, LPCSTR username, LPCSTR password, LPCSTR domain)
|
| 1931 |
+
{
|
| 1932 |
+
return FALSE;
|
| 1933 |
+
}
|
| 1934 |
+
|
| 1935 |
+
void server_channel_common_free(rdpPeerChannel* channel)
|
| 1936 |
+
{
|
| 1937 |
+
if (!channel)
|
| 1938 |
+
return;
|
| 1939 |
+
MessageQueue_Free(channel->queue);
|
| 1940 |
+
Stream_Free(channel->receiveData, TRUE);
|
| 1941 |
+
DeleteCriticalSection(&channel->writeLock);
|
| 1942 |
+
free(channel);
|
| 1943 |
+
}
|
| 1944 |
+
|
| 1945 |
+
rdpPeerChannel* server_channel_common_new(freerdp_peer* client, UINT16 index, UINT32 channelId,
|
| 1946 |
+
size_t chunkSize, const wObject* callback,
|
| 1947 |
+
const char* name)
|
| 1948 |
+
{
|
| 1949 |
+
rdpPeerChannel* channel = (rdpPeerChannel*)calloc(1, sizeof(rdpPeerChannel));
|
| 1950 |
+
if (!channel)
|
| 1951 |
+
return NULL;
|
| 1952 |
+
|
| 1953 |
+
InitializeCriticalSection(&channel->writeLock);
|
| 1954 |
+
|
| 1955 |
+
channel->receiveData = Stream_New(NULL, chunkSize);
|
| 1956 |
+
if (!channel->receiveData)
|
| 1957 |
+
goto fail;
|
| 1958 |
+
|
| 1959 |
+
channel->queue = MessageQueue_New(callback);
|
| 1960 |
+
if (!channel->queue)
|
| 1961 |
+
goto fail;
|
| 1962 |
+
|
| 1963 |
+
channel->index = index;
|
| 1964 |
+
channel->client = client;
|
| 1965 |
+
channel->channelId = channelId;
|
| 1966 |
+
strncpy(channel->channelName, name, ARRAYSIZE(channel->channelName) - 1);
|
| 1967 |
+
return channel;
|
| 1968 |
+
fail:
|
| 1969 |
+
WINPR_PRAGMA_DIAG_PUSH
|
| 1970 |
+
WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
|
| 1971 |
+
server_channel_common_free(channel);
|
| 1972 |
+
WINPR_PRAGMA_DIAG_POP
|
| 1973 |
+
return NULL;
|
| 1974 |
+
}
|
local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/settings.c
ADDED
|
@@ -0,0 +1,1764 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* FreeRDP: A Remote Desktop Protocol Implementation
|
| 3 |
+
* RDP Settings
|
| 4 |
+
*
|
| 5 |
+
* Copyright 2009-2011 Jay Sorg
|
| 6 |
+
* Copyright 2023 Armin Novak <[email protected]>
|
| 7 |
+
* Copyright 2023 Thincast Technologies GmbH
|
| 8 |
+
*
|
| 9 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 10 |
+
* you may not use this file except in compliance with the License.
|
| 11 |
+
* You may obtain a copy of the License at
|
| 12 |
+
*
|
| 13 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 14 |
+
*
|
| 15 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 16 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 17 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 18 |
+
* See the License for the specific language governing permissions and
|
| 19 |
+
* limitations under the License.
|
| 20 |
+
*/
|
| 21 |
+
|
| 22 |
+
#include <freerdp/config.h>
|
| 23 |
+
|
| 24 |
+
#include "settings.h"
|
| 25 |
+
|
| 26 |
+
#include <freerdp/crypto/certificate.h>
|
| 27 |
+
|
| 28 |
+
#include <ctype.h>
|
| 29 |
+
|
| 30 |
+
#include <winpr/crt.h>
|
| 31 |
+
#include <winpr/file.h>
|
| 32 |
+
#include <winpr/path.h>
|
| 33 |
+
#include <winpr/sysinfo.h>
|
| 34 |
+
#include <winpr/registry.h>
|
| 35 |
+
#include <winpr/wtsapi.h>
|
| 36 |
+
|
| 37 |
+
#include <freerdp/settings.h>
|
| 38 |
+
#include <freerdp/build-config.h>
|
| 39 |
+
|
| 40 |
+
#include "../crypto/certificate.h"
|
| 41 |
+
#include "../crypto/privatekey.h"
|
| 42 |
+
#include "capabilities.h"
|
| 43 |
+
|
| 44 |
+
#define TAG FREERDP_TAG("settings")
|
| 45 |
+
|
| 46 |
+
#ifdef _MSC_VER
|
| 47 |
+
#pragma warning(push)
|
| 48 |
+
#pragma warning(disable : 4244)
|
| 49 |
+
#endif
|
| 50 |
+
|
| 51 |
+
static const char client_dll[] = "C:\\Windows\\System32\\mstscax.dll";
|
| 52 |
+
|
| 53 |
+
#define SERVER_KEY "Software\\" FREERDP_VENDOR_STRING "\\" FREERDP_PRODUCT_STRING "\\Server"
|
| 54 |
+
#define CLIENT_KEY "Software\\" FREERDP_VENDOR_STRING "\\" FREERDP_PRODUCT_STRING "\\Client"
|
| 55 |
+
#define BITMAP_CACHE_KEY CLIENT_KEY "\\BitmapCacheV2"
|
| 56 |
+
#define GLYPH_CACHE_KEY CLIENT_KEY "\\GlyphCache"
|
| 57 |
+
#define POINTER_CACHE_KEY CLIENT_KEY "\\PointerCache"
|
| 58 |
+
|
| 59 |
+
struct bounds_t
|
| 60 |
+
{
|
| 61 |
+
INT32 x;
|
| 62 |
+
INT32 y;
|
| 63 |
+
INT32 width;
|
| 64 |
+
INT32 height;
|
| 65 |
+
};
|
| 66 |
+
|
| 67 |
+
static const char* bounds2str(const struct bounds_t* bounds, char* buffer, size_t len)
|
| 68 |
+
{
|
| 69 |
+
WINPR_ASSERT(bounds);
|
| 70 |
+
(void)_snprintf(buffer, len, "{%dx%d-%dx%d}", bounds->x, bounds->y, bounds->x + bounds->width,
|
| 71 |
+
bounds->y + bounds->height);
|
| 72 |
+
return buffer;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
static struct bounds_t union_rect(const struct bounds_t* a, const struct bounds_t* b)
|
| 76 |
+
{
|
| 77 |
+
WINPR_ASSERT(a);
|
| 78 |
+
WINPR_ASSERT(b);
|
| 79 |
+
|
| 80 |
+
struct bounds_t u = *a;
|
| 81 |
+
if (b->x < u.x)
|
| 82 |
+
u.x = b->x;
|
| 83 |
+
if (b->y < u.y)
|
| 84 |
+
u.y = b->y;
|
| 85 |
+
|
| 86 |
+
const INT32 rightA = a->x + a->width;
|
| 87 |
+
const INT32 rightB = b->x + b->width;
|
| 88 |
+
const INT32 right = MAX(rightA, rightB);
|
| 89 |
+
u.width = right - u.x;
|
| 90 |
+
|
| 91 |
+
const INT32 bottomA = a->y + a->height;
|
| 92 |
+
const INT32 bottomB = b->y + b->height;
|
| 93 |
+
const INT32 bottom = MAX(bottomA, bottomB);
|
| 94 |
+
u.height = bottom - u.y;
|
| 95 |
+
|
| 96 |
+
return u;
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
static BOOL intersect_rects(const struct bounds_t* r1, const struct bounds_t* r2)
|
| 100 |
+
{
|
| 101 |
+
WINPR_ASSERT(r1);
|
| 102 |
+
WINPR_ASSERT(r2);
|
| 103 |
+
|
| 104 |
+
const INT32 left = MAX(r1->x, r2->x);
|
| 105 |
+
const INT32 top = MAX(r1->y, r2->y);
|
| 106 |
+
const INT32 right = MIN(r1->x + r1->width, r2->x + r2->width);
|
| 107 |
+
const INT32 bottom = MIN(r1->y + r1->height, r2->y + r2->height);
|
| 108 |
+
|
| 109 |
+
return (left < right) && (top < bottom);
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
static BOOL align_rects(const struct bounds_t* r1, const struct bounds_t* r2)
|
| 113 |
+
{
|
| 114 |
+
WINPR_ASSERT(r1);
|
| 115 |
+
WINPR_ASSERT(r2);
|
| 116 |
+
|
| 117 |
+
const INT32 left = MAX(r1->x, r2->x);
|
| 118 |
+
const INT32 top = MAX(r1->y, r2->y);
|
| 119 |
+
const INT32 right = MIN(r1->x + r1->width, r2->x + r2->width);
|
| 120 |
+
const INT32 bottom = MIN(r1->y + r1->height, r2->y + r2->height);
|
| 121 |
+
|
| 122 |
+
return (left == right) || (top == bottom);
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
static BOOL settings_reg_query_dword_val(HKEY hKey, const TCHAR* sub, DWORD* value)
|
| 126 |
+
{
|
| 127 |
+
DWORD dwType = 0;
|
| 128 |
+
DWORD dwSize = 0;
|
| 129 |
+
|
| 130 |
+
dwSize = sizeof(DWORD);
|
| 131 |
+
if (RegQueryValueEx(hKey, sub, NULL, &dwType, (BYTE*)value, &dwSize) != ERROR_SUCCESS)
|
| 132 |
+
return FALSE;
|
| 133 |
+
if (dwType != REG_DWORD)
|
| 134 |
+
return FALSE;
|
| 135 |
+
|
| 136 |
+
return TRUE;
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
static BOOL settings_reg_query_word_val(HKEY hKey, const TCHAR* sub, UINT16* value)
|
| 140 |
+
{
|
| 141 |
+
DWORD dwValue = 0;
|
| 142 |
+
|
| 143 |
+
if (!settings_reg_query_dword_val(hKey, sub, &dwValue))
|
| 144 |
+
return FALSE;
|
| 145 |
+
|
| 146 |
+
if (dwValue > UINT16_MAX)
|
| 147 |
+
return FALSE;
|
| 148 |
+
|
| 149 |
+
*value = (UINT16)dwValue;
|
| 150 |
+
return TRUE;
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
+
static BOOL settings_reg_query_bool_val(HKEY hKey, const TCHAR* sub, BOOL* value)
|
| 154 |
+
{
|
| 155 |
+
DWORD dwValue = 0;
|
| 156 |
+
|
| 157 |
+
if (!settings_reg_query_dword_val(hKey, sub, &dwValue))
|
| 158 |
+
return FALSE;
|
| 159 |
+
*value = dwValue != 0;
|
| 160 |
+
return TRUE;
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
static BOOL settings_reg_query_dword(rdpSettings* settings, FreeRDP_Settings_Keys_UInt32 id,
|
| 164 |
+
HKEY hKey, const TCHAR* sub)
|
| 165 |
+
{
|
| 166 |
+
DWORD dwValue = 0;
|
| 167 |
+
|
| 168 |
+
if (!settings_reg_query_dword_val(hKey, sub, &dwValue))
|
| 169 |
+
return FALSE;
|
| 170 |
+
|
| 171 |
+
return freerdp_settings_set_uint32(settings, id, dwValue);
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
static BOOL settings_reg_query_bool(rdpSettings* settings, FreeRDP_Settings_Keys_Bool id, HKEY hKey,
|
| 175 |
+
const TCHAR* sub)
|
| 176 |
+
{
|
| 177 |
+
DWORD dwValue = 0;
|
| 178 |
+
|
| 179 |
+
if (!settings_reg_query_dword_val(hKey, sub, &dwValue))
|
| 180 |
+
return FALSE;
|
| 181 |
+
|
| 182 |
+
return freerdp_settings_set_bool(settings, id, dwValue != 0 ? TRUE : FALSE);
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
static void settings_client_load_hkey_local_machine(rdpSettings* settings)
|
| 186 |
+
{
|
| 187 |
+
HKEY hKey = NULL;
|
| 188 |
+
LONG status = 0;
|
| 189 |
+
status = RegOpenKeyExA(HKEY_LOCAL_MACHINE, CLIENT_KEY, 0, KEY_READ | KEY_WOW64_64KEY, &hKey);
|
| 190 |
+
|
| 191 |
+
if (status == ERROR_SUCCESS)
|
| 192 |
+
{
|
| 193 |
+
settings_reg_query_dword(settings, FreeRDP_DesktopWidth, hKey, _T("DesktopWidth"));
|
| 194 |
+
settings_reg_query_dword(settings, FreeRDP_DesktopHeight, hKey, _T("DesktopHeight"));
|
| 195 |
+
settings_reg_query_bool(settings, FreeRDP_Fullscreen, hKey, _T("Fullscreen"));
|
| 196 |
+
settings_reg_query_dword(settings, FreeRDP_ColorDepth, hKey, _T("ColorDepth"));
|
| 197 |
+
settings_reg_query_dword(settings, FreeRDP_KeyboardType, hKey, _T("KeyboardType"));
|
| 198 |
+
settings_reg_query_dword(settings, FreeRDP_KeyboardSubType, hKey, _T("KeyboardSubType"));
|
| 199 |
+
settings_reg_query_dword(settings, FreeRDP_KeyboardFunctionKey, hKey,
|
| 200 |
+
_T("KeyboardFunctionKeys"));
|
| 201 |
+
settings_reg_query_dword(settings, FreeRDP_KeyboardLayout, hKey, _T("KeyboardLayout"));
|
| 202 |
+
settings_reg_query_bool(settings, FreeRDP_ExtSecurity, hKey, _T("ExtSecurity"));
|
| 203 |
+
settings_reg_query_bool(settings, FreeRDP_NlaSecurity, hKey, _T("NlaSecurity"));
|
| 204 |
+
settings_reg_query_bool(settings, FreeRDP_TlsSecurity, hKey, _T("TlsSecurity"));
|
| 205 |
+
settings_reg_query_bool(settings, FreeRDP_RdpSecurity, hKey, _T("RdpSecurity"));
|
| 206 |
+
settings_reg_query_bool(settings, FreeRDP_MstscCookieMode, hKey, _T("MstscCookieMode"));
|
| 207 |
+
settings_reg_query_dword(settings, FreeRDP_CookieMaxLength, hKey, _T("CookieMaxLength"));
|
| 208 |
+
settings_reg_query_bool(settings, FreeRDP_BitmapCacheEnabled, hKey, _T("BitmapCache"));
|
| 209 |
+
settings_reg_query_dword(settings, FreeRDP_OffscreenSupportLevel, hKey,
|
| 210 |
+
_T("OffscreenBitmapCache"));
|
| 211 |
+
settings_reg_query_dword(settings, FreeRDP_OffscreenCacheSize, hKey,
|
| 212 |
+
_T("OffscreenBitmapCacheSize"));
|
| 213 |
+
settings_reg_query_dword(settings, FreeRDP_OffscreenCacheEntries, hKey,
|
| 214 |
+
_T("OffscreenBitmapCacheEntries"));
|
| 215 |
+
RegCloseKey(hKey);
|
| 216 |
+
}
|
| 217 |
+
|
| 218 |
+
status =
|
| 219 |
+
RegOpenKeyExA(HKEY_LOCAL_MACHINE, BITMAP_CACHE_KEY, 0, KEY_READ | KEY_WOW64_64KEY, &hKey);
|
| 220 |
+
|
| 221 |
+
if (status == ERROR_SUCCESS)
|
| 222 |
+
{
|
| 223 |
+
settings_reg_query_dword(settings, FreeRDP_BitmapCacheV2NumCells, hKey, _T("NumCells"));
|
| 224 |
+
for (unsigned x = 0; x < 5; x++)
|
| 225 |
+
{
|
| 226 |
+
DWORD val = 0;
|
| 227 |
+
TCHAR numentries[64] = { 0 };
|
| 228 |
+
TCHAR persist[64] = { 0 };
|
| 229 |
+
BITMAP_CACHE_V2_CELL_INFO cache = { 0 };
|
| 230 |
+
(void)_sntprintf(numentries, ARRAYSIZE(numentries), _T("Cell%uNumEntries"), x);
|
| 231 |
+
(void)_sntprintf(persist, ARRAYSIZE(persist), _T("Cell%uPersistent"), x);
|
| 232 |
+
if (!settings_reg_query_dword_val(hKey, numentries, &val) ||
|
| 233 |
+
!settings_reg_query_bool_val(hKey, persist, &cache.persistent) ||
|
| 234 |
+
!freerdp_settings_set_pointer_array(settings, FreeRDP_BitmapCacheV2CellInfo, x,
|
| 235 |
+
&cache))
|
| 236 |
+
WLog_WARN(TAG, "Failed to load registry keys to settings!");
|
| 237 |
+
cache.numEntries = val;
|
| 238 |
+
}
|
| 239 |
+
|
| 240 |
+
settings_reg_query_bool(settings, FreeRDP_AllowCacheWaitingList, hKey,
|
| 241 |
+
_T("AllowCacheWaitingList"));
|
| 242 |
+
RegCloseKey(hKey);
|
| 243 |
+
}
|
| 244 |
+
|
| 245 |
+
status =
|
| 246 |
+
RegOpenKeyExA(HKEY_LOCAL_MACHINE, GLYPH_CACHE_KEY, 0, KEY_READ | KEY_WOW64_64KEY, &hKey);
|
| 247 |
+
|
| 248 |
+
if (status == ERROR_SUCCESS)
|
| 249 |
+
{
|
| 250 |
+
unsigned x = 0;
|
| 251 |
+
UINT32 GlyphSupportLevel = 0;
|
| 252 |
+
settings_reg_query_dword(settings, FreeRDP_GlyphSupportLevel, hKey, _T("SupportLevel"));
|
| 253 |
+
for (; x < 10; x++)
|
| 254 |
+
{
|
| 255 |
+
GLYPH_CACHE_DEFINITION cache = { 0 };
|
| 256 |
+
TCHAR numentries[64] = { 0 };
|
| 257 |
+
TCHAR maxsize[64] = { 0 };
|
| 258 |
+
(void)_sntprintf(numentries, ARRAYSIZE(numentries), _T("Cache%uNumEntries"), x);
|
| 259 |
+
(void)_sntprintf(maxsize, ARRAYSIZE(maxsize), _T("Cache%uMaxCellSize"), x);
|
| 260 |
+
|
| 261 |
+
settings_reg_query_word_val(hKey, numentries, &cache.cacheEntries);
|
| 262 |
+
settings_reg_query_word_val(hKey, maxsize, &cache.cacheMaximumCellSize);
|
| 263 |
+
if (!freerdp_settings_set_pointer_array(settings, FreeRDP_GlyphCache, x, &cache))
|
| 264 |
+
WLog_WARN(TAG, "Failed to store GlyphCache %" PRIuz, x);
|
| 265 |
+
}
|
| 266 |
+
{
|
| 267 |
+
GLYPH_CACHE_DEFINITION cache = { 0 };
|
| 268 |
+
settings_reg_query_word_val(hKey, _T("FragCacheNumEntries"), &cache.cacheEntries);
|
| 269 |
+
settings_reg_query_word_val(hKey, _T("FragCacheMaxCellSize"),
|
| 270 |
+
&cache.cacheMaximumCellSize);
|
| 271 |
+
if (!freerdp_settings_set_pointer_array(settings, FreeRDP_FragCache, x, &cache))
|
| 272 |
+
WLog_WARN(TAG, "Failed to store FragCache");
|
| 273 |
+
}
|
| 274 |
+
|
| 275 |
+
RegCloseKey(hKey);
|
| 276 |
+
|
| 277 |
+
if (!freerdp_settings_set_uint32(settings, FreeRDP_GlyphSupportLevel, GlyphSupportLevel))
|
| 278 |
+
WLog_WARN(TAG, "Failed to load registry keys to settings!");
|
| 279 |
+
}
|
| 280 |
+
|
| 281 |
+
status =
|
| 282 |
+
RegOpenKeyExA(HKEY_LOCAL_MACHINE, POINTER_CACHE_KEY, 0, KEY_READ | KEY_WOW64_64KEY, &hKey);
|
| 283 |
+
|
| 284 |
+
if (status == ERROR_SUCCESS)
|
| 285 |
+
{
|
| 286 |
+
settings_reg_query_dword(settings, FreeRDP_LargePointerFlag, hKey, _T("LargePointer"));
|
| 287 |
+
settings_reg_query_dword(settings, FreeRDP_PointerCacheSize, hKey, _T("PointerCacheSize"));
|
| 288 |
+
settings_reg_query_dword(settings, FreeRDP_ColorPointerCacheSize, hKey,
|
| 289 |
+
_T("ColorPointerCacheSize"));
|
| 290 |
+
RegCloseKey(hKey);
|
| 291 |
+
}
|
| 292 |
+
}
|
| 293 |
+
|
| 294 |
+
static void settings_server_load_hkey_local_machine(rdpSettings* settings)
|
| 295 |
+
{
|
| 296 |
+
HKEY hKey = NULL;
|
| 297 |
+
LONG status = 0;
|
| 298 |
+
|
| 299 |
+
status = RegOpenKeyExA(HKEY_LOCAL_MACHINE, SERVER_KEY, 0, KEY_READ | KEY_WOW64_64KEY, &hKey);
|
| 300 |
+
|
| 301 |
+
if (status != ERROR_SUCCESS)
|
| 302 |
+
return;
|
| 303 |
+
|
| 304 |
+
settings_reg_query_bool(settings, FreeRDP_ExtSecurity, hKey, _T("ExtSecurity"));
|
| 305 |
+
settings_reg_query_bool(settings, FreeRDP_NlaSecurity, hKey, _T("NlaSecurity"));
|
| 306 |
+
settings_reg_query_bool(settings, FreeRDP_TlsSecurity, hKey, _T("TlsSecurity"));
|
| 307 |
+
settings_reg_query_dword(settings, FreeRDP_TlsSecLevel, hKey, _T("TlsSecLevel"));
|
| 308 |
+
settings_reg_query_bool(settings, FreeRDP_RdpSecurity, hKey, _T("RdpSecurity"));
|
| 309 |
+
|
| 310 |
+
RegCloseKey(hKey);
|
| 311 |
+
}
|
| 312 |
+
|
| 313 |
+
static void settings_load_hkey_local_machine(rdpSettings* settings)
|
| 314 |
+
{
|
| 315 |
+
if (freerdp_settings_get_bool(settings, FreeRDP_ServerMode))
|
| 316 |
+
settings_server_load_hkey_local_machine(settings);
|
| 317 |
+
else
|
| 318 |
+
settings_client_load_hkey_local_machine(settings);
|
| 319 |
+
}
|
| 320 |
+
|
| 321 |
+
static BOOL settings_init_computer_name(rdpSettings* settings)
|
| 322 |
+
{
|
| 323 |
+
CHAR computerName[MAX_COMPUTERNAME_LENGTH + 1] = { 0 };
|
| 324 |
+
DWORD nSize = ARRAYSIZE(computerName);
|
| 325 |
+
|
| 326 |
+
if (!GetComputerNameExA(ComputerNameNetBIOS, computerName, &nSize))
|
| 327 |
+
return FALSE;
|
| 328 |
+
|
| 329 |
+
if (!freerdp_settings_set_string(settings, FreeRDP_ComputerName, computerName))
|
| 330 |
+
return FALSE;
|
| 331 |
+
return freerdp_settings_set_string(settings, FreeRDP_ClientHostname, computerName);
|
| 332 |
+
}
|
| 333 |
+
|
| 334 |
+
void freerdp_settings_print_warnings(const rdpSettings* settings)
|
| 335 |
+
{
|
| 336 |
+
const UINT32 level = freerdp_settings_get_uint32(settings, FreeRDP_GlyphSupportLevel);
|
| 337 |
+
if (level != GLYPH_SUPPORT_NONE)
|
| 338 |
+
{
|
| 339 |
+
char buffer[32] = { 0 };
|
| 340 |
+
WLog_WARN(TAG, "[experimental] enabled GlyphSupportLevel %s, expect visual artefacts!",
|
| 341 |
+
freerdp_settings_glyph_level_string(level, buffer, sizeof(buffer)));
|
| 342 |
+
}
|
| 343 |
+
}
|
| 344 |
+
|
| 345 |
+
static BOOL monitor_operlaps(const rdpSettings* settings, UINT32 orig, UINT32 start, UINT32 count,
|
| 346 |
+
const rdpMonitor* compare)
|
| 347 |
+
{
|
| 348 |
+
const struct bounds_t rect1 = {
|
| 349 |
+
.x = compare->x, .y = compare->y, .width = compare->width, .height = compare->height
|
| 350 |
+
};
|
| 351 |
+
for (UINT32 x = start; x < count; x++)
|
| 352 |
+
{
|
| 353 |
+
const rdpMonitor* monitor =
|
| 354 |
+
freerdp_settings_get_pointer_array(settings, FreeRDP_MonitorDefArray, x);
|
| 355 |
+
const struct bounds_t rect2 = {
|
| 356 |
+
.x = monitor->x, .y = monitor->y, .width = monitor->width, .height = monitor->height
|
| 357 |
+
};
|
| 358 |
+
|
| 359 |
+
if (intersect_rects(&rect1, &rect2))
|
| 360 |
+
{
|
| 361 |
+
char buffer1[32] = { 0 };
|
| 362 |
+
char buffer2[32] = { 0 };
|
| 363 |
+
|
| 364 |
+
WLog_ERR(TAG, "Monitor %" PRIu32 " and %" PRIu32 " are overlapping:", orig, x);
|
| 365 |
+
WLog_ERR(TAG, "%s overlapps with %s", bounds2str(&rect1, buffer1, sizeof(buffer1)),
|
| 366 |
+
bounds2str(&rect2, buffer2, sizeof(buffer2)));
|
| 367 |
+
WLog_ERR(
|
| 368 |
+
TAG,
|
| 369 |
+
"Mulitimonitor mode requested, but local layout has gaps or overlapping areas!");
|
| 370 |
+
WLog_ERR(TAG,
|
| 371 |
+
"Please reconfigure your local monitor setup so that there are no gaps or "
|
| 372 |
+
"overlapping areas!");
|
| 373 |
+
return TRUE;
|
| 374 |
+
}
|
| 375 |
+
}
|
| 376 |
+
return FALSE;
|
| 377 |
+
}
|
| 378 |
+
|
| 379 |
+
static BOOL monitor_has_gaps(const rdpSettings* settings, UINT32 start, UINT32 count,
|
| 380 |
+
const rdpMonitor* compare, UINT32** graph)
|
| 381 |
+
{
|
| 382 |
+
const struct bounds_t rect1 = {
|
| 383 |
+
.x = compare->x, .y = compare->y, .width = compare->width, .height = compare->height
|
| 384 |
+
};
|
| 385 |
+
|
| 386 |
+
BOOL hasNeighbor = FALSE;
|
| 387 |
+
for (UINT32 i = 0; i < count; i++)
|
| 388 |
+
{
|
| 389 |
+
if (i == start)
|
| 390 |
+
continue;
|
| 391 |
+
|
| 392 |
+
const rdpMonitor* monitor =
|
| 393 |
+
freerdp_settings_get_pointer_array(settings, FreeRDP_MonitorDefArray, i);
|
| 394 |
+
|
| 395 |
+
const struct bounds_t rect2 = {
|
| 396 |
+
.x = monitor->x, .y = monitor->y, .width = monitor->width, .height = monitor->height
|
| 397 |
+
};
|
| 398 |
+
if (align_rects(&rect1, &rect2))
|
| 399 |
+
{
|
| 400 |
+
hasNeighbor = TRUE;
|
| 401 |
+
graph[start][i] = 1;
|
| 402 |
+
graph[i][start] = 1;
|
| 403 |
+
}
|
| 404 |
+
}
|
| 405 |
+
|
| 406 |
+
if (!hasNeighbor)
|
| 407 |
+
{
|
| 408 |
+
WLog_ERR(TAG,
|
| 409 |
+
"Monitor configuration has gaps! Monitor %" PRIu32 " does not have any neighbor",
|
| 410 |
+
start);
|
| 411 |
+
}
|
| 412 |
+
|
| 413 |
+
return !hasNeighbor;
|
| 414 |
+
}
|
| 415 |
+
|
| 416 |
+
static void alloc_free(UINT32** ptr)
|
| 417 |
+
{
|
| 418 |
+
free((void*)ptr);
|
| 419 |
+
}
|
| 420 |
+
|
| 421 |
+
WINPR_ATTR_MALLOC(alloc_free, 1)
|
| 422 |
+
static UINT32** alloc_array(size_t count)
|
| 423 |
+
{
|
| 424 |
+
// NOLINTNEXTLINE(clang-analyzer-unix.MallocSizeof)
|
| 425 |
+
BYTE* array = calloc(count * sizeof(uintptr_t), count * sizeof(UINT32));
|
| 426 |
+
UINT32** dst = (UINT32**)array;
|
| 427 |
+
UINT32* val = (UINT32*)(array + count * sizeof(uintptr_t));
|
| 428 |
+
for (size_t x = 0; x < count; x++)
|
| 429 |
+
dst[x] = &val[x];
|
| 430 |
+
|
| 431 |
+
return dst;
|
| 432 |
+
}
|
| 433 |
+
|
| 434 |
+
/* Monitors in the array need to:
|
| 435 |
+
*
|
| 436 |
+
* 1. be connected to another monitor (edges touch but don't overlap or have gaps)
|
| 437 |
+
* 2. all monitors need to be connected so there are no separate groups.
|
| 438 |
+
*
|
| 439 |
+
* So, what we do here is we use dijkstra algorithm to find a path from any start node
|
| 440 |
+
* (lazy as we are we always use the first in the array) to each other node.
|
| 441 |
+
*/
|
| 442 |
+
static BOOL find_path_exists_with_dijkstra(UINT32** graph, size_t count, UINT32 start)
|
| 443 |
+
{
|
| 444 |
+
if (count < 1)
|
| 445 |
+
return FALSE;
|
| 446 |
+
|
| 447 |
+
WINPR_ASSERT(start < count);
|
| 448 |
+
|
| 449 |
+
UINT32** cost = alloc_array(count);
|
| 450 |
+
WINPR_ASSERT(cost);
|
| 451 |
+
|
| 452 |
+
UINT32* distance = calloc(count, sizeof(UINT32));
|
| 453 |
+
WINPR_ASSERT(distance);
|
| 454 |
+
|
| 455 |
+
UINT32* visited = calloc(count, sizeof(UINT32));
|
| 456 |
+
WINPR_ASSERT(visited);
|
| 457 |
+
|
| 458 |
+
UINT32* parent = calloc(count, sizeof(UINT32));
|
| 459 |
+
WINPR_ASSERT(parent);
|
| 460 |
+
|
| 461 |
+
for (size_t x = 0; x < count; x++)
|
| 462 |
+
{
|
| 463 |
+
for (size_t y = 0; y < count; y++)
|
| 464 |
+
{
|
| 465 |
+
if (graph[x][y] == 0)
|
| 466 |
+
cost[x][y] = UINT32_MAX;
|
| 467 |
+
else
|
| 468 |
+
cost[x][y] = graph[x][y];
|
| 469 |
+
}
|
| 470 |
+
}
|
| 471 |
+
|
| 472 |
+
for (UINT32 x = 0; x < count; x++)
|
| 473 |
+
{
|
| 474 |
+
distance[x] = cost[start][x];
|
| 475 |
+
parent[x] = start;
|
| 476 |
+
visited[x] = 0;
|
| 477 |
+
}
|
| 478 |
+
|
| 479 |
+
distance[start] = 0;
|
| 480 |
+
visited[start] = 1;
|
| 481 |
+
|
| 482 |
+
size_t pos = 1;
|
| 483 |
+
UINT32 nextnode = UINT32_MAX;
|
| 484 |
+
while (pos < count - 1)
|
| 485 |
+
{
|
| 486 |
+
UINT32 mindistance = UINT32_MAX;
|
| 487 |
+
|
| 488 |
+
for (UINT32 x = 0; x < count; x++)
|
| 489 |
+
{
|
| 490 |
+
if ((distance[x] < mindistance) && !visited[x])
|
| 491 |
+
{
|
| 492 |
+
mindistance = distance[x];
|
| 493 |
+
nextnode = x;
|
| 494 |
+
}
|
| 495 |
+
}
|
| 496 |
+
|
| 497 |
+
visited[nextnode] = 1;
|
| 498 |
+
|
| 499 |
+
for (size_t y = 0; y < count; y++)
|
| 500 |
+
{
|
| 501 |
+
if (!visited[y])
|
| 502 |
+
{
|
| 503 |
+
UINT32 dist = mindistance + cost[nextnode][y];
|
| 504 |
+
if (dist < distance[y])
|
| 505 |
+
{
|
| 506 |
+
distance[y] = dist;
|
| 507 |
+
parent[y] = nextnode;
|
| 508 |
+
}
|
| 509 |
+
}
|
| 510 |
+
}
|
| 511 |
+
pos++;
|
| 512 |
+
}
|
| 513 |
+
|
| 514 |
+
BOOL rc = TRUE;
|
| 515 |
+
for (size_t x = 0; x < count; x++)
|
| 516 |
+
{
|
| 517 |
+
if (x != start)
|
| 518 |
+
{
|
| 519 |
+
if (distance[x] == UINT32_MAX)
|
| 520 |
+
{
|
| 521 |
+
WLog_ERR(TAG, "monitor %" PRIu32 " not connected with monitor %" PRIuz, start, x);
|
| 522 |
+
rc = FALSE;
|
| 523 |
+
break;
|
| 524 |
+
}
|
| 525 |
+
}
|
| 526 |
+
}
|
| 527 |
+
alloc_free(cost);
|
| 528 |
+
free(distance);
|
| 529 |
+
free(visited);
|
| 530 |
+
free(parent);
|
| 531 |
+
|
| 532 |
+
return rc;
|
| 533 |
+
}
|
| 534 |
+
|
| 535 |
+
static BOOL freerdp_settings_client_monitors_have_gaps(const rdpSettings* settings)
|
| 536 |
+
{
|
| 537 |
+
BOOL rc = TRUE;
|
| 538 |
+
const UINT32 count = freerdp_settings_get_uint32(settings, FreeRDP_MonitorCount);
|
| 539 |
+
if (count <= 1)
|
| 540 |
+
return FALSE;
|
| 541 |
+
|
| 542 |
+
UINT32** graph = alloc_array(count);
|
| 543 |
+
WINPR_ASSERT(graph);
|
| 544 |
+
|
| 545 |
+
for (UINT32 x = 0; x < count; x++)
|
| 546 |
+
{
|
| 547 |
+
const rdpMonitor* monitor =
|
| 548 |
+
freerdp_settings_get_pointer_array(settings, FreeRDP_MonitorDefArray, x);
|
| 549 |
+
if (monitor_has_gaps(settings, x, count, monitor, graph))
|
| 550 |
+
goto fail;
|
| 551 |
+
}
|
| 552 |
+
|
| 553 |
+
rc = !find_path_exists_with_dijkstra(graph, count, 0);
|
| 554 |
+
|
| 555 |
+
fail:
|
| 556 |
+
alloc_free(graph);
|
| 557 |
+
|
| 558 |
+
return rc;
|
| 559 |
+
}
|
| 560 |
+
|
| 561 |
+
static void log_monitor(UINT32 idx, const rdpMonitor* monitor, wLog* log, DWORD level)
|
| 562 |
+
{
|
| 563 |
+
WINPR_ASSERT(monitor);
|
| 564 |
+
|
| 565 |
+
WLog_Print(log, level,
|
| 566 |
+
"[%" PRIu32 "] [%s] {%dx%d-%dx%d} [%" PRIu32 "] {%" PRIu32 "x%" PRIu32
|
| 567 |
+
", orientation: %" PRIu32 ", desktopScale: %" PRIu32 ", deviceScale: %" PRIu32 "}",
|
| 568 |
+
idx, monitor->is_primary ? "primary" : " ", monitor->x, monitor->y,
|
| 569 |
+
monitor->width, monitor->height, monitor->orig_screen,
|
| 570 |
+
monitor->attributes.physicalWidth, monitor->attributes.physicalHeight,
|
| 571 |
+
monitor->attributes.orientation, monitor->attributes.desktopScaleFactor,
|
| 572 |
+
monitor->attributes.deviceScaleFactor);
|
| 573 |
+
}
|
| 574 |
+
|
| 575 |
+
static void log_monitor_configuration(const rdpSettings* settings, wLog* log, DWORD level)
|
| 576 |
+
{
|
| 577 |
+
const UINT32 count = freerdp_settings_get_uint32(settings, FreeRDP_MonitorCount);
|
| 578 |
+
WLog_Print(log, level, "[BEGIN] MonitorDefArray[%" PRIu32 "]", count);
|
| 579 |
+
for (UINT32 x = 0; x < count; x++)
|
| 580 |
+
{
|
| 581 |
+
const rdpMonitor* monitor =
|
| 582 |
+
freerdp_settings_get_pointer_array(settings, FreeRDP_MonitorDefArray, x);
|
| 583 |
+
log_monitor(x, monitor, log, level);
|
| 584 |
+
}
|
| 585 |
+
WLog_Print(log, level, "[END] MonitorDefArray[%" PRIu32 "]", count);
|
| 586 |
+
}
|
| 587 |
+
|
| 588 |
+
static BOOL freerdp_settings_client_monitors_overlap(const rdpSettings* settings)
|
| 589 |
+
{
|
| 590 |
+
const UINT32 count = freerdp_settings_get_uint32(settings, FreeRDP_MonitorCount);
|
| 591 |
+
for (UINT32 x = 0; x < count; x++)
|
| 592 |
+
{
|
| 593 |
+
const rdpMonitor* monitor =
|
| 594 |
+
freerdp_settings_get_pointer_array(settings, FreeRDP_MonitorDefArray, x);
|
| 595 |
+
if (monitor_operlaps(settings, x, x + 1, count, monitor))
|
| 596 |
+
return TRUE;
|
| 597 |
+
}
|
| 598 |
+
return FALSE;
|
| 599 |
+
}
|
| 600 |
+
|
| 601 |
+
/* See [MS-RDPBCGR] 2.2.1.3.6.1 for details on limits
|
| 602 |
+
* https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-rdpbcgr/c3964b39-3d54-4ae1-a84a-ceaed311e0f6
|
| 603 |
+
*/
|
| 604 |
+
static BOOL freerdp_settings_client_monitors_check_primary_and_origin(const rdpSettings* settings)
|
| 605 |
+
{
|
| 606 |
+
const UINT32 count = freerdp_settings_get_uint32(settings, FreeRDP_MonitorCount);
|
| 607 |
+
BOOL havePrimary = FALSE;
|
| 608 |
+
BOOL foundOrigin = FALSE;
|
| 609 |
+
BOOL primaryIsOrigin = FALSE;
|
| 610 |
+
BOOL rc = TRUE;
|
| 611 |
+
|
| 612 |
+
struct bounds_t bounds = { 0 };
|
| 613 |
+
|
| 614 |
+
if (count == 0)
|
| 615 |
+
{
|
| 616 |
+
WLog_WARN(TAG, "Monitor configuration empty.");
|
| 617 |
+
return TRUE;
|
| 618 |
+
}
|
| 619 |
+
|
| 620 |
+
for (UINT32 x = 0; x < count; x++)
|
| 621 |
+
{
|
| 622 |
+
const rdpMonitor* monitor =
|
| 623 |
+
freerdp_settings_get_pointer_array(settings, FreeRDP_MonitorDefArray, x);
|
| 624 |
+
struct bounds_t cur = {
|
| 625 |
+
.x = monitor->x, .y = monitor->y, .width = monitor->width, .height = monitor->height
|
| 626 |
+
};
|
| 627 |
+
|
| 628 |
+
bounds = union_rect(&bounds, &cur);
|
| 629 |
+
|
| 630 |
+
if (monitor->is_primary)
|
| 631 |
+
{
|
| 632 |
+
if (havePrimary)
|
| 633 |
+
{
|
| 634 |
+
WLog_ERR(TAG, "Monitor configuration contains multiple primary monitors!");
|
| 635 |
+
rc = FALSE;
|
| 636 |
+
}
|
| 637 |
+
havePrimary = TRUE;
|
| 638 |
+
}
|
| 639 |
+
|
| 640 |
+
if ((monitor->x == 0) && (monitor->y == 0))
|
| 641 |
+
{
|
| 642 |
+
if (foundOrigin)
|
| 643 |
+
{
|
| 644 |
+
WLog_ERR(TAG, "Monitor configuration does have multiple origin 0/0");
|
| 645 |
+
rc = FALSE;
|
| 646 |
+
}
|
| 647 |
+
foundOrigin = TRUE;
|
| 648 |
+
primaryIsOrigin = monitor->is_primary != 0;
|
| 649 |
+
}
|
| 650 |
+
}
|
| 651 |
+
|
| 652 |
+
if ((bounds.width > 32766) || (bounds.width < 200))
|
| 653 |
+
{
|
| 654 |
+
WLog_ERR(TAG,
|
| 655 |
+
"Monitor configuration virtual desktop width must be 200 <= %" PRId32 " <= 32766",
|
| 656 |
+
bounds.width);
|
| 657 |
+
rc = FALSE;
|
| 658 |
+
}
|
| 659 |
+
if ((bounds.height > 32766) || (bounds.height < 200))
|
| 660 |
+
{
|
| 661 |
+
WLog_ERR(TAG,
|
| 662 |
+
"Monitor configuration virtual desktop height must be 200 <= %" PRId32 " <= 32766",
|
| 663 |
+
bounds.height);
|
| 664 |
+
rc = FALSE;
|
| 665 |
+
}
|
| 666 |
+
|
| 667 |
+
if (!havePrimary)
|
| 668 |
+
{
|
| 669 |
+
WLog_ERR(TAG, "Monitor configuration does not contain a primary monitor!");
|
| 670 |
+
rc = FALSE;
|
| 671 |
+
}
|
| 672 |
+
if (!foundOrigin)
|
| 673 |
+
{
|
| 674 |
+
WLog_ERR(TAG, "Monitor configuration must start at 0/0 for first monitor!");
|
| 675 |
+
rc = FALSE;
|
| 676 |
+
}
|
| 677 |
+
if (!primaryIsOrigin)
|
| 678 |
+
{
|
| 679 |
+
WLog_ERR(TAG, "Monitor configuration must start at 0/0 for primary monitor!");
|
| 680 |
+
rc = FALSE;
|
| 681 |
+
}
|
| 682 |
+
|
| 683 |
+
return rc;
|
| 684 |
+
}
|
| 685 |
+
|
| 686 |
+
BOOL freerdp_settings_check_client_after_preconnect(const rdpSettings* settings)
|
| 687 |
+
{
|
| 688 |
+
wLog* log = WLog_Get(TAG);
|
| 689 |
+
BOOL rc = TRUE;
|
| 690 |
+
log_monitor_configuration(settings, log, WLOG_DEBUG);
|
| 691 |
+
if (freerdp_settings_client_monitors_overlap(settings))
|
| 692 |
+
rc = FALSE;
|
| 693 |
+
if (freerdp_settings_client_monitors_have_gaps(settings))
|
| 694 |
+
rc = FALSE;
|
| 695 |
+
if (!freerdp_settings_client_monitors_check_primary_and_origin(settings))
|
| 696 |
+
rc = FALSE;
|
| 697 |
+
if (!rc)
|
| 698 |
+
{
|
| 699 |
+
DWORD level = WLOG_ERROR;
|
| 700 |
+
WLog_Print(log, level, "Invalid or unsupported monitor configuration detected");
|
| 701 |
+
WLog_Print(log, level, "Check if the configuration is valid.");
|
| 702 |
+
WLog_Print(log, level,
|
| 703 |
+
"If you suspect a bug create a new issue at "
|
| 704 |
+
"https://github.com/FreeRDP/FreeRDP/issues/new");
|
| 705 |
+
WLog_Print(
|
| 706 |
+
log, level,
|
| 707 |
+
"Provide at least the following log lines detailing your monitor configuration:");
|
| 708 |
+
log_monitor_configuration(settings, log, level);
|
| 709 |
+
}
|
| 710 |
+
|
| 711 |
+
return rc;
|
| 712 |
+
}
|
| 713 |
+
|
| 714 |
+
BOOL freerdp_settings_set_default_order_support(rdpSettings* settings)
|
| 715 |
+
{
|
| 716 |
+
BYTE* OrderSupport = freerdp_settings_get_pointer_writable(settings, FreeRDP_OrderSupport);
|
| 717 |
+
if (!OrderSupport)
|
| 718 |
+
return FALSE;
|
| 719 |
+
|
| 720 |
+
ZeroMemory(OrderSupport, 32);
|
| 721 |
+
OrderSupport[NEG_DSTBLT_INDEX] = TRUE;
|
| 722 |
+
OrderSupport[NEG_PATBLT_INDEX] = TRUE;
|
| 723 |
+
OrderSupport[NEG_SCRBLT_INDEX] = TRUE;
|
| 724 |
+
OrderSupport[NEG_OPAQUE_RECT_INDEX] = TRUE;
|
| 725 |
+
OrderSupport[NEG_DRAWNINEGRID_INDEX] = FALSE;
|
| 726 |
+
OrderSupport[NEG_MULTIDSTBLT_INDEX] = FALSE;
|
| 727 |
+
OrderSupport[NEG_MULTIPATBLT_INDEX] = FALSE;
|
| 728 |
+
OrderSupport[NEG_MULTISCRBLT_INDEX] = FALSE;
|
| 729 |
+
OrderSupport[NEG_MULTIOPAQUERECT_INDEX] = TRUE;
|
| 730 |
+
OrderSupport[NEG_MULTI_DRAWNINEGRID_INDEX] = FALSE;
|
| 731 |
+
OrderSupport[NEG_LINETO_INDEX] = TRUE;
|
| 732 |
+
OrderSupport[NEG_POLYLINE_INDEX] = TRUE;
|
| 733 |
+
OrderSupport[NEG_MEMBLT_INDEX] =
|
| 734 |
+
freerdp_settings_get_bool(settings, FreeRDP_BitmapCacheEnabled) ? 1 : 0;
|
| 735 |
+
OrderSupport[NEG_MEM3BLT_INDEX] =
|
| 736 |
+
freerdp_settings_get_bool(settings, FreeRDP_BitmapCacheEnabled) ? 1 : 0;
|
| 737 |
+
OrderSupport[NEG_MEMBLT_V2_INDEX] =
|
| 738 |
+
freerdp_settings_get_bool(settings, FreeRDP_BitmapCacheEnabled) ? 1 : 0;
|
| 739 |
+
OrderSupport[NEG_MEM3BLT_V2_INDEX] =
|
| 740 |
+
freerdp_settings_get_bool(settings, FreeRDP_BitmapCacheEnabled) ? 1 : 0;
|
| 741 |
+
OrderSupport[NEG_SAVEBITMAP_INDEX] = FALSE;
|
| 742 |
+
OrderSupport[NEG_GLYPH_INDEX_INDEX] =
|
| 743 |
+
freerdp_settings_get_uint32(settings, FreeRDP_GlyphSupportLevel) != GLYPH_SUPPORT_NONE;
|
| 744 |
+
OrderSupport[NEG_FAST_INDEX_INDEX] =
|
| 745 |
+
freerdp_settings_get_uint32(settings, FreeRDP_GlyphSupportLevel) != GLYPH_SUPPORT_NONE;
|
| 746 |
+
OrderSupport[NEG_FAST_GLYPH_INDEX] =
|
| 747 |
+
freerdp_settings_get_uint32(settings, FreeRDP_GlyphSupportLevel) != GLYPH_SUPPORT_NONE;
|
| 748 |
+
OrderSupport[NEG_POLYGON_SC_INDEX] = FALSE;
|
| 749 |
+
OrderSupport[NEG_POLYGON_CB_INDEX] = FALSE;
|
| 750 |
+
OrderSupport[NEG_ELLIPSE_SC_INDEX] = FALSE;
|
| 751 |
+
OrderSupport[NEG_ELLIPSE_CB_INDEX] = FALSE;
|
| 752 |
+
return TRUE;
|
| 753 |
+
}
|
| 754 |
+
|
| 755 |
+
BOOL freerdp_capability_buffer_allocate(rdpSettings* settings, UINT32 count)
|
| 756 |
+
{
|
| 757 |
+
WINPR_ASSERT(settings);
|
| 758 |
+
WINPR_ASSERT(count > 0);
|
| 759 |
+
WINPR_ASSERT(count == 32);
|
| 760 |
+
|
| 761 |
+
freerdp_capability_buffer_free(settings);
|
| 762 |
+
WINPR_ASSERT(settings->ReceivedCapabilitiesSize == 0);
|
| 763 |
+
|
| 764 |
+
settings->ReceivedCapabilitiesSize = count;
|
| 765 |
+
void* tmp = realloc(settings->ReceivedCapabilities, count * sizeof(BYTE));
|
| 766 |
+
if (!tmp)
|
| 767 |
+
return FALSE;
|
| 768 |
+
memset(tmp, 0, count * sizeof(BYTE));
|
| 769 |
+
settings->ReceivedCapabilities = tmp;
|
| 770 |
+
|
| 771 |
+
tmp = realloc((void*)settings->ReceivedCapabilityData, count * sizeof(BYTE*));
|
| 772 |
+
if (!tmp)
|
| 773 |
+
return FALSE;
|
| 774 |
+
memset(tmp, 0, count * sizeof(BYTE*));
|
| 775 |
+
settings->ReceivedCapabilityData = (BYTE**)tmp;
|
| 776 |
+
|
| 777 |
+
tmp = realloc(settings->ReceivedCapabilityDataSizes, count * sizeof(UINT32));
|
| 778 |
+
if (!tmp)
|
| 779 |
+
return FALSE;
|
| 780 |
+
memset(tmp, 0, count * sizeof(UINT32));
|
| 781 |
+
settings->ReceivedCapabilityDataSizes = tmp;
|
| 782 |
+
|
| 783 |
+
return (settings->ReceivedCapabilities && settings->ReceivedCapabilityData &&
|
| 784 |
+
settings->ReceivedCapabilityDataSizes);
|
| 785 |
+
}
|
| 786 |
+
|
| 787 |
+
#if !defined(WITH_FULL_CONFIG_PATH)
|
| 788 |
+
static char* freerdp_settings_get_legacy_config_path(void)
|
| 789 |
+
{
|
| 790 |
+
char product[sizeof(FREERDP_PRODUCT_STRING)] = { 0 };
|
| 791 |
+
|
| 792 |
+
for (size_t i = 0; i < sizeof(product); i++)
|
| 793 |
+
product[i] = (char)tolower(FREERDP_PRODUCT_STRING[i]);
|
| 794 |
+
|
| 795 |
+
return GetKnownSubPath(KNOWN_PATH_XDG_CONFIG_HOME, product);
|
| 796 |
+
}
|
| 797 |
+
#endif
|
| 798 |
+
|
| 799 |
+
char* freerdp_settings_get_config_path(void)
|
| 800 |
+
{
|
| 801 |
+
char* path = NULL;
|
| 802 |
+
/* For default FreeRDP continue using same config directory
|
| 803 |
+
* as in old releases.
|
| 804 |
+
* Custom builds use <Vendor>/<Product> as config folder. */
|
| 805 |
+
#if !defined(WITH_FULL_CONFIG_PATH)
|
| 806 |
+
if (_stricmp(FREERDP_VENDOR_STRING, FREERDP_PRODUCT_STRING) == 0)
|
| 807 |
+
return freerdp_settings_get_legacy_config_path();
|
| 808 |
+
#endif
|
| 809 |
+
|
| 810 |
+
char* base = GetKnownSubPath(KNOWN_PATH_XDG_CONFIG_HOME, FREERDP_VENDOR_STRING);
|
| 811 |
+
if (base)
|
| 812 |
+
path = GetCombinedPath(base, FREERDP_PRODUCT_STRING);
|
| 813 |
+
free(base);
|
| 814 |
+
|
| 815 |
+
return path;
|
| 816 |
+
}
|
| 817 |
+
|
| 818 |
+
rdpSettings* freerdp_settings_new(DWORD flags)
|
| 819 |
+
{
|
| 820 |
+
char* issuers[] = { "FreeRDP", "FreeRDP-licenser" };
|
| 821 |
+
const BOOL server = (flags & FREERDP_SETTINGS_SERVER_MODE) != 0 ? TRUE : FALSE;
|
| 822 |
+
const BOOL remote = (flags & FREERDP_SETTINGS_REMOTE_MODE) != 0 ? TRUE : FALSE;
|
| 823 |
+
rdpSettings* settings = (rdpSettings*)calloc(1, sizeof(rdpSettings));
|
| 824 |
+
|
| 825 |
+
if (!settings)
|
| 826 |
+
return NULL;
|
| 827 |
+
|
| 828 |
+
if (!server && !remote)
|
| 829 |
+
{
|
| 830 |
+
if (!freerdp_settings_set_string(settings, FreeRDP_GatewayAvdClientID,
|
| 831 |
+
"a85cf173-4192-42f8-81fa-777a763e6e2c"))
|
| 832 |
+
goto out_fail;
|
| 833 |
+
if (!freerdp_settings_set_string(settings, FreeRDP_GatewayAzureActiveDirectory,
|
| 834 |
+
"login.microsoftonline.com"))
|
| 835 |
+
goto out_fail;
|
| 836 |
+
if (!freerdp_settings_set_string(settings, FreeRDP_GatewayAvdAadtenantid, "common"))
|
| 837 |
+
goto out_fail;
|
| 838 |
+
if (!freerdp_settings_set_bool(settings, FreeRDP_GatewayAvdUseTenantid, FALSE))
|
| 839 |
+
goto out_fail;
|
| 840 |
+
if (!freerdp_settings_set_uint32(settings, FreeRDP_DesktopPhysicalWidth, 1000))
|
| 841 |
+
goto out_fail;
|
| 842 |
+
if (!freerdp_settings_set_uint32(settings, FreeRDP_DesktopPhysicalHeight, 1000))
|
| 843 |
+
goto out_fail;
|
| 844 |
+
if (!freerdp_settings_set_uint16(settings, FreeRDP_DesktopOrientation,
|
| 845 |
+
ORIENTATION_LANDSCAPE))
|
| 846 |
+
goto out_fail;
|
| 847 |
+
if (!freerdp_settings_set_uint32(settings, FreeRDP_DeviceScaleFactor, 100))
|
| 848 |
+
goto out_fail;
|
| 849 |
+
if (!freerdp_settings_set_uint32(settings, FreeRDP_DesktopScaleFactor, 100))
|
| 850 |
+
goto out_fail;
|
| 851 |
+
}
|
| 852 |
+
if (!freerdp_settings_set_uint32(settings, FreeRDP_SurfaceCommandsSupported,
|
| 853 |
+
SURFCMDS_SET_SURFACE_BITS | SURFCMDS_STREAM_SURFACE_BITS |
|
| 854 |
+
SURFCMDS_FRAME_MARKER))
|
| 855 |
+
goto out_fail;
|
| 856 |
+
|
| 857 |
+
if (!freerdp_settings_set_uint32(settings, FreeRDP_RemoteFxRlgrMode, RLGR3))
|
| 858 |
+
goto out_fail;
|
| 859 |
+
|
| 860 |
+
if (!freerdp_settings_set_uint16(settings, FreeRDP_CapsProtocolVersion,
|
| 861 |
+
TS_CAPS_PROTOCOLVERSION))
|
| 862 |
+
goto out_fail;
|
| 863 |
+
|
| 864 |
+
if (!freerdp_settings_set_uint32(settings, FreeRDP_ClipboardFeatureMask,
|
| 865 |
+
CLIPRDR_FLAG_DEFAULT_MASK))
|
| 866 |
+
goto out_fail;
|
| 867 |
+
if (!freerdp_settings_set_string(settings, FreeRDP_ServerLicenseCompanyName, "FreeRDP"))
|
| 868 |
+
goto out_fail;
|
| 869 |
+
if (!freerdp_settings_set_string(settings, FreeRDP_ServerLicenseProductName,
|
| 870 |
+
"FreeRDP-licensing-server"))
|
| 871 |
+
goto out_fail;
|
| 872 |
+
if (!freerdp_settings_set_uint32(settings, FreeRDP_ServerLicenseProductVersion, 1))
|
| 873 |
+
goto out_fail;
|
| 874 |
+
if (!freerdp_server_license_issuers_copy(settings, issuers, ARRAYSIZE(issuers)))
|
| 875 |
+
goto out_fail;
|
| 876 |
+
|
| 877 |
+
if (!freerdp_settings_set_uint16(settings, FreeRDP_SupportedColorDepths,
|
| 878 |
+
RNS_UD_32BPP_SUPPORT | RNS_UD_24BPP_SUPPORT |
|
| 879 |
+
RNS_UD_16BPP_SUPPORT | RNS_UD_15BPP_SUPPORT))
|
| 880 |
+
goto out_fail;
|
| 881 |
+
|
| 882 |
+
if (!freerdp_settings_set_bool(settings, FreeRDP_UnicodeInput, TRUE) ||
|
| 883 |
+
!freerdp_settings_set_bool(settings, FreeRDP_HasHorizontalWheel, TRUE) ||
|
| 884 |
+
!freerdp_settings_set_bool(settings, FreeRDP_HasExtendedMouseEvent, TRUE) ||
|
| 885 |
+
!freerdp_settings_set_bool(settings, FreeRDP_HasQoeEvent, TRUE) ||
|
| 886 |
+
!freerdp_settings_set_bool(settings, FreeRDP_HasRelativeMouseEvent, TRUE) ||
|
| 887 |
+
!freerdp_settings_set_bool(settings, FreeRDP_HiDefRemoteApp, TRUE) ||
|
| 888 |
+
!freerdp_settings_set_uint32(
|
| 889 |
+
settings, FreeRDP_RemoteApplicationSupportMask,
|
| 890 |
+
RAIL_LEVEL_SUPPORTED | RAIL_LEVEL_DOCKED_LANGBAR_SUPPORTED |
|
| 891 |
+
RAIL_LEVEL_SHELL_INTEGRATION_SUPPORTED | RAIL_LEVEL_LANGUAGE_IME_SYNC_SUPPORTED |
|
| 892 |
+
RAIL_LEVEL_SERVER_TO_CLIENT_IME_SYNC_SUPPORTED |
|
| 893 |
+
RAIL_LEVEL_HIDE_MINIMIZED_APPS_SUPPORTED | RAIL_LEVEL_WINDOW_CLOAKING_SUPPORTED |
|
| 894 |
+
RAIL_LEVEL_HANDSHAKE_EX_SUPPORTED) ||
|
| 895 |
+
!freerdp_settings_set_uint16(settings, FreeRDP_TextANSICodePage, CP_UTF8) ||
|
| 896 |
+
!freerdp_settings_set_uint16(settings, FreeRDP_OrderSupportFlags,
|
| 897 |
+
NEGOTIATE_ORDER_SUPPORT | ZERO_BOUNDS_DELTA_SUPPORT |
|
| 898 |
+
COLOR_INDEX_SUPPORT) ||
|
| 899 |
+
!freerdp_settings_set_bool(settings, FreeRDP_SupportHeartbeatPdu, TRUE) ||
|
| 900 |
+
!freerdp_settings_set_bool(settings, FreeRDP_ServerMode, server) ||
|
| 901 |
+
!freerdp_settings_set_bool(settings, FreeRDP_WaitForOutputBufferFlush, TRUE) ||
|
| 902 |
+
!freerdp_settings_set_uint32(settings, FreeRDP_ClusterInfoFlags, REDIRECTION_SUPPORTED) ||
|
| 903 |
+
!freerdp_settings_set_uint32(settings, FreeRDP_DesktopWidth, 1024) ||
|
| 904 |
+
!freerdp_settings_set_uint32(settings, FreeRDP_DesktopHeight, 768) ||
|
| 905 |
+
!freerdp_settings_set_bool(settings, FreeRDP_Workarea, FALSE) ||
|
| 906 |
+
!freerdp_settings_set_bool(settings, FreeRDP_Fullscreen, FALSE) ||
|
| 907 |
+
!freerdp_settings_set_bool(settings, FreeRDP_GrabKeyboard, TRUE) ||
|
| 908 |
+
!freerdp_settings_set_bool(settings, FreeRDP_Decorations, TRUE) ||
|
| 909 |
+
!freerdp_settings_set_uint32(settings, FreeRDP_RdpVersion, RDP_VERSION_10_12) ||
|
| 910 |
+
!freerdp_settings_set_uint32(settings, FreeRDP_ColorDepth, 32) ||
|
| 911 |
+
!freerdp_settings_set_bool(settings, FreeRDP_AadSecurity, FALSE) ||
|
| 912 |
+
!freerdp_settings_set_bool(settings, FreeRDP_ExtSecurity, FALSE) ||
|
| 913 |
+
!freerdp_settings_set_bool(settings, FreeRDP_NlaSecurity, TRUE) ||
|
| 914 |
+
!freerdp_settings_set_bool(settings, FreeRDP_TlsSecurity, TRUE) ||
|
| 915 |
+
!freerdp_settings_set_bool(settings, FreeRDP_RdpSecurity, TRUE) ||
|
| 916 |
+
!freerdp_settings_set_bool(settings, FreeRDP_RdstlsSecurity, FALSE) ||
|
| 917 |
+
!freerdp_settings_set_bool(settings, FreeRDP_NegotiateSecurityLayer, TRUE) ||
|
| 918 |
+
!freerdp_settings_set_bool(settings, FreeRDP_RestrictedAdminModeRequired, FALSE) ||
|
| 919 |
+
!freerdp_settings_set_bool(settings, FreeRDP_MstscCookieMode, FALSE) ||
|
| 920 |
+
!freerdp_settings_set_uint32(settings, FreeRDP_CookieMaxLength,
|
| 921 |
+
DEFAULT_COOKIE_MAX_LENGTH) ||
|
| 922 |
+
!freerdp_settings_set_uint32(settings, FreeRDP_ClientBuild,
|
| 923 |
+
18363) || /* Windows 10, Version 1909 */
|
| 924 |
+
!freerdp_settings_set_uint32(settings, FreeRDP_KeyboardType, 4) ||
|
| 925 |
+
!freerdp_settings_set_uint32(settings, FreeRDP_KeyboardSubType, 0) ||
|
| 926 |
+
!freerdp_settings_set_uint32(settings, FreeRDP_KeyboardFunctionKey, 12) ||
|
| 927 |
+
!freerdp_settings_set_uint32(settings, FreeRDP_KeyboardLayout, 0) ||
|
| 928 |
+
!freerdp_settings_set_uint32(settings, FreeRDP_KeyboardHook,
|
| 929 |
+
KEYBOARD_HOOK_FULLSCREEN_ONLY) ||
|
| 930 |
+
!freerdp_settings_set_bool(settings, FreeRDP_UseRdpSecurityLayer, FALSE) ||
|
| 931 |
+
!freerdp_settings_set_bool(settings, FreeRDP_SaltedChecksum, TRUE) ||
|
| 932 |
+
!freerdp_settings_set_uint32(settings, FreeRDP_ServerPort, 3389) ||
|
| 933 |
+
!freerdp_settings_set_uint32(settings, FreeRDP_GatewayPort, 443) ||
|
| 934 |
+
!freerdp_settings_set_bool(settings, FreeRDP_DesktopResize, TRUE) ||
|
| 935 |
+
!freerdp_settings_set_bool(settings, FreeRDP_ToggleFullscreen, TRUE) ||
|
| 936 |
+
!freerdp_settings_set_uint32(settings, FreeRDP_DesktopPosX, UINT32_MAX) ||
|
| 937 |
+
!freerdp_settings_set_uint32(settings, FreeRDP_DesktopPosY, UINT32_MAX) ||
|
| 938 |
+
!freerdp_settings_set_bool(settings, FreeRDP_SoftwareGdi, TRUE) ||
|
| 939 |
+
!freerdp_settings_set_bool(settings, FreeRDP_UnmapButtons, FALSE) ||
|
| 940 |
+
!freerdp_settings_set_uint32(settings, FreeRDP_PerformanceFlags, PERF_FLAG_NONE) ||
|
| 941 |
+
!freerdp_settings_set_bool(settings, FreeRDP_AllowFontSmoothing, TRUE) ||
|
| 942 |
+
!freerdp_settings_set_bool(settings, FreeRDP_AllowDesktopComposition, FALSE) ||
|
| 943 |
+
!freerdp_settings_set_bool(settings, FreeRDP_DisableWallpaper, FALSE) ||
|
| 944 |
+
!freerdp_settings_set_bool(settings, FreeRDP_DisableFullWindowDrag, TRUE) ||
|
| 945 |
+
!freerdp_settings_set_bool(settings, FreeRDP_DisableMenuAnims, TRUE) ||
|
| 946 |
+
!freerdp_settings_set_bool(settings, FreeRDP_DisableThemes, FALSE) ||
|
| 947 |
+
!freerdp_settings_set_uint32(settings, FreeRDP_ConnectionType,
|
| 948 |
+
CONNECTION_TYPE_AUTODETECT) ||
|
| 949 |
+
!freerdp_settings_set_bool(settings, FreeRDP_NetworkAutoDetect, TRUE) ||
|
| 950 |
+
!freerdp_settings_set_uint32(settings, FreeRDP_EncryptionMethods, ENCRYPTION_METHOD_NONE) ||
|
| 951 |
+
!freerdp_settings_set_uint32(settings, FreeRDP_EncryptionLevel, ENCRYPTION_LEVEL_NONE) ||
|
| 952 |
+
!freerdp_settings_set_bool(settings, FreeRDP_FIPSMode, FALSE) ||
|
| 953 |
+
!freerdp_settings_set_bool(settings, FreeRDP_CompressionEnabled, TRUE) ||
|
| 954 |
+
!freerdp_settings_set_bool(settings, FreeRDP_LogonNotify, TRUE) ||
|
| 955 |
+
!freerdp_settings_set_uint32(settings, FreeRDP_BrushSupportLevel, BRUSH_COLOR_FULL) ||
|
| 956 |
+
!freerdp_settings_set_uint32(settings, FreeRDP_CompressionLevel, PACKET_COMPR_TYPE_RDP61) ||
|
| 957 |
+
!freerdp_settings_set_bool(settings, FreeRDP_Authentication, TRUE) ||
|
| 958 |
+
!freerdp_settings_set_bool(settings, FreeRDP_AuthenticationOnly, FALSE) ||
|
| 959 |
+
!freerdp_settings_set_bool(settings, FreeRDP_CredentialsFromStdin, FALSE) ||
|
| 960 |
+
!freerdp_settings_set_bool(settings, FreeRDP_DisableCredentialsDelegation, FALSE) ||
|
| 961 |
+
!freerdp_settings_set_uint32(settings, FreeRDP_AuthenticationLevel, 2) ||
|
| 962 |
+
!freerdp_settings_set_uint32(settings, FreeRDP_ChannelCount, 0) ||
|
| 963 |
+
!freerdp_settings_set_bool(settings, FreeRDP_CertificateCallbackPreferPEM, FALSE) ||
|
| 964 |
+
!freerdp_settings_set_uint32(settings, FreeRDP_KeySpec, AT_KEYEXCHANGE))
|
| 965 |
+
goto out_fail;
|
| 966 |
+
|
| 967 |
+
if (!freerdp_settings_set_pointer_len(settings, FreeRDP_ChannelDefArray, NULL,
|
| 968 |
+
CHANNEL_MAX_COUNT))
|
| 969 |
+
goto out_fail;
|
| 970 |
+
|
| 971 |
+
if (!freerdp_settings_set_bool(settings, FreeRDP_SupportMonitorLayoutPdu, FALSE))
|
| 972 |
+
goto out_fail;
|
| 973 |
+
|
| 974 |
+
if (!freerdp_settings_set_uint32(settings, FreeRDP_MonitorCount, 0))
|
| 975 |
+
goto out_fail;
|
| 976 |
+
|
| 977 |
+
if (!freerdp_settings_set_pointer_len(settings, FreeRDP_MonitorDefArray, NULL, 32))
|
| 978 |
+
goto out_fail;
|
| 979 |
+
|
| 980 |
+
if (!freerdp_settings_set_int32(settings, FreeRDP_MonitorLocalShiftX, 0))
|
| 981 |
+
goto out_fail;
|
| 982 |
+
|
| 983 |
+
if (!freerdp_settings_set_int32(settings, FreeRDP_MonitorLocalShiftY, 0))
|
| 984 |
+
goto out_fail;
|
| 985 |
+
|
| 986 |
+
if (!freerdp_settings_set_pointer_len(settings, FreeRDP_MonitorIds, NULL, 0))
|
| 987 |
+
goto out_fail;
|
| 988 |
+
|
| 989 |
+
if (!freerdp_settings_set_uint32(settings, FreeRDP_MultitransportFlags,
|
| 990 |
+
TRANSPORT_TYPE_UDP_FECR))
|
| 991 |
+
goto out_fail;
|
| 992 |
+
if (!freerdp_settings_set_bool(settings, FreeRDP_SupportMultitransport, TRUE))
|
| 993 |
+
goto out_fail;
|
| 994 |
+
|
| 995 |
+
if (!settings_init_computer_name(settings))
|
| 996 |
+
goto out_fail;
|
| 997 |
+
|
| 998 |
+
if (!freerdp_settings_set_pointer_len(settings, FreeRDP_RdpServerCertificate, NULL, 1))
|
| 999 |
+
goto out_fail;
|
| 1000 |
+
|
| 1001 |
+
if (!freerdp_capability_buffer_allocate(settings, 32))
|
| 1002 |
+
goto out_fail;
|
| 1003 |
+
|
| 1004 |
+
{
|
| 1005 |
+
char tmp[32] = { 0 };
|
| 1006 |
+
if (!freerdp_settings_set_string_len(settings, FreeRDP_ClientProductId, tmp, sizeof(tmp)))
|
| 1007 |
+
goto out_fail;
|
| 1008 |
+
}
|
| 1009 |
+
|
| 1010 |
+
/* [MS-RDPBCGR] 2.2.7.1.5 Pointer Capability Set (TS_POINTER_CAPABILITYSET)
|
| 1011 |
+
*
|
| 1012 |
+
* if we are in server mode send a reasonable large cache size,
|
| 1013 |
+
* if we are in client mode just set the value to the maximum we want to
|
| 1014 |
+
* support and during capability exchange that size will be limited to the
|
| 1015 |
+
* sizes the server supports
|
| 1016 |
+
*
|
| 1017 |
+
* We have chosen 128 cursors in cache which is at worst 128 * 576kB (384x384 pixel cursor with
|
| 1018 |
+
* 32bit color depth)
|
| 1019 |
+
* */
|
| 1020 |
+
if (freerdp_settings_get_bool(settings, FreeRDP_ServerMode))
|
| 1021 |
+
{
|
| 1022 |
+
if (!freerdp_settings_set_uint32(settings, FreeRDP_PointerCacheSize, 25) ||
|
| 1023 |
+
!freerdp_settings_set_uint32(settings, FreeRDP_ColorPointerCacheSize, 25))
|
| 1024 |
+
goto out_fail;
|
| 1025 |
+
}
|
| 1026 |
+
else
|
| 1027 |
+
{
|
| 1028 |
+
if (!freerdp_settings_set_uint32(settings, FreeRDP_PointerCacheSize, 128) ||
|
| 1029 |
+
!freerdp_settings_set_uint32(settings, FreeRDP_ColorPointerCacheSize, 128))
|
| 1030 |
+
goto out_fail;
|
| 1031 |
+
}
|
| 1032 |
+
|
| 1033 |
+
if (!freerdp_settings_set_uint32(settings, FreeRDP_LargePointerFlag,
|
| 1034 |
+
(LARGE_POINTER_FLAG_96x96 | LARGE_POINTER_FLAG_384x384)) ||
|
| 1035 |
+
!freerdp_settings_set_bool(settings, FreeRDP_SoundBeepsEnabled, TRUE) ||
|
| 1036 |
+
!freerdp_settings_set_bool(settings, FreeRDP_DrawGdiPlusEnabled, FALSE) ||
|
| 1037 |
+
!freerdp_settings_set_bool(settings, FreeRDP_DrawAllowSkipAlpha, TRUE) ||
|
| 1038 |
+
!freerdp_settings_set_bool(settings, FreeRDP_DrawAllowColorSubsampling, FALSE) ||
|
| 1039 |
+
!freerdp_settings_set_bool(settings, FreeRDP_DrawAllowDynamicColorFidelity, TRUE) ||
|
| 1040 |
+
!freerdp_settings_set_bool(settings, FreeRDP_FrameMarkerCommandEnabled, TRUE) ||
|
| 1041 |
+
!freerdp_settings_set_bool(settings, FreeRDP_SurfaceFrameMarkerEnabled, TRUE) ||
|
| 1042 |
+
!freerdp_settings_set_bool(settings, FreeRDP_AllowCacheWaitingList, TRUE) ||
|
| 1043 |
+
!freerdp_settings_set_uint32(settings, FreeRDP_BitmapCacheV2NumCells, 5))
|
| 1044 |
+
goto out_fail;
|
| 1045 |
+
settings->BitmapCacheV2CellInfo =
|
| 1046 |
+
(BITMAP_CACHE_V2_CELL_INFO*)calloc(6, sizeof(BITMAP_CACHE_V2_CELL_INFO));
|
| 1047 |
+
|
| 1048 |
+
if (!settings->BitmapCacheV2CellInfo)
|
| 1049 |
+
goto out_fail;
|
| 1050 |
+
|
| 1051 |
+
{
|
| 1052 |
+
BITMAP_CACHE_V2_CELL_INFO cache = { 0 };
|
| 1053 |
+
cache.numEntries = 600;
|
| 1054 |
+
if (!freerdp_settings_set_pointer_array(settings, FreeRDP_BitmapCacheV2CellInfo, 0,
|
| 1055 |
+
&cache) ||
|
| 1056 |
+
!freerdp_settings_set_pointer_array(settings, FreeRDP_BitmapCacheV2CellInfo, 1, &cache))
|
| 1057 |
+
goto out_fail;
|
| 1058 |
+
cache.numEntries = 2048;
|
| 1059 |
+
if (!freerdp_settings_set_pointer_array(settings, FreeRDP_BitmapCacheV2CellInfo, 2,
|
| 1060 |
+
&cache) ||
|
| 1061 |
+
!freerdp_settings_set_pointer_array(settings, FreeRDP_BitmapCacheV2CellInfo, 4, &cache))
|
| 1062 |
+
goto out_fail;
|
| 1063 |
+
cache.numEntries = 4096;
|
| 1064 |
+
if (!freerdp_settings_set_pointer_array(settings, FreeRDP_BitmapCacheV2CellInfo, 3, &cache))
|
| 1065 |
+
goto out_fail;
|
| 1066 |
+
}
|
| 1067 |
+
if (!freerdp_settings_set_bool(settings, FreeRDP_NoBitmapCompressionHeader, TRUE) ||
|
| 1068 |
+
!freerdp_settings_set_bool(settings, FreeRDP_RefreshRect, TRUE) ||
|
| 1069 |
+
!freerdp_settings_set_bool(settings, FreeRDP_SuppressOutput, TRUE) ||
|
| 1070 |
+
!freerdp_settings_set_uint32(settings, FreeRDP_GlyphSupportLevel, GLYPH_SUPPORT_NONE))
|
| 1071 |
+
goto out_fail;
|
| 1072 |
+
settings->GlyphCache = calloc(10, sizeof(GLYPH_CACHE_DEFINITION));
|
| 1073 |
+
|
| 1074 |
+
if (!settings->GlyphCache)
|
| 1075 |
+
goto out_fail;
|
| 1076 |
+
|
| 1077 |
+
settings->FragCache = calloc(1, sizeof(GLYPH_CACHE_DEFINITION));
|
| 1078 |
+
|
| 1079 |
+
if (!settings->FragCache)
|
| 1080 |
+
goto out_fail;
|
| 1081 |
+
|
| 1082 |
+
for (size_t x = 0; x < 10; x++)
|
| 1083 |
+
{
|
| 1084 |
+
GLYPH_CACHE_DEFINITION cache = { 0 };
|
| 1085 |
+
cache.cacheEntries = 254;
|
| 1086 |
+
switch (x)
|
| 1087 |
+
{
|
| 1088 |
+
case 0:
|
| 1089 |
+
case 1:
|
| 1090 |
+
cache.cacheMaximumCellSize = 4;
|
| 1091 |
+
break;
|
| 1092 |
+
case 2:
|
| 1093 |
+
case 3:
|
| 1094 |
+
cache.cacheMaximumCellSize = 8;
|
| 1095 |
+
break;
|
| 1096 |
+
case 4:
|
| 1097 |
+
cache.cacheMaximumCellSize = 16;
|
| 1098 |
+
break;
|
| 1099 |
+
case 5:
|
| 1100 |
+
cache.cacheMaximumCellSize = 32;
|
| 1101 |
+
break;
|
| 1102 |
+
case 6:
|
| 1103 |
+
cache.cacheMaximumCellSize = 64;
|
| 1104 |
+
break;
|
| 1105 |
+
case 7:
|
| 1106 |
+
cache.cacheMaximumCellSize = 128;
|
| 1107 |
+
break;
|
| 1108 |
+
case 8:
|
| 1109 |
+
cache.cacheMaximumCellSize = 256;
|
| 1110 |
+
break;
|
| 1111 |
+
case 9:
|
| 1112 |
+
cache.cacheMaximumCellSize = 256;
|
| 1113 |
+
break;
|
| 1114 |
+
default:
|
| 1115 |
+
goto out_fail;
|
| 1116 |
+
}
|
| 1117 |
+
|
| 1118 |
+
if (!freerdp_settings_set_pointer_array(settings, FreeRDP_GlyphCache, x, &cache))
|
| 1119 |
+
goto out_fail;
|
| 1120 |
+
}
|
| 1121 |
+
{
|
| 1122 |
+
GLYPH_CACHE_DEFINITION cache = { 0 };
|
| 1123 |
+
cache.cacheEntries = 256;
|
| 1124 |
+
cache.cacheMaximumCellSize = 256;
|
| 1125 |
+
if (!freerdp_settings_set_pointer_array(settings, FreeRDP_FragCache, 0, &cache))
|
| 1126 |
+
goto out_fail;
|
| 1127 |
+
}
|
| 1128 |
+
if (!freerdp_settings_set_uint32(settings, FreeRDP_OffscreenSupportLevel, 0) ||
|
| 1129 |
+
!freerdp_settings_set_uint32(settings, FreeRDP_OffscreenCacheSize, 7680) ||
|
| 1130 |
+
!freerdp_settings_set_uint32(settings, FreeRDP_OffscreenCacheEntries, 2000) ||
|
| 1131 |
+
!freerdp_settings_set_uint32(settings, FreeRDP_DrawNineGridCacheSize, 2560) ||
|
| 1132 |
+
!freerdp_settings_set_uint32(settings, FreeRDP_DrawNineGridCacheEntries, 256) ||
|
| 1133 |
+
!freerdp_settings_set_string(settings, FreeRDP_ClientDir, client_dll) ||
|
| 1134 |
+
!freerdp_settings_get_string(settings, FreeRDP_ClientDir) ||
|
| 1135 |
+
!freerdp_settings_set_uint32(settings, FreeRDP_RemoteWndSupportLevel,
|
| 1136 |
+
WINDOW_LEVEL_SUPPORTED | WINDOW_LEVEL_SUPPORTED_EX) ||
|
| 1137 |
+
!freerdp_settings_set_uint32(settings, FreeRDP_RemoteAppNumIconCaches, 3) ||
|
| 1138 |
+
!freerdp_settings_set_uint32(settings, FreeRDP_RemoteAppNumIconCacheEntries, 12) ||
|
| 1139 |
+
!freerdp_settings_set_uint32(settings, FreeRDP_VCChunkSize,
|
| 1140 |
+
(server && !remote) ? CHANNEL_CHUNK_MAX_LENGTH
|
| 1141 |
+
: CHANNEL_CHUNK_LENGTH) ||
|
| 1142 |
+
/* [MS-RDPBCGR] 2.2.7.2.7 Large Pointer Capability Set (TS_LARGE_POINTER_CAPABILITYSET)
|
| 1143 |
+
requires at least this size */
|
| 1144 |
+
!freerdp_settings_set_uint32(settings, FreeRDP_MultifragMaxRequestSize,
|
| 1145 |
+
server ? 0 : 608299) ||
|
| 1146 |
+
!freerdp_settings_set_bool(settings, FreeRDP_GatewayUseSameCredentials, FALSE) ||
|
| 1147 |
+
!freerdp_settings_set_bool(settings, FreeRDP_GatewayBypassLocal, FALSE) ||
|
| 1148 |
+
!freerdp_settings_set_bool(settings, FreeRDP_GatewayRpcTransport, TRUE) ||
|
| 1149 |
+
!freerdp_settings_set_bool(settings, FreeRDP_GatewayHttpTransport, TRUE) ||
|
| 1150 |
+
!freerdp_settings_set_bool(settings, FreeRDP_GatewayUdpTransport, TRUE) ||
|
| 1151 |
+
!freerdp_settings_set_bool(settings, FreeRDP_GatewayHttpUseWebsockets, TRUE) ||
|
| 1152 |
+
!freerdp_settings_set_bool(settings, FreeRDP_GatewayHttpExtAuthSspiNtlm, FALSE) ||
|
| 1153 |
+
!freerdp_settings_set_bool(settings, FreeRDP_GatewayArmTransport, FALSE) ||
|
| 1154 |
+
!freerdp_settings_set_bool(settings, FreeRDP_FastPathInput, TRUE) ||
|
| 1155 |
+
!freerdp_settings_set_bool(settings, FreeRDP_FastPathOutput, TRUE) ||
|
| 1156 |
+
!freerdp_settings_set_bool(settings, FreeRDP_LongCredentialsSupported, TRUE) ||
|
| 1157 |
+
!freerdp_settings_set_uint32(settings, FreeRDP_FrameAcknowledge, 2) ||
|
| 1158 |
+
!freerdp_settings_set_bool(settings, FreeRDP_MouseMotion, TRUE) ||
|
| 1159 |
+
!freerdp_settings_set_uint32(settings, FreeRDP_NSCodecColorLossLevel, 3) ||
|
| 1160 |
+
!freerdp_settings_set_bool(settings, FreeRDP_NSCodecAllowSubsampling, TRUE) ||
|
| 1161 |
+
!freerdp_settings_set_bool(settings, FreeRDP_NSCodecAllowDynamicColorFidelity, TRUE) ||
|
| 1162 |
+
!freerdp_settings_set_bool(settings, FreeRDP_AutoReconnectionEnabled, FALSE) ||
|
| 1163 |
+
!freerdp_settings_set_uint32(settings, FreeRDP_AutoReconnectMaxRetries, 20) ||
|
| 1164 |
+
!freerdp_settings_set_bool(settings, FreeRDP_GfxThinClient, FALSE) ||
|
| 1165 |
+
!freerdp_settings_set_bool(settings, FreeRDP_GfxSmallCache, TRUE) ||
|
| 1166 |
+
!freerdp_settings_set_bool(settings, FreeRDP_GfxProgressive, FALSE) ||
|
| 1167 |
+
!freerdp_settings_set_bool(settings, FreeRDP_GfxProgressiveV2, FALSE) ||
|
| 1168 |
+
!freerdp_settings_set_bool(settings, FreeRDP_GfxPlanar, TRUE) ||
|
| 1169 |
+
!freerdp_settings_set_bool(settings, FreeRDP_GfxH264, FALSE) ||
|
| 1170 |
+
!freerdp_settings_set_bool(settings, FreeRDP_GfxAVC444, FALSE) ||
|
| 1171 |
+
!freerdp_settings_set_bool(settings, FreeRDP_GfxSendQoeAck, FALSE))
|
| 1172 |
+
goto out_fail;
|
| 1173 |
+
{
|
| 1174 |
+
ARC_CS_PRIVATE_PACKET cookie = { 0 };
|
| 1175 |
+
if (!freerdp_settings_set_pointer_len(settings, FreeRDP_ClientAutoReconnectCookie, &cookie,
|
| 1176 |
+
1))
|
| 1177 |
+
goto out_fail;
|
| 1178 |
+
}
|
| 1179 |
+
{
|
| 1180 |
+
ARC_SC_PRIVATE_PACKET cookie = { 0 };
|
| 1181 |
+
if (!freerdp_settings_set_pointer_len(settings, FreeRDP_ServerAutoReconnectCookie, &cookie,
|
| 1182 |
+
1))
|
| 1183 |
+
goto out_fail;
|
| 1184 |
+
}
|
| 1185 |
+
|
| 1186 |
+
settings->ClientTimeZone = (LPTIME_ZONE_INFORMATION)calloc(1, sizeof(TIME_ZONE_INFORMATION));
|
| 1187 |
+
|
| 1188 |
+
if (!settings->ClientTimeZone)
|
| 1189 |
+
goto out_fail;
|
| 1190 |
+
|
| 1191 |
+
if (!settings->ServerMode)
|
| 1192 |
+
{
|
| 1193 |
+
DYNAMIC_TIME_ZONE_INFORMATION dynamic = { 0 };
|
| 1194 |
+
TIME_ZONE_INFORMATION* tz =
|
| 1195 |
+
freerdp_settings_get_pointer_writable(settings, FreeRDP_ClientTimeZone);
|
| 1196 |
+
WINPR_ASSERT(tz);
|
| 1197 |
+
|
| 1198 |
+
GetTimeZoneInformation(tz);
|
| 1199 |
+
GetDynamicTimeZoneInformation(&dynamic);
|
| 1200 |
+
|
| 1201 |
+
if (!freerdp_settings_set_string_from_utf16N(settings, FreeRDP_DynamicDSTTimeZoneKeyName,
|
| 1202 |
+
dynamic.TimeZoneKeyName,
|
| 1203 |
+
ARRAYSIZE(dynamic.TimeZoneKeyName)))
|
| 1204 |
+
goto out_fail;
|
| 1205 |
+
|
| 1206 |
+
if (!freerdp_settings_set_bool(settings, FreeRDP_DynamicDaylightTimeDisabled,
|
| 1207 |
+
dynamic.DynamicDaylightTimeDisabled))
|
| 1208 |
+
goto out_fail;
|
| 1209 |
+
}
|
| 1210 |
+
|
| 1211 |
+
if (!freerdp_settings_set_bool(settings, FreeRDP_TcpKeepAlive, TRUE) ||
|
| 1212 |
+
!freerdp_settings_set_uint32(settings, FreeRDP_TcpKeepAliveRetries, 3) ||
|
| 1213 |
+
!freerdp_settings_set_uint32(settings, FreeRDP_TcpKeepAliveDelay, 5) ||
|
| 1214 |
+
!freerdp_settings_set_uint32(settings, FreeRDP_TcpKeepAliveInterval, 2) ||
|
| 1215 |
+
!freerdp_settings_set_uint32(settings, FreeRDP_TcpAckTimeout, 9000) ||
|
| 1216 |
+
!freerdp_settings_set_uint32(settings, FreeRDP_TcpConnectTimeout, 15000))
|
| 1217 |
+
goto out_fail;
|
| 1218 |
+
|
| 1219 |
+
if (!freerdp_settings_get_bool(settings, FreeRDP_ServerMode))
|
| 1220 |
+
{
|
| 1221 |
+
BOOL rc = FALSE;
|
| 1222 |
+
char* path = NULL;
|
| 1223 |
+
if (!freerdp_settings_set_bool(settings, FreeRDP_RedirectClipboard, TRUE))
|
| 1224 |
+
goto out_fail;
|
| 1225 |
+
/* these values are used only by the client part */
|
| 1226 |
+
path = GetKnownPath(KNOWN_PATH_HOME);
|
| 1227 |
+
rc = freerdp_settings_set_string(settings, FreeRDP_HomePath, path);
|
| 1228 |
+
free(path);
|
| 1229 |
+
|
| 1230 |
+
if (!rc || !freerdp_settings_get_string(settings, FreeRDP_HomePath))
|
| 1231 |
+
goto out_fail;
|
| 1232 |
+
|
| 1233 |
+
char* config = freerdp_settings_get_config_path();
|
| 1234 |
+
rc = freerdp_settings_set_string(settings, FreeRDP_ConfigPath, config);
|
| 1235 |
+
if (rc)
|
| 1236 |
+
{
|
| 1237 |
+
char* action = GetCombinedPath(config, "action.sh");
|
| 1238 |
+
rc = freerdp_settings_set_string(settings, FreeRDP_ActionScript, action);
|
| 1239 |
+
free(action);
|
| 1240 |
+
}
|
| 1241 |
+
|
| 1242 |
+
free(config);
|
| 1243 |
+
if (!rc)
|
| 1244 |
+
goto out_fail;
|
| 1245 |
+
}
|
| 1246 |
+
|
| 1247 |
+
settings_load_hkey_local_machine(settings);
|
| 1248 |
+
|
| 1249 |
+
if (!freerdp_settings_set_bool(settings, FreeRDP_SmartcardLogon, FALSE))
|
| 1250 |
+
goto out_fail;
|
| 1251 |
+
if (!freerdp_settings_set_uint32(settings, FreeRDP_TlsSecLevel, 1))
|
| 1252 |
+
goto out_fail;
|
| 1253 |
+
settings->OrderSupport = calloc(1, 32);
|
| 1254 |
+
|
| 1255 |
+
if (!freerdp_settings_set_uint16(settings, FreeRDP_TLSMinVersion, TLS1_VERSION))
|
| 1256 |
+
goto out_fail;
|
| 1257 |
+
if (!freerdp_settings_set_uint16(settings, FreeRDP_TLSMaxVersion, 0))
|
| 1258 |
+
goto out_fail;
|
| 1259 |
+
|
| 1260 |
+
if (!settings->OrderSupport)
|
| 1261 |
+
goto out_fail;
|
| 1262 |
+
|
| 1263 |
+
if (!freerdp_settings_set_default_order_support(settings))
|
| 1264 |
+
goto out_fail;
|
| 1265 |
+
|
| 1266 |
+
const BOOL enable = freerdp_settings_get_bool(settings, FreeRDP_ServerMode);
|
| 1267 |
+
|
| 1268 |
+
{
|
| 1269 |
+
const FreeRDP_Settings_Keys_Bool keys[] = { FreeRDP_SupportGraphicsPipeline,
|
| 1270 |
+
FreeRDP_SupportStatusInfoPdu,
|
| 1271 |
+
FreeRDP_SupportErrorInfoPdu,
|
| 1272 |
+
FreeRDP_SupportAsymetricKeys };
|
| 1273 |
+
|
| 1274 |
+
for (size_t x = 0; x < ARRAYSIZE(keys); x++)
|
| 1275 |
+
{
|
| 1276 |
+
if (!freerdp_settings_set_bool(settings, keys[x], enable))
|
| 1277 |
+
goto out_fail;
|
| 1278 |
+
}
|
| 1279 |
+
}
|
| 1280 |
+
|
| 1281 |
+
if (!freerdp_settings_set_bool(settings, FreeRDP_SupportDynamicTimeZone, TRUE))
|
| 1282 |
+
goto out_fail;
|
| 1283 |
+
if (!freerdp_settings_set_bool(settings, FreeRDP_SupportSkipChannelJoin, TRUE))
|
| 1284 |
+
goto out_fail;
|
| 1285 |
+
|
| 1286 |
+
return settings;
|
| 1287 |
+
out_fail:
|
| 1288 |
+
WINPR_PRAGMA_DIAG_PUSH
|
| 1289 |
+
WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
|
| 1290 |
+
freerdp_settings_free(settings);
|
| 1291 |
+
WINPR_PRAGMA_DIAG_POP
|
| 1292 |
+
return NULL;
|
| 1293 |
+
}
|
| 1294 |
+
|
| 1295 |
+
static void freerdp_settings_free_internal(rdpSettings* settings)
|
| 1296 |
+
{
|
| 1297 |
+
freerdp_server_license_issuers_free(settings);
|
| 1298 |
+
freerdp_target_net_addresses_free(settings);
|
| 1299 |
+
freerdp_device_collection_free(settings);
|
| 1300 |
+
freerdp_static_channel_collection_free(settings);
|
| 1301 |
+
freerdp_dynamic_channel_collection_free(settings);
|
| 1302 |
+
|
| 1303 |
+
freerdp_capability_buffer_free(settings);
|
| 1304 |
+
|
| 1305 |
+
/* Free all strings, set other pointers NULL */
|
| 1306 |
+
freerdp_settings_free_keys(settings, TRUE);
|
| 1307 |
+
}
|
| 1308 |
+
|
| 1309 |
+
void freerdp_settings_free(rdpSettings* settings)
|
| 1310 |
+
{
|
| 1311 |
+
if (!settings)
|
| 1312 |
+
return;
|
| 1313 |
+
|
| 1314 |
+
freerdp_settings_free_internal(settings);
|
| 1315 |
+
free(settings);
|
| 1316 |
+
}
|
| 1317 |
+
|
| 1318 |
+
static BOOL freerdp_settings_int_buffer_copy(rdpSettings* _settings, const rdpSettings* settings)
|
| 1319 |
+
{
|
| 1320 |
+
BOOL rc = FALSE;
|
| 1321 |
+
|
| 1322 |
+
if (!_settings || !settings)
|
| 1323 |
+
return FALSE;
|
| 1324 |
+
|
| 1325 |
+
typedef struct
|
| 1326 |
+
{
|
| 1327 |
+
FreeRDP_Settings_Keys_UInt32 lenKey;
|
| 1328 |
+
FreeRDP_Settings_Keys_Pointer pointerKey;
|
| 1329 |
+
} PointerDefs;
|
| 1330 |
+
|
| 1331 |
+
PointerDefs pointerDefs[] = {
|
| 1332 |
+
/* */
|
| 1333 |
+
{ FreeRDP_LoadBalanceInfoLength, FreeRDP_LoadBalanceInfo },
|
| 1334 |
+
{ FreeRDP_ServerRandomLength, FreeRDP_ServerRandom },
|
| 1335 |
+
{ FreeRDP_ClientRandomLength, FreeRDP_ClientRandom },
|
| 1336 |
+
{ FreeRDP_ServerCertificateLength, FreeRDP_ServerCertificate },
|
| 1337 |
+
{ FreeRDP_ChannelDefArraySize, FreeRDP_ChannelDefArray },
|
| 1338 |
+
{ FreeRDP_NumMonitorIds, FreeRDP_MonitorIds },
|
| 1339 |
+
{ FreeRDP_BitmapCacheV2NumCells, FreeRDP_BitmapCacheV2CellInfo },
|
| 1340 |
+
{ FreeRDP_RedirectionPasswordLength, FreeRDP_RedirectionPassword },
|
| 1341 |
+
{ FreeRDP_RedirectionTsvUrlLength, FreeRDP_RedirectionTsvUrl },
|
| 1342 |
+
{ FreeRDP_RedirectionGuidLength, FreeRDP_RedirectionGuid },
|
| 1343 |
+
{ FreeRDP_MonitorDefArraySize, FreeRDP_MonitorDefArray }
|
| 1344 |
+
};
|
| 1345 |
+
|
| 1346 |
+
for (size_t i = 0; i < ARRAYSIZE(pointerDefs); i++)
|
| 1347 |
+
{
|
| 1348 |
+
const PointerDefs* keys = &pointerDefs[i];
|
| 1349 |
+
UINT32 n = freerdp_settings_get_uint32(settings, keys->lenKey);
|
| 1350 |
+
|
| 1351 |
+
const void* ptr = freerdp_settings_get_pointer(settings, keys->pointerKey);
|
| 1352 |
+
if (!freerdp_settings_set_pointer_len(_settings, keys->pointerKey, ptr, n))
|
| 1353 |
+
goto out_fail;
|
| 1354 |
+
}
|
| 1355 |
+
|
| 1356 |
+
if (!freerdp_server_license_issuers_copy(_settings, settings->ServerLicenseProductIssuers,
|
| 1357 |
+
settings->ServerLicenseProductIssuersCount))
|
| 1358 |
+
return FALSE;
|
| 1359 |
+
|
| 1360 |
+
if (settings->RdpServerCertificate)
|
| 1361 |
+
{
|
| 1362 |
+
rdpCertificate* cert = freerdp_certificate_clone(settings->RdpServerCertificate);
|
| 1363 |
+
if (!cert)
|
| 1364 |
+
goto out_fail;
|
| 1365 |
+
if (!freerdp_settings_set_pointer_len(_settings, FreeRDP_RdpServerCertificate, cert, 1))
|
| 1366 |
+
goto out_fail;
|
| 1367 |
+
}
|
| 1368 |
+
else
|
| 1369 |
+
{
|
| 1370 |
+
if (!freerdp_settings_set_pointer_len(_settings, FreeRDP_RdpServerCertificate, NULL, 0))
|
| 1371 |
+
goto out_fail;
|
| 1372 |
+
}
|
| 1373 |
+
|
| 1374 |
+
if (settings->RdpServerRsaKey)
|
| 1375 |
+
{
|
| 1376 |
+
rdpPrivateKey* key = freerdp_key_clone(settings->RdpServerRsaKey);
|
| 1377 |
+
if (!key)
|
| 1378 |
+
goto out_fail;
|
| 1379 |
+
if (!freerdp_settings_set_pointer_len(_settings, FreeRDP_RdpServerRsaKey, key, 1))
|
| 1380 |
+
goto out_fail;
|
| 1381 |
+
}
|
| 1382 |
+
else
|
| 1383 |
+
{
|
| 1384 |
+
if (!freerdp_settings_set_pointer_len(_settings, FreeRDP_RdpServerRsaKey, NULL, 0))
|
| 1385 |
+
goto out_fail;
|
| 1386 |
+
}
|
| 1387 |
+
|
| 1388 |
+
if (!freerdp_settings_set_uint32(_settings, FreeRDP_ChannelCount,
|
| 1389 |
+
freerdp_settings_get_uint32(settings, FreeRDP_ChannelCount)))
|
| 1390 |
+
goto out_fail;
|
| 1391 |
+
|
| 1392 |
+
_settings->OrderSupport = malloc(32);
|
| 1393 |
+
if (!_settings->OrderSupport)
|
| 1394 |
+
goto out_fail;
|
| 1395 |
+
|
| 1396 |
+
if (!freerdp_capability_buffer_copy(_settings, settings))
|
| 1397 |
+
goto out_fail;
|
| 1398 |
+
CopyMemory(_settings->OrderSupport, settings->OrderSupport, 32);
|
| 1399 |
+
|
| 1400 |
+
const UINT32 glyphCacheCount = 10;
|
| 1401 |
+
const GLYPH_CACHE_DEFINITION* glyphCache =
|
| 1402 |
+
freerdp_settings_get_pointer(settings, FreeRDP_GlyphCache);
|
| 1403 |
+
if (!freerdp_settings_set_pointer_len(_settings, FreeRDP_GlyphCache, glyphCache,
|
| 1404 |
+
glyphCacheCount))
|
| 1405 |
+
goto out_fail;
|
| 1406 |
+
|
| 1407 |
+
const UINT32 fragCacheCount = 1;
|
| 1408 |
+
const GLYPH_CACHE_DEFINITION* fragCache =
|
| 1409 |
+
freerdp_settings_get_pointer(settings, FreeRDP_FragCache);
|
| 1410 |
+
if (!freerdp_settings_set_pointer_len(_settings, FreeRDP_FragCache, fragCache, fragCacheCount))
|
| 1411 |
+
goto out_fail;
|
| 1412 |
+
|
| 1413 |
+
if (!freerdp_settings_set_pointer_len(
|
| 1414 |
+
_settings, FreeRDP_ClientAutoReconnectCookie,
|
| 1415 |
+
freerdp_settings_get_pointer(settings, FreeRDP_ClientAutoReconnectCookie), 1))
|
| 1416 |
+
goto out_fail;
|
| 1417 |
+
if (!freerdp_settings_set_pointer_len(
|
| 1418 |
+
_settings, FreeRDP_ServerAutoReconnectCookie,
|
| 1419 |
+
freerdp_settings_get_pointer(settings, FreeRDP_ServerAutoReconnectCookie), 1))
|
| 1420 |
+
goto out_fail;
|
| 1421 |
+
|
| 1422 |
+
const TIME_ZONE_INFORMATION* tz =
|
| 1423 |
+
freerdp_settings_get_pointer(settings, FreeRDP_ClientTimeZone);
|
| 1424 |
+
if (!freerdp_settings_set_pointer_len(_settings, FreeRDP_ClientTimeZone, tz, 1))
|
| 1425 |
+
goto out_fail;
|
| 1426 |
+
|
| 1427 |
+
const UINT32 nrports = freerdp_settings_get_uint32(settings, FreeRDP_TargetNetAddressCount);
|
| 1428 |
+
if (!freerdp_target_net_adresses_reset(_settings, nrports))
|
| 1429 |
+
return FALSE;
|
| 1430 |
+
|
| 1431 |
+
for (UINT32 i = 0; i < nrports; i++)
|
| 1432 |
+
{
|
| 1433 |
+
const char* address =
|
| 1434 |
+
freerdp_settings_get_pointer_array(settings, FreeRDP_TargetNetAddresses, i);
|
| 1435 |
+
const UINT32* port =
|
| 1436 |
+
freerdp_settings_get_pointer_array(settings, FreeRDP_TargetNetPorts, i);
|
| 1437 |
+
if (!freerdp_settings_set_pointer_array(_settings, FreeRDP_TargetNetAddresses, i, address))
|
| 1438 |
+
return FALSE;
|
| 1439 |
+
if (!freerdp_settings_set_pointer_array(_settings, FreeRDP_TargetNetPorts, i, port))
|
| 1440 |
+
return FALSE;
|
| 1441 |
+
}
|
| 1442 |
+
|
| 1443 |
+
{
|
| 1444 |
+
const UINT32 len = freerdp_settings_get_uint32(_settings, FreeRDP_DeviceArraySize);
|
| 1445 |
+
const UINT32 count = freerdp_settings_get_uint32(settings, FreeRDP_DeviceCount);
|
| 1446 |
+
|
| 1447 |
+
if (len < count)
|
| 1448 |
+
goto out_fail;
|
| 1449 |
+
if (!freerdp_settings_set_pointer_len(_settings, FreeRDP_DeviceArray, NULL, len))
|
| 1450 |
+
goto out_fail;
|
| 1451 |
+
if (!freerdp_settings_set_uint32(_settings, FreeRDP_DeviceCount, count))
|
| 1452 |
+
goto out_fail;
|
| 1453 |
+
|
| 1454 |
+
for (size_t index = 0; index < count; index++)
|
| 1455 |
+
{
|
| 1456 |
+
const RDPDR_DEVICE* argv =
|
| 1457 |
+
freerdp_settings_get_pointer_array(settings, FreeRDP_DeviceArray, index);
|
| 1458 |
+
if (!freerdp_settings_set_pointer_array(_settings, FreeRDP_DeviceArray, index, argv))
|
| 1459 |
+
goto out_fail;
|
| 1460 |
+
}
|
| 1461 |
+
}
|
| 1462 |
+
{
|
| 1463 |
+
const UINT32 len = freerdp_settings_get_uint32(_settings, FreeRDP_StaticChannelArraySize);
|
| 1464 |
+
const UINT32 count = freerdp_settings_get_uint32(settings, FreeRDP_StaticChannelCount);
|
| 1465 |
+
|
| 1466 |
+
if (len < count)
|
| 1467 |
+
goto out_fail;
|
| 1468 |
+
if (!freerdp_settings_set_pointer_len(_settings, FreeRDP_StaticChannelArray, NULL, len))
|
| 1469 |
+
goto out_fail;
|
| 1470 |
+
if (!freerdp_settings_set_uint32(_settings, FreeRDP_StaticChannelCount, count))
|
| 1471 |
+
goto out_fail;
|
| 1472 |
+
|
| 1473 |
+
for (size_t index = 0; index < count; index++)
|
| 1474 |
+
{
|
| 1475 |
+
const ADDIN_ARGV* argv =
|
| 1476 |
+
freerdp_settings_get_pointer_array(settings, FreeRDP_StaticChannelArray, index);
|
| 1477 |
+
if (!freerdp_settings_set_pointer_array(_settings, FreeRDP_StaticChannelArray, index,
|
| 1478 |
+
argv))
|
| 1479 |
+
goto out_fail;
|
| 1480 |
+
}
|
| 1481 |
+
}
|
| 1482 |
+
{
|
| 1483 |
+
const UINT32 len = freerdp_settings_get_uint32(_settings, FreeRDP_DynamicChannelArraySize);
|
| 1484 |
+
const UINT32 count = freerdp_settings_get_uint32(settings, FreeRDP_DynamicChannelCount);
|
| 1485 |
+
|
| 1486 |
+
if (len < count)
|
| 1487 |
+
goto out_fail;
|
| 1488 |
+
if (!freerdp_settings_set_pointer_len(_settings, FreeRDP_DynamicChannelArray, NULL, len))
|
| 1489 |
+
goto out_fail;
|
| 1490 |
+
if (!freerdp_settings_set_uint32(_settings, FreeRDP_DynamicChannelCount, count))
|
| 1491 |
+
goto out_fail;
|
| 1492 |
+
|
| 1493 |
+
for (size_t index = 0; index < count; index++)
|
| 1494 |
+
{
|
| 1495 |
+
const ADDIN_ARGV* argv =
|
| 1496 |
+
freerdp_settings_get_pointer_array(settings, FreeRDP_DynamicChannelArray, index);
|
| 1497 |
+
if (!freerdp_settings_set_pointer_array(_settings, FreeRDP_DynamicChannelArray, index,
|
| 1498 |
+
argv))
|
| 1499 |
+
goto out_fail;
|
| 1500 |
+
}
|
| 1501 |
+
}
|
| 1502 |
+
|
| 1503 |
+
rc = freerdp_settings_set_string(_settings, FreeRDP_ActionScript,
|
| 1504 |
+
freerdp_settings_get_string(settings, FreeRDP_ActionScript));
|
| 1505 |
+
|
| 1506 |
+
out_fail:
|
| 1507 |
+
return rc;
|
| 1508 |
+
}
|
| 1509 |
+
|
| 1510 |
+
BOOL freerdp_settings_copy(rdpSettings* _settings, const rdpSettings* settings)
|
| 1511 |
+
{
|
| 1512 |
+
BOOL rc = 0;
|
| 1513 |
+
|
| 1514 |
+
if (!settings || !_settings)
|
| 1515 |
+
return FALSE;
|
| 1516 |
+
|
| 1517 |
+
/* This is required to free all non string buffers */
|
| 1518 |
+
freerdp_settings_free_internal(_settings);
|
| 1519 |
+
/* This copies everything except allocated non string buffers. reset all allocated buffers to
|
| 1520 |
+
* NULL to fix issues during cleanup */
|
| 1521 |
+
rc = freerdp_settings_clone_keys(_settings, settings);
|
| 1522 |
+
|
| 1523 |
+
_settings->LoadBalanceInfo = NULL;
|
| 1524 |
+
_settings->ServerRandom = NULL;
|
| 1525 |
+
_settings->ClientRandom = NULL;
|
| 1526 |
+
_settings->ServerCertificate = NULL;
|
| 1527 |
+
_settings->RdpServerCertificate = NULL;
|
| 1528 |
+
_settings->RdpServerRsaKey = NULL;
|
| 1529 |
+
_settings->ChannelDefArray = NULL;
|
| 1530 |
+
_settings->MonitorDefArray = NULL;
|
| 1531 |
+
_settings->MonitorIds = NULL;
|
| 1532 |
+
_settings->OrderSupport = NULL;
|
| 1533 |
+
_settings->BitmapCacheV2CellInfo = NULL;
|
| 1534 |
+
_settings->GlyphCache = NULL;
|
| 1535 |
+
_settings->FragCache = NULL;
|
| 1536 |
+
_settings->ClientAutoReconnectCookie = NULL;
|
| 1537 |
+
_settings->ServerAutoReconnectCookie = NULL;
|
| 1538 |
+
_settings->ClientTimeZone = NULL;
|
| 1539 |
+
_settings->RedirectionPassword = NULL;
|
| 1540 |
+
_settings->RedirectionTsvUrl = NULL;
|
| 1541 |
+
_settings->TargetNetAddresses = NULL;
|
| 1542 |
+
_settings->TargetNetPorts = NULL;
|
| 1543 |
+
_settings->RedirectionGuid = NULL;
|
| 1544 |
+
_settings->DeviceArray = NULL;
|
| 1545 |
+
_settings->StaticChannelArray = NULL;
|
| 1546 |
+
_settings->DynamicChannelArray = NULL;
|
| 1547 |
+
_settings->ReceivedCapabilities = NULL;
|
| 1548 |
+
_settings->ReceivedCapabilityData = NULL;
|
| 1549 |
+
_settings->ReceivedCapabilityDataSizes = NULL;
|
| 1550 |
+
|
| 1551 |
+
_settings->ServerLicenseProductIssuersCount = 0;
|
| 1552 |
+
_settings->ServerLicenseProductIssuers = NULL;
|
| 1553 |
+
|
| 1554 |
+
if (!rc)
|
| 1555 |
+
goto out_fail;
|
| 1556 |
+
|
| 1557 |
+
/* Begin copying */
|
| 1558 |
+
if (!freerdp_settings_int_buffer_copy(_settings, settings))
|
| 1559 |
+
goto out_fail;
|
| 1560 |
+
return TRUE;
|
| 1561 |
+
out_fail:
|
| 1562 |
+
freerdp_settings_free_internal(_settings);
|
| 1563 |
+
return FALSE;
|
| 1564 |
+
}
|
| 1565 |
+
|
| 1566 |
+
rdpSettings* freerdp_settings_clone(const rdpSettings* settings)
|
| 1567 |
+
{
|
| 1568 |
+
rdpSettings* _settings = (rdpSettings*)calloc(1, sizeof(rdpSettings));
|
| 1569 |
+
|
| 1570 |
+
if (!freerdp_settings_copy(_settings, settings))
|
| 1571 |
+
goto out_fail;
|
| 1572 |
+
|
| 1573 |
+
return _settings;
|
| 1574 |
+
out_fail:
|
| 1575 |
+
WINPR_PRAGMA_DIAG_PUSH
|
| 1576 |
+
WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
|
| 1577 |
+
freerdp_settings_free(_settings);
|
| 1578 |
+
WINPR_PRAGMA_DIAG_POP
|
| 1579 |
+
return NULL;
|
| 1580 |
+
}
|
| 1581 |
+
#ifdef _MSC_VER
|
| 1582 |
+
#pragma warning(pop)
|
| 1583 |
+
#endif
|
| 1584 |
+
|
| 1585 |
+
static void zfree(WCHAR* str, size_t len)
|
| 1586 |
+
{
|
| 1587 |
+
if (str)
|
| 1588 |
+
memset(str, 0, len * sizeof(WCHAR));
|
| 1589 |
+
free(str);
|
| 1590 |
+
}
|
| 1591 |
+
|
| 1592 |
+
BOOL identity_set_from_settings_with_pwd(SEC_WINNT_AUTH_IDENTITY* identity,
|
| 1593 |
+
const rdpSettings* settings,
|
| 1594 |
+
FreeRDP_Settings_Keys_String UserId,
|
| 1595 |
+
FreeRDP_Settings_Keys_String DomainId,
|
| 1596 |
+
const WCHAR* Password, size_t pwdLen)
|
| 1597 |
+
{
|
| 1598 |
+
WINPR_ASSERT(identity);
|
| 1599 |
+
WINPR_ASSERT(settings);
|
| 1600 |
+
|
| 1601 |
+
size_t UserLen = 0;
|
| 1602 |
+
size_t DomainLen = 0;
|
| 1603 |
+
|
| 1604 |
+
WCHAR* Username = freerdp_settings_get_string_as_utf16(settings, UserId, &UserLen);
|
| 1605 |
+
WCHAR* Domain = freerdp_settings_get_string_as_utf16(settings, DomainId, &DomainLen);
|
| 1606 |
+
|
| 1607 |
+
const int rc = sspi_SetAuthIdentityWithLengthW(identity, Username, UserLen, Domain, DomainLen,
|
| 1608 |
+
Password, pwdLen);
|
| 1609 |
+
zfree(Username, UserLen);
|
| 1610 |
+
zfree(Domain, DomainLen);
|
| 1611 |
+
if (rc < 0)
|
| 1612 |
+
return FALSE;
|
| 1613 |
+
return TRUE;
|
| 1614 |
+
}
|
| 1615 |
+
|
| 1616 |
+
BOOL identity_set_from_settings(SEC_WINNT_AUTH_IDENTITY_W* identity, const rdpSettings* settings,
|
| 1617 |
+
FreeRDP_Settings_Keys_String UserId,
|
| 1618 |
+
FreeRDP_Settings_Keys_String DomainId,
|
| 1619 |
+
FreeRDP_Settings_Keys_String PwdId)
|
| 1620 |
+
{
|
| 1621 |
+
WINPR_ASSERT(identity);
|
| 1622 |
+
WINPR_ASSERT(settings);
|
| 1623 |
+
|
| 1624 |
+
size_t PwdLen = 0;
|
| 1625 |
+
|
| 1626 |
+
WCHAR* Password = freerdp_settings_get_string_as_utf16(settings, PwdId, &PwdLen);
|
| 1627 |
+
|
| 1628 |
+
const BOOL rc =
|
| 1629 |
+
identity_set_from_settings_with_pwd(identity, settings, UserId, DomainId, Password, PwdLen);
|
| 1630 |
+
zfree(Password, PwdLen);
|
| 1631 |
+
return rc;
|
| 1632 |
+
}
|
| 1633 |
+
|
| 1634 |
+
BOOL identity_set_from_smartcard_hash(SEC_WINNT_AUTH_IDENTITY_W* identity,
|
| 1635 |
+
const rdpSettings* settings,
|
| 1636 |
+
FreeRDP_Settings_Keys_String userId,
|
| 1637 |
+
FreeRDP_Settings_Keys_String domainId,
|
| 1638 |
+
FreeRDP_Settings_Keys_String pwdId, const BYTE* certSha1,
|
| 1639 |
+
size_t sha1len)
|
| 1640 |
+
{
|
| 1641 |
+
#ifdef _WIN32
|
| 1642 |
+
CERT_CREDENTIAL_INFO certInfo = { sizeof(CERT_CREDENTIAL_INFO), { 0 } };
|
| 1643 |
+
LPWSTR marshalledCredentials = NULL;
|
| 1644 |
+
|
| 1645 |
+
memcpy(certInfo.rgbHashOfCert, certSha1, MIN(sha1len, sizeof(certInfo.rgbHashOfCert)));
|
| 1646 |
+
|
| 1647 |
+
if (!CredMarshalCredentialW(CertCredential, &certInfo, &marshalledCredentials))
|
| 1648 |
+
{
|
| 1649 |
+
WLog_ERR(TAG, "error marshalling cert credentials");
|
| 1650 |
+
return FALSE;
|
| 1651 |
+
}
|
| 1652 |
+
|
| 1653 |
+
size_t pwdLen = 0;
|
| 1654 |
+
WCHAR* Password = freerdp_settings_get_string_as_utf16(settings, pwdId, &pwdLen);
|
| 1655 |
+
const int rc = sspi_SetAuthIdentityWithLengthW(
|
| 1656 |
+
identity, marshalledCredentials, _wcslen(marshalledCredentials), NULL, 0, Password, pwdLen);
|
| 1657 |
+
zfree(Password, pwdLen);
|
| 1658 |
+
CredFree(marshalledCredentials);
|
| 1659 |
+
if (rc < 0)
|
| 1660 |
+
return FALSE;
|
| 1661 |
+
|
| 1662 |
+
#else
|
| 1663 |
+
if (!identity_set_from_settings(identity, settings, userId, domainId, pwdId))
|
| 1664 |
+
return FALSE;
|
| 1665 |
+
#endif /* _WIN32 */
|
| 1666 |
+
return TRUE;
|
| 1667 |
+
}
|
| 1668 |
+
|
| 1669 |
+
const char* freerdp_settings_glyph_level_string(UINT32 level, char* buffer, size_t size)
|
| 1670 |
+
{
|
| 1671 |
+
const char* str = "GLYPH_SUPPORT_UNKNOWN";
|
| 1672 |
+
switch (level)
|
| 1673 |
+
{
|
| 1674 |
+
case GLYPH_SUPPORT_NONE:
|
| 1675 |
+
str = "GLYPH_SUPPORT_NONE";
|
| 1676 |
+
break;
|
| 1677 |
+
case GLYPH_SUPPORT_PARTIAL:
|
| 1678 |
+
str = "GLYPH_SUPPORT_PARTIAL";
|
| 1679 |
+
break;
|
| 1680 |
+
case GLYPH_SUPPORT_FULL:
|
| 1681 |
+
str = "GLYPH_SUPPORT_FULL";
|
| 1682 |
+
break;
|
| 1683 |
+
case GLYPH_SUPPORT_ENCODE:
|
| 1684 |
+
str = "GLYPH_SUPPORT_ENCODE";
|
| 1685 |
+
break;
|
| 1686 |
+
default:
|
| 1687 |
+
break;
|
| 1688 |
+
}
|
| 1689 |
+
|
| 1690 |
+
(void)_snprintf(buffer, size, "%s[0x%08" PRIx32 "]", str, level);
|
| 1691 |
+
return buffer;
|
| 1692 |
+
}
|
| 1693 |
+
|
| 1694 |
+
BOOL freerdp_target_net_adresses_reset(rdpSettings* settings, size_t size)
|
| 1695 |
+
{
|
| 1696 |
+
freerdp_target_net_addresses_free(settings);
|
| 1697 |
+
|
| 1698 |
+
if (size > 0)
|
| 1699 |
+
{
|
| 1700 |
+
if (!freerdp_settings_set_pointer_len_(settings, FreeRDP_TargetNetPorts,
|
| 1701 |
+
FreeRDP_UINT32_UNUSED, NULL, size, sizeof(UINT32)))
|
| 1702 |
+
return FALSE;
|
| 1703 |
+
if (!freerdp_settings_set_pointer_len_(settings, FreeRDP_TargetNetAddresses,
|
| 1704 |
+
FreeRDP_TargetNetAddressCount, NULL, size,
|
| 1705 |
+
sizeof(char*)))
|
| 1706 |
+
return FALSE;
|
| 1707 |
+
}
|
| 1708 |
+
return TRUE;
|
| 1709 |
+
}
|
| 1710 |
+
|
| 1711 |
+
BOOL freerdp_settings_enforce_monitor_exists(rdpSettings* settings)
|
| 1712 |
+
{
|
| 1713 |
+
const UINT32 nrIds = freerdp_settings_get_uint32(settings, FreeRDP_NumMonitorIds);
|
| 1714 |
+
const UINT32 count = freerdp_settings_get_uint32(settings, FreeRDP_MonitorCount);
|
| 1715 |
+
const BOOL fullscreen = freerdp_settings_get_bool(settings, FreeRDP_Fullscreen);
|
| 1716 |
+
const BOOL multimon = freerdp_settings_get_bool(settings, FreeRDP_UseMultimon);
|
| 1717 |
+
const BOOL useMonitors = fullscreen || multimon;
|
| 1718 |
+
|
| 1719 |
+
const UINT32 size = freerdp_settings_get_uint32(settings, FreeRDP_MonitorDefArraySize);
|
| 1720 |
+
if (size == 0)
|
| 1721 |
+
{
|
| 1722 |
+
if (!freerdp_settings_set_pointer_len(settings, FreeRDP_MonitorDefArray, NULL, 16))
|
| 1723 |
+
return FALSE;
|
| 1724 |
+
}
|
| 1725 |
+
|
| 1726 |
+
if (nrIds == 0)
|
| 1727 |
+
{
|
| 1728 |
+
if (!freerdp_settings_set_uint32(settings, FreeRDP_NumMonitorIds, 1))
|
| 1729 |
+
return FALSE;
|
| 1730 |
+
}
|
| 1731 |
+
if (!useMonitors || (count == 0))
|
| 1732 |
+
{
|
| 1733 |
+
const UINT32 width = freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth);
|
| 1734 |
+
const UINT32 height = freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight);
|
| 1735 |
+
const UINT32 pwidth = freerdp_settings_get_uint32(settings, FreeRDP_DesktopPhysicalWidth);
|
| 1736 |
+
const UINT32 pheight = freerdp_settings_get_uint32(settings, FreeRDP_DesktopPhysicalHeight);
|
| 1737 |
+
const UINT16 orientation =
|
| 1738 |
+
freerdp_settings_get_uint16(settings, FreeRDP_DesktopOrientation);
|
| 1739 |
+
const UINT32 desktopScaleFactor =
|
| 1740 |
+
freerdp_settings_get_uint32(settings, FreeRDP_DeviceScaleFactor);
|
| 1741 |
+
const UINT32 deviceScaleFactor =
|
| 1742 |
+
freerdp_settings_get_uint32(settings, FreeRDP_DesktopScaleFactor);
|
| 1743 |
+
|
| 1744 |
+
if (!freerdp_settings_set_uint32(settings, FreeRDP_MonitorCount, 1))
|
| 1745 |
+
return FALSE;
|
| 1746 |
+
|
| 1747 |
+
rdpMonitor monitor = { 0 };
|
| 1748 |
+
monitor.x = 0;
|
| 1749 |
+
monitor.y = 0;
|
| 1750 |
+
monitor.width = WINPR_ASSERTING_INT_CAST(int32_t, width);
|
| 1751 |
+
monitor.height = WINPR_ASSERTING_INT_CAST(int32_t, height);
|
| 1752 |
+
monitor.is_primary = TRUE;
|
| 1753 |
+
monitor.orig_screen = 0;
|
| 1754 |
+
monitor.attributes.physicalWidth = pwidth;
|
| 1755 |
+
monitor.attributes.physicalHeight = pheight;
|
| 1756 |
+
monitor.attributes.orientation = orientation;
|
| 1757 |
+
monitor.attributes.desktopScaleFactor = desktopScaleFactor;
|
| 1758 |
+
monitor.attributes.deviceScaleFactor = deviceScaleFactor;
|
| 1759 |
+
if (!freerdp_settings_set_monitor_def_array_sorted(settings, &monitor, 1))
|
| 1760 |
+
return FALSE;
|
| 1761 |
+
}
|
| 1762 |
+
|
| 1763 |
+
return TRUE;
|
| 1764 |
+
}
|
local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/state.c
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* FreeRDP: A Remote Desktop Protocol Implementation
|
| 3 |
+
*
|
| 4 |
+
* RDP state machine types and helper functions
|
| 5 |
+
*
|
| 6 |
+
* Copyright 2022 Armin Novak <[email protected]>
|
| 7 |
+
* Copyright 2022 Thincast Technologies GmbH
|
| 8 |
+
*
|
| 9 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 10 |
+
* you may not use this file except in compliance with the License.
|
| 11 |
+
* You may obtain a copy of the License at
|
| 12 |
+
*
|
| 13 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 14 |
+
*
|
| 15 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 16 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 17 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 18 |
+
* See the License for the specific language governing permissions and
|
| 19 |
+
* limitations under the License.
|
| 20 |
+
*/
|
| 21 |
+
|
| 22 |
+
#include "state.h"
|
| 23 |
+
|
| 24 |
+
#include <winpr/string.h>
|
| 25 |
+
|
| 26 |
+
BOOL state_run_failed(state_run_t status)
|
| 27 |
+
{
|
| 28 |
+
switch (status)
|
| 29 |
+
{
|
| 30 |
+
case STATE_RUN_FAILED:
|
| 31 |
+
case STATE_RUN_QUIT_SESSION:
|
| 32 |
+
return TRUE;
|
| 33 |
+
default:
|
| 34 |
+
return FALSE;
|
| 35 |
+
}
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
BOOL state_run_success(state_run_t status)
|
| 39 |
+
{
|
| 40 |
+
if (status == STATE_RUN_CONTINUE)
|
| 41 |
+
return TRUE;
|
| 42 |
+
return status >= STATE_RUN_SUCCESS;
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
const char* state_run_result_string(state_run_t status, char* buffer, size_t buffersize)
|
| 46 |
+
{
|
| 47 |
+
const char* name = NULL;
|
| 48 |
+
|
| 49 |
+
switch (status)
|
| 50 |
+
{
|
| 51 |
+
case STATE_RUN_ACTIVE:
|
| 52 |
+
name = "STATE_RUN_ACTIVE";
|
| 53 |
+
break;
|
| 54 |
+
case STATE_RUN_REDIRECT:
|
| 55 |
+
name = "STATE_RUN_REDIRECT";
|
| 56 |
+
break;
|
| 57 |
+
case STATE_RUN_SUCCESS:
|
| 58 |
+
name = "STATE_RUN_SUCCESS";
|
| 59 |
+
break;
|
| 60 |
+
case STATE_RUN_FAILED:
|
| 61 |
+
name = "STATE_RUN_FAILED";
|
| 62 |
+
break;
|
| 63 |
+
case STATE_RUN_QUIT_SESSION:
|
| 64 |
+
name = "STATE_RUN_QUIT_SESSION";
|
| 65 |
+
break;
|
| 66 |
+
case STATE_RUN_TRY_AGAIN:
|
| 67 |
+
name = "STATE_RUN_TRY_AGAIN";
|
| 68 |
+
break;
|
| 69 |
+
case STATE_RUN_CONTINUE:
|
| 70 |
+
name = "STATE_RUN_CONTINUE";
|
| 71 |
+
break;
|
| 72 |
+
default:
|
| 73 |
+
name = "STATE_RUN_UNKNOWN";
|
| 74 |
+
break;
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
(void)_snprintf(buffer, buffersize, "%s [%d]", name, status);
|
| 78 |
+
return buffer;
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
BOOL state_run_continue(state_run_t status)
|
| 82 |
+
{
|
| 83 |
+
return (status == STATE_RUN_TRY_AGAIN) || (status == STATE_RUN_CONTINUE) ||
|
| 84 |
+
(status == STATE_RUN_ACTIVE);
|
| 85 |
+
}
|
local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/surface.c
ADDED
|
@@ -0,0 +1,333 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* FreeRDP: A Remote Desktop Protocol Implementation
|
| 3 |
+
* Surface Commands
|
| 4 |
+
*
|
| 5 |
+
* Copyright 2011 Vic Lee
|
| 6 |
+
*
|
| 7 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 8 |
+
* you may not use this file except in compliance with the License.
|
| 9 |
+
* You may obtain a copy of the License at
|
| 10 |
+
*
|
| 11 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
+
*
|
| 13 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 14 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 15 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 16 |
+
* See the License for the specific language governing permissions and
|
| 17 |
+
* limitations under the License.
|
| 18 |
+
*/
|
| 19 |
+
|
| 20 |
+
#include <freerdp/config.h>
|
| 21 |
+
|
| 22 |
+
#include "settings.h"
|
| 23 |
+
|
| 24 |
+
#include <winpr/assert.h>
|
| 25 |
+
#include <winpr/cast.h>
|
| 26 |
+
|
| 27 |
+
#include <freerdp/utils/pcap.h>
|
| 28 |
+
#include <freerdp/log.h>
|
| 29 |
+
|
| 30 |
+
#include "../cache/cache.h"
|
| 31 |
+
#include "surface.h"
|
| 32 |
+
|
| 33 |
+
#define TAG FREERDP_TAG("core.surface")
|
| 34 |
+
|
| 35 |
+
static BOOL update_recv_surfcmd_bitmap_header_ex(wStream* s, TS_COMPRESSED_BITMAP_HEADER_EX* header)
|
| 36 |
+
{
|
| 37 |
+
if (!s || !header)
|
| 38 |
+
return FALSE;
|
| 39 |
+
|
| 40 |
+
if (!Stream_CheckAndLogRequiredLength(TAG, s, 24))
|
| 41 |
+
return FALSE;
|
| 42 |
+
|
| 43 |
+
Stream_Read_UINT32(s, header->highUniqueId);
|
| 44 |
+
Stream_Read_UINT32(s, header->lowUniqueId);
|
| 45 |
+
Stream_Read_UINT64(s, header->tmMilliseconds);
|
| 46 |
+
Stream_Read_UINT64(s, header->tmSeconds);
|
| 47 |
+
return TRUE;
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
static BOOL update_recv_surfcmd_bitmap_ex(wStream* s, TS_BITMAP_DATA_EX* bmp)
|
| 51 |
+
{
|
| 52 |
+
if (!s || !bmp)
|
| 53 |
+
return FALSE;
|
| 54 |
+
|
| 55 |
+
if (!Stream_CheckAndLogRequiredLength(TAG, s, 12))
|
| 56 |
+
return FALSE;
|
| 57 |
+
|
| 58 |
+
Stream_Read_UINT8(s, bmp->bpp);
|
| 59 |
+
Stream_Read_UINT8(s, bmp->flags);
|
| 60 |
+
Stream_Seek(s, 1); /* reserved */
|
| 61 |
+
Stream_Read_UINT8(s, bmp->codecID);
|
| 62 |
+
Stream_Read_UINT16(s, bmp->width);
|
| 63 |
+
Stream_Read_UINT16(s, bmp->height);
|
| 64 |
+
Stream_Read_UINT32(s, bmp->bitmapDataLength);
|
| 65 |
+
|
| 66 |
+
if ((bmp->width == 0) || (bmp->height == 0))
|
| 67 |
+
{
|
| 68 |
+
WLog_ERR(TAG, "invalid size value width=%" PRIu16 ", height=%" PRIu16, bmp->width,
|
| 69 |
+
bmp->height);
|
| 70 |
+
return FALSE;
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
if ((bmp->bpp < 1) || (bmp->bpp > 32))
|
| 74 |
+
{
|
| 75 |
+
WLog_ERR(TAG, "invalid bpp value %" PRIu32 "", bmp->bpp);
|
| 76 |
+
return FALSE;
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
if (bmp->flags & EX_COMPRESSED_BITMAP_HEADER_PRESENT)
|
| 80 |
+
{
|
| 81 |
+
if (!update_recv_surfcmd_bitmap_header_ex(s, &bmp->exBitmapDataHeader))
|
| 82 |
+
return FALSE;
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
bmp->bitmapData = Stream_Pointer(s);
|
| 86 |
+
if (!Stream_SafeSeek(s, bmp->bitmapDataLength))
|
| 87 |
+
{
|
| 88 |
+
WLog_ERR(TAG, "expected bitmapDataLength %" PRIu32 ", not enough data",
|
| 89 |
+
bmp->bitmapDataLength);
|
| 90 |
+
return FALSE;
|
| 91 |
+
}
|
| 92 |
+
return TRUE;
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
static BOOL update_recv_surfcmd_is_rect_valid(const rdpContext* context,
|
| 96 |
+
const SURFACE_BITS_COMMAND* cmd)
|
| 97 |
+
{
|
| 98 |
+
WINPR_ASSERT(context);
|
| 99 |
+
WINPR_ASSERT(context->settings);
|
| 100 |
+
WINPR_ASSERT(cmd);
|
| 101 |
+
|
| 102 |
+
/* We need a rectangle with left/top being smaller than right/bottom.
|
| 103 |
+
* Also do not allow empty rectangles. */
|
| 104 |
+
if ((cmd->destTop >= cmd->destBottom) || (cmd->destLeft >= cmd->destRight))
|
| 105 |
+
{
|
| 106 |
+
WLog_WARN(TAG,
|
| 107 |
+
"Empty surface bits command rectangle: %" PRIu16 "x%" PRIu16 "-%" PRIu16
|
| 108 |
+
"x%" PRIu16,
|
| 109 |
+
cmd->destLeft, cmd->destTop, cmd->destRight, cmd->destBottom);
|
| 110 |
+
return FALSE;
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
/* The rectangle needs to fit into our session size */
|
| 114 |
+
if ((cmd->destRight > context->settings->DesktopWidth) ||
|
| 115 |
+
(cmd->destBottom > context->settings->DesktopHeight))
|
| 116 |
+
{
|
| 117 |
+
WLog_WARN(TAG,
|
| 118 |
+
"Invalid surface bits command rectangle: %" PRIu16 "x%" PRIu16 "-%" PRIu16
|
| 119 |
+
"x%" PRIu16 " does not fit %" PRIu32 "x%" PRIu32,
|
| 120 |
+
cmd->destLeft, cmd->destTop, cmd->destRight, cmd->destBottom,
|
| 121 |
+
context->settings->DesktopWidth, context->settings->DesktopHeight);
|
| 122 |
+
return FALSE;
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
return TRUE;
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
static BOOL update_recv_surfcmd_surface_bits(rdpUpdate* update, wStream* s, UINT16 cmdType)
|
| 129 |
+
{
|
| 130 |
+
BOOL rc = FALSE;
|
| 131 |
+
SURFACE_BITS_COMMAND cmd = { 0 };
|
| 132 |
+
|
| 133 |
+
if (!Stream_CheckAndLogRequiredLength(TAG, s, 8))
|
| 134 |
+
goto fail;
|
| 135 |
+
|
| 136 |
+
cmd.cmdType = cmdType;
|
| 137 |
+
Stream_Read_UINT16(s, cmd.destLeft);
|
| 138 |
+
Stream_Read_UINT16(s, cmd.destTop);
|
| 139 |
+
Stream_Read_UINT16(s, cmd.destRight);
|
| 140 |
+
Stream_Read_UINT16(s, cmd.destBottom);
|
| 141 |
+
|
| 142 |
+
if (!update_recv_surfcmd_is_rect_valid(update->context, &cmd))
|
| 143 |
+
goto fail;
|
| 144 |
+
|
| 145 |
+
if (!update_recv_surfcmd_bitmap_ex(s, &cmd.bmp))
|
| 146 |
+
goto fail;
|
| 147 |
+
|
| 148 |
+
if (!IFCALLRESULT(TRUE, update->SurfaceBits, update->context, &cmd))
|
| 149 |
+
{
|
| 150 |
+
WLog_DBG(TAG, "update->SurfaceBits implementation failed");
|
| 151 |
+
goto fail;
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
rc = TRUE;
|
| 155 |
+
fail:
|
| 156 |
+
return rc;
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
static BOOL update_recv_surfcmd_frame_marker(rdpUpdate* update, wStream* s)
|
| 160 |
+
{
|
| 161 |
+
SURFACE_FRAME_MARKER marker = { 0 };
|
| 162 |
+
rdp_update_internal* up = update_cast(update);
|
| 163 |
+
|
| 164 |
+
WINPR_ASSERT(s);
|
| 165 |
+
|
| 166 |
+
if (!Stream_CheckAndLogRequiredLength(TAG, s, 2))
|
| 167 |
+
return FALSE;
|
| 168 |
+
|
| 169 |
+
Stream_Read_UINT16(s, marker.frameAction);
|
| 170 |
+
if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
|
| 171 |
+
WLog_WARN(TAG,
|
| 172 |
+
"[SERVER-BUG]: got %" PRIuz ", expected %" PRIuz
|
| 173 |
+
" bytes. [MS-RDPBCGR] 2.2.9.2.3 Frame Marker Command (TS_FRAME_MARKER) is "
|
| 174 |
+
"missing frameId, ignoring",
|
| 175 |
+
Stream_GetRemainingLength(s), 4);
|
| 176 |
+
else
|
| 177 |
+
Stream_Read_UINT32(s, marker.frameId);
|
| 178 |
+
WLog_Print(up->log, WLOG_DEBUG, "SurfaceFrameMarker: action: %s (%" PRIu32 ") id: %" PRIu32 "",
|
| 179 |
+
(!marker.frameAction) ? "Begin" : "End", marker.frameAction, marker.frameId);
|
| 180 |
+
|
| 181 |
+
if (!update->SurfaceFrameMarker)
|
| 182 |
+
{
|
| 183 |
+
WINPR_ASSERT(update->context);
|
| 184 |
+
if (freerdp_settings_get_bool(update->context->settings, FreeRDP_DeactivateClientDecoding))
|
| 185 |
+
return TRUE;
|
| 186 |
+
WLog_ERR(TAG, "Missing callback update->SurfaceFrameMarker");
|
| 187 |
+
return FALSE;
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
if (!update->SurfaceFrameMarker(update->context, &marker))
|
| 191 |
+
{
|
| 192 |
+
WLog_DBG(TAG, "update->SurfaceFrameMarker implementation failed");
|
| 193 |
+
return FALSE;
|
| 194 |
+
}
|
| 195 |
+
|
| 196 |
+
return TRUE;
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
int update_recv_surfcmds(rdpUpdate* update, wStream* s)
|
| 200 |
+
{
|
| 201 |
+
UINT16 cmdType = 0;
|
| 202 |
+
rdp_update_internal* up = update_cast(update);
|
| 203 |
+
|
| 204 |
+
WINPR_ASSERT(s);
|
| 205 |
+
|
| 206 |
+
while (Stream_GetRemainingLength(s) >= 2)
|
| 207 |
+
{
|
| 208 |
+
const size_t start = Stream_GetPosition(s);
|
| 209 |
+
const BYTE* mark = Stream_ConstPointer(s);
|
| 210 |
+
|
| 211 |
+
Stream_Read_UINT16(s, cmdType);
|
| 212 |
+
|
| 213 |
+
switch (cmdType)
|
| 214 |
+
{
|
| 215 |
+
case CMDTYPE_SET_SURFACE_BITS:
|
| 216 |
+
case CMDTYPE_STREAM_SURFACE_BITS:
|
| 217 |
+
if (!update_recv_surfcmd_surface_bits(update, s, cmdType))
|
| 218 |
+
return -1;
|
| 219 |
+
|
| 220 |
+
break;
|
| 221 |
+
|
| 222 |
+
case CMDTYPE_FRAME_MARKER:
|
| 223 |
+
if (!update_recv_surfcmd_frame_marker(update, s))
|
| 224 |
+
return -1;
|
| 225 |
+
|
| 226 |
+
break;
|
| 227 |
+
|
| 228 |
+
default:
|
| 229 |
+
WLog_ERR(TAG, "unknown cmdType 0x%04" PRIX16 "", cmdType);
|
| 230 |
+
return -1;
|
| 231 |
+
}
|
| 232 |
+
|
| 233 |
+
if (up->dump_rfx)
|
| 234 |
+
{
|
| 235 |
+
const size_t size = Stream_GetPosition(s) - start;
|
| 236 |
+
/* TODO: treat return values */
|
| 237 |
+
pcap_add_record(up->pcap_rfx, mark, size);
|
| 238 |
+
pcap_flush(up->pcap_rfx);
|
| 239 |
+
}
|
| 240 |
+
}
|
| 241 |
+
|
| 242 |
+
return 0;
|
| 243 |
+
}
|
| 244 |
+
|
| 245 |
+
static BOOL update_write_surfcmd_bitmap_header_ex(wStream* s,
|
| 246 |
+
const TS_COMPRESSED_BITMAP_HEADER_EX* header)
|
| 247 |
+
{
|
| 248 |
+
if (!s || !header)
|
| 249 |
+
return FALSE;
|
| 250 |
+
|
| 251 |
+
if (!Stream_EnsureRemainingCapacity(s, 24))
|
| 252 |
+
return FALSE;
|
| 253 |
+
|
| 254 |
+
Stream_Write_UINT32(s, header->highUniqueId);
|
| 255 |
+
Stream_Write_UINT32(s, header->lowUniqueId);
|
| 256 |
+
Stream_Write_UINT64(s, header->tmMilliseconds);
|
| 257 |
+
Stream_Write_UINT64(s, header->tmSeconds);
|
| 258 |
+
return TRUE;
|
| 259 |
+
}
|
| 260 |
+
|
| 261 |
+
static BOOL update_write_surfcmd_bitmap_ex(wStream* s, const TS_BITMAP_DATA_EX* bmp)
|
| 262 |
+
{
|
| 263 |
+
if (!s || !bmp)
|
| 264 |
+
return FALSE;
|
| 265 |
+
|
| 266 |
+
if (!Stream_EnsureRemainingCapacity(s, 12))
|
| 267 |
+
return FALSE;
|
| 268 |
+
|
| 269 |
+
if (bmp->codecID > UINT8_MAX)
|
| 270 |
+
{
|
| 271 |
+
WLog_ERR(TAG, "Invalid TS_BITMAP_DATA_EX::codecID=0x%04" PRIx16 "", bmp->codecID);
|
| 272 |
+
return FALSE;
|
| 273 |
+
}
|
| 274 |
+
Stream_Write_UINT8(s, bmp->bpp);
|
| 275 |
+
Stream_Write_UINT8(s, bmp->flags);
|
| 276 |
+
Stream_Write_UINT8(s, 0); /* reserved1, reserved2 */
|
| 277 |
+
Stream_Write_UINT8(s, (UINT8)bmp->codecID);
|
| 278 |
+
Stream_Write_UINT16(s, bmp->width);
|
| 279 |
+
Stream_Write_UINT16(s, bmp->height);
|
| 280 |
+
Stream_Write_UINT32(s, bmp->bitmapDataLength);
|
| 281 |
+
|
| 282 |
+
if (bmp->flags & EX_COMPRESSED_BITMAP_HEADER_PRESENT)
|
| 283 |
+
{
|
| 284 |
+
if (!update_write_surfcmd_bitmap_header_ex(s, &bmp->exBitmapDataHeader))
|
| 285 |
+
return FALSE;
|
| 286 |
+
}
|
| 287 |
+
|
| 288 |
+
if (!Stream_EnsureRemainingCapacity(s, bmp->bitmapDataLength))
|
| 289 |
+
return FALSE;
|
| 290 |
+
|
| 291 |
+
Stream_Write(s, bmp->bitmapData, bmp->bitmapDataLength);
|
| 292 |
+
return TRUE;
|
| 293 |
+
}
|
| 294 |
+
|
| 295 |
+
BOOL update_write_surfcmd_surface_bits(wStream* s, const SURFACE_BITS_COMMAND* cmd)
|
| 296 |
+
{
|
| 297 |
+
if (!Stream_EnsureRemainingCapacity(s, SURFCMD_SURFACE_BITS_HEADER_LENGTH))
|
| 298 |
+
return FALSE;
|
| 299 |
+
|
| 300 |
+
WINPR_ASSERT(cmd->cmdType <= UINT16_MAX);
|
| 301 |
+
UINT16 cmdType = (UINT16)cmd->cmdType;
|
| 302 |
+
switch (cmdType)
|
| 303 |
+
{
|
| 304 |
+
case CMDTYPE_SET_SURFACE_BITS:
|
| 305 |
+
case CMDTYPE_STREAM_SURFACE_BITS:
|
| 306 |
+
break;
|
| 307 |
+
default:
|
| 308 |
+
WLog_WARN(TAG,
|
| 309 |
+
"SURFACE_BITS_COMMAND->cmdType 0x%04" PRIx16
|
| 310 |
+
" not allowed, correcting to 0x%04" PRIx16,
|
| 311 |
+
cmdType, CMDTYPE_STREAM_SURFACE_BITS);
|
| 312 |
+
cmdType = CMDTYPE_STREAM_SURFACE_BITS;
|
| 313 |
+
break;
|
| 314 |
+
}
|
| 315 |
+
|
| 316 |
+
Stream_Write_UINT16(s, WINPR_ASSERTING_INT_CAST(uint16_t, cmdType));
|
| 317 |
+
Stream_Write_UINT16(s, WINPR_ASSERTING_INT_CAST(uint16_t, cmd->destLeft));
|
| 318 |
+
Stream_Write_UINT16(s, WINPR_ASSERTING_INT_CAST(uint16_t, cmd->destTop));
|
| 319 |
+
Stream_Write_UINT16(s, WINPR_ASSERTING_INT_CAST(uint16_t, cmd->destRight));
|
| 320 |
+
Stream_Write_UINT16(s, WINPR_ASSERTING_INT_CAST(uint16_t, cmd->destBottom));
|
| 321 |
+
return update_write_surfcmd_bitmap_ex(s, &cmd->bmp);
|
| 322 |
+
}
|
| 323 |
+
|
| 324 |
+
BOOL update_write_surfcmd_frame_marker(wStream* s, UINT16 frameAction, UINT32 frameId)
|
| 325 |
+
{
|
| 326 |
+
if (!Stream_EnsureRemainingCapacity(s, SURFCMD_FRAME_MARKER_LENGTH))
|
| 327 |
+
return FALSE;
|
| 328 |
+
|
| 329 |
+
Stream_Write_UINT16(s, CMDTYPE_FRAME_MARKER);
|
| 330 |
+
Stream_Write_UINT16(s, frameAction);
|
| 331 |
+
Stream_Write_UINT32(s, frameId);
|
| 332 |
+
return TRUE;
|
| 333 |
+
}
|
local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/tcp.c
ADDED
|
@@ -0,0 +1,1545 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* FreeRDP: A Remote Desktop Protocol Implementation
|
| 3 |
+
* Transmission Control Protocol (TCP)
|
| 4 |
+
*
|
| 5 |
+
* Copyright 2011 Vic Lee
|
| 6 |
+
* Copyright 2011 Marc-Andre Moreau <[email protected]>
|
| 7 |
+
*
|
| 8 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 9 |
+
* you may not use this file except in compliance with the License.
|
| 10 |
+
* You may obtain a copy of the License at
|
| 11 |
+
*
|
| 12 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 13 |
+
*
|
| 14 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 15 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 16 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 17 |
+
* See the License for the specific language governing permissions and
|
| 18 |
+
* limitations under the License.
|
| 19 |
+
*/
|
| 20 |
+
|
| 21 |
+
#include <freerdp/config.h>
|
| 22 |
+
|
| 23 |
+
#include "settings.h"
|
| 24 |
+
|
| 25 |
+
#include <time.h>
|
| 26 |
+
#include <errno.h>
|
| 27 |
+
#include <fcntl.h>
|
| 28 |
+
|
| 29 |
+
#include <winpr/crt.h>
|
| 30 |
+
#include <winpr/platform.h>
|
| 31 |
+
#include <winpr/winsock.h>
|
| 32 |
+
|
| 33 |
+
#include "rdp.h"
|
| 34 |
+
#include "utils.h"
|
| 35 |
+
|
| 36 |
+
#if !defined(_WIN32)
|
| 37 |
+
|
| 38 |
+
#include <netdb.h>
|
| 39 |
+
#include <unistd.h>
|
| 40 |
+
#include <sys/ioctl.h>
|
| 41 |
+
#include <sys/socket.h>
|
| 42 |
+
#include <netinet/in.h>
|
| 43 |
+
#include <netinet/tcp.h>
|
| 44 |
+
#include <net/if.h>
|
| 45 |
+
#include <sys/types.h>
|
| 46 |
+
#include <arpa/inet.h>
|
| 47 |
+
|
| 48 |
+
#ifdef WINPR_HAVE_POLL_H
|
| 49 |
+
#include <poll.h>
|
| 50 |
+
#else
|
| 51 |
+
#include <time.h>
|
| 52 |
+
#include <sys/select.h>
|
| 53 |
+
#endif
|
| 54 |
+
|
| 55 |
+
#if defined(__FreeBSD__) || defined(__OpenBSD__)
|
| 56 |
+
#ifndef SOL_TCP
|
| 57 |
+
#define SOL_TCP IPPROTO_TCP
|
| 58 |
+
#endif
|
| 59 |
+
#endif
|
| 60 |
+
|
| 61 |
+
#ifdef __APPLE__
|
| 62 |
+
#ifndef SOL_TCP
|
| 63 |
+
#define SOL_TCP IPPROTO_TCP
|
| 64 |
+
#endif
|
| 65 |
+
#ifndef TCP_KEEPIDLE
|
| 66 |
+
#define TCP_KEEPIDLE TCP_KEEPALIVE
|
| 67 |
+
#endif
|
| 68 |
+
#endif
|
| 69 |
+
|
| 70 |
+
#else
|
| 71 |
+
|
| 72 |
+
#include <winpr/windows.h>
|
| 73 |
+
|
| 74 |
+
#include <winpr/crt.h>
|
| 75 |
+
|
| 76 |
+
#define SHUT_RDWR SD_BOTH
|
| 77 |
+
#define close(_fd) closesocket(_fd)
|
| 78 |
+
|
| 79 |
+
#endif
|
| 80 |
+
|
| 81 |
+
#include <freerdp/log.h>
|
| 82 |
+
|
| 83 |
+
#include <winpr/stream.h>
|
| 84 |
+
|
| 85 |
+
#include "tcp.h"
|
| 86 |
+
#include "../crypto/opensslcompat.h"
|
| 87 |
+
|
| 88 |
+
#if defined(HAVE_AF_VSOCK_H)
|
| 89 |
+
#include <ctype.h>
|
| 90 |
+
#include <linux/vm_sockets.h>
|
| 91 |
+
#endif
|
| 92 |
+
|
| 93 |
+
#define TAG FREERDP_TAG("core")
|
| 94 |
+
|
| 95 |
+
/* Simple Socket BIO */
|
| 96 |
+
|
| 97 |
+
typedef struct
|
| 98 |
+
{
|
| 99 |
+
SOCKET socket;
|
| 100 |
+
HANDLE hEvent;
|
| 101 |
+
} WINPR_BIO_SIMPLE_SOCKET;
|
| 102 |
+
|
| 103 |
+
static int transport_bio_simple_init(BIO* bio, SOCKET socket, int shutdown);
|
| 104 |
+
static int transport_bio_simple_uninit(BIO* bio);
|
| 105 |
+
|
| 106 |
+
static long transport_bio_simple_callback(BIO* bio, int mode, const char* argp, int argi, long argl,
|
| 107 |
+
long ret)
|
| 108 |
+
{
|
| 109 |
+
return 1;
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
static int transport_bio_simple_write(BIO* bio, const char* buf, int size)
|
| 113 |
+
{
|
| 114 |
+
int error = 0;
|
| 115 |
+
int status = 0;
|
| 116 |
+
WINPR_BIO_SIMPLE_SOCKET* ptr = (WINPR_BIO_SIMPLE_SOCKET*)BIO_get_data(bio);
|
| 117 |
+
|
| 118 |
+
if (!buf)
|
| 119 |
+
return 0;
|
| 120 |
+
|
| 121 |
+
BIO_clear_flags(bio, BIO_FLAGS_WRITE);
|
| 122 |
+
status = _send(ptr->socket, buf, size, 0);
|
| 123 |
+
|
| 124 |
+
if (status <= 0)
|
| 125 |
+
{
|
| 126 |
+
error = WSAGetLastError();
|
| 127 |
+
|
| 128 |
+
if ((error == WSAEWOULDBLOCK) || (error == WSAEINTR) || (error == WSAEINPROGRESS) ||
|
| 129 |
+
(error == WSAEALREADY))
|
| 130 |
+
{
|
| 131 |
+
BIO_set_flags(bio, (BIO_FLAGS_WRITE | BIO_FLAGS_SHOULD_RETRY));
|
| 132 |
+
}
|
| 133 |
+
else
|
| 134 |
+
{
|
| 135 |
+
BIO_clear_flags(bio, BIO_FLAGS_SHOULD_RETRY);
|
| 136 |
+
}
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
return status;
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
static int transport_bio_simple_read(BIO* bio, char* buf, int size)
|
| 143 |
+
{
|
| 144 |
+
int error = 0;
|
| 145 |
+
int status = 0;
|
| 146 |
+
WINPR_BIO_SIMPLE_SOCKET* ptr = (WINPR_BIO_SIMPLE_SOCKET*)BIO_get_data(bio);
|
| 147 |
+
|
| 148 |
+
if (!buf)
|
| 149 |
+
return 0;
|
| 150 |
+
|
| 151 |
+
BIO_clear_flags(bio, BIO_FLAGS_READ);
|
| 152 |
+
(void)WSAResetEvent(ptr->hEvent);
|
| 153 |
+
status = _recv(ptr->socket, buf, size, 0);
|
| 154 |
+
|
| 155 |
+
if (status > 0)
|
| 156 |
+
{
|
| 157 |
+
return status;
|
| 158 |
+
}
|
| 159 |
+
|
| 160 |
+
if (status == 0)
|
| 161 |
+
{
|
| 162 |
+
BIO_clear_flags(bio, BIO_FLAGS_SHOULD_RETRY);
|
| 163 |
+
return 0;
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
error = WSAGetLastError();
|
| 167 |
+
|
| 168 |
+
if ((error == WSAEWOULDBLOCK) || (error == WSAEINTR) || (error == WSAEINPROGRESS) ||
|
| 169 |
+
(error == WSAEALREADY))
|
| 170 |
+
{
|
| 171 |
+
BIO_set_flags(bio, (BIO_FLAGS_READ | BIO_FLAGS_SHOULD_RETRY));
|
| 172 |
+
}
|
| 173 |
+
else
|
| 174 |
+
{
|
| 175 |
+
BIO_clear_flags(bio, BIO_FLAGS_SHOULD_RETRY);
|
| 176 |
+
}
|
| 177 |
+
|
| 178 |
+
return -1;
|
| 179 |
+
}
|
| 180 |
+
|
| 181 |
+
static int transport_bio_simple_puts(BIO* bio, const char* str)
|
| 182 |
+
{
|
| 183 |
+
return 1;
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
+
static int transport_bio_simple_gets(BIO* bio, char* str, int size)
|
| 187 |
+
{
|
| 188 |
+
return 1;
|
| 189 |
+
}
|
| 190 |
+
|
| 191 |
+
static long transport_bio_simple_ctrl(BIO* bio, int cmd, long arg1, void* arg2)
|
| 192 |
+
{
|
| 193 |
+
int status = -1;
|
| 194 |
+
WINPR_BIO_SIMPLE_SOCKET* ptr = (WINPR_BIO_SIMPLE_SOCKET*)BIO_get_data(bio);
|
| 195 |
+
|
| 196 |
+
switch (cmd)
|
| 197 |
+
{
|
| 198 |
+
case BIO_C_SET_SOCKET:
|
| 199 |
+
transport_bio_simple_uninit(bio);
|
| 200 |
+
transport_bio_simple_init(bio, (SOCKET)arg2, (int)arg1);
|
| 201 |
+
return 1;
|
| 202 |
+
case BIO_C_GET_SOCKET:
|
| 203 |
+
if (!BIO_get_init(bio) || !arg2)
|
| 204 |
+
return 0;
|
| 205 |
+
|
| 206 |
+
*((SOCKET*)arg2) = ptr->socket;
|
| 207 |
+
return 1;
|
| 208 |
+
case BIO_C_GET_EVENT:
|
| 209 |
+
if (!BIO_get_init(bio) || !arg2)
|
| 210 |
+
return 0;
|
| 211 |
+
|
| 212 |
+
*((HANDLE*)arg2) = ptr->hEvent;
|
| 213 |
+
return 1;
|
| 214 |
+
case BIO_C_SET_NONBLOCK:
|
| 215 |
+
{
|
| 216 |
+
#ifndef _WIN32
|
| 217 |
+
int flags = 0;
|
| 218 |
+
flags = fcntl((int)ptr->socket, F_GETFL);
|
| 219 |
+
|
| 220 |
+
if (flags == -1)
|
| 221 |
+
return 0;
|
| 222 |
+
|
| 223 |
+
if (arg1)
|
| 224 |
+
(void)fcntl((int)ptr->socket, F_SETFL, flags | O_NONBLOCK);
|
| 225 |
+
else
|
| 226 |
+
(void)fcntl((int)ptr->socket, F_SETFL, flags & ~(O_NONBLOCK));
|
| 227 |
+
|
| 228 |
+
#else
|
| 229 |
+
/* the internal socket is always non-blocking */
|
| 230 |
+
#endif
|
| 231 |
+
return 1;
|
| 232 |
+
}
|
| 233 |
+
case BIO_C_WAIT_READ:
|
| 234 |
+
{
|
| 235 |
+
int timeout = (int)arg1;
|
| 236 |
+
int sockfd = (int)ptr->socket;
|
| 237 |
+
#ifdef WINPR_HAVE_POLL_H
|
| 238 |
+
struct pollfd pollset;
|
| 239 |
+
pollset.fd = sockfd;
|
| 240 |
+
pollset.events = POLLIN;
|
| 241 |
+
pollset.revents = 0;
|
| 242 |
+
|
| 243 |
+
do
|
| 244 |
+
{
|
| 245 |
+
status = poll(&pollset, 1, timeout);
|
| 246 |
+
} while ((status < 0) && (errno == EINTR));
|
| 247 |
+
|
| 248 |
+
#else
|
| 249 |
+
fd_set rset = { 0 };
|
| 250 |
+
struct timeval tv = { 0 };
|
| 251 |
+
FD_ZERO(&rset);
|
| 252 |
+
FD_SET(sockfd, &rset);
|
| 253 |
+
|
| 254 |
+
if (timeout)
|
| 255 |
+
{
|
| 256 |
+
tv.tv_sec = timeout / 1000;
|
| 257 |
+
tv.tv_usec = (timeout % 1000) * 1000;
|
| 258 |
+
}
|
| 259 |
+
|
| 260 |
+
do
|
| 261 |
+
{
|
| 262 |
+
status = select(sockfd + 1, &rset, NULL, NULL, timeout ? &tv : NULL);
|
| 263 |
+
} while ((status < 0) && (errno == EINTR));
|
| 264 |
+
|
| 265 |
+
#endif
|
| 266 |
+
/* Convert timeout to error return */
|
| 267 |
+
if (status == 0)
|
| 268 |
+
errno = ETIMEDOUT;
|
| 269 |
+
}
|
| 270 |
+
break;
|
| 271 |
+
|
| 272 |
+
case BIO_C_WAIT_WRITE:
|
| 273 |
+
{
|
| 274 |
+
int timeout = (int)arg1;
|
| 275 |
+
int sockfd = (int)ptr->socket;
|
| 276 |
+
#ifdef WINPR_HAVE_POLL_H
|
| 277 |
+
struct pollfd pollset;
|
| 278 |
+
pollset.fd = sockfd;
|
| 279 |
+
pollset.events = POLLOUT;
|
| 280 |
+
pollset.revents = 0;
|
| 281 |
+
|
| 282 |
+
do
|
| 283 |
+
{
|
| 284 |
+
status = poll(&pollset, 1, timeout);
|
| 285 |
+
} while ((status < 0) && (errno == EINTR));
|
| 286 |
+
|
| 287 |
+
#else
|
| 288 |
+
fd_set rset = { 0 };
|
| 289 |
+
struct timeval tv = { 0 };
|
| 290 |
+
FD_ZERO(&rset);
|
| 291 |
+
FD_SET(sockfd, &rset);
|
| 292 |
+
|
| 293 |
+
if (timeout)
|
| 294 |
+
{
|
| 295 |
+
tv.tv_sec = timeout / 1000;
|
| 296 |
+
tv.tv_usec = (timeout % 1000) * 1000;
|
| 297 |
+
}
|
| 298 |
+
|
| 299 |
+
do
|
| 300 |
+
{
|
| 301 |
+
status = select(sockfd + 1, NULL, &rset, NULL, timeout ? &tv : NULL);
|
| 302 |
+
} while ((status < 0) && (errno == EINTR));
|
| 303 |
+
|
| 304 |
+
#endif
|
| 305 |
+
/* Convert timeout to error return */
|
| 306 |
+
if (status == 0)
|
| 307 |
+
errno = ETIMEDOUT;
|
| 308 |
+
}
|
| 309 |
+
break;
|
| 310 |
+
|
| 311 |
+
case BIO_C_SET_FD:
|
| 312 |
+
if (arg2)
|
| 313 |
+
{
|
| 314 |
+
transport_bio_simple_uninit(bio);
|
| 315 |
+
transport_bio_simple_init(bio, (SOCKET) * ((int*)arg2), (int)arg1);
|
| 316 |
+
status = 1;
|
| 317 |
+
}
|
| 318 |
+
|
| 319 |
+
break;
|
| 320 |
+
|
| 321 |
+
case BIO_C_GET_FD:
|
| 322 |
+
if (BIO_get_init(bio))
|
| 323 |
+
{
|
| 324 |
+
if (arg2)
|
| 325 |
+
*((int*)arg2) = (int)ptr->socket;
|
| 326 |
+
|
| 327 |
+
status = (int)ptr->socket;
|
| 328 |
+
}
|
| 329 |
+
|
| 330 |
+
break;
|
| 331 |
+
|
| 332 |
+
case BIO_CTRL_GET_CLOSE:
|
| 333 |
+
status = BIO_get_shutdown(bio);
|
| 334 |
+
break;
|
| 335 |
+
|
| 336 |
+
case BIO_CTRL_SET_CLOSE:
|
| 337 |
+
BIO_set_shutdown(bio, (int)arg1);
|
| 338 |
+
status = 1;
|
| 339 |
+
break;
|
| 340 |
+
|
| 341 |
+
case BIO_CTRL_FLUSH:
|
| 342 |
+
case BIO_CTRL_DUP:
|
| 343 |
+
status = 1;
|
| 344 |
+
break;
|
| 345 |
+
|
| 346 |
+
default:
|
| 347 |
+
status = 0;
|
| 348 |
+
break;
|
| 349 |
+
}
|
| 350 |
+
|
| 351 |
+
return status;
|
| 352 |
+
}
|
| 353 |
+
|
| 354 |
+
static int transport_bio_simple_init(BIO* bio, SOCKET socket, int shutdown)
|
| 355 |
+
{
|
| 356 |
+
WINPR_BIO_SIMPLE_SOCKET* ptr = (WINPR_BIO_SIMPLE_SOCKET*)BIO_get_data(bio);
|
| 357 |
+
ptr->socket = socket;
|
| 358 |
+
BIO_set_shutdown(bio, shutdown);
|
| 359 |
+
BIO_set_flags(bio, BIO_FLAGS_SHOULD_RETRY);
|
| 360 |
+
BIO_set_init(bio, 1);
|
| 361 |
+
ptr->hEvent = WSACreateEvent();
|
| 362 |
+
|
| 363 |
+
if (!ptr->hEvent)
|
| 364 |
+
return 0;
|
| 365 |
+
|
| 366 |
+
/* WSAEventSelect automatically sets the socket in non-blocking mode */
|
| 367 |
+
if (WSAEventSelect(ptr->socket, ptr->hEvent, FD_READ | FD_ACCEPT | FD_CLOSE))
|
| 368 |
+
{
|
| 369 |
+
WLog_ERR(TAG, "WSAEventSelect returned 0x%08X", WSAGetLastError());
|
| 370 |
+
return 0;
|
| 371 |
+
}
|
| 372 |
+
|
| 373 |
+
return 1;
|
| 374 |
+
}
|
| 375 |
+
|
| 376 |
+
static int transport_bio_simple_uninit(BIO* bio)
|
| 377 |
+
{
|
| 378 |
+
WINPR_BIO_SIMPLE_SOCKET* ptr = (WINPR_BIO_SIMPLE_SOCKET*)BIO_get_data(bio);
|
| 379 |
+
|
| 380 |
+
if (BIO_get_shutdown(bio))
|
| 381 |
+
{
|
| 382 |
+
if (BIO_get_init(bio) && ptr)
|
| 383 |
+
{
|
| 384 |
+
_shutdown(ptr->socket, SD_BOTH);
|
| 385 |
+
closesocket(ptr->socket);
|
| 386 |
+
ptr->socket = 0;
|
| 387 |
+
}
|
| 388 |
+
}
|
| 389 |
+
|
| 390 |
+
if (ptr && ptr->hEvent)
|
| 391 |
+
{
|
| 392 |
+
(void)CloseHandle(ptr->hEvent);
|
| 393 |
+
ptr->hEvent = NULL;
|
| 394 |
+
}
|
| 395 |
+
|
| 396 |
+
BIO_set_init(bio, 0);
|
| 397 |
+
BIO_set_flags(bio, 0);
|
| 398 |
+
return 1;
|
| 399 |
+
}
|
| 400 |
+
|
| 401 |
+
static int transport_bio_simple_new(BIO* bio)
|
| 402 |
+
{
|
| 403 |
+
WINPR_BIO_SIMPLE_SOCKET* ptr = NULL;
|
| 404 |
+
BIO_set_flags(bio, BIO_FLAGS_SHOULD_RETRY);
|
| 405 |
+
ptr = (WINPR_BIO_SIMPLE_SOCKET*)calloc(1, sizeof(WINPR_BIO_SIMPLE_SOCKET));
|
| 406 |
+
|
| 407 |
+
if (!ptr)
|
| 408 |
+
return 0;
|
| 409 |
+
|
| 410 |
+
BIO_set_data(bio, ptr);
|
| 411 |
+
return 1;
|
| 412 |
+
}
|
| 413 |
+
|
| 414 |
+
static int transport_bio_simple_free(BIO* bio)
|
| 415 |
+
{
|
| 416 |
+
WINPR_BIO_SIMPLE_SOCKET* ptr = NULL;
|
| 417 |
+
|
| 418 |
+
if (!bio)
|
| 419 |
+
return 0;
|
| 420 |
+
|
| 421 |
+
transport_bio_simple_uninit(bio);
|
| 422 |
+
ptr = (WINPR_BIO_SIMPLE_SOCKET*)BIO_get_data(bio);
|
| 423 |
+
|
| 424 |
+
if (ptr)
|
| 425 |
+
{
|
| 426 |
+
BIO_set_data(bio, NULL);
|
| 427 |
+
free(ptr);
|
| 428 |
+
}
|
| 429 |
+
|
| 430 |
+
return 1;
|
| 431 |
+
}
|
| 432 |
+
|
| 433 |
+
BIO_METHOD* BIO_s_simple_socket(void)
|
| 434 |
+
{
|
| 435 |
+
static BIO_METHOD* bio_methods = NULL;
|
| 436 |
+
|
| 437 |
+
if (bio_methods == NULL)
|
| 438 |
+
{
|
| 439 |
+
if (!(bio_methods = BIO_meth_new(BIO_TYPE_SIMPLE, "SimpleSocket")))
|
| 440 |
+
return NULL;
|
| 441 |
+
|
| 442 |
+
BIO_meth_set_write(bio_methods, transport_bio_simple_write);
|
| 443 |
+
BIO_meth_set_read(bio_methods, transport_bio_simple_read);
|
| 444 |
+
BIO_meth_set_puts(bio_methods, transport_bio_simple_puts);
|
| 445 |
+
BIO_meth_set_gets(bio_methods, transport_bio_simple_gets);
|
| 446 |
+
BIO_meth_set_ctrl(bio_methods, transport_bio_simple_ctrl);
|
| 447 |
+
BIO_meth_set_create(bio_methods, transport_bio_simple_new);
|
| 448 |
+
BIO_meth_set_destroy(bio_methods, transport_bio_simple_free);
|
| 449 |
+
}
|
| 450 |
+
|
| 451 |
+
return bio_methods;
|
| 452 |
+
}
|
| 453 |
+
|
| 454 |
+
/* Buffered Socket BIO */
|
| 455 |
+
|
| 456 |
+
typedef struct
|
| 457 |
+
{
|
| 458 |
+
BIO* bufferedBio;
|
| 459 |
+
BOOL readBlocked;
|
| 460 |
+
BOOL writeBlocked;
|
| 461 |
+
RingBuffer xmitBuffer;
|
| 462 |
+
} WINPR_BIO_BUFFERED_SOCKET;
|
| 463 |
+
|
| 464 |
+
static long transport_bio_buffered_callback(BIO* bio, int mode, const char* argp, int argi,
|
| 465 |
+
long argl, long ret)
|
| 466 |
+
{
|
| 467 |
+
return 1;
|
| 468 |
+
}
|
| 469 |
+
|
| 470 |
+
static int transport_bio_buffered_write(BIO* bio, const char* buf, int num)
|
| 471 |
+
{
|
| 472 |
+
int ret = num;
|
| 473 |
+
int nchunks = 0;
|
| 474 |
+
size_t committedBytes = 0;
|
| 475 |
+
DataChunk chunks[2] = { 0 };
|
| 476 |
+
WINPR_BIO_BUFFERED_SOCKET* ptr = (WINPR_BIO_BUFFERED_SOCKET*)BIO_get_data(bio);
|
| 477 |
+
BIO* next_bio = NULL;
|
| 478 |
+
|
| 479 |
+
WINPR_ASSERT(bio);
|
| 480 |
+
WINPR_ASSERT(ptr);
|
| 481 |
+
if (num < 0)
|
| 482 |
+
return num;
|
| 483 |
+
|
| 484 |
+
ptr->writeBlocked = FALSE;
|
| 485 |
+
BIO_clear_flags(bio, BIO_FLAGS_WRITE);
|
| 486 |
+
|
| 487 |
+
/* we directly append extra bytes in the xmit buffer, this could be prevented
|
| 488 |
+
* but for now it makes the code more simple.
|
| 489 |
+
*/
|
| 490 |
+
if (buf && (num > 0) && !ringbuffer_write(&ptr->xmitBuffer, (const BYTE*)buf, (size_t)num))
|
| 491 |
+
{
|
| 492 |
+
WLog_ERR(TAG, "an error occurred when writing (num: %d)", num);
|
| 493 |
+
return -1;
|
| 494 |
+
}
|
| 495 |
+
|
| 496 |
+
nchunks = ringbuffer_peek(&ptr->xmitBuffer, chunks, ringbuffer_used(&ptr->xmitBuffer));
|
| 497 |
+
next_bio = BIO_next(bio);
|
| 498 |
+
|
| 499 |
+
for (int i = 0; i < nchunks; i++)
|
| 500 |
+
{
|
| 501 |
+
while (chunks[i].size)
|
| 502 |
+
{
|
| 503 |
+
ERR_clear_error();
|
| 504 |
+
|
| 505 |
+
const size_t wr = MIN(INT32_MAX, chunks[i].size);
|
| 506 |
+
const int status = BIO_write(next_bio, chunks[i].data, (int)wr);
|
| 507 |
+
|
| 508 |
+
if (status <= 0)
|
| 509 |
+
{
|
| 510 |
+
if (!BIO_should_retry(next_bio))
|
| 511 |
+
{
|
| 512 |
+
BIO_clear_flags(bio, BIO_FLAGS_SHOULD_RETRY);
|
| 513 |
+
ret = -1; /* fatal error */
|
| 514 |
+
goto out;
|
| 515 |
+
}
|
| 516 |
+
|
| 517 |
+
if (BIO_should_write(next_bio))
|
| 518 |
+
{
|
| 519 |
+
BIO_set_flags(bio, BIO_FLAGS_WRITE);
|
| 520 |
+
ptr->writeBlocked = TRUE;
|
| 521 |
+
goto out; /* EWOULDBLOCK */
|
| 522 |
+
}
|
| 523 |
+
}
|
| 524 |
+
else
|
| 525 |
+
{
|
| 526 |
+
committedBytes += (size_t)status;
|
| 527 |
+
chunks[i].size -= (size_t)status;
|
| 528 |
+
chunks[i].data += status;
|
| 529 |
+
}
|
| 530 |
+
}
|
| 531 |
+
}
|
| 532 |
+
|
| 533 |
+
out:
|
| 534 |
+
ringbuffer_commit_read_bytes(&ptr->xmitBuffer, committedBytes);
|
| 535 |
+
return ret;
|
| 536 |
+
}
|
| 537 |
+
|
| 538 |
+
static int transport_bio_buffered_read(BIO* bio, char* buf, int size)
|
| 539 |
+
{
|
| 540 |
+
int status = 0;
|
| 541 |
+
WINPR_BIO_BUFFERED_SOCKET* ptr = (WINPR_BIO_BUFFERED_SOCKET*)BIO_get_data(bio);
|
| 542 |
+
BIO* next_bio = BIO_next(bio);
|
| 543 |
+
ptr->readBlocked = FALSE;
|
| 544 |
+
BIO_clear_flags(bio, BIO_FLAGS_READ);
|
| 545 |
+
ERR_clear_error();
|
| 546 |
+
status = BIO_read(next_bio, buf, size);
|
| 547 |
+
|
| 548 |
+
if (status <= 0)
|
| 549 |
+
{
|
| 550 |
+
if (!BIO_should_retry(next_bio))
|
| 551 |
+
{
|
| 552 |
+
BIO_clear_flags(bio, BIO_FLAGS_SHOULD_RETRY);
|
| 553 |
+
goto out;
|
| 554 |
+
}
|
| 555 |
+
|
| 556 |
+
BIO_set_flags(bio, BIO_FLAGS_SHOULD_RETRY);
|
| 557 |
+
|
| 558 |
+
if (BIO_should_read(next_bio))
|
| 559 |
+
{
|
| 560 |
+
BIO_set_flags(bio, BIO_FLAGS_READ);
|
| 561 |
+
ptr->readBlocked = TRUE;
|
| 562 |
+
goto out;
|
| 563 |
+
}
|
| 564 |
+
}
|
| 565 |
+
|
| 566 |
+
out:
|
| 567 |
+
return status;
|
| 568 |
+
}
|
| 569 |
+
|
| 570 |
+
static int transport_bio_buffered_puts(BIO* bio, const char* str)
|
| 571 |
+
{
|
| 572 |
+
return 1;
|
| 573 |
+
}
|
| 574 |
+
|
| 575 |
+
static int transport_bio_buffered_gets(BIO* bio, char* str, int size)
|
| 576 |
+
{
|
| 577 |
+
return 1;
|
| 578 |
+
}
|
| 579 |
+
|
| 580 |
+
static long transport_bio_buffered_ctrl(BIO* bio, int cmd, long arg1, void* arg2)
|
| 581 |
+
{
|
| 582 |
+
long status = -1;
|
| 583 |
+
WINPR_BIO_BUFFERED_SOCKET* ptr = (WINPR_BIO_BUFFERED_SOCKET*)BIO_get_data(bio);
|
| 584 |
+
|
| 585 |
+
switch (cmd)
|
| 586 |
+
{
|
| 587 |
+
case BIO_CTRL_FLUSH:
|
| 588 |
+
if (!ringbuffer_used(&ptr->xmitBuffer))
|
| 589 |
+
status = 1;
|
| 590 |
+
else
|
| 591 |
+
status = (transport_bio_buffered_write(bio, NULL, 0) >= 0) ? 1 : -1;
|
| 592 |
+
|
| 593 |
+
break;
|
| 594 |
+
|
| 595 |
+
case BIO_CTRL_WPENDING:
|
| 596 |
+
status = WINPR_ASSERTING_INT_CAST(long, ringbuffer_used(&ptr->xmitBuffer));
|
| 597 |
+
break;
|
| 598 |
+
|
| 599 |
+
case BIO_CTRL_PENDING:
|
| 600 |
+
status = 0;
|
| 601 |
+
break;
|
| 602 |
+
|
| 603 |
+
case BIO_C_READ_BLOCKED:
|
| 604 |
+
status = (int)ptr->readBlocked;
|
| 605 |
+
break;
|
| 606 |
+
|
| 607 |
+
case BIO_C_WRITE_BLOCKED:
|
| 608 |
+
status = (int)ptr->writeBlocked;
|
| 609 |
+
break;
|
| 610 |
+
|
| 611 |
+
default:
|
| 612 |
+
status = BIO_ctrl(BIO_next(bio), cmd, arg1, arg2);
|
| 613 |
+
break;
|
| 614 |
+
}
|
| 615 |
+
|
| 616 |
+
return status;
|
| 617 |
+
}
|
| 618 |
+
|
| 619 |
+
static int transport_bio_buffered_new(BIO* bio)
|
| 620 |
+
{
|
| 621 |
+
WINPR_BIO_BUFFERED_SOCKET* ptr = NULL;
|
| 622 |
+
BIO_set_init(bio, 1);
|
| 623 |
+
BIO_set_flags(bio, BIO_FLAGS_SHOULD_RETRY);
|
| 624 |
+
ptr = (WINPR_BIO_BUFFERED_SOCKET*)calloc(1, sizeof(WINPR_BIO_BUFFERED_SOCKET));
|
| 625 |
+
|
| 626 |
+
if (!ptr)
|
| 627 |
+
return -1;
|
| 628 |
+
|
| 629 |
+
BIO_set_data(bio, (void*)ptr);
|
| 630 |
+
|
| 631 |
+
if (!ringbuffer_init(&ptr->xmitBuffer, 0x10000))
|
| 632 |
+
return -1;
|
| 633 |
+
|
| 634 |
+
return 1;
|
| 635 |
+
}
|
| 636 |
+
|
| 637 |
+
/* Free the buffered BIO.
|
| 638 |
+
* Do not free other elements in the BIO stack,
|
| 639 |
+
* let BIO_free_all handle that. */
|
| 640 |
+
static int transport_bio_buffered_free(BIO* bio)
|
| 641 |
+
{
|
| 642 |
+
WINPR_BIO_BUFFERED_SOCKET* ptr = (WINPR_BIO_BUFFERED_SOCKET*)BIO_get_data(bio);
|
| 643 |
+
|
| 644 |
+
if (!ptr)
|
| 645 |
+
return 0;
|
| 646 |
+
|
| 647 |
+
ringbuffer_destroy(&ptr->xmitBuffer);
|
| 648 |
+
free(ptr);
|
| 649 |
+
return 1;
|
| 650 |
+
}
|
| 651 |
+
|
| 652 |
+
BIO_METHOD* BIO_s_buffered_socket(void)
|
| 653 |
+
{
|
| 654 |
+
static BIO_METHOD* bio_methods = NULL;
|
| 655 |
+
|
| 656 |
+
if (bio_methods == NULL)
|
| 657 |
+
{
|
| 658 |
+
if (!(bio_methods = BIO_meth_new(BIO_TYPE_BUFFERED, "BufferedSocket")))
|
| 659 |
+
return NULL;
|
| 660 |
+
|
| 661 |
+
BIO_meth_set_write(bio_methods, transport_bio_buffered_write);
|
| 662 |
+
BIO_meth_set_read(bio_methods, transport_bio_buffered_read);
|
| 663 |
+
BIO_meth_set_puts(bio_methods, transport_bio_buffered_puts);
|
| 664 |
+
BIO_meth_set_gets(bio_methods, transport_bio_buffered_gets);
|
| 665 |
+
BIO_meth_set_ctrl(bio_methods, transport_bio_buffered_ctrl);
|
| 666 |
+
BIO_meth_set_create(bio_methods, transport_bio_buffered_new);
|
| 667 |
+
BIO_meth_set_destroy(bio_methods, transport_bio_buffered_free);
|
| 668 |
+
}
|
| 669 |
+
|
| 670 |
+
return bio_methods;
|
| 671 |
+
}
|
| 672 |
+
|
| 673 |
+
char* freerdp_tcp_address_to_string(const struct sockaddr_storage* addr, BOOL* pIPv6)
|
| 674 |
+
{
|
| 675 |
+
char ipAddress[INET6_ADDRSTRLEN + 1] = { 0 };
|
| 676 |
+
const struct sockaddr_in6* sockaddr_ipv6 = (const struct sockaddr_in6*)addr;
|
| 677 |
+
const struct sockaddr_in* sockaddr_ipv4 = (const struct sockaddr_in*)addr;
|
| 678 |
+
|
| 679 |
+
if (addr == NULL)
|
| 680 |
+
{
|
| 681 |
+
return NULL;
|
| 682 |
+
}
|
| 683 |
+
|
| 684 |
+
switch (sockaddr_ipv4->sin_family)
|
| 685 |
+
{
|
| 686 |
+
case AF_INET:
|
| 687 |
+
if (!inet_ntop(sockaddr_ipv4->sin_family, &sockaddr_ipv4->sin_addr, ipAddress,
|
| 688 |
+
sizeof(ipAddress)))
|
| 689 |
+
return NULL;
|
| 690 |
+
|
| 691 |
+
break;
|
| 692 |
+
|
| 693 |
+
case AF_INET6:
|
| 694 |
+
if (!inet_ntop(sockaddr_ipv6->sin6_family, &sockaddr_ipv6->sin6_addr, ipAddress,
|
| 695 |
+
sizeof(ipAddress)))
|
| 696 |
+
return NULL;
|
| 697 |
+
|
| 698 |
+
break;
|
| 699 |
+
|
| 700 |
+
case AF_UNIX:
|
| 701 |
+
(void)sprintf_s(ipAddress, ARRAYSIZE(ipAddress), "127.0.0.1");
|
| 702 |
+
break;
|
| 703 |
+
|
| 704 |
+
default:
|
| 705 |
+
return NULL;
|
| 706 |
+
}
|
| 707 |
+
|
| 708 |
+
if (pIPv6 != NULL)
|
| 709 |
+
{
|
| 710 |
+
*pIPv6 = (sockaddr_ipv4->sin_family == AF_INET6);
|
| 711 |
+
}
|
| 712 |
+
|
| 713 |
+
return _strdup(ipAddress);
|
| 714 |
+
}
|
| 715 |
+
|
| 716 |
+
static char* freerdp_tcp_get_ip_address(int sockfd, BOOL* pIPv6)
|
| 717 |
+
{
|
| 718 |
+
struct sockaddr_storage saddr = { 0 };
|
| 719 |
+
socklen_t length = sizeof(struct sockaddr_storage);
|
| 720 |
+
|
| 721 |
+
if (getsockname(sockfd, (struct sockaddr*)&saddr, &length) != 0)
|
| 722 |
+
{
|
| 723 |
+
return NULL;
|
| 724 |
+
}
|
| 725 |
+
|
| 726 |
+
return freerdp_tcp_address_to_string(&saddr, pIPv6);
|
| 727 |
+
}
|
| 728 |
+
|
| 729 |
+
char* freerdp_tcp_get_peer_address(SOCKET sockfd)
|
| 730 |
+
{
|
| 731 |
+
struct sockaddr_storage saddr = { 0 };
|
| 732 |
+
socklen_t length = sizeof(struct sockaddr_storage);
|
| 733 |
+
|
| 734 |
+
if (getpeername((int)sockfd, (struct sockaddr*)&saddr, &length) != 0)
|
| 735 |
+
{
|
| 736 |
+
return NULL;
|
| 737 |
+
}
|
| 738 |
+
|
| 739 |
+
return freerdp_tcp_address_to_string(&saddr, NULL);
|
| 740 |
+
}
|
| 741 |
+
|
| 742 |
+
static int freerdp_uds_connect(const char* path)
|
| 743 |
+
{
|
| 744 |
+
#ifndef _WIN32
|
| 745 |
+
int status = 0;
|
| 746 |
+
int sockfd = 0;
|
| 747 |
+
struct sockaddr_un addr = { 0 };
|
| 748 |
+
sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
|
| 749 |
+
|
| 750 |
+
if (sockfd == -1)
|
| 751 |
+
{
|
| 752 |
+
WLog_ERR(TAG, "socket");
|
| 753 |
+
return -1;
|
| 754 |
+
}
|
| 755 |
+
|
| 756 |
+
addr.sun_family = AF_UNIX;
|
| 757 |
+
strncpy(addr.sun_path, path, sizeof(addr.sun_path) - 1);
|
| 758 |
+
status = connect(sockfd, (struct sockaddr*)&addr, sizeof(addr));
|
| 759 |
+
|
| 760 |
+
if (status < 0)
|
| 761 |
+
{
|
| 762 |
+
WLog_ERR(TAG, "connect");
|
| 763 |
+
close(sockfd);
|
| 764 |
+
return -1;
|
| 765 |
+
}
|
| 766 |
+
|
| 767 |
+
return sockfd;
|
| 768 |
+
#else /* ifndef _WIN32 */
|
| 769 |
+
return -1;
|
| 770 |
+
#endif
|
| 771 |
+
}
|
| 772 |
+
|
| 773 |
+
struct addrinfo* freerdp_tcp_resolve_host(const char* hostname, int port, int ai_flags)
|
| 774 |
+
{
|
| 775 |
+
char* service = NULL;
|
| 776 |
+
char port_str[16];
|
| 777 |
+
int status = 0;
|
| 778 |
+
struct addrinfo hints = { 0 };
|
| 779 |
+
struct addrinfo* result = NULL;
|
| 780 |
+
hints.ai_family = AF_UNSPEC;
|
| 781 |
+
hints.ai_socktype = SOCK_STREAM;
|
| 782 |
+
hints.ai_flags = ai_flags;
|
| 783 |
+
|
| 784 |
+
if (port >= 0)
|
| 785 |
+
{
|
| 786 |
+
(void)sprintf_s(port_str, sizeof(port_str) - 1, "%d", port);
|
| 787 |
+
service = port_str;
|
| 788 |
+
}
|
| 789 |
+
|
| 790 |
+
status = getaddrinfo(hostname, service, &hints, &result);
|
| 791 |
+
|
| 792 |
+
if (status)
|
| 793 |
+
return NULL;
|
| 794 |
+
|
| 795 |
+
return result;
|
| 796 |
+
}
|
| 797 |
+
|
| 798 |
+
static BOOL freerdp_tcp_is_hostname_resolvable(rdpContext* context, const char* hostname)
|
| 799 |
+
{
|
| 800 |
+
struct addrinfo* result = freerdp_tcp_resolve_host(hostname, -1, 0);
|
| 801 |
+
|
| 802 |
+
if (!result)
|
| 803 |
+
{
|
| 804 |
+
freerdp_set_last_error_if_not(context, FREERDP_ERROR_DNS_NAME_NOT_FOUND);
|
| 805 |
+
|
| 806 |
+
return FALSE;
|
| 807 |
+
}
|
| 808 |
+
|
| 809 |
+
freerdp_set_last_error_log(context, 0);
|
| 810 |
+
freeaddrinfo(result);
|
| 811 |
+
return TRUE;
|
| 812 |
+
}
|
| 813 |
+
|
| 814 |
+
static BOOL freerdp_tcp_connect_timeout(rdpContext* context, int sockfd, struct sockaddr* addr,
|
| 815 |
+
socklen_t addrlen, UINT32 timeout)
|
| 816 |
+
{
|
| 817 |
+
BOOL rc = FALSE;
|
| 818 |
+
HANDLE handles[2] = { 0 };
|
| 819 |
+
DWORD count = 0;
|
| 820 |
+
u_long arg = 0;
|
| 821 |
+
DWORD tout = (timeout > 0) ? timeout : INFINITE;
|
| 822 |
+
|
| 823 |
+
handles[count] = CreateEvent(NULL, TRUE, FALSE, NULL);
|
| 824 |
+
|
| 825 |
+
if (!handles[count])
|
| 826 |
+
return FALSE;
|
| 827 |
+
|
| 828 |
+
const int wsastatus = WSAEventSelect((SOCKET)sockfd, handles[count++],
|
| 829 |
+
FD_READ | FD_WRITE | FD_CONNECT | FD_CLOSE);
|
| 830 |
+
|
| 831 |
+
if (wsastatus < 0)
|
| 832 |
+
{
|
| 833 |
+
WLog_ERR(TAG, "WSAEventSelect failed with %d", WSAGetLastError());
|
| 834 |
+
goto fail;
|
| 835 |
+
}
|
| 836 |
+
|
| 837 |
+
handles[count++] = utils_get_abort_event(context->rdp);
|
| 838 |
+
const int constatus = _connect((SOCKET)sockfd, addr, WINPR_ASSERTING_INT_CAST(int, addrlen));
|
| 839 |
+
|
| 840 |
+
if (constatus < 0)
|
| 841 |
+
{
|
| 842 |
+
const int estatus = WSAGetLastError();
|
| 843 |
+
|
| 844 |
+
switch (estatus)
|
| 845 |
+
{
|
| 846 |
+
case WSAEINPROGRESS:
|
| 847 |
+
case WSAEWOULDBLOCK:
|
| 848 |
+
break;
|
| 849 |
+
|
| 850 |
+
default:
|
| 851 |
+
goto fail;
|
| 852 |
+
}
|
| 853 |
+
}
|
| 854 |
+
|
| 855 |
+
const DWORD wstatus = WaitForMultipleObjects(count, handles, FALSE, tout);
|
| 856 |
+
|
| 857 |
+
if (WAIT_OBJECT_0 != wstatus)
|
| 858 |
+
goto fail;
|
| 859 |
+
|
| 860 |
+
const SSIZE_T res = recv(sockfd, NULL, 0, 0);
|
| 861 |
+
|
| 862 |
+
if (res == SOCKET_ERROR)
|
| 863 |
+
{
|
| 864 |
+
if (WSAGetLastError() == WSAECONNRESET)
|
| 865 |
+
goto fail;
|
| 866 |
+
}
|
| 867 |
+
|
| 868 |
+
const int status = WSAEventSelect((SOCKET)sockfd, handles[0], 0);
|
| 869 |
+
|
| 870 |
+
if (status < 0)
|
| 871 |
+
{
|
| 872 |
+
WLog_ERR(TAG, "WSAEventSelect failed with %d", WSAGetLastError());
|
| 873 |
+
goto fail;
|
| 874 |
+
}
|
| 875 |
+
|
| 876 |
+
if (_ioctlsocket((SOCKET)sockfd, FIONBIO, &arg) != 0)
|
| 877 |
+
goto fail;
|
| 878 |
+
|
| 879 |
+
rc = TRUE;
|
| 880 |
+
fail:
|
| 881 |
+
(void)CloseHandle(handles[0]);
|
| 882 |
+
return rc;
|
| 883 |
+
}
|
| 884 |
+
|
| 885 |
+
typedef struct
|
| 886 |
+
{
|
| 887 |
+
SOCKET s;
|
| 888 |
+
struct addrinfo* addr;
|
| 889 |
+
struct addrinfo* result;
|
| 890 |
+
} t_peer;
|
| 891 |
+
|
| 892 |
+
static void peer_free(t_peer* peer)
|
| 893 |
+
{
|
| 894 |
+
if (peer->s != INVALID_SOCKET)
|
| 895 |
+
closesocket(peer->s);
|
| 896 |
+
|
| 897 |
+
freeaddrinfo(peer->addr);
|
| 898 |
+
memset(peer, 0, sizeof(t_peer));
|
| 899 |
+
peer->s = INVALID_SOCKET;
|
| 900 |
+
}
|
| 901 |
+
|
| 902 |
+
static int freerdp_tcp_connect_multi(rdpContext* context, char** hostnames, const UINT32* ports,
|
| 903 |
+
UINT32 count, UINT16 port, UINT32 timeout)
|
| 904 |
+
{
|
| 905 |
+
UINT32 sindex = count;
|
| 906 |
+
SOCKET sockfd = INVALID_SOCKET;
|
| 907 |
+
struct addrinfo* addr = NULL;
|
| 908 |
+
struct addrinfo* result = NULL;
|
| 909 |
+
|
| 910 |
+
HANDLE* events = (HANDLE*)calloc(count + 1, sizeof(HANDLE));
|
| 911 |
+
t_peer* peers = (t_peer*)calloc(count, sizeof(t_peer));
|
| 912 |
+
|
| 913 |
+
if (!peers || !events || (count < 1))
|
| 914 |
+
{
|
| 915 |
+
free(peers);
|
| 916 |
+
free((void*)events);
|
| 917 |
+
return -1;
|
| 918 |
+
}
|
| 919 |
+
|
| 920 |
+
for (UINT32 index = 0; index < count; index++)
|
| 921 |
+
{
|
| 922 |
+
int curPort = port;
|
| 923 |
+
|
| 924 |
+
if (ports)
|
| 925 |
+
curPort = WINPR_ASSERTING_INT_CAST(int, ports[index]);
|
| 926 |
+
|
| 927 |
+
result = freerdp_tcp_resolve_host(hostnames[index], curPort, 0);
|
| 928 |
+
|
| 929 |
+
if (!result)
|
| 930 |
+
continue;
|
| 931 |
+
|
| 932 |
+
addr = result;
|
| 933 |
+
|
| 934 |
+
if ((addr->ai_family == AF_INET6) && (addr->ai_next != 0))
|
| 935 |
+
{
|
| 936 |
+
while ((addr = addr->ai_next))
|
| 937 |
+
{
|
| 938 |
+
if (addr->ai_family == AF_INET)
|
| 939 |
+
break;
|
| 940 |
+
}
|
| 941 |
+
|
| 942 |
+
if (!addr)
|
| 943 |
+
addr = result;
|
| 944 |
+
}
|
| 945 |
+
|
| 946 |
+
peers[index].s = _socket(addr->ai_family, addr->ai_socktype, addr->ai_protocol);
|
| 947 |
+
|
| 948 |
+
if (peers[index].s == INVALID_SOCKET)
|
| 949 |
+
{
|
| 950 |
+
freeaddrinfo(result);
|
| 951 |
+
continue;
|
| 952 |
+
}
|
| 953 |
+
|
| 954 |
+
peers[index].addr = addr;
|
| 955 |
+
peers[index].result = result;
|
| 956 |
+
}
|
| 957 |
+
|
| 958 |
+
for (UINT32 index = 0; index < count; index++)
|
| 959 |
+
{
|
| 960 |
+
sockfd = peers[index].s;
|
| 961 |
+
addr = peers[index].addr;
|
| 962 |
+
|
| 963 |
+
if ((sockfd == INVALID_SOCKET) || (!addr))
|
| 964 |
+
continue;
|
| 965 |
+
|
| 966 |
+
/* blocking tcp connect */
|
| 967 |
+
const int rc =
|
| 968 |
+
_connect(sockfd, addr->ai_addr, WINPR_ASSERTING_INT_CAST(int, addr->ai_addrlen));
|
| 969 |
+
|
| 970 |
+
if (rc >= 0)
|
| 971 |
+
{
|
| 972 |
+
/* connection success */
|
| 973 |
+
sindex = index;
|
| 974 |
+
break;
|
| 975 |
+
}
|
| 976 |
+
}
|
| 977 |
+
|
| 978 |
+
if (sindex < count)
|
| 979 |
+
{
|
| 980 |
+
sockfd = peers[sindex].s;
|
| 981 |
+
peers[sindex].s = INVALID_SOCKET;
|
| 982 |
+
}
|
| 983 |
+
else
|
| 984 |
+
freerdp_set_last_error_log(context, FREERDP_ERROR_CONNECT_CANCELLED);
|
| 985 |
+
|
| 986 |
+
for (UINT32 index = 0; index < count; index++)
|
| 987 |
+
peer_free(&peers[index]);
|
| 988 |
+
|
| 989 |
+
free(peers);
|
| 990 |
+
free((void*)events);
|
| 991 |
+
return (int)sockfd;
|
| 992 |
+
}
|
| 993 |
+
|
| 994 |
+
BOOL freerdp_tcp_set_keep_alive_mode(const rdpSettings* settings, int sockfd)
|
| 995 |
+
{
|
| 996 |
+
const BOOL keepalive = (freerdp_settings_get_bool(settings, FreeRDP_TcpKeepAlive));
|
| 997 |
+
UINT32 optval = 0;
|
| 998 |
+
socklen_t optlen = 0;
|
| 999 |
+
optval = keepalive ? 1 : 0;
|
| 1000 |
+
optlen = sizeof(optval);
|
| 1001 |
+
|
| 1002 |
+
if (setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, (void*)&optval, optlen) < 0)
|
| 1003 |
+
{
|
| 1004 |
+
WLog_WARN(TAG, "setsockopt() SOL_SOCKET, SO_KEEPALIVE");
|
| 1005 |
+
}
|
| 1006 |
+
|
| 1007 |
+
#ifndef _WIN32
|
| 1008 |
+
#ifdef TCP_KEEPIDLE
|
| 1009 |
+
optval = keepalive ? freerdp_settings_get_uint32(settings, FreeRDP_TcpKeepAliveDelay) : 0;
|
| 1010 |
+
optlen = sizeof(optval);
|
| 1011 |
+
|
| 1012 |
+
if (setsockopt(sockfd, IPPROTO_TCP, TCP_KEEPIDLE, (void*)&optval, optlen) < 0)
|
| 1013 |
+
{
|
| 1014 |
+
WLog_WARN(TAG, "setsockopt() IPPROTO_TCP, TCP_KEEPIDLE");
|
| 1015 |
+
}
|
| 1016 |
+
|
| 1017 |
+
#endif
|
| 1018 |
+
#ifndef SOL_TCP
|
| 1019 |
+
/* "tcp" from /etc/protocols as getprotobyname(3C) */
|
| 1020 |
+
#define SOL_TCP 6
|
| 1021 |
+
#endif
|
| 1022 |
+
#ifdef TCP_KEEPCNT
|
| 1023 |
+
optval = keepalive ? freerdp_settings_get_uint32(settings, FreeRDP_TcpKeepAliveRetries) : 0;
|
| 1024 |
+
optlen = sizeof(optval);
|
| 1025 |
+
|
| 1026 |
+
if (setsockopt(sockfd, SOL_TCP, TCP_KEEPCNT, (void*)&optval, optlen) < 0)
|
| 1027 |
+
{
|
| 1028 |
+
WLog_WARN(TAG, "setsockopt() SOL_TCP, TCP_KEEPCNT");
|
| 1029 |
+
}
|
| 1030 |
+
|
| 1031 |
+
#endif
|
| 1032 |
+
#ifdef TCP_KEEPINTVL
|
| 1033 |
+
optval = keepalive ? freerdp_settings_get_uint32(settings, FreeRDP_TcpKeepAliveInterval) : 0;
|
| 1034 |
+
optlen = sizeof(optval);
|
| 1035 |
+
|
| 1036 |
+
if (setsockopt(sockfd, SOL_TCP, TCP_KEEPINTVL, (void*)&optval, optlen) < 0)
|
| 1037 |
+
{
|
| 1038 |
+
WLog_WARN(TAG, "setsockopt() SOL_TCP, TCP_KEEPINTVL");
|
| 1039 |
+
}
|
| 1040 |
+
|
| 1041 |
+
#endif
|
| 1042 |
+
#endif
|
| 1043 |
+
#if defined(__MACOSX__) || defined(__IOS__)
|
| 1044 |
+
optval = 1;
|
| 1045 |
+
optlen = sizeof(optval);
|
| 1046 |
+
|
| 1047 |
+
if (setsockopt(sockfd, SOL_SOCKET, SO_NOSIGPIPE, (void*)&optval, optlen) < 0)
|
| 1048 |
+
{
|
| 1049 |
+
WLog_WARN(TAG, "setsockopt() SOL_SOCKET, SO_NOSIGPIPE");
|
| 1050 |
+
}
|
| 1051 |
+
|
| 1052 |
+
#endif
|
| 1053 |
+
#ifdef TCP_USER_TIMEOUT
|
| 1054 |
+
optval = freerdp_settings_get_uint32(settings, FreeRDP_TcpAckTimeout);
|
| 1055 |
+
optlen = sizeof(optval);
|
| 1056 |
+
|
| 1057 |
+
if (setsockopt(sockfd, SOL_TCP, TCP_USER_TIMEOUT, (void*)&optval, optlen) < 0)
|
| 1058 |
+
{
|
| 1059 |
+
WLog_WARN(TAG, "setsockopt() SOL_TCP, TCP_USER_TIMEOUT");
|
| 1060 |
+
}
|
| 1061 |
+
|
| 1062 |
+
#endif
|
| 1063 |
+
return TRUE;
|
| 1064 |
+
}
|
| 1065 |
+
|
| 1066 |
+
int freerdp_tcp_connect(rdpContext* context, const char* hostname, int port, DWORD timeout)
|
| 1067 |
+
{
|
| 1068 |
+
rdpTransport* transport = NULL;
|
| 1069 |
+
if (!context || !context->rdp)
|
| 1070 |
+
return -1;
|
| 1071 |
+
transport = context->rdp->transport;
|
| 1072 |
+
if (!transport)
|
| 1073 |
+
return -1;
|
| 1074 |
+
return transport_tcp_connect(context->rdp->transport, hostname, port, timeout);
|
| 1075 |
+
}
|
| 1076 |
+
|
| 1077 |
+
static int get_next_addrinfo(rdpContext* context, struct addrinfo* input, struct addrinfo** result,
|
| 1078 |
+
UINT32 errorCode)
|
| 1079 |
+
{
|
| 1080 |
+
WINPR_ASSERT(context);
|
| 1081 |
+
WINPR_ASSERT(result);
|
| 1082 |
+
|
| 1083 |
+
struct addrinfo* addr = input;
|
| 1084 |
+
if (!addr)
|
| 1085 |
+
goto fail;
|
| 1086 |
+
|
| 1087 |
+
if (freerdp_settings_get_bool(context->settings, FreeRDP_PreferIPv6OverIPv4))
|
| 1088 |
+
{
|
| 1089 |
+
while (addr && (addr->ai_family != AF_INET6))
|
| 1090 |
+
addr = addr->ai_next;
|
| 1091 |
+
if (!addr)
|
| 1092 |
+
addr = input;
|
| 1093 |
+
}
|
| 1094 |
+
|
| 1095 |
+
/* We want to force IPvX, abort if not detected */
|
| 1096 |
+
const UINT32 IPvX = freerdp_settings_get_uint32(context->settings, FreeRDP_ForceIPvX);
|
| 1097 |
+
switch (IPvX)
|
| 1098 |
+
{
|
| 1099 |
+
case 4:
|
| 1100 |
+
case 6:
|
| 1101 |
+
{
|
| 1102 |
+
const int family = (IPvX == 4) ? AF_INET : AF_INET6;
|
| 1103 |
+
while (addr && (addr->ai_family != family))
|
| 1104 |
+
addr = addr->ai_next;
|
| 1105 |
+
}
|
| 1106 |
+
break;
|
| 1107 |
+
default:
|
| 1108 |
+
break;
|
| 1109 |
+
}
|
| 1110 |
+
|
| 1111 |
+
if (!addr)
|
| 1112 |
+
goto fail;
|
| 1113 |
+
|
| 1114 |
+
*result = addr;
|
| 1115 |
+
return 0;
|
| 1116 |
+
|
| 1117 |
+
fail:
|
| 1118 |
+
freerdp_set_last_error_if_not(context, errorCode);
|
| 1119 |
+
freeaddrinfo(input);
|
| 1120 |
+
return -1;
|
| 1121 |
+
}
|
| 1122 |
+
|
| 1123 |
+
int freerdp_tcp_default_connect(rdpContext* context, rdpSettings* settings, const char* hostname,
|
| 1124 |
+
int port, DWORD timeout)
|
| 1125 |
+
{
|
| 1126 |
+
int sockfd = 0;
|
| 1127 |
+
UINT32 optval = 0;
|
| 1128 |
+
socklen_t optlen = 0;
|
| 1129 |
+
BOOL ipcSocket = FALSE;
|
| 1130 |
+
BOOL useExternalDefinedSocket = FALSE;
|
| 1131 |
+
|
| 1132 |
+
if (!hostname)
|
| 1133 |
+
{
|
| 1134 |
+
freerdp_set_last_error_if_not(context, FREERDP_ERROR_CONNECT_FAILED);
|
| 1135 |
+
|
| 1136 |
+
return -1;
|
| 1137 |
+
}
|
| 1138 |
+
|
| 1139 |
+
if (hostname[0] == '/')
|
| 1140 |
+
ipcSocket = TRUE;
|
| 1141 |
+
|
| 1142 |
+
if (hostname[0] == '|')
|
| 1143 |
+
useExternalDefinedSocket = TRUE;
|
| 1144 |
+
|
| 1145 |
+
const char* vsock = utils_is_vsock(hostname);
|
| 1146 |
+
if (ipcSocket)
|
| 1147 |
+
{
|
| 1148 |
+
sockfd = freerdp_uds_connect(hostname);
|
| 1149 |
+
|
| 1150 |
+
if (sockfd < 0)
|
| 1151 |
+
{
|
| 1152 |
+
freerdp_set_last_error_if_not(context, FREERDP_ERROR_CONNECT_FAILED);
|
| 1153 |
+
return -1;
|
| 1154 |
+
}
|
| 1155 |
+
}
|
| 1156 |
+
else if (useExternalDefinedSocket)
|
| 1157 |
+
sockfd = port;
|
| 1158 |
+
else if (vsock)
|
| 1159 |
+
{
|
| 1160 |
+
#if defined(HAVE_AF_VSOCK_H)
|
| 1161 |
+
hostname = vsock;
|
| 1162 |
+
sockfd = socket(AF_VSOCK, SOCK_STREAM, 0);
|
| 1163 |
+
if (sockfd < 0)
|
| 1164 |
+
{
|
| 1165 |
+
char buffer[256] = { 0 };
|
| 1166 |
+
WLog_WARN(TAG, "socket(AF_VSOCK, SOCK_STREAM, 0) failed with %s [%d]",
|
| 1167 |
+
winpr_strerror(errno, buffer, sizeof(buffer)));
|
| 1168 |
+
freerdp_set_last_error_if_not(context, FREERDP_ERROR_CONNECT_FAILED);
|
| 1169 |
+
return -1;
|
| 1170 |
+
}
|
| 1171 |
+
|
| 1172 |
+
struct sockaddr_vm addr = { 0 };
|
| 1173 |
+
|
| 1174 |
+
addr.svm_family = AF_VSOCK;
|
| 1175 |
+
addr.svm_port = WINPR_ASSERTING_INT_CAST(typeof(addr.svm_port), port);
|
| 1176 |
+
|
| 1177 |
+
errno = 0;
|
| 1178 |
+
char* ptr = NULL;
|
| 1179 |
+
unsigned long val = strtoul(hostname, &ptr, 10);
|
| 1180 |
+
if (errno || (val > UINT32_MAX))
|
| 1181 |
+
{
|
| 1182 |
+
char ebuffer[256] = { 0 };
|
| 1183 |
+
WLog_ERR(TAG, "could not extract port from '%s', value=%ul, error=%s", hostname, val,
|
| 1184 |
+
winpr_strerror(errno, ebuffer, sizeof(ebuffer)));
|
| 1185 |
+
return -1;
|
| 1186 |
+
}
|
| 1187 |
+
addr.svm_cid = WINPR_ASSERTING_INT_CAST(typeof(addr.svm_cid), val);
|
| 1188 |
+
if (addr.svm_cid == 2)
|
| 1189 |
+
{
|
| 1190 |
+
addr.svm_flags = VMADDR_FLAG_TO_HOST;
|
| 1191 |
+
}
|
| 1192 |
+
if ((connect(sockfd, (struct sockaddr*)&addr, sizeof(struct sockaddr_vm))) == -1)
|
| 1193 |
+
{
|
| 1194 |
+
WLog_ERR(TAG, "failed to connect to %s", hostname);
|
| 1195 |
+
return -1;
|
| 1196 |
+
}
|
| 1197 |
+
#else
|
| 1198 |
+
WLog_ERR(TAG, "Compiled without AF_VSOCK, '%s' not supported", hostname);
|
| 1199 |
+
return -1;
|
| 1200 |
+
#endif
|
| 1201 |
+
}
|
| 1202 |
+
else
|
| 1203 |
+
{
|
| 1204 |
+
sockfd = -1;
|
| 1205 |
+
|
| 1206 |
+
if (!settings->GatewayEnabled)
|
| 1207 |
+
{
|
| 1208 |
+
if (!freerdp_tcp_is_hostname_resolvable(context, hostname) ||
|
| 1209 |
+
settings->RemoteAssistanceMode)
|
| 1210 |
+
{
|
| 1211 |
+
if (settings->TargetNetAddressCount > 0)
|
| 1212 |
+
{
|
| 1213 |
+
WINPR_ASSERT(port <= UINT16_MAX);
|
| 1214 |
+
sockfd = freerdp_tcp_connect_multi(
|
| 1215 |
+
context, settings->TargetNetAddresses, settings->TargetNetPorts,
|
| 1216 |
+
settings->TargetNetAddressCount, (UINT16)port, timeout);
|
| 1217 |
+
}
|
| 1218 |
+
}
|
| 1219 |
+
}
|
| 1220 |
+
|
| 1221 |
+
if (sockfd <= 0)
|
| 1222 |
+
{
|
| 1223 |
+
char* peerAddress = NULL;
|
| 1224 |
+
struct addrinfo* addr = NULL;
|
| 1225 |
+
struct addrinfo* result = NULL;
|
| 1226 |
+
|
| 1227 |
+
result = freerdp_tcp_resolve_host(hostname, port, 0);
|
| 1228 |
+
|
| 1229 |
+
if (!result)
|
| 1230 |
+
{
|
| 1231 |
+
freerdp_set_last_error_if_not(context, FREERDP_ERROR_DNS_NAME_NOT_FOUND);
|
| 1232 |
+
|
| 1233 |
+
return -1;
|
| 1234 |
+
}
|
| 1235 |
+
freerdp_set_last_error_log(context, 0);
|
| 1236 |
+
|
| 1237 |
+
/* By default we take the first returned entry.
|
| 1238 |
+
*
|
| 1239 |
+
* If PreferIPv6OverIPv4 = TRUE we force to IPv6 if there
|
| 1240 |
+
* is such an address available, but fall back to first if not found
|
| 1241 |
+
*/
|
| 1242 |
+
const int rc =
|
| 1243 |
+
get_next_addrinfo(context, result, &addr, FREERDP_ERROR_DNS_NAME_NOT_FOUND);
|
| 1244 |
+
if (rc < 0)
|
| 1245 |
+
return rc;
|
| 1246 |
+
|
| 1247 |
+
do
|
| 1248 |
+
{
|
| 1249 |
+
sockfd = socket(addr->ai_family, addr->ai_socktype, addr->ai_protocol);
|
| 1250 |
+
if (sockfd < 0)
|
| 1251 |
+
{
|
| 1252 |
+
const int lrc = get_next_addrinfo(context, addr->ai_next, &addr,
|
| 1253 |
+
FREERDP_ERROR_CONNECT_FAILED);
|
| 1254 |
+
if (lrc < 0)
|
| 1255 |
+
return lrc;
|
| 1256 |
+
}
|
| 1257 |
+
} while (sockfd < 0);
|
| 1258 |
+
|
| 1259 |
+
if ((peerAddress = freerdp_tcp_address_to_string(
|
| 1260 |
+
(const struct sockaddr_storage*)addr->ai_addr, NULL)) != NULL)
|
| 1261 |
+
{
|
| 1262 |
+
WLog_DBG(TAG, "connecting to peer %s", peerAddress);
|
| 1263 |
+
free(peerAddress);
|
| 1264 |
+
}
|
| 1265 |
+
|
| 1266 |
+
if (!freerdp_tcp_connect_timeout(context, sockfd, addr->ai_addr, addr->ai_addrlen,
|
| 1267 |
+
timeout))
|
| 1268 |
+
{
|
| 1269 |
+
freeaddrinfo(result);
|
| 1270 |
+
close(sockfd);
|
| 1271 |
+
|
| 1272 |
+
freerdp_set_last_error_if_not(context, FREERDP_ERROR_CONNECT_FAILED);
|
| 1273 |
+
|
| 1274 |
+
WLog_ERR(TAG, "failed to connect to %s", hostname);
|
| 1275 |
+
return -1;
|
| 1276 |
+
}
|
| 1277 |
+
|
| 1278 |
+
freeaddrinfo(result);
|
| 1279 |
+
}
|
| 1280 |
+
}
|
| 1281 |
+
|
| 1282 |
+
if (!vsock)
|
| 1283 |
+
{
|
| 1284 |
+
free(settings->ClientAddress);
|
| 1285 |
+
settings->ClientAddress = freerdp_tcp_get_ip_address(sockfd, &settings->IPv6Enabled);
|
| 1286 |
+
|
| 1287 |
+
if (!settings->ClientAddress)
|
| 1288 |
+
{
|
| 1289 |
+
if (!useExternalDefinedSocket)
|
| 1290 |
+
close(sockfd);
|
| 1291 |
+
|
| 1292 |
+
freerdp_set_last_error_if_not(context, FREERDP_ERROR_CONNECT_FAILED);
|
| 1293 |
+
|
| 1294 |
+
WLog_ERR(TAG, "Couldn't get socket ip address");
|
| 1295 |
+
return -1;
|
| 1296 |
+
}
|
| 1297 |
+
}
|
| 1298 |
+
|
| 1299 |
+
optval = 1;
|
| 1300 |
+
optlen = sizeof(optval);
|
| 1301 |
+
|
| 1302 |
+
if (!ipcSocket && !useExternalDefinedSocket)
|
| 1303 |
+
{
|
| 1304 |
+
if (setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY, (void*)&optval, optlen) < 0)
|
| 1305 |
+
WLog_ERR(TAG, "unable to set TCP_NODELAY");
|
| 1306 |
+
}
|
| 1307 |
+
|
| 1308 |
+
/* receive buffer must be a least 32 K */
|
| 1309 |
+
if (getsockopt(sockfd, SOL_SOCKET, SO_RCVBUF, (void*)&optval, &optlen) == 0)
|
| 1310 |
+
{
|
| 1311 |
+
if (optval < (1024 * 32))
|
| 1312 |
+
{
|
| 1313 |
+
optval = 1024 * 32;
|
| 1314 |
+
optlen = sizeof(optval);
|
| 1315 |
+
|
| 1316 |
+
if (setsockopt(sockfd, SOL_SOCKET, SO_RCVBUF, (void*)&optval, optlen) < 0)
|
| 1317 |
+
{
|
| 1318 |
+
close(sockfd);
|
| 1319 |
+
|
| 1320 |
+
freerdp_set_last_error_if_not(context, FREERDP_ERROR_CONNECT_FAILED);
|
| 1321 |
+
|
| 1322 |
+
WLog_ERR(TAG, "unable to set receive buffer len");
|
| 1323 |
+
return -1;
|
| 1324 |
+
}
|
| 1325 |
+
}
|
| 1326 |
+
}
|
| 1327 |
+
|
| 1328 |
+
if (!ipcSocket && !useExternalDefinedSocket)
|
| 1329 |
+
{
|
| 1330 |
+
if (!freerdp_tcp_set_keep_alive_mode(settings, sockfd))
|
| 1331 |
+
{
|
| 1332 |
+
close(sockfd);
|
| 1333 |
+
|
| 1334 |
+
freerdp_set_last_error_if_not(context, FREERDP_ERROR_CONNECT_FAILED);
|
| 1335 |
+
|
| 1336 |
+
WLog_ERR(TAG, "Couldn't set keep alive mode.");
|
| 1337 |
+
return -1;
|
| 1338 |
+
}
|
| 1339 |
+
}
|
| 1340 |
+
|
| 1341 |
+
if (WaitForSingleObject(utils_get_abort_event(context->rdp), 0) == WAIT_OBJECT_0)
|
| 1342 |
+
{
|
| 1343 |
+
close(sockfd);
|
| 1344 |
+
return -1;
|
| 1345 |
+
}
|
| 1346 |
+
|
| 1347 |
+
return sockfd;
|
| 1348 |
+
}
|
| 1349 |
+
|
| 1350 |
+
struct rdp_tcp_layer
|
| 1351 |
+
{
|
| 1352 |
+
int sockfd;
|
| 1353 |
+
HANDLE hEvent;
|
| 1354 |
+
};
|
| 1355 |
+
typedef struct rdp_tcp_layer rdpTcpLayer;
|
| 1356 |
+
|
| 1357 |
+
static int freerdp_tcp_layer_read(void* userContext, void* data, int bytes)
|
| 1358 |
+
{
|
| 1359 |
+
if (!userContext)
|
| 1360 |
+
return -1;
|
| 1361 |
+
if (!data || !bytes)
|
| 1362 |
+
return 0;
|
| 1363 |
+
|
| 1364 |
+
rdpTcpLayer* tcpLayer = (rdpTcpLayer*)userContext;
|
| 1365 |
+
|
| 1366 |
+
int error = 0;
|
| 1367 |
+
int status = 0;
|
| 1368 |
+
|
| 1369 |
+
(void)WSAResetEvent(tcpLayer->hEvent);
|
| 1370 |
+
status = _recv((SOCKET)tcpLayer->sockfd, data, bytes, 0);
|
| 1371 |
+
|
| 1372 |
+
if (status > 0)
|
| 1373 |
+
return status;
|
| 1374 |
+
|
| 1375 |
+
if (status == 0)
|
| 1376 |
+
return -1; /* socket closed */
|
| 1377 |
+
|
| 1378 |
+
error = WSAGetLastError();
|
| 1379 |
+
|
| 1380 |
+
if ((error == WSAEWOULDBLOCK) || (error == WSAEINTR) || (error == WSAEINPROGRESS) ||
|
| 1381 |
+
(error == WSAEALREADY))
|
| 1382 |
+
{
|
| 1383 |
+
status = 0;
|
| 1384 |
+
}
|
| 1385 |
+
else
|
| 1386 |
+
{
|
| 1387 |
+
status = -1;
|
| 1388 |
+
}
|
| 1389 |
+
|
| 1390 |
+
return status;
|
| 1391 |
+
}
|
| 1392 |
+
|
| 1393 |
+
static int freerdp_tcp_layer_write(void* userContext, const void* data, int bytes)
|
| 1394 |
+
{
|
| 1395 |
+
if (!userContext)
|
| 1396 |
+
return -1;
|
| 1397 |
+
if (!data || !bytes)
|
| 1398 |
+
return 0;
|
| 1399 |
+
|
| 1400 |
+
rdpTcpLayer* tcpLayer = (rdpTcpLayer*)userContext;
|
| 1401 |
+
|
| 1402 |
+
int error = 0;
|
| 1403 |
+
int status = 0;
|
| 1404 |
+
|
| 1405 |
+
status = _send((SOCKET)tcpLayer->sockfd, data, bytes, 0);
|
| 1406 |
+
|
| 1407 |
+
if (status <= 0)
|
| 1408 |
+
{
|
| 1409 |
+
error = WSAGetLastError();
|
| 1410 |
+
|
| 1411 |
+
if ((error == WSAEWOULDBLOCK) || (error == WSAEINTR) || (error == WSAEINPROGRESS) ||
|
| 1412 |
+
(error == WSAEALREADY))
|
| 1413 |
+
{
|
| 1414 |
+
status = 0;
|
| 1415 |
+
}
|
| 1416 |
+
else
|
| 1417 |
+
{
|
| 1418 |
+
status = -1;
|
| 1419 |
+
}
|
| 1420 |
+
}
|
| 1421 |
+
|
| 1422 |
+
return status;
|
| 1423 |
+
}
|
| 1424 |
+
|
| 1425 |
+
static BOOL freerdp_tcp_layer_close(void* userContext)
|
| 1426 |
+
{
|
| 1427 |
+
if (!userContext)
|
| 1428 |
+
return FALSE;
|
| 1429 |
+
|
| 1430 |
+
rdpTcpLayer* tcpLayer = (rdpTcpLayer*)userContext;
|
| 1431 |
+
|
| 1432 |
+
if (tcpLayer->sockfd >= 0)
|
| 1433 |
+
closesocket((SOCKET)tcpLayer->sockfd);
|
| 1434 |
+
if (tcpLayer->hEvent)
|
| 1435 |
+
(void)CloseHandle(tcpLayer->hEvent);
|
| 1436 |
+
|
| 1437 |
+
return TRUE;
|
| 1438 |
+
}
|
| 1439 |
+
|
| 1440 |
+
static BOOL freerdp_tcp_layer_wait(void* userContext, BOOL waitWrite, DWORD timeout)
|
| 1441 |
+
{
|
| 1442 |
+
if (!userContext)
|
| 1443 |
+
return FALSE;
|
| 1444 |
+
|
| 1445 |
+
rdpTcpLayer* tcpLayer = (rdpTcpLayer*)userContext;
|
| 1446 |
+
|
| 1447 |
+
int status = -1;
|
| 1448 |
+
int sockfd = tcpLayer->sockfd;
|
| 1449 |
+
#ifdef WINPR_HAVE_POLL_H
|
| 1450 |
+
struct pollfd pollset = { 0 };
|
| 1451 |
+
pollset.fd = sockfd;
|
| 1452 |
+
pollset.events = waitWrite ? POLLOUT : POLLIN;
|
| 1453 |
+
|
| 1454 |
+
do
|
| 1455 |
+
{
|
| 1456 |
+
status = poll(&pollset, 1, (int)timeout);
|
| 1457 |
+
} while ((status < 0) && (errno == EINTR));
|
| 1458 |
+
|
| 1459 |
+
#else
|
| 1460 |
+
fd_set rset = { 0 };
|
| 1461 |
+
struct timeval tv = { 0 };
|
| 1462 |
+
FD_ZERO(&rset);
|
| 1463 |
+
FD_SET(sockfd, &rset);
|
| 1464 |
+
|
| 1465 |
+
if (timeout)
|
| 1466 |
+
{
|
| 1467 |
+
tv.tv_sec = timeout / 1000;
|
| 1468 |
+
tv.tv_usec = (timeout % 1000) * 1000;
|
| 1469 |
+
}
|
| 1470 |
+
|
| 1471 |
+
do
|
| 1472 |
+
{
|
| 1473 |
+
if (waitWrite)
|
| 1474 |
+
status = select(sockfd + 1, NULL, &rset, NULL, timeout ? &tv : NULL);
|
| 1475 |
+
else
|
| 1476 |
+
status = select(sockfd + 1, &rset, NULL, NULL, timeout ? &tv : NULL);
|
| 1477 |
+
} while ((status < 0) && (errno == EINTR));
|
| 1478 |
+
|
| 1479 |
+
#endif
|
| 1480 |
+
|
| 1481 |
+
return status != 0;
|
| 1482 |
+
}
|
| 1483 |
+
|
| 1484 |
+
static HANDLE freerdp_tcp_layer_get_event(void* userContext)
|
| 1485 |
+
{
|
| 1486 |
+
if (!userContext)
|
| 1487 |
+
return NULL;
|
| 1488 |
+
|
| 1489 |
+
rdpTcpLayer* tcpLayer = (rdpTcpLayer*)userContext;
|
| 1490 |
+
|
| 1491 |
+
return tcpLayer->hEvent;
|
| 1492 |
+
}
|
| 1493 |
+
|
| 1494 |
+
rdpTransportLayer* freerdp_tcp_connect_layer(rdpContext* context, const char* hostname, int port,
|
| 1495 |
+
DWORD timeout)
|
| 1496 |
+
{
|
| 1497 |
+
WINPR_ASSERT(context);
|
| 1498 |
+
|
| 1499 |
+
const rdpSettings* settings = context->settings;
|
| 1500 |
+
WINPR_ASSERT(settings);
|
| 1501 |
+
|
| 1502 |
+
rdpTransportLayer* layer = NULL;
|
| 1503 |
+
rdpTcpLayer* tcpLayer = NULL;
|
| 1504 |
+
|
| 1505 |
+
int sockfd = freerdp_tcp_connect(context, hostname, port, timeout);
|
| 1506 |
+
if (sockfd < 0)
|
| 1507 |
+
goto fail;
|
| 1508 |
+
if (!freerdp_tcp_set_keep_alive_mode(settings, sockfd))
|
| 1509 |
+
goto fail;
|
| 1510 |
+
|
| 1511 |
+
layer = transport_layer_new(freerdp_get_transport(context), sizeof(rdpTcpLayer));
|
| 1512 |
+
if (!layer)
|
| 1513 |
+
goto fail;
|
| 1514 |
+
|
| 1515 |
+
layer->Read = freerdp_tcp_layer_read;
|
| 1516 |
+
layer->Write = freerdp_tcp_layer_write;
|
| 1517 |
+
layer->Close = freerdp_tcp_layer_close;
|
| 1518 |
+
layer->Wait = freerdp_tcp_layer_wait;
|
| 1519 |
+
layer->GetEvent = freerdp_tcp_layer_get_event;
|
| 1520 |
+
|
| 1521 |
+
tcpLayer = (rdpTcpLayer*)layer->userContext;
|
| 1522 |
+
WINPR_ASSERT(tcpLayer);
|
| 1523 |
+
|
| 1524 |
+
tcpLayer->sockfd = -1;
|
| 1525 |
+
tcpLayer->hEvent = WSACreateEvent();
|
| 1526 |
+
if (!tcpLayer->hEvent)
|
| 1527 |
+
goto fail;
|
| 1528 |
+
|
| 1529 |
+
/* WSAEventSelect automatically sets the socket in non-blocking mode */
|
| 1530 |
+
if (WSAEventSelect((SOCKET)sockfd, tcpLayer->hEvent, FD_READ | FD_ACCEPT | FD_CLOSE))
|
| 1531 |
+
{
|
| 1532 |
+
WLog_ERR(TAG, "WSAEventSelect returned 0x%08X", WSAGetLastError());
|
| 1533 |
+
goto fail;
|
| 1534 |
+
}
|
| 1535 |
+
|
| 1536 |
+
tcpLayer->sockfd = sockfd;
|
| 1537 |
+
|
| 1538 |
+
return layer;
|
| 1539 |
+
|
| 1540 |
+
fail:
|
| 1541 |
+
if (sockfd >= 0)
|
| 1542 |
+
closesocket((SOCKET)sockfd);
|
| 1543 |
+
transport_layer_free(layer);
|
| 1544 |
+
return NULL;
|
| 1545 |
+
}
|
local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/timezone.c
ADDED
|
@@ -0,0 +1,281 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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 1 |
+
/**
|
| 2 |
+
* FreeRDP: A Remote Desktop Protocol Implementation
|
| 3 |
+
* Time Zone Redirection
|
| 4 |
+
*
|
| 5 |
+
* Copyright 2012 Marc-Andre Moreau <[email protected]>
|
| 6 |
+
*
|
| 7 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 8 |
+
* you may not use this file except in compliance with the License.
|
| 9 |
+
* You may obtain a copy of the License at
|
| 10 |
+
*
|
| 11 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
+
*
|
| 13 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 14 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 15 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 16 |
+
* See the License for the specific language governing permissions and
|
| 17 |
+
* limitations under the License.
|
| 18 |
+
*/
|
| 19 |
+
|
| 20 |
+
#include <freerdp/config.h>
|
| 21 |
+
|
| 22 |
+
#include <winpr/crt.h>
|
| 23 |
+
#include <winpr/assert.h>
|
| 24 |
+
#include <winpr/timezone.h>
|
| 25 |
+
|
| 26 |
+
#include "settings.h"
|
| 27 |
+
#include "timezone.h"
|
| 28 |
+
|
| 29 |
+
#include <freerdp/log.h>
|
| 30 |
+
#define TAG FREERDP_TAG("core.timezone")
|
| 31 |
+
|
| 32 |
+
#if !defined(WITH_DEBUG_TIMEZONE)
|
| 33 |
+
#define log_timezone(tzif, result)
|
| 34 |
+
#else
|
| 35 |
+
#define log_timezone(tzif, result) log_timezone_((tzif), (result), __FILE__, __func__, __LINE__)
|
| 36 |
+
static const char* weekday2str(WORD wDayOfWeek)
|
| 37 |
+
{
|
| 38 |
+
switch (wDayOfWeek)
|
| 39 |
+
{
|
| 40 |
+
case 0:
|
| 41 |
+
return "SUNDAY";
|
| 42 |
+
case 1:
|
| 43 |
+
return "MONDAY";
|
| 44 |
+
case 2:
|
| 45 |
+
return "TUESDAY";
|
| 46 |
+
case 3:
|
| 47 |
+
return "WEDNESDAY";
|
| 48 |
+
case 4:
|
| 49 |
+
return "THURSDAY";
|
| 50 |
+
case 5:
|
| 51 |
+
return "FRIDAY";
|
| 52 |
+
case 6:
|
| 53 |
+
return "SATURDAY";
|
| 54 |
+
default:
|
| 55 |
+
return "DAY-OF-MAGIC";
|
| 56 |
+
}
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
static char* systemtime2str(const SYSTEMTIME* t, char* buffer, size_t len)
|
| 60 |
+
{
|
| 61 |
+
const SYSTEMTIME empty = { 0 };
|
| 62 |
+
|
| 63 |
+
if (memcmp(t, &empty, sizeof(SYSTEMTIME)) == 0)
|
| 64 |
+
(void)_snprintf(buffer, len, "{ not set }");
|
| 65 |
+
else
|
| 66 |
+
{
|
| 67 |
+
(void)_snprintf(buffer, len,
|
| 68 |
+
"{ %" PRIu16 "-%" PRIu16 "-%" PRIu16 " [%s] %" PRIu16 ":%" PRIu16
|
| 69 |
+
":%" PRIu16 ".%" PRIu16 "}",
|
| 70 |
+
t->wYear, t->wMonth, t->wDay, weekday2str(t->wDayOfWeek), t->wHour,
|
| 71 |
+
t->wMinute, t->wSecond, t->wMilliseconds);
|
| 72 |
+
}
|
| 73 |
+
return buffer;
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
static void log_print(wLog* log, DWORD level, const char* file, const char* fkt, size_t line, ...)
|
| 77 |
+
{
|
| 78 |
+
if (!WLog_IsLevelActive(log, level))
|
| 79 |
+
return;
|
| 80 |
+
|
| 81 |
+
va_list ap = { 0 };
|
| 82 |
+
va_start(ap, line);
|
| 83 |
+
WLog_PrintMessageVA(log, WLOG_MESSAGE_TEXT, level, line, file, fkt, ap);
|
| 84 |
+
va_end(ap);
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
static void log_timezone_(const TIME_ZONE_INFORMATION* tzif, DWORD result, const char* file,
|
| 88 |
+
const char* fkt, size_t line)
|
| 89 |
+
{
|
| 90 |
+
WINPR_ASSERT(tzif);
|
| 91 |
+
|
| 92 |
+
char buffer[64] = { 0 };
|
| 93 |
+
DWORD level = WLOG_TRACE;
|
| 94 |
+
wLog* log = WLog_Get(TIMEZONE_TAG);
|
| 95 |
+
log_print(log, level, file, fkt, line, "TIME_ZONE_INFORMATION {");
|
| 96 |
+
log_print(log, level, file, fkt, line, " Bias=%" PRId32, tzif->Bias);
|
| 97 |
+
(void)ConvertWCharNToUtf8(tzif->StandardName, ARRAYSIZE(tzif->StandardName), buffer,
|
| 98 |
+
ARRAYSIZE(buffer));
|
| 99 |
+
log_print(log, level, file, fkt, line, " StandardName=%s", buffer);
|
| 100 |
+
log_print(log, level, file, fkt, line, " StandardDate=%s",
|
| 101 |
+
systemtime2str(&tzif->StandardDate, buffer, sizeof(buffer)));
|
| 102 |
+
log_print(log, level, file, fkt, line, " StandardBias=%" PRId32, tzif->StandardBias);
|
| 103 |
+
|
| 104 |
+
(void)ConvertWCharNToUtf8(tzif->DaylightName, ARRAYSIZE(tzif->DaylightName), buffer,
|
| 105 |
+
ARRAYSIZE(buffer));
|
| 106 |
+
log_print(log, level, file, fkt, line, " DaylightName=%s", buffer);
|
| 107 |
+
log_print(log, level, file, fkt, line, " DaylightDate=%s",
|
| 108 |
+
systemtime2str(&tzif->DaylightDate, buffer, sizeof(buffer)));
|
| 109 |
+
log_print(log, level, file, fkt, line, " DaylightBias=%" PRId32, tzif->DaylightBias);
|
| 110 |
+
|
| 111 |
+
switch (result)
|
| 112 |
+
{
|
| 113 |
+
case TIME_ZONE_ID_DAYLIGHT:
|
| 114 |
+
log_print(log, level, file, fkt, line, " DaylightDate in use");
|
| 115 |
+
break;
|
| 116 |
+
case TIME_ZONE_ID_STANDARD:
|
| 117 |
+
log_print(log, level, file, fkt, line, " StandardDate in use");
|
| 118 |
+
break;
|
| 119 |
+
default:
|
| 120 |
+
log_print(log, level, file, fkt, line, " UnknownDate in use");
|
| 121 |
+
break;
|
| 122 |
+
}
|
| 123 |
+
log_print(log, level, file, fkt, line, "}");
|
| 124 |
+
}
|
| 125 |
+
#endif
|
| 126 |
+
|
| 127 |
+
static BOOL rdp_read_system_time(wStream* s, SYSTEMTIME* system_time);
|
| 128 |
+
static BOOL rdp_write_system_time(wStream* s, const SYSTEMTIME* system_time);
|
| 129 |
+
|
| 130 |
+
/**
|
| 131 |
+
* Read SYSTEM_TIME structure (TS_SYSTEMTIME).
|
| 132 |
+
* msdn{cc240478}
|
| 133 |
+
* @param s stream
|
| 134 |
+
* @param system_time system time structure
|
| 135 |
+
*/
|
| 136 |
+
|
| 137 |
+
BOOL rdp_read_system_time(wStream* s, SYSTEMTIME* system_time)
|
| 138 |
+
{
|
| 139 |
+
WINPR_ASSERT(system_time);
|
| 140 |
+
|
| 141 |
+
if (!Stream_CheckAndLogRequiredLength(TAG, s, 16ull))
|
| 142 |
+
return FALSE;
|
| 143 |
+
|
| 144 |
+
Stream_Read_UINT16(s, system_time->wYear); /* wYear, must be set to 0 */
|
| 145 |
+
Stream_Read_UINT16(s, system_time->wMonth); /* wMonth */
|
| 146 |
+
Stream_Read_UINT16(s, system_time->wDayOfWeek); /* wDayOfWeek */
|
| 147 |
+
Stream_Read_UINT16(s, system_time->wDay); /* wDay */
|
| 148 |
+
Stream_Read_UINT16(s, system_time->wHour); /* wHour */
|
| 149 |
+
Stream_Read_UINT16(s, system_time->wMinute); /* wMinute */
|
| 150 |
+
Stream_Read_UINT16(s, system_time->wSecond); /* wSecond */
|
| 151 |
+
Stream_Read_UINT16(s, system_time->wMilliseconds); /* wMilliseconds */
|
| 152 |
+
return TRUE;
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
/**
|
| 156 |
+
* Write SYSTEM_TIME structure (TS_SYSTEMTIME).
|
| 157 |
+
* msdn{cc240478}
|
| 158 |
+
* @param s stream
|
| 159 |
+
* @param system_time system time structure
|
| 160 |
+
*/
|
| 161 |
+
|
| 162 |
+
BOOL rdp_write_system_time(wStream* s, const SYSTEMTIME* system_time)
|
| 163 |
+
{
|
| 164 |
+
WINPR_ASSERT(system_time);
|
| 165 |
+
if (!Stream_EnsureRemainingCapacity(s, 16ull))
|
| 166 |
+
return FALSE;
|
| 167 |
+
|
| 168 |
+
Stream_Write_UINT16(s, system_time->wYear); /* wYear, must be set to 0 */
|
| 169 |
+
Stream_Write_UINT16(s, system_time->wMonth); /* wMonth */
|
| 170 |
+
Stream_Write_UINT16(s, system_time->wDayOfWeek); /* wDayOfWeek */
|
| 171 |
+
Stream_Write_UINT16(s, system_time->wDay); /* wDay */
|
| 172 |
+
Stream_Write_UINT16(s, system_time->wHour); /* wHour */
|
| 173 |
+
Stream_Write_UINT16(s, system_time->wMinute); /* wMinute */
|
| 174 |
+
Stream_Write_UINT16(s, system_time->wSecond); /* wSecond */
|
| 175 |
+
Stream_Write_UINT16(s, system_time->wMilliseconds); /* wMilliseconds */
|
| 176 |
+
return TRUE;
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
/**
|
| 180 |
+
* Read client time zone information (TS_TIME_ZONE_INFORMATION).
|
| 181 |
+
* msdn{cc240477}
|
| 182 |
+
* @param s stream
|
| 183 |
+
* @param settings settings
|
| 184 |
+
*
|
| 185 |
+
* @return \b TRUE for success, \b FALSE otherwise
|
| 186 |
+
*/
|
| 187 |
+
|
| 188 |
+
BOOL rdp_read_client_time_zone(wStream* s, rdpSettings* settings)
|
| 189 |
+
{
|
| 190 |
+
LPTIME_ZONE_INFORMATION tz = { 0 };
|
| 191 |
+
|
| 192 |
+
if (!s || !settings)
|
| 193 |
+
return FALSE;
|
| 194 |
+
|
| 195 |
+
if (!Stream_CheckAndLogRequiredLength(TAG, s, 172))
|
| 196 |
+
return FALSE;
|
| 197 |
+
|
| 198 |
+
tz = settings->ClientTimeZone;
|
| 199 |
+
|
| 200 |
+
if (!tz)
|
| 201 |
+
return FALSE;
|
| 202 |
+
|
| 203 |
+
Stream_Read_INT32(s, tz->Bias); /* Bias */
|
| 204 |
+
/* standardName (64 bytes) */
|
| 205 |
+
Stream_Read(s, tz->StandardName, sizeof(tz->StandardName));
|
| 206 |
+
if (!rdp_read_system_time(s, &tz->StandardDate)) /* StandardDate */
|
| 207 |
+
return FALSE;
|
| 208 |
+
Stream_Read_INT32(s, tz->StandardBias); /* StandardBias */
|
| 209 |
+
/* daylightName (64 bytes) */
|
| 210 |
+
Stream_Read(s, tz->DaylightName, sizeof(tz->DaylightName));
|
| 211 |
+
if (!rdp_read_system_time(s, &tz->DaylightDate)) /* DaylightDate */
|
| 212 |
+
return FALSE;
|
| 213 |
+
Stream_Read_INT32(s, tz->DaylightBias); /* DaylightBias */
|
| 214 |
+
log_timezone(tz, 0);
|
| 215 |
+
return TRUE;
|
| 216 |
+
}
|
| 217 |
+
|
| 218 |
+
/**
|
| 219 |
+
* Write client time zone information (TS_TIME_ZONE_INFORMATION).
|
| 220 |
+
* msdn{cc240477}
|
| 221 |
+
* @param s stream
|
| 222 |
+
* @param settings settings
|
| 223 |
+
*
|
| 224 |
+
* @return \b TRUE for success, \b FALSE otherwise
|
| 225 |
+
*/
|
| 226 |
+
|
| 227 |
+
BOOL rdp_write_client_time_zone(wStream* s, rdpSettings* settings)
|
| 228 |
+
{
|
| 229 |
+
WINPR_ASSERT(settings);
|
| 230 |
+
const LPTIME_ZONE_INFORMATION tz = settings->ClientTimeZone;
|
| 231 |
+
|
| 232 |
+
if (!tz)
|
| 233 |
+
return FALSE;
|
| 234 |
+
|
| 235 |
+
log_timezone(tz, 0);
|
| 236 |
+
if (!Stream_EnsureRemainingCapacity(s, 4ull + sizeof(tz->StandardName)))
|
| 237 |
+
return FALSE;
|
| 238 |
+
|
| 239 |
+
/* Bias defined in windows headers as LONG
|
| 240 |
+
* but [MS-RDPBCGR] 2.2.1.11.1.1.1.1 Time Zone Information (TS_TIME_ZONE_INFORMATION) defines it
|
| 241 |
+
* as unsigned.... assume the spec is buggy as an unsigned value only works on half of the
|
| 242 |
+
* world.
|
| 243 |
+
*/
|
| 244 |
+
Stream_Write_INT32(s, tz->Bias);
|
| 245 |
+
/* standardName (64 bytes) */
|
| 246 |
+
Stream_Write(s, tz->StandardName, sizeof(tz->StandardName));
|
| 247 |
+
/* StandardDate */
|
| 248 |
+
if (!rdp_write_system_time(s, &tz->StandardDate))
|
| 249 |
+
return FALSE;
|
| 250 |
+
|
| 251 |
+
/* Note that StandardBias is ignored if no valid standardDate is provided. */
|
| 252 |
+
/* StandardBias */
|
| 253 |
+
if (!Stream_EnsureRemainingCapacity(s, 4ull + sizeof(tz->DaylightName)))
|
| 254 |
+
return FALSE;
|
| 255 |
+
|
| 256 |
+
/* StandardBias defined in windows headers as LONG
|
| 257 |
+
* but [MS-RDPBCGR] 2.2.1.11.1.1.1.1 Time Zone Information (TS_TIME_ZONE_INFORMATION) defines it
|
| 258 |
+
* as unsigned.... assume the spec is buggy as an unsigned value only works on half of the
|
| 259 |
+
* world.
|
| 260 |
+
*/
|
| 261 |
+
Stream_Write_INT32(s, tz->StandardBias);
|
| 262 |
+
|
| 263 |
+
/* daylightName (64 bytes) */
|
| 264 |
+
Stream_Write(s, tz->DaylightName, sizeof(tz->DaylightName));
|
| 265 |
+
/* DaylightDate */
|
| 266 |
+
if (!rdp_write_system_time(s, &tz->DaylightDate))
|
| 267 |
+
return FALSE;
|
| 268 |
+
/* Note that DaylightBias is ignored if no valid daylightDate is provided. */
|
| 269 |
+
/* DaylightBias */
|
| 270 |
+
if (!Stream_EnsureRemainingCapacity(s, 4ull))
|
| 271 |
+
return FALSE;
|
| 272 |
+
|
| 273 |
+
/* DaylightBias defined in windows headers as LONG
|
| 274 |
+
* but [MS-RDPBCGR] 2.2.1.11.1.1.1.1 Time Zone Information (TS_TIME_ZONE_INFORMATION) defines it
|
| 275 |
+
* as unsigned.... assume the spec is buggy as an unsigned value only works on half of the
|
| 276 |
+
* world.
|
| 277 |
+
*/
|
| 278 |
+
Stream_Write_INT32(s, tz->DaylightBias);
|
| 279 |
+
|
| 280 |
+
return TRUE;
|
| 281 |
+
}
|
local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/tpkt.h
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* FreeRDP: A Remote Desktop Protocol Implementation
|
| 3 |
+
* Transport Packets (TPKTs)
|
| 4 |
+
*
|
| 5 |
+
* Copyright 2011 Marc-Andre Moreau <[email protected]>
|
| 6 |
+
*
|
| 7 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 8 |
+
* you may not use this file except in compliance with the License.
|
| 9 |
+
* You may obtain a copy of the License at
|
| 10 |
+
*
|
| 11 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
+
*
|
| 13 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 14 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 15 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 16 |
+
* See the License for the specific language governing permissions and
|
| 17 |
+
* limitations under the License.
|
| 18 |
+
*/
|
| 19 |
+
|
| 20 |
+
#ifndef FREERDP_LIB_CORE_TPKT_H
|
| 21 |
+
#define FREERDP_LIB_CORE_TPKT_H
|
| 22 |
+
|
| 23 |
+
#include "tpdu.h"
|
| 24 |
+
#include "transport.h"
|
| 25 |
+
|
| 26 |
+
#include <winpr/stream.h>
|
| 27 |
+
#include <freerdp/api.h>
|
| 28 |
+
|
| 29 |
+
#define TPKT_HEADER_LENGTH 4
|
| 30 |
+
|
| 31 |
+
FREERDP_LOCAL int tpkt_verify_header(wStream* s);
|
| 32 |
+
FREERDP_LOCAL BOOL tpkt_read_header(wStream* s, UINT16* length);
|
| 33 |
+
FREERDP_LOCAL BOOL tpkt_write_header(wStream* s, size_t length);
|
| 34 |
+
#define tpkt_ensure_stream_consumed(s, length) tpkt_ensure_stream_consumed_((s), (length), __func__)
|
| 35 |
+
FREERDP_LOCAL BOOL tpkt_ensure_stream_consumed_(wStream* s, size_t length, const char* fkt);
|
| 36 |
+
|
| 37 |
+
#endif /* FREERDP_LIB_CORE_TPKT_H */
|
local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/transport.h
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* FreeRDP: A Remote Desktop Protocol Implementation
|
| 3 |
+
* Network Transport Layer
|
| 4 |
+
*
|
| 5 |
+
* Copyright 2011 Vic Lee
|
| 6 |
+
*
|
| 7 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 8 |
+
* you may not use this file except in compliance with the License.
|
| 9 |
+
* You may obtain a copy of the License at
|
| 10 |
+
*
|
| 11 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
+
*
|
| 13 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 14 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 15 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 16 |
+
* See the License for the specific language governing permissions and
|
| 17 |
+
* limitations under the License.
|
| 18 |
+
*/
|
| 19 |
+
|
| 20 |
+
#ifndef FREERDP_LIB_CORE_TRANSPORT_H
|
| 21 |
+
#define FREERDP_LIB_CORE_TRANSPORT_H
|
| 22 |
+
|
| 23 |
+
typedef enum
|
| 24 |
+
{
|
| 25 |
+
TRANSPORT_LAYER_TCP,
|
| 26 |
+
TRANSPORT_LAYER_TLS,
|
| 27 |
+
TRANSPORT_LAYER_NAMEDPIPE,
|
| 28 |
+
TRANSPORT_LAYER_TSG,
|
| 29 |
+
TRANSPORT_LAYER_TSG_TLS,
|
| 30 |
+
TRANSPORT_LAYER_CLOSED
|
| 31 |
+
} TRANSPORT_LAYER;
|
| 32 |
+
|
| 33 |
+
#include "tcp.h"
|
| 34 |
+
#include "nla.h"
|
| 35 |
+
#include "rdstls.h"
|
| 36 |
+
|
| 37 |
+
#include "gateway/tsg.h"
|
| 38 |
+
|
| 39 |
+
#include <winpr/sspi.h>
|
| 40 |
+
#include <winpr/wlog.h>
|
| 41 |
+
#include <winpr/synch.h>
|
| 42 |
+
#include <winpr/thread.h>
|
| 43 |
+
#include <winpr/stream.h>
|
| 44 |
+
#include <winpr/collections.h>
|
| 45 |
+
|
| 46 |
+
#include <freerdp/api.h>
|
| 47 |
+
|
| 48 |
+
#include <time.h>
|
| 49 |
+
#include <freerdp/types.h>
|
| 50 |
+
#include <freerdp/settings.h>
|
| 51 |
+
#include <freerdp/transport_io.h>
|
| 52 |
+
|
| 53 |
+
#include "state.h"
|
| 54 |
+
|
| 55 |
+
typedef state_run_t (*TransportRecv)(rdpTransport* transport, wStream* stream, void* extra);
|
| 56 |
+
|
| 57 |
+
FREERDP_LOCAL wStream* transport_send_stream_init(rdpTransport* transport, size_t size);
|
| 58 |
+
FREERDP_LOCAL BOOL transport_connect(rdpTransport* transport, const char* hostname, UINT16 port,
|
| 59 |
+
DWORD timeout);
|
| 60 |
+
FREERDP_LOCAL BOOL transport_connect_childsession(rdpTransport* transport);
|
| 61 |
+
|
| 62 |
+
/**! \brief Attach a socket to the transport layer
|
| 63 |
+
*
|
| 64 |
+
* The ownership of the socket provided by \b sockfd is taken if and only if the function is
|
| 65 |
+
* successful. In such a case the caller must no longer close or otherwise use the socket. If the
|
| 66 |
+
* function fails it is up to the caller to close the socket.
|
| 67 |
+
*
|
| 68 |
+
* The implementation can be overridden by
|
| 69 |
+
* transport_set_io_callbacks(rdpTransportIo::TransportAttach)
|
| 70 |
+
*
|
| 71 |
+
* \param transport The transport instance to attach the socket to
|
| 72 |
+
* \param sockfd The socket to attach to the transport
|
| 73 |
+
*
|
| 74 |
+
* \return \b TRUE in case of success, \b FALSE otherwise.
|
| 75 |
+
*/
|
| 76 |
+
FREERDP_LOCAL BOOL transport_attach(rdpTransport* transport, int sockfd);
|
| 77 |
+
|
| 78 |
+
/**! \brief Attach a transport layer
|
| 79 |
+
*
|
| 80 |
+
* The ownership of the transport layer provided by \b layer is taken if and only if the function is
|
| 81 |
+
* successful. In such a case the caller must no longer free or otherwise use the layer. If the
|
| 82 |
+
* function fails it is up to the caller to free the layer.
|
| 83 |
+
*
|
| 84 |
+
* The implementation can be overridden by
|
| 85 |
+
* transport_set_io_callbacks(rdpTransportIo::AttachLayer)
|
| 86 |
+
*
|
| 87 |
+
* \param transport The transport instance to attach the socket to
|
| 88 |
+
* \param layer The layer to attach to the transport
|
| 89 |
+
*
|
| 90 |
+
* \return \b TRUE in case of success, \b FALSE otherwise.
|
| 91 |
+
*/
|
| 92 |
+
FREERDP_LOCAL BOOL transport_attach_layer(rdpTransport* transport, rdpTransportLayer* layer);
|
| 93 |
+
|
| 94 |
+
FREERDP_LOCAL BOOL transport_disconnect(rdpTransport* transport);
|
| 95 |
+
FREERDP_LOCAL BOOL transport_connect_rdp(rdpTransport* transport);
|
| 96 |
+
FREERDP_LOCAL BOOL transport_connect_tls(rdpTransport* transport);
|
| 97 |
+
FREERDP_LOCAL BOOL transport_connect_nla(rdpTransport* transport, BOOL earlyUserAuth);
|
| 98 |
+
FREERDP_LOCAL BOOL transport_connect_rdstls(rdpTransport* transport);
|
| 99 |
+
FREERDP_LOCAL BOOL transport_connect_aad(rdpTransport* transport);
|
| 100 |
+
FREERDP_LOCAL BOOL transport_accept_rdp(rdpTransport* transport);
|
| 101 |
+
FREERDP_LOCAL BOOL transport_accept_tls(rdpTransport* transport);
|
| 102 |
+
FREERDP_LOCAL BOOL transport_accept_nla(rdpTransport* transport);
|
| 103 |
+
FREERDP_LOCAL BOOL transport_accept_rdstls(rdpTransport* transport);
|
| 104 |
+
|
| 105 |
+
FREERDP_LOCAL int transport_read_pdu(rdpTransport* transport, wStream* s);
|
| 106 |
+
FREERDP_LOCAL int transport_write(rdpTransport* transport, wStream* s);
|
| 107 |
+
|
| 108 |
+
FREERDP_LOCAL BOOL transport_get_public_key(rdpTransport* transport, const BYTE** data,
|
| 109 |
+
DWORD* length);
|
| 110 |
+
|
| 111 |
+
#if defined(WITH_FREERDP_DEPRECATED)
|
| 112 |
+
FREERDP_LOCAL void transport_get_fds(rdpTransport* transport, void** rfds, int* rcount);
|
| 113 |
+
#endif
|
| 114 |
+
FREERDP_LOCAL int transport_check_fds(rdpTransport* transport);
|
| 115 |
+
|
| 116 |
+
FREERDP_LOCAL DWORD transport_get_event_handles(rdpTransport* transport, HANDLE* events,
|
| 117 |
+
DWORD nCount);
|
| 118 |
+
FREERDP_LOCAL HANDLE transport_get_front_bio(rdpTransport* transport);
|
| 119 |
+
|
| 120 |
+
FREERDP_LOCAL BOOL transport_set_blocking_mode(rdpTransport* transport, BOOL blocking);
|
| 121 |
+
FREERDP_LOCAL void transport_set_gateway_enabled(rdpTransport* transport, BOOL GatewayEnabled);
|
| 122 |
+
FREERDP_LOCAL void transport_set_nla_mode(rdpTransport* transport, BOOL NlaMode);
|
| 123 |
+
FREERDP_LOCAL void transport_set_rdstls_mode(rdpTransport* transport, BOOL RdstlsMode);
|
| 124 |
+
FREERDP_LOCAL void transport_set_aad_mode(rdpTransport* transport, BOOL AadMode);
|
| 125 |
+
FREERDP_LOCAL BOOL transport_is_write_blocked(rdpTransport* transport);
|
| 126 |
+
FREERDP_LOCAL int transport_drain_output_buffer(rdpTransport* transport);
|
| 127 |
+
|
| 128 |
+
FREERDP_LOCAL BOOL transport_io_callback_set_event(rdpTransport* transport, BOOL set);
|
| 129 |
+
|
| 130 |
+
FREERDP_LOCAL const rdpTransportIo* transport_get_io_callbacks(rdpTransport* transport);
|
| 131 |
+
FREERDP_LOCAL BOOL transport_set_io_callbacks(rdpTransport* transport,
|
| 132 |
+
const rdpTransportIo* io_callbacks);
|
| 133 |
+
|
| 134 |
+
FREERDP_LOCAL BOOL transport_set_nla(rdpTransport* transport, rdpNla* nla);
|
| 135 |
+
FREERDP_LOCAL rdpNla* transport_get_nla(rdpTransport* transport);
|
| 136 |
+
|
| 137 |
+
FREERDP_LOCAL BOOL transport_set_tls(rdpTransport* transport, rdpTls* tls);
|
| 138 |
+
FREERDP_LOCAL rdpTls* transport_get_tls(rdpTransport* transport);
|
| 139 |
+
|
| 140 |
+
FREERDP_LOCAL BOOL transport_set_tsg(rdpTransport* transport, rdpTsg* tsg);
|
| 141 |
+
FREERDP_LOCAL rdpTsg* transport_get_tsg(rdpTransport* transport);
|
| 142 |
+
|
| 143 |
+
FREERDP_LOCAL wStream* transport_take_from_pool(rdpTransport* transport, size_t size);
|
| 144 |
+
|
| 145 |
+
FREERDP_LOCAL ULONG transport_get_bytes_sent(rdpTransport* transport, BOOL resetCount);
|
| 146 |
+
|
| 147 |
+
FREERDP_LOCAL BOOL transport_have_more_bytes_to_read(rdpTransport* transport);
|
| 148 |
+
|
| 149 |
+
FREERDP_LOCAL TRANSPORT_LAYER transport_get_layer(rdpTransport* transport);
|
| 150 |
+
FREERDP_LOCAL BOOL transport_set_layer(rdpTransport* transport, TRANSPORT_LAYER layer);
|
| 151 |
+
|
| 152 |
+
FREERDP_LOCAL BOOL transport_get_blocking(rdpTransport* transport);
|
| 153 |
+
FREERDP_LOCAL BOOL transport_set_blocking(rdpTransport* transport, BOOL blocking);
|
| 154 |
+
|
| 155 |
+
FREERDP_LOCAL BOOL transport_set_connected_event(rdpTransport* transport);
|
| 156 |
+
|
| 157 |
+
FREERDP_LOCAL BOOL transport_set_recv_callbacks(rdpTransport* transport, TransportRecv recv,
|
| 158 |
+
void* extra);
|
| 159 |
+
|
| 160 |
+
FREERDP_LOCAL int transport_tcp_connect(rdpTransport* transport, const char* hostname, int port,
|
| 161 |
+
DWORD timeout);
|
| 162 |
+
|
| 163 |
+
FREERDP_LOCAL rdpTransportLayer*
|
| 164 |
+
transport_connect_layer(rdpTransport* transport, const char* hostname, int port, DWORD timeout);
|
| 165 |
+
|
| 166 |
+
FREERDP_LOCAL void transport_free(rdpTransport* transport);
|
| 167 |
+
|
| 168 |
+
WINPR_ATTR_MALLOC(transport_free, 1)
|
| 169 |
+
FREERDP_LOCAL rdpTransport* transport_new(rdpContext* context);
|
| 170 |
+
|
| 171 |
+
FREERDP_LOCAL void transport_set_early_user_auth_mode(rdpTransport* transport, BOOL EUAMode);
|
| 172 |
+
|
| 173 |
+
FREERDP_LOCAL BIO_METHOD* BIO_s_transport_layer(void);
|
| 174 |
+
|
| 175 |
+
#endif /* FREERDP_LIB_CORE_TRANSPORT_H */
|