PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
acl.h File Reference
#include "access/htup.h"
#include "nodes/parsenodes.h"
#include "parser/parse_node.h"
#include "utils/array.h"
#include "utils/snapshot.h"
Include dependency graph for acl.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  AclItem
 

Macros

#define ACL_ID_PUBLIC   0 /* placeholder for id in a PUBLIC acl item */
 
#define ACLITEM_GET_PRIVS(item)   ((item).ai_privs & 0xFFFF)
 
#define ACLITEM_GET_GOPTIONS(item)   (((item).ai_privs >> 16) & 0xFFFF)
 
#define ACLITEM_GET_RIGHTS(item)   ((item).ai_privs)
 
#define ACL_GRANT_OPTION_FOR(privs)   (((AclMode) (privs) & 0xFFFF) << 16)
 
#define ACL_OPTION_TO_PRIVS(privs)   (((AclMode) (privs) >> 16) & 0xFFFF)
 
#define ACLITEM_SET_PRIVS(item, privs)
 
#define ACLITEM_SET_GOPTIONS(item, goptions)
 
#define ACLITEM_SET_RIGHTS(item, rights)   ((item).ai_privs = (AclMode) (rights))
 
#define ACLITEM_SET_PRIVS_GOPTIONS(item, privs, goptions)
 
#define ACLITEM_ALL_PRIV_BITS   ((AclMode) 0xFFFF)
 
#define ACLITEM_ALL_GOPTION_BITS   ((AclMode) 0xFFFF << 16)
 
#define ACL_NUM(ACL)   (ARR_DIMS(ACL)[0])
 
#define ACL_DAT(ACL)   ((AclItem *) ARR_DATA_PTR(ACL))
 
#define ACL_N_SIZE(N)   (ARR_OVERHEAD_NONULLS(1) + ((N) * sizeof(AclItem)))
 
#define ACL_SIZE(ACL)   ARR_SIZE(ACL)
 
#define DatumGetAclItemP(X)   ((AclItem *) DatumGetPointer(X))
 
#define PG_GETARG_ACLITEM_P(n)   DatumGetAclItemP(PG_GETARG_DATUM(n))
 
#define PG_RETURN_ACLITEM_P(x)   PG_RETURN_POINTER(x)
 
#define DatumGetAclP(X)   ((Acl *) PG_DETOAST_DATUM(X))
 
#define DatumGetAclPCopy(X)   ((Acl *) PG_DETOAST_DATUM_COPY(X))
 
#define PG_GETARG_ACL_P(n)   DatumGetAclP(PG_GETARG_DATUM(n))
 
#define PG_GETARG_ACL_P_COPY(n)   DatumGetAclPCopy(PG_GETARG_DATUM(n))
 
#define PG_RETURN_ACL_P(x)   PG_RETURN_POINTER(x)
 
#define ACL_MODECHG_ADD   1
 
#define ACL_MODECHG_DEL   2
 
#define ACL_MODECHG_EQL   3
 
#define ACL_INSERT_CHR   'a' /* formerly known as "append" */
 
#define ACL_SELECT_CHR   'r' /* formerly known as "read" */
 
#define ACL_UPDATE_CHR   'w' /* formerly known as "write" */
 
#define ACL_DELETE_CHR   'd'
 
#define ACL_TRUNCATE_CHR   'D' /* super-delete, as it were */
 
#define ACL_REFERENCES_CHR   'x'
 
#define ACL_TRIGGER_CHR   't'
 
#define ACL_EXECUTE_CHR   'X'
 
#define ACL_USAGE_CHR   'U'
 
#define ACL_CREATE_CHR   'C'
 
#define ACL_CREATE_TEMP_CHR   'T'
 
#define ACL_CONNECT_CHR   'c'
 
#define ACL_ALL_RIGHTS_STR   "arwdDxtXUCTc"
 
#define ACL_ALL_RIGHTS_COLUMN   (ACL_INSERT|ACL_SELECT|ACL_UPDATE|ACL_REFERENCES)
 
#define ACL_ALL_RIGHTS_RELATION   (ACL_INSERT|ACL_SELECT|ACL_UPDATE|ACL_DELETE|ACL_TRUNCATE|ACL_REFERENCES|ACL_TRIGGER)
 
#define ACL_ALL_RIGHTS_SEQUENCE   (ACL_USAGE|ACL_SELECT|ACL_UPDATE)
 
#define ACL_ALL_RIGHTS_DATABASE   (ACL_CREATE|ACL_CREATE_TEMP|ACL_CONNECT)
 
#define ACL_ALL_RIGHTS_FDW   (ACL_USAGE)
 
#define ACL_ALL_RIGHTS_FOREIGN_SERVER   (ACL_USAGE)
 
#define ACL_ALL_RIGHTS_FUNCTION   (ACL_EXECUTE)
 
#define ACL_ALL_RIGHTS_LANGUAGE   (ACL_USAGE)
 
#define ACL_ALL_RIGHTS_LARGEOBJECT   (ACL_SELECT|ACL_UPDATE)
 
#define ACL_ALL_RIGHTS_NAMESPACE   (ACL_USAGE|ACL_CREATE)
 
#define ACL_ALL_RIGHTS_TABLESPACE   (ACL_CREATE)
 
#define ACL_ALL_RIGHTS_TYPE   (ACL_USAGE)
 

Typedefs

typedef struct AclItem AclItem
 
typedef ArrayType Acl
 
typedef enum AclObjectKind AclObjectKind
 

Enumerations

enum  AclMaskHow { ACLMASK_ALL, ACLMASK_ANY }
 
enum  AclResult { ACLCHECK_OK = 0, ACLCHECK_NO_PRIV, ACLCHECK_NOT_OWNER }
 
enum  AclObjectKind {
  ACL_KIND_COLUMN, ACL_KIND_CLASS, ACL_KIND_SEQUENCE, ACL_KIND_DATABASE,
  ACL_KIND_PROC, ACL_KIND_OPER, ACL_KIND_TYPE, ACL_KIND_LANGUAGE,
  ACL_KIND_LARGEOBJECT, ACL_KIND_NAMESPACE, ACL_KIND_OPCLASS, ACL_KIND_OPFAMILY,
  ACL_KIND_COLLATION, ACL_KIND_CONVERSION, ACL_KIND_STATISTICS, ACL_KIND_TABLESPACE,
  ACL_KIND_TSDICTIONARY, ACL_KIND_TSCONFIGURATION, ACL_KIND_FDW, ACL_KIND_FOREIGN_SERVER,
  ACL_KIND_EVENT_TRIGGER, ACL_KIND_EXTENSION, ACL_KIND_PUBLICATION, ACL_KIND_SUBSCRIPTION,
  MAX_ACL_KIND
}
 

Functions

Aclacldefault (GrantObjectType objtype, Oid ownerId)
 
Aclget_user_default_acl (GrantObjectType objtype, Oid ownerId, Oid nsp_oid)
 
Aclaclupdate (const Acl *old_acl, const AclItem *mod_aip, int modechg, Oid ownerId, DropBehavior behavior)
 
Aclaclnewowner (const Acl *old_acl, Oid oldOwnerId, Oid newOwnerId)
 
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)
 
AclMode aclmask (const Acl *acl, Oid roleid, Oid ownerId, AclMode mask, AclMaskHow how)
 
int aclmembers (const Acl *acl, Oid **roleids)
 
bool has_privs_of_role (Oid member, Oid role)
 
bool is_member_of_role (Oid member, Oid role)
 
bool is_member_of_role_nosuper (Oid member, Oid role)
 
bool is_admin_of_role (Oid member, Oid role)
 
void check_is_member_of_role (Oid member, Oid role)
 
Oid get_role_oid (const char *rolename, bool missing_ok)
 
Oid get_role_oid_or_public (const char *rolename)
 
Oid get_rolespec_oid (const RoleSpec *role, bool missing_ok)
 
void check_rolespec_name (const RoleSpec *role, const char *detail_msg)
 
HeapTuple get_rolespec_tuple (const RoleSpec *role)
 
char * get_rolespec_name (const RoleSpec *role)
 
void select_best_grantor (Oid roleId, AclMode privileges, const Acl *acl, Oid ownerId, Oid *grantorId, AclMode *grantOptions)
 
void initialize_acl (void)
 
void ExecuteGrantStmt (GrantStmt *stmt)
 
void ExecAlterDefaultPrivilegesStmt (ParseState *pstate, AlterDefaultPrivilegesStmt *stmt)
 
void RemoveRoleFromObjectACL (Oid roleid, Oid classid, Oid objid)
 
void RemoveDefaultACLById (Oid defaclOid)
 
AclMode pg_attribute_aclmask (Oid table_oid, AttrNumber attnum, Oid roleid, AclMode mask, AclMaskHow how)
 
AclMode pg_class_aclmask (Oid table_oid, Oid roleid, AclMode mask, AclMaskHow how)
 
AclMode pg_database_aclmask (Oid db_oid, Oid roleid, AclMode mask, AclMaskHow how)
 
AclMode pg_proc_aclmask (Oid proc_oid, Oid roleid, AclMode mask, AclMaskHow how)
 
AclMode pg_language_aclmask (Oid lang_oid, Oid roleid, AclMode mask, AclMaskHow how)
 
AclMode pg_largeobject_aclmask_snapshot (Oid lobj_oid, Oid roleid, AclMode mask, AclMaskHow how, Snapshot snapshot)
 
AclMode pg_namespace_aclmask (Oid nsp_oid, Oid roleid, AclMode mask, AclMaskHow how)
 
AclMode pg_tablespace_aclmask (Oid spc_oid, Oid roleid, AclMode mask, AclMaskHow how)
 
AclMode pg_foreign_data_wrapper_aclmask (Oid fdw_oid, Oid roleid, AclMode mask, AclMaskHow how)
 
AclMode pg_foreign_server_aclmask (Oid srv_oid, Oid roleid, AclMode mask, AclMaskHow how)
 
AclMode pg_type_aclmask (Oid type_oid, Oid roleid, AclMode mask, AclMaskHow how)
 
AclResult pg_attribute_aclcheck (Oid table_oid, AttrNumber attnum, Oid roleid, AclMode mode)
 
AclResult pg_attribute_aclcheck_all (Oid table_oid, Oid roleid, AclMode mode, AclMaskHow how)
 
AclResult pg_class_aclcheck (Oid table_oid, Oid roleid, AclMode mode)
 
AclResult pg_database_aclcheck (Oid db_oid, Oid roleid, AclMode mode)
 
AclResult pg_proc_aclcheck (Oid proc_oid, Oid roleid, AclMode mode)
 
AclResult pg_language_aclcheck (Oid lang_oid, Oid roleid, AclMode mode)
 
AclResult pg_largeobject_aclcheck_snapshot (Oid lang_oid, Oid roleid, AclMode mode, Snapshot snapshot)
 
AclResult pg_namespace_aclcheck (Oid nsp_oid, Oid roleid, AclMode mode)
 
AclResult pg_tablespace_aclcheck (Oid spc_oid, Oid roleid, AclMode mode)
 
AclResult pg_foreign_data_wrapper_aclcheck (Oid fdw_oid, Oid roleid, AclMode mode)
 
AclResult pg_foreign_server_aclcheck (Oid srv_oid, Oid roleid, AclMode mode)
 
AclResult pg_type_aclcheck (Oid type_oid, Oid roleid, AclMode mode)
 
void aclcheck_error (AclResult aclerr, AclObjectKind objectkind, const char *objectname)
 
void aclcheck_error_col (AclResult aclerr, AclObjectKind objectkind, const char *objectname, const char *colname)
 
void aclcheck_error_type (AclResult aclerr, Oid typeOid)
 
void recordExtObjInitPriv (Oid objoid, Oid classoid)
 
void removeExtObjInitPriv (Oid objoid, Oid classoid)
 
bool pg_class_ownercheck (Oid class_oid, Oid roleid)
 
bool pg_type_ownercheck (Oid type_oid, Oid roleid)
 
bool pg_oper_ownercheck (Oid oper_oid, Oid roleid)
 
bool pg_proc_ownercheck (Oid proc_oid, Oid roleid)
 
bool pg_language_ownercheck (Oid lan_oid, Oid roleid)
 
bool pg_largeobject_ownercheck (Oid lobj_oid, Oid roleid)
 
bool pg_namespace_ownercheck (Oid nsp_oid, Oid roleid)
 
bool pg_tablespace_ownercheck (Oid spc_oid, Oid roleid)
 
bool pg_opclass_ownercheck (Oid opc_oid, Oid roleid)
 
bool pg_opfamily_ownercheck (Oid opf_oid, Oid roleid)
 
bool pg_database_ownercheck (Oid db_oid, Oid roleid)
 
bool pg_collation_ownercheck (Oid coll_oid, Oid roleid)
 
bool pg_conversion_ownercheck (Oid conv_oid, Oid roleid)
 
bool pg_ts_dict_ownercheck (Oid dict_oid, Oid roleid)
 
bool pg_ts_config_ownercheck (Oid cfg_oid, Oid roleid)
 
bool pg_foreign_data_wrapper_ownercheck (Oid srv_oid, Oid roleid)
 
bool pg_foreign_server_ownercheck (Oid srv_oid, Oid roleid)
 
bool pg_event_trigger_ownercheck (Oid et_oid, Oid roleid)
 
bool pg_extension_ownercheck (Oid ext_oid, Oid roleid)
 
bool pg_publication_ownercheck (Oid pub_oid, Oid roleid)
 
bool pg_subscription_ownercheck (Oid sub_oid, Oid roleid)
 
bool pg_statistics_ownercheck (Oid stat_oid, Oid roleid)
 
bool has_createrole_privilege (Oid roleid)
 
bool has_bypassrls_privilege (Oid roleid)
 

Macro Definition Documentation

#define ACL_ALL_RIGHTS_COLUMN   (ACL_INSERT|ACL_SELECT|ACL_UPDATE|ACL_REFERENCES)

Definition at line 149 of file acl.h.

Referenced by ExecGrant_Attribute(), ExecGrant_Relation(), and restrict_and_check_grant().

#define ACL_ALL_RIGHTS_DATABASE   (ACL_CREATE|ACL_CREATE_TEMP|ACL_CONNECT)

Definition at line 152 of file acl.h.

Referenced by acldefault(), ExecGrant_Database(), ExecuteGrantStmt(), and restrict_and_check_grant().

#define ACL_ALL_RIGHTS_FDW   (ACL_USAGE)

Definition at line 153 of file acl.h.

Referenced by acldefault(), ExecGrant_Fdw(), ExecuteGrantStmt(), and restrict_and_check_grant().

#define ACL_ALL_RIGHTS_FOREIGN_SERVER   (ACL_USAGE)
#define ACL_ALL_RIGHTS_FUNCTION   (ACL_EXECUTE)
#define ACL_ALL_RIGHTS_LANGUAGE   (ACL_USAGE)

Definition at line 156 of file acl.h.

Referenced by acldefault(), ExecGrant_Language(), ExecuteGrantStmt(), and restrict_and_check_grant().

#define ACL_ALL_RIGHTS_LARGEOBJECT   (ACL_SELECT|ACL_UPDATE)
#define ACL_ALL_RIGHTS_STR   "arwdDxtXUCTc"

Definition at line 144 of file acl.h.

Referenced by aclitemout(), and aclparse().

#define ACL_ALL_RIGHTS_TABLESPACE   (ACL_CREATE)
#define ACL_ALL_RIGHTS_TYPE   (ACL_USAGE)
#define ACL_CONNECT_CHR   'c'

Definition at line 141 of file acl.h.

Referenced by aclparse().

#define ACL_CREATE_CHR   'C'

Definition at line 139 of file acl.h.

Referenced by aclparse().

#define ACL_CREATE_TEMP_CHR   'T'

Definition at line 140 of file acl.h.

Referenced by aclparse().

#define ACL_DELETE_CHR   'd'
#define ACL_EXECUTE_CHR   'X'

Definition at line 137 of file acl.h.

Referenced by aclparse().

#define ACL_INSERT_CHR   'a' /* formerly known as "append" */
#define ACL_MODECHG_ADD   1

Definition at line 122 of file acl.h.

Referenced by aclmerge(), aclupdate(), and merge_acl_with_grant().

