PostgreSQL Source Code  git master
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_authid.h"
#include "catalog/pg_auth_members.h"
#include "catalog/pg_type.h"
#include "catalog/pg_class.h"
#include "commands/dbcommands.h"
#include "commands/proclang.h"
#include "commands/tablespace.h"
#include "foreign/foreign.h"
#include "funcapi.h"
#include "miscadmin.h"
#include "utils/acl.h"
#include "utils/array.h"
#include "utils/builtins.h"
#include "utils/catcache.h"
#include "utils/hashutils.h"
#include "utils/inval.h"
#include "utils/lsyscache.h"
#include "utils/memutils.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
 

Functions

static const char * getid (const char *s, char *n)
 
static void putid (char *p, const char *s)
 
static Aclallocacl (int n)
 
static void check_acl (const Acl *acl)
 
static const char * aclparse (const char *s, AclItem *aip)
 
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_priv_string (text *priv_type_text)
 
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_role_priv_string (text *priv_type_text)
 
static AclResult pg_role_aclcheck (Oid role_oid, Oid roleid, AclMode mode)
 
static void RoleMembershipCacheCallback (Datum arg, int cacheid, uint32 hashvalue)
 
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 char * convert_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)
 
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 bool has_rolinherit (Oid roleid)
 
static Listroles_has_privs_of (Oid roleid)
 
static Listroles_is_member_of (Oid roleid)
 
bool has_privs_of_role (Oid member, Oid role)
 
bool is_member_of_role (Oid member, Oid role)
 
void check_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)
 
static int count_one_bits (AclMode mask)
 
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)
 
char * get_rolespec_name (const RoleSpec *role)
 
void check_rolespec_name (const RoleSpec *role, const char *detail_msg)
 

Variables

static Oid cached_privs_role = InvalidOid
 
static Listcached_privs_roles = NIL
 
static Oid cached_member_role = InvalidOid
 
static Listcached_membership_roles = NIL
 

Function Documentation

◆ aclconcat()

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

Definition at line 428 of file acl.c.

References ACL_DAT, ACL_NUM, and allocacl().

Referenced by ExecGrant_Attribute().

429 {
430  Acl *result_acl;
431 
432  result_acl = allocacl(ACL_NUM(left_acl) + ACL_NUM(right_acl));
433 
434  memcpy(ACL_DAT(result_acl),
435  ACL_DAT(left_acl),
436  ACL_NUM(left_acl) * sizeof(AclItem));
437 
438  memcpy(ACL_DAT(result_acl) + ACL_NUM(left_acl),
439  ACL_DAT(right_acl),
440  ACL_NUM(right_acl) * sizeof(AclItem));
441 
442  return result_acl;
443 }
static Acl * allocacl(int n)
Definition: acl.c:377
#define ACL_NUM(ACL)
Definition: acl.h:108
#define ACL_DAT(ACL)
Definition: acl.h:109
Definition: acl.h:54

◆ aclcontains()

Datum aclcontains ( PG_FUNCTION_ARGS  )

Definition at line 1553 of file acl.c.

References ACL_DAT, ACL_NUM, ACLITEM_GET_RIGHTS, AclItem::ai_grantee, AclItem::ai_grantor, check_acl(), i, PG_GETARG_ACL_P, PG_GETARG_ACLITEM_P, and PG_RETURN_BOOL.

1554 {
1555  Acl *acl = PG_GETARG_ACL_P(0);
1556  AclItem *aip = PG_GETARG_ACLITEM_P(1);
1557  AclItem *aidat;
1558  int i,
1559  num;
1560 
1561  check_acl(acl);
1562  num = ACL_NUM(acl);
1563  aidat = ACL_DAT(acl);
1564  for (i = 0; i < num; ++i)
1565  {
1566  if (aip->ai_grantee == aidat[i].ai_grantee &&
1567  aip->ai_grantor == aidat[i].ai_grantor &&
1568  (ACLITEM_GET_RIGHTS(*aip) & ACLITEM_GET_RIGHTS(aidat[i])) == ACLITEM_GET_RIGHTS(*aip))
1569  PG_RETURN_BOOL(true);
1570  }
1571  PG_RETURN_BOOL(false);
1572 }
Oid ai_grantee
Definition: acl.h:56
#define PG_GETARG_ACLITEM_P(n)
Definition: acl.h:117
Oid ai_grantor
Definition: acl.h:57
#define ACL_NUM(ACL)
Definition: acl.h:108
#define ACLITEM_GET_RIGHTS(item)
Definition: acl.h:68
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define ACL_DAT(ACL)
Definition: acl.h:109
Definition: acl.h:54
#define PG_GETARG_ACL_P(n)
Definition: acl.h:122
int i
static void check_acl(const Acl *acl)
Definition: acl.c:541

◆ aclcopy()

Acl* aclcopy ( const Acl orig_acl)

Definition at line 408 of file acl.c.

References ACL_DAT, ACL_NUM, and allocacl().

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

409 {
410  Acl *result_acl;
411 
412  result_acl = allocacl(ACL_NUM(orig_acl));
413 
414  memcpy(ACL_DAT(result_acl),
415  ACL_DAT(orig_acl),
416  ACL_NUM(orig_acl) * sizeof(AclItem));
417 
418  return result_acl;
419 }
static Acl * allocacl(int n)
Definition: acl.c:377
#define ACL_NUM(ACL)
Definition: acl.h:108
#define ACL_DAT(ACL)
Definition: acl.h:109
Definition: acl.h:54

◆ acldefault()

Acl* acldefault ( ObjectType  objtype,
Oid  ownerId 
)

Definition at line 749 of file acl.c.

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_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, AclItem::ai_grantee, AclItem::ai_grantor, allocacl(), elog, ERROR, OBJECT_COLUMN, OBJECT_DATABASE, OBJECT_DOMAIN, OBJECT_FDW, OBJECT_FOREIGN_SERVER, OBJECT_FUNCTION, OBJECT_LANGUAGE, OBJECT_LARGEOBJECT, OBJECT_SCHEMA, OBJECT_SEQUENCE, OBJECT_TABLE, OBJECT_TABLESPACE, and OBJECT_TYPE.

Referenced by acldefault_sql(), ExecGrant_Attribute(), ExecGrant_Database(), ExecGrant_Fdw(), ExecGrant_ForeignServer(), ExecGrant_Function(), ExecGrant_Language(), ExecGrant_Largeobject(), ExecGrant_Namespace(), ExecGrant_Relation(), ExecGrant_Tablespace(), ExecGrant_Type(), get_user_default_acl(), pg_class_aclmask(), pg_database_aclmask(), pg_foreign_data_wrapper_aclmask(), pg_foreign_server_aclmask(), pg_language_aclmask(), pg_largeobject_aclmask_snapshot(), pg_namespace_aclmask(), pg_proc_aclmask(), pg_tablespace_aclmask(), pg_type_aclmask(), and SetDefaultACL().

750 {
751  AclMode world_default;
752  AclMode owner_default;
753  int nacl;
754  Acl *acl;
755  AclItem *aip;
756 
757  switch (objtype)
758  {
759  case OBJECT_COLUMN:
760  /* by default, columns have no extra privileges */
761  world_default = ACL_NO_RIGHTS;
762  owner_default = ACL_NO_RIGHTS;
763  break;
764  case OBJECT_TABLE:
765  world_default = ACL_NO_RIGHTS;
766  owner_default = ACL_ALL_RIGHTS_RELATION;
767  break;
768  case OBJECT_SEQUENCE:
769  world_default = ACL_NO_RIGHTS;
770  owner_default = ACL_ALL_RIGHTS_SEQUENCE;
771  break;
772  case OBJECT_DATABASE:
773  /* for backwards compatibility, grant some rights by default */
774  world_default = ACL_CREATE_TEMP | ACL_CONNECT;
775  owner_default = ACL_ALL_RIGHTS_DATABASE;
776  break;
777  case OBJECT_FUNCTION:
778  /* Grant EXECUTE by default, for now */
779  world_default = ACL_EXECUTE;
780  owner_default = ACL_ALL_RIGHTS_FUNCTION;
781  break;
782  case OBJECT_LANGUAGE:
783  /* Grant USAGE by default, for now */
784  world_default = ACL_USAGE;
785  owner_default = ACL_ALL_RIGHTS_LANGUAGE;
786  break;
787  case OBJECT_LARGEOBJECT:
788  world_default = ACL_NO_RIGHTS;
789  owner_default = ACL_ALL_RIGHTS_LARGEOBJECT;
790  break;
791  case OBJECT_SCHEMA:
792  world_default = ACL_NO_RIGHTS;
793  owner_default = ACL_ALL_RIGHTS_SCHEMA;
794  break;
795  case OBJECT_TABLESPACE:
796  world_default = ACL_NO_RIGHTS;
797  owner_default = ACL_ALL_RIGHTS_TABLESPACE;
798  break;
799  case OBJECT_FDW:
800  world_default = ACL_NO_RIGHTS;
801  owner_default = ACL_ALL_RIGHTS_FDW;
802  break;
804  world_default = ACL_NO_RIGHTS;
805  owner_default = ACL_ALL_RIGHTS_FOREIGN_SERVER;
806  break;
807  case OBJECT_DOMAIN:
808  case OBJECT_TYPE:
809  world_default = ACL_USAGE;
810  owner_default = ACL_ALL_RIGHTS_TYPE;
811  break;
812  default:
813  elog(ERROR, "unrecognized objtype: %d", (int) objtype);
814  world_default = ACL_NO_RIGHTS; /* keep compiler quiet */
815  owner_default = ACL_NO_RIGHTS;
816  break;
817  }
818 
819  nacl = 0;
820  if (world_default != ACL_NO_RIGHTS)
821  nacl++;
822  if (owner_default != ACL_NO_RIGHTS)
823  nacl++;
824 
825  acl = allocacl(nacl);
826  aip = ACL_DAT(acl);
827 
828  if (world_default != ACL_NO_RIGHTS)
829  {
830  aip->ai_grantee = ACL_ID_PUBLIC;
831  aip->ai_grantor = ownerId;
832  ACLITEM_SET_PRIVS_GOPTIONS(*aip, world_default, ACL_NO_RIGHTS);
833  aip++;
834  }
835 
836  /*
837  * Note that the owner's entry shows all ordinary privileges but no grant
838  * options. This is because his grant options come "from the system" and
839  * not from his own efforts. (The SQL spec says that the owner's rights
840  * come from a "_SYSTEM" authid.) However, we do consider that the
841  * owner's ordinary privileges are self-granted; this lets him revoke
842  * them. We implement the owner's grant options without any explicit
843  * "_SYSTEM"-like ACL entry, by internally special-casing the owner
844  * wherever we are testing grant options.
845  */
846  if (owner_default != ACL_NO_RIGHTS)
847  {
848  aip->ai_grantee = ownerId;
849  aip->ai_grantor = ownerId;
850  ACLITEM_SET_PRIVS_GOPTIONS(*aip, owner_default, ACL_NO_RIGHTS);
851  }
852 
853  return acl;
854 }
Oid ai_grantee
Definition: acl.h:56
#define ACL_ALL_RIGHTS_FUNCTION
Definition: acl.h:162
static Acl * allocacl(int n)
Definition: acl.c:377
#define ACL_ALL_RIGHTS_TABLESPACE
Definition: acl.h:166
Oid ai_grantor
Definition: acl.h:57
#define ACL_ALL_RIGHTS_LANGUAGE
Definition: acl.h:163
uint32 AclMode
Definition: parsenodes.h:72
#define ERROR
Definition: elog.h:43
#define ACL_NO_RIGHTS
Definition: parsenodes.h:88
#define ACL_ALL_RIGHTS_SCHEMA
Definition: acl.h:165
#define ACL_ALL_RIGHTS_TYPE
Definition: acl.h:167
#define ACL_USAGE
Definition: parsenodes.h:82
#define ACL_CONNECT
Definition: parsenodes.h:86
#define ACL_DAT(ACL)
Definition: acl.h:109
#define ACL_ALL_RIGHTS_SEQUENCE
Definition: acl.h:158
Definition: acl.h:54
#define ACL_ALL_RIGHTS_LARGEOBJECT
Definition: acl.h:164
#define ACL_ALL_RIGHTS_DATABASE
Definition: acl.h:159
#define ACL_ALL_RIGHTS_FOREIGN_SERVER
Definition: acl.h:161
#define ACL_EXECUTE
Definition: parsenodes.h:81
#define elog(elevel,...)
Definition: elog.h:226
#define ACL_ALL_RIGHTS_RELATION
Definition: acl.h:157
#define ACL_CREATE_TEMP
Definition: parsenodes.h:85
#define ACL_ID_PUBLIC
Definition: acl.h:46
#define ACL_ALL_RIGHTS_FDW
Definition: acl.h:160
#define ACLITEM_SET_PRIVS_GOPTIONS(item, privs, goptions)
Definition: acl.h:82

◆ acldefault_sql()

Datum acldefault_sql ( PG_FUNCTION_ARGS  )

Definition at line 862 of file acl.c.

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

863 {
864  char objtypec = PG_GETARG_CHAR(0);
865  Oid owner = PG_GETARG_OID(1);
866  ObjectType objtype = 0;
867 
868  switch (objtypec)
869  {
870  case 'c':
871  objtype = OBJECT_COLUMN;
872  break;
873  case 'r':
874  objtype = OBJECT_TABLE;
875  break;
876  case 's':
877  objtype = OBJECT_SEQUENCE;
878  break;
879  case 'd':
880  objtype = OBJECT_DATABASE;
881  break;
882  case 'f':
883  objtype = OBJECT_FUNCTION;
884  break;
885  case 'l':
886  objtype = OBJECT_LANGUAGE;
887  break;
888  case 'L':
889  objtype = OBJECT_LARGEOBJECT;
890  break;
891  case 'n':
892  objtype = OBJECT_SCHEMA;
893  break;
894  case 't':
895  objtype = OBJECT_TABLESPACE;
896  break;
897  case 'F':
898  objtype = OBJECT_FDW;
899  break;
900  case 'S':
901  objtype = OBJECT_FOREIGN_SERVER;
902  break;
903  case 'T':
904  objtype = OBJECT_TYPE;
905  break;
906  default:
907  elog(ERROR, "unrecognized objtype abbreviation: %c", objtypec);
908  }
909 
910  PG_RETURN_ACL_P(acldefault(objtype, owner));
911 }
#define PG_RETURN_ACL_P(x)
Definition: acl.h:124
Acl * acldefault(ObjectType objtype, Oid ownerId)
Definition: acl.c:749
unsigned int Oid
Definition: postgres_ext.h:31
#define ERROR
Definition: elog.h:43
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
ObjectType
Definition: parsenodes.h:1669
#define elog(elevel,...)
Definition: elog.h:226
#define PG_GETARG_CHAR(n)
Definition: fmgr.h:268

◆ aclequal()

bool aclequal ( const Acl left_acl,
const Acl right_acl 
)

Definition at line 510 of file acl.c.

References ACL_DAT, and ACL_NUM.

Referenced by get_user_default_acl(), and SetDefaultACL().

511 {
512  /* Check for cases where one or both are empty/null */
513  if (left_acl == NULL || ACL_NUM(left_acl) == 0)
514  {
515  if (right_acl == NULL || ACL_NUM(right_acl) == 0)
516  return true;
517  else
518  return false;
519  }
520  else
521  {
522  if (right_acl == NULL || ACL_NUM(right_acl) == 0)
523  return false;
524  }
525 
526  if (ACL_NUM(left_acl) != ACL_NUM(right_acl))
527  return false;
528 
529  if (memcmp(ACL_DAT(left_acl),
530  ACL_DAT(right_acl),
531  ACL_NUM(left_acl) * sizeof(AclItem)) == 0)
532  return true;
533 
534  return false;
535 }
#define ACL_NUM(ACL)
Definition: acl.h:108
#define ACL_DAT(ACL)
Definition: acl.h:109
Definition: acl.h:54

◆ aclexplode()

Datum aclexplode ( PG_FUNCTION_ARGS  )

Definition at line 1746 of file acl.c.

References ACL_DAT, ACL_NUM, ACLITEM_GET_GOPTIONS, ACLITEM_GET_PRIVS, AclItem::ai_grantee, AclItem::ai_grantor, BlessTupleDesc(), BoolGetDatum, check_acl(), convert_aclright_to_string(), CreateTemplateTupleDesc(), CStringGetTextDatum, heap_form_tuple(), HeapTupleGetDatum, idx(), MemoryContextSwitchTo(), MemSet, FuncCallContext::multi_call_memory_ctx, N_ACL_RIGHTS, ObjectIdGetDatum, palloc(), PG_GETARG_ACL_P, SRF_FIRSTCALL_INIT, SRF_IS_FIRSTCALL, SRF_PERCALL_SETUP, SRF_RETURN_DONE, SRF_RETURN_NEXT, FuncCallContext::tuple_desc, TupleDescInitEntry(), FuncCallContext::user_fctx, and values.

1747 {
1748  Acl *acl = PG_GETARG_ACL_P(0);
1749  FuncCallContext *funcctx;
1750  int *idx;
1751  AclItem *aidat;
1752 
1753  if (SRF_IS_FIRSTCALL())
1754  {
1755  TupleDesc tupdesc;
1756  MemoryContext oldcontext;
1757 
1758  check_acl(acl);
1759 
1760  funcctx = SRF_FIRSTCALL_INIT();
1761  oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
1762 
1763  /*
1764  * build tupdesc for result tuples (matches out parameters in pg_proc
1765  * entry)
1766  */
1767  tupdesc = CreateTemplateTupleDesc(4);
1768  TupleDescInitEntry(tupdesc, (AttrNumber) 1, "grantor",
1769  OIDOID, -1, 0);
1770  TupleDescInitEntry(tupdesc, (AttrNumber) 2, "grantee",
1771  OIDOID, -1, 0);
1772  TupleDescInitEntry(tupdesc, (AttrNumber) 3, "privilege_type",
1773  TEXTOID, -1, 0);
1774  TupleDescInitEntry(tupdesc, (AttrNumber) 4, "is_grantable",
1775  BOOLOID, -1, 0);
1776 
1777  funcctx->tuple_desc = BlessTupleDesc(tupdesc);
1778 
1779  /* allocate memory for user context */
1780  idx = (int *) palloc(sizeof(int[2]));
1781  idx[0] = 0; /* ACL array item index */
1782  idx[1] = -1; /* privilege type counter */
1783  funcctx->user_fctx = (void *) idx;
1784 
1785  MemoryContextSwitchTo(oldcontext);
1786  }
1787 
1788  funcctx = SRF_PERCALL_SETUP();
1789  idx = (int *) funcctx->user_fctx;
1790  aidat = ACL_DAT(acl);
1791 
1792  /* need test here in case acl has no items */
1793  while (idx[0] < ACL_NUM(acl))
1794  {
1795  AclItem *aidata;
1796  AclMode priv_bit;
1797 
1798  idx[1]++;
1799  if (idx[1] == N_ACL_RIGHTS)
1800  {
1801  idx[1] = 0;
1802  idx[0]++;
1803  if (idx[0] >= ACL_NUM(acl)) /* done */
1804  break;
1805  }
1806  aidata = &aidat[idx[0]];
1807  priv_bit = 1 << idx[1];
1808 
1809  if (ACLITEM_GET_PRIVS(*aidata) & priv_bit)
1810  {
1811  Datum result;
1812  Datum values[4];
1813  bool nulls[4];
1814  HeapTuple tuple;
1815 
1816  values[0] = ObjectIdGetDatum(aidata->ai_grantor);
1817  values[1] = ObjectIdGetDatum(aidata->ai_grantee);
1818  values[2] = CStringGetTextDatum(convert_aclright_to_string(priv_bit));
1819  values[3] = BoolGetDatum((ACLITEM_GET_GOPTIONS(*aidata) & priv_bit) != 0);
1820 
1821  MemSet(nulls, 0, sizeof(nulls));
1822 
1823  tuple = heap_form_tuple(funcctx->tuple_desc, values, nulls);
1824  result = HeapTupleGetDatum(tuple);
1825 
1826  SRF_RETURN_NEXT(funcctx, result);
1827  }
1828  }
1829 
1830  SRF_RETURN_DONE(funcctx);
1831 }
Oid ai_grantee
Definition: acl.h:56
static const char * convert_aclright_to_string(int aclright)
Definition: acl.c:1696
#define ACLITEM_GET_GOPTIONS(item)
Definition: acl.h:67
TupleDesc CreateTemplateTupleDesc(int natts)
Definition: tupdesc.c:44
#define SRF_IS_FIRSTCALL()
Definition: funcapi.h:283
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
#define MemSet(start, val, len)
Definition: c.h:955
Datum idx(PG_FUNCTION_ARGS)
Definition: _int_op.c:264
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition: heaptuple.c:1020
#define SRF_PERCALL_SETUP()
Definition: funcapi.h:287
Oid ai_grantor
Definition: acl.h:57
TupleDesc tuple_desc
Definition: funcapi.h:113
#define SRF_RETURN_NEXT(_funcctx, _result)
Definition: funcapi.h:289
uint32 AclMode
Definition: parsenodes.h:72
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ACL_NUM(ACL)
Definition: acl.h:108
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
Definition: execTuples.c:2048
#define N_ACL_RIGHTS
Definition: parsenodes.h:87
void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
Definition: tupdesc.c:603
uintptr_t Datum
Definition: postgres.h:367
#define ACL_DAT(ACL)
Definition: acl.h:109
#define BoolGetDatum(X)
Definition: postgres.h:402
Definition: acl.h:54
MemoryContext multi_call_memory_ctx
Definition: funcapi.h:102
#define ACLITEM_GET_PRIVS(item)
Definition: acl.h:66
#define HeapTupleGetDatum(tuple)
Definition: funcapi.h:221
#define PG_GETARG_ACL_P(n)
Definition: acl.h:122
static Datum values[MAXATTR]
Definition: bootstrap.c:167
void * user_fctx
Definition: funcapi.h:83
void * palloc(Size size)
Definition: mcxt.c:924
#define CStringGetTextDatum(s)
Definition: builtins.h:83
int16 AttrNumber
Definition: attnum.h:21
static void check_acl(const Acl *acl)
Definition: acl.c:541
#define SRF_RETURN_DONE(_funcctx)
Definition: funcapi.h:307
#define SRF_FIRSTCALL_INIT()
Definition: funcapi.h:285

