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.

182 lines
4.1 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996 - 1999
  5. //
  6. // File: assert.cpp
  7. //
  8. // Contents: Cert Server wrapper routines
  9. //
  10. //---------------------------------------------------------------------------
  11. #include <pch.cpp>
  12. #pragma hdrstop
  13. #define DBG_CERTSRV_DEBUG_PRINT
  14. #ifdef DBG_CERTSRV_DEBUG_PRINT
  15. __inline VOID CSDbgBreakPoint(VOID)
  16. {
  17. DebugBreak();
  18. }
  19. //+---------------------------------------------------------------------------
  20. // Function: CSPrintAssert, public
  21. //
  22. // Synopsis: Display message and break
  23. //
  24. // Arguments: [pszFailedAssertion] -- failed assertion in string form
  25. // [pszFileName] -- filename
  26. // [LineNumber] -- line number
  27. // [pszMessage] -- optional message
  28. //
  29. // Returns: None
  30. //----------------------------------------------------------------------------
  31. char const *
  32. csTrimPath(
  33. char const *pszFile)
  34. {
  35. char const *psz;
  36. char *pszT;
  37. char const *pszTrim;
  38. static char s_path[MAX_PATH];
  39. if (NULL == pszFile)
  40. {
  41. pszFile = "null.cpp";
  42. }
  43. pszTrim = pszFile;
  44. psz = strrchr(pszFile, '\\');
  45. if (NULL != psz)
  46. {
  47. DWORD count = 1;
  48. while (count != 0 && psz > pszFile)
  49. {
  50. if (*--psz == '\\')
  51. {
  52. if (0 == strncmp(psz, "\\..\\", 4) ||
  53. 0 == strncmp(psz, "\\.\\", 3))
  54. {
  55. count++;
  56. }
  57. else
  58. {
  59. count--;
  60. pszTrim = &psz[1];
  61. }
  62. }
  63. }
  64. if (strlen(pszTrim) < ARRAYSIZE(s_path))
  65. {
  66. pszT = s_path;
  67. while ('\0' != *pszTrim)
  68. {
  69. if ('\\' == *pszTrim)
  70. {
  71. if (0 == strncmp(pszTrim, "\\..\\", 4))
  72. {
  73. pszTrim += 3;
  74. continue;
  75. }
  76. if (0 == strncmp(pszTrim, "\\.\\", 3))
  77. {
  78. pszTrim += 2;
  79. continue;
  80. }
  81. }
  82. *pszT++ = *pszTrim++;
  83. }
  84. *pszT = '\0';
  85. pszTrim = s_path;
  86. }
  87. }
  88. return(pszTrim);
  89. }
  90. VOID
  91. CSPrintAssert(
  92. IN char const *DBGPARMREFERENCED(pszFailedAssertion),
  93. IN char const *DBGPARMREFERENCED(pszFileName),
  94. IN ULONG DBGPARMREFERENCED(LineNumber),
  95. OPTIONAL IN char const *DBGPARMREFERENCED(pszMessage))
  96. {
  97. BOOLEAN fReprint;
  98. do
  99. {
  100. fReprint = FALSE;
  101. DBGPRINT((
  102. DBG_SS_ASSERT,
  103. "\n"
  104. "*** Certificate Services Assertion failed: %hs %hs\n"
  105. "*** Source File: %hs, line %ld\n"
  106. "\n",
  107. pszMessage == NULL? "" : pszMessage,
  108. pszFailedAssertion,
  109. csTrimPath(pszFileName),
  110. LineNumber));
  111. if (IsDebuggerPresent())
  112. {
  113. #if i386
  114. _asm xor al,al
  115. #endif
  116. CSDbgBreakPoint();
  117. #if i386
  118. _asm mov byte ptr [fReprint],al
  119. #endif
  120. }
  121. }
  122. while (fReprint);
  123. }
  124. VOID
  125. CSPrintError(
  126. IN char const *pszMessage,
  127. OPTIONAL IN WCHAR const *pwszData,
  128. IN char const *DBGPARMREFERENCED(pszFile),
  129. IN DWORD DBGPARMREFERENCED(dwLine),
  130. IN HRESULT hr,
  131. IN HRESULT hrquiet)
  132. {
  133. char acherr[1024];
  134. DBGCODE(WCHAR awchr[cwcHRESULTSTRING]);
  135. if (myShouldPrintError(hr, hrquiet))
  136. {
  137. if (NULL != pwszData)
  138. {
  139. LONG cch;
  140. #pragma prefast(disable:53, "PREfast bug 650")
  141. cch = _snprintf(
  142. acherr,
  143. sizeof(acherr),
  144. "%hs(%ws)",
  145. pszMessage,
  146. pwszData);
  147. #pragma prefast(enable:53, "re-enable")
  148. if (0 > cch || sizeof(acherr) <= cch)
  149. {
  150. strcpy(&acherr[sizeof(acherr) - 4], "...");
  151. }
  152. pszMessage = acherr;
  153. }
  154. DBGPRINT((
  155. DBG_SS_ERROR,
  156. "%hs(%u): %hs: error %ws\n",
  157. csTrimPath(pszFile),
  158. dwLine,
  159. pszMessage,
  160. myHResultToString(awchr, hr)));
  161. }
  162. }
  163. #endif // DBG_CERTSRV_DEBUG_PRINT