PostgreSQL Source Code git master
Loading...
Searching...
No Matches
acl.c File Reference
#include "postgres.h"
#include <ctype.h>
#include "access/htup_details.h"
#include "bootstrap/bootstrap.h"
#include "catalog/catalog.h"
#include "catalog/namespace.h"
#include "catalog/pg_auth_members.h"
#include "catalog/pg_authid.h"
#include "catalog/pg_class.h"
#include "catalog/pg_database.h"
#include "catalog/pg_foreign_data_wrapper.h"
#include "catalog/pg_foreign_server.h"
#include "catalog/pg_language.h"
#include "catalog/pg_largeobject.h"
#include "catalog/pg_namespace.h"
#include "catalog/pg_proc.h"
#include "catalog/pg_tablespace.h"
#include "catalog/pg_type.h"
#include "commands/proclang.h"
#include "commands/tablespace.h"
#include "common/hashfn.h"
#include "foreign/foreign.h"
#include "funcapi.h"
#include "lib/bloomfilter.h"
#include "lib/qunique.h"
#include "miscadmin.h"
#include "port/pg_bitutils.h"
#include "storage/large_object.h"
#include "utils/acl.h"
#include "utils/array.h"
#include "utils/builtins.h"
#include "utils/catcache.h"
#include "utils/inval.h"
#include "utils/lsyscache.h"
#include "utils/memutils.h"
#include "utils/snapmgr.h"
#include "utils/syscache.h"
#include "utils/varlena.h"
Include dependency graph for acl.c:

Go to the source code of this file.

Data Structures

struct  priv_map
 

Macros

#define ROLES_LIST_BLOOM_THRESHOLD   1024
 

Enumerations

enum  RoleRecurseType { ROLERECURSE_MEMBERS = 0 , ROLERECURSE_PRIVS = 1 , ROLERECURSE_SETROLE = 2 }
 

Functions

static const chargetid (const char *s, char *n, Node *escontext)
 
static void putid (char *p, const char *s)
 
static Aclallocacl (int n)
 
static void check_acl (const Acl *acl)
 
static const characlparse (const char *s, AclItem *aip, Node *escontext)
 
static bool aclitem_match (const AclItem *a1, const AclItem *a2)
 
static int aclitemComparator (const void *arg1, const void *arg2)
 
static void check_circularity (const Acl *old_acl, const AclItem *mod_aip, Oid ownerId)
 
static Aclrecursive_revoke (Acl *acl, Oid grantee, AclMode revoke_privs, Oid ownerId, DropBehavior behavior)
 
static AclMode convert_any_priv_string (text *priv_type_text, const priv_map *privileges)
 
static Oid convert_table_name (text *tablename)
 
static AclMode convert_table_priv_string (text *priv_type_text)
 
static AclMode convert_sequence_priv_string (text *priv_type_text)
 
static AttrNumber convert_column_name (Oid tableoid, text *column)
 
static AclMode convert_column_priv_string (text *priv_type_text)
 
static Oid convert_database_name (text *databasename)
 
static AclMode convert_database_priv_string (text *priv_type_text)
 
static Oid convert_foreign_data_wrapper_name (text *fdwname)
 
static AclMode convert_foreign_data_wrapper_priv_string (text *priv_type_text)
 
static Oid convert_function_name (text *functionname)
 
static AclMode convert_function_priv_string (text *priv_type_text)
 
static Oid convert_language_name (text *languagename)
 
static AclMode convert_language_priv_string (text *priv_type_text)
 
static Oid convert_schema_name (text *schemaname)
 
static AclMode convert_schema_priv_string (text *priv_type_text)
 
static Oid convert_server_name (text *servername)
 
static AclMode convert_server_priv_string (text *priv_type_text)
 
static Oid convert_tablespace_name (text *tablespacename)
 
static AclMode convert_tablespace_priv_string (text *priv_type_text)
 
static Oid convert_type_name (text *typename)
 
static AclMode convert_type_priv_string (text *priv_type_text)
 
static AclMode convert_parameter_priv_string (text *priv_text)
 
static AclMode convert_largeobject_priv_string (text *priv_type_text)
 
static AclMode convert_role_priv_string (text *priv_type_text)
 
static AclResult pg_role_aclcheck (Oid role_oid, Oid roleid, AclMode mode)
 
static void RoleMembershipCacheCallback (Datum arg, SysCacheIdentifier cacheid, uint32 hashvalue)
 
static bool is_safe_acl_char (unsigned char c, bool is_getid)
 
Aclmake_empty_acl (void)
 
Aclaclcopy (const Acl *orig_acl)
 
Aclaclconcat (const Acl *left_acl, const Acl *right_acl)
 
Aclaclmerge (const Acl *left_acl, const Acl *right_acl, Oid ownerId)
 
void aclitemsort (Acl *acl)
 
bool aclequal (const Acl *left_acl, const Acl *right_acl)
 
Datum aclitemin (PG_FUNCTION_ARGS)
 
Datum aclitemout (PG_FUNCTION_ARGS)
 
Datum aclitem_eq (PG_FUNCTION_ARGS)
 
Datum hash_aclitem (PG_FUNCTION_ARGS)
 
Datum hash_aclitem_extended (PG_FUNCTION_ARGS)
 
Aclacldefault (ObjectType objtype, Oid ownerId)
 
Datum acldefault_sql (PG_FUNCTION_ARGS)
 
Aclaclupdate (const Acl *old_acl, const AclItem *mod_aip, int modechg, Oid ownerId, DropBehavior behavior)
 
Aclaclnewowner (const Acl *old_acl, Oid oldOwnerId, Oid newOwnerId)
 
AclMode aclmask (const Acl *acl, Oid roleid, Oid ownerId, AclMode mask, AclMaskHow how)
 
static AclMode aclmask_direct (const Acl *acl, Oid roleid, Oid ownerId, AclMode mask, AclMaskHow how)
 
int aclmembers (const Acl *acl, Oid **roleids)
 
Datum aclinsert (PG_FUNCTION_ARGS)
 
Datum aclremove (PG_FUNCTION_ARGS)
 
Datum aclcontains (PG_FUNCTION_ARGS)
 
Datum makeaclitem (PG_FUNCTION_ARGS)
 
static const charconvert_aclright_to_string (int aclright)
 
Datum aclexplode (PG_FUNCTION_ARGS)
 
Datum has_table_privilege_name_name (PG_FUNCTION_ARGS)
 
Datum has_table_privilege_name (PG_FUNCTION_ARGS)
 
Datum has_table_privilege_name_id (PG_FUNCTION_ARGS)
 
Datum has_table_privilege_id (PG_FUNCTION_ARGS)
 
Datum has_table_privilege_id_name (PG_FUNCTION_ARGS)
 
Datum has_table_privilege_id_id (PG_FUNCTION_ARGS)
 
Datum has_sequence_privilege_name_name (PG_FUNCTION_ARGS)
 
Datum has_sequence_privilege_name (PG_FUNCTION_ARGS)
 
Datum has_sequence_privilege_name_id (PG_FUNCTION_ARGS)
 
Datum has_sequence_privilege_id (PG_FUNCTION_ARGS)
 
Datum has_sequence_privilege_id_name (PG_FUNCTION_ARGS)
 
Datum has_sequence_privilege_id_id (PG_FUNCTION_ARGS)
 
Datum has_any_column_privilege_name_name (PG_FUNCTION_ARGS)
 
Datum has_any_column_privilege_name (PG_FUNCTION_ARGS)
 
Datum has_any_column_privilege_name_id (PG_FUNCTION_ARGS)
 
Datum has_any_column_privilege_id (PG_FUNCTION_ARGS)
 
Datum has_any_column_privilege_id_name (PG_FUNCTION_ARGS)
 
Datum has_any_column_privilege_id_id (PG_FUNCTION_ARGS)
 
static int column_privilege_check (Oid tableoid, AttrNumber attnum, Oid roleid, AclMode mode)
 
Datum has_column_privilege_name_name_name (PG_FUNCTION_ARGS)
 
Datum has_column_privilege_name_name_attnum (PG_FUNCTION_ARGS)
 
Datum has_column_privilege_name_id_name (PG_FUNCTION_ARGS)
 
Datum has_column_privilege_name_id_attnum (PG_FUNCTION_ARGS)
 
Datum has_column_privilege_id_name_name (PG_FUNCTION_ARGS)
 
Datum has_column_privilege_id_name_attnum (PG_FUNCTION_ARGS)
 
Datum has_column_privilege_id_id_name (PG_FUNCTION_ARGS)
 
Datum has_column_privilege_id_id_attnum (PG_FUNCTION_ARGS)
 
Datum has_column_privilege_name_name (PG_FUNCTION_ARGS)
 
Datum has_column_privilege_name_attnum (PG_FUNCTION_ARGS)
 
Datum has_column_privilege_id_name (PG_FUNCTION_ARGS)
 
Datum has_column_privilege_id_attnum (PG_FUNCTION_ARGS)
 
Datum has_database_privilege_name_name (PG_FUNCTION_ARGS)
 
Datum has_database_privilege_name (PG_FUNCTION_ARGS)
 
Datum has_database_privilege_name_id (PG_FUNCTION_ARGS)
 
Datum has_database_privilege_id (PG_FUNCTION_ARGS)
 
Datum has_database_privilege_id_name (PG_FUNCTION_ARGS)
 
Datum has_database_privilege_id_id (PG_FUNCTION_ARGS)
 
Datum has_foreign_data_wrapper_privilege_name_name (PG_FUNCTION_ARGS)
 
Datum has_foreign_data_wrapper_privilege_name (PG_FUNCTION_ARGS)
 
Datum has_foreign_data_wrapper_privilege_name_id (PG_FUNCTION_ARGS)
 
Datum has_foreign_data_wrapper_privilege_id (PG_FUNCTION_ARGS)
 
Datum has_foreign_data_wrapper_privilege_id_name (PG_FUNCTION_ARGS)
 
Datum has_foreign_data_wrapper_privilege_id_id (PG_FUNCTION_ARGS)
 
Datum has_function_privilege_name_name (PG_FUNCTION_ARGS)
 
Datum has_function_privilege_name (PG_FUNCTION_ARGS)
 
Datum has_function_privilege_name_id (PG_FUNCTION_ARGS)
 
Datum has_function_privilege_id (PG_FUNCTION_ARGS)
 
Datum has_function_privilege_id_name (PG_FUNCTION_ARGS)
 
Datum has_function_privilege_id_id (PG_FUNCTION_ARGS)
 
Datum has_language_privilege_name_name (PG_FUNCTION_ARGS)
 
Datum has_language_privilege_name (PG_FUNCTION_ARGS)
 
Datum has_language_privilege_name_id (PG_FUNCTION_ARGS)
 
Datum has_language_privilege_id (PG_FUNCTION_ARGS)
 
Datum has_language_privilege_id_name (PG_FUNCTION_ARGS)
 
Datum has_language_privilege_id_id (PG_FUNCTION_ARGS)
 
Datum has_schema_privilege_name_name (PG_FUNCTION_ARGS)
 
Datum has_schema_privilege_name (PG_FUNCTION_ARGS)
 
Datum has_schema_privilege_name_id (PG_FUNCTION_ARGS)
 
Datum has_schema_privilege_id (PG_FUNCTION_ARGS)
 
Datum has_schema_privilege_id_name (PG_FUNCTION_ARGS)
 
Datum has_schema_privilege_id_id (PG_FUNCTION_ARGS)
 
Datum has_server_privilege_name_name (PG_FUNCTION_ARGS)
 
Datum has_server_privilege_name (PG_FUNCTION_ARGS)
 
Datum has_server_privilege_name_id (PG_FUNCTION_ARGS)
 
Datum has_server_privilege_id (PG_FUNCTION_ARGS)
 
Datum has_server_privilege_id_name (PG_FUNCTION_ARGS)
 
Datum has_server_privilege_id_id (PG_FUNCTION_ARGS)
 
Datum has_tablespace_privilege_name_name (PG_FUNCTION_ARGS)
 
Datum has_tablespace_privilege_name (PG_FUNCTION_ARGS)
 
Datum has_tablespace_privilege_name_id (PG_FUNCTION_ARGS)
 
Datum has_tablespace_privilege_id (PG_FUNCTION_ARGS)
 
Datum has_tablespace_privilege_id_name (PG_FUNCTION_ARGS)
 
Datum has_tablespace_privilege_id_id (PG_FUNCTION_ARGS)
 
Datum has_type_privilege_name_name (PG_FUNCTION_ARGS)
 
Datum has_type_privilege_name (PG_FUNCTION_ARGS)
 
Datum has_type_privilege_name_id (PG_FUNCTION_ARGS)
 
Datum has_type_privilege_id (PG_FUNCTION_ARGS)
 
Datum has_type_privilege_id_name (PG_FUNCTION_ARGS)
 
Datum has_type_privilege_id_id (PG_FUNCTION_ARGS)
 
static bool has_param_priv_byname (Oid roleid, const text *parameter, AclMode priv)
 
Datum has_parameter_privilege_name_name (PG_FUNCTION_ARGS)
 
Datum has_parameter_privilege_name (PG_FUNCTION_ARGS)
 
Datum has_parameter_privilege_id_name (PG_FUNCTION_ARGS)
 
static bool has_lo_priv_byid (Oid roleid, Oid lobjId, AclMode priv, bool *is_missing)
 
Datum has_largeobject_privilege_name_id (PG_FUNCTION_ARGS)
 
Datum has_largeobject_privilege_id (PG_FUNCTION_ARGS)
 
Datum has_largeobject_privilege_id_id (PG_FUNCTION_ARGS)
 
Datum pg_has_role_name_name (PG_FUNCTION_ARGS)
 
Datum pg_has_role_name (PG_FUNCTION_ARGS)
 
Datum pg_has_role_name_id (PG_FUNCTION_ARGS)
 
Datum pg_has_role_id (PG_FUNCTION_ARGS)
 
Datum pg_has_role_id_name (PG_FUNCTION_ARGS)
 
Datum pg_has_role_id_id (PG_FUNCTION_ARGS)
 
void initialize_acl (void)
 
static Listroles_list_append (List *roles_list, bloom_filter **bf, Oid role)
 
static Listroles_is_member_of (Oid roleid, enum RoleRecurseType type, Oid admin_of, Oid *admin_role)
 
bool has_privs_of_role (Oid member, Oid role)
 
bool member_can_set_role (Oid member, Oid role)
 
void check_can_set_role (Oid member, Oid role)
 
bool is_member_of_role (Oid member, Oid role)
 
bool is_member_of_role_nosuper (Oid member, Oid role)
 
bool is_admin_of_role (Oid member, Oid role)
 
Oid select_best_admin (Oid member, Oid role)
 
void select_best_grantor (const RoleSpec *grantedBy, AclMode privileges, const Acl *acl, Oid ownerId, Oid *grantorId, AclMode *grantOptions)
 
Oid get_role_oid (const char *rolname, bool missing_ok)
 
Oid get_role_oid_or_public (const char *rolname)
 
Oid get_rolespec_oid (const RoleSpec *role, bool missing_ok)
 
HeapTuple get_rolespec_tuple (const RoleSpec *role)
 
charget_rolespec_name (const RoleSpec *role)
 
void check_rolespec_name (const RoleSpec *role, const char *detail_msg)
 

Variables

static Oid cached_role [] = {InvalidOid, InvalidOid, InvalidOid}
 
static Listcached_roles [] = {NIL, NIL, NIL}
 
static uint32 cached_db_hash
 

Macro Definition Documentation

◆ ROLES_LIST_BLOOM_THRESHOLD

#define ROLES_LIST_BLOOM_THRESHOLD   1024

Definition at line 92 of file acl.c.

Enumeration Type Documentation

◆ RoleRecurseType

Enumerator
ROLERECURSE_MEMBERS 
ROLERECURSE_PRIVS 
ROLERECURSE_SETROLE 

Definition at line 76 of file acl.c.

77{
78 ROLERECURSE_MEMBERS = 0, /* recurse unconditionally */
79 ROLERECURSE_PRIVS = 1, /* recurse through inheritable grants */
80 ROLERECURSE_SETROLE = 2 /* recurse through grants with set_option */
81};
@ ROLERECURSE_PRIVS
Definition acl.c:79
@ ROLERECURSE_MEMBERS
Definition acl.c:78
@ ROLERECURSE_SETROLE
Definition acl.c:80

Function Documentation

◆ aclconcat()

Acl * aclconcat ( const Acl left_acl,
const Acl right_acl 
)

Definition at line 491 of file acl.c.

492{
494
496
499 ACL_NUM(left_acl) * sizeof(AclItem));
500
503 ACL_NUM(right_acl) * sizeof(AclItem));
504
505 return result_acl;
506}
static Acl * allocacl(int n)
Definition acl.c:440
#define ACL_DAT(ACL)
Definition acl.h:109
#define ACL_NUM(ACL)
Definition acl.h:108
static int fb(int x)
Definition acl.h:55

References ACL_DAT, ACL_NUM, allocacl(), and fb().

Referenced by ExecGrant_Attribute().

◆ aclcontains()

Datum aclcontains ( PG_FUNCTION_ARGS  )

Definition at line 1640 of file acl.c.

1641{
1642 Acl *acl = PG_GETARG_ACL_P(0);
1644 AclItem *aidat;
1645 int i,
1646 num;
1647
1648 check_acl(acl);
1649 num = ACL_NUM(acl);
1650 aidat = ACL_DAT(acl);
1651 for (i = 0; i < num; ++i)
1652 {
1653 if (aip->ai_grantee == aidat[i].ai_grantee &&
1654 aip->ai_grantor == aidat[i].ai_grantor &&
1656 PG_RETURN_BOOL(true);
1657 }
1658 PG_RETURN_BOOL(false);
1659}
static void check_acl(const Acl *acl)
Definition acl.c:604
#define PG_GETARG_ACLITEM_P(n)
Definition acl.h:117
#define PG_GETARG_ACL_P(n)
Definition acl.h:122
#define ACLITEM_GET_RIGHTS(item)
Definition acl.h:68
#define PG_RETURN_BOOL(x)
Definition fmgr.h:360
int i
Definition isn.c:77

References ACL_DAT, ACL_NUM, ACLITEM_GET_RIGHTS, check_acl(), fb(), i, PG_GETARG_ACL_P, PG_GETARG_ACLITEM_P, and PG_RETURN_BOOL.

◆ aclcopy()

Acl * aclcopy ( const Acl orig_acl)

Definition at line 471 of file acl.c.

472{
474
476
479 ACL_NUM(orig_acl) * sizeof(AclItem));
480
481 return result_acl;
482}

References ACL_DAT, ACL_NUM, allocacl(), and fb().

Referenced by aclmerge(), ExecGrant_Relation(), and SetDefaultACL().

◆ acldefault()

Acl * acldefault ( ObjectType  objtype,
Oid  ownerId 
)

Definition at line 827 of file acl.c.

828{
831 int nacl;
832 Acl *acl;
833 AclItem *aip;
834
835 switch (objtype)
836 {
837 case OBJECT_COLUMN:
838 /* by default, columns have no extra privileges */
841 break;
842 case OBJECT_TABLE:
845 break;
846 case OBJECT_SEQUENCE:
849 break;
850 case OBJECT_DATABASE:
851 /* for backwards compatibility, grant some rights by default */
854 break;
855 case OBJECT_FUNCTION:
856 /* Grant EXECUTE by default, for now */
859 break;
860 case OBJECT_LANGUAGE:
861 /* Grant USAGE by default, for now */
864 break;
868 break;
869 case OBJECT_SCHEMA:
872 break;
876 break;
877 case OBJECT_FDW:
880 break;
884 break;
885 case OBJECT_DOMAIN:
886 case OBJECT_TYPE:
889 break;
893 break;
894 case OBJECT_PROPGRAPH:
897 break;
898 default:
899 elog(ERROR, "unrecognized object type: %d", (int) objtype);
900 world_default = ACL_NO_RIGHTS; /* keep compiler quiet */
902 break;
903 }
904
905 nacl = 0;
907 nacl++;
909 nacl++;
910
911 acl = allocacl(nacl);
912 aip = ACL_DAT(acl);
913
915 {
916 aip->ai_grantee = ACL_ID_PUBLIC;
917 aip->ai_grantor = ownerId;
919 aip++;
920 }
921
922 /*
923 * Note that the owner's entry shows all ordinary privileges but no grant
924 * options. This is because his grant options come "from the system" and
925 * not from his own efforts. (The SQL spec says that the owner's rights
926 * come from a "_SYSTEM" authid.) However, we do consider that the
927 * owner's ordinary privileges are self-granted; this lets him revoke
928 * them. We implement the owner's grant options without any explicit
929 * "_SYSTEM"-like ACL entry, by internally special-casing the owner
930 * wherever we are testing grant options.
931 */
933 {
934 aip->ai_grantee = ownerId;
935 aip->ai_grantor = ownerId;
937 }
938
939 return acl;
940}
#define ACL_ALL_RIGHTS_FOREIGN_SERVER
Definition acl.h:164
#define ACL_ALL_RIGHTS_TABLESPACE
Definition acl.h:171
#define ACL_ALL_RIGHTS_PARAMETER_ACL
Definition acl.h:168
#define ACL_ALL_RIGHTS_SCHEMA
Definition acl.h:170
#define ACL_ALL_RIGHTS_SEQUENCE
Definition acl.h:161
#define ACL_ALL_RIGHTS_DATABASE
Definition acl.h:162
#define ACL_ALL_RIGHTS_PROPGRAPH
Definition acl.h:169
#define ACL_ALL_RIGHTS_FUNCTION
Definition acl.h:165
#define ACL_ALL_RIGHTS_LANGUAGE
Definition acl.h:166
#define ACL_ALL_RIGHTS_TYPE
Definition acl.h:172
#define ACL_ALL_RIGHTS_FDW
Definition acl.h:163
#define ACLITEM_SET_PRIVS_GOPTIONS(item, privs, goptions)
Definition acl.h:82
#define ACL_ALL_RIGHTS_RELATION
Definition acl.h:160
#define ACL_ID_PUBLIC
Definition acl.h:46
#define ACL_ALL_RIGHTS_LARGEOBJECT
Definition acl.h:167
#define ERROR
Definition elog.h:39
#define elog(elevel,...)
Definition elog.h:226
#define ACL_CREATE_TEMP
Definition parsenodes.h:86
uint64 AclMode
Definition parsenodes.h:74
#define ACL_USAGE
Definition parsenodes.h:84
#define ACL_NO_RIGHTS
Definition parsenodes.h:92
@ OBJECT_FDW
@ OBJECT_PROPGRAPH
@ OBJECT_SCHEMA
@ OBJECT_DOMAIN
@ OBJECT_COLUMN
@ OBJECT_TABLESPACE
@ OBJECT_LARGEOBJECT
@ OBJECT_DATABASE
@ OBJECT_SEQUENCE
@ OBJECT_LANGUAGE
@ OBJECT_FOREIGN_SERVER
@ OBJECT_TABLE
@ OBJECT_PARAMETER_ACL
@ OBJECT_TYPE
@ OBJECT_FUNCTION
#define ACL_CONNECT
Definition parsenodes.h:87
#define ACL_EXECUTE
Definition parsenodes.h:83

