6 * Copyright (C) 1987 by the Massachusetts Institute of Technology
9 * Revision 1.1 1987-07-29 15:13:57 wesommer
15 static char *rcsid_qsupport_qc = "$Header$";
19 #include "sms_server.h"
26 /* Specialized Access Routines */
29 ** access_user - verify that client name equals specified login name
31 ** Used by: update_user_shell
32 ** update_finger_by_login
34 ** - since field validation routines are called first, a users_id is
35 ** now in argv[0] instead of the login name. Therefore, we must
36 ** convert the client name to a users_id.
39 access_user(q, argv, cl)
44 register struct krbname *krb;
49 client_name = cl->kname.name;
50 ## repeat retrieve (client_id = users.users_id)
51 ## where users.login = @client_name
52 ## inquire_equel (rowcount = "rowcount")
53 if (rowcount != 1) return(SMS_PERM);
54 if (client_id != *(int *)argv[0]) return(SMS_PERM);
60 ** access_list - check access for adding or deleting list members
62 ** Inputs: argv[0] - list_id
63 ** cl->krb.name - client name
65 ** - check that client is a member of the access control list
66 ** - OR, if q->shortname == {amtl | dfml} and
67 ** if list.flags & LF_PUBLIC, allow access if client = member
71 access_list(q, argv, cl)
85 list_id = *(int *)argv[0];
86 ## repeat retrieve (acl_id = list.#acl_id, flags = list.#flags)
87 ## where list.#list_id = @list_id
89 /* parse client structure */
90 status = get_client(cl, &client_type, &client_id);
91 if (status != SMS_SUCCESS) return(status);
93 /* if amtl or dmfl and list is public allow client to add or delete self */
94 if (!bcmp("amtl", q->shortname, 4) || !bcmp("dmfl", q->shortname, 4)) {
95 if ((flags & LF_PUBLIC) && !bcmp("USER", argv[1], 4)) {
96 member_id = *(int *)argv[2];
97 if (member_id == client_id) return(SMS_SUCCESS);
101 /* check for client in access control list */
102 exists = find_member(acl_id, client_type, client_id, 0);
103 if (!exists) return(SMS_PERM);
109 ** Setup routine for add_user
111 ** Inputs: argv[0] - login
116 ** - if argv[1] == "#" then set argv[1] = next(uid)
117 ** - if argv[0] == "#" then set argv[0] = "#<uid>"
121 setup_add_user(q, argv, cl, access_check)
123 register char *argv[];
130 if (access_check) return(SMS_SUCCESS);
132 if (!bcmp(argv[1], "#", 2)) {
133 ## range of u is users
134 ## range of v is values
135 ## repeat retrieve (nuid = v.value) where v.name = "uid"
139 ## repeat retrieve (exists = any(u.#uid where u.#uid = @nuid))
141 ## repeat replace v (value = @nuid) where v.name = "uid"
142 sprintf(argv[1], "%d", nuid);
145 if (!bcmp(argv[0], "#", 2)) {
146 sprintf(argv[0], "#%s", argv[1]);
153 ** Setup routine for add_group
157 ** Description: allocate next gid and store in values table
161 setup_add_group(q, argv, cl, access_check)
170 if (access_check) return(SMS_SUCCESS);
172 ## range of g is groups
173 ## range of v is values
174 ## repeat retrieve (ngid = v.value) where v.name = "gid"
178 ## repeat retrieve (exists = any(g.#gid where g.#gid = @ngid))
181 ## repeat replace v (value = @ngid) where v.name = "gid"
185 /* Followup Routines */
187 set_user_modtime(q, argv)
194 ## repeat replace u (modtime = "now") where u.#login = @login
198 set_user_modtime_by_id(q, argv)
204 users_id = *(int *)argv[0];
205 ## repeat replace users (modtime = "now") where users.#users_id = @users_id
209 set_list_modtime(q, argv)
216 ## repeat replace list (modtime = "now") where list.name = @list_name
220 set_list_modtime_by_id(q, argv)
226 list_id = *(int *)argv[0];
227 ## repeat replace list (modtime = "now") where list.#list_id = @list_id
231 set_finger_modtime(q, argv)
237 users_id = *(int *)argv[0];
238 ## repeat replace f (modtime = "now") where f.#users_id = @users_id
243 ** delete_list_members - called after the delete_list query to clean up
246 ** Inputs: argv[0] - list_id
249 ** - foreach string member: decr string refc; ifzero, delete string
250 ** - delete all members entries for this list_id
254 delete_list_members(q, argv)
256 register char *argv[];
262 struct save_queue *sq;
263 struct save_queue *sq_create();
265 list_id = *(int *)argv[0];
268 ## range of m is members
269 ## repeat retrieve (string_id = m.member_id)
270 ## where m.#list_id = @list_id and m.member_type = "STRING"
272 sq_save_data(sq, string_id);
275 while (sq_get_data(sq, &string_id)) {
276 ## range of s is strings
277 ## repeat retrieve (refc = s.#refc) where s.#string_id = @string_id
278 ## inquire_equel (rowcount = "rowcount")
279 if (rowcount == 0) continue;
281 ## repeat delete s where s.#string_id = @string_id
283 ## repeat replace s (#refc = @refc) where s.#string_id = @string_id
288 ## repeat delete m where m.#list_id = @list_id
294 ** grvd_support - Support routine for get_rvd_servers query
297 ** q - grvd query structure
298 ** sq - save_queue struture: contains list of {machine, oper_acl_id,
299 ** admin_acl_id, shutdown_acl_id} records.
300 ** v - validate structure (not used)
301 ** action - action routine
302 ** actarg - action routine argument
305 ** - translate acl_ids to list names
309 grvd_support(q, sq, v, action, actarg)
311 struct save_queue *sq;
320 ## char shutdown[33];
327 ## range of l is list
329 while (sq_get_data(sq, &argv)) {
330 sscanf(argv[1], "%d", &list_id);
331 ## repeat retrieve (oper = l.name) where l.#list_id = @list_id
332 sscanf(argv[2], "%d", &list_id);
333 ## repeat retrieve (admin = l.name) where l.#list_id = @list_id
334 sscanf(argv[3], "%d", &list_id);
335 ## repeat retrieve (shutdown = l.name) where l.#list_id = @list_id
338 (*action)(4, targv, actarg);
350 ** set_next_object_id - set next object id in values table
352 ** Inputs: object - object name in values table
354 ** - called before an APPEND operation to set the next object id to
355 ** be used for the new record
359 set_next_object_id(object)
366 ## range of v is values
367 ## repeat retrieve (id = v.value) where v.#name = @name
369 ## repeat replace v (value = @id) where v.#name = @name
375 ** add_locker - special query routine for creating a user locker
378 ** argv[0] - users_id
379 ** argv[1] - machine_id
381 ** argv[3] - initial quota
384 ** - get prefix directory (dir) for mount point on specified machine/device
385 ** - create filesys entry (label=<login>, type=NFS, machine=<machine>,
386 ** mount=<dir>/<login>, access=w, acl=dbadmin)
387 ** - increment allocated in nfsphys by quota
388 ** - create nfsquota entry
391 ** - SMS_NFSPHYS - machine/device does not exist in nfsphys
392 ** - SMS_FILESYS_EXISTS - file system already exists
397 register struct query *q;
413 users_id = *(int *)argv[0];
414 mach_id = *(int *)argv[1];
416 sscanf(argv[3], "%d", "a);
418 ## range of u is users
419 ## range of f is filesys
420 ## range of np is nfsphys
423 ## repeat retrieve (login = u.#login) where u.#users_id = @users_id
425 /* get user's acl id */
426 ## repeat retrieve (user_acl = list.list_id) where list.name = @login
428 /* get filesystem directory prefix; give error if machine/device
429 pair not in nfsphys table */
430 ## repeat retrieve (dir = np.#dir, allocated = np.#allocated)
431 ## where np.#mach_id = @mach_id and np.#device = device
432 ## inquire_equel (rowcount = "rowcount")
433 if (rowcount == 0) return(SMS_NFSPHYS);
435 /* make sure a filesys with user's name does not already exist */
436 ## repeat retrieve (rowcount = any(f.label where f.label = @login))
437 if (rowcount != 0) return(SMS_FILESYS_EXISTS);
439 /* create a new filesys */
440 sprintf(locker, "%s/%s", dir, login);
441 sprintf(mount, "/mit/%s", login);
442 ## repeat append filesys
443 ## (#users_id = @users_id, type = "NFS", #mach_id = @mach_id,
444 ## name = @locker, access = "w", order = 1, #mount = @mount,
445 ## acl_id = @user_acl)
447 /* increment usage count in nfsphys table */
449 ## replace np (#allocated = allocated)
450 ## where np.#mach_id = mach_id and np.#device = device
452 /* create nfsquota entry */
453 ## append nfsquota (#users_id = users_id, #mach_id = mach_id,
454 ## device = #device, #quota = quota)
459 /* Validation Routines */
461 validate_row(q, argv, v)
462 register struct query *q;
464 register struct validate *v;
472 /* build where clause */
473 build_qual(v->qual, v->argc, argv, qual);
475 /* setup ingres variables */
480 /* tell the logfile what we're doing */
481 com_err(whoami, 0, "validating row");
482 com_err(whoami, 0, qual);
484 /* look for the record */
485 ## range of rvar is table
486 ## retrieve (rowcount = count(rvar.name where qual))
487 com_err(whoami, 0, "row validated");
488 if (rowcount == 0) return(SMS_NO_MATCH);
489 if (rowcount > 1) return(SMS_NOT_UNIQUE);
493 validate_fields(q, argv, vo, n)
495 register char *argv[];
496 register struct valobj *vo;
505 sprintf(buf, "validating %s in %s: %s",
506 vo->namefield, vo->table, argv[vo->index]);
507 com_err(whoami, 0, buf);
508 status = validate_name(argv, vo);
512 sprintf(buf, "validating %s in %s: %s",
513 vo->idfield, vo->table, argv[vo->index]);
514 com_err(whoami, 0, buf);
515 status = validate_id(argv, vo);
519 sprintf(buf, "validating %s type: %s",
520 vo->table, argv[vo->index]);
521 com_err(whoami, 0, buf);
522 status = validate_type(argv, vo);
526 sprintf(buf, "validating type-specific data: %s",
528 com_err(whoami, 0, buf);
529 status = validate_typedata(q, argv, vo);
538 if (status != SMS_EXISTS) return(status);
545 validate_id(argv, vo)
547 register struct valobj *vo;
556 name = argv[vo->index];
558 namefield = vo->namefield;
559 idfield = vo->idfield;
560 ## retrieve (id = table.idfield) where table.namefield = name
561 ## inquire_equel (rowcount = "rowcount")
562 if (rowcount != 1) return(vo->error);
563 *(int *)argv[vo->index] = id;
567 validate_name(argv, vo)
569 register struct valobj *vo;
576 name = argv[vo->index];
578 namefield = vo->namefield;
579 ## retrieve (rowcount = countu(table.namefield
580 ## where table.namefield = name))
581 return ((rowcount == 1) ? SMS_EXISTS : vo->error);
584 validate_type(argv, vo)
586 register struct valobj *vo;
593 typename = vo->table;
594 value = argv[vo->index];
596 /* uppercase type fields */
597 for (c = value; *c; c++) if (islower(*c)) *c = toupper(*c);
599 ## range of a is alias
600 ## repeat retrieve (rowcount = count(a.trans where a.name = @typename and
601 ## a.type = "TYPE" and
602 ## a.trans = @value))
603 return ((rowcount == 1) ? SMS_EXISTS : vo->error);
606 /* validate member or type-specific data field */
608 validate_typedata(q, argv, vo)
609 register struct query *q;
610 register char *argv[];
611 register struct valobj *vo;
615 ## char data_type[17];
620 /* get named object */
621 name = argv[vo->index];
623 /* get field type string (known to be at index-1) */
624 field_type = argv[vo->index-1];
626 /* get corresponding data type associated with field type name */
627 ## repeat retrieve (data_type = alias.trans)
628 ## where alias.#name = @field_type and alias.type = "TYPEDATA"
629 ## inquire_equel (rowcount = "rowcount")
630 if (rowcount != 1) return(SMS_TYPE);
632 /* now retrieve the record id corresponding to the named object */
634 if (!strcmp(data_type, "user")) {
636 ## repeat retrieve (id = users.users_id) where users.login = @name
637 ## inquire_equel (rowcount = "rowcount")
638 if (rowcount != 1) return(SMS_USER);
640 } else if (!strcmp(data_type, "list")) {
642 ## repeat retrieve (id = list.list_id) where list.#name = @name
643 ## inquire_equel (rowcount = "rowcount")
644 if (rowcount != 1) return(SMS_LIST);
646 } else if (!strcmp(data_type, "machine")) {
648 ## repeat retrieve (id = machine.mach_id) where machine.#name = @name
649 ## inquire_equel (rowcount = "rowcount")
650 if (rowcount != 1) return(SMS_MACHINE);
652 } else if (!strcmp(data_type, "string")) {
654 ## range of s is strings
655 ## repeat retrieve (id = s.string_id, refc = s.#refc)
656 ## where s.string = @name
657 ## inquire_equel (rowcount = "rowcount")
659 if (q->type != APPEND) return(SMS_STRING);
660 ## range of v is values
661 ## retrieve (id = v.value) where v.#name = "strings_id"
663 ## replace v (value = id) where v.#name = "strings_id"
664 ## append to strings (string_id = id, string = name, #refc = 1)
665 } else if (rowcount == 1) {
666 if (q->type == APPEND || q->type == DELETE) {
667 refc += (q->type == APPEND) ? 1 : -1;
669 ## replace s (#refc = refc) where s.string_id = id
671 ## delete s where s.string_id = id
679 /* now set value in argv */
680 *(int *)argv[vo->index] = id;
686 translate_ids(q, sq, v, action, actarg)
687 register struct query *q;
688 register struct save_queue *sq;
689 register struct validate *v;
690 register int (*action)();
695 ## char data_type[17];
702 for (i = 0; i < v->objcnt; i++) {
704 if (vo->type == V_FOLLOWUP) break;
708 while (sq_get_data(sq, &argv)) {
712 sscanf(argv[i], "%d", &id);
714 name = (char *)malloc(129);
717 /* get field type string (known to be at index-1) */
718 field_type = argv[vo->index-1];
720 /* get corresponding data type associated with field type name */
721 ## repeat retrieve (data_type = alias.trans)
722 ## where alias.#name = @field_type and alias.type = "TYPEDATA"
723 ## inquire_equel (rowcount = "rowcount")
725 sprintf(name, "%d", id);
726 (*action)(q->vcnt, argv, actarg);
730 /* retrieve object name */
732 if (!strcmp(data_type, "user")) {
734 ## repeat retrieve (name = users.login) where users.users_id = @id
735 ## inquire_equel (rowcount = "rowcount")
737 } else if (!strcmp(data_type, "list")) {
739 ## repeat retrieve (name = list.#name) where list.list_id = @id
740 ## inquire_equel (rowcount = "rowcount")
742 } else if (!strcmp(data_type, "machine")) {
744 ## repeat retrieve (name = machine.#name) where machine.mach_id = @id
745 ## inquire_equel (rowcount = "rowcount")
747 } else if (!strcmp(data_type, "string")) {
749 ## repeat retrieve (name = strings.string)
750 ## where strings.string_id = @id
751 ## inquire_equel (rowcount = "rowcount")
757 /* if there wasn't a corresponding object name, then use the id */
758 if (rowcount != 1) sprintf(name, "%d", id);
761 (*action)(q->vcnt, argv, actarg);
763 /* free saved data */
764 for (i = 0; i < q->vcnt; i++)
770 return (SMS_SUCCESS);
777 * c-continued-statement-offset: 4
779 * c-argdecl-indent: 4