◆ aclinsert()

Datum aclinsert ( PG_FUNCTION_ARGS  )

Definition at line 1533 of file acl.c.

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

1534 {
1535  ereport(ERROR,
1536  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1537  errmsg("aclinsert is no longer supported")));
1538 
1539  PG_RETURN_NULL(); /* keep compiler quiet */
1540 }
int errcode(int sqlerrcode)
Definition: elog.c:570
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:141
int errmsg(const char *fmt,...)
Definition: elog.c:784
#define PG_RETURN_NULL()
Definition: fmgr.h:335

◆ aclitem_eq()

Datum aclitem_eq ( PG_FUNCTION_ARGS  )

Definition at line 694 of file acl.c.

References a1, a2, AclItem::ai_grantee, AclItem::ai_grantor, AclItem::ai_privs, PG_GETARG_ACLITEM_P, and PG_RETURN_BOOL.

695 {
698  bool result;
699 
700  result = a1->ai_privs == a2->ai_privs &&
701  a1->ai_grantee == a2->ai_grantee &&
702  a1->ai_grantor == a2->ai_grantor;
703  PG_RETURN_BOOL(result);
704 }
Oid ai_grantee
Definition: acl.h:56
#define PG_GETARG_ACLITEM_P(n)
Definition: acl.h:117
Oid ai_grantor
Definition: acl.h:57
AclMode ai_privs
Definition: acl.h:58
static const FormData_pg_attribute a2
Definition: heap.c:166
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
Definition: acl.h:54
static const FormData_pg_attribute a1
Definition: heap.c:152

◆ aclitem_match()

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

Definition at line 659 of file acl.c.

References AclItem::ai_grantee, and AclItem::ai_grantor.

Referenced by aclnewowner(), and aclupdate().

660 {
661  return a1->ai_grantee == a2->ai_grantee &&
662  a1->ai_grantor == a2->ai_grantor;
663 }
Oid ai_grantee
Definition: acl.h:56
Oid ai_grantor
Definition: acl.h:57

◆ aclitemComparator()

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

Definition at line 670 of file acl.c.

References a1, a2, AclItem::ai_grantee, AclItem::ai_grantor, and AclItem::ai_privs.

Referenced by aclitemsort().

671 {
672  const AclItem *a1 = (const AclItem *) arg1;
673  const AclItem *a2 = (const AclItem *) arg2;
674 
675  if (a1->ai_grantee > a2->ai_grantee)
676  return 1;
677  if (a1->ai_grantee < a2->ai_grantee)
678  return -1;
679  if (a1->ai_grantor > a2->ai_grantor)
680  return 1;
681  if (a1->ai_grantor < a2->ai_grantor)
682  return -1;
683  if (a1->ai_privs > a2->ai_privs)
684  return 1;
685  if (a1->ai_privs < a2->ai_privs)
686  return -1;
687  return 0;
688 }
Oid ai_grantee
Definition: acl.h:56
Oid ai_grantor
Definition: acl.h:57
AclMode ai_privs
Definition: acl.h:58
static const FormData_pg_attribute a2
Definition: heap.c:166
Definition: acl.h:54
static const FormData_pg_attribute a1
Definition: heap.c:152

◆ aclitemin()

Datum aclitemin ( PG_FUNCTION_ARGS  )

Definition at line 566 of file acl.c.

References aclparse(), ereport, errcode(), errmsg(), ERROR, palloc(), PG_GETARG_CSTRING, and PG_RETURN_ACLITEM_P.

567 {
568  const char *s = PG_GETARG_CSTRING(0);
569  AclItem *aip;
570 
571  aip = (AclItem *) palloc(sizeof(AclItem));
572  s = aclparse(s, aip);
573  while (isspace((unsigned char) *s))
574  ++s;
575  if (*s)
576  ereport(ERROR,
577  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
578  errmsg("extra garbage at the end of the ACL specification")));
579 
580  PG_RETURN_ACLITEM_P(aip);
581 }
int errcode(int sqlerrcode)
Definition: elog.c:570
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:141
static const char * aclparse(const char *s, AclItem *aip)
Definition: acl.c:239
Definition: acl.h:54
#define PG_RETURN_ACLITEM_P(x)
Definition: acl.h:118
void * palloc(Size size)
Definition: mcxt.c:924
int errmsg(const char *fmt,...)
Definition: elog.c:784
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:272

◆ aclitemout()

Datum aclitemout ( PG_FUNCTION_ARGS  )

Definition at line 592 of file acl.c.

References ACL_ALL_RIGHTS_STR, ACL_ID_PUBLIC, ACLITEM_GET_GOPTIONS, ACLITEM_GET_PRIVS, AclItem::ai_grantee, AclItem::ai_grantor, AUTHOID, GETSTRUCT, HeapTupleIsValid, i, N_ACL_RIGHTS, NAMEDATALEN, NameStr, ObjectIdGetDatum, palloc(), PG_GETARG_ACLITEM_P, PG_RETURN_CSTRING, putid(), ReleaseSysCache(), rolname, SearchSysCache1(), and sprintf.

593 {
594  AclItem *aip = PG_GETARG_ACLITEM_P(0);
595  char *p;
596  char *out;
597  HeapTuple htup;
598  unsigned i;
599 
600  out = palloc(strlen("=/") +
601  2 * N_ACL_RIGHTS +
602  2 * (2 * NAMEDATALEN + 2) +
603  1);
604 
605  p = out;
606  *p = '\0';
607 
608  if (aip->ai_grantee != ACL_ID_PUBLIC)
609  {
611  if (HeapTupleIsValid(htup))
612  {
613  putid(p, NameStr(((Form_pg_authid) GETSTRUCT(htup))->rolname));
614  ReleaseSysCache(htup);
615  }
616  else
617  {
618  /* Generate numeric OID if we don't find an entry */
619  sprintf(p, "%u", aip->ai_grantee);
620  }
621  }
622  while (*p)
623  ++p;
624 
625  *p++ = '=';
626 
627  for (i = 0; i < N_ACL_RIGHTS; ++i)
628  {
629  if (ACLITEM_GET_PRIVS(*aip) & (1 << i))
630  *p++ = ACL_ALL_RIGHTS_STR[i];
631  if (ACLITEM_GET_GOPTIONS(*aip) & (1 << i))
632  *p++ = '*';
633  }
634 
635  *p++ = '/';
636  *p = '\0';
637 
639  if (HeapTupleIsValid(htup))
640  {
641  putid(p, NameStr(((Form_pg_authid) GETSTRUCT(htup))->rolname));
642  ReleaseSysCache(htup);
643  }
644  else
645  {
646  /* Generate numeric OID if we don't find an entry */
647  sprintf(p, "%u", aip->ai_grantor);
648  }
649 
650  PG_RETURN_CSTRING(out);
651 }
Oid ai_grantee
Definition: acl.h:56
static void putid(char *p, const char *s)
Definition: acl.c:190
#define ACLITEM_GET_GOPTIONS(item)
Definition: acl.h:67
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
NameData rolname
Definition: pg_authid.h:34
#define PG_GETARG_ACLITEM_P(n)
Definition: acl.h:117
Oid ai_grantor
Definition: acl.h:57
#define NAMEDATALEN
FormData_pg_authid * Form_pg_authid
Definition: pg_authid.h:56
#define sprintf
Definition: port.h:194
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define N_ACL_RIGHTS
Definition: parsenodes.h:87
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1124
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1172
#define ACL_ALL_RIGHTS_STR
Definition: acl.h:151
Definition: acl.h:54
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:352
#define ACLITEM_GET_PRIVS(item)
Definition: acl.h:66
void * palloc(Size size)
Definition: mcxt.c:924
int i
#define NameStr(name)
Definition: c.h:609
#define ACL_ID_PUBLIC
Definition: acl.h:46

◆ aclitemsort()

void aclitemsort ( Acl acl)

Definition at line 496 of file acl.c.

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

Referenced by get_user_default_acl(), and SetDefaultACL().

497 {
498  if (acl != NULL && ACL_NUM(acl) > 1)
499  qsort(ACL_DAT(acl), ACL_NUM(acl), sizeof(AclItem), aclitemComparator);
500 }
#define ACL_NUM(ACL)
Definition: acl.h:108
#define ACL_DAT(ACL)
Definition: acl.h:109
Definition: acl.h:54
#define qsort(a, b, c, d)
Definition: port.h:491
static int aclitemComparator(const void *arg1, const void *arg2)
Definition: acl.c:670

◆ aclmask()

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

Definition at line 1321 of file acl.c.

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

Referenced by check_circularity(), LockTableAclCheck(), pg_attribute_aclmask(), pg_class_aclmask(), pg_database_aclmask(), pg_foreign_data_wrapper_aclmask(), pg_foreign_server_aclmask(), pg_language_aclmask(), pg_largeobject_aclmask_snapshot(), pg_namespace_aclmask(), pg_proc_aclmask(), pg_tablespace_aclmask(), pg_type_aclmask(), and recursive_revoke().

1323 {
1324  AclMode result;
1326  AclItem *aidat;
1327  int i,
1328  num;
1329 
1330  /*
1331  * Null ACL should not happen, since caller should have inserted
1332  * appropriate default
1333  */
1334  if (acl == NULL)
1335  elog(ERROR, "null ACL");
1336 
1337  check_acl(acl);
1338 
1339  /* Quick exit for mask == 0 */
1340  if (mask == 0)
1341  return 0;
1342 
1343  result = 0;
1344 
1345  /* Owner always implicitly has all grant options */
1346  if ((mask & ACLITEM_ALL_GOPTION_BITS) &&
1347  has_privs_of_role(roleid, ownerId))
1348  {
1349  result = mask & ACLITEM_ALL_GOPTION_BITS;
1350  if ((how == ACLMASK_ALL) ? (result == mask) : (result != 0))
1351  return result;
1352  }
1353 
1354  num = ACL_NUM(acl);
1355  aidat = ACL_DAT(acl);
1356 
1357  /*
1358  * Check privileges granted directly to roleid or to public
1359  */
1360  for (i = 0; i < num; i++)
1361  {
1362  AclItem *aidata = &aidat[i];
1363 
1364  if (aidata->ai_grantee == ACL_ID_PUBLIC ||
1365  aidata->ai_grantee == roleid)
1366  {
1367  result |= aidata->ai_privs & mask;
1368  if ((how == ACLMASK_ALL) ? (result == mask) : (result != 0))
1369  return result;
1370  }
1371  }
1372 
1373  /*
1374  * Check privileges granted indirectly via role memberships. We do this in
1375  * a separate pass to minimize expensive indirect membership tests. In
1376  * particular, it's worth testing whether a given ACL entry grants any
1377  * privileges still of interest before we perform the has_privs_of_role
1378  * test.
1379  */
1380  remaining = mask & ~result;
1381  for (i = 0; i < num; i++)
1382  {
1383  AclItem *aidata = &aidat[i];
1384 
1385  if (aidata->ai_grantee == ACL_ID_PUBLIC ||
1386  aidata->ai_grantee == roleid)
1387  continue; /* already checked it */
1388 
1389  if ((aidata->ai_privs & remaining) &&
1390  has_privs_of_role(roleid, aidata->ai_grantee))
1391  {
1392  result |= aidata->ai_privs & mask;
1393  if ((how == ACLMASK_ALL) ? (result == mask) : (result != 0))
1394  return result;
1395  remaining = mask & ~result;
1396  }
1397  }
1398 
1399  return result;
1400 }
int remaining
Definition: informix.c:687
Oid ai_grantee
Definition: acl.h:56
#define ACLITEM_ALL_GOPTION_BITS
Definition: acl.h:88
bool has_privs_of_role(Oid member, Oid role)
Definition: acl.c:4908
AclMode ai_privs
Definition: acl.h:58
uint32 AclMode
Definition: parsenodes.h:72
#define ERROR
Definition: elog.h:43
#define ACL_NUM(ACL)
Definition: acl.h:108
#define ACL_DAT(ACL)
Definition: acl.h:109
Definition: acl.h:54
#define elog(elevel,...)
Definition: elog.h:226
int i
#define ACL_ID_PUBLIC
Definition: acl.h:46
static void check_acl(const Acl *acl)
Definition: acl.c:541

◆ aclmask_direct()

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

Definition at line 1410 of file acl.c.

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

Referenced by select_best_grantor().

1412 {
1413  AclMode result;
1414  AclItem *aidat;
1415  int i,
1416  num;
1417 
1418  /*
1419  * Null ACL should not happen, since caller should have inserted
1420  * appropriate default
1421  */
1422  if (acl == NULL)
1423  elog(ERROR, "null ACL");
1424 
1425  check_acl(acl);
1426 
1427  /* Quick exit for mask == 0 */
1428  if (mask == 0)
1429  return 0;
1430 
1431  result = 0;
1432 
1433  /* Owner always implicitly has all grant options */
1434  if ((mask & ACLITEM_ALL_GOPTION_BITS) &&
1435  roleid == ownerId)
1436  {
1437  result = mask & ACLITEM_ALL_GOPTION_BITS;
1438  if ((how == ACLMASK_ALL) ? (result == mask) : (result != 0))
1439  return result;
1440  }
1441 
1442  num = ACL_NUM(acl);
1443  aidat = ACL_DAT(acl);
1444 
1445  /*
1446  * Check privileges granted directly to roleid (and not to public)
1447  */
1448  for (i = 0; i < num; i++)
1449  {
1450  AclItem *aidata = &aidat[i];
1451 
1452  if (aidata->ai_grantee == roleid)
1453  {
1454  result |= aidata->ai_privs & mask;
1455  if ((how == ACLMASK_ALL) ? (result == mask) : (result != 0))
1456  return result;
1457  }
1458  }
1459 
1460  return result;
1461 }
Oid ai_grantee
Definition: acl.h:56
#define ACLITEM_ALL_GOPTION_BITS
Definition: acl.h:88
AclMode ai_privs
Definition: acl.h:58
uint32 AclMode
Definition: parsenodes.h:72
#define ERROR
Definition: elog.h:43
#define ACL_NUM(ACL)
Definition: acl.h:108
#define ACL_DAT(ACL)
Definition: acl.h:109
Definition: acl.h:54
#define elog(elevel,...)
Definition: elog.h:226
int i
static void check_acl(const Acl *acl)
Definition: acl.c:541

◆ aclmembers()

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

Definition at line 1473 of file acl.c.

References ACL_DAT, ACL_ID_PUBLIC, ACL_NUM, AclItem::ai_grantee, AclItem::ai_grantor, check_acl(), i, sort-test::list, oid_cmp(), palloc(), and qsort.

Referenced by ExecGrant_Attribute(), ExecGrant_Database(), ExecGrant_Fdw(), ExecGrant_ForeignServer(), ExecGrant_Function(), ExecGrant_Language(), ExecGrant_Largeobject(), ExecGrant_Namespace(), ExecGrant_Relation(), ExecGrant_Tablespace(), ExecGrant_Type(), recordDependencyOnNewAcl(), and SetDefaultACL().

1474 {
1475  Oid *list;
1476  const AclItem *acldat;
1477  int i,
1478  j,
1479  k;
1480 
1481  if (acl == NULL || ACL_NUM(acl) == 0)
1482  {
1483  *roleids = NULL;
1484  return 0;
1485  }
1486 
1487  check_acl(acl);
1488 
1489  /* Allocate the worst-case space requirement */
1490  list = palloc(ACL_NUM(acl) * 2 * sizeof(Oid));
1491  acldat = ACL_DAT(acl);
1492 
1493  /*
1494  * Walk the ACL collecting mentioned RoleIds.
1495  */
1496  j = 0;
1497  for (i = 0; i < ACL_NUM(acl); i++)
1498  {
1499  const AclItem *ai = &acldat[i];
1500 
1501  if (ai->ai_grantee != ACL_ID_PUBLIC)
1502  list[j++] = ai->ai_grantee;
1503  /* grantor is currently never PUBLIC, but let's check anyway */
1504  if (ai->ai_grantor != ACL_ID_PUBLIC)
1505  list[j++] = ai->ai_grantor;
1506  }
1507 
1508  /* Sort the array */
1509  qsort(list, j, sizeof(Oid), oid_cmp);
1510 
1511  /* Remove duplicates from the array */
1512  k = 0;
1513  for (i = 1; i < j; i++)
1514  {
1515  if (list[k] != list[i])
1516  list[++k] = list[i];
1517  }
1518 
1519  /*
1520  * We could repalloc the array down to minimum size, but it's hardly worth
1521  * it since it's only transient memory.
1522  */
1523  *roleids = list;
1524 
1525  return k + 1;
1526 }
Oid ai_grantee
Definition: acl.h:56
unsigned int Oid
Definition: postgres_ext.h:31
Oid ai_grantor
Definition: acl.h:57
#define ACL_NUM(ACL)
Definition: acl.h:108
#define ACL_DAT(ACL)
Definition: acl.h:109
Definition: acl.h:54
int oid_cmp(const void *p1, const void *p2)
Definition: oid.c:336
void * palloc(Size size)
Definition: mcxt.c:924
int i
#define ACL_ID_PUBLIC
Definition: acl.h:46
#define qsort(a, b, c, d)
Definition: port.h:491
static void check_acl(const Acl *acl)
Definition: acl.c:541

◆ aclmerge()

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

Definition at line 452 of file acl.c.

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

Referenced by get_user_default_acl().

