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.

1409 lines
33 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. setupntp.h
  5. Abstract:
  6. Private top-level header file for Windows NT Setup
  7. services Dll.
  8. Author:
  9. Ted Miller (tedm) 11-Jan-1995
  10. Revision History:
  11. Jamie Hunter (jamiehun) 27-Jan-2000 Added infcache.h
  12. Jim Schmidt (jimschm) 16-Dec-1998 Log api init
  13. Jim Schmidt (jimschm) 28-Apr-1997 Added stub.h
  14. Jamie Hunter (jamiehun) 13-Jan-1997 Added backup.h
  15. --*/
  16. //
  17. // System header files
  18. //
  19. #if DBG
  20. #ifndef MEM_DBG
  21. #define MEM_DBG 1
  22. #endif
  23. #else
  24. #ifndef MEM_DBG
  25. #define MEM_DBG 0
  26. #endif
  27. #endif
  28. //
  29. // NT Header Files
  30. //
  31. #include <nt.h>
  32. #include <ntrtl.h>
  33. #include <nturtl.h>
  34. #include <windows.h>
  35. #include <windowsx.h>
  36. #include <commctrl.h>
  37. #include <commdlg.h>
  38. #include <prsht.h>
  39. #include <spfusion.h>
  40. //
  41. // Make sure we always use version 2 of SP_ALTPLATFORM_INFO structure...
  42. //
  43. #define USE_SP_ALTPLATFORM_INFO_V1 0
  44. #include <setupapi.h>
  45. #include <imagehlp.h>
  46. #include <diamondd.h>
  47. #include <lzexpand.h>
  48. #include <dlgs.h>
  49. #include <regstr.h>
  50. #include <infstr.h>
  51. #include <cfgmgr32.h>
  52. #include <spapip.h>
  53. #include <objbase.h>
  54. #include <devguid.h>
  55. #include <wincrypt.h>
  56. #include <mscat.h>
  57. #include <softpub.h>
  58. #include <wintrust.h>
  59. #include <shlobj.h>
  60. #include <shlwapi.h>
  61. #include <shellapi.h>
  62. #include <cdm.h>
  63. #include <userenv.h>
  64. #include <userenvp.h>
  65. #include <secedit.h>
  66. #include <scesetup.h>
  67. #include <sfcapip.h>
  68. #include <wow64reg.h>
  69. #include <dbt.h>
  70. #include <shimdb.h>
  71. //
  72. // CRT header files
  73. //
  74. #include <process.h>
  75. #include <malloc.h>
  76. #include <wchar.h>
  77. #include <stddef.h>
  78. #include <stdio.h>
  79. #include <fcntl.h>
  80. #include <tchar.h>
  81. #include <mbstring.h>
  82. //
  83. // these definitions may be used by private header files
  84. //
  85. #ifndef ARRAYSIZE
  86. #define ARRAYSIZE(x) (sizeof((x))/sizeof((x)[0]))
  87. #endif
  88. #define SIZECHARS(x) ARRAYSIZE(x)
  89. #define CSTRLEN(x) (SIZECHARS(x)-1)
  90. typedef struct _STRING_TO_DATA {
  91. PCTSTR String;
  92. UINT_PTR Data;
  93. } STRING_TO_DATA, *PSTRING_TO_DATA;
  94. //
  95. // Private header files
  96. //
  97. #include "sputils/locking.h"
  98. #include "sputils/strtab.h"
  99. #include "memory.h"
  100. #include "cntxtlog.h"
  101. #include "inf.h"
  102. #include "infcache.h"
  103. #include "backup.h"
  104. #include "fileq.h"
  105. #include "devinst.h"
  106. #include "devres.h"
  107. #include "rc_ids.h"
  108. #include "msg.h"
  109. #include "stub.h"
  110. #include "helpids.h"
  111. #ifdef CHILDREGISTRATION
  112. #include "childreg.h"
  113. #ifndef _WIN64
  114. #include <wow64t.h>
  115. #endif // _WIN64
  116. #endif // CHILDREGISTRATION
  117. // NTRAID#489682-2001/11/02-JamieHun These need to move into public headers
  118. //
  119. #define SP_COPY_ALREADYDECOMP 0x0400000 // similar to SP_COPY_NODECOMP
  120. //
  121. //
  122. // Private DNF_ flags (start at 0x10000000)
  123. //
  124. #define PDNF_MASK 0xF0000000 // Mask for private PDNF_xxx flags
  125. #define PDNF_CLEANUP_SOURCE_PATH 0x10000000 // Delete the source path when we destroy the driver node
  126. // used when drivers are downloaded from the Internet
  127. //
  128. // Thread Local Storage Index
  129. //
  130. extern DWORD TlsIndex;
  131. //
  132. // Module handle for this DLL. Filled in at process attach.
  133. //
  134. extern HANDLE MyDllModuleHandle;
  135. //
  136. // Module handle for security DLL. Initialized to NULL in at process attach. Filled in when SCE APIs have to be called
  137. //
  138. extern HINSTANCE SecurityDllHandle;
  139. //
  140. // OS Version Information structure filled in at process attach.
  141. //
  142. extern OSVERSIONINFOEX OSVersionInfo;
  143. //
  144. // Static strings we retreive once, at process attach.
  145. //
  146. extern PCTSTR WindowsDirectory,InfDirectory,SystemDirectory,ConfigDirectory,DriversDirectory,System16Directory;
  147. extern PCTSTR SystemSourcePath,ServicePackSourcePath,DriverCacheSourcePath;
  148. extern PCTSTR OsLoaderRelativePath; // may be NULL
  149. extern PCTSTR OsSystemPartitionRoot; // \\?\GLOBALROOT\Device\Volume
  150. extern PCTSTR WindowsBackupDirectory; // Directory to write uninstall backups to
  151. extern PCTSTR ProcessFileName; // Filename of app calling setupapi
  152. extern PCTSTR LastGoodDirectory; // %windir%\LastGood
  153. //
  154. // are we inside gui setup? determined at process attach
  155. //
  156. extern BOOL GuiSetupInProgress;
  157. //
  158. // various other global flags
  159. //
  160. extern DWORD GlobalSetupFlags;
  161. //
  162. // global window message for cancelling autoplay.
  163. //
  164. extern UINT g_uQueryCancelAutoPlay;
  165. //
  166. // Static multi-sz list of directories to be searched for INFs.
  167. //
  168. extern PCTSTR InfSearchPaths;
  169. //
  170. // Determine at runtime if we're running under WOW64
  171. //
  172. #ifndef _WIN64
  173. extern BOOL IsWow64;
  174. #endif
  175. #ifdef UNICODE
  176. extern DWORD Seed;
  177. #endif
  178. //
  179. // ImageHlp isn't multi-thread safe, so needs a mutex
  180. //
  181. extern CRITICAL_SECTION InitMutex; // for one-time initializations
  182. extern CRITICAL_SECTION ImageHlpMutex; // for dealing with IMAGEHLP library
  183. extern CRITICAL_SECTION PlatformPathOverrideCritSect;
  184. extern CRITICAL_SECTION LogUseCountCs;
  185. extern CRITICAL_SECTION MruCritSect;
  186. extern CRITICAL_SECTION NetConnectionListCritSect;
  187. //
  188. // Debug memory functions and wrappers to track allocations
  189. //
  190. DWORD
  191. QueryRegistryValue(
  192. IN HKEY KeyHandle,
  193. IN PCTSTR ValueName,
  194. OUT PTSTR *Value,
  195. OUT PDWORD DataType,
  196. OUT PDWORD DataSizeBytes
  197. );
  198. DWORD
  199. QueryDeviceRegistryProperty(
  200. IN HDEVINFO DeviceInfoSet,
  201. IN PSP_DEVINFO_DATA DeviceInfoData,
  202. IN DWORD Property,
  203. OUT PTSTR *Value,
  204. OUT PDWORD DataType,
  205. OUT PDWORD DataSizeBytes
  206. );
  207. DWORD
  208. QueryRegistryDwordValue(
  209. IN HKEY KeyHandle,
  210. IN PCTSTR ValueName,
  211. OUT PDWORD Value
  212. );
  213. BOOL
  214. MemoryInitializeEx(
  215. IN BOOL Attach
  216. );
  217. #if MEM_DBG
  218. //
  219. // Macros and wrappers are needed for externally exposed functions
  220. //
  221. PVOID MyDebugMalloc(
  222. IN DWORD Size,
  223. IN PCSTR Filename,
  224. IN DWORD Line,
  225. IN DWORD Tag
  226. );
  227. #define MyMalloc(sz) MyDebugMalloc(sz,__FILE__,__LINE__,0)
  228. #define MyTaggedMalloc(sz,tag) MyDebugMalloc(sz,__FILE__,__LINE__,tag)
  229. #define MyTaggedRealloc(ptr,sz,tag) pSetupReallocWithTag(ptr,sz,tag)
  230. #define MyTaggedFree(ptr,tag) pSetupFreeWithTag(ptr,tag)
  231. DWORD
  232. TrackedQueryRegistryValue(
  233. IN TRACK_ARG_DECLARE,
  234. IN HKEY KeyHandle,
  235. IN PCTSTR ValueName,
  236. OUT PTSTR *Value,
  237. OUT PDWORD DataType,
  238. OUT PDWORD DataSizeBytes
  239. );
  240. #define QueryRegistryValue(a,b,c,d,e) TrackedQueryRegistryValue(TRACK_ARG_CALL,a,b,c,d,e)
  241. DWORD
  242. TrackedQueryDeviceRegistryProperty(
  243. IN TRACK_ARG_DECLARE TRACK_ARG_COMMA
  244. IN HDEVINFO DeviceInfoSet,
  245. IN PSP_DEVINFO_DATA DeviceInfoData,
  246. IN DWORD Property,
  247. OUT PTSTR *Value,
  248. OUT PDWORD DataType,
  249. OUT PDWORD DataSizeBytes
  250. );
  251. #define QueryDeviceRegistryProperty(a,b,c,d,e,f) TrackedQueryDeviceRegistryProperty(TRACK_ARG_CALL,a,b,c,d,e,f)
  252. PTSTR
  253. TrackedDuplicateString(
  254. IN TRACK_ARG_DECLARE,
  255. IN PCTSTR String
  256. );
  257. #define DuplicateString(x) TrackedDuplicateString(TRACK_ARG_CALL,x)
  258. #else
  259. #define DuplicateString pSetupDuplicateString
  260. #define MyMalloc(sz) pSetupMalloc(sz)
  261. #define MyTaggedMalloc(sz,tag) pSetupMalloc(sz)
  262. #define MyTaggedRealloc(ptr,sz,tag) pSetupRealloc(ptr,sz)
  263. #define MyTaggedFree(ptr,tag) pSetupFree(ptr)
  264. #endif
  265. #define MyFree(ptr) pSetupFree(ptr)
  266. #define MyRealloc(ptr,sz) pSetupRealloc(ptr,sz)
  267. //
  268. // memory tags grouped here for easy reference
  269. // see also common.h in sputils
  270. //
  271. //
  272. // Log Context tags
  273. //
  274. #define MEMTAG_LOGCONTEXT (0x636c434c) // LClc - context structure
  275. #define MEMTAG_LCSECTION (0x7378434c) // LCxs - section string
  276. #define MEMTAG_LCBUFFER (0x6278434c) // LCxb - other strings
  277. #define MEMTAG_LCINFO (0x6269434c) // LCib - info (array of buffers)
  278. #define MEMTAG_LCINDEXES (0x6969434c) // LCii - index
  279. //
  280. // Loaded_Inf tags
  281. //
  282. #define MEMTAG_INF (0x666e694c) // Linf - LOADED_INF
  283. #define MEMTAG_VBDATA (0x6462764c) // Lvbd - version block data
  284. //
  285. // File functions in fileutil.c
  286. //
  287. typedef struct _TEXTFILE_READ_BUFFER {
  288. PCTSTR TextBuffer;
  289. DWORD TextBufferSize;
  290. HANDLE FileHandle;
  291. HANDLE MappingHandle;
  292. PVOID ViewAddress;
  293. } TEXTFILE_READ_BUFFER, *PTEXTFILE_READ_BUFFER;
  294. DWORD
  295. ReadAsciiOrUnicodeTextFile(
  296. IN HANDLE FileHandle,
  297. OUT PTEXTFILE_READ_BUFFER Result,
  298. IN PSETUP_LOG_CONTEXT LogContext OPTIONAL
  299. );
  300. BOOL
  301. DestroyTextFileReadBuffer(
  302. IN PTEXTFILE_READ_BUFFER ReadBuffer
  303. );
  304. DWORD
  305. GetSetFileTimestamp(
  306. IN PCTSTR FileName,
  307. OUT FILETIME *CreateTime, OPTIONAL
  308. OUT FILETIME *AccessTime, OPTIONAL
  309. OUT FILETIME *WriteTime, OPTIONAL
  310. IN BOOL Set
  311. );
  312. DWORD
  313. RetreiveFileSecurity(
  314. IN PCTSTR FileName,
  315. OUT PSECURITY_DESCRIPTOR *SecurityDescriptor
  316. );
  317. DWORD
  318. StampFileSecurity(
  319. IN PCTSTR FileName,
  320. IN PSECURITY_DESCRIPTOR SecurityInfo
  321. );
  322. DWORD
  323. TakeOwnershipOfFile(
  324. IN PCTSTR Filename
  325. );
  326. DWORD
  327. SearchForInfFile(
  328. IN PCTSTR InfName,
  329. OUT LPWIN32_FIND_DATA FindData,
  330. IN DWORD SearchControl,
  331. OUT PTSTR FullInfPath,
  332. IN UINT FullInfPathSize,
  333. OUT PUINT RequiredSize OPTIONAL
  334. );
  335. DWORD
  336. MultiSzFromSearchControl(
  337. IN DWORD SearchControl,
  338. OUT PTCHAR PathList,
  339. IN DWORD PathListSize,
  340. OUT PDWORD RequiredSize OPTIONAL
  341. );
  342. PSTR
  343. GetAnsiMuiSafePathname(
  344. IN PCTSTR FilePath
  345. );
  346. PSTR
  347. GetAnsiMuiSafeFilename(
  348. IN PCTSTR FilePath
  349. );
  350. BOOL
  351. pSetupAppendPath(
  352. IN PCTSTR Path1,
  353. IN PCTSTR Path2,
  354. OUT PTSTR* Combined
  355. );
  356. BOOL
  357. pSetupApplyExtension(
  358. IN PCTSTR Original,
  359. IN PCTSTR Extension,
  360. OUT PTSTR* NewName
  361. );
  362. //
  363. // Resource/string retrieval routines in resource.c
  364. //
  365. VOID
  366. SetDlgText(
  367. IN HWND hwndDlg,
  368. IN INT iControl,
  369. IN UINT nStartString,
  370. IN UINT nEndString
  371. );
  372. #define SDT_MAX_TEXT 1000 // Max SetDlgText() combined text size
  373. PTSTR
  374. MyLoadString(
  375. IN UINT StringId
  376. );
  377. PTSTR
  378. FormatStringMessage(
  379. IN UINT FormatStringId,
  380. ...
  381. );
  382. PTSTR
  383. FormatStringMessageV(
  384. IN UINT FormatStringId,
  385. IN va_list *ArgumentList
  386. );
  387. PTSTR
  388. FormatStringMessageFromString(
  389. IN PTSTR FormatString,
  390. ...
  391. );
  392. PTSTR
  393. FormatStringMessageFromStringV(
  394. IN PTSTR FormatString,
  395. IN va_list *ArgumentList
  396. );
  397. PTSTR
  398. RetreiveAndFormatMessage(
  399. IN UINT MessageId,
  400. ...
  401. );
  402. PTSTR
  403. RetreiveAndFormatMessageV(
  404. IN UINT MessageId,
  405. IN va_list *ArgumentList
  406. );
  407. INT
  408. FormatMessageBox(
  409. IN HANDLE hinst,
  410. IN HWND hwndParent,
  411. IN UINT TextMessageId,
  412. IN PCTSTR Title,
  413. IN UINT Style,
  414. ...
  415. );
  416. //
  417. // This is in shell32.dll and in windows\inc16\shlsemip.h but
  418. // that file cannot be #include'd here as it has macros that clash
  419. // with our own, etc.
  420. //
  421. #ifdef ANSI_SETUPAPI
  422. //
  423. // Win9x - does not have RestartDialogEx
  424. //
  425. #define RestartDialogEx(hwnd,Prompt,Return,ReasonCode) RestartDialog(hwnd,Prompt,Return)
  426. #endif
  427. //
  428. // Decompression/filename manupilation routines in decomp.c.
  429. //
  430. PTSTR
  431. SetupGenerateCompressedName(
  432. IN PCTSTR Filename
  433. );
  434. DWORD
  435. SetupInternalGetFileCompressionInfo(
  436. IN PCTSTR SourceFileName,
  437. OUT PTSTR *ActualSourceFileName,
  438. OUT PWIN32_FIND_DATA SourceFindData,
  439. OUT PDWORD TargetFileSize,
  440. OUT PUINT CompressionType
  441. );
  442. DWORD
  443. SetupDetermineSourceFileName(
  444. IN PCTSTR FileName,
  445. OUT PBOOL UsedCompressedName,
  446. OUT PTSTR *FileNameLocated,
  447. OUT PWIN32_FIND_DATA FindData
  448. );
  449. BOOL
  450. pSetupDoesFileMatch(
  451. IN PCTSTR InputName,
  452. IN PCTSTR CompareName,
  453. OUT PBOOL UsedCompressedName,
  454. OUT PTSTR *FileNameLocated
  455. );
  456. //
  457. // Diamond functions. The Process and Thread Attach routines are called
  458. // by the DLL entry point routine and should not be called by anyone else.
  459. //
  460. BOOL
  461. DiamondProcessAttach(
  462. IN BOOL Attach
  463. );
  464. BOOL
  465. DiamondTlsInit(
  466. IN BOOL Init
  467. );
  468. BOOL
  469. DiamondIsCabinet(
  470. IN PCTSTR FileName
  471. );
  472. DWORD
  473. DiamondProcessCabinet(
  474. IN PCTSTR CabinetFile,
  475. IN DWORD Flags,
  476. IN PVOID MsgHandler,
  477. IN PVOID Context,
  478. IN BOOL IsUnicodeMsgHandler
  479. );
  480. //
  481. // Misc routines
  482. //
  483. VOID
  484. DiskPromptGetDriveType(
  485. IN PCTSTR PathToSource,
  486. OUT PUINT DriveType,
  487. OUT PBOOL IsRemovable
  488. );
  489. BOOL
  490. SetTruncatedDlgItemText(
  491. HWND hdlg,
  492. UINT CtlId,
  493. PCTSTR TextIn
  494. );
  495. LPTSTR
  496. CompactFileName(
  497. LPCTSTR FileNameIn,
  498. DWORD CharsToRemove
  499. );
  500. DWORD
  501. ExtraChars(
  502. HWND hwnd,
  503. LPCTSTR TextBuffer
  504. );
  505. VOID
  506. pSetupInitPlatformPathOverrideSupport(
  507. IN BOOL Init
  508. );
  509. VOID
  510. pSetupInitSourceListSupport(
  511. IN BOOL Init
  512. );
  513. DWORD
  514. pSetupDecompressOrCopyFile(
  515. IN PCTSTR SourceFileName,
  516. IN PCTSTR TargetFileName,
  517. IN PUINT CompressionType, OPTIONAL
  518. IN BOOL AllowMove,
  519. OUT PBOOL Moved OPTIONAL
  520. );
  521. BOOL
  522. _SetupInstallFileEx(
  523. IN PSP_FILE_QUEUE Queue, OPTIONAL
  524. IN PSP_FILE_QUEUE_NODE QueueNode, OPTIONAL
  525. IN HINF InfHandle, OPTIONAL
  526. IN PINFCONTEXT InfContext, OPTIONAL
  527. IN PCTSTR SourceFile, OPTIONAL
  528. IN PCTSTR SourcePathRoot, OPTIONAL
  529. IN PCTSTR DestinationName, OPTIONAL
  530. IN DWORD CopyStyle,
  531. IN PVOID CopyMsgHandler, OPTIONAL
  532. IN PVOID Context, OPTIONAL
  533. OUT PBOOL FileWasInUse,
  534. IN BOOL IsMsgHandlerNativeCharWidth,
  535. OUT PBOOL SignatureVerifyFailed
  536. );
  537. //
  538. // Define flags for _SetupCopyOEMInf
  539. //
  540. #define SCOI_NO_UI_ON_SIGFAIL 0x00000001
  541. #define SCOI_NO_ERRLOG_ON_MISSING_CATALOG 0x00000002
  542. #define SCOI_NO_ERRLOG_IF_INF_ALREADY_PRESENT 0x00000004
  543. #define SCOI_KEEP_INF_AND_CAT_ORIGINAL_NAMES 0x00000008 // for exception INFs
  544. #define SCOI_ABORT_IF_UNSIGNED 0x00000010
  545. #define SCOI_TRY_UPDATE_PNF 0x00000020 // not fatal if PNF
  546. // present and in use
  547. BOOL
  548. _SetupCopyOEMInf(
  549. IN PCTSTR SourceInfFileName,
  550. IN PCTSTR OEMSourceMediaLocation, OPTIONAL
  551. IN DWORD OEMSourceMediaType,
  552. IN DWORD CopyStyle,
  553. OUT PTSTR DestinationInfFileName, OPTIONAL
  554. IN DWORD DestinationInfFileNameSize,
  555. OUT PDWORD RequiredSize, OPTIONAL
  556. OUT PTSTR *DestinationInfFileNameComponent, OPTIONAL
  557. IN PCTSTR SourceInfOriginalName,
  558. IN PCTSTR SourceInfCatalogName, OPTIONAL
  559. IN HWND Owner,
  560. IN PCTSTR DeviceDesc, OPTIONAL
  561. IN DWORD DriverSigningPolicy,
  562. IN DWORD Flags,
  563. IN PCTSTR AltCatalogFile, OPTIONAL
  564. IN PSP_ALTPLATFORM_INFO_V2 AltPlatformInfo, OPTIONAL
  565. OUT PDWORD DriverSigningError, OPTIONAL
  566. OUT PTSTR CatalogFilenameOnSystem,
  567. IN PSETUP_LOG_CONTEXT LogContext,
  568. IN OUT HCATADMIN *hCatAdmin OPTIONAL
  569. );
  570. DWORD
  571. pSetupUninstallCatalog(
  572. IN LPCTSTR CatalogFilename
  573. );
  574. VOID
  575. pSetupUninstallOEMInf(
  576. IN LPCTSTR InfFullPath,
  577. IN PSETUP_LOG_CONTEXT LogContext, OPTIONAL
  578. IN DWORD Flags,
  579. OUT PDWORD InfDeleteErr OPTIONAL
  580. );
  581. PTSTR
  582. AllocAndReturnDriverSearchList(
  583. IN DWORD SearchControl
  584. );
  585. pSetupGetSecurityInfo(
  586. IN HINF Inf,
  587. IN PCTSTR SectionName,
  588. OUT PCTSTR *SecDesc );
  589. BOOL
  590. pSetupGetDriverDate(
  591. IN HINF InfHandle,
  592. IN PCTSTR Section,
  593. IN OUT PFILETIME pFileTime
  594. );
  595. BOOL
  596. pSetupGetDriverVersion(
  597. IN HINF InfHandle,
  598. IN PCTSTR Section,
  599. OUT DWORDLONG *Version
  600. );
  601. PTSTR
  602. GetMultiSzFromInf(
  603. IN HINF InfHandle,
  604. IN PCTSTR SectionName,
  605. IN PCTSTR Key,
  606. OUT PBOOL pSetupOutOfMemory
  607. );
  608. VOID
  609. pSetupInitNetConnectionList(
  610. IN BOOL Init
  611. );
  612. BOOL
  613. _SetupGetSourceFileSize(
  614. IN HINF InfHandle,
  615. IN PINFCONTEXT InfContext, OPTIONAL
  616. IN PCTSTR FileName, OPTIONAL
  617. IN PCTSTR Section, OPTIONAL
  618. IN PSP_ALTPLATFORM_INFO_V2 AltPlatformInfo, OPTIONAL
  619. OUT PDWORD FileSize,
  620. IN UINT RoundingFactor OPTIONAL
  621. );
  622. BOOL
  623. _SetupGetSourceFileLocation(
  624. IN HINF InfHandle,
  625. IN PINFCONTEXT InfContext, OPTIONAL
  626. IN PCTSTR FileName, OPTIONAL
  627. IN PSP_ALTPLATFORM_INFO_V2 AltPlatformInfo, OPTIONAL
  628. OUT PUINT SourceId, OPTIONAL
  629. OUT PTSTR ReturnBuffer, OPTIONAL
  630. IN DWORD ReturnBufferSize,
  631. OUT PDWORD RequiredSize, OPTIONAL
  632. OUT PINFCONTEXT LineContext OPTIONAL
  633. );
  634. DWORD
  635. pSetupLogSectionError(
  636. IN HINF InfHandle, OPTIONAL
  637. IN HDEVINFO DeviceInfoSet, OPTIONAL
  638. IN PSP_DEVINFO_DATA DeviceInfoData, OPTIONAL
  639. IN PSP_FILE_QUEUE Queue, OPTIONAL
  640. IN PCTSTR SectionName,
  641. IN DWORD MsgID,
  642. IN DWORD Err,
  643. IN PCTSTR KeyName OPTIONAL
  644. );
  645. DWORD
  646. pSetupLogSectionWarning(
  647. IN HINF InfHandle, OPTIONAL
  648. IN HDEVINFO DeviceInfoSet, OPTIONAL
  649. IN PSP_DEVINFO_DATA DeviceInfoData, OPTIONAL
  650. IN PSP_FILE_QUEUE Queue, OPTIONAL
  651. IN PCTSTR SectionName,
  652. IN DWORD MsgID,
  653. IN DWORD Err,
  654. IN PCTSTR KeyName OPTIONAL
  655. );
  656. DWORD
  657. pSetupCopyRelatedInfs(
  658. IN HINF hDeviceInf,
  659. IN PCTSTR InfFileName, OPTIONAL
  660. IN PCTSTR InfSectionName,
  661. IN DWORD OEMSourceMediaType,
  662. IN PSETUP_LOG_CONTEXT LogContext OPTIONAL
  663. );
  664. BOOL
  665. pCompareFilesExact(
  666. IN PCTSTR File1,
  667. IN PCTSTR File2
  668. );
  669. //
  670. // Routine to call out to a PSP_FILE_CALLBACK, handles
  671. // Unicode<-->ANSI issues
  672. //
  673. UINT
  674. pSetupCallMsgHandler(
  675. IN PSETUP_LOG_CONTEXT LogContext,
  676. IN PVOID MsgHandler,
  677. IN BOOL MsgHandlerIsNativeCharWidth,
  678. IN PVOID Context,
  679. IN UINT Notification,
  680. IN UINT_PTR Param1,
  681. IN UINT_PTR Param2
  682. );
  683. UINT
  684. pSetupCallDefaultMsgHandler(
  685. IN PVOID Context,
  686. IN UINT Notification,
  687. IN UINT_PTR Param1,
  688. IN UINT_PTR Param2
  689. );
  690. //
  691. // Internal routine to get MRU list.
  692. //
  693. DWORD
  694. pSetupGetList(
  695. IN DWORD Flags,
  696. OUT PCTSTR **List,
  697. OUT PUINT Count,
  698. OUT PBOOL NoBrowse
  699. );
  700. #define SRCPATH_USEPNFINFORMATION 0x00000001
  701. #define SRCPATH_USEINFLOCATION 0x00000002
  702. #define SRC_FLAGS_SVCPACK_SOURCE (0x0001)
  703. #define PSP_COPY_USE_DRIVERCACHE 0x80000000
  704. #define PSP_COPY_CHK_DRIVERCACHE 0x40000000
  705. PTSTR
  706. pSetupGetDefaultSourcePath(
  707. IN HINF InfHandle,
  708. IN DWORD Flags,
  709. OUT PDWORD InfSourceMediaType
  710. );
  711. VOID
  712. InfSourcePathFromFileName(
  713. IN PCTSTR InfFileName,
  714. OUT PTSTR *SourcePath, OPTIONAL
  715. OUT PBOOL TryPnf
  716. );
  717. BOOL
  718. pSetupGetSourceInfo(
  719. IN HINF InfHandle, OPTIONAL
  720. IN PINFCONTEXT LayoutLineContext, OPTIONAL
  721. IN UINT SourceId,
  722. IN PSP_ALTPLATFORM_INFO_V2 AltPlatformInfo, OPTIONAL
  723. IN UINT InfoDesired,
  724. OUT PTSTR ReturnBuffer, OPTIONAL
  725. IN DWORD ReturnBufferSize,
  726. OUT PDWORD RequiredSize OPTIONAL
  727. );
  728. //
  729. // function to get the apropriate return value for ReturnStatus, for specific callback Notification
  730. //
  731. UINT
  732. pGetCallbackErrorReturn(
  733. IN UINT Notification,
  734. IN DWORD ReturnStatus
  735. );
  736. //
  737. // Routines for creating/destroying global mini-icon list.
  738. //
  739. BOOL
  740. CreateMiniIcons(
  741. VOID
  742. );
  743. VOID
  744. DestroyMiniIcons(
  745. VOID
  746. );
  747. //
  748. // Global log init/terminate
  749. //
  750. VOID
  751. InitLogApi (
  752. VOID
  753. );
  754. VOID
  755. TerminateLogApi (
  756. VOID
  757. );
  758. //
  759. // DIRID mapping routines.
  760. //
  761. PCTSTR
  762. pSetupVolatileDirIdToPath(
  763. IN PCTSTR DirectoryId, OPTIONAL
  764. IN UINT DirectoryIdInt, OPTIONAL
  765. IN PCTSTR SubDirectory, OPTIONAL
  766. IN PLOADED_INF Inf
  767. );
  768. DWORD
  769. ApplyNewVolatileDirIdsToInfs(
  770. IN PLOADED_INF MasterInf,
  771. IN PLOADED_INF Inf OPTIONAL
  772. );
  773. PCTSTR
  774. pSetupDirectoryIdToPathEx(
  775. IN PCTSTR DirectoryId, OPTIONAL
  776. IN OUT PUINT DirectoryIdInt, OPTIONAL
  777. IN PCTSTR SubDirectory, OPTIONAL
  778. IN PCTSTR InfSourcePath, OPTIONAL
  779. IN OUT PCTSTR *OsLoaderPath, OPTIONAL
  780. OUT PBOOL VolatileSystemDirId OPTIONAL
  781. );
  782. PCTSTR
  783. pGetPathFromDirId(
  784. IN PCTSTR DirectoryId,
  785. IN PCTSTR SubDirectory, OPTIONAL
  786. IN PLOADED_INF pLoadedInf
  787. );
  788. //
  789. // routines for inter-thread communication
  790. //
  791. #ifndef UNICODE
  792. #define MyMsgWaitForMultipleObjectsEx(nc,ph,dwms,dwwm,dwfl) MsgWaitForMultipleObjects(nc,ph,FALSE,dwms,dwwm)
  793. #else
  794. #define MyMsgWaitForMultipleObjectsEx MsgWaitForMultipleObjectsEx
  795. #endif
  796. //
  797. // Macro to make ansi vs unicode string handling
  798. // a little easier
  799. //
  800. #ifdef UNICODE
  801. #define NewAnsiString(x) pSetupUnicodeToAnsi(x)
  802. #define NewPortableString(x) pSetupAnsiToUnicode(x)
  803. #else
  804. #define NewAnsiString(x) DuplicateString(x)
  805. #define NewPortableString(x) DuplicateString(x)
  806. #endif
  807. //
  808. // Internal file-handling routines in fileutil.c
  809. //
  810. DWORD
  811. MapFileForRead(
  812. IN HANDLE FileHandle,
  813. OUT PDWORD FileSize,
  814. OUT PHANDLE MappingHandle,
  815. OUT PVOID *BaseAddress
  816. );
  817. BOOL
  818. DoMove(
  819. IN PCTSTR CurrentName,
  820. IN PCTSTR NewName
  821. );
  822. BOOL
  823. DelayedMove(
  824. IN PCTSTR CurrentName,
  825. IN PCTSTR NewName OPTIONAL
  826. );
  827. extern GUID DriverVerifyGuid;
  828. //
  829. // Flags for VerifySourceFile and _VerifyFile
  830. //
  831. #define VERIFY_FILE_IGNORE_SELFSIGNED 0x00000001
  832. #define VERIFY_FILE_USE_OEM_CATALOGS 0x00000002
  833. #define VERIFY_FILE_FAIL_COPIED_INFS 0x00000004
  834. #define VERIFY_FILE_DRIVERBLOCKED_ONLY 0x00000008
  835. #define VERIFY_FILE_NO_DRIVERBLOCKED_CHECK 0x00000010
  836. DWORD
  837. _VerifyFile(
  838. IN PSETUP_LOG_CONTEXT LogContext,
  839. IN OUT HCATADMIN *hCatAdmin, OPTIONAL
  840. IN OUT HSDB *hSDBDrvMain, OPTIONAL
  841. IN LPCTSTR Catalog, OPTIONAL
  842. IN PVOID CatalogBaseAddress, OPTIONAL
  843. IN DWORD CatalogImageSize,
  844. IN LPCTSTR Key,
  845. IN LPCTSTR FileFullPath,
  846. OUT SetupapiVerifyProblem *Problem, OPTIONAL
  847. OUT LPTSTR ProblemFile, OPTIONAL
  848. IN BOOL CatalogAlreadyVerified,
  849. IN PSP_ALTPLATFORM_INFO_V2 AltPlatformInfo, OPTIONAL
  850. IN DWORD Flags, OPTIONAL
  851. OUT LPTSTR CatalogFileUsed, OPTIONAL
  852. OUT PDWORD NumCatalogsConsidered, OPTIONAL
  853. OUT LPTSTR DigitalSigner, OPTIONAL
  854. OUT LPTSTR SignerVersion OPTIONAL
  855. );
  856. DWORD
  857. VerifySourceFile(
  858. IN PSETUP_LOG_CONTEXT LogContext,
  859. IN PSP_FILE_QUEUE Queue, OPTIONAL
  860. IN PSP_FILE_QUEUE_NODE QueueNode, OPTIONAL
  861. IN PCTSTR Key,
  862. IN PCTSTR FileToVerifyFullPath,
  863. IN PCTSTR OriginalSourceFileFullPath, OPTIONAL
  864. IN PSP_ALTPLATFORM_INFO_V2 AltPlatformInfo, OPTIONAL
  865. IN DWORD Flags,
  866. OUT SetupapiVerifyProblem *Problem,
  867. OUT LPTSTR ProblemFile,
  868. OUT LPTSTR CatalogFileUsed, OPTIONAL
  869. OUT LPTSTR DigitalSigner, OPTIONAL
  870. OUT LPTSTR SignerVersion OPTIONAL
  871. );
  872. BOOL
  873. VerifyDeviceInfFile(
  874. IN PSETUP_LOG_CONTEXT LogContext,
  875. IN OUT HCATADMIN *hCatAdmin, OPTIONAL
  876. IN LPCTSTR CurrentInfName,
  877. IN PLOADED_INF pInf,
  878. IN PSP_ALTPLATFORM_INFO_V2 AltPlatformInfo, OPTIONAL
  879. OUT LPTSTR CatalogFileUsed, OPTIONAL
  880. OUT LPTSTR DigitalSigner, OPTIONAL
  881. OUT LPTSTR SignerVersion OPTIONAL
  882. );
  883. BOOL
  884. IsInfForDeviceInstall(
  885. IN PSETUP_LOG_CONTEXT LogContext, OPTIONAL
  886. IN CONST GUID *DeviceSetupClassGuid, OPTIONAL
  887. IN PLOADED_INF LoadedInf, OPTIONAL
  888. OUT PTSTR *DeviceDesc, OPTIONAL
  889. OUT PSP_ALTPLATFORM_INFO_V2 *ValidationPlatform, OPTIONAL
  890. OUT PDWORD PolicyToUse, OPTIONAL
  891. OUT PBOOL UseOriginalInfName OPTIONAL
  892. );
  893. DWORD
  894. GetCodeSigningPolicyForInf(
  895. IN PSETUP_LOG_CONTEXT LogContext, OPTIONAL
  896. IN HINF InfHandle,
  897. OUT PSP_ALTPLATFORM_INFO_V2 *ValidationPlatform, OPTIONAL
  898. OUT PBOOL UseOriginalInfName OPTIONAL
  899. );
  900. typedef struct _DRVSIGN_CLASS_LIST_NODE {
  901. GUID DeviceSetupClassGuid; // class subject to driver signing policy
  902. INT MajorVerLB; // -1 if no validation platform override info
  903. INT MinorVerLB; // -1 if no validation platform override info
  904. } DRVSIGN_CLASS_LIST_NODE, *PDRVSIGN_CLASS_LIST_NODE;
  905. typedef struct _DRVSIGN_POLICY_LIST {
  906. //
  907. // Array of device setup class GUIDs for which driver signing policy is
  908. // applicable, along with validation platform override information (if
  909. // appropriate).
  910. //
  911. PDRVSIGN_CLASS_LIST_NODE Members;
  912. //
  913. // Number of elements in above array (initialized to -1).
  914. //
  915. INT NumMembers;
  916. //
  917. // Synchronization
  918. //
  919. MYLOCK Lock;
  920. } DRVSIGN_POLICY_LIST, *PDRVSIGN_POLICY_LIST;
  921. #define LockDrvSignPolicyList(d) BeginSynchronizedAccess(&((d)->Lock))
  922. #define UnlockDrvSignPolicyList(d) EndSynchronizedAccess(&((d)->Lock))
  923. //
  924. // Global "Driver Search In-Progress" list.
  925. //
  926. extern DRVSIGN_POLICY_LIST GlobalDrvSignPolicyList;
  927. BOOL
  928. InitDrvSignPolicyList(
  929. VOID
  930. );
  931. VOID
  932. DestroyDrvSignPolicyList(
  933. VOID
  934. );
  935. BOOL
  936. IsFileProtected(
  937. IN LPCTSTR FileFullPath,
  938. IN PSETUP_LOG_CONTEXT LogContext, OPTIONAL
  939. OUT PHANDLE phSfp OPTIONAL
  940. );
  941. #define FileExists pSetupFileExists
  942. BOOL
  943. GetVersionInfoFromImage(
  944. IN PCTSTR FileName,
  945. OUT PDWORDLONG Version,
  946. OUT LANGID *Language
  947. );
  948. //
  949. // Utils
  950. //
  951. PCTSTR
  952. GetSystemSourcePath(
  953. TRACK_ARG_DECLARE
  954. );
  955. PCTSTR
  956. GetServicePackSourcePath(
  957. TRACK_ARG_DECLARE
  958. );
  959. DWORD
  960. RegistryDelnode(
  961. IN HKEY RootKey,
  962. IN PCTSTR SubKeyName,
  963. IN DWORD ExtraFlags
  964. );
  965. DWORD
  966. CaptureStringArg(
  967. IN PCTSTR String,
  968. OUT PCTSTR *CapturedString
  969. );
  970. DWORD
  971. DelimStringToMultiSz(
  972. IN PTSTR String,
  973. IN DWORD StringLen,
  974. IN TCHAR Delim
  975. );
  976. BOOL
  977. pAToI(
  978. IN PCTSTR Field,
  979. OUT PINT IntegerValue
  980. );
  981. DWORD
  982. pAcquireSCMLock(
  983. IN SC_HANDLE SCMHandle,
  984. OUT SC_LOCK *pSCMLock,
  985. IN PSETUP_LOG_CONTEXT LogContext
  986. );
  987. //
  988. // wrapper around pSetupStringTableStringFromIdEx to allocate buffer on fly
  989. //
  990. DWORD
  991. QueryStringTableStringFromId(
  992. IN PVOID StringTable,
  993. IN LONG StringId,
  994. IN ULONG Padding,
  995. OUT PTSTR *pBuffer
  996. );
  997. //
  998. // Define flags for DoInstallActionWithParams
  999. //
  1000. #define INSTALLACTION_CALL_CI 0x00000001
  1001. #define INSTALLACTION_NO_DEFAULT 0x00000002
  1002. DWORD
  1003. DoInstallActionWithParams(
  1004. IN DI_FUNCTION InstallFunction,
  1005. IN HDEVINFO DeviceInfoSet,
  1006. IN PSP_DEVINFO_DATA DeviceInfoData, OPTIONAL
  1007. IN PSP_CLASSINSTALL_HEADER ClassInstallParams, OPTIONAL
  1008. IN DWORD ClassInstallParamsSize,
  1009. IN DWORD Flags
  1010. );
  1011. BOOL
  1012. LookUpStringInTable(
  1013. IN PSTRING_TO_DATA Table,
  1014. IN PCTSTR String,
  1015. OUT PUINT_PTR Data
  1016. );
  1017. //
  1018. // Diagnostic/debug functions in debug.c
  1019. //
  1020. #define DebugPrintEx pSetupDebugPrintEx
  1021. #if DBG
  1022. #define MYTRACE(x) DebugPrintEx x /*(...)*/
  1023. #else
  1024. #define MYTRACE(x)
  1025. #endif
  1026. //
  1027. // Allow assertion checking to be turned on independently
  1028. // of DBG, like by specifying C_DEFINES=-DASSERTS_ON=1 in sources file.
  1029. //
  1030. #ifndef ASSERTS_ON
  1031. #if DBG
  1032. #define ASSERTS_ON 1
  1033. #else
  1034. #define ASSERTS_ON 0
  1035. #endif
  1036. #endif
  1037. #if ASSERTS_ON
  1038. VOID
  1039. AssertFail(
  1040. IN PSTR FileName,
  1041. IN UINT LineNumber,
  1042. IN PSTR Condition,
  1043. IN BOOL NoUI
  1044. );
  1045. #define MYASSERT(x) if(!(x)) { AssertFail(__FILE__,__LINE__,#x,FALSE); }
  1046. #else
  1047. #define MYASSERT(x)
  1048. #endif
  1049. #ifdef _X86_
  1050. BOOL
  1051. IsNEC98(
  1052. VOID
  1053. );
  1054. #endif
  1055. //
  1056. // Stubs to allow ANSI build to run on Win9x
  1057. //
  1058. #ifdef DBGHEAP_CHECK
  1059. #ifdef ANSI_SETUPAPI
  1060. #define ASSERT_HEAP_IS_VALID()
  1061. #else
  1062. #define ASSERT_HEAP_IS_VALID() RtlValidateHeap(pSetupGetHeap(),0,NULL)
  1063. #endif // ANSI_SETUPAPI
  1064. #else
  1065. #define ASSERT_HEAP_IS_VALID()
  1066. #endif // DBGHEAP_CHECK
  1067. //
  1068. // TLS data/macro's
  1069. //
  1070. //
  1071. // Diamond TLS data.
  1072. //
  1073. typedef struct _DIAMOND_THREAD_DATA {
  1074. //
  1075. // Boolean value indicating whether the current thread
  1076. // is inside diamond. Diamond doesn't really providee
  1077. // a full context environment so we declare it non-reentrant.
  1078. //
  1079. BOOL InDiamond;
  1080. //
  1081. // Diamond context data
  1082. //
  1083. HFDI FdiContext;
  1084. ERF FdiError;
  1085. //
  1086. // Last encountered error
  1087. //
  1088. DWORD LastError;
  1089. //
  1090. // Name of cabinet as passed to DiamondProcessCabinet,
  1091. //
  1092. PCTSTR CabinetFile;
  1093. //
  1094. // Notification callback and context parameter
  1095. //
  1096. PVOID MsgHandler;
  1097. PVOID Context;
  1098. BOOL IsMsgHandlerNativeCharWidth;
  1099. //
  1100. // Full path of the current target file being extracted.
  1101. //
  1102. PTSTR CurrentTargetFile;
  1103. //
  1104. // Flag indicating whether diamond asked us to switch cabinets.
  1105. // If we do switch, then we stop copying when the current file
  1106. // is done. This prevents diamond from happily doing each file
  1107. // in the new cabinet, which would ruin the queue commit routine's
  1108. // ability to allow some files to exist outside the cabinet, etc.
  1109. //
  1110. BOOL SwitchedCabinets;
  1111. //
  1112. // If the source path changes as the result of a prompt for a
  1113. // new cabinet (when a file continues across multiple cabinets),
  1114. // we remember the path the user gave us here.
  1115. //
  1116. TCHAR UserPath[MAX_PATH];
  1117. } DIAMOND_THREAD_DATA, *PDIAMOND_THREAD_DATA;
  1118. typedef struct _SETUP_TLS {
  1119. struct _SETUP_TLS *Prev;
  1120. struct _SETUP_TLS *Next;
  1121. //
  1122. // all TLS data used by SetupAPI
  1123. //
  1124. DIAMOND_THREAD_DATA Diamond;
  1125. SETUP_LOG_TLS SetupLog;
  1126. DWORD PerThreadDoneComponent;
  1127. DWORD PerThreadFailedComponent;
  1128. } SETUP_TLS, *PSETUP_TLS;
  1129. PSETUP_TLS
  1130. SetupGetTlsData(
  1131. );
  1132. //
  1133. // Registration flags.
  1134. //
  1135. #define SP_GETSTATUS_FROMDLL 0x00000001 // in proc dll registration
  1136. #define SP_GETSTATUS_FROMPROCESS 0x00000002 // executable registration
  1137. #define SP_GETSTATUS_FROMSURRAGATE 0x00000004 // surragate process dll registration
  1138. #if MEM_DBG
  1139. //
  1140. // these have to be at the bottom to compile
  1141. //
  1142. #define GetSystemSourcePath() GetSystemSourcePath(TRACK_ARG_CALL)
  1143. #define GetServicePackSourcePath() GetServicePackSourcePath(TRACK_ARG_CALL)
  1144. #define InheritLogContext(a,b) InheritLogContext(TRACK_ARG_CALL,a,b)
  1145. #endif
  1146. BOOL
  1147. InitComponents(
  1148. DWORD Components
  1149. );
  1150. VOID
  1151. ComponentCleanup(
  1152. DWORD Components
  1153. );
  1154. //#define COMPONENT_OLE 0x00000001 // need to use OLE
  1155. //#define COMPONENT_FUSION 0x00000002 // need to use Fusion
  1156. //
  1157. // RetrieveAllDriversForDevice flags
  1158. //
  1159. #define RADFD_FLAG_FUNCTION_DRIVER 0x00000001
  1160. #define RADFD_FLAG_DEVICE_UPPER_FILTERS 0x00000002
  1161. #define RADFD_FLAG_DEVICE_LOWER_FILTERS 0x00000004
  1162. #define RADFD_FLAG_CLASS_UPPER_FILTERS 0x00000008
  1163. #define RADFD_FLAG_CLASS_LOWER_FILTERS 0x00000010
  1164. #define RADFD_FLAG_DEVICE_FILTERS RADFD_FLAG_DEVICE_UPPER_FILTERS | RADFD_FLAG_DEVICE_LOWER_FILTERS
  1165. #define RADFD_FLAG_CLASS_FILTERS RADFD_FLAG_CLASS_UPPER_FILTERS | RADFD_FLAG_CLASS_LOWER_FILTERS
  1166. #define RADFD_FLAG_ALL_FILTERS RADFD_FLAG_DEVICE_FILTERS | RADFD_FLAG_CLASS_FILTERS
  1167. BOOL
  1168. RetrieveAllDriversForDevice(
  1169. IN PDEVINFO_ELEM DevInfoElem,
  1170. OUT PTSTR *FilterDrivers,
  1171. IN DWORD Flags,
  1172. IN HMACHINE hMachine
  1173. );