References ACL_ALL_RIGHTS_DATABASE, ACL_ALL_RIGHTS_FDW, ACL_ALL_RIGHTS_FOREIGN_SERVER, ACL_ALL_RIGHTS_FUNCTION, ACL_ALL_RIGHTS_LANGUAGE, ACL_ALL_RIGHTS_LARGEOBJECT, ACL_ALL_RIGHTS_PARAMETER_ACL, ACL_ALL_RIGHTS_PROPGRAPH, ACL_ALL_RIGHTS_RELATION, ACL_ALL_RIGHTS_SCHEMA, ACL_ALL_RIGHTS_SEQUENCE, ACL_ALL_RIGHTS_TABLESPACE, ACL_ALL_RIGHTS_TYPE, ACL_CONNECT, ACL_CREATE_TEMP, ACL_DAT, ACL_EXECUTE, ACL_ID_PUBLIC, ACL_NO_RIGHTS, ACL_USAGE, ACLITEM_SET_PRIVS_GOPTIONS, allocacl(), elog, ERROR, fb(), OBJECT_COLUMN, OBJECT_DATABASE, OBJECT_DOMAIN, OBJECT_FDW, OBJECT_FOREIGN_SERVER, OBJECT_FUNCTION, OBJECT_LANGUAGE, OBJECT_LARGEOBJECT, OBJECT_PARAMETER_ACL, OBJECT_PROPGRAPH, OBJECT_SCHEMA, OBJECT_SEQUENCE, OBJECT_TABLE, OBJECT_TABLESPACE, and OBJECT_TYPE.

Referenced by acldefault_sql(), buildDefaultACLCommands(), dumpACL(), dumpRoleGUCPrivs(), dumpTable(), dumpTablespaces(), ExecGrant_Attribute(), ExecGrant_common(), ExecGrant_Largeobject(), ExecGrant_Parameter(), ExecGrant_Relation(), get_user_default_acl(), object_aclmask_ext(), pg_class_aclmask_ext(), pg_largeobject_aclmask_snapshot(), pg_namespace_aclmask_ext(), pg_parameter_acl_aclmask(), pg_parameter_aclmask(), pg_type_aclmask_ext(), and SetDefaultACL().

◆ acldefault_sql()

Datum acldefault_sql ( PG_FUNCTION_ARGS  )

Definition at line 948 of file acl.c.

949{
950 char objtypec = PG_GETARG_CHAR(0);
951 Oid owner = PG_GETARG_OID(1);
952 ObjectType objtype = 0;
953
954 switch (objtypec)
955 {
956 case 'c':
957 objtype = OBJECT_COLUMN;
958 break;
959 case 'r':
960 objtype = OBJECT_TABLE;
961 break;
962 case 's':
963 objtype = OBJECT_SEQUENCE;
964 break;
965 case 'd':
966 objtype = OBJECT_DATABASE;
967 break;
968 case 'f':
969 objtype = OBJECT_FUNCTION;
970 break;
971 case 'l':
972 objtype = OBJECT_LANGUAGE;
973 break;
974 case 'L':
975 objtype = OBJECT_LARGEOBJECT;
976 break;
977 case 'n':
978 objtype = OBJECT_SCHEMA;
979 break;
980 case 'p':
981 objtype = OBJECT_PARAMETER_ACL;
982 break;
983 case 't':
984 objtype = OBJECT_TABLESPACE;
985 break;
986 case 'F':
987 objtype = OBJECT_FDW;
988 break;
989 case 'S':
990 objtype = OBJECT_FOREIGN_SERVER;
991 break;
992 case 'T':
993 objtype = OBJECT_TYPE;
994 break;
995 default:
996 elog(ERROR, "unrecognized object type abbreviation: %c", objtypec);
997 }
998
999 PG_RETURN_ACL_P(acldefault(objtype, owner));
1000}
Acl * acldefault(ObjectType objtype, Oid ownerId)
Definition acl.c:827
#define PG_RETURN_ACL_P(x)
Definition acl.h:124
#define PG_GETARG_OID(n)
Definition fmgr.h:275
#define PG_GETARG_CHAR(n)
Definition fmgr.h:273
ObjectType
unsigned int Oid

References acldefault(), elog, ERROR, fb(), OBJECT_COLUMN, OBJECT_DATABASE, OBJECT_FDW, OBJECT_FOREIGN_SERVER, OBJECT_FUNCTION, OBJECT_LANGUAGE, OBJECT_LARGEOBJECT, OBJECT_PARAMETER_ACL, OBJECT_SCHEMA, OBJECT_SEQUENCE, OBJECT_TABLE, OBJECT_TABLESPACE, OBJECT_TYPE, PG_GETARG_CHAR, PG_GETARG_OID, and PG_RETURN_ACL_P.

◆ aclequal()

bool aclequal ( const Acl left_acl,
const Acl right_acl 
)

Definition at line 573 of file acl.c.

574{
575 /* Check for cases where one or both are empty/null */
576 if (left_acl == NULL || ACL_NUM(left_acl) == 0)
577 {
578 if (right_acl == NULL || ACL_NUM(right_acl) == 0)
579 return true;
580 else
581 return false;
582 }
583 else
584 {
585 if (right_acl == NULL || ACL_NUM(right_acl) == 0)
586 return false;
587 }
588
590 return false;
591
594 ACL_NUM(left_acl) * sizeof(AclItem)) == 0)
595 return true;
596
597 return false;
598}

References ACL_DAT, ACL_NUM, and fb().

Referenced by ExecGrant_Parameter(), get_user_default_acl(), and SetDefaultACL().

◆ aclexplode()

Datum aclexplode ( PG_FUNCTION_ARGS  )

Definition at line 1818 of file acl.c.

1819{
1820 Acl *acl = PG_GETARG_ACL_P(0);
1822 int *idx;
1823 AclItem *aidat;
1824
1825 if (SRF_IS_FIRSTCALL())
1826 {
1827 TupleDesc tupdesc;
1828 MemoryContext oldcontext;
1829
1830 check_acl(acl);
1831
1833 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
1834
1835 /*
1836 * build tupdesc for result tuples (matches out parameters in pg_proc
1837 * entry)
1838 */
1839 tupdesc = CreateTemplateTupleDesc(4);
1840 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "grantor",
1841 OIDOID, -1, 0);
1842 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "grantee",
1843 OIDOID, -1, 0);
1844 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "privilege_type",
1845 TEXTOID, -1, 0);
1846 TupleDescInitEntry(tupdesc, (AttrNumber) 4, "is_grantable",
1847 BOOLOID, -1, 0);
1848
1849 TupleDescFinalize(tupdesc);
1850 funcctx->tuple_desc = BlessTupleDesc(tupdesc);
1851
1852 /* allocate memory for user context */
1853 idx = palloc_array(int, 2);
1854 idx[0] = 0; /* ACL array item index */
1855 idx[1] = -1; /* privilege type counter */
1856 funcctx->user_fctx = idx;
1857
1858 MemoryContextSwitchTo(oldcontext);
1859 }
1860
1862 idx = (int *) funcctx->user_fctx;
1863 aidat = ACL_DAT(acl);
1864
1865 /* need test here in case acl has no items */
1866 while (idx[0] < ACL_NUM(acl))
1867 {
1868 AclItem *aidata;
1870
1871 idx[1]++;
1872 if (idx[1] == N_ACL_RIGHTS)
1873 {
1874 idx[1] = 0;
1875 idx[0]++;
1876 if (idx[0] >= ACL_NUM(acl)) /* done */
1877 break;
1878 }
1879 aidata = &aidat[idx[0]];
1880 priv_bit = UINT64CONST(1) << idx[1];
1881
1883 {
1884 Datum result;
1885 Datum values[4];
1886 bool nulls[4] = {0};
1887 HeapTuple tuple;
1888
1889 values[0] = ObjectIdGetDatum(aidata->ai_grantor);
1890 values[1] = ObjectIdGetDatum(aidata->ai_grantee);
1893
1894 tuple = heap_form_tuple(funcctx->tuple_desc, values, nulls);
1895 result = HeapTupleGetDatum(tuple);
1896
1897 SRF_RETURN_NEXT(funcctx, result);
1898 }
1899 }
1900
1902}
Datum idx(PG_FUNCTION_ARGS)
Definition _int_op.c:262
static const char * convert_aclright_to_string(int aclright)
Definition acl.c:1762
#define ACLITEM_GET_PRIVS(item)
Definition acl.h:66
#define ACLITEM_GET_GOPTIONS(item)
Definition acl.h:67
int16 AttrNumber
Definition attnum.h:21
static Datum values[MAXATTR]
Definition bootstrap.c:188
#define CStringGetTextDatum(s)
Definition builtins.h:98
#define UINT64CONST(x)
Definition c.h:633
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
#define palloc_array(type, count)
Definition fe_memutils.h:76
#define SRF_IS_FIRSTCALL()
Definition funcapi.h:304
#define SRF_PERCALL_SETUP()
Definition funcapi.h:308
#define SRF_RETURN_NEXT(_funcctx, _result)
Definition funcapi.h:310
#define SRF_FIRSTCALL_INIT()
Definition funcapi.h:306
static Datum HeapTupleGetDatum(const HeapTupleData *tuple)
Definition funcapi.h:230
#define SRF_RETURN_DONE(_funcctx)
Definition funcapi.h:328
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
Definition heaptuple.c:1037
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition palloc.h:124
#define N_ACL_RIGHTS
Definition parsenodes.h:91
static Datum BoolGetDatum(bool X)
Definition postgres.h:112
static Datum ObjectIdGetDatum(Oid X)
Definition postgres.h:252
uint64_t Datum
Definition postgres.h:70
TupleDesc CreateTemplateTupleDesc(int natts)
Definition tupdesc.c:165
void TupleDescFinalize(TupleDesc tupdesc)
Definition tupdesc.c:511
void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
Definition tupdesc.c:900

References ACL_DAT, ACL_NUM, ACLITEM_GET_GOPTIONS, ACLITEM_GET_PRIVS, BlessTupleDesc(), BoolGetDatum(), check_acl(), convert_aclright_to_string(), CreateTemplateTupleDesc(), CStringGetTextDatum, fb(), heap_form_tuple(), HeapTupleGetDatum(), idx(), MemoryContextSwitchTo(), N_ACL_RIGHTS, ObjectIdGetDatum(), palloc_array, PG_GETARG_ACL_P, SRF_FIRSTCALL_INIT, SRF_IS_FIRSTCALL, SRF_PERCALL_SETUP, SRF_RETURN_DONE, SRF_RETURN_NEXT, TupleDescFinalize(), TupleDescInitEntry(), UINT64CONST, and values.

◆ aclinsert()

Datum aclinsert ( PG_FUNCTION_ARGS  )

Definition at line 1620 of file acl.c.

1621{
1622 ereport(ERROR,
1624 errmsg("aclinsert is no longer supported")));
1625
1626 PG_RETURN_NULL(); /* keep compiler quiet */
1627}
int errcode(int sqlerrcode)
Definition elog.c:874
#define ereport(elevel,...)
Definition elog.h:150
#define PG_RETURN_NULL()
Definition fmgr.h:346
static char * errmsg

References ereport, errcode(), errmsg, ERROR, fb(), and PG_RETURN_NULL.

◆ aclitem_eq()

Datum aclitem_eq ( PG_FUNCTION_ARGS  )

Definition at line 772 of file acl.c.

773{
776 bool result;
777
778 result = a1->ai_privs == a2->ai_privs &&
779 a1->ai_grantee == a2->ai_grantee &&
780 a1->ai_grantor == a2->ai_grantor;
781 PG_RETURN_BOOL(result);
782}
static const FormData_pg_attribute a1
Definition heap.c:144
static const FormData_pg_attribute a2
Definition heap.c:157

References a1, a2, PG_GETARG_ACLITEM_P, and PG_RETURN_BOOL.

◆ aclitem_match()

static bool aclitem_match ( const AclItem a1,
const AclItem a2 
)
static

Definition at line 737 of file acl.c.

738{
739 return a1->ai_grantee == a2->ai_grantee &&
740 a1->ai_grantor == a2->ai_grantor;
741}

References a1, and a2.

Referenced by aclnewowner(), and aclupdate().

◆ aclitemComparator()

static int aclitemComparator ( const void arg1,
const void arg2 
)
static

Definition at line 748 of file acl.c.

749{
750 const AclItem *a1 = (const AclItem *) arg1;
751 const AclItem *a2 = (const AclItem *) arg2;
752
753 if (a1->ai_grantee > a2->ai_grantee)
754 return 1;
755 if (a1->ai_grantee < a2->ai_grantee)
756 return -1;
757 if (a1->ai_grantor > a2->ai_grantor)
758 return 1;
759 if (a1->ai_grantor < a2->ai_grantor)
760 return -1;
761 if (a1->ai_privs > a2->ai_privs)
762 return 1;
763 if (a1->ai_privs < a2->ai_privs)
764 return -1;
765 return 0;
766}

References a1, a2, and fb().

Referenced by aclitemsort().

◆ aclitemin()

Datum aclitemin ( PG_FUNCTION_ARGS  )

Definition at line 629 of file acl.c.

630{
631 const char *s = PG_GETARG_CSTRING(0);
632 Node *escontext = fcinfo->context;
633 AclItem *aip;
634
636
637 s = aclparse(s, aip, escontext);
638 if (s == NULL)
640
641 while (isspace((unsigned char) *s))
642 ++s;
643 if (*s)
644 ereturn(escontext, (Datum) 0,
646 errmsg("extra garbage at the end of the ACL specification")));
647
649}
static const char * aclparse(const char *s, AclItem *aip, Node *escontext)
Definition acl.c:279
#define PG_RETURN_ACLITEM_P(x)
Definition acl.h:118
#define ereturn(context, dummy_value,...)
Definition elog.h:278
#define palloc_object(type)
Definition fe_memutils.h:74
#define PG_GETARG_CSTRING(n)
Definition fmgr.h:278
Definition nodes.h:135

References aclparse(), ereturn, errcode(), errmsg, fb(), palloc_object, PG_GETARG_CSTRING, PG_RETURN_ACLITEM_P, and PG_RETURN_NULL.

◆ aclitemout()

Datum aclitemout ( PG_FUNCTION_ARGS  )

Definition at line 664 of file acl.c.

665{
667 char *p;
668 char *out;
669 HeapTuple htup;
670 unsigned i;
671
672 out = palloc(strlen("=/") +
673 2 * N_ACL_RIGHTS +
674 2 * (2 * NAMEDATALEN + 2) +
675 1);
676
677 p = out;
678 *p = '\0';
679
680 if (aip->ai_grantee != ACL_ID_PUBLIC)
681 {
683 htup = SearchSysCache1(AUTHOID, ObjectIdGetDatum(aip->ai_grantee));
684 else
685 htup = NULL;
686 if (HeapTupleIsValid(htup))
687 {
689 ReleaseSysCache(htup);
690 }
691 else
692 {
693 /* No such entry, or bootstrap mode: print numeric OID */
694 sprintf(p, "%u", aip->ai_grantee);
695 }
696 }
697 while (*p)
698 ++p;
699
700 *p++ = '=';
701
702 for (i = 0; i < N_ACL_RIGHTS; ++i)
703 {
704 if (ACLITEM_GET_PRIVS(*aip) & (UINT64CONST(1) << i))
705 *p++ = ACL_ALL_RIGHTS_STR[i];
706 if (ACLITEM_GET_GOPTIONS(*aip) & (UINT64CONST(1) << i))
707 *p++ = '*';
708 }
709
710 *p++ = '/';
711 *p = '\0';
712
714 htup = SearchSysCache1(AUTHOID, ObjectIdGetDatum(aip->ai_grantor));
715 else
716 htup = NULL;
717 if (HeapTupleIsValid(htup))
718 {
720 ReleaseSysCache(htup);
721 }
722 else
723 {
724 /* No such entry, or bootstrap mode: print numeric OID */
725 sprintf(p, "%u", aip->ai_grantor);
726 }
727
729}
static void putid(char *p, const char *s)
Definition acl.c:224
#define ACL_ALL_RIGHTS_STR
Definition acl.h:154
#define NameStr(name)
Definition c.h:837
#define PG_RETURN_CSTRING(x)
Definition fmgr.h:364
#define HeapTupleIsValid(tuple)
Definition htup.h:78
static void * GETSTRUCT(const HeapTupleData *tuple)
void * palloc(Size size)
Definition mcxt.c:1387
#define IsBootstrapProcessingMode()
Definition miscadmin.h:477
NameData rolname
Definition pg_authid.h:36
END_CATALOG_STRUCT typedef FormData_pg_authid * Form_pg_authid
Definition pg_authid.h:60
#define NAMEDATALEN
#define sprintf
Definition port.h:262
void ReleaseSysCache(HeapTuple tuple)
Definition syscache.c:265
HeapTuple SearchSysCache1(SysCacheIdentifier cacheId, Datum key1)
Definition syscache.c:221

References ACL_ALL_RIGHTS_STR, ACL_ID_PUBLIC, ACLITEM_GET_GOPTIONS, ACLITEM_GET_PRIVS, fb(), Form_pg_authid, GETSTRUCT(), HeapTupleIsValid, i, IsBootstrapProcessingMode, N_ACL_RIGHTS, NAMEDATALEN, NameStr, ObjectIdGetDatum(), palloc(), PG_GETARG_ACLITEM_P, PG_RETURN_CSTRING, putid(), ReleaseSysCache(), rolname, SearchSysCache1(), sprintf, and UINT64CONST.

◆ aclitemsort()

void aclitemsort ( Acl acl)

Definition at line 559 of file acl.c.

560{
561 if (acl != NULL && ACL_NUM(acl) > 1)
562 qsort(ACL_DAT(acl), ACL_NUM(acl), sizeof(AclItem), aclitemComparator);
563}
static int aclitemComparator(const void *arg1, const void *arg2)
Definition acl.c:748
#define qsort(a, b, c, d)
Definition port.h:495

References ACL_DAT, ACL_NUM, aclitemComparator(), fb(), and qsort.

Referenced by get_user_default_acl(), and SetDefaultACL().

◆ aclmask()

AclMode aclmask ( const Acl acl,
Oid  roleid,
Oid  ownerId,
AclMode  mask,
AclMaskHow  how 
)

Definition at line 1416 of file acl.c.

1418{
1419 AclMode result;
1421 AclItem *aidat;
1422 int i,
1423 num;
1424
1425 /*
1426 * Null ACL should not happen, since caller should have inserted
1427 * appropriate default
1428 */
1429 if (acl == NULL)
1430 elog(ERROR, "null ACL");
1431
1432 check_acl(acl);
1433
1434 /* Quick exit for mask == 0 */
1435 if (mask == 0)
1436 return 0;
1437
1438 result = 0;
1439
1440 /* Owner always implicitly has all grant options */
1441 if ((mask & ACLITEM_ALL_GOPTION_BITS) &&
1442 has_privs_of_role(roleid, ownerId))
1443 {
1444 result = mask & ACLITEM_ALL_GOPTION_BITS;
1445 if ((how == ACLMASK_ALL) ? (result == mask) : (result != 0))
1446 return result;
1447 }
1448
1449 num = ACL_NUM(acl);
1450 aidat = ACL_DAT(acl);
1451
1452 /*
1453 * Check privileges granted directly to roleid or to public
1454 */
1455 for (i = 0; i < num; i++)
1456 {
1457 AclItem *aidata = &aidat[i];
1458
1459 if (aidata->ai_grantee == ACL_ID_PUBLIC ||
1460 aidata->ai_grantee == roleid)
1461 {
1462 result |= aidata->ai_privs & mask;
1463 if ((how == ACLMASK_ALL) ? (result == mask) : (result != 0))
1464 return result;
1465 }
1466 }
1467
1468 /*
1469 * Check privileges granted indirectly via role memberships. We do this in
1470 * a separate pass to minimize expensive indirect membership tests. In
1471 * particular, it's worth testing whether a given ACL entry grants any
1472 * privileges still of interest before we perform the has_privs_of_role
1473 * test.
1474 */
1475 remaining = mask & ~result;
1476 for (i = 0; i < num; i++)
1477 {
1478 AclItem *aidata = &aidat[i];
1479
1480 if (aidata->ai_grantee == ACL_ID_PUBLIC ||
1481 aidata->ai_grantee == roleid)
1482 continue; /* already checked it */
1483
1484 if ((aidata->ai_privs & remaining) &&
1485 has_privs_of_role(roleid, aidata->ai_grantee))
1486 {
1487 result |= aidata->ai_privs & mask;
1488 if ((how == ACLMASK_ALL) ? (result == mask) : (result != 0))
1489 return result;
1490 remaining = mask & ~result;
1491 }
1492 }
1493
1494 return result;
1495}
bool has_privs_of_role(Oid member, Oid role)
Definition acl.c:5314
#define ACLITEM_ALL_GOPTION_BITS
Definition acl.h:88
@ ACLMASK_ALL
Definition acl.h:177
int remaining
Definition informix.c:692
AclMode ai_privs
Definition acl.h:58

