6 * Copyright (C) 1987 by the Massachusetts Institute of Technology
9 * Revision 1.9 1987-08-22 17:41:34 wesommer
10 * More of Mike's changes.
12 Revision 1.8 87/08/18 15:05:20 wesommer
13 Fixed definition of add_locker.
15 Revision 1.7 87/08/04 01:49:41 wesommer
18 Revision 1.6 87/08/04 01:10:02 wesommer
19 Changes by mike; checked in prior to my hacking.
21 Revision 1.5 87/07/30 14:54:13 wesommer
22 Added debugging code in an attempt to catch a flakey problem.
24 Revision 1.4 87/07/30 00:30:21 wesommer
25 replaced appends = appends+1 with appends = tbs.appends+1
27 Revision 1.3 87/07/30 00:26:11 wesommer
28 Changes by mike prior to "appends" fix.
30 Revision 1.2 87/07/29 16:00:39 wesommer
33 Revision 1.1 87/07/29 15:13:57 wesommer
39 static char *rcsid_qsupport_qc = "$Header$";
43 #include "sms_server.h"
50 /* Specialized Access Routines */
53 ** access_user - verify that client name equals specified login name
55 ** Used by: update_user_shell
56 ** update_finger_by_login
58 ** - since field validation routines are called first, a users_id is
59 ** now in argv[0] instead of the login name. Therefore, we must
60 ** convert the client name to a users_id.
63 access_user(q, argv, cl)
68 register struct krbname *krb;
73 client_name = cl->kname.name;
74 ## repeat retrieve (client_id = users.users_id)
75 ## where users.login = @client_name
76 ## inquire_equel (rowcount = "rowcount")
77 if (rowcount != 1) return(SMS_PERM);
78 if (client_id != *(int *)argv[0]) return(SMS_PERM);
84 ** access_pop - same as access_user plus verifies that a user has only one
85 ** mailbox of type "POP"
94 ** - if q->name = "add_pobox" and type = "POP",
95 ** verify that no POP box already exists for user
100 access_pop(q, argv, cl)
110 if (!bcmp(q->name, "add_pobox", 10) && !bcmp(argv[1], "POP", 4)) {
111 users_id = *(int *)argv[0];
112 mach_id = *(int *)argv[2];
114 ## range of p is pobox
115 ## repeat retrieve (exists = any(p.#box where p.#users_id = @users_id
116 ## and p.type = "POP"
117 ## and p.#mach_id = @mach_id
118 ## and p.#box = @box))
119 if (exists) return(SMS_EXISTS);
122 return(access_user(q, argv, cl));
126 ** access_list - check access for adding or deleting list members
128 ** Inputs: argv[0] - list_id
129 ** cl->krb.name - client name
131 ** - check that client is a member of the access control list
132 ** - OR, if q->shortname == {amtl | dfml} and
133 ** if list.flags & LF_PUBLIC, allow access if client = member
137 access_list(q, argv, cl)
151 list_id = *(int *)argv[0];
152 ## repeat retrieve (acl_id = list.#acl_id, flags = list.#flags)
153 ## where list.#list_id = @list_id
155 /* parse client structure */
156 status = get_client(cl, &client_type, &client_id);
157 if (status != SMS_SUCCESS) return(status);
159 /* if amtl or dmfl and list is public allow client to add or delete self */
160 if (!bcmp("amtl", q->shortname, 4) || !bcmp("dmfl", q->shortname, 4)) {
161 if ((flags & LF_PUBLIC) && !bcmp("USER", argv[1], 4)) {
162 member_id = *(int *)argv[2];
163 if (member_id == client_id) return(SMS_SUCCESS);
167 /* check for client in access control list */
168 exists = find_member(acl_id, client_type, client_id, 0);
169 if (!exists) return(SMS_PERM);
175 ** access_maillist - access_list + disallow adding user-group to maillists
182 access_maillist(q, argv, cl)
189 ## char list_name[32];
192 status = access_list(q, argv, cl);
193 if (status != SMS_SUCCESS) return(status);
194 if (bcmp(q->name, "add_maillist", 12)) return(status);
196 list_id = *(int *)argv[0];
197 ## range of g is groups
198 ## repeat retrieve (exists = any(g.#list_id where g.#list_id = @list_id))
199 if (!exists) return(SMS_SUCCESS);
200 ## repeat retrieve (list_name = list.name) where list.#list_id = @list_id
201 ## repeat retrieve (exists = any(users.login where users.login = @list_name))
202 return ((exists) ? SMS_USER_GROUP : SMS_SUCCESS);
206 ** Setup routine for add_group
210 ** Description: allocate next gid and store in values table
214 setup_add_group(q, argv, cl, access_check)
224 status = access_list(q, argv, cl);
226 if (status != SMS_SUCCESS || access_check) return(status);
228 ## range of g is groups
229 ## range of v is values
230 ## repeat retrieve (ngid = v.value) where v.name = "gid"
234 ## repeat retrieve (exists = any(g.#gid where g.#gid = @ngid))
237 ## repeat replace v (value = @ngid) where v.name = "gid"
242 ** Setup routine for add_user
244 ** Inputs: argv[0] - login
249 ** - if argv[1] == "#" then set argv[1] = next(uid)
250 ** - if argv[0] == "#" then set argv[0] = "#<uid>"
254 setup_add_user(q, argv, cl, access_check)
256 register char *argv[];
263 if (access_check) return(SMS_SUCCESS);
265 if (!bcmp(argv[1], "#", 2)) {
266 ## range of u is users
267 ## range of v is values
268 ## repeat retrieve (nuid = v.value) where v.name = "uid"
272 ## repeat retrieve (exists = any(u.#uid where u.#uid = @nuid))
274 ## repeat replace v (value = @nuid) where v.name = "uid"
275 sprintf(argv[1], "%d", nuid);
278 if (!bcmp(argv[0], "#", 2)) {
279 sprintf(argv[0], "#%s", argv[1]);
286 ** followup_add_user - add finger entry, set_user_modtime
287 ** followup_delete_user - delete finger entry
290 ** argv[0] - login (add_user)
291 ** argv[0] - users_id (delete_user)
295 followup_add_user(q, argv)
304 ## char fullname[128];
310 /* get user information */
311 ## range of u is users
312 ## repeat retrieve (users_id = u.#users_id, last = u.#last,
313 ## first = u.#first, middle = u.#middle)
314 ## where u.#login = @login
319 while (*cp1) *cp2++ = *cp1++;
322 if (*cp1 == 0) cp2--;
323 while (*cp1) *cp2++ = *cp1++;
326 while (*cp2++ = *cp1++) ;
328 /* create a finger entry */
329 ## repeat append finger (#users_id = @users_id, #fullname = @fullname)
331 /* set modtime (creation time) on user */
332 ## repeat replace u (modtime = "now") where u.#users_id = @users_id
337 followup_delete_user(q, argv)
343 users_id = *(int *)argv[0];
344 ## repeat delete finger where finger.#users_id = @users_id
349 ** setup_add_filesys - verify existance of referenced file systems
350 ** setup_update_filesys - same, except argv[1..5] --> argv[2..6]
352 ** Inputs: Add Update
353 ** argv[0] - label label
354 ** argv[1] - type new label
355 ** argv[2] - mach_id type
356 ** argv[3] - name mach_id
357 ** argv[4] - mount name
358 ** argv[5] - access mount
363 ** * verify mach_id/name in rvdvirt
364 ** * verify access in {r, x, R, X}
366 ** * extract directory prefix from name
367 ** * verify mach_id/dir in nfsphys
368 ** * verify access in {r, w, R, W}
371 ** SMS_RVD - no such rvd
372 ** SMS_NFS - specified directory not exported
373 ** SMS_FILESYS_ACCESS - invalid filesys access
377 setup_add_filesys(q, argv)
387 mach_id = *(int *)argv[2];
391 if (!bcmp(type, "RVD", 3))
392 return (check_rvd(mach_id, name, access));
393 else if (!bcmp(type, "NFS", 3))
394 return (check_nfs(mach_id, name, access));
399 setup_update_filesys(q, argv)
409 mach_id = *(int *)argv[3];
413 if (!bcmp(type, "RVD", 3))
414 return (check_rvd(mach_id, name, access));
415 else if (!bcmp(type, "NFS", 3))
416 return (check_nfs(mach_id, name, access));
421 ##check_rvd(mach_id, name, access)
429 ## range of rv is rvdvirt
430 ## retrieve (rowcount = any(rv.#name where rv.#mach_id = mach_id and
432 if (rowcount == 0) return(SMS_RVD);
434 caccess = (isupper(*access)) ? tolower(*access) : *access;
435 if (caccess != 'r' && caccess != 'x') return(SMS_FILESYS_ACCESS);
440 ##check_nfs(mach_id, name, access)
451 caccess = (isupper(*access)) ? tolower(*access) : *access;
452 if (caccess != 'r' && caccess != 'w') return(SMS_FILESYS_ACCESS);
454 ## range of np is nfsphys
455 ## retrieve (dir = np.#dir) where np.#mach_id = mach_id
460 if (*cp1++ != *cp2) break;
463 if (*cp2 == 0) return(SMS_SUCCESS);
469 /* Followup Routines */
471 set_user_modtime(q, argv)
478 ## repeat replace u (modtime = "now") where u.#login = @login
482 set_user_modtime_by_id(q, argv)
488 users_id = *(int *)argv[0];
489 ## repeat replace users (modtime = "now") where users.#users_id = @users_id
493 set_list_modtime(q, argv)
500 ## repeat replace list (modtime = "now") where list.name = @list_name
504 set_list_modtime_by_id(q, argv)
510 list_id = *(int *)argv[0];
511 ## repeat replace list (modtime = "now") where list.#list_id = @list_id
515 set_finger_modtime(q, argv)
521 users_id = *(int *)argv[0];
522 ## repeat replace f (modtime = "now") where f.#users_id = @users_id
527 ** followup_amtl - followup for amtl and dmfl; when adding a list
528 ** member to a maillist, add list to maillist table,
529 ** unless list is a user-group.
530 ** Then set_list_modtime_by_id.
534 ** argv[1] - member_type
535 ** argv[2] - member_id
539 followup_amtl(q, argv)
546 ## char list_name[33];
548 list_id = *(int *)argv[0];
550 ## repeat replace list (modtime = "now") where list.#list_id = @list_id
552 /* if query is not amtl or if member_type is not LIST then return */
553 if (bcmp(q->shortname, "amtl", 4) || bcmp(argv[1], "LIST", 4))
556 member_id = *(int *)argv[2];
557 ## range of l is list
558 ## range of ml is maillists
559 ## range of g is groups
561 /* is parent list a mailing list? */
562 ## repeat retrieve (exists = any(ml.#list_id where ml.#list_id=@list_id))
564 /* if not then return */
565 if (!exists) return(SMS_SUCCESS);
567 /* is member_list a user-group? */
569 ## repeat retrieve (exists = any(g.#list_id where g.#list_id = @member_id))
572 ## repeat retrieve (list_name = l.#name) where l.#list_id = @member_id
573 /* is list_name a username? */
574 ## repeat retrieve (exists = any(users.login
575 ## where users.login = @list_name))
576 /* yes, return error */
577 if (exists) return(SMS_USER_GROUP);
580 /* list is not a user-group; add list to maillist table */
581 ## repeat append maillists (#list_id = @member_id, ltid = l.tid)
582 ## where l.#list_id = @member_id
588 ** followup_add_pobox
589 ** followup_delete_pobox - followup routines for pobox queries
592 ** add_pobox: set pobox creation time
593 ** increment pop usage in serverhosts
595 ** delete_pobox: decrement pop usage in serverhosts
599 followup_add_pobox(q, argv)
603 set_pobox_creation(q, argv);
604 set_pop_usage(q, argv, 1);
608 followup_delete_pobox(q, argv)
612 set_pop_usage(q, argv, -1);
616 set_pobox_creation(q, argv)
625 users_id = *(int *)argv[0];
627 mach_id = *(int *)argv[2];
630 ## range of p is pobox
631 ## repeat replace p (created = "now")
632 ## where p.#users_id = @users_id and p.#type = @type and
633 ## p.#mach_id = @mach_id and p.#box = @box
635 return (SMS_SUCCESS);
639 ** set_pop_usage - incr/decr usage count for pop server in serverhosts talbe
642 ** q->name - "add_pobox" or "delete_pobox"
647 ** - incr/decr value field in serverhosts table for pop/mach_id
651 set_pop_usage(q, argv, count)
658 if (bcmp(argv[1], "POP", 3)) return(SMS_SUCCESS);
660 mach_id = *(int *)argv[2];
663 ## range of sh is serverhosts
664 ## repeat replace sh (value1 = sh.value1 + @n)
665 ## where sh.service = "pop" and sh.#mach_id = @mach_id
671 ** delete_user_poboxes - delete all poboxes for a user
674 ** argv[0] - users_id
678 delete_user_poboxes(q, argv)
688 users_id = *(int *)argv[0];
690 /* get machine ids for pop server(s) on which the user currently exists */
691 ## range of p is pobox
693 ## repeat retrieve (mach_id = p.#mach_id)
694 ## where p.#users_id = @users_id and p.type = "POP"
696 mach_ids[i++] = mach_id;
702 /* decrement counts on serverhost entries */
703 ## range of sh is serverhosts
705 mach_id = mach_ids[i];
706 ## repeat replace sh (value1 = sh.value1 - 1)
707 ## where sh.service = "pop" and sh.#mach_id = @mach_id
710 /* delete user's poboxes */
711 ## repeat delete p where p.#users_id = @users_id
719 ** delete_current_quota - adjust nfsphys values on xxx_quota queries.
724 ** argv[2] - users_id
725 ** argv[3] - quota (add_new_quota only)
728 ** delete_current_quota:
729 ** - find nfsquota entry
730 ** - decrement nfsphys.allocated by nfsquota.quota
732 ** - increment nfsphys.allocated by quota
736 add_new_quota(q, argv)
738 register char *argv[];
744 mach_id = *(int*)argv[0];
746 quota = *(int *)argv[3];
748 ## range of np is nfsphys
749 ## repeat replace np (allocated = np.allocated + @quota)
750 ## where np.#mach_id = @mach_id and np.#device = @device
755 delete_current_quota(q, argv, cl, access_check)
757 register char *argv[];
766 if (access_check) return(SMS_SUCCESS);
768 mach_id = *(int *)argv[0];
770 users_id = *(int *)argv[2];
772 ## range of np is nfsphys
773 ## range of nq is nfsquota
774 ## repeat retrieve (quota = nq.#quota)
775 ## where nq.#mach_id = @mach_id and nq.#device = @device and
776 ## nq.#users_id = @users_id
777 ## repeat replace np (allocated = np.allocated - @quota)
778 ## where np.#mach_id = @mach_id and np.#device = @device
784 ** delete_list_members - called after the delete_list query to clean up
787 ** Inputs: argv[0] - list_id
790 ** - foreach string member: decr string refc; ifzero, delete string
791 ** - delete all members entries for this list_id
795 delete_list_members(q, argv)
797 register char *argv[];
803 struct save_queue *sq;
804 struct save_queue *sq_create();
806 list_id = *(int *)argv[0];
809 ## range of m is members
810 ## repeat retrieve (string_id = m.member_id)
811 ## where m.#list_id = @list_id and m.member_type = "STRING"
813 sq_save_data(sq, string_id);
816 while (sq_get_data(sq, &string_id)) {
817 ## range of s is strings
818 ## repeat retrieve (refc = s.#refc) where s.#string_id = @string_id
819 ## inquire_equel (rowcount = "rowcount")
820 if (rowcount == 0) continue;
822 ## repeat delete s where s.#string_id = @string_id
824 ## repeat replace s (#refc = @refc) where s.#string_id = @string_id
829 ## repeat delete m where m.#list_id = @list_id
835 ** grvd_support - Support routine for get_rvd_servers query
838 ** q - grvd query structure
839 ** sq - save_queue struture: contains list of {machine, oper_acl_id,
840 ** admin_acl_id, shutdown_acl_id} records.
841 ** v - validate structure (not used)
842 ** action - action routine
843 ** actarg - action routine argument
846 ** - translate acl_ids to list names
850 grvd_support(q, sq, v, action, actarg)
852 struct save_queue *sq;
861 ## char shutdown[33];
868 ## range of l is list
870 while (sq_get_data(sq, &argv)) {
871 sscanf(argv[0], "%d", &list_id);
872 ## repeat retrieve (oper = l.name) where l.#list_id = @list_id
873 sscanf(argv[1], "%d", &list_id);
874 ## repeat retrieve (admin = l.name) where l.#list_id = @list_id
875 sscanf(argv[2], "%d", &list_id);
876 ## repeat retrieve (shutdown = l.name) where l.#list_id = @list_id
878 (*action)(3, targv, actarg);
888 gars_support(q, sq, v, action, actarg)
890 struct save_queue *sq;
899 ## char shutdown[33];
906 ## range of l is list
908 while (sq_get_data(sq, &argv)) {
909 sscanf(argv[1], "%d", &list_id);
910 ## repeat retrieve (oper = l.name) where l.#list_id = @list_id
911 sscanf(argv[2], "%d", &list_id);
912 ## repeat retrieve (admin = l.name) where l.#list_id = @list_id
913 sscanf(argv[3], "%d", &list_id);
914 ## repeat retrieve (shutdown = l.name) where l.#list_id = @list_id
917 (*action)(4, targv, actarg);
929 ** set_next_object_id - set next object id in values table
931 ** Inputs: object - object name in values table
933 ** - called before an APPEND operation to set the next object id to
934 ** be used for the new record
938 set_next_object_id(object)
944 ## range of v is values
945 ## repeat replace v (value = v.value + 1) where v.#name = @name
950 ** get_query_need - check modtime of query's associated table against given
951 ** time and return true if greater (false if not)
954 ** argv[0] - query name
955 ** argv[1] - time to compare against
959 get_query_need(q, argv, action, actarg)
961 register char *argv[];
965 ## char *last_get_time;
969 struct query *get_query_by_name();
971 q1 = get_query_by_name(argv[0]);
973 last_get_time = argv[1];
976 if (q1->type != RETRIEVE) return(SMS_NO_MATCH);
978 ## range of tbs is tblstats
979 ## repeat retrieve (need = any(tbs.modtime where tbs.#table = @table and
980 ## tbs.modtime > @last_get_time))
982 result = (need) ? "true" : "false";
983 (*action)(1, &result, actarg);
989 ** get_list_is_maillist
999 get_list_is_group(q, argv, action, actarg)
1009 list_id = *(int *)argv[0];
1011 ## range of g is groups
1012 ## repeat retrieve (exists = any(g.#list_id where g.#list_id = @list_id))
1014 result = (exists) ? "true" : "false";
1015 (*action)(1, &result, actarg);
1016 return(SMS_SUCCESS);
1019 get_list_is_maillist(q, argv, action, actarg)
1029 list_id = *(int *)argv[0];
1031 ## range of ml is maillists
1032 ## repeat retrieve (exists = any(ml.#list_id where ml.#list_id = @list_id))
1034 result = (exists) ? "true" : "false";
1035 (*action)(1, &result, actarg);
1036 return(SMS_SUCCESS);
1041 ** add_locker - special query routine for creating a user locker
1044 ** argv[0] - users_id
1045 ** argv[1] - machine_id
1047 ** argv[3] - initial quota
1050 ** - get prefix directory (dir) for mount point on specified machine/device
1051 ** - create filesys entry (label=<login>, type=NFS, machine=<machine>,
1052 ** mount=<dir>/<login>, access=w, acl=dbadmin)
1053 ** - increment allocated in nfsphys by quota
1054 ** - create nfsquota entry
1057 ** - SMS_NFSPHYS - machine/device does not exist in nfsphys
1058 ** - SMS_FILESYS_EXISTS - file system already exists
1063 register struct query *q;
1078 /* copy arguments */
1079 users_id = *(int *)argv[0];
1080 mach_id = *(int *)argv[1];
1082 sscanf(argv[3], "%d", "a);
1084 ## range of u is users
1085 ## range of f is filesys
1086 ## range of np is nfsphys
1087 ## range of tbs is tblstats
1089 /* get login name */
1090 ## repeat retrieve (login = u.#login) where u.#users_id = @users_id
1092 /* get user's acl id */
1093 ## repeat retrieve (user_acl = list.list_id) where list.name = @login
1095 /* get filesystem directory prefix; give error if machine/device
1096 pair not in nfsphys table */
1097 printf("np.mach_id = %d and np.device = %s\n", mach_id, device);
1099 ## repeat retrieve (dir = np.#dir, allocated = np.#allocated)
1100 ## where np.#mach_id = @mach_id and np.#device = @device
1101 ## inquire_equel (rowcount = "rowcount")
1102 if (rowcount == 0) return(SMS_NFSPHYS);
1104 /* make sure a filesys with user's name does not already exist */
1105 ## repeat retrieve (rowcount = any(f.label where f.label = @login))
1106 if (rowcount != 0) return(SMS_FILESYS_EXISTS);
1108 /* create a new filesys */
1109 sprintf(locker, "%s/%s", dir, login);
1110 sprintf(mount, "/mit/%s", login);
1111 ## repeat append filesys
1112 ## (#label = @login, type = "NFS", #mach_id = @mach_id,
1113 ## name = @locker, access = "w", order = 1, #mount = @mount,
1114 ## acl_id = @user_acl)
1115 ## repeat replace tbs (appends = tbs.appends + 1, modtime = "now")
1116 ## where tbs.table = "filesys"
1118 /* increment usage count in nfsphys table */
1120 ## replace np (#allocated = allocated)
1121 ## where np.#mach_id = mach_id and np.#device = device
1122 ## repeat replace tbs (updates = tbs.updates + 1, modtime = "now")
1123 ## where tbs.table = "nfsphys"
1125 /* create nfsquota entry */
1126 ## append nfsquota (#users_id = users_id, #mach_id = mach_id,
1127 ## #device = device, #quota = quota)
1128 ## repeat replace tbs (appends = tbs.appends + 1, modtime = "now")
1129 ## where tbs.table = "nfsquota"
1131 return(SMS_SUCCESS);
1135 ** delete_locker - special query routine for deleting a user locker
1138 ** argv[0] - users_id
1139 ** argv[1] - machine_id
1144 ** - delete filesys entry (label=<login>)
1145 ** - decrement allocated in nfsphys by quota
1146 ** - delete nfsquota entry
1149 ** - SMS_FILESYS - no filesys exists for user
1153 delete_locker(q, argv)
1154 register struct query *q;
1155 register char *argv[];
1164 /* copy arguments */
1165 users_id = *(int *)argv[0];
1166 mach_id = *(int *)argv[1];
1168 sscanf(argv[3], "%d", "a);
1170 ## range of u is users
1171 ## range of f is filesys
1172 ## range of np is nfsphys
1173 ## range of nq is nfsquota
1174 ## range of tbs is tblstats
1176 /* get login name */
1177 ## repeat retrieve (login = u.#login) where u.#users_id = @users_id
1179 /* delete the filesys entry */
1180 ## repeat delete f where f.label = @login
1181 ## inquire_equel (rowcount = "rowcount")
1182 if (rowcount == 0) return(SMS_FILESYS);
1183 ## repeat replace tbs (deletes = tbs.deletes + 1, modtime = "now")
1184 ## where tbs.table = "filesys"
1186 /* decrement usage count in nfsphys table */
1187 ## replace np (#allocated = np.#allocated - quota)
1188 ## where np.#mach_id = mach_id and np.#device = device
1189 ## repeat replace tbs (updates = tbs.updates + 1, modtime = "now")
1190 ## where tbs.table = "nfsphys"
1192 /* delete nfsquota entry */
1193 ## delete nq where nq.#users_id = users_id and nq.#mach_id = mach_id and
1194 ## nq.#device = device
1195 ## repeat replace tbs (deletes = tbs.deletes + 1, modtime = "now")
1196 ## where tbs.table = "nfsquota"
1198 return(SMS_SUCCESS);
1202 ** add_user_group - create a group for a user and add user to group
1208 ** - verify specified user exists
1209 ** - create a list of same name as user
1210 ** - add user as a member of the list
1214 add_user_group(q, argv)
1226 /* verify user exists */
1227 ## repeat retrieve (users_id = users.#users_id) where users.#login = @login
1228 ## inquire_equel (exists = "rowcount")
1229 if (exists != 1) return(SMS_USER);
1231 /* verify list does not exist */
1232 ## repeat retrieve (exists = any(list.name where list.name = @login))
1233 if (exists) return(SMS_LIST);
1235 /* get new list_id */
1236 ## repeat retrieve (list_id = values.value) where values.name = "list_id"
1238 ## repeat replace values (value = @list_id) where values.name = "list_id"
1240 /* create the list */
1241 ## repeat append list (name = @login, #list_id = @list_id, flags = 1,
1242 ## desc = "User Group", acl_id = @list_id,
1243 ## expdate = "today" + "5 years", modtime = "now")
1245 /* add user to list */
1246 ## repeat append members (#list_id = @list_id, member_type = "USER",
1247 ## member_id = @users_id)
1250 ## range of g is groups
1251 ## range of v is values
1252 ## repeat retrieve (gid = v.value) where v.name = "gid"
1256 ## repeat retrieve (exists = any(g.#gid where g.#gid = @gid))
1258 ## repeat replace v (value = @gid) where v.name = "gid"
1260 /* add list to group table */
1261 ## repeat append groups (#list_id = @list_id, ltid = list.tid, #gid = @gid)
1262 ## where list.#list_id = @list_id
1264 /* and we're done */
1265 return(SMS_SUCCESS);
1270 ** get_members_of_list - optimized query for retrieval of list members
1273 ** argv[0] - list_id
1276 ** - retrieve USER members, then LIST members, then STRING members
1280 get_members_of_list(q, argv, action, actarg)
1287 ## char member_name[129];
1290 list_id = *(int *)argv[0];
1292 targv[1] = member_name;
1294 ## range of m is members
1295 ## repeat retrieve (member_name = users.login)
1296 ## where m.#list_id = @list_id and m.member_type = "USER"
1297 ## and m.member_id = users.users_id
1298 ## sort by #member_name
1300 (*action)(2, targv, actarg);
1304 ## repeat retrieve (member_name = list.name)
1305 ## where m.#list_id = @list_id and m.member_type = "LIST"
1306 ## and m.member_id = list.#list_id
1307 ## sort by #member_name
1309 (*action)(2, targv, actarg);
1312 targv[0] = "STRING";
1313 ## repeat retrieve (member_name = strings.string)
1314 ## where m.#list_id = @list_id and m.member_type = "STRING"
1315 ## and m.member_id = strings.string_id
1316 ## sort by #member_name
1318 (*action)(2, targv, actarg);
1321 return(SMS_SUCCESS);
1325 ** get_groups_of_user - optimized query for retrieval of all groups to
1326 ** which a user belongs
1330 get_groups_of_user(q, argv, action, actarg)
1337 ## char list_name[33];
1342 users_id = *(int *)argv[0];
1343 targv[0] = list_name;
1346 ## range of m is members
1348 ## repeat retrieve (list_name = list.name, gid = text(groups.#gid))
1349 ## where m.member_id = @users_id and m.member_type = "USER" and
1350 ## m.list_id = groups.list_id and groups.ltid = list.tid
1351 ## sort by #list_name
1353 (*action)(2, targv, actarg);
1355 ## inquire_equel (rowcount = "rowcount")
1357 return ((rowcount = 0) ? SMS_NO_MATCH : SMS_SUCCESS);
1360 get_groups_of_all_users(q, argv, action, actarg)
1371 ## range of u is users
1372 ## range of l is list
1373 ## range of m is members
1374 ## range of g is groups
1376 ## repeat retrieve (login = u.#login, group = l.name, gid = g.#gid)
1377 ## where m.member_type = "USER" and m.member_id = u.users_id and
1378 ## u.status != 0 and m.list_id = g.list_id and
1380 ## sort by #login, #group
1382 ## inquire_equel (errorno = "errorno")
1384 return((errorno) ? SMS_INGRES_ERR : SMS_SUCCESS);
1388 ** get_all_poboxes - optimized query for retrieval of all poboxes
1391 ** - retrieve LOCAL boxes, then POP boxes, then FOREIGN boxes
1395 get_all_poboxes(q, argv, action, actarg)
1402 ## char machine[129];
1411 ## range of p is pobox
1412 ## repeat retrieve (login=users.#login, machine = #machine.name, box=p.#box)
1413 ## where p.type = "LOCAL" and p.users_id = users.users_id
1414 ## and p.mach_id = #machine.mach_id
1416 (*action)(4, targv, actarg);
1420 ## repeat retrieve (login=users.#login, machine = #machine.name, box=p.#box)
1421 ## where p.type = "POP" and p.users_id = users.users_id
1422 ## and p.mach_id = #machine.mach_id
1424 (*action)(4, targv, actarg);
1427 targv[1] = "FOREIGN";
1428 ## repeat retrieve (login=users.#login, machine=strings.string, box=p.#box)
1429 ## where p.type = "FOREIGN" and p.users_id = users.users_id
1430 ## and p.mach_id = strings.string_id
1432 (*action)(4, targv, actarg);
1435 return(SMS_SUCCESS);
1438 get_new_poboxes(q, argv, action, actarg)
1446 ## char machine[129];
1457 ## range of p is pobox
1458 ## repeat retrieve (login=users.#login, machine = #machine.name, box=p.#box)
1459 ## where p.type = "LOCAL" and p.users_id = users.users_id
1460 ## and p.mach_id = #machine.mach_id and
1461 ## p.#created > @created
1463 (*action)(4, targv, actarg);
1467 ## repeat retrieve (login=users.#login, machine = #machine.name, box=p.#box)
1468 ## where p.type = "POP" and p.users_id = users.users_id
1469 ## and p.mach_id = #machine.mach_id and
1470 ## p.#created > @created
1472 (*action)(4, targv, actarg);
1475 targv[1] = "FOREIGN";
1476 ## repeat retrieve (login=users.#login, machine=strings.string, box=p.#box)
1477 ## where p.type = "FOREIGN" and p.users_id = users.users_id
1478 ## and p.mach_id = strings.string_id and
1479 ## p.#created > @created
1481 (*action)(4, targv, actarg);
1484 return(SMS_SUCCESS);
1487 /* Validation Routines */
1489 validate_row(q, argv, v)
1490 register struct query *q;
1492 register struct validate *v;
1500 /* build where clause */
1501 build_qual(v->qual, v->argc, argv, qual);
1503 /* setup ingres variables */
1508 if (log_flags & LOG_RES)
1509 /* tell the logfile what we're doing */
1510 com_err(whoami, 0, "validating row: %s", qual);
1512 /* look for the record */
1513 ## range of rvar is table
1514 ## retrieve (rowcount = count(rvar.name where qual))
1515 if (rowcount == 0) return(SMS_NO_MATCH);
1516 if (rowcount > 1) return(SMS_NOT_UNIQUE);
1520 validate_fields(q, argv, vo, n)
1522 register char *argv[];
1523 register struct valobj *vo;
1526 register int status;
1531 if (log_flags & LOG_RES)
1532 com_err(whoami, 0, "validating %s in %s: %s",
1533 vo->namefield, vo->table, argv[vo->index]);
1534 status = validate_name(argv, vo);
1538 if (log_flags & LOG_RES)
1539 com_err(whoami, 0, "validating %s in %s: %s",
1540 vo->idfield, vo->table, argv[vo->index]);
1541 status = validate_id(argv, vo);
1545 if (log_flags & LOG_RES)
1546 com_err(whoami, 0, "validating date: %s", argv[vo->index]);
1547 status = validate_date(argv, vo);
1551 if (log_flags & LOG_RES)
1552 com_err(whoami, 0, "validating %s type: %s",
1553 vo->table, argv[vo->index]);
1554 status = validate_type(argv, vo);
1558 if (log_flags & LOG_RES)
1559 com_err(whoami, 0, "validating typed data (%s): %s",
1560 argv[vo->index - 1], argv[vo->index]);
1561 status = validate_typedata(q, argv, vo);
1565 status = SMS_EXISTS;
1569 status = SMS_EXISTS;
1574 if (status != SMS_EXISTS) return(status);
1578 return(SMS_SUCCESS);
1581 validate_id(argv, vo)
1583 register struct valobj *vo;
1592 name = argv[vo->index];
1594 namefield = vo->namefield;
1595 idfield = vo->idfield;
1596 ## retrieve (id = table.idfield) where table.namefield = name
1597 ## inquire_equel (rowcount = "rowcount")
1598 if (rowcount != 1) return(vo->error);
1599 *(int *)argv[vo->index] = id;
1603 validate_name(argv, vo)
1605 register struct valobj *vo;
1612 name = argv[vo->index];
1614 namefield = vo->namefield;
1615 ## retrieve (rowcount = countu(table.namefield
1616 ## where table.namefield = name))
1617 return ((rowcount == 1) ? SMS_EXISTS : vo->error);
1620 validate_date(argv, vo)
1628 idate = argv[vo->index];
1630 ## retrieve (dd = interval("years", date(idate) - date("today")))
1631 ## inquire_equel (errorno = "errorno")
1632 if (errorno != 0 || dd > 5.0) return(SMS_DATE);
1633 return(SMS_SUCCESS);
1636 validate_type(argv, vo)
1638 register struct valobj *vo;
1645 typename = vo->table;
1646 value = argv[vo->index];
1648 /* uppercase type fields */
1649 for (c = value; *c; c++) if (islower(*c)) *c = toupper(*c);
1651 ## range of a is alias
1652 ## repeat retrieve (rowcount = count(a.trans where a.name = @typename and
1653 ## a.type = "TYPE" and
1654 ## a.trans = @value))
1655 return ((rowcount == 1) ? SMS_EXISTS : vo->error);
1658 /* validate member or type-specific data field */
1660 validate_typedata(q, argv, vo)
1661 register struct query *q;
1662 register char *argv[];
1663 register struct valobj *vo;
1666 ## char *field_type;
1667 ## char data_type[17];
1673 /* get named object */
1674 name = argv[vo->index];
1676 /* get field type string (known to be at index-1) */
1677 field_type = argv[vo->index-1];
1679 /* get corresponding data type associated with field type name */
1680 ## repeat retrieve (data_type = alias.trans)
1681 ## where alias.#name = @field_type and alias.type = "TYPEDATA"
1682 ## inquire_equel (rowcount = "rowcount")
1683 if (rowcount != 1) return(SMS_TYPE);
1685 /* now retrieve the record id corresponding to the named object */
1687 if (!strcmp(data_type, "user")) {
1689 ## repeat retrieve (id = users.users_id) where users.login = @name
1690 ## inquire_equel (rowcount = "rowcount")
1691 if (rowcount != 1) return(SMS_USER);
1693 } else if (!strcmp(data_type, "list")) {
1695 ## repeat retrieve (id = list.list_id) where list.#name = @name
1696 ## inquire_equel (rowcount = "rowcount")
1697 if (rowcount != 1) return(SMS_LIST);
1699 } else if (!strcmp(data_type, "machine")) {
1701 for (c = name; *c; c++) if (islower(*c)) *c = toupper(*c);
1702 ## repeat retrieve (id = machine.mach_id) where machine.#name = @name
1703 ## inquire_equel (rowcount = "rowcount")
1704 if (rowcount != 1) return(SMS_MACHINE);
1706 } else if (!strcmp(data_type, "string")) {
1708 ## range of s is strings
1709 ## repeat retrieve (id = s.string_id, refc = s.#refc)
1710 ## where s.string = @name
1711 ## inquire_equel (rowcount = "rowcount")
1712 if (rowcount == 0) {
1713 if (q->type != APPEND) return(SMS_STRING);
1714 ## range of v is values
1715 ## retrieve (id = v.value) where v.#name = "strings_id"
1717 ## replace v (value = id) where v.#name = "strings_id"
1718 ## append to strings (string_id = id, string = name, #refc = 1)
1719 } else if (rowcount == 1) {
1720 if (q->type == APPEND || q->type == DELETE) {
1721 refc += (q->type == APPEND) ? 1 : -1;
1723 ## replace s (#refc = refc) where s.string_id = id
1725 ## delete s where s.string_id = id
1733 /* now set value in argv */
1734 *(int *)argv[vo->index] = id;
1736 return (SMS_EXISTS);
1740 translate_ids(q, sq, v, action, actarg)
1741 register struct query *q;
1742 register struct save_queue *sq;
1743 register struct validate *v;
1744 register int (*action)();
1748 ## char *field_type;
1749 ## char data_type[17];
1756 for (i = 0; i < v->objcnt; i++) {
1758 if (vo->type == V_FOLLOWUP) break;
1762 while (sq_get_data(sq, &argv)) {
1766 sscanf(argv[i], "%d", &id);
1768 name = (char *)malloc(129);
1771 /* get field type string (known to be at index-1) */
1772 field_type = argv[vo->index-1];
1774 /* get corresponding data type associated with field type name */
1775 ## repeat retrieve (data_type = alias.trans)
1776 ## where alias.#name = @field_type and alias.type = "TYPEDATA"
1777 ## inquire_equel (rowcount = "rowcount")
1778 if (rowcount != 1) {
1779 sprintf(name, "%d", id);
1780 (*action)(q->vcnt, argv, actarg);
1784 /* retrieve object name */
1786 if (!strcmp(data_type, "user")) {
1788 ## repeat retrieve (name = users.login) where users.users_id = @id
1789 ## inquire_equel (rowcount = "rowcount")
1791 } else if (!strcmp(data_type, "list")) {
1793 ## repeat retrieve (name = list.#name) where list.list_id = @id
1794 ## inquire_equel (rowcount = "rowcount")
1796 } else if (!strcmp(data_type, "machine")) {
1798 ## repeat retrieve (name = machine.#name) where machine.mach_id = @id
1799 ## inquire_equel (rowcount = "rowcount")
1801 } else if (!strcmp(data_type, "string")) {
1803 ## repeat retrieve (name = strings.string)
1804 ## where strings.string_id = @id
1805 ## inquire_equel (rowcount = "rowcount")
1811 /* if there wasn't a corresponding object name, then use the id */
1812 if (rowcount != 1) sprintf(name, "%d", id);
1815 (*action)(q->vcnt, argv, actarg);
1817 /* free saved data */
1818 for (i = 0; i < q->vcnt; i++)
1824 return (SMS_SUCCESS);
1831 * c-continued-statement-offset: 4
1832 * c-brace-offset: -4
1833 * c-argdecl-indent: 4
1834 * c-label-offset: -4