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.

227 lines
4.0 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. All rights reserved
  4. Module Name:
  5. sspioutput.cxx
  6. Abstract:
  7. sspioutput
  8. Author:
  9. Larry Zhu (LZhu) December 1, 2001 Created
  10. Environment:
  11. User Mode -Win32
  12. Revision History:
  13. --*/
  14. // #include "precomp.hxx"
  15. // #pragma hdrstop
  16. extern "C" {
  17. #define SECURITY_KERNEL
  18. #include <ntosp.h>
  19. #include <zwapi.h>
  20. #include <security.h>
  21. #include <ntlmsp.h>
  22. #include <string.h>
  23. #include <wcstr.h>
  24. #include <ntiologc.h>
  25. #include <tchar.h>
  26. }
  27. #include "sspioutput.hxx"
  28. #include "ntstatus.hxx"
  29. TSspiLibarayGlobals g_SspiGlobals = {
  30. 1, // major version
  31. 2, // minor version
  32. 0xF, // debug mask
  33. TEXT("SSPI"), // debug prompt
  34. };
  35. #if defined(UNICODE) || defined(_UNICODE)
  36. #define lstrlen wcslen
  37. #endif
  38. WCHAR SspiToChar(IN UCHAR c)
  39. {
  40. UCHAR* pChar = &c;
  41. if ((c >= ' ') && (c <= '~'))
  42. {
  43. return RtlAnsiCharToUnicodeChar(&pChar);
  44. }
  45. return TEXT('.');
  46. }
  47. VOID SspiSpaceIt(IN ULONG cchLen, IN TCHAR* buf)
  48. {
  49. for (ULONG i = 0; i < cchLen; i++)
  50. {
  51. buf[i] = TEXT(' ');
  52. }
  53. }
  54. TCHAR SspiToHex(
  55. IN ULONG c
  56. )
  57. {
  58. static PCTSTR pszDigits = TEXT("0123456789abcdef");
  59. static ULONG len = lstrlen(pszDigits);
  60. if (c <= len)
  61. { // c >= 0
  62. return pszDigits[c];
  63. }
  64. return TEXT('*');
  65. }
  66. VOID
  67. SspiPrintHex(
  68. IN ULONG ulLevel,
  69. IN OPTIONAL PCTSTR pszBanner,
  70. IN ULONG cbBuffer,
  71. IN const VOID* pvbuffer
  72. )
  73. {
  74. if (g_SspiGlobals.uDebugMask & ulLevel)
  75. {
  76. const UCHAR* pBuffer = reinterpret_cast<const UCHAR*>(pvbuffer);
  77. ULONG high = 0;
  78. ULONG low = 0;
  79. TCHAR szLine[256] = {0};
  80. ULONG i = 0;
  81. OutputDebugString(pszBanner);
  82. OutputDebugString(TEXT("\n"));
  83. SspiSpaceIt(72, szLine);
  84. for (i = 0; i < cbBuffer; i++)
  85. {
  86. high = pBuffer[i] / 16;
  87. low = pBuffer[i] % 16;
  88. szLine[3 * (i % 16)] = SspiToHex(high);
  89. szLine[3 * (i % 16) + 1] = SspiToHex(low);
  90. szLine [52 + (i % 16)] = SspiToChar(pBuffer[i]);
  91. if (i % 16 == 7 && i != (cbBuffer - 1))
  92. {
  93. szLine[3 * (i % 16) + 2] = TEXT('-');
  94. }
  95. if (i % 16 == 15)
  96. {
  97. OutputDebugString(szLine);
  98. OutputDebugString(TEXT("\n"));
  99. SspiSpaceIt(72, szLine);
  100. }
  101. }
  102. OutputDebugString(szLine);
  103. OutputDebugString(TEXT("\n"));
  104. }
  105. }
  106. PCTSTR
  107. SspiLevel2Str(
  108. IN ULONG ulLevel
  109. )
  110. {
  111. PCTSTR pszText = NULL;
  112. switch (ulLevel)
  113. {
  114. case SSPI_WARN:
  115. pszText = TEXT("[warn]");
  116. break;
  117. case SSPI_ERROR:
  118. pszText = TEXT("[error]");
  119. break;
  120. case SSPI_LOG:
  121. pszText = TEXT("[log]");
  122. break;
  123. case SSPI_LOG_MORE:
  124. pszText = TEXT("[more]");
  125. break;
  126. case SSPI_MSG:
  127. pszText = TEXT("[msg]");
  128. break;
  129. default:
  130. pszText = TEXT("[invalid]");
  131. break;
  132. }
  133. return pszText;
  134. }
  135. VOID
  136. SspiLogOpen(
  137. IN PCTSTR pszPrompt,
  138. IN ULONG ulMask
  139. )
  140. {
  141. g_SspiGlobals.uDebugMask = ulMask;
  142. g_SspiGlobals.pszDbgPrompt = pszPrompt;
  143. }
  144. VOID
  145. SspiLogClose(
  146. VOID
  147. )
  148. {
  149. g_SspiGlobals.uDebugMask = 0;
  150. g_SspiGlobals.pszDbgPrompt = NULL;
  151. }
  152. VOID
  153. SspiPrint(
  154. IN ULONG ulLevel,
  155. IN PCTSTR pszOutput
  156. )
  157. {
  158. if (g_SspiGlobals.uDebugMask & ulLevel)
  159. {
  160. OutputDebugString(pszOutput);
  161. }
  162. }
  163. void OutputDebugString(PCTSTR pszBuff)
  164. {
  165. #if defined(UNICODE) || defined(_UNICODE)
  166. UNICODE_STRING Buff = {0};
  167. ANSI_STRING AnsiBuff = {0};
  168. RtlInitUnicodeString(&Buff, pszBuff);
  169. RtlUnicodeStringToAnsiString(&AnsiBuff, &Buff, TRUE);
  170. DebugPrint((AnsiBuff.Buffer));
  171. RtlFreeAnsiString(&AnsiBuff);
  172. #else
  173. DebugPrint((pszBuff));
  174. #endif
  175. }