]>
Commit | Line | Data |
---|---|---|
7ac48069 | 1 | /* $Id$ |
73cf66ba | 2 | * |
7ac48069 | 3 | * Check access to queries |
73cf66ba | 4 | * |
7ac48069 | 5 | * Copyright (C) 1987-1998 by the Massachusetts Institute of Technology |
6 | * For copying and distribution information, please see the file | |
7 | * <mit-copyright.h>. | |
73cf66ba | 8 | */ |
9 | ||
73cf66ba | 10 | #include <mit-copyright.h> |
73cf66ba | 11 | #include "mr_server.h" |
7ac48069 | 12 | #include "qrtn.h" |
03c05291 | 13 | #include "query.h" |
7ac48069 | 14 | |
73cf66ba | 15 | #include <ctype.h> |
7ac48069 | 16 | #include <stdlib.h> |
17 | ||
73cf66ba | 18 | EXEC SQL INCLUDE sqlca; |
7ac48069 | 19 | |
20 | RCSID("$Header$"); | |
73cf66ba | 21 | |
22 | extern char *whoami; | |
03c05291 | 23 | extern int dbms_errno, mr_errcode; |
73cf66ba | 24 | |
03c05291 | 25 | EXEC SQL WHENEVER SQLERROR DO dbmserr(); |
73cf66ba | 26 | |
27 | ||
28 | /* Specialized Access Routines */ | |
29 | ||
30 | /* access_user - verify that client name equals specified login name | |
31 | * | |
32 | * - since field validation routines are called first, a users_id is | |
33 | * now in argv[0] instead of the login name. | |
34 | */ | |
35 | ||
5eaef520 | 36 | int access_user(struct query *q, char *argv[], client *cl) |
73cf66ba | 37 | { |
5eaef520 | 38 | if (cl->users_id != *(int *)argv[0]) |
39 | return MR_PERM; | |
40 | else | |
41 | return MR_SUCCESS; | |
73cf66ba | 42 | } |
43 | ||
44 | ||
45 | ||
46 | /* access_login - verify that client name equals specified login name | |
47 | * | |
48 | * argv[0...n] contain search info. q-> | |
49 | */ | |
50 | ||
5eaef520 | 51 | int access_login(struct query *q, char *argv[], client *cl) |
73cf66ba | 52 | { |
5eaef520 | 53 | EXEC SQL BEGIN DECLARE SECTION; |
54 | int id; | |
55 | EXEC SQL END DECLARE SECTION; | |
73cf66ba | 56 | |
5eaef520 | 57 | if (q->argc != 1) |
58 | return MR_ARGS; | |
03c05291 | 59 | |
5eaef520 | 60 | if (!strcmp(q->shortname, "gual")) |
61 | { | |
5906749e | 62 | EXEC SQL SELECT users_id INTO :id FROM users |
cc0ec904 | 63 | WHERE login = :argv[0] AND users_id != 0; |
5eaef520 | 64 | } |
65 | else if (!strcmp(q->shortname, "gubl")) | |
66 | { | |
03c05291 | 67 | EXEC SQL SELECT users_id INTO :id FROM users u |
cc0ec904 | 68 | WHERE u.login = :argv[0] AND u.users_id != 0; |
5eaef520 | 69 | } |
70 | else if (!strcmp(q->shortname, "guau")) | |
71 | { | |
5906749e | 72 | EXEC SQL SELECT users_id INTO :id FROM users |
73 | WHERE unix_uid = :argv[0] AND users_id != 0; | |
5eaef520 | 74 | } |
75 | else if (!strcmp(q->shortname, "gubu")) | |
76 | { | |
03c05291 | 77 | EXEC SQL SELECT users_id INTO :id FROM users u |
78 | WHERE u.unix_uid = :argv[0] AND u.users_id != 0; | |
73cf66ba | 79 | } |
80 | ||
5eaef520 | 81 | if (sqlca.sqlcode == SQL_NO_MATCH) |
82 | return MR_NO_MATCH; /* ought to be MR_USER, but this is what | |
83 | gual returns, so we have to be consistent */ | |
84 | else if (sqlca.sqlerrd[2] != 1 || id != cl->users_id) | |
85 | return MR_PERM; | |
86 | else | |
87 | return MR_SUCCESS; | |
73cf66ba | 88 | } |
89 | ||
90 | ||
f659afb2 | 91 | /* access_spob - check access for set_pobox */ |
92 | ||
93 | int access_spob(struct query *q, char *argv[], client *cl) | |
94 | { | |
51e578b6 | 95 | EXEC SQL BEGIN DECLARE SECTION; |
96 | int id; | |
97 | EXEC SQL END DECLARE SECTION; | |
98 | ||
99 | if (!strcmp(argv[1], "IMAP")) | |
100 | { | |
101 | EXEC SQL SELECT owner INTO :id FROM filesys f | |
102 | WHERE f.label = :argv[2] AND f.type = 'IMAP' AND | |
103 | f.lockertype = 'USER'; | |
104 | if (cl->users_id != id) | |
105 | return MR_PERM; | |
106 | } | |
107 | if (cl->users_id != *(int *)argv[0]) | |
f659afb2 | 108 | return MR_PERM; |
109 | else | |
110 | return MR_SUCCESS; | |
111 | } | |
112 | ||
73cf66ba | 113 | |
114 | /* access_list - check access for most list operations | |
115 | * | |
116 | * Inputs: argv[0] - list_id | |
117 | * q - query name | |
118 | * argv[2] - member ID (only for queries "amtl" and "dmfl") | |
e688520a | 119 | * argv[7] - group ID (only for query "ulis") |
73cf66ba | 120 | * cl - client name |
121 | * | |
122 | * - check that client is a member of the access control list | |
123 | * - OR, if the query is add_member_to_list or delete_member_from_list | |
124 | * and the list is public, allow access if client = member | |
125 | */ | |
126 | ||
5eaef520 | 127 | int access_list(struct query *q, char *argv[], client *cl) |
73cf66ba | 128 | { |
5eaef520 | 129 | EXEC SQL BEGIN DECLARE SECTION; |
40b33762 | 130 | int list_id, acl_id, flags, gid, users_id, member_id, member_acl_id; |
59c3208b | 131 | int memacl_id; |
e688520a | 132 | char acl_type[LIST_ACL_TYPE_SIZE], name[LIST_NAME_SIZE], *newname; |
59c3208b | 133 | char member_acl_type[LIST_ACL_TYPE_SIZE], memacl_type[LIST_ACL_TYPE_SIZE]; |
5eaef520 | 134 | EXEC SQL END DECLARE SECTION; |
135 | int status; | |
136 | ||
137 | list_id = *(int *)argv[0]; | |
40b33762 | 138 | member_id = *(int *)argv[2]; |
59c3208b | 139 | EXEC SQL SELECT acl_id, acl_type, memacl_id, memacl_type, |
140 | gid, publicflg, name | |
141 | INTO :acl_id, :acl_type, :memacl_id, :memacl_type, | |
142 | :gid, :flags, :name | |
5eaef520 | 143 | FROM list |
144 | WHERE list_id = :list_id; | |
145 | ||
146 | if (sqlca.sqlerrd[2] != 1) | |
147 | return MR_INTERNAL; | |
148 | ||
59c3208b | 149 | /* if update_list, don't allow them to change the GID or rename to a |
150 | username other than their own */ | |
151 | if (!strcmp("ulis", q->shortname)) | |
5eaef520 | 152 | { |
153 | if (!strcmp(argv[7], UNIQUE_GID)) | |
154 | { | |
155 | if (gid != -1) | |
156 | return MR_PERM; | |
157 | } | |
158 | else | |
159 | { | |
160 | if (gid != atoi(argv[7])) | |
161 | return MR_PERM; | |
162 | } | |
5c96d2cd | 163 | |
d83ee5a2 | 164 | newname = argv[1]; |
5c96d2cd | 165 | |
166 | if (!strcmp("ulis", q->shortname)) | |
167 | { | |
168 | /* Check that it doesn't conflict with the Grouper namespace. */ | |
169 | if (strlen(newname) > 4 && isdigit(newname[2]) && | |
170 | isdigit(newname[3]) && newname[4] == '-') | |
171 | { | |
172 | if (!strncasecmp(newname, "fa", 2) || | |
173 | !strncasecmp(newname, "sp", 2) || | |
174 | !strncasecmp(newname, "su", 2) || | |
175 | !strncasecmp(newname, "ja", 2)) | |
176 | return MR_RESERVED; | |
177 | } | |
178 | ||
179 | /* Don't let anyone take owner-foo list names. They interact | |
180 | * weirdly with the aliases automatically generated by | |
181 | * mailhub.gen. | |
182 | */ | |
183 | if (!strncasecmp(newname, "owner-", 6)) | |
184 | return MR_RESERVED; | |
185 | } | |
186 | ||
d83ee5a2 | 187 | EXEC SQL SELECT users_id INTO :users_id FROM users |
5eaef520 | 188 | WHERE login = :newname; |
17f090e1 | 189 | if ((sqlca.sqlcode != SQL_NO_MATCH) && strcmp(strtrim(name), newname) && |
190 | (users_id != cl->users_id)) | |
5eaef520 | 191 | return MR_PERM; |
73cf66ba | 192 | } |
193 | ||
59c3208b | 194 | /* check for client in access control list and return success right |
195 | * away if it's there. */ | |
196 | if (find_member(acl_type, acl_id, cl)) | |
197 | return MR_SUCCESS; | |
198 | ||
199 | /* If not amtl, atml, or dmfl, we lose. */ | |
200 | if (strcmp(q->shortname, "amtl") && strcmp(q->shortname, "atml") && | |
e3fbe284 | 201 | strcmp(q->shortname, "dmfl") && strcmp(q->shortname, "tmol")) |
5eaef520 | 202 | return MR_PERM; |
73cf66ba | 203 | |
59c3208b | 204 | if (find_member(memacl_type, memacl_id, cl)) |
205 | return MR_SUCCESS; | |
206 | ||
207 | if (flags || q->type == DELETE) | |
208 | { | |
209 | if (!strcmp("USER", argv[1]) && *(int *)argv[2] == cl->users_id) | |
210 | return MR_SUCCESS; | |
211 | if (!strcmp("KERBEROS", argv[1]) && *(int *)argv[2] == -cl->client_id) | |
212 | return MR_SUCCESS; | |
213 | if (!strcmp("LIST", argv[1]) && !strcmp("dmfl", q->shortname)) | |
214 | { | |
215 | EXEC SQL SELECT acl_id, acl_type INTO :member_acl_id, | |
216 | :member_acl_type | |
217 | FROM list | |
218 | WHERE list_id = :member_id; | |
219 | ||
220 | if (find_member(member_acl_type, member_acl_id, cl)) | |
221 | return MR_SUCCESS; | |
222 | } | |
223 | } | |
224 | ||
225 | /* Otherwise fail. */ | |
226 | return MR_PERM; | |
73cf66ba | 227 | } |
228 | ||
229 | ||
230 | /* access_visible_list - allow access to list only if it is not hidden, | |
231 | * or if the client is on the ACL | |
232 | * | |
233 | * Inputs: argv[0] - list_id | |
234 | * cl - client identifier | |
235 | */ | |
236 | ||
5eaef520 | 237 | int access_visible_list(struct query *q, char *argv[], client *cl) |
73cf66ba | 238 | { |
5eaef520 | 239 | EXEC SQL BEGIN DECLARE SECTION; |
59c3208b | 240 | int list_id, acl_id, memacl_id, flags ; |
241 | char acl_type[LIST_ACL_TYPE_SIZE], memacl_type[LIST_ACL_TYPE_SIZE]; | |
5eaef520 | 242 | EXEC SQL END DECLARE SECTION; |
243 | int status; | |
244 | ||
245 | list_id = *(int *)argv[0]; | |
59c3208b | 246 | EXEC SQL SELECT hidden, acl_id, acl_type, memacl_id, memacl_type |
247 | INTO :flags, :acl_id, :acl_type, :memacl_id, :memacl_type | |
5eaef520 | 248 | FROM list |
249 | WHERE list_id = :list_id; | |
250 | if (sqlca.sqlerrd[2] != 1) | |
251 | return MR_INTERNAL; | |
252 | if (!flags) | |
253 | return MR_SUCCESS; | |
254 | ||
255 | /* check for client in access control list */ | |
256 | status = find_member(acl_type, acl_id, cl); | |
257 | if (!status) | |
59c3208b | 258 | { |
259 | status = find_member(memacl_type, memacl_id, cl); | |
260 | if (!status) | |
261 | return MR_PERM; | |
262 | } | |
5eaef520 | 263 | return MR_SUCCESS; |
73cf66ba | 264 | } |
265 | ||
266 | ||
267 | /* access_vis_list_by_name - allow access to list only if it is not hidden, | |
268 | * or if the client is on the ACL | |
269 | * | |
270 | * Inputs: argv[0] - list name | |
271 | * cl - client identifier | |
272 | */ | |
273 | ||
5eaef520 | 274 | int access_vis_list_by_name(struct query *q, char *argv[], client *cl) |
73cf66ba | 275 | { |
5eaef520 | 276 | EXEC SQL BEGIN DECLARE SECTION; |
2affa9d4 | 277 | int acl_id, memacl_id, flags, rowcount, list_id; |
59c3208b | 278 | char acl_type[LIST_ACL_TYPE_SIZE], memacl_type[LIST_ACL_TYPE_SIZE]; |
279 | char *listname; | |
5eaef520 | 280 | EXEC SQL END DECLARE SECTION; |
281 | int status; | |
282 | ||
283 | listname = argv[0]; | |
2affa9d4 | 284 | EXEC SQL SELECT hidden, acl_id, acl_type, memacl_id, memacl_type, list_id |
285 | INTO :flags, :acl_id, :acl_type, :memacl_id, :memacl_type, :list_id | |
59c3208b | 286 | FROM list |
287 | WHERE name = :listname; | |
5eaef520 | 288 | |
289 | rowcount = sqlca.sqlerrd[2]; | |
290 | if (rowcount > 1) | |
291 | return MR_WILDCARD; | |
292 | if (rowcount == 0) | |
293 | return MR_NO_MATCH; | |
294 | if (!flags) | |
295 | return MR_SUCCESS; | |
296 | ||
2affa9d4 | 297 | /* If the user is a member of the acl, memacl, or the list itself, |
298 | * accept them. | |
299 | */ | |
5eaef520 | 300 | status = find_member(acl_type, acl_id, cl); |
301 | if (!status) | |
2affa9d4 | 302 | status = find_member(memacl_type, memacl_id, cl); |
303 | if (!status) | |
304 | status = find_member("LIST", list_id, cl); | |
305 | if (!status) | |
306 | return MR_PERM; | |
307 | ||
5eaef520 | 308 | return MR_SUCCESS; |
73cf66ba | 309 | } |
310 | ||
311 | ||
312 | /* access_member - allow user to access member of type "USER" and name matches | |
f3c08a60 | 313 | * username, or to access member of type "KERBEROS" and the principal matches |
314 | * the user, or to access member of type "LIST" and list is one that user is | |
d1d964a0 | 315 | * on the acl of, or the list is visible. Allow anyone to look up list |
316 | * memberships of MACHINEs. | |
73cf66ba | 317 | */ |
318 | ||
5eaef520 | 319 | int access_member(struct query *q, char *argv[], client *cl) |
73cf66ba | 320 | { |
5eaef520 | 321 | if (!strcmp(argv[0], "LIST") || !strcmp(argv[0], "RLIST")) |
322 | return access_visible_list(q, &argv[1], cl); | |
73cf66ba | 323 | |
5eaef520 | 324 | if (!strcmp(argv[0], "USER") || !strcmp(argv[0], "RUSER")) |
325 | { | |
326 | if (cl->users_id == *(int *)argv[1]) | |
327 | return MR_SUCCESS; | |
73cf66ba | 328 | } |
329 | ||
5eaef520 | 330 | if (!strcmp(argv[0], "KERBEROS") || !strcmp(argv[0], "RKERBEROS")) |
331 | { | |
332 | if (cl->client_id == -*(int *)argv[1]) | |
333 | return MR_SUCCESS; | |
73cf66ba | 334 | } |
335 | ||
d1d964a0 | 336 | if (!strcmp(argv[0], "MACHINE") || !strcmp(argv[0], "RMACHINE")) |
337 | return MR_SUCCESS; | |
338 | ||
5eaef520 | 339 | return MR_PERM; |
73cf66ba | 340 | } |
341 | ||
342 | ||
343 | /* access_qgli - special access routine for Qualified_get_lists. Allows | |
344 | * access iff argv[0] == "TRUE" and argv[2] == "FALSE". | |
345 | */ | |
346 | ||
5eaef520 | 347 | int access_qgli(struct query *q, char *argv[], client *cl) |
73cf66ba | 348 | { |
5eaef520 | 349 | if (!strcmp(argv[0], "TRUE") && !strcmp(argv[2], "FALSE")) |
350 | return MR_SUCCESS; | |
351 | return MR_PERM; | |
73cf66ba | 352 | } |
353 | ||
354 | ||
355 | /* access_service - allow access if user is on ACL of service. Don't | |
356 | * allow access if a wildcard is used. | |
357 | */ | |
358 | ||
5eaef520 | 359 | int access_service(struct query *q, char *argv[], client *cl) |
73cf66ba | 360 | { |
5eaef520 | 361 | EXEC SQL BEGIN DECLARE SECTION; |
362 | int acl_id; | |
e688520a | 363 | char *name, acl_type[LIST_ACL_TYPE_SIZE]; |
5eaef520 | 364 | EXEC SQL END DECLARE SECTION; |
365 | int status; | |
366 | char *c; | |
367 | ||
368 | name = argv[0]; | |
369 | for (c = name; *c; c++) | |
370 | { | |
371 | if (islower(*c)) | |
372 | *c = toupper(*c); | |
373 | } | |
374 | EXEC SQL SELECT acl_id, acl_type INTO :acl_id, :acl_type FROM servers | |
375 | WHERE name = :name; | |
376 | if (sqlca.sqlerrd[2] > 1) | |
377 | return MR_PERM; | |
378 | ||
379 | /* check for client in access control list */ | |
380 | status = find_member(acl_type, acl_id, cl); | |
381 | if (!status) | |
382 | return MR_PERM; | |
383 | ||
384 | return MR_SUCCESS; | |
73cf66ba | 385 | } |
386 | ||
387 | ||
388 | /* access_filesys - verify that client is owner or on owners list of filesystem | |
389 | * named by argv[0] | |
390 | */ | |
391 | ||
5eaef520 | 392 | int access_filesys(struct query *q, char *argv[], client *cl) |
73cf66ba | 393 | { |
5eaef520 | 394 | EXEC SQL BEGIN DECLARE SECTION; |
395 | int users_id, list_id; | |
396 | char *name; | |
397 | EXEC SQL END DECLARE SECTION; | |
398 | int status; | |
399 | ||
400 | name = argv[0]; | |
401 | EXEC SQL SELECT owner, owners INTO :users_id, :list_id FROM filesys | |
402 | WHERE label = :name; | |
403 | ||
404 | if (sqlca.sqlerrd[2] != 1) | |
405 | return MR_PERM; | |
406 | if (users_id == cl->users_id) | |
407 | return MR_SUCCESS; | |
408 | status = find_member("LIST", list_id, cl); | |
409 | if (status) | |
410 | return MR_SUCCESS; | |
411 | else | |
412 | return MR_PERM; | |
73cf66ba | 413 | } |
414 | ||
1beb5e23 | 415 | |
416 | /* access_host - successful if owner of host, or subnet containing host | |
417 | */ | |
418 | ||
5eaef520 | 419 | int access_host(struct query *q, char *argv[], client *cl) |
1beb5e23 | 420 | { |
5eaef520 | 421 | EXEC SQL BEGIN DECLARE SECTION; |
4f6b1a05 | 422 | int mid, sid, id, subnet_status; |
e688520a | 423 | char mtype[MACHINE_OWNER_TYPE_SIZE], stype[SUBNET_OWNER_TYPE_SIZE]; |
4f6b1a05 | 424 | char *account_number; |
5eaef520 | 425 | EXEC SQL END DECLARE SECTION; |
e4ae0190 | 426 | int status, idx; |
427 | ||
428 | if (q->version < 6) | |
429 | idx = 0; | |
4f6b1a05 | 430 | else if (q->version >= 6 && q->version < 8) |
e4ae0190 | 431 | idx = 1; |
4f6b1a05 | 432 | else |
433 | idx = 2; | |
434 | ||
17f090e1 | 435 | if (q->type == RETRIEVE) |
436 | { | |
437 | if (strcmp(argv[0], "*") || strcmp(argv[1], "*") || | |
438 | strcmp(argv[2], "*") || strcmp(argv[3], "*")) | |
439 | return MR_SUCCESS; | |
440 | else | |
441 | return MR_PERM; | |
442 | } | |
9e252e6f | 443 | |
5eaef520 | 444 | if (q->type == APPEND) |
445 | { | |
17f090e1 | 446 | /* Non-query owner must set use to zero */ |
e4ae0190 | 447 | if (atoi(argv[6 + idx]) != 0) |
17f090e1 | 448 | return MR_PERM; |
449 | ||
9e252e6f | 450 | /* ... and start the hostname with a letter */ |
451 | if (isdigit(argv[0][0])) | |
452 | return MR_BAD_CHAR; | |
453 | ||
e4ae0190 | 454 | id = *(int *)argv[8 + idx]; |
4f6b1a05 | 455 | EXEC SQL SELECT s.owner_type, s.owner_id, s.status |
456 | INTO :stype, :sid, :subnet_status FROM subnet s | |
5eaef520 | 457 | WHERE s.snet_id = :id; |
458 | mid = 0; | |
17f090e1 | 459 | |
4f6b1a05 | 460 | /* Non query owner must provide valid billing information. */ |
461 | if (q->version >= 8) | |
462 | { | |
463 | if (subnet_status == SNET_STATUS_BILLABLE) | |
464 | { | |
465 | account_number = argv[7]; | |
466 | EXEC SQL SELECT account_number FROM accountnumbers | |
467 | WHERE account_number = :account_number; | |
468 | if (sqlca.sqlcode == SQL_NO_MATCH) | |
469 | return MR_ACCOUNT_NUMBER; | |
470 | } | |
471 | } | |
472 | ||
17f090e1 | 473 | if (find_member(stype, sid, cl)) |
5eaef520 | 474 | return MR_SUCCESS; |
475 | else | |
476 | return MR_PERM; | |
477 | } | |
17f090e1 | 478 | else /* q-type == UPDATE */ |
5eaef520 | 479 | { |
17f090e1 | 480 | EXEC SQL BEGIN DECLARE SECTION; |
481 | int status, acomment, use, ocomment, snid; | |
e688520a | 482 | char contact[MACHINE_CONTACT_SIZE], address[MACHINE_ADDRESS_SIZE]; |
9e252e6f | 483 | char name[MACHINE_NAME_SIZE]; |
e4ae0190 | 484 | char billing_contact[MACHINE_BILLING_CONTACT_SIZE]; |
17f090e1 | 485 | EXEC SQL END DECLARE SECTION; |
486 | ||
5eaef520 | 487 | id = *(int *)argv[0]; |
e4ae0190 | 488 | EXEC SQL SELECT m.name, m.use, m.contact, m.billing_contact, m.status, |
489 | m.address, m.owner_type, m.owner_id, m.acomment, m.ocomment, m.snet_id, | |
4f6b1a05 | 490 | s.owner_type, s.owner_id, s.status INTO :name, :use, :contact, |
491 | :billing_contact, :status, :address, :mtype, :mid, :acomment, | |
492 | :ocomment, :snid, :stype, :sid, :subnet_status | |
17f090e1 | 493 | FROM machine m, subnet s |
494 | WHERE m.mach_id = :id AND s.snet_id = m.snet_id; | |
495 | if (dbms_errno) | |
496 | return mr_errcode; | |
497 | ||
4f6b1a05 | 498 | /* Non query owner must provide valid billing information. */ |
499 | if (q->version >= 8) | |
500 | { | |
c862fa4e | 501 | if ((subnet_status == SNET_STATUS_BILLABLE) && |
502 | (atoi(argv[10]) != 3)) | |
4f6b1a05 | 503 | { |
504 | account_number = argv[8]; | |
505 | EXEC SQL SELECT account_number FROM accountnumbers | |
506 | WHERE account_number = :account_number; | |
507 | if (sqlca.sqlcode == SQL_NO_MATCH) | |
508 | return MR_ACCOUNT_NUMBER; | |
509 | } | |
510 | } | |
511 | ||
17f090e1 | 512 | /* non-query-owner cannot change use or ocomment */ |
e4ae0190 | 513 | if ((use != atoi(argv[7 + idx])) || (ocomment != *(int *)argv[14 + idx])) |
17f090e1 | 514 | return MR_PERM; |
515 | ||
9e252e6f | 516 | /* or rename to start with digit */ |
517 | if (isdigit(argv[1][0]) && strcmp(strtrim(name), argv[1])) | |
518 | return MR_BAD_CHAR; | |
519 | ||
17f090e1 | 520 | if (!find_member(stype, sid, cl)) |
521 | { | |
522 | if (find_member(mtype, mid, cl)) | |
523 | { | |
524 | /* host owner also cannot change contact, status, address, | |
525 | owner, or acomment */ | |
7617c632 | 526 | if (strcmp(argv[6], strtrim(contact)) || |
e4ae0190 | 527 | (status != atoi(argv[8 + idx])) || |
528 | strcmp(argv[10 + idx], strtrim(address)) || | |
529 | strcmp(argv[11 + idx], strtrim(mtype)) || | |
530 | (mid != *(int *)argv[12 + idx]) || | |
531 | (acomment != *(int *)argv[13 + idx])) | |
17f090e1 | 532 | return MR_PERM; |
e4ae0190 | 533 | /* Billing contact field didn't appear until version 6 */ |
534 | if (q->version >= 6) | |
7617c632 | 535 | if (strcmp(argv[7], strtrim(billing_contact))) |
e4ae0190 | 536 | return MR_PERM; |
17f090e1 | 537 | } |
538 | else | |
539 | return MR_PERM; | |
540 | } | |
541 | ||
542 | /* If moving to a new subnet, make sure user is on acl there */ | |
e4ae0190 | 543 | id = *(int *)argv[9 + idx]; |
17f090e1 | 544 | if (id != snid) |
545 | { | |
546 | EXEC SQL SELECT owner_type, owner_id INTO :stype, :sid | |
547 | FROM subnet WHERE snet_id=:id; | |
548 | if (!find_member(stype, sid, cl)) | |
549 | return MR_PERM; | |
550 | } | |
5eaef520 | 551 | |
5eaef520 | 552 | return MR_SUCCESS; |
1beb5e23 | 553 | } |
1beb5e23 | 554 | } |
555 | ||
556 | ||
557 | /* access_ahal - check for adding a host alias. | |
558 | * successful if host has less then 2 aliases and (client is owner of | |
559 | * host or subnet). | |
560 | * If deleting an alias, any owner will do. | |
561 | */ | |
562 | ||
5eaef520 | 563 | int access_ahal(struct query *q, char *argv[], client *cl) |
1beb5e23 | 564 | { |
5eaef520 | 565 | EXEC SQL BEGIN DECLARE SECTION; |
566 | int cnt, id, mid, sid; | |
e688520a | 567 | char mtype[MACHINE_OWNER_TYPE_SIZE], stype[SUBNET_OWNER_TYPE_SIZE]; |
5eaef520 | 568 | EXEC SQL END DECLARE SECTION; |
569 | int status; | |
570 | ||
571 | if (q->type == RETRIEVE) | |
572 | return MR_SUCCESS; | |
573 | ||
574 | id = *(int *)argv[1]; | |
575 | ||
9e252e6f | 576 | if (q->type == APPEND && isdigit(argv[0][0])) |
577 | return MR_BAD_CHAR; | |
578 | ||
5eaef520 | 579 | EXEC SQL SELECT count(name) INTO :cnt from hostalias WHERE mach_id = :id; |
580 | if (dbms_errno) | |
581 | return mr_errcode; | |
582 | /* if the type is APPEND, this is ahal and we need to make sure there | |
583 | * will be no more than 2 aliases. If it's not, it must be dhal and | |
584 | * any owner will do. | |
585 | */ | |
586 | if (q->type == APPEND && cnt >= 2) | |
587 | return MR_PERM; | |
588 | EXEC SQL SELECT m.owner_type, m.owner_id, s.owner_type, s.owner_id | |
589 | INTO :mtype, :mid, :stype, :sid FROM machine m, subnet s | |
590 | WHERE m.mach_id = :id and s.snet_id = m.snet_id; | |
591 | status = find_member(mtype, mid, cl); | |
592 | if (status) | |
593 | return MR_SUCCESS; | |
594 | status = find_member(stype, sid, cl); | |
595 | if (status) | |
596 | return MR_SUCCESS; | |
597 | else | |
598 | return MR_PERM; | |
1beb5e23 | 599 | } |
7cf83f0f | 600 | |
601 | ||
7cf83f0f | 602 | /* access_snt - check for retrieving network structure |
603 | */ | |
604 | ||
5eaef520 | 605 | int access_snt(struct query *q, char *argv[], client *cl) |
7cf83f0f | 606 | { |
5eaef520 | 607 | if (q->type == RETRIEVE) |
608 | return MR_SUCCESS; | |
7cf83f0f | 609 | |
5eaef520 | 610 | return MR_PERM; |
7cf83f0f | 611 | } |
1a9a0a59 | 612 | |
613 | ||
614 | /* access_printer */ | |
615 | int access_printer(struct query *q, char *argv[], client *cl) | |
616 | { | |
617 | EXEC SQL BEGIN DECLARE SECTION; | |
618 | char type[PRINTSERVERS_OWNER_TYPE_SIZE]; | |
619 | int id, mach_id; | |
620 | EXEC SQL END DECLARE SECTION; | |
621 | int status; | |
622 | ||
623 | mach_id = *(int *)argv[PRN_RM]; | |
624 | EXEC SQL SELECT owner_type, owner_id INTO :type, :id | |
625 | FROM printservers WHERE mach_id = :mach_id; | |
626 | if (sqlca.sqlcode) | |
627 | return MR_PERM; | |
628 | ||
629 | status = find_member(type, id, cl); | |
630 | if (status) | |
631 | return MR_SUCCESS; | |
632 | else | |
633 | return MR_PERM; | |
634 | } | |
d7ddc011 | 635 | |
636 | /* access_zephyr */ | |
637 | int access_zephyr(struct query *q, char *argv[], client *cl) | |
638 | { | |
639 | EXEC SQL BEGIN DECLARE SECTION; | |
640 | char type[ZEPHYR_OWNER_TYPE_SIZE]; | |
641 | char *class; | |
642 | int id; | |
643 | EXEC SQL END DECLARE SECTION; | |
644 | int status; | |
645 | ||
646 | class = argv[ZA_CLASS]; | |
647 | EXEC SQL SELECT owner_type, owner_id INTO :type, :id | |
648 | FROM zephyr WHERE class = :class; | |
649 | if (sqlca.sqlcode) | |
650 | return MR_PERM; | |
651 | ||
652 | status = find_member(type, id, cl); | |
653 | if (status) | |
654 | return MR_SUCCESS; | |
655 | else | |
656 | return MR_PERM; | |
657 | } | |
658 | ||
2fb668b0 | 659 | /* access_container - check access for most container operations |
660 | * | |
661 | * Inputs: argv[0] - cnt_id | |
662 | * q - query name | |
663 | * cl - client name | |
664 | * | |
665 | * - check if that client is a member of the access control list | |
666 | * - OR, if the query is add_machine_to_container or delete_machine_from_container | |
667 | * check if the client is a memeber of the mem_acl list | |
668 | * - if the query is update_container and the container is to be renamed and | |
669 | * it is a top-level container, only priviledged users can do it | |
670 | */ | |
671 | ||
672 | int access_container(struct query *q, char *argv[], client *cl) | |
673 | { | |
674 | EXEC SQL BEGIN DECLARE SECTION; | |
73155abd | 675 | int cnt_id, acl_id, memacl_id, mach_id, machine_owner_id, flag; |
2fb668b0 | 676 | char acl_type[CONTAINERS_ACL_TYPE_SIZE], memacl_type[CONTAINERS_ACL_TYPE_SIZE]; |
677 | char name[CONTAINERS_NAME_SIZE], *newname; | |
73155abd | 678 | char machine_owner_type[MACHINE_OWNER_TYPE_SIZE]; |
2fb668b0 | 679 | EXEC SQL END DECLARE SECTION; |
680 | int status; | |
681 | ||
682 | cnt_id = *(int *)argv[0]; | |
683 | ||
684 | /* if amcn or dmcn, container id is the second argument */ | |
685 | if (strcmp(q->shortname, "amcn") == 0 || strcmp(q->shortname, "dmcn") == 0) | |
73155abd | 686 | { |
687 | mach_id = *(int *)argv[0]; | |
2fb668b0 | 688 | cnt_id = *(int *)argv[1]; |
73155abd | 689 | } |
2fb668b0 | 690 | |
73155abd | 691 | EXEC SQL SELECT acl_id, acl_type, memacl_id, memacl_type, name, publicflg |
692 | INTO :acl_id, :acl_type, :memacl_id, :memacl_type, :name, :flag | |
2fb668b0 | 693 | FROM containers |
694 | WHERE cnt_id = :cnt_id; | |
695 | ||
696 | if (sqlca.sqlerrd[2] != 1) | |
697 | return MR_INTERNAL; | |
698 | ||
699 | /* trim off the trailing spaces */ | |
700 | strcpy(name, strtrim(name)); | |
701 | ||
702 | /* if the query is update_container and the containers is to be renamed | |
703 | * and it is a top-level container, only dbadmin can do it */ | |
704 | if (!strcmp(q->shortname, "ucon")) | |
705 | { | |
706 | newname = argv[1]; | |
707 | if (strcmp(name, newname) && strchr(name, '/') == NULL) | |
708 | return MR_PERM; | |
709 | } | |
710 | ||
711 | /* check for client in access control list and return success right | |
712 | * away if it's there. */ | |
713 | if (find_member(acl_type, acl_id, cl)) | |
714 | return MR_SUCCESS; | |
715 | ||
716 | /* If not amcn, dmcn, we lose. */ | |
717 | if (strcmp(q->shortname, "amcn") && strcmp(q->shortname, "dmcn")) | |
718 | return MR_PERM; | |
719 | ||
720 | if (find_member(memacl_type, memacl_id, cl)) | |
721 | return MR_SUCCESS; | |
722 | ||
73155abd | 723 | /* if the container is public or the query is delete, grant access if client |
724 | * is on owner list */ | |
725 | if (flag || q->type == DELETE) | |
726 | { | |
727 | EXEC SQL SELECT owner_type, owner_id INTO :machine_owner_type, | |
728 | :machine_owner_id | |
729 | FROM machine | |
730 | WHERE mach_id = :mach_id; | |
731 | ||
732 | if (sqlca.sqlerrd[2] == 1 && strcmp("NONE", machine_owner_type) && | |
733 | find_member(machine_owner_type, machine_owner_id, cl)) | |
734 | return MR_SUCCESS; | |
735 | } | |
2fb668b0 | 736 | /* Otherwise fail. */ |
737 | return MR_PERM; | |
738 | } |