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.

152 lines
2.9 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1998 - 1999
  3. Module Name:
  4. trcUtils
  5. Abstract:
  6. This module provides utility services for the CSP Trace functions.
  7. Author:
  8. Doug Barlow (dbarlow) 5/18/1998
  9. Notes:
  10. ?Notes?
  11. --*/
  12. #ifndef WIN32_LEAN_AND_MEAN
  13. #define WIN32_LEAN_AND_MEAN
  14. #endif
  15. #include <windows.h>
  16. #ifndef _WIN32_WINNT
  17. #define _WIN32_WINNT 0x0400
  18. #endif
  19. #include <wincrypt.h>
  20. #include <stdlib.h>
  21. #include <iostream.h>
  22. #include <iomanip.h>
  23. #include <tchar.h>
  24. #include <scardlib.h>
  25. #include "cspTrace.h"
  26. static const TCHAR l_szLogCsp[] = TEXT("LogCsp.dll");
  27. /*++
  28. FindLogCsp:
  29. This routine locates the LogCsp.dll file on the disk.
  30. Arguments:
  31. None
  32. Return Value:
  33. The full path name of the LogCsp.dll.
  34. Author:
  35. Doug Barlow (dbarlow) 5/18/1998
  36. --*/
  37. LPCTSTR
  38. FindLogCsp(
  39. void)
  40. {
  41. static TCHAR szLogCspPath[MAX_PATH] = TEXT("");
  42. SUBACTION("Searching for the Logging CSP Image");
  43. if (0 == szLogCspPath[0])
  44. {
  45. DWORD dwSts;
  46. LPTSTR szFile;
  47. dwSts = SearchPath(
  48. NULL,
  49. l_szLogCsp,
  50. NULL,
  51. sizeof(szLogCspPath),
  52. szLogCspPath,
  53. &szFile);
  54. ASSERT(sizeof(szLogCspPath) >= dwSts);
  55. if (0 == dwSts)
  56. {
  57. szLogCspPath[0] = 0;
  58. throw GetLastError();
  59. }
  60. }
  61. return szLogCspPath;
  62. }
  63. /*++
  64. FindLoggedCsp:
  65. This routine scans the CSP registry, looking for an entry that points to
  66. the Logging CSP. If more than one such entry exists, only the first one is
  67. returned.
  68. Arguments:
  69. None
  70. Return Value:
  71. The name of a CSP that is being logged, or NULL.
  72. Author:
  73. Doug Barlow (dbarlow) 5/18/1998
  74. --*/
  75. LPCTSTR
  76. FindLoggedCsp(
  77. void)
  78. {
  79. static TCHAR szCspName[MAX_PATH];
  80. SUBACTION("Searching for a Logged CSP");
  81. CRegistry
  82. rgCspDefault(
  83. HKEY_LOCAL_MACHINE,
  84. TEXT("SOFTWARE\\Microsoft\\Cryptography\\Defaults\\Provider"),
  85. KEY_READ);
  86. CRegistry rgCsp;
  87. LPCTSTR szCsp, szCspPath;
  88. DWORD dwIndex, dwLen;
  89. LONG nCompare;
  90. for (dwIndex = 0;; dwIndex += 1)
  91. {
  92. szCsp = rgCspDefault.Subkey(dwIndex);
  93. if (NULL == szCsp)
  94. break;
  95. rgCsp.Open(rgCspDefault, szCsp, KEY_READ);
  96. szCspPath = rgCsp.GetStringValue(TEXT("Image Path"));
  97. dwLen = lstrlen(szCspPath);
  98. if (dwLen >= (sizeof(l_szLogCsp) - 1) / sizeof(TCHAR))
  99. nCompare = lstrcmpi(
  100. l_szLogCsp,
  101. &szCspPath[dwLen - (sizeof(l_szLogCsp) - 1) / sizeof(TCHAR)]);
  102. else
  103. nCompare = -1;
  104. rgCsp.Close();
  105. if (0 == nCompare)
  106. {
  107. lstrcpy(szCspName, szCsp);
  108. return szCspName;
  109. }
  110. }
  111. return NULL;
  112. }