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.

211 lines
8.8 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. EAMAccountStats* pStats
  49. )
  50. {
  51. return S_OK;
  52. }
  53. //---------------------------------------------------------------------------
  54. // ProcessObject : This method adds the copied account info to the DB
  55. //---------------------------------------------------------------------------
  56. STDMETHODIMP CStoreInfo::ProcessObject(
  57. IUnknown *pSource, //in- Pointer to the source AD object
  58. IUnknown *pTarget, //in- Pointer to the target AD object
  59. IUnknown *pMainSettings, //in- Varset filled with the settings supplied by user
  60. IUnknown **ppPropsToSet, //in,out - Varset filled with Prop-Value pairs that will be set
  61. // once all extension objects are executed.
  62. EAMAccountStats* pStats
  63. )
  64. {
  65. IIManageDBPtr pDBMgr;//(__uuidof(IManageDB));
  66. IVarSetPtr pVs(__uuidof(VarSet));
  67. IVarSetPtr pMain = pMainSettings;
  68. IUnknown * pUnk;
  69. HRESULT hr;
  70. long lActionID = 0;
  71. _variant_t var;
  72. TError logFile;
  73. var = pMain->get(GET_BSTR(DCTVS_DBManager));
  74. if ( var.vt == VT_DISPATCH )
  75. {
  76. pDBMgr = var.pdispVal;
  77. // Fill up the Varset from the info in the main settings varset.
  78. var = pMain->get(GET_BSTR(DCTVS_CopiedAccount_SourcePath));
  79. pVs->put(GET_BSTR(DB_SourceAdsPath),var);
  80. var = pMain->get(GET_BSTR(DCTVS_CopiedAccount_TargetPath));
  81. pVs->put(GET_BSTR(DB_TargetAdsPath),var);
  82. var = pMain->get(GET_BSTR(DCTVS_Options_SourceDomain));
  83. pVs->put(GET_BSTR(DB_SourceDomain), var);
  84. var = pMain->get(GET_BSTR(DCTVS_Options_TargetDomain));
  85. pVs->put(GET_BSTR(DB_TargetDomain), var);
  86. var = pMain->get(GET_BSTR(DCTVS_CopiedAccount_SourceSam));
  87. pVs->put(GET_BSTR(DB_SourceSamName), var);
  88. var = pMain->get(GET_BSTR(DCTVS_CopiedAccount_TargetSam));
  89. pVs->put(GET_BSTR(DB_TargetSamName), var);
  90. _bstr_t sType = pMain->get(GET_BSTR(DCTVS_CopiedAccount_Type));
  91. //we now want to save any group accounts by their types ("ugroup", "lgroup",
  92. //or "ggroup") instead of just "group"
  93. if (sType.length() && (!UStrICmp((WCHAR*)sType, L"group")))
  94. {
  95. _bstr_t sGroup;
  96. long nGroup = pMain->get(GET_BSTR(DCTVS_CopiedAccount_GroupType));
  97. if (nGroup & 2)
  98. sGroup = L"ggroup";
  99. else if (nGroup & 4)
  100. sGroup = L"lgroup";
  101. else if (nGroup & 8)
  102. sGroup = L"ugroup";
  103. else
  104. sGroup = L"group";
  105. pVs->put(GET_BSTR(DB_Type), sGroup);
  106. }
  107. else
  108. pVs->put(GET_BSTR(DB_Type), sType);
  109. var = pMain->get(GET_BSTR(DCTVS_CopiedAccount_GUID));
  110. pVs->put(GET_BSTR(DB_GUID), var);
  111. var = pMain->get(GET_BSTR(DCTVS_CopiedAccount_Status));
  112. pVs->put(GET_BSTR(DB_status), var);
  113. var = pMain->get(GET_BSTR(DCTVS_CopiedAccount_SourceRID));
  114. pVs->put(GET_BSTR(DB_SourceRid),var);
  115. var = pMain->get(GET_BSTR(DCTVS_CopiedAccount_TargetRID));
  116. pVs->put(GET_BSTR(DB_TargetRid),var);
  117. var = pMain->get(GET_BSTR(DCTVS_CopiedAccount_SourceDomainSid));
  118. pVs->put(GET_BSTR(DB_SourceDomainSid), var);
  119. hr = pVs->QueryInterface(IID_IUnknown, (void**)&pUnk);
  120. if ( FAILED(hr)) return hr;
  121. hr = pDBMgr->raw_GetCurrentActionID(&lActionID);
  122. if ( FAILED(hr)) return hr;
  123. hr = pDBMgr->raw_SaveMigratedObject(lActionID, pUnk);
  124. if ( FAILED(hr)) return hr;
  125. pUnk->Release();
  126. }
  127. return S_OK;
  128. }
  129. //---------------------------------------------------------------------------
  130. // ProcessUndo : This method adds an entry into the DB for undoing migration
  131. //---------------------------------------------------------------------------
  132. STDMETHODIMP CStoreInfo::ProcessUndo(
  133. IUnknown *pSource, //in- Pointer to the source AD object
  134. IUnknown *pTarget, //in- Pointer to the target AD object
  135. IUnknown *pMainSettings, //in- Varset filled with the settings supplied by user
  136. IUnknown **ppPropsToSet, //in,out - Varset filled with Prop-Value pairs that will be set
  137. // once all extension objects are executed.
  138. EAMAccountStats* pStats
  139. )
  140. {
  141. // We need to delete this entry from the database.
  142. WCHAR sQuery[LEN_Path];
  143. IVarSetPtr pVs = pMainSettings;
  144. IIManageDBPtr pDBMgr;
  145. HRESULT hr = E_INVALIDARG;
  146. _variant_t var;
  147. _bstr_t sSourceSam = pVs->get(GET_BSTR(DCTVS_CopiedAccount_SourceSam));
  148. _bstr_t sTargetSam = pVs->get(GET_BSTR(DCTVS_CopiedAccount_TargetSam));
  149. _bstr_t sSourceDom = pVs->get(GET_BSTR(DCTVS_Options_SourceDomain));
  150. _bstr_t sTargetDom = pVs->get(GET_BSTR(DCTVS_Options_TargetDomain));
  151. //
  152. // If undoing a computer migration do not delete records from the migrated objects table as
  153. // the migration driver component requires the computer object migration records when trimming
  154. // the server list.
  155. //
  156. _bstr_t strWizard = pVs->get(GET_BSTR(DCTVS_Options_Wizard));
  157. if (UStrICmp(strWizard, L"computer") == 0)
  158. {
  159. hr = S_OK;
  160. }
  161. else
  162. {
  163. var = pVs->get(GET_BSTR(DCTVS_DBManager));
  164. if ( var.vt == VT_DISPATCH )
  165. {
  166. pDBMgr = var.pdispVal;
  167. _bstr_t bstrSameForest = pVs->get(GET_BSTR(DCTVS_Options_IsIntraforest));
  168. if (! UStrICmp((WCHAR*)bstrSameForest,GET_STRING(IDS_YES)) )
  169. {
  170. swprintf(sQuery, L"SourceSamName = \"%s\" and TargetSamName = \"%s\" and SourceDomain = \"%s\" and TargetDomain = \"%s\"",
  171. (WCHAR*)sTargetSam, (WCHAR*)sSourceSam, (WCHAR*)sTargetDom, (WCHAR*)sSourceDom);
  172. }
  173. else
  174. {
  175. swprintf(sQuery, L"SourceSamName = \"%s\" and TargetSamName = \"%s\" and SourceDomain = \"%s\" and TargetDomain = \"%s\"",
  176. (WCHAR*)sSourceSam, (WCHAR*)sTargetSam, (WCHAR*)sSourceDom, (WCHAR*)sTargetDom);
  177. }
  178. _bstr_t sFilter = sQuery;
  179. _variant_t Filter = sFilter;
  180. hr = pDBMgr->raw_ClearTable(L"MigratedObjects", Filter);
  181. }
  182. }
  183. return hr;
  184. }