PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
superuser.c File Reference
#include "postgres.h"
#include "access/htup_details.h"
#include "catalog/pg_authid.h"
#include "miscadmin.h"
#include "utils/inval.h"
#include "utils/syscache.h"
Include dependency graph for superuser.c:

Go to the source code of this file.

Functions

static void RoleidCallback (Datum arg, int cacheid, uint32 hashvalue)
 
bool superuser (void)
 
bool superuser_arg (Oid roleid)
 

Variables

static Oid last_roleid = InvalidOid
 
static bool last_roleid_is_super = false
 
static bool roleid_callback_registered = false
 

Function Documentation

◆ RoleidCallback()

static void RoleidCallback ( Datum  arg,
int  cacheid,
uint32  hashvalue 
)
static

Definition at line 103 of file superuser.c.

104{
105 /* Invalidate our local cache in case role's superuserness changed */
107}
#define InvalidOid
Definition: postgres_ext.h:36
static Oid last_roleid
Definition: superuser.c:35

References InvalidOid, and last_roleid.

Referenced by superuser_arg().

◆ superuser()

bool superuser ( void  )

Definition at line 46 of file superuser.c.

47{
48 return superuser_arg(GetUserId());
49}
Oid GetUserId(void)
Definition: miscinit.c:517
bool superuser_arg(Oid roleid)
Definition: superuser.c:56

References GetUserId(), and superuser_arg().

Referenced by AlterForeignDataWrapper(), AlterForeignDataWrapperOwner_internal(), AlterForeignServerOwner_internal(), AlterFunction(), AlterObjectNamespace_internal(), AlterObjectOwner_internal(), AlterObjectRename_internal(), AlterOpFamily(), AlterPublicationOwner_internal(), AlterRole(), AlterRoleSet(), AlterSubscription(), AlterSubscriptionOwner_internal(), AlterSystemSetConfigFile(), AlterType(), AlterTypeOwner(), ATExecChangeOwner(), brin_metapage_info(), brin_page_items(), brin_page_type(), brin_revmap_data(), bt_metap(), bt_multi_page_stats(), bt_page_items_bytea(), bt_page_items_internal(), bt_page_stats_internal(), check_encoding_locale_matches(), CheckAlterPublication(), CreateAccessMethod(), CreateCast(), CreateEventTrigger(), CreateForeignDataWrapper(), CreateFunction(), CreateProceduralLanguage(), CreatePublication(), CreateRole(), CreateSubscription(), CreateTableSpace(), dblink_connstr_check(), dblink_security_check(), DefineAggregate(), DefineOpClass(), DefineOpFamily(), DefineTSParser(), DefineTSTemplate(), DefineType(), DropRole(), dummy_object_relabel(), EnableDisableTrigger(), ExecSetVariableStmt(), execute_extension_script(), ExecuteDoStmt(), fmgr_security_definer(), fsm_page_contents(), get_raw_page_internal(), gin_leafpage_items(), gin_metapage_info(), gin_page_opaque_info(), gist_page_items(), gist_page_items_bytea(), gist_page_opaque_info(), GUCArrayReset(), hash_bitmap_info(), hash_metapage_info(), hash_page_items(), hash_page_stats(), hash_page_type(), have_createdb_privilege(), heap_page_items(), heap_tuple_infomask_flags(), InitPostgres(), interpret_func_support(), main(), page_checksum_internal(), page_header(), pg_buffercache_evict(), pg_import_system_collations(), pg_nextoid(), pg_relpages(), pg_relpagesbyid(), pg_signal_backend(), pg_stop_making_pinned_objects(), pgstat_get_backend_current_activity(), pgstatginindex(), pgstatindex(), pgstatindexbyid(), pgstattuple(), pgstattuple_approx(), pgstattuplebyid(), postgres_fdw_validator(), ProcedureCreate(), regress_setenv(), RenameRole(), sepgsql_restorecon(), set_config_by_name(), SetPGVariable(), standard_ProcessUtility(), TerminateOtherDBBackends(), tuple_data_split(), validate_option_array_item(), and wait_pid().

