}\r
\r
LSA_UNICODE_STRING lsa_username;\r
-#ifdef UNICODE\r
- lsa_username.Buffer = (wchar_t *) expanded;\r
- lsa_username.Length = (unsigned short) _tcslen(expanded) * sizeof(TCHAR);\r
- lsa_username.MaximumLength = lsa_username.Length + sizeof(TCHAR);\r
-#else\r
- size_t buflen;\r
- mbstowcs_s(&buflen, NULL, 0, expanded, _TRUNCATE);\r
- lsa_username.MaximumLength = (unsigned short) buflen * sizeof(wchar_t);\r
- lsa_username.Length = lsa_username.MaximumLength - sizeof(wchar_t);\r
- lsa_username.Buffer = (wchar_t *) HeapAlloc(GetProcessHeap(), 0, lsa_username.MaximumLength);\r
- if (lsa_username.Buffer) mbstowcs_s(&buflen, lsa_username.Buffer, lsa_username.MaximumLength, expanded, _TRUNCATE);\r
- else {\r
+ int ret = to_utf16(expanded, &lsa_username.Buffer, (unsigned long *) &lsa_username.Length);\r
+ HeapFree(GetProcessHeap(), 0, expanded);\r
+ if (ret) {\r
if (policy == &handle) LsaClose(handle);\r
- HeapFree(GetProcessHeap(), 0, expanded);\r
print_message(stderr, NSSM_MESSAGE_OUT_OF_MEMORY, _T("LSA_UNICODE_STRING"), _T("username_sid()"));\r
return 4;\r
}\r
-#endif\r
+ lsa_username.Length *= sizeof(wchar_t);\r
+ lsa_username.MaximumLength = lsa_username.Length + sizeof(wchar_t);\r
\r
LSA_REFERENCED_DOMAIN_LIST *translated_domains;\r
LSA_TRANSLATED_SID *translated_sid;\r
NTSTATUS status = LsaLookupNames(*policy, 1, &lsa_username, &translated_domains, &translated_sid);\r
-#ifndef UNICODE\r
HeapFree(GetProcessHeap(), 0, lsa_username.Buffer);\r
-#endif\r
- HeapFree(GetProcessHeap(), 0, expanded);\r
if (policy == &handle) LsaClose(handle);\r
if (status != STATUS_SUCCESS) {\r
LsaFreeMemory(translated_domains);\r
else *sub = translated_sid->RelativeId;\r
}\r
\r
- int ret = 0;\r
+ ret = 0;\r
if (translated_sid->Use == SidTypeWellKnownGroup && ! well_known_sid(*sid)) {\r
print_message(stderr, NSSM_GUI_INVALID_USERNAME, username);\r
ret = 10;\r
memmove((char *) lsa_canon.Buffer + trust->Name.Length, L"\\", sizeof(wchar_t));\r
memmove((char *) lsa_canon.Buffer + trust->Name.Length + sizeof(wchar_t), translated_name->Name.Buffer, translated_name->Name.Length);\r
\r
-#ifdef UNICODE\r
- *canon = lsa_canon.Buffer;\r
-#else\r
- size_t buflen;\r
- wcstombs_s(&buflen, NULL, 0, lsa_canon.Buffer, _TRUNCATE);\r
- *canon = (TCHAR *) HeapAlloc(GetProcessHeap(), 0, buflen);\r
- if (! *canon) {\r
+ unsigned long canonlen;\r
+ if (from_utf16(lsa_canon.Buffer, canon, &canonlen)) {\r
LsaFreeMemory(translated_domains);\r
LsaFreeMemory(translated_name);\r
print_message(stderr, NSSM_MESSAGE_OUT_OF_MEMORY, _T("canon"), _T("username_sid"));\r
return 10;\r
}\r
- wcstombs_s(&buflen, *canon, buflen, lsa_canon.Buffer, _TRUNCATE);\r
HeapFree(GetProcessHeap(), 0, lsa_canon.Buffer);\r
-#endif\r
\r
LsaFreeMemory(translated_domains);\r
LsaFreeMemory(translated_name);\r
*error = GetLastError();\r
if (*error != ERROR_PROC_NOT_FOUND) {\r
TCHAR *function_name;\r
-#ifdef UNICODE\r
- size_t buflen;\r
- mbstowcs_s(&buflen, NULL, 0, function, _TRUNCATE);\r
- function_name = (TCHAR *) HeapAlloc(GetProcessHeap(), 0, buflen * sizeof(TCHAR));\r
- if (function_name) mbstowcs_s(&buflen, function_name, buflen * sizeof(TCHAR), function, _TRUNCATE);\r
-#else\r
- function_name = (TCHAR *) function;\r
-#endif\r
- log_event(EVENTLOG_WARNING_TYPE, NSSM_EVENT_GETPROCADDRESS_FAILED, function_name, error_string(*error), 0);\r
-#ifdef UNICODE\r
- if (function_name) HeapFree(GetProcessHeap(), 0, function_name);\r
-#endif\r
+ if (! from_utf8(function, &function_name, 0)) {\r
+ log_event(EVENTLOG_WARNING_TYPE, NSSM_EVENT_GETPROCADDRESS_FAILED, function_name, error_string(*error), 0);\r
+ HeapFree(GetProcessHeap(), 0, function_name);\r
+ }\r
}\r
}\r
\r