]> 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 e8e905902764c019a9871c903157829da8b077af..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);
 }
 
     
@@ -62,9 +62,9 @@ access_login(q, argv, cl)
 ##  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);
 ##}
 
     
@@ -98,29 +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) && flags) ||
         (!strcmp("dmfl", q->shortname))) &&
        (!strcmp("USER", argv[1]))) {
-       if (*(int *)argv[2] == client_id) return(SMS_SUCCESS);
+       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);
 ##}
 
 
@@ -146,21 +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);
 ##}
 
 
@@ -186,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);
 ##}
 
 
@@ -220,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);
 }
 
 
@@ -237,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);
 }
 
 
@@ -261,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);
 ##}
 
 
@@ -296,16 +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(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(MR_SUCCESS);
     else
-      return(SMS_PERM);
+      return(MR_PERM);
 ##}
 
     
@@ -329,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);
     }
 
@@ -344,7 +355,7 @@ setup_ausr(q, argv, cl)
        sprintf(argv[0], "#%s", argv[1]);
     }
 
-    return(SMS_SUCCESS);
+    return(MR_SUCCESS);
 ##}
 
 
@@ -363,32 +374,32 @@ 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 && flag != 4)
-      return(SMS_IN_USE);
+      return(MR_IN_USE);
 
-##  repeat delete nfsquota where nfsquota.users_id = @id
+##  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);
+       return(MR_IN_USE);
     if (ingres_errno)
-       return(sms_errcode);
-    return(SMS_SUCCESS);
+       return(mr_errcode);
+    return(MR_SUCCESS);
 ##}
 
 
@@ -408,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);
 ##}
 
 
@@ -427,11 +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(sms_errcode);
+    if (ingres_errno) return(mr_errcode);
 
     if (!strcmp(strtrim(type), "POP"))
       set_pop_usage(id, -1);
-    return(SMS_SUCCESS);
+    return(MR_SUCCESS);
 ##}
 
 
@@ -449,27 +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(SMS_IN_USE);
+       return(MR_IN_USE);
 
 ##  repeat delete mcmap where mcmap.mach_id = @id
-    if (ingres_errno) return(sms_errcode);
-    return(SMS_SUCCESS);
+    if (ingres_errno) return(mr_errcode);
+    return(MR_SUCCESS);
 ##}
 
 
@@ -486,13 +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);
+       return(MR_IN_USE);
     if (ingres_errno)
-       return(sms_errcode);
-    return(SMS_SUCCESS);
+       return(mr_errcode);
+    return(MR_SUCCESS);
 ##}
 
 
@@ -519,16 +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(sms_errcode);
+           if (ingres_errno) return(mr_errcode);
            sprintf(argv[idx], "%d", ngid);
        } else {
            strcpy(argv[idx], "-1");
        }
     }
 
-    return(SMS_SUCCESS);
+    return(MR_SUCCESS);
 ##}
 
 
@@ -546,38 +560,42 @@ int setup_dlis(q, argv)
 ##  repeat retrieve (flag = any(imembers.member_id where imembers.member_id=@id
 ##                      and imembers.member_type = "LIST"))
     if (flag)
-       return(SMS_IN_USE);
+       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);
+        return(MR_IN_USE);
     if (ingres_errno)
-       return(sms_errcode);
-    return(SMS_SUCCESS);
+       return(mr_errcode);
+    return(MR_SUCCESS);
 ##}
 
 
@@ -596,13 +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);
+       return(MR_IN_USE);
     if (ingres_errno)
-       return(sms_errcode);
-    return(SMS_SUCCESS);
+       return(mr_errcode);
+    return(MR_SUCCESS);
 ##}
 
 
@@ -622,10 +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);
+       return(MR_IN_USE);
     if (ingres_errno)
-       return(sms_errcode);
-    return(SMS_SUCCESS);
+       return(mr_errcode);
+    return(MR_SUCCESS);
 ##}
 
 
@@ -650,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
  **
  **/
 
@@ -660,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];
@@ -672,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
@@ -684,28 +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
-       if (ingres_errno) return(sms_errcode);
+##     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);
 ##}
 
 
