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.

393 lines
8.4 KiB

  1. /*++
  2. Copyright (c) 1996,1997 Microsoft Corporation
  3. Module Name:
  4. dynalink.c
  5. Abstract:
  6. This module contains routines to perform dynamic linking to interfaces
  7. during protected storage server startup. This is required because some
  8. interfaces do not exist on both target platforms, or, due to setup/install
  9. requirements where some of these .dlls may not be on the system when
  10. we are run the first time to do install initialization.
  11. Author:
  12. Scott Field (sfield) 03-Feb-97
  13. --*/
  14. #include <windows.h>
  15. #include "dynalink.h"
  16. #if 1
  17. BOOL
  18. InitDynamicInterfaces(
  19. VOID
  20. )
  21. {
  22. return TRUE;
  23. }
  24. #else
  25. #include "unicode.h"
  26. // WinNT specific
  27. extern FARPROC pNtQueryInformationProcess;
  28. extern FARPROC _NtOpenEvent;
  29. FARPROC _NtWaitForSingleObject = NULL;
  30. FARPROC _ZwClose = NULL;
  31. //FARPROC _DbgPrint = NULL;
  32. FARPROC _ZwRequestWaitReplyPort = NULL;
  33. FARPROC _RtlInitUnicodeString = NULL;
  34. FARPROC _NtClose = NULL;
  35. //FARPROC _strncpy = NULL;
  36. FARPROC _ZwConnectPort = NULL;
  37. FARPROC _ZwFreeVirtualMemory = NULL;
  38. FARPROC _RtlInitString = NULL;
  39. FARPROC _ZwWaitForSingleObject = NULL;
  40. FARPROC _ZwOpenEvent = NULL;
  41. #ifdef WIN95_LEGACY
  42. // Win95 specific
  43. // kernel.dll
  44. extern FARPROC pCreateToolhelp32Snapshot;
  45. extern FARPROC pModule32First;
  46. extern FARPROC pModule32Next;
  47. extern FARPROC pProcess32First;
  48. extern FARPROC pProcess32Next;
  49. extern FARPROC _WNetGetUserA;
  50. #endif // WIN95_LEGACY
  51. //
  52. // common
  53. // authenticode related (wintrust.dll, crypt32.dll)
  54. //
  55. extern BOOL g_bAuthenticodeInitialized; // authenticode available for us to use?
  56. BOOL
  57. InitDynamicInterfaces(
  58. VOID
  59. )
  60. {
  61. UINT uPriorErrorMode;
  62. BOOL bSuccess = FALSE;
  63. //
  64. // insure no popups are seen about missing files,
  65. // entry points, etc.
  66. //
  67. uPriorErrorMode = SetErrorMode(
  68. SEM_FAILCRITICALERRORS |
  69. SEM_NOGPFAULTERRORBOX |
  70. SEM_NOOPENFILEERRORBOX
  71. );
  72. if(FIsWinNT()) {
  73. //
  74. // get WinNT specific interfaces
  75. //
  76. HINSTANCE hNtDll;
  77. // we LoadLibrary ntdll.dll even though it is likely to be in our
  78. // address space - we don't want to assume it is so because it may not be.
  79. hNtDll = LoadLibraryW(L"ntdll.dll");
  80. if(hNtDll == NULL) goto cleanup;
  81. if((pNtQueryInformationProcess = GetProcAddress(hNtDll, "NtQueryInformationProcess")) == NULL)
  82. goto cleanup;
  83. // interfaces required for lsadll.lib
  84. if((_NtWaitForSingleObject = GetProcAddress(hNtDll, "NtWaitForSingleObject")) == NULL)
  85. goto cleanup;
  86. if((_ZwClose = GetProcAddress(hNtDll, "ZwClose")) == NULL)
  87. goto cleanup;
  88. // if((_DbgPrint = GetProcAddress(hNtDll, "DbgPrint")) == NULL)
  89. // goto cleanup;
  90. if((_ZwRequestWaitReplyPort = GetProcAddress(hNtDll, "ZwRequestWaitReplyPort")) == NULL)
  91. goto cleanup;
  92. if((_RtlInitUnicodeString = GetProcAddress(hNtDll, "RtlInitUnicodeString")) == NULL)
  93. goto cleanup;
  94. if((_NtOpenEvent = GetProcAddress(hNtDll, "NtOpenEvent")) == NULL)
  95. goto cleanup;
  96. if((_NtClose = GetProcAddress(hNtDll, "NtClose")) == NULL)
  97. goto cleanup;
  98. // if((_strncpy = GetProcAddress(hNtDll, "strncpy")) == NULL)
  99. // goto cleanup;
  100. if((_ZwConnectPort = GetProcAddress(hNtDll, "ZwConnectPort")) == NULL)
  101. goto cleanup;
  102. if((_ZwFreeVirtualMemory = GetProcAddress(hNtDll, "ZwFreeVirtualMemory")) == NULL)
  103. goto cleanup;
  104. if((_RtlInitString = GetProcAddress(hNtDll, "RtlInitString")) == NULL)
  105. goto cleanup;
  106. if((_ZwWaitForSingleObject = GetProcAddress(hNtDll, "ZwWaitForSingleObject")) == NULL)
  107. goto cleanup;
  108. if((_ZwOpenEvent = GetProcAddress(hNtDll, "ZwOpenEvent")) == NULL)
  109. goto cleanup;
  110. bSuccess = TRUE;
  111. }
  112. #ifdef WIN95_LEGACY
  113. else {
  114. //
  115. // get Win95 specific interfaces
  116. //
  117. HMODULE hKernel = NULL;
  118. HMODULE hMpr = NULL;
  119. hKernel = GetModuleHandle("KERNEL32.DLL");
  120. pCreateToolhelp32Snapshot = GetProcAddress(
  121. hKernel,
  122. "CreateToolhelp32Snapshot");
  123. if(pCreateToolhelp32Snapshot == NULL)
  124. goto cleanup;
  125. pModule32First = GetProcAddress(
  126. hKernel,
  127. "Module32First");
  128. if(pModule32First == NULL)
  129. goto cleanup;
  130. pModule32Next = GetProcAddress(
  131. hKernel,
  132. "Module32Next");
  133. if(pModule32Next == NULL)
  134. goto cleanup;
  135. pProcess32First = GetProcAddress(
  136. hKernel,
  137. "Process32First");
  138. if(pProcess32First == NULL)
  139. goto cleanup;
  140. pProcess32Next = GetProcAddress(
  141. hKernel,
  142. "Process32Next");
  143. if(pProcess32Next == NULL)
  144. goto cleanup;
  145. hMpr = LoadLibraryA("MPR.DLL");
  146. if(hMpr == NULL)
  147. goto cleanup;
  148. _WNetGetUserA = GetProcAddress(
  149. hMpr,
  150. "WNetGetUserA"
  151. );
  152. if(_WNetGetUserA == NULL)
  153. goto cleanup;
  154. bSuccess = TRUE;
  155. }
  156. #endif // WIN95_LEGACY
  157. cleanup:
  158. //
  159. // restore previous error mode.
  160. //
  161. SetErrorMode(uPriorErrorMode);
  162. return bSuccess;
  163. }
  164. ULONG
  165. NTAPI
  166. NtWaitForSingleObject(
  167. IN HANDLE Handle,
  168. IN BOOLEAN Alertable,
  169. IN PLARGE_INTEGER Timeout OPTIONAL
  170. )
  171. {
  172. return (ULONG)_NtWaitForSingleObject(Handle, Alertable, Timeout);
  173. }
  174. ULONG
  175. __cdecl
  176. DbgPrint(
  177. PCH Format,
  178. ...
  179. )
  180. {
  181. return 0;
  182. }
  183. VOID
  184. NTAPI
  185. RtlInitUnicodeString(
  186. PVOID DestinationString,
  187. PCWSTR SourceString
  188. )
  189. {
  190. _RtlInitUnicodeString(DestinationString, SourceString);
  191. }
  192. VOID
  193. NTAPI
  194. RtlInitString(
  195. PVOID DestinationString,
  196. PVOID SourceString
  197. )
  198. {
  199. _RtlInitString(DestinationString, SourceString);
  200. }
  201. ULONG
  202. NTAPI
  203. NtOpenEvent (
  204. OUT PHANDLE EventHandle,
  205. IN ACCESS_MASK DesiredAccess,
  206. IN PVOID ObjectAttributes
  207. )
  208. {
  209. return (ULONG)_NtOpenEvent(EventHandle, DesiredAccess, ObjectAttributes);
  210. }
  211. ULONG
  212. NTAPI
  213. NtClose(
  214. IN HANDLE Handle
  215. )
  216. {
  217. return (ULONG)_NtClose( Handle );
  218. }
  219. ULONG
  220. NTAPI
  221. ZwClose(
  222. IN HANDLE Handle
  223. )
  224. {
  225. return (ULONG)_ZwClose(Handle);
  226. }
  227. ULONG
  228. NTAPI
  229. ZwRequestWaitReplyPort(
  230. IN HANDLE PortHandle,
  231. IN PVOID RequestMessage,
  232. OUT PVOID ReplyMessage
  233. )
  234. {
  235. return (ULONG)_ZwRequestWaitReplyPort(
  236. PortHandle,
  237. RequestMessage,
  238. ReplyMessage
  239. );
  240. }
  241. ULONG
  242. NTAPI
  243. ZwConnectPort(
  244. OUT PHANDLE PortHandle,
  245. IN PVOID PortName,
  246. IN PSECURITY_QUALITY_OF_SERVICE SecurityQos,
  247. IN OUT PVOID ClientView OPTIONAL,
  248. OUT PVOID ServerView OPTIONAL,
  249. OUT PULONG MaxMessageLength OPTIONAL,
  250. IN OUT PVOID ConnectionInformation OPTIONAL,
  251. IN OUT PULONG ConnectionInformationLength OPTIONAL
  252. )
  253. {
  254. return (ULONG)_ZwConnectPort(
  255. PortHandle,
  256. PortName,
  257. SecurityQos,
  258. ClientView,
  259. ServerView,
  260. MaxMessageLength,
  261. ConnectionInformation,
  262. ConnectionInformationLength
  263. );
  264. }
  265. ULONG
  266. NTAPI
  267. ZwFreeVirtualMemory(
  268. IN HANDLE ProcessHandle,
  269. IN OUT PVOID *BaseAddress,
  270. IN OUT PULONG RegionSize,
  271. IN ULONG FreeType
  272. )
  273. {
  274. return (ULONG)_ZwFreeVirtualMemory(
  275. ProcessHandle,
  276. BaseAddress,
  277. RegionSize,
  278. FreeType
  279. );
  280. }
  281. ULONG
  282. NTAPI
  283. ZwWaitForSingleObject(
  284. IN HANDLE Handle,
  285. IN BOOLEAN Alertable,
  286. IN PLARGE_INTEGER Timeout OPTIONAL
  287. )
  288. {
  289. return (ULONG)_ZwWaitForSingleObject(Handle, Alertable, Timeout);
  290. }
  291. ULONG
  292. NTAPI
  293. ZwOpenEvent (
  294. OUT PHANDLE EventHandle,
  295. IN ACCESS_MASK DesiredAccess,
  296. IN PVOID ObjectAttributes
  297. )
  298. {
  299. return (ULONG)_ZwOpenEvent(EventHandle, DesiredAccess, ObjectAttributes);
  300. }
  301. VOID
  302. NTAPI
  303. RtlAssert(
  304. PVOID FailedAssertion,
  305. PVOID FileName,
  306. ULONG LineNumber,
  307. PCHAR Message
  308. )
  309. {
  310. return;
  311. }
  312. #endif