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 "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 "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 (Oid roleId, 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 90 of file acl.c.

Enumeration Type Documentation

◆ RoleRecurseType

Enumerator
ROLERECURSE_MEMBERS 
ROLERECURSE_PRIVS 
ROLERECURSE_SETROLE 

Definition at line 74 of file acl.c.

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

Function Documentation

◆ aclconcat()

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

Definition at line 478 of file acl.c.

479{
481
483
486 ACL_NUM(left_acl) * sizeof(AclItem));
487
490 ACL_NUM(right_acl) * sizeof(AclItem));
491
492 return result_acl;
493}
static Acl * allocacl(int n)
Definition acl.c:427
#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 1613 of file acl.c.

1614{
1615 Acl *acl = PG_GETARG_ACL_P(0);
1617 AclItem *aidat;
1618 int i,
1619 num;
1620
1621 check_acl(acl);
1622 num = ACL_NUM(acl);
1623 aidat = ACL_DAT(acl);
1624 for (i = 0; i < num; ++i)
1625 {
1626 if (aip->ai_grantee == aidat[i].ai_grantee &&
1627 aip->ai_grantor == aidat[i].ai_grantor &&
1629 PG_RETURN_BOOL(true);
1630 }
1631 PG_RETURN_BOOL(false);
1632}
static void check_acl(const Acl *acl)
Definition acl.c:591
#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 458 of file acl.c.

459{
461
463
466 ACL_NUM(orig_acl) * sizeof(AclItem));
467
468 return result_acl;
469}

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 804 of file acl.c.

805{
808 int nacl;
809 Acl *acl;
810 AclItem *aip;
811
812 switch (objtype)
813 {
814 case OBJECT_COLUMN:
815 /* by default, columns have no extra privileges */
818 break;
819 case OBJECT_TABLE:
822 break;
823 case OBJECT_SEQUENCE:
826 break;
827 case OBJECT_DATABASE:
828 /* for backwards compatibility, grant some rights by default */
831 break;
832 case OBJECT_FUNCTION:
833 /* Grant EXECUTE by default, for now */
836 break;
837 case OBJECT_LANGUAGE:
838 /* Grant USAGE by default, for now */
841 break;
845 break;
846 case OBJECT_SCHEMA:
849 break;
853 break;
854 case OBJECT_FDW:
857 break;
861 break;
862 case OBJECT_DOMAIN:
863 case OBJECT_TYPE:
866 break;
870 break;
871 default:
872 elog(ERROR, "unrecognized object type: %d", (int) objtype);
873 world_default = ACL_NO_RIGHTS; /* keep compiler quiet */
875 break;
876 }
877
878 nacl = 0;
880 nacl++;
882 nacl++;
883
884 acl = allocacl(nacl);
885 aip = ACL_DAT(acl);
886
888 {
889 aip->ai_grantee = ACL_ID_PUBLIC;
890 aip->ai_grantor = ownerId;
892 aip++;
893 }
894
895 /*
896 * Note that the owner's entry shows all ordinary privileges but no grant
897 * options. This is because his grant options come "from the system" and
898 * not from his own efforts. (The SQL spec says that the owner's rights
899 * come from a "_SYSTEM" authid.) However, we do consider that the
900 * owner's ordinary privileges are self-granted; this lets him revoke
901 * them. We implement the owner's grant options without any explicit
902 * "_SYSTEM"-like ACL entry, by internally special-casing the owner
903 * wherever we are testing grant options.
904 */
906 {
907 aip->ai_grantee = ownerId;
908 aip->ai_grantor = ownerId;
910 }
911
912 return acl;
913}
#define ACL_ALL_RIGHTS_FOREIGN_SERVER
Definition acl.h:164
#define ACL_ALL_RIGHTS_TABLESPACE
Definition acl.h:170
#define ACL_ALL_RIGHTS_PARAMETER_ACL
Definition acl.h:168
#define ACL_ALL_RIGHTS_SCHEMA
Definition acl.h:169
#define ACL_ALL_RIGHTS_SEQUENCE
Definition acl.h:161
#define ACL_ALL_RIGHTS_DATABASE
Definition acl.h:162
#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:171
#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_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_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_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 921 of file acl.c.

922{
923 char objtypec = PG_GETARG_CHAR(0);
924 Oid owner = PG_GETARG_OID(1);
925 ObjectType objtype = 0;
926
927 switch (objtypec)
928 {
929 case 'c':
930 objtype = OBJECT_COLUMN;
931 break;
932 case 'r':
933 objtype = OBJECT_TABLE;
934 break;
935 case 's':
936 objtype = OBJECT_SEQUENCE;
937 break;
938 case 'd':
939 objtype = OBJECT_DATABASE;
940 break;
941 case 'f':
942 objtype = OBJECT_FUNCTION;
943 break;
944 case 'l':
945 objtype = OBJECT_LANGUAGE;
946 break;
947 case 'L':
948 objtype = OBJECT_LARGEOBJECT;
949 break;
950 case 'n':
951 objtype = OBJECT_SCHEMA;
952 break;
953 case 'p':
954 objtype = OBJECT_PARAMETER_ACL;
955 break;
956 case 't':
957 objtype = OBJECT_TABLESPACE;
958 break;
959 case 'F':
960 objtype = OBJECT_FDW;
961 break;
962 case 'S':
963 objtype = OBJECT_FOREIGN_SERVER;
964 break;
965 case 'T':
966 objtype = OBJECT_TYPE;
967 break;
968 default:
969 elog(ERROR, "unrecognized object type abbreviation: %c", objtypec);
970 }
971
972 PG_RETURN_ACL_P(acldefault(objtype, owner));
973}
Acl * acldefault(ObjectType objtype, Oid ownerId)
Definition acl.c:804
#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 560 of file acl.c.

561{
562 /* Check for cases where one or both are empty/null */
563 if (left_acl == NULL || ACL_NUM(left_acl) == 0)
564 {
565 if (right_acl == NULL || ACL_NUM(right_acl) == 0)
566 return true;
567 else
568 return false;
569 }
570 else
571 {
572 if (right_acl == NULL || ACL_NUM(right_acl) == 0)
573 return false;
574 }
575
577 return false;
578
581 ACL_NUM(left_acl) * sizeof(AclItem)) == 0)
582 return true;
583
584 return false;
585}

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 1791 of file acl.c.

1792{
1793 Acl *acl = PG_GETARG_ACL_P(0);
1795 int *idx;
1796 AclItem *aidat;
1797
1798 if (SRF_IS_FIRSTCALL())
1799 {
1800 TupleDesc tupdesc;
1801 MemoryContext oldcontext;
1802
1803 check_acl(acl);
1804
1806 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
1807
1808 /*
1809 * build tupdesc for result tuples (matches out parameters in pg_proc
1810 * entry)
1811 */
1812 tupdesc = CreateTemplateTupleDesc(4);
1813 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "grantor",
1814 OIDOID, -1, 0);
1815 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "grantee",
1816 OIDOID, -1, 0);
1817 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "privilege_type",
1818 TEXTOID, -1, 0);
1819 TupleDescInitEntry(tupdesc, (AttrNumber) 4, "is_grantable",
1820 BOOLOID, -1, 0);
1821
1822 funcctx->tuple_desc = BlessTupleDesc(tupdesc);
1823
1824 /* allocate memory for user context */
1825 idx = palloc_array(int, 2);
1826 idx[0] = 0; /* ACL array item index */
1827 idx[1] = -1; /* privilege type counter */
1828 funcctx->user_fctx = idx;
1829
1830 MemoryContextSwitchTo(oldcontext);
1831 }
1832
1834 idx = (int *) funcctx->user_fctx;
1835 aidat = ACL_DAT(acl);
1836
1837 /* need test here in case acl has no items */
1838 while (idx[0] < ACL_NUM(acl))
1839 {
1840 AclItem *aidata;
1842
1843 idx[1]++;
1844 if (idx[1] == N_ACL_RIGHTS)
1845 {
1846 idx[1] = 0;
1847 idx[0]++;
1848 if (idx[0] >= ACL_NUM(acl)) /* done */
1849 break;
1850 }
1851 aidata = &aidat[idx[0]];
1852 priv_bit = UINT64CONST(1) << idx[1];
1853
1855 {
1856 Datum result;
1857 Datum values[4];
1858 bool nulls[4] = {0};
1859 HeapTuple tuple;
1860
1861 values[0] = ObjectIdGetDatum(aidata->ai_grantor);
1862 values[1] = ObjectIdGetDatum(aidata->ai_grantee);
1865
1866 tuple = heap_form_tuple(funcctx->tuple_desc, values, nulls);
1867 result = HeapTupleGetDatum(tuple);
1868
1869 SRF_RETURN_NEXT(funcctx, result);
1870 }
1871 }
1872
1874}
Datum idx(PG_FUNCTION_ARGS)
Definition _int_op.c:262
static const char * convert_aclright_to_string(int aclright)
Definition acl.c:1735
#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:155
#define CStringGetTextDatum(s)
Definition builtins.h:98
#define UINT64CONST(x)
Definition c.h:561
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:1117
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:262
uint64_t Datum
Definition postgres.h:70
TupleDesc CreateTemplateTupleDesc(int natts)
Definition tupdesc.c:165
void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
Definition tupdesc.c:825

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, TupleDescInitEntry(), UINT64CONST, and values.

◆ aclinsert()

Datum aclinsert ( PG_FUNCTION_ARGS  )

Definition at line 1593 of file acl.c.

1594{
1595 ereport(ERROR,
1597 errmsg("aclinsert is no longer supported")));
1598
1599 PG_RETURN_NULL(); /* keep compiler quiet */
1600}
int errcode(int sqlerrcode)
Definition elog.c:864
int errmsg(const char *fmt,...)
Definition elog.c:1081
#define ereport(elevel,...)
Definition elog.h:150
#define PG_RETURN_NULL()
Definition fmgr.h:346

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

◆ aclitem_eq()

Datum aclitem_eq ( PG_FUNCTION_ARGS  )

Definition at line 749 of file acl.c.

750{
753 bool result;
754
755 result = a1->ai_privs == a2->ai_privs &&
756 a1->ai_grantee == a2->ai_grantee &&
757 a1->ai_grantor == a2->ai_grantor;
758 PG_RETURN_BOOL(result);
759}
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 714 of file acl.c.

715{
716 return a1->ai_grantee == a2->ai_grantee &&
717 a1->ai_grantor == a2->ai_grantor;
718}

References a1, and a2.

Referenced by aclnewowner(), and aclupdate().

◆ aclitemComparator()

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

Definition at line 725 of file acl.c.

726{
727 const AclItem *a1 = (const AclItem *) arg1;
728 const AclItem *a2 = (const AclItem *) arg2;
729
730 if (a1->ai_grantee > a2->ai_grantee)
731 return 1;
732 if (a1->ai_grantee < a2->ai_grantee)
733 return -1;
734 if (a1->ai_grantor > a2->ai_grantor)
735 return 1;
736 if (a1->ai_grantor < a2->ai_grantor)
737 return -1;
738 if (a1->ai_privs > a2->ai_privs)
739 return 1;
740 if (a1->ai_privs < a2->ai_privs)
741 return -1;
742 return 0;
743}

