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
6.6 KiB

  1. //*************************************************************
  2. //
  3. // Microsoft Confidential
  4. // Copyright (c) Microsoft Corporation 2000
  5. // All rights reserved
  6. //
  7. // WMI interfae class
  8. //
  9. // History: 10-Mar-00 SitaramR Created
  10. //
  11. //*************************************************************
  12. #include "uenv.h"
  13. #include "locator.h"
  14. extern CDebug CDbgCommon;
  15. //*************************************************************
  16. //
  17. // CLocator::GetWbemLocator
  18. //
  19. // Purpose: Returns the WbemLocator pointer
  20. //
  21. //*************************************************************
  22. IWbemLocator *CLocator::GetWbemLocator()
  23. {
  24. XLastError xe;
  25. if ( m_xpWbemLocator == NULL ) {
  26. OLE32_API *pOle32Api = LoadOle32Api();
  27. if ( pOle32Api == NULL ) {
  28. dbgCommon.Msg( DEBUG_MESSAGE_WARNING,
  29. TEXT("CLocator::GetWbemLocator: Load of ole32.dll failed") );
  30. xe = GetLastError();
  31. return NULL;
  32. }
  33. HRESULT hr = pOle32Api->pfnCoCreateInstance(CLSID_WbemLocator,
  34. 0,
  35. CLSCTX_INPROC_SERVER,
  36. IID_IWbemLocator,
  37. (LPVOID *) &m_xpWbemLocator);
  38. if(FAILED(hr)) {
  39. dbgCommon.Msg( DEBUG_MESSAGE_WARNING,
  40. TEXT("CLocator::GetWbemLocator: CoCreateInstance failed with 0x%x"), hr );
  41. xe = hr;
  42. return NULL;
  43. }
  44. }
  45. return m_xpWbemLocator;
  46. }
  47. //*************************************************************
  48. //
  49. // CLocator::GetPolicyConnection
  50. //
  51. // Purpose: Returns the WbemServices ptr to root\policy
  52. //
  53. //*************************************************************
  54. IWbemServices *CLocator::GetPolicyConnection()
  55. {
  56. XLastError xe;
  57. if ( m_xpPolicyConnection == NULL ) {
  58. IWbemLocator *pWbemLocator = GetWbemLocator();
  59. if ( pWbemLocator == NULL ) {
  60. xe = GetLastError();
  61. return NULL;
  62. }
  63. XBStr xbstrNamespace = L"\\\\.\\Root\\policy";
  64. if(!xbstrNamespace) {
  65. dbgCommon.Msg( DEBUG_MESSAGE_WARNING,
  66. TEXT("CLocator::GetPolicyConnection: Failed to allocate memory") );
  67. xe = GetLastError();
  68. return NULL;
  69. }
  70. HRESULT hr = pWbemLocator->ConnectServer(xbstrNamespace,
  71. NULL,
  72. NULL,
  73. 0L,
  74. 0L,
  75. NULL,
  76. NULL,
  77. &m_xpPolicyConnection);
  78. if(FAILED(hr)) {
  79. dbgCommon.Msg( DEBUG_MESSAGE_WARNING,
  80. TEXT("CLocator::GetPolicyConnection: ConnectServer failed with 0x%x"), hr );
  81. xe = hr;
  82. return NULL;
  83. }
  84. hr = CoSetProxyBlanket((IUnknown *)m_xpPolicyConnection, RPC_C_AUTHN_DEFAULT,
  85. RPC_C_AUTHZ_DEFAULT, COLE_DEFAULT_PRINCIPAL, RPC_C_AUTHN_LEVEL_DEFAULT,
  86. RPC_C_IMP_LEVEL_IMPERSONATE, NULL,
  87. EOAC_DYNAMIC_CLOAKING /* | EOAC_NO_CUSTOM_MARSHAL */);
  88. if (FAILED(hr)) {
  89. dbgCommon.Msg( DEBUG_MESSAGE_WARNING,
  90. TEXT("CLocator::GetPolicyConnection: CoSetProxyBlanket failed with 0x%x"), hr );
  91. xe = hr;
  92. m_xpPolicyConnection = NULL;
  93. return NULL;
  94. }
  95. }
  96. return m_xpPolicyConnection;
  97. }
  98. //*************************************************************
  99. //
  100. // CLocator::GetUserConnection
  101. //
  102. // Purpose: Returns the WbemServices ptr to root\User
  103. //
  104. //*************************************************************
  105. IWbemServices *CLocator::GetUserConnection()
  106. {
  107. if ( m_xpUserConnection == NULL ) {
  108. IWbemLocator *pWbemLocator = GetWbemLocator();
  109. if ( pWbemLocator == NULL )
  110. return NULL;
  111. XBStr xbstrNamespace = L"root\\User";
  112. if(!xbstrNamespace) {
  113. dbgCommon.Msg( DEBUG_MESSAGE_WARNING,
  114. TEXT("CLocator::GetUserConnection: Failed to allocate memory") );
  115. return NULL;
  116. }
  117. HRESULT hr = pWbemLocator->ConnectServer(xbstrNamespace,
  118. NULL,
  119. NULL,
  120. 0L,
  121. 0L,
  122. NULL,
  123. NULL,
  124. &m_xpUserConnection);
  125. if(FAILED(hr)) {
  126. dbgCommon.Msg( DEBUG_MESSAGE_WARNING,
  127. TEXT("CLocator::GetUserConnection: ConnectServer failed with 0x%x"), hr );
  128. return NULL;
  129. }
  130. }
  131. return m_xpUserConnection;
  132. }
  133. //*************************************************************
  134. //
  135. // CLocator::GetMachConnection
  136. //
  137. // Purpose: Returns the WbemServices ptr to root\Mach
  138. //
  139. //*************************************************************
  140. IWbemServices *CLocator::GetMachConnection()
  141. {
  142. if ( m_xpMachConnection == NULL ) {
  143. IWbemLocator *pWbemLocator = GetWbemLocator();
  144. if ( pWbemLocator == NULL )
  145. return NULL;
  146. XBStr xbstrNamespace = L"root\\Computer";
  147. if(!xbstrNamespace) {
  148. dbgCommon.Msg( DEBUG_MESSAGE_WARNING,
  149. TEXT("CLocator::GetMachConnection: Failed to allocate memory") );
  150. return NULL;
  151. }
  152. HRESULT hr = pWbemLocator->ConnectServer(xbstrNamespace,
  153. NULL,
  154. NULL,
  155. 0L,
  156. 0L,
  157. NULL,
  158. NULL,
  159. &m_xpMachConnection);
  160. if(FAILED(hr)) {
  161. dbgCommon.Msg( DEBUG_MESSAGE_WARNING,
  162. TEXT("CLocator::GetMachConnection: ConnectServer failed with 0x%x"), hr );
  163. return NULL;
  164. }
  165. }
  166. return m_xpMachConnection;
  167. }