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.

721 lines
22 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation
  3. Module Name:
  4. wsuser.cpp
  5. Abstract:
  6. This file can be used to initializes all the objects for access token ,
  7. user, groups , privileges and displays the user name with respective
  8. security identifiers (SID), privileges, logon identifier (logon ID)
  9. in the current access token on a local system or a remote system.
  10. Authors:
  11. Christophe Robert
  12. Revision History:
  13. 02-July-2001 : Updated by Wipro Technologies.
  14. --*/
  15. //common header files needed for this file
  16. #include "pch.h"
  17. #include "CommonHeaderFiles.h"
  18. WsUser::WsUser ( VOID )
  19. /*++
  20. Routine Description:
  21. This function intializes the members of WsUser class.
  22. Arguments:
  23. None
  24. Return Value:
  25. None
  26. --*/
  27. {
  28. // intialize member variables
  29. lpLogonId = NULL ;
  30. lpPriv = NULL ;
  31. lpwGroups = NULL ;
  32. dwnbGroups = 0 ;
  33. }
  34. WsUser::~WsUser ( VOID )
  35. /*++
  36. Routine Description:
  37. This function deallocates the members of WsUser class.
  38. Arguments:
  39. None
  40. Return Value:
  41. None
  42. --*/
  43. {
  44. /// sub-local varible
  45. WORD wloop = 0 ;
  46. //release memory
  47. if(NULL != lpLogonId){
  48. delete lpLogonId ;
  49. }
  50. //release memory
  51. if(NULL != lpPriv) {
  52. for(wloop = 0 ; wloop < dwnbPriv ; wloop++){
  53. delete lpPriv[wloop] ;
  54. }
  55. FreeMemory ((LPVOID *) &lpPriv) ;
  56. }
  57. //release memory
  58. if(NULL != lpwGroups) {
  59. for(wloop = 0 ; wloop < dwnbGroups ; wloop++){
  60. delete lpwGroups[wloop] ;
  61. }
  62. FreeMemory ((LPVOID *) &lpwGroups ) ;
  63. }
  64. }
  65. DWORD
  66. WsUser::Init ( VOID )
  67. /*++
  68. Routine Description:
  69. This function initializes all objects for access token , user, groups and privileges.
  70. Arguments:
  71. None
  72. Return Value:
  73. EXIT_FAILURE : On failure
  74. EXIT_SUCCESS : On success
  75. --*/
  76. {
  77. //sub-local variable
  78. DWORD dwErr = 0 ;
  79. // Open current token
  80. if((dwErr = wToken.Open()) != EXIT_SUCCESS){
  81. ShowLastErrorEx ( stderr, SLE_TYPE_ERROR | SLE_SYSTEM );
  82. // return 1 for failure
  83. return EXIT_FAILURE ;
  84. }
  85. // Get SIDs
  86. if((dwErr = wToken.InitUserSid (&wUserSid)) != EXIT_SUCCESS){
  87. // display an error message with respect to the GetLastError()
  88. ShowLastErrorEx ( stderr, SLE_TYPE_ERROR | SLE_SYSTEM );
  89. //return 1 for failure
  90. return EXIT_FAILURE ;
  91. }
  92. // Get Groups
  93. if((dwErr = wToken.InitGroups (&lpwGroups, &lpLogonId, &dwnbGroups))
  94. != EXIT_SUCCESS){
  95. // display an error message with respect to the GetLastError()
  96. ShowLastErrorEx ( stderr, SLE_TYPE_ERROR | SLE_SYSTEM );
  97. //return 1 for failure
  98. return EXIT_FAILURE ;
  99. }
  100. // Get Privileges
  101. if((dwErr = wToken.InitPrivs (&lpPriv, &dwnbPriv)) != EXIT_SUCCESS){
  102. // display an error message with respect to GetLastError()
  103. ShowLastErrorEx ( stderr, SLE_TYPE_ERROR | SLE_SYSTEM );
  104. //return 1 for failure
  105. return EXIT_FAILURE ;
  106. }
  107. //return 0 for success
  108. return EXIT_SUCCESS ;
  109. }
  110. DWORD
  111. WsUser::DisplayGroups (
  112. IN DWORD dwFormatType
  113. )
  114. /*++
  115. Routine Description:
  116. This function displays the group names.
  117. Arguments:
  118. [IN] DWORD dwFormatType : Format type i.,e LIST, CSV or TABLE
  119. Return Value:
  120. EXIT_SUCCESS : On success
  121. EXIT_FAILURE : On failure
  122. --*/
  123. {
  124. //sub-local variables
  125. DWORD dwArrSize = 0 ;
  126. DWORD dwColCount = 0 ;
  127. DWORD dw = 0 ;
  128. DWORD dwCount = 0 ;
  129. WORD wloop = 0 ;
  130. DWORD dwGroupNameColLen = 0;
  131. DWORD dwGroupNameLen = 0;
  132. DWORD dwGroupTmpNameLen = 0;
  133. DWORD dwGroupSidColLen = 0;
  134. DWORD dwGroupSidLen = 0;
  135. DWORD dwGroupTmpSidLen = 0;
  136. DWORD dwGroupAttribColLen = 0;
  137. DWORD dwGroupAttribLen = 0;
  138. DWORD dwGroupTmpAttribLen = 0;
  139. DWORD dwGroupTypeCol = 0;
  140. DWORD dwGroupType = 0;
  141. DWORD dwGroupTmpType = 0;
  142. DWORD SidNameUse = 0;
  143. DWORD dwSize = 0;
  144. WCHAR wszGroupName[ 2 * MAX_RES_STRING ];
  145. WCHAR wszGroupSid [ MAX_RES_STRING ];
  146. LPCWSTR wszPartialName = NULL;
  147. WCHAR wszDomainAttr[MAX_STRING_LENGTH] ;
  148. WCHAR wszSidType[MAX_STRING_LENGTH] ;
  149. WCHAR wszDomainAttrib[ 2 * MAX_RES_STRING ];
  150. WCHAR wszSidName[ 2 * MAX_RES_STRING ];
  151. // initialize the variables
  152. SecureZeroMemory ( wszGroupName, SIZE_OF_ARRAY(wszGroupName) );
  153. SecureZeroMemory ( wszGroupSid, SIZE_OF_ARRAY(wszGroupSid) );
  154. SecureZeroMemory ( wszDomainAttr, SIZE_OF_ARRAY(wszDomainAttr) );
  155. SecureZeroMemory ( wszSidType, SIZE_OF_ARRAY(wszSidType) );
  156. SecureZeroMemory ( wszDomainAttrib, SIZE_OF_ARRAY(wszDomainAttrib) );
  157. SecureZeroMemory ( wszSidName, SIZE_OF_ARRAY(wszSidName) );
  158. // get the maximum length of group name and sid
  159. for( wloop = 0 , dwCount = 0 ; wloop < dwnbGroups ; wloop++ , dwCount++ ) {
  160. // display group names along with the SID for a specified format.
  161. if ( EXIT_SUCCESS != ( lpwGroups[wloop]->DisplayGroupName ( wszGroupName, wszGroupSid, &SidNameUse ) ) )
  162. {
  163. return EXIT_FAILURE;
  164. }
  165. dwSize = SIZE_OF_ARRAY(wszDomainAttrib);
  166. wToken.GetDomainAttributes(wToken.dwDomainAttributes[wloop], wszDomainAttrib, dwSize);
  167. //get attributes
  168. StringCopy(wszDomainAttr, wszDomainAttrib, SIZE_OF_ARRAY(wszSidType));
  169. dwSize = SIZE_OF_ARRAY(wszSidName);
  170. GetDomainType ( SidNameUse , wszSidName, dwSize );
  171. //get type
  172. StringCopy(wszSidType, wszSidName, SIZE_OF_ARRAY(wszSidType));;
  173. // block the domain\None name
  174. wszPartialName = FindString ( wszGroupSid, STRING_SID, 0 );
  175. if ( ( NULL != wszPartialName ) || ( 0 == StringLength (wszGroupName, 0) ) )
  176. {
  177. wszPartialName = NULL;
  178. dwCount--;
  179. continue;
  180. }
  181. // get the max length of group name
  182. dwGroupTmpNameLen = StringLengthInBytes(wszGroupName);
  183. if ( dwGroupNameLen < dwGroupTmpNameLen )
  184. {
  185. dwGroupNameLen = dwGroupTmpNameLen;
  186. }
  187. // get the max length of type
  188. dwGroupTmpType = StringLengthInBytes (wszSidType);
  189. if ( dwGroupType < dwGroupTmpType )
  190. {
  191. dwGroupType = dwGroupTmpType;
  192. }
  193. // get the max length of SID
  194. dwGroupTmpSidLen = StringLengthInBytes (wszGroupSid);
  195. if ( dwGroupSidLen < dwGroupTmpSidLen )
  196. {
  197. dwGroupSidLen = dwGroupTmpSidLen;
  198. }
  199. // get the max length of Attributes
  200. dwGroupTmpAttribLen = StringLengthInBytes (wszDomainAttr);
  201. if ( dwGroupAttribLen < dwGroupTmpAttribLen )
  202. {
  203. dwGroupAttribLen = dwGroupTmpAttribLen;
  204. }
  205. }
  206. //
  207. //To avoid localization problems, get the maximum length of column name and
  208. // values of respective columns
  209. //
  210. // Get the maximum length of a column name "Group Name"
  211. dwGroupNameColLen = StringLengthInBytes( GetResString(IDS_COL_GROUP_NAME) );
  212. if ( dwGroupNameColLen > dwGroupNameLen )
  213. {
  214. dwGroupNameLen = dwGroupNameColLen;
  215. }
  216. // Get the maximum length of a column name "Type"
  217. dwGroupTypeCol = StringLengthInBytes( GetResString(IDS_COL_TYPE_GROUP) );
  218. if ( dwGroupTypeCol > dwGroupType )
  219. {
  220. dwGroupType = dwGroupTypeCol;
  221. }
  222. // Get the maximum length of a column name "SID"
  223. dwGroupSidColLen = StringLengthInBytes( GetResString(IDS_COL_GROUP_SID) );
  224. if ( dwGroupSidColLen > dwGroupSidLen )
  225. {
  226. dwGroupSidLen = dwGroupSidColLen;
  227. }
  228. // Get the maximum length of a column name "Attributes"
  229. dwGroupAttribColLen = StringLengthInBytes( GetResString(IDS_COL_ATTRIBUTE) );
  230. if ( dwGroupAttribColLen > dwGroupAttribLen )
  231. {
  232. dwGroupAttribLen = dwGroupAttribColLen;
  233. }
  234. // defining the verbose columns with actual length of values
  235. TCOLUMNS pVerboseCols[] =
  236. {
  237. {L"\0",dwGroupNameLen, SR_TYPE_STRING, COL_FORMAT_STRING, NULL, NULL},
  238. {L"\0",dwGroupType,SR_TYPE_STRING,COL_FORMAT_STRING,NULL,NULL},
  239. {L"\0",dwGroupSidLen,SR_TYPE_STRING,COL_FORMAT_STRING,NULL,NULL},
  240. {L"\0",dwGroupAttribLen,SR_TYPE_STRING,COL_FORMAT_STRING,NULL,NULL},
  241. };
  242. // get the size of pVerboseCols
  243. dwArrSize = SIZE_OF_ARRAY( pVerboseCols );
  244. //Load the column names for verbose mode
  245. for( dwColCount = IDS_COL_GROUP_NAME , dw = 0 ; dwColCount <= IDS_COL_ATTRIBUTE;
  246. dwColCount++, dw++)
  247. {
  248. StringCopy (pVerboseCols[dw].szColumn , GetResString(dwColCount), MAX_RES_STRING);
  249. }
  250. // create a dynamic array
  251. TARRAY pColData = CreateDynamicArray();
  252. if ( NULL == pColData )
  253. {
  254. SetLastError ((DWORD)E_OUTOFMEMORY);
  255. SaveLastError();
  256. ShowLastErrorEx ( stderr, SLE_TYPE_ERROR | SLE_INTERNAL );
  257. return EXIT_FAILURE;
  258. }
  259. //loop through and display the group names
  260. for( wloop = 0 , dwCount = 0 ; wloop < dwnbGroups ; wloop++ , dwCount++ ) {
  261. // display the group name and SID
  262. if ( EXIT_SUCCESS != ( lpwGroups[wloop]->DisplayGroupName ( wszGroupName, wszGroupSid, &SidNameUse ) ) )
  263. {
  264. DestroyDynamicArray(&pColData);
  265. return EXIT_FAILURE;
  266. }
  267. dwSize = SIZE_OF_ARRAY(wszDomainAttrib);
  268. wToken.GetDomainAttributes(wToken.dwDomainAttributes[wloop], wszDomainAttrib, dwSize );
  269. //get attributes
  270. StringCopy(wszDomainAttr, wszDomainAttrib, SIZE_OF_ARRAY(wszSidType));
  271. dwSize = SIZE_OF_ARRAY(wszSidName);
  272. GetDomainType ( SidNameUse , wszSidName, dwSize);
  273. //get type
  274. StringCopy(wszSidType, wszSidName, SIZE_OF_ARRAY(wszSidType));
  275. // block the domain\None name
  276. wszPartialName = FindString ( wszGroupSid, STRING_SID, 0 );
  277. if ( ( NULL != wszPartialName ) || ( 0 == StringLength (wszGroupName, 0) ) )
  278. {
  279. wszPartialName = NULL;
  280. dwCount--;
  281. continue;
  282. }
  283. //Start appending to the 2D array
  284. DynArrayAppendRow(pColData,dwArrSize);
  285. //Insert the user name
  286. DynArraySetString2(pColData, dwCount, GROUP_NAME_COL_NUMBER, _X(wszGroupName), 0);
  287. //Insert the domain type
  288. DynArraySetString2(pColData, dwCount, GROUP_TYPE_COL_NUMBER, wszSidType, 0);
  289. //Insert the SID string
  290. DynArraySetString2(pColData, dwCount, GROUP_SID_COL_NUMBER, _X(wszGroupSid), 0);
  291. //Insert Attributes
  292. DynArraySetString2(pColData, dwCount, GROUP_ATT_COL_NUMBER, wszDomainAttr, 0);
  293. }
  294. // 1) If the display format is CSV.. then we should not display column headings..
  295. // 2) If /NH is specified ...then we should not display column headings..
  296. if ( !(( SR_FORMAT_CSV == dwFormatType ) || ((dwFormatType & SR_HIDECOLUMN) == SR_HIDECOLUMN)))
  297. {
  298. // display heading before displaying group name information
  299. ShowMessage ( stdout, L"\n" );
  300. ShowMessage ( stdout, GetResString ( IDS_LIST_GROUP_NAMES ) );
  301. ShowMessage ( stdout, GetResString ( IDS_DISPLAY_GROUP_DASH ) );
  302. }
  303. // display atual group names along with SIDs
  304. ShowResults(dwArrSize, pVerboseCols, dwFormatType, pColData);
  305. // release memory
  306. DestroyDynamicArray(&pColData);
  307. // return success
  308. return EXIT_SUCCESS ;
  309. }
  310. DWORD
  311. WsUser::DisplayLogonId ()
  312. /*++
  313. Routine Description:
  314. This function displays the logon ID.
  315. Arguments:
  316. [IN] DWORD dwFormatType : Format type i.,e LIST, CSV or TABLE
  317. Return Value:
  318. EXIT_SUCCESS : On success
  319. EXIT_FAILURE : On failure
  320. --*/
  321. {
  322. // sub-local variables
  323. WCHAR wszSid [ MAX_RES_STRING ] ;
  324. // initialize the variables
  325. SecureZeroMemory ( wszSid, SIZE_OF_ARRAY(wszSid) );
  326. DWORD dwRet = 0 ;
  327. // get logon id
  328. if ( EXIT_SUCCESS != ( dwRet = lpLogonId->DisplaySid ( wszSid ) ) )
  329. {
  330. return dwRet;
  331. }
  332. // display logon id
  333. ShowMessage ( stdout, _X(wszSid) );
  334. ShowMessage ( stdout, L"\n" );
  335. return EXIT_SUCCESS ;
  336. }
  337. DWORD
  338. WsUser::DisplayPrivileges (
  339. IN DWORD dwFormatType
  340. )
  341. /*++
  342. Routine Description:
  343. This function displays the privileges
  344. Arguments:
  345. [IN] DWORD dwFormatType : Format type i.,e LIST, CSV or TABLE
  346. Return Value:
  347. EXIT_SUCCESS : On success
  348. EXIT_FAILURE : On failure
  349. --*/
  350. {
  351. //sub-local variables
  352. WCHAR wszPrivName [ MAX_RES_STRING ];
  353. WCHAR wszPrivDisplayName [ MAX_RES_STRING ];
  354. WCHAR wszState [ MAX_RES_STRING ];
  355. DWORD dwErr = 0 ;
  356. WORD wloop = 0 ;
  357. DWORD dwColCount = 0 ;
  358. DWORD dwCount = 0 ;
  359. DWORD dw = 0 ;
  360. DWORD dwArrSize = 0 ;
  361. DWORD dwStateColLen = 0;
  362. DWORD dwPrivNameColLen = 0;
  363. DWORD dwPrivDescColLen = 0;
  364. DWORD dwStateLen = 0;
  365. DWORD dwTmpStateLen = 0;
  366. DWORD dwPrivNameLen = 0;
  367. DWORD dwTmpPrivNameLen = 0;
  368. DWORD dwPrivDispNameLen = 0;
  369. DWORD dwTmpPrivDispNameLen = 0;
  370. // initialize the variables
  371. SecureZeroMemory ( wszPrivName, SIZE_OF_ARRAY(wszPrivName) );
  372. SecureZeroMemory ( wszPrivDisplayName, SIZE_OF_ARRAY(wszPrivDisplayName) );
  373. SecureZeroMemory ( wszState, SIZE_OF_ARRAY(wszState) );
  374. // get the length of state, pivilege name, and display name
  375. for( wloop = 0 , dwCount = 0 ; wloop < dwnbPriv ; wloop++, dwCount++) {
  376. // check whether the privilege is enabled or not
  377. if(lpPriv[wloop]->IsEnabled() == TRUE )
  378. {
  379. // copy the status as .. enabled..
  380. StringCopy ( wszState, GetResString ( IDS_STATE_ENABLED ), SIZE_OF_ARRAY(wszState) );
  381. }
  382. else
  383. {
  384. // copy the status as .. disabled..
  385. StringCopy ( wszState, GetResString ( IDS_STATE_DISABLED ), SIZE_OF_ARRAY(wszState) );
  386. }
  387. // get the privilege name and description
  388. if((dwErr = lpPriv[wloop]->GetName ( wszPrivName)) != EXIT_SUCCESS ||
  389. (dwErr = lpPriv[wloop]->GetDisplayName ( wszPrivName, wszPrivDisplayName ))
  390. != EXIT_SUCCESS){
  391. // return GetLastError()
  392. return dwErr ;
  393. }
  394. // get the length of state
  395. dwTmpStateLen = StringLengthInBytes (wszState);
  396. if ( dwStateLen < dwTmpStateLen )
  397. {
  398. dwStateLen = dwTmpStateLen;
  399. }
  400. // get the length privilege name
  401. dwTmpPrivNameLen = StringLengthInBytes (wszPrivName);
  402. if ( dwPrivNameLen < dwTmpPrivNameLen )
  403. {
  404. dwPrivNameLen = dwTmpPrivNameLen;
  405. }
  406. // get the length of privilege display name
  407. dwTmpPrivDispNameLen = StringLengthInBytes (wszPrivDisplayName);
  408. if ( dwPrivDispNameLen < dwTmpPrivDispNameLen )
  409. {
  410. dwPrivDispNameLen = dwTmpPrivDispNameLen;
  411. }
  412. }
  413. //
  414. //To avoid localization problems, get the maximum length of column name and
  415. // values of respective columns
  416. //
  417. // Get the maximum length of a column name "Privilege Name"
  418. dwPrivNameColLen = StringLengthInBytes( GetResString(IDS_COL_PRIV_NAME) );
  419. if ( dwPrivNameColLen > dwPrivNameLen )
  420. {
  421. dwPrivNameLen = dwPrivNameColLen;
  422. }
  423. // Get the maximum length of a column name "Privilege Description"
  424. dwPrivDescColLen = StringLengthInBytes( GetResString(IDS_COL_PRIV_DESC) );
  425. if ( dwPrivDescColLen > dwPrivDispNameLen )
  426. {
  427. dwPrivDispNameLen = dwPrivDescColLen;
  428. }
  429. // Get the maximum length of a column name "State"
  430. dwStateColLen = StringLengthInBytes ( GetResString(IDS_COL_PRIV_STATE));
  431. if ( dwStateColLen > dwStateLen )
  432. {
  433. dwStateLen = dwStateColLen;
  434. }
  435. // create a dynamic array
  436. TARRAY pColData = CreateDynamicArray();
  437. // defining verbose columns
  438. TCOLUMNS pVerboseCols[] =
  439. {
  440. {L"\0",dwPrivNameLen, SR_TYPE_STRING, COL_FORMAT_STRING, NULL, NULL},
  441. {L"\0",dwPrivDispNameLen,SR_TYPE_STRING,COL_FORMAT_STRING,NULL,NULL},
  442. {L"\0",dwStateLen,SR_TYPE_STRING,COL_FORMAT_STRING,NULL,NULL}
  443. };
  444. // get number of columns
  445. dwArrSize = SIZE_OF_ARRAY( pVerboseCols );
  446. //Load the column names for verbose mode
  447. for( dwColCount = IDS_COL_PRIV_NAME , dw = 0 ; dwColCount <= IDS_COL_PRIV_STATE;
  448. dwColCount++, dw++)
  449. {
  450. StringCopy (pVerboseCols[dw].szColumn , GetResString(dwColCount), MAX_RES_STRING);
  451. }
  452. // get the pivilege name, display name and state
  453. for( wloop = 0 , dwCount = 0 ; wloop < dwnbPriv ; wloop++, dwCount++) {
  454. if(lpPriv[wloop]->IsEnabled() == TRUE )
  455. {
  456. // copy the status as ... enabled..
  457. StringCopy ( wszState, GetResString ( IDS_STATE_ENABLED ), SIZE_OF_ARRAY(wszState) );
  458. }
  459. else
  460. {
  461. // copy the status as .. disabled..
  462. StringCopy ( wszState, GetResString ( IDS_STATE_DISABLED ), SIZE_OF_ARRAY(wszState) );
  463. }
  464. if((dwErr = lpPriv[wloop]->GetName ( wszPrivName)) != EXIT_SUCCESS ||
  465. (dwErr = lpPriv[wloop]->GetDisplayName ( wszPrivName, wszPrivDisplayName ))
  466. != EXIT_SUCCESS){
  467. // release memory
  468. DestroyDynamicArray(&pColData);
  469. // return GetLastError()
  470. return dwErr ;
  471. }
  472. //Start appending to the 2D array
  473. DynArrayAppendRow( pColData, dwArrSize );
  474. //Insert the privilege name
  475. DynArraySetString2(pColData, dwCount, PRIVNAME_COL_NUMBER, _X(wszPrivName), 0);
  476. //Insert the privilege display name
  477. DynArraySetString2(pColData, dwCount, PRIVDESC_COL_NUMBER, _X(wszPrivDisplayName), 0);
  478. //Insert the state
  479. DynArraySetString2(pColData, dwCount, PRIVSTATE_COL_NUMBER, _X(wszState), 0);
  480. }
  481. // 1) If the display format is CSV.. then we should not display column headings..
  482. // 2) If /NH is specified ...then we should not display column headings..
  483. if ( !(( SR_FORMAT_CSV == dwFormatType ) || ((dwFormatType & SR_HIDECOLUMN) == SR_HIDECOLUMN)))
  484. {
  485. // display the the headings before displaying the actual values
  486. ShowMessage ( stdout, L"\n" );
  487. ShowMessage ( stdout, GetResString ( IDS_LIST_PRIV_NAMES ) );
  488. ShowMessage ( stdout, GetResString ( IDS_DISPLAY_PRIV_DASH ) );
  489. }
  490. // display privilege name, description and status values
  491. ShowResults(dwArrSize, pVerboseCols, dwFormatType, pColData);
  492. // release memory
  493. DestroyDynamicArray(&pColData);
  494. // return success
  495. return EXIT_SUCCESS ;
  496. }
  497. DWORD
  498. WsUser::DisplayUser (
  499. IN DWORD dwFormatType,
  500. IN DWORD dwNameFormat
  501. )
  502. /*++
  503. Routine Description:
  504. This function calls the methods to display the user name and SID.
  505. Arguments:
  506. [IN] DWORD dwFormatType : Format type i.,e LIST, CSV or TABLE
  507. [IN] DWORD dwNameFormat : Name format either UPN or FQDN
  508. Return Value:
  509. EXIT_SUCCESS : On success
  510. EXIT_FAILURE : On failure
  511. --*/
  512. {
  513. // sub-local variables
  514. DWORD dwRetVal = 0;
  515. // get logged-on user name
  516. dwRetVal = wUserSid.DisplayAccountName ( dwFormatType, dwNameFormat );
  517. if( 0 != dwRetVal )
  518. {
  519. // return GetLastError()
  520. return dwRetVal;
  521. }
  522. // return success
  523. return EXIT_SUCCESS ;
  524. }
  525. VOID
  526. WsUser::GetDomainType (
  527. IN DWORD NameUse,
  528. OUT LPWSTR szSidNameUse,
  529. IN DWORD dwSize
  530. )
  531. /*++
  532. Routine Description:
  533. Gets the domain type
  534. Arguments:
  535. [IN] NameUse : Specifies SDI use name value
  536. [OUT] szSidNameUse : Buffer for SID Name
  537. [IN] dwSize : size of Sid name
  538. Return Value:
  539. EXIT_SUCCESS : On success
  540. EXIT_FAILURE : On failure
  541. --*/
  542. {
  543. //local variables
  544. WCHAR szSidType[2 * MAX_STRING_LENGTH];
  545. // initialize the variables
  546. SecureZeroMemory ( szSidType, SIZE_OF_ARRAY(szSidType) );
  547. //store appropriate type name with respect to NameUse value.
  548. switch( NameUse )
  549. {
  550. case SidTypeUser:
  551. StringCopy ( szSidType, GetResString(IDS_TYPE_USER), SIZE_OF_ARRAY(szSidType) );
  552. break;
  553. case SidTypeGroup:
  554. StringCopy ( szSidType, GetResString(IDS_TYPE_GROUP), SIZE_OF_ARRAY(szSidType) );
  555. break;
  556. case SidTypeDomain:
  557. StringCopy ( szSidType, GetResString(IDS_TYPE_DOMAIN), SIZE_OF_ARRAY(szSidType) );
  558. break;
  559. case SidTypeAlias:
  560. StringCopy ( szSidType, GetResString(IDS_TYPE_ALIAS), SIZE_OF_ARRAY(szSidType) );
  561. break;
  562. case SidTypeWellKnownGroup:
  563. StringCopy ( szSidType, GetResString(IDS_TYPE_WELLKNOWN), SIZE_OF_ARRAY(szSidType) );
  564. break;
  565. case SidTypeDeletedAccount:
  566. StringCopy ( szSidType, GetResString(IDS_TYPE_DELETACCOUNT), SIZE_OF_ARRAY(szSidType) );
  567. break;
  568. case SidTypeInvalid:
  569. StringCopy ( szSidType, GetResString(IDS_TYPE_INVALIDSID), SIZE_OF_ARRAY(szSidType) );
  570. break;
  571. case SidTypeUnknown:
  572. default:
  573. StringCopy ( szSidType, GetResString(IDS_TYPE_UNKNOWN), SIZE_OF_ARRAY(szSidType) );
  574. break;
  575. }
  576. // Copy SID Name
  577. StringCopy (szSidNameUse, szSidType, dwSize);
  578. //return success
  579. return;
  580. }