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.

341 lines
15 KiB

  1. //***************************************************************************
  2. //
  3. // MSIProv.h
  4. //
  5. // Module: WBEM MSI instance provider code.
  6. //
  7. // Copyright (c) 1997-2001 Microsoft Corporation, All Rights Reserved
  8. //
  9. //***************************************************************************
  10. #ifndef _MSIProv_H_
  11. #define _MSIProv_H_
  12. #define _WIN32_DCOM
  13. #include <wbemidl.h>
  14. #include <ProvExce.h>
  15. #include <msi.h>
  16. #include <msiQuery.h>
  17. #include <objbase.h>
  18. //#include "msimeth.h"
  19. #define BUFF_SIZE 512
  20. #define QUERY_SIZE 128
  21. #define MSI_PACKAGE_LIST_SIZE 100
  22. #define MSI_MAX_APPLICATIONS 1500
  23. #define MSI_KEY_LIST_SIZE 10
  24. typedef enum tagACTIONTYPE
  25. {
  26. ACTIONTYPE_ENUM = 0,
  27. ACTIONTYPE_GET = 1,
  28. ACTIONTYPE_QUERY = 2
  29. } ACTIONTYPE;
  30. // The provider string is always in WCHAR format
  31. #define DELIMETER L'|'
  32. typedef LPVOID * PPVOID;
  33. // Provider interfaces are provided by objects of this class
  34. extern bool UnloadMsiDll();
  35. class CMSIProv : public IWbemServices, public IWbemProviderInit
  36. {
  37. protected:
  38. ULONG m_cRef; //Object reference count
  39. public:
  40. IWbemServices *m_pNamespace;
  41. CMSIProv(BSTR ObjectPath = NULL, BSTR User = NULL, BSTR Password = NULL, IWbemContext * pCtx=NULL);
  42. ~CMSIProv(void);
  43. //Non-delegating object IUnknown
  44. STDMETHODIMP QueryInterface(REFIID, PPVOID);
  45. STDMETHODIMP_(ULONG) AddRef(void);
  46. STDMETHODIMP_(ULONG) Release(void);
  47. //IWbemProviderInit
  48. HRESULT STDMETHODCALLTYPE Initialize(
  49. /* [in] */ LPWSTR pszUser,
  50. /* [in] */ LONG lFlags,
  51. /* [in] */ LPWSTR pszNamespace,
  52. /* [in] */ LPWSTR pszLocale,
  53. /* [in] */ IWbemServices *pNamespace,
  54. /* [in] */ IWbemContext *pCtx,
  55. /* [in] */ IWbemProviderInitSink *pInitSink);
  56. //IWbemServices
  57. HRESULT STDMETHODCALLTYPE OpenNamespace(
  58. /* [in] */ const BSTR strNamespace,
  59. /* [in] */ long lFlags,
  60. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  61. /* [unique][in][out] */ IWbemServices __RPC_FAR *__RPC_FAR *ppWorkingNamespace,
  62. /* [unique][in][out] */ IWbemCallResult __RPC_FAR *__RPC_FAR *ppResult) {return WBEM_E_NOT_SUPPORTED;};
  63. HRESULT STDMETHODCALLTYPE CancelAsyncCall(
  64. /* [in] */ IWbemObjectSink __RPC_FAR *pSink) {return WBEM_E_NOT_SUPPORTED;};
  65. HRESULT STDMETHODCALLTYPE QueryObjectSink(
  66. /* [in] */ long lFlags,
  67. /* [out] */ IWbemObjectSink __RPC_FAR *__RPC_FAR *ppResponseHandler) {return WBEM_E_NOT_SUPPORTED;};
  68. HRESULT STDMETHODCALLTYPE GetObject(
  69. /* [in] */ const BSTR ObjectPath,
  70. /* [in] */ long lFlags,
  71. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  72. /* [unique][in][out] */ IWbemClassObject __RPC_FAR *__RPC_FAR *ppObject,
  73. /* [unique][in][out] */ IWbemCallResult __RPC_FAR *__RPC_FAR *ppCallResult) {return WBEM_E_NOT_SUPPORTED;};
  74. HRESULT STDMETHODCALLTYPE GetObjectAsync(
  75. /* [in] */ const BSTR ObjectPath,
  76. /* [in] */ long lFlags,
  77. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  78. /* [in] */ IWbemObjectSink __RPC_FAR *pResponseHandler);
  79. HRESULT STDMETHODCALLTYPE PutClass(
  80. /* [in] */ IWbemClassObject __RPC_FAR *pObject,
  81. /* [in] */ long lFlags,
  82. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  83. /* [unique][in][out] */ IWbemCallResult __RPC_FAR *__RPC_FAR *ppCallResult) {return WBEM_E_NOT_SUPPORTED;};
  84. HRESULT STDMETHODCALLTYPE PutClassAsync(
  85. /* [in] */ IWbemClassObject __RPC_FAR *pObject,
  86. /* [in] */ long lFlags,
  87. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  88. /* [in] */ IWbemObjectSink __RPC_FAR *pResponseHandler) {return WBEM_E_NOT_SUPPORTED;};
  89. HRESULT STDMETHODCALLTYPE DeleteClass(
  90. /* [in] */ const BSTR Class,
  91. /* [in] */ long lFlags,
  92. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  93. /* [unique][in][out] */ IWbemCallResult __RPC_FAR *__RPC_FAR *ppCallResult) {return WBEM_E_NOT_SUPPORTED;};
  94. HRESULT STDMETHODCALLTYPE DeleteClassAsync(
  95. /* [in] */ const BSTR Class,
  96. /* [in] */ long lFlags,
  97. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  98. /* [in] */ IWbemObjectSink __RPC_FAR *pResponseHandler) {return WBEM_E_NOT_SUPPORTED;};
  99. HRESULT STDMETHODCALLTYPE CreateClassEnum(
  100. /* [in] */ const BSTR Superclass,
  101. /* [in] */ long lFlags,
  102. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  103. /* [out] */ IEnumWbemClassObject __RPC_FAR *__RPC_FAR *ppEnum) {return WBEM_E_NOT_SUPPORTED;};
  104. HRESULT STDMETHODCALLTYPE CreateClassEnumAsync(
  105. /* [in] */ const BSTR Superclass,
  106. /* [in] */ long lFlags,
  107. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  108. /* [in] */ IWbemObjectSink __RPC_FAR *pResponseHandler) {return WBEM_E_NOT_SUPPORTED;};
  109. HRESULT STDMETHODCALLTYPE PutInstance(
  110. /* [in] */ IWbemClassObject __RPC_FAR *pInst,
  111. /* [in] */ long lFlags,
  112. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  113. /* [unique][in][out] */ IWbemCallResult __RPC_FAR *__RPC_FAR *ppCallResult) {return WBEM_E_NOT_SUPPORTED;};
  114. HRESULT STDMETHODCALLTYPE PutInstanceAsync(
  115. /* [in] */ IWbemClassObject __RPC_FAR *pInst,
  116. /* [in] */ long lFlags,
  117. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  118. /* [in] */ IWbemObjectSink __RPC_FAR *pResponseHandler);
  119. HRESULT STDMETHODCALLTYPE DeleteInstance(
  120. /* [in] */ const BSTR ObjectPath,
  121. /* [in] */ long lFlags,
  122. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  123. /* [unique][in][out] */ IWbemCallResult __RPC_FAR *__RPC_FAR *ppCallResult) {return WBEM_E_NOT_SUPPORTED;};
  124. HRESULT STDMETHODCALLTYPE DeleteInstanceAsync(
  125. /* [in] */ const BSTR ObjectPath,
  126. /* [in] */ long lFlags,
  127. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  128. /* [in] */ IWbemObjectSink __RPC_FAR *pResponseHandler);
  129. HRESULT STDMETHODCALLTYPE CreateInstanceEnum(
  130. /* [in] */ const BSTR Class,
  131. /* [in] */ long lFlags,
  132. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  133. /* [out] */ IEnumWbemClassObject __RPC_FAR *__RPC_FAR *ppEnum) {return WBEM_E_NOT_SUPPORTED;};
  134. HRESULT STDMETHODCALLTYPE CreateInstanceEnumAsync(
  135. /* [in] */ const BSTR Class,
  136. /* [in] */ long lFlags,
  137. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  138. /* [in] */ IWbemObjectSink __RPC_FAR *pResponseHandler);
  139. HRESULT STDMETHODCALLTYPE ExecQuery(
  140. /* [in] */ const BSTR QueryLanguage,
  141. /* [in] */ const BSTR Query,
  142. /* [in] */ long lFlags,
  143. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  144. /* [out] */ IEnumWbemClassObject __RPC_FAR *__RPC_FAR *ppEnum) {return WBEM_E_NOT_SUPPORTED;};
  145. HRESULT STDMETHODCALLTYPE ExecQueryAsync(
  146. /* [in] */ const BSTR QueryLanguage,
  147. /* [in] */ const BSTR Query,
  148. /* [in] */ long lFlags,
  149. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  150. /* [in] */ IWbemObjectSink __RPC_FAR *pResponseHandler);
  151. HRESULT STDMETHODCALLTYPE ExecNotificationQuery(
  152. /* [in] */ const BSTR QueryLanguage,
  153. /* [in] */ const BSTR Query,
  154. /* [in] */ long lFlags,
  155. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  156. /* [out] */ IEnumWbemClassObject __RPC_FAR *__RPC_FAR *ppEnum) {return WBEM_E_NOT_SUPPORTED;};
  157. HRESULT STDMETHODCALLTYPE ExecNotificationQueryAsync(
  158. /* [in] */ const BSTR QueryLanguage,
  159. /* [in] */ const BSTR Query,
  160. /* [in] */ long lFlags,
  161. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  162. /* [in] */ IWbemObjectSink __RPC_FAR *pResponseHandler) {return WBEM_E_NOT_SUPPORTED;};
  163. HRESULT STDMETHODCALLTYPE ExecMethod( const BSTR, const BSTR, long, IWbemContext*,
  164. IWbemClassObject*, IWbemClassObject**, IWbemCallResult**) {return WBEM_E_NOT_SUPPORTED;}
  165. HRESULT STDMETHODCALLTYPE ExecMethodAsync(const BSTR ObjectPath, const BSTR Method,
  166. long lFlags,
  167. IWbemContext *pCtx,
  168. IWbemClassObject *pInParams,
  169. IWbemObjectSink *pResponse);
  170. private:
  171. bool CheckForMsiDll();
  172. static CHeap_Exception m_he;
  173. };
  174. typedef CMSIProv *PCMSIProv;
  175. // Some utility functions
  176. char * WcharToTchar(WCHAR * wcPtr, char *wcTmp);
  177. WCHAR * TcharToWchar(char * tcPtr, WCHAR *wcTmp);
  178. WCHAR * TcharToWchar(const char * tcPtr, WCHAR *wcTmp);
  179. HRESULT ConvertError(UINT uiStatus);
  180. WCHAR * EscapeStringW(WCHAR * wcIn, WCHAR * wcOut);
  181. bool SafeLeaveCriticalSection(CRITICAL_SECTION *pcs);
  182. void SoftwareElementState(INSTALLSTATE piInstalled, int *iState);
  183. bool CreateProductString(WCHAR *cProductCode, WCHAR *cProductPath);
  184. DWORD CreateSoftwareElementString ( MSIHANDLE hDatabase,
  185. WCHAR *wcComponent,
  186. WCHAR *wcProductCode,
  187. WCHAR *wcPath,
  188. DWORD * dwPath
  189. );
  190. bool CreateSoftwareFeatureString(WCHAR *wcName, WCHAR *wcProductCode, WCHAR * wcString, bool bValidate);
  191. int GetOS();
  192. bool IsNT4();
  193. bool IsNT5();
  194. BOOL IsLessThan4();
  195. bool AreWeOnNT();
  196. HRESULT CheckImpersonationLevel();
  197. bool ValidateComponentID(WCHAR *wcID, WCHAR *wcProductCode);
  198. bool ValidateComponentName(MSIHANDLE hDatabase, WCHAR *wcProductCode, WCHAR *wcName);
  199. bool ValidateFeatureName(WCHAR *wcName, WCHAR *wcProduct);
  200. // These variables keep track of when the module can be unloaded
  201. extern long g_cObj;
  202. extern long g_cLock;
  203. // These variables keep track of acces to the MSI databases
  204. extern CRITICAL_SECTION g_msi_prov_cs;
  205. extern WCHAR *g_wcpLoggingDir;
  206. //These are the valiables used to track MSI.dll and it's exported functions
  207. typedef UINT (CALLBACK* LPFNMSIVIEWFETCH)(MSIHANDLE, MSIHANDLE*);
  208. typedef UINT (CALLBACK* LPFNMSIRECORDGETSTRINGW)(MSIHANDLE, unsigned int, LPWSTR, DWORD*);
  209. typedef UINT (CALLBACK* LPFNMSICLOSEHANDLE)(MSIHANDLE);
  210. typedef UINT (CALLBACK* LPFNMSIDATABASEOPENVIEWW)(MSIHANDLE, LPCWSTR, MSIHANDLE*);
  211. typedef UINT (CALLBACK* LPFNMSIVIEWEXECUTE)(MSIHANDLE, MSIHANDLE);
  212. typedef UINT (CALLBACK* LPFNMSIGETACTIVEDATABASE)(MSIHANDLE);
  213. typedef INSTALLSTATE (CALLBACK* LPFNMSIGETCOMPONENTPATHW)(LPCWSTR, LPCWSTR, LPWSTR, DWORD*);
  214. typedef UINT (CALLBACK* LPFNMSIGETCOMPONENTSTATEW)(MSIHANDLE, LPCWSTR, INSTALLSTATE*, INSTALLSTATE*);
  215. typedef UINT (CALLBACK* LPFNMSIOPENPRODUCTW)(LPCWSTR, MSIHANDLE*);
  216. typedef UINT (CALLBACK* LPFNMSIOPENPACKAGEW)(LPCWSTR, MSIHANDLE*);
  217. typedef UINT (CALLBACK* LPFNMSIDATABASEISTABLEPERSITENTW)(MSIHANDLE, LPCWSTR);
  218. typedef INSTALLUILEVEL (CALLBACK* LPFNMSISETINTERNALUI)(INSTALLUILEVEL, HWND);
  219. typedef INSTALLUI_HANDLER (CALLBACK* LPFNMSISETEXTERNALUIW)(INSTALLUI_HANDLER, DWORD, LPVOID);
  220. typedef UINT (CALLBACK* LPFNMSIENABLELOGW)(DWORD, LPCWSTR, DWORD);
  221. typedef UINT (CALLBACK* LPFNMSIGETPRODUCTPROPERTYW)(MSIHANDLE, LPCWSTR, LPWSTR, DWORD*);
  222. typedef INSTALLSTATE (CALLBACK* LPFNMSIQUERYPRODUCTSTATEW)(LPCWSTR);
  223. typedef UINT (CALLBACK* LPFNMSIINSTALLPRODUCTW)(LPCWSTR, LPCWSTR);
  224. typedef UINT (CALLBACK* LPFNMSICONFIGUREPRODUCTW)(LPCWSTR, int, INSTALLSTATE);
  225. typedef UINT (CALLBACK* LPFNMSIREINSTALLPRODUCTW)(LPCWSTR, DWORD);
  226. typedef UINT (CALLBACK* LPFNMSIAPPLYPATCHW)(LPCWSTR, LPCWSTR, INSTALLTYPE, LPCWSTR);
  227. typedef int (CALLBACK* LPFNMSIRECORDGETINTEGER)(MSIHANDLE, unsigned int);
  228. typedef UINT (CALLBACK* LPFNMSIENUMFEATURESW)(LPCWSTR, DWORD, LPWSTR, LPWSTR);
  229. typedef UINT (CALLBACK* LPFNMSIGETPRODUCTINFOW)(LPCWSTR, LPCWSTR, LPWSTR, DWORD*);
  230. typedef INSTALLSTATE (CALLBACK* LPFNMSIQUERYFEATURESTATEW)(LPCWSTR, LPCWSTR);
  231. typedef UINT (CALLBACK* LPFNMSIGETFEATUREUSAGEW)(LPCWSTR, LPCWSTR, DWORD*, WORD*);
  232. typedef UINT (CALLBACK* LPFNMSIGETFEATUREINFOW)(MSIHANDLE, LPCWSTR, DWORD*, LPWSTR, DWORD*, LPWSTR, DWORD*);
  233. typedef UINT (CALLBACK* LPFNMSICONFIGUREFEATUREW)(LPCWSTR, LPCWSTR, INSTALLSTATE);
  234. typedef UINT (CALLBACK* LPFNMSIREINSTALLFEATUREW)(LPCWSTR, LPCWSTR, DWORD);
  235. typedef UINT (CALLBACK* LPFNMSIENUMPRODUCTSW)(DWORD, LPWSTR);
  236. typedef UINT (CALLBACK* LPFNMSIGETDATABASESTATE)(MSIHANDLE);
  237. typedef UINT (CALLBACK* LPFNMSIRECORDSETSTRINGW)(MSIHANDLE, unsigned int, LPCWSTR);
  238. typedef UINT (CALLBACK* LPFNMSIDATABASECOMMIT)(MSIHANDLE);
  239. typedef UINT (CALLBACK* LPFNMSIENUMCOMPONENTSW)(DWORD, LPWSTR);
  240. typedef UINT (CALLBACK* LPFNMSIVIEWCLOSE)(MSIHANDLE);
  241. extern bool g_bMsiPresent;
  242. extern bool g_bMsiLoaded;
  243. extern LPFNMSIVIEWFETCH g_fpMsiViewFetch;
  244. extern LPFNMSIRECORDGETSTRINGW g_fpMsiRecordGetStringW;
  245. extern LPFNMSICLOSEHANDLE g_fpMsiCloseHandle;
  246. extern LPFNMSIDATABASEOPENVIEWW g_fpMsiDatabaseOpenViewW;
  247. extern LPFNMSIVIEWEXECUTE g_fpMsiViewExecute;
  248. extern LPFNMSIGETACTIVEDATABASE g_fpMsiGetActiveDatabase;
  249. extern LPFNMSIGETCOMPONENTPATHW g_fpMsiGetComponentPathW;
  250. extern LPFNMSIGETCOMPONENTSTATEW g_fpMsiGetComponentStateW;
  251. extern LPFNMSIOPENPRODUCTW g_fpMsiOpenProductW;
  252. extern LPFNMSIOPENPACKAGEW g_fpMsiOpenPackageW;
  253. extern LPFNMSIDATABASEISTABLEPERSITENTW g_fpMsiDatabaseIsTablePersistentW;
  254. extern LPFNMSISETINTERNALUI g_fpMsiSetInternalUI;
  255. extern LPFNMSISETEXTERNALUIW g_fpMsiSetExternalUIW;
  256. extern LPFNMSIENABLELOGW g_fpMsiEnableLogW;
  257. extern LPFNMSIGETPRODUCTPROPERTYW g_fpMsiGetProductPropertyW;
  258. extern LPFNMSIQUERYPRODUCTSTATEW g_fpMsiQueryProductStateW;
  259. extern LPFNMSIINSTALLPRODUCTW g_fpMsiInstallProductW;
  260. extern LPFNMSICONFIGUREPRODUCTW g_fpMsiConfigureProductW;
  261. extern LPFNMSIREINSTALLPRODUCTW g_fpMsiReinstallProductW;
  262. extern LPFNMSIAPPLYPATCHW g_fpMsiApplyPatchW;
  263. extern LPFNMSIRECORDGETINTEGER g_fpMsiRecordGetInteger;
  264. extern LPFNMSIENUMFEATURESW g_fpMsiEnumFeaturesW;
  265. extern LPFNMSIGETPRODUCTINFOW g_fpMsiGetProductInfoW;
  266. extern LPFNMSIQUERYFEATURESTATEW g_fpMsiQueryFeatureStateW;
  267. extern LPFNMSIGETFEATUREUSAGEW g_fpMsiGetFeatureUsageW;
  268. extern LPFNMSIGETFEATUREINFOW g_fpMsiGetFeatureInfoW;
  269. extern LPFNMSICONFIGUREFEATUREW g_fpMsiConfigureFeatureW;
  270. extern LPFNMSIREINSTALLFEATUREW g_fpMsiReinstallFeatureW;
  271. extern LPFNMSIENUMPRODUCTSW g_fpMsiEnumProductsW;
  272. extern LPFNMSIGETDATABASESTATE g_fpMsiGetDatabaseState;
  273. extern LPFNMSIRECORDSETSTRINGW g_fpMsiRecordSetStringW;
  274. extern LPFNMSIDATABASECOMMIT g_fpMsiDatabaseCommit;
  275. extern LPFNMSIENUMCOMPONENTSW g_fpMsiEnumComponentsW;
  276. extern LPFNMSIVIEWCLOSE g_fpMsiViewClose;
  277. #endif