]> andersk Git - moira.git/blobdiff - server/qsupport.qc
Used /bin/sh format instead of /bin/csh format, by accident.
[moira.git] / server / qsupport.qc
index e654960e7f7e14f0d3b5fe733d64c0f1e721c390..5e3638346f3508628b5d3798a85acfc5228157f6 100644 (file)
@@ -15,12 +15,12 @@ static char *rcsid_qsupport_qc = "$Header$";
 
 #include <mit-copyright.h>
 #include "query.h"
-#include "sms_server.h"
+#include "mr_server.h"
 #include <ctype.h>
 
 
 extern char *whoami, *strsave();
-extern int ingres_errno, sms_errcode;
+extern int ingres_errno, mr_errcode;
 
 
 /* Specialized Access Routines */
@@ -37,9 +37,9 @@ access_user(q, argv, cl)
     client *cl;
 {
     if (cl->users_id != *(int *)argv[0])
-       return(SMS_PERM);
+       return(MR_PERM);
     else
-       return(SMS_SUCCESS);
+       return(MR_SUCCESS);
 }
 
     
@@ -58,12 +58,13 @@ access_login(q, argv, cl)
 ##  char qual[256];
 
     build_qual(q->qual, q->argc, argv, qual);
+##  range of u is users
 ##  retrieve (id = u.users_id) where qual
 ##  inquire_equel(rowcount = "rowcount")
     if (rowcount != 1 || id != cl->users_id)
-       return(SMS_PERM);
+       return(MR_PERM);
     else
-       return(SMS_SUCCESS);
+       return(MR_SUCCESS);
 ##}
 
     
@@ -97,28 +98,29 @@ access_list(q, argv, cl)
 ##        where list.#list_id = @list_id
 ##  inquire_equel(rowcount = "rowcount")
     if (rowcount != 1)
-      return(SMS_INTERNAL);
+      return(MR_INTERNAL);
 
     /* parse client structure */
-    if ((status = get_client(cl, &client_type, &client_id)) != SMS_SUCCESS)
+    if ((status = get_client(cl, &client_type, &client_id)) != MR_SUCCESS)
        return(status);
 
     /* if amtl or dmfl and list is public allow client to add or delete self */
-    if ((!strcmp("amtl", q->shortname) || !strcmp("dmfl", q->shortname)) &&
-       (flags && !strcmp("USER", argv[1]))) {
-       if (*(int *)argv[2] == client_id) return(SMS_SUCCESS);
+    if (((!strcmp("amtl", q->shortname) && flags) ||
+        (!strcmp("dmfl", q->shortname))) &&
+       (!strcmp("USER", argv[1]))) {
+       if (*(int *)argv[2] == client_id) return(MR_SUCCESS);
     /* if update_list, don't allow them to change the GID */
     } else if (!strcmp("ulis", q->shortname)) {
        if ((!strcmp(argv[7], UNIQUE_GID) && (gid != -1)) ||
            (strcmp(argv[7], UNIQUE_GID) && (gid != atoi(argv[7]))))
-         return(SMS_PERM);
+         return(MR_PERM);
     }
 
     /* check for client in access control list */
     status = find_member(acl_type, acl_id, client_type, client_id, 0);
-    if (!status) return(SMS_PERM);
+    if (!status) return(MR_PERM);
 
-    return(SMS_SUCCESS);
+    return(MR_SUCCESS);
 ##}
 
 
@@ -144,20 +146,21 @@ access_visible_list(q, argv, cl)
 ##     acl_type = list.#acl_type) where list.#list_id = @list_id
 ##  inquire_equel(rowcount = "rowcount")
     if (rowcount != 1)
-      return(SMS_INTERNAL);
+      return(MR_INTERNAL);
     if (!flags)
-       return(SMS_SUCCESS);
+       return(MR_SUCCESS);
+
 
     /* parse client structure */
-    if ((status = get_client(cl, &client_type, &client_id)) != SMS_SUCCESS)
+    if ((status = get_client(cl, &client_type, &client_id)) != MR_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(MR_PERM);
 
-    return(SMS_SUCCESS);
+    return(MR_SUCCESS);
 ##}
 
 
@@ -183,22 +186,22 @@ access_vis_list_by_name(q, argv, cl)
 ##     acl_type = list.#acl_type) where list.#name = @listname
 ##  inquire_equel(rowcount = "rowcount");
     if (rowcount > 1)
-      return(SMS_WILDCARD);
+      return(MR_WILDCARD);
     if (rowcount == 0)
-      return(SMS_NO_MATCH);
+      return(MR_NO_MATCH);
     if (!flags)
-       return(SMS_SUCCESS);
+       return(MR_SUCCESS);
 
     /* parse client structure */
-    if ((status = get_client(cl, &client_type, &client_id)) != SMS_SUCCESS)
+    if ((status = get_client(cl, &client_type, &client_id)) != MR_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(MR_PERM);
 
-    return(SMS_SUCCESS);
+    return(MR_SUCCESS);
 ##}
 
 
@@ -217,10 +220,10 @@ access_member(q, argv, cl)
 
     if (!strcmp(argv[0], "USER") || !strcmp(argv[0], "RUSER")) {
        if (cl->users_id == *(int *)argv[1])
-         return(SMS_SUCCESS);
+         return(MR_SUCCESS);
     }
 
-    return(SMS_PERM);
+    return(MR_PERM);
 }
 
 
@@ -234,8 +237,8 @@ access_qgli(q, argv, cl)
     client *cl;
 {
     if (!strcmp(argv[0], "TRUE") && !strcmp(argv[2], "FALSE"))
-      return(SMS_SUCCESS);
-    return(SMS_PERM);
+      return(MR_SUCCESS);
+    return(MR_PERM);
 }
 
 
@@ -258,17 +261,17 @@ access_service(q, argv, cl)
 ##     where servers.#name = uppercase(@name)
 ##  inquire_equel(rowcount = "rowcount")
     if (rowcount > 1)
-      return(SMS_PERM);
+      return(MR_PERM);
 
     /* parse client structure */
-    if ((status = get_client(cl, &client_type, &client_id)) != SMS_SUCCESS)
+    if ((status = get_client(cl, &client_type, &client_id)) != MR_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);
+    if (!status) return(MR_PERM);
 
-    return(SMS_SUCCESS);
+    return(MR_SUCCESS);
 ##}
 
 
@@ -293,15 +296,16 @@ access_filesys(q, argv, cl)
 ##  inquire_equel(rowcount = "rowcount")
 
     if (rowcount != 1)
-      return(SMS_PERM);
+      return(MR_PERM);
     if (users_id == cl->users_id)
-      return(SMS_SUCCESS);
-    if ((status = get_client(cl, &client_type, &client_id)) != SMS_SUCCESS)
-       return(status);
+      return(MR_SUCCESS);
+    if ((status = get_client(cl, &client_type, &client_id)) != MR_SUCCESS)
+      return(status);
     status = find_member("LIST", list_id, client_type, client_id, 0);
     if (status)
-      return(SMS_SUCCESS);
-    return(SMS_PERM);
+      return(MR_SUCCESS);
+    else
+      return(MR_PERM);
 ##}
 
     
@@ -325,14 +329,25 @@ setup_ausr(q, argv, cl)
     client *cl;
 ##{
 ##  int nuid, rowcount;
+##  char *mit_id;
+
+#ifdef notdef
+    /* this is currently disabled because we need an index on ID's
+     * before it can run in finite time.
+     */
+    mit_id = argv[U_MITID];
+##  retrieve (rowcount = any(u.#mit_id where u.#mit_id = mit_id))
+    if (ingres_errno) return(mr_errcode);
+    if (rowcount) return(MR_EXISTS);
+#endif notdef
 
     if (!strcmp(argv[1], UNIQUE_UID) || atoi(argv[1]) == -1) {
        if (set_next_object_id("uid", "users"))
-         return(SMS_INGRES_ERR);
+         return(MR_INGRES_ERR);
 ##      repeat retrieve (nuid = values.value) where values.name = "uid"
 ##     inquire_equel(rowcount = "rowcount")
        if (rowcount != 1)
-         return(SMS_INTERNAL);
+         return(MR_INTERNAL);
        sprintf(argv[1], "%d", nuid);
     }
 
@@ -340,7 +355,7 @@ setup_ausr(q, argv, cl)
        sprintf(argv[0], "#%s", argv[1]);
     }
 
-    return(SMS_SUCCESS);
+    return(MR_SUCCESS);
 ##}
 
 
@@ -358,31 +373,33 @@ int setup_dusr(q, argv)
 
     /* For now, only allow users to be deleted if their status is 0 */
 ##  repeat retrieve (flag = u.status) where u.users_id = @id
-    if (flag != 0)
-      return(SMS_IN_USE);
+    if (flag != 0 && flag != 4)
+      return(MR_IN_USE);
 
-##  repeat delete nfsquota where nfsquota.users_id = @id
-##  repeat retrieve (flag = any(members.member_id where members.member_id=@id
-##                      and members.member_type = "USER"))
+##  repeat delete quota where quota.entity_id = @id and quota.type = "USER"
+##  repeat delete krbmap where krbmap.users_id = @id
+##  repeat retrieve (flag = any(imembers.member_id where imembers.member_id=@id
+##                      and imembers.member_type = "USER"))
     if (flag)
-       return(SMS_IN_USE);
+       return(MR_IN_USE);
 ##  repeat retrieve (flag = any(filesys.label where filesys.owner=@id))
     if (flag)
-       return(SMS_IN_USE);
+       return(MR_IN_USE);
 ##  repeat retrieve (flag = any(list.name where list.acl_id=@id and
 ##                     list.acl_type = "USER"))
     if (flag)
-       return(SMS_IN_USE);
+       return(MR_IN_USE);
 ##  repeat retrieve (flag = any(servers.name where servers.acl_id=@id and
 ##                     servers.acl_type = "USER"))
     if (flag)
-       return(SMS_IN_USE);
+       return(MR_IN_USE);
 ##  repeat retrieve (flag=any(hostaccess.acl_id where hostaccess.acl_id=@id and
 ##                     hostaccess.acl_type = "USER"))
     if (flag)
-       return(SMS_IN_USE);
-    else
-       return(SMS_SUCCESS);
+       return(MR_IN_USE);
+    if (ingres_errno)
+       return(mr_errcode);
+    return(MR_SUCCESS);
 ##}
 
 
@@ -402,10 +419,10 @@ char **argv;
 ##                                  and u.pop_id != 0 and u.users_id = @id))
 ##     where u.users_id = @id
     if (!flag)
-      return(SMS_MACHINE);
+      return(MR_MACHINE);
     if (strcmp(strtrim(type), "POP"))
       set_pop_usage(mid, 1);
-    return(SMS_SUCCESS);
+    return(MR_SUCCESS);
 ##}
 
 
@@ -421,10 +438,11 @@ char **argv;
     user = *(int *)argv[0];
 ##  repeat retrieve (type = u.potype, id = u.pop_id)
 ##             where u.users_id = @user
+    if (ingres_errno) return(mr_errcode);
 
     if (!strcmp(strtrim(type), "POP"))
       set_pop_usage(id, -1);
-    return(SMS_SUCCESS);
+    return(MR_SUCCESS);
 ##}
 
 
@@ -442,23 +460,30 @@ int setup_dmac(q, argv)
 ##  repeat retrieve (flag = any(users.login where users.potype = "POP" 
 ##                                               and users.pop_id=@id))
     if (flag)
-       return(SMS_IN_USE);
+       return(MR_IN_USE);
 ##  repeat retrieve (flag = any(serverhosts.mach_id
 ##                              where serverhosts.mach_id=@id))
     if (flag)
-       return(SMS_IN_USE);
+       return(MR_IN_USE);
 ##  repeat retrieve (flag = any(nfsphys.mach_id where nfsphys.mach_id=@id))
     if (flag)
-       return(SMS_IN_USE);
+       return(MR_IN_USE);
 ##  repeat retrieve (flag = any(hostaccess.mach_id where hostaccess.mach_id=@id))
     if (flag)
-       return(SMS_IN_USE);
+       return(MR_IN_USE);
 ##  repeat retrieve (flag = any(printcap.mach_id where printcap.mach_id=@id))
     if (flag)
-       return(SMS_IN_USE);
+       return(MR_IN_USE);
+##  repeat retrieve (flag = any(printcap.quotaserver where printcap.quotaserver=@id))
+    if (flag)
+       return(MR_IN_USE);
+##  repeat retrieve (flag = any(palladium.mach_id where palladium.mach_id=@id))
+    if (flag)
+       return(MR_IN_USE);
 
 ##  repeat delete mcmap where mcmap.mach_id = @id
-    return(SMS_SUCCESS);
+    if (ingres_errno) return(mr_errcode);
+    return(MR_SUCCESS);
 ##}
 
 
@@ -475,12 +500,13 @@ int setup_dclu(q, argv)
     id = *(int *)argv[0];
 ##  repeat retrieve (flag = any(mcmap.mach_id where mcmap.clu_id=@id))
     if (flag)
-       return(SMS_IN_USE);
+       return(MR_IN_USE);
 ##  repeat retrieve (flag = any(svc.clu_id where svc.clu_id=@id))
     if (flag)
-       return(SMS_IN_USE);
-    else
-       return(SMS_SUCCESS);
+       return(MR_IN_USE);
+    if (ingres_errno)
+       return(mr_errcode);
+    return(MR_SUCCESS);
 ##}
 
 
@@ -507,15 +533,16 @@ char **argv;
     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);
