* GetTokenUser(HANDLE hToken, PTOKEN_USER *ppTokenUser) * * Get the users token information from a process token. * * The caller of this function is responsible for calling LocalFree() on the * returned TOKEN_USER memory. */
| 642 | * returned TOKEN_USER memory. |
| 643 | */ |
| 644 | static BOOL |
| 645 | GetTokenUser(HANDLE hToken, PTOKEN_USER *ppTokenUser) |
| 646 | { |
| 647 | DWORD dwLength; |
| 648 | |
| 649 | *ppTokenUser = NULL; |
| 650 | |
| 651 | if (!GetTokenInformation(hToken, |
| 652 | TokenUser, |
| 653 | NULL, |
| 654 | 0, |
| 655 | &dwLength)) |
| 656 | { |
| 657 | if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) |
| 658 | { |
| 659 | *ppTokenUser = (PTOKEN_USER) LocalAlloc(LPTR, dwLength); |
| 660 | |
| 661 | if (*ppTokenUser == NULL) |
| 662 | { |
| 663 | log_error(errcode(ERRCODE_OUT_OF_MEMORY), |
| 664 | _("out of memory")); |
| 665 | return FALSE; |
| 666 | } |
| 667 | } |
| 668 | else |
| 669 | { |
| 670 | log_error(errcode(ERRCODE_SYSTEM_ERROR), |
| 671 | "could not get token information buffer size: error code %lu", |
| 672 | GetLastError()); |
| 673 | return FALSE; |
| 674 | } |
| 675 | } |
| 676 | |
| 677 | if (!GetTokenInformation(hToken, |
| 678 | TokenUser, |
| 679 | *ppTokenUser, |
| 680 | dwLength, |
| 681 | &dwLength)) |
| 682 | { |
| 683 | LocalFree(*ppTokenUser); |
| 684 | *ppTokenUser = NULL; |
| 685 | |
| 686 | log_error(errcode(ERRCODE_SYSTEM_ERROR), |
| 687 | "could not get token information: error code %lu", |
| 688 | GetLastError()); |
| 689 | return FALSE; |
| 690 | } |
| 691 | |
| 692 | /* Memory in *ppTokenUser is LocalFree():d by the caller */ |
| 693 | return TRUE; |
| 694 | } |
| 695 | |
| 696 | #endif |
no test coverage detected