@@ -726,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 {
@@ -740,12 +785,12 @@ setup_ufil(q, argv)
             cp2++;
         }
         if (*cp2 == 0) {
-            status = SMS_SUCCESS;
+            status = MR_SUCCESS;
 ##           endretrieve
         }
 ##  }
     if (ingres_errno)
-       return(sms_errcode);
+       return(mr_errcode);
     return(status);
 ##}
 
@@ -762,17 +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
-    if (ingres_errno) return(sms_errcode);
-    return(SMS_SUCCESS);
+    if (ingres_errno) return(mr_errcode);
+    return(MR_SUCCESS);
 ##}
 
 
@@ -790,35 +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(MR_IN_USE);
     if (ingres_errno)
-      return(sms_errcode);
-    return(SMS_SUCCESS);
+      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
-    if (ingres_errno) return(sms_errcode);
-    return(SMS_SUCCESS);
+    if (ingres_errno) return(mr_errcode);
+    return(MR_SUCCESS);
 ##}
 
 
@@ -848,20 +900,18 @@ client *cl;
 ##  char *name;
 
     name = argv[1];
-##  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);
+    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(sms_errcode);
+    if (ingres_errno) return(mr_errcode);
     *(int *)argv[1] = id;
-    return(SMS_SUCCESS);
+    return(MR_SUCCESS);
 ##}
 
 
@@ -888,7 +938,7 @@ set_modtime(q, argv, cl)
 
 ##  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
@@ -913,7 +963,7 @@ set_modtime_by_id(q, argv, cl)
     id = *(int *)argv[0];
 ##  replace table (modtime = "now", modby = who, modwith = entity)
 ##      where table.id_name = id
-    return(SMS_SUCCESS);
+    return(MR_SUCCESS);
 ##}
 
 
@@ -934,7 +984,7 @@ set_finger_modtime(q, argv, cl)
 
 ##  repeat replace u (fmodtime = "now", fmodby = @who, fmodwith = @entity)
 ##      where u.#users_id = @users_id
-    return(SMS_SUCCESS);
+    return(MR_SUCCESS);
 ##}
 
 
@@ -955,7 +1005,7 @@ set_pobox_modtime(q, argv, cl)
 
 ##  repeat replace users (pmodtime = "now", pmodby = @who, pmodwith = @entity)
 ##      where users.#users_id = @users_id
-    return(SMS_SUCCESS);
+    return(MR_SUCCESS);
 ##}
 
 
@@ -977,7 +1027,7 @@ set_uppercase_modtime(q, argv, cl)
 
 ##  replace table (modtime = "now", modby = who, modwith = entity)
 ##      where table.#name = uppercase(name)
-    return(SMS_SUCCESS);
+    return(MR_SUCCESS);
 ##}
 
 
@@ -998,10 +1048,9 @@ set_mach_modtime_by_id(q, argv, cl)
     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);
 ##}
 
 
@@ -1022,10 +1071,9 @@ set_cluster_modtime_by_id(q, argv, cl)
     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);
 ##}
 
 
@@ -1048,7 +1096,7 @@ set_serverhost_modtime(q, argv, cl)
     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);
 ##}
 
 
@@ -1071,7 +1119,7 @@ set_nfsphys_modtime(q, argv, cl)
     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);
 ##}
 
 
@@ -1096,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);
 ##}
 
 
@@ -1119,7 +1167,7 @@ set_zephyr_modtime(q, argv, cl)
 
 ##  repeat replace z (modtime = "now", modby = @who, modwith = @entity)
 ##                    where z.#class = @class
-    return(SMS_SUCCESS);
+    return(MR_SUCCESS);
 ##}
 
 
@@ -1135,38 +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(256);
-       name = argv[i];
        if (id > 0)
