]> andersk Git - moira.git/blobdiff - server/qsupport.qc
update for use with new com_err library
[moira.git] / server / qsupport.qc
index 7016993cc1bc049636c260fa21944c9f9d67f60e..ad4f988f763a3f9723fa4926a9cb6e945af75359 100644 (file)
@@ -4,6 +4,8 @@
  *     $Header$
  *
  *     Copyright (C) 1987 by the Massachusetts Institute of Technology
+ *     For copying and distribution information, please see the file
+ *     <mit-copyright.h>.
  *
  */
 
 static char *rcsid_qsupport_qc = "$Header$";
 #endif lint
 
+#include <mit-copyright.h>
 #include "query.h"
 #include "sms_server.h"
 #include <ctype.h>
 
 
 extern char *whoami, *strsave();
+extern int ingres_errno, sms_errcode;
 
 
 /* Specialized Access Routines */
@@ -69,7 +73,8 @@ access_login(q, argv, cl)
  * Inputs: argv[0] - list_id
  *         q - query name
  *         argv[2] - member ID (only for queries "amtl" and  "dmfl")
- *         cl - client name
+ *         argv[7] - group IID (only for query "ulis")
+ *          cl - client name
  *
  * - check that client is a member of the access control list
  * - OR, if the query is add_member_to_list or delete_member_from_list
@@ -81,14 +86,14 @@ access_list(q, argv, cl)
     char *argv[];
     client *cl;
 ##{
-##  int list_id, acl_id, flags, rowcount;
+##  int list_id, acl_id, flags, rowcount, gid;
 ##  char acl_type[9];
     char *client_type;
     int client_id, status;
 
     list_id = *(int *)argv[0];
 ##  repeat retrieve (acl_id = list.#acl_id, acl_type = list.#acl_type,
-##                  flags = list.#public) 
+##                  gid = list.#gid, flags = list.#public) 
 ##        where list.#list_id = @list_id
 ##  inquire_equel(rowcount = "rowcount")
     if (rowcount != 1)
@@ -102,6 +107,11 @@ access_list(q, argv, cl)
     if ((!strcmp("amtl", q->shortname) || !strcmp("dmfl", q->shortname)) &&
        (flags && !strcmp("USER", argv[1]))) {
        if (*(int *)argv[2] == client_id) return(SMS_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);
     }
 
     /* check for client in access control list */
@@ -206,7 +216,7 @@ access_member(q, argv, cl)
       return(access_visible_list(q, &argv[1], cl));
 
     if (!strcmp(argv[0], "USER") || !strcmp(argv[0], "RUSER")) {
-       if (!strcmp(cl->kname.name, argv[1]))
+       if (cl->users_id == *(int *)argv[1])
          return(SMS_SUCCESS);
     }
 
@@ -245,7 +255,7 @@ access_service(q, argv, cl)
 
     name = argv[0];
 ##  repeat retrieve (acl_id = servers.#acl_id, acl_type = servers.#acl_type)
-##     where servers.#name = @name
+##     where servers.#name = uppercase(@name)
 ##  inquire_equel(rowcount = "rowcount")
     if (rowcount > 1)
       return(SMS_PERM);
@@ -345,6 +355,13 @@ int setup_dusr(q, argv)
 ##  int flag, id;
 
     id = *(int *)argv[0];