References a1, a2, and fb().

Referenced by aclitemsort().

◆ aclitemin()

Datum aclitemin ( PG_FUNCTION_ARGS  )

Definition at line 616 of file acl.c.

617{
618 const char *s = PG_GETARG_CSTRING(0);
619 Node *escontext = fcinfo->context;
620 AclItem *aip;
621
623
624 s = aclparse(s, aip, escontext);
625 if (s == NULL)
627
628 while (isspace((unsigned char) *s))
629 ++s;
630 if (*s)
631 ereturn(escontext, (Datum) 0,
633 errmsg("extra garbage at the end of the ACL specification")));
634
636}
static const char * aclparse(const char *s, AclItem *aip, Node *escontext)
Definition acl.c:274
#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 647 of file acl.c.

648{
650 char *p;
651 char *out;
652 HeapTuple htup;
653 unsigned i;
654
655 out = palloc(strlen("=/") +
656 2 * N_ACL_RIGHTS +
657 2 * (2 * NAMEDATALEN + 2) +
658 1);
659
660 p = out;
661 *p = '\0';
662
663 if (aip->ai_grantee != ACL_ID_PUBLIC)
664 {
665 htup = SearchSysCache1(AUTHOID, ObjectIdGetDatum(aip->ai_grantee));
666 if (HeapTupleIsValid(htup))
667 {
669 ReleaseSysCache(htup);
670 }
671 else
672 {
673 /* Generate numeric OID if we don't find an entry */
674 sprintf(p, "%u", aip->ai_grantee);
675 }
676 }
677 while (*p)
678 ++p;
679
680 *p++ = '=';
681
682 for (i = 0; i < N_ACL_RIGHTS; ++i)
683 {
684 if (ACLITEM_GET_PRIVS(*aip) & (UINT64CONST(1) << i))
685 *p++ = ACL_ALL_RIGHTS_STR[i];
686 if (ACLITEM_GET_GOPTIONS(*aip) & (UINT64CONST(1) << i))
687 *p++ = '*';
688 }
689
690 *p++ = '/';
691 *p = '\0';
692
693 htup = SearchSysCache1(AUTHOID, ObjectIdGetDatum(aip->ai_grantor));
694 if (HeapTupleIsValid(htup))
695 {
697 ReleaseSysCache(htup);
698 }
699 else
700 {
701 /* Generate numeric OID if we don't find an entry */
702 sprintf(p, "%u", aip->ai_grantor);
703 }
704
706}
static void putid(char *p, const char *s)
Definition acl.c:222
#define ACL_ALL_RIGHTS_STR
Definition acl.h:154
#define NameStr(name)
Definition c.h:765
#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
NameData rolname
Definition pg_authid.h:34
FormData_pg_authid * Form_pg_authid
Definition pg_authid.h:56
#define NAMEDATALEN
#define sprintf
Definition port.h:262
void ReleaseSysCache(HeapTuple tuple)
Definition syscache.c:264
HeapTuple SearchSysCache1(SysCacheIdentifier cacheId, Datum key1)
Definition syscache.c:220

References ACL_ALL_RIGHTS_STR, ACL_ID_PUBLIC, ACLITEM_GET_GOPTIONS, ACLITEM_GET_PRIVS, fb(), GETSTRUCT(), HeapTupleIsValid, i, 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 546 of file acl.c.

547{
548 if (acl != NULL && ACL_NUM(acl) > 1)
549 qsort(ACL_DAT(acl), ACL_NUM(acl), sizeof(AclItem), aclitemComparator);
550}
static int aclitemComparator(const void *arg1, const void *arg2)
Definition acl.c:725
#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 1389 of file acl.c.

1391{
1392 AclMode result;
1394 AclItem *aidat;
1395 int i,
1396 num;
1397
1398 /*
1399 * Null ACL should not happen, since caller should have inserted
1400 * appropriate default
1401 */
1402 if (acl == NULL)
1403 elog(ERROR, "null ACL");
1404
1405 check_acl(acl);
1406
1407 /* Quick exit for mask == 0 */
1408 if (mask == 0)
1409 return 0;
1410
1411 result = 0;
1412
1413 /* Owner always implicitly has all grant options */
1414 if ((mask & ACLITEM_ALL_GOPTION_BITS) &&
1415 has_privs_of_role(roleid, ownerId))
1416 {
1417 result = mask & ACLITEM_ALL_GOPTION_BITS;
1418 if ((how == ACLMASK_ALL) ? (result == mask) : (result != 0))
1419 return result;
1420 }
1421
1422 num = ACL_NUM(acl);
1423 aidat = ACL_DAT(acl);
1424
1425 /*
1426 * Check privileges granted directly to roleid or to public
1427 */
1428 for (i = 0; i < num; i++)
1429 {
1430 AclItem *aidata = &aidat[i];
1431
1432 if (aidata->ai_grantee == ACL_ID_PUBLIC ||
1433 aidata->ai_grantee == roleid)
1434 {
1435 result |= aidata->ai_privs & mask;
1436 if ((how == ACLMASK_ALL) ? (result == mask) : (result != 0))
1437 return result;
1438 }
1439 }
1440
1441 /*
1442 * Check privileges granted indirectly via role memberships. We do this in
1443 * a separate pass to minimize expensive indirect membership tests. In
1444 * particular, it's worth testing whether a given ACL entry grants any
1445 * privileges still of interest before we perform the has_privs_of_role
1446 * test.
1447 */
1448 remaining = mask & ~result;
1449 for (i = 0; i < num; i++)
1450 {
1451 AclItem *aidata = &aidat[i];
1452
1453 if (aidata->ai_grantee == ACL_ID_PUBLIC ||
1454 aidata->ai_grantee == roleid)
1455 continue; /* already checked it */
1456
1457 if ((aidata->ai_privs & remaining) &&
1458 has_privs_of_role(roleid, aidata->ai_grantee))
1459 {
1460 result |= aidata->ai_privs & mask;
1461 if ((how == ACLMASK_ALL) ? (result == mask) : (result != 0))
1462 return result;
1463 remaining = mask & ~result;
1464 }
1465 }
1466
1467 return result;
1468}
bool has_privs_of_role(Oid member, Oid role)
Definition acl.c:5286
#define ACLITEM_ALL_GOPTION_BITS
Definition acl.h:88
@ ACLMASK_ALL
Definition acl.h:176
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 1478 of file acl.c.

1480{
1481 AclMode result;
1482 AclItem *aidat;
1483 int i,
1484 num;
1485
1486 /*
1487 * Null ACL should not happen, since caller should have inserted
1488 * appropriate default
1489 */
1490 if (acl == NULL)
1491 elog(ERROR, "null ACL");
1492
1493 check_acl(acl);
1494
1495 /* Quick exit for mask == 0 */
1496 if (mask == 0)
1497 return 0;
1498
1499 result = 0;
1500
1501 /* Owner always implicitly has all grant options */
1502 if ((mask & ACLITEM_ALL_GOPTION_BITS) &&
1503 roleid == ownerId)
1504 {
1505 result = mask & ACLITEM_ALL_GOPTION_BITS;
1506 if ((how == ACLMASK_ALL) ? (result == mask) : (result != 0))
1507 return result;
1508 }
1509
1510 num = ACL_NUM(acl);
1511 aidat = ACL_DAT(acl);
1512
1513 /*
1514 * Check privileges granted directly to roleid (and not to public)
1515 */
1516 for (i = 0; i < num; i++)
1517 {
1518 AclItem *aidata = &aidat[i];
1519
1520 if (aidata->ai_grantee == roleid)
1521 {
1522 result |= aidata->ai_privs & mask;
1523 if ((how == ACLMASK_ALL) ? (result == mask) : (result != 0))
1524 return result;
1525 }
1526 }
1527
1528 return result;
1529}

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 1541 of file acl.c.

1542{
1543 Oid *list;
1544 const AclItem *acldat;
1545 int i,
1546 j;
1547
1548 if (acl == NULL || ACL_NUM(acl) == 0)
1549 {
1550 *roleids = NULL;
1551 return 0;
1552 }
1553
1554 check_acl(acl);
1555
1556 /* Allocate the worst-case space requirement */
1557 list = palloc(ACL_NUM(acl) * 2 * sizeof(Oid));
1558 acldat = ACL_DAT(acl);
1559
1560 /*
1561 * Walk the ACL collecting mentioned RoleIds.
1562 */
1563 j = 0;
1564 for (i = 0; i < ACL_NUM(acl); i++)
1565 {
1566 const AclItem *ai = &acldat[i];
1567
1568 if (ai->ai_grantee != ACL_ID_PUBLIC)
1569 list[j++] = ai->ai_grantee;
1570 /* grantor is currently never PUBLIC, but let's check anyway */
1571 if (ai->ai_grantor != ACL_ID_PUBLIC)
1572 list[j++] = ai->ai_grantor;
1573 }
1574
1575 /* Sort the array */
1576 qsort(list, j, sizeof(Oid), oid_cmp);
1577
1578 /*
1579 * We could repalloc the array down to minimum size, but it's hardly worth
1580 * it since it's only transient memory.
1581 */
1582 *roleids = list;
1583
1584 /* Remove duplicates from the array */
1585 return qunique(list, j, sizeof(Oid), oid_cmp);
1586}
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 502 of file acl.c.

503{
505 AclItem *aip;
506 int i,
507 num;
508
509 /* Check for cases where one or both are empty/null */
510 if (left_acl == NULL || ACL_NUM(left_acl) == 0)
511 {
512 if (right_acl == NULL || ACL_NUM(right_acl) == 0)
513 return NULL;
514 else
515 return aclcopy(right_acl);
516 }
517 else
518 {
519 if (right_acl == NULL || ACL_NUM(right_acl) == 0)
520 return aclcopy(left_acl);
521 }
522
523 /* Merge them the hard way, one item at a time */
525
527 num = ACL_NUM(right_acl);
528
529 for (i = 0; i < num; i++, aip++)
530 {
531 Acl *tmp_acl;
532
534 ownerId, DROP_RESTRICT);
537 }
538
539 return result_acl;
540}
Acl * aclupdate(const Acl *old_acl, const AclItem *mod_aip, int modechg, Oid ownerId, DropBehavior behavior)
Definition acl.c:993
Acl * aclcopy(const Acl *orig_acl)
Definition acl.c:458
#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 1120 of file acl.c.