+             return(MR_INGRES_ERR);
 ##         repeat retrieve (ngid = values.value) where values.name = "gid"
+           if (ingres_errno) return(mr_errcode);
            sprintf(argv[idx], "%d", ngid);
        } else {
            strcpy(argv[idx], "-1");
        }
     }
 
-    return(SMS_SUCCESS);
+    return(MR_SUCCESS);
 ##}
 
 
@@ -530,40 +557,45 @@ int setup_dlis(q, argv)
 ##  int flag, id;
 
     id = *(int *)argv[0];
-##  repeat retrieve (flag = any(members.member_id where members.member_id=@id
-##                      and members.member_type = "LIST"))
+##  repeat retrieve (flag = any(imembers.member_id where imembers.member_id=@id
+##                      and imembers.member_type = "LIST"))
     if (flag)
-       return(SMS_IN_USE);
-##  repeat retrieve (flag = any(members.member_id where members.list_id=@id))
+       return(MR_IN_USE);
+##  repeat retrieve (flag = any(imembers.member_id where imembers.list_id=@id))
     if (flag)
-       return(SMS_IN_USE);
+       return(MR_IN_USE);
 ##  repeat retrieve (flag = any(filesys.label where filesys.owners=@id))
     if (flag)
-       return(SMS_IN_USE);
+       return(MR_IN_USE);
 ##  repeat retrieve (flag = any(capacls.tag where capacls.list_id=@id))
     if (flag)
-       return(SMS_IN_USE);
+       return(MR_IN_USE);
 ##  repeat retrieve (flag = any(list.name where list.acl_id=@id and
 ##                     list.acl_type = "LIST" and list.list_id != @id))
     if (flag)
-       return(SMS_IN_USE);
+       return(MR_IN_USE);
 ##  repeat retrieve (flag = any(servers.name where servers.acl_id=@id and
 ##                     servers.acl_type = "LIST"))
     if (flag)
-       return(SMS_IN_USE);
+       return(MR_IN_USE);
+##  repeat retrieve (flag = any(quota.entity_id where quota.entity_id=@id and
+##                     quota.type = "GROUP"))
+    if (flag)
+       return(MR_IN_USE);
 ##  repeat retrieve (flag=any(hostaccess.acl_id where hostaccess.acl_id=@id and
 ##                     hostaccess.acl_type = "LIST"))
     if (flag)
-       return(SMS_IN_USE);
+       return(MR_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);
+        return(MR_IN_USE);
+    if (ingres_errno)
+       return(mr_errcode);
+    return(MR_SUCCESS);
 ##}
 
 
@@ -582,12 +614,13 @@ int setup_dsin(q, argv)
 ##  repeat retrieve (flag = any(serverhosts.service 
 ##                             where serverhosts.service=uppercase(@name)))
     if (flag)
-       return(SMS_IN_USE);
+       return(MR_IN_USE);
 ##  repeat retrieve (flag = servers.inprogress) where servers.#name = @name
     if (flag)
-       return(SMS_IN_USE);
-    else
-       return(SMS_SUCCESS);
+       return(MR_IN_USE);
+    if (ingres_errno)
+       return(mr_errcode);
+    return(MR_SUCCESS);
 ##}
 
 
@@ -607,9 +640,10 @@ int setup_dshi(q, argv)
 ##  repeat retrieve (flag=serverhosts.inprogress) 
 ##     where serverhosts.service=uppercase(@name) and serverhosts.mach_id=@id
     if (flag)
-       return(SMS_IN_USE);
-    else
-       return(SMS_SUCCESS);
+       return(MR_IN_USE);
+    if (ingres_errno)
+       return(mr_errcode);
+    return(MR_SUCCESS);
 ##}
 
 
@@ -634,8 +668,8 @@ int setup_dshi(q, argv)
  **    filesystem (nfsphys_id for NFS, 0 for RVD)
  **
  ** Errors:
- **   SMS_NFS - specified directory not exported
- **   SMS_FILESYS_ACCESS - invalid filesys access
+ **   MR_NFS - specified directory not exported
+ **   MR_FILESYS_ACCESS - invalid filesys access
  **
  **/
 
@@ -644,11 +678,11 @@ int setup_dshi(q, argv)
 setup_afil(q, argv)
     struct query *q;
     char *argv[];
-{
-    char *type;
+##{
+    char *type, *name;
     int mach_id;
-    char *name;
-    char *access;  
+##  int ok;
+##  char ftype[32], *access;
 
     type = argv[1];
     mach_id = *(int *)argv[2];
@@ -656,11 +690,17 @@ setup_afil(q, argv)
     access = argv[5];
     var_phys_id = 0;
 
+    sprintf(ftype, "fs_access_%s", type);
+##  retrieve (ok = any(alias.trans where alias.name = ftype and
+##                          alias.type = "TYPE" and alias.trans = access))
+    if (ingres_errno) return(mr_errcode);
+    if (ok == 0) return(MR_FILESYS_ACCESS);
+
     if (!strcmp(type, "NFS"))
        return (check_nfs(mach_id, name, access));
     else
-       return(SMS_SUCCESS);
-}
+       return(MR_SUCCESS);
+##}
 
 
 /* Verify the arguments, depending on the FStype.  Also, if this is an
@@ -668,27 +708,52 @@ setup_afil(q, argv)
  * the new phys_id.
  */
 
-setup_ufil(q, argv)
+setup_ufil(q, argv, cl)
     struct query *q;
     char *argv[];
+    client *cl;
 ##{
     int mach_id, status;
-    char *type, *name, *access;  
-##  int fid;
+    char *type, *name;  
+##  int fid, total, who;
+##  char *entity, ftype[32], *access;
 
     type = argv[2];
     mach_id = *(int *)argv[3];
     name = argv[4];
     access = argv[6];
     var_phys_id = 0;
+    fid = *(int *)argv[0];
+    who = cl->client_id;
+    entity = cl->entity;
+
+    sprintf(ftype, "fs_access_%s", type);
+##  retrieve (total = any(alias.trans where alias.name = ftype and
+##                          alias.type = "TYPE" and alias.trans = access))
+    if (ingres_errno) return(mr_errcode);
+    if (total == 0) return(MR_FILESYS_ACCESS);
 
     if (!strcmp(type, "NFS")) {
        status = check_nfs(mach_id, name, access);
-       fid = *(int *)argv[0];
-##     replace nfsquota (phys_id = var_phys_id) where nfsquota.filsys_id = fid
+##     replace quota (phys_id = var_phys_id) where quota.filsys_id = fid
+       if (ingres_errno) return(mr_errcode);
        return(status);
-    } else
-      return(SMS_SUCCESS);
+    } else if (!strcmp(type, "AFS")) {
+       total = 0;
+##     retrieve (total = sum(quota.quota where quota.filsys_id = fid
+##                           and quota.phys_id != 0))
+       if (ingres_errno) return(mr_errcode);
+       if (total != 0) {
+##         append quota (quota = total, filsys_id = fid,
+##                          phys_id = 0, entity_id = 0, type = "ANY",
+##                          modtime = "now", modby = who, modwith = entity)
+           if (ingres_errno) return(mr_errcode);
+       }
+    } else {
+##     replace quota (phys_id = 0) where quota.filsys_id = fid
+       if (ingres_errno) return(mr_errcode);
+    }
+    return(MR_SUCCESS);
 ##}
 
 
@@ -709,10 +774,7 @@ setup_ufil(q, argv)
     register char *cp1;
     register char *cp2;
 
-    caccess = (isupper(*access)) ? tolower(*access) : *access;
-    if (caccess != 'r' && caccess != 'w') return(SMS_FILESYS_ACCESS);
-
-    status = SMS_NFS;
+    status = MR_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 {
@@ -723,11 +785,12 @@ setup_ufil(q, argv)
             cp2++;
         }
         if (*cp2 == 0) {
-            status = SMS_SUCCESS;
+            status = MR_SUCCESS;
 ##           endretrieve
         }
 ##  }
-
+    if (ingres_errno)
+       return(mr_errcode);
     return(status);
 ##}
 
@@ -744,16 +807,16 @@ setup_dfil(q, argv, cl)
 ##  int id;
 
     id = *(int *)argv[0];
-##  range of q is nfsquota
-##  range of fs is filesys
+##  range of q is quota
 ##  range of n is nfsphys
 ##  repeat replace n (allocated=n.allocated-sum(q.quota where q.filsys_id=@id))
-##     where n.nfsphys_id = fs.phys_id and fs.filsys_id = @id
+##     where n.nfsphys_id = filesys.phys_id and filesys.filsys_id = @id
 
 ##  repeat delete q where q.filsys_id = @id
 ##  repeat delete fsgroup where fsgroup.filsys_id = @id
 ##  repeat delete fsgroup where fsgroup.group_id = @id
