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.

563 lines
10 KiB

  1. //---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995
  5. //
  6. // File: cSecurityDescriptor.cxx
  7. //
  8. // Contents: SecurityDescriptor object
  9. //
  10. // History: 11-1-95 krishnag Created.
  11. //
  12. //----------------------------------------------------------------------------
  13. #include "oleds.hxx"
  14. #pragma hdrstop
  15. // Class CSecurityDescriptor
  16. DEFINE_IDispatch_Implementation(CSecurityDescriptor)
  17. CSecurityDescriptor::CSecurityDescriptor():
  18. _pDispMgr(NULL),
  19. _lpOwner(NULL),
  20. _fOwnerDefaulted(FALSE),
  21. _lpGroup(NULL),
  22. _fGroupDefaulted(FALSE),
  23. _dwRevision(0),
  24. _dwControl(0),
  25. _pDAcl(NULL),
  26. _fDaclDefaulted(FALSE),
  27. _pSAcl(NULL),
  28. _fSaclDefaulted(FALSE)
  29. {
  30. ENLIST_TRACKING(CSecurityDescriptor);
  31. }
  32. HRESULT
  33. CSecurityDescriptor::CreateSecurityDescriptor(
  34. REFIID riid,
  35. void **ppvObj
  36. )
  37. {
  38. CSecurityDescriptor FAR * pSecurityDescriptor = NULL;
  39. HRESULT hr = S_OK;
  40. hr = AllocateSecurityDescriptorObject(&pSecurityDescriptor);
  41. BAIL_ON_FAILURE(hr);
  42. hr = pSecurityDescriptor->QueryInterface(riid, ppvObj);
  43. BAIL_ON_FAILURE(hr);
  44. pSecurityDescriptor->Release();
  45. RRETURN(hr);
  46. error:
  47. delete pSecurityDescriptor;
  48. RRETURN_EXP_IF_ERR(hr);
  49. }
  50. CSecurityDescriptor::~CSecurityDescriptor( )
  51. {
  52. delete _pDispMgr;
  53. if (_pDAcl) {
  54. _pDAcl->Release();
  55. }
  56. if (_pSAcl) {
  57. _pSAcl->Release();
  58. }
  59. if (_lpOwner) {
  60. FreeADsStr(_lpOwner);
  61. }
  62. if (_lpGroup) {
  63. FreeADsStr(_lpGroup);
  64. }
  65. }
  66. STDMETHODIMP
  67. CSecurityDescriptor::QueryInterface(
  68. REFIID iid,
  69. LPVOID FAR* ppv
  70. )
  71. {
  72. if (IsEqualIID(iid, IID_IUnknown))
  73. {
  74. *ppv = (IADsSecurityDescriptor FAR *) this;
  75. }
  76. else if (IsEqualIID(iid, IID_IADsSecurityDescriptor))
  77. {
  78. *ppv = (IADsSecurityDescriptor FAR *) this;
  79. }
  80. else if (IsEqualIID(iid, IID_IDispatch))
  81. {
  82. *ppv = (IADsSecurityDescriptor FAR *) this;
  83. }
  84. else if (IsEqualIID(iid, IID_ISupportErrorInfo))
  85. {
  86. *ppv = (ISupportErrorInfo FAR *) this;
  87. }
  88. else
  89. {
  90. *ppv = NULL;
  91. return E_NOINTERFACE;
  92. }
  93. AddRef();
  94. return NOERROR;
  95. }
  96. HRESULT
  97. CSecurityDescriptor::AllocateSecurityDescriptorObject(
  98. CSecurityDescriptor ** ppSecurityDescriptor
  99. )
  100. {
  101. CSecurityDescriptor FAR * pSecurityDescriptor = NULL;
  102. CDispatchMgr FAR * pDispMgr = NULL;
  103. HRESULT hr = S_OK;
  104. pSecurityDescriptor = new CSecurityDescriptor();
  105. if (pSecurityDescriptor == NULL) {
  106. hr = E_OUTOFMEMORY;
  107. }
  108. BAIL_ON_FAILURE(hr);
  109. pDispMgr = new CDispatchMgr;
  110. if (pDispMgr == NULL) {
  111. hr = E_OUTOFMEMORY;
  112. }
  113. BAIL_ON_FAILURE(hr);
  114. hr = LoadTypeInfoEntry(
  115. pDispMgr,
  116. LIBID_ADs,
  117. IID_IADsSecurityDescriptor,
  118. (IADsSecurityDescriptor *)pSecurityDescriptor,
  119. DISPID_REGULAR
  120. );
  121. BAIL_ON_FAILURE(hr);
  122. pSecurityDescriptor->_pDispMgr = pDispMgr;
  123. *ppSecurityDescriptor = pSecurityDescriptor;
  124. RRETURN(hr);
  125. error:
  126. delete pSecurityDescriptor;
  127. delete pDispMgr;
  128. RRETURN_EXP_IF_ERR(hr);
  129. }
  130. //
  131. // ISupportErrorInfo method
  132. //
  133. STDMETHODIMP
  134. CSecurityDescriptor::InterfaceSupportsErrorInfo(THIS_ REFIID riid)
  135. {
  136. if (IsEqualIID(riid, IID_IADsSecurityDescriptor)) {
  137. return S_OK;
  138. } else {
  139. return S_FALSE;
  140. }
  141. }
  142. STDMETHODIMP
  143. CSecurityDescriptor::get_DiscretionaryAcl(
  144. IDispatch FAR * FAR * retval
  145. )
  146. {
  147. if (_pDAcl) {
  148. //
  149. // Need to AddRef this pointer
  150. _pDAcl->AddRef();
  151. *retval = _pDAcl;
  152. }else {
  153. *retval = NULL;
  154. }
  155. RRETURN(S_OK);
  156. }
  157. STDMETHODIMP
  158. CSecurityDescriptor::put_DiscretionaryAcl(
  159. IDispatch FAR * pDiscretionaryAcl
  160. )
  161. {
  162. HRESULT hr = S_OK;
  163. if (_pDAcl) {
  164. _pDAcl->Release();
  165. }
  166. if (pDiscretionaryAcl) {
  167. hr = pDiscretionaryAcl->QueryInterface(
  168. IID_IADsAccessControlList,
  169. (void **)&_pDAcl
  170. );
  171. }else {
  172. _pDAcl = NULL;
  173. }
  174. RRETURN_EXP_IF_ERR(hr);
  175. }
  176. STDMETHODIMP
  177. CSecurityDescriptor::get_SystemAcl(
  178. IDispatch FAR * FAR * retval
  179. )
  180. {
  181. if (_pSAcl) {
  182. //
  183. // Need to AddRef this pointer
  184. //
  185. _pSAcl->AddRef();
  186. *retval = _pSAcl;
  187. }else {
  188. *retval = NULL;
  189. }
  190. RRETURN(S_OK);
  191. }
  192. STDMETHODIMP
  193. CSecurityDescriptor::put_SystemAcl(
  194. IDispatch FAR * pSystemAcl
  195. )
  196. {
  197. HRESULT hr = S_OK;
  198. if (_pSAcl) {
  199. _pSAcl->Release();
  200. }
  201. if (pSystemAcl) {
  202. hr = pSystemAcl->QueryInterface(
  203. IID_IADsAccessControlList,
  204. (void **)&_pSAcl
  205. );
  206. }else {
  207. _pSAcl = NULL;
  208. }
  209. RRETURN_EXP_IF_ERR(hr);
  210. }
  211. STDMETHODIMP
  212. CSecurityDescriptor::get_Revision(THIS_ long FAR * retval)
  213. {
  214. *retval = _dwRevision;
  215. RRETURN(S_OK);
  216. }
  217. STDMETHODIMP
  218. CSecurityDescriptor::put_Revision(THIS_ long lnRevision)
  219. {
  220. _dwRevision = lnRevision;
  221. RRETURN(S_OK);
  222. }
  223. STDMETHODIMP
  224. CSecurityDescriptor::get_Control(THIS_ long FAR * retval)
  225. {
  226. *retval = _dwControl;
  227. RRETURN(S_OK);
  228. }
  229. STDMETHODIMP
  230. CSecurityDescriptor::put_Control(THIS_ long lnControl)
  231. {
  232. _dwControl = lnControl;
  233. RRETURN(S_OK);
  234. }
  235. STDMETHODIMP
  236. CSecurityDescriptor::get_Owner(THIS_ BSTR FAR * retval)
  237. {
  238. HRESULT hr = S_OK;
  239. hr = ADsAllocString(_lpOwner, retval);
  240. RRETURN_EXP_IF_ERR(hr);
  241. }
  242. STDMETHODIMP
  243. CSecurityDescriptor::put_Owner(THIS_ BSTR bstrOwner)
  244. {
  245. if (_lpOwner) {
  246. FreeADsStr(_lpOwner);
  247. }
  248. if (!bstrOwner) {
  249. _lpOwner = NULL;
  250. }
  251. else {
  252. _lpOwner = AllocADsStr(bstrOwner);
  253. if (!_lpOwner) {
  254. RRETURN(E_OUTOFMEMORY);
  255. }
  256. }
  257. RRETURN(S_OK);
  258. }
  259. STDMETHODIMP
  260. CSecurityDescriptor::get_Group(THIS_ BSTR FAR * retval)
  261. {
  262. HRESULT hr = S_OK;
  263. hr = ADsAllocString(_lpGroup, retval);
  264. RRETURN_EXP_IF_ERR(hr);
  265. }
  266. STDMETHODIMP
  267. CSecurityDescriptor::put_Group(THIS_ BSTR bstrGroup)
  268. {
  269. if (_lpGroup) {
  270. FreeADsStr(_lpGroup);
  271. }
  272. if (!bstrGroup) {
  273. _lpGroup = NULL;
  274. }
  275. else {
  276. _lpGroup = AllocADsStr(bstrGroup);
  277. if (!_lpGroup) {
  278. RRETURN_EXP_IF_ERR(E_OUTOFMEMORY);
  279. }
  280. }
  281. RRETURN(S_OK);
  282. }
  283. STDMETHODIMP
  284. CSecurityDescriptor::CopySecurityDescriptor(THIS_ IDispatch FAR * FAR * ppSecurityDescriptor)
  285. {
  286. HRESULT hr = S_OK;
  287. IADsSecurityDescriptor * pSecDes = NULL;
  288. IDispatch *pTargetDACL = NULL;
  289. IDispatch *pTargetSACL = NULL;
  290. IDispatch * pDisp = NULL;
  291. hr = CoCreateInstance(
  292. CLSID_SecurityDescriptor,
  293. NULL,
  294. CLSCTX_INPROC_SERVER,
  295. IID_IADsSecurityDescriptor,
  296. (void **)&pSecDes
  297. );
  298. BAIL_ON_FAILURE(hr);
  299. if (_lpOwner) {
  300. hr = pSecDes->put_Owner(_lpOwner);
  301. BAIL_ON_FAILURE(hr);
  302. }
  303. if (_lpGroup) {
  304. hr = pSecDes->put_Group(_lpGroup);
  305. BAIL_ON_FAILURE(hr);
  306. }
  307. hr = pSecDes->put_Revision(_dwRevision);
  308. BAIL_ON_FAILURE(hr);
  309. hr = pSecDes->put_Control((DWORD)_dwControl);
  310. BAIL_ON_FAILURE(hr);
  311. if (_pDAcl) {
  312. hr = _pDAcl->CopyAccessList(&pTargetDACL);
  313. BAIL_ON_FAILURE(hr);
  314. hr = pSecDes->put_DiscretionaryAcl(pTargetDACL);
  315. BAIL_ON_FAILURE(hr);
  316. }
  317. if (_pSAcl) {
  318. hr = _pSAcl->CopyAccessList(&pTargetSACL);
  319. BAIL_ON_FAILURE(hr);
  320. hr = pSecDes->put_SystemAcl(pTargetSACL);
  321. BAIL_ON_FAILURE(hr);
  322. }
  323. hr = pSecDes->QueryInterface(
  324. IID_IDispatch,
  325. (void**)&pDisp
  326. );
  327. BAIL_ON_FAILURE(hr);
  328. *ppSecurityDescriptor = pDisp;
  329. cleanup:
  330. if (pTargetSACL) {
  331. pTargetSACL->Release();
  332. }
  333. if (pTargetDACL) {
  334. pTargetDACL->Release();
  335. }
  336. if (pSecDes) {
  337. pSecDes->Release();
  338. }
  339. RRETURN_EXP_IF_ERR(hr);
  340. error:
  341. *ppSecurityDescriptor = NULL;
  342. goto cleanup;
  343. }
  344. STDMETHODIMP
  345. CSecurityDescriptor::get_OwnerDefaulted(THIS_ VARIANT_BOOL FAR* retval)
  346. {
  347. if (_fOwnerDefaulted) {
  348. *retval = VARIANT_TRUE;
  349. }else{
  350. *retval = VARIANT_FALSE;
  351. }
  352. RRETURN(S_OK);
  353. }
  354. STDMETHODIMP
  355. CSecurityDescriptor::put_OwnerDefaulted(THIS_ VARIANT_BOOL fOwnerDefaulted)
  356. {
  357. if (fOwnerDefaulted == VARIANT_TRUE) {
  358. _fOwnerDefaulted = TRUE;
  359. }else {
  360. _fOwnerDefaulted = FALSE;
  361. }
  362. RRETURN(S_OK);
  363. }
  364. STDMETHODIMP
  365. CSecurityDescriptor::get_GroupDefaulted(THIS_ VARIANT_BOOL FAR* retval)
  366. {
  367. if (_fGroupDefaulted) {
  368. *retval = VARIANT_TRUE;
  369. }else{
  370. *retval = VARIANT_FALSE;
  371. }
  372. RRETURN(S_OK);
  373. }
  374. STDMETHODIMP
  375. CSecurityDescriptor::put_GroupDefaulted(THIS_ VARIANT_BOOL fGroupDefaulted)
  376. {
  377. if (fGroupDefaulted == VARIANT_TRUE) {
  378. _fGroupDefaulted = TRUE;
  379. }else {
  380. _fGroupDefaulted = FALSE;
  381. }
  382. RRETURN(S_OK);
  383. }
  384. STDMETHODIMP
  385. CSecurityDescriptor::get_DaclDefaulted(THIS_ VARIANT_BOOL FAR* retval)
  386. {
  387. if (_fDaclDefaulted) {
  388. *retval = VARIANT_TRUE;
  389. }else{
  390. *retval = VARIANT_FALSE;
  391. }
  392. RRETURN(S_OK);
  393. }
  394. STDMETHODIMP
  395. CSecurityDescriptor::put_DaclDefaulted(THIS_ VARIANT_BOOL fDaclDefaulted)
  396. {
  397. if (fDaclDefaulted == VARIANT_TRUE) {
  398. _fDaclDefaulted = TRUE;
  399. }else {
  400. _fDaclDefaulted = FALSE;
  401. }
  402. RRETURN(S_OK);
  403. }
  404. STDMETHODIMP
  405. CSecurityDescriptor::get_SaclDefaulted(THIS_ VARIANT_BOOL FAR* retval)
  406. {
  407. if (_fSaclDefaulted) {
  408. *retval = VARIANT_TRUE;
  409. }else{
  410. *retval = VARIANT_FALSE;
  411. }
  412. RRETURN(S_OK);
  413. }
  414. STDMETHODIMP
  415. CSecurityDescriptor::put_SaclDefaulted(THIS_ VARIANT_BOOL fSaclDefaulted)
  416. {
  417. if (fSaclDefaulted == VARIANT_TRUE) {
  418. _fSaclDefaulted = TRUE;
  419. }else {
  420. _fSaclDefaulted = FALSE;
  421. }
  422. RRETURN(S_OK);
  423. }
  424.