1121{
1122 Acl *new_acl;
1128 bool newpresent = false;
1129 int dst,
1130 src,
1131 targ,
1132 num;
1133
1135
1136 /*
1137 * Make a copy of the given ACL, substituting new owner ID for old
1138 * wherever it appears as either grantor or grantee. Also note if the new
1139 * owner ID is already present.
1140 */
1141 num = ACL_NUM(old_acl);
1143 new_acl = allocacl(num);
1145 memcpy(new_aip, old_aip, num * sizeof(AclItem));
1146 for (dst = 0, dst_aip = new_aip; dst < num; dst++, dst_aip++)
1147 {
1148 if (dst_aip->ai_grantor == oldOwnerId)
1149 dst_aip->ai_grantor = newOwnerId;
1150 else if (dst_aip->ai_grantor == newOwnerId)
1151 newpresent = true;
1152 if (dst_aip->ai_grantee == oldOwnerId)
1153 dst_aip->ai_grantee = newOwnerId;
1154 else if (dst_aip->ai_grantee == newOwnerId)
1155 newpresent = true;
1156 }
1157
1158 /*
1159 * If the old ACL contained any references to the new owner, then we may
1160 * now have generated an ACL containing duplicate entries. Find them and
1161 * merge them so that there are not duplicates. (This is relatively
1162 * expensive since we use a stupid O(N^2) algorithm, but it's unlikely to
1163 * be the normal case.)
1164 *
1165 * To simplify deletion of duplicate entries, we temporarily leave them in
1166 * the array but set their privilege masks to zero; when we reach such an
1167 * entry it's just skipped. (Thus, a side effect of this code will be to
1168 * remove privilege-free entries, should there be any in the input.) dst
1169 * is the next output slot, targ is the currently considered input slot
1170 * (always >= dst), and src scans entries to the right of targ looking for
1171 * duplicates. Once an entry has been emitted to dst it is known
1172 * duplicate-free and need not be considered anymore.
1173 */
1174 if (newpresent)
1175 {
1176 dst = 0;
1177 for (targ = 0, targ_aip = new_aip; targ < num; targ++, targ_aip++)
1178 {
1179 /* ignore if deleted in an earlier pass */
1181 continue;
1182 /* find and merge any duplicates */
1183 for (src = targ + 1, src_aip = targ_aip + 1; src < num;
1184 src++, src_aip++)
1185 {
1187 continue;
1189 {
1193 /* mark the duplicate deleted */
1195 }
1196 }
1197 /* and emit to output */
1198 new_aip[dst] = *targ_aip;
1199 dst++;
1200 }
1201 /* Adjust array size to be 'dst' items */
1202 ARR_DIMS(new_acl)[0] = dst;
1204 }
1205
1206 return new_acl;
1207}
static bool aclitem_match(const AclItem *a1, const AclItem *a2)
Definition acl.c:714
#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 274 of file acl.c.

275{
277 goption,
278 read;
279 char name[NAMEDATALEN];
280 char name2[NAMEDATALEN];
281
282 Assert(s && aip);
283
284 s = getid(s, name, escontext);
285 if (s == NULL)
286 return NULL;
287 if (*s != '=')
288 {
289 /* we just read a keyword, not a name */
290 if (strcmp(name, "group") != 0 && strcmp(name, "user") != 0)
291 ereturn(escontext, NULL,
293 errmsg("unrecognized key word: \"%s\"", name),
294 errhint("ACL key word must be \"group\" or \"user\".")));
295 /* move s to the name beyond the keyword */
296 s = getid(s, name, escontext);
297 if (s == NULL)
298 return NULL;
299 if (name[0] == '\0')
300 ereturn(escontext, NULL,
302 errmsg("missing name"),
303 errhint("A name must follow the \"group\" or \"user\" key word.")));
304 }
305
306 if (*s != '=')
307 ereturn(escontext, NULL,
309 errmsg("missing \"=\" sign")));
310
312
313 for (++s, read = 0; isalpha((unsigned char) *s) || *s == '*'; s++)
314 {
315 switch (*s)
316 {
317 case '*':
318 goption |= read;
319 break;
320 case ACL_INSERT_CHR:
322 break;
323 case ACL_SELECT_CHR:
325 break;
326 case ACL_UPDATE_CHR:
328 break;
329 case ACL_DELETE_CHR:
331 break;
332 case ACL_TRUNCATE_CHR:
334 break;
337 break;
338 case ACL_TRIGGER_CHR:
340 break;
341 case ACL_EXECUTE_CHR:
343 break;
344 case ACL_USAGE_CHR:
345 read = ACL_USAGE;
346 break;
347 case ACL_CREATE_CHR:
349 break;
352 break;
353 case ACL_CONNECT_CHR:
355 break;
356 case ACL_SET_CHR:
357 read = ACL_SET;
358 break;
361 break;
362 case ACL_MAINTAIN_CHR:
364 break;
365 default:
366 ereturn(escontext, NULL,
368 errmsg("invalid mode character: must be one of \"%s\"",
370 }
371
372 privs |= read;
373 }
374
375 if (name[0] == '\0')
376 aip->ai_grantee = ACL_ID_PUBLIC;
377 else
378 {
379 aip->ai_grantee = get_role_oid(name, true);
380 if (!OidIsValid(aip->ai_grantee))
381 ereturn(escontext, NULL,
383 errmsg("role \"%s\" does not exist", name)));
384 }
385
386 /*
387 * XXX Allow a degree of backward compatibility by defaulting the grantor
388 * to the superuser.
389 */
390 if (*s == '/')
391 {
392 s = getid(s + 1, name2, escontext);
393 if (s == NULL)
394 return NULL;
395 if (name2[0] == '\0')
396 ereturn(escontext, NULL,
398 errmsg("a name must follow the \"/\" sign")));
399 aip->ai_grantor = get_role_oid(name2, true);
400 if (!OidIsValid(aip->ai_grantor))
401 ereturn(escontext, NULL,
403 errmsg("role \"%s\" does not exist", name2)));
404 }
405 else
406 {
407 aip->ai_grantor = BOOTSTRAP_SUPERUSERID;
410 errmsg("defaulting grantor to user ID %u",
412 }
413
415
416 return s;
417}
static const char * getid(const char *s, char *n, Node *escontext)
Definition acl.c:169
Oid get_role_oid(const char *rolname, bool missing_ok)
Definition acl.c:5554
#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
#define Assert(condition)
Definition c.h:873
#define OidIsValid(objectId)
Definition c.h:788
int errhint(const char *fmt,...)
Definition elog.c:1331
#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, ereport, ereturn, errcode(), errhint(), errmsg(), fb(), get_role_oid(), getid(), name, NAMEDATALEN, OidIsValid, read, and WARNING.

Referenced by aclitemin().

◆ aclremove()

Datum aclremove ( PG_FUNCTION_ARGS  )

Definition at line 1603 of file acl.c.

1604{
1605 ereport(ERROR,
1607 errmsg("aclremove is no longer supported")));
1608
1609 PG_RETURN_NULL(); /* keep compiler quiet */
1610}

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 993 of file acl.c.

995{
996 Acl *new_acl = NULL;
998 *new_aip = NULL;
1001 new_rights,
1003 int dst,
1004 num;
1005
1006 /* Caller probably already checked old_acl, but be safe */
1008
1009 /* If granting grant options, check for circularity */
1010 if (modechg != ACL_MODECHG_DEL &&
1013
1014 num = ACL_NUM(old_acl);
1016
1017 /*
1018 * Search the ACL for an existing entry for this grantee and grantor. If
1019 * one exists, just modify the entry in-place (well, in the same position,
1020 * since we actually return a copy); otherwise, insert the new entry at
1021 * the end.
1022 */
1023
1024 for (dst = 0; dst < num; ++dst)
1025 {
1027 {
1028 /* found a match, so modify existing item */
1029 new_acl = allocacl(num);
1032 break;
1033 }
1034 }
1035
1036 if (dst == num)
1037 {
1038 /* need to append a new item */
1039 new_acl = allocacl(num + 1);
1041 memcpy(new_aip, old_aip, num * sizeof(AclItem));
1042
1043 /* initialize the new entry with no permissions */
1044 new_aip[dst].ai_grantee = mod_aip->ai_grantee;
1045 new_aip[dst].ai_grantor = mod_aip->ai_grantor;
1048 num++; /* set num to the size of new_acl */
1049 }
1050
1053
1054 /* apply the specified permissions change */
1055 switch (modechg)
1056 {
1057 case ACL_MODECHG_ADD:
1060 break;
1061 case ACL_MODECHG_DEL:
1064 break;
1065 case ACL_MODECHG_EQL:
1068 break;
1069 }
1070
1073
1074 /*
1075 * If the adjusted entry has no permissions, delete it from the list.
1076 */
1078 {
1080 new_aip + dst + 1,
1081 (num - dst - 1) * sizeof(AclItem));
1082 /* Adjust array size to be 'num - 1' items */
1083 ARR_DIMS(new_acl)[0] = num - 1;
1084 SET_VARSIZE(new_acl, ACL_N_SIZE(num - 1));
1085 }
1086
1087 /*
1088 * Remove abandoned privileges (cascading revoke). Currently we can only
1089 * handle this when the grantee is not PUBLIC.
1090 */
1091 if ((old_goptions & ~new_goptions) != 0)
1092 {
1093 Assert(mod_aip->ai_grantee != ACL_ID_PUBLIC);
1094 new_acl = recursive_revoke(new_acl, mod_aip->ai_grantee,
1096 ownerId, behavior);
1097 }
1098
1099 return new_acl;
1100}
static Acl * recursive_revoke(Acl *acl, Oid grantee, AclMode revoke_privs, Oid ownerId, DropBehavior behavior)
Definition acl.c:1303
static void check_circularity(const Acl *old_acl, const AclItem *mod_aip, Oid ownerId)
Definition acl.c:1223
#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 427 of file acl.c.

428{
429 Acl *new_acl;
430 Size size;
431
432 if (n < 0)
433 elog(ERROR, "invalid size: %d", n);
434 size = ACL_N_SIZE(n);
435 new_acl = (Acl *) palloc0(size);
436 SET_VARSIZE(new_acl, size);
437 new_acl->ndim = 1;
438 new_acl->dataoffset = 0; /* we never put in any nulls */
439 new_acl->elemtype = ACLITEMOID;
440 ARR_LBOUND(new_acl)[0] = 1;
441 ARR_DIMS(new_acl)[0] = n;
442 return new_acl;
443}
#define ARR_LBOUND(a)
Definition array.h:296
size_t Size
Definition c.h:619
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 591 of file acl.c.

592{
593 if (ARR_ELEMTYPE(acl) != ACLITEMOID)
596 errmsg("ACL array contains wrong data type")));
597 if (ARR_NDIM(acl) != 1)
600 errmsg("ACL arrays must be one-dimensional")));
601 if (ARR_HASNULL(acl))
604 errmsg("ACL arrays must not contain null values")));
605}
#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 5343 of file acl.c.

5344{
5345 if (!member_can_set_role(member, role))
5346 ereport(ERROR,
5348 errmsg("must be able to SET ROLE \"%s\"",
5349 GetUserNameFromId(role, false))));
5350}
bool member_can_set_role(Oid member, Oid role)
Definition acl.c:5320
char * GetUserNameFromId(Oid roleid, bool noerr)
Definition miscinit.c:988

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 1223 of file acl.c.

