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.7 1997/08/19 21:40:18 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>
29 * AclId system identifier for the user, group, etc.
30 * XXX currently UNIX uid for users...
33 #define ACL_ID_WORLD 0 /* XXX only idtype should be checked */
36 * AclIdType tag that describes if the AclId is a user, group, etc.
38 typedef uint8 AclIdType;
39 #define ACL_IDTYPE_WORLD 0x00
40 #define ACL_IDTYPE_UID 0x01 /* user id - from pg_user */
41 #define ACL_IDTYPE_GID 0x02 /* group id - from pg_group */
44 * AclMode the actual permissions
45 * XXX should probably use bit.h routines.
46 * XXX should probably also stuff the modechg cruft in the
49 typedef uint8 AclMode;
50 #define ACL_NO 0 /* no permissions */
51 #define ACL_AP (1<<0) /* append */
52 #define ACL_RD (1<<1) /* read */
53 #define ACL_WR (1<<2) /* write (append/delete/replace) */
54 #define ACL_RU (1<<3) /* place rules */
57 #define ACL_MODECHG_ADD 1
58 #define ACL_MODECHG_DEL 2
59 #define ACL_MODECHG_EQL 3
61 /* change this line if you want to set the default acl permission */
62 #define ACL_WORLD_DEFAULT (ACL_RD)
63 /* #define ACL_WORLD_DEFAULT (ACL_RD|ACL_WR|ACL_AP|ACL_RU) */
64 #define ACL_OWNER_DEFAULT (ACL_RD|ACL_WR|ACL_AP|ACL_RU)
69 typedef struct AclItem {
74 /* Note: if the size of AclItem changes,
75 change the aclitem typlen in pg_type.h */
78 * The value of the first dimension-array element. Since these arrays
79 * always have a lower-bound of 0, this is the same as the number of
80 * elements in the array.
82 #define ARR_DIM0(a) (((unsigned *) (((char *) a) + sizeof(ArrayType)))[0])
85 * Acl a one-dimensional POSTGRES array of AclItem
87 typedef ArrayType Acl;
88 #define ACL_NUM(ACL) ARR_DIM0(ACL)
89 #define ACL_DAT(ACL) ((AclItem *) ARR_DATA_PTR(ACL))
90 #define ACL_N_SIZE(N) \
91 ((unsigned) (ARR_OVERHEAD(1) + ((N) * sizeof(AclItem))))
92 #define ACL_SIZE(ACL) ARR_SIZE(ACL)
95 * IdList a one-dimensional POSTGRES array of AclId
97 typedef ArrayType IdList;
98 #define IDLIST_NUM(IDL) ARR_DIM0(IDL)
99 #define IDLIST_DAT(IDL) ((AclId *) ARR_DATA_PTR(IDL))
100 #define IDLIST_N_SIZE(N) \
101 ((unsigned) (ARR_OVERHEAD(1) + ((N) * sizeof(AclId))))
102 #define IDLIST_SIZE(IDL) ARR_SIZE(IDL)
104 #define ACL_MODECHG_STR "+-=" /* list of valid characters */
105 #define ACL_MODECHG_ADD_CHR '+'
106 #define ACL_MODECHG_DEL_CHR '-'
107 #define ACL_MODECHG_EQL_CHR '='
108 #define ACL_MODE_STR "arwR" /* list of valid characters */
109 #define ACL_MODE_AP_CHR 'a'
110 #define ACL_MODE_RD_CHR 'r'
111 #define ACL_MODE_WR_CHR 'w'
112 #define ACL_MODE_RU_CHR 'R'
114 /* result codes for pg_aclcheck */
115 #define ACLCHECK_OK 0
116 #define ACLCHECK_NO_PRIV 1
117 #define ACLCHECK_NO_CLASS 2
118 #define ACLCHECK_NOT_OWNER 3
120 /* warning messages. set these in aclchk.c. */
121 extern char *aclcheck_error_strings[];
124 * Enable ACL execution tracing and table dumps
126 /*#define ACLDEBUG_TRACE*/
129 * routines used internally (parser, etc.)
131 extern Acl *aclownerdefault(AclId ownerid);
132 extern Acl *acldefault(void);
133 extern Acl *aclinsert3(Acl *old_acl, AclItem *mod_aip, unsigned modechg);
135 extern char* aclmakepriv(char* old_privlist, char new_priv);
136 extern char* aclmakeuser(char* user_type, char* user);
137 extern ChangeACLStmt* makeAclStmt(char* privs, List* rel_list, char* grantee,
138 char grant_or_revoke);
141 * exported routines (from acl.c)
143 extern Acl *makeacl(int n);
144 extern AclItem *aclitemin(char *s);
145 extern char *aclitemout(AclItem *aip);
146 extern Acl *aclinsert(Acl *old_acl, AclItem *mod_aip);
147 extern Acl *aclremove(Acl *old_acl, AclItem *mod_aip);
148 extern int32 aclcontains(Acl *acl, AclItem *aip);
151 * prototypes for functions in aclchk.c
153 extern void ChangeAcl(char *relname, AclItem *mod_aip, unsigned modechg);
154 extern AclId get_grosysid(char *groname);
155 extern char *get_groname(AclId grosysid);
157 /* XXX move these elsewhere -pma */
158 extern int32 pg_aclcheck(char *relname, char *usename, AclMode mode);
159 extern int32 pg_ownercheck(char *usename, char *value, int cacheid);
160 extern int32 pg_func_ownercheck(char *usename, char *funcname,
161 int nargs, Oid *arglist);
162 extern int32 pg_aggr_ownercheck(char *usename, char *aggname,