-    return(SMS_SUCCESS);
+    if (ingres_errno) return(mr_errcode);
+    return(MR_SUCCESS);
 ##}
 
 
@@ -771,32 +834,43 @@ setup_dnfp(q, argv, cl)
     id = *(int *)argv[0];
 ##  repeat retrieve (exists = any(filesys.label where filesys.phys_id = @id))
     if (exists)
-      return(SMS_IN_USE);
-    return(SMS_SUCCESS);
+      return(MR_IN_USE);
+    if (ingres_errno)
+      return(mr_errcode);
+    return(MR_SUCCESS);
 ##}
 
 
-/* setup_dnfq: Remove allocation from nfsphys before deleting quota.
+/* setup_dqot: Remove allocation from nfsphys before deleting quota.
  *   argv[0] = filsys_id
- *   argv[1] = users_id
+ *   argv[1] = type if "update_quota" or "delete_quota"
+ *   argv[2 or 1] = users_id or list_id
  */
 
-setup_dnfq(q, argv, cl)
+setup_dqot(q, argv, cl)
     struct query  *q;
     char **argv;
     client *cl;
 ##{
-##  int quota, fs, user;
+##  int quota, fs, id;
+##  char *qtype;
 
     fs = *(int *)argv[0];
-    user = *(int *)argv[1];
+    if (!strcmp(q->name, "update_quota") || !strcmp(q->name, "delete_quota")) {
+       qtype = argv[1];
+       id = *(int *)argv[2];
+    } else {
+       qtype = "USER";
+       id = *(int *)argv[1];
+    }
 
-##  range of q is nfsquota
-##  repeat retrieve (quota = q.#quota) where q.users_id = @user and
-##     q.filsys_id = @fs
+##  range of q is #quota
+##  repeat retrieve (quota = q.#quota) where q.type = @qtype and
+##     q.entity_id = @id 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);
+    if (ingres_errno) return(mr_errcode);
+    return(MR_SUCCESS);
 ##}
 
 
@@ -813,6 +887,34 @@ setup_sshi(q, argv, cl)
 ##}
 
 
+/* setup add_kerberos_user_mapping: add the string to the string 
+ * table if necessary.
+ */
+
+setup_akum(q, argv, cl)
+struct query *q;
+char **argv;
+client *cl;
+##{
+##  int id, rowcount;
+##  char *name;
+
+    name = argv[1];
+    if (name_to_id(name, "STRING", &id) != MR_SUCCESS) {
+       if (q->type != APPEND) return(MR_STRING);
+##     range of v is values
+##     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)
+       cache_entry(name, "STRING", id);
+    }
+    if (ingres_errno) return(mr_errcode);
+    *(int *)argv[1] = id;
+    return(MR_SUCCESS);
+##}
+
+
 \f
 /* FOLLOWUP ROUTINES */
 
@@ -830,13 +932,13 @@ set_modtime(q, argv, cl)
 ##  int who;
 
     entity = cl->entity;
-    who = cl->users_id;
+    who = cl->client_id;
     table = q->rtable;
     name = argv[0];
 
 ##  replace table (modtime = "now", modby = who, modwith = entity)
 ##      where table.#name = name
-    return(SMS_SUCCESS);
+    return(MR_SUCCESS);
 ##}
 
 /* generic set_modtime_by_id routine.  This takes the table name from
@@ -854,14 +956,14 @@ set_modtime_by_id(q, argv, cl)
 ##  int who, id;
 
     entity = cl->entity;
-    who = cl->users_id;
+    who = cl->client_id;
     table = q->rtable;
     id_name = q->validate->object_id;
 
     id = *(int *)argv[0];
 ##  replace table (modtime = "now", modby = who, modwith = entity)
 ##      where table.id_name = id
-    return(SMS_SUCCESS);
+    return(MR_SUCCESS);
 ##}
 
 
@@ -877,12 +979,12 @@ set_finger_modtime(q, argv, cl)
 ##  char *entity;
 
     entity = cl->entity;
-    who = cl->users_id;
+    who = cl->client_id;
     users_id = *(int *)argv[0];
 
 ##  repeat replace u (fmodtime = "now", fmodby = @who, fmodwith = @entity)
 ##      where u.#users_id = @users_id
-    return(SMS_SUCCESS);
+    return(MR_SUCCESS);
 ##}
 
 
@@ -898,12 +1000,12 @@ set_pobox_modtime(q, argv, cl)
 ##  char *entity;
 
     entity = cl->entity;
-    who = cl->users_id;
+    who = cl->client_id;
     users_id = *(int *)argv[0];
 
 ##  repeat replace users (pmodtime = "now", pmodby = @who, pmodwith = @entity)
 ##      where users.#users_id = @users_id
-    return(SMS_SUCCESS);
+    return(MR_SUCCESS);
 ##}
 
 
@@ -919,13 +1021,13 @@ set_uppercase_modtime(q, argv, cl)
 ##  int who;
 
     entity = cl->entity;
-    who = cl->users_id;
+    who = cl->client_id;
     table = q->rtable;
     name = argv[0];
 
 ##  replace table (modtime = "now", modby = who, modwith = entity)
 ##      where table.#name = uppercase(name)
-    return(SMS_SUCCESS);
+    return(MR_SUCCESS);
 ##}
 
 
@@ -943,13 +1045,12 @@ set_mach_modtime_by_id(q, argv, cl)
 ##  int who, id;
 
     entity = cl->entity;
-    who = cl->users_id;
+    who = cl->client_id;
 
     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);
+##  repeat replace machine (modtime = "now", modby = @who, modwith = @entity)
+##      where machine.mach_id = @id
+    return(MR_SUCCESS);
 ##}
 
 
@@ -967,13 +1068,12 @@ set_cluster_modtime_by_id(q, argv, cl)
 ##  int who, id;
 
     entity = cl->entity;
-    who = cl->users_id;
+    who = cl->client_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);
+##  repeat replace cluster (modtime = "now", modby = @who, modwith = @entity)
+##      where cluster.clu_id = @id
+    return(MR_SUCCESS);
 ##}
 
 
@@ -990,13 +1090,13 @@ set_serverhost_modtime(q, argv, cl)
 ##  int who, id;
 
     entity = cl->entity;
-    who = cl->users_id;
+    who = cl->client_id;
 
     serv = argv[0];
     id = *(int *)argv[1];
 ##  repeat replace sh (modtime = "now", modby = @who, modwith = @entity)
 ##      where sh.service = uppercase(@serv) and sh.mach_id = @id
-    return(SMS_SUCCESS);
+    return(MR_SUCCESS);
 ##}
 
 
@@ -1013,13 +1113,13 @@ set_nfsphys_modtime(q, argv, cl)
 ##  int who, id;
 
     entity = cl->entity;
-    who = cl->users_id;
+    who = cl->client_id;
 
     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);
+    return(MR_SUCCESS);
 ##}
 
 
@@ -1036,7 +1136,7 @@ set_filesys_modtime(q, argv, cl)
 ##  int who;
 
     entity = cl->entity;
-    who = cl->users_id;
+    who = cl->client_id;
 
     label = argv[0];
     if (!strcmp(q->shortname, "ufil"))
@@ -1044,7 +1144,7 @@ set_filesys_modtime(q, argv, cl)
 
 ##  repeat replace fs (modtime = "now", modby = @who, modwith = @entity,
 ##                    #phys_id = @var_phys_id)  where fs.#label = @label
-    return(SMS_SUCCESS);
+    return(MR_SUCCESS);
 ##}
 
 
@@ -1061,13 +1161,13 @@ set_zephyr_modtime(q, argv, cl)
 ##  int who;
 
     entity = cl->entity;
-    who = cl->users_id;
+    who = cl->client_id;
 
     class = argv[0];
 
 ##  repeat replace z (modtime = "now", modby = @who, modwith = @entity)
 ##                    where z.#class = @class
-    return(SMS_SUCCESS);
+    return(MR_SUCCESS);
 ##}
 
 
@@ -1083,31 +1183,28 @@ followup_fix_modby(q, sq, v, action, actarg, cl)
     register int (*action)();
     register int actarg;
     client *cl;
-##{
+{
     register int i, j;
     char **argv, *malloc();
-##  int id, rowcount;
-##  char *name;
+    int id, status;
 
     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);
-       }
+       if (id > 0)
+         status = id_to_name(id, "USER", &argv[i]);
+       else
+         status = id_to_name(-id, "STRING", &argv[i]);
+       if (status && status != MR_NO_MATCH)
+         return(status);
        (*action)(q->vcnt, argv, actarg);
        for (j = 0; j < q->vcnt; j++)
          free(argv[j]);
        free(argv);
     }
     sq_destroy(sq);
-    return(SMS_SUCCESS);
-##}
+    return(MR_SUCCESS);
+}
 
 
 /**
@@ -1131,7 +1228,7 @@ followup_ausr(q, argv, cl)
 ##  char fullname[129];
 
     login = argv[0];
-    who = cl->users_id;
+    who = cl->client_id;
     entity = cl->entity;
 
     /* build fullname */
@@ -1149,7 +1246,7 @@ followup_ausr(q, argv, cl)
 ##          potype="NONE", pmodtime="now", pmodby=@who, pmodwith=@entity)
 ##     where u.#login = @login
 
-    return(SMS_SUCCESS);
+    return(MR_SUCCESS);
 ##}
 
 
@@ -1169,59 +1266,54 @@ followup_gpob(q, sq, v, action, actarg, cl)
     register int (*action)();
     int actarg;
     client *cl;
-##{
+{
     char **argv, *index();
     char *ptype, *p;
-##  char box[129], *name;
-##  int mid, sid, rowcount;
+    int mid, sid, status;
 
     /* for each row */
     while (sq_get_data(sq, &argv)) {
-       sms_trim_args(2, argv);
+       mr_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);
+           status = id_to_name(mid, "MACHINE", &argv[2]);
+           if (status == MR_NO_MATCH)
+             return(MR_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);
+           status = id_to_name(sid, "STRING", &argv[2]);
+           if (status == MR_NO_MATCH)
+             return(MR_STRING);
        } else /* ptype == "NONE" */ {
            goto skip;
        }
+       if (status) return(status);
 
        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);
+           if (sid > 0)
+             status = id_to_name(sid, "USER", &argv[4]);
+           else
+             status = id_to_name(-sid, "STRING", &argv[4]);
        }
+       if (status && status != MR_NO_MATCH) return(status);
 
-       argv[2] = box;
        (*action)(q->vcnt, argv, actarg);
     skip:
        /* free saved data */
        free(argv[0]);
        free(argv[1]);
+       free(argv[4]);
        free(argv);
     }
 
     sq_destroy(sq);
