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.

239 lines
5.0 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995.
  5. //
  6. // File: libmain.cxx
  7. //
  8. // Contents: LibMain for nds.dll
  9. //
  10. // Functions: LibMain, DllGetClassObject
  11. //
  12. // History: 25-Oct-94 KrishnaG Created.
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "nds.hxx"
  16. #pragma hdrstop
  17. HRESULT
  18. ConvertSecDesToNDSAclVarArray(
  19. IADsSecurityDescriptor *pSecDes,
  20. PVARIANT pvarNDSAcl
  21. )
  22. {
  23. IADsAccessControlList FAR * pDiscAcl = NULL;
  24. IDispatch FAR * pDispatch = NULL;
  25. HRESULT hr = S_OK;
  26. hr = pSecDes->get_DiscretionaryAcl(
  27. &pDispatch
  28. );
  29. BAIL_ON_FAILURE(hr);
  30. if (!pDispatch) {
  31. hr = E_FAIL;
  32. goto error;
  33. }
  34. hr = pDispatch->QueryInterface(
  35. IID_IADsAccessControlList,
  36. (void **)&pDiscAcl
  37. );
  38. BAIL_ON_FAILURE(hr);
  39. hr = ConvertAccessControlListToNDSAclVarArray(
  40. pDiscAcl,
  41. pvarNDSAcl
  42. );
  43. BAIL_ON_FAILURE(hr);
  44. error:
  45. if (pDispatch) {
  46. pDispatch->Release();
  47. }
  48. if (pDiscAcl) {
  49. pDiscAcl->Release();
  50. }
  51. RRETURN(hr);
  52. }
  53. HRESULT
  54. ConvertAccessControlListToNDSAclVarArray(
  55. IADsAccessControlList FAR * pAccessList,
  56. PVARIANT pvarNDSAcl
  57. )
  58. {
  59. IUnknown * pUnknown = NULL;
  60. IEnumVARIANT * pEnumerator = NULL;
  61. HRESULT hr = S_OK;
  62. DWORD i = 0;
  63. VARIANT varAce;
  64. DWORD dwAceCount = 0;
  65. DWORD cReturned = 0;
  66. IADsAccessControlEntry FAR * pAccessControlEntry = NULL;
  67. VARIANT varNDSAce;
  68. SAFEARRAY *aList = NULL;
  69. SAFEARRAYBOUND aBound;
  70. hr = pAccessList->get_AceCount((long *)&dwAceCount);
  71. BAIL_ON_FAILURE(hr);
  72. hr = pAccessList->get__NewEnum(
  73. &pUnknown
  74. );
  75. BAIL_ON_FAILURE(hr);
  76. hr = pUnknown->QueryInterface(
  77. IID_IEnumVARIANT,
  78. (void FAR * FAR *)&pEnumerator
  79. );
  80. BAIL_ON_FAILURE(hr);
  81. VariantInit(pvarNDSAcl);
  82. aBound.lLbound = 0;
  83. aBound.cElements = dwAceCount;
  84. aList = SafeArrayCreate( VT_VARIANT, 1, &aBound );
  85. if ( aList == NULL )
  86. {
  87. hr = E_OUTOFMEMORY;
  88. BAIL_ON_FAILURE(hr);
  89. }
  90. for (i = 0; i < dwAceCount; i++) {
  91. VariantInit(&varAce);
  92. hr = pEnumerator->Next(
  93. 1,
  94. &varAce,
  95. &cReturned
  96. );
  97. CONTINUE_ON_FAILURE(hr);
  98. hr = (V_DISPATCH(&varAce))->QueryInterface(
  99. IID_IADsAccessControlEntry,
  100. (void **)&pAccessControlEntry
  101. );
  102. CONTINUE_ON_FAILURE(hr);
  103. hr = ConvertAccessControlEntryToAceVariant(
  104. pAccessControlEntry,
  105. &varNDSAce
  106. );
  107. CONTINUE_ON_FAILURE(hr);
  108. //
  109. // Add the NDSAce into your Safe Array
  110. //
  111. hr = SafeArrayPutElement( aList, (long*)&i, &varNDSAce );
  112. VariantClear(&varAce);
  113. if (pAccessControlEntry) {
  114. pAccessControlEntry->Release();
  115. pAccessControlEntry = NULL;
  116. }
  117. //dwCount++;
  118. }
  119. //
  120. // Return the Safe Array back to the caller
  121. //
  122. V_VT(pvarNDSAcl) = VT_ARRAY | VT_VARIANT;
  123. V_ARRAY(pvarNDSAcl) = aList;
  124. if (pUnknown) {
  125. pUnknown->Release();
  126. }
  127. if (pEnumerator) {
  128. pEnumerator->Release();
  129. }
  130. RRETURN(hr);
  131. error:
  132. if ( aList ) {
  133. SafeArrayDestroy( aList );
  134. }
  135. if (pUnknown) {
  136. pUnknown->Release();
  137. }
  138. if (pEnumerator) {
  139. pEnumerator->Release();
  140. }
  141. RRETURN(hr);
  142. }
  143. HRESULT
  144. ConvertAccessControlEntryToAceVariant(
  145. IADsAccessControlEntry * pAccessControlEntry,
  146. PVARIANT pvarNDSAce
  147. )
  148. {
  149. HRESULT hr = S_OK;
  150. BSTR bstrTrustee = NULL;
  151. BSTR bstrObjectTypeClsid = NULL;
  152. IADsAcl * pSecDes = NULL;
  153. IDispatch * pDispatch = NULL;
  154. DWORD dwAccessMask;
  155. VariantInit(pvarNDSAce);
  156. hr = pAccessControlEntry->get_Trustee(&bstrTrustee);
  157. BAIL_ON_FAILURE(hr);
  158. hr = pAccessControlEntry->get_AccessMask((long *)&dwAccessMask);
  159. BAIL_ON_FAILURE(hr);
  160. hr = pAccessControlEntry->get_ObjectType(&bstrObjectTypeClsid);
  161. BAIL_ON_FAILURE(hr);
  162. hr = CAcl::CreateSecurityDescriptor(
  163. IID_IADsAcl,
  164. (void **)&pSecDes
  165. );
  166. BAIL_ON_FAILURE(hr);
  167. hr = pSecDes->put_SubjectName(bstrTrustee);
  168. BAIL_ON_FAILURE(hr);
  169. hr = pSecDes->put_ProtectedAttrName(bstrObjectTypeClsid);
  170. BAIL_ON_FAILURE(hr);
  171. hr = pSecDes->put_Privileges(dwAccessMask);
  172. BAIL_ON_FAILURE(hr);
  173. hr = pSecDes->QueryInterface(IID_IDispatch, (void**)&pDispatch);
  174. BAIL_ON_FAILURE(hr);
  175. V_VT(pvarNDSAce) = VT_DISPATCH;
  176. V_DISPATCH(pvarNDSAce) = pDispatch;
  177. error:
  178. if (pSecDes) {
  179. pSecDes->Release();
  180. }
  181. RRETURN(hr);
  182. }