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.

238 lines
9.4 KiB

  1. //---------------------------------------------------------------------------
  2. // GrpUpdt.cpp
  3. //
  4. // Comment: This is a COM object extension for the MCS DCTAccountReplicator.
  5. // This object implements the IExtendAccountMigration interface.
  6. // The Process method adds the migrated account to the specified
  7. // group on source and target domain. The Undo function removes these
  8. // from the specified group.
  9. //
  10. // (c) Copyright 1995-1998, Mission Critical Software, Inc., All Rights Reserved
  11. //
  12. // Proprietary and confidential to Mission Critical Software, Inc.
  13. //---------------------------------------------------------------------------
  14. #include "stdafx.h"
  15. #include <lm.h>
  16. #include "AddToGrp.h"
  17. #include "ARExt.h"
  18. #include "ARExt_i.c"
  19. #include "GrpUpdt.h"
  20. #include "ResStr.h"
  21. #include "ErrDCT.hpp"
  22. #include "EALen.hpp"
  23. //#import "\bin\mcsvarsetmin.tlb" no_namespace
  24. #import "VarSet.tlb" no_namespace rename("property", "aproperty")
  25. StringLoader gString;
  26. /////////////////////////////////////////////////////////////////////////////
  27. // CGroupUpdate
  28. //---------------------------------------------------------------------------
  29. // Get and set methods for the properties.
  30. //---------------------------------------------------------------------------
  31. STDMETHODIMP CGroupUpdate::get_sName(BSTR *pVal)
  32. {
  33. *pVal = m_sName;
  34. return S_OK;
  35. }
  36. STDMETHODIMP CGroupUpdate::put_sName(BSTR newVal)
  37. {
  38. m_sName = newVal;
  39. return S_OK;
  40. }
  41. STDMETHODIMP CGroupUpdate::get_sDesc(BSTR *pVal)
  42. {
  43. *pVal = m_sDesc;
  44. return S_OK;
  45. }
  46. STDMETHODIMP CGroupUpdate::put_sDesc(BSTR newVal)
  47. {
  48. m_sDesc = newVal;
  49. return S_OK;
  50. }
  51. //---------------------------------------------------------------------------
  52. // PreProcessObject : This method doesn't do anything at this point
  53. //---------------------------------------------------------------------------
  54. STDMETHODIMP CGroupUpdate::PreProcessObject(
  55. IUnknown *pSource, //in- Pointer to the source AD object
  56. IUnknown *pTarget, //in- Pointer to the target AD object
  57. IUnknown *pMainSettings, //in- Varset filled with the settings supplied by user
  58. IUnknown **ppPropsToSet, //in,out - Varset filled with Prop-Value pairs that will be set
  59. // once all extension objects are executed.
  60. EAMAccountStats* pStats
  61. )
  62. {
  63. return S_OK;
  64. }
  65. //---------------------------------------------------------------------------
  66. // ProcessObject : This method adds the copied account to the specified
  67. // groups on source and target domains.
  68. //---------------------------------------------------------------------------
  69. STDMETHODIMP CGroupUpdate::ProcessObject(
  70. IUnknown *pSource, //in- Pointer to the source AD object
  71. IUnknown *pTarget, //in- Pointer to the target AD object
  72. IUnknown *pMainSettings, //in- Varset filled with the settings supplied by user
  73. IUnknown **ppPropsToSet, //in,out - Varset filled with Prop-Value pairs that will be set
  74. // once all extension objects are executed.
  75. EAMAccountStats* pStats
  76. )
  77. {
  78. IVarSetPtr pVs = pMainSettings;
  79. _variant_t var;
  80. _bstr_t sGrpName, sServer, sAcct;
  81. HRESULT hr = S_OK;
  82. long rc = 0;
  83. TErrorDct err;
  84. WCHAR fileName[LEN_Path];
  85. // Get the Error log filename from the Varset
  86. var = pVs->get(GET_BSTR(DCTVS_Options_Logfile));
  87. wcscpy(fileName, (WCHAR*)V_BSTR(&var));
  88. // Open the error log
  89. err.LogOpen(fileName, 1);
  90. // Process adding users to the source domain.
  91. var = pVs->get(GET_BSTR(DCTVS_AccountOptions_AddToGroupOnSourceDomain));
  92. if ( var.vt == VT_BSTR )
  93. {
  94. sGrpName = V_BSTR(&var);
  95. if ( sGrpName.length() > 0 )
  96. {
  97. var = pVs->get(GET_BSTR(DCTVS_Options_SourceServer));
  98. sServer = V_BSTR(&var);
  99. var = pVs->get(GET_BSTR(DCTVS_CopiedAccount_SourceSam));
  100. sAcct = V_BSTR(&var);
  101. rc = NetGroupAddUser((WCHAR*) sServer, (WCHAR *) sGrpName, (WCHAR *) sAcct);
  102. if ( rc != 0 )
  103. {
  104. hr = HRESULT_FROM_WIN32(rc);
  105. if (pStats != NULL)
  106. pStats->warnings.users++;
  107. err.SysMsgWrite(ErrW, rc, DCT_MSG_ADDTO_FAILED_SSD, sAcct, sGrpName, rc);
  108. }
  109. else
  110. {
  111. err.MsgWrite(0,DCT_MSG_ADDED_TO_GROUP_SS,sAcct,sGrpName);
  112. }
  113. }
  114. }
  115. // Now process the group on the target domain.
  116. var = pVs->get(GET_BSTR(DCTVS_AccountOptions_AddToGroup));
  117. if ( var.vt == VT_BSTR )
  118. {
  119. sGrpName = V_BSTR(&var);
  120. if ( sGrpName.length() > 0 )
  121. {
  122. var = pVs->get(GET_BSTR(DCTVS_Options_TargetServer));
  123. sServer = V_BSTR(&var);
  124. var = pVs->get(GET_BSTR(DCTVS_CopiedAccount_TargetSam));
  125. sAcct = V_BSTR(&var);
  126. rc = NetGroupAddUser((WCHAR*) sServer, (WCHAR *) sGrpName, (WCHAR *) sAcct);
  127. if ( rc != 0 )
  128. {
  129. hr = HRESULT_FROM_WIN32(rc);
  130. if (pStats != NULL)
  131. pStats->warnings.users++;
  132. err.SysMsgWrite(ErrW, rc, DCT_MSG_ADDTO_FAILED_SSD, sAcct, sGrpName, rc);
  133. }
  134. else
  135. {
  136. err.MsgWrite(0,DCT_MSG_ADDED_TO_GROUP_SS,sAcct,sGrpName);
  137. }
  138. }
  139. }
  140. err.LogClose();
  141. return hr;
  142. }
  143. //---------------------------------------------------------------------------
  144. // ProcessUndo : This method removes the account from the specified group.
  145. //---------------------------------------------------------------------------
  146. STDMETHODIMP CGroupUpdate::ProcessUndo(
  147. IUnknown *pSource, //in- Pointer to the source AD object
  148. IUnknown *pTarget, //in- Pointer to the target AD object
  149. IUnknown *pMainSettings, //in- Varset filled with the settings supplied by user
  150. IUnknown **ppPropsToSet, //in,out - Varset filled with Prop-Value pairs that will be set
  151. // once all extension objects are executed.
  152. EAMAccountStats* pStats
  153. )
  154. {
  155. IVarSetPtr pVs = pMainSettings;
  156. _variant_t var;
  157. _bstr_t sGrpName, sServer, sAcct;
  158. HRESULT hr = S_OK;
  159. long rc = 0;
  160. TErrorDct err;
  161. WCHAR fileName[LEN_Path];
  162. // Get the Error log filename from the Varset
  163. var = pVs->get(GET_BSTR(DCTVS_Options_Logfile));
  164. wcscpy(fileName, (WCHAR*)V_BSTR(&var));
  165. VariantInit(&var);
  166. // Open the error log
  167. err.LogOpen(fileName, 1);
  168. // Process adding users to the source domain.
  169. var = pVs->get(GET_BSTR(DCTVS_AccountOptions_AddToGroupOnSourceDomain));
  170. if ( var.vt == VT_BSTR )
  171. {
  172. sGrpName = V_BSTR(&var);
  173. if ( sGrpName.length() > 0 )
  174. {
  175. var = pVs->get(GET_BSTR(DCTVS_Options_SourceServer));
  176. sServer = V_BSTR(&var);
  177. var = pVs->get(GET_BSTR(DCTVS_CopiedAccount_SourceSam));
  178. sAcct = V_BSTR(&var);
  179. rc = NetGroupDelUser((WCHAR*) sServer, (WCHAR *) sGrpName, (WCHAR *) sAcct);
  180. if ( rc != 0 )
  181. {
  182. hr = HRESULT_FROM_WIN32(rc);
  183. if (pStats != NULL)
  184. pStats->warnings.users++;
  185. err.SysMsgWrite(ErrW, rc, DCT_MSG_REMOVE_FROM_FAILED_SSD, (WCHAR *)sAcct, (WCHAR*)sGrpName, rc);
  186. }
  187. else
  188. {
  189. err.MsgWrite(0,DCT_MSG_REMOVE_FROM_GROUP_SS,(WCHAR *)sAcct,(WCHAR *)sGrpName);
  190. }
  191. }
  192. }
  193. // Now process the group on the target domain.
  194. var = pVs->get(GET_BSTR(DCTVS_AccountOptions_AddToGroup));
  195. if ( var.vt == VT_BSTR )
  196. {
  197. sGrpName = V_BSTR(&var);
  198. if ( sGrpName.length() > 0 )
  199. {
  200. var = pVs->get(GET_BSTR(DCTVS_Options_TargetServer));
  201. sServer = V_BSTR(&var);
  202. var = pVs->get(GET_BSTR(DCTVS_CopiedAccount_TargetSam));
  203. sAcct = V_BSTR(&var);
  204. rc = NetGroupDelUser((WCHAR*) sServer, (WCHAR *) sGrpName, (WCHAR *) sAcct);
  205. if ( rc != 0 )
  206. {
  207. hr = HRESULT_FROM_WIN32(rc);
  208. if (pStats != NULL)
  209. pStats->warnings.users++;
  210. err.SysMsgWrite(ErrW, rc, DCT_MSG_REMOVE_FROM_FAILED_SSD, (WCHAR *)sAcct, (WCHAR *)sGrpName, rc);
  211. }
  212. else
  213. {
  214. err.MsgWrite(0,DCT_MSG_REMOVE_FROM_GROUP_SS,(WCHAR *)sAcct,(WCHAR *)sGrpName);
  215. }
  216. }
  217. }
  218. err.LogClose();
  219. return hr;
  220. }