1 /*-------------------------------------------------------------------------
4 * Definition of (and support for) access control list data structures.
7 * Copyright (c) 1994, Regents of the University of California
9 * $Id: acl.h,v 1.22 1999/07/15 23:04:19 momjian Exp $
12 * For backward-compatability purposes we have to allow there
13 * to be a null ACL in a pg_class tuple. This will be defined as
14 * meaning "no protection" (i.e., old catalogs get old semantics).
16 * The AclItems in an ACL array are currently kept in sorted order.
17 * Things will break hard if you change that without changing the
18 * code wherever this is included.
20 *-------------------------------------------------------------------------
25 #include "nodes/parsenodes.h"
26 #include "utils/array.h"
27 #include "utils/memutils.h"
30 * AclId system identifier for the user, group, etc.
31 * XXX currently UNIX uid for users...
35 #define ACL_ID_WORLD 0 /* XXX only idtype should be checked */
38 * AclIdType tag that describes if the AclId is a user, group, etc.
40 typedef uint8 AclIdType;
42 #define ACL_IDTYPE_WORLD 0x00
43 #define ACL_IDTYPE_UID 0x01 /* user id - from pg_shadow */
44 #define ACL_IDTYPE_GID 0x02 /* group id - from pg_group */
47 * AclMode the actual permissions
48 * XXX should probably use bit.h routines.
49 * XXX should probably also stuff the modechg cruft in the
52 typedef uint8 AclMode;
54 #define ACL_NO 0 /* no permissions */
55 #define ACL_AP (1<<0) /* append */
56 #define ACL_RD (1<<1) /* read */
57 #define ACL_WR (1<<2) /* write (append/delete/replace) */
58 #define ACL_RU (1<<3) /* place rules */
61 #define ACL_MODECHG_ADD 1
62 #define ACL_MODECHG_DEL 2
63 #define ACL_MODECHG_EQL 3
65 /* change this line if you want to set the default acl permission */
66 #define ACL_WORLD_DEFAULT (ACL_NO)
67 /* #define ACL_WORLD_DEFAULT (ACL_RD|ACL_WR|ACL_AP|ACL_RU) */
68 #define ACL_OWNER_DEFAULT (ACL_RD|ACL_WR|ACL_AP|ACL_RU)
73 typedef struct AclItem
79 * This is actually type 'aclitem', and we want a fixed size for
80 * for all platforms, so we pad this with dummies.
85 /* Note: if the size of AclItem changes,
86 change the aclitem typlen in pg_type.h */
89 * The value of the first dimension-array element. Since these arrays
90 * always have a lower-bound of 0, this is the same as the number of
91 * elements in the array.
93 #define ARR_DIM0(a) (((unsigned *) (((char *) a) + sizeof(ArrayType)))[0])
96 * Acl a one-dimensional POSTGRES array of AclItem
98 typedef ArrayType Acl;
100 #define ACL_NUM(ACL) ARR_DIM0(ACL)
101 #define ACL_DAT(ACL) ((AclItem *) ARR_DATA_PTR(ACL))
102 #define ACL_N_SIZE(N) \
103 ((unsigned) (ARR_OVERHEAD(1) + ((N) * sizeof(AclItem))))
104 #define ACL_SIZE(ACL) ARR_SIZE(ACL)
107 * IdList a one-dimensional POSTGRES array of AclId
109 typedef ArrayType IdList;
111 #define IDLIST_NUM(IDL) ARR_DIM0(IDL)
112 #define IDLIST_DAT(IDL) ((AclId *) ARR_DATA_PTR(IDL))
113 #define IDLIST_N_SIZE(N) \
114 ((unsigned) (ARR_OVERHEAD(1) + ((N) * sizeof(AclId))))
115 #define IDLIST_SIZE(IDL) ARR_SIZE(IDL)
117 #define ACL_MODECHG_STR "+-=" /* list of valid characters */
118 #define ACL_MODECHG_ADD_CHR '+'
119 #define ACL_MODECHG_DEL_CHR '-'
120 #define ACL_MODECHG_EQL_CHR '='
121 #define ACL_MODE_STR "arwR" /* list of valid characters */
122 #define ACL_MODE_AP_CHR 'a'
123 #define ACL_MODE_RD_CHR 'r'
124 #define ACL_MODE_WR_CHR 'w'
125 #define ACL_MODE_RU_CHR 'R'
127 /* result codes for pg_aclcheck */
128 #define ACLCHECK_OK 0
129 #define ACLCHECK_NO_PRIV 1
130 #define ACLCHECK_NO_CLASS 2
131 #define ACLCHECK_NOT_OWNER 3
133 /* warning messages. set these in aclchk.c. */
134 extern char *aclcheck_error_strings[];
137 * Enable ACL execution tracing and table dumps
139 /*#define ACLDEBUG_TRACE*/
142 * routines used internally (parser, etc.)
144 extern Acl *aclownerdefault(char *relname, AclId ownerid);
145 extern Acl *acldefault(char *relname);
146 extern Acl *aclinsert3(Acl *old_acl, AclItem *mod_aip, unsigned modechg);
148 extern char *aclmakepriv(char *old_privlist, char new_priv);
149 extern char *aclmakeuser(char *user_type, char *user);
150 extern ChangeACLStmt *makeAclStmt(char *privs, List *rel_list, char *grantee,
151 char grant_or_revoke);
154 * exported routines (from acl.c)
156 extern Acl *makeacl(int n);
157 extern AclItem *aclitemin(char *s);
158 extern char *aclitemout(AclItem *aip);
159 extern Acl *aclinsert(Acl *old_acl, AclItem *mod_aip);
160 extern Acl *aclremove(Acl *old_acl, AclItem *mod_aip);
161 extern int32 aclcontains(Acl *acl, AclItem *aip);
164 * prototypes for functions in aclchk.c
166 extern void ChangeAcl(char *relname, AclItem *mod_aip, unsigned modechg);
167 extern AclId get_grosysid(char *groname);
168 extern char *get_groname(AclId grosysid);
170 extern int32 pg_aclcheck(char *relname, char *usename, AclMode mode);
171 extern int32 pg_ownercheck(char *usename, char *value, int cacheid);
172 extern int32 pg_func_ownercheck(char *usename, char *funcname,
173 int nargs, Oid *arglist);
174 extern int32 pg_aggr_ownercheck(char *usename, char *aggname,