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.

270 lines
7.6 KiB

  1. //******************************************************************************
  2. //
  3. // PERMBIND.CPP
  4. //
  5. // Copyright (C) 1996-1999 Microsoft Corporation
  6. //
  7. //******************************************************************************
  8. #include "precomp.h"
  9. #include <stdio.h>
  10. #include "pragmas.h"
  11. #include <permbind.h>
  12. #include <permfilt.h>
  13. long CPermanentBinding::mstatic_lConsumerHandle = 0;
  14. long CPermanentBinding::mstatic_lFilterHandle = 0;
  15. long CPermanentBinding::mstatic_lQosHandle = 0;
  16. long CPermanentBinding::mstatic_lSynchronicityHandle = 0;
  17. long CPermanentBinding::mstatic_lSlowDownHandle = 0;
  18. long CPermanentBinding::mstatic_lSecureHandle = 0;
  19. long CPermanentBinding::mstatic_lSidHandle = 0;
  20. bool CPermanentBinding::mstatic_bHandlesInitialized = false;
  21. // static
  22. HRESULT CPermanentBinding::InitializeHandles( _IWmiObject* pBindingObj)
  23. {
  24. if(mstatic_bHandlesInitialized)
  25. return S_FALSE;
  26. CIMTYPE ct;
  27. pBindingObj->GetPropertyHandle(CONSUMER_ROLE_NAME, &ct,
  28. &mstatic_lConsumerHandle);
  29. pBindingObj->GetPropertyHandle(FILTER_ROLE_NAME, &ct,
  30. &mstatic_lFilterHandle);
  31. pBindingObj->GetPropertyHandle(BINDING_SYNCHRONICITY_PROPNAME, &ct,
  32. &mstatic_lSynchronicityHandle);
  33. pBindingObj->GetPropertyHandle(BINDING_QOS_PROPNAME, &ct,
  34. &mstatic_lQosHandle);
  35. pBindingObj->GetPropertyHandle(BINDING_SECURE_PROPNAME, &ct,
  36. &mstatic_lSecureHandle);
  37. pBindingObj->GetPropertyHandle(BINDING_SLOWDOWN_PROPNAME, &ct,
  38. &mstatic_lSlowDownHandle);
  39. pBindingObj->GetPropertyHandleEx(OWNER_SID_PROPNAME, 0, &ct,
  40. &mstatic_lSidHandle);
  41. mstatic_bHandlesInitialized = true;
  42. return S_OK;
  43. }
  44. HRESULT CPermanentBinding::Initialize( IWbemClassObject* pObj )
  45. {
  46. HRESULT hres;
  47. CWbemPtr<_IWmiObject> pBindingObj;
  48. hres = pObj->QueryInterface(IID__IWmiObject, (void**)&pBindingObj );
  49. if (FAILED(hres))
  50. return hres;
  51. hres = InitializeHandles(pBindingObj);
  52. if(FAILED(hres))
  53. return hres;
  54. long lSize;
  55. //
  56. // Read the Qos property.
  57. //
  58. hres = pBindingObj->ReadPropertyValue( mstatic_lQosHandle,
  59. sizeof(DWORD),
  60. &lSize,
  61. (BYTE*)&m_dwQoS );
  62. if(FAILED(hres))
  63. return hres;
  64. if ( hres != WBEM_S_NO_ERROR)
  65. {
  66. m_dwQoS = WMIMSG_FLAG_QOS_EXPRESS; // default.
  67. }
  68. #ifdef __WHISTLER_UNCUT
  69. if ( m_dwQoS > WMIMSG_FLAG_QOS_XACT )
  70. {
  71. ERRORTRACE((LOG_ESS, "Invalid QoS of %d is used in a binding. "
  72. "Setting to default.\n", m_dwQoS));
  73. m_dwQoS = WMIMSG_FLAG_QOS_EXPRESS;
  74. }
  75. else if ( m_dwQoS == WMIMSG_FLAG_QOS_XACT )
  76. {
  77. ERRORTRACE((LOG_ESS, "XACT QoS is not a supported qos for binding. "
  78. "Downgrading to Guaranteed Delivery.\n"));
  79. m_dwQoS = WMIMSG_FLAG_QOS_GUARANTEED;
  80. }
  81. #else
  82. if ( m_dwQoS > WMIMSG_FLAG_QOS_EXPRESS )
  83. {
  84. ERRORTRACE((LOG_ESS, "Invalid QoS of %d is used in a binding.", m_dwQoS));
  85. return WBEM_E_INVALID_OBJECT;
  86. }
  87. #endif
  88. //
  89. // Read the synchronousness property - for backwards compatibility
  90. // Always overrides any Qos setting.
  91. //
  92. VARIANT_BOOL bTemp;
  93. hres = pBindingObj->ReadPropertyValue(mstatic_lSynchronicityHandle,
  94. sizeof(VARIANT_BOOL), &lSize, (BYTE*)&bTemp);
  95. if(FAILED(hres))
  96. return hres;
  97. if( hres == WBEM_S_NO_ERROR && bTemp == VARIANT_TRUE )
  98. {
  99. m_dwQoS = WMIMSG_FLAG_QOS_SYNCHRONOUS;
  100. }
  101. // Read security property
  102. // ======================
  103. hres = pBindingObj->ReadPropertyValue(mstatic_lSecureHandle,
  104. sizeof(VARIANT_BOOL), &lSize, (BYTE*)&bTemp);
  105. if(FAILED(hres))
  106. return hres;
  107. if(hres != WBEM_S_NO_ERROR)
  108. m_bSecure = FALSE;
  109. else
  110. m_bSecure = (bTemp != 0);
  111. // Read "slow down" property
  112. // =========================
  113. hres = pBindingObj->ReadPropertyValue(mstatic_lSlowDownHandle,
  114. sizeof(VARIANT_BOOL), &lSize, (BYTE*)&bTemp);
  115. if(FAILED(hres))
  116. return hres;
  117. if(hres != WBEM_S_NO_ERROR)
  118. m_bSlowDown = FALSE;
  119. else
  120. m_bSlowDown = (bTemp != 0);
  121. return WBEM_S_NO_ERROR;
  122. }
  123. HRESULT CPermanentBinding::ComputeKeysFromObject( IWbemClassObject* pObj,
  124. BSTR* pstrConsumer,
  125. BSTR* pstrFilter )
  126. {
  127. HRESULT hres;
  128. CWbemPtr<_IWmiObject> pBindingObj;
  129. hres = pObj->QueryInterface(IID__IWmiObject, (void**)&pBindingObj );
  130. if ( hres != S_OK)
  131. {
  132. return NULL;
  133. }
  134. InitializeHandles(pBindingObj);
  135. // Read filter path
  136. // ================
  137. ULONG ulFlags;
  138. CCompressedString* pcsFilter;
  139. hres = pBindingObj->GetPropAddrByHandle( mstatic_lFilterHandle,
  140. WMIOBJECT_FLAG_ENCODING_V1,
  141. &ulFlags,
  142. (void**)&pcsFilter );
  143. if( hres != S_OK )
  144. {
  145. return WBEM_E_INVALID_OBJECT;
  146. }
  147. BSTR strFilterPath = pcsFilter->CreateBSTRCopy();
  148. if(strFilterPath == NULL)
  149. return WBEM_E_OUT_OF_MEMORY;
  150. CSysFreeMe sfm1(strFilterPath);
  151. // Construct its key
  152. // =================
  153. BSTR strFilter = CPermanentFilter::ComputeKeyFromPath(strFilterPath);
  154. if(strFilter == NULL)
  155. return WBEM_E_INVALID_OBJECT_PATH;
  156. // Read consumer path
  157. // ==================
  158. CCompressedString* pcsConsumer;
  159. hres = pBindingObj->GetPropAddrByHandle( mstatic_lConsumerHandle,
  160. WMIOBJECT_FLAG_ENCODING_V1,
  161. &ulFlags,
  162. (void**)&pcsConsumer );
  163. if( hres != S_OK )
  164. {
  165. SysFreeString(strFilter);
  166. return WBEM_E_INVALID_OBJECT;
  167. }
  168. *pstrConsumer = pcsConsumer->CreateBSTRCopy();
  169. if(*pstrConsumer == NULL)
  170. {
  171. SysFreeString(strFilter);
  172. return WBEM_E_OUT_OF_MEMORY;
  173. }
  174. *pstrFilter = strFilter;
  175. return WBEM_S_NO_ERROR;
  176. }
  177. INTERNAL DELETE_ME PSID
  178. CPermanentBinding::GetSidFromObject(IWbemClassObject* pObj)
  179. {
  180. HRESULT hres;
  181. CWbemPtr<_IWmiObject> pBindingObj;
  182. hres = pObj->QueryInterface(IID__IWmiObject, (void**)&pBindingObj );
  183. if ( hres != S_OK)
  184. {
  185. return NULL;
  186. }
  187. InitializeHandles(pBindingObj);
  188. PSID pAddr;
  189. ULONG ulNumElements;
  190. hres = pBindingObj->GetArrayPropAddrByHandle( mstatic_lSidHandle,
  191. 0,
  192. &ulNumElements,
  193. &pAddr );
  194. if ( hres != S_OK )
  195. {
  196. return NULL;
  197. }
  198. //
  199. // we copy the SID here because the SID that is returned might be
  200. // unaligned. To avoid having the caller deal with these issues, we
  201. // just copy the sid into a buffer that is guaranteed to be aligned.
  202. //
  203. PBYTE pSid = new BYTE[ulNumElements];
  204. if ( pSid != NULL )
  205. {
  206. memcpy( pSid, pAddr, ulNumElements );
  207. }
  208. return pSid;
  209. }