References ACL_DAT, ACL_ID_PUBLIC, ACL_NUM, ACLITEM_ALL_GOPTION_BITS, ACLMASK_ALL, AclItem::ai_privs, check_acl(), elog, ERROR, fb(), has_privs_of_role(), i, and remaining.

Referenced by check_circularity(), LockTableAclCheck(), object_aclmask_ext(), pg_attribute_aclcheck_all_ext(), pg_attribute_aclmask_ext(), pg_class_aclmask_ext(), pg_largeobject_aclmask_snapshot(), pg_namespace_aclmask_ext(), pg_parameter_acl_aclmask(), pg_parameter_aclmask(), pg_type_aclmask_ext(), and recursive_revoke().

◆ aclmask_direct()

static AclMode aclmask_direct ( const Acl acl,
Oid  roleid,
Oid  ownerId,
AclMode  mask,
AclMaskHow  how 
)
static

Definition at line 1505 of file acl.c.

1507{
1508 AclMode result;
1509 AclItem *aidat;
1510 int i,
1511 num;
1512
1513 /*
1514 * Null ACL should not happen, since caller should have inserted
1515 * appropriate default
1516 */
1517 if (acl == NULL)
1518 elog(ERROR, "null ACL");
1519
1520 check_acl(acl);
1521
1522 /* Quick exit for mask == 0 */
1523 if (mask == 0)
1524 return 0;
1525
1526 result = 0;
1527
1528 /* Owner always implicitly has all grant options */
1529 if ((mask & ACLITEM_ALL_GOPTION_BITS) &&
1530 roleid == ownerId)
1531 {
1532 result = mask & ACLITEM_ALL_GOPTION_BITS;
1533 if ((how == ACLMASK_ALL) ? (result == mask) : (result != 0))
1534 return result;
1535 }
1536
1537 num = ACL_NUM(acl);
1538 aidat = ACL_DAT(acl);
1539
1540 /*
1541 * Check privileges granted directly to roleid (and not to public)
1542 */
1543 for (i = 0; i < num; i++)
1544 {
1545 AclItem *aidata = &aidat[i];
1546
1547 if (aidata->ai_grantee == roleid)
1548 {
1549 result |= aidata->ai_privs & mask;
1550 if ((how == ACLMASK_ALL) ? (result == mask) : (result != 0))
1551 return result;
1552 }
1553 }
1554
1555 return result;
1556}

References ACL_DAT, ACL_NUM, ACLITEM_ALL_GOPTION_BITS, ACLMASK_ALL, AclItem::ai_privs, check_acl(), elog, ERROR, fb(), and i.

Referenced by select_best_grantor().

◆ aclmembers()

int aclmembers ( const Acl acl,
Oid **  roleids 
)

Definition at line 1568 of file acl.c.

1569{
1570 Oid *list;
1571 const AclItem *acldat;
1572 int i,
1573 j;
1574
1575 if (acl == NULL || ACL_NUM(acl) == 0)
1576 {
1577 *roleids = NULL;
1578 return 0;
1579 }
1580
1581 check_acl(acl);
1582
1583 /* Allocate the worst-case space requirement */
1584 list = palloc(ACL_NUM(acl) * 2 * sizeof(Oid));
1585 acldat = ACL_DAT(acl);
1586
1587 /*
1588 * Walk the ACL collecting mentioned RoleIds.
1589 */
1590 j = 0;
1591 for (i = 0; i < ACL_NUM(acl); i++)
1592 {
1593 const AclItem *ai = &acldat[i];
1594
1595 if (ai->ai_grantee != ACL_ID_PUBLIC)
1596 list[j++] = ai->ai_grantee;
1597 /* grantor is currently never PUBLIC, but let's check anyway */
1598 if (ai->ai_grantor != ACL_ID_PUBLIC)
1599 list[j++] = ai->ai_grantor;
1600 }
1601
1602 /* Sort the array */
1603 qsort(list, j, sizeof(Oid), oid_cmp);
1604
1605 /*
1606 * We could repalloc the array down to minimum size, but it's hardly worth
1607 * it since it's only transient memory.
1608 */
1609 *roleids = list;
1610
1611 /* Remove duplicates from the array */
1612 return qunique(list, j, sizeof(Oid), oid_cmp);
1613}
int j
Definition isn.c:78
int oid_cmp(const void *p1, const void *p2)
Definition oid.c:287
static size_t qunique(void *array, size_t elements, size_t width, int(*compare)(const void *, const void *))
Definition qunique.h:21

References ACL_DAT, ACL_ID_PUBLIC, ACL_NUM, check_acl(), fb(), i, j, oid_cmp(), palloc(), qsort, and qunique().

Referenced by ExecGrant_Attribute(), ExecGrant_common(), ExecGrant_Largeobject(), ExecGrant_Parameter(), ExecGrant_Relation(), recordDependencyOnNewAcl(), recordExtensionInitPrivWorker(), RemoveRoleFromInitPriv(), ReplaceRoleInInitPriv(), and SetDefaultACL().

◆ aclmerge()

Acl * aclmerge ( const Acl left_acl,
const Acl right_acl,
Oid  ownerId 
)

Definition at line 515 of file acl.c.

516{
518 AclItem *aip;
519 int i,
520 num;
521
522 /* Check for cases where one or both are empty/null */
523 if (left_acl == NULL || ACL_NUM(left_acl) == 0)
524 {
525 if (right_acl == NULL || ACL_NUM(right_acl) == 0)
526 return NULL;
527 else
528 return aclcopy(right_acl);
529 }
530 else
531 {
532 if (right_acl == NULL || ACL_NUM(right_acl) == 0)
533 return aclcopy(left_acl);
534 }
535
536 /* Merge them the hard way, one item at a time */
538
540 num = ACL_NUM(right_acl);
541
542 for (i = 0; i < num; i++, aip++)
543 {
544 Acl *tmp_acl;
545
547 ownerId, DROP_RESTRICT);
550 }
551
552 return result_acl;
553}
Acl * aclupdate(const Acl *old_acl, const AclItem *mod_aip, int modechg, Oid ownerId, DropBehavior behavior)
Definition acl.c:1020
Acl * aclcopy(const Acl *orig_acl)
Definition acl.c:471
#define ACL_MODECHG_ADD
Definition acl.h:129
void pfree(void *pointer)
Definition mcxt.c:1616
@ DROP_RESTRICT

References ACL_DAT, ACL_MODECHG_ADD, ACL_NUM, aclcopy(), aclupdate(), DROP_RESTRICT, fb(), i, and pfree().

Referenced by get_user_default_acl().

◆ aclnewowner()

Acl * aclnewowner ( const Acl old_acl,
Oid  oldOwnerId,
Oid  newOwnerId 
)

Definition at line 1147 of file acl.c.

1148{
1149 Acl *new_acl;
1155 bool newpresent = false;
1156 int dst,
1157 src,
1158 targ,
1159 num;
1160
1162
1163 /*
1164 * Make a copy of the given ACL, substituting new owner ID for old
1165 * wherever it appears as either grantor or grantee. Also note if the new
1166 * owner ID is already present.
1167 */
1168 num = ACL_NUM(old_acl);
1170 new_acl = allocacl(num);
1172 memcpy(new_aip, old_aip, num * sizeof(AclItem));
1173 for (dst = 0, dst_aip = new_aip; dst < num; dst++, dst_aip++)
1174 {
1175 if (dst_aip->ai_grantor == oldOwnerId)
1176 dst_aip->ai_grantor = newOwnerId;
1177 else if (dst_aip->ai_grantor == newOwnerId)
1178 newpresent = true;
1179 if (dst_aip->ai_grantee == oldOwnerId)
1180 dst_aip->ai_grantee = newOwnerId;
1181 else if (dst_aip->ai_grantee == newOwnerId)
1182 newpresent = true;
1183 }
1184
1185 /*
1186 * If the old ACL contained any references to the new owner, then we may
1187 * now have generated an ACL containing duplicate entries. Find them and
1188 * merge them so that there are not duplicates. (This is relatively
1189 * expensive since we use a stupid O(N^2) algorithm, but it's unlikely to
1190 * be the normal case.)
1191 *
1192 * To simplify deletion of duplicate entries, we temporarily leave them in
1193 * the array but set their privilege masks to zero; when we reach such an
1194 * entry it's just skipped. (Thus, a side effect of this code will be to
1195 * remove privilege-free entries, should there be any in the input.) dst
1196 * is the next output slot, targ is the currently considered input slot
1197 * (always >= dst), and src scans entries to the right of targ looking for
1198 * duplicates. Once an entry has been emitted to dst it is known
1199 * duplicate-free and need not be considered anymore.
1200 */
1201 if (newpresent)
1202 {
1203 dst = 0;
1204 for (targ = 0, targ_aip = new_aip; targ < num; targ++, targ_aip++)
1205 {
1206 /* ignore if deleted in an earlier pass */
1208 continue;
1209 /* find and merge any duplicates */
1210 for (src = targ + 1, src_aip = targ_aip + 1; src < num;
1211 src++, src_aip++)
1212 {
1214 continue;
1216 {
1220 /* mark the duplicate deleted */
1222 }
1223 }
1224 /* and emit to output */
1225 new_aip[dst] = *targ_aip;
1226 dst++;
1227 }
1228 /* Adjust array size to be 'dst' items */
1229 ARR_DIMS(new_acl)[0] = dst;
1231 }
1232
1233 return new_acl;
1234}
static bool aclitem_match(const AclItem *a1, const AclItem *a2)
Definition acl.c:737
#define ACL_N_SIZE(N)
Definition acl.h:110
#define ACLITEM_SET_RIGHTS(item, rights)
Definition acl.h:79
#define ARR_DIMS(a)
Definition array.h:294
static void SET_VARSIZE(void *PTR, Size len)
Definition varatt.h:432

References ACL_DAT, ACL_N_SIZE, ACL_NO_RIGHTS, ACL_NUM, ACLITEM_GET_RIGHTS, aclitem_match(), ACLITEM_SET_RIGHTS, allocacl(), ARR_DIMS, check_acl(), fb(), and SET_VARSIZE().

Referenced by AlterDatabaseOwner(), AlterForeignDataWrapperOwner_internal(), AlterForeignServerOwner_internal(), AlterObjectOwner_internal(), AlterSchemaOwner_internal(), AlterTypeOwnerInternal(), ATExecChangeOwner(), change_owner_fix_column_acls(), and ReplaceRoleInInitPriv().

◆ aclparse()

static const char * aclparse ( const char s,
AclItem aip,
Node escontext 
)
static

Definition at line 279 of file acl.c.

280{
282 goption,
283 read;
284 char name[NAMEDATALEN];
285 char name2[NAMEDATALEN];
286
287 Assert(s && aip);
288
289 s = getid(s, name, escontext);
290 if (s == NULL)
291 return NULL;
292 if (*s != '=')
293 {
294 /* we just read a keyword, not a name */
295 if (strcmp(name, "group") != 0 && strcmp(name, "user") != 0)
296 ereturn(escontext, NULL,
298 errmsg("unrecognized key word: \"%s\"", name),
299 errhint("ACL key word must be \"group\" or \"user\".")));
300 /* move s to the name beyond the keyword */
301 s = getid(s, name, escontext);
302 if (s == NULL)
303 return NULL;
304 if (name[0] == '\0')
305 ereturn(escontext, NULL,
307 errmsg("missing name"),
308 errhint("A name must follow the \"group\" or \"user\" key word.")));
309 }
310
311 if (*s != '=')
312 ereturn(escontext, NULL,
314 errmsg("missing \"=\" sign")));
315
317
318 for (++s, read = 0; isalpha((unsigned char) *s) || *s == '*'; s++)
319 {
320 switch (*s)
321 {
322 case '*':
323 goption |= read;
324 break;
325 case ACL_INSERT_CHR:
327 break;
328 case ACL_SELECT_CHR:
330 break;
331 case ACL_UPDATE_CHR:
333 break;
334 case ACL_DELETE_CHR:
336 break;
337 case ACL_TRUNCATE_CHR:
339 break;
342 break;
343 case ACL_TRIGGER_CHR:
345 break;
346 case ACL_EXECUTE_CHR:
348 break;
349 case ACL_USAGE_CHR:
350 read = ACL_USAGE;
351 break;
352 case ACL_CREATE_CHR:
354 break;
357 break;
358 case ACL_CONNECT_CHR:
360 break;
361 case ACL_SET_CHR:
362 read = ACL_SET;
363 break;
366 break;
367 case ACL_MAINTAIN_CHR:
369 break;
370 default:
371 ereturn(escontext, NULL,
373 errmsg("invalid mode character: must be one of \"%s\"",
375 }
376
377 privs |= read;
378 }
379
380 if (name[0] == '\0')
381 aip->ai_grantee = ACL_ID_PUBLIC;
382 else
383 {
385 aip->ai_grantee = boot_get_role_oid(name);
386 else
387 aip->ai_grantee = get_role_oid(name, true);
388 if (!OidIsValid(aip->ai_grantee))
389 ereturn(escontext, NULL,
391 errmsg("role \"%s\" does not exist", name)));
392 }
393
394 /*
395 * XXX Allow a degree of backward compatibility by defaulting the grantor
396 * to the superuser. We condone that practice in the catalog .dat files
397 * (i.e., in bootstrap mode) for brevity; otherwise, issue a warning.
398 */
399 if (*s == '/')
400 {
401 s = getid(s + 1, name2, escontext);
402 if (s == NULL)
403 return NULL;
404 if (name2[0] == '\0')
405 ereturn(escontext, NULL,
407 errmsg("a name must follow the \"/\" sign")));
409 aip->ai_grantor = boot_get_role_oid(name2);
410 else
411 aip->ai_grantor = get_role_oid(name2, true);
412 if (!OidIsValid(aip->ai_grantor))
413 ereturn(escontext, NULL,
415 errmsg("role \"%s\" does not exist", name2)));
416 }
417 else
418 {
419 aip->ai_grantor = BOOTSTRAP_SUPERUSERID;
423 errmsg("defaulting grantor to user ID %u",
425 }
426
428
429 return s;
430}
static const char * getid(const char *s, char *n, Node *escontext)
Definition acl.c:171
Oid get_role_oid(const char *rolname, bool missing_ok)
Definition acl.c:5605
#define ACL_CREATE_CHR
Definition acl.h:146
#define ACL_SET_CHR
Definition acl.h:149
#define ACL_REFERENCES_CHR
Definition acl.h:142
#define ACL_TRUNCATE_CHR
Definition acl.h:141
#define ACL_SELECT_CHR
Definition acl.h:138
#define ACL_EXECUTE_CHR
Definition acl.h:144
#define ACL_DELETE_CHR
Definition acl.h:140
#define ACL_INSERT_CHR
Definition acl.h:137
#define ACL_UPDATE_CHR
Definition acl.h:139
#define ACL_ALTER_SYSTEM_CHR
Definition acl.h:150
#define ACL_USAGE_CHR
Definition acl.h:145
#define ACL_CONNECT_CHR
Definition acl.h:148
#define ACL_TRIGGER_CHR
Definition acl.h:143
#define ACL_CREATE_TEMP_CHR
Definition acl.h:147
#define ACL_MAINTAIN_CHR
Definition acl.h:151
Oid boot_get_role_oid(const char *rolname)
Definition bootstrap.c:1087
#define Assert(condition)
Definition c.h:945
#define OidIsValid(objectId)
Definition c.h:860
int errhint(const char *fmt,...) pg_attribute_printf(1
#define WARNING
Definition elog.h:36
#define read(a, b, c)
Definition win32.h:13
#define ACL_SET
Definition parsenodes.h:88
#define ACL_DELETE
Definition parsenodes.h:79
#define ACL_MAINTAIN
Definition parsenodes.h:90
#define ACL_INSERT
Definition parsenodes.h:76
#define ACL_UPDATE
Definition parsenodes.h:78
#define ACL_ALTER_SYSTEM
Definition parsenodes.h:89
#define ACL_REFERENCES
Definition parsenodes.h:81
#define ACL_SELECT
Definition parsenodes.h:77
#define ACL_TRUNCATE
Definition parsenodes.h:80
#define ACL_CREATE
Definition parsenodes.h:85
#define ACL_TRIGGER
Definition parsenodes.h:82
const char * name

References ACL_ALL_RIGHTS_STR, ACL_ALTER_SYSTEM, ACL_ALTER_SYSTEM_CHR, ACL_CONNECT, ACL_CONNECT_CHR, ACL_CREATE, ACL_CREATE_CHR, ACL_CREATE_TEMP, ACL_CREATE_TEMP_CHR, ACL_DELETE, ACL_DELETE_CHR, ACL_EXECUTE, ACL_EXECUTE_CHR, ACL_ID_PUBLIC, ACL_INSERT, ACL_INSERT_CHR, ACL_MAINTAIN, ACL_MAINTAIN_CHR, ACL_NO_RIGHTS, ACL_REFERENCES, ACL_REFERENCES_CHR, ACL_SELECT, ACL_SELECT_CHR, ACL_SET, ACL_SET_CHR, ACL_TRIGGER, ACL_TRIGGER_CHR, ACL_TRUNCATE, ACL_TRUNCATE_CHR, ACL_UPDATE, ACL_UPDATE_CHR, ACL_USAGE, ACL_USAGE_CHR, ACLITEM_SET_PRIVS_GOPTIONS, Assert, boot_get_role_oid(), ereport, ereturn, errcode(), errhint(), errmsg, fb(), get_role_oid(), getid(), IsBootstrapProcessingMode, name, NAMEDATALEN, OidIsValid, read, and WARNING.

Referenced by aclitemin().

◆ aclremove()

Datum aclremove ( PG_FUNCTION_ARGS  )

Definition at line 1630 of file acl.c.

1631{
1632 ereport(ERROR,
1634 errmsg("aclremove is no longer supported")));
1635
1636 PG_RETURN_NULL(); /* keep compiler quiet */
1637}

References ereport, errcode(), errmsg, ERROR, fb(), and PG_RETURN_NULL.

◆ aclupdate()

Acl * aclupdate ( const Acl old_acl,
const AclItem mod_aip,
int  modechg,
Oid  ownerId,
DropBehavior  behavior 
)

Definition at line 1020 of file acl.c.

1022{
1023 Acl *new_acl = NULL;
1025 *new_aip = NULL;
1028 new_rights,
1030 int dst,
1031 num;
1032
1033 /* Caller probably already checked old_acl, but be safe */
1035
1036 /* If granting grant options, check for circularity */
1037 if (modechg != ACL_MODECHG_DEL &&
1040
1041 num = ACL_NUM(old_acl);
1043
1044 /*
1045 * Search the ACL for an existing entry for this grantee and grantor. If
1046 * one exists, just modify the entry in-place (well, in the same position,
1047 * since we actually return a copy); otherwise, insert the new entry at
1048 * the end.
1049 */
1050
1051 for (dst = 0; dst < num; ++dst)
1052 {
1054 {
1055 /* found a match, so modify existing item */
1056 new_acl = allocacl(num);
1059 break;
1060 }
1061 }
1062
1063 if (dst == num)
1064 {
1065 /* need to append a new item */
1066 new_acl = allocacl(num + 1);
1068 memcpy(new_aip, old_aip, num * sizeof(AclItem));
1069
1070 /* initialize the new entry with no permissions */
1071 new_aip[dst].ai_grantee = mod_aip->ai_grantee;
1072 new_aip[dst].ai_grantor = mod_aip->ai_grantor;
1075 num++; /* set num to the size of new_acl */
1076 }
1077
1080
1081 /* apply the specified permissions change */
1082 switch (modechg)
1083 {
1084 case ACL_MODECHG_ADD:
1087 break;
1088 case ACL_MODECHG_DEL:
1091 break;
1092 case ACL_MODECHG_EQL:
1095 break;
1096 }
1097
1100
1101 /*
1102 * If the adjusted entry has no permissions, delete it from the list.
1103 */
1105 {
1107 new_aip + dst + 1,
1108 (num - dst - 1) * sizeof(AclItem));
1109 /* Adjust array size to be 'num - 1' items */
1110 ARR_DIMS(new_acl)[0] = num - 1;
1111 SET_VARSIZE(new_acl, ACL_N_SIZE(num - 1));
1112 }
1113
1114 /*
1115 * Remove abandoned privileges (cascading revoke). Currently we can only
1116 * handle this when the grantee is not PUBLIC.
1117 */
1118 if ((old_goptions & ~new_goptions) != 0)
1119 {
1120 Assert(mod_aip->ai_grantee != ACL_ID_PUBLIC);
1121 new_acl = recursive_revoke(new_acl, mod_aip->ai_grantee,
1123 ownerId, behavior);
1124 }
1125
1126 return new_acl;
1127}
static Acl * recursive_revoke(Acl *acl, Oid grantee, AclMode revoke_privs, Oid ownerId, DropBehavior behavior)
Definition acl.c:1330
static void check_circularity(const Acl *old_acl, const AclItem *mod_aip, Oid ownerId)
Definition acl.c:1250
#define ACL_SIZE(ACL)
Definition acl.h:111
#define ACL_MODECHG_DEL
Definition acl.h:130
#define ACL_MODECHG_EQL
Definition acl.h:131

