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.

3330 lines
121 KiB

  1. /*********************************************************************************************
  2. Copyright (c) Microsoft Corporation
  3. Module Name:
  4. LoggingData.cpp
  5. Abstract:
  6. Collects and displays all the data related with the logging option.
  7. Author:
  8. Wipro Technologies.
  9. Revision History:
  10. 22-Feb-2001 : Created It.
  11. *********************************************************************************************/
  12. #include "pch.h"
  13. #include "GpResult.h"
  14. #include "WMI.h"
  15. // Local function prototypes
  16. BOOL GetDomainType( LPTSTR lpszDomainName, BOOL * pbW2K, BOOL *pbLocalAccount );
  17. BOOL RsopDeleteMethod( IWbemClassObject *pClass, CHString strNameSpace,
  18. IWbemServices *pNamespace );
  19. VOID DisplayLinkSpeed( IWbemServices *pNameSpace, COAUTHIDENTITY *pAuthIdentity );
  20. VOID SortAppliedData( TARRAY arrAppliedData );
  21. /*********************************************************************************************
  22. Routine Description:
  23. This function is the main entry point for collecting and displaying the data for logging mode
  24. Arguments:
  25. None
  26. Return Value:
  27. TRUE on SUCCESS
  28. FALSE on ERROR
  29. *********************************************************************************************/
  30. BOOL CGpResult::GetLoggingData()
  31. {
  32. // Local declarations
  33. BOOL bResult = FALSE;
  34. BOOL bAllUsers = TRUE;
  35. DWORD dwBufferSize = MAX_STRING_LENGTH;
  36. DWORD dwPosition = 0xffffffff;
  37. // Connect to wmi...connecting to 'cimv2' and saving the pointer in a member variable
  38. bResult = ConnectWmiEx( m_pWbemLocator, &m_pWbemServices, m_strServerName,
  39. m_strUserName, m_strPassword, &m_pAuthIdentity,
  40. m_bNeedPassword, ROOT_NAME_SPACE, &m_bLocalSystem );
  41. if( bResult == FALSE )
  42. {
  43. ShowMessage( stderr, GetResString( IDS_ERROR ) );
  44. ShowMessage( stderr, GetReason() );
  45. return FALSE;
  46. }
  47. // check the remote system version and its compatiblity
  48. if ( m_bLocalSystem == FALSE )
  49. {
  50. // check the version compatibility
  51. DWORD dwVersion = 0;
  52. dwVersion = GetTargetVersionEx( m_pWbemServices, m_pAuthIdentity );
  53. // Check for the version W2K = 5000 and WindowsXP = 5001
  54. if ( dwVersion <= VERSION_CHECK )
  55. {
  56. // Display the appropriate error message
  57. ShowMessage( stderr, GetResString( IDS_ERROR ) );
  58. ShowMessage( stderr, ERROR_OS_INCOMPATIBLE );
  59. return FALSE;
  60. }
  61. }
  62. // Set the password to the one got in the AUTHIDENTITY structure
  63. if( m_pAuthIdentity != NULL )
  64. {
  65. m_pwszPassword = m_pAuthIdentity->Password;
  66. }
  67. // check if it is the local system and the user credentials are specified....
  68. // if so display a warning message
  69. if( ( m_bLocalSystem == TRUE ) && ( m_strUserName.GetLength() != 0 ) )
  70. {
  71. ShowMessage( stderr, GetResString( IDS_WARNING ) );
  72. ShowMessage( stderr, GetResString( IDS_WARN_LOCAL ) );
  73. ShowMessage( stderr, NEW_LINE );
  74. // set the user name and password to NULL
  75. m_strUserName = L"";
  76. m_pwszPassword = NULL;
  77. // Get the new screen co-ordinates
  78. if ( m_hOutput != NULL )
  79. {
  80. GetConsoleScreenBufferInfo( m_hOutput, &m_csbi );
  81. }
  82. }
  83. // Connection part is over...check wether the user,for whom the RSOP data
  84. // has to be got has been specified.
  85. if( m_strUser.GetLength() == 0 )
  86. {
  87. // user is not specified....get the current logged on user
  88. LPWSTR pwszUserName = NULL;
  89. try
  90. {
  91. pwszUserName = m_strUser.GetBufferSetLength( dwBufferSize );
  92. }
  93. catch( ... )
  94. {
  95. // display the error message
  96. SetLastError((DWORD) E_OUTOFMEMORY );
  97. SaveLastError();
  98. ShowMessage( stderr, GetResString( IDS_ERROR ) );
  99. ShowMessage( stderr, GetReason() );
  100. }
  101. if ( GetUserNameEx( NameSamCompatible, pwszUserName, &dwBufferSize ) == FALSE )
  102. {
  103. // error occured while trying to get the current user info
  104. ShowMessage( stderr, GetResString( IDS_ERROR ) );
  105. ShowMessage( stderr, GetResString( IDS_METHOD_FAILED ) );
  106. return FALSE;
  107. }
  108. // Release the buffer
  109. m_strUser.ReleaseBuffer();
  110. }
  111. // Separating the domain name from the user name for whom the data has to be retrieved
  112. if( m_strUser.Compare( TEXT_WILD_CARD ) != 0 )
  113. {
  114. bAllUsers = FALSE;
  115. dwPosition = m_strUser.Find( SLASH );
  116. try
  117. {
  118. if( dwPosition != -1 )
  119. {
  120. m_strDomainName = m_strUser.Left( dwPosition );
  121. m_strUser = m_strUser.Mid( ( dwPosition + 1 ), m_strUser.GetLength() );
  122. }
  123. else
  124. {
  125. // Try for the name@domain format (UPN format)
  126. dwPosition = m_strUser.Find( SEPARATOR_AT );
  127. if( dwPosition != -1 )
  128. {
  129. m_strDomainName = m_strUser.Mid( ( dwPosition + 1 ), m_strUser.GetLength() );
  130. m_strUser = m_strUser.Left( dwPosition );
  131. }
  132. // Remove the unwanted things in the domain name
  133. dwPosition = m_strDomainName.Find( SEPARATOR_DOT );
  134. if( dwPosition != -1 )
  135. {
  136. m_strDomainName = m_strDomainName.Left( dwPosition );
  137. }
  138. }
  139. }
  140. catch( ... )
  141. {
  142. // display the error message
  143. SetLastError( (DWORD)E_OUTOFMEMORY );
  144. SaveLastError();
  145. ShowMessage( stderr, GetResString( IDS_ERROR ) );
  146. ShowMessage( stderr, GetReason() );
  147. }
  148. }
  149. PrintProgressMsg( m_hOutput, GetResString( IDS_USER_DATA ), m_csbi );
  150. //
  151. // Start the retrieval of information....
  152. // Get the user information
  153. if( GetUserData( bAllUsers ) == FALSE )
  154. {
  155. return FALSE;
  156. }
  157. return TRUE;
  158. }
  159. /*********************************************************************************************
  160. Routine Description:
  161. This function displays the non verbose data
  162. Arguments:
  163. [in] USERINFO : pointer to the user information structure
  164. [in] IWBEMSERVICES : pointer to the namespace
  165. Return Value:
  166. TRUE on SUCCESS
  167. FALSE on FAILURE
  168. *********************************************************************************************/
  169. BOOL CGpResult::DisplayData( PUSERINFO pUserInfo, IWbemServices *pRsopNameSpace )
  170. {
  171. // local variables
  172. HRESULT hResult = S_OK;
  173. BOOL bResult = FALSE;
  174. BOOL bCreatedRsop = FALSE;
  175. ULONG ulReturn = 0;
  176. ULONG ulExtendedCode = 0;
  177. DWORD dwi = 0;
  178. DWORD dwFlags = 0;
  179. DWORD dwMutex = 0;
  180. CHString strTemp;
  181. CHString strNameSpace;
  182. IWbemClassObject *pClass = NULL;
  183. IWbemClassObject *pInClass = NULL;
  184. IWbemClassObject *pInInst = NULL;
  185. IWbemClassObject *pOutInst = NULL;
  186. IWbemServices *pNameSpace = NULL;
  187. IEnumWbemClassObject *pRsopClass = NULL;
  188. BOOL bW2KDomain = FALSE;
  189. BOOL bLocalAccount = FALSE;
  190. WCHAR szMsgBuffer[MAX_RES_STRING] = NULL_STRING;
  191. WCHAR szMutexName[512] = MUTEX_NAME;
  192. try
  193. {
  194. if( pUserInfo == NULL || pRsopNameSpace == NULL )
  195. {
  196. // erase the last status message
  197. PrintProgressMsg( m_hOutput, NULL, m_csbi );
  198. _com_issue_error( STG_E_UNKNOWN );
  199. }
  200. PrintProgressMsg( m_hOutput, GetResString( IDS_GET_PROVIDER ), m_csbi );
  201. // Get the object for the RSOP diagnostic mode provider
  202. hResult = pRsopNameSpace->GetObject( _bstr_t( CLS_DIAGNOSTIC_PROVIDER ),
  203. 0, NULL, &pClass, NULL );
  204. CHECK_HRESULT_EX( hResult );
  205. PrintProgressMsg( m_hOutput, GetResString( IDS_GET_METHOD ), m_csbi );
  206. // get the reqd. method....create an rsop session
  207. hResult = pClass->GetMethod( _bstr_t( FN_CREATE_RSOP ), 0, &pInClass, NULL );
  208. CHECK_HRESULT_EX( hResult );
  209. // spawn the instances....get a new instance of the provider
  210. hResult = pInClass->SpawnInstance( 0, &pInInst );
  211. CHECK_HRESULT_EX( hResult );
  212. // Put the user SID...
  213. PrintProgressMsg( m_hOutput, GetResString( IDS_PUT_SID ), m_csbi );
  214. hResult = PropertyPut( pInInst, CPV_USER_SID, pUserInfo->strUserSid );
  215. CHECK_HRESULT_EX( hResult );
  216. dwFlags = FLAG_FORCE_CREATENAMESPACE;
  217. if ( m_dwScope == SCOPE_COMPUTER )
  218. {
  219. dwFlags |= FLAG_NO_USER;
  220. }
  221. else if ( m_dwScope == SCOPE_USER )
  222. {
  223. dwFlags |= FLAG_NO_COMPUTER;
  224. }
  225. hResult = PropertyPut( pInInst, CPV_FLAGS, dwFlags );
  226. CHECK_HRESULT_EX( hResult );
  227. PrintProgressMsg( m_hOutput, GetResString( IDS_WAIT ), m_csbi );
  228. // We are ready to call the method to create a session
  229. // Check on the mutex to see if the call can be executed
  230. //create the mutex
  231. StringConcat( szMutexName, L"_", SIZE_OF_ARRAY(szMutexName));
  232. strTemp = pUserInfo->strUserName;
  233. LONG lPos = strTemp.Find(TEXT_BACKSLASH);
  234. if( lPos >= 0 && lPos <= strTemp.GetLength() )
  235. {
  236. strTemp.SetAt(lPos, L'_' );
  237. }
  238. StringConcat( szMutexName, strTemp, SIZE_OF_ARRAY(szMutexName) );
  239. if( FALSE == CreateRsopMutex( szMutexName ) )
  240. {
  241. ShowMessage(stdout, GetResString(IDS_INFO) );
  242. ShowMessage(stdout, GetResString(IDS_MUTEX_FAILED));
  243. // release the interface pointers and exit
  244. SAFEIRELEASE( pRsopClass );
  245. SAFEIRELEASE( pClass );
  246. SAFEIRELEASE( pInClass );
  247. SAFEIRELEASE( pInInst );
  248. SAFEIRELEASE( pOutInst );
  249. SAFEIRELEASE( pNameSpace );
  250. return TRUE;
  251. }
  252. dwMutex = WAIT_FAILED;
  253. if( NULL == m_hMutex )
  254. {
  255. PrintProgressMsg( m_hOutput, NULL, m_csbi );
  256. ShowMessage(stdout, GetResString(IDS_INFO) );
  257. ShowMessage(stdout, GetResString(IDS_ERROR_SESSION_CONFLICT));
  258. // release the interface pointers and exit
  259. SAFEIRELEASE( pRsopClass );
  260. SAFEIRELEASE( pClass );
  261. SAFEIRELEASE( pInClass );
  262. SAFEIRELEASE( pInInst );
  263. SAFEIRELEASE( pOutInst );
  264. SAFEIRELEASE( pNameSpace );
  265. return TRUE;
  266. }
  267. if( m_hMutex != NULL )
  268. {
  269. dwMutex = WaitForSingleObject( m_hMutex, INFINITE );
  270. if( dwMutex == WAIT_FAILED )
  271. {
  272. ShowLastErrorEx( stdout, SLE_TYPE_ERROR | SLE_SYSTEM );
  273. }
  274. }
  275. retry:
  276. if( dwMutex != WAIT_FAILED )
  277. {
  278. // Print the progress message
  279. strTemp.Format( GetResString( IDS_CREATE_SESSION ), pUserInfo->strUserName );
  280. PrintProgressMsg( m_hOutput, strTemp, m_csbi );
  281. // All The required properties are set, so...execute method RSopCreateSession
  282. hResult = pRsopNameSpace->ExecMethod( _bstr_t( CLS_DIAGNOSTIC_PROVIDER ),
  283. _bstr_t( FN_CREATE_RSOP ),
  284. 0, NULL, pInInst, &pOutInst, NULL);
  285. }
  286. if( pOutInst == NULL )
  287. {
  288. hResult = E_FAIL;
  289. }
  290. if( FAILED( hResult ) )
  291. {
  292. // erase the last status message
  293. PrintProgressMsg( m_hOutput, NULL, m_csbi );
  294. // display the error message
  295. ShowMessage( stderr, GetResString( IDS_ERROR ) );
  296. ShowMessage( stderr, GetResString( IDS_METHOD_FAILED ) );
  297. // release the interface pointers and exit
  298. SAFEIRELEASE( pRsopClass );
  299. SAFEIRELEASE( pClass );
  300. SAFEIRELEASE( pInClass );
  301. SAFEIRELEASE( pInInst );
  302. SAFEIRELEASE( pOutInst );
  303. SAFEIRELEASE( pNameSpace );
  304. // Release the object
  305. ReleaseMutex( m_hMutex );
  306. return FALSE;
  307. }
  308. // Get the result value...
  309. bResult = PropertyGet( pOutInst, FPR_RETURN_VALUE, ulReturn, 0 );
  310. CHECK_BRESULT( bResult );
  311. if( ulReturn != 0 )
  312. {
  313. if ( ulReturn == WBEM_E_ACCESS_DENIED )
  314. {
  315. // check the extended error code to see why this is failed
  316. bResult = PropertyGet( pOutInst, CPV_EXTENDEDINFO, ulExtendedCode, 0 );
  317. CHECK_BRESULT( bResult );
  318. // ...
  319. if ( ulExtendedCode == RSOP_COMPUTER_ACCESS_DENIED )
  320. {
  321. if ( m_dwScope != SCOPE_COMPUTER )
  322. {
  323. hResult = PropertyPut( pInInst,
  324. CPV_FLAGS, FLAG_FORCE_CREATENAMESPACE | FLAG_NO_COMPUTER );
  325. CHECK_HRESULT_EX( hResult );
  326. // change the scope parameter accordingly
  327. m_dwScope = SCOPE_USER;
  328. // retry the creation of namespace
  329. goto retry;
  330. }
  331. }
  332. else if ( ulExtendedCode == RSOP_USER_ACCESS_DENIED )
  333. {
  334. if ( m_dwScope != SCOPE_USER )
  335. {
  336. hResult = PropertyPut( pInInst,
  337. CPV_FLAGS, FLAG_FORCE_CREATENAMESPACE | FLAG_NO_USER );
  338. CHECK_HRESULT_EX( hResult );
  339. // change the scope parameter accordingly
  340. m_dwScope = SCOPE_COMPUTER;
  341. // retry the creation of namespace
  342. goto retry;
  343. }
  344. }
  345. }
  346. // erase the last status message
  347. PrintProgressMsg( m_hOutput, NULL, m_csbi );
  348. ShowMessage( stderr, GetResString( IDS_ERROR ) );
  349. ShowMessage( stderr, GetResString( IDS_METHOD_FAILED ) );
  350. // release the interface pointers and exit
  351. SAFEIRELEASE( pRsopClass );
  352. SAFEIRELEASE( pClass );
  353. SAFEIRELEASE( pInClass );
  354. SAFEIRELEASE( pInInst );
  355. SAFEIRELEASE( pOutInst );
  356. SAFEIRELEASE( pNameSpace );
  357. // Release the object
  358. ReleaseMutex( m_hMutex );
  359. return FALSE;
  360. }
  361. // set the flag to indicate that the namespace has been created.
  362. bCreatedRsop = TRUE;
  363. // Get the resultant RSOP name space
  364. bResult = PropertyGet( pOutInst, FPR_RSOP_NAME_SPACE, strTemp, V_NOT_AVAILABLE );
  365. CHECK_BRESULT( bResult );
  366. // Check if we have got the output
  367. if( StringCompare( strTemp, V_NOT_AVAILABLE, FALSE, 0 ) == 0 )
  368. {
  369. // erase the last status message
  370. PrintProgressMsg( m_hOutput, NULL, m_csbi );
  371. ShowMessage( stderr, GetResString( IDS_ERROR ) );
  372. ShowMessage( stderr, GetResString( IDS_METHOD_FAILED ) );
  373. // release the allocated variables
  374. SAFEIRELEASE( pRsopClass );
  375. SAFEIRELEASE( pClass );
  376. SAFEIRELEASE( pInClass );
  377. SAFEIRELEASE( pInInst );
  378. SAFEIRELEASE( pOutInst );
  379. SAFEIRELEASE( pNameSpace );
  380. // Release the object
  381. ReleaseMutex( m_hMutex );
  382. return FALSE;
  383. }
  384. // Got the data so start displaying
  385. // Display the information common to both scopes
  386. DisplayCommonData( pUserInfo );
  387. // Get the string starting with 'R'...as that's where the RSOP namespace starts
  388. // This is done to remove the '\'s in the beginning of the string returned.
  389. lPos = 0;
  390. strTemp.MakeLower();
  391. lPos = strTemp.Find( START_NAMESPACE );
  392. if ( lPos != -1 )
  393. {
  394. strTemp = strTemp.Mid( lPos + 1 );
  395. }
  396. else
  397. {
  398. _com_issue_error( STG_E_UNKNOWN );
  399. }
  400. // check if the computer information has to be displayed
  401. if( (m_dwScope == SCOPE_COMPUTER) || (m_dwScope == SCOPE_ALL) )
  402. {
  403. // connect to the resultant name space (computer)
  404. strNameSpace = strTemp + TEXT_BACKSLASH + TEXT_SCOPE_COMPUTER;
  405. ConnectWmi( m_pWbemLocator, &pNameSpace, m_strServerName,
  406. m_strUserName, m_pwszPassword, &m_pAuthIdentity,
  407. FALSE, strNameSpace, &hResult );
  408. CHECK_HRESULT( hResult );
  409. // get the link speed information
  410. DisplayLinkSpeed( pNameSpace, m_pAuthIdentity );
  411. // Display the heading for the scope Computer
  412. ShowMessage( stdout, GetResString( IDS_GPO_COMPUTER ) );
  413. ShowMessage( stdout, NEW_LINE );
  414. for( dwi = StringLengthInBytes( GetResString( IDS_GPO_COMPUTER ) ); dwi > 1; dwi-- )
  415. {
  416. ShowMessage( stdout, GetResString( IDS_DASH ) );
  417. }
  418. ShowMessage( stdout, GetResString( IDS_NEWLINE_TAB ) );
  419. // Display the FQDN for the computer
  420. ShowMessage( stdout, pUserInfo->strComputerFQDN );
  421. ShowMessage( stdout, GetResString( IDS_NEWLINE_TAB ) );
  422. // Display the link speed threshold value for the computer
  423. DisplayThresholdSpeedAndLastTimeInfo( TRUE );
  424. /************this code is moved from common data to display domain name and domain type on 18-oct-2001*****************/
  425. StringCopy( szMsgBuffer, pUserInfo->strComputerDomain, MAX_RES_STRING );
  426. if( StringLengthW( szMsgBuffer,0 ) != 0 )
  427. {
  428. StringCopy( szMsgBuffer, _tcstok( szMsgBuffer, GetResString( IDS_LAST_CHAR ) ), MAX_RES_STRING );
  429. StringCopy( szMsgBuffer, _tcstok( NULL, GetResString( IDS_LAST_CHAR ) ), MAX_RES_STRING );
  430. }
  431. // Get the domain type information
  432. GetDomainType (szMsgBuffer, &bW2KDomain, &bLocalAccount);
  433. ShowMessage( stdout, GetResString( IDS_NEWLINE_TAB ) );
  434. ShowMessage( stdout, GetResString( IDS_DOMAIN_NAME ) );
  435. ShowMessage( stdout, szMsgBuffer );
  436. ShowMessage( stdout, GetResString( IDS_NEWLINE_TAB ) );
  437. ShowMessage( stdout, GetResString( IDS_DOMAIN_TYPE ) );
  438. // if it is a win2k domain type
  439. if ( bW2KDomain )
  440. {
  441. ShowMessage( stdout, GetResString( IDS_W2K_DOMAIN ) );
  442. }
  443. else
  444. {
  445. if ( bLocalAccount ) // local account
  446. {
  447. // ShowMessage( stdout, V_NOT_AVAILABLE );
  448. ShowMessage( stdout, GetResString( IDS_LOCAL_COMP ) );
  449. }
  450. else //win NT4
  451. {
  452. ShowMessage( stdout, GetResString( IDS_NT4_DOMAIN ) );
  453. }
  454. }
  455. ShowMessage( stdout, GetResString( IDS_NEWLINE ) );
  456. /*************************************************************************************************/
  457. // Display the heading for the Computer GPO's
  458. ShowMessage( stdout, GetResString( IDS_GPO_DISPLAY ) );
  459. ShowMessage( stdout, GetResString( IDS_NEWLINE_TAB ) );
  460. for( dwi = StringLengthInBytes( GetResString( IDS_GPO_DISPLAY ) ); dwi > 4; dwi-- )
  461. {
  462. ShowMessage( stdout, GetResString( IDS_DASH ) );
  463. }
  464. ShowMessage( stdout, GetResString( IDS_NEWLINE ) );
  465. // Display the GPO data for computer
  466. GpoDisplay( pNameSpace, TEXT_SCOPE_COMPUTER );
  467. // Display the security groups for the system
  468. DisplaySecurityGroups( pNameSpace, TRUE );
  469. // check wether the verbose option is specified
  470. if( m_bVerbose == TRUE || m_bSuperVerbose == TRUE )
  471. {
  472. // display the verbose computer information
  473. DisplayVerboseComputerData( pNameSpace );
  474. }
  475. // release the interface pointer
  476. SAFEIRELEASE( pNameSpace );
  477. }
  478. // check for user...
  479. if( (m_dwScope == SCOPE_USER) || (m_dwScope == SCOPE_ALL) )
  480. {
  481. // connect to the resultant name space (user)
  482. strNameSpace = strTemp + TEXT_BACKSLASH + TEXT_SCOPE_USER;
  483. ConnectWmi( m_pWbemLocator, &pNameSpace, m_strServerName,
  484. m_strUserName, m_pwszPassword, &m_pAuthIdentity,
  485. FALSE, strNameSpace, &hResult );
  486. CHECK_HRESULT( hResult );
  487. // if only the user scope has been specified then the link speed
  488. // information has not yet been displayed...display it
  489. if( m_dwScope == SCOPE_USER )
  490. {
  491. // Get the link speed information
  492. DisplayLinkSpeed( pNameSpace, m_pAuthIdentity );
  493. }
  494. // Display the heading for the scope User
  495. ShowMessage( stdout, GetResString( IDS_GPO_USER ) );
  496. ShowMessage( stdout, NEW_LINE );
  497. for( dwi = StringLengthInBytes( GetResString( IDS_GPO_USER ) ); dwi > 1; dwi-- )
  498. {
  499. ShowMessage( stdout, GetResString( IDS_DASH ) );
  500. }
  501. ShowMessage( stdout, GetResString( IDS_NEWLINE_TAB ) );
  502. // Display the FQDN for the computer
  503. ShowMessage( stdout, pUserInfo->strUserFQDN );
  504. ShowMessage( stdout, GetResString( IDS_NEWLINE_TAB ) );
  505. // Display the link speed threshold value for the user
  506. DisplayThresholdSpeedAndLastTimeInfo( FALSE );
  507. /******this code is added to display domain name and domain type for the user**************/
  508. ShowMessage( stdout, GetResString(IDS_NEWLINE) );
  509. StringCopy( szMsgBuffer, pUserInfo->strUserDomain, MAX_RES_STRING );
  510. GetDomainType (szMsgBuffer, &bW2KDomain, &bLocalAccount);
  511. ShowMessage( stdout, TAB_ONE );
  512. ShowMessage( stdout, GetResString( IDS_USER_DOMAIN_NAME ) );
  513. ShowMessage( stdout, szMsgBuffer );
  514. ShowMessage( stdout, GetResString( IDS_NEWLINE_TAB ) );
  515. ShowMessage( stdout, GetResString( IDS_USER_DOMAIN_TYPE ) );
  516. // if it is a win2k domain type
  517. if ( bW2KDomain )
  518. {
  519. ShowMessage( stdout, GetResString( IDS_W2K_DOMAIN ) );
  520. }
  521. else
  522. {
  523. if ( bLocalAccount ) // local account
  524. {
  525. // ShowMessage( stdout, V_NOT_AVAILABLE );
  526. ShowMessage( stdout, GetResString( IDS_LOCAL_COMP ) );
  527. }
  528. else //win NT4
  529. {
  530. ShowMessage( stdout, GetResString( IDS_NT4_DOMAIN ) );
  531. }
  532. }
  533. ShowMessage( stdout, GetResString( IDS_NEWLINE_TAB ) );
  534. /*****************************************************************************************/
  535. // Display the heading for the User GPO's
  536. ShowMessage( stdout, GetResString( IDS_GPO_DISPLAY ) );
  537. ShowMessage( stdout, GetResString( IDS_NEWLINE_TAB ) );
  538. for( dwi = StringLengthInBytes( GetResString( IDS_GPO_DISPLAY ) ); dwi > 4; dwi-- )
  539. {
  540. ShowMessage( stdout, GetResString( IDS_DASH ) );
  541. }
  542. ShowMessage( stdout, GetResString( IDS_NEWLINE ) );
  543. // Display the GPO data for user
  544. GpoDisplay( pNameSpace, TEXT_SCOPE_USER );
  545. // Display the security groups for the user
  546. DisplaySecurityGroups( pNameSpace, FALSE );
  547. // check wether the verbose option is specified
  548. if( m_bVerbose == TRUE || m_bSuperVerbose == TRUE )
  549. {
  550. // display the verbose computer information
  551. DisplayVerboseUserData( pUserInfo, pNameSpace );
  552. }
  553. // release the interface pointer
  554. SAFEIRELEASE( pNameSpace );
  555. }
  556. // Delete the namespace created
  557. if( RsopDeleteMethod( pClass, strTemp, pRsopNameSpace ) == FALSE )
  558. {
  559. // release the allocated variables
  560. SAFEIRELEASE( pRsopNameSpace );
  561. SAFEIRELEASE( pRsopClass );
  562. SAFEIRELEASE( pClass );
  563. SAFEIRELEASE( pInClass );
  564. SAFEIRELEASE( pInInst );
  565. SAFEIRELEASE( pOutInst );
  566. // Release the object
  567. ReleaseMutex( m_hMutex );
  568. return FALSE;
  569. }
  570. }
  571. catch( _com_error & error )
  572. {
  573. // display the error message
  574. WMISaveError( error.Error() );
  575. ShowMessage( stderr, GetResString( IDS_ERROR ) );
  576. ShowMessage( stderr, GetReason() );
  577. // Delete the name space if it has been created.
  578. if( bCreatedRsop == TRUE )
  579. {
  580. RsopDeleteMethod( pClass, strTemp, pRsopNameSpace );
  581. }
  582. // release the interface pointers and exit
  583. SAFEIRELEASE( pRsopClass );
  584. SAFEIRELEASE( pClass );
  585. SAFEIRELEASE( pInClass );
  586. SAFEIRELEASE( pInInst );
  587. SAFEIRELEASE( pOutInst );
  588. SAFEIRELEASE( pNameSpace );
  589. // Release the object
  590. ReleaseMutex( m_hMutex );
  591. return FALSE;
  592. }
  593. // release the interface pointers and exit
  594. SAFEIRELEASE( pRsopClass );
  595. SAFEIRELEASE( pClass );
  596. SAFEIRELEASE( pInClass );
  597. SAFEIRELEASE( pInInst );
  598. SAFEIRELEASE( pOutInst );
  599. SAFEIRELEASE( pNameSpace );
  600. // Release the object
  601. ReleaseMutex( m_hMutex );
  602. return TRUE;
  603. }
  604. /*********************************************************************************************
  605. Routine Description:
  606. This function gets the user data and fills the structure with the same
  607. Arguments:
  608. [in] BOOL bAllUsers : Specifies that the Rsop data has to be retrieved
  609. for all the users.
  610. Return Value:
  611. TRUE on SUCCESS
  612. FALSE on FAILURE
  613. *********************************************************************************************/
  614. BOOL CGpResult::GetUserData( BOOL bAllUsers )
  615. {
  616. // Local variables
  617. HRESULT hResult = S_OK;
  618. BOOL bResult = FALSE;
  619. BOOL bGotDomainInfo = FALSE;
  620. BOOL bConnFlag = TRUE;
  621. TCHAR szTemp[ MAX_STRING_LENGTH ];
  622. TCHAR szServer[ MAX_STRING_LENGTH ];
  623. TCHAR szName[ MAX_STRING_LENGTH ];
  624. TCHAR szDomain[ MAX_STRING_LENGTH ];
  625. TCHAR szFQDN[ MAX_STRING_LENGTH ];
  626. TCHAR szAdsiBuffer[ MAX_STRING_LENGTH ];
  627. CHString strTemp = NULL_STRING;
  628. CHString strDisplay = NULL_STRING;
  629. IEnumWbemClassObject *pEnumClass = NULL;
  630. IWbemServices *pRsopNameSpace = NULL;
  631. IWbemClassObject *pUserClass = NULL;
  632. IWbemClassObject *pInInst = NULL;
  633. IWbemClassObject *pOutInst = NULL;
  634. ULONG ulReturn = 0;
  635. LONG lCount = 0;
  636. LONG lLBound = 0;
  637. LONG lUBound = 0;
  638. DWORD dwName = MAX_STRING_LENGTH;
  639. DWORD dwDomain = MAX_STRING_LENGTH;
  640. DWORD dwBufSize = MAX_STRING_LENGTH;
  641. USERINFO *pUserInfo = new USERINFO;
  642. VARIANT vVarVerbose;
  643. VARTYPE vartype;
  644. SAFEARRAY *safeArray = NULL;
  645. PSID pSid = NULL;
  646. SID_NAME_USE *pSidNameUse = new SID_NAME_USE;
  647. try
  648. {
  649. // set the strings to NULL
  650. SecureZeroMemory( szTemp, MAX_STRING_LENGTH * sizeof( TCHAR ) );
  651. SecureZeroMemory( szName, MAX_STRING_LENGTH * sizeof( TCHAR ) );
  652. SecureZeroMemory( szServer, MAX_STRING_LENGTH * sizeof( TCHAR ) );
  653. SecureZeroMemory( szDomain, MAX_STRING_LENGTH * sizeof( TCHAR ) );
  654. SecureZeroMemory( szFQDN, MAX_STRING_LENGTH * sizeof( TCHAR ) );
  655. PrintProgressMsg( m_hOutput, GetResString( IDS_CONNECT_RSOP ), m_csbi );
  656. // connect to the RSOP namespace
  657. ConnectWmi( m_pWbemLocator, &pRsopNameSpace, m_strServerName,
  658. m_strUserName, m_pwszPassword, &m_pAuthIdentity,
  659. FALSE, _bstr_t( ROOT_RSOP ), &hResult );
  660. CHECK_HRESULT( hResult );
  661. // Get the object for the RSOP diagnostic mode provider
  662. hResult = pRsopNameSpace->GetObject( _bstr_t( CLS_DIAGNOSTIC_PROVIDER ),
  663. 0, NULL, &pUserClass, NULL );
  664. CHECK_HRESULT( hResult );
  665. PrintProgressMsg( m_hOutput, GetResString( IDS_GET_METHOD ), m_csbi );
  666. // get the reqd. method....to enumerate the users
  667. hResult = pUserClass->GetMethod( _bstr_t( FN_ENUM_USERS ), 0, &pInInst, NULL );
  668. CHECK_HRESULT( hResult );
  669. PrintProgressMsg( m_hOutput, GetResString( IDS_GET_SID ), m_csbi );
  670. // Execute method RSopEnumerateUsers
  671. hResult = pRsopNameSpace->ExecMethod( _bstr_t( CLS_DIAGNOSTIC_PROVIDER ),
  672. _bstr_t( FN_ENUM_USERS ),
  673. 0, NULL, pInInst, &pOutInst, NULL);
  674. if( pOutInst == NULL )
  675. {
  676. hResult = E_FAIL;
  677. }
  678. if( FAILED( hResult ) )
  679. {
  680. // erase the last status message
  681. PrintProgressMsg( m_hOutput, NULL, m_csbi );
  682. ShowMessage( stderr, GetResString( IDS_ERROR ) );
  683. ShowMessage( stderr, GetResString( IDS_METHOD_FAILED ) );
  684. // release the interface pointers and exit
  685. SAFEIRELEASE( pRsopNameSpace );
  686. SAFEIRELEASE( pUserClass );
  687. SAFEIRELEASE( pInInst );
  688. SAFEIRELEASE( pOutInst );
  689. SAFEIRELEASE( pEnumClass );
  690. SAFE_DELETE( pUserInfo );
  691. SAFE_DELETE( pSidNameUse );
  692. return FALSE;
  693. }
  694. // Get the result value...
  695. bResult = PropertyGet( pOutInst, FPR_RETURN_VALUE, ulReturn, 0 );
  696. CHECK_BRESULT( bResult );
  697. if( ulReturn != 0 )
  698. {
  699. // erase the last status message
  700. PrintProgressMsg( m_hOutput, NULL, m_csbi );
  701. ShowMessage( stderr, GetResString( IDS_ERROR ) );
  702. ShowMessage( stderr, GetResString( IDS_METHOD_FAILED ) );
  703. // release the interface pointers and exit
  704. SAFEIRELEASE( pRsopNameSpace );
  705. SAFEIRELEASE( pUserClass );
  706. SAFEIRELEASE( pInInst );
  707. SAFEIRELEASE( pOutInst );
  708. SAFEIRELEASE( pEnumClass );
  709. SAFE_DELETE( pUserInfo );
  710. SAFE_DELETE( pSidNameUse );
  711. return FALSE;
  712. }
  713. VariantInit( &vVarVerbose );
  714. pOutInst->Get( _bstr_t( CPV_USER_SIDS ), 0, &vVarVerbose, 0, 0 );
  715. CHECK_HRESULT_VAR( hResult, vVarVerbose );
  716. if( vVarVerbose.vt != VT_NULL && vVarVerbose.vt != VT_EMPTY )
  717. {
  718. // get the type of the elements in the safe array
  719. vartype = (VARTYPE)(V_VT( &vVarVerbose ) & ~VT_ARRAY);
  720. //get the array of strings in to the safe array from the variant
  721. safeArray = (SAFEARRAY *)vVarVerbose.parray;
  722. //get the number of elements (subkeys)
  723. if( safeArray != NULL )
  724. {
  725. hResult = SafeArrayGetLBound( safeArray, 1, &lLBound );
  726. CHECK_HRESULT( hResult );
  727. hResult = SafeArrayGetUBound( safeArray, 1, &lUBound );
  728. CHECK_HRESULT( hResult );
  729. if( lUBound == 0xffffffff )
  730. {
  731. // erase the last status message
  732. PrintProgressMsg( m_hOutput, NULL, m_csbi );
  733. ShowMessage( stdout, GetResString( IDS_INFO) );
  734. ShowMessageEx( stdout, 1, TRUE, GetResString( IDS_USER_NO_RSOP1) );
  735. // release the interface pointers and exit
  736. SAFEIRELEASE( pRsopNameSpace );
  737. SAFEIRELEASE( pUserClass );
  738. SAFEIRELEASE( pInInst );
  739. SAFEIRELEASE( pOutInst );
  740. SAFEIRELEASE( pEnumClass );
  741. SAFE_DELETE( pUserInfo );
  742. SAFE_DELETE( pSidNameUse );
  743. return TRUE;
  744. }
  745. }
  746. // If we have to get the information from a remote machine then...
  747. // connect to the remote machine.
  748. if ( m_bLocalSystem == FALSE )
  749. {
  750. StringCopy( szServer, m_strServerName, MAX_STRING_LENGTH );
  751. StringCopy( szName, m_strUserName, MAX_STRING_LENGTH );
  752. // erase the last status message
  753. PrintProgressMsg( m_hOutput, NULL, m_csbi );
  754. bResult = EstablishConnection( szServer, szName, MAX_STRING_LENGTH,
  755. m_pwszPassword, MAX_STRING_LENGTH, FALSE );
  756. if( bResult != TRUE )
  757. {
  758. // erase the last status message
  759. PrintProgressMsg( m_hOutput, NULL, m_csbi );
  760. ShowMessage( stderr, GetResString( IDS_ERROR ) );
  761. ShowMessage( stderr, GetReason() );
  762. // release the interface pointers and exit
  763. SAFEIRELEASE( pRsopNameSpace );
  764. SAFEIRELEASE( pUserClass );
  765. SAFEIRELEASE( pInInst );
  766. SAFEIRELEASE( pOutInst );
  767. SAFEIRELEASE( pEnumClass );
  768. SAFE_DELETE( pUserInfo );
  769. SAFE_DELETE( pSidNameUse );
  770. return FALSE;
  771. }
  772. else
  773. {
  774. switch( GetLastError() )
  775. {
  776. case I_NO_CLOSE_CONNECTION:
  777. bConnFlag = FALSE;
  778. break;
  779. case E_LOCAL_CREDENTIALS:
  780. case ERROR_SESSION_CREDENTIAL_CONFLICT:
  781. bConnFlag = FALSE;
  782. break;
  783. default:
  784. break;
  785. }
  786. }
  787. // Get the new output co-ordinates
  788. if ( m_hOutput != NULL )
  789. {
  790. GetConsoleScreenBufferInfo( m_hOutput, &m_csbi );
  791. }
  792. }
  793. for( lCount = lLBound ; lLBound <= lUBound; lLBound++ )
  794. {
  795. bResult = GetPropertyFromSafeArray( safeArray, lLBound, strTemp, vartype );
  796. CHECK_BRESULT( bResult );
  797. // Got the SID...save it in the structure
  798. pUserInfo->strUserSid = strTemp;
  799. PrintProgressMsg( m_hOutput, GetResString( IDS_GET_NAME ), m_csbi );
  800. // Get the User Name
  801. StringCopy( szTemp, strTemp, MAX_STRING_LENGTH );
  802. ConvertStringSidToSid( szTemp, &pSid );
  803. // Get the user name for the SID we have got
  804. bResult = LookupAccountSid( szServer, pSid, szName, &dwName, szDomain,
  805. &dwDomain, pSidNameUse );
  806. if( bResult == 0 )
  807. {
  808. // Could not get the name from the API try to retrieve it from WMI
  809. bResult = GetUserNameFromWMI( szTemp, szName, szDomain );
  810. PrintProgressMsg( m_hOutput, NULL, m_csbi );
  811. if( bResult == FALSE )
  812. {
  813. // Increment the count
  814. lCount++;
  815. // If the user was not found then display a message stating the same
  816. if( lCount > lUBound )
  817. {
  818. strTemp = L"";
  819. if( bAllUsers == FALSE )
  820. {
  821. // check if we need to append the domain name
  822. if ( m_strDomainName.GetLength() != 0 )
  823. {
  824. strTemp = m_strDomainName + _T( "\\" ) + m_strUser;
  825. }
  826. else
  827. {
  828. strTemp = m_strUser;
  829. }
  830. }
  831. // Form the display string
  832. strDisplay.Format( GetResString( IDS_USER_NO_RSOP ), _X( strTemp ) );
  833. ShowMessage( stdout, GetResString( IDS_INFO ) );
  834. ShowMessage( stdout, strDisplay );
  835. }
  836. // could not get a name for this SID, so continue with the next SID.
  837. continue;
  838. }
  839. }
  840. // Free the pSid
  841. if( pSid != NULL )
  842. {
  843. LocalFree( pSid );
  844. pSid = NULL;
  845. }
  846. // Check wether the Rsop data has to be retrieved for this user name.
  847. if( bAllUsers == FALSE )
  848. {
  849. if( StringCompare( szName, m_strUser, TRUE, 0 ) != 0
  850. || ( StringCompare( szDomain, m_strDomainName, TRUE, 0 ) != 0
  851. && m_strDomainName.GetLength() != 0 ) )
  852. {
  853. // erase the last status message
  854. PrintProgressMsg( m_hOutput, NULL, m_csbi );
  855. // re-set the buffer sizes
  856. dwName = MAX_STRING_LENGTH;
  857. dwDomain = MAX_STRING_LENGTH;
  858. // Increment the count
  859. lCount++;
  860. // If the user was not found then display a message stating the same
  861. if( lCount > lUBound )
  862. {
  863. // check if we need to append the domain name
  864. if ( m_strDomainName.GetLength() != 0 )
  865. {
  866. strTemp = m_strDomainName + _T( "\\" ) + m_strUser;
  867. }
  868. else
  869. {
  870. strTemp = m_strUser;
  871. }
  872. // Form the display string
  873. strDisplay.Format( GetResString( IDS_USER_NO_RSOP ), _X( strTemp ) );
  874. ShowMessage( stdout, GetResString( IDS_INFO ) );
  875. ShowMessage( stdout, strDisplay );
  876. }
  877. // No need to get the data for this user
  878. continue;
  879. }
  880. }
  881. // Store the user name into the structure.
  882. pUserInfo->strUserName = szName;
  883. // Append the domain name to the user name.
  884. StringConcat( szDomain, TEXT_BACKSLASH, MAX_STRING_LENGTH );
  885. StringConcat( szDomain, pUserInfo->strUserName, MAX_STRING_LENGTH );
  886. pUserInfo->strUserName = szDomain;
  887. PrintProgressMsg( m_hOutput, GetResString( IDS_GET_PROFILE ), m_csbi );
  888. // Get the user profile information
  889. if( GetUserProfile( pUserInfo ) == FALSE )
  890. {
  891. // erase the last status message
  892. PrintProgressMsg( m_hOutput, NULL, m_csbi );
  893. // Display the error message
  894. ShowMessage( stderr, GetResString( IDS_ERROR ) );
  895. ShowMessage( stderr, GetResString( IDS_METHOD_FAILED ) );
  896. // release the interface pointers and exit
  897. SAFEIRELEASE( pRsopNameSpace );
  898. SAFEIRELEASE( pUserClass );
  899. SAFEIRELEASE( pInInst );
  900. SAFEIRELEASE( pOutInst );
  901. SAFEIRELEASE( pEnumClass );
  902. SAFE_DELETE( pUserInfo );
  903. SAFE_DELETE( pSidNameUse );
  904. // if we have opened a connection then close the same.
  905. if( m_bLocalSystem == FALSE && bConnFlag == TRUE )
  906. {
  907. StringCopy( szServer, m_strServerName, MAX_STRING_LENGTH );
  908. CloseConnection( szServer );
  909. }
  910. return FALSE;
  911. }
  912. if( bGotDomainInfo == FALSE )
  913. {
  914. PrintProgressMsg( m_hOutput, GetResString( IDS_GET_COMMON ), m_csbi );
  915. // Get the domain name and other related information
  916. if( GetDomainInfo( pUserInfo ) == FALSE )
  917. {
  918. // erase the last status message
  919. PrintProgressMsg( m_hOutput, NULL, m_csbi );
  920. // Display the error message
  921. ShowMessage( stderr, GetResString( IDS_ERROR ) );
  922. ShowMessage( stderr, GetResString( IDS_METHOD_FAILED ) );
  923. // release the interface pointers and exit
  924. SAFEIRELEASE( pRsopNameSpace );
  925. SAFEIRELEASE( pUserClass );
  926. SAFEIRELEASE( pInInst );
  927. SAFEIRELEASE( pOutInst );
  928. SAFEIRELEASE( pEnumClass );
  929. SAFE_DELETE( pUserInfo );
  930. SAFE_DELETE( pSidNameUse );
  931. // if we have opened a connection then close the same.
  932. if( m_bLocalSystem == FALSE && bConnFlag == TRUE )
  933. {
  934. StringCopy( szServer, m_strServerName, MAX_STRING_LENGTH );
  935. CloseConnection( szServer );
  936. }
  937. return FALSE;
  938. }
  939. // Get the OS information
  940. if( GetOsInfo( pUserInfo ) == FALSE )
  941. {
  942. // erase the last status message
  943. PrintProgressMsg( m_hOutput, NULL, m_csbi );
  944. // Display the error message
  945. ShowMessage( stderr, GetResString( IDS_ERROR ) );
  946. ShowMessage( stderr, GetResString( IDS_METHOD_FAILED ) );
  947. // release the interface pointers and exit
  948. SAFEIRELEASE( pRsopNameSpace );
  949. SAFEIRELEASE( pUserClass );
  950. SAFEIRELEASE( pInInst );
  951. SAFEIRELEASE( pOutInst );
  952. SAFEIRELEASE( pEnumClass );
  953. SAFE_DELETE( pUserInfo );
  954. SAFE_DELETE( pSidNameUse );
  955. // if we have opened a connection then close the same.
  956. if( m_bLocalSystem == FALSE && bConnFlag == TRUE )
  957. {
  958. StringCopy( szServer, m_strServerName, MAX_STRING_LENGTH );
  959. CloseConnection( szServer );
  960. }
  961. return FALSE;
  962. }
  963. // Get the FQDN of the computer
  964. // PrintProgressMsg( m_hOutput, GetResString( IDS_GET_FQDN ), m_csbi );
  965. if( m_bLocalSystem == TRUE )
  966. {
  967. // we have to get the FQDN for the local system
  968. // use the GetComputerObjectName API
  969. ulReturn = MAX_STRING_LENGTH;
  970. GetComputerObjectName( NameFullyQualifiedDN, szFQDN, &ulReturn);
  971. }
  972. else
  973. {
  974. // Get the local computers domain name
  975. GetComputerNameEx( ComputerNameDnsDomain, szAdsiBuffer, &dwBufSize );
  976. StringCopy( szServer, m_strADSIServer, MAX_STRING_LENGTH );
  977. StringConcat( szServer, TEXT_DOLLAR, MAX_STRING_LENGTH );
  978. // Check if the machine we are querying is in the same domain
  979. if( m_strADSIDomain.CompareNoCase( szAdsiBuffer ) == 0 )
  980. {
  981. // get the FQDN from the Translate name call
  982. dwBufSize = MAX_STRING_LENGTH;
  983. TranslateName( szServer, NameDisplay, NameFullyQualifiedDN,
  984. szFQDN, &dwBufSize );
  985. }
  986. else
  987. {
  988. // Get the FQDN from ADSI directory services
  989. GetFQDNFromADSI( szFQDN, TRUE, szServer );
  990. }
  991. }
  992. // Store the FQDN into the structure.
  993. pUserInfo->strComputerFQDN = szFQDN;
  994. // Set the flag to TRUE so that this code is not executed again and again
  995. bGotDomainInfo = TRUE;
  996. }
  997. // Get the FQDN of the user
  998. if( ( m_bLocalSystem == TRUE )
  999. || ( m_strADSIDomain.CompareNoCase( szAdsiBuffer ) == 0 ) )
  1000. {
  1001. SecureZeroMemory( szFQDN, MAX_STRING_LENGTH * sizeof( TCHAR ) );
  1002. dwBufSize = MAX_STRING_LENGTH;
  1003. StringCopy( szName, pUserInfo->strUserName, MAX_STRING_LENGTH );
  1004. // get the FQDN from the Translate name call
  1005. TranslateName( szName, NameSamCompatible, NameFullyQualifiedDN,
  1006. szFQDN, &dwBufSize );
  1007. }
  1008. else
  1009. {
  1010. // Get the FQDN from ADSI directory services
  1011. StringCopy( szName, pUserInfo->strUserName, MAX_STRING_LENGTH );
  1012. GetFQDNFromADSI( szFQDN, FALSE, szName );
  1013. }
  1014. // Store the FQDN into the structure.
  1015. pUserInfo->strUserFQDN = szFQDN;
  1016. //get the terminal server mode
  1017. GetTerminalServerMode(pUserInfo);
  1018. // Now display the data
  1019. PrintProgressMsg( m_hOutput, GetResString( IDS_STARTED_RETRIEVAL ), m_csbi );
  1020. if( FALSE == DisplayData( pUserInfo, pRsopNameSpace ) )
  1021. {
  1022. // release the interface pointers and exit
  1023. SAFEIRELEASE( pRsopNameSpace );
  1024. SAFEIRELEASE( pUserClass );
  1025. SAFEIRELEASE( pInInst );
  1026. SAFEIRELEASE( pOutInst );
  1027. SAFEIRELEASE( pEnumClass );
  1028. SAFE_DELETE( pUserInfo );
  1029. SAFE_DELETE( pSidNameUse );
  1030. return FALSE;
  1031. }
  1032. // Get the new output co-ordinates
  1033. if ( m_hOutput != NULL )
  1034. {
  1035. GetConsoleScreenBufferInfo( m_hOutput, &m_csbi );
  1036. }
  1037. // re-set the buffers and their sizes
  1038. SecureZeroMemory( szTemp, MAX_STRING_LENGTH * sizeof( TCHAR ) );
  1039. SecureZeroMemory( szName, MAX_STRING_LENGTH * sizeof( TCHAR ) );
  1040. SecureZeroMemory( szServer, MAX_STRING_LENGTH * sizeof( TCHAR ) );
  1041. SecureZeroMemory( szDomain, MAX_STRING_LENGTH * sizeof( TCHAR ) );
  1042. dwName = MAX_STRING_LENGTH;
  1043. dwDomain = MAX_STRING_LENGTH;
  1044. }// for
  1045. // if we have opened a connection then close the same.
  1046. if( m_bLocalSystem == FALSE && bConnFlag == TRUE )
  1047. {
  1048. StringCopy( szServer, m_strServerName, MAX_STRING_LENGTH );
  1049. CloseConnection( szServer );
  1050. }
  1051. }
  1052. else
  1053. {
  1054. // No classes were retrieved....display msg
  1055. // erase the last status message
  1056. PrintProgressMsg( m_hOutput, NULL, m_csbi );
  1057. // check if we need to append the domain name
  1058. if ( m_strDomainName.GetLength() != 0 )
  1059. {
  1060. strTemp = m_strDomainName + _T( "\\" ) + m_strUser;
  1061. }
  1062. else
  1063. {
  1064. strTemp = m_strUser;
  1065. }
  1066. // Form the display string
  1067. strDisplay.Format( GetResString( IDS_USER_NO_RSOP ), _X( strTemp ) );
  1068. ShowMessage( stdout, GetResString( IDS_INFO ) );
  1069. ShowMessage( stdout, strDisplay );
  1070. }
  1071. VariantClear(&vVarVerbose);
  1072. }
  1073. catch( _com_error & error )
  1074. {
  1075. // erase the last status message
  1076. PrintProgressMsg( m_hOutput, NULL, m_csbi );
  1077. // display the error msg
  1078. WMISaveError( error.Error() );
  1079. ShowMessage( stderr, GetResString( IDS_ERROR ) );
  1080. ShowMessage( stderr, GetReason() );
  1081. // release the interface pointers and exit
  1082. SAFEIRELEASE( pRsopNameSpace );
  1083. SAFEIRELEASE( pUserClass );
  1084. SAFEIRELEASE( pInInst );
  1085. SAFEIRELEASE( pOutInst );
  1086. SAFEIRELEASE( pEnumClass );
  1087. SAFE_DELETE( pUserInfo );
  1088. SAFE_DELETE( pSidNameUse );
  1089. VariantClear(&vVarVerbose);
  1090. return FALSE;
  1091. }
  1092. // release the interface pointers and exit
  1093. SAFEIRELEASE( pRsopNameSpace );
  1094. SAFEIRELEASE( pUserClass );
  1095. SAFEIRELEASE( pInInst );
  1096. SAFEIRELEASE( pOutInst );
  1097. SAFEIRELEASE( pEnumClass );
  1098. SAFE_DELETE( pUserInfo );
  1099. SAFE_DELETE( pSidNameUse );
  1100. VariantClear(&vVarVerbose);
  1101. return TRUE;
  1102. }
  1103. /*********************************************************************************************
  1104. Routine Description:
  1105. This function gets the user profile data and fills the array with the same
  1106. Arguments:
  1107. [in] PUSERINFO pUserInfo : Structure containing the user information.
  1108. Return Value:
  1109. TRUE on SUCCESS
  1110. FALSE on FAILURE
  1111. *********************************************************************************************/
  1112. BOOL CGpResult::GetUserProfile( PUSERINFO pUserInfo )
  1113. {
  1114. // Local variables
  1115. HRESULT hResult = S_OK;
  1116. IWbemServices *pDefaultNameSpace = NULL;
  1117. TCHAR szTemp[ MAX_STRING_LENGTH ];
  1118. try
  1119. {
  1120. // connect to the default namespace
  1121. ConnectWmi( m_pWbemLocator, &pDefaultNameSpace, m_strServerName,
  1122. m_strUserName, m_pwszPassword, &m_pAuthIdentity,
  1123. FALSE, _bstr_t( ROOT_DEFAULT ), &hResult );
  1124. CHECK_HRESULT( hResult );
  1125. // Set the sub key name
  1126. StringCopy( szTemp, PATH, MAX_STRING_LENGTH );
  1127. StringConcat( szTemp, pUserInfo->strUserSid, MAX_STRING_LENGTH );
  1128. // Get the local profile
  1129. RegQueryValueWMI( pDefaultNameSpace, HKEY_DEF, szTemp, FPR_LOCAL_VALUE,
  1130. pUserInfo->strLocalProfile, V_NOT_AVAILABLE );
  1131. // Get the roaming profile
  1132. RegQueryValueWMI( pDefaultNameSpace, HKEY_DEF, szTemp, FPR_ROAMING_VALUE,
  1133. pUserInfo->strRoamingProfile, V_NOT_AVAILABLE );
  1134. }
  1135. catch( _com_error & error )
  1136. {
  1137. WMISaveError( error.Error() );
  1138. ShowMessage( stderr, GetResString( IDS_ERROR ) );
  1139. ShowMessage( stderr, GetReason() );
  1140. // release the allocated variables
  1141. SAFEIRELEASE( pDefaultNameSpace );
  1142. return FALSE;
  1143. }
  1144. // release the interface pointer
  1145. SAFEIRELEASE( pDefaultNameSpace );
  1146. return TRUE;
  1147. }
  1148. /*********************************************************************************************
  1149. Routine Description:
  1150. This function gets the domain information and fills the array with the same
  1151. Arguments:
  1152. [in] PUSERINFO pUserInfo : Structure containing the user information.
  1153. Return Value:
  1154. TRUE on SUCCESS
  1155. FALSE on FAILURE
  1156. *********************************************************************************************/
  1157. BOOL CGpResult::GetDomainInfo( PUSERINFO pUserInfo )
  1158. {
  1159. // Local variables
  1160. HRESULT hResult = S_OK;
  1161. BOOL bResult = FALSE;
  1162. BOOL bDone = FALSE;
  1163. IEnumWbemClassObject *pEnumClass = NULL;
  1164. IWbemClassObject *pClass = NULL;
  1165. ULONG ulReturn = 0;
  1166. CHString strTemp;
  1167. PSID psid = NULL;
  1168. SID_NAME_USE sidNameUse;
  1169. WCHAR szTemp[MAX_RES_STRING]=NULL_STRING;
  1170. DWORD dwSize=MAX_RES_STRING;
  1171. DWORD dwSidSize=0;
  1172. try
  1173. {
  1174. // print the progress message
  1175. PrintProgressMsg( m_hOutput, GetResString( IDS_GET_DOMAIN ), m_csbi );
  1176. // Enumerate the instances to get the domain and site names of the Win32 NT domain
  1177. hResult = m_pWbemServices->CreateInstanceEnum( _bstr_t( CLS_WIN32_SITE ),
  1178. WBEM_FLAG_FORWARD_ONLY |
  1179. WBEM_FLAG_RETURN_IMMEDIATELY,
  1180. NULL, &pEnumClass );
  1181. CHECK_HRESULT( hResult );
  1182. // Set the interface security
  1183. hResult = SetInterfaceSecurity( pEnumClass, m_pAuthIdentity );
  1184. CHECK_HRESULT( hResult );
  1185. // get the data
  1186. // since there may be more than one instance and we are looking for the instance
  1187. // with the domain controller and site name.....using a while loop and as soon as
  1188. // we get the instance we need break out of it
  1189. hResult = WBEM_S_NO_ERROR;
  1190. while( hResult == WBEM_S_NO_ERROR )
  1191. {
  1192. hResult = pEnumClass->Next( WBEM_INFINITE, 1, &pClass, &ulReturn );
  1193. CHECK_HRESULT( hResult );
  1194. if( ulReturn == 0 )
  1195. {
  1196. // no more data so break out of the loop
  1197. break;
  1198. }
  1199. // get the server name
  1200. if( bDone == FALSE )
  1201. {
  1202. bDone = TRUE;
  1203. bResult = PropertyGet( pClass, CPV_GPO_SERVER, pUserInfo->strUserServer,
  1204. V_NOT_AVAILABLE );
  1205. CHECK_BRESULT( bResult );
  1206. }
  1207. // get the domain name
  1208. bResult = PropertyGet( pClass, CPV_GPO_NAME, pUserInfo->strComputerDomain,
  1209. V_NOT_AVAILABLE );
  1210. CHECK_BRESULT( bResult );
  1211. PrintProgressMsg( m_hOutput, GetResString( IDS_GET_SITE ), m_csbi );
  1212. // get the site name
  1213. bResult = PropertyGet( pClass, CPV_SITE_NAME, pUserInfo->strUserSite,
  1214. V_NOT_AVAILABLE );
  1215. CHECK_BRESULT( bResult );
  1216. // get the domain controller name
  1217. bResult = PropertyGet( pClass, CPV_DC_NAME, strTemp, V_NOT_AVAILABLE );
  1218. CHECK_BRESULT( bResult );
  1219. if( StringCompare( strTemp, V_NOT_AVAILABLE, FALSE, 0 ) != 0 )
  1220. {
  1221. // this enumeration has the domain controller name...
  1222. // we have got the enumeration we need so get the other data
  1223. break;
  1224. }
  1225. }// while
  1226. /************this code is added to get the user domain on 19-oct-2001 **************/
  1227. psid = NULL;
  1228. dwSidSize = 0;
  1229. // get the actual size of SID
  1230. if ( FALSE == LookupAccountName( m_strServerName, pUserInfo->strUserName, psid, &dwSidSize, szTemp, &dwSize, &sidNameUse ) )
  1231. {
  1232. if ( GetLastError() != ERROR_INSUFFICIENT_BUFFER )
  1233. {
  1234. SaveLastError();
  1235. ShowLastErrorEx( stderr, SLE_TYPE_ERROR | SLE_INTERNAL );
  1236. SAFEIRELEASE( pClass );
  1237. SAFEIRELEASE( pEnumClass );
  1238. return FALSE;
  1239. }
  1240. }
  1241. //Allocate memory for SID with the actual size of dwSidSize
  1242. psid = (PSID) AllocateMemory( dwSidSize );
  1243. if( NULL == psid )
  1244. {
  1245. SaveLastError();
  1246. ShowLastErrorEx( stderr, SLE_TYPE_ERROR | SLE_INTERNAL );
  1247. SAFEIRELEASE( pClass );
  1248. SAFEIRELEASE( pEnumClass );
  1249. return FALSE;
  1250. }
  1251. // Get the account name
  1252. if( FALSE == LookupAccountName( m_strServerName, pUserInfo->strUserName, psid, &dwSidSize, szTemp, &dwSize, &sidNameUse ) )
  1253. {
  1254. DISPLAY_MESSAGE( stderr, GetResString(IDS_ERROR) );
  1255. DISPLAY_MESSAGE( stderr, GetReason() );
  1256. FreeMemory((LPVOID*) &psid);
  1257. SAFEIRELEASE( pClass );
  1258. SAFEIRELEASE( pEnumClass );
  1259. return FALSE;
  1260. }
  1261. pUserInfo->strUserDomain = szTemp;
  1262. //release memory
  1263. FreeMemory((LPVOID*) &psid);
  1264. /**********************************************************************************/
  1265. } //try
  1266. catch( _com_error & error )
  1267. {
  1268. // erase the last status message
  1269. PrintProgressMsg( m_hOutput, NULL, m_csbi );
  1270. WMISaveError( error.Error() );
  1271. ShowMessage( stderr, GetResString( IDS_ERROR ) );
  1272. ShowMessage( stderr, GetReason() );
  1273. //release memory
  1274. FreeMemory((LPVOID*) &psid);
  1275. // release the allocated variables
  1276. SAFEIRELEASE( pEnumClass );
  1277. SAFEIRELEASE( pClass );
  1278. return FALSE;
  1279. }
  1280. // release the interface pointers
  1281. SAFEIRELEASE( pEnumClass );
  1282. SAFEIRELEASE( pClass );
  1283. return TRUE;
  1284. }
  1285. /*********************************************************************************************
  1286. Routine Description:
  1287. This function returns the domain type
  1288. Arguments:
  1289. [in] lpDomainName : domain name intends to view Rsop data.
  1290. [out] pbW2K : contain whether the domain type in W2K.
  1291. [out] pbLocalAccount : contain whether the account is local.
  1292. Return Value:
  1293. TRUE - if DC found/domain name is computer name
  1294. FALSE - if DC not found
  1295. *********************************************************************************************/
  1296. BOOL GetDomainType( LPTSTR lpszDomainName, BOOL * pbW2K, BOOL *pbLocalAccount )
  1297. {
  1298. PDOMAIN_CONTROLLER_INFO pDCI;
  1299. DWORD dwResult = 0;
  1300. DWORD dwSize = 0;
  1301. TCHAR szComputerName[ MAX_PATH ];
  1302. // Check the incoming pointers
  1303. if( lpszDomainName == NULL || pbW2K == NULL || pbLocalAccount == NULL )
  1304. {
  1305. return FALSE;
  1306. }
  1307. // Check this domain for a Domain Controller
  1308. dwResult = DsGetDcName( NULL, lpszDomainName, NULL, NULL,
  1309. DS_DIRECTORY_SERVICE_PREFERRED, &pDCI );
  1310. if ( dwResult == NO_ERROR )
  1311. {
  1312. // Found a DC, does it have a DS ?
  1313. if ( pDCI->Flags & DS_DS_FLAG )
  1314. {
  1315. *pbW2K = TRUE;
  1316. }
  1317. NetApiBufferFree( pDCI );
  1318. return TRUE;
  1319. }
  1320. // Check if the domain name is also the computer name (eg: local account)
  1321. dwSize = ARRAYSIZE( szComputerName );
  1322. if ( GetComputerName ( szComputerName, &dwSize ) != 0 )
  1323. {
  1324. if ( StringCompare( szComputerName, lpszDomainName, TRUE, 0 ) == 0 )
  1325. {
  1326. *pbLocalAccount = TRUE;
  1327. return TRUE;
  1328. }
  1329. }
  1330. return FALSE;
  1331. }
  1332. /*********************************************************************************************
  1333. Routine Description:
  1334. This function displays the data common to both scopes
  1335. Arguments:
  1336. [in] PUSERINFO pUserInfo : Structure containing the user information.
  1337. Return Value:
  1338. TRUE on SUCCESS
  1339. FALSE on FAILURE
  1340. *********************************************************************************************/
  1341. BOOL CGpResult::DisplayCommonData( PUSERINFO pUserInfo )
  1342. {
  1343. // Local variables
  1344. TCHAR szMsgBuffer[ MAX_RES_STRING ];
  1345. TCHAR szDate[ MAX_RES_STRING ];
  1346. TCHAR szTime[ MAX_RES_STRING ];
  1347. BOOL bLocaleChanged = FALSE;
  1348. DWORD dwLength = 0;
  1349. SYSTEMTIME systime;
  1350. LCID lcid;
  1351. // erase the last status message
  1352. PrintProgressMsg( m_hOutput, NULL, m_csbi );
  1353. // Clear the Msg buffer
  1354. SecureZeroMemory( szMsgBuffer, MAX_RES_STRING );
  1355. // Start displaying the output
  1356. ShowMessage( stdout, NEW_LINE );
  1357. // Print the leagal information
  1358. ShowMessage( stdout, GetResString( IDS_LEGAL_INFO1 ) );
  1359. ShowMessage( stdout, GetResString( IDS_LEGAL_INFO2 ) );
  1360. // Print the date and time this report is generated
  1361. GetLocalTime( &systime );
  1362. // verify whether console supports the current locale 100% or not
  1363. lcid = GetSupportedUserLocale( &bLocaleChanged );
  1364. // get the formatted date
  1365. GetDateFormat( lcid, 0, &systime, ((bLocaleChanged == TRUE) ? L"MM/dd/yyyy" : NULL),
  1366. szDate, SIZE_OF_ARRAY( szDate ) );
  1367. // now format the date
  1368. GetTimeFormat( LOCALE_USER_DEFAULT, 0, &systime, ((bLocaleChanged == TRUE) ? L"HH:mm:ss" : NULL),
  1369. szTime, SIZE_OF_ARRAY( szTime ) );
  1370. ShowMessageEx( stdout, 2, TRUE, GetResString( IDS_CREATED_ON ), _X(szDate), _X1(szTime) );
  1371. ShowMessage( stdout, NEW_LINE );
  1372. // Display the common information....Domain Info
  1373. ShowMessageEx( stdout, 2, TRUE, GetResString( IDS_GPO_TITLE ), _X( pUserInfo->strUserName ), _X2( pUserInfo->strUserServer ) );
  1374. ShowMessage( stdout, NEW_LINE );
  1375. StringCchPrintf( szMsgBuffer, SIZE_OF_ARRAY( szMsgBuffer ), GetResString( IDS_GPO_TITLE ), _X( pUserInfo->strUserName ), _X2( pUserInfo->strUserServer ) );
  1376. // Underline the above heading
  1377. dwLength = StringLengthInBytes( szMsgBuffer );
  1378. for( ; dwLength > 0; dwLength-- )
  1379. {
  1380. ShowMessage( stdout, GetResString( IDS_DASH ) );
  1381. }
  1382. ShowMessage( stdout, NEW_LINE );
  1383. StringCopy( szMsgBuffer, pUserInfo->strComputerDomain, MAX_RES_STRING );
  1384. if( StringLengthW( szMsgBuffer, 0 ) != 0 )
  1385. {
  1386. StringCopy( szMsgBuffer, _tcstok( szMsgBuffer, GetResString( IDS_LAST_CHAR ) ), MAX_RES_STRING );
  1387. StringCopy( szMsgBuffer, _tcstok( NULL, GetResString( IDS_LAST_CHAR ) ), MAX_RES_STRING );
  1388. }
  1389. // Show the OS information
  1390. ShowMessage( stdout, GetResString( IDS_OS_TYPE ) );
  1391. ShowMessage( stdout, pUserInfo->strOsType );
  1392. ShowMessage( stdout, GetResString( IDS_OS_CONFIG ) );
  1393. ShowMessage( stdout, pUserInfo->strOsConfig );
  1394. ShowMessage( stdout, GetResString( IDS_OS_VERSION ) );
  1395. ShowMessage( stdout, pUserInfo->strOsVersion );
  1396. // This code is added on 4-sep-2001 to display Terminal server mode
  1397. ShowMessage( stdout, NEW_LINE );
  1398. ShowMessage( stdout, GetResString( IDS_TERMINAL_SERVER_MODE ) );
  1399. ShowMessage( stdout, pUserInfo->strTerminalServerMode );
  1400. // Display the Site name
  1401. ShowMessage( stdout, NEW_LINE );
  1402. ShowMessage( stdout, GetResString( IDS_SITE_NAME ) );
  1403. ShowMessage( stdout, pUserInfo->strUserSite );
  1404. // Display the roaming profile
  1405. ShowMessage( stdout, NEW_LINE );
  1406. ShowMessage( stdout, GetResString( IDS_ROAMING_PROFILE ) );
  1407. ShowMessage( stdout, pUserInfo->strRoamingProfile );
  1408. // Display the local profile
  1409. ShowMessage( stdout, NEW_LINE );
  1410. ShowMessage( stdout, GetResString( IDS_LOCAL_PROFILE ) );
  1411. DISPLAY_MESSAGE( stdout, _X((LPCWSTR)pUserInfo->strLocalProfile) );
  1412. ShowMessage( stdout, NEW_LINE );
  1413. return TRUE;
  1414. }
  1415. /*********************************************************************************************
  1416. Routine Description:
  1417. This function displays the GPO information from the rsop namespace created.
  1418. Arguments:
  1419. [in] IEnumWbemClassObject : pointer to the Enumeration class object
  1420. [in] LPCTSTR : string containing the scope( USER or COMPUTER )
  1421. Return Value:
  1422. TRUE - if SUCCESS
  1423. FALSE - if ERROR
  1424. *********************************************************************************************/
  1425. BOOL CGpResult::GpoDisplay( IWbemServices *pNameSpace, LPCTSTR pszScopeName )
  1426. {
  1427. HRESULT hResult = WBEM_S_NO_ERROR;
  1428. BOOL bResult = FALSE;
  1429. BOOL bFilterAllowed = FALSE;
  1430. BOOL bLinkEnabled = FALSE;
  1431. BOOL bGpoEnabled = FALSE;
  1432. BOOL bAccessDenied = FALSE;
  1433. BOOL bConnected = FALSE;
  1434. ULONG ulReturn = 0;
  1435. ULONG ulAppliedOrder = 0;
  1436. ULONG ulVersion = 0;
  1437. DWORD dwAppliedRow = 0;
  1438. DWORD dwFilteredRow = 0;
  1439. CHString strTemp;
  1440. IEnumWbemClassObject *pRsopLinkClass = NULL;
  1441. IWbemClassObject *pRsopLinkObj = NULL;
  1442. IWbemClassObject *pRsopObj = NULL;
  1443. IWbemClassObject *pSomFilter = NULL;
  1444. IWbemServices *pPolicyNameSpace = NULL;
  1445. TARRAY arrAppliedData = NULL;
  1446. TARRAY arrFilteredData = NULL;
  1447. BOOL bNobreak = TRUE;
  1448. try
  1449. {
  1450. if( pNameSpace == NULL || pszScopeName == NULL )
  1451. {
  1452. _com_issue_error( STG_E_UNKNOWN );
  1453. }
  1454. // Create the Dynamic Arrays
  1455. arrAppliedData = CreateDynamicArray( );
  1456. arrFilteredData = CreateDynamicArray( );
  1457. // Check the memory allocations
  1458. if( arrAppliedData == NULL || arrFilteredData == NULL )
  1459. {
  1460. _com_issue_error( E_OUTOFMEMORY );
  1461. }
  1462. // enumerate the instances of the RSOP GPLink class
  1463. hResult = pNameSpace->CreateInstanceEnum( _bstr_t( CLS_RSOP_GPOLINK ),
  1464. WBEM_FLAG_FORWARD_ONLY |
  1465. WBEM_FLAG_RETURN_IMMEDIATELY,
  1466. NULL, &pRsopLinkClass );
  1467. CHECK_HRESULT( hResult );
  1468. // set the interface security
  1469. hResult = SetInterfaceSecurity( pRsopLinkClass, m_pAuthIdentity );
  1470. CHECK_HRESULT( hResult );
  1471. // Get the information from the enumerated classes
  1472. do
  1473. {
  1474. // Get the pointer to the next class
  1475. hResult = pRsopLinkClass->Next( WBEM_INFINITE, 1, &pRsopLinkObj, &ulReturn );
  1476. CHECK_HRESULT( hResult );
  1477. if( ulReturn == 0 )
  1478. {
  1479. bNobreak = FALSE;
  1480. break;
  1481. }
  1482. // Get the applied order for the link
  1483. bResult = PropertyGet( pRsopLinkObj, CPV_APPLIED_ORDER, ulAppliedOrder, 0 );
  1484. CHECK_BRESULT( bResult );
  1485. // Get the link enabled property
  1486. bResult = PropertyGet( pRsopLinkObj, CPV_ENABLED, bLinkEnabled, FALSE );
  1487. CHECK_BRESULT( bResult );
  1488. // Get the reference to the GPO class
  1489. bResult = PropertyGet( pRsopLinkObj, CPV_GPO_REF, strTemp, V_NOT_AVAILABLE );
  1490. CHECK_BRESULT( bResult );
  1491. // Check wether the link has a GPO class
  1492. if( strTemp.Find( GPO_REFERENCE ) != VAR_TRUE )
  1493. {
  1494. // Get the object for the GPO reference got
  1495. hResult = pNameSpace->GetObject( _bstr_t( strTemp ), 0, NULL, &pRsopObj, NULL );
  1496. if( FAILED( hResult ) )
  1497. {
  1498. if( hResult == WBEM_E_NOT_FOUND )
  1499. {
  1500. continue;
  1501. }
  1502. _com_issue_error( hResult );
  1503. }
  1504. // Get the GPO name
  1505. bResult = PropertyGet( pRsopObj, CPV_GPO_NAME, strTemp, V_NOT_AVAILABLE );
  1506. CHECK_BRESULT( bResult );
  1507. // Get the WMI filter status
  1508. bResult = PropertyGet( pRsopObj, CPV_GPO_FILTER_STATUS, bFilterAllowed, FALSE );
  1509. CHECK_BRESULT( bResult );
  1510. // Get the Gpo enabled information
  1511. bResult = PropertyGet( pRsopObj, CPV_ENABLED, bGpoEnabled, FALSE );
  1512. CHECK_BRESULT( bResult );
  1513. // Get the access denied information
  1514. bResult = PropertyGet( pRsopObj, CPV_ACCESS_DENIED, bAccessDenied, FALSE );
  1515. CHECK_BRESULT( bResult );
  1516. // Get the version
  1517. bResult = PropertyGet( pRsopObj, CPV_VERSION, ulVersion, 0 );
  1518. CHECK_BRESULT( bResult );
  1519. // If the applied order id not zero then this GPO is applied
  1520. if( ulAppliedOrder > 0 )
  1521. {
  1522. // Populate the applied Gpo array
  1523. DynArrayAppendRow( arrAppliedData, COL_MAX );
  1524. DynArraySetString2( arrAppliedData, dwAppliedRow, COL_DATA, strTemp, 0 );
  1525. DynArraySetDWORD2( arrAppliedData, dwAppliedRow, COL_ORDER, ulAppliedOrder );
  1526. dwAppliedRow++;
  1527. }
  1528. else if( bLinkEnabled != VAR_TRUE )
  1529. {
  1530. // if the link is disabled...populate the Filtered Array
  1531. DynArrayAppendRow( arrFilteredData, COL_MAX );
  1532. DynArraySetString2( arrFilteredData, dwFilteredRow, COL_DATA, strTemp, 0 );
  1533. DynArraySetString2( arrFilteredData, dwFilteredRow, COL_FILTER,
  1534. GetResString( IDS_LINK_DISABLED ), 0 );
  1535. dwFilteredRow++;
  1536. }
  1537. else if( bGpoEnabled != VAR_TRUE )
  1538. {
  1539. // if the GPO is disabled...populate the Filtered Array
  1540. DynArrayAppendRow( arrFilteredData, COL_MAX );
  1541. DynArraySetString2( arrFilteredData, dwFilteredRow, COL_DATA, strTemp, 0 );
  1542. DynArraySetString2( arrFilteredData, dwFilteredRow, COL_FILTER,
  1543. GetResString( IDS_GPO_DISABLED ), 0 );
  1544. dwFilteredRow++;
  1545. }
  1546. else if( bAccessDenied == VAR_TRUE )
  1547. {
  1548. // if the access is denied...populate the Filtered Array
  1549. DynArrayAppendRow( arrFilteredData, COL_MAX );
  1550. DynArraySetString2( arrFilteredData, dwFilteredRow, COL_DATA, strTemp, 0 );
  1551. DynArraySetString2( arrFilteredData, dwFilteredRow, COL_FILTER,
  1552. GetResString( IDS_ACCESS_DENIED ), 0 );
  1553. dwFilteredRow++;
  1554. }
  1555. else if( bFilterAllowed != VAR_TRUE )
  1556. {
  1557. // if the filter status is false...populate the Filtered Array
  1558. DynArrayAppendRow( arrFilteredData, COL_MAX_FILTER );
  1559. DynArraySetString2( arrFilteredData, dwFilteredRow, COL_DATA, strTemp, 0 );
  1560. DynArraySetString2( arrFilteredData, dwFilteredRow, COL_FILTER,
  1561. GetResString( IDS_WMI_DENIED ), 0 );
  1562. // Get the filter ID
  1563. bResult = PropertyGet( pRsopObj, CPV_GPO_FILTER_ID, strTemp, V_NOT_AVAILABLE );
  1564. CHECK_BRESULT( bResult );
  1565. // Store it in the array
  1566. DynArraySetString2( arrFilteredData, dwFilteredRow, COL_FILTER_ID, strTemp, 0 );
  1567. dwFilteredRow++;
  1568. }
  1569. else if( ulVersion == 0 )
  1570. {
  1571. // if the version is zero...populate the Filtered Array
  1572. DynArrayAppendRow( arrFilteredData, COL_MAX );
  1573. DynArraySetString2( arrFilteredData, dwFilteredRow, COL_DATA, strTemp, 0 );
  1574. DynArraySetString2( arrFilteredData, dwFilteredRow, COL_FILTER,
  1575. GetResString( IDS_VERSION_ZERO ), 0 );
  1576. dwFilteredRow++;
  1577. }
  1578. else
  1579. {
  1580. // the Gpo is not applied due to an unknown reason...
  1581. // populate the Filtered Array
  1582. DynArrayAppendRow( arrFilteredData, COL_MAX );
  1583. DynArraySetString2( arrFilteredData, dwFilteredRow, COL_DATA, strTemp, 0 );
  1584. DynArraySetString2( arrFilteredData, dwFilteredRow, COL_FILTER,
  1585. GetResString( IDS_NOT_APPLIED ), 0 );
  1586. dwFilteredRow++;
  1587. }
  1588. }
  1589. }while( TRUE == bNobreak );// while
  1590. // Got the data...sort it
  1591. SortAppliedData( arrAppliedData );
  1592. // Display the applied data first
  1593. dwAppliedRow = DynArrayGetCount( arrAppliedData );
  1594. for( DWORD dwi = 0; dwi < dwAppliedRow; dwi++ )
  1595. {
  1596. ShowMessage( stdout, TAB_TWO );
  1597. ShowMessage( stdout, DynArrayItemAsString2( arrAppliedData, dwi, COL_DATA ) );
  1598. ShowMessage( stdout, GetResString( IDS_NEWLINE ) );
  1599. }
  1600. // Check if there was any data displayed
  1601. if( dwAppliedRow <= 0 )
  1602. {
  1603. ShowMessage( stdout, TAB_TWO );
  1604. ShowMessage( stdout, V_NOT_AVAILABLE );
  1605. ShowMessage( stdout, NEW_LINE );
  1606. }
  1607. // Display the filtered GPOs
  1608. // Display the header...if there are any GPO's filtered out
  1609. dwFilteredRow = DynArrayGetCount( arrFilteredData );
  1610. if( dwFilteredRow > 0 )
  1611. {
  1612. ShowMessage( stdout, GetResString( IDS_GPO_FILTERED ) );
  1613. ShowMessage( stdout, GetResString( IDS_NEWLINE_TAB ) );
  1614. for( dwi = StringLengthInBytes( GetResString( IDS_GPO_FILTERED ) ); dwi > 4; dwi-- )
  1615. {
  1616. ShowMessage( stdout, GetResString( IDS_DASH ) );
  1617. }
  1618. ShowMessage( stdout, GetResString( IDS_NEWLINE ) );
  1619. }
  1620. else
  1621. {
  1622. // There are no filtered GPO's hence put a new line and continue
  1623. // displaying the rest of the output
  1624. ShowMessage( stdout, GetResString( IDS_NEWLINE ) );
  1625. }
  1626. // display the data
  1627. for( DWORD dwi = 0; dwi < dwFilteredRow; dwi++ )
  1628. {
  1629. ShowMessage( stdout, TAB_TWO );
  1630. ShowMessage( stdout, DynArrayItemAsString2( arrFilteredData, dwi, COL_DATA ) );
  1631. ShowMessage( stdout, GetResString( IDS_FILTERING ) );
  1632. ShowMessage( stdout, DynArrayItemAsString2( arrFilteredData, dwi, COL_FILTER ) );
  1633. // Check if we have to display the filter id for the WMI filter that evaluated to false
  1634. if( StringCompare( DynArrayItemAsString2( arrFilteredData, dwi, COL_FILTER ),
  1635. GetResString( IDS_WMI_DENIED ), TRUE, 0 ) == 0 )
  1636. {
  1637. if( bConnected == FALSE )
  1638. {
  1639. // we need to connect to Root\Policy
  1640. // connect to the default namespace
  1641. ConnectWmi( m_pWbemLocator, &pPolicyNameSpace, m_strServerName,
  1642. m_strUserName, m_pwszPassword, &m_pAuthIdentity,
  1643. FALSE, _bstr_t( ROOT_POLICY ), &hResult );
  1644. CHECK_HRESULT( hResult );
  1645. bConnected = TRUE;
  1646. }
  1647. // Get the object
  1648. hResult = pPolicyNameSpace->GetObject( _bstr_t( DynArrayItemAsString2(
  1649. arrFilteredData, dwi, COL_FILTER_ID ) ),
  1650. 0, NULL, &pSomFilter, NULL );
  1651. // check whether we got the object or not -- if at all error occured
  1652. // ignore this and proceed
  1653. if ( FAILED( hResult ) )
  1654. {
  1655. if ( WBEM_E_NOT_FOUND == hResult )
  1656. {
  1657. // ignore this error -- proceed with the normal logic flow
  1658. }
  1659. // still ignore this error -- currently we are not trapping this error too
  1660. }
  1661. else
  1662. {
  1663. // Get the name of the filter applied
  1664. bResult = PropertyGet( pSomFilter, CPV_NAME, strTemp, V_NOT_AVAILABLE );
  1665. // display the filter ID
  1666. ShowMessage( stdout, GetResString( IDS_GPO_FILTER_ID ) );
  1667. ShowMessage( stdout, strTemp );
  1668. ShowMessage( stdout, GetResString( IDS_NEWLINE ) );
  1669. }
  1670. }
  1671. ShowMessage( stdout, GetResString( IDS_NEWLINE ) );
  1672. }
  1673. // destroy the dynamic arrays
  1674. DESTROY_ARRAY( arrAppliedData );
  1675. DESTROY_ARRAY( arrFilteredData );
  1676. }
  1677. catch( _com_error & error )
  1678. {
  1679. // display the error message
  1680. WMISaveError( error.Error() );
  1681. ShowMessage( stderr, GetResString( IDS_ERROR ) );
  1682. ShowMessage( stderr, GetReason() );
  1683. SAFEIRELEASE( pRsopLinkObj );
  1684. SAFEIRELEASE( pRsopLinkClass );
  1685. SAFEIRELEASE( pRsopObj );
  1686. SAFEIRELEASE( pSomFilter );
  1687. SAFEIRELEASE( pPolicyNameSpace );
  1688. // destroy the dynamic arrays
  1689. DESTROY_ARRAY( arrAppliedData );
  1690. DESTROY_ARRAY( arrFilteredData );
  1691. return FALSE;
  1692. }
  1693. SAFEIRELEASE( pRsopLinkObj );
  1694. SAFEIRELEASE( pRsopLinkClass );
  1695. SAFEIRELEASE( pRsopObj );
  1696. SAFEIRELEASE( pSomFilter );
  1697. SAFEIRELEASE( pPolicyNameSpace );
  1698. return TRUE;
  1699. }
  1700. /*********************************************************************************************
  1701. Routine Description:
  1702. This function Will delete the Rsop namespace created by method RsopCreateSession.
  1703. Arguments:
  1704. [in] pClass : pointer to IWbemServices.
  1705. [in] CHString : string containing the RsopNamespace.
  1706. [in] pObject : pointer to IWbemClassObject.
  1707. Return Value:
  1708. TRUE - if SUCCESS
  1709. FALSE - if ERROR
  1710. *********************************************************************************************/
  1711. BOOL RsopDeleteMethod( IWbemClassObject *pClass, CHString strNameSpace,
  1712. IWbemServices *pNamespace )
  1713. {
  1714. HRESULT hResult = S_OK;
  1715. BOOL bResult = FALSE;
  1716. IWbemClassObject *pInClass = NULL;
  1717. IWbemClassObject *pInInst = NULL;
  1718. IWbemClassObject *pOutInst = NULL;
  1719. CHString strTemp;
  1720. DWORD ulReturn=0;
  1721. try
  1722. {
  1723. // Check the input Parameters
  1724. if( pClass == NULL )
  1725. {
  1726. _com_issue_error( STG_E_UNKNOWN );
  1727. }
  1728. //Delete the resultant RSOP namespace as the snap shot
  1729. //of RSOP has been obtained
  1730. hResult = pClass->GetMethod( _bstr_t( FN_DELETE_RSOP ), 0, &pInClass, NULL );
  1731. CHECK_HRESULT( hResult );
  1732. hResult = pInClass->SpawnInstance( 0, &pInInst );
  1733. CHECK_HRESULT( hResult );
  1734. //Put the input parameter
  1735. hResult = PropertyPut( pInInst, FPR_RSOP_NAMESPACE, strNameSpace );
  1736. CHECK_HRESULT( hResult );
  1737. // All The required properties are set so, execute method RsopDeleteSession
  1738. hResult = pNamespace->ExecMethod( _bstr_t( CLS_DIAGNOSTIC_PROVIDER ),
  1739. _bstr_t( FN_DELETE_RSOP ),
  1740. 0, NULL, pInInst, &pOutInst, NULL );
  1741. if(pOutInst == NULL)
  1742. {
  1743. hResult = E_FAIL;
  1744. }
  1745. if( FAILED( hResult ) )
  1746. {
  1747. // display the error msg
  1748. ShowMessage( stderr, GetResString( IDS_ERROR ) );
  1749. ShowMessage( stderr, GetResString( IDS_METHOD_FAILED ) );
  1750. // release the interface pointers and exit
  1751. SAFEIRELEASE(pInClass);
  1752. SAFEIRELEASE(pInInst);
  1753. SAFEIRELEASE(pOutInst);
  1754. return FALSE;
  1755. }
  1756. //Get returned paramter to check whether the method was successfull
  1757. bResult = PropertyGet( pOutInst, FPR_RETURN_VALUE, ulReturn, 0);
  1758. CHECK_BRESULT( bResult );
  1759. // Returns some ERROR code.
  1760. if( ulReturn != 0 )
  1761. {
  1762. // Show Error Message
  1763. ShowMessage( stderr, GetResString( IDS_ERROR ) );
  1764. ShowMessage( stderr, GetResString( IDS_METHOD_FAILED ) );
  1765. bResult = FALSE;
  1766. }
  1767. bResult = TRUE;
  1768. }
  1769. catch( _com_error & error )
  1770. {
  1771. // display the error message and set the return value to FALSE
  1772. WMISaveError( error.Error() );
  1773. ShowMessage( stderr, GetResString( IDS_ERROR ) );
  1774. ShowMessage( stderr, GetReason() );
  1775. bResult = FALSE;
  1776. }
  1777. // release the interface pointers and exit
  1778. SAFEIRELEASE(pInClass);
  1779. SAFEIRELEASE(pInInst);
  1780. SAFEIRELEASE(pOutInst);
  1781. return bResult;
  1782. }
  1783. /*********************************************************************************************
  1784. Routine Description:
  1785. This function gets the OS information and fills the array with the same
  1786. Arguments:
  1787. [in] PUSERINFO pUserInfo : Structure containing the user information.
  1788. Return Value:
  1789. TRUE on SUCCESS
  1790. FALSE on FAILURE
  1791. *********************************************************************************************/
  1792. BOOL CGpResult::GetOsInfo( PUSERINFO pUserInfo )
  1793. {
  1794. // Local variables
  1795. HRESULT hResult = S_OK;
  1796. BOOL bResult = FALSE;
  1797. IEnumWbemClassObject *pEnumClass = NULL;
  1798. IWbemClassObject *pClass = NULL;
  1799. ULONG ulReturn = 0;
  1800. DWORD dwDomainRole = 0;
  1801. CHString strTemp;
  1802. try
  1803. {
  1804. // print the progress message
  1805. PrintProgressMsg( m_hOutput, GetResString( IDS_GET_OSINFO ), m_csbi );
  1806. // Enumerate the instances to get the domain and site names of the Win32 NT domain
  1807. hResult = m_pWbemServices->CreateInstanceEnum( _bstr_t( CLS_WIN32_OS ),
  1808. WBEM_FLAG_FORWARD_ONLY |
  1809. WBEM_FLAG_RETURN_IMMEDIATELY,
  1810. NULL, &pEnumClass );
  1811. CHECK_HRESULT( hResult );
  1812. // Set the interface security
  1813. hResult = SetInterfaceSecurity( pEnumClass, m_pAuthIdentity );
  1814. CHECK_HRESULT( hResult );
  1815. // get the data
  1816. hResult = pEnumClass->Next( WBEM_INFINITE, 1, &pClass, &ulReturn );
  1817. CHECK_HRESULT( hResult );
  1818. // get the OS version
  1819. bResult = PropertyGet( pClass, CPV_OS_VERSION, pUserInfo->strOsVersion,
  1820. V_NOT_AVAILABLE );
  1821. CHECK_BRESULT( bResult );
  1822. // get the OS type
  1823. bResult = PropertyGet( pClass, CPV_OS_CAPTION, pUserInfo->strOsType,
  1824. V_NOT_AVAILABLE );
  1825. CHECK_BRESULT( bResult );
  1826. // enumerate the instances of Win32_ComputerSystem class
  1827. SAFE_RELEASE( pEnumClass );
  1828. hResult = m_pWbemServices->CreateInstanceEnum( _bstr_t( CLS_WIN32_CS ),
  1829. WBEM_FLAG_RETURN_IMMEDIATELY |
  1830. WBEM_FLAG_FORWARD_ONLY,
  1831. NULL, &pEnumClass );
  1832. // check the result of enumeration
  1833. CHECK_HRESULT( hResult );
  1834. // set the security on the obtained interface
  1835. hResult = SetInterfaceSecurity( pEnumClass, m_pAuthIdentity );
  1836. CHECK_HRESULT( hResult );
  1837. // get the enumerated objects information
  1838. // NOTE: This needs to be traversed only one time.
  1839. hResult = pEnumClass->Next( WBEM_INFINITE, 1, &pClass, &ulReturn );
  1840. CHECK_HRESULT( hResult );
  1841. // get the OS config
  1842. bResult = PropertyGet( pClass, CPV_DOMAIN_ROLE, dwDomainRole, 0 );
  1843. CHECK_BRESULT( bResult );
  1844. // get the domain name information for later use
  1845. bResult = PropertyGet( pClass, CPV_DOMAIN, m_strADSIDomain );
  1846. CHECK_BRESULT( bResult );
  1847. // get the server name for future use by LDAP
  1848. bResult = PropertyGet( pClass, CPV_NAME, m_strADSIServer );
  1849. CHECK_BRESULT( bResult );
  1850. //
  1851. // Mapping information of Win32_ComputerSystem's DomainRole property
  1852. // NOTE: Refer to the _DSROLE_MACHINE_ROLE enumeration values in DsRole.h header file
  1853. switch( dwDomainRole )
  1854. {
  1855. case DsRole_RoleStandaloneWorkstation:
  1856. pUserInfo->strOsConfig = VALUE_STANDALONEWORKSTATION;
  1857. break;
  1858. case DsRole_RoleMemberWorkstation:
  1859. pUserInfo->strOsConfig = VALUE_MEMBERWORKSTATION;
  1860. break;
  1861. case DsRole_RoleStandaloneServer:
  1862. pUserInfo->strOsConfig = VALUE_STANDALONESERVER;
  1863. break;
  1864. case DsRole_RoleMemberServer:
  1865. pUserInfo->strOsConfig = VALUE_MEMBERSERVER;
  1866. break;
  1867. case DsRole_RoleBackupDomainController:
  1868. pUserInfo->strOsConfig = VALUE_BACKUPDOMAINCONTROLLER;
  1869. break;
  1870. case DsRole_RolePrimaryDomainController:
  1871. pUserInfo->strOsConfig = VALUE_PRIMARYDOMAINCONTROLLER;
  1872. break;
  1873. default:
  1874. break;
  1875. }
  1876. }
  1877. catch( _com_error & error )
  1878. {
  1879. WMISaveError( error.Error() );
  1880. ShowMessage( stderr, GetResString( IDS_ERROR ) );
  1881. ShowMessage( stderr, GetReason() );
  1882. // release the allocated variables
  1883. SAFEIRELEASE( pEnumClass );
  1884. SAFEIRELEASE( pClass );
  1885. return FALSE;
  1886. }
  1887. catch( CHeap_Exception )
  1888. {
  1889. // display the error message
  1890. SetLastError( (DWORD)E_OUTOFMEMORY );
  1891. SaveLastError();
  1892. SAFEIRELEASE( pEnumClass );
  1893. SAFEIRELEASE( pClass );
  1894. ShowMessage( stderr, GetResString( IDS_ERROR ) );
  1895. ShowMessage( stderr, GetReason() );
  1896. }
  1897. // release the interface pointers
  1898. SAFEIRELEASE( pEnumClass );
  1899. SAFEIRELEASE( pClass );
  1900. return TRUE;
  1901. }
  1902. /*********************************************************************************************
  1903. Routine Description:
  1904. This function displays the security groups for system and user
  1905. Arguments:
  1906. IWbemServices : pointer to the name space
  1907. BOOL : set to TRUE if the system o/p is to be displayed
  1908. Return Value:
  1909. None
  1910. *********************************************************************************************/
  1911. VOID CGpResult::DisplaySecurityGroups( IWbemServices *pNameSpace, BOOL bComputer )
  1912. {
  1913. HRESULT hResult = S_OK;
  1914. BOOL bResult = FALSE;
  1915. BOOL bGotClass = FALSE;
  1916. ULONG ulReturned = 0;
  1917. LONG lLBound = 0;
  1918. LONG lUBound = 0;
  1919. DWORD dwLength = 0;
  1920. IWbemClassObject *pClass = NULL;
  1921. IWbemClassObject *pName = NULL;
  1922. IWbemClassObject *pDomain = NULL;
  1923. IEnumWbemClassObject *pEnumClass = NULL;
  1924. IEnumWbemClassObject *pEnumDomain = NULL;
  1925. VARIANT vVarVerbose;
  1926. VARTYPE vartype;
  1927. TCHAR szTemp[ MAX_STRING_LENGTH ];
  1928. TCHAR szQueryString[ MAX_STRING_LENGTH ];
  1929. CHString strTemp;
  1930. CHString strDomain;
  1931. SAFEARRAY *safeArray = NULL;
  1932. try
  1933. {
  1934. SecureZeroMemory( szTemp, sizeof( szTemp ) );
  1935. SecureZeroMemory( szQueryString, sizeof( szQueryString ) );
  1936. // Enumerate the classes for the user privelege rights
  1937. hResult = pNameSpace->CreateInstanceEnum( _bstr_t( CLS_RSOP_SESSION ),
  1938. WBEM_FLAG_FORWARD_ONLY |
  1939. WBEM_FLAG_RETURN_IMMEDIATELY,
  1940. NULL, &pEnumClass );
  1941. CHECK_HRESULT( hResult );
  1942. // Set the interface security
  1943. hResult = SetInterfaceSecurity( pEnumClass, m_pAuthIdentity );
  1944. CHECK_HRESULT( hResult );
  1945. hResult = WBEM_S_NO_ERROR;
  1946. while( WBEM_S_NO_ERROR == hResult )
  1947. {
  1948. // Get the next class
  1949. hResult = pEnumClass->Next( WBEM_INFINITE , 1, &pClass, &ulReturned );
  1950. CHECK_HRESULT( hResult );
  1951. if( ulReturned == 0 )
  1952. {
  1953. // No more classes to enumerate
  1954. // Display N/A if there were no classes
  1955. if( bGotClass == FALSE )
  1956. {
  1957. ShowMessage( stdout, GetResString( IDS_NEWLINETAB ) );
  1958. ShowMessage( stdout, V_NOT_AVAILABLE );
  1959. ShowMessage( stdout, NEW_LINE );
  1960. }
  1961. break;
  1962. }
  1963. bGotClass = TRUE;
  1964. // Get the security groups
  1965. if( bComputer == TRUE )
  1966. {
  1967. ShowMessage( stdout, GetResString( IDS_SYS_SG ) );
  1968. ShowMessage( stdout, GetResString( IDS_NEWLINE_TAB ) );
  1969. for( dwLength = StringLengthInBytes( GetResString( IDS_SYS_SG ) ); dwLength > 4; dwLength-- )
  1970. {
  1971. ShowMessage( stdout, GetResString( IDS_DASH ) );
  1972. }
  1973. ShowMessage( stdout, GetResString( IDS_NEWLINETAB ) );
  1974. }
  1975. else
  1976. {
  1977. ShowMessage( stdout, GetResString( IDS_USER_SG ) );
  1978. ShowMessage( stdout, GetResString( IDS_NEWLINE_TAB ) );
  1979. for( dwLength = StringLengthInBytes( GetResString( IDS_USER_SG ) ); dwLength > 4; dwLength-- )
  1980. {
  1981. ShowMessage( stdout, GetResString( IDS_DASH ) );
  1982. }
  1983. ShowMessage( stdout, GetResString( IDS_NEWLINETAB ) );
  1984. }
  1985. VariantInit( &vVarVerbose );
  1986. hResult = pClass->Get( _bstr_t(CPV_SEC_GRPS), 0, &vVarVerbose, 0, 0 );
  1987. CHECK_HRESULT_VAR( hResult, vVarVerbose );
  1988. if( vVarVerbose.vt != VT_NULL && vVarVerbose.vt != VT_EMPTY )
  1989. {
  1990. // get the type of the elements in the safe array
  1991. vartype = (VARTYPE)(V_VT( &vVarVerbose ) & ~VT_ARRAY);
  1992. //get the array of strings in to the safe array from the variant
  1993. safeArray = (SAFEARRAY *)vVarVerbose.parray;
  1994. //get the number of elements (subkeys)
  1995. if( safeArray != NULL )
  1996. {
  1997. hResult = SafeArrayGetLBound( safeArray, 1, &lLBound );
  1998. CHECK_HRESULT( hResult );
  1999. hResult = SafeArrayGetUBound( safeArray, 1, &lUBound );
  2000. CHECK_HRESULT( hResult );
  2001. }
  2002. if( FALSE == bComputer )
  2003. {
  2004. //alllocate memory to store user groups
  2005. m_szUserGroups = (LPWSTR*) AllocateMemory( (lUBound+1)*sizeof(LPWSTR));
  2006. if( NULL == m_szUserGroups )
  2007. {
  2008. VariantClear(&vVarVerbose);
  2009. ShowLastErrorEx(stderr, SLE_TYPE_ERROR | SLE_INTERNAL );
  2010. SAFEIRELEASE( pClass );
  2011. SAFEIRELEASE( pName );
  2012. SAFEIRELEASE( pDomain );
  2013. SAFEIRELEASE( pEnumClass );
  2014. SAFEIRELEASE( pEnumDomain );
  2015. return;
  2016. }
  2017. m_NoOfGroups = lUBound;
  2018. }
  2019. for( ; lLBound <= lUBound; lLBound++ )
  2020. {
  2021. bResult = GetPropertyFromSafeArray( safeArray, lLBound, strTemp, vartype );
  2022. CHECK_BRESULT( bResult );
  2023. //place the user security groups
  2024. if( FALSE == bComputer )
  2025. {
  2026. m_szUserGroups[lLBound] = (LPWSTR) AllocateMemory( (strTemp.GetLength()+10)*sizeof(WCHAR) );
  2027. if( NULL == m_szUserGroups[lLBound] )
  2028. {
  2029. VariantClear(&vVarVerbose);
  2030. ShowLastErrorEx( stderr, SLE_TYPE_ERROR | SLE_INTERNAL );
  2031. SAFEIRELEASE( pClass );
  2032. SAFEIRELEASE( pName );
  2033. SAFEIRELEASE( pDomain );
  2034. SAFEIRELEASE( pEnumClass );
  2035. SAFEIRELEASE( pEnumDomain );
  2036. return;
  2037. }
  2038. StringCopy( m_szUserGroups[lLBound], (LPCWSTR)strTemp, GetBufferSize(m_szUserGroups[lLBound])/sizeof(WCHAR) );
  2039. }
  2040. // Got a sid, now get it's coressponding name
  2041. // form the object path using the SID
  2042. //
  2043. //
  2044. // if( strTemp.Right(4) == L"-513" )
  2045. // continue;
  2046. //
  2047. //
  2048. StringCchPrintf( szTemp, MAX_STRING_LENGTH, OBJECT_PATH, (LPCWSTR)strTemp );
  2049. // Get the object
  2050. hResult = m_pWbemServices->GetObject( _bstr_t( szTemp ), 0, NULL, &pName, NULL );
  2051. CHECK_HRESULT( hResult );
  2052. // Get the Account name
  2053. bResult = PropertyGet( pName, CPV_ACCOUNT_NAME, strTemp, V_NOT_AVAILABLE );
  2054. // Append the appropriate prefix
  2055. if( strTemp.Compare( _T( "ANONYMOUS LOGON" ) ) == 0
  2056. || strTemp.Compare( _T( "BATCH" ) ) == 0
  2057. || strTemp.Compare( _T( "DIALUP" ) ) == 0
  2058. || strTemp.Compare( _T( "INTERACTIVE" ) ) == 0
  2059. || strTemp.Compare( _T( "SERVICE" ) ) == 0
  2060. || strTemp.Compare( _T( "SYSTEM" ) ) == 0
  2061. || strTemp.Compare( _T( "TERMINAL SERVICE USER" ) ) == 0
  2062. || strTemp.Compare( _T( "PROXY" ) ) == 0
  2063. || strTemp.Compare( _T( "NETWORK" ) ) == 0
  2064. || strTemp.Compare( _T( "ENTERPRISE DOMAIN CONTROLLERS" ) ) == 0
  2065. || strTemp.Compare( _T( "Authenticated Users" ) ) == 0
  2066. || strTemp.Compare( _T( "RESTRICTED" ) ) == 0
  2067. || strTemp.Compare( _T( "SELF" ) ) == 0 )
  2068. {
  2069. ShowMessage( stdout, _T( "NT AUTHORITY\\" ) );
  2070. }
  2071. else if( strTemp.Compare( _T( "Administrators" ) ) == 0
  2072. || strTemp.Compare( _T( "Backup Operators" ) ) == 0
  2073. || strTemp.Compare( _T( "Guests" ) ) == 0
  2074. || strTemp.Compare( _T( "Power Users" ) ) == 0
  2075. || strTemp.Compare( _T( "Replicator" ) ) == 0
  2076. || strTemp.Compare( _T( "Pre-Windows 2000 Compatible Access" ) ) == 0
  2077. || strTemp.Compare( _T( "Users" ) ) == 0 )
  2078. {
  2079. ShowMessage( stdout, _T( "BUILTIN\\" ) );
  2080. }
  2081. if( strTemp.Compare( _T("") ) != 0)
  2082. {
  2083. ShowMessage( stdout, strTemp );
  2084. ShowMessage( stdout, GetResString( IDS_NEWLINETAB ) );
  2085. }
  2086. }
  2087. }
  2088. else
  2089. {
  2090. ShowMessage( stdout, V_NOT_AVAILABLE );
  2091. ShowMessage( stdout, NEW_LINE );
  2092. }
  2093. VariantClear(&vVarVerbose);
  2094. }
  2095. }
  2096. catch( _com_error & error )
  2097. {
  2098. WMISaveError( error.Error() );
  2099. ShowMessage( stderr, GetResString( IDS_ERROR ) );
  2100. ShowMessage( stderr, GetReason() );
  2101. SAFEIRELEASE(pEnumClass);
  2102. SAFEIRELEASE(pEnumDomain);
  2103. SAFEIRELEASE(pClass);
  2104. SAFEIRELEASE(pName);
  2105. SAFEIRELEASE(pDomain);
  2106. VariantClear(&vVarVerbose);
  2107. }
  2108. // release the interface pointers
  2109. SAFEIRELEASE(pEnumClass);
  2110. SAFEIRELEASE(pEnumDomain);
  2111. SAFEIRELEASE(pClass);
  2112. SAFEIRELEASE(pName);
  2113. SAFEIRELEASE(pDomain);
  2114. return;
  2115. }
  2116. /*********************************************************************************************
  2117. Routine Description:
  2118. This function gets the link speed information
  2119. Arguments:
  2120. IWbemServices : pointer to the name space.
  2121. COAUTHIDENTITY : pointer to the AuthIdentity structure.
  2122. Return Value:
  2123. None
  2124. *********************************************************************************************/
  2125. VOID DisplayLinkSpeed( IWbemServices *pNameSpace, COAUTHIDENTITY *pAuthIdentity )
  2126. {
  2127. HRESULT hResult = S_OK;
  2128. BOOL bGotClass = FALSE;
  2129. BOOL bTemp = FALSE;
  2130. ULONG ulReturned = 0;
  2131. IWbemClassObject *pClass = NULL;
  2132. IEnumWbemClassObject *pEnumClass = NULL;
  2133. VARIANT vVarTemp;
  2134. try
  2135. {
  2136. // Get the pointer to ennumerate with
  2137. hResult = pNameSpace->CreateInstanceEnum( _bstr_t( CLS_RSOP_SESSION ),
  2138. WBEM_FLAG_FORWARD_ONLY |
  2139. WBEM_FLAG_RETURN_IMMEDIATELY,
  2140. NULL, &pEnumClass );
  2141. CHECK_HRESULT( hResult );
  2142. // Set the interface security
  2143. hResult = SetInterfaceSecurity( pEnumClass, pAuthIdentity );
  2144. CHECK_HRESULT( hResult );
  2145. // Enumerate the classes one by one and get the data
  2146. hResult = WBEM_S_NO_ERROR;
  2147. while( WBEM_S_NO_ERROR == hResult )
  2148. {
  2149. // Get the next class
  2150. hResult = pEnumClass->Next( WBEM_INFINITE , 1, &pClass, &ulReturned );
  2151. CHECK_HRESULT( hResult );
  2152. if( ulReturned == 0 )
  2153. {
  2154. // No more classes to enumerate
  2155. // Display N/A if there were no classes
  2156. if( bGotClass == FALSE )
  2157. {
  2158. ShowMessage( stdout, GetResString( IDS_NEWLINETAB ) );
  2159. ShowMessage( stdout, V_NOT_AVAILABLE );
  2160. ShowMessage( stdout, NEW_LINE );
  2161. }
  2162. break;
  2163. }
  2164. bGotClass = TRUE;
  2165. VariantInit( &vVarTemp );
  2166. hResult = pClass->Get( _bstr_t( CPV_SLOW_LINK ), 0, &vVarTemp, 0, 0 );
  2167. CHECK_HRESULT_VAR( hResult, vVarTemp );
  2168. ShowMessage( stdout, GetResString( IDS_LINK_SPEED ) );
  2169. if( vVarTemp.vt != VT_NULL )
  2170. {
  2171. bTemp = vVarTemp.boolVal;
  2172. if( bTemp == VAR_TRUE )
  2173. {
  2174. ShowMessage( stdout, GetResString( IDS_YES ) );
  2175. }
  2176. else
  2177. {
  2178. ShowMessage( stdout, GetResString( IDS_NO ) );
  2179. }
  2180. }
  2181. else
  2182. {
  2183. ShowMessage( stdout, V_NOT_AVAILABLE );
  2184. }
  2185. ShowMessage( stdout, NEW_LINE );
  2186. VariantClear( &vVarTemp );
  2187. }// while
  2188. }
  2189. catch(_com_error & error)
  2190. {
  2191. WMISaveError( error.Error() );
  2192. ShowMessage( stderr, GetResString( IDS_ERROR ) );
  2193. ShowMessage( stderr, GetReason() );
  2194. VariantClear( &vVarTemp );
  2195. }
  2196. // release the interface pointers
  2197. SAFEIRELEASE(pEnumClass);
  2198. SAFEIRELEASE(pClass);
  2199. return;
  2200. }
  2201. /*********************************************************************************************
  2202. Routine Description:
  2203. This function gets the User name and the domain name from WMI..
  2204. Arguments:
  2205. [in] szSid : string containing the SID
  2206. [out] szName : string to hold the user name
  2207. [out] szDomain : string to hold the domain name
  2208. Return Value:
  2209. TRUE on SUCCESS
  2210. FALSE on FAILURE
  2211. *********************************************************************************************/
  2212. BOOL CGpResult::GetUserNameFromWMI( TCHAR szSid[], TCHAR szName[], TCHAR szDomain[] )
  2213. {
  2214. // Local variables
  2215. HRESULT hResult = S_OK;
  2216. BOOL bResult = FALSE;
  2217. TCHAR szQueryString[ MAX_QUERY_STRING ];
  2218. TCHAR szTemp[ MAX_STRING_LENGTH ];
  2219. CHString strTemp = NULL_STRING;
  2220. IEnumWbemClassObject *pEnumClass = NULL;
  2221. IWbemClassObject *pClass = NULL;
  2222. ULONG ulReturn = 0;
  2223. try
  2224. {
  2225. // set the strings to NULL
  2226. SecureZeroMemory( szQueryString, MAX_QUERY_STRING * sizeof( TCHAR ));
  2227. SecureZeroMemory( szTemp, MAX_STRING_LENGTH * sizeof( TCHAR ) );
  2228. // Form the query string
  2229. StringCopy( szTemp, QUERY_USER_NAME, MAX_STRING_LENGTH );
  2230. StringCchPrintf( szQueryString, MAX_QUERY_STRING, szTemp, szSid );
  2231. // execute the respective query
  2232. hResult = m_pWbemServices->ExecQuery( _bstr_t( QUERY_LANGUAGE ),
  2233. _bstr_t( szQueryString ),
  2234. WBEM_FLAG_FORWARD_ONLY |
  2235. WBEM_FLAG_RETURN_IMMEDIATELY,
  2236. NULL, &pEnumClass );
  2237. CHECK_HRESULT( hResult );
  2238. // set the security parameters
  2239. hResult = SetInterfaceSecurity( pEnumClass, m_pAuthIdentity );
  2240. CHECK_HRESULT( hResult );
  2241. // Get the user name
  2242. hResult = pEnumClass->Next( TIME_OUT_NEXT, 1, &pClass, &ulReturn );
  2243. CHECK_HRESULT( hResult );
  2244. // if there are no classes to enumerate break out of the loop
  2245. if( ulReturn == 0 )
  2246. {
  2247. // No classes were retrieved....display msg
  2248. // release the interface pointers and exit
  2249. SAFEIRELEASE( pClass );
  2250. SAFEIRELEASE( pEnumClass );
  2251. return FALSE;
  2252. }
  2253. // Get the class property(Name)
  2254. bResult = PropertyGet( pClass, CPV_NAME, strTemp, V_NOT_AVAILABLE );
  2255. CHECK_BRESULT( bResult );
  2256. // Got the name...Store it.
  2257. StringCopy( szName, (LPCWSTR)strTemp, MAX_STRING_LENGTH );
  2258. // Get and add the domain name if it exists
  2259. bResult = PropertyGet( pClass, CPV_DOMAIN, strTemp, V_NOT_AVAILABLE );
  2260. CHECK_BRESULT( bResult );
  2261. if( strTemp.Compare( V_NOT_AVAILABLE ) != 0 )
  2262. {
  2263. // Got the domain name...Store it.
  2264. StringCopy( szDomain, (LPCWSTR)strTemp, MAX_STRING_LENGTH );
  2265. }
  2266. }
  2267. catch( _com_error & error )
  2268. {
  2269. // erase the last status message
  2270. PrintProgressMsg( m_hOutput, NULL, m_csbi );
  2271. // display the error msg
  2272. WMISaveError( error.Error() );
  2273. ShowMessage( stderr, GetResString( IDS_ERROR ) );
  2274. ShowMessage( stderr, GetReason() );
  2275. // release the interface pointers and exit
  2276. SAFEIRELEASE( pClass );
  2277. SAFEIRELEASE( pEnumClass );
  2278. return FALSE;
  2279. }
  2280. // release the interface pointers and exit
  2281. SAFEIRELEASE( pClass );
  2282. SAFEIRELEASE( pEnumClass );
  2283. return TRUE;
  2284. }
  2285. /*********************************************************************************************
  2286. Routine Description:
  2287. This function gets the User name and the domain name from WMI..
  2288. Arguments:
  2289. [in] szSid : string containing the SID
  2290. [out] szName : string to hold the user name
  2291. [out] szDomain : string to hold the domain name
  2292. Return Value:
  2293. TRUE on SUCCESS
  2294. FALSE on FAILURE
  2295. *********************************************************************************************/
  2296. BOOL CGpResult::GetTerminalServerMode( PUSERINFO pUserInfo )
  2297. {
  2298. // Local variables
  2299. HRESULT hResult = S_OK;
  2300. BOOL bResult = FALSE;
  2301. TCHAR szQueryString[ MAX_QUERY_STRING ];
  2302. TCHAR szTemp[ MAX_STRING_LENGTH ];
  2303. DWORD dwTerminalServerMode;
  2304. IEnumWbemClassObject *pEnumClass = NULL;
  2305. IWbemClassObject *pClass = NULL;
  2306. ULONG ulReturn = 0;
  2307. try
  2308. {
  2309. // set the strings to NULL
  2310. SecureZeroMemory( szQueryString, MAX_QUERY_STRING * sizeof( TCHAR ));
  2311. SecureZeroMemory( szTemp, MAX_STRING_LENGTH * sizeof( TCHAR ) );
  2312. // Form the query string
  2313. StringCopy( szTemp, QUERY_TERMINAL_SERVER_MODE, MAX_STRING_LENGTH );
  2314. StringCchPrintf( szQueryString, MAX_QUERY_STRING, szTemp, pUserInfo->strUserServer);
  2315. // execute the respective query
  2316. hResult = m_pWbemServices->ExecQuery( _bstr_t( QUERY_LANGUAGE ),
  2317. _bstr_t( szQueryString ),
  2318. WBEM_FLAG_FORWARD_ONLY |
  2319. WBEM_FLAG_RETURN_IMMEDIATELY,
  2320. NULL, &pEnumClass );
  2321. CHECK_HRESULT( hResult );
  2322. // set the security parameters
  2323. hResult = SetInterfaceSecurity( pEnumClass, m_pAuthIdentity );
  2324. CHECK_HRESULT( hResult );
  2325. // Get the Terminal server mode
  2326. hResult = pEnumClass->Next( TIME_OUT_NEXT, 1, &pClass, &ulReturn );
  2327. CHECK_HRESULT( hResult );
  2328. // if there are no classes to enumerate break out of the loop
  2329. if( ulReturn == 0 )
  2330. {
  2331. // No classes were retrieved....display msg
  2332. // release the interface pointers and exit
  2333. SAFEIRELEASE( pClass );
  2334. SAFEIRELEASE( pEnumClass );
  2335. return FALSE;
  2336. }
  2337. // Get the class property(Name)
  2338. bResult = PropertyGet( pClass, CPV_TERMINAL_SERVER_MODE, dwTerminalServerMode, 0 );
  2339. CHECK_BRESULT( bResult );
  2340. // Got the terminal server mode ...Store it.
  2341. if( 1 == dwTerminalServerMode )
  2342. {
  2343. pUserInfo->strTerminalServerMode=GetResString(IDS_TS_APPSERVER);
  2344. }
  2345. else if( 0 == dwTerminalServerMode )
  2346. {
  2347. pUserInfo->strTerminalServerMode=GetResString(IDS_TS_REMOTEADMIN);
  2348. }
  2349. else
  2350. {
  2351. pUserInfo->strTerminalServerMode=GetResString(IDS_TS_REMOTEADMIN);
  2352. }
  2353. }
  2354. catch( _com_error & error )
  2355. {
  2356. // erase the last status message
  2357. PrintProgressMsg( m_hOutput, NULL, m_csbi );
  2358. // display the error msg
  2359. WMISaveError( error.Error() );
  2360. // ShowMessage( stderr, GetResString( IDS_ERROR ) );
  2361. // ShowMessage( stderr, GetReason() );
  2362. // release the interface pointers and exit
  2363. SAFEIRELEASE( pClass );
  2364. SAFEIRELEASE( pEnumClass );
  2365. return FALSE;
  2366. }
  2367. // release the interface pointers and exit
  2368. SAFEIRELEASE( pClass );
  2369. SAFEIRELEASE( pEnumClass );
  2370. return TRUE;
  2371. }
  2372. /*********************************************************************************************
  2373. Routine Description:
  2374. This function gets the threshold link speed information.
  2375. Arguments:
  2376. [in] BOOL : set to TRUE if the information is to be retrieved for the computer.
  2377. Return Value:
  2378. TRUE on SUCCESS
  2379. FALSE on FAILURE
  2380. *********************************************************************************************/
  2381. BOOL CGpResult::DisplayThresholdSpeedAndLastTimeInfo( BOOL bComputer )
  2382. {
  2383. // Local variables
  2384. HRESULT hResult = S_OK;
  2385. HKEY hKey = NULL;
  2386. HKEY hRemoteKey = NULL;
  2387. IWbemServices *pDefaultNameSpace = NULL;
  2388. TCHAR szTemp[ MAX_STRING_LENGTH ];
  2389. TCHAR szServer[ MAX_STRING_LENGTH ];
  2390. TCHAR szName[ MAX_STRING_LENGTH ];
  2391. TCHAR szTime[ MAX_STRING_LENGTH ];
  2392. TCHAR szDate[ MAX_STRING_LENGTH ];
  2393. BOOL bResult = FALSE;
  2394. BOOL bLocaleChanged = FALSE;
  2395. BOOL bConnFlag = TRUE;
  2396. CHString strTemp;
  2397. DWORD dwHkey = 0;
  2398. DWORD dwValue;
  2399. DWORD dwResult = 0;
  2400. FILETIME ftWrite;
  2401. FILETIME ftLocal;
  2402. SYSTEMTIME systime;
  2403. LCID lcid;
  2404. SecureZeroMemory( &ftWrite, sizeof(FILETIME) );
  2405. SecureZeroMemory( &ftLocal, sizeof(FILETIME) );
  2406. SecureZeroMemory( &systime, sizeof(SYSTEMTIME) );
  2407. try
  2408. {
  2409. // If we have to get the information from a remote machine then...
  2410. // connect to the remote machine for the last time execution information.
  2411. if ( m_bLocalSystem == FALSE )
  2412. {
  2413. StringCopy( szServer, m_strServerName, MAX_STRING_LENGTH );
  2414. StringCopy( szName, m_strUserName, MAX_STRING_LENGTH );
  2415. bResult = EstablishConnection( szServer, szName, MAX_STRING_LENGTH,
  2416. m_pwszPassword, MAX_STRING_LENGTH, FALSE );
  2417. if( bResult != TRUE )
  2418. {
  2419. strTemp = V_NOT_AVAILABLE;
  2420. }
  2421. else
  2422. {
  2423. switch( GetLastError() )
  2424. {
  2425. case I_NO_CLOSE_CONNECTION:
  2426. bConnFlag = FALSE;
  2427. break;
  2428. case E_LOCAL_CREDENTIALS:
  2429. case ERROR_SESSION_CREDENTIAL_CONFLICT:
  2430. bConnFlag = FALSE;
  2431. break;
  2432. default:
  2433. break;
  2434. }
  2435. }
  2436. // Connect to the remote registry
  2437. StringCopy( szServer , _T( "\\\\" ), MAX_STRING_LENGTH );
  2438. StringConcat( szServer, m_strServerName, MAX_STRING_LENGTH );
  2439. dwResult = RegConnectRegistry( szServer, bComputer ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER,
  2440. &hRemoteKey );
  2441. if( dwResult != ERROR_SUCCESS )
  2442. {
  2443. strTemp = V_NOT_AVAILABLE;
  2444. }
  2445. }
  2446. // Open the last time execution information key
  2447. dwResult = RegOpenKeyEx (bComputer ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER,
  2448. GROUPPOLICY_PATH, 0, KEY_READ, &hKey);
  2449. if( dwResult != ERROR_SUCCESS )
  2450. {
  2451. strTemp = V_NOT_AVAILABLE;
  2452. }
  2453. // Get the last time execution information
  2454. dwResult = RegQueryInfoKey( hKey, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  2455. NULL, &ftWrite );
  2456. if( dwResult == ERROR_SUCCESS )
  2457. {
  2458. FileTimeToLocalFileTime( &ftWrite, &ftLocal );
  2459. FileTimeToSystemTime( &ftLocal, &systime );
  2460. // verify whether console supports the current locale 100% or not
  2461. lcid = GetSupportedUserLocale( &bLocaleChanged );
  2462. // get the formatted date
  2463. GetDateFormat( lcid, 0, &systime, ((bLocaleChanged == TRUE) ? L"MM/dd/yyyy" : NULL),
  2464. szDate, SIZE_OF_ARRAY( szDate ) );
  2465. // now format the date
  2466. GetTimeFormat( LOCALE_USER_DEFAULT, 0, &systime, ((bLocaleChanged == TRUE) ? L"HH:mm:ss" : NULL),
  2467. szTime, SIZE_OF_ARRAY( szTime ) );
  2468. StringCchPrintf( szTemp, SIZE_OF_ARRAY(szTemp), LAST_TIME_OP, _X( szDate ), _X2( szTime ) );
  2469. strTemp = szTemp;
  2470. }
  2471. else
  2472. {
  2473. strTemp = V_NOT_AVAILABLE;
  2474. }
  2475. // Display the retrieved data
  2476. ShowMessage( stdout, GetResString( IDS_LAST_TIME ) );
  2477. ShowMessage( stdout, strTemp );
  2478. ShowMessage( stdout, GetResString( IDS_NEWLINE_TAB ) );
  2479. // if we have opened a connection then close the same.
  2480. if( m_bLocalSystem == FALSE && bConnFlag == TRUE )
  2481. {
  2482. StringCopy( szServer, m_strServerName, MAX_STRING_LENGTH );
  2483. CloseConnection( szServer );
  2484. }
  2485. // Close the registry keys
  2486. if( hKey != NULL )
  2487. {
  2488. RegCloseKey( hKey );
  2489. }
  2490. if( hRemoteKey != NULL )
  2491. {
  2492. RegCloseKey( hRemoteKey );
  2493. }
  2494. // connect to the default namespace
  2495. ConnectWmi( m_pWbemLocator, &pDefaultNameSpace, m_strServerName,
  2496. m_strUserName, m_pwszPassword, &m_pAuthIdentity,
  2497. FALSE, _bstr_t( ROOT_DEFAULT ), &hResult );
  2498. CHECK_HRESULT( hResult );
  2499. // form the key
  2500. if( bComputer == TRUE )
  2501. {
  2502. dwHkey = HKEY_DEF;
  2503. }
  2504. else
  2505. {
  2506. dwHkey = HKEY_CURRENT_USER_DEF;
  2507. }
  2508. // Get the DC name from where the policy was applied last
  2509. RegQueryValueWMI( pDefaultNameSpace, dwHkey, APPLIED_PATH, FPR_APPLIED_FROM,
  2510. strTemp, V_NOT_AVAILABLE );
  2511. // remove the forward slashes (UNC) if exist in the begining of the server name
  2512. if ( IsUNCFormat( strTemp ) == TRUE )
  2513. {
  2514. strTemp = strTemp.Mid( 2 );
  2515. }
  2516. // Display the retrieved data
  2517. ShowMessage( stdout, GetResString( IDS_APPLIED_FROM ) );
  2518. ShowMessage( stdout, strTemp );
  2519. ShowMessage( stdout, GetResString( IDS_NEWLINE_TAB ) );
  2520. // Get the threshold link speed information
  2521. RegQueryValueWMI( pDefaultNameSpace, dwHkey, GPRESULT_PATH, FPR_LINK_SPEED_VALUE, dwValue, (DWORD)-1 );
  2522. if( dwValue == (DWORD)-1 )
  2523. {
  2524. strTemp = DEFAULT_LINK_SPEED;
  2525. }
  2526. else
  2527. {
  2528. StringCchPrintf( szTemp, MAX_STRING_LENGTH, _T( "%d kbps" ), dwValue );
  2529. strTemp = szTemp;
  2530. }
  2531. // Display the retrieved data
  2532. ShowMessage( stdout, GetResString( IDS_THRESHOLD_LINK_SPEED ) );
  2533. ShowMessage( stdout, strTemp );
  2534. }
  2535. catch( _com_error & error )
  2536. {
  2537. WMISaveError( error.Error() );
  2538. ShowMessage( stderr, GetResString( IDS_ERROR ) );
  2539. ShowMessage( stderr, GetReason() );
  2540. // release the allocated variables
  2541. SAFEIRELEASE( pDefaultNameSpace );
  2542. return FALSE;
  2543. }
  2544. catch( CHeap_Exception )
  2545. {
  2546. // display the error message
  2547. SetLastError( (DWORD)E_OUTOFMEMORY );
  2548. SaveLastError();
  2549. ShowMessage( stderr, GetResString( IDS_ERROR ) );
  2550. ShowMessage( stderr, GetReason() );
  2551. SAFEIRELEASE( pDefaultNameSpace );
  2552. return FALSE;
  2553. }
  2554. // release the interface pointer
  2555. SAFEIRELEASE( pDefaultNameSpace );
  2556. return TRUE;
  2557. }
  2558. /*********************************************************************************************
  2559. Routine Description:
  2560. This function sorts the applied Gpo data in the order applied.
  2561. Arguments:
  2562. [in/out] TARRAY : Array to be sorted
  2563. Return Value:
  2564. None
  2565. *********************************************************************************************/
  2566. VOID SortAppliedData( TARRAY arrAppliedData )
  2567. {
  2568. // Local variables
  2569. TARRAY arrSortedData = NULL;
  2570. DWORD dwMax = 0;
  2571. DWORD dwCount = 0;
  2572. DWORD dwi = 0;
  2573. DWORD dwOrder = 0;
  2574. DWORD dwIndex = 0;
  2575. BOOL bNobreak = TRUE;
  2576. // Create the dynamic array to hold the sorted data temporarily
  2577. arrSortedData = CreateDynamicArray( );
  2578. if( NULL == arrSortedData || NULL == arrAppliedData)
  2579. {
  2580. //simply return, at most it can print non sorted data, that's all
  2581. SetLastError((DWORD)E_OUTOFMEMORY );
  2582. return;
  2583. }
  2584. dwCount = DynArrayGetCount( arrAppliedData );
  2585. // Get the max applied order in the array
  2586. for( dwi = 0; dwi < dwCount; dwi++ )
  2587. {
  2588. dwOrder = DynArrayItemAsDWORD2( arrAppliedData, dwi, COL_ORDER );
  2589. if( dwOrder > dwMax )
  2590. {
  2591. dwMax = dwOrder;
  2592. }
  2593. }
  2594. // Create the sorted array in the descending order of the applied order
  2595. for( dwi = 0; dwi < dwCount; dwi++ )
  2596. {
  2597. // re-set the index variable
  2598. dwIndex = 0;
  2599. // Get the index of the row whose order = dwMax
  2600. while( bNobreak )
  2601. {
  2602. dwOrder = DynArrayItemAsDWORD2( arrAppliedData, dwIndex, COL_ORDER );
  2603. if( dwOrder == dwMax )
  2604. {
  2605. break;
  2606. }
  2607. // increment the index
  2608. dwIndex++;
  2609. // Additional check...just in case the order does not exist
  2610. // avoid an AV
  2611. if( dwIndex == dwCount )
  2612. {
  2613. break;
  2614. }
  2615. }
  2616. // Additional check...just in case the order does not exist
  2617. // avoid an AV
  2618. if( dwIndex == dwCount )
  2619. {
  2620. // could not find the index
  2621. // decrement the max order
  2622. dwMax--;
  2623. continue;
  2624. }
  2625. // Store the contents of the row
  2626. DynArrayAppendRow( arrSortedData, COL_MAX );
  2627. DynArraySetString2( arrSortedData, dwi, COL_DATA,
  2628. DynArrayItemAsString2( arrAppliedData, dwIndex, COL_DATA ), 0 );
  2629. DynArraySetDWORD2( arrSortedData, dwi, COL_ORDER, dwOrder );
  2630. // decrement the max order
  2631. dwMax--;
  2632. }
  2633. // copy the sorted data onto the applied data array
  2634. for( dwi = 0; dwi < dwCount; dwi++ )
  2635. {
  2636. DynArraySetString2( arrAppliedData, dwi, COL_DATA,
  2637. DynArrayItemAsString2( arrSortedData, dwi, COL_DATA ), 0 );
  2638. DynArraySetDWORD2( arrAppliedData, dwi, COL_ORDER,
  2639. DynArrayItemAsDWORD2( arrSortedData, dwi, COL_ORDER ) );
  2640. }
  2641. // destroy the temporarily created dynamic array
  2642. DESTROY_ARRAY( arrSortedData );
  2643. return;
  2644. }
  2645. /*********************************************************************************************
  2646. Routine Description:
  2647. This function retrieves the FQDN from ADSI
  2648. Arguments:
  2649. [out] TCHAR [] : Array to hold the FQDN
  2650. [in] BOOL : flag to specify wether the FQDN is to be retrieved for
  2651. the computer or the user
  2652. [in] LPCTSTR : The name for whom the FQDN is to be retrieved
  2653. Return Value:
  2654. None
  2655. *********************************************************************************************/
  2656. VOID CGpResult::GetFQDNFromADSI( TCHAR szFQDN[], BOOL bComputer, LPCTSTR pszName )
  2657. {
  2658. // Local variables
  2659. HANDLE hDS = NULL;
  2660. DWORD dwReturn = 0;
  2661. DS_NAME_RESULT *pNameResult = NULL;
  2662. SecureZeroMemory( szFQDN, MAX_STRING_LENGTH * sizeof( TCHAR ) );
  2663. // Bind to the ADSI directory service
  2664. dwReturn = DsBindWithCred( NULL, m_strADSIDomain, m_pAuthIdentity, &hDS );
  2665. if( dwReturn != NO_ERROR )
  2666. {
  2667. return;
  2668. }
  2669. // Get the FQDN information
  2670. dwReturn = DsCrackNames( hDS, DS_NAME_NO_FLAGS,
  2671. bComputer ? DS_DISPLAY_NAME : DS_NT4_ACCOUNT_NAME, DS_FQDN_1779_NAME,
  2672. 1, &pszName, &pNameResult );
  2673. if( dwReturn != DS_NAME_NO_ERROR )
  2674. {
  2675. return;
  2676. }
  2677. // store the retrieved FQDN
  2678. StringCopy( szFQDN, pNameResult->rItems->pName, MAX_STRING_LENGTH );
  2679. // Free the handle to the ADSI directory services
  2680. DsUnBind( &hDS );
  2681. // Free the allocated memory
  2682. DsFreeNameResult( pNameResult );
  2683. return;
  2684. }