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.

210 lines
5.2 KiB

  1. // Copyright (c) 2000-2001 Microsoft Corporation, All Rights Reserved
  2. // JobObjectProps.cpp
  3. //#define _WIN32_WINNT 0x0500
  4. #include "precomp.h"
  5. #include <wbemprov.h>
  6. #include "FRQueryEx.h"
  7. #include <vector>
  8. #include "helpers.h"
  9. #include "CVARIANT.h"
  10. #include "CObjProps.h"
  11. #include "CJobObjProps.h"
  12. #include <crtdbg.h>
  13. //*****************************************************************************
  14. // BEGIN: Declaration of Win32_NamedJobObject class properties.
  15. //*****************************************************************************
  16. // WARNING!! MUST KEEP MEMBERS OF THE FOLLOWING ARRAY
  17. // IN SYNCH WITH THE JOB_OBJ_PROPS ENUMERATION DECLARED
  18. // IN CJobObjProps.h !!!
  19. LPCWSTR g_rgJobObjPropNames[] =
  20. {
  21. { L"CollectionID" },
  22. { L"BasicUIRestrictions" }
  23. };
  24. //*****************************************************************************
  25. // END: Declaration of Win32_NamedJobObject class properties.
  26. //*****************************************************************************
  27. CJobObjProps::CJobObjProps(CHString& chstrNamespace)
  28. : CObjProps(chstrNamespace)
  29. {
  30. }
  31. CJobObjProps::CJobObjProps(
  32. HANDLE hJob,
  33. CHString& chstrNamespace)
  34. : CObjProps(chstrNamespace),
  35. m_hJob(hJob)
  36. {
  37. }
  38. CJobObjProps::~CJobObjProps()
  39. {
  40. }
  41. // Clients call this to establish which properties
  42. // were requested. This function calls a base class
  43. // helper, which calls our CheckProps function.
  44. // The base class helper finally stores the result
  45. // in the base class member m_dwReqProps.
  46. HRESULT CJobObjProps::GetWhichPropsReq(
  47. CFrameworkQuery& cfwq)
  48. {
  49. HRESULT hr = S_OK;
  50. // Call base class version for help.
  51. // Base class version will call our
  52. // CheckProps function.
  53. hr = CObjProps::GetWhichPropsReq(
  54. cfwq,
  55. CheckProps);
  56. return hr;
  57. }
  58. DWORD CJobObjProps::CheckProps(
  59. CFrameworkQuery& Query)
  60. {
  61. DWORD dwReqProps = PROP_NONE_REQUIRED;
  62. // Get the requested properties for this
  63. // specific object...
  64. if (Query.IsPropertyRequired(g_rgJobObjPropNames[JO_ID]))
  65. dwReqProps |= PROP_ID;
  66. if (Query.IsPropertyRequired(g_rgJobObjPropNames[JO_JobObjectBasicUIRestrictions]))
  67. dwReqProps |= PROP_JobObjectBasicUIRestrictions;
  68. return dwReqProps;
  69. }
  70. void CJobObjProps::SetHandle(
  71. const HANDLE hJob)
  72. {
  73. m_hJob = hJob;
  74. }
  75. HANDLE& CJobObjProps::GetHandle()
  76. {
  77. _ASSERT(m_hJob);
  78. return m_hJob;
  79. }
  80. // Sets the key properties from the ObjectPath.
  81. HRESULT CJobObjProps::SetKeysFromPath(
  82. const BSTR ObjectPath,
  83. IWbemContext __RPC_FAR *pCtx)
  84. {
  85. HRESULT hr = WBEM_S_NO_ERROR;
  86. // This array contains the key field names
  87. CHStringArray rgchstrKeys;
  88. rgchstrKeys.Add(g_rgJobObjPropNames[JO_ID]);
  89. // This array contains the index numbers
  90. // in m_PropMap corresponding to the keys.
  91. short sKeyNum[1];
  92. sKeyNum[0] = JO_ID;
  93. hr = CObjProps::SetKeysFromPath(
  94. ObjectPath,
  95. pCtx,
  96. IDS_Win32_NamedJobObject,
  97. rgchstrKeys,
  98. sKeyNum);
  99. return hr;
  100. }
  101. // Sets the key property from in supplied
  102. // parameter.
  103. HRESULT CJobObjProps::SetKeysDirect(
  104. std::vector<CVARIANT>& vecvKeys)
  105. {
  106. HRESULT hr = WBEM_S_NO_ERROR;
  107. if(vecvKeys.size() == 1)
  108. {
  109. short sKeyNum[1];
  110. sKeyNum[0] = JO_ID;
  111. hr = CObjProps::SetKeysDirect(
  112. vecvKeys,
  113. sKeyNum);
  114. }
  115. else
  116. {
  117. hr = WBEM_E_INVALID_PARAMETER;
  118. }
  119. return hr;
  120. }
  121. // Sets the non-key properties. Only those
  122. // properties requested are set (as determined
  123. // by base class member m_dwReqProps).
  124. HRESULT CJobObjProps::SetNonKeyReqProps()
  125. {
  126. HRESULT hr = WBEM_S_NO_ERROR;
  127. DWORD dwReqProps = GetReqProps();
  128. if(dwReqProps & PROP_JobObjectBasicUIRestrictions)
  129. {
  130. // Get the value from the underlying JO:
  131. JOBOBJECT_BASIC_UI_RESTRICTIONS jouir;
  132. BOOL fQIJO = ::QueryInformationJobObject(
  133. m_hJob,
  134. JobObjectBasicUIRestrictions,
  135. &jouir,
  136. sizeof(JOBOBJECT_BASIC_UI_RESTRICTIONS),
  137. NULL);
  138. if(!fQIJO)
  139. {
  140. hr = WBEM_E_FAILED;
  141. }
  142. else
  143. {
  144. try // CVARIANT can throw...
  145. {
  146. // Store the value...
  147. m_PropMap.insert(SHORT2PVARIANT::value_type(
  148. JO_JobObjectBasicUIRestrictions,
  149. new CVARIANT(jouir.UIRestrictionsClass)));
  150. }
  151. catch(CVARIANTError& cve)
  152. {
  153. hr = cve.GetWBEMError();
  154. }
  155. }
  156. }
  157. return hr;
  158. }
  159. HRESULT CJobObjProps::LoadPropertyValues(
  160. IWbemClassObject* pIWCO)
  161. {
  162. HRESULT hr = WBEM_S_NO_ERROR;
  163. if(!pIWCO) return E_POINTER;
  164. hr = CObjProps::LoadPropertyValues(
  165. g_rgJobObjPropNames,
  166. pIWCO);
  167. return hr;
  168. }