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.

204 lines
5.3 KiB

  1. /*++
  2. Copyright (C) 1997-2001 Microsoft Corporation
  3. Module Name:
  4. CPROVLOC.CPP
  5. Abstract:
  6. Defines the CProviderLoc object
  7. History:
  8. davj 30-Oct-00 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 <strsafe.h>
  18. #include "cprovloc.h"
  19. #include "comtrans.h"
  20. #include <arrtempl.h>
  21. #define IsSlash(x) (x == L'\\' || x== L'/')
  22. //***************************************************************************
  23. //
  24. // CProviderLoc::CProviderLoc
  25. //
  26. // DESCRIPTION:
  27. //
  28. // Constructor.
  29. //
  30. //***************************************************************************
  31. CProviderLoc::CProviderLoc(DWORD dwType)
  32. {
  33. m_cRef=0;
  34. InterlockedIncrement(&g_cObj);
  35. m_dwType = dwType;
  36. }
  37. //***************************************************************************
  38. //
  39. // CProviderLoc::~CProviderLoc
  40. //
  41. // DESCRIPTION:
  42. //
  43. // Destructor.
  44. //
  45. //***************************************************************************
  46. CProviderLoc::~CProviderLoc(void)
  47. {
  48. InterlockedDecrement(&g_cObj);
  49. }
  50. //***************************************************************************
  51. // HRESULT CProviderLoc::QueryInterface
  52. //
  53. // DESCRIPTION:
  54. //
  55. // Standard Com IUNKNOWN functions.
  56. //
  57. //***************************************************************************
  58. STDMETHODIMP CProviderLoc::QueryInterface (
  59. IN REFIID riid,
  60. OUT PPVOID ppv
  61. )
  62. {
  63. *ppv=NULL;
  64. if (IID_IUnknown==riid || riid == IID_IWbemLocator)
  65. *ppv=this;
  66. if (NULL!=*ppv)
  67. {
  68. ((LPUNKNOWN)*ppv)->AddRef();
  69. return NOERROR;
  70. }
  71. return ResultFromScode(E_NOINTERFACE);
  72. }
  73. //***************************************************************************
  74. //
  75. // SCODE CProviderLoc::ConnectServer
  76. //
  77. // DESCRIPTION:
  78. //
  79. // Connects up to either local or remote WBEM Server. Returns
  80. // standard SCODE and more importantly sets the address of an initial
  81. // stub pointer.
  82. //
  83. // PARAMETERS:
  84. //
  85. // NetworkResource Namespace path
  86. // User User name
  87. // Password password
  88. // LocaleId language locale
  89. // lFlags flags
  90. // Authority domain
  91. // ppProv set to provdider proxy
  92. //
  93. // RETURN VALUE:
  94. //
  95. // S_OK all is well
  96. // else error listed in WBEMSVC.H
  97. //
  98. //***************************************************************************
  99. SCODE CProviderLoc::ConnectServer (
  100. IN const BSTR NetworkResource,
  101. IN const BSTR User,
  102. IN const BSTR Password,
  103. IN const BSTR LocaleId,
  104. IN long lFlags,
  105. IN const BSTR Authority,
  106. IWbemContext __RPC_FAR *pCtx,
  107. OUT IWbemServices FAR* FAR* ppProv
  108. )
  109. {
  110. SCODE sc = S_OK;
  111. BOOL bOutOfProc = FALSE; // Set below
  112. IWbemLocator * pActualLocator = NULL;
  113. IWbemLevel1Login * pLevel1 = NULL;
  114. if(NetworkResource == NULL || ppProv == NULL)
  115. return WBEM_E_INVALID_PARAMETER;
  116. // make sure they are not specifying a server
  117. LPWSTR ObjectPath = NetworkResource;
  118. if (IsSlash(ObjectPath[0]) && IsSlash(ObjectPath[1]))
  119. {
  120. if(!IsSlash(ObjectPath[3]) || ObjectPath[2] != L'.')
  121. return WBEM_E_INVALID_PARAMETER;
  122. }
  123. // Get the normal login pointer.
  124. sc = CoCreateInstance(CLSID_WbemLevel1Login, NULL,
  125. CLSCTX_LOCAL_SERVER | CLSCTX_INPROC_SERVER, IID_IWbemLevel1Login,(void **)&pLevel1);
  126. if(FAILED(sc))
  127. return sc;
  128. CReleaseMe rm(pLevel1);
  129. // determine if winmgmt is inproc. Do so by checking if there is an IClientSecurity interface
  130. IClientSecurity * pCliSec = NULL;
  131. sc = pLevel1->QueryInterface(IID_IClientSecurity, (void **)&pCliSec);
  132. if(SUCCEEDED(sc) && pCliSec)
  133. {
  134. // We are out of proc, then use the current dcomtrans logic
  135. pCliSec->Release();
  136. CDCOMTrans * pDcomTrans = new CDCOMTrans;
  137. if(pDcomTrans == NULL)
  138. return WBEM_E_OUT_OF_MEMORY;
  139. pDcomTrans->AddRef();
  140. sc = pDcomTrans->DoConnection(NetworkResource, User, Password, LocaleId, lFlags,
  141. Authority, pCtx, ppProv);
  142. pDcomTrans->Release();
  143. return sc;
  144. }
  145. // If we are inproc, get the class from wbemcore.dll and forward the call on to it.
  146. switch(m_dwType)
  147. {
  148. case ADMINLOC:
  149. sc = CoCreateInstance(CLSID_ActualWbemAdministrativeLocator, NULL,
  150. CLSCTX_INPROC_SERVER, IID_IWbemLocator,(void **)&pActualLocator);
  151. break;
  152. case AUTHLOC:
  153. sc = CoCreateInstance(CLSID_ActualWbemAuthenticatedLocator, NULL,
  154. CLSCTX_INPROC_SERVER, IID_IWbemLocator,(void **)&pActualLocator);
  155. break;
  156. case UNAUTHLOC:
  157. sc = CoCreateInstance(CLSID_ActualWbemUnauthenticatedLocator, NULL,
  158. CLSCTX_INPROC_SERVER, IID_IWbemLocator,(void **)&pActualLocator);
  159. break;
  160. default:
  161. return WBEM_E_FAILED;
  162. }
  163. if(FAILED(sc))
  164. return sc;
  165. CReleaseMe rm3(pActualLocator);
  166. sc = pActualLocator->ConnectServer(NetworkResource, User, Password, LocaleId,
  167. lFlags, Authority, pCtx, ppProv);
  168. return sc;
  169. }