PostgreSQL Source Code  git master
acl.c File Reference
#include "postgres.h"
#include <ctype.h>
#include "access/hash.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/builtins.h"
#include "utils/catcache.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 (GrantObjectType 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 427 of file acl.c.

References ACL_DAT, ACL_NUM, and allocacl().

Referenced by ExecGrant_Attribute().

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

◆ 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:57
#define PG_GETARG_ACLITEM_P(n)
Definition: acl.h:118
Oid ai_grantor
Definition: acl.h:58
#define ACL_NUM(ACL)
Definition: acl.h:109
#define ACLITEM_GET_RIGHTS(item)
Definition: acl.h:69
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define ACL_DAT(ACL)
Definition: acl.h:110
Definition: acl.h:55
#define PG_GETARG_ACL_P(n)
Definition: acl.h:123
int i
static void check_acl(const Acl *acl)
Definition: acl.c:540

◆ aclcopy()

Acl* aclcopy ( const Acl orig_acl)

Definition at line 407 of file acl.c.

References ACL_DAT, ACL_NUM, and allocacl().

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

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

◆ acldefault()

Acl* acldefault ( GrantObjectType  objtype,
Oid  ownerId 
)

Definition at line 748 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_NAMESPACE, ACL_ALL_RIGHTS_RELATION, 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_OBJECT_COLUMN, ACL_OBJECT_DATABASE, ACL_OBJECT_DOMAIN, ACL_OBJECT_FDW, ACL_OBJECT_FOREIGN_SERVER, ACL_OBJECT_FUNCTION, ACL_OBJECT_LANGUAGE, ACL_OBJECT_LARGEOBJECT, ACL_OBJECT_NAMESPACE, ACL_OBJECT_RELATION, ACL_OBJECT_SEQUENCE, ACL_OBJECT_TABLESPACE, ACL_OBJECT_TYPE, ACL_USAGE, ACLITEM_SET_PRIVS_GOPTIONS, AclItem::ai_grantee, AclItem::ai_grantor, allocacl(), elog, and ERROR.

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

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

◆ acldefault_sql()

Datum acldefault_sql ( PG_FUNCTION_ARGS  )

Definition at line 862 of file acl.c.

References ACL_OBJECT_COLUMN, ACL_OBJECT_DATABASE, ACL_OBJECT_FDW, ACL_OBJECT_FOREIGN_SERVER, ACL_OBJECT_FUNCTION, ACL_OBJECT_LANGUAGE, ACL_OBJECT_LARGEOBJECT, ACL_OBJECT_NAMESPACE, ACL_OBJECT_RELATION, ACL_OBJECT_SEQUENCE, ACL_OBJECT_TABLESPACE, ACL_OBJECT_TYPE, acldefault(), elog, ERROR, 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  GrantObjectType objtype = 0;
867 
868  switch (objtypec)
869  {
870  case 'c':
871  objtype = ACL_OBJECT_COLUMN;
872  break;
873  case 'r':
874  objtype = ACL_OBJECT_RELATION;
875  break;
876  case 's':
877  objtype = ACL_OBJECT_SEQUENCE;
878  break;
879  case 'd':
880  objtype = ACL_OBJECT_DATABASE;
881  break;
882  case 'f':
883  objtype = ACL_OBJECT_FUNCTION;
884  break;
885  case 'l':
886  objtype = ACL_OBJECT_LANGUAGE;
887  break;
888  case 'L':
889  objtype = ACL_OBJECT_LARGEOBJECT;
890  break;
891  case 'n':
892  objtype = ACL_OBJECT_NAMESPACE;
893  break;
894  case 't':
895  objtype = ACL_OBJECT_TABLESPACE;
896  break;
897  case 'F':
898  objtype = ACL_OBJECT_FDW;
899  break;
900  case 'S':
901  objtype = ACL_OBJECT_FOREIGN_SERVER;
902  break;
903  case 'T':
904  objtype = ACL_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 }
GrantObjectType
Definition: parsenodes.h:1846
#define PG_RETURN_ACL_P(x)
Definition: acl.h:125
Acl * acldefault(GrantObjectType objtype, Oid ownerId)
Definition: acl.c:748
unsigned int Oid
Definition: postgres_ext.h:31
#define ERROR
Definition: elog.h:43
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
#define elog
Definition: elog.h:219
#define PG_GETARG_CHAR(n)
Definition: fmgr.h:238

◆ aclequal()

bool aclequal ( const Acl left_acl,
const Acl right_acl 
)

Definition at line 509 of file acl.c.

References ACL_DAT, and ACL_NUM.

Referenced by get_user_default_acl(), and SetDefaultACL().

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

◆ 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, BOOLOID, check_acl(), convert_aclright_to_string(), CreateTemplateTupleDesc(), CStringGetTextDatum, heap_form_tuple(), HeapTupleGetDatum, idx(), MemoryContextSwitchTo(), MemSet, FuncCallContext::multi_call_memory_ctx, N_ACL_RIGHTS, ObjectIdGetDatum, OIDOID, palloc(), PG_GETARG_ACL_P, SRF_FIRSTCALL_INIT, SRF_IS_FIRSTCALL, SRF_PERCALL_SETUP, SRF_RETURN_DONE, SRF_RETURN_NEXT, TEXTOID, 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, false);
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:57
static const char * convert_aclright_to_string(int aclright)
Definition: acl.c:1696
#define ACLITEM_GET_GOPTIONS(item)
Definition: acl.h:68
#define OIDOID
Definition: pg_type.h:328
#define TEXTOID
Definition: pg_type.h:324
#define SRF_IS_FIRSTCALL()
Definition: funcapi.h:293
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
#define MemSet(start, val, len)
Definition: c.h:853
Datum idx(PG_FUNCTION_ARGS)
Definition: _int_op.c:264
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition: heaptuple.c:695
#define SRF_PERCALL_SETUP()
Definition: funcapi.h:297
Oid ai_grantor
Definition: acl.h:58
TupleDesc tuple_desc
Definition: funcapi.h:121
#define SRF_RETURN_NEXT(_funcctx, _result)
Definition: funcapi.h:299
uint32 AclMode
Definition: parsenodes.h:70
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ACL_NUM(ACL)
Definition: acl.h:109
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
Definition: execTuples.c:1032
#define N_ACL_RIGHTS
Definition: parsenodes.h:85
void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
Definition: tupdesc.c:505
uintptr_t Datum
Definition: postgres.h:372
#define ACL_DAT(ACL)
Definition: acl.h:110
#define BoolGetDatum(X)
Definition: postgres.h:408
Definition: acl.h:55
MemoryContext multi_call_memory_ctx
Definition: funcapi.h:110
#define ACLITEM_GET_PRIVS(item)
Definition: acl.h:67
#define HeapTupleGetDatum(tuple)
Definition: funcapi.h:230
#define BOOLOID
Definition: pg_type.h:288
TupleDesc CreateTemplateTupleDesc(int natts, bool hasoid)
Definition: tupdesc.c:43
#define PG_GETARG_ACL_P(n)
Definition: acl.h:123
static Datum values[MAXATTR]
Definition: bootstrap.c:164
void * user_fctx
Definition: funcapi.h:91
void * palloc(Size size)
Definition: mcxt.c:848
#define CStringGetTextDatum(s)
Definition: builtins.h:91
int16 AttrNumber
Definition: attnum.h:21
static void check_acl(const Acl *acl)
Definition: acl.c:540
#define SRF_RETURN_DONE(_funcctx)
Definition: funcapi.h:317
#define SRF_FIRSTCALL_INIT()
Definition: funcapi.h:295

◆ 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:575
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define PG_RETURN_NULL()
Definition: fmgr.h:305

◆ aclitem_eq()

Datum aclitem_eq ( PG_FUNCTION_ARGS  )

Definition at line 693 of file acl.c.

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

694 {
697  bool result;
698 
699  result = a1->ai_privs == a2->ai_privs &&
700  a1->ai_grantee == a2->ai_grantee &&
701  a1->ai_grantor == a2->ai_grantor;
702  PG_RETURN_BOOL(result);
703 }
Oid ai_grantee
Definition: acl.h:57
#define PG_GETARG_ACLITEM_P(n)
Definition: acl.h:118
Oid ai_grantor
Definition: acl.h:58
AclMode ai_privs
Definition: acl.h:59
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
Definition: acl.h:55
static FormData_pg_attribute a1
Definition: heap.c:144
static FormData_pg_attribute a2
Definition: heap.c:150

◆ aclitem_match()

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

Definition at line 658 of file acl.c.

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

Referenced by aclnewowner(), and aclupdate().

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

◆ aclitemComparator()

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

Definition at line 669 of file acl.c.

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

Referenced by aclitemsort().

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

◆ aclitemin()

Datum aclitemin ( PG_FUNCTION_ARGS  )

Definition at line 565 of file acl.c.

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

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

◆ aclitemout()

Datum aclitemout ( PG_FUNCTION_ARGS  )

Definition at line 591 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(), and SearchSysCache1().

592 {
593  AclItem *aip = PG_GETARG_ACLITEM_P(0);
594  char *p;
595  char *out;
596  HeapTuple htup;
597  unsigned i;
598 
599  out = palloc(strlen("=/") +
600  2 * N_ACL_RIGHTS +
601  2 * (2 * NAMEDATALEN + 2) +
602  1);
603 
604  p = out;
605  *p = '\0';
606 
607  if (aip->ai_grantee != ACL_ID_PUBLIC)
608  {
610  if (HeapTupleIsValid(htup))
611  {
612  putid(p, NameStr(((Form_pg_authid) GETSTRUCT(htup))->rolname));
613  ReleaseSysCache(htup);
614  }
615  else
616  {
617  /* Generate numeric OID if we don't find an entry */
618  sprintf(p, "%u", aip->ai_grantee);
619  }
620  }
621  while (*p)
622  ++p;
623 
624  *p++ = '=';
625 
626  for (i = 0; i < N_ACL_RIGHTS; ++i)
627  {
628  if (ACLITEM_GET_PRIVS(*aip) & (1 << i))
629  *p++ = ACL_ALL_RIGHTS_STR[i];
630  if (ACLITEM_GET_GOPTIONS(*aip) & (1 << i))
631  *p++ = '*';
632  }
633 
634  *p++ = '/';
635  *p = '\0';
636 
638  if (HeapTupleIsValid(htup))
639  {
640  putid(p, NameStr(((Form_pg_authid) GETSTRUCT(htup))->rolname));
641  ReleaseSysCache(htup);
642  }
643  else
644  {
645  /* Generate numeric OID if we don't find an entry */
646  sprintf(p, "%u", aip->ai_grantor);
647  }
648 
649  PG_RETURN_CSTRING(out);
650 }
Oid ai_grantee
Definition: acl.h:57
static void putid(char *p, const char *s)
Definition: acl.c:189
#define ACLITEM_GET_GOPTIONS(item)
Definition: acl.h:68
#define GETSTRUCT(TUP)
Definition: htup_details.h:661
#define PG_GETARG_ACLITEM_P(n)
Definition: acl.h:118
Oid ai_grantor
Definition: acl.h:58
#define NAMEDATALEN
FormData_pg_authid * Form_pg_authid
Definition: pg_authid.h:72
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define N_ACL_RIGHTS
Definition: parsenodes.h:85
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1112
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1160
#define ACL_ALL_RIGHTS_STR
Definition: acl.h:152
Definition: acl.h:55
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:322
#define ACLITEM_GET_PRIVS(item)
Definition: acl.h:67
void * palloc(Size size)
Definition: mcxt.c:848
int i
#define NameStr(name)
Definition: c.h:547
#define ACL_ID_PUBLIC
Definition: acl.h:47

◆ aclitemsort()

void aclitemsort ( Acl acl)

Definition at line 495 of file acl.c.

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

Referenced by get_user_default_acl(), and SetDefaultACL().

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

