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.

543 lines
24 KiB

  1. /*++
  2. Copyright (c) 1999 Microsoft Corporation
  3. Abstract:
  4. @doc
  5. @module ComAdmin.hxx | Wrappers around COM admin interfaces
  6. @end
  7. Author:
  8. Adi Oltean [aoltean] 08/15/1999
  9. Remarks:
  10. Non-thread safe.
  11. Revision History:
  12. Name Date Comments
  13. aoltean 08/15/1999 Created
  14. --*/
  15. #ifndef __VSS_COM_ADMIN_HXX__
  16. #define __VSS_COM_ADMIN_HXX__
  17. #if _MSC_VER > 1000
  18. #pragma once
  19. #endif
  20. ////////////////////////////////////////////////////////////////////////
  21. // Standard foo for file name aliasing. This code block must be after
  22. // all includes of VSS header files.
  23. //
  24. #ifdef VSS_FILE_ALIAS
  25. #undef VSS_FILE_ALIAS
  26. #endif
  27. #define VSS_FILE_ALIAS "INCCADMH"
  28. //
  29. ////////////////////////////////////////////////////////////////////////
  30. /////////////////////////////////////////////////////////////////////////////
  31. // Constants
  32. // Collection types
  33. typedef enum
  34. {
  35. VSS_COM_UNKNOWN = 0,
  36. VSS_COM_APPLICATION_CLUSTER,
  37. VSS_COM_APPLICATIONS,
  38. VSS_COM_COMPONENTS,
  39. VSS_COM_COMPUTERLIST,
  40. VSS_COM_DCOM_PROTOCOLS,
  41. VSS_COM_ERRORINFO,
  42. VSS_COM_IMDB_DATA_SOURCES,
  43. VSS_COM_IMDB_DATA_SOURCE_TABLES,
  44. VSS_COM_INPROC_SERVERS,
  45. VSS_COM_INTERFACES_FOR_COMPONENT,
  46. VSS_COM_LOCAL_COMPUTER,
  47. VSS_COM_METHODS_FOR_INTERFACE,
  48. VSS_COM_PROPERTY_INFO,
  49. VSS_COM_PUBLISHER_PROPERTIES,
  50. VSS_COM_RELATED_COLLECTION_INFO,
  51. VSS_COM_ROLES,
  52. VSS_COM_ROLES_FOR_COMPONENT,
  53. VSS_COM_ROLES_FOR_INTERFACE,
  54. VSS_COM_ROLES_FOR_METHOD,
  55. VSS_COM_ROOT,
  56. VSS_COM_SUBSCRIBER_PROPERTIES,
  57. VSS_COM_SUBSCRIPTIONS,
  58. VSS_COM_TRANSIENT_SUBSCRIPTIONS,
  59. VSS_COM_USERS_IN_ROLE,
  60. VSS_COM_COLLECTIONS_COUNT,
  61. } VSS_COM_COLLECTION_TYPE, *PVSS_COM_COLLECTION_TYPE;
  62. // collection attributes
  63. extern "C" struct _VsCOMCollectionAttr
  64. {
  65. const WCHAR* wszName;
  66. const WCHAR* wszMainKey;
  67. const WCHAR* wszDefaultKey;
  68. } g_VsCOMCollectionsArray[];
  69. /////////////////////////////////////////////////////////////////////////////
  70. // Macros for defining object properties in COM Administration interfaces
  71. //
  72. //
  73. // Macros for defining object properties of string type
  74. //
  75. // Example:
  76. // VSS_BSTR_PUT_PROP(Name)
  77. // will be expanded into a property identified by string L"Name"
  78. // and member m_bstrName
  79. //
  80. #define VSS_BSTR_PUT_PROP(FieldName) \
  81. void Put##FieldName(BSTR bstrValue) \
  82. throw(HRESULT) \
  83. { \
  84. /* Copy the given string into a new variant */ \
  85. CComVariant variant(bstrValue); \
  86. if (variant.vt == VT_ERROR) \
  87. throw(E_OUTOFMEMORY); \
  88. \
  89. /* Call put_Value with the new string */ \
  90. HRESULT hr = m_pIObject->put_Value(L#FieldName, variant); \
  91. if (FAILED(hr)) \
  92. throw(hr); \
  93. }
  94. #define VSS_BSTR_GET_PROP(FieldName) \
  95. BSTR Get##FieldName() \
  96. throw(HRESULT) \
  97. { \
  98. CComVariant variant; \
  99. /* Beware to not leave variant resources before get_Value call! */ \
  100. HRESULT hr = m_pIObject->get_Value(L#FieldName, &variant); \
  101. if (FAILED(hr)) \
  102. throw(hr); \
  103. \
  104. if (variant.vt != VT_BSTR) \
  105. throw(E_FAIL); \
  106. \
  107. CComBSTR bstr = variant.bstrVal; \
  108. return bstr.Detach(); \
  109. }
  110. // Read-write or write-once property
  111. #define VSS_BSTR_RW_PROP(FieldName) \
  112. _declspec(property(get=Get##FieldName, put=Put##FieldName)) \
  113. BSTR m_bstr##FieldName; \
  114. VSS_BSTR_GET_PROP(FieldName) \
  115. VSS_BSTR_PUT_PROP(FieldName)
  116. // Read-only property
  117. #define VSS_BSTR_RO_PROP(FieldName) \
  118. _declspec(property(get=Get##FieldName)) \
  119. BSTR m_bstr##FieldName; \
  120. VSS_BSTR_GET_PROP(FieldName)
  121. // Write-only property (not Write-once)
  122. #define VSS_BSTR_WO_PROP(FieldName) \
  123. _declspec(property(put=Put##FieldName)) \
  124. BSTR m_bstr##FieldName; \
  125. VSS_BSTR_PUT_PROP(FieldName)
  126. //
  127. // Macros for defining object properties of bool type
  128. //
  129. // Example:
  130. // VSS_BOOL_PUT_PROP(EventsEnabled)
  131. // will be expanded into a property identified by string L"EventsEnabled"
  132. // and member m_bEventsEnabled
  133. //
  134. #define VSS_BOOL_PUT_PROP(FieldName) \
  135. void Put##FieldName(bool bValue) \
  136. throw(HRESULT) \
  137. { \
  138. /* Copy the given bool into a new variant */ \
  139. CComVariant variant(bValue); \
  140. \
  141. /* Call put_Value with the new string */ \
  142. HRESULT hr = m_pIObject->put_Value(L#FieldName, variant); \
  143. if (FAILED(hr)) \
  144. throw(hr); \
  145. }
  146. #define VSS_BOOL_GET_PROP(FieldName) \
  147. bool Get##FieldName() \
  148. throw(HRESULT) \
  149. { \
  150. CComVariant variant; \
  151. /* Beware to not leave variant resources before get_Value call! */ \
  152. HRESULT hr = m_pIObject->get_Value(L#FieldName, &variant); \
  153. if (FAILED(hr)) \
  154. throw(hr); \
  155. \
  156. if (variant.vt != VT_BOOL) \
  157. throw(E_FAIL); \
  158. \
  159. return (variant.boolVal == VARIANT_TRUE); \
  160. }
  161. // Read-write or write-once property
  162. #define VSS_BOOL_RW_PROP(FieldName) \
  163. _declspec(property(get=Get##FieldName, put=Put##FieldName)) \
  164. bool m_b##FieldName; \
  165. VSS_BOOL_GET_PROP(FieldName) \
  166. VSS_BOOL_PUT_PROP(FieldName)
  167. // Read-only property
  168. #define VSS_BOOL_RO_PROP(FieldName) \
  169. _declspec(property(get=Get##FieldName)) \
  170. bool m_b##FieldName; \
  171. VSS_BOOL_GET_PROP(FieldName)
  172. // Write-only property (not Write-once)
  173. #define VSS_BOOL_WO_PROP(FieldName) \
  174. _declspec(property(put=Put##FieldName)) \
  175. bool m_b##FieldName; \
  176. VSS_BOOL_PUT_PROP(FieldName)
  177. //
  178. // Macros for defining object properties of LONG type.
  179. //
  180. // Example:
  181. // VSS_LONG_PUT_PROP(ShutdownAfter)
  182. // will be expanded into a property identified by string L"ShutdownAfter"
  183. // and member m_lShutdownAfter
  184. //
  185. #define VSS_LONG_PUT_PROP(FieldName) \
  186. void Put##FieldName(LONG lValue) \
  187. throw(HRESULT) \
  188. { \
  189. /* Copy the given LONG into a new variant */ \
  190. CComVariant variant(lValue); \
  191. \
  192. /* Call put_Value with the new string */ \
  193. HRESULT hr = m_pIObject->put_Value(L#FieldName, variant); \
  194. if (FAILED(hr)) \
  195. throw(hr); \
  196. }
  197. #define VSS_LONG_GET_PROP(FieldName) \
  198. LONG Get##FieldName() \
  199. throw(HRESULT) \
  200. { \
  201. CComVariant variant; \
  202. /* Beware to not leave variant resources before get_Value call! */ \
  203. HRESULT hr = m_pIObject->get_Value(L#FieldName, &variant); \
  204. if (FAILED(hr)) \
  205. throw(hr); \
  206. \
  207. if (variant.vt != VT_I4) \
  208. throw(E_FAIL); \
  209. \
  210. return variant.lVal; \
  211. }
  212. // Read-write or write-once property
  213. #define VSS_LONG_RW_PROP(FieldName) \
  214. _declspec(property(get=Get##FieldName, put=Put##FieldName)) \
  215. LONG m_l##FieldName; \
  216. VSS_LONG_GET_PROP(FieldName) \
  217. VSS_LONG_PUT_PROP(FieldName)
  218. // Read-only property
  219. #define VSS_LONG_RO_PROP(FieldName) \
  220. _declspec(property(get=Get##FieldName)) \
  221. LONG m_l##FieldName; \
  222. VSS_LONG_GET_PROP(FieldName)
  223. // Write-only property (not Write-once)
  224. #define VSS_LONG_WO_PROP(FieldName) \
  225. _declspec(property(put=Put##FieldName)) \
  226. LONG m_l##FieldName; \
  227. VSS_LONG_PUT_PROP(FieldName)
  228. //
  229. // Macros for defining object properties of VARIANT type.
  230. //
  231. // Example:
  232. // VSS_VAR_PUT_PROP(Value)
  233. // will be expanded into a property identified by string L"Value"
  234. // and member m_varValue
  235. //
  236. #define VSS_VAR_PUT_PROP(FieldName) \
  237. void Put##FieldName(CComVariant varValue) \
  238. throw(HRESULT) \
  239. { \
  240. /* Copy the given LONG into a new variant */ \
  241. CComVariant variant(varValue); \
  242. \
  243. /* Call put_Value with the new variant */ \
  244. HRESULT hr = m_pIObject->put_Value(L#FieldName, variant); \
  245. if (FAILED(hr)) \
  246. throw(hr); \
  247. }
  248. #define VSS_VAR_GET_PROP(FieldName) \
  249. CComVariant Get##FieldName() \
  250. throw(HRESULT) \
  251. { \
  252. CComVariant variant; \
  253. /* Beware to not leave variant resources before get_Value call! */ \
  254. HRESULT hr = m_pIObject->get_Value(L#FieldName, &variant); \
  255. if (FAILED(hr)) \
  256. throw(hr); \
  257. \
  258. return variant; \
  259. }
  260. // Read-write or write-once property
  261. #define VSS_VAR_RW_PROP(FieldName) \
  262. _declspec(property(get=Get##FieldName, put=Put##FieldName)) \
  263. CComVariant m_var##FieldName; \
  264. VSS_VAR_GET_PROP(FieldName) \
  265. VSS_VAR_PUT_PROP(FieldName)
  266. // Read-only property
  267. #define VSS_VAR_RO_PROP(FieldName) \
  268. _declspec(property(get=Get##FieldName)) \
  269. CComVariant m_var##FieldName; \
  270. VSS_VAR_GET_PROP(FieldName)
  271. // Write-only property (not Write-once)
  272. #define VSS_VAR_WO_PROP(FieldName) \
  273. _declspec(property(put=Put##FieldName)) \
  274. CComVariant m_var##FieldName; \
  275. VSS_VAR_PUT_PROP(FieldName)
  276. /////////////////////////////////////////////////////////////////////////////
  277. // Forward declarations
  278. class CVssCOMCatalog;
  279. class CVssCOMCatalogCollection;
  280. class CVssCOMCatalogObject;
  281. class CVssCOMApplication;
  282. class CVssCOMComponent;
  283. /////////////////////////////////////////////////////////////////////////////
  284. // CCOMAdminCatalog wrapper class
  285. class CVssCOMAdminCatalog
  286. {
  287. // Constructors& destructors
  288. protected:
  289. CVssCOMAdminCatalog(const CVssCOMAdminCatalog&);
  290. public:
  291. CVssCOMAdminCatalog(): m_bInitialized(false) {};
  292. // Properties
  293. public:
  294. CComPtr<ICOMAdminCatalog2> GetInterface() { return m_pICatalog; };
  295. BSTR GetAppName() { return m_bstrAppName; };
  296. // Operations
  297. public:
  298. HRESULT Attach(
  299. IN const WCHAR* pwszAppName
  300. );
  301. HRESULT InstallComponent(
  302. IN const WCHAR* pwszDllName,
  303. IN const WCHAR* pwszTlbName,
  304. IN const WCHAR* pwszProxyStubName
  305. );
  306. HRESULT CreateServiceForApplication(
  307. IN const WCHAR* pwszServiceName
  308. );
  309. private:
  310. bool m_bInitialized; // Must be tested for TRUE in each method.
  311. CComPtr<ICOMAdminCatalog2> m_pICatalog;
  312. CComBSTR m_bstrAppName;
  313. };
  314. /////////////////////////////////////////////////////////////////////////////
  315. // ICatalogCollection wrapper class for "Applications" collection
  316. class CVssCOMCatalogCollection
  317. {
  318. // Constructors& destructors
  319. protected:
  320. CVssCOMCatalogCollection(const CVssCOMCatalogCollection&);
  321. public:
  322. CVssCOMCatalogCollection(VSS_COM_COLLECTION_TYPE eType):
  323. m_bInitialized(false), m_eType(eType) {};
  324. // Properties
  325. public:
  326. CComPtr<ICatalogCollection> GetInterface() { return m_pICollection; };
  327. LONG GetType() { return m_eType; };
  328. // Operations
  329. public:
  330. HRESULT Attach(
  331. IN CVssCOMAdminCatalog& catalog
  332. );
  333. HRESULT Attach(
  334. IN CVssCOMCatalogObject& parentObject
  335. );
  336. HRESULT SaveChanges();
  337. // Implementation
  338. protected:
  339. bool m_bInitialized;
  340. CComPtr<ICatalogCollection> m_pICollection;
  341. VSS_COM_COLLECTION_TYPE m_eType;
  342. };
  343. /////////////////////////////////////////////////////////////////////////////
  344. // CVssCOMCatalogObject wrapper class for ICatalogObject
  345. class CVssCOMCatalogObject
  346. {
  347. // Constructors& destructors
  348. protected:
  349. CVssCOMCatalogObject(const CVssCOMCatalogObject&);
  350. public:
  351. CVssCOMCatalogObject(VSS_COM_COLLECTION_TYPE eType): m_bInitialized(false), m_eType(eType), m_lIndex(-1) {};
  352. // Properties
  353. public:
  354. CComPtr<ICatalogObject> GetInterface() { return m_pIObject; };
  355. CComPtr<ICatalogCollection> GetParentInterface() { return m_pIParentCollection; };
  356. LONG GetType() { return m_eType; };
  357. LONG GetIndex() { return m_lIndex; };
  358. // Operations
  359. public:
  360. HRESULT InsertInto(
  361. IN CVssCOMCatalogCollection& collection
  362. );
  363. HRESULT AttachByName(
  364. IN CVssCOMCatalogCollection& collection,
  365. IN const WCHAR wszName[],
  366. IN const WCHAR wszPropertyName[] = NULL
  367. );
  368. // Implementation
  369. protected:
  370. VSS_COM_COLLECTION_TYPE m_eType; // Type of the parent collection. Do not modify!
  371. CComPtr<ICatalogCollection> m_pIParentCollection; // The collection where this app resides
  372. CComPtr<ICatalogObject> m_pIObject; // The corresponding catalog object
  373. bool m_bInitialized; // true, iif initialized
  374. LONG m_lIndex; // Index of the object in the collection.
  375. };
  376. /////////////////////////////////////////////////////////////////////////////
  377. // CVssCOMCatalogObject wrapper class for an Applications
  378. class CVssCOMApplication : public CVssCOMCatalogObject
  379. {
  380. // Constructors& destructors
  381. public:
  382. CVssCOMApplication(): CVssCOMCatalogObject(VSS_COM_APPLICATIONS) {};
  383. // Properties
  384. public:
  385. VSS_LONG_RW_PROP(AccessChecksLevel) // m_lAccessChecksLevel
  386. VSS_LONG_RW_PROP(Activation) // m_lActivation
  387. VSS_BOOL_RW_PROP(ApplicationAccessChecksEnabled) // m_bApplicationAccessChecksEnabled
  388. VSS_BOOL_RO_PROP(ApplicationProxy) // m_bApplicationProxy
  389. VSS_BSTR_RW_PROP(ApplicationProxyServerName) // m_bstrApplicationProxyServerName
  390. VSS_LONG_RW_PROP(Authentication) // m_lAuthentication
  391. VSS_LONG_RW_PROP(AuthenticationCapability) // m_lAuthenticationCapability
  392. VSS_BOOL_RW_PROP(Changeable) // m_bChangeable
  393. VSS_BSTR_RW_PROP(CommandLine) // m_bstrCommandLine
  394. VSS_BSTR_RW_PROP(CreatedBy) // m_bstrCreatedBy
  395. VSS_BOOL_RW_PROP(CRMEnabled) // m_bCRMEnabled
  396. VSS_BSTR_RW_PROP(CRMLogFile) // m_bstrCRMLogFile
  397. VSS_BOOL_RW_PROP(Deleteable) // m_bDeleteable
  398. VSS_BSTR_RW_PROP(Description) // m_bstrDescription
  399. VSS_BOOL_RW_PROP(EventsEnabled) // m_bEventsEnabled
  400. VSS_BSTR_RW_PROP(ID) // m_bstrID
  401. VSS_BSTR_RW_PROP(Identity) // m_bstrIdentity
  402. VSS_LONG_RW_PROP(ImpersonationLevel) // m_lImpersonationLevel
  403. VSS_BOOL_RO_PROP(IsSystem) // m_bIsSystem
  404. VSS_BSTR_RW_PROP(Name) // m_bstrName
  405. VSS_BSTR_WO_PROP(Password) // m_bstrPassword
  406. VSS_BOOL_RW_PROP(QueuingEnabled) // m_bQueuingEnabled
  407. VSS_BOOL_RW_PROP(QueueListenerEnabled) // m_bQueueListenerEnabled
  408. VSS_BOOL_RW_PROP(RunForever) // m_bRunForever
  409. VSS_LONG_RW_PROP(ShutdownAfter) // m_lShutdownAfter
  410. VSS_BOOL_RW_PROP(3GigSupportEnabled) // m_b3GigSupportEnabled
  411. };
  412. /////////////////////////////////////////////////////////////////////////////
  413. // CVssCOMCatalogObject wrapper class for an Applications
  414. class CVssCOMComponent : public CVssCOMCatalogObject
  415. {
  416. // Constructors& destructors
  417. public:
  418. CVssCOMComponent(): CVssCOMCatalogObject(VSS_COM_COMPONENTS) {};
  419. // Properties
  420. public:
  421. VSS_BOOL_RW_PROP(AllowInprocSubscribers) // m_bAllowInprocSubscribers
  422. VSS_BSTR_RW_PROP(ApplicationID) // m_bstrApplicationID
  423. VSS_BSTR_RW_PROP(CLSID) // m_bstrCLSID
  424. VSS_BOOL_RW_PROP(ComponentAccessChecksEnabled) // m_bComponentAccessChecksEnabled
  425. VSS_BOOL_RW_PROP(COMTIIntrinsics) // m_bCOMTIIntrinsics
  426. VSS_BOOL_RW_PROP(ConstructionEnabled) // m_bConstructionEnabled
  427. VSS_BSTR_RW_PROP(ConstructorString) // m_bstrConstructorString
  428. VSS_LONG_RW_PROP(CreationTimeout) // m_lCreationTimeout
  429. VSS_BSTR_RW_PROP(Description) // m_bstrDescription
  430. VSS_BSTR_RW_PROP(DLL) // m_bstrDLL
  431. VSS_BOOL_RW_PROP(EventTrackingEnabled) // m_bEventTrackingEnabled
  432. VSS_BSTR_RW_PROP(ExceptionClass) // m_bstrExceptionClass
  433. VSS_BOOL_RW_PROP(FireInParallel) // m_bFireInParallel
  434. VSS_BOOL_RW_PROP(IISIntrinsics) // m_bIISIntrinsics
  435. VSS_BOOL_RW_PROP(IsEventClass) // m_bIsEventClass
  436. VSS_BOOL_RW_PROP(JustInTimeActivation) // m_bJustInTimeActivation
  437. VSS_BOOL_RW_PROP(LoadBalancingSupported) // m_bLoadBalancingSupported
  438. VSS_LONG_RW_PROP(MaxPoolSize) // m_lMaxPoolSize
  439. VSS_LONG_RW_PROP(MinPoolSize) // m_lMinPoolSize
  440. VSS_BSTR_RW_PROP(MultiInterfacePublisherFilterCLSID) // m_bstrMultiInterfacePublisherFilterCLSID
  441. VSS_BOOL_RW_PROP(MustRunInClientContext) // m_bMustRunInClientContext
  442. VSS_BOOL_RW_PROP(ObjectPoolingEnabled) // m_bObjectPoolingEnabled
  443. VSS_BSTR_RW_PROP(ProgID) // m_bstrProgID
  444. VSS_BSTR_RW_PROP(PublisherID) // m_bstrPublisherID
  445. VSS_LONG_RW_PROP(Synchronization) // m_lSynchronization
  446. VSS_LONG_RW_PROP(ThreadingModel) // m_lThreadingModel
  447. VSS_LONG_RW_PROP(Transaction) // m_lTransaction
  448. VSS_LONG_RW_PROP(VersionBuild) // m_lVersionBuild
  449. VSS_LONG_RW_PROP(VersionMajor) // m_lVersionMajor
  450. VSS_LONG_RW_PROP(VersionMinor) // m_lVersionMinor
  451. VSS_LONG_RW_PROP(VersionSubBuild) // m_lVersionSubBuild
  452. };
  453. #endif // __VSS_COM_ADMIN_HXX__