PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
acl.c File Reference
#include "postgres.h"
#include <ctype.h>
#include "access/htup_details.h"
#include "catalog/catalog.h"
#include "catalog/namespace.h"
#include "catalog/pg_authid.h"
#include "catalog/pg_auth_members.h"
#include "catalog/pg_type.h"
#include "catalog/pg_class.h"
#include "commands/dbcommands.h"
#include "commands/proclang.h"
#include "commands/tablespace.h"
#include "foreign/foreign.h"
#include "funcapi.h"
#include "miscadmin.h"
#include "utils/acl.h"
#include "utils/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)
 
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

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

Definition at line 426 of file acl.c.

References ACL_DAT, ACL_NUM, and allocacl().

Referenced by ExecGrant_Attribute().

427 {
428  Acl *result_acl;
429 
430  result_acl = allocacl(ACL_NUM(left_acl) + ACL_NUM(right_acl));
431 
432  memcpy(ACL_DAT(result_acl),
433  ACL_DAT(left_acl),
434  ACL_NUM(left_acl) * sizeof(AclItem));
435 
436  memcpy(ACL_DAT(result_acl) + ACL_NUM(left_acl),
437  ACL_DAT(right_acl),
438  ACL_NUM(right_acl) * sizeof(AclItem));
439 
440  return result_acl;
441 }
static Acl * allocacl(int n)
Definition: acl.c:375
#define ACL_NUM(ACL)
Definition: acl.h:101
#define ACL_DAT(ACL)
Definition: acl.h:102
Definition: acl.h:47
Datum aclcontains ( PG_FUNCTION_ARGS  )

Definition at line 1536 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.

1537 {
1538  Acl *acl = PG_GETARG_ACL_P(0);
1539  AclItem *aip = PG_GETARG_ACLITEM_P(1);
1540  AclItem *aidat;
1541  int i,
1542  num;
1543 
1544  check_acl(acl);
1545  num = ACL_NUM(acl);
1546  aidat = ACL_DAT(acl);
1547  for (i = 0; i < num; ++i)
1548  {
1549  if (aip->ai_grantee == aidat[i].ai_grantee &&
1550  aip->ai_grantor == aidat[i].ai_grantor &&
1551  (ACLITEM_GET_RIGHTS(*aip) & ACLITEM_GET_RIGHTS(aidat[i])) == ACLITEM_GET_RIGHTS(*aip))
1552  PG_RETURN_BOOL(true);
1553  }
1554  PG_RETURN_BOOL(false);
1555 }
Oid ai_grantee
Definition: acl.h:49
#define PG_GETARG_ACLITEM_P(n)
Definition: acl.h:110
Oid ai_grantor
Definition: acl.h:50
#define ACL_NUM(ACL)
Definition: acl.h:101
#define ACLITEM_GET_RIGHTS(item)
Definition: acl.h:61
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define ACL_DAT(ACL)
Definition: acl.h:102
Definition: acl.h:47
#define PG_GETARG_ACL_P(n)
Definition: acl.h:115
int i
static void check_acl(const Acl *acl)
Definition: acl.c:539
Acl* aclcopy ( const Acl orig_acl)

Definition at line 406 of file acl.c.

References ACL_DAT, ACL_NUM, and allocacl().

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

407 {
408  Acl *result_acl;
409 
410  result_acl = allocacl(ACL_NUM(orig_acl));
411 
412  memcpy(ACL_DAT(result_acl),
413  ACL_DAT(orig_acl),
414  ACL_NUM(orig_acl) * sizeof(AclItem));
415 
416  return result_acl;
417 }
static Acl * allocacl(int n)
Definition: acl.c:375
#define ACL_NUM(ACL)
Definition: acl.h:101
#define ACL_DAT(ACL)
Definition: acl.h:102
Definition: acl.h:47
Acl* acldefault ( GrantObjectType  objtype,
Oid  ownerId 
)

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

732 {
733  AclMode world_default;
734  AclMode owner_default;
735  int nacl;
736  Acl *acl;
737  AclItem *aip;
738 
739  switch (objtype)
740  {
741  case ACL_OBJECT_COLUMN:
742  /* by default, columns have no extra privileges */
743  world_default = ACL_NO_RIGHTS;
744  owner_default = ACL_NO_RIGHTS;
745  break;
746  case ACL_OBJECT_RELATION:
747  world_default = ACL_NO_RIGHTS;
748  owner_default = ACL_ALL_RIGHTS_RELATION;
749  break;
750  case ACL_OBJECT_SEQUENCE:
751  world_default = ACL_NO_RIGHTS;
752  owner_default = ACL_ALL_RIGHTS_SEQUENCE;
753  break;
754  case ACL_OBJECT_DATABASE:
755  /* for backwards compatibility, grant some rights by default */
756  world_default = ACL_CREATE_TEMP | ACL_CONNECT;
757  owner_default = ACL_ALL_RIGHTS_DATABASE;
758  break;
759  case ACL_OBJECT_FUNCTION:
760  /* Grant EXECUTE by default, for now */
761  world_default = ACL_EXECUTE;
762  owner_default = ACL_ALL_RIGHTS_FUNCTION;
763  break;
764  case ACL_OBJECT_LANGUAGE:
765  /* Grant USAGE by default, for now */
766  world_default = ACL_USAGE;
767  owner_default = ACL_ALL_RIGHTS_LANGUAGE;
768  break;
770  world_default = ACL_NO_RIGHTS;
771  owner_default = ACL_ALL_RIGHTS_LARGEOBJECT;
772  break;
774  world_default = ACL_NO_RIGHTS;
775  owner_default = ACL_ALL_RIGHTS_NAMESPACE;
776  break;
778  world_default = ACL_NO_RIGHTS;
779  owner_default = ACL_ALL_RIGHTS_TABLESPACE;
780  break;
781  case ACL_OBJECT_FDW:
782  world_default = ACL_NO_RIGHTS;
783  owner_default = ACL_ALL_RIGHTS_FDW;
784  break;
786  world_default = ACL_NO_RIGHTS;
787  owner_default = ACL_ALL_RIGHTS_FOREIGN_SERVER;
788  break;
789  case ACL_OBJECT_DOMAIN:
790  case ACL_OBJECT_TYPE:
791  world_default = ACL_USAGE;
792  owner_default = ACL_ALL_RIGHTS_TYPE;
793  break;
794  default:
795  elog(ERROR, "unrecognized objtype: %d", (int) objtype);
796  world_default = ACL_NO_RIGHTS; /* keep compiler quiet */
797  owner_default = ACL_NO_RIGHTS;
798  break;
799  }
800 
801  nacl = 0;
802  if (world_default != ACL_NO_RIGHTS)
803  nacl++;
804  if (owner_default != ACL_NO_RIGHTS)
805  nacl++;
806 
807  acl = allocacl(nacl);
808  aip = ACL_DAT(acl);
809 
810  if (world_default != ACL_NO_RIGHTS)
811  {
812  aip->ai_grantee = ACL_ID_PUBLIC;
813  aip->ai_grantor = ownerId;
814  ACLITEM_SET_PRIVS_GOPTIONS(*aip, world_default, ACL_NO_RIGHTS);
815  aip++;
816  }
817 
818  /*
819  * Note that the owner's entry shows all ordinary privileges but no grant
820  * options. This is because his grant options come "from the system" and
821  * not from his own efforts. (The SQL spec says that the owner's rights
822  * come from a "_SYSTEM" authid.) However, we do consider that the
823  * owner's ordinary privileges are self-granted; this lets him revoke
824  * them. We implement the owner's grant options without any explicit
825  * "_SYSTEM"-like ACL entry, by internally special-casing the owner
826  * wherever we are testing grant options.
827  */
828  if (owner_default != ACL_NO_RIGHTS)
829  {
830  aip->ai_grantee = ownerId;
831  aip->ai_grantor = ownerId;
832  ACLITEM_SET_PRIVS_GOPTIONS(*aip, owner_default, ACL_NO_RIGHTS);
833  }
834 
835  return acl;
836 }
Oid ai_grantee
Definition: acl.h:49
#define ACL_ALL_RIGHTS_FUNCTION
Definition: acl.h:155
static Acl * allocacl(int n)
Definition: acl.c:375
#define ACL_ALL_RIGHTS_TABLESPACE
Definition: acl.h:159
Oid ai_grantor
Definition: acl.h:50
#define ACL_ALL_RIGHTS_LANGUAGE
Definition: acl.h:156
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:160
#define ACL_USAGE
Definition: parsenodes.h:80
#define ACL_CONNECT
Definition: parsenodes.h:84
#define ACL_ALL_RIGHTS_NAMESPACE
Definition: acl.h:158
#define ACL_DAT(ACL)
Definition: acl.h:102
#define ACL_ALL_RIGHTS_SEQUENCE
Definition: acl.h:151
Definition: acl.h:47
#define ACL_ALL_RIGHTS_LARGEOBJECT
Definition: acl.h:157
#define ACL_ALL_RIGHTS_DATABASE
Definition: acl.h:152
#define ACL_ALL_RIGHTS_FOREIGN_SERVER
Definition: acl.h:154
#define ACL_EXECUTE
Definition: parsenodes.h:79
#define ACL_ALL_RIGHTS_RELATION
Definition: acl.h:150
#define ACL_CREATE_TEMP
Definition: parsenodes.h:83
#define ACL_ID_PUBLIC
Definition: acl.h:39
#define ACL_ALL_RIGHTS_FDW
Definition: acl.h:153
#define elog
Definition: elog.h:219
#define ACLITEM_SET_PRIVS_GOPTIONS(item, privs, goptions)
Definition: acl.h:75
Datum acldefault_sql ( PG_FUNCTION_ARGS  )

Definition at line 845 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.

846 {
847  char objtypec = PG_GETARG_CHAR(0);
848  Oid owner = PG_GETARG_OID(1);
849  GrantObjectType objtype = 0;
850 
851  switch (objtypec)
852  {
853  case 'c':
854  objtype = ACL_OBJECT_COLUMN;
855  break;
856  case 'r':
857  objtype = ACL_OBJECT_RELATION;
858  break;
859  case 's':
860  objtype = ACL_OBJECT_SEQUENCE;
861  break;
862  case 'd':
863  objtype = ACL_OBJECT_DATABASE;
864  break;
865  case 'f':
866  objtype = ACL_OBJECT_FUNCTION;
867  break;
868  case 'l':
869  objtype = ACL_OBJECT_LANGUAGE;
870  break;
871  case 'L':
872  objtype = ACL_OBJECT_LARGEOBJECT;
873  break;
874  case 'n':
875  objtype = ACL_OBJECT_NAMESPACE;
876  break;
877  case 't':
878  objtype = ACL_OBJECT_TABLESPACE;
879  break;
880  case 'F':
881  objtype = ACL_OBJECT_FDW;
882  break;
883  case 'S':
884  objtype = ACL_OBJECT_FOREIGN_SERVER;
885  break;
886  case 'T':
887  objtype = ACL_OBJECT_TYPE;
888  break;
889  default:
890  elog(ERROR, "unrecognized objtype abbreviation: %c", objtypec);
891  }
892 
893  PG_RETURN_ACL_P(acldefault(objtype, owner));
894 }
GrantObjectType
Definition: parsenodes.h:1804
#define PG_RETURN_ACL_P(x)
Definition: acl.h:117
Acl * acldefault(GrantObjectType objtype, Oid ownerId)
Definition: acl.c:731
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
bool aclequal ( const Acl left_acl,
const Acl right_acl 
)

Definition at line 508 of file acl.c.

References ACL_DAT, ACL_NUM, and NULL.

Referenced by get_user_default_acl(), and SetDefaultACL().

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

Definition at line 1729 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, result, 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.

