Skip to content

Commit 5ac372f

Browse files
committed
Add a function to get the authenticated user ID.
Previously, this was not exposed outside of miscinit.c. It is needed for the pending pg_background patch, and will also be needed for parallelism. Without it, there's no way for a background worker to re-create the exact authentication environment that was present in the process that started it, which could lead to security exposures.
1 parent c7371c4 commit 5ac372f

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/backend/utils/init/miscinit.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,16 @@ SetSessionUserId(Oid userid, bool is_superuser)
222222
CurrentUserId = userid;
223223
}
224224

225+
/*
226+
* GetAuthenticatedUserId - get the authenticated user ID
227+
*/
228+
Oid
229+
GetAuthenticatedUserId(void)
230+
{
231+
AssertState(OidIsValid(AuthenticatedUserId));
232+
return AuthenticatedUserId;
233+
}
234+
225235

226236
/*
227237
* GetUserIdAndSecContext/SetUserIdAndSecContext - get/set the current user ID

src/include/miscadmin.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ extern char *GetUserNameFromId(Oid roleid);
283283
extern Oid GetUserId(void);
284284
extern Oid GetOuterUserId(void);
285285
extern Oid GetSessionUserId(void);
286+
extern Oid GetAuthenticatedUserId(void);
286287
extern void GetUserIdAndSecContext(Oid *userid, int *sec_context);
287288
extern void SetUserIdAndSecContext(Oid userid, int sec_context);
288289
extern bool InLocalUserIdChange(void);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy