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.

334 lines
8.3 KiB

  1. /*++
  2. Copyright (c) 1998-2000 Microsoft Corporation
  3. Module Name:
  4. rnddo.cpp
  5. Abstract:
  6. This module contains implementation of CDirectoryObject object.
  7. --*/
  8. #include "stdafx.h"
  9. #include "rnddo.h"
  10. /////////////////////////////////////////////////////////////////////////////
  11. // ITDirectoryObject
  12. /////////////////////////////////////////////////////////////////////////////
  13. STDMETHODIMP CDirectoryObject::get_ObjectType(
  14. OUT DIRECTORY_OBJECT_TYPE * pObjectType
  15. )
  16. {
  17. if ( IsBadWritePtr(pObjectType, sizeof(DIRECTORY_OBJECT_TYPE) ) )
  18. {
  19. LOG((MSP_ERROR, "CDirectoryObject.get_ObjectType, invalid pointer"));
  20. return E_POINTER;
  21. }
  22. CLock Lock(m_lock);
  23. *pObjectType = m_Type;
  24. return S_OK;
  25. }
  26. STDMETHODIMP CDirectoryObject::get_SecurityDescriptor(
  27. OUT IDispatch ** ppSecDes
  28. )
  29. {
  30. LOG((MSP_INFO, "CDirectoryObject::get_SecurityDescriptor - enter"));
  31. //
  32. // Check parameters.
  33. //
  34. BAIL_IF_BAD_WRITE_PTR(ppSecDes, E_POINTER);
  35. //
  36. // Do the rest in our lock.
  37. //
  38. CLock Lock(m_lock);
  39. //
  40. // If we don't have an IDispatch security descriptor, convert it. This
  41. // will happen if PutConvertedSecurityDescriptor was called on object
  42. // creation but neither get_SecurityDescriptor nor
  43. // put_SecurityDescriptor have ever been called before on this object.
  44. //
  45. if ( ( m_pIDispatchSecurity == NULL ) && ( m_pSecDesData != NULL ) )
  46. {
  47. HRESULT hr;
  48. hr = ConvertSDToIDispatch( (PSECURITY_DESCRIPTOR) m_pSecDesData,
  49. &m_pIDispatchSecurity);
  50. if ( FAILED(hr) )
  51. {
  52. LOG((MSP_ERROR, "CDirectoryObject::get_SecurityDescriptor - "
  53. "invalid security descriptor - exit 0x%08x", hr));
  54. // make sure we don't return something
  55. *ppSecDes = NULL;
  56. m_pIDispatchSecurity = NULL;
  57. return hr;
  58. }
  59. //
  60. // We keep our own reference to the IDispatch. (ie ref = 1 now)
  61. //
  62. }
  63. //
  64. // Return our IDispatch pointer, (possibly NULL if the object has no
  65. // security descriptor), AddRefing if not NULL.
  66. //
  67. *ppSecDes = m_pIDispatchSecurity;
  68. if (m_pIDispatchSecurity)
  69. {
  70. m_pIDispatchSecurity->AddRef();
  71. }
  72. LOG((MSP_INFO, "CDirectoryObject::get_SecurityDescriptor - exit S_OK"));
  73. return S_OK;
  74. }
  75. STDMETHODIMP CDirectoryObject::put_SecurityDescriptor(
  76. IN IDispatch * pSecDes
  77. )
  78. {
  79. LOG((MSP_INFO, "CDirectoryObject::put_SecurityDescriptor - enter"));
  80. //
  81. // Make sure we are setting a valid interface pointer.
  82. // (We've always done it this way -- it also means that
  83. // you can't put a null security descriptor. The way to
  84. // "turn off" the security descriptor is to construct an
  85. // "empty" one or one granting everyone all access, and put_
  86. // that here.)
  87. //
  88. BAIL_IF_BAD_READ_PTR(pSecDes, E_POINTER);
  89. //
  90. // Do the rest in our critical section.
  91. //
  92. CLock Lock(m_lock);
  93. PSECURITY_DESCRIPTOR pSecDesData;
  94. DWORD dwSecDesSize;
  95. //
  96. // Convert the new security descriptor to a SECURITY_DESCRIPTOR.
  97. //
  98. HRESULT hr;
  99. hr = ConvertObjectToSDDispatch(pSecDes, &pSecDesData, &dwSecDesSize);
  100. if ( FAILED(hr) )
  101. {
  102. LOG((MSP_ERROR, "CDirectoryObject::put_SecurityDescriptor - "
  103. "ConvertObjectToSDDispatch failed - exit 0x%08x", hr));
  104. return hr;
  105. }
  106. //
  107. // Check if the new security descriptor's contents differ from the
  108. // old security descriptor's contents.
  109. //
  110. m_fSecurityDescriptorChanged =
  111. CheckIfSecurityDescriptorsDiffer(m_pSecDesData, m_dwSecDesSize,
  112. pSecDesData, dwSecDesSize);
  113. if (m_pIDispatchSecurity) // need this check because it's initially NULL
  114. {
  115. m_pIDispatchSecurity->Release();
  116. // this was newed on previous ConvertObjectToSDDispatch
  117. // or before PutConvertedSecurityDescriptor
  118. delete m_pSecDesData;
  119. }
  120. m_pIDispatchSecurity = pSecDes;
  121. m_pSecDesData = pSecDesData;
  122. m_dwSecDesSize = dwSecDesSize;
  123. m_pIDispatchSecurity->AddRef();
  124. LOG((MSP_INFO, "CDirectoryObject::put_SecurityDescriptor - exit S_OK"));
  125. return S_OK;
  126. }
  127. /* currently not exposed publicly, but nothing's stopping us from exposing it */
  128. STDMETHODIMP CDirectoryObject::get_SecurityDescriptorIsModified(
  129. OUT VARIANT_BOOL * pfIsModified
  130. )
  131. {
  132. LOG((MSP_INFO, "CDirectoryObject::get_SecurityDescriptorIsModified - "
  133. "enter"));
  134. //
  135. // Check parameters.
  136. //
  137. if ( IsBadWritePtr(pfIsModified, sizeof(VARIANT_BOOL) ) )
  138. {
  139. LOG((MSP_ERROR, "CDirectoryObject::get_SecurityDescriptorIsModified - "
  140. "enter"));
  141. return E_POINTER;
  142. }
  143. if ( m_fSecurityDescriptorChanged )
  144. {
  145. *pfIsModified = VARIANT_TRUE;
  146. }
  147. else
  148. {
  149. *pfIsModified = VARIANT_FALSE;
  150. }
  151. LOG((MSP_INFO, "CDirectoryObject::get_SecurityDescriptorIsModified - "
  152. "exit S_OK"));
  153. return S_OK;
  154. }
  155. // to keep the logic consistent this is not exposed publicly
  156. // this overrules our comparison... it's normally called with VARIANT_FALSE
  157. // to inform us that the object has been successfully written to the server
  158. // or that the previous put_SecurityDescriptor was the one from the server
  159. // rather than from the app.
  160. STDMETHODIMP CDirectoryObject::put_SecurityDescriptorIsModified(
  161. IN VARIANT_BOOL fIsModified
  162. )
  163. {
  164. LOG((MSP_INFO, "CDirectoryObject::put_SecurityDescriptorIsModified - "
  165. "enter"));
  166. if ( fIsModified )
  167. {
  168. m_fSecurityDescriptorChanged = TRUE;
  169. }
  170. else
  171. {
  172. m_fSecurityDescriptorChanged = FALSE;
  173. }
  174. LOG((MSP_INFO, "CDirectoryObject::put_SecurityDescriptorIsModified - "
  175. "exit S_OK"));
  176. return S_OK;
  177. }
  178. HRESULT CDirectoryObject::PutConvertedSecurityDescriptor(
  179. IN char * pSD,
  180. IN DWORD dwSize
  181. )
  182. {
  183. LOG((MSP_INFO, "CDirectoryObject::PutConvertedSecurityDescriptor - "
  184. "enter"));
  185. //
  186. // Return our data. We retain ownership of the pointer;
  187. // the caller must not delete it. (We may delete it later so the caller
  188. // must have newed it.)
  189. //
  190. m_pSecDesData = pSD;
  191. m_dwSecDesSize = dwSize;
  192. LOG((MSP_INFO, "CDirectoryObject::PutConvertedSecurityDescriptor - "
  193. "exit S_OK"));
  194. return S_OK;
  195. }
  196. HRESULT CDirectoryObject::GetConvertedSecurityDescriptor(
  197. OUT char ** ppSD,
  198. OUT DWORD * pdwSize
  199. )
  200. {
  201. LOG((MSP_INFO, "CDirectoryObject::GetConvertedSecurityDescriptor - "
  202. "enter"));
  203. //
  204. // Return our data. We retain ownership of the pointer;
  205. // the caller must not delete it.
  206. //
  207. *ppSD = (char *)m_pSecDesData;
  208. *pdwSize = m_dwSecDesSize;
  209. LOG((MSP_INFO, "CDirectoryObject::GetConvertedSecurityDescriptor - "
  210. "exit S_OK"));
  211. return S_OK;
  212. }
  213. /////////////////////////////////////////////////////////////////////////////
  214. void CDirectoryObject::FinalRelease(void)
  215. {
  216. LOG((MSP_INFO, "CDirectoryObject::FinalRelease - "
  217. "enter"));
  218. if ( NULL != m_pIDispatchSecurity )
  219. {
  220. m_pIDispatchSecurity->Release();
  221. m_pIDispatchSecurity = NULL;
  222. }
  223. if ( NULL != m_pSecDesData )
  224. {
  225. delete m_pSecDesData; // newed on last ConvertObjectToSDDispatch
  226. }
  227. if ( m_pFTM )
  228. {
  229. m_pFTM->Release();
  230. }
  231. LOG((MSP_INFO, "CDirectoryObject::FinalRelease - "
  232. "exit S_OK"));
  233. }
  234. HRESULT CDirectoryObject::FinalConstruct(void)
  235. {
  236. LOG((MSP_INFO, "CDirectoryObject::FinalConstruct - enter"));
  237. HRESULT hr = CoCreateFreeThreadedMarshaler( GetControllingUnknown(),
  238. & m_pFTM );
  239. if ( FAILED(hr) )
  240. {
  241. LOG((MSP_INFO, "CDirectoryObject::FinalConstruct - "
  242. "create FTM returned 0x%08x; exit", hr));
  243. return hr;
  244. }
  245. LOG((MSP_INFO, "CDirectoryObject::FinalConstruct - exit S_OK"));
  246. return S_OK;
  247. }
  248. // eof