Skip to content

Commit 7d8167b

Browse files
committed
pathman_post_parse_analysis_hook(): improve 'shared_preload_libraries' check (issue #82)
1 parent 13e8aef commit 7d8167b

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/hooks.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "xact_handling.h"
2121

2222
#include "access/transam.h"
23+
#include "catalog/pg_authid.h"
2324
#include "miscadmin.h"
2425
#include "optimizer/cost.h"
2526
#include "optimizer/restrictinfo.h"
@@ -556,14 +557,33 @@ pathman_post_parse_analysis_hook(ParseState *pstate, Query *query)
556557
/* Check that pg_pathman is the last extension loaded */
557558
if (post_parse_analyze_hook != pathman_post_parse_analysis_hook)
558559
{
559-
char *spl_value; /* value of "shared_preload_libraries" GUC */
560+
Oid save_userid;
561+
int save_sec_context;
562+
bool need_priv_escalation = !superuser(); /* we might be a SU */
563+
char *spl_value; /* value of "shared_preload_libraries" GUC */
560564

565+
/* Do we have to escalate privileges? */
566+
if (need_priv_escalation)
567+
{
568+
/* Get current user's Oid and security context */
569+
GetUserIdAndSecContext(&save_userid, &save_sec_context);
570+
571+
/* Become superuser in order to bypass sequence ACL checks */
572+
SetUserIdAndSecContext(BOOTSTRAP_SUPERUSERID,
573+
save_sec_context | SECURITY_LOCAL_USERID_CHANGE);
574+
}
575+
576+
/* Only SU can read this GUC */
561577
#if PG_VERSION_NUM >= 90600
562578
spl_value = GetConfigOptionByName("shared_preload_libraries", NULL, false);
563579
#else
564580
spl_value = GetConfigOptionByName("shared_preload_libraries", NULL);
565581
#endif
566582

583+
/* Restore user's privileges */
584+
if (need_priv_escalation)
585+
SetUserIdAndSecContext(save_userid, save_sec_context);
586+
567587
ereport(ERROR,
568588
(errmsg("extension conflict has been detected"),
569589
errdetail("shared_preload_libraries = \"%s\"", spl_value),

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