Changeset 40393 in vbox for trunk/src/VBox/Additions/WINNT
- Timestamp:
- Mar 7, 2012 2:41:37 PM (13 years ago)
- Location:
- trunk/src/VBox/Additions/WINNT/VBoxCredProv
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/WINNT/VBoxCredProv/VBoxCredProvCredential.cpp
r40348 r40393 30 30 #include <lm.h> 31 31 32 #include <iprt/initterm.h> 32 33 #include <iprt/mem.h> 33 34 #include <iprt/string.h> … … 35 36 36 37 37 VBoxCredProvCredential::VBoxCredProvCredential(VBoxCredProvProvider *pProvider) : 38 VBoxCredProvCredential::VBoxCredProvCredential(void) : 39 m_cpUS(CPUS_INVALID), 38 40 m_cRefCount(1), 39 41 m_pEvents(NULL) 40 42 { 41 VBoxCredProvVerbose(0, "VBoxCredProvCredential: Created, pProvider=%p\n", 42 pProvider); 43 VBoxCredProvVerbose(0, "VBoxCredProvCredential: Created\n"); 43 44 44 45 VBoxCredentialProviderAcquire(); 45 46 46 AssertPtr(pProvider); 47 m_pProvider = pProvider; 48 49 ZeroMemory(m_pwszCredentials, sizeof(m_pwszCredentials)); 47 ZeroMemory(m_pwszCredentials, sizeof(PRTUTF16) * VBOXCREDPROV_NUM_FIELDS); 50 48 } 51 49 … … 54 52 { 55 53 VBoxCredProvVerbose(0, "VBoxCredProvCredential: Destroying\n"); 54 55 Reset(); 56 56 57 57 VBoxCredentialProviderRelease(); … … 62 62 ULONG VBoxCredProvCredential::AddRef(void) 63 63 { 64 VBoxCredProvVerbose(0, "VBoxCredProvCredential: Increasing reference to %ld\n",65 m_cRefCount + 1);66 67 return m_cRefCount++;64 LONG cRefCount = InterlockedIncrement(&m_cRefCount); 65 VBoxCredProvVerbose(0, "VBoxCredProvCredential::AddRef: Returning refcount=%ld\n", 66 cRefCount); 67 return cRefCount; 68 68 } 69 69 … … 71 71 ULONG VBoxCredProvCredential::Release(void) 72 72 { 73 Assert(m_cRefCount); 74 75 ULONG cRefCount = --m_cRefCount; 76 VBoxCredProvVerbose(0, "VBoxCredProvCredential: Decreasing reference to %ld\n", 73 LONG cRefCount = InterlockedDecrement(&m_cRefCount); 74 VBoxCredProvVerbose(0, "VBoxCredProvCredential::Release: Returning refcount=%ld\n", 77 75 cRefCount); 78 76 if (!cRefCount) … … 127 125 bool fCopy) 128 126 { 127 AssertPtrReturn(pUnicodeDest, VERR_INVALID_POINTER); 129 128 AssertPtrReturn(pwszSource, VERR_INVALID_POINTER); 130 AssertPtrReturn(pUnicodeDest, VERR_INVALID_POINTER);131 129 132 130 size_t cbLen = RTUtf16Len(pwszSource) * sizeof(RTUTF16); … … 165 163 166 164 #ifdef DEBUG 167 VBoxCredProvVerbose(3, "VBoxCredProvCredential: 165 VBoxCredProvVerbose(3, "VBoxCredProvCredential::AllocateLogonPackage: Allocating %ld bytes (%d bytes credentials)\n", 168 166 cbLogon, cbLogon - sizeof(KERB_INTERACTIVE_UNLOCK_LOGON)); 169 167 #endif … … 207 205 208 206 209 void VBoxCredProvCredential::Reset(void) 210 { 211 VBoxCredProvVerbose(0, "VBoxCredProvCredential: Wiping credentials ...\n"); 207 HRESULT VBoxCredProvCredential::Reset(void) 208 { 209 210 VBoxCredProvVerbose(0, "VBoxCredProvCredential::Reset: Wiping credentials user=%ls, pw=%ls, domain=%ls\n", 211 m_pwszCredentials[VBOXCREDPROV_FIELDID_USERNAME], 212 #ifdef DEBUG 213 m_pwszCredentials[VBOXCREDPROV_FIELDID_PASSWORD], 214 #else 215 L"XXX" /* Don't show any passwords in release mode. */, 216 #endif 217 m_pwszCredentials[VBOXCREDPROV_FIELDID_DOMAINNAME]); 212 218 213 219 VbglR3CredentialsDestroyUtf16(m_pwszCredentials[VBOXCREDPROV_FIELDID_USERNAME], … … 215 221 m_pwszCredentials[VBOXCREDPROV_FIELDID_DOMAINNAME], 216 222 3 /* Passes */); 223 HRESULT hr = S_OK; 217 224 if (m_pEvents) 218 225 { 219 m_pEvents->SetFieldString(this, VBOXCREDPROV_FIELDID_USERNAME, NULL); 220 m_pEvents->SetFieldString(this, VBOXCREDPROV_FIELDID_PASSWORD, NULL); 221 m_pEvents->SetFieldString(this, VBOXCREDPROV_FIELDID_DOMAINNAME, NULL); 222 } 226 /* Note: On Windows 8, set "this" to "nullptr". */ 227 HRESULT hr2 = m_pEvents->SetFieldString(this, VBOXCREDPROV_FIELDID_USERNAME, L""); 228 if (SUCCEEDED(hr)) 229 hr = hr2; 230 hr2 = m_pEvents->SetFieldString(this, VBOXCREDPROV_FIELDID_PASSWORD, L""); 231 if (SUCCEEDED(hr)) 232 hr = hr2; 233 hr2 = m_pEvents->SetFieldString(this, VBOXCREDPROV_FIELDID_DOMAINNAME, L""); 234 if (SUCCEEDED(hr)) 235 hr = hr2; 236 } 237 238 VBoxCredProvVerbose(0, "VBoxCredProvCredential::Reset: Returned hr=%08x\n", hr); 239 return hr; 223 240 } 224 241 … … 240 257 &m_pwszCredentials[VBOXCREDPROV_FIELDID_DOMAINNAME]); 241 258 242 VBoxCredProvVerbose(0, "VBoxCredProvCredential: Retrieving credentials returnedrc=%Rrc\n", rc);259 VBoxCredProvVerbose(0, "VBoxCredProvCredential::RetrieveCredentials: Retrieved credentials with rc=%Rrc\n", rc); 243 260 } 244 261 245 262 if (RT_SUCCESS(rc)) 246 263 { 247 VBoxCredProvVerbose(0, "VBoxCredProvCredential: Got credentials: User=%ls, Password=%ls, Domain=%ls\n",264 VBoxCredProvVerbose(0, "VBoxCredProvCredential::RetrieveCredentials: User=%ls, Password=%ls, Domain=%ls\n", 248 265 m_pwszCredentials[VBOXCREDPROV_FIELDID_USERNAME], 249 266 #ifdef DEBUG … … 262 279 if (TranslateAccountName(m_pwszCredentials[VBOXCREDPROV_FIELDID_USERNAME], &pwszAcount)) 263 280 { 264 VBoxCredProvVerbose(0, "VBoxCredProvCredential: Translated account name %ls -> %ls\n",281 VBoxCredProvVerbose(0, "VBoxCredProvCredential::RetrieveCredentials: Translated account name %ls -> %ls\n", 265 282 m_pwszCredentials[VBOXCREDPROV_FIELDID_USERNAME], pwszAcount); 266 283 267 RTUtf16Free(m_pwszCredentials[VBOXCREDPROV_FIELDID_USERNAME]); 284 if (m_pwszCredentials[VBOXCREDPROV_FIELDID_USERNAME]) 285 { 286 RTMemWipeThoroughly(m_pwszCredentials[VBOXCREDPROV_FIELDID_USERNAME], 287 RTUtf16Len(m_pwszCredentials[VBOXCREDPROV_FIELDID_USERNAME]) + sizeof(RTUTF16), 3 /* Passes */); 288 RTUtf16Free(m_pwszCredentials[VBOXCREDPROV_FIELDID_USERNAME]); 289 } 268 290 m_pwszCredentials[VBOXCREDPROV_FIELDID_USERNAME] = pwszAcount; 269 291 } … … 281 303 { 282 304 /* Update user name. */ 283 RTUtf16Free(m_pwszCredentials[VBOXCREDPROV_FIELDID_USERNAME]); 305 if (m_pwszCredentials[VBOXCREDPROV_FIELDID_USERNAME]) 306 { 307 RTMemWipeThoroughly(m_pwszCredentials[VBOXCREDPROV_FIELDID_USERNAME], 308 RTUtf16Len(m_pwszCredentials[VBOXCREDPROV_FIELDID_USERNAME]) + sizeof(RTUTF16), 3 /* Passes */); 309 RTUtf16Free(m_pwszCredentials[VBOXCREDPROV_FIELDID_USERNAME]); 310 } 284 311 m_pwszCredentials[VBOXCREDPROV_FIELDID_USERNAME] = pwszAcount; 285 312 286 313 /* Update domain. */ 287 RTUtf16Free(m_pwszCredentials[VBOXCREDPROV_FIELDID_DOMAINNAME]); 314 if (m_pwszCredentials[VBOXCREDPROV_FIELDID_DOMAINNAME]) 315 { 316 RTMemWipeThoroughly(m_pwszCredentials[VBOXCREDPROV_FIELDID_DOMAINNAME], 317 RTUtf16Len(m_pwszCredentials[VBOXCREDPROV_FIELDID_DOMAINNAME]) + sizeof(RTUTF16), 3 /* Passes */); 318 RTUtf16Free(m_pwszCredentials[VBOXCREDPROV_FIELDID_DOMAINNAME]); 319 } 288 320 m_pwszCredentials[VBOXCREDPROV_FIELDID_DOMAINNAME] = pwszDomain; 289 321 290 VBoxCredProvVerbose(0, "VBoxCredProvCredential: Extracted account data is pwszAccount=%ls, pwszDomain=%ls\n", 291 pwszAcount, pwszDomain); 322 VBoxCredProvVerbose(0, "VBoxCredProvCredential::RetrieveCredentials: Extracted account data pwszAccount=%ls, pwszDomain=%ls\n", 323 m_pwszCredentials[VBOXCREDPROV_FIELDID_USERNAME], 324 m_pwszCredentials[VBOXCREDPROV_FIELDID_DOMAINNAME]); 292 325 } 293 326 } 294 327 } 295 328 296 VBoxCredProvVerbose(0, "VBoxCredProvCredential: Checking credentials returned withrc=%Rrc\n", rc);329 VBoxCredProvVerbose(0, "VBoxCredProvCredential::RetrieveCredentials: Returned rc=%Rrc\n", rc); 297 330 return rc; 298 331 } … … 306 339 HRESULT VBoxCredProvCredential::Initialize(CREDENTIAL_PROVIDER_USAGE_SCENARIO cpUS) 307 340 { 308 VBoxCredProvVerbose(0, "VBoxCredProvCredential: 341 VBoxCredProvVerbose(0, "VBoxCredProvCredential::Initialize: cpUS=%ld\n", cpUS); 309 342 310 343 m_cpUS = cpUS; … … 318 351 * Store this callback pointer for later use. 319 352 */ 320 HRESULT VBoxCredProvCredential::Advise(ICredentialProviderCredentialEvents* pcpce) 321 { 322 VBoxCredProvVerbose(0, "VBoxCredProvCredential: Advise\n"); 323 324 if (m_pEvents != NULL) 353 HRESULT VBoxCredProvCredential::Advise(ICredentialProviderCredentialEvents *pEvents) 354 { 355 VBoxCredProvVerbose(0, "VBoxCredProvCredential::Advise: pEvents=0x%p\n", 356 pEvents); 357 358 if (m_pEvents) 359 { 325 360 m_pEvents->Release(); 326 m_pEvents = pcpce; 327 m_pEvents->AddRef(); 361 m_pEvents = NULL; 362 } 363 364 m_pEvents = pEvents; 365 if (m_pEvents) 366 m_pEvents->AddRef(); 367 328 368 return S_OK; 329 369 } … … 333 373 HRESULT VBoxCredProvCredential::UnAdvise(void) 334 374 { 335 VBoxCredProvVerbose(0, "VBoxCredProvCredential: UnAdvise\n"); 336 337 /* 338 * We're done with the current iteration, trigger a refresh of ourselves 339 * to reset credentials and to keep the logon UI clean (no stale entries anymore). 340 */ 341 Reset(); 342 343 /* 344 * Force a re-iteration of the provider (which will give zero credentials 345 * to try out because we just reset our one and only a line above. 346 */ 347 if (m_pProvider) 348 m_pProvider->OnCredentialsProvided(); 375 VBoxCredProvVerbose(0, "VBoxCredProvCredential::UnAdvise\n"); 349 376 350 377 if (m_pEvents) 378 { 351 379 m_pEvents->Release(); 352 m_pEvents = NULL; 380 m_pEvents = NULL; 381 } 382 353 383 return S_OK; 354 384 } … … 363 393 * selected, you would do it here. 364 394 */ 365 HRESULT VBoxCredProvCredential::SetSelected(BOOL *pbAutoLogon)366 { 367 VBoxCredProvVerbose(0, "VBoxCredProvCredential: 395 HRESULT VBoxCredProvCredential::SetSelected(BOOL *pbAutoLogon) 396 { 397 VBoxCredProvVerbose(0, "VBoxCredProvCredential::SetSelected\n"); 368 398 369 399 /* … … 372 402 * winlogon wait before new login attempts can be made. 373 403 */ 374 *pbAutoLogon = FALSE; 404 if (pbAutoLogon) 405 *pbAutoLogon = FALSE; 375 406 return S_OK; 376 407 } … … 382 413 * is to clear out the password field. 383 414 */ 384 HRESULT VBoxCredProvCredential::SetDeselected() 385 { 386 VBoxCredProvVerbose(0, "VBoxCredProvCredential: SetDeselected\n"); 387 388 VbglR3CredentialsDestroyUtf16(m_pwszCredentials[VBOXCREDPROV_FIELDID_USERNAME], 389 m_pwszCredentials[VBOXCREDPROV_FIELDID_PASSWORD], 390 m_pwszCredentials[VBOXCREDPROV_FIELDID_DOMAINNAME], 391 3 /* Passes */); 415 HRESULT VBoxCredProvCredential::SetDeselected(void) 416 { 417 VBoxCredProvVerbose(0, "VBoxCredProvCredential::SetDeselected\n"); 418 419 Reset(); 392 420 393 421 if (m_pEvents) … … 406 434 CREDENTIAL_PROVIDER_FIELD_INTERACTIVE_STATE* pFieldstateInteractive) 407 435 { 408 VBoxCredProvVerbose(0, "VBoxCredProvCredential: 436 VBoxCredProvVerbose(0, "VBoxCredProvCredential::GetFieldState: dwFieldID=%ld\n", dwFieldID); 409 437 410 438 HRESULT hr = S_OK; … … 431 459 { 432 460 AssertPtrReturn(pwszDisplayName, FALSE); 433 VBoxCredProvVerbose(0, "VBoxCredProvCredential: 461 VBoxCredProvVerbose(0, "VBoxCredProvCredential::TranslateAccountName: Getting account name for \"%ls\" ...\n", 434 462 pwszDisplayName); 435 463 … … 482 510 } 483 511 else 484 VBoxCredProvVerbose(0, "VBoxCredProvCredential: 512 VBoxCredProvVerbose(0, "VBoxCredProvCredential::TranslateAccountName: Error copying data, hr=%08x\n", hr); 485 513 break; 486 514 } … … 502 530 } 503 531 504 VBoxCredProvVerbose(0, "VBoxCredProvCredential: TranslateAccountName: Returned nStatus=%ld, fFound=%s\n",505 nStatus, fFound ? "Yes" : "No");532 VBoxCredProvVerbose(0, "VBoxCredProvCredential::TranslateAccountName returned nStatus=%ld, fFound=%RTbool\n", 533 nStatus, fFound); 506 534 return fFound; 507 535 … … 512 540 && cbLen > 0) 513 541 { 514 VBoxCredProvVerbose(0, "VBoxCredProvCredential: 542 VBoxCredProvVerbose(0, "VBoxCredProvCredential::GetAccountName: Translated ADS name has %u characters\n", cbLen)); 515 543 516 544 ppwszAccoutName = (PWSTR)RTMemAlloc(cbLen * sizeof(WCHAR)); … … 518 546 if (TranslateNameW(pwszName, NameUnknown, NameUserPrincipal, ppwszAccoutName, &cbLen)) 519 547 { 520 VBoxCredProvVerbose(0, "VBoxCredProvCredential: 548 VBoxCredProvVerbose(0, "VBoxCredProvCredential::GetAccountName: Real ADS account name of '%ls' is '%ls'\n", 521 549 pwszName, ppwszAccoutName)); 522 550 } … … 546 574 { 547 575 AssertPtrReturn(pwszAccountData, FALSE); 548 VBoxCredProvVerbose(0, "VBoxCredProvCredential: 576 VBoxCredProvVerbose(0, "VBoxCredProvCredential::ExtractAccoutData: Getting account name for \"%ls\" ...\n", 549 577 pwszAccountData); 550 578 HRESULT hr = E_FAIL; … … 573 601 } 574 602 else 575 VBoxCredProvVerbose(0, "VBoxCredProvCredential: 603 VBoxCredProvVerbose(0, "VBoxCredProvCredential::ExtractAccoutData: Error copying domain data, hr=%08x\n", hr); 576 604 } 577 605 else 578 606 { 579 607 hr = E_FAIL; 580 VBoxCredProvVerbose(0, "VBoxCredProvCredential: 608 VBoxCredProvVerbose(0, "VBoxCredProvCredential::ExtractAccoutData: No domain name found!\n"); 581 609 } 582 610 } 583 611 else 584 VBoxCredProvVerbose(0, "VBoxCredProvCredential: 612 VBoxCredProvVerbose(0, "VBoxCredProvCredential::ExtractAccoutData: Error copying account data, hr=%08x\n", hr); 585 613 586 614 if (hr != S_OK) … … 592 620 } 593 621 else 594 VBoxCredProvVerbose(0, "VBoxCredProvCredential: 622 VBoxCredProvVerbose(0, "VBoxCredProvCredential::ExtractAccoutData: No valid principal account name found!\n"); 595 623 596 624 return (hr == S_OK); … … 632 660 #ifdef DEBUG 633 661 if (SUCCEEDED(hr)) 634 VBoxCredProvVerbose(0, "VBoxCredProvCredential: 662 VBoxCredProvVerbose(0, "VBoxCredProvCredential::GetStringValue: dwFieldID=%ld, ppwszString=%ls\n", 635 663 dwFieldID, *ppwszString); 636 664 #endif … … 651 679 DWORD* pdwAdjacentTo) 652 680 { 653 VBoxCredProvVerbose(0, "VBoxCredProvCredential: 681 VBoxCredProvVerbose(0, "VBoxCredProvCredential::GetSubmitButtonValue: dwFieldID=%ld\n", dwFieldID); 654 682 655 683 HRESULT hr = S_OK; … … 661 689 /* pdwAdjacentTo is a pointer to the fieldID you want the submit button to appear next to. */ 662 690 *pdwAdjacentTo = VBOXCREDPROV_FIELDID_PASSWORD; 663 VBoxCredProvVerbose(0, "VBoxCredProvCredential: 691 VBoxCredProvVerbose(0, "VBoxCredProvCredential::GetSubmitButtonValue: dwFieldID=%ld, *pdwAdjacentTo=%ld\n", 664 692 dwFieldID, *pdwAdjacentTo); 665 693 } … … 678 706 PCWSTR pcwzString) 679 707 { 680 VBoxCredProvVerbose(0, "VBoxCredProvCredential: SetStringValue: dwFieldID=%ld, pcwzString=%ls\n", 708 #ifdef DEBUG 709 VBoxCredProvVerbose(0, "VBoxCredProvCredential::SetStringValue: dwFieldID=%ld, pcwzString=%ls\n", 681 710 dwFieldID, pcwzString); 682 683 /* 684 * We don't set any values into fields (e.g. the password, hidden 685 * by dots), instead keep it secret by resetting all credentials. 686 */ 687 Reset(); 688 689 return S_OK; 711 #endif 712 713 /* Do more things here later. */ 714 HRESULT hr = S_OK; 715 716 VBoxCredProvVerbose(0, "VBoxCredProvCredential::SetStringValue returned with hr=%08x\n", hr); 717 return hr; 690 718 } 691 719 … … 787 815 788 816 #ifdef DEBUG 789 VBoxCredProvVerbose(0, "VBoxCredProvCredential: 817 VBoxCredProvVerbose(0, "VBoxCredProvCredential::GetSerialization: Username=%ls, Password=%ls, Domain=%ls\n", 790 818 m_pwszCredentials[VBOXCREDPROV_FIELDID_USERNAME], 791 819 m_pwszCredentials[VBOXCREDPROV_FIELDID_PASSWORD], … … 793 821 #endif 794 822 795 WCHAR wszComputerName[MAX_COMPUTERNAME_LENGTH + 1]; 796 DWORD cch = ARRAYSIZE(wszComputerName); 797 if (GetComputerNameW(wszComputerName, &cch)) 798 { 799 /* Is a domain name missing? Then use the name of the local computer. */ 800 if ( m_pwszCredentials[VBOXCREDPROV_FIELDID_DOMAINNAME] 801 && RTUtf16Len(m_pwszCredentials[VBOXCREDPROV_FIELDID_DOMAINNAME])) 802 { 803 hr = RTUTF16toToUnicode(&pKerberosLogon->LogonDomainName, 804 m_pwszCredentials[VBOXCREDPROV_FIELDID_DOMAINNAME], 805 false /* Just assign, no copy */); 806 } 807 else 823 /* Do we have a domain name set? */ 824 if ( m_pwszCredentials[VBOXCREDPROV_FIELDID_DOMAINNAME] 825 && RTUtf16Len(m_pwszCredentials[VBOXCREDPROV_FIELDID_DOMAINNAME])) 826 { 827 hr = RTUTF16toToUnicode(&pKerberosLogon->LogonDomainName, 828 m_pwszCredentials[VBOXCREDPROV_FIELDID_DOMAINNAME], 829 false /* Just assign, no copy */); 830 } 831 else /* No domain (FQDN) given, try local computer name. */ 832 { 833 WCHAR wszComputerName[MAX_COMPUTERNAME_LENGTH + 1]; 834 DWORD cch = ARRAYSIZE(wszComputerName); 835 if (GetComputerNameW(wszComputerName, &cch)) 836 { 837 /* Is a domain name missing? Then use the name of the local computer. */ 808 838 hr = RTUTF16toToUnicode(&pKerberosLogon->LogonDomainName, 809 839 wszComputerName, 810 840 false /* Just assign, no copy */); 811 841 842 VBoxCredProvVerbose(0, "VBoxCredProvCredential::GetSerialization: Local computer name=%ls\n", 843 wszComputerName); 844 } 845 else 846 hr = HRESULT_FROM_WIN32(GetLastError()); 847 } 848 849 if (SUCCEEDED(hr)) 850 { 812 851 /* Fill in the username and password. */ 813 852 if (SUCCEEDED(hr)) … … 844 883 } 845 884 846 if (SUCCEEDED(hr)) 847 { 848 /* Allocate copies of, and package, the strings in a binary blob. */ 885 if (SUCCEEDED(hr)) /* Build the logon package. */ 849 886 hr = AllocateLogonPackage(KerberosUnlockLogon, 850 887 &pcpCredentialSerialization->rgbSerialization, 851 888 &pcpCredentialSerialization->cbSerialization); 852 }853 889 854 890 if (SUCCEEDED(hr)) … … 900 936 } 901 937 } 902 else 903 hr = HRESULT_FROM_WIN32(GetLastError()); 904 905 VBoxCredProvVerbose(0, "VBoxCredProvCredential: GetSerialization: Returned 0x%08x\n", hr); 938 939 VBoxCredProvVerbose(0, "VBoxCredProvCredential::GetSerialization returned hr=0x%08x\n", hr); 906 940 return hr; 907 941 } … … 914 948 * being disabled. 915 949 */ 916 HRESULT VBoxCredProvCredential::ReportResult(NTSTATUS nt sStatus,917 NTSTATUS nt sSubstatus,950 HRESULT VBoxCredProvCredential::ReportResult(NTSTATUS ntStatus, 951 NTSTATUS ntSubStatus, 918 952 PWSTR *ppwszOptionalStatusText, 919 953 CREDENTIAL_PROVIDER_STATUS_ICON *pcpsiOptionalStatusIcon) … … 923 957 * this function can't fail 924 958 */ 959 VBoxCredProvVerbose(0, "VBoxCredProvCredential::ReportResult: ntStatus=%ld, ntSubStatus=%ld\n", 960 ntStatus, ntSubStatus); 925 961 return S_OK; 926 962 } -
trunk/src/VBox/Additions/WINNT/VBoxCredProv/VBoxCredProvCredential.h
r40271 r40393 43 43 public: 44 44 45 VBoxCredProvCredential( VBoxCredProvProvider *pProvider);45 VBoxCredProvCredential(void); 46 46 47 47 virtual ~VBoxCredProvCredential(void); … … 81 81 PWSTR *ppwszOptionalStatusText, 82 82 CREDENTIAL_PROVIDER_STATUS_ICON *pcpsiOptionalStatusIcon); 83 IFACEMETHODIMP ReportResult(NTSTATUS nt sStatus,84 NTSTATUS nt sSubstatus,83 IFACEMETHODIMP ReportResult(NTSTATUS ntStatus, 84 NTSTATUS ntSubStatus, 85 85 PWSTR* ppwszOptionalStatusText, 86 86 CREDENTIAL_PROVIDER_STATUS_ICON* pcpsiOptionalStatusIcon); … … 88 88 public: 89 89 90 voidReset(void);90 HRESULT Reset(void); 91 91 HRESULT Initialize(CREDENTIAL_PROVIDER_USAGE_SCENARIO cpus); 92 92 int RetrieveCredentials(void); … … 102 102 private: 103 103 104 /** Pointer to parent. */105 VBoxCredProvProvider *m_pProvider;106 104 /** Internal reference count. */ 107 ULONGm_cRefCount;105 LONG m_cRefCount; 108 106 /** The usage scenario for which we were enumerated. */ 109 107 CREDENTIAL_PROVIDER_USAGE_SCENARIO m_cpUS; -
trunk/src/VBox/Additions/WINNT/VBoxCredProv/VBoxCredProvFactory.cpp
r40271 r40393 35 35 ULONG VBoxCredProvFactory::AddRef(void) 36 36 { 37 VBoxCredProvVerbose(0, "VBoxCredProvFactory: Increasing reference from %ld to %ld\n",38 m_cRefCount, m_cRefCount + 1);39 40 return m_cRefCount++;37 LONG cRefCount = InterlockedIncrement(&m_cRefCount); 38 VBoxCredProvVerbose(0, "VBoxCredProvFactory: AddRef: Returning refcount=%ld\n", 39 cRefCount); 40 return cRefCount; 41 41 } 42 42 43 43 ULONG VBoxCredProvFactory::Release(void) 44 44 { 45 VBoxCredProvVerbose(0, "VBoxCredProvFactory: Decreasing reference from %ld to %ld\n", 46 m_cRefCount, m_cRefCount - 1); 47 48 ULONG cRefCount = --m_cRefCount; 45 LONG cRefCount = InterlockedDecrement(&m_cRefCount); 46 VBoxCredProvVerbose(0, "VBoxCredProvFactory: Release: Returning refcount=%ld\n", 47 cRefCount); 49 48 if (!cRefCount) 50 49 { … … 57 56 HRESULT VBoxCredProvFactory::QueryInterface(REFIID interfaceID, void **ppvInterface) 58 57 { 58 VBoxCredProvVerbose(0, "VBoxCredProvFactory: QueryInterface\n"); 59 59 60 HRESULT hr = S_OK; 60 61 if (ppvInterface) -
trunk/src/VBox/Additions/WINNT/VBoxCredProv/VBoxCredProvFactory.h
r40271 r40393 47 47 private: 48 48 49 ULONG m_cRefCount;49 LONG m_cRefCount; 50 50 friend HRESULT VBoxCredentialProviderCreate(REFCLSID rclsid, REFIID riid, void** ppv); 51 51 }; -
trunk/src/VBox/Additions/WINNT/VBoxCredProv/VBoxCredProvPoller.cpp
r40271 r40393 39 39 VBoxCredProvPoller::~VBoxCredProvPoller(void) 40 40 { 41 VBoxCredProvVerbose(0, "VBoxCredProvPoller: Destroying ...\n"); 42 41 43 Shutdown(); 42 44 } … … 52 54 if (m_hThreadPoller != NIL_RTTHREAD) 53 55 { 54 VBoxCredProvVerbose(0, "VBoxCredProvPoller: Thread already running, returning !\n");56 VBoxCredProvVerbose(0, "VBoxCredProvPoller: Thread already running, returning\n"); 55 57 return VINF_SUCCESS; 56 58 } … … 58 60 if (m_pProv != NULL) 59 61 m_pProv->Release(); 62 60 63 m_pProv = pProvider; 61 AssertPtr(m_pProv); 64 /* 65 * We must not add a reference via AddRef() here, otherwise 66 * the credential provider does not get destructed properly. 67 * In order to get this thread terminated normally the credential 68 * provider has to call Shutdown(). 69 */ 62 70 63 71 /* Create the poller thread. */ … … 85 93 /* Wait until the thread has terminated. */ 86 94 rc = RTThreadWait(m_hThreadPoller, RT_INDEFINITE_WAIT, NULL); 87 VBoxCredProvVerbose(0, "VBoxCredProvPoller: Thread has (probably) terminated (rc=%Rrc)\n", rc); 95 if (RT_FAILURE(rc)) 96 VBoxCredProvVerbose(0, "VBoxCredProvPoller: Wait returned error rc=%Rrc\n", rc); 88 97 } 89 98 else 90 { 91 /* Failed to signal the thread - very unlikely - so no point in waiting long. */ 92 VBoxCredProvVerbose(0, "VBoxCredProvPoller::Shutdown: Failed to signal semaphore, rc=%Rrc\n", rc); 93 rc = RTThreadWait(m_hThreadPoller, 100, NULL); 94 VBoxCredProvVerbose(0, "VBoxCredProvPoller::Shutdown: Thread has terminated? Wait rc=%Rrc\n", rc); 95 } 99 VBoxCredProvVerbose(0, "VBoxCredProvPoller: Error waiting for thread shutdown, rc=%Rrc\n", rc); 96 100 101 m_pProv = NULL; 97 102 m_hThreadPoller = NIL_RTTHREAD; 103 104 VBoxCredProvVerbose(0, "VBoxCredProvPoller: Shutdown returned with rc=%Rrc\n", rc); 98 105 return rc; 99 106 } -
trunk/src/VBox/Additions/WINNT/VBoxCredProv/VBoxCredProvProvider.cpp
r40271 r40393 30 30 m_pPoller(NULL), 31 31 m_pCred(NULL), 32 m_pCredProvEvents(NULL), 33 m_fGotCredentials(false), 32 m_pEvents(NULL), 34 33 m_fHandleRemoteSessions(false) 35 34 { 36 LONG cRefCount =VBoxCredentialProviderAcquire();35 VBoxCredentialProviderAcquire(); 37 36 38 37 VBoxCredProvReportStatus(VBoxGuestFacilityStatus_Init); … … 42 41 VBoxCredProvProvider::~VBoxCredProvProvider(void) 43 42 { 43 VBoxCredProvVerbose(0, "VBoxCredProv: Destroying\n"); 44 44 45 if (m_pCred) 45 46 { … … 55 56 } 56 57 57 ULONG cRefCount = VBoxCredentialProviderRefCount();58 VBoxCredProvVerbose(0, "VBoxCredProv: Destroying (global DLL refcount=%ld)\n", cRefCount);59 60 58 VBoxCredProvReportStatus(VBoxGuestFacilityStatus_Terminated); 61 59 … … 67 65 ULONG VBoxCredProvProvider::AddRef(void) 68 66 { 69 VBoxCredProvVerbose(0, "VBoxCredProv: Increasing reference from %ld to %ld\n",70 m_cRefCount, m_cRefCount + 1);71 72 return m_cRefCount++;67 LONG cRefCount = InterlockedIncrement(&m_cRefCount); 68 VBoxCredProvVerbose(0, "VBoxCredProv: AddRef: Returning refcount=%ld\n", 69 cRefCount); 70 return cRefCount; 73 71 } 74 72 … … 76 74 ULONG VBoxCredProvProvider::Release(void) 77 75 { 78 Assert(m_cRefCount); 79 80 VBoxCredProvVerbose(0, "VBoxCredProv: Decreasing reference from %ld to %ld\n", 81 m_cRefCount, m_cRefCount - 1); 82 83 ULONG cRefCount = --m_cRefCount; 76 LONG cRefCount = InterlockedDecrement(&m_cRefCount); 77 VBoxCredProvVerbose(0, "VBoxCredProv: Release: Returning refcount=%ld\n", 78 cRefCount); 84 79 if (!cRefCount) 85 80 { … … 203 198 HRESULT hr = S_OK; 204 199 DWORD dwErr; 200 201 VBoxCredProvVerbose(0, "VBoxCredProv::SetUsageScenario: cpUS=%d, dwFlags=%ld\n", 202 cpUsageScenario, dwFlags); 205 203 206 204 m_cpUsageScenario = cpUsageScenario; … … 238 236 if (!m_pCred) 239 237 { 240 m_pCred = new VBoxCredProvCredential( this);238 m_pCred = new VBoxCredProvCredential(); 241 239 if (m_pCred) 242 240 { … … 251 249 } 252 250 253 /* If we did fail -> cleanup*/251 /* If we failed, do some cleanup. */ 254 252 if (FAILED(hr)) 255 253 { … … 275 273 } 276 274 277 VBoxCredProvVerbose(0, "VBoxCredProv::SetUsageScenario returned hr=0x%08x (cpUS=%d, dwFlags=%ld)\n", 278 hr, cpUsageScenario, dwFlags); 275 VBoxCredProvVerbose(0, "VBoxCredProv::SetUsageScenario returned hr=0x%08x\n", hr); 279 276 return hr; 280 277 } … … 308 305 UINT_PTR upAdviseContext) 309 306 { 310 VBoxCredProvVerbose(0, "VBoxCredProv::Advise\n"); 311 312 if (m_pCredProvEvents != NULL) 313 m_pCredProvEvents->Release(); 314 315 m_pCredProvEvents = pcpEvents; 316 AssertPtr(m_pCredProvEvents); 317 m_pCredProvEvents->AddRef(); 307 VBoxCredProvVerbose(0, "VBoxCredProv::Advise, pcpEvents=0x%p, upAdviseContext=%u\n", 308 pcpEvents, upAdviseContext); 309 if (m_pEvents) 310 { 311 m_pEvents->Release(); 312 m_pEvents = NULL; 313 } 314 315 m_pEvents = pcpEvents; 316 if (m_pEvents) 317 m_pEvents->AddRef(); 318 318 319 319 /* … … 329 329 HRESULT VBoxCredProvProvider::UnAdvise(void) 330 330 { 331 VBoxCredProvVerbose(0, "VBoxCredProv::UnAdvise\n"); 332 if (m_pCredProvEvents != NULL) 333 { 334 m_pCredProvEvents->Release(); 335 m_pCredProvEvents = NULL; 331 VBoxCredProvVerbose(0, "VBoxCredProv::UnAdvise: pEvents=0x%p\n", 332 m_pEvents); 333 if (m_pEvents) 334 { 335 m_pEvents->Release(); 336 m_pEvents = NULL; 336 337 } 337 338 … … 350 351 HRESULT VBoxCredProvProvider::GetFieldDescriptorCount(DWORD *pdwCount) 351 352 { 352 Assert(pdwCount); 353 *pdwCount = VBOXCREDPROV_NUM_FIELDS; 354 355 VBoxCredProvVerbose(0, "VBoxCredProv::GetFieldDescriptorCount: %ld\n", *pdwCount); 353 if (pdwCount) 354 { 355 *pdwCount = VBOXCREDPROV_NUM_FIELDS; 356 VBoxCredProvVerbose(0, "VBoxCredProv::GetFieldDescriptorCount: %ld\n", *pdwCount); 357 } 356 358 return S_OK; 357 359 } … … 457 459 HRESULT hr; 458 460 459 VBoxCredProvVerbose(0, "VBoxCredProv::GetCredentialAt: Index=%ld, ppCredProvCredential=%p\n", dwIndex, ppCredProvCredential); 461 VBoxCredProvVerbose(0, "VBoxCredProv::GetCredentialAt: Index=%ld, ppCredProvCredential=0x%p\n", 462 dwIndex, ppCredProvCredential); 460 463 461 464 if (!m_pCred) … … 487 490 VBoxCredProvVerbose(0, "VBoxCredProv::OnCredentialsProvided\n"); 488 491 489 if (m_p CredProvEvents != NULL)490 m_p CredProvEvents->CredentialsChanged(m_upAdviseContext);492 if (m_pEvents) 493 m_pEvents->CredentialsChanged(m_upAdviseContext); 491 494 } 492 495 -
trunk/src/VBox/Additions/WINNT/VBoxCredProv/VBoxCredProvProvider.h
r40271 r40393 75 75 76 76 /** Interface reference count. */ 77 ULONGm_cRefCount;77 LONG m_cRefCount; 78 78 /** Our one and only credential. */ 79 79 VBoxCredProvCredential *m_pCred; … … 81 81 VBoxCredProvPoller *m_pPoller; 82 82 /** Used to tell our owner to re-enumerate credentials. */ 83 ICredentialProviderEvents *m_p CredProvEvents;83 ICredentialProviderEvents *m_pEvents; 84 84 /** Used to tell our owner who we are when asking to re-enumerate credentials. */ 85 85 UINT_PTR m_upAdviseContext; 86 86 /** Saved usage scenario. */ 87 87 CREDENTIAL_PROVIDER_USAGE_SCENARIO m_cpUsageScenario; 88 /** Flag indicating we got some credentials to work with. */89 bool m_fGotCredentials;90 88 /** Flag whether we need to handle remote session over Windows Remote 91 89 * Desktop Service. */ -
trunk/src/VBox/Additions/WINNT/VBoxCredProv/VBoxCredentialProvider.cpp
r40271 r40393 33 33 * Global Variables * 34 34 *******************************************************************************/ 35 static LONG g_cDllRefCount = 0; /* Global DLL reference count. */36 HINSTANCE g_hDllInst= NULL; /* Global DLL hInstance. */35 static LONG g_cDllRefCount = 0; /* Global DLL reference count. */ 36 static HINSTANCE g_hDllInst = NULL; /* Global DLL hInstance. */ 37 37 38 38 … … 56 56 if (RT_SUCCESS(rc)) 57 57 { 58 VBoxCredProvVerbose(0, "VBoxCredProv: v%s r%s (%s %s) loaded \n",58 VBoxCredProvVerbose(0, "VBoxCredProv: v%s r%s (%s %s) loaded (refs=%ld)\n", 59 59 RTBldCfgVersion(), RTBldCfgRevisionStr(), 60 __DATE__, __TIME__ );60 __DATE__, __TIME__, g_cDllRefCount); 61 61 } 62 62 … … 67 67 case DLL_PROCESS_DETACH: 68 68 69 VbglR3Term(); 69 if (!g_cDllRefCount) 70 VbglR3Term(); 70 71 break; 71 72 … … 82 83 * Increments the reference count by one. Must be released 83 84 * with VBoxCredentialProviderRelease() when finished. 84 *85 * @return LONG The current referecne count.86 85 */ 87 LONGVBoxCredentialProviderAcquire(void)86 void VBoxCredentialProviderAcquire(void) 88 87 { 89 VBoxCredProvVerbose(0, "VBoxCredProv: Increasing global refcount to %ld\n",90 g_cDllRefCount + 1);91 return InterlockedIncrement(&g_cDllRefCount);88 LONG cRefCount = InterlockedIncrement(&g_cDllRefCount); 89 VBoxCredProvVerbose(0, "VBoxCredentialProviderAcquire: Increasing global refcount to %ld\n", 90 cRefCount); 92 91 } 93 92 … … 95 94 /** 96 95 * Decrements the reference count by one. 97 *98 * @return LONG The current referecne count.99 96 */ 100 LONGVBoxCredentialProviderRelease(void)97 void VBoxCredentialProviderRelease(void) 101 98 { 102 VBoxCredProvVerbose(0, "VBoxCredProv: Decreasing global refcount to %ld\n",103 g_cDllRefCount - 1);104 return InterlockedDecrement(&g_cDllRefCount);99 LONG cRefCount = InterlockedDecrement(&g_cDllRefCount); 100 VBoxCredProvVerbose(0, "VBoxCredentialProviderRelease: Decreasing global refcount to %ld\n", 101 cRefCount); 105 102 } 106 103 -
trunk/src/VBox/Additions/WINNT/VBoxCredProv/VBoxCredentialProvider.h
r40271 r40393 71 71 72 72 /** Prototypes. */ 73 LONGVBoxCredentialProviderAcquire(void);74 LONGVBoxCredentialProviderRelease(void);73 void VBoxCredentialProviderAcquire(void); 74 void VBoxCredentialProviderRelease(void); 75 75 LONG VBoxCredentialProviderRefCount(void); 76 76
Note:
See TracChangeset
for help on using the changeset viewer.