From 5489c6c955748d43c942009b7b93f0704607f80f Mon Sep 17 00:00:00 2001 From: Jeffrey Altman Date: Sun, 11 Jul 2004 21:56:27 +0000 Subject: [PATCH] unicode-strings-20040711 UNICODE_STRING buffers are measured by their length field; do not assume they are nul terminated --- src/WINNT/afsd/afslogon.c | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/WINNT/afsd/afslogon.c b/src/WINNT/afsd/afslogon.c index 8cb927031..1d24875bd 100644 --- a/src/WINNT/afsd/afslogon.c +++ b/src/WINNT/afsd/afslogon.c @@ -44,6 +44,7 @@ WSADATA WSAjunk; #define TRACE_OPTION_EVENT 1 #define ISLOGONTRACE(v) ( ((v) & TRACE_OPTION_EVENT)==TRACE_OPTION_EVENT) +#ifdef COMMENT /* Structure def copied from DDK (NTDEF.H) */ typedef struct UNICODE_STRING { USHORT Length; /* number of bytes of Buffer actually used */ @@ -58,6 +59,7 @@ typedef struct _MSV1_0_INTERACTIVE_LOGON { UNICODE_STRING UserName; UNICODE_STRING Password; } MSV1_0_INTERACTIVE_LOGON; +#endif /* * GetLogonScript @@ -311,6 +313,31 @@ BOOL IsServiceRunning (void) return (Status.dwCurrentState == SERVICE_RUNNING); } + +static BOOL +WINAPI +UnicodeStringToANSI(UNICODE_STRING uInputString, LPSTR lpszOutputString, int nOutStringLen) +{ + CPINFO CodePageInfo; + + GetCPInfo(CP_ACP, &CodePageInfo); + + if (CodePageInfo.MaxCharSize > 1) + // Only supporting non-Unicode strings + return FALSE; + + if (((LPBYTE) uInputString.Buffer)[1] == '\0') + { + // Looks like unicode, better translate it + // UNICODE_STRING specifies the length of the buffer string in Bytes not WCHARS + WideCharToMultiByte(CP_ACP, 0, (LPCWSTR) uInputString.Buffer, uInputString.Length/2, + lpszOutputString, nOutStringLen-1, NULL, NULL); + lpszOutputString[max(uInputString.Length/2,nOutStringLen-1)] = '\0'; + return TRUE; + } + return FALSE; +} // UnicodeStringToANSI + DWORD APIENTRY NPLogonNotify( PLUID lpLogonId, LPCWSTR lpAuthentInfoType, @@ -350,8 +377,8 @@ DWORD APIENTRY NPLogonNotify( interactive = (wcscmp(lpStationName, L"WinSta0") == 0); /* Convert from Unicode to ANSI */ - wcstombs(uname, IL->UserName.Buffer, 256); - wcstombs(password, IL->Password.Buffer, 256); + UnicodeStringToANSI(IL->UserName, uname, 256); + UnicodeStringToANSI(IL->Password, password, 256); /* Make sure AD-DOMANS sent from login that is sent to us is striped */ ctemp = strchr(uname, '@'); -- 2.39.5