+
+    /* 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);
+
+##  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"))
     if (flag)
@@ -360,6 +377,10 @@ int setup_dusr(q, argv)
 ##                     servers.acl_type = "USER"))
     if (flag)
        return(SMS_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);
 ##}
@@ -372,18 +393,18 @@ int setup_spop(q, argv)
 struct query *q;
 char **argv;
 ##{
-##  int id, flag;
+##  int id, mid, flag;
 ##  char type[9];
 
     id = *(int *)argv[0];
-##  repeat retrieve (type = u.potype, flag = any(machine.name
-##                                     where machine.mach_id = u.pop_id 
-##                                             and u.pop_id != 0
-##                                             and u.users_id = @id))
+##  repeat retrieve (type = u.potype, mid = u.pop_id,
+##                  flag = any(machine.name where machine.mach_id = u.pop_id 
+##                                  and u.pop_id != 0 and u.users_id = @id))
+##     where u.users_id = @id
     if (!flag)
       return(SMS_MACHINE);
-    if (strcmp(type, "POP"))
-      set_pop_usage(id, 1);
+    if (strcmp(strtrim(type), "POP"))
+      set_pop_usage(mid, 1);
     return(SMS_SUCCESS);
 ##}
 
@@ -401,7 +422,7 @@ char **argv;
 ##  repeat retrieve (type = u.potype, id = u.pop_id)
 ##             where u.users_id = @user
 
-    if (strcmp(type, "POP"))
+    if (!strcmp(strtrim(type), "POP"))
       set_pop_usage(id, -1);
     return(SMS_SUCCESS);
 ##}
@@ -432,8 +453,12 @@ int setup_dmac(q, argv)
 ##  repeat retrieve (flag = any(hostaccess.mach_id where hostaccess.mach_id=@id))
     if (flag)
        return(SMS_IN_USE);
-    else
-       return(SMS_SUCCESS);
+##  repeat retrieve (flag = any(printcap.mach_id where printcap.mach_id=@id))
+    if (flag)
+       return(SMS_IN_USE);
+
+##  repeat delete mcmap where mcmap.mach_id = @id
+    return(SMS_SUCCESS);
 ##}
 
 
@@ -519,13 +544,17 @@ int setup_dlis(q, argv)
     if (flag)
        return(SMS_IN_USE);
 ##  repeat retrieve (flag = any(list.name where list.acl_id=@id and
-##                     list.acl_type = "LIST"))
+##                     list.acl_type = "LIST" and list.list_id != @id))
     if (flag)
        return(SMS_IN_USE);
 ##  repeat retrieve (flag = any(servers.name where servers.acl_id=@id and
 ##                     servers.acl_type = "LIST"))
     if (flag)
        return(SMS_IN_USE);
+##  repeat retrieve (flag=any(hostaccess.acl_id where hostaccess.acl_id=@id and
+##                     hostaccess.acl_type = "LIST"))
+    if (flag)
+       return(SMS_IN_USE);
 ##  repeat retrieve (flag = any(zephyr.class
 ##             where zephyr.xmt_type = "LIST" and zephyr.xmt_id = @id or
 ##                   zephyr.sub_type = "LIST" and zephyr.sub_id = @id or
@@ -550,7 +579,8 @@ int setup_dsin(q, argv)
 ##  char *name;
 
     name = argv[0];
-##  repeat retrieve (flag = any(serverhosts.service where serverhosts.service=@name))
+##  repeat retrieve (flag = any(serverhosts.service 
+##                             where serverhosts.service=uppercase(@name)))
     if (flag)
        return(SMS_IN_USE);
 ##  repeat retrieve (flag = servers.inprogress) where servers.#name = @name
@@ -575,7 +605,7 @@ int setup_dshi(q, argv)
     name = argv[0];
     id = *(int *)argv[1];
 ##  repeat retrieve (flag=serverhosts.inprogress) 
-##     where serverhosts.service=@name and serverhosts.mach_id=@id
+##     where serverhosts.service=uppercase(@name) and serverhosts.mach_id=@id
     if (flag)
        return(SMS_IN_USE);
     else
@@ -633,14 +663,18 @@ setup_afil(q, argv)
 }
 
 
+/* Verify the arguments, depending on the FStype.  Also, if this is an
+ * NFS filesystem, then update any quotas for that filesystem to reflect
+ * the new phys_id.
+ */
+
 setup_ufil(q, argv)
     struct query *q;
     char *argv[];
-{
-    char *type;
-    int mach_id;
-    char *name;
-    char *access;  
+##{
+    int mach_id, status;
+    char *type, *name, *access;  
+##  int fid;
 
     type = argv[2];
     mach_id = *(int *)argv[3];
@@ -648,11 +682,14 @@ setup_ufil(q, argv)
     access = argv[6];
     var_phys_id = 0;
 
-    if (!strcmp(type, "NFS"))
-       return (check_nfs(mach_id, name, access));
-    else
-       return(SMS_SUCCESS);
-}
+    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
+       return(status);
+    } else
+      return(SMS_SUCCESS);
+##}
 
 
 /* Find the NFS physical partition that the named directory is on.
@@ -695,8 +732,8 @@ setup_ufil(q, argv)
 ##}
 
 
-/* setup_dfil: free any quota records associated with a filesystem
- * when it is deleted.
+/* setup_dfil: free any quota records and fsgroup info associated with
+ * a filesystem when it is deleted.  Also adjust the allocation numbers.
  */
 
 setup_dfil(q, argv, cl)