◆ superuser_arg()

bool superuser_arg ( Oid  roleid)

Definition at line 56 of file superuser.c.

57{
58 bool result;
59 HeapTuple rtup;
60
61 /* Quick out for cache hit */
62 if (OidIsValid(last_roleid) && last_roleid == roleid)
64
65 /* Special escape path in case you deleted all your users. */
66 if (!IsUnderPostmaster && roleid == BOOTSTRAP_SUPERUSERID)
67 return true;
68
69 /* OK, look up the information in pg_authid */
70 rtup = SearchSysCache1(AUTHOID, ObjectIdGetDatum(roleid));
71 if (HeapTupleIsValid(rtup))
72 {
73 result = ((Form_pg_authid) GETSTRUCT(rtup))->rolsuper;
74 ReleaseSysCache(rtup);
75 }
76 else
77 {
78 /* Report "not superuser" for invalid roleids */
79 result = false;
80 }
81
82 /* If first time through, set up callback for cache flushes */
84 {
87 (Datum) 0);
89 }
90
91 /* Cache the result for next time */
92 last_roleid = roleid;
93 last_roleid_is_super = result;
94
95 return result;
96}
#define OidIsValid(objectId)
Definition: c.h:729
bool IsUnderPostmaster
Definition: globals.c:119
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define GETSTRUCT(TUP)
Definition: htup_details.h:653
void CacheRegisterSyscacheCallback(int cacheid, SyscacheCallbackFunction func, Datum arg)
Definition: inval.c:1704
bool rolsuper
Definition: pg_authid.h:35
FormData_pg_authid * Form_pg_authid
Definition: pg_authid.h:56
uintptr_t Datum
Definition: postgres.h:64
static Datum ObjectIdGetDatum(Oid X)
Definition: postgres.h:252
static bool roleid_callback_registered
Definition: superuser.c:37
static void RoleidCallback(Datum arg, int cacheid, uint32 hashvalue)
Definition: superuser.c:103
static bool last_roleid_is_super
Definition: superuser.c:36
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:269
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:221

References CacheRegisterSyscacheCallback(), GETSTRUCT, HeapTupleIsValid, IsUnderPostmaster, last_roleid, last_roleid_is_super, ObjectIdGetDatum(), OidIsValid, ReleaseSysCache(), roleid_callback_registered, RoleidCallback(), rolsuper, and SearchSysCache1().

Referenced by AlterEventTriggerOwner_internal(), AlterForeignDataWrapperOwner_internal(), AlterPublicationOwner_internal(), check_conn_params(), check_object_ownership(), check_role_grantor(), check_role_membership_authorization(), check_session_authorization(), CreateRole(), CreateSubscription(), DropSubscription(), emit_audit_message(), GetSubscription(), has_bypassrls_privilege(), has_createrole_privilege(), has_privs_of_role(), has_rolreplication(), is_admin_of_role(), is_member_of_role(), LockGXact(), member_can_set_role(), object_aclmask_ext(), object_ownercheck(), pg_class_aclmask_ext(), pg_largeobject_aclmask_snapshot(), pg_namespace_aclmask_ext(), pg_parameter_acl_aclmask(), pg_parameter_aclmask(), pg_signal_backend(), pg_type_aclmask_ext(), pgfdw_security_check(), REGRESS_exec_check_perms(), REGRESS_object_access_hook(), REGRESS_object_access_hook_str(), REGRESS_utility_command(), select_best_grantor(), superuser(), and TerminateOtherDBBackends().

Variable Documentation

◆ last_roleid

Oid last_roleid = InvalidOid
static

Definition at line 35 of file superuser.c.

Referenced by RoleidCallback(), and superuser_arg().

◆ last_roleid_is_super

bool last_roleid_is_super = false
static

Definition at line 36 of file superuser.c.

Referenced by superuser_arg().

◆ roleid_callback_registered

bool roleid_callback_registered = false
static

Definition at line 37 of file superuser.c.

Referenced by superuser_arg().