From 13c025e04c908d38985f4b4aaa208634f87158a1 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Tue, 4 Apr 2023 15:24:04 +0200 Subject: [PATCH] [winpr,sspi] remove sspi_SetAuthIdentityWithUnicodePassword the function is useless as we always use the SetAuthIdentityW API now --- libfreerdp/core/nla.c | 17 ++++-- winpr/include/winpr/sspi.h | 3 -- winpr/libwinpr/sspi/sspi_winpr.c | 89 +++++++++++--------------------- 3 files changed, 43 insertions(+), 66 deletions(-) diff --git a/libfreerdp/core/nla.c b/libfreerdp/core/nla.c index 2f324f6d9..ad4270e3a 100644 --- a/libfreerdp/core/nla.c +++ b/libfreerdp/core/nla.c @@ -385,10 +385,19 @@ static BOOL nla_client_setup_identity(rdpNla* nla) if (settings->RedirectionPassword && (settings->RedirectionPasswordLength > 0)) { - if (sspi_SetAuthIdentityWithUnicodePassword( - nla->identity, settings->Username, settings->Domain, - (const WCHAR*)settings->RedirectionPassword, - settings->RedirectionPasswordLength / sizeof(WCHAR) - 1) < 0) + size_t userLength = 0; + size_t domainLength = 0; + WCHAR* user = + freerdp_settings_get_string_as_utf16(settings, FreeRDP_Username, &userLength); + WCHAR* domain = + freerdp_settings_get_string_as_utf16(settings, FreeRDP_Domain, &domainLength); + const int rc = sspi_SetAuthIdentityWithLengthW( + nla->identity, user, userLength, domain, domainLength, + (const WCHAR*)settings->RedirectionPassword, + settings->RedirectionPasswordLength / sizeof(WCHAR) - 1); + free(user); + free(domain); + if (rc < 0) return FALSE; usePassword = FALSE; diff --git a/winpr/include/winpr/sspi.h b/winpr/include/winpr/sspi.h index 617d6a27e..420fa29c0 100644 --- a/winpr/include/winpr/sspi.h +++ b/winpr/include/winpr/sspi.h @@ -1421,9 +1421,6 @@ extern "C" const WCHAR* user, size_t userLen, const WCHAR* domain, size_t domainLen, const WCHAR* password, size_t passwordLen); - WINPR_API int sspi_SetAuthIdentityWithUnicodePassword(SEC_WINNT_AUTH_IDENTITY* identity, - const char* user, const char* domain, - LPCWSTR password, ULONG passwordLength); WINPR_API UINT32 sspi_GetAuthIdentityVersion(const void* identity); WINPR_API UINT32 sspi_GetAuthIdentityFlags(const void* identity); WINPR_API BOOL sspi_GetAuthIdentityUserDomainW(const void* identity, const WCHAR** pUser, diff --git a/winpr/libwinpr/sspi/sspi_winpr.c b/winpr/libwinpr/sspi/sspi_winpr.c index c5920ce69..5283b7934 100644 --- a/winpr/libwinpr/sspi/sspi_winpr.c +++ b/winpr/libwinpr/sspi/sspi_winpr.c @@ -333,9 +333,9 @@ static BOOL copy(WCHAR** dst, UINT32* dstLen, const WCHAR* what, size_t len) { WINPR_ASSERT(dst); WINPR_ASSERT(dstLen); - WINPR_ASSERT(what); - WINPR_ASSERT(len > 0); - WINPR_ASSERT(_wcsnlen(what, len) == len); + + *dst = NULL; + *dstLen = 0; *dst = calloc(sizeof(WCHAR), len + 1); if (!*dst) @@ -353,75 +353,46 @@ int sspi_SetAuthIdentityWithLengthW(SEC_WINNT_AUTH_IDENTITY* identity, const WCH sspi_FreeAuthIdentity(identity); identity->Flags &= ~SEC_WINNT_AUTH_IDENTITY_ANSI; identity->Flags |= SEC_WINNT_AUTH_IDENTITY_UNICODE; - if (user && userLen > 0) - { - if (!copy(&identity->User, &identity->UserLength, user, userLen)) - return -1; - } - if (domain && domainLen > 0) - { - if (!copy(&identity->Domain, &identity->DomainLength, domain, domainLen)) - return -1; - } - if (password && passwordLen > 0) - { - if (!copy(&identity->Password, &identity->PasswordLength, password, passwordLen)) - return -1; - } + + if (!copy(&identity->User, &identity->UserLength, user, userLen)) + return -1; + + if (!copy(&identity->Domain, &identity->DomainLength, domain, domainLen)) + return -1; + + if (!copy(&identity->Password, &identity->PasswordLength, password, passwordLen)) + return -1; return 1; } +static void zfree(WCHAR* str, size_t len) +{ + if (str) + memset(str, 0, len * sizeof(WCHAR)); + free(str); +} + int sspi_SetAuthIdentityA(SEC_WINNT_AUTH_IDENTITY* identity, const char* user, const char* domain, const char* password) { + int rc; + size_t unicodeUserLenW = 0; + size_t unicodeDomainLenW = 0; size_t unicodePasswordLenW = 0; + LPWSTR unicodeUser = ConvertUtf8ToWCharAlloc(user, &unicodeUserLenW); + LPWSTR unicodeDomain = ConvertUtf8ToWCharAlloc(domain, &unicodeDomainLenW); LPWSTR unicodePassword = ConvertUtf8ToWCharAlloc(password, &unicodePasswordLenW); - const int rc = sspi_SetAuthIdentityWithUnicodePassword(identity, user, domain, unicodePassword, - (ULONG)(unicodePasswordLenW)); - free(unicodePassword); + rc = sspi_SetAuthIdentityWithLengthW(identity, unicodeUser, unicodeUserLenW, unicodeDomain, + unicodeDomainLenW, unicodePassword, unicodePasswordLenW); + + zfree(unicodeUser, unicodeUserLenW); + zfree(unicodeDomain, unicodeDomainLenW); + zfree(unicodePassword, unicodePasswordLenW); return rc; } -int sspi_SetAuthIdentityWithUnicodePassword(SEC_WINNT_AUTH_IDENTITY* identity, const char* user, - const char* domain, LPCWSTR password, - ULONG passwordLength) -{ - sspi_FreeAuthIdentity(identity); - identity->Flags &= ~SEC_WINNT_AUTH_IDENTITY_ANSI; - identity->Flags |= SEC_WINNT_AUTH_IDENTITY_UNICODE; - - if (user && (strlen(user) > 0)) - { - size_t len = 0; - identity->User = ConvertUtf8ToWCharAlloc(user, &len); - if (!identity->User || (len == 0) || (len > ULONG_MAX)) - return -1; - - identity->UserLength = (ULONG)len; - } - - if (domain && (strlen(domain) > 0)) - { - size_t len = 0; - identity->Domain = ConvertUtf8ToWCharAlloc(domain, &len); - if (!identity->Domain || (len == 0) || (len > ULONG_MAX)) - return -1; - - identity->DomainLength = len; - } - - identity->Password = (UINT16*)calloc(1, (passwordLength + 1) * sizeof(WCHAR)); - - if (!identity->Password) - return -1; - - CopyMemory(identity->Password, password, passwordLength * sizeof(WCHAR)); - identity->PasswordLength = passwordLength; - return 1; -} - UINT32 sspi_GetAuthIdentityVersion(const void* identity) { UINT32 version;