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.

309 lines
8.0 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1993.
  5. //
  6. // File: debug.c
  7. //
  8. // Contents: Debugging support functions
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. // Note: This file is not compiled for retail builds
  15. //
  16. // History: 4-29-93 RichardW Created
  17. //
  18. //----------------------------------------------------------------------------
  19. #include <lsapch.hxx>
  20. extern "C"
  21. {
  22. #define ANSI
  23. #include <stdarg.h>
  24. }
  25. //
  26. // For ease of debugging the SPMgr, all the debug support functions have
  27. // been stuck here. Basically, we read info from win.ini, since that allows
  28. // us to configure the debug level via a text file (and DOS, for example).
  29. //
  30. // Format is:
  31. //
  32. // win.ini
  33. //
  34. // [SPM]
  35. // DebugFlags=<Flag>[<,Flag>]*
  36. // BreakFlags=<BreakFlag>[<,BreakFlags>]*
  37. //
  38. // WHERE:
  39. // Flag is one of the following:
  40. // Error, Warning, Trace, Verbose, BreakOnError, Helpers,
  41. // RefMon, Locator, WAPI, Init, Audit, Db, Lsa
  42. //
  43. // BreakFlags will cause SPMgr to break, if BreakOnError is set in
  44. // DebugFlags:
  45. // InitBegin, InitEnd, Connect, Exception, Problem, Load
  46. //
  47. //
  48. #if DBG // NOTE: This file not compiled for retail builds
  49. extern "C"
  50. {
  51. WINBASEAPI
  52. BOOL
  53. WINAPI
  54. IsDebuggerPresent(
  55. VOID
  56. );
  57. }
  58. DEFINE_DEBUG2(SPM);
  59. DEBUG_KEY SpmgrDebugKeys[] = { {DEB_ERROR, "Error"},
  60. {DEB_WARN, "Warning"},
  61. {DEB_TRACE, "Trace"},
  62. {DEB_TRACE_VERB, "Verbose"},
  63. {DEB_TRACE_WAPI, "WAPI"},
  64. {DEB_TRACE_HELPERS, "Helpers"},
  65. {DEB_TRACE_RM, "RefMon"},
  66. {DEB_TRACE_INIT, "Init"},
  67. {DEB_TRACE_SCAV, "Scav"},
  68. {DEB_TRACE_CRED, "Cred"},
  69. {DEB_TRACE_NEG, "Neg"},
  70. {DEB_TRACE_LPC, "LPC"},
  71. {DEB_TRACE_SAM, "SAM"},
  72. {DEB_TRACE_LSA, "LSA"},
  73. {DEB_TRACE_SPECIAL, "Special"},
  74. {DEB_TRACE_QUEUE, "Queue"},
  75. {DEB_TRACE_HANDLES, "Handles"},
  76. {DEB_TRACE_NEG_LOCKS, "NegLock"},
  77. {DEB_TRACE_AUDIT, "Audit"},
  78. {DEB_TRACE_EFS, "EFS"},
  79. {DEB_TRACE_FRAG, "NegFrag"},
  80. {DEB_BREAK_ON_ERROR, "BreakOnError"},
  81. {0, NULL},
  82. };
  83. DWORD BreakFlags = 0;
  84. DEFINE_DEBUG2(Neg);
  85. DEBUG_KEY NegDebugKeys[] = { {DEB_ERROR, "Error"},
  86. {DEB_WARN, "Warning"},
  87. {DEB_TRACE, "Trace"},
  88. {DEB_TRACE_LOCKS, "Locks"},
  89. {0, NULL},
  90. };
  91. extern DWORD NoUnload;
  92. CHAR DbgPackageName[] = "LSA Debug Package";
  93. LSA_AP_INITIALIZE_PACKAGE DbgInitialize;
  94. LSA_AP_CALL_PACKAGE DbgCallPackage;
  95. SECPKG_FUNCTION_TABLE DbgTable = {
  96. DbgInitialize,
  97. NULL,
  98. DbgCallPackage,
  99. NULL,
  100. DbgCallPackage,
  101. DbgCallPackage,
  102. NULL,
  103. NULL,
  104. NULL
  105. };
  106. // Debugging support functions.
  107. // These two functions do not exist in Non-Debug builds. They are wrappers
  108. // to the commnot functions (maybe I should get rid of that as well...)
  109. // that echo the message to a log file.
  110. char szSection[] = "SPMgr";
  111. typedef struct _DebugKeys {
  112. char * Name;
  113. DWORD Value;
  114. } DebugKeys, *PDebugKeys;
  115. DebugKeys BreakKeyNames[] = {
  116. {"InitBegin", BREAK_ON_BEGIN_INIT},
  117. {"InitEnd", BREAK_ON_BEGIN_END},
  118. {"Connect", BREAK_ON_P_CONNECT},
  119. {"Exception", BREAK_ON_SP_EXCEPT},
  120. {"Problem", BREAK_ON_PROBLEM},
  121. {"Shutdown", BREAK_ON_SHUTDOWN},
  122. {"Load", BREAK_ON_LOAD}
  123. };
  124. #define NUM_BREAK_KEYS (sizeof(BreakKeyNames) / sizeof(DebugKeys))
  125. DWORD
  126. GetDebugKeyValue(
  127. PDebugKeys KeyTable,
  128. int cKeys,
  129. LPSTR pszKey)
  130. {
  131. int i;
  132. for (i = 0; i < cKeys ; i++ )
  133. {
  134. if (_strcmpi(KeyTable[i].Name, pszKey) == 0)
  135. {
  136. return(KeyTable[i].Value);
  137. }
  138. }
  139. return(0);
  140. }
  141. //+---------------------------------------------------------------------------
  142. //
  143. // Function: LoadDebugParameters
  144. //
  145. // Synopsis: Loads debug parameters from win.ini
  146. //
  147. // Effects:
  148. //
  149. // Arguments: (none)
  150. //
  151. // Requires:
  152. //
  153. // Returns:
  154. //
  155. // Signals:
  156. //
  157. // Modifies:
  158. //
  159. // Algorithm:
  160. //
  161. // History: 4-29-93 RichardW Created
  162. //
  163. // Notes:
  164. //
  165. //----------------------------------------------------------------------------
  166. void
  167. LoadDebugParameters(void)
  168. {
  169. char szVal[128];
  170. char * pszDebug;
  171. int cbVal;
  172. if (SPMInfoLevel & DEB_BREAK_ON_ERROR)
  173. {
  174. SPMSetOption( DEBUG_BREAK_ON_ERROR, TRUE, TRUE );
  175. cbVal = GetProfileStringA(szSection, "BreakFlags", "", szVal, sizeof(szVal));
  176. if (cbVal)
  177. {
  178. pszDebug = strtok(szVal, ", \t");
  179. while (pszDebug)
  180. {
  181. BreakFlags |= GetDebugKeyValue(BreakKeyNames, NUM_BREAK_KEYS,
  182. pszDebug);
  183. pszDebug = strtok(NULL, ", \t");
  184. }
  185. } // If break flags exists
  186. }
  187. }
  188. //+---------------------------------------------------------------------------
  189. //
  190. // Function: InitDebugSupport
  191. //
  192. // Synopsis: Initializes debugging support for the SPMgr
  193. //
  194. // Effects:
  195. //
  196. // Arguments: (none)
  197. //
  198. // Requires:
  199. //
  200. // Returns:
  201. //
  202. // Signals:
  203. //
  204. // Modifies:
  205. //
  206. // Algorithm:
  207. //
  208. // History: 4-29-93 RichardW Created
  209. //
  210. // Notes:
  211. //
  212. //----------------------------------------------------------------------------
  213. void
  214. InitDebugSupport(void)
  215. {
  216. SPMInitDebug(SpmgrDebugKeys);
  217. LoadDebugParameters();
  218. }
  219. SECURITY_STATUS
  220. SEC_ENTRY
  221. DbgInitialize(
  222. IN ULONG AuthenticationPackageId,
  223. IN PLSA_DISPATCH_TABLE LsaDispatchTable,
  224. IN OPTIONAL PSTRING Database,
  225. IN OPTIONAL PSTRING Confidentiality,
  226. OUT PSTRING *AuthenticationPackageName
  227. )
  228. {
  229. PSTRING Name ;
  230. Name = (PSTRING) LsapAllocateLsaHeap( sizeof( STRING ) );
  231. if ( Name )
  232. {
  233. Name->Buffer = (PSTR) LsapAllocateLsaHeap( sizeof( DbgPackageName ) );
  234. Name->Length = sizeof( DbgPackageName ) - 1;
  235. Name->MaximumLength = sizeof( DbgPackageName );
  236. if ( Name->Buffer )
  237. {
  238. strcpy( Name->Buffer, DbgPackageName );
  239. *AuthenticationPackageName = Name ;
  240. return TRUE ;
  241. }
  242. else
  243. {
  244. LsapFreeLsaHeap( Name );
  245. }
  246. }
  247. return FALSE ;
  248. }
  249. NTSTATUS
  250. DbgCallPackage(
  251. IN PLSA_CLIENT_REQUEST ClientRequest,
  252. IN PVOID ProtocolSubmitBuffer,
  253. IN PVOID ClientBufferBase,
  254. IN ULONG SubmitBufferLength,
  255. OUT PVOID *ProtocolReturnBuffer,
  256. OUT PULONG ReturnBufferLength,
  257. OUT PNTSTATUS ProtocolStatus
  258. )
  259. {
  260. return STATUS_INVALID_PARAMETER ;
  261. }
  262. #else // DBG
  263. #pragma warning(disable:4206) // Disable the empty transation unit
  264. // warning/error
  265. #endif // NOTE: This file not compiled for retail builds