2012-11-18 09:08:03 +04:00
|
|
|
/**
|
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
|
|
|
* Settings Management
|
|
|
|
*
|
|
|
|
* Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
2016-02-26 16:50:27 +03:00
|
|
|
* Copyright 2016 Armin Novak <armin.novak@gmail.com>
|
2023-02-09 10:48:11 +03:00
|
|
|
* Copyright 2023 Armin Novak <anovak@thincast.com>
|
|
|
|
* Copyright 2023 Thincast Technologies GmbH
|
2012-11-18 09:08:03 +04:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2022-02-16 13:20:38 +03:00
|
|
|
#include <freerdp/config.h>
|
2012-11-18 09:08:03 +04:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2020-04-11 12:55:11 +03:00
|
|
|
#include <errno.h>
|
2012-11-18 09:08:03 +04:00
|
|
|
|
2012-12-05 23:00:49 +04:00
|
|
|
#include <winpr/crt.h>
|
2022-04-19 15:29:17 +03:00
|
|
|
#include <winpr/assert.h>
|
2012-12-05 23:00:49 +04:00
|
|
|
|
2020-11-19 12:09:34 +03:00
|
|
|
#include "../core/settings.h"
|
2022-10-05 10:30:37 +03:00
|
|
|
#include "../core/capabilities.h"
|
2023-02-03 13:40:35 +03:00
|
|
|
|
|
|
|
#include <freerdp/crypto/certificate.h>
|
2012-11-18 09:08:03 +04:00
|
|
|
#include <freerdp/settings.h>
|
2013-04-25 00:33:43 +04:00
|
|
|
#include <freerdp/freerdp.h>
|
2014-09-12 16:36:29 +04:00
|
|
|
#include <freerdp/log.h>
|
|
|
|
|
|
|
|
#define TAG FREERDP_TAG("common")
|
2012-11-18 09:08:03 +04:00
|
|
|
|
2021-04-12 11:38:40 +03:00
|
|
|
BOOL freerdp_addin_argv_add_argument_ex(ADDIN_ARGV* args, const char* argument, size_t len)
|
2012-12-05 23:00:49 +04:00
|
|
|
{
|
2021-04-12 11:38:40 +03:00
|
|
|
char* str;
|
2018-08-22 14:40:41 +03:00
|
|
|
char** new_argv;
|
2012-12-05 23:00:49 +04:00
|
|
|
|
2021-04-12 11:38:40 +03:00
|
|
|
if (!args || !argument)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (len == 0)
|
|
|
|
len = strlen(argument);
|
|
|
|
|
|
|
|
new_argv = (char**)realloc(args->argv, sizeof(char*) * (args->argc + 1));
|
|
|
|
|
|
|
|
if (!new_argv)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
args->argv = new_argv;
|
|
|
|
|
|
|
|
str = calloc(len + 1, sizeof(char));
|
|
|
|
if (!str)
|
|
|
|
return FALSE;
|
|
|
|
memcpy(str, argument, len);
|
|
|
|
args->argv[args->argc++] = str;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL freerdp_addin_argv_add_argument(ADDIN_ARGV* args, const char* argument)
|
|
|
|
{
|
|
|
|
return freerdp_addin_argv_add_argument_ex(args, argument, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL freerdp_addin_argv_del_argument(ADDIN_ARGV* args, const char* argument)
|
|
|
|
{
|
|
|
|
int x;
|
|
|
|
if (!args || !argument)
|
|
|
|
return FALSE;
|
|
|
|
for (x = 0; x < args->argc; x++)
|
|
|
|
{
|
|
|
|
char* arg = args->argv[x];
|
|
|
|
if (strcmp(argument, arg) == 0)
|
|
|
|
{
|
|
|
|
free(arg);
|
|
|
|
memmove_s(&args->argv[x], (args->argc - x) * sizeof(char*), &args->argv[x + 1],
|
|
|
|
(args->argc - x - 1) * sizeof(char*));
|
|
|
|
args->argv[args->argc - 1] = NULL;
|
|
|
|
args->argc--;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
int freerdp_addin_set_argument(ADDIN_ARGV* args, const char* argument)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
if (!args || !argument)
|
|
|
|
return -2;
|
|
|
|
|
2012-12-05 23:00:49 +04:00
|
|
|
for (i = 0; i < args->argc; i++)
|
|
|
|
{
|
|
|
|
if (strcmp(args->argv[i], argument) == 0)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-12 11:38:40 +03:00
|
|
|
if (!freerdp_addin_argv_add_argument(args, argument))
|
2015-03-11 08:52:24 +03:00
|
|
|
return -1;
|
2012-12-05 23:00:49 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-04-12 11:38:40 +03:00
|
|
|
int freerdp_addin_replace_argument(ADDIN_ARGV* args, const char* previous, const char* argument)
|
2012-12-05 23:00:49 +04:00
|
|
|
{
|
|
|
|
int i;
|
2021-04-12 11:38:40 +03:00
|
|
|
|
|
|
|
if (!args || !previous || !argument)
|
|
|
|
return -2;
|
2012-12-05 23:00:49 +04:00
|
|
|
|
|
|
|
for (i = 0; i < args->argc; i++)
|
|
|
|
{
|
|
|
|
if (strcmp(args->argv[i], previous) == 0)
|
|
|
|
{
|
|
|
|
free(args->argv[i]);
|
2018-08-22 14:40:41 +03:00
|
|
|
|
2015-06-17 23:08:02 +03:00
|
|
|
if (!(args->argv[i] = _strdup(argument)))
|
|
|
|
return -1;
|
2012-12-05 23:00:49 +04:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-12 11:38:40 +03:00
|
|
|
if (!freerdp_addin_argv_add_argument(args, argument))
|
2015-06-17 23:08:02 +03:00
|
|
|
return -1;
|
2012-12-05 23:00:49 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-04-12 11:38:40 +03:00
|
|
|
int freerdp_addin_set_argument_value(ADDIN_ARGV* args, const char* option, const char* value)
|
2012-12-05 23:00:49 +04:00
|
|
|
{
|
2021-04-12 11:38:40 +03:00
|
|
|
BOOL rc;
|
2012-12-05 23:00:49 +04:00
|
|
|
int i;
|
|
|
|
char* p;
|
|
|
|
char* str;
|
2019-10-29 12:18:09 +03:00
|
|
|
size_t length;
|
2021-04-12 11:38:40 +03:00
|
|
|
if (!args || !option || !value)
|
|
|
|
return -2;
|
2012-12-05 23:00:49 +04:00
|
|
|
length = strlen(option) + strlen(value) + 1;
|
2021-04-12 11:38:40 +03:00
|
|
|
str = (char*)calloc(length + 1, sizeof(char));
|
2018-08-22 14:40:41 +03:00
|
|
|
|
2015-06-16 16:42:07 +03:00
|
|
|
if (!str)
|
|
|
|
return -1;
|
2018-08-22 14:40:41 +03:00
|
|
|
|
2012-12-05 23:00:49 +04:00
|
|
|
sprintf_s(str, length + 1, "%s:%s", option, value);
|
|
|
|
|
|
|
|
for (i = 0; i < args->argc; i++)
|
|
|
|
{
|
|
|
|
p = strchr(args->argv[i], ':');
|
|
|
|
|
|
|
|
if (p)
|
|
|
|
{
|
|
|
|
if (strncmp(args->argv[i], option, p - args->argv[i]) == 0)
|
|
|
|
{
|
|
|
|
free(args->argv[i]);
|
|
|
|
args->argv[i] = str;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-12 11:38:40 +03:00
|
|
|
rc = freerdp_addin_argv_add_argument(args, str);
|
|
|
|
free(str);
|
|
|
|
if (!rc)
|
2015-03-11 08:52:24 +03:00
|
|
|
return -1;
|
2012-12-05 23:00:49 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-04-12 11:38:40 +03:00
|
|
|
int freerdp_addin_replace_argument_value(ADDIN_ARGV* args, const char* previous, const char* option,
|
|
|
|
const char* value)
|
2012-12-05 23:00:49 +04:00
|
|
|
{
|
|
|
|
int i;
|
2021-04-12 11:38:40 +03:00
|
|
|
BOOL rc;
|
2012-12-05 23:00:49 +04:00
|
|
|
char* str;
|
2019-10-29 12:18:09 +03:00
|
|
|
size_t length;
|
2021-04-12 11:38:40 +03:00
|
|
|
if (!args || !previous || !option || !value)
|
|
|
|
return -2;
|
2012-12-05 23:00:49 +04:00
|
|
|
length = strlen(option) + strlen(value) + 1;
|
2021-04-12 11:38:40 +03:00
|
|
|
str = (char*)calloc(length + 1, sizeof(char));
|
2018-08-22 14:40:41 +03:00
|
|
|
|
2015-06-16 16:42:07 +03:00
|
|
|
if (!str)
|
|
|
|
return -1;
|
2018-08-22 14:40:41 +03:00
|
|
|
|
2012-12-05 23:00:49 +04:00
|
|
|
sprintf_s(str, length + 1, "%s:%s", option, value);
|
|
|
|
|
|
|
|
for (i = 0; i < args->argc; i++)
|
|
|
|
{
|
|
|
|
if (strcmp(args->argv[i], previous) == 0)
|
|
|
|
{
|
|
|
|
free(args->argv[i]);
|
|
|
|
args->argv[i] = str;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-12 11:38:40 +03:00
|
|
|
rc = freerdp_addin_argv_add_argument(args, str);
|
|
|
|
free(str);
|
|
|
|
if (!rc)
|
2015-03-11 08:52:24 +03:00
|
|
|
return -1;
|
2012-12-05 23:00:49 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-06-18 14:00:10 +03:00
|
|
|
BOOL freerdp_device_collection_add(rdpSettings* settings, RDPDR_DEVICE* device)
|
2012-11-18 09:08:03 +04:00
|
|
|
{
|
2022-05-01 11:57:11 +03:00
|
|
|
UINT32 count, old;
|
2021-10-07 11:43:16 +03:00
|
|
|
WINPR_ASSERT(settings);
|
|
|
|
WINPR_ASSERT(device);
|
2015-03-10 15:10:39 +03:00
|
|
|
|
2022-05-01 11:57:11 +03:00
|
|
|
count = freerdp_settings_get_uint32(settings, FreeRDP_DeviceCount) + 1;
|
|
|
|
old = freerdp_settings_get_uint32(settings, FreeRDP_DeviceArraySize);
|
|
|
|
if (old < count)
|
2012-11-18 09:08:03 +04:00
|
|
|
{
|
2022-05-01 11:57:11 +03:00
|
|
|
UINT32 new_size = old * 2;
|
2018-08-22 14:40:41 +03:00
|
|
|
RDPDR_DEVICE** new_array;
|
2022-05-01 11:57:11 +03:00
|
|
|
|
2021-10-07 11:43:16 +03:00
|
|
|
if (new_size == 0)
|
|
|
|
new_size = count * 2;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
new_array =
|
|
|
|
(RDPDR_DEVICE**)realloc(settings->DeviceArray, new_size * sizeof(RDPDR_DEVICE*));
|
2018-08-22 14:40:41 +03:00
|
|
|
|
2015-03-11 08:52:24 +03:00
|
|
|
if (!new_array)
|
2015-06-18 14:00:10 +03:00
|
|
|
return FALSE;
|
2018-08-22 14:40:41 +03:00
|
|
|
|
2015-03-11 08:52:24 +03:00
|
|
|
settings->DeviceArray = new_array;
|
2022-05-01 11:57:11 +03:00
|
|
|
memset(&settings->DeviceArray[old], 0, (new_size - old) * sizeof(RDPDR_DEVICE*));
|
|
|
|
|
2020-11-19 12:09:34 +03:00
|
|
|
if (!freerdp_settings_set_uint32(settings, FreeRDP_DeviceArraySize, new_size))
|
|
|
|
return FALSE;
|
2012-11-18 09:08:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
settings->DeviceArray[settings->DeviceCount++] = device;
|
2015-06-18 14:00:10 +03:00
|
|
|
return TRUE;
|
2012-11-18 09:08:03 +04:00
|
|
|
}
|
|
|
|
|
2013-02-15 04:38:45 +04:00
|
|
|
RDPDR_DEVICE* freerdp_device_collection_find(rdpSettings* settings, const char* name)
|
|
|
|
{
|
2014-02-11 07:12:13 +04:00
|
|
|
UINT32 index;
|
2013-02-15 04:38:45 +04:00
|
|
|
RDPDR_DEVICE* device;
|
|
|
|
|
2022-04-28 09:00:39 +03:00
|
|
|
WINPR_ASSERT(settings);
|
|
|
|
WINPR_ASSERT(name);
|
2013-02-15 04:38:45 +04:00
|
|
|
for (index = 0; index < settings->DeviceCount; index++)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
device = (RDPDR_DEVICE*)settings->DeviceArray[index];
|
2013-02-15 04:38:45 +04:00
|
|
|
|
2014-03-26 19:05:12 +04:00
|
|
|
if (!device->Name)
|
2013-09-06 14:35:33 +04:00
|
|
|
continue;
|
|
|
|
|
2013-02-15 04:38:45 +04:00
|
|
|
if (strcmp(device->Name, name) == 0)
|
|
|
|
return device;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-02-26 16:50:27 +03:00
|
|
|
RDPDR_DEVICE* freerdp_device_collection_find_type(rdpSettings* settings, UINT32 type)
|
|
|
|
{
|
|
|
|
UINT32 index;
|
|
|
|
RDPDR_DEVICE* device;
|
2022-04-28 09:00:39 +03:00
|
|
|
WINPR_ASSERT(settings);
|
2016-02-26 16:50:27 +03:00
|
|
|
|
|
|
|
for (index = 0; index < settings->DeviceCount; index++)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
device = (RDPDR_DEVICE*)settings->DeviceArray[index];
|
2016-02-26 16:50:27 +03:00
|
|
|
|
|
|
|
if (device->Type == type)
|
|
|
|
return device;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2021-10-07 11:43:16 +03:00
|
|
|
RDPDR_DEVICE* freerdp_device_new(UINT32 Type, size_t count, const char* args[])
|
2013-10-19 06:42:50 +04:00
|
|
|
{
|
2021-10-07 11:43:16 +03:00
|
|
|
size_t size;
|
|
|
|
union
|
2013-10-19 06:42:50 +04:00
|
|
|
{
|
2021-10-07 11:43:16 +03:00
|
|
|
RDPDR_DEVICE* base;
|
|
|
|
RDPDR_DRIVE* drive;
|
|
|
|
RDPDR_SERIAL* serial;
|
|
|
|
RDPDR_PRINTER* printer;
|
|
|
|
RDPDR_PARALLEL* parallel;
|
|
|
|
RDPDR_SMARTCARD* smartcard;
|
|
|
|
} device;
|
|
|
|
|
|
|
|
device.base = NULL;
|
|
|
|
WINPR_ASSERT(args || (count == 0));
|
|
|
|
|
|
|
|
switch (Type)
|
2013-10-19 06:42:50 +04:00
|
|
|
{
|
2021-10-07 11:43:16 +03:00
|
|
|
case RDPDR_DTYP_PRINT:
|
|
|
|
size = sizeof(RDPDR_PRINTER);
|
|
|
|
break;
|
|
|
|
case RDPDR_DTYP_SERIAL:
|
|
|
|
size = sizeof(RDPDR_SERIAL);
|
|
|
|
break;
|
|
|
|
case RDPDR_DTYP_PARALLEL:
|
|
|
|
size = sizeof(RDPDR_PARALLEL);
|
|
|
|
break;
|
|
|
|
case RDPDR_DTYP_SMARTCARD:
|
|
|
|
size = sizeof(RDPDR_SMARTCARD);
|
|
|
|
break;
|
|
|
|
case RDPDR_DTYP_FILESYSTEM:
|
|
|
|
size = sizeof(RDPDR_DRIVE);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto fail;
|
|
|
|
}
|
2014-03-26 19:05:12 +04:00
|
|
|
|
2021-10-07 11:43:16 +03:00
|
|
|
device.base = calloc(1, size);
|
|
|
|
if (!device.base)
|
|
|
|
goto fail;
|
|
|
|
device.base->Id = 0;
|
|
|
|
device.base->Type = Type;
|
2013-10-19 06:42:50 +04:00
|
|
|
|
2021-10-07 11:43:16 +03:00
|
|
|
if (count > 0)
|
|
|
|
{
|
2021-10-18 13:39:52 +03:00
|
|
|
device.base->Name = _strdup(args[0]);
|
2021-10-07 11:43:16 +03:00
|
|
|
if (!device.base->Name)
|
|
|
|
goto fail;
|
2014-03-26 19:05:12 +04:00
|
|
|
|
2021-10-07 11:43:16 +03:00
|
|
|
switch (Type)
|
2014-03-26 19:05:12 +04:00
|
|
|
{
|
2021-10-07 11:43:16 +03:00
|
|
|
case RDPDR_DTYP_PRINT:
|
|
|
|
if (count > 1)
|
|
|
|
{
|
|
|
|
device.printer->DriverName = _strdup(args[1]);
|
|
|
|
if (!device.printer->DriverName)
|
|
|
|
goto fail;
|
|
|
|
}
|
2022-09-20 11:36:45 +03:00
|
|
|
|
|
|
|
if (count > 2)
|
|
|
|
{
|
|
|
|
device.printer->IsDefault = _stricmp(args[2], "default") == 0;
|
|
|
|
}
|
2021-10-07 11:43:16 +03:00
|
|
|
break;
|
|
|
|
case RDPDR_DTYP_SERIAL:
|
|
|
|
if (count > 1)
|
|
|
|
{
|
|
|
|
device.serial->Path = _strdup(args[1]);
|
|
|
|
if (!device.serial->Path)
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count > 2)
|
|
|
|
{
|
|
|
|
device.serial->Driver = _strdup(args[2]);
|
|
|
|
if (!device.serial->Driver)
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count > 3)
|
|
|
|
{
|
2022-05-02 15:20:12 +03:00
|
|
|
device.serial->Permissive = _strdup(args[3]);
|
2021-10-07 11:43:16 +03:00
|
|
|
if (!device.serial->Permissive)
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case RDPDR_DTYP_PARALLEL:
|
|
|
|
if (count > 1)
|
|
|
|
{
|
|
|
|
device.parallel->Path = _strdup(args[1]);
|
|
|
|
if (!device.serial->Path)
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case RDPDR_DTYP_SMARTCARD:
|
|
|
|
break;
|
|
|
|
case RDPDR_DTYP_FILESYSTEM:
|
|
|
|
if (count > 1)
|
|
|
|
{
|
|
|
|
device.drive->Path = _strdup(args[1]);
|
|
|
|
if (!device.drive->Path)
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
if (count > 2)
|
2022-03-07 17:05:04 +03:00
|
|
|
device.drive->automount = (args[2] == NULL) ? TRUE : FALSE;
|
2021-10-07 11:43:16 +03:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto fail;
|
2014-03-26 19:05:12 +04:00
|
|
|
}
|
2021-10-07 11:43:16 +03:00
|
|
|
}
|
|
|
|
return device.base;
|
2014-03-26 19:05:12 +04:00
|
|
|
|
2021-10-07 11:43:16 +03:00
|
|
|
fail:
|
|
|
|
freerdp_device_free(device.base);
|
|
|
|
return NULL;
|
|
|
|
}
|
2018-08-22 14:40:41 +03:00
|
|
|
|
2021-10-07 11:43:16 +03:00
|
|
|
void freerdp_device_free(RDPDR_DEVICE* device)
|
|
|
|
{
|
|
|
|
union
|
|
|
|
{
|
|
|
|
RDPDR_DEVICE* dev;
|
|
|
|
RDPDR_DRIVE* drive;
|
|
|
|
RDPDR_SERIAL* serial;
|
|
|
|
RDPDR_PRINTER* printer;
|
|
|
|
RDPDR_PARALLEL* parallel;
|
|
|
|
RDPDR_SMARTCARD* smartcard;
|
|
|
|
} cnv;
|
|
|
|
|
|
|
|
cnv.dev = device;
|
|
|
|
if (!cnv.dev)
|
|
|
|
return;
|
2014-03-26 02:13:08 +04:00
|
|
|
|
2021-10-07 11:43:16 +03:00
|
|
|
switch (device->Type)
|
|
|
|
{
|
|
|
|
case RDPDR_DTYP_PRINT:
|
|
|
|
free(cnv.printer->DriverName);
|
|
|
|
break;
|
|
|
|
case RDPDR_DTYP_SERIAL:
|
|
|
|
free(cnv.serial->Path);
|
|
|
|
free(cnv.serial->Driver);
|
|
|
|
free(cnv.serial->Permissive);
|
|
|
|
break;
|
|
|
|
case RDPDR_DTYP_PARALLEL:
|
|
|
|
free(cnv.parallel->Path);
|
|
|
|
break;
|
|
|
|
case RDPDR_DTYP_SMARTCARD:
|
|
|
|
break;
|
|
|
|
case RDPDR_DTYP_FILESYSTEM:
|
|
|
|
free(cnv.drive->Path);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2013-10-19 06:42:50 +04:00
|
|
|
}
|
2021-10-07 11:43:16 +03:00
|
|
|
free(cnv.dev->Name);
|
|
|
|
free(cnv.dev);
|
|
|
|
}
|
2014-03-26 02:13:08 +04:00
|
|
|
|
2021-10-07 11:43:16 +03:00
|
|
|
RDPDR_DEVICE* freerdp_device_clone(const RDPDR_DEVICE* device)
|
|
|
|
{
|
|
|
|
union
|
2013-10-19 06:42:50 +04:00
|
|
|
{
|
2021-10-07 11:43:16 +03:00
|
|
|
const RDPDR_DEVICE* dev;
|
|
|
|
const RDPDR_DRIVE* drive;
|
|
|
|
const RDPDR_SERIAL* serial;
|
|
|
|
const RDPDR_PRINTER* printer;
|
|
|
|
const RDPDR_PARALLEL* parallel;
|
|
|
|
const RDPDR_SMARTCARD* smartcard;
|
|
|
|
} src;
|
|
|
|
|
|
|
|
union
|
|
|
|
{
|
|
|
|
RDPDR_DEVICE* dev;
|
|
|
|
RDPDR_DRIVE* drive;
|
|
|
|
RDPDR_SERIAL* serial;
|
|
|
|
RDPDR_PRINTER* printer;
|
|
|
|
RDPDR_PARALLEL* parallel;
|
|
|
|
RDPDR_SMARTCARD* smartcard;
|
|
|
|
} copy;
|
2022-05-02 15:20:12 +03:00
|
|
|
size_t count = 0;
|
|
|
|
const char* args[4] = { 0 };
|
2022-05-01 11:57:11 +03:00
|
|
|
|
2022-05-02 15:20:12 +03:00
|
|
|
copy.dev = NULL;
|
2021-10-07 11:43:16 +03:00
|
|
|
src.dev = device;
|
2021-10-18 16:22:08 +03:00
|
|
|
|
2022-05-02 15:20:12 +03:00
|
|
|
if (!device)
|
2014-03-26 02:13:08 +04:00
|
|
|
return NULL;
|
|
|
|
|
2022-05-02 15:20:12 +03:00
|
|
|
if (device->Name)
|
|
|
|
{
|
|
|
|
count = 1;
|
|
|
|
args[0] = device->Name;
|
|
|
|
}
|
|
|
|
|
2021-10-07 11:43:16 +03:00
|
|
|
switch (device->Type)
|
2013-10-19 06:42:50 +04:00
|
|
|
{
|
2021-10-07 11:43:16 +03:00
|
|
|
case RDPDR_DTYP_FILESYSTEM:
|
|
|
|
if (src.drive->Path)
|
2022-05-02 15:20:12 +03:00
|
|
|
{
|
|
|
|
args[1] = src.drive->Path;
|
|
|
|
count = 2;
|
|
|
|
}
|
2022-06-23 08:57:38 +03:00
|
|
|
break;
|
2014-03-26 02:13:08 +04:00
|
|
|
|
2021-10-07 11:43:16 +03:00
|
|
|
case RDPDR_DTYP_PRINT:
|
2022-05-02 15:20:12 +03:00
|
|
|
if (src.printer->DriverName)
|
2021-10-07 11:43:16 +03:00
|
|
|
{
|
2022-05-02 15:20:12 +03:00
|
|
|
args[1] = src.printer->DriverName;
|
|
|
|
count = 2;
|
2021-10-07 11:43:16 +03:00
|
|
|
}
|
2022-06-23 08:57:38 +03:00
|
|
|
break;
|
2014-06-18 20:20:21 +04:00
|
|
|
|
2021-10-07 11:43:16 +03:00
|
|
|
case RDPDR_DTYP_SMARTCARD:
|
|
|
|
break;
|
2014-03-26 19:05:12 +04:00
|
|
|
|
2021-10-07 11:43:16 +03:00
|
|
|
case RDPDR_DTYP_SERIAL:
|
2022-05-02 15:20:12 +03:00
|
|
|
if (src.serial->Path)
|
2021-10-07 11:43:16 +03:00
|
|
|
{
|
2022-05-02 15:20:12 +03:00
|
|
|
args[1] = src.serial->Path;
|
|
|
|
count = 2;
|
2021-10-07 11:43:16 +03:00
|
|
|
}
|
2014-03-26 19:05:12 +04:00
|
|
|
|
2022-05-02 15:20:12 +03:00
|
|
|
if (src.serial->Driver)
|
2021-10-07 11:43:16 +03:00
|
|
|
{
|
2022-05-02 15:20:12 +03:00
|
|
|
args[2] = src.serial->Driver;
|
|
|
|
count = 3;
|
2021-10-07 11:43:16 +03:00
|
|
|
}
|
2021-10-18 16:30:41 +03:00
|
|
|
|
2022-05-02 15:20:12 +03:00
|
|
|
if (src.serial->Permissive)
|
2021-10-18 16:30:41 +03:00
|
|
|
{
|
2022-05-02 15:20:12 +03:00
|
|
|
args[3] = src.serial->Permissive;
|
|
|
|
count = 4;
|
2021-10-18 16:30:41 +03:00
|
|
|
}
|
2022-06-23 08:57:38 +03:00
|
|
|
break;
|
2014-03-26 19:05:12 +04:00
|
|
|
|
2021-10-07 11:43:16 +03:00
|
|
|
case RDPDR_DTYP_PARALLEL:
|
|
|
|
if (src.parallel->Path)
|
2022-05-02 15:20:12 +03:00
|
|
|
{
|
|
|
|
args[1] = src.parallel->Path;
|
|
|
|
count = 2;
|
|
|
|
}
|
2022-06-23 08:57:38 +03:00
|
|
|
break;
|
2021-10-07 11:43:16 +03:00
|
|
|
default:
|
|
|
|
WLog_ERR(TAG, "unknown device type %" PRIu32 "", device->Type);
|
|
|
|
break;
|
2013-10-19 06:42:50 +04:00
|
|
|
}
|
|
|
|
|
2022-05-02 15:20:12 +03:00
|
|
|
copy.dev = freerdp_device_new(device->Type, count, args);
|
|
|
|
if (!copy.dev)
|
|
|
|
return NULL;
|
2021-10-07 11:43:16 +03:00
|
|
|
|
2022-05-02 15:20:12 +03:00
|
|
|
copy.dev->Id = device->Id;
|
|
|
|
|
|
|
|
return copy.dev;
|
2013-10-19 06:42:50 +04:00
|
|
|
}
|
|
|
|
|
2012-11-19 22:26:56 +04:00
|
|
|
void freerdp_device_collection_free(rdpSettings* settings)
|
|
|
|
{
|
2014-02-11 07:12:13 +04:00
|
|
|
UINT32 index;
|
2021-10-07 11:43:16 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(settings);
|
2012-11-19 22:26:56 +04:00
|
|
|
|
2022-05-01 11:57:11 +03:00
|
|
|
if (settings->DeviceArray)
|
2012-11-19 22:26:56 +04:00
|
|
|
{
|
2022-05-01 11:57:11 +03:00
|
|
|
for (index = 0; index < settings->DeviceArraySize; index++)
|
|
|
|
freerdp_settings_set_pointer_array(settings, FreeRDP_DeviceArray, index, NULL);
|
2012-11-19 22:26:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
free(settings->DeviceArray);
|
2022-05-01 11:57:11 +03:00
|
|
|
|
|
|
|
freerdp_settings_set_pointer(settings, FreeRDP_DeviceArray, NULL);
|
2020-11-19 12:09:34 +03:00
|
|
|
freerdp_settings_set_uint32(settings, FreeRDP_DeviceArraySize, 0);
|
2022-05-01 11:57:11 +03:00
|
|
|
freerdp_settings_set_uint32(settings, FreeRDP_DeviceCount, 0);
|
2012-11-19 22:26:56 +04:00
|
|
|
}
|
|
|
|
|
2021-04-12 11:38:40 +03:00
|
|
|
BOOL freerdp_static_channel_collection_del(rdpSettings* settings, const char* name)
|
|
|
|
{
|
|
|
|
UINT32 x;
|
|
|
|
const UINT32 count = freerdp_settings_get_uint32(settings, FreeRDP_StaticChannelCount);
|
|
|
|
if (!settings || !settings->StaticChannelArray)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
for (x = 0; x < count; x++)
|
|
|
|
{
|
|
|
|
ADDIN_ARGV* cur = settings->StaticChannelArray[x];
|
|
|
|
if (cur && (cur->argc > 0))
|
|
|
|
{
|
|
|
|
if (strcmp(name, cur->argv[0]) == 0)
|
|
|
|
{
|
2022-05-02 12:39:38 +03:00
|
|
|
const size_t rem = settings->StaticChannelArraySize - count + 1;
|
2021-04-12 11:38:40 +03:00
|
|
|
memmove_s(&settings->StaticChannelArray[x], (count - x) * sizeof(ADDIN_ARGV*),
|
|
|
|
&settings->StaticChannelArray[x + 1],
|
|
|
|
(count - x - 1) * sizeof(ADDIN_ARGV*));
|
2022-05-02 12:39:38 +03:00
|
|
|
memset(&settings->StaticChannelArray[count - 1], 0, sizeof(ADDIN_ARGV*) * rem);
|
|
|
|
|
|
|
|
freerdp_addin_argv_free(cur);
|
2021-04-12 11:38:40 +03:00
|
|
|
return freerdp_settings_set_uint32(settings, FreeRDP_StaticChannelCount, count - 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-04-30 10:10:09 +03:00
|
|
|
{
|
|
|
|
const size_t rem = settings->StaticChannelArraySize - count;
|
|
|
|
memset(&settings->StaticChannelArray[count], 0, sizeof(ADDIN_ARGV*) * rem);
|
|
|
|
}
|
2021-04-12 11:38:40 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2015-06-16 16:42:07 +03:00
|
|
|
BOOL freerdp_static_channel_collection_add(rdpSettings* settings, ADDIN_ARGV* channel)
|
2012-11-18 09:08:03 +04:00
|
|
|
{
|
2020-11-19 12:09:34 +03:00
|
|
|
UINT32 count;
|
2015-03-10 15:10:39 +03:00
|
|
|
|
2021-10-07 11:43:16 +03:00
|
|
|
WINPR_ASSERT(settings);
|
|
|
|
WINPR_ASSERT(channel);
|
|
|
|
|
|
|
|
count = freerdp_settings_get_uint32(settings, FreeRDP_StaticChannelCount) + 1;
|
|
|
|
if (freerdp_settings_get_uint32(settings, FreeRDP_StaticChannelArraySize) < count)
|
2012-11-18 09:08:03 +04:00
|
|
|
{
|
2022-04-30 10:10:09 +03:00
|
|
|
const UINT32 oldSize =
|
|
|
|
freerdp_settings_get_uint32(settings, FreeRDP_StaticChannelArraySize);
|
|
|
|
UINT32 new_size = oldSize * 2ul;
|
2022-04-28 09:00:39 +03:00
|
|
|
ADDIN_ARGV** new_array = NULL;
|
2021-10-07 11:43:16 +03:00
|
|
|
if (new_size == 0)
|
2022-04-28 09:00:39 +03:00
|
|
|
new_size = count * 2ul;
|
2021-10-07 11:43:16 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
new_array =
|
|
|
|
(ADDIN_ARGV**)realloc(settings->StaticChannelArray, new_size * sizeof(ADDIN_ARGV*));
|
2018-08-22 14:40:41 +03:00
|
|
|
|
2015-03-11 08:52:24 +03:00
|
|
|
if (!new_array)
|
2015-06-16 16:42:07 +03:00
|
|
|
return FALSE;
|
2018-08-22 14:40:41 +03:00
|
|
|
|
2015-03-11 08:52:24 +03:00
|
|
|
settings->StaticChannelArray = new_array;
|
2022-04-30 10:10:09 +03:00
|
|
|
{
|
|
|
|
const size_t rem = new_size - oldSize;
|
|
|
|
memset(&settings->StaticChannelArray[oldSize], 0, sizeof(ADDIN_ARGV*) * rem);
|
|
|
|
}
|
2020-11-19 12:09:34 +03:00
|
|
|
if (!freerdp_settings_set_uint32(settings, FreeRDP_StaticChannelArraySize, new_size))
|
|
|
|
return FALSE;
|
2012-11-18 09:08:03 +04:00
|
|
|
}
|
|
|
|
|
2020-11-19 12:09:34 +03:00
|
|
|
count = freerdp_settings_get_uint32(settings, FreeRDP_StaticChannelCount);
|
2022-11-22 14:30:03 +03:00
|
|
|
|
|
|
|
ADDIN_ARGV** cur = &settings->StaticChannelArray[count++];
|
|
|
|
freerdp_addin_argv_free(*cur);
|
|
|
|
*cur = channel;
|
2020-11-19 12:09:34 +03:00
|
|
|
return freerdp_settings_set_uint32(settings, FreeRDP_StaticChannelCount, count);
|
2012-11-18 09:08:03 +04:00
|
|
|
}
|
|
|
|
|
2012-11-21 18:30:06 +04:00
|
|
|
ADDIN_ARGV* freerdp_static_channel_collection_find(rdpSettings* settings, const char* name)
|
|
|
|
{
|
2014-02-11 07:12:13 +04:00
|
|
|
UINT32 index;
|
2012-11-21 18:30:06 +04:00
|
|
|
ADDIN_ARGV* channel;
|
|
|
|
|
2021-10-07 11:43:16 +03:00
|
|
|
WINPR_ASSERT(settings);
|
|
|
|
WINPR_ASSERT(name);
|
|
|
|
|
2020-11-19 12:09:34 +03:00
|
|
|
for (index = 0; index < freerdp_settings_get_uint32(settings, FreeRDP_StaticChannelCount);
|
|
|
|
index++)
|
2012-11-21 18:30:06 +04:00
|
|
|
{
|
|
|
|
channel = settings->StaticChannelArray[index];
|
|
|
|
|
|
|
|
if (strcmp(channel->argv[0], name) == 0)
|
|
|
|
return channel;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-11-19 22:26:56 +04:00
|
|
|
void freerdp_static_channel_collection_free(rdpSettings* settings)
|
|
|
|
{
|
2014-02-11 07:12:13 +04:00
|
|
|
UINT32 i;
|
2012-11-19 22:26:56 +04:00
|
|
|
|
2021-10-07 11:43:16 +03:00
|
|
|
if (!settings)
|
|
|
|
return;
|
|
|
|
|
2022-04-30 10:10:09 +03:00
|
|
|
if (settings->StaticChannelArray)
|
2012-11-19 22:26:56 +04:00
|
|
|
{
|
2022-04-30 10:10:09 +03:00
|
|
|
for (i = 0; i < freerdp_settings_get_uint32(settings, FreeRDP_StaticChannelArraySize); i++)
|
|
|
|
freerdp_addin_argv_free(settings->StaticChannelArray[i]);
|
2012-11-19 22:26:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
free(settings->StaticChannelArray);
|
2020-11-19 12:09:34 +03:00
|
|
|
freerdp_settings_set_uint32(settings, FreeRDP_StaticChannelArraySize, 0);
|
2012-11-19 22:26:56 +04:00
|
|
|
settings->StaticChannelArray = NULL;
|
2020-11-19 12:09:34 +03:00
|
|
|
freerdp_settings_set_uint32(settings, FreeRDP_StaticChannelCount, 0);
|
2012-11-19 22:26:56 +04:00
|
|
|
}
|
|
|
|
|
2021-04-12 11:38:40 +03:00
|
|
|
BOOL freerdp_dynamic_channel_collection_del(rdpSettings* settings, const char* name)
|
|
|
|
{
|
|
|
|
UINT32 x;
|
|
|
|
const UINT32 count = freerdp_settings_get_uint32(settings, FreeRDP_DynamicChannelCount);
|
|
|
|
if (!settings || !settings->DynamicChannelArray)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
for (x = 0; x < count; x++)
|
|
|
|
{
|
|
|
|
ADDIN_ARGV* cur = settings->DynamicChannelArray[x];
|
|
|
|
if (cur && (cur->argc > 0))
|
|
|
|
{
|
2022-05-02 12:39:38 +03:00
|
|
|
if (strcmp(name, cur->argv[0]) == 0)
|
2021-04-12 11:38:40 +03:00
|
|
|
{
|
2022-05-02 12:39:38 +03:00
|
|
|
const size_t rem = settings->DynamicChannelArraySize - count + 1;
|
2021-04-12 11:38:40 +03:00
|
|
|
memmove_s(&settings->DynamicChannelArray[x], (count - x) * sizeof(ADDIN_ARGV*),
|
|
|
|
&settings->DynamicChannelArray[x + 1],
|
|
|
|
(count - x - 1) * sizeof(ADDIN_ARGV*));
|
2022-05-02 12:39:38 +03:00
|
|
|
memset(&settings->DynamicChannelArray[count - 1], 0, sizeof(ADDIN_ARGV*) * rem);
|
2022-04-30 10:10:09 +03:00
|
|
|
|
2022-05-02 12:39:38 +03:00
|
|
|
freerdp_addin_argv_free(cur);
|
2021-04-12 11:38:40 +03:00
|
|
|
return freerdp_settings_set_uint32(settings, FreeRDP_DynamicChannelCount,
|
|
|
|
count - 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2015-06-16 16:42:07 +03:00
|
|
|
BOOL freerdp_dynamic_channel_collection_add(rdpSettings* settings, ADDIN_ARGV* channel)
|
2012-11-18 09:08:03 +04:00
|
|
|
{
|
2022-04-30 10:10:09 +03:00
|
|
|
UINT32 count, oldSize;
|
2015-03-10 15:10:39 +03:00
|
|
|
|
2021-10-07 11:43:16 +03:00
|
|
|
WINPR_ASSERT(settings);
|
|
|
|
WINPR_ASSERT(channel);
|
|
|
|
|
|
|
|
count = freerdp_settings_get_uint32(settings, FreeRDP_DynamicChannelCount) + 1;
|
2022-04-30 10:10:09 +03:00
|
|
|
oldSize = freerdp_settings_get_uint32(settings, FreeRDP_DynamicChannelArraySize);
|
|
|
|
if (oldSize < count)
|
2012-11-18 09:08:03 +04:00
|
|
|
{
|
2018-08-22 14:40:41 +03:00
|
|
|
ADDIN_ARGV** new_array;
|
2022-04-30 10:10:09 +03:00
|
|
|
UINT32 size = oldSize * 2;
|
2021-10-07 11:43:16 +03:00
|
|
|
if (size == 0)
|
|
|
|
size = count * 2;
|
|
|
|
|
2020-11-19 12:09:34 +03:00
|
|
|
new_array = realloc(settings->DynamicChannelArray, sizeof(ADDIN_ARGV*) * size);
|
2015-03-13 14:17:22 +03:00
|
|
|
|
2015-03-11 08:52:24 +03:00
|
|
|
if (!new_array)
|
2015-06-16 16:42:07 +03:00
|
|
|
return FALSE;
|
|
|
|
|
2015-03-11 08:52:24 +03:00
|
|
|
settings->DynamicChannelArray = new_array;
|
2022-04-30 10:10:09 +03:00
|
|
|
{
|
|
|
|
const size_t rem = size - oldSize;
|
|
|
|
memset(&settings->DynamicChannelArray[oldSize], 0, sizeof(ADDIN_ARGV*) * rem);
|
|
|
|
}
|
2020-11-19 12:09:34 +03:00
|
|
|
if (!freerdp_settings_set_uint32(settings, FreeRDP_DynamicChannelArraySize, size))
|
|
|
|
return FALSE;
|
2012-11-18 09:08:03 +04:00
|
|
|
}
|
|
|
|
|
2020-11-19 12:09:34 +03:00
|
|
|
count = freerdp_settings_get_uint32(settings, FreeRDP_DynamicChannelCount);
|
|
|
|
settings->DynamicChannelArray[count++] = channel;
|
|
|
|
return freerdp_settings_set_uint32(settings, FreeRDP_DynamicChannelCount, count);
|
2012-11-18 09:08:03 +04:00
|
|
|
}
|
2012-11-19 22:26:56 +04:00
|
|
|
|
2021-05-18 13:16:21 +03:00
|
|
|
ADDIN_ARGV* freerdp_dynamic_channel_collection_find(const rdpSettings* settings, const char* name)
|
2012-11-21 18:30:06 +04:00
|
|
|
{
|
2014-02-11 07:12:13 +04:00
|
|
|
UINT32 index;
|
2012-11-21 18:30:06 +04:00
|
|
|
ADDIN_ARGV* channel;
|
|
|
|
|
2021-10-07 11:43:16 +03:00
|
|
|
WINPR_ASSERT(settings);
|
|
|
|
WINPR_ASSERT(name);
|
|
|
|
|
2020-11-19 12:09:34 +03:00
|
|
|
for (index = 0; index < freerdp_settings_get_uint32(settings, FreeRDP_DynamicChannelCount);
|
|
|
|
index++)
|
2012-11-21 18:30:06 +04:00
|
|
|
{
|
|
|
|
channel = settings->DynamicChannelArray[index];
|
|
|
|
|
|
|
|
if (strcmp(channel->argv[0], name) == 0)
|
|
|
|
return channel;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2021-04-12 11:38:40 +03:00
|
|
|
void freerdp_addin_argv_free(ADDIN_ARGV* args)
|
2013-10-19 06:42:50 +04:00
|
|
|
{
|
|
|
|
int index;
|
2021-04-12 11:38:40 +03:00
|
|
|
if (!args)
|
|
|
|
return;
|
2015-02-07 01:35:14 +03:00
|
|
|
|
2021-04-12 11:38:40 +03:00
|
|
|
if (args->argv)
|
|
|
|
{
|
|
|
|
for (index = 0; index < args->argc; index++)
|
|
|
|
free(args->argv[index]);
|
|
|
|
free(args->argv);
|
|
|
|
}
|
2013-10-19 06:42:50 +04:00
|
|
|
|
2021-04-12 11:38:40 +03:00
|
|
|
free(args);
|
|
|
|
}
|
2015-02-07 01:35:14 +03:00
|
|
|
|
2021-04-12 11:38:40 +03:00
|
|
|
ADDIN_ARGV* freerdp_addin_argv_new(size_t argc, const char* argv[])
|
|
|
|
{
|
|
|
|
ADDIN_ARGV* args = calloc(1, sizeof(ADDIN_ARGV));
|
|
|
|
if (!args)
|
|
|
|
return NULL;
|
|
|
|
if (argc == 0)
|
|
|
|
return args;
|
2013-10-19 06:42:50 +04:00
|
|
|
|
2021-04-12 11:38:40 +03:00
|
|
|
args->argc = argc;
|
|
|
|
args->argv = calloc(argc, sizeof(char*));
|
|
|
|
if (!args->argv)
|
|
|
|
goto fail;
|
2015-02-07 01:35:14 +03:00
|
|
|
|
2021-04-12 11:38:40 +03:00
|
|
|
if (argv)
|
|
|
|
{
|
|
|
|
size_t x;
|
|
|
|
for (x = 0; x < argc; x++)
|
|
|
|
{
|
|
|
|
args->argv[x] = _strdup(argv[x]);
|
|
|
|
if (!args->argv[x])
|
|
|
|
goto fail;
|
|
|
|
}
|
2013-10-19 06:42:50 +04:00
|
|
|
}
|
2021-04-12 11:38:40 +03:00
|
|
|
return args;
|
2013-10-19 06:42:50 +04:00
|
|
|
|
2021-04-12 11:38:40 +03:00
|
|
|
fail:
|
|
|
|
freerdp_addin_argv_free(args);
|
2014-03-26 02:13:08 +04:00
|
|
|
return NULL;
|
2013-10-19 06:42:50 +04:00
|
|
|
}
|
|
|
|
|
2021-04-12 11:38:40 +03:00
|
|
|
ADDIN_ARGV* freerdp_addin_argv_clone(const ADDIN_ARGV* args)
|
|
|
|
{
|
2021-10-07 10:22:27 +03:00
|
|
|
union
|
|
|
|
{
|
|
|
|
char** c;
|
|
|
|
const char** cc;
|
|
|
|
} cnv;
|
2021-04-12 11:38:40 +03:00
|
|
|
if (!args)
|
|
|
|
return NULL;
|
2021-10-07 10:22:27 +03:00
|
|
|
cnv.c = args->argv;
|
|
|
|
return freerdp_addin_argv_new(args->argc, cnv.cc);
|
2021-04-12 11:38:40 +03:00
|
|
|
}
|
|
|
|
|
2012-11-19 22:26:56 +04:00
|
|
|
void freerdp_dynamic_channel_collection_free(rdpSettings* settings)
|
|
|
|
{
|
2014-06-20 21:52:13 +04:00
|
|
|
UINT32 i;
|
2012-11-19 22:26:56 +04:00
|
|
|
|
2022-04-19 15:29:17 +03:00
|
|
|
WINPR_ASSERT(settings);
|
2022-04-30 10:10:09 +03:00
|
|
|
|
|
|
|
if (settings->DynamicChannelArray)
|
2012-11-19 22:26:56 +04:00
|
|
|
{
|
2022-04-30 10:10:09 +03:00
|
|
|
for (i = 0; i < freerdp_settings_get_uint32(settings, FreeRDP_DynamicChannelArraySize); i++)
|
|
|
|
freerdp_addin_argv_free(settings->DynamicChannelArray[i]);
|
2012-11-19 22:26:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
free(settings->DynamicChannelArray);
|
2020-11-19 12:09:34 +03:00
|
|
|
freerdp_settings_set_uint32(settings, FreeRDP_DynamicChannelArraySize, 0);
|
2012-11-19 22:26:56 +04:00
|
|
|
settings->DynamicChannelArray = NULL;
|
2020-11-19 12:09:34 +03:00
|
|
|
freerdp_settings_set_uint32(settings, FreeRDP_DynamicChannelCount, 0);
|
2012-11-19 22:26:56 +04:00
|
|
|
}
|
2013-03-20 23:33:33 +04:00
|
|
|
|
2022-06-27 13:05:24 +03:00
|
|
|
void freerdp_capability_buffer_free(rdpSettings* settings)
|
2013-11-04 01:25:56 +04:00
|
|
|
{
|
2022-10-05 10:30:37 +03:00
|
|
|
UINT32 x;
|
|
|
|
|
2022-06-27 13:05:24 +03:00
|
|
|
WINPR_ASSERT(settings);
|
|
|
|
|
2022-10-05 10:30:37 +03:00
|
|
|
if (settings->ReceivedCapabilityData)
|
|
|
|
{
|
|
|
|
for (x = 0; x < settings->ReceivedCapabilitiesSize; x++)
|
|
|
|
{
|
|
|
|
free(settings->ReceivedCapabilityData[x]);
|
|
|
|
settings->ReceivedCapabilityData[x] = NULL;
|
|
|
|
}
|
|
|
|
}
|
2022-06-27 13:05:24 +03:00
|
|
|
settings->ReceivedCapabilitiesSize = 0;
|
|
|
|
|
2022-10-05 10:30:37 +03:00
|
|
|
free(settings->ReceivedCapabilityDataSizes);
|
|
|
|
settings->ReceivedCapabilityDataSizes = NULL;
|
|
|
|
|
|
|
|
free(settings->ReceivedCapabilityData);
|
|
|
|
settings->ReceivedCapabilityData = NULL;
|
2022-06-27 13:05:24 +03:00
|
|
|
free(settings->ReceivedCapabilities);
|
|
|
|
settings->ReceivedCapabilities = NULL;
|
|
|
|
}
|
2013-11-04 01:25:56 +04:00
|
|
|
|
2022-06-27 13:05:24 +03:00
|
|
|
BOOL freerdp_capability_buffer_copy(rdpSettings* settings, const rdpSettings* src)
|
|
|
|
{
|
|
|
|
WINPR_ASSERT(settings);
|
|
|
|
WINPR_ASSERT(src);
|
|
|
|
|
|
|
|
if (!freerdp_capability_buffer_allocate(settings, src->ReceivedCapabilitiesSize))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
for (UINT32 x = 0; x < src->ReceivedCapabilitiesSize; x++)
|
|
|
|
{
|
|
|
|
WINPR_ASSERT(settings->ReceivedCapabilities);
|
|
|
|
settings->ReceivedCapabilities[x] = src->ReceivedCapabilities[x];
|
2022-10-05 10:30:37 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(settings->ReceivedCapabilityDataSizes);
|
|
|
|
settings->ReceivedCapabilityDataSizes[x] = src->ReceivedCapabilityDataSizes[x];
|
|
|
|
|
|
|
|
WINPR_ASSERT(settings->ReceivedCapabilityData);
|
|
|
|
if (src->ReceivedCapabilityDataSizes[x] > 0)
|
|
|
|
{
|
2023-06-05 13:16:57 +03:00
|
|
|
void* tmp = realloc(settings->ReceivedCapabilityData[x],
|
|
|
|
settings->ReceivedCapabilityDataSizes[x]);
|
2022-10-05 10:30:37 +03:00
|
|
|
if (!tmp)
|
|
|
|
return FALSE;
|
|
|
|
memcpy(tmp, src->ReceivedCapabilityData[x], src->ReceivedCapabilityDataSizes[x]);
|
|
|
|
settings->ReceivedCapabilityData[x] = tmp;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
free(settings->ReceivedCapabilityData[x]);
|
|
|
|
settings->ReceivedCapabilityData[x] = NULL;
|
|
|
|
}
|
2022-06-27 13:05:24 +03:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void freerdp_target_net_addresses_free(rdpSettings* settings)
|
|
|
|
{
|
2022-04-19 15:29:17 +03:00
|
|
|
WINPR_ASSERT(settings);
|
|
|
|
|
2022-04-28 09:00:39 +03:00
|
|
|
if (settings->TargetNetAddresses)
|
|
|
|
{
|
2022-06-27 13:05:24 +03:00
|
|
|
for (UINT32 index = 0; index < settings->TargetNetAddressCount; index++)
|
2022-04-28 09:00:39 +03:00
|
|
|
free(settings->TargetNetAddresses[index]);
|
|
|
|
}
|
2013-11-04 01:25:56 +04:00
|
|
|
|
|
|
|
free(settings->TargetNetAddresses);
|
2015-05-06 23:32:45 +03:00
|
|
|
free(settings->TargetNetPorts);
|
2013-11-04 01:25:56 +04:00
|
|
|
settings->TargetNetAddressCount = 0;
|
|
|
|
settings->TargetNetAddresses = NULL;
|
2015-05-06 23:32:45 +03:00
|
|
|
settings->TargetNetPorts = NULL;
|
2013-11-04 01:25:56 +04:00
|
|
|
}
|
|
|
|
|
2022-10-06 12:32:08 +03:00
|
|
|
void freerdp_server_license_issuers_free(rdpSettings* settings)
|
|
|
|
{
|
|
|
|
UINT32 x;
|
|
|
|
WINPR_ASSERT(settings);
|
|
|
|
|
|
|
|
if (settings->ServerLicenseProductIssuers)
|
|
|
|
{
|
|
|
|
for (x = 0; x < settings->ServerLicenseProductIssuersCount; x++)
|
|
|
|
free(settings->ServerLicenseProductIssuers[x]);
|
|
|
|
}
|
|
|
|
free(settings->ServerLicenseProductIssuers);
|
|
|
|
settings->ServerLicenseProductIssuers = NULL;
|
|
|
|
settings->ServerLicenseProductIssuersCount = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL freerdp_server_license_issuers_copy(rdpSettings* settings, char** issuers, UINT32 count)
|
|
|
|
{
|
|
|
|
UINT32 x;
|
|
|
|
|
|
|
|
WINPR_ASSERT(settings);
|
|
|
|
WINPR_ASSERT(issuers || (count == 0));
|
|
|
|
|
|
|
|
if (!freerdp_settings_set_pointer_len(settings, FreeRDP_ServerLicenseProductIssuers, NULL,
|
|
|
|
count))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
for (x = 0; x < count; x++)
|
|
|
|
{
|
|
|
|
char* issuer = _strdup(issuers[x]);
|
|
|
|
if (!issuer)
|
|
|
|
return FALSE;
|
|
|
|
settings->ServerLicenseProductIssuers[x] = issuer;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2013-09-17 22:56:23 +04:00
|
|
|
void freerdp_performance_flags_make(rdpSettings* settings)
|
|
|
|
{
|
2020-11-19 12:09:34 +03:00
|
|
|
UINT32 PerformanceFlags = PERF_FLAG_NONE;
|
2013-09-17 22:56:23 +04:00
|
|
|
|
2020-11-19 12:09:34 +03:00
|
|
|
if (freerdp_settings_get_bool(settings, FreeRDP_AllowFontSmoothing))
|
|
|
|
PerformanceFlags |= PERF_ENABLE_FONT_SMOOTHING;
|
2013-09-17 22:56:23 +04:00
|
|
|
|
2020-11-19 12:09:34 +03:00
|
|
|
if (freerdp_settings_get_bool(settings, FreeRDP_AllowDesktopComposition))
|
|
|
|
PerformanceFlags |= PERF_ENABLE_DESKTOP_COMPOSITION;
|
2013-09-17 22:56:23 +04:00
|
|
|
|
2020-11-19 12:09:34 +03:00
|
|
|
if (freerdp_settings_get_bool(settings, FreeRDP_DisableWallpaper))
|
|
|
|
PerformanceFlags |= PERF_DISABLE_WALLPAPER;
|
2013-09-17 22:56:23 +04:00
|
|
|
|
2020-11-19 12:09:34 +03:00
|
|
|
if (freerdp_settings_get_bool(settings, FreeRDP_DisableFullWindowDrag))
|
|
|
|
PerformanceFlags |= PERF_DISABLE_FULLWINDOWDRAG;
|
2013-09-17 22:56:23 +04:00
|
|
|
|
2020-11-19 12:09:34 +03:00
|
|
|
if (freerdp_settings_get_bool(settings, FreeRDP_DisableMenuAnims))
|
|
|
|
PerformanceFlags |= PERF_DISABLE_MENUANIMATIONS;
|
2013-09-17 22:56:23 +04:00
|
|
|
|
2020-11-19 12:09:34 +03:00
|
|
|
if (freerdp_settings_get_bool(settings, FreeRDP_DisableThemes))
|
|
|
|
PerformanceFlags |= PERF_DISABLE_THEMING;
|
|
|
|
freerdp_settings_set_uint32(settings, FreeRDP_PerformanceFlags, PerformanceFlags);
|
2013-09-17 22:56:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void freerdp_performance_flags_split(rdpSettings* settings)
|
|
|
|
{
|
2020-11-19 12:09:34 +03:00
|
|
|
freerdp_settings_set_bool(settings, FreeRDP_AllowFontSmoothing,
|
|
|
|
(freerdp_settings_get_uint32(settings, FreeRDP_PerformanceFlags) &
|
|
|
|
PERF_ENABLE_FONT_SMOOTHING)
|
|
|
|
? TRUE
|
|
|
|
: FALSE);
|
|
|
|
freerdp_settings_set_bool(settings, FreeRDP_AllowDesktopComposition,
|
|
|
|
(freerdp_settings_get_uint32(settings, FreeRDP_PerformanceFlags) &
|
|
|
|
PERF_ENABLE_DESKTOP_COMPOSITION)
|
|
|
|
? TRUE
|
|
|
|
: FALSE);
|
|
|
|
freerdp_settings_set_bool(
|
|
|
|
settings, FreeRDP_DisableWallpaper,
|
|
|
|
(freerdp_settings_get_uint32(settings, FreeRDP_PerformanceFlags) & PERF_DISABLE_WALLPAPER)
|
|
|
|
? TRUE
|
|
|
|
: FALSE);
|
|
|
|
freerdp_settings_set_bool(settings, FreeRDP_DisableFullWindowDrag,
|
|
|
|
(freerdp_settings_get_uint32(settings, FreeRDP_PerformanceFlags) &
|
|
|
|
PERF_DISABLE_FULLWINDOWDRAG)
|
|
|
|
? TRUE
|
|
|
|
: FALSE);
|
|
|
|
freerdp_settings_set_bool(settings, FreeRDP_DisableMenuAnims,
|
|
|
|
(freerdp_settings_get_uint32(settings, FreeRDP_PerformanceFlags) &
|
|
|
|
PERF_DISABLE_MENUANIMATIONS)
|
|
|
|
? TRUE
|
|
|
|
: FALSE);
|
|
|
|
freerdp_settings_set_bool(
|
|
|
|
settings, FreeRDP_DisableThemes,
|
|
|
|
(freerdp_settings_get_uint32(settings, FreeRDP_PerformanceFlags) & PERF_DISABLE_THEMING)
|
|
|
|
? TRUE
|
|
|
|
: FALSE);
|
2013-09-17 22:56:23 +04:00
|
|
|
}
|
|
|
|
|
2019-05-06 10:51:42 +03:00
|
|
|
BOOL freerdp_set_gateway_usage_method(rdpSettings* settings, UINT32 GatewayUsageMethod)
|
2014-04-25 01:05:10 +04:00
|
|
|
{
|
2019-05-08 15:35:25 +03:00
|
|
|
if (!freerdp_settings_set_uint32(settings, FreeRDP_GatewayUsageMethod, GatewayUsageMethod))
|
2019-05-06 10:51:42 +03:00
|
|
|
return FALSE;
|
2014-04-25 01:05:10 +04:00
|
|
|
|
|
|
|
if (GatewayUsageMethod == TSC_PROXY_MODE_NONE_DIRECT)
|
|
|
|
{
|
2019-05-08 15:35:25 +03:00
|
|
|
if (!freerdp_settings_set_bool(settings, FreeRDP_GatewayEnabled, FALSE) ||
|
|
|
|
!freerdp_settings_set_bool(settings, FreeRDP_GatewayBypassLocal, FALSE))
|
2019-05-06 10:51:42 +03:00
|
|
|
return FALSE;
|
2014-04-25 01:05:10 +04:00
|
|
|
}
|
|
|
|
else if (GatewayUsageMethod == TSC_PROXY_MODE_DIRECT)
|
|
|
|
{
|
2019-05-08 15:35:25 +03:00
|
|
|
if (!freerdp_settings_set_bool(settings, FreeRDP_GatewayEnabled, TRUE) ||
|
|
|
|
!freerdp_settings_set_bool(settings, FreeRDP_GatewayBypassLocal, FALSE))
|
2019-05-06 10:51:42 +03:00
|
|
|
return FALSE;
|
2014-04-25 01:05:10 +04:00
|
|
|
}
|
|
|
|
else if (GatewayUsageMethod == TSC_PROXY_MODE_DETECT)
|
|
|
|
{
|
2019-05-08 15:35:25 +03:00
|
|
|
if (!freerdp_settings_set_bool(settings, FreeRDP_GatewayEnabled, TRUE) ||
|
|
|
|
!freerdp_settings_set_bool(settings, FreeRDP_GatewayBypassLocal, TRUE))
|
2019-05-06 10:51:42 +03:00
|
|
|
return FALSE;
|
2014-04-25 01:05:10 +04:00
|
|
|
}
|
|
|
|
else if (GatewayUsageMethod == TSC_PROXY_MODE_DEFAULT)
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* This corresponds to "Automatically detect RD Gateway server settings",
|
|
|
|
* which means the client attempts to use gateway group policy settings
|
|
|
|
* http://technet.microsoft.com/en-us/library/cc770601.aspx
|
|
|
|
*/
|
2019-05-08 15:35:25 +03:00
|
|
|
if (!freerdp_settings_set_bool(settings, FreeRDP_GatewayEnabled, FALSE) ||
|
|
|
|
!freerdp_settings_set_bool(settings, FreeRDP_GatewayBypassLocal, FALSE))
|
2019-05-06 10:51:42 +03:00
|
|
|
return FALSE;
|
2014-04-25 01:05:10 +04:00
|
|
|
}
|
|
|
|
else if (GatewayUsageMethod == TSC_PROXY_MODE_NONE_DETECT)
|
|
|
|
{
|
2019-05-08 15:35:25 +03:00
|
|
|
if (!freerdp_settings_set_bool(settings, FreeRDP_GatewayEnabled, FALSE) ||
|
|
|
|
!freerdp_settings_set_bool(settings, FreeRDP_GatewayBypassLocal, FALSE))
|
2019-05-06 10:51:42 +03:00
|
|
|
return FALSE;
|
2014-04-25 01:05:10 +04:00
|
|
|
}
|
2019-05-06 10:51:42 +03:00
|
|
|
|
|
|
|
return TRUE;
|
2014-04-25 01:05:10 +04:00
|
|
|
}
|
|
|
|
|
2018-08-22 14:40:41 +03:00
|
|
|
void freerdp_update_gateway_usage_method(rdpSettings* settings, UINT32 GatewayEnabled,
|
2019-11-06 17:24:51 +03:00
|
|
|
UINT32 GatewayBypassLocal)
|
2014-05-30 20:55:17 +04:00
|
|
|
{
|
|
|
|
UINT32 GatewayUsageMethod = 0;
|
|
|
|
|
|
|
|
if (!GatewayEnabled && !GatewayBypassLocal)
|
|
|
|
GatewayUsageMethod = TSC_PROXY_MODE_NONE_DIRECT;
|
|
|
|
else if (GatewayEnabled && !GatewayBypassLocal)
|
|
|
|
GatewayUsageMethod = TSC_PROXY_MODE_DIRECT;
|
|
|
|
else if (GatewayEnabled && GatewayBypassLocal)
|
|
|
|
GatewayUsageMethod = TSC_PROXY_MODE_DETECT;
|
|
|
|
|
|
|
|
freerdp_set_gateway_usage_method(settings, GatewayUsageMethod);
|
|
|
|
}
|
2019-05-08 15:35:25 +03:00
|
|
|
|
2021-07-28 16:18:03 +03:00
|
|
|
#if defined(WITH_FREERDP_DEPRECATED)
|
2019-11-07 14:39:22 +03:00
|
|
|
BOOL freerdp_get_param_bool(const rdpSettings* settings, int id)
|
2019-05-08 15:35:25 +03:00
|
|
|
{
|
|
|
|
return freerdp_settings_get_bool(settings, (size_t)id);
|
|
|
|
}
|
|
|
|
|
|
|
|
int freerdp_set_param_bool(rdpSettings* settings, int id, BOOL param)
|
|
|
|
{
|
|
|
|
return freerdp_settings_set_bool(settings, (size_t)id, param) ? 0 : -1;
|
|
|
|
}
|
|
|
|
|
2019-11-07 14:39:22 +03:00
|
|
|
int freerdp_get_param_int(const rdpSettings* settings, int id)
|
2019-05-08 15:35:25 +03:00
|
|
|
{
|
|
|
|
return freerdp_settings_get_int32(settings, (size_t)id);
|
|
|
|
}
|
|
|
|
|
|
|
|
int freerdp_set_param_int(rdpSettings* settings, int id, int param)
|
|
|
|
{
|
|
|
|
return freerdp_settings_set_int32(settings, (size_t)id, param) ? 0 : -1;
|
|
|
|
}
|
|
|
|
|
2019-11-07 14:39:22 +03:00
|
|
|
UINT32 freerdp_get_param_uint32(const rdpSettings* settings, int id)
|
2019-05-08 15:35:25 +03:00
|
|
|
{
|
|
|
|
return freerdp_settings_get_uint32(settings, (size_t)id);
|
|
|
|
}
|
|
|
|
|
|
|
|
int freerdp_set_param_uint32(rdpSettings* settings, int id, UINT32 param)
|
|
|
|
{
|
|
|
|
return freerdp_settings_set_uint32(settings, (size_t)id, param) ? 0 : -1;
|
|
|
|
}
|
|
|
|
|
2019-11-07 14:39:22 +03:00
|
|
|
UINT64 freerdp_get_param_uint64(const rdpSettings* settings, int id)
|
2019-05-08 15:35:25 +03:00
|
|
|
{
|
|
|
|
return freerdp_settings_get_uint64(settings, (size_t)id);
|
|
|
|
}
|
|
|
|
|
|
|
|
int freerdp_set_param_uint64(rdpSettings* settings, int id, UINT64 param)
|
|
|
|
{
|
|
|
|
return freerdp_settings_set_uint64(settings, (size_t)id, param) ? 0 : -1;
|
|
|
|
}
|
|
|
|
|
2019-11-07 14:39:22 +03:00
|
|
|
char* freerdp_get_param_string(const rdpSettings* settings, int id)
|
2019-05-08 15:35:25 +03:00
|
|
|
{
|
|
|
|
return (char*)freerdp_settings_get_string(settings, (size_t)id);
|
|
|
|
}
|
|
|
|
|
|
|
|
int freerdp_set_param_string(rdpSettings* settings, int id, const char* param)
|
|
|
|
{
|
|
|
|
return freerdp_settings_set_string(settings, (size_t)id, param) ? 0 : -1;
|
|
|
|
}
|
2021-07-28 16:18:03 +03:00
|
|
|
#endif
|
2020-04-11 12:55:11 +03:00
|
|
|
|
|
|
|
static BOOL value_to_uint(const char* value, ULONGLONG* result, ULONGLONG min, ULONGLONG max)
|
|
|
|
{
|
2022-05-02 15:20:12 +03:00
|
|
|
char* endptr = NULL;
|
2020-04-11 12:55:11 +03:00
|
|
|
unsigned long long rc;
|
|
|
|
|
|
|
|
if (!value || !result)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
errno = 0;
|
2022-05-02 15:20:12 +03:00
|
|
|
rc = _strtoui64(value, &endptr, 0);
|
2020-04-11 12:55:11 +03:00
|
|
|
|
|
|
|
if (errno != 0)
|
|
|
|
return FALSE;
|
|
|
|
|
2022-05-02 15:20:12 +03:00
|
|
|
if (endptr == value)
|
|
|
|
return FALSE;
|
|
|
|
|
2020-04-11 12:55:11 +03:00
|
|
|
if ((rc < min) || (rc > max))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
*result = rc;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL value_to_int(const char* value, LONGLONG* result, LONGLONG min, LONGLONG max)
|
|
|
|
{
|
2022-05-02 15:20:12 +03:00
|
|
|
char* endptr = NULL;
|
2020-04-11 12:55:11 +03:00
|
|
|
long long rc;
|
|
|
|
|
|
|
|
if (!value || !result)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
errno = 0;
|
2022-05-02 15:20:12 +03:00
|
|
|
rc = _strtoi64(value, &endptr, 0);
|
2020-04-11 12:55:11 +03:00
|
|
|
|
|
|
|
if (errno != 0)
|
|
|
|
return FALSE;
|
|
|
|
|
2022-05-02 15:20:12 +03:00
|
|
|
if (endptr == value)
|
|
|
|
return FALSE;
|
|
|
|
|
2020-04-11 12:55:11 +03:00
|
|
|
if ((rc < min) || (rc > max))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
*result = rc;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL parsing_fail(const char* key, const char* type, const char* value)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Failed to parse key [%s] of type [%s]: value [%s]", key, type, value);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL freerdp_settings_set_value_for_name(rdpSettings* settings, const char* name, const char* value)
|
|
|
|
{
|
|
|
|
ULONGLONG uval;
|
|
|
|
LONGLONG ival;
|
2022-02-01 10:33:41 +03:00
|
|
|
SSIZE_T i, type;
|
|
|
|
size_t index;
|
2020-04-11 12:55:11 +03:00
|
|
|
if (!settings || !name)
|
|
|
|
return FALSE;
|
|
|
|
|
2022-02-01 10:33:41 +03:00
|
|
|
i = freerdp_settings_get_key_for_name(name);
|
|
|
|
if (i < 0)
|
2020-04-11 12:55:11 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Invalid settings key [%s]", name);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2022-02-01 10:33:41 +03:00
|
|
|
index = (size_t)i;
|
|
|
|
|
|
|
|
type = freerdp_settings_get_type_for_key(index);
|
2020-04-11 12:55:11 +03:00
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
|
|
|
|
case RDP_SETTINGS_TYPE_BOOL:
|
|
|
|
{
|
|
|
|
BOOL val = _strnicmp(value, "TRUE", 5) == 0;
|
2022-05-02 15:20:12 +03:00
|
|
|
if (!val && _strnicmp(value, "FALSE", 6) != 0)
|
2020-04-11 12:55:11 +03:00
|
|
|
return parsing_fail(name, "BOOL", value);
|
|
|
|
return freerdp_settings_set_bool(settings, index, val);
|
|
|
|
}
|
|
|
|
case RDP_SETTINGS_TYPE_UINT16:
|
|
|
|
if (!value_to_uint(value, &uval, 0, UINT16_MAX))
|
|
|
|
return parsing_fail(name, "UINT16", value);
|
|
|
|
if (!freerdp_settings_set_uint16(settings, index, uval))
|
|
|
|
return parsing_fail(name, "UINT16", value);
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
case RDP_SETTINGS_TYPE_INT16:
|
|
|
|
if (!value_to_int(value, &ival, INT16_MIN, INT16_MAX))
|
|
|
|
return parsing_fail(name, "INT16", value);
|
|
|
|
if (!freerdp_settings_set_int16(settings, index, ival))
|
|
|
|
return parsing_fail(name, "INT16", value);
|
|
|
|
return TRUE;
|
|
|
|
case RDP_SETTINGS_TYPE_UINT32:
|
|
|
|
if (!value_to_uint(value, &uval, 0, UINT32_MAX))
|
|
|
|
return parsing_fail(name, "UINT32", value);
|
|
|
|
if (!freerdp_settings_set_uint32(settings, index, uval))
|
|
|
|
return parsing_fail(name, "UINT32", value);
|
|
|
|
return TRUE;
|
|
|
|
case RDP_SETTINGS_TYPE_INT32:
|
|
|
|
if (!value_to_int(value, &ival, INT32_MIN, INT32_MAX))
|
|
|
|
return parsing_fail(name, "INT32", value);
|
|
|
|
if (!freerdp_settings_set_int32(settings, index, ival))
|
|
|
|
return parsing_fail(name, "INT32", value);
|
|
|
|
return TRUE;
|
|
|
|
case RDP_SETTINGS_TYPE_UINT64:
|
|
|
|
if (!value_to_uint(value, &uval, 0, UINT64_MAX))
|
|
|
|
return parsing_fail(name, "UINT64", value);
|
|
|
|
if (!freerdp_settings_set_uint64(settings, index, uval))
|
|
|
|
return parsing_fail(name, "UINT64", value);
|
|
|
|
return TRUE;
|
|
|
|
case RDP_SETTINGS_TYPE_INT64:
|
|
|
|
if (!value_to_int(value, &ival, INT64_MIN, INT64_MAX))
|
|
|
|
return parsing_fail(name, "INT64", value);
|
|
|
|
if (!freerdp_settings_set_int64(settings, index, ival))
|
|
|
|
return parsing_fail(name, "INT64", value);
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
case RDP_SETTINGS_TYPE_STRING:
|
|
|
|
return freerdp_settings_set_string(settings, index, value);
|
|
|
|
case RDP_SETTINGS_TYPE_POINTER:
|
|
|
|
return parsing_fail(name, "POINTER", value);
|
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
2020-12-15 18:11:22 +03:00
|
|
|
|
2020-11-19 12:09:34 +03:00
|
|
|
static BOOL freerdp_settings_set_pointer_len_(rdpSettings* settings, size_t id, SSIZE_T lenId,
|
2021-04-12 12:06:45 +03:00
|
|
|
const void* data, size_t len, size_t size)
|
2020-11-19 12:09:34 +03:00
|
|
|
{
|
2023-01-18 13:44:22 +03:00
|
|
|
BOOL rc = FALSE;
|
|
|
|
void* copy = NULL;
|
2020-11-19 12:09:34 +03:00
|
|
|
void* old = freerdp_settings_get_pointer_writable(settings, id);
|
|
|
|
free(old);
|
|
|
|
if (!freerdp_settings_set_pointer(settings, id, NULL))
|
|
|
|
return FALSE;
|
|
|
|
if (lenId >= 0)
|
|
|
|
{
|
2022-02-01 10:33:41 +03:00
|
|
|
if (!freerdp_settings_set_uint32(settings, (size_t)lenId, 0))
|
2020-11-19 12:09:34 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (len == 0)
|
|
|
|
return TRUE;
|
2021-04-12 12:06:45 +03:00
|
|
|
copy = calloc(len, size);
|
2020-11-19 12:09:34 +03:00
|
|
|
if (!copy)
|
|
|
|
return FALSE;
|
|
|
|
if (data)
|
2021-04-12 12:06:45 +03:00
|
|
|
memcpy(copy, data, len * size);
|
2020-11-19 12:09:34 +03:00
|
|
|
rc = freerdp_settings_set_pointer(settings, id, copy);
|
|
|
|
if (!rc)
|
|
|
|
{
|
|
|
|
free(copy);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (lenId < 0)
|
|
|
|
return TRUE;
|
2022-02-01 10:33:41 +03:00
|
|
|
return freerdp_settings_set_uint32(settings, (size_t)lenId, len);
|
2020-11-19 12:09:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
const void* freerdp_settings_get_pointer(const rdpSettings* settings, size_t id)
|
|
|
|
{
|
2022-02-01 10:22:51 +03:00
|
|
|
union
|
|
|
|
{
|
|
|
|
const rdpSettings* pc;
|
|
|
|
rdpSettings* p;
|
|
|
|
} cnv;
|
|
|
|
cnv.pc = settings;
|
|
|
|
return freerdp_settings_get_pointer_writable(cnv.p, id);
|
2020-11-19 12:09:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL freerdp_settings_set_pointer_len(rdpSettings* settings, size_t id, const void* data,
|
|
|
|
size_t len)
|
|
|
|
{
|
2021-10-07 10:22:27 +03:00
|
|
|
union
|
|
|
|
{
|
|
|
|
const void* cv;
|
|
|
|
void* v;
|
|
|
|
} cnv;
|
|
|
|
|
|
|
|
cnv.cv = data;
|
2020-11-19 12:09:34 +03:00
|
|
|
if (!settings)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
switch (id)
|
|
|
|
{
|
|
|
|
case FreeRDP_RdpServerCertificate:
|
2023-02-03 13:40:35 +03:00
|
|
|
freerdp_certificate_free(settings->RdpServerCertificate);
|
2022-04-19 15:29:17 +03:00
|
|
|
|
|
|
|
if (len > 1)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "FreeRDP_RdpServerCertificate::len must be 0 or 1");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
settings->RdpServerCertificate = cnv.v;
|
|
|
|
if (!settings->RdpServerCertificate && (len > 0))
|
|
|
|
{
|
2023-02-03 13:40:35 +03:00
|
|
|
settings->RdpServerCertificate = freerdp_certificate_new();
|
2022-04-19 15:29:17 +03:00
|
|
|
if (!settings->RdpServerCertificate)
|
|
|
|
return FALSE;
|
|
|
|
}
|
2020-11-19 12:09:34 +03:00
|
|
|
return TRUE;
|
|
|
|
case FreeRDP_RdpServerRsaKey:
|
2023-02-03 13:40:35 +03:00
|
|
|
freerdp_key_free(settings->RdpServerRsaKey);
|
2022-04-28 09:00:39 +03:00
|
|
|
if (len > 1)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "FreeRDP_RdpServerRsaKey::len must be 0 or 1");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2023-02-03 17:15:18 +03:00
|
|
|
settings->RdpServerRsaKey = (rdpPrivateKey*)cnv.v;
|
2023-02-03 13:40:35 +03:00
|
|
|
if (!settings->RdpServerRsaKey && (len > 0))
|
|
|
|
{
|
|
|
|
settings->RdpServerRsaKey = freerdp_key_new();
|
|
|
|
if (!settings->RdpServerRsaKey)
|
|
|
|
return FALSE;
|
|
|
|
}
|
2020-11-19 12:09:34 +03:00
|
|
|
return TRUE;
|
|
|
|
case FreeRDP_RedirectionPassword:
|
2021-04-12 12:06:45 +03:00
|
|
|
return freerdp_settings_set_pointer_len_(
|
|
|
|
settings, id, FreeRDP_RedirectionPasswordLength, data, len, sizeof(char));
|
2020-11-19 12:09:34 +03:00
|
|
|
case FreeRDP_RedirectionTsvUrl:
|
|
|
|
return freerdp_settings_set_pointer_len_(settings, id, FreeRDP_RedirectionTsvUrlLength,
|
2021-04-12 12:06:45 +03:00
|
|
|
data, len, sizeof(char));
|
2023-01-16 10:33:46 +03:00
|
|
|
case FreeRDP_RedirectionTargetCertificate:
|
2023-02-22 18:41:37 +03:00
|
|
|
freerdp_certificate_free(settings->RedirectionTargetCertificate);
|
|
|
|
|
|
|
|
if (len > 1)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "FreeRDP_RedirectionTargetCertificate::len must be 0 or 1");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
settings->RedirectionTargetCertificate = cnv.v;
|
|
|
|
if (!settings->RedirectionTargetCertificate && (len > 0))
|
|
|
|
{
|
|
|
|
settings->RedirectionTargetCertificate = freerdp_certificate_new();
|
|
|
|
if (!settings->RedirectionTargetCertificate)
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
2023-01-16 10:33:46 +03:00
|
|
|
case FreeRDP_RedirectionGuid:
|
|
|
|
return freerdp_settings_set_pointer_len_(settings, id, FreeRDP_RedirectionGuidLength,
|
|
|
|
data, len, sizeof(BYTE));
|
2020-11-19 12:09:34 +03:00
|
|
|
case FreeRDP_LoadBalanceInfo:
|
|
|
|
return freerdp_settings_set_pointer_len_(settings, id, FreeRDP_LoadBalanceInfoLength,
|
2021-04-12 12:06:45 +03:00
|
|
|
data, len, sizeof(char));
|
2020-11-19 12:09:34 +03:00
|
|
|
case FreeRDP_ServerRandom:
|
|
|
|
return freerdp_settings_set_pointer_len_(settings, id, FreeRDP_ServerRandomLength, data,
|
2021-04-12 12:06:45 +03:00
|
|
|
len, sizeof(char));
|
2020-11-19 12:09:34 +03:00
|
|
|
case FreeRDP_ClientRandom:
|
|
|
|
return freerdp_settings_set_pointer_len_(settings, id, FreeRDP_ClientRandomLength, data,
|
2021-04-12 12:06:45 +03:00
|
|
|
len, sizeof(char));
|
2020-11-19 12:09:34 +03:00
|
|
|
case FreeRDP_ServerCertificate:
|
|
|
|
return freerdp_settings_set_pointer_len_(settings, id, FreeRDP_ServerCertificateLength,
|
2021-04-12 12:06:45 +03:00
|
|
|
data, len, sizeof(char));
|
2020-11-19 12:09:34 +03:00
|
|
|
case FreeRDP_TargetNetAddresses:
|
|
|
|
if (data == NULL)
|
|
|
|
freerdp_target_net_addresses_free(settings);
|
|
|
|
return freerdp_settings_set_pointer_len_(settings, FreeRDP_TargetNetAddresses,
|
2021-04-12 12:06:45 +03:00
|
|
|
FreeRDP_TargetNetAddressCount, data, len,
|
2022-05-02 15:59:33 +03:00
|
|
|
sizeof(char*));
|
2022-10-06 12:32:08 +03:00
|
|
|
case FreeRDP_ServerLicenseProductIssuers:
|
|
|
|
if (data == NULL)
|
|
|
|
freerdp_server_license_issuers_free(settings);
|
|
|
|
return freerdp_settings_set_pointer_len_(settings, FreeRDP_ServerLicenseProductIssuers,
|
|
|
|
FreeRDP_ServerLicenseProductIssuersCount, data,
|
|
|
|
len, sizeof(char*));
|
2020-11-19 12:09:34 +03:00
|
|
|
case FreeRDP_TargetNetPorts:
|
|
|
|
if (data == NULL)
|
|
|
|
freerdp_target_net_addresses_free(settings);
|
|
|
|
return freerdp_settings_set_pointer_len_(settings, FreeRDP_TargetNetPorts,
|
2021-04-12 12:06:45 +03:00
|
|
|
FreeRDP_TargetNetAddressCount, data, len,
|
2022-05-01 16:07:23 +03:00
|
|
|
sizeof(UINT32));
|
2022-04-28 09:00:39 +03:00
|
|
|
case FreeRDP_DeviceArray:
|
|
|
|
if (data == NULL)
|
|
|
|
freerdp_device_collection_free(settings);
|
|
|
|
return freerdp_settings_set_pointer_len_(settings, id, FreeRDP_DeviceArraySize, data,
|
2022-05-01 16:07:23 +03:00
|
|
|
len, sizeof(ADDIN_ARGV*));
|
2021-09-22 15:27:21 +03:00
|
|
|
case FreeRDP_ChannelDefArray:
|
2022-04-28 09:00:39 +03:00
|
|
|
if ((len > 0) && (len < CHANNEL_MAX_COUNT))
|
|
|
|
WLog_WARN(TAG,
|
|
|
|
"FreeRDP_ChannelDefArray::len expected to be >= %" PRIu32
|
|
|
|
", but have %" PRIu32,
|
|
|
|
CHANNEL_MAX_COUNT, len);
|
2022-06-27 13:05:24 +03:00
|
|
|
return freerdp_settings_set_pointer_len_(settings, FreeRDP_ChannelDefArray,
|
|
|
|
FreeRDP_ChannelDefArraySize, data, len,
|
|
|
|
sizeof(CHANNEL_DEF));
|
2022-04-19 15:29:17 +03:00
|
|
|
case FreeRDP_MonitorDefArray:
|
2022-04-28 09:00:39 +03:00
|
|
|
return freerdp_settings_set_pointer_len_(settings, id, FreeRDP_MonitorDefArraySize,
|
|
|
|
data, len, sizeof(rdpMonitor));
|
2020-11-19 12:09:34 +03:00
|
|
|
case FreeRDP_ClientAutoReconnectCookie:
|
2022-04-19 15:29:17 +03:00
|
|
|
return freerdp_settings_set_pointer_len_(settings, id, -1, data, len,
|
|
|
|
sizeof(ARC_CS_PRIVATE_PACKET));
|
2020-11-19 12:09:34 +03:00
|
|
|
case FreeRDP_ServerAutoReconnectCookie:
|
2022-04-19 15:29:17 +03:00
|
|
|
return freerdp_settings_set_pointer_len_(settings, id, -1, data, len,
|
|
|
|
sizeof(ARC_SC_PRIVATE_PACKET));
|
|
|
|
case FreeRDP_ClientTimeZone:
|
2022-04-28 09:00:39 +03:00
|
|
|
if (len > 1)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "FreeRDP_ClientTimeZone::len must be 0 or 1");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2022-04-19 15:29:17 +03:00
|
|
|
return freerdp_settings_set_pointer_len_(settings, id, -1, data, len,
|
|
|
|
sizeof(TIME_ZONE_INFORMATION));
|
2020-11-19 12:09:34 +03:00
|
|
|
case FreeRDP_BitmapCacheV2CellInfo:
|
2022-04-28 09:00:39 +03:00
|
|
|
return freerdp_settings_set_pointer_len_(settings, id, FreeRDP_BitmapCacheV2NumCells,
|
|
|
|
data, len, sizeof(BITMAP_CACHE_V2_CELL_INFO));
|
2020-11-19 12:09:34 +03:00
|
|
|
case FreeRDP_GlyphCache:
|
2022-04-28 09:00:39 +03:00
|
|
|
if ((len != 0) && (len != 10))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "FreeRDP_GlyphCache::len must be 0 or 10");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return freerdp_settings_set_pointer_len_(settings, id, -1, data, len,
|
|
|
|
sizeof(GLYPH_CACHE_DEFINITION));
|
2020-11-19 12:09:34 +03:00
|
|
|
case FreeRDP_FragCache:
|
2022-04-28 09:00:39 +03:00
|
|
|
if (len > 1)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "FreeRDP_FragCache::len must be 0 or 1");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return freerdp_settings_set_pointer_len_(settings, id, -1, data, len,
|
|
|
|
sizeof(GLYPH_CACHE_DEFINITION));
|
|
|
|
case FreeRDP_StaticChannelArray:
|
|
|
|
if (data == NULL)
|
|
|
|
freerdp_static_channel_collection_free(settings);
|
|
|
|
return freerdp_settings_set_pointer_len_(settings, id, FreeRDP_StaticChannelArraySize,
|
|
|
|
data, len, sizeof(ADDIN_ARGV*));
|
|
|
|
case FreeRDP_DynamicChannelArray:
|
|
|
|
if (data == NULL)
|
|
|
|
freerdp_dynamic_channel_collection_free(settings);
|
|
|
|
return freerdp_settings_set_pointer_len_(settings, id, FreeRDP_DynamicChannelArraySize,
|
|
|
|
data, len, sizeof(ADDIN_ARGV*));
|
2022-10-05 10:30:37 +03:00
|
|
|
case FreeRDP_ReceivedCapabilityData:
|
|
|
|
if (data == NULL)
|
|
|
|
freerdp_capability_buffer_free(settings);
|
|
|
|
return freerdp_settings_set_pointer_len_(settings, id, FreeRDP_ReceivedCapabilitiesSize,
|
|
|
|
data, len, sizeof(BYTE*));
|
2022-04-28 09:00:39 +03:00
|
|
|
case FreeRDP_ReceivedCapabilities:
|
2022-06-27 13:05:24 +03:00
|
|
|
if (data == NULL)
|
|
|
|
freerdp_capability_buffer_free(settings);
|
|
|
|
return freerdp_settings_set_pointer_len_(settings, id, FreeRDP_ReceivedCapabilitiesSize,
|
|
|
|
data, len, sizeof(char));
|
2022-04-28 09:00:39 +03:00
|
|
|
case FreeRDP_OrderSupport:
|
2021-04-12 12:06:45 +03:00
|
|
|
return freerdp_settings_set_pointer_len_(settings, id, -1, data, len, sizeof(char));
|
|
|
|
|
|
|
|
case FreeRDP_MonitorIds:
|
|
|
|
return freerdp_settings_set_pointer_len_(
|
|
|
|
settings, FreeRDP_MonitorIds, FreeRDP_NumMonitorIds, data, len, sizeof(UINT32));
|
|
|
|
|
2020-11-19 12:09:34 +03:00
|
|
|
default:
|
|
|
|
if ((data == NULL) && (len == 0))
|
|
|
|
{
|
|
|
|
freerdp_settings_set_pointer(settings, id, NULL);
|
|
|
|
}
|
|
|
|
else
|
2023-01-23 14:03:18 +03:00
|
|
|
WLog_WARN(TAG, "Invalid id %" PRIuz, id);
|
2020-11-19 12:09:34 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void* freerdp_settings_get_pointer_array_writable(const rdpSettings* settings, size_t id,
|
|
|
|
size_t offset)
|
|
|
|
{
|
2022-05-02 15:59:33 +03:00
|
|
|
size_t max;
|
2020-11-19 12:09:34 +03:00
|
|
|
if (!settings)
|
|
|
|
return NULL;
|
|
|
|
switch (id)
|
|
|
|
{
|
2022-05-02 15:59:33 +03:00
|
|
|
case FreeRDP_ClientAutoReconnectCookie:
|
|
|
|
max = 1;
|
|
|
|
if ((offset >= max) || !settings->ClientAutoReconnectCookie)
|
|
|
|
goto fail;
|
|
|
|
return &settings->ClientAutoReconnectCookie[offset];
|
|
|
|
case FreeRDP_ServerAutoReconnectCookie:
|
|
|
|
max = 1;
|
|
|
|
if ((offset >= max) || !settings->ServerAutoReconnectCookie)
|
|
|
|
goto fail;
|
|
|
|
return &settings->ServerAutoReconnectCookie[offset];
|
|
|
|
case FreeRDP_ServerCertificate:
|
|
|
|
max = freerdp_settings_get_uint32(settings, FreeRDP_ServerCertificateLength);
|
|
|
|
if (offset >= max)
|
|
|
|
goto fail;
|
|
|
|
return &settings->ServerCertificate[offset];
|
|
|
|
case FreeRDP_ServerRandom:
|
|
|
|
max = freerdp_settings_get_uint32(settings, FreeRDP_ServerRandomLength);
|
|
|
|
if (offset >= max)
|
|
|
|
goto fail;
|
|
|
|
return &settings->ServerRandom[offset];
|
|
|
|
case FreeRDP_ClientRandom:
|
|
|
|
max = freerdp_settings_get_uint32(settings, FreeRDP_ClientRandomLength);
|
|
|
|
if (offset >= max)
|
|
|
|
goto fail;
|
|
|
|
return &settings->ClientRandom[offset];
|
|
|
|
case FreeRDP_LoadBalanceInfo:
|
|
|
|
max = freerdp_settings_get_uint32(settings, FreeRDP_LoadBalanceInfoLength);
|
|
|
|
if (offset >= max)
|
|
|
|
goto fail;
|
|
|
|
return &settings->LoadBalanceInfo[offset];
|
|
|
|
|
|
|
|
case FreeRDP_RedirectionTsvUrl:
|
|
|
|
max = freerdp_settings_get_uint32(settings, FreeRDP_RedirectionTsvUrlLength);
|
|
|
|
if (offset >= max)
|
|
|
|
goto fail;
|
|
|
|
return &settings->RedirectionTsvUrl[offset];
|
|
|
|
|
|
|
|
case FreeRDP_RedirectionPassword:
|
|
|
|
max = freerdp_settings_get_uint32(settings, FreeRDP_RedirectionPasswordLength);
|
|
|
|
if (offset >= max)
|
|
|
|
goto fail;
|
|
|
|
return &settings->RedirectionPassword[offset];
|
|
|
|
|
2020-11-19 12:09:34 +03:00
|
|
|
case FreeRDP_OrderSupport:
|
2022-05-02 15:59:33 +03:00
|
|
|
max = 32;
|
|
|
|
if (offset >= max)
|
|
|
|
goto fail;
|
2020-11-19 12:09:34 +03:00
|
|
|
return &settings->OrderSupport[offset];
|
|
|
|
case FreeRDP_MonitorIds:
|
2022-05-02 15:59:33 +03:00
|
|
|
max = freerdp_settings_get_uint32(settings, FreeRDP_NumMonitorIds);
|
|
|
|
if (offset >= max)
|
|
|
|
goto fail;
|
2020-11-19 12:09:34 +03:00
|
|
|
return &settings->MonitorIds[offset];
|
|
|
|
case FreeRDP_MonitorDefArray:
|
2022-05-02 15:59:33 +03:00
|
|
|
max = freerdp_settings_get_uint32(settings, FreeRDP_MonitorDefArraySize);
|
|
|
|
if (offset >= max)
|
|
|
|
goto fail;
|
2020-11-19 12:09:34 +03:00
|
|
|
return &settings->MonitorDefArray[offset];
|
|
|
|
case FreeRDP_ChannelDefArray:
|
2022-05-02 15:59:33 +03:00
|
|
|
max = freerdp_settings_get_uint32(settings, FreeRDP_ChannelDefArraySize);
|
|
|
|
if (offset >= max)
|
|
|
|
goto fail;
|
2020-11-19 12:09:34 +03:00
|
|
|
return &settings->ChannelDefArray[offset];
|
|
|
|
case FreeRDP_DeviceArray:
|
2022-05-02 15:59:33 +03:00
|
|
|
max = freerdp_settings_get_uint32(settings, FreeRDP_DeviceArraySize);
|
|
|
|
if (offset >= max)
|
|
|
|
goto fail;
|
2022-07-06 11:34:50 +03:00
|
|
|
return settings->DeviceArray[offset];
|
2020-11-19 12:09:34 +03:00
|
|
|
case FreeRDP_StaticChannelArray:
|
2022-05-02 15:59:33 +03:00
|
|
|
max = freerdp_settings_get_uint32(settings, FreeRDP_StaticChannelArraySize);
|
|
|
|
if (offset >= max)
|
|
|
|
goto fail;
|
2020-11-19 12:09:34 +03:00
|
|
|
return settings->StaticChannelArray[offset];
|
|
|
|
case FreeRDP_DynamicChannelArray:
|
2022-05-02 15:59:33 +03:00
|
|
|
max = freerdp_settings_get_uint32(settings, FreeRDP_DynamicChannelArraySize);
|
|
|
|
if (offset >= max)
|
|
|
|
goto fail;
|
2020-11-19 12:09:34 +03:00
|
|
|
return settings->DynamicChannelArray[offset];
|
|
|
|
case FreeRDP_FragCache:
|
2022-05-02 15:59:33 +03:00
|
|
|
max = 1;
|
|
|
|
if (offset >= max)
|
|
|
|
goto fail;
|
2020-11-19 12:09:34 +03:00
|
|
|
return &settings->FragCache[offset];
|
|
|
|
case FreeRDP_GlyphCache:
|
2022-05-02 15:59:33 +03:00
|
|
|
max = 10;
|
|
|
|
if (offset >= max)
|
|
|
|
goto fail;
|
2020-11-19 12:09:34 +03:00
|
|
|
return &settings->GlyphCache[offset];
|
|
|
|
case FreeRDP_BitmapCacheV2CellInfo:
|
2022-05-02 15:59:33 +03:00
|
|
|
max = freerdp_settings_get_uint32(settings, FreeRDP_BitmapCacheV2NumCells);
|
|
|
|
if (offset >= max)
|
|
|
|
goto fail;
|
2020-11-19 12:09:34 +03:00
|
|
|
return &settings->BitmapCacheV2CellInfo[offset];
|
|
|
|
case FreeRDP_ReceivedCapabilities:
|
2022-05-02 15:59:33 +03:00
|
|
|
max = freerdp_settings_get_uint32(settings, FreeRDP_ReceivedCapabilitiesSize);
|
|
|
|
if (offset >= max)
|
|
|
|
goto fail;
|
2020-11-19 12:09:34 +03:00
|
|
|
return &settings->ReceivedCapabilities[offset];
|
2022-05-02 15:59:33 +03:00
|
|
|
case FreeRDP_TargetNetAddresses:
|
|
|
|
max = freerdp_settings_get_uint32(settings, FreeRDP_TargetNetAddressCount);
|
|
|
|
if (offset >= max)
|
|
|
|
goto fail;
|
|
|
|
return settings->TargetNetAddresses[offset];
|
|
|
|
case FreeRDP_TargetNetPorts:
|
|
|
|
max = freerdp_settings_get_uint32(settings, FreeRDP_TargetNetAddressCount);
|
|
|
|
if (offset >= max)
|
|
|
|
goto fail;
|
2023-02-01 11:40:36 +03:00
|
|
|
return &settings->TargetNetPorts[offset];
|
2022-05-02 15:59:33 +03:00
|
|
|
case FreeRDP_ClientTimeZone:
|
|
|
|
max = 1;
|
|
|
|
if (offset >= max)
|
|
|
|
goto fail;
|
|
|
|
return settings->ClientTimeZone;
|
|
|
|
case FreeRDP_RdpServerCertificate:
|
|
|
|
max = 1;
|
|
|
|
if (offset >= max)
|
|
|
|
goto fail;
|
|
|
|
return settings->RdpServerCertificate;
|
|
|
|
case FreeRDP_RdpServerRsaKey:
|
|
|
|
max = 1;
|
|
|
|
if (offset >= max)
|
|
|
|
goto fail;
|
|
|
|
return settings->RdpServerRsaKey;
|
2020-11-19 12:09:34 +03:00
|
|
|
default:
|
2023-01-23 14:03:18 +03:00
|
|
|
WLog_WARN(TAG, "Invalid id %s [%" PRIuz "]", freerdp_settings_get_name_for_key(id), id);
|
2020-11-19 12:09:34 +03:00
|
|
|
return NULL;
|
|
|
|
}
|
2022-05-02 15:59:33 +03:00
|
|
|
|
|
|
|
fail:
|
|
|
|
WLog_WARN(TAG, "Invalid offset for %s [%" PRIuz "]: size=%" PRIuz ", offset=%" PRIuz,
|
|
|
|
freerdp_settings_get_name_for_key(id), id, max, offset);
|
|
|
|
return NULL;
|
2020-11-19 12:09:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL freerdp_settings_set_pointer_array(rdpSettings* settings, size_t id, size_t offset,
|
|
|
|
const void* data)
|
|
|
|
{
|
2022-04-28 09:00:39 +03:00
|
|
|
size_t maxOffset = 0;
|
2020-11-19 12:09:34 +03:00
|
|
|
if (!settings)
|
|
|
|
return FALSE;
|
|
|
|
switch (id)
|
|
|
|
{
|
2022-05-02 15:59:33 +03:00
|
|
|
case FreeRDP_ClientAutoReconnectCookie:
|
|
|
|
maxOffset = 1;
|
|
|
|
if ((offset >= maxOffset) || !data || !settings->ClientAutoReconnectCookie)
|
|
|
|
goto fail;
|
|
|
|
settings->ClientAutoReconnectCookie[offset] = *(const ARC_CS_PRIVATE_PACKET*)data;
|
|
|
|
return TRUE;
|
|
|
|
case FreeRDP_ServerAutoReconnectCookie:
|
|
|
|
maxOffset = 1;
|
|
|
|
if ((offset >= maxOffset) || !data || !settings->ServerAutoReconnectCookie)
|
|
|
|
goto fail;
|
|
|
|
settings->ServerAutoReconnectCookie[offset] = *(const ARC_SC_PRIVATE_PACKET*)data;
|
|
|
|
return TRUE;
|
|
|
|
case FreeRDP_ServerCertificate:
|
|
|
|
maxOffset = freerdp_settings_get_uint32(settings, FreeRDP_ServerCertificateLength);
|
|
|
|
if ((offset >= maxOffset) || !data)
|
|
|
|
goto fail;
|
|
|
|
settings->ServerCertificate[offset] = *(const BYTE*)data;
|
|
|
|
return TRUE;
|
2022-04-28 09:00:39 +03:00
|
|
|
case FreeRDP_DeviceArray:
|
|
|
|
maxOffset = freerdp_settings_get_uint32(settings, FreeRDP_DeviceArraySize);
|
2022-05-01 11:57:11 +03:00
|
|
|
if (offset >= maxOffset)
|
2022-04-28 09:00:39 +03:00
|
|
|
goto fail;
|
|
|
|
freerdp_device_free(settings->DeviceArray[offset]);
|
|
|
|
settings->DeviceArray[offset] = freerdp_device_clone(data);
|
2022-05-01 11:57:11 +03:00
|
|
|
return TRUE;
|
2020-11-19 12:09:34 +03:00
|
|
|
case FreeRDP_TargetNetAddresses:
|
2022-04-28 09:00:39 +03:00
|
|
|
maxOffset = freerdp_settings_get_uint32(settings, FreeRDP_TargetNetAddressCount);
|
|
|
|
if ((offset >= maxOffset) || !data)
|
|
|
|
goto fail;
|
2020-11-19 12:09:34 +03:00
|
|
|
free(settings->TargetNetAddresses[offset]);
|
|
|
|
settings->TargetNetAddresses[offset] = _strdup((const char*)data);
|
|
|
|
return settings->TargetNetAddresses[offset] != NULL;
|
|
|
|
case FreeRDP_TargetNetPorts:
|
2022-04-28 09:00:39 +03:00
|
|
|
maxOffset = freerdp_settings_get_uint32(settings, FreeRDP_TargetNetAddressCount);
|
|
|
|
if ((offset >= maxOffset) || !data)
|
|
|
|
goto fail;
|
2020-11-19 12:09:34 +03:00
|
|
|
settings->TargetNetPorts[offset] = *((const UINT32*)data);
|
|
|
|
return TRUE;
|
2022-04-28 09:00:39 +03:00
|
|
|
case FreeRDP_StaticChannelArray:
|
|
|
|
maxOffset = freerdp_settings_get_uint32(settings, FreeRDP_StaticChannelArraySize);
|
|
|
|
if ((offset >= maxOffset) || !data)
|
|
|
|
goto fail;
|
|
|
|
freerdp_addin_argv_free(settings->StaticChannelArray[offset]);
|
|
|
|
settings->StaticChannelArray[offset] = freerdp_addin_argv_clone(data);
|
|
|
|
return TRUE;
|
|
|
|
case FreeRDP_DynamicChannelArray:
|
|
|
|
maxOffset = freerdp_settings_get_uint32(settings, FreeRDP_DynamicChannelArraySize);
|
|
|
|
if ((offset >= maxOffset) || !data)
|
|
|
|
goto fail;
|
|
|
|
freerdp_addin_argv_free(settings->DynamicChannelArray[offset]);
|
|
|
|
settings->DynamicChannelArray[offset] = freerdp_addin_argv_clone(data);
|
|
|
|
return TRUE;
|
2020-11-19 12:09:34 +03:00
|
|
|
case FreeRDP_BitmapCacheV2CellInfo:
|
2022-05-02 15:59:33 +03:00
|
|
|
maxOffset = freerdp_settings_get_uint32(settings, FreeRDP_BitmapCacheV2NumCells);
|
|
|
|
if ((offset >= maxOffset) || !data)
|
|
|
|
goto fail;
|
|
|
|
{
|
|
|
|
const BITMAP_CACHE_V2_CELL_INFO* cdata = (const BITMAP_CACHE_V2_CELL_INFO*)data;
|
|
|
|
settings->BitmapCacheV2CellInfo[offset] = *cdata;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
case FreeRDP_ServerRandom:
|
|
|
|
maxOffset = freerdp_settings_get_uint32(settings, FreeRDP_ServerRandomLength);
|
|
|
|
if ((offset >= maxOffset) || !data)
|
|
|
|
goto fail;
|
|
|
|
settings->ServerRandom[offset] = *(const BYTE*)data;
|
|
|
|
return TRUE;
|
|
|
|
case FreeRDP_ClientRandom:
|
|
|
|
maxOffset = freerdp_settings_get_uint32(settings, FreeRDP_ClientRandomLength);
|
|
|
|
if ((offset >= maxOffset) || !data)
|
|
|
|
goto fail;
|
|
|
|
settings->ClientRandom[offset] = *(const BYTE*)data;
|
|
|
|
return TRUE;
|
|
|
|
case FreeRDP_LoadBalanceInfo:
|
|
|
|
maxOffset = freerdp_settings_get_uint32(settings, FreeRDP_LoadBalanceInfoLength);
|
|
|
|
if ((offset >= maxOffset) || !data)
|
|
|
|
goto fail;
|
|
|
|
settings->LoadBalanceInfo[offset] = *(const BYTE*)data;
|
|
|
|
return TRUE;
|
|
|
|
case FreeRDP_RedirectionTsvUrl:
|
|
|
|
maxOffset = freerdp_settings_get_uint32(settings, FreeRDP_RedirectionTsvUrlLength);
|
|
|
|
if ((offset >= maxOffset) || !data)
|
|
|
|
goto fail;
|
|
|
|
settings->RedirectionTsvUrl[offset] = *(const BYTE*)data;
|
|
|
|
return TRUE;
|
|
|
|
case FreeRDP_RedirectionPassword:
|
|
|
|
maxOffset = freerdp_settings_get_uint32(settings, FreeRDP_RedirectionPasswordLength);
|
2022-04-28 09:00:39 +03:00
|
|
|
if ((offset >= maxOffset) || !data)
|
|
|
|
goto fail;
|
2022-05-02 15:59:33 +03:00
|
|
|
settings->RedirectionPassword[offset] = *(const BYTE*)data;
|
2020-11-19 12:09:34 +03:00
|
|
|
return TRUE;
|
|
|
|
case FreeRDP_OrderSupport:
|
2022-04-28 09:00:39 +03:00
|
|
|
maxOffset = 32;
|
2022-05-02 15:59:33 +03:00
|
|
|
if (!settings->OrderSupport)
|
|
|
|
goto fail;
|
2022-04-28 09:00:39 +03:00
|
|
|
if ((offset >= maxOffset) || !data)
|
|
|
|
goto fail;
|
2020-11-19 12:09:34 +03:00
|
|
|
settings->OrderSupport[offset] = *(const BOOL*)data;
|
|
|
|
return TRUE;
|
|
|
|
case FreeRDP_GlyphCache:
|
2022-04-28 09:00:39 +03:00
|
|
|
maxOffset = 10;
|
2022-05-02 15:59:33 +03:00
|
|
|
if (!settings->GlyphCache)
|
|
|
|
goto fail;
|
2022-04-28 09:00:39 +03:00
|
|
|
if ((offset >= maxOffset) || !data)
|
|
|
|
goto fail;
|
2020-11-19 12:09:34 +03:00
|
|
|
settings->GlyphCache[offset] = *(const GLYPH_CACHE_DEFINITION*)data;
|
|
|
|
return TRUE;
|
|
|
|
case FreeRDP_FragCache:
|
2022-04-28 09:00:39 +03:00
|
|
|
maxOffset = 1;
|
2022-05-02 15:59:33 +03:00
|
|
|
if (!settings->FragCache)
|
|
|
|
goto fail;
|
2022-04-28 09:00:39 +03:00
|
|
|
if ((offset >= maxOffset) || !data)
|
|
|
|
goto fail;
|
2020-11-19 12:09:34 +03:00
|
|
|
settings->FragCache[offset] = *(const GLYPH_CACHE_DEFINITION*)data;
|
|
|
|
return TRUE;
|
|
|
|
case FreeRDP_MonitorIds:
|
2022-04-28 09:00:39 +03:00
|
|
|
maxOffset = freerdp_settings_get_uint32(settings, FreeRDP_NumMonitorIds);
|
|
|
|
if ((offset >= maxOffset) || !data)
|
|
|
|
goto fail;
|
2020-11-19 12:09:34 +03:00
|
|
|
settings->MonitorIds[offset] = *(const UINT32*)data;
|
|
|
|
return TRUE;
|
|
|
|
case FreeRDP_ChannelDefArray:
|
2022-04-28 09:00:39 +03:00
|
|
|
maxOffset = freerdp_settings_get_uint32(settings, FreeRDP_ChannelDefArraySize);
|
|
|
|
if ((offset >= maxOffset) || !data)
|
|
|
|
goto fail;
|
2020-11-19 12:09:34 +03:00
|
|
|
settings->ChannelDefArray[offset] = *(const CHANNEL_DEF*)data;
|
|
|
|
return TRUE;
|
2022-04-19 15:29:17 +03:00
|
|
|
case FreeRDP_MonitorDefArray:
|
2022-04-28 09:00:39 +03:00
|
|
|
maxOffset = freerdp_settings_get_uint32(settings, FreeRDP_MonitorDefArraySize);
|
|
|
|
if ((offset >= maxOffset) || !data)
|
|
|
|
goto fail;
|
2022-04-19 15:29:17 +03:00
|
|
|
settings->MonitorDefArray[offset] = *(const rdpMonitor*)data;
|
|
|
|
return TRUE;
|
2022-05-02 15:59:33 +03:00
|
|
|
|
|
|
|
case FreeRDP_ClientTimeZone:
|
|
|
|
maxOffset = 1;
|
|
|
|
if ((offset >= maxOffset) || !data || !settings->ClientTimeZone)
|
|
|
|
goto fail;
|
|
|
|
settings->ClientTimeZone[0] = *(const TIME_ZONE_INFORMATION*)data;
|
|
|
|
return TRUE;
|
|
|
|
|
2020-11-19 12:09:34 +03:00
|
|
|
default:
|
2023-01-23 14:03:18 +03:00
|
|
|
WLog_WARN(TAG, "Invalid id %s [%" PRIuz "]", freerdp_settings_get_name_for_key(id), id);
|
2020-11-19 12:09:34 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
2022-04-28 09:00:39 +03:00
|
|
|
|
|
|
|
fail:
|
|
|
|
WLog_WARN(TAG, "[%s] Invalid offset=%" PRIuz " [%" PRIuz "] or NULL data=%p",
|
|
|
|
freerdp_settings_get_name_for_key(id), offset, maxOffset, data);
|
|
|
|
return FALSE;
|
2020-11-19 12:09:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
const void* freerdp_settings_get_pointer_array(const rdpSettings* settings, size_t id,
|
|
|
|
size_t offset)
|
|
|
|
{
|
|
|
|
return freerdp_settings_get_pointer_array_writable(settings, id, offset);
|
|
|
|
}
|
|
|
|
|
2020-12-15 18:11:22 +03:00
|
|
|
UINT32 freerdp_settings_get_codecs_flags(const rdpSettings* settings)
|
|
|
|
{
|
|
|
|
UINT32 flags = FREERDP_CODEC_ALL;
|
|
|
|
if (settings->RemoteFxCodec == FALSE)
|
|
|
|
{
|
|
|
|
flags &= ~FREERDP_CODEC_REMOTEFX;
|
|
|
|
}
|
|
|
|
if (settings->NSCodec == FALSE)
|
|
|
|
{
|
|
|
|
flags &= ~FREERDP_CODEC_NSCODEC;
|
|
|
|
}
|
|
|
|
/*TODO: check other codecs flags */
|
|
|
|
return flags;
|
2020-11-19 12:09:34 +03:00
|
|
|
}
|
2021-04-12 11:38:40 +03:00
|
|
|
|
2022-10-14 20:39:12 +03:00
|
|
|
const char* freerdp_settings_get_server_name(const rdpSettings* settings)
|
|
|
|
{
|
2022-11-25 14:09:40 +03:00
|
|
|
WINPR_ASSERT(settings);
|
2022-10-14 20:39:12 +03:00
|
|
|
const char* hostname = settings->ServerHostname;
|
|
|
|
|
|
|
|
if (settings->UserSpecifiedServerName)
|
|
|
|
hostname = settings->UserSpecifiedServerName;
|
|
|
|
|
|
|
|
return hostname;
|
|
|
|
}
|
|
|
|
|
2021-07-28 16:18:03 +03:00
|
|
|
#if defined(WITH_FREERDP_DEPRECATED)
|
2021-04-12 11:38:40 +03:00
|
|
|
ADDIN_ARGV* freerdp_static_channel_clone(ADDIN_ARGV* channel)
|
|
|
|
{
|
|
|
|
return freerdp_addin_argv_clone(channel);
|
|
|
|
}
|
|
|
|
|
|
|
|
ADDIN_ARGV* freerdp_dynamic_channel_clone(ADDIN_ARGV* channel)
|
|
|
|
{
|
|
|
|
return freerdp_addin_argv_clone(channel);
|
|
|
|
}
|
2021-07-28 16:18:03 +03:00
|
|
|
#endif
|
2021-12-15 11:30:18 +03:00
|
|
|
|
|
|
|
BOOL freerdp_target_net_addresses_copy(rdpSettings* settings, char** addresses, UINT32 count)
|
|
|
|
{
|
|
|
|
UINT32 i;
|
|
|
|
|
|
|
|
WINPR_ASSERT(settings);
|
|
|
|
WINPR_ASSERT(addresses);
|
|
|
|
|
|
|
|
freerdp_target_net_addresses_free(settings);
|
|
|
|
|
|
|
|
settings->TargetNetAddressCount = count;
|
|
|
|
settings->TargetNetAddresses = (char**)calloc(settings->TargetNetAddressCount, sizeof(char*));
|
|
|
|
|
|
|
|
if (!settings->TargetNetAddresses)
|
|
|
|
{
|
|
|
|
freerdp_target_net_addresses_free(settings);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < settings->TargetNetAddressCount; i++)
|
|
|
|
{
|
|
|
|
settings->TargetNetAddresses[i] = _strdup(addresses[i]);
|
|
|
|
|
|
|
|
if (!settings->TargetNetAddresses[i])
|
|
|
|
{
|
|
|
|
freerdp_target_net_addresses_free(settings);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2022-05-02 15:20:12 +03:00
|
|
|
|
|
|
|
BOOL freerdp_device_equal(const RDPDR_DEVICE* what, const RDPDR_DEVICE* expect)
|
|
|
|
{
|
|
|
|
if (!what && !expect)
|
|
|
|
return TRUE;
|
|
|
|
if (!what || !expect)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (what->Id != expect->Id)
|
|
|
|
return FALSE;
|
|
|
|
if (what->Type != expect->Type)
|
|
|
|
return FALSE;
|
|
|
|
if (what->Name && expect->Name)
|
|
|
|
{
|
|
|
|
if (strcmp(what->Name, expect->Name) != 0)
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (what->Name != expect->Name)
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (what->Type)
|
|
|
|
{
|
|
|
|
case RDPDR_DTYP_PRINT:
|
|
|
|
{
|
|
|
|
const RDPDR_PRINTER* a = (const RDPDR_PRINTER*)what;
|
|
|
|
const RDPDR_PRINTER* b = (const RDPDR_PRINTER*)expect;
|
|
|
|
if (a->DriverName && b->DriverName)
|
|
|
|
return strcmp(a->DriverName, b->DriverName) == 0;
|
|
|
|
return a->DriverName == b->DriverName;
|
|
|
|
}
|
|
|
|
|
|
|
|
case RDPDR_DTYP_SERIAL:
|
|
|
|
{
|
|
|
|
const RDPDR_SERIAL* a = (const RDPDR_SERIAL*)what;
|
|
|
|
const RDPDR_SERIAL* b = (const RDPDR_SERIAL*)expect;
|
|
|
|
|
|
|
|
if (a->Path && b->Path)
|
|
|
|
{
|
|
|
|
if (strcmp(a->Path, b->Path) != 0)
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else if (a->Path != b->Path)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (a->Driver && b->Driver)
|
|
|
|
{
|
|
|
|
if (strcmp(a->Driver, b->Driver) != 0)
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else if (a->Driver != b->Driver)
|
|
|
|
return FALSE;
|
|
|
|
if (a->Permissive && b->Permissive)
|
|
|
|
return strcmp(a->Permissive, b->Permissive) == 0;
|
|
|
|
return a->Permissive == b->Permissive;
|
|
|
|
}
|
|
|
|
|
|
|
|
case RDPDR_DTYP_PARALLEL:
|
|
|
|
{
|
|
|
|
const RDPDR_PARALLEL* a = (const RDPDR_PARALLEL*)what;
|
|
|
|
const RDPDR_PARALLEL* b = (const RDPDR_PARALLEL*)expect;
|
|
|
|
if (a->Path && b->Path)
|
|
|
|
return strcmp(a->Path, b->Path) == 0;
|
|
|
|
return a->Path == b->Path;
|
|
|
|
}
|
|
|
|
|
|
|
|
case RDPDR_DTYP_SMARTCARD:
|
|
|
|
break;
|
|
|
|
case RDPDR_DTYP_FILESYSTEM:
|
|
|
|
{
|
|
|
|
const RDPDR_DRIVE* a = (const RDPDR_DRIVE*)what;
|
|
|
|
const RDPDR_DRIVE* b = (const RDPDR_DRIVE*)expect;
|
|
|
|
if (a->automount != b->automount)
|
|
|
|
return FALSE;
|
|
|
|
if (a->Path && b->Path)
|
|
|
|
return strcmp(a->Path, b->Path) == 0;
|
|
|
|
return a->Path == b->Path;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2022-06-29 13:35:31 +03:00
|
|
|
|
|
|
|
char* freerdp_rail_support_flags_to_string(UINT32 flags, char* buffer, size_t length)
|
|
|
|
{
|
2022-11-25 14:09:40 +03:00
|
|
|
const UINT32 mask =
|
|
|
|
RAIL_LEVEL_SUPPORTED | RAIL_LEVEL_DOCKED_LANGBAR_SUPPORTED |
|
|
|
|
RAIL_LEVEL_SHELL_INTEGRATION_SUPPORTED | RAIL_LEVEL_LANGUAGE_IME_SYNC_SUPPORTED |
|
|
|
|
RAIL_LEVEL_SERVER_TO_CLIENT_IME_SYNC_SUPPORTED | RAIL_LEVEL_HIDE_MINIMIZED_APPS_SUPPORTED |
|
|
|
|
RAIL_LEVEL_WINDOW_CLOAKING_SUPPORTED | RAIL_LEVEL_HANDSHAKE_EX_SUPPORTED;
|
|
|
|
|
2022-06-29 13:35:31 +03:00
|
|
|
if (flags & RAIL_LEVEL_SUPPORTED)
|
|
|
|
winpr_str_append("RAIL_LEVEL_SUPPORTED", buffer, length, "|");
|
|
|
|
if (flags & RAIL_LEVEL_DOCKED_LANGBAR_SUPPORTED)
|
|
|
|
winpr_str_append("RAIL_LEVEL_DOCKED_LANGBAR_SUPPORTED", buffer, length, "|");
|
|
|
|
if (flags & RAIL_LEVEL_SHELL_INTEGRATION_SUPPORTED)
|
|
|
|
winpr_str_append("RAIL_LEVEL_SHELL_INTEGRATION_SUPPORTED", buffer, length, "|");
|
|
|
|
if (flags & RAIL_LEVEL_LANGUAGE_IME_SYNC_SUPPORTED)
|
|
|
|
winpr_str_append("RAIL_LEVEL_LANGUAGE_IME_SYNC_SUPPORTED", buffer, length, "|");
|
|
|
|
if (flags & RAIL_LEVEL_SERVER_TO_CLIENT_IME_SYNC_SUPPORTED)
|
|
|
|
winpr_str_append("RAIL_LEVEL_SERVER_TO_CLIENT_IME_SYNC_SUPPORTED", buffer, length, "|");
|
|
|
|
if (flags & RAIL_LEVEL_HIDE_MINIMIZED_APPS_SUPPORTED)
|
|
|
|
winpr_str_append("RAIL_LEVEL_HIDE_MINIMIZED_APPS_SUPPORTED", buffer, length, "|");
|
|
|
|
if (flags & RAIL_LEVEL_WINDOW_CLOAKING_SUPPORTED)
|
|
|
|
winpr_str_append("RAIL_LEVEL_WINDOW_CLOAKING_SUPPORTED", buffer, length, "|");
|
|
|
|
if (flags & RAIL_LEVEL_HANDSHAKE_EX_SUPPORTED)
|
|
|
|
winpr_str_append("RAIL_LEVEL_HANDSHAKE_EX_SUPPORTED", buffer, length, "|");
|
|
|
|
if (flags & RAIL_LEVEL_LANGUAGE_IME_SYNC_SUPPORTED)
|
|
|
|
winpr_str_append("RAIL_LEVEL_LANGUAGE_IME_SYNC_SUPPORTED", buffer, length, "|");
|
2023-01-20 11:33:09 +03:00
|
|
|
if ((flags & ~mask) != 0)
|
2022-11-25 14:09:40 +03:00
|
|
|
{
|
|
|
|
char tbuffer[64] = { 0 };
|
|
|
|
_snprintf(tbuffer, sizeof(tbuffer), "RAIL_FLAG_UNKNOWN 0x%08" PRIx32, flags & mask);
|
|
|
|
winpr_str_append(tbuffer, buffer, length, "|");
|
|
|
|
}
|
2022-06-29 13:35:31 +03:00
|
|
|
return buffer;
|
|
|
|
}
|
2022-10-12 13:37:54 +03:00
|
|
|
|
2022-11-28 14:35:02 +03:00
|
|
|
BOOL freerdp_settings_update_from_caps(rdpSettings* settings, const BYTE* capsFlags,
|
|
|
|
const BYTE** capsData, const UINT32* capsSizes,
|
|
|
|
UINT32 capsCount, BOOL serverReceivedCaps)
|
2022-10-05 10:30:37 +03:00
|
|
|
{
|
|
|
|
UINT32 x;
|
|
|
|
WINPR_ASSERT(settings);
|
|
|
|
WINPR_ASSERT(capsFlags || (capsCount == 0));
|
|
|
|
WINPR_ASSERT(capsData || (capsCount == 0));
|
|
|
|
WINPR_ASSERT(capsSizes || (capsCount == 0));
|
|
|
|
WINPR_ASSERT(capsCount <= UINT16_MAX);
|
|
|
|
|
|
|
|
for (x = 0; x < capsCount; x++)
|
|
|
|
{
|
|
|
|
if (capsFlags[x])
|
|
|
|
{
|
|
|
|
wStream buffer;
|
|
|
|
wStream* sub = Stream_StaticConstInit(&buffer, capsData[x], capsSizes[x]);
|
|
|
|
|
|
|
|
if (!rdp_read_capability_set(sub, (UINT16)x, settings, serverReceivedCaps))
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2022-10-12 13:37:54 +03:00
|
|
|
const char* freerdp_rdp_version_string(UINT32 version)
|
|
|
|
{
|
|
|
|
switch (version)
|
|
|
|
{
|
|
|
|
case RDP_VERSION_4:
|
|
|
|
return "RDP_VERSION_4";
|
|
|
|
case RDP_VERSION_5_PLUS:
|
|
|
|
return "RDP_VERSION_5_PLUS";
|
|
|
|
case RDP_VERSION_10_0:
|
|
|
|
return "RDP_VERSION_10_0";
|
|
|
|
case RDP_VERSION_10_1:
|
|
|
|
return "RDP_VERSION_10_1";
|
|
|
|
case RDP_VERSION_10_2:
|
|
|
|
return "RDP_VERSION_10_2";
|
|
|
|
case RDP_VERSION_10_3:
|
|
|
|
return "RDP_VERSION_10_3";
|
|
|
|
case RDP_VERSION_10_4:
|
|
|
|
return "RDP_VERSION_10_4";
|
|
|
|
case RDP_VERSION_10_5:
|
|
|
|
return "RDP_VERSION_10_5";
|
|
|
|
case RDP_VERSION_10_6:
|
|
|
|
return "RDP_VERSION_10_6";
|
|
|
|
case RDP_VERSION_10_7:
|
|
|
|
return "RDP_VERSION_10_7";
|
|
|
|
case RDP_VERSION_10_8:
|
|
|
|
return "RDP_VERSION_10_8";
|
|
|
|
case RDP_VERSION_10_9:
|
|
|
|
return "RDP_VERSION_10_9";
|
|
|
|
case RDP_VERSION_10_10:
|
|
|
|
return "RDP_VERSION_10_11";
|
|
|
|
case RDP_VERSION_10_11:
|
|
|
|
return "RDP_VERSION_10_11";
|
|
|
|
default:
|
|
|
|
return "RDP_VERSION_UNKNOWN";
|
|
|
|
}
|
|
|
|
}
|
2022-10-28 11:27:46 +03:00
|
|
|
|
|
|
|
BOOL freerdp_settings_set_string_from_utf16(rdpSettings* settings, size_t id, const WCHAR* param)
|
|
|
|
{
|
|
|
|
WINPR_ASSERT(settings);
|
|
|
|
|
|
|
|
if (!param)
|
2023-01-30 16:18:24 +03:00
|
|
|
return freerdp_settings_set_string_copy_(settings, id, NULL, 0, TRUE);
|
2022-10-28 11:27:46 +03:00
|
|
|
|
|
|
|
size_t len = 0;
|
|
|
|
|
|
|
|
char* str = ConvertWCharToUtf8Alloc(param, &len);
|
|
|
|
if (!str && (len != 0))
|
|
|
|
return FALSE;
|
|
|
|
|
2023-01-30 16:18:24 +03:00
|
|
|
return freerdp_settings_set_string_(settings, id, str, len);
|
2022-10-28 11:27:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL freerdp_settings_set_string_from_utf16N(rdpSettings* settings, size_t id, const WCHAR* param,
|
|
|
|
size_t length)
|
|
|
|
{
|
|
|
|
size_t len = 0;
|
|
|
|
|
|
|
|
WINPR_ASSERT(settings);
|
|
|
|
|
|
|
|
if (!param)
|
2023-01-30 16:18:24 +03:00
|
|
|
return freerdp_settings_set_string_copy_(settings, id, NULL, length, TRUE);
|
2022-10-28 11:27:46 +03:00
|
|
|
|
|
|
|
char* str = ConvertWCharNToUtf8Alloc(param, length, &len);
|
|
|
|
if (!str && (length != 0))
|
2023-01-18 12:31:00 +03:00
|
|
|
{
|
|
|
|
/* If the input string is an empty string, but length > 0
|
|
|
|
* consider the conversion a success */
|
|
|
|
const size_t wlen = _wcsnlen(param, length);
|
|
|
|
if (wlen != 0)
|
|
|
|
return FALSE;
|
|
|
|
}
|
2022-10-28 11:27:46 +03:00
|
|
|
|
2023-01-30 16:18:24 +03:00
|
|
|
return freerdp_settings_set_string_(settings, id, str, len);
|
2022-10-28 11:27:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
WCHAR* freerdp_settings_get_string_as_utf16(const rdpSettings* settings, size_t id,
|
|
|
|
size_t* pCharLen)
|
|
|
|
{
|
|
|
|
const char* str = freerdp_settings_get_string(settings, id);
|
|
|
|
if (pCharLen)
|
|
|
|
*pCharLen = 0;
|
|
|
|
if (!str)
|
|
|
|
return NULL;
|
|
|
|
return ConvertUtf8ToWCharAlloc(str, pCharLen);
|
|
|
|
}
|
2022-12-15 12:33:59 +03:00
|
|
|
|
|
|
|
const char* freerdp_rdpdr_dtyp_string(UINT32 type)
|
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case RDPDR_DTYP_FILESYSTEM:
|
|
|
|
return "RDPDR_DTYP_FILESYSTEM";
|
|
|
|
case RDPDR_DTYP_PARALLEL:
|
|
|
|
return "RDPDR_DTYP_PARALLEL";
|
|
|
|
case RDPDR_DTYP_PRINT:
|
|
|
|
return "RDPDR_DTYP_PRINT";
|
|
|
|
case RDPDR_DTYP_SERIAL:
|
|
|
|
return "RDPDR_DTYP_SERIAL";
|
|
|
|
case RDPDR_DTYP_SMARTCARD:
|
|
|
|
return "RDPDR_DTYP_SMARTCARD";
|
|
|
|
default:
|
|
|
|
return "RDPDR_DTYP_UNKNOWN";
|
|
|
|
}
|
|
|
|
}
|
2023-01-17 17:36:18 +03:00
|
|
|
|
|
|
|
const char* freerdp_encryption_level_string(UINT32 EncryptionLevel)
|
|
|
|
{
|
|
|
|
switch (EncryptionLevel)
|
|
|
|
{
|
|
|
|
case ENCRYPTION_LEVEL_NONE:
|
|
|
|
return "ENCRYPTION_LEVEL_NONE";
|
|
|
|
case ENCRYPTION_LEVEL_LOW:
|
|
|
|
return "ENCRYPTION_LEVEL_LOW";
|
|
|
|
case ENCRYPTION_LEVEL_CLIENT_COMPATIBLE:
|
|
|
|
return "ENCRYPTION_LEVEL_CLIENT_COMPATIBLE";
|
|
|
|
case ENCRYPTION_LEVEL_HIGH:
|
|
|
|
return "ENCRYPTION_LEVEL_HIGH";
|
|
|
|
case ENCRYPTION_LEVEL_FIPS:
|
|
|
|
return "ENCRYPTION_LEVEL_FIPS";
|
|
|
|
default:
|
|
|
|
return "ENCRYPTION_LEVEL_UNKNOWN";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* freerdp_encryption_methods_string(UINT32 EncryptionMethods, char* buffer, size_t size)
|
|
|
|
{
|
|
|
|
if (EncryptionMethods == ENCRYPTION_METHOD_NONE)
|
|
|
|
{
|
|
|
|
winpr_str_append("ENCRYPTION_METHOD_NONE", buffer, size, "|");
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (EncryptionMethods & ENCRYPTION_METHOD_40BIT)
|
|
|
|
{
|
|
|
|
winpr_str_append("ENCRYPTION_METHOD_40BIT", buffer, size, "|");
|
|
|
|
}
|
|
|
|
if (EncryptionMethods & ENCRYPTION_METHOD_128BIT)
|
|
|
|
{
|
|
|
|
winpr_str_append("ENCRYPTION_METHOD_128BIT", buffer, size, "|");
|
|
|
|
}
|
|
|
|
if (EncryptionMethods & ENCRYPTION_METHOD_56BIT)
|
|
|
|
{
|
|
|
|
winpr_str_append("ENCRYPTION_METHOD_56BIT", buffer, size, "|");
|
|
|
|
}
|
|
|
|
if (EncryptionMethods & ENCRYPTION_METHOD_FIPS)
|
|
|
|
{
|
|
|
|
winpr_str_append("ENCRYPTION_METHOD_FIPS", buffer, size, "|");
|
|
|
|
}
|
|
|
|
|
|
|
|
return buffer;
|
|
|
|
}
|
2023-04-13 13:52:38 +03:00
|
|
|
|
|
|
|
const char* freerdp_supported_color_depths_string(UINT16 mask, char* buffer, size_t size)
|
|
|
|
{
|
|
|
|
const UINT32 invalid = mask & ~(RNS_UD_32BPP_SUPPORT | RNS_UD_24BPP_SUPPORT |
|
|
|
|
RNS_UD_16BPP_SUPPORT | RNS_UD_15BPP_SUPPORT);
|
|
|
|
|
|
|
|
if (mask & RNS_UD_32BPP_SUPPORT)
|
|
|
|
winpr_str_append("RNS_UD_32BPP_SUPPORT", buffer, size, "|");
|
|
|
|
if (mask & RNS_UD_24BPP_SUPPORT)
|
|
|
|
winpr_str_append("RNS_UD_24BPP_SUPPORT", buffer, size, "|");
|
|
|
|
if (mask & RNS_UD_16BPP_SUPPORT)
|
|
|
|
winpr_str_append("RNS_UD_16BPP_SUPPORT", buffer, size, "|");
|
|
|
|
if (mask & RNS_UD_15BPP_SUPPORT)
|
|
|
|
winpr_str_append("RNS_UD_15BPP_SUPPORT", buffer, size, "|");
|
|
|
|
|
|
|
|
if (invalid != 0)
|
|
|
|
{
|
|
|
|
char str[32] = { 0 };
|
|
|
|
_snprintf(str, sizeof(str), "RNS_UD_INVALID[0x%04" PRIx16 "]", invalid);
|
|
|
|
winpr_str_append(str, buffer, size, "|");
|
|
|
|
}
|
|
|
|
char hex[32] = { 0 };
|
|
|
|
_snprintf(hex, sizeof(hex), "[0x%04" PRIx16 "]", mask);
|
|
|
|
return buffer;
|
|
|
|
}
|