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.

244 lines
5.3 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. ConvertNDSAclVArrayToSecDesVar(
  19. PVARIANT pVarArrayNDSAcl,
  20. PVARIANT pVarSecDes
  21. )
  22. {
  23. HRESULT hr = S_OK;
  24. IADsSecurityDescriptor * pSecDes = NULL;
  25. IDispatch * pDispatch = NULL;
  26. VARIANT varDACL;
  27. VariantInit(pVarSecDes);
  28. memset(&varDACL, 0, sizeof(VARIANT));
  29. hr = ConvertNDSAclVArrayToAclVariant(
  30. pVarArrayNDSAcl,
  31. &varDACL
  32. );
  33. BAIL_ON_FAILURE(hr);
  34. hr = CoCreateInstance(
  35. CLSID_SecurityDescriptor,
  36. NULL,
  37. CLSCTX_INPROC_SERVER,
  38. IID_IADsSecurityDescriptor,
  39. (void **)&pSecDes
  40. );
  41. BAIL_ON_FAILURE(hr);
  42. hr = pSecDes->put_DiscretionaryAcl(V_DISPATCH(&varDACL));
  43. BAIL_ON_FAILURE(hr);
  44. hr = pSecDes->QueryInterface(IID_IDispatch, (void**)&pDispatch);
  45. BAIL_ON_FAILURE(hr);
  46. V_VT(pVarSecDes) = VT_DISPATCH;
  47. V_DISPATCH(pVarSecDes) = pDispatch;
  48. error:
  49. if (pSecDes) {
  50. pSecDes->Release();
  51. }
  52. VariantClear(&varDACL);
  53. RRETURN(hr);
  54. }
  55. HRESULT
  56. ConvertNDSAclVArrayToAclVariant(
  57. PVARIANT pVarArrayNDSACL,
  58. PVARIANT pVarACL
  59. )
  60. {
  61. IADsAccessControlList *pAccessControlList = NULL;
  62. IDispatch *pDispatch = NULL;
  63. VARIANT *pVarArray = NULL;
  64. VARIANT varAce;
  65. DWORD i = 0;
  66. HRESULT hr = S_OK;
  67. DWORD dwNumValues = 0;
  68. DWORD dwNewAceCount = 0;
  69. VariantInit(pVarACL);
  70. hr = CoCreateInstance(
  71. CLSID_AccessControlList,
  72. NULL,
  73. CLSCTX_INPROC_SERVER,
  74. IID_IADsAccessControlList,
  75. (void **)&pAccessControlList
  76. );
  77. BAIL_ON_FAILURE(hr);
  78. hr = ConvertSafeArrayToVariantArray(
  79. *pVarArrayNDSACL,
  80. &pVarArray,
  81. &dwNumValues
  82. );
  83. BAIL_ON_FAILURE(hr);
  84. for (i = 0; i < dwNumValues; i++) {
  85. hr = ConvertNDSAclVariantToAceVariant(
  86. &(pVarArray[i]),
  87. (PVARIANT)&varAce
  88. );
  89. hr = pAccessControlList->AddAce(V_DISPATCH(&varAce));
  90. if (SUCCEEDED(hr)) {
  91. dwNewAceCount++;
  92. }
  93. VariantClear(&varAce);
  94. }
  95. pAccessControlList->put_AceCount(dwNewAceCount);
  96. hr = pAccessControlList->QueryInterface(
  97. IID_IDispatch,
  98. (void **)&pDispatch
  99. );
  100. V_VT(pVarACL) = VT_DISPATCH;
  101. V_DISPATCH(pVarACL) = pDispatch;
  102. error:
  103. if (pAccessControlList) {
  104. pAccessControlList->Release();
  105. }
  106. if (pVarArray) {
  107. for (DWORD i=0; i < dwNumValues; i++) {
  108. VariantClear(&(pVarArray[i]));
  109. }
  110. FreeADsMem(pVarArray);
  111. }
  112. RRETURN(hr);
  113. }
  114. HRESULT
  115. ConvertNDSAclVariantToAceVariant(
  116. PVARIANT pvarNDSAce,
  117. PVARIANT pvarAce
  118. )
  119. {
  120. HRESULT hr = S_OK;
  121. IADsAccessControlEntry *pAccessControlEntry = NULL;
  122. IDispatch *pDispatch = NULL;
  123. IADsAcl *pSecDes = NULL;
  124. DWORD dwPrivileges = 0;
  125. BSTR bstrProtectedAttrName = NULL;
  126. BSTR bstrSubjectName = NULL;
  127. if (V_VT(pvarNDSAce) != VT_DISPATCH){
  128. hr = E_FAIL;
  129. BAIL_ON_FAILURE(hr);
  130. }
  131. pDispatch = V_DISPATCH(pvarNDSAce);
  132. hr = pDispatch->QueryInterface(
  133. IID_IADsAcl,
  134. (void **)&pSecDes
  135. );
  136. BAIL_ON_FAILURE(hr);
  137. hr = pSecDes->get_ProtectedAttrName(
  138. &bstrProtectedAttrName
  139. );
  140. BAIL_ON_FAILURE(hr);
  141. hr = pSecDes->get_SubjectName(
  142. &bstrSubjectName
  143. );
  144. BAIL_ON_FAILURE(hr);
  145. hr = pSecDes->get_Privileges(
  146. (LONG *)&dwPrivileges);
  147. BAIL_ON_FAILURE(hr);
  148. VariantInit(pvarAce);
  149. hr = CoCreateInstance(
  150. CLSID_AccessControlEntry,
  151. NULL,
  152. CLSCTX_INPROC_SERVER,
  153. IID_IADsAccessControlEntry,
  154. (void **)&pAccessControlEntry
  155. );
  156. BAIL_ON_FAILURE(hr);
  157. hr = pAccessControlEntry->put_AccessMask(dwPrivileges);
  158. BAIL_ON_FAILURE(hr);
  159. hr = pAccessControlEntry->put_Trustee(bstrSubjectName);
  160. BAIL_ON_FAILURE(hr);
  161. hr = pAccessControlEntry->put_ObjectType(bstrProtectedAttrName);
  162. BAIL_ON_FAILURE(hr);
  163. hr = pAccessControlEntry->QueryInterface(
  164. IID_IDispatch,
  165. (void **)&pDispatch
  166. );
  167. BAIL_ON_FAILURE(hr);
  168. V_DISPATCH(pvarAce) = pDispatch;
  169. V_VT(pvarAce) = VT_DISPATCH;
  170. cleanup:
  171. if (pSecDes) {
  172. pSecDes->Release();
  173. }
  174. if (pAccessControlEntry) {
  175. pAccessControlEntry->Release();
  176. }
  177. if (bstrSubjectName) {
  178. ADsFreeString(bstrSubjectName);
  179. }
  180. if (bstrProtectedAttrName) {
  181. ADsFreeString(bstrProtectedAttrName);
  182. }
  183. RRETURN(hr);
  184. error:
  185. if (pDispatch) {
  186. pDispatch->Release();
  187. }
  188. goto cleanup;
  189. }