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.

134 lines
3.7 KiB

  1. #include "precomp.h"
  2. #include "winmgmt.h"
  3. #include "backuprestore.h"
  4. //***************************************************************************
  5. //
  6. // CForwardFactory::AddRef()
  7. // CForwardFactory::Release()
  8. // CForwardFactory::QueryInterface()
  9. // CForwardFactory::CreateInstance()
  10. //
  11. // DESCRIPTION:
  12. //
  13. // Class factory for the exported WbemNTLMLogin interface. Note that this
  14. // just serves as a wrapper to the factory inside the core. The reason for
  15. // having a wrapper is that the core may not always be loaded.
  16. //
  17. //***************************************************************************
  18. ULONG STDMETHODCALLTYPE CForwardFactory::AddRef()
  19. {
  20. return InterlockedIncrement(&m_lRef);
  21. }
  22. ULONG STDMETHODCALLTYPE CForwardFactory::Release()
  23. {
  24. long lRef = InterlockedDecrement(&m_lRef);
  25. if(lRef == 0)
  26. delete this;
  27. return lRef;
  28. }
  29. HRESULT STDMETHODCALLTYPE CForwardFactory::QueryInterface(REFIID riid,
  30. void** ppv)
  31. {
  32. if(riid == IID_IUnknown || riid == IID_IClassFactory)
  33. {
  34. *ppv = (IClassFactory*)this;
  35. AddRef();
  36. return S_OK;
  37. }
  38. else return E_NOINTERFACE;
  39. }
  40. #ifdef INSTRUMENTED_BUILD
  41. #ifdef _X86_
  42. extern BOOL g_FaultHeapEnabled;
  43. extern BOOL g_FaultFileEnabled;
  44. extern LONG g_nSuccConn;
  45. #endif
  46. #endif
  47. HRESULT STDMETHODCALLTYPE CForwardFactory::CreateInstance(IUnknown* pUnkOuter,
  48. REFIID riid, void** ppv)
  49. {
  50. DEBUGTRACE((LOG_WINMGMT, "CForwardFactory::CreateInstance\n"));
  51. SCODE sc = S_OK;
  52. CInMutex im(g_ProgRes.hMainMutex);
  53. try
  54. {
  55. if(g_ProgRes.bShuttingDownWinMgmt)
  56. {
  57. DEBUGTRACE((LOG_WINMGMT, "CreateInstance returned CO_E_SERVER_STOPPING\n"));
  58. return CO_E_SERVER_STOPPING;
  59. }
  60. if(m_ForwardClsid == CLSID_WbemBackupRestore)
  61. {
  62. CWbemBackupRestore * pObj = new CWbemBackupRestore(g_hInstance);
  63. if (!pObj)
  64. return WBEM_E_OUT_OF_MEMORY;
  65. sc = pObj->QueryInterface(riid, ppv);
  66. if(FAILED(sc))
  67. delete pObj;
  68. }
  69. else // tertium non datur
  70. {
  71. HMODULE hCoreModule = LoadLibraryEx(__TEXT("wbemcore.dll"),NULL,0);
  72. if(hCoreModule)
  73. {
  74. HRESULT (STDAPICALLTYPE *pfn)(DWORD);
  75. pfn = (long (__stdcall *)(DWORD))GetProcAddress(hCoreModule, "Reinitialize");
  76. if(pfn == NULL)
  77. sc = WBEM_E_CRITICAL_ERROR;
  78. else
  79. {
  80. pfn(0);
  81. sc = CoCreateInstance(CLSID_InProcWbemLevel1Login, NULL,
  82. CLSCTX_INPROC_SERVER , IID_IUnknown,
  83. (void**)ppv);
  84. if (FAILED(sc))
  85. DEBUGTRACE((LOG_WINMGMT, "CoCreateInstance(CLSID_InProcWbemLevel1Login) returned\n: 0x%X\n", sc));
  86. }
  87. FreeLibrary(hCoreModule);
  88. }
  89. else
  90. sc = WBEM_E_CRITICAL_ERROR;
  91. #ifdef INSTRUMENTED_BUILD
  92. #ifdef _X86_
  93. /*
  94. if (++g_nSuccConn > 500)
  95. {
  96. g_FaultHeapEnabled = TRUE;
  97. g_FaultFileEnabled = TRUE;
  98. };
  99. */
  100. #endif
  101. #endif
  102. }
  103. }
  104. catch (...)
  105. {
  106. ERRORTRACE((LOG_WINMGMT,"--------------- CForwardFactory::Exception thrown from CreateInstance -------------\n"));
  107. sc = E_NOINTERFACE;
  108. }
  109. return sc;
  110. }
  111. HRESULT STDMETHODCALLTYPE CForwardFactory::LockServer(BOOL fLock)
  112. {
  113. return S_OK;
  114. }
  115. CForwardFactory::~CForwardFactory()
  116. {
  117. }