1730 {
1731  Acl *acl = PG_GETARG_ACL_P(0);
1732  FuncCallContext *funcctx;
1733  int *idx;
1734  AclItem *aidat;
1735 
1736  if (SRF_IS_FIRSTCALL())
1737  {
1738  TupleDesc tupdesc;
1739  MemoryContext oldcontext;
1740 
1741  check_acl(acl);
1742 
1743  funcctx = SRF_FIRSTCALL_INIT();
1744  oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
1745 
1746  /*
1747  * build tupdesc for result tuples (matches out parameters in pg_proc
1748  * entry)
1749  */
1750  tupdesc = CreateTemplateTupleDesc(4, false);
1751  TupleDescInitEntry(tupdesc, (AttrNumber) 1, "grantor",
1752  OIDOID, -1, 0);
1753  TupleDescInitEntry(tupdesc, (AttrNumber) 2, "grantee",
1754  OIDOID, -1, 0);
1755  TupleDescInitEntry(tupdesc, (AttrNumber) 3, "privilege_type",
1756  TEXTOID, -1, 0);
1757  TupleDescInitEntry(tupdesc, (AttrNumber) 4, "is_grantable",
1758  BOOLOID, -1, 0);
1759 
1760  funcctx->tuple_desc = BlessTupleDesc(tupdesc);
1761 
1762  /* allocate memory for user context */
1763  idx = (int *) palloc(sizeof(int[2]));
1764  idx[0] = 0; /* ACL array item index */
1765  idx[1] = -1; /* privilege type counter */
1766  funcctx->user_fctx = (void *) idx;
1767 
1768  MemoryContextSwitchTo(oldcontext);
1769  }
1770 
1771  funcctx = SRF_PERCALL_SETUP();
1772  idx = (int *) funcctx->user_fctx;
1773  aidat = ACL_DAT(acl);
1774 
1775  /* need test here in case acl has no items */
1776  while (idx[0] < ACL_NUM(acl))
1777  {
1778  AclItem *aidata;
1779  AclMode priv_bit;
1780 
1781  idx[1]++;
1782  if (idx[1] == N_ACL_RIGHTS)
1783  {
1784  idx[1] = 0;
1785  idx[0]++;
1786  if (idx[0] >= ACL_NUM(acl)) /* done */
1787  break;
1788  }
1789  aidata = &aidat[idx[0]];
1790  priv_bit = 1 << idx[1];
1791 
1792  if (ACLITEM_GET_PRIVS(*aidata) & priv_bit)
1793  {
1794  Datum result;
1795  Datum values[4];
1796  bool nulls[4];
1797  HeapTuple tuple;
1798 
1799  values[0] = ObjectIdGetDatum(aidata->ai_grantor);
1800  values[1] = ObjectIdGetDatum(aidata->ai_grantee);
1801  values[2] = CStringGetTextDatum(convert_aclright_to_string(priv_bit));
1802  values[3] = BoolGetDatum((ACLITEM_GET_GOPTIONS(*aidata) & priv_bit) != 0);
1803 
1804  MemSet(nulls, 0, sizeof(nulls));
1805 
1806  tuple = heap_form_tuple(funcctx->tuple_desc, values, nulls);
1807  result = HeapTupleGetDatum(tuple);
1808 
1809  SRF_RETURN_NEXT(funcctx, result);
1810  }
1811  }
1812 
1813  SRF_RETURN_DONE(funcctx);
1814 }
Oid ai_grantee
Definition: acl.h:49
static const char * convert_aclright_to_string(int aclright)
Definition: acl.c:1679
#define ACLITEM_GET_GOPTIONS(item)
Definition: acl.h:60
#define OIDOID
Definition: pg_type.h:328
#define TEXTOID
Definition: pg_type.h:324
#define SRF_IS_FIRSTCALL()
Definition: funcapi.h:285
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
#define MemSet(start, val, len)
Definition: c.h:857
Datum idx(PG_FUNCTION_ARGS)
Definition: _int_op.c:264
return result
Definition: formatting.c:1632
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition: heaptuple.c:692
#define SRF_PERCALL_SETUP()
Definition: funcapi.h:289
Oid ai_grantor
Definition: acl.h:50
TupleDesc tuple_desc
Definition: funcapi.h:120
#define SRF_RETURN_NEXT(_funcctx, _result)
Definition: funcapi.h:291
uint32 AclMode
Definition: parsenodes.h:70
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ACL_NUM(ACL)
Definition: acl.h:101
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
Definition: execTuples.c:1031
#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:497
uintptr_t Datum
Definition: postgres.h:372
#define ACL_DAT(ACL)
Definition: acl.h:102
#define BoolGetDatum(X)
Definition: postgres.h:408
Definition: acl.h:47
MemoryContext multi_call_memory_ctx
Definition: funcapi.h:109
#define ACLITEM_GET_PRIVS(item)
Definition: acl.h:59
#define HeapTupleGetDatum(tuple)
Definition: funcapi.h:222
#define BOOLOID
Definition: pg_type.h:288
TupleDesc CreateTemplateTupleDesc(int natts, bool hasoid)
Definition: tupdesc.c:41
#define PG_GETARG_ACL_P(n)
Definition: acl.h:115
static Datum values[MAXATTR]
Definition: bootstrap.c:163
void * user_fctx
Definition: funcapi.h:90
void * palloc(Size size)
Definition: mcxt.c:849
#define CStringGetTextDatum(s)
Definition: builtins.h:91
int16 AttrNumber
Definition: attnum.h:21
static void check_acl(const Acl *acl)
Definition: acl.c:539
#define SRF_RETURN_DONE(_funcctx)
Definition: funcapi.h:309
#define SRF_FIRSTCALL_INIT()
Definition: funcapi.h:287
Datum aclinsert ( PG_FUNCTION_ARGS  )

Definition at line 1516 of file acl.c.

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

1517 {
1518  ereport(ERROR,
1519  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1520  errmsg("aclinsert is no longer supported")));
1521 
1522  PG_RETURN_NULL(); /* keep compiler quiet */
1523 }
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
Datum aclitem_eq ( PG_FUNCTION_ARGS  )

Definition at line 692 of file acl.c.

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

693 {
696  bool result;
697 
698  result = a1->ai_privs == a2->ai_privs &&
699  a1->ai_grantee == a2->ai_grantee &&
700  a1->ai_grantor == a2->ai_grantor;
701  PG_RETURN_BOOL(result);
702 }
Oid ai_grantee
Definition: acl.h:49
return result
Definition: formatting.c:1632
#define PG_GETARG_ACLITEM_P(n)
Definition: acl.h:110
Oid ai_grantor
Definition: acl.h:50
AclMode ai_privs
Definition: acl.h:51
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
Definition: acl.h:47
static FormData_pg_attribute a1
Definition: heap.c:144
static FormData_pg_attribute a2
Definition: heap.c:150
static bool aclitem_match ( const AclItem a1,
const AclItem a2 
)
static

Definition at line 657 of file acl.c.

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

Referenced by aclnewowner(), and aclupdate().

658 {
659  return a1->ai_grantee == a2->ai_grantee &&
660  a1->ai_grantor == a2->ai_grantor;
661 }
Oid ai_grantee
Definition: acl.h:49
Oid ai_grantor
Definition: acl.h:50
static int aclitemComparator ( const void *  arg1,
const void *  arg2 
)
static

Definition at line 668 of file acl.c.

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

Referenced by aclitemsort().

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

Definition at line 564 of file acl.c.

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

565 {
566  const char *s = PG_GETARG_CSTRING(0);
567  AclItem *aip;
568 
569  aip = (AclItem *) palloc(sizeof(AclItem));
570  s = aclparse(s, aip);
571  while (isspace((unsigned char) *s))
572  ++s;
573  if (*s)
574  ereport(ERROR,
575  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
576  errmsg("extra garbage at the end of the ACL specification")));
577 
578  PG_RETURN_ACLITEM_P(aip);
579 }
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:237
Definition: acl.h:47
#define PG_RETURN_ACLITEM_P(x)
Definition: acl.h:111
void * palloc(Size size)
Definition: mcxt.c:849
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:242
Datum aclitemout ( PG_FUNCTION_ARGS  )

Definition at line 590 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.

591 {
592  AclItem *aip = PG_GETARG_ACLITEM_P(0);
593  char *p;
594  char *out;
595  HeapTuple htup;
596  unsigned i;
597 
598  out = palloc(strlen("=/") +
599  2 * N_ACL_RIGHTS +
600  2 * (2 * NAMEDATALEN + 2) +
601  1);
602 
603  p = out;
604  *p = '\0';
605 
606  if (aip->ai_grantee != ACL_ID_PUBLIC)
607  {
609  if (HeapTupleIsValid(htup))
610  {
611  putid(p, NameStr(((Form_pg_authid) GETSTRUCT(htup))->rolname));
612  ReleaseSysCache(htup);
613  }
614  else
615  {
616  /* Generate numeric OID if we don't find an entry */
617  sprintf(p, "%u", aip->ai_grantee);
618  }
619  }
620  while (*p)
621  ++p;
622 
623  *p++ = '=';
624 
625  for (i = 0; i < N_ACL_RIGHTS; ++i)
626  {
627  if (ACLITEM_GET_PRIVS(*aip) & (1 << i))
628  *p++ = ACL_ALL_RIGHTS_STR[i];
629  if (ACLITEM_GET_GOPTIONS(*aip) & (1 << i))
630  *p++ = '*';
631  }
632 
633  *p++ = '/';
634  *p = '\0';
635 
637  if (HeapTupleIsValid(htup))
638  {
639  putid(p, NameStr(((Form_pg_authid) GETSTRUCT(htup))->rolname));
640  ReleaseSysCache(htup);
641  }
642  else
643  {
644  /* Generate numeric OID if we don't find an entry */
645  sprintf(p, "%u", aip->ai_grantor);
646  }
647 
648  PG_RETURN_CSTRING(out);
649 }
Oid ai_grantee
Definition: acl.h:49
static void putid(char *p, const char *s)
Definition: acl.c:188
#define ACLITEM_GET_GOPTIONS(item)
Definition: acl.h:60
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
#define PG_GETARG_ACLITEM_P(n)
Definition: acl.h:110
Oid ai_grantor
Definition: acl.h:50
#define SearchSysCache1(cacheId, key1)
Definition: syscache.h:156
#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
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1117
#define ACL_ALL_RIGHTS_STR
Definition: acl.h:144
Definition: acl.h:47
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:322
#define ACLITEM_GET_PRIVS(item)
Definition: acl.h:59
void * palloc(Size size)
Definition: mcxt.c:849
int i
#define NameStr(name)
Definition: c.h:499
#define ACL_ID_PUBLIC
Definition: acl.h:39
void aclitemsort ( Acl acl)

Definition at line 494 of file acl.c.

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

Referenced by get_user_default_acl(), and SetDefaultACL().

495 {
496  if (acl != NULL && ACL_NUM(acl) > 1)
497  qsort(ACL_DAT(acl), ACL_NUM(acl), sizeof(AclItem), aclitemComparator);
498 }
#define ACL_NUM(ACL)
Definition: acl.h:101
#define ACL_DAT(ACL)
Definition: acl.h:102
Definition: acl.h:47
#define NULL
Definition: c.h:229
#define qsort(a, b, c, d)
Definition: port.h:440
static int aclitemComparator(const void *arg1, const void *arg2)
Definition: acl.c:668
AclMode aclmask ( const Acl acl,
Oid  roleid,
Oid  ownerId,
AclMode  mask,
AclMaskHow  how 
)

Definition at line 1304 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, NULL, remaining, and result.

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

1306 {
1307  AclMode result;
1309  AclItem *aidat;
1310  int i,
1311  num;
1312 
1313  /*
1314  * Null ACL should not happen, since caller should have inserted
1315  * appropriate default
1316  */
1317  if (acl == NULL)
1318  elog(ERROR, "null ACL");
1319 
1320  check_acl(acl);
1321 
1322  /* Quick exit for mask == 0 */
1323  if (mask == 0)
1324  return 0;
1325 
1326  result = 0;
1327 
1328  /* Owner always implicitly has all grant options */
1329  if ((mask & ACLITEM_ALL_GOPTION_BITS) &&
1330  has_privs_of_role(roleid, ownerId))
1331  {
1332  result = mask & ACLITEM_ALL_GOPTION_BITS;
1333  if ((how == ACLMASK_ALL) ? (result == mask) : (result != 0))
1334  return result;
1335  }
1336 
1337  num = ACL_NUM(acl);
1338  aidat = ACL_DAT(acl);
1339 
1340  /*
1341  * Check privileges granted directly to roleid or to public
1342  */
1343  for (i = 0; i < num; i++)
1344  {
1345  AclItem *aidata = &aidat[i];
1346 
1347  if (aidata->ai_grantee == ACL_ID_PUBLIC ||
1348  aidata->ai_grantee == roleid)
1349  {
1350  result |= aidata->ai_privs & mask;
1351  if ((how == ACLMASK_ALL) ? (result == mask) : (result != 0))
1352  return result;
1353  }
1354  }
1355 
1356  /*
1357  * Check privileges granted indirectly via role memberships. We do this in
1358  * a separate pass to minimize expensive indirect membership tests. In
1359  * particular, it's worth testing whether a given ACL entry grants any
1360  * privileges still of interest before we perform the has_privs_of_role
1361  * test.
1362  */
1363  remaining = mask & ~result;
1364  for (i = 0; i < num; i++)
1365  {
1366  AclItem *aidata = &aidat[i];
1367 
1368  if (aidata->ai_grantee == ACL_ID_PUBLIC ||
1369  aidata->ai_grantee == roleid)
1370  continue; /* already checked it */
1371 
1372  if ((aidata->ai_privs & remaining) &&
1373  has_privs_of_role(roleid, aidata->ai_grantee))
1374  {
1375  result |= aidata->ai_privs & mask;
1376  if ((how == ACLMASK_ALL) ? (result == mask) : (result != 0))
1377  return result;
1378  remaining = mask & ~result;
1379  }
1380  }
1381 
1382  return result;
1383 }
int remaining
Definition: informix.c:692
Oid ai_grantee
Definition: acl.h:49
#define ACLITEM_ALL_GOPTION_BITS
Definition: acl.h:81
bool has_privs_of_role(Oid member, Oid role)
Definition: acl.c:4813
return result
Definition: formatting.c:1632
AclMode ai_privs
Definition: acl.h:51
uint32 AclMode
Definition: parsenodes.h:70
#define ERROR
Definition: elog.h:43
#define ACL_NUM(ACL)
Definition: acl.h:101
#define ACL_DAT(ACL)
Definition: acl.h:102
Definition: acl.h:47
#define NULL
Definition: c.h:229
int i
#define ACL_ID_PUBLIC
Definition: acl.h:39
#define elog
Definition: elog.h:219
static void check_acl(const Acl *acl)
Definition: acl.c:539
static AclMode aclmask_direct ( const Acl acl,
Oid  roleid,
Oid  ownerId,
AclMode  mask,
AclMaskHow  how 
)
static

Definition at line 1393 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, i, NULL, and result.

Referenced by select_best_grantor().

1395 {
1396  AclMode result;
1397  AclItem *aidat;
1398  int i,
1399  num;
1400 
1401  /*
1402  * Null ACL should not happen, since caller should have inserted
1403  * appropriate default
1404  */
1405  if (acl == NULL)
1406  elog(ERROR, "null ACL");
1407 
1408  check_acl(acl);
1409 
1410  /* Quick exit for mask == 0 */
1411  if (mask == 0)
1412  return 0;
1413 
1414  result = 0;
1415 
1416  /* Owner always implicitly has all grant options */
1417  if ((mask & ACLITEM_ALL_GOPTION_BITS) &&
1418  roleid == ownerId)
1419  {
1420  result = mask & ACLITEM_ALL_GOPTION_BITS;
1421  if ((how == ACLMASK_ALL) ? (result == mask) : (result != 0))
1422  return result;
1423  }
1424 
1425  num = ACL_NUM(acl);
1426  aidat = ACL_DAT(acl);
1427 
1428  /*
1429  * Check privileges granted directly to roleid (and not to public)
1430  */
1431  for (i = 0; i < num; i++)
1432  {
1433  AclItem *aidata = &aidat[i];
1434 
1435  if (aidata->ai_grantee == roleid)
1436  {
1437  result |= aidata->ai_privs & mask;
1438  if ((how == ACLMASK_ALL) ? (result == mask) : (result != 0))
1439  return result;
1440  }
1441  }
1442 
1443  return result;
1444 }
Oid ai_grantee
Definition: acl.h:49
#define ACLITEM_ALL_GOPTION_BITS
Definition: acl.h:81
return result
Definition: formatting.c:1632
AclMode ai_privs
Definition: acl.h:51
uint32 AclMode
Definition: parsenodes.h:70
#define ERROR
Definition: elog.h:43
#define ACL_NUM(ACL)
Definition: acl.h:101
#define ACL_DAT(ACL)
Definition: acl.h:102
Definition: acl.h:47
#define NULL
Definition: c.h:229
int i
#define elog
Definition: elog.h:219
static void check_acl(const Acl *acl)
Definition: acl.c:539
int aclmembers ( const Acl acl,
Oid **  roleids 
)

