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.

220 lines
7.2 KiB

  1. //*************************************************************
  2. //
  3. // Debug.c - Debugging utility for User Environments
  4. //
  5. // Microsoft Confidential
  6. // Copyright (c) Microsoft Corporation 1995
  7. // All rights reserved
  8. //
  9. //*************************************************************
  10. #include <nt.h>
  11. #include <ntrtl.h>
  12. #include <nturtl.h>
  13. #include <windows.h>
  14. #include <ntexapi.h>
  15. #include "debug.h"
  16. int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
  17. LPSTR lpCmdLine, INT nCmdShow)
  18. {
  19. DialogBox (hInstance, TEXT("DEBUG"), NULL, DebugDlgProc);
  20. return 0;
  21. }
  22. BOOL CALLBACK DebugDlgProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  23. {
  24. switch (uMsg) {
  25. case WM_INITDIALOG:
  26. {
  27. HKEY hKey;
  28. LONG lResult;
  29. DWORD dwButton = IDD_NORMAL;
  30. DWORD dwType, dwSize, dwValue;
  31. lResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  32. WINLOGON_KEY,
  33. 0,
  34. KEY_READ,
  35. &hKey);
  36. if (lResult == ERROR_SUCCESS) {
  37. dwSize = sizeof(dwValue);
  38. lResult = RegQueryValueEx(hKey,
  39. USERENV_DEBUG_LEVEL,
  40. NULL,
  41. &dwType,
  42. (LPBYTE)&dwValue,
  43. &dwSize);
  44. if (lResult == ERROR_SUCCESS) {
  45. if (LOWORD(dwValue) == DL_NONE) {
  46. dwButton = IDD_NONE;
  47. } else if (LOWORD(dwValue) == DL_VERBOSE) {
  48. dwButton = IDD_VERBOSE;
  49. }
  50. }
  51. RegCloseKey(hKey);
  52. }
  53. CheckRadioButton (hDlg, IDD_NONE, IDD_VERBOSE, dwButton);
  54. if (dwValue & DL_LOGFILE) {
  55. CheckDlgButton (hDlg, IDD_LOGFILE, 1);
  56. }
  57. //
  58. // Now check for winlogon
  59. //
  60. dwButton = 0;
  61. if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  62. EXEC_OPTIONS_KEY,
  63. 0,
  64. KEY_READ,
  65. &hKey) == ERROR_SUCCESS) {
  66. dwButton = 1;
  67. RegCloseKey(hKey);
  68. }
  69. CheckDlgButton (hDlg, IDD_WINLOGON, dwButton);
  70. }
  71. return TRUE;
  72. case WM_COMMAND:
  73. switch (LOWORD(wParam)) {
  74. case IDOK:
  75. {
  76. HKEY hKey;
  77. LONG lResult;
  78. DWORD dwType, dwValue = DL_NORMAL;
  79. DWORD dwButton, dwSize, dwDisp;
  80. if (IsDlgButtonChecked(hDlg, IDD_NONE)) {
  81. dwValue = DL_NONE;
  82. } else if (IsDlgButtonChecked(hDlg, IDD_VERBOSE)) {
  83. dwValue = (DL_VERBOSE | DL_DEBUGGER);
  84. }
  85. if (IsDlgButtonChecked(hDlg, IDD_LOGFILE)) {
  86. dwValue |= DL_LOGFILE;
  87. }
  88. lResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  89. WINLOGON_KEY,
  90. 0,
  91. KEY_WRITE,
  92. &hKey);
  93. if (lResult == ERROR_SUCCESS) {
  94. lResult = RegSetValueEx(hKey,
  95. USERENV_DEBUG_LEVEL,
  96. 0,
  97. REG_DWORD,
  98. (LPBYTE)&dwValue,
  99. sizeof(dwValue));
  100. if (lResult != ERROR_SUCCESS) {
  101. MessageBox(hDlg, TEXT("Failed to save settings."), NULL, MB_OK);
  102. }
  103. RegCloseKey(hKey);
  104. }
  105. //
  106. // Debug output for winlogon / msgina
  107. //
  108. if (dwValue & DL_VERBOSE) {
  109. WriteProfileString (TEXT("Winlogon"),
  110. TEXT("DebugFlags"),
  111. TEXT("Error,Warning,Trace,Init,Timeout,Sas,State,CoolSwitch,Profile,Notify,Job"));
  112. WriteProfileString (TEXT("Winlogon"),
  113. TEXT("EnableDesktopSwitching"),
  114. TEXT("1"));
  115. WriteProfileString (TEXT("MSGina"),
  116. TEXT("DebugFlags"),
  117. TEXT("Error,Warning,Trace,Domain,Cache"));
  118. } else {
  119. WriteProfileString (TEXT("Winlogon"),
  120. TEXT("DebugFlags"),
  121. NULL);
  122. WriteProfileString (TEXT("Winlogon"),
  123. TEXT("EnableDesktopSwitching"),
  124. NULL);
  125. WriteProfileString (TEXT("MSGina"),
  126. TEXT("DebugFlags"),
  127. NULL);
  128. }
  129. //
  130. // Now check for winlogon
  131. //
  132. if (IsDlgButtonChecked(hDlg, IDD_WINLOGON)) {
  133. if (RegCreateKeyEx(HKEY_LOCAL_MACHINE,
  134. EXEC_OPTIONS_KEY,
  135. 0,
  136. NULL,
  137. REG_OPTION_NON_VOLATILE,
  138. KEY_ALL_ACCESS,
  139. NULL,
  140. &hKey,
  141. &dwDisp) == ERROR_SUCCESS) {
  142. RegSetValueEx (hKey,
  143. TEXT("Debugger"),
  144. 0, REG_SZ,
  145. (LPBYTE) TEXT("ntsd -d -G"),
  146. 16);
  147. RegCloseKey (hKey);
  148. }
  149. } else {
  150. RegDeleteKey (HKEY_LOCAL_MACHINE,
  151. EXEC_OPTIONS_KEY);
  152. }
  153. EndDialog(hDlg, FALSE);
  154. return TRUE;
  155. }
  156. case IDCANCEL:
  157. EndDialog(hDlg, FALSE);
  158. return TRUE;
  159. }
  160. break;
  161. default:
  162. break;
  163. }
  164. return FALSE;
  165. }