1996-08-28 03:59:28 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
1999-02-14 00:22:53 +01:00
|
|
|
* acl.h
|
1997-09-07 07:04:48 +02:00
|
|
|
* Definition of (and support for) access control list data structures.
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
|
|
|
*
|
2001-01-24 20:43:33 +01:00
|
|
|
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
|
2000-01-26 06:58:53 +01:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
2002-04-21 02:26:44 +02:00
|
|
|
* $Id: acl.h,v 1.43 2002/04/21 00:26:44 tgl Exp $
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
|
|
|
* NOTES
|
2000-08-01 00:39:17 +02:00
|
|
|
* For backward-compatibility purposes we have to allow there
|
1997-09-07 07:04:48 +02:00
|
|
|
* to be a null ACL in a pg_class tuple. This will be defined as
|
2000-10-02 06:49:28 +02:00
|
|
|
* meaning "default protection" (i.e., whatever acldefault() returns).
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
1997-09-07 07:04:48 +02:00
|
|
|
* The AclItems in an ACL array are currently kept in sorted order.
|
|
|
|
* Things will break hard if you change that without changing the
|
|
|
|
* code wherever this is included.
|
1996-08-28 03:59:28 +02:00
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#ifndef ACL_H
|
|
|
|
#define ACL_H
|
|
|
|
|
1999-07-16 01:04:24 +02:00
|
|
|
#include "nodes/parsenodes.h"
|
|
|
|
#include "utils/array.h"
|
2002-03-22 00:27:25 +01:00
|
|
|
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/*
|
1997-09-07 07:04:48 +02:00
|
|
|
* AclId system identifier for the user, group, etc.
|
2002-03-22 00:27:25 +01:00
|
|
|
* XXX Perhaps replace this type by OID?
|
1996-08-28 03:59:28 +02:00
|
|
|
*/
|
1997-09-08 04:41:22 +02:00
|
|
|
typedef uint32 AclId;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2000-10-02 06:49:28 +02:00
|
|
|
#define ACL_ID_WORLD 0 /* placeholder for id in a WORLD acl item */
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* AclIdType tag that describes if the AclId is a user, group, etc.
|
|
|
|
*/
|
2002-04-21 02:26:44 +02:00
|
|
|
#define ACL_IDTYPE_WORLD 0x00 /* PUBLIC */
|
1998-02-25 14:09:49 +01:00
|
|
|
#define ACL_IDTYPE_UID 0x01 /* user id - from pg_shadow */
|
1997-09-07 07:04:48 +02:00
|
|
|
#define ACL_IDTYPE_GID 0x02 /* group id - from pg_group */
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/*
|
2002-04-21 02:26:44 +02:00
|
|
|
* AclMode a bitmask of privilege bits
|
|
|
|
*/
|
|
|
|
typedef uint32 AclMode;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1996-08-28 03:59:28 +02:00
|
|
|
/*
|
|
|
|
* AclItem
|
2002-04-21 02:26:44 +02:00
|
|
|
*
|
|
|
|
* Note: must be same size on all platforms, because the size is hardcoded
|
|
|
|
* in the pg_type.h entry for aclitem.
|
1996-08-28 03:59:28 +02:00
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef struct AclItem
|
|
|
|
{
|
2002-04-21 02:26:44 +02:00
|
|
|
AclId ai_id; /* ID that this item applies to */
|
|
|
|
AclMode ai_privs; /* AclIdType plus privilege bits */
|
1997-09-08 22:59:27 +02:00
|
|
|
} AclItem;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2002-04-21 02:26:44 +02:00
|
|
|
/*
|
|
|
|
* The AclIdType is stored in the top two bits of the ai_privs field of an
|
|
|
|
* AclItem, leaving us with thirty usable privilege bits.
|
|
|
|
*/
|
|
|
|
#define ACLITEM_GET_PRIVS(item) ((item).ai_privs & 0x3FFFFFFF)
|
|
|
|
#define ACLITEM_GET_IDTYPE(item) ((item).ai_privs >> 30)
|
|
|
|
#define ACLITEM_SET_PRIVS_IDTYPE(item,privs,idtype) \
|
|
|
|
((item).ai_privs = ((privs) & 0x3FFFFFFF) | ((idtype) << 30))
|
1996-08-28 03:59:28 +02:00
|
|
|
|
2000-08-01 00:39:17 +02:00
|
|
|
|
1996-08-28 03:59:28 +02:00
|
|
|
/*
|
2000-08-01 00:39:17 +02:00
|
|
|
* Definitions for convenient access to Acl (array of AclItem) and IdList
|
|
|
|
* (array of AclId). These are standard Postgres arrays, but are restricted
|
|
|
|
* to have one dimension. We also ignore the lower bound when reading,
|
|
|
|
* and set it to zero when writing.
|
|
|
|
*
|
|
|
|
* CAUTION: as of Postgres 7.1, these arrays are toastable (just like all
|
2001-03-22 05:01:46 +01:00
|
|
|
* other array types). Therefore, be careful to detoast them with the
|
2000-08-01 00:39:17 +02:00
|
|
|
* macros provided, unless you know for certain that a particular array
|
|
|
|
* can't have been toasted. Presently, we do not provide toast tables for
|
|
|
|
* pg_class or pg_group, so the entries in those tables won't have been
|
|
|
|
* stored externally --- but they could have been compressed!
|
1996-08-28 03:59:28 +02:00
|
|
|
*/
|
2000-08-01 00:39:17 +02:00
|
|
|
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/*
|
1997-09-07 07:04:48 +02:00
|
|
|
* Acl a one-dimensional POSTGRES array of AclItem
|
1996-08-28 03:59:28 +02:00
|
|
|
*/
|
|
|
|
typedef ArrayType Acl;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2000-08-01 00:39:17 +02:00
|
|
|
#define ACL_NUM(ACL) (ARR_DIMS(ACL)[0])
|
1997-09-07 07:04:48 +02:00
|
|
|
#define ACL_DAT(ACL) ((AclItem *) ARR_DATA_PTR(ACL))
|
2000-08-01 00:39:17 +02:00
|
|
|
#define ACL_N_SIZE(N) (ARR_OVERHEAD(1) + ((N) * sizeof(AclItem)))
|
1997-09-07 07:04:48 +02:00
|
|
|
#define ACL_SIZE(ACL) ARR_SIZE(ACL)
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/*
|
1997-09-07 07:04:48 +02:00
|
|
|
* IdList a one-dimensional POSTGRES array of AclId
|
1996-08-28 03:59:28 +02:00
|
|
|
*/
|
|
|
|
typedef ArrayType IdList;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2000-08-01 00:39:17 +02:00
|
|
|
#define IDLIST_NUM(IDL) (ARR_DIMS(IDL)[0])
|
1997-09-07 07:04:48 +02:00
|
|
|
#define IDLIST_DAT(IDL) ((AclId *) ARR_DATA_PTR(IDL))
|
2000-08-01 00:39:17 +02:00
|
|
|
#define IDLIST_N_SIZE(N) (ARR_OVERHEAD(1) + ((N) * sizeof(AclId)))
|
1997-09-07 07:04:48 +02:00
|
|
|
#define IDLIST_SIZE(IDL) ARR_SIZE(IDL)
|
|
|
|
|
2000-08-01 00:39:17 +02:00
|
|
|
/*
|
|
|
|
* fmgr macros for these types
|
|
|
|
*/
|
2001-03-22 05:01:46 +01:00
|
|
|
#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)
|
2000-08-01 00:39:17 +02:00
|
|
|
|
2001-03-22 05:01:46 +01:00
|
|
|
#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))
|
2000-08-01 00:39:17 +02:00
|
|
|
#define PG_GETARG_ACL_P_COPY(n) DatumGetAclPCopy(PG_GETARG_DATUM(n))
|
2001-03-22 05:01:46 +01:00
|
|
|
#define PG_RETURN_ACL_P(x) PG_RETURN_POINTER(x)
|
2000-08-01 00:39:17 +02:00
|
|
|
|
2001-03-22 05:01:46 +01:00
|
|
|
#define DatumGetIdListP(X) ((IdList *) PG_DETOAST_DATUM(X))
|
|
|
|
#define DatumGetIdListPCopy(X) ((IdList *) PG_DETOAST_DATUM_COPY(X))
|
|
|
|
#define PG_GETARG_IDLIST_P(n) DatumGetIdListP(PG_GETARG_DATUM(n))
|
2000-08-01 00:39:17 +02:00
|
|
|
#define PG_GETARG_IDLIST_P_COPY(n) DatumGetIdListPCopy(PG_GETARG_DATUM(n))
|
2001-03-22 05:01:46 +01:00
|
|
|
#define PG_RETURN_IDLIST_P(x) PG_RETURN_POINTER(x)
|
2000-08-01 00:39:17 +02:00
|
|
|
|
|
|
|
|
2000-10-02 06:49:28 +02:00
|
|
|
/*
|
|
|
|
* ACL modification opcodes
|
|
|
|
*/
|
|
|
|
#define ACL_MODECHG_ADD 1
|
|
|
|
#define ACL_MODECHG_DEL 2
|
|
|
|
#define ACL_MODECHG_EQL 3
|
|
|
|
|
2002-04-21 02:26:44 +02:00
|
|
|
/* external representation of mode indicators for I/O */
|
1997-09-07 07:04:48 +02:00
|
|
|
#define ACL_MODECHG_ADD_CHR '+'
|
|
|
|
#define ACL_MODECHG_DEL_CHR '-'
|
|
|
|
#define ACL_MODECHG_EQL_CHR '='
|
2002-04-21 02:26:44 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* External representations of the privilege bits --- aclitemin/aclitemout
|
|
|
|
* represent each possible privilege bit with a distinct 1-character code
|
|
|
|
*/
|
|
|
|
#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_RULE_CHR 'R'
|
|
|
|
#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'
|
|
|
|
|
|
|
|
/* string holding all privilege code chars, in order by bitmask position */
|
|
|
|
#define ACL_ALL_RIGHTS_STR "arwdRxtXUCT"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Bitmasks defining "all rights" for each supported object type
|
|
|
|
*/
|
|
|
|
#define ACL_ALL_RIGHTS_RELATION (ACL_INSERT|ACL_SELECT|ACL_UPDATE|ACL_DELETE|ACL_RULE|ACL_REFERENCES|ACL_TRIGGER)
|
|
|
|
#define ACL_ALL_RIGHTS_DATABASE (ACL_CREATE|ACL_CREATE_TEMP)
|
|
|
|
#define ACL_ALL_RIGHTS_FUNCTION (ACL_EXECUTE)
|
|
|
|
#define ACL_ALL_RIGHTS_LANGUAGE (ACL_USAGE)
|
|
|
|
#define ACL_ALL_RIGHTS_NAMESPACE (ACL_USAGE|ACL_CREATE)
|
|
|
|
|
1996-08-28 03:59:28 +02:00
|
|
|
|
2002-03-22 00:27:25 +01:00
|
|
|
/* result codes for pg_*_aclcheck */
|
1997-09-07 07:04:48 +02:00
|
|
|
#define ACLCHECK_OK 0
|
|
|
|
#define ACLCHECK_NO_PRIV 1
|
|
|
|
#define ACLCHECK_NO_CLASS 2
|
|
|
|
#define ACLCHECK_NOT_OWNER 3
|
1997-03-12 21:48:48 +01:00
|
|
|
|
2002-03-22 00:27:25 +01:00
|
|
|
/* error messages (index by ACLCHECK_* result code). set in aclchk.c. */
|
|
|
|
extern const char * const aclcheck_error_strings[];
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/*
|
2000-10-07 02:58:23 +02:00
|
|
|
* routines used internally
|
1996-08-28 03:59:28 +02:00
|
|
|
*/
|
2002-04-21 02:26:44 +02:00
|
|
|
extern Acl *acldefault(GrantObjectType objtype, AclId ownerid);
|
|
|
|
extern Acl *aclinsert3(const Acl *old_acl, const AclItem *mod_aip,
|
|
|
|
unsigned modechg);
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* exported routines (from acl.c)
|
|
|
|
*/
|
2000-08-01 00:39:17 +02:00
|
|
|
extern Datum aclitemin(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum aclitemout(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum aclinsert(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum aclremove(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum aclcontains(PG_FUNCTION_ARGS);
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* prototypes for functions in aclchk.c
|
|
|
|
*/
|
2001-06-10 01:21:55 +02:00
|
|
|
extern void ExecuteGrantStmt(GrantStmt *stmt);
|
1997-09-08 04:41:22 +02:00
|
|
|
extern AclId get_grosysid(char *groname);
|
|
|
|
extern char *get_groname(AclId grosysid);
|
1996-08-28 03:59:28 +02:00
|
|
|
|
2002-03-22 00:27:25 +01:00
|
|
|
/* these return ACLCHECK_* result codes */
|
|
|
|
extern int32 pg_class_aclcheck(Oid table_oid, Oid userid, AclMode mode);
|
2002-04-21 02:26:44 +02:00
|
|
|
extern int32 pg_database_aclcheck(Oid db_oid, Oid userid, AclMode mode);
|
|
|
|
extern int32 pg_proc_aclcheck(Oid proc_oid, Oid userid, AclMode mode);
|
|
|
|
extern int32 pg_language_aclcheck(Oid lang_oid, Oid userid, AclMode mode);
|
|
|
|
extern int32 pg_namespace_aclcheck(Oid nsp_oid, Oid userid, AclMode mode);
|
2002-02-19 00:11:58 +01:00
|
|
|
|
2002-03-22 00:27:25 +01:00
|
|
|
/* ownercheck routines just return true (owner) or false (not) */
|
|
|
|
extern bool pg_class_ownercheck(Oid class_oid, Oid userid);
|
|
|
|
extern bool pg_type_ownercheck(Oid type_oid, Oid userid);
|
|
|
|
extern bool pg_oper_ownercheck(Oid oper_oid, Oid userid);
|
|
|
|
extern bool pg_proc_ownercheck(Oid proc_oid, Oid userid);
|
2002-04-21 02:26:44 +02:00
|
|
|
extern bool pg_namespace_ownercheck(Oid nsp_oid, Oid userid);
|
2002-03-22 00:27:25 +01:00
|
|
|
|
2001-11-05 18:46:40 +01:00
|
|
|
#endif /* ACL_H */
|