@@ -708,11 +745,14 @@ setup_dfil(q, argv, cl)
 
     id = *(int *)argv[0];
 ##  range of q is nfsquota
-##  repeat replace nfsphys (allocated = nfsphys.allocated - q.quota)
-##     where nfsphys.nfsphys_id = fs.phys_id and 
-##           q.filsys_id = @id and fs.filsys_id = @id
+##  range of fs is filesys
+##  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
 
 ##  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);
 ##}
 
@@ -736,45 +776,6 @@ setup_dnfp(q, argv, cl)
 ##}
 
 
-/* setup_ssif: check to see if lock is already set.  If it is not set or
- * it is set, but this request is turning it off, fine.  Otherwise, give
- * a lock error.  setup_sshi is the same for each serverhost.
- */
-
-setup_ssif(q, argv, cl)
-    struct query  *q;
-    char **argv;
-    client *cl;
-##{
-##  char *service;
-##  int lock;
-
-    service = argv[0];
-##  repeat retrieve (lock = s.inprogress) where s.name = @service
-    if (lock && atoi(argv[2]))
-      return(SMS_LOCKED);
-    return(SMS_SUCCESS);
-##}
-
-
-setup_sshi(q, argv, cl)
-    struct query  *q;
-    char **argv;
-    client *cl;
-##{
-##  char *service;
-##  int lock, mach_id;
-
-    service = argv[0];
-    mach_id = *(int *)argv[1];
-##  repeat retrieve (lock = sh.inprogress) where sh.#mach_id = @mach_id and
-##             sh.#service = @service
-    if (lock && atoi(argv[4]))
-      return(SMS_LOCKED);
-    return(SMS_SUCCESS);
-##}
-
-
 /* setup_dnfq: Remove allocation from nfsphys before deleting quota.
  *   argv[0] = filsys_id
  *   argv[1] = users_id
@@ -893,25 +894,24 @@ set_pobox_modtime(q, argv, cl)
 ##}
 
 
-/* Sets the modtime on a machine record.  The machine name is in argv[0].
- * This routine is different from the generic set_modtime in that the
- * name is uppercased first.
+/* Like set_modtime, but uppercases the name first.
  */
 
-set_mach_modtime(q, argv, cl)
+set_uppercase_modtime(q, argv, cl)
     struct query *q;
     char **argv;
     client *cl;
 ##{
-##  char *host, *entity;
+##  char *name, *entity, *table;
 ##  int who;
 
     entity = cl->entity;
     who = cl->users_id;
+    table = q->rtable;
+    name = argv[0];
 
-    host = argv[0];
-##  repeat replace m (modtime = "now", modby = @who, modwith = @entity)
-##      where m.name = uppercase(@host)
+##  replace table (modtime = "now", modby = who, modwith = entity)
+##      where table.#name = uppercase(name)
     return(SMS_SUCCESS);
 ##}
 
@@ -982,7 +982,7 @@ set_serverhost_modtime(q, argv, cl)
     serv = argv[0];
     id = *(int *)argv[1];
 ##  repeat replace sh (modtime = "now", modby = @who, modwith = @entity)
-##      where sh.service = @serv and sh.mach_id = @id
+##      where sh.service = uppercase(@serv) and sh.mach_id = @id
     return(SMS_SUCCESS);
 ##}
 
@@ -1211,8 +1211,8 @@ followup_gpob(q, sq, v, action, actarg, cl)
 ##}
 
 
-/* followup_glin: fix the acl_name in argv[8].  argv[7] will contain the
- * acl_type: "LIST", "USER", or "NONE".  Decode the id in argv[8] into the
+/* followup_glin: fix the ace_name in argv[8].  argv[7] will contain the
+ * ace_type: "LIST", "USER", or "NONE".  Decode the id in argv[8] into the
  * proper name based on the type, and repace that string in the argv.
  * Also fixes the modby field by called followup_fix_modby.
  */
