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

Function SetSessionAuthorization

src/backend/utils/init/miscinit.c:860–883  ·  view source on GitHub ↗

* Change session auth ID while running * * Only a superuser may set auth ID to something other than himself. Note * that in case of multiple SETs in a single session, the original userid's * superuserness is what matters. But we set the GUC variable is_superuser * to indicate whether the *current* session userid is a superuser. * * Note: this is not an especially clean place to do the per

Source from the content-addressed store, hash-verified

858 * have to push it up into assign_session_authorization.
859 */
860void
861SetSessionAuthorization(Oid userid, bool is_superuser)
862{
863 /* Must have authenticated already, else can't make permission check */
864 AssertState(OidIsValid(AuthenticatedUserId));
865
866 if (userid != AuthenticatedUserId &&
867 !AuthenticatedUserIsSuperuser)
868 ereport(ERROR,
869 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
870 errmsg("permission denied to set session authorization")));
871
872 SetSessionUserId(userid, is_superuser);
873
874 /* If resource scheduling enabled, set the cached queue for the new role.*/
875 if ((Gp_role == GP_ROLE_DISPATCH || IS_SINGLENODE() || Gp_role == GP_ROLE_EXECUTE) && IsResQueueEnabled())
876 {
877 SetResQueueId();
878 }
879
880 SetConfigOption("is_superuser",
881 is_superuser ? "on" : "off",
882 PGC_INTERNAL, PGC_S_OVERRIDE);
883}
884
885/*
886 * Report current role id

Callers 1

Calls 5

SetSessionUserIdFunction · 0.85
SetResQueueIdFunction · 0.85
SetConfigOptionFunction · 0.85
errcodeFunction · 0.50
errmsgFunction · 0.50

Tested by

no test coverage detected