-    return (SMS_SUCCESS);
-##}
+    return (MR_SUCCESS);
+}
 
 
 /* followup_glin: fix the ace_name in argv[8].  argv[7] will contain the
@@ -1237,53 +1329,45 @@ followup_glin(q, sq, v, action, actarg, cl)
     register int (*action)();
     int actarg;
     client *cl;
-##{
+{
     char **argv, *malloc(), *realloc(), *type;
-##  char *name;
-##  int id, rowcount;
-    int i, idx;
+    int id, i, idx, status;
 
     idx = 8;
     if (!strcmp(q->shortname, "gsin"))
       idx = 12;
 
     while (sq_get_data(sq, &argv)) {
-       sms_trim_args(q->vcnt, argv);
+       mr_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);
+       if (id > 0)
+         status = id_to_name(id, "USER", &argv[i]);
+       else
+         status = id_to_name(-id, "STRING", &argv[i]);
+       if (status && status != MR_NO_MATCH)
+         return(status);
 
        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, "???");
+           status = id_to_name(id, "LIST", &argv[idx]);
        } else if (!strcmp(type, "USER")) {
-##         repeat retrieve (name = users.login) where users.users_id = @id
-##         inquire_equel(rowcount = "rowcount")
-           if (rowcount != 1)
-               strcpy(name, "???");
+           status = id_to_name(id, "USER", &argv[idx]);
        } else if (!strcmp(type, "KERBEROS")) {
-##         repeat retrieve (name = strings.string) where strings.string_id = @id
-##         inquire_equel(rowcount = "rowcount")
-           if (rowcount != 1)
-               strcpy(name, "???");
+           status = id_to_name(id, "STRING", &argv[idx]);
        } else if (!strcmp(type, "NONE")) {
-           strcpy(name, "NONE");
-       } else
-         strcpy(name, "???");
-       free(argv[idx]);
-       argv[idx] = name;
+           status = 0;
+           free(argv[idx]);
+           argv[idx] = strsave("NONE");
+       } else {
+           status = 0;
+           free(argv[idx]);
+           argv[idx] = strsave("???");
+       }
+       if (status && status != MR_NO_MATCH)
+         return(status);
 
        if (!strcmp(q->shortname, "glin") && atoi(argv[6]) == -1) {
            argv[6] = realloc(argv[6], strlen(UNIQUE_GID) + 1);
@@ -1300,84 +1384,159 @@ followup_glin(q, sq, v, action, actarg, cl)
     }
 
     sq_destroy(sq);
-    return (SMS_SUCCESS);
-##}
+    return (MR_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
- **   argv[1] - member_type
- **   argv[2] - member_id
- **
- **/
+/* followup_gqot: Fix the entity name, directory name & modby fields
+ *   argv[0] = filsys_id
+ *   argv[1] = type
+ *   argv[2] = entity_id
+ *   argv[3] = ascii(quota)
+ */
 
-followup_amtl(q, argv, cl)
+followup_gqot(q, sq, v, action, actarg, cl)
     struct query *q;
-    char *argv[];
+    register struct save_queue *sq;
+    struct validate *v;
+    register int (*action)();
+    register int actarg;
     client *cl;
 ##{
-##  int list_id;
-##  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
-
-    /* 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);
-
-    member_id = *(int *)argv[2];
+    register int j;
+    char **argv, *malloc();
+##  int id, rowcount;
+##  char *name, *label;
+    int status, idx;
 
-    /* is parent list a mailing list? */
-##  repeat retrieve (exists = l.maillist) where l.#list_id=@list_id
-    if (!exists)
-       return(SMS_SUCCESS);
+    if (!strcmp(q->name, "get_quota") ||
+       !strcmp(q->name, "get_quota_by_filesys"))
+      idx = 4;
+    else
+      idx = 3;
+    while (sq_get_data(sq, &argv)) {
+       if (idx == 4) {
+           switch (argv[1][0]) {
+           case 'U':
+               status = id_to_name(atoi(argv[2]), "USER", &argv[2]);
+               break;
+           case 'G':
+           case 'L':
+               status = id_to_name(atoi(argv[2]), "LIST", &argv[2]);
+               break;
+           case 'A':
+               free(argv[2]);
+               argv[2] = strsave("system:anyuser");
+               break;
+           default:
+               id = atoi(argv[2]);
+               argv[2] = malloc(8);
+               sprintf(argv[2], "%d", id);
+           }
+       }
+       id = atoi(argv[idx]);
+       free(argv[idx]);
+       argv[idx] = malloc(256);
+       name = argv[idx];
+       if (id == 0) {
+           label = argv[0];
+##         repeat retrieve (name = filesys.#name) where filesys.#label = @label
+       } else {
+##         repeat retrieve (name = nfsphys.dir) where nfsphys.nfsphys_id = @id
+       }
+##     inquire_equel(rowcount = "rowcount")
+       if (rowcount != 1) {
+           sprintf(argv[idx], "#%d", id);
+       }
 
-    /* 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);
+       id = atoi(argv[idx+3]);
+       if (id > 0)
+         status = id_to_name(id, "USER", &argv[idx+3]);
+       else
+         status = id_to_name(-id, "STRING", &argv[idx+3]);
+       if (status && status != MR_NO_MATCH)
+         return(status);
+       (*action)(q->vcnt, argv, actarg);
+       for (j = 0; j < q->vcnt; j++)
+         free(argv[j]);
+       free(argv);
+    }
+    sq_destroy(sq);
+    return(MR_SUCCESS);
 ##}
 
 
-/* followup_anfq: Add allocation to nfsphys after creating quota.
+/* followup_aqot: Add allocation to nfsphys after creating quota.
  *   argv[0] = filsys_id
- *   argv[2] = ascii(quota)
+ *   argv[1] = type if "add_quota" or "update_quota"
+ *   argv[2 or 1] = id
+ *   argv[3 or 2] = ascii(quota)
  */
 
-followup_anfq(q, argv, cl)
+followup_aqot(q, argv, cl)
     struct query  *q;
     char **argv;
     client *cl;
 ##{
-##  int quota, user, fs, who;
-##  char *entity;
+##  int quota, id, fs, who;
+##  char *entity, *qtype;
 
     fs = *(int *)argv[0];
-    user = *(int *)argv[1];
-    quota = atoi(argv[2]);
-    who = cl->users_id;
+    if (!strcmp(q->name, "add_quota") || !strcmp(q->name, "update_quota")) {
+       qtype = argv[1];
+       id = *(int *)argv[2];
+       quota = atoi(argv[3]);
+    } else {
+       qtype = "USER";
+       id = *(int *)argv[1];
+       quota = atoi(argv[2]);
+    }
+    who = cl->client_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 q (modtime = "now", modby = @who, modwith = @entity)
+##     where q.filsys_id = @fs and q.type = @qtype and q.entity_id = @id
 ##  repeat replace nfsphys (allocated = nfsphys.allocated + @quota)
 ##     where nfsphys.nfsphys_id = filesys.#phys_id and filesys.filsys_id = @fs
-    return(SMS_SUCCESS);
+    if (ingres_errno) return(mr_errcode);
+    return(MR_SUCCESS);
 ##}
 
 
+followup_gpce(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, status;
+
+    i = q->vcnt - 2;
+    while (sq_get_data(sq, &argv)) {
+       id = atoi(argv[PCAP_QSERVER]);
+       status = id_to_name(id, "MACHINE", &argv[PCAP_QSERVER]);
+       if (status) return (status);
+       id = atoi(argv[i]);
+       if (id > 0)
+         status = id_to_name(id, "USER", &argv[i]);
+       else
+         status = id_to_name(-id, "STRING", &argv[i]);
+       if (status && status != MR_NO_MATCH)
+         return(status);
+       (*action)(q->vcnt, argv, actarg);
+       for (j = 0; j < q->vcnt; j++)
+         free(argv[j]);
+       free(argv);
+    }
+    sq_destroy(sq);
+    return(MR_SUCCESS);
+}
+
+
 /* followup_gzcl:
  */
 
@@ -1388,48 +1547,40 @@ followup_gzcl(q, sq, v, action, actarg, cl)
     register int (*action)();
     int actarg;
     client *cl;
-##{
-##  char *name;
-##  int rowcount, id;
+{
+    int id, i, status;
     char **argv;
-    int i;
 
     while (sq_get_data(sq, &argv)) {
-       sms_trim_args(q->vcnt, argv);
+       mr_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);
+       if (id > 0)
+         status = id_to_name(id, "USER", &argv[i]);
+       else
+         status = id_to_name(-id, "STRING", &argv[i]);
+       if (status && status != MR_NO_MATCH)
+         return(status);
 
        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, "???");
+               status = id_to_name(id, "LIST", &argv[i+1]);
            } 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, "???");
+               status = id_to_name(id, "USER", &argv[i+1]);
            } else if (!strcmp(argv[i], "KERBEROS")) {
-##             repeat retrieve (name = strings.string) where strings.string_id = @id
-##             inquire_equel(rowcount = "rowcount")
-               if (rowcount != 1)
-                 strcpy(name, "???");
+               status = id_to_name(id, "STRING", &argv[i+1]);
            } else if (!strcmp(argv[i], "NONE")) {
-               strcpy(name, "NONE");
+               status = 0;
+               free(argv[i+1]);
+               argv[i+1] = strsave("NONE");
            } else {
-               strcpy(name, "???");
+               status = 0;
+               free(argv[i+1]);
+               argv[i+1] = strsave("???");
            }
+           if (status && status != MR_NO_MATCH)
+             return(status);
        }
 
        /* send the data */
@@ -1441,8 +1592,8 @@ followup_gzcl(q, sq, v, action, actarg, cl)
        free(argv);
     }
     sq_destroy(sq);
-    return(SMS_SUCCESS);
-##}
+    return(MR_SUCCESS);
+}
 
 
 /* followup_gsha:
@@ -1455,47 +1606,39 @@ followup_gsha(q, sq, v, action, actarg, cl)
     register int (*action)();
     int actarg;
     client *cl;
-##{
-##  char *name;
-##  int rowcount, id;
+{
     char **argv;
-    int i;
+    int i, id, status;
 
     while (sq_get_data(sq, &argv)) {
-       sms_trim_args(q->vcnt, argv);
+       mr_trim_args(q->vcnt, argv);
 
        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);
+       if (id > 0)
+         status = id_to_name(id, "USER", &argv[4]);
+       else
+         status = id_to_name(-id, "STRING", &argv[4]);
+       if (status && status != MR_NO_MATCH)
+         return(status);
 
        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, "???");
+           status = id_to_name(id, "LIST", &argv[2]);
        } 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, "???");
+           status = id_to_name(id, "USER", &argv[2]);
        } else if (!strcmp(argv[1], "KERBEROS")) {
-##         repeat retrieve (name = strings.string) where strings.string_id = @id
-##         inquire_equel(rowcount = "rowcount")
-           if (rowcount != 1)
-             strcpy(name, "???");
+           status = id_to_name(id, "STRING", &argv[2]);
        } else if (!strcmp(argv[1], "NONE")) {
-           strcpy(name, "NONE");
+           status = 0;
+           free(argv[2]);
+           argv[2] = strsave("NONE");
        } else {
-           strcpy(name, "???");
+           status = 0;
+           free(argv[2]);
+           argv[2] = strsave("???");
        }
+       if (status && status != MR_NO_MATCH)
+         return(status);
 
        /* send the data */
        (*action)(q->vcnt, argv, actarg);
@@ -1506,8 +1649,8 @@ followup_gsha(q, sq, v, action, actarg, cl)
        free(argv);
     }
     sq_destroy(sq);
