Source code of Windows XP (NT5)
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.

147 lines
3.3 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1999 - 1999
  6. //
  7. // File: log.cpp
  8. //
  9. // Contents: implements policy and exit module logging routines.
  10. //
  11. //--------------------------------------------------------------------------
  12. #include <pch.cpp>
  13. #pragma hdrstop
  14. #include "csdisp.h"
  15. BOOL
  16. LogModuleStatus(
  17. IN HMODULE hModule,
  18. IN DWORD dwLogID, // Resource ID of log string
  19. IN BOOL fPolicy,
  20. IN WCHAR const *pwszSource,
  21. IN WCHAR const * const *ppwszInsert) // array of insert strings
  22. {
  23. HRESULT hr = S_OK;
  24. BOOL fResult = FALSE;
  25. WCHAR *pwszResult = NULL;
  26. ICreateErrorInfo *pCreateErrorInfo = NULL;
  27. IErrorInfo *pErrorInfo = NULL;
  28. if (0 == FormatMessage(
  29. FORMAT_MESSAGE_ALLOCATE_BUFFER |
  30. FORMAT_MESSAGE_ARGUMENT_ARRAY |
  31. FORMAT_MESSAGE_FROM_HMODULE,
  32. hModule,
  33. dwLogID,
  34. 0,
  35. (WCHAR *) &pwszResult,
  36. 0,
  37. (va_list *) ppwszInsert))
  38. {
  39. goto error;
  40. }
  41. DBGPRINT((DBG_SS_CERTPOL, "LogPolicyStatus: %ws\n", pwszResult));
  42. hr = CreateErrorInfo(&pCreateErrorInfo);
  43. _JumpIfError(hr, error, "CreateErrorInfo");
  44. hr = pCreateErrorInfo->SetGUID(fPolicy? IID_ICertPolicy : IID_ICertExit);
  45. _PrintIfError(hr, "SetGUID");
  46. hr = pCreateErrorInfo->SetDescription(pwszResult);
  47. _PrintIfError(hr, "SetDescription");
  48. // Set ProgId:
  49. hr = pCreateErrorInfo->SetSource(const_cast<WCHAR *>(pwszSource));
  50. _PrintIfError(hr, "SetSource");
  51. hr = pCreateErrorInfo->QueryInterface(
  52. IID_IErrorInfo,
  53. (VOID **) &pErrorInfo);
  54. _JumpIfError(hr, error, "QueryInterface");
  55. SetErrorInfo(0, pErrorInfo);
  56. fResult = TRUE;
  57. error:
  58. if (NULL != pwszResult)
  59. {
  60. LocalFree(pwszResult);
  61. }
  62. if (NULL != pErrorInfo)
  63. {
  64. pErrorInfo->Release();
  65. }
  66. if (NULL != pCreateErrorInfo)
  67. {
  68. pCreateErrorInfo->Release();
  69. }
  70. return(fResult);
  71. }
  72. HRESULT
  73. LogPolicyEvent(
  74. IN HMODULE hModule,
  75. IN DWORD dwLogID, // Resource ID of log string
  76. IN ICertServerPolicy *pServer,
  77. IN WCHAR const *pwszPropEvent,
  78. IN WCHAR const * const *ppwszInsert) // array of insert strings
  79. {
  80. HRESULT hr;
  81. WCHAR *pwszValue = NULL;
  82. BSTR strName = NULL;
  83. VARIANT varValue;
  84. if (0 == FormatMessage(
  85. FORMAT_MESSAGE_ALLOCATE_BUFFER |
  86. FORMAT_MESSAGE_ARGUMENT_ARRAY |
  87. FORMAT_MESSAGE_FROM_HMODULE,
  88. hModule,
  89. dwLogID,
  90. 0,
  91. (WCHAR *) &pwszValue,
  92. 0,
  93. (va_list *) ppwszInsert))
  94. {
  95. hr = myHLastError();
  96. _JumpError(hr, error, "FormatMessage");
  97. }
  98. DBGPRINT((DBG_SS_CERTPOL, "LogPolicyEvent: %ws\n", pwszValue));
  99. varValue.vt = VT_EMPTY;
  100. if (!myConvertWszToBstr(&strName, pwszPropEvent, -1))
  101. {
  102. hr = E_OUTOFMEMORY;
  103. _JumpError(hr, error, "myConvertWszToBstr");
  104. }
  105. varValue.bstrVal = NULL;
  106. if (!myConvertWszToBstr(&varValue.bstrVal, pwszValue, -1))
  107. {
  108. hr = E_OUTOFMEMORY;
  109. _JumpError(hr, error, "myConvertWszToBstr");
  110. }
  111. varValue.vt = VT_BSTR;
  112. hr = pServer->SetCertificateProperty(strName, PROPTYPE_STRING, &varValue);
  113. _JumpIfError(hr, error, "SetCertificateProperty");
  114. error:
  115. VariantClear(&varValue);
  116. if (NULL != strName)
  117. {
  118. SysFreeString(strName);
  119. }
  120. if (NULL != pwszValue)
  121. {
  122. LocalFree(pwszValue);
  123. }
  124. return(hr);
  125. }