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.

249 lines
4.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(hr);
  42. }
  43. CAcl::~CAcl( )
  44. {
  45. delete _pDispMgr;
  46. }
  47. STDMETHODIMP
  48. CAcl::QueryInterface(
  49. REFIID iid,
  50. LPVOID FAR* ppv
  51. )
  52. {
  53. if (ppv == NULL) {
  54. RRETURN(E_POINTER);
  55. }
  56. if (IsEqualIID(iid, IID_IUnknown))
  57. {
  58. *ppv = (IADsAcl FAR *) this;
  59. }
  60. else if (IsEqualIID(iid, IID_IADsAcl))
  61. {
  62. *ppv = (IADsAcl FAR *) this;
  63. }
  64. else if (IsEqualIID(iid, IID_IDispatch))
  65. {
  66. *ppv = (IADsAcl FAR *) this;
  67. }
  68. else
  69. {
  70. *ppv = NULL;
  71. return E_NOINTERFACE;
  72. }
  73. AddRef();
  74. return NOERROR;
  75. }
  76. HRESULT
  77. CAcl::AllocateSecurityDescriptorObject(
  78. CAcl ** ppSecurityDescriptor
  79. )
  80. {
  81. CAcl FAR * pSecurityDescriptor = NULL;
  82. CDispatchMgr FAR * pDispMgr = NULL;
  83. HRESULT hr = S_OK;
  84. pSecurityDescriptor = new CAcl();
  85. if (pSecurityDescriptor == NULL) {
  86. hr = E_OUTOFMEMORY;
  87. }
  88. BAIL_ON_FAILURE(hr);
  89. pDispMgr = new CDispatchMgr;
  90. if (pDispMgr == NULL) {
  91. hr = E_OUTOFMEMORY;
  92. }
  93. BAIL_ON_FAILURE(hr);
  94. /*
  95. hr = LoadTypeInfoEntry(
  96. pDispMgr,
  97. LIBID_NDSOle,
  98. IID_IADsAcl,
  99. (IADsAcl *)pSecurityDescriptor,
  100. DISPID_REGULAR
  101. );
  102. BAIL_ON_FAILURE(hr);
  103. */
  104. pSecurityDescriptor->_pDispMgr = pDispMgr;
  105. *ppSecurityDescriptor = pSecurityDescriptor;
  106. RRETURN(hr);
  107. error:
  108. delete pDispMgr;
  109. RRETURN(hr);
  110. }
  111. // new stuff!
  112. STDMETHODIMP
  113. CAcl::get_Privileges(THIS_ long FAR * retval)
  114. {
  115. *retval = _dwPrivileges;
  116. RRETURN(S_OK);
  117. }
  118. STDMETHODIMP
  119. CAcl::put_Privileges(THIS_ long lnPrivileges)
  120. {
  121. _dwPrivileges = lnPrivileges;
  122. RRETURN(S_OK);
  123. }
  124. STDMETHODIMP
  125. CAcl::get_SubjectName(THIS_ BSTR FAR * retval)
  126. {
  127. HRESULT hr = S_OK;
  128. hr = ADsAllocString(_lpSubjectName, retval);
  129. RRETURN(hr);
  130. }
  131. STDMETHODIMP
  132. CAcl::put_SubjectName(THIS_ BSTR bstrSubjectName)
  133. {
  134. if (!bstrSubjectName) {
  135. RRETURN(E_FAIL);
  136. }
  137. if (_lpSubjectName) {
  138. FreeADsStr(_lpSubjectName);
  139. }
  140. _lpSubjectName= AllocADsStr(bstrSubjectName);
  141. if (!_lpSubjectName) {
  142. RRETURN(E_OUTOFMEMORY);
  143. }
  144. RRETURN(S_OK);
  145. }
  146. STDMETHODIMP
  147. CAcl::get_ProtectedAttrName(THIS_ BSTR FAR * retval)
  148. {
  149. HRESULT hr = S_OK;
  150. hr = ADsAllocString(_lpProtectedAttrName, retval);
  151. RRETURN(hr);
  152. }
  153. STDMETHODIMP
  154. CAcl::put_ProtectedAttrName(THIS_ BSTR bstrProtectedAttrName)
  155. {
  156. if (!bstrProtectedAttrName) {
  157. RRETURN(E_FAIL);
  158. }
  159. if (_lpProtectedAttrName) {
  160. FreeADsStr(_lpProtectedAttrName);
  161. }
  162. _lpProtectedAttrName= AllocADsStr(bstrProtectedAttrName);
  163. if (!_lpProtectedAttrName) {
  164. RRETURN(E_OUTOFMEMORY);
  165. }
  166. RRETURN(S_OK);
  167. }
  168. STDMETHODIMP
  169. CAcl::CopyAcl(THIS_ IDispatch FAR * FAR * ppAcl)
  170. {
  171. HRESULT hr = S_OK;
  172. IADsAcl * pSecDes = NULL;
  173. hr = CAcl::CreateSecurityDescriptor(
  174. IID_IADsAcl,
  175. (void **)&pSecDes
  176. );
  177. BAIL_ON_FAILURE(hr);
  178. hr = pSecDes->put_Privileges(_dwPrivileges);
  179. BAIL_ON_FAILURE(hr);
  180. hr = pSecDes->put_SubjectName(_lpSubjectName);
  181. BAIL_ON_FAILURE(hr);
  182. hr = pSecDes->put_ProtectedAttrName(_lpProtectedAttrName);
  183. BAIL_ON_FAILURE(hr);
  184. hr = pSecDes->QueryInterface(IID_IDispatch,
  185. (void**)ppAcl);
  186. BAIL_ON_FAILURE(hr);
  187. error:
  188. RRETURN(hr);
  189. }