-    return(SMS_SUCCESS);
-##}
+    return(MR_SUCCESS);
+}
 
 
 \f
@@ -1527,34 +1670,37 @@ int set_pobox(q, argv, cl)
 ##{
 ##  int user, id, rowcount;
 ##  char *box, potype[9];
+    int status;
 
     box = argv[2];
     user = *(int *)argv[0];
 
 ##  repeat retrieve (id = users.pop_id, potype = users.#potype)
 ##             where users.users_id = @user
+    if (ingres_errno) return(mr_errcode);
     if (!strcmp(strtrim(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);
+       status = name_to_id(box, "MACHINE", &id);
+       if (status == MR_NO_MATCH)
+         return(MR_MACHINE);
+       else if (status)
+         return(status);
 ##     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"
+       if (index(box, '/') || index(box, '|'))
+         return(MR_BAD_CHAR);
+       status = name_to_id(box, "STRING", &id);
+       if (status == MR_NO_MATCH) {
+##          repeat retrieve (id = values.value) where values.name = "strings_id"
            id++;
-##          repeat replace v (value = @id) where v.name = "strings_id"
+##          repeat replace values (value = @id) where values.name = "strings_id"
 ##         append to strings (string_id = id, string = box)
-       }
+       } else if (status)
+         return(status);
 ##     repeat replace users (#potype = "SMTP", box_id = @id) 
 ##            where users.users_id = @user
     } else /* argv[1] == "NONE" */ {
@@ -1564,7 +1710,8 @@ int set_pobox(q, argv, cl)
     set_pobox_modtime(q, argv, cl);
 ##  repeat replace tblstats (updates = tblstats.updates + 1, modtime = "now")
 ##     where tblstats.#table = "users"
-    return(SMS_SUCCESS);
+    if (ingres_errno) return(mr_errcode);
+    return(MR_SUCCESS);
 ##}
 
 
@@ -1582,10 +1729,10 @@ get_list_info(q, aargv, cl, action, actarg)
 ##{
     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];
+##  char maillist[5], group[5], gid[6], acl_name[256], desc[256], modtime[27];
+##  char modby[256], modwith[9];
 ##  int id, rowcount, acl_id, hid, modby_id;
-    int returned;
+    int returned, status;
     struct save_queue *sq, *sq_create();
 
     returned = rowcount = 0;
@@ -1597,13 +1744,13 @@ get_list_info(q, aargv, cl, action, actarg)
        sq_save_data(sq, id);
        rowcount++;
 ##  }
+    if (ingres_errno) return(mr_errcode);
     if (rowcount == 0)
-      return(SMS_NO_MATCH);
+      return(MR_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;
+    argv[9] = desc; argv[10] = modtime; argv[12] = modwith;
 
     while (sq_get_data(sq, &id)) {
        if (id == 0)
@@ -1617,47 +1764,299 @@ get_list_info(q, aargv, cl, action, actarg)
 ##             desc = l.#desc, modtime = l.#modtime, modby_id = l.#modby,
 ##             modwith =l.#modwith)
 ##         where l.list_id = @id
+       if (ingres_errno) return(mr_errcode);
 
        if (atoi(gid) == -1)
            argv[6] = UNIQUE_GID;
 
+       argv[8] = malloc(0);
        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, "???");
+           status = id_to_name(acl_id, "LIST", &argv[8]);
        } 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, "???");
+           status = id_to_name(acl_id, "USER", &argv[8]);
        } else if (!strcmp(acl_type, "KERBEROS")) {
-##         repeat retrieve (acl_name = strings.string)
-##             where strings.string_id = @acl_id
-##         inquire_equel(rowcount = "rowcount")
-           if (rowcount != 1)
-               strcpy(acl_name, "???");
+           status = id_to_name(acl_id, "STRING", &argv[8]);
        } else if (!strcmp(acl_type, "NONE")) {
-           strcpy(acl_name, "NONE");
-       } else
-         strcpy(acl_name, "???");
+           status = 0;
+           free(argv[8]);
+           argv[8] = strsave("NONE");
+       } else {
+           status = 0;
+           free(argv[8]);
+           argv[8] = strsave("???");
+       }
+       if (status && status != MR_NO_MATCH) return(status);
 
-##     repeat retrieve (modby = users.login) where users.users_id = @modby_id
-##     inquire_equel(rowcount = "rowcount")
-       if (rowcount != 1)
-         sprintf(modby, "#%d", id);
+       argv[11] = malloc(0);
+       if (modby_id > 0)
+         status = id_to_name(modby_id, "USER", &argv[11]);
+       else
+         status = id_to_name(-modby_id, "STRING", &argv[11]);
+       if (status && status != MR_NO_MATCH) return(status);
 
-       sms_trim_args(q->vcnt, argv);
+       mr_trim_args(q->vcnt, argv);
        returned++;
        (*action)(q->vcnt, argv, actarg);
+       free(argv[8]);
+       free(argv[11]);
     }
 
     sq_destroy(sq);
-##  repeat replace tblstats (retrieves = tblstats.retrieves + 1)
-##     where tblstats.#table = "list"
+    if (ingres_errno) return(mr_errcode);
+    return (MR_SUCCESS);
+##}
+
+
+/* Add_member_to_list: do list flattening as we go!  MAXLISTDEPTH is
+ * how many different ancestors a member is allowed to have.
+ */
+
+#define MAXLISTDEPTH   1024
+
+int add_member_to_list(q, argv, cl)
+    struct query *q;
+    char **argv;
+    client *cl;
+##{
+##  int id, lid, mid, exists, error, who, ref;
+##  char *mtype, dtype[9], *entity;
+    int ancestors[MAXLISTDEPTH], aref[MAXLISTDEPTH], acount, a;
+    int descendants[MAXLISTDEPTH], dref[MAXLISTDEPTH], dcount, d;
+    int status;
+    char *dtypes[MAXLISTDEPTH];
+    char *iargv[3], *buf;
+
+##  range of m is imembers
+    lid = *(int *)argv[0];
+    mtype = argv[1];
+    mid = *(int *)argv[2];
+    /* if the member is already a direct member of the list, punt */
+##  repeat retrieve (exists = any(m.list_id where m.list_id=@lid and 
+##                        m.member_id = @mid and m.member_type = @mtype
+##                        and m.direct = 1))
+    if (exists)
+      return(MR_EXISTS);
+    if (!strcasecmp(mtype, "STRING")) {
+       buf = malloc(0);
+       status = id_to_name(mid, "STRING", &buf);
+       if (status) return(status);
+       if (index(buf, '/') || index(buf, '|')) {
+           free(buf);
+           return(MR_BAD_CHAR);
+       }
+       free(buf);
+    }
 
-    return (SMS_SUCCESS);
+    ancestors[0] = lid;
+    aref[0] = 1;
+    acount = 1;
+##  repeat retrieve (id = m.list_id, ref = m.ref_count)
+##     where m.member_id = @lid and m.member_type = "LIST" {
+       aref[acount] = ref;
+       ancestors[acount++] = id;
+       if (acount >= MAXLISTDEPTH) {
+##         endretrieve
+       }
+##  }
+    if (ingres_errno) return(mr_errcode);
+    if (acount >= MAXLISTDEPTH) {
+       return(MR_INTERNAL);
+    }
+    descendants[0] = mid;
+    dtypes[0] = mtype;
+    dref[0] = 1;
+    dcount = 1;
+    error = 0;
+    if (!strcmp(mtype, "LIST")) {
+##     repeat retrieve (id = m.member_id, dtype = m.member_type,
+##                      ref = m.ref_count)
+##       where m.list_id = @mid {
+           switch (dtype[0]) {
+           case 'L':
+               dtypes[dcount] = "LIST";
+               break;
+           case 'U':
+               dtypes[dcount] = "USER";
+               break;
+           case 'S':
+               dtypes[dcount] = "STRING";
+               break;
+           case 'K':
+               dtypes[dcount] = "KERBEROS";
+               break;
+           default:
+               error++;
+##             endretrieve
+           }
+           dref[dcount] = ref;
+           descendants[dcount++] = id;
+           if (dcount >= MAXLISTDEPTH) {
+               error++;
+##             endretrieve
+           }
+##     }
+       if (ingres_errno) return(mr_errcode);
+       if (error)
+         return(MR_INTERNAL);
+    }
+    for (a = 0; a < acount; a++) {
+       lid = ancestors[a];
+       for (d = 0; d < dcount; d++) {
+           mid = descendants[d];
+           mtype = dtypes[d];
+           if (mid == lid && !strcmp(mtype, "LIST")) {
+               return(MR_LISTLOOP);
+           }
+##         repeat retrieve (exists = any(m.ref_count where m.list_id = @lid
+##                                      and m.member_id = @mid
+##                                      and m.member_type = @mtype))
+           ref = aref[a] * dref[d];
+           if (exists) {
+               if (a == 0 && d == 0)
+##               replace m (ref_count = m.ref_count+ref, direct = 1)
+##                          where m.list_id = lid and m.member_id = mid and
+##                          m.member_type = mtype
+               else
+##               replace m (ref_count = m.ref_count+ref)
+##                          where m.list_id = lid and m.member_id = mid and
+##                          m.member_type = mtype
+           } else {
+               incremental_clear_before();
+               if (a == 0 && d == 0)
+##               append imembers (list_id=lid, member_id = mid, direct = 1,
+##                                member_type=mtype, ref_count = 1)
+               else
+##               append imembers (list_id=lid, member_id = mid,
+##                                member_type=mtype, ref_count = ref)
+               iargv[0] = (char *)lid;
+               iargv[1] = mtype;
+               iargv[2] = (char *)mid;
+               incremental_after("members", 0, iargv);
+           }
+       }
+    }
+    lid = *(int *)argv[0];
+    entity = cl->entity;
+    who = cl->client_id;
+##  repeat replace list (modtime = "now", modby = @who, modwith = @entity)
+##      where list.#list_id = @lid
+    if (ingres_errno) return(mr_errcode);
+    return(MR_SUCCESS);
+##}
+
+
+/* Delete_member_from_list: do list flattening as we go!
+ */
+
+int delete_member_from_list(q, argv, cl)
+    struct query *q;
+    char **argv;
+    client *cl;
+##{
+##  int id, lid, mid, cnt, exists, error, who, ref;
+##  char *mtype, dtype[9], *entity;
+    int ancestors[MAXLISTDEPTH], aref[MAXLISTDEPTH], acount, a;
+    int descendants[MAXLISTDEPTH], dref[MAXLISTDEPTH], dcount, d;
+    char *dtypes[MAXLISTDEPTH];
+    char *iargv[3];
+
+##  range of m is imembers
+    lid = *(int *)argv[0];
+    mtype = argv[1];
+    mid = *(int *)argv[2];
+    /* if the member is not a direct member of the list, punt */
+##  repeat retrieve (exists = any(m.list_id where m.list_id=@lid and 
+##                        m.member_id = @mid and m.member_type = @mtype
+##                        and m.direct = 1))
+    if (ingres_errno) return(mr_errcode);
+    if (!exists)
+      return(MR_NO_MATCH);
+    ancestors[0] = lid;
+    aref[0] = 1;
+    acount = 1;
+##  repeat retrieve (id = m.list_id, ref = m.ref_count)
+##     where m.member_id = @lid and m.member_type = "LIST" {
+       aref[acount] = ref;
+       ancestors[acount++] = id;
+       if (acount >= MAXLISTDEPTH)
+##       endretrieve
+##  }
+         if (ingres_errno) return(mr_errcode);
+    if (acount >= MAXLISTDEPTH)
+      return(MR_INTERNAL);
+    descendants[0] = mid;
+    dtypes[0] = mtype;
+    dref[0] = 1;
+    dcount = 1;
+    error = 0;
+    if (!strcmp(mtype, "LIST")) {
+##     repeat retrieve (id = m.member_id, dtype = m.member_type,
+##                      ref = m.ref_count)
+##       where m.list_id = @mid {
+           switch (dtype[0]) {
+           case 'L':
+               dtypes[dcount] = "LIST";
+               break;
+           case 'U':
+               dtypes[dcount] = "USER";
+               break;
+           case 'S':
+               dtypes[dcount] = "STRING";
+               break;
+           case 'K':
+               dtypes[dcount] = "KERBEROS";
+               break;
+           default:
+               error++;
+##             endretrieve
+           }
+           dref[dcount] = ref;
+           descendants[dcount++] = id;
+           if (dcount >= MAXLISTDEPTH)
+##           endretrieve
+##     }
+             if (ingres_errno) return(mr_errcode);
+       if (error)
+         return(MR_INTERNAL);
+    }
+    for (a = 0; a < acount; a++) {
+       lid = ancestors[a];
+       for (d = 0; d < dcount; d++) {
+           mid = descendants[d];
+           mtype = dtypes[d];
+           if (mid == lid && !strcmp(mtype, "LIST")) {
+               return(MR_LISTLOOP);
+           }
+##         repeat retrieve (cnt = m.ref_count)
+##             where m.list_id = @lid and m.member_id = @mid
+##               and m.member_type = @mtype
+           ref = aref[a] * dref[d];
+           if (cnt <= ref) {
+               iargv[0] = (char *)lid;
+               iargv[1] = mtype;
+               iargv[2] = (char *)mid;
+               incremental_before("members", 0, iargv);
+##             delete m where m.list_id = lid and m.member_id = mid and
+##                 m.member_type = mtype
+               incremental_clear_after();
+           } else if (a == 0 && d == 0) {
+##             replace m (ref_count = m.ref_count-ref, direct = 0)
+##                 where m.list_id = lid and m.member_id = mid and
+##                 m.member_type = mtype
+           } else {
+##             replace m (ref_count = m.ref_count-ref)
+##                 where m.list_id = lid and m.member_id = mid and
+##                 m.member_type = mtype
+           }
+       }
+    }
+    lid = *(int *)argv[0];
+    entity = cl->entity;
+    who = cl->client_id;
+##  repeat replace list (modtime = "now", modby = @who, modwith = @entity)
+##      where list.#list_id = @lid
+    if (ingres_errno) return(mr_errcode);
+    return(MR_SUCCESS);
 ##}
 
 