453 {
454  Acl *result_acl;
455  AclItem *aip;
456  int i,
457  num;
458 
459  /* Check for cases where one or both are empty/null */
460  if (left_acl == NULL || ACL_NUM(left_acl) == 0)
461  {
462  if (right_acl == NULL || ACL_NUM(right_acl) == 0)
463  return NULL;
464  else
465  return aclcopy(right_acl);
466  }
467  else
468  {
469  if (right_acl == NULL || ACL_NUM(right_acl) == 0)
470  return aclcopy(left_acl);
471  }
472 
473  /* Merge them the hard way, one item at a time */
474  result_acl = aclcopy(left_acl);
475 
476  aip = ACL_DAT(right_acl);
477  num = ACL_NUM(right_acl);
478 
479  for (i = 0; i < num; i++, aip++)
480  {
481  Acl *tmp_acl;
482 
483  tmp_acl = aclupdate(result_acl, aip, ACL_MODECHG_ADD,
484  ownerId, DROP_RESTRICT);
485  pfree(result_acl);
486  result_acl = tmp_acl;
487  }
488 
489  return result_acl;
490 }
void pfree(void *pointer)
Definition: mcxt.c:1031
#define ACL_NUM(ACL)
Definition: acl.h:108
#define ACL_MODECHG_ADD
Definition: acl.h:129
#define ACL_DAT(ACL)
Definition: acl.h:109
Definition: acl.h:54
Acl * aclcopy(const Acl *orig_acl)
Definition: acl.c:408
int i
Acl * aclupdate(const Acl *old_acl, const AclItem *mod_aip, int modechg, Oid ownerId, DropBehavior behavior)
Definition: acl.c:931

◆ aclnewowner()

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

Definition at line 1052 of file acl.c.

References ACL_DAT, ACL_N_SIZE, ACL_NO_RIGHTS, ACL_NUM, ACLITEM_GET_RIGHTS, aclitem_match(), ACLITEM_SET_RIGHTS, AclItem::ai_grantee, AclItem::ai_grantor, allocacl(), ARR_DIMS, check_acl(), and SET_VARSIZE.

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

1053 {
1054  Acl *new_acl;
1055  AclItem *new_aip;
1056  AclItem *old_aip;
1057  AclItem *dst_aip;
1058  AclItem *src_aip;
1059  AclItem *targ_aip;
1060  bool newpresent = false;
1061  int dst,
1062  src,
1063  targ,
1064  num;
1065 
1066  check_acl(old_acl);
1067 
1068  /*
1069  * Make a copy of the given ACL, substituting new owner ID for old
1070  * wherever it appears as either grantor or grantee. Also note if the new
1071  * owner ID is already present.
1072  */
1073  num = ACL_NUM(old_acl);
1074  old_aip = ACL_DAT(old_acl);
1075  new_acl = allocacl(num);
1076  new_aip = ACL_DAT(new_acl);
1077  memcpy(new_aip, old_aip, num * sizeof(AclItem));
1078  for (dst = 0, dst_aip = new_aip; dst < num; dst++, dst_aip++)
1079  {
1080  if (dst_aip->ai_grantor == oldOwnerId)
1081  dst_aip->ai_grantor = newOwnerId;
1082  else if (dst_aip->ai_grantor == newOwnerId)
1083  newpresent = true;
1084  if (dst_aip->ai_grantee == oldOwnerId)
1085  dst_aip->ai_grantee = newOwnerId;
1086  else if (dst_aip->ai_grantee == newOwnerId)
1087  newpresent = true;
1088  }
1089 
1090  /*
1091  * If the old ACL contained any references to the new owner, then we may
1092  * now have generated an ACL containing duplicate entries. Find them and
1093  * merge them so that there are not duplicates. (This is relatively
1094  * expensive since we use a stupid O(N^2) algorithm, but it's unlikely to
1095  * be the normal case.)
1096  *
1097  * To simplify deletion of duplicate entries, we temporarily leave them in
1098  * the array but set their privilege masks to zero; when we reach such an
1099  * entry it's just skipped. (Thus, a side effect of this code will be to
1100  * remove privilege-free entries, should there be any in the input.) dst
1101  * is the next output slot, targ is the currently considered input slot
1102  * (always >= dst), and src scans entries to the right of targ looking for
1103  * duplicates. Once an entry has been emitted to dst it is known
1104  * duplicate-free and need not be considered anymore.
1105  */
1106  if (newpresent)
1107  {
1108  dst = 0;
1109  for (targ = 0, targ_aip = new_aip; targ < num; targ++, targ_aip++)
1110  {
1111  /* ignore if deleted in an earlier pass */
1112  if (ACLITEM_GET_RIGHTS(*targ_aip) == ACL_NO_RIGHTS)
1113  continue;
1114  /* find and merge any duplicates */
1115  for (src = targ + 1, src_aip = targ_aip + 1; src < num;
1116  src++, src_aip++)
1117  {
1118  if (ACLITEM_GET_RIGHTS(*src_aip) == ACL_NO_RIGHTS)
1119  continue;
1120  if (aclitem_match(targ_aip, src_aip))
1121  {
1122  ACLITEM_SET_RIGHTS(*targ_aip,
1123  ACLITEM_GET_RIGHTS(*targ_aip) |
1124  ACLITEM_GET_RIGHTS(*src_aip));
1125  /* mark the duplicate deleted */
1126  ACLITEM_SET_RIGHTS(*src_aip, ACL_NO_RIGHTS);
1127  }
1128  }
1129  /* and emit to output */
1130  new_aip[dst] = *targ_aip;
1131  dst++;
1132  }
1133  /* Adjust array size to be 'dst' items */
1134  ARR_DIMS(new_acl)[0] = dst;
1135  SET_VARSIZE(new_acl, ACL_N_SIZE(dst));
1136  }
1137 
1138  return new_acl;
1139 }
Oid ai_grantee
Definition: acl.h:56
static Acl * allocacl(int n)
Definition: acl.c:377
Oid ai_grantor
Definition: acl.h:57
#define ARR_DIMS(a)
Definition: array.h:282
#define ACL_NUM(ACL)
Definition: acl.h:108
#define ACL_NO_RIGHTS
Definition: parsenodes.h:88
#define ACLITEM_GET_RIGHTS(item)
Definition: acl.h:68
#define ACLITEM_SET_RIGHTS(item, rights)
Definition: acl.h:79
#define ACL_DAT(ACL)
Definition: acl.h:109
Definition: acl.h:54
static bool aclitem_match(const AclItem *a1, const AclItem *a2)
Definition: acl.c:659
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:329
#define ACL_N_SIZE(N)
Definition: acl.h:110
static void check_acl(const Acl *acl)
Definition: acl.c:541

◆ aclparse()

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

Definition at line 239 of file acl.c.

References ACL_ALL_RIGHTS_STR, 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_NO_RIGHTS, ACL_REFERENCES, ACL_REFERENCES_CHR, ACL_SELECT, ACL_SELECT_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, AclItem::ai_grantee, AclItem::ai_grantor, Assert, elog, ereport, errcode(), errhint(), errmsg(), ERROR, get_role_oid(), getid(), LOG, name, NAMEDATALEN, read, and WARNING.

Referenced by aclitemin().

240 {
241  AclMode privs,
242  goption,
243  read;
244  char name[NAMEDATALEN];
245  char name2[NAMEDATALEN];
246 
247  Assert(s && aip);
248 
249 #ifdef ACLDEBUG
250  elog(LOG, "aclparse: input = \"%s\"", s);
251 #endif
252  s = getid(s, name);
253  if (*s != '=')
254  {
255  /* we just read a keyword, not a name */
256  if (strcmp(name, "group") != 0 && strcmp(name, "user") != 0)
257  ereport(ERROR,
258  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
259  errmsg("unrecognized key word: \"%s\"", name),
260  errhint("ACL key word must be \"group\" or \"user\".")));
261  s = getid(s, name); /* move s to the name beyond the keyword */
262  if (name[0] == '\0')
263  ereport(ERROR,
264  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
265  errmsg("missing name"),
266  errhint("A name must follow the \"group\" or \"user\" key word.")));
267  }
268 
269  if (*s != '=')
270  ereport(ERROR,
271  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
272  errmsg("missing \"=\" sign")));
273 
274  privs = goption = ACL_NO_RIGHTS;
275 
276  for (++s, read = 0; isalpha((unsigned char) *s) || *s == '*'; s++)
277  {
278  switch (*s)
279  {
280  case '*':
281  goption |= read;
282  break;
283  case ACL_INSERT_CHR:
284  read = ACL_INSERT;
285  break;
286  case ACL_SELECT_CHR:
287  read = ACL_SELECT;
288  break;
289  case ACL_UPDATE_CHR:
290  read = ACL_UPDATE;
291  break;
292  case ACL_DELETE_CHR:
293  read = ACL_DELETE;
294  break;
295  case ACL_TRUNCATE_CHR:
296  read = ACL_TRUNCATE;
297  break;
298  case ACL_REFERENCES_CHR:
299  read = ACL_REFERENCES;
300  break;
301  case ACL_TRIGGER_CHR:
302  read = ACL_TRIGGER;
303  break;
304  case ACL_EXECUTE_CHR:
305  read = ACL_EXECUTE;
306  break;
307  case ACL_USAGE_CHR:
308  read = ACL_USAGE;
309  break;
310  case ACL_CREATE_CHR:
311  read = ACL_CREATE;
312  break;
313  case ACL_CREATE_TEMP_CHR:
314  read = ACL_CREATE_TEMP;
315  break;
316  case ACL_CONNECT_CHR:
317  read = ACL_CONNECT;
318  break;
319  case 'R': /* ignore old RULE privileges */
320  read = 0;
321  break;
322  default:
323  ereport(ERROR,
324  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
325  errmsg("invalid mode character: must be one of \"%s\"",
327  }
328 
329  privs |= read;
330  }
331 
332  if (name[0] == '\0')
333  aip->ai_grantee = ACL_ID_PUBLIC;
334  else
335  aip->ai_grantee = get_role_oid(name, false);
336 
337  /*
338  * XXX Allow a degree of backward compatibility by defaulting the grantor
339  * to the superuser.
340  */
341  if (*s == '/')
342  {
343  s = getid(s + 1, name2);
344  if (name2[0] == '\0')
345  ereport(ERROR,
346  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
347  errmsg("a name must follow the \"/\" sign")));
348  aip->ai_grantor = get_role_oid(name2, false);
349  }
350  else
351  {
352  aip->ai_grantor = BOOTSTRAP_SUPERUSERID;
354  (errcode(ERRCODE_INVALID_GRANTOR),
355  errmsg("defaulting grantor to user ID %u",
356  BOOTSTRAP_SUPERUSERID)));
357  }
358 
359  ACLITEM_SET_PRIVS_GOPTIONS(*aip, privs, goption);
360 
361 #ifdef ACLDEBUG
362  elog(LOG, "aclparse: correctly read [%u %x %x]",
363  aip->ai_grantee, privs, goption);
364 #endif
365 
366  return s;
367 }
Oid ai_grantee
Definition: acl.h:56
#define ACL_INSERT_CHR
Definition: acl.h:137
int errhint(const char *fmt,...)
Definition: elog.c:974
#define ACL_CONNECT_CHR
Definition: acl.h:148
#define ACL_DELETE_CHR
Definition: acl.h:140
int errcode(int sqlerrcode)
Definition: elog.c:570
#define ACL_DELETE
Definition: parsenodes.h:77
#define LOG
Definition: elog.h:26
Oid ai_grantor
Definition: acl.h:57
Oid get_role_oid(const char *rolname, bool missing_ok)
Definition: acl.c:5191
#define NAMEDATALEN
uint32 AclMode
Definition: parsenodes.h:72
#define ACL_CREATE_TEMP_CHR
Definition: acl.h:147
#define ERROR
Definition: elog.h:43
#define ACL_CREATE
Definition: parsenodes.h:84
static const char * getid(const char *s, char *n)
Definition: acl.c:138
#define ACL_NO_RIGHTS
Definition: parsenodes.h:88
#define ACL_TRIGGER
Definition: parsenodes.h:80
#define ACL_TRUNCATE_CHR
Definition: acl.h:141
#define ACL_REFERENCES_CHR
Definition: acl.h:142
#define ACL_USAGE
Definition: parsenodes.h:82
#define ereport(elevel, rest)
Definition: elog.h:141
#define ACL_CONNECT
Definition: parsenodes.h:86
#define WARNING
Definition: elog.h:40
#define ACL_SELECT_CHR
Definition: acl.h:138
#define ACL_UPDATE
Definition: parsenodes.h:76
#define ACL_SELECT
Definition: parsenodes.h:75
#define ACL_ALL_RIGHTS_STR
Definition: acl.h:151
#define ACL_USAGE_CHR
Definition: acl.h:145
#define ACL_REFERENCES
Definition: parsenodes.h:79
#define Assert(condition)
Definition: c.h:732
#define ACL_INSERT
Definition: parsenodes.h:74
#define ACL_UPDATE_CHR
Definition: acl.h:139
const char * name
Definition: encode.c:521
#define ACL_TRIGGER_CHR
Definition: acl.h:143
int errmsg(const char *fmt,...)
Definition: elog.c:784
#define ACL_EXECUTE
Definition: parsenodes.h:81
#define elog(elevel,...)
Definition: elog.h:226
#define ACL_CREATE_TEMP
Definition: parsenodes.h:85
#define ACL_ID_PUBLIC
Definition: acl.h:46
#define ACLITEM_SET_PRIVS_GOPTIONS(item, privs, goptions)
Definition: acl.h:82
#define read(a, b, c)
Definition: win32.h:13
#define ACL_EXECUTE_CHR
Definition: acl.h:144
#define ACL_CREATE_CHR
Definition: acl.h:146
#define ACL_TRUNCATE
Definition: parsenodes.h:78

◆ aclremove()

Datum aclremove ( PG_FUNCTION_ARGS  )

Definition at line 1543 of file acl.c.

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

1544 {
1545  ereport(ERROR,
1546  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1547  errmsg("aclremove is no longer supported")));
1548 
1549  PG_RETURN_NULL(); /* keep compiler quiet */
1550 }
int errcode(int sqlerrcode)
Definition: elog.c:570
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:141
int errmsg(const char *fmt,...)
Definition: elog.c:784
#define PG_RETURN_NULL()
Definition: fmgr.h:335

◆ aclupdate()

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

Definition at line 931 of file acl.c.

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, AclItem::ai_grantee, AclItem::ai_grantor, allocacl(), ARR_DIMS, Assert, check_acl(), check_circularity(), memmove, recursive_revoke(), and SET_VARSIZE.

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

933 {
934  Acl *new_acl = NULL;
935  AclItem *old_aip,
936  *new_aip = NULL;
937  AclMode old_rights,
938  old_goptions,
939  new_rights,
940  new_goptions;
941  int dst,
942  num;
943 
944  /* Caller probably already checked old_acl, but be safe */
945  check_acl(old_acl);
946 
947  /* If granting grant options, check for circularity */
948  if (modechg != ACL_MODECHG_DEL &&
949  ACLITEM_GET_GOPTIONS(*mod_aip) != ACL_NO_RIGHTS)
950  check_circularity(old_acl, mod_aip, ownerId);
951 
952  num = ACL_NUM(old_acl);
953  old_aip = ACL_DAT(old_acl);
954 
955  /*
956  * Search the ACL for an existing entry for this grantee and grantor. If
957  * one exists, just modify the entry in-place (well, in the same position,
958  * since we actually return a copy); otherwise, insert the new entry at
959  * the end.
960  */
961 
962  for (dst = 0; dst < num; ++dst)
963  {
964  if (aclitem_match(mod_aip, old_aip + dst))
965  {
966  /* found a match, so modify existing item */
967  new_acl = allocacl(num);
968  new_aip = ACL_DAT(new_acl);
969  memcpy(new_acl, old_acl, ACL_SIZE(old_acl));
970  break;
971  }
972  }
973 
974  if (dst == num)
975  {
976  /* need to append a new item */
977  new_acl = allocacl(num + 1);
978  new_aip = ACL_DAT(new_acl);
979  memcpy(new_aip, old_aip, num * sizeof(AclItem));
980 
981  /* initialize the new entry with no permissions */
982  new_aip[dst].ai_grantee = mod_aip->ai_grantee;
983  new_aip[dst].ai_grantor = mod_aip->ai_grantor;
984  ACLITEM_SET_PRIVS_GOPTIONS(new_aip[dst],
986  num++; /* set num to the size of new_acl */
987  }
988 
989  old_rights = ACLITEM_GET_RIGHTS(new_aip[dst]);
990  old_goptions = ACLITEM_GET_GOPTIONS(new_aip[dst]);
991 
992  /* apply the specified permissions change */
993  switch (modechg)
994  {
995  case ACL_MODECHG_ADD:
996  ACLITEM_SET_RIGHTS(new_aip[dst],
997  old_rights | ACLITEM_GET_RIGHTS(*mod_aip));
998  break;
999  case ACL_MODECHG_DEL:
1000  ACLITEM_SET_RIGHTS(new_aip[dst],
1001  old_rights & ~ACLITEM_GET_RIGHTS(*mod_aip));
1002  break;
1003  case ACL_MODECHG_EQL:
1004  ACLITEM_SET_RIGHTS(new_aip[dst],
1005  ACLITEM_GET_RIGHTS(*mod_aip));
1006  break;
1007  }
1008 
1009  new_rights = ACLITEM_GET_RIGHTS(new_aip[dst]);
1010  new_goptions = ACLITEM_GET_GOPTIONS(new_aip[dst]);
1011 
1012  /*
1013  * If the adjusted entry has no permissions, delete it from the list.
1014  */
1015  if (new_rights == ACL_NO_RIGHTS)
1016  {
1017  memmove(new_aip + dst,
1018  new_aip + dst + 1,
1019  (num - dst - 1) * sizeof(AclItem));
1020  /* Adjust array size to be 'num - 1' items */
1021  ARR_DIMS(new_acl)[0] = num - 1;
1022  SET_VARSIZE(new_acl, ACL_N_SIZE(num - 1));
1023  }
1024 
1025  /*
1026  * Remove abandoned privileges (cascading revoke). Currently we can only
1027  * handle this when the grantee is not PUBLIC.
1028  */
1029  if ((old_goptions & ~new_goptions) != 0)
1030  {
1031  Assert(mod_aip->ai_grantee != ACL_ID_PUBLIC);
1032  new_acl = recursive_revoke(new_acl, mod_aip->ai_grantee,
1033  (old_goptions & ~new_goptions),
1034  ownerId, behavior);
1035  }
1036 
1037  return new_acl;
1038 }
Oid ai_grantee
Definition: acl.h:56
#define ACL_MODECHG_EQL
Definition: acl.h:131
#define ACLITEM_GET_GOPTIONS(item)
Definition: acl.h:67
static Acl * allocacl(int n)
Definition: acl.c:377
#define ACL_MODECHG_DEL
Definition: acl.h:130
#define ACL_SIZE(ACL)
Definition: acl.h:111
Oid ai_grantor
Definition: acl.h:57
uint32 AclMode
Definition: parsenodes.h:72
static void check_circularity(const Acl *old_acl, const AclItem *mod_aip, Oid ownerId)
Definition: acl.c:1155
#define ARR_DIMS(a)
Definition: array.h:282
#define ACL_NUM(ACL)
Definition: acl.h:108
#define ACL_NO_RIGHTS
Definition: parsenodes.h:88
#define memmove(d, s, c)
Definition: c.h:1238
#define ACLITEM_GET_RIGHTS(item)
Definition: acl.h:68
#define ACLITEM_SET_RIGHTS(item, rights)
Definition: acl.h:79
#define ACL_MODECHG_ADD
Definition: acl.h:129
#define ACL_DAT(ACL)
Definition: acl.h:109
Definition: acl.h:54
#define Assert(condition)
Definition: c.h:732
static bool aclitem_match(const AclItem *a1, const AclItem *a2)
Definition: acl.c:659
static Acl * recursive_revoke(Acl *acl, Oid grantee, AclMode revoke_privs, Oid ownerId, DropBehavior behavior)
Definition: acl.c:1235
#define ACL_ID_PUBLIC
Definition: acl.h:46
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:329
#define ACL_N_SIZE(N)
Definition: acl.h:110
#define ACLITEM_SET_PRIVS_GOPTIONS(item, privs, goptions)
Definition: acl.h:82
static void check_acl(const Acl *acl)
Definition: acl.c:541

◆ allocacl()

static Acl * allocacl ( int  n)
static

Definition at line 377 of file acl.c.

References ACL_N_SIZE, ARR_DIMS, ARR_LBOUND, ArrayType::dataoffset, ArrayType::elemtype, elog, ERROR, ArrayType::ndim, palloc0(), and SET_VARSIZE.

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

378 {
379  Acl *new_acl;
380  Size size;
381 
382  if (n < 0)
383  elog(ERROR, "invalid size: %d", n);
384  size = ACL_N_SIZE(n);
385  new_acl = (Acl *) palloc0(size);
386  SET_VARSIZE(new_acl, size);
387  new_acl->ndim = 1;
388  new_acl->dataoffset = 0; /* we never put in any nulls */
389  new_acl->elemtype = ACLITEMOID;
390  ARR_LBOUND(new_acl)[0] = 1;
391  ARR_DIMS(new_acl)[0] = n;
392  return new_acl;
393 }
int32 dataoffset
Definition: array.h:84
#define ARR_LBOUND(a)
Definition: array.h:284
#define ERROR
Definition: elog.h:43
Oid elemtype
Definition: array.h:85
#define ARR_DIMS(a)
Definition: array.h:282
void * palloc0(Size size)
Definition: mcxt.c:955
size_t Size
Definition: c.h:466
#define elog(elevel,...)
Definition: elog.h:226
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:329
#define ACL_N_SIZE(N)
Definition: acl.h:110
int ndim
Definition: array.h:83

◆ check_acl()

static void check_acl ( const Acl acl)
static

Definition at line 541 of file acl.c.

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

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

542 {
543  if (ARR_ELEMTYPE(acl) != ACLITEMOID)
544  ereport(ERROR,
545  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
546  errmsg("ACL array contains wrong data type")));
547  if (ARR_NDIM(acl) != 1)
548  ereport(ERROR,
549  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
550  errmsg("ACL arrays must be one-dimensional")));
551  if (ARR_HASNULL(acl))
552  ereport(ERROR,
553  (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
554  errmsg("ACL arrays must not contain null values")));
555 }
int errcode(int sqlerrcode)
Definition: elog.c:570
#define ERROR
Definition: elog.h:43
#define ARR_HASNULL(a)
Definition: array.h:279
#define ereport(elevel, rest)
Definition: elog.h:141
#define ARR_NDIM(a)
Definition: array.h:278
int errmsg(const char *fmt,...)
Definition: elog.c:784
#define ARR_ELEMTYPE(a)
Definition: array.h:280

