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.8 1997/09/07 05:02:05 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...
34 #define ACL_ID_WORLD 0 /* XXX only idtype should be checked */
37 * AclIdType tag that describes if the AclId is a user, group, etc.
39 typedef uint8 AclIdType;
41 #define ACL_IDTYPE_WORLD 0x00
42 #define ACL_IDTYPE_UID 0x01 /* user id - from pg_user */
43 #define ACL_IDTYPE_GID 0x02 /* group id - from pg_group */
46 * AclMode the actual permissions
47 * XXX should probably use bit.h routines.
48 * XXX should probably also stuff the modechg cruft in the
51 typedef uint8 AclMode;
53 #define ACL_NO 0 /* no permissions */
54 #define ACL_AP (1<<0) /* append */
55 #define ACL_RD (1<<1) /* read */
56 #define ACL_WR (1<<2) /* write (append/delete/replace) */
57 #define ACL_RU (1<<3) /* place rules */
60 #define ACL_MODECHG_ADD 1
61 #define ACL_MODECHG_DEL 2
62 #define ACL_MODECHG_EQL 3
64 /* change this line if you want to set the default acl permission */
65 #define ACL_WORLD_DEFAULT (ACL_RD)
66 /* #define ACL_WORLD_DEFAULT (ACL_RD|ACL_WR|ACL_AP|ACL_RU) */
67 #define ACL_OWNER_DEFAULT (ACL_RD|ACL_WR|ACL_AP|ACL_RU)
72 typedef struct AclItem
79 /* Note: if the size of AclItem changes,
80 change the aclitem typlen in pg_type.h */
83 * The value of the first dimension-array element. Since these arrays
84 * always have a lower-bound of 0, this is the same as the number of
85 * elements in the array.
87 #define ARR_DIM0(a) (((unsigned *) (((char *) a) + sizeof(ArrayType)))[0])
90 * Acl a one-dimensional POSTGRES array of AclItem
92 typedef ArrayType Acl;
94 #define ACL_NUM(ACL) ARR_DIM0(ACL)
95 #define ACL_DAT(ACL) ((AclItem *) ARR_DATA_PTR(ACL))
96 #define ACL_N_SIZE(N) \
97 ((unsigned) (ARR_OVERHEAD(1) + ((N) * sizeof(AclItem))))
98 #define ACL_SIZE(ACL) ARR_SIZE(ACL)
101 * IdList a one-dimensional POSTGRES array of AclId
103 typedef ArrayType IdList;
105 #define IDLIST_NUM(IDL) ARR_DIM0(IDL)
106 #define IDLIST_DAT(IDL) ((AclId *) ARR_DATA_PTR(IDL))
107 #define IDLIST_N_SIZE(N) \
108 ((unsigned) (ARR_OVERHEAD(1) + ((N) * sizeof(AclId))))
109 #define IDLIST_SIZE(IDL) ARR_SIZE(IDL)
111 #define ACL_MODECHG_STR "+-=" /* list of valid characters */
112 #define ACL_MODECHG_ADD_CHR '+'
113 #define ACL_MODECHG_DEL_CHR '-'
114 #define ACL_MODECHG_EQL_CHR '='
115 #define ACL_MODE_STR "arwR" /* list of valid characters */
116 #define ACL_MODE_AP_CHR 'a'
117 #define ACL_MODE_RD_CHR 'r'
118 #define ACL_MODE_WR_CHR 'w'
119 #define ACL_MODE_RU_CHR 'R'
121 /* result codes for pg_aclcheck */
122 #define ACLCHECK_OK 0
123 #define ACLCHECK_NO_PRIV 1
124 #define ACLCHECK_NO_CLASS 2
125 #define ACLCHECK_NOT_OWNER 3
127 /* warning messages. set these in aclchk.c. */
128 extern char *aclcheck_error_strings[];
131 * Enable ACL execution tracing and table dumps
133 /*#define ACLDEBUG_TRACE*/
136 * routines used internally (parser, etc.)
138 extern Acl *aclownerdefault(AclId ownerid);
139 extern Acl *acldefault(void);
140 extern Acl *aclinsert3(Acl * old_acl, AclItem * mod_aip, unsigned modechg);
142 extern char *aclmakepriv(char *old_privlist, char new_priv);
143 extern char *aclmakeuser(char *user_type, char *user);
144 extern ChangeACLStmt *
145 makeAclStmt(char *privs, List * rel_list, char *grantee,
146 char grant_or_revoke);
149 * exported routines (from acl.c)
151 extern Acl *makeacl(int n);
152 extern AclItem *aclitemin(char *s);
153 extern char *aclitemout(AclItem * aip);
154 extern Acl *aclinsert(Acl * old_acl, AclItem * mod_aip);
155 extern Acl *aclremove(Acl * old_acl, AclItem * mod_aip);
156 extern int32 aclcontains(Acl * acl, AclItem * aip);
159 * prototypes for functions in aclchk.c
161 extern void ChangeAcl(char *relname, AclItem * mod_aip, unsigned modechg);
162 extern AclId get_grosysid(char *groname);
163 extern char *get_groname(AclId grosysid);
165 /* XXX move these elsewhere -pma */
166 extern int32 pg_aclcheck(char *relname, char *usename, AclMode mode);
167 extern int32 pg_ownercheck(char *usename, char *value, int cacheid);
169 pg_func_ownercheck(char *usename, char *funcname,
170 int nargs, Oid * arglist);
172 pg_aggr_ownercheck(char *usename, char *aggname,