@@ -1681,6 +2080,7 @@ int get_ace_use(q, argv, cl, action, actarg)
 ##  int aid, listid, id;
     struct save_queue *sq, *sq_create();
 
+##  range of m is imembers
     atype = argv[0];
     aid = *(int *)argv[1];
     if (!strcmp(atype, "LIST") || !strcmp(atype, "USER") ||
@@ -1692,67 +2092,49 @@ int get_ace_use(q, argv, cl, action, actarg)
     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)
+##     repeat retrieve (listid = m.list_id)
 ##             where m.member_type = "LIST" and m.member_id = @id {
-             sq_save_unique_data(sq, listid);
-##         }
-         }
+           sq_save_unique_data(sq, listid);
+##     }
        /* now process each one */
        while (sq_get_data(sq, &id)) {
-           if (get_ace_internal("LIST", id, action, actarg) == SMS_SUCCESS)
+           if (get_ace_internal("LIST", id, action, actarg) == MR_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_ace_internal("LIST", id, action, actarg) == SMS_SUCCESS)
+           if (get_ace_internal("LIST", id, action, actarg) == MR_SUCCESS)
              found++;
        }
-       if (get_ace_internal("USER", aid, action, actarg) == SMS_SUCCESS)
+       if (get_ace_internal("USER", aid, action, actarg) == MR_SUCCESS)
          found++;
     }
 
     if (!strcmp(atype, "RKERBERO")) {
-##     range of m is members
 ##     repeat retrieve (listid = m.list_id)
 ##             where m.member_type = "KERBEROS" 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_ace_internal("LIST", id, action, actarg) == SMS_SUCCESS)
+           if (get_ace_internal("LIST", id, action, actarg) == MR_SUCCESS)
              found++;
        }
-       if (get_ace_internal("KERBEROS", aid, action, actarg) == SMS_SUCCESS)
+       if (get_ace_internal("KERBEROS", aid, action, actarg) == MR_SUCCESS)
          found++;
     }
 
     sq_destroy(sq);    
-    if (!found) return(SMS_NO_MATCH);
-    return(SMS_SUCCESS);
+    if (ingres_errno) return(mr_errcode);
+    if (!found) return(MR_NO_MATCH);
+    return(MR_SUCCESS);
 ##}
 
 
@@ -1826,8 +2208,8 @@ int get_ace_use(q, argv, cl, action, actarg)
         found++;
 ##  }
 
-    if (!found) return(SMS_NO_MATCH);
-    return(SMS_SUCCESS);
+    if (!found) return(MR_NO_MATCH);
+    return(MR_SUCCESS);
 ##}
 
 
@@ -1846,144 +2228,61 @@ int get_lists_of_member(q, argv, cl, action, actarg)
     int (*action)();
     int actarg;
 ##{
-    int found = 0;
+    int found = 0, direct = 1;
+    char *rargv[6];
 ##  char *atype;
 ##  int aid, listid, id;
-    struct save_queue *sq, *sq_create();
+##  char name[33], active[5], public[5], hidden[5], maillist[5], group[5];
 
     atype = argv[0];
     aid = *(int *)argv[1];
-    if (!strcmp(atype, "LIST") ||
-       !strcmp(atype, "USER") ||
-       !strcmp(atype, "STRING") ||
-       !strcmp(atype, "KERBEROS")) {
-      return(glom_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 (glom_internal("LIST", id, action, actarg) == SMS_SUCCESS)
-             found++;
-       }
+       atype = "LIST";
+       direct = 0;
     }
-
     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++;
+       atype = "USER";
+       direct = 0;
     }
-
     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++;
+       atype = "STRING";
+       direct = 0;
     }
