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.

356 lines
8.7 KiB

  1. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Microsoft WMIOLE DB Provider
  4. // (C) Copyright 1999 Microsoft Corporation. All Rights Reserved.
  5. //
  6. //
  7. // IObjAccessControl.cpp - IObjectAccessControl interface implementation
  8. //
  9. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  10. #include "headers.h"
  11. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  12. //
  13. // CImpIObjectAccessControl::GetObjectAccessRights
  14. //
  15. // Gets a list of all access rights
  16. //
  17. // Returns one of the following values:
  18. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  19. STDMETHODIMP CImpIObjectAccessControl::GetObjectAccessRights( SEC_OBJECT *pObject,
  20. ULONG *pcAccessEntries,
  21. EXPLICIT_ACCESS_W **prgAccessEntries)
  22. {
  23. HRESULT hr = S_OK;
  24. CSetStructuredExceptionHandler seh;
  25. TRY_BLOCK;
  26. // Serialize the object
  27. CAutoBlock cab(DATASOURCE->GetCriticalSection());
  28. g_pCError->ClearErrorInfo();
  29. if (!m_pObj->m_fDSOInitialized)
  30. {
  31. hr = E_UNEXPECTED;
  32. }
  33. else
  34. if(( *pcAccessEntries != 0 && *prgAccessEntries == NULL) ||
  35. !pcAccessEntries || !prgAccessEntries )
  36. {
  37. hr = E_INVALIDARG;
  38. }
  39. else
  40. if(SUCCEEDED(hr = IfValidSecObject(pObject)))
  41. {
  42. CBSTR strTemp(pObject->prgObjects->ObjectID.uName.pwszName);
  43. if(!m_pObj->m_pWbemWrap->IsValidObject(strTemp))
  44. {
  45. hr = SEC_E_INVALIDOBJECT;
  46. }
  47. }
  48. if(SUCCEEDED(hr))
  49. {
  50. ULONG ulExplicitAccess = 0;
  51. EXPLICIT_ACCESS_W *pAccessEntriesTemp = NULL;
  52. CBSTR strTemp(pObject->prgObjects[0].ObjectID.uName.pwszName);
  53. hr = m_pObj->m_pWbemWrap->GetObjectAccessRights(strTemp,
  54. &ulExplicitAccess,
  55. &pAccessEntriesTemp,
  56. *pcAccessEntries,
  57. *prgAccessEntries);
  58. }
  59. hr = hr == S_OK ? hr :g_pCError->PostHResult(hr,&IID_IObjectAccessControl);
  60. CATCH_BLOCK_HRESULT(hr,L"IObjectAccessControl::GetObjectAccessRights");
  61. return hr;
  62. }
  63. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  64. //
  65. // CImpIObjectAccessControl::GetObjectOwner
  66. //
  67. // Get the owner of the object
  68. //
  69. // Returns one of the following values:
  70. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  71. STDMETHODIMP CImpIObjectAccessControl::GetObjectOwner( SEC_OBJECT *pObject,TRUSTEE_W ** ppOwner)
  72. {
  73. HRESULT hr = S_OK;
  74. CSetStructuredExceptionHandler seh;
  75. TRY_BLOCK;
  76. // Serialize the object
  77. CAutoBlock cab(DATASOURCE->GetCriticalSection());
  78. g_pCError->ClearErrorInfo();
  79. if (m_pObj->m_fDSOInitialized)
  80. {
  81. hr = E_UNEXPECTED;
  82. }
  83. else
  84. if( *ppOwner == NULL)
  85. {
  86. hr = E_INVALIDARG;
  87. }
  88. else
  89. if(SUCCEEDED(hr = IfValidSecObject(pObject)))
  90. {
  91. {
  92. CBSTR strTemp(pObject->prgObjects->ObjectID.uName.pwszName);
  93. if(!m_pObj->m_pWbemWrap->IsValidObject(strTemp))
  94. {
  95. hr = SEC_E_INVALIDOBJECT;
  96. }
  97. }
  98. }
  99. if(SUCCEEDED(hr))
  100. {
  101. CBSTR strObj(pObject->prgObjects->ObjectID.uName.pwszName);
  102. hr = m_pObj->m_pWbemWrap->GetObjectOwner(strObj,ppOwner);
  103. }
  104. hr = hr == S_OK ? hr :g_pCError->PostHResult(hr,&IID_IObjectAccessControl);
  105. CATCH_BLOCK_HRESULT(hr,L"IObjectAccessControl::GetObjectOwner");
  106. return hr;
  107. }
  108. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  109. //
  110. // CImpIObjectAccessControl::IsObjectAccessAllowed
  111. //
  112. // Checks if the a trustee has the given access on the object
  113. //
  114. // Returns one of the following values:
  115. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  116. STDMETHODIMP CImpIObjectAccessControl::IsObjectAccessAllowed( SEC_OBJECT *pObject,
  117. EXPLICIT_ACCESS_W *pAccessEntry,
  118. BOOL *pfResult)
  119. {
  120. HRESULT hr = S_OK;
  121. CSetStructuredExceptionHandler seh;
  122. TRY_BLOCK;
  123. // Serialize the object
  124. CAutoBlock cab(DATASOURCE->GetCriticalSection());
  125. g_pCError->ClearErrorInfo();
  126. if (m_pObj->m_fDSOInitialized)
  127. {
  128. hr = E_UNEXPECTED;
  129. }
  130. else
  131. if(pAccessEntry == NULL || !pfResult)
  132. {
  133. hr = E_INVALIDARG;
  134. }
  135. else
  136. if(SUCCEEDED(hr = IfValidSecObject(pObject)))
  137. {
  138. CBSTR strTemp(pObject->prgObjects->ObjectID.uName.pwszName);
  139. if(!m_pObj->m_pWbemWrap->IsValidObject(strTemp))
  140. {
  141. hr = SEC_E_INVALIDOBJECT;
  142. }
  143. }
  144. if(SUCCEEDED(hr))
  145. {
  146. CBSTR strObj(pObject->prgObjects->ObjectID.uName.pwszName);
  147. hr = m_pObj->m_pWbemWrap->IsObjectAccessAllowed(strObj,pAccessEntry,pfResult);
  148. }
  149. hr = hr == S_OK ? hr :g_pCError->PostHResult(hr,&IID_IObjectAccessControl);
  150. CATCH_BLOCK_HRESULT(hr,L"IObjectAccessControl::IsObjectAccessAllowed");
  151. return hr;
  152. }
  153. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  154. //
  155. // CImpIObjectAccessControl::SetObjectAccessRights
  156. //
  157. // Set the AccessRights for a particular object
  158. //
  159. // Returns one of the following values:
  160. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  161. STDMETHODIMP CImpIObjectAccessControl::SetObjectAccessRights( SEC_OBJECT *pObject,
  162. ULONG cAccessEntries,
  163. EXPLICIT_ACCESS_W *prgAccessEntries)
  164. {
  165. HRESULT hr = S_OK;
  166. CSetStructuredExceptionHandler seh;
  167. TRY_BLOCK;
  168. // Serialize the object
  169. CAutoBlock cab(DATASOURCE->GetCriticalSection());
  170. g_pCError->ClearErrorInfo();
  171. if (m_pObj->m_fDSOInitialized)
  172. {
  173. hr = E_UNEXPECTED;
  174. }
  175. else
  176. if(( cAccessEntries != 0 && prgAccessEntries == NULL) ||
  177. !pObject)
  178. {
  179. hr = E_INVALIDARG;
  180. }
  181. else
  182. if(SUCCEEDED(hr = IfValidSecObject(pObject)))
  183. {
  184. if(cAccessEntries != 0)
  185. {
  186. CBSTR strTemp(pObject->prgObjects->ObjectID.uName.pwszName);
  187. if(!m_pObj->m_pWbemWrap->IsValidObject(strTemp))
  188. {
  189. hr = SEC_E_INVALIDOBJECT;
  190. }
  191. if(SUCCEEDED(hr))
  192. {
  193. ULONG ulExplicitAccess = 0;
  194. EXPLICIT_ACCESS_W *pAccessEntriesTemp = NULL;
  195. CBSTR strTemp(pObject->prgObjects[0].ObjectID.uName.pwszName);
  196. hr = m_pObj->m_pWbemWrap->SetObjectAccessRights(strTemp,
  197. cAccessEntries,
  198. prgAccessEntries);
  199. }
  200. }
  201. }
  202. hr = hr == S_OK ? hr :g_pCError->PostHResult(hr,&IID_IObjectAccessControl);
  203. CATCH_BLOCK_HRESULT(hr,L"IObjectAccessControl::SetObjectAccessRights");
  204. return hr;
  205. }
  206. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  207. //
  208. // CImpIObjectAccessControl::SetObjectOwner
  209. //
  210. // Set Owner for a particular object
  211. //
  212. // Returns one of the following values:
  213. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  214. STDMETHODIMP CImpIObjectAccessControl::SetObjectOwner( SEC_OBJECT *pObject,TRUSTEE_W *pOwner)
  215. {
  216. HRESULT hr = S_OK;
  217. CSetStructuredExceptionHandler seh;
  218. TRY_BLOCK;
  219. // Serialize the object
  220. CAutoBlock cab(DATASOURCE->GetCriticalSection());
  221. g_pCError->ClearErrorInfo();
  222. if (m_pObj->m_fDSOInitialized)
  223. {
  224. hr = E_UNEXPECTED;
  225. }
  226. else
  227. if(!pOwner)
  228. {
  229. hr = E_INVALIDARG;
  230. }
  231. else
  232. if(SUCCEEDED(hr = IfValidSecObject(pObject)))
  233. {
  234. CBSTR strTemp(pObject->prgObjects->ObjectID.uName.pwszName);
  235. if(!m_pObj->m_pWbemWrap->IsValidObject(strTemp))
  236. {
  237. hr = SEC_E_INVALIDOBJECT;
  238. }
  239. }
  240. if(SUCCEEDED(hr))
  241. {
  242. CBSTR strObj(pObject->prgObjects->ObjectID.uName.pwszName);
  243. hr = m_pObj->m_pWbemWrap->SetObjectOwner(strObj,pOwner);
  244. }
  245. hr = hr == S_OK ? hr :g_pCError->PostHResult(hr,&IID_IObjectAccessControl);
  246. CATCH_BLOCK_HRESULT(hr,L"IObjectAccessControl::SetObjectOwner");
  247. return hr;
  248. }
  249. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  250. //
  251. // CImpIObjectAccessControl::IfValidSecObject
  252. //
  253. // a function to validate SEC_OBJECT parameter
  254. //
  255. // Returns one of the following values:
  256. // E_INVALIDARG
  257. // SEC_E_INVALIDOBJECT
  258. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  259. STDMETHODIMP CImpIObjectAccessControl::IfValidSecObject(SEC_OBJECT *pObject)
  260. {
  261. HRESULT hr = S_OK;
  262. if(!pObject)
  263. {
  264. hr = E_INVALIDARG;
  265. }
  266. else
  267. if((pObject->cObjects != 0 && pObject->prgObjects == NULL) ||
  268. pObject->cObjects > 1)
  269. {
  270. hr = E_INVALIDARG;
  271. }
  272. else
  273. if(pObject->cObjects == 0 )
  274. {
  275. hr = SEC_E_INVALIDOBJECT;
  276. }
  277. else
  278. // WMIOLEDB allows setting/setting security for only one object
  279. if(pObject->cObjects != 1)
  280. {
  281. hr = E_INVALIDARG;
  282. }
  283. else if(pObject->prgObjects[0].guidObjectType != DBOBJECT_TABLE &&
  284. pObject->prgObjects[0].guidObjectType != DBOBJECT_DATABASE &&
  285. pObject->prgObjects[0].guidObjectType != DBOBJECT_WMIINSTANCE)
  286. {
  287. hr = SEC_E_INVALIDOBJECT;
  288. }
  289. else
  290. if(pObject->prgObjects->ObjectID.eKind != DBKIND_NAME)
  291. {
  292. hr = E_INVALIDARG;
  293. }
  294. return hr;
  295. }