#define ACL_MODECHG_DEL   2

Definition at line 123 of file acl.h.

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

#define ACL_MODECHG_EQL   3

Definition at line 124 of file acl.h.

Referenced by aclupdate().

#define ACL_N_SIZE (   N)    (ARR_OVERHEAD_NONULLS(1) + ((N) * sizeof(AclItem)))

Definition at line 103 of file acl.h.

Referenced by aclnewowner(), aclupdate(), and allocacl().

#define ACL_OPTION_TO_PRIVS (   privs)    (((AclMode) (privs) >> 16) & 0xFFFF)

Definition at line 64 of file acl.h.

Referenced by check_circularity(), recursive_revoke(), and restrict_and_check_grant().

#define ACL_REFERENCES_CHR   'x'

Definition at line 135 of file acl.h.

Referenced by aclparse().

#define ACL_SELECT_CHR   'r' /* formerly known as "read" */
#define ACL_SIZE (   ACL)    ARR_SIZE(ACL)

Definition at line 104 of file acl.h.

Referenced by aclupdate(), and check_circularity().

#define ACL_TRIGGER_CHR   't'

Definition at line 136 of file acl.h.

Referenced by aclparse().

#define ACL_TRUNCATE_CHR   'D' /* super-delete, as it were */

Definition at line 134 of file acl.h.

Referenced by aclparse().

#define ACL_UPDATE_CHR   'w' /* formerly known as "write" */

Definition at line 132 of file acl.h.

Referenced by aclparse(), get_policies_for_relation(), and parse_policy_command().

#define ACL_USAGE_CHR   'U'

Definition at line 138 of file acl.h.

Referenced by aclparse().

#define ACLITEM_ALL_GOPTION_BITS   ((AclMode) 0xFFFF << 16)

Definition at line 81 of file acl.h.

Referenced by aclmask(), and aclmask_direct().

#define ACLITEM_ALL_PRIV_BITS   ((AclMode) 0xFFFF)

Definition at line 80 of file acl.h.

#define ACLITEM_GET_GOPTIONS (   item)    (((item).ai_privs >> 16) & 0xFFFF)

Definition at line 60 of file acl.h.

Referenced by aclexplode(), aclitemout(), aclupdate(), and check_circularity().

#define ACLITEM_GET_PRIVS (   item)    ((item).ai_privs & 0xFFFF)

Definition at line 59 of file acl.h.

Referenced by aclexplode(), aclitemout(), and recursive_revoke().

#define ACLITEM_GET_RIGHTS (   item)    ((item).ai_privs)

Definition at line 61 of file acl.h.

Referenced by aclcontains(), aclnewowner(), and aclupdate().

#define ACLITEM_SET_GOPTIONS (   item,
  goptions 
)
Value:
((item).ai_privs = ((item).ai_privs & ~(((AclMode) 0xFFFF) << 16)) | \
(((AclMode) (goptions) & 0xFFFF) << 16))
uint32 AclMode
Definition: parsenodes.h:63

Definition at line 69 of file acl.h.

#define ACLITEM_SET_PRIVS (   item,
  privs 
)
Value:
((item).ai_privs = ((item).ai_privs & ~((AclMode) 0xFFFF)) | \
((AclMode) (privs) & 0xFFFF))
uint32 AclMode
Definition: parsenodes.h:63

Definition at line 66 of file acl.h.

#define ACLITEM_SET_PRIVS_GOPTIONS (   item,
  privs,
  goptions 
)
Value:
((item).ai_privs = ((AclMode) (privs) & 0xFFFF) | \
(((AclMode) (goptions) & 0xFFFF) << 16))
uint32 AclMode
Definition: parsenodes.h:63

Definition at line 75 of file acl.h.

Referenced by acldefault(), aclparse(), aclupdate(), makeaclitem(), merge_acl_with_grant(), and recursive_revoke().

#define ACLITEM_SET_RIGHTS (   item,
  rights 
)    ((item).ai_privs = (AclMode) (rights))

Definition at line 72 of file acl.h.

Referenced by aclnewowner(), and aclupdate().

#define DatumGetAclItemP (   X)    ((AclItem *) DatumGetPointer(X))

Definition at line 109 of file acl.h.

#define PG_GETARG_ACL_P (   n)    DatumGetAclP(PG_GETARG_DATUM(n))

Definition at line 115 of file acl.h.

Referenced by aclcontains(), and aclexplode().

#define PG_GETARG_ACL_P_COPY (   n)    DatumGetAclPCopy(PG_GETARG_DATUM(n))

Definition at line 116 of file acl.h.

#define PG_GETARG_ACLITEM_P (   n)    DatumGetAclItemP(PG_GETARG_DATUM(n))

Definition at line 110 of file acl.h.

Referenced by aclcontains(), aclitem_eq(), aclitemout(), and hash_aclitem().

#define PG_RETURN_ACL_P (   x)    PG_RETURN_POINTER(x)

Definition at line 117 of file acl.h.

Referenced by acldefault_sql().

#define PG_RETURN_ACLITEM_P (   x)    PG_RETURN_POINTER(x)

Definition at line 111 of file acl.h.

Referenced by aclitemin(), and makeaclitem().

Typedef Documentation

Definition at line 99 of file acl.h.

Enumeration Type Documentation

enum AclMaskHow
Enumerator
ACLMASK_ALL 
ACLMASK_ANY 

Definition at line 163 of file acl.h.

164 {
165  ACLMASK_ALL, /* normal case: compute all bits */
166  ACLMASK_ANY /* return when result is known nonzero */
167 } AclMaskHow;
AclMaskHow
Definition: acl.h:163
Enumerator
ACL_KIND_COLUMN 
ACL_KIND_CLASS 
ACL_KIND_SEQUENCE 
ACL_KIND_DATABASE 
ACL_KIND_PROC 
ACL_KIND_OPER 
ACL_KIND_TYPE 
ACL_KIND_LANGUAGE 
ACL_KIND_LARGEOBJECT 
ACL_KIND_NAMESPACE 
ACL_KIND_OPCLASS 
ACL_KIND_OPFAMILY 
ACL_KIND_COLLATION 
ACL_KIND_CONVERSION 
ACL_KIND_STATISTICS 
ACL_KIND_TABLESPACE 
ACL_KIND_TSDICTIONARY 
ACL_KIND_TSCONFIGURATION 
ACL_KIND_FDW 
ACL_KIND_FOREIGN_SERVER 
ACL_KIND_EVENT_TRIGGER 
ACL_KIND_EXTENSION 
ACL_KIND_PUBLICATION 
ACL_KIND_SUBSCRIPTION 
MAX_ACL_KIND 

Definition at line 179 of file acl.h.

180 {
181  ACL_KIND_COLUMN, /* pg_attribute */
182  ACL_KIND_CLASS, /* pg_class */
183  ACL_KIND_SEQUENCE, /* pg_sequence */
184  ACL_KIND_DATABASE, /* pg_database */
185  ACL_KIND_PROC, /* pg_proc */
186  ACL_KIND_OPER, /* pg_operator */
187  ACL_KIND_TYPE, /* pg_type */
188  ACL_KIND_LANGUAGE, /* pg_language */
189  ACL_KIND_LARGEOBJECT, /* pg_largeobject */
190  ACL_KIND_NAMESPACE, /* pg_namespace */
191  ACL_KIND_OPCLASS, /* pg_opclass */
192  ACL_KIND_OPFAMILY, /* pg_opfamily */
193  ACL_KIND_COLLATION, /* pg_collation */
194  ACL_KIND_CONVERSION, /* pg_conversion */
195  ACL_KIND_STATISTICS, /* pg_statistic_ext */
196  ACL_KIND_TABLESPACE, /* pg_tablespace */
197  ACL_KIND_TSDICTIONARY, /* pg_ts_dict */
198  ACL_KIND_TSCONFIGURATION, /* pg_ts_config */
199  ACL_KIND_FDW, /* pg_foreign_data_wrapper */
200  ACL_KIND_FOREIGN_SERVER, /* pg_foreign_server */
201  ACL_KIND_EVENT_TRIGGER, /* pg_event_trigger */
202  ACL_KIND_EXTENSION, /* pg_extension */
203  ACL_KIND_PUBLICATION, /* pg_publication */
204  ACL_KIND_SUBSCRIPTION, /* pg_subscription */
205  MAX_ACL_KIND /* MUST BE LAST */
206 } AclObjectKind;
AclObjectKind
Definition: acl.h:179
enum AclResult
Enumerator
ACLCHECK_OK 
ACLCHECK_NO_PRIV 
ACLCHECK_NOT_OWNER 

Definition at line 170 of file acl.h.

171 {
172  ACLCHECK_OK = 0,
175 } AclResult;
AclResult
Definition: acl.h:170

Function Documentation

void aclcheck_error ( AclResult  aclerr,
AclObjectKind  objectkind,
const char *  objectname 
)

Definition at line 3399 of file aclchk.c.

References ACLCHECK_NO_PRIV, ACLCHECK_NOT_OWNER, ACLCHECK_OK, elog, ereport, errcode(), errmsg(), and ERROR.

Referenced by aclcheck_error_type(), AlterCollation(), AlterDatabase(), AlterDatabaseOwner(), AlterDatabaseSet(), AlterEventTrigger(), AlterEventTriggerOwner_internal(), AlterExtensionNamespace(), AlterForeignServer(), AlterForeignServerOwner_internal(), AlterFunction(), AlterObjectNamespace_internal(), AlterObjectOwner_internal(), AlterObjectRename_internal(), AlterOperator(), AlterOpFamilyAdd(), AlterPublication(), AlterPublicationOwner_internal(), AlterRoleSet(), AlterSchemaOwner_internal(), AlterSequence(), AlterSubscription(), AlterSubscriptionOwner_internal(), AlterTableMoveAll(), AlterTableSpaceOptions(), AlterTSConfiguration(), AlterTSDictionary(), AlterTypeOwner(), ATExecChangeOwner(), ATPrepSetStatistics(), ATPrepSetTableSpace(), ATSimplePermissions(), brin_summarize_new_values(), calculate_database_size(), calculate_tablespace_size(), call_pltcl_start_proc(), check_object_ownership(), check_temp_tablespaces(), checkFkeyPermissions(), CheckFunctionValidatorAccess(), compute_return_type(), create_proc_lang(), CreateConversionCommand(), createdb(), CreateForeignServer(), CreateForeignTable(), CreateFunction(), CreateProceduralLanguage(), CreatePublication(), CreateSchemaCommand(), CreateTransform(), CreateTrigger(), currtid_byrelname(), currtid_byreloid(), DefineAggregate(), DefineCollation(), DefineDomain(), DefineEnum(), DefineIndex(), DefineOpClass(), DefineOperator(), DefineOpFamily(), DefineQueryRewrite(), DefineRange(), DefineRelation(), DefineTSConfiguration(), DefineTSDictionary(), DefineType(), dropdb(), DropSubscription(), DropTableSpace(), EnableDisableRule(), ExecAlterExtensionContentsStmt(), ExecAlterExtensionStmt(), ExecCheckRTPerms(), ExecInitAgg(), ExecInitExprRec(), ExecInitFunc(), ExecInitWindowAgg(), ExecuteDoStmt(), ExecuteTruncate(), findRangeCanonicalFunction(), findRangeSubtypeDiffFunction(), get_connect_string(), get_other_operator(), get_rel_from_relname(), gin_clean_pending_list(), HandleFunctionRequest(), ImportForeignSchema(), init_sexpr(), initialize_peragg(), LockTableRecurse(), lookup_agg_function(), LookupCreationNamespace(), LookupExplicitNamespace(), MergeAttributes(), movedb(), OperatorCreate(), pg_prewarm(), pgrowlocks(), ProcedureCreate(), PublicationAddTables(), RangeVarCallbackForAlterRelation(), RangeVarCallbackForDropRelation(), RangeVarCallbackForLockTable(), RangeVarCallbackForPolicy(), RangeVarCallbackForReindexIndex(), RangeVarCallbackForRenameRule(), RangeVarCallbackForRenameTrigger(), RangeVarCallbackOwnsRelation(), RangeVarCallbackOwnsTable(), RangeVarGetAndCheckCreationNamespace(), ReindexMultipleTables(), renameatt_check(), RenameDatabase(), RenameSchema(), RenameTableSpace(), restrict_and_check_grant(), transformTableLikeClause(), truncate_check_rel(), TypeCreate(), user_mapping_ddl_aclcheck(), ValidateJoinEstimator(), and ValidateRestrictionEstimator().

3401 {
3402  switch (aclerr)
3403  {
3404  case ACLCHECK_OK:
3405  /* no error, so return to caller */
3406  break;
3407  case ACLCHECK_NO_PRIV:
3408  ereport(ERROR,
3409  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
3410  errmsg(no_priv_msg[objectkind], objectname)));
3411  break;
3412  case ACLCHECK_NOT_OWNER:
3413  ereport(ERROR,
3414  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
3415  errmsg(not_owner_msg[objectkind], objectname)));
3416  break;
3417  default:
3418  elog(ERROR, "unrecognized AclResult: %d", (int) aclerr);
3419  break;
3420  }
3421 }
static const char *const no_priv_msg[MAX_ACL_KIND]
Definition: aclchk.c:3293
static const char *const not_owner_msg[MAX_ACL_KIND]
Definition: aclchk.c:3345
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 elog
Definition: elog.h:219
void aclcheck_error_col ( AclResult  aclerr,
AclObjectKind  objectkind,
const char *  objectname,
const char *  colname 
)

Definition at line 3425 of file aclchk.c.

References ACLCHECK_NO_PRIV, ACLCHECK_NOT_OWNER, ACLCHECK_OK, elog, ereport, errcode(), errmsg(), and ERROR.

Referenced by restrict_and_check_grant().

3427 {
3428  switch (aclerr)
3429  {
3430  case ACLCHECK_OK:
3431  /* no error, so return to caller */
3432  break;
3433  case ACLCHECK_NO_PRIV:
3434  ereport(ERROR,
3435  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
3436  errmsg("permission denied for column \"%s\" of relation \"%s\"",
3437  colname, objectname)));
3438  break;
3439  case ACLCHECK_NOT_OWNER:
3440  /* relation msg is OK since columns don't have separate owners */
3441  ereport(ERROR,
3442  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
3443  errmsg(not_owner_msg[objectkind], objectname)));
3444  break;
3445  default:
3446  elog(ERROR, "unrecognized AclResult: %d", (int) aclerr);
3447  break;
3448  }
3449 }
static const char *const not_owner_msg[MAX_ACL_KIND]
Definition: aclchk.c:3345
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 elog
Definition: elog.h:219
void aclcheck_error_type ( AclResult  aclerr,
Oid  typeOid 
)

Definition at line 3457 of file aclchk.c.

References ACL_KIND_TYPE, aclcheck_error(), format_type_be(), and get_element_type().

Referenced by AggregateCreate(), AlterTypeNamespace_oid(), AlterTypeOwner(), ATExecAddColumn(), ATPrepAlterColumnType(), BuildDescForRelation(), check_object_ownership(), checkDomainOwner(), checkEnumOwner(), compute_return_type(), CreateCast(), CreateTransform(), DefineDomain(), DefineOpClass(), DefineOperator(), DefineRelation(), interpret_function_parameter_list(), and RenameType().

3458 {
3459  Oid element_type = get_element_type(typeOid);
3460 
3461  aclcheck_error(aclerr, ACL_KIND_TYPE, format_type_be(element_type ? element_type : typeOid));
3462 }
Oid get_element_type(Oid typid)
Definition: lsyscache.c:2452
char * format_type_be(Oid type_oid)
Definition: format_type.c:94
unsigned int Oid
Definition: postgres_ext.h:31
void aclcheck_error(AclResult aclerr, AclObjectKind objectkind, const char *objectname)
Definition: aclchk.c:3399
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
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:63
#define ERROR
Definition: elog.h:43
#define ACL_NO_RIGHTS
Definition: parsenodes.h:79
#define ACL_ALL_RIGHTS_TYPE
Definition: acl.h:160
#define ACL_USAGE
Definition: parsenodes.h:73
#define ACL_CONNECT
Definition: parsenodes.h:77
#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:72
#define ACL_ALL_RIGHTS_RELATION
Definition: acl.h:150
#define ACL_CREATE_TEMP
Definition: parsenodes.h:76
#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
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
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:1618
AclMode ai_privs
Definition: acl.h:51
uint32 AclMode
Definition: parsenodes.h:63
#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
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:79
#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
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:63
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:79
#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
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:319
char * rolename
Definition: parsenodes.h:320
int errmsg(const char *fmt,...)
Definition: elog.c:797
void ExecAlterDefaultPrivilegesStmt ( ParseState pstate,
AlterDefaultPrivilegesStmt stmt 
)

