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.

216 lines
5.1 KiB

  1. /*++
  2. Copyright (c) 1987-1993 Microsoft Corporation
  3. Module Name:
  4. debug.cxx
  5. Abstract:
  6. Support routines allowing the NtLmSsp DLL side use the common routines
  7. shared between the DLL and the SERVICE.
  8. These routines exist in the DLL side. They are different implementations
  9. of the same routines that exist on the SERVICE side. These implementations
  10. are significantly simpler because they run in the address space of the
  11. caller.
  12. Author:
  13. Cliff Van Dyke (CliffV) 22-Sep-1993
  14. Environment:
  15. User mode only.
  16. Contains NT-specific code.
  17. Requires ANSI C extensions: slash-slash comments, long external names.
  18. Revision History:
  19. ChandanS 03-Aug-1996 Stolen from net\svcdlls\ntlmssp\client\support.c
  20. --*/
  21. //
  22. // Common include files.
  23. //
  24. #include <global.h>
  25. #if DBG
  26. #include <stdio.h>
  27. #define MAX_PRINTF_LEN 1024 // Arbitrary.
  28. VOID
  29. SspPrintRoutine(
  30. IN DWORD DebugFlag,
  31. IN LPSTR Format,
  32. ...
  33. )
  34. {
  35. va_list arglist;
  36. char OutputBuffer[MAX_PRINTF_LEN];
  37. ULONG length;
  38. int cbUsed = 0;
  39. static BeginningOfLine = TRUE;
  40. static LineCount = 0;
  41. //
  42. // If we aren't debugging this functionality, just return.
  43. //
  44. if ( DebugFlag != 0 && (SspGlobalDbflag & DebugFlag) == 0 ) {
  45. return;
  46. }
  47. //
  48. // vsprintf isn't multithreaded + we don't want to intermingle output
  49. // from different threads.
  50. //
  51. EnterCriticalSection( &SspGlobalLogFileCritSect );
  52. length = 0;
  53. //
  54. // make sure it is null terminated
  55. //
  56. OutputBuffer[sizeof(OutputBuffer) - 1] = '\0';
  57. //
  58. // Handle the beginning of a new line.
  59. //
  60. //
  61. if ( BeginningOfLine )
  62. {
  63. //
  64. // If we're writing to the debug terminal,
  65. // indicate this is an NtLmSsp message.
  66. //
  67. cbUsed = _snprintf(&OutputBuffer[length], sizeof(OutputBuffer) - 1 - length, "[MSV1_0.dll] ");
  68. if (cbUsed <= 0)
  69. {
  70. goto Done;
  71. }
  72. length += cbUsed;
  73. //
  74. // Put the timestamp at the begining of the line.
  75. //
  76. IF_DEBUG( TIMESTAMP )
  77. {
  78. SYSTEMTIME SystemTime;
  79. GetLocalTime( &SystemTime );
  80. cbUsed = _snprintf( &OutputBuffer[length], sizeof(OutputBuffer) - 1 - length,
  81. "%02u/%02u %02u:%02u:%02u ",
  82. SystemTime.wMonth,
  83. SystemTime.wDay,
  84. SystemTime.wHour,
  85. SystemTime.wMinute,
  86. SystemTime.wSecond );
  87. if (cbUsed <= 0)
  88. {
  89. goto Done;
  90. }
  91. length += cbUsed;
  92. }
  93. //
  94. // Indicate the type of message on the line
  95. //
  96. {
  97. char *Text;
  98. switch (DebugFlag)
  99. {
  100. case SSP_INIT:
  101. Text = "INIT"; break;
  102. case SSP_MISC:
  103. Text = "MISC"; break;
  104. case SSP_LOGON_SESS:
  105. Text = "LOGON_SESS"; break;
  106. case SSP_CRITICAL:
  107. Text = "CRITICAL"; break;
  108. case SSP_LEAK_TRACK:
  109. Text = "LEAK_TRACK"; break;
  110. case SSP_WARNING:
  111. Text = "WARNING"; break;
  112. case SSP_LPC:
  113. case SSP_LPC_MORE:
  114. Text = "LPC"; break;
  115. case SSP_API:
  116. Text = "API"; break;
  117. case SSP_API_MORE:
  118. Text = "APIMORE"; break;
  119. case SSP_SESSION_KEYS:
  120. Text = "SESSION_KEYS"; break;
  121. case SSP_NEGOTIATE_FLAGS:
  122. Text = "NEGOTIATE_FLAGS"; break;
  123. case SSP_UPDATES:
  124. Text = "UPDATES"; break;
  125. case SSP_NTLM_V2:
  126. Text = "NTLM_V2"; break;
  127. case SSP_CRED:
  128. Text = "CRED"; break;
  129. case SSP_VERSION:
  130. Text = "VER"; break;
  131. default:
  132. Text = "UNKNOWN"; break;
  133. case 0:
  134. Text = NULL;
  135. }
  136. if ( Text != NULL )
  137. {
  138. cbUsed = _snprintf( &OutputBuffer[length], sizeof(OutputBuffer) - 1 - length,
  139. "[%s] ", Text );
  140. if (cbUsed <= 0)
  141. {
  142. goto Done;
  143. }
  144. length += cbUsed;
  145. }
  146. }
  147. }
  148. //
  149. // Put a the information requested by the caller onto the line
  150. //
  151. va_start(arglist, Format);
  152. cbUsed = _vsnprintf(&OutputBuffer[length], sizeof(OutputBuffer) - 1 - length,
  153. Format, arglist);
  154. va_end(arglist);
  155. if (cbUsed <= 0)
  156. {
  157. goto Done;
  158. }
  159. length += cbUsed;
  160. Done:
  161. BeginningOfLine = (length > 0 && OutputBuffer[length - 1] == '\n' );
  162. //
  163. // just output to the debug terminal
  164. //
  165. (void) DbgPrint( (PCH) OutputBuffer);
  166. LeaveCriticalSection( &SspGlobalLogFileCritSect );
  167. } // SspPrintRoutine
  168. #endif // DBG