@@ -1232,7 +1232,7 @@ followup_glin(q, sq, v, action, actarg, cl)
 
     idx = 8;
     if (!strcmp(q->shortname, "gsin"))
-      idx = 11;
+      idx = 12;
 
     while (sq_get_data(sq, &argv)) {
        sms_trim_args(q->vcnt, argv);
@@ -1257,6 +1257,11 @@ followup_glin(q, sq, v, action, actarg, cl)
                strcpy(name, "???");
        } else if (!strcmp(type, "USER")) {
 ##         repeat retrieve (name = users.login) where users.users_id = @id
+##         inquire_equel(rowcount = "rowcount")
+           if (rowcount != 1)
+               strcpy(name, "???");
+       } else if (!strcmp(type, "KERBEROS")) {
+##         repeat retrieve (name = strings.string) where strings.string_id = @id
 ##         inquire_equel(rowcount = "rowcount")
            if (rowcount != 1)
                strcpy(name, "???");
@@ -1399,6 +1404,11 @@ followup_gzcl(q, sq, v, action, actarg, cl)
                  strcpy(name, "???");
            } else if (!strcmp(argv[i], "USER")) {
 ##             repeat retrieve (name = users.login) where users.users_id = @id
+##             inquire_equel(rowcount = "rowcount")
+               if (rowcount != 1)
+                 strcpy(name, "???");
+           } else if (!strcmp(argv[i], "KERBEROS")) {
+##             repeat retrieve (name = strings.string) where strings.string_id = @id
 ##             inquire_equel(rowcount = "rowcount")
                if (rowcount != 1)
                  strcpy(name, "???");
@@ -1460,6 +1470,11 @@ followup_gsha(q, sq, v, action, actarg, cl)
              strcpy(name, "???");
        } else if (!strcmp(argv[1], "USER")) {
 ##         repeat retrieve (name = users.login) where users.users_id = @id
+##         inquire_equel(rowcount = "rowcount")
+           if (rowcount != 1)
+             strcpy(name, "???");
+       } else if (!strcmp(argv[1], "KERBEROS")) {
+##         repeat retrieve (name = strings.string) where strings.string_id = @id
 ##         inquire_equel(rowcount = "rowcount")
            if (rowcount != 1)
              strcpy(name, "???");
@@ -1505,7 +1520,7 @@ int set_pobox(q, argv, cl)
 
 ##  repeat retrieve (id = users.pop_id, potype = users.#potype)
 ##             where users.users_id = @user
-    if (!strcmp(potype, "POP"))
+    if (!strcmp(strtrim(potype), "POP"))
       set_pop_usage(id, -1);
 
     if (!strcmp(argv[1], "POP")) {
@@ -1542,7 +1557,7 @@ int set_pobox(q, argv, cl)
 
 /* get_list_info:  passed a wildcard list name, returns lots of stuff about
  * each list.  This is tricky:  first build a queue of all requested
- * data.  Rest of processing consists of fixing gid, acl_name, and modby.
+ * data.  Rest of processing consists of fixing gid, ace_name, and modby.
  */
 
 get_list_info(q, aargv, cl, action, actarg)
@@ -1601,6 +1616,12 @@ get_list_info(q, aargv, cl, action, actarg)
        } else if (!strcmp(acl_type, "USER")) {
 ##         repeat retrieve (acl_name = users.#login)
 ##             where users.users_id = @acl_id
+##         inquire_equel(rowcount = "rowcount")
+           if (rowcount != 1)
+               strcpy(acl_name, "???");
+       } else if (!strcmp(acl_type, "KERBEROS")) {
+##         repeat retrieve (acl_name = strings.string)
+##             where strings.string_id = @acl_id
 ##         inquire_equel(rowcount = "rowcount")
            if (rowcount != 1)
                strcpy(acl_name, "???");
@@ -1627,15 +1648,15 @@ get_list_info(q, aargv, cl, action, actarg)
 ##}
 
 
-/* get_acl_use - given a type and a name, return a type and a name.
- * The acl_type is one of "LIST", "USER", "RLIST", or "RUSER" in argv[0],
+/* get_ace_use - given a type and a name, return a type and a name.
+ * The ace_type is one of "LIST", "USER", "RLIST", or "RUSER" in argv[0],
  * and argv[1] will contain the ID of the entity in question.  The R*
  * types mean to recursively look at every containing list, not just
  * when the object in question is a direct member.  On return, the
  * usage type will be one of LIST, SERVICE, FILESYS, QUOTA, QUERY, or ZEPHYR.
  */
 
-int get_acl_use(q, argv, cl, action, actarg)
+int get_ace_use(q, argv, cl, action, actarg)
     struct query *q;
     char *argv[];
     client *cl;
@@ -1649,8 +1670,9 @@ int get_acl_use(q, argv, cl, action, actarg)
 
     atype = argv[0];
     aid = *(int *)argv[1];
-    if (!strcmp(atype, "LIST") || !strcmp(atype, "USER")) {
-       return(get_acl_internal(atype, aid, action, actarg));
+    if (!strcmp(atype, "LIST") || !strcmp(atype, "USER") ||
+       !strcmp(atype, "KERBEROS")) {
+       return(get_ace_internal(atype, aid, action, actarg));
     }
 
     sq = sq_create();
@@ -1666,7 +1688,7 @@ int get_acl_use(q, argv, cl, action, actarg)
          }
        /* now process each one */
        while (sq_get_data(sq, &id)) {
-           if (get_acl_internal("LIST", id, action, actarg) == SMS_SUCCESS)
+           if (get_ace_internal("LIST", id, action, actarg) == SMS_SUCCESS)
              found++;
        }
     }
@@ -1686,10 +1708,32 @@ int get_acl_use(q, argv, cl, action, actarg)
          }
        /* now process each one */
        while (sq_get_data(sq, &id)) {
-           if (get_acl_internal("LIST", id, action, actarg) == SMS_SUCCESS)
+           if (get_ace_internal("LIST", id, action, actarg) == SMS_SUCCESS)
              found++;
        }
