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.

1323 lines
49 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. fileq6.c
  5. Abstract:
  6. Copy list scanning functions.
  7. Author:
  8. Ted Miller (tedm) 24-Feb-1995
  9. Revision History:
  10. --*/
  11. #include "precomp.h"
  12. #pragma hdrstop
  13. //
  14. // Define mask that isolates the action to be performed on the file queue.
  15. //
  16. #define SPQ_ACTION_MASK (SPQ_SCAN_FILE_PRESENCE | SPQ_SCAN_FILE_VALIDITY | SPQ_SCAN_USE_CALLBACK | SPQ_SCAN_USE_CALLBACKEX | SPQ_SCAN_USE_CALLBACK_SIGNERINFO)
  17. #define SPQ_SCAN_USE_CALLBACKEX_PRESENCE (SPQ_SCAN_FILE_PRESENCE|SPQ_SCAN_USE_CALLBACKEX)
  18. BOOL
  19. _SetupMarkFileNodeTargetFlags(
  20. IN PSP_FILE_QUEUE FileQueue,
  21. IN LONG RootID,
  22. IN LONG DirID,
  23. IN LONG FileID,
  24. IN DWORD MaskFlags,
  25. IN DWORD Flags,
  26. OUT PDWORD PriorFlags
  27. )
  28. {
  29. SP_TARGET_ENT TargetInfo;
  30. LONG TargetID;
  31. DWORD rc;
  32. DWORD OldFlags;
  33. MYASSERT(Flags == (MaskFlags&Flags));
  34. rc = pSetupBackupGetTargetByPath((HSPFILEQ)FileQueue,
  35. NULL, // use Queue's string table
  36. NULL,
  37. RootID,
  38. DirID,
  39. FileID,
  40. &TargetID,
  41. &TargetInfo
  42. );
  43. if (rc != NO_ERROR) {
  44. SetLastError(rc);
  45. return FALSE;
  46. }
  47. OldFlags = TargetInfo.InternalFlags;
  48. TargetInfo.InternalFlags = (TargetInfo.InternalFlags&~MaskFlags)|Flags;
  49. if(OldFlags != TargetInfo.InternalFlags) {
  50. rc = pSetupBackupSetTargetByID((HSPFILEQ)FileQueue,
  51. TargetID,
  52. &TargetInfo
  53. );
  54. }
  55. if(PriorFlags) {
  56. *PriorFlags = OldFlags;
  57. }
  58. if (rc != NO_ERROR) {
  59. SetLastError(rc);
  60. return FALSE;
  61. }
  62. return TRUE;
  63. }
  64. BOOL
  65. _SetupScanFileQueue(
  66. IN HSPFILEQ FileQueue,
  67. IN DWORD Flags,
  68. IN HWND Window, OPTIONAL
  69. IN PVOID CallbackRoutine, OPTIONAL
  70. IN PVOID CallbackContext, OPTIONAL
  71. OUT PDWORD Result,
  72. IN BOOL IsNativeCharWidth
  73. )
  74. /*++
  75. Routine Description:
  76. Implementation for SetupScanFileQueue, handles ANSI and Unicode
  77. callback functions.
  78. Arguments:
  79. Same as SetupScanFileQueue().
  80. IsNativeCharWidth - supplies flag indicating whether callback routine is
  81. expecting unicode params. Meaningful only in UNICODE version of DLL.
  82. Return Value:
  83. Same as SetupScanFileQueue().
  84. --*/
  85. {
  86. DWORD Action;
  87. PSP_FILE_QUEUE Queue;
  88. PSP_FILE_QUEUE_NODE QueueNode, TempNode, NextNode;
  89. PSP_FILE_QUEUE_NODE CheckNode;
  90. PSOURCE_MEDIA_INFO SourceMedia;
  91. BOOL Continue;
  92. TCHAR TargetPath[MAX_PATH];
  93. BOOL Err;
  94. int i;
  95. PTSTR Message;
  96. DWORD flags;
  97. DWORD Win32Error;
  98. SetupapiVerifyProblem Problem;
  99. TCHAR TempCharBuffer[MAX_PATH];
  100. TCHAR SourcePath[MAX_PATH];
  101. TCHAR DigitalSigner[MAX_PATH];
  102. TCHAR SignerVersion[MAX_PATH];
  103. TCHAR CatalogFile[MAX_PATH];
  104. DWORD rc;
  105. UINT Notification;
  106. UINT_PTR CallbackParam1;
  107. FILEPATHS FilePaths;
  108. FILEPATHS_SIGNERINFO FilePathsSignerInfo;
  109. BOOL DoPruning, PruneNode;
  110. PSPQ_CATALOG_INFO CatalogNode;
  111. PSETUP_LOG_CONTEXT lc = NULL;
  112. DWORD slot_fileop = 0;
  113. Queue = (PSP_FILE_QUEUE)FileQueue;
  114. rc = NO_ERROR;
  115. try {
  116. if (Queue->Signature != SP_FILE_QUEUE_SIG) {
  117. rc = ERROR_INVALID_HANDLE;
  118. }
  119. } except(EXCEPTION_EXECUTE_HANDLER) {
  120. rc = ERROR_INVALID_HANDLE;
  121. }
  122. if(rc != NO_ERROR) {
  123. SetLastError(rc);
  124. return(FALSE);
  125. }
  126. lc = Queue->LogContext;
  127. //
  128. // Validate arguments. Exactly one action flag must be specified.
  129. //
  130. if(Result) {
  131. *Result = 0;
  132. } else {
  133. SetLastError(ERROR_INVALID_PARAMETER);
  134. return(FALSE);
  135. }
  136. Action = (Flags & SPQ_ACTION_MASK);
  137. switch(Action) {
  138. case SPQ_SCAN_FILE_PRESENCE:
  139. case SPQ_SCAN_FILE_VALIDITY:
  140. break;
  141. case SPQ_SCAN_USE_CALLBACK:
  142. case SPQ_SCAN_USE_CALLBACKEX:
  143. case SPQ_SCAN_USE_CALLBACKEX_PRESENCE:
  144. case SPQ_SCAN_USE_CALLBACK_SIGNERINFO:
  145. if(CallbackRoutine) {
  146. break;
  147. }
  148. // else fall through to invalid arg case
  149. default:
  150. SetLastError(ERROR_INVALID_PARAMETER);
  151. return(FALSE);
  152. }
  153. DoPruning = Flags & SPQ_SCAN_PRUNE_COPY_QUEUE;
  154. if(DoPruning) {
  155. if(Queue->Flags & FQF_QUEUE_ALREADY_COMMITTED) {
  156. //
  157. // If we've been asked to prune the copy queue, then make sure the queue
  158. // hasn't been committed yet.
  159. //
  160. SetLastError(ERROR_NO_MORE_ITEMS);
  161. return FALSE;
  162. }
  163. if((Action == SPQ_SCAN_USE_CALLBACK)
  164. || (Action == SPQ_SCAN_USE_CALLBACKEX)
  165. || (Action == SPQ_SCAN_USE_CALLBACKEX_PRESENCE)
  166. || (Action == SPQ_SCAN_USE_CALLBACK_SIGNERINFO)
  167. || (Flags & SPQ_SCAN_INFORM_USER)) {
  168. //
  169. // Presently, pruning the queue is not supported when using a callback.
  170. // Also, SPQ_SCAN_INFORM_USER and SPQ_SCAN_PRUNE_COPY_QUEUE don't play well
  171. // together...
  172. //
  173. SetLastError(ERROR_INVALID_FLAGS);
  174. return FALSE;
  175. }
  176. }
  177. //
  178. // If the caller asked for UI, make sure we're running interactively.
  179. //
  180. if((Flags & SPQ_SCAN_INFORM_USER) && (GlobalSetupFlags & (PSPGF_NONINTERACTIVE|PSPGF_UNATTENDED_SETUP))) {
  181. SetLastError(ERROR_REQUIRES_INTERACTIVE_WINDOWSTATION);
  182. return FALSE;
  183. }
  184. //
  185. // If we're verifying the digital signatures of the files, then first make
  186. // sure that we've processed the catalog nodes for this queue. However, we
  187. // don't want any copying to take place if there are OEM INFs in the list.
  188. //
  189. if((Action == SPQ_SCAN_FILE_VALIDITY) ||
  190. (Action == SPQ_SCAN_USE_CALLBACKEX) ||
  191. (Action == SPQ_SCAN_USE_CALLBACK_SIGNERINFO)) {
  192. WriteLogEntry(
  193. lc,
  194. SETUP_LOG_TIME,
  195. MSG_LOG_BEGIN_VERIFY4_CAT_TIME,
  196. NULL); // text message
  197. rc = _SetupVerifyQueuedCatalogs(Window,
  198. Queue,
  199. VERCAT_NO_PROMPT_ON_ERROR,
  200. NULL,
  201. NULL
  202. );
  203. WriteLogEntry(
  204. lc,
  205. SETUP_LOG_TIME,
  206. MSG_LOG_END_VERIFY4_CAT_TIME,
  207. NULL); // text message
  208. if((Action == SPQ_SCAN_FILE_VALIDITY) && (rc != NO_ERROR)) {
  209. WriteLogEntry(
  210. lc,
  211. (rc == ERROR_CANNOT_COPY ? SETUP_LOG_VVERBOSE : SETUP_LOG_WARNING) | SETUP_LOG_BUFFER,
  212. MSG_LOG_SCANQUEUE_VERIFY_FAILED,
  213. NULL);
  214. WriteLogError(
  215. lc,
  216. (rc == ERROR_CANNOT_COPY ? SETUP_LOG_VVERBOSE : SETUP_LOG_WARNING),
  217. rc);
  218. //
  219. // Result output param has already been initialized to zero
  220. // above.
  221. //
  222. return TRUE;
  223. }
  224. } else {
  225. rc = NO_ERROR;
  226. }
  227. //
  228. // Regardless of whether or not the catalog validation succeeded
  229. // above, we still want to call the callback for each file. The
  230. // failed catalog verifications will be reflected in the failed
  231. // file verifications that the caller gets informed of via the
  232. // Win32Error field of the FILEPATHS struct we give the callback.
  233. //
  234. // Initialize the static fields of that structure here so we don't
  235. // have to each pass through the loop below.
  236. //
  237. FilePaths.Target = TargetPath;
  238. FilePaths.Source = SourcePath;
  239. FilePathsSignerInfo.Target = TargetPath;
  240. FilePathsSignerInfo.Source = SourcePath;
  241. //
  242. // markup delete/rename usage
  243. // we don't need to do this if we have SPQ_SCAN_PRUNE_DELREN set
  244. //
  245. if(!(Flags & SPQ_SCAN_PRUNE_DELREN)) {
  246. for(TempNode=Queue->DeleteQueue; TempNode; TempNode=TempNode->Next) {
  247. if(!_SetupMarkFileNodeTargetFlags(Queue,
  248. TempNode->TargetDirectory,
  249. -1,
  250. TempNode->TargetFilename,
  251. SP_TEFLG_PRUNE_DEL,SP_TEFLG_PRUNE_DEL,
  252. NULL)) {
  253. //
  254. // this would indicate an out-of-memory condition
  255. // last error is set
  256. //
  257. return FALSE;
  258. }
  259. }
  260. for(TempNode=Queue->RenameQueue; TempNode; TempNode=TempNode->Next) {
  261. if(!_SetupMarkFileNodeTargetFlags(Queue,
  262. TempNode->SourcePath,
  263. -1,
  264. TempNode->SourceFilename,
  265. SP_TEFLG_PRUNE_RENSRC,SP_TEFLG_PRUNE_RENSRC,
  266. NULL)) {
  267. //
  268. // this would indicate an out-of-memory condition
  269. // last error is set
  270. //
  271. return FALSE;
  272. }
  273. if(!_SetupMarkFileNodeTargetFlags(Queue,
  274. TempNode->TargetDirectory == -1 ? TempNode->SourcePath : TempNode->TargetDirectory,
  275. -1,
  276. TempNode->TargetFilename,
  277. SP_TEFLG_PRUNE_RENTARG,SP_TEFLG_PRUNE_RENTARG,
  278. NULL)) {
  279. //
  280. // this would indicate an out-of-memory condition
  281. // last error is set
  282. //
  283. return FALSE;
  284. }
  285. }
  286. }
  287. //
  288. // Process all nodes in the copy queue.
  289. //
  290. Err = FALSE;
  291. Continue = TRUE;
  292. for(SourceMedia=Queue->SourceMediaList; Continue && SourceMedia; SourceMedia=SourceMedia->Next) {
  293. TempNode = NULL;
  294. QueueNode = SourceMedia->CopyQueue;
  295. while(Continue && QueueNode) {
  296. DWORD PrevNodeFlags;
  297. //
  298. // markup copy usage
  299. //
  300. if(!_SetupMarkFileNodeTargetFlags(Queue,
  301. QueueNode->TargetDirectory,
  302. -1,
  303. QueueNode->TargetFilename,
  304. SP_TEFLG_PRUNE_COPY,SP_TEFLG_PRUNE_COPY,
  305. &PrevNodeFlags)) {
  306. //
  307. // this would indicate an out-of-memory condition
  308. // last error is set
  309. //
  310. rc = GetLastError();
  311. Err = TRUE;
  312. Continue = FALSE;
  313. break;
  314. }
  315. //
  316. // Form target path.
  317. //
  318. lstrcpyn(
  319. TargetPath,
  320. pSetupStringTableStringFromId(Queue->StringTable,QueueNode->TargetDirectory),
  321. MAX_PATH
  322. );
  323. pSetupConcatenatePaths(
  324. TargetPath,
  325. pSetupStringTableStringFromId(Queue->StringTable,QueueNode->TargetFilename),
  326. MAX_PATH,
  327. NULL
  328. );
  329. if((PrevNodeFlags & (SP_TEFLG_PRUNE_DEL|SP_TEFLG_PRUNE_RENSRC|SP_TEFLG_PRUNE_RENTARG))
  330. && !((Flags & SPQ_SCAN_PRUNE_DELREN) || (QueueNode->StyleFlags & SP_COPY_NOPRUNE))) {
  331. DWORD msg;
  332. //
  333. // this file is touched in source/target
  334. // but the INF author forgot to mark it as SP_COPY_NOPRUNE
  335. // this typically indicates a mistake on the author's part
  336. // so we try and handle it best as we can
  337. // if SPQ_SCAN_PRUNE_DELREN is set, we'll kill the delete/rename entries
  338. // if it's not set, we enforce the SP_COPY_NOPRUNE
  339. //
  340. QueueNode->StyleFlags |= SP_COPY_NOPRUNE;
  341. if(PrevNodeFlags & SP_TEFLG_PRUNE_DEL) {
  342. msg = MSG_LOG_CHANGEPRUNE_DEL;
  343. } else if(PrevNodeFlags & SP_TEFLG_PRUNE_RENSRC) {
  344. msg = MSG_LOG_CHANGEPRUNE_RENSRC;
  345. } else {
  346. msg = MSG_LOG_CHANGEPRUNE_RENTARG;
  347. }
  348. WriteLogEntry(
  349. lc,
  350. SETUP_LOG_WARNING,
  351. msg,
  352. NULL,
  353. TargetPath);
  354. }
  355. //
  356. // Perform check on file.
  357. //
  358. PruneNode = FALSE;
  359. switch(Action) {
  360. case SPQ_SCAN_FILE_PRESENCE:
  361. Continue = FileExists(TargetPath,NULL);
  362. if(DoPruning) {
  363. //
  364. // File's presence should result in this copy node's removal
  365. // from the queue--it's absence should be ignored.
  366. //
  367. if(Continue) {
  368. PruneNode = TRUE;
  369. } else {
  370. //
  371. // Leave copy node alone.
  372. //
  373. PruneNode = FALSE;
  374. Continue = TRUE;
  375. }
  376. } else {
  377. if (Continue) {
  378. //
  379. // we should not continue if the copy node is marked as a "no prune" node
  380. //
  381. if (QueueNode->StyleFlags & SP_COPY_NOPRUNE) {
  382. Continue = FALSE;
  383. }
  384. }
  385. }
  386. break;
  387. case SPQ_SCAN_FILE_VALIDITY:
  388. //
  389. // If we are going to prune the copy queue then:
  390. //
  391. // (a) only validate the file against the system catalogs (not
  392. // against any OEM catalogs), and
  393. // (b) don't validate self-signed files.
  394. //
  395. // (Note: we will never consider an INF in %windir%\Inf to be
  396. // signed, since it is invalid to copy an INF there via a file
  397. // queue. SetupCopyOEMInf must be used instead.)
  398. //
  399. if(GlobalSetupFlags & PSPGF_MINIMAL_EMBEDDED) {
  400. //
  401. // If we're pruning, then we don't want to consider any
  402. // existing files as valid, otherwise we'd never copy
  403. // anything!
  404. //
  405. Continue = !DoPruning;
  406. //
  407. // We want to prune the queue node if the target exists and the source doesn't
  408. //
  409. if ( DoPruning && FileExists(TargetPath, NULL) ) {
  410. //
  411. // The target exists! Now build the path the source file...
  412. //
  413. lstrcpyn(SourcePath,
  414. pSetupStringTableStringFromId(Queue->StringTable, QueueNode->SourceRootPath),
  415. SIZECHARS(SourcePath)
  416. );
  417. if (QueueNode->SourcePath != -1) {
  418. pSetupConcatenatePaths(SourcePath,
  419. pSetupStringTableStringFromId(Queue->StringTable, QueueNode->SourcePath),
  420. SIZECHARS(SourcePath),
  421. NULL
  422. );
  423. }
  424. pSetupConcatenatePaths(SourcePath,
  425. pSetupStringTableStringFromId(Queue->StringTable, QueueNode->SourceFilename),
  426. SIZECHARS(SourcePath),
  427. NULL
  428. );
  429. //
  430. // If there's no source file to copy, prune this node
  431. //
  432. Continue = !FileExists(SourcePath, NULL);
  433. }
  434. } else {
  435. Continue = (NO_ERROR == VerifySourceFile(lc,
  436. Queue,
  437. QueueNode,
  438. pSetupGetFileTitle(TargetPath),
  439. TargetPath,
  440. NULL,
  441. ((Queue->Flags & FQF_USE_ALT_PLATFORM)
  442. ? &(Queue->AltPlatformInfo)
  443. : Queue->ValidationPlatform),
  444. (DoPruning
  445. ? (VERIFY_FILE_IGNORE_SELFSIGNED | VERIFY_FILE_FAIL_COPIED_INFS)
  446. : (VERIFY_FILE_USE_OEM_CATALOGS | VERIFY_FILE_FAIL_COPIED_INFS)),
  447. &Problem,
  448. TempCharBuffer,
  449. NULL,
  450. NULL,
  451. NULL
  452. ));
  453. }
  454. if(DoPruning) {
  455. //
  456. // File's validity should result in this copy node's removal
  457. // from the queue--it's invalidity should be ignored.
  458. //
  459. if(Continue) {
  460. PruneNode = TRUE;
  461. } else {
  462. //
  463. // Leave copy node alone.
  464. //
  465. PruneNode = FALSE;
  466. Continue = TRUE;
  467. }
  468. } else {
  469. if (Continue) {
  470. //
  471. // we should not continue if the copy node is marked as a "no prune" node
  472. //
  473. if (QueueNode->StyleFlags & SP_COPY_NOPRUNE) {
  474. Continue = FALSE;
  475. }
  476. }
  477. }
  478. break;
  479. case SPQ_SCAN_USE_CALLBACK:
  480. case SPQ_SCAN_USE_CALLBACKEX:
  481. case SPQ_SCAN_USE_CALLBACKEX_PRESENCE:
  482. case SPQ_SCAN_USE_CALLBACK_SIGNERINFO:
  483. flags = (QueueNode->InternalFlags & (INUSE_INF_WANTS_REBOOT | INUSE_IN_USE))
  484. ? SPQ_DELAYED_COPY
  485. : 0;
  486. if((Action == SPQ_SCAN_USE_CALLBACKEX) ||
  487. (Action == SPQ_SCAN_USE_CALLBACKEX_PRESENCE) ||
  488. (Action == SPQ_SCAN_USE_CALLBACK_SIGNERINFO)) {
  489. //
  490. // The caller requested the extended version of the queue
  491. // scan callback--we need to build the source file path.
  492. //
  493. lstrcpyn(SourcePath,
  494. pSetupStringTableStringFromId(Queue->StringTable, QueueNode->SourceRootPath),
  495. SIZECHARS(SourcePath)
  496. );
  497. if(QueueNode->SourcePath != -1) {
  498. pSetupConcatenatePaths(SourcePath,
  499. pSetupStringTableStringFromId(Queue->StringTable, QueueNode->SourcePath),
  500. SIZECHARS(SourcePath),
  501. NULL
  502. );
  503. }
  504. pSetupConcatenatePaths(SourcePath,
  505. pSetupStringTableStringFromId(Queue->StringTable, QueueNode->SourceFilename),
  506. SIZECHARS(SourcePath),
  507. NULL
  508. );
  509. if((Action == SPQ_SCAN_USE_CALLBACKEX_PRESENCE)) {
  510. Win32Error = NO_ERROR;
  511. } else {
  512. CatalogFile[0] = TEXT('\0');
  513. DigitalSigner[0] = TEXT('\0');
  514. SignerVersion[0] = TEXT('\0');
  515. if(GlobalSetupFlags & PSPGF_MINIMAL_EMBEDDED) {
  516. //
  517. // We can't call our internal VerifySourceFile
  518. // routine, because it doesn't expect to be asked
  519. // for signer info when in "minimal embedded" mode
  520. // (plus, it doesn't make sense to ask for such
  521. // info anyway, since we have no idea who signed
  522. // the file, or even if it was signed).
  523. //
  524. Win32Error = NO_ERROR;
  525. } else {
  526. Win32Error = VerifySourceFile(lc,
  527. Queue,
  528. QueueNode,
  529. pSetupGetFileTitle(TargetPath),
  530. TargetPath,
  531. NULL,
  532. ((Queue->Flags & FQF_USE_ALT_PLATFORM)
  533. ? &(Queue->AltPlatformInfo)
  534. : Queue->ValidationPlatform),
  535. VERIFY_FILE_USE_OEM_CATALOGS | VERIFY_FILE_FAIL_COPIED_INFS,
  536. &Problem,
  537. TempCharBuffer,
  538. (Action == SPQ_SCAN_USE_CALLBACK_SIGNERINFO)
  539. ? CatalogFile
  540. : NULL,
  541. (Action == SPQ_SCAN_USE_CALLBACK_SIGNERINFO)
  542. ? DigitalSigner
  543. : NULL,
  544. (Action == SPQ_SCAN_USE_CALLBACK_SIGNERINFO)
  545. ? SignerVersion
  546. : NULL
  547. );
  548. }
  549. }
  550. if ((Action == SPQ_SCAN_USE_CALLBACKEX) ||
  551. (Action == SPQ_SCAN_USE_CALLBACKEX_PRESENCE)) {
  552. FilePaths.Win32Error = Win32Error;
  553. FilePaths.Flags = QueueNode->StyleFlags;
  554. CallbackParam1 = (UINT_PTR)(&FilePaths);
  555. Notification = SPFILENOTIFY_QUEUESCAN_EX;
  556. } else {
  557. FilePathsSignerInfo.Win32Error = Win32Error;
  558. FilePathsSignerInfo.Flags = QueueNode->StyleFlags;
  559. FilePathsSignerInfo.DigitalSigner = (DigitalSigner[0] != TEXT('\0'))
  560. ? DigitalSigner
  561. : NULL;
  562. FilePathsSignerInfo.Version = (SignerVersion[0] != TEXT('\0'))
  563. ? SignerVersion
  564. : NULL;
  565. FilePathsSignerInfo.CatalogFile = (CatalogFile[0] != TEXT('\0'))
  566. ? CatalogFile
  567. : NULL;
  568. CallbackParam1 = (UINT_PTR)(&FilePathsSignerInfo);
  569. Notification = SPFILENOTIFY_QUEUESCAN_SIGNERINFO;
  570. }
  571. } else {
  572. CallbackParam1 = (UINT_PTR)TargetPath;
  573. Notification = SPFILENOTIFY_QUEUESCAN;
  574. }
  575. rc = (DWORD)pSetupCallMsgHandler(
  576. lc,
  577. CallbackRoutine,
  578. IsNativeCharWidth,
  579. CallbackContext,
  580. Notification,
  581. CallbackParam1,
  582. flags
  583. );
  584. *Result = rc;
  585. Err = (rc != NO_ERROR);
  586. Continue = !Err;
  587. break;
  588. }
  589. if(DoPruning && PruneNode) {
  590. BOOL ReallyPrune = TRUE;
  591. MYASSERT(Continue == TRUE);
  592. //
  593. // before we remove the item from the queue, we must check if the copy item
  594. // also exists in the rename or delete queues. if it does, then we cannot
  595. // prune the item from the copy queue
  596. //
  597. if (QueueNode->StyleFlags & SP_COPY_NOPRUNE) {
  598. ReallyPrune = FALSE;
  599. TempNode = QueueNode;
  600. QueueNode = QueueNode->Next;
  601. }
  602. if (ReallyPrune) {
  603. WriteLogEntry(
  604. lc,
  605. SETUP_LOG_VERBOSE,
  606. MSG_LOG_PRUNE,
  607. NULL,
  608. TargetPath);
  609. NextNode = QueueNode->Next;
  610. if(TempNode) {
  611. TempNode->Next = NextNode;
  612. } else {
  613. SourceMedia->CopyQueue = NextNode;
  614. }
  615. MyFree(QueueNode);
  616. QueueNode = NextNode;
  617. //
  618. // Adjust the queue node counts.
  619. //
  620. Queue->CopyNodeCount--;
  621. SourceMedia->CopyNodeCount--;
  622. }
  623. } else {
  624. TempNode = QueueNode;
  625. QueueNode = QueueNode->Next;
  626. }
  627. }
  628. }
  629. if(Flags & SPQ_SCAN_PRUNE_DELREN) {
  630. //
  631. // flag tells us to rip out of Delete/Rename queues
  632. // files that are (or was) in the copy queue.
  633. // we'll only be asked to do this in limited cases
  634. // (eg, GUI setup)
  635. //
  636. TempNode = NULL;
  637. QueueNode = Queue->DeleteQueue;
  638. while(QueueNode) {
  639. DWORD PrevFlags;
  640. NextNode = QueueNode->Next;
  641. if(_SetupMarkFileNodeTargetFlags(Queue,
  642. QueueNode->TargetDirectory,
  643. -1,
  644. QueueNode->TargetFilename,
  645. 0,0,
  646. &PrevFlags)) {
  647. if(PrevFlags & SP_TEFLG_PRUNE_COPY) {
  648. //
  649. // warn about this
  650. //
  651. lstrcpyn(
  652. TargetPath,
  653. pSetupStringTableStringFromId(Queue->StringTable,QueueNode->TargetDirectory),
  654. MAX_PATH
  655. );
  656. pSetupConcatenatePaths(
  657. TargetPath,
  658. pSetupStringTableStringFromId(Queue->StringTable,QueueNode->TargetFilename),
  659. MAX_PATH,
  660. NULL
  661. );
  662. WriteLogEntry(
  663. lc,
  664. SETUP_LOG_WARNING,
  665. MSG_LOG_PRUNE_DEL,
  666. NULL,
  667. TargetPath);
  668. if(TempNode) {
  669. TempNode->Next = NextNode;
  670. } else {
  671. Queue->DeleteQueue = NextNode;
  672. }
  673. MyFree(QueueNode);
  674. Queue->DeleteNodeCount--;
  675. QueueNode = NextNode;
  676. continue;
  677. }
  678. }
  679. TempNode = QueueNode;
  680. QueueNode = NextNode;
  681. }
  682. TempNode = NULL;
  683. QueueNode = Queue->RenameQueue;
  684. while(QueueNode) {
  685. DWORD PrevFlags;
  686. NextNode = QueueNode->Next;
  687. if(_SetupMarkFileNodeTargetFlags(Queue,
  688. QueueNode->SourcePath,
  689. -1,
  690. QueueNode->SourceFilename,
  691. 0,0,
  692. &PrevFlags)) {
  693. if(PrevFlags & SP_TEFLG_PRUNE_COPY) {
  694. //
  695. // warn about this
  696. //
  697. lstrcpyn(
  698. TargetPath,
  699. pSetupStringTableStringFromId(Queue->StringTable,QueueNode->SourcePath),
  700. MAX_PATH
  701. );
  702. pSetupConcatenatePaths(
  703. TargetPath,
  704. pSetupStringTableStringFromId(Queue->StringTable,QueueNode->SourceFilename),
  705. MAX_PATH,
  706. NULL
  707. );
  708. WriteLogEntry(
  709. lc,
  710. SETUP_LOG_WARNING,
  711. MSG_LOG_PRUNE_RENSRC,
  712. NULL,
  713. TargetPath);
  714. if(TempNode) {
  715. TempNode->Next = NextNode;
  716. } else {
  717. Queue->RenameQueue = NextNode;
  718. }
  719. MyFree(QueueNode);
  720. Queue->RenameNodeCount--;
  721. QueueNode = NextNode;
  722. continue;
  723. }
  724. }
  725. if(_SetupMarkFileNodeTargetFlags(Queue,
  726. QueueNode->TargetDirectory == -1 ? QueueNode->SourcePath : QueueNode->TargetDirectory,
  727. -1,
  728. QueueNode->TargetFilename,
  729. 0,0,
  730. &PrevFlags)) {
  731. if(PrevFlags & SP_TEFLG_PRUNE_COPY) {
  732. //
  733. // warn about this
  734. //
  735. lstrcpyn(
  736. TargetPath,
  737. pSetupStringTableStringFromId(Queue->StringTable,QueueNode->TargetDirectory == -1 ? QueueNode->SourcePath : QueueNode->TargetDirectory),
  738. MAX_PATH
  739. );
  740. pSetupConcatenatePaths(
  741. TargetPath,
  742. pSetupStringTableStringFromId(Queue->StringTable,QueueNode->TargetFilename),
  743. MAX_PATH,
  744. NULL
  745. );
  746. WriteLogEntry(
  747. lc,
  748. SETUP_LOG_WARNING,
  749. MSG_LOG_PRUNE_RENTARG,
  750. NULL,
  751. TargetPath);
  752. if(TempNode) {
  753. TempNode->Next = NextNode;
  754. } else {
  755. Queue->RenameQueue = NextNode;
  756. }
  757. MyFree(QueueNode);
  758. Queue->RenameNodeCount--;
  759. QueueNode = NextNode;
  760. continue;
  761. }
  762. }
  763. TempNode = QueueNode;
  764. QueueNode = NextNode;
  765. }
  766. }
  767. //
  768. // If the case of SPQ_SCAN_USE_CALLBACK(EX), *Result is already set up
  769. // when we get here. If Continue is TRUE then we visited all nodes
  770. // and the presence/validity check passed on all of them. Note that
  771. // if Continue is TRUE then Err must be FALSE.
  772. //
  773. if((Action == SPQ_SCAN_FILE_PRESENCE) || (Action == SPQ_SCAN_FILE_VALIDITY)) {
  774. if(DoPruning) {
  775. //
  776. // Set result based on whether any of the queues have nodes in them.
  777. //
  778. if(Queue->CopyNodeCount) {
  779. *Result = 0;
  780. } else {
  781. *Result = (Queue->DeleteNodeCount || Queue->RenameNodeCount || Queue->BackupNodeCount) ? 2 : 1;
  782. }
  783. } else {
  784. //
  785. // If we weren't doing pruning, then we know that the Continue
  786. // variable indicates whether or not we bailed partway through.
  787. //
  788. if(Continue) {
  789. //
  790. // Need to set up Result.
  791. //
  792. if((Flags & SPQ_SCAN_INFORM_USER) && Queue->CopyNodeCount
  793. && (Message = RetreiveAndFormatMessage(MSG_NO_NEED_TO_COPY))) {
  794. //
  795. // Overload TargetPath for use as the caption string.
  796. //
  797. GetWindowText(Window,TargetPath,sizeof(TargetPath)/sizeof(TargetPath[0]));
  798. i = MessageBox(
  799. Window,
  800. Message,
  801. TargetPath,
  802. MB_APPLMODAL | MB_YESNO | MB_ICONINFORMATION
  803. );
  804. MyFree(Message);
  805. if(i == IDYES) {
  806. //
  807. // User wants to skip copying.
  808. //
  809. *Result = (Queue->DeleteNodeCount || Queue->RenameNodeCount || Queue->BackupNodeCount) ? 2 : 1;
  810. } else {
  811. //
  812. // User wants to perform copy.
  813. //
  814. *Result = 0;
  815. }
  816. } else {
  817. //
  818. // Don't want to ask user. Set up Result based on whether
  819. // there are items in the delete, rename or backup queues.
  820. //
  821. *Result = (Queue->DeleteNodeCount || Queue->RenameNodeCount || Queue->BackupNodeCount) ? 2 : 1;
  822. }
  823. } else {
  824. //
  825. // Presence/validity check failed.
  826. //
  827. *Result = 0;
  828. }
  829. //
  830. // Empty the copy queue if necessary.
  831. //
  832. if(*Result) {
  833. for(SourceMedia=Queue->SourceMediaList; Continue && SourceMedia; SourceMedia=SourceMedia->Next) {
  834. for(QueueNode=SourceMedia->CopyQueue; QueueNode; QueueNode=TempNode) {
  835. TempNode = QueueNode->Next;
  836. MyFree(QueueNode);
  837. }
  838. Queue->CopyNodeCount -= SourceMedia->CopyNodeCount;
  839. SourceMedia->CopyQueue = NULL;
  840. SourceMedia->CopyNodeCount = 0;
  841. }
  842. //
  843. // We think we just removed all files in all copy queues.
  844. // The 2 counts we maintain should be in sync -- meaning that
  845. // the total copy node count should now be 0.
  846. //
  847. MYASSERT(Queue->CopyNodeCount == 0);
  848. }
  849. }
  850. }
  851. SetLastError(rc);
  852. return(!Err);
  853. }
  854. #ifdef UNICODE
  855. //
  856. // ANSI version for UNICODE
  857. //
  858. BOOL
  859. SetupScanFileQueueA(
  860. IN HSPFILEQ FileQueue,
  861. IN DWORD Flags,
  862. IN HWND Window, OPTIONAL
  863. IN PSP_FILE_CALLBACK_A CallbackRoutine, OPTIONAL
  864. IN PVOID CallbackContext, OPTIONAL
  865. OUT PDWORD Result
  866. )
  867. {
  868. BOOL b;
  869. try {
  870. b = _SetupScanFileQueue(
  871. FileQueue,
  872. Flags,
  873. Window,
  874. CallbackRoutine,
  875. CallbackContext,
  876. Result,
  877. FALSE
  878. );
  879. } except(EXCEPTION_EXECUTE_HANDLER) {
  880. b = FALSE;
  881. SetLastError(ERROR_INVALID_DATA);
  882. }
  883. return(b);
  884. }
  885. #else
  886. //
  887. // UNICODE version for Win9x
  888. //
  889. BOOL
  890. SetupScanFileQueueW(
  891. IN HSPFILEQ FileQueue,
  892. IN DWORD Flags,
  893. IN HWND Window, OPTIONAL
  894. IN PSP_FILE_CALLBACK_W CallbackRoutine, OPTIONAL
  895. IN PVOID CallbackContext, OPTIONAL
  896. OUT PDWORD Result
  897. )
  898. {
  899. UNREFERENCED_PARAMETER(FileQueue);
  900. UNREFERENCED_PARAMETER(Flags);
  901. UNREFERENCED_PARAMETER(Window);
  902. UNREFERENCED_PARAMETER(CallbackRoutine);
  903. UNREFERENCED_PARAMETER(CallbackContext);
  904. UNREFERENCED_PARAMETER(Result);
  905. SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
  906. return(FALSE);
  907. }
  908. #endif
  909. BOOL
  910. SetupScanFileQueue(
  911. IN HSPFILEQ FileQueue,
  912. IN DWORD Flags,
  913. IN HWND Window, OPTIONAL
  914. IN PSP_FILE_CALLBACK CallbackRoutine, OPTIONAL
  915. IN PVOID CallbackContext, OPTIONAL
  916. OUT PDWORD Result
  917. )
  918. /*++
  919. Routine Description:
  920. This routine scans a setup file queue, performing an operation on each
  921. node in its copy list. The operation is specified by a set of flags.
  922. A caller can use this API to determine whether all files that have been
  923. enqueued for copy already exist on the target, and if so, to inform the
  924. user, who may elect to skip the file copying. This can spare the user from
  925. having to furnish Setup media in many cases.
  926. Arguments:
  927. FileQueue - supplies handle to Setup file queue whose copy list is to
  928. be scanned/iterated.
  929. Flags - supplies a set of values that control operation of the API. A
  930. combination of the following values:
  931. SPQ_SCAN_FILE_PRESENCE - determine whether all target files in the
  932. copy queue are already present on the target.
  933. SPQ_SCAN_FILE_VALIDITY - determine whether all target files in the
  934. copy queue are already present on the target, and verify their
  935. digital signatures.
  936. SPQ_SCAN_USE_CALLBACK - for each node in the queue, call the
  937. callback routine with SPFILENOTIFY_QUEUESCAN. If the callback
  938. routine returns non-0 then queue processing is stopped and this
  939. routine returns FALSE immediately.
  940. SPQ_SCAN_USE_CALLBACKEX - same as SPQ_SCAN_USE_CALLBACK except that
  941. SPFILENOTIFY_QUEUESCAN_EX is used instead. This supplies a pointer
  942. to a FILEPATHS structure in Param1, thus you get both source and
  943. destination info. You also get the results of the file presence
  944. check (and if present, of its digital signature verification) in
  945. the Win32Error field, and the CopyStyle flags in effect for that
  946. copy queue node in the Flags field.
  947. SPQ_SCAN_USE_CALLBACK_SIGNERINFO - same as SPQ_SCAN_USE_CALLBACK except
  948. that SPFILENOTIFY_QUEUESCAN_SIGNERINFO is used instead. This
  949. supplies a pointer to a FILEPATHS_SIGNERINFO structure in Param1,
  950. thus you get both source and destination info. You also get the
  951. results of the file presence check (and if present, of its digital
  952. signature verification) in the Win32Error field, and the CopyStyle
  953. flags in effect for that copy queue node in the Flags field. In
  954. addition you get who digitaly signed the file in the DigitalSigner
  955. field and the SHA1 key in the SignerId field.
  956. Exactly one of SPQ_SCAN_FILE_PRESENCE, SPQ_SCAN_FILE_VALIDITY,
  957. SPQ_SCAN_USE_CALLBACK, SPQ_SCAN_USE_CALLBACKEX, or
  958. SPQ_SCAN_USE_CALLBACK_SIGNERINFO must be specified.
  959. SPQ_SCAN_INFORM_USER - if specified and all files in the queue
  960. pass the presence/validity check, then this routine will inform
  961. the user that the operation he is attempting requires files but
  962. that we believe all files are already present. Ignored if
  963. SPQ_SCAN_FILE_PRESENCE or SPQ_SCAN_FILE_VALIDITY is not specified.
  964. Not valid if specified in combination with SPQ_SCAN_PRUNE_COPY_QUEUE.
  965. SPQ_SCAN_PRUNE_COPY_QUEUE - if specified, the copy queue will be pruned
  966. of any nodes that are deemed unnecessary. This determination is
  967. made based on the type of queue scan being performed:
  968. If SPQ_SCAN_FILE_PRESENCE, then the presence of a file having the
  969. destination filename is sufficient to consider this copy operation
  970. unnecessary.
  971. If SPQ_SCAN_FILE_VALIDITY, then the destination file must not only
  972. be present, but also valid in order for the copy operation to be
  973. considered unnecessary.
  974. If SPQ_SCAN_USE_CALLBACK, SPQ_SCAN_USE_CALLBACKEX or
  975. SPQ_SCAN_USE_CALLBACK_SIGNERINFO, then the queue callback routine
  976. should return zero to mark the copy node as unnecessary, or non-zero
  977. to leave the node in the copy queue.
  978. NOTE: This flag may only be specified _before_ the queue has been
  979. committed. This means that the flags contained in Param2 will
  980. always be zero. If SetupScanFileQueue is called with
  981. SPQ_SCAN_PRUNE_COPY_QUEUE after committing the queue, the API will
  982. fail and GetLastError() will return
  983. ERROR_NO_MORE_ITEMS.
  984. This flag is not valid if specified in combination with
  985. SPQ_SCAN_INFORM_USER.
  986. Window - specifies the window to own any dialogs, etc, that may be
  987. presented. Unused if Flags does not contain one of
  988. SPQ_SCAN_FILE_PRESENCE or SPQ_SCAN_FILE_VALIDITY, or if Flags does not
  989. contain SPQ_SCAN_INFORM_USER.
  990. CallbackRoutine - required if Flags includes SPQ_SCAN_USE_CALLBACK.
  991. Specifies a callback function to be called on each node in
  992. the copy queue. The notification code passed to the callback is
  993. SPFILENOTIFY_QUEUESCAN.
  994. CallbackContext - caller-defined data to be passed to CallbackRoutine.
  995. Result - receives result of routine. See below.
  996. Return Value:
  997. If FALSE, then an error occurred or the callback function returned non-0.
  998. Check Result -- if it is non-0, then it is the value returned by
  999. the callback function which stopped queue processing.
  1000. If Result is 0, then extended error information is available from
  1001. GetLastError().
  1002. If TRUE, then all nodes were processed. Result is 0 if a callback was
  1003. specified. If SPQ_SCAN_USE_CALLBACK(EX) or SPQ_SCAN_USE_CALLBACK_SIGNERINFO
  1004. was not specified, then Result indicates whether the queue passed the
  1005. presence/validity check:
  1006. Result = 0: queue failed the check, or the queue passed the
  1007. check but SPQ_SCAN_INFORM_USER was specified and the user indicated
  1008. that he wants new copies of the files. There are still nodes in the
  1009. copy queue, although if SPQ_SCAN_PRUNE_COPY_QUEUE is specified, then
  1010. any nodes that were validated have been pruned.
  1011. Result = 1: queue passed the check, and, if SPQ_SCAN_INFORM_USER was
  1012. specified, the user indicated that no copying is required. If Result is
  1013. 1, the copy queue has been emptied, and there are no elements on the
  1014. delete or rename queues, so the caller may skip queue commit.
  1015. Result = 2: queue passed the check, and, if SPQ_SCAN_INFORM_USER was
  1016. specified, the user indicated that no copying is required. In this case,
  1017. the copy queue has been emptied, however there are elements on the
  1018. delete or rename queues, so the caller may not skip queue commit.
  1019. --*/
  1020. {
  1021. BOOL b;
  1022. try {
  1023. b = _SetupScanFileQueue(
  1024. FileQueue,
  1025. Flags,
  1026. Window,
  1027. CallbackRoutine,
  1028. CallbackContext,
  1029. Result,
  1030. TRUE
  1031. );
  1032. } except(EXCEPTION_EXECUTE_HANDLER) {
  1033. b = FALSE;
  1034. SetLastError(ERROR_INVALID_DATA);
  1035. }
  1036. return(b);
  1037. }
  1038. INT
  1039. SetupPromptReboot(
  1040. IN HSPFILEQ FileQueue, OPTIONAL
  1041. IN HWND Owner,
  1042. IN BOOL ScanOnly
  1043. )
  1044. /*++
  1045. Routine Description:
  1046. This routine asks the user whether he wants to reboot the system,
  1047. optionally dependent on whether any files in a committed file queue
  1048. were in use (and are thus now pending operations via MoveFileEx()).
  1049. A reboot is also required if any files were installed as boot files
  1050. (e.g., marked as COPYFLG_REPLACE_BOOT_FILE in the INF).
  1051. If the user answers yes to the prompt, shutdown is initiated
  1052. before this routine returns.
  1053. Arguments:
  1054. FileQueue - if specified, supplies a file queue upon which
  1055. to base the decision about whether shutdown is necessary.
  1056. If not specified, then this routine assumes shutdown is
  1057. necessary and asks the user what to do.
  1058. Owner - supplies window handle for parent window to own windows
  1059. created by this routine.
  1060. ScanOnly - if TRUE, then the user is never asked whether he wants
  1061. to reboot and no shutdown is initiated. In this case FileQueue
  1062. must be specified. If FALSE then this routine functions as
  1063. described above.
  1064. This flags is used when the caller wants to determine whether
  1065. shutdown is necessary separately from actually performing
  1066. the shutdown.
  1067. Return Value:
  1068. A combination of the following flags or -1 if an error occured:
  1069. SPFILEQ_FILE_IN_USE: at least one file was in use and thus there are
  1070. delayed file operations pending. This flag will never be set
  1071. when FileQueue is not specified.
  1072. SPFILEQ_REBOOT_RECOMMENDED: it is recommended that the system
  1073. be rebooted. Depending on other flags and user response to
  1074. the shutdown query, shutdown may already be happening.
  1075. SPFILEQ_REBOOT_IN_PROGRESS: shutdown is in progress.
  1076. --*/
  1077. {
  1078. PSP_FILE_QUEUE Queue;
  1079. PSP_FILE_QUEUE_NODE QueueNode;
  1080. PSOURCE_MEDIA_INFO SourceMedia;
  1081. INT Flags;
  1082. int i;
  1083. DWORD Reason = REASON_PLANNED_FLAG;
  1084. //
  1085. // If only scanning, there must be a FileQueue to scan!
  1086. //
  1087. if(ScanOnly && !FileQueue) {
  1088. SetLastError(ERROR_INVALID_PARAMETER);
  1089. return -1;
  1090. }
  1091. //
  1092. // If we're not just scanning (i.e., we're potentially going to popup UI,
  1093. // then we'd better be interactive.
  1094. //
  1095. if(!ScanOnly && (GlobalSetupFlags & (PSPGF_NONINTERACTIVE|PSPGF_UNATTENDED_SETUP))) {
  1096. SetLastError(ERROR_REQUIRES_INTERACTIVE_WINDOWSTATION);
  1097. return -1;
  1098. }
  1099. Queue = (PSP_FILE_QUEUE)FileQueue;
  1100. Flags = 0;
  1101. //
  1102. // Scan file queue if the caller so desires.
  1103. //
  1104. if(FileQueue) {
  1105. try {
  1106. if(Queue->Flags & FQF_DEVICE_INSTALL) {
  1107. Reason |= REASON_HWINSTALL;
  1108. }
  1109. //
  1110. // Check delete queue for in-use files.
  1111. //
  1112. for(QueueNode=Queue->DeleteQueue; QueueNode; QueueNode=QueueNode->Next) {
  1113. if(QueueNode->InternalFlags & INUSE_INF_WANTS_REBOOT) {
  1114. Flags |= SPFILEQ_REBOOT_RECOMMENDED;
  1115. }
  1116. if(QueueNode->InternalFlags & INUSE_IN_USE) {
  1117. Flags |= SPFILEQ_FILE_IN_USE;
  1118. }
  1119. }
  1120. //
  1121. // Check copy queues for in-use files.
  1122. //
  1123. for(SourceMedia=Queue->SourceMediaList; SourceMedia; SourceMedia=SourceMedia->Next) {
  1124. for(QueueNode=SourceMedia->CopyQueue; QueueNode; QueueNode=QueueNode->Next) {
  1125. if(QueueNode->InternalFlags & INUSE_INF_WANTS_REBOOT) {
  1126. Flags |= SPFILEQ_REBOOT_RECOMMENDED;
  1127. }
  1128. if(QueueNode->InternalFlags & INUSE_IN_USE) {
  1129. Flags |= SPFILEQ_FILE_IN_USE;
  1130. }
  1131. }
  1132. }
  1133. } except(EXCEPTION_EXECUTE_HANDLER) {
  1134. SetLastError(ERROR_INVALID_PARAMETER);
  1135. Flags = -1;
  1136. }
  1137. } else {
  1138. Flags = SPFILEQ_REBOOT_RECOMMENDED;
  1139. }
  1140. //
  1141. // Ask the user if he wants to shut down, if necessary.
  1142. //
  1143. if(!ScanOnly &&
  1144. (Flags & (SPFILEQ_REBOOT_RECOMMENDED | SPFILEQ_FILE_IN_USE)) &&
  1145. (Flags != -1)) {
  1146. if(RestartDialogEx(Owner,NULL,EWX_REBOOT,Reason) == IDYES) {
  1147. Flags |= SPFILEQ_REBOOT_IN_PROGRESS;
  1148. }
  1149. }
  1150. return(Flags);
  1151. }