PostgreSQL Source Code git master
Loading...
Searching...
No Matches
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, SysCacheIdentifier 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,
SysCacheIdentifier  cacheid,
uint32  hashvalue 
)
static

Definition at line 104 of file superuser.c.

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

References InvalidOid, and last_roleid.

Referenced by superuser_arg().

◆ superuser()

bool superuser ( void  )

Definition at line 47 of file superuser.c.

48{
49 return superuser_arg(GetUserId());
50}
Oid GetUserId(void)
Definition miscinit.c:469
bool superuser_arg(Oid roleid)
Definition superuser.c:57

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_extension_location(), 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_superuser_check(), 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(), ValidateJoinEstimator(), ValidateRestrictionEstimator(), and wait_pid().

◆ superuser_arg()

bool superuser_arg ( Oid  roleid)

Definition at line 57 of file superuser.c.

58{
59 bool result;
61
62 /* Quick out for cache hit */
63 if (OidIsValid(last_roleid) && last_roleid == roleid)
65
66 /* Special escape path in case you deleted all your users. */
68 return true;
69
70 /* OK, look up the information in pg_authid */
73 {
76 }
77 else
78 {
79 /* Report "not superuser" for invalid roleids */
80 result = false;
81 }
82
83 /* If first time through, set up callback for cache flushes */
85 {
88 (Datum) 0);
90 }
91
92 /* Cache the result for next time */
93 last_roleid = roleid;
94 last_roleid_is_super = result;
95
96 return result;
97}
#define OidIsValid(objectId)
Definition c.h:821
bool IsUnderPostmaster
Definition globals.c:120
#define HeapTupleIsValid(tuple)
Definition htup.h:78
static void * GETSTRUCT(const HeapTupleData *tuple)
void CacheRegisterSyscacheCallback(SysCacheIdentifier cacheid, SyscacheCallbackFunction func, Datum arg)
Definition inval.c:1816
bool rolsuper
Definition pg_authid.h:37
END_CATALOG_STRUCT typedef FormData_pg_authid * Form_pg_authid
Definition pg_authid.h:60
static Datum ObjectIdGetDatum(Oid X)
Definition postgres.h:262
uint64_t Datum
Definition postgres.h:70
static int fb(int x)
static bool roleid_callback_registered
Definition superuser.c:37
static void RoleidCallback(Datum arg, SysCacheIdentifier cacheid, uint32 hashvalue)
Definition superuser.c:104
static bool last_roleid_is_super
Definition superuser.c:36
void ReleaseSysCache(HeapTuple tuple)
Definition syscache.c:264
HeapTuple SearchSysCache1(SysCacheIdentifier cacheId, Datum key1)
Definition syscache.c:220

References CacheRegisterSyscacheCallback(), fb(), Form_pg_authid, 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().