-
-    if (!strcmp(atype, "RKERBERO")) {
-##     range of m is members
-##     repeat retrieve (listid = m.list_id)
-##             where m.member_type = "KERBEROS" 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("KERBEROS", aid, action, actarg) == SMS_SUCCESS)
-         found++;
+    if (!strcmp(atype, "RKERBEROS")) {
+       atype = "KERBEROS";
+       direct = 0;
     }
 
-##  repeat replace tblstats (retrieves = tblstats.retrieves + 1)
-##     where tblstats.#table = "members"
-    sq_destroy(sq);    
-    if (!found) return(SMS_NO_MATCH);
-    return(SMS_SUCCESS);
-##}
-
-
-/* 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), 
+##  range of m is imembers
+    if (direct) {
+##    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.direct = 1 and
+##                   m.member_type = @atype and m.member_id = @aid {
+        (*action)(6, rargv, actarg);
+        found++;
+##    }
+    } else {
+##    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++;
-##  }
+##    }
+    }
 
-    if (!found) return(SMS_NO_MATCH);
-    return(SMS_SUCCESS);
+    if (ingres_errno) return(mr_errcode);
+    if (!found) return(MR_NO_MATCH);
+    return(MR_SUCCESS);
 ##}
 
 
@@ -2023,53 +2322,101 @@ get_members_of_list(q, argv, cl, action, actarg)
     int (*action)();
     int actarg;
 ##{
-##  int list_id;
-##  char member_name[129];
+##  int list_id, member_id;
+##  char member_name[129], member_type[9];
     char *targv[2];
+    int members;
+    struct save_queue *sq;
 
     list_id = *(int *)argv[0];
-    targv[0] = "USER";
-    targv[1] = member_name;
+    members = 0;
+    sq = sq_create();
 
-##  range of m is members
+##  repeat retrieve (member_type = imembers.#member_type,
+##                  member_id = imembers.#member_id)
+##     where imembers.#list_id = @list_id and imembers.direct = 1 {
+      if (members++ > 49)
+##     endretrieve
+      sq_save_data(sq, (member_type[0] << 24) | (member_id & 0xffffff));
+##  }
+    if (members <= 49) {
+       targv[1] = malloc(0);
+       while (sq_remove_data(sq, &member_id)) {
+           switch (member_id >> 24) {
+           case 'U':
+               targv[0] = "USER";
+               id_to_name(member_id & 0xffffff, "USER", &targv[1]);
+               (*action)(2, targv, actarg);
+               break;
+           case 'L':
+               targv[0] = "LIST";
+               id_to_name(member_id & 0xffffff, "LIST", &targv[1]);
+               (*action)(2, targv, actarg);
+               break;
+           case 'S':
+               targv[0] = "STRING";
+               id_to_name(member_id & 0xffffff, "STRING", &targv[1]);
+               (*action)(2, targv, actarg);
+               break;
+           case 'K':
+               targv[0] = "KERBEROS";
+               id_to_name(member_id & 0xffffff, "STRING", &targv[1]);
+               (*action)(2, targv, actarg);
+               break;
+           default:
+               sq_destroy(sq);
+               return(MR_INTERNAL);
+           }
+       }
+       free(targv[1]);
+       sq_destroy(sq);
+       return(MR_SUCCESS);
+    }
+    sq_destroy(sq);
+
+    targv[1] = member_name;
+    targv[0] = "USER";
+##  range of m is imembers
 ##  repeat retrieve (member_name = users.login)
-##             where m.#list_id = @list_id and m.member_type = "USER"
-##                   and m.member_id = users.users_id
+##             where m.#list_id = @list_id and m.#member_type = "USER"
+##                   and m.#member_id = users.users_id and m.direct = 1
 ##             sort by #member_name
 ##  {
         (*action)(2, targv, actarg);
 ##  }
+    if (ingres_errno) return(mr_errcode);
 
     targv[0] = "LIST";
 ##  repeat retrieve (member_name = list.name)
-##             where m.#list_id = @list_id and m.member_type = "LIST"
-##                   and m.member_id = list.#list_id
+##             where m.#list_id = @list_id and m.#member_type = "LIST"
+##                   and m.#member_id = list.#list_id and m.direct = 1
 ##             sort by #member_name
 ##  {
         (*action)(2, targv, actarg);
 ##  }
+    if (ingres_errno) return(mr_errcode);
 
     targv[0] = "STRING";
 ##  repeat retrieve (member_name = strings.string)
-##             where m.#list_id = @list_id and m.member_type = "STRING"
-##                   and m.member_id = strings.string_id
+##             where m.#list_id = @list_id and m.#member_type = "STRING"
+##                   and m.#member_id = strings.string_id and m.direct = 1
 ##             sort by #member_name
 ##  {
         (*action)(2, targv, actarg);
 ##  }
+    if (ingres_errno) return(mr_errcode);
 
     targv[0] = "KERBEROS";
 ##  repeat retrieve (member_name = strings.string)
-##             where m.#list_id = @list_id and m.member_type = "KERBEROS"
-##                   and m.member_id = strings.string_id
+##             where m.#list_id = @list_id and m.#member_type = "KERBEROS"
+##                   and m.#member_id = strings.string_id and m.direct = 1
 ##             sort by #member_name
 ##  {
         (*action)(2, targv, actarg);
 ##  }
+    if (ingres_errno) return(mr_errcode);
 
-##  repeat replace tblstats (retrieves = tblstats.retrieves + 1)
-##     where tblstats.#table = "members"
-    return(SMS_SUCCESS);
+    return(MR_SUCCESS);
 ##}
 
 
@@ -2089,12 +2436,13 @@ int count_members_of_list(q, argv, cl, action, actarg)
 
     list = *(int *)argv[0];
     rargv[0] = countbuf;
-##  repeat retrieve (ct = count(members.list_id where members.list_id = @list))
+##  repeat retrieve (ct = count(imembers.list_id
+##                             where imembers.list_id = @list and
+##                                   imembers.direct = 1))
+    if (ingres_errno) return(mr_errcode);
     sprintf(countbuf, "%d", ct);
     (*action)(1, rargv, actarg);
-##  repeat replace tblstats (retrieves = tblstats.retrieves + 1)
-##     where tblstats.#table = "members"
-    return(SMS_SUCCESS);
+    return(MR_SUCCESS);
 ##}
 
 
@@ -2160,12 +2508,11 @@ int qualified_get(q, argv, action, actarg, start, range, field, flags)
 ##  retrieve (name = rvar.rfield) where qual {
        (*action)(1, rargv, actarg);
 ##  }
+    if (ingres_errno) return(mr_errcode);
 ##  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);
+      return(MR_NO_MATCH);
+    return(MR_SUCCESS);
 ##}
 
 
@@ -2207,20 +2554,19 @@ int qualified_get_serverhost(q, argv, cl, action, actarg)
 ##  retrieve (sname = sh.service, mname = machine.name) where qual {
        (*action)(2, rargv, actarg);
 ##  }
+    if (ingres_errno) return(mr_errcode);
 ##  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);
+      return(MR_NO_MATCH);
+    return(MR_SUCCESS);
 ##}
 
 
 /* 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).
+ * type for filesystem allocation (MR_FS_STUDENT, MR_FS_FACULTY, 
+ * MR_FS_STAFF, MR_FS_MISC).
  */
 
 register_user(q, argv, cl)
@@ -2231,10 +2577,11 @@ register_user(q, argv, 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;
+    char buffer[256], *aargv[3];
     int maxsize;
 
     entity = cl->entity;
-    who = cl->users_id;
+    who = cl->client_id;
 
     uid = atoi(argv[0]);
     login = argv[1];
@@ -2248,69 +2595,86 @@ register_user(q, argv, cl)
 
     /* find user */
 ##  repeat retrieve (users_id = u.#users_id)
-##     where u.#uid = @uid and u.status = 0
+##     where u.#uid = @uid and (u.status = 0 or u.status = 5 or u.status = 6)
 ##  inquire_equel(rowcount = "rowcount");
     if (rowcount == 0)
-      return(SMS_NO_MATCH);
+      return(MR_NO_MATCH);
     if (rowcount > 1)
-      return(SMS_NOT_UNIQUE);
+      return(MR_NOT_UNIQUE);
 
     /* check new login name */
-##  repeat retrieve (flag = any(u.#login where u.#login = @login))
-    if (ingres_errno) return(sms_errcode);
-    if (flag) return(SMS_IN_USE);
+##  repeat retrieve (flag = any(u.#login where u.#login = @login and
+##                             u.#users_id != users_id))
+    if (ingres_errno) return(mr_errcode);
+    if (flag) return(MR_IN_USE);
 ##  repeat retrieve (flag = any(l.#name where l.#name = @login))
-    if (ingres_errno) return(sms_errcode);
-    if (flag) return(SMS_IN_USE);
+    if (ingres_errno) return(mr_errcode);
+    if (flag) return(MR_IN_USE);
 ##  repeat retrieve (flag = any(filesys.#label where filesys.#label = @login))
-    if (ingres_errno) return(sms_errcode);
-    if (flag) return(SMS_IN_USE);
+    if (ingres_errno) return(mr_errcode);
+    if (flag) return(MR_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")
+    if (ingres_errno) return(mr_errcode);
 ##  inquire_equel(rowcount = "rowcount");
     if (rowcount == 0)
-      return(SMS_NO_POBOX);
+      return(MR_NO_POBOX);
 
     /* change login name, set pobox */
+    sprintf(buffer, "u.users_id = %d", users_id);
+    incremental_before("users", buffer, 0);
 ##  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 (ingres_errno) return(mr_errcode);
     if (rowcount != 1)
-      return(SMS_INTERNAL);
+      return(MR_INTERNAL);
     set_pop_usage(mid, 1);
     com_err(whoami, 0, "set login name to %s and pobox to %s", login,
-           trim(machname));
+           strtrim(machname));
+    incremental_after("users", buffer, 0);
 
     /* create group list */
     if (set_next_object_id("gid", "list"))
-      return(SMS_NO_ID);
+      return(MR_NO_ID);
     if (set_next_object_id("list_id", "list"))
-      return(SMS_NO_ID);
+      return(MR_NO_ID);
 ##  repeat retrieve (list_id = values.value) where values.name = "list_id"
+    if (ingres_errno) return(mr_errcode);
 ##  inquire_equel(rowcount = "rowcount");
     if (rowcount != 1)
-      return(SMS_INTERNAL);
+      return(MR_INTERNAL);
+    incremental_clear_before();
 ##  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"
+    if (ingres_errno) return(mr_errcode);
 ##  inquire_equel(rowcount = "rowcount");
     if (rowcount != 1)
-      return(SMS_INTERNAL);
-##  repeat append members (#list_id = @list_id, member_type = "USER",
-##                        member_id = @users_id)
+      return(MR_INTERNAL);
+    sprintf(buffer, "l.list_id = %d", list_id);
+    incremental_after("list", buffer, 0);
+    aargv[0] = (char *) list_id;
+    aargv[1] = "USER";
+    aargv[2] = (char *) users_id;
+    incremental_clear_before();
+##  repeat append imembers (#list_id = @list_id, member_type = "USER",
+##                        member_id = @users_id, ref_count = 1, direct = 1)
+    if (ingres_errno) return(mr_errcode);
 ##  inquire_equel(rowcount = "rowcount");
     if (rowcount != 1)
-      return(SMS_INTERNAL);
+      return(MR_INTERNAL);
+    incremental_after("members", 0, aargv);
     com_err(whoami, 0, "group list created");
 
     /* decide where to put filesystem */
@@ -2327,12 +2691,14 @@ register_user(q, argv, cl)
            m_id = mid;
        }
 ##  }
+    if (ingres_errno) return(mr_errcode);
     if (maxsize == 0)
-      return(SMS_NO_FILESYS);
+      return(MR_NO_FILESYS);
 
     /* create filesystem */
     if (set_next_object_id("filsys_id", "filesys"))
-      return(SMS_NO_ID);
+      return(MR_NO_ID);
+    incremental_clear_before();        
 ##  repeat append filesys (filsys_id = values.value, phys_id = @pid,
 ##                        label = @login, type = "NFS", mach_id = @m_id,
 ##                        name = @directory + "/" + @login,
@@ -2342,38 +2708,56 @@ register_user(q, argv, cl)
 ##                        lockertype = "HOMEDIR", modtime = "now",
 ##                        modby = @who, modwith = @entity)
 ##     where values.name = "filsys_id"
+    if (ingres_errno) return(mr_errcode);
 ##  inquire_equel(rowcount = "rowcount");
     if (rowcount != 1)
-      return(SMS_INTERNAL);
+      return(MR_INTERNAL);
+    incremental_after("filesys", 
+         "fs.filsys_id = values.value and values.name = \"filsys_id\"",
+                     0);
     com_err(whoami, 0, "filesys created on mach %d in %s/%s", m_id,
            directory, login);
 
     /* set quota */
 ##  repeat retrieve (quota = values.value) where values.name = "def_quota"
+    if (ingres_errno) return(mr_errcode);
 ##  inquire_equel(rowcount = "rowcount");
     if (rowcount != 1)
-      return(SMS_NO_QUOTA);
-##  repeat append nfsquota (#users_id = @users_id, filsys_id = values.value,
-##                         #quota = @quota, phys_id = @pid, modtime = "now",
-##                         modby = @who, modwith = @entity)
+      return(MR_NO_QUOTA);
+    incremental_clear_before();
+##  repeat append #quota (entity_id = @users_id, filsys_id = values.value,
+##                       type = "USER",
+##                       #quota = @quota, phys_id = @pid, modtime = "now",
+##                       modby = @who, modwith = @entity)
 ##     where values.name = "filsys_id"
+    if (ingres_errno) return(mr_errcode);
 ##  inquire_equel(rowcount = "rowcount");
     if (rowcount != 1)
-      return(SMS_INTERNAL);
+      return(MR_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"
+    if (ingres_errno) return(mr_errcode);
 ##  inquire_equel(rowcount = "rowcount");
     if (rowcount != 1)
-      return(SMS_INTERNAL);
+      return(MR_INTERNAL);
+    aargv[0] = login;
+    aargv[1] = "USER";
+    aargv[2] = login;
+    sprintf(buffer, "q.entity_id = %d and q.filsys_id = values.value and q.type = \"USER\" and values.name = \"filsys_id\"", users_id);
+    incremental_after("quota", buffer, aargv);
     com_err(whoami, 0, "quota of %d assigned", quota);
+    if (ingres_errno) return(mr_errcode);
+
+    cache_entry(login, "USER", users_id);
 
 ##  repeat replace tblstats (updates = tblstats.updates + 1, modtime = "now")
 ##     where tblstats.table = "users"
 ##  repeat replace tblstats (appends = tblstats.appends + 1, modtime = "now")
 ##     where tblstats.table = "list" or tblstats.table = "filesys" or
-##           tblstats.table = "nfsquota"
-    return(SMS_SUCCESS);
+##           tblstats.table = "quota"
+    if (ingres_errno) return(mr_errcode);
+    return(MR_SUCCESS);
 ##}
 
 
@@ -2396,11 +2780,11 @@ 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
+##  repeat replace serverhosts (value1 = serverhosts.value1 + @n)
+##         where serverhosts.service = "POP" and serverhosts.#mach_id = @mach_id
 
-    return(SMS_SUCCESS);
+    if (ingres_errno) return(mr_errcode);
+    return(MR_SUCCESS);
 ##}
 
 
@@ -2433,10 +2817,10 @@ validate_row(q, argv, v)
     /* look for the record */
 ##  range of rvar is table
 ##  retrieve (rowcount = count(rvar.name where qual))
-    if (ingres_errno) return(sms_errcode);
-    if (rowcount == 0) return(SMS_NO_MATCH);
-    if (rowcount > 1) return(SMS_NOT_UNIQUE);
-    return(SMS_EXISTS);
+    if (ingres_errno) return(mr_errcode);
+    if (rowcount == 0) return(MR_NO_MATCH);
+    if (rowcount > 1) return(MR_NOT_UNIQUE);
+    return(MR_EXISTS);
 ##}
 
 validate_fields(q, argv, vo, n)
@@ -2497,7 +2881,7 @@ validate_fields(q, argv, vo, n)
            break;
 
        case V_SORT:
-           status = SMS_EXISTS;
+           status = MR_EXISTS;
            break;
 
        case V_LOCK:
@@ -2505,11 +2889,12 @@ validate_fields(q, argv, vo, n)
            break;
        }
 
-       if (status != SMS_EXISTS) return(status);
+       if (status != MR_EXISTS) return(status);
        vo++;
     }
 
