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.

469 lines
17 KiB

  1. // *********************************************************************************
  2. //
  3. // Copyright (c) Microsoft Corporation
  4. //
  5. // Module Name:
  6. //
  7. // DriverQuery.h
  8. //
  9. // Abstract:
  10. //
  11. // This module contains all necessary header files required by DriverQuery.cpp module.
  12. //
  13. //
  14. // Author:
  15. //
  16. // J.S.Vasu 31-Oct-2000
  17. //
  18. // Revision History:
  19. // Created on 31-0ct-2000 by J.S.Vasu
  20. //
  21. // *********************************************************************************
  22. #ifndef _DRIVERQUERY
  23. #define _DRIVERQUERY
  24. #include <wbemidl.h>
  25. #include <comdef.h>
  26. #include <CHSTRING.h>
  27. #include <time.h>
  28. #include <tchar.h>
  29. #include <lm.h>
  30. #include <Oleauto.h>
  31. #include <strsafe.h>
  32. #define ID_HELP_START 1
  33. #define ID_USAGE_START IDS_USAGE_COPYRIGHT1
  34. #define ID_USAGE_END IDS_USAGE_EXAMPLE32
  35. #define ID_USAGE_BEGIN IDS_USAGEBEGIN1
  36. #define ID_USAGE_ENDING IDS_USAGEEND1
  37. #define OI_HELP 0
  38. #define OI_SERVER 1
  39. #define OI_USERNAME 2
  40. #define OI_PASSWORD 3
  41. #define OI_FORMAT 4
  42. #define OI_HEADER 5
  43. #define OI_VERBOSE 6
  44. #define OI_SIGNED 7
  45. #define MAX_OPTIONS 8
  46. // supported options ( do not localize )
  47. #define OPTION_HELP _T( "?" )
  48. #define OPTION_SERVER _T( "s" )
  49. #define OPTION_USERNAME _T( "u" )
  50. #define OPTION_PASSWORD _T( "p" )
  51. #define OPTION_FORMAT _T( "fo")
  52. #define OPTION_HEADER _T( "nh")
  53. #define OPTION_VERBOSE _T( "v" )
  54. #define OPTION_SIGNED _T( "si")
  55. //localized error messages.
  56. #define ERROR_USERNAME_BUT_NOMACHINE GetResString( IDS_ERROR_USERNAME_BUT_NOMACHINE )
  57. #define ERROR_PASSWORD_BUT_NOUSERNAME GetResString( IDS_ERROR_PASSWORD_BUT_NOUSERNAME )
  58. #define ERROR_COM_INTIALIZE GetResString(IDS_ERROR_COM_INTIALIZE)
  59. #define ERROR_SECURITY_INTIALIZE GetResString(IDS_ERROR_COM_SECURITY_INITIALIZE)
  60. #define ERROR_ENUMERATE_INSTANCE GetResString(IDS_ERROR_COM_ENUMERATE_INSTANCE)
  61. #define ERROR_CONNECT GetResString(IDS_ERROR_CONNECT)
  62. #define ERROR_SYNTAX GetResString(IDS_INVALID_SYNTAX)
  63. #define ERROR_RETREIVE_INFO GetResString(IDS_ERROR_RETREIVE_INFO)
  64. #define ERROR_INVALID_CREDENTIALS GetResString(IDS_INVALID_CREDENTIALS)
  65. #define ERROR_INVALID_FORMAT GetResString(IDS_ERROR_INVALID_FORMAT)
  66. #define ERROR_TAG GetResString(IDS_ERROR_TAG)
  67. #define ERROR_GET_VALUE GetResString(IDS_ERROR_GET)
  68. #define WARNING_TAG GetResString(IDS_WARNING_TAG)
  69. #define LIST_FORMAT GetResString(IDS_FORMAT_LIST)
  70. #define TABLE_FORMAT GetResString(IDS_FORMAT_TABLE)
  71. #define CSV_FORMAT GetResString(IDS_FORMAT_CSV)
  72. #define DRIVER_TAG GetResString(IDS_DRIVER_TAG)
  73. #define ERROR_AUTHENTICATION_FAILURE GetResString(IDS_ERROR_AUTHENTICATION_FAILURE)
  74. #define ERROR_LOCAL_CREDENTIALS GetResString(IDS_ERROR_LOCAL_CRED)
  75. #define ERROR_WMI_FAILURE GetResString(IDS_ERROR_WMI_FAILURE)
  76. #define IGNORE_LOCALCREDENTIALS GetResString(IDS_IGNORE_LOCAL_CRED)
  77. #define INPUT_PASSWORD GetResString( IDS_INPUT_PASSWORD )
  78. #define COL_HOSTNAME GetResString(IDS_COL_HOSTNAME)
  79. #define COL_FILENAME GetResString(IDS_COL_FILENAME)
  80. #define COL_SIGNED GetResString(IDS_SIGNED)
  81. #define COL_DISPLAYNAME GetResString(IDS_COL_DISPLAYNAME)
  82. #define COL_DESCRIPTION GetResString(IDS_COL_DESCRIPTION)
  83. #define COL_DRIVERTYPE GetResString(IDS_COL_DRIVERTYPE)
  84. #define COL_STARTMODE GetResString(IDS_COL_STARTMODE)
  85. #define COL_STATE GetResString(IDS_COL_STATE)
  86. #define COL_STATUS GetResString(IDS_COL_STATUS)
  87. #define COL_ACCEPTSTOP GetResString(IDS_COL_ACCEPTSTOP)
  88. #define COL_ACCEPTPAUSE GetResString(IDS_COL_ACCEPTPAUSE)
  89. #define COL_MEMORYUSAGE GetResString(IDS_COL_MEMORYUSAGE)
  90. #define COL_PAGEDPOOL GetResString(IDS_COL_PAGEDPOOL)
  91. #define COL_NONPAGEDPOOL GetResString(IDS_COL_NONPAGEDPOOL)
  92. #define COL_EXECCODE GetResString(IDS_COL_EXECCODE)
  93. #define COL_NBSS GetResString(IDS_COL_NBSS)
  94. #define COL_BSS GetResString(IDS_COL_BSS)
  95. #define COL_LINKDATE GetResString(IDS_COL_LINKDATE)
  96. #define COL_LOCATION GetResString(IDS_COL_LOCATION)
  97. #define COL_LINKDATE GetResString(IDS_COL_LINKDATE)
  98. #define COL_LOCATION GetResString(IDS_COL_LOCATION)
  99. #define COL_INITSIZE GetResString(IDS_COL_INITSIZE)
  100. #define COL_PAGESIZE GetResString(IDS_COL_PAGESIZE)
  101. #define ERROR_ALLOC_FAILURE GetResString(IDS_ALLOC_FAILURE)
  102. #define ERROR_NO_HEADERS GetResString(IDS_NO_HEADERS)
  103. #define ERROR_INVALID_SERVER GetResString(IDS_INVALID_SERVER)
  104. #define ERROR_INVALID_USER GetResString(IDS_INVALID_USER)
  105. #define INVALID_SIGNED_SYNTAX GetResString(IDS_INVALID_SIGNED_SYNTAX)
  106. #define COL_HOSTNAME_WIDTH AsLong(GetResString(IDS_COL_HOSTNAME_SIZE),10)
  107. #define COL_FILENAME_WIDTH AsLong(GetResString(IDS_COL_FILENAME_SIZE),10)
  108. #define COL_SIGNED_WIDTH AsLong(GetResString(IDS_SIGNED_SIZE),10)
  109. #define COL_DISPLAYNAME_WIDTH AsLong(GetResString(IDS_COL_DISPLAYNAME_SIZE),10)
  110. #define COL_DESCRIPTION_WIDTH AsLong(GetResString(IDS_COL_DESCRIPTION_SIZE),10)
  111. #define COL_DRIVERTYPE_WIDTH AsLong(GetResString(IDS_COL_DRIVERTYPE_SIZE),10)
  112. #define COL_STARTMODE_WIDTH AsLong(GetResString(IDS_COL_STARTMODE_SIZE),10)
  113. #define COL_STATE_WIDTH AsLong(GetResString(IDS_COL_STATE_SIZE),10)
  114. #define COL_STATUS_WIDTH AsLong(GetResString(IDS_COL_STATUS_SIZE),10)
  115. #define COL_ACCEPTSTOP_WIDTH AsLong(GetResString(IDS_COL_ACCEPTSTOP_SIZE),10)
  116. #define COL_ACCEPTPAUSE_WIDTH AsLong(GetResString(IDS_COL_ACCEPTPAUSE_SIZE),10)
  117. #define COL_MEMORYUSAGE_WIDTH AsLong(GetResString(IDS_COL_MEMORYUSAGE_SIZE),10)
  118. #define COL_PAGEDPOOL_WIDTH AsLong(GetResString(IDS_COL_PAGEDPOOL_SIZE),10)
  119. #define COL_NONPAGEDPOOL_WIDTH AsLong(GetResString(IDS_COL_NONPAGEDPOOL_SIZE),10)
  120. #define COL_EXECCODE_WIDTH AsLong(GetResString(IDS_COL_EXECCODE_SIZE),10)
  121. #define COL_NBSS_WIDTH AsLong(GetResString(IDS_COL_NBSS_SIZE),10)
  122. #define COL_BSS_WIDTH AsLong(GetResString(IDS_COL_BSS_SIZE),10)
  123. #define COL_LINKDATE_WIDTH AsLong(GetResString(IDS_COL_LINKDATE_SIZE),10)
  124. #define COL_LOCATION_WIDTH AsLong(GetResString(IDS_COL_LOCATION_SIZE),10)
  125. #define COL_INITSIZE_WIDTH AsLong(GetResString(IDS_COL_INITSIZE_SIZE),10)
  126. #define COL_PAGESIZE_WIDTH AsLong(GetResString(IDS_COL_PAGESIZE_SIZE),10)
  127. #define COL_DEVICE_WIDTH AsLong(GetResString(IDS_COL_DEVICE_WIDTH),10)
  128. #define COL_INF_WIDTH AsLong(GetResString(IDS_COL_INF_WIDTH),10)
  129. #define COL_ISSIGNED_WIDTH AsLong(GetResString(IDS_COL_ISSIGNED_WIDTH),10)
  130. #define COL_MANUFACTURER_WIDTH AsLong(GetResString(IDS_COL_MANUFACTURER_WIDTH),10)
  131. #define FORMAT_VALUES L"List|Table|Csv"
  132. #define MAX_COLUMNS 16
  133. #define MAX_SIGNED_COLUMNS 4
  134. #define COL0 0
  135. #define COL1 1
  136. #define COL2 2
  137. #define COL3 3
  138. #define COL4 4
  139. #define COL5 5
  140. #define COL6 6
  141. #define COL7 7
  142. #define COL8 8
  143. #define COL9 9
  144. #define COL10 10
  145. #define COL11 11
  146. #define COL12 12
  147. #define COL13 13
  148. #define COL14 14
  149. #define COL15 15
  150. #define COL16 16
  151. #define COL17 17
  152. #define COL18 18
  153. #define SUCCESS 0
  154. #define FAILURE 1
  155. #define EXTN_BSS ".bss"
  156. #define EXTN_PAGE "PAGE"
  157. #define EXTN_EDATA ".edata"
  158. #define EXTN_IDATA ".idata"
  159. #define EXTN_RSRC ".rsrc"
  160. #define EXTN_INIT "INIT"
  161. #define TOKEN_DOLLAR _T('$')
  162. #define COLON_SYMBOL _T(":")
  163. #define TOKEN_BACKSLASH _T("\\")
  164. #define TOKEN_BACKSLASH2 _T("\\\\")
  165. #define TOKEN_BACKSLASH3 _T("\\\\\\")
  166. #define CIMV2_NAMESPACE _T("ROOT\\CIMV2")
  167. #define DEFAULT_NAMESPACE _T("ROOT\\DEFAULT")
  168. #define CIMV2_NAME_SPACE _T("ROOT\\CIMV2")
  169. #define NO_DATA_AVAILABLE _T("N/A")
  170. #define FALSE_VALUE _T("FALSE")
  171. #define TRUE_VALUE _T("TRUE")
  172. #define IDENTIFIER_VALUE _T("Identifier")
  173. #define X86_MACHINE _T("x86")
  174. #define TOKEN_EMPTYSTRING _T("")
  175. #define LANGUAGE_WQL _T("WQL")
  176. #define NEWLINE _T("\n")
  177. #define WQL_QUERY _T("select * from Win32_PnpSignedDriver where DeviceName != NULL")
  178. #define TOKEN_CONSTANT 11
  179. #define GROUP_FORMAT_32 L"3;2;0"
  180. #define GROUP_32_VALUE 32
  181. #define EXIT_SUCCESSFUL 3
  182. #define EXIT_FAILURE_MALLOC 1
  183. #define EXIT_FAILURE_FORMAT 2
  184. #define EXIT_FAILURE_RESULTS 4
  185. #define VERSION_MISMATCH_ERROR 8
  186. #define PROPERTY_NAME L"Name"
  187. #define PROPERTY_SYSTEMNAME L"SystemName"
  188. #define PROPERTY_STARTMODE L"StartMode"
  189. #define PROPERTY_DISPLAYNAME L"DisplayName"
  190. #define PROPERTY_DESCRIPTION L"Description"
  191. #define PROPERTY_STATUS L"Status"
  192. #define PROPERTY_STATE L"State"
  193. #define PROPERTY_ACCEPTPAUSE L"AcceptPause"
  194. #define PROPERTY_ACCEPTSTOP L"AcceptStop"
  195. #define PROPERTY_SERVICETYPE L"ServiceType"
  196. #define PROPERTY_PATHNAME L"PathName"
  197. #define PROPERTY_SYSTEM_TYPE L"SystemType"
  198. #define PROPERTY_GETSTRINGVAL L"GetStringValue"
  199. #define PROPERTY_RETURNVAL L"ReturnValue"
  200. #define STD_REG_CLASS L"StdRegProv"
  201. #define REG_METHOD L"GetStringValue"
  202. #define HKEY_VALUE L"hDefKey"
  203. #define REG_SUB_KEY_VALUE L"sSubKeyName"
  204. #define REG_VALUE_NAME L"sValueName"
  205. #define REG_RETURN_VALUE L"sValue"
  206. #define REG_PATH L"HARDWARE\\DESCRIPTION\\SYSTEM\\CENTRALPROCESSOR\\0"
  207. #define REG_SVALUE L"Identifier"
  208. #define HEF_KEY_VALUE 2147483650
  209. #define DRIVERQUERY_MUTEX L"Global\\SignedDriversMutex"
  210. #define ERROR_WMI_VALUES 1
  211. #define SYSTEM_64_BIT 2
  212. #define SYSTEM_32_BIT 3
  213. #define ERROR_RETREIVE_REGISTRY 4
  214. #define ERROR_WMI_CONNECT 5
  215. #define ERROR_GET 6
  216. #define CLASS_SYSTEMDRIVER L"Win32_SystemDriver"
  217. #define CLASS_COMPUTERSYSTEM L"Win32_ComputerSystem"
  218. #define CLASS_PNPSIGNEDDRIVER L"Win32_PnpSignedDriver"
  219. #define PROPERTY_PNP_DEVICENAME L"DeviceName"
  220. #define PROPERTY_PNP_INFNAME L"InfName"
  221. #define PROPERTY_PNP_ISSIGNED L"IsSigned"
  222. //#define PROPERTY_PNP_MFG L"Mfg"
  223. #define PROPERTY_PNP_MFG L"Manufacturer"
  224. // Registry key information
  225. #define HKEY_MACHINE_INFO 2147483650 // registry value for HKEY_LOCAL_MACHINE
  226. #define SUBKEY _T("HARDWARE\\DESCRIPTION\\SYSTEM\\CENTRALPROCESSOR\\0")
  227. // User Defined Macros
  228. #define SAFEDELETE(pObj) \
  229. if (pObj) \
  230. { \
  231. delete[] pObj; \
  232. pObj = NULL; \
  233. }
  234. // SAFEIRELEASE
  235. #define SAFEIRELEASE(pIObj) \
  236. if (pIObj) \
  237. { \
  238. pIObj->Release(); \
  239. pIObj = NULL; \
  240. }
  241. //SAFEBSTRFREE
  242. #define SAFEBSTRFREE(bstrVal) \
  243. if (bstrVal) \
  244. { \
  245. SysFreeString(bstrVal); \
  246. bstrVal = NULL; \
  247. }
  248. #define ONFAILTHROWERROR(hResult) \
  249. if (FAILED(hResult)) \
  250. { \
  251. _com_issue_error(hResult); \
  252. }
  253. #define SAFE_RELEASE( interfacepointer ) \
  254. if ( (interfacepointer) != NULL ) \
  255. { \
  256. (interfacepointer)->Release(); \
  257. (interfacepointer) = NULL; \
  258. } \
  259. #define SAFE_EXECUTE( statement ) \
  260. hRes = statement; \
  261. if ( FAILED( hRes ) ) \
  262. { \
  263. _com_issue_error( hRes ); \
  264. } \
  265. #define EMPTY_LINE _T("\n")
  266. #define SIZE_OF_ARRAY_IN_BYTES(x) \
  267. GetBufferSize(x)
  268. #define SIZE_OF_ARRAY_IN_CHARS(x) \
  269. GetBufferSize(x)/sizeof(WCHAR)
  270. // structure to store the data fetched using the API's
  271. typedef struct _MODULE_DATA
  272. {
  273. ULONG ulCodeSize;
  274. ULONG ulDataSize;
  275. ULONG ulBssSize;
  276. ULONG ulPagedSize;
  277. ULONG ulInitSize;
  278. ULONG ulImportDataSize ;
  279. ULONG ulExportDataSize ;
  280. ULONG ulResourceDataSize;
  281. __MAX_SIZE_STRING szTimeDateStamp ;
  282. } MODULE_DATA, *PMODULE_DATA;
  283. // function prototypes
  284. DWORD
  285. QueryDriverInfo(LPTSTR szServer,
  286. LPTSTR szUserName,
  287. LPTSTR szPassword,
  288. LPTSTR szFormat,
  289. BOOL bHeader,
  290. BOOL bVerbose,
  291. IWbemLocator* pIWbemLocator,
  292. COAUTHIDENTITY* pAuthIdentity,
  293. IWbemServices* pIWbemServReg ,
  294. BOOL bSigned
  295. );
  296. DWORD
  297. ProcessCompSysEnum(CHString szHostName,
  298. IEnumWbemClassObject *pSystemSet,
  299. LPTSTR szFormat,
  300. BOOL bHeader,
  301. DWORD dwSystemType,
  302. BOOL bVerbose
  303. );
  304. BOOL
  305. ProcessOptions(LONG argc,
  306. LPCTSTR argv[],
  307. PBOOL pbShowUsage,
  308. LPTSTR *pszServer,
  309. LPTSTR *pszUserName,
  310. LPTSTR pszPassword,
  311. LPTSTR pszFormat,
  312. PBOOL pbHeader,
  313. PBOOL bNeedPassword,
  314. PBOOL pbVerbose,
  315. PBOOL pbSigned
  316. );
  317. VOID ShowUsage() ;
  318. BOOL GetApiInfo(LPTSTR szHostName,LPCTSTR szPath,PMODULE_DATA Mod,DWORD dwSystemType);
  319. VOID PrintModuleLine(PMODULE_DATA Current);
  320. VOID FormHeader(DWORD dwFormatType,BOOL bHeader,TCOLUMNS *ResultHeader,BOOL bVerbose);
  321. SCODE ParseAuthorityUserArgs1(BSTR & AuthArg, BSTR & UserArg,BSTR & Authority,BSTR & User);
  322. BOOL bIsNT();
  323. BOOL
  324. FormatAccToLocale( NUMBERFMT *pNumberFmt,
  325. LPTSTR* pszGroupSep,
  326. LPTSTR* pszDecimalSep,
  327. LPTSTR* pszGroupThousSep
  328. );
  329. BOOL GetInfo( LCTYPE lctype, LPTSTR* pszData );
  330. BOOL InitialiseCom(IWbemLocator** ppIWbemLocator);
  331. DWORD GetSystemType(COAUTHIDENTITY* pAuthIdentity,IWbemServices* pIWbemServReg);
  332. HRESULT PropertyGet(IWbemClassObject* pWmiObject,LPCTSTR pszInputVal,CHString &szOutPutVal);
  333. SCODE ParseAuthorityUserArgs( BSTR& bstrAuthArg,
  334. BSTR& bstrUserArg,
  335. BSTR& bstrUser ) ;
  336. HRESULT SetSecurity( IUnknown *pIUnknown,
  337. LPCTSTR lpDomain,
  338. LPCTSTR lpUser,
  339. LPCTSTR lpPassword,
  340. BOOL bLocCred );
  341. HRESULT
  342. FreeMemoryAll(IWbemClassObject *pInClass,
  343. IWbemClassObject * pClass,
  344. IWbemClassObject * pOutInst ,
  345. IWbemClassObject * pInInst,
  346. IWbemServices *pIWbemServReg,
  347. VARIANT *varConnectName,
  348. VARIANT *varSvalue,
  349. VARIANT *varHkey,
  350. VARIANT *varRetVal,
  351. VARIANT *varVaue,
  352. LPTSTR szSysName
  353. );
  354. BOOL IsValidUserEx( LPCWSTR pwszUser );
  355. #define GetWbemErrorText( hr ) WMISaveError( hr )
  356. HRESULT SetInterfaceSecurity( IUnknown *pInterface, COAUTHIDENTITY *pAuthIdentity );
  357. BOOL ConnectWmiEx( IWbemLocator *pLocator,
  358. IWbemServices **ppServices,
  359. const CHString &strServer,
  360. CHString &strUserName,
  361. CHString &strPassword,
  362. COAUTHIDENTITY **ppAuthIdentity,
  363. BOOL bNeedPassword = FALSE,
  364. LPCWSTR pszNamespace = CIMV2_NAME_SPACE,
  365. BOOL *pbLocalSystem = NULL );
  366. DWORD
  367. ProcessSignedDriverInfo(CHString szHost,
  368. IEnumWbemClassObject *pSystemSet,
  369. LPTSTR szFormat,
  370. BOOL bHeader,
  371. DWORD dwSystemType,
  372. BOOL bVerbose
  373. );
  374. HRESULT
  375. PropertyGet_Bool(IWbemClassObject* pWmiObject,
  376. LPCTSTR pszInputVal,
  377. PBOOL pIsSigned
  378. );
  379. VOID FormSignedHeader(DWORD dwFormatType,BOOL bHeader,TCOLUMNS *ResultHeader);
  380. VOID WMISaveError( HRESULT hResError );
  381. LCID GetSupportedUserLocale( BOOL& bLocaleChanged ) ;
  382. VOID WINAPI WbemFreeAuthIdentity( COAUTHIDENTITY **ppAuthIdentity );
  383. #define COL_DEVICENAME GetResString(IDS_COL_DEVICENAME)
  384. #define COL_INF_NAME GetResString(IDS_COL_INF_NAME)
  385. #define COL_ISSIGNED GetResString(IDS_COL_ISSIGNED)
  386. #define COL_MANUFACTURER GetResString(IDS_COL_MANUFACTURER)
  387. // inline functions
  388. inline VOID WMISaveError( _com_error &e )
  389. {
  390. WMISaveError( e.Error() );
  391. }
  392. VOID WMISaveError( HRESULT hResError );
  393. #endif