23 #include <freerdp/settings.h>
25 #include "wf_defaults.h"
27 static PCWSTR ValidateString(
const BYTE* pb, ULONG cb)
32 if (cb %
sizeof(WCHAR) != 0)
38 static void AddDefaultSettings_I(rdpSettings* settings,
size_t idHostname,
size_t idUsername,
39 size_t idDomain,
size_t idPassword)
41 static const PSTR TERMSRV =
"TERMSRV/%s";
43 PSTR TargetName = NULL;
45 PWSTR TargetNameW = NULL;
46 PWSTR ServerHostNameW = NULL;
47 PWSTR ParsedUserNameW = NULL;
48 PWSTR ParsedDomainW = NULL;
49 PWSTR PasswordNullTerminatedW = NULL;
50 PCREDENTIALW Credential = { 0 };
60 if (bExistUserName && bExistPassword)
63 int len = _snprintf(TargetName, 0, TERMSRV, ServerHostname);
65 TargetName = (PSTR)malloc(len);
70 _snprintf(TargetName, len, TERMSRV, ServerHostname);
72 TargetName[len - 1] = 0;
74 TargetNameW = ConvertUtf8ToWCharAlloc(TargetName, NULL);
78 if (!CredReadW(TargetNameW, CRED_TYPE_GENERIC, 0, &Credential))
83 const WCHAR* PasswordW =
84 ValidateString(Credential->CredentialBlob, Credential->CredentialBlobSize);
86 PasswordNullTerminatedW = (PWSTR)calloc(Credential->CredentialBlobSize + 1,
sizeof(WCHAR));
88 if (!PasswordNullTerminatedW)
91 memcpy(PasswordNullTerminatedW, PasswordW, Credential->CredentialBlobSize *
sizeof(WCHAR));
93 if (PasswordNullTerminatedW)
96 PasswordNullTerminatedW))
105 const WCHAR* UserNameW = Credential->UserName;
109 ParsedUserNameW = calloc(CREDUI_MAX_USERNAME_LENGTH + 1,
sizeof(WCHAR));
110 if (!ParsedUserNameW)
113 ParsedDomainW = calloc(CREDUI_MAX_DOMAIN_TARGET_LENGTH + 1,
sizeof(WCHAR));
118 CredUIParseUserNameW(UserNameW, ParsedUserNameW, CREDUI_MAX_USERNAME_LENGTH + 1,
119 ParsedDomainW, CREDUI_MAX_DOMAIN_TARGET_LENGTH + 1);
121 if (ParseResult == NO_ERROR)
126 if (*ParsedDomainW != 0)
132 else if (ParseResult == ERROR_INVALID_ACCOUNT_NAME)
143 CredFree(Credential);
148 free(ServerHostNameW);
149 free(ParsedUserNameW);
151 free(PasswordNullTerminatedW);
155 void WINAPI AddDefaultSettings(rdpSettings* settings)
157 AddDefaultSettings_I(settings, FreeRDP_ServerHostname, FreeRDP_Username, FreeRDP_Domain,
159 AddDefaultSettings_I(settings, FreeRDP_GatewayHostname, FreeRDP_GatewayUsername,
160 FreeRDP_GatewayDomain, FreeRDP_GatewayPassword);
FREERDP_API const char * freerdp_settings_get_string(const rdpSettings *settings, FreeRDP_Settings_Keys_String id)
Returns a immutable string settings value.
FREERDP_API BOOL freerdp_settings_set_string_from_utf16(rdpSettings *settings, FreeRDP_Settings_Keys_String id, const WCHAR *param)
Sets a string settings value. The param is converted to UTF-8 and the copy stored.