-##       repeat retrieve (name = users.login) where users.users_id = @id
-       else {
-           id = -id;
-##         repeat retrieve (name = strings.string) where strings.string_id = @id
-           id = -id;
-       }
-##     inquire_equel(rowcount = "rowcount")
-       if (rowcount != 1) {
-           sprintf(argv[i], "#%d", id);
-       }
+         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);
-    if (ingres_errno) return(sms_errcode);
-    return(SMS_SUCCESS);
-##}
+    return(MR_SUCCESS);
+}
 
 
 /**
@@ -1208,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);
 ##}
 
 
@@ -1228,55 +1266,42 @@ 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(256);
-           name = argv[4];
            if (sid > 0)
-##           repeat retrieve (name = users.login) where users.users_id = @sid
-           else {
-             sid = -sid;
-##           repeat retrieve (name = strings.string) 
-##               where strings.string_id = @sid
-             sid = -sid;
-           }
-##         inquire_equel(rowcount = "rowcount")
-           if (rowcount != 1)
-             sprintf(name, "#%d", sid);
+             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 */
@@ -1287,8 +1312,8 @@ followup_gpob(q, sq, v, action, actarg, cl)
     }
 
     sq_destroy(sq);
-    return (SMS_SUCCESS);
-##}
+    return (MR_SUCCESS);
+}
 
 
 /* followup_glin: fix the ace_name in argv[8].  argv[7] will contain the
@@ -1304,59 +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(256);
        if (id > 0)
-##       repeat retrieve (name = users.login) where users.users_id = @id
-       else {
-         id = -id;
-##       repeat retrieve (name = strings.string) where strings.string_id = @id
-         id = -id;
-       }
-##     inquire_equel(rowcount = "rowcount")
-       if (rowcount != 1)
-         sprintf(argv[i], "#%d", id);
+         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);
@@ -1373,16 +1384,18 @@ followup_glin(q, sq, v, action, actarg, cl)
     }
 
     sq_destroy(sq);
-    return (SMS_SUCCESS);
-##}
+    return (MR_SUCCESS);
+}
 
 
-/* followup_gnfq: Fix the directory name & modby fields
+/* followup_gqot: Fix the entity name, directory name & modby fields
  *   argv[0] = filsys_id
- *   argv[2] = ascii(quota)
+ *   argv[1] = type
+ *   argv[2] = entity_id
+ *   argv[3] = ascii(quota)
  */
 
-followup_gnfq(q, sq, v, action, actarg, cl)
+followup_gqot(q, sq, v, action, actarg, cl)
     struct query *q;
     register struct save_queue *sq;
     struct validate *v;
@@ -1394,12 +1407,37 @@ followup_gnfq(q, sq, v, action, actarg, cl)
     char **argv, *malloc();
 ##  int id, rowcount;
 ##  char *name, *label;
+    int status, idx;
 
+    if (!strcmp(q->name, "get_quota") ||
+       !strcmp(q->name, "get_quota_by_filesys"))
+      idx = 4;
+    else
+      idx = 3;
     while (sq_get_data(sq, &argv)) {
-       id = atoi(argv[3]);
-       free(argv[3]);
-       argv[3] = malloc(256);
-       name = argv[3];
+       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
@@ -1408,62 +1446,97 @@ followup_gnfq(q, sq, v, action, actarg, cl)
        }
 ##     inquire_equel(rowcount = "rowcount")
        if (rowcount != 1) {
-           sprintf(argv[3], "#%d", id);
+           sprintf(argv[idx], "#%d", id);
        }
 
-       id = atoi(argv[6]);
-       free(argv[6]);
-       argv[6] = malloc(256);
-       name = argv[6];
+       id = atoi(argv[idx+3]);
        if (id > 0)
-##       repeat retrieve (name = users.login) where users.users_id = @id
-       else {
-           id = -id;
-##         repeat retrieve (name = strings.string) where strings.string_id = @id
-           id = -id;
-       }
-##     inquire_equel(rowcount = "rowcount")
-       if (rowcount != 1) {
-           sprintf(argv[6], "#%d", id);
-       }
+         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(SMS_SUCCESS);
+    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]);
+    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
-    if (ingres_errno) return(sms_errcode);
-    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:
  */
 
@@ -1474,54 +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(256);
        if (id > 0)
-##       repeat retrieve (name = users.login) where users.users_id = @id
-       else {
-         id = -id;
-##       repeat retrieve (name = strings.string) where strings.string_id = @id
-         id = -id;
-       }
-##     inquire_equel(rowcount = "rowcount")
-       if (rowcount != 1)
-         sprintf(argv[i], "#%d", id);
+         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 */
@@ -1533,8 +1592,8 @@ followup_gzcl(q, sq, v, action, actarg, cl)
        free(argv);
     }
     sq_destroy(sq);
