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.

569 lines
9.9 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 pDispMgr;
  127. RRETURN_EXP_IF_ERR(hr);
  128. }
  129. //
  130. // ISupportErrorInfo method
  131. //
  132. STDMETHODIMP
  133. CSecurityDescriptor::InterfaceSupportsErrorInfo(THIS_ REFIID riid)
  134. {
  135. if (IsEqualIID(riid, IID_IADsSecurityDescriptor)) {
  136. return S_OK;
  137. } else {
  138. return S_FALSE;
  139. }
  140. }
  141. STDMETHODIMP
  142. CSecurityDescriptor::get_DiscretionaryAcl(
  143. IDispatch FAR * FAR * retval
  144. )
  145. {
  146. if (_pDAcl) {
  147. //
  148. // Need to AddRef this pointer
  149. _pDAcl->AddRef();
  150. *retval = _pDAcl;
  151. }else {
  152. *retval = NULL;
  153. }
  154. RRETURN(S_OK);
  155. }
  156. STDMETHODIMP
  157. CSecurityDescriptor::put_DiscretionaryAcl(
  158. IDispatch FAR * pDiscretionaryAcl
  159. )
  160. {
  161. HRESULT hr = S_OK;
  162. if (_pDAcl) {
  163. _pDAcl->Release();
  164. }
  165. if (pDiscretionaryAcl) {
  166. hr = pDiscretionaryAcl->QueryInterface(
  167. IID_IADsAccessControlList,
  168. (void **)&_pDAcl
  169. );
  170. }else {
  171. _pDAcl = NULL;
  172. }
  173. RRETURN_EXP_IF_ERR(hr);
  174. }
  175. STDMETHODIMP
  176. CSecurityDescriptor::get_SystemAcl(
  177. IDispatch FAR * FAR * retval
  178. )
  179. {
  180. if (_pSAcl) {
  181. //
  182. // Need to AddRef this pointer
  183. //
  184. _pSAcl->AddRef();
  185. *retval = _pSAcl;
  186. }else {
  187. *retval = NULL;
  188. }
  189. RRETURN(S_OK);
  190. }
  191. STDMETHODIMP
  192. CSecurityDescriptor::put_SystemAcl(
  193. IDispatch FAR * pSystemAcl
  194. )
  195. {
  196. HRESULT hr = S_OK;
  197. if (_pSAcl) {
  198. _pSAcl->Release();
  199. }
  200. if (pSystemAcl) {
  201. hr = pSystemAcl->QueryInterface(
  202. IID_IADsAccessControlList,
  203. (void **)&_pSAcl
  204. );
  205. }else {
  206. _pSAcl = NULL;
  207. }
  208. RRETURN_EXP_IF_ERR(hr);
  209. }
  210. STDMETHODIMP
  211. CSecurityDescriptor::get_Revision(THIS_ long FAR * retval)
  212. {
  213. *retval = _dwRevision;
  214. RRETURN(S_OK);
  215. }
  216. STDMETHODIMP
  217. CSecurityDescriptor::put_Revision(THIS_ long lnRevision)
  218. {
  219. _dwRevision = lnRevision;
  220. RRETURN(S_OK);
  221. }
  222. STDMETHODIMP
  223. CSecurityDescriptor::get_Control(THIS_ long FAR * retval)
  224. {
  225. *retval = _dwControl;
  226. RRETURN(S_OK);
  227. }
  228. STDMETHODIMP
  229. CSecurityDescriptor::put_Control(THIS_ long lnControl)
  230. {
  231. _dwControl = lnControl;
  232. RRETURN(S_OK);
  233. }
  234. STDMETHODIMP
  235. CSecurityDescriptor::get_Owner(THIS_ BSTR FAR * retval)
  236. {
  237. HRESULT hr = S_OK;
  238. hr = ADsAllocString(_lpOwner, retval);
  239. RRETURN_EXP_IF_ERR(hr);
  240. }
  241. STDMETHODIMP
  242. CSecurityDescriptor::put_Owner(THIS_ BSTR bstrOwner)
  243. {
  244. if (_lpOwner) {
  245. FreeADsStr(_lpOwner);
  246. }
  247. if (!bstrOwner) {
  248. _lpOwner = NULL;
  249. }
  250. else {
  251. _lpOwner = AllocADsStr(bstrOwner);
  252. if (!_lpOwner) {
  253. RRETURN(E_OUTOFMEMORY);
  254. }
  255. }
  256. RRETURN(S_OK);
  257. }
  258. STDMETHODIMP
  259. CSecurityDescriptor::get_Group(THIS_ BSTR FAR * retval)
  260. {
  261. HRESULT hr = S_OK;
  262. hr = ADsAllocString(_lpGroup, retval);
  263. RRETURN_EXP_IF_ERR(hr);
  264. }
  265. STDMETHODIMP
  266. CSecurityDescriptor::put_Group(THIS_ BSTR bstrGroup)
  267. {
  268. if (_lpGroup) {
  269. FreeADsStr(_lpGroup);
  270. }
  271. if (!bstrGroup) {
  272. _lpGroup = NULL;
  273. }
  274. else {
  275. _lpGroup = AllocADsStr(bstrGroup);
  276. if (!_lpGroup) {
  277. RRETURN_EXP_IF_ERR(E_OUTOFMEMORY);
  278. }
  279. }
  280. RRETURN(S_OK);
  281. }
  282. STDMETHODIMP
  283. CSecurityDescriptor::CopySecurityDescriptor(THIS_ IDispatch FAR * FAR * ppSecurityDescriptor)
  284. {
  285. HRESULT hr = S_OK;
  286. IADsSecurityDescriptor * pSecDes = NULL;
  287. IDispatch *pTargetDACL = NULL;
  288. IDispatch *pTargetSACL = NULL;
  289. IDispatch * pDisp = NULL;
  290. hr = CoCreateInstance(
  291. CLSID_SecurityDescriptor,
  292. NULL,
  293. CLSCTX_INPROC_SERVER,
  294. IID_IADsSecurityDescriptor,
  295. (void **)&pSecDes
  296. );
  297. BAIL_ON_FAILURE(hr);
  298. if (_lpOwner) {
  299. hr = pSecDes->put_Owner(_lpOwner);
  300. BAIL_ON_FAILURE(hr);
  301. }
  302. if (_lpGroup) {
  303. hr = pSecDes->put_Group(_lpGroup);
  304. BAIL_ON_FAILURE(hr);
  305. }
  306. hr = pSecDes->put_Revision(_dwRevision);
  307. BAIL_ON_FAILURE(hr);
  308. hr = pSecDes->put_Control((DWORD)_dwControl);
  309. BAIL_ON_FAILURE(hr);
  310. if (_pDAcl) {
  311. hr = _pDAcl->CopyAccessList(&pTargetDACL);
  312. BAIL_ON_FAILURE(hr);
  313. hr = pSecDes->put_DiscretionaryAcl(pTargetDACL);
  314. BAIL_ON_FAILURE(hr);
  315. }
  316. if (_pSAcl) {
  317. hr = _pSAcl->CopyAccessList(&pTargetSACL);
  318. BAIL_ON_FAILURE(hr);
  319. hr = pSecDes->put_SystemAcl(pTargetSACL);
  320. BAIL_ON_FAILURE(hr);
  321. }
  322. hr = pSecDes->QueryInterface(
  323. IID_IDispatch,
  324. (void**)&pDisp
  325. );
  326. BAIL_ON_FAILURE(hr);
  327. *ppSecurityDescriptor = pDisp;
  328. cleanup:
  329. if (pTargetSACL) {
  330. pTargetSACL->Release();
  331. }
  332. if (pTargetDACL) {
  333. pTargetDACL->Release();
  334. }
  335. if (pSecDes) {
  336. pSecDes->Release();
  337. }
  338. RRETURN_EXP_IF_ERR(hr);
  339. error:
  340. *ppSecurityDescriptor = NULL;
  341. if (pTargetDACL) {
  342. pTargetDACL->Release();
  343. }
  344. if (pTargetSACL) {
  345. pTargetSACL->Release();
  346. }
  347. goto cleanup;
  348. }
  349. STDMETHODIMP
  350. CSecurityDescriptor::get_OwnerDefaulted(THIS_ VARIANT_BOOL FAR* retval)
  351. {
  352. if (_fOwnerDefaulted) {
  353. *retval = VARIANT_TRUE;
  354. }else{
  355. *retval = VARIANT_FALSE;
  356. }
  357. RRETURN(S_OK);
  358. }
  359. STDMETHODIMP
  360. CSecurityDescriptor::put_OwnerDefaulted(THIS_ VARIANT_BOOL fOwnerDefaulted)
  361. {
  362. if (fOwnerDefaulted == VARIANT_TRUE) {
  363. _fOwnerDefaulted = TRUE;
  364. }else {
  365. _fOwnerDefaulted = FALSE;
  366. }
  367. RRETURN(S_OK);
  368. }
  369. STDMETHODIMP
  370. CSecurityDescriptor::get_GroupDefaulted(THIS_ VARIANT_BOOL FAR* retval)
  371. {
  372. if (_fGroupDefaulted) {
  373. *retval = VARIANT_TRUE;
  374. }else{
  375. *retval = VARIANT_FALSE;
  376. }
  377. RRETURN(S_OK);
  378. }
  379. STDMETHODIMP
  380. CSecurityDescriptor::put_GroupDefaulted(THIS_ VARIANT_BOOL fGroupDefaulted)
  381. {
  382. if (fGroupDefaulted == VARIANT_TRUE) {
  383. _fGroupDefaulted = TRUE;
  384. }else {
  385. _fGroupDefaulted = FALSE;
  386. }
  387. RRETURN(S_OK);
  388. }
  389. STDMETHODIMP
  390. CSecurityDescriptor::get_DaclDefaulted(THIS_ VARIANT_BOOL FAR* retval)
  391. {
  392. if (_fDaclDefaulted) {
  393. *retval = VARIANT_TRUE;
  394. }else{
  395. *retval = VARIANT_FALSE;
  396. }
  397. RRETURN(S_OK);
  398. }
  399. STDMETHODIMP
  400. CSecurityDescriptor::put_DaclDefaulted(THIS_ VARIANT_BOOL fDaclDefaulted)
  401. {
  402. if (fDaclDefaulted == VARIANT_TRUE) {
  403. _fDaclDefaulted = TRUE;
  404. }else {
  405. _fDaclDefaulted = FALSE;
  406. }
  407. RRETURN(S_OK);
  408. }
  409. STDMETHODIMP
  410. CSecurityDescriptor::get_SaclDefaulted(THIS_ VARIANT_BOOL FAR* retval)
  411. {
  412. if (_fSaclDefaulted) {
  413. *retval = VARIANT_TRUE;
  414. }else{
  415. *retval = VARIANT_FALSE;
  416. }
  417. RRETURN(S_OK);
  418. }
  419. STDMETHODIMP
  420. CSecurityDescriptor::put_SaclDefaulted(THIS_ VARIANT_BOOL fSaclDefaulted)
  421. {
  422. if (fSaclDefaulted == VARIANT_TRUE) {
  423. _fSaclDefaulted = TRUE;
  424. }else {
  425. _fSaclDefaulted = FALSE;
  426. }
  427. RRETURN(S_OK);
  428. }
  429.