Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
2.6 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) Microsoft Corp. All rights reserved.
  4. //
  5. // FILE
  6. //
  7. // adsstore.cpp
  8. //
  9. // SYNOPSIS
  10. //
  11. // This file defines the class ADsDataStore.
  12. //
  13. // MODIFICATION HISTORY
  14. //
  15. // 02/20/1998 Original version.
  16. // 02/11/1999 Changes to support keeping downlevel parameters in sync.
  17. //
  18. ///////////////////////////////////////////////////////////////////////////////
  19. #include <ias.h>
  20. #include <iasutil.h>
  21. #include <adsstore.h>
  22. #include <dsobject.h>
  23. STDMETHODIMP ADsDataStore::get_Root(IDataStoreObject** ppObject)
  24. {
  25. if (ppObject == NULL) { return E_INVALIDARG; }
  26. if (*ppObject = root) { (*ppObject)->AddRef(); }
  27. return S_OK;
  28. }
  29. STDMETHODIMP ADsDataStore::Initialize(BSTR bstrDSName,
  30. BSTR bstrUserName,
  31. BSTR bstrPassword)
  32. {
  33. try
  34. {
  35. // Save these for later.
  36. userName = bstrUserName;
  37. password = bstrPassword;
  38. // Open the root container.
  39. _com_util::CheckError(OpenObject(bstrDSName, &root));
  40. }
  41. CATCH_AND_RETURN()
  42. return S_OK;
  43. }
  44. STDMETHODIMP ADsDataStore::OpenObject(BSTR bstrPath,
  45. IDataStoreObject** ppObject)
  46. {
  47. if (bstrPath == NULL || ppObject == NULL) { return E_INVALIDARG; }
  48. *ppObject = NULL;
  49. try
  50. {
  51. // Open the underlying ADSI object ...
  52. CComPtr<IUnknown> unk;
  53. // First try with signing and sealing, ...
  54. HRESULT hr = ADsOpenObject(
  55. bstrPath,
  56. userName,
  57. password,
  58. ADS_SECURE_AUTHENTICATION |
  59. ADS_USE_SIGNING |
  60. ADS_USE_SEALING,
  61. __uuidof(IUnknown),
  62. (PVOID*)&unk
  63. );
  64. if (hr == HRESULT_FROM_WIN32(ERROR_DS_UNWILLING_TO_PERFORM))
  65. {
  66. // ... then without. This allows us to connect using NTLM.
  67. hr = ADsOpenObject(
  68. bstrPath,
  69. userName,
  70. password,
  71. ADS_SECURE_AUTHENTICATION,
  72. __uuidof(IUnknown),
  73. (PVOID*)&unk
  74. );
  75. }
  76. _com_util::CheckError(hr);
  77. // ... and convert it to a DSObject.
  78. (*ppObject = new DSObject(unk))->AddRef();
  79. }
  80. CATCH_AND_RETURN()
  81. return S_OK;
  82. }
  83. STDMETHODIMP ADsDataStore::Shutdown()
  84. {
  85. root.Release();
  86. return S_OK;
  87. }