◆ check_circularity()

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

Definition at line 1155 of file acl.c.

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(), AclItem::ai_grantee, AclItem::ai_grantor, allocacl(), Assert, check_acl(), DROP_CASCADE, ereport, errcode(), errmsg(), ERROR, i, and pfree().

Referenced by aclupdate().

1157 {
1158  Acl *acl;
1159  AclItem *aip;
1160  int i,
1161  num;
1162  AclMode own_privs;
1163 
1164  check_acl(old_acl);
1165 
1166  /*
1167  * For now, grant options can only be granted to roles, not PUBLIC.
1168  * Otherwise we'd have to work a bit harder here.
1169  */
1170  Assert(mod_aip->ai_grantee != ACL_ID_PUBLIC);
1171 
1172  /* The owner always has grant options, no need to check */
1173  if (mod_aip->ai_grantor == ownerId)
1174  return;
1175 
1176  /* Make a working copy */
1177  acl = allocacl(ACL_NUM(old_acl));
1178  memcpy(acl, old_acl, ACL_SIZE(old_acl));
1179 
1180  /* Zap all grant options of target grantee, plus what depends on 'em */
1181 cc_restart:
1182  num = ACL_NUM(acl);
1183  aip = ACL_DAT(acl);
1184  for (i = 0; i < num; i++)
1185  {
1186  if (aip[i].ai_grantee == mod_aip->ai_grantee &&
1188  {
1189  Acl *new_acl;
1190 
1191  /* We'll actually zap ordinary privs too, but no matter */
1192  new_acl = aclupdate(acl, &aip[i], ACL_MODECHG_DEL,
1193  ownerId, DROP_CASCADE);
1194 
1195  pfree(acl);
1196  acl = new_acl;
1197 
1198  goto cc_restart;
1199  }
1200  }
1201 
1202  /* Now we can compute grantor's independently-derived privileges */
1203  own_privs = aclmask(acl,
1204  mod_aip->ai_grantor,
1205  ownerId,
1207  ACLMASK_ALL);
1208  own_privs = ACL_OPTION_TO_PRIVS(own_privs);
1209 
1210  if ((ACLITEM_GET_GOPTIONS(*mod_aip) & ~own_privs) != 0)
1211  ereport(ERROR,
1212  (errcode(ERRCODE_INVALID_GRANT_OPERATION),
1213  errmsg("grant options cannot be granted back to your own grantor")));
1214 
1215  pfree(acl);
1216 }
Oid ai_grantee
Definition: acl.h:56
#define ACLITEM_GET_GOPTIONS(item)
Definition: acl.h:67
static Acl * allocacl(int n)
Definition: acl.c:377
#define ACL_MODECHG_DEL
Definition: acl.h:130
AclMode aclmask(const Acl *acl, Oid roleid, Oid ownerId, AclMode mask, AclMaskHow how)
Definition: acl.c:1321
#define ACL_SIZE(ACL)
Definition: acl.h:111
int errcode(int sqlerrcode)
Definition: elog.c:570
Oid ai_grantor
Definition: acl.h:57
uint32 AclMode
Definition: parsenodes.h:72
void pfree(void *pointer)
Definition: mcxt.c:1031
#define ERROR
Definition: elog.h:43
#define ACL_NUM(ACL)
Definition: acl.h:108
#define ACL_NO_RIGHTS
Definition: parsenodes.h:88
#define ereport(elevel, rest)
Definition: elog.h:141
#define ACL_GRANT_OPTION_FOR(privs)
Definition: acl.h:70
#define ACL_DAT(ACL)
Definition: acl.h:109
Definition: acl.h:54
#define ACL_OPTION_TO_PRIVS(privs)
Definition: acl.h:71
#define Assert(condition)
Definition: c.h:732
int errmsg(const char *fmt,...)
Definition: elog.c:784
int i
#define ACL_ID_PUBLIC
Definition: acl.h:46
Acl * aclupdate(const Acl *old_acl, const AclItem *mod_aip, int modechg, Oid ownerId, DropBehavior behavior)
Definition: acl.c:931
static void check_acl(const Acl *acl)
Definition: acl.c:541

◆ check_is_member_of_role()

void check_is_member_of_role ( Oid  member,
Oid  role 
)

Definition at line 4954 of file acl.c.

References ereport, errcode(), errmsg(), ERROR, GetUserNameFromId(), and is_member_of_role().

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

4955 {
4956  if (!is_member_of_role(member, role))
4957  ereport(ERROR,
4958  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
4959  errmsg("must be member of role \"%s\"",
4960  GetUserNameFromId(role, false))));
4961 }
int errcode(int sqlerrcode)
Definition: elog.c:570
Oid member
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:141
bool is_member_of_role(Oid member, Oid role)
Definition: acl.c:4932
char * GetUserNameFromId(Oid roleid, bool noerr)
Definition: miscinit.c:795
int errmsg(const char *fmt,...)
Definition: elog.c:784

◆ check_rolespec_name()

void check_rolespec_name ( const RoleSpec role,
const char *  detail_msg 
)

Definition at line 5330 of file acl.c.

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

Referenced by AlterRole(), and AlterRoleSet().

5331 {
5332  if (!role)
5333  return;
5334 
5335  if (role->roletype != ROLESPEC_CSTRING)
5336  return;
5337 
5338  if (IsReservedName(role->rolename))
5339  {
5340  if (detail_msg)
5341  ereport(ERROR,
5342  (errcode(ERRCODE_RESERVED_NAME),
5343  errmsg("role name \"%s\" is reserved",
5344  role->rolename),
5345  errdetail("%s", detail_msg)));
5346  else
5347  ereport(ERROR,
5348  (errcode(ERRCODE_RESERVED_NAME),
5349  errmsg("role name \"%s\" is reserved",
5350  role->rolename)));
5351  }
5352 }
int errcode(int sqlerrcode)
Definition: elog.c:570
bool IsReservedName(const char *name)
Definition: catalog.c:214
#define ERROR
Definition: elog.h:43
int errdetail(const char *fmt,...)
Definition: elog.c:860
#define ereport(elevel, rest)
Definition: elog.h:141
RoleSpecType roletype
Definition: parsenodes.h:328
char * rolename
Definition: parsenodes.h:329
int errmsg(const char *fmt,...)
Definition: elog.c:784

◆ column_privilege_check()

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

Definition at line 2466 of file acl.c.

References ACLCHECK_OK, ATTNUM, GETSTRUCT, HeapTupleIsValid, Int16GetDatum, InvalidAttrNumber, ObjectIdGetDatum, pg_attribute_aclcheck(), pg_class_aclcheck(), ReleaseSysCache(), RELOID, SearchSysCache2(), and SearchSysCacheExists1.

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().

