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.

200 lines
5.8 KiB

  1. //***************************************************************************
  2. //
  3. // INSTPRO.CPP
  4. //
  5. // Module: WMI Instance provider code for Boot Parameters
  6. //
  7. // Purpose: Defines the CInstPro class. An object of this class is
  8. // created by the class factory for each connection.
  9. //
  10. // Copyright (c) 1997-1999 Microsoft Corporation
  11. //
  12. //***************************************************************************
  13. #include <objbase.h>
  14. #include "bootini.h"
  15. #include <process.h>
  16. //***************************************************************************
  17. //
  18. // CBootInstPro::CBootInstPro
  19. // CBootInstPro::~CInstPro
  20. //
  21. //***************************************************************************
  22. CBootInstPro::CBootInstPro(BSTR ObjectPath, BSTR User, BSTR Password, IWbemContext * pCtx)
  23. {
  24. m_pNamespace = NULL;
  25. m_cRef=0;
  26. InterlockedIncrement(&g_cObj);
  27. return;
  28. }
  29. CBootInstPro::~CBootInstPro(void)
  30. {
  31. if(m_pNamespace)
  32. m_pNamespace->Release();
  33. InterlockedDecrement(&g_cObj);
  34. return;
  35. }
  36. //***************************************************************************
  37. //
  38. // CBootInstPro::QueryInterface
  39. // CBootInstPro::AddRef
  40. // CBootInstPro::Release
  41. //
  42. // Purpose: IUnknown members for CInstPro object.
  43. //***************************************************************************
  44. STDMETHODIMP CBootInstPro::QueryInterface(REFIID riid, PPVOID ppv)
  45. {
  46. *ppv=NULL;
  47. // Since we have dual inheritance, it is necessary to cast the return type
  48. if(riid== IID_IWbemServices)
  49. *ppv=(IWbemServices*)this;
  50. if(IID_IUnknown==riid || riid== IID_IWbemProviderInit)
  51. *ppv=(IWbemProviderInit*)this;
  52. if (NULL!=*ppv) {
  53. AddRef();
  54. return NOERROR;
  55. }
  56. else
  57. return E_NOINTERFACE;
  58. }
  59. STDMETHODIMP_(ULONG) CBootInstPro::AddRef(void)
  60. {
  61. return ++m_cRef;
  62. }
  63. STDMETHODIMP_(ULONG) CBootInstPro::Release(void)
  64. {
  65. ULONG nNewCount = InterlockedDecrement((long *)&m_cRef);
  66. if (0L == nNewCount)
  67. delete this;
  68. return nNewCount;
  69. }
  70. /***********************************************************************
  71. * *
  72. * CBootInstPro::Initialize *
  73. * *
  74. * Purpose: This is the implementation of IWbemProviderInit. The method *
  75. * is need to initialize with CIMOM. *
  76. * *
  77. ***********************************************************************/
  78. STDMETHODIMP CBootInstPro::Initialize(LPWSTR pszUser,
  79. LONG lFlags,
  80. LPWSTR pszNamespace,
  81. LPWSTR pszLocale,
  82. IWbemServices *pNamespace,
  83. IWbemContext *pCtx,
  84. IWbemProviderInitSink *pInitSink
  85. )
  86. {
  87. if(pNamespace)
  88. pNamespace->AddRef();
  89. m_pNamespace = pNamespace;
  90. //Let CIMOM know you are initialized
  91. //==================================
  92. pInitSink->SetStatus(WBEM_S_INITIALIZED,0);
  93. return WBEM_S_NO_ERROR;
  94. }
  95. //***************************************************************************
  96. //
  97. // CBootInstPro::GetObjectByPath
  98. // CBootInstPro::GetObjectByPathAsync
  99. //
  100. // Purpose: Creates an instance given a particular path value.
  101. //
  102. //***************************************************************************
  103. SCODE CBootInstPro::GetObjectAsync(const BSTR ObjectPath,
  104. long lFlags,
  105. IWbemContext *pCtx,
  106. IWbemObjectSink FAR* pHandler
  107. )
  108. {
  109. SCODE sc;
  110. int iCnt;
  111. IWbemClassObject FAR* pNewInst;
  112. IWbemClassObject FAR* pNewOSInst;
  113. IWbemClassObject *pClass;
  114. // Do a check of arguments and make sure we have pointer to Namespace
  115. if(pHandler == NULL || m_pNamespace == NULL)
  116. return WBEM_E_INVALID_PARAMETER;
  117. if(wcscmp(ObjectPath,L"BootLoaderParameters=@") == 0){
  118. // fill in the loader parameters and return
  119. sc = m_pNamespace->GetObject(L"BootLoaderParameters", 0, pCtx, &pClass, NULL);
  120. if(sc != S_OK){
  121. return WBEM_E_FAILED;
  122. }
  123. sc = pClass->SpawnInstance(0,&pNewInst);
  124. if(FAILED(sc)){
  125. return sc;
  126. }
  127. pClass->Release();
  128. sc = GetBootLoaderParameters(m_pNamespace, pNewInst, pCtx);
  129. if(sc != S_OK){
  130. pNewInst->Release();
  131. return sc;
  132. }
  133. pHandler->Indicate(1,&pNewInst);
  134. pNewInst->Release();
  135. pHandler->SetStatus(0,sc,NULL, NULL);
  136. return S_OK;
  137. }
  138. return WBEM_E_INVALID_PARAMETER;
  139. }
  140. SCODE CBootInstPro::PutInstanceAsync(IWbemClassObject *pInst,
  141. long lFlags,
  142. IWbemContext *pCtx,
  143. IWbemObjectSink FAR* pHandler
  144. )
  145. {
  146. IWbemClassObject *pClass;
  147. IWbemClassObject *pOldInst;
  148. SCODE sc;
  149. if(pHandler == NULL || m_pNamespace == NULL)
  150. return WBEM_E_INVALID_PARAMETER;
  151. sc = m_pNamespace->GetObject(L"OSParameters", 0, pCtx, &pClass, NULL);
  152. if(sc != S_OK){
  153. return WBEM_E_FAILED;
  154. }
  155. LONG ret = SaveBootFile(pInst,pClass);
  156. pClass->Release();
  157. if (ret) {
  158. return WBEM_E_FAILED;
  159. }
  160. pHandler->SetStatus(0,sc,NULL, NULL);
  161. return WBEM_S_NO_ERROR;
  162. }