security.lib.php
11.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
<?php
/*
File: security.lib.php
Author: Chris
Date: 2000/12/14
Owl: Copyright Chris Vincent <cvincent@project802.net>
You should have received a copy of the GNU Public
License along with this package; if not, write to the
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
function getfolderpolicy($id) {
global $default;
$sql = new Owl_DB; $sql->query("select security from $default->owl_folders_table where id = '$id'");
while ($sql->next_record()) return $sql->f("security");
}
function getfilepolicy($id) {
global $default;
$sql = new Owl_DB; $sql->query("select security from $default->owl_files_table where id = '$id'");
while ($sql->next_record()) return $sql->f("security");
}
//
// This function is simple...it returns either a 1 or 0
// If the authentication is good, it returns 1
// If the authentication is bad, it returns 0
//
// Policy key for FILES:
//
// 0 = World read
// 1 = World edit
// 6 = World edit no delete
// 2 = Group read
// 3 = Group edit
// 5 = Group edit no delete
// 4 = Creator edit
// 7 = Group edit, World read
// 8 = Group edit, World read - no delete
//
// Policy key for FOLDERS:
//
// 50 = Anyone can read
// 51 = Anyone can upload/create folders
// 56 = Anyone can upload/create folders but not delete
// 52 = Only the group can read
// 53 = Only the group can upload/create folders
// 55 = Only the group can upload/create folders but not delete; except the creator
// 54 = Only the creator can upload/create folders
// 57 = Only the group can upload/create folders but anyone can read
// 58 = Only the group can upload/create folders (no delete) but anyone can read
//
function check_auth($id, $action, $userid) {
global $default;
$usergroup = owlusergroup($userid);
$filecreator = owlfilecreator($id);
$foldercreator = owlfoldercreator($id);
$filegroup = owlfilegroup($id);
$foldergroup = owlfoldergroup($id);
// print "Action is $action<br>";
// print "filecreation username is $filecreator<br>";
// print "filecreation groupname is $filegroup<br>";
// print "folder group is $foldergroup<br>";
// print "userid is $userid<br>";
// print "dbusername is $dbuser<br>";
// print "usergroup is $usergroup<br>";
if (($action == "folder_modify") ||
($action == "folder_view") ||
($action == "folder_delete") ||
($action == "folder_property")) {
$policy = getfolderpolicy($id);
} else {
$policy = getfilepolicy($id);
}
// print "Policy is $policy<br>";
if ($policy == "0") {
if (($action == "file_delete") || ($action == "file_modify")) {
if ($userid != $filecreator) {
$authorization = "0";
} else {
$authorization = "1";
}
} else {
$authorization = "1";
}
}
if ($policy == "1") {
$authorization = "1";
}
if ($policy == "2") {
if (($action == "file_delete") || ($action == "file_modify")) {
if ($userid != $filecreator) {
$authorization = "0";
} else {
$authorization = "1";
}
} else {
// Bozz Change Begin
$sql = new Owl_DB;
$sql->query("SELECT * FROM $default->owl_users_grpmem_table WHERE userid = '$userid' and groupid = '$filegroup'");
if ($filegroup == $usergroup || $sql->num_rows($sql) > 0) {
// Bozz Change End
$authorization = "1";
} else {
$authorization = "0";
}
}
}
if ($policy == "3") {
if (($action == "file_delete") || ($action == "file_modify") || ($action == "file_download")) {
// Bozz Change Begin
$sql = new Owl_DB;
$sql->query("SELECT * FROM $default->owl_users_grpmem_table WHERE userid = '$userid' and groupid = '$filegroup'");
// Bozz Change End
if ($usergroup != $filegroup && $sql->num_rows($sql) == 0) {
$authorization = "0";
} else {
$authorization = "1";
}
}
}
if ($policy == "4") {
if ($filecreator == $userid) {
$authorization = "1";
} else {
$authorization = "0";
}
}
if ($policy == "5") {
if (($action == "file_modify") || ($action == "file_download")) {
// Bozz Change Begin
$sql = new Owl_DB;
$sql->query("SELECT * FROM $default->owl_users_grpmem_table WHERE userid = '$userid' and groupid = '$filegroup'");
// Bozz Change End
if ($usergroup != $filegroup && $sql->num_rows($sql) == 0) {
$authorization = "0";
} else {
$authorization = "1";
}
}
if ($action == "file_delete") {
if ($filecreator == $userid) {
$authorization = "1";
} else {
$authorization = "0";
}
}
}
if ($policy == "6") {
$authorization = "1";
if ($action == "file_delete") {
if ($filecreator == $userid) {
$authorization = "1";
} else {
$authorization = "0";
}
}
}
if ($policy == "7") {
if (($action == "file_delete") || ($action == "file_modify")) {
$sql = new Owl_DB;
$sql->query("SELECT * FROM $default->owl_users_grpmem_table WHERE userid = '$userid' and groupid = '$filegroup'");
if ($usergroup != $filegroup && $sql->num_rows($sql) == 0) {
$authorization = "0";
} else {
$authorization = "1";
}
}
if ($action == "file_download") {
$authorization = "1";
}
}
if ($policy == "8") {
if ($action == "file_modify") {
$sql = new Owl_DB;
$sql->query("SELECT * FROM $default->owl_users_grpmem_table WHERE userid = '$userid' and groupid = '$filegroup'");
if ($usergroup != $filegroup && $sql->num_rows($sql) == 0) {
$authorization = "0";
} else {
$authorization = "1";
}
}
if ($action == "file_download") {
$authorization = "1";
}
if ($action == "file_delete") {
if ($filecreator == $userid) {
$authorization = "1";
} else {
$authorization = "0";
}
}
}
if ($policy == "50") {
if (($action == "folder_delete") ||
($action == "folder_property") ||
($action == "folder_modify")) {
if ($userid != $foldercreator) {
$authorization = "0";
} else {
$authorization = "1";
}
} else {
$authorization = "1";
}
}
if ($policy == "51") {
$authorization = "1";
}
if ($policy == "52") {
if (($action == "folder_delete") ||
($action == "folder_property") ||
($action == "folder_modify")) {
if ($userid != $foldercreator) {
$authorization = "0";
} else {
$authorization = "1";
}
} else {
// Bozz Change Begin
$sql = new Owl_DB;
$sql->query("SELECT * FROM $default->owl_users_grpmem_table WHERE userid = '$userid' and groupid = '$foldergroup'");
if ($foldergroup == $usergroup || $sql->num_rows($sql) > 0) {
// Bozz Change End
$authorization = "1";
} else {
$authorization = "0";
}
}
}
if ($policy == "53") {
if (($action == "folder_delete") ||
($action == "folder_modify") ||
($action == "folder_property") ||
($action == "folder_view")) {
// Bozz Change Begin
$sql = new Owl_DB;
$sql->query("SELECT * FROM $default->owl_users_grpmem_table WHERE userid = '$userid' and groupid = '$foldergroup'");
if ($usergroup != $foldergroup && $sql->num_rows($sql) == 0) {
// Bozz Change End
$authorization = "0";
} else {
$authorization = "1";
}
}
}
if ($policy == "54") {
if ($foldercreator == $userid) {
$authorization = "1";
} else {
$authorization = "0";
}
}
if ($policy == "55") {
if (($action == "folder_modify") || ($action == "folder_view")) {
// Bozz Change Begin
$sql = new Owl_DB;
$sql->query("SELECT * FROM $default->owl_users_grpmem_table WHERE userid = '$userid' and groupid = '$foldergroup'");
if ($usergroup != $foldergroup && $sql->num_rows($sql) == 0) {
// Bozz Change End
$authorization = "0";
} else {
$authorization = "1";
}
}
if (($action == "folder_delete") ||
($action == "folder_property")) {
if ($foldercreator == $userid) {
$authorization = "1";
} else {
$authorization = "0";
}
}
}
if ($policy == "56") {
$authorization = "1";
if (($action == "folder_delete") ||
($action == "folder_property")) {
if ($foldercreator == $userid) {
$authorization = "1";
} else {
$authorization = "0";
}
}
}
if ($policy == "57") {
if (($action == "folder_modify") || ($action == "folder_delete")) {
$sql = new Owl_DB;
$sql->query("SELECT * FROM $default->owl_users_grpmem_table WHERE userid = '$userid' and groupid = '$foldergroup'");
if (($usergroup != $foldergroup) && ($sql->num_rows($sql) == 0)) {
$authorization = "0";
} else {
$authorization = "1";
}
}
if ($action == "folder_property") {
if ($foldercreator == $userid) {
$authorization = "1";
} else {
$authorization = "0";
}
}
if ($action == "folder_view") {
$authorization = "1";
}
}
if ($policy == "58") {
if ($action == "folder_modify") {
$sql = new Owl_DB;
$sql->query("SELECT * FROM $default->owl_users_grpmem_table WHERE userid = '$userid' and groupid = '$foldergroup'");
if ($usergroup != $foldergroup && $sql->num_rows($sql) == 0) {
$authorization = "0";
} else {
$authorization = "1";
}
}
if ($action == "folder_property") {
if ($foldercreator == $userid) {
$authorization = "1";
} else {
$authorization = "0";
}
}
if ($action == "folder_delete") {
if ($foldercreator == $userid) {
$authorization = "1";
} else {
$authorization = "0";
}
}
if ($action == "folder_view") {
$authorization = "1";
}
}
// Bozz Change Begin
// I Think that the Admin Group should
// have the same rights as the admin user
if ($userid == 1 || $usergroup == 0) {
// Bozz Change End
$authorization = "1";
}
// cv change bug #504298
// this call must be recursive through the parent directories
// continue recursion?
if( $authorization == 1 ) {
if( ($policy > 49) && ($id == 1) ) {
// stop if we are at the doc root
return $authorization;
} else {
// continue;
if($policy < 50) {
$parent = owlfileparent($id);
} else {
$parent = owlfolderparent($id);
}
return check_auth($parent, "folder_view", $userid);
}
} else {
// dont continue because authorization is 0
return $authorization;
}
}