MCPcopy Create free account
hub / github.com/apache/cloudberry / GetTokenUser

Function GetTokenUser

src/common/exec.c:644–694  ·  view source on GitHub ↗

* 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. */

Source from the content-addressed store, hash-verified

642 * returned TOKEN_USER memory.
643 */
644static BOOL
645GetTokenUser(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

Callers 1

AddUserToTokenDaclFunction · 0.85

Calls 2

GetLastErrorFunction · 0.85
errcodeFunction · 0.50

Tested by

no test coverage detected