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.

425 lines
10 KiB

  1. /*++
  2. Copyright (c) 1998-2000 Microsoft Corporation
  3. Module Name:
  4. metabase.h
  5. Abstract:
  6. This file contains implementation of:
  7. CMetabase, CServerMethod
  8. CMetabase encapsulates an IMSAdminBase pointer.
  9. Author:
  10. ???
  11. Revision History:
  12. Mohit Srivastava 18-Dec-00
  13. --*/
  14. #ifndef _metabase_h_
  15. #define _metabase_h_
  16. #include <iadmw.h>
  17. #include <comdef.h>
  18. //
  19. // Used by CMetabase
  20. //
  21. #define MAX_METABASE_PATH 1024
  22. #define DEFAULT_TIMEOUT_VALUE 30000
  23. //
  24. // Period to sleep while waiting for service to attain desired state
  25. // Used by CServerMethod
  26. //
  27. #define SLEEP_INTERVAL (500L)
  28. #define MAX_SLEEP_INST (60000) // For an instance
  29. class CMetabase;
  30. //
  31. // CMetabaseCache
  32. //
  33. class CMetabaseCache
  34. {
  35. private:
  36. static const m_cbBufFixed = 1024;
  37. BYTE m_pBufFixed[m_cbBufFixed];
  38. LPBYTE m_pBufDynamic;
  39. LPBYTE m_pBuf;
  40. DWORD m_cbBuf;
  41. DWORD m_dwNumEntries;
  42. METADATA_HANDLE m_hKey;
  43. public:
  44. CMetabaseCache()
  45. {
  46. memset(m_pBufFixed, 0, sizeof(m_pBufFixed));
  47. m_pBufDynamic = NULL;
  48. m_pBuf = NULL;
  49. m_cbBuf = 0;
  50. m_dwNumEntries = 0;
  51. m_hKey = 0;
  52. }
  53. ~CMetabaseCache()
  54. {
  55. delete [] m_pBufDynamic;
  56. m_pBufDynamic = NULL;
  57. m_pBuf = NULL;
  58. }
  59. METADATA_HANDLE GetHandle()
  60. {
  61. return m_hKey;
  62. }
  63. HRESULT Populate(
  64. IMSAdminBase* i_pIABase,
  65. METADATA_HANDLE i_hKey);
  66. HRESULT GetProp(
  67. DWORD i_dwId,
  68. DWORD i_dwUserType,
  69. DWORD i_dwDataType,
  70. LPBYTE* o_ppData,
  71. METADATA_GETALL_RECORD** o_ppmr) const;
  72. };
  73. class CMetabaseKeyList
  74. {
  75. public:
  76. CMetabaseKeyList()
  77. {
  78. InitializeListHead(&m_leHead);
  79. }
  80. ~CMetabaseKeyList()
  81. {
  82. while(!IsListEmpty(&m_leHead))
  83. {
  84. CKeyListNode* pNode =
  85. CONTAINING_RECORD(m_leHead.Flink, CKeyListNode, m_leEntry);
  86. DBG_ASSERT(pNode != NULL);
  87. RemoveEntryList(&pNode->m_leEntry);
  88. delete pNode;
  89. pNode = NULL;
  90. }
  91. }
  92. HRESULT Add(METADATA_HANDLE i_hKey)
  93. {
  94. CKeyListNode* pNew = new CKeyListNode;
  95. if(pNew == NULL)
  96. {
  97. return WBEM_E_OUT_OF_MEMORY;
  98. }
  99. pNew->hKey = i_hKey;
  100. InsertHeadList(&m_leHead, &pNew->m_leEntry);
  101. return WBEM_S_NO_ERROR;
  102. }
  103. HRESULT Remove(METADATA_HANDLE i_hKey)
  104. {
  105. LIST_ENTRY* pleEntry = &m_leHead;
  106. while(pleEntry->Flink != pleEntry)
  107. {
  108. CKeyListNode* pNode =
  109. CONTAINING_RECORD(pleEntry->Flink, CKeyListNode, m_leEntry);
  110. if(pNode->hKey == i_hKey)
  111. {
  112. RemoveEntryList(&pNode->m_leEntry);
  113. delete pNode;
  114. pNode = NULL;
  115. return WBEM_S_NO_ERROR;
  116. }
  117. pleEntry = pleEntry->Flink;
  118. }
  119. return WBEM_E_FAILED;
  120. }
  121. struct CKeyListNode
  122. {
  123. LIST_ENTRY m_leEntry;
  124. METADATA_HANDLE hKey;
  125. };
  126. const LIST_ENTRY* GetHead() const { return &m_leHead; }
  127. private:
  128. LIST_ENTRY m_leHead;
  129. };
  130. //
  131. // CMetabase
  132. //
  133. class CMetabase
  134. {
  135. private:
  136. IMSAdminBase2* m_pIABase;
  137. CMetabaseKeyList m_keyList;
  138. CMetabaseCache* m_pNodeCache;
  139. bool CheckKeyType(
  140. LPCWSTR i_wszKeyTypeCurrent,
  141. METABASE_KEYTYPE*& io_pktKeyTypeSearch);
  142. public:
  143. CMetabase();
  144. ~CMetabase();
  145. operator IMSAdminBase2*()
  146. {
  147. return m_pIABase;
  148. }
  149. //
  150. // IMSAdminBase/IMSAdminBase2 methods exposed thru WMI
  151. //
  152. HRESULT SaveData();
  153. HRESULT BackupWithPasswd(
  154. LPCWSTR i_wszMDBackupLocation,
  155. DWORD i_dwMDVersion,
  156. DWORD i_dwMDFlags,
  157. LPCWSTR i_wszPassword);
  158. HRESULT DeleteBackup(
  159. LPCWSTR i_wszMDBackupLocation,
  160. DWORD i_dwMDVersion);
  161. HRESULT EnumBackups(
  162. LPWSTR io_wszMDBackupLocation,
  163. DWORD* o_pdwMDVersion,
  164. PFILETIME o_pftMDBackupTime,
  165. DWORD i_dwMDEnumIndex);
  166. HRESULT RestoreWithPasswd(
  167. LPCWSTR i_wszMDBackupLocation,
  168. DWORD i_dwMDVersion,
  169. DWORD i_dwMDFlags,
  170. LPCWSTR i_wszPassword);
  171. HRESULT Export(
  172. LPCWSTR i_wszPasswd,
  173. LPCWSTR i_wszFileName,
  174. LPCWSTR i_wszSourcePath,
  175. DWORD i_dwMDFlags);
  176. HRESULT Import(
  177. LPCWSTR i_wszPasswd,
  178. LPCWSTR i_wszFileName,
  179. LPCWSTR i_wszSourcePath,
  180. LPCWSTR i_wszDestPath,
  181. DWORD i_dwMDFlags);
  182. HRESULT RestoreHistory(
  183. LPCWSTR i_wszMDHistoryLocation,
  184. DWORD i_dwMDMajorVersion,
  185. DWORD i_dwMDMinorVersion,
  186. DWORD i_dwMDFlags);
  187. HRESULT EnumHistory(
  188. LPWSTR io_wszMDHistoryLocation,
  189. DWORD* o_pdwMDMajorVersion,
  190. DWORD* o_pdwMDMinorVersion,
  191. PFILETIME o_pftMDHistoryTime,
  192. DWORD i_dwMDEnumIndex);
  193. //
  194. // Other IMSAdminBase methods
  195. //
  196. void CloseKey(METADATA_HANDLE i_hKey);
  197. METADATA_HANDLE OpenKey(LPCWSTR i_wszKey, BOOL i_bWrite);
  198. METADATA_HANDLE CreateKey(LPCWSTR i_wszKey);
  199. bool CheckKey(LPCWSTR i_wszKey);
  200. HRESULT CheckKey(LPCWSTR i_wszKey, METABASE_KEYTYPE* i_pktSearchKeyType);
  201. HRESULT DeleteKey(METADATA_HANDLE i_hKey, LPCWSTR i_wszKeyPath);
  202. //
  203. // Cache
  204. //
  205. void CacheInit(METADATA_HANDLE i_hKey);
  206. void CacheFree();
  207. //
  208. // Get Data from metabase and convert to WMI-friendly format
  209. //
  210. void Get(
  211. METADATA_HANDLE i_hKey,
  212. METABASE_PROPERTY* i_pmbp,
  213. CWbemServices* i_pNamespace,
  214. _variant_t& io_vt,
  215. BOOL* io_pbIsInherited,
  216. BOOL* io_pbIsDefault);
  217. void GetDword(
  218. METADATA_HANDLE i_hKey,
  219. METABASE_PROPERTY* i_pmbp,
  220. _variant_t& io_vt,
  221. BOOL* io_pbIsInherited,
  222. BOOL* io_pbIsDefault);
  223. void GetString(
  224. METADATA_HANDLE i_hKey,
  225. METABASE_PROPERTY* i_pmbp,
  226. _variant_t& io_vt,
  227. BOOL* io_pbIsInherited,
  228. BOOL* io_pbIsDefault);
  229. void GetMultiSz(
  230. METADATA_HANDLE i_hKey,
  231. METABASE_PROPERTY* i_pmbp,
  232. CWbemServices* i_pNamespace,
  233. _variant_t& io_vt,
  234. BOOL* io_pbIsInherited,
  235. BOOL* io_pbIsDefault);
  236. void GetBinary(
  237. METADATA_HANDLE i_hKey,
  238. METABASE_PROPERTY* i_pmbp,
  239. _variant_t& io_vt,
  240. BOOL* io_pbIsInherited,
  241. BOOL* io_pbIsDefault);
  242. //
  243. // Put data to metabase (converting from WMI-friendly format in the process)
  244. //
  245. void Put(
  246. METADATA_HANDLE i_hKey,
  247. METABASE_PROPERTY* i_pmbp,
  248. CWbemServices* i_pNamespace,
  249. _variant_t& i_vt,
  250. _variant_t* i_pvtOld, // can be NULL
  251. DWORD i_dwQuals=0,
  252. BOOL i_bDoDiff=false);
  253. void PutDword(
  254. METADATA_HANDLE i_hKey,
  255. METABASE_PROPERTY* i_pmbp,
  256. _variant_t& i_vt,
  257. _variant_t* i_pvtOld, // can be NULL
  258. DWORD i_dwQuals=0,
  259. BOOL i_bDoDiff=false);
  260. void PutString(
  261. METADATA_HANDLE i_hKey,
  262. METABASE_PROPERTY* i_pmbp,
  263. _variant_t& i_vt,
  264. _variant_t* i_pvtOld, // can be NULL
  265. DWORD i_dwQuals=0,
  266. BOOL i_bDoDiff=false);
  267. void PutMultiSz(
  268. METADATA_HANDLE i_hKey,
  269. METABASE_PROPERTY* i_pmbp,
  270. CWbemServices* i_pNamespace,
  271. _variant_t& i_vt,
  272. _variant_t* i_pvtOld, // can be NULL
  273. DWORD i_dwQuals=0,
  274. BOOL i_bDoDiff=false);
  275. void PutBinary(
  276. METADATA_HANDLE i_hKey,
  277. METABASE_PROPERTY* i_pmbp,
  278. _variant_t& i_vt,
  279. _variant_t* i_pvtOld, // can be NULL
  280. DWORD i_dwQuals=0,
  281. BOOL i_bDoDiff=false);
  282. void PutMethod(
  283. LPWSTR i_wszPath,
  284. DWORD i_id);
  285. //
  286. // Delete from metabase
  287. //
  288. void DeleteData(
  289. METADATA_HANDLE i_hKey,
  290. DWORD i_dwMDIdentifier,
  291. DWORD i_dwMDDataType);
  292. void DeleteData(
  293. METADATA_HANDLE i_hKey,
  294. METABASE_PROPERTY* i_pmbp,
  295. bool i_bThrowOnRO);
  296. HRESULT EnumKeys(
  297. METADATA_HANDLE i_hKey,
  298. LPCWSTR i_wszMDPath,
  299. LPWSTR io_wszMDName,
  300. DWORD* io_pdwMDEnumKeyIndex,
  301. METABASE_KEYTYPE*& io_pktKeyTypeSearch,
  302. bool i_bLookForMatchAtCurrentLevelOnly=false);
  303. HRESULT WebAppCheck(METADATA_HANDLE);
  304. HRESULT WebAppGetStatus(METADATA_HANDLE, PDWORD);
  305. HRESULT WebAppSetStatus(METADATA_HANDLE, DWORD);
  306. };
  307. //
  308. // Handles the Server.{Start,Stop,Pause,Continue} methods
  309. //
  310. class CServerMethod
  311. {
  312. private:
  313. LPWSTR m_wszPath; // full metabase path of loc where we will execute method
  314. IMSAdminBase* m_pIABase;
  315. HRESULT IISGetServerState(
  316. METADATA_HANDLE hObjHandle,
  317. LPDWORD pdwState);
  318. HRESULT IISGetServerWin32Error(
  319. METADATA_HANDLE hObjHandle,
  320. HRESULT* phrError);
  321. HRESULT IISSetDword(
  322. METADATA_HANDLE hKey,
  323. DWORD dwPropId,
  324. DWORD dwValue);
  325. public:
  326. CServerMethod()
  327. {
  328. m_wszPath = 0;
  329. }
  330. HRESULT Initialize(IMSAdminBase* i_pIABase, LPWSTR i_wszPath)
  331. {
  332. m_pIABase = i_pIABase;
  333. m_wszPath = new WCHAR[wcslen(i_wszPath)+1];
  334. if(m_wszPath == NULL)
  335. {
  336. return E_OUTOFMEMORY;
  337. }
  338. wcscpy(m_wszPath, i_wszPath);
  339. return S_OK;
  340. }
  341. ~CServerMethod()
  342. {
  343. delete [] m_wszPath;
  344. }
  345. HRESULT ExecMethod(DWORD dwControl);
  346. };
  347. #endif