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.

299 lines
8.2 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation
  3. Module Name:
  4. sxsfind.c
  5. Abstract:
  6. Side-by-side activation APIs for Win32, broken out of sxs.c
  7. Author:
  8. Jay Krell (JayKrell) November 2001
  9. Revision History:
  10. --*/
  11. #include "basedll.h"
  12. #include <sxstypes.h>
  13. #include "sxsapi.h"
  14. BOOL
  15. BasepFindActCtxSection_FillOutReturnData(
  16. IN DWORD dwWin32FlagsIn,
  17. OUT PACTCTX_SECTION_KEYED_DATA ReturnedData,
  18. IN PCACTIVATION_CONTEXT_SECTION_KEYED_DATA RtlData
  19. )
  20. {
  21. ReturnedData->ulDataFormatVersion = RtlData->DataFormatVersion;
  22. ReturnedData->lpData = RtlData->Data;
  23. ReturnedData->ulLength = RtlData->Length;
  24. ReturnedData->lpSectionGlobalData = RtlData->SectionGlobalData;
  25. ReturnedData->ulSectionGlobalDataLength = RtlData->SectionGlobalDataLength;
  26. ReturnedData->lpSectionBase = RtlData->SectionBase;
  27. ReturnedData->ulSectionTotalLength = RtlData->SectionTotalLength;
  28. //
  29. // The size check happens earlier.
  30. // We then don't pay attention to the flag, but just always copy the data
  31. // out, as 2600 does.
  32. //
  33. ASSERT(RTL_CONTAINS_FIELD(ReturnedData, ReturnedData->cbSize, hActCtx));
  34. ReturnedData->hActCtx = (HANDLE) RtlData->ActivationContext;
  35. //
  36. // There's no flag for this. 2600 always returns it if it fits.
  37. //
  38. if (RTL_CONTAINS_FIELD(ReturnedData, ReturnedData->cbSize, ulAssemblyRosterIndex)) {
  39. ReturnedData->ulAssemblyRosterIndex = RtlData->AssemblyRosterIndex;
  40. }
  41. if ((dwWin32FlagsIn & FIND_ACTCTX_SECTION_KEY_RETURN_FLAGS) != 0) {
  42. ReturnedData->ulFlags = RtlData->Flags;
  43. }
  44. if ((dwWin32FlagsIn & FIND_ACTCTX_SECTION_KEY_RETURN_ASSEMBLY_METADATA) != 0) {
  45. ReturnedData->AssemblyMetadata.lpInformation = RtlData->AssemblyMetadata.Information;
  46. ReturnedData->AssemblyMetadata.lpSectionBase = RtlData->AssemblyMetadata.SectionBase;
  47. ReturnedData->AssemblyMetadata.ulSectionLength = RtlData->AssemblyMetadata.SectionLength;
  48. ReturnedData->AssemblyMetadata.lpSectionGlobalDataBase = RtlData->AssemblyMetadata.SectionGlobalDataBase;
  49. ReturnedData->AssemblyMetadata.ulSectionGlobalDataLength = RtlData->AssemblyMetadata.SectionGlobalDataLength;
  50. }
  51. return TRUE;
  52. }
  53. BOOL
  54. BasepFindActCtxSection_CheckAndConvertParameters(
  55. IN DWORD dwWin32Flags,
  56. IN PCACTCTX_SECTION_KEYED_DATA pWin32ReturnedData,
  57. OUT PULONG pulRtlFlags
  58. )
  59. {
  60. BOOL fSuccess = FALSE;
  61. ULONG cbWin32Size = 0;
  62. ULONG ulRtlFlags = 0;
  63. if (pulRtlFlags != NULL) {
  64. *pulRtlFlags = 0;
  65. }
  66. if (pWin32ReturnedData == NULL) {
  67. goto InvalidParameter;
  68. }
  69. if (pulRtlFlags == NULL) {
  70. goto InvalidParameter;
  71. }
  72. cbWin32Size = pWin32ReturnedData->cbSize;
  73. if (cbWin32Size < RTL_SIZEOF_THROUGH_FIELD(ACTCTX_SECTION_KEYED_DATA, hActCtx)) {
  74. goto InvalidParameter;
  75. }
  76. if (((dwWin32Flags & ~(FIND_ACTCTX_SECTION_KEY_RETURN_HACTCTX |
  77. FIND_ACTCTX_SECTION_KEY_RETURN_FLAGS |
  78. FIND_ACTIVATION_CONTEXT_SECTION_KEY_RETURN_ASSEMBLY_METADATA
  79. )) != 0)
  80. ) {
  81. goto InvalidParameter;
  82. }
  83. if (dwWin32Flags & FIND_ACTCTX_SECTION_KEY_RETURN_HACTCTX) {
  84. if (!RTL_CONTAINS_FIELD(pWin32ReturnedData, cbWin32Size, hActCtx)) {
  85. goto InvalidParameter;
  86. }
  87. ulRtlFlags |= FIND_ACTIVATION_CONTEXT_SECTION_KEY_RETURN_ACTIVATION_CONTEXT;
  88. }
  89. if (dwWin32Flags & FIND_ACTCTX_SECTION_KEY_RETURN_FLAGS) {
  90. if (!RTL_CONTAINS_FIELD(pWin32ReturnedData, cbWin32Size, ulFlags)) {
  91. goto InvalidParameter;
  92. }
  93. ulRtlFlags |= FIND_ACTIVATION_CONTEXT_SECTION_KEY_RETURN_FLAGS;
  94. }
  95. if (dwWin32Flags & FIND_ACTCTX_SECTION_KEY_RETURN_ASSEMBLY_METADATA) {
  96. if (!RTL_CONTAINS_FIELD(pWin32ReturnedData, cbWin32Size, AssemblyMetadata)) {
  97. goto InvalidParameter;
  98. }
  99. ulRtlFlags |= FIND_ACTIVATION_CONTEXT_SECTION_KEY_RETURN_ASSEMBLY_METADATA;
  100. }
  101. *pulRtlFlags = ulRtlFlags;
  102. fSuccess = TRUE;
  103. Exit:
  104. return fSuccess;
  105. InvalidParameter:
  106. DbgPrintEx(
  107. DPFLTR_SXS_ID,
  108. DPFLTR_ERROR_LEVEL,
  109. "SXS: Invalid parameter(s) passed to FindActCtxSection*()\n"
  110. " dwFlags = 0x%08lx\n"
  111. " ReturnedData = %p\n"
  112. " ->cbSize = %u\n",
  113. dwWin32Flags,
  114. pWin32ReturnedData,
  115. (pWin32ReturnedData != NULL) ? cbWin32Size : 0);
  116. SetLastError(ERROR_INVALID_PARAMETER);
  117. goto Exit;
  118. }
  119. BOOL
  120. BasepFindActCtxSectionString(
  121. DWORD dwFlags,
  122. const GUID *lpExtensionGuid,
  123. ULONG ulSectionId,
  124. PCUNICODE_STRING PUnicodeString,
  125. PACTCTX_SECTION_KEYED_DATA ReturnedData
  126. )
  127. {
  128. BOOL fSuccess = FALSE;
  129. NTSTATUS Status;
  130. ULONG ulRtlFindFlags = 0;
  131. ACTIVATION_CONTEXT_SECTION_KEYED_DATA TempData;
  132. if (!BasepFindActCtxSection_CheckAndConvertParameters(
  133. dwFlags,
  134. ReturnedData,
  135. &ulRtlFindFlags
  136. )) {
  137. goto Exit;
  138. }
  139. RtlZeroMemory(&TempData, sizeof(TempData));
  140. TempData.Size = sizeof(TempData);
  141. Status = RtlFindActivationContextSectionString(
  142. ulRtlFindFlags,
  143. lpExtensionGuid,
  144. ulSectionId,
  145. PUnicodeString,
  146. &TempData);
  147. if (!NT_SUCCESS(Status)) {
  148. BaseSetLastNTError(Status);
  149. goto Exit;
  150. }
  151. if (!BasepFindActCtxSection_FillOutReturnData(
  152. dwFlags,
  153. ReturnedData,
  154. &TempData
  155. )) {
  156. goto Exit;
  157. }
  158. fSuccess = TRUE;
  159. Exit:
  160. return fSuccess;
  161. }
  162. #if !defined(COMPILE_FIND_ACTCTX_SECTION_STRING_A) || COMPILE_FIND_ACTCTX_SECTION_STRING_A
  163. WINBASEAPI
  164. BOOL
  165. FindActCtxSectionStringA(
  166. DWORD dwFlags,
  167. const GUID *lpExtensionGuid,
  168. ULONG ulSectionId,
  169. LPCSTR lpStringToFind,
  170. PACTCTX_SECTION_KEYED_DATA ReturnedData
  171. )
  172. {
  173. BOOL fSuccess = FALSE;
  174. UNICODE_STRING UnicodeString;
  175. PUNICODE_STRING PUnicodeString = NULL;
  176. if (lpStringToFind != NULL) {
  177. if (!Basep8BitStringToDynamicUnicodeString(&UnicodeString, lpStringToFind))
  178. goto Exit;
  179. PUnicodeString = &UnicodeString;
  180. }
  181. if (!BasepFindActCtxSectionString(dwFlags, lpExtensionGuid, ulSectionId, PUnicodeString, ReturnedData))
  182. goto Exit;
  183. fSuccess = TRUE;
  184. Exit:
  185. if (PUnicodeString != NULL)
  186. RtlFreeUnicodeString(PUnicodeString);
  187. return fSuccess;
  188. }
  189. #endif
  190. BOOL
  191. FindActCtxSectionStringW(
  192. DWORD dwFlags,
  193. const GUID *lpExtensionGuid,
  194. ULONG ulSectionId,
  195. LPCWSTR lpStringToFind,
  196. PACTCTX_SECTION_KEYED_DATA ReturnedData
  197. )
  198. {
  199. BOOL fSuccess = FALSE;
  200. UNICODE_STRING UnicodeString;
  201. PUNICODE_STRING PUnicodeString = NULL;
  202. if (lpStringToFind != NULL) {
  203. RtlInitUnicodeString(&UnicodeString, lpStringToFind);
  204. PUnicodeString = &UnicodeString;
  205. }
  206. if (!BasepFindActCtxSectionString(dwFlags, lpExtensionGuid, ulSectionId, PUnicodeString, ReturnedData))
  207. goto Exit;
  208. fSuccess = TRUE;
  209. Exit:
  210. return fSuccess;
  211. }
  212. BOOL
  213. WINAPI
  214. FindActCtxSectionGuid(
  215. DWORD dwFlags,
  216. const GUID *lpExtensionGuid,
  217. ULONG ulSectionId,
  218. const GUID *lpGuidToFind,
  219. PACTCTX_SECTION_KEYED_DATA ReturnedData
  220. )
  221. {
  222. BOOL fSuccess = FALSE;
  223. NTSTATUS Status;
  224. ULONG ulRtlFindFlags = 0;
  225. ACTIVATION_CONTEXT_SECTION_KEYED_DATA TempData;
  226. if (!BasepFindActCtxSection_CheckAndConvertParameters(
  227. dwFlags,
  228. ReturnedData,
  229. &ulRtlFindFlags
  230. )) {
  231. goto Exit;
  232. }
  233. RtlZeroMemory(&TempData, sizeof(TempData));
  234. TempData.Size = sizeof(TempData);
  235. Status = RtlFindActivationContextSectionGuid(
  236. ulRtlFindFlags,
  237. lpExtensionGuid,
  238. ulSectionId,
  239. lpGuidToFind,
  240. &TempData);
  241. if (!NT_SUCCESS(Status)) {
  242. BaseSetLastNTError(Status);
  243. goto Exit;
  244. }
  245. if (!BasepFindActCtxSection_FillOutReturnData(
  246. dwFlags,
  247. ReturnedData,
  248. &TempData
  249. )) {
  250. goto Exit;
  251. }
  252. fSuccess = TRUE;
  253. Exit:
  254. return fSuccess;
  255. }