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.

367 lines
7.1 KiB

  1. /*++
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. sfcfiles.c
  5. Abstract:
  6. Routines to initialize and retrieve a list of files to be proected by the
  7. system.
  8. Author:
  9. Wesley Witt (wesw) 18-Dec-1998
  10. Revision History:
  11. Andrew Ritz (andrewr) 2-Jul-199 -- added comments
  12. --*/
  13. #include <nt.h>
  14. #include <ntrtl.h>
  15. #include <nturtl.h>
  16. #include <windows.h>
  17. #include "sfcfiles.h"
  18. #if defined(_AMD64_)
  19. #include "amd64_wks.h"
  20. #elif defined(_IA64_)
  21. #include "ia64_wks.h"
  22. #elif defined(_X86_)
  23. #include "x86_per.h"
  24. #undef SFCFILES_SKU_TABLET
  25. #undef SFCFILES_SKU_MEDIA
  26. #include "x86_wks.h"
  27. #define SFCFILES_SKU_TABLET
  28. #include "x86_wks.h"
  29. #undef SFCFILES_SKU_TABLET
  30. #define SFCFILES_SKU_MEDIA
  31. #include "x86_wks.h"
  32. #else
  33. #error "No Target Platform"
  34. #endif
  35. //
  36. // Globals
  37. //
  38. //
  39. // module handle
  40. //
  41. HMODULE SfcInstanceHandle;
  42. //
  43. // pointer to tier2 files for this system
  44. //
  45. PPROTECT_FILE_ENTRY Tier2Files;
  46. //
  47. // number of files in the tier 2 list. there must always be at least one file
  48. // in the list of protected files
  49. //
  50. ULONG CountTier2Files;
  51. DWORD
  52. SfcDllEntry(
  53. HINSTANCE hInstance,
  54. DWORD Reason,
  55. LPVOID Context
  56. )
  57. /*++
  58. Routine Description:
  59. Main Dll Entrypoint
  60. Arguments:
  61. hInstance - handle to dll module
  62. Reason - reason for calling function
  63. Context - reserved
  64. Return Value:
  65. always TRUE
  66. --*/
  67. {
  68. if (Reason == DLL_PROCESS_ATTACH) {
  69. SfcInstanceHandle = hInstance;
  70. //
  71. // we don't need thread attach/detach notifications
  72. //
  73. LdrDisableThreadCalloutsForDll( hInstance );
  74. }
  75. return TRUE;
  76. }
  77. #if !defined(_AMD64_) && !defined(_IA64_)
  78. DWORD
  79. SfcReadDwordRegVal(
  80. PCWSTR szKeyName,
  81. PCWSTR szValueName,
  82. DWORD dwDefaultVal
  83. )
  84. {
  85. NTSTATUS Status;
  86. DWORD dwRet = dwDefaultVal;
  87. HKEY hKey = NULL;
  88. UNICODE_STRING Name;
  89. OBJECT_ATTRIBUTES Attrs;
  90. ULONG Length;
  91. //
  92. // This will be larger than we actually need
  93. //
  94. struct {
  95. KEY_VALUE_PARTIAL_INFORMATION Info;
  96. DWORD dwData;
  97. } Buffer;
  98. RtlInitUnicodeString(&Name, szKeyName);
  99. InitializeObjectAttributes(&Attrs, &Name, OBJ_CASE_INSENSITIVE, NULL, NULL);
  100. Status = NtOpenKey(&hKey, KEY_QUERY_VALUE, &Attrs);
  101. if(!NT_SUCCESS(Status)) {
  102. hKey = NULL;
  103. goto exit;
  104. }
  105. RtlInitUnicodeString(&Name, szValueName);
  106. Status = NtQueryValueKey(hKey, &Name, KeyValuePartialInformation, (PVOID) &Buffer, sizeof(Buffer), &Length);
  107. if(!NT_SUCCESS(Status) || Buffer.Info.Type != REG_DWORD || Buffer.Info.DataLength != sizeof(DWORD)) {
  108. goto exit;
  109. }
  110. dwRet = *((LPDWORD) Buffer.Info.Data);
  111. exit:
  112. if(hKey != NULL) {
  113. NtClose(hKey);
  114. }
  115. return dwRet;
  116. }
  117. static const WCHAR szTabletPCKey[] = L"\\Registry\\Machine\\System\\WPA\\TabletPC";
  118. static const WCHAR szTabletPCValue[] = L"Installed";
  119. static const WCHAR szMediaCenterKey[] = L"\\Registry\\Machine\\System\\WPA\\MediaCenter";
  120. static const WCHAR szMediaCenterValue[] = L"Installed";
  121. FORCEINLINE
  122. BOOL
  123. SfcIsTabletPC(
  124. VOID
  125. )
  126. {
  127. return SfcReadDwordRegVal(szTabletPCKey, szTabletPCValue, 0) != 0;
  128. }
  129. FORCEINLINE
  130. BOOL
  131. SfcIsMediaCenter(
  132. VOID
  133. )
  134. {
  135. return SfcReadDwordRegVal(szMediaCenterKey, szMediaCenterValue, 0) != 0;
  136. }
  137. #endif
  138. NTSTATUS
  139. SfcFilesInit(
  140. void
  141. )
  142. /*++
  143. Routine Description:
  144. Initialization routine. This routine must be called before
  145. SfcGetFiles() can do any work. The initialization routine
  146. determines what embedded file list we should use based on
  147. product type and architecture.
  148. Arguments:
  149. NONE.
  150. Return Value:
  151. NTSTATUS code indicating outcome.
  152. --*/
  153. {
  154. NTSTATUS Status;
  155. OSVERSIONINFOEXW ver;
  156. //
  157. // set the tier2 file pointer based on the product we're running on
  158. //
  159. //
  160. // retrieve product information
  161. //
  162. RtlZeroMemory( &ver, sizeof(ver) );
  163. ver.dwOSVersionInfoSize = sizeof(ver);
  164. Status = RtlGetVersion( (LPOSVERSIONINFOW)&ver );
  165. if (!NT_SUCCESS(Status)) {
  166. return Status;
  167. }
  168. if (ver.wProductType == VER_NT_WORKSTATION) {
  169. #if !defined(_AMD64_) && !defined(_IA64_)
  170. if (ver.wSuiteMask & VER_SUITE_PERSONAL)
  171. {
  172. Tier2Files = PerFiles;
  173. CountTier2Files = CountPerFiles;
  174. }
  175. else if(SfcIsTabletPC()) {
  176. Tier2Files = TabFiles;
  177. CountTier2Files = CountTabFiles;
  178. }
  179. else if(SfcIsMediaCenter()) {
  180. Tier2Files = MedFiles;
  181. CountTier2Files = CountMedFiles;
  182. }
  183. else
  184. #endif
  185. {
  186. Tier2Files = WksFiles;
  187. CountTier2Files = CountWksFiles;
  188. }
  189. } else {
  190. return STATUS_NOT_SUPPORTED;
  191. }
  192. return STATUS_SUCCESS;
  193. }
  194. NTSTATUS
  195. SfcGetFiles(
  196. OUT PPROTECT_FILE_ENTRY *Files,
  197. OUT PULONG FileCount
  198. )
  199. /*++
  200. Routine Description:
  201. Retreives pointers to the file list and file count. Note that we refer to
  202. a "tier2" list here but in actuality there is no tier 1 list.
  203. Arguments:
  204. Files - pointer to a PPROTECT_FILE_ENTRY, which is filled in with a pointer
  205. to the actual protected files list.
  206. FileCount - pointer to a ULONG which is filled in with the file count.
  207. Return Value:
  208. NTSTATUS code indicating outcome.
  209. --*/
  210. {
  211. NTSTATUS Status;
  212. if (CountTier2Files == 0) {
  213. Status = SfcFilesInit();
  214. if (!NT_SUCCESS(Status)) {
  215. *Files = NULL;
  216. *FileCount = 0;
  217. return Status;
  218. }
  219. }
  220. ASSERT(Tier2Files != NULL);
  221. ASSERT(CountTier2Files != 0);
  222. *Files = Tier2Files;
  223. *FileCount = CountTier2Files;
  224. return STATUS_SUCCESS;
  225. }
  226. NTSTATUS
  227. pSfcGetFilesList(
  228. IN DWORD ListMask,
  229. OUT PPROTECT_FILE_ENTRY *Files,
  230. OUT PULONG FileCount
  231. )
  232. /*++
  233. Routine Description:
  234. Retreives pointers to the requested file list and file count.
  235. This is an internal testing routine that is used so that we can retrieve
  236. any file list on a given machine so testing does not have to install more
  237. than one build to get at multiple file lists
  238. Arguments:
  239. ListMask - specifies a SFCFILESMASK_* constant
  240. Files - pointer to a PPROTECT_FILE_ENTRY, which is filled in with a pointer
  241. to the actual protected files list.
  242. FileCount - pointer to a ULONG which is filled in with the file count.
  243. Return Value:
  244. NTSTATUS code indicating outcome.
  245. --*/
  246. {
  247. NTSTATUS RetVal = STATUS_SUCCESS;
  248. if (!Files || !FileCount) {
  249. return(STATUS_INVALID_PARAMETER);
  250. }
  251. switch (ListMask) {
  252. case SFCFILESMASK_PROFESSIONAL:
  253. *Files = WksFiles;
  254. *FileCount = CountWksFiles;
  255. break;
  256. #if !defined(_AMD64_) && !defined(_IA64_)
  257. case SFCFILESMASK_PERSONAL:
  258. *Files = PerFiles;
  259. *FileCount = CountPerFiles;
  260. break;
  261. case SFCFILESMASK_TABLET:
  262. *Files = TabFiles;
  263. *FileCount = CountTabFiles;
  264. break;
  265. case SFCFILESMASK_MEDIACTR:
  266. *Files = MedFiles;
  267. *FileCount = CountMedFiles;
  268. break;
  269. #endif
  270. default:
  271. RetVal = STATUS_INVALID_PARAMETER;
  272. }
  273. return RetVal;
  274. }