Definition at line 1456 of file acl.c.

References ACL_DAT, ACL_ID_PUBLIC, ACL_NUM, AclItem::ai_grantee, AclItem::ai_grantor, check_acl(), i, sort-test::list, NULL, 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().

1457 {
1458  Oid *list;
1459  const AclItem *acldat;
1460  int i,
1461  j,
1462  k;
1463 
1464  if (acl == NULL || ACL_NUM(acl) == 0)
1465  {
1466  *roleids = NULL;
1467  return 0;
1468  }
1469 
1470  check_acl(acl);
1471 
1472  /* Allocate the worst-case space requirement */
1473  list = palloc(ACL_NUM(acl) * 2 * sizeof(Oid));
1474  acldat = ACL_DAT(acl);
1475 
1476  /*
1477  * Walk the ACL collecting mentioned RoleIds.
1478  */
1479  j = 0;
1480  for (i = 0; i < ACL_NUM(acl); i++)
1481  {
1482  const AclItem *ai = &acldat[i];
1483 
1484  if (ai->ai_grantee != ACL_ID_PUBLIC)
1485  list[j++] = ai->ai_grantee;
1486  /* grantor is currently never PUBLIC, but let's check anyway */
1487  if (ai->ai_grantor != ACL_ID_PUBLIC)
1488  list[j++] = ai->ai_grantor;
1489  }
1490 
1491  /* Sort the array */
1492  qsort(list, j, sizeof(Oid), oid_cmp);
1493 
1494  /* Remove duplicates from the array */
1495  k = 0;
1496  for (i = 1; i < j; i++)
1497  {
1498  if (list[k] != list[i])
1499  list[++k] = list[i];
1500  }
1501 
1502  /*
1503  * We could repalloc the array down to minimum size, but it's hardly worth
1504  * it since it's only transient memory.
1505  */
1506  *roleids = list;
1507 
1508  return k + 1;
1509 }
Oid ai_grantee
Definition: acl.h:49
unsigned int Oid
Definition: postgres_ext.h:31
Oid ai_grantor
Definition: acl.h:50
#define ACL_NUM(ACL)
Definition: acl.h:101
#define ACL_DAT(ACL)
Definition: acl.h:102
Definition: acl.h:47
#define NULL
Definition: c.h:229
int oid_cmp(const void *p1, const void *p2)
Definition: oid.c:336
tuple list
Definition: sort-test.py:11
void * palloc(Size size)
Definition: mcxt.c:849
int i
#define ACL_ID_PUBLIC
Definition: acl.h:39
#define qsort(a, b, c, d)
Definition: port.h:440
static void check_acl(const Acl *acl)
Definition: acl.c:539
Acl* aclmerge ( const Acl left_acl,
const Acl right_acl,
Oid  ownerId 
)

Definition at line 450 of file acl.c.

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

Referenced by get_user_default_acl().

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

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

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

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

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

Definition at line 1526 of file acl.c.

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

1527 {
1528  ereport(ERROR,
1529  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1530  errmsg("aclremove is no longer supported")));
1531 
1532  PG_RETURN_NULL(); /* keep compiler quiet */
1533 }
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
Acl* aclupdate ( const Acl old_acl,
const AclItem mod_aip,
int  modechg,
Oid  ownerId,
DropBehavior  behavior 
)

Definition at line 914 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, NULL, recursive_revoke(), and SET_VARSIZE.

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

