]> andersk Git - moira.git/commitdiff
Changed everything for new database format & version 2.0 of the protocol
authormar <mar>
Thu, 30 Jun 1988 15:30:05 +0000 (15:30 +0000)
committermar <mar>
Thu, 30 Jun 1988 15:30:05 +0000 (15:30 +0000)
server/qsupport.qc

index f28dc8a0f1622eb151f7c6f2a1c2a08580754da9..7016993cc1bc049636c260fa21944c9f9d67f60e 100644 (file)
@@ -5,78 +5,6 @@
  *
  *     Copyright (C) 1987 by the Massachusetts Institute of Technology
  *
- *     $Log$
- *     Revision 1.18  1988-01-14 12:00:38  mar
- *     separate access check from setup routine.
- *     make get_query_need be more paranoid
- *
-Revision 1.17  88/01/04  12:09:00  mar
-fixup pobox access checking & make id assignment more paranoid (wesommer)
-
-Revision 1.16  87/11/12  18:16:56  wesommer
-Add support for delete_user_by_uid.
-Fix access_pop.
-Check a few return codes.
-
-Revision 1.15  87/09/11  15:31:58  wesommer
-add_user_group modified to side-effect the time for tbs for groups as 
-well as the other things.
-
-Revision 1.15  87/09/10  22:44:49  wesommer
-One more table needs to be modified when adding the user-group.
-
-Revision 1.14  87/09/04  17:50:03  mike
-Renamed delete_list_members to followup_delete_list.  New routine removes
-list from maillists and groups tables in addition to the members table.
-
-Added routines validate_label and validate_label_2 used in validating
-filesys labels for get_filesys and delete_filesys respectively.
-
-Revision 1.13  87/09/01  16:24:01  wesommer
-A list should be considered modified if its acl changes.
-
-Revision 1.12  87/08/29  00:05:54  mike
-Fixed bug in check_nfs.
-Added code to upcasify machine names in validate_id.
-
-Revision 1.11  87/08/28  14:55:45  mike
-Modified delete_locker to require only one argument, the login name.
-Modified get_groups_of_all_users and get_all_poboxes to disable INGRES
-table locking.
-
-Revision 1.10  87/08/25  15:56:54  mike
-- Fixed bugs in get_groups_of_all_users
-- Added tblstats updates to add_user_group
-- Added routines: add_hostaccess (ashi), delete_hostaccess (dshi),
-  followup_ushp, and followup_usha
-
-Revision 1.9  87/08/22  17:41:34  wesommer
-More of Mike's changes. 
-
-Revision 1.8  87/08/18  15:05:20  wesommer
-Fixed definition of add_locker.
-
-Revision 1.7  87/08/04  01:49:41  wesommer
-Rearranged messages.
-
-Revision 1.6  87/08/04  01:10:02  wesommer
-Changes by mike; checked in prior to my hacking.
-
-Revision 1.5  87/07/30  14:54:13  wesommer
-Added debugging code in an attempt to catch a flakey problem.
-
-Revision 1.4  87/07/30  00:30:21  wesommer
-replaced appends = appends+1 with appends = tbs.appends+1
-
-Revision 1.3  87/07/30  00:26:11  wesommer
-Changes by mike prior to "appends" fix.
-
-Revision 1.2  87/07/29  16:00:39  wesommer
-Fixed add_locker.
-
-Revision 1.1  87/07/29  15:13:57  wesommer
-Initial revision
-
  */
 
 #ifndef lint
@@ -87,1351 +15,1931 @@ static char *rcsid_qsupport_qc = "$Header$";
 #include "sms_server.h"
 #include <ctype.h>
 
-#define SMS_SUCCESS 0
 
-extern char *whoami;
+extern char *whoami, *strsave();
+
 
 /* Specialized Access Routines */
 
-/**
- ** access_user - verify that client name equals specified login name
- **
- ** Used by: update_user_shell
- **          update_finger_by_login
- **
- **  - since field validation routines are called first, a users_id is
- **    now in argv[0] instead of the login name.  Therefore, we must 
- **    convert the client name to a users_id.
- **/
+/* access_user - verify that client name equals specified login name
+ *
+ *  - since field validation routines are called first, a users_id is
+ *    now in argv[0] instead of the login name.
+ */
 
 access_user(q, argv, cl)
     struct query *q;
     char *argv[];
     client *cl;
-##{
-    register struct krbname *krb;
-##  int client_id;
-##  char *client_name;
-##  int rowcount;
-
-    client_name = cl->kname.name;
-##  repeat retrieve (client_id = users.users_id) 
-##         where users.login = @client_name
-##  inquire_equel (rowcount = "rowcount")
-    if (rowcount != 1) return(SMS_PERM);
-    if (client_id != *(int *)argv[0]) return(SMS_PERM);
+{
+    if (cl->users_id != *(int *)argv[0])
+       return(SMS_PERM);
+    else
+       return(SMS_SUCCESS);
+}
 
-    return(SMS_SUCCESS);
-##}
     
-/**
- ** access_pop - same as access_user plus verifies that a user has only one
- **             mailbox of type "POP"
- **
- ** Inputs:
- **   argv[0] - users_id
- **   argv[1] - type
- **   argv[2] - mach_id
- **   argv[3] - box
- **
- ** Description:
- **   - if q->name = "add_pobox" and type = "POP", 
- **        verify that no POP box already exists for user
- **   - call access_user
- **
- **/
 
-access_pop(q, argv, cl)
+/* access_login - verify that client name equals specified login name
+ *
+ *   argv[0...n] contain search info.  q->
+ */
+
+access_login(q, argv, cl)
     struct query *q;
     char *argv[];
     client *cl;
 ##{
-##  int users_id;
-##  int mach_id;
-##  char *box;
-##  int exists;
-
-    if (!bcmp(q->name, "add_pobox", 10) && !bcmp(argv[1], "POP", 4)) {
-       box = argv[3];
-       if (strcmp(cl->kname.name, box) != 0) return SMS_PERM;
-       
-       users_id = *(int *)argv[0];
-       mach_id = *(int *)argv[2];
-           
-##      range of p is pobox
-##      repeat retrieve (exists = any(p.#box where p.#users_id = @users_id
-##                                   and p.type = "POP"))
-       if (exists) return(SMS_EXISTS);
-    }
-
-    return(access_user(q, argv, cl));
+##  int rowcount, id;
+##  char qual[256];
+
+    build_qual(q->qual, q->argc, argv, qual);
+##  retrieve (id = u.users_id) where qual
+##  inquire_equel(rowcount = "rowcount")
+    if (rowcount != 1 || id != cl->users_id)
+       return(SMS_PERM);
+    else
+       return(SMS_SUCCESS);
 ##}
 
-/**
- ** access_list - check access for adding or deleting list members
- **
- ** Inputs: argv[0] - list_id
- **         cl->krb.name - client name
- **
- ** - check that client is a member of the access control list
- ** - OR, if q->shortname == {amtl | dfml} and
- **       if list.flags & LF_PUBLIC, allow access if client = member
- **
- **/ 
+    
+
+/* access_list - check access for most list operations
+ *
+ * Inputs: argv[0] - list_id
+ *         q - query name
+ *         argv[2] - member ID (only for queries "amtl" and  "dmfl")
+ *         cl - client name
+ *
+ * - check that client is a member of the access control list
+ * - OR, if the query is add_member_to_list or delete_member_from_list
+ *     and the list is public, allow access if client = member
+ */ 
 
 access_list(q, argv, cl)
     struct query *q;
     char *argv[];
     client *cl;
 ##{
-##  int list_id;
-##  int acl_id;
-##  int flags;
-    int member_id;
+##  int list_id, acl_id, flags, rowcount;
+##  char acl_type[9];
     char *client_type;
-    int client_id;
-    int status;
-    int exists;
+    int client_id, status;
 
     list_id = *(int *)argv[0];
-##  repeat retrieve (acl_id = list.#acl_id, flags = list.#flags) 
+##  repeat retrieve (acl_id = list.#acl_id, acl_type = list.#acl_type,
+##                  flags = list.#public) 
 ##        where list.#list_id = @list_id
+##  inquire_equel(rowcount = "rowcount")
+    if (rowcount != 1)
+      return(SMS_INTERNAL);
 
     /* parse client structure */
-    status = get_client(cl, &client_type, &client_id);
-    if (status != SMS_SUCCESS) return(status);
+    if ((status = get_client(cl, &client_type, &client_id)) != SMS_SUCCESS)
+       return(status);
 
     /* if amtl or dmfl and list is public allow client to add or delete self */