◆ 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:692
Oid ai_grantee
Definition: acl.h:57
#define ACLITEM_ALL_GOPTION_BITS
Definition: acl.h:89
bool has_privs_of_role(Oid member, Oid role)
Definition: acl.c:4830
AclMode ai_privs
Definition: acl.h:59
uint32 AclMode
Definition: parsenodes.h:70
#define ERROR
Definition: elog.h:43
#define ACL_NUM(ACL)
Definition: acl.h:109
#define ACL_DAT(ACL)
Definition: acl.h:110
Definition: acl.h:55
int i
#define ACL_ID_PUBLIC
Definition: acl.h:47
#define elog
Definition: elog.h:219
static void check_acl(const Acl *acl)
Definition: acl.c:540

◆ 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:57
#define ACLITEM_ALL_GOPTION_BITS
Definition: acl.h:89
AclMode ai_privs
Definition: acl.h:59
uint32 AclMode
Definition: parsenodes.h:70
#define ERROR
Definition: elog.h:43
#define ACL_NUM(ACL)
Definition: acl.h:109
#define ACL_DAT(ACL)
Definition: acl.h:110
Definition: acl.h:55
int i
#define elog
Definition: elog.h:219
static void check_acl(const Acl *acl)
Definition: acl.c:540

◆ 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(), heap_create_with_catalog(), ProcedureCreate(), 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:57
unsigned int Oid
Definition: postgres_ext.h:31
Oid ai_grantor
Definition: acl.h:58
#define ACL_NUM(ACL)
Definition: acl.h:109
#define ACL_DAT(ACL)
Definition: acl.h:110
Definition: acl.h:55
int oid_cmp(const void *p1, const void *p2)
Definition: oid.c:336
void * palloc(Size size)
Definition: mcxt.c:848
int i
#define ACL_ID_PUBLIC
Definition: acl.h:47
#define qsort(a, b, c, d)
Definition: port.h:408
static void check_acl(const Acl *acl)
Definition: acl.c:540

◆ aclmerge()

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

Definition at line 451 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().

452 {
453  Acl *result_acl;
454  AclItem *aip;
455  int i,
456  num;
457 
458  /* Check for cases where one or both are empty/null */
459  if (left_acl == NULL || ACL_NUM(left_acl) == 0)
460  {
461  if (right_acl == NULL || ACL_NUM(right_acl) == 0)
462  return NULL;
463  else
464  return aclcopy(right_acl);
465  }
466  else
467  {
468  if (right_acl == NULL || ACL_NUM(right_acl) == 0)
469  return aclcopy(left_acl);
470  }
471 
472  /* Merge them the hard way, one item at a time */
473  result_acl = aclcopy(left_acl);
474 
475  aip = ACL_DAT(right_acl);
476  num = ACL_NUM(right_acl);
477 
478  for (i = 0; i < num; i++, aip++)
479  {
480  Acl *tmp_acl;
481 
482  tmp_acl = aclupdate(result_acl, aip, ACL_MODECHG_ADD,
483  ownerId, DROP_RESTRICT);
484  pfree(result_acl);
485  result_acl = tmp_acl;
486  }
487 
488  return result_acl;
489 }
void pfree(void *pointer)
Definition: mcxt.c:949
#define ACL_NUM(ACL)
Definition: acl.h:109
#define ACL_MODECHG_ADD
Definition: acl.h:130
#define ACL_DAT(ACL)
Definition: acl.h:110
Definition: acl.h:55
Acl * aclcopy(const Acl *orig_acl)
Definition: acl.c:407
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:57
static Acl * allocacl(int n)
Definition: acl.c:376
Oid ai_grantor
Definition: acl.h:58
#define ARR_DIMS(a)
Definition: array.h:279
#define ACL_NUM(ACL)
Definition: acl.h:109
#define ACL_NO_RIGHTS
Definition: parsenodes.h:86
#define ACLITEM_GET_RIGHTS(item)
Definition: acl.h:69
#define ACLITEM_SET_RIGHTS(item, rights)
Definition: acl.h:80
#define ACL_DAT(ACL)
Definition: acl.h:110
Definition: acl.h:55
static bool aclitem_match(const AclItem *a1, const AclItem *a2)
Definition: acl.c:658
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:328
#define ACL_N_SIZE(N)
Definition: acl.h:111
static void check_acl(const Acl *acl)
Definition: acl.c:540

◆ aclparse()

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

Definition at line 238 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, BOOTSTRAP_SUPERUSERID, elog, ereport, errcode(), errhint(), errmsg(), ERROR, get_role_oid(), getid(), LOG, name, NAMEDATALEN, read, and WARNING.

Referenced by aclitemin().

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

◆ 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:575
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define PG_RETURN_NULL()
Definition: fmgr.h:305

◆ 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:57
#define ACL_MODECHG_EQL
Definition: acl.h:132
#define ACLITEM_GET_GOPTIONS(item)
Definition: acl.h:68
static Acl * allocacl(int n)
Definition: acl.c:376
#define ACL_MODECHG_DEL
Definition: acl.h:131
#define ACL_SIZE(ACL)
Definition: acl.h:112
Oid ai_grantor
Definition: acl.h:58
uint32 AclMode
Definition: parsenodes.h:70
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:279
#define ACL_NUM(ACL)
Definition: acl.h:109
#define ACL_NO_RIGHTS
Definition: parsenodes.h:86
#define memmove(d, s, c)
Definition: c.h:1045
#define ACLITEM_GET_RIGHTS(item)
Definition: acl.h:69
#define ACLITEM_SET_RIGHTS(item, rights)
Definition: acl.h:80
#define ACL_MODECHG_ADD
Definition: acl.h:130
#define ACL_DAT(ACL)
Definition: acl.h:110
Definition: acl.h:55
#define Assert(condition)
Definition: c.h:670
static bool aclitem_match(const AclItem *a1, const AclItem *a2)
Definition: acl.c:658
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:47
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:328
#define ACL_N_SIZE(N)
Definition: acl.h:111
#define ACLITEM_SET_PRIVS_GOPTIONS(item, privs, goptions)
Definition: acl.h:83
static void check_acl(const Acl *acl)
Definition: acl.c:540

◆ allocacl()

static Acl * allocacl ( int  n)
static

Definition at line 376 of file acl.c.

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

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

◆ check_acl()

static void check_acl ( const Acl acl)
static

Definition at line 540 of file acl.c.

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

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

◆ 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:57
#define ACLITEM_GET_GOPTIONS(item)
Definition: acl.h:68
static Acl * allocacl(int n)
Definition: acl.c:376
#define ACL_MODECHG_DEL
Definition: acl.h:131
AclMode aclmask(const Acl *acl, Oid roleid, Oid ownerId, AclMode mask, AclMaskHow how)
Definition: acl.c:1321
#define ACL_SIZE(ACL)
Definition: acl.h:112
int errcode(int sqlerrcode)
Definition: elog.c:575
Oid ai_grantor
Definition: acl.h:58
uint32 AclMode
Definition: parsenodes.h:70
void pfree(void *pointer)
Definition: mcxt.c:949
#define ERROR
Definition: elog.h:43
#define ACL_NUM(ACL)
Definition: acl.h:109
#define ACL_NO_RIGHTS
Definition: parsenodes.h:86
#define ereport(elevel, rest)
Definition: elog.h:122
#define ACL_GRANT_OPTION_FOR(privs)
Definition: acl.h:71
#define ACL_DAT(ACL)
Definition: acl.h:110
Definition: acl.h:55
#define ACL_OPTION_TO_PRIVS(privs)
Definition: acl.h:72
#define Assert(condition)
Definition: c.h:670
int errmsg(const char *fmt,...)
Definition: elog.c:797
int i
#define ACL_ID_PUBLIC
Definition: acl.h:47
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:540

◆ check_is_member_of_role()

void check_is_member_of_role ( Oid  member,
Oid  role 
)

Definition at line 4876 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().

4877 {
4878  if (!is_member_of_role(member, role))
4879  ereport(ERROR,
4880  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
4881  errmsg("must be member of role \"%s\"",
4882  GetUserNameFromId(role, false))));
4883 }
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
bool is_member_of_role(Oid member, Oid role)
Definition: acl.c:4854
char * GetUserNameFromId(Oid roleid, bool noerr)
Definition: miscinit.c:692
int errmsg(const char *fmt,...)
Definition: elog.c:797

◆ check_rolespec_name()

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

Definition at line 5250 of file acl.c.

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

Referenced by AlterRole(), and AlterRoleSet().

5251 {
5252  if (!role)
5253  return;
5254 
5255  if (role->roletype != ROLESPEC_CSTRING)
5256  return;
5257 
5258  if (IsReservedName(role->rolename))
5259  {
5260  if (detail_msg)
5261  ereport(ERROR,
5262  (errcode(ERRCODE_RESERVED_NAME),
5263  errmsg("role name \"%s\" is reserved",
5264  role->rolename),
5265  errdetail("%s", detail_msg)));
5266  else
5267  ereport(ERROR,
5268  (errcode(ERRCODE_RESERVED_NAME),
5269  errmsg("role name \"%s\" is reserved",
5270  role->rolename)));
5271  }
5272 }
int errcode(int sqlerrcode)
Definition: elog.c:575
bool IsReservedName(const char *name)
Definition: catalog.c:194
#define ERROR
Definition: elog.h:43
int errdetail(const char *fmt,...)
Definition: elog.c:873
#define ereport(elevel, rest)
Definition: elog.h:122
RoleSpecType roletype
Definition: parsenodes.h:327
char * rolename
Definition: parsenodes.h:328
int errmsg(const char *fmt,...)
Definition: elog.c:797

◆ column_privilege_check()

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

Definition at line 2459 of file acl.c.

References ACLCHECK_OK, ATTNUM, GETSTRUCT, HeapTupleIsValid, Int16GetDatum, 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().

