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.

204 lines
7.2 KiB

  1. // RidSave.cpp : Implementation of CGetRidsApp and DLL registration.
  2. #include "stdafx.h"
  3. #include "GetRids.h"
  4. #include "RidSave.h"
  5. #include "ARExt.h"
  6. #include "ARExt_i.c"
  7. #include <iads.h>
  8. #include <AdsHlp.h>
  9. #include "resstr.h"
  10. #include "exldap.h"
  11. #include "TxtSid.h"
  12. //#import "\bin\McsVarSetMin.tlb" no_namespace
  13. #import "VarSet.tlb" no_namespace rename("property", "aproperty")
  14. /////////////////////////////////////////////////////////////////////////////
  15. // RidSave
  16. StringLoader gString;
  17. //---------------------------------------------------------------------------
  18. // Get and set methods for the properties.
  19. //---------------------------------------------------------------------------
  20. STDMETHODIMP RidSave::get_sName(BSTR *pVal)
  21. {
  22. *pVal = m_sName;
  23. return S_OK;
  24. }
  25. STDMETHODIMP RidSave::put_sName(BSTR newVal)
  26. {
  27. m_sName = newVal;
  28. return S_OK;
  29. }
  30. STDMETHODIMP RidSave::get_sDesc(BSTR *pVal)
  31. {
  32. *pVal = m_sDesc;
  33. return S_OK;
  34. }
  35. STDMETHODIMP RidSave::put_sDesc(BSTR newVal)
  36. {
  37. m_sDesc = newVal;
  38. return S_OK;
  39. }
  40. void VariantSidToString(_variant_t & varSid)
  41. {
  42. if ( varSid.vt == VT_BSTR )
  43. {
  44. return;
  45. }
  46. else if ( varSid.vt == ( VT_ARRAY | VT_UI1) )
  47. {
  48. // convert the array of bits to a string
  49. CLdapConnection c;
  50. LPBYTE pByte = NULL;
  51. WCHAR str[LEN_Path];
  52. SafeArrayAccessData(varSid.parray,(void**)&pByte);
  53. c.BytesToString(pByte,str,GetLengthSid(pByte));
  54. SafeArrayUnaccessData(varSid.parray);
  55. varSid = str;
  56. }
  57. else
  58. {
  59. varSid.ChangeType(VT_BSTR);
  60. }
  61. }
  62. //---------------------------------------------------------------------------
  63. // ProcessObject : This method doesn't do anything.
  64. //---------------------------------------------------------------------------
  65. STDMETHODIMP RidSave::PreProcessObject(
  66. IUnknown *pSource, //in- Pointer to the source AD object
  67. IUnknown *pTarget, //in- Pointer to the target AD object
  68. IUnknown *pMainSettings, //in- Varset filled with the settings supplied by user
  69. IUnknown **ppPropsToSet //in,out - Varset filled with Prop-Value pairs that will be set
  70. // once all extension objects are executed.
  71. )
  72. {
  73. IVarSetPtr pVs = pMainSettings;
  74. _variant_t var;
  75. _bstr_t sTemp;
  76. IADs * pAds = NULL;
  77. HRESULT hr = S_OK;
  78. DWORD rid = 0; // default to 0, if RID not found
  79. // We need to process users and groups only
  80. sTemp = pVs->get(GET_BSTR(DCTVS_CopiedAccount_Type));
  81. if (!sTemp.length())
  82. return HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY);
  83. if ( _wcsicmp((WCHAR*)sTemp,L"user") && _wcsicmp((WCHAR*)sTemp,L"group") )
  84. return S_OK;
  85. if ( pSource )
  86. {
  87. //Get the IADs pointer to manipulate properties
  88. hr = pSource->QueryInterface(IID_IADs, (void**) &pAds);
  89. if ( SUCCEEDED(hr) )
  90. {
  91. hr = pAds->Get(SysAllocString(L"objectSID"),&var);
  92. if ( SUCCEEDED(hr) )
  93. {
  94. // got the SID -- convert it to the proper format
  95. VariantSidToString(var);
  96. CLdapConnection e;
  97. BYTE sid[300];
  98. if ( e.StringToBytes(var.bstrVal,sid) )
  99. {
  100. // Get the rid
  101. UCHAR len = (* GetSidSubAuthorityCount(sid));
  102. PDWORD pRid = GetSidSubAuthority(sid,len-1);
  103. rid = (*pRid);
  104. }
  105. }
  106. pAds->Release();
  107. }
  108. }
  109. // save the RID
  110. pVs->put(GET_BSTR(DCTVS_CopiedAccount_SourceRID),(long)rid);
  111. return hr;
  112. }
  113. //---------------------------------------------------------------------------
  114. // ProcessObject : This method updates the UPN property of the object. It
  115. // first sees if a E-Mail is specified then it will set UPN
  116. // to that otherwise it builds it from SAMAccountName and the
  117. // Domain name
  118. //---------------------------------------------------------------------------
  119. STDMETHODIMP RidSave::ProcessObject(
  120. IUnknown *pSource, //in- Pointer to the source AD object
  121. IUnknown *pTarget, //in- Pointer to the target AD object
  122. IUnknown *pMainSettings, //in- Varset filled with the settings supplied by user
  123. IUnknown **ppPropsToSet //in,out - Varset filled with Prop-Value pairs that will be set
  124. // once all extension objects are executed.
  125. )
  126. {
  127. IVarSetPtr pVs = pMainSettings;
  128. _variant_t var;
  129. _bstr_t sTemp;
  130. IADs * pAds = NULL;
  131. HRESULT hr = S_OK;
  132. DWORD rid = 0; // default to 0, if RID not found
  133. // We need to process users and groups only
  134. sTemp = pVs->get(GET_BSTR(DCTVS_CopiedAccount_Type));
  135. if ( _wcsicmp((WCHAR*)sTemp,L"user") && _wcsicmp((WCHAR*)sTemp,L"group") )
  136. {
  137. return S_OK;
  138. }
  139. if ( pTarget )
  140. {
  141. //Get the IADs pointer to manipulate properties
  142. hr = pTarget->QueryInterface(IID_IADs, (void**) &pAds);
  143. if ( SUCCEEDED(hr) )
  144. {
  145. hr = pAds->Get(SysAllocString(L"objectSID"),&var);
  146. if ( SUCCEEDED(hr) )
  147. {
  148. // got the SID -- convert it to the proper format
  149. CLdapConnection e;
  150. BYTE sid[300];
  151. VariantSidToString(var);
  152. if ( e.StringToBytes(var.bstrVal,sid) )
  153. {
  154. // Get the rid
  155. UCHAR len = (* GetSidSubAuthorityCount(sid));
  156. PDWORD pRid = GetSidSubAuthority(sid,len-1);
  157. rid = (*pRid);
  158. }
  159. }
  160. pAds->Release();
  161. }
  162. }
  163. // save the RID
  164. pVs->put(GET_BSTR(DCTVS_CopiedAccount_TargetRID),(long)rid);
  165. return hr;
  166. }
  167. //---------------------------------------------------------------------------
  168. // ProcessUndo : We are not going to undo this.
  169. //---------------------------------------------------------------------------
  170. STDMETHODIMP RidSave::ProcessUndo(
  171. IUnknown *pSource, //in- Pointer to the source AD object
  172. IUnknown *pTarget, //in- Pointer to the target AD object
  173. IUnknown *pMainSettings, //in- Varset filled with the settings supplied by user
  174. IUnknown **ppPropsToSet //in,out - Varset filled with Prop-Value pairs that will be set
  175. // once all extension objects are executed.
  176. )
  177. {
  178. return S_OK;
  179. }