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.

1202 lines
34 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. stub.c
  5. Abstract:
  6. Dynamic loading of routines that are implemented differently on Win9x and NT.
  7. Author:
  8. Jim Schmidt (jimschm) 29-Apr-1997
  9. Revision History:
  10. jimschm 26-Oct-1998 Added cfgmgr32, crypt32, mscat and wintrust APIs
  11. lonnym 01-Apr-2000 Added VerifyVersionInfo and VerSetConditionMask
  12. --*/
  13. #include "precomp.h"
  14. //
  15. // Stub & emulation prototypes -- implemented below
  16. //
  17. GETFILEATTRIBUTESEXA_PROTOTYPE EmulatedGetFileAttributesExA;
  18. //
  19. // Function ptr declarations. When adding, prefix the function ptr with
  20. // Dyn_ to indicate a dynamically loaded version of an API.
  21. //
  22. GETFILEATTRIBUTESEXA_PROC Dyn_GetFileAttributesExA;
  23. GETSYSTEMWINDOWSDIRECTORYA_PROC Dyn_GetSystemWindowsDirectoryA;
  24. VERIFYVERSIONINFOA_PROC Dyn_VerifyVersionInfoA;
  25. VERSETCONDITIONMASK_PROC Dyn_VerSetConditionMask;
  26. //
  27. // these functions are a little more involved, since we don't want to
  28. // pull in SFC until we have to (delay-load)
  29. //
  30. SFCONNECTTOSERVER_PROC Dyn_SfcConnectToServer = FirstLoad_SfcConnectToServer;
  31. SFCCLOSE_PROC Dyn_SfcClose = FirstLoad_SfcClose;
  32. SFCFILEEXCEPTION_PROC Dyn_SfcFileException = FirstLoad_SfcFileException;
  33. SFCISFILEPROTECTED_PROC Dyn_SfcIsFileProtected = FirstLoad_SfcIsFileProtected;
  34. #ifdef ANSI_SETUPAPI
  35. CM_QUERY_RESOURCE_CONFLICT_LIST Dyn_CM_Query_Resource_Conflict_List;
  36. CM_FREE_RESOURCE_CONFLICT_HANDLE Dyn_CM_Free_Resource_Conflict_Handle;
  37. CM_GET_RESOURCE_CONFLICT_COUNT Dyn_CM_Get_Resource_Conflict_Count;
  38. CM_GET_RESOURCE_CONFLICT_DETAILSA Dyn_CM_Get_Resource_Conflict_DetailsA;
  39. CM_GET_CLASS_REGISTRY_PROPERTYA Dyn_CM_Get_Class_Registry_PropertyA;
  40. CM_SET_CLASS_REGISTRY_PROPERTYA Dyn_CM_Set_Class_Registry_PropertyA;
  41. CM_GET_DEVICE_INTERFACE_ALIAS_EXA Dyn_CM_Get_Device_Interface_Alias_ExA;
  42. CM_GET_DEVICE_INTERFACE_LIST_EXA Dyn_CM_Get_Device_Interface_List_ExA;
  43. CM_GET_DEVICE_INTERFACE_LIST_SIZE_EXA Dyn_CM_Get_Device_Interface_List_Size_ExA;
  44. CM_GET_LOG_CONF_PRIORITY_EX Dyn_CM_Get_Log_Conf_Priority_Ex;
  45. CM_QUERY_AND_REMOVE_SUBTREE_EXA Dyn_CM_Query_And_Remove_SubTree_ExA;
  46. CM_REGISTER_DEVICE_INTERFACE_EXA Dyn_CM_Register_Device_Interface_ExA;
  47. CM_SET_DEVNODE_PROBLEM_EX Dyn_CM_Set_DevNode_Problem_Ex;
  48. CM_UNREGISTER_DEVICE_INTERFACE_EXA Dyn_CM_Unregister_Device_Interface_ExA;
  49. CRYPTCATADMINACQUIRECONTEXT Dyn_CryptCATAdminAcquireContext;
  50. CRYPTCATADMINRELEASECONTEXT Dyn_CryptCATAdminReleaseContext;
  51. CRYPTCATADMINRELEASECATALOGCONTEXT Dyn_CryptCATAdminReleaseCatalogContext;
  52. CRYPTCATADMINADDCATALOG Dyn_CryptCATAdminAddCatalog;
  53. CRYPTCATCATALOGINFOFROMCONTEXT Dyn_CryptCATCatalogInfoFromContext;
  54. CRYPTCATADMINCALCHASHFROMFILEHANDLE Dyn_CryptCATAdminCalcHashFromFileHandle;
  55. CRYPTCATADMINENUMCATALOGFROMHASH Dyn_CryptCATAdminEnumCatalogFromHash;
  56. CRYPTCATADMINREMOVECATALOG Dyn_CryptCATAdminRemoveCatalog;
  57. CRYPTCATADMINRESOLVECATALOGPATH Dyn_CryptCATAdminResolveCatalogPath;
  58. CERTFREECERTIFICATECONTEXT CertFreeCertificateContext;
  59. WINVERIFYTRUST WinVerifyTrust;
  60. #endif
  61. VOID
  62. InitializeStubFnPtrs (
  63. VOID
  64. )
  65. /*++
  66. Routine Description:
  67. This routine tries to load the function ptr of OS-provided APIs, and if
  68. they aren't available, stub versions are used instead. We do this
  69. for APIs that are unimplemented on a platform that setupapi will
  70. run on.
  71. Arguments:
  72. none
  73. Return Value:
  74. none
  75. --*/
  76. {
  77. //
  78. // no dynamic loading should be done here for WinXP etc
  79. // it's only done for ANSI version of setupapi.dll
  80. // who's sole purpose is for setup of WinXP
  81. // from Win9x (ie, used in context of winnt32.exe)
  82. //
  83. #ifdef ANSI_SETUPAPI
  84. //
  85. // Kernel32 API's - try loading from the OS dll, and if the API
  86. // doesn't exist, use an emulation version
  87. //
  88. (FARPROC) Dyn_GetFileAttributesExA = ObtainFnPtr (
  89. "kernel32.dll",
  90. "GetFileAttributesExA",
  91. (FARPROC) EmulatedGetFileAttributesExA
  92. );
  93. (FARPROC) Dyn_GetSystemWindowsDirectoryA = ObtainFnPtr (
  94. "kernel32.dll",
  95. "GetSystemWindowsDirectoryA",
  96. (FARPROC) GetWindowsDirectoryA
  97. );
  98. //
  99. // use Win9x config manager APIs if they exist, otherwise return ERROR_CALL_NOT_IMPLEMENTED
  100. //
  101. (FARPROC) Dyn_CM_Get_Class_Registry_PropertyA = ObtainFnPtr (
  102. "cfgmgr32.dll",
  103. "CM_Get_Class_Registry_PropertyA",
  104. (FARPROC) Stub_CM_Get_Class_Registry_PropertyA
  105. );
  106. (FARPROC) Dyn_CM_Set_Class_Registry_PropertyA = ObtainFnPtr (
  107. "cfgmgr32.dll",
  108. "CM_Set_Class_Registry_PropertyA",
  109. (FARPROC) Stub_CM_Set_Class_Registry_PropertyA
  110. );
  111. (FARPROC) Dyn_CM_Get_Device_Interface_Alias_ExA = ObtainFnPtr (
  112. "cfgmgr32.dll",
  113. "CM_Get_Device_Interface_Alias_ExA",
  114. (FARPROC) Stub_CM_Get_Device_Interface_Alias_ExA
  115. );
  116. (FARPROC) Dyn_CM_Get_Device_Interface_List_ExA = ObtainFnPtr (
  117. "cfgmgr32.dll",
  118. "CM_Get_Device_Interface_List_ExA",
  119. (FARPROC) Stub_CM_Get_Device_Interface_List_ExA
  120. );
  121. (FARPROC) Dyn_CM_Get_Device_Interface_List_Size_ExA = ObtainFnPtr (
  122. "cfgmgr32.dll",
  123. "CM_Get_Device_Interface_List_Size_ExA",
  124. (FARPROC) Stub_CM_Get_Device_Interface_List_Size_ExA
  125. );
  126. (FARPROC) Dyn_CM_Get_Log_Conf_Priority_Ex = ObtainFnPtr (
  127. "cfgmgr32.dll",
  128. "CM_Get_Log_Conf_Priority_Ex",
  129. (FARPROC) Stub_CM_Get_Log_Conf_Priority_Ex
  130. );
  131. (FARPROC) Dyn_CM_Query_And_Remove_SubTree_ExA = ObtainFnPtr (
  132. "cfgmgr32.dll",
  133. "CM_Query_And_Remove_SubTree_ExA",
  134. (FARPROC) Stub_CM_Query_And_Remove_SubTree_ExA
  135. );
  136. (FARPROC) Dyn_CM_Register_Device_Interface_ExA = ObtainFnPtr (
  137. "cfgmgr32.dll",
  138. "CM_Register_Device_Interface_ExA",
  139. (FARPROC) Stub_CM_Register_Device_Interface_ExA
  140. );
  141. (FARPROC) Dyn_CM_Set_DevNode_Problem_Ex = ObtainFnPtr (
  142. "cfgmgr32.dll",
  143. "CM_Set_DevNode_Problem_Ex",
  144. (FARPROC) Stub_CM_Set_DevNode_Problem_Ex
  145. );
  146. (FARPROC) Dyn_CM_Unregister_Device_Interface_ExA = ObtainFnPtr (
  147. "cfgmgr32.dll",
  148. "CM_Unregister_Device_Interface_ExA",
  149. (FARPROC) Stub_CM_Unregister_Device_Interface_ExA
  150. );
  151. (FARPROC)Dyn_CM_Query_Resource_Conflict_List = ObtainFnPtr (
  152. "cfgmgr32.dll",
  153. "CM_Query_Resource_Conflict_List",
  154. (FARPROC) Stub_CM_Query_Resource_Conflict_List
  155. );
  156. (FARPROC)Dyn_CM_Free_Resource_Conflict_Handle = ObtainFnPtr (
  157. "cfgmgr32.dll",
  158. "CM_Free_Resource_Conflict_Handle",
  159. (FARPROC) Stub_CM_Free_Resource_Conflict_Handle
  160. );
  161. (FARPROC)Dyn_CM_Get_Resource_Conflict_Count = ObtainFnPtr (
  162. "cfgmgr32.dll",
  163. "CM_Get_Resource_Conflict_Count",
  164. (FARPROC) Stub_CM_Get_Resource_Conflict_Count
  165. );
  166. (FARPROC)Dyn_CM_Get_Resource_Conflict_DetailsA = ObtainFnPtr (
  167. "cfgmgr32.dll",
  168. "CM_Get_Resource_Conflict_DetailsA",
  169. (FARPROC) Stub_CM_Get_Resource_Conflict_DetailsA
  170. );
  171. //
  172. // use Win9x crypto APIs if they exist, otherwise fail with ERROR_CALL_NOT_IMPLEMENTED
  173. //
  174. (FARPROC) Dyn_CryptCATAdminAcquireContext = ObtainFnPtr (
  175. "wintrust.dll",
  176. "CryptCATAdminAcquireContext",
  177. (FARPROC) Stub_CryptCATAdminAcquireContext
  178. );
  179. (FARPROC) Dyn_CryptCATAdminReleaseContext = ObtainFnPtr (
  180. "wintrust.dll",
  181. "CryptCATAdminReleaseContext",
  182. (FARPROC) Stub_CryptCATAdminReleaseContext
  183. );
  184. (FARPROC) Dyn_CryptCATAdminReleaseCatalogContext = ObtainFnPtr (
  185. "wintrust.dll",
  186. "CryptCATAdminReleaseCatalogContext",
  187. (FARPROC) Stub_CryptCATAdminReleaseCatalogContext
  188. );
  189. (FARPROC) Dyn_CryptCATAdminAddCatalog = ObtainFnPtr (
  190. "wintrust.dll",
  191. "CryptCATAdminAddCatalog",
  192. (FARPROC) Stub_CryptCATAdminAddCatalog
  193. );
  194. (FARPROC) Dyn_CryptCATCatalogInfoFromContext = ObtainFnPtr (
  195. "wintrust.dll",
  196. "CryptCATCatalogInfoFromContext",
  197. (FARPROC) Stub_CryptCATCatalogInfoFromContext
  198. );
  199. (FARPROC) Dyn_CryptCATAdminCalcHashFromFileHandle = ObtainFnPtr (
  200. "wintrust.dll",
  201. "CryptCATAdminCalcHashFromFileHandle",
  202. (FARPROC) Stub_CryptCATAdminCalcHashFromFileHandle
  203. );
  204. (FARPROC) Dyn_CryptCATAdminEnumCatalogFromHash = ObtainFnPtr (
  205. "wintrust.dll",
  206. "CryptCATAdminEnumCatalogFromHash",
  207. (FARPROC) Stub_CryptCATAdminEnumCatalogFromHash
  208. );
  209. (FARPROC) Dyn_CryptCATAdminRemoveCatalog = ObtainFnPtr (
  210. "wintrust.dll",
  211. "CryptCATAdminRemoveCatalog",
  212. (FARPROC) Stub_CryptCATAdminRemoveCatalog
  213. );
  214. (FARPROC) Dyn_CryptCATAdminResolveCatalogPath = ObtainFnPtr (
  215. "wintrust.dll",
  216. "CryptCATAdminResolveCatalogPath",
  217. (FARPROC) Stub_CryptCATAdminResolveCatalogPath
  218. );
  219. (FARPROC) Dyn_CertFreeCertificateContext = ObtainFnPtr (
  220. "crypt32.dll",
  221. "CertFreeCertificateContext",
  222. (FARPROC) Stub_CertFreeCertificateContext
  223. );
  224. //
  225. // use Win9x WinVerifyTrust if it exists, otherwise return ERROR_SUCCESS
  226. //
  227. (FARPROC) Dyn_WinVerifyTrust = ObtainFnPtr (
  228. "wintrust.dll",
  229. "WinVerifyTrust",
  230. (FARPROC) Stub_WinVerifyTrust
  231. );
  232. //
  233. // Use VerifyVersionInfo and VerSetConditionMask APIs,
  234. // if available, otherwise fail with ERROR_CALL_NOT_IMPLEMENTED.
  235. //
  236. (FARPROC) Dyn_VerifyVersionInfoA = ObtainFnPtr(
  237. "kernel32.dll",
  238. "VerifyVersionInfoA",
  239. (FARPROC) Stub_VerifyVersionInfoA
  240. );
  241. (FARPROC) Dyn_VerSetConditionMask = ObtainFnPtr(
  242. "ntdll.dll",
  243. "VerSetConditionMask",
  244. (FARPROC) Stub_VerSetConditionMask
  245. );
  246. //
  247. // ***Add other dynamic loading here***
  248. //
  249. #endif
  250. }
  251. BOOL
  252. EmulatedGetFileAttributesExA (
  253. IN PCSTR FileName,
  254. IN GET_FILEEX_INFO_LEVELS InfoLevelId,
  255. OUT LPVOID FileInformation
  256. )
  257. /*++
  258. Routine Description:
  259. Implements an emulation of the NT-specific function GetFileAttributesEx.
  260. Basic exception handling is implemented, but parameters are not otherwise
  261. validated.
  262. Arguments:
  263. FileName - Specifies file to get attributes for
  264. InfoLevelId - Must be GetFileExInfoStandard
  265. FileInformation - Must be a valid pointer to WIN32_FILE_ATTRIBUTE_DATA struct
  266. Return Value:
  267. TRUE for success, FALSE for failure. GetLastError provided error code.
  268. --*/
  269. {
  270. //
  271. // GetFileAttributesEx does not exist on Win95, and ANSI version of setupapi.dll
  272. // is required for Win9x to NT 5 upgrade
  273. //
  274. HANDLE FileEnum;
  275. WIN32_FIND_DATAA fd;
  276. PCSTR p,pChar;
  277. TCHAR CurChar;
  278. WIN32_FILE_ATTRIBUTE_DATA *FileAttribData = (WIN32_FILE_ATTRIBUTE_DATA *) FileInformation;
  279. __try {
  280. //
  281. // We only support GetFileExInfoStandard
  282. //
  283. if (InfoLevelId != GetFileExInfoStandard) {
  284. SetLastError (ERROR_INVALID_PARAMETER);
  285. return FALSE;
  286. }
  287. //
  288. // Locate file title
  289. // note that this is an ANSI implementation of pSetupGetFileTitle
  290. //
  291. p = pChar = FileName;
  292. while(CurChar = *pChar) {
  293. pChar = CharNextA(pChar);
  294. if((CurChar == '\\') || (CurChar == '/') || (CurChar == ':')) {
  295. p = pChar;
  296. }
  297. }
  298. ZeroMemory (FileAttribData, sizeof (WIN32_FILE_ATTRIBUTE_DATA));
  299. FileEnum = FindFirstFileA (FileName, &fd);
  300. //
  301. // Prohibit caller-supplied pattern
  302. //
  303. if (FileEnum!=INVALID_HANDLE_VALUE && lstrcmpiA (p, fd.cFileName)) {
  304. FindClose (FileEnum);
  305. FileEnum = INVALID_HANDLE_VALUE;
  306. SetLastError (ERROR_INVALID_PARAMETER);
  307. }
  308. //
  309. // If exact match found, fill in the attributes
  310. //
  311. if (FileEnum) {
  312. FileAttribData->dwFileAttributes = fd.dwFileAttributes;
  313. FileAttribData->nFileSizeHigh = fd.nFileSizeHigh;
  314. FileAttribData->nFileSizeLow = fd.nFileSizeLow;
  315. CopyMemory (&FileAttribData->ftCreationTime, &fd.ftCreationTime, sizeof (FILETIME));
  316. CopyMemory (&FileAttribData->ftLastAccessTime, &fd.ftLastAccessTime, sizeof (FILETIME));
  317. CopyMemory (&FileAttribData->ftLastWriteTime, &fd.ftLastWriteTime, sizeof (FILETIME));
  318. FindClose (FileEnum);
  319. }
  320. return FileEnum != INVALID_HANDLE_VALUE;
  321. }
  322. __except (TRUE) {
  323. //
  324. // If bogus FileInformation pointer is passed, an exception is thrown.
  325. //
  326. SetLastError (ERROR_INVALID_PARAMETER);
  327. return FALSE;
  328. }
  329. }
  330. //
  331. // DLL array structures
  332. //
  333. #define MAX_DLL_ARRAY 16
  334. typedef struct {
  335. PCSTR DllName;
  336. HINSTANCE DllInst;
  337. } DLLTABLE, *PDLLTABLE;
  338. static INT g_ArraySize = 0;
  339. static DLLTABLE g_DllArray[MAX_DLL_ARRAY];
  340. //
  341. // Attempt to get library out of System32 directory first
  342. //
  343. HMODULE DelayLoadLibrary(
  344. IN LPCSTR LibName
  345. )
  346. /*++
  347. internal
  348. Routine Description:
  349. Given an ANSI library name, prepend system32 directory and load it
  350. (ie, enforce our own search path)
  351. Don't assume anything is initialized
  352. Arguments:
  353. LibName - name passed to us by pDelayLoadHook
  354. Result:
  355. HMODULE from LoadLibrary, or NULL for default processing
  356. --*/
  357. {
  358. CHAR path[MAX_PATH];
  359. UINT swdLen;
  360. UINT libLen;
  361. HMODULE result;
  362. libLen = strlen(LibName);
  363. if(strrchr(LibName,'\\') || strrchr(LibName,'/')) {
  364. MYASSERT(FALSE);
  365. return NULL;
  366. }
  367. swdLen = GetSystemDirectoryA(path,MAX_PATH);
  368. if((swdLen == 0) || ((swdLen+libLen+1)>=MAX_PATH)) {
  369. return NULL;
  370. }
  371. if(*CharPrevA(path,path+swdLen)!=TEXT('\\')) {
  372. path[swdLen++] = TEXT('\\');
  373. }
  374. strcpy(path+swdLen,LibName);
  375. result = LoadLibraryA(path);
  376. if(result) {
  377. MYTRACE((DPFLTR_TRACE_LEVEL, TEXT("SetupAPI: delay-loaded %hs.\n"), path));
  378. } else {
  379. MYTRACE((DPFLTR_ERROR_LEVEL, TEXT("SetupAPI: Could not delay-load %hs.\n"), path));
  380. }
  381. return result;
  382. }
  383. FARPROC
  384. ObtainFnPtr (
  385. IN PCSTR DllName,
  386. IN PCSTR ProcName,
  387. IN FARPROC Default
  388. )
  389. /*++
  390. Routine Description:
  391. This routine manages an array of DLL instance handles and returns the
  392. proc address of the caller-specified routine. The DLL is loaded
  393. and remains loaded until the DLL terminates. This array is not
  394. synchronized.
  395. Arguments:
  396. DllName - The ANSI DLL name to load
  397. ProcName - The ANSI procedure name to locate
  398. Default - The default procedure, if the export was not found
  399. Return Value:
  400. The address of the requested function, or NULL if the DLL could not
  401. be loaded, or the function is not implemented in the loaded DLL.
  402. --*/
  403. {
  404. INT i;
  405. PSTR DupBuf;
  406. FARPROC Address = NULL;
  407. //
  408. // Search for loaded DLL
  409. //
  410. for (i = 0 ; i < g_ArraySize ; i++) {
  411. if (!lstrcmpiA (DllName, g_DllArray[i].DllName)) {
  412. break;
  413. }
  414. }
  415. do {
  416. //
  417. // If necessary, load the DLL
  418. //
  419. if (i == g_ArraySize) {
  420. if (g_ArraySize == MAX_DLL_ARRAY) {
  421. // Constant limit needs to be raised
  422. MYASSERT (FALSE);
  423. break;
  424. }
  425. g_DllArray[i].DllInst = DelayLoadLibrary (DllName);
  426. if (!g_DllArray[i].DllInst) {
  427. break;
  428. }
  429. DupBuf = (PSTR) MyMalloc (lstrlenA (DllName) + 1);
  430. if (!DupBuf) {
  431. break;
  432. }
  433. lstrcpyA (DupBuf, DllName);
  434. g_DllArray[i].DllName = DupBuf;
  435. g_ArraySize++;
  436. }
  437. //
  438. // Now that DLL is loaded, return the proc address if it exists
  439. //
  440. Address = GetProcAddress (g_DllArray[i].DllInst, ProcName);
  441. } while (FALSE);
  442. if (!Address) {
  443. return Default;
  444. }
  445. return Address;
  446. }
  447. VOID
  448. pCleanUpDllArray (
  449. VOID
  450. )
  451. /*++
  452. Routine Description:
  453. Cleans up the DLL array resources.
  454. Arguments:
  455. none
  456. Return Value:
  457. none
  458. --*/
  459. {
  460. INT i;
  461. for (i = 0 ; i < g_ArraySize ; i++) {
  462. FreeLibrary (g_DllArray[i].DllInst);
  463. MyFree (g_DllArray[i].DllName);
  464. }
  465. g_ArraySize = 0;
  466. }
  467. VOID
  468. CleanUpStubFns (
  469. VOID
  470. )
  471. /*++
  472. Routine Description:
  473. Cleans up all resources used by emulation routines and function pointer list.
  474. Arguments:
  475. none
  476. Return Value:
  477. none
  478. --*/
  479. {
  480. pCleanUpDllArray();
  481. }
  482. BOOL
  483. WINAPI
  484. Stub_VerifyVersionInfoA(
  485. IN LPOSVERSIONINFOEXA lpVersionInformation,
  486. IN DWORD dwTypeMask,
  487. IN DWORDLONG dwlConditionMask
  488. )
  489. {
  490. UNREFERENCED_PARAMETER(lpVersionInformation);
  491. UNREFERENCED_PARAMETER(dwTypeMask);
  492. UNREFERENCED_PARAMETER(dwlConditionMask);
  493. SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
  494. return(FALSE);
  495. }
  496. ULONGLONG
  497. NTAPI
  498. Stub_VerSetConditionMask(
  499. IN ULONGLONG ConditionMask,
  500. IN DWORD TypeMask,
  501. IN BYTE Condition
  502. )
  503. {
  504. UNREFERENCED_PARAMETER(TypeMask);
  505. UNREFERENCED_PARAMETER(Condition);
  506. //
  507. // Simply return ConditionMask unaltered. (If this API doesn't exist, we
  508. // don't expect VerifyVersionInfo to exist either, so that should fail.)
  509. //
  510. return ConditionMask;
  511. }
  512. HANDLE
  513. WINAPI
  514. Stub_SfcConnectToServer(
  515. IN LPCWSTR ServerName
  516. )
  517. {
  518. SetLastError (ERROR_CALL_NOT_IMPLEMENTED);
  519. return NULL;
  520. }
  521. VOID
  522. Stub_SfcClose(
  523. IN HANDLE RpcHandle
  524. )
  525. {
  526. return;
  527. }
  528. DWORD
  529. WINAPI
  530. Stub_SfcFileException(
  531. IN HANDLE RpcHandle,
  532. IN PCWSTR FileName,
  533. IN DWORD ExpectedChangeType
  534. )
  535. {
  536. return ERROR_CALL_NOT_IMPLEMENTED;
  537. }
  538. BOOL
  539. WINAPI
  540. Stub_SfcIsFileProtected(
  541. IN HANDLE RpcHandle,
  542. IN LPCWSTR ProtFileName
  543. )
  544. {
  545. SetLastError (ERROR_CALL_NOT_IMPLEMENTED);
  546. return FALSE;
  547. }
  548. HANDLE
  549. WINAPI
  550. FirstLoad_SfcConnectToServer(
  551. IN LPCWSTR ServerName
  552. )
  553. {
  554. BOOL ok = FALSE;
  555. try {
  556. EnterCriticalSection(&InitMutex);
  557. if(Dyn_SfcConnectToServer == FirstLoad_SfcConnectToServer) {
  558. (FARPROC) Dyn_SfcConnectToServer = ObtainFnPtr (
  559. "sfc_os.dll",
  560. (LPCSTR)3,
  561. (FARPROC) Stub_SfcConnectToServer
  562. );
  563. }
  564. LeaveCriticalSection(&InitMutex);
  565. ok = TRUE;
  566. } except(EXCEPTION_EXECUTE_HANDLER) {
  567. }
  568. if(ok) {
  569. return Dyn_SfcConnectToServer(ServerName);
  570. } else {
  571. return Stub_SfcConnectToServer(ServerName);
  572. }
  573. }
  574. VOID
  575. FirstLoad_SfcClose(
  576. IN HANDLE RpcHandle
  577. )
  578. {
  579. BOOL ok = FALSE;
  580. try {
  581. EnterCriticalSection(&InitMutex);
  582. if(Dyn_SfcClose == FirstLoad_SfcClose) {
  583. (FARPROC) Dyn_SfcClose = ObtainFnPtr (
  584. "sfc_os.dll",
  585. (LPCSTR)4,
  586. (FARPROC) Stub_SfcClose
  587. );
  588. }
  589. LeaveCriticalSection(&InitMutex);
  590. ok = TRUE;
  591. } except(EXCEPTION_EXECUTE_HANDLER) {
  592. }
  593. if(ok) {
  594. Dyn_SfcClose(RpcHandle);
  595. }
  596. return;
  597. }
  598. DWORD
  599. WINAPI
  600. FirstLoad_SfcFileException(
  601. IN HANDLE RpcHandle,
  602. IN PCWSTR FileName,
  603. IN DWORD ExpectedChangeType
  604. )
  605. {
  606. BOOL ok = FALSE;
  607. try {
  608. EnterCriticalSection(&InitMutex);
  609. if(Dyn_SfcFileException == FirstLoad_SfcFileException) {
  610. (FARPROC) Dyn_SfcFileException = ObtainFnPtr (
  611. "sfc_os.dll",
  612. (LPCSTR)5,
  613. (FARPROC) Stub_SfcFileException
  614. );
  615. }
  616. LeaveCriticalSection(&InitMutex);
  617. ok = TRUE;
  618. } except(EXCEPTION_EXECUTE_HANDLER) {
  619. }
  620. if(ok) {
  621. return Dyn_SfcFileException(RpcHandle,FileName,ExpectedChangeType);
  622. } else {
  623. return Stub_SfcFileException(RpcHandle,FileName,ExpectedChangeType);
  624. }
  625. }
  626. BOOL
  627. WINAPI
  628. FirstLoad_SfcIsFileProtected(
  629. IN HANDLE RpcHandle,
  630. IN LPCWSTR ProtFileName
  631. )
  632. {
  633. BOOL ok = FALSE;
  634. try {
  635. EnterCriticalSection(&InitMutex);
  636. if(Dyn_SfcIsFileProtected == FirstLoad_SfcIsFileProtected) {
  637. (FARPROC) Dyn_SfcIsFileProtected = ObtainFnPtr (
  638. "sfc_os.dll",
  639. "SfcIsFileProtected",
  640. (FARPROC) Stub_SfcIsFileProtected
  641. );
  642. }
  643. LeaveCriticalSection(&InitMutex);
  644. ok = TRUE;
  645. } except(EXCEPTION_EXECUTE_HANDLER) {
  646. }
  647. if(ok) {
  648. return Dyn_SfcIsFileProtected(RpcHandle,ProtFileName);
  649. } else {
  650. return Stub_SfcIsFileProtected(RpcHandle,ProtFileName);
  651. }
  652. }
  653. #ifdef ANSI_SETUPAPI
  654. CONFIGRET
  655. WINAPI
  656. Stub_CM_Query_Resource_Conflict_List(
  657. OUT PCONFLICT_LIST pclConflictList,
  658. IN DEVINST dnDevInst,
  659. IN RESOURCEID ResourceID,
  660. IN PCVOID ResourceData,
  661. IN ULONG ResourceLen,
  662. IN ULONG ulFlags,
  663. IN HMACHINE hMachine
  664. )
  665. {
  666. return CR_CALL_NOT_IMPLEMENTED;
  667. }
  668. CONFIGRET
  669. WINAPI
  670. Stub_CM_Free_Resource_Conflict_Handle(
  671. IN CONFLICT_LIST clConflictList
  672. )
  673. {
  674. return CR_CALL_NOT_IMPLEMENTED;
  675. }
  676. CONFIGRET
  677. WINAPI
  678. Stub_CM_Get_Resource_Conflict_Count(
  679. IN CONFLICT_LIST clConflictList,
  680. OUT PULONG pulCount
  681. )
  682. {
  683. return CR_CALL_NOT_IMPLEMENTED;
  684. }
  685. CONFIGRET
  686. WINAPI
  687. Stub_CM_Get_Resource_Conflict_DetailsA(
  688. IN CONFLICT_LIST clConflictList,
  689. IN ULONG ulIndex,
  690. IN OUT PCONFLICT_DETAILS_A pConflictDetails
  691. )
  692. {
  693. return CR_CALL_NOT_IMPLEMENTED;
  694. }
  695. CONFIGRET
  696. WINAPI
  697. Stub_CM_Get_Class_Registry_PropertyA(
  698. IN LPGUID ClassGUID,
  699. IN ULONG ulProperty,
  700. OUT PULONG pulRegDataType, OPTIONAL
  701. OUT PVOID Buffer, OPTIONAL
  702. IN OUT PULONG pulLength,
  703. IN ULONG ulFlags,
  704. IN HMACHINE hMachine
  705. )
  706. {
  707. return CR_CALL_NOT_IMPLEMENTED;
  708. }
  709. CONFIGRET
  710. WINAPI
  711. Stub_CM_Set_Class_Registry_PropertyA(
  712. IN LPGUID ClassGUID,
  713. IN ULONG ulProperty,
  714. IN PCVOID Buffer, OPTIONAL
  715. IN ULONG ulLength,
  716. IN ULONG ulFlags,
  717. IN HMACHINE hMachine
  718. )
  719. {
  720. return CR_CALL_NOT_IMPLEMENTED;
  721. }
  722. CONFIGRET
  723. WINAPI
  724. Stub_CM_Get_Device_Interface_Alias_ExA(
  725. IN PCSTR pszDeviceInterface,
  726. IN LPGUID AliasInterfaceGuid,
  727. OUT PSTR pszAliasDeviceInterface,
  728. IN OUT PULONG pulLength,
  729. IN ULONG ulFlags,
  730. IN HMACHINE hMachine
  731. )
  732. {
  733. return CR_CALL_NOT_IMPLEMENTED;
  734. }
  735. CONFIGRET
  736. WINAPI
  737. Stub_CM_Get_Device_Interface_List_ExA(
  738. IN LPGUID InterfaceClassGuid,
  739. IN DEVINSTID_A pDeviceID, OPTIONAL
  740. OUT PCHAR Buffer,
  741. IN ULONG BufferLen,
  742. IN ULONG ulFlags,
  743. IN HMACHINE hMachine
  744. )
  745. {
  746. return CR_CALL_NOT_IMPLEMENTED;
  747. }
  748. CONFIGRET
  749. WINAPI
  750. Stub_CM_Get_Device_Interface_List_Size_ExA(
  751. IN PULONG pulLen,
  752. IN LPGUID InterfaceClassGuid,
  753. IN DEVINSTID_A pDeviceID, OPTIONAL
  754. IN ULONG ulFlags,
  755. IN HMACHINE hMachine
  756. )
  757. {
  758. return CR_CALL_NOT_IMPLEMENTED;
  759. }
  760. CONFIGRET
  761. WINAPI
  762. Stub_CM_Get_Log_Conf_Priority_Ex(
  763. IN LOG_CONF lcLogConf,
  764. OUT PPRIORITY pPriority,
  765. IN ULONG ulFlags,
  766. IN HMACHINE hMachine
  767. )
  768. {
  769. return CR_CALL_NOT_IMPLEMENTED;
  770. }
  771. CONFIGRET
  772. WINAPI
  773. Stub_CM_Query_And_Remove_SubTree_ExA(
  774. IN DEVINST dnAncestor,
  775. OUT PPNP_VETO_TYPE pVetoType,
  776. OUT PSTR pszVetoName,
  777. IN ULONG ulNameLength,
  778. IN ULONG ulFlags,
  779. IN HMACHINE hMachine
  780. )
  781. {
  782. return CR_CALL_NOT_IMPLEMENTED;
  783. }
  784. CONFIGRET
  785. WINAPI
  786. Stub_CM_Register_Device_Interface_ExA(
  787. IN DEVINST dnDevInst,
  788. IN LPGUID InterfaceClassGuid,
  789. IN PCSTR pszReference, OPTIONAL
  790. OUT PSTR pszDeviceInterface,
  791. IN OUT PULONG pulLength,
  792. IN ULONG ulFlags,
  793. IN HMACHINE hMachine
  794. )
  795. {
  796. return CR_CALL_NOT_IMPLEMENTED;
  797. }
  798. CONFIGRET
  799. WINAPI
  800. Stub_CM_Set_DevNode_Problem_Ex(
  801. IN DEVINST dnDevInst,
  802. IN ULONG ulProblem,
  803. IN ULONG ulFlags,
  804. IN HMACHINE hMachine
  805. )
  806. {
  807. return CR_CALL_NOT_IMPLEMENTED;
  808. }
  809. CONFIGRET
  810. WINAPI
  811. Stub_CM_Unregister_Device_Interface_ExA(
  812. IN PCSTR pszDeviceInterface,
  813. IN ULONG ulFlags,
  814. IN HMACHINE hMachine
  815. )
  816. {
  817. return CR_CALL_NOT_IMPLEMENTED;
  818. }
  819. BOOL
  820. WINAPI
  821. Stub_CryptCATAdminAcquireContext (
  822. OUT HCATADMIN *phCatAdmin,
  823. IN const GUID *pgSubsystem,
  824. IN DWORD dwFlags
  825. )
  826. {
  827. SetLastError (ERROR_CALL_NOT_IMPLEMENTED);
  828. return FALSE;
  829. }
  830. BOOL
  831. WINAPI
  832. Stub_CryptCATAdminReleaseContext (
  833. IN HCATADMIN hCatAdmin,
  834. IN DWORD dwFlags
  835. )
  836. {
  837. SetLastError (ERROR_CALL_NOT_IMPLEMENTED);
  838. return FALSE;
  839. }
  840. BOOL
  841. WINAPI
  842. Stub_CryptCATAdminReleaseCatalogContext (
  843. IN HCATADMIN hCatAdmin,
  844. IN HCATINFO hCatInfo,
  845. IN DWORD dwFlags
  846. )
  847. {
  848. SetLastError (ERROR_CALL_NOT_IMPLEMENTED);
  849. return FALSE;
  850. }
  851. HCATINFO
  852. WINAPI
  853. Stub_CryptCATAdminAddCatalog (
  854. IN HCATADMIN hCatAdmin,
  855. IN WCHAR *pwszCatalogFile,
  856. IN OPTIONAL WCHAR *pwszSelectBaseName,
  857. IN DWORD dwFlags
  858. )
  859. {
  860. SetLastError (ERROR_CALL_NOT_IMPLEMENTED);
  861. return NULL;
  862. }
  863. BOOL
  864. WINAPI
  865. Stub_CryptCATCatalogInfoFromContext (
  866. IN HCATINFO hCatInfo,
  867. IN OUT CATALOG_INFO *psCatInfo,
  868. IN DWORD dwFlags
  869. )
  870. {
  871. SetLastError (ERROR_CALL_NOT_IMPLEMENTED);
  872. return FALSE;
  873. }
  874. BOOL
  875. WINAPI
  876. Stub_CryptCATAdminCalcHashFromFileHandle (
  877. IN HANDLE hFile,
  878. IN OUT DWORD *pcbHash,
  879. OUT OPTIONAL BYTE *pbHash,
  880. IN DWORD dwFlags
  881. )
  882. {
  883. SetLastError (ERROR_CALL_NOT_IMPLEMENTED);
  884. return FALSE;
  885. }
  886. HCATINFO
  887. WINAPI
  888. Stub_CryptCATAdminEnumCatalogFromHash(
  889. IN HCATADMIN hCatAdmin,
  890. IN BYTE *pbHash,
  891. IN DWORD cbHash,
  892. IN DWORD dwFlags,
  893. IN OUT HCATINFO *phPrevCatInfo
  894. )
  895. {
  896. SetLastError (ERROR_CALL_NOT_IMPLEMENTED);
  897. return NULL;
  898. }
  899. BOOL
  900. WINAPI
  901. Stub_CryptCATAdminRemoveCatalog(
  902. IN HCATADMIN hCatAdmin,
  903. IN WCHAR *pwszCatalogFile,
  904. IN DWORD dwFlags
  905. )
  906. {
  907. SetLastError (ERROR_CALL_NOT_IMPLEMENTED);
  908. return FALSE;
  909. }
  910. BOOL
  911. WINAPI
  912. Stub_CryptCATAdminResolveCatalogPath(
  913. IN HCATADMIN hCatAdmin,
  914. IN WCHAR *pwszCatalogFile,
  915. IN OUT CATALOG_INFO *psCatInfo,
  916. IN DWORD dwFlags
  917. )
  918. {
  919. SetLastError (ERROR_CALL_NOT_IMPLEMENTED);
  920. return FALSE;
  921. }
  922. BOOL
  923. WINAPI
  924. Stub_CertFreeCertificateContext(
  925. IN PCCERT_CONTEXT pCertContext
  926. )
  927. {
  928. SetLastError (ERROR_CALL_NOT_IMPLEMENTED);
  929. return FALSE;
  930. }
  931. LONG
  932. WINAPI
  933. Stub_WinVerifyTrust(
  934. HWND hwnd,
  935. GUID *pgActionID,
  936. LPVOID pWVTData
  937. )
  938. {
  939. return ERROR_SUCCESS;
  940. }
  941. int
  942. Stub_wnsprintf(
  943. LPTSTR lpOut,
  944. int cchLimitIn,
  945. LPCTSTR pszFmt,
  946. ...
  947. )
  948. {
  949. //
  950. // Win95 doesn't have wnsprintf
  951. // in ANSI version of SetupAPI, use CRT instead
  952. //
  953. va_list argptr;
  954. int sz;
  955. if(cchLimitIn<=0) {
  956. return 0;
  957. }
  958. va_start(argptr,pszFmt);
  959. sz = _vsntprintf(lpOut,cchLimitIn,pszFmt,argptr);
  960. if(sz == cchLimitIn) {
  961. //
  962. // backup
  963. //
  964. sz = CharPrev(lpOut,lpOut+sz)-lpOut;
  965. lpOut[sz] = TEXT('\0');
  966. }
  967. return sz;
  968. }
  969. #endif