-    if (!bcmp("amtl", q->shortname, 4) || !bcmp("dmfl", q->shortname, 4)) {
-       if ((flags & LF_PUBLIC) && !bcmp("USER", argv[1], 4)) {
-           member_id = *(int *)argv[2];
-           if (member_id == client_id) return(SMS_SUCCESS);
-       }
+    if ((!strcmp("amtl", q->shortname) || !strcmp("dmfl", q->shortname)) &&
+       (flags && !strcmp("USER", argv[1]))) {
+       if (*(int *)argv[2] == client_id) return(SMS_SUCCESS);
     }
 
     /* check for client in access control list */
-    exists = find_member(acl_id, client_type, client_id, 0);
-    if (!exists) return(SMS_PERM);
+    status = find_member(acl_type, acl_id, client_type, client_id, 0);
+    if (!status) return(SMS_PERM);
 
     return(SMS_SUCCESS);
 ##}
 
-/**
- ** access_maillist - access_list + disallow adding user-group to maillists
- **
- ** Inputs:
- **   argv[0] - list_id
- **
- **/
 
-access_maillist(q, argv, cl)
+/* access_visible_list - allow access to list only if it is not hidden,
+ *     or if the client is on the ACL
+ *
+ * Inputs: argv[0] - list_id
+ *         cl - client identifier
+ */ 
+
+access_visible_list(q, argv, cl)
     struct query *q;
     char *argv[];
     client *cl;
 ##{
-##  int list_id;
-##  int exists;
-##  char list_name[32];
-    int status;
-
-    status = access_list(q, argv, cl);
-    if (status != SMS_SUCCESS) return(status);
-    if (bcmp(q->name, "add_maillist", 12)) return(status);
+##  int list_id, acl_id, flags, rowcount;
+##  char acl_type[9];
+    char *client_type;
+    int client_id, status;
 
     list_id = *(int *)argv[0];
-##  range of g is groups
-##  repeat retrieve (exists = any(g.#list_id where g.#list_id = @list_id))
-    if (!exists) return(SMS_SUCCESS);
-##  repeat retrieve (list_name = list.name) where list.#list_id = @list_id
-##  repeat retrieve (exists = any(users.login where users.login = @list_name))
-    return ((exists) ? SMS_USER_GROUP : SMS_SUCCESS);
+##  repeat retrieve (flags = list.hidden, acl_id = list.#acl_id, 
+##     acl_type = list.#acl_type) where list.#list_id = @list_id
+##  inquire_equel(rowcount = "rowcount")
+    if (rowcount != 1)
+      return(SMS_INTERNAL);
+    if (!flags)
+       return(SMS_SUCCESS);
+
+    /* parse client structure */
+    if ((status = get_client(cl, &client_type, &client_id)) != SMS_SUCCESS)
+       return(status);
+
+    /* check for client in access control list */
+    status = find_member(acl_type, acl_id, client_type, client_id, 0);
+    if (!status)
+       return(SMS_PERM);
+
+    return(SMS_SUCCESS);
 ##}
 
-/**
- ** Setup routine for add_group
- **
- ** Inputs: none
- **
- ** Description: allocate next gid and store in values table
- **
- **/
 
-setup_add_group(q, argv, cl)
+/* access_vis_list_by_name - allow access to list only if it is not hidden,
+ *     or if the client is on the ACL
+ *
+ * Inputs: argv[0] - list name
+ *         cl - client identifier
+ */ 
+
+access_vis_list_by_name(q, argv, cl)
     struct query *q;
     char *argv[];
     client *cl;
 ##{
-##  int ngid;
-##  int exists;
-##  int rowcount;
-       int status;
-
-##  range of g is groups
-##  range of v is values
-##  repeat retrieve (ngid = v.value) where v.name = "gid"
-    exists = 1;
-    while (exists) {
-       ngid++;
-##      repeat retrieve (exists = any(g.#gid where g.#gid = @ngid))
-    }
+##  int acl_id, flags, rowcount;
+##  char acl_type[9], *listname;
+    char *client_type;
+    int client_id, status;
+
+    listname = argv[0];
+##  repeat retrieve (flags = list.hidden, acl_id = list.#acl_id, 
+##     acl_type = list.#acl_type) where list.#name = @listname
+##  inquire_equel(rowcount = "rowcount");
+    if (rowcount > 1)
+      return(SMS_WILDCARD);
+    if (rowcount == 0)
+      return(SMS_NO_MATCH);
+    if (!flags)
+       return(SMS_SUCCESS);
 
-##  repeat replace v (value = @ngid) where v.name = "gid"
-##  inquire_equel (rowcount = "rowcount")
-    if (rowcount != 1) return SMS_INGRES_ERR;
-    else return(SMS_SUCCESS);
+    /* parse client structure */
+    if ((status = get_client(cl, &client_type, &client_id)) != SMS_SUCCESS)
+       return(status);
+
+    /* check for client in access control list */
+    status = find_member(acl_type, acl_id, client_type, client_id, 0);
+    if (!status)
+       return(SMS_PERM);
+
+    return(SMS_SUCCESS);
 ##}
-\f
-/**
- ** Setup routine for add_user
- **
- ** Inputs: argv[0] - login
- **         argv[1] - uid
- **
- ** Description:
- **
- ** - if argv[1] == "#" then set argv[1] = next(uid)
- ** - if argv[0] == "#" then set argv[0] = "#<uid>"
- **
- **/
 
-setup_add_user(q, argv, cl)
+
+/* access_member - allow user to access member of type "USER" and name matches
+ * username, or to access member of type "LIST" and list is one that user is
+ * on the acl of, or the list is visible.
+ */
+
+access_member(q, argv, cl)
     struct query *q;
-    register char *argv[];
+    char *argv[];
     client *cl;
-##{
-##  int nuid;
-##  int exists;
+{
+    if (!strcmp(argv[0], "LIST") || !strcmp(argv[0], "RLIST"))
+      return(access_visible_list(q, &argv[1], cl));
 
-    if (!bcmp(argv[1], "#", 2)) {
-##      range of u is users
-##      range of v is values
-##      repeat retrieve (nuid = v.value) where v.name = "uid"
-       exists = 1;
-       while (exists) {
-           nuid++;
-##          repeat retrieve (exists = any(u.#uid where u.#uid = @nuid))
-       }
-##     repeat replace v (value = @nuid) where v.name = "uid"
-       sprintf(argv[1], "%d", nuid);
+    if (!strcmp(argv[0], "USER") || !strcmp(argv[0], "RUSER")) {
+       if (!strcmp(cl->kname.name, argv[1]))
+         return(SMS_SUCCESS);
     }
 
-    if (!bcmp(argv[0], "#", 2)) {
-       sprintf(argv[0], "#%s", argv[1]);
-    }
+    return(SMS_PERM);
+}
 
-    return(SMS_SUCCESS);
-##}
 
-/**
- ** followup_add_user - add finger entry, set_user_modtime
- ** followup_delete_user - delete finger entry
- **
- ** Inputs:
- **   argv[0] - login (add_user)
- **   argv[0] - users_id (delete_user)
- **
- **/
+/* access_qgli - special access routine for Qualified_get_lists.  Allows
+ * access iff argv[0] == "TRUE" and argv[2] == "FALSE".
+ */
+
+access_qgli(q, argv, cl)
+    struct query *q;
+    char *argv[];
+    client *cl;
+{
+    if (!strcmp(argv[0], "TRUE") && !strcmp(argv[2], "FALSE"))
+      return(SMS_SUCCESS);
+    return(SMS_PERM);
+}
+
+
+/* access_service - allow access if user is on ACL of service.  Don't
+ * allow access if a wildcard is used.
+ */
 
-followup_add_user(q, argv)
+access_service(q, argv, cl)
     struct query *q;
     char *argv[];
+    client *cl;
 ##{
-##  char *login;
-##  int users_id;
-##  char first[33];
-##  char middle[33];
-##  char last[33];
-##  char fullname[128];
-    register char *cp1;
-    register char *cp2;
+##  int acl_id, rowcount;
+##  char *name, acl_type[9];
+    int client_id, status;
+    char *client_type;
 
-    login = argv[0];
+    name = argv[0];
+##  repeat retrieve (acl_id = servers.#acl_id, acl_type = servers.#acl_type)
+##     where servers.#name = @name
+##  inquire_equel(rowcount = "rowcount")
+    if (rowcount > 1)
+      return(SMS_PERM);
 
-    /* get user information */
-##  range of u is users
-##  repeat retrieve (users_id = u.#users_id, last = u.#last,
-##                   first = u.#first, middle = u.#middle) 
-##         where u.#login = @login
+    /* parse client structure */
+    if ((status = get_client(cl, &client_type, &client_id)) != SMS_SUCCESS)
+       return(status);
 
-    /* build fullname */
-    cp2 = fullname;
-    cp1 = first;
-    while (*cp1) *cp2++ = *cp1++;
-    *cp2++ = ' ';
-    cp1 = middle;
-    if (*cp1 == 0) cp2--;
-    while (*cp1) *cp2++ = *cp1++;
-    *cp2++ = ' ';
-    cp1 = last;
-    while (*cp2++ = *cp1++) ;
-
-    /* create a finger entry */
-##  repeat append finger (#users_id = @users_id, #fullname = @fullname)
-
-    /* set modtime (creation time) on user */
-##  repeat replace u (modtime = "now") where u.#users_id = @users_id
+    /* check for client in access control list */
+    status = find_member(acl_type, acl_id, client_type, client_id, 0);
+    if (!status) return(SMS_PERM);
 
     return(SMS_SUCCESS);
 ##}
 
-followup_delete_user(q, argv)
+
+
+/* access_filesys - verify that client is owner or on owners list of filesystem
+ *     named by argv[0]
+ */
+
+access_filesys(q, argv, cl)
     struct query *q;
     char *argv[];
+    client *cl;
 ##{
-##  int users_id;
+##  int rowcount, users_id, list_id;
+##  char *name;
+    int status, client_id;
+    char *client_type;
 
-    users_id = *(int *)argv[0];
-##  repeat delete finger where finger.#users_id = @users_id
-    return(SMS_SUCCESS);
+    name = argv[0];
+##  repeat retrieve (users_id = filesys.owner, list_id = filesys.owners)
+##     where filesys.label = @name
+##  inquire_equel(rowcount = "rowcount")
+
+    if (rowcount != 1)
+      return(SMS_PERM);
+    if (users_id == cl->users_id)
+      return(SMS_SUCCESS);
+    if ((status = get_client(cl, &client_type, &client_id)) != SMS_SUCCESS)
+       return(status);
+    status = find_member("LIST", list_id, client_type, client_id, 0);
+    if (status)
+      return(SMS_SUCCESS);
+    return(SMS_PERM);
 ##}
+
+    
 \f
-/**
- ** setup_add_filesys - verify existance of referenced file systems
- ** setup_update_filesys - same, except argv[1..5] --> argv[2..6]
- **
- ** Inputs:     Add         Update
- **   argv[0] - label       label
- **   argv[1] - type        new label
- **   argv[2] - mach_id     type
- **   argv[3] - name        mach_id
- **   argv[4] - mount       name
- **   argv[5] - access      mount
- **   argv[6] -             access
- **
- ** Description:
- **   - for type = RVD:
- **        * verify mach_id/name in rvdvirt
- **        * verify access in {r, x, R, X}
- **   - for type = NFS:
- **        * extract directory prefix from name
- **        * verify mach_id/dir in nfsphys
- **        * verify access in {r, w, R, W}
- **
- ** Errors:
- **   SMS_RVD - no such rvd
- **   SMS_NFS - specified directory not exported
- **   SMS_FILESYS_ACCESS - invalid filesys access
- **
- **/
+/* Setup Routines */
+
+/* Setup routine for add_user
+ *
+ * Inputs: argv[0] - login
+ *         argv[1] - uid
+ *
+ * Description:
+ *
+ * - if argv[1] == UNIQUE_UID then set argv[1] = next(uid)
+ * - if argv[0] == UNIQUE_LOGIN then set argv[0] = "#<uid>"
+ */
 
-setup_add_filesys(q, argv)
+setup_ausr(q, argv, cl)
     struct query *q;
-    char *argv[];
-{
-    char *type;
-    int mach_id;
-    char *name;
-    char *access;  
+    register char *argv[];
+    client *cl;
+##{
+##  int nuid, rowcount;
+
+    if (!strcmp(argv[1], UNIQUE_UID) || atoi(argv[1]) == -1) {
+       if (set_next_object_id("uid", "users"))
+         return(SMS_INGRES_ERR);
+##      repeat retrieve (nuid = values.value) where values.name = "uid"
+##     inquire_equel(rowcount = "rowcount")
+       if (rowcount != 1)
+         return(SMS_INTERNAL);
+       sprintf(argv[1], "%d", nuid);
+    }
 
-    type = argv[1];
-    mach_id = *(int *)argv[2];
-    name = argv[3];
-    access = argv[5];
+    if (!strcmp(argv[0], UNIQUE_LOGIN) || atoi(argv[1]) == -1) {
+       sprintf(argv[0], "#%s", argv[1]);
+    }
 
-    if (!bcmp(type, "RVD", 3))
-       return (check_rvd(mach_id, name, access));
-    else if (!bcmp(type, "NFS", 3))
-       return (check_nfs(mach_id, name, access));
-    else
-       return(SMS_SUCCESS);
-}
+    return(SMS_SUCCESS);
+##}
 
-setup_update_filesys(q, argv)
-    struct query *q;
-    char *argv[];
-{
-    char *type;
-    int mach_id;
-    char *name;
-    char *access;  
 
-    type = argv[2];
-    mach_id = *(int *)argv[3];
-    name = argv[4];
-    access = argv[6];
+/* setup_dusr - verify that the user is no longer being referenced 
+ * and may safely be deleted.
+ */
 
-    if (!bcmp(type, "RVD", 3))
-       return (check_rvd(mach_id, name, access));
-    else if (!bcmp(type, "NFS", 3))
-       return (check_nfs(mach_id, name, access));
+int setup_dusr(q, argv)
+    struct query *q;
+    char **argv;
+##{
+##  int flag, id;
+
+    id = *(int *)argv[0];
+##  repeat retrieve (flag = any(members.member_id where members.member_id=@id
+##                      and members.member_type = "USER"))
+    if (flag)
+       return(SMS_IN_USE);
+##  repeat retrieve (flag = any(filesys.label where filesys.owner=@id))
+    if (flag)
+       return(SMS_IN_USE);
+##  repeat retrieve (flag = any(list.name where list.acl_id=@id and
+##                     list.acl_type = "USER"))
+    if (flag)
+       return(SMS_IN_USE);
+##  repeat retrieve (flag = any(servers.name where servers.acl_id=@id and
+##                     servers.acl_type = "USER"))
+    if (flag)
+       return(SMS_IN_USE);
     else
        return(SMS_SUCCESS);
-}
+##}
 
-##check_rvd(mach_id, name, access)
-##  int mach_id;
-##  char *name;
-    char *access;
+
+/* setup_spop: verify that there is already a valid POP machine_id in the
+ * pop_id field.  Also take care of keeping track of the post office usage.
+ */
+int setup_spop(q, argv)
+struct query *q;
+char **argv;
 ##{
-##  int rowcount;
-    char caccess;
+##  int id, flag;
+##  char type[9];
+
+    id = *(int *)argv[0];
+##  repeat retrieve (type = u.potype, flag = any(machine.name
+##                                     where machine.mach_id = u.pop_id 
+##                                             and u.pop_id != 0
+##                                             and u.users_id = @id))
+    if (!flag)
+      return(SMS_MACHINE);
+    if (strcmp(type, "POP"))
+      set_pop_usage(id, 1);
+    return(SMS_SUCCESS);
+##}
 
-##  range of rv is rvdvirt
-##  retrieve (rowcount = any(rv.#name where rv.#mach_id = mach_id and
-##                           rv.#name = name))
-    if (rowcount == 0) return(SMS_RVD);
 
-    caccess = (isupper(*access)) ? tolower(*access) : *access;
-    if (caccess != 'r' && caccess != 'x') return(SMS_FILESYS_ACCESS);
+/* setup_dpob:  Take care of keeping track of the post office usage.
+ */
+int setup_dpob(q, argv)
+struct query *q;
+char **argv;
+##{
+##  int id, user;
+##  char type[9];
+
+    user = *(int *)argv[0];
+##  repeat retrieve (type = u.potype, id = u.pop_id)
+##             where u.users_id = @user
 
+    if (strcmp(type, "POP"))
+      set_pop_usage(id, -1);
     return(SMS_SUCCESS);
 ##}
 
-##check_nfs(mach_id, name, access)
-##  int mach_id;
-    char *name;
-    char *access;
-##{
-##  int rowcount;
-##  char dir[32];
-    char caccess;
-    register int status;
-    register char *cp1;
-    register char *cp2;
 
-    caccess = (isupper(*access)) ? tolower(*access) : *access;
-    if (caccess != 'r' && caccess != 'w') return(SMS_FILESYS_ACCESS);
+/* setup_dmac - verify that the machine is no longer being referenced 
+ * and may safely be deleted.
+ */
 
-    status = SMS_NFS;
-##  range of np is nfsphys
-##  retrieve (dir = np.#dir) where np.#mach_id = mach_id
-##  {
-        cp1 = name;
-        cp2 = dir;
-        while (*cp2) {
-            if (*cp1++ != *cp2) break;
-            cp2++;
-        }
-        if (*cp2 == 0) {
-            status = SMS_SUCCESS;
-##           endretrieve
-        }
-##  }
-
-    return(status);
-##}
-\f
-/* Followup Routines */
-
-set_user_modtime(q, argv)
+int setup_dmac(q, argv)
     struct query *q;
-    char *argv[];
+    char **argv;
 ##{
-##  char *login;
-
-    login = argv[0];
-##  repeat replace u (modtime = "now") where u.#login = @login
-    return(SMS_SUCCESS);
+##  int flag, id;
+
+    id = *(int *)argv[0];
+##  repeat retrieve (flag = any(users.login where users.potype = "POP" 
+##                                               and users.pop_id=@id))
+    if (flag)
+       return(SMS_IN_USE);
+##  repeat retrieve (flag = any(serverhosts.mach_id
+##                              where serverhosts.mach_id=@id))
+    if (flag)
+       return(SMS_IN_USE);
+##  repeat retrieve (flag = any(nfsphys.mach_id where nfsphys.mach_id=@id))
+    if (flag)
+       return(SMS_IN_USE);
+##  repeat retrieve (flag = any(hostaccess.mach_id where hostaccess.mach_id=@id))
+    if (flag)
+       return(SMS_IN_USE);
+    else
+       return(SMS_SUCCESS);
 ##}
 
-set_user_modtime_by_id(q, argv)
-    struct query *q;
-    char *argv[];
-##{
-##  int users_id;
 
-    users_id = *(int *)argv[0];
-##  repeat replace users (modtime = "now") where users.#users_id = @users_id
-    return(SMS_SUCCESS);
-##}
+/* setup_dclu - verify that the cluster is no longer being referenced 
+ * and may safely be deleted.
+ */
 
-set_list_modtime(q, argv)
+int setup_dclu(q, argv)
     struct query *q;
-    char *argv[];
+    char **argv;
 ##{
-##  char *list_name;
-
-    list_name = argv[0];
-##  repeat replace list (modtime = "now") where list.name = @list_name
-    return(SMS_SUCCESS);
+##  int flag, id;
+
+    id = *(int *)argv[0];
+##  repeat retrieve (flag = any(mcmap.mach_id where mcmap.clu_id=@id))
+    if (flag)
+       return(SMS_IN_USE);
+##  repeat retrieve (flag = any(svc.clu_id where svc.clu_id=@id))
+    if (flag)
+       return(SMS_IN_USE);
+    else
+       return(SMS_SUCCESS);
 ##}
 
-set_list_modtime_by_id(q, argv)
-    struct query *q;
-    char *argv[];
-##{
-##  int list_id;
 
-    list_id = *(int *)argv[0];
-##  repeat replace list (modtime = "now") where list.#list_id = @list_id
-##  repeat replace list (modtime = "now") where list.#acl_id = @list_id
-    return(SMS_SUCCESS);
-##}
+/* setup_alis - if argv[5] is non-zero and argv[6] is UNIQUE_ID, then allocate
+ * a new gid and put it in argv[6].  Otherwise if argv[6] is UNIQUE_ID but
+ * argv[5] is not, then remember that UNIQUE_ID is being stored by putting
+ * a -1 there.  Remember that this is also used for ulis, with the indexes
+ * at 6 & 7.
+ */
 
-set_finger_modtime(q, argv)
-    struct query *q;
-    char *argv[];
+int setup_alis(q, argv)
+struct query *q;
+char **argv;
 ##{
-##  int users_id;
+##  int ngid;
+    char *malloc();
+    int idx;
+
+    if (!strcmp(q->shortname, "alis"))
+      idx = 6;
+    else if (!strcmp(q->shortname, "ulis"))
+      idx = 7;
+
+    if (!strcmp(argv[idx], UNIQUE_GID) || atoi(argv[idx]) == -1) {
+       if (atoi(argv[idx - 1])) {
+           if (set_next_object_id("gid", "list"))
+             return(SMS_INGRES_ERR);
+##         repeat retrieve (ngid = values.value) where values.name = "gid"
+           sprintf(argv[idx], "%d", ngid);
+       } else {
+           strcpy(argv[idx], "-1");
+       }
+    }
 
-    users_id = *(int *)argv[0];
-##  repeat replace f (modtime = "now") where f.#users_id = @users_id
     return(SMS_SUCCESS);
 ##}
-\f
-/**
- ** followup_amtl - followup for amtl and dmfl; when adding a list 
- **                 member to a maillist, add list to maillist table,
- **                 unless list is a user-group.
- **                 Then set_list_modtime_by_id.
- **
- ** Inputs:
- **   argv[0] - list_id
- **   argv[1] - member_type
- **   argv[2] - member_id
- **
- **/
 
-followup_amtl(q, argv)
+
+/* setup_dlist - verify that the list is no longer being referenced 
+ * and may safely be deleted.
+ */
+
+int setup_dlis(q, argv)
     struct query *q;
-    char *argv[];
+    char **argv;
 ##{
-##  int list_id;
-##  int member_id;
-##  int exists;
-##  char list_name[33];
+##  int flag, id;
+
+    id = *(int *)argv[0];
+##  repeat retrieve (flag = any(members.member_id where members.member_id=@id
+##                      and members.member_type = "LIST"))
+    if (flag)
+       return(SMS_IN_USE);
+##  repeat retrieve (flag = any(members.member_id where members.list_id=@id))
+    if (flag)
+       return(SMS_IN_USE);
+##  repeat retrieve (flag = any(filesys.label where filesys.owners=@id))
+    if (flag)
+       return(SMS_IN_USE);
+##  repeat retrieve (flag = any(capacls.tag where capacls.list_id=@id))
+    if (flag)
+       return(SMS_IN_USE);
+##  repeat retrieve (flag = any(list.name where list.acl_id=@id and
+##                     list.acl_type = "LIST"))
+    if (flag)
+       return(SMS_IN_USE);
+##  repeat retrieve (flag = any(servers.name where servers.acl_id=@id and
+##                     servers.acl_type = "LIST"))
+    if (flag)
+       return(SMS_IN_USE);
+##  repeat retrieve (flag = any(zephyr.class
+##             where zephyr.xmt_type = "LIST" and zephyr.xmt_id = @id or
+##                   zephyr.sub_type = "LIST" and zephyr.sub_id = @id or
+##                   zephyr.iws_type = "LIST" and zephyr.iws_id = @id or
+##                   zephyr.iui_type = "LIST" and zephyr.iui_id = @id))
+    if (flag)
+        return(SMS_IN_USE);
+    else
+       return(SMS_SUCCESS);
+##}
 
-    list_id = *(int *)argv[0];
 
-##  repeat replace list (modtime = "now") where list.#list_id = @list_id
-##  repeat replace list (modtime = "now") where list.#acl_id = @list_id
+/* setup_dsin - verify that the service is no longer being referenced 
+ * and may safely be deleted.
+ */
 
-    /* if query is not amtl or if member_type is not LIST then return */
-    if (bcmp(q->shortname, "amtl", 4) || bcmp(argv[1], "LIST", 4)) 
+int setup_dsin(q, argv)
+    struct query *q;
+    char **argv;
+##{
+##  int flag;
+##  char *name;
+
+    name = argv[0];
+##  repeat retrieve (flag = any(serverhosts.service where serverhosts.service=@name))
+    if (flag)
+       return(SMS_IN_USE);
+##  repeat retrieve (flag = servers.inprogress) where servers.#name = @name
+    if (flag)
+       return(SMS_IN_USE);
+    else
        return(SMS_SUCCESS);
+##}
 
-    member_id = *(int *)argv[2];
-##  range of l is list
-##  range of ml is maillists
-##  range of g is groups
 
-    /* is parent list a mailing list? */
-##  repeat retrieve (exists = any(ml.#list_id where ml.#list_id=@list_id))
-
-    /* if not then return */
-    if (!exists) return(SMS_SUCCESS);
-
-    /* is member_list a user-group? */
-    /* is it a group? */
-##  repeat retrieve (exists = any(g.#list_id where g.#list_id = @member_id))
-    if (exists) {
-       /* get list_name */
-##      repeat retrieve (list_name = l.#name) where l.#list_id = @member_id
-       /* is list_name a username? */
-##      repeat retrieve (exists = any(users.login 
-##                                   where users.login = @list_name))
-       /* yes, return error */
-       if (exists) return(SMS_USER_GROUP);
-    }
+/* setup_dshi - verify that the service-host is no longer being referenced 
+ * and may safely be deleted.
+ */
 
-    /* list is not a user-group; add list to maillist table */
-##  repeat append maillists (#list_id = @member_id, ltid = l.tid)
-##         where l.#list_id = @member_id
+int setup_dshi(q, argv)
+    struct query *q;
+    char **argv;
+##{
+##  int flag, id;
+##  char *name;
 
-    return(SMS_SUCCESS);
+    name = argv[0];
+    id = *(int *)argv[1];
+##  repeat retrieve (flag=serverhosts.inprogress) 
+##     where serverhosts.service=@name and serverhosts.mach_id=@id
+    if (flag)
+       return(SMS_IN_USE);
+    else
+       return(SMS_SUCCESS);
 ##}
-\f
+
+
 /**
- ** followup_add_pobox
- ** followup_delete_pobox - followup routines for pobox queries
+ ** setup_add_filesys - verify existance of referenced file systems
+ **
+ ** Inputs:     Add
+ **   argv[1] - type
+ **   argv[2] - mach_id
+ **   argv[3] - name
+ **   argv[5] - access
  **
  ** Description:
- **   add_pobox: set pobox creation time
- **              increment pop usage in serverhosts
+ **   - for type = RVD:
+ **       * allow anything
+ **   - for type = NFS:
+ **        * extract directory prefix from name
+ **        * verify mach_id/dir in nfsphys
+ **        * verify access in {r, w, R, W}
+ **
+ **  Side effect: sets variable var_phys_id to the ID of the physical
+ **    filesystem (nfsphys_id for NFS, 0 for RVD)
  **
- **   delete_pobox: decrement pop usage in serverhosts
+ ** Errors:
+ **   SMS_NFS - specified directory not exported
+ **   SMS_FILESYS_ACCESS - invalid filesys access
  **
  **/
 
-followup_add_pobox(q, argv)
-    struct query *q;
-    char *argv[];
-{
-    set_pobox_creation(q, argv);
-    set_pop_usage(q, argv, 1);
-    return(SMS_SUCCESS);
-}
+##static int var_phys_id;
 
-followup_delete_pobox(q, argv)
+setup_afil(q, argv)
     struct query *q;
     char *argv[];
 {
-    set_pop_usage(q, argv, -1);
-    return(SMS_SUCCESS);
-}
-
-set_pobox_creation(q, argv)
-    struct query *q;
-    char *argv[];
-##{
-##  int users_id;
-##  int mach_id;
-##  char *type;
-##  char *box;
+    char *type;
+    int mach_id;
+    char *name;
+    char *access;  
 
-    users_id = *(int *)argv[0];
     type = argv[1];
     mach_id = *(int *)argv[2];
-    box = argv[3];
-
-##  range of p is pobox
-##  repeat replace p (created = "now") 
-##         where p.#users_id = @users_id and p.#type = @type and
-##               p.#mach_id = @mach_id and p.#box = @box
+    name = argv[3];
+    access = argv[5];
+    var_phys_id = 0;
 
-    return (SMS_SUCCESS);
-##}
+    if (!strcmp(type, "NFS"))
+       return (check_nfs(mach_id, name, access));
+    else
+       return(SMS_SUCCESS);
+}
 
-/**
- ** set_pop_usage - incr/decr usage count for pop server in serverhosts talbe
- **
- ** Inputs:
- **   q->name - "add_pobox" or "delete_pobox"
- **   argv[1] - type
- **   argv[2] - mach_id
- **
- ** Description:
- **   - incr/decr value field in serverhosts table for pop/mach_id
- **
- **/
 
-set_pop_usage(q, argv, count)
+setup_ufil(q, argv)
     struct query *q;
     char *argv[];
-##{
-##  int mach_id;
-##  int n;
-
-    if (bcmp(argv[1], "POP", 3)) return(SMS_SUCCESS);
+{
+    char *type;
+    int mach_id;
+    char *name;
+    char *access;  
 
-    mach_id = *(int *)argv[2];
-    n = count;
+    type = argv[2];
+    mach_id = *(int *)argv[3];
+    name = argv[4];
+    access = argv[6];
+    var_phys_id = 0;
 
-##  range of sh is serverhosts
-##  repeat replace sh (value1 = sh.value1 + @n)
-##         where sh.service = "pop" and sh.#mach_id = @mach_id
+    if (!strcmp(type, "NFS"))
+       return (check_nfs(mach_id, name, access));
+    else
+       return(SMS_SUCCESS);
+}
 
-    return(SMS_SUCCESS);
-##}
 
-/**
- ** delete_user_poboxes - delete all poboxes for a user
- **
- ** Inputs:
- **   argv[0] - users_id
- **
- **/
+/* Find the NFS physical partition that the named directory is on.
+ * This is done by comparing the dir against the mount point of the
+ * partition.  To make sure we get the correct match when there is 
+ * more than one, we sort the query in reverse order by dir name.
+ */
 
-delete_user_poboxes(q, argv)
-    struct query *q;
-    char *argv[];
-##{
-##  int users_id;
-##  int n;
+##check_nfs(mach_id, name, access)
 ##  int mach_id;
-    register int i;
-    int mach_ids[10];
+    char *name;
+    char *access;
+##{
+##  char dir[32];
+    char caccess;
+    register int status;
+    register char *cp1;
+    register char *cp2;
 
-    users_id = *(int *)argv[0];
+    caccess = (isupper(*access)) ? tolower(*access) : *access;
+    if (caccess != 'r' && caccess != 'w') return(SMS_FILESYS_ACCESS);
 
-    /* get machine ids for pop server(s) on which the user currently exists */
-##  range of p is pobox
-    i = 0;
-##  repeat retrieve (mach_id = p.#mach_id) 
-##         where p.#users_id = @users_id and p.type = "POP"
-##  {
-        mach_ids[i++] = mach_id;
-        if (i == 10) {
+    status = SMS_NFS;
+##  range of np is nfsphys
+##  repeat retrieve (var_phys_id = np.#nfsphys_id, dir = trim(np.#dir))
+##     where np.#mach_id = @mach_id sort by #dir:d {
+        cp1 = name;
+        cp2 = dir;
+        while (*cp2) {
+            if (*cp1++ != *cp2) break;
+            cp2++;
+        }
+        if (*cp2 == 0) {
+            status = SMS_SUCCESS;
 ##           endretrieve
         }
 ##  }
 
-    /* decrement counts on serverhost entries */
-##  range of sh is serverhosts
-    while (--i >= 0) {
-       mach_id = mach_ids[i];
-##      repeat replace sh (value1 = sh.value1 - 1)
-##             where sh.service = "pop" and sh.#mach_id = @mach_id
-    }
-
-    /* delete user's poboxes */
-##  repeat delete p where p.#users_id = @users_id
-
-    return(SMS_SUCCESS);
+    return(status);
 ##}
 
-\f
-/**
- ** add_new_quota
- ** delete_current_quota - adjust nfsphys values on xxx_quota queries.
- **
- ** Inputs:
- **   argv[0] - mach_id
- **   argv[1] - device
- **   argv[2] - users_id
- **   argv[3] - quota (add_new_quota only)
- **
- ** Description:
- **   delete_current_quota:
- **     - find nfsquota entry
- **     - decrement nfsphys.allocated by nfsquota.quota
- **   add_new_quota
- **     - increment nfsphys.allocated by quota
- **
- **/
 
-add_new_quota(q, argv)
-    struct query *q;
-    register char *argv[];
-##{
-##  int mach_id;
-##  char *device;
-##  int quota;
+/* setup_dfil: free any quota records associated with a filesystem
+ * when it is deleted.
+ */
 
-    mach_id = *(int*)argv[0];
-    device = argv[1];
-    quota = *(int *)argv[3];
+setup_dfil(q, argv, cl)
+    struct query  *q;
+    char **argv;
+    client *cl;
+##{
+##  int id;
 
-##  range of np is nfsphys
-##  repeat replace np (allocated = np.allocated + @quota)
-##      where np.#mach_id = @mach_id and np.#device = @device
+    id = *(int *)argv[0];
+##  range of q is nfsquota
+##  repeat replace nfsphys (allocated = nfsphys.allocated - q.quota)
+##     where nfsphys.nfsphys_id = fs.phys_id and 
+##           q.filsys_id = @id and fs.filsys_id = @id
 
+##  repeat delete q where q.filsys_id = @id
     return(SMS_SUCCESS);
 ##}
 
-delete_current_quota(q, argv, cl)
-    struct query *q;
-    register char *argv[];
+
+/* setup_dnfp: check to see that the nfs physical partition does not have
+ * any filesystems assigned to it before allowing it to be deleted.
+ */
+
+setup_dnfp(q, argv, cl)
+    struct query  *q;
+    char **argv;
     client *cl;
 ##{
-##  int mach_id;
-##  int users_id;
-##  char *device;
-##  int quota;
+##  int id, exists;
 
-    mach_id = *(int *)argv[0];
-    device = argv[1];
-    users_id = *(int *)argv[2];
-
-##  range of np is nfsphys
-##  range of nq is nfsquota
-##  repeat retrieve (quota = nq.#quota) 
-##      where nq.#mach_id = @mach_id and nq.#device = @device and
-##            nq.#users_id = @users_id
-##  repeat replace np (allocated = np.allocated - @quota)
-##      where np.#mach_id = @mach_id and np.#device = @device
+    id = *(int *)argv[0];
+##  repeat retrieve (exists = any(filesys.label where filesys.phys_id = @id))
+    if (exists)
+      return(SMS_IN_USE);
     return(SMS_SUCCESS);
 ##}
-\f
-/**
- ** add_hostaccess - create entry in hostaccess table upon adding a new
- **                  machine to the serverhosts table where service =
- **                  "hostaccess".
- **
- ** Inputs:
- **   argv[0] - service
- **   argv[1] - mach_id
- **
- **/
 
-add_hostaccess(q, argv)
-    struct query *q;
-    char *argv[];
-##{
-##  int mach_id;
 
-    /* only work with service = "hostaccess" */
-    if (bcmp(argv[0], "hostaccess", 10)) return(SMS_SUCCESS);
+/* setup_ssif: check to see if lock is already set.  If it is not set or
+ * it is set, but this request is turning it off, fine.  Otherwise, give
+ * a lock error.  setup_sshi is the same for each serverhost.
+ */
 
-    mach_id = *(int *)argv[1];
-##  repeat append hostaccess (#mach_id = @mach_id, status = 0)
-##  repeat replace tblstats (modtime = "now", appends = tblstats.appends + 1)
-##         where tblstats.table = "hostaccess"
+setup_ssif(q, argv, cl)
+    struct query  *q;
+    char **argv;
+    client *cl;
+##{
+##  char *service;
+##  int lock;
+
+    service = argv[0];
+##  repeat retrieve (lock = s.inprogress) where s.name = @service
+    if (lock && atoi(argv[2]))
+      return(SMS_LOCKED);
     return(SMS_SUCCESS);
 ##}
 
-/* followup to delete_server_host_info */
 
-delete_hostaccess(q, argv)
+setup_sshi(q, argv, cl)
+    struct query  *q;
+    char **argv;
+    client *cl;
+##{
+##  char *service;
+##  int lock, mach_id;
+
+    service = argv[0];
+    mach_id = *(int *)argv[1];
+##  repeat retrieve (lock = sh.inprogress) where sh.#mach_id = @mach_id and
+##             sh.#service = @service
+    if (lock && atoi(argv[4]))
+      return(SMS_LOCKED);
+    return(SMS_SUCCESS);
+##}
+
+
+/* setup_dnfq: Remove allocation from nfsphys before deleting quota.
+ *   argv[0] = filsys_id
+ *   argv[1] = users_id
+ */
+
+setup_dnfq(q, argv, cl)
+    struct query  *q;
+    char **argv;
+    client *cl;
+##{
+##  int quota, fs, user;
+
+    fs = *(int *)argv[0];
+    user = *(int *)argv[1];
+
+##  range of q is nfsquota
+##  repeat retrieve (quota = q.#quota) where q.users_id = @user and
+##     q.filsys_id = @fs
+##  repeat replace nfsphys (allocated = nfsphys.allocated - @quota)
+##     where nfsphys.nfsphys_id = filesys.#phys_id and filesys.filsys_id = @fs
+    return(SMS_SUCCESS);
+##}
+
+
+\f
+/* FOLLOWUP ROUTINES */
+
+/* generic set_modtime routine.  This takes the table name from the query,
+ * and will update the modtime, modby, and modwho fields in the entry in
+ * the table whose name field matches argv[0].
+ */
+
+set_modtime(q, argv, cl)
     struct query *q;
     char *argv[];
+    client *cl;
 ##{
-##  int mach_id;
+##  char *name, *entity, *table;
+##  int who;
 
-    /* only work with service = "hostaccess" */
-    if (bcmp(argv[0], "hostaccess", 10)) return(SMS_SUCCESS);
+    entity = cl->entity;
+    who = cl->users_id;
+    table = q->rtable;
+    name = argv[0];
 
-    mach_id = *(int *)argv[1];
-##  repeat delete hostaccess where hostaccess.#mach_id = @mach_id
-##  repeat replace tblstats (modtime = "now", deletes = tblstats.deletes + 1)
-##         where tblstats.table = "hostaccess"
+##  replace table (modtime = "now", modby = who, modwith = entity)
+##      where table.#name = name
     return(SMS_SUCCESS);
 ##}
 
-followup_ushp(q, argv)
+/* generic set_modtime_by_id routine.  This takes the table name from
+ * the query, and the id name from the validate record,
+ * and will update the modtime, modby, and modwho fields in the entry in
+ * the table whose id matches argv[0].
+ */
+
+set_modtime_by_id(q, argv, cl)
     struct query *q;
-    char *argv[];
+    char **argv;
+    client *cl;
 ##{
-##  int mach_id;
-##  int status;
+##  char *entity, *table, *id_name;
+##  int who, id;
+
+    entity = cl->entity;
+    who = cl->users_id;
+    table = q->rtable;
+    id_name = q->validate->object_id;
 
-    mach_id = *(int *)argv[0];
-##  range of ha is hostaccess
-##  repeat retrieve (status = ha.#status) where ha.#mach_id = @mach_id
-    status |= 1;
-##  repeat replace ha (#status = @status) where ha.#mach_id = @mach_id
+    id = *(int *)argv[0];
+##  replace table (modtime = "now", modby = who, modwith = entity)
+##      where table.id_name = id
     return(SMS_SUCCESS);
 ##}
 
-followup_usha(q, argv)
+
+/* Sets the finger modtime on a user record.  The users_id will be in argv[0].
+ */
+
+set_finger_modtime(q, argv, cl)
     struct query *q;
     char *argv[];
+    client *cl;
 ##{
-##  int mach_id;
-##  int status;
+##  int users_id, who;
+##  char *entity;
+
+    entity = cl->entity;
+    who = cl->users_id;
+    users_id = *(int *)argv[0];
 
-    mach_id = *(int *)argv[0];
-##  range of ha is hostaccess
-##  repeat retrieve (status = ha.#status) where ha.#mach_id = @mach_id
-    status |= 2;
-##  repeat replace ha (#status = @status) where ha.#mach_id = @mach_id
+##  repeat replace u (fmodtime = "now", fmodby = @who, fmodwith = @entity)
+##      where u.#users_id = @users_id
     return(SMS_SUCCESS);
 ##}
-\f
-/**
- ** followup_delete_list - called after the delete_list query to clean up
- **                       members table; also deletes list from maillist
- **                        and groups tables.
- **
- ** Inputs: argv[0] - list_id
- **
- ** Description:
- **   - foreach string member: decr string refc; ifzero, delete string
- **   - delete all members entries for this list_id
- **
- **/
 
-followup_delete_list(q, argv)
+
+/* Sets the pobox modtime on a user record.  The users_id will be in argv[0].
+ */
+
+set_pobox_modtime(q, argv, cl)
     struct query *q;
-    register char *argv[];
+    char **argv;
+    client *cl;
 ##{
-##  int list_id;
-##  int string_id;
-##  int refc;
-##  int rowcount;
-    struct save_queue *sq;
-    struct save_queue *sq_create();
+##  int users_id, who;
+##  char *entity;
 
-    list_id = *(int *)argv[0];
-    sq = sq_create();
+    entity = cl->entity;
+    who = cl->users_id;
+    users_id = *(int *)argv[0];
 
-##  range of m is members
-##  repeat retrieve (string_id = m.member_id)
-##         where m.#list_id = @list_id and m.member_type = "STRING"
-##  {
-        sq_save_data(sq, string_id);
-##  }
+##  repeat replace users (pmodtime = "now", pmodby = @who, pmodwith = @entity)
+##      where users.#users_id = @users_id
+    return(SMS_SUCCESS);
+##}
 
-    while (sq_get_data(sq, &string_id)) {
-##     range of s is strings
-##     repeat retrieve (refc = s.#refc) where s.#string_id = @string_id
-##      inquire_equel (rowcount = "rowcount")
-       if (rowcount == 0) continue;
-       if (--refc == 0) {
-##         repeat delete s where s.#string_id = @string_id
-       } else {
-##         repeat replace s (#refc = @refc) where s.#string_id = @string_id
-       }
-    }
-    sq_destroy(sq);
 
-##  repeat delete m where m.#list_id = @list_id
-##  repeat delete maillists where maillists.#list_id = @list_id
-##  repeat delete groups where groups.#list_id = @list_id
+/* Sets the modtime on a machine record.  The machine name is in argv[0].
+ * This routine is different from the generic set_modtime in that the
+ * name is uppercased first.
+ */
+
+set_mach_modtime(q, argv, cl)
+    struct query *q;
+    char **argv;
+    client *cl;
+##{
+##  char *host, *entity;
+##  int who;
+
+    entity = cl->entity;
+    who = cl->users_id;
 
+    host = argv[0];
+##  repeat replace m (modtime = "now", modby = @who, modwith = @entity)
+##      where m.name = uppercase(@host)
     return(SMS_SUCCESS);
 ##}
-\f
-/**
- ** followup_grvd - Support routine for get_rvd_servers query
- **
- ** Inputs:
- **    q     - grvd query structure
- **    sq    - save_queue struture: contains list of {machine, oper_acl_id,
- **            admin_acl_id, shutdown_acl_id} records.
- **    v     - validate structure (not used)
- **    action - action routine
- **    actarg - action routine argument
- **
- ** Description:
- **   - translate acl_ids to list names
- **
- **/
 
-followup_grvd(q, sq, v, action, actarg)
+
+/* Sets the modtime on the machine whose mach_id is in argv[0].  This routine
+ * is necessary for add_machine_to_cluster becuase the table that query
+ * operates on is "mcm", not "machine".
+ */
+
+set_mach_modtime_by_id(q, argv, cl)
     struct query *q;
-    struct save_queue *sq;
-    struct validate *v;
-    int (*action)();
-    int actarg;
-##{
     char **argv;
-    char *targv[4];
-##  char oper[33];
-##  char admin[33];
-##  char shutdown[33];
-##  int list_id;
+    client *cl;
+##{
+##  char *entity;
+##  int who, id;
 
-    targv[0] = oper;
-    targv[1] = admin;
-    targv[2] = shutdown;
+    entity = cl->entity;
+    who = cl->users_id;
 
-##  range of l is list
+    id = *(int *)argv[0];
+##  range of m is machine
+##  repeat replace m (modtime = "now", modby = @who, modwith = @entity)
+##      where m.mach_id = @id
+    return(SMS_SUCCESS);
+##}
 
-    while (sq_get_data(sq, &argv)) {
-       sscanf(argv[0], "%d", &list_id);
-##      repeat retrieve (oper = l.name) where l.#list_id = @list_id
-       sscanf(argv[1], "%d", &list_id);
-##      repeat retrieve (admin = l.name) where l.#list_id = @list_id
-       sscanf(argv[2], "%d", &list_id);
-##      repeat retrieve (shutdown = l.name) where l.#list_id = @list_id
-       
-       (*action)(3, targv, actarg);
-       free(argv[0]);
-       free(argv[1]);
-       free(argv[2]);
-    }
 
-    sq_destroy(sq);
+/* Sets the modtime on the cluster whose mach_id is in argv[0].  This routine
+ * is necessary for add_cluster_data and delete_cluster_data becuase the
+ * table that query operates on is "svc", not "cluster".
+ */
+
+set_cluster_modtime_by_id(q, argv, cl)
+    struct query *q;
+    char **argv;
+    client *cl;
+##{
+##  char *entity;
+##  int who, id;
+
+    entity = cl->entity;
+    who = cl->users_id;
+
+    id = *(int *)argv[0];
+##  range of c is cluster
+##  repeat replace c (modtime = "now", modby = @who, modwith = @entity)
+##      where c.clu_id = @id
     return(SMS_SUCCESS);
 ##}
 
-followup_gars(q, sq, v, action, actarg)
+
+/* sets the modtime on the serverhost where the service name is in argv[0]
+ * and the mach_id is in argv[1].
+ */
+
+set_serverhost_modtime(q, argv, cl)
     struct query *q;
-    struct save_queue *sq;
-    struct validate *v;
-    int (*action)();
-    int actarg;
+    char **argv;
+    client *cl;
 ##{
+##  char *entity, *serv;
+##  int who, id;
+
+    entity = cl->entity;
+    who = cl->users_id;
+
+    serv = argv[0];
+    id = *(int *)argv[1];
+##  repeat replace sh (modtime = "now", modby = @who, modwith = @entity)
+##      where sh.service = @serv and sh.mach_id = @id
+    return(SMS_SUCCESS);
+##}
+
+
+/* sets the modtime on the nfsphys where the mach_id is in argv[0] and the
+ * directory name is in argv[1].
+ */
+
+set_nfsphys_modtime(q, argv, cl)
+    struct query *q;
     char **argv;
-    char *targv[4];
-##  char oper[33];
-##  char admin[33];
-##  char shutdown[33];
-##  int list_id;
+    client *cl;
+##{
+##  char *entity, *dir;
+##  int who, id;
 
-    targv[1] = oper;
-    targv[2] = admin;
-    targv[3] = shutdown;
+    entity = cl->entity;
+    who = cl->users_id;
 
-##  range of l is list
+    id = *(int *)argv[0];
+    dir = argv[1];
+##  repeat replace np (modtime = "now", modby = @who, modwith = @entity)
+##      where np.#dir = @dir and np.mach_id = @id
+    return(SMS_SUCCESS);
+##}
 
-    while (sq_get_data(sq, &argv)) {
-       sscanf(argv[1], "%d", &list_id);
-##      repeat retrieve (oper = l.name) where l.#list_id = @list_id
-       sscanf(argv[2], "%d", &list_id);
-##      repeat retrieve (admin = l.name) where l.#list_id = @list_id
-       sscanf(argv[3], "%d", &list_id);
-##      repeat retrieve (shutdown = l.name) where l.#list_id = @list_id
-       
-       targv[0] = argv[0];
-       (*action)(4, targv, actarg);
-       free(argv[0]);
-       free(argv[1]);
-       free(argv[2]);
-       free(argv[3]);
-    }
 
-    sq_destroy(sq);
+/* sets the modtime on a filesystem, where argv[0] contains the filesys
+ * label.
+ */
+
+set_filesys_modtime(q, argv, cl)
+    struct query *q;
+    char *argv[];
+    client *cl;
+##{
+##  char *label, *entity;
+##  int who;
+
+    entity = cl->entity;
+    who = cl->users_id;
+
+    label = argv[0];
+    if (!strcmp(q->shortname, "ufil"))
+      label = argv[1];
+
+##  repeat replace fs (modtime = "now", modby = @who, modwith = @entity,
+##                    #phys_id = @var_phys_id)  where fs.#label = @label
     return(SMS_SUCCESS);
 ##}
-\f
-/**
- ** set_next_object_id - set next object id in values table
- **
- ** Inputs: object - object name in values table
- **
- ** - called before an APPEND operation to set the next object id to
- **   be used for the new record
- **
- **/
 
-set_next_object_id(object)
-    char *object;
+
+/* sets the modtime on a zephyr class, where argv[0] contains the class
+ * name.
+ */
+
+set_zephyr_modtime(q, argv, cl)
+    struct query *q;
+    char *argv[];
+    client *cl;
 ##{
+##  char *class, *entity;
+##  int who;
+
+    entity = cl->entity;
+    who = cl->users_id;
+
+    class = argv[0];
+
+##  repeat replace z (modtime = "now", modby = @who, modwith = @entity)
+##                    where z.#class = @class
+    return(SMS_SUCCESS);
+##}
+
+
+/* fixes the modby field.  This will be the second to last thing in the
+ * argv, the argv length is determined from the query structure.  It is
+ * passed as a pointer to an integer.  This will either turn it into a
+ * username, or # + the users_id.
+ */
+followup_fix_modby(q, sq, v, action, actarg, cl)
+    struct query *q;
+    register struct save_queue *sq;
+    struct validate *v;
+    register int (*action)();
+    register int actarg;
+    client *cl;
+##{
+    register int i, j;
+    char **argv, *malloc();
+##  int id, rowcount;
 ##  char *name;
-##  int rowcount;
 
-       name = object;
-##  range of v is values
-##  repeat replace v (value = v.value + 1) where v.#name = @name
-##      inquire_equel (rowcount = "rowcount")
-    if (rowcount != 1)
-       return SMS_INGRES_ERR;
-    else return(SMS_SUCCESS);
+    i = q->vcnt - 2;
+    while (sq_get_data(sq, &argv)) {
+       id = atoi(argv[i]);
+       free(argv[i]);
+       argv[i] = malloc(9);
+       name = argv[i];
+##     repeat retrieve (name = users.login) where users.users_id = @id
+##     inquire_equel(rowcount = "rowcount")
+       if (rowcount != 1) {
+           sprintf(argv[i], "#%d", id);
+       }
+       (*action)(q->vcnt, argv, actarg);
+       for (j = 0; j < q->vcnt; j++)
+         free(argv[j]);
+       free(argv);
+    }
+    sq_destroy(sq);
+    return(SMS_SUCCESS);
 ##}
 
+
 /**
- ** get_query_need - check modtime of query's associated table against given
- **                  time and return true if greater (false if not)
+ ** followup_ausr - add finger and pobox entries, set_user_modtime
  **
  ** Inputs:
- **   argv[0] - query name
- **   argv[1] - time to compare against
+ **    argv[0] - login (add_user)
+ **    argv[3] - last name
+ **    argv[4] - first name
+ **    argv[5] - middle name
  **
  **/
 
-get_query_need(q, argv, action, actarg)
+followup_ausr(q, argv, cl)
     struct query *q;
-    register char *argv[];
-    int (*action)();
+    char *argv[];
+    client *cl;
 ##{
-    struct query *q1;
-##  char *last_get_time;
-##  char *table;
-##  int need;
-    char *result;
-    struct query *get_query_by_name();
+##  int who;
+##  char *login, *entity;
+##  char fullname[129];
 
-    q1 = get_query_by_name(argv[0]);
+    login = argv[0];
+    who = cl->users_id;
+    entity = cl->entity;
 
-    last_get_time = argv[1];
-    table = q1->rtable;
+    /* build fullname */
+    if (strlen(argv[4]) && strlen(argv[5]))
+       sprintf(fullname, "%s %s %s", argv[4], argv[5], argv[3]);
+    else if (strlen(argv[4]))
+       sprintf(fullname, "%s %s", argv[4], argv[3]);
+    else
+       sprintf(fullname, "%s", argv[3]);
 
-    if (q1 == NULL || q1->type != RETRIEVE || table == NULL)
-       return(SMS_NO_MATCH);
+    /* create finger entry, pobox & set modtime on user */
+##  repeat replace u (modtime = "now", modby=@who, modwith=@entity,
+##          #fullname=@fullname, mit_affil = u.mit_year,
+##          fmodtime="now", fmodby=@who, fmodwith=@entity,
+##          potype="NONE", pmodtime="now", pmodby=@who, pmodwith=@entity)
+##     where u.#login = @login
 
-##  range of tbs is tblstats
-##  repeat retrieve (need = any(tbs.modtime where tbs.#table = @table and
-##                             tbs.modtime > @last_get_time))
-    
-    result = (need) ? "true" : "false";
-    (*action)(1, &result, actarg);
     return(SMS_SUCCESS);
 ##}
 
-/**
- ** get_list_is_group
- ** get_list_is_maillist
+
+/* followup_gpob: fixes argv[2] based on the IDs currently there and the
+ * type in argv[1].  Then completes the upcall to the user.
+ *
+ * argv[2] is of the form "123:234" where the first integer is the machine
+ * ID if it is a pop box, and the second is the string ID if it is an SMTP
+ * box.  argv[1] should be "POP", "SMTP", or "NONE".  Boxes of type NONE
+ * are skipped.
+ */
+
+followup_gpob(q, sq, v, action, actarg, cl)
+    register struct query *q;
+    register struct save_queue *sq;
+    register struct validate *v;
+    register int (*action)();
+    int actarg;
+    client *cl;
+##{
+    char **argv, *index();
+    char *ptype, *p;
+##  char box[129], *name;
+##  int mid, sid, rowcount;
+
+    /* for each row */
+    while (sq_get_data(sq, &argv)) {
+       sms_trim_args(2, argv);
+       ptype = argv[1];
+       p = index(argv[2], ':');
+       *p++ = 0;
+       mid = atoi(argv[2]);
+       sid = atoi(p);
+       free(argv[2]);
+
+       if (!strcmp(ptype, "POP")) {
+##         repeat retrieve (box=machine.#name) where machine.mach_id=@mid
+##         inquire_equel(rowcount = "rowcount")
+           if (rowcount != 1)
+             return(SMS_MACHINE);
+       } else if (!strcmp(ptype, "SMTP")) {
+##         repeat retrieve (box=strings.string) where strings.string_id=@sid
+##         inquire_equel(rowcount = "rowcount")
+           if (rowcount != 1)
+             return(SMS_STRING);
+       } else /* ptype == "NONE" */ {
+           goto skip;
+       }
+
+       if (!strcmp(q->shortname, "gpob")) {
+           sid = atoi(argv[4]);
+           free(argv[4]);
+           argv[4] = malloc(9);
+           name = argv[4];
+##         repeat retrieve (name = users.login) where users.users_id = @sid
+##         inquire_equel(rowcount = "rowcount")
+           if (rowcount != 1)
+             sprintf(name, "#%d", sid);
+       }
+
+       argv[2] = box;
+       (*action)(q->vcnt, argv, actarg);
+    skip:
+       /* free saved data */
+       free(argv[0]);
+       free(argv[1]);
+       free(argv);
+    }
+
+    sq_destroy(sq);
+    return (SMS_SUCCESS);
+##}
+
+
+/* followup_glin: fix the acl_name in argv[8].  argv[7] will contain the
+ * acl_type: "LIST", "USER", or "NONE".  Decode the id in argv[8] into the
+ * proper name based on the type, and repace that string in the argv.
+ * Also fixes the modby field by called followup_fix_modby.
+ */
+
+followup_glin(q, sq, v, action, actarg, cl)
+    register struct query *q;
+    register struct save_queue *sq;
+    register struct validate *v;
+    register int (*action)();
+    int actarg;
+    client *cl;
+##{
+    char **argv, *malloc(), *realloc(), *type;
+##  char *name;
+##  int id, rowcount;
+    int i, idx;
+
+    idx = 8;
+    if (!strcmp(q->shortname, "gsin"))
+      idx = 11;
+
+    while (sq_get_data(sq, &argv)) {
+       sms_trim_args(q->vcnt, argv);
+
+       id = atoi(argv[i = q->vcnt - 2]);
+       free(argv[i]);
+       name = argv[i] = malloc(9);
+##     repeat retrieve (name = users.login) where users.users_id = @id
+##     inquire_equel(rowcount = "rowcount")
+       if (rowcount != 1)
+         sprintf(argv[i], "#%d", id);
+
+       id = atoi(argv[idx]);
+       type = argv[idx - 1];
+       if ((name = malloc(33)) == NULL)
+           return(SMS_NO_MEM);
+
+       if (!strcmp(type, "LIST")) {
+##         repeat retrieve (name = list.#name) where list.list_id = @id
+##         inquire_equel(rowcount = "rowcount")
+           if (rowcount != 1)
+               strcpy(name, "???");
+       } else if (!strcmp(type, "USER")) {
+##         repeat retrieve (name = users.login) where users.users_id = @id
+##         inquire_equel(rowcount = "rowcount")
+           if (rowcount != 1)
+               strcpy(name, "???");
+       } else if (!strcmp(type, "NONE")) {
+           strcpy(name, "NONE");
+       } else
+         strcpy(name, "???");
+       free(argv[idx]);
+       argv[idx] = name;
+
+       if (!strcmp(q->shortname, "glin") && atoi(argv[6]) == -1) {
+           argv[6] = realloc(argv[6], strlen(UNIQUE_GID) + 1);
+           strcpy(argv[6], UNIQUE_GID);
+       }
+
+       /* send the data */
+       (*action)(q->vcnt, argv, actarg);
+
+       /* free saved data */
+       for (i = 0; i < q->vcnt; i++) 
+           free(argv[i]);
+       free(argv);
+    }
+
+    sq_destroy(sq);
+    return (SMS_SUCCESS);
+##}
+
+
+/** followup_amtl - followup for amtl and dmfl; when adding a list 
+ **                 member to a maillist, make member list a maillist also
+ **                 unless list is a user-group.
+ **                 Then set_list_modtime_by_id.
  **
  ** Inputs:
  **   argv[0] - list_id
- **
- ** Returns:
- **   {true | false}
+ **   argv[1] - member_type
+ **   argv[2] - member_id
  **
  **/
 
-get_list_is_group(q, argv, action, actarg)
+followup_amtl(q, argv, cl)
     struct query *q;
     char *argv[];
-    int (*action)();
-    int actarg;
+    client *cl;
 ##{
-##  int exists;
 ##  int list_id;
-    char *result;
+##  int member_id;
+##  int exists, who;
+##  char *entity;
 
     list_id = *(int *)argv[0];
+    entity = cl->entity;
+    who = cl->users_id;
+
+##  range of l is list
+##  repeat replace l (modtime = "now", modby = @who, modwith = @entity)
+##      where l.#list_id = @list_id
 
-##  range of g is groups
-##  repeat retrieve (exists = any(g.#list_id where g.#list_id = @list_id))
+    /* if query is not amtl or if member_type is not LIST then return */
+    if (bcmp(q->shortname, "amtl", 4) || bcmp(argv[1], "LIST", 4)) 
+       return(SMS_SUCCESS);
 
-    result = (exists) ? "true" : "false";
-    (*action)(1, &result, actarg);
+    member_id = *(int *)argv[2];
+
+    /* is parent list a mailing list? */
+##  repeat retrieve (exists = l.maillist) where l.#list_id=@list_id
+    if (!exists)
+       return(SMS_SUCCESS);
+
+    /* list is not a user-group; add list to maillist table */
+##  repeat replace l (maillist = 1) where l.#list_id = @member_id
     return(SMS_SUCCESS);
 ##}
 
-get_list_is_maillist(q, argv, action, actarg)
-    struct query *q;
-    char *argv[];
-    int (*action)();
+
+/* followup_anfq: Add allocation to nfsphys after creating quota.
+ *   argv[0] = filsys_id
+ *   argv[2] = ascii(quota)
+ */
+
+followup_anfq(q, argv, cl)
+    struct query  *q;
+    char **argv;
+    client *cl;
+##{
+##  int quota, user, fs, who;
+##  char *entity;
+
+    fs = *(int *)argv[0];
+    user = *(int *)argv[1];
+    quota = atoi(argv[2]);
+    who = cl->users_id;
+    entity = cl->entity;
+
+##  repeat replace nq (modtime = "now", modby = @who, modwith = @entity)
+##     where nq.filsys_id = @fs and nq.users_id = @user
+##  repeat replace nfsphys (allocated = nfsphys.allocated + @quota)
+##     where nfsphys.nfsphys_id = filesys.#phys_id and filesys.filsys_id = @fs
+    return(SMS_SUCCESS);
+##}
+
+
+/* followup_gzcl:
+ */
+
+followup_gzcl(q, sq, v, action, actarg, cl)
+    register struct query *q;
+    register struct save_queue *sq;
+    register struct validate *v;
+    register int (*action)();
     int actarg;
+    client *cl;
 ##{
-##  int exists;
-##  int list_id;
-    char *result;
+##  char *name;
+##  int rowcount, id;
+    char **argv;
+    int i;
 
-    list_id = *(int *)argv[0];
+    while (sq_get_data(sq, &argv)) {
+       sms_trim_args(q->vcnt, argv);
 
-##  range of ml is maillists
-##  repeat retrieve (exists = any(ml.#list_id where ml.#list_id = @list_id))
+       id = atoi(argv[i = q->vcnt - 2]);
+       free(argv[i]);
+       name = argv[i] = malloc(9);
+##     repeat retrieve (name = users.login) where users.users_id = @id
+##     inquire_equel(rowcount = "rowcount")
+       if (rowcount != 1)
+         sprintf(argv[i], "#%d", id);
+
+       for (i = 1; i < 8; i+=2) {
+           id = atoi(argv[i+1]);
+           free(argv[i+1]);
+           if ((name = argv[i+1] = malloc(33)) == NULL)
+             return(SMS_NO_MEM);
+           if (!strcmp(argv[i], "LIST")) {
+##             repeat retrieve (name = list.#name) where list.list_id = @id
+##             inquire_equel(rowcount = "rowcount")
+               if (rowcount != 1)
+                 strcpy(name, "???");
+           } else if (!strcmp(argv[i], "USER")) {
+##             repeat retrieve (name = users.login) where users.users_id = @id
+##             inquire_equel(rowcount = "rowcount")
+               if (rowcount != 1)
+                 strcpy(name, "???");
+           } else if (!strcmp(argv[i], "NONE")) {
+               strcpy(name, "NONE");
+           } else {
+               strcpy(name, "???");
+           }
+       }
 
-    result = (exists) ? "true" : "false";
-    (*action)(1, &result, actarg);
+       /* send the data */
+       (*action)(q->vcnt, argv, actarg);
+
+       /* free saved data */
+       for (i = 0; i < q->vcnt; i++) 
+           free(argv[i]);
+       free(argv);
+    }
+    sq_destroy(sq);
     return(SMS_SUCCESS);
 ##}
 
-\f
-/**
- ** add_locker - special query routine for creating a user locker
- **
- ** Inputs:
- **   argv[0] - users_id
- **   argv[1] - machine_id
- **   argv[2] - device
- **   argv[3] - initial quota
- ** 
- ** Description:
- **   - get prefix directory (dir) for mount point on specified machine/device
- **   - create filesys entry (label=<login>, type=NFS, machine=<machine>,
- **     mount=<dir>/<login>, access=w, acl=dbadmin)
- **   - increment allocated in nfsphys by quota
- **   - create nfsquota entry
- **
- ** Errors:
- **   - SMS_NFSPHYS - machine/device does not exist in nfsphys
- **   - SMS_FILESYS_EXISTS - file system already exists
- ** 
- **/
 
-add_locker(q, argv)
+/* followup_gsha:
+ */
+
+followup_gsha(q, sq, v, action, actarg, cl)
     register struct query *q;
-    char *argv[];
+    register struct save_queue *sq;
+    register struct validate *v;
+    register int (*action)();
+    int actarg;
+    client *cl;
 ##{
-##  int users_id;
-##  int mach_id;
-##  char *device;
-##  int quota;
-##  int rowcount;
-##  char login[9];
-##  char dir[32];
-##  int allocated;
-##  char locker[64];
-##  char mount[64];
-##  int user_acl;
+##  char *name;
+##  int rowcount, id;
+    char **argv;
+    int i;
 
-    /* copy arguments */
-    users_id = *(int *)argv[0];
-    mach_id = *(int *)argv[1];
-    device = argv[2];
-    sscanf(argv[3], "%d", &quota);
+    while (sq_get_data(sq, &argv)) {
+       sms_trim_args(q->vcnt, argv);
 
-##  range of u is users
-##  range of f is filesys
-##  range of np is nfsphys
-##  range of tbs is tblstats
+       id = atoi(argv[4]);
+       free(argv[4]);
+       name = argv[4] = malloc(9);
+##     repeat retrieve (name = users.login) where users.users_id = @id
+##     inquire_equel(rowcount = "rowcount")
+       if (rowcount != 1)
+         sprintf(argv[4], "#%d", id);
+
+       id = atoi(argv[2]);
+       free(argv[2]);
+       if ((name = argv[2] = malloc(33)) == NULL)
+         return(SMS_NO_MEM);
+       if (!strcmp(argv[1], "LIST")) {
+##         repeat retrieve (name = list.#name) where list.list_id = @id
+##         inquire_equel(rowcount = "rowcount")
+           if (rowcount != 1)
+             strcpy(name, "???");
+       } else if (!strcmp(argv[1], "USER")) {
+##         repeat retrieve (name = users.login) where users.users_id = @id
+##         inquire_equel(rowcount = "rowcount")
+           if (rowcount != 1)
+             strcpy(name, "???");
+       } else if (!strcmp(argv[1], "NONE")) {
+           strcpy(name, "NONE");
+       } else {
+           strcpy(name, "???");
+       }
 
-    /* get login name */
-##  repeat retrieve (login = u.#login) where u.#users_id = @users_id
+       /* send the data */
+       (*action)(q->vcnt, argv, actarg);
+
+       /* free saved data */
+       for (i = 0; i < q->vcnt; i++) 
+           free(argv[i]);
+       free(argv);
+    }
+    sq_destroy(sq);
+    return(SMS_SUCCESS);
+##}
 
-    /* get user's acl id */
-##  repeat retrieve (user_acl = list.list_id) where list.name = @login
 
-    /* get filesystem directory prefix; give error if machine/device
-       pair not in nfsphys table */
-    printf("np.mach_id = %d and np.device = %s\n", mach_id, device);
-    
-##  repeat retrieve (dir = np.#dir, allocated = np.#allocated) 
-##         where np.#mach_id = @mach_id and np.#device = @device
-##  inquire_equel (rowcount = "rowcount")
-    if (rowcount == 0) return(SMS_NFSPHYS);
-
-    /* make sure a filesys with user's name does not already exist */
-##  repeat retrieve (rowcount = any(f.label where f.label = @login))
-    if (rowcount != 0) return(SMS_FILESYS_EXISTS);
-
-    /* create a new filesys */
-    sprintf(locker, "%s/%s", dir, login);
-    sprintf(mount, "/mit/%s", login);
-##  repeat append filesys 
-##             (#label = @login, type = "NFS", #mach_id = @mach_id,
-##             name = @locker, access = "w", order = 1, #mount = @mount,
-##             acl_id = @user_acl)
-##  repeat replace tbs (appends = tbs.appends + 1, modtime = "now")
-##             where tbs.table = "filesys"
-
-    /* increment usage count in nfsphys table */
-    allocated += quota;
-##  replace np (#allocated = allocated) 
-##         where np.#mach_id = mach_id and np.#device = device
-##  repeat replace tbs (updates = tbs.updates + 1, modtime = "now")
-##             where tbs.table = "nfsphys"
-
-    /* create nfsquota entry */
-##  append nfsquota (#users_id = users_id, #mach_id = mach_id,
-##                  #device = device, #quota = quota)
-##  repeat replace tbs (appends = tbs.appends + 1, modtime = "now")
-##             where tbs.table = "nfsquota"
+\f
+/* Special query routines */
 
+/* set_pobox - this does all of the real work.
+ *      argv = user_id, type, box
+ * if type is POP, then box should be a machine, and its ID should be put in
+ * pop_id.  If type is SMTP, then box should be a string and its ID should
+ * be put in box_id.  If type is NONE, then box doesn't matter.
+ */
+
+int set_pobox(q, argv, cl)
+    struct query *q;
+    char **argv;
+    client *cl;
+##{
+##  int user, id, rowcount;
+##  char *box, potype[9];
+
+    box = argv[2];
+    user = *(int *)argv[0];
+
+##  repeat retrieve (id = users.pop_id, potype = users.#potype)
+##             where users.users_id = @user
+    if (!strcmp(potype, "POP"))
+      set_pop_usage(id, -1);
+
+    if (!strcmp(argv[1], "POP")) {
+##     repeat retrieve (id=machine.mach_id) where machine.name=uppercase(@box)
+##     inquire_equel(rowcount = "rowcount")
+       if (rowcount != 1)
+           return(SMS_MACHINE);
+##     repeat replace users (#potype = "POP", pop_id = @id)
+##             where users.users_id = @user
+       set_pop_usage(id, 1);
+    } else if (!strcmp(argv[1], "SMTP")) {
+##      range of s is strings
+##      repeat retrieve (id = s.string_id) where s.string = @box
+##      inquire_equel (rowcount = "rowcount")
+       if (rowcount == 0) {
+##          range of v is values
+##          repeat retrieve (id = v.value) where v.name = "strings_id"
+           id++;
+##          repeat replace v (value = @id) where v.name = "strings_id"
+##         append to strings (string_id = id, string = box)
+       }
+##     repeat replace users (#potype = "SMTP", box_id = @id) 
+##            where users.users_id = @user
+    } else /* argv[1] == "NONE" */ {
+##     repeat replace users (#potype = "NONE") where users.users_id = @user
+    }
+
+    set_pobox_modtime(q, argv, cl);
+##  repeat replace tblstats (updates = tblstats.updates + 1, modtime = "now")
+##     where tblstats.#table = "users"
     return(SMS_SUCCESS);
 ##}
 
-/**
- ** delete_locker - special query routine for deleting a user locker
- **
- ** Inputs:
- **   argv[0] - users_id
- ** 
- ** Description:
- **   - get login name from users_id
- **   - get filesys entry from login
- **   - use filesys.mach_id and filesys.name to determine machine/device
- **     pair for nfsphys and nfsquota
- **   - delete filesys entry (label=<login>)
- **   - decrement allocated in nfsphys by quota
- **   - delete nfsquota entry
- **
- ** Errors:
- **   - SMS_FILESYS - no filesys exists for user
- ** 
- **/
 
-delete_locker(q, argv)
+/* get_list_info:  passed a wildcard list name, returns lots of stuff about
+ * each list.  This is tricky:  first build a queue of all requested
+ * data.  Rest of processing consists of fixing gid, acl_name, and modby.
+ */
+
+get_list_info(q, aargv, cl, action, actarg)
     register struct query *q;
-    register char *argv[];
+    char **aargv;
+    client *cl;
+    register int (*action)();
+    int actarg;
 ##{
-##  int users_id;
-##  int mach_id;
-##  int quota;
-##  int rowcount;
-##  char login[9];
-##  char lname[64];
-##  char ndev[32];
-    register char *c;
+    char *argv[13], *malloc(), *realloc();
+##  char *name, acl_type[9], listname[33], active[5], public[5], hidden[5];
+##  char maillist[5], group[5], gid[6], acl_name[33], desc[256], modtime[27];
+##  char modby[9], modwith[9];
+##  int id, rowcount, acl_id, hid, modby_id;
+    int returned;
+    struct save_queue *sq, *sq_create();
 
-    /* copy arguments */
-    users_id = *(int *)argv[0];
+    returned = rowcount = 0;
+    name = aargv[0];
 
-##  range of u is users
-##  range of f is filesys
-##  range of np is nfsphys
-##  range of nq is nfsquota
-##  range of tbs is tblstats
+    sq = sq_create();
+##  range of l is list
+##  repeat retrieve (id = l.list_id) where l.#name = @name {
+       sq_save_data(sq, id);
+       rowcount++;
+##  }
+    if (rowcount == 0)
+      return(SMS_NO_MATCH);
+
+    argv[0] = listname; argv[1] = active; argv[2] = public; argv[3] = hidden;
+    argv[4] = maillist; argv[5] = group; argv[6] = gid; argv[7] = acl_type;
+    argv[8] = acl_name; argv[9] = desc; argv[10] = modtime; argv[11] = modby;
+    argv[12] = modwith;
+
+    while (sq_get_data(sq, &id)) {
+       if (id == 0)
+         continue;
+       argv[6] = gid;
+##     repeat retrieve (listname = l.#name, active = text(l.#active), 
+##             public = text(l.#public), hidden = text(l.#hidden),
+##             hid = l.#hidden, maillist = text(l.#maillist),
+##             group = text(l.#group), gid = text(l.#gid),
+##             acl_type = trim(l.#acl_type), acl_id = l.#acl_id,
+##             desc = l.#desc, modtime = l.#modtime, modby_id = l.#modby,
+##             modwith =l.#modwith)
+##         where l.list_id = @id
+
+       if (atoi(gid) == -1)
+           argv[6] = UNIQUE_GID;
+
+       if (!strcmp(acl_type, "LIST")) {
+##         repeat retrieve (acl_name = l.#name) where l.list_id = @acl_id
+##         inquire_equel(rowcount = "rowcount")
+           if (rowcount != 1)
+               strcpy(acl_name, "???");
+       } else if (!strcmp(acl_type, "USER")) {
+##         repeat retrieve (acl_name = users.#login)
+##             where users.users_id = @acl_id
+##         inquire_equel(rowcount = "rowcount")
+           if (rowcount != 1)
+               strcpy(acl_name, "???");
+       } else if (!strcmp(acl_type, "NONE")) {
+           strcpy(acl_name, "NONE");
+       } else
+         strcpy(acl_name, "???");
+
+##     repeat retrieve (modby = users.login) where users.users_id = @modby_id
+##     inquire_equel(rowcount = "rowcount")
+       if (rowcount != 1)
+         sprintf(modby, "#%d", id);
+
+       sms_trim_args(q->vcnt, argv);
+       returned++;
+       (*action)(q->vcnt, argv, actarg);
+    }
 
-    /* get login name */
-##  repeat retrieve (login = u.#login) where u.#users_id = @users_id
+    sq_destroy(sq);
+##  repeat replace tblstats (retrieves = tblstats.retrieves + 1)
+##     where tblstats.#table = "list"
 
-    /* get mach_id and locker name from filesys entry; then delete it */
-##  repeat retrieve (mach_id = f.#mach_id, lname = f.#name)
-##         where f.#label = @login
-##  inquire_equel (rowcount = "rowcount")
-    if (rowcount == 0) return(SMS_FILESYS);
-##  repeat delete f where f.#label = @login
-
-    /* get prefix directory */
-    c = (char *)rindex(lname, '/');
-    *c = 0;
-
-    /* get nfs device */
-##  repeat retrieve (ndev = np.device) 
-##         where np.#mach_id = @mach_id and np.dir = @lname
-
-    /* get quota from nfsquota entry; then delete entry */
-##  repeat retrieve (quota = nq.#quota)
-##         where nq.#mach_id = @mach_id and nq.#device = @ndev and
-##               nq.#users_id = @users_id
-##  repeat delete nq where nq.#mach_id = @mach_id and nq.#device = @ndev and
-##                  nq.#users_id = @users_id
-
-    /* decrement nfsphys.allocated */
-##  repeat replace np (allocated = np.allocated - @quota)
-##         where np.#mach_id = @mach_id and np.#device = @ndev
-
-    /* adjust table statistics */
-##  repeat replace tbs (deletes = tbs.deletes + 1, modtime = "now")
-##             where tbs.table = "filesys"
-##  repeat replace tbs (updates = tbs.updates + 1, modtime = "now")
-##             where tbs.table = "nfsphys"
-##  repeat replace tbs (deletes = tbs.deletes + 1, modtime = "now")
-##             where tbs.table = "nfsquota"
+    return (SMS_SUCCESS);
+##}
+
+
+/* get_acl_use - given a type and a name, return a type and a name.
+ * The acl_type is one of "LIST", "USER", "RLIST", or "RUSER" in argv[0],
+ * and argv[1] will contain the ID of the entity in question.  The R*
+ * types mean to recursively look at every containing list, not just
+ * when the object in question is a direct member.  On return, the
+ * usage type will be one of LIST, SERVICE, FILESYS, QUOTA, QUERY, or ZEPHYR.
+ */
+
+int get_acl_use(q, argv, cl, action, actarg)
+    struct query *q;
+    char *argv[];
+    client *cl;
+    int (*action)();
+    int actarg;
+##{
+    int found = 0;
+##  char *atype;
+##  int aid, listid, id;
+    struct save_queue *sq, *sq_create();
+
+    atype = argv[0];
+    aid = *(int *)argv[1];
+    if (!strcmp(atype, "LIST") || !strcmp(atype, "USER")) {
+       return(get_acl_internal(atype, aid, action, actarg));
+    }
+
+    sq = sq_create();
+    if (!strcmp(atype, "RLIST")) {
+       sq_save_data(sq, aid);
+       /* get all the list_id's of containing lists */
+##     range of m is members
+       while (sq_get_data(sq, &id)) {
+##         repeat retrieve (listid = m.list_id)
+##             where m.member_type = "LIST" and m.member_id = @id {
+             sq_save_unique_data(sq, listid);
+##         }
+         }
+       /* now process each one */
+       while (sq_get_data(sq, &id)) {
+           if (get_acl_internal("LIST", id, action, actarg) == SMS_SUCCESS)
+             found++;
+       }
+    }
+
+    if (!strcmp(atype, "RUSER")) {
+##     range of m is members
+##     repeat retrieve (listid = m.list_id)
+##             where m.member_type = "USER" and m.member_id = @aid {
+           sq_save_data(sq, listid);
+##     }
+       /* get all the list_id's of containing lists */
+       while (sq_get_data(sq, &id)) {
+##         repeat retrieve (listid = m.list_id)
+##             where m.member_type = "LIST" and m.member_id = @id {
+             sq_save_unique_data(sq, listid);
+##         }
+         }
+       /* now process each one */
+       while (sq_get_data(sq, &id)) {
+           if (get_acl_internal("LIST", id, action, actarg) == SMS_SUCCESS)
+             found++;
+       }
+       if (get_acl_internal("USER", aid, action, actarg) == SMS_SUCCESS)
+         found++;
+    }
 
+    sq_destroy(sq);    
+    if (!found) return(SMS_NO_MATCH);
     return(SMS_SUCCESS);
 ##}
-\f
-/**
- ** add_user_group - create a group for a user and add user to group
- **
- ** Inputs:
- **   argv[0] - login
- **
- ** Description:
- **   - verify specified user exists
- **   - create a list of same name as user
- **   - add user as a member of the list
- **
- **/
 
-add_user_group(q, argv)
+
+/* This looks up a single list or user for acl use.  atype must be "USER"
+ * or "LIST", and aid is the ID of the corresponding object.  This is used
+ * by get_acl_use above.
+ */
+
+##get_acl_internal(atype, aid, action, actarg)
+##  char *atype;
+##  int aid;
+    int (*action)();
+    int actarg;
+##{
+    char *rargv[2];
+    int found = 0;
+##  char name[33];
+
+    rargv[1] = name;
+    if (!strcmp(atype, "LIST")) {
+       rargv[0] = "FILESYS";
+##     repeat retrieve (name = filesys.label) 
+##             where filesys.owners = @aid {
+           (*action)(2, rargv, actarg);
+           found++;
+##     }
+
+       rargv[0] = "QUERY";
+##     repeat retrieve (name = capacls.capability)
+##             where capacls.list_id = @aid {
+           (*action)(2, rargv, actarg);
+           found++;
+##     }
+    } else if (!strcmp(atype, "USER")) {
+       rargv[0] = "FILESYS";
+##     repeat retrieve (name = filesys.label) 
+##             where filesys.owner = @aid {
+           (*action)(2, rargv, actarg);
+           found++;
+##     }
+    }
+
+    rargv[0] = "LIST";
+##  repeat retrieve (name = list.#name) 
+##             where list.acl_type = @atype and list.acl_id = @aid {
+        (*action)(2, rargv, actarg);
+        found++;
+##  }
+
+    rargv[0] = "SERVICE";
+##  repeat retrieve (name = servers.#name) 
+##             where servers.acl_type = @atype and servers.acl_id = @aid {
+        (*action)(2, rargv, actarg);
+        found++;
+##  }
+
+    rargv[0] = "HOSTACCESS";
+##  repeat retrieve (name = machine.#name)
+##             where machine.mach_id = hostaccess.mach_id and 
+##                  hostaccess.acl_type = @atype and hostaccess.acl_id = @aid {
+       (*action)(2, rargv, actarg);
+       found++;
+##  }
+    rargv[0] = "ZEPHYR";
+##  repeat retrieve (name = zephyr.class) 
+##             where zephyr.xmt_type = @atype and zephyr.xmt_id = @aid or
+##                   zephyr.sub_type = @atype and zephyr.sub_id = @aid or
+##                   zephyr.iws_type = @atype and zephyr.iws_id = @aid or
+##                   zephyr.iui_type = @atype and zephyr.iui_id = @aid {
+        (*action)(2, rargv, actarg);
+        found++;
+##  }
+
+    if (!found) return(SMS_NO_MATCH);
+    return(SMS_SUCCESS);
+##}
+
+
+/* get_lists_of_member - given a type and a name, return the name and flags
+ * of all of the lists of the given member.  The member_type is one of
+ * "LIST", "USER", "STRING", "RLIST", "RUSER", or "RSTRING" in argv[0],
+ * and argv[1] will contain the ID of the entity in question.  The R*
+ * types mean to recursively look at every containing list, not just
+ * when the object in question is a direct member.
+ */
+
+int get_lists_of_member(q, argv, cl, action, actarg)
     struct query *q;
     char *argv[];
+    client *cl;
+    int (*action)();
+    int actarg;
 ##{
-##  char *login;
-##  int exists;
-##  int users_id;
-##  int list_id;
-##  int gid;
-
-    login = argv[0];
+    int found = 0;
+##  char *atype;
+##  int aid, listid, id;
+    struct save_queue *sq, *sq_create();
+
+    atype = argv[0];
+    aid = *(int *)argv[1];
+    if (!strcmp(atype, "LIST") ||
+       !strcmp(atype, "USER") ||
+       !strcmp(atype, "STRING")) {
+      return(glom_internal(atype, aid, action, actarg));
+    }
 
-    /* verify user exists */
-##  repeat retrieve (users_id = users.#users_id) where users.#login = @login
-##  inquire_equel (exists = "rowcount")
-    if (exists != 1) return(SMS_USER);
+    sq = sq_create();
+    if (!strcmp(atype, "RLIST")) {
+       sq_save_data(sq, aid);
+       /* get all the list_id's of containing lists */
+##     range of m is members
+       while (sq_get_data(sq, &id)) {
+##         repeat retrieve (listid = m.list_id)
+##             where m.member_type = "LIST" and m.member_id = @id {
+             sq_save_unique_data(sq, listid);
+##         }
+         }
+       /* now process each one */
+       while (sq_get_data(sq, &id)) {
+           if (glom_internal("LIST", id, action, actarg) == SMS_SUCCESS)
+             found++;
+       }
+    }
 
-    /* verify list does not exist */
-##  repeat retrieve (exists = any(list.name where list.name = @login))
-    if (exists) return(SMS_LIST);
+    if (!strcmp(atype, "RUSER")) {
+##     range of m is members
+##     repeat retrieve (listid = m.list_id)
+##             where m.member_type = "USER" and m.member_id = @aid {
+           sq_save_data(sq, listid);
+##     }
+       /* get all the list_id's of containing lists */
+       while (sq_get_data(sq, &id)) {
+##         repeat retrieve (listid = m.list_id)
+##             where m.member_type = "LIST" and m.member_id = @id {
+             sq_save_unique_data(sq, listid);
+##         }
+         }
+       /* now process each one */
+       while (sq_get_data(sq, &id)) {
+           if (glom_internal("LIST", id, action, actarg) == SMS_SUCCESS)
+             found++;
+       }
+       if (glom_internal("USER", aid, action, actarg) == SMS_SUCCESS)
+         found++;
+    }
 
-    /* get new list_id */
-##  repeat retrieve (list_id = values.value) where values.name = "list_id"
-    list_id++;
-##  repeat replace values (value = @list_id) where values.name = "list_id"
-
-    /* create the list */
-##  range of tbs is tblstats
-##  repeat append list (name = @login, #list_id = @list_id, flags = 1,
-##                      desc = "User Group", acl_id = @list_id,
-##                     expdate = "today" + "5 years", modtime = "now")
-##  repeat replace tbs (modtime = "now", appends = tbs.appends + 1)
-##         where tbs.table = "list"
-
-    /* add user to list */
-##  repeat append members (#list_id = @list_id, member_type = "USER",
-##                        member_id = @users_id)
-##  repeat replace tbs (modtime = "now", appends = tbs.appends + 1)
-##         where tbs.table = "members"
-
-    /* get new gid */
-##  range of g is groups
-##  range of v is values
-##  repeat retrieve (gid = v.value) where v.name = "gid"
-    exists = 1;
-    while (exists) {
-       gid++;
-##      repeat retrieve (exists = any(g.#gid where g.#gid = @gid))
+    if (!strcmp(atype, "RSTRING")) {
+##     range of m is members
+##     repeat retrieve (listid = m.list_id)
+##             where m.member_type = "STRING" and m.member_id = @aid {
+           sq_save_data(sq, listid);
+##     }
+       /* get all the list_id's of containing lists */
+       while (sq_get_data(sq, &id)) {
+##         repeat retrieve (listid = m.list_id)
+##             where m.member_type = "LIST" and m.member_id = @id {
+             sq_save_unique_data(sq, listid);
+##         }
+         }
+       /* now process each one */
+       while (sq_get_data(sq, &id)) {
+           if (glom_internal("LIST", id, action, actarg) == SMS_SUCCESS)
+             found++;
+       }
+       if (glom_internal("STRING", aid, action, actarg) == SMS_SUCCESS)
+         found++;
     }
-##  repeat replace v (value = @gid) where v.name = "gid"
-    /* add list to group table */
-##  repeat append groups (#list_id = @list_id, ltid = list.tid, #gid = @gid)
-##      where list.#list_id = @list_id
 
-##  repeat replace tbs (modtime = "now", appends = tbs.appends + 1)
-##             where tbs.table = "groups"
+##  repeat replace tblstats (retrieves = tblstats.retrieves + 1)
+##     where tblstats.#table = "members"
+    sq_destroy(sq);    
+    if (!found) return(SMS_NO_MATCH);
+    return(SMS_SUCCESS);
+##}
+
 
-##  repeat replace tbs (modtime = "now", appends = tbs.appends + 1)
-##         where tbs.table = "members"
+/* This looks up a single list, user, or string as a member.  atype must be
+ * "USER", "LIST", or "STRING" and aid is the ID of the corresponding object.
+ * This is used by get_lists_of_members above.
+ */
+
+##glom_internal(atype, aid, action, actarg)
+##  char *atype;
+##  int aid;
+    int (*action)();
+    int actarg;
+##{
+    char *rargv[6];
+    int found = 0;
+##  char name[33], active[5], public[5], hidden[5], maillist[5], group[5];
+
+    rargv[0] = name;
+    rargv[1] = active;
+    rargv[2] = public;
+    rargv[3] = hidden;
+    rargv[4] = maillist;
+    rargv[5] = group;
+##  repeat retrieve (name = list.#name, active = text(list.#active), 
+##                  public = text(list.#public), hidden = text(list.#hidden),
+##                  maillist = text(list.#maillist), group = text(list.#group))
+##             where list.list_id = m.list_id and
+##                   m.member_type = @atype and m.member_id = @aid {
+        (*action)(6, rargv, actarg);
+        found++;
+##  }
 
-    /* and we're done */
+    if (!found) return(SMS_NO_MATCH);
     return(SMS_SUCCESS);
 ##}
 
-\f
-/**
- ** get_members_of_list - optimized query for retrieval of list members
+
+/* qualified_get_lists: passed "TRUE", "FALSE", or "DONTCARE" for each of
+ * the five flags associated with each list.  It will return the name of
+ * each list that meets the quailifications.  It does this by building a
+ * where clause based on the arguments, then doing a retrieve.
+ */
+
+static char *lflags[5] = { "active", "public", "hidden", "maillist", "group" };
+
+int qualified_get_lists(q, argv, cl, action, actarg)
+    struct query *q;
+    char *argv[];
+    client *cl;
+    int (*action)();
+    int actarg;
+{
+    return(qualified_get(q, argv, action, actarg, "l.list_id != 0",
+                        "l", "name", lflags));
+}
+
+
+/** get_members_of_list - optimized query for retrieval of list members
  **
  ** Inputs:
  **   argv[0] - list_id
  **
  ** Description:
  **   - retrieve USER members, then LIST members, then STRING members
- **
  **/
 
-get_members_of_list(q, argv, action, actarg)
+get_members_of_list(q, argv, cl, action, actarg)
     struct query *q;
     char *argv[];
+    client *cl;
     int (*action)();
     int actarg;
 ##{
@@ -1470,185 +1978,332 @@ get_members_of_list(q, argv, action, actarg)
         (*action)(2, targv, actarg);
 ##  }
 
+##  repeat replace tblstats (retrieves = tblstats.retrieves + 1)
+##     where tblstats.#table = "members"
     return(SMS_SUCCESS);
 ##}
 
-/**
- ** get_groups_of_user - optimized query for retrieval of all groups to
- **                      which a user belongs
- **
- **/
 
-get_groups_of_user(q, argv, action, actarg)
+/* count_members_of_list: this is a simple query, but it cannot be done
+ * through the dispatch table.
+ */
+
+int count_members_of_list(q, argv, cl, action, actarg)
     struct query *q;
     char *argv[];
+    client *cl;
     int (*action)();
     int actarg;
 ##{
-##  int users_id;
-##  char list_name[33];
-##  char gid[11];
-##  int rowcount;
-    char *targv[2];
-
-    users_id = *(int *)argv[0];
-    targv[0] = list_name;
-    targv[1] = gid;
+##  int  list, ct = 0;
+    char *rargv[1], countbuf[5];
+
+    list = *(int *)argv[0];
+    rargv[0] = countbuf;
+##  repeat retrieve (ct = count(members.list_id where members.list_id = @list))
+    sprintf(countbuf, "%d", ct);
+    (*action)(1, rargv, actarg);
+##  repeat replace tblstats (retrieves = tblstats.retrieves + 1)
+##     where tblstats.#table = "members"
+    return(SMS_SUCCESS);
+##}
 
-##  range of m is members
 
-##  repeat retrieve (list_name = list.name, gid = text(groups.#gid))
-##         where m.member_id = @users_id and m.member_type = "USER" and
-##               m.list_id = groups.list_id and groups.ltid = list.tid
-##         sort by #list_name
-##  {
-        (*action)(2, targv, actarg);
-##  }
-##  inquire_equel (rowcount = "rowcount")
+/* qualified_get_server: passed "TRUE", "FALSE", or "DONTCARE" for each of
+ * the three flags associated with each service.  It will return the name of
+ * each service that meets the quailifications.  It does this by building a
+ * where clause based on the arguments, then doing a retrieve.
+ */
 
-    return ((rowcount = 0) ? SMS_NO_MATCH : SMS_SUCCESS);
-##}
+static char *sflags[3] = { "enable", "inprogress", "harderror" };
 
-get_groups_of_all_users(q, argv, action, actarg)
+int qualified_get_server(q, argv, cl, action, actarg)
     struct query *q;
     char *argv[];
+    client *cl;
     int (*action)();
     int actarg;
-##{
-##  char login[9];
-##  char group[33];
-##  char gid[11];
-    char *targv[3];
-##  int errorno;
-
-    targv[0] = login;
-    targv[1] = group;
-    targv[2] = gid;
-
-##  range of u is users
-##  range of l is list
-##  range of m is members
-##  range of g is groups
-
-##  set lockmode session where readlock = nolock
-
-##  repeat retrieve (login = u.#login, group = l.name, gid = text(g.#gid))
-##         where m.member_type = "USER" and m.member_id = u.users_id and
-##               u.status != 0 and m.list_id = g.list_id and
-##               g.ltid = l.tid
-##         sort by #login, #group
-##  {
-        (*action)(3, targv, actarg);
-##  }
+{
+    return(qualified_get(q, argv, action, actarg, "s.name != \"\"",
+                        "s", "name", sflags));
+}
 
-##  inquire_equel (errorno = "errorno")
-##  set lockmode session where readlock = system
 
-    return((errorno) ? SMS_INGRES_ERR : SMS_SUCCESS);
-##}
-\f
-/**
- ** get_all_poboxes - optimized query for retrieval of all poboxes
- **
- ** Description:
- **   - retrieve LOCAL boxes, then POP boxes, then FOREIGN boxes
- **
- **/
+/* generic qualified get routine, used by qualified_get_lists,
+ * qualified_get_server, and qualified_get_serverhost.
+ *   Args:
+ *     start - a simple where clause, must not be empty
+ *     range - the name of the range variable
+ *     field - the field to return
+ *     flags - an array of strings, names of the flag variables
+ */
 
-get_all_poboxes(q, argv, action, actarg)
+int qualified_get(q, argv, action, actarg, start, range, field, flags)
     struct query *q;
     char *argv[];
     int (*action)();
     int actarg;
+    char *start;
+    char *range;
+    char *field;
+    char *flags[];
 ##{
-##  char login[9];
-##  char machine[129];
-##  char box[129];
-    char *targv[4];
-
-    targv[0] = login;
-    targv[2] = machine;
-    targv[3] = box;
-
-    targv[1] = "LOCAL";
-
-##  set lockmode session where readlock = nolock
-##  range of p is pobox
-##  repeat retrieve (login=users.#login, machine = #machine.name, box=p.#box)
-##             where p.type = "LOCAL" and p.users_id = users.users_id
-##                   and p.mach_id = #machine.mach_id
-##  {
-        (*action)(4, targv, actarg);
+##  char name[33], qual[256], *rvar, *rtbl, *rfield;
+    char *rargv[1], buf[32];
+##  int rowcount, i;
+
+    strcpy(qual, start);
+    for (i = 0; i < q->argc; i++) {
+       if (!strcmp(argv[i], "TRUE")) {
+           sprintf(buf, " and %s.%s != 0", range, flags[i]);
+           (void) strcat(qual, buf);
+       } else if (!strcmp(argv[i], "FALSE")) {
+           sprintf(buf, " and %s.%s = 0", range, flags[i]);
+           (void) strcat(qual, buf);
+       }
+    }
+      
+    rargv[0] = name;
+    rvar = range;
+    rtbl = q->rtable;
+    rfield = field;
+##  range of rvar is rtbl
+##  retrieve (name = rvar.rfield) where qual {
+       (*action)(1, rargv, actarg);
 ##  }
+##  inquire_equel(rowcount = "rowcount")
+##  repeat replace tblstats (retrieves = tblstats.retrieves + 1)
+##     where tblstats.#table = @rtbl
+    if (rowcount == 0)
+      return(SMS_NO_MATCH);
+    return(SMS_SUCCESS);
+##}
 
-    targv[1] = "POP";
-##  repeat retrieve (login=users.#login, machine = #machine.name, box=p.#box)
-##             where p.type = "POP" and p.users_id = users.users_id
-##                   and p.mach_id = #machine.mach_id
-##  {
-        (*action)(4, targv, actarg);
-##  }
 
-    targv[1] = "FOREIGN";
-##  repeat retrieve (login=users.#login, machine=strings.string, box=p.#box)
-##             where p.type = "FOREIGN" and p.users_id = users.users_id
-##                   and p.mach_id = strings.string_id
-##  {
-        (*action)(4, targv, actarg);
-##  }
-##  set lockmode session where readlock = system
+/* qualified_get_serverhost: passed "TRUE", "FALSE", or "DONTCARE" for each of
+ * the five flags associated with each serverhost.  It will return the name of
+ * each service and host that meets the quailifications.  It does this by 
+ * building a where clause based on the arguments, then doing a retrieve.
+ */
 
-    return(SMS_SUCCESS);
-##}
+static char *shflags[6] = { "service", "enable", "override", "success",
+                           "inprogress", "hosterror" };
 
-get_new_poboxes(q, argv, action, actarg)
+int qualified_get_serverhost(q, argv, cl, action, actarg)
     struct query *q;
     char *argv[];
+    client *cl;
     int (*action)();
     int actarg;
 ##{
-##  char *created;
-##  char login[9];
-##  char machine[129];
-##  char box[129];
-    char *targv[4];
-
-    created = argv[0];
-
-    targv[0] = login;
-    targv[2] = machine;
-    targv[3] = box;
-
-    targv[1] = "LOCAL";
-##  range of p is pobox
-##  repeat retrieve (login=users.#login, machine = #machine.name, box=p.#box)
-##             where p.type = "LOCAL" and p.users_id = users.users_id
-##                   and p.mach_id = #machine.mach_id and
-##                   p.#created > @created
-##  {
-        (*action)(4, targv, actarg);
+##  char sname[33], mname[33], qual[256];
+    char *rargv[2], buf[32];
+##  int rowcount, i;
+
+    sprintf(qual, "machine.mach_id = sh.mach_id and sh.service = \"%s\"",
+           argv[0]);
+    for (i = 1; i < q->argc; i++) {
+       if (!strcmp(argv[i], "TRUE")) {
+           sprintf(buf, " and sh.%s != 0", shflags[i]);
+           strcat(qual, buf);
+       } else if (!strcmp(argv[i], "FALSE")) {
+           sprintf(buf, " and sh.%s = 0", shflags[i]);
+           strcat(qual, buf);
+       }
+    }
+      
+    rargv[0] = sname;
+    rargv[1] = mname;
+##  range of sh is serverhosts
+##  retrieve (sname = sh.service, mname = machine.name) where qual {
+       (*action)(2, rargv, actarg);
 ##  }
+##  inquire_equel(rowcount = "rowcount")
+##  repeat replace tblstats (retrieves = tblstats.retrieves + 1)
+##     where tblstats.#table = "serverhosts"
+    if (rowcount == 0)
+      return(SMS_NO_MATCH);
+    return(SMS_SUCCESS);
+##}
 
-    targv[1] = "POP";
-##  repeat retrieve (login=users.#login, machine = #machine.name, box=p.#box)
-##             where p.type = "POP" and p.users_id = users.users_id
-##                   and p.mach_id = #machine.mach_id and
-##                   p.#created > @created
-##  {
-        (*action)(4, targv, actarg);
-##  }
 
-    targv[1] = "FOREIGN";
-##  repeat retrieve (login=users.#login, machine=strings.string, box=p.#box)
-##             where p.type = "FOREIGN" and p.users_id = users.users_id
-##                   and p.mach_id = strings.string_id and
-##                   p.#created > @created
-##  {
-        (*action)(4, targv, actarg);
+/* register_user - change user's login name and allocate a pobox, group,
+ * filesystem, and quota for them.  The user's status must start out as 0,
+ * and is left as 2.  Arguments are: user's UID, new login name, and user's
+ * type for filesystem allocation (SMS_FS_STUDENT, SMS_FS_FACULTY, 
+ * SMS_FS_STAFF, SMS_FS_MISC).
+ */
+
+register_user(q, argv, cl)
+    struct query *q;
+    char **argv;
+    client *cl;
+##{
+##  char *login, dir[65], *entity, *directory, machname[33];
+##  int who, rowcount, mid, uid, users_id, flag, utype, nid, list_id, quota;
+##  int size, alloc, pid, m_id;
+    int maxsize;
+
+    entity = cl->entity;
+    who = cl->users_id;
+
+    uid = atoi(argv[0]);
+    login = argv[1];
+    utype = atoi(argv[2]);
+
+##  range of u is users
+##  range of l is list
+##  range of sh is serverhosts
+##  range of n is nfsphys
+##  range of m is machine
+
+    /* find user */
+##  repeat retrieve (users_id = u.#users_id)
+##     where u.#uid = @uid and u.status = 0
+##  inquire_equel(rowcount = "rowcount");
+    if (rowcount == 0)
+      return(SMS_NO_MATCH);
+    if (rowcount > 1)
+      return(SMS_NOT_UNIQUE);
+
+    /* check new login name */
+##  repeat retrieve (flag = any(u.#login where u.#login = @login))
+    if (flag)
+      return(SMS_IN_USE);
+##  repeat retrieve (flag = any(l.name where l.name = @login))
+    if (flag)
+      return(SMS_IN_USE);
+##  repeat retrieve (flag = any(filesys.#name where filesys.#name = @login))
+    if (flag)
+      return(SMS_IN_USE);
+    com_err(whoami, 0, "new login name OK");
+
+    /* choose place for pobox, put in mid */
+##  repeat retrieve (mid = sh.mach_id, machname = m.name)
+##    where sh.service = "pop" and m.mach_id = sh.mach_id and
+##     sh.value2 - sh.value1 = max(sh.value2-sh.value1 where sh.service="pop")
+##  inquire_equel(rowcount = "rowcount");
+    if (rowcount == 0)
+      return(SMS_INTERNAL);
+
+    /* change login name, set pobox */
+##  repeat replace u (#login = @login, status = 2, modtime = "now",
+##                   modby = @who, modwith = @entity, potype="POP",
+##                   pop_id = @mid, pmodtime="now", pmodby=@who,
+##                   pmodwith=@entity)
+##     where u.#users_id = @users_id
+##  inquire_equel(rowcount = "rowcount");
+    if (rowcount != 1)
+      return(SMS_INTERNAL);
+    set_pop_usage(mid, 1);
+    com_err(whoami, 0, "set login name to %s and pobox to %s", login,
+           trim(machname));
+
+    /* create group list */
+    if (set_next_object_id("gid", "list"))
+      return(SMS_INTERNAL);
+    if (set_next_object_id("list_id", "list"))
+      return(SMS_INTERNAL);
+##  repeat retrieve (list_id = values.value) where values.name = "list_id"
+##  inquire_equel(rowcount = "rowcount");
+    if (rowcount != 1)
+      return(SMS_INTERNAL);
+##  repeat append list (name = @login, #list_id = @list_id, active = 1,
+##                     public = 0, hidden = 0, maillist = 0, group = 1,
+##                     #gid = values.value, desc = "User Group",
+##                     acl_type = "USER", acl_id = @users_id, modtime = "now",
+##                     modby = @who, modwith = @entity)
+##     where values.name = "gid"
+##  inquire_equel(rowcount = "rowcount");
+    if (rowcount != 1)
+      return(SMS_INTERNAL);
+    com_err(whoami, 0, "group list created");
+
+    /* decide where to put filesystem */
+    maxsize = 0;
+    directory = NULL;
+##  repeat retrieve (mid = n.mach_id, dir = trim(n.#dir), nid = n.nfsphys_id,
+##                  flag = n.status, size = n.#size, alloc = n.allocated) {
+       if ((flag & utype) && (size != 0) && (size - alloc > maxsize)) {
+           maxsize = size - alloc;
+           if (directory)
+             free(directory);
+           directory = strsave(dir);
+           pid = nid;
+           m_id = mid;
+       }
 ##  }
+    if (maxsize == 0)
+      return(SMS_INTERNAL);
+
+    /* create filesystem */
+    if (set_next_object_id("filsys_id", "filesys"))
+      return(SMS_INTERNAL);
+##  repeat append filesys (filsys_id = values.value, phys_id = @pid,
+##                        label = @login, type = "NFS", mach_id = @m_id,
+##                        name = @directory + @login, mount = "/mit/" + @login,
+##                        access = "w", comments = "User Locker",
+##                        owner = @users_id, owners = @list_id, createflg = 1,
+##                        lockertype = "HOMEDIR", modtime = "now",
+##                        modby = @who, modwith = @entity)
+##     where values.name = "filsys_id"
+##  inquire_equel(rowcount = "rowcount");
+    if (rowcount != 1)
+      return(SMS_INTERNAL);
+    com_err(whoami, 0, "filesys created on mach %d in %s/%s", m_id,
+           trim(directory), login);
+
+    /* set quota */
+##  repeat retrieve (quota = values.value) where values.name = "def_quota"
+##  inquire_equel(rowcount = "rowcount");
+    if (rowcount != 1)
+      return(SMS_INTERNAL);
+##  repeat append nfsquota (#users_id = @users_id, filsys_id = values.value,
+##                         #quota = @quota, modtime = "now", modby = @who,
+##                         modwith = @entity)
+##     where values.name = "filsys_id"
+##  inquire_equel(rowcount = "rowcount");
+    if (rowcount != 1)
+      return(SMS_INTERNAL);
+##  repeat replace nfsphys (allocated = nfsphys.allocated + @quota)
+##     where nfsphys.nfsphys_id = filesys.#phys_id and
+##           filesys.filsys_id = values.value and values.name = "filsys_id"
+##  inquire_equel(rowcount = "rowcount");
+    if (rowcount != 1)
+      return(SMS_INTERNAL);
+    com_err(whoami, 0, "quota of %d assigned", quota);
+
+    return(SMS_SUCCESS);
+##}
+
+
+
+/** set_pop_usage - incr/decr usage count for pop server in serverhosts talbe
+ **
+ ** Inputs:
+ **   id of machine
+ **   delta (will be +/- 1)
+ **
+ ** Description:
+ **   - incr/decr value field in serverhosts table for pop/mach_id
+ **
+ **/
+
+static int set_pop_usage(id, count)
+int id;
+int count;
+##{
+##  int mach_id = id;
+##  int n = count;
+
+##  range of sh is serverhosts
+##  repeat replace sh (value1 = sh.value1 + @n)
+##         where sh.service = "pop" and sh.#mach_id = @mach_id
 
     return(SMS_SUCCESS);
 ##}
+
+
 \f
 /* Validation Routines */
 
@@ -1727,8 +2382,17 @@ validate_fields(q, argv, vo, n)
            status = validate_typedata(q, argv, vo);
            break;
 
-       case V_FOLLOWUP:
-           status = SMS_EXISTS;
+       case V_RENAME:
+           if (log_flags & LOG_RES)
+               com_err(whoami, 0, "validating rename %s in %s",
+                       argv[vo->index], vo->table);
+           status = validate_rename(argv, vo);
+           break;
+
+       case V_CHAR:
+           if (log_flags & LOG_RES)
+             com_err(whoami, 0, "validating chars: %s", argv[vo->index]);
+           status = validate_chars(argv[vo->index]);
            break;
 
        case V_SORT:
@@ -1744,6 +2408,40 @@ validate_fields(q, argv, vo, n)
     return(SMS_SUCCESS);
 }
 
+
+/* validate_chars: verify that there are no illegal characters in
+ * the string.  Legal characters are printing chars other than 
+ * ", *, ?, [ and ].
+ */
+static int illegalchars[] = {
+    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* ^@ - ^O */
+    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* ^P - ^_ */
+    0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, /* SPACE - / */
+    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, /* 0 - ? */
+    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* @ - O */
+    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, /* P - _ */
+    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* ` - o */
+    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, /* p - ^? */
+    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+};
+
+validate_chars(s)
+register char *s;
+{
+    while (*s)
+      if (illegalchars[*s++])
+       return(SMS_BAD_CHAR);
+    return(SMS_EXISTS);
+}
+
+
 validate_id(argv, vo)
     char *argv[];
     register struct valobj *vo;
@@ -1759,11 +2457,11 @@ validate_id(argv, vo)
     name = argv[vo->index];
     table = vo->table;
     /* minor kludge to upcasify machine names */
-    if (!bcmp(table, "machine", 7))
+    if (!strcmp(table, "machine"))
        for (c = name; *c; c++) if (islower(*c)) *c = toupper(*c);
     namefield = vo->namefield;
     idfield = vo->idfield;
-    if (!bcmp(namefield, "uid", 4)) {
+    if (!strcmp(namefield, "uid")) {
 ##    retrieve (id = table.idfield) where table.namefield = int4(name)
 ##    inquire_equel (rowcount = "rowcount")
     } else {
@@ -1792,29 +2490,6 @@ validate_name(argv, vo)
     return ((rowcount == 1) ? SMS_EXISTS : vo->error);
 ##}
 
-/* Special validation routine for get_filesys */
-validate_label(q, argv)
-    struct query *q;
-    char *argv[];
-{
-    register char *label;
-    register char *c;
-
-    label = argv[0];
-    c = (char *)index(label, '*');
-    if (c == label) return(SMS_NOT_UNIQUE);
-    return(SMS_SUCCESS);
-}
-
-/* Special validation routine for delete_filesys */
-validate_label_2(q, argv)
-    struct query *q;
-    char *argv[];
-{
-    if (index(argv[0], '*') != 0) return(SMS_NOT_UNIQUE);
-    return(SMS_SUCCESS);
-}
-
 validate_date(argv, vo)
     char *argv[];
     struct valobj *vo;
@@ -1831,26 +2506,66 @@ validate_date(argv, vo)
     return(SMS_SUCCESS);
 ##}
 
+
+validate_rename(argv, vo)
+char *argv[];
+struct valobj *vo;
+##{
+##  char *name, *table, *namefield, *idfield;
+##  int id;
+    register char *c;
+
+    c = name = argv[vo->index];
+    while (*c)
+      if (illegalchars[*c++])
+       return(SMS_BAD_CHAR);
+    table = vo->table;
+    /* minor kludge to upcasify machine names */
+    if (!strcmp(table, "machine"))
+       for (c = name; *c; c++) if (islower(*c)) *c = toupper(*c);
+    namefield = vo->namefield;
+    idfield = vo->idfield;
+    id = -1;
+    if (idfield == 0) {
+       if (!strcmp(argv[vo->index], argv[vo->index - 1]))
+         return(SMS_EXISTS);
+##     retrieve (id = any(table.namefield where table.namefield = name))
+       if (id)
+         return(vo->error);
+       else
+         return(SMS_EXISTS);
+    }
+##  retrieve (id = table.idfield) where table.namefield = name
+    if (id == -1 || id == *(int *)argv[vo->index - 1])
+      return(SMS_EXISTS);
+    else
+      return(vo->error);
+##}
+
+
 validate_type(argv, vo)
     char *argv[];
     register struct valobj *vo;
 ##{
 ##  char *typename;
 ##  char *value;
-##  int rowcount;
+##  int exists;
     register char *c;
 
     typename = vo->table;
-    value = argv[vo->index];
+    c = value = argv[vo->index];
+    while (*c)
+      if (illegalchars[*c++])
+       return(SMS_BAD_CHAR);
 
     /* uppercase type fields */
     for (c = value; *c; c++) if (islower(*c)) *c = toupper(*c);
 
 ##  range of a is alias
-##  repeat retrieve (rowcount = count(a.trans where a.name = @typename and
+##  repeat retrieve (exists = any(a.trans where a.name = @typename and
 ##                                   a.type = "TYPE" and
 ##                                   a.trans = @value))
-    return ((rowcount == 1) ? SMS_EXISTS : vo->error);
+    return (exists ? SMS_EXISTS : vo->error);
 ##}
 
 /* validate member or type-specific data field */
@@ -1862,10 +2577,10 @@ validate_typedata(q, argv, vo)
 ##{
 ##  char *name;
 ##  char *field_type;
-##  char data_type[17];
+##  char data_type[129];
 ##  int id;
-##  int refc;
 ##  int rowcount;
+    char *index();
     register char *c;
 
     /* get named object */
@@ -1881,7 +2596,8 @@ validate_typedata(q, argv, vo)
     if (rowcount != 1) return(SMS_TYPE);
 
     /* now retrieve the record id corresponding to the named object */
-
+    if (index(data_type, ' '))
+       *index(data_type, ' ') = 0;
     if (!strcmp(data_type, "user")) {
        /* USER */
 ##     repeat retrieve (id = users.users_id) where users.login = @name
@@ -1892,8 +2608,19 @@ validate_typedata(q, argv, vo)
        /* LIST */
 ##     repeat retrieve (id = list.list_id) where list.#name = @name
 ##     inquire_equel (rowcount = "rowcount")
-       if (rowcount != 1) return(SMS_LIST);
-
+       if (rowcount != 1) {
+           /* if idfield is non-zero, then if argv[0] matches the string
+            * that we're trying to resolve, we should get the value of
+            * values.[idfield] for the id.
+            */
+           if (vo->idfield && !strcmp(argv[0], argv[vo->index])) {
+               name = vo->idfield;
+##             repeat retrieve (id = values.value+1) where values.#name = @name
+##             inquire_equel(rowcount = "rowcount")
+               if (rowcount != 1) return(SMS_LIST);
+           } else
+             return(SMS_LIST);
+       }
     } else if (!strcmp(data_type, "machine")) {
        /* MACHINE */
        for (c = name; *c; c++) if (islower(*c)) *c = toupper(*c);
@@ -1904,8 +2631,7 @@ validate_typedata(q, argv, vo)
     } else if (!strcmp(data_type, "string")) {
        /* STRING */
 ##      range of s is strings
-##      repeat retrieve (id = s.string_id, refc = s.#refc) 
-##             where s.string = @name
+##      repeat retrieve (id = s.string_id) where s.string = @name
 ##      inquire_equel (rowcount = "rowcount")
        if (rowcount == 0) {
            if (q->type != APPEND) return(SMS_STRING);
@@ -1913,17 +2639,10 @@ validate_typedata(q, argv, vo)
 ##          retrieve (id = v.value) where v.#name = "strings_id"
            id++;
 ##          replace v (value = id) where v.#name = "strings_id"
-##         append to strings (string_id = id, string = name, #refc = 1)
-       } else if (rowcount == 1) {
-           if (q->type == APPEND || q->type == DELETE) {
-               refc += (q->type == APPEND) ? 1 : -1;
-               if (refc > 0) {
-##                 replace s (#refc = refc) where s.string_id = id
-               } else {
-##                 delete s where s.string_id = id
-               }
-           }
+##         append to strings (string_id = id, string = name)
        }
+    } else if (!strcmp(data_type, "none")) {
+       id = 0;
     } else {
        return(SMS_TYPE);
     }
@@ -1934,101 +2653,36 @@ validate_typedata(q, argv, vo)
     return (SMS_EXISTS);
 ##}
 
-\f
-translate_ids(q, sq, v, action, actarg)
-    register struct query *q;
-    register struct save_queue *sq;
-    register struct validate *v;
-    register int (*action)();
-    int actarg;
-##{
-##  char *name;
-##  char *field_type;
-##  char data_type[17];
-##  int id;
-##  int rowcount;
-    register int i;
-    struct valobj *vo;
-    char **argv;
-
-    for (i = 0; i < v->objcnt; i++) {
-       vo = &v->valobj[i];
-       if (vo->type == V_FOLLOWUP) break;
-    }
-
-    /* for each row */
-    while (sq_get_data(sq, &argv)) {
-
-       /* get object id */
-       i = vo->index;
-       sscanf(argv[i], "%d", &id);
-       free(argv[i]);
-       name = (char *)malloc(129);
-       argv[i] = name;
-
-       /* get field type string (known to be at index-1) */
-       field_type = argv[vo->index-1];
-
-       /* get corresponding data type associated with field type name */
-##      repeat retrieve (data_type = alias.trans) 
-##             where alias.#name = @field_type and alias.type = "TYPEDATA"
-##      inquire_equel (rowcount = "rowcount")
-       if (rowcount != 1) {
-           sprintf(name, "%d", id);
-           (*action)(q->vcnt, argv, actarg);
-           continue;
-       }
-
-       /* retrieve object name */
-
-       if (!strcmp(data_type, "user")) {
-           /* USER */
-##          repeat retrieve (name = users.login) where users.users_id = @id
-##         inquire_equel (rowcount = "rowcount")
-
-       } else if (!strcmp(data_type, "list")) {
-           /* LIST */
-##          repeat retrieve (name = list.#name) where list.list_id = @id
-##         inquire_equel (rowcount = "rowcount")
 
-       } else if (!strcmp(data_type, "machine")) {
-           /* MACHINE */
-##          repeat retrieve (name = machine.#name) where machine.mach_id = @id
-##          inquire_equel (rowcount = "rowcount")
+/* This looks up a login name and returns the SMS internal ID.  It is used
+ * by authenticate to put the users_id in the client structure.
+ */
 
-       } else if (!strcmp(data_type, "string")) {
-           /* STRING */
-##          repeat retrieve (name = strings.string) 
-##                 where strings.string_id = @id
-##          inquire_equel (rowcount = "rowcount")
+int get_users_id(name)
+char *name;
+##{
+##  int id, rowcount;
+##  char *login;
 
-       } else {
-           rowcount = 0;
-       }
+    login = name;
 
-       /* if there wasn't a corresponding object name, then use the id */
-       if (rowcount != 1) sprintf(name, "%d", id);
+##  range of u is users
+##  repeat retrieve (id = u.#users_id) where u.#login = @login
+##  inquire_equel (rowcount = "rowcount")
+    
+    if (rowcount == 1)
+       return(id);
+    else
+       return(0);
+##}
 
-       /* send the data */
-       (*action)(q->vcnt, argv, actarg);
 
-       /* free saved data */
-       for (i = 0; i < q->vcnt; i++) 
-           free(argv[i]);
-       free(argv);
-    }
+/* Check the database at startup time.  For now this just resets the
+ * inprogress flags that the DCM uses.
+ */
 
-    sq_destroy(sq);
-    return (SMS_SUCCESS);
+sanity_check_database()
+##{
+##  replace servers (inprogress = 0)
+##  replace serverhosts (inprogress = 0)
 ##}
-\f
-/*
- * Local Variables:
- * mode: c
- * c-indent-level: 4
- * c-continued-statement-offset: 4
- * c-brace-offset: -4
- * c-argdecl-indent: 4
- * c-label-offset: -4
- * End:
- */
This page took 0.272004 seconds and 5 git commands to generate.