Header And Logo

PostgreSQL
| The world's most advanced open source database.

Functions | Variables

superuser.c File Reference

#include "postgres.h"
#include "access/htup_details.h"
#include "catalog/pg_authid.h"
#include "utils/inval.h"
#include "utils/syscache.h"
#include "miscadmin.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

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

Definition at line 104 of file superuser.c.

References last_roleid.

Referenced by superuser_arg().

{
    /* Invalidate our local cache in case role's superuserness changed */
    last_roleid = InvalidOid;
}

bool superuser ( void   ) 

Definition at line 47 of file superuser.c.

References GetUserId(), and superuser_arg().

Referenced by AddRoleMems(), AlterForeignDataWrapper(), AlterForeignDataWrapperOwner_internal(), AlterForeignServerOwner_internal(), AlterFunction(), AlterObjectNamespace_internal(), AlterObjectOwner_internal(), AlterObjectRename_internal(), AlterOpFamily(), AlterRole(), AlterRoleSet(), AlterTypeOwner(), ATExecChangeOwner(), bt_metap(), bt_page_items(), bt_page_stats(), check_conn_params(), check_encoding_locale_matches(), connect_pg_server(), CreateCast(), CreateEventTrigger(), CreateForeignDataWrapper(), CreateFunction(), CreateProceduralLanguage(), CreateRole(), CreateTableSpace(), dblink_connstr_check(), dblink_security_check(), DefineAggregate(), DefineOpClass(), DefineOpFamily(), DefineTSParser(), DefineTSTemplate(), DefineType(), DelRoleMems(), do_pg_start_backup(), do_pg_stop_backup(), DoCopy(), DropRole(), dummy_object_relabel(), EnableDisableTrigger(), ExecSetVariableStmt(), execute_extension_script(), ExecuteDoStmt(), file_fdw_validator(), fmgr_security_definer(), fsm_page_contents(), get_raw_page_internal(), GetConfigOption(), GetConfigOptionByName(), GetConfigOptionByNum(), GetConfigOptionResetString(), GUCArrayReset(), have_createdb_privilege(), heap_page_items(), InitPostgres(), lo_export(), lo_import_internal(), main(), page_header(), pg_create_restore_point(), pg_is_xlog_replay_paused(), pg_logdir_ls(), pg_ls_dir(), pg_read_binary_file(), pg_read_binary_file_all(), pg_read_file(), pg_read_file_all(), pg_reload_conf(), pg_relpages(), pg_rotate_logfile(), pg_signal_backend(), pg_stat_file(), pg_stat_get_activity(), pg_stat_get_backend_activity(), pg_stat_get_backend_activity_start(), pg_stat_get_backend_client_addr(), pg_stat_get_backend_client_port(), pg_stat_get_backend_start(), pg_stat_get_backend_waiting(), pg_stat_get_backend_xact_start(), pg_stat_get_wal_senders(), pg_stat_statements(), pg_switch_xlog(), pg_xlog_replay_pause(), pg_xlog_replay_resume(), pgstat_get_backend_current_activity(), pgstat_reset_counters(), pgstat_reset_shared_counters(), pgstat_reset_single_counter(), pgstatginindex(), pgstatindex(), pgstattuple(), pgstattuplebyid(), ProcedureCreate(), RenameRole(), requireSuperuser(), sepgsql_restorecon(), set_config_by_name(), SetPGVariable(), ShowAllGUCConfig(), standard_ProcessUtility(), and validate_option_array_item().

{
    return superuser_arg(GetUserId());
}

bool superuser_arg ( Oid  roleid  ) 

Definition at line 57 of file superuser.c.

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

Referenced by AddRoleMems(), AlterEventTriggerOwner_internal(), AlterForeignDataWrapperOwner_internal(), check_object_ownership(), DelRoleMems(), has_createrole_privilege(), has_privs_of_role(), is_admin_of_role(), is_member_of_role(), LockGXact(), pg_class_aclmask(), pg_class_ownercheck(), pg_collation_ownercheck(), pg_conversion_ownercheck(), pg_database_aclmask(), pg_database_ownercheck(), pg_event_trigger_ownercheck(), pg_extension_ownercheck(), pg_foreign_data_wrapper_aclmask(), pg_foreign_data_wrapper_ownercheck(), pg_foreign_server_aclmask(), pg_foreign_server_ownercheck(), pg_language_aclmask(), pg_language_ownercheck(), pg_largeobject_aclmask_snapshot(), pg_largeobject_ownercheck(), pg_namespace_aclmask(), pg_namespace_ownercheck(), pg_opclass_ownercheck(), pg_oper_ownercheck(), pg_opfamily_ownercheck(), pg_proc_aclmask(), pg_proc_ownercheck(), pg_tablespace_aclmask(), pg_tablespace_ownercheck(), pg_ts_config_ownercheck(), pg_ts_dict_ownercheck(), pg_type_aclmask(), pg_type_ownercheck(), pltcl_init_load_unknown(), select_best_grantor(), and superuser().

{
    bool        result;
    HeapTuple   rtup;

    /* Quick out for cache hit */
    if (OidIsValid(last_roleid) && last_roleid == roleid)
        return last_roleid_is_super;

    /* Special escape path in case you deleted all your users. */
    if (!IsUnderPostmaster && roleid == BOOTSTRAP_SUPERUSERID)
        return true;

    /* OK, look up the information in pg_authid */
    rtup = SearchSysCache1(AUTHOID, ObjectIdGetDatum(roleid));
    if (HeapTupleIsValid(rtup))
    {
        result = ((Form_pg_authid) GETSTRUCT(rtup))->rolsuper;
        ReleaseSysCache(rtup);
    }
    else
    {
        /* Report "not superuser" for invalid roleids */
        result = false;
    }

    /* If first time through, set up callback for cache flushes */
    if (!roleid_callback_registered)
    {
        CacheRegisterSyscacheCallback(AUTHOID,
                                      RoleidCallback,
                                      (Datum) 0);
        roleid_callback_registered = true;
    }

    /* Cache the result for next time */
    last_roleid = roleid;
    last_roleid_is_super = result;

    return result;
}


Variable Documentation

Oid last_roleid = InvalidOid [static]

Definition at line 36 of file superuser.c.

Referenced by RoleidCallback(), and superuser_arg().

bool last_roleid_is_super = false [static]

Definition at line 37 of file superuser.c.

Referenced by superuser_arg().

bool roleid_callback_registered = false [static]

Definition at line 38 of file superuser.c.

Referenced by superuser_arg().