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.

556 lines
18 KiB

  1. /////////////////////////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Microsoft WMI OLE DB Provider
  4. // (C) Copyright 1999 Microsoft Corporation. All Rights Reserved.
  5. //
  6. // CDataSource base object and contained interface definitions
  7. //
  8. /////////////////////////////////////////////////////////////////////////////////////////////////////////
  9. #ifndef _DATASRC_H_
  10. #define _DATASRC_H_
  11. #include "headers.h"
  12. #include "errinf.h"
  13. ///////////////////////////////////////////////////////////////////////////////////
  14. // Forward declarations
  15. ///////////////////////////////////////////////////////////////////////////////////
  16. class CImpIDBInitialize;
  17. class CImpIDBProperties;
  18. class CImpIDBInfo;
  19. class CImpIDBCreateSession;
  20. class CImpIPersistFile;
  21. class CDataSource;
  22. class CImpIDBDataSrcAdmin;
  23. class CImpIObjectAccessControl;
  24. class CImpISecurityInfo;
  25. typedef CImpIDBInitialize* PIMPIDBINITIALIZE;
  26. typedef CImpIDBProperties* PIMPIDBProperties;
  27. typedef CImpIDBInfo* PIMPIDBINFO;
  28. typedef CImpIDBCreateSession* PIMPIDBCREATESESSION;
  29. typedef CImpIPersistFile* PIMPIPERSISTFILE;
  30. typedef CDataSource* PCDATASOURCE;
  31. typedef CImpIDBDataSrcAdmin* PIDBDATASRCADMIN;
  32. typedef CImpIObjectAccessControl* PIOBJACCESSCTRL;
  33. typedef CImpISecurityInfo * PIMPISECURITYINFO;
  34. ///////////////////////////////////////////////////////////////////////////////////
  35. //
  36. // CDataSource: Containing class for all interfaces on the Datasource
  37. // CoType Object
  38. //
  39. ///////////////////////////////////////////////////////////////////////////////////
  40. class CDataSource : public CBaseObj
  41. {
  42. //==========================================
  43. // Contained interfaces are friends
  44. //==========================================
  45. friend class CImpIDBInitialize;
  46. friend class CImpIDBInfo;
  47. friend class CImpIDBProperties;
  48. friend class CImpIDBCreateSession;
  49. friend class CImpIPersistFile;
  50. friend class CDBSession;
  51. friend class CImpIDBDataSrcAdmin;
  52. friend class CImpISupportErrorInfo;
  53. friend class CImpIObjectAccessControl;
  54. friend class CImpISecurityInfo;
  55. protected:
  56. BOOL m_fDSOInitialized; // TRUE if this Data Source object is an an initialized state
  57. BOOL m_fDBSessionCreated; // TRUE if DBSession object has been created
  58. PCUTILPROP m_pUtilProp; // Utility object to manage properties
  59. PIMPIDBINITIALIZE m_pIDBInitialize; // Contained IDBInitialize
  60. PIMPIDBProperties m_pIDBProperties; // Contained IDBProperties
  61. PIMPIDBINFO m_pIDBInfo; // Contained IDBInfo
  62. PIMPIDBCREATESESSION m_pIDBCreateSession; // contained IDBCreateSession
  63. PIMPIPERSISTFILE m_pIPersistFile; // contained IPersistFile
  64. // PIMPIPERSISTFILE m_pIPersistFile;
  65. PIDBDATASRCADMIN m_pIDBDataSourceAdmin; //contained IDBDataSourceAdmin interface
  66. PIOBJACCESSCTRL m_pIObjectAccessControl; // contained IObjectAccessControl
  67. PIMPISUPPORTERRORINFO m_pISupportErrorInfo; //DataSource interface
  68. PIMPISECURITYINFO m_pISecurityInfo;
  69. CErrorData m_CErrorData; // Error data object
  70. BOOL m_bIsPersitFileDirty; // flag to indicate whether persist file is dirty or not
  71. BSTR m_strPersistFileName; // Name of the file in which datasource is persisted
  72. HRESULT AddInterfacesForISupportErrorInfo();
  73. HRESULT AdjustPreviligeTokens();
  74. HRESULT InitializeConnectionProperties();
  75. HRESULT CreateSession(IUnknown* pUnkOuter, //IN Controlling IUnknown if being aggregated
  76. REFIID riid, //IN The ID of the interface
  77. IUnknown** ppDBSession);
  78. public:
  79. CDataSource(LPUNKNOWN);
  80. ~CDataSource(void);
  81. HRESULT FInit(void); //Intitialization Routine
  82. STDMETHODIMP QueryInterface(REFIID, LPVOID *);// Request an Interface
  83. STDMETHODIMP_(ULONG) AddRef(void); //Increments the Reference count
  84. STDMETHODIMP_(ULONG) Release(void); //Decrements the Reference count
  85. inline VOID RemoveSession(void) //Set the DBSessionCreated flag to FALSE
  86. { m_fDBSessionCreated = FALSE;};
  87. inline CErrorData * GetErrorDataPtr() { return &m_CErrorData; }
  88. //==========================================================================
  89. // The wbem api
  90. //==========================================================================
  91. CWbemConnectionWrapper* m_pWbemWrap;
  92. HRESULT GetDataSrcProperty(DBPROPID propId , VARIANT & varValue);
  93. void SetPersistDirty() { m_bIsPersitFileDirty = FALSE; }
  94. void ReSetPersistDirty() { m_bIsPersitFileDirty = TRUE; }
  95. HRESULT GetConnectionInitProperties(DBPROPSET** pprgPropertySets)
  96. {
  97. return m_pUtilProp->GetConnectionInitProperties(pprgPropertySets);
  98. }
  99. };
  100. ///////////////////////////////////////////////////////////////////////////////////
  101. typedef CDataSource *PCDATASOURCE;
  102. ///////////////////////////////////////////////////////////////////////////////////
  103. //
  104. // CImpIDBInitialize: Contained IDBInitialize class
  105. //
  106. ///////////////////////////////////////////////////////////////////////////////////
  107. class CImpIDBInitialize : public IDBInitialize
  108. {
  109. private:
  110. DEBUGCODE(ULONG m_cRef);
  111. CDataSource *m_pObj;
  112. public:
  113. CImpIDBInitialize( CDataSource *pObj )
  114. {
  115. m_cRef = 0L;
  116. m_pObj = pObj;
  117. }
  118. ~CImpIDBInitialize()
  119. {
  120. }
  121. STDMETHODIMP_(ULONG) AddRef(void)
  122. {
  123. DEBUGCODE(InterlockedIncrement((long*)&m_cRef));
  124. return m_pObj->GetOuterUnknown()->AddRef();
  125. }
  126. STDMETHODIMP_(ULONG) Release(void)
  127. {
  128. DEBUGCODE(long lRef = InterlockedDecrement((long*)&m_cRef));
  129. return m_pObj->GetOuterUnknown()->Release();
  130. }
  131. STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppv)
  132. {
  133. return m_pObj->GetOuterUnknown()->QueryInterface(riid, ppv);
  134. }
  135. //==================================================
  136. // IDBInitialize members
  137. //==================================================
  138. STDMETHODIMP Initialize(void); // Initialize Method
  139. STDMETHODIMP Uninitialize(void); // Uninitialize Method
  140. };
  141. ///////////////////////////////////////////////////////////////////////////////////
  142. //
  143. // CImpIDBCreateSession: contained IDBCreateSession class
  144. //
  145. ///////////////////////////////////////////////////////////////////////////////////
  146. class CImpIDBCreateSession : public IDBCreateSession
  147. {
  148. private:
  149. DEBUGCODE(ULONG m_cRef);
  150. CDataSource *m_pObj;
  151. public:
  152. CImpIDBCreateSession( CDataSource *pObj )
  153. {
  154. DEBUGCODE(m_cRef = 0L);
  155. m_pObj = pObj;
  156. }
  157. ~CImpIDBCreateSession()
  158. {
  159. }
  160. STDMETHODIMP_(ULONG) AddRef(void)
  161. {
  162. DEBUGCODE(InterlockedIncrement((long*)&m_cRef));
  163. return m_pObj->GetOuterUnknown()->AddRef();
  164. }
  165. STDMETHODIMP_(ULONG) Release(void)
  166. {
  167. DEBUGCODE(long lRef = InterlockedDecrement((long*)&m_cRef));
  168. return m_pObj->GetOuterUnknown()->Release();
  169. }
  170. STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppv)
  171. {
  172. return m_pObj->GetOuterUnknown()->QueryInterface(riid, ppv);
  173. }
  174. //=================================================================
  175. // IDBCreateSession method
  176. //=================================================================
  177. STDMETHODIMP CreateSession( IUnknown*, REFIID, IUnknown** ); // CreateSession method
  178. };
  179. /////////////////////////////////////////////////////////////////////////////////////////////////
  180. //
  181. // CImpIDBProperties: Contained IDBProperties class
  182. //
  183. /////////////////////////////////////////////////////////////////////////////////////////////////
  184. class CImpIDBProperties : public IDBProperties
  185. {
  186. private:
  187. DEBUGCODE(ULONG m_cRef);
  188. CDataSource *m_pObj;
  189. public:
  190. CImpIDBProperties( CDataSource *pObj )
  191. {
  192. DEBUGCODE(m_cRef = 0L);
  193. m_pObj = pObj;
  194. }
  195. ~CImpIDBProperties()
  196. {
  197. }
  198. STDMETHODIMP_(ULONG) AddRef(void)
  199. {
  200. DEBUGCODE(InterlockedIncrement((long*)&m_cRef));
  201. return m_pObj->GetOuterUnknown()->AddRef();
  202. }
  203. STDMETHODIMP_(ULONG) Release(void)
  204. {
  205. DEBUGCODE(long lRef = InterlockedDecrement((long*)&m_cRef));
  206. return m_pObj->GetOuterUnknown()->Release();
  207. }
  208. STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppv)
  209. {
  210. return m_pObj->GetOuterUnknown()->QueryInterface(riid, ppv);
  211. }
  212. //==========================================================
  213. // IDBProperties member functions
  214. //==========================================================
  215. STDMETHODIMP GetProperties // GetProperties method
  216. (
  217. ULONG cPropertySets,
  218. const DBPROPIDSET rgPropertySets[],
  219. ULONG* pcProperties,
  220. DBPROPSET** prgProperties
  221. );
  222. STDMETHODIMP GetPropertyInfo // GetPropertyInfo method
  223. (
  224. ULONG cPropertySets,
  225. const DBPROPIDSET rgPropertySets[],
  226. ULONG* pcPropertyInfoSets,
  227. DBPROPINFOSET** prgPropertyInfoSets,
  228. WCHAR** ppDescBuffer
  229. );
  230. STDMETHODIMP SetProperties // SetProperties method
  231. (
  232. ULONG cProperties,
  233. DBPROPSET rgProperties[]
  234. );
  235. };
  236. ////////////////////////////////////////////////////////////////////////////////////////
  237. //
  238. // CImpIDBInfo: Contained IDBInfo class
  239. //
  240. ////////////////////////////////////////////////////////////////////////////////////////
  241. class CImpIDBInfo : public IDBInfo
  242. {
  243. private:
  244. DEBUGCODE(ULONG m_cRef);
  245. CDataSource *m_pObj;
  246. LONG GetLiteralIndex(DBLITERAL rgLiterals);
  247. LONG GetStringBufferSize(ULONG cLiterals,
  248. const DBLITERAL rgLiterals[]);
  249. public:
  250. CImpIDBInfo( CDataSource *pObj )
  251. {
  252. DEBUGCODE(m_cRef = 0L);
  253. m_pObj = pObj;
  254. }
  255. ~CImpIDBInfo()
  256. {
  257. }
  258. STDMETHODIMP_(ULONG) AddRef(void)
  259. {
  260. DEBUGCODE(InterlockedIncrement((long*)&m_cRef));
  261. return m_pObj->GetOuterUnknown()->AddRef();
  262. }
  263. STDMETHODIMP_(ULONG) Release(void)
  264. {
  265. DEBUGCODE(long lRef = InterlockedDecrement((long*)&m_cRef));
  266. return m_pObj->GetOuterUnknown()->Release();
  267. }
  268. STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppv)
  269. {
  270. return m_pObj->GetOuterUnknown()->QueryInterface(riid, ppv);
  271. }
  272. //========================================================
  273. // IDBProperties member functions
  274. //========================================================
  275. STDMETHODIMP GetKeywords // GetKeywords method
  276. (
  277. LPWSTR* ppwsKeywords
  278. );
  279. STDMETHODIMP GetLiteralInfo // GetLiteralInfo method
  280. (
  281. ULONG cLiterals,
  282. const DBLITERAL rgLiterals[ ],
  283. ULONG* pcLiteralInfo,
  284. DBLITERALINFO** prgLiteralInfo,
  285. WCHAR** ppCharBuffer
  286. );
  287. };
  288. ///////////////////////////////////////////////////////////////////////////////////////////////////////
  289. //
  290. // CImpIPersist: contained IPersist class
  291. //
  292. ///////////////////////////////////////////////////////////////////////////////////////////////////////
  293. class CImpIPersistFile : public IPersistFile
  294. {
  295. private:
  296. DEBUGCODE(ULONG m_cRef);
  297. CDataSource *m_pObj;
  298. HRESULT WriteToFile(LPCOLESTR strFileName);
  299. HRESULT ReadFromFile(LPCOLESTR pszFileName);
  300. void ClearDirtyFlag();
  301. BOOL IsInitialized();
  302. BOOL WritePrivateProfileString(LPCOLESTR wszAppName,LPCOLESTR wszKeyName,LPCOLESTR wszValue,LPCOLESTR wszFileName);
  303. HRESULT GetCurrentFile(LPCOLESTR pszFileName,LPOLESTR wszFileNameFull,DWORD dwAccess);
  304. BOOL GetPrivateProfileStr(LPCOLESTR wszAppName,LPCOLESTR wszKeyName,LPCOLESTR wszFileName,LPOLESTR wszValue);
  305. BOOL GetPrivateProfileLong(LPCOLESTR wszAppName,LPCOLESTR wszKeyName,LPCOLESTR wszFileName, LONG &lValue);
  306. HRESULT GetAbsolutePath(LPCOLESTR pwszFileName,LPOLESTR wszFileNameFull);
  307. HRESULT SetDBInitProp(DBPROPID propId ,GUID guidPropSet,VARIANT vPropValue);
  308. public:
  309. CImpIPersistFile( CDataSource *pObj )
  310. {
  311. DEBUGCODE(m_cRef = 0L);
  312. m_pObj = pObj;
  313. }
  314. ~CImpIPersistFile()
  315. {
  316. }
  317. STDMETHODIMP_(ULONG) AddRef(void)
  318. {
  319. DEBUGCODE(InterlockedIncrement((long*)&m_cRef));
  320. return m_pObj->GetOuterUnknown()->AddRef();
  321. }
  322. STDMETHODIMP_(ULONG) Release(void)
  323. {
  324. DEBUGCODE(long lRef = InterlockedDecrement((long*)&m_cRef));
  325. return m_pObj->GetOuterUnknown()->Release();
  326. }
  327. STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppv)
  328. {
  329. return m_pObj->GetOuterUnknown()->QueryInterface(riid, ppv);
  330. }
  331. //============================================================
  332. // IPersist method
  333. //============================================================
  334. STDMETHODIMP GetClassID( CLSID *pClassID ); // GetClassID method
  335. STDMETHODIMP IsDirty(void);
  336. STDMETHODIMP GetCurFile(LPOLESTR *ppszFileName);
  337. STDMETHODIMP Load(LPCOLESTR pszFileName, DWORD dwMode);
  338. STDMETHODIMP Save(LPCOLESTR pszFileName,BOOL fRemember);
  339. STDMETHODIMP SaveCompleted(LPCOLESTR pszFileName);
  340. };
  341. class CImpIDBDataSrcAdmin : public IDBDataSourceAdmin
  342. {
  343. private:
  344. DEBUGCODE(ULONG m_cRef);
  345. CDataSource *m_pObj;
  346. public:
  347. CImpIDBDataSrcAdmin( CDataSource *pObj )
  348. {
  349. DEBUGCODE(m_cRef = 0L);
  350. m_pObj = pObj;
  351. }
  352. ~CImpIDBDataSrcAdmin()
  353. {
  354. }
  355. STDMETHODIMP_(ULONG) AddRef(void)
  356. {
  357. DEBUGCODE(InterlockedIncrement((long*)&m_cRef));
  358. return m_pObj->GetOuterUnknown()->AddRef();
  359. }
  360. STDMETHODIMP_(ULONG) Release(void)
  361. {
  362. DEBUGCODE(long lRef = InterlockedDecrement((long*)&m_cRef));
  363. return m_pObj->GetOuterUnknown()->Release();
  364. }
  365. STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppv)
  366. {
  367. return m_pObj->GetOuterUnknown()->QueryInterface(riid, ppv);
  368. }
  369. STDMETHODIMP CreateDataSource( ULONG cPropertySets,
  370. DBPROPSET rgPropertySets[ ],
  371. IUnknown * pUnkOuter,
  372. REFIID riid,
  373. IUnknown ** ppDBSession);
  374. STDMETHODIMP DestroyDataSource( void);
  375. STDMETHODIMP GetCreationProperties( ULONG cPropertyIDSets,
  376. const DBPROPIDSET rgPropertyIDSets[ ],
  377. ULONG * pcPropertyInfoSets,
  378. DBPROPINFOSET ** prgPropertyInfoSets,
  379. OLECHAR ** ppDescBuffer);
  380. STDMETHODIMP ModifyDataSource( ULONG cPropertySets,DBPROPSET rgPropertySets[]);
  381. };
  382. class CImpIObjectAccessControl : public IObjectAccessControl
  383. {
  384. private:
  385. DEBUGCODE(ULONG m_cRef);
  386. CDataSource *m_pObj;
  387. STDMETHODIMP IfValidSecObject(SEC_OBJECT *pObject);
  388. public:
  389. CImpIObjectAccessControl( CDataSource *pObj )
  390. {
  391. DEBUGCODE(m_cRef = 0L);
  392. m_pObj = pObj;
  393. }
  394. ~CImpIObjectAccessControl()
  395. {
  396. }
  397. STDMETHODIMP_(ULONG) AddRef(void)
  398. {
  399. DEBUGCODE(InterlockedIncrement((long*)&m_cRef));
  400. return m_pObj->GetOuterUnknown()->AddRef();
  401. }
  402. STDMETHODIMP_(ULONG) Release(void)
  403. {
  404. DEBUGCODE(long lRef = InterlockedDecrement((long*)&m_cRef));
  405. return m_pObj->GetOuterUnknown()->Release();
  406. }
  407. STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppv)
  408. {
  409. return m_pObj->GetOuterUnknown()->QueryInterface(riid, ppv);
  410. }
  411. STDMETHODIMP GetObjectAccessRights( SEC_OBJECT *pObject,
  412. ULONG *pcAccessEntries,
  413. EXPLICIT_ACCESS_W **prgAccessEntries);
  414. STDMETHODIMP GetObjectOwner( SEC_OBJECT *pObject,TRUSTEE_W ** ppOwner);
  415. STDMETHODIMP IsObjectAccessAllowed( SEC_OBJECT *pObject,
  416. EXPLICIT_ACCESS_W *pAccessEntry,
  417. BOOL *pfResult);
  418. STDMETHODIMP SetObjectAccessRights( SEC_OBJECT *pObject,
  419. ULONG cAccessEntries,
  420. EXPLICIT_ACCESS_W *prgAccessEntries);
  421. STDMETHODIMP SetObjectOwner( SEC_OBJECT *pObject,TRUSTEE_W *pOwner);
  422. };
  423. class CImpISecurityInfo : public ISecurityInfo
  424. {
  425. private:
  426. DEBUGCODE(ULONG m_cRef);
  427. CDataSource *m_pObj;
  428. STDMETHODIMP GetCurTrustee(TRUSTEE_W ** ppTrustee);
  429. public:
  430. CImpISecurityInfo( CDataSource *pObj )
  431. {
  432. DEBUGCODE(m_cRef = 0L);
  433. m_pObj = pObj;
  434. }
  435. ~CImpISecurityInfo()
  436. {
  437. }
  438. STDMETHODIMP_(ULONG) AddRef(void)
  439. {
  440. DEBUGCODE(InterlockedIncrement((long*)&m_cRef));
  441. return m_pObj->GetOuterUnknown()->AddRef();
  442. }
  443. STDMETHODIMP_(ULONG) Release(void)
  444. {
  445. DEBUGCODE(long lRef = InterlockedDecrement((long*)&m_cRef));
  446. return m_pObj->GetOuterUnknown()->Release();
  447. }
  448. STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppv)
  449. {
  450. return m_pObj->GetOuterUnknown()->QueryInterface(riid, ppv);
  451. }
  452. STDMETHODIMP GetCurrentTrustee(TRUSTEE_W ** ppTrustee);
  453. STDMETHODIMP GetObjectTypes(ULONG *cObjectTypes,GUID **gObjectTypes);
  454. STDMETHODIMP GetPermissions(GUID ObjectType,ACCESS_MASK *pPermissions);
  455. };
  456. #endif