-    return(SMS_SUCCESS);
-##}
+    return(MR_SUCCESS);
+}
 
 
 /* followup_gsha:
@@ -1547,53 +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(256);
        if (id > 0)
-##       repeat retrieve (name = users.login) where users.users_id = @id
-       else {
-         id = -id;
-##       repeat retrieve (name = strings.string) where strings.string_id = @id
-         id = -id;
-       }
-##     inquire_equel(rowcount = "rowcount")
-       if (rowcount != 1)
-         sprintf(argv[4], "#%d", id);
+         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);
@@ -1604,8 +1649,8 @@ followup_gsha(q, sq, v, action, actarg, cl)
        free(argv);
     }
     sq_destroy(sq);
-    return(SMS_SUCCESS);
-##}
+    return(MR_SUCCESS);
+}
 
 
 \f
@@ -1625,37 +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(sms_errcode);
+    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")) {
        if (index(box, '/') || index(box, '|'))
-         return(SMS_BAD_CHAR);
-##      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"
+         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" */ {
@@ -1665,8 +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"
-    if (ingres_errno) return(sms_errcode);
-    return(SMS_SUCCESS);
+    if (ingres_errno) return(mr_errcode);
+    return(MR_SUCCESS);
 ##}
 
 
@@ -1684,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 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;
@@ -1699,14 +1744,13 @@ get_list_info(q, aargv, cl, action, actarg)
        sq_save_data(sq, id);
        rowcount++;
 ##  }
-    if (ingres_errno) return(sms_errcode);
+    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)
@@ -1720,57 +1764,46 @@ 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(sms_errcode);
+       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);
 
+       argv[11] = malloc(0);
        if (modby_id > 0)
-##       repeat retrieve (modby = users.login) where users.users_id = @modby_id
-       else {
-           modby_id = -modby_id;
-##          repeat retrieve (modby = strings.string) 
-##             where strings.string_id = @modby_id
-           modby_id = -modby_id;
-       }
-##     inquire_equel(rowcount = "rowcount")
-       if (rowcount != 1)
-         sprintf(modby, "#%d", modby_id);
-       if (ingres_errno) return(sms_errcode);
+         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);
-    if (ingres_errno) return(sms_errcode);
-##  repeat replace tblstats (retrieves = tblstats.retrieves + 1)
-##     where tblstats.#table = "list"
-
-    return (SMS_SUCCESS);
+    if (ingres_errno) return(mr_errcode);
+    return (MR_SUCCESS);
 ##}
 
 
@@ -1778,54 +1811,65 @@ get_list_info(q, aargv, cl, action, actarg)
  * how many different ancestors a member is allowed to have.
  */
 
-#define MAXLISTDEPTH   100
+#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;
-##  char *mtype, dtype[9], buf[256], *entity;
-    int ancestors[MAXLISTDEPTH], acount, a;
-    int descendants[MAXLISTDEPTH], dcount, d;
+##  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];
+    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(SMS_EXISTS);
+      return(MR_EXISTS);
     if (!strcasecmp(mtype, "STRING")) {
-##     repeat retrieve (buf = strings.string) where strings.string_id = @mid
-       if (index(buf, '/') || index(buf, '|'))
-         return(SMS_BAD_CHAR);
+       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);
     }
 
     ancestors[0] = lid;
+    aref[0] = 1;
     acount = 1;
-##  repeat retrieve (id = m.list_id)
+##  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(sms_errcode);
+    if (ingres_errno) return(mr_errcode);
     if (acount >= MAXLISTDEPTH) {
-       return(SMS_INTERNAL);
+       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)
+##     repeat retrieve (id = m.member_id, dtype = m.member_type,
+##                      ref = m.ref_count)
 ##       where m.list_id = @mid {
            switch (dtype[0]) {
            case 'L':
@@ -1844,15 +1888,16 @@ int add_member_to_list(q, argv, cl)
                error++;
 ##             endretrieve
            }
+           dref[dcount] = ref;
            descendants[dcount++] = id;
            if (dcount >= MAXLISTDEPTH) {
                error++;
 ##             endretrieve
            }
 ##     }
-       if (ingres_errno) return(sms_errcode);
+       if (ingres_errno) return(mr_errcode);
        if (error)