References ACL_DAT, ACL_ID_PUBLIC, ACL_MODECHG_ADD, ACL_MODECHG_DEL, ACL_MODECHG_EQL, ACL_N_SIZE, ACL_NO_RIGHTS, ACL_NUM, ACL_SIZE, ACLITEM_GET_GOPTIONS, ACLITEM_GET_RIGHTS, aclitem_match(), ACLITEM_SET_PRIVS_GOPTIONS, ACLITEM_SET_RIGHTS, allocacl(), ARR_DIMS, Assert, check_acl(), check_circularity(), fb(), recursive_revoke(), and SET_VARSIZE().

Referenced by aclmerge(), check_circularity(), merge_acl_with_grant(), and recursive_revoke().

◆ allocacl()

static Acl * allocacl ( int  n)
static

Definition at line 440 of file acl.c.

441{
442 Acl *new_acl;
443 Size size;
444
445 if (n < 0)
446 elog(ERROR, "invalid size: %d", n);
447 size = ACL_N_SIZE(n);
448 new_acl = (Acl *) palloc0(size);
449 SET_VARSIZE(new_acl, size);
450 new_acl->ndim = 1;
451 new_acl->dataoffset = 0; /* we never put in any nulls */
452 new_acl->elemtype = ACLITEMOID;
453 ARR_LBOUND(new_acl)[0] = 1;
454 ARR_DIMS(new_acl)[0] = n;
455 return new_acl;
456}
#define ARR_LBOUND(a)
Definition array.h:296
size_t Size
Definition c.h:691
void * palloc0(Size size)
Definition mcxt.c:1417

References ACL_N_SIZE, ARR_DIMS, ARR_LBOUND, elog, ERROR, fb(), palloc0(), and SET_VARSIZE().

Referenced by aclconcat(), aclcopy(), acldefault(), aclnewowner(), aclupdate(), check_circularity(), and make_empty_acl().

◆ check_acl()

static void check_acl ( const Acl acl)
static

Definition at line 604 of file acl.c.

605{
606 if (ARR_ELEMTYPE(acl) != ACLITEMOID)
609 errmsg("ACL array contains wrong data type")));
610 if (ARR_NDIM(acl) != 1)
613 errmsg("ACL arrays must be one-dimensional")));
614 if (ARR_HASNULL(acl))
617 errmsg("ACL arrays must not contain null values")));
618}
#define ARR_NDIM(a)
Definition array.h:290
#define ARR_ELEMTYPE(a)
Definition array.h:292
#define ARR_HASNULL(a)
Definition array.h:291

References ARR_ELEMTYPE, ARR_HASNULL, ARR_NDIM, ereport, errcode(), errmsg, ERROR, and fb().

Referenced by aclcontains(), aclexplode(), aclmask(), aclmask_direct(), aclmembers(), aclnewowner(), aclupdate(), check_circularity(), and recursive_revoke().

◆ check_can_set_role()

void check_can_set_role ( Oid  member,
Oid  role 
)

Definition at line 5371 of file acl.c.

5372{
5373 if (!member_can_set_role(member, role))
5374 ereport(ERROR,
5376 errmsg("must be able to SET ROLE \"%s\"",
5377 GetUserNameFromId(role, false))));
5378}
bool member_can_set_role(Oid member, Oid role)
Definition acl.c:5348
char * GetUserNameFromId(Oid roleid, bool noerr)
Definition miscinit.c:989

References ereport, errcode(), errmsg, ERROR, fb(), GetUserNameFromId(), and member_can_set_role().

Referenced by AlterDatabaseOwner(), AlterForeignServerOwner_internal(), AlterObjectOwner_internal(), AlterPublicationOwner_internal(), AlterSchemaOwner_internal(), AlterSubscriptionOwner_internal(), AlterTypeOwner(), ATExecChangeOwner(), createdb(), and CreateSchemaCommand().

◆ check_circularity()

static void check_circularity ( const Acl old_acl,
const AclItem mod_aip,
Oid  ownerId 
)
static

Definition at line 1250 of file acl.c.

1252{
1253 Acl *acl;
1254 AclItem *aip;
1255 int i,
1256 num;
1258
1260
1261 /*
1262 * For now, grant options can only be granted to roles, not PUBLIC.
1263 * Otherwise we'd have to work a bit harder here.
1264 */
1265 Assert(mod_aip->ai_grantee != ACL_ID_PUBLIC);
1266
1267 /* The owner always has grant options, no need to check */
1268 if (mod_aip->ai_grantor == ownerId)
1269 return;
1270
1271 /* Make a working copy */
1272 acl = allocacl(ACL_NUM(old_acl));
1274
1275 /* Zap all grant options of target grantee, plus what depends on 'em */
1277 num = ACL_NUM(acl);
1278 aip = ACL_DAT(acl);
1279 for (i = 0; i < num; i++)
1280 {
1281 if (aip[i].ai_grantee == mod_aip->ai_grantee &&
1283 {
1284 Acl *new_acl;
1285
1286 /* We'll actually zap ordinary privs too, but no matter */
1288 ownerId, DROP_CASCADE);
1289
1290 pfree(acl);
1291 acl = new_acl;
1292
1293 goto cc_restart;
1294 }
1295 }
1296
1297 /* Now we can compute grantor's independently-derived privileges */
1298 own_privs = aclmask(acl,
1299 mod_aip->ai_grantor,
1300 ownerId,
1302 ACLMASK_ALL);
1304
1305 if ((ACLITEM_GET_GOPTIONS(*mod_aip) & ~own_privs) != 0)
1306 ereport(ERROR,
1308 errmsg("grant options cannot be granted back to your own grantor")));
1309
1310 pfree(acl);
1311}
AclMode aclmask(const Acl *acl, Oid roleid, Oid ownerId, AclMode mask, AclMaskHow how)
Definition acl.c:1416
#define ACL_OPTION_TO_PRIVS(privs)
Definition acl.h:71
#define ACL_GRANT_OPTION_FOR(privs)
Definition acl.h:70
@ DROP_CASCADE

References ACL_DAT, ACL_GRANT_OPTION_FOR, ACL_ID_PUBLIC, ACL_MODECHG_DEL, ACL_NO_RIGHTS, ACL_NUM, ACL_OPTION_TO_PRIVS, ACL_SIZE, ACLITEM_GET_GOPTIONS, aclmask(), ACLMASK_ALL, aclupdate(), allocacl(), Assert, check_acl(), DROP_CASCADE, ereport, errcode(), errmsg, ERROR, fb(), i, and pfree().

Referenced by aclupdate().

◆ check_rolespec_name()

void check_rolespec_name ( const RoleSpec role,
const char detail_msg 
)

Definition at line 5746 of file acl.c.

5747{
5748 if (!role)
5749 return;
5750
5751 if (role->roletype != ROLESPEC_CSTRING)
5752 return;
5753
5754 if (IsReservedName(role->rolename))
5755 {
5756 if (detail_msg)
5757 ereport(ERROR,
5759 errmsg("role name \"%s\" is reserved",
5760 role->rolename),
5762 else
5763 ereport(ERROR,
5765 errmsg("role name \"%s\" is reserved",
5766 role->rolename)));
5767 }
5768}
bool IsReservedName(const char *name)
Definition catalog.c:278
int int errdetail_internal(const char *fmt,...) pg_attribute_printf(1
@ ROLESPEC_CSTRING
Definition parsenodes.h:419
RoleSpecType roletype
Definition parsenodes.h:429
char * rolename
Definition parsenodes.h:430

References ereport, errcode(), errdetail_internal(), errmsg, ERROR, fb(), IsReservedName(), RoleSpec::rolename, ROLESPEC_CSTRING, and RoleSpec::roletype.

Referenced by AlterRole(), and AlterRoleSet().

◆ column_privilege_check()

static int column_privilege_check ( Oid  tableoid,
AttrNumber  attnum,
Oid  roleid,
AclMode  mode 
)
static

Definition at line 2564 of file acl.c.

2566{
2568 bool is_missing = false;
2569
2570 /*
2571 * If convert_column_name failed, we can just return -1 immediately.
2572 */
2574 return -1;
2575
2576 /*
2577 * Check for column-level privileges first. This serves in part as a check
2578 * on whether the column even exists, so we need to do it before checking
2579 * table-level privilege.
2580 */
2581 aclresult = pg_attribute_aclcheck_ext(tableoid, attnum, roleid,
2582 mode, &is_missing);
2583 if (aclresult == ACLCHECK_OK)
2584 return 1;
2585 else if (is_missing)
2586 return -1;
2587
2588 /* Next check if we have the privilege at the table level */
2589 aclresult = pg_class_aclcheck_ext(tableoid, roleid, mode, &is_missing);
2590 if (aclresult == ACLCHECK_OK)
2591 return 1;
2592 else if (is_missing)
2593 return -1;
2594 else
2595 return 0;
2596}
AclResult
Definition acl.h:183
@ ACLCHECK_OK
Definition acl.h:184
AclResult pg_class_aclcheck_ext(Oid table_oid, Oid roleid, AclMode mode, bool *is_missing)
Definition aclchk.c:4092
AclResult pg_attribute_aclcheck_ext(Oid table_oid, AttrNumber attnum, Oid roleid, AclMode mode, bool *is_missing)
Definition aclchk.c:3923
#define InvalidAttrNumber
Definition attnum.h:23
int16 attnum
static PgChecksumMode mode

References ACLCHECK_OK, attnum, fb(), InvalidAttrNumber, mode, pg_attribute_aclcheck_ext(), and pg_class_aclcheck_ext().

Referenced by has_column_privilege_id_attnum(), has_column_privilege_id_id_attnum(), has_column_privilege_id_id_name(), has_column_privilege_id_name(), has_column_privilege_id_name_attnum(), has_column_privilege_id_name_name(), has_column_privilege_name_attnum(), has_column_privilege_name_id_attnum(), has_column_privilege_name_id_name(), has_column_privilege_name_name(), has_column_privilege_name_name_attnum(), and has_column_privilege_name_name_name().

◆ convert_aclright_to_string()

static const char * convert_aclright_to_string ( int  aclright)
static

Definition at line 1762 of file acl.c.

1763{
1764 switch (aclright)
1765 {
1766 case ACL_INSERT:
1767 return "INSERT";
1768 case ACL_SELECT:
1769 return "SELECT";
1770 case ACL_UPDATE:
1771 return "UPDATE";
1772 case ACL_DELETE:
1773 return "DELETE";
1774 case ACL_TRUNCATE:
1775 return "TRUNCATE";
1776 case ACL_REFERENCES:
1777 return "REFERENCES";
1778 case ACL_TRIGGER:
1779 return "TRIGGER";
1780 case ACL_EXECUTE:
1781 return "EXECUTE";
1782 case ACL_USAGE:
1783 return "USAGE";
1784 case ACL_CREATE:
1785 return "CREATE";
1786 case ACL_CREATE_TEMP:
1787 return "TEMPORARY";
1788 case ACL_CONNECT:
1789 return "CONNECT";
1790 case ACL_SET:
1791 return "SET";
1792 case ACL_ALTER_SYSTEM:
1793 return "ALTER SYSTEM";
1794 case ACL_MAINTAIN:
1795 return "MAINTAIN";
1796 default:
1797 elog(ERROR, "unrecognized aclright: %d", aclright);
1798 return NULL;
1799 }
1800}

References ACL_ALTER_SYSTEM, ACL_CONNECT, ACL_CREATE, ACL_CREATE_TEMP, ACL_DELETE, ACL_EXECUTE, ACL_INSERT, ACL_MAINTAIN, ACL_REFERENCES, ACL_SELECT, ACL_SET, ACL_TRIGGER, ACL_TRUNCATE, ACL_UPDATE, ACL_USAGE, elog, ERROR, and fb().

Referenced by aclexplode().

◆ convert_any_priv_string()

static AclMode convert_any_priv_string ( text priv_type_text,
const priv_map privileges 
)
static

Definition at line 1714 of file acl.c.

1716{
1717 AclMode result = 0;
1719 char *chunk;
1720 char *next_chunk;
1721
1722 /* We rely on priv_type being a private, modifiable string */
1723 for (chunk = priv_type; chunk; chunk = next_chunk)
1724 {
1725 int chunk_len;
1726 const priv_map *this_priv;
1727
1728 /* Split string at commas */
1729 next_chunk = strchr(chunk, ',');
1730 if (next_chunk)
1731 *next_chunk++ = '\0';
1732
1733 /* Drop leading/trailing whitespace in this chunk */
1734 while (*chunk && isspace((unsigned char) *chunk))
1735 chunk++;
1736 chunk_len = strlen(chunk);
1737 while (chunk_len > 0 && isspace((unsigned char) chunk[chunk_len - 1]))
1738 chunk_len--;
1739 chunk[chunk_len] = '\0';
1740
1741 /* Match to the privileges list */
1742 for (this_priv = privileges; this_priv->name; this_priv++)
1743 {
1744 if (pg_strcasecmp(this_priv->name, chunk) == 0)
1745 {
1746 result |= this_priv->value;
1747 break;
1748 }
1749 }
1750 if (!this_priv->name)
1751 ereport(ERROR,
1753 errmsg("unrecognized privilege type: \"%s\"", chunk)));
1754 }
1755
1757 return result;
1758}
int pg_strcasecmp(const char *s1, const char *s2)
Definition acl.c:57
char * text_to_cstring(const text *t)
Definition varlena.c:217

References ereport, errcode(), errmsg, ERROR, fb(), priv_map::name, pfree(), pg_strcasecmp(), and text_to_cstring().

Referenced by convert_column_priv_string(), convert_database_priv_string(), convert_foreign_data_wrapper_priv_string(), convert_function_priv_string(), convert_language_priv_string(), convert_largeobject_priv_string(), convert_parameter_priv_string(), convert_role_priv_string(), convert_schema_priv_string(), convert_sequence_priv_string(), convert_server_priv_string(), convert_table_priv_string(), convert_tablespace_priv_string(), convert_type_priv_string(), and makeaclitem().

◆ convert_column_name()

static AttrNumber convert_column_name ( Oid  tableoid,
text column 
)
static

Definition at line 2924 of file acl.c.

2925{
2926 char *colname;
2929
2930 colname = text_to_cstring(column);
2931
2932 /*
2933 * We don't use get_attnum() here because it will report that dropped
2934 * columns don't exist. We need to treat dropped columns differently from
2935 * nonexistent columns.
2936 */
2938 ObjectIdGetDatum(tableoid),
2939 CStringGetDatum(colname));
2941 {
2943
2945 /* We want to return NULL for dropped columns */
2946 if (attributeForm->attisdropped)
2948 else
2949 attnum = attributeForm->attnum;
2951 }
2952 else
2953 {
2954 char *tablename = get_rel_name(tableoid);
2955
2956 /*
2957 * If the table OID is bogus, or it's just been dropped, we'll get
2958 * NULL back. In such cases we want has_column_privilege to return
2959 * NULL too, so just return InvalidAttrNumber.
2960 */
2961 if (tablename != NULL)
2962 {
2963 /* tableoid exists, colname does not, so throw error */
2964 ereport(ERROR,
2966 errmsg("column \"%s\" of relation \"%s\" does not exist",
2967 colname, tablename)));
2968 }
2969 /* tableoid doesn't exist, so act like attisdropped case */
2971 }
2972
2973 pfree(colname);
2974 return attnum;
2975}
char * get_rel_name(Oid relid)
Definition lsyscache.c:2148
FormData_pg_attribute * Form_pg_attribute
static Datum CStringGetDatum(const char *X)
Definition postgres.h:370
HeapTuple SearchSysCache2(SysCacheIdentifier cacheId, Datum key1, Datum key2)
Definition syscache.c:231

References attnum, CStringGetDatum(), ereport, errcode(), errmsg, ERROR, fb(), get_rel_name(), GETSTRUCT(), HeapTupleIsValid, InvalidAttrNumber, ObjectIdGetDatum(), pfree(), ReleaseSysCache(), SearchSysCache2(), and text_to_cstring().

Referenced by has_column_privilege_id_id_name(), has_column_privilege_id_name(), has_column_privilege_id_name_name(), has_column_privilege_name_id_name(), has_column_privilege_name_name(), and has_column_privilege_name_name_name().

◆ convert_column_priv_string()

static AclMode convert_column_priv_string ( text priv_type_text)
static

Definition at line 2982 of file acl.c.