Definition at line 863 of file aclchk.c.

References ACL_ALL_RIGHTS_FUNCTION, ACL_ALL_RIGHTS_NAMESPACE, ACL_ALL_RIGHTS_RELATION, ACL_ALL_RIGHTS_SEQUENCE, ACL_ALL_RIGHTS_TYPE, ACL_ID_PUBLIC, ACL_NO_RIGHTS, ACL_OBJECT_FUNCTION, ACL_OBJECT_NAMESPACE, ACL_OBJECT_RELATION, ACL_OBJECT_SEQUENCE, ACL_OBJECT_TYPE, AlterDefaultPrivilegesStmt::action, InternalDefaultACL::all_privs, DefElem::arg, InternalDefaultACL::behavior, GrantStmt::behavior, check_is_member_of_role(), AccessPriv::cols, DefElem::defname, elog, ereport, errcode(), errmsg(), ERROR, get_rolespec_oid(), gettext_noop, GetUserId(), InternalDefaultACL::grant_option, GrantStmt::grant_option, InternalDefaultACL::grantees, GrantStmt::grantees, InternalDefaultACL::is_grant, GrantStmt::is_grant, lappend_oid(), lfirst, DefElem::location, NIL, NULL, InternalDefaultACL::objtype, GrantStmt::objtype, AlterDefaultPrivilegesStmt::options, parser_errposition(), AccessPriv::priv_name, privilege_to_string(), InternalDefaultACL::privileges, GrantStmt::privileges, InternalDefaultACL::roleid, ROLESPEC_PUBLIC, RoleSpec::roletype, SetDefaultACLsInSchemas(), and string_to_privilege().

Referenced by ProcessUtilitySlow().

864 {
865  GrantStmt *action = stmt->action;
866  InternalDefaultACL iacls;
867  ListCell *cell;
868  List *rolespecs = NIL;
869  List *nspnames = NIL;
870  DefElem *drolespecs = NULL;
871  DefElem *dnspnames = NULL;
872  AclMode all_privileges;
873  const char *errormsg;
874 
875  /* Deconstruct the "options" part of the statement */
876  foreach(cell, stmt->options)
877  {
878  DefElem *defel = (DefElem *) lfirst(cell);
879 
880  if (strcmp(defel->defname, "schemas") == 0)
881  {
882  if (dnspnames)
883  ereport(ERROR,
884  (errcode(ERRCODE_SYNTAX_ERROR),
885  errmsg("conflicting or redundant options"),
886  parser_errposition(pstate, defel->location)));
887  dnspnames = defel;
888  }
889  else if (strcmp(defel->defname, "roles") == 0)
890  {
891  if (drolespecs)
892  ereport(ERROR,
893  (errcode(ERRCODE_SYNTAX_ERROR),
894  errmsg("conflicting or redundant options"),
895  parser_errposition(pstate, defel->location)));
896  drolespecs = defel;
897  }
898  else
899  elog(ERROR, "option \"%s\" not recognized", defel->defname);
900  }
901 
902  if (dnspnames)
903  nspnames = (List *) dnspnames->arg;
904  if (drolespecs)
905  rolespecs = (List *) drolespecs->arg;
906 
907  /* Prepare the InternalDefaultACL representation of the statement */
908  /* roleid to be filled below */
909  /* nspid to be filled in SetDefaultACLsInSchemas */
910  iacls.is_grant = action->is_grant;
911  iacls.objtype = action->objtype;
912  /* all_privs to be filled below */
913  /* privileges to be filled below */
914  iacls.grantees = NIL; /* filled below */
915  iacls.grant_option = action->grant_option;
916  iacls.behavior = action->behavior;
917 
918  /*
919  * Convert the RoleSpec list into an Oid list. Note that at this point we
920  * insert an ACL_ID_PUBLIC into the list if appropriate, so downstream
921  * there shouldn't be any additional work needed to support this case.
922  */
923  foreach(cell, action->grantees)
924  {
925  RoleSpec *grantee = (RoleSpec *) lfirst(cell);
926  Oid grantee_uid;
927 
928  switch (grantee->roletype)
929  {
930  case ROLESPEC_PUBLIC:
931  grantee_uid = ACL_ID_PUBLIC;
932  break;
933  default:
934  grantee_uid = get_rolespec_oid(grantee, false);
935  break;
936  }
937  iacls.grantees = lappend_oid(iacls.grantees, grantee_uid);
938  }
939 
940  /*
941  * Convert action->privileges, a list of privilege strings, into an
942  * AclMode bitmask.
943  */
944  switch (action->objtype)
945  {
946  case ACL_OBJECT_RELATION:
947  all_privileges = ACL_ALL_RIGHTS_RELATION;
948  errormsg = gettext_noop("invalid privilege type %s for relation");
949  break;
950  case ACL_OBJECT_SEQUENCE:
951  all_privileges = ACL_ALL_RIGHTS_SEQUENCE;
952  errormsg = gettext_noop("invalid privilege type %s for sequence");
953  break;
954  case ACL_OBJECT_FUNCTION:
955  all_privileges = ACL_ALL_RIGHTS_FUNCTION;
956  errormsg = gettext_noop("invalid privilege type %s for function");
957  break;
958  case ACL_OBJECT_TYPE:
959  all_privileges = ACL_ALL_RIGHTS_TYPE;
960  errormsg = gettext_noop("invalid privilege type %s for type");
961  break;
963  all_privileges = ACL_ALL_RIGHTS_NAMESPACE;
964  errormsg = gettext_noop("invalid privilege type %s for schema");
965  break;
966  default:
967  elog(ERROR, "unrecognized GrantStmt.objtype: %d",
968  (int) action->objtype);
969  /* keep compiler quiet */
970  all_privileges = ACL_NO_RIGHTS;
971  errormsg = NULL;
972  }
973 
974  if (action->privileges == NIL)
975  {
976  iacls.all_privs = true;
977 
978  /*
979  * will be turned into ACL_ALL_RIGHTS_* by the internal routines
980  * depending on the object type
981  */
982  iacls.privileges = ACL_NO_RIGHTS;
983  }
984  else
985  {
986  iacls.all_privs = false;
987  iacls.privileges = ACL_NO_RIGHTS;
988 
989  foreach(cell, action->privileges)
990  {
991  AccessPriv *privnode = (AccessPriv *) lfirst(cell);
992  AclMode priv;
993 
994  if (privnode->cols)
995  ereport(ERROR,
996  (errcode(ERRCODE_INVALID_GRANT_OPERATION),
997  errmsg("default privileges cannot be set for columns")));
998 
999  if (privnode->priv_name == NULL) /* parser mistake? */
1000  elog(ERROR, "AccessPriv node must specify privilege");
1001  priv = string_to_privilege(privnode->priv_name);
1002 
1003  if (priv & ~((AclMode) all_privileges))
1004  ereport(ERROR,
1005  (errcode(ERRCODE_INVALID_GRANT_OPERATION),
1006  errmsg(errormsg, privilege_to_string(priv))));
1007 
1008  iacls.privileges |= priv;
1009  }
1010  }
1011 
1012  if (rolespecs == NIL)
1013  {
1014  /* Set permissions for myself */
1015  iacls.roleid = GetUserId();
1016 
1017  SetDefaultACLsInSchemas(&iacls, nspnames);
1018  }
1019  else
1020  {
1021  /* Look up the role OIDs and do permissions checks */
1022  ListCell *rolecell;
1023 
1024  foreach(rolecell, rolespecs)
1025  {
1026  RoleSpec *rolespec = lfirst(rolecell);
1027 
1028  iacls.roleid = get_rolespec_oid(rolespec, false);
1029 
1030  /*
1031  * We insist that calling user be a member of each target role. If
1032  * he has that, he could become that role anyway via SET ROLE, so
1033  * FOR ROLE is just a syntactic convenience and doesn't give any
1034  * special privileges.
1035  */
1037 
1038  SetDefaultACLsInSchemas(&iacls, nspnames);
1039  }
1040  }
1041 }
#define NIL
Definition: pg_list.h:69
#define ACL_ALL_RIGHTS_FUNCTION
Definition: acl.h:155
bool grant_option
Definition: aclchk.c:93
Oid GetUserId(void)
Definition: miscinit.c:283
static AclMode string_to_privilege(const char *privname)
Definition: aclchk.c:3215
bool grant_option
Definition: parsenodes.h:1812
#define gettext_noop(x)
Definition: c.h:139
int errcode(int sqlerrcode)
Definition: elog.c:575
List * cols
Definition: parsenodes.h:1842
unsigned int Oid
Definition: postgres_ext.h:31
GrantObjectType objtype
Definition: aclchk.c:89
List * grantees
Definition: aclchk.c:92
List * lappend_oid(List *list, Oid datum)
Definition: list.c:164
uint32 AclMode
Definition: parsenodes.h:63
#define ERROR
Definition: elog.h:43
#define ACL_NO_RIGHTS
Definition: parsenodes.h:79
int location
Definition: parsenodes.h:711
#define ACL_ALL_RIGHTS_TYPE
Definition: acl.h:160
void check_is_member_of_role(Oid member, Oid role)
Definition: acl.c:4859
#define ereport(elevel, rest)
Definition: elog.h:122
Node * arg
Definition: parsenodes.h:709
#define ACL_ALL_RIGHTS_NAMESPACE
Definition: acl.h:158
bool is_grant
Definition: parsenodes.h:1804
RoleSpecType roletype
Definition: parsenodes.h:319
Oid get_rolespec_oid(const RoleSpec *role, bool missing_ok)
Definition: acl.c:5129
#define ACL_ALL_RIGHTS_SEQUENCE
Definition: acl.h:151
DropBehavior behavior
Definition: aclchk.c:94
List * privileges
Definition: parsenodes.h:1809
DropBehavior behavior
Definition: parsenodes.h:1813
#define NULL
Definition: c.h:229
#define lfirst(lc)
Definition: pg_list.h:106
int parser_errposition(ParseState *pstate, int location)
Definition: parse_node.c:109
static void SetDefaultACLsInSchemas(InternalDefaultACL *iacls, List *nspnames)
Definition: aclchk.c:1049
GrantObjectType objtype
Definition: parsenodes.h:1806
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define ACL_ALL_RIGHTS_RELATION
Definition: acl.h:150
#define ACL_ID_PUBLIC
Definition: acl.h:39
char * defname
Definition: parsenodes.h:708
static const char * privilege_to_string(AclMode privilege)
Definition: aclchk.c:3252
List * grantees
Definition: parsenodes.h:1811
#define elog
Definition: elog.h:219
AclMode privileges
Definition: aclchk.c:91
Definition: pg_list.h:45
char * priv_name
Definition: parsenodes.h:1841
void ExecuteGrantStmt ( GrantStmt stmt)

Definition at line 385 of file aclchk.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_ID_PUBLIC, ACL_NO_RIGHTS, 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_TARGET_ALL_IN_SCHEMA, ACL_TARGET_OBJECT, InternalGrant::all_privs, InternalGrant::behavior, GrantStmt::behavior, InternalGrant::col_privs, AccessPriv::cols, elog, ereport, errcode(), errmsg(), ERROR, ExecGrantStmt_oids(), get_rolespec_oid(), gettext_noop, InternalGrant::grant_option, GrantStmt::grant_option, InternalGrant::grantees, GrantStmt::grantees, InternalGrant::is_grant, GrantStmt::is_grant, lappend(), lappend_oid(), lfirst, NIL, NULL, objectNamesToOids(), InternalGrant::objects, GrantStmt::objects, objectsInSchemaToOids(), InternalGrant::objtype, GrantStmt::objtype, AccessPriv::priv_name, privilege_to_string(), InternalGrant::privileges, GrantStmt::privileges, ROLESPEC_PUBLIC, RoleSpec::roletype, string_to_privilege(), and GrantStmt::targtype.

Referenced by ProcessUtilitySlow(), and standard_ProcessUtility().