-         return(SMS_INTERNAL);
+         return(MR_INTERNAL);
     }
     for (a = 0; a < acount; a++) {
        lid = ancestors[a];
@@ -1860,18 +1905,19 @@ int add_member_to_list(q, argv, cl)
            mid = descendants[d];
            mtype = dtypes[d];
            if (mid == lid && !strcmp(mtype, "LIST")) {
-               return(SMS_LISTLOOP);
+               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+1, direct = 1)
+##               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+1)
+##               replace m (ref_count = m.ref_count+ref)
 ##                          where m.list_id = lid and m.member_id = mid and
 ##                          m.member_type = mtype
            } else {
@@ -1881,7 +1927,7 @@ int add_member_to_list(q, argv, cl)
 ##                                member_type=mtype, ref_count = 1)
                else
 ##               append imembers (list_id=lid, member_id = mid,
-##                                member_type=mtype, ref_count = 1)
+##                                member_type=mtype, ref_count = ref)
                iargv[0] = (char *)lid;
                iargv[1] = mtype;
                iargv[2] = (char *)mid;
@@ -1894,8 +1940,8 @@ int add_member_to_list(q, argv, cl)
     who = cl->client_id;
 ##  repeat replace list (modtime = "now", modby = @who, modwith = @entity)
 ##      where list.#list_id = @lid
-    if (ingres_errno) return(sms_errcode);
-    return(SMS_SUCCESS);
+    if (ingres_errno) return(mr_errcode);
+    return(MR_SUCCESS);
 ##}
 
 
@@ -1907,10 +1953,10 @@ int delete_member_from_list(q, argv, cl)
     char **argv;
     client *cl;
 ##{
-##  int id, lid, mid, cnt, exists, error, who;
+##  int id, lid, mid, cnt, exists, error, who, ref;
 ##  char *mtype, dtype[9], *entity;
-    int ancestors[MAXLISTDEPTH], acount, a;
-    int descendants[MAXLISTDEPTH], dcount, d;
+    int ancestors[MAXLISTDEPTH], aref[MAXLISTDEPTH], acount, a;
+    int descendants[MAXLISTDEPTH], dref[MAXLISTDEPTH], dcount, d;
     char *dtypes[MAXLISTDEPTH];
     char *iargv[3];
 
@@ -1918,29 +1964,34 @@ int delete_member_from_list(q, argv, cl)
     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(sms_errcode);
+    if (ingres_errno) return(mr_errcode);
     if (!exists)
-      return(SMS_NO_MATCH);
+      return(MR_NO_MATCH);
     ancestors[0] = lid;
+    aref[0] = 1;
     acount = 1;
-##  repeat retrieve (id = m.list_id)
+##  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(sms_errcode);
+         if (ingres_errno) return(mr_errcode);
     if (acount >= MAXLISTDEPTH)
-      return(SMS_INTERNAL);
+      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)
+##     repeat retrieve (id = m.member_id, dtype = m.member_type,
+##                      ref = m.ref_count)
 ##       where m.list_id = @mid {
            switch (dtype[0]) {
            case 'L':
@@ -1959,13 +2010,14 @@ int delete_member_from_list(q, argv, cl)
                error++;
 ##             endretrieve
            }
+           dref[dcount] = ref;
            descendants[dcount++] = id;
            if (dcount >= MAXLISTDEPTH)
 ##           endretrieve
 ##     }
-             if (ingres_errno) return(sms_errcode);
+             if (ingres_errno) return(mr_errcode);
        if (error)