-       if (get_acl_internal("USER", aid, action, actarg) == SMS_SUCCESS)
+       if (get_ace_internal("USER", aid, action, actarg) == SMS_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)
+             found++;
+       }
+       if (get_ace_internal("KERBEROS", aid, action, actarg) == SMS_SUCCESS)
          found++;
     }
 
@@ -1699,12 +1743,12 @@ int get_acl_use(q, argv, cl, action, actarg)
 ##}
 
 
-/* This looks up a single list or user for acl use.  atype must be "USER"
+/* This looks up a single list or user for ace use.  atype must be "USER"
  * or "LIST", and aid is the ID of the corresponding object.  This is used
- * by get_acl_use above.
+ * by get_ace_use above.
  */
 
-##get_acl_internal(atype, aid, action, actarg)
+##get_ace_internal(atype, aid, action, actarg)
 ##  char *atype;
 ##  int aid;
     int (*action)();
@@ -1798,7 +1842,8 @@ int get_lists_of_member(q, argv, cl, action, actarg)
     aid = *(int *)argv[1];
     if (!strcmp(atype, "LIST") ||
        !strcmp(atype, "USER") ||
-       !strcmp(atype, "STRING")) {
+       !strcmp(atype, "STRING") ||
+       !strcmp(atype, "KERBEROS")) {
       return(glom_internal(atype, aid, action, actarg));
     }
 
@@ -1864,6 +1909,28 @@ int get_lists_of_member(q, argv, cl, action, actarg)
          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 (glom_internal("LIST", id, action, actarg) == SMS_SUCCESS)
+             found++;
+       }
+       if (glom_internal("KERBEROS", aid, action, actarg) == SMS_SUCCESS)
+         found++;
+    }
+
 ##  repeat replace tblstats (retrieves = tblstats.retrieves + 1)
 ##     where tblstats.#table = "members"
     sq_destroy(sq);    
@@ -1974,6 +2041,15 @@ get_members_of_list(q, argv, cl, action, actarg)
 ##             where m.#list_id = @list_id and m.member_type = "STRING"
 ##                   and m.member_id = strings.string_id
 ##             sort by #member_name
+##  {
+        (*action)(2, targv, actarg);
+##  }
+
+    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
+##             sort by #member_name
 ##  {
         (*action)(2, targv, actarg);
 ##  }
