Source code of Windows XP (NT5)
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.

516 lines
19 KiB

  1. /*++
  2. Copyright (C) 2000-2001 Microsoft Corporation
  3. --*/
  4. #ifndef __A51PROV__H_
  5. #define __A51PROV__H_
  6. #include <windows.h>
  7. #include <wbemidl.h>
  8. #include <unk.h>
  9. #include <wbemcomn.h>
  10. #include <sync.h>
  11. #include <reposit.h>
  12. #include <wmiutils.h>
  13. #include <objpath.h>
  14. #include <filecach.h>
  15. #include <hiecache.h>
  16. #include <corex.h>
  17. #include "a51fib.h"
  18. #include "creposit.h"
  19. class CDbIterator;
  20. class CRepEvent
  21. {
  22. public:
  23. DWORD m_dwType;
  24. LPWSTR m_wszArg1;
  25. LPWSTR m_wszNamespace;
  26. _IWmiObject* m_pObj1;
  27. _IWmiObject* m_pObj2;
  28. CRepEvent(DWORD dwType, LPCWSTR wszNamespace, LPCWSTR wszArg1,
  29. _IWmiObject* pObj1, _IWmiObject* pObj2);
  30. ~CRepEvent();
  31. void* operator new(size_t) {return TempAlloc(sizeof(CRepEvent));}
  32. void operator delete(void* p) {return TempFree(p, sizeof(CRepEvent));}
  33. };
  34. class CEventCollector
  35. {
  36. protected:
  37. CUniquePointerArray<CRepEvent> m_apEvents;
  38. bool m_bNamespaceOnly;
  39. CRITICAL_SECTION m_csLock;
  40. public:
  41. CEventCollector() : m_bNamespaceOnly(false){ InitializeCriticalSection(&m_csLock);}
  42. ~CEventCollector() { DeleteCriticalSection(&m_csLock); }
  43. bool AddEvent(CRepEvent* pEvent);
  44. void SetNamespaceOnly(bool bNamespaceOnly)
  45. {m_bNamespaceOnly = bNamespaceOnly;}
  46. bool IsNamespaceOnly() {return m_bNamespaceOnly;}
  47. HRESULT SendEvents(_IWmiCoreServices* pCore);
  48. void DeleteAllEvents();
  49. void TransferEvents(CEventCollector &aEventsToTransfer);
  50. int GetSize() { return m_apEvents.GetSize(); }
  51. };
  52. class CSession : public CUnkBase<IWmiDbSessionEx, &IID_IWmiDbSessionEx>
  53. {
  54. private:
  55. CEventCollector m_aTransactedEvents;
  56. bool m_bInWriteTransaction;
  57. public:
  58. CSession(CLifeControl* pControl = NULL) : TUnkBase(pControl), m_bInWriteTransaction(false) {}
  59. virtual ~CSession();
  60. ULONG STDMETHODCALLTYPE Release();
  61. HRESULT STDMETHODCALLTYPE GetObject(
  62. IWmiDbHandle *pScope,
  63. IWbemPath *pPath,
  64. DWORD dwFlags,
  65. DWORD dwRequestedHandleType,
  66. IWmiDbHandle **ppResult
  67. );
  68. HRESULT STDMETHODCALLTYPE GetObjectDirect(
  69. IWmiDbHandle *pScope,
  70. IWbemPath *pPath,
  71. DWORD dwFlags,
  72. REFIID riid,
  73. LPVOID *pObj
  74. );
  75. HRESULT STDMETHODCALLTYPE PutObject(
  76. IWmiDbHandle *pScope,
  77. REFIID riid,
  78. LPVOID pObj,
  79. DWORD dwFlags,
  80. DWORD dwRequestedHandleType,
  81. IWmiDbHandle **ppResult
  82. );
  83. HRESULT STDMETHODCALLTYPE DeleteObject(
  84. IWmiDbHandle *pScope,
  85. DWORD dwFlags,
  86. REFIID riid,
  87. LPVOID pObj
  88. );
  89. HRESULT STDMETHODCALLTYPE ExecQuery(
  90. IWmiDbHandle *pScope,
  91. IWbemQuery *pQuery,
  92. DWORD dwFlags,
  93. DWORD dwRequestedHandleType,
  94. DWORD *dwMessageFlags,
  95. IWmiDbIterator **ppQueryResult
  96. );
  97. HRESULT STDMETHODCALLTYPE RenameObject(
  98. IWbemPath *pOldPath,
  99. IWbemPath *pNewPath,
  100. DWORD dwFlags,
  101. DWORD dwRequestedHandleType,
  102. IWmiDbHandle **ppResult
  103. );
  104. HRESULT STDMETHODCALLTYPE Enumerate(
  105. IWmiDbHandle *pScope,
  106. DWORD dwFlags,
  107. DWORD dwRequestedHandleType,
  108. IWmiDbIterator **ppQueryResult
  109. );
  110. HRESULT STDMETHODCALLTYPE AddObject(
  111. IWmiDbHandle *pScope,
  112. IWbemPath *pPath,
  113. DWORD dwFlags,
  114. DWORD dwRequestedHandleType,
  115. IWmiDbHandle **ppResult
  116. );
  117. HRESULT STDMETHODCALLTYPE RemoveObject (
  118. IWmiDbHandle *pScope,
  119. IWbemPath *pPath,
  120. DWORD dwFlags
  121. );
  122. HRESULT STDMETHODCALLTYPE SetDecoration(
  123. LPWSTR lpMachineName,
  124. LPWSTR lpNamespacePath
  125. );
  126. HRESULT STDMETHODCALLTYPE SupportsQueries(
  127. DWORD *dwQuerySupportLevel
  128. ) {return WBEM_E_FAILED;};
  129. HRESULT STDMETHODCALLTYPE GetObjectByPath(
  130. IWmiDbHandle *pScope,
  131. LPCWSTR wszPath,
  132. DWORD dwFlags,
  133. REFIID riid,
  134. LPVOID *pObj
  135. );
  136. HRESULT STDMETHODCALLTYPE DeleteObjectByPath(
  137. IWmiDbHandle *pScope,
  138. LPCWSTR wszObjectPath,
  139. DWORD dwFlags
  140. );
  141. HRESULT STDMETHODCALLTYPE ExecQuerySink(
  142. IWmiDbHandle *pScope,
  143. IWbemQuery *pQuery,
  144. DWORD dwFlags,
  145. DWORD dwRequestedHandleType,
  146. IWbemObjectSink* pSink,
  147. DWORD *dwMessageFlags
  148. );
  149. HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppv);
  150. HRESULT STDMETHODCALLTYPE BeginWriteTransaction(DWORD dwFlags);
  151. HRESULT STDMETHODCALLTYPE BeginReadTransaction(DWORD dwFlags);
  152. HRESULT STDMETHODCALLTYPE CommitTransaction(DWORD dwFlags);
  153. HRESULT STDMETHODCALLTYPE AbortTransaction(DWORD dwFlags);
  154. protected:
  155. };
  156. class CNamespaceHandle : public CUnkBase<IWmiDbHandle, &IID_IWmiDbHandle>
  157. {
  158. protected:
  159. static long s_lActiveRepNs;
  160. CRepository * m_pRepository;
  161. WString m_wsNamespace;
  162. WString m_wsScope;
  163. WString m_wsFullNamespace;
  164. WCHAR m_wszMachineName[MAX_COMPUTERNAME_LENGTH+1];
  165. WCHAR m_wszClassRootDir[MAX_PATH];
  166. long m_lClassRootDirLen;
  167. WCHAR m_wszInstanceRootDir[MAX_PATH];
  168. long m_lInstanceRootDirLen;
  169. CHierarchyCache* m_pClassCache;
  170. CForestCache* m_ForestCache;
  171. _IWmiObject* m_pNullClass;
  172. bool m_bCached;
  173. bool m_bUseIteratorLock;
  174. public:
  175. CNamespaceHandle(CLifeControl* pControl, CRepository * pRepository);
  176. ~CNamespaceHandle();
  177. STDMETHOD(GetHandleType)(DWORD* pdwType) {*pdwType = 0; return S_OK;}
  178. CHR Initialize(LPCWSTR wszNamespace, LPCWSTR wszScope = NULL);
  179. CHR GetObject(
  180. IWbemPath *pPath,
  181. DWORD dwFlags,
  182. DWORD dwRequestedHandleType,
  183. IWmiDbHandle **ppResult
  184. );
  185. CHR GetObjectDirect(
  186. IWbemPath *pPath,
  187. DWORD dwFlags,
  188. REFIID riid,
  189. LPVOID *pObj
  190. );
  191. CHR PutObject(
  192. REFIID riid,
  193. LPVOID pObj,
  194. DWORD dwFlags,
  195. DWORD dwRequestedHandleType,
  196. IWmiDbHandle **ppResult,
  197. CEventCollector &aEvents
  198. );
  199. CHR DeleteObject(
  200. DWORD dwFlags,
  201. REFIID riid,
  202. LPVOID pObj,
  203. CEventCollector &aEvents
  204. );
  205. CHR ExecQuery(
  206. IWbemQuery *pQuery,
  207. DWORD dwFlags,
  208. DWORD dwRequestedHandleType,
  209. DWORD *dwMessageFlags,
  210. IWmiDbIterator **ppQueryResult
  211. );
  212. CHR GetObjectByPath(
  213. LPWSTR wszPath,
  214. DWORD dwFlags,
  215. REFIID riid,
  216. LPVOID *pObj
  217. );
  218. CHR ExecQuerySink(
  219. IWbemQuery *pQuery,
  220. DWORD dwFlags,
  221. DWORD dwRequestedHandleType,
  222. IWbemObjectSink* pSink,
  223. DWORD *dwMessageFlags
  224. );
  225. CHR DeleteObjectByPath(DWORD dwFlags, LPWSTR wszPath, CEventCollector &aEvents);
  226. HRESULT SendEvents(CEventCollector &aEvents);
  227. CHR GetErrorStatus();
  228. void SetErrorStatus(HRESULT hres);
  229. HRESULT CreateSystemClasses(CFlexArray &aSystemClasses);
  230. HRESULT RecursiveDeleteSystemClasses(CWStringArray &aSystemClasses, CWStringArray &aSystemClassesSuperclass);
  231. void TellIteratorNotToLock() { m_bUseIteratorLock = false; }
  232. protected:
  233. CHR GetObjectHandleByPath(LPWSTR wszBuffer, DWORD dwFlags,
  234. DWORD dwRequestedHandleType, IWmiDbHandle **ppResult);
  235. CHR PutInstance(_IWmiObject* pInst, DWORD dwFlags, CEventCollector &aEvents);
  236. CHR PutClass(_IWmiObject* pClass, DWORD dwFlags, CEventCollector &aEvents);
  237. CHR ConstructClassRelationshipsDir(LPCWSTR wszClassName,
  238. LPWSTR wszDirPath);
  239. CHR WriteParentChildRelationship(LPCWSTR wszChildFileName,
  240. LPCWSTR wszParentName);
  241. CHR WriteClassReferences(_IWmiObject* pClass, LPCWSTR wszFileName);
  242. CHR ExecClassQuery(QL_LEVEL_1_RPN_EXPRESSION* pQuery,
  243. IWbemObjectSink* pSink, DWORD dwFlags);
  244. CHR ExecInstanceQuery(QL_LEVEL_1_RPN_EXPRESSION* pQuery,
  245. LPCWSTR wszClassName, bool bDeep,
  246. IWbemObjectSink* pSink);
  247. CHR GetClassDirect(LPCWSTR wszClassName, REFIID riid, void** ppObj,
  248. bool bClone, __int64* pnTime,
  249. bool* pbRead, bool *pbSystemClass);
  250. CHR GetInstanceDirect(ParsedObjectPath* pPath,
  251. REFIID riid, void** ppObj);
  252. CHR DeleteInstance(LPCWSTR wszClassName, LPCWSTR wszKey, CEventCollector &aEvents);
  253. CHR DeleteInstanceByFile(LPCWSTR wszFilePath, _IWmiObject* pClass,
  254. bool bClassDeletion, CEventCollector &aEvents);
  255. CHR DeleteClass(LPCWSTR wszClassName, CEventCollector &aEvents);
  256. CHR DeleteClassInstances(LPCWSTR wszClassName, _IWmiObject* pClass, CEventCollector &aEvents);
  257. CHR FileToSystemClass(LPCWSTR wszFileName, _IWmiObject** ppClass,
  258. bool bClone, __int64* pnTime = NULL);
  259. CHR FileToClass(LPCWSTR wszFileName, _IWmiObject** ppClass,
  260. bool bClone, __int64* pnTime,
  261. bool *pbSystemClass);
  262. CHR FileToInstance(LPCWSTR wszFileName, _IWmiObject** ppInstance,
  263. bool bMustBeThere = false);
  264. CHR WriteInstanceReferences(_IWmiObject* pInst, LPCWSTR wszClassName,
  265. LPCWSTR wszFilePath);
  266. CHR WriteInstanceReference(LPCWSTR wszReferringFile,
  267. LPCWSTR wszReferringClass,
  268. LPCWSTR wszReferringProp, LPWSTR wszReference);
  269. CHR CalculateInstanceFileBase(LPCWSTR wszInstancePath,
  270. LPWSTR wszFilePath);
  271. CHR ExecClassRefQuery(LPCWSTR wszQuery, LPCWSTR wszClassName,
  272. IWbemObjectSink* pSink);
  273. CHR ExecReferencesQuery(LPCWSTR wszQuery, IWbemObjectSink* pSink);
  274. CHR ExecInstanceRefQuery(LPCWSTR wszQuery, LPCWSTR wszClassName,
  275. LPCWSTR wszKey, IWbemObjectSink* pSink);
  276. CHR GetReferrerFromFile(LPCWSTR wszReferenceFile,
  277. LPWSTR wszReferrerRelFile,
  278. LPWSTR* pwszReferrerNamespace,
  279. LPWSTR* pwszReferrerClass,
  280. LPWSTR* pwszReferrerProp);
  281. CHR DeleteInstanceReference(LPCWSTR wszOurFilePath,
  282. LPWSTR wszReference);
  283. CHR DeleteInstanceReferences(_IWmiObject* pInst, LPCWSTR wszFilePath);
  284. CHR EnumerateClasses(IWbemObjectSink* pSink,
  285. LPCWSTR wszSuperClass, LPCWSTR wszAncestor,
  286. bool bClone, bool bDontIncludeAncestorInResultSet);
  287. CHR ListToEnum(CWStringArray& wsClasses,
  288. IWbemObjectSink* pSink, bool bClone);
  289. bool Hash(LPCWSTR wszName, LPWSTR wszHash);
  290. CHR InstanceToFile(IWbemClassObject* pInst, LPCWSTR wszClassName,
  291. LPCWSTR wszFileName, __int64 nClassTime);
  292. CHR ConstructInstanceDefName(LPWSTR wszInstanceDefName, LPCWSTR wszKey);
  293. CHR ClassToFile(_IWmiObject* pSuperClass, _IWmiObject* pClass,
  294. LPCWSTR wszFileName, __int64 nFakeUpdateTime = 0);
  295. CHR ConstructClassName(LPCWSTR wszClassName,
  296. LPWSTR wszFileName);
  297. CHR TryGetShortcut(LPWSTR wszPath, DWORD dwFlags, REFIID riid,
  298. LPVOID *pObj);
  299. CHR ComputeKeyFromPath(LPWSTR wszPath, LPWSTR wszKey,
  300. LPWSTR* pwszClassName, bool* pbIsClass,
  301. LPWSTR* pwszNamespace = NULL);
  302. CHR ParseKey(LPWSTR wszKeyStart, LPWSTR* pwcRealStart,
  303. LPWSTR* pwcNextKey);
  304. CHR GetInstanceByKey(LPCWSTR wszClassName, LPCWSTR wszKey,
  305. REFIID riid, void** ppObj);
  306. CHR WriteClassRelationships(_IWmiObject* pClass, LPCWSTR wszFileName);
  307. CHR ConstructParentChildFileName(LPCWSTR wszChildFileName,
  308. LPCWSTR wszParentName,
  309. LPWSTR wszParentChildFileName);
  310. CHR DeleteDerivedClasses(LPCWSTR wszClassName, CEventCollector &aEvents);
  311. CHR EraseParentChildRelationship(LPCWSTR wszChildFileName,
  312. LPCWSTR wszParentName);
  313. CHR EraseClassRelationships(LPCWSTR wszClassName,
  314. _IWmiObject* pClass, LPCWSTR wszFileName);
  315. CHR GetClassByHash(LPCWSTR wszHash, bool bClone, _IWmiObject** ppClass,
  316. __int64* pnTime, bool* pbRead,
  317. bool *pbSystemClass);
  318. CHR DeleteClassByHash(LPCWSTR wszHash, CEventCollector &aEvents);
  319. CHR DeleteClassInternal(LPCWSTR wszClassName, _IWmiObject* pClass,
  320. LPCWSTR wszFileName, CEventCollector &aEvents,
  321. bool bSystemClass);
  322. CHR GetChildHashes(LPCWSTR wszClassName, CWStringArray& wsChildHashes);
  323. CHR GetChildDefs(LPCWSTR wszClassName, bool bRecursive,
  324. IWbemObjectSink* pSink, bool bClone);
  325. CHR ConstructClassDefFileName(LPCWSTR wszClassName, LPWSTR wszFileName);
  326. CHR ConstructClassDefFileNameFromHash(LPCWSTR wszHash,
  327. LPWSTR wszFileName);
  328. CHR ConstructClassRelationshipsDirFromHash(LPCWSTR wszHash,
  329. LPWSTR wszDirPath);
  330. CHR GetChildHashesByHash(LPCWSTR wszHash, CWStringArray& wsChildHashes);
  331. CHR GetChildDefsByHash(LPCWSTR wszHash, bool bRecursive,
  332. IWbemObjectSink* pSink, bool bClone);
  333. CHR FireEvent(CEventCollector &aEvents, DWORD dwType, LPCWSTR wszArg1, _IWmiObject* pObj1,
  334. _IWmiObject* pObj2 = NULL);
  335. CHR DeleteSelf(CEventCollector &aEvents);
  336. CHR DeleteInstanceAsScope(_IWmiObject* pInst, CEventCollector &aEvents);
  337. CHR DeleteInstanceSelf(LPCWSTR wszFilePath, _IWmiObject* pInst,
  338. bool bClassDeletion);
  339. CHR ConstructReferenceDir(LPWSTR wszTargetPath, LPWSTR wszDir);
  340. CHR ConstructReferenceDirFromKey(LPCWSTR wszClassName,
  341. LPCWSTR wszKey, LPWSTR wszReferenceDir);
  342. CHR ConstructReferenceFileName(LPWSTR wszReference,
  343. LPCWSTR wszReferringFile, LPWSTR wszReferenceFile);
  344. CHR ConstructKeyRootDirFromClass(LPWSTR wszDir, LPCWSTR wszClassName);
  345. CHR ConstructKeyRootDirFromKeyRoot(LPWSTR wszDir,
  346. LPCWSTR wszKeyRootClass);
  347. CHR ConstructLinkDirFromClass(LPWSTR wszDir, LPCWSTR wszClassName);
  348. CHR WriteInstanceLinkByHash(LPCWSTR wszClassName,
  349. LPCWSTR wszInstanceHash);
  350. CHR DeleteInstanceLink(_IWmiObject* pInst,
  351. LPCWSTR wszInstanceDefFilePath);
  352. CHR GetKeyRoot(LPCWSTR wszClass,
  353. TEMPFREE_ME LPWSTR* pwszKeyRootClass);
  354. CHR ConstructInstDefNameFromLinkName(LPWSTR wszInstanceDefName,
  355. LPCWSTR wszInstanceLinkName);
  356. CHR ExecDeepInstanceQuery(QL_LEVEL_1_RPN_EXPRESSION* pQuery,
  357. LPCWSTR wszClassHash,
  358. IWbemObjectSink* pSink);
  359. CHR ExecShallowInstanceQuery(QL_LEVEL_1_RPN_EXPRESSION* pQuery,
  360. LPCWSTR wszClassHash,
  361. IWbemObjectSink* pSink);
  362. CHR GetKeyRootByHash(LPCWSTR wszClassHash,
  363. TEMPFREE_ME LPWSTR* pwszKeyRootClass);
  364. CHR ConstructKeyRootDirFromClassHash(LPWSTR wszDir,
  365. LPCWSTR wszClassHash);
  366. CHR ConstructLinkDirFromClassHash(LPWSTR wszDir, LPCWSTR wszClassHash);
  367. CHR ConstructClassReferenceFileName(LPCWSTR wszReferredToClass,
  368. LPCWSTR wszReferringFile,
  369. LPCWSTR wszReferringProp,
  370. LPWSTR wszFieName);
  371. CHR WriteClassReference(_IWmiObject* pReferringClass,
  372. LPCWSTR wszReferringFile,
  373. LPCWSTR wszReferringProp);
  374. CHR EraseClassReference(_IWmiObject* pReferringClass,
  375. LPCWSTR wszReferringFile,
  376. LPCWSTR wszReferringProp);
  377. //CFileCache* GetFileCache();
  378. CHR CanClassBeUpdatedCompatible(DWORD dwFlags, LPCWSTR wszClassName,
  379. _IWmiObject *pOldClass, _IWmiObject *pNewClass);
  380. CHR DeleteInstanceBackReferences(LPCWSTR wszFilePath);
  381. CHR ConstructReferenceDirFromFilePath(LPCWSTR wszFilePath,
  382. LPWSTR wszReferenceDir);
  383. CHR ClassHasChildren(LPCWSTR wszClassName);
  384. CHR ClassHasInstances(LPCWSTR wszClassName);
  385. CHR ClassHasInstancesFromClassHash(LPCWSTR wszClassHash);
  386. CHR ClassHasInstancesInScopeFromClassHash(
  387. LPCWSTR wszInstanceRootDir, LPCWSTR wszClassHash);
  388. CHR UpdateClassCompatible(_IWmiObject* pSuperClass,
  389. LPCWSTR wszClassName, _IWmiObject *pNewClass,
  390. _IWmiObject *pOldClass, __int64 nFakeUpdateTime = 0);
  391. CHR UpdateClassCompatibleHash(_IWmiObject* pSuperClass,
  392. LPCWSTR wszClassHash, _IWmiObject *pClass,
  393. _IWmiObject *pOldClass, __int64 nFakeUpdateTime = 0);
  394. CHR UpdateClassSafeForce(_IWmiObject* pSuperClass, DWORD dwFlags,
  395. LPCWSTR wcsClassName, _IWmiObject *pOldClass,
  396. _IWmiObject *pNewClass, CEventCollector &aEvents);
  397. CHR UpdateClassAggressively(_IWmiObject* pSuperClass, DWORD dwFlags,
  398. LPCWSTR wszClassName, _IWmiObject *pNewClass,
  399. _IWmiObject *pOldClass,
  400. CEventCollector &aEvents);
  401. CHR UpdateChildClassAggressively(DWORD dwFlags, LPCWSTR wszClassHash,
  402. _IWmiObject *pNewClass,
  403. CEventCollector &aEvents);
  404. };
  405. class CDbIterator : public CUnkBase2<IWmiDbIterator, &IID_IWmiDbIterator,
  406. IWbemObjectSink, &IID_IWbemObjectSink>
  407. {
  408. protected:
  409. CCritSec m_cs;
  410. CRefedPointerQueue<IWbemClassObject> m_qObjects;
  411. long m_lCurrentIndex;
  412. void* m_pExecFiber;
  413. CFiberTask* m_pExecReq;
  414. HRESULT m_hresStatus;
  415. void* m_pMainFiber;
  416. DWORD m_dwNumRequested;
  417. HRESULT m_hresCancellationStatus;
  418. bool m_bExecFiberRunning;
  419. bool m_bUseLock;
  420. public:
  421. CDbIterator(CLifeControl* pControl, bool bUseLock);
  422. ~CDbIterator();
  423. STDMETHOD(Cancel) (DWORD dwFlags);
  424. STDMETHOD(NextBatch)(
  425. DWORD dwNumRequested,
  426. DWORD dwTimeOutSeconds,
  427. DWORD dwFlags,
  428. DWORD dwRequestedHandleType,
  429. REFIID riid,
  430. DWORD *pdwNumReturned,
  431. LPVOID *ppObjects
  432. );
  433. void SetExecFiber(void* pFiber, CFiberTask* pReq);
  434. STDMETHOD(Indicate)(long lNumObjects, IWbemClassObject** apObjects);
  435. STDMETHOD(SetStatus)(long lFlags, HRESULT hresResult,
  436. BSTR, IWbemClassObject*);
  437. };
  438. #endif