Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

412 lines
9.1 KiB

  1. /*++
  2. Copyright (c) 1997-1999 Microsoft Corporation
  3. Module Name:
  4. dbaction.c
  5. Abstract:
  6. This source implements action functions used by MigDb. There are two types
  7. of action functions here as the third parameter of the macro list is TRUE
  8. or FALSE.
  9. First type of action function is called whenever an action is triggered
  10. during file scanning. The second type of action function is called at the
  11. end of file scanning if the associated action was not triggered during
  12. file scanning phase.
  13. Author:
  14. Calin Negreanu (calinn) 07-Jan-1998
  15. Revision History:
  16. marcw 31-Aug-1999 Added BlockingHardware
  17. ovidiut 20-Jul-1999 Added Ignore
  18. ovidiut 28-May-1999 Added IniFileMappings
  19. marcw 23-Sep-1998 Added BlockingVirusScanner
  20. jimschm 13-Aug-1998 Added CompatibleFiles
  21. jimschm 19-May-1998 Added MinorProblems_NoLinkRequired
  22. jimschm 27-Feb-1998 Added UninstallSections
  23. calinn 18-Jan-1998 Added CompatibleModules action
  24. --*/
  25. #include "pch.h"
  26. #include "logmsg.h"
  27. #include "osfiles.h"
  28. /*++
  29. Macro Expansion List Description:
  30. GATHER_DATA_FUNCTIONS and ACTION_FUNCTIONS lists all valid actions to be performed
  31. by migdb when a context is met. Meeting a context means that all the sections
  32. associated with the context are satisfied (usually there is only one section).
  33. The difference is that GATHER_DATA_FUNCTIONS are called even if some function already
  34. handles a file.
  35. Line Syntax:
  36. DEFMAC(ActionFn, ActionName, CallWhenTriggered, CanHandleVirtualFiles)
  37. Arguments:
  38. ActionFn - This is a boolean function that returnes TRUE if the specified action
  39. could be performed. It should return FALSE only if a serious error
  40. occures. You must implement a function with this name and required
  41. parameters.
  42. ActionName - This is the string that identifies the action function. It should
  43. have the same value as listed in migdb.inf. This arg is declared
  44. as both a macro and the migdb.inf section name string.
  45. PatternFormat - The format in the INF for this section is the pattern format. The non
  46. pattern format is the file name followed by the attributes. The pattern
  47. format is the leaf pattern, node pattern and then the attributes.
  48. CallWhenTriggered - If the MigDbContext this action is associated with is triggered
  49. the action will be called if this field is TRUE, otherwise we will call
  50. the action at the end of file scan if the context was not triggered.
  51. CanHandleVirtualFiles - This is for treating files that are supposed to be in a fixed place
  52. but are not there (not installed or deleted). We need this in order to fix
  53. registry or links that point to this kind of files. A good example is backup.exe
  54. which is located in %ProgramFiles%\Accessories. The rules say that we should
  55. use ntbackup.exe instead but since this file is not existent we don't normalle fix
  56. registry settings pointing to this file. We do now, with this new variable
  57. Variables Generated From List:
  58. g_ActionFunctions - do not touch!
  59. For accessing the array there are the following functions:
  60. MigDb_GetActionAddr
  61. MigDb_GetActionIdx
  62. MigDb_GetActionName
  63. --*/
  64. /*
  65. Declare the macro list of action functions. If you need to add a new action just
  66. add a line in this list and implement the function.
  67. */
  68. #define ACTION_FUNCTIONS \
  69. DEFMAC(OsFiles, TEXT("OsFiles"), FALSE, TRUE, TRUE) \
  70. DEFMAC(OsFiles, TEXT("OsFilesPattern"), TRUE, TRUE, TRUE) \
  71. DEFMAC(NonCritical, TEXT("NonCriticalFiles"), TRUE, TRUE, TRUE) \
  72. DEFMAC(OsFilesExcluded, TEXT("OsFilesExcluded"), TRUE, TRUE, TRUE) \
  73. /*
  74. Declare the action functions
  75. */
  76. #define DEFMAC(fn,id,pat,trig,call) ACTION_PROTOTYPE fn;
  77. ACTION_FUNCTIONS
  78. #undef DEFMAC
  79. /*
  80. This is the structure used for handling action functions
  81. */
  82. typedef struct {
  83. PCTSTR ActionName;
  84. PACTION_PROTOTYPE ActionFunction;
  85. BOOL PatternFormat;
  86. BOOL CallWhenTriggered;
  87. BOOL CallAlways;
  88. } ACTION_STRUCT, *PACTION_STRUCT;
  89. /*
  90. Declare a global array of functions and name identifiers for action functions
  91. */
  92. #define DEFMAC(fn,id,pat,trig,call) {id,fn,pat,trig,call},
  93. static ACTION_STRUCT g_ActionFunctions[] = {
  94. ACTION_FUNCTIONS
  95. {NULL, NULL, FALSE, FALSE, FALSE}
  96. };
  97. #undef DEFMAC
  98. PACTION_PROTOTYPE
  99. MigDb_GetActionAddr (
  100. IN INT ActionIdx
  101. )
  102. /*++
  103. Routine Description:
  104. MigDb_GetActionAddr returns the address of the action function based on the action index
  105. Arguments:
  106. ActionIdx - Action index.
  107. Return value:
  108. Action function address. Note that no checking is made so the address returned could be invalid.
  109. This is not a problem since the parsing code did the right job.
  110. --*/
  111. {
  112. return g_ActionFunctions[ActionIdx].ActionFunction;
  113. }
  114. INT
  115. MigDb_GetActionIdx (
  116. IN PCTSTR ActionName
  117. )
  118. /*++
  119. Routine Description:
  120. MigDb_GetActionIdx returns the action index based on the action name
  121. Arguments:
  122. ActionName - Action name.
  123. Return value:
  124. Action index. If the name is not found, the index returned is -1.
  125. --*/
  126. {
  127. PACTION_STRUCT p = g_ActionFunctions;
  128. INT i = 0;
  129. while (p->ActionName != NULL) {
  130. if (StringIMatch (p->ActionName, ActionName)) {
  131. return i;
  132. }
  133. p++;
  134. i++;
  135. }
  136. return -1;
  137. }
  138. PCTSTR
  139. MigDb_GetActionName (
  140. IN INT ActionIdx
  141. )
  142. /*++
  143. Routine Description:
  144. MigDb_GetActionName returns the name of an action based on the action index
  145. Arguments:
  146. ActionIdx - Action index.
  147. Return value:
  148. Action name. Note that no checking is made so the returned pointer could be invalid.
  149. This is not a problem since the parsing code did the right job.
  150. --*/
  151. {
  152. return g_ActionFunctions[ActionIdx].ActionName;
  153. }
  154. BOOL
  155. MigDb_IsPatternFormat (
  156. IN INT ActionIdx
  157. )
  158. /*++
  159. Routine Description:
  160. MigDb_IsPatternFormat is called when we try to find what is the section format.
  161. Arguments:
  162. ActionIdx - Action index.
  163. Return value:
  164. TRUE if the format is pattern like, FALSE otherwise.
  165. --*/
  166. {
  167. return g_ActionFunctions[ActionIdx].PatternFormat;
  168. }
  169. BOOL
  170. MigDb_CallWhenTriggered (
  171. IN INT ActionIdx
  172. )
  173. /*++
  174. Routine Description:
  175. MigDb_CallWhenTriggered is called every time when an action is triggered. Will return
  176. TRUE is the associated action function needs to be called, FALSE otherwise.
  177. Arguments:
  178. ActionIdx - Action index.
  179. Return value:
  180. TRUE if the associated action function needs to be called, FALSE otherwise.
  181. --*/
  182. {
  183. return g_ActionFunctions[ActionIdx].CallWhenTriggered;
  184. }
  185. BOOL
  186. MigDb_CallAlways (
  187. IN INT ActionIdx
  188. )
  189. /*++
  190. Routine Description:
  191. MigDb_CallAlways returnes if an action should be called regardless of handled state.
  192. Arguments:
  193. ActionIdx - Action index.
  194. Return value:
  195. TRUE if the associated action should be called every time.
  196. --*/
  197. {
  198. return g_ActionFunctions[ActionIdx].CallAlways;
  199. }
  200. BOOL
  201. OsFiles (
  202. IN PMIGDB_CONTEXT Context
  203. )
  204. /*++
  205. Routine Description:
  206. This is the action taken when an OS file is found. Basically the file gets deleted to
  207. make room for NT version.
  208. Arguments:
  209. Context - See definition.
  210. Return value:
  211. TRUE - if operation was successful
  212. FALSE - otherwise
  213. --*/
  214. {
  215. MULTISZ_ENUM fileEnum;
  216. if (EnumFirstMultiSz (&fileEnum, (PCTSTR) Context->FileList.Buf)) {
  217. do {
  218. IsmSetAttributeOnObject (
  219. MIG_FILE_TYPE,
  220. fileEnum.CurrentString,
  221. g_OsFileAttribute
  222. );
  223. }
  224. while (EnumNextMultiSz (&fileEnum));
  225. }
  226. return TRUE;
  227. }
  228. BOOL
  229. NonCritical (
  230. IN PMIGDB_CONTEXT Context
  231. )
  232. /*++
  233. Routine Description:
  234. This is the action taken when an non critical file is found.
  235. We are calling ISM to mark this file as NonCritical
  236. Arguments:
  237. Context - See definition.
  238. Return value:
  239. TRUE - if operation was successful
  240. FALSE - otherwise
  241. --*/
  242. {
  243. MULTISZ_ENUM fileEnum;
  244. if (EnumFirstMultiSz (&fileEnum, (PCTSTR) Context->FileList.Buf)) {
  245. do {
  246. IsmMakeNonCriticalObject (
  247. MIG_FILE_TYPE,
  248. fileEnum.CurrentString
  249. );
  250. }
  251. while (EnumNextMultiSz (&fileEnum));
  252. }
  253. return TRUE;
  254. }
  255. BOOL
  256. OsFilesExcluded (
  257. IN PMIGDB_CONTEXT Context
  258. )
  259. /*++
  260. Routine Description:
  261. This is the action taken when an file that is not an OS file is found.
  262. Since this file might have the OS file attribute (due to patterns in os files)
  263. we are calling ISM to remove the OsFile attribute from this file
  264. Arguments:
  265. Context - See definition.
  266. Return value:
  267. TRUE - if operation was successful
  268. FALSE - otherwise
  269. --*/
  270. {
  271. MULTISZ_ENUM fileEnum;
  272. if (EnumFirstMultiSz (&fileEnum, (PCTSTR) Context->FileList.Buf)) {
  273. do {
  274. IsmClearAttributeOnObject (
  275. MIG_FILE_TYPE,
  276. fileEnum.CurrentString,
  277. g_OsFileAttribute
  278. );
  279. }
  280. while (EnumNextMultiSz (&fileEnum));
  281. }
  282. return TRUE;
  283. }