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.

277 lines
5.0 KiB

  1. //---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995
  5. //
  6. // File: CAcl.cxx
  7. //
  8. // Contents: SecurityDescriptor object
  9. //
  10. // History: 11-1-95 krishnag Created.
  11. //
  12. //----------------------------------------------------------------------------
  13. #include "nds.hxx"
  14. #pragma hdrstop
  15. // Class CAcl
  16. DEFINE_IDispatch_Implementation(CAcl)
  17. CAcl::CAcl():
  18. _pDispMgr(NULL),
  19. _lpProtectedAttrName(NULL),
  20. _lpSubjectName(NULL),
  21. _dwPrivileges(0)
  22. {
  23. ENLIST_TRACKING(CAcl);
  24. }
  25. HRESULT
  26. CAcl::CreateSecurityDescriptor(
  27. REFIID riid,
  28. void **ppvObj
  29. )
  30. {
  31. CAcl FAR * pSecurityDescriptor = NULL;
  32. HRESULT hr = S_OK;
  33. hr = AllocateSecurityDescriptorObject(&pSecurityDescriptor);
  34. BAIL_ON_FAILURE(hr);
  35. hr = pSecurityDescriptor->QueryInterface(riid, ppvObj);
  36. BAIL_ON_FAILURE(hr);
  37. pSecurityDescriptor->Release();
  38. RRETURN(hr);
  39. error:
  40. delete pSecurityDescriptor;
  41. RRETURN_EXP_IF_ERR(hr);
  42. }
  43. CAcl::~CAcl( )
  44. {
  45. delete _pDispMgr;
  46. if (_lpProtectedAttrName)
  47. FreeADsMem(_lpProtectedAttrName);
  48. if (_lpSubjectName)
  49. FreeADsMem(_lpSubjectName);
  50. }
  51. STDMETHODIMP
  52. CAcl::QueryInterface(
  53. REFIID iid,
  54. LPVOID FAR* ppv
  55. )
  56. {
  57. if (ppv == NULL) {
  58. RRETURN(E_POINTER);
  59. }
  60. if (IsEqualIID(iid, IID_IUnknown))
  61. {
  62. *ppv = (IADsAcl FAR *) this;
  63. }
  64. else if (IsEqualIID(iid, IID_IADsAcl))
  65. {
  66. *ppv = (IADsAcl FAR *) this;
  67. }
  68. else if (IsEqualIID(iid, IID_IDispatch))
  69. {
  70. *ppv = (IADsAcl FAR *) this;
  71. }
  72. else if (IsEqualIID(iid, IID_ISupportErrorInfo))
  73. {
  74. *ppv = (ISupportErrorInfo FAR *) this;
  75. }
  76. else
  77. {
  78. *ppv = NULL;
  79. return E_NOINTERFACE;
  80. }
  81. AddRef();
  82. return NOERROR;
  83. }
  84. HRESULT
  85. CAcl::AllocateSecurityDescriptorObject(
  86. CAcl ** ppSecurityDescriptor
  87. )
  88. {
  89. CAcl FAR * pSecurityDescriptor = NULL;
  90. CDispatchMgr FAR * pDispMgr = NULL;
  91. HRESULT hr = S_OK;
  92. pSecurityDescriptor = new CAcl();
  93. if (pSecurityDescriptor == NULL) {
  94. hr = E_OUTOFMEMORY;
  95. }
  96. BAIL_ON_FAILURE(hr);
  97. pDispMgr = new CDispatchMgr;
  98. if (pDispMgr == NULL) {
  99. hr = E_OUTOFMEMORY;
  100. }
  101. BAIL_ON_FAILURE(hr);
  102. /*
  103. hr = LoadTypeInfoEntry(
  104. pDispMgr,
  105. LIBIDOle,
  106. IID_IADsAcl,
  107. (IADsAcl *)pSecurityDescriptor,
  108. DISPID_REGULAR
  109. );
  110. BAIL_ON_FAILURE(hr);
  111. */
  112. pSecurityDescriptor->_pDispMgr = pDispMgr;
  113. *ppSecurityDescriptor = pSecurityDescriptor;
  114. RRETURN(hr);
  115. error:
  116. delete pDispMgr;
  117. RRETURN(hr);
  118. }
  119. /* ISupportErrorInfo method */
  120. STDMETHODIMP
  121. CAcl::InterfaceSupportsErrorInfo(
  122. THIS_ REFIID riid
  123. )
  124. {
  125. if (IsEqualIID(riid, IID_IADsAcl)) {
  126. RRETURN(S_OK);
  127. } else {
  128. RRETURN(S_FALSE);
  129. }
  130. }
  131. // new stuff!
  132. STDMETHODIMP
  133. CAcl::get_Privileges(THIS_ long FAR * retval)
  134. {
  135. *retval = _dwPrivileges;
  136. RRETURN(S_OK);
  137. }
  138. STDMETHODIMP
  139. CAcl::put_Privileges(THIS_ long lnPrivileges)
  140. {
  141. _dwPrivileges = lnPrivileges;
  142. RRETURN(S_OK);
  143. }
  144. STDMETHODIMP
  145. CAcl::get_SubjectName(THIS_ BSTR FAR * retval)
  146. {
  147. HRESULT hr = S_OK;
  148. hr = ADsAllocString(_lpSubjectName, retval);
  149. RRETURN_EXP_IF_ERR(hr);
  150. }
  151. STDMETHODIMP
  152. CAcl::put_SubjectName(THIS_ BSTR bstrSubjectName)
  153. {
  154. if (!bstrSubjectName) {
  155. RRETURN_EXP_IF_ERR(E_FAIL);
  156. }
  157. if (_lpSubjectName) {
  158. FreeADsStr(_lpSubjectName);
  159. }
  160. _lpSubjectName = NULL;
  161. _lpSubjectName= AllocADsStr(bstrSubjectName);
  162. if (!_lpSubjectName) {
  163. RRETURN_EXP_IF_ERR(E_OUTOFMEMORY);
  164. }
  165. RRETURN(S_OK);
  166. }
  167. STDMETHODIMP
  168. CAcl::get_ProtectedAttrName(THIS_ BSTR FAR * retval)
  169. {
  170. HRESULT hr = S_OK;
  171. hr = ADsAllocString(_lpProtectedAttrName, retval);
  172. RRETURN_EXP_IF_ERR(hr);
  173. }
  174. STDMETHODIMP
  175. CAcl::put_ProtectedAttrName(THIS_ BSTR bstrProtectedAttrName)
  176. {
  177. if (!bstrProtectedAttrName) {
  178. RRETURN_EXP_IF_ERR(E_FAIL);
  179. }
  180. if (_lpProtectedAttrName) {
  181. FreeADsStr(_lpProtectedAttrName);
  182. }
  183. _lpProtectedAttrName = NULL;
  184. _lpProtectedAttrName= AllocADsStr(bstrProtectedAttrName);
  185. if (!_lpProtectedAttrName) {
  186. RRETURN_EXP_IF_ERR(E_OUTOFMEMORY);
  187. }
  188. RRETURN(S_OK);
  189. }
  190. STDMETHODIMP
  191. CAcl::CopyAcl(THIS_ IDispatch FAR * FAR * ppAcl)
  192. {
  193. HRESULT hr = S_OK;
  194. IADsAcl * pSecDes = NULL;
  195. hr = CAcl::CreateSecurityDescriptor(
  196. IID_IADsAcl,
  197. (void **)&pSecDes
  198. );
  199. BAIL_ON_FAILURE(hr);
  200. hr = pSecDes->put_Privileges(_dwPrivileges);
  201. BAIL_ON_FAILURE(hr);
  202. hr = pSecDes->put_SubjectName(_lpSubjectName);
  203. BAIL_ON_FAILURE(hr);
  204. hr = pSecDes->put_ProtectedAttrName(_lpProtectedAttrName);
  205. BAIL_ON_FAILURE(hr);
  206. hr = pSecDes->QueryInterface(IID_IDispatch,
  207. (void**)ppAcl);
  208. BAIL_ON_FAILURE(hr);
  209. error:
  210. if (pSecDes) {
  211. pSecDes->Release();
  212. }
  213. RRETURN_EXP_IF_ERR(hr);
  214. }