386 {
387  InternalGrant istmt;
388  ListCell *cell;
389  const char *errormsg;
390  AclMode all_privileges;
391 
392  /*
393  * Turn the regular GrantStmt into the InternalGrant form.
394  */
395  istmt.is_grant = stmt->is_grant;
396  istmt.objtype = stmt->objtype;
397 
398  /* Collect the OIDs of the target objects */
399  switch (stmt->targtype)
400  {
401  case ACL_TARGET_OBJECT:
402  istmt.objects = objectNamesToOids(stmt->objtype, stmt->objects);
403  break;
405  istmt.objects = objectsInSchemaToOids(stmt->objtype, stmt->objects);
406  break;
407  /* ACL_TARGET_DEFAULTS should not be seen here */
408  default:
409  elog(ERROR, "unrecognized GrantStmt.targtype: %d",
410  (int) stmt->targtype);
411  }
412 
413  /* all_privs to be filled below */
414  /* privileges to be filled below */
415  istmt.col_privs = NIL; /* may get filled below */
416  istmt.grantees = NIL; /* filled below */
417  istmt.grant_option = stmt->grant_option;
418  istmt.behavior = stmt->behavior;
419 
420  /*
421  * Convert the RoleSpec list into an Oid list. Note that at this point we
422  * insert an ACL_ID_PUBLIC into the list if appropriate, so downstream
423  * there shouldn't be any additional work needed to support this case.
424  */
425  foreach(cell, stmt->grantees)
426  {
427  RoleSpec *grantee = (RoleSpec *) lfirst(cell);
428  Oid grantee_uid;
429 
430  switch (grantee->roletype)
431  {
432  case ROLESPEC_PUBLIC:
433  grantee_uid = ACL_ID_PUBLIC;
434  break;
435  default:
436  grantee_uid = get_rolespec_oid(grantee, false);
437  break;
438  }
439  istmt.grantees = lappend_oid(istmt.grantees, grantee_uid);
440  }
441 
442  /*
443  * Convert stmt->privileges, a list of AccessPriv nodes, into an AclMode
444  * bitmask. Note: objtype can't be ACL_OBJECT_COLUMN.
445  */
446  switch (stmt->objtype)
447  {
448  /*
449  * Because this might be a sequence, we test both relation and
450  * sequence bits, and later do a more limited test when we know
451  * the object type.
452  */
453  case ACL_OBJECT_RELATION:
455  errormsg = gettext_noop("invalid privilege type %s for relation");
456  break;
457  case ACL_OBJECT_SEQUENCE:
458  all_privileges = ACL_ALL_RIGHTS_SEQUENCE;
459  errormsg = gettext_noop("invalid privilege type %s for sequence");
460  break;
461  case ACL_OBJECT_DATABASE:
462  all_privileges = ACL_ALL_RIGHTS_DATABASE;
463  errormsg = gettext_noop("invalid privilege type %s for database");
464  break;
465  case ACL_OBJECT_DOMAIN:
466  all_privileges = ACL_ALL_RIGHTS_TYPE;
467  errormsg = gettext_noop("invalid privilege type %s for domain");
468  break;
469  case ACL_OBJECT_FUNCTION:
470  all_privileges = ACL_ALL_RIGHTS_FUNCTION;
471  errormsg = gettext_noop("invalid privilege type %s for function");
472  break;
473  case ACL_OBJECT_LANGUAGE:
474  all_privileges = ACL_ALL_RIGHTS_LANGUAGE;
475  errormsg = gettext_noop("invalid privilege type %s for language");
476  break;
478  all_privileges = ACL_ALL_RIGHTS_LARGEOBJECT;
479  errormsg = gettext_noop("invalid privilege type %s for large object");
480  break;
482  all_privileges = ACL_ALL_RIGHTS_NAMESPACE;
483  errormsg = gettext_noop("invalid privilege type %s for schema");
484  break;
486  all_privileges = ACL_ALL_RIGHTS_TABLESPACE;
487  errormsg = gettext_noop("invalid privilege type %s for tablespace");
488  break;
489  case ACL_OBJECT_TYPE:
490  all_privileges = ACL_ALL_RIGHTS_TYPE;
491  errormsg = gettext_noop("invalid privilege type %s for type");
492  break;
493  case ACL_OBJECT_FDW:
494  all_privileges = ACL_ALL_RIGHTS_FDW;
495  errormsg = gettext_noop("invalid privilege type %s for foreign-data wrapper");
496  break;
498  all_privileges = ACL_ALL_RIGHTS_FOREIGN_SERVER;
499  errormsg = gettext_noop("invalid privilege type %s for foreign server");
500  break;
501  default:
502  elog(ERROR, "unrecognized GrantStmt.objtype: %d",
503  (int) stmt->objtype);
504  /* keep compiler quiet */
505  all_privileges = ACL_NO_RIGHTS;
506  errormsg = NULL;
507  }
508 
509  if (stmt->privileges == NIL)
510  {
511  istmt.all_privs = true;
512 
513  /*
514  * will be turned into ACL_ALL_RIGHTS_* by the internal routines
515  * depending on the object type
516  */
517  istmt.privileges = ACL_NO_RIGHTS;
518  }
519  else
520  {
521  istmt.all_privs = false;
522  istmt.privileges = ACL_NO_RIGHTS;
523 
524  foreach(cell, stmt->privileges)
525  {
526  AccessPriv *privnode = (AccessPriv *) lfirst(cell);
527  AclMode priv;
528 
529  /*
530  * If it's a column-level specification, we just set it aside in
531  * col_privs for the moment; but insist it's for a relation.
532  */
533  if (privnode->cols)
534  {
535  if (stmt->objtype != ACL_OBJECT_RELATION)
536  ereport(ERROR,
537  (errcode(ERRCODE_INVALID_GRANT_OPERATION),
538  errmsg("column privileges are only valid for relations")));
539  istmt.col_privs = lappend(istmt.col_privs, privnode);
540  continue;
541  }
542 
543  if (privnode->priv_name == NULL) /* parser mistake? */
544  elog(ERROR, "AccessPriv node must specify privilege or columns");
545  priv = string_to_privilege(privnode->priv_name);
546 
547  if (priv & ~((AclMode) all_privileges))
548  ereport(ERROR,
549  (errcode(ERRCODE_INVALID_GRANT_OPERATION),
550  errmsg(errormsg, privilege_to_string(priv))));
551 
552  istmt.privileges |= priv;
553  }
554  }
555 
556  ExecGrantStmt_oids(&istmt);
557 }
#define NIL
Definition: pg_list.h:69
#define ACL_ALL_RIGHTS_FUNCTION
Definition: acl.h:155
static AclMode string_to_privilege(const char *privname)
Definition: aclchk.c:3215
AclMode privileges
bool grant_option
Definition: parsenodes.h:1812
#define gettext_noop(x)
Definition: c.h:139
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ACL_ALL_RIGHTS_TABLESPACE
Definition: acl.h:159
List * cols
Definition: parsenodes.h:1842
unsigned int Oid
Definition: postgres_ext.h:31
List * lappend_oid(List *list, Oid datum)
Definition: list.c:164
static List * objectsInSchemaToOids(GrantObjectType objtype, List *nspnames)
Definition: aclchk.c:756
#define ACL_ALL_RIGHTS_LANGUAGE
Definition: acl.h:156
GrantObjectType objtype
uint32 AclMode
Definition: parsenodes.h:63
#define ERROR
Definition: elog.h:43
#define ACL_NO_RIGHTS
Definition: parsenodes.h:79
#define ACL_ALL_RIGHTS_TYPE
Definition: acl.h:160
#define ereport(elevel, rest)
Definition: elog.h:122
List * lappend(List *list, void *datum)
Definition: list.c:128
#define ACL_ALL_RIGHTS_NAMESPACE
Definition: acl.h:158
bool is_grant
Definition: parsenodes.h:1804
static void ExecGrantStmt_oids(InternalGrant *istmt)
Definition: aclchk.c:565
RoleSpecType roletype
Definition: parsenodes.h:319
Oid get_rolespec_oid(const RoleSpec *role, bool missing_ok)
Definition: acl.c:5129
#define ACL_ALL_RIGHTS_SEQUENCE
Definition: acl.h:151
List * privileges
Definition: parsenodes.h:1809
#define ACL_ALL_RIGHTS_LARGEOBJECT
Definition: acl.h:157
DropBehavior behavior
DropBehavior behavior
Definition: parsenodes.h:1813
#define NULL
Definition: c.h:229
#define lfirst(lc)
Definition: pg_list.h:106
List * objects
Definition: parsenodes.h:1807
#define ACL_ALL_RIGHTS_DATABASE
Definition: acl.h:152
#define ACL_ALL_RIGHTS_FOREIGN_SERVER
Definition: acl.h:154
GrantObjectType objtype
Definition: parsenodes.h:1806
static List * objectNamesToOids(GrantObjectType objtype, List *objnames)
Definition: aclchk.c:627
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define ACL_ALL_RIGHTS_RELATION
Definition: acl.h:150
#define ACL_ID_PUBLIC
Definition: acl.h:39
#define ACL_ALL_RIGHTS_FDW
Definition: acl.h:153
static const char * privilege_to_string(AclMode privilege)
Definition: aclchk.c:3252
List * grantees
Definition: parsenodes.h:1811
#define elog
Definition: elog.h:219
GrantTargetType targtype
Definition: parsenodes.h:1805
char * priv_name
Definition: parsenodes.h:1841
Oid get_role_oid ( const char *  rolename,
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:179
#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:1116
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:319
#define InvalidOid
Definition: postgres_ext.h:36
#define Assert(condition)
Definition: c.h:675
char * rolename
Definition: parsenodes.h:320
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:152
#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:319
#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:320
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define elog
Definition: elog.h:219
Acl* get_user_default_acl ( GrantObjectType  objtype,
Oid  ownerId,
Oid  nsp_oid 
)

Definition at line 5245 of file aclchk.c.

References ACL_OBJECT_FUNCTION, ACL_OBJECT_NAMESPACE, ACL_OBJECT_RELATION, ACL_OBJECT_SEQUENCE, ACL_OBJECT_TYPE, acldefault(), aclequal(), aclitemsort(), aclmerge(), DEFACLOBJ_FUNCTION, DEFACLOBJ_NAMESPACE, DEFACLOBJ_RELATION, DEFACLOBJ_SEQUENCE, DEFACLOBJ_TYPE, get_default_acl_internal(), InvalidOid, IsBootstrapProcessingMode, NULL, and result.

Referenced by heap_create_with_catalog(), NamespaceCreate(), ProcedureCreate(), and TypeCreate().

5246 {
5247  Acl *result;
5248  Acl *glob_acl;
5249  Acl *schema_acl;
5250  Acl *def_acl;
5251  char defaclobjtype;
5252 
5253  /*
5254  * Use NULL during bootstrap, since pg_default_acl probably isn't there
5255  * yet.
5256  */
5258  return NULL;
5259 
5260  /* Check if object type is supported in pg_default_acl */
5261  switch (objtype)
5262  {
5263  case ACL_OBJECT_RELATION:
5264  defaclobjtype = DEFACLOBJ_RELATION;
5265  break;
5266 
5267  case ACL_OBJECT_SEQUENCE:
5268  defaclobjtype = DEFACLOBJ_SEQUENCE;
5269  break;
5270 
5271  case ACL_OBJECT_FUNCTION:
5272  defaclobjtype = DEFACLOBJ_FUNCTION;
5273  break;
5274 
5275  case ACL_OBJECT_TYPE:
5276  defaclobjtype = DEFACLOBJ_TYPE;
5277  break;
5278 
5279  case ACL_OBJECT_NAMESPACE:
5280  defaclobjtype = DEFACLOBJ_NAMESPACE;
5281  break;
5282 
5283  default:
5284  return NULL;
5285  }
5286 
5287  /* Look up the relevant pg_default_acl entries */
5288  glob_acl = get_default_acl_internal(ownerId, InvalidOid, defaclobjtype);
5289  schema_acl = get_default_acl_internal(ownerId, nsp_oid, defaclobjtype);
5290 
5291  /* Quick out if neither entry exists */
5292  if (glob_acl == NULL && schema_acl == NULL)
5293  return NULL;
5294 
5295  /* We need to know the hard-wired default value, too */
5296  def_acl = acldefault(objtype, ownerId);
5297 
5298  /* If there's no global entry, substitute the hard-wired default */
5299  if (glob_acl == NULL)
5300  glob_acl = def_acl;
5301 
5302  /* Merge in any per-schema privileges */
5303  result = aclmerge(glob_acl, schema_acl, ownerId);
5304 
5305  /*
5306  * For efficiency, we want to return NULL if the result equals default.
5307  * This requires sorting both arrays to get an accurate comparison.
5308  */
5309  aclitemsort(result);
5310  aclitemsort(def_acl);
5311  if (aclequal(result, def_acl))
5312  result = NULL;
5313 
5314  return result;
5315 }
Acl * acldefault(GrantObjectType objtype, Oid ownerId)
Definition: acl.c:731
static Acl * get_default_acl_internal(Oid roleId, Oid nsp_oid, char objtype)
Definition: aclchk.c:5213
return result
Definition: formatting.c:1618
bool aclequal(const Acl *left_acl, const Acl *right_acl)
Definition: acl.c:508
#define DEFACLOBJ_SEQUENCE
#define DEFACLOBJ_TYPE
#define InvalidOid
Definition: postgres_ext.h:36
#define DEFACLOBJ_NAMESPACE
#define DEFACLOBJ_RELATION
Acl * aclmerge(const Acl *left_acl, const Acl *right_acl, Oid ownerId)
Definition: acl.c:450
#define NULL
Definition: c.h:229
#define DEFACLOBJ_FUNCTION
void aclitemsort(Acl *acl)
Definition: acl.c:494
#define IsBootstrapProcessingMode()
Definition: miscadmin.h:365
bool has_bypassrls_privilege ( Oid  roleid)

Definition at line 5189 of file aclchk.c.

References AUTHOID, GETSTRUCT, HeapTupleIsValid, ObjectIdGetDatum, ReleaseSysCache(), result, SearchSysCache1, and superuser_arg().

Referenced by check_enable_rls(), and RI_Initial_Check().

5190 {
5191  bool result = false;
5192  HeapTuple utup;
5193 
5194  /* Superusers bypass all permission checking. */
5195  if (superuser_arg(roleid))
5196  return true;
5197 
5198  utup = SearchSysCache1(AUTHOID, ObjectIdGetDatum(roleid));
5199  if (HeapTupleIsValid(utup))
5200  {
5201  result = ((Form_pg_authid) GETSTRUCT(utup))->rolbypassrls;
5202  ReleaseSysCache(utup);
5203  }
5204  return result;
5205 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
return result
Definition: formatting.c:1618
#define SearchSysCache1(cacheId, key1)
Definition: syscache.h:152
FormData_pg_authid * Form_pg_authid
Definition: pg_authid.h:72
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
bool superuser_arg(Oid roleid)
Definition: superuser.c:57
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1116
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
bool has_createrole_privilege ( Oid  roleid)

Definition at line 5170 of file aclchk.c.

References AUTHOID, GETSTRUCT, HeapTupleIsValid, ObjectIdGetDatum, ReleaseSysCache(), result, SearchSysCache1, and superuser_arg().

Referenced by check_object_ownership(), and have_createrole_privilege().

5171 {
5172  bool result = false;
5173  HeapTuple utup;
5174 
5175  /* Superusers bypass all permission checking. */
5176  if (superuser_arg(roleid))
5177  return true;
5178 
5179  utup = SearchSysCache1(AUTHOID, ObjectIdGetDatum(roleid));
5180  if (HeapTupleIsValid(utup))
5181  {
5182  result = ((Form_pg_authid) GETSTRUCT(utup))->rolcreaterole;
5183  ReleaseSysCache(utup);
5184  }
5185  return result;
5186 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
return result
Definition: formatting.c:1618
#define SearchSysCache1(cacheId, key1)
Definition: syscache.h:152
FormData_pg_authid * Form_pg_authid
Definition: pg_authid.h:72
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
bool superuser_arg(Oid roleid)
Definition: superuser.c:57
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1116
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
bool has_privs_of_role ( Oid  member,
Oid  role 
)

Definition at line 4813 of file acl.c.

References list_member_oid(), roles_has_privs_of(), and superuser_arg().

Referenced by aclmask(), AlterObjectNamespace_internal(), AlterObjectOwner_internal(), AlterObjectRename_internal(), check_role_for_policy(), DropOwnedObjects(), pg_class_ownercheck(), pg_collation_ownercheck(), pg_conversion_ownercheck(), pg_database_ownercheck(), pg_event_trigger_ownercheck(), pg_extension_ownercheck(), pg_foreign_data_wrapper_ownercheck(), pg_foreign_server_ownercheck(), pg_language_ownercheck(), pg_largeobject_ownercheck(), pg_namespace_ownercheck(), pg_opclass_ownercheck(), pg_oper_ownercheck(), pg_opfamily_ownercheck(), pg_proc_ownercheck(), pg_publication_ownercheck(), pg_role_aclcheck(), pg_signal_backend(), pg_stat_get_activity(), pg_stat_get_backend_activity(), pg_stat_get_backend_activity_start(), pg_stat_get_backend_client_addr(), pg_stat_get_backend_client_port(), pg_stat_get_backend_start(), pg_stat_get_backend_wait_event(), pg_stat_get_backend_wait_event_type(), pg_stat_get_backend_xact_start(), pg_stat_get_progress_info(), pg_statistics_ownercheck(), pg_subscription_ownercheck(), pg_tablespace_ownercheck(), pg_ts_config_ownercheck(), pg_ts_dict_ownercheck(), pg_type_ownercheck(), and ReassignOwnedObjects().

4814 {
4815  /* Fast path for simple case */
4816  if (member == role)
4817  return true;
4818 
4819  /* Superusers have every privilege, so are part of every role */
4820  if (superuser_arg(member))
4821  return true;
4822 
4823  /*
4824  * Find all the roles that member has the privileges of, including
4825  * multi-level recursion, then see if target role is any one of them.
4826  */
4827  return list_member_oid(roles_has_privs_of(member), role);
4828 }
static List * roles_has_privs_of(Oid roleid)
Definition: acl.c:4653
bool superuser_arg(Oid roleid)
Definition: superuser.c:57
bool list_member_oid(const List *list, Oid datum)
Definition: list.c:505
void initialize_acl ( void  )

Definition at line 4594 of file acl.c.

References AUTHMEMROLEMEM, CacheRegisterSyscacheCallback(), IsBootstrapProcessingMode, and RoleMembershipCacheCallback().

Referenced by InitPostgres().

4595 {
4597  {
4598  /*
4599  * In normal mode, set a callback on any syscache invalidation of
4600  * pg_auth_members rows
4601  */
4604  (Datum) 0);
4605  }
4606 }
void CacheRegisterSyscacheCallback(int cacheid, SyscacheCallbackFunction func, Datum arg)
Definition: inval.c:1381
uintptr_t Datum
Definition: postgres.h:372
static void RoleMembershipCacheCallback(Datum arg, int cacheid, uint32 hashvalue)
Definition: acl.c:4613
#define IsBootstrapProcessingMode()
Definition: miscadmin.h:365
bool is_admin_of_role ( Oid  member,
Oid  role 
)

Definition at line 4895 of file acl.c.

References AUTHMEMMEMROLE, GetSessionUserId(), GETSTRUCT, i, InLocalUserIdChange(), InSecurityRestrictedOperation(), lfirst_oid, list_append_unique_oid(), list_free(), list_make1_oid, catclist::members, catclist::n_members, ObjectIdGetDatum, ReleaseSysCacheList, result, SearchSysCacheList1, superuser_arg(), and catctup::tuple.

Referenced by AddRoleMems(), DelRoleMems(), and pg_role_aclcheck().

4896 {
4897  bool result = false;
4898  List *roles_list;
4899  ListCell *l;
4900 
4901  if (superuser_arg(member))
4902  return true;
4903 
4904  if (member == role)
4905 
4906  /*
4907  * A role can admin itself when it matches the session user and we're
4908  * outside any security-restricted operation, SECURITY DEFINER or
4909  * similar context. SQL-standard roles cannot self-admin. However,
4910  * SQL-standard users are distinct from roles, and they are not
4911  * grantable like roles: PostgreSQL's role-user duality extends the
4912  * standard. Checking for a session user match has the effect of
4913  * letting a role self-admin only when it's conspicuously behaving
4914  * like a user. Note that allowing self-admin under a mere SET ROLE
4915  * would make WITH ADMIN OPTION largely irrelevant; any member could
4916  * SET ROLE to issue the otherwise-forbidden command.
4917  *
4918  * Withholding self-admin in a security-restricted operation prevents
4919  * object owners from harnessing the session user identity during
4920  * administrative maintenance. Suppose Alice owns a database, has
4921  * issued "GRANT alice TO bob", and runs a daily ANALYZE. Bob creates
4922  * an alice-owned SECURITY DEFINER function that issues "REVOKE alice
4923  * FROM carol". If he creates an expression index calling that
4924  * function, Alice will attempt the REVOKE during each ANALYZE.
4925  * Checking InSecurityRestrictedOperation() thwarts that attack.
4926  *
4927  * Withholding self-admin in SECURITY DEFINER functions makes their
4928  * behavior independent of the calling user. There's no security or
4929  * SQL-standard-conformance need for that restriction, though.
4930  *
4931  * A role cannot have actual WITH ADMIN OPTION on itself, because that
4932  * would imply a membership loop. Therefore, we're done either way.
4933  */
4934  return member == GetSessionUserId() &&
4936 
4937  /*
4938  * Find all the roles that member is a member of, including multi-level
4939  * recursion. We build a list in the same way that is_member_of_role does
4940  * to track visited and unvisited roles.
4941  */
4942  roles_list = list_make1_oid(member);
4943 
4944  foreach(l, roles_list)
4945  {
4946  Oid memberid = lfirst_oid(l);
4947  CatCList *memlist;
4948  int i;
4949 
4950  /* Find roles that memberid is directly a member of */
4952  ObjectIdGetDatum(memberid));
4953  for (i = 0; i < memlist->n_members; i++)
4954  {
4955  HeapTuple tup = &memlist->members[i]->tuple;
4956  Oid otherid = ((Form_pg_auth_members) GETSTRUCT(tup))->roleid;
4957 
4958  if (otherid == role &&
4959  ((Form_pg_auth_members) GETSTRUCT(tup))->admin_option)
4960  {
4961  /* Found what we came for, so can stop searching */
4962  result = true;
4963  break;
4964  }
4965 
4966  roles_list = list_append_unique_oid(roles_list, otherid);
4967  }
4968  ReleaseSysCacheList(memlist);
4969  if (result)
4970  break;
4971  }
4972 
4973  list_free(roles_list);
4974 
4975  return result;
4976 }
bool InLocalUserIdChange(void)
Definition: miscinit.c:406
int n_members
Definition: catcache.h:154
List * list_append_unique_oid(List *list, Oid datum)
Definition: list.c:999
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
return result
Definition: formatting.c:1618
unsigned int Oid
Definition: postgres_ext.h:31
Oid GetSessionUserId(void)
Definition: miscinit.c:317
CatCTup * members[FLEXIBLE_ARRAY_MEMBER]
Definition: catcache.h:155
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define SearchSysCacheList1(cacheId, key1)
Definition: syscache.h:197
bool superuser_arg(Oid roleid)
Definition: superuser.c:57
#define ReleaseSysCacheList(x)
Definition: syscache.h:206
#define list_make1_oid(x1)
Definition: pg_list.h:145
FormData_pg_auth_members * Form_pg_auth_members
bool InSecurityRestrictedOperation(void)
Definition: miscinit.c:415
void list_free(List *list)
Definition: list.c:1133
int i
HeapTupleData tuple
Definition: catcache.h:116
Definition: pg_list.h:45
#define lfirst_oid(lc)
Definition: pg_list.h:108
bool is_member_of_role ( Oid  member,
Oid  role 
)

Definition at line 4837 of file acl.c.

References list_member_oid(), roles_is_member_of(), and superuser_arg().

Referenced by check_is_member_of_role(), check_role(), and pg_role_aclcheck().

4838 {
4839  /* Fast path for simple case */
4840  if (member == role)
4841  return true;
4842 
4843  /* Superusers have every privilege, so are part of every role */
4844  if (superuser_arg(member))
4845  return true;
4846 
4847  /*
4848  * Find all the roles that member is a member of, including multi-level
4849  * recursion, then see if target role is any one of them.
4850  */
4851  return list_member_oid(roles_is_member_of(member), role);
4852 }
static List * roles_is_member_of(Oid roleid)
Definition: acl.c:4736
bool superuser_arg(Oid roleid)
Definition: superuser.c:57
bool list_member_oid(const List *list, Oid datum)
Definition: list.c:505
bool is_member_of_role_nosuper ( Oid  member,
Oid  role 
)

Definition at line 4875 of file acl.c.

References list_member_oid(), and roles_is_member_of().

Referenced by AddRoleMems(), and is_member().

4876 {
4877  /* Fast path for simple case */
4878  if (member == role)
4879  return true;
4880 
4881  /*
4882  * Find all the roles that member is a member of, including multi-level
4883  * recursion, then see if target role is any one of them.
4884  */
4885  return list_member_oid(roles_is_member_of(member), role);
4886 }
static List * roles_is_member_of(Oid roleid)
Definition: acl.c:4736
bool list_member_oid(const List *list, Oid datum)
Definition: list.c:505
Acl* make_empty_acl ( void  )

Definition at line 397 of file acl.c.

References allocacl().

Referenced by SetDefaultACL().

398 {
399  return allocacl(0);
400 }
static Acl * allocacl(int n)
Definition: acl.c:375
AclResult pg_attribute_aclcheck ( Oid  table_oid,
AttrNumber  attnum,
Oid  roleid,
AclMode  mode 
)

Definition at line 4308 of file aclchk.c.

References ACLCHECK_NO_PRIV, ACLCHECK_OK, ACLMASK_ANY, and pg_attribute_aclmask().

Referenced by BuildIndexValueDescription(), checkFkeyPermissions(), column_privilege_check(), ExecBuildSlotPartitionKeyDescription(), ExecBuildSlotValueDescription(), ExecCheckRTEPerms(), ExecCheckRTEPermsModified(), and ri_ReportViolation().

4310 {
4311  if (pg_attribute_aclmask(table_oid, attnum, roleid, mode, ACLMASK_ANY) != 0)
4312  return ACLCHECK_OK;
4313  else
4314  return ACLCHECK_NO_PRIV;
4315 }
AclMode pg_attribute_aclmask(Oid table_oid, AttrNumber attnum, Oid roleid, AclMode mask, AclMaskHow how)
Definition: aclchk.c:3537
AclResult pg_attribute_aclcheck_all ( Oid  table_oid,
Oid  roleid,
AclMode  mode,
AclMaskHow  how 
)

Definition at line 4337 of file aclchk.c.

References ACLCHECK_NO_PRIV, ACLCHECK_OK, ACLMASK_ALL, ACLMASK_ANY, Anum_pg_attribute_attacl, ATTNUM, GETSTRUCT, heap_attisnull(), HeapTupleIsValid, Int16GetDatum, ObjectIdGetDatum, pg_attribute_aclmask(), ReleaseSysCache(), RELOID, result, SearchSysCache1, and SearchSysCache2.

Referenced by ExecCheckRTEPerms(), ExecCheckRTEPermsModified(), 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(), and has_any_column_privilege_name_name().

4339 {
4340  AclResult result;
4341  HeapTuple classTuple;
4342  Form_pg_class classForm;
4343  AttrNumber nattrs;
4344  AttrNumber curr_att;
4345 
4346  /*
4347  * Must fetch pg_class row to check number of attributes. As in
4348  * pg_attribute_aclmask, we prefer to return "no privileges" instead of
4349  * throwing an error if we get any unexpected lookup errors.
4350  */
4351  classTuple = SearchSysCache1(RELOID, ObjectIdGetDatum(table_oid));
4352  if (!HeapTupleIsValid(classTuple))
4353  return ACLCHECK_NO_PRIV;
4354  classForm = (Form_pg_class) GETSTRUCT(classTuple);
4355 
4356  nattrs = classForm->relnatts;
4357 
4358  ReleaseSysCache(classTuple);
4359 
4360  /*
4361  * Initialize result in case there are no non-dropped columns. We want to
4362  * report failure in such cases for either value of 'how'.
4363  */
4364  result = ACLCHECK_NO_PRIV;
4365 
4366  for (curr_att = 1; curr_att <= nattrs; curr_att++)
4367  {
4368  HeapTuple attTuple;
4369  AclMode attmask;
4370 
4371  attTuple = SearchSysCache2(ATTNUM,
4372  ObjectIdGetDatum(table_oid),
4373  Int16GetDatum(curr_att));
4374  if (!HeapTupleIsValid(attTuple))
4375  continue;
4376 
4377  /* ignore dropped columns */
4378  if (((Form_pg_attribute) GETSTRUCT(attTuple))->attisdropped)
4379  {
4380  ReleaseSysCache(attTuple);
4381  continue;
4382  }
4383 
4384  /*
4385  * Here we hard-wire knowledge that the default ACL for a column
4386  * grants no privileges, so that we can fall out quickly in the very
4387  * common case where attacl is null.
4388  */
4390  attmask = 0;
4391  else
4392  attmask = pg_attribute_aclmask(table_oid, curr_att, roleid,
4393  mode, ACLMASK_ANY);
4394 
4395  ReleaseSysCache(attTuple);
4396 
4397  if (attmask != 0)
4398  {
4399  result = ACLCHECK_OK;
4400  if (how == ACLMASK_ANY)
4401  break; /* succeed on any success */
4402  }
4403  else
4404  {
4405  result = ACLCHECK_NO_PRIV;
4406  if (how == ACLMASK_ALL)
4407  break; /* fail on any failure */
4408  }
4409  }
4410 
4411  return result;
4412 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
AclMode pg_attribute_aclmask(Oid table_oid, AttrNumber attnum, Oid roleid, AclMode mask, AclMaskHow how)
Definition: aclchk.c:3537
#define Int16GetDatum(X)
Definition: postgres.h:457
#define Anum_pg_attribute_attacl
Definition: pg_attribute.h:210
return result
Definition: formatting.c:1618
#define SearchSysCache1(cacheId, key1)
Definition: syscache.h:152
uint32 AclMode
Definition: parsenodes.h:63
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
bool heap_attisnull(HeapTuple tup, int attnum)
Definition: heaptuple.c:297
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:184
AclResult
Definition: acl.h:170
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1116
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
FormData_pg_class * Form_pg_class
Definition: pg_class.h:95
int16 AttrNumber
Definition: attnum.h:21
#define SearchSysCache2(cacheId, key1, key2)
Definition: syscache.h:154
AclMode pg_attribute_aclmask ( Oid  table_oid,
AttrNumber  attnum,
Oid  roleid,
AclMode  mask,
AclMaskHow  how 
)

Definition at line 3537 of file aclchk.c.

References aclmask(), Anum_pg_attribute_attacl, ATTNUM, DatumGetAclP, DatumGetPointer, ereport, errcode(), errmsg(), ERROR, GETSTRUCT, HeapTupleIsValid, Int16GetDatum, ObjectIdGetDatum, pfree(), ReleaseSysCache(), RELOID, result, SearchSysCache1, SearchSysCache2, and SysCacheGetAttr().

Referenced by pg_aclmask(), pg_attribute_aclcheck(), and pg_attribute_aclcheck_all().

3539 {
3540  AclMode result;
3541  HeapTuple classTuple;
3542  HeapTuple attTuple;
3543  Form_pg_class classForm;
3544  Form_pg_attribute attributeForm;
3545  Datum aclDatum;
3546  bool isNull;
3547  Acl *acl;
3548  Oid ownerId;
3549 
3550  /*
3551  * First, get the column's ACL from its pg_attribute entry
3552  */
3553  attTuple = SearchSysCache2(ATTNUM,
3554  ObjectIdGetDatum(table_oid),
3555  Int16GetDatum(attnum));
3556  if (!HeapTupleIsValid(attTuple))
3557  ereport(ERROR,
3558  (errcode(ERRCODE_UNDEFINED_COLUMN),
3559  errmsg("attribute %d of relation with OID %u does not exist",
3560  attnum, table_oid)));
3561  attributeForm = (Form_pg_attribute) GETSTRUCT(attTuple);
3562 
3563  /* Throw error on dropped columns, too */
3564  if (attributeForm->attisdropped)
3565  ereport(ERROR,
3566  (errcode(ERRCODE_UNDEFINED_COLUMN),
3567  errmsg("attribute %d of relation with OID %u does not exist",
3568  attnum, table_oid)));
3569 
3570  aclDatum = SysCacheGetAttr(ATTNUM, attTuple, Anum_pg_attribute_attacl,
3571  &isNull);
3572 
3573  /*
3574  * Here we hard-wire knowledge that the default ACL for a column grants no
3575  * privileges, so that we can fall out quickly in the very common case
3576  * where attacl is null.
3577  */
3578  if (isNull)
3579  {
3580  ReleaseSysCache(attTuple);
3581  return 0;
3582  }
3583 
3584  /*
3585  * Must get the relation's ownerId from pg_class. Since we already found
3586  * a pg_attribute entry, the only likely reason for this to fail is that a
3587  * concurrent DROP of the relation committed since then (which could only
3588  * happen if we don't have lock on the relation). We prefer to report "no
3589  * privileges" rather than failing in such a case, so as to avoid unwanted
3590  * failures in has_column_privilege() tests.
3591  */
3592  classTuple = SearchSysCache1(RELOID, ObjectIdGetDatum(table_oid));
3593  if (!HeapTupleIsValid(classTuple))
3594  {
3595  ReleaseSysCache(attTuple);
3596  return 0;
3597  }
3598  classForm = (Form_pg_class) GETSTRUCT(classTuple);
3599 
3600  ownerId = classForm->relowner;
3601 
3602  ReleaseSysCache(classTuple);
3603 
3604  /* detoast column's ACL if necessary */
3605  acl = DatumGetAclP(aclDatum);
3606 
3607  result = aclmask(acl, roleid, ownerId, mask, how);
3608 
3609  /* if we have a detoasted copy, free it */
3610  if (acl && (Pointer) acl != DatumGetPointer(aclDatum))
3611  pfree(acl);
3612 
3613  ReleaseSysCache(attTuple);
3614 
3615  return result;
3616 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
#define DatumGetAclP(X)
Definition: acl.h:113
AclMode aclmask(const Acl *acl, Oid roleid, Oid ownerId, AclMode mask, AclMaskHow how)
Definition: acl.c:1304
#define Int16GetDatum(X)
Definition: postgres.h:457
int errcode(int sqlerrcode)
Definition: elog.c:575
#define Anum_pg_attribute_attacl
Definition: pg_attribute.h:210
return result
Definition: formatting.c:1618
unsigned int Oid
Definition: postgres_ext.h:31
#define SearchSysCache1(cacheId, key1)
Definition: syscache.h:152
uint32 AclMode
Definition: parsenodes.h:63
void pfree(void *pointer)
Definition: mcxt.c:950
char * Pointer
Definition: c.h:245
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ERROR
Definition: elog.h:43
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:184
#define ereport(elevel, rest)
Definition: elog.h:122
uintptr_t Datum
Definition: postgres.h:372
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1116
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition: syscache.c:1278
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define DatumGetPointer(X)
Definition: postgres.h:555
FormData_pg_class * Form_pg_class
Definition: pg_class.h:95
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define SearchSysCache2(cacheId, key1, key2)
Definition: syscache.h:154
AclResult pg_class_aclcheck ( Oid  table_oid,
Oid  roleid,
AclMode  mode 
)

Definition at line 4422 of file aclchk.c.

References ACLCHECK_NO_PRIV, ACLCHECK_OK, ACLMASK_ANY, and pg_class_aclmask().

Referenced by BuildIndexValueDescription(), checkFkeyPermissions(), column_privilege_check(), CreateTrigger(), currtid_byrelname(), currtid_byreloid(), currval_oid(), do_setval(), ExecBuildSlotPartitionKeyDescription(), ExecBuildSlotValueDescription(), get_rel_from_relname(), 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_sequence_privilege_id(), has_sequence_privilege_id_id(), has_sequence_privilege_id_name(), has_sequence_privilege_name(), has_sequence_privilege_name_id(), has_sequence_privilege_name_name(), has_table_privilege_id(), has_table_privilege_id_id(), has_table_privilege_id_name(), has_table_privilege_name(), has_table_privilege_name_id(), has_table_privilege_name_name(), lastval(), LockTableAclCheck(), nextval_internal(), pg_prewarm(), pg_sequence_last_value(), pg_sequence_parameters(), pgrowlocks(), ri_ReportViolation(), transformTableLikeClause(), and truncate_check_rel().

4423 {
4424  if (pg_class_aclmask(table_oid, roleid, mode, ACLMASK_ANY) != 0)
4425  return ACLCHECK_OK;
4426  else
4427  return ACLCHECK_NO_PRIV;
4428 }
AclMode pg_class_aclmask(Oid table_oid, Oid roleid, AclMode mask, AclMaskHow how)
Definition: aclchk.c:3622
AclMode pg_class_aclmask ( Oid  table_oid,
Oid  roleid,
AclMode  mask,
AclMaskHow  how 
)

Definition at line 3622 of file aclchk.c.

References ACL_DELETE, ACL_INSERT, ACL_OBJECT_RELATION, ACL_OBJECT_SEQUENCE, ACL_TRUNCATE, ACL_UPDATE, ACL_USAGE, acldefault(), aclmask(), allowSystemTableMods, Anum_pg_class_relacl, DatumGetAclP, DatumGetPointer, DEBUG2, elog, ereport, errcode(), ERRCODE_UNDEFINED_TABLE, errmsg(), ERROR, GETSTRUCT, HeapTupleIsValid, IsSystemClass(), ObjectIdGetDatum, pfree(), ReleaseSysCache(), RELKIND_SEQUENCE, RELKIND_VIEW, RELOID, result, SearchSysCache1, superuser_arg(), and SysCacheGetAttr().

Referenced by ExecCheckRTEPerms(), pg_aclmask(), and pg_class_aclcheck().

3624 {
3625  AclMode result;
3626  HeapTuple tuple;
3627  Form_pg_class classForm;
3628  Datum aclDatum;
3629  bool isNull;
3630  Acl *acl;
3631  Oid ownerId;
3632 
3633  /*
3634  * Must get the relation's tuple from pg_class
3635  */
3636  tuple = SearchSysCache1(RELOID, ObjectIdGetDatum(table_oid));
3637  if (!HeapTupleIsValid(tuple))
3638  ereport(ERROR,
3640  errmsg("relation with OID %u does not exist",
3641  table_oid)));
3642  classForm = (Form_pg_class) GETSTRUCT(tuple);
3643 
3644  /*
3645  * Deny anyone permission to update a system catalog unless
3646  * pg_authid.rolsuper is set. Also allow it if allowSystemTableMods.
3647  *
3648  * As of 7.4 we have some updatable system views; those shouldn't be
3649  * protected in this way. Assume the view rules can take care of
3650  * themselves. ACL_USAGE is if we ever have system sequences.
3651  */
3652  if ((mask & (ACL_INSERT | ACL_UPDATE | ACL_DELETE | ACL_TRUNCATE | ACL_USAGE)) &&
3653  IsSystemClass(table_oid, classForm) &&
3654  classForm->relkind != RELKIND_VIEW &&
3655  !superuser_arg(roleid) &&
3657  {
3658 #ifdef ACLDEBUG
3659  elog(DEBUG2, "permission denied for system catalog update");
3660 #endif
3662  }
3663 
3664  /*
3665  * Otherwise, superusers bypass all permission-checking.
3666  */
3667  if (superuser_arg(roleid))
3668  {
3669 #ifdef ACLDEBUG
3670  elog(DEBUG2, "OID %u is superuser, home free", roleid);
3671 #endif
3672  ReleaseSysCache(tuple);
3673  return mask;
3674  }
3675 
3676  /*
3677  * Normal case: get the relation's ACL from pg_class
3678  */
3679  ownerId = classForm->relowner;
3680 
3681  aclDatum = SysCacheGetAttr(RELOID, tuple, Anum_pg_class_relacl,
3682  &isNull);
3683  if (isNull)
3684  {
3685  /* No ACL, so build default ACL */
3686  switch (classForm->relkind)
3687  {
3688  case RELKIND_SEQUENCE:
3689  acl = acldefault(ACL_OBJECT_SEQUENCE, ownerId);
3690  break;
3691  default:
3692  acl = acldefault(ACL_OBJECT_RELATION, ownerId);
3693  break;
3694  }
3695  aclDatum = (Datum) 0;
3696  }
3697  else
3698  {
3699  /* detoast rel's ACL if necessary */
3700  acl = DatumGetAclP(aclDatum);
3701  }
3702 
3703  result = aclmask(acl, roleid, ownerId, mask, how);
3704 
3705  /* if we have a detoasted copy, free it */
3706  if (acl && (Pointer) acl != DatumGetPointer(aclDatum))
3707  pfree(acl);
3708 
3709  ReleaseSysCache(tuple);
3710 
3711  return result;
3712 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
#define ERRCODE_UNDEFINED_TABLE
Definition: pgbench.c:61
#define Anum_pg_class_relacl
Definition: pg_class.h:133
#define DatumGetAclP(X)
Definition: acl.h:113
AclMode aclmask(const Acl *acl, Oid roleid, Oid ownerId, AclMode mask, AclMaskHow how)
Definition: acl.c:1304
Acl * acldefault(GrantObjectType objtype, Oid ownerId)
Definition: acl.c:731
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ACL_DELETE
Definition: parsenodes.h:68
return result
Definition: formatting.c:1618
unsigned int Oid
Definition: postgres_ext.h:31
#define SearchSysCache1(cacheId, key1)
Definition: syscache.h:152
bool IsSystemClass(Oid relid, Form_pg_class reltuple)
Definition: catalog.c:74
uint32 AclMode
Definition: parsenodes.h:63
void pfree(void *pointer)
Definition: mcxt.c:950
char * Pointer
Definition: c.h:245
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ERROR
Definition: elog.h:43
#define DEBUG2
Definition: elog.h:24
#define ACL_USAGE
Definition: parsenodes.h:73
#define ereport(elevel, rest)
Definition: elog.h:122
bool superuser_arg(Oid roleid)
Definition: superuser.c:57
#define ACL_UPDATE
Definition: parsenodes.h:67
uintptr_t Datum
Definition: postgres.h:372
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1116
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition: syscache.c:1278
bool allowSystemTableMods
Definition: globals.c:111
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define ACL_INSERT
Definition: parsenodes.h:65
#define DatumGetPointer(X)
Definition: postgres.h:555
FormData_pg_class * Form_pg_class
Definition: pg_class.h:95
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define RELKIND_VIEW
Definition: pg_class.h:164
#define elog
Definition: elog.h:219
#define RELKIND_SEQUENCE
Definition: pg_class.h:162
#define ACL_TRUNCATE
Definition: parsenodes.h:69
bool pg_class_ownercheck ( Oid  class_oid,
Oid  roleid 
)

Definition at line 4546 of file aclchk.c.

References ereport, errcode(), ERRCODE_UNDEFINED_TABLE, errmsg(), ERROR, GETSTRUCT, has_privs_of_role(), HeapTupleIsValid, ObjectIdGetDatum, ReleaseSysCache(), RELOID, SearchSysCache1, and superuser_arg().

Referenced by AlterSequence(), AlterTableMoveAll(), analyze_rel(), ATExecChangeOwner(), ATPrepSetStatistics(), ATSimplePermissions(), brin_summarize_new_values(), check_enable_rls(), check_object_ownership(), cluster_rel(), DefineQueryRewrite(), EnableDisableRule(), ExecuteTruncate(), get_tables_to_cluster(), gin_clean_pending_list(), MergeAttributes(), PublicationAddTables(), RangeVarCallbackForAlterRelation(), RangeVarCallbackForDropRelation(), RangeVarCallbackForPolicy(), RangeVarCallbackForReindexIndex(), RangeVarCallbackForRenameRule(), RangeVarCallbackForRenameTrigger(), RangeVarCallbackOwnsRelation(), RangeVarCallbackOwnsTable(), RangeVarGetAndCheckCreationNamespace(), RemoveRoleFromObjectPolicy(), renameatt_check(), RI_Initial_Check(), and vacuum_rel().

4547 {
4548  HeapTuple tuple;
4549  Oid ownerId;
4550 
4551  /* Superusers bypass all permission checking. */
4552  if (superuser_arg(roleid))
4553  return true;
4554 
4555  tuple = SearchSysCache1(RELOID, ObjectIdGetDatum(class_oid));
4556  if (!HeapTupleIsValid(tuple))
4557  ereport(ERROR,
4559  errmsg("relation with OID %u does not exist", class_oid)));
4560 
4561  ownerId = ((Form_pg_class) GETSTRUCT(tuple))->relowner;
4562 
4563  ReleaseSysCache(tuple);
4564 
4565  return has_privs_of_role(roleid, ownerId);
4566 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
#define ERRCODE_UNDEFINED_TABLE
Definition: pgbench.c:61
bool has_privs_of_role(Oid member, Oid role)
Definition: acl.c:4813
int errcode(int sqlerrcode)
Definition: elog.c:575
unsigned int Oid
Definition: postgres_ext.h:31
#define SearchSysCache1(cacheId, key1)
Definition: syscache.h:152
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
bool superuser_arg(Oid roleid)
Definition: superuser.c:57
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1116
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
FormData_pg_class * Form_pg_class
Definition: pg_class.h:95
int errmsg(const char *fmt,...)
Definition: elog.c:797
bool pg_collation_ownercheck ( Oid  coll_oid,
Oid  roleid 
)

Definition at line 4990 of file aclchk.c.

References COLLOID, ereport, errcode(), errmsg(), ERROR, GETSTRUCT, has_privs_of_role(), HeapTupleIsValid, ObjectIdGetDatum, ReleaseSysCache(), SearchSysCache1, and superuser_arg().

Referenced by AlterCollation(), and check_object_ownership().

4991 {
4992  HeapTuple tuple;
4993  Oid ownerId;
4994 
4995  /* Superusers bypass all permission checking. */
4996  if (superuser_arg(roleid))
4997  return true;
4998 
4999  tuple = SearchSysCache1(COLLOID, ObjectIdGetDatum(coll_oid));
5000  if (!HeapTupleIsValid(tuple))
5001  ereport(ERROR,
5002  (errcode(ERRCODE_UNDEFINED_OBJECT),
5003  errmsg("collation with OID %u does not exist", coll_oid)));
5004 
5005  ownerId = ((Form_pg_collation) GETSTRUCT(tuple))->collowner;
5006 
5007  ReleaseSysCache(tuple);
5008 
5009  return has_privs_of_role(roleid, ownerId);
5010 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
bool has_privs_of_role(Oid member, Oid role)
Definition: acl.c:4813
int errcode(int sqlerrcode)
Definition: elog.c:575
unsigned int Oid
Definition: postgres_ext.h:31
#define SearchSysCache1(cacheId, key1)
Definition: syscache.h:152
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
bool superuser_arg(Oid roleid)
Definition: superuser.c:57
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1116
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
FormData_pg_collation * Form_pg_collation
Definition: pg_collation.h:51
int errmsg(const char *fmt,...)
Definition: elog.c:797
bool pg_conversion_ownercheck ( Oid  conv_oid,
Oid  roleid 
)

Definition at line 5016 of file aclchk.c.

References CONVOID, ereport, errcode(), errmsg(), ERROR, GETSTRUCT, has_privs_of_role(), HeapTupleIsValid, ObjectIdGetDatum, ReleaseSysCache(), SearchSysCache1, and superuser_arg().

Referenced by check_object_ownership().

5017 {
5018  HeapTuple tuple;
5019  Oid ownerId;
5020 
5021  /* Superusers bypass all permission checking. */
5022  if (superuser_arg(roleid))
5023  return true;
5024 
5025  tuple = SearchSysCache1(CONVOID, ObjectIdGetDatum(conv_oid));
5026  if (!HeapTupleIsValid(tuple))
5027  ereport(ERROR,
5028  (errcode(ERRCODE_UNDEFINED_OBJECT),
5029  errmsg("conversion with OID %u does not exist", conv_oid)));
5030 
5031  ownerId = ((Form_pg_conversion) GETSTRUCT(tuple))->conowner;
5032 
5033  ReleaseSysCache(tuple);
5034 
5035  return has_privs_of_role(roleid, ownerId);
5036 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
bool has_privs_of_role(Oid member, Oid role)
Definition: acl.c:4813
int errcode(int sqlerrcode)
Definition: elog.c:575
unsigned int Oid
Definition: postgres_ext.h:31
#define SearchSysCache1(cacheId, key1)
Definition: syscache.h:152
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
bool superuser_arg(Oid roleid)
Definition: superuser.c:57
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1116
FormData_pg_conversion * Form_pg_conversion
Definition: pg_conversion.h:56
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
int errmsg(const char *fmt,...)
Definition: elog.c:797
AclMode pg_database_aclmask ( Oid  db_oid,
Oid  roleid,
AclMode  mask,
AclMaskHow  how 
)

Definition at line 3718 of file aclchk.c.

References ACL_OBJECT_DATABASE, acldefault(), aclmask(), Anum_pg_database_datacl, DATABASEOID, DatumGetAclP, DatumGetPointer, ereport, errcode(), errmsg(), ERROR, GETSTRUCT, HeapTupleIsValid, ObjectIdGetDatum, pfree(), ReleaseSysCache(), result, SearchSysCache1, superuser_arg(), and SysCacheGetAttr().

Referenced by pg_aclmask(), and pg_database_aclcheck().

3720 {
3721  AclMode result;
3722  HeapTuple tuple;
3723  Datum aclDatum;
3724  bool isNull;
3725  Acl *acl;
3726  Oid ownerId;
3727 
3728  /* Superusers bypass all permission checking. */
3729  if (superuser_arg(roleid))
3730  return mask;
3731 
3732  /*
3733  * Get the database's ACL from pg_database
3734  */
3735  tuple = SearchSysCache1(DATABASEOID, ObjectIdGetDatum(db_oid));
3736  if (!HeapTupleIsValid(tuple))
3737  ereport(ERROR,
3738  (errcode(ERRCODE_UNDEFINED_DATABASE),
3739  errmsg("database with OID %u does not exist", db_oid)));
3740 
3741  ownerId = ((Form_pg_database) GETSTRUCT(tuple))->datdba;
3742 
3744  &isNull);
3745  if (isNull)
3746  {
3747  /* No ACL, so build default ACL */
3748  acl = acldefault(ACL_OBJECT_DATABASE, ownerId);
3749  aclDatum = (Datum) 0;
3750  }
3751  else
3752  {
3753  /* detoast ACL if necessary */
3754  acl = DatumGetAclP(aclDatum);
3755  }
3756 
3757  result = aclmask(acl, roleid, ownerId, mask, how);
3758 
3759  /* if we have a detoasted copy, free it */
3760  if (acl && (Pointer) acl != DatumGetPointer(aclDatum))
3761  pfree(acl);
3762 
3763  ReleaseSysCache(tuple);
3764 
3765  return result;
3766 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
FormData_pg_database * Form_pg_database
Definition: pg_database.h:57
#define DatumGetAclP(X)
Definition: acl.h:113
AclMode aclmask(const Acl *acl, Oid roleid, Oid ownerId, AclMode mask, AclMaskHow how)
Definition: acl.c:1304
Acl * acldefault(GrantObjectType objtype, Oid ownerId)
Definition: acl.c:731
int errcode(int sqlerrcode)
Definition: elog.c:575
return result
Definition: formatting.c:1618
unsigned int Oid
Definition: postgres_ext.h:31
#define SearchSysCache1(cacheId, key1)
Definition: syscache.h:152
uint32 AclMode
Definition: parsenodes.h:63
void pfree(void *pointer)
Definition: mcxt.c:950
char * Pointer
Definition: c.h:245
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
bool superuser_arg(Oid roleid)
Definition: superuser.c:57
#define Anum_pg_database_datacl
Definition: pg_database.h:76
uintptr_t Datum
Definition: postgres.h:372
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1116
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition: syscache.c:1278
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define DatumGetPointer(X)
Definition: postgres.h:555
int errmsg(const char *fmt,...)
Definition: elog.c:797
bool pg_database_ownercheck ( Oid  db_oid,
Oid  roleid 
)

Definition at line 4964 of file aclchk.c.

References DATABASEOID, ereport, errcode(), errmsg(), ERROR, GETSTRUCT, has_privs_of_role(), HeapTupleIsValid, ObjectIdGetDatum, ReleaseSysCache(), SearchSysCache1, and superuser_arg().

Referenced by AlterDatabase(), AlterDatabaseOwner(), AlterDatabaseSet(), AlterRoleSet(), analyze_rel(), check_object_ownership(), createdb(), CreateProceduralLanguage(), dropdb(), movedb(), ReindexMultipleTables(), RenameDatabase(), and vacuum_rel().

4965 {
4966  HeapTuple tuple;
4967  Oid dba;
4968 
4969  /* Superusers bypass all permission checking. */
4970  if (superuser_arg(roleid))
4971  return true;
4972 
4973  tuple = SearchSysCache1(DATABASEOID, ObjectIdGetDatum(db_oid));
4974  if (!HeapTupleIsValid(tuple))
4975  ereport(ERROR,
4976  (errcode(ERRCODE_UNDEFINED_DATABASE),
4977  errmsg("database with OID %u does not exist", db_oid)));
4978 
4979  dba = ((Form_pg_database) GETSTRUCT(tuple))->datdba;
4980 
4981  ReleaseSysCache(tuple);
4982 
4983  return has_privs_of_role(roleid, dba);
4984 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
FormData_pg_database * Form_pg_database
Definition: pg_database.h:57
bool has_privs_of_role(Oid member, Oid role)
Definition: acl.c:4813
int errcode(int sqlerrcode)
Definition: elog.c:575
unsigned int Oid
Definition: postgres_ext.h:31
#define SearchSysCache1(cacheId, key1)
Definition: syscache.h:152
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
bool superuser_arg(Oid roleid)
Definition: superuser.c:57
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1116
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
int errmsg(const char *fmt,...)
Definition: elog.c:797
bool pg_event_trigger_ownercheck ( Oid  et_oid,
Oid  roleid 
)

Definition at line 4937 of file aclchk.c.

References ereport, errcode(), errmsg(), ERROR, EVENTTRIGGEROID, GETSTRUCT, has_privs_of_role(), HeapTupleIsValid, ObjectIdGetDatum, ReleaseSysCache(), SearchSysCache1, and superuser_arg().

Referenced by AlterEventTrigger(), AlterEventTriggerOwner_internal(), and check_object_ownership().

4938 {
4939  HeapTuple tuple;
4940  Oid ownerId;
4941 
4942  /* Superusers bypass all permission checking. */
4943  if (superuser_arg(roleid))
4944  return true;
4945 
4947  if (!HeapTupleIsValid(tuple))
4948  ereport(ERROR,
4949  (errcode(ERRCODE_UNDEFINED_OBJECT),
4950  errmsg("event trigger with OID %u does not exist",
4951  et_oid)));
4952 
4953  ownerId = ((Form_pg_event_trigger) GETSTRUCT(tuple))->evtowner;
4954 
4955  ReleaseSysCache(tuple);
4956 
4957  return has_privs_of_role(roleid, ownerId);
4958 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
bool has_privs_of_role(Oid member, Oid role)
Definition: acl.c:4813
int errcode(int sqlerrcode)
Definition: elog.c:575
unsigned int Oid
Definition: postgres_ext.h:31
#define SearchSysCache1(cacheId, key1)
Definition: syscache.h:152
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
bool superuser_arg(Oid roleid)
Definition: superuser.c:57
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1116
FormData_pg_event_trigger * Form_pg_event_trigger
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
int errmsg(const char *fmt,...)
Definition: elog.c:797
bool pg_extension_ownercheck ( Oid  ext_oid,
Oid  roleid 
)

Definition at line 5042 of file aclchk.c.

References AccessShareLock, BTEqualStrategyNumber, ereport, errcode(), errmsg(), ERROR, ExtensionOidIndexId, ExtensionRelationId, GETSTRUCT, has_privs_of_role(), heap_close, heap_open(), HeapTupleIsValid, NULL, ObjectIdAttributeNumber, ObjectIdGetDatum, ScanKeyInit(), superuser_arg(), systable_beginscan(), systable_endscan(), and systable_getnext().

Referenced by AlterExtensionNamespace(), check_object_ownership(), ExecAlterExtensionContentsStmt(), and ExecAlterExtensionStmt().

5043 {
5044  Relation pg_extension;
5045  ScanKeyData entry[1];
5046  SysScanDesc scan;
5047  HeapTuple tuple;
5048  Oid ownerId;
5049 
5050  /* Superusers bypass all permission checking. */
5051  if (superuser_arg(roleid))
5052  return true;
5053 
5054  /* There's no syscache for pg_extension, so do it the hard way */
5056 
5057  ScanKeyInit(&entry[0],
5059  BTEqualStrategyNumber, F_OIDEQ,
5060  ObjectIdGetDatum(ext_oid));
5061 
5062  scan = systable_beginscan(pg_extension,
5063  ExtensionOidIndexId, true,
5064  NULL, 1, entry);
5065 
5066  tuple = systable_getnext(scan);
5067  if (!HeapTupleIsValid(tuple))
5068  ereport(ERROR,
5069  (errcode(ERRCODE_UNDEFINED_OBJECT),
5070  errmsg("extension with OID %u does not exist", ext_oid)));
5071 
5072  ownerId = ((Form_pg_extension) GETSTRUCT(tuple))->extowner;
5073 
5074  systable_endscan(scan);
5075  heap_close(pg_extension, AccessShareLock);
5076 
5077  return has_privs_of_role(roleid, ownerId);
5078 }
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:499
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
#define ObjectIdAttributeNumber
Definition: sysattr.h:22
bool has_privs_of_role(Oid member, Oid role)
Definition: acl.c:4813
#define AccessShareLock
Definition: lockdefs.h:36
int errcode(int sqlerrcode)
Definition: elog.c:575
#define heap_close(r, l)
Definition: heapam.h:97
unsigned int Oid
Definition: postgres_ext.h:31
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:328
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:416
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
bool superuser_arg(Oid roleid)
Definition: superuser.c:57
#define ExtensionOidIndexId
Definition: indexing.h:319
FormData_pg_extension * Form_pg_extension
Definition: pg_extension.h:51
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1284
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define NULL
Definition: c.h:229
int errmsg(const char *fmt,...)
Definition: elog.c:797
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
#define ExtensionRelationId
Definition: pg_extension.h:29
#define BTEqualStrategyNumber
Definition: stratnum.h:31
AclResult pg_foreign_data_wrapper_aclcheck ( Oid  fdw_oid,
Oid  roleid,
AclMode  mode 
)
AclMode pg_foreign_data_wrapper_aclmask ( Oid  fdw_oid,
Oid  roleid,
AclMode  mask,
AclMaskHow  how 
)

Definition at line 4101 of file aclchk.c.

References ACL_OBJECT_FDW, acldefault(), aclmask(), Anum_pg_foreign_data_wrapper_fdwacl, DatumGetAclP, DatumGetPointer, ereport, errcode(), errmsg(), ERROR, FOREIGNDATAWRAPPEROID, GETSTRUCT, HeapTupleIsValid, ObjectIdGetDatum, pfree(), ReleaseSysCache(), result, SearchSysCache1, superuser_arg(), and SysCacheGetAttr().

Referenced by pg_aclmask(), and pg_foreign_data_wrapper_aclcheck().

4103 {
4104  AclMode result;
4105  HeapTuple tuple;
4106  Datum aclDatum;
4107  bool isNull;
4108  Acl *acl;
4109  Oid ownerId;
4110 
4112 
4113  /* Bypass permission checks for superusers */
4114  if (superuser_arg(roleid))
4115  return mask;
4116 
4117  /*
4118  * Must get the FDW's tuple from pg_foreign_data_wrapper
4119  */
4121  if (!HeapTupleIsValid(tuple))
4122  ereport(ERROR,
4123  (errcode(ERRCODE_UNDEFINED_OBJECT),
4124  errmsg("foreign-data wrapper with OID %u does not exist",
4125  fdw_oid)));
4126  fdwForm = (Form_pg_foreign_data_wrapper) GETSTRUCT(tuple);
4127 
4128  /*
4129  * Normal case: get the FDW's ACL from pg_foreign_data_wrapper
4130  */
4131  ownerId = fdwForm->fdwowner;
4132 
4133  aclDatum = SysCacheGetAttr(FOREIGNDATAWRAPPEROID, tuple,
4135  if (isNull)
4136  {
4137  /* No ACL, so build default ACL */
4138  acl = acldefault(ACL_OBJECT_FDW, ownerId);
4139  aclDatum = (Datum) 0;
4140  }
4141  else
4142  {
4143  /* detoast rel's ACL if necessary */
4144  acl = DatumGetAclP(aclDatum);
4145  }
4146 
4147  result = aclmask(acl, roleid, ownerId, mask, how);
4148 
4149  /* if we have a detoasted copy, free it */
4150  if (acl && (Pointer) acl != DatumGetPointer(aclDatum))
4151  pfree(acl);
4152 
4153  ReleaseSysCache(tuple);
4154 
4155  return result;
4156 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
#define DatumGetAclP(X)
Definition: acl.h:113
AclMode aclmask(const Acl *acl, Oid roleid, Oid ownerId, AclMode mask, AclMaskHow how)
Definition: acl.c:1304
Acl * acldefault(GrantObjectType objtype, Oid ownerId)
Definition: acl.c:731
int errcode(int sqlerrcode)
Definition: elog.c:575
return result
Definition: formatting.c:1618
unsigned int Oid
Definition: postgres_ext.h:31
#define SearchSysCache1(cacheId, key1)
Definition: syscache.h:152
#define Anum_pg_foreign_data_wrapper_fdwacl
uint32 AclMode
Definition: parsenodes.h:63
void pfree(void *pointer)
Definition: mcxt.c:950
char * Pointer
Definition: c.h:245
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
bool superuser_arg(Oid roleid)
Definition: superuser.c:57
uintptr_t Datum
Definition: postgres.h:372
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1116
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition: syscache.c:1278
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
FormData_pg_foreign_data_wrapper * Form_pg_foreign_data_wrapper
#define DatumGetPointer(X)
Definition: postgres.h:555
int errmsg(const char *fmt,...)
Definition: elog.c:797
bool pg_foreign_data_wrapper_ownercheck ( Oid  srv_oid,
Oid  roleid 
)

Definition at line 4883 of file aclchk.c.

References ereport, errcode(), errmsg(), ERROR, FOREIGNDATAWRAPPEROID, GETSTRUCT, has_privs_of_role(), HeapTupleIsValid, ObjectIdGetDatum, ReleaseSysCache(), SearchSysCache1, and superuser_arg().

Referenced by check_object_ownership().

4884 {
4885  HeapTuple tuple;
4886  Oid ownerId;
4887 
4888  /* Superusers bypass all permission checking. */
4889  if (superuser_arg(roleid))
4890  return true;
4891 
4893  if (!HeapTupleIsValid(tuple))
4894  ereport(ERROR,
4895  (errcode(ERRCODE_UNDEFINED_OBJECT),
4896  errmsg("foreign-data wrapper with OID %u does not exist",
4897  srv_oid)));
4898 
4899  ownerId = ((Form_pg_foreign_data_wrapper) GETSTRUCT(tuple))->fdwowner;
4900 
4901  ReleaseSysCache(tuple);
4902 
4903  return has_privs_of_role(roleid, ownerId);
4904 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
bool has_privs_of_role(Oid member, Oid role)
Definition: acl.c:4813
int errcode(int sqlerrcode)
Definition: elog.c:575
unsigned int Oid
Definition: postgres_ext.h:31
#define SearchSysCache1(cacheId, key1)
Definition: syscache.h:152
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
bool superuser_arg(Oid roleid)
Definition: superuser.c:57
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1116
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
FormData_pg_foreign_data_wrapper * Form_pg_foreign_data_wrapper
int errmsg(const char *fmt,...)
Definition: elog.c:797
AclResult pg_foreign_server_aclcheck ( Oid  srv_oid,
Oid  roleid,
AclMode  mode 
)
AclMode pg_foreign_server_aclmask ( Oid  srv_oid,
Oid  roleid,
AclMode  mask,
AclMaskHow  how 
)

Definition at line 4163 of file aclchk.c.

References ACL_OBJECT_FOREIGN_SERVER, acldefault(), aclmask(), Anum_pg_foreign_server_srvacl, DatumGetAclP, DatumGetPointer, ereport, errcode(), errmsg(), ERROR, FOREIGNSERVEROID, GETSTRUCT, HeapTupleIsValid, ObjectIdGetDatum, pfree(), ReleaseSysCache(), result, SearchSysCache1, superuser_arg(), and SysCacheGetAttr().

Referenced by pg_aclmask(), and pg_foreign_server_aclcheck().

4165 {
4166  AclMode result;
4167  HeapTuple tuple;
4168  Datum aclDatum;
4169  bool isNull;
4170  Acl *acl;
4171  Oid ownerId;
4172 
4173  Form_pg_foreign_server srvForm;
4174 
4175  /* Bypass permission checks for superusers */
4176  if (superuser_arg(roleid))
4177  return mask;
4178 
4179  /*
4180  * Must get the FDW's tuple from pg_foreign_data_wrapper
4181  */
4183  if (!HeapTupleIsValid(tuple))
4184  ereport(ERROR,
4185  (errcode(ERRCODE_UNDEFINED_OBJECT),
4186  errmsg("foreign server with OID %u does not exist",
4187  srv_oid)));
4188  srvForm = (Form_pg_foreign_server) GETSTRUCT(tuple);
4189 
4190  /*
4191  * Normal case: get the foreign server's ACL from pg_foreign_server
4192  */
4193  ownerId = srvForm->srvowner;
4194 
4195  aclDatum = SysCacheGetAttr(FOREIGNSERVEROID, tuple,
4197  if (isNull)
4198  {
4199  /* No ACL, so build default ACL */
4200  acl = acldefault(ACL_OBJECT_FOREIGN_SERVER, ownerId);
4201  aclDatum = (Datum) 0;
4202  }
4203  else
4204  {
4205  /* detoast rel's ACL if necessary */
4206  acl = DatumGetAclP(aclDatum);
4207  }
4208 
4209  result = aclmask(acl, roleid, ownerId, mask, how);
4210 
4211  /* if we have a detoasted copy, free it */
4212  if (acl && (Pointer) acl != DatumGetPointer(aclDatum))
4213  pfree(acl);
4214 
4215  ReleaseSysCache(tuple);
4216 
4217  return result;
4218 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
#define DatumGetAclP(X)
Definition: acl.h:113
AclMode aclmask(const Acl *acl, Oid roleid, Oid ownerId, AclMode mask, AclMaskHow how)
Definition: acl.c:1304
Acl * acldefault(GrantObjectType objtype, Oid ownerId)
Definition: acl.c:731
int errcode(int sqlerrcode)
Definition: elog.c:575
return result
Definition: formatting.c:1618
unsigned int Oid
Definition: postgres_ext.h:31
#define SearchSysCache1(cacheId, key1)
Definition: syscache.h:152
uint32 AclMode
Definition: parsenodes.h:63
void pfree(void *pointer)
Definition: mcxt.c:950
char * Pointer
Definition: c.h:245
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
bool superuser_arg(Oid roleid)
Definition: superuser.c:57
#define Anum_pg_foreign_server_srvacl
uintptr_t Datum
Definition: postgres.h:372
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1116
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition: syscache.c:1278
FormData_pg_foreign_server * Form_pg_foreign_server
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define DatumGetPointer(X)
Definition: postgres.h:555
int errmsg(const char *fmt,...)
Definition: elog.c:797
bool pg_foreign_server_ownercheck ( Oid  srv_oid,
Oid  roleid 
)

Definition at line 4910 of file aclchk.c.

References ereport, errcode(), errmsg(), ERROR, FOREIGNSERVEROID, GETSTRUCT, has_privs_of_role(), HeapTupleIsValid, ObjectIdGetDatum, ReleaseSysCache(), SearchSysCache1, and superuser_arg().

Referenced by AlterForeignServer(), AlterForeignServerOwner_internal(), check_object_ownership(), and user_mapping_ddl_aclcheck().

4911 {
4912  HeapTuple tuple;
4913  Oid ownerId;
4914 
4915  /* Superusers bypass all permission checking. */
4916  if (superuser_arg(roleid))
4917  return true;
4918 
4920  if (!HeapTupleIsValid(tuple))
4921  ereport(ERROR,
4922  (errcode(ERRCODE_UNDEFINED_OBJECT),
4923  errmsg("foreign server with OID %u does not exist",
4924  srv_oid)));
4925 
4926  ownerId = ((Form_pg_foreign_server) GETSTRUCT(tuple))->srvowner;
4927 
4928  ReleaseSysCache(tuple);
4929 
4930  return has_privs_of_role(roleid, ownerId);
4931 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
bool has_privs_of_role(Oid member, Oid role)
Definition: acl.c:4813
int errcode(int sqlerrcode)
Definition: elog.c:575
unsigned int Oid
Definition: postgres_ext.h:31
#define SearchSysCache1(cacheId, key1)
Definition: syscache.h:152
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
bool superuser_arg(Oid roleid)
Definition: superuser.c:57
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1116
FormData_pg_foreign_server * Form_pg_foreign_server
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
int errmsg(const char *fmt,...)
Definition: elog.c:797
AclResult pg_language_aclcheck ( Oid  lang_oid,
Oid  roleid,
AclMode  mode 
)

Definition at line 4458 of file aclchk.c.

References ACLCHECK_NO_PRIV, ACLCHECK_OK, ACLMASK_ANY, and pg_language_aclmask().

Referenced by CheckFunctionValidatorAccess(), CreateFunction(), CreateTransform(), ExecuteDoStmt(), 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().

4459 {
4460  if (pg_language_aclmask(lang_oid, roleid, mode, ACLMASK_ANY) != 0)
4461  return ACLCHECK_OK;
4462  else
4463  return ACLCHECK_NO_PRIV;
4464 }
AclMode pg_language_aclmask(Oid lang_oid, Oid roleid, AclMode mask, AclMaskHow how)
Definition: aclchk.c:3826
AclMode pg_language_aclmask ( Oid  lang_oid,
Oid  roleid,
AclMode  mask,
AclMaskHow  how 
)

Definition at line 3826 of file aclchk.c.

References ACL_OBJECT_LANGUAGE, acldefault(), aclmask(), Anum_pg_language_lanacl, DatumGetAclP, DatumGetPointer, ereport, errcode(), errmsg(), ERROR, GETSTRUCT, HeapTupleIsValid, LANGOID, ObjectIdGetDatum, pfree(), ReleaseSysCache(), result, SearchSysCache1, superuser_arg(), and SysCacheGetAttr().

Referenced by pg_aclmask(), and pg_language_aclcheck().

3828 {
3829  AclMode result;
3830  HeapTuple tuple;
3831  Datum aclDatum;
3832  bool isNull;
3833  Acl *acl;
3834  Oid ownerId;
3835 
3836  /* Superusers bypass all permission checking. */
3837  if (superuser_arg(roleid))
3838  return mask;
3839 
3840  /*
3841  * Get the language's ACL from pg_language
3842  */
3843  tuple = SearchSysCache1(LANGOID, ObjectIdGetDatum(lang_oid));
3844  if (!HeapTupleIsValid(tuple))
3845  ereport(ERROR,
3846  (errcode(ERRCODE_UNDEFINED_OBJECT),
3847  errmsg("language with OID %u does not exist", lang_oid)));
3848 
3849  ownerId = ((Form_pg_language) GETSTRUCT(tuple))->lanowner;
3850 
3851  aclDatum = SysCacheGetAttr(LANGOID, tuple, Anum_pg_language_lanacl,
3852  &isNull);
3853  if (isNull)
3854  {
3855  /* No ACL, so build default ACL */
3856  acl = acldefault(ACL_OBJECT_LANGUAGE, ownerId);
3857  aclDatum = (Datum) 0;
3858  }
3859  else
3860  {
3861  /* detoast ACL if necessary */
3862  acl = DatumGetAclP(aclDatum);
3863  }
3864 
3865  result = aclmask(acl, roleid, ownerId, mask, how);
3866 
3867  /* if we have a detoasted copy, free it */
3868  if (acl && (Pointer) acl != DatumGetPointer(aclDatum))
3869  pfree(acl);
3870 
3871  ReleaseSysCache(tuple);
3872 
3873  return result;
3874 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
#define DatumGetAclP(X)
Definition: acl.h:113
#define Anum_pg_language_lanacl
Definition: pg_language.h:65
AclMode aclmask(const Acl *acl, Oid roleid, Oid ownerId, AclMode mask, AclMaskHow how)
Definition: acl.c:1304
Acl * acldefault(GrantObjectType objtype, Oid ownerId)
Definition: acl.c:731
int errcode(int sqlerrcode)
Definition: elog.c:575
return result
Definition: formatting.c:1618
unsigned int Oid
Definition: postgres_ext.h:31
#define SearchSysCache1(cacheId, key1)
Definition: syscache.h:152
uint32 AclMode
Definition: parsenodes.h:63
void pfree(void *pointer)
Definition: mcxt.c:950
char * Pointer
Definition: c.h:245
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
bool superuser_arg(Oid roleid)
Definition: superuser.c:57
uintptr_t Datum
Definition: postgres.h:372
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1116
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition: syscache.c:1278
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define DatumGetPointer(X)
Definition: postgres.h:555
FormData_pg_language * Form_pg_language
Definition: pg_language.h:51
int errmsg(const char *fmt,...)
Definition: elog.c:797
bool pg_language_ownercheck ( Oid  lan_oid,
Oid  roleid 
)

Definition at line 4650 of file aclchk.c.

References ereport, errcode(), errmsg(), ERROR, GETSTRUCT, has_privs_of_role(), HeapTupleIsValid, LANGOID, ObjectIdGetDatum, ReleaseSysCache(), SearchSysCache1, and superuser_arg().

Referenced by check_object_ownership(), and create_proc_lang().

4651 {
4652  HeapTuple tuple;
4653  Oid ownerId;
4654 
4655  /* Superusers bypass all permission checking. */
4656  if (superuser_arg(roleid))
4657  return true;
4658 
4659  tuple = SearchSysCache1(LANGOID, ObjectIdGetDatum(lan_oid));
4660  if (!HeapTupleIsValid(tuple))
4661  ereport(ERROR,
4662  (errcode(ERRCODE_UNDEFINED_FUNCTION),
4663  errmsg("language with OID %u does not exist", lan_oid)));
4664 
4665  ownerId = ((Form_pg_language) GETSTRUCT(tuple))->lanowner;
4666 
4667  ReleaseSysCache(tuple);
4668 
4669  return has_privs_of_role(roleid, ownerId);
4670 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
bool has_privs_of_role(Oid member, Oid role)
Definition: acl.c:4813
int errcode(int sqlerrcode)
Definition: elog.c:575
unsigned int Oid
Definition: postgres_ext.h:31
#define SearchSysCache1(cacheId, key1)
Definition: syscache.h:152
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
bool superuser_arg(Oid roleid)
Definition: superuser.c:57
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1116
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
FormData_pg_language * Form_pg_language
Definition: pg_language.h:51
int errmsg(const char *fmt,...)
Definition: elog.c:797
AclResult pg_largeobject_aclcheck_snapshot ( Oid  lang_oid,
Oid  roleid,
AclMode  mode,
Snapshot  snapshot 
)

Definition at line 4470 of file aclchk.c.

References ACLCHECK_NO_PRIV, ACLCHECK_OK, ACLMASK_ANY, and pg_largeobject_aclmask_snapshot().

Referenced by lo_get_fragment_internal(), lo_read(), lo_truncate_internal(), and lo_write().

4472 {
4473  if (pg_largeobject_aclmask_snapshot(lobj_oid, roleid, mode,
4474  ACLMASK_ANY, snapshot) != 0)
4475  return ACLCHECK_OK;
4476  else
4477  return ACLCHECK_NO_PRIV;
4478 }
AclMode pg_largeobject_aclmask_snapshot(Oid lobj_oid, Oid roleid, AclMode mask, AclMaskHow how, Snapshot snapshot)
Definition: aclchk.c:3889
AclMode pg_largeobject_aclmask_snapshot ( Oid  lobj_oid,
Oid  roleid,
AclMode  mask,
AclMaskHow  how,
Snapshot  snapshot 
)

Definition at line 3889 of file aclchk.c.

References AccessShareLock, ACL_OBJECT_LARGEOBJECT, acldefault(), aclmask(), Anum_pg_largeobject_metadata_lomacl, BTEqualStrategyNumber, DatumGetAclP, DatumGetPointer, ereport, errcode(), errmsg(), ERROR, GETSTRUCT, heap_close, heap_getattr, heap_open(), HeapTupleIsValid, LargeObjectMetadataOidIndexId, LargeObjectMetadataRelationId, ObjectIdAttributeNumber, ObjectIdGetDatum, pfree(), RelationGetDescr, result, ScanKeyInit(), superuser_arg(), systable_beginscan(), systable_endscan(), and systable_getnext().

Referenced by pg_aclmask(), and pg_largeobject_aclcheck_snapshot().

3892 {
3893  AclMode result;
3894  Relation pg_lo_meta;
3895  ScanKeyData entry[1];
3896  SysScanDesc scan;
3897  HeapTuple tuple;
3898  Datum aclDatum;
3899  bool isNull;
3900  Acl *acl;
3901  Oid ownerId;
3902 
3903  /* Superusers bypass all permission checking. */
3904  if (superuser_arg(roleid))
3905  return mask;
3906 
3907  /*
3908  * Get the largeobject's ACL from pg_language_metadata
3909  */
3911  AccessShareLock);
3912 
3913  ScanKeyInit(&entry[0],
3915  BTEqualStrategyNumber, F_OIDEQ,
3916  ObjectIdGetDatum(lobj_oid));
3917 
3918  scan = systable_beginscan(pg_lo_meta,
3920  snapshot, 1, entry);
3921 
3922  tuple = systable_getnext(scan);
3923  if (!HeapTupleIsValid(tuple))
3924  ereport(ERROR,
3925  (errcode(ERRCODE_UNDEFINED_OBJECT),
3926  errmsg("large object %u does not exist", lobj_oid)));
3927 
3928  ownerId = ((Form_pg_largeobject_metadata) GETSTRUCT(tuple))->lomowner;
3929 
3931  RelationGetDescr(pg_lo_meta), &isNull);
3932 
3933  if (isNull)
3934  {
3935  /* No ACL, so build default ACL */
3936  acl = acldefault(ACL_OBJECT_LARGEOBJECT, ownerId);
3937  aclDatum = (Datum) 0;
3938  }
3939  else
3940  {
3941  /* detoast ACL if necessary */
3942  acl = DatumGetAclP(aclDatum);
3943  }
3944 
3945  result = aclmask(acl, roleid, ownerId, mask, how);
3946 
3947  /* if we have a detoasted copy, free it */
3948  if (acl && (Pointer) acl != DatumGetPointer(aclDatum))
3949  pfree(acl);
3950 
3951  systable_endscan(scan);
3952 
3953  heap_close(pg_lo_meta, AccessShareLock);
3954 
3955  return result;
3956 }
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:499
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
#define RelationGetDescr(relation)
Definition: rel.h:429
#define ObjectIdAttributeNumber
Definition: sysattr.h:22
#define DatumGetAclP(X)
Definition: acl.h:113
AclMode aclmask(const Acl *acl, Oid roleid, Oid ownerId, AclMode mask, AclMaskHow how)
Definition: acl.c:1304
#define AccessShareLock
Definition: lockdefs.h:36
Acl * acldefault(GrantObjectType objtype, Oid ownerId)
Definition: acl.c:731
int errcode(int sqlerrcode)
Definition: elog.c:575
return result
Definition: formatting.c:1618
#define heap_close(r, l)
Definition: heapam.h:97
unsigned int Oid
Definition: postgres_ext.h:31
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:328
uint32 AclMode
Definition: parsenodes.h:63
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:416
void pfree(void *pointer)
Definition: mcxt.c:950
char * Pointer
Definition: c.h:245
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
bool superuser_arg(Oid roleid)
Definition: superuser.c:57
#define LargeObjectMetadataOidIndexId
Definition: indexing.h:183
#define heap_getattr(tup, attnum, tupleDesc, isnull)
Definition: htup_details.h:769
FormData_pg_largeobject_metadata * Form_pg_largeobject_metadata
uintptr_t Datum
Definition: postgres.h:372
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1284
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define LargeObjectMetadataRelationId
#define DatumGetPointer(X)
Definition: postgres.h:555
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define Anum_pg_largeobject_metadata_lomacl
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
#define BTEqualStrategyNumber
Definition: stratnum.h:31
bool pg_largeobject_ownercheck ( Oid  lobj_oid,
Oid  roleid 
)

Definition at line 4679 of file aclchk.c.

References AccessShareLock, BTEqualStrategyNumber, ereport, errcode(), errmsg(), ERROR, GETSTRUCT, has_privs_of_role(), heap_close, heap_open(), HeapTupleIsValid, LargeObjectMetadataOidIndexId, LargeObjectMetadataRelationId, NULL, ObjectIdAttributeNumber, ObjectIdGetDatum, ScanKeyInit(), superuser_arg(), systable_beginscan(), systable_endscan(), and systable_getnext().

Referenced by be_lo_unlink(), and check_object_ownership().

4680 {
4681  Relation pg_lo_meta;
4682  ScanKeyData entry[1];
4683  SysScanDesc scan;
4684  HeapTuple tuple;
4685  Oid ownerId;
4686 
4687  /* Superusers bypass all permission checking. */
4688  if (superuser_arg(roleid))
4689  return true;
4690 
4691  /* There's no syscache for pg_largeobject_metadata */
4693  AccessShareLock);
4694 
4695  ScanKeyInit(&entry[0],
4697  BTEqualStrategyNumber, F_OIDEQ,
4698  ObjectIdGetDatum(lobj_oid));
4699 
4700  scan = systable_beginscan(pg_lo_meta,
4702  NULL, 1, entry);
4703 
4704  tuple = systable_getnext(scan);
4705  if (!HeapTupleIsValid(tuple))
4706  ereport(ERROR,
4707  (errcode(ERRCODE_UNDEFINED_OBJECT),
4708  errmsg("large object %u does not exist", lobj_oid)));
4709 
4710  ownerId = ((Form_pg_largeobject_metadata) GETSTRUCT(tuple))->lomowner;
4711 
4712  systable_endscan(scan);
4713  heap_close(pg_lo_meta, AccessShareLock);
4714 
4715  return has_privs_of_role(roleid, ownerId);
4716 }
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:499
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
#define ObjectIdAttributeNumber
Definition: sysattr.h:22
bool has_privs_of_role(Oid member, Oid role)
Definition: acl.c:4813
#define AccessShareLock
Definition: lockdefs.h:36
int errcode(int sqlerrcode)
Definition: elog.c:575
#define heap_close(r, l)
Definition: heapam.h:97
unsigned int Oid
Definition: postgres_ext.h:31
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:328
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:416
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
bool superuser_arg(Oid roleid)
Definition: superuser.c:57
#define LargeObjectMetadataOidIndexId
Definition: indexing.h:183
FormData_pg_largeobject_metadata * Form_pg_largeobject_metadata
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1284
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define NULL
Definition: c.h:229
#define LargeObjectMetadataRelationId
int errmsg(const char *fmt,...)
Definition: elog.c:797
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
#define BTEqualStrategyNumber
Definition: stratnum.h:31