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.

461 lines
17 KiB

  1. /*********************************************************************************************
  2. Copyright (c) Microsoft Corporation
  3. Module Name:
  4. GpResult.h
  5. Abstract:
  6. This module contanins function definations required by GpResult.cpp,
  7. and all necessary Defines and header files used in this project.
  8. Author:
  9. Wipro Technologies.
  10. Revision History:
  11. 20-Feb-2001 : Created It.
  12. *********************************************************************************************/
  13. #ifndef _GPRESULT_H
  14. #define _GPRESULT_H
  15. #include "Resource.h"
  16. //
  17. // macro definitions
  18. // Exit the program with appropriate error code after releasing the memory
  19. #define EXIT_PROCESS( exitcode ) \
  20. ReleaseGlobals(); \
  21. return exitcode; \
  22. 1
  23. // Macro to check for the returned hresult value
  24. #define CHECK_HRESULT( hr ) \
  25. if( FAILED( hr ) ) \
  26. { \
  27. _com_issue_error( hr ); \
  28. }\
  29. 1
  30. // Macro to check for the returned hresult value, this one cleans the status msg
  31. #define CHECK_HRESULT_EX( hr ) \
  32. if( FAILED( hr ) ) \
  33. { \
  34. PrintProgressMsg( m_hOutput, NULL, m_csbi ); \
  35. _com_issue_error( hr ); \
  36. }\
  37. 1
  38. // Macro to check for the returned hresult value
  39. // It also sets the variant to VT_EMPTY
  40. #define CHECK_HRESULT_VAR( hr, var ) \
  41. if( FAILED( hr ) ) \
  42. { \
  43. V_VT( &var ) = VT_EMPTY; \
  44. _com_issue_error( hr ); \
  45. }\
  46. 1
  47. #define CHECK_BRESULT( bResult ) \
  48. if( bResult == FALSE ) \
  49. { \
  50. _com_issue_error( STG_E_UNKNOWN ); \
  51. } \
  52. 1
  53. //SAFEDELETE
  54. #define SAFEDELETE( pObj ) \
  55. if (pObj) \
  56. { \
  57. delete[] pObj; \
  58. pObj = NULL; \
  59. }\
  60. 1
  61. //SAFEIRELEASE
  62. #define SAFEIRELEASE( pIObj )\
  63. if ( pIObj )\
  64. {\
  65. pIObj->Release();\
  66. pIObj = NULL;\
  67. }\
  68. 1
  69. // SAFEBSTRFREE
  70. #define SAFEBSTRFREE( bstrVal ) \
  71. if ( bstrVal ) \
  72. { \
  73. SysFreeString( bstrVal ); \
  74. bstrVal = NULL; \
  75. } \
  76. 1
  77. // CHECK_ALLOCATION
  78. #define CHECK_ALLOCATION( allocation )\
  79. if( ( allocation ) == NULL )\
  80. {\
  81. _com_issue_error( E_OUTOFMEMORY ); \
  82. }\
  83. 1
  84. #define SAFE_DELETE( pointer ) \
  85. if ( (pointer) != NULL ) \
  86. { \
  87. delete (pointer); \
  88. (pointer) = NULL; \
  89. } \
  90. 1
  91. #define SAFE_DELETE_EX( pointer ) \
  92. if ( (pointer) != NULL ) \
  93. { \
  94. delete [] (pointer); \
  95. (pointer) = NULL; \
  96. } \
  97. 1
  98. #define DESTROY_ARRAY( array ) \
  99. if ( (array) != NULL ) \
  100. { \
  101. DestroyDynamicArray( &(array) ); \
  102. (array) = NULL; \
  103. } \
  104. 1
  105. #ifdef _DEBUG
  106. #define TRACE_DEBUG( text ) _tprintf( _T("TRACE: ") ## text )
  107. #else
  108. #define TRACE_DEBUG( text ) 1
  109. #endif
  110. //
  111. // Constants and Definitions
  112. // Maximum Command Line List
  113. #define MAX_CMDLINE_OPTIONS 10
  114. #define MAX_DATA 6
  115. #define MAX_QUERY_STRING 512
  116. #define TIME_OUT_NEXT 5000
  117. #define VERSION_CHECK 5000
  118. // Defining the domain role of a PDC for LDAP purposes
  119. #define DOMAIN_ROLE_PDC 5
  120. // Define a constant to check for the True value returned from WMI
  121. #define VAR_TRUE -1
  122. // Option indices
  123. #define OI_USAGE 0
  124. #define OI_LOGGING 1
  125. #define OI_PLANNING 2
  126. #define OI_SERVER 3
  127. #define OI_USERNAME 4
  128. #define OI_PASSWORD 5
  129. #define OI_USER 6
  130. #define OI_SCOPE 7
  131. #define OI_VERBOSE 8
  132. #define OI_SUPER_VERBOSE 9
  133. // Option values
  134. #define OPTION_USAGE _T( "?" )
  135. #define OPTION_LOGGING _T( "Logging" )
  136. #define OPTION_PLANNING _T( "Planning" )
  137. #define OPTION_SERVER _T( "s" )
  138. #define OPTION_USERNAME _T( "u" )
  139. #define OPTION_PASSWORD _T( "p" )
  140. #define OPTION_USER _T( "User" )
  141. #define OPTION_SCOPE _T( "Scope" )
  142. #define OPTION_VERBOSE _T( "v" )
  143. #define OPTION_SUPER_VERBOSE _T( "z" )
  144. // Data Indices
  145. #define DI_USER_SID 0
  146. #define DI_USER_NAME 1
  147. #define DI_LOCAL_PROFILE 2
  148. #define DI_USER_SERVER 3
  149. #define DI_USER_DOMAIN 4
  150. #define DI_USER_SITE 5
  151. // Exit values
  152. #define CLEAN_EXIT 0
  153. #define ERROR_EXIT 1
  154. // Array column values
  155. #define COL_DATA 0
  156. #define COL_ORDER 1
  157. #define COL_FILTER 1
  158. #define COL_FILTER_ID 2
  159. #define COL_MAX 2
  160. #define COL_MAX_FILTER 3
  161. // General defines
  162. #define ARRAYSIZE( a ) ( sizeof(a)/sizeof( a[0] ) )
  163. #define MUTEX_NAME _T( "RsopCreateSessionMutex" )
  164. #define START_NAMESPACE _T( "\\root\\rsop" )
  165. #define DEFAULT_LINK_SPEED _T( "500 kbps" )
  166. #define HELP_OPTION _T( "-?" )
  167. #define HELP_OPTION1 _T( "/?" )
  168. #define NEW_LINE _T( "\n" )
  169. #define TAB_TWO _T( " " )
  170. #define SLASH _T( '\\' )
  171. #define SEPARATOR_AT _T( '@' )
  172. #define SEPARATOR_DOT _T( '.' )
  173. // SID values
  174. #define SID_NULL_SID _T( "S-1-0-0" )
  175. #define SID_EVERYONE _T( "S-1-1-0" )
  176. #define SID_LOCAL _T( "S-1-2-0" )
  177. #define SID_CREATOR_OWNER _T( "S-1-3-0" )
  178. #define SID_CREATOR_GROUP _T( "S-1-3-1" )
  179. // Scope (Computer/User/All)
  180. #define SCOPE_ALL 0
  181. #define SCOPE_USER 1
  182. #define SCOPE_COMPUTER 2
  183. #define TEXT_SCOPE_VALUES _T( "USER|COMPUTER" )
  184. #define TEXT_SCOPE_USER _T( "USER" )
  185. #define TEXT_SCOPE_COMPUTER _T( "COMPUTER" )
  186. #define TEXT_WILD_CARD _T( "*" )
  187. #define TEXT_BACKSLASH _T( "\\" )
  188. #define TEXT_COMMA_DC _T( ", DC=" )
  189. #define TEXT_DOLLAR _T( "$" )
  190. // Queries
  191. #define QUERY_LOCAL _T( "Select * from Win32_UserAccount where name = \"%s\"" )
  192. #define QUERY_DOMAIN _T( "Select * from Win32_UserAccount where name = \"%s\" and Domain = \"%s\" " )
  193. #define QUERY_LANGUAGE _T( "WQL" )
  194. #define QUERY_WILD_CARD _T( "Select * from Win32_UserAccount" )
  195. #define QUERY_GPO_NAME _T( "Select name from Rsop_Gpo WHERE id = \"%s\"" )
  196. #define QUERY_DOMAIN_NAME _T( "ASSOCIATORS OF {%s} WHERE ResultClass=Win32_Group" )
  197. #define QUERY_USER_NAME _T( "Select name, domain from Win32_UserAccount where SID = \"%s\"" )
  198. #define QUERY_COMPUTER_FQDN _T( "Select ds_distinguishedName from ds_computer" )
  199. #define QUERY_USER_FQDN _T( "Select ds_distinguishedName from ds_user where ds_SAMAccountName = \"%s\"" )
  200. #define OBJECT_PATH _T( "Win32_SID.SID=\"%s\"" )
  201. #define GPO_REFERENCE _T( "RSOP_GPO.id=" )
  202. // error messages
  203. #define ERROR_USERNAME_BUT_NOMACHINE GetResString( IDS_ERROR_USERNAME_BUT_NOMACHINE )
  204. #define ERROR_PASSWORD_BUT_NOUSERNAME GetResString( IDS_ERROR_PASSWORD_BUT_NOUSERNAME )
  205. #define ERROR_NODATA_AVAILABLE_REMOTE GetResString( IDS_ERROR_NODATA_AVAILABLE_REMOTE )
  206. #define ERROR_NODATA_AVAILABLE_LOCAL GetResString( IDS_ERROR_NODATA_AVAILABLE_LOCAL )
  207. #define ERROR_USERNAME_EMPTY GetResString( IDS_ERROR_USERNAME_EMPTY )
  208. #define ERROR_SERVERNAME_EMPTY GetResString( IDS_ERROR_SERVERNAME_EMPTY )
  209. #define ERROR_NO_OPTIONS GetResString( IDS_ERROR_NO_OPTIONS )
  210. #define ERROR_USAGE GetResString( IDS_ERROR_USAGE )
  211. #define ERROR_TARGET_EMPTY GetResString( IDS_ERROR_TARGET_EMPTY )
  212. #define ERROR_VERBOSE_SYNTAX GetResString( IDS_ERROR_VERBOSE_SYNTAX )
  213. //
  214. // Mapping information of Win32_ComputerSystem's DomainRole property
  215. // NOTE: Refer to the _DSROLE_MACHINE_ROLE enumeration values in DsRole.h header file
  216. #define VALUE_STANDALONEWORKSTATION GetResString( IDS_VALUE_STANDALONEWORKSTATION )
  217. #define VALUE_MEMBERWORKSTATION GetResString( IDS_VALUE_MEMBERWORKSTATION )
  218. #define VALUE_STANDALONESERVER GetResString( IDS_VALUE_STANDALONESERVER )
  219. #define VALUE_MEMBERSERVER GetResString( IDS_VALUE_MEMBERSERVER )
  220. #define VALUE_BACKUPDOMAINCONTROLLER GetResString( IDS_VALUE_BACKUPDOMAINCONTROLLER )
  221. #define VALUE_PRIMARYDOMAINCONTROLLER GetResString( IDS_VALUE_PRIMARYDOMAINCONTROLLER )
  222. // Classes, providers and namespaces...
  223. #define ROOT_NAME_SPACE _T( "root\\cimv2" )
  224. #define ROOT_RSOP _T( "root\\rsop" )
  225. #define ROOT_DEFAULT _T( "root\\default" )
  226. #define ROOT_POLICY _T( "root\\policy" )
  227. #define ROOT_LDAP _T( "root\\directory\\ldap" )
  228. #define CLS_DIAGNOSTIC_PROVIDER _T( "RsopLoggingModeProvider" )
  229. #define CLS_STD_REGPROV _T( "StdRegProv" )
  230. #define CLS_WIN32_SITE _T( "Win32_NTDomain" )
  231. #define CLS_WIN32_OS _T( "Win32_OperatingSystem" )
  232. #define CLS_WIN32_CS _T( "Win32_ComputerSystem" )
  233. #define CLS_WIN32_UA _T( "Win32_UserAccount" )
  234. #define CLS_WIN32_C _T( "Win32_Computer" )
  235. #define CLS_RSOP_GPO _T( "Rsop_GPO" )
  236. #define CLS_RSOP_GPOLINK _T( "Rsop_GPLink" )
  237. #define CLS_RSOP_SESSION _T( "Rsop_Session" )
  238. // Class Property Values
  239. #define CPV_SID _T( "SID" )
  240. #define CPV_NAME _T( "name" )
  241. #define CPV_DOMAIN _T( "domain" )
  242. #define CPV_SVALUE _T( "sValue" )
  243. #define CPV_GPO_NAME _T( "name" )
  244. #define CPV_GPO_FILTER_STATUS _T( "filterAllowed" )
  245. #define CPV_GPO_FILTER_ID _T( "filterId" )
  246. #define CPV_GPO_SERVER _T( "__SERVER" )
  247. #define CPV_SITE_NAME _T( "DcSiteName" )
  248. #define CPV_DC_NAME _T( "DomainControllerName" )
  249. #define CPV_USER_SID _T( "userSid" )
  250. #define CPV_DOMAIN_ROLE _T( "DomainRole" )
  251. #define CPV_OS_VERSION _T( "Version" )
  252. #define CPV_OS_CAPTION _T( "Caption" )
  253. #define CPV_SEC_GRPS _T( "SecurityGroups" )
  254. #define CPV_SLOW_LINK _T( "slowLink" )
  255. #define CPV_ACCOUNT_NAME _T( "AccountName" )
  256. #define CPV_USER_SIDS _T( "userSids" )
  257. #define CPV_APPLIED_ORDER _T( "appliedOrder" )
  258. #define CPV_GPO_REF _T( "GPO" )
  259. #define CPV_ENABLED _T( "enabled" )
  260. #define CPV_ACCESS_DENIED _T( "accessDenied" )
  261. #define CPV_VERSION _T( "version" )
  262. #define CPV_FQDN _T( "ds_distinguishedName" )
  263. #define CPV_LDAP_FQDN _T( "distinguishedName" )
  264. #define CPV_LDAP_SAM _T( "sAMAccountName" )
  265. // Function return
  266. #define FPR_VALUE_NAME _T( "sValueName" )
  267. #define FPR_LOCAL_VALUE _T( "ProfileImagePath" )
  268. #define FPR_ROAMING_VALUE _T( "CentralProfile" )
  269. #define FPR_SUB_KEY_NAME _T( "sSubKeyName" )
  270. #define FPR_HDEFKEY _T( "hDefKey" )
  271. #define FPR_RSOP_NAME_SPACE _T( "nameSpace" )
  272. #define FPR_RETURN_VALUE _T( "hResult" )
  273. #define FPR_RSOP_NAMESPACE _T( "nameSpace" )
  274. #define FPR_SNAMES _T( "sNames" )
  275. #define FPR_LINK_SPEED_VALUE _T( "GroupPolicyMinTransferRate" )
  276. #define FPR_APPLIED_FROM _T( "DCName" )
  277. #define CPV_FLAGS _T( "flags" )
  278. // Paths in registry to retrieve info. from
  279. #define PATH _T( "SOFTWARE\\MicroSoft\\Windows NT\\CurrentVersion\\ProfileList\\" )
  280. #define GPRESULT_PATH _T( "Software\\policies\\microsoft\\windows\\system" )
  281. #define GROUPPOLICY_PATH _T( "Software\\Microsoft\\Windows\\CurrentVersion\\Group Policy" )
  282. #define APPLIED_PATH _T( "Software\\Microsoft\\Windows\\CurrentVersion\\Group Policy\\History" )
  283. // Registry keys
  284. #define HKEY_DEF 2147483650
  285. #define HKEY_CURRENT_USER_DEF 2147483649
  286. // keys in registry whose info. is required
  287. #define FN_GET_EXPAND_VAL _T( "GetExpandedStringValue" )
  288. #define FN_CREATE_RSOP _T( "RsopCreateSession" )
  289. #define FN_DELETE_RSOP _T( "RsopDeleteSession" )
  290. #define FN_ENUM_USERS _T( "RsopEnumerateUsers" )
  291. #define FN_ENUM_KEYS _T( "EnumKey" )
  292. // general defines
  293. #define SEPARATOR _T("-")
  294. #define DOUBLESLASH _T("\\\\")
  295. #define ZERO _T("00000000000000.000000+000")
  296. #define EXTRA _T('e')
  297. #define LAST_TIME_OP _T( "%s at %s" )
  298. // Structure to hold the User Information
  299. typedef struct _USER_INFO
  300. {
  301. CHString strUserSid; // Holds the SID value for the user.
  302. CHString strUserName; // Holds the Name of the user.
  303. CHString strLocalProfile; // Holds the local profile for the user.
  304. CHString strRoamingProfile; // Holds the roaming profile for the user.
  305. CHString strUserServer; // Holds the server name for the user.
  306. CHString strUserDomain; // Holds the domain name.
  307. CHString strUserSite; // Holds the site name.
  308. CHString strOsType; // Holds the OS type
  309. CHString strOsVersion; // Holds the OS Version
  310. CHString strOsConfig; // Holds the OS Configuration
  311. CHString strUserFQDN; // Holds the FQDN of the user
  312. CHString strComputerFQDN; // Holds the FQDN of the computer
  313. }USERINFO, *PUSERINFO;
  314. //
  315. // CGpResult
  316. //
  317. class CGpResult
  318. {
  319. // constructor / destructor
  320. public:
  321. CGpResult();
  322. ~CGpResult();
  323. // data memebers
  324. private:
  325. // WMI / COM interfaces
  326. IWbemLocator *m_pWbemLocator;
  327. IWbemServices *m_pWbemServices;
  328. IWbemServices *m_pRsopNameSpace;
  329. IEnumWbemClassObject *m_pEnumObjects;
  330. // WMI connectivity
  331. COAUTHIDENTITY *m_pAuthIdentity;
  332. // command-line argument values
  333. CHString m_strUserName; // Stores the user name
  334. CHString m_strPassword; // Stores the password
  335. CHString m_strUser; // Stores the User for whom the data is to be retrieved
  336. CHString m_strServerName; // Stores the server name
  337. CHString m_strDomainName; // Stores the domain name, if specified with the user name
  338. LPWSTR m_pwszPassword; // Stores the password returned by the AUTHIDENTITY structure
  339. BOOL m_bVerbose; // is set to TRUE if the verbose information is to be displayed
  340. BOOL m_bSuperVerbose; // is set to TRUE if the super verbose information is to be displayed
  341. DWORD m_dwScope; // This gives the scope of information to be displayed
  342. // others
  343. BOOL m_bNeedPassword; // is set to TRUE if the password has to be prompted for
  344. BOOL m_bLocalSystem; // is set to TRUE if the local system has to be queried.
  345. HANDLE m_hMutex; // Handle to the mutex for the RsopCreateSession method
  346. CHString m_strADSIDomain; // Holds the domain name for the ADSI connection
  347. CHString m_strADSIServer; // Holds the server name for ADSI
  348. // data members that we need to access directly
  349. public:
  350. // main command line arguments
  351. BOOL m_bLogging; // set to TRUE if the logging mode data is to be displayed
  352. BOOL m_bPlanning; // set to TRUE if the planning mode data is to be displayed
  353. BOOL m_bUsage; // set to TRUE if the usage is to be displayed
  354. // progress message related
  355. HANDLE m_hOutput;
  356. CONSOLE_SCREEN_BUFFER_INFO m_csbi;
  357. private:
  358. BOOL DisplayCommonData( PUSERINFO pUserInfo );
  359. VOID DisplaySecurityGroups( IWbemServices *pNameSpace, BOOL bComputer );
  360. BOOL DisplayData( PUSERINFO pUserInfo, IWbemServices *pRsopNameSpace );
  361. BOOL DisplayVerboseComputerData( IWbemServices *pNameSpace );
  362. BOOL DisplayVerboseUserData( IWbemServices *pNameSpace );
  363. BOOL GetUserData( BOOL bAllUsers );
  364. BOOL GetUserProfile( PUSERINFO pUserInfo );
  365. BOOL GetDomainInfo( PUSERINFO pUserInfo );
  366. BOOL GetOsInfo( PUSERINFO pUserInfo );
  367. BOOL GetUserNameFromWMI( TCHAR szSid[], TCHAR szName[], TCHAR szDomain[] );
  368. BOOL DisplayThresholdSpeedAndLastTimeInfo( BOOL bComputer );
  369. BOOL GpoDisplay( IWbemServices *pNameSpace, LPCTSTR pszScopeName );
  370. VOID GetFQDNFromADSI( TCHAR szFQDN[], BOOL bComputer, LPCTSTR pszUserName );
  371. BOOL CreateRsopMutex( LPWSTR szMutexName );
  372. public:
  373. VOID DisplayUsage();
  374. BOOL Initialize();
  375. BOOL ProcessOptions( DWORD argc, LPCWSTR argv[], BOOL *pbNeedUsageMsg );
  376. // functionality related
  377. BOOL GetLoggingData();
  378. BOOL Connect( LPCWSTR pszServer );
  379. VOID Disconnect();
  380. };
  381. // Function prototypes
  382. VOID GetWbemErrorText( HRESULT hResult );
  383. VOID PrintProgressMsg( HANDLE hOutput, LPCWSTR pwszMsg,
  384. const CONSOLE_SCREEN_BUFFER_INFO& csbi );
  385. LCID GetSupportedUserLocale( BOOL& bLocaleChanged );
  386. #endif //#ifndef _GPRESULT_H