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.

1714 lines
48 KiB

  1. /*++
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. modules.c
  5. Abstract:
  6. Implements routines that are common to the entire ISM.
  7. Author:
  8. Jim Schmidt (jimschm) 21-Mar-2000
  9. Revision History:
  10. <alias> <date> <comments>
  11. --*/
  12. //
  13. // Includes
  14. //
  15. #include "pch.h"
  16. #include "ism.h"
  17. #include "ismp.h"
  18. #define DBG_ISM "Ism"
  19. //
  20. // Strings
  21. //
  22. // None
  23. //
  24. // Constants
  25. //
  26. // None
  27. //
  28. // Macros
  29. //
  30. // None
  31. //
  32. // Types
  33. //
  34. typedef struct {
  35. UINT RefCount;
  36. HMODULE Handle;
  37. } MODULEDATA, *PMODULEDATA;
  38. //
  39. // Globals
  40. //
  41. HASHTABLE g_ModuleTable;
  42. HASHTABLE g_EtmTable;
  43. HASHTABLE g_VcmTable;
  44. HASHTABLE g_SgmTable;
  45. HASHTABLE g_SamTable;
  46. HASHTABLE g_DgmTable;
  47. HASHTABLE g_DamTable;
  48. HASHTABLE g_CsmTable;
  49. HASHTABLE g_OpmTable;
  50. //
  51. // Macro expansion list
  52. //
  53. // None
  54. //
  55. // Private function prototypes
  56. //
  57. VOID
  58. pFreeEtmTable (
  59. VOID
  60. );
  61. //
  62. // Macro expansion definition
  63. //
  64. // None
  65. //
  66. // Code
  67. //
  68. VOID
  69. pFindModule (
  70. IN PCTSTR ModulePath,
  71. OUT PTSTR FullModulePath
  72. )
  73. {
  74. HANDLE result = NULL;
  75. TCHAR relativePath[MAX_PATH] = TEXT("");
  76. PCTSTR fileName;
  77. PTSTR p;
  78. fileName = GetFileNameFromPath (ModulePath);
  79. if (fileName) {
  80. if (GetModuleFileName (g_hInst, relativePath, ARRAYSIZE(relativePath))) {
  81. p = _tcsrchr (relativePath, TEXT('\\'));
  82. if (p) {
  83. p++;
  84. StringCopyByteCount (
  85. p,
  86. fileName,
  87. sizeof (relativePath) - (HALF_PTR) ((PBYTE) p - (PBYTE) relativePath)
  88. );
  89. }
  90. if (DoesFileExist (relativePath)) {
  91. StringCopy (FullModulePath, relativePath);
  92. return;
  93. }
  94. }
  95. }
  96. GetFullPathName (ModulePath, ARRAYSIZE(relativePath), relativePath, (PTSTR *) &fileName);
  97. if (DoesFileExist (relativePath)) {
  98. StringCopy (FullModulePath, relativePath);
  99. return;
  100. }
  101. if (SearchPath (NULL, fileName, NULL, MAX_PATH, FullModulePath, &p)) {
  102. return;
  103. }
  104. StringCopy (FullModulePath, ModulePath);
  105. }
  106. PMODULEDATA
  107. pGetModuleData (
  108. IN PCTSTR ModulePath
  109. )
  110. {
  111. HASHITEM rc;
  112. PMODULEDATA moduleData;
  113. rc = HtFindStringEx (
  114. g_ModuleTable,
  115. ModulePath,
  116. &moduleData,
  117. FALSE
  118. );
  119. if (!rc) {
  120. return NULL;
  121. }
  122. return moduleData;
  123. }
  124. BOOL
  125. pRegisterModule (
  126. IN PCTSTR ModulePath,
  127. IN HMODULE ModuleHandle
  128. )
  129. {
  130. PMODULEDATA moduleData;
  131. PMODULEINITIALIZE moduleInitialize = NULL;
  132. BOOL result = TRUE;
  133. moduleData = pGetModuleData (ModulePath);
  134. if (moduleData) {
  135. if (moduleData->RefCount == 0) {
  136. moduleData->Handle = ModuleHandle;
  137. // time to call the initialization routine
  138. moduleInitialize = (PMODULEINITIALIZE) GetProcAddress (moduleData->Handle, "ModuleInitialize");
  139. if (moduleInitialize) {
  140. result = moduleInitialize ();
  141. }
  142. }
  143. MYASSERT (moduleData->Handle == ModuleHandle);
  144. moduleData->RefCount ++;
  145. } else {
  146. moduleData = (PMODULEDATA) PmGetMemory (g_IsmUntrackedPool, sizeof (MODULEDATA));
  147. ZeroMemory (moduleData, sizeof (MODULEDATA));
  148. moduleData->RefCount = 1;
  149. moduleData->Handle = ModuleHandle;
  150. // time to call the initialization routine
  151. moduleInitialize = (PMODULEINITIALIZE) GetProcAddress (moduleData->Handle, "ModuleInitialize");
  152. if (moduleInitialize) {
  153. result = moduleInitialize ();
  154. }
  155. HtAddStringEx (g_ModuleTable, ModulePath, &moduleData, FALSE);
  156. }
  157. return TRUE;
  158. }
  159. BOOL
  160. pUnregisterModule (
  161. IN PCTSTR ModulePath
  162. )
  163. {
  164. PMODULEDATA moduleData;
  165. PMODULETERMINATE moduleTerminate = NULL;
  166. moduleData = pGetModuleData (ModulePath);
  167. if (moduleData) {
  168. if (moduleData->RefCount) {
  169. moduleData->RefCount --;
  170. if (moduleData->RefCount == 0) {
  171. // time to call the termination routine
  172. moduleTerminate = (PMODULETERMINATE) GetProcAddress (moduleData->Handle, "ModuleTerminate");
  173. if (moduleTerminate) {
  174. moduleTerminate ();
  175. }
  176. FreeLibrary (moduleData->Handle);
  177. moduleData->Handle = NULL;
  178. }
  179. } else {
  180. DEBUGMSG ((DBG_WHOOPS, "Too many UnregisterModule called for %s", ModulePath));
  181. }
  182. }
  183. return TRUE;
  184. }
  185. VOID
  186. pFreeRegisteredModules (
  187. VOID
  188. )
  189. {
  190. PMODULEDATA moduleData;
  191. PMODULETERMINATE moduleTerminate = NULL;
  192. HASHTABLE_ENUM e;
  193. if (g_ModuleTable) {
  194. if (EnumFirstHashTableString (&e, g_ModuleTable)) {
  195. do {
  196. moduleData = *((PMODULEDATA *) e.ExtraData);
  197. if (moduleData) {
  198. if (moduleData->RefCount) {
  199. DEBUGMSG ((DBG_WHOOPS, "Registered module was not unregistered."));
  200. moduleData->RefCount = 0;
  201. moduleTerminate = (PMODULETERMINATE) GetProcAddress (moduleData->Handle, "ModuleTerminate");
  202. if (moduleTerminate) {
  203. moduleTerminate ();
  204. }
  205. FreeLibrary (moduleData->Handle);
  206. }
  207. }
  208. } while (EnumNextHashTableString (&e));
  209. }
  210. HtFree (g_ModuleTable);
  211. g_ModuleTable = NULL;
  212. }
  213. }
  214. BOOL
  215. pRegisterEtm (
  216. IN MIG_PLATFORMTYPEID Platform,
  217. IN PCTSTR ModuleId,
  218. IN PCTSTR ModulePath,
  219. IN PVOID Reserved
  220. )
  221. {
  222. PETMDATA etmData;
  223. HASHITEM rc;
  224. PTYPEMODULE queryTypeModule;
  225. TYPE_ENTRYPOINTS entryPoints;
  226. TCHAR fullModulePath[MAX_TCHAR_PATH];
  227. rc = HtFindString (g_EtmTable, ModuleId);
  228. if (rc) {
  229. return FALSE;
  230. }
  231. etmData = (PETMDATA) PmGetAlignedMemory (g_IsmUntrackedPool, sizeof (ETMDATA));
  232. ZeroMemory (etmData, sizeof (ETMDATA));
  233. pFindModule (ModulePath, fullModulePath);
  234. etmData->EtmPath = PmDuplicateString (g_IsmUntrackedPool, fullModulePath);
  235. etmData->LibHandle = LoadLibrary (fullModulePath);
  236. if (etmData->LibHandle) {
  237. queryTypeModule = (PTYPEMODULE) GetProcAddress (etmData->LibHandle, "TypeModule");
  238. if (queryTypeModule) {
  239. ZeroMemory (&entryPoints, sizeof (entryPoints));
  240. entryPoints.Version = ISM_VERSION;
  241. if (queryTypeModule (ModuleId, &entryPoints)) {
  242. etmData->EtmInitialize = entryPoints.EtmInitialize;
  243. etmData->EtmParse = entryPoints.EtmParse;
  244. etmData->EtmTerminate = entryPoints.EtmTerminate;
  245. etmData->EtmNewUserCreated = entryPoints.EtmNewUserCreated;
  246. if (etmData->EtmInitialize) {
  247. etmData->ShouldBeCalled = TRUE;
  248. }
  249. } else {
  250. LOG ((LOG_MODULE_ERROR, (PCSTR) MSG_DLL_DOES_NOT_SUPPORT_TAG, fullModulePath, ModuleId));
  251. }
  252. } else {
  253. LOG ((LOG_MODULE_ERROR, (PCSTR) MSG_ETM_ENTRYPOINT_MISSING, fullModulePath));
  254. }
  255. } else {
  256. LOG ((LOG_WARNING, (PCSTR) MSG_LOADLIBRARY_FAILURE, ModuleId));
  257. }
  258. if (etmData->ShouldBeCalled) {
  259. etmData->Group = PmDuplicateString (g_IsmUntrackedPool, ModuleId);
  260. HtAddStringEx (g_EtmTable, ModuleId, &etmData, FALSE);
  261. if (pRegisterModule (fullModulePath, etmData->LibHandle)) {
  262. MYASSERT (!g_CurrentGroup);
  263. g_CurrentGroup = ModuleId;
  264. if (!etmData->EtmInitialize (Platform, g_LogCallback, Reserved)) {
  265. LOG ((LOG_MODULE_ERROR, (PCSTR) MSG_MODULE_RETURNED_FAILURE, ModuleId));
  266. etmData->ShouldBeCalled = FALSE;
  267. }
  268. g_CurrentGroup = NULL;
  269. etmData->Initialized = TRUE;
  270. } else {
  271. etmData->ShouldBeCalled = FALSE;
  272. LOG ((LOG_MODULE_ERROR, (PCSTR) MSG_MODULEINIT_FAILURE, ModuleId));
  273. }
  274. }
  275. return etmData->ShouldBeCalled;
  276. }
  277. BOOL
  278. pRegisterVcm (
  279. IN PCTSTR ModuleId,
  280. IN PCTSTR ModulePath,
  281. IN PVOID Reserved
  282. )
  283. {
  284. PVCMDATA vcmData;
  285. HASHITEM rc;
  286. PVIRTUALCOMPUTERMODULE queryEntryPoints;
  287. VIRTUAL_COMPUTER_ENTRYPOINTS entryPoints;
  288. TCHAR fullModulePath[MAX_TCHAR_PATH];
  289. pFindModule (ModulePath, fullModulePath);
  290. rc = HtFindString (g_VcmTable, ModuleId);
  291. if (rc) {
  292. return FALSE;
  293. }
  294. vcmData = (PVCMDATA) PmGetAlignedMemory (g_IsmUntrackedPool, sizeof (VCMDATA));
  295. ZeroMemory (vcmData, sizeof (VCMDATA));
  296. vcmData->VcmPath = PmDuplicateString (g_IsmUntrackedPool, fullModulePath);
  297. vcmData->LibHandle = LoadLibrary (fullModulePath);
  298. if (vcmData->LibHandle) {
  299. queryEntryPoints = (PVIRTUALCOMPUTERMODULE) GetProcAddress (
  300. vcmData->LibHandle,
  301. "VirtualComputerModule"
  302. );
  303. if (queryEntryPoints) {
  304. ZeroMemory (&entryPoints, sizeof (entryPoints));
  305. entryPoints.Version = ISM_VERSION;
  306. if (queryEntryPoints (ModuleId, &entryPoints)) {
  307. vcmData->VcmInitialize = entryPoints.VcmInitialize;
  308. vcmData->VcmParse = entryPoints.VcmParse;
  309. vcmData->VcmQueueEnumeration = entryPoints.VcmQueueEnumeration;
  310. vcmData->VcmQueueHighPriorityEnumeration = entryPoints.VcmQueueHighPriorityEnumeration;
  311. vcmData->VcmTerminate = entryPoints.VcmTerminate;
  312. if (vcmData->VcmInitialize && vcmData->VcmQueueEnumeration) {
  313. vcmData->ShouldBeCalled = TRUE;
  314. }
  315. } else {
  316. LOG ((LOG_MODULE_ERROR, (PCSTR) MSG_DLL_DOES_NOT_SUPPORT_TAG, fullModulePath, ModuleId));
  317. }
  318. } else {
  319. LOG ((LOG_MODULE_ERROR, (PCSTR) MSG_VCM_ENTRYPOINT_MISSING, fullModulePath));
  320. }
  321. } else {
  322. LOG ((LOG_WARNING, (PCSTR) MSG_LOADLIBRARY_FAILURE, ModuleId));
  323. }
  324. if (vcmData->ShouldBeCalled) {
  325. vcmData->Group = PmDuplicateString (g_IsmUntrackedPool, ModuleId);
  326. HtAddStringEx (g_VcmTable, ModuleId, &vcmData, FALSE);
  327. if (pRegisterModule (fullModulePath, vcmData->LibHandle)) {
  328. MYASSERT (!g_CurrentGroup);
  329. g_CurrentGroup = ModuleId;
  330. if (!vcmData->VcmInitialize (g_LogCallback, Reserved)) {
  331. LOG ((LOG_MODULE_ERROR, (PCSTR) MSG_MODULE_RETURNED_FAILURE, ModuleId));
  332. vcmData->ShouldBeCalled = FALSE;
  333. }
  334. g_CurrentGroup = NULL;
  335. vcmData->Initialized = TRUE;
  336. } else {
  337. vcmData->ShouldBeCalled = FALSE;
  338. LOG ((LOG_MODULE_ERROR, (PCSTR) MSG_MODULEINIT_FAILURE, ModuleId));
  339. }
  340. }
  341. return vcmData->ShouldBeCalled;
  342. }
  343. BOOL
  344. pRegisterSm (
  345. IN PCTSTR ModuleId,
  346. IN PCTSTR ModulePath,
  347. IN PVOID Reserved
  348. )
  349. {
  350. PSGMDATA sgmData;
  351. PSAMDATA samData;
  352. HASHITEM rc;
  353. PSOURCEMODULE queryEntryPoints;
  354. SOURCE_ENTRYPOINTS entryPoints;
  355. TCHAR fullModulePath[MAX_TCHAR_PATH];
  356. pFindModule (ModulePath, fullModulePath);
  357. rc = HtFindString (g_SgmTable, ModuleId);
  358. if (!rc) {
  359. rc = HtFindString (g_SamTable, ModuleId);
  360. }
  361. if (rc) {
  362. return FALSE;
  363. }
  364. sgmData = (PSGMDATA) PmGetAlignedMemory (g_IsmUntrackedPool, sizeof (SGMDATA));
  365. ZeroMemory (sgmData, sizeof (SGMDATA));
  366. samData = (PSAMDATA) PmGetAlignedMemory (g_IsmUntrackedPool, sizeof (SAMDATA));
  367. ZeroMemory (samData, sizeof (SAMDATA));
  368. sgmData->SgmPath = PmDuplicateString (g_IsmUntrackedPool, fullModulePath);
  369. sgmData->LibHandle = LoadLibrary (fullModulePath);
  370. samData->SamPath = sgmData->SgmPath;
  371. samData->LibHandle = sgmData->LibHandle;
  372. if (sgmData->LibHandle) {
  373. queryEntryPoints = (PSOURCEMODULE) GetProcAddress (sgmData->LibHandle, "SourceModule");
  374. if (queryEntryPoints) {
  375. ZeroMemory (&entryPoints, sizeof (entryPoints));
  376. entryPoints.Version = ISM_VERSION;
  377. if (queryEntryPoints (ModuleId, &entryPoints)) {
  378. sgmData->SgmInitialize = entryPoints.SgmInitialize;
  379. sgmData->SgmParse = entryPoints.SgmParse;
  380. sgmData->SgmQueueEnumeration = entryPoints.SgmQueueEnumeration;
  381. sgmData->SgmQueueHighPriorityEnumeration = entryPoints.SgmQueueHighPriorityEnumeration;
  382. sgmData->SgmTerminate = entryPoints.SgmTerminate;
  383. if (sgmData->SgmInitialize && sgmData->SgmQueueEnumeration) {
  384. sgmData->ShouldBeCalled = TRUE;
  385. }
  386. samData->SamInitialize = entryPoints.SamInitialize;
  387. samData->SamExecute = entryPoints.SamExecute;
  388. samData->SamEstimateProgressBar = entryPoints.SamEstimateProgressBar;
  389. samData->SamTerminate = entryPoints.SamTerminate;
  390. if (samData->SamInitialize && samData->SamExecute) {
  391. samData->ShouldBeCalled = TRUE;
  392. }
  393. } else {
  394. LOG ((LOG_MODULE_ERROR, (PCSTR) MSG_DLL_DOES_NOT_SUPPORT_TAG, fullModulePath, ModuleId));
  395. }
  396. } else {
  397. LOG ((LOG_MODULE_ERROR, (PCSTR) MSG_SOURCE_ENTRYPOINT_MISSING, fullModulePath));
  398. }
  399. } else {
  400. LOG ((LOG_WARNING, (PCSTR) MSG_LOADLIBRARY_FAILURE, ModuleId));
  401. }
  402. if (sgmData->ShouldBeCalled) {
  403. sgmData->Group = PmDuplicateString (g_IsmUntrackedPool, ModuleId);
  404. HtAddStringEx (g_SgmTable, ModuleId, &sgmData, FALSE);
  405. if (pRegisterModule (fullModulePath, sgmData->LibHandle)) {
  406. MYASSERT (!g_CurrentGroup);
  407. g_CurrentGroup = ModuleId;
  408. if (!sgmData->SgmInitialize (g_LogCallback, Reserved)) {
  409. LOG ((LOG_MODULE_ERROR, (PCSTR) MSG_MODULE_RETURNED_FAILURE, ModuleId));
  410. sgmData->ShouldBeCalled = FALSE;
  411. }
  412. g_CurrentGroup = NULL;
  413. sgmData->Initialized = TRUE;
  414. } else {
  415. sgmData->ShouldBeCalled = FALSE;
  416. LOG ((LOG_MODULE_ERROR, (PCSTR) MSG_MODULEINIT_FAILURE, ModuleId));
  417. }
  418. }
  419. if (samData->ShouldBeCalled) {
  420. samData->Group = PmDuplicateString (g_IsmUntrackedPool, ModuleId);
  421. HtAddStringEx (g_SamTable, ModuleId, &samData, FALSE);
  422. if (pRegisterModule (fullModulePath, samData->LibHandle)) {
  423. MYASSERT (!g_CurrentGroup);
  424. g_CurrentGroup = ModuleId;
  425. if (!samData->SamInitialize (g_LogCallback, Reserved)) {
  426. LOG ((LOG_MODULE_ERROR, (PCSTR) MSG_MODULE_RETURNED_FAILURE, ModuleId));
  427. samData->ShouldBeCalled = FALSE;
  428. }
  429. g_CurrentGroup = NULL;
  430. samData->Initialized = TRUE;
  431. } else {
  432. samData->ShouldBeCalled = FALSE;
  433. LOG ((LOG_MODULE_ERROR, (PCSTR) MSG_MODULEINIT_FAILURE, ModuleId));
  434. }
  435. }
  436. return sgmData->ShouldBeCalled || samData->ShouldBeCalled;
  437. }
  438. BOOL
  439. pRegisterDm (
  440. IN PCTSTR ModuleId,
  441. IN PCTSTR ModulePath,
  442. IN PVOID Reserved
  443. )
  444. {
  445. PDAMDATA damData;
  446. PDGMDATA dgmData;
  447. PCSMDATA csmData;
  448. POPMDATA opmData;
  449. HASHITEM rc;
  450. PDESTINATIONMODULE queryEntryPoints;
  451. DESTINATION_ENTRYPOINTS entryPoints;
  452. TCHAR fullModulePath[MAX_TCHAR_PATH];
  453. pFindModule (ModulePath, fullModulePath);
  454. rc = HtFindString (g_DgmTable, ModuleId);
  455. if (!rc) {
  456. rc = HtFindString (g_DamTable, ModuleId);
  457. }
  458. if (!rc) {
  459. rc = HtFindString (g_CsmTable, ModuleId);
  460. }
  461. if (!rc) {
  462. rc = HtFindString (g_OpmTable, ModuleId);
  463. }
  464. if (rc) {
  465. return FALSE;
  466. }
  467. dgmData = (PDGMDATA) PmGetAlignedMemory (g_IsmUntrackedPool, sizeof (DGMDATA));
  468. ZeroMemory (dgmData, sizeof (DGMDATA));
  469. dgmData->DgmPath = PmDuplicateString (g_IsmUntrackedPool, fullModulePath);
  470. dgmData->LibHandle = LoadLibrary (fullModulePath);
  471. damData = (PDAMDATA) PmGetAlignedMemory (g_IsmUntrackedPool, sizeof (DAMDATA));
  472. ZeroMemory (damData, sizeof (DAMDATA));
  473. damData->DamPath = dgmData->DgmPath;
  474. damData->LibHandle = dgmData->LibHandle;
  475. csmData = (PCSMDATA) PmGetAlignedMemory (g_IsmUntrackedPool, sizeof (CSMDATA));
  476. ZeroMemory (csmData, sizeof (CSMDATA));
  477. csmData->CsmPath = dgmData->DgmPath;
  478. csmData->LibHandle = dgmData->LibHandle;
  479. opmData = (POPMDATA) PmGetAlignedMemory (g_IsmUntrackedPool, sizeof (OPMDATA));
  480. ZeroMemory (opmData, sizeof (OPMDATA));
  481. opmData->OpmPath = dgmData->DgmPath;
  482. opmData->LibHandle = dgmData->LibHandle;
  483. if (dgmData->LibHandle) {
  484. queryEntryPoints = (PDESTINATIONMODULE) GetProcAddress (dgmData->LibHandle, "DestinationModule");
  485. if (queryEntryPoints) {
  486. ZeroMemory (&entryPoints, sizeof (entryPoints));
  487. entryPoints.Version = ISM_VERSION;
  488. if (queryEntryPoints (ModuleId, &entryPoints)) {
  489. dgmData->DgmInitialize = entryPoints.DgmInitialize;
  490. dgmData->DgmQueueEnumeration = entryPoints.DgmQueueEnumeration;
  491. dgmData->DgmQueueHighPriorityEnumeration = entryPoints.DgmQueueHighPriorityEnumeration;
  492. dgmData->DgmTerminate = entryPoints.DgmTerminate;
  493. if (dgmData->DgmInitialize && dgmData->DgmQueueEnumeration) {
  494. dgmData->ShouldBeCalled = TRUE;
  495. }
  496. damData->DamInitialize = entryPoints.DamInitialize;
  497. damData->DamExecute = entryPoints.DamExecute;
  498. damData->DamEstimateProgressBar = entryPoints.DamEstimateProgressBar;
  499. damData->DamTerminate = entryPoints.DamTerminate;
  500. if (damData->DamInitialize && damData->DamExecute) {
  501. damData->ShouldBeCalled = TRUE;
  502. }
  503. csmData->CsmInitialize = entryPoints.CsmInitialize;
  504. csmData->CsmExecute = entryPoints.CsmExecute;
  505. csmData->CsmEstimateProgressBar = entryPoints.CsmEstimateProgressBar;
  506. csmData->CsmTerminate = entryPoints.CsmTerminate;
  507. if (csmData->CsmInitialize && csmData->CsmExecute) {
  508. csmData->ShouldBeCalled = TRUE;
  509. }
  510. opmData->OpmInitialize = entryPoints.OpmInitialize;
  511. opmData->OpmTerminate = entryPoints.OpmTerminate;
  512. if (opmData->OpmInitialize) {
  513. opmData->ShouldBeCalled = TRUE;
  514. }
  515. }
  516. } else {
  517. LOG ((LOG_MODULE_ERROR, (PCSTR) MSG_DEST_ENTRYPOINT_MISSING, fullModulePath));
  518. }
  519. } else {
  520. LOG ((LOG_WARNING, (PCSTR) MSG_LOADLIBRARY_FAILURE, ModuleId));
  521. }
  522. if (dgmData->ShouldBeCalled) {
  523. dgmData->Group = PmDuplicateString (g_IsmUntrackedPool, ModuleId);
  524. HtAddStringEx (g_DgmTable, ModuleId, &dgmData, FALSE);
  525. if (pRegisterModule (fullModulePath, dgmData->LibHandle)) {
  526. MYASSERT (!g_CurrentGroup);
  527. g_CurrentGroup = ModuleId;
  528. if (!dgmData->DgmInitialize (g_LogCallback, Reserved)) {
  529. LOG ((LOG_MODULE_ERROR, (PCSTR) MSG_MODULE_RETURNED_FAILURE, ModuleId));
  530. dgmData->ShouldBeCalled = FALSE;
  531. }
  532. g_CurrentGroup = NULL;
  533. dgmData->Initialized = TRUE;
  534. } else {
  535. dgmData->ShouldBeCalled = FALSE;
  536. LOG ((LOG_MODULE_ERROR, (PCSTR) MSG_MODULEINIT_FAILURE, ModuleId));
  537. }
  538. }
  539. if (damData->ShouldBeCalled) {
  540. damData->Group = PmDuplicateString (g_IsmUntrackedPool, ModuleId);
  541. HtAddStringEx (g_DamTable, ModuleId, &damData, FALSE);
  542. if (pRegisterModule (fullModulePath, damData->LibHandle)) {
  543. MYASSERT (!g_CurrentGroup);
  544. g_CurrentGroup = ModuleId;
  545. if (!damData->DamInitialize (g_LogCallback, Reserved)) {
  546. LOG ((LOG_MODULE_ERROR, (PCSTR) MSG_MODULE_RETURNED_FAILURE, ModuleId));
  547. damData->ShouldBeCalled = FALSE;
  548. }
  549. g_CurrentGroup = NULL;
  550. damData->Initialized = TRUE;
  551. } else {
  552. damData->ShouldBeCalled = FALSE;
  553. LOG ((LOG_MODULE_ERROR, (PCSTR) MSG_MODULEINIT_FAILURE, ModuleId));
  554. }
  555. }
  556. if (csmData->ShouldBeCalled) {
  557. csmData->Group = PmDuplicateString (g_IsmUntrackedPool, ModuleId);
  558. HtAddStringEx (g_CsmTable, ModuleId, &csmData, FALSE);
  559. if (pRegisterModule (fullModulePath, csmData->LibHandle)) {
  560. MYASSERT (!g_CurrentGroup);
  561. g_CurrentGroup = ModuleId;
  562. if (!csmData->CsmInitialize (g_LogCallback, Reserved)) {
  563. LOG ((LOG_MODULE_ERROR, (PCSTR) MSG_MODULE_RETURNED_FAILURE, ModuleId));
  564. csmData->ShouldBeCalled = FALSE;
  565. }
  566. g_CurrentGroup = NULL;
  567. csmData->Initialized = TRUE;
  568. } else {
  569. csmData->ShouldBeCalled = FALSE;
  570. LOG ((LOG_MODULE_ERROR, (PCSTR) MSG_MODULEINIT_FAILURE, ModuleId));
  571. }
  572. }
  573. if (opmData->ShouldBeCalled) {
  574. opmData->Group = PmDuplicateString (g_IsmUntrackedPool, ModuleId);
  575. HtAddStringEx (g_OpmTable, ModuleId, &opmData, FALSE);
  576. if (pRegisterModule (fullModulePath, opmData->LibHandle)) {
  577. MYASSERT (!g_CurrentGroup);
  578. g_CurrentGroup = ModuleId;
  579. if (!opmData->OpmInitialize (g_LogCallback, Reserved)) {
  580. LOG ((LOG_MODULE_ERROR, (PCSTR) MSG_MODULE_RETURNED_FAILURE, ModuleId));
  581. opmData->ShouldBeCalled = FALSE;
  582. }
  583. g_CurrentGroup = NULL;
  584. opmData->Initialized = TRUE;
  585. } else {
  586. opmData->ShouldBeCalled = FALSE;
  587. LOG ((LOG_MODULE_ERROR, (PCSTR) MSG_MODULEINIT_FAILURE, ModuleId));
  588. }
  589. }
  590. return dgmData->ShouldBeCalled ||
  591. damData->ShouldBeCalled ||
  592. csmData->ShouldBeCalled ||
  593. opmData->ShouldBeCalled;
  594. }
  595. BOOL
  596. pRegisterTransport (
  597. IN PCTSTR ModuleId,
  598. IN PCTSTR ModulePath,
  599. IN PVOID Reserved
  600. )
  601. {
  602. PTRANSPORTDATA transportData;
  603. HASHITEM rc;
  604. PTRANSPORTMODULE queryEntryPoints;
  605. TRANSPORT_ENTRYPOINTS entryPoints;
  606. TCHAR fullModulePath[MAX_TCHAR_PATH];
  607. pFindModule (ModulePath, fullModulePath);
  608. rc = HtFindString (g_TransportTable, ModuleId);
  609. if (rc) {
  610. return FALSE;
  611. }
  612. transportData = (PTRANSPORTDATA) PmGetAlignedMemory (g_IsmUntrackedPool, sizeof (TRANSPORTDATA));
  613. ZeroMemory (transportData, sizeof (TRANSPORTDATA));
  614. transportData->TransportPath = PmDuplicateString (g_IsmUntrackedPool, fullModulePath);
  615. transportData->LibHandle = LoadLibrary (fullModulePath);
  616. if (transportData->LibHandle) {
  617. queryEntryPoints = (PTRANSPORTMODULE) GetProcAddress (transportData->LibHandle, "TransportModule");
  618. if (queryEntryPoints) {
  619. ZeroMemory (&entryPoints, sizeof (entryPoints));
  620. entryPoints.Version = ISM_VERSION;
  621. if (queryEntryPoints (ModuleId, &entryPoints)) {
  622. transportData->TransportInitialize = entryPoints.TransportInitialize;
  623. transportData->TransportTerminate = entryPoints.TransportTerminate;
  624. transportData->TransportQueryCapabilities = entryPoints.TransportQueryCapabilities;
  625. transportData->TransportSetStorage = entryPoints.TransportSetStorage;
  626. transportData->TransportResetStorage = entryPoints.TransportResetStorage;
  627. transportData->TransportSaveState = entryPoints.TransportSaveState;
  628. transportData->TransportResumeSaveState = entryPoints.TransportResumeSaveState;
  629. transportData->TransportBeginApply = entryPoints.TransportBeginApply;
  630. transportData->TransportResumeApply = entryPoints.TransportResumeApply;
  631. transportData->TransportAcquireObject = entryPoints.TransportAcquireObject;
  632. transportData->TransportReleaseObject = entryPoints.TransportReleaseObject;
  633. transportData->TransportEndApply = entryPoints.TransportEndApply;
  634. transportData->TransportEstimateProgressBar = entryPoints.TransportEstimateProgressBar;
  635. if (transportData->TransportInitialize &&
  636. transportData->TransportTerminate &&
  637. transportData->TransportQueryCapabilities &&
  638. transportData->TransportSetStorage &&
  639. transportData->TransportSaveState &&
  640. transportData->TransportBeginApply &&
  641. transportData->TransportAcquireObject &&
  642. transportData->TransportReleaseObject &&
  643. transportData->TransportEndApply
  644. ) {
  645. transportData->ShouldBeCalled = TRUE;
  646. }
  647. }
  648. } else {
  649. LOG ((LOG_MODULE_ERROR, (PCSTR) MSG_TRANS_ENTRYPOINT_MISSING, fullModulePath));
  650. }
  651. } else {
  652. LOG ((LOG_WARNING, (PCSTR) MSG_LOADLIBRARY_FAILURE, ModuleId));
  653. }
  654. if (transportData->ShouldBeCalled) {
  655. transportData->Group = PmDuplicateString (g_IsmUntrackedPool, ModuleId);
  656. HtAddStringEx (g_TransportTable, ModuleId, &transportData, FALSE);
  657. if (pRegisterModule (fullModulePath, transportData->LibHandle)) {
  658. MYASSERT (!g_CurrentGroup);
  659. g_CurrentGroup = ModuleId;
  660. if (!transportData->TransportInitialize (g_LogCallback)) {
  661. LOG ((LOG_MODULE_ERROR, (PCSTR) MSG_MODULE_RETURNED_FAILURE, ModuleId));
  662. transportData->ShouldBeCalled = FALSE;
  663. }
  664. g_CurrentGroup = NULL;
  665. transportData->Initialized = TRUE;
  666. } else {
  667. transportData->ShouldBeCalled = FALSE;
  668. LOG ((LOG_MODULE_ERROR, (PCSTR) MSG_MODULEINIT_FAILURE, ModuleId));
  669. }
  670. }
  671. return transportData->ShouldBeCalled;
  672. }
  673. VOID
  674. pAllocModuleTables (
  675. VOID
  676. )
  677. {
  678. if (!g_VcmTable) {
  679. g_VcmTable = HtAllocWithData (sizeof (PVCMDATA));
  680. }
  681. if (!g_SgmTable) {
  682. g_SgmTable = HtAllocWithData (sizeof (PSGMDATA));
  683. }
  684. if (!g_SamTable) {
  685. g_SamTable = HtAllocWithData (sizeof (PSAMDATA));
  686. }
  687. if (!g_DgmTable) {
  688. g_DgmTable = HtAllocWithData (sizeof (PDGMDATA));
  689. }
  690. if (!g_DamTable) {
  691. g_DamTable = HtAllocWithData (sizeof (PDAMDATA));
  692. }
  693. if (!g_CsmTable) {
  694. g_CsmTable = HtAllocWithData (sizeof (PCSMDATA));
  695. }
  696. if (!g_OpmTable) {
  697. g_OpmTable = HtAllocWithData (sizeof (POPMDATA));
  698. }
  699. }
  700. VOID
  701. pFreeModuleTables (
  702. VOID
  703. )
  704. {
  705. HASHTABLE_ENUM e;
  706. POPMDATA opmData;
  707. PCSMDATA csmData;
  708. PDAMDATA damData;
  709. PDGMDATA dgmData;
  710. PSAMDATA samData;
  711. PSGMDATA sgmData;
  712. PVCMDATA vcmData;
  713. if (g_OpmTable) {
  714. if (EnumFirstHashTableString (&e, g_OpmTable)) {
  715. do {
  716. opmData = *((POPMDATA *) e.ExtraData);
  717. if (opmData) {
  718. if (opmData->Initialized && opmData->OpmTerminate) {
  719. opmData->OpmTerminate ();
  720. }
  721. if (opmData->OpmPath) {
  722. pUnregisterModule (opmData->OpmPath);
  723. // opmData->OpmPath is owned by DGM
  724. }
  725. }
  726. } while (EnumNextHashTableString (&e));
  727. }
  728. HtFree (g_OpmTable);
  729. g_OpmTable = NULL;
  730. }
  731. if (g_CsmTable) {
  732. if (EnumFirstHashTableString (&e, g_CsmTable)) {
  733. do {
  734. csmData = *((PCSMDATA *) e.ExtraData);
  735. if (csmData) {
  736. if (csmData->Initialized && csmData->CsmTerminate) {
  737. csmData->CsmTerminate ();
  738. }
  739. if (csmData->CsmPath) {
  740. pUnregisterModule (csmData->CsmPath);
  741. // csmData->CsmPath is owned by DGM
  742. }
  743. }
  744. } while (EnumNextHashTableString (&e));
  745. }
  746. HtFree (g_CsmTable);
  747. g_CsmTable = NULL;
  748. }
  749. if (g_DamTable) {
  750. if (EnumFirstHashTableString (&e, g_DamTable)) {
  751. do {
  752. damData = *((PDAMDATA *) e.ExtraData);
  753. if (damData) {
  754. if (damData->Initialized && damData->DamTerminate) {
  755. damData->DamTerminate ();
  756. }
  757. if (damData->DamPath) {
  758. pUnregisterModule (damData->DamPath);
  759. // damData->DamPath is owned by DGM
  760. }
  761. }
  762. } while (EnumNextHashTableString (&e));
  763. }
  764. HtFree (g_DamTable);
  765. g_DamTable = NULL;
  766. }
  767. if (g_DgmTable) {
  768. if (EnumFirstHashTableString (&e, g_DgmTable)) {
  769. do {
  770. dgmData = *((PDGMDATA *) e.ExtraData);
  771. if (dgmData) {
  772. if (dgmData->Initialized && dgmData->DgmTerminate) {
  773. dgmData->DgmTerminate ();
  774. }
  775. if (dgmData->DgmPath) {
  776. pUnregisterModule (dgmData->DgmPath);
  777. }
  778. }
  779. } while (EnumNextHashTableString (&e));
  780. }
  781. HtFree (g_DgmTable);
  782. g_DgmTable = NULL;
  783. }
  784. if (g_SamTable) {
  785. if (EnumFirstHashTableString (&e, g_SamTable)) {
  786. do {
  787. samData = *((PSAMDATA *) e.ExtraData);
  788. if (samData) {
  789. if (samData->Initialized && samData->SamTerminate) {
  790. samData->SamTerminate ();
  791. }
  792. if (samData->SamPath) {
  793. pUnregisterModule (samData->SamPath);
  794. // samData->SamPath is owned by SGM
  795. }
  796. }
  797. } while (EnumNextHashTableString (&e));
  798. }
  799. HtFree (g_SamTable);
  800. g_SamTable = NULL;
  801. }
  802. if (g_SgmTable) {
  803. if (EnumFirstHashTableString (&e, g_SgmTable)) {
  804. do {
  805. sgmData = *((PSGMDATA *) e.ExtraData);
  806. if (sgmData) {
  807. if (sgmData->Initialized && sgmData->SgmTerminate) {
  808. sgmData->SgmTerminate ();
  809. }
  810. if (sgmData->SgmPath) {
  811. pUnregisterModule (sgmData->SgmPath);
  812. }
  813. }
  814. } while (EnumNextHashTableString (&e));
  815. }
  816. HtFree (g_SgmTable);
  817. g_SgmTable = NULL;
  818. }
  819. if (g_VcmTable) {
  820. if (EnumFirstHashTableString (&e, g_VcmTable)) {
  821. do {
  822. vcmData = *((PVCMDATA *) e.ExtraData);
  823. if (vcmData) {
  824. if (vcmData->Initialized && vcmData->VcmTerminate) {
  825. vcmData->VcmTerminate ();
  826. }
  827. if (vcmData->VcmPath) {
  828. pUnregisterModule (vcmData->VcmPath);
  829. }
  830. }
  831. } while (EnumNextHashTableString (&e));
  832. }
  833. HtFree (g_VcmTable);
  834. g_VcmTable = NULL;
  835. }
  836. }
  837. VOID
  838. pFreeTransportTable (
  839. VOID
  840. )
  841. {
  842. PTRANSPORTDATA transportData;
  843. HASHTABLE_ENUM e;
  844. if (g_TransportTable) {
  845. if (EnumFirstHashTableString (&e, g_TransportTable)) {
  846. do {
  847. transportData = *((PTRANSPORTDATA *) e.ExtraData);
  848. if (transportData) {
  849. if (transportData->Initialized && transportData->TransportTerminate) {
  850. transportData->TransportTerminate ();
  851. }
  852. if (transportData->TransportPath) {
  853. pUnregisterModule (transportData->TransportPath);
  854. }
  855. }
  856. } while (EnumNextHashTableString (&e));
  857. }
  858. HtFree (g_TransportTable);
  859. g_TransportTable = NULL;
  860. }
  861. }
  862. BOOL
  863. ValidateModuleName (
  864. IN PCTSTR ModuleName
  865. )
  866. {
  867. if (StringIMatch (ModuleName, S_COMMON)) {
  868. return FALSE;
  869. }
  870. if (!IsValidCName (ModuleName)) {
  871. return FALSE;
  872. }
  873. return TRUE;
  874. }
  875. BOOL
  876. InitializeVcmModules (
  877. IN PVOID Reserved
  878. )
  879. {
  880. INFSTRUCT is = INITINFSTRUCT_PMHANDLE;
  881. PCTSTR modulePath;
  882. PCTSTR moduleId;
  883. BOOL b = TRUE;
  884. BOOL cancelled = FALSE;
  885. PCTSTR sectionName;
  886. //
  887. // Initialize external modules
  888. //
  889. pAllocModuleTables();
  890. sectionName = TEXT("Virtual Computer Modules");
  891. if (InfFindFirstLine (g_IsmInf, sectionName, NULL, &is)) {
  892. do {
  893. //
  894. // A source gather module has an ID and module path
  895. //
  896. moduleId = InfGetStringField (&is, 0);
  897. modulePath = InfGetStringField (&is, 1);
  898. if (!ValidateModuleName (moduleId)) {
  899. LOG ((LOG_WARNING, (PCSTR) MSG_INVALID_ID, moduleId));
  900. continue;
  901. }
  902. if (moduleId && modulePath) {
  903. //
  904. // Register the VCM in an internal database
  905. //
  906. b = pRegisterVcm (moduleId, modulePath, Reserved);
  907. cancelled = CheckCancel();
  908. if (!b) {
  909. if (cancelled) {
  910. LOG ((LOG_MODULE_ERROR, (PCSTR) MSG_MODULE_RETURNED_FAILURE, moduleId));
  911. break;
  912. } else {
  913. LOG ((LOG_INFORMATION, (PCSTR) MSG_IGNORE_MODULE, moduleId));
  914. }
  915. }
  916. }
  917. } while (InfFindNextLine (&is));
  918. }
  919. if (cancelled) {
  920. return FALSE;
  921. }
  922. InfCleanUpInfStruct (&is);
  923. if (!b) {
  924. pFreeModuleTables();
  925. }
  926. return b;
  927. }
  928. BOOL
  929. InitializeModules (
  930. IN MIG_PLATFORMTYPEID Platform,
  931. IN PVOID Reserved
  932. )
  933. {
  934. INFSTRUCT is = INITINFSTRUCT_PMHANDLE;
  935. PCTSTR modulePath;
  936. PCTSTR moduleId;
  937. BOOL b = TRUE;
  938. BOOL cancelled = FALSE;
  939. __try {
  940. //
  941. // Initialize external modules
  942. //
  943. pAllocModuleTables();
  944. if (Platform == PLATFORM_SOURCE) {
  945. if (InfFindFirstLine (g_IsmInf, TEXT("Source Modules"), NULL, &is)) {
  946. do {
  947. //
  948. // A source gather module has an ID and module path
  949. //
  950. moduleId = InfGetStringField (&is, 0);
  951. modulePath = InfGetStringField (&is, 1);
  952. if (!ValidateModuleName (moduleId)) {
  953. LOG ((LOG_WARNING, (PCSTR) MSG_INVALID_ID, moduleId));
  954. continue;
  955. }
  956. if (moduleId && modulePath) {
  957. //
  958. // Register the source module in an internal database
  959. //
  960. b = pRegisterSm (moduleId, modulePath, Reserved);
  961. cancelled = CheckCancel();
  962. if (!b) {
  963. if (cancelled) {
  964. LOG ((LOG_MODULE_ERROR, (PCSTR) MSG_MODULE_RETURNED_FAILURE, moduleId));
  965. break;
  966. } else {
  967. LOG ((LOG_INFORMATION, (PCSTR) MSG_IGNORE_MODULE, moduleId));
  968. }
  969. }
  970. }
  971. } while (InfFindNextLine (&is));
  972. }
  973. if (cancelled) {
  974. __leave;
  975. }
  976. } else if (g_IsmCurrentPlatform == PLATFORM_DESTINATION) {
  977. if (InfFindFirstLine (g_IsmInf, TEXT("Destination Modules"), NULL, &is)) {
  978. do {
  979. //
  980. // A destination module has an ID and module path
  981. //
  982. moduleId = InfGetStringField (&is, 0);
  983. modulePath = InfGetStringField (&is, 1);
  984. if (!ValidateModuleName (moduleId)) {
  985. LOG ((LOG_WARNING, (PCSTR) MSG_INVALID_ID, moduleId));
  986. continue;
  987. }
  988. if (moduleId && modulePath) {
  989. //
  990. // Register the destination module in an internal database
  991. //
  992. b = pRegisterDm (moduleId, modulePath, Reserved);
  993. cancelled = CheckCancel();
  994. if (!b) {
  995. if (cancelled) {
  996. LOG ((LOG_MODULE_ERROR, (PCSTR) MSG_MODULE_RETURNED_FAILURE, moduleId));
  997. break;
  998. } else {
  999. LOG ((LOG_INFORMATION, (PCSTR) MSG_IGNORE_MODULE, moduleId));
  1000. }
  1001. }
  1002. }
  1003. } while (InfFindNextLine (&is));
  1004. }
  1005. if (cancelled) {
  1006. __leave;
  1007. }
  1008. } else {
  1009. DEBUGMSG ((DBG_ERROR, "InitializeModules: Unknown ISM current platform %d", g_IsmCurrentPlatform));
  1010. cancelled = TRUE;
  1011. }
  1012. }
  1013. __finally {
  1014. if (cancelled) {
  1015. pFreeModuleTables();
  1016. }
  1017. InfCleanUpInfStruct (&is);
  1018. }
  1019. return !cancelled;
  1020. }
  1021. VOID
  1022. TerminateModules (
  1023. VOID
  1024. )
  1025. {
  1026. pFreeModuleTables();
  1027. }
  1028. BOOL
  1029. pStartEtmModules (
  1030. IN MIG_PLATFORMTYPEID Platform
  1031. )
  1032. {
  1033. INFSTRUCT is = INITINFSTRUCT_PMHANDLE;
  1034. PCTSTR modulePath;
  1035. PCTSTR moduleId;
  1036. BOOL b = TRUE;
  1037. BOOL cancelled = FALSE;
  1038. MYASSERT (g_IsmInf != INVALID_HANDLE_VALUE);
  1039. if (InfFindFirstLine (g_IsmInf, TEXT("Type Modules"), NULL, &is)) {
  1040. do {
  1041. //
  1042. // An ETM has an ID and module path
  1043. //
  1044. moduleId = InfGetStringField (&is, 0);
  1045. modulePath = InfGetStringField (&is, 1);
  1046. if (!ValidateModuleName (moduleId)) {
  1047. LOG ((LOG_WARNING, (PCSTR) MSG_INVALID_ID, moduleId));
  1048. continue;
  1049. }
  1050. if (moduleId && modulePath) {
  1051. //
  1052. // Register the ETM in an internal database
  1053. //
  1054. b = pRegisterEtm (Platform, moduleId, modulePath, NULL);
  1055. cancelled = CheckCancel();
  1056. if (!b) {
  1057. if (cancelled) {
  1058. LOG ((LOG_MODULE_ERROR, (PCSTR) MSG_MODULE_RETURNED_FAILURE, moduleId));
  1059. break;
  1060. } else {
  1061. LOG ((LOG_INFORMATION, (PCSTR) MSG_IGNORE_MODULE, moduleId));
  1062. }
  1063. }
  1064. }
  1065. } while (InfFindNextLine (&is));
  1066. }
  1067. if (cancelled) {
  1068. return FALSE;
  1069. }
  1070. #ifdef PRERELEASE
  1071. //
  1072. // If pre-release, read in the exclusions from exclude.inf
  1073. //
  1074. {
  1075. TCHAR path[MAX_PATH];
  1076. PTSTR p;
  1077. HINF inf;
  1078. MIG_OBJECTSTRINGHANDLE handle;
  1079. MIG_OBJECTTYPEID typeId;
  1080. PCTSTR data;
  1081. PCTSTR leaf;
  1082. GetWindowsDirectory (path, MAX_PATH);
  1083. p = _tcschr (path, TEXT('\\'));
  1084. StringCopy (_tcsinc (p), TEXT("exclude.inf"));
  1085. inf = InfOpenInfFile (path);
  1086. if (inf && inf != INVALID_HANDLE_VALUE) {
  1087. if (InfFindFirstLine (inf, TEXT("Objects"), NULL, &is)) {
  1088. do {
  1089. data = InfGetStringField (&is, 1);
  1090. if (!data) {
  1091. continue;
  1092. }
  1093. typeId = IsmGetObjectTypeId (data);
  1094. if (!typeId) {
  1095. LOG ((LOG_ERROR, "EXCLUDE.INF: Invalid object exclusion type: %s", data));
  1096. continue;
  1097. }
  1098. data = InfGetStringField (&is, 2);
  1099. if (!data) {
  1100. LOG ((LOG_ERROR, "EXCLUDE.INF: Missing node object in field 2"));
  1101. continue;
  1102. }
  1103. leaf = InfGetStringField (&is, 3);
  1104. if (!leaf) {
  1105. LOG ((LOG_ERROR, "EXCLUDE.INF: Missing leaf object in field 3"));
  1106. continue;
  1107. }
  1108. handle = IsmCreateObjectHandle (data, leaf);
  1109. if (handle) {
  1110. IsmRegisterStaticExclusion (typeId, handle);
  1111. IsmDestroyObjectHandle (handle);
  1112. }
  1113. } while (InfFindNextLine (&is));
  1114. }
  1115. if (InfFindFirstLine (inf, TEXT("Nodes"), NULL, &is)) {
  1116. do {
  1117. data = InfGetStringField (&is, 1);
  1118. if (!data) {
  1119. continue;
  1120. }
  1121. typeId = IsmGetObjectTypeId (data);
  1122. if (!typeId) {
  1123. LOG ((LOG_ERROR, "EXCLUDE.INF: Invalid node exclusion type: %s", data));
  1124. continue;
  1125. }
  1126. data = InfGetStringField (&is, 2);
  1127. if (!data) {
  1128. LOG ((LOG_ERROR, "EXCLUDE.INF: Missing node object in field 2"));
  1129. continue;
  1130. }
  1131. handle = IsmCreateObjectHandle (data, NULL);
  1132. if (handle) {
  1133. IsmRegisterStaticExclusion (typeId, handle);
  1134. IsmDestroyObjectHandle (handle);
  1135. }
  1136. } while (InfFindNextLine (&is));
  1137. }
  1138. if (InfFindFirstLine (inf, TEXT("Leaves"), NULL, &is)) {
  1139. do {
  1140. data = InfGetStringField (&is, 1);
  1141. if (!data) {
  1142. continue;
  1143. }
  1144. typeId = IsmGetObjectTypeId (data);
  1145. if (!typeId) {
  1146. LOG ((LOG_ERROR, "EXCLUDE.INF: Invalid leaf exclusion type: %s", data));
  1147. continue;
  1148. }
  1149. data = InfGetStringField (&is, 2);
  1150. if (!data) {
  1151. LOG ((LOG_ERROR, "EXCLUDE.INF: Missing leaf object in field 2"));
  1152. continue;
  1153. }
  1154. handle = IsmCreateObjectHandle (NULL, data);
  1155. if (handle) {
  1156. IsmRegisterStaticExclusion (typeId, handle);
  1157. IsmDestroyObjectHandle (handle);
  1158. }
  1159. } while (InfFindNextLine (&is));
  1160. }
  1161. InfCleanUpInfStruct (&is);
  1162. InfCloseInfFile (inf);
  1163. }
  1164. }
  1165. #endif
  1166. InfCleanUpInfStruct (&is);
  1167. if (!b) {
  1168. pFreeEtmTable ();
  1169. }
  1170. return b;
  1171. }
  1172. VOID
  1173. pFreeEtmTable (
  1174. VOID
  1175. )
  1176. {
  1177. PETMDATA etmData;
  1178. HASHTABLE_ENUM e;
  1179. if (g_EtmTable) {
  1180. if (EnumFirstHashTableString (&e, g_EtmTable)) {
  1181. do {
  1182. etmData = *((PETMDATA *) e.ExtraData);
  1183. if (etmData) {
  1184. if (etmData->Initialized && etmData->EtmTerminate) {
  1185. etmData->EtmTerminate ();
  1186. }
  1187. if (etmData->EtmPath) {
  1188. pUnregisterModule (etmData->EtmPath);
  1189. }
  1190. }
  1191. } while (EnumNextHashTableString (&e));
  1192. }
  1193. HtFree (g_EtmTable);
  1194. g_EtmTable = NULL;
  1195. }
  1196. }
  1197. BOOL
  1198. IsmStartEtmModules (
  1199. VOID
  1200. )
  1201. {
  1202. BOOL result;
  1203. if (CheckCancel ()) {
  1204. return FALSE;
  1205. }
  1206. g_ExecutionInProgress = TRUE;
  1207. if (!g_ModuleTable) {
  1208. g_ModuleTable = HtAllocWithData (sizeof (PMODULEDATA));
  1209. }
  1210. if (!g_EtmTable) {
  1211. g_EtmTable = HtAllocWithData (sizeof (PETMDATA));
  1212. }
  1213. result = pStartEtmModules (g_IsmCurrentPlatform);
  1214. #ifdef PRERELEASE
  1215. LoadCrashHooks ();
  1216. #endif
  1217. g_ExecutionInProgress = FALSE;
  1218. return result;
  1219. }
  1220. BOOL
  1221. BroadcastUserCreation (
  1222. IN PTEMPORARYPROFILE UserProfile
  1223. )
  1224. {
  1225. PETMDATA etmData;
  1226. HASHTABLE_ENUM e;
  1227. if (g_EtmTable) {
  1228. if (EnumFirstHashTableString (&e, g_EtmTable)) {
  1229. do {
  1230. etmData = *((PETMDATA *) e.ExtraData);
  1231. if (etmData) {
  1232. if (etmData->Initialized && etmData->EtmNewUserCreated) {
  1233. etmData->EtmNewUserCreated (
  1234. UserProfile->UserName,
  1235. UserProfile->DomainName,
  1236. UserProfile->UserProfileRoot,
  1237. UserProfile->UserSid
  1238. );
  1239. }
  1240. }
  1241. } while (EnumNextHashTableString (&e));
  1242. }
  1243. }
  1244. return TRUE;
  1245. }
  1246. VOID
  1247. TerminateProcessWideModules (
  1248. VOID
  1249. )
  1250. {
  1251. //
  1252. // Terminate the phase-specific modules
  1253. //
  1254. TerminateModules();
  1255. //
  1256. // Terminate the process-wide modules: ETMs, transports
  1257. //
  1258. // Terminate Etm modules table
  1259. //
  1260. pFreeEtmTable ();
  1261. //
  1262. // Terminate all transport modules
  1263. //
  1264. pFreeTransportTable ();
  1265. //
  1266. // Enumerate all registered modules and verify that RefCount is 0
  1267. //
  1268. pFreeRegisteredModules ();
  1269. }
  1270. BOOL
  1271. IsmStartTransport (
  1272. VOID
  1273. )
  1274. {
  1275. INFSTRUCT is = INITINFSTRUCT_PMHANDLE;
  1276. PCTSTR modulePath;
  1277. PCTSTR moduleId;
  1278. BOOL b = TRUE;
  1279. BOOL cancelled = FALSE;
  1280. if (CheckCancel ()) {
  1281. return FALSE;
  1282. }
  1283. g_ExecutionInProgress = TRUE;
  1284. MYASSERT (g_IsmInf != INVALID_HANDLE_VALUE);
  1285. if (InfFindFirstLine (g_IsmInf, TEXT("Transport Modules"), NULL, &is)) {
  1286. do {
  1287. //
  1288. // A transport module has an ID and module path
  1289. //
  1290. moduleId = InfGetStringField (&is, 0);
  1291. modulePath = InfGetStringField (&is, 1);
  1292. if (!ValidateModuleName (moduleId)) {
  1293. LOG ((LOG_WARNING, (PCSTR) MSG_INVALID_ID, moduleId));
  1294. continue;
  1295. }
  1296. if (moduleId && modulePath) {
  1297. //
  1298. // Register the transport in an internal database
  1299. //
  1300. b = pRegisterTransport (moduleId, modulePath, NULL);
  1301. cancelled = CheckCancel();
  1302. if (!b) {
  1303. if (cancelled) {
  1304. LOG ((LOG_MODULE_ERROR, (PCSTR) MSG_MODULE_RETURNED_FAILURE, moduleId));
  1305. break;
  1306. } else {
  1307. LOG ((LOG_INFORMATION, (PCSTR) MSG_IGNORE_MODULE, moduleId));
  1308. }
  1309. }
  1310. }
  1311. } while (InfFindNextLine (&is));
  1312. }
  1313. if (!cancelled) {
  1314. InfCleanUpInfStruct (&is);
  1315. if (!b) {
  1316. pFreeTransportTable ();
  1317. }
  1318. } else {
  1319. b = FALSE;
  1320. }
  1321. g_ExecutionInProgress = FALSE;
  1322. return b;
  1323. }