Windows NT 4.0 source code leak
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.

304 lines
7.0 KiB

4 years ago
  1. /*++
  2. Copyright (c) 1994 Microsoft Corporation
  3. Module Name:
  4. fontload.c
  5. Abstract:
  6. This module performs actions related to secure font loading.
  7. This is controlled by the presence and contents of the
  8. following registry key:
  9. \Registry\Machine\Software\Microsoft\Windows NT\CurrentVersion\FontPath
  10. If this key contains a [REG_SZ] string, it is expected to contain
  11. a semi-colon delimited path variable. The entries on this path
  12. variable specify where fonts may be loaded from.
  13. Author:
  14. Jim Kelly (JimK) 22-Sep-1994
  15. Revision History:
  16. --*/
  17. #include "secmgrp.h"
  18. ///////////////////////////////////////////////////////////////////////
  19. // //
  20. // Module-Private Definitions //
  21. // //
  22. ///////////////////////////////////////////////////////////////////////
  23. ///////////////////////////////////////////////////////////////////////
  24. // //
  25. // Module-wide variables //
  26. // //
  27. ///////////////////////////////////////////////////////////////////////
  28. ///////////////////////////////////////////////////////////////////////
  29. // //
  30. // Module-Private Prototypes //
  31. // //
  32. ///////////////////////////////////////////////////////////////////////
  33. NTSTATUS
  34. FontPathQueryRoutine
  35. (
  36. IN PWSTR ValueName,
  37. IN ULONG ValueType,
  38. IN PVOID ValueData,
  39. IN ULONG ValueLength,
  40. IN PVOID Context,
  41. IN PVOID EntryContext
  42. );
  43. ///////////////////////////////////////////////////////////////////////
  44. // //
  45. // Externally callable functions //
  46. // //
  47. ///////////////////////////////////////////////////////////////////////
  48. BOOLEAN
  49. SecMgrpGetFontLoadingSetting(
  50. HWND hwnd,
  51. PBOOLEAN Secure
  52. )
  53. /*++
  54. Routine Description:
  55. This function is used to get the current font loading path.
  56. Arguments
  57. hwnd - The caller's window. This is used if we need to put
  58. up an error popup.
  59. Secure - Receives a boolean indicating whether the executive
  60. objects are protected (return TRUE) or unprotected (return
  61. FALSE).
  62. Return Values:
  63. TRUE - The value has been successfully retrieved.
  64. FALSE - we ran into trouble querying the current setting.
  65. If an error is encountered, then an error popup will be
  66. displayed by this routine.
  67. --*/
  68. {
  69. NTSTATUS
  70. NtStatus;
  71. WCHAR
  72. PathBuffer[MAX_PATH];
  73. ULONG
  74. Length;
  75. RTL_QUERY_REGISTRY_TABLE
  76. QueryTable[2];
  77. //
  78. // Initialize the registry query table.
  79. //
  80. QueryTable[0].QueryRoutine = FontPathQueryRoutine;
  81. QueryTable[0].Flags = RTL_REGISTRY_OPTIONAL;
  82. QueryTable[0].Name = NULL;
  83. QueryTable[0].EntryContext = &Length;
  84. QueryTable[0].DefaultType = REG_NONE;
  85. QueryTable[0].DefaultData = NULL;
  86. QueryTable[0].DefaultLength = 0;
  87. QueryTable[1].QueryRoutine = NULL;
  88. QueryTable[1].Flags = 0;
  89. QueryTable[1].Name = NULL;
  90. //
  91. // Query the font path.
  92. // RTL_REGISTRY_WINDOWS_NT references the following registry
  93. // key:
  94. // \Registry\Machine\Software\Microsoft\Windows NT\CurrentVersion
  95. //
  96. Length = 0;
  97. NtStatus = RtlQueryRegistryValues(
  98. RTL_REGISTRY_WINDOWS_NT | RTL_REGISTRY_OPTIONAL,
  99. (PWSTR)L"FontPath",
  100. &QueryTable[0],
  101. &PathBuffer[0],
  102. NULL);
  103. if ( (!NT_SUCCESS(NtStatus)) &&
  104. (NtStatus != STATUS_OBJECT_NAME_NOT_FOUND) ) {
  105. //
  106. // Put up a popup
  107. //
  108. SecMgrpPopUp( hwnd, SECMGRP_STRING_ERROR_GETTING_FONT_PATH);
  109. return(FALSE);
  110. }
  111. if ( Length == 0 )
  112. {
  113. (*Secure) = FALSE;
  114. } else {
  115. (*Secure) = TRUE;
  116. }
  117. return(TRUE);
  118. }
  119. BOOLEAN
  120. SecMgrpSetFontLoadingSetting(
  121. HWND hwnd,
  122. BOOLEAN Secure
  123. )
  124. /*++
  125. Routine Description:
  126. This function is used to secure or unsecure Font Loading.
  127. If it is to be secured, for the time being we set a hardcoded
  128. list of trusted directories in the Font-Loading path. These
  129. directories are:
  130. %WinDir%\System
  131. Arguments
  132. hwnd - The caller's window. This is used if we need to put
  133. up an error popup.
  134. Secure - A boolean indicating whether font-loading should be
  135. secured (TRUE) or left unsecured (FALSE).
  136. Return Values:
  137. TRUE - The value has been successfully set
  138. FALSE - we ran into trouble setting the new setting.
  139. If an error is encountered, then an error popup will be
  140. displayed by this routine.
  141. --*/
  142. {
  143. NTSTATUS
  144. NtStatus;
  145. WCHAR
  146. SecuredPath[] = L"%WinDir%\\System";
  147. PWSTR
  148. PathToAssign;
  149. ULONG
  150. PathLength;
  151. //
  152. // Set the new value
  153. //
  154. if ( Secure ) {
  155. PathToAssign = SecuredPath;
  156. PathLength = sizeof(SecuredPath);
  157. } else {
  158. PathToAssign = NULL;
  159. PathLength = 0;
  160. }
  161. NtStatus = RtlWriteRegistryValue( RTL_REGISTRY_WINDOWS_NT, // RelativeTo
  162. L"FontPath", // Path
  163. NULL, // ValueName
  164. REG_SZ, // ValueType
  165. PathToAssign, //ValueData
  166. PathLength // ValueLength
  167. );
  168. if (!NT_SUCCESS(NtStatus)) {
  169. //
  170. // Put up a pop-up
  171. //
  172. SecMgrpPopUp( hwnd, SECMGRP_STRING_ERROR_SETTING_FONT_PATH );
  173. return(FALSE);
  174. }
  175. return(TRUE);
  176. }
  177. NTSTATUS
  178. FontPathQueryRoutine
  179. (
  180. IN PWSTR ValueName,
  181. IN ULONG ValueType,
  182. IN PVOID ValueData,
  183. IN ULONG ValueLength,
  184. IN PVOID Context,
  185. IN PVOID EntryContext
  186. )
  187. /*++
  188. Routine Description:
  189. This function is the dispatch routine for the query registry
  190. table used to query the font path.
  191. This routine was copied from GDI code. There were no comments
  192. there, and so there aren't many here either. Great.
  193. Arguments
  194. Return Values:
  195. --*/
  196. {
  197. //
  198. // If the type of value is a string, the value is not NULL, and the
  199. // value will fit in the destination buffer, then copy the string.
  200. //
  201. if ((ValueType == REG_SZ) &&
  202. (ValueLength != sizeof(WCHAR)) && (ValueLength <= MAX_PATH)) {
  203. *(PULONG)EntryContext = ValueLength;
  204. RtlCopyMemory(Context, ValueData, ValueLength);
  205. }
  206. return STATUS_SUCCESS;
  207. }