]> andersk Git - moira.git/blame - server/qsupport.qc
Fixed makefile; now has install step.
[moira.git] / server / qsupport.qc
CommitLineData
05cdd922 1/*
2 * $Source$
3 * $Author$
4 * $Header$
5 *
6 * Copyright (C) 1987 by the Massachusetts Institute of Technology
7 *
8 * $Log$
92a943d6 9 * Revision 1.8 1987-08-18 15:05:20 wesommer
10 * Fixed definition of add_locker.
05cdd922 11 *
92a943d6 12Revision 1.7 87/08/04 01:49:41 wesommer
13Rearranged messages.
14
b4182127 15Revision 1.6 87/08/04 01:10:02 wesommer
16Changes by mike; checked in prior to my hacking.
17
c2408bd5 18Revision 1.5 87/07/30 14:54:13 wesommer
19Added debugging code in an attempt to catch a flakey problem.
20
247969d5 21Revision 1.4 87/07/30 00:30:21 wesommer
22replaced appends = appends+1 with appends = tbs.appends+1
23
3b2ceb9a 24Revision 1.3 87/07/30 00:26:11 wesommer
25Changes by mike prior to "appends" fix.
26
30967516 27Revision 1.2 87/07/29 16:00:39 wesommer
28Fixed add_locker.
29
7195989f 30Revision 1.1 87/07/29 15:13:57 wesommer
31Initial revision
32
05cdd922 33 */
34
35#ifndef lint
36static char *rcsid_qsupport_qc = "$Header$";
37#endif lint
38
39#include "query.h"
40#include "sms_server.h"
41#include <ctype.h>
42
43#define SMS_SUCCESS 0
44
45extern char *whoami;
46
47/* Specialized Access Routines */
48
49/**
50 ** access_user - verify that client name equals specified login name
51 **
52 ** Used by: update_user_shell
53 ** update_finger_by_login
54 **
55 ** - since field validation routines are called first, a users_id is
56 ** now in argv[0] instead of the login name. Therefore, we must
57 ** convert the client name to a users_id.
58 **/
59
60access_user(q, argv, cl)
61 struct query *q;
62 char *argv[];
63 client *cl;
64##{
65 register struct krbname *krb;
66## int client_id;
67## char *client_name;
68## int rowcount;
69
70 client_name = cl->kname.name;
71## repeat retrieve (client_id = users.users_id)
72## where users.login = @client_name
73## inquire_equel (rowcount = "rowcount")
74 if (rowcount != 1) return(SMS_PERM);
75 if (client_id != *(int *)argv[0]) return(SMS_PERM);
76
77 return(SMS_SUCCESS);
78##}
79
30967516 80/**
81 ** access_pop - same as access_user plus verifies that a user has only one
82 ** mailbox of type "POP"
83 **
84 ** Inputs:
85 ** argv[0] - users_id
86 ** argv[1] - type
87 ** argv[2] - mach_id
88 ** argv[3] - box
89 **
90 ** Description:
91 ** - if q->name = "add_pobox" and type = "POP",
92 ** verify that no POP box already exists for user
93 ** - call access_user
94 **
95 **/
96
97access_pop(q, argv, cl)
98 struct query *q;
99 char *argv[];
100 client *cl;
101##{
102## int users_id;
103## int mach_id;
104## char *box;
105## int exists;
106
107 if (!bcmp(q->name, "add_pobox", 10) && !bcmp(argv[1], "POP", 4)) {
108 users_id = *(int *)argv[0];
109 mach_id = *(int *)argv[2];
110 box = argv[3];
111## range of p is pobox
112## repeat retrieve (exists = any(p.#box where p.#users_id = @users_id
113## and p.type = "POP"
114## and p.#mach_id = @mach_id
115## and p.#box = @box))
116 if (exists) return(SMS_EXISTS);
117 }
118
119 return(access_user(q, argv, cl));
120##}
121
05cdd922 122/**
123 ** access_list - check access for adding or deleting list members
124 **
125 ** Inputs: argv[0] - list_id
126 ** cl->krb.name - client name
127 **
128 ** - check that client is a member of the access control list
129 ** - OR, if q->shortname == {amtl | dfml} and
130 ** if list.flags & LF_PUBLIC, allow access if client = member
131 **
132 **/
133
134access_list(q, argv, cl)
135 struct query *q;
136 char *argv[];
137 client *cl;
138##{
139## int list_id;
140## int acl_id;
141## int flags;
142 int member_id;
143 char *client_type;
144 int client_id;
145 int status;
146 int exists;
147
148 list_id = *(int *)argv[0];
149## repeat retrieve (acl_id = list.#acl_id, flags = list.#flags)
150## where list.#list_id = @list_id
151
152 /* parse client structure */
153 status = get_client(cl, &client_type, &client_id);
154 if (status != SMS_SUCCESS) return(status);
155
156 /* if amtl or dmfl and list is public allow client to add or delete self */
157 if (!bcmp("amtl", q->shortname, 4) || !bcmp("dmfl", q->shortname, 4)) {
158 if ((flags & LF_PUBLIC) && !bcmp("USER", argv[1], 4)) {
159 member_id = *(int *)argv[2];
160 if (member_id == client_id) return(SMS_SUCCESS);
161 }
162 }
163
164 /* check for client in access control list */
165 exists = find_member(acl_id, client_type, client_id, 0);
166 if (!exists) return(SMS_PERM);
167
168 return(SMS_SUCCESS);
169##}
92a943d6 170
171/**
172 ** Setup routine for add_group
173 **
174 ** Inputs: none
175 **
176 ** Description: allocate next gid and store in values table
177 **
178 **/
179
180setup_add_group(q, argv, cl, access_check)
181 struct query *q;
182 char *argv[];
183 client *cl;
184 int access_check;
185##{
186## int ngid;
187## int exists;
188 int status;
189
190 status = access_list(q, argv, cl);
191
192 if (status != SMS_SUCCESS || access_check) return(status);
193
194## range of g is groups
195## range of v is values
196## repeat retrieve (ngid = v.value) where v.name = "gid"
197 exists = 1;
198 while (exists) {
199 ngid++;
200## repeat retrieve (exists = any(g.#gid where g.#gid = @ngid))
201 }
202
203## repeat replace v (value = @ngid) where v.name = "gid"
204 return(SMS_SUCCESS);
205##}
05cdd922 206\f
207/**
208 ** Setup routine for add_user
209 **
210 ** Inputs: argv[0] - login
211 ** argv[1] - uid
212 **
213 ** Description:
214 **
215 ** - if argv[1] == "#" then set argv[1] = next(uid)
216 ** - if argv[0] == "#" then set argv[0] = "#<uid>"
217 **
218 **/
219
220setup_add_user(q, argv, cl, access_check)
221 struct query *q;
222 register char *argv[];
223 client *cl;
224 int access_check;
225##{
226## int nuid;
227## int exists;
228
229 if (access_check) return(SMS_SUCCESS);
230
231 if (!bcmp(argv[1], "#", 2)) {
232## range of u is users
233## range of v is values
234## repeat retrieve (nuid = v.value) where v.name = "uid"
235 exists = 1;
236 while (exists) {
237 nuid++;
238## repeat retrieve (exists = any(u.#uid where u.#uid = @nuid))
239 }
240## repeat replace v (value = @nuid) where v.name = "uid"
241 sprintf(argv[1], "%d", nuid);
242 }
243
244 if (!bcmp(argv[0], "#", 2)) {
245 sprintf(argv[0], "#%s", argv[1]);
246 }
247
248 return(SMS_SUCCESS);
249##}
250
251/**
92a943d6 252 ** followup_add_user - add finger entry, set_user_modtime
253 ** followup_delete_user - delete finger entry
05cdd922 254 **
92a943d6 255 ** Inputs:
256 ** argv[0] - login (add_user)
257 ** argv[0] - users_id (delete_user)
05cdd922 258 **
259 **/
260
92a943d6 261followup_add_user(q, argv)
05cdd922 262 struct query *q;
263 char *argv[];
05cdd922 264##{
92a943d6 265## char *login;
266## int users_id;
267## char first[33];
268## char middle[33];
269## char last[33];
270## char fullname[128];
271 register char *cp1;
272 register char *cp2;
05cdd922 273
92a943d6 274 login = argv[0];
05cdd922 275
92a943d6 276 /* get user information */
277## range of u is users
278## repeat retrieve (users_id = u.#users_id, last = u.#last,
279## first = u.#first, middle = u.#middle)
280## where u.#login = @login
281
282 /* build fullname */
283 cp2 = fullname;
284 cp1 = first;
285 while (*cp1) *cp2++ = *cp1++;
286 *cp2++ = ' ';
287 cp1 = middle;
288 if (*cp1 == 0) cp2--;
289 while (*cp1) *cp2++ = *cp1++;
290 *cp2++ = ' ';
291 cp1 = last;
292 while (*cp2++ = *cp1++) ;
293
294 /* create a finger entry */
295## repeat append finger (#users_id = @users_id, #fullname = @fullname)
296
297 /* set modtime (creation time) on user */
298## repeat replace u (modtime = "now") where u.#users_id = @users_id
05cdd922 299
92a943d6 300 return(SMS_SUCCESS);
301##}
302
303followup_delete_user(q, argv)
304 struct query *q;
305 char *argv[];
306##{
307## int users_id;
308
309 users_id = *(int *)argv[0];
310## repeat delete finger where finger.#users_id = @users_id
05cdd922 311 return(SMS_SUCCESS);
312##}
313\f
c2408bd5 314/**
315 ** setup_add_filesys - verify existance of referenced file systems
316 ** setup_update_filesys - same, except argv[1..5] --> argv[2..6]
317 **
318 ** Inputs: Add Update
319 ** argv[0] - label label
320 ** argv[1] - type new label
321 ** argv[2] - mach_id type
322 ** argv[3] - name mach_id
323 ** argv[4] - mount name
324 ** argv[5] - access mount
325 ** argv[6] - access
326 **
327 ** Description:
328 ** - for type = RVD:
329 ** * verify mach_id/name in rvdvirt
330 ** * verify access in {r, x, R, X}
331 ** - for type = NFS:
332 ** * extract directory prefix from name
333 ** * verify mach_id/dir in nfsphys
334 ** * verify access in {r, w, R, W}
335 **
336 ** Errors:
337 ** SMS_RVD - no such rvd
338 ** SMS_NFS - specified directory not exported
339 ** SMS_FILESYS_ACCESS - invalid filesys access
340 **
341 **/
342
343setup_add_filesys(q, argv)
344 struct query *q;
345 char *argv[];
346{
347 char *type;
348 int mach_id;
349 char *name;
350 char *access;
351
352 type = argv[1];
353 mach_id = *(int *)argv[2];
354 name = argv[3];
355 access = argv[5];
356
357 if (!bcmp(type, "RVD", 3))
358 return (check_rvd(mach_id, name, access));
359 else if (!bcmp(type, "NFS", 3))
360 return (check_nfs(mach_id, name, access));
361 else
362 return(SMS_SUCCESS);
363}
364
365setup_update_filesys(q, argv)
366 struct query *q;
367 char *argv[];
368{
369 char *type;
370 int mach_id;
371 char *name;
372 char *access;
373
374 type = argv[2];
375 mach_id = *(int *)argv[3];
376 name = argv[4];
377 access = argv[6];
378
379 if (!bcmp(type, "RVD", 3))
380 return (check_rvd(mach_id, name, access));
381 else if (!bcmp(type, "NFS", 3))
382 return (check_nfs(mach_id, name, access));
383 else
384 return(SMS_SUCCESS);
385}
386
387##check_rvd(mach_id, name, access)
388## int mach_id;
389## char *name;
390 char *access;
391##{
392## int rowcount;
393 char caccess;
394
395## range of rv is rvdvirt
396## retrieve (rowcount = any(rv.#name where rv.#mach_id = mach_id and
397## rv.#name = name))
398 if (rowcount == 0) return(SMS_RVD);
399
400 caccess = (isupper(*access)) ? tolower(*access) : *access;
401 if (caccess != 'r' && caccess != 'x') return(SMS_FILESYS_ACCESS);
402
403 return(SMS_SUCCESS);
404##}
405
406##check_nfs(mach_id, name, access)
407## int mach_id;
408 char *name;
409 char *access;
410##{
411## int rowcount;
412## char dir[32];
413 char caccess;
414 register char *cp1;
415 register char *cp2;
416
417 caccess = (isupper(*access)) ? tolower(*access) : *access;
418 if (caccess != 'r' && caccess != 'w') return(SMS_FILESYS_ACCESS);
419
420## range of np is nfsphys
421## retrieve (dir = np.#dir) where np.#mach_id = mach_id
422## {
423 cp1 = name;
424 cp2 = dir;
425 while (*cp2) {
426 if (*cp1++ != *cp2) break;
427 cp2++;
428 }
429 if (*cp2 == 0) return(SMS_SUCCESS);
430## }
431
432 return(SMS_NFS);
433##}
434\f
05cdd922 435/* Followup Routines */
436
437set_user_modtime(q, argv)
438 struct query *q;
439 char *argv[];
440##{
441## char *login;
442
443 login = argv[0];
444## repeat replace u (modtime = "now") where u.#login = @login
445 return(SMS_SUCCESS);
446##}
447
448set_user_modtime_by_id(q, argv)
449 struct query *q;
450 char *argv[];
451##{
452## int users_id;
453
454 users_id = *(int *)argv[0];
455## repeat replace users (modtime = "now") where users.#users_id = @users_id
456 return(SMS_SUCCESS);
457##}
458
459set_list_modtime(q, argv)
460 struct query *q;
461 char *argv[];
462##{
463## char *list_name;
464
465 list_name = argv[0];
466## repeat replace list (modtime = "now") where list.name = @list_name
467 return(SMS_SUCCESS);
468##}
469
470set_list_modtime_by_id(q, argv)
471 struct query *q;
472 char *argv[];
473##{
474## int list_id;
475
476 list_id = *(int *)argv[0];
477## repeat replace list (modtime = "now") where list.#list_id = @list_id
478 return(SMS_SUCCESS);
479##}
480
481set_finger_modtime(q, argv)
482 struct query *q;
483 char *argv[];
484##{
485## int users_id;
486
487 users_id = *(int *)argv[0];
488## repeat replace f (modtime = "now") where f.#users_id = @users_id
489 return(SMS_SUCCESS);
490##}
491
30967516 492/**
493 ** set_pop_usage - incr/decr usage count for pop server in serverhosts talbe
494 **
495 ** Inputs:
496 ** q->name - "add_pobox" or "delete_pobox"
497 ** argv[2] - mach_id
498 **
499 ** Description:
500 ** - incr/decr value field in serverhosts table for pop/mach_id
501 **
502 **/
503
504set_pop_usage(q, argv)
505 struct query *q;
506 char *argv[];
507##{
508## int mach_id;
509
510 mach_id = *(int *)argv[2];
511## range of sh is serverhosts
512
513 if (!bcmp(q->name, "add_pobox", 10)) {
514## repeat replace sh (value1 = sh.value1 + 1)
515## where sh.service = "pop" and sh.#mach_id = @mach_id
516 } else if (!bcmp(q->name, "delete_pobox", 13)) {
517## repeat replace sh (value1 = sh.value1 - 1)
518## where sh.service = "pop" and sh.#mach_id = @mach_id
519 }
520
521 return(SMS_SUCCESS);
522##}
92a943d6 523\f
524/**
525 ** add_new_quota
526 ** delete_current_quota - adjust nfsphys values on xxx_quota queries.
527 **
528 ** Inputs:
529 ** argv[0] - mach_id
530 ** argv[1] - device
531 ** argv[2] - users_id
532 ** argv[3] - quota (add_new_quota only)
533 **
534 ** Description:
535 ** delete_current_quota:
536 ** - find nfsquota entry
537 ** - decrement nfsphys.allocated by nfsquota.quota
538 ** add_new_quota
539 ** - increment nfsphys.allocated by quota
540 **
541 **/
542
543add_new_quota(q, argv)
544 struct query *q;
545 register char *argv[];
546##{
547## int mach_id;
548## char *device;
549## int quota;
550
551 mach_id = *(int*)argv[0];
552 device = argv[1];
553 quota = *(int *)argv[3];
554
555## range of np is nfsphys
556## repeat replace np (allocated = np.allocated + @quota)
557## where np.#mach_id = @mach_id and np.#device = @device
558
559 return(SMS_SUCCESS);
560##}
30967516 561
92a943d6 562delete_current_quota(q, argv, cl, access_check)
563 struct query *q;
564 register char *argv[];
565 client *cl;
566 int access_check;
567##{
568## int mach_id;
569## int users_id;
570## char *device;
571## int quota;
572
573 if (access_check) return(SMS_SUCCESS);
574
575 mach_id = *(int *)argv[0];
576 device = argv[1];
577 users_id = *(int *)argv[2];
578
579## range of np is nfsphys
580## range of nq is nfsquota
581## repeat retrieve (quota = nq.#quota)
582## where nq.#mach_id = @mach_id and nq.#device = @device and
583## nq.#users_id = @users_id
584## repeat replace np (allocated = np.allocated - @quota)
585## where np.#mach_id = @mach_id and np.#device = @device
586
587 return(SMS_SUCCESS);
588##}
589\f
05cdd922 590/**
591 ** delete_list_members - called after the delete_list query to clean up
592 ** members table.
593 **
594 ** Inputs: argv[0] - list_id
595 **
596 ** Description:
597 ** - foreach string member: decr string refc; ifzero, delete string
598 ** - delete all members entries for this list_id
599 **
600 **/
601
602delete_list_members(q, argv)
603 struct query *q;
604 register char *argv[];
605##{
606## int list_id;
607## int string_id;
608## int refc;
609## int rowcount;
610 struct save_queue *sq;
611 struct save_queue *sq_create();
612
613 list_id = *(int *)argv[0];
614 sq = sq_create();
615
616## range of m is members
617## repeat retrieve (string_id = m.member_id)
618## where m.#list_id = @list_id and m.member_type = "STRING"
619## {
620 sq_save_data(sq, string_id);
621## }
622
623 while (sq_get_data(sq, &string_id)) {
624## range of s is strings
625## repeat retrieve (refc = s.#refc) where s.#string_id = @string_id
626## inquire_equel (rowcount = "rowcount")
627 if (rowcount == 0) continue;
628 if (--refc == 0) {
629## repeat delete s where s.#string_id = @string_id
630 } else {
631## repeat replace s (#refc = @refc) where s.#string_id = @string_id
632 }
633 }
634 sq_destroy(sq);
635
636## repeat delete m where m.#list_id = @list_id
637
638 return(SMS_SUCCESS);
639##}
92a943d6 640\f
05cdd922 641/**
642 ** grvd_support - Support routine for get_rvd_servers query
643 **
644 ** Inputs:
645 ** q - grvd query structure
646 ** sq - save_queue struture: contains list of {machine, oper_acl_id,
647 ** admin_acl_id, shutdown_acl_id} records.
648 ** v - validate structure (not used)
649 ** action - action routine
650 ** actarg - action routine argument
651 **
652 ** Description:
653 ** - translate acl_ids to list names
654 **
655 **/
656
657grvd_support(q, sq, v, action, actarg)
658 struct query *q;
659 struct save_queue *sq;
660 struct validate *v;
661 int (*action)();
662 int actarg;
663##{
664 char **argv;
665 char *targv[4];
666## char oper[33];
667## char admin[33];
668## char shutdown[33];
669## int list_id;
670
30967516 671 targv[0] = oper;
672 targv[1] = admin;
673 targv[2] = shutdown;
05cdd922 674
675## range of l is list
676
677 while (sq_get_data(sq, &argv)) {
30967516 678 sscanf(argv[0], "%d", &list_id);
05cdd922 679## repeat retrieve (oper = l.name) where l.#list_id = @list_id
30967516 680 sscanf(argv[1], "%d", &list_id);
05cdd922 681## repeat retrieve (admin = l.name) where l.#list_id = @list_id
30967516 682 sscanf(argv[2], "%d", &list_id);
05cdd922 683## repeat retrieve (shutdown = l.name) where l.#list_id = @list_id
684
30967516 685 (*action)(3, targv, actarg);
05cdd922 686 free(argv[0]);
687 free(argv[1]);
688 free(argv[2]);
05cdd922 689 }
690
691 sq_destroy(sq);
692 return(SMS_SUCCESS);
693##}
694
92a943d6 695gars_support(q, sq, v, action, actarg)
696 struct query *q;
697 struct save_queue *sq;
698 struct validate *v;
699 int (*action)();
700 int actarg;
701##{
702 char **argv;
703 char *targv[4];
704## char oper[33];
705## char admin[33];
706## char shutdown[33];
707## int list_id;
708
709 targv[1] = oper;
710 targv[2] = admin;
711 targv[3] = shutdown;
712
713## range of l is list
714
715 while (sq_get_data(sq, &argv)) {
716 sscanf(argv[1], "%d", &list_id);
717## repeat retrieve (oper = l.name) where l.#list_id = @list_id
718 sscanf(argv[2], "%d", &list_id);
719## repeat retrieve (admin = l.name) where l.#list_id = @list_id
720 sscanf(argv[3], "%d", &list_id);
721## repeat retrieve (shutdown = l.name) where l.#list_id = @list_id
722
723 targv[0] = argv[0];
724 (*action)(4, targv, actarg);
725 free(argv[0]);
726 free(argv[1]);
727 free(argv[2]);
728 free(argv[3]);
729 }
730
731 sq_destroy(sq);
732 return(SMS_SUCCESS);
733##}
734\f
05cdd922 735/**
736 ** set_next_object_id - set next object id in values table
737 **
738 ** Inputs: object - object name in values table
739 **
740 ** - called before an APPEND operation to set the next object id to
741 ** be used for the new record
742 **
743 **/
744
745set_next_object_id(object)
746 char *object;
747##{
748## char *name;
05cdd922 749
750 name = object;
751## range of v is values
30967516 752## repeat replace v (value = v.value + 1) where v.#name = @name
753 return(SMS_SUCCESS);
754##}
755
756/**
757 ** get_query_need - check modtime of query's associated table against given
758 ** time and return true if greater (false if not)
759 **
760 ** Inputs:
761 ** argv[0] - query name
762 ** argv[1] - time to compare against
763 **
764 **/
765
766get_query_need(q, argv, action, actarg)
767 struct query *q;
768 register char *argv[];
769 int (*action)();
770##{
771 struct query *q1;
772## char *last_get_time;
773## char *table;
774## int need;
775 char *result;
776 struct query *get_query_by_name();
777
778 q1 = get_query_by_name(argv[0]);
779
780 last_get_time = argv[1];
781 table = q1->rtable;
782
92a943d6 783 if (q1->type != RETRIEVE) return(SMS_NO_MATCH);
30967516 784
785## range of tbs is tblstats
786## repeat retrieve (need = any(tbs.modtime where tbs.#table = @table and
787## tbs.modtime > @last_get_time))
788
789 result = (need) ? "true" : "false";
790 (*action)(1, &result, actarg);
05cdd922 791 return(SMS_SUCCESS);
792##}
793
92a943d6 794/**
795 ** get_list_is_group
796 ** get_list_is_maillist
797 **
798 ** Inputs:
799 ** argv[0] - list_id
800 **
801 ** Returns:
802 ** {true | false}
803 **
804 **/
805
806get_list_is_group(q, argv, action, actarg)
807 struct query *q;
808 char *argv[];
809 int (*action)();
810 int actarg;
811##{
812## int exists;
813## int list_id;
814 char *result;
815
816 list_id = *(int *)argv[0];
817
818## range of g is groups
819## repeat retrieve (exists = any(g.#list_id where g.#list_id = @list_id))
820
821 result = (exists) ? "true" : "false";
822 (*action)(1, &result, actarg);
823 return(SMS_SUCCESS);
824##}
825
826get_list_is_maillist(q, argv, action, actarg)
827 struct query *q;
828 char *argv[];
829 int (*action)();
830 int actarg;
831##{
832## int exists;
833## int list_id;
834 char *result;
835
836 list_id = *(int *)argv[0];
837
838## range of ml is maillists
839## repeat retrieve (exists = any(ml.#list_id where ml.#list_id = @list_id))
840
841 result = (exists) ? "true" : "false";
842 (*action)(1, &result, actarg);
843 return(SMS_SUCCESS);
844##}
845
05cdd922 846\f
847/**
848 ** add_locker - special query routine for creating a user locker
849 **
850 ** Inputs:
851 ** argv[0] - users_id
852 ** argv[1] - machine_id
853 ** argv[2] - device
854 ** argv[3] - initial quota
855 **
856 ** Description:
857 ** - get prefix directory (dir) for mount point on specified machine/device
858 ** - create filesys entry (label=<login>, type=NFS, machine=<machine>,
859 ** mount=<dir>/<login>, access=w, acl=dbadmin)
860 ** - increment allocated in nfsphys by quota
861 ** - create nfsquota entry
862 **
863 ** Errors:
864 ** - SMS_NFSPHYS - machine/device does not exist in nfsphys
865 ** - SMS_FILESYS_EXISTS - file system already exists
866 **
867 **/
868
869add_locker(q, argv)
870 register struct query *q;
871 char *argv[];
872##{
873## int users_id;
874## int mach_id;
875## char *device;
876## int quota;
877## int rowcount;
30967516 878## char login[9];
05cdd922 879## char dir[32];
880## int allocated;
881## char locker[64];
882## char mount[64];
883## int user_acl;
884
885 /* copy arguments */
886 users_id = *(int *)argv[0];
887 mach_id = *(int *)argv[1];
888 device = argv[2];
889 sscanf(argv[3], "%d", &quota);
890
891## range of u is users
892## range of f is filesys
893## range of np is nfsphys
30967516 894## range of tbs is tblstats
05cdd922 895
896 /* get login name */
897## repeat retrieve (login = u.#login) where u.#users_id = @users_id
898
899 /* get user's acl id */
900## repeat retrieve (user_acl = list.list_id) where list.name = @login
901
902 /* get filesystem directory prefix; give error if machine/device
903 pair not in nfsphys table */
247969d5 904 printf("np.mach_id = %d and np.device = %s\n", mach_id, device);
905
05cdd922 906## repeat retrieve (dir = np.#dir, allocated = np.#allocated)
92a943d6 907## where np.#mach_id = @mach_id and np.#device = @device
05cdd922 908## inquire_equel (rowcount = "rowcount")
909 if (rowcount == 0) return(SMS_NFSPHYS);
910
911 /* make sure a filesys with user's name does not already exist */
912## repeat retrieve (rowcount = any(f.label where f.label = @login))
913 if (rowcount != 0) return(SMS_FILESYS_EXISTS);
914
915 /* create a new filesys */
916 sprintf(locker, "%s/%s", dir, login);
917 sprintf(mount, "/mit/%s", login);
918## repeat append filesys
7195989f 919## (#label = @login, type = "NFS", #mach_id = @mach_id,
05cdd922 920## name = @locker, access = "w", order = 1, #mount = @mount,
921## acl_id = @user_acl)
30967516 922## repeat replace tbs (appends = tbs.appends + 1, modtime = "now")
923## where tbs.table = "filesys"
05cdd922 924
925 /* increment usage count in nfsphys table */
926 allocated += quota;
927## replace np (#allocated = allocated)
928## where np.#mach_id = mach_id and np.#device = device
30967516 929## repeat replace tbs (updates = tbs.updates + 1, modtime = "now")
930## where tbs.table = "nfsphys"
05cdd922 931
932 /* create nfsquota entry */
933## append nfsquota (#users_id = users_id, #mach_id = mach_id,
7195989f 934## #device = device, #quota = quota)
3b2ceb9a 935## repeat replace tbs (appends = tbs.appends + 1, modtime = "now")
30967516 936## where tbs.table = "nfsquota"
937
938 return(SMS_SUCCESS);
939##}
940
941/**
942 ** delete_locker - special query routine for deleting a user locker
943 **
944 ** Inputs:
945 ** argv[0] - users_id
946 ** argv[1] - machine_id
947 ** argv[2] - device
948 ** argv[3] - quota
949 **
950 ** Description:
951 ** - delete filesys entry (label=<login>)
952 ** - decrement allocated in nfsphys by quota
953 ** - delete nfsquota entry
954 **
955 ** Errors:
956 ** - SMS_FILESYS - no filesys exists for user
957 **
958 **/
959
960delete_locker(q, argv)
961 register struct query *q;
962 register char *argv[];
963##{
964## int users_id;
965## int mach_id;
966## char *device;
967## int quota;
968## int rowcount;
969## char login[9];
970
971 /* copy arguments */
972 users_id = *(int *)argv[0];
973 mach_id = *(int *)argv[1];
974 device = argv[2];
975 sscanf(argv[3], "%d", &quota);
976
977## range of u is users
978## range of f is filesys
979## range of np is nfsphys
980## range of nq is nfsquota
981## range of tbs is tblstats
982
983 /* get login name */
984## repeat retrieve (login = u.#login) where u.#users_id = @users_id
985
986 /* delete the filesys entry */
987## repeat delete f where f.label = @login
988## inquire_equel (rowcount = "rowcount")
989 if (rowcount == 0) return(SMS_FILESYS);
990## repeat replace tbs (deletes = tbs.deletes + 1, modtime = "now")
991## where tbs.table = "filesys"
992
993 /* decrement usage count in nfsphys table */
994## replace np (#allocated = np.#allocated - quota)
995## where np.#mach_id = mach_id and np.#device = device
996## repeat replace tbs (updates = tbs.updates + 1, modtime = "now")
997## where tbs.table = "nfsphys"
998
999 /* delete nfsquota entry */
1000## delete nq where nq.#users_id = users_id and nq.#mach_id = mach_id and
1001## nq.#device = device
1002## repeat replace tbs (deletes = tbs.deletes + 1, modtime = "now")
1003## where tbs.table = "nfsquota"
05cdd922 1004
1005 return(SMS_SUCCESS);
1006##}
92a943d6 1007\f
1008/**
1009 ** add_user_group - create a group for a user and add user to group
1010 **
1011 ** Inputs:
1012 ** argv[0] - login
1013 **
1014 ** Description:
1015 ** - verify specified user exists
1016 ** - create a list of same name as user
1017 ** - add user as a member of the list
1018 **
1019 **/
1020
1021add_user_group(q, argv)
1022 struct query *q;
1023 char *argv[];
1024##{
1025## char *login;
1026## int exists;
1027## int users_id;
1028## int list_id;
1029## int gid;
1030
1031 login = argv[0];
1032
1033 /* verify user exists */
1034## repeat retrieve (users_id = users.#users_id) where users.#login = @login
1035## inquire_equel (exists = "rowcount")
1036 if (exists != 1) return(SMS_USER);
1037
1038 /* verify list does not exist */
1039## repeat retrieve (exists = any(list.name where list.name = @login))
1040 if (exists) return(SMS_LIST);
1041
1042 /* get new list_id */
1043## repeat retrieve (list_id = values.value) where values.name = "list_id"
1044 list_id++;
1045## repeat replace values (value = @list_id) where values.name = "list_id"
1046
1047 /* create the list */
1048## repeat append list (name = @login, #list_id = @list_id, flags = 1,
1049## desc = "User Group", acl_id = @list_id,
1050## expdate = "today" + "5 years", modtime = "now")
1051
1052 /* add user to list */
1053## repeat append members (#list_id = @list_id, member_type = "USER",
1054## member_id = @users_id)
1055
1056 /* get new gid */
1057## range of g is groups
1058## range of v is values
1059## repeat retrieve (gid = v.value) where v.name = "gid"
1060 exists = 1;
1061 while (exists) {
1062 gid++;
1063## repeat retrieve (exists = any(g.#gid where g.#gid = @gid))
1064 }
1065## repeat replace v (value = @gid) where v.name = "gid"
1066
1067 /* add list to group table */
1068## repeat append groups (#list_id = @list_id, ltid = list.tid, #gid = @gid)
1069## where list.#list_id = @list_id
1070
1071 /* and we're done */
1072 return(SMS_SUCCESS);
1073##}
1074
05cdd922 1075\f
c2408bd5 1076/**
1077 ** get_members_of_list - optimized query for retrieval of list members
1078 **
1079 ** Inputs:
1080 ** argv[0] - list_id
1081 **
1082 ** Description:
1083 ** - retrieve USER members, then LIST members, then STRING members
1084 **
1085 **/
1086
1087get_members_of_list(q, argv, action, actarg)
1088 struct query *q;
1089 char *argv[];
1090 int (*action)();
1091 int actarg;
1092##{
1093## int list_id;
1094## char member_name[129];
1095 char *targv[2];
1096
1097 list_id = *(int *)argv[0];
1098 targv[0] = "USER";
1099 targv[1] = member_name;
1100
1101## range of m is members
1102## repeat retrieve (member_name = users.login)
1103## where m.#list_id = @list_id and m.member_type = "USER"
1104## and m.member_id = users.users_id
92a943d6 1105## sort by #member_name
c2408bd5 1106## {
1107 (*action)(2, targv, actarg);
1108## }
1109
1110 targv[0] = "LIST";
1111## repeat retrieve (member_name = list.name)
1112## where m.#list_id = @list_id and m.member_type = "LIST"
1113## and m.member_id = list.#list_id
92a943d6 1114## sort by #member_name
c2408bd5 1115## {
1116 (*action)(2, targv, actarg);
1117## }
1118
1119 targv[0] = "STRING";
1120## repeat retrieve (member_name = strings.string)
1121## where m.#list_id = @list_id and m.member_type = "STRING"
1122## and m.member_id = strings.string_id
92a943d6 1123## sort by #member_name
c2408bd5 1124## {
1125 (*action)(2, targv, actarg);
1126## }
1127
1128 return(SMS_SUCCESS);
1129##}
1130
1131/**
92a943d6 1132 ** get_groups_of_user - optimized query for retrieval of all groups to
1133 ** which a user belongs
1134 **
1135 **/
1136
1137get_groups_of_user(q, argv, action, actarg)
1138 struct query *q;
1139 char *argv[];
1140 int (*action)();
1141 int actarg;
1142##{
1143## int users_id;
1144## char list_name[33];
1145## char gid[11];
1146## int rowcount;
1147 char *targv[2];
1148
1149 users_id = *(int *)argv[0];
1150 targv[0] = list_name;
1151 targv[1] = gid;
1152
1153## range of m is members
1154
1155## repeat retrieve (list_name = list.name, gid = text(groups.#gid))
1156## where m.member_id = @users_id and m.member_type = "USER" and
1157## m.list_id = groups.list_id and groups.ltid = list.tid
1158## sort by #list_name
1159## {
1160 (*action)(2, targv, actarg);
1161## }
1162## inquire_equel (rowcount = "rowcount")
1163
1164 return ((rowcount = 0) ? SMS_NO_MATCH : SMS_SUCCESS);
1165##}
1166\f
1167/**
1168 ** get_all_poboxes - optimized query for retrieval of all poboxes
c2408bd5 1169 **
1170 ** Description:
1171 ** - retrieve LOCAL boxes, then POP boxes, then FOREIGN boxes
1172 **
1173 **/
1174
1175get_all_poboxes(q, argv, action, actarg)
1176 struct query *q;
1177 char *argv[];
1178 int (*action)();
1179 int actarg;
1180##{
1181## char login[9];
1182## char machine[129];
1183## char box[129];
1184 char *targv[4];
1185
1186 targv[0] = login;
1187 targv[2] = machine;
1188 targv[3] = box;
1189
1190 targv[1] = "LOCAL";
1191## range of p is pobox
1192## repeat retrieve (login=users.#login, machine = #machine.name, box=p.#box)
1193## where p.type = "LOCAL" and p.users_id = users.users_id
1194## and p.mach_id = #machine.mach_id
1195## {
1196 (*action)(4, targv, actarg);
1197## }
1198
1199 targv[1] = "POP";
1200## repeat retrieve (login=users.#login, machine = #machine.name, box=p.#box)
1201## where p.type = "POP" and p.users_id = users.users_id
1202## and p.mach_id = #machine.mach_id
1203## {
1204 (*action)(4, targv, actarg);
1205## }
1206
1207 targv[1] = "FOREIGN";
1208## repeat retrieve (login=users.#login, machine=strings.string, box=p.#box)
1209## where p.type = "FOREIGN" and p.users_id = users.users_id
1210## and p.mach_id = strings.string_id
1211## {
1212 (*action)(4, targv, actarg);
1213## }
1214
1215 return(SMS_SUCCESS);
1216##}
1217\f
05cdd922 1218/* Validation Routines */
1219
1220validate_row(q, argv, v)
1221 register struct query *q;
1222 char *argv[];
1223 register struct validate *v;
1224##{
1225## char *rvar;
1226## char *table;
1227## char *name;
1228## char qual[128];
1229## int rowcount;
1230
1231 /* build where clause */
1232 build_qual(v->qual, v->argc, argv, qual);
1233
1234 /* setup ingres variables */
1235 rvar = q->rvar;
1236 table = q->rtable;
1237 name = v->field;
1238
b4182127 1239 if (log_flags & LOG_RES)
1240 /* tell the logfile what we're doing */
1241 com_err(whoami, 0, "validating row: %s", qual);
1242
05cdd922 1243 /* look for the record */
1244## range of rvar is table
1245## retrieve (rowcount = count(rvar.name where qual))
05cdd922 1246 if (rowcount == 0) return(SMS_NO_MATCH);
1247 if (rowcount > 1) return(SMS_NOT_UNIQUE);
1248 return(SMS_EXISTS);
1249##}
1250
1251validate_fields(q, argv, vo, n)
1252 struct query *q;
1253 register char *argv[];
1254 register struct valobj *vo;
1255 register int n;
1256{
1257 register int status;
05cdd922 1258
1259 while (--n >= 0) {
1260 switch (vo->type) {
1261 case V_NAME:
92a943d6 1262 if (log_flags & LOG_RES)
b4182127 1263 com_err(whoami, 0, "validating %s in %s: %s",
05cdd922 1264 vo->namefield, vo->table, argv[vo->index]);
05cdd922 1265 status = validate_name(argv, vo);
1266 break;
1267
1268 case V_ID:
92a943d6 1269 if (log_flags & LOG_RES)
b4182127 1270 com_err(whoami, 0, "validating %s in %s: %s",
05cdd922 1271 vo->idfield, vo->table, argv[vo->index]);
05cdd922 1272 status = validate_id(argv, vo);
1273 break;
1274
92a943d6 1275 case V_DATE:
1276 if (log_flags & LOG_RES)
1277 com_err(whoami, 0, "validating date: %s", argv[vo->index]);
1278 status = validate_date(argv, vo);
1279 break;
1280
05cdd922 1281 case V_TYPE:
92a943d6 1282 if (log_flags & LOG_RES)
b4182127 1283 com_err(whoami, 0, "validating %s type: %s",
05cdd922 1284 vo->table, argv[vo->index]);
05cdd922 1285 status = validate_type(argv, vo);
1286 break;
1287
1288 case V_TYPEDATA:
92a943d6 1289 if (log_flags & LOG_RES)
1290 com_err(whoami, 0, "validating typed data (%s): %s",
1291 argv[vo->index - 1], argv[vo->index]);
05cdd922 1292 status = validate_typedata(q, argv, vo);
1293 break;
1294
1295 case V_FOLLOWUP:
1296 status = SMS_EXISTS;
1297 break;
1298
92a943d6 1299 case V_SORT:
1300 status = SMS_EXISTS;
1301 break;
1302
05cdd922 1303 }
1304
1305 if (status != SMS_EXISTS) return(status);
1306 vo++;
1307 }
1308
1309 return(SMS_SUCCESS);
1310}
1311
1312validate_id(argv, vo)
1313 char *argv[];
1314 register struct valobj *vo;
1315##{
1316## char *name;
1317## char *table;
1318## char *namefield;
1319## char *idfield;
1320## int id;
1321## int rowcount;
1322
1323 name = argv[vo->index];
1324 table = vo->table;
1325 namefield = vo->namefield;
1326 idfield = vo->idfield;
1327## retrieve (id = table.idfield) where table.namefield = name
1328## inquire_equel (rowcount = "rowcount")
1329 if (rowcount != 1) return(vo->error);
1330 *(int *)argv[vo->index] = id;
1331 return(SMS_EXISTS);
1332##}
1333
1334validate_name(argv, vo)
1335 char *argv[];
1336 register struct valobj *vo;
1337##{
1338## char *name;
1339## char *table;
1340## char *namefield;
1341## int rowcount;
1342
1343 name = argv[vo->index];
1344 table = vo->table;
1345 namefield = vo->namefield;
1346## retrieve (rowcount = countu(table.namefield
1347## where table.namefield = name))
1348 return ((rowcount == 1) ? SMS_EXISTS : vo->error);
1349##}
1350
92a943d6 1351validate_date(argv, vo)
1352 char *argv[];
1353 struct valobj *vo;
1354##{
1355## char *idate;
1356## double dd;
1357## int errorno;
1358
1359 idate = argv[vo->index];
1360
1361## retrieve (dd = interval("years", date(idate) - date("today")))
1362## inquire_equel (errorno = "errorno")
1363 if (errorno != 0 || dd > 5.0) return(SMS_DATE);
1364 return(SMS_SUCCESS);
1365##}
1366
05cdd922 1367validate_type(argv, vo)
1368 char *argv[];
1369 register struct valobj *vo;
1370##{
1371## char *typename;
1372## char *value;
1373## int rowcount;
1374 register char *c;
1375
1376 typename = vo->table;
1377 value = argv[vo->index];
1378
1379 /* uppercase type fields */
1380 for (c = value; *c; c++) if (islower(*c)) *c = toupper(*c);
1381
1382## range of a is alias
1383## repeat retrieve (rowcount = count(a.trans where a.name = @typename and
1384## a.type = "TYPE" and
1385## a.trans = @value))
1386 return ((rowcount == 1) ? SMS_EXISTS : vo->error);
1387##}
1388
1389/* validate member or type-specific data field */
1390
1391validate_typedata(q, argv, vo)
1392 register struct query *q;
1393 register char *argv[];
1394 register struct valobj *vo;
1395##{
1396## char *name;
1397## char *field_type;
1398## char data_type[17];
1399## int id;
1400## int refc;
1401## int rowcount;
1402
1403 /* get named object */
1404 name = argv[vo->index];
1405
1406 /* get field type string (known to be at index-1) */
1407 field_type = argv[vo->index-1];
1408
1409 /* get corresponding data type associated with field type name */
1410## repeat retrieve (data_type = alias.trans)
1411## where alias.#name = @field_type and alias.type = "TYPEDATA"
1412## inquire_equel (rowcount = "rowcount")
1413 if (rowcount != 1) return(SMS_TYPE);
1414
1415 /* now retrieve the record id corresponding to the named object */
1416
1417 if (!strcmp(data_type, "user")) {
1418 /* USER */
1419## repeat retrieve (id = users.users_id) where users.login = @name
1420## inquire_equel (rowcount = "rowcount")
1421 if (rowcount != 1) return(SMS_USER);
1422
1423 } else if (!strcmp(data_type, "list")) {
1424 /* LIST */
1425## repeat retrieve (id = list.list_id) where list.#name = @name
1426## inquire_equel (rowcount = "rowcount")
1427 if (rowcount != 1) return(SMS_LIST);
1428
1429 } else if (!strcmp(data_type, "machine")) {
1430 /* MACHINE */
1431## repeat retrieve (id = machine.mach_id) where machine.#name = @name
1432## inquire_equel (rowcount = "rowcount")
1433 if (rowcount != 1) return(SMS_MACHINE);
1434
1435 } else if (!strcmp(data_type, "string")) {
1436 /* STRING */
1437## range of s is strings
1438## repeat retrieve (id = s.string_id, refc = s.#refc)
1439## where s.string = @name
1440## inquire_equel (rowcount = "rowcount")
1441 if (rowcount == 0) {
1442 if (q->type != APPEND) return(SMS_STRING);
1443## range of v is values
1444## retrieve (id = v.value) where v.#name = "strings_id"
1445 id++;
1446## replace v (value = id) where v.#name = "strings_id"
1447## append to strings (string_id = id, string = name, #refc = 1)
1448 } else if (rowcount == 1) {
1449 if (q->type == APPEND || q->type == DELETE) {
1450 refc += (q->type == APPEND) ? 1 : -1;
1451 if (refc > 0) {
1452## replace s (#refc = refc) where s.string_id = id
1453 } else {
1454## delete s where s.string_id = id
1455 }
1456 }
1457 }
1458 } else {
1459 return(SMS_TYPE);
1460 }
1461
1462 /* now set value in argv */
1463 *(int *)argv[vo->index] = id;
1464
1465 return (SMS_EXISTS);
1466##}
1467
1468\f
1469translate_ids(q, sq, v, action, actarg)
1470 register struct query *q;
1471 register struct save_queue *sq;
1472 register struct validate *v;
1473 register int (*action)();
1474 int actarg;
1475##{
1476## char *name;
1477## char *field_type;
1478## char data_type[17];
1479## int id;
1480## int rowcount;
1481 register int i;
1482 struct valobj *vo;
1483 char **argv;
1484
1485 for (i = 0; i < v->objcnt; i++) {
1486 vo = &v->valobj[i];
1487 if (vo->type == V_FOLLOWUP) break;
1488 }
1489
1490 /* for each row */
1491 while (sq_get_data(sq, &argv)) {
1492
1493 /* get object id */
1494 i = vo->index;
1495 sscanf(argv[i], "%d", &id);
1496 free(argv[i]);
1497 name = (char *)malloc(129);
1498 argv[i] = name;
1499
1500 /* get field type string (known to be at index-1) */
1501 field_type = argv[vo->index-1];
1502
1503 /* get corresponding data type associated with field type name */
1504## repeat retrieve (data_type = alias.trans)
1505## where alias.#name = @field_type and alias.type = "TYPEDATA"
1506## inquire_equel (rowcount = "rowcount")
1507 if (rowcount != 1) {
1508 sprintf(name, "%d", id);
1509 (*action)(q->vcnt, argv, actarg);
1510 continue;
1511 }
1512
1513 /* retrieve object name */
1514
1515 if (!strcmp(data_type, "user")) {
1516 /* USER */
1517## repeat retrieve (name = users.login) where users.users_id = @id
1518## inquire_equel (rowcount = "rowcount")
1519
1520 } else if (!strcmp(data_type, "list")) {
1521 /* LIST */
1522## repeat retrieve (name = list.#name) where list.list_id = @id
1523## inquire_equel (rowcount = "rowcount")
1524
1525 } else if (!strcmp(data_type, "machine")) {
1526 /* MACHINE */
1527## repeat retrieve (name = machine.#name) where machine.mach_id = @id
1528## inquire_equel (rowcount = "rowcount")
1529
1530 } else if (!strcmp(data_type, "string")) {
1531 /* STRING */
1532## repeat retrieve (name = strings.string)
1533## where strings.string_id = @id
1534## inquire_equel (rowcount = "rowcount")
1535
1536 } else {
1537 rowcount = 0;
1538 }
1539
1540 /* if there wasn't a corresponding object name, then use the id */
1541 if (rowcount != 1) sprintf(name, "%d", id);
1542
1543 /* send the data */
1544 (*action)(q->vcnt, argv, actarg);
1545
1546 /* free saved data */
1547 for (i = 0; i < q->vcnt; i++)
1548 free(argv[i]);
1549 free(argv);
1550 }
1551
1552 sq_destroy(sq);
1553 return (SMS_SUCCESS);
1554##}
1555\f
1556/*
1557 * Local Variables:
1558 * mode: c
1559 * c-indent-level: 4
1560 * c-continued-statement-offset: 4
1561 * c-brace-offset: -4
1562 * c-argdecl-indent: 4
1563 * c-label-offset: -4
1564 * End:
1565 */
This page took 0.410099 seconds and 5 git commands to generate.