|
99fcc43…
|
drh
|
1 |
/* |
|
99fcc43…
|
drh
|
2 |
** Copyright (c) 2018 D. Richard Hipp |
|
99fcc43…
|
drh
|
3 |
** |
|
99fcc43…
|
drh
|
4 |
** This program is free software; you can redistribute it and/or |
|
99fcc43…
|
drh
|
5 |
** modify it under the terms of the Simplified BSD License (also |
|
99fcc43…
|
drh
|
6 |
** known as the "2-Clause License" or "FreeBSD License".) |
|
99fcc43…
|
drh
|
7 |
** |
|
99fcc43…
|
drh
|
8 |
** This program is distributed in the hope that it will be useful, |
|
99fcc43…
|
drh
|
9 |
** but without any warranty; without even the implied warranty of |
|
99fcc43…
|
drh
|
10 |
** merchantability or fitness for a particular purpose. |
|
99fcc43…
|
drh
|
11 |
** |
|
99fcc43…
|
drh
|
12 |
** Author contact information: |
|
99fcc43…
|
drh
|
13 |
** [email protected] |
|
99fcc43…
|
drh
|
14 |
** http://www.hwaci.com/drh/ |
|
99fcc43…
|
drh
|
15 |
** |
|
99fcc43…
|
drh
|
16 |
******************************************************************************* |
|
99fcc43…
|
drh
|
17 |
** |
|
99fcc43…
|
drh
|
18 |
** This file contains code used managing user capability strings. |
|
99fcc43…
|
drh
|
19 |
*/ |
|
99fcc43…
|
drh
|
20 |
#include "config.h" |
|
99fcc43…
|
drh
|
21 |
#include "capabilities.h" |
|
99fcc43…
|
drh
|
22 |
#include <assert.h> |
|
99fcc43…
|
drh
|
23 |
|
|
99fcc43…
|
drh
|
24 |
#if INTERFACE |
|
99fcc43…
|
drh
|
25 |
/* |
|
99fcc43…
|
drh
|
26 |
** A capability string object holds all defined capabilities in a |
|
99fcc43…
|
drh
|
27 |
** vector format that is subject to boolean operations. |
|
99fcc43…
|
drh
|
28 |
*/ |
|
99fcc43…
|
drh
|
29 |
struct CapabilityString { |
|
99fcc43…
|
drh
|
30 |
unsigned char x[128]; |
|
99fcc43…
|
drh
|
31 |
}; |
|
99fcc43…
|
drh
|
32 |
#endif |
|
99fcc43…
|
drh
|
33 |
|
|
99fcc43…
|
drh
|
34 |
/* |
|
99fcc43…
|
drh
|
35 |
** Add capabilities to a CapabilityString. If pIn is NULL, then create |
|
99fcc43…
|
drh
|
36 |
** a new capability string. |
|
99fcc43…
|
drh
|
37 |
** |
|
99fcc43…
|
drh
|
38 |
** Call capability_free() on the allocated CapabilityString object to |
|
99fcc43…
|
drh
|
39 |
** deallocate. |
|
99fcc43…
|
drh
|
40 |
*/ |
|
99fcc43…
|
drh
|
41 |
CapabilityString *capability_add(CapabilityString *pIn, const char *zCap){ |
|
99fcc43…
|
drh
|
42 |
int c; |
|
99fcc43…
|
drh
|
43 |
int i; |
|
99fcc43…
|
drh
|
44 |
if( pIn==0 ){ |
|
99fcc43…
|
drh
|
45 |
pIn = fossil_malloc( sizeof(*pIn) ); |
|
99fcc43…
|
drh
|
46 |
memset(pIn, 0, sizeof(*pIn)); |
|
99fcc43…
|
drh
|
47 |
} |
|
99fcc43…
|
drh
|
48 |
if( zCap ){ |
|
99fcc43…
|
drh
|
49 |
for(i=0; (c = zCap[i])!=0; i++){ |
|
99fcc43…
|
drh
|
50 |
if( c>='0' && c<='z' ) pIn->x[c] = 1; |
|
99fcc43…
|
drh
|
51 |
} |
|
99fcc43…
|
drh
|
52 |
} |
|
99fcc43…
|
drh
|
53 |
return pIn; |
|
99fcc43…
|
drh
|
54 |
} |
|
99fcc43…
|
drh
|
55 |
|
|
99fcc43…
|
drh
|
56 |
/* |
|
99fcc43…
|
drh
|
57 |
** Remove capabilities from a CapabilityString. |
|
99fcc43…
|
drh
|
58 |
*/ |
|
99fcc43…
|
drh
|
59 |
CapabilityString *capability_remove(CapabilityString *pIn, const char *zCap){ |
|
99fcc43…
|
drh
|
60 |
int c; |
|
99fcc43…
|
drh
|
61 |
int i; |
|
99fcc43…
|
drh
|
62 |
if( pIn==0 ){ |
|
99fcc43…
|
drh
|
63 |
pIn = fossil_malloc( sizeof(*pIn) ); |
|
99fcc43…
|
drh
|
64 |
memset(pIn, 0, sizeof(*pIn)); |
|
99fcc43…
|
drh
|
65 |
} |
|
99fcc43…
|
drh
|
66 |
if( zCap ){ |
|
99fcc43…
|
drh
|
67 |
for(i=0; (c = zCap[i])!=0; i++){ |
|
99fcc43…
|
drh
|
68 |
if( c>='0' && c<='z' ) pIn->x[c] = 0; |
|
99fcc43…
|
drh
|
69 |
} |
|
99fcc43…
|
drh
|
70 |
} |
|
99fcc43…
|
drh
|
71 |
return pIn; |
|
99fcc43…
|
drh
|
72 |
} |
|
99fcc43…
|
drh
|
73 |
|
|
99fcc43…
|
drh
|
74 |
/* |
|
99fcc43…
|
drh
|
75 |
** Return true if any of the capabilities in zNeeded are found in pCap |
|
99fcc43…
|
drh
|
76 |
*/ |
|
99fcc43…
|
drh
|
77 |
int capability_has_any(CapabilityString *p, const char *zNeeded){ |
|
99fcc43…
|
drh
|
78 |
if( p==0 ) return 0; |
|
99fcc43…
|
drh
|
79 |
if( zNeeded==0 ) return 0; |
|
99fcc43…
|
drh
|
80 |
while( zNeeded[0] ){ |
|
99fcc43…
|
drh
|
81 |
int c = zNeeded[0]; |
|
99fcc43…
|
drh
|
82 |
if( fossil_isalnum(c) && p->x[c] ) return 1; |
|
99fcc43…
|
drh
|
83 |
zNeeded++; |
|
99fcc43…
|
drh
|
84 |
} |
|
99fcc43…
|
drh
|
85 |
return 0; |
|
99fcc43…
|
drh
|
86 |
} |
|
99fcc43…
|
drh
|
87 |
|
|
99fcc43…
|
drh
|
88 |
/* |
|
99fcc43…
|
drh
|
89 |
** Delete a CapabilityString object. |
|
99fcc43…
|
drh
|
90 |
*/ |
|
99fcc43…
|
drh
|
91 |
void capability_free(CapabilityString *p){ |
|
99fcc43…
|
drh
|
92 |
fossil_free(p); |
|
99fcc43…
|
drh
|
93 |
} |
|
99fcc43…
|
drh
|
94 |
|
|
99fcc43…
|
drh
|
95 |
/* |
|
70a94d0…
|
jan.nijtmans
|
96 |
** Expand the capability string by including all capabilities for |
|
99fcc43…
|
drh
|
97 |
** special users "nobody" and "anonymous". Also include "reader" |
|
99fcc43…
|
drh
|
98 |
** if "u" is present and "developer" if "v" is present. |
|
99fcc43…
|
drh
|
99 |
*/ |
|
99fcc43…
|
drh
|
100 |
void capability_expand(CapabilityString *pIn){ |
|
99fcc43…
|
drh
|
101 |
static char *zNobody = 0; |
|
99fcc43…
|
drh
|
102 |
static char *zAnon = 0; |
|
99fcc43…
|
drh
|
103 |
static char *zReader = 0; |
|
99fcc43…
|
drh
|
104 |
static char *zDev = 0; |
|
a363d26…
|
stephan
|
105 |
static char *zAdmin = "bcdefghijklmnopqrtwz234567ACD"; |
|
397d23c…
|
drh
|
106 |
int doneV = 0; |
|
99fcc43…
|
drh
|
107 |
|
|
99fcc43…
|
drh
|
108 |
if( pIn==0 ){ |
|
99fcc43…
|
drh
|
109 |
fossil_free(zNobody); zNobody = 0; |
|
99fcc43…
|
drh
|
110 |
fossil_free(zAnon); zAnon = 0; |
|
99fcc43…
|
drh
|
111 |
fossil_free(zReader); zReader = 0; |
|
99fcc43…
|
drh
|
112 |
fossil_free(zDev); zDev = 0; |
|
99fcc43…
|
drh
|
113 |
return; |
|
99fcc43…
|
drh
|
114 |
} |
|
99fcc43…
|
drh
|
115 |
if( zNobody==0 ){ |
|
99fcc43…
|
drh
|
116 |
zNobody = db_text(0, "SELECT cap FROM user WHERE login='nobody'"); |
|
99fcc43…
|
drh
|
117 |
zAnon = db_text(0, "SELECT cap FROM user WHERE login='anonymous'"); |
|
397d23c…
|
drh
|
118 |
zReader = db_text(0, "SELECT cap FROM user WHERE login='reader'"); |
|
397d23c…
|
drh
|
119 |
zDev = db_text(0, "SELECT cap FROM user WHERE login='developer'"); |
|
99fcc43…
|
drh
|
120 |
} |
|
99fcc43…
|
drh
|
121 |
pIn = capability_add(pIn, zAnon); |
|
99fcc43…
|
drh
|
122 |
pIn = capability_add(pIn, zNobody); |
|
384fdb6…
|
drh
|
123 |
if( pIn->x['a'] || pIn->x['s'] ){ |
|
384fdb6…
|
drh
|
124 |
pIn = capability_add(pIn, zAdmin); |
|
384fdb6…
|
drh
|
125 |
} |
|
397d23c…
|
drh
|
126 |
if( pIn->x['v'] ){ |
|
397d23c…
|
drh
|
127 |
pIn = capability_add(pIn, zDev); |
|
397d23c…
|
drh
|
128 |
doneV = 1; |
|
397d23c…
|
drh
|
129 |
} |
|
397d23c…
|
drh
|
130 |
if( pIn->x['u'] ){ |
|
397d23c…
|
drh
|
131 |
pIn = capability_add(pIn, zReader); |
|
397d23c…
|
drh
|
132 |
if( pIn->x['v'] && !doneV ){ |
|
397d23c…
|
drh
|
133 |
pIn = capability_add(pIn, zDev); |
|
397d23c…
|
drh
|
134 |
} |
|
397d23c…
|
drh
|
135 |
} |
|
99fcc43…
|
drh
|
136 |
} |
|
99fcc43…
|
drh
|
137 |
|
|
99fcc43…
|
drh
|
138 |
/* |
|
99fcc43…
|
drh
|
139 |
** Render a capability string in canonical string format. Space to hold |
|
99fcc43…
|
drh
|
140 |
** the returned string is obtained from fossil_malloc() can should be freed |
|
99fcc43…
|
drh
|
141 |
** by the caller. |
|
99fcc43…
|
drh
|
142 |
*/ |
|
99fcc43…
|
drh
|
143 |
char *capability_string(CapabilityString *p){ |
|
99fcc43…
|
drh
|
144 |
Blob out; |
|
99fcc43…
|
drh
|
145 |
int i; |
|
99fcc43…
|
drh
|
146 |
int j = 0; |
|
99fcc43…
|
drh
|
147 |
char buf[100]; |
|
99fcc43…
|
drh
|
148 |
blob_init(&out, 0, 0); |
|
99fcc43…
|
drh
|
149 |
for(i='a'; i<='z'; i++){ |
|
99fcc43…
|
drh
|
150 |
if( p->x[i] ) buf[j++] = i; |
|
99fcc43…
|
drh
|
151 |
} |
|
99fcc43…
|
drh
|
152 |
for(i='0'; i<='9'; i++){ |
|
99fcc43…
|
drh
|
153 |
if( p->x[i] ) buf[j++] = i; |
|
99fcc43…
|
drh
|
154 |
} |
|
99fcc43…
|
drh
|
155 |
for(i='A'; i<='Z'; i++){ |
|
99fcc43…
|
drh
|
156 |
if( p->x[i] ) buf[j++] = i; |
|
99fcc43…
|
drh
|
157 |
} |
|
99fcc43…
|
drh
|
158 |
buf[j] = 0; |
|
99fcc43…
|
drh
|
159 |
return fossil_strdup(buf); |
|
99fcc43…
|
drh
|
160 |
} |
|
99fcc43…
|
drh
|
161 |
|
|
99fcc43…
|
drh
|
162 |
/* |
|
99fcc43…
|
drh
|
163 |
** The next two routines implement an aggregate SQL function that |
|
99fcc43…
|
drh
|
164 |
** takes multiple capability strings and in the end returns their |
|
99fcc43…
|
drh
|
165 |
** union. Example usage: |
|
99fcc43…
|
drh
|
166 |
** |
|
99fcc43…
|
drh
|
167 |
** SELECT capunion(cap) FROM user WHERE login IN ('nobody','anonymous'); |
|
99fcc43…
|
drh
|
168 |
*/ |
|
99fcc43…
|
drh
|
169 |
void capability_union_step( |
|
99fcc43…
|
drh
|
170 |
sqlite3_context *context, |
|
99fcc43…
|
drh
|
171 |
int argc, |
|
99fcc43…
|
drh
|
172 |
sqlite3_value **argv |
|
99fcc43…
|
drh
|
173 |
){ |
|
99fcc43…
|
drh
|
174 |
CapabilityString *p; |
|
99fcc43…
|
drh
|
175 |
const char *zIn; |
|
99fcc43…
|
drh
|
176 |
|
|
99fcc43…
|
drh
|
177 |
zIn = (const char*)sqlite3_value_text(argv[0]); |
|
99fcc43…
|
drh
|
178 |
if( zIn==0 ) return; |
|
99fcc43…
|
drh
|
179 |
p = (CapabilityString*)sqlite3_aggregate_context(context, sizeof(*p)); |
|
99fcc43…
|
drh
|
180 |
p = capability_add(p, zIn); |
|
99fcc43…
|
drh
|
181 |
} |
|
99fcc43…
|
drh
|
182 |
void capability_union_finalize(sqlite3_context *context){ |
|
99fcc43…
|
drh
|
183 |
CapabilityString *p; |
|
99fcc43…
|
drh
|
184 |
p = sqlite3_aggregate_context(context, 0); |
|
99fcc43…
|
drh
|
185 |
if( p ){ |
|
99fcc43…
|
drh
|
186 |
char *zOut = capability_string(p); |
|
99fcc43…
|
drh
|
187 |
sqlite3_result_text(context, zOut, -1, fossil_free); |
|
99fcc43…
|
drh
|
188 |
} |
|
99fcc43…
|
drh
|
189 |
} |
|
99fcc43…
|
drh
|
190 |
|
|
99fcc43…
|
drh
|
191 |
/* |
|
99fcc43…
|
drh
|
192 |
** The next routines takes the raw USER.CAP field and expands it with |
|
99fcc43…
|
drh
|
193 |
** capabilities from special users. Example: |
|
99fcc43…
|
drh
|
194 |
** |
|
99fcc43…
|
drh
|
195 |
** SELECT fullcap(cap) FROM user WHERE login=?1 |
|
99fcc43…
|
drh
|
196 |
*/ |
|
99fcc43…
|
drh
|
197 |
void capability_fullcap( |
|
99fcc43…
|
drh
|
198 |
sqlite3_context *context, |
|
99fcc43…
|
drh
|
199 |
int argc, |
|
99fcc43…
|
drh
|
200 |
sqlite3_value **argv |
|
99fcc43…
|
drh
|
201 |
){ |
|
99fcc43…
|
drh
|
202 |
CapabilityString *p; |
|
99fcc43…
|
drh
|
203 |
const char *zIn; |
|
99fcc43…
|
drh
|
204 |
char *zOut; |
|
99fcc43…
|
drh
|
205 |
|
|
99fcc43…
|
drh
|
206 |
zIn = (const char*)sqlite3_value_text(argv[0]); |
|
99fcc43…
|
drh
|
207 |
if( zIn==0 ) zIn = ""; |
|
99fcc43…
|
drh
|
208 |
p = capability_add(0, zIn); |
|
99fcc43…
|
drh
|
209 |
capability_expand(p); |
|
99fcc43…
|
drh
|
210 |
zOut = capability_string(p); |
|
99fcc43…
|
drh
|
211 |
sqlite3_result_text(context, zOut, -1, fossil_free); |
|
99fcc43…
|
drh
|
212 |
capability_free(p); |
|
99fcc43…
|
drh
|
213 |
} |
|
99fcc43…
|
drh
|
214 |
|
|
8689cf8…
|
drh
|
215 |
#if INTERFACE |
|
8689cf8…
|
drh
|
216 |
/* |
|
8689cf8…
|
drh
|
217 |
** Capabilities are grouped into "classes" as follows: |
|
8689cf8…
|
drh
|
218 |
*/ |
|
8689cf8…
|
drh
|
219 |
#define CAPCLASS_CODE 0x0001 |
|
8689cf8…
|
drh
|
220 |
#define CAPCLASS_WIKI 0x0002 |
|
8689cf8…
|
drh
|
221 |
#define CAPCLASS_TKT 0x0004 |
|
8689cf8…
|
drh
|
222 |
#define CAPCLASS_FORUM 0x0008 |
|
8689cf8…
|
drh
|
223 |
#define CAPCLASS_DATA 0x0010 |
|
8689cf8…
|
drh
|
224 |
#define CAPCLASS_ALERT 0x0020 |
|
8689cf8…
|
drh
|
225 |
#define CAPCLASS_OTHER 0x0040 |
|
8689cf8…
|
drh
|
226 |
#define CAPCLASS_SUPER 0x0080 |
|
8689cf8…
|
drh
|
227 |
#define CAPCLASS_ALL 0xffff |
|
8689cf8…
|
drh
|
228 |
#endif /* INTERFACE */ |
|
8689cf8…
|
drh
|
229 |
|
|
8689cf8…
|
drh
|
230 |
|
|
8689cf8…
|
drh
|
231 |
/* |
|
8689cf8…
|
drh
|
232 |
** The following structure holds descriptions of the various capabilities. |
|
8689cf8…
|
drh
|
233 |
*/ |
|
8689cf8…
|
drh
|
234 |
static struct Caps { |
|
8689cf8…
|
drh
|
235 |
char cCap; /* The capability letter */ |
|
8689cf8…
|
drh
|
236 |
unsigned short eClass; /* The "class" for this capability */ |
|
5944217…
|
drh
|
237 |
unsigned nUser; /* Number of users with this capability */ |
|
8689cf8…
|
drh
|
238 |
char *zAbbrev; /* Abbreviated mnemonic name */ |
|
8689cf8…
|
drh
|
239 |
char *zOneLiner; /* One-line summary */ |
|
8689cf8…
|
drh
|
240 |
} aCap[] = { |
|
5944217…
|
drh
|
241 |
{ 'a', CAPCLASS_SUPER, 0, |
|
8689cf8…
|
drh
|
242 |
"Admin", "Create and delete users" }, |
|
5944217…
|
drh
|
243 |
{ 'b', CAPCLASS_WIKI|CAPCLASS_TKT, 0, |
|
7dd07b2…
|
drh
|
244 |
"Attach", "Add attachments to wiki or tickets" }, |
|
5944217…
|
drh
|
245 |
{ 'c', CAPCLASS_TKT, 0, |
|
8689cf8…
|
drh
|
246 |
"Append-Tkt", "Append to existing tickets" }, |
|
1274054…
|
drh
|
247 |
/* |
|
1274054…
|
drh
|
248 |
** d unused since fork from CVSTrac; |
|
1274054…
|
drh
|
249 |
** see https://fossil-scm.org/forum/forumpost/43c78f4bef |
|
1274054…
|
drh
|
250 |
*/ |
|
5944217…
|
drh
|
251 |
{ 'e', CAPCLASS_DATA, 0, |
|
8689cf8…
|
drh
|
252 |
"View-PII", "View sensitive info such as email addresses" }, |
|
5944217…
|
drh
|
253 |
{ 'f', CAPCLASS_WIKI, 0, |
|
8689cf8…
|
drh
|
254 |
"New-Wiki", "Create new wiki pages" }, |
|
5944217…
|
drh
|
255 |
{ 'g', CAPCLASS_DATA, 0, |
|
8689cf8…
|
drh
|
256 |
"Clone", "Clone the repository" }, |
|
5944217…
|
drh
|
257 |
{ 'h', CAPCLASS_OTHER, 0, |
|
8689cf8…
|
drh
|
258 |
"Hyperlinks", "Show hyperlinks to detailed repository history" }, |
|
5944217…
|
drh
|
259 |
{ 'i', CAPCLASS_CODE, 0, |
|
8689cf8…
|
drh
|
260 |
"Check-In", "Check-in code changes" }, |
|
5944217…
|
drh
|
261 |
{ 'j', CAPCLASS_WIKI, 0, |
|
8689cf8…
|
drh
|
262 |
"Read-Wiki", "View wiki pages" }, |
|
5944217…
|
drh
|
263 |
{ 'k', CAPCLASS_WIKI, 0, |
|
8689cf8…
|
drh
|
264 |
"Write-Wiki", "Edit wiki pages" }, |
|
5944217…
|
drh
|
265 |
{ 'l', CAPCLASS_WIKI|CAPCLASS_SUPER, 0, |
|
8689cf8…
|
drh
|
266 |
"Mod-Wiki", "Moderator for wiki pages" }, |
|
5944217…
|
drh
|
267 |
{ 'm', CAPCLASS_WIKI, 0, |
|
8689cf8…
|
drh
|
268 |
"Append-Wiki", "Append to wiki pages" }, |
|
5944217…
|
drh
|
269 |
{ 'n', CAPCLASS_TKT, 0, |
|
8689cf8…
|
drh
|
270 |
"New-Tkt", "Create new tickets" }, |
|
5944217…
|
drh
|
271 |
{ 'o', CAPCLASS_CODE, 0, |
|
8689cf8…
|
drh
|
272 |
"Check-Out", "Check out code" }, |
|
5944217…
|
drh
|
273 |
{ 'p', CAPCLASS_OTHER, 0, |
|
8689cf8…
|
drh
|
274 |
"Password", "Change your own password" }, |
|
5944217…
|
drh
|
275 |
{ 'q', CAPCLASS_TKT|CAPCLASS_SUPER, 0, |
|
8689cf8…
|
drh
|
276 |
"Mod-Tkt", "Moderate tickets" }, |
|
5944217…
|
drh
|
277 |
{ 'r', CAPCLASS_TKT, 0, |
|
8689cf8…
|
drh
|
278 |
"Read-Tkt", "View tickets" }, |
|
5944217…
|
drh
|
279 |
{ 's', CAPCLASS_SUPER, 0, |
|
9993c43…
|
danshearer
|
280 |
"Superuser", "Setup and configure the repository" }, |
|
5944217…
|
drh
|
281 |
{ 't', CAPCLASS_TKT, 0, |
|
8689cf8…
|
drh
|
282 |
"Reports", "Create new ticket report formats" }, |
|
5944217…
|
drh
|
283 |
{ 'u', CAPCLASS_OTHER, 0, |
|
8689cf8…
|
drh
|
284 |
"Reader", "Inherit all the capabilities of the \"reader\" user" }, |
|
5944217…
|
drh
|
285 |
{ 'v', CAPCLASS_OTHER, 0, |
|
8689cf8…
|
drh
|
286 |
"Developer", "Inherit all capabilities of the \"developer\" user" }, |
|
5944217…
|
drh
|
287 |
{ 'w', CAPCLASS_TKT, 0, |
|
8689cf8…
|
drh
|
288 |
"Write-Tkt", "Edit tickets" }, |
|
5944217…
|
drh
|
289 |
{ 'x', CAPCLASS_DATA, 0, |
|
8689cf8…
|
drh
|
290 |
"Private", "Push and/or pull private branches" }, |
|
5944217…
|
drh
|
291 |
{ 'y', CAPCLASS_SUPER, 0, |
|
8689cf8…
|
drh
|
292 |
"Write-UV", "Push unversioned content" }, |
|
5944217…
|
drh
|
293 |
{ 'z', CAPCLASS_CODE, 0, |
|
8689cf8…
|
drh
|
294 |
"Zip-Download", "Download a ZIP archive, tarball, or SQL archive" }, |
|
5944217…
|
drh
|
295 |
{ '2', CAPCLASS_FORUM, 0, |
|
8689cf8…
|
drh
|
296 |
"Forum-Read", "Read forum posts by others" }, |
|
5944217…
|
drh
|
297 |
{ '3', CAPCLASS_FORUM, 0, |
|
8689cf8…
|
drh
|
298 |
"Forum-Write", "Create new forum messages" }, |
|
5944217…
|
drh
|
299 |
{ '4', CAPCLASS_FORUM, 0, |
|
8689cf8…
|
drh
|
300 |
"Forum-Trusted", "Create forum messages that bypass moderation" }, |
|
5944217…
|
drh
|
301 |
{ '5', CAPCLASS_FORUM|CAPCLASS_SUPER, 0, |
|
8689cf8…
|
drh
|
302 |
"Forum-Mod", "Moderator for forum messages" }, |
|
5944217…
|
drh
|
303 |
{ '6', CAPCLASS_FORUM|CAPCLASS_SUPER, 0, |
|
779ddef…
|
wyoung
|
304 |
"Forum-Admin", "Grant capability '4' to other users" }, |
|
5944217…
|
drh
|
305 |
{ '7', CAPCLASS_ALERT, 0, |
|
8689cf8…
|
drh
|
306 |
"Alerts", "Sign up for email alerts" }, |
|
5944217…
|
drh
|
307 |
{ 'A', CAPCLASS_ALERT|CAPCLASS_SUPER, 0, |
|
8689cf8…
|
drh
|
308 |
"Announce", "Send announcements to all subscribers" }, |
|
5079ffb…
|
stephan
|
309 |
{ 'B', CAPCLASS_FORUM|CAPCLASS_SUPER, 0, |
|
5079ffb…
|
stephan
|
310 |
"Forum-Attach", "Add attachment to Forum posts" }, |
|
e8ba89b…
|
drh
|
311 |
{ 'C', CAPCLASS_FORUM, 0, |
|
e8ba89b…
|
drh
|
312 |
"Chat", "Read and/or writes messages in the chatroom" }, |
|
5944217…
|
drh
|
313 |
{ 'D', CAPCLASS_OTHER, 0, |
|
8689cf8…
|
drh
|
314 |
"Debug", "Enable debugging features" }, |
|
8689cf8…
|
drh
|
315 |
}; |
|
5944217…
|
drh
|
316 |
|
|
5944217…
|
drh
|
317 |
/* |
|
5944217…
|
drh
|
318 |
** Populate the aCap[].nUser values based on the current content |
|
5944217…
|
drh
|
319 |
** of the USER table. |
|
5944217…
|
drh
|
320 |
*/ |
|
5944217…
|
drh
|
321 |
void capabilities_count(void){ |
|
5944217…
|
drh
|
322 |
int i; |
|
5944217…
|
drh
|
323 |
static int done = 0; |
|
5944217…
|
drh
|
324 |
Stmt q; |
|
5944217…
|
drh
|
325 |
if( done ) return; |
|
5944217…
|
drh
|
326 |
db_prepare(&q, "SELECT fullcap(cap) FROM user"); |
|
5944217…
|
drh
|
327 |
while( db_step(&q)==SQLITE_ROW ){ |
|
5944217…
|
drh
|
328 |
const char *zCap = db_column_text(&q, 0); |
|
5944217…
|
drh
|
329 |
if( zCap==0 || zCap[0]==0 ) continue; |
|
53db40e…
|
drh
|
330 |
for(i=0; i<(int)(sizeof(aCap)/sizeof(aCap[0])); i++){ |
|
5944217…
|
drh
|
331 |
if( strchr(zCap, aCap[i].cCap) ) aCap[i].nUser++; |
|
5944217…
|
drh
|
332 |
} |
|
5944217…
|
drh
|
333 |
} |
|
5944217…
|
drh
|
334 |
db_finalize(&q); |
|
5944217…
|
drh
|
335 |
done = 1; |
|
5944217…
|
drh
|
336 |
} |
|
8689cf8…
|
drh
|
337 |
|
|
8689cf8…
|
drh
|
338 |
|
|
99fcc43…
|
drh
|
339 |
/* |
|
99fcc43…
|
drh
|
340 |
** Generate HTML that lists all of the capability letters together with |
|
99fcc43…
|
drh
|
341 |
** a brief summary of what each letter means. |
|
99fcc43…
|
drh
|
342 |
*/ |
|
8689cf8…
|
drh
|
343 |
void capabilities_table(unsigned mClass){ |
|
8689cf8…
|
drh
|
344 |
int i; |
|
5944217…
|
drh
|
345 |
if( g.perm.Admin ) capabilities_count(); |
|
99fcc43…
|
drh
|
346 |
@ <table> |
|
5944217…
|
drh
|
347 |
@ <tbody> |
|
53db40e…
|
drh
|
348 |
for(i=0; i<(int)(sizeof(aCap)/sizeof(aCap[0])); i++){ |
|
5944217…
|
drh
|
349 |
int n; |
|
8689cf8…
|
drh
|
350 |
if( (aCap[i].eClass & mClass)==0 ) continue; |
|
8689cf8…
|
drh
|
351 |
@ <tr><th valign="top">%c(aCap[i].cCap)</th> |
|
5944217…
|
drh
|
352 |
@ <td>%h(aCap[i].zAbbrev)</td><td>%h(aCap[i].zOneLiner)</td>\ |
|
5944217…
|
drh
|
353 |
n = aCap[i].nUser; |
|
5944217…
|
drh
|
354 |
if( n && g.perm.Admin ){ |
|
5944217…
|
drh
|
355 |
@ <td><a href="%R/setup_ulist?with=%c(aCap[i].cCap)">\ |
|
5944217…
|
drh
|
356 |
@ %d(n) user%s(n>1?"s":"")</a></td>\ |
|
5944217…
|
drh
|
357 |
} |
|
5944217…
|
drh
|
358 |
@ </tr> |
|
8689cf8…
|
drh
|
359 |
} |
|
5944217…
|
drh
|
360 |
@ </tbody> |
|
99fcc43…
|
drh
|
361 |
@ </table> |
|
99fcc43…
|
drh
|
362 |
} |
|
99fcc43…
|
drh
|
363 |
|
|
99fcc43…
|
drh
|
364 |
/* |
|
99fcc43…
|
drh
|
365 |
** Generate a "capability summary table" that shows the major capabilities |
|
99fcc43…
|
drh
|
366 |
** against the various user categories. |
|
99fcc43…
|
drh
|
367 |
*/ |
|
99fcc43…
|
drh
|
368 |
void capability_summary(void){ |
|
99fcc43…
|
drh
|
369 |
Stmt q; |
|
0c37445…
|
drh
|
370 |
CapabilityString *pCap; |
|
0c37445…
|
drh
|
371 |
char *zSelfCap; |
|
0c37445…
|
drh
|
372 |
char *zPubPages = db_get("public-pages",0); |
|
0c37445…
|
drh
|
373 |
int hasPubPages = zPubPages && zPubPages[0]; |
|
0c37445…
|
drh
|
374 |
|
|
c00e912…
|
drh
|
375 |
pCap = capability_add(0, db_get("default-perms","u")); |
|
0c37445…
|
drh
|
376 |
capability_expand(pCap); |
|
0c37445…
|
drh
|
377 |
zSelfCap = capability_string(pCap); |
|
0c37445…
|
drh
|
378 |
capability_free(pCap); |
|
0c37445…
|
drh
|
379 |
|
|
99fcc43…
|
drh
|
380 |
db_prepare(&q, |
|
99fcc43…
|
drh
|
381 |
"WITH t(id,seq) AS (VALUES('nobody',1),('anonymous',2),('reader',3)," |
|
99fcc43…
|
drh
|
382 |
"('developer',4))" |
|
b833df2…
|
drh
|
383 |
" SELECT id, CASE WHEN user.login='nobody' THEN user.cap" |
|
b833df2…
|
drh
|
384 |
" ELSE fullcap(user.cap) END,seq,1" |
|
99fcc43…
|
drh
|
385 |
" FROM t LEFT JOIN user ON t.id=user.login" |
|
99fcc43…
|
drh
|
386 |
" UNION ALL" |
|
0c37445…
|
drh
|
387 |
" SELECT 'Public Pages', %Q, 100, %d" |
|
0c37445…
|
drh
|
388 |
" UNION ALL" |
|
0c37445…
|
drh
|
389 |
" SELECT 'New User Default', %Q, 110, 1" |
|
99fcc43…
|
drh
|
390 |
" UNION ALL" |
|
0c37445…
|
drh
|
391 |
" SELECT 'Regular User', fullcap(capunion(cap)), 200, count(*) FROM user" |
|
63febeb…
|
drh
|
392 |
" WHERE cap NOT GLOB '*[as]*' AND login NOT IN (SELECT id FROM t)" |
|
99fcc43…
|
drh
|
393 |
" UNION ALL" |
|
0df0586…
|
danield
|
394 |
" SELECT 'Administrator', fullcap(capunion(cap)), 300, count(*) FROM user" |
|
99fcc43…
|
drh
|
395 |
" WHERE cap GLOB '*[as]*'" |
|
99fcc43…
|
drh
|
396 |
" ORDER BY 3 ASC", |
|
0c37445…
|
drh
|
397 |
zSelfCap, hasPubPages, zSelfCap |
|
99fcc43…
|
drh
|
398 |
); |
|
99fcc43…
|
drh
|
399 |
@ <table id='capabilitySummary' cellpadding="0" cellspacing="0" border="1"> |
|
e8ba89b…
|
drh
|
400 |
@ <tr><th> <th>Code<th>Forum<th>Tickets<th>Wiki<th>Chat\ |
|
99fcc43…
|
drh
|
401 |
@ <th>Unversioned Content</th></tr> |
|
99fcc43…
|
drh
|
402 |
while( db_step(&q)==SQLITE_ROW ){ |
|
99fcc43…
|
drh
|
403 |
const char *zId = db_column_text(&q, 0); |
|
99fcc43…
|
drh
|
404 |
const char *zCap = db_column_text(&q, 1); |
|
99fcc43…
|
drh
|
405 |
int n = db_column_int(&q, 3); |
|
99fcc43…
|
drh
|
406 |
int eType; |
|
70a94d0…
|
jan.nijtmans
|
407 |
static const char *const azType[] = { "off", "read", "write" }; |
|
275da70…
|
danield
|
408 |
static const char *const azClass[] = |
|
0c37445…
|
drh
|
409 |
{ "capsumOff", "capsumRead", "capsumWrite" }; |
|
99fcc43…
|
drh
|
410 |
|
|
99fcc43…
|
drh
|
411 |
if( n==0 ) continue; |
|
99fcc43…
|
drh
|
412 |
|
|
99fcc43…
|
drh
|
413 |
/* Code */ |
|
99fcc43…
|
drh
|
414 |
if( db_column_int(&q,2)<10 ){ |
|
99fcc43…
|
drh
|
415 |
@ <tr><th align="right"><tt>"%h(zId)"</tt></th> |
|
99fcc43…
|
drh
|
416 |
}else if( n>1 ){ |
|
99fcc43…
|
drh
|
417 |
@ <tr><th align="right">%d(n) %h(zId)s</th> |
|
99fcc43…
|
drh
|
418 |
}else{ |
|
99fcc43…
|
drh
|
419 |
@ <tr><th align="right">%h(zId)</th> |
|
99fcc43…
|
drh
|
420 |
} |
|
99fcc43…
|
drh
|
421 |
if( sqlite3_strglob("*[asi]*",zCap)==0 ){ |
|
99fcc43…
|
drh
|
422 |
eType = 2; |
|
99fcc43…
|
drh
|
423 |
}else if( sqlite3_strglob("*[oz]*",zCap)==0 ){ |
|
99fcc43…
|
drh
|
424 |
eType = 1; |
|
99fcc43…
|
drh
|
425 |
}else{ |
|
99fcc43…
|
drh
|
426 |
eType = 0; |
|
99fcc43…
|
drh
|
427 |
} |
|
99fcc43…
|
drh
|
428 |
@ <td class="%s(azClass[eType])">%s(azType[eType])</td> |
|
99fcc43…
|
drh
|
429 |
|
|
99fcc43…
|
drh
|
430 |
/* Forum */ |
|
99fcc43…
|
drh
|
431 |
if( sqlite3_strglob("*[as3456]*",zCap)==0 ){ |
|
99fcc43…
|
drh
|
432 |
eType = 2; |
|
99fcc43…
|
drh
|
433 |
}else if( sqlite3_strglob("*2*",zCap)==0 ){ |
|
99fcc43…
|
drh
|
434 |
eType = 1; |
|
99fcc43…
|
drh
|
435 |
}else{ |
|
99fcc43…
|
drh
|
436 |
eType = 0; |
|
99fcc43…
|
drh
|
437 |
} |
|
99fcc43…
|
drh
|
438 |
@ <td class="%s(azClass[eType])">%s(azType[eType])</td> |
|
99fcc43…
|
drh
|
439 |
|
|
99fcc43…
|
drh
|
440 |
/* Ticket */ |
|
3941824…
|
drh
|
441 |
if( sqlite3_strglob("*[ascnqtw]*",zCap)==0 ){ |
|
99fcc43…
|
drh
|
442 |
eType = 2; |
|
99fcc43…
|
drh
|
443 |
}else if( sqlite3_strglob("*r*",zCap)==0 ){ |
|
99fcc43…
|
drh
|
444 |
eType = 1; |
|
99fcc43…
|
drh
|
445 |
}else{ |
|
99fcc43…
|
drh
|
446 |
eType = 0; |
|
99fcc43…
|
drh
|
447 |
} |
|
99fcc43…
|
drh
|
448 |
@ <td class="%s(azClass[eType])">%s(azType[eType])</td> |
|
99fcc43…
|
drh
|
449 |
|
|
99fcc43…
|
drh
|
450 |
/* Wiki */ |
|
99fcc43…
|
drh
|
451 |
if( sqlite3_strglob("*[asdfklm]*",zCap)==0 ){ |
|
99fcc43…
|
drh
|
452 |
eType = 2; |
|
99fcc43…
|
drh
|
453 |
}else if( sqlite3_strglob("*j*",zCap)==0 ){ |
|
99fcc43…
|
drh
|
454 |
eType = 1; |
|
e8ba89b…
|
drh
|
455 |
}else{ |
|
e8ba89b…
|
drh
|
456 |
eType = 0; |
|
e8ba89b…
|
drh
|
457 |
} |
|
e8ba89b…
|
drh
|
458 |
@ <td class="%s(azClass[eType])">%s(azType[eType])</td> |
|
e8ba89b…
|
drh
|
459 |
|
|
e8ba89b…
|
drh
|
460 |
/* Chat */ |
|
e8ba89b…
|
drh
|
461 |
if( sqlite3_strglob("*C*",zCap)==0 ){ |
|
e8ba89b…
|
drh
|
462 |
eType = 2; |
|
99fcc43…
|
drh
|
463 |
}else{ |
|
99fcc43…
|
drh
|
464 |
eType = 0; |
|
99fcc43…
|
drh
|
465 |
} |
|
99fcc43…
|
drh
|
466 |
@ <td class="%s(azClass[eType])">%s(azType[eType])</td> |
|
99fcc43…
|
drh
|
467 |
|
|
99fcc43…
|
drh
|
468 |
/* Unversioned */ |
|
99fcc43…
|
drh
|
469 |
if( sqlite3_strglob("*y*",zCap)==0 ){ |
|
99fcc43…
|
drh
|
470 |
eType = 2; |
|
99fcc43…
|
drh
|
471 |
}else if( sqlite3_strglob("*[ioas]*",zCap)==0 ){ |
|
99fcc43…
|
drh
|
472 |
eType = 1; |
|
99fcc43…
|
drh
|
473 |
}else{ |
|
99fcc43…
|
drh
|
474 |
eType = 0; |
|
99fcc43…
|
drh
|
475 |
} |
|
99fcc43…
|
drh
|
476 |
@ <td class="%s(azClass[eType])">%s(azType[eType])</td> |
|
99fcc43…
|
drh
|
477 |
|
|
99fcc43…
|
drh
|
478 |
} |
|
99fcc43…
|
drh
|
479 |
db_finalize(&q); |
|
99fcc43…
|
drh
|
480 |
@ </table> |
|
99fcc43…
|
drh
|
481 |
} |