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.

3681 lines
111 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. sgmqueue.c
  5. Abstract:
  6. Parses the v1 script, builds rules and queues enumeration callbacks.
  7. Author:
  8. Jim Schmidt (jimschm) 12-Mar-2000
  9. Revision History:
  10. <alias> <date> <comments>
  11. --*/
  12. //
  13. // Includes
  14. //
  15. #include "pch.h"
  16. #include "v2app.h"
  17. #include "v1p.h"
  18. #define DBG_SCRIPT "Script"
  19. //
  20. // Strings
  21. //
  22. // None
  23. //
  24. // Constants
  25. //
  26. // none
  27. //
  28. // Macros
  29. //
  30. // None
  31. //
  32. // Types
  33. //
  34. // None
  35. //
  36. // Globals
  37. //
  38. MIG_OPERATIONID g_RenameFileExOp;
  39. MIG_OPERATIONID g_RenameFileOp;
  40. MIG_OPERATIONID g_RenameExOp;
  41. MIG_OPERATIONID g_RenameOp;
  42. MIG_OPERATIONID g_RenameIniExOp;
  43. MIG_OPERATIONID g_RenameIniOp;
  44. BOOL g_VcmMode;
  45. BOOL g_PreParse;
  46. //
  47. // Macro expansion list
  48. //
  49. // None
  50. //
  51. // Private function prototypes
  52. //
  53. VCMPARSE ScriptVcmParse;
  54. VCMQUEUEENUMERATION ScriptVcmQueueEnumeration;
  55. SGMPARSE ScriptSgmParse;
  56. SGMQUEUEENUMERATION ScriptSgmQueueEnumeration;
  57. BOOL
  58. pSelectFilesAndFolders (
  59. VOID
  60. );
  61. BOOL
  62. pParseAllInfs (
  63. IN BOOL PreParse
  64. );
  65. //
  66. // Macro expansion definition
  67. //
  68. // None
  69. //
  70. // Code
  71. //
  72. BOOL
  73. pCommonQueueEnumeration (
  74. IN BOOL PreParse
  75. )
  76. {
  77. MIG_OBJECTSTRINGHANDLE objectHandle;
  78. ACTION_STRUCT actionStruct;
  79. BOOL b = FALSE;
  80. //
  81. // INF-based inclusion/exclusion mechanism. We are called first to pre-parse
  82. // the INF (to allow the UI to alter the results). Then we are called to
  83. // queue the enumeration.
  84. //
  85. if (PreParse) {
  86. g_RenameFileExOp = IsmRegisterOperation (S_OPERATION_V1_FILEMOVEEX, TRUE);
  87. g_RenameFileOp = IsmRegisterOperation (S_OPERATION_V1_FILEMOVE, TRUE);
  88. g_RenameOp = IsmRegisterOperation (S_OPERATION_MOVE, FALSE);
  89. g_RenameIniOp = IsmRegisterOperation (S_OPERATION_INIMOVE, FALSE);
  90. g_DefaultIconOp = IsmRegisterOperation (S_OPERATION_DEFICON_FIXCONTENT, FALSE);
  91. g_DefaultIconData = IsmRegisterProperty (S_V1PROP_ICONDATA, FALSE);
  92. g_FileCollPatternData = IsmRegisterProperty (S_V1PROP_FILECOLLPATTERN, FALSE);
  93. g_RenameExOp = IsmRegisterOperation (S_OPERATION_ENHANCED_MOVE, FALSE);
  94. g_RenameIniExOp = IsmRegisterOperation (S_OPERATION_ENHANCED_INIMOVE, FALSE);
  95. g_RegAutoFilterOp = IsmRegisterOperation (S_OPERATION_REG_AUTO_FILTER, FALSE);
  96. g_IniAutoFilterOp = IsmRegisterOperation (S_OPERATION_INI_AUTO_FILTER, FALSE);
  97. return pParseAllInfs (TRUE);
  98. }
  99. //
  100. // Now queue enumeration
  101. //
  102. MYASSERT (g_RenameFileExOp);
  103. MYASSERT (g_RenameFileOp);
  104. MYASSERT (g_RenameOp);
  105. MYASSERT (g_RenameIniOp);
  106. MYASSERT (g_RegAutoFilterOp);
  107. MYASSERT (g_IniAutoFilterOp);
  108. //
  109. // From the sgm point of view, the v1 tool supports the following:
  110. //
  111. // - Optional transfer of the entire HKCU
  112. // - Optional transfer of the entire HKLM
  113. // - Optional transfer of all files except for OS files
  114. // - INF-based inclusion/exclusion mechanism
  115. // - Specialized migration of certain settings (RAS, printers)
  116. //
  117. // This SGM implements this functionality set.
  118. //
  119. __try {
  120. //
  121. // Component-based inclusion mechanism
  122. //
  123. if (!pSelectFilesAndFolders ()) {
  124. __leave;
  125. }
  126. //
  127. // INF-based inclusion/exclusion mechanism
  128. //
  129. if (!pParseAllInfs (FALSE)) {
  130. __leave;
  131. }
  132. //
  133. // If the /u was specified at the command line we want to suck and apply all HKR
  134. // like if we had a rule in the script: AddReg=HKR\*
  135. //
  136. if (IsmIsEnvironmentFlagSet (IsmGetRealPlatform(), NULL, S_ENV_HKCU_V1)) {
  137. ZeroMemory (&actionStruct, sizeof (ACTION_STRUCT));
  138. objectHandle = TurnRegStringIntoHandle (TEXT("HKCU\\*"), TRUE, NULL);
  139. MYASSERT (objectHandle);
  140. actionStruct.ObjectBase = TurnRegStringIntoHandle (TEXT("HKCU\\*"), FALSE, NULL);
  141. MYASSERT (actionStruct.ObjectBase);
  142. //
  143. // Add this rule
  144. //
  145. if (AddRule (
  146. g_RegType,
  147. actionStruct.ObjectBase,
  148. objectHandle,
  149. ACTIONGROUP_INCLUDE,
  150. ACTION_PERSIST,
  151. &actionStruct
  152. )) {
  153. AddRuleEx (
  154. g_RegType,
  155. actionStruct.ObjectBase,
  156. objectHandle,
  157. ACTIONGROUP_DEFAULTPRIORITY,
  158. ACTION_PRIORITYDEST,
  159. NULL,
  160. RULEGROUP_PRIORITY
  161. );
  162. IsmHookEnumeration (
  163. g_RegType,
  164. objectHandle,
  165. ObjectPriority,
  166. 0,
  167. NULL
  168. );
  169. //
  170. // Queue enumeration for include patterns
  171. //
  172. IsmQueueEnumeration (
  173. g_RegType,
  174. objectHandle,
  175. g_VcmMode ? GatherVirtualComputer : PrepareActions,
  176. 0,
  177. NULL
  178. );
  179. }
  180. IsmDestroyObjectHandle (objectHandle);
  181. }
  182. b = TRUE;
  183. }
  184. __finally {
  185. }
  186. return b;
  187. }
  188. VOID
  189. QueueAllFiles (
  190. IN BOOL VcmMode
  191. )
  192. {
  193. static BOOL done = FALSE;
  194. DRIVE_ENUM driveEnum;
  195. PTSTR fixedDrives = NULL;
  196. DWORD sizeNeeded;
  197. PATH_ENUM pathEnum;
  198. MIG_OBJECTSTRINGHANDLE objectHandle;
  199. MIG_SEGMENTS nodeSeg[2];
  200. if (done) {
  201. return;
  202. }
  203. done = TRUE;
  204. if (VcmMode) {
  205. // Let's get all the fixed drives and put them into an
  206. // environment variable called "FIXED_DRIVES"
  207. if (EnumFirstDrive (&driveEnum, DRIVEENUM_FIXED)) {
  208. do {
  209. if (fixedDrives != NULL) {
  210. fixedDrives = JoinTextEx (NULL, fixedDrives, driveEnum.DriveName, TEXT(";"), 0, NULL);
  211. } else {
  212. fixedDrives = DuplicateText (driveEnum.DriveName);
  213. }
  214. } while (EnumNextDrive (&driveEnum));
  215. }
  216. MYASSERT (fixedDrives);
  217. if (fixedDrives) {
  218. IsmSetEnvironmentString (PLATFORM_SOURCE, NULL, S_FIXED_DRIVES, fixedDrives);
  219. }
  220. } else {
  221. // Let's get the fixed drives from the source machine
  222. if (IsmGetEnvironmentString (
  223. PLATFORM_SOURCE,
  224. NULL,
  225. S_FIXED_DRIVES,
  226. NULL,
  227. 0,
  228. &sizeNeeded
  229. )) {
  230. fixedDrives = AllocText (sizeNeeded);
  231. if (fixedDrives) {
  232. IsmGetEnvironmentString (
  233. PLATFORM_SOURCE,
  234. NULL,
  235. S_FIXED_DRIVES,
  236. fixedDrives,
  237. sizeNeeded,
  238. NULL
  239. );
  240. }
  241. }
  242. }
  243. if (fixedDrives) {
  244. // now enumerate the fixed drives and add queue an
  245. // enumeration for each of them.
  246. if (EnumFirstPathEx (&pathEnum, fixedDrives, NULL, NULL, FALSE)) {
  247. do {
  248. nodeSeg[0].Segment = JoinPaths (pathEnum.PtrCurrPath, TEXT("*"));
  249. nodeSeg[0].IsPattern = TRUE ;
  250. objectHandle = IsmCreateObjectPattern (nodeSeg, 1, ALL_PATTERN, 0);
  251. IsmQueueEnumeration (g_FileType, objectHandle, NulCallback, 0, NULL);
  252. IsmDestroyObjectHandle (objectHandle);
  253. FreePathString (nodeSeg[0].Segment);
  254. } while (EnumNextPath (&pathEnum));
  255. }
  256. AbortPathEnum (&pathEnum);
  257. }
  258. }
  259. VOID
  260. pQueueAllReg (
  261. VOID
  262. )
  263. {
  264. static BOOL done = FALSE;
  265. MIG_OBJECTSTRINGHANDLE objectHandle;
  266. MIG_SEGMENTS nodeSeg[2];
  267. MIG_PLATFORMTYPEID platform = IsmGetRealPlatform();
  268. if (done) {
  269. return;
  270. }
  271. done = TRUE;
  272. //
  273. // Optional transfer of entire HKCU
  274. //
  275. if (IsmIsEnvironmentFlagSet (platform, NULL, S_ENV_HKCU_ON)) {
  276. nodeSeg[0].Segment = TEXT("HKCU\\");
  277. nodeSeg[0].IsPattern = FALSE;
  278. nodeSeg[1].Segment = TEXT("*");
  279. nodeSeg[1].IsPattern = TRUE;
  280. objectHandle = IsmCreateObjectPattern (nodeSeg, 2, ALL_PATTERN, 0);
  281. IsmQueueEnumeration (g_RegType, objectHandle, NulCallback, 0, NULL);
  282. IsmDestroyObjectHandle (objectHandle);
  283. }
  284. //
  285. // Optional transfer of entire HKLM
  286. //
  287. if (IsmIsEnvironmentFlagSet (platform, NULL, S_ENV_HKLM_ON)) {
  288. nodeSeg[0].Segment = TEXT("HKLM\\");
  289. nodeSeg[0].IsPattern = FALSE;
  290. nodeSeg[1].Segment = TEXT("*");
  291. nodeSeg[1].IsPattern = TRUE;
  292. objectHandle = IsmCreateObjectPattern (nodeSeg, 2, ALL_PATTERN, 0);
  293. IsmQueueEnumeration (g_RegType, objectHandle, NulCallback, 0, NULL);
  294. IsmDestroyObjectHandle (objectHandle);
  295. }
  296. }
  297. BOOL
  298. WINAPI
  299. ScriptSgmParse (
  300. IN PVOID Reserved
  301. )
  302. {
  303. return pCommonQueueEnumeration (TRUE);
  304. }
  305. BOOL
  306. WINAPI
  307. ScriptSgmQueueEnumeration (
  308. IN PVOID Reserved
  309. )
  310. {
  311. BOOL result;
  312. result = pCommonQueueEnumeration (FALSE);
  313. OEAddComplexRules();
  314. return result;
  315. }
  316. BOOL
  317. WINAPI
  318. ScriptVcmParse (
  319. IN PVOID Reserved
  320. )
  321. {
  322. g_VcmMode = TRUE;
  323. return pCommonQueueEnumeration (TRUE);
  324. }
  325. BOOL
  326. WINAPI
  327. ScriptVcmQueueEnumeration (
  328. IN PVOID Reserved
  329. )
  330. {
  331. g_VcmMode = TRUE;
  332. return pCommonQueueEnumeration (FALSE);
  333. }
  334. PCTSTR
  335. pFixDestination (
  336. IN PCTSTR Source,
  337. IN PCTSTR Destination
  338. )
  339. {
  340. PTSTR result = (PTSTR)Source;
  341. PTSTR tempPtr;
  342. PTSTR sKey;
  343. PTSTR sSubKey;
  344. PTSTR sValueName;
  345. PTSTR dKey;
  346. PTSTR dSubKey;
  347. PTSTR dValueName;
  348. UINT size;
  349. BOOL sTree = FALSE;
  350. sKey = DuplicatePathString (Source, 0);
  351. sValueName = _tcschr (sKey, TEXT('['));
  352. if (sValueName) {
  353. tempPtr = _tcschr (sValueName, TEXT(']'));
  354. if (tempPtr) {
  355. *tempPtr = 0;
  356. }
  357. tempPtr = sValueName;
  358. sValueName = _tcsinc (sValueName);
  359. *tempPtr = 0;
  360. tempPtr = _tcsdec2 (sKey, tempPtr);
  361. if (tempPtr) {
  362. if (_tcsnextc (tempPtr) == TEXT('\\')) {
  363. *tempPtr = 0;
  364. }
  365. if (_tcsnextc (tempPtr) == TEXT(' ')) {
  366. *tempPtr = 0;
  367. }
  368. }
  369. }
  370. sSubKey = _tcsrchr (sKey, TEXT('\\'));
  371. if (sSubKey) {
  372. tempPtr = _tcsinc (sSubKey);
  373. if (_tcsnextc (tempPtr) == TEXT('*')) {
  374. *sSubKey = 0;
  375. sTree = TRUE;
  376. }
  377. }
  378. sSubKey = _tcsrchr (sKey, TEXT('\\'));
  379. if (sSubKey) {
  380. tempPtr = sSubKey;
  381. sSubKey = _tcsinc (sSubKey);
  382. *tempPtr = 0;
  383. }
  384. dKey = DuplicatePathString (Destination, 0);
  385. dValueName = _tcschr (dKey, TEXT('['));
  386. if (dValueName) {
  387. tempPtr = _tcschr (dValueName, TEXT(']'));
  388. if (tempPtr) {
  389. *tempPtr = 0;
  390. }
  391. tempPtr = dValueName;
  392. dValueName = _tcsinc (dValueName);
  393. *tempPtr = 0;
  394. tempPtr = _tcsdec2 (dKey, tempPtr);
  395. if (tempPtr) {
  396. if (_tcsnextc (tempPtr) == TEXT('\\')) {
  397. *tempPtr = 0;
  398. }
  399. if (_tcsnextc (tempPtr) == TEXT(' ')) {
  400. *tempPtr = 0;
  401. }
  402. }
  403. }
  404. dSubKey = _tcsrchr (dKey, TEXT('\\'));
  405. if (dSubKey) {
  406. tempPtr = _tcsinc (dSubKey);
  407. if (_tcsnextc (tempPtr) == TEXT('*')) {
  408. *dSubKey = 0;
  409. }
  410. }
  411. dSubKey = _tcsrchr (dKey, TEXT('\\'));
  412. if (dSubKey) {
  413. tempPtr = dSubKey;
  414. dSubKey = _tcsinc (dSubKey);
  415. *tempPtr = 0;
  416. }
  417. if (!dSubKey) {
  418. dSubKey = dKey;
  419. dKey = NULL;
  420. }
  421. size = 0;
  422. if (dKey && *dKey) {
  423. size += TcharCount (dKey) + 1;
  424. } else if (sKey && *sKey) {
  425. size += TcharCount (sKey) + 1;
  426. }
  427. if (dSubKey && *dSubKey) {
  428. size += TcharCount (dSubKey) + 1;
  429. } else if (sSubKey && *sSubKey) {
  430. size += TcharCount (sSubKey) + 1;
  431. }
  432. if (dValueName && *dValueName) {
  433. size += TcharCount (dValueName) + ARRAYSIZE(TEXT(" []")) - 1;
  434. } else if (sValueName && *sValueName) {
  435. size += TcharCount (sValueName) + ARRAYSIZE(TEXT(" []")) - 1;
  436. }
  437. if (sTree) {
  438. size += ARRAYSIZE(TEXT("\\*")) - 1;
  439. }
  440. size += 1;
  441. result = AllocPathString (size);
  442. *result = 0;
  443. if (dKey && *dKey) {
  444. StringCat (result, dKey);
  445. } else if (sKey && *sKey) {
  446. StringCat (result, sKey);
  447. }
  448. if (dSubKey && *dSubKey) {
  449. StringCat (result, TEXT("\\"));
  450. StringCat (result, dSubKey);
  451. } else if (sSubKey && *sSubKey) {
  452. StringCat (result, TEXT("\\"));
  453. StringCat (result, sSubKey);
  454. }
  455. if (sTree) {
  456. StringCat (result, TEXT("\\*"));
  457. }
  458. if (dValueName && *dValueName) {
  459. StringCat (result, TEXT(" ["));
  460. StringCat (result, dValueName);
  461. StringCat (result, TEXT("]"));
  462. } else if (sValueName && *sValueName) {
  463. StringCat (result, TEXT(" ["));
  464. StringCat (result, sValueName);
  465. StringCat (result, TEXT("]"));
  466. }
  467. if (sKey) {
  468. FreePathString (sKey);
  469. }
  470. if (dKey) {
  471. FreePathString (dKey);
  472. } else if (dSubKey) {
  473. FreePathString (dSubKey);
  474. }
  475. return result;
  476. }
  477. BOOL
  478. pParseRegEx (
  479. IN HINF Inf,
  480. IN PCTSTR Section,
  481. IN ACTIONGROUP ActionGroup,
  482. IN DWORD ActionFlags,
  483. IN PCTSTR Application OPTIONAL
  484. )
  485. {
  486. INFSTRUCT is = INITINFSTRUCT_PMHANDLE;
  487. PCTSTR srcNode;
  488. PCTSTR srcLeaf;
  489. MIG_OBJECTSTRINGHANDLE srcHandle = NULL;
  490. PCTSTR destNode;
  491. PCTSTR destLeaf;
  492. PCTSTR filesDest;
  493. PCTSTR newDest = NULL;
  494. ACTION_STRUCT actionStruct;
  495. BOOL result = FALSE;
  496. if (InfFindFirstLine (Inf, Section, NULL, &is)) {
  497. do {
  498. if (IsmCheckCancel()) {
  499. break;
  500. }
  501. __try {
  502. ZeroMemory (&actionStruct, sizeof (ACTION_STRUCT));
  503. srcNode = InfGetStringField (&is, 1);
  504. srcLeaf = InfGetStringField (&is, 2);
  505. if (!srcNode && !srcLeaf) {
  506. LOG ((LOG_ERROR, (PCSTR) MSG_EMPTY_RENREGEX));
  507. __leave;
  508. }
  509. // Validate rule
  510. if (!StringIMatchTcharCount (srcNode, S_HKLM, ARRAYSIZE(S_HKLM) - 1) &&
  511. !StringIMatchTcharCount (srcNode, S_HKR, ARRAYSIZE(S_HKR) - 1) &&
  512. !StringIMatchTcharCount (srcNode, S_HKCC, ARRAYSIZE(S_HKCC) - 1)
  513. ) {
  514. LOG ((LOG_ERROR, (PCSTR) MSG_INVALID_REGROOT, srcNode));
  515. __leave;
  516. }
  517. srcHandle = CreatePatternFromNodeLeaf (srcNode, srcLeaf);
  518. if (!srcHandle) {
  519. LOG ((LOG_ERROR, (PCSTR) MSG_REG_SPEC_BAD, srcNode));
  520. __leave;
  521. }
  522. actionStruct.ObjectBase = MakeRegExBase (srcNode, srcLeaf);
  523. if (!actionStruct.ObjectBase) {
  524. LOG ((LOG_ERROR, (PCSTR) MSG_REG_SPEC_BAD, srcNode));
  525. __leave;
  526. }
  527. if (ActionGroup == ACTIONGROUP_RENAMEEX) {
  528. destNode = InfGetStringField (&is, 3);
  529. destLeaf = InfGetStringField (&is, 4);
  530. if (!destNode && !destLeaf) {
  531. LOG ((LOG_ERROR, (PCSTR) MSG_REG_SPEC_MISSING_DEST, srcNode));
  532. __leave;
  533. }
  534. actionStruct.ObjectDest = CreatePatternFromNodeLeaf (destNode, destLeaf);
  535. if (!actionStruct.ObjectDest) {
  536. LOG ((LOG_ERROR, (PCSTR) MSG_REG_SPEC_BAD_DEST, destNode));
  537. __leave;
  538. }
  539. }
  540. if (ActionGroup == ACTIONGROUP_INCFILEEX ||
  541. ActionGroup == ACTIONGROUP_INCFOLDEREX ||
  542. ActionGroup == ACTIONGROUP_INCICONEX
  543. ) {
  544. destNode = InfGetStringField (&is, 3);
  545. destLeaf = InfGetStringField (&is, 4);
  546. if (destNode && destLeaf &&
  547. *destNode && *destLeaf) {
  548. actionStruct.ObjectDest = CreatePatternFromNodeLeaf (destNode, destLeaf);
  549. if (!actionStruct.ObjectDest) {
  550. LOG ((LOG_ERROR, (PCSTR) MSG_REG_SPEC_BAD_DEST, destNode));
  551. __leave;
  552. }
  553. }
  554. }
  555. if ((ActionGroup == ACTIONGROUP_INCFILEEX ||
  556. ActionGroup == ACTIONGROUP_INCFOLDEREX ||
  557. ActionGroup == ACTIONGROUP_INCICONEX
  558. ) &&
  559. ((ActionFlags & ACTION_PERSIST_PATH_IN_DATA) ||
  560. (ActionFlags & ACTION_PERSIST_ICON_IN_DATA)
  561. )
  562. ) {
  563. filesDest = InfGetStringField (&is, 5);
  564. if (filesDest && *filesDest) {
  565. newDest = SanitizePath (filesDest);
  566. if (newDest) {
  567. actionStruct.AddnlDest = TurnFileStringIntoHandle (
  568. newDest,
  569. PFF_COMPUTE_BASE|
  570. PFF_NO_SUBDIR_PATTERN|
  571. PFF_NO_PATTERNS_ALLOWED|
  572. PFF_NO_LEAF_AT_ALL
  573. );
  574. FreePathString (newDest);
  575. newDest = NULL;
  576. }
  577. if (!actionStruct.AddnlDest) {
  578. LOG ((LOG_ERROR, (PCSTR) MSG_FILE_SPEC_BAD_DEST, filesDest));
  579. }
  580. }
  581. actionStruct.ObjectHint = InfGetStringField (&is, 6);
  582. if (actionStruct.ObjectHint && !(*actionStruct.ObjectHint)) {
  583. actionStruct.ObjectHint = NULL;
  584. }
  585. }
  586. //
  587. // Add this rule
  588. //
  589. if (!AddRule (
  590. g_RegType,
  591. actionStruct.ObjectBase,
  592. srcHandle,
  593. ActionGroup,
  594. ActionFlags,
  595. &actionStruct
  596. )) {
  597. DEBUGMSG ((DBG_ERROR, "Error processing registry rules for %s", srcNode));
  598. }
  599. AddRuleEx (
  600. g_RegType,
  601. actionStruct.ObjectBase,
  602. srcHandle,
  603. ACTIONGROUP_DEFAULTPRIORITY,
  604. ACTION_PRIORITYSRC,
  605. NULL,
  606. RULEGROUP_PRIORITY
  607. );
  608. IsmHookEnumeration (
  609. g_RegType,
  610. srcHandle,
  611. ObjectPriority,
  612. 0,
  613. NULL
  614. );
  615. //
  616. // Queue enumeration for include patterns
  617. //
  618. if ((ActionGroup == ACTIONGROUP_INCLUDEEX) ||
  619. (ActionGroup == ACTIONGROUP_RENAMEEX) ||
  620. (ActionGroup == ACTIONGROUP_INCFILEEX) ||
  621. (ActionGroup == ACTIONGROUP_INCFOLDEREX) ||
  622. (ActionGroup == ACTIONGROUP_INCICONEX)
  623. ) {
  624. if (IsmIsObjectHandleLeafOnly (srcHandle)) {
  625. pQueueAllReg();
  626. IsmHookEnumeration (
  627. g_RegType,
  628. srcHandle,
  629. g_VcmMode ? GatherVirtualComputer : PrepareActions,
  630. 0,
  631. NULL
  632. );
  633. } else {
  634. IsmQueueEnumeration (
  635. g_RegType,
  636. srcHandle,
  637. g_VcmMode ? GatherVirtualComputer : PrepareActions,
  638. 0,
  639. NULL
  640. );
  641. }
  642. }
  643. if (ActionGroup == ACTIONGROUP_DELREGKEY) {
  644. IsmHookEnumeration (g_RegType, srcHandle, ExcludeKeyIfValueExists, 0, NULL);
  645. IsmRegisterTypePostEnumerationCallback (g_RegType, PostDelregKeyCallback, NULL);
  646. }
  647. }
  648. __finally {
  649. IsmDestroyObjectHandle (srcHandle);
  650. srcHandle = NULL;
  651. IsmDestroyObjectHandle (actionStruct.ObjectBase);
  652. actionStruct.ObjectBase = NULL;
  653. IsmDestroyObjectHandle (actionStruct.ObjectDest);
  654. actionStruct.ObjectDest = NULL;
  655. IsmDestroyObjectHandle (actionStruct.AddnlDest);
  656. actionStruct.AddnlDest = NULL;
  657. }
  658. } while (InfFindNextLine (&is));
  659. result = !IsmCheckCancel();
  660. } else {
  661. LOG ((LOG_ERROR, (PCSTR) MSG_EMPTY_OR_MISSING_SECTION, Section));
  662. }
  663. InfCleanUpInfStruct (&is);
  664. return result;
  665. }
  666. BOOL
  667. pParseReg (
  668. IN HINF Inf,
  669. IN PCTSTR Section,
  670. IN ACTIONGROUP ActionGroup,
  671. IN DWORD ActionFlags,
  672. IN BOOL FixDestination,
  673. IN PCTSTR Application OPTIONAL
  674. )
  675. {
  676. INFSTRUCT is = INITINFSTRUCT_PMHANDLE;
  677. PCTSTR pattern;
  678. MIG_OBJECTSTRINGHANDLE srcHandle = NULL;
  679. PCTSTR destination;
  680. PCTSTR newDestination;
  681. PCTSTR filesDest;
  682. PCTSTR newDest = NULL;
  683. ACTION_STRUCT actionStruct;
  684. BOOL hadLeaf = FALSE;
  685. BOOL result = FALSE;
  686. if (InfFindFirstLine (Inf, Section, NULL, &is)) {
  687. do {
  688. if (IsmCheckCancel()) {
  689. break;
  690. }
  691. __try {
  692. ZeroMemory (&actionStruct, sizeof (ACTION_STRUCT));
  693. srcHandle = NULL;
  694. pattern = InfGetStringField (&is, 0);
  695. if (!pattern) {
  696. pattern = InfGetStringField (&is, 1);
  697. if (!pattern) {
  698. LOG ((LOG_WARNING, (PCSTR) MSG_EMPTY_RENREG));
  699. __leave;
  700. }
  701. }
  702. // Validate rule
  703. if (!StringIMatchTcharCount (pattern, S_HKLM, ARRAYSIZE(S_HKLM) - 1) &&
  704. !StringIMatchTcharCount (pattern, S_HKR, ARRAYSIZE(S_HKR) - 1) &&
  705. !StringIMatchTcharCount (pattern, S_HKCC, ARRAYSIZE(S_HKCC) - 1)
  706. ) {
  707. LOG ((LOG_ERROR, (PCSTR) MSG_INVALID_REGROOT, pattern));
  708. __leave;
  709. }
  710. srcHandle = TurnRegStringIntoHandle (pattern, TRUE, &hadLeaf);
  711. if (!srcHandle) {
  712. LOG ((LOG_ERROR, (PCSTR) MSG_REG_SPEC_BAD, pattern));
  713. __leave;
  714. }
  715. actionStruct.ObjectBase = TurnRegStringIntoHandle (pattern, FALSE, NULL);
  716. if (!actionStruct.ObjectBase) {
  717. LOG ((LOG_ERROR, (PCSTR) MSG_REG_SPEC_BAD, pattern));
  718. __leave;
  719. }
  720. if (ActionGroup == ACTIONGROUP_RENAME) {
  721. destination = InfGetStringField (&is, 1);
  722. if (destination && *destination) {
  723. if (FixDestination) {
  724. newDestination = pFixDestination (pattern, destination);
  725. } else {
  726. newDestination = destination;
  727. }
  728. actionStruct.ObjectDest = TurnRegStringIntoHandle (newDestination, FALSE, NULL);
  729. if (newDestination != destination) {
  730. FreePathString (newDestination);
  731. }
  732. if (!actionStruct.ObjectDest) {
  733. LOG ((LOG_ERROR, (PCSTR) MSG_REG_SPEC_BAD_DEST, destination));
  734. __leave;
  735. }
  736. } else {
  737. LOG ((LOG_ERROR, (PCSTR) MSG_REG_SPEC_MISSING_DEST, pattern));
  738. __leave;
  739. }
  740. }
  741. if (ActionGroup == ACTIONGROUP_INCFILE ||
  742. ActionGroup == ACTIONGROUP_INCFOLDER ||
  743. ActionGroup == ACTIONGROUP_INCICON
  744. ) {
  745. destination = InfGetStringField (&is, 1);
  746. if (destination && *destination) {
  747. if (FixDestination) {
  748. newDestination = pFixDestination (pattern, destination);
  749. } else {
  750. newDestination = destination;
  751. }
  752. actionStruct.ObjectDest = TurnRegStringIntoHandle (newDestination, FALSE, NULL);
  753. if (newDestination != destination) {
  754. FreePathString (newDestination);
  755. }
  756. if (!actionStruct.ObjectDest) {
  757. LOG ((LOG_ERROR, (PCSTR) MSG_REG_SPEC_BAD_DEST, destination));
  758. __leave;
  759. }
  760. }
  761. }
  762. if ((ActionGroup == ACTIONGROUP_INCFILE ||
  763. ActionGroup == ACTIONGROUP_INCFOLDER ||
  764. ActionGroup == ACTIONGROUP_INCICON
  765. ) &&
  766. ((ActionFlags & ACTION_PERSIST_PATH_IN_DATA) ||
  767. (ActionFlags & ACTION_PERSIST_ICON_IN_DATA)
  768. )
  769. ) {
  770. filesDest = InfGetStringField (&is, 2);
  771. if (filesDest && *filesDest) {
  772. newDest = SanitizePath (filesDest);
  773. if (newDest) {
  774. actionStruct.AddnlDest = TurnFileStringIntoHandle (
  775. newDest,
  776. PFF_COMPUTE_BASE|
  777. PFF_NO_SUBDIR_PATTERN|
  778. PFF_NO_PATTERNS_ALLOWED|
  779. PFF_NO_LEAF_AT_ALL
  780. );
  781. FreePathString (newDest);
  782. newDest = NULL;
  783. }
  784. if (!actionStruct.AddnlDest) {
  785. LOG ((LOG_ERROR, (PCSTR) MSG_FILE_SPEC_BAD_DEST, filesDest));
  786. }
  787. }
  788. actionStruct.ObjectHint = InfGetStringField (&is, 3);
  789. if (actionStruct.ObjectHint && !(*actionStruct.ObjectHint)) {
  790. actionStruct.ObjectHint = NULL;
  791. }
  792. }
  793. //
  794. // Add this rule
  795. //
  796. if (!AddRule (
  797. g_RegType,
  798. actionStruct.ObjectBase,
  799. srcHandle,
  800. ActionGroup,
  801. ActionFlags,
  802. &actionStruct
  803. )) {
  804. DEBUGMSG ((DBG_ERROR, "Error processing registry rules for %s", pattern));
  805. }
  806. AddRuleEx (
  807. g_RegType,
  808. actionStruct.ObjectBase,
  809. srcHandle,
  810. ACTIONGROUP_DEFAULTPRIORITY,
  811. ACTION_PRIORITYSRC,
  812. NULL,
  813. RULEGROUP_PRIORITY
  814. );
  815. IsmHookEnumeration (
  816. g_RegType,
  817. srcHandle,
  818. ObjectPriority,
  819. 0,
  820. NULL
  821. );
  822. //
  823. // Queue enumeration for include patterns
  824. //
  825. if ((ActionGroup == ACTIONGROUP_INCLUDE) ||
  826. (ActionGroup == ACTIONGROUP_RENAME) ||
  827. (ActionGroup == ACTIONGROUP_INCFILE) ||
  828. (ActionGroup == ACTIONGROUP_INCFOLDER) ||
  829. (ActionGroup == ACTIONGROUP_INCICON)
  830. ) {
  831. if (IsmIsObjectHandleLeafOnly (srcHandle)) {
  832. pQueueAllReg();
  833. IsmHookEnumeration (
  834. g_RegType,
  835. srcHandle,
  836. g_VcmMode ? GatherVirtualComputer : PrepareActions,
  837. 0,
  838. NULL
  839. );
  840. } else {
  841. if ((!hadLeaf) && actionStruct.ObjectBase) {
  842. IsmQueueEnumeration (
  843. g_RegType,
  844. actionStruct.ObjectBase,
  845. g_VcmMode ? GatherVirtualComputer : PrepareActions,
  846. 0,
  847. NULL
  848. );
  849. }
  850. IsmQueueEnumeration (
  851. g_RegType,
  852. srcHandle,
  853. g_VcmMode ? GatherVirtualComputer : PrepareActions,
  854. 0,
  855. NULL
  856. );
  857. }
  858. }
  859. if (ActionGroup == ACTIONGROUP_DELREGKEY) {
  860. IsmHookEnumeration (g_RegType, srcHandle, ExcludeKeyIfValueExists, 0, NULL);
  861. IsmRegisterTypePostEnumerationCallback (g_RegType, PostDelregKeyCallback, NULL);
  862. }
  863. }
  864. __finally {
  865. IsmDestroyObjectHandle (srcHandle);
  866. srcHandle = NULL;
  867. IsmDestroyObjectHandle (actionStruct.ObjectBase);
  868. actionStruct.ObjectBase = NULL;
  869. IsmDestroyObjectHandle (actionStruct.ObjectDest);
  870. actionStruct.ObjectDest = NULL;
  871. IsmDestroyObjectHandle (actionStruct.AddnlDest);
  872. actionStruct.AddnlDest = NULL;
  873. }
  874. } while (InfFindNextLine (&is));
  875. result = !IsmCheckCancel();
  876. } else {
  877. LOG ((LOG_ERROR, (PCSTR) MSG_EMPTY_OR_MISSING_SECTION, Section));
  878. }
  879. InfCleanUpInfStruct (&is);
  880. return result;
  881. }
  882. BOOL
  883. pParseIni (
  884. IN HINF Inf,
  885. IN PCTSTR Section,
  886. IN ACTIONGROUP ActionGroup,
  887. IN DWORD ActionFlags,
  888. IN PCTSTR Application OPTIONAL
  889. )
  890. {
  891. INFSTRUCT is = INITINFSTRUCT_PMHANDLE;
  892. PCTSTR iniFile = NULL;
  893. TCHAR buffer [MAX_TCHAR_PATH * 2];
  894. PCTSTR newIniFile = NULL;
  895. BOOL expandResult = TRUE;
  896. PCTSTR sectPattern = NULL;
  897. PCTSTR keyPattern = NULL;
  898. PCTSTR destIniFile = NULL;
  899. PCTSTR newDestIniFile = NULL;
  900. PCTSTR destSect = NULL;
  901. PCTSTR destKey = NULL;
  902. PCTSTR filesDest = NULL;
  903. PCTSTR newFilesDest = NULL;
  904. MIG_OBJECTSTRINGHANDLE srcHandle = NULL;
  905. MIG_OBJECTSTRINGHANDLE srcHandle1 = NULL;
  906. ACTION_STRUCT actionStruct;
  907. BOOL result = FALSE;
  908. if (InfFindFirstLine (Inf, Section, NULL, &is)) {
  909. do {
  910. if (IsmCheckCancel()) {
  911. break;
  912. }
  913. __try {
  914. ZeroMemory (&actionStruct, sizeof (ACTION_STRUCT));
  915. srcHandle = NULL;
  916. iniFile = InfGetStringField (&is, 1);
  917. if (!iniFile) {
  918. continue;
  919. }
  920. //
  921. // Expand environment variables in ini file specification
  922. //
  923. expandResult = AppSearchAndReplace (
  924. PLATFORM_SOURCE,
  925. Application,
  926. iniFile,
  927. buffer,
  928. ARRAYSIZE(buffer)
  929. );
  930. if (!expandResult) {
  931. // the line contains at least one unexpandable env. variables
  932. expandResult = AppCheckAndLogUndefVariables (
  933. PLATFORM_SOURCE,
  934. Application,
  935. iniFile
  936. );
  937. if (expandResult) {
  938. // the line contains known but undefined env. variables
  939. continue;
  940. }
  941. }
  942. //
  943. // Fix the ini file specification
  944. //
  945. newIniFile = SanitizePath (buffer);
  946. if(!newIniFile) {
  947. continue;
  948. }
  949. // require full spec for the INI file
  950. if (!IsValidFileSpec (newIniFile)) {
  951. if (expandResult) {
  952. LOG ((LOG_ERROR, (PCSTR) MSG_FILE_SPEC_BAD, iniFile));
  953. }
  954. FreePathString (newIniFile);
  955. newIniFile = NULL;
  956. continue;
  957. }
  958. // let's get the section pattern. If nothing is specified we assume all
  959. sectPattern = InfGetStringField (&is, 2);
  960. if ((!sectPattern) || IsEmptyStr (sectPattern)) {
  961. sectPattern = PmDuplicateString (is.PoolHandle, TEXT("*"));
  962. }
  963. // let's get the key pattern. If nothing is specified we assume all
  964. keyPattern = InfGetStringField (&is, 3);
  965. if (!keyPattern || IsEmptyStr (keyPattern)) {
  966. keyPattern = PmDuplicateString (is.PoolHandle, TEXT("*"));
  967. }
  968. // let's build the object handle
  969. srcHandle = TurnIniSpecIntoHandle (
  970. newIniFile,
  971. sectPattern,
  972. keyPattern,
  973. TRUE,
  974. TRUE
  975. );
  976. // let's build the object handle (ignore node pattern if exists)
  977. srcHandle1 = TurnIniSpecIntoHandle (
  978. newIniFile,
  979. sectPattern,
  980. keyPattern,
  981. FALSE,
  982. TRUE
  983. );
  984. // now let's build the object base
  985. actionStruct.ObjectBase = TurnIniSpecIntoHandle (
  986. newIniFile,
  987. sectPattern,
  988. keyPattern,
  989. FALSE,
  990. FALSE
  991. );
  992. FreePathString (newIniFile);
  993. newIniFile = NULL;
  994. if (ActionGroup == ACTIONGROUP_RENAME ||
  995. ActionGroup == ACTIONGROUP_INCFILE ||
  996. ActionGroup == ACTIONGROUP_INCFOLDER ||
  997. ActionGroup == ACTIONGROUP_INCICON
  998. ) {
  999. destIniFile = InfGetStringField (&is, 4);
  1000. if (destIniFile && (destIniFile [0] == 0)) {
  1001. // dest is unspecified
  1002. destIniFile = NULL;
  1003. }
  1004. if (destIniFile) {
  1005. newDestIniFile = SanitizePath (destIniFile);
  1006. } else {
  1007. newDestIniFile = NULL;
  1008. }
  1009. destSect = InfGetStringField (&is, 5);
  1010. destKey = InfGetStringField (&is, 6);
  1011. actionStruct.ObjectDest = TurnIniSpecIntoHandle (
  1012. newDestIniFile,
  1013. destSect,
  1014. destKey,
  1015. FALSE,
  1016. FALSE
  1017. );
  1018. if (newDestIniFile) {
  1019. FreePathString (newDestIniFile);
  1020. newDestIniFile = NULL;
  1021. }
  1022. }
  1023. if ((ActionGroup == ACTIONGROUP_INCFILE ||
  1024. ActionGroup == ACTIONGROUP_INCFOLDER ||
  1025. ActionGroup == ACTIONGROUP_INCICON
  1026. ) &&
  1027. ((ActionFlags & ACTION_PERSIST_PATH_IN_DATA) ||
  1028. (ActionFlags & ACTION_PERSIST_ICON_IN_DATA)
  1029. )
  1030. ) {
  1031. filesDest = InfGetStringField (&is, 7);
  1032. if (filesDest && *filesDest) {
  1033. newFilesDest = SanitizePath (filesDest);
  1034. if (newFilesDest) {
  1035. actionStruct.AddnlDest = TurnFileStringIntoHandle (
  1036. newFilesDest,
  1037. PFF_COMPUTE_BASE|
  1038. PFF_NO_SUBDIR_PATTERN|
  1039. PFF_NO_PATTERNS_ALLOWED|
  1040. PFF_NO_LEAF_AT_ALL
  1041. );
  1042. FreePathString (newFilesDest);
  1043. newFilesDest = NULL;
  1044. }
  1045. if (!actionStruct.AddnlDest) {
  1046. LOG ((LOG_ERROR, (PCSTR) MSG_FILE_SPEC_BAD_DEST, filesDest));
  1047. }
  1048. }
  1049. actionStruct.ObjectHint = InfGetStringField (&is, 8);
  1050. if (actionStruct.ObjectHint && !(*actionStruct.ObjectHint)) {
  1051. actionStruct.ObjectHint = NULL;
  1052. }
  1053. }
  1054. //
  1055. // Add this rule
  1056. //
  1057. if (!AddRule (
  1058. g_IniType,
  1059. actionStruct.ObjectBase,
  1060. srcHandle,
  1061. ActionGroup,
  1062. ActionFlags,
  1063. &actionStruct
  1064. )) {
  1065. DEBUGMSG ((DBG_ERROR, "Error processing INI files rules for %s", iniFile));
  1066. }
  1067. //
  1068. // Queue enumeration for include patterns
  1069. //
  1070. if ((ActionGroup == ACTIONGROUP_INCLUDE) ||
  1071. (ActionGroup == ACTIONGROUP_RENAME) ||
  1072. (ActionGroup == ACTIONGROUP_INCFILE) ||
  1073. (ActionGroup == ACTIONGROUP_INCFOLDER) ||
  1074. (ActionGroup == ACTIONGROUP_INCICON)
  1075. ) {
  1076. if (!StringIMatch (srcHandle, srcHandle1)) {
  1077. IsmQueueEnumeration (
  1078. g_IniType,
  1079. srcHandle1,
  1080. g_VcmMode ? GatherVirtualComputer : PrepareActions,
  1081. 0,
  1082. NULL
  1083. );
  1084. }
  1085. IsmQueueEnumeration (
  1086. g_IniType,
  1087. srcHandle,
  1088. g_VcmMode ? GatherVirtualComputer : PrepareActions,
  1089. 0,
  1090. NULL
  1091. );
  1092. }
  1093. }
  1094. __finally {
  1095. IsmDestroyObjectHandle (srcHandle);
  1096. srcHandle = NULL;
  1097. IsmDestroyObjectHandle (srcHandle1);
  1098. srcHandle1 = NULL;
  1099. IsmDestroyObjectHandle (actionStruct.ObjectBase);
  1100. actionStruct.ObjectBase = NULL;
  1101. IsmDestroyObjectHandle (actionStruct.ObjectDest);
  1102. actionStruct.ObjectDest = NULL;
  1103. IsmDestroyObjectHandle (actionStruct.AddnlDest);
  1104. actionStruct.AddnlDest = NULL;
  1105. }
  1106. } while (InfFindNextLine (&is));
  1107. result = !IsmCheckCancel();
  1108. } else {
  1109. LOG ((LOG_ERROR, (PCSTR) MSG_EMPTY_OR_MISSING_SECTION, Section));
  1110. }
  1111. InfCleanUpInfStruct (&is);
  1112. return result;
  1113. }
  1114. BOOL
  1115. pParseCertificates (
  1116. IN HINF Inf,
  1117. IN PCTSTR Section,
  1118. IN ACTIONGROUP ActionGroup,
  1119. IN DWORD ActionFlags,
  1120. IN PCTSTR Application OPTIONAL
  1121. )
  1122. {
  1123. INFSTRUCT is = INITINFSTRUCT_PMHANDLE;
  1124. PCTSTR certStore;
  1125. TCHAR buffer [MAX_TCHAR_PATH * 2];
  1126. PCTSTR newCertStore = NULL;
  1127. BOOL expandResult = TRUE;
  1128. PCTSTR certPattern;
  1129. MIG_OBJECTSTRINGHANDLE srcHandle = NULL;
  1130. ACTION_STRUCT actionStruct;
  1131. BOOL result = FALSE;
  1132. if (InfFindFirstLine (Inf, Section, NULL, &is)) {
  1133. do {
  1134. if (IsmCheckCancel()) {
  1135. break;
  1136. }
  1137. __try {
  1138. ZeroMemory (&actionStruct, sizeof (ACTION_STRUCT));
  1139. srcHandle = NULL;
  1140. certStore = InfGetStringField (&is, 1);
  1141. if (!certStore) {
  1142. continue;
  1143. }
  1144. //
  1145. // Expand environment variables in ini file specification
  1146. //
  1147. expandResult = AppSearchAndReplace (
  1148. PLATFORM_SOURCE,
  1149. Application,
  1150. certStore,
  1151. buffer,
  1152. ARRAYSIZE(buffer)
  1153. );
  1154. if (!expandResult) {
  1155. // the line contains at least one unexpandable env. variables
  1156. expandResult = AppCheckAndLogUndefVariables (
  1157. PLATFORM_SOURCE,
  1158. Application,
  1159. certStore
  1160. );
  1161. if (expandResult) {
  1162. // the line contains known but undefined env. variables
  1163. continue;
  1164. }
  1165. }
  1166. if (IsValidFileSpec (buffer)) {
  1167. //
  1168. // Fix the potential file store specification
  1169. //
  1170. newCertStore = SanitizePath (buffer);
  1171. if(!newCertStore) {
  1172. continue;
  1173. }
  1174. }
  1175. // let's get the certificate pattern. If nothing is specified we assume all
  1176. certPattern = InfGetStringField (&is, 2);
  1177. if (!certPattern) {
  1178. certPattern = PmDuplicateString (is.PoolHandle, TEXT("*"));
  1179. }
  1180. // let's build the object handle
  1181. srcHandle = TurnCertSpecIntoHandle (newCertStore?newCertStore:buffer, certPattern, TRUE);
  1182. // now let's build the object base
  1183. actionStruct.ObjectBase = TurnCertSpecIntoHandle (newCertStore?newCertStore:buffer, certPattern, FALSE);
  1184. if (newCertStore) {
  1185. FreePathString (newCertStore);
  1186. newCertStore = NULL;
  1187. }
  1188. //
  1189. // Add this rule
  1190. //
  1191. if (!AddRule (
  1192. g_CertType,
  1193. actionStruct.ObjectBase,
  1194. srcHandle,
  1195. ActionGroup,
  1196. ActionFlags,
  1197. &actionStruct
  1198. )) {
  1199. DEBUGMSG ((DBG_ERROR, "Error processing CERT rules for %s\\%s", newCertStore, certPattern));
  1200. }
  1201. //
  1202. // Queue enumeration for include patterns
  1203. //
  1204. if (ActionGroup == ACTIONGROUP_INCLUDE) {
  1205. IsmQueueEnumeration (
  1206. g_CertType,
  1207. srcHandle,
  1208. g_VcmMode ? GatherVirtualComputer : PrepareActions,
  1209. 0,
  1210. NULL
  1211. );
  1212. }
  1213. }
  1214. __finally {
  1215. IsmDestroyObjectHandle (srcHandle);
  1216. srcHandle = NULL;
  1217. IsmDestroyObjectHandle (actionStruct.ObjectBase);
  1218. actionStruct.ObjectBase = NULL;
  1219. }
  1220. } while (InfFindNextLine (&is));
  1221. result = !IsmCheckCancel();
  1222. } else {
  1223. LOG ((LOG_ERROR, (PCSTR) MSG_EMPTY_OR_MISSING_SECTION, Section));
  1224. }
  1225. InfCleanUpInfStruct (&is);
  1226. return result;
  1227. }
  1228. BOOL
  1229. pParseFiles (
  1230. IN HINF Inf,
  1231. IN PCTSTR Section,
  1232. IN ACTIONGROUP ActionGroup,
  1233. IN DWORD ActionFlags,
  1234. IN PCTSTR Application OPTIONAL
  1235. )
  1236. {
  1237. INFSTRUCT is = INITINFSTRUCT_PMHANDLE;
  1238. PCTSTR pattern;
  1239. PCTSTR newPattern = NULL;
  1240. PCTSTR dirText;
  1241. BOOL tree;
  1242. MIG_OBJECTSTRINGHANDLE srcHandle = NULL;
  1243. PCTSTR destination;
  1244. PCTSTR leafDest;
  1245. TCHAR buffer1[MAX_TCHAR_PATH * 2];
  1246. ACTION_STRUCT actionStruct;
  1247. BOOL result = FALSE;
  1248. PCTSTR msgNode;
  1249. PCTSTR msgLeaf;
  1250. PCTSTR newDest = NULL;
  1251. BOOL expandResult = TRUE;
  1252. if (InfFindFirstLine (Inf, Section, NULL, &is)) {
  1253. do {
  1254. if (IsmCheckCancel()) {
  1255. break;
  1256. }
  1257. ZeroMemory (&actionStruct, sizeof (ACTION_STRUCT));
  1258. dirText = InfGetStringField (&is, 0);
  1259. pattern = InfGetStringField (&is, 1);
  1260. if (!pattern) {
  1261. continue;
  1262. }
  1263. //
  1264. // Expand environment variables in pattern (the left-side file spec)
  1265. //
  1266. expandResult = AppSearchAndReplace (
  1267. PLATFORM_SOURCE,
  1268. Application,
  1269. pattern,
  1270. buffer1,
  1271. ARRAYSIZE(buffer1)
  1272. );
  1273. if (!expandResult) {
  1274. // the line contains at least one unexpandable env. variables
  1275. expandResult = AppCheckAndLogUndefVariables (
  1276. PLATFORM_SOURCE,
  1277. Application,
  1278. pattern
  1279. );
  1280. if (expandResult) {
  1281. // the line contains known but undefined env. variables
  1282. continue;
  1283. }
  1284. }
  1285. //
  1286. // Fix the pattern
  1287. //
  1288. newPattern = SanitizePath(buffer1);
  1289. if(!newPattern) {
  1290. continue;
  1291. }
  1292. //
  1293. // Test for dir specification
  1294. //
  1295. if (dirText && StringIMatch (dirText, TEXT("Dir")) && !StringIMatch (pattern, TEXT("Dir"))) {
  1296. tree = TRUE;
  1297. } else {
  1298. tree = FALSE;
  1299. }
  1300. // require full spec or leaf only
  1301. if (!IsValidFileSpec (newPattern) && _tcschr (newPattern, TEXT('\\'))) {
  1302. if (expandResult) {
  1303. LOG ((LOG_ERROR, (PCSTR) MSG_FILE_SPEC_BAD, pattern));
  1304. }
  1305. continue;
  1306. }
  1307. srcHandle = TurnFileStringIntoHandle (newPattern, tree ? PFF_PATTERN_IS_DIR : 0);
  1308. if (!srcHandle) {
  1309. LOG ((LOG_ERROR, (PCSTR) MSG_FILE_SPEC_BAD, pattern));
  1310. continue;
  1311. }
  1312. actionStruct.ObjectBase = TurnFileStringIntoHandle (
  1313. newPattern,
  1314. PFF_COMPUTE_BASE|
  1315. PFF_NO_SUBDIR_PATTERN|
  1316. (tree?PFF_NO_LEAF_AT_ALL:PFF_NO_LEAF_PATTERN)
  1317. );
  1318. if (actionStruct.ObjectBase && !StringIMatch (actionStruct.ObjectBase, srcHandle)) {
  1319. IsmCreateObjectStringsFromHandle (actionStruct.ObjectBase, &msgNode, &msgLeaf);
  1320. MYASSERT (!msgLeaf);
  1321. LOG ((LOG_INFORMATION, (PCSTR) MSG_FILE_MOVE_BASE_INFO, newPattern, msgNode));
  1322. IsmDestroyObjectString (msgNode);
  1323. IsmDestroyObjectString (msgLeaf);
  1324. }
  1325. if (ActionFlags & ACTION_PERSIST) {
  1326. if (ActionGroup == ACTIONGROUP_INCLUDE ||
  1327. ActionGroup == ACTIONGROUP_INCLUDEEX ||
  1328. ActionGroup == ACTIONGROUP_RENAME ||
  1329. ActionGroup == ACTIONGROUP_RENAMEEX ||
  1330. ActionGroup == ACTIONGROUP_INCLUDERELEVANT ||
  1331. ActionGroup == ACTIONGROUP_INCLUDERELEVANTEX ||
  1332. ActionGroup == ACTIONGROUP_RENAMERELEVANT ||
  1333. ActionGroup == ACTIONGROUP_RENAMERELEVANTEX
  1334. ) {
  1335. //
  1336. // For the CopyFiles and CopyFilesFiltered sections, get the
  1337. // optional destination. If destination is specified, move
  1338. // all of the files into that destination.
  1339. //
  1340. destination = InfGetStringField (&is, 2);
  1341. if (destination && *destination) {
  1342. if (ActionGroup == ACTIONGROUP_INCLUDE) {
  1343. ActionGroup = ACTIONGROUP_RENAME;
  1344. }
  1345. if (ActionGroup == ACTIONGROUP_INCLUDEEX) {
  1346. ActionGroup = ACTIONGROUP_RENAMEEX;
  1347. }
  1348. if (ActionGroup == ACTIONGROUP_INCLUDERELEVANT) {
  1349. ActionGroup = ACTIONGROUP_RENAMERELEVANT;
  1350. }
  1351. if (ActionGroup == ACTIONGROUP_INCLUDERELEVANTEX) {
  1352. ActionGroup = ACTIONGROUP_RENAMERELEVANTEX;
  1353. }
  1354. newDest = SanitizePath (destination);
  1355. if (newDest) {
  1356. actionStruct.ObjectDest = TurnFileStringIntoHandle (
  1357. newDest,
  1358. PFF_COMPUTE_BASE|
  1359. PFF_NO_SUBDIR_PATTERN|
  1360. PFF_NO_PATTERNS_ALLOWED|
  1361. PFF_NO_LEAF_AT_ALL
  1362. );
  1363. FreePathString (newDest);
  1364. newDest = NULL;
  1365. }
  1366. if ((ActionGroup == ACTIONGROUP_RENAMEEX) ||
  1367. (ActionGroup == ACTIONGROUP_RENAMERELEVANTEX)
  1368. ) {
  1369. // we might have an extra field for the leaf name
  1370. leafDest = InfGetStringField (&is, 3);
  1371. if (leafDest && *leafDest) {
  1372. // we have to rebuild actionStruct.ObjectDest
  1373. IsmCreateObjectStringsFromHandle (actionStruct.ObjectDest, &msgNode, &msgLeaf);
  1374. IsmDestroyObjectHandle (actionStruct.ObjectDest);
  1375. actionStruct.ObjectDest = IsmCreateObjectHandle (msgNode, leafDest);
  1376. IsmDestroyObjectString (msgNode);
  1377. IsmDestroyObjectString (msgLeaf);
  1378. }
  1379. }
  1380. if (!actionStruct.ObjectDest) {
  1381. LOG ((LOG_ERROR, (PCSTR) MSG_FILE_SPEC_BAD_DEST, destination));
  1382. IsmDestroyObjectHandle (srcHandle);
  1383. srcHandle = NULL;
  1384. continue;
  1385. }
  1386. }
  1387. }
  1388. }
  1389. //
  1390. // Add this rule
  1391. //
  1392. if (!AddRule (
  1393. g_FileType,
  1394. actionStruct.ObjectBase,
  1395. srcHandle,
  1396. ActionGroup,
  1397. ActionFlags,
  1398. &actionStruct
  1399. )) {
  1400. DEBUGMSG ((DBG_ERROR, "Error processing file rules"));
  1401. break;
  1402. }
  1403. //
  1404. // Queue enumeration for include patterns
  1405. //
  1406. if ((ActionGroup == ACTIONGROUP_INCLUDE) ||
  1407. (ActionGroup == ACTIONGROUP_INCLUDEEX) ||
  1408. (ActionGroup == ACTIONGROUP_RENAME) ||
  1409. (ActionGroup == ACTIONGROUP_RENAMEEX) ||
  1410. (ActionGroup == ACTIONGROUP_INCLUDERELEVANT) ||
  1411. (ActionGroup == ACTIONGROUP_INCLUDERELEVANTEX) ||
  1412. (ActionGroup == ACTIONGROUP_RENAMERELEVANT) ||
  1413. (ActionGroup == ACTIONGROUP_RENAMERELEVANTEX)
  1414. ) {
  1415. //
  1416. // Queue the enumeration callback
  1417. //
  1418. if (IsmIsObjectHandleLeafOnly (srcHandle)) {
  1419. DEBUGMSG ((DBG_SCRIPT, "Pattern %s triggered enumeration of entire file system", pattern));
  1420. QueueAllFiles (g_VcmMode);
  1421. IsmHookEnumeration (
  1422. g_FileType,
  1423. srcHandle,
  1424. g_VcmMode ? GatherVirtualComputer : PrepareActions,
  1425. 0,
  1426. NULL
  1427. );
  1428. } else {
  1429. if (tree && actionStruct.ObjectBase) {
  1430. IsmQueueEnumeration (
  1431. g_FileType,
  1432. actionStruct.ObjectBase,
  1433. g_VcmMode ? GatherVirtualComputer : PrepareActions,
  1434. 0,
  1435. NULL
  1436. );
  1437. }
  1438. IsmQueueEnumeration (
  1439. g_FileType,
  1440. srcHandle,
  1441. g_VcmMode ? GatherVirtualComputer : PrepareActions,
  1442. 0,
  1443. NULL
  1444. );
  1445. }
  1446. }
  1447. IsmDestroyObjectHandle (srcHandle);
  1448. srcHandle = NULL;
  1449. IsmDestroyObjectHandle (actionStruct.ObjectBase);
  1450. actionStruct.ObjectBase = NULL;
  1451. IsmDestroyObjectHandle (actionStruct.ObjectDest);
  1452. actionStruct.ObjectDest = NULL;
  1453. FreePathString(newPattern);
  1454. } while (InfFindNextLine (&is));
  1455. result = !IsmCheckCancel();
  1456. }
  1457. InfCleanUpInfStruct (&is);
  1458. return result;
  1459. }
  1460. BOOL
  1461. pParseLockPartition (
  1462. IN HINF Inf,
  1463. IN PCTSTR Section
  1464. )
  1465. {
  1466. INFSTRUCT is = INITINFSTRUCT_PMHANDLE;
  1467. PCTSTR pattern;
  1468. MIG_OBJECTSTRINGHANDLE srcHandle = NULL;
  1469. BOOL result = FALSE;
  1470. if (InfFindFirstLine (Inf, Section, NULL, &is)) {
  1471. do {
  1472. if (IsmCheckCancel()) {
  1473. break;
  1474. }
  1475. pattern = InfGetStringField (&is, 0);
  1476. if (!pattern) {
  1477. LOG ((LOG_WARNING, (PCSTR) MSG_EMPTY_FILE_SPEC));
  1478. IsmDestroyObjectHandle (srcHandle);
  1479. srcHandle = NULL;
  1480. continue;
  1481. }
  1482. srcHandle = TurnFileStringIntoHandle (pattern, 0);
  1483. if (!srcHandle) {
  1484. LOG ((LOG_ERROR, (PCSTR) MSG_FILE_SPEC_BAD, pattern));
  1485. IsmDestroyObjectHandle (srcHandle);
  1486. srcHandle = NULL;
  1487. continue;
  1488. }
  1489. IsmHookEnumeration (
  1490. g_FileType,
  1491. srcHandle,
  1492. LockPartition,
  1493. 0,
  1494. NULL
  1495. );
  1496. IsmDestroyObjectHandle (srcHandle);
  1497. srcHandle = NULL;
  1498. } while (InfFindNextLine (&is));
  1499. result = !IsmCheckCancel();
  1500. }
  1501. InfCleanUpInfStruct (&is);
  1502. return result;
  1503. }
  1504. BOOL
  1505. pParseRegPriority (
  1506. IN HINF Inf,
  1507. IN PCTSTR Section,
  1508. IN DWORD ActionFlags,
  1509. IN PCTSTR Application, OPTIONAL
  1510. IN BOOL ExtendedPattern
  1511. )
  1512. {
  1513. INFSTRUCT is = INITINFSTRUCT_PMHANDLE;
  1514. PCTSTR pattern = NULL;
  1515. PCTSTR patternLeaf = NULL;
  1516. PCTSTR baseNode = NULL;
  1517. PCTSTR nodeCopy = NULL;
  1518. PTSTR ptr;
  1519. MIG_OBJECTSTRINGHANDLE srcHandle = NULL;
  1520. MIG_OBJECTSTRINGHANDLE baseHandle = NULL;
  1521. BOOL result = FALSE;
  1522. if (InfFindFirstLine (Inf, Section, NULL, &is)) {
  1523. do {
  1524. if (IsmCheckCancel()) {
  1525. break;
  1526. }
  1527. pattern = InfGetStringField (&is, 1);
  1528. if (!pattern) {
  1529. LOG ((LOG_WARNING, (PCSTR) MSG_EMPTY_RENREG));
  1530. IsmDestroyObjectHandle (srcHandle);
  1531. srcHandle = NULL;
  1532. continue;
  1533. }
  1534. if (ExtendedPattern) {
  1535. patternLeaf = InfGetStringField (&is, 2);
  1536. }
  1537. if (ExtendedPattern) {
  1538. srcHandle = CreatePatternFromNodeLeaf (pattern, patternLeaf?patternLeaf:TEXT("*"));
  1539. } else {
  1540. srcHandle = TurnRegStringIntoHandle (pattern, TRUE, NULL);
  1541. }
  1542. if (!srcHandle) {
  1543. LOG ((LOG_ERROR, (PCSTR) MSG_REG_SPEC_BAD, pattern));
  1544. IsmDestroyObjectHandle (srcHandle);
  1545. srcHandle = NULL;
  1546. continue;
  1547. }
  1548. if (ExtendedPattern) {
  1549. ptr = _tcschr (pattern, TEXT('\\'));
  1550. if (ptr) {
  1551. if (StringIPrefix (pattern, TEXT("HKR\\"))) {
  1552. nodeCopy = JoinText (TEXT("HKCU"), ptr);
  1553. } else {
  1554. nodeCopy = DuplicateText (pattern);
  1555. }
  1556. baseNode = GetPatternBase (nodeCopy);
  1557. if (baseNode) {
  1558. baseHandle = IsmCreateObjectHandle (baseNode, NULL);
  1559. FreePathString (baseNode);
  1560. }
  1561. FreeText (nodeCopy);
  1562. }
  1563. } else {
  1564. baseHandle = TurnRegStringIntoHandle (pattern, FALSE, NULL);
  1565. }
  1566. AddRuleEx (
  1567. g_RegType,
  1568. baseHandle,
  1569. srcHandle,
  1570. ACTIONGROUP_SPECIFICPRIORITY,
  1571. ActionFlags,
  1572. NULL,
  1573. RULEGROUP_PRIORITY
  1574. );
  1575. IsmHookEnumeration (
  1576. g_RegType,
  1577. srcHandle,
  1578. ObjectPriority,
  1579. 0,
  1580. NULL
  1581. );
  1582. IsmDestroyObjectHandle (baseHandle);
  1583. IsmDestroyObjectHandle (srcHandle);
  1584. srcHandle = NULL;
  1585. } while (InfFindNextLine (&is));
  1586. result = !IsmCheckCancel();
  1587. }
  1588. InfCleanUpInfStruct (&is);
  1589. return result;
  1590. }
  1591. BOOL
  1592. pParseIniPriority (
  1593. IN HINF Inf,
  1594. IN PCTSTR Section,
  1595. IN DWORD ActionFlags,
  1596. IN PCTSTR Application OPTIONAL
  1597. )
  1598. {
  1599. INFSTRUCT is = INITINFSTRUCT_PMHANDLE;
  1600. PCTSTR iniFile = NULL;
  1601. TCHAR buffer [MAX_TCHAR_PATH * 2];
  1602. PCTSTR newIniFile = NULL;
  1603. BOOL expandResult = TRUE;
  1604. PCTSTR sectPattern = NULL;
  1605. PCTSTR keyPattern = NULL;
  1606. MIG_OBJECTSTRINGHANDLE srcHandle = NULL;
  1607. MIG_OBJECTSTRINGHANDLE baseHandle = NULL;
  1608. BOOL result = FALSE;
  1609. if (InfFindFirstLine (Inf, Section, NULL, &is)) {
  1610. do {
  1611. if (IsmCheckCancel()) {
  1612. break;
  1613. }
  1614. __try {
  1615. srcHandle = NULL;
  1616. iniFile = InfGetStringField (&is, 1);
  1617. if (!iniFile) {
  1618. continue;
  1619. }
  1620. //
  1621. // Expand environment variables in ini file specification
  1622. //
  1623. expandResult = AppSearchAndReplace (
  1624. PLATFORM_SOURCE,
  1625. Application,
  1626. iniFile,
  1627. buffer,
  1628. ARRAYSIZE(buffer)
  1629. );
  1630. if (!expandResult) {
  1631. // the line contains at least one unexpandable env. variables
  1632. expandResult = AppCheckAndLogUndefVariables (
  1633. PLATFORM_SOURCE,
  1634. Application,
  1635. iniFile
  1636. );
  1637. if (expandResult) {
  1638. // the line contains known but undefined env. variables
  1639. continue;
  1640. }
  1641. }
  1642. //
  1643. // Fix the ini file specification
  1644. //
  1645. newIniFile = SanitizePath (buffer);
  1646. if(!newIniFile) {
  1647. continue;
  1648. }
  1649. // require full spec for the INI dir
  1650. if (!IsValidFileSpec (newIniFile)) {
  1651. if (expandResult) {
  1652. LOG ((LOG_ERROR, (PCSTR) MSG_FILE_SPEC_BAD, iniFile));
  1653. }
  1654. FreePathString (newIniFile);
  1655. newIniFile = NULL;
  1656. continue;
  1657. }
  1658. // let's get the section pattern. If nothing is specified we assume all
  1659. sectPattern = InfGetStringField (&is, 2);
  1660. if (!sectPattern) {
  1661. sectPattern = PmDuplicateString (is.PoolHandle, TEXT("*"));
  1662. }
  1663. // let's get the key pattern. If nothing is specified we assume all
  1664. keyPattern = InfGetStringField (&is, 3);
  1665. if (!keyPattern) {
  1666. keyPattern = PmDuplicateString (is.PoolHandle, TEXT("*"));
  1667. }
  1668. // let's build the object handle
  1669. srcHandle = TurnIniSpecIntoHandle (
  1670. newIniFile,
  1671. sectPattern,
  1672. keyPattern,
  1673. TRUE,
  1674. TRUE
  1675. );
  1676. // now let's build the object base
  1677. baseHandle = TurnIniSpecIntoHandle (
  1678. newIniFile,
  1679. sectPattern,
  1680. keyPattern,
  1681. FALSE,
  1682. FALSE
  1683. );
  1684. FreePathString (newIniFile);
  1685. newIniFile = NULL;
  1686. AddRuleEx (
  1687. g_IniType,
  1688. baseHandle,
  1689. srcHandle,
  1690. ACTIONGROUP_SPECIFICPRIORITY,
  1691. ActionFlags,
  1692. NULL,
  1693. RULEGROUP_PRIORITY
  1694. );
  1695. IsmHookEnumeration (
  1696. g_IniType,
  1697. srcHandle,
  1698. ObjectPriority,
  1699. 0,
  1700. NULL
  1701. );
  1702. }
  1703. __finally {
  1704. IsmDestroyObjectHandle (srcHandle);
  1705. srcHandle = NULL;
  1706. IsmDestroyObjectHandle (baseHandle);
  1707. baseHandle = NULL;
  1708. }
  1709. } while (InfFindNextLine (&is));
  1710. result = !IsmCheckCancel();
  1711. } else {
  1712. LOG ((LOG_ERROR, (PCSTR) MSG_EMPTY_OR_MISSING_SECTION, Section));
  1713. }
  1714. InfCleanUpInfStruct (&is);
  1715. return result;
  1716. }
  1717. BOOL
  1718. pParseCertPriority (
  1719. IN HINF Inf,
  1720. IN PCTSTR Section,
  1721. IN DWORD ActionFlags,
  1722. IN PCTSTR Application OPTIONAL
  1723. )
  1724. {
  1725. INFSTRUCT is = INITINFSTRUCT_PMHANDLE;
  1726. PCTSTR certStore;
  1727. TCHAR buffer [MAX_TCHAR_PATH * 2];
  1728. PCTSTR newCertStore = NULL;
  1729. BOOL expandResult = TRUE;
  1730. PCTSTR certPattern;
  1731. MIG_OBJECTSTRINGHANDLE srcHandle = NULL;
  1732. ACTION_STRUCT actionStruct;
  1733. BOOL result = FALSE;
  1734. if (InfFindFirstLine (Inf, Section, NULL, &is)) {
  1735. do {
  1736. if (IsmCheckCancel()) {
  1737. break;
  1738. }
  1739. __try {
  1740. ZeroMemory (&actionStruct, sizeof (ACTION_STRUCT));
  1741. srcHandle = NULL;
  1742. certStore = InfGetStringField (&is, 1);
  1743. if (!certStore) {
  1744. continue;
  1745. }
  1746. //
  1747. // Expand environment variables in ini file specification
  1748. //
  1749. expandResult = AppSearchAndReplace (
  1750. PLATFORM_SOURCE,
  1751. Application,
  1752. certStore,
  1753. buffer,
  1754. ARRAYSIZE(buffer)
  1755. );
  1756. if (!expandResult) {
  1757. // the line contains at least one unexpandable env. variables
  1758. expandResult = AppCheckAndLogUndefVariables (
  1759. PLATFORM_SOURCE,
  1760. Application,
  1761. certStore
  1762. );
  1763. if (expandResult) {
  1764. // the line contains known but undefined env. variables
  1765. continue;
  1766. }
  1767. }
  1768. if (IsValidFileSpec (buffer)) {
  1769. //
  1770. // Fix the potential file store specification
  1771. //
  1772. newCertStore = SanitizePath (buffer);
  1773. if(!newCertStore) {
  1774. continue;
  1775. }
  1776. }
  1777. // let's get the certificate pattern. If nothing is specified we assume all
  1778. certPattern = InfGetStringField (&is, 2);
  1779. if (!certPattern) {
  1780. certPattern = PmDuplicateString (is.PoolHandle, TEXT("*"));
  1781. }
  1782. // let's build the object handle
  1783. srcHandle = TurnCertSpecIntoHandle (newCertStore?newCertStore:buffer, certPattern, TRUE);
  1784. // now let's build the object base
  1785. actionStruct.ObjectBase = TurnCertSpecIntoHandle (newCertStore?newCertStore:buffer, certPattern, FALSE);
  1786. if (newCertStore) {
  1787. FreePathString (newCertStore);
  1788. newCertStore = NULL;
  1789. }
  1790. AddRuleEx (
  1791. g_CertType,
  1792. actionStruct.ObjectBase,
  1793. srcHandle,
  1794. ACTIONGROUP_SPECIFICPRIORITY,
  1795. ActionFlags,
  1796. NULL,
  1797. RULEGROUP_PRIORITY
  1798. );
  1799. IsmHookEnumeration (
  1800. g_CertType,
  1801. srcHandle,
  1802. ObjectPriority,
  1803. 0,
  1804. NULL
  1805. );
  1806. }
  1807. __finally {
  1808. IsmDestroyObjectHandle (srcHandle);
  1809. srcHandle = NULL;
  1810. IsmDestroyObjectHandle (actionStruct.ObjectBase);
  1811. actionStruct.ObjectBase = NULL;
  1812. }
  1813. } while (InfFindNextLine (&is));
  1814. result = !IsmCheckCancel();
  1815. } else {
  1816. LOG ((LOG_ERROR, (PCSTR) MSG_EMPTY_OR_MISSING_SECTION, Section));
  1817. }
  1818. InfCleanUpInfStruct (&is);
  1819. return result;
  1820. }
  1821. BOOL
  1822. pParseFilePriority (
  1823. IN HINF Inf,
  1824. IN PCTSTR Section,
  1825. IN DWORD ActionFlags,
  1826. IN PCTSTR Application OPTIONAL
  1827. )
  1828. {
  1829. INFSTRUCT is = INITINFSTRUCT_PMHANDLE;
  1830. PCTSTR newPattern = NULL;
  1831. PCTSTR pattern;
  1832. PCTSTR dirText;
  1833. BOOL tree;
  1834. MIG_OBJECTSTRINGHANDLE srcHandle = NULL;
  1835. MIG_OBJECTSTRINGHANDLE baseHandle = NULL;
  1836. TCHAR buffer1[MAX_TCHAR_PATH * 2];
  1837. BOOL result = FALSE;
  1838. BOOL expandResult = TRUE;
  1839. if (InfFindFirstLine (Inf, Section, NULL, &is)) {
  1840. do {
  1841. if (IsmCheckCancel()) {
  1842. break;
  1843. }
  1844. dirText = InfGetStringField (&is, 0);
  1845. pattern = InfGetStringField (&is, 1);
  1846. if (!pattern) {
  1847. continue;
  1848. }
  1849. //
  1850. // Expand environment variables in pattern (the left-side file spec)
  1851. //
  1852. expandResult = AppSearchAndReplace (
  1853. PLATFORM_SOURCE,
  1854. Application,
  1855. pattern,
  1856. buffer1,
  1857. ARRAYSIZE(buffer1)
  1858. );
  1859. if (!expandResult) {
  1860. // the line contains at least one unexpandable env. variables
  1861. expandResult = AppCheckAndLogUndefVariables (
  1862. PLATFORM_SOURCE,
  1863. Application,
  1864. pattern
  1865. );
  1866. if (expandResult) {
  1867. // the line contains known but undefined env. variables
  1868. continue;
  1869. }
  1870. }
  1871. //
  1872. // Fix the pattern
  1873. //
  1874. newPattern = SanitizePath(buffer1);
  1875. if(!newPattern) {
  1876. continue;
  1877. }
  1878. //
  1879. // Test for dir specification
  1880. //
  1881. if (dirText && StringIMatch (dirText, TEXT("Dir"))) {
  1882. tree = TRUE;
  1883. } else {
  1884. tree = FALSE;
  1885. }
  1886. // require full spec
  1887. if (!IsValidFileSpec (newPattern)) {
  1888. if (expandResult) {
  1889. LOG ((LOG_ERROR, (PCSTR) MSG_FILE_SPEC_BAD, pattern));
  1890. }
  1891. FreePathString (newPattern);
  1892. newPattern = NULL;
  1893. continue;
  1894. }
  1895. srcHandle = TurnFileStringIntoHandle (newPattern, tree ? PFF_PATTERN_IS_DIR : 0);
  1896. if (!srcHandle) {
  1897. LOG ((LOG_ERROR, (PCSTR) MSG_FILE_SPEC_BAD, pattern));
  1898. FreePathString (newPattern);
  1899. newPattern = NULL;
  1900. continue;
  1901. }
  1902. baseHandle = TurnFileStringIntoHandle (
  1903. newPattern,
  1904. PFF_COMPUTE_BASE|
  1905. PFF_NO_SUBDIR_PATTERN|
  1906. (tree?PFF_NO_LEAF_AT_ALL:PFF_NO_LEAF_PATTERN)
  1907. );
  1908. AddRuleEx (
  1909. g_FileType,
  1910. baseHandle,
  1911. srcHandle,
  1912. ACTIONGROUP_SPECIFICPRIORITY,
  1913. ActionFlags,
  1914. NULL,
  1915. RULEGROUP_PRIORITY
  1916. );
  1917. IsmHookEnumeration (
  1918. g_FileType,
  1919. srcHandle,
  1920. ObjectPriority,
  1921. 0,
  1922. NULL
  1923. );
  1924. IsmDestroyObjectHandle (baseHandle);
  1925. IsmDestroyObjectHandle (srcHandle);
  1926. srcHandle = NULL;
  1927. FreePathString (newPattern);
  1928. newPattern = NULL;
  1929. } while (InfFindNextLine (&is));
  1930. result = !IsmCheckCancel();
  1931. }
  1932. InfCleanUpInfStruct (&is);
  1933. return result;
  1934. }
  1935. BOOL
  1936. pParseFileCollisionPattern (
  1937. IN HINF Inf,
  1938. IN PCTSTR Section,
  1939. IN PCTSTR Application OPTIONAL
  1940. )
  1941. {
  1942. INFSTRUCT is = INITINFSTRUCT_PMHANDLE;
  1943. PCTSTR pattern;
  1944. PCTSTR newPattern = NULL;
  1945. PCTSTR dirText;
  1946. BOOL tree;
  1947. MIG_OBJECTSTRINGHANDLE srcHandle = NULL;
  1948. PCTSTR collPattern;
  1949. TCHAR buffer1[MAX_TCHAR_PATH * 2];
  1950. ACTION_STRUCT actionStruct;
  1951. BOOL result = FALSE;
  1952. PCTSTR msgNode;
  1953. PCTSTR msgLeaf;
  1954. BOOL expandResult = TRUE;
  1955. if (InfFindFirstLine (Inf, Section, NULL, &is)) {
  1956. do {
  1957. if (IsmCheckCancel()) {
  1958. break;
  1959. }
  1960. ZeroMemory (&actionStruct, sizeof (ACTION_STRUCT));
  1961. dirText = InfGetStringField (&is, 0);
  1962. pattern = InfGetStringField (&is, 1);
  1963. if (!pattern) {
  1964. continue;
  1965. }
  1966. //
  1967. // Expand environment variables in pattern (the left-side file spec)
  1968. //
  1969. expandResult = AppSearchAndReplace (
  1970. PLATFORM_SOURCE,
  1971. Application,
  1972. pattern,
  1973. buffer1,
  1974. ARRAYSIZE(buffer1)
  1975. );
  1976. if (!expandResult) {
  1977. // the line contains at least one unexpandable env. variables
  1978. expandResult = AppCheckAndLogUndefVariables (
  1979. PLATFORM_SOURCE,
  1980. Application,
  1981. pattern
  1982. );
  1983. if (expandResult) {
  1984. // the line contains known but undefined env. variables
  1985. continue;
  1986. }
  1987. }
  1988. //
  1989. // Fix the pattern
  1990. //
  1991. newPattern = SanitizePath(buffer1);
  1992. if(!newPattern) {
  1993. continue;
  1994. }
  1995. //
  1996. // Test for dir specification
  1997. //
  1998. if (dirText && StringIMatch (dirText, TEXT("Dir")) && !StringIMatch (pattern, TEXT("Dir"))) {
  1999. tree = TRUE;
  2000. } else {
  2001. tree = FALSE;
  2002. }
  2003. // require full spec or leaf only
  2004. if (!IsValidFileSpec (newPattern) && _tcschr (newPattern, TEXT('\\'))) {
  2005. if (expandResult) {
  2006. LOG ((LOG_ERROR, (PCSTR) MSG_FILE_SPEC_BAD, pattern));
  2007. }
  2008. continue;
  2009. }
  2010. srcHandle = TurnFileStringIntoHandle (newPattern, tree ? PFF_PATTERN_IS_DIR : 0);
  2011. if (!srcHandle) {
  2012. LOG ((LOG_ERROR, (PCSTR) MSG_FILE_SPEC_BAD, pattern));
  2013. continue;
  2014. }
  2015. actionStruct.ObjectBase = TurnFileStringIntoHandle (
  2016. newPattern,
  2017. PFF_COMPUTE_BASE|
  2018. PFF_NO_SUBDIR_PATTERN|
  2019. (tree?PFF_NO_LEAF_AT_ALL:PFF_NO_LEAF_PATTERN)
  2020. );
  2021. collPattern = InfGetStringField (&is, 2);
  2022. if ((!collPattern) || (!(*collPattern))) {
  2023. // we have no collision pattern, let's get out
  2024. continue;
  2025. }
  2026. actionStruct.ObjectHint = IsmDuplicateString (collPattern);
  2027. //
  2028. // Add this rule
  2029. //
  2030. if (!AddRuleEx (
  2031. g_FileType,
  2032. actionStruct.ObjectBase,
  2033. srcHandle,
  2034. ACTIONGROUP_FILECOLLPATTERN,
  2035. 0,
  2036. &actionStruct,
  2037. RULEGROUP_COLLPATTERN
  2038. )) {
  2039. DEBUGMSG ((DBG_ERROR, "Error processing file rules"));
  2040. break;
  2041. }
  2042. //
  2043. // Queue the enumeration callback
  2044. //
  2045. if (IsmIsObjectHandleLeafOnly (srcHandle)) {
  2046. DEBUGMSG ((DBG_SCRIPT, "Pattern %s triggered enumeration of entire file system", pattern));
  2047. IsmHookEnumeration (
  2048. g_FileType,
  2049. srcHandle,
  2050. FileCollPattern,
  2051. 0,
  2052. NULL
  2053. );
  2054. } else {
  2055. if (tree && actionStruct.ObjectBase) {
  2056. IsmHookEnumeration (
  2057. g_FileType,
  2058. actionStruct.ObjectBase,
  2059. FileCollPattern,
  2060. 0,
  2061. NULL
  2062. );
  2063. }
  2064. IsmHookEnumeration (
  2065. g_FileType,
  2066. srcHandle,
  2067. FileCollPattern,
  2068. 0,
  2069. NULL
  2070. );
  2071. }
  2072. IsmDestroyObjectHandle (srcHandle);
  2073. srcHandle = NULL;
  2074. IsmDestroyObjectHandle (actionStruct.ObjectBase);
  2075. actionStruct.ObjectBase = NULL;
  2076. IsmReleaseMemory (actionStruct.ObjectHint);
  2077. actionStruct.ObjectHint = NULL;
  2078. FreePathString(newPattern);
  2079. } while (InfFindNextLine (&is));
  2080. result = !IsmCheckCancel();
  2081. }
  2082. InfCleanUpInfStruct (&is);
  2083. return result;
  2084. }
  2085. BOOL
  2086. pParseOneInstruction (
  2087. IN HINF InfHandle,
  2088. IN PCTSTR Type,
  2089. IN PCTSTR SectionMultiSz,
  2090. IN PINFSTRUCT InfStruct,
  2091. IN PCTSTR Application OPTIONAL
  2092. )
  2093. {
  2094. ACTIONGROUP actionGroup;
  2095. DWORD actionFlags;
  2096. MULTISZ_ENUM e;
  2097. BOOL result = TRUE;
  2098. MIG_PLATFORMTYPEID platform = IsmGetRealPlatform();
  2099. //
  2100. // First thing: look for nested sections
  2101. //
  2102. if (StringIMatch (Type, TEXT("ProcessSection"))) {
  2103. if (EnumFirstMultiSz (&e, SectionMultiSz)) {
  2104. do {
  2105. result = result & ParseOneApplication (
  2106. PLATFORM_SOURCE,
  2107. InfHandle,
  2108. Application,
  2109. FALSE,
  2110. 0,
  2111. e.CurrentString,
  2112. NULL,
  2113. NULL,
  2114. NULL
  2115. );
  2116. } while (EnumNextMultiSz (&e));
  2117. }
  2118. return result;
  2119. }
  2120. //
  2121. // Parse registry sections
  2122. //
  2123. actionGroup = ACTIONGROUP_NONE;
  2124. actionFlags = 0;
  2125. if (StringIMatch (Type, TEXT("AddReg"))) {
  2126. actionGroup = ACTIONGROUP_INCLUDE;
  2127. actionFlags = ACTION_PERSIST;
  2128. } else if (StringIMatch (Type, TEXT("RenReg"))) {
  2129. actionGroup = ACTIONGROUP_RENAME;
  2130. actionFlags = ACTION_PERSIST;
  2131. } else if (StringIMatch (Type, TEXT("DelReg"))) {
  2132. actionGroup = ACTIONGROUP_EXCLUDE;
  2133. actionFlags = 0;
  2134. } else if (StringIMatch (Type, TEXT("RegFile"))) {
  2135. actionGroup = ACTIONGROUP_INCFILE;
  2136. actionFlags = ACTION_PERSIST_PATH_IN_DATA;
  2137. } else if (StringIMatch (Type, TEXT("RegFolder"))) {
  2138. actionGroup = ACTIONGROUP_INCFOLDER;
  2139. actionFlags = ACTION_PERSIST_PATH_IN_DATA;
  2140. } else if (StringIMatch (Type, TEXT("RegIcon"))) {
  2141. actionGroup = ACTIONGROUP_INCICON;
  2142. actionFlags = ACTION_PERSIST_ICON_IN_DATA;
  2143. } else if (StringIMatch (Type, TEXT("DelRegKey"))) {
  2144. actionGroup = ACTIONGROUP_DELREGKEY;
  2145. actionFlags = 0;
  2146. }
  2147. if (actionGroup != ACTIONGROUP_NONE) {
  2148. if (EnumFirstMultiSz (&e, SectionMultiSz)) {
  2149. do {
  2150. if (!pParseReg (
  2151. InfHandle,
  2152. e.CurrentString,
  2153. actionGroup,
  2154. actionFlags,
  2155. TRUE,
  2156. Application
  2157. )) {
  2158. result = FALSE;
  2159. if (InfStruct) {
  2160. InfLogContext (LOG_ERROR, InfHandle, InfStruct);
  2161. }
  2162. break;
  2163. }
  2164. } while (EnumNextMultiSz (&e));
  2165. }
  2166. return result;
  2167. }
  2168. //
  2169. // Parse INI sections
  2170. //
  2171. actionGroup = ACTIONGROUP_NONE;
  2172. actionFlags = 0;
  2173. if (StringIMatch (Type, TEXT("AddIni"))) {
  2174. actionGroup = ACTIONGROUP_INCLUDE;
  2175. actionFlags = ACTION_PERSIST;
  2176. } else if (StringIMatch (Type, TEXT("RenIni"))) {
  2177. actionGroup = ACTIONGROUP_RENAME;
  2178. actionFlags = ACTION_PERSIST;
  2179. } else if (StringIMatch (Type, TEXT("DelIni"))) {
  2180. actionGroup = ACTIONGROUP_EXCLUDE;
  2181. actionFlags = 0;
  2182. } else if (StringIMatch (Type, TEXT("IniFile"))) {
  2183. actionGroup = ACTIONGROUP_INCFILE;
  2184. actionFlags = ACTION_PERSIST_PATH_IN_DATA;
  2185. } else if (StringIMatch (Type, TEXT("IniFolder"))) {
  2186. actionGroup = ACTIONGROUP_INCFOLDER;
  2187. actionFlags = ACTION_PERSIST_PATH_IN_DATA;
  2188. } else if (StringIMatch (Type, TEXT("IniIcon"))) {
  2189. actionGroup = ACTIONGROUP_INCICON;
  2190. actionFlags = ACTION_PERSIST_ICON_IN_DATA;
  2191. }
  2192. if (actionGroup != ACTIONGROUP_NONE) {
  2193. if (EnumFirstMultiSz (&e, SectionMultiSz)) {
  2194. do {
  2195. if (!pParseIni (
  2196. InfHandle,
  2197. e.CurrentString,
  2198. actionGroup,
  2199. actionFlags,
  2200. Application
  2201. )) {
  2202. result = FALSE;
  2203. if (InfStruct) {
  2204. InfLogContext (LOG_ERROR, InfHandle, InfStruct);
  2205. }
  2206. break;
  2207. }
  2208. } while (EnumNextMultiSz (&e));
  2209. }
  2210. return result;
  2211. }
  2212. //
  2213. // Parse file sections
  2214. //
  2215. if (StringIMatch (Type, TEXT("CopyFilesFiltered"))) {
  2216. actionGroup = ACTIONGROUP_INCLUDERELEVANT;
  2217. actionFlags = ACTION_PERSIST;
  2218. } else if (StringIMatch (Type, TEXT("CopyFilesFilteredEx"))) {
  2219. actionGroup = ACTIONGROUP_INCLUDERELEVANTEX;
  2220. actionFlags = ACTION_PERSIST;
  2221. } else if (StringIMatch (Type, TEXT("CopyFiles"))) {
  2222. actionGroup = ACTIONGROUP_INCLUDE;
  2223. actionFlags = ACTION_PERSIST;
  2224. } else if (StringIMatch (Type, TEXT("CopyFilesEx"))) {
  2225. actionGroup = ACTIONGROUP_INCLUDEEX;
  2226. actionFlags = ACTION_PERSIST;
  2227. } else if (StringIMatch (Type, TEXT("DelFiles"))) {
  2228. actionGroup = ACTIONGROUP_EXCLUDE;
  2229. actionFlags = 0;
  2230. }
  2231. if (actionGroup != ACTIONGROUP_NONE) {
  2232. if (EnumFirstMultiSz (&e, SectionMultiSz)) {
  2233. do {
  2234. if (IsmIsEnvironmentFlagSet (platform, NULL, S_ENV_ALL_FILES)) {
  2235. if (!pParseFiles (
  2236. InfHandle,
  2237. e.CurrentString,
  2238. actionGroup,
  2239. actionFlags,
  2240. Application
  2241. )) {
  2242. result = FALSE;
  2243. if (InfStruct) {
  2244. InfLogContext (LOG_ERROR, InfHandle, InfStruct);
  2245. }
  2246. break;
  2247. }
  2248. } else {
  2249. LOG ((
  2250. LOG_INFORMATION,
  2251. (PCSTR) MSG_IGNORING_FILE_SECTION,
  2252. e.CurrentString
  2253. ));
  2254. }
  2255. } while (EnumNextMultiSz (&e));
  2256. }
  2257. return result;
  2258. }
  2259. //
  2260. // Parse certificates sections
  2261. //
  2262. actionGroup = ACTIONGROUP_NONE;
  2263. actionFlags = 0;
  2264. if (StringIMatch (Type, TEXT("AddCertificates"))) {
  2265. actionGroup = ACTIONGROUP_INCLUDE;
  2266. actionFlags = ACTION_PERSIST;
  2267. } else if (StringIMatch (Type, TEXT("DelCertificates"))) {
  2268. actionGroup = ACTIONGROUP_EXCLUDE;
  2269. actionFlags = 0;
  2270. }
  2271. if (actionGroup != ACTIONGROUP_NONE) {
  2272. if (EnumFirstMultiSz (&e, SectionMultiSz)) {
  2273. do {
  2274. if (!pParseCertificates (
  2275. InfHandle,
  2276. e.CurrentString,
  2277. actionGroup,
  2278. actionFlags,
  2279. Application
  2280. )) {
  2281. result = FALSE;
  2282. if (InfStruct) {
  2283. InfLogContext (LOG_ERROR, InfHandle, InfStruct);
  2284. }
  2285. break;
  2286. }
  2287. } while (EnumNextMultiSz (&e));
  2288. }
  2289. return result;
  2290. }
  2291. //
  2292. // Parse registry priority
  2293. //
  2294. if (StringIMatch (Type, TEXT("ForceDestRegEx"))) {
  2295. if (EnumFirstMultiSz (&e, SectionMultiSz)) {
  2296. do {
  2297. if (!pParseRegPriority (InfHandle, e.CurrentString, ACTION_PRIORITYDEST, Application, TRUE)) {
  2298. result = FALSE;
  2299. if (InfStruct) {
  2300. InfLogContext (LOG_ERROR, InfHandle, InfStruct);
  2301. }
  2302. break;
  2303. }
  2304. } while (EnumNextMultiSz (&e));
  2305. }
  2306. return result;
  2307. }
  2308. if (StringIMatch (Type, TEXT("ForceDestReg"))) {
  2309. if (EnumFirstMultiSz (&e, SectionMultiSz)) {
  2310. do {
  2311. if (!pParseRegPriority (InfHandle, e.CurrentString, ACTION_PRIORITYDEST, Application, FALSE)) {
  2312. result = FALSE;
  2313. if (InfStruct) {
  2314. InfLogContext (LOG_ERROR, InfHandle, InfStruct);
  2315. }
  2316. break;
  2317. }
  2318. } while (EnumNextMultiSz (&e));
  2319. }
  2320. return result;
  2321. }
  2322. if (StringIMatch (Type, TEXT("ForceSrcRegEx"))) {
  2323. if (EnumFirstMultiSz (&e, SectionMultiSz)) {
  2324. do {
  2325. if (!pParseRegPriority (InfHandle, e.CurrentString, ACTION_PRIORITYSRC, Application, TRUE)) {
  2326. result = FALSE;
  2327. if (InfStruct) {
  2328. InfLogContext (LOG_ERROR, InfHandle, InfStruct);
  2329. }
  2330. break;
  2331. }
  2332. } while (EnumNextMultiSz (&e));
  2333. }
  2334. return result;
  2335. }
  2336. if (StringIMatch (Type, TEXT("ForceSrcReg"))) {
  2337. if (EnumFirstMultiSz (&e, SectionMultiSz)) {
  2338. do {
  2339. if (!pParseRegPriority (InfHandle, e.CurrentString, ACTION_PRIORITYSRC, Application, FALSE)) {
  2340. result = FALSE;
  2341. if (InfStruct) {
  2342. InfLogContext (LOG_ERROR, InfHandle, InfStruct);
  2343. }
  2344. break;
  2345. }
  2346. } while (EnumNextMultiSz (&e));
  2347. }
  2348. return result;
  2349. }
  2350. //
  2351. // Parse INI priority
  2352. //
  2353. if (StringIMatch (Type, TEXT("ForceDestIni"))) {
  2354. if (EnumFirstMultiSz (&e, SectionMultiSz)) {
  2355. do {
  2356. if (!pParseIniPriority (InfHandle, e.CurrentString, ACTION_PRIORITYDEST, Application)) {
  2357. result = FALSE;
  2358. if (InfStruct) {
  2359. InfLogContext (LOG_ERROR, InfHandle, InfStruct);
  2360. }
  2361. break;
  2362. }
  2363. } while (EnumNextMultiSz (&e));
  2364. }
  2365. return result;
  2366. }
  2367. if (StringIMatch (Type, TEXT("ForceSrcIni"))) {
  2368. if (EnumFirstMultiSz (&e, SectionMultiSz)) {
  2369. do {
  2370. if (!pParseIniPriority (InfHandle, e.CurrentString, ACTION_PRIORITYSRC, Application)) {
  2371. result = FALSE;
  2372. if (InfStruct) {
  2373. InfLogContext (LOG_ERROR, InfHandle, InfStruct);
  2374. }
  2375. break;
  2376. }
  2377. } while (EnumNextMultiSz (&e));
  2378. }
  2379. return result;
  2380. }
  2381. //
  2382. // Parse certificates priority
  2383. //
  2384. if (StringIMatch (Type, TEXT("ForceDestCert"))) {
  2385. if (EnumFirstMultiSz (&e, SectionMultiSz)) {
  2386. do {
  2387. if (!pParseCertPriority (InfHandle, e.CurrentString, ACTION_PRIORITYDEST, Application)) {
  2388. result = FALSE;
  2389. if (InfStruct) {
  2390. InfLogContext (LOG_ERROR, InfHandle, InfStruct);
  2391. }
  2392. break;
  2393. }
  2394. } while (EnumNextMultiSz (&e));
  2395. }
  2396. return result;
  2397. }
  2398. if (StringIMatch (Type, TEXT("ForceSrcCert"))) {
  2399. if (EnumFirstMultiSz (&e, SectionMultiSz)) {
  2400. do {
  2401. if (!pParseCertPriority (InfHandle, e.CurrentString, ACTION_PRIORITYSRC, Application)) {
  2402. result = FALSE;
  2403. if (InfStruct) {
  2404. InfLogContext (LOG_ERROR, InfHandle, InfStruct);
  2405. }
  2406. break;
  2407. }
  2408. } while (EnumNextMultiSz (&e));
  2409. }
  2410. return result;
  2411. }
  2412. //
  2413. // Parse file collision rules (default is %s(%d).%s)
  2414. //
  2415. if (StringIMatch (Type, TEXT("FileCollisionPattern"))) {
  2416. if (EnumFirstMultiSz (&e, SectionMultiSz)) {
  2417. do {
  2418. if (!pParseFileCollisionPattern (InfHandle, e.CurrentString, Application)) {
  2419. result = FALSE;
  2420. if (InfStruct) {
  2421. InfLogContext (LOG_ERROR, InfHandle, InfStruct);
  2422. }
  2423. break;
  2424. }
  2425. } while (EnumNextMultiSz (&e));
  2426. }
  2427. return result;
  2428. }
  2429. //
  2430. // Parse restore callback rule
  2431. //
  2432. if (StringIMatch (Type, TEXT("RestoreCallback"))) {
  2433. if (!g_VcmMode) {
  2434. if (EnumFirstMultiSz (&e, SectionMultiSz)) {
  2435. do {
  2436. IsmAppendEnvironmentString (PLATFORM_SOURCE, NULL, S_ENV_DEST_RESTORE, e.CurrentString);
  2437. } while (EnumNextMultiSz (&e));
  2438. }
  2439. }
  2440. return result;
  2441. }
  2442. //
  2443. // Parse destination rule
  2444. //
  2445. if (StringIMatch (Type, TEXT("DestDelReg"))) {
  2446. if (!g_VcmMode) {
  2447. if (EnumFirstMultiSz (&e, SectionMultiSz)) {
  2448. do {
  2449. IsmAppendEnvironmentString (PLATFORM_SOURCE, NULL, S_ENV_DEST_DELREG, e.CurrentString);
  2450. } while (EnumNextMultiSz (&e));
  2451. }
  2452. }
  2453. return result;
  2454. }
  2455. if (StringIMatch (Type, TEXT("DestDelRegEx"))) {
  2456. if (!g_VcmMode) {
  2457. if (EnumFirstMultiSz (&e, SectionMultiSz)) {
  2458. do {
  2459. IsmAppendEnvironmentString (PLATFORM_SOURCE, NULL, S_ENV_DEST_DELREGEX, e.CurrentString);
  2460. } while (EnumNextMultiSz (&e));
  2461. }
  2462. }
  2463. return result;
  2464. }
  2465. //
  2466. // Parse destination detect rules
  2467. //
  2468. if (StringIMatch (Type, TEXT("DestCheckDetect"))) {
  2469. if (!g_VcmMode) {
  2470. if (EnumFirstMultiSz (&e, SectionMultiSz)) {
  2471. do {
  2472. IsmAppendEnvironmentString (PLATFORM_SOURCE, NULL, S_ENV_DEST_CHECKDETECT, e.CurrentString);
  2473. } while (EnumNextMultiSz (&e));
  2474. }
  2475. }
  2476. return result;
  2477. }
  2478. //
  2479. // Parse destination AddObject rule
  2480. //
  2481. if (StringIMatch (Type, TEXT("DestAddObject"))) {
  2482. if (!g_VcmMode) {
  2483. if (EnumFirstMultiSz (&e, SectionMultiSz)) {
  2484. do {
  2485. IsmAppendEnvironmentString (PLATFORM_SOURCE, NULL, S_ENV_DEST_ADDOBJECT, e.CurrentString);
  2486. } while (EnumNextMultiSz (&e));
  2487. }
  2488. }
  2489. return result;
  2490. }
  2491. //
  2492. // Parse execute rule
  2493. //
  2494. if (StringIMatch (Type, TEXT("Execute"))) {
  2495. if (!g_VcmMode) {
  2496. if (EnumFirstMultiSz (&e, SectionMultiSz)) {
  2497. do {
  2498. IsmAppendEnvironmentString (PLATFORM_SOURCE, NULL, S_ENV_SCRIPT_EXECUTE, e.CurrentString);
  2499. } while (EnumNextMultiSz (&e));
  2500. }
  2501. }
  2502. return result;
  2503. }
  2504. //
  2505. // Parse file priority
  2506. //
  2507. if (StringIMatch (Type, TEXT("ForceDestFile"))) {
  2508. if (EnumFirstMultiSz (&e, SectionMultiSz)) {
  2509. do {
  2510. if (IsmIsEnvironmentFlagSet (platform, NULL, S_ENV_ALL_FILES)) {
  2511. if (!pParseFilePriority (InfHandle, e.CurrentString, ACTION_PRIORITYDEST, Application)) {
  2512. result = FALSE;
  2513. if (InfStruct) {
  2514. InfLogContext (LOG_ERROR, InfHandle, InfStruct);
  2515. }
  2516. break;
  2517. }
  2518. } else {
  2519. LOG ((
  2520. LOG_INFORMATION,
  2521. (PCSTR) MSG_IGNORING_FILE_SECTION,
  2522. e.CurrentString
  2523. ));
  2524. }
  2525. } while (EnumNextMultiSz (&e));
  2526. }
  2527. return result;
  2528. }
  2529. if (StringIMatch (Type, TEXT("ForceSrcFile"))) {
  2530. if (EnumFirstMultiSz (&e, SectionMultiSz)) {
  2531. do {
  2532. if (IsmIsEnvironmentFlagSet (platform, NULL, S_ENV_ALL_FILES)) {
  2533. if (!pParseFilePriority (InfHandle, e.CurrentString, ACTION_PRIORITYSRC, Application)) {
  2534. result = FALSE;
  2535. if (InfStruct) {
  2536. InfLogContext (LOG_ERROR, InfHandle, InfStruct);
  2537. }
  2538. break;
  2539. }
  2540. } else {
  2541. LOG ((
  2542. LOG_INFORMATION,
  2543. (PCSTR) MSG_IGNORING_FILE_SECTION,
  2544. e.CurrentString
  2545. ));
  2546. }
  2547. } while (EnumNextMultiSz (&e));
  2548. }
  2549. return result;
  2550. }
  2551. //
  2552. // Parse special conversion
  2553. //
  2554. if (StringIMatch (Type, TEXT("Conversion"))) {
  2555. if (EnumFirstMultiSz (&e, SectionMultiSz)) {
  2556. do {
  2557. if (!DoRegistrySpecialConversion (InfHandle, e.CurrentString)) {
  2558. result = FALSE;
  2559. if (InfStruct) {
  2560. InfLogContext (LOG_ERROR, InfHandle, InfStruct);
  2561. }
  2562. break;
  2563. }
  2564. } while (EnumNextMultiSz (&e));
  2565. }
  2566. return result;
  2567. }
  2568. if (StringIMatch (Type, TEXT("RenRegFn"))) {
  2569. if (EnumFirstMultiSz (&e, SectionMultiSz)) {
  2570. do {
  2571. if (!DoRegistrySpecialRename (InfHandle, e.CurrentString)) {
  2572. result = FALSE;
  2573. if (InfStruct) {
  2574. InfLogContext (LOG_ERROR, InfHandle, InfStruct);
  2575. }
  2576. break;
  2577. }
  2578. } while (EnumNextMultiSz (&e));
  2579. }
  2580. return result;
  2581. }
  2582. //
  2583. // Parse enhanced renreg
  2584. //
  2585. actionGroup = ACTIONGROUP_NONE;
  2586. actionFlags = 0;
  2587. if (StringIMatch (Type, TEXT("AddRegEx"))) {
  2588. actionGroup = ACTIONGROUP_INCLUDEEX;
  2589. actionFlags = ACTION_PERSIST;
  2590. } else if (StringIMatch (Type, TEXT("RenRegEx"))) {
  2591. actionGroup = ACTIONGROUP_RENAMEEX;
  2592. actionFlags = ACTION_PERSIST;
  2593. } else if (StringIMatch (Type, TEXT("DelRegEx"))) {
  2594. actionGroup = ACTIONGROUP_EXCLUDEEX;
  2595. actionFlags = 0;
  2596. } else if (StringIMatch (Type, TEXT("RegFileEx"))) {
  2597. actionGroup = ACTIONGROUP_INCFILEEX;
  2598. actionFlags = ACTION_PERSIST_PATH_IN_DATA;
  2599. } else if (StringIMatch (Type, TEXT("RegFolderEx"))) {
  2600. actionGroup = ACTIONGROUP_INCFOLDEREX;
  2601. actionFlags = ACTION_PERSIST_PATH_IN_DATA;
  2602. } else if (StringIMatch (Type, TEXT("RegIconEx"))) {
  2603. actionGroup = ACTIONGROUP_INCICONEX;
  2604. actionFlags = ACTION_PERSIST_ICON_IN_DATA;
  2605. }
  2606. if (actionGroup != ACTIONGROUP_NONE) {
  2607. if (EnumFirstMultiSz (&e, SectionMultiSz)) {
  2608. do {
  2609. if (!pParseRegEx (InfHandle, e.CurrentString, actionGroup, actionFlags, Application)) {
  2610. result = FALSE;
  2611. if (InfStruct) {
  2612. InfLogContext (LOG_ERROR, InfHandle, InfStruct);
  2613. }
  2614. break;
  2615. }
  2616. } while (EnumNextMultiSz (&e));
  2617. }
  2618. return result;
  2619. }
  2620. if (StringIMatch (Type, TEXT("LockPartition"))) {
  2621. if (EnumFirstMultiSz (&e, SectionMultiSz)) {
  2622. do {
  2623. if (!pParseLockPartition (InfHandle, e.CurrentString)) {
  2624. result = FALSE;
  2625. if (InfStruct) {
  2626. InfLogContext (LOG_ERROR, InfHandle, InfStruct);
  2627. }
  2628. break;
  2629. }
  2630. } while (EnumNextMultiSz (&e));
  2631. }
  2632. return result;
  2633. }
  2634. //
  2635. // Unknown section type
  2636. //
  2637. LOG ((LOG_ERROR, (PCSTR) MSG_UNEXPECTED_SECTION_TYPE, Type));
  2638. if (InfStruct) {
  2639. InfLogContext (LOG_ERROR, InfHandle, InfStruct);
  2640. }
  2641. return FALSE;
  2642. }
  2643. BOOL
  2644. pParseInfInstructionsWorker (
  2645. IN PINFSTRUCT InfStruct,
  2646. IN HINF InfHandle,
  2647. IN PCTSTR Application, OPTIONAL
  2648. IN PCTSTR Section
  2649. )
  2650. {
  2651. PCTSTR type;
  2652. PCTSTR sections;
  2653. GROWBUFFER multiSz = INIT_GROWBUFFER;
  2654. BOOL result = TRUE;
  2655. if (InfFindFirstLine (InfHandle, Section, NULL, InfStruct)) {
  2656. do {
  2657. if (IsmCheckCancel()) {
  2658. result = FALSE;
  2659. break;
  2660. }
  2661. InfResetInfStruct (InfStruct);
  2662. type = InfGetStringField (InfStruct, 0);
  2663. sections = InfGetMultiSzField (InfStruct, 1);
  2664. if (!type || !sections) {
  2665. LOG ((LOG_WARNING, (PCSTR) MSG_BAD_INF_LINE, Section));
  2666. InfLogContext (LOG_WARNING, InfHandle, InfStruct);
  2667. continue;
  2668. }
  2669. result = pParseOneInstruction (InfHandle, type, sections, InfStruct, Application);
  2670. } while (result && InfFindNextLine (InfStruct));
  2671. }
  2672. InfCleanUpInfStruct (InfStruct);
  2673. GbFree (&multiSz);
  2674. return result;
  2675. }
  2676. BOOL
  2677. ParseInfInstructions (
  2678. IN HINF InfHandle,
  2679. IN PCTSTR Application, OPTIONAL
  2680. IN PCTSTR Section
  2681. )
  2682. {
  2683. PCTSTR osSpecificSection;
  2684. BOOL b;
  2685. INFSTRUCT is = INITINFSTRUCT_PMHANDLE;
  2686. PTSTR instrSection;
  2687. b = pParseInfInstructionsWorker (&is, InfHandle, Application, Section);
  2688. if (b) {
  2689. osSpecificSection = GetMostSpecificSection (PLATFORM_SOURCE, &is, InfHandle, Section);
  2690. if (osSpecificSection) {
  2691. b = pParseInfInstructionsWorker (&is, InfHandle, Application, osSpecificSection);
  2692. FreeText (osSpecificSection);
  2693. }
  2694. }
  2695. InfCleanUpInfStruct (&is);
  2696. return b;
  2697. }
  2698. BOOL
  2699. pParseInf (
  2700. IN HINF InfHandle,
  2701. IN BOOL PreParse
  2702. )
  2703. {
  2704. BOOL result = TRUE;
  2705. if (InfHandle == INVALID_HANDLE_VALUE) {
  2706. return FALSE;
  2707. }
  2708. //
  2709. // Process the application sections
  2710. //
  2711. if (!ParseApplications (PLATFORM_SOURCE, InfHandle, TEXT("Applications"), PreParse, MASTERGROUP_APP)) {
  2712. LOG ((LOG_FATAL_ERROR, (PCSTR) MSG_APP_PARSE_FAILURE));
  2713. IsmSetCancel();
  2714. return FALSE;
  2715. }
  2716. //
  2717. // Process system settings
  2718. //
  2719. if (!ParseApplications (PLATFORM_SOURCE, InfHandle, TEXT("System Settings"), PreParse, MASTERGROUP_SYSTEM)) {
  2720. LOG ((LOG_FATAL_ERROR, (PCSTR) MSG_SYSTEM_PARSE_FAILURE));
  2721. IsmSetCancel();
  2722. return FALSE;
  2723. }
  2724. //
  2725. // Process user settings
  2726. //
  2727. if (!ParseApplications (PLATFORM_SOURCE, InfHandle, TEXT("User Settings"), PreParse, MASTERGROUP_USER)) {
  2728. LOG ((LOG_FATAL_ERROR, (PCSTR) MSG_USER_PARSE_FAILURE));
  2729. IsmSetCancel();
  2730. return FALSE;
  2731. }
  2732. //
  2733. // Process files and folders settings
  2734. //
  2735. if (!ProcessFilesAndFolders (InfHandle, TEXT("Files and Folders"), PreParse)) {
  2736. LOG ((LOG_FATAL_ERROR, (PCSTR) MSG_FNF_PARSE_FAILURE));
  2737. IsmSetCancel();
  2738. return FALSE;
  2739. }
  2740. //
  2741. // Process the administrator script sections
  2742. //
  2743. if (!ParseApplications (PLATFORM_SOURCE, InfHandle, TEXT("Administrator Scripts"), PreParse, MASTERGROUP_SCRIPT)) {
  2744. LOG ((LOG_FATAL_ERROR, (PCSTR) MSG_SCRIPT_PARSE_FAILURE));
  2745. IsmSetCancel();
  2746. return FALSE;
  2747. }
  2748. return TRUE;
  2749. }
  2750. BOOL
  2751. pAddFileSpec (
  2752. IN PCTSTR Node, OPTIONAL
  2753. IN PCTSTR Leaf, OPTIONAL
  2754. IN BOOL IncludeSubDirs,
  2755. IN BOOL LeafIsPattern,
  2756. IN ACTIONGROUP ActionGroup,
  2757. IN DWORD ActionFlags,
  2758. IN BOOL DefaultPriority,
  2759. IN BOOL SrcPriority
  2760. )
  2761. {
  2762. MIG_OBJECTSTRINGHANDLE srcHandle = NULL;
  2763. MIG_OBJECTSTRINGHANDLE srcBaseHandle = NULL;
  2764. BOOL result = FALSE;
  2765. ACTION_STRUCT actionStruct;
  2766. __try {
  2767. //
  2768. // Build object string
  2769. //
  2770. MYASSERT (Node || Leaf);
  2771. srcHandle = IsmCreateSimpleObjectPattern (Node, IncludeSubDirs, Leaf, LeafIsPattern);
  2772. if (!srcHandle) {
  2773. __leave;
  2774. }
  2775. if (Node) {
  2776. srcBaseHandle = IsmCreateObjectHandle (Node, NULL);
  2777. }
  2778. //
  2779. // Add this rule
  2780. //
  2781. ZeroMemory (&actionStruct, sizeof (ACTION_STRUCT));
  2782. actionStruct.ObjectBase = srcBaseHandle;
  2783. if (!AddRule (
  2784. g_FileType,
  2785. actionStruct.ObjectBase,
  2786. srcHandle,
  2787. ActionGroup,
  2788. ActionFlags,
  2789. &actionStruct
  2790. )) {
  2791. __leave;
  2792. }
  2793. if (!DefaultPriority) {
  2794. AddRuleEx (
  2795. g_FileType,
  2796. actionStruct.ObjectBase,
  2797. srcHandle,
  2798. ACTIONGROUP_SPECIFICPRIORITY,
  2799. SrcPriority?ACTION_PRIORITYSRC:ACTION_PRIORITYDEST,
  2800. NULL,
  2801. RULEGROUP_PRIORITY
  2802. );
  2803. IsmHookEnumeration (
  2804. g_RegType,
  2805. srcHandle,
  2806. ObjectPriority,
  2807. 0,
  2808. NULL
  2809. );
  2810. }
  2811. //
  2812. // Queue enumeration for include patterns
  2813. //
  2814. if (ActionGroup == ACTIONGROUP_INCLUDE) {
  2815. if (IsmIsObjectHandleLeafOnly (srcHandle)) {
  2816. DEBUGMSG ((
  2817. DBG_SCRIPT,
  2818. "File node %s leaf %s triggered enumeration of entire file system",
  2819. Node,
  2820. Leaf
  2821. ));
  2822. QueueAllFiles (g_VcmMode);
  2823. IsmHookEnumeration (
  2824. g_FileType,
  2825. srcHandle,
  2826. g_VcmMode ? GatherVirtualComputer : PrepareActions,
  2827. 0,
  2828. NULL
  2829. );
  2830. } else {
  2831. IsmQueueEnumeration (
  2832. g_FileType,
  2833. srcHandle,
  2834. g_VcmMode ? GatherVirtualComputer : PrepareActions,
  2835. 0,
  2836. NULL
  2837. );
  2838. }
  2839. }
  2840. result = TRUE;
  2841. }
  2842. __finally {
  2843. IsmDestroyObjectHandle (srcHandle);
  2844. INVALID_POINTER (srcHandle);
  2845. IsmDestroyObjectHandle (srcBaseHandle);
  2846. INVALID_POINTER (srcBaseHandle);
  2847. }
  2848. return result;
  2849. }
  2850. BOOL
  2851. pParseFilesAndFolders (
  2852. IN UINT Group,
  2853. IN ACTIONGROUP ActionGroup,
  2854. IN DWORD ActionFlags,
  2855. IN BOOL HasNode,
  2856. IN BOOL HasLeaf,
  2857. IN BOOL HasPriority
  2858. )
  2859. {
  2860. MIG_COMPONENT_ENUM e;
  2861. BOOL result = FALSE;
  2862. PCTSTR node;
  2863. PCTSTR leaf;
  2864. PTSTR copyOfData = NULL;
  2865. PTSTR p;
  2866. BOOL defaultPriority = TRUE;
  2867. BOOL srcPriority = FALSE;
  2868. __try {
  2869. //
  2870. // Enumerate all the components
  2871. //
  2872. if (IsmEnumFirstComponent (&e, COMPONENTENUM_ENABLED|COMPONENTENUM_ALIASES, Group)) {
  2873. do {
  2874. //
  2875. // Parse string into node/leaf format
  2876. //
  2877. if (e.MasterGroup != MASTERGROUP_FILES_AND_FOLDERS) {
  2878. continue;
  2879. }
  2880. copyOfData = DuplicateText (e.LocalizedAlias);
  2881. node = copyOfData;
  2882. leaf = NULL;
  2883. if (HasNode && HasLeaf) {
  2884. p = (PTSTR) FindLastWack (copyOfData);
  2885. if (p) {
  2886. leaf = _tcsinc (p);
  2887. *p = 0;
  2888. }
  2889. } else if (!HasNode) {
  2890. node = NULL;
  2891. leaf = JoinText (TEXT("*."), copyOfData);
  2892. }
  2893. //
  2894. // Add rule
  2895. //
  2896. if (!pAddFileSpec (
  2897. node,
  2898. leaf,
  2899. (HasNode && (!HasLeaf)),
  2900. (HasNode && (!HasLeaf)) || (!HasNode),
  2901. ActionGroup,
  2902. ActionFlags,
  2903. defaultPriority,
  2904. srcPriority
  2905. )) {
  2906. IsmAbortComponentEnum (&e);
  2907. __leave;
  2908. }
  2909. if (!HasNode) {
  2910. FreeText (leaf);
  2911. }
  2912. FreeText (copyOfData);
  2913. copyOfData = NULL;
  2914. } while (IsmEnumNextComponent (&e));
  2915. }
  2916. result = TRUE;
  2917. }
  2918. __finally {
  2919. FreeText (copyOfData);
  2920. if (!result) {
  2921. IsmAbortComponentEnum (&e);
  2922. }
  2923. }
  2924. return result;
  2925. }
  2926. BOOL
  2927. pSelectFilesAndFolders (
  2928. VOID
  2929. )
  2930. {
  2931. if (!pParseFilesAndFolders (
  2932. COMPONENT_EXTENSION,
  2933. ACTIONGROUP_INCLUDE,
  2934. ACTION_PERSIST,
  2935. FALSE,
  2936. TRUE,
  2937. TRUE
  2938. )) {
  2939. return FALSE;
  2940. }
  2941. if (!pParseFilesAndFolders (
  2942. COMPONENT_FOLDER,
  2943. ACTIONGROUP_INCLUDE,
  2944. ACTION_PERSIST,
  2945. TRUE,
  2946. FALSE,
  2947. TRUE
  2948. )) {
  2949. return FALSE;
  2950. }
  2951. if (!pParseFilesAndFolders (
  2952. COMPONENT_FILE,
  2953. ACTIONGROUP_INCLUDE,
  2954. ACTION_PERSIST,
  2955. TRUE,
  2956. TRUE,
  2957. TRUE
  2958. )) {
  2959. return FALSE;
  2960. }
  2961. return TRUE;
  2962. }
  2963. BOOL
  2964. pParseAllInfs (
  2965. IN BOOL PreParse
  2966. )
  2967. {
  2968. PTSTR multiSz = NULL;
  2969. MULTISZ_ENUM e;
  2970. UINT sizeNeeded;
  2971. HINF infHandle = INVALID_HANDLE_VALUE;
  2972. ENVENTRY_TYPE dataType;
  2973. BOOL result = FALSE;
  2974. if (IsmGetEnvironmentValue (
  2975. IsmGetRealPlatform (),
  2976. NULL,
  2977. S_GLOBAL_INF_HANDLE,
  2978. (PBYTE)(&infHandle),
  2979. sizeof (HINF),
  2980. &sizeNeeded,
  2981. &dataType
  2982. ) &&
  2983. (sizeNeeded == sizeof (HINF)) &&
  2984. (dataType == ENVENTRY_BINARY)
  2985. ) {
  2986. if (pParseInf (infHandle, PreParse)) {
  2987. result = TRUE;
  2988. }
  2989. InfNameHandle (infHandle, NULL, FALSE);
  2990. } else {
  2991. if (!IsmGetEnvironmentValue (IsmGetRealPlatform (), NULL, S_INF_FILE_MULTISZ, NULL, 0, &sizeNeeded, NULL)) {
  2992. return TRUE; // no INF files specified
  2993. }
  2994. __try {
  2995. multiSz = AllocText (sizeNeeded);
  2996. if (!multiSz) {
  2997. __leave;
  2998. }
  2999. if (!IsmGetEnvironmentValue (IsmGetRealPlatform (), NULL, S_INF_FILE_MULTISZ, (PBYTE) multiSz, sizeNeeded, NULL, NULL)) {
  3000. __leave;
  3001. }
  3002. if (EnumFirstMultiSz (&e, multiSz)) {
  3003. do {
  3004. infHandle = InfOpenInfFile (e.CurrentString);
  3005. if (infHandle != INVALID_HANDLE_VALUE) {
  3006. if (!pParseInf (infHandle, PreParse)) {
  3007. InfCloseInfFile (infHandle);
  3008. infHandle = INVALID_HANDLE_VALUE;
  3009. __leave;
  3010. }
  3011. } else {
  3012. LOG ((LOG_ERROR, (PCSTR) MSG_CANT_OPEN_INF, e.CurrentString));
  3013. }
  3014. InfCloseInfFile (infHandle);
  3015. infHandle = INVALID_HANDLE_VALUE;
  3016. } while (EnumNextMultiSz (&e));
  3017. }
  3018. result = TRUE;
  3019. }
  3020. __finally {
  3021. if (multiSz) {
  3022. FreeText (multiSz);
  3023. multiSz = NULL;
  3024. }
  3025. }
  3026. }
  3027. return result;
  3028. }