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.

446 lines
12 KiB

  1. //***************************************************************************
  2. //
  3. // VPTASKS.H
  4. //
  5. // Module:
  6. //
  7. // Purpose: Defines tasks that IWbemServices needs to perform.
  8. //
  9. // Copyright (c) 1998-2001 Microsoft Corporation, All Rights Reserved
  10. //
  11. //***************************************************************************
  12. #ifndef _VIEW_PROV_VPTASKS_H
  13. #define _VIEW_PROV_VPTASKS_H
  14. #define WBEM_TASKSTATE_START 0x0
  15. #define WBEM_TASKSTATE_ASYNCHRONOUSCOMPLETE 0x100000
  16. #define WBEM_TASKSTATE_ASYNCHRONOUSABORT 0x100001
  17. #define CONST_NETAPI_LIBRARY _T("netapi32.dll")
  18. #define CONST_NETAPI_DSPROC ("DsGetDcNameW")
  19. #define CONST_NETAPI_NETPROC ("NetApiBufferFree")
  20. typedef DWORD ( WINAPI *NETAPI_PROC_DsGetDcName ) (
  21. IN LPCWSTR ComputerName OPTIONAL,
  22. IN LPCWSTR DomainName OPTIONAL,
  23. IN GUID *DomainGuid OPTIONAL,
  24. IN LPCWSTR SiteName OPTIONAL,
  25. IN ULONG Flags,
  26. OUT PDOMAIN_CONTROLLER_INFOW *DomainControllerInfo
  27. ) ;
  28. typedef NET_API_STATUS ( NET_API_FUNCTION *NETAPI_PROC_NetApiBufferFree ) (
  29. IN LPVOID Buffer
  30. ) ;
  31. class WbemTaskObject;
  32. class CObjectSinkResults;
  33. class CViewProvObjectSink : public IWbemObjectSink
  34. {
  35. private:
  36. LONG m_ReferenceCount; //Object reference count
  37. CObjectSinkResults *m_parent;
  38. CCriticalSection m_lock;
  39. CWbemServerWrap *m_ServWrap;
  40. IWbemObjectSink *m_RemoteSink;
  41. BOOL m_DoCancel;
  42. DWORD m_nsindex;
  43. public:
  44. //Constructor
  45. CViewProvObjectSink(CObjectSinkResults* parent, CWbemServerWrap *pServ, DWORD a_indx);
  46. //Non-delegating object IUnknown
  47. STDMETHODIMP QueryInterface (REFIID refIID, LPVOID FAR * ppV);
  48. STDMETHODIMP_(ULONG) AddRef ();
  49. STDMETHODIMP_(ULONG) Release ();
  50. //IWbemObjectSink methods
  51. HRESULT STDMETHODCALLTYPE Indicate(LONG count, IWbemClassObject** ppObjArray);
  52. HRESULT STDMETHODCALLTYPE SetStatus(LONG lFlags, HRESULT hr, BSTR bStr, IWbemClassObject* pObj);
  53. //implementation
  54. void Disconnect();
  55. void DisAssociate();
  56. IWbemObjectSink* Associate();
  57. //Destructor
  58. ~CViewProvObjectSink();
  59. };
  60. template <> inline void AFXAPI DestructElements<IWbemClassObject*> (IWbemClassObject** ptr_e, int x)
  61. {
  62. for (int i = 0; i < x; i++)
  63. {
  64. if (ptr_e[i] != NULL)
  65. {
  66. ptr_e[i]->Release();
  67. }
  68. }
  69. }
  70. class CWbemClassObjectWithIndex
  71. {
  72. private:
  73. LONG m_ReferenceCount;
  74. DWORD m_nsindex;
  75. IWbemClassObject *m_pObject;
  76. public:
  77. CWbemClassObjectWithIndex(DWORD a_indx, IWbemClassObject *a_pObj);
  78. ULONG AddRef();
  79. ULONG Release();
  80. DWORD GetIndex() { return m_nsindex; }
  81. IWbemClassObject * GetWrappedObject() { return m_pObject; }
  82. ~CWbemClassObjectWithIndex();
  83. };
  84. template <> inline void AFXAPI DestructElements<CWbemClassObjectWithIndex*> (CWbemClassObjectWithIndex** ptr_e, int x)
  85. {
  86. for (int i = 0; i < x; i++)
  87. {
  88. if (ptr_e[i] != NULL)
  89. {
  90. ptr_e[i]->Release();
  91. }
  92. }
  93. }
  94. class CObjectSinkResults : public CObject
  95. {
  96. private:
  97. CList<CViewProvObjectSink *, CViewProvObjectSink *> m_realSnks;
  98. CCriticalSection m_CriticalSection;
  99. WbemTaskObject *m_parent;
  100. DWORD m_index;
  101. HRESULT m_hr;
  102. BOOL m_bSet;
  103. LONG m_ReferenceCount;
  104. public:
  105. CArray<CWbemClassObjectWithIndex*, CWbemClassObjectWithIndex*> m_ObjArray;
  106. DWORD GetIndex() { return m_index; }
  107. BOOL IsSet() { return m_bSet; }
  108. HRESULT GetResult() { return m_hr; }
  109. void Disconnect();
  110. BOOL RemoveSink(CViewProvObjectSink *pSnk);
  111. void SetSink(CViewProvObjectSink *pSnk);
  112. void SetStatus(HRESULT hr, CViewProvObjectSink *pSnk);
  113. HRESULT Indicate(LONG count, IWbemClassObject** ppObjArray, DWORD a_indx);
  114. ULONG AddRef ();
  115. ULONG Release ();
  116. CObjectSinkResults(WbemTaskObject* parent, DWORD index);
  117. ~CObjectSinkResults();
  118. };
  119. class WbemTaskObject
  120. {
  121. private:
  122. protected:
  123. WbemProvErrorObject m_ErrorObject ;
  124. ULONG m_OperationFlag;
  125. IWbemClassObject *m_ClassObject;
  126. IWbemObjectSink *m_NotificationHandler;
  127. IWbemContext *m_Ctx;
  128. CViewProvServ *m_Provider;
  129. CTypedPtrArray<CObArray, CSourceQualifierItem*> m_SourceArray;
  130. CMap<CStringW, LPCWSTR, int, int> m_ClassToIndexMap;
  131. CTypedPtrArray<CObArray, CNSpaceQualifierItem*> m_NSpaceArray;
  132. CMap<CStringW, LPCWSTR, CPropertyQualifierItem*, CPropertyQualifierItem*> m_PropertyMap;
  133. CMap<CStringW, LPCWSTR, int, int> m_EnumerateClasses;
  134. CJoinOnQualifierArray m_JoinOnArray;
  135. SQL_LEVEL_1_RPN_EXPRESSION* m_RPNPostFilter;
  136. BSTR m_ClassName;
  137. CStringW m_ProviderName;
  138. LONG m_Ref;
  139. CTypedPtrArray<CObArray, CObjectSinkResults*> m_ObjSinkArray;
  140. CCriticalSection m_ArrayLock;
  141. int m_iQueriesAsked;
  142. int m_iQueriesAnswered;
  143. BOOL m_bAssoc;
  144. BOOL m_bSingleton;
  145. HANDLE m_StatusHandle;
  146. IWbemServices *m_Serv;
  147. CWbemServerWrap *m_ServerWrap;
  148. BOOL m_bIndicate;
  149. BOOL m_ResultReceived;
  150. protected:
  151. void SetRequestHandle ( ULONG a_RequestHandle ) ;
  152. BOOL GetRequestHandle () ;
  153. BOOL GetClassObject (IWbemServices* pServ, BSTR a_Class, IWbemClassObject** ppClass, CWbemServerWrap **a_pServ = NULL) ;
  154. BOOL SetClass (const wchar_t* a_Class) ;
  155. BOOL GetExtendedNotifyStatusObject ( IWbemClassObject **a_NotifyObject ) ;
  156. BOOL GetNotifyStatusObject ( IWbemClassObject **a_NotifyObject ) ;
  157. BOOL ParseAndProcessClassQualifiers (WbemProvErrorObject &a_ErrorObject,
  158. ParsedObjectPath *a_ParsedObjectPath = NULL,
  159. CMap<CStringW, LPCWSTR, int, int>* parentMap = NULL);
  160. #ifdef VP_PERFORMANT_JOINS
  161. BOOL CreateAndIndicateJoinsPerf(WbemProvErrorObject &a_ErrorObject, BOOL a_bSingle);
  162. BOOL JoinTwoColumns(WbemProvErrorObject &a_ErrorObject,
  163. CMap<CStringW, LPCWSTR, int, int> &a_JoinedClasses,
  164. CList<IWbemClassObject*, IWbemClassObject*> &a_ResultObjs);
  165. BOOL AddColumnToJoin(WbemProvErrorObject &a_ErrorObject,
  166. CMap<CStringW, LPCWSTR, int, int> &a_JoinedClasses,
  167. CList<IWbemClassObject*, IWbemClassObject*> &a_ResultObjs,
  168. DWORD a_Index,
  169. CList <int, int> &a_IndexArray);
  170. BOOL JoinTwoItems(WbemProvErrorObject &a_ErrorObject,
  171. IWbemClassObject *a_Obj1,
  172. IWbemClassObject *a_Obj2,
  173. IWbemClassObject *a_resObj,
  174. CList <int, int> &a_IndexArray,
  175. DWORD a_indx1, DWORD a_indx2);
  176. BOOL JoinItem(WbemProvErrorObject &a_ErrorObject,
  177. IWbemClassObject *a_Obj1,
  178. IWbemClassObject *a_vObj,
  179. IWbemClassObject *a_resObj,
  180. CList <int, int> &a_IndexArray,
  181. DWORD a_indx1);
  182. #else
  183. BOOL CreateAndIndicateJoins(WbemProvErrorObject &a_ErrorObject, BOOL a_bSingle);
  184. BOOL CreateAndIndicate(WbemProvErrorObject &a_ErrorObject, IWbemClassObject **pSrcs, IWbemClassObject **pOut);
  185. #endif
  186. BOOL CreateAndIndicateUnions(WbemProvErrorObject &a_ErrorObject, int index = -1);
  187. BOOL CreateAndIndicate(WbemProvErrorObject &a_ErrorObject, CObjectSinkResults *pSrcs);
  188. #if 0
  189. BOOL SetDefaultUnionKeyValue(wchar_t* propstr, IWbemClassObject* pObj);
  190. #endif
  191. BOOL ValidateClassDependencies(IWbemClassObject*** arrayofArrayOfObjs, CMap<CStringW, LPCWSTR, int, int>* parentMap);
  192. BOOL ValidateJoin();
  193. BOOL TransposeReference(CPropertyQualifierItem* pItm, VARIANT vSrc, VARIANT* pvDst, BOOL bMapToView, CWbemServerWrap **a_ns);
  194. BSTR MapFromView(BSTR path, const wchar_t* src, IWbemClassObject** pInst = NULL, BOOL bAllprops = FALSE);
  195. BSTR MapToView(BSTR path, const wchar_t* src, CWbemServerWrap **a_ns);
  196. BOOL EvaluateToken(IWbemClassObject *pTestObj, SQL_LEVEL_1_TOKEN &Tok);
  197. BOOL PostFilter(IWbemClassObject* a_pObj);
  198. HRESULT Connect(const wchar_t* path, CWbemServerWrap** ppServ, BOOL a_bUpdate = FALSE);
  199. HRESULT UpdateConnection(CWbemServerWrap **a_pServ, IWbemServices **a_proxy);
  200. HRESULT DoConnectServer(BSTR bstrPath, CWbemServerWrap **a_ppServ, BOOL a_bUpdate);
  201. HRESULT LocalConnectServer(BSTR bstrPath, IWbemServices** ppServ);
  202. #ifdef UNICODE
  203. HRESULT CoCreateForConnectServer(BSTR bstrPath, COSERVERINFO* psi, COAUTHIDENTITY* pauthid, IWbemServices** ppServ);
  204. #endif
  205. wchar_t* NormalisePath(wchar_t *wszObjectPath, CWbemServerWrap **pNSWrap);
  206. wchar_t* GetClassWithKeyDefn(CWbemServerWrap **pNS, BSTR classname, BOOL bGetNS, wchar_t **nsPath, BOOL bCheckSingleton = TRUE);
  207. DWORD GetIndexList(const wchar_t* a_src, DWORD** a_pdwArray);
  208. public:
  209. WbemTaskObject (
  210. CViewProvServ *a_Provider ,
  211. IWbemObjectSink *a_NotificationHandler ,
  212. ULONG a_OperationFlag ,
  213. IWbemContext *a_Ctx ,
  214. IWbemServices* a_Serv = NULL,
  215. CWbemServerWrap *a_ServWrap = NULL
  216. ) ;
  217. LONG AddRef();
  218. LONG Release();
  219. WbemProvErrorObject &GetErrorObject();
  220. void CleanUpObjSinks(BOOL a_bDisconnect = FALSE);
  221. virtual void SetStatus(HRESULT hr, DWORD index);
  222. void SetResultReceived();
  223. virtual ~WbemTaskObject();
  224. } ;
  225. class HelperTaskObject : public WbemTaskObject
  226. {
  227. private:
  228. wchar_t *m_ObjectPath ;
  229. ParsedObjectPath *m_ParsedObjectPath ;
  230. wchar_t* m_principal ;
  231. BOOL DoQuery(ParsedObjectPath* parsedObjectPath, IWbemClassObject** pInst, int indx);
  232. public:
  233. HelperTaskObject(
  234. CViewProvServ *a_Provider ,
  235. const wchar_t *a_ObjectPath ,
  236. ULONG a_Flag ,
  237. IWbemObjectSink *a_NotificationHandler,
  238. IWbemContext *pCtx,
  239. IWbemServices* a_Serv,
  240. const wchar_t* prncpl,
  241. CWbemServerWrap* a_ServWrap
  242. );
  243. BOOL Validate(CMap<CStringW, LPCWSTR, int, int>* parentMap);
  244. BOOL GetViewObject(const wchar_t* path, IWbemClassObject** pInst, CWbemServerWrap **a_ns);
  245. ~HelperTaskObject();
  246. };
  247. class GetObjectTaskObject : public WbemTaskObject
  248. {
  249. private:
  250. wchar_t *m_ObjectPath ;
  251. ParsedObjectPath *m_ParsedObjectPath ;
  252. protected:
  253. BOOL PerformGet(WbemProvErrorObject &a_ErrorObject, IWbemClassObject** pInst = NULL, const wchar_t* src = NULL, BOOL bAllprops = FALSE);
  254. BOOL PerformQueries(WbemProvErrorObject &a_ErrorObject, BOOL bAllprops);
  255. BOOL ProcessResults(WbemProvErrorObject &a_ErrorObject, IWbemClassObject** pInst, const wchar_t* src);
  256. public:
  257. GetObjectTaskObject (
  258. CViewProvServ *a_Provider ,
  259. wchar_t *a_ObjectPath ,
  260. ULONG a_Flag ,
  261. IWbemObjectSink *a_NotificationHandler,
  262. IWbemContext *pCtx,
  263. IWbemServices* a_Serv,
  264. CWbemServerWrap *a_ServerWrap
  265. );
  266. BOOL GetObject();
  267. BOOL GetSourceObject(const wchar_t* src, IWbemClassObject** pInst, BOOL bAllprops);
  268. ~GetObjectTaskObject();
  269. } ;
  270. class ExecMethodTaskObject : public WbemTaskObject
  271. {
  272. private:
  273. wchar_t *m_ObjectPath ;
  274. wchar_t *m_Method ;
  275. ParsedObjectPath *m_ParsedObjectPath ;
  276. IWbemClassObject* m_InParamObject;
  277. IWbemClassObject* m_OutParamObject;
  278. protected:
  279. BOOL CompareMethods(WbemProvErrorObject &a_ErrorObject,
  280. LONG &a_Index,
  281. CStringW &a_SrcMethodName,
  282. BOOL &a_bStatic);
  283. BOOL PerformMethod(WbemProvErrorObject &a_ErrorObject,
  284. LONG a_Index,
  285. CStringW a_SrcMethodName,
  286. BOOL a_bStatic);
  287. public:
  288. ExecMethodTaskObject (
  289. CViewProvServ *a_Provider ,
  290. wchar_t *a_ObjectPath ,
  291. wchar_t *a_MethodName,
  292. ULONG a_Flag ,
  293. IWbemClassObject *a_InParams ,
  294. IWbemObjectSink *a_NotificationHandler ,
  295. IWbemContext *pCtx
  296. );
  297. BOOL ExecMethod();
  298. ~ExecMethodTaskObject();
  299. } ;
  300. class PutInstanceTaskObject : public WbemTaskObject
  301. {
  302. private:
  303. IWbemClassObject *m_InstObject ;
  304. protected:
  305. BOOL PerformPut(WbemProvErrorObject &a_ErrorObject);
  306. public:
  307. PutInstanceTaskObject (
  308. CViewProvServ *a_Provider ,
  309. IWbemClassObject *a_Inst ,
  310. ULONG a_Flag ,
  311. IWbemObjectSink *a_NotificationHandler ,
  312. IWbemContext *pCtx
  313. );
  314. BOOL PutInstance();
  315. ~PutInstanceTaskObject();
  316. } ;
  317. class ExecQueryTaskObject : public WbemTaskObject
  318. {
  319. private:
  320. wchar_t *m_QueryFormat ;
  321. wchar_t *m_Query ;
  322. wchar_t *m_Class ;
  323. SQL_LEVEL_1_RPN_EXPRESSION *m_RPNExpression ;
  324. protected:
  325. BOOL PerformQuery(WbemProvErrorObject &a_ErrorObject);
  326. BOOL PerformEnumQueries(WbemProvErrorObject &a_ErrorObject);
  327. BOOL PerformSelectQueries(WbemProvErrorObject &a_ErrorObject, BOOL &bWait);
  328. BOOL ProcessResults(WbemProvErrorObject &a_ErrorObject);
  329. void ModifySourceQueriesForUserQuery();
  330. void ModifySourceQueriesWithEnumResults();
  331. public:
  332. ExecQueryTaskObject (
  333. CViewProvServ *a_Provider ,
  334. BSTR a_QueryFormat ,
  335. BSTR a_Query ,
  336. ULONG a_Flag ,
  337. IWbemObjectSink *a_NotificationHandler ,
  338. IWbemContext *pCtx
  339. );
  340. BOOL ExecQuery();
  341. ~ExecQueryTaskObject();
  342. } ;
  343. #endif //_VIEW_PROV_VPTASKS_H