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.

402 lines
9.6 KiB

  1. /*******************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORP., 1993-1994
  4. *
  5. * TITLE: REGMAIN.C
  6. *
  7. * VERSION: 4.01
  8. *
  9. * AUTHOR: Tracy Sharpe
  10. *
  11. * DATE: 05 Mar 1994
  12. *
  13. *******************************************************************************/
  14. #include "pch.h"
  15. #include <regstr.h>
  16. #include "regedit.h"
  17. #include "regfile.h"
  18. #include "regbined.h"
  19. #include "regresid.h"
  20. // Instance handle of this application.
  21. HINSTANCE g_hInstance;
  22. // TRUE if accelerator table should not be used, such as during a rename
  23. // operation.
  24. BOOL g_fDisableAccelerators = FALSE;
  25. TCHAR g_KeyNameBuffer[MAXKEYNAME];
  26. TCHAR g_ValueNameBuffer[MAXVALUENAME_LENGTH];
  27. COLORREF g_clrWindow;
  28. COLORREF g_clrWindowText;
  29. COLORREF g_clrHighlight;
  30. COLORREF g_clrHighlightText;
  31. HWND g_hRegEditWnd;
  32. PTSTR g_pHelpFileName;
  33. TCHAR g_NullString[] = TEXT("");
  34. #define PARSERET_CONTINUE 0
  35. #define PARSERET_REFRESH 1
  36. #define PARSERET_EXIT 2
  37. UINT
  38. PASCAL
  39. ParseCommandLine(
  40. VOID
  41. );
  42. BOOL
  43. PASCAL
  44. IsRegistryToolDisabled(
  45. VOID
  46. );
  47. int
  48. PASCAL
  49. ModuleEntry(
  50. VOID
  51. )
  52. {
  53. HWND hPopupWnd;
  54. HACCEL hRegEditAccel;
  55. MSG Msg;
  56. USHORT wLanguageId = LANGIDFROMLCID(GetThreadLocale());
  57. INITCOMMONCONTROLSEX icce;
  58. g_hInstance = GetModuleHandle(NULL);
  59. icce.dwSize = sizeof(icce);
  60. // DebugAssert(icce.dwSize == sizeof(INITCOMMONCONTROLSEX));
  61. icce.dwICC = ICC_ALL_CLASSES;
  62. InitCommonControlsEx(&icce);
  63. g_hRegEditWnd = FindWindow(g_RegEditClassName, NULL);
  64. //
  65. // To prevent users from corrupting their registries,
  66. // administrators can set a policy switch to prevent editing. Check that
  67. // switch now.
  68. //
  69. if (IsRegistryToolDisabled())
  70. {
  71. InternalMessageBox(g_hInstance, NULL, MAKEINTRESOURCE(IDS_REGEDITDISABLED),
  72. MAKEINTRESOURCE(IDS_REGEDIT), MB_ICONERROR | MB_OK);
  73. goto ModuleExit;
  74. }
  75. //
  76. // Check if we were given a commandline and handle if appropriate.
  77. //
  78. switch (ParseCommandLine()) {
  79. case PARSERET_REFRESH:
  80. if (g_hRegEditWnd != NULL)
  81. PostMessage(g_hRegEditWnd, WM_COMMAND, ID_REFRESH, 0);
  82. // FALL THROUGH
  83. case PARSERET_EXIT:
  84. goto ModuleExit;
  85. }
  86. //
  87. // Allow only one instance of the Registry Editor.
  88. //
  89. if (g_hRegEditWnd != NULL) {
  90. if (IsIconic(g_hRegEditWnd))
  91. ShowWindow(g_hRegEditWnd, SW_RESTORE);
  92. else {
  93. BringWindowToTop(g_hRegEditWnd);
  94. if ((hPopupWnd = GetLastActivePopup(g_hRegEditWnd)) != g_hRegEditWnd)
  95. BringWindowToTop(hPopupWnd);
  96. SetForegroundWindow(hPopupWnd);
  97. }
  98. goto ModuleExit;
  99. }
  100. //
  101. // Initialize and create an instance of the Registry Editor window.
  102. //
  103. if ((g_pHelpFileName = LoadDynamicString(IDS_HELPFILENAME)) == NULL)
  104. goto ModuleExit;
  105. if (!RegisterRegEditClass() || !RegisterHexEditClass())
  106. goto ModuleExit;
  107. if ((hRegEditAccel = LoadAccelerators(g_hInstance,
  108. MAKEINTRESOURCE(IDACCEL_REGEDIT))) == NULL)
  109. goto ModuleExit;
  110. if ((g_hRegEditWnd = CreateRegEditWnd()) != NULL) {
  111. while (GetMessage(&Msg, NULL, 0, 0)) {
  112. if (g_fDisableAccelerators || !TranslateAccelerator(g_hRegEditWnd,
  113. hRegEditAccel, &Msg)) {
  114. TranslateMessage(&Msg);
  115. DispatchMessage(&Msg);
  116. }
  117. }
  118. }
  119. ModuleExit:
  120. ExitProcess(0);
  121. return 0;
  122. }
  123. /*******************************************************************************
  124. *
  125. * ParseCommandline
  126. *
  127. * DESCRIPTION:
  128. *
  129. * PARAMETERS:
  130. * (returns), TRUE to continuing loading, else FALSE to stop immediately.
  131. *
  132. *******************************************************************************/
  133. UINT
  134. PASCAL
  135. ParseCommandLine(
  136. VOID
  137. )
  138. {
  139. BOOL fSilentMode;
  140. BOOL fExportMode;
  141. LPTSTR lpCmdLine;
  142. LPTSTR lpFileName;
  143. LPTSTR lpSelectedPath;
  144. fSilentMode = FALSE;
  145. fExportMode = FALSE;
  146. lpCmdLine = GetCommandLine();
  147. //
  148. // Skip past the application pathname. Be sure to handle long filenames
  149. // correctly.
  150. //
  151. if (*lpCmdLine == TEXT('\"')) {
  152. do
  153. lpCmdLine = CharNext(lpCmdLine);
  154. while (*lpCmdLine != 0 && *lpCmdLine != TEXT('\"'));
  155. if (*lpCmdLine == TEXT('\"'))
  156. lpCmdLine = CharNext(lpCmdLine);
  157. }
  158. else {
  159. while (*lpCmdLine > TEXT(' '))
  160. lpCmdLine = CharNext(lpCmdLine);
  161. }
  162. while (*lpCmdLine != 0 && *lpCmdLine <= TEXT(' '))
  163. lpCmdLine = CharNext(lpCmdLine);
  164. while (TRUE) {
  165. while (*lpCmdLine == TEXT(' '))
  166. lpCmdLine = CharNext(lpCmdLine);
  167. if (*lpCmdLine != TEXT('/') && *lpCmdLine != TEXT('-'))
  168. break;
  169. lpCmdLine = CharNext(lpCmdLine);
  170. while (*lpCmdLine != 0 && *lpCmdLine != TEXT(' ')) {
  171. switch (*lpCmdLine) {
  172. case TEXT('m'):
  173. case TEXT('M'):
  174. //
  175. // Allow multiple instances mode. Pretend we are the only
  176. // copy of regedit running.
  177. //
  178. g_hRegEditWnd = NULL;
  179. break;
  180. //
  181. // Specifies the location of the SYSTEM.DAT and USER.DAT
  182. // files in real-mode. We don't use these switches, but
  183. // we do need to bump past the filename.
  184. //
  185. case TEXT('l'):
  186. case TEXT('L'):
  187. case TEXT('r'):
  188. case TEXT('R'):
  189. return PARSERET_EXIT;
  190. case TEXT('e'):
  191. case TEXT('E'):
  192. fExportMode = TRUE;
  193. break;
  194. case TEXT('a'):
  195. case TEXT('A'):
  196. fExportMode = TRUE;
  197. g_RegEditData.uExportFormat = FILE_TYPE_REGEDIT4;
  198. break;
  199. case TEXT('s'):
  200. case TEXT('S'):
  201. //
  202. // Silent mode where we don't show any dialogs when we
  203. // import a registry file script.
  204. //
  205. fSilentMode = TRUE;
  206. break;
  207. case TEXT('v'):
  208. case TEXT('V'):
  209. //
  210. // With the Windows 3.1 Registry Editor, this brought up
  211. // the tree-style view. Now we always show the tree so
  212. // nothing to do here!
  213. //
  214. // FALL THROUGH
  215. case TEXT('u'):
  216. case TEXT('U'):
  217. //
  218. // Update, don't overwrite existing path entries in
  219. // shell\open\command or shell\open\print. This isn't even
  220. // used by the Windows 3.1 Registry Editor!
  221. //
  222. // FALL THROUGH
  223. default:
  224. break;
  225. }
  226. lpCmdLine = CharNext(lpCmdLine);
  227. }
  228. }
  229. if (!fExportMode) {
  230. if (*lpCmdLine == 0)
  231. return PARSERET_CONTINUE;
  232. else {
  233. lpFileName = GetNextSubstring(lpCmdLine);
  234. while (lpFileName != NULL) {
  235. RegEdit_ImportRegFile(NULL, fSilentMode, lpFileName, NULL);
  236. lpFileName = GetNextSubstring(NULL);
  237. }
  238. return PARSERET_REFRESH;
  239. }
  240. }
  241. else
  242. {
  243. lpFileName = GetNextSubstring(lpCmdLine);
  244. lpSelectedPath = GetNextSubstring(NULL);
  245. if (GetNextSubstring(NULL) == NULL)
  246. RegEdit_ExportRegFile(NULL, fSilentMode, lpFileName, lpSelectedPath);
  247. return PARSERET_EXIT;
  248. }
  249. }
  250. /*******************************************************************************
  251. *
  252. * IsRegistryToolDisabled
  253. *
  254. * DESCRIPTION:
  255. * Checks the policy section of the registry to see if registry editing
  256. * tools should be disabled. This switch is set by administrators to
  257. * protect novice users.
  258. *
  259. * The Registry Editor is disabled if and only if this value exists and is
  260. * set.
  261. *
  262. * PARAMETERS:
  263. * (returns), TRUE if registry tool should not be run, else FALSE.
  264. *
  265. *******************************************************************************/
  266. BOOL
  267. PASCAL
  268. IsRegistryToolDisabled(
  269. VOID
  270. )
  271. {
  272. BOOL fRegistryToolDisabled;
  273. HKEY hKey;
  274. DWORD Type;
  275. DWORD ValueBuffer;
  276. DWORD cbValueBuffer;
  277. fRegistryToolDisabled = FALSE;
  278. if ( RegOpenKey( HKEY_CURRENT_USER,
  279. REGSTR_PATH_POLICIES TEXT("\\") REGSTR_KEY_SYSTEM,
  280. &hKey)
  281. == ERROR_SUCCESS )
  282. {
  283. cbValueBuffer = sizeof(DWORD);
  284. if (RegEdit_QueryValueEx(hKey, REGSTR_VAL_DISABLEREGTOOLS, NULL, &Type,
  285. (LPSTR) &ValueBuffer, &cbValueBuffer) == ERROR_SUCCESS)
  286. {
  287. if ( (Type == REG_DWORD) &&
  288. (cbValueBuffer == sizeof(DWORD)) &&
  289. (ValueBuffer != FALSE) )
  290. {
  291. fRegistryToolDisabled = TRUE;
  292. }
  293. }
  294. RegCloseKey(hKey);
  295. }
  296. return fRegistryToolDisabled;
  297. }