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.

168 lines
4.3 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995.
  5. //
  6. // File: debug.c
  7. //
  8. // Contents:
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. // History: 10-02-96 RichardW Created
  15. //
  16. //----------------------------------------------------------------------------
  17. #include "sslp.h"
  18. #if DBG // NOTE: This file not compiled for retail builds
  19. DEBUG_KEY SslDebugKeys[] = { {DEB_ERROR, "Error"},
  20. {DEB_WARN, "Warning"},
  21. {DEB_TRACE, "Trace"},
  22. {DEB_TRACE_FUNC, "Func"},
  23. {DEB_TRACE_CRED, "Cred"},
  24. {DEB_TRACE_CTXT, "Ctxt"},
  25. {DEB_TRACE_MAPPER, "Mapper"},
  26. {0, NULL}
  27. };
  28. DEFINE_DEBUG2( Ssl );
  29. void
  30. InitDebugSupport(
  31. HKEY hGlobalKey)
  32. {
  33. static BOOL fFirstTime = TRUE;
  34. CHAR szFileName[MAX_PATH];
  35. CHAR szDirectoryName[MAX_PATH];
  36. DWORD dwSize;
  37. DWORD dwType;
  38. DWORD err;
  39. DWORD fVal;
  40. HKEY hkBase;
  41. DWORD disp;
  42. SslInitDebug(SslDebugKeys);
  43. // SslInfoLevel |= DEB_TRACE_MAPPER ;
  44. if(hGlobalKey)
  45. {
  46. // We're running in the lsass.exe process.
  47. hkBase = hGlobalKey;
  48. }
  49. else
  50. {
  51. err = RegCreateKeyEx(HKEY_LOCAL_MACHINE,
  52. SP_REG_KEY_BASE,
  53. 0,
  54. TEXT(""),
  55. REG_OPTION_NON_VOLATILE,
  56. KEY_READ,
  57. NULL,
  58. &hkBase,
  59. &disp);
  60. if(err)
  61. {
  62. DebugLog((DEB_WARN,"Failed to open SCHANNEL key: 0x%x\n", err));
  63. return;
  64. }
  65. }
  66. dwSize = sizeof(DWORD);
  67. err = RegQueryValueEx(hkBase, SP_REG_VAL_LOGLEVEL, NULL, &dwType, (PUCHAR)&fVal, &dwSize);
  68. if(!err)
  69. {
  70. g_dwInfoLevel = fVal;
  71. }
  72. dwSize = sizeof(DWORD);
  73. err = RegQueryValueEx(hkBase, SP_REG_VAL_BREAK, NULL, &dwType, (PUCHAR)&fVal, &dwSize);
  74. if(!err)
  75. {
  76. g_dwDebugBreak = fVal;
  77. }
  78. if(g_hfLogFile)
  79. {
  80. CloseHandle(g_hfLogFile);
  81. g_hfLogFile = NULL;
  82. }
  83. dwSize = 255;
  84. err = RegQueryValueExA(hkBase, SP_REG_VAL_LOGFILE, NULL, &dwType, (PUCHAR)szDirectoryName, &dwSize);
  85. if(!err)
  86. {
  87. if(hGlobalKey)
  88. {
  89. strcpy(szFileName, szDirectoryName);
  90. strcat(szFileName, "\\Schannel.log");
  91. }
  92. else
  93. {
  94. sprintf(szFileName,"%s\\Schannel_%d.log",szDirectoryName,GetCurrentProcessId());
  95. }
  96. g_hfLogFile = CreateFileA(szFileName,
  97. GENERIC_WRITE,
  98. FILE_SHARE_READ | FILE_SHARE_WRITE,
  99. NULL, OPEN_ALWAYS,
  100. FILE_ATTRIBUTE_NORMAL,
  101. NULL);
  102. if(g_hfLogFile)
  103. {
  104. SetFilePointer(g_hfLogFile, 0, 0, FILE_END);
  105. }
  106. if(fFirstTime == TRUE)
  107. {
  108. SYSTEMTIME stTime;
  109. GetLocalTime(&stTime);
  110. DebugLog((SP_LOG_ERROR, "==== SCHANNEL LOG INITIATED %d/%d/%d %02d:%02d:%02d ====\n",
  111. stTime.wMonth, stTime.wDay, stTime.wYear,
  112. stTime.wHour, stTime.wMinute, stTime.wSecond));
  113. dwSize = sizeof(szFileName);
  114. if(GetModuleFileNameA(NULL, szFileName, dwSize) != 0)
  115. {
  116. DebugLog((SP_LOG_ERROR, "Module name:%s\n", szFileName));
  117. }
  118. }
  119. fFirstTime = FALSE;
  120. }
  121. if(hGlobalKey == NULL)
  122. {
  123. RegCloseKey(hkBase);
  124. }
  125. }
  126. VOID
  127. UnloadDebugSupport(
  128. VOID
  129. )
  130. {
  131. SslUnloadDebug();
  132. }
  133. #else // DBG
  134. #pragma warning(disable:4206) // Disable the empty translation unit
  135. // warning/error
  136. #endif // NOTE: This file not compiled for retail builds