Add a function to get the authenticated user ID.
authorRobert Haas <rhaas@postgresql.org>
Thu, 23 Oct 2014 12:18:45 +0000 (08:18 -0400)
committerRobert Haas <rhaas@postgresql.org>
Thu, 23 Oct 2014 12:18:45 +0000 (08:18 -0400)
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.

src/backend/utils/init/miscinit.c
src/include/miscadmin.h

index a703c67eaddd601bd21c1568ce28414d67fff8d9..8fccb4c8262c60c6782b6223c5148dfed7312ff9 100644 (file)
@@ -222,6 +222,16 @@ SetSessionUserId(Oid userid, bool is_superuser)
    CurrentUserId = userid;
 }
 
+/*
+ * GetAuthenticatedUserId - get the authenticated user ID
+ */
+Oid
+GetAuthenticatedUserId(void)
+{
+   AssertState(OidIsValid(AuthenticatedUserId));
+   return AuthenticatedUserId;
+}
+
 
 /*
  * GetUserIdAndSecContext/SetUserIdAndSecContext - get/set the current user ID
index 2ba98856ff27782d778bacc4da3cb9a080acc269..1558a75fbde658ce69e7f4f41c59e5515417a2d8 100644 (file)
@@ -283,6 +283,7 @@ extern char *GetUserNameFromId(Oid roleid);
 extern Oid GetUserId(void);
 extern Oid GetOuterUserId(void);
 extern Oid GetSessionUserId(void);
+extern Oid GetAuthenticatedUserId(void);
 extern void GetUserIdAndSecContext(Oid *userid, int *sec_context);
 extern void SetUserIdAndSecContext(Oid userid, int sec_context);
 extern bool InLocalUserIdChange(void);