1225{
1226 Acl *acl;
1227 AclItem *aip;
1228 int i,
1229 num;
1231
1233
1234 /*
1235 * For now, grant options can only be granted to roles, not PUBLIC.
1236 * Otherwise we'd have to work a bit harder here.
1237 */
1238 Assert(mod_aip->ai_grantee != ACL_ID_PUBLIC);
1239
1240 /* The owner always has grant options, no need to check */
1241 if (mod_aip->ai_grantor == ownerId)
1242 return;
1243
1244 /* Make a working copy */
1245 acl = allocacl(ACL_NUM(old_acl));
1247
1248 /* Zap all grant options of target grantee, plus what depends on 'em */
1250 num = ACL_NUM(acl);
1251 aip = ACL_DAT(acl);
1252 for (i = 0; i < num; i++)
1253 {
1254 if (aip[i].ai_grantee == mod_aip->ai_grantee &&
1256 {
1257 Acl *new_acl;
1258
1259 /* We'll actually zap ordinary privs too, but no matter */
1261 ownerId, DROP_CASCADE);
1262
1263 pfree(acl);
1264 acl = new_acl;
1265
1266 goto cc_restart;
1267 }
1268 }
1269
1270 /* Now we can compute grantor's independently-derived privileges */
1271 own_privs = aclmask(acl,
1272 mod_aip->ai_grantor,
1273 ownerId,
1275 ACLMASK_ALL);
1277
1278 if ((ACLITEM_GET_GOPTIONS(*mod_aip) & ~own_privs) != 0)
1279 ereport(ERROR,
1281 errmsg("grant options cannot be granted back to your own grantor")));
1282
1283 pfree(acl);
1284}
AclMode aclmask(const Acl *acl, Oid roleid, Oid ownerId, AclMode mask, AclMaskHow how)
Definition acl.c:1389
#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 5695 of file acl.c.

5696{
5697 if (!role)
5698 return;
5699
5700 if (role->roletype != ROLESPEC_CSTRING)
5701 return;
5702
5703 if (IsReservedName(role->rolename))
5704 {
5705 if (detail_msg)
5706 ereport(ERROR,
5708 errmsg("role name \"%s\" is reserved",
5709 role->rolename),
5711 else
5712 ereport(ERROR,
5714 errmsg("role name \"%s\" is reserved",
5715 role->rolename)));
5716 }
5717}
bool IsReservedName(const char *name)
Definition catalog.c:278
int errdetail_internal(const char *fmt,...)
Definition elog.c:1244
@ 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 2536 of file acl.c.

2538{
2540 bool is_missing = false;
2541
2542 /*
2543 * If convert_column_name failed, we can just return -1 immediately.
2544 */
2546 return -1;
2547
2548 /*
2549 * Check for column-level privileges first. This serves in part as a check
2550 * on whether the column even exists, so we need to do it before checking
2551 * table-level privilege.
2552 */
2553 aclresult = pg_attribute_aclcheck_ext(tableoid, attnum, roleid,
2554 mode, &is_missing);
2555 if (aclresult == ACLCHECK_OK)
2556 return 1;
2557 else if (is_missing)
2558 return -1;
2559
2560 /* Next check if we have the privilege at the table level */
2561 aclresult = pg_class_aclcheck_ext(tableoid, roleid, mode, &is_missing);
2562 if (aclresult == ACLCHECK_OK)
2563 return 1;
2564 else if (is_missing)
2565 return -1;
2566 else
2567 return 0;
2568}
AclResult
Definition acl.h:182
@ ACLCHECK_OK
Definition acl.h:183
AclResult pg_class_aclcheck_ext(Oid table_oid, Oid roleid, AclMode mode, bool *is_missing)
Definition aclchk.c:4049
AclResult pg_attribute_aclcheck_ext(Oid table_oid, AttrNumber attnum, Oid roleid, AclMode mode, bool *is_missing)
Definition aclchk.c:3880
#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 1735 of file acl.c.

1736{
1737 switch (aclright)
1738 {
1739 case ACL_INSERT:
1740 return "INSERT";
1741 case ACL_SELECT:
1742 return "SELECT";
1743 case ACL_UPDATE:
1744 return "UPDATE";
1745 case ACL_DELETE:
1746 return "DELETE";
1747 case ACL_TRUNCATE:
1748 return "TRUNCATE";
1749 case ACL_REFERENCES:
1750 return "REFERENCES";
1751 case ACL_TRIGGER:
1752 return "TRIGGER";
1753 case ACL_EXECUTE:
1754 return "EXECUTE";
1755 case ACL_USAGE:
1756 return "USAGE";
1757 case ACL_CREATE:
1758 return "CREATE";
1759 case ACL_CREATE_TEMP:
1760 return "TEMPORARY";
1761 case ACL_CONNECT:
1762 return "CONNECT";
1763 case ACL_SET:
1764 return "SET";
1765 case ACL_ALTER_SYSTEM:
1766 return "ALTER SYSTEM";
1767 case ACL_MAINTAIN:
1768 return "MAINTAIN";
1769 default:
1770 elog(ERROR, "unrecognized aclright: %d", aclright);
1771 return NULL;
1772 }
1773}

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 1687 of file acl.c.

1689{
1690 AclMode result = 0;
1692 char *chunk;
1693 char *next_chunk;
1694
1695 /* We rely on priv_type being a private, modifiable string */
1697 {
1698 int chunk_len;
1699 const priv_map *this_priv;
1700
1701 /* Split string at commas */
1702 next_chunk = strchr(chunk, ',');
1703 if (next_chunk)
1704 *next_chunk++ = '\0';
1705
1706 /* Drop leading/trailing whitespace in this chunk */
1707 while (*chunk && isspace((unsigned char) *chunk))
1708 chunk++;
1710 while (chunk_len > 0 && isspace((unsigned char) chunk[chunk_len - 1]))
1711 chunk_len--;
1712 chunk[chunk_len] = '\0';
1713
1714 /* Match to the privileges list */
1715 for (this_priv = privileges; this_priv->name; this_priv++)
1716 {
1717 if (pg_strcasecmp(this_priv->name, chunk) == 0)
1718 {
1719 result |= this_priv->value;
1720 break;
1721 }
1722 }
1723 if (!this_priv->name)
1724 ereport(ERROR,
1726 errmsg("unrecognized privilege type: \"%s\"", chunk)));
1727 }
1728
1730 return result;
1731}
int pg_strcasecmp(const char *s1, const char *s2)
Definition acl.c:55
char * text_to_cstring(const text *t)
Definition varlena.c:215

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 2896 of file acl.c.

2897{
2898 char *colname;
2901
2902 colname = text_to_cstring(column);
2903
2904 /*
2905 * We don't use get_attnum() here because it will report that dropped
2906 * columns don't exist. We need to treat dropped columns differently from
2907 * nonexistent columns.
2908 */
2910 ObjectIdGetDatum(tableoid),
2911 CStringGetDatum(colname));
2913 {
2915
2917 /* We want to return NULL for dropped columns */
2918 if (attributeForm->attisdropped)
2920 else
2921 attnum = attributeForm->attnum;
2923 }
2924 else
2925 {
2926 char *tablename = get_rel_name(tableoid);
2927
2928 /*
2929 * If the table OID is bogus, or it's just been dropped, we'll get
2930 * NULL back. In such cases we want has_column_privilege to return
2931 * NULL too, so just return InvalidAttrNumber.
2932 */
2933 if (tablename != NULL)
2934 {
2935 /* tableoid exists, colname does not, so throw error */
2936 ereport(ERROR,
2938 errmsg("column \"%s\" of relation \"%s\" does not exist",
2939 colname, tablename)));
2940 }
2941 /* tableoid doesn't exist, so act like attisdropped case */
2943 }
2944
2945 pfree(colname);
2946 return attnum;
2947}
char * get_rel_name(Oid relid)
Definition lsyscache.c:2078
FormData_pg_attribute * Form_pg_attribute
static Datum CStringGetDatum(const char *X)
Definition postgres.h:380
HeapTuple SearchSysCache2(SysCacheIdentifier cacheId, Datum key1, Datum key2)
Definition syscache.c:230

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 2954 of file acl.c.