-    return(SMS_SUCCESS);
+    if (ingres_errno) return(mr_errcode);
+    return(MR_SUCCESS);
 }
 
 
@@ -2541,8 +2926,8 @@ register char *s;
 {
     while (*s)
       if (illegalchars[*s++])
-       return(SMS_BAD_CHAR);
-    return(SMS_EXISTS);
+       return(MR_BAD_CHAR);
+    return(MR_EXISTS);
 }
 
 
@@ -2554,29 +2939,46 @@ validate_id(argv, vo)
 ##  char *table;
 ##  char *namefield;
 ##  char *idfield;
-##  int id;
-##  int rowcount;
+##  int id, rowcount;
+    int status;
     register char *c;
 
+
     name = argv[vo->index];
     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;
+
+    if ((!strcmp(table, "users") && !strcmp(namefield, "login")) ||
+       !strcmp(table, "machine") ||
+       !strcmp(table, "filesys") ||
+       !strcmp(table, "list") ||
+       !strcmp(table, "cluster") ||
+       !strcmp(table, "string")) {
+       if (!strcmp(table, "machine"))
+         for (c = name; *c; c++) if (islower(*c)) *c = toupper(*c);
+       status = name_to_id(name, table, &id);
+       if (status == 0) {
+           *(int *)argv[vo->index] = id;
+           return(MR_EXISTS);
+       } else if (status == MR_NO_MATCH || status == MR_NOT_UNIQUE)
+         return(vo->error);
+       else
+         return(status);
+    }
+
     if (!strcmp(namefield, "uid")) {
 ##    retrieve (id = table.idfield) where table.namefield = int4(name)
-      if (ingres_errno) return(sms_errcode);
+      if (ingres_errno) return(mr_errcode);
 ##    inquire_equel (rowcount = "rowcount")
     } else {
 ##    retrieve (id = table.idfield) where table.namefield = name
-      if (ingres_errno) return(sms_errcode);
+      if (ingres_errno) return(mr_errcode);
 ##    inquire_equel (rowcount = "rowcount")
     }
     if (rowcount != 1) return(vo->error);
     *(int *)argv[vo->index] = id;
-    return(SMS_EXISTS);
+    return(MR_EXISTS);
 ##}
 
 validate_name(argv, vo)
@@ -2599,8 +3001,8 @@ validate_name(argv, vo)
     }
 ##  retrieve (rowcount = countu(table.namefield 
 ##            where table.namefield = name))
-    if (ingres_errno) return(sms_errcode);
-    return ((rowcount == 1) ? SMS_EXISTS : vo->error);
+    if (ingres_errno) return(mr_errcode);
+    return ((rowcount == 1) ? MR_EXISTS : vo->error);
 ##}
 
 validate_date(argv, vo)
@@ -2615,8 +3017,8 @@ validate_date(argv, vo)
 
 ##  retrieve (dd = interval("years", date(idate) - date("today")))
 ##  inquire_equel (errorno = "errorno")
-    if (errorno != 0 || dd > 5.0) return(SMS_DATE);
-    return(SMS_EXISTS);
+    if (errorno != 0 || dd > 5.0) return(MR_DATE);
+    return(MR_EXISTS);
 ##}
 
 
@@ -2626,12 +3028,13 @@ struct valobj *vo;
 ##{
 ##  char *name, *table, *namefield, *idfield;
 ##  int id;
+    int status;
     register char *c;
 
     c = name = argv[vo->index];
     while (*c)
       if (illegalchars[*c++])
-       return(SMS_BAD_CHAR);
+       return(MR_BAD_CHAR);
     table = vo->table;
     /* minor kludge to upcasify machine names */
     if (!strcmp(table, "machine"))
@@ -2641,18 +3044,17 @@ struct valobj *vo;
     id = -1;
     if (idfield == 0) {
        if (!strcmp(argv[vo->index], argv[vo->index - 1]))
-         return(SMS_EXISTS);
+         return(MR_EXISTS);
 ##     retrieve (id = any(table.namefield where table.namefield = name))
-       if (ingres_errno) return(sms_errcode);
+       if (ingres_errno) return(mr_errcode);
        if (id)
          return(vo->error);
        else
-         return(SMS_EXISTS);
+         return(MR_EXISTS);
     }
-##  retrieve (id = table.idfield) where table.namefield = name
-    if (ingres_errno) return(sms_errcode);
-    if (id == -1 || id == *(int *)argv[vo->index - 1])
-      return(SMS_EXISTS);
+    status = name_to_id(name, table, &id);
+    if (status == MR_NO_MATCH || id == *(int *)argv[vo->index - 1])
+      return(MR_EXISTS);
     else
       return(vo->error);
 ##}
@@ -2671,17 +3073,15 @@ validate_type(argv, vo)
     c = value = argv[vo->index];
     while (*c)
       if (illegalchars[*c++])
-       return(SMS_BAD_CHAR);
+       return(MR_BAD_CHAR);
 
     /* uppercase type fields */
     for (c = value; *c; c++) if (islower(*c)) *c = toupper(*c);
 
-##  range of a is alias
-##  repeat retrieve (exists = any(a.trans where a.name = @typename and
-##                                   a.type = "TYPE" and
-##                                   a.trans = @value))
-    if (ingres_errno) return(sms_errcode);
-    return (exists ? SMS_EXISTS : vo->error);
+##  repeat retrieve (exists = any(alias.trans where alias.name = @typename and
+##                               alias.type = "TYPE" and alias.trans = @value))
+    if (ingres_errno) return(mr_errcode);
+    return (exists ? MR_EXISTS : vo->error);
 ##}
 
 /* validate member or type-specific data field */
@@ -2694,8 +3094,8 @@ validate_typedata(q, argv, vo)
 ##  char *name;
 ##  char *field_type;
 ##  char data_type[129];
-##  int id;
-##  int rowcount;
+##  int id, rowcount;
+    int status;
     char *index();
     register char *c;
 
@@ -2708,24 +3108,25 @@ validate_typedata(q, argv, vo)
     /* get corresponding data type associated with field type name */
 ##  repeat retrieve (data_type = alias.trans) 
 ##         where alias.#name = @field_type and alias.type = "TYPEDATA"
-    if (ingres_errno) return(sms_errcode);
+    if (ingres_errno) return(mr_errcode);
 ##  inquire_equel (rowcount = "rowcount")
-    if (rowcount != 1) return(SMS_TYPE);
+    if (rowcount != 1) return(MR_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
-##     inquire_equel (rowcount = "rowcount")
-       if (rowcount != 1) return(SMS_USER);
-
+       status = name_to_id(name, data_type, &id);
+       if (status && (status == MR_NO_MATCH || status == MR_NOT_UNIQUE))
+         return(MR_USER);
+       if (status) return(status);
     } else if (!strcmp(data_type, "list")) {
        /* LIST */
-##     repeat retrieve (id = list.list_id) where list.#name = @name
-##     inquire_equel (rowcount = "rowcount")
-       if (rowcount != 1) {
+       status = name_to_id(name, data_type, &id);
+       if (status && status == MR_NOT_UNIQUE)
+         return(MR_LIST);
+       if (status == MR_NO_MATCH) {
            /* 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.
@@ -2735,40 +3136,39 @@ validate_typedata(q, argv, vo)
                name = vo->idfield;
 ##             repeat retrieve (id = values.value) where values.#name = @name
 ##             inquire_equel(rowcount = "rowcount")
-               if (rowcount != 1) return(SMS_LIST);
+               if (rowcount != 1) return(MR_LIST);
            } else
-             return(SMS_LIST);
-       }
+             return(MR_LIST);
+       } else if (status) return(status);
     } else if (!strcmp(data_type, "machine")) {
        /* MACHINE */
        for (c = name; *c; c++) if (islower(*c)) *c = toupper(*c);
-##      repeat retrieve (id = machine.mach_id) where machine.#name = @name
-##      inquire_equel (rowcount = "rowcount")
-       if (rowcount != 1) return(SMS_MACHINE);
-
+       status = name_to_id(name, data_type, &id);
+       if (status && (status == MR_NO_MATCH || status == MR_NOT_UNIQUE))
+         return(MR_MACHINE);
+       if (status) return(status);
     } else if (!strcmp(data_type, "string")) {
        /* STRING */
-##      range of s is strings
-##      repeat retrieve (id = s.string_id) where s.string = @name
-##      inquire_equel (rowcount = "rowcount")
-       if (rowcount == 0) {
-           if (q->type != APPEND) return(SMS_STRING);
-##          range of v is values
-##          retrieve (id = v.value) where v.#name = "strings_id"
+       status = name_to_id(name, data_type, &id);
+       if (status && status == MR_NOT_UNIQUE)
+         return(MR_STRING);
+       if (status == MR_NO_MATCH) {
+           if (q->type != APPEND && q->type != UPDATE) return(MR_STRING);
+##          retrieve (id = values.value) where values.#name = "strings_id"
            id++;
-##          replace v (value = id) where v.#name = "strings_id"
+##          replace values (value = id) where values.#name = "strings_id"
 ##         append to strings (string_id = id, string = name)
-       }
+       } else if (status) return(status);
     } else if (!strcmp(data_type, "none")) {
        id = 0;
     } else {
-       return(SMS_TYPE);
+       return(MR_TYPE);
     }
 
     /* now set value in argv */
     *(int *)argv[vo->index] = id;
     
-    return (SMS_EXISTS);
+    return (MR_EXISTS);
 ##}
 
 
@@ -2783,35 +3183,12 @@ struct valobj *vo;
     table = vo->table;
     idfield = vo->idfield;
 ##  replace table (modtime = "now") where table.idfield = 0
-    if (ingres_errno) return(sms_errcode);
+    if (ingres_errno) return(mr_errcode);
 ##  inquire_equel (rowcount = "rowcount")
     if (rowcount != 1)
       return(vo->error);
     else
-      return(SMS_EXISTS);
-##}
-
-
-/* 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.
- */
-
-int get_users_id(name)
-char *name;
-##{
-##  int id, rowcount;
-##  char *login;
-
-    login = name;
-
-##  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);
+      return(MR_EXISTS);
 ##}
 
 
This page took 0.196606 seconds and 4 git commands to generate.