]> andersk Git - moira.git/blobdiff - server/qsupport.qc
Case-insensitive stuff.
[moira.git] / server / qsupport.qc
index 899bc6a621b0c605baf31c3529b94a01ed2f13f9..5e3638346f3508628b5d3798a85acfc5228157f6 100644 (file)
@@ -329,6 +329,17 @@ 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"))
@@ -365,7 +376,7 @@ int setup_dusr(q, argv)
     if (flag != 0 && flag != 4)
       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"))
@@ -463,6 +474,9 @@ int setup_dmac(q, argv)
 ##  repeat retrieve (flag = any(printcap.mach_id where printcap.mach_id=@id))
     if (flag)
        return(MR_IN_USE);
+##  repeat retrieve (flag = any(printcap.quotaserver where printcap.quotaserver=@id))
+    if (flag)
+       return(MR_IN_USE);
 ##  repeat retrieve (flag = any(palladium.mach_id where palladium.mach_id=@id))
     if (flag)
        return(MR_IN_USE);
@@ -564,6 +578,10 @@ int setup_dlis(q, argv)
 ##                     servers.acl_type = "LIST"))
     if (flag)
        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)
@@ -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(MR_SUCCESS);
-}
+##}
 
 
 /* Verify the arguments, depending on the FStype.  Also, if this is an
@@ -684,13 +708,15 @@ 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, total;
+    char *type, *name;  
+##  int fid, total, who;
+##  char *entity, ftype[32], *access;
 
     type = argv[2];
     mach_id = *(int *)argv[3];
@@ -698,25 +724,33 @@ setup_ufil(q, argv)
     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);
-##     replace nfsquota (phys_id = var_phys_id) where nfsquota.filsys_id = fid
+##     replace quota (phys_id = var_phys_id) where quota.filsys_id = fid
        if (ingres_errno) return(mr_errcode);
        return(status);
     } else if (!strcmp(type, "AFS")) {
        total = 0;
-##     retrieve (total = sum(nfsquota.quota where nfsquota.filsys_id = fid))
+##     retrieve (total = sum(quota.quota where quota.filsys_id = fid
+##                           and quota.phys_id != 0))
        if (ingres_errno) return(mr_errcode);
        if (total != 0) {
-##         delete nfsquota where nfsquota.filsys_id = fid
-           if (ingres_errno) return(mr_errcode);
-##         append nfsquota (quota = total, filsys_id = fid,
-##                          phys_id = 0, users_id = 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 nfsquota (phys_id = 0) where nfsquota.filsys_id = fid
+##     replace quota (phys_id = 0) where quota.filsys_id = fid
        if (ingres_errno) return(mr_errcode);
     }
     return(MR_SUCCESS);
@@ -740,10 +774,6 @@ setup_ufil(q, argv)
     register char *cp1;
     register char *cp2;
 
-    caccess = (isupper(*access)) ? tolower(*access) : *access;
-    if (caccess != 'r' && caccess != 'w' && caccess != 'n')
-      return(MR_FILESYS_ACCESS);
-
     status = MR_NFS;
 ##  range of np is nfsphys
 ##  repeat retrieve (var_phys_id = np.#nfsphys_id, dir = trim(np.#dir))
@@ -777,7 +807,7 @@ setup_dfil(q, argv, cl)
 ##  int id;
 
     id = *(int *)argv[0];
-##  range of q is nfsquota
+##  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 = filesys.phys_id and filesys.filsys_id = @id
@@ -811,24 +841,32 @@ setup_dnfp(q, argv, cl)
 ##}
 
 
-/* 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(mr_errcode);
@@ -1350,12 +1388,14 @@ followup_glin(q, sq, v, action, actarg, cl)
 }
 
 
-/* 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;
@@ -1367,13 +1407,37 @@ followup_gnfq(q, sq, v, action, actarg, cl)
     char **argv, *malloc();
 ##  int id, rowcount;
 ##  char *name, *label;
-    int status;
+    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
@@ -1382,14 +1446,14 @@ 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]);
+       id = atoi(argv[idx+3]);
        if (id > 0)
-         status = id_to_name(id, "USER", &argv[6]);
+         status = id_to_name(id, "USER", &argv[idx+3]);
        else
-         status = id_to_name(-id, "STRING", &argv[6]);
+         status = id_to_name(-id, "STRING", &argv[idx+3]);
        if (status && status != MR_NO_MATCH)
          return(status);
        (*action)(q->vcnt, argv, actarg);
@@ -1402,27 +1466,36 @@ followup_gnfq(q, sq, v, action, actarg, cl)
 ##}
 
 
-/* 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(mr_errcode);
@@ -1430,6 +1503,40 @@ followup_anfq(q, argv, cl)
 ##}
 
 
+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:
  */
 
@@ -1704,7 +1811,7 @@ 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;
@@ -2488,7 +2595,7 @@ 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(MR_NO_MATCH);
@@ -2618,9 +2725,10 @@ register_user(q, argv, cl)
     if (rowcount != 1)
       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(mr_errcode);
 ##  inquire_equel(rowcount = "rowcount");
@@ -2634,9 +2742,10 @@ register_user(q, argv, cl)
     if (rowcount != 1)
       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(mr_errcode);
 
@@ -2646,7 +2755,7 @@ register_user(q, argv, cl)
 ##     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"
+##           tblstats.table = "quota"
     if (ingres_errno) return(mr_errcode);
     return(MR_SUCCESS);
 ##}
This page took 0.462936 seconds and 4 git commands to generate.