| 844 | } |
| 845 | |
| 846 | bool GetUserNameFromToken(HANDLE handle, wstring& user, wstring& domain) |
| 847 | { |
| 848 | |
| 849 | UCHAR buffer[1024]; |
| 850 | DWORD returnLength; |
| 851 | WCHAR accountName[256]; |
| 852 | WCHAR domainName[256]; |
| 853 | DWORD accountLength = sizeof(accountName) / sizeof(WCHAR); |
| 854 | DWORD domainLength = sizeof(domainName) / sizeof(WCHAR); |
| 855 | PTOKEN_USER tokenUser; |
| 856 | SID_NAME_USE snu; |
| 857 | |
| 858 | if (!GetTokenInformation(handle, TokenUser, buffer, sizeof(buffer), |
| 859 | &returnLength)) { |
| 860 | //DbgPrint(L" GetTokenInformaiton failed: %d\n", GetLastError()); |
| 861 | return false; |
| 862 | } |
| 863 | |
| 864 | tokenUser = (PTOKEN_USER)buffer; |
| 865 | if (!LookupAccountSid(NULL, tokenUser->User.Sid, accountName, &accountLength, |
| 866 | domainName, &domainLength, &snu)) { |
| 867 | //DbgPrint(L" LookupAccountSid failed: %d\n", GetLastError()); |
| 868 | return false; |
| 869 | } |
| 870 | |
| 871 | //DbgPrint(L" AccountName: %s, DomainName: %s\n", accountName, domainName); |
| 872 | |
| 873 | if (snu != SidTypeUser) |
| 874 | return false; |
| 875 | |
| 876 | user = accountName; |
| 877 | domain = domainName; |
| 878 | |
| 879 | DWORD sessionid = 0; |
| 880 | |
| 881 | if (GetTokenInformation(handle, TokenSessionId, &sessionid, sizeof(sessionid), &returnLength)) { |
| 882 | DbgPrint(L"SessionId = %u\n", sessionid); |
| 883 | } else { |
| 884 | DbgPrint(L"failed to get SessionId\n"); |
| 885 | } |
| 886 | |
| 887 | return true; |
| 888 | } |
| 889 | |
| 890 | bool GetSessionIdFromToken(HANDLE handle, DWORD &sessionid) |
| 891 | { |
no test coverage detected