6 * Copyright (C) 1987 by the Massachusetts Institute of Technology
7 * For copying and distribution information, please see the file
13 static char *rcsid_qsupport_qc = "$Header$";
16 #include <mit-copyright.h>
18 #include "sms_server.h"
22 extern char *whoami, *strsave();
23 extern int ingres_errno, sms_errcode;
26 /* Specialized Access Routines */
28 /* access_user - verify that client name equals specified login name
30 * - since field validation routines are called first, a users_id is
31 * now in argv[0] instead of the login name.
34 access_user(q, argv, cl)
39 if (cl->users_id != *(int *)argv[0])
47 /* access_login - verify that client name equals specified login name
49 * argv[0...n] contain search info. q->
52 access_login(q, argv, cl)
60 build_qual(q->qual, q->argc, argv, qual);
61 ## retrieve (id = u.users_id) where qual
62 ## inquire_equel(rowcount = "rowcount")
63 if (rowcount != 1 || id != cl->users_id)
71 /* access_list - check access for most list operations
73 * Inputs: argv[0] - list_id
75 * argv[2] - member ID (only for queries "amtl" and "dmfl")
76 * argv[7] - group IID (only for query "ulis")
79 * - check that client is a member of the access control list
80 * - OR, if the query is add_member_to_list or delete_member_from_list
81 * and the list is public, allow access if client = member
84 access_list(q, argv, cl)
89 ## int list_id, acl_id, flags, rowcount, gid;
92 int client_id, status;
94 list_id = *(int *)argv[0];
95 ## repeat retrieve (acl_id = list.#acl_id, acl_type = list.#acl_type,
96 ## gid = list.#gid, flags = list.#public)
97 ## where list.#list_id = @list_id
98 ## inquire_equel(rowcount = "rowcount")
100 return(SMS_INTERNAL);
102 /* parse client structure */
103 if ((status = get_client(cl, &client_type, &client_id)) != SMS_SUCCESS)
106 /* if amtl or dmfl and list is public allow client to add or delete self */
107 if ((!strcmp("amtl", q->shortname) || !strcmp("dmfl", q->shortname)) &&
108 (flags && !strcmp("USER", argv[1]))) {
109 if (*(int *)argv[2] == client_id) return(SMS_SUCCESS);
110 /* if update_list, don't allow them to change the GID */
111 } else if (!strcmp("ulis", q->shortname)) {
112 if ((!strcmp(argv[7], UNIQUE_GID) && (gid != -1)) ||
113 (strcmp(argv[7], UNIQUE_GID) && (gid != atoi(argv[7]))))
117 /* check for client in access control list */
118 status = find_member(acl_type, acl_id, client_type, client_id, 0);
119 if (!status) return(SMS_PERM);
125 /* access_visible_list - allow access to list only if it is not hidden,
126 * or if the client is on the ACL
128 * Inputs: argv[0] - list_id
129 * cl - client identifier
132 access_visible_list(q, argv, cl)
137 ## int list_id, acl_id, flags, rowcount;
140 int client_id, status;
142 list_id = *(int *)argv[0];
143 ## repeat retrieve (flags = list.hidden, acl_id = list.#acl_id,
144 ## acl_type = list.#acl_type) where list.#list_id = @list_id
145 ## inquire_equel(rowcount = "rowcount")
147 return(SMS_INTERNAL);
151 /* parse client structure */
152 if ((status = get_client(cl, &client_type, &client_id)) != SMS_SUCCESS)
155 /* check for client in access control list */
156 status = find_member(acl_type, acl_id, client_type, client_id, 0);
164 /* access_vis_list_by_name - allow access to list only if it is not hidden,
165 * or if the client is on the ACL
167 * Inputs: argv[0] - list name
168 * cl - client identifier
171 access_vis_list_by_name(q, argv, cl)
176 ## int acl_id, flags, rowcount;
177 ## char acl_type[9], *listname;
179 int client_id, status;
182 ## repeat retrieve (flags = list.hidden, acl_id = list.#acl_id,
183 ## acl_type = list.#acl_type) where list.#name = @listname
184 ## inquire_equel(rowcount = "rowcount");
186 return(SMS_WILDCARD);
188 return(SMS_NO_MATCH);
192 /* parse client structure */
193 if ((status = get_client(cl, &client_type, &client_id)) != SMS_SUCCESS)
196 /* check for client in access control list */
197 status = find_member(acl_type, acl_id, client_type, client_id, 0);
205 /* access_member - allow user to access member of type "USER" and name matches
206 * username, or to access member of type "LIST" and list is one that user is
207 * on the acl of, or the list is visible.
210 access_member(q, argv, cl)
215 if (!strcmp(argv[0], "LIST") || !strcmp(argv[0], "RLIST"))
216 return(access_visible_list(q, &argv[1], cl));
218 if (!strcmp(argv[0], "USER") || !strcmp(argv[0], "RUSER")) {
219 if (cl->users_id == *(int *)argv[1])
227 /* access_qgli - special access routine for Qualified_get_lists. Allows
228 * access iff argv[0] == "TRUE" and argv[2] == "FALSE".
231 access_qgli(q, argv, cl)
236 if (!strcmp(argv[0], "TRUE") && !strcmp(argv[2], "FALSE"))
242 /* access_service - allow access if user is on ACL of service. Don't
243 * allow access if a wildcard is used.
246 access_service(q, argv, cl)
251 ## int acl_id, rowcount;
252 ## char *name, acl_type[9];
253 int client_id, status;
257 ## repeat retrieve (acl_id = servers.#acl_id, acl_type = servers.#acl_type)
258 ## where servers.#name = uppercase(@name)
259 ## inquire_equel(rowcount = "rowcount")
263 /* parse client structure */
264 if ((status = get_client(cl, &client_type, &client_id)) != SMS_SUCCESS)
267 /* check for client in access control list */
268 status = find_member(acl_type, acl_id, client_type, client_id, 0);
269 if (!status) return(SMS_PERM);
276 /* access_filesys - verify that client is owner or on owners list of filesystem
280 access_filesys(q, argv, cl)
285 ## int rowcount, users_id, list_id;
287 int status, client_id;
291 ## repeat retrieve (users_id = filesys.owner, list_id = filesys.owners)
292 ## where filesys.label = @name
293 ## inquire_equel(rowcount = "rowcount")
297 if (users_id == cl->users_id)
299 if ((status = get_client(cl, &client_type, &client_id)) != SMS_SUCCESS)
301 status = find_member("LIST", list_id, client_type, client_id, 0);
311 /* Setup routine for add_user
313 * Inputs: argv[0] - login
318 * - if argv[1] == UNIQUE_UID then set argv[1] = next(uid)
319 * - if argv[0] == UNIQUE_LOGIN then set argv[0] = "#<uid>"
322 setup_ausr(q, argv, cl)
324 register char *argv[];
327 ## int nuid, rowcount;
329 if (!strcmp(argv[1], UNIQUE_UID) || atoi(argv[1]) == -1) {
330 if (set_next_object_id("uid", "users"))
331 return(SMS_INGRES_ERR);
332 ## repeat retrieve (nuid = values.value) where values.name = "uid"
333 ## inquire_equel(rowcount = "rowcount")
335 return(SMS_INTERNAL);
336 sprintf(argv[1], "%d", nuid);
339 if (!strcmp(argv[0], UNIQUE_LOGIN) || atoi(argv[1]) == -1) {
340 sprintf(argv[0], "#%s", argv[1]);
347 /* setup_dusr - verify that the user is no longer being referenced
348 * and may safely be deleted.
351 int setup_dusr(q, argv)
357 id = *(int *)argv[0];
359 /* For now, only allow users to be deleted if their status is 0 */
360 ## repeat retrieve (flag = u.status) where u.users_id = @id
364 ## repeat delete nfsquota where nfsquota.users_id = @id
365 ## repeat retrieve (flag = any(members.member_id where members.member_id=@id
366 ## and members.member_type = "USER"))
369 ## repeat retrieve (flag = any(filesys.label where filesys.owner=@id))
372 ## repeat retrieve (flag = any(list.name where list.acl_id=@id and
373 ## list.acl_type = "USER"))
376 ## repeat retrieve (flag = any(servers.name where servers.acl_id=@id and
377 ## servers.acl_type = "USER"))
380 ## repeat retrieve (flag=any(hostaccess.acl_id where hostaccess.acl_id=@id and
381 ## hostaccess.acl_type = "USER"))
389 /* setup_spop: verify that there is already a valid POP machine_id in the
390 * pop_id field. Also take care of keeping track of the post office usage.
392 int setup_spop(q, argv)
396 ## int id, mid, flag;
399 id = *(int *)argv[0];
400 ## repeat retrieve (type = u.potype, mid = u.pop_id,
401 ## flag = any(machine.name where machine.mach_id = u.pop_id
402 ## and u.pop_id != 0 and u.users_id = @id))
403 ## where u.users_id = @id
406 if (strcmp(strtrim(type), "POP"))
407 set_pop_usage(mid, 1);
412 /* setup_dpob: Take care of keeping track of the post office usage.
414 int setup_dpob(q, argv)
421 user = *(int *)argv[0];
422 ## repeat retrieve (type = u.potype, id = u.pop_id)
423 ## where u.users_id = @user
425 if (!strcmp(strtrim(type), "POP"))
426 set_pop_usage(id, -1);
431 /* setup_dmac - verify that the machine is no longer being referenced
432 * and may safely be deleted.
435 int setup_dmac(q, argv)
441 id = *(int *)argv[0];
442 ## repeat retrieve (flag = any(users.login where users.potype = "POP"
443 ## and users.pop_id=@id))
446 ## repeat retrieve (flag = any(serverhosts.mach_id
447 ## where serverhosts.mach_id=@id))
450 ## repeat retrieve (flag = any(nfsphys.mach_id where nfsphys.mach_id=@id))
453 ## repeat retrieve (flag = any(hostaccess.mach_id where hostaccess.mach_id=@id))
456 ## repeat retrieve (flag = any(printcap.mach_id where printcap.mach_id=@id))
460 ## repeat delete mcmap where mcmap.mach_id = @id
465 /* setup_dclu - verify that the cluster is no longer being referenced
466 * and may safely be deleted.
469 int setup_dclu(q, argv)
475 id = *(int *)argv[0];
476 ## repeat retrieve (flag = any(mcmap.mach_id where mcmap.clu_id=@id))
479 ## repeat retrieve (flag = any(svc.clu_id where svc.clu_id=@id))
487 /* setup_alis - if argv[5] is non-zero and argv[6] is UNIQUE_ID, then allocate
488 * a new gid and put it in argv[6]. Otherwise if argv[6] is UNIQUE_ID but
489 * argv[5] is not, then remember that UNIQUE_ID is being stored by putting
490 * a -1 there. Remember that this is also used for ulis, with the indexes
494 int setup_alis(q, argv)
502 if (!strcmp(q->shortname, "alis"))
504 else if (!strcmp(q->shortname, "ulis"))
507 if (!strcmp(argv[idx], UNIQUE_GID) || atoi(argv[idx]) == -1) {
508 if (atoi(argv[idx - 1])) {
509 if (set_next_object_id("gid", "list"))
510 return(SMS_INGRES_ERR);
511 ## repeat retrieve (ngid = values.value) where values.name = "gid"
512 sprintf(argv[idx], "%d", ngid);
514 strcpy(argv[idx], "-1");
522 /* setup_dlist - verify that the list is no longer being referenced
523 * and may safely be deleted.
526 int setup_dlis(q, argv)
532 id = *(int *)argv[0];
533 ## repeat retrieve (flag = any(members.member_id where members.member_id=@id
534 ## and members.member_type = "LIST"))
537 ## repeat retrieve (flag = any(members.member_id where members.list_id=@id))
540 ## repeat retrieve (flag = any(filesys.label where filesys.owners=@id))
543 ## repeat retrieve (flag = any(capacls.tag where capacls.list_id=@id))
546 ## repeat retrieve (flag = any(list.name where list.acl_id=@id and
547 ## list.acl_type = "LIST" and list.list_id != @id))
550 ## repeat retrieve (flag = any(servers.name where servers.acl_id=@id and
551 ## servers.acl_type = "LIST"))
554 ## repeat retrieve (flag=any(hostaccess.acl_id where hostaccess.acl_id=@id and
555 ## hostaccess.acl_type = "LIST"))
558 ## repeat retrieve (flag = any(zephyr.class
559 ## where zephyr.xmt_type = "LIST" and zephyr.xmt_id = @id or
560 ## zephyr.sub_type = "LIST" and zephyr.sub_id = @id or
561 ## zephyr.iws_type = "LIST" and zephyr.iws_id = @id or
562 ## zephyr.iui_type = "LIST" and zephyr.iui_id = @id))
570 /* setup_dsin - verify that the service is no longer being referenced
571 * and may safely be deleted.
574 int setup_dsin(q, argv)
582 ## repeat retrieve (flag = any(serverhosts.service
583 ## where serverhosts.service=uppercase(@name)))
586 ## repeat retrieve (flag = servers.inprogress) where servers.#name = @name
594 /* setup_dshi - verify that the service-host is no longer being referenced
595 * and may safely be deleted.
598 int setup_dshi(q, argv)
606 id = *(int *)argv[1];
607 ## repeat retrieve (flag=serverhosts.inprogress)
608 ## where serverhosts.service=uppercase(@name) and serverhosts.mach_id=@id
617 ** setup_add_filesys - verify existance of referenced file systems
629 ** * extract directory prefix from name
630 ** * verify mach_id/dir in nfsphys
631 ** * verify access in {r, w, R, W}
633 ** Side effect: sets variable var_phys_id to the ID of the physical
634 ** filesystem (nfsphys_id for NFS, 0 for RVD)
637 ** SMS_NFS - specified directory not exported
638 ** SMS_FILESYS_ACCESS - invalid filesys access
642 ##static int var_phys_id;
654 mach_id = *(int *)argv[2];
659 if (!strcmp(type, "NFS"))
660 return (check_nfs(mach_id, name, access));
666 /* Verify the arguments, depending on the FStype. Also, if this is an
667 * NFS filesystem, then update any quotas for that filesystem to reflect
676 char *type, *name, *access;
680 mach_id = *(int *)argv[3];
685 if (!strcmp(type, "NFS")) {
686 status = check_nfs(mach_id, name, access);
687 fid = *(int *)argv[0];
688 ## replace nfsquota (phys_id = var_phys_id) where nfsquota.filsys_id = fid
695 /* Find the NFS physical partition that the named directory is on.
696 * This is done by comparing the dir against the mount point of the
697 * partition. To make sure we get the correct match when there is
698 * more than one, we sort the query in reverse order by dir name.
701 ##check_nfs(mach_id, name, access)
712 caccess = (isupper(*access)) ? tolower(*access) : *access;
713 if (caccess != 'r' && caccess != 'w') return(SMS_FILESYS_ACCESS);
716 ## range of np is nfsphys
717 ## repeat retrieve (var_phys_id = np.#nfsphys_id, dir = trim(np.#dir))
718 ## where np.#mach_id = @mach_id sort by #dir:d {
722 if (*cp1++ != *cp2) break;
726 status = SMS_SUCCESS;
735 /* setup_dfil: free any quota records and fsgroup info associated with
736 * a filesystem when it is deleted. Also adjust the allocation numbers.
739 setup_dfil(q, argv, cl)
746 id = *(int *)argv[0];
747 ## range of q is nfsquota
748 ## range of fs is filesys
749 ## range of n is nfsphys
750 ## repeat replace n (allocated=n.allocated-sum(q.quota where q.filsys_id=@id))
751 ## where n.nfsphys_id = fs.phys_id and fs.filsys_id = @id
753 ## repeat delete q where q.filsys_id = @id
754 ## repeat delete fsgroup where fsgroup.filsys_id = @id
755 ## repeat delete fsgroup where fsgroup.group_id = @id
760 /* setup_dnfp: check to see that the nfs physical partition does not have
761 * any filesystems assigned to it before allowing it to be deleted.
764 setup_dnfp(q, argv, cl)
771 id = *(int *)argv[0];
772 ## repeat retrieve (exists = any(filesys.label where filesys.phys_id = @id))
779 /* setup_dnfq: Remove allocation from nfsphys before deleting quota.
780 * argv[0] = filsys_id
784 setup_dnfq(q, argv, cl)
789 ## int quota, fs, user;
791 fs = *(int *)argv[0];
792 user = *(int *)argv[1];
794 ## range of q is nfsquota
795 ## repeat retrieve (quota = q.#quota) where q.users_id = @user and
797 ## repeat replace nfsphys (allocated = nfsphys.allocated - @quota)
798 ## where nfsphys.nfsphys_id = filesys.#phys_id and filesys.filsys_id = @fs
804 /* FOLLOWUP ROUTINES */
806 /* generic set_modtime routine. This takes the table name from the query,
807 * and will update the modtime, modby, and modwho fields in the entry in
808 * the table whose name field matches argv[0].
811 set_modtime(q, argv, cl)
816 ## char *name, *entity, *table;
824 ## replace table (modtime = "now", modby = who, modwith = entity)
825 ## where table.#name = name
829 /* generic set_modtime_by_id routine. This takes the table name from
830 * the query, and the id name from the validate record,
831 * and will update the modtime, modby, and modwho fields in the entry in
832 * the table whose id matches argv[0].
835 set_modtime_by_id(q, argv, cl)
840 ## char *entity, *table, *id_name;
846 id_name = q->validate->object_id;
848 id = *(int *)argv[0];
849 ## replace table (modtime = "now", modby = who, modwith = entity)
850 ## where table.id_name = id
855 /* Sets the finger modtime on a user record. The users_id will be in argv[0].
858 set_finger_modtime(q, argv, cl)
863 ## int users_id, who;
868 users_id = *(int *)argv[0];
870 ## repeat replace u (fmodtime = "now", fmodby = @who, fmodwith = @entity)
871 ## where u.#users_id = @users_id
876 /* Sets the pobox modtime on a user record. The users_id will be in argv[0].
879 set_pobox_modtime(q, argv, cl)
884 ## int users_id, who;
889 users_id = *(int *)argv[0];
891 ## repeat replace users (pmodtime = "now", pmodby = @who, pmodwith = @entity)
892 ## where users.#users_id = @users_id
897 /* Like set_modtime, but uppercases the name first.
900 set_uppercase_modtime(q, argv, cl)
905 ## char *name, *entity, *table;
913 ## replace table (modtime = "now", modby = who, modwith = entity)
914 ## where table.#name = uppercase(name)
919 /* Sets the modtime on the machine whose mach_id is in argv[0]. This routine
920 * is necessary for add_machine_to_cluster becuase the table that query
921 * operates on is "mcm", not "machine".
924 set_mach_modtime_by_id(q, argv, cl)
935 id = *(int *)argv[0];
936 ## range of m is machine
937 ## repeat replace m (modtime = "now", modby = @who, modwith = @entity)
938 ## where m.mach_id = @id
943 /* Sets the modtime on the cluster whose mach_id is in argv[0]. This routine
944 * is necessary for add_cluster_data and delete_cluster_data becuase the
945 * table that query operates on is "svc", not "cluster".
948 set_cluster_modtime_by_id(q, argv, cl)
959 id = *(int *)argv[0];
960 ## range of c is cluster
961 ## repeat replace c (modtime = "now", modby = @who, modwith = @entity)
962 ## where c.clu_id = @id
967 /* sets the modtime on the serverhost where the service name is in argv[0]
968 * and the mach_id is in argv[1].
971 set_serverhost_modtime(q, argv, cl)
976 ## char *entity, *serv;
983 id = *(int *)argv[1];
984 ## repeat replace sh (modtime = "now", modby = @who, modwith = @entity)
985 ## where sh.service = uppercase(@serv) and sh.mach_id = @id
990 /* sets the modtime on the nfsphys where the mach_id is in argv[0] and the
991 * directory name is in argv[1].
994 set_nfsphys_modtime(q, argv, cl)
999 ## char *entity, *dir;
1002 entity = cl->entity;
1005 id = *(int *)argv[0];
1007 ## repeat replace np (modtime = "now", modby = @who, modwith = @entity)
1008 ## where np.#dir = @dir and np.mach_id = @id
1009 return(SMS_SUCCESS);
1013 /* sets the modtime on a filesystem, where argv[0] contains the filesys
1017 set_filesys_modtime(q, argv, cl)
1022 ## char *label, *entity;
1025 entity = cl->entity;
1029 if (!strcmp(q->shortname, "ufil"))
1032 ## repeat replace fs (modtime = "now", modby = @who, modwith = @entity,
1033 ## #phys_id = @var_phys_id) where fs.#label = @label
1034 return(SMS_SUCCESS);
1038 /* sets the modtime on a zephyr class, where argv[0] contains the class
1042 set_zephyr_modtime(q, argv, cl)
1047 ## char *class, *entity;
1050 entity = cl->entity;
1055 ## repeat replace z (modtime = "now", modby = @who, modwith = @entity)
1056 ## where z.#class = @class
1057 return(SMS_SUCCESS);
1061 /* fixes the modby field. This will be the second to last thing in the
1062 * argv, the argv length is determined from the query structure. It is
1063 * passed as a pointer to an integer. This will either turn it into a
1064 * username, or # + the users_id.
1066 followup_fix_modby(q, sq, v, action, actarg, cl)
1068 register struct save_queue *sq;
1070 register int (*action)();
1071 register int actarg;
1075 char **argv, *malloc();
1076 ## int id, rowcount;
1080 while (sq_get_data(sq, &argv)) {
1083 argv[i] = malloc(9);
1085 ## repeat retrieve (name = users.login) where users.users_id = @id
1086 ## inquire_equel(rowcount = "rowcount")
1087 if (rowcount != 1) {
1088 sprintf(argv[i], "#%d", id);
1090 (*action)(q->vcnt, argv, actarg);
1091 for (j = 0; j < q->vcnt; j++)
1096 return(SMS_SUCCESS);
1101 ** followup_ausr - add finger and pobox entries, set_user_modtime
1104 ** argv[0] - login (add_user)
1105 ** argv[3] - last name
1106 ** argv[4] - first name
1107 ** argv[5] - middle name
1111 followup_ausr(q, argv, cl)
1117 ## char *login, *entity;
1118 ## char fullname[129];
1122 entity = cl->entity;
1124 /* build fullname */
1125 if (strlen(argv[4]) && strlen(argv[5]))
1126 sprintf(fullname, "%s %s %s", argv[4], argv[5], argv[3]);
1127 else if (strlen(argv[4]))
1128 sprintf(fullname, "%s %s", argv[4], argv[3]);
1130 sprintf(fullname, "%s", argv[3]);
1132 /* create finger entry, pobox & set modtime on user */
1133 ## repeat replace u (modtime = "now", modby=@who, modwith=@entity,
1134 ## #fullname=@fullname, mit_affil = u.mit_year,
1135 ## fmodtime="now", fmodby=@who, fmodwith=@entity,
1136 ## potype="NONE", pmodtime="now", pmodby=@who, pmodwith=@entity)
1137 ## where u.#login = @login
1139 return(SMS_SUCCESS);
1143 /* followup_gpob: fixes argv[2] based on the IDs currently there and the
1144 * type in argv[1]. Then completes the upcall to the user.
1146 * argv[2] is of the form "123:234" where the first integer is the machine
1147 * ID if it is a pop box, and the second is the string ID if it is an SMTP
1148 * box. argv[1] should be "POP", "SMTP", or "NONE". Boxes of type NONE
1152 followup_gpob(q, sq, v, action, actarg, cl)
1153 register struct query *q;
1154 register struct save_queue *sq;
1155 register struct validate *v;
1156 register int (*action)();
1160 char **argv, *index();
1162 ## char box[129], *name;
1163 ## int mid, sid, rowcount;
1166 while (sq_get_data(sq, &argv)) {
1167 sms_trim_args(2, argv);
1169 p = index(argv[2], ':');
1171 mid = atoi(argv[2]);
1175 if (!strcmp(ptype, "POP")) {
1176 ## repeat retrieve (box=machine.#name) where machine.mach_id=@mid
1177 ## inquire_equel(rowcount = "rowcount")
1179 return(SMS_MACHINE);
1180 } else if (!strcmp(ptype, "SMTP")) {
1181 ## repeat retrieve (box=strings.string) where strings.string_id=@sid
1182 ## inquire_equel(rowcount = "rowcount")
1185 } else /* ptype == "NONE" */ {
1189 if (!strcmp(q->shortname, "gpob")) {
1190 sid = atoi(argv[4]);
1192 argv[4] = malloc(9);
1194 ## repeat retrieve (name = users.login) where users.users_id = @sid
1195 ## inquire_equel(rowcount = "rowcount")
1197 sprintf(name, "#%d", sid);
1201 (*action)(q->vcnt, argv, actarg);
1203 /* free saved data */
1210 return (SMS_SUCCESS);
1214 /* followup_glin: fix the ace_name in argv[8]. argv[7] will contain the
1215 * ace_type: "LIST", "USER", or "NONE". Decode the id in argv[8] into the
1216 * proper name based on the type, and repace that string in the argv.
1217 * Also fixes the modby field by called followup_fix_modby.
1220 followup_glin(q, sq, v, action, actarg, cl)
1221 register struct query *q;
1222 register struct save_queue *sq;
1223 register struct validate *v;
1224 register int (*action)();
1228 char **argv, *malloc(), *realloc(), *type;
1230 ## int id, rowcount;
1234 if (!strcmp(q->shortname, "gsin"))
1237 while (sq_get_data(sq, &argv)) {
1238 sms_trim_args(q->vcnt, argv);
1240 id = atoi(argv[i = q->vcnt - 2]);
1242 name = argv[i] = malloc(9);
1243 ## repeat retrieve (name = users.login) where users.users_id = @id
1244 ## inquire_equel(rowcount = "rowcount")
1246 sprintf(argv[i], "#%d", id);
1248 id = atoi(argv[idx]);
1249 type = argv[idx - 1];
1250 if ((name = malloc(33)) == NULL)
1253 if (!strcmp(type, "LIST")) {
1254 ## repeat retrieve (name = list.#name) where list.list_id = @id
1255 ## inquire_equel(rowcount = "rowcount")
1257 strcpy(name, "???");
1258 } else if (!strcmp(type, "USER")) {
1259 ## repeat retrieve (name = users.login) where users.users_id = @id
1260 ## inquire_equel(rowcount = "rowcount")
1262 strcpy(name, "???");
1263 } else if (!strcmp(type, "NONE")) {
1264 strcpy(name, "NONE");
1266 strcpy(name, "???");
1270 if (!strcmp(q->shortname, "glin") && atoi(argv[6]) == -1) {
1271 argv[6] = realloc(argv[6], strlen(UNIQUE_GID) + 1);
1272 strcpy(argv[6], UNIQUE_GID);
1276 (*action)(q->vcnt, argv, actarg);
1278 /* free saved data */
1279 for (i = 0; i < q->vcnt; i++)
1285 return (SMS_SUCCESS);
1289 /** followup_amtl - followup for amtl and dmfl; when adding a list
1290 ** member to a maillist, make member list a maillist also
1291 ** unless list is a user-group.
1292 ** Then set_list_modtime_by_id.
1295 ** argv[0] - list_id
1296 ** argv[1] - member_type
1297 ** argv[2] - member_id
1301 followup_amtl(q, argv, cl)
1311 list_id = *(int *)argv[0];
1312 entity = cl->entity;
1315 ## range of l is list
1316 ## repeat replace l (modtime = "now", modby = @who, modwith = @entity)
1317 ## where l.#list_id = @list_id
1319 /* if query is not amtl or if member_type is not LIST then return */
1320 if (bcmp(q->shortname, "amtl", 4) || bcmp(argv[1], "LIST", 4))
1321 return(SMS_SUCCESS);
1323 member_id = *(int *)argv[2];
1325 /* is parent list a mailing list? */
1326 ## repeat retrieve (exists = l.maillist) where l.#list_id=@list_id
1328 return(SMS_SUCCESS);
1330 /* list is not a user-group; add list to maillist table */
1331 ## repeat replace l (maillist = 1) where l.#list_id = @member_id
1332 return(SMS_SUCCESS);
1336 /* followup_anfq: Add allocation to nfsphys after creating quota.
1337 * argv[0] = filsys_id
1338 * argv[2] = ascii(quota)
1341 followup_anfq(q, argv, cl)
1346 ## int quota, user, fs, who;
1349 fs = *(int *)argv[0];
1350 user = *(int *)argv[1];
1351 quota = atoi(argv[2]);
1353 entity = cl->entity;
1355 ## repeat replace nq (modtime = "now", modby = @who, modwith = @entity)
1356 ## where nq.filsys_id = @fs and nq.users_id = @user
1357 ## repeat replace nfsphys (allocated = nfsphys.allocated + @quota)
1358 ## where nfsphys.nfsphys_id = filesys.#phys_id and filesys.filsys_id = @fs
1359 return(SMS_SUCCESS);
1366 followup_gzcl(q, sq, v, action, actarg, cl)
1367 register struct query *q;
1368 register struct save_queue *sq;
1369 register struct validate *v;
1370 register int (*action)();
1375 ## int rowcount, id;
1379 while (sq_get_data(sq, &argv)) {
1380 sms_trim_args(q->vcnt, argv);
1382 id = atoi(argv[i = q->vcnt - 2]);
1384 name = argv[i] = malloc(9);
1385 ## repeat retrieve (name = users.login) where users.users_id = @id
1386 ## inquire_equel(rowcount = "rowcount")
1388 sprintf(argv[i], "#%d", id);
1390 for (i = 1; i < 8; i+=2) {
1391 id = atoi(argv[i+1]);
1393 if ((name = argv[i+1] = malloc(33)) == NULL)
1395 if (!strcmp(argv[i], "LIST")) {
1396 ## repeat retrieve (name = list.#name) where list.list_id = @id
1397 ## inquire_equel(rowcount = "rowcount")
1399 strcpy(name, "???");
1400 } else if (!strcmp(argv[i], "USER")) {
1401 ## repeat retrieve (name = users.login) where users.users_id = @id
1402 ## inquire_equel(rowcount = "rowcount")
1404 strcpy(name, "???");
1405 } else if (!strcmp(argv[i], "NONE")) {
1406 strcpy(name, "NONE");
1408 strcpy(name, "???");
1413 (*action)(q->vcnt, argv, actarg);
1415 /* free saved data */
1416 for (i = 0; i < q->vcnt; i++)
1421 return(SMS_SUCCESS);
1428 followup_gsha(q, sq, v, action, actarg, cl)
1429 register struct query *q;
1430 register struct save_queue *sq;
1431 register struct validate *v;
1432 register int (*action)();
1437 ## int rowcount, id;
1441 while (sq_get_data(sq, &argv)) {
1442 sms_trim_args(q->vcnt, argv);
1446 name = argv[4] = malloc(9);
1447 ## repeat retrieve (name = users.login) where users.users_id = @id
1448 ## inquire_equel(rowcount = "rowcount")
1450 sprintf(argv[4], "#%d", id);
1454 if ((name = argv[2] = malloc(33)) == NULL)
1456 if (!strcmp(argv[1], "LIST")) {
1457 ## repeat retrieve (name = list.#name) where list.list_id = @id
1458 ## inquire_equel(rowcount = "rowcount")
1460 strcpy(name, "???");
1461 } else if (!strcmp(argv[1], "USER")) {
1462 ## repeat retrieve (name = users.login) where users.users_id = @id
1463 ## inquire_equel(rowcount = "rowcount")
1465 strcpy(name, "???");
1466 } else if (!strcmp(argv[1], "NONE")) {
1467 strcpy(name, "NONE");
1469 strcpy(name, "???");
1473 (*action)(q->vcnt, argv, actarg);
1475 /* free saved data */
1476 for (i = 0; i < q->vcnt; i++)
1481 return(SMS_SUCCESS);
1486 /* Special query routines */
1488 /* set_pobox - this does all of the real work.
1489 * argv = user_id, type, box
1490 * if type is POP, then box should be a machine, and its ID should be put in
1491 * pop_id. If type is SMTP, then box should be a string and its ID should
1492 * be put in box_id. If type is NONE, then box doesn't matter.
1495 int set_pobox(q, argv, cl)
1500 ## int user, id, rowcount;
1501 ## char *box, potype[9];
1504 user = *(int *)argv[0];
1506 ## repeat retrieve (id = users.pop_id, potype = users.#potype)
1507 ## where users.users_id = @user
1508 if (!strcmp(strtrim(potype), "POP"))
1509 set_pop_usage(id, -1);
1511 if (!strcmp(argv[1], "POP")) {
1512 ## repeat retrieve (id=machine.mach_id) where machine.name=uppercase(@box)
1513 ## inquire_equel(rowcount = "rowcount")
1515 return(SMS_MACHINE);
1516 ## repeat replace users (#potype = "POP", pop_id = @id)
1517 ## where users.users_id = @user
1518 set_pop_usage(id, 1);
1519 } else if (!strcmp(argv[1], "SMTP")) {
1520 ## range of s is strings
1521 ## repeat retrieve (id = s.string_id) where s.string = @box
1522 ## inquire_equel (rowcount = "rowcount")
1523 if (rowcount == 0) {
1524 ## range of v is values
1525 ## repeat retrieve (id = v.value) where v.name = "strings_id"
1527 ## repeat replace v (value = @id) where v.name = "strings_id"
1528 ## append to strings (string_id = id, string = box)
1530 ## repeat replace users (#potype = "SMTP", box_id = @id)
1531 ## where users.users_id = @user
1532 } else /* argv[1] == "NONE" */ {
1533 ## repeat replace users (#potype = "NONE") where users.users_id = @user
1536 set_pobox_modtime(q, argv, cl);
1537 ## repeat replace tblstats (updates = tblstats.updates + 1, modtime = "now")
1538 ## where tblstats.#table = "users"
1539 return(SMS_SUCCESS);
1543 /* get_list_info: passed a wildcard list name, returns lots of stuff about
1544 * each list. This is tricky: first build a queue of all requested
1545 * data. Rest of processing consists of fixing gid, ace_name, and modby.
1548 get_list_info(q, aargv, cl, action, actarg)
1549 register struct query *q;
1552 register int (*action)();
1555 char *argv[13], *malloc(), *realloc();
1556 ## char *name, acl_type[9], listname[33], active[5], public[5], hidden[5];
1557 ## char maillist[5], group[5], gid[6], acl_name[33], desc[256], modtime[27];
1558 ## char modby[9], modwith[9];
1559 ## int id, rowcount, acl_id, hid, modby_id;
1561 struct save_queue *sq, *sq_create();
1563 returned = rowcount = 0;
1567 ## range of l is list
1568 ## repeat retrieve (id = l.list_id) where l.#name = @name {
1569 sq_save_data(sq, id);
1573 return(SMS_NO_MATCH);
1575 argv[0] = listname; argv[1] = active; argv[2] = public; argv[3] = hidden;
1576 argv[4] = maillist; argv[5] = group; argv[6] = gid; argv[7] = acl_type;
1577 argv[8] = acl_name; argv[9] = desc; argv[10] = modtime; argv[11] = modby;
1580 while (sq_get_data(sq, &id)) {
1584 ## repeat retrieve (listname = l.#name, active = text(l.#active),
1585 ## public = text(l.#public), hidden = text(l.#hidden),
1586 ## hid = l.#hidden, maillist = text(l.#maillist),
1587 ## group = text(l.#group), gid = text(l.#gid),
1588 ## acl_type = trim(l.#acl_type), acl_id = l.#acl_id,
1589 ## desc = l.#desc, modtime = l.#modtime, modby_id = l.#modby,
1590 ## modwith =l.#modwith)
1591 ## where l.list_id = @id
1593 if (atoi(gid) == -1)
1594 argv[6] = UNIQUE_GID;
1596 if (!strcmp(acl_type, "LIST")) {
1597 ## repeat retrieve (acl_name = l.#name) where l.list_id = @acl_id
1598 ## inquire_equel(rowcount = "rowcount")
1600 strcpy(acl_name, "???");
1601 } else if (!strcmp(acl_type, "USER")) {
1602 ## repeat retrieve (acl_name = users.#login)
1603 ## where users.users_id = @acl_id
1604 ## inquire_equel(rowcount = "rowcount")
1606 strcpy(acl_name, "???");
1607 } else if (!strcmp(acl_type, "NONE")) {
1608 strcpy(acl_name, "NONE");
1610 strcpy(acl_name, "???");
1612 ## repeat retrieve (modby = users.login) where users.users_id = @modby_id
1613 ## inquire_equel(rowcount = "rowcount")
1615 sprintf(modby, "#%d", id);
1617 sms_trim_args(q->vcnt, argv);
1619 (*action)(q->vcnt, argv, actarg);
1623 ## repeat replace tblstats (retrieves = tblstats.retrieves + 1)
1624 ## where tblstats.#table = "list"
1626 return (SMS_SUCCESS);
1630 /* get_ace_use - given a type and a name, return a type and a name.
1631 * The ace_type is one of "LIST", "USER", "RLIST", or "RUSER" in argv[0],
1632 * and argv[1] will contain the ID of the entity in question. The R*
1633 * types mean to recursively look at every containing list, not just
1634 * when the object in question is a direct member. On return, the
1635 * usage type will be one of LIST, SERVICE, FILESYS, QUOTA, QUERY, or ZEPHYR.
1638 int get_ace_use(q, argv, cl, action, actarg)
1647 ## int aid, listid, id;
1648 struct save_queue *sq, *sq_create();
1651 aid = *(int *)argv[1];
1652 if (!strcmp(atype, "LIST") || !strcmp(atype, "USER")) {
1653 return(get_ace_internal(atype, aid, action, actarg));
1657 if (!strcmp(atype, "RLIST")) {
1658 sq_save_data(sq, aid);
1659 /* get all the list_id's of containing lists */
1660 ## range of m is members
1661 while (sq_get_data(sq, &id)) {
1662 ## repeat retrieve (listid = m.list_id)
1663 ## where m.member_type = "LIST" and m.member_id = @id {
1664 sq_save_unique_data(sq, listid);
1667 /* now process each one */
1668 while (sq_get_data(sq, &id)) {
1669 if (get_ace_internal("LIST", id, action, actarg) == SMS_SUCCESS)
1674 if (!strcmp(atype, "RUSER")) {
1675 ## range of m is members
1676 ## repeat retrieve (listid = m.list_id)
1677 ## where m.member_type = "USER" and m.member_id = @aid {
1678 sq_save_data(sq, listid);
1680 /* get all the list_id's of containing lists */
1681 while (sq_get_data(sq, &id)) {
1682 ## repeat retrieve (listid = m.list_id)
1683 ## where m.member_type = "LIST" and m.member_id = @id {
1684 sq_save_unique_data(sq, listid);
1687 /* now process each one */
1688 while (sq_get_data(sq, &id)) {
1689 if (get_ace_internal("LIST", id, action, actarg) == SMS_SUCCESS)
1692 if (get_ace_internal("USER", aid, action, actarg) == SMS_SUCCESS)
1697 if (!found) return(SMS_NO_MATCH);
1698 return(SMS_SUCCESS);
1702 /* This looks up a single list or user for ace use. atype must be "USER"
1703 * or "LIST", and aid is the ID of the corresponding object. This is used
1704 * by get_ace_use above.
1707 ##get_ace_internal(atype, aid, action, actarg)
1718 if (!strcmp(atype, "LIST")) {
1719 rargv[0] = "FILESYS";
1720 ## repeat retrieve (name = filesys.label)
1721 ## where filesys.owners = @aid {
1722 (*action)(2, rargv, actarg);
1727 ## repeat retrieve (name = capacls.capability)
1728 ## where capacls.list_id = @aid {
1729 (*action)(2, rargv, actarg);
1732 } else if (!strcmp(atype, "USER")) {
1733 rargv[0] = "FILESYS";
1734 ## repeat retrieve (name = filesys.label)
1735 ## where filesys.owner = @aid {
1736 (*action)(2, rargv, actarg);
1742 ## repeat retrieve (name = list.#name)
1743 ## where list.acl_type = @atype and list.acl_id = @aid {
1744 (*action)(2, rargv, actarg);
1748 rargv[0] = "SERVICE";
1749 ## repeat retrieve (name = servers.#name)
1750 ## where servers.acl_type = @atype and servers.acl_id = @aid {
1751 (*action)(2, rargv, actarg);
1755 rargv[0] = "HOSTACCESS";
1756 ## repeat retrieve (name = machine.#name)
1757 ## where machine.mach_id = hostaccess.mach_id and
1758 ## hostaccess.acl_type = @atype and hostaccess.acl_id = @aid {
1759 (*action)(2, rargv, actarg);
1762 rargv[0] = "ZEPHYR";
1763 ## repeat retrieve (name = zephyr.class)
1764 ## where zephyr.xmt_type = @atype and zephyr.xmt_id = @aid or
1765 ## zephyr.sub_type = @atype and zephyr.sub_id = @aid or
1766 ## zephyr.iws_type = @atype and zephyr.iws_id = @aid or
1767 ## zephyr.iui_type = @atype and zephyr.iui_id = @aid {
1768 (*action)(2, rargv, actarg);
1772 if (!found) return(SMS_NO_MATCH);
1773 return(SMS_SUCCESS);
1777 /* get_lists_of_member - given a type and a name, return the name and flags
1778 * of all of the lists of the given member. The member_type is one of
1779 * "LIST", "USER", "STRING", "RLIST", "RUSER", or "RSTRING" in argv[0],
1780 * and argv[1] will contain the ID of the entity in question. The R*
1781 * types mean to recursively look at every containing list, not just
1782 * when the object in question is a direct member.
1785 int get_lists_of_member(q, argv, cl, action, actarg)
1794 ## int aid, listid, id;
1795 struct save_queue *sq, *sq_create();
1798 aid = *(int *)argv[1];
1799 if (!strcmp(atype, "LIST") ||
1800 !strcmp(atype, "USER") ||
1801 !strcmp(atype, "STRING")) {
1802 return(glom_internal(atype, aid, action, actarg));
1806 if (!strcmp(atype, "RLIST")) {
1807 sq_save_data(sq, aid);
1808 /* get all the list_id's of containing lists */
1809 ## range of m is members
1810 while (sq_get_data(sq, &id)) {
1811 ## repeat retrieve (listid = m.list_id)
1812 ## where m.member_type = "LIST" and m.member_id = @id {
1813 sq_save_unique_data(sq, listid);
1816 /* now process each one */
1817 while (sq_get_data(sq, &id)) {
1818 if (glom_internal("LIST", id, action, actarg) == SMS_SUCCESS)
1823 if (!strcmp(atype, "RUSER")) {
1824 ## range of m is members
1825 ## repeat retrieve (listid = m.list_id)
1826 ## where m.member_type = "USER" and m.member_id = @aid {
1827 sq_save_data(sq, listid);
1829 /* get all the list_id's of containing lists */
1830 while (sq_get_data(sq, &id)) {
1831 ## repeat retrieve (listid = m.list_id)
1832 ## where m.member_type = "LIST" and m.member_id = @id {
1833 sq_save_unique_data(sq, listid);
1836 /* now process each one */
1837 while (sq_get_data(sq, &id)) {
1838 if (glom_internal("LIST", id, action, actarg) == SMS_SUCCESS)
1841 if (glom_internal("USER", aid, action, actarg) == SMS_SUCCESS)
1845 if (!strcmp(atype, "RSTRING")) {
1846 ## range of m is members
1847 ## repeat retrieve (listid = m.list_id)
1848 ## where m.member_type = "STRING" and m.member_id = @aid {
1849 sq_save_data(sq, listid);
1851 /* get all the list_id's of containing lists */
1852 while (sq_get_data(sq, &id)) {
1853 ## repeat retrieve (listid = m.list_id)
1854 ## where m.member_type = "LIST" and m.member_id = @id {
1855 sq_save_unique_data(sq, listid);
1858 /* now process each one */
1859 while (sq_get_data(sq, &id)) {
1860 if (glom_internal("LIST", id, action, actarg) == SMS_SUCCESS)
1863 if (glom_internal("STRING", aid, action, actarg) == SMS_SUCCESS)
1867 ## repeat replace tblstats (retrieves = tblstats.retrieves + 1)
1868 ## where tblstats.#table = "members"
1870 if (!found) return(SMS_NO_MATCH);
1871 return(SMS_SUCCESS);
1875 /* This looks up a single list, user, or string as a member. atype must be
1876 * "USER", "LIST", or "STRING" and aid is the ID of the corresponding object.
1877 * This is used by get_lists_of_members above.
1880 ##glom_internal(atype, aid, action, actarg)
1888 ## char name[33], active[5], public[5], hidden[5], maillist[5], group[5];
1894 rargv[4] = maillist;
1896 ## repeat retrieve (name = list.#name, active = text(list.#active),
1897 ## public = text(list.#public), hidden = text(list.#hidden),
1898 ## maillist = text(list.#maillist), group = text(list.#group))
1899 ## where list.list_id = m.list_id and
1900 ## m.member_type = @atype and m.member_id = @aid {
1901 (*action)(6, rargv, actarg);
1905 if (!found) return(SMS_NO_MATCH);
1906 return(SMS_SUCCESS);
1910 /* qualified_get_lists: passed "TRUE", "FALSE", or "DONTCARE" for each of
1911 * the five flags associated with each list. It will return the name of
1912 * each list that meets the quailifications. It does this by building a
1913 * where clause based on the arguments, then doing a retrieve.
1916 static char *lflags[5] = { "active", "public", "hidden", "maillist", "group" };
1918 int qualified_get_lists(q, argv, cl, action, actarg)
1925 return(qualified_get(q, argv, action, actarg, "l.list_id != 0",
1926 "l", "name", lflags));
1930 /** get_members_of_list - optimized query for retrieval of list members
1933 ** argv[0] - list_id
1936 ** - retrieve USER members, then LIST members, then STRING members
1939 get_members_of_list(q, argv, cl, action, actarg)
1947 ## char member_name[129];
1950 list_id = *(int *)argv[0];
1952 targv[1] = member_name;
1954 ## range of m is members
1955 ## repeat retrieve (member_name = users.login)
1956 ## where m.#list_id = @list_id and m.member_type = "USER"
1957 ## and m.member_id = users.users_id
1958 ## sort by #member_name
1960 (*action)(2, targv, actarg);
1964 ## repeat retrieve (member_name = list.name)
1965 ## where m.#list_id = @list_id and m.member_type = "LIST"
1966 ## and m.member_id = list.#list_id
1967 ## sort by #member_name
1969 (*action)(2, targv, actarg);
1972 targv[0] = "STRING";
1973 ## repeat retrieve (member_name = strings.string)
1974 ## where m.#list_id = @list_id and m.member_type = "STRING"
1975 ## and m.member_id = strings.string_id
1976 ## sort by #member_name
1978 (*action)(2, targv, actarg);
1981 ## repeat replace tblstats (retrieves = tblstats.retrieves + 1)
1982 ## where tblstats.#table = "members"
1983 return(SMS_SUCCESS);
1987 /* count_members_of_list: this is a simple query, but it cannot be done
1988 * through the dispatch table.
1991 int count_members_of_list(q, argv, cl, action, actarg)
1998 ## int list, ct = 0;
1999 char *rargv[1], countbuf[5];
2001 list = *(int *)argv[0];
2002 rargv[0] = countbuf;
2003 ## repeat retrieve (ct = count(members.list_id where members.list_id = @list))
2004 sprintf(countbuf, "%d", ct);
2005 (*action)(1, rargv, actarg);
2006 ## repeat replace tblstats (retrieves = tblstats.retrieves + 1)
2007 ## where tblstats.#table = "members"
2008 return(SMS_SUCCESS);
2012 /* qualified_get_server: passed "TRUE", "FALSE", or "DONTCARE" for each of
2013 * the three flags associated with each service. It will return the name of
2014 * each service that meets the quailifications. It does this by building a
2015 * where clause based on the arguments, then doing a retrieve.
2018 static char *sflags[3] = { "enable", "inprogress", "harderror" };
2020 int qualified_get_server(q, argv, cl, action, actarg)
2027 return(qualified_get(q, argv, action, actarg, "s.name != \"\"",
2028 "s", "name", sflags));
2032 /* generic qualified get routine, used by qualified_get_lists,
2033 * qualified_get_server, and qualified_get_serverhost.
2035 * start - a simple where clause, must not be empty
2036 * range - the name of the range variable
2037 * field - the field to return
2038 * flags - an array of strings, names of the flag variables
2041 int qualified_get(q, argv, action, actarg, start, range, field, flags)
2051 ## char name[33], qual[256], *rvar, *rtbl, *rfield;
2052 char *rargv[1], buf[32];
2055 strcpy(qual, start);
2056 for (i = 0; i < q->argc; i++) {
2057 if (!strcmp(argv[i], "TRUE")) {
2058 sprintf(buf, " and %s.%s != 0", range, flags[i]);
2059 (void) strcat(qual, buf);
2060 } else if (!strcmp(argv[i], "FALSE")) {
2061 sprintf(buf, " and %s.%s = 0", range, flags[i]);
2062 (void) strcat(qual, buf);
2070 ## range of rvar is rtbl
2071 ## retrieve (name = rvar.rfield) where qual {
2072 (*action)(1, rargv, actarg);
2074 ## inquire_equel(rowcount = "rowcount")
2075 ## repeat replace tblstats (retrieves = tblstats.retrieves + 1)
2076 ## where tblstats.#table = @rtbl
2078 return(SMS_NO_MATCH);
2079 return(SMS_SUCCESS);
2083 /* qualified_get_serverhost: passed "TRUE", "FALSE", or "DONTCARE" for each of
2084 * the five flags associated with each serverhost. It will return the name of
2085 * each service and host that meets the quailifications. It does this by
2086 * building a where clause based on the arguments, then doing a retrieve.
2089 static char *shflags[6] = { "service", "enable", "override", "success",
2090 "inprogress", "hosterror" };
2092 int qualified_get_serverhost(q, argv, cl, action, actarg)
2099 ## char sname[33], mname[33], qual[256];
2100 char *rargv[2], buf[32];
2103 sprintf(qual, "machine.mach_id = sh.mach_id and sh.service = uppercase(\"%s\")",
2105 for (i = 1; i < q->argc; i++) {
2106 if (!strcmp(argv[i], "TRUE")) {
2107 sprintf(buf, " and sh.%s != 0", shflags[i]);
2109 } else if (!strcmp(argv[i], "FALSE")) {
2110 sprintf(buf, " and sh.%s = 0", shflags[i]);
2117 ## range of sh is serverhosts
2118 ## retrieve (sname = sh.service, mname = machine.name) where qual {
2119 (*action)(2, rargv, actarg);
2121 ## inquire_equel(rowcount = "rowcount")
2122 ## repeat replace tblstats (retrieves = tblstats.retrieves + 1)
2123 ## where tblstats.#table = "serverhosts"
2125 return(SMS_NO_MATCH);
2126 return(SMS_SUCCESS);
2130 /* register_user - change user's login name and allocate a pobox, group,
2131 * filesystem, and quota for them. The user's status must start out as 0,
2132 * and is left as 2. Arguments are: user's UID, new login name, and user's
2133 * type for filesystem allocation (SMS_FS_STUDENT, SMS_FS_FACULTY,
2134 * SMS_FS_STAFF, SMS_FS_MISC).
2137 register_user(q, argv, cl)
2142 ## char *login, dir[65], *entity, *directory, machname[33];
2143 ## int who, rowcount, mid, uid, users_id, flag, utype, nid, list_id, quota;
2144 ## int size, alloc, pid, m_id;
2147 entity = cl->entity;
2150 uid = atoi(argv[0]);
2152 utype = atoi(argv[2]);
2154 ## range of u is users
2155 ## range of l is list
2156 ## range of sh is serverhosts
2157 ## range of n is nfsphys
2158 ## range of m is machine
2161 ## repeat retrieve (users_id = u.#users_id)
2162 ## where u.#uid = @uid and u.status = 0
2163 ## inquire_equel(rowcount = "rowcount");
2165 return(SMS_NO_MATCH);
2167 return(SMS_NOT_UNIQUE);
2169 /* check new login name */
2170 ## repeat retrieve (flag = any(u.#login where u.#login = @login))
2171 if (ingres_errno) return(sms_errcode);
2172 if (flag) return(SMS_IN_USE);
2173 ## repeat retrieve (flag = any(l.#name where l.#name = @login))
2174 if (ingres_errno) return(sms_errcode);
2175 if (flag) return(SMS_IN_USE);
2176 ## repeat retrieve (flag = any(filesys.#label where filesys.#label = @login))
2177 if (ingres_errno) return(sms_errcode);
2178 if (flag) return(SMS_IN_USE);
2179 com_err(whoami, 0, "new login name OK");
2181 /* choose place for pobox, put in mid */
2182 ## repeat retrieve (mid = sh.mach_id, machname = m.name)
2183 ## where sh.service = "POP" and m.mach_id = sh.mach_id and
2184 ## sh.value2 - sh.value1 = max(sh.value2-sh.value1 where sh.service="POP")
2185 ## inquire_equel(rowcount = "rowcount");
2187 return(SMS_NO_POBOX);
2189 /* change login name, set pobox */
2190 ## repeat replace u (#login = @login, status = 2, modtime = "now",
2191 ## modby = @who, modwith = @entity, potype="POP",
2192 ## pop_id = @mid, pmodtime="now", pmodby=@who,
2193 ## pmodwith=@entity)
2194 ## where u.#users_id = @users_id
2195 ## inquire_equel(rowcount = "rowcount");
2197 return(SMS_INTERNAL);
2198 set_pop_usage(mid, 1);
2199 com_err(whoami, 0, "set login name to %s and pobox to %s", login,
2202 /* create group list */
2203 if (set_next_object_id("gid", "list"))
2205 if (set_next_object_id("list_id", "list"))
2207 ## repeat retrieve (list_id = values.value) where values.name = "list_id"
2208 ## inquire_equel(rowcount = "rowcount");
2210 return(SMS_INTERNAL);
2211 ## repeat append list (name = @login, #list_id = @list_id, active = 1,
2212 ## public = 0, hidden = 0, maillist = 0, group = 1,
2213 ## #gid = values.value, desc = "User Group",
2214 ## acl_type = "USER", acl_id = @users_id, modtime = "now",
2215 ## modby = @who, modwith = @entity)
2216 ## where values.name = "gid"
2217 ## inquire_equel(rowcount = "rowcount");
2219 return(SMS_INTERNAL);
2220 ## repeat append members (#list_id = @list_id, member_type = "USER",
2221 ## member_id = @users_id)
2222 ## inquire_equel(rowcount = "rowcount");
2224 return(SMS_INTERNAL);
2225 com_err(whoami, 0, "group list created");
2227 /* decide where to put filesystem */
2230 ## repeat retrieve (mid = n.mach_id, dir = trim(n.#dir), nid = n.nfsphys_id,
2231 ## flag = n.status, size = n.#size, alloc = n.allocated) {
2232 if ((flag & utype) && (size != 0) && (size - alloc > maxsize)) {
2233 maxsize = size - alloc;
2236 directory = strsave(dir);
2242 return(SMS_NO_FILESYS);
2244 /* create filesystem */
2245 if (set_next_object_id("filsys_id", "filesys"))
2247 ## repeat append filesys (filsys_id = values.value, phys_id = @pid,
2248 ## label = @login, type = "NFS", mach_id = @m_id,
2249 ## name = @directory + "/" + @login,
2250 ## mount = "/mit/" + @login,
2251 ## access = "w", comments = "User Locker",
2252 ## owner = @users_id, owners = @list_id, createflg = 1,
2253 ## lockertype = "HOMEDIR", modtime = "now",
2254 ## modby = @who, modwith = @entity)
2255 ## where values.name = "filsys_id"
2256 ## inquire_equel(rowcount = "rowcount");
2258 return(SMS_INTERNAL);
2259 com_err(whoami, 0, "filesys created on mach %d in %s/%s", m_id,
2263 ## repeat retrieve (quota = values.value) where values.name = "def_quota"
2264 ## inquire_equel(rowcount = "rowcount");
2266 return(SMS_NO_QUOTA);
2267 ## repeat append nfsquota (#users_id = @users_id, filsys_id = values.value,
2268 ## #quota = @quota, phys_id = @pid, modtime = "now",
2269 ## modby = @who, modwith = @entity)
2270 ## where values.name = "filsys_id"
2271 ## inquire_equel(rowcount = "rowcount");
2273 return(SMS_INTERNAL);
2274 ## repeat replace nfsphys (allocated = nfsphys.allocated + @quota)
2275 ## where nfsphys.nfsphys_id = filesys.#phys_id and
2276 ## filesys.filsys_id = values.value and values.name = "filsys_id"
2277 ## inquire_equel(rowcount = "rowcount");
2279 return(SMS_INTERNAL);
2280 com_err(whoami, 0, "quota of %d assigned", quota);
2282 ## repeat replace tblstats (updates = tblstats.updates + 1, modtime = "now")
2283 ## where tblstats.table = "users"
2284 ## repeat replace tblstats (appends = tblstats.appends + 1, modtime = "now")
2285 ## where tblstats.table = "list" or tblstats.table = "filesys" or
2286 ## tblstats.table = "nfsquota"
2287 return(SMS_SUCCESS);
2292 /** set_pop_usage - incr/decr usage count for pop server in serverhosts talbe
2296 ** delta (will be +/- 1)
2299 ** - incr/decr value field in serverhosts table for pop/mach_id
2303 static int set_pop_usage(id, count)
2307 ## int mach_id = id;
2310 ## range of sh is serverhosts
2311 ## repeat replace sh (value1 = sh.value1 + @n)
2312 ## where sh.service = "POP" and sh.#mach_id = @mach_id
2314 return(SMS_SUCCESS);
2319 /* Validation Routines */
2321 validate_row(q, argv, v)
2322 register struct query *q;
2324 register struct validate *v;
2332 /* build where clause */
2333 build_qual(v->qual, v->argc, argv, qual);
2335 /* setup ingres variables */
2340 if (log_flags & LOG_VALID)
2341 /* tell the logfile what we're doing */
2342 com_err(whoami, 0, "validating row: %s", qual);
2344 /* look for the record */
2345 ## range of rvar is table
2346 ## retrieve (rowcount = count(rvar.name where qual))
2347 if (ingres_errno) return(sms_errcode);
2348 if (rowcount == 0) return(SMS_NO_MATCH);
2349 if (rowcount > 1) return(SMS_NOT_UNIQUE);
2353 validate_fields(q, argv, vo, n)
2355 register char *argv[];
2356 register struct valobj *vo;
2359 register int status;
2364 if (log_flags & LOG_VALID)
2365 com_err(whoami, 0, "validating %s in %s: %s",
2366 vo->namefield, vo->table, argv[vo->index]);
2367 status = validate_name(argv, vo);
2371 if (log_flags & LOG_VALID)
2372 com_err(whoami, 0, "validating %s in %s: %s",
2373 vo->idfield, vo->table, argv[vo->index]);
2374 status = validate_id(argv, vo);
2378 if (log_flags & LOG_VALID)
2379 com_err(whoami, 0, "validating date: %s", argv[vo->index]);
2380 status = validate_date(argv, vo);
2384 if (log_flags & LOG_VALID)
2385 com_err(whoami, 0, "validating %s type: %s",
2386 vo->table, argv[vo->index]);
2387 status = validate_type(argv, vo);
2391 if (log_flags & LOG_VALID)
2392 com_err(whoami, 0, "validating typed data (%s): %s",
2393 argv[vo->index - 1], argv[vo->index]);
2394 status = validate_typedata(q, argv, vo);
2398 if (log_flags & LOG_VALID)
2399 com_err(whoami, 0, "validating rename %s in %s",
2400 argv[vo->index], vo->table);
2401 status = validate_rename(argv, vo);
2405 if (log_flags & LOG_VALID)
2406 com_err(whoami, 0, "validating chars: %s", argv[vo->index]);
2407 status = validate_chars(argv[vo->index]);
2411 status = SMS_EXISTS;
2415 status = lock_table(vo);
2419 if (status != SMS_EXISTS) return(status);
2423 return(SMS_SUCCESS);
2427 /* validate_chars: verify that there are no illegal characters in
2428 * the string. Legal characters are printing chars other than
2429 * ", *, ?, \, [ and ].
2431 static int illegalchars[] = {
2432 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* ^@ - ^O */
2433 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* ^P - ^_ */
2434 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, /* SPACE - / */
2435 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, /* 0 - ? */
2436 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* @ - O */
2437 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, /* P - _ */
2438 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* ` - o */
2439 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, /* p - ^? */
2440 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2441 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2442 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2443 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2444 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2445 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2446 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2447 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2454 if (illegalchars[*s++])
2455 return(SMS_BAD_CHAR);
2460 validate_id(argv, vo)
2462 register struct valobj *vo;
2472 name = argv[vo->index];
2474 /* minor kludge to upcasify machine names */
2475 if (!strcmp(table, "machine"))
2476 for (c = name; *c; c++) if (islower(*c)) *c = toupper(*c);
2477 namefield = vo->namefield;
2478 idfield = vo->idfield;
2479 if (!strcmp(namefield, "uid")) {
2480 ## retrieve (id = table.idfield) where table.namefield = int4(name)
2481 if (ingres_errno) return(sms_errcode);
2482 ## inquire_equel (rowcount = "rowcount")
2484 ## retrieve (id = table.idfield) where table.namefield = name
2485 if (ingres_errno) return(sms_errcode);
2486 ## inquire_equel (rowcount = "rowcount")
2488 if (rowcount != 1) return(vo->error);
2489 *(int *)argv[vo->index] = id;
2493 validate_name(argv, vo)
2495 register struct valobj *vo;
2503 name = argv[vo->index];
2505 namefield = vo->namefield;
2506 if (!strcmp(table, "servers") && !strcmp(namefield, "name")) {
2507 for (c = name; *c; c++)
2511 ## retrieve (rowcount = countu(table.namefield
2512 ## where table.namefield = name))
2513 if (ingres_errno) return(sms_errcode);
2514 return ((rowcount == 1) ? SMS_EXISTS : vo->error);
2517 validate_date(argv, vo)
2525 idate = argv[vo->index];
2527 ## retrieve (dd = interval("years", date(idate) - date("today")))
2528 ## inquire_equel (errorno = "errorno")
2529 if (errorno != 0 || dd > 5.0) return(SMS_DATE);
2534 validate_rename(argv, vo)
2538 ## char *name, *table, *namefield, *idfield;
2542 c = name = argv[vo->index];
2544 if (illegalchars[*c++])
2545 return(SMS_BAD_CHAR);
2547 /* minor kludge to upcasify machine names */
2548 if (!strcmp(table, "machine"))
2549 for (c = name; *c; c++) if (islower(*c)) *c = toupper(*c);
2550 namefield = vo->namefield;
2551 idfield = vo->idfield;
2554 if (!strcmp(argv[vo->index], argv[vo->index - 1]))
2556 ## retrieve (id = any(table.namefield where table.namefield = name))
2557 if (ingres_errno) return(sms_errcode);
2563 ## retrieve (id = table.idfield) where table.namefield = name
2564 if (ingres_errno) return(sms_errcode);
2565 if (id == -1 || id == *(int *)argv[vo->index - 1])
2572 validate_type(argv, vo)
2574 register struct valobj *vo;
2581 typename = vo->table;
2582 c = value = argv[vo->index];
2584 if (illegalchars[*c++])
2585 return(SMS_BAD_CHAR);
2587 /* uppercase type fields */
2588 for (c = value; *c; c++) if (islower(*c)) *c = toupper(*c);
2590 ## range of a is alias
2591 ## repeat retrieve (exists = any(a.trans where a.name = @typename and
2592 ## a.type = "TYPE" and
2593 ## a.trans = @value))
2594 if (ingres_errno) return(sms_errcode);
2595 return (exists ? SMS_EXISTS : vo->error);
2598 /* validate member or type-specific data field */
2600 validate_typedata(q, argv, vo)
2601 register struct query *q;
2602 register char *argv[];
2603 register struct valobj *vo;
2606 ## char *field_type;
2607 ## char data_type[129];
2613 /* get named object */
2614 name = argv[vo->index];
2616 /* get field type string (known to be at index-1) */
2617 field_type = argv[vo->index-1];
2619 /* get corresponding data type associated with field type name */
2620 ## repeat retrieve (data_type = alias.trans)
2621 ## where alias.#name = @field_type and alias.type = "TYPEDATA"
2622 if (ingres_errno) return(sms_errcode);
2623 ## inquire_equel (rowcount = "rowcount")
2624 if (rowcount != 1) return(SMS_TYPE);
2626 /* now retrieve the record id corresponding to the named object */
2627 if (index(data_type, ' '))
2628 *index(data_type, ' ') = 0;
2629 if (!strcmp(data_type, "user")) {
2631 ## repeat retrieve (id = users.users_id) where users.login = @name
2632 ## inquire_equel (rowcount = "rowcount")
2633 if (rowcount != 1) return(SMS_USER);
2635 } else if (!strcmp(data_type, "list")) {
2637 ## repeat retrieve (id = list.list_id) where list.#name = @name
2638 ## inquire_equel (rowcount = "rowcount")
2639 if (rowcount != 1) {
2640 /* if idfield is non-zero, then if argv[0] matches the string
2641 * that we're trying to resolve, we should get the value of
2642 * values.[idfield] for the id.
2644 if (vo->idfield && !strcmp(argv[0], argv[vo->index])) {
2645 set_next_object_id(q->validate->object_id, q->rtable);
2647 ## repeat retrieve (id = values.value) where values.#name = @name
2648 ## inquire_equel(rowcount = "rowcount")
2649 if (rowcount != 1) return(SMS_LIST);
2653 } else if (!strcmp(data_type, "machine")) {
2655 for (c = name; *c; c++) if (islower(*c)) *c = toupper(*c);
2656 ## repeat retrieve (id = machine.mach_id) where machine.#name = @name
2657 ## inquire_equel (rowcount = "rowcount")
2658 if (rowcount != 1) return(SMS_MACHINE);
2660 } else if (!strcmp(data_type, "string")) {
2662 ## range of s is strings
2663 ## repeat retrieve (id = s.string_id) where s.string = @name
2664 ## inquire_equel (rowcount = "rowcount")
2665 if (rowcount == 0) {
2666 if (q->type != APPEND) return(SMS_STRING);
2667 ## range of v is values
2668 ## retrieve (id = v.value) where v.#name = "strings_id"
2670 ## replace v (value = id) where v.#name = "strings_id"
2671 ## append to strings (string_id = id, string = name)
2673 } else if (!strcmp(data_type, "none")) {
2679 /* now set value in argv */
2680 *(int *)argv[vo->index] = id;
2682 return (SMS_EXISTS);
2686 /* Lock the table named by the validation object */
2691 ## char *table, *idfield;
2695 idfield = vo->idfield;
2696 ## replace table (modtime = "now") where table.idfield = 0
2697 if (ingres_errno) return(sms_errcode);
2698 ## inquire_equel (rowcount = "rowcount")
2706 /* This looks up a login name and returns the SMS internal ID. It is used
2707 * by authenticate to put the users_id in the client structure.
2710 int get_users_id(name)
2713 ## int id, rowcount;
2718 ## range of u is users
2719 ## repeat retrieve (id = u.#users_id) where u.#login = @login
2720 ## inquire_equel (rowcount = "rowcount")
2729 /* Check the database at startup time. For now this just resets the
2730 * inprogress flags that the DCM uses.
2733 sanity_check_database()