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.

205 lines
5.2 KiB

  1. #include "precomp.h"
  2. #include <commain.h>
  3. #include <clsfac.h>
  4. #include <arrtempl.h>
  5. #include "fconprov.h"
  6. #include "fevprov.h"
  7. // Function pointer type used with LoadMofFiles entrypoint in wbemupgd.dll
  8. typedef BOOL ( WINAPI *PFN_LOAD_MOF_FILES )(wchar_t* pComponentName, const char* rgpszMofFilename[]);
  9. // {AD1B46E8-0AAC-401b-A3B8-FCDCF8186F55}
  10. static const CLSID CLSID_FwdConsProvider =
  11. {0xad1b46e8, 0xaac, 0x401b, {0xa3, 0xb8, 0xfc, 0xdc, 0xf8, 0x18, 0x6f, 0x55}};
  12. // {7879E40D-9FB5-450a-8A6D-00C89F349FCE}
  13. static const CLSID CLSID_FwdEventProvider =
  14. {0x7879e40d, 0x9fb5, 0x450a, {0x8a, 0x6d, 0x0, 0xc8, 0x9f, 0x34, 0x9f, 0xce}};
  15. #define REG_WBEM_FWD TEXT("Software\\Microsoft\\WBEM\\FWD")
  16. class CFwdConsProviderServer : public CComServer
  17. {
  18. protected:
  19. void Register();
  20. void Unregister();
  21. HRESULT Initialize();
  22. void Uninitialize() { CFwdConsProv::UninitializeModule(); }
  23. } g_Server;
  24. BOOL AllowUnauthenticatedEvents()
  25. {
  26. //
  27. // look up in registry if we will allow unauthenticated forwarded events.
  28. //
  29. HKEY hKey;
  30. LONG lRes;
  31. BOOL bAllowUnauth = FALSE;
  32. lRes = RegOpenKey( HKEY_LOCAL_MACHINE, REG_WBEM_FWD, &hKey );
  33. if ( lRes == ERROR_SUCCESS )
  34. {
  35. DWORD dwAllowUnauth;
  36. DWORD dwBuffSize = 4;
  37. lRes = RegQueryValueEx( hKey,
  38. TEXT("AllowUnauthenticatedEvents"),
  39. 0,
  40. NULL,
  41. (BYTE*)&dwAllowUnauth,
  42. &dwBuffSize );
  43. if ( lRes == ERROR_SUCCESS )
  44. {
  45. bAllowUnauth = dwAllowUnauth != 0 ? TRUE : FALSE;
  46. }
  47. RegCloseKey( hKey );
  48. }
  49. return bAllowUnauth;
  50. }
  51. HRESULT CFwdConsProviderServer::Initialize()
  52. {
  53. ENTER_API_CALL
  54. HRESULT hr;
  55. hr = CFwdConsProv::InitializeModule();
  56. if ( FAILED(hr) )
  57. {
  58. return hr;
  59. }
  60. CWbemPtr<CBaseClassFactory> pFactory;
  61. pFactory = new CSimpleClassFactory<CFwdConsProv>(GetLifeControl());
  62. if ( pFactory == NULL )
  63. {
  64. return WBEM_E_OUT_OF_MEMORY;
  65. }
  66. hr = AddClassInfo( CLSID_FwdConsProvider,
  67. pFactory,
  68. TEXT("Forwarding Consumer Provider"),
  69. TRUE );
  70. if ( FAILED(hr) )
  71. {
  72. return hr;
  73. }
  74. pFactory = new CClassFactory<CFwdEventProv>( GetLifeControl() );
  75. if ( pFactory == NULL )
  76. {
  77. return WBEM_E_OUT_OF_MEMORY;
  78. }
  79. hr = AddClassInfo( CLSID_FwdEventProvider,
  80. pFactory,
  81. TEXT("Forwarding Event Provider"),
  82. TRUE );
  83. if ( FAILED(hr) )
  84. {
  85. return hr;
  86. }
  87. #ifdef __WHISTLER_UNCUT
  88. pFactory = new CClassFactory<CFwdAckEventProv>( GetLifeControl() );
  89. if ( pFactory == NULL )
  90. {
  91. return WBEM_E_OUT_OF_MEMORY;
  92. }
  93. hr = AddClassInfo( CLSID_FwdAckEventProvider,
  94. pFactory,
  95. TEXT("Forwarding Ack Event Provider"),
  96. TRUE );
  97. #endif
  98. return hr;
  99. EXIT_API_CALL
  100. }
  101. void CFwdConsProviderServer::Register()
  102. {
  103. HKEY hKey;
  104. LONG lRes;
  105. DWORD dwDisposition;
  106. lRes = RegCreateKeyEx( HKEY_LOCAL_MACHINE,
  107. REG_WBEM_FWD,
  108. 0,
  109. NULL,
  110. 0,
  111. KEY_ALL_ACCESS,
  112. NULL,
  113. &hKey,
  114. &dwDisposition );
  115. if ( lRes == ERROR_SUCCESS )
  116. {
  117. if ( dwDisposition == REG_CREATED_NEW_KEY )
  118. {
  119. DWORD dwAllowUnauth = 0;
  120. lRes = RegSetValueEx( hKey,
  121. TEXT("AllowUnauthenticatedEvents"),
  122. 0,
  123. REG_DWORD,
  124. (BYTE*)&dwAllowUnauth,
  125. 4 );
  126. }
  127. RegCloseKey( hKey );
  128. if ( lRes == ERROR_SUCCESS )
  129. {
  130. //
  131. // Load mofs and mfls during registration
  132. //
  133. HINSTANCE hinstWbemupgd = LoadLibrary(L"wbemupgd.dll");
  134. if (hinstWbemupgd)
  135. {
  136. PFN_LOAD_MOF_FILES pfnLoadMofFiles = (PFN_LOAD_MOF_FILES) GetProcAddress(hinstWbemupgd, "LoadMofFiles"); // no wide version of GetProcAddress
  137. if (pfnLoadMofFiles)
  138. {
  139. wchar_t* wszComponentName = L"Fwdprov";
  140. const char* rgpszMofFilename[] =
  141. {
  142. "fconprov.mof",
  143. "fconprov.mfl",
  144. "fevprov.mof",
  145. "fevprov.mfl",
  146. NULL
  147. };
  148. pfnLoadMofFiles(wszComponentName, rgpszMofFilename);
  149. }
  150. FreeLibrary(hinstWbemupgd);
  151. }
  152. }
  153. }
  154. }
  155. void CFwdConsProviderServer::Unregister()
  156. {
  157. RegDeleteKey( HKEY_LOCAL_MACHINE, REG_WBEM_FWD );
  158. }