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
|
|
|
*
|
|
|
|
*
|
2000-01-26 06:58:53 +01:00
|
|
|
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
|
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
2000-08-01 00:39:17 +02:00
|
|
|
* $Id: acl.h,v 1.26 2000/07/31 22:39:02 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
|
|
|
|
* meaning "no protection" (i.e., old catalogs get old semantics).
|
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"
|
1999-07-15 17:21:54 +02:00
|
|
|
#include "utils/memutils.h"
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/*
|
1997-09-07 07:04:48 +02:00
|
|
|
* AclId system identifier for the user, group, etc.
|
|
|
|
* XXX currently UNIX uid for users...
|
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
|
|
|
|
|
|
|
#define ACL_ID_WORLD 0 /* XXX only idtype should be checked */
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* AclIdType tag that describes if the AclId is a user, group, etc.
|
|
|
|
*/
|
1997-09-08 04:41:22 +02:00
|
|
|
typedef uint8 AclIdType;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
#define ACL_IDTYPE_WORLD 0x00
|
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
|
|
|
|
|
|
|
/*
|
1997-09-07 07:04:48 +02:00
|
|
|
* AclMode the actual permissions
|
|
|
|
* XXX should probably use bit.h routines.
|
|
|
|
* XXX should probably also stuff the modechg cruft in the
|
|
|
|
* high bits, too.
|
1996-08-28 03:59:28 +02:00
|
|
|
*/
|
1997-09-08 04:41:22 +02:00
|
|
|
typedef uint8 AclMode;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
#define ACL_NO 0 /* no permissions */
|
|
|
|
#define ACL_AP (1<<0) /* append */
|
|
|
|
#define ACL_RD (1<<1) /* read */
|
|
|
|
#define ACL_WR (1<<2) /* write (append/delete/replace) */
|
|
|
|
#define ACL_RU (1<<3) /* place rules */
|
|
|
|
#define N_ACL_MODES 4
|
|
|
|
|
|
|
|
#define ACL_MODECHG_ADD 1
|
|
|
|
#define ACL_MODECHG_DEL 2
|
|
|
|
#define ACL_MODECHG_EQL 3
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/* change this line if you want to set the default acl permission */
|
1998-02-23 19:43:13 +01:00
|
|
|
#define ACL_WORLD_DEFAULT (ACL_NO)
|
1997-09-07 07:04:48 +02:00
|
|
|
/* #define ACL_WORLD_DEFAULT (ACL_RD|ACL_WR|ACL_AP|ACL_RU) */
|
|
|
|
#define ACL_OWNER_DEFAULT (ACL_RD|ACL_WR|ACL_AP|ACL_RU)
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* AclItem
|
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef struct AclItem
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
AclId ai_id;
|
|
|
|
AclIdType ai_idtype;
|
|
|
|
AclMode ai_mode;
|
2000-04-12 19:17:23 +02:00
|
|
|
|
1999-07-09 05:28:53 +02:00
|
|
|
/*
|
2000-08-01 00:39:17 +02:00
|
|
|
* This is actually type 'aclitem', and we want a fixed size for
|
2000-04-12 19:17:23 +02:00
|
|
|
* all platforms, so we pad this with dummies.
|
1999-07-09 05:28:53 +02:00
|
|
|
*/
|
2000-04-12 19:17:23 +02:00
|
|
|
char dummy1,
|
|
|
|
dummy2;
|
1997-09-08 22:59:27 +02:00
|
|
|
} AclItem;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
/* Note: if the size of AclItem changes,
|
1996-08-28 03:59:28 +02:00
|
|
|
change the aclitem typlen in pg_type.h */
|
|
|
|
|
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
|
|
|
|
* other array types). Therefore, be careful to detoast them with the
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
#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 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))
|
|
|
|
#define PG_GETARG_IDLIST_P_COPY(n) DatumGetIdListPCopy(PG_GETARG_DATUM(n))
|
|
|
|
#define PG_RETURN_IDLIST_P(x) PG_RETURN_POINTER(x)
|
|
|
|
|
|
|
|
|
|
|
|
/* mode indicators for I/O */
|
1997-09-07 07:04:48 +02:00
|
|
|
#define ACL_MODECHG_STR "+-=" /* list of valid characters */
|
|
|
|
#define ACL_MODECHG_ADD_CHR '+'
|
|
|
|
#define ACL_MODECHG_DEL_CHR '-'
|
|
|
|
#define ACL_MODECHG_EQL_CHR '='
|
|
|
|
#define ACL_MODE_STR "arwR" /* list of valid characters */
|
|
|
|
#define ACL_MODE_AP_CHR 'a'
|
|
|
|
#define ACL_MODE_RD_CHR 'r'
|
|
|
|
#define ACL_MODE_WR_CHR 'w'
|
|
|
|
#define ACL_MODE_RU_CHR 'R'
|
1996-08-28 03:59:28 +02:00
|
|
|
|
1997-03-12 21:48:48 +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
|
|
|
|
|
|
|
/* warning messages. set these in aclchk.c. */
|
1997-09-08 04:41:22 +02:00
|
|
|
extern char *aclcheck_error_strings[];
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Enable ACL execution tracing and table dumps
|
|
|
|
*/
|
|
|
|
/*#define ACLDEBUG_TRACE*/
|
|
|
|
|
|
|
|
/*
|
1997-09-07 07:04:48 +02:00
|
|
|
* routines used internally (parser, etc.)
|
1996-08-28 03:59:28 +02:00
|
|
|
*/
|
1998-02-24 04:31:50 +01:00
|
|
|
extern Acl *aclownerdefault(char *relname, AclId ownerid);
|
|
|
|
extern Acl *acldefault(char *relname);
|
1997-09-08 22:59:27 +02:00
|
|
|
extern Acl *aclinsert3(Acl *old_acl, AclItem *mod_aip, unsigned modechg);
|
1996-08-28 03:59:28 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
extern char *aclmakepriv(char *old_privlist, char new_priv);
|
|
|
|
extern char *aclmakeuser(char *user_type, char *user);
|
1998-09-01 06:40:42 +02:00
|
|
|
extern ChangeACLStmt *makeAclStmt(char *privs, List *rel_list, char *grantee,
|
1997-09-07 07:04:48 +02:00
|
|
|
char grant_or_revoke);
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* exported routines (from acl.c)
|
|
|
|
*/
|
1997-09-08 04:41:22 +02:00
|
|
|
extern Acl *makeacl(int n);
|
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
|
|
|
|
*/
|
1997-09-08 22:59:27 +02:00
|
|
|
extern void ChangeAcl(char *relname, AclItem *mod_aip, unsigned modechg);
|
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
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
extern int32 pg_aclcheck(char *relname, char *usename, AclMode mode);
|
2000-01-16 21:05:00 +01:00
|
|
|
extern int32 pg_ownercheck(const char *usename, const char *value, int cacheid);
|
1998-09-01 06:40:42 +02:00
|
|
|
extern int32 pg_func_ownercheck(char *usename, char *funcname,
|
1997-09-08 23:56:23 +02:00
|
|
|
int nargs, Oid *arglist);
|
1998-09-01 06:40:42 +02:00
|
|
|
extern int32 pg_aggr_ownercheck(char *usename, char *aggname,
|
1997-09-07 07:04:48 +02:00
|
|
|
Oid basetypeID);
|
|
|
|
|
1998-09-01 06:40:42 +02:00
|
|
|
#endif /* ACL_H */
|