2955{
2956 static const priv_map column_priv_map[] = {
2957 {"SELECT", ACL_SELECT},
2958 {"SELECT WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_SELECT)},
2959 {"INSERT", ACL_INSERT},
2960 {"INSERT WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_INSERT)},
2961 {"UPDATE", ACL_UPDATE},
2962 {"UPDATE WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_UPDATE)},
2963 {"REFERENCES", ACL_REFERENCES},
2964 {"REFERENCES WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_REFERENCES)},
2965 {NULL, 0}
2966 };
2967
2969}
static AclMode convert_any_priv_string(text *priv_type_text, const priv_map *privileges)
Definition acl.c:1687

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 3148 of file acl.c.

3149{
3151
3152 return get_database_oid(dbname, false);
3153}
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 3160 of file acl.c.

3161{
3162 static const priv_map database_priv_map[] = {
3163 {"CREATE", ACL_CREATE},
3164 {"CREATE WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_CREATE)},
3165 {"TEMPORARY", ACL_CREATE_TEMP},
3166 {"TEMPORARY WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_CREATE_TEMP)},
3167 {"TEMP", ACL_CREATE_TEMP},
3168 {"TEMP WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_CREATE_TEMP)},
3169 {"CONNECT", ACL_CONNECT},
3170 {"CONNECT WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_CONNECT)},
3171 {NULL, 0}
3172 };
3173
3175}

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 3354 of file acl.c.

3355{
3356 char *fdwstr = text_to_cstring(fdwname);
3357
3358 return get_foreign_data_wrapper_oid(fdwstr, false);
3359}
Oid get_foreign_data_wrapper_oid(const char *fdwname, bool missing_ok)
Definition foreign.c:682

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 3554 of file acl.c.

3555{
3557 Oid oid;
3558
3561
3562 if (!OidIsValid(oid))
3563 ereport(ERROR,
3565 errmsg("function \"%s\" does not exist", funcname)));
3566
3567 return oid;
3568}
#define DirectFunctionCall1(func, arg1)
Definition fmgr.h:684
#define funcname
static Oid DatumGetObjectId(Datum X)
Definition postgres.h:252
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 3763 of file acl.c.

3764{
3765 char *langname = text_to_cstring(languagename);
3766
3767 return get_language_oid(langname, false);
3768}
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 4810 of file acl.c.

4811{
4812 static const priv_map largeobject_priv_map[] = {
4813 {"SELECT", ACL_SELECT},
4814 {"SELECT WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_SELECT)},
4815 {"UPDATE", ACL_UPDATE},
4816 {"UPDATE WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_UPDATE)},
4817 {NULL, 0}
4818 };
4819
4821}

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 4674 of file acl.c.

4675{
4676 static const priv_map parameter_priv_map[] = {
4677 {"SET", ACL_SET},
4678 {"SET WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_SET)},
4679 {"ALTER SYSTEM", ACL_ALTER_SYSTEM},
4680 {"ALTER SYSTEM WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_ALTER_SYSTEM)},
4681 {NULL, 0}
4682 };
4683
4685}

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 4988 of file acl.c.

4989{
4990 static const priv_map role_priv_map[] = {
4991 {"USAGE", ACL_USAGE},
4992 {"MEMBER", ACL_CREATE},
4993 {"SET", ACL_SET},
4994 {"USAGE WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_CREATE)},
4995 {"USAGE WITH ADMIN OPTION", ACL_GRANT_OPTION_FOR(ACL_CREATE)},
4996 {"MEMBER WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_CREATE)},
4997 {"MEMBER WITH ADMIN OPTION", ACL_GRANT_OPTION_FOR(ACL_CREATE)},
4998 {"SET WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_CREATE)},
4999 {"SET WITH ADMIN OPTION", ACL_GRANT_OPTION_FOR(ACL_CREATE)},
5000 {NULL, 0}
5001 };
5002
5004}

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 3963 of file acl.c.

3964{
3965 char *nspname = text_to_cstring(schemaname);
3966
3967 return get_namespace_oid(nspname, false);
3968}
Oid get_namespace_oid(const char *nspname, bool missing_ok)
Definition namespace.c:3606

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 3975 of file acl.c.

3976{
3977 static const priv_map schema_priv_map[] = {
3978 {"CREATE", ACL_CREATE},
3979 {"CREATE WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_CREATE)},
3980 {"USAGE", ACL_USAGE},
3981 {"USAGE WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_USAGE)},
3982 {NULL, 0}
3983 };
3984
3986}

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 2299 of file acl.c.

2300{
2301 static const priv_map sequence_priv_map[] = {
2302 {"USAGE", ACL_USAGE},
2303 {"USAGE WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_USAGE)},
2304 {"SELECT", ACL_SELECT},
2305 {"SELECT WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_SELECT)},
2306 {"UPDATE", ACL_UPDATE},
2307 {"UPDATE WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_UPDATE)},
2308 {NULL, 0}
2309 };
2310
2312}

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 4165 of file acl.c.

4166{
4167 char *serverstr = text_to_cstring(servername);
4168
4169 return get_foreign_server_oid(serverstr, false);
4170}
Oid get_foreign_server_oid(const char *servername, bool missing_ok)
Definition foreign.c:705

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 2064 of file acl.c.

2065{
2066 static const priv_map table_priv_map[] = {
2067 {"SELECT", ACL_SELECT},
2068 {"SELECT WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_SELECT)},
2069 {"INSERT", ACL_INSERT},
2070 {"INSERT WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_INSERT)},
2071 {"UPDATE", ACL_UPDATE},
2072 {"UPDATE WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_UPDATE)},
2073 {"DELETE", ACL_DELETE},
2074 {"DELETE WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_DELETE)},
2075 {"TRUNCATE", ACL_TRUNCATE},
2076 {"TRUNCATE WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_TRUNCATE)},
2077 {"REFERENCES", ACL_REFERENCES},
2078 {"REFERENCES WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_REFERENCES)},
2079 {"TRIGGER", ACL_TRIGGER},
2080 {"TRIGGER WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_TRIGGER)},
2081 {"MAINTAIN", ACL_MAINTAIN},
2082 {"MAINTAIN WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_MAINTAIN)},
2083 {NULL, 0}
2084 };
2085
2087}

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 4365 of file acl.c.

4366{
4367 char *spcname = text_to_cstring(tablespacename);
4368
4369 return get_tablespace_oid(spcname, false);
4370}
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 4564 of file acl.c.

4565{
4566 char *typname = text_to_cstring(typename);
4567 Oid oid;
4568
4571
4572 if (!OidIsValid(oid))
4573 ereport(ERROR,
4575 errmsg("type \"%s\" does not exist", typname)));
4576
4577 return oid;
4578}
NameData typname
Definition pg_type.h:41
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 5673 of file acl.c.

5674{
5675 HeapTuple tp;
5677 char *rolename;
5678
5679 tp = get_rolespec_tuple(role);
5681 rolename = pstrdup(NameStr(authForm->rolname));
5682 ReleaseSysCache(tp);
5683
5684 return rolename;
5685}
HeapTuple get_rolespec_tuple(const RoleSpec *role)
Definition acl.c:5627
char * pstrdup(const char *in)
Definition mcxt.c:1781

References fb(), 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 5588 of file acl.c.

5589{
5590 Oid oid;
5591
5592 switch (role->roletype)
5593 {
5594 case ROLESPEC_CSTRING:
5595 Assert(role->rolename);
5596 oid = get_role_oid(role->rolename, missing_ok);
5597 break;
5598
5601 oid = GetUserId();
5602 break;
5603
5605 oid = GetSessionUserId();
5606 break;
5607
5608 case ROLESPEC_PUBLIC:
5609 ereport(ERROR,
5611 errmsg("role \"%s\" does not exist", "public")));
5612 oid = InvalidOid; /* make compiler happy */
5613 break;
5614
5615 default:
5616 elog(ERROR, "unexpected role type %d", role->roletype);
5617 }
5618
5619 return oid;
5620}
Oid GetUserId(void)
Definition miscinit.c:469
Oid GetSessionUserId(void)
Definition miscinit.c:508
@ 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(), and roleSpecsToIds().

◆ get_rolespec_tuple()

HeapTuple get_rolespec_tuple ( const RoleSpec role)

Definition at line 5627 of file acl.c.

5628{
5629 HeapTuple tuple;
5630
5631 switch (role->roletype)
5632 {
5633 case ROLESPEC_CSTRING:
5634 Assert(role->rolename);
5636 if (!HeapTupleIsValid(tuple))
5637 ereport(ERROR,
5639 errmsg("role \"%s\" does not exist", role->rolename)));
5640 break;
5641
5645 if (!HeapTupleIsValid(tuple))
5646 elog(ERROR, "cache lookup failed for role %u", GetUserId());
5647 break;
5648
5651 if (!HeapTupleIsValid(tuple))
5652 elog(ERROR, "cache lookup failed for role %u", GetSessionUserId());
5653 break;
5654
5655 case ROLESPEC_PUBLIC:
5656 ereport(ERROR,
5658 errmsg("role \"%s\" does not exist", "public")));
5659 tuple = NULL; /* make compiler happy */
5660 break;
5661
5662 default:
5663 elog(ERROR, "unexpected role type %d", role->roletype);
5664 }
5665
5666 return tuple;
5667}

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 169 of file acl.c.

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

2426{
2427 Oid tableoid = PG_GETARG_OID(0);
2429 Oid roleid;
2430 AclMode mode;
2432 bool is_missing = false;
2433
2434 roleid = GetUserId();
2436
2437 /* First check at table level, then examine each column if needed */
2438 aclresult = pg_class_aclcheck_ext(tableoid, roleid, mode, &is_missing);
2439 if (aclresult != ACLCHECK_OK)
2440 {
2441 if (is_missing)
2443 aclresult = pg_attribute_aclcheck_all_ext(tableoid, roleid, mode,
2445 if (is_missing)
2447 }
2448
2450}
static AclMode convert_column_priv_string(text *priv_type_text)
Definition acl.c:2954
@ ACLMASK_ANY
Definition acl.h:177
AclResult pg_attribute_aclcheck_all_ext(Oid table_oid, Oid roleid, AclMode mode, AclMaskHow how, bool *is_missing)
Definition aclchk.c:3921
#define PG_GETARG_TEXT_PP(n)
Definition fmgr.h:310
Definition c.h:706

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 2485 of file acl.c.

2486{
2487 Oid roleid = PG_GETARG_OID(0);
2488 Oid tableoid = PG_GETARG_OID(1);
2490 AclMode mode;
2492 bool is_missing = false;
2493
2495
2496 /* First check at table level, then examine each column if needed */
2497 aclresult = pg_class_aclcheck_ext(tableoid, roleid, mode, &is_missing);
2498 if (aclresult != ACLCHECK_OK)
2499 {
2500 if (is_missing)
2502 aclresult = pg_attribute_aclcheck_all_ext(tableoid, roleid, mode,
2504 if (is_missing)
2506 }
2507
2509}

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 2458 of file acl.c.

2459{
2460 Oid roleid = PG_GETARG_OID(0);
2461 text *tablename = PG_GETARG_TEXT_PP(1);
2463 Oid tableoid;
2464 AclMode mode;
2466
2467 tableoid = convert_table_name(tablename);
2469
2470 /* First check at table level, then examine each column if needed */
2471 aclresult = pg_class_aclcheck(tableoid, roleid, mode);
2472 if (aclresult != ACLCHECK_OK)
2473 aclresult = pg_attribute_aclcheck_all(tableoid, roleid, mode,
2474 ACLMASK_ANY);
2475
2477}
static Oid convert_table_name(text *tablename)
Definition acl.c:2049
AclResult pg_attribute_aclcheck_all(Oid table_oid, Oid roleid, AclMode mode, AclMaskHow how)
Definition aclchk.c:3910
AclResult pg_class_aclcheck(Oid table_oid, Oid roleid, AclMode mode)
Definition aclchk.c:4039

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 2362 of file acl.c.

2363{
2364 text *tablename = PG_GETARG_TEXT_PP(0);
2366 Oid roleid;
2367 Oid tableoid;
2368 AclMode mode;
2370
2371 roleid = GetUserId();
2372 tableoid = convert_table_name(tablename);
2374
2375 /* First check at table level, then examine each column if needed */
2376 aclresult = pg_class_aclcheck(tableoid, roleid, mode);
2377 if (aclresult != ACLCHECK_OK)
2378 aclresult = pg_attribute_aclcheck_all(tableoid, roleid, mode,
2379 ACLMASK_ANY);
2380
2382}

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 2390 of file acl.c.

2391{
2393 Oid tableoid = PG_GETARG_OID(1);
2395 Oid roleid;
2396 AclMode mode;
2398 bool is_missing = false;
2399
2402
2403 /* First check at table level, then examine each column if needed */
2404 aclresult = pg_class_aclcheck_ext(tableoid, roleid, mode, &is_missing);
2405 if (aclresult != ACLCHECK_OK)
2406 {
2407 if (is_missing)
2409 aclresult = pg_attribute_aclcheck_all_ext(tableoid, roleid, mode,
2411 if (is_missing)
2413 }
2414
2416}
Oid get_role_oid_or_public(const char *rolname)
Definition acl.c:5572
#define PG_GETARG_NAME(n)
Definition fmgr.h:279
static char * username
Definition initdb.c:153
Definition c.h:760

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 2332 of file acl.c.

2333{
2334 Name rolename = PG_GETARG_NAME(0);
2335 text *tablename = PG_GETARG_TEXT_PP(1);
2337 Oid roleid;
2338 Oid tableoid;
2339 AclMode mode;
2341
2342 roleid = get_role_oid_or_public(NameStr(*rolename));
2343 tableoid = convert_table_name(tablename);
2345
2346 /* First check at table level, then examine each column if needed */
2347 aclresult = pg_class_aclcheck(tableoid, roleid, mode);
2348 if (aclresult != ACLCHECK_OK)
2349 aclresult = pg_attribute_aclcheck_all(tableoid, roleid, mode,
2350 ACLMASK_ANY);
2351
2353}

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 2868 of file acl.c.

2869{
2870 Oid tableoid = PG_GETARG_OID(0);
2873 Oid roleid;
2874 AclMode mode;
2875 int privresult;
2876
2877 roleid = GetUserId();
2879
2880 privresult = column_privilege_check(tableoid, colattnum, roleid, mode);
2881 if (privresult < 0)
2884}
static int column_privilege_check(Oid tableoid, AttrNumber attnum, Oid roleid, AclMode mode)
Definition acl.c:2536
#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 2736 of file acl.c.

2737{
2738 Oid roleid = PG_GETARG_OID(0);
2739 Oid tableoid = PG_GETARG_OID(1);
2743 AclMode mode;
2744 int privresult;
2745
2748
2749 privresult = column_privilege_check(tableoid, colattnum, roleid, mode);
2750 if (privresult < 0)
2753}
static AttrNumber convert_column_name(Oid tableoid, text *column)
Definition acl.c:2896

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 2711 of file acl.c.

2712{
2713 Oid roleid = PG_GETARG_OID(0);
2714 text *tablename = PG_GETARG_TEXT_PP(1);
2717 Oid tableoid;
2718 AclMode mode;
2719 int privresult;
2720
2721 tableoid = convert_table_name(tablename);
2723
2724 privresult = column_privilege_check(tableoid, colattnum, roleid, mode);
2725 if (privresult < 0)
2728}

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 2684 of file acl.c.

2685{
2686 Oid roleid = PG_GETARG_OID(0);
2687 text *tablename = PG_GETARG_TEXT_PP(1);
2690 Oid tableoid;
2692 AclMode mode;
2693 int privresult;
2694
2695 tableoid = convert_table_name(tablename);
2698
2699 privresult = column_privilege_check(tableoid, colattnum, roleid, mode);
2700 if (privresult < 0)
2703}

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 2814 of file acl.c.

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

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 2785 of file acl.c.

2786{
2787 text *tablename = PG_GETARG_TEXT_PP(0);
2790 Oid roleid;
2791 Oid tableoid;
2793 AclMode mode;
2794 int privresult;
2795
2796 roleid = GetUserId();
2797 tableoid = convert_table_name(tablename);
2800
2801 privresult = column_privilege_check(tableoid, colattnum, roleid, mode);
2802 if (privresult < 0)
2805}

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 2605 of file acl.c.

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

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 2576 of file acl.c.

2577{
2578 Name rolename = PG_GETARG_NAME(0);
2579 text *tablename = PG_GETARG_TEXT_PP(1);
2582 Oid roleid;
2583 Oid tableoid;
2585 AclMode mode;
2586 int privresult;
2587
2588 roleid = get_role_oid_or_public(NameStr(*rolename));
2589 tableoid = convert_table_name(tablename);
2592
2593 privresult = column_privilege_check(tableoid, colattnum, roleid, mode);
2594 if (privresult < 0)
2597}

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 3068 of file acl.c.

3069{
3072 Oid roleid;
3073 AclMode mode;
3075 bool is_missing = false;
3076
3077 roleid = GetUserId();
3079
3081 roleid, mode,
3082 &is_missing);
3083
3084 if (is_missing)
3086
3088}
static AclMode convert_database_priv_string(text *priv_type_text)
Definition acl.c:3160
AclResult object_aclcheck_ext(Oid classid, Oid objectid, Oid roleid, AclMode mode, bool *is_missing)
Definition aclchk.c:3846

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 3096 of file acl.c.

3097{
3098 Oid roleid = PG_GETARG_OID(0);
3102 AclMode mode;
3104
3107
3109
3111}
static Oid convert_database_name(text *databasename)
Definition acl.c:3148
AclResult object_aclcheck(Oid classid, Oid objectid, Oid roleid, AclMode mode)
Definition aclchk.c:3836

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 3274 of file acl.c.

3275{
3276 Oid fdwid = PG_GETARG_OID(0);
3278 Oid roleid;
3279 AclMode mode;
3281 bool is_missing = false;
3282
3283 roleid = GetUserId();
3285
3287 roleid, mode,
3288 &is_missing);
3289
3290 if (is_missing)
3292
3294}
static AclMode convert_foreign_data_wrapper_priv_string(text *priv_type_text)
Definition acl.c:3366

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 3474 of file acl.c.

3475{
3478 Oid roleid;
3479 AclMode mode;
3481 bool is_missing = false;
3482
3483 roleid = GetUserId();
3485
3487 roleid, mode,
3488 &is_missing);
3489
3490 if (is_missing)
3492
3494}
static AclMode convert_function_priv_string(text *priv_type_text)
Definition acl.c:3575

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 3683 of file acl.c.

3684{
3687 Oid roleid;
3688 AclMode mode;
3690 bool is_missing = false;
3691
3692 roleid = GetUserId();
3694
3696 roleid, mode,
3697 &is_missing);
3698
3699 if (is_missing)
3701
3703}
static AclMode convert_language_priv_string(text *priv_type_text)
Definition acl.c:3775

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 4763 of file acl.c.

4764{
4766 Oid roleid = GetUserId();
4768 AclMode mode;
4769 bool is_missing = false;
4770 bool result;
4771
4773 result = has_lo_priv_byid(roleid, lobjId, mode, &is_missing);
4774
4775 if (is_missing)
4777
4778 PG_RETURN_BOOL(result);
4779}
static AclMode convert_largeobject_priv_string(text *priv_type_text)
Definition acl.c:4810
static bool has_lo_priv_byid(Oid roleid, Oid lobjId, AclMode priv, bool *is_missing)
Definition acl.c:4704

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 4787 of file acl.c.

4788{
4789 Oid roleid = PG_GETARG_OID(0);
4792 AclMode mode;
4793 bool is_missing = false;
4794 bool result;
4795
4797 result = has_lo_priv_byid(roleid, lobjId, mode, &is_missing);
4798
4799 if (is_missing)
4801
4802 PG_RETURN_BOOL(result);
4803}

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 4704 of file acl.c.

4705{
4706 Snapshot snapshot = NULL;
4708
4709 if (priv & ACL_UPDATE)
4710 snapshot = NULL;
4711 else
4712 snapshot = GetActiveSnapshot();
4713
4714 if (!LargeObjectExistsWithSnapshot(lobjId, snapshot))
4715 {
4717 *is_missing = true;
4718 return false;
4719 }
4720
4722 return true;
4723
4725 roleid,
4726 priv,
4727 snapshot);
4728 return aclresult == ACLCHECK_OK;
4729}
AclResult pg_largeobject_aclcheck_snapshot(Oid lobj_oid, Oid roleid, AclMode mode, Snapshot snapshot)
Definition aclchk.c:4076
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 4613 of file acl.c.

4614{
4616
4617 return pg_parameter_aclcheck(paramstr, roleid, priv) == ACLCHECK_OK;
4618}
AclResult pg_parameter_aclcheck(const char *name, Oid roleid, AclMode mode)
Definition aclchk.c:4064

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 4656 of file acl.c.

4657{
4658 Oid roleid = PG_GETARG_OID(0);
4661
4663}
static bool has_param_priv_byname(Oid roleid, const text *parameter, AclMode priv)
Definition acl.c:4613
static AclMode convert_parameter_priv_string(text *priv_text)
Definition acl.c:4674

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 5286 of file acl.c.

5287{
5288 /* Fast path for simple case */
5289 if (member == role)
5290 return true;
5291
5292 /* Superusers have every privilege, so are part of every role */
5293 if (superuser_arg(member))
5294 return true;
5295
5296 /*
5297 * Find all the roles that member has the privileges of, including
5298 * multi-level recursion, then see if target role is any one of them.
5299 */
5301 InvalidOid, NULL),
5302 role);
5303}
static List * roles_is_member_of(Oid roleid, enum RoleRecurseType type, Oid admin_of, Oid *admin_role)
Definition acl.c:5154
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_namespace_aclmask_ext(), pg_role_aclcheck(), pg_signal_backend(), pg_stat_get_wal_receiver(), pg_stat_get_wal_senders(), pg_stat_statements_internal(), pgrowlocks(), ReassignOwnedObjects(), ReindexMultipleTables(), shell_check_detail(), and TerminateOtherDBBackends().

◆ has_schema_privilege_id()

Datum has_schema_privilege_id ( PG_FUNCTION_ARGS  )

Definition at line 3883 of file acl.c.

3884{
3887 Oid roleid;
3888 AclMode mode;
3890 bool is_missing = false;
3891
3892 roleid = GetUserId();
3894
3896 roleid, mode,
3897 &is_missing);
3898
3899 if (is_missing)
3901
3903}
static AclMode convert_schema_priv_string(text *priv_type_text)
Definition acl.c:3975

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 3911 of file acl.c.

3912{
3913 Oid roleid = PG_GETARG_OID(0);
3914 text *schemaname = PG_GETARG_TEXT_PP(1);
3916 Oid schemaoid;
3917 AclMode mode;
3919
3920 schemaoid = convert_schema_name(schemaname);
3922
3924
3926}
static Oid convert_schema_name(text *schemaname)
Definition acl.c:3963

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 2203 of file acl.c.

2204{
2207 Oid roleid;
2208 AclMode mode;
2210 char relkind;
2211 bool is_missing = false;
2212
2213 roleid = GetUserId();
2215 relkind = get_rel_relkind(sequenceoid);
2216 if (relkind == '\0')
2218 else if (relkind != RELKIND_SEQUENCE)
2219 ereport(ERROR,
2221 errmsg("\"%s\" is not a sequence",
2223
2225
2226 if (is_missing)
2228
2230}
static AclMode convert_sequence_priv_string(text *priv_type_text)
Definition acl.c:2299
char get_rel_relkind(Oid relid)
Definition lsyscache.c:2153

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 2266 of file acl.c.

2267{
2268 Oid roleid = PG_GETARG_OID(0);
2271 AclMode mode;
2273 char relkind;
2274 bool is_missing = false;
2275
2277 relkind = get_rel_relkind(sequenceoid);
2278 if (relkind == '\0')
2280 else if (relkind != RELKIND_SEQUENCE)
2281 ereport(ERROR,
2283 errmsg("\"%s\" is not a sequence",
2285
2287
2288 if (is_missing)
2290
2292}

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 4085 of file acl.c.

4086{
4087 Oid serverid = PG_GETARG_OID(0);
4089 Oid roleid;
4090 AclMode mode;
4092 bool is_missing = false;
4093
4094 roleid = GetUserId();
4096
4098 roleid, mode,
4099 &is_missing);
4100
4101 if (is_missing)
4103
4105}
static AclMode convert_server_priv_string(text *priv_type_text)
Definition acl.c:4177

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 4136 of file acl.c.

4137{
4138 Oid roleid = PG_GETARG_OID(0);
4139 Oid serverid = PG_GETARG_OID(1);
4141 AclMode mode;
4143 bool is_missing = false;
4144
4146
4148 roleid, mode,
4149 &is_missing);
4150
4151 if (is_missing)
4153
4155}

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 4113 of file acl.c.

4114{
4115 Oid roleid = PG_GETARG_OID(0);
4116 text *servername = PG_GETARG_TEXT_PP(1);
4118 Oid serverid;
4119 AclMode mode;
4121
4122 serverid = convert_server_name(servername);
4124
4126
4128}
static Oid convert_server_name(text *servername)
Definition acl.c:4165

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 4031 of file acl.c.

4032{
4033 text *servername = PG_GETARG_TEXT_PP(0);
4035 Oid roleid;
4036 Oid serverid;
4037 AclMode mode;
4039
4040 roleid = GetUserId();
4041 serverid = convert_server_name(servername);
4043
4045
4047}

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 1973 of file acl.c.

1974{
1975 Oid tableoid = PG_GETARG_OID(0);
1977 Oid roleid;
1978 AclMode mode;
1980 bool is_missing = false;
1981
1982 roleid = GetUserId();
1984
1985 aclresult = pg_class_aclcheck_ext(tableoid, roleid, mode, &is_missing);
1986
1987 if (is_missing)
1989
1991}
static AclMode convert_table_priv_string(text *priv_type_text)
Definition acl.c:2064

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 2022 of file acl.c.

2023{
2024 Oid roleid = PG_GETARG_OID(0);
2025 Oid tableoid = PG_GETARG_OID(1);
2027 AclMode mode;
2029 bool is_missing = false;
2030
2032
2033 aclresult = pg_class_aclcheck_ext(tableoid, roleid, mode, &is_missing);
2034
2035 if (is_missing)
2037
2039}

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 1999 of file acl.c.

2000{
2001 Oid roleid = PG_GETARG_OID(0);
2002 text *tablename = PG_GETARG_TEXT_PP(1);
2004 Oid tableoid;
2005 AclMode mode;
2007
2008 tableoid = convert_table_name(tablename);
2010
2011 aclresult = pg_class_aclcheck(tableoid, roleid, mode);
2012
2014}

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 1921 of file acl.c.

1922{
1923 text *tablename = PG_GETARG_TEXT_PP(0);
1925 Oid roleid;
1926 Oid tableoid;
1927 AclMode mode;
1929
1930 roleid = GetUserId();
1931 tableoid = convert_table_name(tablename);
1933
1934 aclresult = pg_class_aclcheck(tableoid, roleid, mode);
1935
1937}

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 1895 of file acl.c.

1896{
1897 Name rolename = PG_GETARG_NAME(0);
1898 text *tablename = PG_GETARG_TEXT_PP(1);
1900 Oid roleid;
1901 Oid tableoid;
1902 AclMode mode;
1904
1905 roleid = get_role_oid_or_public(NameStr(*rolename));
1906 tableoid = convert_table_name(tablename);
1908
1909 aclresult = pg_class_aclcheck(tableoid, roleid, mode);
1910
1912}

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 4285 of file acl.c.

4286{
4289 Oid roleid;
4290 AclMode mode;
4292 bool is_missing = false;
4293
4294 roleid = GetUserId();
4296
4298 roleid, mode,
4299 &is_missing);
4300
4301 if (is_missing)
4303
4305}
static AclMode convert_tablespace_priv_string(text *priv_type_text)
Definition acl.c:4377

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 4313 of file acl.c.

4314{
4315 Oid roleid = PG_GETARG_OID(0);
4316 text *tablespacename = PG_GETARG_TEXT_PP(1);
4319 AclMode mode;
4321
4322 tablespaceoid = convert_tablespace_name(tablespacename);
4324
4326
4328}
static Oid convert_tablespace_name(text *tablespacename)
Definition acl.c:4365

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 4484 of file acl.c.

4485{
4486 Oid typeoid = PG_GETARG_OID(0);
4488 Oid roleid;
4489 AclMode mode;
4491 bool is_missing = false;
4492
4493 roleid = GetUserId();
4495
4497 roleid, mode,
4498 &is_missing);
4499
4500 if (is_missing)
4502
4504}
static AclMode convert_type_priv_string(text *priv_type_text)
Definition acl.c:4585

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 4535 of file acl.c.

4536{
4537 Oid roleid = PG_GETARG_OID(0);
4538 Oid typeoid = PG_GETARG_OID(1);
4540 AclMode mode;
4542 bool is_missing = false;
4543
4545
4547 roleid, mode,
4548 &is_missing);
4549
4550 if (is_missing)
4552
4554}

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 4512 of file acl.c.

4513{
4514 Oid roleid = PG_GETARG_OID(0);
4515 text *typename = PG_GETARG_TEXT_PP(1);
4517 Oid typeoid;
4518 AclMode mode;
4520
4521 typeoid = convert_type_name(typename);
4523
4524 aclresult = object_aclcheck(TypeRelationId, typeoid, roleid, mode);
4525
4527}
static Oid convert_type_name(text *typename)
Definition acl.c:4564

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 4430 of file acl.c.

4431{
4432 text *typename = PG_GETARG_TEXT_PP(0);
4434 Oid roleid;
4435 Oid typeoid;
4436 AclMode mode;
4438
4439 roleid = GetUserId();
4440 typeoid = convert_type_name(typename);
4442
4443 aclresult = object_aclcheck(TypeRelationId, typeoid, roleid, mode);
4444
4446}

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 769 of file acl.c.

770{
772
773 /* not very bright, but avoids any issue of padding in struct */
774 PG_RETURN_UINT32((uint32) (a->ai_privs + a->ai_grantee + a->ai_grantor));
775}
uint32_t uint32
Definition c.h:546
#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 783 of file acl.c.

784{
786 uint64 seed = PG_GETARG_INT64(1);
787 uint32 sum = (uint32) (a->ai_privs + a->ai_grantee + a->ai_grantor);
788
789 return (seed == 0) ? UInt64GetDatum(sum) : hash_uint32_extended(sum, seed);
790}
uint64_t uint64
Definition c.h:547
#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:443

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

◆ initialize_acl()

void initialize_acl ( void  )

Definition at line 5041 of file acl.c.

5042{
5044 {
5048
5049 /*
5050 * In normal mode, set a callback on any syscache invalidation of rows
5051 * of pg_auth_members (for roles_is_member_of()) pg_database (for
5052 * roles_is_member_of())
5053 */
5056 (Datum) 0);
5059 (Datum) 0);
5062 (Datum) 0);
5063 }
5064}
static uint32 cached_db_hash
Definition acl.c:82
static void RoleMembershipCacheCallback(Datum arg, SysCacheIdentifier cacheid, uint32 hashvalue)
Definition acl.c:5071
Oid MyDatabaseId
Definition globals.c:94
void CacheRegisterSyscacheCallback(SysCacheIdentifier cacheid, SyscacheCallbackFunction func, Datum arg)
Definition inval.c:1816
#define IsBootstrapProcessingMode()
Definition miscadmin.h:477
#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 5416 of file acl.c.

5417{
5419
5420 if (superuser_arg(member))
5421 return true;
5422
5423 /* By policy, a role cannot have WITH ADMIN OPTION on itself. */
5424 if (member == role)
5425 return false;
5426
5428 return OidIsValid(admin_role);
5429}

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 5366 of file acl.c.

5367{
5368 /* Fast path for simple case */
5369 if (member == role)
5370 return true;
5371
5372 /* Superusers have every privilege, so are part of every role */
5373 if (superuser_arg(member))
5374 return true;
5375
5376 /*
5377 * Find all the roles that member is a member of, including multi-level
5378 * recursion, then see if target role is any one of them.
5379 */
5381 InvalidOid, NULL),
5382 role);
5383}

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 5394 of file acl.c.

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

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 146 of file acl.c.

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

References fb(), and IS_HIGHBIT_SET.

Referenced by getid(), and putid().

◆ make_empty_acl()

Acl * make_empty_acl ( void  )

Definition at line 449 of file acl.c.

450{
451 return allocacl(0);
452}

References allocacl().

Referenced by SetDefaultACL().

◆ makeaclitem()

Datum makeaclitem ( PG_FUNCTION_ARGS  )

Definition at line 1635 of file acl.c.

1636{
1638 Oid grantor = PG_GETARG_OID(1);
1640 bool goption = PG_GETARG_BOOL(3);
1641 AclItem *result;
1642 AclMode priv;
1643 static const priv_map any_priv_map[] = {
1644 {"SELECT", ACL_SELECT},
1645 {"INSERT", ACL_INSERT},
1646 {"UPDATE", ACL_UPDATE},
1647 {"DELETE", ACL_DELETE},
1648 {"TRUNCATE", ACL_TRUNCATE},
1649 {"REFERENCES", ACL_REFERENCES},
1650 {"TRIGGER", ACL_TRIGGER},
1651 {"EXECUTE", ACL_EXECUTE},
1652 {"USAGE", ACL_USAGE},
1653 {"CREATE", ACL_CREATE},
1654 {"TEMP", ACL_CREATE_TEMP},
1655 {"TEMPORARY", ACL_CREATE_TEMP},
1656 {"CONNECT", ACL_CONNECT},
1657 {"SET", ACL_SET},
1658 {"ALTER SYSTEM", ACL_ALTER_SYSTEM},
1659 {"MAINTAIN", ACL_MAINTAIN},
1660 {NULL, 0}
1661 };
1662
1664
1665 result = palloc_object(AclItem);
1666
1667 result->ai_grantee = grantee;
1668 result->ai_grantor = grantor;
1669
1670 ACLITEM_SET_PRIVS_GOPTIONS(*result, priv,
1671 (goption ? priv : ACL_NO_RIGHTS));
1672
1673 PG_RETURN_ACLITEM_P(result);
1674}
#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 5320 of file acl.c.

5321{
5322 /* Fast path for simple case */
5323 if (member == role)
5324 return true;
5325
5326 /* Superusers have every privilege, so can always SET ROLE */
5327 if (superuser_arg(member))
5328 return true;
5329
5330 /*
5331 * Find all the roles that member can access via SET ROLE, including
5332 * multi-level recursion, then see if target role is any one of them.
5333 */
5335 InvalidOid, NULL),
5336 role);
5337}

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 4913 of file acl.c.

4914{
4915 Oid roleoid = PG_GETARG_OID(0);
4917 Oid roleid;
4918 AclMode mode;
4920
4921 roleid = GetUserId();
4923
4924 aclresult = pg_role_aclcheck(roleoid, roleid, mode);
4925
4927}
static AclMode convert_role_priv_string(text *priv_type_text)
Definition acl.c:4988
static AclResult pg_role_aclcheck(Oid role_oid, Oid roleid, AclMode mode)
Definition acl.c:5011

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 4958 of file acl.c.

4959{
4960 Oid roleid = PG_GETARG_OID(0);
4961 Oid roleoid = PG_GETARG_OID(1);
4963 AclMode mode;
4965
4967
4968 aclresult = pg_role_aclcheck(roleoid, roleid, mode);
4969
4971}

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 4935 of file acl.c.

4936{
4937 Oid roleid = PG_GETARG_OID(0);
4938 Name rolename = PG_GETARG_NAME(1);
4940 Oid roleoid;
4941 AclMode mode;
4943
4944 roleoid = get_role_oid(NameStr(*rolename), false);
4946
4947 aclresult = pg_role_aclcheck(roleoid, roleid, mode);
4948
4950}

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 4865 of file acl.c.

4866{
4867 Name rolename = PG_GETARG_NAME(0);
4869 Oid roleid;
4870 Oid roleoid;
4871 AclMode mode;
4873
4874 roleid = GetUserId();
4875 roleoid = get_role_oid(NameStr(*rolename), false);
4877
4878 aclresult = pg_role_aclcheck(roleoid, roleid, mode);
4879
4881}

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 4839 of file acl.c.

4840{
4842 Name rolename = PG_GETARG_NAME(1);
4844 Oid roleid;
4845 Oid roleoid;
4846 AclMode mode;
4848
4849 roleid = get_role_oid(NameStr(*username), false);
4850 roleoid = get_role_oid(NameStr(*rolename), false);
4852
4853 aclresult = pg_role_aclcheck(roleoid, roleid, mode);
4854
4856}

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 5011 of file acl.c.

5012{
5014 {
5015 if (is_admin_of_role(roleid, role_oid))
5016 return ACLCHECK_OK;
5017 }
5018 if (mode & ACL_CREATE)
5019 {
5020 if (is_member_of_role(roleid, role_oid))
5021 return ACLCHECK_OK;
5022 }
5023 if (mode & ACL_USAGE)
5024 {
5025 if (has_privs_of_role(roleid, role_oid))
5026 return ACLCHECK_OK;
5027 }
5028 if (mode & ACL_SET)
5029 {
5030 if (member_can_set_role(roleid, role_oid))
5031 return ACLCHECK_OK;
5032 }
5033 return ACLCHECK_NO_PRIV;
5034}
bool is_admin_of_role(Oid member, Oid role)
Definition acl.c:5416
bool is_member_of_role(Oid member, Oid role)
Definition acl.c:5366
@ ACLCHECK_NO_PRIV
Definition acl.h:184

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 222 of file acl.c.

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

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 1303 of file acl.c.

1308{
1310 AclItem *aip;
1311 int i,
1312 num;
1313
1314 check_acl(acl);
1315
1316 /* The owner can never truly lose grant options, so short-circuit */
1317 if (grantee == ownerId)
1318 return acl;
1319
1320 /* The grantee might still have some grant options via another grantor */
1321 still_has = aclmask(acl, grantee, ownerId,
1323 ACLMASK_ALL);
1326 return acl;
1327
1328restart:
1329 num = ACL_NUM(acl);
1330 aip = ACL_DAT(acl);
1331 for (i = 0; i < num; i++)
1332 {
1333 if (aip[i].ai_grantor == grantee
1334 && (ACLITEM_GET_PRIVS(aip[i]) & revoke_privs) != 0)
1335 {
1337 Acl *new_acl;
1338
1339 if (behavior == DROP_RESTRICT)
1340 ereport(ERROR,
1342 errmsg("dependent privileges exist"),
1343 errhint("Use CASCADE to revoke them too.")));
1344
1345 mod_acl.ai_grantor = grantee;
1346 mod_acl.ai_grantee = aip[i].ai_grantee;
1349 revoke_privs);
1350
1352 ownerId, behavior);
1353
1354 pfree(acl);
1355 acl = new_acl;
1356
1357 goto restart;
1358 }
1359 }
1360
1361 return acl;
1362}

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 5071 of file acl.c.

5073{
5074 if (cacheid == DATABASEOID &&
5075 hashvalue != cached_db_hash &&
5076 hashvalue != 0)
5077 {
5078 return; /* ignore pg_database changes for other DBs */
5079 }
5080
5081 /* Force membership caches to be recomputed on next use */
5085}
static Oid cached_role[]
Definition acl.c:80

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 5154 of file acl.c.

5156{
5157 Oid dba;
5159 ListCell *l;
5162 bloom_filter *bf = NULL;
5163
5165 if (admin_role != NULL)
5167
5168 /* If cache is valid and ADMIN OPTION not sought, just return the list */
5169 if (cached_role[type] == roleid && !OidIsValid(admin_of) &&
5171 return cached_roles[type];
5172
5173 /*
5174 * Role expansion happens in a non-database backend when guc.c checks
5175 * ROLE_PG_READ_ALL_SETTINGS for a physical walsender SHOW command. In
5176 * that case, no role gets pg_database_owner.
5177 */
5179 dba = InvalidOid;
5180 else
5181 {
5183
5185 if (!HeapTupleIsValid(dbtup))
5186 elog(ERROR, "cache lookup failed for database %u", MyDatabaseId);
5189 }
5190
5191 /*
5192 * Find all the roles that roleid is a member of, including multi-level
5193 * recursion. The role itself will always be the first element of the
5194 * resulting list.
5195 *
5196 * Each element of the list is scanned to see if it adds any indirect
5197 * memberships. We can use a single list as both the record of
5198 * already-found memberships and the agenda of roles yet to be scanned.
5199 * This is a bit tricky but works because the foreach() macro doesn't
5200 * fetch the next list element until the bottom of the loop.
5201 */
5202 roles_list = list_make1_oid(roleid);
5203
5204 foreach(l, roles_list)
5205 {
5206 Oid memberid = lfirst_oid(l);
5208 int i;
5209
5210 /* Find roles that memberid is directly a member of */
5213 for (i = 0; i < memlist->n_members; i++)
5214 {
5215 HeapTuple tup = &memlist->members[i]->tuple;
5217 Oid otherid = form->roleid;
5218
5219 /*
5220 * While otherid==InvalidOid shouldn't appear in the catalog, the
5221 * OidIsValid() avoids crashing if that arises.
5222 */
5223 if (otherid == admin_of && form->admin_option &&
5226
5227 /* If we're supposed to ignore non-heritable grants, do so. */
5228 if (type == ROLERECURSE_PRIVS && !form->inherit_option)
5229 continue;
5230
5231 /* If we're supposed to ignore non-SET grants, do so. */
5232 if (type == ROLERECURSE_SETROLE && !form->set_option)
5233 continue;
5234
5235 /*
5236 * Even though there shouldn't be any loops in the membership
5237 * graph, we must test for having already seen this role. It is
5238 * legal for instance to have both A->B and A->C->B.
5239 */
5241 }
5243
5244 /* implement pg_database_owner implicit membership */
5245 if (memberid == dba && OidIsValid(dba))
5248 }
5249
5250 /*
5251 * Free the Bloom filter created by roles_list_append(), if there is one.
5252 */
5253 if (bf)
5254 bloom_free(bf);
5255
5256 /*
5257 * Copy the completed list into TopMemoryContext so it will persist.
5258 */
5263
5264 /*
5265 * Now safe to assign to state variable
5266 */
5267 cached_role[type] = InvalidOid; /* just paranoia */
5270 cached_role[type] = roleid;
5271
5272 /* And now we can return the answer */
5273 return cached_roles[type];
5274}
static List * roles_list_append(List *roles_list, bloom_filter **bf, Oid role)
Definition acl.c:5094
static List * cached_roles[]
Definition acl.c:81
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
FormData_pg_auth_members * Form_pg_auth_members
FormData_pg_database * Form_pg_database
Definition pg_database.h:96
#define list_make1_oid(x1)
Definition pg_list.h:242
#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(), 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 5094 of file acl.c.

5095{
5096 unsigned char *roleptr = (unsigned char *) &role;
5097
5098 /*
5099 * If there is a previously-created Bloom filter, use it to try to
5100 * determine whether the role is missing from the list. If it says yes,
5101 * that's a hard fact and we can go ahead and add the role. If it says
5102 * no, that's only probabilistic and we'd better search the list. Without
5103 * a filter, we must always do an ordinary linear search through the
5104 * existing list.
5105 */
5106 if ((*bf && bloom_lacks_element(*bf, roleptr, sizeof(Oid))) ||
5108 {
5109 /*
5110 * If the list is large, we take on the overhead of creating and
5111 * populating a Bloom filter to speed up future calls to this
5112 * function.
5113 */
5114 if (*bf == NULL &&
5116 {
5118 foreach_oid(roleid, roles_list)
5119 bloom_add_element(*bf, (unsigned char *) &roleid, sizeof(Oid));
5120 }
5121
5122 /*
5123 * Finally, add the role to the list and the Bloom filter, if it
5124 * exists.
5125 */
5127 if (*bf)
5128 bloom_add_element(*bf, roleptr, sizeof(Oid));
5129 }
5130
5131 return roles_list;
5132}
#define ROLES_LIST_BLOOM_THRESHOLD
Definition acl.c:90
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:471

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 5441 of file acl.c.

5442{
5444
5445 /* By policy, a role cannot have WITH ADMIN OPTION on itself. */
5446 if (member == role)
5447 return InvalidOid;
5448
5450 return admin_role;
5451}

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

Referenced by check_role_grantor().

◆ select_best_grantor()

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

Definition at line 5478 of file acl.c.

5481{
5484 int nrights;
5485 ListCell *l;
5486
5487 /*
5488 * The object owner is always treated as having all grant options, so if
5489 * roleId is the owner it's easy. Also, if roleId is a superuser it's
5490 * easy: superusers are implicitly members of every role, so they act as
5491 * the object owner.
5492 */
5493 if (roleId == ownerId || superuser_arg(roleId))
5494 {
5495 *grantorId = ownerId;
5497 return;
5498 }
5499
5500 /*
5501 * Otherwise we have to do a careful search to see if roleId has the
5502 * privileges of any suitable role. Note: we can hang onto the result of
5503 * roles_is_member_of() throughout this loop, because aclmask_direct()
5504 * doesn't query any role memberships.
5505 */
5507 InvalidOid, NULL);
5508
5509 /* initialize candidate result as default */
5510 *grantorId = roleId;
5512 nrights = 0;
5513
5514 foreach(l, roles_list)
5515 {
5518
5519 otherprivs = aclmask_direct(acl, otherrole, ownerId,
5522 {
5523 /* Found a suitable grantor */
5526 return;
5527 }
5528
5529 /*
5530 * If it has just some of the needed privileges, remember best
5531 * candidate.
5532 */
5534 {
5536
5537 if (nnewrights > nrights)
5538 {
5542 }
5543 }
5544 }
5545}
static AclMode aclmask_direct(const Acl *acl, Oid roleid, Oid ownerId, AclMode mask, AclMaskHow how)
Definition acl.c:1478
static int pg_popcount64(uint64 word)

References ACL_GRANT_OPTION_FOR, ACL_NO_RIGHTS, ACLMASK_ALL, aclmask_direct(), fb(), 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 82 of file acl.c.

Referenced by initialize_acl(), and RoleMembershipCacheCallback().

◆ cached_role

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

Definition at line 80 of file acl.c.

Referenced by RoleMembershipCacheCallback(), and roles_is_member_of().

◆ cached_roles

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

Definition at line 81 of file acl.c.

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

Referenced by roles_is_member_of().