Source code of Windows XP (NT5)
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.

175 lines
7.4 KiB

  1. // StoreInfo.cpp : Implementation of CStoreInfo
  2. #include "stdafx.h"
  3. #include "UpdateDB.h"
  4. #include "ResStr.h"
  5. #include "StoreInfo.h"
  6. #include "Err.hpp"
  7. #include "ARExt_i.c"
  8. //#import "\bin\mcsvarsetmin.tlb" no_namespace
  9. //#import "\bin\DBManager.tlb" no_namespace
  10. #import "VarSet.tlb" no_namespace rename("property", "aproperty")
  11. #import "DBMgr.tlb" no_namespace
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CStoreInfo
  14. StringLoader gString;
  15. #define LEN_Path 255
  16. //---------------------------------------------------------------------------
  17. // Get and set methods for the properties.
  18. //---------------------------------------------------------------------------
  19. STDMETHODIMP CStoreInfo::get_sName(BSTR *pVal)
  20. {
  21. *pVal = m_sName;
  22. return S_OK;
  23. }
  24. STDMETHODIMP CStoreInfo::put_sName(BSTR newVal)
  25. {
  26. m_sName = newVal;
  27. return S_OK;
  28. }
  29. STDMETHODIMP CStoreInfo::get_sDesc(BSTR *pVal)
  30. {
  31. *pVal = m_sDesc;
  32. return S_OK;
  33. }
  34. STDMETHODIMP CStoreInfo::put_sDesc(BSTR newVal)
  35. {
  36. m_sDesc = newVal;
  37. return S_OK;
  38. }
  39. //---------------------------------------------------------------------------
  40. // ProcessObject : This method doesn't do anything
  41. //---------------------------------------------------------------------------
  42. STDMETHODIMP CStoreInfo::PreProcessObject(
  43. IUnknown *pSource, //in- Pointer to the source AD object
  44. IUnknown *pTarget, //in- Pointer to the target AD object
  45. IUnknown *pMainSettings, //in- Varset filled with the settings supplied by user
  46. IUnknown **ppPropsToSet //in,out - Varset filled with Prop-Value pairs that will be set
  47. // once all extension objects are executed.
  48. )
  49. {
  50. return S_OK;
  51. }
  52. //---------------------------------------------------------------------------
  53. // ProcessObject : This method adds the copied account info to the DB
  54. //---------------------------------------------------------------------------
  55. STDMETHODIMP CStoreInfo::ProcessObject(
  56. IUnknown *pSource, //in- Pointer to the source AD object
  57. IUnknown *pTarget, //in- Pointer to the target AD object
  58. IUnknown *pMainSettings, //in- Varset filled with the settings supplied by user
  59. IUnknown **ppPropsToSet //in,out - Varset filled with Prop-Value pairs that will be set
  60. // once all extension objects are executed.
  61. )
  62. {
  63. IIManageDBPtr pDBMgr;//(__uuidof(IManageDB));
  64. IVarSetPtr pVs(__uuidof(VarSet));
  65. IVarSetPtr pMain = pMainSettings;
  66. IUnknown * pUnk;
  67. HRESULT hr;
  68. long lActionID = 0;
  69. _variant_t var;
  70. TError logFile;
  71. var = pMain->get(GET_BSTR(DCTVS_DBManager));
  72. if ( var.vt == VT_DISPATCH )
  73. {
  74. pDBMgr = var.pdispVal;
  75. // Fill up the Varset from the info in the main settings varset.
  76. var = pMain->get(GET_BSTR(DCTVS_CopiedAccount_SourcePath));
  77. pVs->put(GET_BSTR(DB_SourceAdsPath),var);
  78. var = pMain->get(GET_BSTR(DCTVS_CopiedAccount_TargetPath));
  79. pVs->put(GET_BSTR(DB_TargetAdsPath),var);
  80. var = pMain->get(GET_BSTR(DCTVS_Options_SourceDomain));
  81. pVs->put(GET_BSTR(DB_SourceDomain), var);
  82. var = pMain->get(GET_BSTR(DCTVS_Options_TargetDomain));
  83. pVs->put(GET_BSTR(DB_TargetDomain), var);
  84. var = pMain->get(GET_BSTR(DCTVS_CopiedAccount_SourceSam));
  85. pVs->put(GET_BSTR(DB_SourceSamName), var);
  86. var = pMain->get(GET_BSTR(DCTVS_CopiedAccount_TargetSam));
  87. pVs->put(GET_BSTR(DB_TargetSamName), var);
  88. var = pMain->get(GET_BSTR(DCTVS_CopiedAccount_Type));
  89. pVs->put(GET_BSTR(DB_Type), var);
  90. var = pMain->get(GET_BSTR(DCTVS_CopiedAccount_GUID));
  91. pVs->put(GET_BSTR(DB_GUID), var);
  92. var = pMain->get(GET_BSTR(DCTVS_CopiedAccount_Status));
  93. pVs->put(GET_BSTR(DB_status), var);
  94. var = pMain->get(GET_BSTR(DCTVS_CopiedAccount_SourceRID));
  95. pVs->put(GET_BSTR(DB_SourceRid),var);
  96. var = pMain->get(GET_BSTR(DCTVS_CopiedAccount_TargetRID));
  97. pVs->put(GET_BSTR(DB_TargetRid),var);
  98. var = pMain->get(GET_BSTR(DCTVS_CopiedAccount_SourceDomainSid));
  99. pVs->put(GET_BSTR(DB_SourceDomainSid), var);
  100. hr = pVs->QueryInterface(IID_IUnknown, (void**)&pUnk);
  101. if ( FAILED(hr)) return hr;
  102. hr = pDBMgr->raw_GetCurrentActionID(&lActionID);
  103. if ( FAILED(hr)) return hr;
  104. hr = pDBMgr->raw_SaveMigratedObject(lActionID, pUnk);
  105. if ( FAILED(hr)) return hr;
  106. pUnk->Release();
  107. }
  108. return S_OK;
  109. }
  110. //---------------------------------------------------------------------------
  111. // ProcessUndo : This method adds an entry into the DB for undoing migration
  112. //---------------------------------------------------------------------------
  113. STDMETHODIMP CStoreInfo::ProcessUndo(
  114. IUnknown *pSource, //in- Pointer to the source AD object
  115. IUnknown *pTarget, //in- Pointer to the target AD object
  116. IUnknown *pMainSettings, //in- Varset filled with the settings supplied by user
  117. IUnknown **ppPropsToSet //in,out - Varset filled with Prop-Value pairs that will be set
  118. // once all extension objects are executed.
  119. )
  120. {
  121. // We need to delete this entry from the database.
  122. WCHAR sQuery[LEN_Path];
  123. IVarSetPtr pVs = pMainSettings;
  124. IIManageDBPtr pDBMgr;
  125. HRESULT hr = E_INVALIDARG;
  126. _variant_t var;
  127. _bstr_t sSourceSam = pVs->get(GET_BSTR(DCTVS_CopiedAccount_SourceSam));
  128. _bstr_t sTargetSam = pVs->get(GET_BSTR(DCTVS_CopiedAccount_TargetSam));
  129. _bstr_t sSourceDom = pVs->get(GET_BSTR(DCTVS_Options_SourceDomain));
  130. _bstr_t sTargetDom = pVs->get(GET_BSTR(DCTVS_Options_TargetDomain));
  131. var = pVs->get(GET_BSTR(DCTVS_DBManager));
  132. if ( var.vt == VT_DISPATCH )
  133. {
  134. pDBMgr = var.pdispVal;
  135. _bstr_t bstrSameForest = pVs->get(GET_BSTR(DCTVS_Options_IsIntraforest));
  136. if (! UStrICmp((WCHAR*)bstrSameForest,GET_STRING(IDS_YES)) )
  137. {
  138. swprintf(sQuery, L"SourceSamName = \"%s\" and TargetSamName = \"%s\" and SourceDomain = \"%s\" and TargetDomain = \"%s\"",
  139. (WCHAR*)sTargetSam, (WCHAR*)sSourceSam, (WCHAR*)sTargetDom, (WCHAR*)sSourceDom);
  140. }
  141. else
  142. {
  143. swprintf(sQuery, L"SourceSamName = \"%s\" and TargetSamName = \"%s\" and SourceDomain = \"%s\" and TargetDomain = \"%s\"",
  144. (WCHAR*)sSourceSam, (WCHAR*)sTargetSam, (WCHAR*)sSourceDom, (WCHAR*)sTargetDom);
  145. }
  146. _bstr_t sFilter = sQuery;
  147. _variant_t Filter = sFilter;
  148. hr = pDBMgr->raw_ClearTable(L"MigratedObjects", Filter);
  149. }
  150. return hr;
  151. }