2461 {
2462  AclResult aclresult;
2463  HeapTuple attTuple;
2464  Form_pg_attribute attributeForm;
2465 
2466  /*
2467  * First check if we have the privilege at the table level. We check
2468  * existence of the pg_class row before risking calling pg_class_aclcheck.
2469  * Note: it might seem there's a race condition against concurrent DROP,
2470  * but really it's safe because there will be no syscache flush between
2471  * here and there. So if we see the row in the syscache, so will
2472  * pg_class_aclcheck.
2473  */
2475  return -1;
2476 
2477  aclresult = pg_class_aclcheck(tableoid, roleid, mode);
2478 
2479  if (aclresult == ACLCHECK_OK)
2480  return true;
2481 
2482  /*
2483  * No table privilege, so try per-column privileges. Again, we have to
2484  * check for dropped attribute first, and we rely on the syscache not to
2485  * notice a concurrent drop before pg_attribute_aclcheck fetches the row.
2486  */
2487  attTuple = SearchSysCache2(ATTNUM,
2488  ObjectIdGetDatum(tableoid),
2489  Int16GetDatum(attnum));
2490  if (!HeapTupleIsValid(attTuple))
2491  return -1;
2492  attributeForm = (Form_pg_attribute) GETSTRUCT(attTuple);
2493  if (attributeForm->attisdropped)
2494  {
2495  ReleaseSysCache(attTuple);
2496  return -1;
2497  }
2498  ReleaseSysCache(attTuple);
2499 
2500  aclresult = pg_attribute_aclcheck(tableoid, attnum, roleid, mode);
2501 
2502  return (aclresult == ACLCHECK_OK);
2503 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:661
AclResult pg_attribute_aclcheck(Oid table_oid, AttrNumber attnum, Oid roleid, AclMode mode)
Definition: aclchk.c:4308
#define Int16GetDatum(X)
Definition: postgres.h:457
#define SearchSysCacheExists1(cacheId, key1)
Definition: syscache.h:182
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:187
AclResult
Definition: acl.h:178
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1160
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
HeapTuple SearchSysCache2(int cacheId, Datum key1, Datum key2)
Definition: syscache.c:1123
AclResult pg_class_aclcheck(Oid table_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4422

◆ 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:75
#define ERROR
Definition: elog.h:43
#define ACL_CREATE
Definition: parsenodes.h:82
#define ACL_TRIGGER
Definition: parsenodes.h:78
#define ACL_USAGE
Definition: parsenodes.h:80
#define ACL_CONNECT
Definition: parsenodes.h:84
#define ACL_UPDATE
Definition: parsenodes.h:74
#define ACL_SELECT
Definition: parsenodes.h:73
#define ACL_REFERENCES
Definition: parsenodes.h:77
#define ACL_INSERT
Definition: parsenodes.h:72
#define ACL_EXECUTE
Definition: parsenodes.h:79
#define ACL_CREATE_TEMP
Definition: parsenodes.h:83
#define elog
Definition: elog.h:219
#define ACL_TRUNCATE
Definition: parsenodes.h:76

◆ 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:43
int errcode(int sqlerrcode)
Definition: elog.c:575
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
const char * name
Definition: acl.c:45
uint32 AclMode
Definition: parsenodes.h:70
void pfree(void *pointer)
Definition: mcxt.c:949
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
AclMode value
Definition: acl.c:46
char * text_to_cstring(const text *t)
Definition: varlena.c:182
int errmsg(const char *fmt,...)
Definition: elog.c:797

◆ convert_column_name()

static AttrNumber convert_column_name ( Oid  tableoid,
text column 
)
static

Definition at line 2830 of file acl.c.

References ereport, errcode(), errmsg(), ERROR, get_attnum(), get_rel_name(), InvalidAttrNumber, pfree(), 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().

2831 {
2832  AttrNumber attnum;
2833  char *colname;
2834 
2835  colname = text_to_cstring(column);
2836  attnum = get_attnum(tableoid, colname);
2837  if (attnum == InvalidAttrNumber)
2838  ereport(ERROR,
2839  (errcode(ERRCODE_UNDEFINED_COLUMN),
2840  errmsg("column \"%s\" of relation \"%s\" does not exist",
2841  colname, get_rel_name(tableoid))));
2842  pfree(colname);
2843  return attnum;
2844 }
int errcode(int sqlerrcode)
Definition: elog.c:575
void pfree(void *pointer)
Definition: mcxt.c:949
#define ERROR
Definition: elog.h:43
AttrNumber get_attnum(Oid relid, const char *attname)
Definition: lsyscache.c:821
#define ereport(elevel, rest)
Definition: elog.h:122
#define InvalidAttrNumber
Definition: attnum.h:23
char * text_to_cstring(const text *t)
Definition: varlena.c:182
int errmsg(const char *fmt,...)
Definition: elog.c:797
char * get_rel_name(Oid relid)
Definition: lsyscache.c:1726
int16 AttrNumber
Definition: attnum.h:21

◆ convert_column_priv_string()

static AclMode convert_column_priv_string ( text priv_type_text)
static

Definition at line 2851 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().

2852 {
2853  static const priv_map column_priv_map[] = {
2854  {"SELECT", ACL_SELECT},
2855  {"SELECT WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_SELECT)},
2856  {"INSERT", ACL_INSERT},
2857  {"INSERT WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_INSERT)},
2858  {"UPDATE", ACL_UPDATE},
2859  {"UPDATE WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_UPDATE)},
2860  {"REFERENCES", ACL_REFERENCES},
2861  {"REFERENCES WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_REFERENCES)},
2862  {NULL, 0}
2863  };
2864 
2865  return convert_any_priv_string(priv_type_text, column_priv_map);
2866 }
Definition: acl.c:43
static AclMode convert_any_priv_string(text *priv_type_text, const priv_map *privileges)
Definition: acl.c:1648
#define ACL_UPDATE
Definition: parsenodes.h:74
#define ACL_GRANT_OPTION_FOR(privs)
Definition: acl.h:71
#define ACL_SELECT
Definition: parsenodes.h:73
#define ACL_REFERENCES
Definition: parsenodes.h:77
#define ACL_INSERT
Definition: parsenodes.h:72

◆ convert_database_name()

static Oid convert_database_name ( text databasename)
static

Definition at line 3036 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().

3037 {
3038  char *dbname = text_to_cstring(databasename);
3039 
3040  return get_database_oid(dbname, false);
3041 }
Oid get_database_oid(const char *dbname, bool missing_ok)
Definition: dbcommands.c:2009
char * dbname
Definition: streamutil.c:42
char * text_to_cstring(const text *t)
Definition: varlena.c:182

◆ convert_database_priv_string()

static AclMode convert_database_priv_string ( text priv_type_text)
static

Definition at line 3048 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().

3049 {
3050  static const priv_map database_priv_map[] = {
3051  {"CREATE", ACL_CREATE},
3052  {"CREATE WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_CREATE)},
3053  {"TEMPORARY", ACL_CREATE_TEMP},
3054  {"TEMPORARY WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_CREATE_TEMP)},
3055  {"TEMP", ACL_CREATE_TEMP},
3056  {"TEMP WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_CREATE_TEMP)},
3057  {"CONNECT", ACL_CONNECT},
3058  {"CONNECT WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_CONNECT)},
3059  {NULL, 0}
3060  };
3061 
3062  return convert_any_priv_string(priv_type_text, database_priv_map);
3063 
3064 }
Definition: acl.c:43
static AclMode convert_any_priv_string(text *priv_type_text, const priv_map *privileges)
Definition: acl.c:1648
#define ACL_CREATE
Definition: parsenodes.h:82
#define ACL_CONNECT
Definition: parsenodes.h:84
#define ACL_GRANT_OPTION_FOR(privs)
Definition: acl.h:71
#define ACL_CREATE_TEMP
Definition: parsenodes.h:83

◆ convert_foreign_data_wrapper_name()

static Oid convert_foreign_data_wrapper_name ( text fdwname)
static

Definition at line 3225 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().

3226 {
3227  char *fdwstr = text_to_cstring(fdwname);
3228 
3229  return get_foreign_data_wrapper_oid(fdwstr, false);
3230 }
Oid get_foreign_data_wrapper_oid(const char *fdwname, bool missing_ok)
Definition: foreign.c:659
char * text_to_cstring(const text *t)
Definition: varlena.c:182

◆ convert_foreign_data_wrapper_priv_string()

static AclMode convert_foreign_data_wrapper_priv_string ( text priv_type_text)
static

Definition at line 3237 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().

3238 {
3239  static const priv_map foreign_data_wrapper_priv_map[] = {
3240  {"USAGE", ACL_USAGE},
3241  {"USAGE WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_USAGE)},
3242  {NULL, 0}
3243  };
3244 
3245  return convert_any_priv_string(priv_type_text, foreign_data_wrapper_priv_map);
3246 }
Definition: acl.c:43
static AclMode convert_any_priv_string(text *priv_type_text, const priv_map *privileges)
Definition: acl.c:1648
#define ACL_USAGE
Definition: parsenodes.h:80
#define ACL_GRANT_OPTION_FOR(privs)
Definition: acl.h:71

◆ convert_function_name()

static Oid convert_function_name ( text functionname)
static

Definition at line 3416 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().

3417 {
3418  char *funcname = text_to_cstring(functionname);
3419  Oid oid;
3420 
3422  CStringGetDatum(funcname)));
3423 
3424  if (!OidIsValid(oid))
3425  ereport(ERROR,
3426  (errcode(ERRCODE_UNDEFINED_FUNCTION),
3427  errmsg("function \"%s\" does not exist", funcname)));
3428 
3429  return oid;
3430 }
#define DatumGetObjectId(X)
Definition: postgres.h:506
int errcode(int sqlerrcode)
Definition: elog.c:575
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:585
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:576
#define ERROR
Definition: elog.h:43
Datum regprocedurein(PG_FUNCTION_ARGS)
Definition: regproc.c:231
#define CStringGetDatum(X)
Definition: postgres.h:584
#define ereport(elevel, rest)
Definition: elog.h:122
char * text_to_cstring(const text *t)
Definition: varlena.c:182
int errmsg(const char *fmt,...)
Definition: elog.c:797

◆ convert_function_priv_string()

static AclMode convert_function_priv_string ( text priv_type_text)
static

Definition at line 3437 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().

3438 {
3439  static const priv_map function_priv_map[] = {
3440  {"EXECUTE", ACL_EXECUTE},
3441  {"EXECUTE WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_EXECUTE)},
3442  {NULL, 0}
3443  };
3444 
3445  return convert_any_priv_string(priv_type_text, function_priv_map);
3446 }
Definition: acl.c:43
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:71
#define ACL_EXECUTE
Definition: parsenodes.h:79

◆ convert_language_name()

static Oid convert_language_name ( text languagename)
static

Definition at line 3616 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().

3617 {
3618  char *langname = text_to_cstring(languagename);
3619 
3620  return get_language_oid(langname, false);
3621 }
Oid get_language_oid(const char *langname, bool missing_ok)
Definition: proclang.c:553
char * text_to_cstring(const text *t)
Definition: varlena.c:182

◆ convert_language_priv_string()

static AclMode convert_language_priv_string ( text priv_type_text)
static

Definition at line 3628 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().

3629 {
3630  static const priv_map language_priv_map[] = {
3631  {"USAGE", ACL_USAGE},
3632  {"USAGE WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_USAGE)},
3633  {NULL, 0}
3634  };
3635 
3636  return convert_any_priv_string(priv_type_text, language_priv_map);
3637 }
Definition: acl.c:43
static AclMode convert_any_priv_string(text *priv_type_text, const priv_map *privileges)
Definition: acl.c:1648
#define ACL_USAGE
Definition: parsenodes.h:80
#define ACL_GRANT_OPTION_FOR(privs)
Definition: acl.h:71

◆ 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:575
#define ACL_DELETE
Definition: parsenodes.h:75
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:82
#define ACL_NO_RIGHTS
Definition: parsenodes.h:86
#define ACL_TRIGGER
Definition: parsenodes.h:78
#define ACL_USAGE
Definition: parsenodes.h:80
#define ereport(elevel, rest)
Definition: elog.h:122
#define ACL_CONNECT
Definition: parsenodes.h:84
#define ACL_UPDATE
Definition: parsenodes.h:74
#define ACL_SELECT
Definition: parsenodes.h:73
#define ACL_REFERENCES
Definition: parsenodes.h:77
#define ACL_INSERT
Definition: parsenodes.h:72
char * text_to_cstring(const text *t)
Definition: varlena.c:182
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define ACL_EXECUTE
Definition: parsenodes.h:79
#define ACL_CREATE_TEMP
Definition: parsenodes.h:83
#define ACL_TRUNCATE
Definition: parsenodes.h:76

◆ convert_role_priv_string()

static AclMode convert_role_priv_string ( text priv_type_text)
static

Definition at line 4561 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().

4562 {
4563  static const priv_map role_priv_map[] = {
4564  {"USAGE", ACL_USAGE},
4565  {"MEMBER", ACL_CREATE},
4566  {"USAGE WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_CREATE)},
4567  {"USAGE WITH ADMIN OPTION", ACL_GRANT_OPTION_FOR(ACL_CREATE)},
4568  {"MEMBER WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_CREATE)},
4569  {"MEMBER WITH ADMIN OPTION", ACL_GRANT_OPTION_FOR(ACL_CREATE)},
4570  {NULL, 0}
4571  };
4572 
4573  return convert_any_priv_string(priv_type_text, role_priv_map);
4574 }
Definition: acl.c:43
static AclMode convert_any_priv_string(text *priv_type_text, const priv_map *privileges)
Definition: acl.c:1648
#define ACL_CREATE
Definition: parsenodes.h:82
#define ACL_USAGE
Definition: parsenodes.h:80
#define ACL_GRANT_OPTION_FOR(privs)
Definition: acl.h:71

◆ convert_schema_name()

static Oid convert_schema_name ( text schemaname)
static

Definition at line 3807 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().

3808 {
3809  char *nspname = text_to_cstring(schemaname);
3810 
3811  return get_namespace_oid(nspname, false);
3812 }
Oid get_namespace_oid(const char *nspname, bool missing_ok)
Definition: namespace.c:3005
char * text_to_cstring(const text *t)
Definition: varlena.c:182

◆ convert_schema_priv_string()

static AclMode convert_schema_priv_string ( text priv_type_text)
static

Definition at line 3819 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().

3820 {
3821  static const priv_map schema_priv_map[] = {
3822  {"CREATE", ACL_CREATE},
3823  {"CREATE WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_CREATE)},
3824  {"USAGE", ACL_USAGE},
3825  {"USAGE WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_USAGE)},
3826  {NULL, 0}
3827  };
3828 
3829  return convert_any_priv_string(priv_type_text, schema_priv_map);
3830 }
Definition: acl.c:43
static AclMode convert_any_priv_string(text *priv_type_text, const priv_map *privileges)
Definition: acl.c:1648
#define ACL_CREATE
Definition: parsenodes.h:82
#define ACL_USAGE
Definition: parsenodes.h:80
#define ACL_GRANT_OPTION_FOR(privs)
Definition: acl.h:71

◆ 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_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  {"SELECT", ACL_SELECT},
2246  {"UPDATE", ACL_UPDATE},
2247  {NULL, 0}
2248  };
2249 
2250  return convert_any_priv_string(priv_type_text, sequence_priv_map);
2251 }
Definition: acl.c:43
static AclMode convert_any_priv_string(text *priv_type_text, const priv_map *privileges)
Definition: acl.c:1648
#define ACL_USAGE
Definition: parsenodes.h:80
#define ACL_UPDATE
Definition: parsenodes.h:74
#define ACL_SELECT
Definition: parsenodes.h:73

◆ convert_server_name()

static Oid convert_server_name ( text servername)
static

Definition at line 3991 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().

3992 {
3993  char *serverstr = text_to_cstring(servername);
3994 
3995  return get_foreign_server_oid(serverstr, false);
3996 }
char * text_to_cstring(const text *t)
Definition: varlena.c:182
Oid get_foreign_server_oid(const char *servername, bool missing_ok)
Definition: foreign.c:680

◆ convert_server_priv_string()

static AclMode convert_server_priv_string ( text priv_type_text)
static

Definition at line 4003 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().

4004 {
4005  static const priv_map server_priv_map[] = {
4006  {"USAGE", ACL_USAGE},
4007  {"USAGE WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_USAGE)},
4008  {NULL, 0}
4009  };
4010 
4011  return convert_any_priv_string(priv_type_text, server_priv_map);
4012 }
Definition: acl.c:43
static AclMode convert_any_priv_string(text *priv_type_text, const priv_map *privileges)
Definition: acl.c:1648
#define ACL_USAGE
Definition: parsenodes.h:80
#define ACL_GRANT_OPTION_FOR(privs)
Definition: acl.h:71

◆ 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:43
#define ACL_DELETE
Definition: parsenodes.h:75
static AclMode convert_any_priv_string(text *priv_type_text, const priv_map *privileges)
Definition: acl.c:1648
#define ACL_TRIGGER
Definition: parsenodes.h:78
#define ACL_UPDATE
Definition: parsenodes.h:74
#define ACL_GRANT_OPTION_FOR(privs)
Definition: acl.h:71
#define ACL_SELECT
Definition: parsenodes.h:73
#define ACL_REFERENCES
Definition: parsenodes.h:77
#define ACL_INSERT
Definition: parsenodes.h:72
#define ACL_TRUNCATE
Definition: parsenodes.h:76

◆ convert_tablespace_name()

static Oid convert_tablespace_name ( text tablespacename)
static

Definition at line 4173 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().

4174 {
4175  char *spcname = text_to_cstring(tablespacename);
4176 
4177  return get_tablespace_oid(spcname, false);
4178 }
Oid get_tablespace_oid(const char *tablespacename, bool missing_ok)
Definition: tablespace.c:1380
char * text_to_cstring(const text *t)
Definition: varlena.c:182

◆ convert_tablespace_priv_string()

static AclMode convert_tablespace_priv_string ( text priv_type_text)
static

Definition at line 4185 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().

4186 {
4187  static const priv_map tablespace_priv_map[] = {
4188  {"CREATE", ACL_CREATE},
4189  {"CREATE WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_CREATE)},
4190  {NULL, 0}
4191  };
4192 
4193  return convert_any_priv_string(priv_type_text, tablespace_priv_map);
4194 }
Definition: acl.c:43
static AclMode convert_any_priv_string(text *priv_type_text, const priv_map *privileges)
Definition: acl.c:1648
#define ACL_CREATE
Definition: parsenodes.h:82
#define ACL_GRANT_OPTION_FOR(privs)
Definition: acl.h:71

◆ convert_type_name()

static Oid convert_type_name ( text typename)
static

Definition at line 4363 of file acl.c.

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

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

4364 {
4365  char *typname = text_to_cstring(typename);
4366  Oid oid;
4367 
4369  CStringGetDatum(typname)));
4370 
4371  if (!OidIsValid(oid))
4372  ereport(ERROR,
4373  (errcode(ERRCODE_UNDEFINED_OBJECT),
4374  errmsg("type \"%s\" does not exist", typname)));
4375 
4376  return oid;
4377 }
#define DatumGetObjectId(X)
Definition: postgres.h:506
int errcode(int sqlerrcode)
Definition: elog.c:575
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:585
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:576
#define ERROR
Definition: elog.h:43
#define CStringGetDatum(X)
Definition: postgres.h:584
#define ereport(elevel, rest)
Definition: elog.h:122
Datum regtypein(PG_FUNCTION_ARGS)
Definition: regproc.c:1061
char * text_to_cstring(const text *t)
Definition: varlena.c:182
int errmsg(const char *fmt,...)
Definition: elog.c:797

◆ convert_type_priv_string()

static AclMode convert_type_priv_string ( text priv_type_text)
static

Definition at line 4384 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().

4385 {
4386  static const priv_map type_priv_map[] = {
4387  {"USAGE", ACL_USAGE},
4388  {"USAGE WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_USAGE)},
4389  {NULL, 0}
4390  };
4391 
4392  return convert_any_priv_string(priv_type_text, type_priv_map);
4393 }
Definition: acl.c:43
static AclMode convert_any_priv_string(text *priv_type_text, const priv_map *privileges)
Definition: acl.c:1648
#define ACL_USAGE
Definition: parsenodes.h:80
#define ACL_GRANT_OPTION_FOR(privs)
Definition: acl.h:71

◆ count_one_bits()

static int count_one_bits ( AclMode  mask)
static

Definition at line 4998 of file acl.c.

Referenced by select_best_grantor().

4999 {
5000  int nbits = 0;
5001 
5002  /* this code relies on AclMode being an unsigned type */
5003  while (mask)
5004  {
5005  if (mask & 1)
5006  nbits++;
5007  mask >>= 1;
5008  }
5009  return nbits;
5010 }

◆ get_role_oid()

Oid get_role_oid ( const char *  rolname,
bool  missing_ok 
)

Definition at line 5113 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().

5114 {
5115  Oid oid;
5116 
5117  oid = GetSysCacheOid1(AUTHNAME, CStringGetDatum(rolname));
5118  if (!OidIsValid(oid) && !missing_ok)
5119  ereport(ERROR,
5120  (errcode(ERRCODE_UNDEFINED_OBJECT),
5121  errmsg("role \"%s\" does not exist", rolname)));
5122  return oid;
5123 }
int errcode(int sqlerrcode)
Definition: elog.c:575
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:576
#define GetSysCacheOid1(cacheId, key1)
Definition: syscache.h:191
#define ERROR
Definition: elog.h:43
#define CStringGetDatum(X)
Definition: postgres.h:584
#define ereport(elevel, rest)
Definition: elog.h:122
int errmsg(const char *fmt,...)
Definition: elog.c:797

◆ get_role_oid_or_public()

◆ get_rolespec_name()

char* get_rolespec_name ( const RoleSpec role)

Definition at line 5228 of file acl.c.

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

Referenced by AddRoleMems(), and DelRoleMems().

5229 {
5230  HeapTuple tp;
5231  Form_pg_authid authForm;
5232  char *rolename;
5233 
5234  tp = get_rolespec_tuple(role);
5235  authForm = (Form_pg_authid) GETSTRUCT(tp);
5236  rolename = pstrdup(NameStr(authForm->rolname));
5237  ReleaseSysCache(tp);
5238 
5239  return rolename;
5240 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:661
char * pstrdup(const char *in)
Definition: mcxt.c:1076
FormData_pg_authid * Form_pg_authid
Definition: pg_authid.h:72
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1160
HeapTuple get_rolespec_tuple(const RoleSpec *role)
Definition: acl.c:5184
#define NameStr(name)
Definition: c.h:547

◆ get_rolespec_oid()

Oid get_rolespec_oid ( const RoleSpec role,
bool  missing_ok 
)

Definition at line 5146 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().

5147 {
5148  Oid oid;
5149 
5150  switch (role->roletype)
5151  {
5152  case ROLESPEC_CSTRING:
5153  Assert(role->rolename);
5154  oid = get_role_oid(role->rolename, missing_ok);
5155  break;
5156 
5157  case ROLESPEC_CURRENT_USER:
5158  oid = GetUserId();
5159  break;
5160 
5161  case ROLESPEC_SESSION_USER:
5162  oid = GetSessionUserId();
5163  break;
5164 
5165  case ROLESPEC_PUBLIC:
5166  ereport(ERROR,
5167  (errcode(ERRCODE_UNDEFINED_OBJECT),
5168  errmsg("role \"%s\" does not exist", "public")));
5169  oid = InvalidOid; /* make compiler happy */
5170  break;
5171 
5172  default:
5173  elog(ERROR, "unexpected role type %d", role->roletype);
5174  }
5175 
5176  return oid;
5177 }
Oid GetUserId(void)
Definition: miscinit.c:284
int errcode(int sqlerrcode)
Definition: elog.c:575
unsigned int Oid
Definition: postgres_ext.h:31
Oid GetSessionUserId(void)
Definition: miscinit.c:318
Oid get_role_oid(const char *rolname, bool missing_ok)
Definition: acl.c:5113
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
RoleSpecType roletype
Definition: parsenodes.h:327
#define InvalidOid
Definition: postgres_ext.h:36
#define Assert(condition)
Definition: c.h:670
char * rolename
Definition: parsenodes.h:328
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define elog
Definition: elog.h:219

◆ get_rolespec_tuple()

HeapTuple get_rolespec_tuple ( const RoleSpec role)

Definition at line 5184 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().

5185 {
5186  HeapTuple tuple;
5187 
5188  switch (role->roletype)
5189  {
5190  case ROLESPEC_CSTRING:
5191  Assert(role->rolename);
5193  if (!HeapTupleIsValid(tuple))
5194  ereport(ERROR,
5195  (errcode(ERRCODE_UNDEFINED_OBJECT),
5196  errmsg("role \"%s\" does not exist", role->rolename)));
5197  break;
5198 
5199  case ROLESPEC_CURRENT_USER:
5200  tuple = SearchSysCache1(AUTHOID, GetUserId());
5201  if (!HeapTupleIsValid(tuple))
5202  elog(ERROR, "cache lookup failed for role %u", GetUserId());
5203  break;
5204 
5205  case ROLESPEC_SESSION_USER:
5207  if (!HeapTupleIsValid(tuple))
5208  elog(ERROR, "cache lookup failed for role %u", GetSessionUserId());
5209  break;
5210 
5211  case ROLESPEC_PUBLIC:
5212  ereport(ERROR,
5213  (errcode(ERRCODE_UNDEFINED_OBJECT),
5214  errmsg("role \"%s\" does not exist", "public")));
5215  tuple = NULL; /* make compiler happy */
5216 
5217  default:
5218  elog(ERROR, "unexpected role type %d", role->roletype);
5219  }
5220 
5221  return tuple;
5222 }
Oid GetUserId(void)
Definition: miscinit.c:284
int errcode(int sqlerrcode)
Definition: elog.c:575
Oid GetSessionUserId(void)
Definition: miscinit.c:318
#define ERROR
Definition: elog.h:43
#define CStringGetDatum(X)
Definition: postgres.h:584
#define ereport(elevel, rest)
Definition: elog.h:122
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1112
RoleSpecType roletype
Definition: parsenodes.h:327
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define Assert(condition)
Definition: c.h:670
char * rolename
Definition: parsenodes.h:328
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define elog
Definition: elog.h:219

◆ getid()

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

Definition at line 137 of file acl.c.

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

Referenced by aclparse().

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

◆ has_any_column_privilege_id()

Datum has_any_column_privilege_id ( PG_FUNCTION_ARGS  )

Definition at line 2360 of file acl.c.

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

2361 {
2362  Oid tableoid = PG_GETARG_OID(0);
2363  text *priv_type_text = PG_GETARG_TEXT_PP(1);
2364  Oid roleid;
2365  AclMode mode;
2366  AclResult aclresult;
2367 
2368  roleid = GetUserId();
2369  mode = convert_column_priv_string(priv_type_text);
2370 
2372  PG_RETURN_NULL();
2373 
2374  /* First check at table level, then examine each column if needed */
2375  aclresult = pg_class_aclcheck(tableoid, roleid, mode);
2376  if (aclresult != ACLCHECK_OK)
2377  aclresult = pg_attribute_aclcheck_all(tableoid, roleid, mode,
2378  ACLMASK_ANY);
2379 
2380  PG_RETURN_BOOL(aclresult == ACLCHECK_OK);
2381 }
Oid GetUserId(void)
Definition: miscinit.c:284
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:273
uint32 AclMode
Definition: parsenodes.h:70
#define SearchSysCacheExists1(cacheId, key1)
Definition: syscache.h:182
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
AclResult
Definition: acl.h:178
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
AclResult pg_attribute_aclcheck_all(Oid table_oid, Oid roleid, AclMode mode, AclMaskHow how)
Definition: aclchk.c:4337
AclResult pg_class_aclcheck(Oid table_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4422
Definition: c.h:487
static AclMode convert_column_priv_string(text *priv_type_text)
Definition: acl.c:2851
#define PG_RETURN_NULL()
Definition: fmgr.h:305

◆ has_any_column_privilege_id_id()

Datum has_any_column_privilege_id_id ( PG_FUNCTION_ARGS  )

Definition at line 2416 of file acl.c.

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

2417 {
2418  Oid roleid = PG_GETARG_OID(0);
2419  Oid tableoid = PG_GETARG_OID(1);
2420  text *priv_type_text = PG_GETARG_TEXT_PP(2);
2421  AclMode mode;
2422  AclResult aclresult;
2423 
2424  mode = convert_column_priv_string(priv_type_text);
2425 
2427  PG_RETURN_NULL();
2428 
2429  /* First check at table level, then examine each column if needed */
2430  aclresult = pg_class_aclcheck(tableoid, roleid, mode);
2431  if (aclresult != ACLCHECK_OK)
2432  aclresult = pg_attribute_aclcheck_all(tableoid, roleid, mode,
2433  ACLMASK_ANY);
2434 
2435  PG_RETURN_BOOL(aclresult == ACLCHECK_OK);
2436 }
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:273
uint32 AclMode
Definition: parsenodes.h:70
#define SearchSysCacheExists1(cacheId, key1)
Definition: syscache.h:182
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
AclResult
Definition: acl.h:178
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
AclResult pg_attribute_aclcheck_all(Oid table_oid, Oid roleid, AclMode mode, AclMaskHow how)
Definition: aclchk.c:4337
AclResult pg_class_aclcheck(Oid table_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4422
Definition: c.h:487
static AclMode convert_column_priv_string(text *priv_type_text)
Definition: acl.c:2851
#define PG_RETURN_NULL()
Definition: fmgr.h:305

◆ has_any_column_privilege_id_name()

Datum has_any_column_privilege_id_name ( PG_FUNCTION_ARGS  )

Definition at line 2389 of file acl.c.

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

2390 {
2391  Oid roleid = PG_GETARG_OID(0);
2392  text *tablename = PG_GETARG_TEXT_PP(1);
2393  text *priv_type_text = PG_GETARG_TEXT_PP(2);
2394  Oid tableoid;
2395  AclMode mode;
2396  AclResult aclresult;
2397 
2398  tableoid = convert_table_name(tablename);
2399  mode = convert_column_priv_string(priv_type_text);
2400 
2401  /* First check at table level, then examine each column if needed */
2402  aclresult = pg_class_aclcheck(tableoid, roleid, mode);
2403  if (aclresult != ACLCHECK_OK)
2404  aclresult = pg_attribute_aclcheck_all(tableoid, roleid, mode,
2405  ACLMASK_ANY);
2406 
2407  PG_RETURN_BOOL(aclresult == ACLCHECK_OK);
2408 }
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:273
uint32 AclMode
Definition: parsenodes.h:70
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
AclResult
Definition: acl.h:178
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
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:4337
AclResult pg_class_aclcheck(Oid table_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4422
Definition: c.h:487
static AclMode convert_column_priv_string(text *priv_type_text)
Definition: acl.c:2851

◆ has_any_column_privilege_name()

Datum has_any_column_privilege_name ( PG_FUNCTION_ARGS  )

Definition at line 2301 of file acl.c.

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

2302 {
2303  text *tablename = PG_GETARG_TEXT_PP(0);
2304  text *priv_type_text = PG_GETARG_TEXT_PP(1);
2305  Oid roleid;
2306  Oid tableoid;
2307  AclMode mode;
2308  AclResult aclresult;
2309 
2310  roleid = GetUserId();
2311  tableoid = convert_table_name(tablename);
2312  mode = convert_column_priv_string(priv_type_text);
2313 
2314  /* First check at table level, then examine each column if needed */
2315  aclresult = pg_class_aclcheck(tableoid, roleid, mode);
2316  if (aclresult != ACLCHECK_OK)
2317  aclresult = pg_attribute_aclcheck_all(tableoid, roleid, mode,
2318  ACLMASK_ANY);
2319 
2320  PG_RETURN_BOOL(aclresult == ACLCHECK_OK);
2321 }
Oid GetUserId(void)
Definition: miscinit.c:284
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:273
uint32 AclMode
Definition: parsenodes.h:70
AclResult
Definition: acl.h:178
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
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:4337
AclResult pg_class_aclcheck(Oid table_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4422
Definition: c.h:487
static AclMode convert_column_priv_string(text *priv_type_text)
Definition: acl.c:2851

◆ has_any_column_privilege_name_id()

Datum has_any_column_privilege_name_id ( PG_FUNCTION_ARGS  )

Definition at line 2329 of file acl.c.

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

2330 {
2332  Oid tableoid = PG_GETARG_OID(1);
2333  text *priv_type_text = PG_GETARG_TEXT_PP(2);
2334  Oid roleid;
2335  AclMode mode;
2336  AclResult aclresult;
2337 
2338  roleid = get_role_oid_or_public(NameStr(*username));
2339  mode = convert_column_priv_string(priv_type_text);
2340 
2342  PG_RETURN_NULL();
2343 
2344  /* First check at table level, then examine each column if needed */
2345  aclresult = pg_class_aclcheck(tableoid, roleid, mode);
2346  if (aclresult != ACLCHECK_OK)
2347  aclresult = pg_attribute_aclcheck_all(tableoid, roleid, mode,
2348  ACLMASK_ANY);
2349 
2350  PG_RETURN_BOOL(aclresult == ACLCHECK_OK);
2351 }
Oid get_role_oid_or_public(const char *rolname)
Definition: acl.c:5130
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:273
uint32 AclMode
Definition: parsenodes.h:70
#define SearchSysCacheExists1(cacheId, key1)
Definition: syscache.h:182
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
Definition: c.h:541
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
AclResult
Definition: acl.h:178
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
static char * username
Definition: initdb.c:132
AclResult pg_attribute_aclcheck_all(Oid table_oid, Oid roleid, AclMode mode, AclMaskHow how)
Definition: aclchk.c:4337
AclResult pg_class_aclcheck(Oid table_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4422
#define NameStr(name)
Definition: c.h:547
Definition: c.h:487
static AclMode convert_column_priv_string(text *priv_type_text)
Definition: acl.c:2851
#define PG_RETURN_NULL()
Definition: fmgr.h:305
#define PG_GETARG_NAME(n)
Definition: fmgr.h:243

◆ has_any_column_privilege_name_name()

Datum has_any_column_privilege_name_name ( PG_FUNCTION_ARGS  )

Definition at line 2271 of file acl.c.

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

2272 {
2273  Name rolename = PG_GETARG_NAME(0);
2274  text *tablename = PG_GETARG_TEXT_PP(1);
2275  text *priv_type_text = PG_GETARG_TEXT_PP(2);
2276  Oid roleid;
2277  Oid tableoid;
2278  AclMode mode;
2279  AclResult aclresult;
2280 
2281  roleid = get_role_oid_or_public(NameStr(*rolename));
2282  tableoid = convert_table_name(tablename);
2283  mode = convert_column_priv_string(priv_type_text);
2284 
2285  /* First check at table level, then examine each column if needed */
2286  aclresult = pg_class_aclcheck(tableoid, roleid, mode);
2287  if (aclresult != ACLCHECK_OK)
2288  aclresult = pg_attribute_aclcheck_all(tableoid, roleid, mode,
2289  ACLMASK_ANY);
2290 
2291  PG_RETURN_BOOL(aclresult == ACLCHECK_OK);
2292 }
Oid get_role_oid_or_public(const char *rolname)
Definition: acl.c:5130
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:273
uint32 AclMode
Definition: parsenodes.h:70
Definition: c.h:541
AclResult
Definition: acl.h:178
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
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:4337
AclResult pg_class_aclcheck(Oid table_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4422
#define NameStr(name)
Definition: c.h:547
Definition: c.h:487
static AclMode convert_column_priv_string(text *priv_type_text)
Definition: acl.c:2851
#define PG_GETARG_NAME(n)
Definition: fmgr.h:243

◆ has_column_privilege_id_attnum()

Datum has_column_privilege_id_attnum ( PG_FUNCTION_ARGS  )

Definition at line 2803 of file acl.c.

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

2804 {
2805  Oid tableoid = PG_GETARG_OID(0);
2806  AttrNumber colattnum = PG_GETARG_INT16(1);
2807  text *priv_type_text = PG_GETARG_TEXT_PP(2);
2808  Oid roleid;
2809  AclMode mode;
2810  int privresult;
2811 
2812  roleid = GetUserId();
2813  mode = convert_column_priv_string(priv_type_text);
2814 
2815  privresult = column_privilege_check(tableoid, colattnum, roleid, mode);
2816  if (privresult < 0)
2817  PG_RETURN_NULL();
2818  PG_RETURN_BOOL(privresult);
2819 }
Oid GetUserId(void)
Definition: miscinit.c:284
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:273
uint32 AclMode
Definition: parsenodes.h:70
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define PG_GETARG_INT16(n)
Definition: fmgr.h:236
static int column_privilege_check(Oid tableoid, AttrNumber attnum, Oid roleid, AclMode mode)
Definition: acl.c:2459
Definition: c.h:487
static AclMode convert_column_priv_string(text *priv_type_text)
Definition: acl.c:2851
int16 AttrNumber
Definition: attnum.h:21
#define PG_RETURN_NULL()
Definition: fmgr.h:305

◆ has_column_privilege_id_id_attnum()

Datum has_column_privilege_id_id_attnum ( PG_FUNCTION_ARGS  )

Definition at line 2696 of file acl.c.

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

2697 {
2698  Oid roleid = PG_GETARG_OID(0);
2699  Oid tableoid = PG_GETARG_OID(1);
2700  AttrNumber colattnum = PG_GETARG_INT16(2);
2701  text *priv_type_text = PG_GETARG_TEXT_PP(3);
2702  AclMode mode;
2703  int privresult;
2704 
2705  mode = convert_column_priv_string(priv_type_text);
2706 
2707  privresult = column_privilege_check(tableoid, colattnum, roleid, mode);
2708  if (privresult < 0)
2709  PG_RETURN_NULL();
2710  PG_RETURN_BOOL(privresult);
2711 }
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:273
uint32 AclMode
Definition: parsenodes.h:70
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define PG_GETARG_INT16(n)
Definition: fmgr.h:236
static int column_privilege_check(Oid tableoid, AttrNumber attnum, Oid roleid, AclMode mode)
Definition: acl.c:2459
Definition: c.h:487
static AclMode convert_column_priv_string(text *priv_type_text)
Definition: acl.c:2851
int16 AttrNumber
Definition: attnum.h:21
#define PG_RETURN_NULL()
Definition: fmgr.h:305

◆ has_column_privilege_id_id_name()

Datum has_column_privilege_id_id_name ( PG_FUNCTION_ARGS  )

Definition at line 2671 of file acl.c.

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

2672 {
2673  Oid roleid = PG_GETARG_OID(0);
2674  Oid tableoid = PG_GETARG_OID(1);
2675  text *column = PG_GETARG_TEXT_PP(2);
2676  text *priv_type_text = PG_GETARG_TEXT_PP(3);
2677  AttrNumber colattnum;
2678  AclMode mode;
2679  int privresult;
2680 
2681  colattnum = convert_column_name(tableoid, column);
2682  mode = convert_column_priv_string(priv_type_text);
2683 
2684  privresult = column_privilege_check(tableoid, colattnum, roleid, mode);
2685  if (privresult < 0)
2686  PG_RETURN_NULL();
2687  PG_RETURN_BOOL(privresult);
2688 }
static AttrNumber convert_column_name(Oid tableoid, text *column)
Definition: acl.c:2830
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:273
uint32 AclMode
Definition: parsenodes.h:70
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
static int column_privilege_check(Oid tableoid, AttrNumber attnum, Oid roleid, AclMode mode)
Definition: acl.c:2459
Definition: c.h:487
static AclMode convert_column_priv_string(text *priv_type_text)
Definition: acl.c:2851
int16 AttrNumber
Definition: attnum.h:21
#define PG_RETURN_NULL()
Definition: fmgr.h:305

◆ has_column_privilege_id_name()

Datum has_column_privilege_id_name ( PG_FUNCTION_ARGS  )

Definition at line 2776 of file acl.c.

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

2777 {
2778  Oid tableoid = PG_GETARG_OID(0);
2779  text *column = PG_GETARG_TEXT_PP(1);
2780  text *priv_type_text = PG_GETARG_TEXT_PP(2);
2781  Oid roleid;
2782  AttrNumber colattnum;
2783  AclMode mode;
2784  int privresult;
2785 
2786  roleid = GetUserId();
2787  colattnum = convert_column_name(tableoid, column);
2788  mode = convert_column_priv_string(priv_type_text);
2789 
2790  privresult = column_privilege_check(tableoid, colattnum, roleid, mode);
2791  if (privresult < 0)
2792  PG_RETURN_NULL();
2793  PG_RETURN_BOOL(privresult);
2794 }
static AttrNumber convert_column_name(Oid tableoid, text *column)
Definition: acl.c:2830
Oid GetUserId(void)
Definition: miscinit.c:284
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:273
uint32 AclMode
Definition: parsenodes.h:70
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
static int column_privilege_check(Oid tableoid, AttrNumber attnum, Oid roleid, AclMode mode)
Definition: acl.c:2459
Definition: c.h:487
static AclMode convert_column_priv_string(text *priv_type_text)
Definition: acl.c:2851
int16 AttrNumber
Definition: attnum.h:21
#define PG_RETURN_NULL()
Definition: fmgr.h:305

◆ has_column_privilege_id_name_attnum()

Datum has_column_privilege_id_name_attnum ( PG_FUNCTION_ARGS  )

Definition at line 2646 of file acl.c.

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

2647 {
2648  Oid roleid = PG_GETARG_OID(0);
2649  text *tablename = PG_GETARG_TEXT_PP(1);
2650  AttrNumber colattnum = PG_GETARG_INT16(2);
2651  text *priv_type_text = PG_GETARG_TEXT_PP(3);
2652  Oid tableoid;
2653  AclMode mode;
2654  int privresult;
2655 
2656  tableoid = convert_table_name(tablename);
2657  mode = convert_column_priv_string(priv_type_text);
2658 
2659  privresult = column_privilege_check(tableoid, colattnum, roleid, mode);
2660  if (privresult < 0)
2661  PG_RETURN_NULL();
2662  PG_RETURN_BOOL(privresult);
2663 }
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:273
uint32 AclMode
Definition: parsenodes.h:70
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define PG_GETARG_INT16(n)
Definition: fmgr.h:236
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:2459
Definition: c.h:487
static AclMode convert_column_priv_string(text *priv_type_text)
Definition: acl.c:2851
int16 AttrNumber
Definition: attnum.h:21
#define PG_RETURN_NULL()
Definition: fmgr.h:305

◆ has_column_privilege_id_name_name()

Datum has_column_privilege_id_name_name ( PG_FUNCTION_ARGS  )

Definition at line 2619 of file acl.c.

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

2620 {
2621  Oid roleid = PG_GETARG_OID(0);
2622  text *tablename = PG_GETARG_TEXT_PP(1);
2623  text *column = PG_GETARG_TEXT_PP(2);
2624  text *priv_type_text = PG_GETARG_TEXT_PP(3);
2625  Oid tableoid;
2626  AttrNumber colattnum;
2627  AclMode mode;
2628  int privresult;
2629 
2630  tableoid = convert_table_name(tablename);
2631  colattnum = convert_column_name(tableoid, column);
2632  mode = convert_column_priv_string(priv_type_text);
2633 
2634  privresult = column_privilege_check(tableoid, colattnum, roleid, mode);
2635  if (privresult < 0)
2636  PG_RETURN_NULL();
2637  PG_RETURN_BOOL(privresult);
2638 }
static AttrNumber convert_column_name(Oid tableoid, text *column)
Definition: acl.c:2830
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:273
uint32 AclMode
Definition: parsenodes.h:70
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
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:2459
Definition: c.h:487
static AclMode convert_column_priv_string(text *priv_type_text)
Definition: acl.c:2851
int16 AttrNumber
Definition: attnum.h:21
#define PG_RETURN_NULL()
Definition: fmgr.h:305

◆ has_column_privilege_name_attnum()

Datum has_column_privilege_name_attnum ( PG_FUNCTION_ARGS  )

Definition at line 2749 of file acl.c.

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

2750 {
2751  text *tablename = PG_GETARG_TEXT_PP(0);
2752  AttrNumber colattnum = PG_GETARG_INT16(1);
2753  text *priv_type_text = PG_GETARG_TEXT_PP(2);
2754  Oid roleid;
2755  Oid tableoid;
2756  AclMode mode;
2757  int privresult;
2758 
2759  roleid = GetUserId();
2760  tableoid = convert_table_name(tablename);
2761  mode = convert_column_priv_string(priv_type_text);
2762 
2763  privresult = column_privilege_check(tableoid, colattnum, roleid, mode);
2764  if (privresult < 0)
2765  PG_RETURN_NULL();
2766  PG_RETURN_BOOL(privresult);
2767 }
Oid GetUserId(void)
Definition: miscinit.c:284
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:273
uint32 AclMode
Definition: parsenodes.h:70
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define PG_GETARG_INT16(n)
Definition: fmgr.h:236
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:2459
Definition: c.h:487
static AclMode convert_column_priv_string(text *priv_type_text)
Definition: acl.c:2851
int16 AttrNumber
Definition: attnum.h:21
#define PG_RETURN_NULL()
Definition: fmgr.h:305

◆ has_column_privilege_name_id_attnum()

Datum has_column_privilege_name_id_attnum ( PG_FUNCTION_ARGS  )

Definition at line 2594 of file acl.c.

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

2595 {
2597  Oid tableoid = PG_GETARG_OID(1);
2598  AttrNumber colattnum = PG_GETARG_INT16(2);
2599  text *priv_type_text = PG_GETARG_TEXT_PP(3);
2600  Oid roleid;
2601  AclMode mode;
2602  int privresult;
2603 
2604  roleid = get_role_oid_or_public(NameStr(*username));
2605  mode = convert_column_priv_string(priv_type_text);
2606 
2607  privresult = column_privilege_check(tableoid, colattnum, roleid, mode);
2608  if (privresult < 0)
2609  PG_RETURN_NULL();
2610  PG_RETURN_BOOL(privresult);
2611 }
Oid get_role_oid_or_public(const char *rolname)
Definition: acl.c:5130
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:273
uint32 AclMode
Definition: parsenodes.h:70
Definition: c.h:541
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define PG_GETARG_INT16(n)
Definition: fmgr.h:236
static char * username
Definition: initdb.c:132
static int column_privilege_check(Oid tableoid, AttrNumber attnum, Oid roleid, AclMode mode)
Definition: acl.c:2459
#define NameStr(name)
Definition: c.h:547
Definition: c.h:487
static AclMode convert_column_priv_string(text *priv_type_text)
Definition: acl.c:2851
int16 AttrNumber
Definition: attnum.h:21
#define PG_RETURN_NULL()
Definition: fmgr.h:305
#define PG_GETARG_NAME(n)
Definition: fmgr.h:243

◆ has_column_privilege_name_id_name()

Datum has_column_privilege_name_id_name ( PG_FUNCTION_ARGS  )

Definition at line 2567 of file acl.c.

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

2568 {
2570  Oid tableoid = PG_GETARG_OID(1);
2571  text *column = PG_GETARG_TEXT_PP(2);
2572  text *priv_type_text = PG_GETARG_TEXT_PP(3);
2573  Oid roleid;
2574  AttrNumber colattnum;
2575  AclMode mode;
2576  int privresult;
2577 
2578  roleid = get_role_oid_or_public(NameStr(*username));
2579  colattnum = convert_column_name(tableoid, column);
2580  mode = convert_column_priv_string(priv_type_text);
2581 
2582  privresult = column_privilege_check(tableoid, colattnum, roleid, mode);
2583  if (privresult < 0)
2584  PG_RETURN_NULL();
2585  PG_RETURN_BOOL(privresult);
2586 }
static AttrNumber convert_column_name(Oid tableoid, text *column)
Definition: acl.c:2830
Oid get_role_oid_or_public(const char *rolname)
Definition: acl.c:5130
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:273
uint32 AclMode
Definition: parsenodes.h:70
Definition: c.h:541
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
static char * username
Definition: initdb.c:132
static int column_privilege_check(Oid tableoid, AttrNumber attnum, Oid roleid, AclMode mode)
Definition: acl.c:2459
#define NameStr(name)
Definition: c.h:547
Definition: c.h:487
static AclMode convert_column_priv_string(text *priv_type_text)
Definition: acl.c:2851
int16 AttrNumber
Definition: attnum.h:21
#define PG_RETURN_NULL()
Definition: fmgr.h:305
#define PG_GETARG_NAME(n)
Definition: fmgr.h:243

◆ has_column_privilege_name_name()

Datum has_column_privilege_name_name ( PG_FUNCTION_ARGS  )

Definition at line 2720 of file acl.c.

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

2721 {
2722  text *tablename = PG_GETARG_TEXT_PP(0);
2723  text *column = PG_GETARG_TEXT_PP(1);
2724  text *priv_type_text = PG_GETARG_TEXT_PP(2);
2725  Oid roleid;
2726  Oid tableoid;
2727  AttrNumber colattnum;
2728  AclMode mode;
2729  int privresult;
2730 
2731  roleid = GetUserId();
2732  tableoid = convert_table_name(tablename);
2733  colattnum = convert_column_name(tableoid, column);
2734  mode = convert_column_priv_string(priv_type_text);
2735 
2736  privresult = column_privilege_check(tableoid, colattnum, roleid, mode);
2737  if (privresult < 0)
2738  PG_RETURN_NULL();
2739  PG_RETURN_BOOL(privresult);
2740 }
static AttrNumber convert_column_name(Oid tableoid, text *column)
Definition: acl.c:2830
Oid GetUserId(void)
Definition: miscinit.c:284
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:273
uint32 AclMode
Definition: parsenodes.h:70
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
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:2459
Definition: c.h:487
static AclMode convert_column_priv_string(text *priv_type_text)
Definition: acl.c:2851
int16 AttrNumber
Definition: attnum.h:21
#define PG_RETURN_NULL()
Definition: fmgr.h:305

◆ has_column_privilege_name_name_attnum()

Datum has_column_privilege_name_name_attnum ( PG_FUNCTION_ARGS  )

Definition at line 2540 of file acl.c.

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

2541 {
2542  Name rolename = PG_GETARG_NAME(0);
2543  text *tablename = PG_GETARG_TEXT_PP(1);
2544  AttrNumber colattnum = PG_GETARG_INT16(2);
2545  text *priv_type_text = PG_GETARG_TEXT_PP(3);
2546  Oid roleid;
2547  Oid tableoid;
2548  AclMode mode;
2549  int privresult;
2550 
2551  roleid = get_role_oid_or_public(NameStr(*rolename));
2552  tableoid = convert_table_name(tablename);
2553  mode = convert_column_priv_string(priv_type_text);
2554 
2555  privresult = column_privilege_check(tableoid, colattnum, roleid, mode);
2556  if (privresult < 0)
2557  PG_RETURN_NULL();
2558  PG_RETURN_BOOL(privresult);
2559 }
Oid get_role_oid_or_public(const char *rolname)
Definition: acl.c:5130
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:273
uint32 AclMode
Definition: parsenodes.h:70
Definition: c.h:541
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define PG_GETARG_INT16(n)
Definition: fmgr.h:236
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:2459
#define NameStr(name)
Definition: c.h:547
Definition: c.h:487
static AclMode convert_column_priv_string(text *priv_type_text)
Definition: acl.c:2851
int16 AttrNumber
Definition: attnum.h:21
#define PG_RETURN_NULL()
Definition: fmgr.h:305
#define PG_GETARG_NAME(n)
Definition: fmgr.h:243

◆ has_column_privilege_name_name_name()

Datum has_column_privilege_name_name_name ( PG_FUNCTION_ARGS  )

Definition at line 2511 of file acl.c.

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

2512 {
2513  Name rolename = PG_GETARG_NAME(0);
2514  text *tablename = PG_GETARG_TEXT_PP(1);
2515  text *column = PG_GETARG_TEXT_PP(2);
2516  text *priv_type_text = PG_GETARG_TEXT_PP(3);
2517  Oid roleid;
2518  Oid tableoid;
2519  AttrNumber colattnum;
2520  AclMode mode;
2521  int privresult;
2522 
2523  roleid = get_role_oid_or_public(NameStr(*rolename));
2524  tableoid = convert_table_name(tablename);
2525  colattnum = convert_column_name(tableoid, column);
2526  mode = convert_column_priv_string(priv_type_text);
2527 
2528  privresult = column_privilege_check(tableoid, colattnum, roleid, mode);
2529  if (privresult < 0)
2530  PG_RETURN_NULL();
2531  PG_RETURN_BOOL(privresult);
2532 }
static AttrNumber convert_column_name(Oid tableoid, text *column)
Definition: acl.c:2830
Oid get_role_oid_or_public(const char *rolname)
Definition: acl.c:5130
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:273
uint32 AclMode
Definition: parsenodes.h:70
Definition: c.h:541
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
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:2459
#define NameStr(name)
Definition: c.h:547
Definition: c.h:487
static AclMode convert_column_priv_string(text *priv_type_text)
Definition: acl.c:2851
int16 AttrNumber
Definition: attnum.h:21
#define PG_RETURN_NULL()
Definition: fmgr.h:305
#define PG_GETARG_NAME(n)
Definition: fmgr.h:243

◆ has_database_privilege_id()

Datum has_database_privilege_id ( PG_FUNCTION_ARGS  )

Definition at line 2962 of file acl.c.

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

2963 {
2964  Oid databaseoid = PG_GETARG_OID(0);
2965  text *priv_type_text = PG_GETARG_TEXT_PP(1);
2966  Oid roleid;
2967  AclMode mode;
2968  AclResult aclresult;
2969 
2970  roleid = GetUserId();
2971  mode = convert_database_priv_string(priv_type_text);
2972 
2974  PG_RETURN_NULL();
2975 
2976  aclresult = pg_database_aclcheck(databaseoid, roleid, mode);
2977 
2978  PG_RETURN_BOOL(aclresult == ACLCHECK_OK);
2979 }
Oid GetUserId(void)
Definition: miscinit.c:284
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:273
uint32 AclMode
Definition: parsenodes.h:70
#define SearchSysCacheExists1(cacheId, key1)
Definition: syscache.h:182
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
static AclMode convert_database_priv_string(text *priv_type_text)
Definition: acl.c:3048
AclResult
Definition: acl.h:178
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
AclResult pg_database_aclcheck(Oid db_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4434
Definition: c.h:487
#define PG_RETURN_NULL()
Definition: fmgr.h:305

◆ has_database_privilege_id_id()

Datum has_database_privilege_id_id ( PG_FUNCTION_ARGS  )

Definition at line 3010 of file acl.c.

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

3011 {
3012  Oid roleid = PG_GETARG_OID(0);
3013  Oid databaseoid = PG_GETARG_OID(1);
3014  text *priv_type_text = PG_GETARG_TEXT_PP(2);
3015  AclMode mode;
3016  AclResult aclresult;
3017 
3018  mode = convert_database_priv_string(priv_type_text);
3019 
3021  PG_RETURN_NULL();
3022 
3023  aclresult = pg_database_aclcheck(databaseoid, roleid, mode);
3024 
3025  PG_RETURN_BOOL(aclresult == ACLCHECK_OK);
3026 }
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:273
uint32 AclMode
Definition: parsenodes.h:70
#define SearchSysCacheExists1(cacheId, key1)
Definition: syscache.h:182
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
static AclMode convert_database_priv_string(text *priv_type_text)
Definition: acl.c:3048
AclResult
Definition: acl.h:178
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
AclResult pg_database_aclcheck(Oid db_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4434
Definition: c.h:487
#define PG_RETURN_NULL()
Definition: fmgr.h:305

◆ has_database_privilege_id_name()

Datum has_database_privilege_id_name ( PG_FUNCTION_ARGS  )

Definition at line 2987 of file acl.c.

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

2988 {
2989  Oid roleid = PG_GETARG_OID(0);
2990  text *databasename = PG_GETARG_TEXT_PP(1);
2991  text *priv_type_text = PG_GETARG_TEXT_PP(2);
2992  Oid databaseoid;
2993  AclMode mode;
2994  AclResult aclresult;
2995 
2996  databaseoid = convert_database_name(databasename);
2997  mode = convert_database_priv_string(priv_type_text);
2998 
2999  aclresult = pg_database_aclcheck(databaseoid, roleid, mode);
3000 
3001  PG_RETURN_BOOL(aclresult == ACLCHECK_OK);
3002 }
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:273
uint32 AclMode
Definition: parsenodes.h:70
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
static Oid convert_database_name(text *databasename)
Definition: acl.c:3036
static AclMode convert_database_priv_string(text *priv_type_text)
Definition: acl.c:3048
AclResult
Definition: acl.h:178
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
AclResult pg_database_aclcheck(Oid db_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4434
Definition: c.h:487

◆ has_database_privilege_name()

Datum has_database_privilege_name ( PG_FUNCTION_ARGS  )

Definition at line 2911 of file acl.c.

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

2912 {
2913  text *databasename = PG_GETARG_TEXT_PP(0);
2914  text *priv_type_text = PG_GETARG_TEXT_PP(1);
2915  Oid roleid;
2916  Oid databaseoid;
2917  AclMode mode;
2918  AclResult aclresult;
2919 
2920  roleid = GetUserId();
2921  databaseoid = convert_database_name(databasename);
2922  mode = convert_database_priv_string(priv_type_text);
2923 
2924  aclresult = pg_database_aclcheck(databaseoid, roleid, mode);
2925 
2926  PG_RETURN_BOOL(aclresult == ACLCHECK_OK);
2927 }
Oid GetUserId(void)
Definition: miscinit.c:284
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:273
uint32 AclMode
Definition: parsenodes.h:70
static Oid convert_database_name(text *databasename)
Definition: acl.c:3036
static AclMode convert_database_priv_string(text *priv_type_text)
Definition: acl.c:3048
AclResult
Definition: acl.h:178
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
AclResult pg_database_aclcheck(Oid db_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4434
Definition: c.h:487

◆ has_database_privilege_name_id()

Datum has_database_privilege_name_id ( PG_FUNCTION_ARGS  )

Definition at line 2935 of file acl.c.

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

2936 {
2938  Oid databaseoid = PG_GETARG_OID(1);
2939  text *priv_type_text = PG_GETARG_TEXT_PP(2);
2940  Oid roleid;
2941  AclMode mode;
2942  AclResult aclresult;
2943 
2944  roleid = get_role_oid_or_public(NameStr(*username));
2945  mode = convert_database_priv_string(priv_type_text);
2946 
2948  PG_RETURN_NULL();
2949 
2950  aclresult = pg_database_aclcheck(databaseoid, roleid, mode);
2951 
2952  PG_RETURN_BOOL(aclresult == ACLCHECK_OK);
2953 }
Oid get_role_oid_or_public(const char *rolname)
Definition: acl.c:5130
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:273
uint32 AclMode
Definition: parsenodes.h:70
#define SearchSysCacheExists1(cacheId, key1)
Definition: syscache.h:182
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
Definition: c.h:541
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
static AclMode convert_database_priv_string(text *priv_type_text)
Definition: acl.c:3048
AclResult
Definition: acl.h:178
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
static char * username
Definition: initdb.c:132
AclResult pg_database_aclcheck(Oid db_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4434
#define NameStr(name)
Definition: c.h:547
Definition: c.h:487
#define PG_RETURN_NULL()
Definition: fmgr.h:305
#define PG_GETARG_NAME(n)
Definition: fmgr.h:243

◆ has_database_privilege_name_name()

Datum has_database_privilege_name_name ( PG_FUNCTION_ARGS  )

Definition at line 2885 of file acl.c.

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

2886 {
2888  text *databasename = PG_GETARG_TEXT_PP(1);
2889  text *priv_type_text = PG_GETARG_TEXT_PP(2);
2890  Oid roleid;
2891  Oid databaseoid;
2892  AclMode mode;
2893  AclResult aclresult;
2894 
2895  roleid = get_role_oid_or_public(NameStr(*username));
2896  databaseoid = convert_database_name(databasename);
2897  mode = convert_database_priv_string(priv_type_text);
2898 
2899  aclresult = pg_database_aclcheck(databaseoid, roleid, mode);
2900 
2901  PG_RETURN_BOOL(aclresult == ACLCHECK_OK);
2902 }
Oid get_role_oid_or_public(const char *rolname)
Definition: acl.c:5130
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:273
uint32 AclMode
Definition: parsenodes.h:70
Definition: c.h:541
static Oid convert_database_name(text *databasename)
Definition: acl.c:3036
static AclMode convert_database_priv_string(text *priv_type_text)
Definition: acl.c:3048
AclResult
Definition: acl.h:178
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
static char * username
Definition: initdb.c:132
AclResult pg_database_aclcheck(Oid db_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4434
#define NameStr(name)
Definition: c.h:547
Definition: c.h:487
#define PG_GETARG_NAME(n)
Definition: fmgr.h:243

◆ has_foreign_data_wrapper_privilege_id()

Datum has_foreign_data_wrapper_privilege_id ( PG_FUNCTION_ARGS  )

Definition at line 3157 of file acl.c.

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

3158 {
3159  Oid fdwid = PG_GETARG_OID(0);
3160  text *priv_type_text = PG_GETARG_TEXT_PP(1);
3161  Oid roleid;
3162  AclMode mode;
3163  AclResult aclresult;
3164 
3165  roleid = GetUserId();
3166  mode = convert_foreign_data_wrapper_priv_string(priv_type_text);
3167 
3168  aclresult = pg_foreign_data_wrapper_aclcheck(fdwid, roleid, mode);
3169 
3170  PG_RETURN_BOOL(aclresult == ACLCHECK_OK);
3171 }
Oid GetUserId(void)
Definition: miscinit.c:284
AclResult pg_foreign_data_wrapper_aclcheck(Oid fdw_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4509
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:273
uint32 AclMode
Definition: parsenodes.h:70
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
AclResult
Definition: acl.h:178
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
static AclMode convert_foreign_data_wrapper_priv_string(text *priv_type_text)
Definition: acl.c:3237
Definition: c.h:487

◆ has_foreign_data_wrapper_privilege_id_id()

Datum has_foreign_data_wrapper_privilege_id_id ( PG_FUNCTION_ARGS  )

Definition at line 3202 of file acl.c.

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

3203 {
3204  Oid roleid = PG_GETARG_OID(0);
3205  Oid fdwid = PG_GETARG_OID(1);
3206  text *priv_type_text = PG_GETARG_TEXT_PP(2);
3207  AclMode mode;
3208  AclResult aclresult;
3209 
3210  mode = convert_foreign_data_wrapper_priv_string(priv_type_text);
3211 
3212  aclresult = pg_foreign_data_wrapper_aclcheck(fdwid, roleid, mode);
3213 
3214  PG_RETURN_BOOL(aclresult == ACLCHECK_OK);
3215 }
AclResult pg_foreign_data_wrapper_aclcheck(Oid fdw_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4509
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:273
uint32 AclMode
Definition: parsenodes.h:70
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
AclResult
Definition: acl.h:178
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
static AclMode convert_foreign_data_wrapper_priv_string(text *priv_type_text)
Definition: acl.c:3237
Definition: c.h:487

◆ has_foreign_data_wrapper_privilege_id_name()

Datum has_foreign_data_wrapper_privilege_id_name ( PG_FUNCTION_ARGS  )

Definition at line 3179 of file acl.c.

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

3180 {
3181  Oid roleid = PG_GETARG_OID(0);
3182  text *fdwname = PG_GETARG_TEXT_PP(1);
3183  text *priv_type_text = PG_GETARG_TEXT_PP(2);
3184  Oid fdwid;
3185  AclMode mode;
3186  AclResult aclresult;
3187 
3188  fdwid = convert_foreign_data_wrapper_name(fdwname);
3189  mode = convert_foreign_data_wrapper_priv_string(priv_type_text);
3190 
3191  aclresult = pg_foreign_data_wrapper_aclcheck(fdwid, roleid, mode);
3192 
3193  PG_RETURN_BOOL(aclresult == ACLCHECK_OK);
3194 }
AclResult pg_foreign_data_wrapper_aclcheck(Oid fdw_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4509
static Oid convert_foreign_data_wrapper_name(text *fdwname)
Definition: acl.c:3225
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:273
uint32 AclMode
Definition: parsenodes.h:70
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
AclResult
Definition: acl.h:178
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
static AclMode convert_foreign_data_wrapper_priv_string(text *priv_type_text)
Definition: acl.c:3237
Definition: c.h:487

◆ has_foreign_data_wrapper_privilege_name()

Datum has_foreign_data_wrapper_privilege_name ( PG_FUNCTION_ARGS  )

Definition at line 3109 of file acl.c.

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

3110 {
3111  text *fdwname = PG_GETARG_TEXT_PP(0);
3112  text *priv_type_text = PG_GETARG_TEXT_PP(1);
3113  Oid roleid;
3114  Oid fdwid;
3115  AclMode mode;
3116  AclResult aclresult;
3117 
3118  roleid = GetUserId();
3119  fdwid = convert_foreign_data_wrapper_name(fdwname);
3120  mode = convert_foreign_data_wrapper_priv_string(priv_type_text);
3121 
3122  aclresult = pg_foreign_data_wrapper_aclcheck(fdwid, roleid, mode);
3123 
3124  PG_RETURN_BOOL(aclresult == ACLCHECK_OK);
3125 }
Oid GetUserId(void)
Definition: miscinit.c:284
AclResult pg_foreign_data_wrapper_aclcheck(Oid fdw_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4509
static Oid convert_foreign_data_wrapper_name(text *fdwname)
Definition: acl.c:3225
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:273
uint32 AclMode
Definition: parsenodes.h:70
AclResult
Definition: acl.h:178
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
static AclMode convert_foreign_data_wrapper_priv_string(text *priv_type_text)
Definition: acl.c:3237
Definition: c.h:487

◆ has_foreign_data_wrapper_privilege_name_id()

Datum has_foreign_data_wrapper_privilege_name_id ( PG_FUNCTION_ARGS  )

Definition at line 3133 of file acl.c.

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

3134 {
3136  Oid fdwid = PG_GETARG_OID(1);
3137  text *priv_type_text = PG_GETARG_TEXT_PP(2);
3138  Oid roleid;
3139  AclMode mode;
3140  AclResult aclresult;
3141 
3142  roleid = get_role_oid_or_public(NameStr(*username));
3143  mode = convert_foreign_data_wrapper_priv_string(priv_type_text);
3144 
3145  aclresult = pg_foreign_data_wrapper_aclcheck(fdwid, roleid, mode);
3146 
3147  PG_RETURN_BOOL(aclresult == ACLCHECK_OK);
3148 }
AclResult pg_foreign_data_wrapper_aclcheck(Oid fdw_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4509
Oid get_role_oid_or_public(const char *rolname)
Definition: acl.c:5130
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:273
uint32 AclMode
Definition: parsenodes.h:70
Definition: c.h:541
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
AclResult
Definition: acl.h:178
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
static char * username
Definition: initdb.c:132
static AclMode convert_foreign_data_wrapper_priv_string(text *priv_type_text)
Definition: acl.c:3237
#define NameStr(name)
Definition: c.h:547
Definition: c.h:487
#define PG_GETARG_NAME(n)
Definition: fmgr.h:243

◆ has_foreign_data_wrapper_privilege_name_name()

Datum has_foreign_data_wrapper_privilege_name_name ( PG_FUNCTION_ARGS  )

Definition at line 3083 of file acl.c.

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

3084 {
3086  text *fdwname = PG_GETARG_TEXT_PP(1);
3087  text *priv_type_text = PG_GETARG_TEXT_PP(2);
3088  Oid roleid;
3089  Oid fdwid;
3090  AclMode mode;
3091  AclResult aclresult;
3092 
3093  roleid = get_role_oid_or_public(NameStr(*username));
3094  fdwid = convert_foreign_data_wrapper_name(fdwname);
3095  mode = convert_foreign_data_wrapper_priv_string(priv_type_text);
3096 
3097  aclresult = pg_foreign_data_wrapper_aclcheck(fdwid, roleid, mode);
3098 
3099  PG_RETURN_BOOL(aclresult == ACLCHECK_OK);
3100 }
AclResult pg_foreign_data_wrapper_aclcheck(Oid fdw_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4509
static Oid convert_foreign_data_wrapper_name(text *fdwname)
Definition: acl.c:3225
Oid get_role_oid_or_public(const char *rolname)
Definition: acl.c:5130
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:273
uint32 AclMode
Definition: parsenodes.h:70
Definition: c.h:541
AclResult
Definition: acl.h:178
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
static char * username
Definition: initdb.c:132
static AclMode convert_foreign_data_wrapper_priv_string(text *priv_type_text)
Definition: acl.c:3237
#define NameStr(name)
Definition: c.h:547
Definition: c.h:487
#define PG_GETARG_NAME(n)
Definition: fmgr.h:243

◆ has_function_privilege_id()

Datum has_function_privilege_id ( PG_FUNCTION_ARGS  )

Definition at line 3342 of file acl.c.

References ACLCHECK_OK, convert_function_priv_string(), GetUserId(), ObjectIdGetDatum, PG_GETARG_OID, PG_GETARG_TEXT_PP, pg_proc_aclcheck(), PG_RETURN_BOOL, PG_RETURN_NULL, PROCOID, and SearchSysCacheExists1.

3343 {
3344  Oid functionoid = PG_GETARG_OID(0);
3345  text *priv_type_text = PG_GETARG_TEXT_PP(1);
3346  Oid roleid;
3347  AclMode mode;
3348  AclResult aclresult;
3349 
3350  roleid = GetUserId();
3351  mode = convert_function_priv_string(priv_type_text);
3352 
3353  if (!SearchSysCacheExists1(PROCOID, ObjectIdGetDatum(functionoid)))
3354  PG_RETURN_NULL();
3355 
3356  aclresult = pg_proc_aclcheck(functionoid, roleid, mode);
3357 
3358  PG_RETURN_BOOL(aclresult == ACLCHECK_OK);
3359 }
Oid GetUserId(void)
Definition: miscinit.c:284
static AclMode convert_function_priv_string(text *priv_type_text)
Definition: acl.c:3437
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:273
uint32 AclMode
Definition: parsenodes.h:70
#define SearchSysCacheExists1(cacheId, key1)
Definition: syscache.h:182
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
AclResult
Definition: acl.h:178
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
AclResult pg_proc_aclcheck(Oid proc_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4446
Definition: c.h:487
#define PG_RETURN_NULL()
Definition: fmgr.h:305

◆ has_function_privilege_id_id()

Datum has_function_privilege_id_id ( PG_FUNCTION_ARGS  )

Definition at line 3390 of file acl.c.

References ACLCHECK_OK, convert_function_priv_string(), ObjectIdGetDatum, PG_GETARG_OID, PG_GETARG_TEXT_PP, pg_proc_aclcheck(), PG_RETURN_BOOL, PG_RETURN_NULL, PROCOID, and SearchSysCacheExists1.

3391 {
3392  Oid roleid = PG_GETARG_OID(0);
3393  Oid functionoid = PG_GETARG_OID(1);
3394  text *priv_type_text = PG_GETARG_TEXT_PP(2);
3395  AclMode mode;
3396  AclResult aclresult;
3397 
3398  mode = convert_function_priv_string(priv_type_text);
3399 
3400  if (!SearchSysCacheExists1(PROCOID, ObjectIdGetDatum(functionoid)))
3401  PG_RETURN_NULL();
3402 
3403  aclresult = pg_proc_aclcheck(functionoid, roleid, mode);
3404 
3405  PG_RETURN_BOOL(aclresult == ACLCHECK_OK);
3406 }
static AclMode convert_function_priv_string(text *priv_type_text)
Definition: acl.c:3437
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:273
uint32 AclMode
Definition: parsenodes.h:70
#define SearchSysCacheExists1(cacheId, key1)
Definition: syscache.h:182
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
AclResult
Definition: acl.h:178
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
AclResult pg_proc_aclcheck(Oid proc_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4446
Definition: c.h:487
#define PG_RETURN_NULL()
Definition: fmgr.h:305

◆ has_function_privilege_id_name()

Datum has_function_privilege_id_name ( PG_FUNCTION_ARGS  )

Definition at line 3367 of file acl.c.

References ACLCHECK_OK, convert_function_name(), convert_function_priv_string(), PG_GETARG_OID, PG_GETARG_TEXT_PP, pg_proc_aclcheck(), and PG_RETURN_BOOL.

3368 {
3369  Oid roleid = PG_GETARG_OID(0);
3370  text *functionname = PG_GETARG_TEXT_PP(1);
3371  text *priv_type_text = PG_GETARG_TEXT_PP(2);
3372  Oid functionoid;
3373  AclMode mode;
3374  AclResult aclresult;
3375 
3376  functionoid = convert_function_name(functionname);
3377  mode = convert_function_priv_string(priv_type_text);
3378 
3379  aclresult = pg_proc_aclcheck(functionoid, roleid, mode);
3380 
3381  PG_RETURN_BOOL(aclresult == ACLCHECK_OK);
3382 }
static AclMode convert_function_priv_string(text *priv_type_text)
Definition: acl.c:3437
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:273
uint32 AclMode
Definition: parsenodes.h:70
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
AclResult
Definition: acl.h:178
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
static Oid convert_function_name(text *functionname)
Definition: acl.c:3416
AclResult pg_proc_aclcheck(Oid proc_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4446
Definition: c.h:487

◆ has_function_privilege_name()

Datum has_function_privilege_name ( PG_FUNCTION_ARGS  )

Definition at line 3291 of file acl.c.

References ACLCHECK_OK, convert_function_name(), convert_function_priv_string(), GetUserId(), PG_GETARG_TEXT_PP, pg_proc_aclcheck(), and PG_RETURN_BOOL.

3292 {
3293  text *functionname = PG_GETARG_TEXT_PP(0);
3294  text *priv_type_text = PG_GETARG_TEXT_PP(1);
3295  Oid roleid;
3296  Oid functionoid;
3297  AclMode mode;
3298  AclResult aclresult;
3299 
3300  roleid = GetUserId();
3301  functionoid = convert_function_name(functionname);
3302  mode = convert_function_priv_string(priv_type_text);
3303 
3304  aclresult = pg_proc_aclcheck(functionoid, roleid, mode);
3305 
3306  PG_RETURN_BOOL(aclresult == ACLCHECK_OK);
3307 }
Oid GetUserId(void)
Definition: miscinit.c:284
static AclMode convert_function_priv_string(text *priv_type_text)
Definition: acl.c:3437
unsigned int Oid
Definition: