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.

278 lines
5.3 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 pSecurityDescriptor;
  117. delete pDispMgr;
  118. RRETURN(hr);
  119. }
  120. /* ISupportErrorInfo method */
  121. STDMETHODIMP
  122. CAcl::InterfaceSupportsErrorInfo(
  123. THIS_ REFIID riid
  124. )
  125. {
  126. if (IsEqualIID(riid, IID_IADsAcl)) {
  127. RRETURN(S_OK);
  128. } else {
  129. RRETURN(S_FALSE);
  130. }
  131. }
  132. // new stuff!
  133. STDMETHODIMP
  134. CAcl::get_Privileges(THIS_ long FAR * retval)
  135. {
  136. *retval = _dwPrivileges;
  137. RRETURN(S_OK);
  138. }
  139. STDMETHODIMP
  140. CAcl::put_Privileges(THIS_ long lnPrivileges)
  141. {
  142. _dwPrivileges = lnPrivileges;
  143. RRETURN(S_OK);
  144. }
  145. STDMETHODIMP
  146. CAcl::get_SubjectName(THIS_ BSTR FAR * retval)
  147. {
  148. HRESULT hr = S_OK;
  149. hr = ADsAllocString(_lpSubjectName, retval);
  150. RRETURN_EXP_IF_ERR(hr);
  151. }
  152. STDMETHODIMP
  153. CAcl::put_SubjectName(THIS_ BSTR bstrSubjectName)
  154. {
  155. if (!bstrSubjectName) {
  156. RRETURN_EXP_IF_ERR(E_FAIL);
  157. }
  158. if (_lpSubjectName) {
  159. FreeADsStr(_lpSubjectName);
  160. }
  161. _lpSubjectName = NULL;
  162. _lpSubjectName= AllocADsStr(bstrSubjectName);
  163. if (!_lpSubjectName) {
  164. RRETURN_EXP_IF_ERR(E_OUTOFMEMORY);
  165. }
  166. RRETURN(S_OK);
  167. }
  168. STDMETHODIMP
  169. CAcl::get_ProtectedAttrName(THIS_ BSTR FAR * retval)
  170. {
  171. HRESULT hr = S_OK;
  172. hr = ADsAllocString(_lpProtectedAttrName, retval);
  173. RRETURN_EXP_IF_ERR(hr);
  174. }
  175. STDMETHODIMP
  176. CAcl::put_ProtectedAttrName(THIS_ BSTR bstrProtectedAttrName)
  177. {
  178. if (!bstrProtectedAttrName) {
  179. RRETURN_EXP_IF_ERR(E_FAIL);
  180. }
  181. if (_lpProtectedAttrName) {
  182. FreeADsStr(_lpProtectedAttrName);
  183. }
  184. _lpProtectedAttrName = NULL;
  185. _lpProtectedAttrName= AllocADsStr(bstrProtectedAttrName);
  186. if (!_lpProtectedAttrName) {
  187. RRETURN_EXP_IF_ERR(E_OUTOFMEMORY);
  188. }
  189. RRETURN(S_OK);
  190. }
  191. STDMETHODIMP
  192. CAcl::CopyAcl(THIS_ IDispatch FAR * FAR * ppAcl)
  193. {
  194. HRESULT hr = S_OK;
  195. IADsAcl * pSecDes = NULL;
  196. hr = CAcl::CreateSecurityDescriptor(
  197. IID_IADsAcl,
  198. (void **)&pSecDes
  199. );
  200. BAIL_ON_FAILURE(hr);
  201. hr = pSecDes->put_Privileges(_dwPrivileges);
  202. BAIL_ON_FAILURE(hr);
  203. hr = pSecDes->put_SubjectName(_lpSubjectName);
  204. BAIL_ON_FAILURE(hr);
  205. hr = pSecDes->put_ProtectedAttrName(_lpProtectedAttrName);
  206. BAIL_ON_FAILURE(hr);
  207. hr = pSecDes->QueryInterface(IID_IDispatch,
  208. (void**)ppAcl);
  209. BAIL_ON_FAILURE(hr);
  210. error:
  211. if (pSecDes) {
  212. pSecDes->Release();
  213. }
  214. RRETURN_EXP_IF_ERR(hr);
  215. }