/ db / include /
/db/include/grants.m4
1 dnl Copyright (C) 2012, 2014 The Meme Factory, Inc. http:/www.meme.com/
2 dnl Copyright (C) 2004, 2005, 2008 Karl O. Pinc <kop@meme.com>
3 dnl
4 dnl This file is part of Gombe-MI.
5 dnl
6 dnl Gombe-MI is free software; you can redistribute it and/or modify
7 dnl it under the terms of the GNU General Public License as published by
8 dnl the Free Software Foundation; either version 3 of the License, or
9 dnl (at your option) any later version.
10 dnl
11 dnl This program is distributed in the hope that it will be useful,
12 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
13 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 dnl GNU General Public License for more details.
15 dnl
16 dnl You should have received a copy of the GNU General Public License
17 dnl along with Gombe-MI. If not, see <http://www.gnu.org/licenses/>.
18 dnl
19 dnl Karl O. Pinc <kop@meme.com>
20 dnl
21 dnl Macros to set privliges.
22 dnl
23 dnl Remarks:
24 dnl
25 dnl m4 includes
26 include(`copyright.m4')dnl
27 include(`constants.m4')dnl
28 include(`types.m4')dnl
29 dnl
30 changequote([{[,]}])dnl m4 foolery so includes include only once.
31 dnl Once the macro is in the text, change the quotes back
32 ifdef([{[_grants.m4]}], [{[changequote(`,')]}], [{[dnl
33 changequote(`,')dnl
34 dnl
35 dnl Standard test for having already included the file.
36 define(`_grants.m4')dnl
37 dnl
38 dnl Don't output anything while defining macros.
39 divert(-1)
40
41 dnl Define m4 macros so we don't have to type so much.
42 dnl (Or at least type stuff that's more fun.)
43 dnl
44 dnl Watch out for using the single quote char as it has speical
45 dnl meaning to m4.
46 dnl
47 dnl The dates and timestamps should probably have some sort of
48 dnl reasonable constraints on them to prevent operator error.
49 dnl (Like entering dates from the last century.)
50 dnl
51 dnl Bugs:
52
53
54 dnl Grant privliges to a table.
55 dnl
56 dnl This also prints the name of the table. As every table has
57 dnl priviliges granted on it we get to monitor progress this way.
58 dnl
59 dnl Syntax: grant_priv(tablename)
60 changequote([,])
61 define([grant_priv],[
62 grant_update_priv(`$1')dnl
63 grant_noupdate_priv(`$1')dnl
64 ])
65 changequote(`,')
66
67 dnl Grant all privliges but update to a table.
68 dnl
69 dnl This also prints the name of the table. As every table has
70 dnl priviliges granted on it we get to monitor progress this way.
71 dnl
72 dnl Syntax: grant_noupdate_priv(tablename)
73 changequote([,])
74 define([grant_noupdate_priv],[
75 GRANT SELECT ON $1 TO GROUP gombemi_readers;
76 GRANT SELECT ON $1 TO GROUP gombemi_editors;
77 GRANT INSERT ON $1 TO GROUP gombemi_editors;
78 GRANT DELETE ON $1 TO GROUP gombemi_editors;
79 SELECT '$1' AS done_with;
80 ])
81 changequote(`,')
82
83 dnl Grant update privliges to a table.
84 dnl
85 dnl Syntax: grant_update_priv(tablename)
86 changequote([,])
87 define([grant_update_priv],[
88 GRANT UPDATE ON $1 TO GROUP gombemi_editors;
89 ])
90 changequote(`,')
91
92
93 dnl Grant update privliges to some columns of a table.
94 dnl
95 dnl Syntax: grant_update_cols_privs(tablename, columnames)
96 dnl
97 dnl tablename Name of table
98 dnl columnnames Names of columns, separated by commas
99 dnl
100 changequote([,])
101 define([grant_update_cols_privs],[
102 GRANT UPDATE ($2) ON $1 TO gombemi_editors;
103 ])
104 changequote(`,')
105
106
107
108 dnl Grant privliges to a table's sequence
109 dnl
110 dnl This also prints the name of the sequence.
111 dnl
112 dnl Syntax: grant_seq_priv(tablename, idname)
113 changequote([,])
114 define([grant_seq_priv],[
115 GRANT SELECT ON $1_$2_seq TO GROUP gombemi_readers;
116 GRANT SELECT ON $1_$2_seq TO GROUP gombemi_editors;
117 GRANT UPDATE ON $1_$2_seq TO GROUP gombemi_editors;
118 SELECT '$1_$2_seq' AS done_with;
119 ])
120 changequote(`,')
121
122
123 dnl Grant read-only privliges to a table.
124 dnl
125 dnl Used for those tables updated only by trigger.
126 dnl
127 dnl This also prints the name of the table. As every table has
128 dnl priviliges granted on it we get to monitor progress this way.
129 dnl
130 dnl Syntax: grant_ro_priv(tablename)
131 changequote([,])
132 define([grant_ro_priv],[
133 GRANT SELECT ON $1 TO GROUP gombemi_readers;
134 GRANT SELECT ON $1 TO GROUP gombemi_editors;
135 SELECT '$1' AS done_with;
136 ])
137 changequote(`,')
138
139
140 dnl Grant read-only privliges to a table's sequence
141 dnl
142 dnl Used for those tables updated only by trigger.
143 dnl
144 dnl This also prints the name of the sequence.
145 dnl
146 dnl Syntax: grant_ro_seq_priv(tablename, idname)
147 changequote([,])
148 define([grant_ro_seq_priv],[
149 GRANT SELECT ON $1_$2_seq TO GROUP gombemi_readers;
150 GRANT SELECT ON $1_$2_seq TO GROUP gombemi_editors;
151 SELECT '$1_$2_seq' AS done_with;
152 ])
153 changequote(`,')
154
155 -- Done defining macros.
156 divert`'dnl
157 dnl
158 dnl
159 ]}])dnl End of ifdef over the whole file.