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.

423 lines
14 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. #define ID_HELP_START 1
  32. #define ID_USAGE_START IDS_USAGE_COPYRIGHT1
  33. #define ID_USAGE_END IDS_USAGE_EXAMPLE32
  34. #define ID_USAGE_BEGIN IDS_USAGEBEGIN1
  35. #define ID_USAGE_ENDING IDS_USAGEEND1
  36. #define OI_HELP 0
  37. #define OI_SERVER 1
  38. #define OI_USERNAME 2
  39. #define OI_PASSWORD 3
  40. #define OI_FORMAT 4
  41. #define OI_HEADER 5
  42. #define OI_VERBOSE 6
  43. #define OI_SIGNED 7
  44. #define MAX_OPTIONS 8
  45. // supported options ( do not localize )
  46. #define OPTION_HELP _T( "?" )
  47. #define OPTION_SERVER _T( "s" )
  48. #define OPTION_USERNAME _T( "u" )
  49. #define OPTION_PASSWORD _T( "p" )
  50. #define OPTION_FORMAT _T( "fo")
  51. #define OPTION_HEADER _T( "nh")
  52. #define OPTION_VERBOSE _T( "v" )
  53. #define OPTION_SIGNED _T( "si")
  54. //localized error messages.
  55. #define ERROR_USERNAME_BUT_NOMACHINE GetResString( IDS_ERROR_USERNAME_BUT_NOMACHINE )
  56. #define ERROR_PASSWORD_BUT_NOUSERNAME GetResString( IDS_ERROR_PASSWORD_BUT_NOUSERNAME )
  57. #define ERROR_COM_INTIALIZE GetResString(IDS_ERROR_COM_INTIALIZE)
  58. #define ERROR_SECURITY_INTIALIZE GetResString(IDS_ERROR_COM_SECURITY_INITIALIZE)
  59. #define ERROR_ENUMERATE_INSTANCE GetResString(IDS_ERROR_COM_ENUMERATE_INSTANCE)
  60. #define ERROR_CONNECT GetResString(IDS_ERROR_CONNECT)
  61. #define ERROR_SYNTAX GetResString(IDS_INVALID_SYNTAX)
  62. #define ERROR_RETREIVE_INFO GetResString(IDS_ERROR_RETREIVE_INFO)
  63. #define ERROR_INVALID_CREDENTIALS GetResString(IDS_INVALID_CREDENTIALS)
  64. #define ERROR_INVALID_FORMAT GetResString(IDS_ERROR_INVALID_FORMAT)
  65. #define ERROR_TAG GetResString(IDS_ERROR_TAG)
  66. #define ERROR_GET_VALUE GetResString(IDS_ERROR_GET)
  67. #define WARNING_TAG GetResString(IDS_WARNING_TAG)
  68. #define LIST_FORMAT GetResString(IDS_FORMAT_LIST)
  69. #define TABLE_FORMAT GetResString(IDS_FORMAT_TABLE)
  70. #define CSV_FORMAT GetResString(IDS_FORMAT_CSV)
  71. #define FORMAT_VALUES GetResString(IDS_FORMAT_VALUES)
  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 MAX_COLUMNS 16
  132. #define MAX_SIGNED_COLUMNS 4
  133. #define COL0 0
  134. #define COL1 1
  135. #define COL2 2
  136. #define COL3 3
  137. #define COL4 4
  138. #define COL5 5
  139. #define COL6 6
  140. #define COL7 7
  141. #define COL8 8
  142. #define COL9 9
  143. #define COL10 10
  144. #define COL11 11
  145. #define COL12 12
  146. #define COL13 13
  147. #define COL14 14
  148. #define COL15 15
  149. #define COL16 16
  150. #define COL17 17
  151. #define COL18 18
  152. #define SUCCESS 0
  153. #define FAILURE 1
  154. #define EXTN_BSS ".bss"
  155. #define EXTN_PAGE "PAGE"
  156. #define EXTN_EDATA ".edata"
  157. #define EXTN_IDATA ".idata"
  158. #define EXTN_RSRC ".rsrc"
  159. #define EXTN_INIT "INIT"
  160. #define TOKEN_DOLLAR _T('$')
  161. #define COLON_SYMBOL _T(":")
  162. #define TOKEN_BACKSLASH _T("\\")
  163. #define TOKEN_BACKSLASH2 _T("\\\\")
  164. #define TOKEN_BACKSLASH3 _T("\\\\\\")
  165. #define CIMV2_NAMESPACE _T("ROOT\\CIMV2")
  166. #define DEFAULT_NAMESPACE _T("ROOT\\DEFAULT")
  167. #define CIMV2_NAME_SPACE _T("ROOT\\CIMV2")
  168. #define NO_DATA_AVAILABLE _T("N/A")
  169. #define FALSE_VALUE _T("FALSE")
  170. #define TRUE_VALUE _T("TRUE")
  171. #define IDENTIFIER_VALUE _T("Identifier")
  172. #define X86_MACHINE _T("x86")
  173. #define TOKEN_EMPTYSTRING _T("")
  174. #define LANGUAGE_WQL _T("WQL")
  175. #define WQL_QUERY _T("select * from Win32_PnpSignedDriver where DeviceName != NULL")
  176. #define TOKEN_CONSTANT 11
  177. #define GROUP_FORMAT_32 L"3;2;0"
  178. #define GROUP_32_VALUE 32
  179. #define EXIT_SUCCESSFUL 3
  180. #define EXIT_FAILURE_MALLOC 5
  181. #define EXIT_FAILURE_FORMAT 2
  182. #define EXIT_FAILURE_RESULTS 4
  183. #define PROPERTY_NAME L"Name"
  184. #define PROPERTY_SYSTEMNAME L"SystemName"
  185. #define PROPERTY_STARTMODE L"StartMode"
  186. #define PROPERTY_DISPLAYNAME L"DisplayName"
  187. #define PROPERTY_DESCRIPTION L"Description"
  188. #define PROPERTY_STATUS L"Status"
  189. #define PROPERTY_STATE L"State"
  190. #define PROPERTY_ACCEPTPAUSE L"AcceptPause"
  191. #define PROPERTY_ACCEPTSTOP L"AcceptStop"
  192. #define PROPERTY_SERVICETYPE L"ServiceType"
  193. #define PROPERTY_PATHNAME L"PathName"
  194. #define PROPERTY_SYSTEM_TYPE L"SystemType"
  195. #define PROPERTY_GETSTRINGVAL L"GetStringValue"
  196. #define PROPERTY_RETURNVAL L"ReturnValue"
  197. #define STD_REG_CLASS L"StdRegProv"
  198. #define REG_METHOD L"GetStringValue"
  199. #define HKEY_VALUE L"hDefKey"
  200. #define REG_SUB_KEY_VALUE L"sSubKeyName"
  201. #define REG_VALUE_NAME L"sValueName"
  202. #define REG_RETURN_VALUE L"sValue"
  203. #define REG_PATH L"HARDWARE\\DESCRIPTION\\SYSTEM\\CENTRALPROCESSOR\\0"
  204. #define REG_SVALUE L"Identifier"
  205. #define HEF_KEY_VALUE 2147483650
  206. #define ERROR_WMI_VALUES 1
  207. #define SYSTEM_64_BIT 2
  208. #define SYSTEM_32_BIT 3
  209. #define ERROR_RETREIVE_REGISTRY 4
  210. #define ERROR_WMI_CONNECT 5
  211. #define ERROR_GET 6
  212. #define CLASS_SYSTEMDRIVER L"Win32_SystemDriver"
  213. #define CLASS_COMPUTERSYSTEM L"Win32_ComputerSystem"
  214. #define CLASS_PNPSIGNEDDRIVER L"Win32_PnpSignedDriver"
  215. #define PROPERTY_PNP_DEVICENAME L"DeviceName"
  216. #define PROPERTY_PNP_INFNAME L"InfName"
  217. #define PROPERTY_PNP_ISSIGNED L"IsSigned"
  218. //#define PROPERTY_PNP_MFG L"Mfg"
  219. #define PROPERTY_PNP_MFG L"Manufacturer"
  220. // Registry key information
  221. #define HKEY_MACHINE_INFO 2147483650 // registry value for HKEY_LOCAL_MACHINE
  222. #define SUBKEY _T("HARDWARE\\DESCRIPTION\\SYSTEM\\CENTRALPROCESSOR\\0")
  223. // User Defined Macros
  224. #define SAFEDELETE(pObj) \
  225. if (pObj) \
  226. { \
  227. delete[] pObj; \
  228. pObj = NULL; \
  229. }
  230. // SAFEIRELEASE
  231. #define SAFEIRELEASE(pIObj) \
  232. if (pIObj) \
  233. { \
  234. pIObj->Release(); \
  235. pIObj = NULL; \
  236. }
  237. //SAFEBSTRFREE
  238. #define SAFEBSTRFREE(bstrVal) \
  239. if (bstrVal) \
  240. { \
  241. SysFreeString(bstrVal); \
  242. bstrVal = NULL; \
  243. }
  244. #define SAFEFREE(szPtr)\
  245. if (szPtr!= NULL)\
  246. { \
  247. free(szPtr); \
  248. szPtr = NULL; \
  249. }
  250. #define ONFAILTHROWERROR(hResult) \
  251. if (FAILED(hResult)) \
  252. { \
  253. _com_issue_error(hResult); \
  254. }
  255. #define SAFE_RELEASE( interfacepointer ) \
  256. if ( (interfacepointer) != NULL ) \
  257. { \
  258. (interfacepointer)->Release(); \
  259. (interfacepointer) = NULL; \
  260. } \
  261. #define SAFE_EXECUTE( statement ) \
  262. hRes = statement; \
  263. if ( FAILED( hRes ) ) \
  264. { \
  265. _com_issue_error( hRes ); \
  266. } \
  267. #define EMPTY_LINE _T("\n")
  268. // structure to store the data fetched using the API's
  269. typedef struct _MODULE_DATA
  270. {
  271. ULONG ulCodeSize;
  272. ULONG ulDataSize;
  273. ULONG ulBssSize;
  274. ULONG ulPagedSize;
  275. ULONG ulInitSize;
  276. ULONG ulImportDataSize ;
  277. ULONG ulExportDataSize ;
  278. ULONG ulResourceDataSize;
  279. __MAX_SIZE_STRING szTimeDateStamp ;
  280. } MODULE_DATA, *PMODULE_DATA;
  281. // function prototypes
  282. DWORD QueryDriverInfo(LPTSTR szServer,LPTSTR szUserName,LPTSTR szPassword,LPTSTR szFormat,BOOL bHeader,BOOL bVerbose,IWbemLocator* pIWbemLocator,COAUTHIDENTITY* pAuthIdentity,IWbemServices* pIWbemServReg ,BOOL bSigned );
  283. DWORD ProcessCompSysEnum(CHString szHostName,IEnumWbemClassObject *pSystemSet,LPTSTR szFormat,BOOL bHeader,DWORD dwSystemType,BOOL bVerbose);
  284. BOOL ProcessOptions(LONG argc,LPCTSTR argv[],PBOOL pbShowUsage,LPTSTR *pszServer,LPTSTR *pszUserName,LPTSTR *pszPassword,LPTSTR pszFormat,PBOOL pbHeader, PBOOL bNeedPassword,PBOOL pbVerbose,PBOOL pbSigned);
  285. VOID ShowUsage() ;
  286. BOOL GetApiInfo(LPTSTR szHostName,LPCTSTR szPath,PMODULE_DATA Mod,DWORD dwSystemType);
  287. VOID PrintModuleLine(PMODULE_DATA Current);
  288. VOID FormHeader(DWORD dwFormatType,BOOL bHeader,TCOLUMNS *ResultHeader,BOOL bVerbose);
  289. SCODE ParseAuthorityUserArgs1(BSTR & AuthArg, BSTR & UserArg,BSTR & Authority,BSTR & User);
  290. BOOL bIsNT();
  291. BOOL FormatAccToLocale( NUMBERFMT *pNumberFmt,LPTSTR* pszGroupSep,LPTSTR* pszDecimalSep,LPTSTR* pszGroupThousSep);
  292. BOOL GetInfo( LCTYPE lctype, LPTSTR* pszData );
  293. BOOL InitialiseCom(IWbemLocator** ppIWbemLocator);
  294. DWORD GetSystemType(COAUTHIDENTITY* pAuthIdentity,IWbemServices* pIWbemServReg);
  295. HRESULT PropertyGet(IWbemClassObject* pWmiObject,LPCTSTR pszInputVal,CHString &szOutPutVal);
  296. SCODE ParseAuthorityUserArgs( BSTR& bstrAuthArg,
  297. BSTR& bstrUserArg,
  298. BSTR& bstrUser ) ;
  299. HRESULT SetSecurity( IUnknown *pIUnknown,
  300. LPCTSTR lpDomain,
  301. LPCTSTR lpUser,
  302. LPCTSTR lpPassword,
  303. BOOL bLocCred );
  304. HRESULT FreeMemory(IWbemClassObject *pInClass,IWbemClassObject * pClass,IWbemClassObject * pOutInst ,
  305. IWbemClassObject * pInInst,IWbemServices *pIWbemServReg,VARIANT varConnectName,VARIANT varSvalue,VARIANT varHkey,VARIANT varRetVal,VARIANT varVaue,LPTSTR szSysName );
  306. BOOL IsValidUserEx( LPCWSTR pwszUser );
  307. #define GetWbemErrorText( hr ) WMISaveError( hr )
  308. HRESULT SetInterfaceSecurity( IUnknown *pInterface, COAUTHIDENTITY *pAuthIdentity );
  309. BOOL ConnectWmiEx( IWbemLocator *pLocator,
  310. IWbemServices **ppServices,
  311. const CHString &strServer,
  312. CHString &strUserName,
  313. CHString &strPassword,
  314. COAUTHIDENTITY **ppAuthIdentity,
  315. BOOL bNeedPassword = FALSE,
  316. LPCWSTR pszNamespace = CIMV2_NAME_SPACE,
  317. BOOL *pbLocalSystem = NULL );
  318. DWORD ProcessSignedDriverInfo(CHString szHost, IEnumWbemClassObject *pSystemSet,LPTSTR szFormat,BOOL bHeader,DWORD dwSystemType,BOOL bVerbose);
  319. HRESULT PropertyGet_Bool(IWbemClassObject* pWmiObject, LPCTSTR pszInputVal, PBOOL pIsSigned);
  320. VOID FormSignedHeader(DWORD dwFormatType,BOOL bHeader,TCOLUMNS *ResultHeader);
  321. VOID WMISaveError( HRESULT hResError );
  322. LCID GetSupportedUserLocale( BOOL& bLocaleChanged ) ;
  323. #define COL_DEVICENAME GetResString(IDS_COL_DEVICENAME)
  324. #define COL_INF_NAME GetResString(IDS_COL_INF_NAME)
  325. #define COL_ISSIGNED GetResString(IDS_COL_ISSIGNED)
  326. #define COL_MANUFACTURER GetResString(IDS_COL_MANUFACTURER)
  327. // inline functions
  328. inline VOID WMISaveError( _com_error &e )
  329. {
  330. WMISaveError( e.Error() );
  331. }
  332. #endif