]> granicus.if.org Git - postgresql/blob - src/include/utils/acl.h
Massive commit to run PGINDENT on all *.c and *.h files.
[postgresql] / src / include / utils / acl.h
1 /*-------------------------------------------------------------------------
2  *
3  * acl.h--
4  *        Definition of (and support for) access control list data structures.
5  *
6  *
7  * Copyright (c) 1994, Regents of the University of California
8  *
9  * $Id: acl.h,v 1.8 1997/09/07 05:02:05 momjian Exp $
10  *
11  * NOTES
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).
15  *
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.
19  *
20  *-------------------------------------------------------------------------
21  */
22 #ifndef ACL_H
23 #define ACL_H
24
25 #include <nodes/parsenodes.h>
26 #include <utils/array.h>
27
28 /*
29  * AclId                system identifier for the user, group, etc.
30  *                              XXX currently UNIX uid for users...
31  */
32 typedef uint32  AclId;
33
34 #define ACL_ID_WORLD    0               /* XXX only idtype should be checked */
35
36 /*
37  * AclIdType    tag that describes if the AclId is a user, group, etc.
38  */
39 typedef uint8   AclIdType;
40
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 */
44
45 /*
46  * AclMode              the actual permissions
47  *                              XXX should probably use bit.h routines.
48  *                              XXX should probably also stuff the modechg cruft in the
49  *                                      high bits, too.
50  */
51 typedef uint8   AclMode;
52
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 */
58 #define N_ACL_MODES             4
59
60 #define ACL_MODECHG_ADD                 1
61 #define ACL_MODECHG_DEL                 2
62 #define ACL_MODECHG_EQL                 3
63
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)
68
69 /*
70  * AclItem
71  */
72 typedef struct AclItem
73 {
74         AclId                   ai_id;
75         AclIdType               ai_idtype;
76         AclMode                 ai_mode;
77 }                               AclItem;
78
79 /* Note: if the size of AclItem changes,
80    change the aclitem typlen in pg_type.h */
81
82 /*
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.
86  */
87 #define ARR_DIM0(a) (((unsigned *) (((char *) a) + sizeof(ArrayType)))[0])
88
89 /*
90  * Acl                  a one-dimensional POSTGRES array of AclItem
91  */
92 typedef ArrayType Acl;
93
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)
99
100 /*
101  * IdList               a one-dimensional POSTGRES array of AclId
102  */
103 typedef ArrayType IdList;
104
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)
110
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'
120
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
126
127 /* warning messages.  set these in aclchk.c. */
128 extern char    *aclcheck_error_strings[];
129
130 /*
131  * Enable ACL execution tracing and table dumps
132  */
133 /*#define ACLDEBUG_TRACE*/
134
135 /*
136  * routines used internally (parser, etc.)
137  */
138 extern Acl         *aclownerdefault(AclId ownerid);
139 extern Acl         *acldefault(void);
140 extern Acl         *aclinsert3(Acl * old_acl, AclItem * mod_aip, unsigned modechg);
141
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);
147
148 /*
149  * exported routines (from acl.c)
150  */
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);
157
158 /*
159  * prototypes for functions in aclchk.c
160  */
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);
164
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);
168 extern int32
169 pg_func_ownercheck(char *usename, char *funcname,
170                                    int nargs, Oid * arglist);
171 extern int32
172 pg_aggr_ownercheck(char *usename, char *aggname,
173                                    Oid basetypeID);
174
175 #endif                                                  /* ACL_H */