Changeset 58388 in vbox for trunk/src/VBox/HostServices/auth/winlogon
- Timestamp:
- Oct 23, 2015 11:19:58 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostServices/auth/winlogon/winlogon.cpp
r35943 r58388 6 6 7 7 /* 8 * Copyright (C) 2006-201 1Oracle Corporation8 * Copyright (C) 2006-2015 Oracle Corporation 9 9 * 10 10 * This file is part of VirtualBox Open Source Edition (OSE), as … … 17 17 */ 18 18 19 /* If defined, debug messages will be written to the specified file. */ 20 // #define AUTH_DEBUG_FILE_NAME "\\VBoxAuth.log" 21 22 #include <stdio.h> 23 #include <string.h> 19 /* If defined, debug messages will be written to the debugger. */ 20 // #define AUTH_DEBUG 24 21 25 22 #include <Windows.h> … … 27 24 #include <VBox/VBoxAuth.h> 28 25 29 static void dprintf(const char *fmt, ...) 26 #ifdef AUTH_DEBUG 27 #include <stdio.h> 28 29 static void dprintfw(const WCHAR *fmt, ...) 30 30 { 31 #ifdef AUTH_DEBUG_FILE_NAME32 31 va_list va; 33 34 32 va_start(va, fmt); 35 33 36 charbuffer[1024];34 WCHAR buffer[1024]; 37 35 38 _vsn printf(buffer, sizeof (buffer), fmt, va);36 _vsnwprintf(buffer, sizeof (buffer), fmt, va); 39 37 40 OutputDebugString A(buffer);38 OutputDebugStringW(buffer); 41 39 42 FILE *f = fopen (AUTH_DEBUG_FILE_NAME, "ab");43 if (f) 44 { 45 fprintf (f, "%s", buffer); 46 fclose (f); 47 } 40 va_end(va); 41 } 42 #define DBGAUTH(a) dprintfw a 43 #else 44 #define DBGAUTH(a) 45 #endif 48 46 49 va_end (va); 50 #endif 47 static WCHAR swszEmpty[] = { L"" }; 48 49 static void freeWideChar(WCHAR *pwszString) 50 { 51 if (pwszString && pwszString != &swszEmpty[0]) 52 { 53 size_t cb = (wcslen(pwszString) + 1) * sizeof(WCHAR); 54 SecureZeroMemory(pwszString, cb); 55 free(pwszString); 56 } 57 } 58 59 static WCHAR *utf8ToWideChar(const char *pszString) 60 { 61 /* 62 * Shortcut for empty strings. 63 */ 64 if (!pszString || *pszString == 0) 65 return &swszEmpty[0]; 66 67 /* 68 * Return NULL on errors. 69 */ 70 WCHAR *pwszString = NULL; 71 72 /* 73 * First calc result string length. 74 */ 75 const DWORD dwFlags = MB_ERR_INVALID_CHARS; 76 int cwc = MultiByteToWideChar(CP_UTF8, dwFlags, pszString, -1, NULL, 0); 77 if (cwc > 0) 78 { 79 /* 80 * Alloc space for result buffer. 81 */ 82 pwszString = (WCHAR *)malloc(cwc * sizeof(WCHAR)); 83 if (pwszString) 84 { 85 /* 86 * Do the translation. 87 */ 88 if (MultiByteToWideChar(CP_UTF8, dwFlags, pszString, -1, pwszString, cwc) <= 0) 89 { 90 /* translation error */ 91 free(pwszString); 92 pwszString = NULL; 93 } 94 } 95 } 96 97 return pwszString; 51 98 } 52 99 … … 64 111 unsigned clientId) 65 112 { 113 if (!fLogon) 114 { 115 /* Nothing to cleanup. The return code does not matter. */ 116 return AuthResultAccessDenied; 117 } 118 119 LPWSTR lpwszUsername = utf8ToWideChar(szUser); 120 LPWSTR lpwszDomain = utf8ToWideChar(szDomain); 121 LPWSTR lpwszPassword = utf8ToWideChar(szPassword); 122 123 DBGAUTH((L"u[%ls], d[%ls], p[%ls]\n", lpwszUsername, lpwszDomain, lpwszPassword)); 124 66 125 AuthResult result = AuthResultAccessDenied; 67 126 68 LPTSTR lpszUsername = (char *)szUser; 69 LPTSTR lpszDomain = (char *)szDomain; 70 LPTSTR lpszPassword = (char *)szPassword; 127 if (lpwszUsername && lpwszDomain && lpwszPassword) 128 { 129 /* LOGON32_LOGON_INTERACTIVE is intended for users who will be interactively using the computer, 130 * such as a user being logged on by a terminal server, remote shell, or similar process. 131 */ 132 DWORD dwLogonType = LOGON32_LOGON_INTERACTIVE; 133 DWORD dwLogonProvider = LOGON32_PROVIDER_DEFAULT; 71 134 72 /* LOGON32_LOGON_INTERACTIVE is intended for users who will be interactively using the computer, 73 * such as a user being logged on by a terminal server, remote shell, or similar process. 74 */ 75 DWORD dwLogonType = LOGON32_LOGON_INTERACTIVE; 76 DWORD dwLogonProvider = LOGON32_PROVIDER_DEFAULT; 135 HANDLE hToken; 77 136 78 HANDLE hToken; 137 BOOL fSuccess = LogonUserW(lpwszUsername, 138 lpwszDomain, 139 lpwszPassword, 140 dwLogonType, 141 dwLogonProvider, 142 &hToken); 79 143 80 dprintf("u[%s], d[%s], p[%s]\n", lpszUsername, lpszDomain, lpszPassword); 144 if (fSuccess) 145 { 146 DBGAUTH((L"LogonUser success. hToken = %p\n", hToken)); 81 147 82 BOOL fSuccess = LogonUser(lpszUsername, 83 lpszDomain, 84 lpszPassword, 85 dwLogonType, 86 dwLogonProvider, 87 &hToken); 148 result = AuthResultAccessGranted; 88 149 89 if (fSuccess) 90 { 91 dprintf("LogonUser success. hToken = %p\n", hToken); 150 CloseHandle(hToken); 151 } 152 else 153 { 154 DBGAUTH((L"LogonUser failed %08X\n", GetLastError())); 155 } 156 } 92 157 93 result = AuthResultAccessGranted; 94 95 CloseHandle (hToken); 96 } 97 else 98 { 99 dprintf("LogonUser failed %08X\n", GetLastError ()); 100 } 158 freeWideChar(lpwszUsername); 159 freeWideChar(lpwszDomain); 160 freeWideChar(lpwszPassword); 101 161 102 162 return result;
Note:
See TracChangeset
for help on using the changeset viewer.