GetComputerNameExA(ComputerNameNetBIOS, Workstation, &nSize);
}
- context->Workstation.Length = strlen(Workstation) * 2;
- context->Workstation.Buffer = (PWSTR) malloc(context->Workstation.Length);
- MultiByteToWideChar(CP_ACP, 0, Workstation, strlen(Workstation),
- context->Workstation.Buffer, context->Workstation.Length / 2);
+ context->Workstation.Length = ConvertToUnicode(CP_UTF8, 0,
+ Workstation, -1, &context->Workstation.Buffer, 0) - 1;
+ context->Workstation.Length *= 2;
if (nSize > 0)
free(Workstation);
void ntlm_SetContextServicePrincipalNameW(NTLM_CONTEXT* context, LPWSTR ServicePrincipalName)
{
- context->ServicePrincipalName.Length = lstrlenW(ServicePrincipalName) * 2;
+ context->ServicePrincipalName.Length = _wcslen(ServicePrincipalName) * 2;
context->ServicePrincipalName.Buffer = (PWSTR) malloc(context->ServicePrincipalName.Length);
CopyMemory(context->ServicePrincipalName.Buffer, ServicePrincipalName, context->ServicePrincipalName.Length);
}
void ntlm_SetContextServicePrincipalNameA(NTLM_CONTEXT* context, char* ServicePrincipalName)
{
- context->ServicePrincipalName.Length = strlen(ServicePrincipalName) * 2;
- context->ServicePrincipalName.Buffer = (PWSTR) malloc(context->ServicePrincipalName.Length);
- MultiByteToWideChar(CP_ACP, 0, ServicePrincipalName, strlen(ServicePrincipalName),
- context->ServicePrincipalName.Buffer, context->ServicePrincipalName.Length / 2);
+ context->ServicePrincipalName.Length = ConvertToUnicode(CP_UTF8, 0,
+ ServicePrincipalName, -1, &context->ServicePrincipalName.Buffer, 0) - 1;
+ context->ServicePrincipalName.Length *= 2;
}
void ntlm_SetContextTargetName(NTLM_CONTEXT* context, char* TargetName)
CharUpperA(TargetName);
}
- context->TargetName.cbBuffer = strlen(TargetName) * 2;
- context->TargetName.pvBuffer = (void*) malloc(context->TargetName.cbBuffer);
- MultiByteToWideChar(CP_ACP, 0, TargetName, strlen(TargetName),
- (LPWSTR) context->TargetName.pvBuffer, context->TargetName.cbBuffer / 2);
+ context->TargetName.cbBuffer = ConvertToUnicode(CP_UTF8, 0,
+ TargetName, -1, (LPWSTR*) &context->TargetName.pvBuffer, 0) - 1;
+ context->TargetName.cbBuffer *= 2;
if (nSize > 0)
free(TargetName);
PSecBufferDesc pInput, ULONG Reserved2, PCtxtHandle phNewContext,
PSecBufferDesc pOutput, PULONG pfContextAttr, PTimeStamp ptsExpiry)
{
- int length;
SECURITY_STATUS status;
SEC_WCHAR* pszTargetNameW = NULL;
if (pszTargetName != NULL)
{
- length = strlen(pszTargetName);
- pszTargetNameW = (PWSTR) malloc((length + 1) * 2);
- MultiByteToWideChar(CP_ACP, 0, pszTargetName, length, pszTargetNameW, length);
- pszTargetNameW[length] = 0;
+ ConvertToUnicode(CP_UTF8, 0, pszTargetName, -1, &pszTargetNameW, 0);
}
status = ntlm_InitializeSecurityContextW(phCredential, phContext, pszTargetNameW, fContextReq,
void ntlm_get_target_computer_name(PUNICODE_STRING pName, COMPUTER_NAME_FORMAT type)
{
char* name;
+ int length;
DWORD nSize = 0;
GetComputerNameExA(type, NULL, &nSize);
if (type == ComputerNameNetBIOS)
CharUpperA(name);
- pName->Length = strlen(name) * 2;
- pName->Buffer = (PWSTR) malloc(pName->Length);
- MultiByteToWideChar(CP_ACP, 0, name, strlen(name),
- (LPWSTR) pName->Buffer, pName->Length / 2);
+ length = ConvertToUnicode(CP_UTF8, 0, name, -1, &pName->Buffer, 0);
+ pName->Length = (length - 1) / 2;
pName->MaximumLength = pName->Length;
free(name);
if (user)
{
- identity->UserLength = MultiByteToWideChar(CP_UTF8, 0, user, strlen(user), NULL, 0);
- identity->User = (UINT16*) malloc((identity->UserLength + 1) * sizeof(WCHAR));
- MultiByteToWideChar(CP_UTF8, 0, user, identity->UserLength, (LPWSTR) identity->User, identity->UserLength * sizeof(WCHAR));
- identity->User[identity->UserLength] = 0;
+ identity->UserLength = ConvertToUnicode(CP_UTF8, 0, user, -1, &identity->User, 0) - 1;
}
else
{
if (domain)
{
- identity->DomainLength = MultiByteToWideChar(CP_UTF8, 0, domain, strlen(domain), NULL, 0);
- identity->Domain = (UINT16*) malloc((identity->DomainLength + 1) * sizeof(WCHAR));
- MultiByteToWideChar(CP_UTF8, 0, domain, identity->DomainLength, (LPWSTR) identity->Domain, identity->DomainLength * sizeof(WCHAR));
- identity->Domain[identity->DomainLength] = 0;
+ identity->DomainLength = ConvertToUnicode(CP_UTF8, 0, domain, -1, &identity->Domain, 0) - 1;
}
else
{
if (password != NULL)
{
- identity->PasswordLength = MultiByteToWideChar(CP_UTF8, 0, password, strlen(password), NULL, 0);
- identity->Password = (UINT16*) malloc((identity->PasswordLength + 1) * sizeof(WCHAR));
- MultiByteToWideChar(CP_UTF8, 0, password, identity->PasswordLength, (LPWSTR) identity->Password, identity->PasswordLength * sizeof(WCHAR));
- identity->Password[identity->PasswordLength] = 0;
+ identity->PasswordLength = ConvertToUnicode(CP_UTF8, 0, password, -1, &identity->Password, 0) - 1;
}
else
{
SecurityFunctionTableW* sspi_GetSecurityFunctionTableWByNameA(const SEC_CHAR* Name)
{
- int length;
SEC_WCHAR* NameW;
SecurityFunctionTableW* table;
- length = strlen(Name);
- NameW = (SEC_WCHAR*) malloc((length + 1) * 2);
- MultiByteToWideChar(CP_ACP, 0, Name, length, (LPWSTR) NameW, length);
- NameW[length] = 0;
+ ConvertToUnicode(CP_UTF8, 0, Name, -1, &NameW, 0);
table = sspi_GetSecurityFunctionTableWByNameW(NameW);
free(NameW);