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.

170 lines
3.7 KiB

  1. /*++
  2. Copyright (C) 1997-2001 Microsoft Corporation
  3. Module Name:
  4. LOCATOR.CPP
  5. Abstract:
  6. Defines the Locator object
  7. History:
  8. a-davj 15-Aug-96 Created.
  9. --*/
  10. #include "precomp.h"
  11. #include <wbemidl.h>
  12. #include <wbemint.h>
  13. #include <reg.h>
  14. #include <wbemutil.h>
  15. #include <wbemprox.h>
  16. #include <flexarry.h>
  17. #include "locator.h"
  18. #include "comtrans.h"
  19. #include <arrtempl.h>
  20. #include <helper.h>
  21. #include <strsafe.h>
  22. //***************************************************************************
  23. //
  24. // CLocator::CLocator
  25. //
  26. // DESCRIPTION:
  27. //
  28. // Constructor.
  29. //
  30. //***************************************************************************
  31. CLocator::CLocator()
  32. {
  33. m_cRef=0;
  34. InterlockedIncrement(&g_cObj);
  35. }
  36. //***************************************************************************
  37. //
  38. // CLocator::~CLocator
  39. //
  40. // DESCRIPTION:
  41. //
  42. // Destructor.
  43. //
  44. //***************************************************************************
  45. CLocator::~CLocator(void)
  46. {
  47. InterlockedDecrement(&g_cObj);
  48. }
  49. //***************************************************************************
  50. // HRESULT CLocator::QueryInterface
  51. //
  52. // DESCRIPTION:
  53. //
  54. // Standard Com IUNKNOWN functions.
  55. //
  56. //***************************************************************************
  57. STDMETHODIMP CLocator::QueryInterface (
  58. IN REFIID riid,
  59. OUT PPVOID ppv
  60. )
  61. {
  62. *ppv=NULL;
  63. if (IID_IUnknown==riid || riid == IID_IWbemLocator)
  64. *ppv=this;
  65. if (NULL!=*ppv)
  66. {
  67. ((LPUNKNOWN)*ppv)->AddRef();
  68. return NOERROR;
  69. }
  70. return ResultFromScode(E_NOINTERFACE);
  71. }
  72. ///////////////////////////////////////////////
  73. BOOL IsWinMgmtShutdown(void)
  74. {
  75. HMODULE hMudule = NULL;
  76. if (GetModuleHandleEx(0,L"wmisvc.dll",&hMudule))
  77. {
  78. OnDelete<HMODULE,BOOL(*)(HMODULE),FreeLibrary> FreeMe(hMudule);
  79. BOOL (WINAPI * fnIsWinMgmtDown)(VOID);
  80. fnIsWinMgmtDown = (BOOL (WINAPI *)(VOID))GetProcAddress(hMudule,"IsShutDown");
  81. if (fnIsWinMgmtDown) return fnIsWinMgmtDown();
  82. }
  83. return FALSE;
  84. }
  85. //***************************************************************************
  86. //
  87. // SCODE CLocator::ConnectServer
  88. //
  89. // DESCRIPTION:
  90. //
  91. // Connects up to either local or remote WBEM Server. Returns
  92. // standard SCODE and more importantly sets the address of an initial
  93. // stub pointer.
  94. //
  95. // PARAMETERS:
  96. //
  97. // NetworkResource Namespace path
  98. // User User name
  99. // Password password
  100. // LocaleId language locale
  101. // lFlags flags
  102. // Authority domain
  103. // ppProv set to provdider proxy
  104. //
  105. // RETURN VALUE:
  106. //
  107. // S_OK all is well
  108. // else error listed in WBEMSVC.H
  109. //
  110. //***************************************************************************
  111. SCODE CLocator::ConnectServer (
  112. IN const BSTR NetworkResource,
  113. IN const BSTR User,
  114. IN const BSTR Password,
  115. IN const BSTR LocaleId,
  116. IN long lFlags,
  117. IN const BSTR Authority,
  118. IWbemContext __RPC_FAR *pCtx,
  119. OUT IWbemServices FAR* FAR* ppProv
  120. )
  121. {
  122. if (IsWinMgmtShutdown()) return CO_E_SERVER_STOPPING;
  123. long lRes;
  124. SCODE sc = WBEM_E_TRANSPORT_FAILURE;
  125. // Verify the arguments
  126. if(NetworkResource == NULL || ppProv == NULL)
  127. return WBEM_E_INVALID_PARAMETER;
  128. CDCOMTrans * pComTrans = new CDCOMTrans();
  129. if(pComTrans == NULL)
  130. return WBEM_E_OUT_OF_MEMORY;
  131. pComTrans->AddRef();
  132. sc = pComTrans->DoConnection(NetworkResource, User, Password, LocaleId, lFlags, Authority,
  133. pCtx, ppProv);
  134. pComTrans->Release();
  135. return sc;
  136. }