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.

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