Changeset 66109 in vbox
- Timestamp:
- Mar 15, 2017 10:52:42 AM (8 years ago)
- Location:
- trunk/src/VBox/Additions/WINNT/VBoxCredProv
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/WINNT/VBoxCredProv/VBoxCredProvCredential.cpp
r63476 r66109 5 5 6 6 /* 7 * Copyright (C) 2012-201 6Oracle Corporation7 * Copyright (C) 2012-2017 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 126 126 { 127 127 AssertPtrReturn(pUnicodeDest, E_POINTER); 128 AssertPtrReturn(pwszSource, E_POINTER);128 AssertPtrReturn(pwszSource, E_POINTER); 129 129 130 130 size_t cbLen = RTUtf16Len(pwszSource) * sizeof(RTUTF16); … … 155 155 156 156 157 HRESULT VBoxCredProvCredential::kerberosLogonInit(KERB_INTERACTIVE_LOGON *pLogonIn, 158 CREDENTIAL_PROVIDER_USAGE_SCENARIO enmUsage, 159 PRTUTF16 pwszUser, PRTUTF16 pwszPassword, PRTUTF16 pwszDomain) 160 { 161 AssertPtrReturn(pLogonIn, E_INVALIDARG); 157 /** 158 * Copies an UTF16 string into a PUNICODE_STRING by allocating space for it. 159 * 160 * @return HRESULT 161 * @param pUnicodeDest Where to store the copied (allocated) unicode string. 162 * @param pwszSource UTF16 string to copy. 163 */ 164 HRESULT VBoxCredProvCredential::RTUTF16ToUnicodeA(PUNICODE_STRING pUnicodeDest, PRTUTF16 pwszSource) 165 { 166 AssertPtrReturn(pUnicodeDest, E_POINTER); 167 AssertPtrReturn(pwszSource, E_POINTER); 168 169 size_t cbLen = (RTUtf16Len(pwszSource) + 1 /* Trailing zero */) * sizeof(WCHAR); 170 171 pUnicodeDest->Buffer = (LPWSTR)CoTaskMemAlloc(cbLen); 172 173 if (!pUnicodeDest->Buffer) 174 return E_OUTOFMEMORY; 175 176 pUnicodeDest->MaximumLength = (USHORT)cbLen; 177 pUnicodeDest->Length = 0; 178 179 return RTUTF16ToUnicode(pUnicodeDest, pwszSource, true /* fCopy */); 180 } 181 182 183 /** 184 * Frees a formerly allocated PUNICODE_STRING. 185 * 186 * @param pUnicode String to free. 187 */ 188 void VBoxCredProvCredential::UnicodeStringFree(PUNICODE_STRING pUnicode) 189 { 190 if (!pUnicode) 191 return; 192 193 if (pUnicode->Buffer) 194 { 195 Assert(pUnicode->MaximumLength); 196 197 /* Make sure to wipe contents before free'ing. */ 198 RTMemWipeThoroughly(pUnicode->Buffer, pUnicode->MaximumLength * sizeof(WCHAR), 3 /* Passes */); 199 200 CoTaskMemFree(pUnicode->Buffer); 201 pUnicode->Buffer = NULL; 202 } 203 204 pUnicode->Length = 0; 205 pUnicode->MaximumLength = 0; 206 } 207 208 209 /** 210 * Creates a KERB_INTERACTIVE_LOGON structure with the given parameters. 211 * Must be destroyed with kerberosLogonDestroy(). 212 * 213 * @return HRESULT 214 * @param pLogon Structure to create. 215 * @param enmUsage Intended usage of the structure. 216 * @param pwszUser User name to use. 217 * @param pwszPassword Password to use. 218 * @param pwszDomain Domain to use. Optional and can be NULL. 219 */ 220 HRESULT VBoxCredProvCredential::kerberosLogonCreate(KERB_INTERACTIVE_LOGON *pLogon, 221 CREDENTIAL_PROVIDER_USAGE_SCENARIO enmUsage, 222 PRTUTF16 pwszUser, PRTUTF16 pwszPassword, PRTUTF16 pwszDomain) 223 { 224 AssertPtrReturn(pLogon, E_INVALIDARG); 162 225 AssertPtrReturn(pwszUser, E_INVALIDARG); 163 226 AssertPtrReturn(pwszPassword, E_INVALIDARG); … … 170 233 && RTUtf16Len(pwszDomain)) 171 234 { 172 hr = RTUTF16ToUnicode (&pLogonIn->LogonDomainName, pwszDomain, true /* fCopy */);235 hr = RTUTF16ToUnicodeA(&pLogon->LogonDomainName, pwszDomain); 173 236 } 174 237 else /* No domain (FQDN) given, try local computer name. */ … … 179 242 { 180 243 /* Is a domain name missing? Then use the name of the local computer. */ 181 hr = RTUTF16ToUnicode (&pLogonIn->LogonDomainName, wszComputerName, true /* fCopy */);244 hr = RTUTF16ToUnicodeA(&pLogon->LogonDomainName, wszComputerName); 182 245 183 246 VBoxCredProvVerbose(0, "VBoxCredProvCredential::kerberosLogonInit: Local computer name=%ls\n", … … 191 254 if (SUCCEEDED(hr)) 192 255 { 193 hr = RTUTF16ToUnicode (&pLogonIn->UserName, pwszUser, true /* fCopy */);256 hr = RTUTF16ToUnicodeA(&pLogon->UserName, pwszUser); 194 257 if (SUCCEEDED(hr)) 195 258 { 196 hr = RTUTF16ToUnicode (&pLogonIn->Password, pwszPassword, true /* fCopy */);259 hr = RTUTF16ToUnicodeA(&pLogon->Password, pwszPassword); 197 260 if (SUCCEEDED(hr)) 198 261 { … … 201 264 { 202 265 case CPUS_UNLOCK_WORKSTATION: 203 pLogon In->MessageType = KerbWorkstationUnlockLogon;266 pLogon->MessageType = KerbWorkstationUnlockLogon; 204 267 break; 205 268 206 269 case CPUS_LOGON: 207 pLogon In->MessageType = KerbInteractiveLogon;270 pLogon->MessageType = KerbInteractiveLogon; 208 271 break; 209 272 210 273 case CPUS_CREDUI: 211 pLogon In->MessageType = (KERB_LOGON_SUBMIT_TYPE)0; /* No message type required here. */274 pLogon->MessageType = (KERB_LOGON_SUBMIT_TYPE)0; /* No message type required here. */ 212 275 break; 213 276 … … 223 286 224 287 return hr; 288 } 289 290 291 /** 292 * Destroys a formerly created KERB_INTERACTIVE_LOGON structure. 293 * 294 * @param pLogon Structure to destroy. 295 */ 296 void VBoxCredProvCredential::kerberosLogonDestroy(KERB_INTERACTIVE_LOGON *pLogon) 297 { 298 if (!pLogon) 299 return; 300 301 UnicodeStringFree(&pLogon->UserName); 302 UnicodeStringFree(&pLogon->Password); 303 UnicodeStringFree(&pLogon->LogonDomainName); 225 304 } 226 305 … … 908 987 /* Save a pointer to the interactive logon struct. */ 909 988 KERB_INTERACTIVE_LOGON *pLogon = &KerberosUnlockLogon.Logon; 910 AssertPtr(pLogon);911 989 912 990 #ifdef DEBUG /* Note: NEVER print this in release mode! */ … … 917 995 #endif 918 996 919 HRESULT hr = kerberosLogon Init(pLogon,920 m_enmUsageScenario,921 m_apwszCredentials[VBOXCREDPROV_FIELDID_USERNAME],922 m_apwszCredentials[VBOXCREDPROV_FIELDID_PASSWORD],923 m_apwszCredentials[VBOXCREDPROV_FIELDID_DOMAINNAME]);997 HRESULT hr = kerberosLogonCreate(pLogon, 998 m_enmUsageScenario, 999 m_apwszCredentials[VBOXCREDPROV_FIELDID_USERNAME], 1000 m_apwszCredentials[VBOXCREDPROV_FIELDID_PASSWORD], 1001 m_apwszCredentials[VBOXCREDPROV_FIELDID_DOMAINNAME]); 924 1002 if (SUCCEEDED(hr)) 925 1003 { … … 973 1051 else 974 1052 VBoxCredProvVerbose(1, "VBoxCredProvCredential::GetSerialization: kerberosLogonSerialize failed with hr=0x%08x\n", hr); 1053 1054 kerberosLogonDestroy(pLogon); 1055 pLogon = NULL; 975 1056 } 976 1057 else 977 VBoxCredProvVerbose(1, "VBoxCredProvCredential::GetSerialization: kerberosLogon Initfailed with hr=0x%08x\n", hr);1058 VBoxCredProvVerbose(1, "VBoxCredProvCredential::GetSerialization: kerberosLogonCreate failed with hr=0x%08x\n", hr); 978 1059 979 1060 VBoxCredProvVerbose(0, "VBoxCredProvCredential::GetSerialization returned hr=0x%08x\n", hr); -
trunk/src/VBox/Additions/WINNT/VBoxCredProv/VBoxCredProvCredential.h
r63476 r66109 5 5 6 6 /* 7 * Copyright (C) 2012-201 6Oracle Corporation7 * Copyright (C) 2012-2017 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 95 95 protected: 96 96 HRESULT RTUTF16ToUnicode(PUNICODE_STRING pUnicodeDest, PRTUTF16 pwszSource, bool fCopy); 97 HRESULT kerberosLogonInit(KERB_INTERACTIVE_LOGON *pLogonIn, 98 CREDENTIAL_PROVIDER_USAGE_SCENARIO enmUsage, 99 PRTUTF16 pwszUser, PRTUTF16 pwszPassword, PRTUTF16 pwszDomain); 97 HRESULT RTUTF16ToUnicodeA(PUNICODE_STRING pUnicodeDest, PRTUTF16 pwszSource); 98 void UnicodeStringFree(PUNICODE_STRING pUnicode); 99 100 HRESULT kerberosLogonCreate(KERB_INTERACTIVE_LOGON *pLogon, 101 CREDENTIAL_PROVIDER_USAGE_SCENARIO enmUsage, 102 PRTUTF16 pwszUser, PRTUTF16 pwszPassword, PRTUTF16 pwszDomain); 103 void kerberosLogonDestroy(KERB_INTERACTIVE_LOGON *pLogon); 100 104 HRESULT kerberosLogonSerialize(const KERB_INTERACTIVE_LOGON *pLogon, PBYTE *ppPackage, DWORD *pcbPackage); 101 105
Note:
See TracChangeset
for help on using the changeset viewer.