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.

227 lines
8.7 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. )
  61. {
  62. return S_OK;
  63. }
  64. //---------------------------------------------------------------------------
  65. // ProcessObject : This method adds the copied account to the specified
  66. // groups on source and target domains.
  67. //---------------------------------------------------------------------------
  68. STDMETHODIMP CGroupUpdate::ProcessObject(
  69. IUnknown *pSource, //in- Pointer to the source AD object
  70. IUnknown *pTarget, //in- Pointer to the target AD object
  71. IUnknown *pMainSettings, //in- Varset filled with the settings supplied by user
  72. IUnknown **ppPropsToSet //in,out - Varset filled with Prop-Value pairs that will be set
  73. // once all extension objects are executed.
  74. )
  75. {
  76. IVarSetPtr pVs = pMainSettings;
  77. _variant_t var;
  78. _bstr_t sGrpName, sServer, sAcct;
  79. HRESULT hr = S_OK;
  80. long rc = 0;
  81. TErrorDct err;
  82. WCHAR fileName[LEN_Path];
  83. // Get the Error log filename from the Varset
  84. var = pVs->get(GET_BSTR(DCTVS_Options_Logfile));
  85. wcscpy(fileName, (WCHAR*)V_BSTR(&var));
  86. // Open the error log
  87. err.LogOpen(fileName, 1);
  88. // Process adding users to the source domain.
  89. var = pVs->get(GET_BSTR(DCTVS_AccountOptions_AddToGroupOnSourceDomain));
  90. if ( var.vt == VT_BSTR )
  91. {
  92. sGrpName = V_BSTR(&var);
  93. if ( sGrpName.length() > 0 )
  94. {
  95. var = pVs->get(GET_BSTR(DCTVS_Options_SourceServer));
  96. sServer = V_BSTR(&var);
  97. var = pVs->get(GET_BSTR(DCTVS_CopiedAccount_SourceSam));
  98. sAcct = V_BSTR(&var);
  99. rc = NetGroupAddUser((WCHAR*) sServer, (WCHAR *) sGrpName, (WCHAR *) sAcct);
  100. if ( rc != 0 )
  101. {
  102. hr = HRESULT_FROM_WIN32(rc);
  103. err.SysMsgWrite(ErrW, rc, DCT_MSG_ADDTO_FAILED_SSD, sAcct, sGrpName, rc);
  104. }
  105. else
  106. {
  107. err.MsgWrite(0,DCT_MSG_ADDED_TO_GROUP_SS,sAcct,sGrpName);
  108. }
  109. }
  110. }
  111. // Now process the group on the target domain.
  112. var = pVs->get(GET_BSTR(DCTVS_AccountOptions_AddToGroup));
  113. if ( var.vt == VT_BSTR )
  114. {
  115. sGrpName = V_BSTR(&var);
  116. if ( sGrpName.length() > 0 )
  117. {
  118. var = pVs->get(GET_BSTR(DCTVS_Options_TargetServer));
  119. sServer = V_BSTR(&var);
  120. var = pVs->get(GET_BSTR(DCTVS_CopiedAccount_TargetSam));
  121. sAcct = V_BSTR(&var);
  122. rc = NetGroupAddUser((WCHAR*) sServer, (WCHAR *) sGrpName, (WCHAR *) sAcct);
  123. if ( rc != 0 )
  124. {
  125. hr = HRESULT_FROM_WIN32(rc);
  126. err.SysMsgWrite(ErrW, rc, DCT_MSG_ADDTO_FAILED_SSD, sAcct, sGrpName, rc);
  127. }
  128. else
  129. {
  130. err.MsgWrite(0,DCT_MSG_ADDED_TO_GROUP_SS,sAcct,sGrpName);
  131. }
  132. }
  133. }
  134. err.LogClose();
  135. return hr;
  136. }
  137. //---------------------------------------------------------------------------
  138. // ProcessUndo : This method removes the account from the specified group.
  139. //---------------------------------------------------------------------------
  140. STDMETHODIMP CGroupUpdate::ProcessUndo(
  141. IUnknown *pSource, //in- Pointer to the source AD object
  142. IUnknown *pTarget, //in- Pointer to the target AD object
  143. IUnknown *pMainSettings, //in- Varset filled with the settings supplied by user
  144. IUnknown **ppPropsToSet //in,out - Varset filled with Prop-Value pairs that will be set
  145. // once all extension objects are executed.
  146. )
  147. {
  148. IVarSetPtr pVs = pMainSettings;
  149. _variant_t var;
  150. _bstr_t sGrpName, sServer, sAcct;
  151. HRESULT hr = S_OK;
  152. long rc = 0;
  153. TErrorDct err;
  154. WCHAR fileName[LEN_Path];
  155. // Get the Error log filename from the Varset
  156. var = pVs->get(GET_BSTR(DCTVS_Options_Logfile));
  157. wcscpy(fileName, (WCHAR*)V_BSTR(&var));
  158. VariantInit(&var);
  159. // Open the error log
  160. err.LogOpen(fileName, 1);
  161. // Process adding users to the source domain.
  162. var = pVs->get(GET_BSTR(DCTVS_AccountOptions_AddToGroupOnSourceDomain));
  163. if ( var.vt == VT_BSTR )
  164. {
  165. sGrpName = V_BSTR(&var);
  166. if ( sGrpName.length() > 0 )
  167. {
  168. var = pVs->get(GET_BSTR(DCTVS_Options_SourceServer));
  169. sServer = V_BSTR(&var);
  170. var = pVs->get(GET_BSTR(DCTVS_CopiedAccount_SourceSam));
  171. sAcct = V_BSTR(&var);
  172. rc = NetGroupDelUser((WCHAR*) sServer, (WCHAR *) sGrpName, (WCHAR *) sAcct);
  173. if ( rc != 0 )
  174. {
  175. hr = HRESULT_FROM_WIN32(rc);;
  176. err.SysMsgWrite(ErrW, rc, DCT_MSG_REMOVE_FROM_FAILED_SSD, (WCHAR *)sAcct, (WCHAR*)sGrpName, rc);
  177. }
  178. else
  179. {
  180. err.MsgWrite(0,DCT_MSG_REMOVE_FROM_GROUP_SS,(WCHAR *)sAcct,(WCHAR *)sGrpName);
  181. }
  182. }
  183. }
  184. // Now process the group on the target domain.
  185. var = pVs->get(GET_BSTR(DCTVS_AccountOptions_AddToGroup));
  186. if ( var.vt == VT_BSTR )
  187. {
  188. sGrpName = V_BSTR(&var);
  189. if ( sGrpName.length() > 0 )
  190. {
  191. var = pVs->get(GET_BSTR(DCTVS_Options_TargetServer));
  192. sServer = V_BSTR(&var);
  193. var = pVs->get(GET_BSTR(DCTVS_CopiedAccount_TargetSam));
  194. sAcct = V_BSTR(&var);
  195. rc = NetGroupDelUser((WCHAR*) sServer, (WCHAR *) sGrpName, (WCHAR *) sAcct);
  196. if ( rc != 0 )
  197. {
  198. hr = HRESULT_FROM_WIN32(rc);;
  199. err.SysMsgWrite(ErrW, rc, DCT_MSG_REMOVE_FROM_FAILED_SSD, (WCHAR *)sAcct, (WCHAR *)sGrpName, rc);
  200. }
  201. else
  202. {
  203. err.MsgWrite(0,DCT_MSG_REMOVE_FROM_GROUP_SS,(WCHAR *)sAcct,(WCHAR *)sGrpName);
  204. }
  205. }
  206. }
  207. err.LogClose();
  208. return hr;
  209. }