-         return(SMS_INTERNAL);
+         return(MR_INTERNAL);
     }
     for (a = 0; a < acount; a++) {
        lid = ancestors[a];
@@ -1973,12 +2025,13 @@ int delete_member_from_list(q, argv, cl)
            mid = descendants[d];
            mtype = dtypes[d];
            if (mid == lid && !strcmp(mtype, "LIST")) {
-               return(SMS_LISTLOOP);
+               return(MR_LISTLOOP);
            }
 ##         repeat retrieve (cnt = m.ref_count)
 ##             where m.list_id = @lid and m.member_id = @mid
 ##               and m.member_type = @mtype
-           if (cnt <= 1) {
+           ref = aref[a] * dref[d];
+           if (cnt <= ref) {
                iargv[0] = (char *)lid;
                iargv[1] = mtype;
                iargv[2] = (char *)mid;
@@ -1987,11 +2040,11 @@ int delete_member_from_list(q, argv, cl)
 ##                 m.member_type = mtype
                incremental_clear_after();
            } else if (a == 0 && d == 0) {
-##             replace m (ref_count = m.ref_count-1, direct = 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-1)
+##             replace m (ref_count = m.ref_count-ref)
 ##                 where m.list_id = lid and m.member_id = mid and
 ##                 m.member_type = mtype
            }
@@ -2002,8 +2055,8 @@ int delete_member_from_list(q, argv, cl)
     who = cl->client_id;
 ##  repeat replace list (modtime = "now", modby = @who, modwith = @entity)
 ##      where list.#list_id = @lid
-    if (ingres_errno) return(sms_errcode);
-    return(SMS_SUCCESS);
+    if (ingres_errno) return(mr_errcode);
+    return(MR_SUCCESS);
 ##}
 
 
@@ -2039,14 +2092,13 @@ 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 imembers
 ##     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++;
        }
     }
@@ -2058,10 +2110,10 @@ int get_ace_use(q, argv, cl, action, actarg)
 ##     }
        /* 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++;
     }
 
@@ -2072,17 +2124,17 @@ int get_ace_use(q, argv, cl, action, actarg)
 ##     }
        /* 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 (ingres_errno) return(sms_errcode);
-    if (!found) return(SMS_NO_MATCH);
-    return(SMS_SUCCESS);
+    if (ingres_errno) return(mr_errcode);
+    if (!found) return(MR_NO_MATCH);
+    return(MR_SUCCESS);
 ##}
 
 
@@ -2156,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);
 ##}
 
 
@@ -2228,9 +2280,9 @@ int get_lists_of_member(q, argv, cl, action, actarg)
 ##    }
     }
 
-    if (ingres_errno) return(sms_errcode);
-    if (!found) return(SMS_NO_MATCH);
-    return(SMS_SUCCESS);
+    if (ingres_errno) return(mr_errcode);
+    if (!found) return(MR_NO_MATCH);
+    return(MR_SUCCESS);
 ##}
 
 
@@ -2270,55 +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();
+
+##  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 and m.direct = 1
+##             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(sms_errcode);
+    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 and m.direct = 1
+##             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(sms_errcode);
+    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 and m.direct = 1
+##             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(sms_errcode);
+    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 and m.direct = 1
+##             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(sms_errcode);
+    if (ingres_errno) return(mr_errcode);
 
-    return(SMS_SUCCESS);
+    return(MR_SUCCESS);
 ##}
 
 
@@ -2341,10 +2439,10 @@ int count_members_of_list(q, argv, cl, action, actarg)
 ##  repeat retrieve (ct = count(imembers.list_id
 ##                             where imembers.list_id = @list and
 ##                                   imembers.direct = 1))
-    if (ingres_errno) return(sms_errcode);
+    if (ingres_errno) return(mr_errcode);
     sprintf(countbuf, "%d", ct);
     (*action)(1, rargv, actarg);
-    return(SMS_SUCCESS);
+    return(MR_SUCCESS);
 ##}
 
 
@@ -2410,13 +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(sms_errcode);
+    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);
 ##}
 
 
@@ -2458,21 +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(sms_errcode);
+    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)
@@ -2501,34 +2595,34 @@ register_user(q, argv, cl)
 
     /* find user */
 ##  repeat retrieve (users_id = u.#users_id)
-##     where u.#uid = @uid and (u.status = 0 or u.status = 5)
+##     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 and
 ##                             u.#users_id != users_id))
-    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(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(sms_errcode);
+    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);
@@ -2539,9 +2633,9 @@ register_user(q, argv, cl)
 ##                   pmodwith=@entity)
 ##     where u.#users_id = @users_id
 ##  inquire_equel(rowcount = "rowcount");
-    if (ingres_errno) return(sms_errcode);
+    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,
            strtrim(machname));