@@ -2100,7 +2176,7 @@ int qualified_get_serverhost(q, argv, cl, action, actarg)
     char *rargv[2], buf[32];
 ##  int rowcount, i;
 
-    sprintf(qual, "machine.mach_id = sh.mach_id and sh.service = \"%s\"",
+    sprintf(qual, "machine.mach_id = sh.mach_id and sh.service = uppercase(\"%s\")",
            argv[0]);
     for (i = 1; i < q->argc; i++) {
        if (!strcmp(argv[i], "TRUE")) {
@@ -2168,23 +2244,23 @@ register_user(q, argv, cl)
 
     /* check new login name */
 ##  repeat retrieve (flag = any(u.#login where u.#login = @login))
-    if (flag)
-      return(SMS_IN_USE);
-##  repeat retrieve (flag = any(l.name where l.name = @login))
-    if (flag)
-      return(SMS_IN_USE);
-##  repeat retrieve (flag = any(filesys.#name where filesys.#name = @login))
-    if (flag)
-      return(SMS_IN_USE);
+    if (ingres_errno) return(sms_errcode);
+    if (flag) return(SMS_IN_USE);
+##  repeat retrieve (flag = any(l.#name where l.#name = @login))
+    if (ingres_errno) return(sms_errcode);
+    if (flag) return(SMS_IN_USE);
+##  repeat retrieve (flag = any(filesys.#label where filesys.#label = @login))
+    if (ingres_errno) return(sms_errcode);
+    if (flag) return(SMS_IN_USE);
     com_err(whoami, 0, "new login name OK");
 
     /* choose place for pobox, put in mid */
 ##  repeat retrieve (mid = sh.mach_id, machname = m.name)
-##    where sh.service = "pop" and m.mach_id = sh.mach_id and
-##     sh.value2 - sh.value1 = max(sh.value2-sh.value1 where sh.service="pop")
+##    where sh.service = "POP" and m.mach_id = sh.mach_id and
+##     sh.value2 - sh.value1 = max(sh.value2-sh.value1 where sh.service="POP")
 ##  inquire_equel(rowcount = "rowcount");
     if (rowcount == 0)
-      return(SMS_INTERNAL);
+      return(SMS_NO_POBOX);
 
     /* change login name, set pobox */
 ##  repeat replace u (#login = @login, status = 2, modtime = "now",
@@ -2201,9 +2277,9 @@ register_user(q, argv, cl)
 
     /* create group list */
     if (set_next_object_id("gid", "list"))
-      return(SMS_INTERNAL);
+      return(SMS_NO_ID);
     if (set_next_object_id("list_id", "list"))
-      return(SMS_INTERNAL);
+      return(SMS_NO_ID);
 ##  repeat retrieve (list_id = values.value) where values.name = "list_id"
 ##  inquire_equel(rowcount = "rowcount");
     if (rowcount != 1)
@@ -2214,6 +2290,11 @@ register_user(q, argv, cl)
 ##                     acl_type = "USER", acl_id = @users_id, modtime = "now",
 ##                     modby = @who, modwith = @entity)
 ##     where values.name = "gid"
+##  inquire_equel(rowcount = "rowcount");
+    if (rowcount != 1)
+      return(SMS_INTERNAL);
+##  repeat append members (#list_id = @list_id, member_type = "USER",
+##                        member_id = @users_id)
 ##  inquire_equel(rowcount = "rowcount");
     if (rowcount != 1)
       return(SMS_INTERNAL);
@@ -2234,14 +2315,15 @@ register_user(q, argv, cl)
        }
 ##  }
     if (maxsize == 0)
-      return(SMS_INTERNAL);
+      return(SMS_NO_FILESYS);
 
     /* create filesystem */
     if (set_next_object_id("filsys_id", "filesys"))
-      return(SMS_INTERNAL);
+      return(SMS_NO_ID);
 ##  repeat append filesys (filsys_id = values.value, phys_id = @pid,
 ##                        label = @login, type = "NFS", mach_id = @m_id,
-##                        name = @directory + @login, mount = "/mit/" + @login,
+##                        name = @directory + "/" + @login,
+##                        mount = "/mit/" + @login,
 ##                        access = "w", comments = "User Locker",
 ##                        owner = @users_id, owners = @list_id, createflg = 1,
 ##                        lockertype = "HOMEDIR", modtime = "now",
@@ -2251,16 +2333,16 @@ register_user(q, argv, cl)
     if (rowcount != 1)
       return(SMS_INTERNAL);
     com_err(whoami, 0, "filesys created on mach %d in %s/%s", m_id,
-           trim(directory), login);
+           directory, login);
 
     /* set quota */
 ##  repeat retrieve (quota = values.value) where values.name = "def_quota"
 ##  inquire_equel(rowcount = "rowcount");
     if (rowcount != 1)
-      return(SMS_INTERNAL);
+      return(SMS_NO_QUOTA);
 ##  repeat append nfsquota (#users_id = @users_id, filsys_id = values.value,
-##                         #quota = @quota, modtime = "now", modby = @who,
-##                         modwith = @entity)
+##                         #quota = @quota, phys_id = @pid, modtime = "now",
+##                         modby = @who, modwith = @entity)
 ##     where values.name = "filsys_id"
 ##  inquire_equel(rowcount = "rowcount");
     if (rowcount != 1)
@@ -2273,6 +2355,11 @@ register_user(q, argv, cl)
       return(SMS_INTERNAL);
     com_err(whoami, 0, "quota of %d assigned", quota);
 
+##  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);
 ##}
 
@@ -2298,7 +2385,7 @@ int count;
 
 ##  range of sh is serverhosts
 ##  repeat replace sh (value1 = sh.value1 + @n)
-##         where sh.service = "pop" and sh.#mach_id = @mach_id
+##         where sh.service = "POP" and sh.#mach_id = @mach_id
 
     return(SMS_SUCCESS);
 ##}
@@ -2326,13 +2413,14 @@ validate_row(q, argv, v)
     table = q->rtable;
     name = v->field;
 
-    if (log_flags & LOG_RES)
+    if (log_flags & LOG_VALID)
        /* tell the logfile what we're doing */
        com_err(whoami, 0, "validating row: %s", qual);
     
     /* 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);
@@ -2349,48 +2437,48 @@ validate_fields(q, argv, vo, n)
     while (--n >= 0) {
        switch (vo->type) {
        case V_NAME:
-           if (log_flags & LOG_RES)
+           if (log_flags & LOG_VALID)
                com_err(whoami, 0, "validating %s in %s: %s", 
                    vo->namefield, vo->table, argv[vo->index]);
            status = validate_name(argv, vo);
            break;
 
        case V_ID:
-           if (log_flags & LOG_RES)
+           if (log_flags & LOG_VALID)
                com_err(whoami, 0, "validating %s in %s: %s", 
                    vo->idfield, vo->table, argv[vo->index]);
            status = validate_id(argv, vo);
            break;
 
        case V_DATE:
-           if (log_flags & LOG_RES)
+           if (log_flags & LOG_VALID)
                com_err(whoami, 0, "validating date: %s", argv[vo->index]);
            status = validate_date(argv, vo);
            break;
 
        case V_TYPE:
-           if (log_flags & LOG_RES)
+           if (log_flags & LOG_VALID)
                com_err(whoami, 0, "validating %s type: %s",
                    vo->table, argv[vo->index]);
            status = validate_type(argv, vo);
            break;
 
        case V_TYPEDATA:
-           if (log_flags & LOG_RES)
+           if (log_flags & LOG_VALID)
                com_err(whoami, 0, "validating typed data (%s): %s",
                    argv[vo->index - 1], argv[vo->index]);
            status = validate_typedata(q, argv, vo);
            break;
 
        case V_RENAME:
-           if (log_flags & LOG_RES)
+           if (log_flags & LOG_VALID)
                com_err(whoami, 0, "validating rename %s in %s",
                        argv[vo->index], vo->table);
            status = validate_rename(argv, vo);
            break;
 
        case V_CHAR:
-           if (log_flags & LOG_RES)
+           if (log_flags & LOG_VALID)
              com_err(whoami, 0, "validating chars: %s", argv[vo->index]);
            status = validate_chars(argv[vo->index]);
            break;
@@ -2399,6 +2487,9 @@ validate_fields(q, argv, vo, n)
            status = SMS_EXISTS;
            break;
 
+       case V_LOCK:
+           status = lock_table(vo);
+           break;
        }
 
        if (status != SMS_EXISTS) return(status);
@@ -2411,7 +2502,7 @@ validate_fields(q, argv, vo, n)
 
 /* validate_chars: verify that there are no illegal characters in
  * the string.  Legal characters are printing chars other than 
- * ", *, ?, [ and ].
+ * ", *, ?, \, [ and ].
  */
 static int illegalchars[] = {
     1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* ^@ - ^O */
@@ -2419,7 +2510,7 @@ static int illegalchars[] = {
     0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, /* SPACE - / */
     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, /* 0 - ? */
     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* @ - O */
-    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, /* P - _ */
+    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, /* P - _ */
     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* ` - o */
     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, /* p - ^? */
     1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
@@ -2463,9 +2554,11 @@ validate_id(argv, vo)
     idfield = vo->idfield;
     if (!strcmp(namefield, "uid")) {
 ##    retrieve (id = table.idfield) where table.namefield = int4(name)
+      if (ingres_errno) return(sms_errcode);
 ##    inquire_equel (rowcount = "rowcount")
     } else {
 ##    retrieve (id = table.idfield) where table.namefield = name
+      if (ingres_errno) return(sms_errcode);
 ##    inquire_equel (rowcount = "rowcount")
     }
     if (rowcount != 1) return(vo->error);
@@ -2481,12 +2574,19 @@ validate_name(argv, vo)
 ##  char *table;
 ##  char *namefield;
 ##  int rowcount;
+    register char *c;
 
     name = argv[vo->index];
     table = vo->table;
     namefield = vo->namefield;
+    if (!strcmp(table, "servers") && !strcmp(namefield, "name")) {
+       for (c = name; *c; c++)
+         if (islower(*c))
+           *c = toupper(*c);
+    }
 ##  retrieve (rowcount = countu(table.namefield 
 ##            where table.namefield = name))
+    if (ingres_errno) return(sms_errcode);
     return ((rowcount == 1) ? SMS_EXISTS : vo->error);
 ##}
 
@@ -2503,7 +2603,7 @@ 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_SUCCESS);
+    return(SMS_EXISTS);
 ##}
 
 
@@ -2530,12 +2630,14 @@ struct valobj *vo;
        if (!strcmp(argv[vo->index], argv[vo->index - 1]))
          return(SMS_EXISTS);
 ##     retrieve (id = any(table.namefield where table.namefield = name))
+       if (ingres_errno) return(sms_errcode);
        if (id)
          return(vo->error);
        else
          return(SMS_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);
     else
@@ -2565,6 +2667,7 @@ validate_type(argv, vo)
 ##  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);
 ##}
 
@@ -2592,6 +2695,7 @@ 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);
 ##  inquire_equel (rowcount = "rowcount")
     if (rowcount != 1) return(SMS_TYPE);
 
@@ -2614,8 +2718,9 @@ validate_typedata(q, argv, vo)
             * values.[idfield] for the id.
             */
            if (vo->idfield && !strcmp(argv[0], argv[vo->index])) {
+               set_next_object_id(q->validate->object_id, q->rtable);
                name = vo->idfield;
-##             repeat retrieve (id = values.value+1) where values.#name = @name
+##             repeat retrieve (id = values.value) where values.#name = @name
 ##             inquire_equel(rowcount = "rowcount")
                if (rowcount != 1) return(SMS_LIST);
            } else
@@ -2654,6 +2759,26 @@ validate_typedata(q, argv, vo)
 ##}
 
 
+/* Lock the table named by the validation object */
+
+lock_table(vo)
+struct valobj *vo;
+##{
+##  char *table, *idfield;
+##  int rowcount;
+
+    table = vo->table;
+    idfield = vo->idfield;
+##  replace table (modtime = "now") where table.idfield = 0
+    if (ingres_errno) return(sms_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.
  */
@@ -2683,6 +2808,4 @@ char *name;
 
 sanity_check_database()
 ##{
-##  replace servers (inprogress = 0)
-##  replace serverhosts (inprogress = 0)
 ##}
This page took 0.197919 seconds and 4 git commands to generate.