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.

326 lines
7.8 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_BREAK_ON_ERROR, "BreakOnError"},
  80. {0, NULL},
  81. };
  82. DWORD BreakFlags = 0;
  83. DEFINE_DEBUG2(Neg);
  84. DEBUG_KEY NegDebugKeys[] = { {DEB_ERROR, "Error"},
  85. {DEB_WARN, "Warning"},
  86. {DEB_TRACE, "Trace"},
  87. {DEB_TRACE_LOCKS, "Locks"},
  88. {0, NULL},
  89. };
  90. extern DWORD NoUnload;
  91. CHAR DbgPackageName[] = "LSA Debug Package";
  92. LSA_AP_INITIALIZE_PACKAGE DbgInitialize;
  93. LSA_AP_CALL_PACKAGE DbgCallPackage;
  94. LSA_AP_CALL_PACKAGE_UNTRUSTED DbgCallPackageUntrusted;
  95. LSA_AP_CALL_PACKAGE_PASSTHROUGH DbgCallPackagePassthrough;
  96. SECPKG_FUNCTION_TABLE DbgTable = {
  97. DbgInitialize,
  98. NULL,
  99. DbgCallPackage,
  100. NULL,
  101. DbgCallPackage,
  102. DbgCallPackage,
  103. NULL,
  104. NULL,
  105. NULL
  106. };
  107. // Debugging support functions.
  108. // These two functions do not exist in Non-Debug builds. They are wrappers
  109. // to the commnot functions (maybe I should get rid of that as well...)
  110. // that echo the message to a log file.
  111. char szSection[] = "SPMgr";
  112. typedef struct _DebugKeys {
  113. char * Name;
  114. DWORD Value;
  115. } DebugKeys, *PDebugKeys;
  116. DebugKeys BreakKeyNames[] = {
  117. {"InitBegin", BREAK_ON_BEGIN_INIT},
  118. {"InitEnd", BREAK_ON_BEGIN_END},
  119. {"Connect", BREAK_ON_P_CONNECT},
  120. {"Exception", BREAK_ON_SP_EXCEPT},
  121. {"Problem", BREAK_ON_PROBLEM},
  122. {"Shutdown", BREAK_ON_SHUTDOWN},
  123. {"Load", BREAK_ON_LOAD}
  124. };
  125. #define NUM_BREAK_KEYS (sizeof(BreakKeyNames) / sizeof(DebugKeys))
  126. DWORD
  127. GetDebugKeyValue(
  128. PDebugKeys KeyTable,
  129. int cKeys,
  130. LPSTR pszKey)
  131. {
  132. int i;
  133. for (i = 0; i < cKeys ; i++ )
  134. {
  135. if (_strcmpi(KeyTable[i].Name, pszKey) == 0)
  136. {
  137. return(KeyTable[i].Value);
  138. }
  139. }
  140. return(0);
  141. }
  142. //+---------------------------------------------------------------------------
  143. //
  144. // Function: LoadDebugParameters
  145. //
  146. // Synopsis: Loads debug parameters from win.ini
  147. //
  148. // Effects:
  149. //
  150. // Arguments: (none)
  151. //
  152. // Requires:
  153. //
  154. // Returns:
  155. //
  156. // Signals:
  157. //
  158. // Modifies:
  159. //
  160. // Algorithm:
  161. //
  162. // History: 4-29-93 RichardW Created
  163. //
  164. // Notes:
  165. //
  166. //----------------------------------------------------------------------------
  167. void
  168. LoadDebugParameters(void)
  169. {
  170. char szVal[128];
  171. char * pszDebug;
  172. int cbVal;
  173. if (SPMInfoLevel & DEB_BREAK_ON_ERROR)
  174. {
  175. SPMSetOption( DEBUG_BREAK_ON_ERROR, TRUE, TRUE );
  176. cbVal = GetProfileStringA(szSection, "BreakFlags", "", szVal, sizeof(szVal));
  177. if (cbVal)
  178. {
  179. pszDebug = strtok(szVal, ", \t");
  180. while (pszDebug)
  181. {
  182. BreakFlags |= GetDebugKeyValue(BreakKeyNames, NUM_BREAK_KEYS,
  183. pszDebug);
  184. pszDebug = strtok(NULL, ", \t");
  185. }
  186. } // If break flags exists
  187. }
  188. }
  189. //+---------------------------------------------------------------------------
  190. //
  191. // Function: InitDebugSupport
  192. //
  193. // Synopsis: Initializes debugging support for the SPMgr
  194. //
  195. // Effects:
  196. //
  197. // Arguments: (none)
  198. //
  199. // Requires:
  200. //
  201. // Returns:
  202. //
  203. // Signals:
  204. //
  205. // Modifies:
  206. //
  207. // Algorithm:
  208. //
  209. // History: 4-29-93 RichardW Created
  210. //
  211. // Notes:
  212. //
  213. //----------------------------------------------------------------------------
  214. void
  215. InitDebugSupport(void)
  216. {
  217. SPMInitDebug(SpmgrDebugKeys);
  218. LoadDebugParameters();
  219. }
  220. SECURITY_STATUS
  221. SEC_ENTRY
  222. DbgInitialize(
  223. IN ULONG AuthenticationPackageId,
  224. IN PLSA_DISPATCH_TABLE LsaDispatchTable,
  225. IN PSTRING Database OPTIONAL,
  226. IN PSTRING Confidentiality OPTIONAL,
  227. OUT PSTRING *AuthenticationPackageName
  228. )
  229. {
  230. PSTRING Name ;
  231. Name = (PSTRING) LsapAllocateLsaHeap( sizeof( STRING ) );
  232. if ( Name )
  233. {
  234. Name->Buffer = (PSTR) LsapAllocateLsaHeap( sizeof( DbgPackageName ) );
  235. Name->Length = sizeof( DbgPackageName ) - 1;
  236. Name->MaximumLength = sizeof( DbgPackageName );
  237. if ( Name->Buffer )
  238. {
  239. strcpy( Name->Buffer, DbgPackageName );
  240. *AuthenticationPackageName = Name ;
  241. return TRUE ;
  242. }
  243. else
  244. {
  245. LsapFreeLsaHeap( Name );
  246. }
  247. }
  248. return FALSE ;
  249. }
  250. NTSTATUS
  251. DbgCallPackage(
  252. IN PLSA_CLIENT_REQUEST ClientRequest,
  253. IN PVOID ProtocolSubmitBuffer,
  254. IN PVOID ClientBufferBase,
  255. IN ULONG SubmitBufferLength,
  256. OUT PVOID *ProtocolReturnBuffer,
  257. OUT PULONG ReturnBufferLength,
  258. OUT PNTSTATUS ProtocolStatus
  259. )
  260. {
  261. return STATUS_INVALID_PARAMETER ;
  262. }
  263. #else // DBG
  264. #pragma warning(disable:4206) // Disable the empty transation unit
  265. // warning/error
  266. #endif // NOTE: This file not compiled for retail builds