@@ -2549,14 +2643,14 @@ register_user(q, argv, cl)
 
     /* 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(sms_errcode);
+    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,
@@ -2564,10 +2658,10 @@ register_user(q, argv, cl)
 ##                     acl_type = "USER", acl_id = @users_id, modtime = "now",
 ##                     modby = @who, modwith = @entity)
 ##     where values.name = "gid"
-    if (ingres_errno) return(sms_errcode);
+    if (ingres_errno) return(mr_errcode);
 ##  inquire_equel(rowcount = "rowcount");
     if (rowcount != 1)
-      return(SMS_INTERNAL);
+      return(MR_INTERNAL);
     sprintf(buffer, "l.list_id = %d", list_id);
     incremental_after("list", buffer, 0);
     aargv[0] = (char *) list_id;
@@ -2576,10 +2670,10 @@ register_user(q, argv, cl)
     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(sms_errcode);
+    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");
 
@@ -2597,13 +2691,13 @@ register_user(q, argv, cl)
            m_id = mid;
        }
 ##  }
-    if (ingres_errno) return(sms_errcode);
+    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,
@@ -2614,10 +2708,10 @@ register_user(q, argv, cl)
 ##                        lockertype = "HOMEDIR", modtime = "now",
 ##                        modby = @who, modwith = @entity)
 ##     where values.name = "filsys_id"
-    if (ingres_errno) return(sms_errcode);
+    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);
@@ -2626,40 +2720,44 @@ register_user(q, argv, cl)
 
     /* set quota */
 ##  repeat retrieve (quota = values.value) where values.name = "def_quota"
-    if (ingres_errno) return(sms_errcode);
+    if (ingres_errno) return(mr_errcode);
 ##  inquire_equel(rowcount = "rowcount");
     if (rowcount != 1)
-      return(SMS_NO_QUOTA);
+      return(MR_NO_QUOTA);
     incremental_clear_before();
-##  repeat append nfsquota (#users_id = @users_id, filsys_id = values.value,
-##                         #quota = @quota, phys_id = @pid, modtime = "now",
-##                         modby = @who, modwith = @entity)
+##  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(sms_errcode);
+    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(sms_errcode);
+    if (ingres_errno) return(mr_errcode);
 ##  inquire_equel(rowcount = "rowcount");
     if (rowcount != 1)
-      return(SMS_INTERNAL);
+      return(MR_INTERNAL);
     aargv[0] = login;
-    aargv[1] = login;
-    sprintf(buffer, "nq.users_id = %d and nq.filsys_id = values.value and values.name = \"filsys_id\"", users_id);
-    incremental_after("nfsquota", buffer, aargv);
+    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(sms_errcode);
+    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"
-    if (ingres_errno) return(sms_errcode);
-    return(SMS_SUCCESS);
+##           tblstats.table = "quota"
+    if (ingres_errno) return(mr_errcode);
+    return(MR_SUCCESS);
 ##}
 
 
@@ -2682,12 +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
 
-    if (ingres_errno) return(sms_errcode);
-    return(SMS_SUCCESS);
+    if (ingres_errno) return(mr_errcode);
+    return(MR_SUCCESS);
 ##}
 
 
@@ -2720,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)
@@ -2784,7 +2881,7 @@ validate_fields(q, argv, vo, n)
            break;
 
        case V_SORT:
-           status = SMS_EXISTS;
+           status = MR_EXISTS;
            break;
 
        case V_LOCK:
@@ -2792,12 +2889,12 @@ validate_fields(q, argv, vo, n)
            break;
        }
 
-       if (status != SMS_EXISTS) return(status);
+       if (status != MR_EXISTS) return(status);
        vo++;
     }
 
-    if (ingres_errno) return(sms_errcode);
-    return(SMS_SUCCESS);
+    if (ingres_errno) return(mr_errcode);
+    return(MR_SUCCESS);
 }
 
 
@@ -2829,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);
 }
 
 
@@ -2842,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)
@@ -2887,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)
@@ -2903,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);
 ##}
 
 
@@ -2914,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"))
@@ -2929,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);
 ##}
@@ -2959,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 */
@@ -2982,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;
 
@@ -2996,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.
@@ -3023,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);
 ##}
 
 
@@ -3071,12 +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);
+      return(MR_EXISTS);
 ##}
 
 
This page took 0.195127 seconds and 4 git commands to generate.