]> andersk Git - moira.git/blame - server/qsupport.pc
add svrinstall target that only installs server binaries
[moira.git] / server / qsupport.pc
CommitLineData
7ac48069 1/* $Id$
b070f8a1 2 *
7ac48069 3 * Special query routines
b070f8a1 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>.
b070f8a1 8 */
9
b070f8a1 10#include <mit-copyright.h>
b070f8a1 11#include "mr_server.h"
03c05291 12#include "query.h"
7ac48069 13#include "qrtn.h"
14
b070f8a1 15#include <ctype.h>
7ac48069 16#include <stdlib.h>
03c05291 17#include <string.h>
7ac48069 18
5d677c81 19EXEC SQL INCLUDE sqlca;
7ac48069 20
21RCSID("$Header$");
b070f8a1 22
03c05291 23extern char *whoami, *table_name[];
24extern int dbms_errno, mr_errcode;
b070f8a1 25
0fc7ab46 26EXEC SQL BEGIN DECLARE SECTION;
45bf7573 27extern char stmt_buf[];
0fc7ab46 28EXEC SQL END DECLARE SECTION;
5d677c81 29
03c05291 30EXEC SQL WHENEVER SQLERROR DO dbmserr();
31
7ac48069 32int get_ace_internal(char *atypex, int aid,
33 int (*action)(int, char *[], void *), void *actarg);
03c05291 34int gmol_internal(struct query *q, char *argv[], client *cl,
7ac48069 35 int (*action)(int, char *[], void *), void *actarg,
36 int flag);
37int qualified_get(struct query *q, char *argv[],
38 int (*action)(int, char *[], void *), void *actarg,
03c05291 39 char *start, char *range, char *field, char *flags[]);
453b99fe 40
0fc7ab46 41
0659551f 42/* set_pobox - this does all of the real work.
43 * argv = user_id, type, box
44 * if type is POP, then box should be a machine, and its ID should be put in
45 * pop_id. If type is SMTP, then box should be a string and its ID should
46 * be put in box_id. If type is NONE, then box doesn't matter.
0fc7ab46 47 */
b070f8a1 48
03c05291 49
5eaef520 50int set_pobox(struct query *q, char **argv, client *cl)
5d677c81 51{
5eaef520 52 EXEC SQL BEGIN DECLARE SECTION;
53 int user, id;
e688520a 54 char *box, potype[USERS_POTYPE_SIZE];
5eaef520 55 EXEC SQL END DECLARE SECTION;
56 int status;
57
58 box = argv[2];
59 user = *(int *)argv[0];
60
61 EXEC SQL SELECT pop_id, potype INTO :id, :potype FROM users
62 WHERE users_id = :user;
63 if (dbms_errno)
64 return mr_errcode;
65 if (!strcmp(strtrim(potype), "POP"))
66 set_pop_usage(id, -1);
67
68 if (!strcmp(argv[1], "POP"))
69 {
70 status = name_to_id(box, MACHINE_TABLE, &id);
71 if (status == MR_NO_MATCH)
72 return MR_MACHINE;
73 else if (status)
74 return status;
75 EXEC SQL UPDATE users SET potype = 'POP', pop_id = :id
76 WHERE users_id = :user;
77 set_pop_usage(id, 1);
78 }
79 else if (!strcmp(argv[1], "SMTP"))
80 {
81 if (strchr(box, '/') || strchr(box, '|'))
82 return MR_BAD_CHAR;
83 status = name_to_id(box, STRINGS_TABLE, &id);
84 if (status == MR_NO_MATCH)
85 id = add_string(box);
86 else if (status)
87 return status;
88 EXEC SQL UPDATE users SET potype = 'SMTP', box_id = :id
89 WHERE users_id = :user;
90 }
91 else /* argv[1] == "NONE" */
92 {
93 EXEC SQL UPDATE users SET potype = 'NONE'
94 WHERE users_id = :user;
b070f8a1 95 }
96
5eaef520 97 set_pobox_modtime(q, argv, cl);
98 EXEC SQL UPDATE tblstats SET updates = updates + 1, modtime = SYSDATE
99 WHERE table_name = 'users';
100 if (dbms_errno)
101 return mr_errcode;
102 return MR_SUCCESS;
5d677c81 103}
b070f8a1 104
0659551f 105/* Add_member_to_list: do list flattening as we go! MAXLISTDEPTH is
106 * how many different ancestors a member is allowed to have.
b070f8a1 107 */
108
0659551f 109#define MAXLISTDEPTH 1024
b070f8a1 110
5eaef520 111int add_member_to_list(struct query *q, char **argv, client *cl)
5d677c81 112{
5eaef520 113 EXEC SQL BEGIN DECLARE SECTION;
114 int id, lid, mid, error, who, ref, rowcnt;
e688520a 115 char *mtype, dtype[IMEMBERS_MEMBER_TYPE_SIZE], *entity;
5eaef520 116 EXEC SQL END DECLARE SECTION;
117 int ancestors[MAXLISTDEPTH], aref[MAXLISTDEPTH], acount, a;
118 int descendants[MAXLISTDEPTH], dref[MAXLISTDEPTH], dcount, d;
119 int status;
120 char *dtypes[MAXLISTDEPTH];
121 char *iargv[3], *buf;
122
123 lid = *(int *)argv[0];
124 mtype = argv[1];
125 mid = *(int *)argv[2];
a37b0b99 126
127 if (acl_access_check(lid, cl))
128 return MR_PERM;
129
5eaef520 130 /* if the member is already a direct member of the list, punt */
131 EXEC SQL SELECT COUNT(list_id) INTO :rowcnt FROM imembers
132 WHERE list_id = :lid AND member_id = :mid
133 AND member_type = :mtype AND direct = 1;
134 if (rowcnt > 0)
135 return MR_EXISTS;
136 if (!strcasecmp(mtype, "STRING"))
137 {
138 buf = malloc(0);
139 status = id_to_name(mid, STRINGS_TABLE, &buf);
140 if (status)
141 return status;
142 if (strchr(buf, '/') || strchr(buf, '|'))
143 {
144 free(buf);
145 return MR_BAD_CHAR;
0659551f 146 }
5eaef520 147 free(buf);
0659551f 148 }
b070f8a1 149
5eaef520 150 ancestors[0] = lid;
151 aref[0] = 1;
152 acount = 1;
153 EXEC SQL DECLARE csr103 CURSOR FOR
154 SELECT list_id, ref_count FROM imembers
155 WHERE member_id = :lid AND member_type = 'LIST';
156 if (dbms_errno)
157 return mr_errcode;
158 EXEC SQL OPEN csr103;
159 if (dbms_errno)
160 return mr_errcode;
161 while (1)
162 {
163 EXEC SQL FETCH csr103 INTO :id, :ref;
164 if (sqlca.sqlcode)
165 break;
166 aref[acount] = ref;
167 ancestors[acount++] = id;
168 if (acount >= MAXLISTDEPTH)
169 break;
0659551f 170 }
5eaef520 171 EXEC SQL CLOSE csr103;
172 if (dbms_errno)
173 return mr_errcode;
174 if (acount >= MAXLISTDEPTH)
175 return MR_INTERNAL;
176 descendants[0] = mid;
177 dtypes[0] = mtype;
178 dref[0] = 1;
179 dcount = 1;
180 error = 0;
181 if (!strcmp(mtype, "LIST"))
182 {
183 EXEC SQL DECLARE csr104 CURSOR FOR
184 SELECT member_id, member_type, ref_count
185 FROM imembers
186 WHERE list_id = :mid;
187 if (dbms_errno)
188 return mr_errcode;
189 EXEC SQL OPEN csr104;
190 if (dbms_errno)
191 return mr_errcode;
192 while (1)
193 {
194 EXEC SQL FETCH csr104 INTO :id, :dtype, :ref;
195 if (sqlca.sqlcode)
196 break;
197 switch (dtype[0])
198 {
0659551f 199 case 'L':
5eaef520 200 dtypes[dcount] = "LIST";
201 break;
0659551f 202 case 'U':
5eaef520 203 dtypes[dcount] = "USER";
204 break;
0659551f 205 case 'S':
5eaef520 206 dtypes[dcount] = "STRING";
207 break;
0659551f 208 case 'K':
5eaef520 209 dtypes[dcount] = "KERBEROS";
210 break;
0659551f 211 default:
5eaef520 212 error++;
213 break;
0659551f 214 }
5eaef520 215 dref[dcount] = ref;
216 descendants[dcount++] = id;
217 if (dcount >= MAXLISTDEPTH)
218 {
219 error++;
220 break;
0659551f 221 }
222 }
5eaef520 223 EXEC SQL CLOSE csr104;
224 if (dbms_errno)
225 return mr_errcode;
226 if (error)
227 return MR_INTERNAL;
b070f8a1 228 }
5eaef520 229 for (a = 0; a < acount; a++)
230 {
231 lid = ancestors[a];
232 for (d = 0; d < dcount; d++)
233 {
234 mid = descendants[d];
235 mtype = dtypes[d];
236 if (mid == lid && !strcmp(mtype, "LIST"))
237 return MR_LISTLOOP;
238 EXEC SQL SELECT COUNT(ref_count) INTO :rowcnt
239 FROM imembers
240 WHERE list_id = :lid AND member_id = :mid
241 AND member_type = :mtype;
242 ref = aref[a] * dref[d];
243 if (rowcnt > 0)
244 {
245 if (a == 0 && d == 0)
246 {
247 EXEC SQL UPDATE imembers
248 SET ref_count = ref_count + :ref, direct = 1
249 WHERE list_id = :lid AND member_id = :mid
250 AND member_type = :mtype;
0659551f 251 }
5eaef520 252 else
253 {
254 EXEC SQL UPDATE imembers
255 SET ref_count = ref_count + :ref
256 WHERE list_id = :lid AND member_id = :mid
257 AND member_type = :mtype;
258 }
259 }
260 else
261 {
262 incremental_clear_before();
263 if (a == 0 && d == 0)
264 {
03c05291 265 EXEC SQL INSERT INTO imembers
266 (list_id, member_id, direct, member_type, ref_count)
267 VALUES (:lid, :mid, 1, :mtype, 1);
5eaef520 268 }
269 else
270 {
03c05291 271 EXEC SQL INSERT INTO imembers
272 (list_id, member_id, direct, member_type, ref_count)
273 VALUES (:lid, :mid, 0, :mtype, 1);
0659551f 274 }
5eaef520 275 iargv[0] = (char *)lid;
276 iargv[1] = mtype;
277 iargv[2] = (char *)mid;
278 incremental_after(IMEMBERS_TABLE, 0, iargv);
0659551f 279 }
280 }
b070f8a1 281 }
5eaef520 282 lid = *(int *)argv[0];
283 entity = cl->entity;
284 who = cl->client_id;
285 EXEC SQL UPDATE list
286 SET modtime = SYSDATE, modby = :who, modwith = :entity
287 WHERE list_id = :lid;
288 if (dbms_errno)
289 return mr_errcode;
290 return MR_SUCCESS;
5d677c81 291}
b070f8a1 292
293
0659551f 294/* Delete_member_from_list: do list flattening as we go!
b070f8a1 295 */
296
5eaef520 297int delete_member_from_list(struct query *q, char **argv, client *cl)
5d677c81 298{
5eaef520 299 EXEC SQL BEGIN DECLARE SECTION;
300 int id, lid, mid, cnt, error, who, ref;
e688520a 301 char *mtype, dtype[IMEMBERS_MEMBER_TYPE_SIZE], *entity;
5eaef520 302 EXEC SQL END DECLARE SECTION;
303 int ancestors[MAXLISTDEPTH], aref[MAXLISTDEPTH], acount, a;
304 int descendants[MAXLISTDEPTH], dref[MAXLISTDEPTH], dcount, d;
305 char *dtypes[MAXLISTDEPTH];
306 char *iargv[3];
307
308 lid = *(int *)argv[0];
309 mtype = argv[1];
310 mid = *(int *)argv[2];
a37b0b99 311
312 if (acl_access_check(lid, cl))
313 return MR_PERM;
314
5eaef520 315 /* if the member is not a direct member of the list, punt */
316 EXEC SQL SELECT COUNT(list_id) INTO :cnt FROM imembers
317 WHERE list_id = :lid AND member_id = :mid
318 AND member_type = :mtype AND direct = 1;
319 if (dbms_errno)
320 return mr_errcode;
321 if (cnt == 0)
322 return MR_NO_MATCH;
323 ancestors[0] = lid;
324 aref[0] = 1;
325 acount = 1;
326 EXEC SQL DECLARE csr105 CURSOR FOR
327 SELECT list_id, ref_count FROM imembers
328 WHERE member_id = :lid AND member_type = 'LIST';
329 if (dbms_errno)
330 return mr_errcode;
331 EXEC SQL OPEN csr105;
332 if (dbms_errno)
333 return mr_errcode;
334 while (1)
335 {
336 EXEC SQL FETCH csr105 INTO :id, :ref;
337 if (sqlca.sqlcode)
338 break;
339 aref[acount] = ref;
340 ancestors[acount++] = id;
341 if (acount >= MAXLISTDEPTH)
342 break;
b070f8a1 343 }
5eaef520 344 EXEC SQL CLOSE csr105;
345 if (dbms_errno)
346 return mr_errcode;
347 if (acount >= MAXLISTDEPTH)
348 return MR_INTERNAL;
349 descendants[0] = mid;
350 dtypes[0] = mtype;
351 dref[0] = 1;
352 dcount = 1;
353 error = 0;
354 if (!strcmp(mtype, "LIST"))
355 {
356 EXEC SQL DECLARE csr106 CURSOR FOR
357 SELECT member_id, member_type, ref_count FROM imembers
358 WHERE list_id = :mid;
359 if (dbms_errno)
360 return mr_errcode;
361 EXEC SQL OPEN csr106;
362 if (dbms_errno)
363 return mr_errcode;
364 while (1)
365 {
366 EXEC SQL FETCH csr106 INTO :id, :dtype, :ref;
367 if (sqlca.sqlcode)
368 break;
369 switch (dtype[0])
370 {
0659551f 371 case 'L':
5eaef520 372 dtypes[dcount] = "LIST";
373 break;
0659551f 374 case 'U':
5eaef520 375 dtypes[dcount] = "USER";
376 break;
0659551f 377 case 'S':
5eaef520 378 dtypes[dcount] = "STRING";
379 break;
0659551f 380 case 'K':
5eaef520 381 dtypes[dcount] = "KERBEROS";
382 break;
0659551f 383 default:
5eaef520 384 error++;
385 break;
0659551f 386 }
5eaef520 387 dref[dcount] = ref;
388 descendants[dcount++] = id;
389 if (dcount >= MAXLISTDEPTH)
390 break;
0659551f 391 }
5eaef520 392 EXEC SQL CLOSE csr106;
393 if (dbms_errno)
394 return mr_errcode;
395 if (error)
396 return MR_INTERNAL;
3beadd83 397 }
5eaef520 398 for (a = 0; a < acount; a++)
399 {
400 lid = ancestors[a];
401 for (d = 0; d < dcount; d++)
402 {
403 mid = descendants[d];
404 mtype = dtypes[d];
405 if (mid == lid && !strcmp(mtype, "LIST"))
406 return MR_LISTLOOP;
407 EXEC SQL SELECT ref_count INTO :cnt FROM imembers
408 WHERE list_id = :lid AND member_id = :mid AND member_type = :mtype;
409 ref = aref[a] * dref[d];
410 if (cnt <= ref)
411 {
412 iargv[0] = (char *)lid;
413 iargv[1] = mtype;
414 iargv[2] = (char *)mid;
415 incremental_before(IMEMBERS_TABLE, 0, iargv);
416 EXEC SQL DELETE FROM imembers
417 WHERE list_id = :lid AND member_id = :mid
418 AND member_type= :mtype;
419 incremental_clear_after();
0659551f 420 }
5eaef520 421 else if (a == 0 && d == 0)
422 {
423 EXEC SQL UPDATE imembers
424 SET ref_count = ref_count - :ref, direct = 0
425 WHERE list_id = :lid AND member_id = :mid
426 AND member_type = :mtype;
427 }
428 else
429 {
430 EXEC SQL UPDATE imembers
431 SET ref_count = ref_count - :ref
432 WHERE list_id = :lid AND member_id = :mid
433 AND member_type = :mtype;
0659551f 434 }
435 }
3beadd83 436 }
5eaef520 437 lid = *(int *)argv[0];
438 entity = cl->entity;
439 who = cl->client_id;
440 EXEC SQL UPDATE list SET modtime = SYSDATE, modby = :who, modwith = :entity
441 WHERE list_id = :lid;
442 if (dbms_errno)
443 return mr_errcode;
444 return MR_SUCCESS;
5d677c81 445}
b070f8a1 446
447
a37b0b99 448/* Don't allow someone to add someone to a list which is the acl of a query
449 unless they're on the list acl, even if they're on the query acl! */
450int acl_access_check(int list_id, client *cl)
451{
452 EXEC SQL BEGIN DECLARE SECTION;
453 int c1, c2, lid = list_id, acl_id;
454 char acl_type[LIST_ACL_TYPE_SIZE];
455 EXEC SQL END DECLARE SECTION;
456
457 /* Check if the list is directly a capacl */
458 EXEC SQL SELECT COUNT(list_id) INTO :c1 FROM capacls WHERE list_id=:lid;
459
460 /* Check if the list is a member (direct or indirect) of a list that
461 is a capacl */
462 EXEC SQL SELECT COUNT(l1.list_id) INTO :c2 FROM list l1, list l2,
463 imembers im, capacls c WHERE c.list_id = l2.list_id AND
464 im.list_id = l2.list_id AND im.member_type = 'LIST' AND
465 im.member_id = l1.list_id AND l1.list_id = :lid;
466
467 if (c1 == 0 && c2 == 0)
468 return 0;
469
470 EXEC SQL SELECT acl_type, acl_id INTO :acl_type, :acl_id
471 FROM list WHERE list_id=:lid;
472 return !find_member(acl_type, acl_id, cl);
473}
474
475
0659551f 476/* get_ace_use - given a type and a name, return a type and a name.
477 * The ace_type is one of "LIST", "USER", "RLIST", or "RUSER" in argv[0],
478 * and argv[1] will contain the ID of the entity in question. The R*
479 * types mean to recursively look at every containing list, not just
480 * when the object in question is a direct member. On return, the
481 * usage type will be one of LIST, SERVICE, FILESYS, QUOTA, QUERY, or ZEPHYR.
b070f8a1 482 */
483
5eaef520 484int get_ace_use(struct query *q, char *argv[], client *cl,
7ac48069 485 int (*action)(int, char *[], void *), void *actarg)
5d677c81 486{
5eaef520 487 int found = 0;
488 EXEC SQL BEGIN DECLARE SECTION;
489 char *atype;
490 int aid, listid, id;
491 EXEC SQL END DECLARE SECTION;
7ac48069 492 struct save_queue *sq;
5eaef520 493
494 atype = argv[0];
495 aid = *(int *)argv[1];
496 if (!strcmp(atype, "LIST") || !strcmp(atype, "USER") ||
497 !strcmp(atype, "KERBEROS"))
498 return get_ace_internal(atype, aid, action, actarg);
499
500 sq = sq_create();
501 if (!strcmp(atype, "RLIST"))
502 {
7ac48069 503 sq_save_data(sq, (void *)aid);
5eaef520 504 /* get all the list_id's of containing lists */
505 EXEC SQL DECLARE csr107 CURSOR FOR
506 SELECT list_id FROM imembers
507 WHERE member_type = 'LIST' AND member_id = :aid;
508 if (dbms_errno)
509 return mr_errcode;
510 EXEC SQL OPEN csr107;
511 if (dbms_errno)
512 return mr_errcode;
513 while (1)
514 {
515 EXEC SQL FETCH csr107 INTO :listid;
516 if (sqlca.sqlcode)
517 break;
7ac48069 518 sq_save_unique_data(sq, (void *)listid);
0659551f 519 }
5eaef520 520 EXEC SQL CLOSE csr107;
521 /* now process each one */
522 while (sq_get_data(sq, &id))
523 {
524 if (get_ace_internal("LIST", id, action, actarg) == MR_SUCCESS)
525 found++;
0659551f 526 }
527 }
b070f8a1 528
5eaef520 529 if (!strcmp(atype, "RUSER"))
530 {
531 EXEC SQL DECLARE csr108 CURSOR FOR
532 SELECT list_id FROM imembers
533 WHERE member_type = 'USER' AND member_id = :aid;
534 if (dbms_errno)
535 return mr_errcode;
536 EXEC SQL OPEN csr108;
537 if (dbms_errno)
538 return mr_errcode;
539 while (1)
540 {
541 EXEC SQL FETCH csr108 INTO :listid;
542 if (sqlca.sqlcode)
543 break;
7ac48069 544 sq_save_data(sq, (void *)listid);
0659551f 545 }
5eaef520 546 EXEC SQL CLOSE csr108;
547 /* now process each one */
548 while (sq_get_data(sq, &id))
549 {
550 if (get_ace_internal("LIST", id, action, actarg) == MR_SUCCESS)
551 found++;
0659551f 552 }
5eaef520 553 if (get_ace_internal("USER", aid, action, actarg) == MR_SUCCESS)
554 found++;
0659551f 555 }
45bf7573 556
5eaef520 557 if (!strcmp(atype, "RKERBEROS"))
558 {
559 EXEC SQL DECLARE csr109 CURSOR FOR
560 SELECT list_id FROM imembers
561 WHERE member_type = 'KERBEROS' AND member_id = :aid;
562 if (dbms_errno)
563 return mr_errcode;
564 EXEC SQL OPEN csr109;
565 if (dbms_errno)
566 return mr_errcode;
567 while (1)
568 {
569 EXEC SQL FETCH csr109 INTO :listid;
570 if (sqlca.sqlcode)
571 break;
7ac48069 572 sq_save_data(sq, (void *)listid);
0659551f 573 }
5eaef520 574 EXEC SQL CLOSE csr109;
575 /* now process each one */
576 while (sq_get_data(sq, &id))
577 {
578 if (get_ace_internal("LIST", id, action, actarg) == MR_SUCCESS)
579 found++;
0659551f 580 }
5eaef520 581 if (get_ace_internal("KERBEROS", aid, action, actarg) == MR_SUCCESS)
582 found++;
0659551f 583 }
b3ce33fe 584
5eaef520 585 sq_destroy(sq);
586 if (dbms_errno)
587 return mr_errcode;
588 if (!found)
589 return MR_NO_MATCH;
590 return MR_SUCCESS;
5d677c81 591}
b070f8a1 592
593
0659551f 594/* This looks up a single list or user for ace use. atype must be "USER"
595 * or "LIST", and aid is the ID of the corresponding object. This is used
596 * by get_ace_use above.
b070f8a1 597 */
598
7ac48069 599int get_ace_internal(char *atype, int aid,
600 int (*action)(int, char *[], void *), void *actarg)
5d677c81 601{
5eaef520 602 char *rargv[2];
603 int found = 0;
604 EXEC SQL BEGIN DECLARE SECTION;
e688520a 605 char name[LIST_NAME_SIZE], *type = atype;
5eaef520 606 int id = aid;
607 EXEC SQL END DECLARE SECTION;
608
609 rargv[1] = name;
610 if (!strcmp(atype, "LIST"))
611 {
612 rargv[0] = "FILESYS";
613 EXEC SQL DECLARE csr110 CURSOR FOR
614 SELECT label FROM filesys
615 WHERE owners = :id;
616 if (dbms_errno)
617 return mr_errcode;
618 EXEC SQL OPEN csr110;
619 if (dbms_errno)
620 return mr_errcode;
621 while (1)
622 {
623 EXEC SQL FETCH csr110 INTO :name;
624 if (sqlca.sqlcode)
625 break;
626 (*action)(2, rargv, actarg);
627 found++;
b070f8a1 628 }
5eaef520 629 EXEC SQL CLOSE csr110;
630
631 rargv[0] = "QUERY";
632 EXEC SQL DECLARE csr111 CURSOR FOR
633 SELECT capability FROM capacls
634 WHERE list_id = :id;
635 if (dbms_errno)
636 return mr_errcode;
637 EXEC SQL OPEN csr111;
638 if (dbms_errno)
639 return mr_errcode;
640 while (1)
641 {
642 EXEC SQL FETCH csr111 INTO :name;
643 if (sqlca.sqlcode)
644 break;
645 (*action)(2, rargv, actarg);
646 found++;
b070f8a1 647 }
5eaef520 648 EXEC SQL CLOSE csr111;
649 }
650 else if (!strcmp(atype, "USER"))
651 {
652 rargv[0] = "FILESYS";
653 EXEC SQL DECLARE csr112 CURSOR FOR
654 SELECT label FROM filesys
655 WHERE owner = :id;
656 if (dbms_errno)
657 return mr_errcode;
658 EXEC SQL OPEN csr112;
659 if (dbms_errno)
660 return mr_errcode;
661 while (1)
662 {
663 EXEC SQL FETCH csr112 INTO :name;
664 if (sqlca.sqlcode)
665 break;
666 (*action)(2, rargv, actarg);
667 found++;
b070f8a1 668 }
5eaef520 669 EXEC SQL CLOSE csr112;
b070f8a1 670 }
0fc7ab46 671
5eaef520 672 rargv[0] = "LIST";
673 EXEC SQL DECLARE csr113 CURSOR FOR
674 SELECT name FROM list
675 WHERE acl_type = :type AND acl_id = :id;
676 if (dbms_errno)
677 return mr_errcode;
678 EXEC SQL OPEN csr113;
679 if (dbms_errno)
680 return mr_errcode;
681 while (1)
682 {
683 EXEC SQL FETCH csr113 INTO :name;
684 if (sqlca.sqlcode)
685 break;
686 (*action)(2, rargv, actarg);
687 found++;
5d677c81 688 }
5eaef520 689 EXEC SQL CLOSE csr113;
690
691 rargv[0] = "SERVICE";
692 EXEC SQL DECLARE csr114 CURSOR FOR
693 SELECT name FROM servers
694 WHERE acl_type = :type AND acl_id = :id;
695 if (dbms_errno)
696 return mr_errcode;
697 EXEC SQL OPEN csr114;
698 if (dbms_errno)
699 return mr_errcode;
700 while (1)
701 {
702 EXEC SQL FETCH csr114 INTO :name;
703 if (sqlca.sqlcode)
704 break;
705 (*action)(2, rargv, actarg);
706 found++;
0fc7ab46 707 }
5eaef520 708 EXEC SQL CLOSE csr114;
b070f8a1 709
5eaef520 710 rargv[0] = "HOSTACCESS";
711 EXEC SQL DECLARE csr115 CURSOR FOR
712 SELECT name FROM machine m, hostaccess ha
713 WHERE m.mach_id = ha.mach_id AND ha.acl_type = :type
714 AND ha.acl_id = :id;
03c05291 715 if (dbms_errno)
5eaef520 716 return mr_errcode;
0659551f 717 EXEC SQL OPEN csr115;
03c05291 718 if (dbms_errno)
5eaef520 719 return mr_errcode;
720 while (1)
721 {
0659551f 722 EXEC SQL FETCH csr115 INTO :name;
5eaef520 723 if (sqlca.sqlcode)
724 break;
0659551f 725 (*action)(2, rargv, actarg);
726 found++;
5eaef520 727 }
0659551f 728 EXEC SQL CLOSE csr115;
b070f8a1 729
0659551f 730 rargv[0] = "ZEPHYR";
731 EXEC SQL DECLARE csr116 CURSOR FOR
732 SELECT class FROM zephyr z
5eaef520 733 WHERE z.xmt_type = :type AND z.xmt_id = :id
734 OR z.sub_type = :type AND z.sub_id = :id
735 OR z.iws_type = :type AND z.iws_id = :id
736 OR z.iui_type = :type AND z.iui_id = :id;
03c05291 737 if (dbms_errno)
5eaef520 738 return mr_errcode;
0659551f 739 EXEC SQL OPEN csr116;
03c05291 740 if (dbms_errno)
5eaef520 741 return mr_errcode;
742 while (1)
743 {
0659551f 744 EXEC SQL FETCH csr116 INTO :name;
5eaef520 745 if (sqlca.sqlcode)
746 break;
0659551f 747 (*action)(2, rargv, actarg);
748 found++;
5eaef520 749 }
0659551f 750 EXEC SQL CLOSE csr116;
b070f8a1 751
5eaef520 752 if (!found)
753 return MR_NO_MATCH;
754 return MR_SUCCESS;
5d677c81 755}
b070f8a1 756
757
0659551f 758/* get_lists_of_member - given a type and a name, return the name and flags
759 * of all of the lists of the given member. The member_type is one of
760 * "LIST", "USER", "STRING", "RLIST", "RUSER", or "RSTRING" in argv[0],
761 * and argv[1] will contain the ID of the entity in question. The R*
762 * types mean to recursively look at every containing list, not just
763 * when the object in question is a direct member.
764 */
b070f8a1 765
5eaef520 766int get_lists_of_member(struct query *q, char *argv[], client *cl,
7ac48069 767 int (*action)(int, char *[], void *), void *actarg)
0659551f 768{
5eaef520 769 int found = 0, direct = 1;
770 char *rargv[6];
771 EXEC SQL BEGIN DECLARE SECTION;
772 char *atype;
773 int aid;
e688520a 774 char name[LIST_NAME_SIZE];
775 char active[5], public[5], hidden[5], maillist[5], grouplist[5];
5eaef520 776 EXEC SQL END DECLARE SECTION;
777
778 atype = argv[0];
779 aid = *(int *)argv[1];
780 if (!strcmp(atype, "RLIST"))
781 {
782 atype = "LIST";
783 direct = 0;
0659551f 784 }
5eaef520 785 if (!strcmp(atype, "RUSER"))
786 {
787 atype = "USER";
788 direct = 0;
0659551f 789 }
5eaef520 790 if (!strcmp(atype, "RSTRING"))
791 {
792 atype = "STRING";
793 direct = 0;
0659551f 794 }
5eaef520 795 if (!strcmp(atype, "RKERBEROS"))
796 {
797 atype = "KERBEROS";
798 direct = 0;
0659551f 799 }
b070f8a1 800
5eaef520 801 rargv[0] = name;
802 rargv[1] = active;
803 rargv[2] = public;
804 rargv[3] = hidden;
805 rargv[4] = maillist;
806 rargv[5] = grouplist;
807 if (direct)
808 {
809 EXEC SQL DECLARE csr117a CURSOR FOR
810 SELECT l.name, l.active, l.publicflg, l.hidden, l.maillist, l.grouplist
811 FROM list l, imembers im
812 WHERE l.list_id = im.list_id AND im.direct = 1
813 AND im.member_type = :atype AND im.member_id = :aid;
814 if (dbms_errno)
815 return mr_errcode;
816 EXEC SQL OPEN csr117a;
817 if (dbms_errno)
818 return mr_errcode;
819 while (1)
820 {
821 EXEC SQL FETCH csr117a
822 INTO :name, :active, :public, :hidden, :maillist, :grouplist;
823 if (sqlca.sqlcode)
824 break;
825 (*action)(6, rargv, actarg);
826 found++;
0659551f 827 }
5eaef520 828 EXEC SQL CLOSE csr117a;
829 }
830 else
831 {
832 EXEC SQL DECLARE csr117b CURSOR FOR
833 SELECT l.name, l.active, l.publicflg, l.hidden, l.maillist, l.grouplist
834 FROM list l, imembers im
835 WHERE l.list_id = im.list_id
836 AND im.member_type = :atype AND im.member_id = :aid;
837 if (dbms_errno)
838 return mr_errcode;
839 EXEC SQL OPEN csr117b;
840 if (dbms_errno)
841 return mr_errcode;
842 while (1)
843 {
844 EXEC SQL FETCH csr117b
845 INTO :name, :active, :public, :hidden, :maillist, :grouplist;
846 if (sqlca.sqlcode)
847 break;
848 (*action)(6, rargv, actarg);
849 found++;
0659551f 850 }
5eaef520 851 EXEC SQL CLOSE csr117b;
038fd8a4 852 }
0659551f 853
5eaef520 854 if (dbms_errno)
855 return mr_errcode;
856 if (!found)
857 return MR_NO_MATCH;
858 return MR_SUCCESS;
038fd8a4 859}
860
b070f8a1 861
0659551f 862/* qualified_get_lists: passed "TRUE", "FALSE", or "DONTCARE" for each of
863 * the five flags associated with each list. It will return the name of
864 * each list that meets the quailifications. It does this by building a
865 * where clause based on the arguments, then doing a retrieve.
866 */
867
868static char *lflags[5] = { "active", "publicflg", "hidden", "maillist", "grouplist" };
b070f8a1 869
5eaef520 870int qualified_get_lists(struct query *q, char *argv[], client *cl,
7ac48069 871 int (*action)(int, char *[], void *), void *actarg)
5d677c81 872{
5eaef520 873 return qualified_get(q, argv, action, actarg, "l.list_id != 0",
874 "l", "name", lflags);
0659551f 875}
0fc7ab46 876
5d677c81 877
0659551f 878/* get_members_of_list - this gets only direct members */
5eaef520 879
880int get_members_of_list(struct query *q, char *argv[], client *cl,
7ac48069 881 int (*action)(int, char *[], void *), void *actarg)
0659551f 882{
5eaef520 883 return gmol_internal(q, argv, cl, action, actarg, 1);
5d677c81 884}
5eaef520 885
0659551f 886/* get_end_members_of_list - this gets direct or indirect members */
5eaef520 887
888int get_end_members_of_list(struct query *q, char *argv[], client *cl,
7ac48069 889 int (*action)(int, char *[], void *), void *actarg)
b070f8a1 890{
5eaef520 891 return gmol_internal(q, argv, cl, action, actarg, 0);
0659551f 892}
5eaef520 893
0659551f 894/** gmol_internal - optimized query for retrieval of list members
895 ** used by both get_members_of_list and get_end_members_of_list
896 **
897 ** Inputs:
898 ** argv[0] - list_id
899 **
900 ** Description:
901 ** - retrieve USER members, then LIST members, then STRING members
902 **/
b070f8a1 903
5eaef520 904int gmol_internal(struct query *q, char *argv[], client *cl,
7ac48069 905 int (*action)(int, char *[], void *), void *actarg, int flag)
0659551f 906{
5eaef520 907 EXEC SQL BEGIN DECLARE SECTION;
7ac48069 908 int list_id, direct;
e688520a 909 char member_name[MAX_FIELD_WIDTH];
5eaef520 910 EXEC SQL END DECLARE SECTION;
911 char *targv[2];
5eaef520 912
913 /* true/false flag indicates whether to display only direct members. */
914 if (flag)
915 direct = 0;
916 else
917 direct = -1;
918
919 list_id = *(int *)argv[0];
920
921 targv[1] = member_name;
922 targv[0] = "USER";
923 EXEC SQL DECLARE csr119 CURSOR FOR
924 SELECT u.login FROM users u, imembers im
925 WHERE im.list_id = :list_id AND im.member_type = 'USER'
926 AND im.member_id = u.users_id AND im.direct > :direct
927 ORDER BY 1;
928 if (dbms_errno)
929 return mr_errcode;
930 EXEC SQL OPEN csr119;
931 if (dbms_errno)
932 return mr_errcode;
933 while (1)
934 {
935 EXEC SQL FETCH csr119 INTO :member_name;
936 if (sqlca.sqlcode)
937 break;
938 (*action)(2, targv, actarg);
b070f8a1 939 }
5eaef520 940 EXEC SQL CLOSE csr119;
941 if (dbms_errno)
942 return mr_errcode;
943
944 targv[0] = "LIST";
945 EXEC SQL DECLARE csr120 CURSOR FOR
946 SELECT l.name FROM list l, imembers im
947 WHERE im.list_id = :list_id AND im.member_type = 'LIST'
948 AND im.member_id = l.list_id AND im.direct > :direct
949 ORDER BY 1;
950 if (dbms_errno)
951 return mr_errcode;
952 EXEC SQL OPEN csr120;
953 if (dbms_errno)
954 return mr_errcode;
955 while (1)
956 {
957 EXEC SQL FETCH csr120 INTO :member_name;
958 if (sqlca.sqlcode)
959 break;
960 (*action)(2, targv, actarg);
b070f8a1 961 }
5eaef520 962 EXEC SQL CLOSE csr120;
963 if (dbms_errno)
964 return mr_errcode;
965
966 targv[0] = "STRING";
967 EXEC SQL DECLARE csr121 CURSOR FOR
968 SELECT str.string FROM strings str, imembers im
969 WHERE im.list_id = :list_id AND im.member_type = 'STRING'
970 AND im.member_id = str.string_id AND im.direct > :direct
971 ORDER BY 1;
972 if (dbms_errno)
973 return mr_errcode;
974 EXEC SQL OPEN csr121;
975 if (dbms_errno)
976 return mr_errcode;
977 while (1)
978 {
979 EXEC SQL FETCH csr121 INTO :member_name;
980 if (sqlca.sqlcode)
981 break;
982 (*action)(2, targv, actarg);
b070f8a1 983 }
5eaef520 984 EXEC SQL CLOSE csr121;
985 if (dbms_errno)
986 return mr_errcode;
987
988 targv[0] = "KERBEROS";
989 EXEC SQL DECLARE csr122 CURSOR FOR
990 SELECT str.string FROM strings str, imembers im
991 WHERE im.list_id = :list_id AND im.member_type = 'KERBEROS'
992 AND im.member_id = str.string_id
993 AND im.direct > :direct
994 ORDER BY 1;
995 if (dbms_errno)
996 return mr_errcode;
997 EXEC SQL OPEN csr122;
998 if (dbms_errno)
999 return mr_errcode;
1000 while (1)
1001 {
1002 EXEC SQL FETCH csr122 INTO :member_name;
1003 if (sqlca.sqlcode)
1004 break;
1005 (*action)(2, targv, actarg);
0659551f 1006 }
5eaef520 1007 EXEC SQL CLOSE csr122;
1008 if (dbms_errno)
1009 return mr_errcode;
b070f8a1 1010
5eaef520 1011 return MR_SUCCESS;
5d677c81 1012}
b070f8a1 1013
1014
0659551f 1015/* count_members_of_list: this is a simple query, but it cannot be done
1016 * through the dispatch table.
1017 */
b070f8a1 1018
5eaef520 1019int count_members_of_list(struct query *q, char *argv[], client *cl,
7ac48069 1020 int (*action)(int, char *[], void *), void *actarg)
5d677c81 1021{
5eaef520 1022 EXEC SQL BEGIN DECLARE SECTION;
1023 int list, ct = 0;
1024 EXEC SQL END DECLARE SECTION;
1025 char *rargv[1], countbuf[5];
1026
1027 list = *(int *)argv[0];
1028 rargv[0] = countbuf;
1029 EXEC SQL SELECT count (*) INTO :ct FROM imembers
1030 WHERE list_id = :list AND direct = 1;
1031 if (dbms_errno)
1032 return mr_errcode;
1033 sprintf(countbuf, "%d", ct);
1034 (*action)(1, rargv, actarg);
1035 return MR_SUCCESS;
5d677c81 1036}
b070f8a1 1037
b070f8a1 1038
0659551f 1039/* qualified_get_server: passed "TRUE", "FALSE", or "DONTCARE" for each of
1040 * the three flags associated with each service. It will return the name of
1041 * each service that meets the quailifications. It does this by building a
1042 * where clause based on the arguments, then doing a retrieve.
1043 */
b070f8a1 1044
0659551f 1045static char *sflags[3] = { "enable", "inprogress", "harderror" };
b070f8a1 1046
5eaef520 1047int qualified_get_server(struct query *q, char *argv[], client *cl,
7ac48069 1048 int (*action)(int, char *[], void *), void *actarg)
5d677c81 1049{
5eaef520 1050 return qualified_get(q, argv, action, actarg, "s.name is not null",
1051 "s", "name", sflags);
1052 /* of course, name will never be null, but we need something there
1053 to make qualified_get happy */
5d677c81 1054}
b070f8a1 1055
1056
0659551f 1057/* generic qualified get routine, used by qualified_get_lists,
1058 * qualified_get_server, and qualified_get_serverhost.
1059 * Args:
1060 * start - a simple where clause, must not be empty
1061 * range - the name of the range variable
1062 * field - the field to return
1063 * flags - an array of strings, names of the flag variables
b070f8a1 1064 */
1065
7ac48069 1066int qualified_get(struct query *q, char *argv[],
1067 int (*action)(int, char *[], void *), void *actarg,
5eaef520 1068 char *start, char *range, char *field, char *flags[])
453b99fe 1069{
5eaef520 1070 char qual[256];
1071 int i;
1072 char buf[32];
1073
1074 strcpy(qual, start);
1075 for (i = 0; i < q->argc; i++)
1076 {
1077 if (!strcmp(argv[i], "TRUE"))
1078 {
1079 sprintf(buf, " AND %s.%s != 0", range, flags[i]);
1080 strcat(qual, buf);
1081 }
1082 else if (!strcmp(argv[i], "FALSE"))
1083 {
1084 sprintf(buf, " AND %s.%s = 0", range, flags[i]);
1085 strcat(qual, buf);
0659551f 1086 }
453b99fe 1087 }
1088
5eaef520 1089 sprintf(stmt_buf, "SELECT %s.%s FROM %s %s WHERE %s", range, field,
1090 table_name[q->rtable], range, qual);
1091 return do_for_all_rows(stmt_buf, 1, action, actarg);
453b99fe 1092}
1093
1094
0659551f 1095/* qualified_get_serverhost: passed "TRUE", "FALSE", or "DONTCARE" for each of
1096 * the five flags associated with each serverhost. It will return the name of
1097 * each service and host that meets the quailifications. It does this by
1098 * building a where clause based on the arguments, then doing a retrieve.
45bf7573 1099 */
45bf7573 1100
0659551f 1101static char *shflags[6] = { "service", "enable", "override", "success",
1102 "inprogress", "hosterror" };
45bf7573 1103
5eaef520 1104int qualified_get_serverhost(struct query *q, char *argv[], client *cl,
7ac48069 1105 int (*action)(int, char *[], void *),
1106 void *actarg)
45bf7573 1107{
5eaef520 1108 char qual[256], buf[32];
1109 int i;
1110
1111 sprintf(qual, "m.mach_id = sh.mach_id AND sh.service = UPPER('%s')",
1112 argv[0]);
1113 for (i = 1; i < q->argc; i++)
1114 {
1115 if (!strcmp(argv[i], "TRUE"))
1116 {
1117 sprintf(buf, " AND sh.%s != 0", shflags[i]);
1118 strcat(qual, buf);
1119 }
1120 else if (!strcmp(argv[i], "FALSE"))
1121 {
1122 sprintf(buf, " AND sh.%s = 0", shflags[i]);
1123 strcat(qual, buf);
0659551f 1124 }
1125 }
45bf7573 1126
5eaef520 1127 sprintf(stmt_buf, "SELECT sh.service, m.name FROM serverhosts sh, "
1128 "machine m WHERE %s", qual);
1129 return do_for_all_rows(stmt_buf, 2, action, actarg);
45bf7573 1130}
1131
0659551f 1132
1133/* register_user - change user's login name and allocate a pobox, group,
1134 * filesystem, and quota for them. The user's status must start out as 0,
1135 * and is left as 2. Arguments are: user's UID, new login name, and user's
1136 * type for filesystem allocation (MR_FS_STUDENT, MR_FS_FACULTY,
1137 * MR_FS_STAFF, MR_FS_MISC).
99e09b48 1138 */
0659551f 1139
5eaef520 1140int register_user(struct query *q, char **argv, client *cl)
99e09b48 1141{
5eaef520 1142 EXEC SQL BEGIN DECLARE SECTION;
e688520a 1143 char *login, *entity;
1144 char directory[FILESYS_NAME_SIZE], machname[MACHINE_NAME_SIZE];
5eaef520 1145 int who, rowcount, mid, uid, users_id, utype, list_id;
7ac48069 1146 int ostatus, nstatus, fsidval;
5eaef520 1147 static int m_id = 0, def_quota = 0;
1148 EXEC SQL END DECLARE SECTION;
1149 char buffer[256], *aargv[3];
1150
1151 entity = cl->entity;
1152 who = cl->client_id;
1153
1154 uid = atoi(argv[0]);
1155 login = argv[1];
1156 utype = atoi(argv[2]);
1157
1158 /* find user */
1159 EXEC SQL SELECT users_id, status INTO :users_id, :ostatus
1160 FROM users
1161 WHERE unix_uid = :uid AND (status = 0 OR status = 5 OR status = 6);
1162
1163 if (sqlca.sqlerrd[2] == 0)
1164 return MR_NO_MATCH;
1165 if (sqlca.sqlerrd[2] > 1)
1166 return MR_NOT_UNIQUE;
1167
1168 /* check new login name */
1169 EXEC SQL SELECT COUNT(login) INTO :rowcount FROM users
1170 WHERE login = :login AND users_id != :users_id;
1171 if (dbms_errno)
1172 return mr_errcode;
1173 if (rowcount > 0)
1174 return MR_IN_USE;
1175 EXEC SQL SELECT COUNT(name) INTO :rowcount FROM list
1176 WHERE name = :login;
1177 if (dbms_errno)
1178 return mr_errcode;
1179 if (rowcount > 0)
1180 return MR_IN_USE;
1181 EXEC SQL SELECT COUNT(label) INTO :rowcount FROM filesys
1182 WHERE label = :login;
1183 if (dbms_errno)
1184 return mr_errcode;
1185 if (rowcount > 0)
1186 return MR_IN_USE;
1187 EXEC SQL SELECT COUNT(name) INTO :rowcount FROM alias
1188 WHERE name = :login AND type = 'FILESYS';
1189 if (dbms_errno)
1190 return mr_errcode;
1191 if (rowcount > 0)
1192 return MR_IN_USE;
1193 com_err(whoami, 0, "login name OK");
1194
1195 /* choose place for pobox, put in mid */
1196 EXEC SQL DECLARE csr130 CURSOR FOR
1197 SELECT sh.mach_id, m.name FROM serverhosts sh, machine m
1198 WHERE sh.service = 'POP' AND sh.mach_id = m.mach_id
1199 AND sh.value2 - sh.value1 = (SELECT MAX(value2 - value1) FROM serverhosts
1200 WHERE service = 'POP');
1201 if (dbms_errno)
1202 return mr_errcode;
1203 EXEC SQL OPEN csr130;
1204 if (dbms_errno)
1205 return mr_errcode;
1206 EXEC SQL FETCH csr130 INTO :mid, :machname;
1207 if (sqlca.sqlerrd[2] == 0)
1208 {
1209 EXEC SQL CLOSE csr130;
1210 if (dbms_errno)
1211 return mr_errcode;
1212 return MR_NO_POBOX;
1213 }
1214 else
1215 {
1216 EXEC SQL CLOSE csr130;
1217 if (dbms_errno)
1218 return mr_errcode;
99e09b48 1219 }
99e09b48 1220
5eaef520 1221 /* change login name, set pobox */
1222 sprintf(buffer, "u.users_id = %d", users_id);
1223 incremental_before(USERS_TABLE, buffer, 0);
1224 nstatus = 2;
1225 if (ostatus == 5 || ostatus == 6)
1226 nstatus = 1;
1227 EXEC SQL UPDATE users SET login = :login, status = :nstatus,
1228 modtime = SYSDATE, modby = :who, modwith = :entity, potype = 'POP',
1229 pop_id = :mid, pmodtime = SYSDATE, pmodby = :who, pmodwith = :entity
1230 WHERE users_id = :users_id;
1231
1232 if (dbms_errno)
1233 return mr_errcode;
1234 if (sqlca.sqlerrd[2] != 1)
1235 return MR_INTERNAL;
1236 set_pop_usage(mid, 1);
1237 com_err(whoami, 0, "set login name to %s and pobox to %s", login,
1238 strtrim(machname));
1239 incremental_after(USERS_TABLE, buffer, 0);
1240
1241 if (m_id == 0)
1242 {
1243 /* Cell Name (I know, it shouldn't be hard coded...) */
1244 strcpy(machname, "ATHENA.MIT.EDU");
1245 EXEC SQL SELECT mach_id INTO :m_id FROM machine
1246 WHERE name = :machname;
0659551f 1247 }
3beadd83 1248
5eaef520 1249 EXEC SQL SELECT list_id INTO :list_id FROM list
1250 WHERE name = 'wheel';
1251
1252 /* create filesystem */
1253 if (set_next_object_id("filsys_id", FILESYS_TABLE, 0))
1254 return MR_NO_ID;
1255 incremental_clear_before();
1256 if (islower(login[0]) && islower(login[1]))
1257 {
1258 sprintf(directory, "/afs/athena.mit.edu/user/%c/%c/%s",
1259 login[0], login[1], login);
0659551f 1260 }
5eaef520 1261 else
1262 sprintf(directory, "/afs/athena.mit.edu/user/other/%s", login);
1263
1264 EXEC SQL SELECT value INTO :fsidval FROM numvalues
1265 WHERE numvalues.name = 'filsys_id';
1266 EXEC SQL INSERT INTO filesys
1267 (filsys_id, phys_id, label, type, mach_id, name,
1268 mount, rwaccess, comments, owner, owners, createflg,
1269 lockertype, modtime, modby, modwith)
1270 VALUES
1271 (:fsidval, 0, :login, 'AFS', :m_id, :directory,
1272 '/mit/' || :login, 'w', 'User Locker', :users_id, :list_id, 1,
1273 'HOMEDIR', SYSDATE, :who, :entity);
1274
1275 if (dbms_errno)
1276 return mr_errcode;
1277 if (sqlca.sqlerrd[2] != 1)
1278 return MR_INTERNAL;
1279 sprintf(buffer, "fs.filsys_id = %d", fsidval);
1280 incremental_after(FILESYS_TABLE, buffer, 0);
1281
1282 /* set quota */
1283 if (def_quota == 0)
1284 {
1285 EXEC SQL SELECT value INTO :def_quota FROM numvalues
1286 WHERE name = 'def_quota';
1287 if (dbms_errno)
1288 return mr_errcode;
1289 if (sqlca.sqlerrd[2] != 1)
1290 return MR_NO_QUOTA;
0659551f 1291 }
5eaef520 1292 incremental_clear_before();
1293 EXEC SQL INSERT INTO quota
1294 (entity_id, filsys_id, type, quota, phys_id, modtime, modby, modwith)
1295 VALUES (0, :fsidval, 'ANY', :def_quota, 0, SYSDATE, :who, :entity);
1296 if (dbms_errno)
1297 return mr_errcode;
1298 if (sqlca.sqlerrd[2] != 1)
1299 return MR_INTERNAL;
1300 aargv[0] = login;
1301 aargv[1] = "ANY";
1302 aargv[2] = login;
1303 sprintf(buffer, "q.entity_id = 0 and q.filsys_id = %d and q.type = 'ANY'",
1304 fsidval);
1305 incremental_after(QUOTA_TABLE, buffer, aargv);
1306 com_err(whoami, 0, "quota of %d assigned", def_quota);
1307 if (dbms_errno)
1308 return mr_errcode;
1309
1310 cache_entry(login, USERS_TABLE, users_id);
1311
1312 EXEC SQL UPDATE tblstats SET updates = updates + 1, modtime = SYSDATE
1313 WHERE table_name = 'users';
1314 EXEC SQL UPDATE tblstats SET appends = appends + 1, modtime = SYSDATE
1315 WHERE table_name = 'filesys' OR table_name = 'quota';
1316 if (dbms_errno)
1317 return mr_errcode;
1318 return MR_SUCCESS;
3afb5524 1319}
1320
835aabee 1321
1322
0659551f 1323/** set_pop_usage - incr/decr usage count for pop server in serverhosts talbe
1324 **
1325 ** Inputs:
1326 ** id of machine
1327 ** delta (will be +/- 1)
1328 **
1329 ** Description:
1330 ** - incr/decr value field in serverhosts table for pop/mach_id
1331 **
1332 **/
1333
1334int set_pop_usage(id, cnt)
03c05291 1335 int id, cnt;
0659551f 1336{
5eaef520 1337 EXEC SQL BEGIN DECLARE SECTION;
1338 int iid = id, icnt = cnt;
1339 EXEC SQL END DECLARE SECTION;
03c05291 1340
5eaef520 1341 EXEC SQL UPDATE serverhosts SET value1 = value1 + :icnt
1342 WHERE serverhosts.service = 'POP' AND serverhosts.mach_id = :iid;
835aabee 1343
5eaef520 1344 if (dbms_errno)
1345 return mr_errcode;
1346 return MR_SUCCESS;
835aabee 1347}
1348
This page took 0.323444 seconds and 5 git commands to generate.