6 * Copyright (C) 1987 by the Massachusetts Institute of Technology
9 * Revision 1.18 1988-01-14 12:00:38 mar
10 * separate access check from setup routine.
11 * make get_query_need be more paranoid
13 Revision 1.17 88/01/04 12:09:00 mar
14 fixup pobox access checking & make id assignment more paranoid (wesommer)
16 Revision 1.16 87/11/12 18:16:56 wesommer
17 Add support for delete_user_by_uid.
19 Check a few return codes.
21 Revision 1.15 87/09/11 15:31:58 wesommer
22 add_user_group modified to side-effect the time for tbs for groups as
23 well as the other things.
25 Revision 1.15 87/09/10 22:44:49 wesommer
26 One more table needs to be modified when adding the user-group.
28 Revision 1.14 87/09/04 17:50:03 mike
29 Renamed delete_list_members to followup_delete_list. New routine removes
30 list from maillists and groups tables in addition to the members table.
32 Added routines validate_label and validate_label_2 used in validating
33 filesys labels for get_filesys and delete_filesys respectively.
35 Revision 1.13 87/09/01 16:24:01 wesommer
36 A list should be considered modified if its acl changes.
38 Revision 1.12 87/08/29 00:05:54 mike
39 Fixed bug in check_nfs.
40 Added code to upcasify machine names in validate_id.
42 Revision 1.11 87/08/28 14:55:45 mike
43 Modified delete_locker to require only one argument, the login name.
44 Modified get_groups_of_all_users and get_all_poboxes to disable INGRES
47 Revision 1.10 87/08/25 15:56:54 mike
48 - Fixed bugs in get_groups_of_all_users
49 - Added tblstats updates to add_user_group
50 - Added routines: add_hostaccess (ashi), delete_hostaccess (dshi),
51 followup_ushp, and followup_usha
53 Revision 1.9 87/08/22 17:41:34 wesommer
54 More of Mike's changes.
56 Revision 1.8 87/08/18 15:05:20 wesommer
57 Fixed definition of add_locker.
59 Revision 1.7 87/08/04 01:49:41 wesommer
62 Revision 1.6 87/08/04 01:10:02 wesommer
63 Changes by mike; checked in prior to my hacking.
65 Revision 1.5 87/07/30 14:54:13 wesommer
66 Added debugging code in an attempt to catch a flakey problem.
68 Revision 1.4 87/07/30 00:30:21 wesommer
69 replaced appends = appends+1 with appends = tbs.appends+1
71 Revision 1.3 87/07/30 00:26:11 wesommer
72 Changes by mike prior to "appends" fix.
74 Revision 1.2 87/07/29 16:00:39 wesommer
77 Revision 1.1 87/07/29 15:13:57 wesommer
83 static char *rcsid_qsupport_qc = "$Header$";
87 #include "sms_server.h"
94 /* Specialized Access Routines */
97 ** access_user - verify that client name equals specified login name
99 ** Used by: update_user_shell
100 ** update_finger_by_login
102 ** - since field validation routines are called first, a users_id is
103 ** now in argv[0] instead of the login name. Therefore, we must
104 ** convert the client name to a users_id.
107 access_user(q, argv, cl)
112 register struct krbname *krb;
114 ## char *client_name;
117 client_name = cl->kname.name;
118 ## repeat retrieve (client_id = users.users_id)
119 ## where users.login = @client_name
120 ## inquire_equel (rowcount = "rowcount")
121 if (rowcount != 1) return(SMS_PERM);
122 if (client_id != *(int *)argv[0]) return(SMS_PERM);
128 ** access_pop - same as access_user plus verifies that a user has only one
129 ** mailbox of type "POP"
132 ** argv[0] - users_id
138 ** - if q->name = "add_pobox" and type = "POP",
139 ** verify that no POP box already exists for user
140 ** - call access_user
144 access_pop(q, argv, cl)
154 if (!bcmp(q->name, "add_pobox", 10) && !bcmp(argv[1], "POP", 4)) {
156 if (strcmp(cl->kname.name, box) != 0) return SMS_PERM;
158 users_id = *(int *)argv[0];
159 mach_id = *(int *)argv[2];
161 ## range of p is pobox
162 ## repeat retrieve (exists = any(p.#box where p.#users_id = @users_id
163 ## and p.type = "POP"))
164 if (exists) return(SMS_EXISTS);
167 return(access_user(q, argv, cl));
171 ** access_list - check access for adding or deleting list members
173 ** Inputs: argv[0] - list_id
174 ** cl->krb.name - client name
176 ** - check that client is a member of the access control list
177 ** - OR, if q->shortname == {amtl | dfml} and
178 ** if list.flags & LF_PUBLIC, allow access if client = member
182 access_list(q, argv, cl)
196 list_id = *(int *)argv[0];
197 ## repeat retrieve (acl_id = list.#acl_id, flags = list.#flags)
198 ## where list.#list_id = @list_id
200 /* parse client structure */
201 status = get_client(cl, &client_type, &client_id);
202 if (status != SMS_SUCCESS) return(status);
204 /* if amtl or dmfl and list is public allow client to add or delete self */
205 if (!bcmp("amtl", q->shortname, 4) || !bcmp("dmfl", q->shortname, 4)) {
206 if ((flags & LF_PUBLIC) && !bcmp("USER", argv[1], 4)) {
207 member_id = *(int *)argv[2];
208 if (member_id == client_id) return(SMS_SUCCESS);
212 /* check for client in access control list */
213 exists = find_member(acl_id, client_type, client_id, 0);
214 if (!exists) return(SMS_PERM);
220 ** access_maillist - access_list + disallow adding user-group to maillists
227 access_maillist(q, argv, cl)
234 ## char list_name[32];
237 status = access_list(q, argv, cl);
238 if (status != SMS_SUCCESS) return(status);
239 if (bcmp(q->name, "add_maillist", 12)) return(status);
241 list_id = *(int *)argv[0];
242 ## range of g is groups
243 ## repeat retrieve (exists = any(g.#list_id where g.#list_id = @list_id))
244 if (!exists) return(SMS_SUCCESS);
245 ## repeat retrieve (list_name = list.name) where list.#list_id = @list_id
246 ## repeat retrieve (exists = any(users.login where users.login = @list_name))
247 return ((exists) ? SMS_USER_GROUP : SMS_SUCCESS);
251 ** Setup routine for add_group
255 ** Description: allocate next gid and store in values table
259 setup_add_group(q, argv, cl)
269 ## range of g is groups
270 ## range of v is values
271 ## repeat retrieve (ngid = v.value) where v.name = "gid"
275 ## repeat retrieve (exists = any(g.#gid where g.#gid = @ngid))
278 ## repeat replace v (value = @ngid) where v.name = "gid"
279 ## inquire_equel (rowcount = "rowcount")
280 if (rowcount != 1) return SMS_INGRES_ERR;
281 else return(SMS_SUCCESS);
285 ** Setup routine for add_user
287 ** Inputs: argv[0] - login
292 ** - if argv[1] == "#" then set argv[1] = next(uid)
293 ** - if argv[0] == "#" then set argv[0] = "#<uid>"
297 setup_add_user(q, argv, cl)
299 register char *argv[];
305 if (!bcmp(argv[1], "#", 2)) {
306 ## range of u is users
307 ## range of v is values
308 ## repeat retrieve (nuid = v.value) where v.name = "uid"
312 ## repeat retrieve (exists = any(u.#uid where u.#uid = @nuid))
314 ## repeat replace v (value = @nuid) where v.name = "uid"
315 sprintf(argv[1], "%d", nuid);
318 if (!bcmp(argv[0], "#", 2)) {
319 sprintf(argv[0], "#%s", argv[1]);
326 ** followup_add_user - add finger entry, set_user_modtime
327 ** followup_delete_user - delete finger entry
330 ** argv[0] - login (add_user)
331 ** argv[0] - users_id (delete_user)
335 followup_add_user(q, argv)
344 ## char fullname[128];
350 /* get user information */
351 ## range of u is users
352 ## repeat retrieve (users_id = u.#users_id, last = u.#last,
353 ## first = u.#first, middle = u.#middle)
354 ## where u.#login = @login
359 while (*cp1) *cp2++ = *cp1++;
362 if (*cp1 == 0) cp2--;
363 while (*cp1) *cp2++ = *cp1++;
366 while (*cp2++ = *cp1++) ;
368 /* create a finger entry */
369 ## repeat append finger (#users_id = @users_id, #fullname = @fullname)
371 /* set modtime (creation time) on user */
372 ## repeat replace u (modtime = "now") where u.#users_id = @users_id
377 followup_delete_user(q, argv)
383 users_id = *(int *)argv[0];
384 ## repeat delete finger where finger.#users_id = @users_id
389 ** setup_add_filesys - verify existance of referenced file systems
390 ** setup_update_filesys - same, except argv[1..5] --> argv[2..6]
392 ** Inputs: Add Update
393 ** argv[0] - label label
394 ** argv[1] - type new label
395 ** argv[2] - mach_id type
396 ** argv[3] - name mach_id
397 ** argv[4] - mount name
398 ** argv[5] - access mount
403 ** * verify mach_id/name in rvdvirt
404 ** * verify access in {r, x, R, X}
406 ** * extract directory prefix from name
407 ** * verify mach_id/dir in nfsphys
408 ** * verify access in {r, w, R, W}
411 ** SMS_RVD - no such rvd
412 ** SMS_NFS - specified directory not exported
413 ** SMS_FILESYS_ACCESS - invalid filesys access
417 setup_add_filesys(q, argv)
427 mach_id = *(int *)argv[2];
431 if (!bcmp(type, "RVD", 3))
432 return (check_rvd(mach_id, name, access));
433 else if (!bcmp(type, "NFS", 3))
434 return (check_nfs(mach_id, name, access));
439 setup_update_filesys(q, argv)
449 mach_id = *(int *)argv[3];
453 if (!bcmp(type, "RVD", 3))
454 return (check_rvd(mach_id, name, access));
455 else if (!bcmp(type, "NFS", 3))
456 return (check_nfs(mach_id, name, access));
461 ##check_rvd(mach_id, name, access)
469 ## range of rv is rvdvirt
470 ## retrieve (rowcount = any(rv.#name where rv.#mach_id = mach_id and
472 if (rowcount == 0) return(SMS_RVD);
474 caccess = (isupper(*access)) ? tolower(*access) : *access;
475 if (caccess != 'r' && caccess != 'x') return(SMS_FILESYS_ACCESS);
480 ##check_nfs(mach_id, name, access)
492 caccess = (isupper(*access)) ? tolower(*access) : *access;
493 if (caccess != 'r' && caccess != 'w') return(SMS_FILESYS_ACCESS);
496 ## range of np is nfsphys
497 ## retrieve (dir = np.#dir) where np.#mach_id = mach_id
502 if (*cp1++ != *cp2) break;
506 status = SMS_SUCCESS;
514 /* Followup Routines */
516 set_user_modtime(q, argv)
523 ## repeat replace u (modtime = "now") where u.#login = @login
527 set_user_modtime_by_id(q, argv)
533 users_id = *(int *)argv[0];
534 ## repeat replace users (modtime = "now") where users.#users_id = @users_id
538 set_list_modtime(q, argv)
545 ## repeat replace list (modtime = "now") where list.name = @list_name
549 set_list_modtime_by_id(q, argv)
555 list_id = *(int *)argv[0];
556 ## repeat replace list (modtime = "now") where list.#list_id = @list_id
557 ## repeat replace list (modtime = "now") where list.#acl_id = @list_id
561 set_finger_modtime(q, argv)
567 users_id = *(int *)argv[0];
568 ## repeat replace f (modtime = "now") where f.#users_id = @users_id
573 ** followup_amtl - followup for amtl and dmfl; when adding a list
574 ** member to a maillist, add list to maillist table,
575 ** unless list is a user-group.
576 ** Then set_list_modtime_by_id.
580 ** argv[1] - member_type
581 ** argv[2] - member_id
585 followup_amtl(q, argv)
592 ## char list_name[33];
594 list_id = *(int *)argv[0];
596 ## repeat replace list (modtime = "now") where list.#list_id = @list_id
597 ## repeat replace list (modtime = "now") where list.#acl_id = @list_id
599 /* if query is not amtl or if member_type is not LIST then return */
600 if (bcmp(q->shortname, "amtl", 4) || bcmp(argv[1], "LIST", 4))
603 member_id = *(int *)argv[2];
604 ## range of l is list
605 ## range of ml is maillists
606 ## range of g is groups
608 /* is parent list a mailing list? */
609 ## repeat retrieve (exists = any(ml.#list_id where ml.#list_id=@list_id))
611 /* if not then return */
612 if (!exists) return(SMS_SUCCESS);
614 /* is member_list a user-group? */
616 ## repeat retrieve (exists = any(g.#list_id where g.#list_id = @member_id))
619 ## repeat retrieve (list_name = l.#name) where l.#list_id = @member_id
620 /* is list_name a username? */
621 ## repeat retrieve (exists = any(users.login
622 ## where users.login = @list_name))
623 /* yes, return error */
624 if (exists) return(SMS_USER_GROUP);
627 /* list is not a user-group; add list to maillist table */
628 ## repeat append maillists (#list_id = @member_id, ltid = l.tid)
629 ## where l.#list_id = @member_id
635 ** followup_add_pobox
636 ** followup_delete_pobox - followup routines for pobox queries
639 ** add_pobox: set pobox creation time
640 ** increment pop usage in serverhosts
642 ** delete_pobox: decrement pop usage in serverhosts
646 followup_add_pobox(q, argv)
650 set_pobox_creation(q, argv);
651 set_pop_usage(q, argv, 1);
655 followup_delete_pobox(q, argv)
659 set_pop_usage(q, argv, -1);
663 set_pobox_creation(q, argv)
672 users_id = *(int *)argv[0];
674 mach_id = *(int *)argv[2];
677 ## range of p is pobox
678 ## repeat replace p (created = "now")
679 ## where p.#users_id = @users_id and p.#type = @type and
680 ## p.#mach_id = @mach_id and p.#box = @box
682 return (SMS_SUCCESS);
686 ** set_pop_usage - incr/decr usage count for pop server in serverhosts talbe
689 ** q->name - "add_pobox" or "delete_pobox"
694 ** - incr/decr value field in serverhosts table for pop/mach_id
698 set_pop_usage(q, argv, count)
705 if (bcmp(argv[1], "POP", 3)) return(SMS_SUCCESS);
707 mach_id = *(int *)argv[2];
710 ## range of sh is serverhosts
711 ## repeat replace sh (value1 = sh.value1 + @n)
712 ## where sh.service = "pop" and sh.#mach_id = @mach_id
718 ** delete_user_poboxes - delete all poboxes for a user
721 ** argv[0] - users_id
725 delete_user_poboxes(q, argv)
735 users_id = *(int *)argv[0];
737 /* get machine ids for pop server(s) on which the user currently exists */
738 ## range of p is pobox
740 ## repeat retrieve (mach_id = p.#mach_id)
741 ## where p.#users_id = @users_id and p.type = "POP"
743 mach_ids[i++] = mach_id;
749 /* decrement counts on serverhost entries */
750 ## range of sh is serverhosts
752 mach_id = mach_ids[i];
753 ## repeat replace sh (value1 = sh.value1 - 1)
754 ## where sh.service = "pop" and sh.#mach_id = @mach_id
757 /* delete user's poboxes */
758 ## repeat delete p where p.#users_id = @users_id
766 ** delete_current_quota - adjust nfsphys values on xxx_quota queries.
771 ** argv[2] - users_id
772 ** argv[3] - quota (add_new_quota only)
775 ** delete_current_quota:
776 ** - find nfsquota entry
777 ** - decrement nfsphys.allocated by nfsquota.quota
779 ** - increment nfsphys.allocated by quota
783 add_new_quota(q, argv)
785 register char *argv[];
791 mach_id = *(int*)argv[0];
793 quota = *(int *)argv[3];
795 ## range of np is nfsphys
796 ## repeat replace np (allocated = np.allocated + @quota)
797 ## where np.#mach_id = @mach_id and np.#device = @device
802 delete_current_quota(q, argv, cl)
804 register char *argv[];
812 mach_id = *(int *)argv[0];
814 users_id = *(int *)argv[2];
816 ## range of np is nfsphys
817 ## range of nq is nfsquota
818 ## repeat retrieve (quota = nq.#quota)
819 ## where nq.#mach_id = @mach_id and nq.#device = @device and
820 ## nq.#users_id = @users_id
821 ## repeat replace np (allocated = np.allocated - @quota)
822 ## where np.#mach_id = @mach_id and np.#device = @device
828 ** add_hostaccess - create entry in hostaccess table upon adding a new
829 ** machine to the serverhosts table where service =
838 add_hostaccess(q, argv)
844 /* only work with service = "hostaccess" */
845 if (bcmp(argv[0], "hostaccess", 10)) return(SMS_SUCCESS);
847 mach_id = *(int *)argv[1];
848 ## repeat append hostaccess (#mach_id = @mach_id, status = 0)
849 ## repeat replace tblstats (modtime = "now", appends = tblstats.appends + 1)
850 ## where tblstats.table = "hostaccess"
854 /* followup to delete_server_host_info */
856 delete_hostaccess(q, argv)
862 /* only work with service = "hostaccess" */
863 if (bcmp(argv[0], "hostaccess", 10)) return(SMS_SUCCESS);
865 mach_id = *(int *)argv[1];
866 ## repeat delete hostaccess where hostaccess.#mach_id = @mach_id
867 ## repeat replace tblstats (modtime = "now", deletes = tblstats.deletes + 1)
868 ## where tblstats.table = "hostaccess"
872 followup_ushp(q, argv)
879 mach_id = *(int *)argv[0];
880 ## range of ha is hostaccess
881 ## repeat retrieve (status = ha.#status) where ha.#mach_id = @mach_id
883 ## repeat replace ha (#status = @status) where ha.#mach_id = @mach_id
887 followup_usha(q, argv)
894 mach_id = *(int *)argv[0];
895 ## range of ha is hostaccess
896 ## repeat retrieve (status = ha.#status) where ha.#mach_id = @mach_id
898 ## repeat replace ha (#status = @status) where ha.#mach_id = @mach_id
903 ** followup_delete_list - called after the delete_list query to clean up
904 ** members table; also deletes list from maillist
905 ** and groups tables.
907 ** Inputs: argv[0] - list_id
910 ** - foreach string member: decr string refc; ifzero, delete string
911 ** - delete all members entries for this list_id
915 followup_delete_list(q, argv)
917 register char *argv[];
923 struct save_queue *sq;
924 struct save_queue *sq_create();
926 list_id = *(int *)argv[0];
929 ## range of m is members
930 ## repeat retrieve (string_id = m.member_id)
931 ## where m.#list_id = @list_id and m.member_type = "STRING"
933 sq_save_data(sq, string_id);
936 while (sq_get_data(sq, &string_id)) {
937 ## range of s is strings
938 ## repeat retrieve (refc = s.#refc) where s.#string_id = @string_id
939 ## inquire_equel (rowcount = "rowcount")
940 if (rowcount == 0) continue;
942 ## repeat delete s where s.#string_id = @string_id
944 ## repeat replace s (#refc = @refc) where s.#string_id = @string_id
949 ## repeat delete m where m.#list_id = @list_id
950 ## repeat delete maillists where maillists.#list_id = @list_id
951 ## repeat delete groups where groups.#list_id = @list_id
957 ** followup_grvd - Support routine for get_rvd_servers query
960 ** q - grvd query structure
961 ** sq - save_queue struture: contains list of {machine, oper_acl_id,
962 ** admin_acl_id, shutdown_acl_id} records.
963 ** v - validate structure (not used)
964 ** action - action routine
965 ** actarg - action routine argument
968 ** - translate acl_ids to list names
972 followup_grvd(q, sq, v, action, actarg)
974 struct save_queue *sq;
983 ## char shutdown[33];
990 ## range of l is list
992 while (sq_get_data(sq, &argv)) {
993 sscanf(argv[0], "%d", &list_id);
994 ## repeat retrieve (oper = l.name) where l.#list_id = @list_id
995 sscanf(argv[1], "%d", &list_id);
996 ## repeat retrieve (admin = l.name) where l.#list_id = @list_id
997 sscanf(argv[2], "%d", &list_id);
998 ## repeat retrieve (shutdown = l.name) where l.#list_id = @list_id
1000 (*action)(3, targv, actarg);
1007 return(SMS_SUCCESS);
1010 followup_gars(q, sq, v, action, actarg)
1012 struct save_queue *sq;
1021 ## char shutdown[33];
1026 targv[3] = shutdown;
1028 ## range of l is list
1030 while (sq_get_data(sq, &argv)) {
1031 sscanf(argv[1], "%d", &list_id);
1032 ## repeat retrieve (oper = l.name) where l.#list_id = @list_id
1033 sscanf(argv[2], "%d", &list_id);
1034 ## repeat retrieve (admin = l.name) where l.#list_id = @list_id
1035 sscanf(argv[3], "%d", &list_id);
1036 ## repeat retrieve (shutdown = l.name) where l.#list_id = @list_id
1039 (*action)(4, targv, actarg);
1047 return(SMS_SUCCESS);
1051 ** set_next_object_id - set next object id in values table
1053 ** Inputs: object - object name in values table
1055 ** - called before an APPEND operation to set the next object id to
1056 ** be used for the new record
1060 set_next_object_id(object)
1067 ## range of v is values
1068 ## repeat replace v (value = v.value + 1) where v.#name = @name
1069 ## inquire_equel (rowcount = "rowcount")
1071 return SMS_INGRES_ERR;
1072 else return(SMS_SUCCESS);
1076 ** get_query_need - check modtime of query's associated table against given
1077 ** time and return true if greater (false if not)
1080 ** argv[0] - query name
1081 ** argv[1] - time to compare against
1085 get_query_need(q, argv, action, actarg)
1087 register char *argv[];
1091 ## char *last_get_time;
1095 struct query *get_query_by_name();
1097 q1 = get_query_by_name(argv[0]);
1099 last_get_time = argv[1];
1102 if (q1 == NULL || q1->type != RETRIEVE || table == NULL)
1103 return(SMS_NO_MATCH);
1105 ## range of tbs is tblstats
1106 ## repeat retrieve (need = any(tbs.modtime where tbs.#table = @table and
1107 ## tbs.modtime > @last_get_time))
1109 result = (need) ? "true" : "false";
1110 (*action)(1, &result, actarg);
1111 return(SMS_SUCCESS);
1115 ** get_list_is_group
1116 ** get_list_is_maillist
1119 ** argv[0] - list_id
1126 get_list_is_group(q, argv, action, actarg)
1136 list_id = *(int *)argv[0];
1138 ## range of g is groups
1139 ## repeat retrieve (exists = any(g.#list_id where g.#list_id = @list_id))
1141 result = (exists) ? "true" : "false";
1142 (*action)(1, &result, actarg);
1143 return(SMS_SUCCESS);
1146 get_list_is_maillist(q, argv, action, actarg)
1156 list_id = *(int *)argv[0];
1158 ## range of ml is maillists
1159 ## repeat retrieve (exists = any(ml.#list_id where ml.#list_id = @list_id))
1161 result = (exists) ? "true" : "false";
1162 (*action)(1, &result, actarg);
1163 return(SMS_SUCCESS);
1168 ** add_locker - special query routine for creating a user locker
1171 ** argv[0] - users_id
1172 ** argv[1] - machine_id
1174 ** argv[3] - initial quota
1177 ** - get prefix directory (dir) for mount point on specified machine/device
1178 ** - create filesys entry (label=<login>, type=NFS, machine=<machine>,
1179 ** mount=<dir>/<login>, access=w, acl=dbadmin)
1180 ** - increment allocated in nfsphys by quota
1181 ** - create nfsquota entry
1184 ** - SMS_NFSPHYS - machine/device does not exist in nfsphys
1185 ** - SMS_FILESYS_EXISTS - file system already exists
1190 register struct query *q;
1205 /* copy arguments */
1206 users_id = *(int *)argv[0];
1207 mach_id = *(int *)argv[1];
1209 sscanf(argv[3], "%d", "a);
1211 ## range of u is users
1212 ## range of f is filesys
1213 ## range of np is nfsphys
1214 ## range of tbs is tblstats
1216 /* get login name */
1217 ## repeat retrieve (login = u.#login) where u.#users_id = @users_id
1219 /* get user's acl id */
1220 ## repeat retrieve (user_acl = list.list_id) where list.name = @login
1222 /* get filesystem directory prefix; give error if machine/device
1223 pair not in nfsphys table */
1224 printf("np.mach_id = %d and np.device = %s\n", mach_id, device);
1226 ## repeat retrieve (dir = np.#dir, allocated = np.#allocated)
1227 ## where np.#mach_id = @mach_id and np.#device = @device
1228 ## inquire_equel (rowcount = "rowcount")
1229 if (rowcount == 0) return(SMS_NFSPHYS);
1231 /* make sure a filesys with user's name does not already exist */
1232 ## repeat retrieve (rowcount = any(f.label where f.label = @login))
1233 if (rowcount != 0) return(SMS_FILESYS_EXISTS);
1235 /* create a new filesys */
1236 sprintf(locker, "%s/%s", dir, login);
1237 sprintf(mount, "/mit/%s", login);
1238 ## repeat append filesys
1239 ## (#label = @login, type = "NFS", #mach_id = @mach_id,
1240 ## name = @locker, access = "w", order = 1, #mount = @mount,
1241 ## acl_id = @user_acl)
1242 ## repeat replace tbs (appends = tbs.appends + 1, modtime = "now")
1243 ## where tbs.table = "filesys"
1245 /* increment usage count in nfsphys table */
1247 ## replace np (#allocated = allocated)
1248 ## where np.#mach_id = mach_id and np.#device = device
1249 ## repeat replace tbs (updates = tbs.updates + 1, modtime = "now")
1250 ## where tbs.table = "nfsphys"
1252 /* create nfsquota entry */
1253 ## append nfsquota (#users_id = users_id, #mach_id = mach_id,
1254 ## #device = device, #quota = quota)
1255 ## repeat replace tbs (appends = tbs.appends + 1, modtime = "now")
1256 ## where tbs.table = "nfsquota"
1258 return(SMS_SUCCESS);
1262 ** delete_locker - special query routine for deleting a user locker
1265 ** argv[0] - users_id
1268 ** - get login name from users_id
1269 ** - get filesys entry from login
1270 ** - use filesys.mach_id and filesys.name to determine machine/device
1271 ** pair for nfsphys and nfsquota
1272 ** - delete filesys entry (label=<login>)
1273 ** - decrement allocated in nfsphys by quota
1274 ** - delete nfsquota entry
1277 ** - SMS_FILESYS - no filesys exists for user
1281 delete_locker(q, argv)
1282 register struct query *q;
1283 register char *argv[];
1294 /* copy arguments */
1295 users_id = *(int *)argv[0];
1297 ## range of u is users
1298 ## range of f is filesys
1299 ## range of np is nfsphys
1300 ## range of nq is nfsquota
1301 ## range of tbs is tblstats
1303 /* get login name */
1304 ## repeat retrieve (login = u.#login) where u.#users_id = @users_id
1306 /* get mach_id and locker name from filesys entry; then delete it */
1307 ## repeat retrieve (mach_id = f.#mach_id, lname = f.#name)
1308 ## where f.#label = @login
1309 ## inquire_equel (rowcount = "rowcount")
1310 if (rowcount == 0) return(SMS_FILESYS);
1311 ## repeat delete f where f.#label = @login
1313 /* get prefix directory */
1314 c = (char *)rindex(lname, '/');
1317 /* get nfs device */
1318 ## repeat retrieve (ndev = np.device)
1319 ## where np.#mach_id = @mach_id and np.dir = @lname
1321 /* get quota from nfsquota entry; then delete entry */
1322 ## repeat retrieve (quota = nq.#quota)
1323 ## where nq.#mach_id = @mach_id and nq.#device = @ndev and
1324 ## nq.#users_id = @users_id
1325 ## repeat delete nq where nq.#mach_id = @mach_id and nq.#device = @ndev and
1326 ## nq.#users_id = @users_id
1328 /* decrement nfsphys.allocated */
1329 ## repeat replace np (allocated = np.allocated - @quota)
1330 ## where np.#mach_id = @mach_id and np.#device = @ndev
1332 /* adjust table statistics */
1333 ## repeat replace tbs (deletes = tbs.deletes + 1, modtime = "now")
1334 ## where tbs.table = "filesys"
1335 ## repeat replace tbs (updates = tbs.updates + 1, modtime = "now")
1336 ## where tbs.table = "nfsphys"
1337 ## repeat replace tbs (deletes = tbs.deletes + 1, modtime = "now")
1338 ## where tbs.table = "nfsquota"
1340 return(SMS_SUCCESS);
1344 ** add_user_group - create a group for a user and add user to group
1350 ** - verify specified user exists
1351 ** - create a list of same name as user
1352 ** - add user as a member of the list
1356 add_user_group(q, argv)
1368 /* verify user exists */
1369 ## repeat retrieve (users_id = users.#users_id) where users.#login = @login
1370 ## inquire_equel (exists = "rowcount")
1371 if (exists != 1) return(SMS_USER);
1373 /* verify list does not exist */
1374 ## repeat retrieve (exists = any(list.name where list.name = @login))
1375 if (exists) return(SMS_LIST);
1377 /* get new list_id */
1378 ## repeat retrieve (list_id = values.value) where values.name = "list_id"
1380 ## repeat replace values (value = @list_id) where values.name = "list_id"
1382 /* create the list */
1383 ## range of tbs is tblstats
1384 ## repeat append list (name = @login, #list_id = @list_id, flags = 1,
1385 ## desc = "User Group", acl_id = @list_id,
1386 ## expdate = "today" + "5 years", modtime = "now")
1387 ## repeat replace tbs (modtime = "now", appends = tbs.appends + 1)
1388 ## where tbs.table = "list"
1390 /* add user to list */
1391 ## repeat append members (#list_id = @list_id, member_type = "USER",
1392 ## member_id = @users_id)
1393 ## repeat replace tbs (modtime = "now", appends = tbs.appends + 1)
1394 ## where tbs.table = "members"
1397 ## range of g is groups
1398 ## range of v is values
1399 ## repeat retrieve (gid = v.value) where v.name = "gid"
1403 ## repeat retrieve (exists = any(g.#gid where g.#gid = @gid))
1405 ## repeat replace v (value = @gid) where v.name = "gid"
1406 /* add list to group table */
1407 ## repeat append groups (#list_id = @list_id, ltid = list.tid, #gid = @gid)
1408 ## where list.#list_id = @list_id
1410 ## repeat replace tbs (modtime = "now", appends = tbs.appends + 1)
1411 ## where tbs.table = "groups"
1413 ## repeat replace tbs (modtime = "now", appends = tbs.appends + 1)
1414 ## where tbs.table = "members"
1416 /* and we're done */
1417 return(SMS_SUCCESS);
1422 ** get_members_of_list - optimized query for retrieval of list members
1425 ** argv[0] - list_id
1428 ** - retrieve USER members, then LIST members, then STRING members
1432 get_members_of_list(q, argv, action, actarg)
1439 ## char member_name[129];
1442 list_id = *(int *)argv[0];
1444 targv[1] = member_name;
1446 ## range of m is members
1447 ## repeat retrieve (member_name = users.login)
1448 ## where m.#list_id = @list_id and m.member_type = "USER"
1449 ## and m.member_id = users.users_id
1450 ## sort by #member_name
1452 (*action)(2, targv, actarg);
1456 ## repeat retrieve (member_name = list.name)
1457 ## where m.#list_id = @list_id and m.member_type = "LIST"
1458 ## and m.member_id = list.#list_id
1459 ## sort by #member_name
1461 (*action)(2, targv, actarg);
1464 targv[0] = "STRING";
1465 ## repeat retrieve (member_name = strings.string)
1466 ## where m.#list_id = @list_id and m.member_type = "STRING"
1467 ## and m.member_id = strings.string_id
1468 ## sort by #member_name
1470 (*action)(2, targv, actarg);
1473 return(SMS_SUCCESS);
1477 ** get_groups_of_user - optimized query for retrieval of all groups to
1478 ** which a user belongs
1482 get_groups_of_user(q, argv, action, actarg)
1489 ## char list_name[33];
1494 users_id = *(int *)argv[0];
1495 targv[0] = list_name;
1498 ## range of m is members
1500 ## repeat retrieve (list_name = list.name, gid = text(groups.#gid))
1501 ## where m.member_id = @users_id and m.member_type = "USER" and
1502 ## m.list_id = groups.list_id and groups.ltid = list.tid
1503 ## sort by #list_name
1505 (*action)(2, targv, actarg);
1507 ## inquire_equel (rowcount = "rowcount")
1509 return ((rowcount = 0) ? SMS_NO_MATCH : SMS_SUCCESS);
1512 get_groups_of_all_users(q, argv, action, actarg)
1528 ## range of u is users
1529 ## range of l is list
1530 ## range of m is members
1531 ## range of g is groups
1533 ## set lockmode session where readlock = nolock
1535 ## repeat retrieve (login = u.#login, group = l.name, gid = text(g.#gid))
1536 ## where m.member_type = "USER" and m.member_id = u.users_id and
1537 ## u.status != 0 and m.list_id = g.list_id and
1539 ## sort by #login, #group
1541 (*action)(3, targv, actarg);
1544 ## inquire_equel (errorno = "errorno")
1545 ## set lockmode session where readlock = system
1547 return((errorno) ? SMS_INGRES_ERR : SMS_SUCCESS);
1551 ** get_all_poboxes - optimized query for retrieval of all poboxes
1554 ** - retrieve LOCAL boxes, then POP boxes, then FOREIGN boxes
1558 get_all_poboxes(q, argv, action, actarg)
1565 ## char machine[129];
1575 ## set lockmode session where readlock = nolock
1576 ## range of p is pobox
1577 ## repeat retrieve (login=users.#login, machine = #machine.name, box=p.#box)
1578 ## where p.type = "LOCAL" and p.users_id = users.users_id
1579 ## and p.mach_id = #machine.mach_id
1581 (*action)(4, targv, actarg);
1585 ## repeat retrieve (login=users.#login, machine = #machine.name, box=p.#box)
1586 ## where p.type = "POP" and p.users_id = users.users_id
1587 ## and p.mach_id = #machine.mach_id
1589 (*action)(4, targv, actarg);
1592 targv[1] = "FOREIGN";
1593 ## repeat retrieve (login=users.#login, machine=strings.string, box=p.#box)
1594 ## where p.type = "FOREIGN" and p.users_id = users.users_id
1595 ## and p.mach_id = strings.string_id
1597 (*action)(4, targv, actarg);
1599 ## set lockmode session where readlock = system
1601 return(SMS_SUCCESS);
1604 get_new_poboxes(q, argv, action, actarg)
1612 ## char machine[129];
1623 ## range of p is pobox
1624 ## repeat retrieve (login=users.#login, machine = #machine.name, box=p.#box)
1625 ## where p.type = "LOCAL" and p.users_id = users.users_id
1626 ## and p.mach_id = #machine.mach_id and
1627 ## p.#created > @created
1629 (*action)(4, targv, actarg);
1633 ## repeat retrieve (login=users.#login, machine = #machine.name, box=p.#box)
1634 ## where p.type = "POP" and p.users_id = users.users_id
1635 ## and p.mach_id = #machine.mach_id and
1636 ## p.#created > @created
1638 (*action)(4, targv, actarg);
1641 targv[1] = "FOREIGN";
1642 ## repeat retrieve (login=users.#login, machine=strings.string, box=p.#box)
1643 ## where p.type = "FOREIGN" and p.users_id = users.users_id
1644 ## and p.mach_id = strings.string_id and
1645 ## p.#created > @created
1647 (*action)(4, targv, actarg);
1650 return(SMS_SUCCESS);
1653 /* Validation Routines */
1655 validate_row(q, argv, v)
1656 register struct query *q;
1658 register struct validate *v;
1666 /* build where clause */
1667 build_qual(v->qual, v->argc, argv, qual);
1669 /* setup ingres variables */
1674 if (log_flags & LOG_RES)
1675 /* tell the logfile what we're doing */
1676 com_err(whoami, 0, "validating row: %s", qual);
1678 /* look for the record */
1679 ## range of rvar is table
1680 ## retrieve (rowcount = count(rvar.name where qual))
1681 if (rowcount == 0) return(SMS_NO_MATCH);
1682 if (rowcount > 1) return(SMS_NOT_UNIQUE);
1686 validate_fields(q, argv, vo, n)
1688 register char *argv[];
1689 register struct valobj *vo;
1692 register int status;
1697 if (log_flags & LOG_RES)
1698 com_err(whoami, 0, "validating %s in %s: %s",
1699 vo->namefield, vo->table, argv[vo->index]);
1700 status = validate_name(argv, vo);
1704 if (log_flags & LOG_RES)
1705 com_err(whoami, 0, "validating %s in %s: %s",
1706 vo->idfield, vo->table, argv[vo->index]);
1707 status = validate_id(argv, vo);
1711 if (log_flags & LOG_RES)
1712 com_err(whoami, 0, "validating date: %s", argv[vo->index]);
1713 status = validate_date(argv, vo);
1717 if (log_flags & LOG_RES)
1718 com_err(whoami, 0, "validating %s type: %s",
1719 vo->table, argv[vo->index]);
1720 status = validate_type(argv, vo);
1724 if (log_flags & LOG_RES)
1725 com_err(whoami, 0, "validating typed data (%s): %s",
1726 argv[vo->index - 1], argv[vo->index]);
1727 status = validate_typedata(q, argv, vo);
1731 status = SMS_EXISTS;
1735 status = SMS_EXISTS;
1740 if (status != SMS_EXISTS) return(status);
1744 return(SMS_SUCCESS);
1747 validate_id(argv, vo)
1749 register struct valobj *vo;
1759 name = argv[vo->index];
1761 /* minor kludge to upcasify machine names */
1762 if (!bcmp(table, "machine", 7))
1763 for (c = name; *c; c++) if (islower(*c)) *c = toupper(*c);
1764 namefield = vo->namefield;
1765 idfield = vo->idfield;
1766 if (!bcmp(namefield, "uid", 4)) {
1767 ## retrieve (id = table.idfield) where table.namefield = int4(name)
1768 ## inquire_equel (rowcount = "rowcount")
1770 ## retrieve (id = table.idfield) where table.namefield = name
1771 ## inquire_equel (rowcount = "rowcount")
1773 if (rowcount != 1) return(vo->error);
1774 *(int *)argv[vo->index] = id;
1778 validate_name(argv, vo)
1780 register struct valobj *vo;
1787 name = argv[vo->index];
1789 namefield = vo->namefield;
1790 ## retrieve (rowcount = countu(table.namefield
1791 ## where table.namefield = name))
1792 return ((rowcount == 1) ? SMS_EXISTS : vo->error);
1795 /* Special validation routine for get_filesys */
1796 validate_label(q, argv)
1800 register char *label;
1804 c = (char *)index(label, '*');
1805 if (c == label) return(SMS_NOT_UNIQUE);
1806 return(SMS_SUCCESS);
1809 /* Special validation routine for delete_filesys */
1810 validate_label_2(q, argv)
1814 if (index(argv[0], '*') != 0) return(SMS_NOT_UNIQUE);
1815 return(SMS_SUCCESS);
1818 validate_date(argv, vo)
1826 idate = argv[vo->index];
1828 ## retrieve (dd = interval("years", date(idate) - date("today")))
1829 ## inquire_equel (errorno = "errorno")
1830 if (errorno != 0 || dd > 5.0) return(SMS_DATE);
1831 return(SMS_SUCCESS);
1834 validate_type(argv, vo)
1836 register struct valobj *vo;
1843 typename = vo->table;
1844 value = argv[vo->index];
1846 /* uppercase type fields */
1847 for (c = value; *c; c++) if (islower(*c)) *c = toupper(*c);
1849 ## range of a is alias
1850 ## repeat retrieve (rowcount = count(a.trans where a.name = @typename and
1851 ## a.type = "TYPE" and
1852 ## a.trans = @value))
1853 return ((rowcount == 1) ? SMS_EXISTS : vo->error);
1856 /* validate member or type-specific data field */
1858 validate_typedata(q, argv, vo)
1859 register struct query *q;
1860 register char *argv[];
1861 register struct valobj *vo;
1864 ## char *field_type;
1865 ## char data_type[17];
1871 /* get named object */
1872 name = argv[vo->index];
1874 /* get field type string (known to be at index-1) */
1875 field_type = argv[vo->index-1];
1877 /* get corresponding data type associated with field type name */
1878 ## repeat retrieve (data_type = alias.trans)
1879 ## where alias.#name = @field_type and alias.type = "TYPEDATA"
1880 ## inquire_equel (rowcount = "rowcount")
1881 if (rowcount != 1) return(SMS_TYPE);
1883 /* now retrieve the record id corresponding to the named object */
1885 if (!strcmp(data_type, "user")) {
1887 ## repeat retrieve (id = users.users_id) where users.login = @name
1888 ## inquire_equel (rowcount = "rowcount")
1889 if (rowcount != 1) return(SMS_USER);
1891 } else if (!strcmp(data_type, "list")) {
1893 ## repeat retrieve (id = list.list_id) where list.#name = @name
1894 ## inquire_equel (rowcount = "rowcount")
1895 if (rowcount != 1) return(SMS_LIST);
1897 } else if (!strcmp(data_type, "machine")) {
1899 for (c = name; *c; c++) if (islower(*c)) *c = toupper(*c);
1900 ## repeat retrieve (id = machine.mach_id) where machine.#name = @name
1901 ## inquire_equel (rowcount = "rowcount")
1902 if (rowcount != 1) return(SMS_MACHINE);
1904 } else if (!strcmp(data_type, "string")) {
1906 ## range of s is strings
1907 ## repeat retrieve (id = s.string_id, refc = s.#refc)
1908 ## where s.string = @name
1909 ## inquire_equel (rowcount = "rowcount")
1910 if (rowcount == 0) {
1911 if (q->type != APPEND) return(SMS_STRING);
1912 ## range of v is values
1913 ## retrieve (id = v.value) where v.#name = "strings_id"
1915 ## replace v (value = id) where v.#name = "strings_id"
1916 ## append to strings (string_id = id, string = name, #refc = 1)
1917 } else if (rowcount == 1) {
1918 if (q->type == APPEND || q->type == DELETE) {
1919 refc += (q->type == APPEND) ? 1 : -1;
1921 ## replace s (#refc = refc) where s.string_id = id
1923 ## delete s where s.string_id = id
1931 /* now set value in argv */
1932 *(int *)argv[vo->index] = id;
1934 return (SMS_EXISTS);
1938 translate_ids(q, sq, v, action, actarg)
1939 register struct query *q;
1940 register struct save_queue *sq;
1941 register struct validate *v;
1942 register int (*action)();
1946 ## char *field_type;
1947 ## char data_type[17];
1954 for (i = 0; i < v->objcnt; i++) {
1956 if (vo->type == V_FOLLOWUP) break;
1960 while (sq_get_data(sq, &argv)) {
1964 sscanf(argv[i], "%d", &id);
1966 name = (char *)malloc(129);
1969 /* get field type string (known to be at index-1) */
1970 field_type = argv[vo->index-1];
1972 /* get corresponding data type associated with field type name */
1973 ## repeat retrieve (data_type = alias.trans)
1974 ## where alias.#name = @field_type and alias.type = "TYPEDATA"
1975 ## inquire_equel (rowcount = "rowcount")
1976 if (rowcount != 1) {
1977 sprintf(name, "%d", id);
1978 (*action)(q->vcnt, argv, actarg);
1982 /* retrieve object name */
1984 if (!strcmp(data_type, "user")) {
1986 ## repeat retrieve (name = users.login) where users.users_id = @id
1987 ## inquire_equel (rowcount = "rowcount")
1989 } else if (!strcmp(data_type, "list")) {
1991 ## repeat retrieve (name = list.#name) where list.list_id = @id
1992 ## inquire_equel (rowcount = "rowcount")
1994 } else if (!strcmp(data_type, "machine")) {
1996 ## repeat retrieve (name = machine.#name) where machine.mach_id = @id
1997 ## inquire_equel (rowcount = "rowcount")
1999 } else if (!strcmp(data_type, "string")) {
2001 ## repeat retrieve (name = strings.string)
2002 ## where strings.string_id = @id
2003 ## inquire_equel (rowcount = "rowcount")
2009 /* if there wasn't a corresponding object name, then use the id */
2010 if (rowcount != 1) sprintf(name, "%d", id);
2013 (*action)(q->vcnt, argv, actarg);
2015 /* free saved data */
2016 for (i = 0; i < q->vcnt; i++)
2022 return (SMS_SUCCESS);
2029 * c-continued-statement-offset: 4
2030 * c-brace-offset: -4
2031 * c-argdecl-indent: 4
2032 * c-label-offset: -4