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.

140 lines
3.3 KiB

  1. /*****************************************************************************\
  2. Author: Corey Morgan (coreym)
  3. Copyright (c) 1998-2000 Microsoft Corporation
  4. \*****************************************************************************/
  5. #include <fwcommon.h>
  6. #include <pdhp.h>
  7. #define SECURITY_WIN32
  8. #include <security.h>
  9. #include "smlogprv.h"
  10. CSmonLog SysmonLogProv1( PROVIDER_NAME_SMONLOG, L"root\\wmi" );
  11. CSmonLog SysmonLogProv2( PROVIDER_NAME_SMONLOG, L"root\\perfmon" );
  12. CSmonLog::CSmonLog (LPCWSTR lpwszName, LPCWSTR lpwszNameSpace ) :
  13. Provider(lpwszName, lpwszNameSpace)
  14. {
  15. }
  16. CSmonLog::~CSmonLog ()
  17. {
  18. }
  19. HRESULT
  20. CSmonLog::EnumerateInstances( MethodContext* pMethodContext, long lFlags )
  21. {
  22. HRESULT hr = WBEM_S_NO_ERROR;
  23. DWORD dwSize = 0;
  24. LPTSTR mszCollections = NULL;
  25. hr = PdhPlaEnumCollections( NULL, &dwSize, mszCollections );
  26. mszCollections = (LPTSTR)malloc( dwSize * sizeof(TCHAR) );
  27. if( mszCollections ){
  28. LPTSTR strCollection;
  29. hr = PdhPlaEnumCollections( NULL, &dwSize, mszCollections );
  30. if( hr == ERROR_SUCCESS ){
  31. strCollection = mszCollections;
  32. while( strCollection != NULL && *strCollection != '\0' ){
  33. CInstance *pInstance = CreateNewInstance(pMethodContext);
  34. if( SUCCEEDED( LoadPropertyValues(pInstance, strCollection ) )){
  35. hr = pInstance->Commit();
  36. }
  37. pInstance->Release();
  38. strCollection += ( _tcslen( strCollection ) + 1 );
  39. }
  40. }
  41. }
  42. return hr;
  43. }
  44. HRESULT CSmonLog::GetObject ( CInstance* pInstance, long lFlags )
  45. {
  46. HRESULT hr = WBEM_E_NOT_FOUND;
  47. CHString Name;
  48. PDH_PLA_INFO_W info;
  49. DWORD dwSize = sizeof(PDH_PLA_INFO_W);
  50. ZeroMemory( &info, dwSize );
  51. pInstance->GetCHString( L"Name", Name );
  52. hr = PdhPlaGetInfoW( (LPWSTR)(LPCWSTR)Name, NULL, &dwSize, &info );
  53. return hr;
  54. }
  55. HRESULT
  56. CSmonLog::LoadPropertyValues(
  57. CInstance *pInstance,
  58. LPWSTR strName
  59. )
  60. {
  61. pInstance->SetCHString( L"Name", strName );
  62. return WBEM_S_NO_ERROR;
  63. }
  64. HRESULT CSmonLog::PutInstance( const CInstance &Instance, long lFlags )
  65. {
  66. HRESULT hr = WBEM_E_UNSUPPORTED_PARAMETER;
  67. return hr;
  68. }
  69. HRESULT
  70. CSmonLog::SetRunAs( const CInstance &Instance, CInstance *pInParams )
  71. {
  72. HRESULT hr;
  73. CHString Name;
  74. CHString User;
  75. CHString Password;
  76. Instance.GetCHString( L"Name", Name );
  77. pInParams->GetCHString( L"User", User );
  78. pInParams->GetCHString( L"Password", Password );
  79. RevertToSelf();
  80. hr = PdhiPlaSetRunAs( (LPWSTR)(LPCWSTR)Name, NULL, (LPWSTR)(LPCWSTR)User, (LPWSTR)(LPCWSTR)Password );
  81. return hr;
  82. }
  83. HRESULT
  84. CSmonLog::ExecMethod(
  85. const CInstance& Instance,
  86. const BSTR bstrMethodName,
  87. CInstance *pInParams,
  88. CInstance *pOutParams,
  89. long lFlags
  90. )
  91. {
  92. HRESULT hr = WBEM_E_METHOD_NOT_IMPLEMENTED;
  93. HRESULT hResult = ERROR_SUCCESS;
  94. if( _wcsicmp( bstrMethodName, L"SetRunAs") == 0 ){
  95. hResult = SetRunAs( Instance, pInParams );
  96. hr = WBEM_S_NO_ERROR;
  97. }
  98. pOutParams->SetDWORD( L"ReturnValue", hResult );
  99. return hr;
  100. }