Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

882 lines
23 KiB

  1. /****************************************************************************
  2. PROGRAM: TOKEDIT.C
  3. PURPOSE: Displays and allows the user to edit the contents of a token
  4. ****************************************************************************/
  5. #include "PVIEWP.h"
  6. #include "string.h"
  7. INT_PTR APIENTRY TokenEditDlgProc(HWND, UINT, WPARAM, LPARAM);
  8. INT_PTR APIENTRY MoreDlgProc(HWND, UINT, WPARAM, LPARAM);
  9. BOOL TokenEditDlgInit(HWND);
  10. BOOL TokenEditDlgEnd(HWND, BOOL);
  11. BOOL EnablePrivilege(HWND, BOOL);
  12. BOOL EnableGroup(HWND, BOOL);
  13. BOOL SetDefaultOwner(HWND);
  14. BOOL SetPrimaryGroup(HWND);
  15. BOOL MoreDlgInit(HWND hDlg, LPARAM lParam);
  16. BOOL DisplayMyToken(HWND);
  17. /****************************************************************************
  18. FUNCTION: EditToken
  19. PURPOSE: Displays and allows the user to edit a token
  20. RETURNS: TRUE on success, FALSE on failure
  21. ****************************************************************************/
  22. BOOL EditToken(
  23. HWND hwndParent,
  24. HANDLE Token,
  25. LPWSTR Name
  26. )
  27. {
  28. DLGPROC lpProc;
  29. int Result;
  30. HANDLE hMyToken;
  31. HANDLE Instance;
  32. hMyToken = OpenMyToken(Token, Name);
  33. if (hMyToken == NULL) {
  34. return(FALSE);
  35. }
  36. //
  37. // Get the application instance handle
  38. //
  39. Instance = (HANDLE)(NtCurrentPeb()->ImageBaseAddress);
  40. ASSERT(Instance != 0);
  41. lpProc = (DLGPROC)MakeProcInstance(TokenEditDlgProc, Instance);
  42. Result = (int)DialogBoxParam(Instance,(LPSTR)IDD_MAIN, hwndParent, lpProc, (LPARAM)hMyToken);
  43. FreeProcInstance(lpProc);
  44. return(TRUE);
  45. }
  46. /****************************************************************************
  47. FUNCTION: TokenEditDlgProc(HWND, unsigned, WORD, LONG)
  48. PURPOSE: Processes messages
  49. MESSAGES:
  50. WM_COMMAND - application menu (About dialog box)
  51. WM_DESTROY - destroy window
  52. COMMENTS:
  53. ****************************************************************************/
  54. INT_PTR APIENTRY TokenEditDlgProc(hDlg, message, wParam, lParam)
  55. HWND hDlg;
  56. UINT message;
  57. WPARAM wParam;
  58. LPARAM lParam;
  59. {
  60. DLGPROC lpProc;
  61. HANDLE hMyToken = (HANDLE)GetWindowLongPtr(hDlg, GWLP_USERDATA);
  62. switch (message) {
  63. case WM_INITDIALOG:
  64. SetWindowLongPtr(hDlg, GWLP_USERDATA, lParam);
  65. if (!TokenEditDlgInit(hDlg)) {
  66. // Failed to initialize dialog, get out
  67. EndDialog(hDlg, FALSE);
  68. }
  69. return (TRUE);
  70. case WM_COMMAND:
  71. switch (LOWORD(wParam)) {
  72. case IDOK:
  73. // we're done, drop through to quit dialog....
  74. case IDCANCEL:
  75. TokenEditDlgEnd(hDlg, LOWORD(wParam) == IDOK);
  76. EndDialog(hDlg, TRUE);
  77. return TRUE;
  78. case IDB_DISABLEPRIVILEGE:
  79. case IDB_ENABLEPRIVILEGE:
  80. EnablePrivilege(hDlg, LOWORD(wParam) == IDB_ENABLEPRIVILEGE);
  81. return(TRUE);
  82. case IDB_DISABLEGROUP:
  83. case IDB_ENABLEGROUP:
  84. EnableGroup(hDlg, LOWORD(wParam) == IDB_ENABLEGROUP);
  85. return(TRUE);
  86. case IDC_DEFAULTOWNER:
  87. SetDefaultOwner(hDlg);
  88. return(TRUE);
  89. case IDC_PRIMARYGROUP:
  90. SetPrimaryGroup(hDlg);
  91. return(TRUE);
  92. case IDB_MORE:
  93. {
  94. HANDLE Instance = (HANDLE)(NtCurrentPeb()->ImageBaseAddress);
  95. lpProc = (DLGPROC)MakeProcInstance(MoreDlgProc, Instance);
  96. DialogBoxParam(Instance,(LPSTR)IDD_MORE, hDlg, lpProc, (LPARAM)hMyToken);
  97. FreeProcInstance(lpProc);
  98. return(TRUE);
  99. }
  100. case IDB_DEFAULT_DACL:
  101. {
  102. HANDLE Token = ((PMYTOKEN)hMyToken)->Token;
  103. LPWSTR Name = ((PMYTOKEN)hMyToken)->Name;
  104. EditTokenDefaultDacl(hDlg, Token, Name);
  105. return(TRUE);
  106. }
  107. default:
  108. // We didn't process this message
  109. return FALSE;
  110. }
  111. break;
  112. default:
  113. // We didn't process this message
  114. return FALSE;
  115. }
  116. // We processed the message
  117. return TRUE;
  118. }
  119. /****************************************************************************
  120. FUNCTION: TokenEditDlgInit(HWND)
  121. PURPOSE: Initialises the controls in the main dialog window.
  122. RETURNS: TRUE on success, FALSE if dialog should be terminated.
  123. ****************************************************************************/
  124. BOOL TokenEditDlgInit(
  125. HWND hDlg
  126. )
  127. {
  128. HANDLE hMyToken = (HANDLE)GetWindowLongPtr(hDlg, GWLP_USERDATA);
  129. WCHAR string[MAX_STRING_LENGTH];
  130. HCURSOR OldCursor;
  131. if (!LsaInit()) {
  132. DbgPrint("PVIEW - LsaInit failed\n");
  133. return(FALSE);
  134. }
  135. OldCursor = SetCursor(LoadCursor(NULL, IDC_WAIT));
  136. DisplayMyToken(hDlg);
  137. SetCursor(OldCursor);
  138. //
  139. // Set the dialog caption appropriately
  140. //
  141. GetWindowTextW(hDlg, string, sizeof(string)/sizeof(*string));
  142. lstrcatW(string, L" for <");
  143. lstrcatW(string, ((PMYTOKEN)hMyToken)->Name);
  144. lstrcatW(string, L">");
  145. SetWindowTextW(hDlg, string);
  146. return(TRUE);
  147. }
  148. /****************************************************************************
  149. FUNCTION: TokenEditDlgEnd(HWND)
  150. PURPOSE: Do whatever we have to do to clean up when dialog ends
  151. RETURNS: TRUE on success, FALSE on failure.
  152. ****************************************************************************/
  153. BOOL TokenEditDlgEnd(
  154. HWND hDlg,
  155. BOOL fSaveChanges)
  156. {
  157. HANDLE hMyToken = (HANDLE)GetWindowLongPtr(hDlg, GWLP_USERDATA);
  158. BOOL Success;
  159. Success = CloseMyToken(hDlg, hMyToken, fSaveChanges);
  160. LsaTerminate();
  161. return(Success);
  162. }
  163. /****************************************************************************
  164. FUNCTION: DisplayMyToken
  165. PURPOSE: Reads data out of mytoken and puts in dialog controls.
  166. RETURNS: TRUE on success, FALSE on failure
  167. ****************************************************************************/
  168. BOOL DisplayMyToken(
  169. HWND hDlg
  170. )
  171. {
  172. HANDLE hMyToken = (HANDLE)GetWindowLongPtr(hDlg, GWLP_USERDATA);
  173. PMYTOKEN pMyToken = (PMYTOKEN)hMyToken;
  174. CHAR string[MAX_STRING_BYTES];
  175. UINT GroupIndex;
  176. UINT PrivIndex;
  177. //
  178. // Groups
  179. //
  180. if (pMyToken->Groups != NULL) {
  181. for (GroupIndex=0; GroupIndex < pMyToken->Groups->GroupCount; GroupIndex++ ) {
  182. PSID Sid = pMyToken->Groups->Groups[GroupIndex].Sid;
  183. ULONG Attributes = pMyToken->Groups->Groups[GroupIndex].Attributes;
  184. USHORT ControlID;
  185. if (Attributes & SE_GROUP_ENABLED) {
  186. ControlID = IDL_ENABLEDGROUPS;
  187. } else {
  188. ControlID = IDL_DISABLEDGROUPS;
  189. }
  190. if (SID2Name(Sid, string, MAX_STRING_BYTES)) {
  191. // Add to disable or enabled group box
  192. AddLBItem(hDlg, ControlID, string, GroupIndex);
  193. // Add this group to default owner combo box if it's valid
  194. if (Attributes & SE_GROUP_OWNER) {
  195. AddCBItem(hDlg, IDC_DEFAULTOWNER, string, (LPARAM)Sid);
  196. }
  197. // Add this group to primary group combo box
  198. AddCBItem(hDlg, IDC_PRIMARYGROUP, string, (LPARAM)Sid);
  199. } else {
  200. DbgPrint("PVIEW: Failed to convert Group sid to string\n");
  201. }
  202. }
  203. } else {
  204. DbgPrint("PVIEW : No group info in mytoken\n");
  205. }
  206. //
  207. // User ID
  208. //
  209. if (pMyToken->UserId != NULL) {
  210. PSID Sid = pMyToken->UserId->User.Sid;
  211. if (SID2Name(Sid, string, MAX_STRING_BYTES)) {
  212. // Set user-name static text
  213. SetDlgItemText(hDlg, IDS_USERID, string);
  214. // Add to default owner combo box
  215. AddCBItem(hDlg, IDC_DEFAULTOWNER, string, (LPARAM)Sid);
  216. // Add to primary group combo box
  217. AddCBItem(hDlg, IDC_PRIMARYGROUP, string, (LPARAM)Sid);
  218. } else {
  219. DbgPrint("PVIEW: Failed to convert User ID SID to string\n");
  220. }
  221. } else {
  222. DbgPrint("PVIEW: No user id in mytoken\n");
  223. }
  224. //
  225. // Default Owner
  226. //
  227. if (pMyToken->DefaultOwner != NULL) {
  228. PSID Sid = pMyToken->DefaultOwner->Owner;
  229. if (SID2Name(Sid, string, MAX_STRING_BYTES)) {
  230. INT iItem;
  231. iItem = FindCBSid(hDlg, IDC_DEFAULTOWNER, Sid);
  232. if (iItem >= 0) {
  233. SendMessage(GetDlgItem(hDlg, IDC_DEFAULTOWNER), CB_SETCURSEL, iItem, 0);
  234. } else {
  235. DbgPrint("PVIEW: Default Owner is not userID or one of our groups\n");
  236. }
  237. } else {
  238. DbgPrint("PVIEW: Failed to convert Default Owner SID to string\n");
  239. }
  240. } else {
  241. DbgPrint("PVIEW: No default owner in mytoken\n");
  242. }
  243. //
  244. // Primary group
  245. //
  246. if (pMyToken->PrimaryGroup != NULL) {
  247. PSID Sid = pMyToken->PrimaryGroup->PrimaryGroup;
  248. if (SID2Name(Sid, string, MAX_STRING_BYTES)) {
  249. INT iItem;
  250. iItem = FindCBSid(hDlg, IDC_PRIMARYGROUP, Sid);
  251. if (iItem < 0) {
  252. // Group is not already in combo-box, add it
  253. iItem = AddCBItem(hDlg, IDC_PRIMARYGROUP, string, (LPARAM)Sid);
  254. }
  255. // Select the primary group
  256. SendMessage(GetDlgItem(hDlg, IDC_PRIMARYGROUP), CB_SETCURSEL, iItem, 0);
  257. } else {
  258. DbgPrint("PVIEW: Failed to convert primary group SID to string\n");
  259. }
  260. } else {
  261. DbgPrint("PVIEW: No primary group in mytoken\n");
  262. }
  263. //
  264. // Privileges
  265. //
  266. if (pMyToken->Privileges != NULL) {
  267. for (PrivIndex=0; PrivIndex < pMyToken->Privileges->PrivilegeCount; PrivIndex++ ) {
  268. LUID Privilege = pMyToken->Privileges->Privileges[PrivIndex].Luid;
  269. ULONG Attributes = pMyToken->Privileges->Privileges[PrivIndex].Attributes;
  270. USHORT ControlID;
  271. if (Attributes & SE_PRIVILEGE_ENABLED) {
  272. ControlID = IDL_ENABLEDPRIVILEGES;
  273. } else {
  274. ControlID = IDL_DISABLEDPRIVILEGES;
  275. }
  276. if (PRIV2Name(Privilege, string, MAX_STRING_BYTES)) {
  277. // Add this privelege to the appropriate list-box
  278. AddLBItem(hDlg, ControlID, string, PrivIndex);
  279. } else {
  280. DbgPrint("PVIEW: Failed to convert privilege to string\n");
  281. }
  282. }
  283. } else {
  284. DbgPrint("PVIEW: No privilege info in mytoken\n");
  285. }
  286. return(TRUE);
  287. }
  288. /****************************************************************************
  289. FUNCTION: EnablePrivilege(HWND, fEnable)
  290. PURPOSE: Enables or disables one or more privileges.
  291. If fEnable = TRUE, the selected privileges in the disabled
  292. privilege control are enabled.
  293. Vice versa for fEnable = FALSE
  294. RETURNS: TRUE on success, FALSE on failure
  295. ****************************************************************************/
  296. BOOL EnablePrivilege(
  297. HWND hDlg,
  298. BOOL fEnable)
  299. {
  300. HANDLE hMyToken = (HANDLE)GetWindowLongPtr(hDlg, GWLP_USERDATA);
  301. PMYTOKEN pMyToken = (PMYTOKEN)hMyToken;
  302. HWND hwndFrom;
  303. HWND hwndTo;
  304. USHORT idFrom;
  305. USHORT idTo;
  306. INT cItems;
  307. PINT pItems;
  308. PTOKEN_PRIVILEGES Privileges;
  309. Privileges = pMyToken->Privileges;
  310. if (Privileges == NULL) {
  311. return(FALSE);
  312. }
  313. // Calculate source and destination controls
  314. //
  315. if (fEnable) {
  316. idFrom = IDL_DISABLEDPRIVILEGES;
  317. idTo = IDL_ENABLEDPRIVILEGES;
  318. } else {
  319. idFrom = IDL_ENABLEDPRIVILEGES;
  320. idTo = IDL_DISABLEDPRIVILEGES;
  321. }
  322. hwndFrom = GetDlgItem(hDlg, idFrom);
  323. hwndTo = GetDlgItem(hDlg, idTo);
  324. // Find how many items are selected
  325. //
  326. cItems = (INT)SendMessage(hwndFrom, LB_GETSELCOUNT, 0, 0);
  327. if (cItems <= 0) {
  328. // No items selected
  329. return(TRUE);
  330. }
  331. // Allocate space for the item array
  332. //
  333. pItems = Alloc(cItems * sizeof(*pItems));
  334. if (pItems == NULL) {
  335. return(FALSE);
  336. }
  337. // Read the selected items into the array
  338. //
  339. cItems = (INT)SendMessage(hwndFrom, LB_GETSELITEMS, (WPARAM)cItems, (LPARAM)pItems);
  340. if (cItems == LB_ERR) {
  341. // Something went wrong
  342. Free(pItems);
  343. return(FALSE);
  344. }
  345. while (cItems-- > 0) {
  346. INT iItem;
  347. UINT PrivIndex;
  348. UCHAR PrivilegeName[MAX_STRING_BYTES];
  349. iItem = pItems[cItems]; // Read the item index from the selected item array
  350. // Read the text and data from the source item
  351. //
  352. PrivIndex = (UINT)SendMessage(hwndFrom, LB_GETITEMDATA, iItem, 0);
  353. SendMessage(hwndFrom, LB_GETTEXT, iItem, (LPARAM)PrivilegeName);
  354. // Delete item from source control
  355. //
  356. SendMessage(hwndFrom, LB_DELETESTRING, iItem, 0);
  357. // Add privilege to destination control
  358. //
  359. iItem = (INT)SendMessage(hwndTo, LB_ADDSTRING, 0, (LPARAM)PrivilegeName);
  360. SendMessage(hwndTo, LB_SETITEMDATA, iItem, (LPARAM)PrivIndex);
  361. // Modify global data structure to reflect change
  362. //
  363. if (fEnable) {
  364. Privileges->Privileges[PrivIndex].Attributes |= SE_PRIVILEGE_ENABLED;
  365. } else {
  366. Privileges->Privileges[PrivIndex].Attributes &= ~SE_PRIVILEGE_ENABLED;
  367. }
  368. }
  369. // Free up space allocated for selected item array
  370. Free(pItems);
  371. return(TRUE);
  372. }
  373. /****************************************************************************
  374. FUNCTION: EnableGroup(HWND, fEnable)
  375. PURPOSE: Enables or disables one or more selected groups.
  376. If fEnable = TRUE, the selected groups in the disabled
  377. group control are enabled.
  378. If fEnable = FALSE the selected groups in the enabled
  379. group control are disabled.
  380. RETURNS: TRUE on success, FALSE on failure
  381. ****************************************************************************/
  382. BOOL EnableGroup(
  383. HWND hDlg,
  384. BOOL fEnable)
  385. {
  386. HANDLE hMyToken = (HANDLE)GetWindowLongPtr(hDlg, GWLP_USERDATA);
  387. PMYTOKEN pMyToken = (PMYTOKEN)hMyToken;
  388. HWND hwndFrom;
  389. HWND hwndTo;
  390. USHORT idFrom;
  391. USHORT idTo;
  392. INT cItems;
  393. PINT pItems;
  394. PTOKEN_GROUPS Groups;
  395. Groups = pMyToken->Groups;
  396. if (Groups == NULL) {
  397. return(FALSE);
  398. }
  399. // Calculate source and destination controls
  400. //
  401. if (fEnable) {
  402. idFrom = IDL_DISABLEDGROUPS;
  403. idTo = IDL_ENABLEDGROUPS;
  404. } else {
  405. idFrom = IDL_ENABLEDGROUPS;
  406. idTo = IDL_DISABLEDGROUPS;
  407. }
  408. hwndFrom = GetDlgItem(hDlg, idFrom);
  409. hwndTo = GetDlgItem(hDlg, idTo);
  410. // Find how many items are selected
  411. //
  412. cItems = (INT)SendMessage(hwndFrom, LB_GETSELCOUNT, 0, 0);
  413. if (cItems <= 0) {
  414. // No items selected
  415. return(TRUE);
  416. }
  417. // Allocate space for the item array
  418. //
  419. pItems = Alloc(cItems * sizeof(*pItems));
  420. if (pItems == NULL) {
  421. return(FALSE);
  422. }
  423. // Read the selected items into the array
  424. //
  425. cItems = (INT)SendMessage(hwndFrom, LB_GETSELITEMS, (WPARAM)cItems, (LPARAM)pItems);
  426. if (cItems == LB_ERR) {
  427. // Something went wrong
  428. Free(pItems);
  429. return(FALSE);
  430. }
  431. while (cItems-- > 0) {
  432. INT iItem;
  433. UINT GroupIndex;
  434. UCHAR GroupName[MAX_STRING_BYTES];
  435. iItem = pItems[cItems]; // Read the item index from the selected item array
  436. // Read the text and data from the source item
  437. //
  438. GroupIndex = (UINT)SendMessage(hwndFrom, LB_GETITEMDATA, iItem, 0);
  439. SendMessage(hwndFrom, LB_GETTEXT, iItem, (LPARAM)GroupName);
  440. // Check it's not a mandatory group (Can-not be disabled)
  441. //
  442. if (Groups->Groups[GroupIndex].Attributes & SE_GROUP_MANDATORY) {
  443. CHAR buf[256];
  444. strcpy(buf, "'");
  445. strcat(buf, GroupName);
  446. strcat(buf, "' is a mandatory group and cannot be disabled");
  447. MessageBox(hDlg, buf, NULL, MB_ICONSTOP | MB_APPLMODAL | MB_OK);
  448. continue; // skip to next group
  449. }
  450. // Delete item from source control
  451. //
  452. SendMessage(hwndFrom, LB_DELETESTRING, iItem, 0);
  453. // Add item to destination control
  454. //
  455. iItem = (INT)SendMessage(hwndTo, LB_ADDSTRING, 0, (LPARAM)GroupName);
  456. SendMessage(hwndTo, LB_SETITEMDATA, iItem, (LONG)GroupIndex);
  457. // Modify global data structure to reflect change
  458. //
  459. if (fEnable) {
  460. Groups->Groups[GroupIndex].Attributes |= SE_GROUP_ENABLED;
  461. } else {
  462. Groups->Groups[GroupIndex].Attributes &= ~SE_GROUP_ENABLED;
  463. }
  464. }
  465. // Free up space allocated for selected item array
  466. Free(pItems);
  467. return(TRUE);
  468. }
  469. /****************************************************************************
  470. FUNCTION: SetDefaultOwner()
  471. PURPOSE: Sets the default owner to the new value selected by the user.
  472. RETURNS: TRUE on success, FALSE on failure
  473. ****************************************************************************/
  474. BOOL SetDefaultOwner(
  475. HWND hDlg)
  476. {
  477. HANDLE hMyToken = (HANDLE)GetWindowLongPtr(hDlg, GWLP_USERDATA);
  478. PMYTOKEN pMyToken = (PMYTOKEN)hMyToken;
  479. HWND hwnd;
  480. INT iItem;
  481. PTOKEN_OWNER DefaultOwner;
  482. DefaultOwner = pMyToken->DefaultOwner;
  483. if (DefaultOwner == NULL) {
  484. return(FALSE);
  485. }
  486. hwnd = GetDlgItem(hDlg, IDC_DEFAULTOWNER);
  487. iItem = (INT)SendMessage(hwnd, CB_GETCURSEL, 0, 0);
  488. if (iItem == CB_ERR) {
  489. // No selection ?
  490. return(FALSE);
  491. }
  492. // Modify global data structure to reflect change
  493. DefaultOwner->Owner = (PSID)SendMessage(hwnd, CB_GETITEMDATA, iItem, 0);
  494. return(TRUE);
  495. }
  496. /****************************************************************************
  497. FUNCTION: SetPrimaryGroup()
  498. PURPOSE: Sets the primary group to the new value selected by the user.
  499. RETURNS: TRUE on success, FALSE on failure
  500. ****************************************************************************/
  501. BOOL SetPrimaryGroup(
  502. HWND hDlg)
  503. {
  504. HANDLE hMyToken = (HANDLE)GetWindowLongPtr(hDlg, GWLP_USERDATA);
  505. PMYTOKEN pMyToken = (PMYTOKEN)hMyToken;
  506. HWND hwnd;
  507. INT iItem;
  508. PTOKEN_PRIMARY_GROUP PrimaryGroup;
  509. PrimaryGroup = pMyToken->PrimaryGroup;
  510. if (PrimaryGroup == NULL) {
  511. return(FALSE);
  512. }
  513. hwnd = GetDlgItem(hDlg, IDC_PRIMARYGROUP);
  514. iItem = (INT)SendMessage(hwnd, CB_GETCURSEL, 0, 0);
  515. if (iItem == CB_ERR) {
  516. // No selection ?
  517. return(FALSE);
  518. }
  519. // Modify global data structure to reflect change
  520. PrimaryGroup->PrimaryGroup = (PSID)SendMessage(hwnd, CB_GETITEMDATA, iItem, 0);
  521. return(TRUE);
  522. }
  523. /****************************************************************************
  524. FUNCTION: MoreDlgProc(HWND, UINT, WPARAM, LPARAM)
  525. PURPOSE: Processes messages
  526. ****************************************************************************/
  527. INT_PTR APIENTRY MoreDlgProc(hDlg, message, wParam, lParam)
  528. HWND hDlg;
  529. UINT message;
  530. WPARAM wParam;
  531. LPARAM lParam;
  532. {
  533. HANDLE hMyToken = (HANDLE)GetWindowLongPtr(hDlg, GWLP_USERDATA);
  534. switch (message) {
  535. case WM_INITDIALOG:
  536. if (!MoreDlgInit(hDlg, lParam)) {
  537. // Failed to initialize dialog, get out
  538. EndDialog(hDlg, FALSE);
  539. }
  540. return (TRUE);
  541. case WM_COMMAND:
  542. switch (LOWORD(wParam)) {
  543. case IDOK:
  544. // we're done, drop through to quit dialog....
  545. case IDCANCEL:
  546. EndDialog(hDlg, TRUE);
  547. return TRUE;
  548. break;
  549. default:
  550. // We didn't process this message
  551. return FALSE;
  552. break;
  553. }
  554. break;
  555. default:
  556. // We didn't process this message
  557. return FALSE;
  558. }
  559. // We processed the message
  560. return TRUE;
  561. }
  562. /****************************************************************************
  563. FUNCTION: MoreDlgInit(HWND)
  564. PURPOSE: Initialises the controls in the more dialog window.
  565. RETURNS: TRUE on success, FALSE on failure
  566. ****************************************************************************/
  567. BOOL MoreDlgInit(
  568. HWND hDlg,
  569. LPARAM lParam
  570. )
  571. {
  572. TCHAR string[MAX_STRING_LENGTH];
  573. HANDLE hMyToken = (HANDLE)lParam;
  574. PMYTOKEN pMyToken = (PMYTOKEN)hMyToken;
  575. PTOKEN_STATISTICS Statistics;
  576. PTOKEN_GROUPS Restrictions ;
  577. UINT GroupIndex;
  578. Statistics = pMyToken->TokenStats;
  579. if (Statistics == NULL) {
  580. DbgPrint("PVIEW: No token statistics in mytoken\n");
  581. return(FALSE);
  582. }
  583. wsprintf(string, "0x%lx-%lx",
  584. pMyToken->TokenStats->AuthenticationId.HighPart,
  585. pMyToken->TokenStats->AuthenticationId.LowPart);
  586. SetDlgItemText(hDlg, IDS_LOGONSESSION, string);
  587. if (LUID2String(Statistics->TokenId, string, MAX_STRING_BYTES)) {
  588. SetDlgItemText(hDlg, IDS_TOKENID, string);
  589. } else {
  590. DbgPrint("PVIEW: Failed to convert tokenid luid to string\n");
  591. }
  592. if (Time2String(Statistics->ExpirationTime, string, MAX_STRING_BYTES)) {
  593. SetDlgItemText(hDlg, IDS_EXPIRATIONTIME, string);
  594. } else {
  595. DbgPrint("PVIEW: Failed to convert expiration time to string\n");
  596. }
  597. if (TokenType2String(Statistics->TokenType, string, MAX_STRING_BYTES)) {
  598. SetDlgItemText(hDlg, IDS_TOKENTYPE, string);
  599. } else {
  600. DbgPrint("PVIEW: Failed to convert token type to string\n");
  601. }
  602. if (Statistics->TokenType == TokenPrimary) {
  603. SetDlgItemText(hDlg, IDS_IMPERSONATION, "N/A");
  604. } else {
  605. if (ImpersonationLevel2String(Statistics->ImpersonationLevel, string, MAX_STRING_BYTES)) {
  606. SetDlgItemText(hDlg, IDS_IMPERSONATION, string);
  607. } else {
  608. DbgPrint("PVIEW: Failed to convert impersonation level to string\n");
  609. }
  610. }
  611. if (Dynamic2String(Statistics->DynamicCharged, string, MAX_STRING_BYTES)) {
  612. SetDlgItemText(hDlg, IDS_DYNAMICCHARGED, string);
  613. } else {
  614. DbgPrint("PVIEW: Failed to convert dynamic charged to string\n");
  615. }
  616. if (Dynamic2String(Statistics->DynamicAvailable, string, MAX_STRING_BYTES)) {
  617. SetDlgItemText(hDlg, IDS_DYNAMICAVAILABLE, string);
  618. } else {
  619. DbgPrint("PVIEW: Failed to convert dynamic available to string\n");
  620. }
  621. if (LUID2String(Statistics->ModifiedId, string, MAX_STRING_BYTES)) {
  622. SetDlgItemText(hDlg, IDS_MODIFIEDID, string);
  623. } else {
  624. DbgPrint("PVIEW: Failed to convert modifiedid luid to string\n");
  625. }
  626. Restrictions = pMyToken->RestrictedSids ;
  627. if ( Restrictions && (Restrictions->GroupCount) )
  628. {
  629. for (GroupIndex=0; GroupIndex < Restrictions->GroupCount; GroupIndex++ ) {
  630. PSID Sid = Restrictions->Groups[GroupIndex].Sid;
  631. ULONG Attributes = Restrictions->Groups[GroupIndex].Attributes;
  632. if (SID2Name(Sid, string, MAX_STRING_BYTES)) {
  633. // Add to disable or enabled group box
  634. AddLBItem(hDlg, IDS_RESTRICTEDSIDS, string, GroupIndex);
  635. } else {
  636. DbgPrint("PVIEW: Failed to convert Group sid to string\n");
  637. }
  638. }
  639. }
  640. else
  641. {
  642. AddLBItem( hDlg, IDS_RESTRICTEDSIDS, TEXT("None"), 0 );
  643. }
  644. return(TRUE);
  645. }