916 {
917  Acl *new_acl = NULL;
918  AclItem *old_aip,
919  *new_aip = NULL;
920  AclMode old_rights,
921  old_goptions,
922  new_rights,
923  new_goptions;
924  int dst,
925  num;
926 
927  /* Caller probably already checked old_acl, but be safe */
928  check_acl(old_acl);
929 
930  /* If granting grant options, check for circularity */
931  if (modechg != ACL_MODECHG_DEL &&
932  ACLITEM_GET_GOPTIONS(*mod_aip) != ACL_NO_RIGHTS)
933  check_circularity(old_acl, mod_aip, ownerId);
934 
935  num = ACL_NUM(old_acl);
936  old_aip = ACL_DAT(old_acl);
937 
938  /*
939  * Search the ACL for an existing entry for this grantee and grantor. If
940  * one exists, just modify the entry in-place (well, in the same position,
941  * since we actually return a copy); otherwise, insert the new entry at
942  * the end.
943  */
944 
945  for (dst = 0; dst < num; ++dst)
946  {
947  if (aclitem_match(mod_aip, old_aip + dst))
948  {
949  /* found a match, so modify existing item */
950  new_acl = allocacl(num);
951  new_aip = ACL_DAT(new_acl);
952  memcpy(new_acl, old_acl, ACL_SIZE(old_acl));
953  break;
954  }
955  }
956 
957  if (dst == num)
958  {
959  /* need to append a new item */
960  new_acl = allocacl(num + 1);
961  new_aip = ACL_DAT(new_acl);
962  memcpy(new_aip, old_aip, num * sizeof(AclItem));
963 
964  /* initialize the new entry with no permissions */
965  new_aip[dst].ai_grantee = mod_aip->ai_grantee;
966  new_aip[dst].ai_grantor = mod_aip->ai_grantor;
967  ACLITEM_SET_PRIVS_GOPTIONS(new_aip[dst],
969  num++; /* set num to the size of new_acl */
970  }
971 
972  old_rights = ACLITEM_GET_RIGHTS(new_aip[dst]);
973  old_goptions = ACLITEM_GET_GOPTIONS(new_aip[dst]);
974 
975  /* apply the specified permissions change */
976  switch (modechg)
977  {
978  case ACL_MODECHG_ADD:
979  ACLITEM_SET_RIGHTS(new_aip[dst],
980  old_rights | ACLITEM_GET_RIGHTS(*mod_aip));
981  break;
982  case ACL_MODECHG_DEL:
983  ACLITEM_SET_RIGHTS(new_aip[dst],
984  old_rights & ~ACLITEM_GET_RIGHTS(*mod_aip));
985  break;
986  case ACL_MODECHG_EQL:
987  ACLITEM_SET_RIGHTS(new_aip[dst],
988  ACLITEM_GET_RIGHTS(*mod_aip));
989  break;
990  }
991 
992  new_rights = ACLITEM_GET_RIGHTS(new_aip[dst]);
993  new_goptions = ACLITEM_GET_GOPTIONS(new_aip[dst]);
994 
995  /*
996  * If the adjusted entry has no permissions, delete it from the list.
997  */
998  if (new_rights == ACL_NO_RIGHTS)
999  {
1000  memmove(new_aip + dst,
1001  new_aip + dst + 1,
1002  (num - dst - 1) * sizeof(AclItem));
1003  /* Adjust array size to be 'num - 1' items */
1004  ARR_DIMS(new_acl)[0] = num - 1;
1005  SET_VARSIZE(new_acl, ACL_N_SIZE(num - 1));
1006  }
1007 
1008  /*
1009  * Remove abandoned privileges (cascading revoke). Currently we can only
1010  * handle this when the grantee is not PUBLIC.
1011  */
1012  if ((old_goptions & ~new_goptions) != 0)
1013  {
1014  Assert(mod_aip->ai_grantee != ACL_ID_PUBLIC);
1015  new_acl = recursive_revoke(new_acl, mod_aip->ai_grantee,
1016  (old_goptions & ~new_goptions),
1017  ownerId, behavior);
1018  }
1019 
1020  return new_acl;
1021 }
Oid ai_grantee
Definition: acl.h:49
#define ACL_MODECHG_EQL
Definition: acl.h:124
#define ACLITEM_GET_GOPTIONS(item)
Definition: acl.h:60
static Acl * allocacl(int n)
Definition: acl.c:375
#define ACL_MODECHG_DEL
Definition: acl.h:123
#define ACL_SIZE(ACL)
Definition: acl.h:104
Oid ai_grantor
Definition: acl.h:50
uint32 AclMode
Definition: parsenodes.h:70
static void check_circularity(const Acl *old_acl, const AclItem *mod_aip, Oid ownerId)
Definition: acl.c:1138
#define ARR_DIMS(a)
Definition: array.h:275
#define ACL_NUM(ACL)
Definition: acl.h:101
#define ACL_NO_RIGHTS
Definition: parsenodes.h:86
#define memmove(d, s, c)
Definition: c.h:1058
#define ACLITEM_GET_RIGHTS(item)
Definition: acl.h:61
#define ACLITEM_SET_RIGHTS(item, rights)
Definition: acl.h:72
#define ACL_MODECHG_ADD
Definition: acl.h:122
#define ACL_DAT(ACL)
Definition: acl.h:102
Definition: acl.h:47
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
static bool aclitem_match(const AclItem *a1, const AclItem *a2)
Definition: acl.c:657
static Acl * recursive_revoke(Acl *acl, Oid grantee, AclMode revoke_privs, Oid ownerId, DropBehavior behavior)
Definition: acl.c:1218
#define ACL_ID_PUBLIC
Definition: acl.h:39
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:328
#define ACL_N_SIZE(N)
Definition: acl.h:103
#define ACLITEM_SET_PRIVS_GOPTIONS(item, privs, goptions)
Definition: acl.h:75
static void check_acl(const Acl *acl)
Definition: acl.c:539
static Acl * allocacl ( int  n)
static

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

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

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

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

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

1140 {
1141  Acl *acl;
1142  AclItem *aip;
1143  int i,
1144  num;
1145  AclMode own_privs;
1146 
1147  check_acl(old_acl);
1148 
1149  /*
1150  * For now, grant options can only be granted to roles, not PUBLIC.
1151  * Otherwise we'd have to work a bit harder here.
1152  */
1153  Assert(mod_aip->ai_grantee != ACL_ID_PUBLIC);
1154 
1155  /* The owner always has grant options, no need to check */
1156  if (mod_aip->ai_grantor == ownerId)
1157  return;
1158 
1159  /* Make a working copy */
1160  acl = allocacl(ACL_NUM(old_acl));
1161  memcpy(acl, old_acl, ACL_SIZE(old_acl));
1162 
1163  /* Zap all grant options of target grantee, plus what depends on 'em */
1164 cc_restart:
1165  num = ACL_NUM(acl);
1166  aip = ACL_DAT(acl);
1167  for (i = 0; i < num; i++)
1168  {
1169  if (aip[i].ai_grantee == mod_aip->ai_grantee &&
1171  {
1172  Acl *new_acl;
1173 
1174  /* We'll actually zap ordinary privs too, but no matter */
1175  new_acl = aclupdate(acl, &aip[i], ACL_MODECHG_DEL,
1176  ownerId, DROP_CASCADE);
1177 
1178  pfree(acl);
1179  acl = new_acl;
1180 
1181  goto cc_restart;
1182  }
1183  }
1184 
1185  /* Now we can compute grantor's independently-derived privileges */
1186  own_privs = aclmask(acl,
1187  mod_aip->ai_grantor,
1188  ownerId,
1190  ACLMASK_ALL);
1191  own_privs = ACL_OPTION_TO_PRIVS(own_privs);
1192 
1193  if ((ACLITEM_GET_GOPTIONS(*mod_aip) & ~own_privs) != 0)
1194  ereport(ERROR,
1195  (errcode(ERRCODE_INVALID_GRANT_OPERATION),
1196  errmsg("grant options cannot be granted back to your own grantor")));
1197 
1198  pfree(acl);
1199 }
Oid ai_grantee
Definition: acl.h:49
#define ACLITEM_GET_GOPTIONS(item)
Definition: acl.h:60
static Acl * allocacl(int n)
Definition: acl.c:375
#define ACL_MODECHG_DEL
Definition: acl.h:123
AclMode aclmask(const Acl *acl, Oid roleid, Oid ownerId, AclMode mask, AclMaskHow how)
Definition: acl.c:1304
#define ACL_SIZE(ACL)
Definition: acl.h:104
int errcode(int sqlerrcode)
Definition: elog.c:575
Oid ai_grantor
Definition: acl.h:50
uint32 AclMode
Definition: parsenodes.h:70
void pfree(void *pointer)
Definition: mcxt.c:950
#define ERROR
Definition: elog.h:43
#define ACL_NUM(ACL)
Definition: acl.h:101
#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:63
#define ACL_DAT(ACL)
Definition: acl.h:102
Definition: acl.h:47
#define ACL_OPTION_TO_PRIVS(privs)
Definition: acl.h:64
#define Assert(condition)
Definition: c.h:675
int errmsg(const char *fmt,...)
Definition: elog.c:797
int i
#define ACL_ID_PUBLIC
Definition: acl.h:39
Acl * aclupdate(const Acl *old_acl, const AclItem *mod_aip, int modechg, Oid ownerId, DropBehavior behavior)
Definition: acl.c:914
static void check_acl(const Acl *acl)
Definition: acl.c:539
void check_is_member_of_role ( Oid  member,
Oid  role 
)

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

4860 {
4861  if (!is_member_of_role(member, role))
4862  ereport(ERROR,
4863  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
4864  errmsg("must be member of role \"%s\"",
4865  GetUserNameFromId(role, false))));
4866 }
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:4837
char * GetUserNameFromId(Oid roleid, bool noerr)
Definition: miscinit.c:691
int errmsg(const char *fmt,...)
Definition: elog.c:797
void check_rolespec_name ( const RoleSpec role,
const char *  detail_msg 
)

Definition at line 5233 of file acl.c.

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

Referenced by AlterRole(), and AlterRoleSet().

5234 {
5235  if (!role)
5236  return;
5237 
5238  if (role->roletype != ROLESPEC_CSTRING)
5239  return;
5240 
5241  if (IsReservedName(role->rolename))
5242  {
5243  if (detail_msg)
5244  ereport(ERROR,
5245  (errcode(ERRCODE_RESERVED_NAME),
5246  errmsg("role name \"%s\" is reserved",
5247  role->rolename),
5248  errdetail("%s", detail_msg)));
5249  else
5250  ereport(ERROR,
5251  (errcode(ERRCODE_RESERVED_NAME),
5252  errmsg("role name \"%s\" is reserved",
5253  role->rolename)));
5254  }
5255 }
int errcode(int sqlerrcode)
Definition: elog.c:575
bool IsReservedName(const char *name)
Definition: catalog.c:193
#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:328
char * rolename
Definition: parsenodes.h:329
int errmsg(const char *fmt,...)
Definition: elog.c:797
static int column_privilege_check ( Oid  tableoid,
AttrNumber  attnum,
Oid  roleid,
AclMode  mode 
)
static

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

2444 {
2445  AclResult aclresult;
2446  HeapTuple attTuple;
2447  Form_pg_attribute attributeForm;
2448 
2449  /*
2450  * First check if we have the privilege at the table level. We check
2451  * existence of the pg_class row before risking calling pg_class_aclcheck.
2452  * Note: it might seem there's a race condition against concurrent DROP,
2453  * but really it's safe because there will be no syscache flush between
2454  * here and there. So if we see the row in the syscache, so will
2455  * pg_class_aclcheck.
2456  */
2458  return -1;
2459 
2460  aclresult = pg_class_aclcheck(tableoid, roleid, mode);
2461 
2462  if (aclresult == ACLCHECK_OK)
2463  return true;
2464 
2465  /*
2466  * No table privilege, so try per-column privileges. Again, we have to
2467  * check for dropped attribute first, and we rely on the syscache not to
2468  * notice a concurrent drop before pg_attribute_aclcheck fetches the row.
2469  */
2470  attTuple = SearchSysCache2(ATTNUM,
2471  ObjectIdGetDatum(tableoid),
2472  Int16GetDatum(attnum));
2473  if (!HeapTupleIsValid(attTuple))
2474  return -1;
2475  attributeForm = (Form_pg_attribute) GETSTRUCT(attTuple);
2476  if (attributeForm->attisdropped)
2477  {
2478  ReleaseSysCache(attTuple);
2479  return -1;
2480  }
2481  ReleaseSysCache(attTuple);
2482 
2483  aclresult = pg_attribute_aclcheck(tableoid, attnum, roleid, mode);
2484 
2485  return (aclresult == ACLCHECK_OK);
2486 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
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:174
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:187
AclResult
Definition: acl.h:170
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1117
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
AclResult pg_class_aclcheck(Oid table_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4422
#define SearchSysCache2(cacheId, key1, key2)
Definition: syscache.h:158
static const char* convert_aclright_to_string ( int  aclright)
static

Definition at line 1679 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, ERROR, and NULL.

Referenced by aclexplode().

1680 {
1681  switch (aclright)
1682  {
1683  case ACL_INSERT:
1684  return "INSERT";
1685  case ACL_SELECT:
1686  return "SELECT";
1687  case ACL_UPDATE:
1688  return "UPDATE";
1689  case ACL_DELETE:
1690  return "DELETE";
1691  case ACL_TRUNCATE:
1692  return "TRUNCATE";
1693  case ACL_REFERENCES:
1694  return "REFERENCES";
1695  case ACL_TRIGGER:
1696  return "TRIGGER";
1697  case ACL_EXECUTE:
1698  return "EXECUTE";
1699  case ACL_USAGE:
1700  return "USAGE";
1701  case ACL_CREATE:
1702  return "CREATE";
1703  case ACL_CREATE_TEMP:
1704  return "TEMPORARY";
1705  case ACL_CONNECT:
1706  return "CONNECT";
1707  default:
1708  elog(ERROR, "unrecognized aclright: %d", aclright);
1709  return NULL;
1710  }
1711 }
#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 NULL
Definition: c.h:229
#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
static AclMode convert_any_priv_string ( text priv_type_text,
const priv_map privileges 
)
static

Definition at line 1631 of file acl.c.

References ereport, errcode(), errmsg(), ERROR, priv_map::name, pfree(), pg_strcasecmp(), result, 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().

1633 {
1634  AclMode result = 0;
1635  char *priv_type = text_to_cstring(priv_type_text);
1636  char *chunk;
1637  char *next_chunk;
1638 
1639  /* We rely on priv_type being a private, modifiable string */
1640  for (chunk = priv_type; chunk; chunk = next_chunk)
1641  {
1642  int chunk_len;
1643  const priv_map *this_priv;
1644 
1645  /* Split string at commas */
1646  next_chunk = strchr(chunk, ',');
1647  if (next_chunk)
1648  *next_chunk++ = '\0';
1649 
1650  /* Drop leading/trailing whitespace in this chunk */
1651  while (*chunk && isspace((unsigned char) *chunk))
1652  chunk++;
1653  chunk_len = strlen(chunk);
1654  while (chunk_len > 0 && isspace((unsigned char) chunk[chunk_len - 1]))
1655  chunk_len--;
1656  chunk[chunk_len] = '\0';
1657 
1658  /* Match to the privileges list */
1659  for (this_priv = privileges; this_priv->name; this_priv++)
1660  {
1661  if (pg_strcasecmp(this_priv->name, chunk) == 0)
1662  {
1663  result |= this_priv->value;
1664  break;
1665  }
1666  }
1667  if (!this_priv->name)
1668  ereport(ERROR,
1669  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1670  errmsg("unrecognized privilege type: \"%s\"", chunk)));
1671  }
1672 
1673  pfree(priv_type);
1674  return result;
1675 }
Definition: acl.c:42
int errcode(int sqlerrcode)
Definition: elog.c:575
return result
Definition: formatting.c:1632
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
const char * name
Definition: acl.c:44
uint32 AclMode
Definition: parsenodes.h:70
void pfree(void *pointer)
Definition: mcxt.c:950
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
AclMode value
Definition: acl.c:45
char * text_to_cstring(const text *t)
Definition: varlena.c:182
int errmsg(const char *fmt,...)
Definition: elog.c:797
static AttrNumber convert_column_name ( Oid  tableoid,
text column 
)
static

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

2814 {
2815  AttrNumber attnum;
2816  char *colname;
2817 
2818  colname = text_to_cstring(column);
2819  attnum = get_attnum(tableoid, colname);
2820  if (attnum == InvalidAttrNumber)
2821  ereport(ERROR,
2822  (errcode(ERRCODE_UNDEFINED_COLUMN),
2823  errmsg("column \"%s\" of relation \"%s\" does not exist",
2824  colname, get_rel_name(tableoid))));
2825  pfree(colname);
2826  return attnum;
2827 }
int errcode(int sqlerrcode)
Definition: elog.c:575
void pfree(void *pointer)
Definition: mcxt.c:950
#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
static AclMode convert_column_priv_string ( text priv_type_text)
static

Definition at line 2834 of file acl.c.

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

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

2835 {
2836  static const priv_map column_priv_map[] = {
2837  {"SELECT", ACL_SELECT},
2838  {"SELECT WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_SELECT)},
2839  {"INSERT", ACL_INSERT},
2840  {"INSERT WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_INSERT)},
2841  {"UPDATE", ACL_UPDATE},
2842  {"UPDATE WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_UPDATE)},
2843  {"REFERENCES", ACL_REFERENCES},
2844  {"REFERENCES WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_REFERENCES)},
2845  {NULL, 0}
2846  };
2847 
2848  return convert_any_priv_string(priv_type_text, column_priv_map);
2849 }
Definition: acl.c:42
static AclMode convert_any_priv_string(text *priv_type_text, const priv_map *privileges)
Definition: acl.c:1631
#define ACL_UPDATE
Definition: parsenodes.h:74
#define ACL_GRANT_OPTION_FOR(privs)
Definition: acl.h:63
#define ACL_SELECT
Definition: parsenodes.h:73
#define ACL_REFERENCES
Definition: parsenodes.h:77
#define NULL
Definition: c.h:229
#define ACL_INSERT
Definition: parsenodes.h:72
static Oid convert_database_name ( text databasename)
static

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

3020 {
3021  char *dbname = text_to_cstring(databasename);
3022 
3023  return get_database_oid(dbname, false);
3024 }
Oid get_database_oid(const char *dbname, bool missing_ok)
Definition: dbcommands.c:2009
char * dbname
Definition: streamutil.c:38
char * text_to_cstring(const text *t)
Definition: varlena.c:182
static AclMode convert_database_priv_string ( text priv_type_text)
static

Definition at line 3031 of file acl.c.

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

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

3032 {
3033  static const priv_map database_priv_map[] = {
3034  {"CREATE", ACL_CREATE},
3035  {"CREATE WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_CREATE)},
3036  {"TEMPORARY", ACL_CREATE_TEMP},
3037  {"TEMPORARY WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_CREATE_TEMP)},
3038  {"TEMP", ACL_CREATE_TEMP},
3039  {"TEMP WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_CREATE_TEMP)},
3040  {"CONNECT", ACL_CONNECT},
3041  {"CONNECT WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_CONNECT)},
3042  {NULL, 0}
3043  };
3044 
3045  return convert_any_priv_string(priv_type_text, database_priv_map);
3046 
3047 }
Definition: acl.c:42
static AclMode convert_any_priv_string(text *priv_type_text, const priv_map *privileges)
Definition: acl.c:1631
#define ACL_CREATE
Definition: parsenodes.h:82
#define ACL_CONNECT
Definition: parsenodes.h:84
#define ACL_GRANT_OPTION_FOR(privs)
Definition: acl.h:63
#define NULL
Definition: c.h:229
#define ACL_CREATE_TEMP
Definition: parsenodes.h:83
static Oid convert_foreign_data_wrapper_name ( text fdwname)
static

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

3209 {
3210  char *fdwstr = text_to_cstring(fdwname);
3211 
3212  return get_foreign_data_wrapper_oid(fdwstr, false);
3213 }
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
static AclMode convert_foreign_data_wrapper_priv_string ( text priv_type_text)
static

Definition at line 3220 of file acl.c.

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

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

3221 {
3222  static const priv_map foreign_data_wrapper_priv_map[] = {
3223  {"USAGE", ACL_USAGE},
3224  {"USAGE WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_USAGE)},
3225  {NULL, 0}
3226  };
3227 
3228  return convert_any_priv_string(priv_type_text, foreign_data_wrapper_priv_map);
3229 }
Definition: acl.c:42
static AclMode convert_any_priv_string(text *priv_type_text, const priv_map *privileges)
Definition: acl.c:1631
#define ACL_USAGE
Definition: parsenodes.h:80
#define ACL_GRANT_OPTION_FOR(privs)
Definition: acl.h:63
#define NULL
Definition: c.h:229
static Oid convert_function_name ( text functionname)
static

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

3400 {
3401  char *funcname = text_to_cstring(functionname);
3402  Oid oid;
3403 
3405  CStringGetDatum(funcname)));
3406 
3407  if (!OidIsValid(oid))
3408  ereport(ERROR,
3409  (errcode(ERRCODE_UNDEFINED_FUNCTION),
3410  errmsg("function \"%s\" does not exist", funcname)));
3411 
3412  return oid;
3413 }
#define DatumGetObjectId(X)
Definition: postgres.h:506
int errcode(int sqlerrcode)
Definition: elog.c:575
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:584
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:538
#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
static AclMode convert_function_priv_string ( text priv_type_text)
static

Definition at line 3420 of file acl.c.

References ACL_EXECUTE, ACL_GRANT_OPTION_FOR, convert_any_priv_string(), and NULL.

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

3421 {
3422  static const priv_map function_priv_map[] = {
3423  {"EXECUTE", ACL_EXECUTE},
3424  {"EXECUTE WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_EXECUTE)},
3425  {NULL, 0}
3426  };
3427 
3428  return convert_any_priv_string(priv_type_text, function_priv_map);
3429 }
Definition: acl.c:42
static AclMode convert_any_priv_string(text *priv_type_text, const priv_map *privileges)
Definition: acl.c:1631
#define ACL_GRANT_OPTION_FOR(privs)
Definition: acl.h:63
#define NULL
Definition: c.h:229
#define ACL_EXECUTE
Definition: parsenodes.h:79
static Oid convert_language_name ( text languagename)
static

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

3600 {
3601  char *langname = text_to_cstring(languagename);
3602 
3603  return get_language_oid(langname, false);
3604 }
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
static AclMode convert_language_priv_string ( text priv_type_text)
static

Definition at line 3611 of file acl.c.

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

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

3612 {
3613  static const priv_map language_priv_map[] = {
3614  {"USAGE", ACL_USAGE},
3615  {"USAGE WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_USAGE)},
3616  {NULL, 0}
3617  };
3618 
3619  return convert_any_priv_string(priv_type_text, language_priv_map);
3620 }
Definition: acl.c:42
static AclMode convert_any_priv_string(text *priv_type_text, const priv_map *privileges)
Definition: acl.c:1631
#define ACL_USAGE
Definition: parsenodes.h:80
#define ACL_GRANT_OPTION_FOR(privs)
Definition: acl.h:63
#define NULL
Definition: c.h:229
static AclMode convert_priv_string ( text priv_type_text)
static

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

1582 {
1583  char *priv_type = text_to_cstring(priv_type_text);
1584 
1585  if (pg_strcasecmp(priv_type, "SELECT") == 0)
1586  return ACL_SELECT;
1587  if (pg_strcasecmp(priv_type, "INSERT") == 0)
1588  return ACL_INSERT;
1589  if (pg_strcasecmp(priv_type, "UPDATE") == 0)
1590  return ACL_UPDATE;
1591  if (pg_strcasecmp(priv_type, "DELETE") == 0)
1592  return ACL_DELETE;
1593  if (pg_strcasecmp(priv_type, "TRUNCATE") == 0)
1594  return ACL_TRUNCATE;
1595  if (pg_strcasecmp(priv_type, "REFERENCES") == 0)
1596  return ACL_REFERENCES;
1597  if (pg_strcasecmp(priv_type, "TRIGGER") == 0)
1598  return ACL_TRIGGER;
1599  if (pg_strcasecmp(priv_type, "EXECUTE") == 0)
1600  return ACL_EXECUTE;
1601  if (pg_strcasecmp(priv_type, "USAGE") == 0)
1602  return ACL_USAGE;
1603  if (pg_strcasecmp(priv_type, "CREATE") == 0)
1604  return ACL_CREATE;
1605  if (pg_strcasecmp(priv_type, "TEMP") == 0)
1606  return ACL_CREATE_TEMP;
1607  if (pg_strcasecmp(priv_type, "TEMPORARY") == 0)
1608  return ACL_CREATE_TEMP;
1609  if (pg_strcasecmp(priv_type, "CONNECT") == 0)
1610  return ACL_CONNECT;
1611  if (pg_strcasecmp(priv_type, "RULE") == 0)
1612  return 0; /* ignore old RULE privileges */
1613 
1614  ereport(ERROR,
1615  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1616  errmsg("unrecognized privilege type: \"%s\"", priv_type)));
1617  return ACL_NO_RIGHTS; /* keep compiler quiet */
1618 }
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
static AclMode convert_role_priv_string ( text priv_type_text)
static

Definition at line 4544 of file acl.c.

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

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

4545 {
4546  static const priv_map role_priv_map[] = {
4547  {"USAGE", ACL_USAGE},
4548  {"MEMBER", ACL_CREATE},
4549  {"USAGE WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_CREATE)},
4550  {"USAGE WITH ADMIN OPTION", ACL_GRANT_OPTION_FOR(ACL_CREATE)},
4551  {"MEMBER WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_CREATE)},
4552  {"MEMBER WITH ADMIN OPTION", ACL_GRANT_OPTION_FOR(ACL_CREATE)},
4553  {NULL, 0}
4554  };
4555 
4556  return convert_any_priv_string(priv_type_text, role_priv_map);
4557 }
Definition: acl.c:42
static AclMode convert_any_priv_string(text *priv_type_text, const priv_map *privileges)
Definition: acl.c:1631
#define ACL_CREATE
Definition: parsenodes.h:82
#define ACL_USAGE
Definition: parsenodes.h:80
#define ACL_GRANT_OPTION_FOR(privs)
Definition: acl.h:63
#define NULL
Definition: c.h:229
static Oid convert_schema_name ( text schemaname)
static

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

3791 {
3792  char *nspname = text_to_cstring(schemaname);
3793 
3794  return get_namespace_oid(nspname, false);
3795 }
Oid get_namespace_oid(const char *nspname, bool missing_ok)
Definition: namespace.c:2962
char * text_to_cstring(const text *t)
Definition: varlena.c:182
static AclMode convert_schema_priv_string ( text priv_type_text)
static

Definition at line 3802 of file acl.c.

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

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

3803 {
3804  static const priv_map schema_priv_map[] = {
3805  {"CREATE", ACL_CREATE},
3806  {"CREATE WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_CREATE)},
3807  {"USAGE", ACL_USAGE},
3808  {"USAGE WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_USAGE)},
3809  {NULL, 0}
3810  };
3811 
3812  return convert_any_priv_string(priv_type_text, schema_priv_map);
3813 }
Definition: acl.c:42
static AclMode convert_any_priv_string(text *priv_type_text, const priv_map *privileges)
Definition: acl.c:1631
#define ACL_CREATE
Definition: parsenodes.h:82
#define ACL_USAGE
Definition: parsenodes.h:80
#define ACL_GRANT_OPTION_FOR(privs)
Definition: acl.h:63
#define NULL
Definition: c.h:229
static AclMode convert_sequence_priv_string ( text priv_type_text)
static

Definition at line 2224 of file acl.c.

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

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

2225 {
2226  static const priv_map sequence_priv_map[] = {
2227  {"USAGE", ACL_USAGE},
2228  {"SELECT", ACL_SELECT},
2229  {"UPDATE", ACL_UPDATE},
2230  {NULL, 0}
2231  };
2232 
2233  return convert_any_priv_string(priv_type_text, sequence_priv_map);
2234 }
Definition: acl.c:42
static AclMode convert_any_priv_string(text *priv_type_text, const priv_map *privileges)
Definition: acl.c:1631
#define ACL_USAGE
Definition: parsenodes.h:80
#define ACL_UPDATE
Definition: parsenodes.h:74
#define ACL_SELECT
Definition: parsenodes.h:73
#define NULL
Definition: c.h:229
static Oid convert_server_name ( text servername)
static

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

3975 {
3976  char *serverstr = text_to_cstring(servername);
3977 
3978  return get_foreign_server_oid(serverstr, false);
3979 }
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
static AclMode convert_server_priv_string ( text priv_type_text)
static

Definition at line 3986 of file acl.c.

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

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

3987 {
3988  static const priv_map server_priv_map[] = {
3989  {"USAGE", ACL_USAGE},
3990  {"USAGE WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_USAGE)},
3991  {NULL, 0}
3992  };
3993 
3994  return convert_any_priv_string(priv_type_text, server_priv_map);
3995 }
Definition: acl.c:42
static AclMode convert_any_priv_string(text *priv_type_text, const priv_map *privileges)
Definition: acl.c:1631
#define ACL_USAGE
Definition: parsenodes.h:80
#define ACL_GRANT_OPTION_FOR(privs)
Definition: acl.h:63
#define NULL
Definition: c.h:229
static Oid convert_table_name ( text tablename)
static
static AclMode convert_table_priv_string ( text priv_type_text)
static

Definition at line 2001 of file acl.c.

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

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

2002 {
2003  static const priv_map table_priv_map[] = {
2004  {"SELECT", ACL_SELECT},
2005  {"SELECT WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_SELECT)},
2006  {"INSERT", ACL_INSERT},
2007  {"INSERT WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_INSERT)},
2008  {"UPDATE", ACL_UPDATE},
2009  {"UPDATE WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_UPDATE)},
2010  {"DELETE", ACL_DELETE},
2011  {"DELETE WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_DELETE)},
2012  {"TRUNCATE", ACL_TRUNCATE},
2013  {"TRUNCATE WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_TRUNCATE)},
2014  {"REFERENCES", ACL_REFERENCES},
2015  {"REFERENCES WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_REFERENCES)},
2016  {"TRIGGER", ACL_TRIGGER},
2017  {"TRIGGER WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_TRIGGER)},
2018  {"RULE", 0}, /* ignore old RULE privileges */
2019  {"RULE WITH GRANT OPTION", 0},
2020  {NULL, 0}
2021  };
2022 
2023  return convert_any_priv_string(priv_type_text, table_priv_map);
2024 }
Definition: acl.c:42
#define ACL_DELETE
Definition: parsenodes.h:75
static AclMode convert_any_priv_string(text *priv_type_text, const priv_map *privileges)
Definition: acl.c:1631
#define ACL_TRIGGER
Definition: parsenodes.h:78
#define ACL_UPDATE
Definition: parsenodes.h:74
#define ACL_GRANT_OPTION_FOR(privs)
Definition: acl.h:63
#define ACL_SELECT
Definition: parsenodes.h:73
#define ACL_REFERENCES
Definition: parsenodes.h:77
#define NULL
Definition: c.h:229
#define ACL_INSERT
Definition: parsenodes.h:72
#define ACL_TRUNCATE
Definition: parsenodes.h:76
static Oid convert_tablespace_name ( text tablespacename)
static

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

4157 {
4158  char *spcname = text_to_cstring(tablespacename);
4159 
4160  return get_tablespace_oid(spcname, false);
4161 }
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
static AclMode convert_tablespace_priv_string ( text priv_type_text)
static

Definition at line 4168 of file acl.c.

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

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

4169 {
4170  static const priv_map tablespace_priv_map[] = {
4171  {"CREATE", ACL_CREATE},
4172  {"CREATE WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_CREATE)},
4173  {NULL, 0}
4174  };
4175 
4176  return convert_any_priv_string(priv_type_text, tablespace_priv_map);
4177 }
Definition: acl.c:42
static AclMode convert_any_priv_string(text *priv_type_text, const priv_map *privileges)
Definition: acl.c:1631
#define ACL_CREATE
Definition: parsenodes.h:82
#define ACL_GRANT_OPTION_FOR(privs)
Definition: acl.h:63
#define NULL
Definition: c.h:229
static Oid convert_type_name ( text typename)
static

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

4347 {
4348  char *typname = text_to_cstring(typename);
4349  Oid oid;
4350 
4352  CStringGetDatum(typname)));
4353 
4354  if (!OidIsValid(oid))
4355  ereport(ERROR,
4356  (errcode(ERRCODE_UNDEFINED_OBJECT),
4357  errmsg("type \"%s\" does not exist", typname)));
4358 
4359  return oid;
4360 }
#define DatumGetObjectId(X)
Definition: postgres.h:506
int errcode(int sqlerrcode)
Definition: elog.c:575
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:584
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:538
#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
static AclMode convert_type_priv_string ( text priv_type_text)
static

Definition at line 4367 of file acl.c.

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

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

4368 {
4369  static const priv_map type_priv_map[] = {
4370  {"USAGE", ACL_USAGE},
4371  {"USAGE WITH GRANT OPTION", ACL_GRANT_OPTION_FOR(ACL_USAGE)},
4372  {NULL, 0}
4373  };
4374 
4375  return convert_any_priv_string(priv_type_text, type_priv_map);
4376 }
Definition: acl.c:42
static AclMode convert_any_priv_string(text *priv_type_text, const priv_map *privileges)
Definition: acl.c:1631
#define ACL_USAGE
Definition: parsenodes.h:80
#define ACL_GRANT_OPTION_FOR(privs)
Definition: acl.h:63
#define NULL
Definition: c.h:229
static int count_one_bits ( AclMode  mask)
static

Definition at line 4981 of file acl.c.

Referenced by select_best_grantor().

4982 {
4983  int nbits = 0;
4984 
4985  /* this code relies on AclMode being an unsigned type */
4986  while (mask)
4987  {
4988  if (mask & 1)
4989  nbits++;
4990  mask >>= 1;
4991  }
4992  return nbits;
4993 }
Oid get_role_oid ( const char *  rolname,
bool  missing_ok 
)

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

5097 {
5098  Oid oid;
5099 
5100  oid = GetSysCacheOid1(AUTHNAME, CStringGetDatum(rolname));
5101  if (!OidIsValid(oid) && !missing_ok)
5102  ereport(ERROR,
5103  (errcode(ERRCODE_UNDEFINED_OBJECT),
5104  errmsg("role \"%s\" does not exist", rolname)));
5105  return oid;
5106 }
int errcode(int sqlerrcode)
Definition: elog.c:575
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:538
#define GetSysCacheOid1(cacheId, key1)
Definition: syscache.h:183
#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
char* get_rolespec_name ( const RoleSpec role)

Definition at line 5211 of file acl.c.

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

Referenced by AddRoleMems(), and DelRoleMems().

5212 {
5213  HeapTuple tp;
5214  Form_pg_authid authForm;
5215  char *rolename;
5216 
5217  tp = get_rolespec_tuple(role);
5218  authForm = (Form_pg_authid) GETSTRUCT(tp);
5219  rolename = pstrdup(NameStr(authForm->rolname));
5220  ReleaseSysCache(tp);
5221 
5222  return rolename;
5223 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
char * pstrdup(const char *in)
Definition: mcxt.c:1077
FormData_pg_authid * Form_pg_authid
Definition: pg_authid.h:72
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1117
HeapTuple get_rolespec_tuple(const RoleSpec *role)
Definition: acl.c:5167
#define NameStr(name)
Definition: c.h:499
Oid get_rolespec_oid ( const RoleSpec role,
bool  missing_ok 
)

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

5130 {
5131  Oid oid;
5132 
5133  switch (role->roletype)
5134  {
5135  case ROLESPEC_CSTRING:
5136  Assert(role->rolename);
5137  oid = get_role_oid(role->rolename, missing_ok);
5138  break;
5139 
5140  case ROLESPEC_CURRENT_USER:
5141  oid = GetUserId();
5142  break;
5143 
5144  case ROLESPEC_SESSION_USER:
5145  oid = GetSessionUserId();
5146  break;
5147 
5148  case ROLESPEC_PUBLIC:
5149  ereport(ERROR,
5150  (errcode(ERRCODE_UNDEFINED_OBJECT),
5151  errmsg("role \"%s\" does not exist", "public")));
5152  oid = InvalidOid; /* make compiler happy */
5153  break;
5154 
5155  default:
5156  elog(ERROR, "unexpected role type %d", role->roletype);
5157  }
5158 
5159  return oid;
5160 }
Oid GetUserId(void)
Definition: miscinit.c:283
int errcode(int sqlerrcode)
Definition: elog.c:575
unsigned int Oid
Definition: postgres_ext.h:31
Oid GetSessionUserId(void)
Definition: miscinit.c:317
Oid get_role_oid(const char *rolname, bool missing_ok)
Definition: acl.c:5096
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
RoleSpecType roletype
Definition: parsenodes.h:328
#define InvalidOid
Definition: postgres_ext.h:36
#define Assert(condition)
Definition: c.h:675
char * rolename
Definition: parsenodes.h:329
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define elog
Definition: elog.h:219
HeapTuple get_rolespec_tuple ( const RoleSpec role)

Definition at line 5167 of file acl.c.

References Assert, AUTHNAME, AUTHOID, CStringGetDatum, elog, ereport, errcode(), errmsg(), ERROR, GetSessionUserId(), GetUserId(), HeapTupleIsValid, NULL, 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().

5168 {
5169  HeapTuple tuple;
5170 
5171  switch (role->roletype)
5172  {
5173  case ROLESPEC_CSTRING:
5174  Assert(role->rolename);
5176  if (!HeapTupleIsValid(tuple))
5177  ereport(ERROR,
5178  (errcode(ERRCODE_UNDEFINED_OBJECT),
5179  errmsg("role \"%s\" does not exist", role->rolename)));
5180  break;
5181 
5182  case ROLESPEC_CURRENT_USER:
5183  tuple = SearchSysCache1(AUTHOID, GetUserId());
5184  if (!HeapTupleIsValid(tuple))
5185  elog(ERROR, "cache lookup failed for role %u", GetUserId());
5186  break;
5187 
5188  case ROLESPEC_SESSION_USER:
5190  if (!HeapTupleIsValid(tuple))
5191  elog(ERROR, "cache lookup failed for role %u", GetSessionUserId());
5192  break;
5193 
5194  case ROLESPEC_PUBLIC:
5195  ereport(ERROR,
5196  (errcode(ERRCODE_UNDEFINED_OBJECT),
5197  errmsg("role \"%s\" does not exist", "public")));
5198  tuple = NULL; /* make compiler happy */
5199 
5200  default:
5201  elog(ERROR, "unexpected role type %d", role->roletype);
5202  }
5203 
5204  return tuple;
5205 }
Oid GetUserId(void)
Definition: miscinit.c:283
int errcode(int sqlerrcode)
Definition: elog.c:575
Oid GetSessionUserId(void)
Definition: miscinit.c:317
#define SearchSysCache1(cacheId, key1)
Definition: syscache.h:156
#define ERROR
Definition: elog.h:43
#define CStringGetDatum(X)
Definition: postgres.h:584
#define ereport(elevel, rest)
Definition: elog.h:122
RoleSpecType roletype
Definition: parsenodes.h:328
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
char * rolename
Definition: parsenodes.h:329
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define elog
Definition: elog.h:219
static const char * getid ( const char *  s,
char *  n 
)
static

Definition at line 136 of file acl.c.

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

Referenced by aclparse().

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

Definition at line 2343 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.

2344 {
2345  Oid tableoid = PG_GETARG_OID(0);
2346  text *priv_type_text = PG_GETARG_TEXT_PP(1);
2347  Oid roleid;
2348  AclMode mode;
2349  AclResult aclresult;
2350 
2351  roleid = GetUserId();
2352  mode = convert_column_priv_string(priv_type_text);
2353 
2355  PG_RETURN_NULL();
2356 
2357  /* First check at table level, then examine each column if needed */
2358  aclresult = pg_class_aclcheck(tableoid, roleid, mode);
2359  if (aclresult != ACLCHECK_OK)
2360  aclresult = pg_attribute_aclcheck_all(tableoid, roleid, mode,
2361  ACLMASK_ANY);
2362 
2363  PG_RETURN_BOOL(aclresult == ACLCHECK_OK);
2364 }
Oid GetUserId(void)
Definition: miscinit.c:283
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:174
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
AclResult
Definition: acl.h:170
#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:439
static AclMode convert_column_priv_string(text *priv_type_text)
Definition: acl.c:2834
#define PG_RETURN_NULL()
Definition: fmgr.h:305
Datum has_any_column_privilege_id_id ( PG_FUNCTION_ARGS  )

Definition at line 2399 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.

2400 {
2401  Oid roleid = PG_GETARG_OID(0);
2402  Oid tableoid = PG_GETARG_OID(1);
2403  text *priv_type_text = PG_GETARG_TEXT_PP(2);
2404  AclMode mode;
2405  AclResult aclresult;
2406 
2407  mode = convert_column_priv_string(priv_type_text);
2408 
2410  PG_RETURN_NULL();
2411 
2412  /* First check at table level, then examine each column if needed */
2413  aclresult = pg_class_aclcheck(tableoid, roleid, mode);
2414  if (aclresult != ACLCHECK_OK)
2415  aclresult = pg_attribute_aclcheck_all(tableoid, roleid, mode,
2416  ACLMASK_ANY);
2417 
2418  PG_RETURN_BOOL(aclresult == ACLCHECK_OK);
2419 }
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:174
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
AclResult
Definition: acl.h:170
#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:439
static AclMode convert_column_priv_string(text *priv_type_text)
Definition: acl.c:2834
#define PG_RETURN_NULL()
Definition: fmgr.h:305
Datum has_any_column_privilege_id_name ( PG_FUNCTION_ARGS  )

Definition at line 2372 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.

2373 {
2374  Oid roleid = PG_GETARG_OID(0);
2375  text *tablename = PG_GETARG_TEXT_PP(1);
2376  text *priv_type_text = PG_GETARG_TEXT_PP(2);
2377  Oid tableoid;
2378  AclMode mode;
2379  AclResult aclresult;
2380 
2381  tableoid = convert_table_name(tablename);
2382  mode = convert_column_priv_string(priv_type_text);
2383 
2384  /* First check at table level, then examine each column if needed */
2385  aclresult = pg_class_aclcheck(tableoid, roleid, mode);
2386  if (aclresult != ACLCHECK_OK)
2387  aclresult = pg_attribute_aclcheck_all(tableoid, roleid, mode,
2388  ACLMASK_ANY);
2389 
2390  PG_RETURN_BOOL(aclresult == ACLCHECK_OK);
2391 }
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:170
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
static Oid convert_table_name(text *tablename)
Definition: acl.c:1986
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:439
static AclMode convert_column_priv_string(text *priv_type_text)
Definition: acl.c:2834
Datum has_any_column_privilege_name ( PG_FUNCTION_ARGS  )

Definition at line 2284 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.

2285 {
2286  text *tablename = PG_GETARG_TEXT_PP(0);
2287  text *priv_type_text = PG_GETARG_TEXT_PP(1);
2288  Oid roleid;
2289  Oid tableoid;
2290  AclMode mode;
2291  AclResult aclresult;
2292 
2293  roleid = GetUserId();
2294  tableoid = convert_table_name(tablename);
2295  mode = convert_column_priv_string(priv_type_text);
2296 
2297  /* First check at table level, then examine each column if needed */
2298  aclresult = pg_class_aclcheck(tableoid, roleid, mode);
2299  if (aclresult != ACLCHECK_OK)
2300  aclresult = pg_attribute_aclcheck_all(tableoid, roleid, mode,
2301  ACLMASK_ANY);
2302 
2303  PG_RETURN_BOOL(aclresult == ACLCHECK_OK);
2304 }
Oid GetUserId(void)
Definition: miscinit.c:283
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:170
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
static Oid convert_table_name(text *tablename)
Definition: acl.c:1986
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:439
static AclMode convert_column_priv_string(text *priv_type_text)
Definition: acl.c:2834
Datum has_any_column_privilege_name_id ( PG_FUNCTION_ARGS  )

Definition at line 2312 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.

2313 {
2315  Oid tableoid = PG_GETARG_OID(1);
2316  text *priv_type_text = PG_GETARG_TEXT_PP(2);
2317  Oid roleid;
2318  AclMode mode;
2319  AclResult aclresult;
2320 
2321  roleid = get_role_oid_or_public(NameStr(*username));
2322  mode = convert_column_priv_string(priv_type_text);
2323 
2325  PG_RETURN_NULL();
2326 
2327  /* First check at table level, then examine each column if needed */
2328  aclresult = pg_class_aclcheck(tableoid, roleid, mode);
2329  if (aclresult != ACLCHECK_OK)
2330  aclresult = pg_attribute_aclcheck_all(tableoid, roleid, mode,
2331  ACLMASK_ANY);
2332 
2333  PG_RETURN_BOOL(aclresult == ACLCHECK_OK);
2334 }
Oid get_role_oid_or_public(const char *rolname)
Definition: acl.c:5113
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:174
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
Definition: c.h:493
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
AclResult
Definition: acl.h:170
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
static char * username
Definition: initdb.c:131
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:499
Definition: c.h:439
static AclMode convert_column_priv_string(text *priv_type_text)
Definition: acl.c:2834
#define PG_RETURN_NULL()
Definition: fmgr.h:305
#define PG_GETARG_NAME(n)
Definition: fmgr.h:243
Datum has_any_column_privilege_name_name ( PG_FUNCTION_ARGS  )

Definition at line 2254 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.

2255 {
2256  Name rolename = PG_GETARG_NAME(0);
2257  text *tablename = PG_GETARG_TEXT_PP(1);
2258  text *priv_type_text = PG_GETARG_TEXT_PP(2);
2259  Oid roleid;
2260  Oid tableoid;
2261  AclMode mode;
2262  AclResult aclresult;
2263 
2264  roleid = get_role_oid_or_public(NameStr(*rolename));
2265  tableoid = convert_table_name(tablename);
2266  mode = convert_column_priv_string(priv_type_text);
2267 
2268  /* First check at table level, then examine each column if needed */
2269  aclresult = pg_class_aclcheck(tableoid, roleid, mode);
2270  if (aclresult != ACLCHECK_OK)
2271  aclresult = pg_attribute_aclcheck_all(tableoid, roleid, mode,
2272  ACLMASK_ANY);
2273 
2274  PG_RETURN_BOOL(aclresult == ACLCHECK_OK);
2275 }
Oid get_role_oid_or_public(const char *rolname)
Definition: acl.c:5113
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:493
AclResult
Definition: acl.h:170
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
static Oid convert_table_name(text *tablename)
Definition: acl.c:1986
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:499
Definition: c.h:439
static AclMode convert_column_priv_string(text *priv_type_text)
Definition: acl.c:2834
#define PG_GETARG_NAME(n)
Definition: fmgr.h:243
Datum has_column_privilege_id_attnum ( PG_FUNCTION_ARGS  )

Definition at line 2786 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.

2787 {
2788  Oid tableoid = PG_GETARG_OID(0);
2789  AttrNumber colattnum = PG_GETARG_INT16(1);
2790  text *priv_type_text = PG_GETARG_TEXT_PP(2);
2791  Oid roleid;
2792  AclMode mode;
2793  int privresult;
2794 
2795  roleid = GetUserId();
2796  mode = convert_column_priv_string(priv_type_text);
2797 
2798  privresult = column_privilege_check(tableoid, colattnum, roleid, mode);
2799  if (privresult < 0)
2800  PG_RETURN_NULL();
2801  PG_RETURN_BOOL(privresult);
2802 }
Oid GetUserId(void)
Definition: miscinit.c:283
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:2442
Definition: c.h:439
static AclMode convert_column_priv_string(text *priv_type_text)
Definition: acl.c:2834
int16 AttrNumber
Definition: attnum.h:21
#define PG_RETURN_NULL()
Definition: fmgr.h:305
Datum has_column_privilege_id_id_attnum ( PG_FUNCTION_ARGS  )

Definition at line 2679 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.

2680 {
2681  Oid roleid = PG_GETARG_OID(0);
2682  Oid tableoid = PG_GETARG_OID(1);
2683  AttrNumber colattnum = PG_GETARG_INT16(2);
2684  text *priv_type_text = PG_GETARG_TEXT_PP(3);
2685  AclMode mode;
2686  int privresult;
2687 
2688  mode = convert_column_priv_string(priv_type_text);
2689 
2690  privresult = column_privilege_check(tableoid, colattnum, roleid, mode);
2691  if (privresult < 0)
2692  PG_RETURN_NULL();
2693  PG_RETURN_BOOL(privresult);
2694 }
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:2442
Definition: c.h:439
static AclMode convert_column_priv_string(text *priv_type_text)
Definition: acl.c:2834
int16 AttrNumber
Definition: attnum.h:21
#define PG_RETURN_NULL()
Definition: fmgr.h:305
Datum has_column_privilege_id_id_name ( PG_FUNCTION_ARGS  )

Definition at line 2654 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.

2655 {
2656  Oid roleid = PG_GETARG_OID(0);
2657  Oid tableoid = PG_GETARG_OID(1);
2658  text *column = PG_GETARG_TEXT_PP(2);
2659  text *priv_type_text = PG_GETARG_TEXT_PP(3);
2660  AttrNumber colattnum;
2661  AclMode mode;
2662  int privresult;
2663 
2664  colattnum = convert_column_name(tableoid, column);
2665  mode = convert_column_priv_string(priv_type_text);
2666 
2667  privresult = column_privilege_check(tableoid, colattnum, roleid, mode);
2668  if (privresult < 0)
2669  PG_RETURN_NULL();
2670  PG_RETURN_BOOL(privresult);
2671 }
static AttrNumber convert_column_name(Oid tableoid, text *column)
Definition: acl.c:2813
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:2442
Definition: c.h:439
static AclMode convert_column_priv_string(text *priv_type_text)
Definition: acl.c:2834
int16 AttrNumber
Definition: attnum.h:21
#define PG_RETURN_NULL()
Definition: fmgr.h:305
Datum has_column_privilege_id_name ( PG_FUNCTION_ARGS  )

Definition at line 2759 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.

2760 {
2761  Oid tableoid = PG_GETARG_OID(0);
2762  text *column = PG_GETARG_TEXT_PP(1);
2763  text *priv_type_text = PG_GETARG_TEXT_PP(2);
2764  Oid roleid;
2765  AttrNumber colattnum;
2766  AclMode mode;
2767  int privresult;
2768 
2769  roleid = GetUserId();
2770  colattnum = convert_column_name(tableoid, column);
2771  mode = convert_column_priv_string(priv_type_text);
2772 
2773  privresult = column_privilege_check(tableoid, colattnum, roleid, mode);
2774  if (privresult < 0)
2775  PG_RETURN_NULL();
2776  PG_RETURN_BOOL(privresult);
2777 }
static AttrNumber convert_column_name(Oid tableoid, text *column)
Definition: acl.c:2813
Oid GetUserId(void)
Definition: miscinit.c:283
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:2442
Definition: c.h:439
static AclMode convert_column_priv_string(text *priv_type_text)
Definition: acl.c:2834
int16 AttrNumber
Definition: attnum.h:21
#define PG_RETURN_NULL()
Definition: fmgr.h:305
Datum has_column_privilege_id_name_attnum ( PG_FUNCTION_ARGS  )

Definition at line 2629 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.

2630 {
2631  Oid roleid = PG_GETARG_OID(0);
2632  text *tablename = PG_GETARG_TEXT_PP(1);
2633  AttrNumber colattnum = PG_GETARG_INT16(2);
2634  text *priv_type_text = PG_GETARG_TEXT_PP(3);
2635  Oid tableoid;
2636  AclMode mode;
2637  int privresult;
2638 
2639  tableoid = convert_table_name(tablename);
2640  mode = convert_column_priv_string(priv_type_text);
2641 
2642  privresult = column_privilege_check(tableoid, colattnum, roleid, mode);
2643  if (privresult < 0)
2644  PG_RETURN_NULL();
2645  PG_RETURN_BOOL(privresult);
2646 }
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:1986
static int column_privilege_check(Oid tableoid, AttrNumber attnum, Oid roleid, AclMode mode)
Definition: acl.c:2442
Definition: c.h:439
static AclMode convert_column_priv_string(text *priv_type_text)
Definition: acl.c:2834
int16 AttrNumber
Definition: attnum.h:21
#define PG_RETURN_NULL()
Definition: fmgr.h:305
Datum has_column_privilege_id_name_name ( PG_FUNCTION_ARGS  )

Definition at line 2602 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.

2603 {
2604  Oid roleid = PG_GETARG_OID(0);
2605  text *tablename = PG_GETARG_TEXT_PP(1);
2606  text *column = PG_GETARG_TEXT_PP(2);
2607  text *priv_type_text = PG_GETARG_TEXT_PP(3);
2608  Oid tableoid;
2609  AttrNumber colattnum;
2610  AclMode mode;
2611  int privresult;
2612 
2613  tableoid = convert_table_name(tablename);
2614  colattnum = convert_column_name(tableoid, column);
2615  mode = convert_column_priv_string(priv_type_text);
2616 
2617  privresult = column_privilege_check(tableoid, colattnum, roleid, mode);
2618  if (privresult < 0)
2619  PG_RETURN_NULL();
2620  PG_RETURN_BOOL(privresult);
2621 }
static AttrNumber convert_column_name(Oid tableoid, text *column)
Definition: acl.c:2813
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:1986
static int column_privilege_check(Oid tableoid, AttrNumber attnum, Oid roleid, AclMode mode)
Definition: acl.c:2442
Definition: c.h:439
static AclMode convert_column_priv_string(text *priv_type_text)
Definition: acl.c:2834
int16 AttrNumber
Definition: attnum.h:21
#define PG_RETURN_NULL()
Definition: fmgr.h:305
Datum has_column_privilege_name_attnum ( PG_FUNCTION_ARGS  )

Definition at line 2732 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.

2733 {
2734  text *tablename = PG_GETARG_TEXT_PP(0);
2735  AttrNumber colattnum = PG_GETARG_INT16(1);
2736  text *priv_type_text = PG_GETARG_TEXT_PP(2);
2737  Oid roleid;
2738  Oid tableoid;
2739  AclMode mode;
2740  int privresult;
2741 
2742  roleid = GetUserId();
2743  tableoid = convert_table_name(tablename);
2744  mode = convert_column_priv_string(priv_type_text);
2745 
2746  privresult = column_privilege_check(tableoid, colattnum, roleid, mode);
2747  if (privresult < 0)
2748  PG_RETURN_NULL();
2749  PG_RETURN_BOOL(privresult);
2750 }
Oid GetUserId(void)
Definition: miscinit.c:283
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:1986
static int column_privilege_check(Oid tableoid, AttrNumber attnum, Oid roleid, AclMode mode)
Definition: acl.c:2442
Definition: c.h:439
static AclMode convert_column_priv_string(text *priv_type_text)
Definition: acl.c:2834
int16 AttrNumber
Definition: attnum.h:21
#define PG_RETURN_NULL()
Definition: fmgr.h:305
Datum has_column_privilege_name_id_attnum ( PG_FUNCTION_ARGS  )

Definition at line 2577 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.

2578 {
2580  Oid tableoid = PG_GETARG_OID(1);
2581  AttrNumber colattnum = PG_GETARG_INT16(2);
2582  text *priv_type_text = PG_GETARG_TEXT_PP(3);
2583  Oid roleid;
2584  AclMode mode;
2585  int privresult;
2586 
2587  roleid = get_role_oid_or_public(NameStr(*username));
2588  mode = convert_column_priv_string(priv_type_text);
2589 
2590  privresult = column_privilege_check(tableoid, colattnum, roleid, mode);
2591  if (privresult < 0)
2592  PG_RETURN_NULL();
2593  PG_RETURN_BOOL(privresult);
2594 }
Oid get_role_oid_or_public(const char *rolname)
Definition: acl.c:5113
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:493
#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:131
static int column_privilege_check(Oid tableoid, AttrNumber attnum, Oid roleid, AclMode mode)
Definition: acl.c:2442
#define NameStr(name)
Definition: c.h:499
Definition: c.h:439
static AclMode convert_column_priv_string(text *priv_type_text)
Definition: acl.c:2834
int16 AttrNumber
Definition: attnum.h:21
#define PG_RETURN_NULL()
Definition: fmgr.h:305
#define PG_GETARG_NAME(n)
Definition: fmgr.h:243
Datum has_column_privilege_name_id_name ( PG_FUNCTION_ARGS  )

Definition at line 2550 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.

2551 {
2553  Oid tableoid = PG_GETARG_OID(1);
2554  text *column = PG_GETARG_TEXT_PP(2);
2555  text *priv_type_text = PG_GETARG_TEXT_PP(3);
2556  Oid roleid;
2557  AttrNumber colattnum;
2558  AclMode mode;
2559  int privresult;
2560 
2561  roleid = get_role_oid_or_public(NameStr(*username));
2562  colattnum = convert_column_name(tableoid, column);
2563  mode = convert_column_priv_string(priv_type_text);
2564 
2565  privresult = column_privilege_check(tableoid, colattnum, roleid, mode);
2566  if (privresult < 0)
2567  PG_RETURN_NULL();
2568  PG_RETURN_BOOL(privresult);
2569 }
static AttrNumber convert_column_name(Oid tableoid, text *column)
Definition: acl.c:2813
Oid get_role_oid_or_public(const char *rolname)
Definition: acl.c:5113
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:493
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
static char * username
Definition: initdb.c:131
static int column_privilege_check(Oid tableoid, AttrNumber attnum, Oid roleid, AclMode mode)
Definition: acl.c:2442
#define NameStr(name)
Definition: c.h:499
Definition: c.h:439
static AclMode convert_column_priv_string(text *priv_type_text)
Definition: acl.c:2834
int16 AttrNumber
Definition: attnum.h:21
#define PG_RETURN_NULL()
Definition: fmgr.h:305
#define PG_GETARG_NAME(n)
Definition: fmgr.h:243
Datum has_column_privilege_name_name ( PG_FUNCTION_ARGS  )

Definition at line 2703 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.

2704 {
2705  text *tablename = PG_GETARG_TEXT_PP(0);
2706  text *column = PG_GETARG_TEXT_PP(1);
2707  text *priv_type_text = PG_GETARG_TEXT_PP(2);
2708  Oid roleid;
2709  Oid tableoid;
2710  AttrNumber colattnum;
2711  AclMode mode;
2712  int privresult;
2713 
2714  roleid = GetUserId();
2715  tableoid = convert_table_name(tablename);
2716  colattnum = convert_column_name(tableoid, column);
2717  mode = convert_column_priv_string(priv_type_text);
2718 
2719  privresult = column_privilege_check(tableoid, colattnum, roleid, mode);
2720  if (privresult < 0)
2721  PG_RETURN_NULL();
2722  PG_RETURN_BOOL(privresult);
2723 }
static AttrNumber convert_column_name(Oid tableoid, text *column)
Definition: acl.c:2813
Oid GetUserId(void)
Definition: miscinit.c:283
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:1986
static int column_privilege_check(Oid tableoid, AttrNumber attnum, Oid roleid, AclMode mode)
Definition: acl.c:2442
Definition: c.h:439
static AclMode convert_column_priv_string(text *priv_type_text)
Definition: acl.c:2834
int16 AttrNumber
Definition: attnum.h:21
#define PG_RETURN_NULL()
Definition: fmgr.h:305
Datum has_column_privilege_name_name_attnum ( PG_FUNCTION_ARGS  )

Definition at line 2523 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.

2524 {
2525  Name rolename = PG_GETARG_NAME(0);
2526  text *tablename = PG_GETARG_TEXT_PP(1);
2527  AttrNumber colattnum = PG_GETARG_INT16(2);
2528  text *priv_type_text = PG_GETARG_TEXT_PP(3);
2529  Oid roleid;
2530  Oid tableoid;
2531  AclMode mode;
2532  int privresult;
2533 
2534  roleid = get_role_oid_or_public(NameStr(*rolename));
2535  tableoid = convert_table_name(tablename);
2536  mode = convert_column_priv_string(priv_type_text);
2537 
2538  privresult = column_privilege_check(tableoid, colattnum, roleid, mode);
2539  if (privresult < 0)
2540  PG_RETURN_NULL();
2541  PG_RETURN_BOOL(privresult);
2542 }
Oid get_role_oid_or_public(const char *rolname)
Definition: acl.c:5113
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:493
#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:1986
static int column_privilege_check(Oid tableoid, AttrNumber attnum, Oid roleid, AclMode mode)
Definition: acl.c:2442
#define NameStr(name)
Definition: c.h:499
Definition: c.h:439
static AclMode convert_column_priv_string(text *priv_type_text)
Definition: acl.c:2834
int16 AttrNumber
Definition: attnum.h:21
#define PG_RETURN_NULL()
Definition: fmgr.h:305
#define PG_GETARG_NAME(n)
Definition: fmgr.h:243
Datum has_column_privilege_name_name_name ( PG_FUNCTION_ARGS  )

Definition at line 2494 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.

2495 {
2496  Name rolename = PG_GETARG_NAME(0);
2497  text *tablename = PG_GETARG_TEXT_PP(1);
2498  text *column = PG_GETARG_TEXT_PP(2);
2499  text *priv_type_text = PG_GETARG_TEXT_PP(3);
2500  Oid roleid;
2501  Oid tableoid;
2502  AttrNumber colattnum;
2503  AclMode mode;
2504  int privresult;
2505 
2506  roleid = get_role_oid_or_public(NameStr(*rolename));
2507  tableoid = convert_table_name(tablename);
2508  colattnum = convert_column_name(tableoid, column);
2509  mode = convert_column_priv_string(priv_type_text);
2510 
2511  privresult = column_privilege_check(tableoid, colattnum, roleid, mode);
2512  if (privresult < 0)
2513  PG_RETURN_NULL();
2514  PG_RETURN_BOOL(privresult);
2515 }
static AttrNumber convert_column_name(Oid tableoid, text *column)
Definition: acl.c:2813
Oid get_role_oid_or_public(const char *rolname)
Definition: acl.c:5113
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:493
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
static Oid convert_table_name(text *tablename)
Definition: acl.c:1986
static int column_privilege_check(Oid tableoid, AttrNumber attnum, Oid roleid, AclMode mode)
Definition: acl.c:2442
#define NameStr(name)
Definition: c.h:499
Definition: c.h:439
static AclMode convert_column_priv_string(text *priv_type_text)
Definition: acl.c:2834
int16 AttrNumber
Definition: attnum.h:21
#define PG_RETURN_NULL()
Definition: fmgr.h:305
#define PG_GETARG_NAME(n)
Definition: fmgr.h:243
Datum has_database_privilege_id ( PG_FUNCTION_ARGS  )

Definition at line 2945 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.

2946 {
2947  Oid databaseoid = PG_GETARG_OID(0);
2948  text *priv_type_text = PG_GETARG_TEXT_PP(1);
2949  Oid roleid;
2950  AclMode mode;
2951  AclResult aclresult;
2952 
2953  roleid = GetUserId();
2954  mode = convert_database_priv_string(priv_type_text);
2955 
2957  PG_RETURN_NULL();
2958 
2959  aclresult = pg_database_aclcheck(databaseoid, roleid, mode);
2960 
2961  PG_RETURN_BOOL(aclresult == ACLCHECK_OK);
2962 }
Oid GetUserId(void)
Definition: miscinit.c:283
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:174
#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:3031
AclResult
Definition: acl.h:170
#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:439
#define PG_RETURN_NULL()
Definition: fmgr.h:305
Datum has_database_privilege_id_id ( PG_FUNCTION_ARGS  )

Definition at line 2993 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.

2994 {
2995  Oid roleid = PG_GETARG_OID(0);
2996  Oid databaseoid = PG_GETARG_OID(1);
2997  text *priv_type_text = PG_GETARG_TEXT_PP(2);
2998  AclMode mode;
2999  AclResult aclresult;
3000 
3001  mode = convert_database_priv_string(priv_type_text);
3002 
3004  PG_RETURN_NULL();
3005 
3006  aclresult = pg_database_aclcheck(databaseoid, roleid, mode);
3007 
3008  PG_RETURN_BOOL(aclresult == ACLCHECK_OK);
3009 }
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:174
#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:3031
AclResult
Definition: acl.h:170
#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:439
#define PG_RETURN_NULL()
Definition: fmgr.h:305
Datum has_database_privilege_id_name ( PG_FUNCTION_ARGS  )

Definition at line 2970 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.

2971 {
2972  Oid roleid = PG_GETARG_OID(0);
2973  text *databasename = PG_GETARG_TEXT_PP(1);
2974  text *priv_type_text = PG_GETARG_TEXT_PP(2);
2975  Oid databaseoid;
2976  AclMode mode;
2977  AclResult aclresult;
2978 
2979  databaseoid = convert_database_name(databasename);
2980  mode = convert_database_priv_string(priv_type_text);
2981 
2982  aclresult = pg_database_aclcheck(databaseoid, roleid, mode);
2983 
2984  PG_RETURN_BOOL(aclresult == ACLCHECK_OK);
2985 }
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:3019
static AclMode convert_database_priv_string(text *priv_type_text)
Definition: acl.c:3031
AclResult
Definition: acl.h:170
#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:439
Datum has_database_privilege_name ( PG_FUNCTION_ARGS  )

Definition at line 2894 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.

2895 {
2896  text *databasename = PG_GETARG_TEXT_PP(0);
2897  text *priv_type_text = PG_GETARG_TEXT_PP(1);
2898  Oid roleid;
2899  Oid databaseoid;
2900  AclMode mode;
2901  AclResult aclresult;
2902 
2903  roleid = GetUserId();
2904  databaseoid = convert_database_name(databasename);
2905  mode = convert_database_priv_string(priv_type_text);
2906 
2907  aclresult = pg_database_aclcheck(databaseoid, roleid, mode);
2908 
2909  PG_RETURN_BOOL(aclresult == ACLCHECK_OK);
2910 }
Oid GetUserId(void)
Definition: miscinit.c:283
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:3019
static AclMode convert_database_priv_string(text *priv_type_text)
Definition: acl.c:3031
AclResult
Definition: acl.h:170
#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:439
Datum has_database_privilege_name_id ( PG_FUNCTION_ARGS  )

Definition at line 2918 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.

2919 {
2921  Oid databaseoid = PG_GETARG_OID(1);
2922  text *priv_type_text = PG_GETARG_TEXT_PP(2);
2923  Oid roleid;
2924  AclMode mode;
2925  AclResult aclresult;
2926 
2927  roleid = get_role_oid_or_public(NameStr(*username));
2928  mode = convert_database_priv_string(priv_type_text);
2929 
2931  PG_RETURN_NULL();
2932 
2933  aclresult = pg_database_aclcheck(databaseoid, roleid, mode);
2934 
2935  PG_RETURN_BOOL(aclresult == ACLCHECK_OK);
2936 }
Oid get_role_oid_or_public(const char *rolname)
Definition: acl.c:5113
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:174
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
Definition: c.h:493
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
static AclMode convert_database_priv_string(text *priv_type_text)
Definition: acl.c:3031
AclResult
Definition: acl.h:170
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
static char * username
Definition: initdb.c:131
AclResult pg_database_aclcheck(Oid db_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4434
#define NameStr(name)
Definition: c.h:499
Definition: c.h:439
#define PG_RETURN_NULL()
Definition: fmgr.h:305
#define PG_GETARG_NAME(n)
Definition: fmgr.h:243
Datum has_database_privilege_name_name ( PG_FUNCTION_ARGS  )

Definition at line 2868 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.

2869 {
2871  text *databasename = PG_GETARG_TEXT_PP(1);
2872  text *priv_type_text = PG_GETARG_TEXT_PP(2);
2873  Oid roleid;
2874  Oid databaseoid;
2875  AclMode mode;
2876  AclResult aclresult;
2877 
2878  roleid = get_role_oid_or_public(NameStr(*username));
2879  databaseoid = convert_database_name(databasename);
2880  mode = convert_database_priv_string(priv_type_text);
2881 
2882  aclresult = pg_database_aclcheck(databaseoid, roleid, mode);
2883 
2884  PG_RETURN_BOOL(aclresult == ACLCHECK_OK);
2885 }
Oid get_role_oid_or_public(const char *rolname)
Definition: acl.c:5113
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:493
static Oid convert_database_name(text *databasename)
Definition: acl.c:3019
static AclMode convert_database_priv_string(text *priv_type_text)
Definition: acl.c:3031
AclResult
Definition: acl.h:170
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
static char * username
Definition: initdb.c:131
AclResult pg_database_aclcheck(Oid db_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4434
#define NameStr(name)
Definition: c.h:499
Definition: c.h:439
#define PG_GETARG_NAME(n)
Definition: fmgr.h:243
Datum has_foreign_data_wrapper_privilege_id ( PG_FUNCTION_ARGS  )

Definition at line 3140 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.

3141 {
3142  Oid fdwid = PG_GETARG_OID(0);
3143  text *priv_type_text = PG_GETARG_TEXT_PP(1);
3144  Oid roleid;
3145  AclMode mode;
3146  AclResult aclresult;
3147 
3148  roleid = GetUserId();
3149  mode = convert_foreign_data_wrapper_priv_string(priv_type_text);
3150 
3151  aclresult = pg_foreign_data_wrapper_aclcheck(fdwid, roleid, mode);
3152 
3153  PG_RETURN_BOOL(aclresult == ACLCHECK_OK);
3154 }
Oid GetUserId(void)
Definition: miscinit.c:283
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:170
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
static AclMode convert_foreign_data_wrapper_priv_string(text *priv_type_text)
Definition: acl.c:3220
Definition: c.h:439
Datum has_foreign_data_wrapper_privilege_id_id ( PG_FUNCTION_ARGS  )

Definition at line 3185 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.

3186 {
3187  Oid roleid = PG_GETARG_OID(0);
3188  Oid fdwid = PG_GETARG_OID(1);
3189  text *priv_type_text = PG_GETARG_TEXT_PP(2);
3190  AclMode mode;
3191  AclResult aclresult;
3192 
3193  mode = convert_foreign_data_wrapper_priv_string(priv_type_text);
3194 
3195  aclresult = pg_foreign_data_wrapper_aclcheck(fdwid, roleid, mode);
3196 
3197  PG_RETURN_BOOL(aclresult == ACLCHECK_OK);
3198 }
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:170
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
static AclMode convert_foreign_data_wrapper_priv_string(text *priv_type_text)
Definition: acl.c:3220
Definition: c.h:439
Datum has_foreign_data_wrapper_privilege_id_name ( PG_FUNCTION_ARGS  )

Definition at line 3162 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.

3163 {
3164  Oid roleid = PG_GETARG_OID(0);
3165  text *fdwname = PG_GETARG_TEXT_PP(1);
3166  text *priv_type_text = PG_GETARG_TEXT_PP(2);
3167  Oid fdwid;
3168  AclMode mode;
3169  AclResult aclresult;
3170 
3171  fdwid = convert_foreign_data_wrapper_name(fdwname);
3172  mode = convert_foreign_data_wrapper_priv_string(priv_type_text);
3173 
3174  aclresult = pg_foreign_data_wrapper_aclcheck(fdwid, roleid, mode);
3175 
3176  PG_RETURN_BOOL(aclresult == ACLCHECK_OK);
3177 }
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:3208
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:170
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
static AclMode convert_foreign_data_wrapper_priv_string(text *priv_type_text)
Definition: acl.c:3220
Definition: c.h:439
Datum has_foreign_data_wrapper_privilege_name ( PG_FUNCTION_ARGS  )

Definition at line 3092 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.

3093 {
3094  text *fdwname = PG_GETARG_TEXT_PP(0);
3095  text *priv_type_text = PG_GETARG_TEXT_PP(1);
3096  Oid roleid;
3097  Oid fdwid;
3098  AclMode mode;
3099  AclResult aclresult;
3100 
3101  roleid = GetUserId();
3102  fdwid = convert_foreign_data_wrapper_name(fdwname);
3103  mode = convert_foreign_data_wrapper_priv_string(priv_type_text);
3104 
3105  aclresult = pg_foreign_data_wrapper_aclcheck(fdwid, roleid, mode);
3106 
3107  PG_RETURN_BOOL(aclresult == ACLCHECK_OK);
3108 }
Oid GetUserId(void)
Definition: miscinit.c:283
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:3208
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:170
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
static AclMode convert_foreign_data_wrapper_priv_string(text *priv_type_text)
Definition: acl.c:3220
Definition: c.h:439
Datum has_foreign_data_wrapper_privilege_name_id ( PG_FUNCTION_ARGS  )

Definition at line 3116 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.

3117 {
3119  Oid fdwid = PG_GETARG_OID(1);
3120  text *priv_type_text = PG_GETARG_TEXT_PP(2);
3121  Oid roleid;
3122  AclMode mode;
3123  AclResult aclresult;
3124 
3125  roleid = get_role_oid_or_public(NameStr(*username));
3126  mode = convert_foreign_data_wrapper_priv_string(priv_type_text);
3127 
3128  aclresult = pg_foreign_data_wrapper_aclcheck(fdwid, roleid, mode);
3129 
3130  PG_RETURN_BOOL(aclresult == ACLCHECK_OK);
3131 }
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:5113
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:493
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
AclResult
Definition: acl.h:170
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
static char * username
Definition: initdb.c:131
static AclMode convert_foreign_data_wrapper_priv_string(text *priv_type_text)
Definition: acl.c:3220
#define NameStr(name)
Definition: c.h:499
Definition: c.h:439
#define PG_GETARG_NAME(n)
Definition: fmgr.h:243
Datum has_foreign_data_wrapper_privilege_name_name ( PG_FUNCTION_ARGS  )

Definition at line 3066 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.

3067 {
3069  text *fdwname = PG_GETARG_TEXT_PP(1);
3070  text *priv_type_text = PG_GETARG_TEXT_PP(2);
3071  Oid roleid;
3072  Oid fdwid;
3073  AclMode mode;
3074  AclResult aclresult;
3075 
3076  roleid = get_role_oid_or_public(NameStr(*username));
3077  fdwid = convert_foreign_data_wrapper_name(fdwname);
3078  mode = convert_foreign_data_wrapper_priv_string(priv_type_text);
3079 
3080  aclresult = pg_foreign_data_wrapper_aclcheck(fdwid, roleid, mode);
3081 
3082  PG_RETURN_BOOL(aclresult == ACLCHECK_OK);
3083 }
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:3208
Oid get_role_oid_or_public(const char *rolname)
Definition: acl.c:5113
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:493
AclResult
Definition: acl.h:170
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
static char * username
Definition: initdb.c:131
static AclMode convert_foreign_data_wrapper_priv_string(text *priv_type_text)
Definition: acl.c:3220
#define NameStr(name)
Definition: c.h:499
Definition: c.h:439
#define PG_GETARG_NAME(n)
Definition: fmgr.h:243
Datum has_function_privilege_id ( PG_FUNCTION_ARGS  )

Definition at line 3325 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.

3326 {
3327  Oid functionoid = PG_GETARG_OID(0);
3328  text *priv_type_text = PG_GETARG_TEXT_PP(1);
3329  Oid roleid;
3330  AclMode mode;
3331  AclResult aclresult;
3332 
3333  roleid = GetUserId();
3334  mode = convert_function_priv_string(priv_type_text);
3335 
3336  if (!SearchSysCacheExists1(PROCOID, ObjectIdGetDatum(functionoid)))
3337  PG_RETURN_NULL();
3338 
3339  aclresult = pg_proc_aclcheck(functionoid, roleid, mode);
3340 
3341  PG_RETURN_BOOL(aclresult == ACLCHECK_OK);
3342 }
Oid GetUserId(void)
Definition: miscinit.c:283
static AclMode convert_function_priv_string(text *priv_type_text)
Definition: acl.c:3420
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:174
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
AclResult
Definition: acl.h:170
#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:439
#define PG_RETURN_NULL()
Definition: fmgr.h:305
Datum has_function_privilege_id_id ( PG_FUNCTION_ARGS  )

Definition at line 3373 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.

3374 {
3375  Oid roleid = PG_GETARG_OID(0);
3376  Oid functionoid = PG_GETARG_OID(1);
3377  text *priv_type_text = PG_GETARG_TEXT_PP(2);
3378  AclMode mode;
3379  AclResult aclresult;
3380 
3381  mode = convert_function_priv_string(priv_type_text);
3382 
3383  if (!SearchSysCacheExists1(PROCOID, ObjectIdGetDatum(functionoid)))
3384  PG_RETURN_NULL();
3385 
3386  aclresult = pg_proc_aclcheck(functionoid, roleid, mode);
3387 
3388  PG_RETURN_BOOL(aclresult == ACLCHECK_OK);
3389 }
static AclMode convert_function_priv_string(text *priv_type_text)
Definition: acl.c:3420
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:174
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
AclResult
Definition: acl.h:170
#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:439
#define PG_RETURN_NULL()
Definition: fmgr.h:305
Datum has_function_privilege_id_name ( PG_FUNCTION_ARGS  )

Definition at line 3350 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.

3351 {
3352  Oid roleid = PG_GETARG_OID(0);
3353  text *functionname = PG_GETARG_TEXT_PP(1);
3354  text *priv_type_text = PG_GETARG_TEXT_PP(2);
3355  Oid functionoid;
3356  AclMode mode;
3357  AclResult aclresult;
3358 
3359  functionoid = convert_function_name(functionname);
3360  mode = convert_function_priv_string(priv_type_text);
3361 
3362  aclresult = pg_proc_aclcheck(functionoid, roleid, mode);
3363 
3364  PG_RETURN_BOOL(aclresult == ACLCHECK_OK);
3365 }
static AclMode convert_function_priv_string(text *priv_type_text)
Definition: acl.c:3420
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:170
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
static Oid convert_function_name(text *functionname)
Definition: acl.c:3399
AclResult pg_proc_aclcheck(Oid proc_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4446
Definition: c.h:439
Datum has_function_privilege_name ( PG_FUNCTION_ARGS  )

Definition at line 3274 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.

3275 {
3276  text *functionname = PG_GETARG_TEXT_PP(0);
3277  text *priv_type_text = PG_GETARG_TEXT_PP(1);
3278  Oid roleid;
3279  Oid functionoid;
3280  AclMode mode;
3281  AclResult aclresult;
3282 
3283  roleid = GetUserId();
3284  functionoid = convert_function_name(functionname);
3285  mode = convert_function_priv_string(priv_type_text);
3286 
3287  aclresult = pg_proc_aclcheck(functionoid, roleid, mode);
3288 
3289  PG_RETURN_BOOL(aclresult == ACLCHECK_OK);
3290 }
Oid GetUserId(void)
Definition: miscinit.c:283
static AclMode convert_function_priv_string(text *priv_type_text)
Definition: acl.c:3420
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:170
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319