2468 {
2469  AclResult aclresult;
2470  HeapTuple attTuple;
2471  Form_pg_attribute attributeForm;
2472 
2473  /*
2474  * If convert_column_name failed, we can just return -1 immediately.
2475  */
2476  if (attnum == InvalidAttrNumber)
2477  return -1;
2478 
2479  /*
2480  * First check if we have the privilege at the table level. We check
2481  * existence of the pg_class row before risking calling pg_class_aclcheck.
2482  * Note: it might seem there's a race condition against concurrent DROP,
2483  * but really it's safe because there will be no syscache flush between
2484  * here and there. So if we see the row in the syscache, so will
2485  * pg_class_aclcheck.
2486  */
2488  return -1;
2489 
2490  aclresult = pg_class_aclcheck(tableoid, roleid, mode);
2491 
2492  if (aclresult == ACLCHECK_OK)
2493  return true;
2494 
2495  /*
2496  * No table privilege, so try per-column privileges. Again, we have to
2497  * check for dropped attribute first, and we rely on the syscache not to
2498  * notice a concurrent drop before pg_attribute_aclcheck fetches the row.
2499  */
2500  attTuple = SearchSysCache2(ATTNUM,
2501  ObjectIdGetDatum(tableoid),
2503  if (!HeapTupleIsValid(attTuple))
2504  return -1;
2505  attributeForm = (Form_pg_attribute) GETSTRUCT(attTuple);
2506  if (attributeForm->attisdropped)
2507  {
2508  ReleaseSysCache(attTuple);
2509  return -1;
2510  }
2511  ReleaseSysCache(attTuple);
2512 
2513  aclresult = pg_attribute_aclcheck(tableoid, attnum, roleid, mode);
2514 
2515  return (aclresult == ACLCHECK_OK);
2516 }
static PgChecksumMode mode
Definition: pg_checksums.c:61
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
AclResult pg_attribute_aclcheck(Oid table_oid, AttrNumber attnum, Oid roleid, AclMode mode)
Definition: aclchk.c:4517
#define Int16GetDatum(X)
Definition: postgres.h:451
#define SearchSysCacheExists1(cacheId, key1)
Definition: syscache.h:183
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:200
AclResult
Definition: acl.h:177
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1172
int16 attnum
Definition: pg_attribute.h:79
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
HeapTuple SearchSysCache2(int cacheId, Datum key1, Datum key2)
Definition: syscache.c:1135
#define InvalidAttrNumber
Definition: attnum.h:23
AclResult pg_class_aclcheck(Oid table_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4631

◆ convert_aclright_to_string()

static const char* convert_aclright_to_string ( int  aclright)
static

Definition at line 1696 of file acl.c.

References ACL_CONNECT, ACL_CREATE, ACL_CREATE_TEMP, ACL_DELETE, ACL_EXECUTE, ACL_INSERT, ACL_REFERENCES, ACL_SELECT, ACL_TRIGGER, ACL_TRUNCATE, ACL_UPDATE, ACL_USAGE, elog, and ERROR.

Referenced by aclexplode().

1697 {
1698  switch (aclright)
1699  {
1700  case ACL_INSERT:
1701  return "INSERT";
1702  case ACL_SELECT:
1703  return "SELECT";
1704  case ACL_UPDATE:
1705  return "UPDATE";
1706  case ACL_DELETE:
1707  return "DELETE";
1708  case ACL_TRUNCATE:
1709  return "TRUNCATE";
1710  case ACL_REFERENCES:
1711  return "REFERENCES";
1712  case ACL_TRIGGER:
1713  return "TRIGGER";
1714  case ACL_EXECUTE:
1715  return "EXECUTE";
1716  case ACL_USAGE:
1717  return "USAGE";
1718  case ACL_CREATE:
1719  return "CREATE";
1720  case ACL_CREATE_TEMP:
1721  return "TEMPORARY";
1722  case ACL_CONNECT:
1723  return "CONNECT";
1724  default:
1725  elog(ERROR, "unrecognized aclright: %d", aclright);
1726  return NULL;
1727  }
1728 }
#define ACL_DELETE
Definition: parsenodes.h:77
#define ERROR
Definition: elog.h:43
#define ACL_CREATE
Definition: parsenodes.h:84
#define ACL_TRIGGER
Definition: parsenodes.h:80
#define ACL_USAGE
Definition: parsenodes.h:82
#define ACL_CONNECT
Definition: parsenodes.h:86
#define ACL_UPDATE
Definition: parsenodes.h:76
#define ACL_SELECT
Definition: parsenodes.h:75
#define ACL_REFERENCES
Definition: parsenodes.h:79
#define ACL_INSERT
Definition: parsenodes.h:74
#define ACL_EXECUTE
Definition: parsenodes.h:81
#define elog(elevel,...)
Definition: elog.h:226
#define ACL_CREATE_TEMP
Definition: parsenodes.h:85
#define ACL_TRUNCATE
Definition: parsenodes.h:78

◆ convert_any_priv_string()

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

Definition at line 1648 of file acl.c.

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

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_role_priv_string(), convert_schema_priv_string(), convert_sequence_priv_string(), convert_server_priv_string(), convert_table_priv_string(), convert_tablespace_priv_string(), and convert_type_priv_string().

1650 {
1651  AclMode result = 0;
1652  char *priv_type = text_to_cstring(priv_type_text);
1653  char *chunk;
1654  char *next_chunk;
1655 
1656  /* We rely on priv_type being a private, modifiable string */
1657  for (chunk = priv_type; chunk; chunk = next_chunk)
1658  {
1659  int chunk_len;
1660  const priv_map *this_priv;
1661 
1662  /* Split string at commas */
1663  next_chunk = strchr(chunk, ',');
1664  if (next_chunk)
1665  *next_chunk++ = '\0';
1666 
1667  /* Drop leading/trailing whitespace in this chunk */
1668  while (*chunk && isspace((unsigned char) *chunk))
1669  chunk++;
1670  chunk_len = strlen(chunk);
1671  while (chunk_len > 0 && isspace((unsigned char) chunk[chunk_len - 1]))
1672  chunk_len--;
1673  chunk[chunk_len] = '\0';
1674 
1675  /* Match to the privileges list */
1676  for (this_priv = privileges; this_priv->name; this_priv++)
1677  {
1678  if (pg_strcasecmp(this_priv->name, chunk) == 0)
1679  {
1680  result |= this_priv->value;
1681  break;
1682  }
1683  }
1684  if (!this_priv->name)
1685  ereport(ERROR,
1686  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1687  errmsg("unrecognized privilege type: \"%s\"", chunk)));
1688  }
1689 
1690  pfree(priv_type);
1691  return result;
1692 }
Definition: acl.c:44
int errcode(int sqlerrcode)
Definition: elog.c:570
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
const char * name
Definition: acl.c:46
uint32 AclMode
Definition: parsenodes.h:72
void pfree(void *pointer)
Definition: mcxt.c:1031
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:141
AclMode value
Definition: acl.c:47
char * text_to_cstring(const text *t)
Definition: varlena.c:204
int errmsg(const char *fmt,...)
Definition: elog.c:784

◆ convert_column_name()

static AttrNumber convert_column_name ( Oid  tableoid,
text column 
)
static

Definition at line 2844 of file acl.c.

References ATTNAME, attnum, CStringGetDatum, ereport, errcode(), errmsg(), ERROR, 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().

2845 {
2846  char *colname;
2847  HeapTuple attTuple;
2849 
2850  colname = text_to_cstring(column);
2851 
2852  /*
2853  * We don't use get_attnum() here because it will report that dropped
2854  * columns don't exist. We need to treat dropped columns differently from
2855  * nonexistent columns.
2856  */
2857  attTuple = SearchSysCache2(ATTNAME,
2858  ObjectIdGetDatum(tableoid),
2859  CStringGetDatum(colname));
2860  if (HeapTupleIsValid(attTuple))
2861  {
2862  Form_pg_attribute attributeForm;
2863 
2864  attributeForm = (Form_pg_attribute) GETSTRUCT(attTuple);
2865  /* We want to return NULL for dropped columns */
2866  if (attributeForm->attisdropped)
2867  attnum = InvalidAttrNumber;
2868  else
2869  attnum = attributeForm->attnum;
2870  ReleaseSysCache(attTuple);
2871  }
2872  else
2873  {
2874  char *tablename = get_rel_name(tableoid);
2875 
2876  /*
2877  * If the table OID is bogus, or it's just been dropped, we'll get
2878  * NULL back. In such cases we want has_column_privilege to return
2879  * NULL too, so just return InvalidAttrNumber.
2880  */
2881  if (tablename != NULL)
2882  {
2883  /* tableoid exists, colname does not, so throw error */
2884  ereport(ERROR,
2885  (errcode(ERRCODE_UNDEFINED_COLUMN),
2886  errmsg("column \"%s\" of relation \"%s\" does not exist",
2887  colname, tablename)));
2888  }
2889  /* tableoid doesn't exist, so act like attisdropped case */
2890  attnum = InvalidAttrNumber;
2891  }
2892 
2893  pfree(colname);
2894  return attnum;
2895 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
int errcode(int sqlerrcode)
Definition: elog.c:570
void pfree(void *pointer)
Definition: mcxt.c:1031
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ERROR
Definition: elog.h:43
#define CStringGetDatum(X)
Definition: postgres.h:578
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:200
#define ereport(elevel, rest)
Definition: elog.h:141
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1172
int16 attnum
Definition: pg_attribute.h:79
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
HeapTuple SearchSysCache2(int cacheId, Datum key1, Datum key2)
Definition: syscache.c:1135
#define InvalidAttrNumber
Definition: attnum.h:23
char * text_to_cstring(const text *t)
Definition: varlena.c:204
int errmsg(const char *fmt,...)
Definition: elog.c:784
char * get_rel_name(Oid relid)
Definition: lsyscache.c:1730
int16 AttrNumber
Definition: attnum.h:21

◆ convert_column_priv_string()

static AclMode convert_column_priv_string ( text priv_type_text)
static

Definition at line 2902 of file acl.c.

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

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().

2903 {
2904  static const priv_map column_priv_map[] = {
2905  {"SELECT", ACL_SELECT},
2906  {"SELECT WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_SELECT)},
2907  {"INSERT", ACL_INSERT},
2908  {"INSERT WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_INSERT)},
2909  {"UPDATE", ACL_UPDATE},
2910  {"UPDATE WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_UPDATE)},
2911  {"REFERENCES", ACL_REFERENCES},
2912  {"REFERENCES WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_REFERENCES)},
2913  {NULL, 0}
2914  };
2915 
2916  return convert_any_priv_string(priv_type_text, column_priv_map);
2917 }
Definition: acl.c:44
static AclMode convert_any_priv_string(text *priv_type_text, const priv_map *privileges)
Definition: acl.c:1648
#define ACL_UPDATE
Definition: parsenodes.h:76
#define ACL_GRANT_OPTION_FOR(privs)
Definition: acl.h:70
#define ACL_SELECT
Definition: parsenodes.h:75
#define ACL_REFERENCES
Definition: parsenodes.h:79
#define ACL_INSERT
Definition: parsenodes.h:74

◆ convert_database_name()

static Oid convert_database_name ( text databasename)
static

Definition at line 3087 of file acl.c.

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

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

3088 {
3089  char *dbname = text_to_cstring(databasename);
3090 
3091  return get_database_oid(dbname, false);
3092 }
Oid get_database_oid(const char *dbname, bool missing_ok)
Definition: dbcommands.c:2052
char * dbname
Definition: streamutil.c:52
char * text_to_cstring(const text *t)
Definition: varlena.c:204

◆ convert_database_priv_string()

static AclMode convert_database_priv_string ( text priv_type_text)
static

Definition at line 3099 of file acl.c.

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

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().

3100 {
3101  static const priv_map database_priv_map[] = {
3102  {"CREATE", ACL_CREATE},
3103  {"CREATE WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_CREATE)},
3104  {"TEMPORARY", ACL_CREATE_TEMP},
3105  {"TEMPORARY WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_CREATE_TEMP)},
3106  {"TEMP", ACL_CREATE_TEMP},
3107  {"TEMP WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_CREATE_TEMP)},
3108  {"CONNECT", ACL_CONNECT},
3109  {"CONNECT WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_CONNECT)},
3110  {NULL, 0}
3111  };
3112 
3113  return convert_any_priv_string(priv_type_text, database_priv_map);
3114 
3115 }
Definition: acl.c:44
static AclMode convert_any_priv_string(text *priv_type_text, const priv_map *privileges)
Definition: acl.c:1648
#define ACL_CREATE
Definition: parsenodes.h:84
#define ACL_CONNECT
Definition: parsenodes.h:86
#define ACL_GRANT_OPTION_FOR(privs)
Definition: acl.h:70
#define ACL_CREATE_TEMP
Definition: parsenodes.h:85

◆ convert_foreign_data_wrapper_name()

static Oid convert_foreign_data_wrapper_name ( text fdwname)
static

Definition at line 3285 of file acl.c.

References 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().

3286 {
3287  char *fdwstr = text_to_cstring(fdwname);
3288 
3289  return get_foreign_data_wrapper_oid(fdwstr, false);
3290 }
Oid get_foreign_data_wrapper_oid(const char *fdwname, bool missing_ok)
Definition: foreign.c:691
char * text_to_cstring(const text *t)
Definition: varlena.c:204

◆ convert_foreign_data_wrapper_priv_string()

static AclMode convert_foreign_data_wrapper_priv_string ( text priv_type_text)
static

Definition at line 3297 of file acl.c.

References ACL_GRANT_OPTION_FOR, ACL_USAGE, and convert_any_priv_string().

Referenced by has_foreign_data_wrapper_privilege_id(), has_foreign_data_wrapper_privilege_id_id(), has_foreign_data_wrapper_privilege_id_name(), has_foreign_data_wrapper_privilege_name(), has_foreign_data_wrapper_privilege_name_id(), and has_foreign_data_wrapper_privilege_name_name().

3298 {
3299  static const priv_map foreign_data_wrapper_priv_map[] = {
3300  {"USAGE", ACL_USAGE},
3301  {"USAGE WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_USAGE)},
3302  {NULL, 0}
3303  };
3304 
3305  return convert_any_priv_string(priv_type_text, foreign_data_wrapper_priv_map);
3306 }
Definition: acl.c:44
static AclMode convert_any_priv_string(text *priv_type_text, const priv_map *privileges)
Definition: acl.c:1648
#define ACL_USAGE
Definition: parsenodes.h:82
#define ACL_GRANT_OPTION_FOR(privs)
Definition: acl.h:70

◆ convert_function_name()

static Oid convert_function_name ( text functionname)
static

Definition at line 3476 of file acl.c.

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

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

3477 {
3478  char *funcname = text_to_cstring(functionname);
3479  Oid oid;
3480 
3482  CStringGetDatum(funcname)));
3483 
3484  if (!OidIsValid(oid))
3485  ereport(ERROR,
3486  (errcode(ERRCODE_UNDEFINED_FUNCTION),
3487  errmsg("function \"%s\" does not exist", funcname)));
3488 
3489  return oid;
3490 }
#define DatumGetObjectId(X)
Definition: postgres.h:500
int errcode(int sqlerrcode)
Definition: elog.c:570
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:616
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:638
#define ERROR
Definition: elog.h:43
Datum regprocedurein(PG_FUNCTION_ARGS)
Definition: regproc.c:231
#define CStringGetDatum(X)
Definition: postgres.h:578
#define ereport(elevel, rest)
Definition: elog.h:141
char * text_to_cstring(const text *t)
Definition: varlena.c:204
int errmsg(const char *fmt,...)
Definition: elog.c:784

◆ convert_function_priv_string()

static AclMode convert_function_priv_string ( text priv_type_text)
static

Definition at line 3497 of file acl.c.

References ACL_EXECUTE, ACL_GRANT_OPTION_FOR, and convert_any_priv_string().

Referenced by has_function_privilege_id(), has_function_privilege_id_id(), has_function_privilege_id_name(), has_function_privilege_name(), has_function_privilege_name_id(), and has_function_privilege_name_name().

3498 {
3499  static const priv_map function_priv_map[] = {
3500  {"EXECUTE", ACL_EXECUTE},
3501  {"EXECUTE WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_EXECUTE)},
3502  {NULL, 0}
3503  };
3504 
3505  return convert_any_priv_string(priv_type_text, function_priv_map);
3506 }
Definition: acl.c:44
static AclMode convert_any_priv_string(text *priv_type_text, const priv_map *privileges)
Definition: acl.c:1648
#define ACL_GRANT_OPTION_FOR(privs)
Definition: acl.h:70
#define ACL_EXECUTE
Definition: parsenodes.h:81

◆ convert_language_name()

static Oid convert_language_name ( text languagename)
static

Definition at line 3676 of file acl.c.

References get_language_oid(), and text_to_cstring().

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

3677 {
3678  char *langname = text_to_cstring(languagename);
3679 
3680  return get_language_oid(langname, false);
3681 }
Oid get_language_oid(const char *langname, bool missing_ok)
Definition: proclang.c:559
char * text_to_cstring(const text *t)
Definition: varlena.c:204

◆ convert_language_priv_string()

static AclMode convert_language_priv_string ( text priv_type_text)
static

Definition at line 3688 of file acl.c.

References ACL_GRANT_OPTION_FOR, ACL_USAGE, and convert_any_priv_string().

Referenced by has_language_privilege_id(), has_language_privilege_id_id(), has_language_privilege_id_name(), has_language_privilege_name(), has_language_privilege_name_id(), and has_language_privilege_name_name().

3689 {
3690  static const priv_map language_priv_map[] = {
3691  {"USAGE", ACL_USAGE},
3692  {"USAGE WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_USAGE)},
3693  {NULL, 0}
3694  };
3695 
3696  return convert_any_priv_string(priv_type_text, language_priv_map);
3697 }
Definition: acl.c:44
static AclMode convert_any_priv_string(text *priv_type_text, const priv_map *privileges)
Definition: acl.c:1648
#define ACL_USAGE
Definition: parsenodes.h:82
#define ACL_GRANT_OPTION_FOR(privs)
Definition: acl.h:70

◆ convert_priv_string()

static AclMode convert_priv_string ( text priv_type_text)
static

Definition at line 1598 of file acl.c.

References ACL_CONNECT, ACL_CREATE, ACL_CREATE_TEMP, ACL_DELETE, ACL_EXECUTE, ACL_INSERT, ACL_NO_RIGHTS, ACL_REFERENCES, ACL_SELECT, ACL_TRIGGER, ACL_TRUNCATE, ACL_UPDATE, ACL_USAGE, ereport, errcode(), errmsg(), ERROR, pg_strcasecmp(), and text_to_cstring().

Referenced by makeaclitem().

1599 {
1600  char *priv_type = text_to_cstring(priv_type_text);
1601 
1602  if (pg_strcasecmp(priv_type, "SELECT") == 0)
1603  return ACL_SELECT;
1604  if (pg_strcasecmp(priv_type, "INSERT") == 0)
1605  return ACL_INSERT;
1606  if (pg_strcasecmp(priv_type, "UPDATE") == 0)
1607  return ACL_UPDATE;
1608  if (pg_strcasecmp(priv_type, "DELETE") == 0)
1609  return ACL_DELETE;
1610  if (pg_strcasecmp(priv_type, "TRUNCATE") == 0)
1611  return ACL_TRUNCATE;
1612  if (pg_strcasecmp(priv_type, "REFERENCES") == 0)
1613  return ACL_REFERENCES;
1614  if (pg_strcasecmp(priv_type, "TRIGGER") == 0)
1615  return ACL_TRIGGER;
1616  if (pg_strcasecmp(priv_type, "EXECUTE") == 0)
1617  return ACL_EXECUTE;
1618  if (pg_strcasecmp(priv_type, "USAGE") == 0)
1619  return ACL_USAGE;
1620  if (pg_strcasecmp(priv_type, "CREATE") == 0)
1621  return ACL_CREATE;
1622  if (pg_strcasecmp(priv_type, "TEMP") == 0)
1623  return ACL_CREATE_TEMP;
1624  if (pg_strcasecmp(priv_type, "TEMPORARY") == 0)
1625  return ACL_CREATE_TEMP;
1626  if (pg_strcasecmp(priv_type, "CONNECT") == 0)
1627  return ACL_CONNECT;
1628  if (pg_strcasecmp(priv_type, "RULE") == 0)
1629  return 0; /* ignore old RULE privileges */
1630 
1631  ereport(ERROR,
1632  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1633  errmsg("unrecognized privilege type: \"%s\"", priv_type)));
1634  return ACL_NO_RIGHTS; /* keep compiler quiet */
1635 }
int errcode(int sqlerrcode)
Definition: elog.c:570
#define ACL_DELETE
Definition: parsenodes.h:77
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
#define ERROR
Definition: elog.h:43
#define ACL_CREATE
Definition: parsenodes.h:84
#define ACL_NO_RIGHTS
Definition: parsenodes.h:88
#define ACL_TRIGGER
Definition: parsenodes.h:80
#define ACL_USAGE
Definition: parsenodes.h:82
#define ereport(elevel, rest)
Definition: elog.h:141
#define ACL_CONNECT
Definition: parsenodes.h:86
#define ACL_UPDATE
Definition: parsenodes.h:76
#define ACL_SELECT
Definition: parsenodes.h:75
#define ACL_REFERENCES
Definition: parsenodes.h:79
#define ACL_INSERT
Definition: parsenodes.h:74
char * text_to_cstring(const text *t)
Definition: varlena.c:204
int errmsg(const char *fmt,...)
Definition: elog.c:784
#define ACL_EXECUTE
Definition: parsenodes.h:81
#define ACL_CREATE_TEMP
Definition: parsenodes.h:85
#define ACL_TRUNCATE
Definition: parsenodes.h:78

◆ convert_role_priv_string()

static AclMode convert_role_priv_string ( text priv_type_text)
static

Definition at line 4639 of file acl.c.

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

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().

4640 {
4641  static const priv_map role_priv_map[] = {
4642  {"USAGE", ACL_USAGE},
4643  {"MEMBER", ACL_CREATE},
4644  {"USAGE WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_CREATE)},
4645  {"USAGE WITH ADMIN OPTION", ACL_GRANT_OPTION_FOR(ACL_CREATE)},
4646  {"MEMBER WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_CREATE)},
4647  {"MEMBER WITH ADMIN OPTION", ACL_GRANT_OPTION_FOR(ACL_CREATE)},
4648  {NULL, 0}
4649  };
4650 
4651  return convert_any_priv_string(priv_type_text, role_priv_map);
4652 }
Definition: acl.c:44
static AclMode convert_any_priv_string(text *priv_type_text, const priv_map *privileges)
Definition: acl.c:1648
#define ACL_CREATE
Definition: parsenodes.h:84
#define ACL_USAGE
Definition: parsenodes.h:82
#define ACL_GRANT_OPTION_FOR(privs)
Definition: acl.h:70

◆ convert_schema_name()

static Oid convert_schema_name ( text schemaname)
static

Definition at line 3867 of file acl.c.

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().

3868 {
3869  char *nspname = text_to_cstring(schemaname);
3870 
3871  return get_namespace_oid(nspname, false);
3872 }
Oid get_namespace_oid(const char *nspname, bool missing_ok)
Definition: namespace.c:3035
char * text_to_cstring(const text *t)
Definition: varlena.c:204

◆ convert_schema_priv_string()

static AclMode convert_schema_priv_string ( text priv_type_text)
static

Definition at line 3879 of file acl.c.

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

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().

3880 {
3881  static const priv_map schema_priv_map[] = {
3882  {"CREATE", ACL_CREATE},
3883  {"CREATE WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_CREATE)},
3884  {"USAGE", ACL_USAGE},
3885  {"USAGE WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_USAGE)},
3886  {NULL, 0}
3887  };
3888 
3889  return convert_any_priv_string(priv_type_text, schema_priv_map);
3890 }
Definition: acl.c:44
static AclMode convert_any_priv_string(text *priv_type_text, const priv_map *privileges)
Definition: acl.c:1648
#define ACL_CREATE
Definition: parsenodes.h:84
#define ACL_USAGE
Definition: parsenodes.h:82
#define ACL_GRANT_OPTION_FOR(privs)
Definition: acl.h:70

◆ convert_sequence_priv_string()

static AclMode convert_sequence_priv_string ( text priv_type_text)
static

Definition at line 2241 of file acl.c.

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

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().

2242 {
2243  static const priv_map sequence_priv_map[] = {
2244  {"USAGE", ACL_USAGE},
2245  {"USAGE WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_USAGE)},
2246  {"SELECT", ACL_SELECT},
2247  {"SELECT WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_SELECT)},
2248  {"UPDATE", ACL_UPDATE},
2249  {"UPDATE WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_UPDATE)},
2250  {NULL, 0}
2251  };
2252 
2253  return convert_any_priv_string(priv_type_text, sequence_priv_map);
2254 }
Definition: acl.c:44
static AclMode convert_any_priv_string(text *priv_type_text, const priv_map *privileges)
Definition: acl.c:1648
#define ACL_USAGE
Definition: parsenodes.h:82
#define ACL_UPDATE
Definition: parsenodes.h:76
#define ACL_GRANT_OPTION_FOR(privs)
Definition: acl.h:70
#define ACL_SELECT
Definition: parsenodes.h:75

◆ convert_server_name()

static Oid convert_server_name ( text servername)
static

Definition at line 4060 of file acl.c.

References 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().

4061 {
4062  char *serverstr = text_to_cstring(servername);
4063 
4064  return get_foreign_server_oid(serverstr, false);
4065 }
char * text_to_cstring(const text *t)
Definition: varlena.c:204
Oid get_foreign_server_oid(const char *servername, bool missing_ok)
Definition: foreign.c:714

◆ convert_server_priv_string()

static AclMode convert_server_priv_string ( text priv_type_text)
static

Definition at line 4072 of file acl.c.

References ACL_GRANT_OPTION_FOR, ACL_USAGE, and convert_any_priv_string().

Referenced by has_server_privilege_id(), has_server_privilege_id_id(), has_server_privilege_id_name(), has_server_privilege_name(), has_server_privilege_name_id(), and has_server_privilege_name_name().

4073 {
4074  static const priv_map server_priv_map[] = {
4075  {"USAGE", ACL_USAGE},
4076  {"USAGE WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_USAGE)},
4077  {NULL, 0}
4078  };
4079 
4080  return convert_any_priv_string(priv_type_text, server_priv_map);
4081 }
Definition: acl.c:44
static AclMode convert_any_priv_string(text *priv_type_text, const priv_map *privileges)
Definition: acl.c:1648
#define ACL_USAGE
Definition: parsenodes.h:82
#define ACL_GRANT_OPTION_FOR(privs)
Definition: acl.h:70

◆ convert_table_name()

static Oid convert_table_name ( text tablename)
static

◆ convert_table_priv_string()

static AclMode convert_table_priv_string ( text priv_type_text)
static

Definition at line 2018 of file acl.c.

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

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().

2019 {
2020  static const priv_map table_priv_map[] = {
2021  {"SELECT", ACL_SELECT},
2022  {"SELECT WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_SELECT)},
2023  {"INSERT", ACL_INSERT},
2024  {"INSERT WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_INSERT)},
2025  {"UPDATE", ACL_UPDATE},
2026  {"UPDATE WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_UPDATE)},
2027  {"DELETE", ACL_DELETE},
2028  {"DELETE WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_DELETE)},
2029  {"TRUNCATE", ACL_TRUNCATE},
2030  {"TRUNCATE WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_TRUNCATE)},
2031  {"REFERENCES", ACL_REFERENCES},
2032  {"REFERENCES WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_REFERENCES)},
2033  {"TRIGGER", ACL_TRIGGER},
2034  {"TRIGGER WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_TRIGGER)},
2035  {"RULE", 0}, /* ignore old RULE privileges */
2036  {"RULE WITH GRANT OPTION", 0},
2037  {NULL, 0}
2038  };
2039 
2040  return convert_any_priv_string(priv_type_text, table_priv_map);
2041 }
Definition: acl.c:44
#define ACL_DELETE
Definition: parsenodes.h:77
static AclMode convert_any_priv_string(text *priv_type_text, const priv_map *privileges)
Definition: acl.c:1648
#define ACL_TRIGGER
Definition: parsenodes.h:80
#define ACL_UPDATE
Definition: parsenodes.h:76
#define ACL_GRANT_OPTION_FOR(privs)
Definition: acl.h:70
#define ACL_SELECT
Definition: parsenodes.h:75
#define ACL_REFERENCES
Definition: parsenodes.h:79
#define ACL_INSERT
Definition: parsenodes.h:74
#define ACL_TRUNCATE
Definition: parsenodes.h:78

◆ convert_tablespace_name()

static Oid convert_tablespace_name ( text tablespacename)
static

Definition at line 4251 of file acl.c.

References get_tablespace_oid(), and text_to_cstring().

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

4252 {
4253  char *spcname = text_to_cstring(tablespacename);
4254 
4255  return get_tablespace_oid(spcname, false);
4256 }
Oid get_tablespace_oid(const char *tablespacename, bool missing_ok)
Definition: tablespace.c:1417
char * text_to_cstring(const text *t)
Definition: varlena.c:204

◆ convert_tablespace_priv_string()

static AclMode convert_tablespace_priv_string ( text priv_type_text)
static

Definition at line 4263 of file acl.c.

References ACL_CREATE, ACL_GRANT_OPTION_FOR, and convert_any_priv_string().

Referenced by has_tablespace_privilege_id(), has_tablespace_privilege_id_id(), has_tablespace_privilege_id_name(), has_tablespace_privilege_name(), has_tablespace_privilege_name_id(), and has_tablespace_privilege_name_name().

4264 {
4265  static const priv_map tablespace_priv_map[] = {
4266  {"CREATE", ACL_CREATE},
4267  {"CREATE WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_CREATE)},
4268  {NULL, 0}
4269  };
4270 
4271  return convert_any_priv_string(priv_type_text, tablespace_priv_map);
4272 }
Definition: acl.c:44
static AclMode convert_any_priv_string(text *priv_type_text, const priv_map *privileges)
Definition: acl.c:1648
#define ACL_CREATE
Definition: parsenodes.h:84
#define ACL_GRANT_OPTION_FOR(privs)
Definition: acl.h:70

◆ convert_type_name()

static Oid convert_type_name ( text typename)
static

Definition at line 4441 of file acl.c.

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

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

4442 {
4443  char *typname = text_to_cstring(typename);
4444  Oid oid;
4445 
4447  CStringGetDatum(typname)));
4448 
4449  if (!OidIsValid(oid))
4450  ereport(ERROR,
4451  (errcode(ERRCODE_UNDEFINED_OBJECT),
4452  errmsg("type \"%s\" does not exist", typname)));
4453 
4454  return oid;
4455 }
#define DatumGetObjectId(X)
Definition: postgres.h:500
int errcode(int sqlerrcode)
Definition: elog.c:570
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:616
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:638
#define ERROR
Definition: elog.h:43
#define CStringGetDatum(X)
Definition: postgres.h:578
#define ereport(elevel, rest)
Definition: elog.h:141
NameData typname
Definition: pg_type.h:42
Datum regtypein(PG_FUNCTION_ARGS)
Definition: regproc.c:1061
char * text_to_cstring(const text *t)
Definition: varlena.c:204
int errmsg(const char *fmt,...)
Definition: elog.c:784

◆ convert_type_priv_string()

static AclMode convert_type_priv_string ( text priv_type_text)
static

Definition at line 4462 of file acl.c.

References ACL_GRANT_OPTION_FOR, ACL_USAGE, and convert_any_priv_string().

Referenced by has_type_privilege_id(), has_type_privilege_id_id(), has_type_privilege_id_name(), has_type_privilege_name(), has_type_privilege_name_id(), and has_type_privilege_name_name().

4463 {
4464  static const priv_map type_priv_map[] = {
4465  {"USAGE", ACL_USAGE},
4466  {"USAGE WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_USAGE)},
4467  {NULL, 0}
4468  };
4469 
4470  return convert_any_priv_string(priv_type_text, type_priv_map);
4471 }
Definition: acl.c:44
static AclMode convert_any_priv_string(text *priv_type_text, const priv_map *privileges)
Definition: acl.c:1648
#define ACL_USAGE
Definition: parsenodes.h:82
#define ACL_GRANT_OPTION_FOR(privs)
Definition: acl.h:70

◆ count_one_bits()

static int count_one_bits ( AclMode  mask)
static

Definition at line 5076 of file acl.c.

Referenced by select_best_grantor().

5077 {
5078  int nbits = 0;
5079 
5080  /* this code relies on AclMode being an unsigned type */
5081  while (mask)
5082  {
5083  if (mask & 1)
5084  nbits++;
5085  mask >>= 1;
5086  }
5087  return nbits;
5088 }

◆ get_role_oid()

Oid get_role_oid ( const char *  rolname,
bool  missing_ok 
)

Definition at line 5191 of file acl.c.

References AUTHNAME, CStringGetDatum, ereport, errcode(), errmsg(), ERROR, GetSysCacheOid1, and OidIsValid.

Referenced by aclparse(), check_hba(), createdb(), CreateRole(), get_object_address_unqualified(), get_role_oid_or_public(), get_rolespec_oid(), GrantRole(), is_member(), pg_has_role_id_name(), pg_has_role_name(), pg_has_role_name_id(), pg_has_role_name_name(), regrolein(), and to_regrole().

5192 {
5193  Oid oid;
5194 
5195  oid = GetSysCacheOid1(AUTHNAME, Anum_pg_authid_oid,
5197  if (!OidIsValid(oid) && !missing_ok)
5198  ereport(ERROR,
5199  (errcode(ERRCODE_UNDEFINED_OBJECT),
5200  errmsg("role \"%s\" does not exist", rolname)));
5201  return oid;
5202 }
NameData rolname
Definition: pg_authid.h:34
#define GetSysCacheOid1(cacheId, oidcol, key1)
Definition: syscache.h:192
int errcode(int sqlerrcode)
Definition: elog.c:570
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:638
#define ERROR
Definition: elog.h:43
#define CStringGetDatum(X)
Definition: postgres.h:578
#define ereport(elevel, rest)
Definition: elog.h:141
int errmsg(const char *fmt,...)
Definition: elog.c:784

◆ get_role_oid_or_public()

◆ get_rolespec_name()

char* get_rolespec_name ( const RoleSpec role)

Definition at line 5308 of file acl.c.

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

Referenced by AddRoleMems(), and DelRoleMems().

5309 {
5310  HeapTuple tp;
5311  Form_pg_authid authForm;
5312  char *rolename;
5313 
5314  tp = get_rolespec_tuple(role);
5315  authForm = (Form_pg_authid) GETSTRUCT(tp);
5316  rolename = pstrdup(NameStr(authForm->rolname));
5317  ReleaseSysCache(tp);
5318 
5319  return rolename;
5320 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
char * pstrdup(const char *in)
Definition: mcxt.c:1161
FormData_pg_authid * Form_pg_authid
Definition: pg_authid.h:56
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1172
HeapTuple get_rolespec_tuple(const RoleSpec *role)
Definition: acl.c:5263
#define NameStr(name)
Definition: c.h:609

◆ get_rolespec_oid()

Oid get_rolespec_oid ( const RoleSpec role,
bool  missing_ok 
)

Definition at line 5225 of file acl.c.

References Assert, elog, ereport, errcode(), errmsg(), ERROR, get_role_oid(), GetSessionUserId(), GetUserId(), InvalidOid, RoleSpec::rolename, ROLESPEC_CSTRING, 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().

5226 {
5227  Oid oid;
5228 
5229  switch (role->roletype)
5230  {
5231  case ROLESPEC_CSTRING:
5232  Assert(role->rolename);
5233  oid = get_role_oid(role->rolename, missing_ok);
5234  break;
5235 
5236  case ROLESPEC_CURRENT_USER:
5237  oid = GetUserId();
5238  break;
5239 
5240  case ROLESPEC_SESSION_USER:
5241  oid = GetSessionUserId();
5242  break;
5243 
5244  case ROLESPEC_PUBLIC:
5245  ereport(ERROR,
5246  (errcode(ERRCODE_UNDEFINED_OBJECT),
5247  errmsg("role \"%s\" does not exist", "public")));
5248  oid = InvalidOid; /* make compiler happy */
5249  break;
5250 
5251  default:
5252  elog(ERROR, "unexpected role type %d", role->roletype);
5253  }
5254 
5255  return oid;
5256 }
Oid GetUserId(void)
Definition: miscinit.c:380
int errcode(int sqlerrcode)
Definition: elog.c:570
unsigned int Oid
Definition: postgres_ext.h:31
Oid GetSessionUserId(void)
Definition: miscinit.c:414
Oid get_role_oid(const char *rolname, bool missing_ok)
Definition: acl.c:5191
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:141
RoleSpecType roletype
Definition: parsenodes.h:328
#define InvalidOid
Definition: postgres_ext.h:36
#define Assert(condition)
Definition: c.h:732
char * rolename
Definition: parsenodes.h:329
int errmsg(const char *fmt,...)
Definition: elog.c:784
#define elog(elevel,...)
Definition: elog.h:226

◆ get_rolespec_tuple()

HeapTuple get_rolespec_tuple ( const RoleSpec role)

Definition at line 5263 of file acl.c.

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

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

5264 {
5265  HeapTuple tuple;
5266 
5267  switch (role->roletype)
5268  {
5269  case ROLESPEC_CSTRING:
5270  Assert(role->rolename);
5272  if (!HeapTupleIsValid(tuple))
5273  ereport(ERROR,
5274  (errcode(ERRCODE_UNDEFINED_OBJECT),
5275  errmsg("role \"%s\" does not exist", role->rolename)));
5276  break;
5277 
5278  case ROLESPEC_CURRENT_USER:
5279  tuple = SearchSysCache1(AUTHOID, GetUserId());
5280  if (!HeapTupleIsValid(tuple))
5281  elog(ERROR, "cache lookup failed for role %u", GetUserId());
5282  break;
5283 
5284  case ROLESPEC_SESSION_USER:
5286  if (!HeapTupleIsValid(tuple))
5287  elog(ERROR, "cache lookup failed for role %u", GetSessionUserId());
5288  break;
5289 
5290  case ROLESPEC_PUBLIC:
5291  ereport(ERROR,
5292  (errcode(ERRCODE_UNDEFINED_OBJECT),
5293  errmsg("role \"%s\" does not exist", "public")));
5294  tuple = NULL; /* make compiler happy */
5295  break;
5296 
5297  default:
5298  elog(ERROR, "unexpected role type %d", role->roletype);
5299  }
5300 
5301  return tuple;
5302 }
Oid GetUserId(void)
Definition: miscinit.c:380
int errcode(int sqlerrcode)
Definition: elog.c:570
Oid GetSessionUserId(void)
Definition: miscinit.c:414
#define ERROR
Definition: elog.h:43
#define CStringGetDatum(X)
Definition: postgres.h:578
#define ereport(elevel, rest)
Definition: elog.h:141
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1124
RoleSpecType roletype
Definition: parsenodes.h:328
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define Assert(condition)
Definition: c.h:732
char * rolename
Definition: parsenodes.h:329
int errmsg(const char *fmt,...)
Definition: elog.c:784
#define elog(elevel,...)
Definition: elog.h:226

◆ getid()

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

Definition at line 138 of file acl.c.

References Assert, ereport, errcode(), errdetail(), errmsg(), ERROR, and NAMEDATALEN.

Referenced by aclparse().

139 {
140  int len = 0;
141  bool in_quotes = false;
142 
143  Assert(s && n);
144 
145  while (isspace((unsigned char) *s))
146  s++;
147  /* This code had better match what putid() does, below */
148  for (;
149  *s != '\0' &&
150  (isalnum((unsigned char) *s) ||
151  *s == '_' ||
152  *s == '"' ||
153  in_quotes);
154  s++)
155  {
156  if (*s == '"')
157  {
158  /* safe to look at next char (could be '\0' though) */
159  if (*(s + 1) != '"')
160  {
161  in_quotes = !in_quotes;
162  continue;
163  }
164  /* it's an escaped double quote; skip the escaping char */
165  s++;
166  }
167 
168  /* Add the character to the string */
169  if (len >= NAMEDATALEN - 1)
170  ereport(ERROR,
171  (errcode(ERRCODE_NAME_TOO_LONG),
172  errmsg("identifier too long"),
173  errdetail("Identifier must be less than %d characters.",
174  NAMEDATALEN)));
175 
176  n[len++] = *s;
177  }
178  n[len] = '\0';
179  while (isspace((unsigned char) *s))
180  s++;
181  return s;
182 }
int errcode(int sqlerrcode)
Definition: elog.c:570
#define NAMEDATALEN
#define ERROR
Definition: elog.h:43
int errdetail(const char *fmt,...)
Definition: elog.c:860
#define ereport(elevel, rest)
Definition: elog.h:141
#define Assert(condition)
Definition: c.h:732
int errmsg(const char *fmt,...)
Definition: elog.c:784

◆ has_any_column_privilege_id()

Datum has_any_column_privilege_id ( PG_FUNCTION_ARGS  )

Definition at line 2363 of file acl.c.

References ACLCHECK_OK, ACLMASK_ANY, convert_column_priv_string(), GetUserId(), mode, ObjectIdGetDatum, pg_attribute_aclcheck_all(), pg_class_aclcheck(), PG_GETARG_OID, PG_GETARG_TEXT_PP, PG_RETURN_BOOL, PG_RETURN_NULL, RELOID, and SearchSysCacheExists1.

2364 {
2365  Oid tableoid = PG_GETARG_OID(0);
2366  text *priv_type_text = PG_GETARG_TEXT_PP(1);
2367  Oid roleid;
2368  AclMode mode;
2369  AclResult aclresult;
2370 
2371  roleid = GetUserId();
2372  mode = convert_column_priv_string(priv_type_text);
2373 
2375  PG_RETURN_NULL();
2376 
2377  /* First check at table level, then examine each column if needed */
2378  aclresult = pg_class_aclcheck(tableoid, roleid, mode);
2379  if (aclresult != ACLCHECK_OK)
2380  aclresult = pg_attribute_aclcheck_all(tableoid, roleid, mode,
2381  ACLMASK_ANY);
2382 
2383  PG_RETURN_BOOL(aclresult == ACLCHECK_OK);
2384 }
static PgChecksumMode mode
Definition: pg_checksums.c:61
Oid GetUserId(void)
Definition: miscinit.c:380
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:303
uint32 AclMode
Definition: parsenodes.h:72
#define SearchSysCacheExists1(cacheId, key1)
Definition: syscache.h:183
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
AclResult
Definition: acl.h:177
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
AclResult pg_attribute_aclcheck_all(Oid table_oid, Oid roleid, AclMode mode, AclMaskHow how)
Definition: aclchk.c:4546
AclResult pg_class_aclcheck(Oid table_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4631
Definition: c.h:549
static AclMode convert_column_priv_string(text *priv_type_text)
Definition: acl.c:2902
#define PG_RETURN_NULL()
Definition: fmgr.h:335

◆ has_any_column_privilege_id_id()

Datum has_any_column_privilege_id_id ( PG_FUNCTION_ARGS  )

Definition at line 2419 of file acl.c.

References ACLCHECK_OK, ACLMASK_ANY, convert_column_priv_string(), mode, ObjectIdGetDatum, pg_attribute_aclcheck_all(), pg_class_aclcheck(), PG_GETARG_OID, PG_GETARG_TEXT_PP, PG_RETURN_BOOL, PG_RETURN_NULL, RELOID, and SearchSysCacheExists1.

2420 {
2421  Oid roleid = PG_GETARG_OID(0);
2422  Oid tableoid = PG_GETARG_OID(1);
2423  text *priv_type_text = PG_GETARG_TEXT_PP(2);
2424  AclMode mode;
2425  AclResult aclresult;
2426 
2427  mode = convert_column_priv_string(priv_type_text);
2428 
2430  PG_RETURN_NULL();
2431 
2432  /* First check at table level, then examine each column if needed */
2433  aclresult = pg_class_aclcheck(tableoid, roleid, mode);
2434  if (aclresult != ACLCHECK_OK)
2435  aclresult = pg_attribute_aclcheck_all(tableoid, roleid, mode,
2436  ACLMASK_ANY);
2437 
2438  PG_RETURN_BOOL(aclresult == ACLCHECK_OK);
2439 }
static PgChecksumMode mode
Definition: pg_checksums.c:61
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:303
uint32 AclMode
Definition: parsenodes.h:72
#define SearchSysCacheExists1(cacheId, key1)
Definition: syscache.h:183
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
AclResult
Definition: acl.h:177
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
AclResult pg_attribute_aclcheck_all(Oid table_oid, Oid roleid, AclMode mode, AclMaskHow how)
Definition: aclchk.c:4546
AclResult pg_class_aclcheck(Oid table_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4631
Definition: c.h:549
static AclMode convert_column_priv_string(text *priv_type_text)
Definition: acl.c:2902
#define PG_RETURN_NULL()
Definition: fmgr.h:335

◆ has_any_column_privilege_id_name()

Datum has_any_column_privilege_id_name ( PG_FUNCTION_ARGS  )

Definition at line 2392 of file acl.c.

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

2393 {
2394  Oid roleid = PG_GETARG_OID(0);
2395  text *tablename = PG_GETARG_TEXT_PP(1);
2396  text *priv_type_text = PG_GETARG_TEXT_PP(2);
2397  Oid tableoid;
2398  AclMode mode;
2399  AclResult aclresult;
2400 
2401  tableoid = convert_table_name(tablename);
2402  mode = convert_column_priv_string(priv_type_text);
2403 
2404  /* First check at table level, then examine each column if needed */
2405  aclresult = pg_class_aclcheck(tableoid, roleid, mode);
2406  if (aclresult != ACLCHECK_OK)
2407  aclresult = pg_attribute_aclcheck_all(tableoid, roleid, mode,
2408  ACLMASK_ANY);
2409 
2410  PG_RETURN_BOOL(aclresult == ACLCHECK_OK);
2411 }
static PgChecksumMode mode
Definition: pg_checksums.c:61
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:303
uint32 AclMode
Definition: parsenodes.h:72
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
AclResult
Definition: acl.h:177
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
static Oid convert_table_name(text *tablename)
Definition: acl.c:2003
AclResult pg_attribute_aclcheck_all(Oid table_oid, Oid roleid, AclMode mode, AclMaskHow how)
Definition: aclchk.c:4546
AclResult pg_class_aclcheck(Oid table_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4631
Definition: c.h:549
static AclMode convert_column_priv_string(text *priv_type_text)
Definition: acl.c:2902

◆ has_any_column_privilege_name()

Datum has_any_column_privilege_name ( PG_FUNCTION_ARGS  )

Definition at line 2304 of file acl.c.

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

2305 {
2306  text *tablename = PG_GETARG_TEXT_PP(0);
2307  text *priv_type_text = PG_GETARG_TEXT_PP(1);
2308  Oid roleid;
2309  Oid tableoid;
2310  AclMode mode;
2311  AclResult aclresult;
2312 
2313  roleid = GetUserId();
2314  tableoid = convert_table_name(tablename);
2315  mode = convert_column_priv_string(priv_type_text);
2316 
2317  /* First check at table level, then examine each column if needed */
2318  aclresult = pg_class_aclcheck(tableoid, roleid, mode);
2319  if (aclresult != ACLCHECK_OK)
2320  aclresult = pg_attribute_aclcheck_all(tableoid, roleid, mode,
2321  ACLMASK_ANY);
2322 
2323  PG_RETURN_BOOL(aclresult == ACLCHECK_OK);
2324 }
static PgChecksumMode mode
Definition: pg_checksums.c:61
Oid GetUserId(void)
Definition: miscinit.c:380
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:303
uint32 AclMode
Definition: parsenodes.h:72
AclResult
Definition: acl.h:177
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
static Oid convert_table_name(text *tablename)
Definition: acl.c:2003
AclResult pg_attribute_aclcheck_all(Oid table_oid, Oid roleid, AclMode mode, AclMaskHow how)
Definition: aclchk.c:4546
AclResult pg_class_aclcheck(Oid table_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4631
Definition: c.h:549
static AclMode convert_column_priv_string(text *priv_type_text)
Definition: acl.c:2902

◆ has_any_column_privilege_name_id()

Datum has_any_column_privilege_name_id ( PG_FUNCTION_ARGS  )

Definition at line 2332 of file acl.c.

References ACLCHECK_OK, ACLMASK_ANY, convert_column_priv_string(), get_role_oid_or_public(), mode, NameStr, ObjectIdGetDatum, pg_attribute_aclcheck_all(), pg_class_aclcheck(), PG_GETARG_NAME, PG_GETARG_OID, PG_GETARG_TEXT_PP, PG_RETURN_BOOL, PG_RETURN_NULL, RELOID, SearchSysCacheExists1, and username.

2333 {
2335  Oid tableoid = PG_GETARG_OID(1);
2336  text *priv_type_text = PG_GETARG_TEXT_PP(2);
2337  Oid roleid;
2338  AclMode mode;
2339  AclResult aclresult;
2340 
2341  roleid = get_role_oid_or_public(NameStr(*username));
2342  mode = convert_column_priv_string(priv_type_text);
2343 
2345  PG_RETURN_NULL();
2346 
2347  /* First check at table level, then examine each column if needed */
2348  aclresult = pg_class_aclcheck(tableoid, roleid, mode);
2349  if (aclresult != ACLCHECK_OK)
2350  aclresult = pg_attribute_aclcheck_all(tableoid, roleid, mode,
2351  ACLMASK_ANY);
2352 
2353  PG_RETURN_BOOL(aclresult == ACLCHECK_OK);
2354 }
static PgChecksumMode mode
Definition: pg_checksums.c:61
Oid get_role_oid_or_public(const char *rolname)
Definition: acl.c:5209
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:303
uint32 AclMode
Definition: parsenodes.h:72
#define SearchSysCacheExists1(cacheId, key1)
Definition: syscache.h:183
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
Definition: c.h:603
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
AclResult
Definition: acl.h:177
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
static char * username
Definition: initdb.c:133
AclResult pg_attribute_aclcheck_all(Oid table_oid, Oid roleid, AclMode mode, AclMaskHow how)
Definition: aclchk.c:4546
AclResult pg_class_aclcheck(Oid table_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4631
#define NameStr(name)
Definition: c.h:609
Definition: c.h:549
static AclMode convert_column_priv_string(text *priv_type_text)
Definition: acl.c:2902
#define PG_RETURN_NULL()
Definition: fmgr.h:335
#define PG_GETARG_NAME(n)
Definition: fmgr.h:273

◆ has_any_column_privilege_name_name()

Datum has_any_column_privilege_name_name ( PG_FUNCTION_ARGS  )

Definition at line 2274 of file acl.c.

References ACLCHECK_OK, ACLMASK_ANY, convert_column_priv_string(), convert_table_name(), 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.

2275 {
2276  Name rolename = PG_GETARG_NAME(0);
2277  text *tablename = PG_GETARG_TEXT_PP(1);
2278  text *priv_type_text = PG_GETARG_TEXT_PP(2);
2279  Oid roleid;
2280  Oid tableoid;
2281  AclMode mode;
2282  AclResult aclresult;
2283 
2284  roleid = get_role_oid_or_public(NameStr(*rolename));
2285  tableoid = convert_table_name(tablename);
2286  mode = convert_column_priv_string(priv_type_text);
2287 
2288  /* First check at table level, then examine each column if needed */
2289  aclresult = pg_class_aclcheck(tableoid, roleid, mode);
2290  if (aclresult != ACLCHECK_OK)
2291  aclresult = pg_attribute_aclcheck_all(tableoid, roleid, mode,
2292  ACLMASK_ANY);
2293 
2294  PG_RETURN_BOOL(aclresult == ACLCHECK_OK);
2295 }
static PgChecksumMode mode
Definition: pg_checksums.c:61
Oid get_role_oid_or_public(const char *rolname)
Definition: acl.c:5209
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:303
uint32 AclMode
Definition: parsenodes.h:72
Definition: c.h:603
AclResult
Definition: acl.h:177
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
static Oid convert_table_name(text *tablename)
Definition: acl.c:2003
AclResult pg_attribute_aclcheck_all(Oid table_oid, Oid roleid, AclMode mode, AclMaskHow how)
Definition: aclchk.c:4546
AclResult pg_class_aclcheck(Oid table_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4631
#define NameStr(name)
Definition: c.h:609
Definition: c.h:549
static AclMode convert_column_priv_string(text *priv_type_text)
Definition: acl.c:2902
#define PG_GETARG_NAME(n)
Definition: fmgr.h:273

◆ has_column_privilege_id_attnum()

Datum has_column_privilege_id_attnum ( PG_FUNCTION_ARGS  )

Definition at line 2816 of file acl.c.

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

2817 {
2818  Oid tableoid = PG_GETARG_OID(0);
2819  AttrNumber colattnum = PG_GETARG_INT16(1);
2820  text *priv_type_text = PG_GETARG_TEXT_PP(2);
2821  Oid roleid;
2822  AclMode mode;
2823  int privresult;
2824 
2825  roleid = GetUserId();
2826  mode = convert_column_priv_string(priv_type_text);
2827 
2828  privresult = column_privilege_check(tableoid, colattnum, roleid, mode);
2829  if (privresult < 0)
2830  PG_RETURN_NULL();
2831  PG_RETURN_BOOL(privresult);
2832 }
static PgChecksumMode mode
Definition: pg_checksums.c:61
Oid GetUserId(void)
Definition: miscinit.c:380
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:303
uint32 AclMode
Definition: parsenodes.h:72
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_GETARG_INT16(n)
Definition: fmgr.h:266
static int column_privilege_check(Oid tableoid, AttrNumber attnum, Oid roleid, AclMode mode)
Definition: acl.c:2466
Definition: c.h:549
static AclMode convert_column_priv_string(text *priv_type_text)
Definition: acl.c:2902
int16 AttrNumber
Definition: attnum.h:21
#define PG_RETURN_NULL()
Definition: fmgr.h:335

◆ has_column_privilege_id_id_attnum()

Datum has_column_privilege_id_id_attnum ( PG_FUNCTION_ARGS  )

Definition at line 2709 of file acl.c.

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

2710 {
2711  Oid roleid = PG_GETARG_OID(0);
2712  Oid tableoid = PG_GETARG_OID(1);
2713  AttrNumber colattnum = PG_GETARG_INT16(2);
2714  text *priv_type_text = PG_GETARG_TEXT_PP(3);
2715  AclMode mode;
2716  int privresult;
2717 
2718  mode = convert_column_priv_string(priv_type_text);
2719 
2720  privresult = column_privilege_check(tableoid, colattnum, roleid, mode);
2721  if (privresult < 0)
2722  PG_RETURN_NULL();
2723  PG_RETURN_BOOL(privresult);
2724 }
static PgChecksumMode mode
Definition: pg_checksums.c:61
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:303
uint32 AclMode
Definition: parsenodes.h:72
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_GETARG_INT16(n)
Definition: fmgr.h:266
static int column_privilege_check(Oid tableoid, AttrNumber attnum, Oid roleid, AclMode mode)
Definition: acl.c:2466
Definition: c.h:549
static AclMode convert_column_priv_string(text *priv_type_text)
Definition: acl.c:2902
int16 AttrNumber
Definition: attnum.h:21
#define PG_RETURN_NULL()
Definition: fmgr.h:335

◆ has_column_privilege_id_id_name()

Datum has_column_privilege_id_id_name ( PG_FUNCTION_ARGS  )

Definition at line 2684 of file acl.c.

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

2685 {
2686  Oid roleid = PG_GETARG_OID(0);
2687  Oid tableoid = PG_GETARG_OID(1);
2688  text *column = PG_GETARG_TEXT_PP(2);
2689  text *priv_type_text = PG_GETARG_TEXT_PP(3);
2690  AttrNumber colattnum;
2691  AclMode mode;
2692  int privresult;
2693 
2694  colattnum = convert_column_name(tableoid, column);
2695  mode = convert_column_priv_string(priv_type_text);
2696 
2697  privresult = column_privilege_check(tableoid, colattnum, roleid, mode);
2698  if (privresult < 0)
2699  PG_RETURN_NULL();
2700  PG_RETURN_BOOL(privresult);
2701 }
static PgChecksumMode mode
Definition: pg_checksums.c:61
static AttrNumber convert_column_name(Oid tableoid, text *column)
Definition: acl.c:2844
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:303
uint32 AclMode
Definition: parsenodes.h:72
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
static int column_privilege_check(Oid tableoid, AttrNumber attnum, Oid roleid, AclMode mode)
Definition: acl.c:2466
Definition: c.h:549
static AclMode convert_column_priv_string(text *priv_type_text)
Definition: acl.c:2902
int16 AttrNumber
Definition: attnum.h:21
#define PG_RETURN_NULL()
Definition: fmgr.h:335

◆ has_column_privilege_id_name()

Datum has_column_privilege_id_name ( PG_FUNCTION_ARGS  )

Definition at line 2789 of file acl.c.

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

2790 {
2791  Oid tableoid = PG_GETARG_OID(0);
2792  text *column = PG_GETARG_TEXT_PP(1);
2793  text *priv_type_text = PG_GETARG_TEXT_PP(2);
2794  Oid roleid;
2795  AttrNumber colattnum;
2796  AclMode mode;
2797  int privresult;
2798 
2799  roleid = GetUserId();
2800  colattnum = convert_column_name(tableoid, column);
2801  mode = convert_column_priv_string(priv_type_text);
2802 
2803  privresult = column_privilege_check(tableoid, colattnum, roleid, mode);
2804  if (privresult < 0)
2805  PG_RETURN_NULL();
2806  PG_RETURN_BOOL(privresult);
2807 }
static PgChecksumMode mode
Definition: pg_checksums.c:61
static AttrNumber convert_column_name(Oid tableoid, text *column)
Definition: acl.c:2844
Oid GetUserId(void)
Definition: miscinit.c:380
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:303
uint32 AclMode
Definition: parsenodes.h:72
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
static int column_privilege_check(Oid tableoid, AttrNumber attnum, Oid roleid, AclMode mode)
Definition: acl.c:2466
Definition: c.h:549
static AclMode convert_column_priv_string(text *priv_type_text)
Definition: acl.c:2902
int16 AttrNumber
Definition: attnum.h:21
#define PG_RETURN_NULL()
Definition: fmgr.h:335

◆ has_column_privilege_id_name_attnum()

Datum has_column_privilege_id_name_attnum ( PG_FUNCTION_ARGS  )

Definition at line 2659 of file acl.c.

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

2660 {
2661  Oid roleid = PG_GETARG_OID(0);
2662  text *tablename = PG_GETARG_TEXT_PP(1);
2663  AttrNumber colattnum = PG_GETARG_INT16(2);
2664  text *priv_type_text = PG_GETARG_TEXT_PP(3);
2665  Oid tableoid;
2666  AclMode mode;
2667  int privresult;
2668 
2669  tableoid = convert_table_name(tablename);
2670  mode = convert_column_priv_string(priv_type_text);
2671 
2672  privresult = column_privilege_check(tableoid, colattnum, roleid, mode);
2673  if (privresult < 0)
2674  PG_RETURN_NULL();
2675  PG_RETURN_BOOL(privresult);
2676 }
static PgChecksumMode mode
Definition: pg_checksums.c:61
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:303
uint32 AclMode
Definition: parsenodes.h:72
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_GETARG_INT16(n)
Definition: fmgr.h:266
static Oid convert_table_name(text *tablename)
Definition: acl.c:2003
static int column_privilege_check(Oid tableoid, AttrNumber attnum, Oid roleid, AclMode mode)
Definition: acl.c:2466
Definition: c.h:549
static AclMode convert_column_priv_string(text *priv_type_text)
Definition: acl.c:2902
int16 AttrNumber
Definition: attnum.h:21
#define PG_RETURN_NULL()
Definition: fmgr.h:335

◆ has_column_privilege_id_name_name()

Datum has_column_privilege_id_name_name ( PG_FUNCTION_ARGS  )

Definition at line 2632 of file acl.c.

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

2633 {
2634  Oid roleid = PG_GETARG_OID(0);
2635  text *tablename = PG_GETARG_TEXT_PP(1);
2636  text *column = PG_GETARG_TEXT_PP(2);
2637  text *priv_type_text = PG_GETARG_TEXT_PP(3);
2638  Oid tableoid;
2639  AttrNumber colattnum;
2640  AclMode mode;
2641  int privresult;
2642 
2643  tableoid = convert_table_name(tablename);
2644  colattnum = convert_column_name(tableoid, column);
2645  mode = convert_column_priv_string(priv_type_text);
2646 
2647  privresult = column_privilege_check(tableoid, colattnum, roleid, mode);
2648  if (privresult < 0)
2649  PG_RETURN_NULL();
2650  PG_RETURN_BOOL(privresult);
2651 }
static PgChecksumMode mode
Definition: pg_checksums.c:61
static AttrNumber convert_column_name(Oid tableoid, text *column)
Definition: acl.c:2844
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:303
uint32 AclMode
Definition: parsenodes.h:72
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
static Oid convert_table_name(text *tablename)
Definition: acl.c:2003
static int column_privilege_check(Oid tableoid, AttrNumber attnum, Oid roleid, AclMode mode)
Definition: acl.c:2466
Definition: c.h:549
static AclMode convert_column_priv_string(text *priv_type_text)
Definition: acl.c:2902
int16 AttrNumber
Definition: attnum.h:21
#define PG_RETURN_NULL()
Definition: fmgr.h:335

◆ has_column_privilege_name_attnum()

Datum has_column_privilege_name_attnum ( PG_FUNCTION_ARGS  )

Definition at line 2762 of file acl.c.

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

2763 {
2764  text *tablename = PG_GETARG_TEXT_PP(0);
2765  AttrNumber colattnum = PG_GETARG_INT16(1);
2766  text *priv_type_text = PG_GETARG_TEXT_PP(2);
2767  Oid roleid;
2768  Oid tableoid;
2769  AclMode mode;
2770  int privresult;
2771 
2772  roleid = GetUserId();
2773  tableoid = convert_table_name(tablename);
2774  mode = convert_column_priv_string(priv_type_text);
2775 
2776  privresult = column_privilege_check(tableoid, colattnum, roleid, mode);
2777  if (privresult < 0)
2778  PG_RETURN_NULL();
2779  PG_RETURN_BOOL(privresult);
2780 }
static PgChecksumMode mode
Definition: pg_checksums.c:61
Oid GetUserId(void)
Definition: miscinit.c:380
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:303
uint32 AclMode
Definition: parsenodes.h:72
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_GETARG_INT16(n)
Definition: fmgr.h:266
static Oid convert_table_name(text *tablename)
Definition: acl.c:2003
static int column_privilege_check(Oid tableoid, AttrNumber attnum, Oid roleid, AclMode mode)
Definition: acl.c:2466
Definition: c.h:549
static AclMode convert_column_priv_string(text *priv_type_text)
Definition: acl.c:2902
int16 AttrNumber
Definition: attnum.h:21
#define PG_RETURN_NULL()
Definition: fmgr.h:335

◆ has_column_privilege_name_id_attnum()

Datum has_column_privilege_name_id_attnum ( PG_FUNCTION_ARGS  )

Definition at line 2607 of file acl.c.

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

2608 {
2610  Oid tableoid = PG_GETARG_OID(1);
2611  AttrNumber colattnum = PG_GETARG_INT16(2);
2612  text *priv_type_text = PG_GETARG_TEXT_PP(3);
2613  Oid roleid;
2614  AclMode mode;
2615  int privresult;
2616 
2617  roleid = get_role_oid_or_public(NameStr(*username));
2618  mode = convert_column_priv_string(priv_type_text);
2619 
2620  privresult = column_privilege_check(tableoid, colattnum, roleid, mode);
2621  if (privresult < 0)
2622  PG_RETURN_NULL();
2623  PG_RETURN_BOOL(privresult);
2624 }
static PgChecksumMode mode
Definition: pg_checksums.c:61
Oid get_role_oid_or_public(const char *rolname)
Definition: acl.c:5209
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:303
uint32 AclMode
Definition: parsenodes.h:72
Definition: c.h:603
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_GETARG_INT16(n)
Definition: fmgr.h:266
static char * username
Definition: initdb.c:133
static int column_privilege_check(Oid tableoid, AttrNumber attnum, Oid roleid, AclMode mode)
Definition: acl.c:2466
#define NameStr(name)
Definition: c.h:609
Definition: c.h:549
static AclMode convert_column_priv_string(text *priv_type_text)
Definition: acl.c:2902
int16 AttrNumber
Definition: attnum.h:21
#define PG_RETURN_NULL()
Definition: fmgr.h:335
#define PG_GETARG_NAME(n)
Definition: fmgr.h:273

◆ has_column_privilege_name_id_name()

Datum has_column_privilege_name_id_name ( PG_FUNCTION_ARGS  )

Definition at line 2580 of file acl.c.

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

2581 {
2583  Oid tableoid = PG_GETARG_OID(1);
2584  text *column = PG_GETARG_TEXT_PP(2);
2585  text *priv_type_text = PG_GETARG_TEXT_PP(3);
2586  Oid roleid;
2587  AttrNumber colattnum;
2588  AclMode mode;
2589  int privresult;
2590 
2591  roleid = get_role_oid_or_public(NameStr(*username));
2592  colattnum = convert_column_name(tableoid, column);
2593  mode = convert_column_priv_string(priv_type_text);
2594 
2595  privresult = column_privilege_check(tableoid, colattnum, roleid, mode);
2596  if (privresult < 0)
2597  PG_RETURN_NULL();
2598  PG_RETURN_BOOL(privresult);
2599 }
static PgChecksumMode mode
Definition: pg_checksums.c:61
static AttrNumber convert_column_name(Oid tableoid, text *column)
Definition: acl.c:2844
Oid get_role_oid_or_public(const char *rolname)
Definition: acl.c:5209
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:303
uint32 AclMode
Definition: parsenodes.h:72
Definition: c.h:603
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
static char * username
Definition: initdb.c:133
static int column_privilege_check(Oid tableoid, AttrNumber attnum, Oid roleid, AclMode mode)
Definition: acl.c:2466
#define NameStr(name)
Definition: c.h:609
Definition: c.h:549
static AclMode convert_column_priv_string(text *priv_type_text)
Definition: acl.c:2902
int16 AttrNumber
Definition: attnum.h:21
#define PG_RETURN_NULL()
Definition: fmgr.h:335
#define PG_GETARG_NAME(n)
Definition: fmgr.h:273

◆ has_column_privilege_name_name()

Datum has_column_privilege_name_name ( PG_FUNCTION_ARGS  )

Definition at line 2733 of file acl.c.

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

2734 {
2735  text *tablename = PG_GETARG_TEXT_PP(0);
2736  text *column = PG_GETARG_TEXT_PP(1);
2737  text *priv_type_text = PG_GETARG_TEXT_PP(2);
2738  Oid roleid;
2739  Oid tableoid;
2740  AttrNumber colattnum;
2741  AclMode mode;
2742  int privresult;
2743 
2744  roleid = GetUserId();
2745  tableoid = convert_table_name(tablename);
2746  colattnum = convert_column_name(tableoid, column);
2747  mode = convert_column_priv_string(priv_type_text);
2748 
2749  privresult = column_privilege_check(tableoid, colattnum, roleid, mode);
2750  if (privresult < 0)
2751  PG_RETURN_NULL();
2752  PG_RETURN_BOOL(privresult);
2753 }
static PgChecksumMode mode
Definition: pg_checksums.c:61
static AttrNumber convert_column_name(Oid tableoid, text *column)
Definition: acl.c:2844
Oid GetUserId(void)
Definition: miscinit.c:380
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:303
uint32 AclMode
Definition: parsenodes.h:72
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
static Oid convert_table_name(text *tablename)
Definition: acl.c:2003
static int column_privilege_check(Oid tableoid, AttrNumber attnum, Oid roleid, AclMode mode)
Definition: acl.c:2466
Definition: c.h:549
static AclMode convert_column_priv_string(text *priv_type_text)
Definition: acl.c:2902
int16 AttrNumber
Definition: attnum.h:21
#define PG_RETURN_NULL()
Definition: fmgr.h:335

◆ has_column_privilege_name_name_attnum()

Datum has_column_privilege_name_name_attnum ( PG_FUNCTION_ARGS  )

Definition at line 2553 of file acl.c.

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

2554 {
2555  Name rolename = PG_GETARG_NAME(0);
2556  text *tablename = PG_GETARG_TEXT_PP(1);
2557  AttrNumber colattnum = PG_GETARG_INT16(2);
2558  text *priv_type_text = PG_GETARG_TEXT_PP(3);
2559  Oid roleid;
2560  Oid tableoid;
2561  AclMode mode;
2562  int privresult;
2563 
2564  roleid = get_role_oid_or_public(NameStr(*rolename));
2565  tableoid = convert_table_name(tablename);
2566  mode = convert_column_priv_string(priv_type_text);
2567 
2568  privresult = column_privilege_check(tableoid, colattnum, roleid, mode);
2569  if (privresult < 0)
2570  PG_RETURN_NULL();
2571  PG_RETURN_BOOL(privresult);
2572 }
static PgChecksumMode mode
Definition: pg_checksums.c:61
Oid get_role_oid_or_public(const char *rolname)
Definition: acl.c:5209
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:303
uint32 AclMode
Definition: parsenodes.h:72
Definition: c.h:603
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_GETARG_INT16(n)
Definition: fmgr.h:266
static Oid convert_table_name(text *tablename)
Definition: acl.c:2003
static int column_privilege_check(Oid tableoid, AttrNumber attnum, Oid roleid, AclMode mode)
Definition: acl.c:2466
#define NameStr(name)
Definition: c.h:609
Definition: c.h:549
static AclMode convert_column_priv_string(text *priv_type_text)
Definition: acl.c:2902
int16 AttrNumber
Definition: attnum.h:21
#define PG_RETURN_NULL()
Definition: fmgr.h:335
#define PG_GETARG_NAME(n)
Definition: fmgr.h:273

◆ has_column_privilege_name_name_name()

Datum has_column_privilege_name_name_name ( PG_FUNCTION_ARGS  )

Definition at line 2524 of file acl.c.

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

2525 {
2526  Name rolename = PG_GETARG_NAME(0);
2527  text *tablename = PG_GETARG_TEXT_PP(1);
2528  text *column = PG_GETARG_TEXT_PP(2);
2529  text *priv_type_text = PG_GETARG_TEXT_PP(3);
2530  Oid roleid;
2531  Oid tableoid;
2532  AttrNumber colattnum;
2533  AclMode mode;
2534  int privresult;
2535 
2536  roleid = get_role_oid_or_public(NameStr(*rolename));
2537  tableoid = convert_table_name(tablename);
2538  colattnum = convert_column_name(tableoid, column);
2539  mode = convert_column_priv_string(priv_type_text);
2540 
2541  privresult = column_privilege_check(tableoid, colattnum, roleid, mode);
2542  if (privresult < 0)
2543  PG_RETURN_NULL();
2544  PG_RETURN_BOOL(privresult);
2545 }
static PgChecksumMode mode
Definition: pg_checksums.c:61
static AttrNumber convert_column_name(Oid tableoid, text *column)
Definition: acl.c:2844
Oid get_role_oid_or_public(const char *rolname)
Definition: acl.c:5209
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:303
uint32 AclMode
Definition: parsenodes.h:72
Definition: c.h:603
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
static Oid convert_table_name(text *tablename)
Definition: acl.c:2003
static int column_privilege_check(Oid tableoid, AttrNumber attnum, Oid roleid, AclMode mode)
Definition: acl.c:2466
#define NameStr(name)
Definition: c.h:609
Definition: c.h:549
static AclMode convert_column_priv_string(text *priv_type_text)
Definition: acl.c:2902
int16 AttrNumber
Definition: attnum.h:21
#define PG_RETURN_NULL()
Definition: fmgr.h:335
#define PG_GETARG_NAME(n)
Definition: fmgr.h:273

◆ has_database_privilege_id()

Datum has_database_privilege_id ( PG_FUNCTION_ARGS  )

Definition at line 3013 of file acl.c.

References ACLCHECK_OK, convert_database_priv_string(), DATABASEOID, GetUserId(), mode, ObjectIdGetDatum, pg_database_aclcheck(), PG_GETARG_OID, PG_GETARG_TEXT_PP, PG_RETURN_BOOL, PG_RETURN_NULL, and SearchSysCacheExists1.

3014 {
3015  Oid databaseoid = PG_GETARG_OID(0);
3016  text *priv_type_text = PG_GETARG_TEXT_PP(1);
3017  Oid roleid;
3018  AclMode mode;
3019  AclResult aclresult;
3020 
3021  roleid = GetUserId();
3022  mode = convert_database_priv_string(priv_type_text);
3023 
3025  PG_RETURN_NULL();
3026 
3027  aclresult = pg_database_aclcheck(databaseoid, roleid, mode);
3028 
3029  PG_RETURN_BOOL(aclresult == ACLCHECK_OK);
3030 }
static PgChecksumMode mode
Definition: pg_checksums.c:61
Oid GetUserId(void)
Definition: miscinit.c:380
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:303
uint32 AclMode
Definition: parsenodes.h:72
#define SearchSysCacheExists1(cacheId, key1)
Definition: syscache.h:183
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
static AclMode convert_database_priv_string(text *priv_type_text)
Definition: acl.c:3099
AclResult
Definition: acl.h:177
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
AclResult pg_database_aclcheck(Oid db_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4643
Definition: c.h:549
#define PG_RETURN_NULL()
Definition: fmgr.h:335

◆ has_database_privilege_id_id()

Datum has_database_privilege_id_id ( PG_FUNCTION_ARGS  )

Definition at line 3061 of file acl.c.

References ACLCHECK_OK, convert_database_priv_string(), DATABASEOID, mode, ObjectIdGetDatum, pg_database_aclcheck(), PG_GETARG_OID, PG_GETARG_TEXT_PP, PG_RETURN_BOOL, PG_RETURN_NULL, and SearchSysCacheExists1.

3062 {
3063  Oid roleid = PG_GETARG_OID(0);
3064  Oid databaseoid = PG_GETARG_OID(1);
3065  text *priv_type_text = PG_GETARG_TEXT_PP(2);
3066  AclMode mode;
3067  AclResult aclresult;
3068 
3069  mode = convert_database_priv_string(priv_type_text);
3070 
3072  PG_RETURN_NULL();
3073 
3074  aclresult = pg_database_aclcheck(databaseoid, roleid, mode);
3075 
3076  PG_RETURN_BOOL(aclresult == ACLCHECK_OK);
3077 }
static PgChecksumMode mode
Definition: pg_checksums.c:61
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:303
uint32 AclMode
Definition: parsenodes.h:72
#define SearchSysCacheExists1(cacheId, key1)
Definition: syscache.h:183
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
static AclMode convert_database_priv_string(text *priv_type_text)
Definition: acl.c:3099
AclResult
Definition: acl.h:177
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
AclResult pg_database_aclcheck(Oid db_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4643
Definition: c.h:549
#define PG_RETURN_NULL()
Definition: fmgr.h:335

◆ has_database_privilege_id_name()

Datum has_database_privilege_id_name ( PG_FUNCTION_ARGS  )

Definition at line 3038 of file acl.c.

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

3039 {
3040  Oid roleid = PG_GETARG_OID(0);
3041  text *databasename = PG_GETARG_TEXT_PP(1);
3042  text *priv_type_text = PG_GETARG_TEXT_PP(2);
3043  Oid databaseoid;
3044  AclMode mode;
3045  AclResult aclresult;
3046 
3047  databaseoid = convert_database_name(databasename);
3048  mode = convert_database_priv_string(priv_type_text);
3049 
3050  aclresult = pg_database_aclcheck(databaseoid, roleid, mode);
3051 
3052  PG_RETURN_BOOL(aclresult == ACLCHECK_OK);
3053 }
static PgChecksumMode mode
Definition: pg_checksums.c:61
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:303
uint32 AclMode
Definition: parsenodes.h:72
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
static Oid convert_database_name(text *databasename)
Definition: acl.c:3087
static AclMode convert_database_priv_string(text *priv_type_text)
Definition: acl.c:3099
AclResult
Definition: acl.h:177
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
AclResult pg_database_aclcheck(Oid db_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4643
Definition: c.h:549

◆ has_database_privilege_name()

Datum has_database_privilege_name ( PG_FUNCTION_ARGS  )

Definition at line 2962 of file acl.c.

References ACLCHECK_OK, convert_database_name(), convert_database_priv_string(), GetUserId(), mode, pg_database_aclcheck(), PG_GETARG_TEXT_PP, and PG_RETURN_BOOL.

2963 {
2964  text *databasename = PG_GETARG_TEXT_PP(0);
2965  text *priv_type_text = PG_GETARG_TEXT_PP(1);
2966  Oid roleid;
2967  Oid databaseoid;
2968  AclMode mode;
2969  AclResult aclresult;
2970 
2971  roleid = GetUserId();
2972  databaseoid = convert_database_name(databasename);
2973  mode = convert_database_priv_string(priv_type_text);
2974 
2975  aclresult = pg_database_aclcheck(databaseoid, roleid, mode);
2976 
2977  PG_RETURN_BOOL(aclresult == ACLCHECK_OK);
2978 }
static PgChecksumMode mode
Definition: pg_checksums.c:61
Oid GetUserId(void)
Definition: miscinit.c:380
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:303
uint32 AclMode
Definition: parsenodes.h:72
static Oid convert_database_name(text *databasename)
Definition: acl.c:3087
static AclMode convert_database_priv_string(text *priv_type_text)
Definition: acl.c:3099
AclResult
Definition: acl.h:177
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
AclResult pg_database_aclcheck(Oid db_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4643
Definition: c.h:549

◆ has_database_privilege_name_id()

Datum has_database_privilege_name_id ( PG_FUNCTION_ARGS  )

Definition at line 2986 of file acl.c.

References ACLCHECK_OK, convert_database_priv_string(), DATABASEOID, get_role_oid_or_public(), mode, NameStr, ObjectIdGetDatum, pg_database_aclcheck(), PG_GETARG_NAME, PG_GETARG_OID, PG_GETARG_TEXT_PP, PG_RETURN_BOOL, PG_RETURN_NULL, SearchSysCacheExists1, and username.

2987 {
2989  Oid databaseoid = PG_GETARG_OID(1);
2990  text *priv_type_text = PG_GETARG_TEXT_PP(2);
2991  Oid roleid;
2992  AclMode mode;
2993  AclResult aclresult;
2994 
2995  roleid = get_role_oid_or_public(NameStr(*username));
2996  mode = convert_database_priv_string(priv_type_text);
2997 
2999  PG_RETURN_NULL();
3000 
3001  aclresult = pg_database_aclcheck(databaseoid, roleid, mode);
3002 
3003  PG_RETURN_BOOL(aclresult == ACLCHECK_OK);
3004 }
static PgChecksumMode mode
Definition: pg_checksums.c:61
Oid get_role_oid_or_public(const char *rolname)
Definition: acl.c:5209
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:303
uint32 AclMode
Definition: parsenodes.h:72
#define SearchSysCacheExists1(cacheId, key1)
Definition: syscache.h:183
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
Definition: c.h:603
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
static AclMode convert_database_priv_string(text *priv_type_text)
Definition: acl.c:3099
AclResult
Definition: acl.h:177
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
static char * username
Definition: initdb.c:133
AclResult pg_database_aclcheck(Oid db_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4643
#define NameStr(name)
Definition: c.h:609
Definition: c.h:549
#define PG_RETURN_NULL()
Definition: fmgr.h:335
#define PG_GETARG_NAME(n)
Definition: fmgr.h:273

◆ has_database_privilege_name_name()

Datum has_database_privilege_name_name ( PG_FUNCTION_ARGS  )

Definition at line 2936 of file acl.c.

References ACLCHECK_OK, convert_database_name(), convert_database_priv_string(), get_role_oid_or_public(), mode, NameStr, pg_database_aclcheck(), PG_GETARG_NAME, PG_GETARG_TEXT_PP, PG_RETURN_BOOL, and username.

2937 {
2939  text *databasename = PG_GETARG_TEXT_PP(1);
2940  text *priv_type_text = PG_GETARG_TEXT_PP(2);
2941  Oid roleid;
2942  Oid databaseoid;
2943  AclMode mode;
2944  AclResult aclresult;
2945 
2946  roleid = get_role_oid_or_public(NameStr(*username));
2947  databaseoid = convert_database_name(databasename);
2948  mode = convert_database_priv_string(priv_type_text);
2949 
2950  aclresult = pg_database_aclcheck(databaseoid, roleid, mode);
2951 
2952  PG_RETURN_BOOL(aclresult == ACLCHECK_OK);
2953 }
static PgChecksumMode mode
Definition: pg_checksums.c:61
Oid get_role_oid_or_public(const char *rolname)
Definition: acl.c:5209
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:303
uint32 AclMode
Definition: parsenodes.h:72
Definition: c.h:603
static Oid convert_database_name(text *databasename)
Definition: acl.c:3087
static AclMode convert_database_priv_string(text *priv_type_text)
Definition: acl.c:3099
AclResult
Definition: acl.h:177
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
static char * username
Definition: initdb.c:133
AclResult pg_database_aclcheck(Oid db_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4643
#define NameStr(name)
Definition: c.h:609
Definition: c.h:549
#define PG_GETARG_NAME(n)
Definition: fmgr.h:273

◆ has_foreign_data_wrapper_privilege_id()

Datum has_foreign_data_wrapper_privilege_id ( PG_FUNCTION_ARGS  )

Definition at line 3211 of file acl.c.

References ACLCHECK_OK, convert_foreign_data_wrapper_priv_string(), FOREIGNDATAWRAPPEROID, GetUserId(), mode, ObjectIdGetDatum, pg_foreign_data_wrapper_aclcheck(), PG_GETARG_OID, PG_GETARG_TEXT_PP, PG_RETURN_BOOL, PG_RETURN_NULL, and SearchSysCacheExists1.

3212 {
3213  Oid fdwid = PG_GETARG_OID(0);
3214  text *priv_type_text = PG_GETARG_TEXT_PP(1);
3215  Oid roleid;
3216  AclMode mode;
3217  AclResult aclresult;
3218 
3219  roleid = GetUserId();
3220  mode = convert_foreign_data_wrapper_priv_string(priv_type_text);
3221 
3223  PG_RETURN_NULL();
3224 
3225  aclresult = pg_foreign_data_wrapper_aclcheck(fdwid, roleid, mode);
3226 
3227  PG_RETURN_BOOL(aclresult == ACLCHECK_OK);
3228 }
static PgChecksumMode mode
Definition: pg_checksums.c:61
Oid GetUserId(void)
Definition: miscinit.c:380
AclResult pg_foreign_data_wrapper_aclcheck(Oid fdw_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4718
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:303
uint32 AclMode
Definition: parsenodes.h:72
#define SearchSysCacheExists1(cacheId, key1)
Definition: syscache.h:183
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
AclResult
Definition: acl.h:177
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
static AclMode convert_foreign_data_wrapper_priv_string(text *priv_type_text)
Definition: acl.c:3297
Definition: c.h:549
#define PG_RETURN_NULL()
Definition: fmgr.h:335

◆ has_foreign_data_wrapper_privilege_id_id()

Datum has_foreign_data_wrapper_privilege_id_id ( PG_FUNCTION_ARGS  )

Definition at line 3259 of file acl.c.

References ACLCHECK_OK, convert_foreign_data_wrapper_priv_string(), FOREIGNDATAWRAPPEROID, mode, ObjectIdGetDatum, pg_foreign_data_wrapper_aclcheck(), PG_GETARG_OID, PG_GETARG_TEXT_PP, PG_RETURN_BOOL, PG_RETURN_NULL, and SearchSysCacheExists1.

3260 {
3261  Oid roleid = PG_GETARG_OID(0);
3262  Oid fdwid = PG_GETARG_OID(1);
3263  text *priv_type_text = PG_GETARG_TEXT_PP(2);
3264  AclMode mode;
3265  AclResult aclresult;
3266 
3267  mode = convert_foreign_data_wrapper_priv_string(priv_type_text);
3268 
3270  PG_RETURN_NULL();
3271 
3272  aclresult = pg_foreign_data_wrapper_aclcheck(fdwid, roleid, mode);
3273 
3274  PG_RETURN_BOOL(aclresult == ACLCHECK_OK);
3275 }
static PgChecksumMode mode
Definition: pg_checksums.c:61
AclResult pg_foreign_data_wrapper_aclcheck(Oid fdw_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4718
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:303
uint32 AclMode
Definition: parsenodes.h:72
#define SearchSysCacheExists1(cacheId, key1)
Definition: syscache.h:183
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
AclResult
Definition: acl.h:177
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
static AclMode convert_foreign_data_wrapper_priv_string(text *priv_type_text)
Definition: acl.c:3297
Definition: c.h:549
#define PG_RETURN_NULL()
Definition: fmgr.h:335

◆ has_foreign_data_wrapper_privilege_id_name()

Datum has_foreign_data_wrapper_privilege_id_name ( PG_FUNCTION_ARGS  )

Definition at line 3236 of file acl.c.

References ACLCHECK_OK, convert_foreign_data_wrapper_name(), convert_foreign_data_wrapper_priv_string(), mode, pg_foreign_data_wrapper_aclcheck(), PG_GETARG_OID, PG_GETARG_TEXT_PP, and PG_RETURN_BOOL.

3237 {
3238  Oid roleid = PG_GETARG_OID(0);
3239  text *fdwname = PG_GETARG_TEXT_PP(1);
3240  text *priv_type_text = PG_GETARG_TEXT_PP(2);
3241  Oid fdwid;
3242  AclMode mode;
3243  AclResult aclresult;
3244 
3245  fdwid = convert_foreign_data_wrapper_name(fdwname);
3246  mode = convert_foreign_data_wrapper_priv_string(priv_type_text);
3247 
3248  aclresult = pg_foreign_data_wrapper_aclcheck(fdwid, roleid, mode);
3249 
3250  PG_RETURN_BOOL(aclresult == ACLCHECK_OK);
3251 }
static PgChecksumMode mode
Definition: pg_checksums.c:61
AclResult pg_foreign_data_wrapper_aclcheck(Oid fdw_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4718
static Oid convert_foreign_data_wrapper_name(text *fdwname)
Definition: acl.c:3285
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:303
uint32 AclMode
Definition: parsenodes.h:72
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
AclResult
Definition: acl.h:177
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
static AclMode convert_foreign_data_wrapper_priv_string(text *priv_type_text)
Definition: acl.c:3297
Definition: c.h:549

◆ has_foreign_data_wrapper_privilege_name()

Datum has_foreign_data_wrapper_privilege_name ( PG_FUNCTION_ARGS  )

Definition at line 3160 of file acl.c.

References ACLCHECK_OK, convert_foreign_data_wrapper_name(), convert_foreign_data_wrapper_priv_string(), GetUserId(), mode, pg_foreign_data_wrapper_aclcheck(), PG_GETARG_TEXT_PP, and PG_RETURN_BOOL.

3161 {
3162  text *fdwname = PG_GETARG_TEXT_PP(0);
3163  text *priv_type_text = PG_GETARG_TEXT_PP(1);
3164  Oid roleid;
3165  Oid fdwid;
3166  AclMode mode;
3167  AclResult aclresult;
3168 
3169  roleid = GetUserId();
3170  fdwid = convert_foreign_data_wrapper_name(fdwname);
3171  mode = convert_foreign_data_wrapper_priv_string(priv_type_text);
3172 
3173  aclresult = pg_foreign_data_wrapper_aclcheck(fdwid, roleid, mode);
3174 
3175  PG_RETURN_BOOL(aclresult == ACLCHECK_OK);
3176 }
static PgChecksumMode mode
Definition: pg_checksums.c:61
Oid GetUserId(void)
Definition: miscinit.c:380
AclResult pg_foreign_data_wrapper_aclcheck(Oid fdw_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4718
static Oid convert_foreign_data_wrapper_name(text *fdwname)
Definition: acl.c:3285
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:303
uint32 AclMode
Definition: parsenodes.h:72
AclResult
Definition: acl.h:177
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
static AclMode convert_foreign_data_wrapper_priv_string(text *priv_type_text)
Definition: acl.c:3297
Definition: c.h:549

◆ has_foreign_data_wrapper_privilege_name_id()

Datum has_foreign_data_wrapper_privilege_name_id ( PG_FUNCTION_ARGS  )

Definition at line 3184 of file acl.c.

References ACLCHECK_OK, convert_foreign_data_wrapper_priv_string(), FOREIGNDATAWRAPPEROID, get_role_oid_or_public(), mode, NameStr, ObjectIdGetDatum, pg_foreign_data_wrapper_aclcheck(), PG_GETARG_NAME, PG_GETARG_OID, PG_GETARG_TEXT_PP, PG_RETURN_BOOL, PG_RETURN_NULL, SearchSysCacheExists1, and username.

3185 {
3187  Oid fdwid = PG_GETARG_OID(1);
3188  text *priv_type_text = PG_GETARG_TEXT_PP(2);
3189  Oid roleid;
3190  AclMode mode;
3191  AclResult aclresult;
3192 
3193  roleid = get_role_oid_or_public(NameStr(*username));
3194  mode = convert_foreign_data_wrapper_priv_string(priv_type_text);
3195 
3197  PG_RETURN_NULL();
3198 
3199  aclresult = pg_foreign_data_wrapper_aclcheck(fdwid, roleid, mode);
3200 
3201  PG_RETURN_BOOL(aclresult == ACLCHECK_OK);
3202 }
static PgChecksumMode mode
Definition: pg_checksums.c:61
AclResult pg_foreign_data_wrapper_aclcheck(Oid fdw_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4718
Oid get_role_oid_or_public(const char *rolname)
Definition: acl.c:5209
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:303
uint32 AclMode
Definition: parsenodes.h:72
#define SearchSysCacheExists1(cacheId, key1)
Definition: syscache.h:183
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
Definition: c.h:603
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
AclResult
Definition: acl.h:177
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
static char * username
Definition: initdb.c:133
static AclMode convert_foreign_data_wrapper_priv_string(text *priv_type_text)
Definition: acl.c:3297
#define NameStr(name)
Definition: c.h:609
Definition: c.h:549
#define PG_RETURN_NULL()
Definition: fmgr.h:335
#define PG_GETARG_NAME(n)
Definition: fmgr.h:273

◆ has_foreign_data_wrapper_privilege_name_name()

Datum has_foreign_data_wrapper_privilege_name_name ( PG_FUNCTION_ARGS  )

Definition at line 3134 of file acl.c.

References ACLCHECK_OK, convert_foreign_data_wrapper_name(), convert_foreign_data_wrapper_priv_string(), get_role_oid_or_public(), mode, NameStr, pg_foreign_data_wrapper_aclcheck(), PG_GETARG_NAME, PG_GETARG_TEXT_PP, PG_RETURN_BOOL, and username.

3135 {
3137  text *fdwname = PG_GETARG_TEXT_PP(1);
3138  text *priv_type_text = PG_GETARG_TEXT_PP(2);
3139  Oid roleid;
3140  Oid fdwid;
3141  AclMode mode;
3142  AclResult aclresult;
3143 
3144  roleid = get_role_oid_or_public(NameStr(*username));
3145  fdwid = convert_foreign_data_wrapper_name(fdwname);
3146  mode = convert_foreign_data_wrapper_priv_string(priv_type_text);
3147 
3148  aclresult = pg_foreign_data_wrapper_aclcheck(fdwid, roleid, mode);
3149 
3150  PG_RETURN_BOOL(aclresult == ACLCHECK_OK);
3151 }
static PgChecksumMode mode
Definition: pg_checksums.c:61
AclResult pg_foreign_data_wrapper_aclcheck(Oid fdw_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4718
static Oid convert_foreign_data_wrapper_name(text *fdwname)
Definition: acl.c:3285
Oid get_role_oid_or_public(const char *rolname)
Definition: acl.c:5209
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:303