2983{
2984 static const priv_map column_priv_map[] = {
2985 {"SELECT", ACL_SELECT},
2986 {"SELECT WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_SELECT)},
2987 {"INSERT", ACL_INSERT},
2988 {"INSERT WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_INSERT)},
2989 {"UPDATE", ACL_UPDATE},
2990 {"UPDATE WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_UPDATE)},
2991 {"REFERENCES", ACL_REFERENCES},
2992 {"REFERENCES WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_REFERENCES)},
2993 {NULL, 0}
2994 };
2995
2997}
static AclMode convert_any_priv_string(text *priv_type_text, const priv_map *privileges)
Definition acl.c:1714

References ACL_GRANT_OPTION_FOR, ACL_INSERT, ACL_REFERENCES, ACL_SELECT, ACL_UPDATE, convert_any_priv_string(), and fb().

Referenced by has_any_column_privilege_id(), has_any_column_privilege_id_id(), has_any_column_privilege_id_name(), has_any_column_privilege_name(), has_any_column_privilege_name_id(), has_any_column_privilege_name_name(), has_column_privilege_id_attnum(), has_column_privilege_id_id_attnum(), has_column_privilege_id_id_name(), has_column_privilege_id_name(), has_column_privilege_id_name_attnum(), has_column_privilege_id_name_name(), has_column_privilege_name_attnum(), has_column_privilege_name_id_attnum(), has_column_privilege_name_id_name(), has_column_privilege_name_name(), has_column_privilege_name_name_attnum(), and has_column_privilege_name_name_name().

◆ convert_database_name()

static Oid convert_database_name ( text databasename)
static

Definition at line 3176 of file acl.c.

3177{
3179
3180 return get_database_oid(dbname, false);
3181}
Oid get_database_oid(const char *dbname, bool missing_ok)
char * dbname
Definition streamutil.c:49

References dbname, fb(), get_database_oid(), and text_to_cstring().

Referenced by has_database_privilege_id_name(), has_database_privilege_name(), and has_database_privilege_name_name().

◆ convert_database_priv_string()

static AclMode convert_database_priv_string ( text priv_type_text)
static

Definition at line 3188 of file acl.c.

3189{
3190 static const priv_map database_priv_map[] = {
3191 {"CREATE", ACL_CREATE},
3192 {"CREATE WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_CREATE)},
3193 {"TEMPORARY", ACL_CREATE_TEMP},
3194 {"TEMPORARY WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_CREATE_TEMP)},
3195 {"TEMP", ACL_CREATE_TEMP},
3196 {"TEMP WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_CREATE_TEMP)},
3197 {"CONNECT", ACL_CONNECT},
3198 {"CONNECT WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_CONNECT)},
3199 {NULL, 0}
3200 };
3201
3203}

References ACL_CONNECT, ACL_CREATE, ACL_CREATE_TEMP, ACL_GRANT_OPTION_FOR, convert_any_priv_string(), and fb().

Referenced by has_database_privilege_id(), has_database_privilege_id_id(), has_database_privilege_id_name(), has_database_privilege_name(), has_database_privilege_name_id(), and has_database_privilege_name_name().

◆ convert_foreign_data_wrapper_name()

static Oid convert_foreign_data_wrapper_name ( text fdwname)
static

Definition at line 3382 of file acl.c.

3383{
3384 char *fdwstr = text_to_cstring(fdwname);
3385
3386 return get_foreign_data_wrapper_oid(fdwstr, false);
3387}
Oid get_foreign_data_wrapper_oid(const char *fdwname, bool missing_ok)
Definition foreign.c:713

References fb(), get_foreign_data_wrapper_oid(), and text_to_cstring().

Referenced by has_foreign_data_wrapper_privilege_id_name(), has_foreign_data_wrapper_privilege_name(), and has_foreign_data_wrapper_privilege_name_name().

◆ convert_foreign_data_wrapper_priv_string()

◆ convert_function_name()

static Oid convert_function_name ( text functionname)
static

Definition at line 3582 of file acl.c.

3583{
3585 Oid oid;
3586
3589
3590 if (!OidIsValid(oid))
3591 ereport(ERROR,
3593 errmsg("function \"%s\" does not exist", funcname)));
3594
3595 return oid;
3596}
#define DirectFunctionCall1(func, arg1)
Definition fmgr.h:684
#define funcname
static Oid DatumGetObjectId(Datum X)
Definition postgres.h:242
Datum regprocedurein(PG_FUNCTION_ARGS)
Definition regproc.c:229

References CStringGetDatum(), DatumGetObjectId(), DirectFunctionCall1, ereport, errcode(), errmsg, ERROR, fb(), funcname, OidIsValid, regprocedurein(), and text_to_cstring().

Referenced by has_function_privilege_id_name(), has_function_privilege_name(), and has_function_privilege_name_name().

◆ convert_function_priv_string()

static AclMode convert_function_priv_string ( text priv_type_text)
static

◆ convert_language_name()

static Oid convert_language_name ( text languagename)
static

Definition at line 3791 of file acl.c.

3792{
3793 char *langname = text_to_cstring(languagename);
3794
3795 return get_language_oid(langname, false);
3796}
Oid get_language_oid(const char *langname, bool missing_ok)
Definition proclang.c:227

References fb(), get_language_oid(), and text_to_cstring().

Referenced by has_language_privilege_id_name(), has_language_privilege_name(), and has_language_privilege_name_name().

◆ convert_language_priv_string()

static AclMode convert_language_priv_string ( text priv_type_text)
static

◆ convert_largeobject_priv_string()

static AclMode convert_largeobject_priv_string ( text priv_type_text)
static

Definition at line 4838 of file acl.c.

4839{
4840 static const priv_map largeobject_priv_map[] = {
4841 {"SELECT", ACL_SELECT},
4842 {"SELECT WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_SELECT)},
4843 {"UPDATE", ACL_UPDATE},
4844 {"UPDATE WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_UPDATE)},
4845 {NULL, 0}
4846 };
4847
4849}

References ACL_GRANT_OPTION_FOR, ACL_SELECT, ACL_UPDATE, convert_any_priv_string(), and fb().

Referenced by has_largeobject_privilege_id(), has_largeobject_privilege_id_id(), and has_largeobject_privilege_name_id().

◆ convert_parameter_priv_string()

static AclMode convert_parameter_priv_string ( text priv_text)
static

Definition at line 4702 of file acl.c.

4703{
4704 static const priv_map parameter_priv_map[] = {
4705 {"SET", ACL_SET},
4706 {"SET WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_SET)},
4707 {"ALTER SYSTEM", ACL_ALTER_SYSTEM},
4708 {"ALTER SYSTEM WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_ALTER_SYSTEM)},
4709 {NULL, 0}
4710 };
4711
4713}

References ACL_ALTER_SYSTEM, ACL_GRANT_OPTION_FOR, ACL_SET, convert_any_priv_string(), and fb().

Referenced by has_parameter_privilege_id_name(), has_parameter_privilege_name(), and has_parameter_privilege_name_name().

◆ convert_role_priv_string()

static AclMode convert_role_priv_string ( text priv_type_text)
static

Definition at line 5016 of file acl.c.

5017{
5018 static const priv_map role_priv_map[] = {
5019 {"USAGE", ACL_USAGE},
5020 {"MEMBER", ACL_CREATE},
5021 {"SET", ACL_SET},
5022 {"USAGE WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_CREATE)},
5023 {"USAGE WITH ADMIN OPTION", ACL_GRANT_OPTION_FOR(ACL_CREATE)},
5024 {"MEMBER WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_CREATE)},
5025 {"MEMBER WITH ADMIN OPTION", ACL_GRANT_OPTION_FOR(ACL_CREATE)},
5026 {"SET WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_CREATE)},
5027 {"SET WITH ADMIN OPTION", ACL_GRANT_OPTION_FOR(ACL_CREATE)},
5028 {NULL, 0}
5029 };
5030
5032}

References ACL_CREATE, ACL_GRANT_OPTION_FOR, ACL_SET, ACL_USAGE, convert_any_priv_string(), and fb().

Referenced by pg_has_role_id(), pg_has_role_id_id(), pg_has_role_id_name(), pg_has_role_name(), pg_has_role_name_id(), and pg_has_role_name_name().

◆ convert_schema_name()

static Oid convert_schema_name ( text schemaname)
static

Definition at line 3991 of file acl.c.

3992{
3993 char *nspname = text_to_cstring(schemaname);
3994
3995 return get_namespace_oid(nspname, false);
3996}
Oid get_namespace_oid(const char *nspname, bool missing_ok)
Definition namespace.c:3607

References get_namespace_oid(), and text_to_cstring().

Referenced by has_schema_privilege_id_name(), has_schema_privilege_name(), and has_schema_privilege_name_name().

◆ convert_schema_priv_string()

static AclMode convert_schema_priv_string ( text priv_type_text)
static

Definition at line 4003 of file acl.c.

4004{
4005 static const priv_map schema_priv_map[] = {
4006 {"CREATE", ACL_CREATE},
4007 {"CREATE WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_CREATE)},
4008 {"USAGE", ACL_USAGE},
4009 {"USAGE WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_USAGE)},
4010 {NULL, 0}
4011 };
4012
4014}

References ACL_CREATE, ACL_GRANT_OPTION_FOR, ACL_USAGE, convert_any_priv_string(), and fb().

Referenced by has_schema_privilege_id(), has_schema_privilege_id_id(), has_schema_privilege_id_name(), has_schema_privilege_name(), has_schema_privilege_name_id(), and has_schema_privilege_name_name().

◆ convert_sequence_priv_string()

static AclMode convert_sequence_priv_string ( text priv_type_text)
static

Definition at line 2327 of file acl.c.

2328{
2329 static const priv_map sequence_priv_map[] = {
2330 {"USAGE", ACL_USAGE},
2331 {"USAGE WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_USAGE)},
2332 {"SELECT", ACL_SELECT},
2333 {"SELECT WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_SELECT)},
2334 {"UPDATE", ACL_UPDATE},
2335 {"UPDATE WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_UPDATE)},
2336 {NULL, 0}
2337 };
2338
2340}

References ACL_GRANT_OPTION_FOR, ACL_SELECT, ACL_UPDATE, ACL_USAGE, convert_any_priv_string(), and fb().

Referenced by has_sequence_privilege_id(), has_sequence_privilege_id_id(), has_sequence_privilege_id_name(), has_sequence_privilege_name(), has_sequence_privilege_name_id(), and has_sequence_privilege_name_name().

◆ convert_server_name()

static Oid convert_server_name ( text servername)
static

Definition at line 4193 of file acl.c.

4194{
4195 char *serverstr = text_to_cstring(servername);
4196
4197 return get_foreign_server_oid(serverstr, false);
4198}
Oid get_foreign_server_oid(const char *servername, bool missing_ok)
Definition foreign.c:736

References fb(), get_foreign_server_oid(), and text_to_cstring().

Referenced by has_server_privilege_id_name(), has_server_privilege_name(), and has_server_privilege_name_name().

◆ convert_server_priv_string()

static AclMode convert_server_priv_string ( text priv_type_text)
static

◆ convert_table_name()

◆ convert_table_priv_string()

static AclMode convert_table_priv_string ( text priv_type_text)
static

Definition at line 2092 of file acl.c.

2093{
2094 static const priv_map table_priv_map[] = {
2095 {"SELECT", ACL_SELECT},
2096 {"SELECT WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_SELECT)},
2097 {"INSERT", ACL_INSERT},
2098 {"INSERT WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_INSERT)},
2099 {"UPDATE", ACL_UPDATE},
2100 {"UPDATE WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_UPDATE)},
2101 {"DELETE", ACL_DELETE},
2102 {"DELETE WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_DELETE)},
2103 {"TRUNCATE", ACL_TRUNCATE},
2104 {"TRUNCATE WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_TRUNCATE)},
2105 {"REFERENCES", ACL_REFERENCES},
2106 {"REFERENCES WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_REFERENCES)},
2107 {"TRIGGER", ACL_TRIGGER},
2108 {"TRIGGER WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_TRIGGER)},
2109 {"MAINTAIN", ACL_MAINTAIN},
2110 {"MAINTAIN WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_MAINTAIN)},
2111 {NULL, 0}
2112 };
2113
2115}

References ACL_DELETE, ACL_GRANT_OPTION_FOR, ACL_INSERT, ACL_MAINTAIN, ACL_REFERENCES, ACL_SELECT, ACL_TRIGGER, ACL_TRUNCATE, ACL_UPDATE, convert_any_priv_string(), and fb().

Referenced by has_table_privilege_id(), has_table_privilege_id_id(), has_table_privilege_id_name(), has_table_privilege_name(), has_table_privilege_name_id(), and has_table_privilege_name_name().

◆ convert_tablespace_name()

static Oid convert_tablespace_name ( text tablespacename)
static

Definition at line 4393 of file acl.c.

4394{
4395 char *spcname = text_to_cstring(tablespacename);
4396
4397 return get_tablespace_oid(spcname, false);
4398}
Oid get_tablespace_oid(const char *tablespacename, bool missing_ok)

References fb(), get_tablespace_oid(), and text_to_cstring().

Referenced by has_tablespace_privilege_id_name(), has_tablespace_privilege_name(), and has_tablespace_privilege_name_name().

◆ convert_tablespace_priv_string()

static AclMode convert_tablespace_priv_string ( text priv_type_text)
static

◆ convert_type_name()

static Oid convert_type_name ( text typename)
static

Definition at line 4592 of file acl.c.

4593{
4594 char *typname = text_to_cstring(typename);
4595 Oid oid;
4596
4599
4600 if (!OidIsValid(oid))
4601 ereport(ERROR,
4603 errmsg("type \"%s\" does not exist", typname)));
4604
4605 return oid;
4606}
NameData typname
Definition pg_type.h:43
Datum regtypein(PG_FUNCTION_ARGS)
Definition regproc.c:1184

References CStringGetDatum(), DatumGetObjectId(), DirectFunctionCall1, ereport, errcode(), errmsg, ERROR, fb(), OidIsValid, regtypein(), text_to_cstring(), and typname.

Referenced by has_type_privilege_id_name(), has_type_privilege_name(), and has_type_privilege_name_name().

◆ convert_type_priv_string()

static AclMode convert_type_priv_string ( text priv_type_text)
static

◆ get_role_oid()

Oid get_role_oid ( const char rolname,
bool  missing_ok 
)

◆ get_role_oid_or_public()

◆ get_rolespec_name()

char * get_rolespec_name ( const RoleSpec role)

Definition at line 5724 of file acl.c.

5725{
5726 HeapTuple tp;
5728 char *rolename;
5729
5730 tp = get_rolespec_tuple(role);
5732 rolename = pstrdup(NameStr(authForm->rolname));
5733 ReleaseSysCache(tp);
5734
5735 return rolename;
5736}
HeapTuple get_rolespec_tuple(const RoleSpec *role)
Definition acl.c:5678
char * pstrdup(const char *in)
Definition mcxt.c:1781

References fb(), Form_pg_authid, get_rolespec_tuple(), GETSTRUCT(), NameStr, pstrdup(), and ReleaseSysCache().

Referenced by AddRoleMems(), and DelRoleMems().

◆ get_rolespec_oid()

Oid get_rolespec_oid ( const RoleSpec role,
bool  missing_ok 
)

Definition at line 5639 of file acl.c.

5640{
5641 Oid oid;
5642
5643 switch (role->roletype)
5644 {
5645 case ROLESPEC_CSTRING:
5646 Assert(role->rolename);
5647 oid = get_role_oid(role->rolename, missing_ok);
5648 break;
5649
5652 oid = GetUserId();
5653 break;
5654
5656 oid = GetSessionUserId();
5657 break;
5658
5659 case ROLESPEC_PUBLIC:
5660 ereport(ERROR,
5662 errmsg("role \"%s\" does not exist", "public")));
5663 oid = InvalidOid; /* make compiler happy */
5664 break;
5665
5666 default:
5667 elog(ERROR, "unexpected role type %d", role->roletype);
5668 }
5669
5670 return oid;
5671}
Oid GetUserId(void)
Definition miscinit.c:470
Oid GetSessionUserId(void)
Definition miscinit.c:509
@ ROLESPEC_CURRENT_USER
Definition parsenodes.h:421
@ ROLESPEC_SESSION_USER
Definition parsenodes.h:422
@ ROLESPEC_CURRENT_ROLE
Definition parsenodes.h:420
@ ROLESPEC_PUBLIC
Definition parsenodes.h:423
#define InvalidOid

References Assert, elog, ereport, errcode(), errmsg, ERROR, fb(), get_role_oid(), GetSessionUserId(), GetUserId(), InvalidOid, RoleSpec::rolename, ROLESPEC_CSTRING, ROLESPEC_CURRENT_ROLE, ROLESPEC_CURRENT_USER, ROLESPEC_PUBLIC, ROLESPEC_SESSION_USER, and RoleSpec::roletype.

Referenced by AlterUserMapping(), ATExecCmd(), CreateSchemaCommand(), CreateTableSpace(), CreateUserMapping(), ExecAlterDefaultPrivilegesStmt(), ExecAlterOwnerStmt(), ExecuteGrantStmt(), GrantRole(), policy_role_list_to_array(), ReassignOwnedObjects(), RemoveUserMapping(), roleSpecsToIds(), and select_best_grantor().

◆ get_rolespec_tuple()

HeapTuple get_rolespec_tuple ( const RoleSpec role)

Definition at line 5678 of file acl.c.

5679{
5680 HeapTuple tuple;
5681
5682 switch (role->roletype)
5683 {
5684 case ROLESPEC_CSTRING:
5685 Assert(role->rolename);
5687 if (!HeapTupleIsValid(tuple))
5688 ereport(ERROR,
5690 errmsg("role \"%s\" does not exist", role->rolename)));
5691 break;
5692
5696 if (!HeapTupleIsValid(tuple))
5697 elog(ERROR, "cache lookup failed for role %u", GetUserId());
5698 break;
5699
5702 if (!HeapTupleIsValid(tuple))
5703 elog(ERROR, "cache lookup failed for role %u", GetSessionUserId());
5704 break;
5705
5706 case ROLESPEC_PUBLIC:
5707 ereport(ERROR,
5709 errmsg("role \"%s\" does not exist", "public")));
5710 tuple = NULL; /* make compiler happy */
5711 break;
5712
5713 default:
5714 elog(ERROR, "unexpected role type %d", role->roletype);
5715 }
5716
5717 return tuple;
5718}

References Assert, CStringGetDatum(), elog, ereport, errcode(), errmsg, ERROR, fb(), GetSessionUserId(), GetUserId(), HeapTupleIsValid, ObjectIdGetDatum(), RoleSpec::rolename, ROLESPEC_CSTRING, ROLESPEC_CURRENT_ROLE, ROLESPEC_CURRENT_USER, ROLESPEC_PUBLIC, ROLESPEC_SESSION_USER, RoleSpec::roletype, and SearchSysCache1().

Referenced by AlterRole(), AlterRoleSet(), CreateRole(), and get_rolespec_name().

◆ getid()

static const char * getid ( const char s,
char n,
Node escontext 
)
static

Definition at line 171 of file acl.c.

172{
173 int len = 0;
174 bool in_quotes = false;
175
176 Assert(s && n);
177
178 while (isspace((unsigned char) *s))
179 s++;
180 for (;
181 *s != '\0' &&
182 (in_quotes || *s == '"' || is_safe_acl_char(*s, true));
183 s++)
184 {
185 if (*s == '"')
186 {
187 if (!in_quotes)
188 {
189 in_quotes = true;
190 continue;
191 }
192 /* safe to look at next char (could be '\0' though) */
193 if (*(s + 1) != '"')
194 {
195 in_quotes = false;
196 continue;
197 }
198 /* it's an escaped double quote; skip the escaping char */
199 s++;
200 }
201
202 /* Add the character to the string */
203 if (len >= NAMEDATALEN - 1)
204 ereturn(escontext, NULL,
206 errmsg("identifier too long"),
207 errdetail("Identifier must be less than %d characters.",
208 NAMEDATALEN)));
209
210 n[len++] = *s;
211 }
212 n[len] = '\0';
213 while (isspace((unsigned char) *s))
214 s++;
215 return s;
216}
static bool is_safe_acl_char(unsigned char c, bool is_getid)
Definition acl.c:148
int errdetail(const char *fmt,...) pg_attribute_printf(1
const void size_t len

References Assert, ereturn, errcode(), errdetail(), errmsg, fb(), is_safe_acl_char(), len, and NAMEDATALEN.

Referenced by aclparse().

◆ has_any_column_privilege_id()

Datum has_any_column_privilege_id ( PG_FUNCTION_ARGS  )

Definition at line 2453 of file acl.c.

2454{
2455 Oid tableoid = PG_GETARG_OID(0);
2457 Oid roleid;
2458 AclMode mode;
2460 bool is_missing = false;
2461
2462 roleid = GetUserId();
2464
2465 /* First check at table level, then examine each column if needed */
2466 aclresult = pg_class_aclcheck_ext(tableoid, roleid, mode, &is_missing);
2467 if (aclresult != ACLCHECK_OK)
2468 {
2469 if (is_missing)
2471 aclresult = pg_attribute_aclcheck_all_ext(tableoid, roleid, mode,
2473 if (is_missing)
2475 }
2476
2478}
static AclMode convert_column_priv_string(text *priv_type_text)
Definition acl.c:2982
@ ACLMASK_ANY
Definition acl.h:178
AclResult pg_attribute_aclcheck_all_ext(Oid table_oid, Oid roleid, AclMode mode, AclMaskHow how, bool *is_missing)
Definition aclchk.c:3964
#define PG_GETARG_TEXT_PP(n)
Definition fmgr.h:310
Definition c.h:778

References ACLCHECK_OK, ACLMASK_ANY, convert_column_priv_string(), fb(), GetUserId(), mode, pg_attribute_aclcheck_all_ext(), pg_class_aclcheck_ext(), PG_GETARG_OID, PG_GETARG_TEXT_PP, PG_RETURN_BOOL, and PG_RETURN_NULL.

◆ has_any_column_privilege_id_id()

Datum has_any_column_privilege_id_id ( PG_FUNCTION_ARGS  )

Definition at line 2513 of file acl.c.

2514{
2515 Oid roleid = PG_GETARG_OID(0);
2516 Oid tableoid = PG_GETARG_OID(1);
2518 AclMode mode;
2520 bool is_missing = false;
2521
2523
2524 /* First check at table level, then examine each column if needed */
2525 aclresult = pg_class_aclcheck_ext(tableoid, roleid, mode, &is_missing);
2526 if (aclresult != ACLCHECK_OK)
2527 {
2528 if (is_missing)
2530 aclresult = pg_attribute_aclcheck_all_ext(tableoid, roleid, mode,
2532 if (is_missing)
2534 }
2535
2537}

References ACLCHECK_OK, ACLMASK_ANY, convert_column_priv_string(), fb(), mode, pg_attribute_aclcheck_all_ext(), pg_class_aclcheck_ext(), PG_GETARG_OID, PG_GETARG_TEXT_PP, PG_RETURN_BOOL, and PG_RETURN_NULL.

◆ has_any_column_privilege_id_name()

Datum has_any_column_privilege_id_name ( PG_FUNCTION_ARGS  )

Definition at line 2486 of file acl.c.

2487{
2488 Oid roleid = PG_GETARG_OID(0);
2489 text *tablename = PG_GETARG_TEXT_PP(1);
2491 Oid tableoid;
2492 AclMode mode;
2494
2495 tableoid = convert_table_name(tablename);
2497
2498 /* First check at table level, then examine each column if needed */
2499 aclresult = pg_class_aclcheck(tableoid, roleid, mode);
2500 if (aclresult != ACLCHECK_OK)
2501 aclresult = pg_attribute_aclcheck_all(tableoid, roleid, mode,
2502 ACLMASK_ANY);
2503
2505}
static Oid convert_table_name(text *tablename)
Definition acl.c:2077
AclResult pg_attribute_aclcheck_all(Oid table_oid, Oid roleid, AclMode mode, AclMaskHow how)
Definition aclchk.c:3953
AclResult pg_class_aclcheck(Oid table_oid, Oid roleid, AclMode mode)
Definition aclchk.c:4082

References ACLCHECK_OK, ACLMASK_ANY, convert_column_priv_string(), convert_table_name(), fb(), mode, pg_attribute_aclcheck_all(), pg_class_aclcheck(), PG_GETARG_OID, PG_GETARG_TEXT_PP, and PG_RETURN_BOOL.

◆ has_any_column_privilege_name()

Datum has_any_column_privilege_name ( PG_FUNCTION_ARGS  )

Definition at line 2390 of file acl.c.

2391{
2392 text *tablename = PG_GETARG_TEXT_PP(0);
2394 Oid roleid;
2395 Oid tableoid;
2396 AclMode mode;
2398
2399 roleid = GetUserId();
2400 tableoid = convert_table_name(tablename);
2402
2403 /* First check at table level, then examine each column if needed */
2404 aclresult = pg_class_aclcheck(tableoid, roleid, mode);
2405 if (aclresult != ACLCHECK_OK)
2406 aclresult = pg_attribute_aclcheck_all(tableoid, roleid, mode,
2407 ACLMASK_ANY);
2408
2410}

References ACLCHECK_OK, ACLMASK_ANY, convert_column_priv_string(), convert_table_name(), fb(), GetUserId(), mode, pg_attribute_aclcheck_all(), pg_class_aclcheck(), PG_GETARG_TEXT_PP, and PG_RETURN_BOOL.

◆ has_any_column_privilege_name_id()

Datum has_any_column_privilege_name_id ( PG_FUNCTION_ARGS  )

Definition at line 2418 of file acl.c.

2419{
2421 Oid tableoid = PG_GETARG_OID(1);
2423 Oid roleid;
2424 AclMode mode;
2426 bool is_missing = false;
2427
2430
2431 /* First check at table level, then examine each column if needed */
2432 aclresult = pg_class_aclcheck_ext(tableoid, roleid, mode, &is_missing);
2433 if (aclresult != ACLCHECK_OK)
2434 {
2435 if (is_missing)
2437 aclresult = pg_attribute_aclcheck_all_ext(tableoid, roleid, mode,
2439 if (is_missing)
2441 }
2442
2444}
Oid get_role_oid_or_public(const char *rolname)
Definition acl.c:5623
#define PG_GETARG_NAME(n)
Definition fmgr.h:279
static char * username
Definition initdb.c:153
Definition c.h:832

References ACLCHECK_OK, ACLMASK_ANY, convert_column_priv_string(), fb(), get_role_oid_or_public(), mode, NameStr, pg_attribute_aclcheck_all_ext(), pg_class_aclcheck_ext(), PG_GETARG_NAME, PG_GETARG_OID, PG_GETARG_TEXT_PP, PG_RETURN_BOOL, PG_RETURN_NULL, and username.

◆ has_any_column_privilege_name_name()

Datum has_any_column_privilege_name_name ( PG_FUNCTION_ARGS  )

Definition at line 2360 of file acl.c.

2361{
2362 Name rolename = PG_GETARG_NAME(0);
2363 text *tablename = PG_GETARG_TEXT_PP(1);
2365 Oid roleid;
2366 Oid tableoid;
2367 AclMode mode;
2369
2370 roleid = get_role_oid_or_public(NameStr(*rolename));
2371 tableoid = convert_table_name(tablename);
2373
2374 /* First check at table level, then examine each column if needed */
2375 aclresult = pg_class_aclcheck(tableoid, roleid, mode);
2376 if (aclresult != ACLCHECK_OK)
2377 aclresult = pg_attribute_aclcheck_all(tableoid, roleid, mode,
2378 ACLMASK_ANY);
2379
2381}

References ACLCHECK_OK, ACLMASK_ANY, convert_column_priv_string(), convert_table_name(), fb(), get_role_oid_or_public(), mode, NameStr, pg_attribute_aclcheck_all(), pg_class_aclcheck(), PG_GETARG_NAME, PG_GETARG_TEXT_PP, and PG_RETURN_BOOL.

◆ has_column_privilege_id_attnum()

Datum has_column_privilege_id_attnum ( PG_FUNCTION_ARGS  )

Definition at line 2896 of file acl.c.

2897{
2898 Oid tableoid = PG_GETARG_OID(0);
2901 Oid roleid;
2902 AclMode mode;
2903 int privresult;
2904
2905 roleid = GetUserId();
2907
2908 privresult = column_privilege_check(tableoid, colattnum, roleid, mode);
2909 if (privresult < 0)
2912}
static int column_privilege_check(Oid tableoid, AttrNumber attnum, Oid roleid, AclMode mode)
Definition acl.c:2564
#define PG_GETARG_INT16(n)
Definition fmgr.h:271

References column_privilege_check(), convert_column_priv_string(), fb(), GetUserId(), mode, PG_GETARG_INT16, PG_GETARG_OID, PG_GETARG_TEXT_PP, PG_RETURN_BOOL, and PG_RETURN_NULL.

◆ has_column_privilege_id_id_attnum()

Datum has_column_privilege_id_id_attnum ( PG_FUNCTION_ARGS  )

◆ has_column_privilege_id_id_name()

Datum has_column_privilege_id_id_name ( PG_FUNCTION_ARGS  )

Definition at line 2764 of file acl.c.

2765{
2766 Oid roleid = PG_GETARG_OID(0);
2767 Oid tableoid = PG_GETARG_OID(1);
2771 AclMode mode;
2772 int privresult;
2773
2776
2777 privresult = column_privilege_check(tableoid, colattnum, roleid, mode);
2778 if (privresult < 0)
2781}
static AttrNumber convert_column_name(Oid tableoid, text *column)
Definition acl.c:2924

References column_privilege_check(), convert_column_name(), convert_column_priv_string(), fb(), mode, PG_GETARG_OID, PG_GETARG_TEXT_PP, PG_RETURN_BOOL, and PG_RETURN_NULL.

◆ has_column_privilege_id_name()

Datum has_column_privilege_id_name ( PG_FUNCTION_ARGS  )

◆ has_column_privilege_id_name_attnum()

Datum has_column_privilege_id_name_attnum ( PG_FUNCTION_ARGS  )

Definition at line 2739 of file acl.c.

2740{
2741 Oid roleid = PG_GETARG_OID(0);
2742 text *tablename = PG_GETARG_TEXT_PP(1);
2745 Oid tableoid;
2746 AclMode mode;
2747 int privresult;
2748
2749 tableoid = convert_table_name(tablename);
2751
2752 privresult = column_privilege_check(tableoid, colattnum, roleid, mode);
2753 if (privresult < 0)
2756}

References column_privilege_check(), convert_column_priv_string(), convert_table_name(), fb(), mode, PG_GETARG_INT16, PG_GETARG_OID, PG_GETARG_TEXT_PP, PG_RETURN_BOOL, and PG_RETURN_NULL.

◆ has_column_privilege_id_name_name()

Datum has_column_privilege_id_name_name ( PG_FUNCTION_ARGS  )

Definition at line 2712 of file acl.c.

2713{
2714 Oid roleid = PG_GETARG_OID(0);
2715 text *tablename = PG_GETARG_TEXT_PP(1);
2718 Oid tableoid;
2720 AclMode mode;
2721 int privresult;
2722
2723 tableoid = convert_table_name(tablename);
2726
2727 privresult = column_privilege_check(tableoid, colattnum, roleid, mode);
2728 if (privresult < 0)
2731}

References column_privilege_check(), convert_column_name(), convert_column_priv_string(), convert_table_name(), fb(), mode, PG_GETARG_OID, PG_GETARG_TEXT_PP, PG_RETURN_BOOL, and PG_RETURN_NULL.

◆ has_column_privilege_name_attnum()

Datum has_column_privilege_name_attnum ( PG_FUNCTION_ARGS  )

Definition at line 2842 of file acl.c.

2843{
2844 text *tablename = PG_GETARG_TEXT_PP(0);
2847 Oid roleid;
2848 Oid tableoid;
2849 AclMode mode;
2850 int privresult;
2851
2852 roleid = GetUserId();
2853 tableoid = convert_table_name(tablename);
2855
2856 privresult = column_privilege_check(tableoid, colattnum, roleid, mode);
2857 if (privresult < 0)
2860}

References column_privilege_check(), convert_column_priv_string(), convert_table_name(), fb(), GetUserId(), mode, PG_GETARG_INT16, PG_GETARG_TEXT_PP, PG_RETURN_BOOL, and PG_RETURN_NULL.

◆ has_column_privilege_name_id_attnum()

◆ has_column_privilege_name_id_name()

◆ has_column_privilege_name_name()

Datum has_column_privilege_name_name ( PG_FUNCTION_ARGS  )

Definition at line 2813 of file acl.c.

2814{
2815 text *tablename = PG_GETARG_TEXT_PP(0);
2818 Oid roleid;
2819 Oid tableoid;
2821 AclMode mode;
2822 int privresult;
2823
2824 roleid = GetUserId();
2825 tableoid = convert_table_name(tablename);
2828
2829 privresult = column_privilege_check(tableoid, colattnum, roleid, mode);
2830 if (privresult < 0)
2833}

References column_privilege_check(), convert_column_name(), convert_column_priv_string(), convert_table_name(), fb(), GetUserId(), mode, PG_GETARG_TEXT_PP, PG_RETURN_BOOL, and PG_RETURN_NULL.

◆ has_column_privilege_name_name_attnum()

Datum has_column_privilege_name_name_attnum ( PG_FUNCTION_ARGS  )

Definition at line 2633 of file acl.c.

2634{
2635 Name rolename = PG_GETARG_NAME(0);
2636 text *tablename = PG_GETARG_TEXT_PP(1);
2639 Oid roleid;
2640 Oid tableoid;
2641 AclMode mode;
2642 int privresult;
2643
2644 roleid = get_role_oid_or_public(NameStr(*rolename));
2645 tableoid = convert_table_name(tablename);
2647
2648 privresult = column_privilege_check(tableoid, colattnum, roleid, mode);
2649 if (privresult < 0)
2652}

References column_privilege_check(), convert_column_priv_string(), convert_table_name(), fb(), get_role_oid_or_public(), mode, NameStr, PG_GETARG_INT16, PG_GETARG_NAME, PG_GETARG_TEXT_PP, PG_RETURN_BOOL, and PG_RETURN_NULL.

◆ has_column_privilege_name_name_name()

Datum has_column_privilege_name_name_name ( PG_FUNCTION_ARGS  )

Definition at line 2604 of file acl.c.

2605{
2606 Name rolename = PG_GETARG_NAME(0);
2607 text *tablename = PG_GETARG_TEXT_PP(1);
2610 Oid roleid;
2611 Oid tableoid;
2613 AclMode mode;
2614 int privresult;
2615
2616 roleid = get_role_oid_or_public(NameStr(*rolename));
2617 tableoid = convert_table_name(tablename);
2620
2621 privresult = column_privilege_check(tableoid, colattnum, roleid, mode);
2622 if (privresult < 0)
2625}

References column_privilege_check(), convert_column_name(), convert_column_priv_string(), convert_table_name(), fb(), get_role_oid_or_public(), mode, NameStr, PG_GETARG_NAME, PG_GETARG_TEXT_PP, PG_RETURN_BOOL, and PG_RETURN_NULL.

◆ has_database_privilege_id()

Datum has_database_privilege_id ( PG_FUNCTION_ARGS  )

Definition at line 3096 of file acl.c.

3097{
3100 Oid roleid;
3101 AclMode mode;
3103 bool is_missing = false;
3104
3105 roleid = GetUserId();
3107
3109 roleid, mode,
3110 &is_missing);
3111
3112 if (is_missing)
3114
3116}
static AclMode convert_database_priv_string(text *priv_type_text)
Definition acl.c:3188
AclResult object_aclcheck_ext(Oid classid, Oid objectid, Oid roleid, AclMode mode, bool *is_missing)
Definition aclchk.c:3889

References ACLCHECK_OK, convert_database_priv_string(), fb(), GetUserId(), mode, object_aclcheck_ext(), PG_GETARG_OID, PG_GETARG_TEXT_PP, PG_RETURN_BOOL, and PG_RETURN_NULL.

◆ has_database_privilege_id_id()

Datum has_database_privilege_id_id ( PG_FUNCTION_ARGS  )

◆ has_database_privilege_id_name()

Datum has_database_privilege_id_name ( PG_FUNCTION_ARGS  )

Definition at line 3124 of file acl.c.

3125{
3126 Oid roleid = PG_GETARG_OID(0);
3130 AclMode mode;
3132
3135
3137
3139}
static Oid convert_database_name(text *databasename)
Definition acl.c:3176
AclResult object_aclcheck(Oid classid, Oid objectid, Oid roleid, AclMode mode)
Definition aclchk.c:3879

References ACLCHECK_OK, convert_database_name(), convert_database_priv_string(), fb(), mode, object_aclcheck(), PG_GETARG_OID, PG_GETARG_TEXT_PP, and PG_RETURN_BOOL.

◆ has_database_privilege_name()

◆ has_database_privilege_name_id()

◆ has_database_privilege_name_name()

◆ has_foreign_data_wrapper_privilege_id()

Datum has_foreign_data_wrapper_privilege_id ( PG_FUNCTION_ARGS  )

Definition at line 3302 of file acl.c.

3303{
3304 Oid fdwid = PG_GETARG_OID(0);
3306 Oid roleid;
3307 AclMode mode;
3309 bool is_missing = false;
3310
3311 roleid = GetUserId();
3313
3315 roleid, mode,
3316 &is_missing);
3317
3318 if (is_missing)
3320
3322}
static AclMode convert_foreign_data_wrapper_priv_string(text *priv_type_text)
Definition acl.c:3394

References ACLCHECK_OK, convert_foreign_data_wrapper_priv_string(), fb(), GetUserId(), mode, object_aclcheck_ext(), PG_GETARG_OID, PG_GETARG_TEXT_PP, PG_RETURN_BOOL, and PG_RETURN_NULL.

◆ has_foreign_data_wrapper_privilege_id_id()

Datum has_foreign_data_wrapper_privilege_id_id ( PG_FUNCTION_ARGS  )

◆ has_foreign_data_wrapper_privilege_id_name()

Datum has_foreign_data_wrapper_privilege_id_name ( PG_FUNCTION_ARGS  )

◆ has_foreign_data_wrapper_privilege_name()

Datum has_foreign_data_wrapper_privilege_name ( PG_FUNCTION_ARGS  )

◆ has_foreign_data_wrapper_privilege_name_id()

◆ has_foreign_data_wrapper_privilege_name_name()

◆ has_function_privilege_id()

Datum has_function_privilege_id ( PG_FUNCTION_ARGS  )

Definition at line 3502 of file acl.c.

3503{
3506 Oid roleid;
3507 AclMode mode;
3509 bool is_missing = false;
3510
3511 roleid = GetUserId();
3513
3515 roleid, mode,
3516 &is_missing);
3517
3518 if (is_missing)
3520
3522}
static AclMode convert_function_priv_string(text *priv_type_text)
Definition acl.c:3603

References ACLCHECK_OK, convert_function_priv_string(), fb(), GetUserId(), mode, object_aclcheck_ext(), PG_GETARG_OID, PG_GETARG_TEXT_PP, PG_RETURN_BOOL, and PG_RETURN_NULL.

◆ has_function_privilege_id_id()

◆ has_function_privilege_id_name()

◆ has_function_privilege_name()

◆ has_function_privilege_name_id()

◆ has_function_privilege_name_name()

◆ has_language_privilege_id()

Datum has_language_privilege_id ( PG_FUNCTION_ARGS  )

Definition at line 3711 of file acl.c.

3712{
3715 Oid roleid;
3716 AclMode mode;
3718 bool is_missing = false;
3719
3720 roleid = GetUserId();
3722
3724 roleid, mode,
3725 &is_missing);
3726
3727 if (is_missing)
3729
3731}
static AclMode convert_language_priv_string(text *priv_type_text)
Definition acl.c:3803

References ACLCHECK_OK, convert_language_priv_string(), fb(), GetUserId(), mode, object_aclcheck_ext(), PG_GETARG_OID, PG_GETARG_TEXT_PP, PG_RETURN_BOOL, and PG_RETURN_NULL.

◆ has_language_privilege_id_id()

Datum has_language_privilege_id_id ( PG_FUNCTION_ARGS  )

◆ has_language_privilege_id_name()

◆ has_language_privilege_name()

◆ has_language_privilege_name_id()

◆ has_language_privilege_name_name()

◆ has_largeobject_privilege_id()

Datum has_largeobject_privilege_id ( PG_FUNCTION_ARGS  )

Definition at line 4791 of file acl.c.

4792{
4794 Oid roleid = GetUserId();
4796 AclMode mode;
4797 bool is_missing = false;
4798 bool result;
4799
4801 result = has_lo_priv_byid(roleid, lobjId, mode, &is_missing);
4802
4803 if (is_missing)
4805
4806 PG_RETURN_BOOL(result);
4807}
static AclMode convert_largeobject_priv_string(text *priv_type_text)
Definition acl.c:4838
static bool has_lo_priv_byid(Oid roleid, Oid lobjId, AclMode priv, bool *is_missing)
Definition acl.c:4732

References convert_largeobject_priv_string(), fb(), GetUserId(), has_lo_priv_byid(), mode, PG_GETARG_OID, PG_GETARG_TEXT_PP, PG_RETURN_BOOL, and PG_RETURN_NULL.

◆ has_largeobject_privilege_id_id()

Datum has_largeobject_privilege_id_id ( PG_FUNCTION_ARGS  )

Definition at line 4815 of file acl.c.

4816{
4817 Oid roleid = PG_GETARG_OID(0);
4820 AclMode mode;
4821 bool is_missing = false;
4822 bool result;
4823
4825 result = has_lo_priv_byid(roleid, lobjId, mode, &is_missing);
4826
4827 if (is_missing)
4829
4830 PG_RETURN_BOOL(result);
4831}

References convert_largeobject_priv_string(), fb(), has_lo_priv_byid(), mode, PG_GETARG_OID, PG_GETARG_TEXT_PP, PG_RETURN_BOOL, and PG_RETURN_NULL.

◆ has_largeobject_privilege_name_id()

Datum has_largeobject_privilege_name_id ( PG_FUNCTION_ARGS  )

◆ has_lo_priv_byid()

static bool has_lo_priv_byid ( Oid  roleid,
Oid  lobjId,
AclMode  priv,
bool is_missing 
)
static

Definition at line 4732 of file acl.c.

4733{
4734 Snapshot snapshot = NULL;
4736
4737 if (priv & ACL_UPDATE)
4738 snapshot = NULL;
4739 else
4740 snapshot = GetActiveSnapshot();
4741
4742 if (!LargeObjectExistsWithSnapshot(lobjId, snapshot))
4743 {
4745 *is_missing = true;
4746 return false;
4747 }
4748
4750 return true;
4751
4753 roleid,
4754 priv,
4755 snapshot);
4756 return aclresult == ACLCHECK_OK;
4757}
AclResult pg_largeobject_aclcheck_snapshot(Oid lobj_oid, Oid roleid, AclMode mode, Snapshot snapshot)
Definition aclchk.c:4119
bool lo_compat_privileges
Definition inv_api.c:56
bool LargeObjectExistsWithSnapshot(Oid loid, Snapshot snapshot)
Snapshot GetActiveSnapshot(void)
Definition snapmgr.c:800

References ACL_UPDATE, ACLCHECK_OK, Assert, fb(), GetActiveSnapshot(), LargeObjectExistsWithSnapshot(), lo_compat_privileges, and pg_largeobject_aclcheck_snapshot().

Referenced by has_largeobject_privilege_id(), has_largeobject_privilege_id_id(), and has_largeobject_privilege_name_id().

◆ has_param_priv_byname()

static bool has_param_priv_byname ( Oid  roleid,
const text parameter,
AclMode  priv 
)
static

Definition at line 4641 of file acl.c.

4642{
4644
4645 return pg_parameter_aclcheck(paramstr, roleid, priv) == ACLCHECK_OK;
4646}
AclResult pg_parameter_aclcheck(const char *name, Oid roleid, AclMode mode)
Definition aclchk.c:4107

References ACLCHECK_OK, fb(), pg_parameter_aclcheck(), and text_to_cstring().

Referenced by has_parameter_privilege_id_name(), has_parameter_privilege_name(), and has_parameter_privilege_name_name().

◆ has_parameter_privilege_id_name()

Datum has_parameter_privilege_id_name ( PG_FUNCTION_ARGS  )

Definition at line 4684 of file acl.c.

4685{
4686 Oid roleid = PG_GETARG_OID(0);
4689
4691}
static bool has_param_priv_byname(Oid roleid, const text *parameter, AclMode priv)
Definition acl.c:4641
static AclMode convert_parameter_priv_string(text *priv_text)
Definition acl.c:4702

References convert_parameter_priv_string(), fb(), has_param_priv_byname(), PG_GETARG_OID, PG_GETARG_TEXT_PP, and PG_RETURN_BOOL.

◆ has_parameter_privilege_name()

◆ has_parameter_privilege_name_name()

◆ has_privs_of_role()

bool has_privs_of_role ( Oid  member,
Oid  role 
)

Definition at line 5314 of file acl.c.

5315{
5316 /* Fast path for simple case */
5317 if (member == role)
5318 return true;
5319
5320 /* Superusers have every privilege, so are part of every role */
5321 if (superuser_arg(member))
5322 return true;
5323
5324 /*
5325 * Find all the roles that member has the privileges of, including
5326 * multi-level recursion, then see if target role is any one of them.
5327 */
5329 InvalidOid, NULL),
5330 role);
5331}
static List * roles_is_member_of(Oid roleid, enum RoleRecurseType type, Oid admin_of, Oid *admin_role)
Definition acl.c:5182
bool list_member_oid(const List *list, Oid datum)
Definition list.c:722
bool superuser_arg(Oid roleid)
Definition superuser.c:57

References fb(), InvalidOid, list_member_oid(), ROLERECURSE_PRIVS, roles_is_member_of(), and superuser_arg().

Referenced by aclmask(), AlterObjectNamespace_internal(), AlterObjectOwner_internal(), AlterObjectRename_internal(), bbsink_server_new(), calculate_database_size(), calculate_tablespace_size(), check_role_for_policy(), check_role_grantor(), ConfigOptionIsVisible(), convert_and_check_filename(), CreateSubscription(), DoCopy(), DropOwnedObjects(), ExecAlterDefaultPrivilegesStmt(), ExecCheckpoint(), file_fdw_validator(), GetConfigOptionValues(), InitPostgres(), object_ownercheck(), pg_class_aclmask_ext(), pg_get_multixact_stats(), pg_largeobject_aclmask_snapshot(), pg_namespace_aclmask_ext(), pg_role_aclcheck(), pg_signal_backend(), pg_stat_get_recovery(), pg_stat_get_wal_receiver(), pg_stat_get_wal_senders(), pg_stat_statements_internal(), pgrowlocks(), ReassignOwnedObjects(), ReindexMultipleTables(), select_best_grantor(), shell_check_detail(), and TerminateOtherDBBackends().

◆ has_schema_privilege_id()

Datum has_schema_privilege_id ( PG_FUNCTION_ARGS  )

Definition at line 3911 of file acl.c.

3912{
3915 Oid roleid;
3916 AclMode mode;
3918 bool is_missing = false;
3919
3920 roleid = GetUserId();
3922
3924 roleid, mode,
3925 &is_missing);
3926
3927 if (is_missing)
3929
3931}
static AclMode convert_schema_priv_string(text *priv_type_text)
Definition acl.c:4003

References ACLCHECK_OK, convert_schema_priv_string(), fb(), GetUserId(), mode, object_aclcheck_ext(), PG_GETARG_OID, PG_GETARG_TEXT_PP, PG_RETURN_BOOL, and PG_RETURN_NULL.

◆ has_schema_privilege_id_id()

Datum has_schema_privilege_id_id ( PG_FUNCTION_ARGS  )

◆ has_schema_privilege_id_name()

Datum has_schema_privilege_id_name ( PG_FUNCTION_ARGS  )

Definition at line 3939 of file acl.c.

3940{
3941 Oid roleid = PG_GETARG_OID(0);
3942 text *schemaname = PG_GETARG_TEXT_PP(1);
3944 Oid schemaoid;
3945 AclMode mode;
3947
3948 schemaoid = convert_schema_name(schemaname);
3950
3952
3954}
static Oid convert_schema_name(text *schemaname)
Definition acl.c:3991

References ACLCHECK_OK, convert_schema_name(), convert_schema_priv_string(), fb(), mode, object_aclcheck(), PG_GETARG_OID, PG_GETARG_TEXT_PP, and PG_RETURN_BOOL.

◆ has_schema_privilege_name()

Datum has_schema_privilege_name ( PG_FUNCTION_ARGS  )

◆ has_schema_privilege_name_id()

◆ has_schema_privilege_name_name()

◆ has_sequence_privilege_id()

Datum has_sequence_privilege_id ( PG_FUNCTION_ARGS  )

Definition at line 2231 of file acl.c.

2232{
2235 Oid roleid;
2236 AclMode mode;
2238 char relkind;
2239 bool is_missing = false;
2240
2241 roleid = GetUserId();
2243 relkind = get_rel_relkind(sequenceoid);
2244 if (relkind == '\0')
2246 else if (relkind != RELKIND_SEQUENCE)
2247 ereport(ERROR,
2249 errmsg("\"%s\" is not a sequence",
2251
2253
2254 if (is_missing)
2256
2258}
static AclMode convert_sequence_priv_string(text *priv_type_text)
Definition acl.c:2327
char get_rel_relkind(Oid relid)
Definition lsyscache.c:2223

References ACLCHECK_OK, convert_sequence_priv_string(), ereport, errcode(), errmsg, ERROR, fb(), get_rel_name(), get_rel_relkind(), GetUserId(), mode, pg_class_aclcheck_ext(), PG_GETARG_OID, PG_GETARG_TEXT_PP, PG_RETURN_BOOL, and PG_RETURN_NULL.

◆ has_sequence_privilege_id_id()

Datum has_sequence_privilege_id_id ( PG_FUNCTION_ARGS  )

Definition at line 2294 of file acl.c.

2295{
2296 Oid roleid = PG_GETARG_OID(0);
2299 AclMode mode;
2301 char relkind;
2302 bool is_missing = false;
2303
2305 relkind = get_rel_relkind(sequenceoid);
2306 if (relkind == '\0')
2308 else if (relkind != RELKIND_SEQUENCE)
2309 ereport(ERROR,
2311 errmsg("\"%s\" is not a sequence",
2313
2315
2316 if (is_missing)
2318
2320}

References ACLCHECK_OK, convert_sequence_priv_string(), ereport, errcode(), errmsg, ERROR, fb(), get_rel_name(), get_rel_relkind(), mode, pg_class_aclcheck_ext(), PG_GETARG_OID, PG_GETARG_TEXT_PP, PG_RETURN_BOOL, and PG_RETURN_NULL.

◆ has_sequence_privilege_id_name()

◆ has_sequence_privilege_name()

◆ has_sequence_privilege_name_id()

Datum has_sequence_privilege_name_id ( PG_FUNCTION_ARGS  )

◆ has_sequence_privilege_name_name()

◆ has_server_privilege_id()

Datum has_server_privilege_id ( PG_FUNCTION_ARGS  )

Definition at line 4113 of file acl.c.

4114{
4115 Oid serverid = PG_GETARG_OID(0);
4117 Oid roleid;
4118 AclMode mode;
4120 bool is_missing = false;
4121
4122 roleid = GetUserId();
4124
4126 roleid, mode,
4127 &is_missing);
4128
4129 if (is_missing)
4131
4133}
static AclMode convert_server_priv_string(text *priv_type_text)
Definition acl.c:4205

References ACLCHECK_OK, convert_server_priv_string(), fb(), GetUserId(), mode, object_aclcheck_ext(), PG_GETARG_OID, PG_GETARG_TEXT_PP, PG_RETURN_BOOL, and PG_RETURN_NULL.

◆ has_server_privilege_id_id()

Datum has_server_privilege_id_id ( PG_FUNCTION_ARGS  )

Definition at line 4164 of file acl.c.

4165{
4166 Oid roleid = PG_GETARG_OID(0);
4167 Oid serverid = PG_GETARG_OID(1);
4169 AclMode mode;
4171 bool is_missing = false;
4172
4174
4176 roleid, mode,
4177 &is_missing);
4178
4179 if (is_missing)
4181
4183}

References ACLCHECK_OK, convert_server_priv_string(), fb(), mode, object_aclcheck_ext(), PG_GETARG_OID, PG_GETARG_TEXT_PP, PG_RETURN_BOOL, and PG_RETURN_NULL.

◆ has_server_privilege_id_name()

Datum has_server_privilege_id_name ( PG_FUNCTION_ARGS  )

Definition at line 4141 of file acl.c.

4142{
4143 Oid roleid = PG_GETARG_OID(0);
4144 text *servername = PG_GETARG_TEXT_PP(1);
4146 Oid serverid;
4147 AclMode mode;
4149
4150 serverid = convert_server_name(servername);
4152
4154
4156}
static Oid convert_server_name(text *servername)
Definition acl.c:4193

References ACLCHECK_OK, convert_server_name(), convert_server_priv_string(), fb(), mode, object_aclcheck(), PG_GETARG_OID, PG_GETARG_TEXT_PP, and PG_RETURN_BOOL.

◆ has_server_privilege_name()

Datum has_server_privilege_name ( PG_FUNCTION_ARGS  )

Definition at line 4059 of file acl.c.

4060{
4061 text *servername = PG_GETARG_TEXT_PP(0);
4063 Oid roleid;
4064 Oid serverid;
4065 AclMode mode;
4067
4068 roleid = GetUserId();
4069 serverid = convert_server_name(servername);
4071
4073
4075}

References ACLCHECK_OK, convert_server_name(), convert_server_priv_string(), fb(), GetUserId(), mode, object_aclcheck(), PG_GETARG_TEXT_PP, and PG_RETURN_BOOL.

◆ has_server_privilege_name_id()

◆ has_server_privilege_name_name()

Datum has_server_privilege_name_name ( PG_FUNCTION_ARGS  )

◆ has_table_privilege_id()

Datum has_table_privilege_id ( PG_FUNCTION_ARGS  )

Definition at line 2001 of file acl.c.

2002{
2003 Oid tableoid = PG_GETARG_OID(0);
2005 Oid roleid;
2006 AclMode mode;
2008 bool is_missing = false;
2009
2010 roleid = GetUserId();
2012
2013 aclresult = pg_class_aclcheck_ext(tableoid, roleid, mode, &is_missing);
2014
2015 if (is_missing)
2017
2019}
static AclMode convert_table_priv_string(text *priv_type_text)
Definition acl.c:2092

References ACLCHECK_OK, convert_table_priv_string(), fb(), GetUserId(), mode, pg_class_aclcheck_ext(), PG_GETARG_OID, PG_GETARG_TEXT_PP, PG_RETURN_BOOL, and PG_RETURN_NULL.

◆ has_table_privilege_id_id()

Datum has_table_privilege_id_id ( PG_FUNCTION_ARGS  )

Definition at line 2050 of file acl.c.

2051{
2052 Oid roleid = PG_GETARG_OID(0);
2053 Oid tableoid = PG_GETARG_OID(1);
2055 AclMode mode;
2057 bool is_missing = false;
2058
2060
2061 aclresult = pg_class_aclcheck_ext(tableoid, roleid, mode, &is_missing);
2062
2063 if (is_missing)
2065
2067}

References ACLCHECK_OK, convert_table_priv_string(), fb(), mode, pg_class_aclcheck_ext(), PG_GETARG_OID, PG_GETARG_TEXT_PP, PG_RETURN_BOOL, and PG_RETURN_NULL.

◆ has_table_privilege_id_name()

Datum has_table_privilege_id_name ( PG_FUNCTION_ARGS  )

Definition at line 2027 of file acl.c.

2028{
2029 Oid roleid = PG_GETARG_OID(0);
2030 text *tablename = PG_GETARG_TEXT_PP(1);
2032 Oid tableoid;
2033 AclMode mode;
2035
2036 tableoid = convert_table_name(tablename);
2038
2039 aclresult = pg_class_aclcheck(tableoid, roleid, mode);
2040
2042}

References ACLCHECK_OK, convert_table_name(), convert_table_priv_string(), fb(), mode, pg_class_aclcheck(), PG_GETARG_OID, PG_GETARG_TEXT_PP, and PG_RETURN_BOOL.

◆ has_table_privilege_name()

Datum has_table_privilege_name ( PG_FUNCTION_ARGS  )

Definition at line 1949 of file acl.c.

1950{
1951 text *tablename = PG_GETARG_TEXT_PP(0);
1953 Oid roleid;
1954 Oid tableoid;
1955 AclMode mode;
1957
1958 roleid = GetUserId();
1959 tableoid = convert_table_name(tablename);
1961
1962 aclresult = pg_class_aclcheck(tableoid, roleid, mode);
1963
1965}

References ACLCHECK_OK, convert_table_name(), convert_table_priv_string(), fb(), GetUserId(), mode, pg_class_aclcheck(), PG_GETARG_TEXT_PP, and PG_RETURN_BOOL.

◆ has_table_privilege_name_id()

◆ has_table_privilege_name_name()

Datum has_table_privilege_name_name ( PG_FUNCTION_ARGS  )

Definition at line 1923 of file acl.c.

1924{
1925 Name rolename = PG_GETARG_NAME(0);
1926 text *tablename = PG_GETARG_TEXT_PP(1);
1928 Oid roleid;
1929 Oid tableoid;
1930 AclMode mode;
1932
1933 roleid = get_role_oid_or_public(NameStr(*rolename));
1934 tableoid = convert_table_name(tablename);
1936
1937 aclresult = pg_class_aclcheck(tableoid, roleid, mode);
1938
1940}

References ACLCHECK_OK, convert_table_name(), convert_table_priv_string(), fb(), get_role_oid_or_public(), mode, NameStr, pg_class_aclcheck(), PG_GETARG_NAME, PG_GETARG_TEXT_PP, and PG_RETURN_BOOL.

◆ has_tablespace_privilege_id()

Datum has_tablespace_privilege_id ( PG_FUNCTION_ARGS  )

Definition at line 4313 of file acl.c.

4314{
4317 Oid roleid;
4318 AclMode mode;
4320 bool is_missing = false;
4321
4322 roleid = GetUserId();
4324
4326 roleid, mode,
4327 &is_missing);
4328
4329 if (is_missing)
4331
4333}
static AclMode convert_tablespace_priv_string(text *priv_type_text)
Definition acl.c:4405

References ACLCHECK_OK, convert_tablespace_priv_string(), fb(), GetUserId(), mode, object_aclcheck_ext(), PG_GETARG_OID, PG_GETARG_TEXT_PP, PG_RETURN_BOOL, and PG_RETURN_NULL.

◆ has_tablespace_privilege_id_id()

◆ has_tablespace_privilege_id_name()

Datum has_tablespace_privilege_id_name ( PG_FUNCTION_ARGS  )

Definition at line 4341 of file acl.c.

4342{
4343 Oid roleid = PG_GETARG_OID(0);
4344 text *tablespacename = PG_GETARG_TEXT_PP(1);
4347 AclMode mode;
4349
4350 tablespaceoid = convert_tablespace_name(tablespacename);
4352
4354
4356}
static Oid convert_tablespace_name(text *tablespacename)
Definition acl.c:4393

References ACLCHECK_OK, convert_tablespace_name(), convert_tablespace_priv_string(), fb(), mode, object_aclcheck(), PG_GETARG_OID, PG_GETARG_TEXT_PP, and PG_RETURN_BOOL.

◆ has_tablespace_privilege_name()

◆ has_tablespace_privilege_name_id()

◆ has_tablespace_privilege_name_name()

◆ has_type_privilege_id()

Datum has_type_privilege_id ( PG_FUNCTION_ARGS  )

Definition at line 4512 of file acl.c.

4513{
4514 Oid typeoid = PG_GETARG_OID(0);
4516 Oid roleid;
4517 AclMode mode;
4519 bool is_missing = false;
4520
4521 roleid = GetUserId();
4523
4525 roleid, mode,
4526 &is_missing);
4527
4528 if (is_missing)
4530
4532}
static AclMode convert_type_priv_string(text *priv_type_text)
Definition acl.c:4613

References ACLCHECK_OK, convert_type_priv_string(), fb(), GetUserId(), mode, object_aclcheck_ext(), PG_GETARG_OID, PG_GETARG_TEXT_PP, PG_RETURN_BOOL, and PG_RETURN_NULL.

◆ has_type_privilege_id_id()

Datum has_type_privilege_id_id ( PG_FUNCTION_ARGS  )

Definition at line 4563 of file acl.c.

4564{
4565 Oid roleid = PG_GETARG_OID(0);
4566 Oid typeoid = PG_GETARG_OID(1);
4568 AclMode mode;
4570 bool is_missing = false;
4571
4573
4575 roleid, mode,
4576 &is_missing);
4577
4578 if (is_missing)
4580
4582}

References ACLCHECK_OK, convert_type_priv_string(), fb(), mode, object_aclcheck_ext(), PG_GETARG_OID, PG_GETARG_TEXT_PP, PG_RETURN_BOOL, and PG_RETURN_NULL.

◆ has_type_privilege_id_name()

Datum has_type_privilege_id_name ( PG_FUNCTION_ARGS  )

Definition at line 4540 of file acl.c.

4541{
4542 Oid roleid = PG_GETARG_OID(0);
4543 text *typename = PG_GETARG_TEXT_PP(1);
4545 Oid typeoid;
4546 AclMode mode;
4548
4549 typeoid = convert_type_name(typename);
4551
4552 aclresult = object_aclcheck(TypeRelationId, typeoid, roleid, mode);
4553
4555}
static Oid convert_type_name(text *typename)
Definition acl.c:4592

References ACLCHECK_OK, convert_type_name(), convert_type_priv_string(), fb(), mode, object_aclcheck(), PG_GETARG_OID, PG_GETARG_TEXT_PP, and PG_RETURN_BOOL.

◆ has_type_privilege_name()

Datum has_type_privilege_name ( PG_FUNCTION_ARGS  )

Definition at line 4458 of file acl.c.

4459{
4460 text *typename = PG_GETARG_TEXT_PP(0);
4462 Oid roleid;
4463 Oid typeoid;
4464 AclMode mode;
4466
4467 roleid = GetUserId();
4468 typeoid = convert_type_name(typename);
4470
4471 aclresult = object_aclcheck(TypeRelationId, typeoid, roleid, mode);
4472
4474}

References ACLCHECK_OK, convert_type_name(), convert_type_priv_string(), fb(), GetUserId(), mode, object_aclcheck(), PG_GETARG_TEXT_PP, and PG_RETURN_BOOL.

◆ has_type_privilege_name_id()

Datum has_type_privilege_name_id ( PG_FUNCTION_ARGS  )

◆ has_type_privilege_name_name()

Datum has_type_privilege_name_name ( PG_FUNCTION_ARGS  )

◆ hash_aclitem()

Datum hash_aclitem ( PG_FUNCTION_ARGS  )

Definition at line 792 of file acl.c.

793{
795
796 /* not very bright, but avoids any issue of padding in struct */
797 PG_RETURN_UINT32((uint32) (a->ai_privs + a->ai_grantee + a->ai_grantor));
798}
uint32_t uint32
Definition c.h:618
#define PG_RETURN_UINT32(x)
Definition fmgr.h:356
int a
Definition isn.c:73

References a, PG_GETARG_ACLITEM_P, and PG_RETURN_UINT32.

◆ hash_aclitem_extended()

Datum hash_aclitem_extended ( PG_FUNCTION_ARGS  )

Definition at line 806 of file acl.c.

807{
809 uint64 seed = PG_GETARG_INT64(1);
810 uint32 sum = (uint32) (a->ai_privs + a->ai_grantee + a->ai_grantor);
811
812 return (seed == 0) ? UInt64GetDatum(sum) : hash_uint32_extended(sum, seed);
813}
uint64_t uint64
Definition c.h:619
#define PG_GETARG_INT64(n)
Definition fmgr.h:284
static Datum hash_uint32_extended(uint32 k, uint64 seed)
Definition hashfn.h:49
static Datum UInt64GetDatum(uint64 X)
Definition postgres.h:433

References a, hash_uint32_extended(), PG_GETARG_ACLITEM_P, PG_GETARG_INT64, and UInt64GetDatum().

◆ initialize_acl()

void initialize_acl ( void  )

Definition at line 5069 of file acl.c.

5070{
5072 {
5076
5077 /*
5078 * In normal mode, set a callback on any syscache invalidation of rows
5079 * of pg_auth_members (for roles_is_member_of()) pg_database (for
5080 * roles_is_member_of())
5081 */
5084 (Datum) 0);
5087 (Datum) 0);
5090 (Datum) 0);
5091 }
5092}
static uint32 cached_db_hash
Definition acl.c:84
static void RoleMembershipCacheCallback(Datum arg, SysCacheIdentifier cacheid, uint32 hashvalue)
Definition acl.c:5099
Oid MyDatabaseId
Definition globals.c:94
void CacheRegisterSyscacheCallback(SysCacheIdentifier cacheid, SyscacheCallbackFunction func, Datum arg)
Definition inval.c:1816
#define GetSysCacheHashValue1(cacheId, key1)
Definition syscache.h:118

References cached_db_hash, CacheRegisterSyscacheCallback(), fb(), GetSysCacheHashValue1, IsBootstrapProcessingMode, MyDatabaseId, ObjectIdGetDatum(), and RoleMembershipCacheCallback().

Referenced by InitPostgres().

◆ is_admin_of_role()

bool is_admin_of_role ( Oid  member,
Oid  role 
)

Definition at line 5444 of file acl.c.

5445{
5447
5448 if (superuser_arg(member))
5449 return true;
5450
5451 /* By policy, a role cannot have WITH ADMIN OPTION on itself. */
5452 if (member == role)
5453 return false;
5454
5456 return OidIsValid(admin_role);
5457}

References fb(), OidIsValid, ROLERECURSE_MEMBERS, roles_is_member_of(), and superuser_arg().

Referenced by AlterRole(), AlterRoleSet(), check_object_ownership(), check_role_membership_authorization(), DropRole(), pg_role_aclcheck(), and RenameRole().

◆ is_member_of_role()

bool is_member_of_role ( Oid  member,
Oid  role 
)

Definition at line 5394 of file acl.c.

5395{
5396 /* Fast path for simple case */
5397 if (member == role)
5398 return true;
5399
5400 /* Superusers have every privilege, so are part of every role */
5401 if (superuser_arg(member))
5402 return true;
5403
5404 /*
5405 * Find all the roles that member is a member of, including multi-level
5406 * recursion, then see if target role is any one of them.
5407 */
5409 InvalidOid, NULL),
5410 role);
5411}

References fb(), InvalidOid, list_member_oid(), ROLERECURSE_MEMBERS, roles_is_member_of(), and superuser_arg().

Referenced by pg_role_aclcheck().

◆ is_member_of_role_nosuper()

bool is_member_of_role_nosuper ( Oid  member,
Oid  role 
)

Definition at line 5422 of file acl.c.

5423{
5424 /* Fast path for simple case */
5425 if (member == role)
5426 return true;
5427
5428 /*
5429 * Find all the roles that member is a member of, including multi-level
5430 * recursion, then see if target role is any one of them.
5431 */
5433 InvalidOid, NULL),
5434 role);
5435}

References fb(), InvalidOid, list_member_oid(), ROLERECURSE_MEMBERS, and roles_is_member_of().

Referenced by AddRoleMems(), and is_member().

◆ is_safe_acl_char()

static bool is_safe_acl_char ( unsigned char  c,
bool  is_getid 
)
inlinestatic

Definition at line 148 of file acl.c.

149{
150 if (IS_HIGHBIT_SET(c))
151 return is_getid;
152 return isalnum(c) || c == '_';
153}
#define IS_HIGHBIT_SET(ch)
Definition c.h:1246
char * c

References fb(), and IS_HIGHBIT_SET.

Referenced by getid(), and putid().

◆ make_empty_acl()

Acl * make_empty_acl ( void  )

Definition at line 462 of file acl.c.

463{
464 return allocacl(0);
465}

References allocacl().

Referenced by SetDefaultACL().

◆ makeaclitem()

Datum makeaclitem ( PG_FUNCTION_ARGS  )

Definition at line 1662 of file acl.c.

1663{
1665 Oid grantor = PG_GETARG_OID(1);
1667 bool goption = PG_GETARG_BOOL(3);
1668 AclItem *result;
1669 AclMode priv;
1670 static const priv_map any_priv_map[] = {
1671 {"SELECT", ACL_SELECT},
1672 {"INSERT", ACL_INSERT},
1673 {"UPDATE", ACL_UPDATE},
1674 {"DELETE", ACL_DELETE},
1675 {"TRUNCATE", ACL_TRUNCATE},
1676 {"REFERENCES", ACL_REFERENCES},
1677 {"TRIGGER", ACL_TRIGGER},
1678 {"EXECUTE", ACL_EXECUTE},
1679 {"USAGE", ACL_USAGE},
1680 {"CREATE", ACL_CREATE},
1681 {"TEMP", ACL_CREATE_TEMP},
1682 {"TEMPORARY", ACL_CREATE_TEMP},
1683 {"CONNECT", ACL_CONNECT},
1684 {"SET", ACL_SET},
1685 {"ALTER SYSTEM", ACL_ALTER_SYSTEM},
1686 {"MAINTAIN", ACL_MAINTAIN},
1687 {NULL, 0}
1688 };
1689
1691
1692 result = palloc_object(AclItem);
1693
1694 result->ai_grantee = grantee;
1695 result->ai_grantor = grantor;
1696
1697 ACLITEM_SET_PRIVS_GOPTIONS(*result, priv,
1698 (goption ? priv : ACL_NO_RIGHTS));
1699
1700 PG_RETURN_ACLITEM_P(result);
1701}
#define PG_GETARG_BOOL(n)
Definition fmgr.h:274
Oid ai_grantee
Definition acl.h:56
Oid ai_grantor
Definition acl.h:57

References ACL_ALTER_SYSTEM, ACL_CONNECT, ACL_CREATE, ACL_CREATE_TEMP, ACL_DELETE, ACL_EXECUTE, ACL_INSERT, ACL_MAINTAIN, ACL_NO_RIGHTS, ACL_REFERENCES, ACL_SELECT, ACL_SET, ACL_TRIGGER, ACL_TRUNCATE, ACL_UPDATE, ACL_USAGE, ACLITEM_SET_PRIVS_GOPTIONS, AclItem::ai_grantee, AclItem::ai_grantor, convert_any_priv_string(), fb(), palloc_object, PG_GETARG_BOOL, PG_GETARG_OID, PG_GETARG_TEXT_PP, and PG_RETURN_ACLITEM_P.

◆ member_can_set_role()

bool member_can_set_role ( Oid  member,
Oid  role 
)

Definition at line 5348 of file acl.c.

5349{
5350 /* Fast path for simple case */
5351 if (member == role)
5352 return true;
5353
5354 /* Superusers have every privilege, so can always SET ROLE */
5355 if (superuser_arg(member))
5356 return true;
5357
5358 /*
5359 * Find all the roles that member can access via SET ROLE, including
5360 * multi-level recursion, then see if target role is any one of them.
5361 */
5363 InvalidOid, NULL),
5364 role);
5365}

References fb(), InvalidOid, list_member_oid(), ROLERECURSE_SETROLE, roles_is_member_of(), and superuser_arg().

Referenced by check_can_set_role(), check_role(), pg_role_aclcheck(), and SwitchToUntrustedUser().

◆ pg_has_role_id()

Datum pg_has_role_id ( PG_FUNCTION_ARGS  )

Definition at line 4941 of file acl.c.

4942{
4943 Oid roleoid = PG_GETARG_OID(0);
4945 Oid roleid;
4946 AclMode mode;
4948
4949 roleid = GetUserId();
4951
4952 aclresult = pg_role_aclcheck(roleoid, roleid, mode);
4953
4955}
static AclMode convert_role_priv_string(text *priv_type_text)
Definition acl.c:5016
static AclResult pg_role_aclcheck(Oid role_oid, Oid roleid, AclMode mode)
Definition acl.c:5039

References ACLCHECK_OK, convert_role_priv_string(), fb(), GetUserId(), mode, PG_GETARG_OID, PG_GETARG_TEXT_PP, PG_RETURN_BOOL, and pg_role_aclcheck().

◆ pg_has_role_id_id()

Datum pg_has_role_id_id ( PG_FUNCTION_ARGS  )

Definition at line 4986 of file acl.c.

4987{
4988 Oid roleid = PG_GETARG_OID(0);
4989 Oid roleoid = PG_GETARG_OID(1);
4991 AclMode mode;
4993
4995
4996 aclresult = pg_role_aclcheck(roleoid, roleid, mode);
4997
4999}

References ACLCHECK_OK, convert_role_priv_string(), fb(), mode, PG_GETARG_OID, PG_GETARG_TEXT_PP, PG_RETURN_BOOL, and pg_role_aclcheck().

◆ pg_has_role_id_name()

Datum pg_has_role_id_name ( PG_FUNCTION_ARGS  )

Definition at line 4963 of file acl.c.

4964{
4965 Oid roleid = PG_GETARG_OID(0);
4966 Name rolename = PG_GETARG_NAME(1);
4968 Oid roleoid;
4969 AclMode mode;
4971
4972 roleoid = get_role_oid(NameStr(*rolename), false);
4974
4975 aclresult = pg_role_aclcheck(roleoid, roleid, mode);
4976
4978}

References ACLCHECK_OK, convert_role_priv_string(), fb(), get_role_oid(), mode, NameStr, PG_GETARG_NAME, PG_GETARG_OID, PG_GETARG_TEXT_PP, PG_RETURN_BOOL, and pg_role_aclcheck().

◆ pg_has_role_name()

Datum pg_has_role_name ( PG_FUNCTION_ARGS  )

Definition at line 4893 of file acl.c.

4894{
4895 Name rolename = PG_GETARG_NAME(0);
4897 Oid roleid;
4898 Oid roleoid;
4899 AclMode mode;
4901
4902 roleid = GetUserId();
4903 roleoid = get_role_oid(NameStr(*rolename), false);
4905
4906 aclresult = pg_role_aclcheck(roleoid, roleid, mode);
4907
4909}

References ACLCHECK_OK, convert_role_priv_string(), fb(), get_role_oid(), GetUserId(), mode, NameStr, PG_GETARG_NAME, PG_GETARG_TEXT_PP, PG_RETURN_BOOL, and pg_role_aclcheck().

◆ pg_has_role_name_id()

Datum pg_has_role_name_id ( PG_FUNCTION_ARGS  )

◆ pg_has_role_name_name()

Datum pg_has_role_name_name ( PG_FUNCTION_ARGS  )

Definition at line 4867 of file acl.c.

4868{
4870 Name rolename = PG_GETARG_NAME(1);
4872 Oid roleid;
4873 Oid roleoid;
4874 AclMode mode;
4876
4877 roleid = get_role_oid(NameStr(*username), false);
4878 roleoid = get_role_oid(NameStr(*rolename), false);
4880
4881 aclresult = pg_role_aclcheck(roleoid, roleid, mode);
4882
4884}

References ACLCHECK_OK, convert_role_priv_string(), fb(), get_role_oid(), mode, NameStr, PG_GETARG_NAME, PG_GETARG_TEXT_PP, PG_RETURN_BOOL, pg_role_aclcheck(), and username.

◆ pg_role_aclcheck()

static AclResult pg_role_aclcheck ( Oid  role_oid,
Oid  roleid,
AclMode  mode 
)
static

Definition at line 5039 of file acl.c.

5040{
5042 {
5043 if (is_admin_of_role(roleid, role_oid))
5044 return ACLCHECK_OK;
5045 }
5046 if (mode & ACL_CREATE)
5047 {
5048 if (is_member_of_role(roleid, role_oid))
5049 return ACLCHECK_OK;
5050 }
5051 if (mode & ACL_USAGE)
5052 {
5053 if (has_privs_of_role(roleid, role_oid))
5054 return ACLCHECK_OK;
5055 }
5056 if (mode & ACL_SET)
5057 {
5058 if (member_can_set_role(roleid, role_oid))
5059 return ACLCHECK_OK;
5060 }
5061 return ACLCHECK_NO_PRIV;
5062}
bool is_admin_of_role(Oid member, Oid role)
Definition acl.c:5444
bool is_member_of_role(Oid member, Oid role)
Definition acl.c:5394
@ ACLCHECK_NO_PRIV
Definition acl.h:185

References ACL_CREATE, ACL_GRANT_OPTION_FOR, ACL_SET, ACL_USAGE, ACLCHECK_NO_PRIV, ACLCHECK_OK, fb(), has_privs_of_role(), is_admin_of_role(), is_member_of_role(), member_can_set_role(), and mode.

Referenced by pg_has_role_id(), pg_has_role_id_id(), pg_has_role_id_name(), pg_has_role_name(), pg_has_role_name_id(), and pg_has_role_name_name().

◆ putid()

static void putid ( char p,
const char s 
)
static

Definition at line 224 of file acl.c.

225{
226 const char *src;
227 bool safe = true;
228
229 /* Detect whether we need to use double quotes */
230 for (src = s; *src; src++)
231 {
232 if (!is_safe_acl_char(*src, false))
233 {
234 safe = false;
235 break;
236 }
237 }
238 if (!safe)
239 *p++ = '"';
240 for (src = s; *src; src++)
241 {
242 /* A double quote character in a username is encoded as "" */
243 if (*src == '"')
244 *p++ = '"';
245 *p++ = *src;
246 }
247 if (!safe)
248 *p++ = '"';
249 *p = '\0';
250}

References fb(), and is_safe_acl_char().

Referenced by aclitemout().

◆ recursive_revoke()

static Acl * recursive_revoke ( Acl acl,
Oid  grantee,
AclMode  revoke_privs,
Oid  ownerId,
DropBehavior  behavior 
)
static

Definition at line 1330 of file acl.c.

1335{
1337 AclItem *aip;
1338 int i,
1339 num;
1340
1341 check_acl(acl);
1342
1343 /* The owner can never truly lose grant options, so short-circuit */
1344 if (grantee == ownerId)
1345 return acl;
1346
1347 /* The grantee might still have some grant options via another grantor */
1348 still_has = aclmask(acl, grantee, ownerId,
1350 ACLMASK_ALL);
1353 return acl;
1354
1355restart:
1356 num = ACL_NUM(acl);
1357 aip = ACL_DAT(acl);
1358 for (i = 0; i < num; i++)
1359 {
1360 if (aip[i].ai_grantor == grantee
1361 && (ACLITEM_GET_PRIVS(aip[i]) & revoke_privs) != 0)
1362 {
1364 Acl *new_acl;
1365
1366 if (behavior == DROP_RESTRICT)
1367 ereport(ERROR,
1369 errmsg("dependent privileges exist"),
1370 errhint("Use CASCADE to revoke them too.")));
1371
1372 mod_acl.ai_grantor = grantee;
1373 mod_acl.ai_grantee = aip[i].ai_grantee;
1376 revoke_privs);
1377
1379 ownerId, behavior);
1380
1381 pfree(acl);
1382 acl = new_acl;
1383
1384 goto restart;
1385 }
1386 }
1387
1388 return acl;
1389}

References ACL_DAT, ACL_GRANT_OPTION_FOR, ACL_MODECHG_DEL, ACL_NO_RIGHTS, ACL_NUM, ACLITEM_GET_PRIVS, ACLITEM_SET_PRIVS_GOPTIONS, aclmask(), ACLMASK_ALL, aclupdate(), check_acl(), DROP_RESTRICT, ereport, errcode(), errhint(), errmsg, ERROR, fb(), i, and pfree().

Referenced by aclupdate().

◆ RoleMembershipCacheCallback()

static void RoleMembershipCacheCallback ( Datum  arg,
SysCacheIdentifier  cacheid,
uint32  hashvalue 
)
static

Definition at line 5099 of file acl.c.

5101{
5102 if (cacheid == DATABASEOID &&
5103 hashvalue != cached_db_hash &&
5104 hashvalue != 0)
5105 {
5106 return; /* ignore pg_database changes for other DBs */
5107 }
5108
5109 /* Force membership caches to be recomputed on next use */
5113}
static Oid cached_role[]
Definition acl.c:82

References cached_db_hash, cached_role, fb(), InvalidOid, ROLERECURSE_MEMBERS, ROLERECURSE_PRIVS, and ROLERECURSE_SETROLE.

Referenced by initialize_acl().

◆ roles_is_member_of()

static List * roles_is_member_of ( Oid  roleid,
enum RoleRecurseType  type,
Oid  admin_of,
Oid admin_role 
)
static

Definition at line 5182 of file acl.c.

5184{
5185 Oid dba;
5187 ListCell *l;
5190 bloom_filter *bf = NULL;
5191
5193 if (admin_role != NULL)
5195
5196 /* If cache is valid and ADMIN OPTION not sought, just return the list */
5197 if (cached_role[type] == roleid && !OidIsValid(admin_of) &&
5199 return cached_roles[type];
5200
5201 /*
5202 * Role expansion happens in a non-database backend when guc.c checks
5203 * ROLE_PG_READ_ALL_SETTINGS for a physical walsender SHOW command. In
5204 * that case, no role gets pg_database_owner.
5205 */
5207 dba = InvalidOid;
5208 else
5209 {
5211
5213 if (!HeapTupleIsValid(dbtup))
5214 elog(ERROR, "cache lookup failed for database %u", MyDatabaseId);
5217 }
5218
5219 /*
5220 * Find all the roles that roleid is a member of, including multi-level
5221 * recursion. The role itself will always be the first element of the
5222 * resulting list.
5223 *
5224 * Each element of the list is scanned to see if it adds any indirect
5225 * memberships. We can use a single list as both the record of
5226 * already-found memberships and the agenda of roles yet to be scanned.
5227 * This is a bit tricky but works because the foreach() macro doesn't
5228 * fetch the next list element until the bottom of the loop.
5229 */
5230 roles_list = list_make1_oid(roleid);
5231
5232 foreach(l, roles_list)
5233 {
5234 Oid memberid = lfirst_oid(l);
5236 int i;
5237
5238 /* Find roles that memberid is directly a member of */
5241 for (i = 0; i < memlist->n_members; i++)
5242 {
5243 HeapTuple tup = &memlist->members[i]->tuple;
5245 Oid otherid = form->roleid;
5246
5247 /*
5248 * While otherid==InvalidOid shouldn't appear in the catalog, the
5249 * OidIsValid() avoids crashing if that arises.
5250 */
5251 if (otherid == admin_of && form->admin_option &&
5254
5255 /* If we're supposed to ignore non-heritable grants, do so. */
5256 if (type == ROLERECURSE_PRIVS && !form->inherit_option)
5257 continue;
5258
5259 /* If we're supposed to ignore non-SET grants, do so. */
5260 if (type == ROLERECURSE_SETROLE && !form->set_option)
5261 continue;
5262
5263 /*
5264 * Even though there shouldn't be any loops in the membership
5265 * graph, we must test for having already seen this role. It is
5266 * legal for instance to have both A->B and A->C->B.
5267 */
5269 }
5271
5272 /* implement pg_database_owner implicit membership */
5273 if (memberid == dba && OidIsValid(dba))
5276 }
5277
5278 /*
5279 * Free the Bloom filter created by roles_list_append(), if there is one.
5280 */
5281 if (bf)
5282 bloom_free(bf);
5283
5284 /*
5285 * Copy the completed list into TopMemoryContext so it will persist.
5286 */
5291
5292 /*
5293 * Now safe to assign to state variable
5294 */
5295 cached_role[type] = InvalidOid; /* just paranoia */
5298 cached_role[type] = roleid;
5299
5300 /* And now we can return the answer */
5301 return cached_roles[type];
5302}
static List * roles_list_append(List *roles_list, bloom_filter **bf, Oid role)
Definition acl.c:5122
static List * cached_roles[]
Definition acl.c:83
void bloom_free(bloom_filter *filter)
List * list_copy(const List *oldlist)
Definition list.c:1573
void list_free(List *list)
Definition list.c:1546
MemoryContext TopMemoryContext
Definition mcxt.c:166
END_CATALOG_STRUCT typedef FormData_pg_auth_members * Form_pg_auth_members
END_CATALOG_STRUCT typedef FormData_pg_database * Form_pg_database
#define list_make1_oid(x1)
Definition pg_list.h:274
#define lfirst_oid(lc)
Definition pg_list.h:174
Definition pg_list.h:54
#define ReleaseSysCacheList(x)
Definition syscache.h:134
#define SearchSysCacheList1(cacheId, key1)
Definition syscache.h:127
const char * type

References Assert, bloom_free(), cached_role, cached_roles, elog, ERROR, fb(), Form_pg_auth_members, Form_pg_database, GETSTRUCT(), HeapTupleIsValid, i, InvalidOid, lfirst_oid, list_copy(), list_free(), list_make1_oid, MemoryContextSwitchTo(), MyDatabaseId, ObjectIdGetDatum(), OidIsValid, ReleaseSysCache(), ReleaseSysCacheList, ROLERECURSE_PRIVS, ROLERECURSE_SETROLE, roles_list_append(), SearchSysCache1(), SearchSysCacheList1, TopMemoryContext, and type.

Referenced by has_privs_of_role(), is_admin_of_role(), is_member_of_role(), is_member_of_role_nosuper(), member_can_set_role(), select_best_admin(), and select_best_grantor().

◆ roles_list_append()

static List * roles_list_append ( List roles_list,
bloom_filter **  bf,
Oid  role 
)
inlinestatic

Definition at line 5122 of file acl.c.

5123{
5124 unsigned char *roleptr = (unsigned char *) &role;
5125
5126 /*
5127 * If there is a previously-created Bloom filter, use it to try to
5128 * determine whether the role is missing from the list. If it says yes,
5129 * that's a hard fact and we can go ahead and add the role. If it says
5130 * no, that's only probabilistic and we'd better search the list. Without
5131 * a filter, we must always do an ordinary linear search through the
5132 * existing list.
5133 */
5134 if ((*bf && bloom_lacks_element(*bf, roleptr, sizeof(Oid))) ||
5136 {
5137 /*
5138 * If the list is large, we take on the overhead of creating and
5139 * populating a Bloom filter to speed up future calls to this
5140 * function.
5141 */
5142 if (*bf == NULL &&
5144 {
5146 foreach_oid(roleid, roles_list)
5147 bloom_add_element(*bf, (unsigned char *) &roleid, sizeof(Oid));
5148 }
5149
5150 /*
5151 * Finally, add the role to the list and the Bloom filter, if it
5152 * exists.
5153 */
5155 if (*bf)
5156 bloom_add_element(*bf, roleptr, sizeof(Oid));
5157 }
5158
5159 return roles_list;
5160}
#define ROLES_LIST_BLOOM_THRESHOLD
Definition acl.c:92
bloom_filter * bloom_create(int64 total_elems, int bloom_work_mem, uint64 seed)
Definition bloomfilter.c:87
bool bloom_lacks_element(bloom_filter *filter, unsigned char *elem, size_t len)
void bloom_add_element(bloom_filter *filter, unsigned char *elem, size_t len)
int work_mem
Definition globals.c:131
List * lappend_oid(List *list, Oid datum)
Definition list.c:375
static int list_length(const List *l)
Definition pg_list.h:152
#define foreach_oid(var, lst)
Definition pg_list.h:503

References bloom_add_element(), bloom_create(), bloom_lacks_element(), fb(), foreach_oid, lappend_oid(), list_length(), list_member_oid(), ROLES_LIST_BLOOM_THRESHOLD, and work_mem.

Referenced by roles_is_member_of().

◆ select_best_admin()

Oid select_best_admin ( Oid  member,
Oid  role 
)

Definition at line 5469 of file acl.c.

5470{
5472
5473 /* By policy, a role cannot have WITH ADMIN OPTION on itself. */
5474 if (member == role)
5475 return InvalidOid;
5476
5478 return admin_role;
5479}

References fb(), InvalidOid, ROLERECURSE_PRIVS, and roles_is_member_of().

Referenced by check_role_grantor().

◆ select_best_grantor()

void select_best_grantor ( const RoleSpec grantedBy,
AclMode  privileges,
const Acl acl,
Oid  ownerId,
Oid grantorId,
AclMode grantOptions 
)

Definition at line 5508 of file acl.c.

5511{
5512 Oid roleId = GetUserId();
5515 int nrights;
5516 ListCell *l;
5517
5518 /*
5519 * If we have GRANTED BY, resolve it and verify current user is allowed to
5520 * specify that role.
5521 */
5522 if (grantedBy)
5523 {
5524 Oid grantor = get_rolespec_oid(grantedBy, false);
5525
5526 if (!has_privs_of_role(roleId, grantor))
5527 ereport(ERROR,
5529 errmsg("must inherit privileges of role \"%s\"",
5530 GetUserNameFromId(grantor, false))));
5531 /* Use exactly that grantor, whether it has privileges or not */
5532 *grantorId = grantor;
5533 *grantOptions = aclmask_direct(acl, grantor, ownerId,
5535 return;
5536 }
5537
5538 /*
5539 * The object owner is always treated as having all grant options, so if
5540 * roleId is the owner it's easy. Also, if roleId is a superuser it's
5541 * easy: superusers are implicitly members of every role, so they act as
5542 * the object owner.
5543 */
5544 if (roleId == ownerId || superuser_arg(roleId))
5545 {
5546 *grantorId = ownerId;
5548 return;
5549 }
5550
5551 /*
5552 * Otherwise we have to do a careful search to see if roleId has the
5553 * privileges of any suitable role. Note: we can hang onto the result of
5554 * roles_is_member_of() throughout this loop, because aclmask_direct()
5555 * doesn't query any role memberships.
5556 */
5558 InvalidOid, NULL);
5559
5560 /* initialize candidate result as default */
5561 *grantorId = roleId;
5563 nrights = 0;
5564
5565 foreach(l, roles_list)
5566 {
5569
5570 otherprivs = aclmask_direct(acl, otherrole, ownerId,
5573 {
5574 /* Found a suitable grantor */
5577 return;
5578 }
5579
5580 /*
5581 * If it has just some of the needed privileges, remember best
5582 * candidate.
5583 */
5585 {
5587
5588 if (nnewrights > nrights)
5589 {
5593 }
5594 }
5595 }
5596}
static AclMode aclmask_direct(const Acl *acl, Oid roleid, Oid ownerId, AclMode mask, AclMaskHow how)
Definition acl.c:1505
Oid get_rolespec_oid(const RoleSpec *role, bool missing_ok)
Definition acl.c:5639
static int pg_popcount64(uint64 word)

References ACL_GRANT_OPTION_FOR, ACL_NO_RIGHTS, ACLMASK_ALL, aclmask_direct(), ereport, errcode(), errmsg, ERROR, fb(), get_rolespec_oid(), GetUserId(), GetUserNameFromId(), has_privs_of_role(), InvalidOid, lfirst_oid, pg_popcount64(), ROLERECURSE_PRIVS, roles_is_member_of(), and superuser_arg().

Referenced by ExecGrant_Attribute(), ExecGrant_common(), ExecGrant_Largeobject(), ExecGrant_Parameter(), and ExecGrant_Relation().

Variable Documentation

◆ cached_db_hash

uint32 cached_db_hash
static

Definition at line 84 of file acl.c.

Referenced by initialize_acl(), and RoleMembershipCacheCallback().

◆ cached_role

Oid cached_role[] = {InvalidOid, InvalidOid, InvalidOid}
static

Definition at line 82 of file acl.c.

Referenced by RoleMembershipCacheCallback(), and roles_is_member_of().

◆ cached_roles

List* cached_roles[] = {NIL, NIL, NIL}
static

Definition at line 83 of file acl.c.

83{NIL, NIL, NIL};
#define NIL
Definition pg_list.h:68

Referenced by roles_is_member_of().