]> andersk Git - moira.git/blobdiff - server/qsupport.pc
Don't botch version checks for clients using v2 and v3 glin.
[moira.git] / server / qsupport.pc
index c6bbe15f9e9e424d47986312de2e46e9c72a35b8..fbc893ada2d3a3b2ff87766832050d6a27036c48 100644 (file)
@@ -272,6 +272,9 @@ int add_member_to_list(struct query *q, char **argv, client *cl)
            case 'K':
              dtypes[dcount] = "KERBEROS";
              break;
+           case 'M':
+             dtypes[dcount] = "MACHINE";
+             break;
            default:
              error++;
              break;
@@ -444,6 +447,9 @@ int delete_member_from_list(struct query *q, char **argv, client *cl)
            case 'K':
              dtypes[dcount] = "KERBEROS";
              break;
+           case 'M':
+             dtypes[dcount] = "MACHINE";
+             break;
            default:
              error++;
              break;
@@ -882,7 +888,24 @@ int get_ace_internal(char *atype, int aid,
       found++;
     }
   EXEC SQL CLOSE csr116;
-  
+
+  rargv[0] = "CONTAINER";
+  EXEC SQL DECLARE csr117c CURSOR FOR
+    SELECT name FROM containers c
+    WHERE c.acl_type = :type AND c.acl_id = :id;
+  if (dbms_errno)
+    return mr_errcode;
+  EXEC SQL OPEN csr117c;
+  while (1)
+    {
+      EXEC SQL FETCH csr117c INTO :name;
+      if (sqlca.sqlcode)
+       break;
+      (*action)(2, rargv, actarg);
+      found++;
+    }
+  EXEC SQL CLOSE csr117c;
+
   if (!found)
     return MR_NO_MATCH;
   return MR_SUCCESS;
@@ -1036,10 +1059,11 @@ int get_host_by_owner(struct query *q, char *argv[], client *cl,
 
 /* get_lists_of_member - given a type and a name, return the name and flags
  * of all of the lists of the given member.  The member_type is one of
- * "LIST", "USER", "STRING", "RLIST", "RUSER", or "RSTRING" in argv[0],
- * and argv[1] will contain the ID of the entity in question.  The R*
- * types mean to recursively look at every containing list, not just
- * when the object in question is a direct member.
+ * "LIST", "USER", "STRING", "KERBEROS", "MACHINE", "RLIST", "RUSER", 
+ * "RSTRING", "RKERBEROS", or "RMACHINE" in argv[0], and argv[1] will contain 
+ * the ID of the entity in question.  The R* types mean to recursively look 
+ * at every containing list, not just when the object in question is a direct 
+ * member.
  */
 
 int get_lists_of_member(struct query *q, char *argv[], client *cl,
@@ -1076,6 +1100,11 @@ int get_lists_of_member(struct query *q, char *argv[], client *cl,
       atype = "KERBEROS";
       direct = 0;
     }
+  if (!strcmp(atype, "RMACHINE"))
+    {
+      atype = "MACHINE";
+      direct = 0;
+    }
 
   rargv[0] = name;
   rargv[1] = active;
@@ -1269,6 +1298,28 @@ int get_members_of_list(struct query *q, char *argv[], client *cl,
   if (dbms_errno)
     return mr_errcode;
 
+  targv[0] = "MACHINE";
+  EXEC SQL DECLARE csr123 CURSOR FOR
+    SELECT m.name, s.string FROM machine m, imembers im, strings s
+    WHERE im.list_id = :list_id AND im.member_type = 'MACHINE'
+    AND im.member_id = m.mach_id AND im.direct > :direct
+    AND s.string_id = im.tag ORDER BY 1;
+  if (dbms_errno)
+    return mr_errcode;
+  EXEC SQL OPEN csr123;
+  if (dbms_errno)
+    return mr_errcode;
+  while (1)
+    {
+      EXEC SQL FETCH csr123 INTO :member_name, :tag;
+      if (sqlca.sqlcode)
+       break;
+      (*action)(targc, targv, actarg);
+    }
+  EXEC SQL CLOSE csr123;
+  if (dbms_errno)
+    return mr_errcode;
+
   return MR_SUCCESS;
 }
 
@@ -1440,7 +1491,8 @@ int register_user(struct query *q, char **argv, client *cl)
   /* find user */
   EXEC SQL SELECT users_id, status INTO :users_id, :ostatus
     FROM users
-    WHERE unix_uid = :uid AND (status = 0 OR status = 5 OR status = 6);
+    WHERE unix_uid = :uid AND
+    (status = 0 OR status = 5 OR status = 6 OR status = 9);
 
   if (sqlca.sqlerrd[2] == 0)
     return MR_NO_MATCH;
@@ -1476,7 +1528,7 @@ int register_user(struct query *q, char **argv, client *cl)
        WHERE label = :login || '.po';
       if (dbms_errno)
        return mr_errcode;
-      if ((ostatus == 0) || (tmp != users_id))
+      if ((ostatus == 0 || ostatus == 9) || (tmp != users_id))
        return MR_IN_USE;
       else
        po_exists = 1;
@@ -1623,11 +1675,12 @@ int register_user(struct query *q, char **argv, client *cl)
   sprintf(buffer, "u.users_id = %d", users_id);
   incremental_before(USERS_TABLE, buffer, 0);
   nstatus = 2;
-  if (ostatus == 5 || ostatus == 6)
+  if (ostatus == 5 || ostatus == 6 || ostatus == 9)
     nstatus = 1;
   EXEC SQL UPDATE users SET login = :login, status = :nstatus,
     modtime = SYSDATE, modby = :who, modwith = :entity,
-    pmodtime = SYSDATE, pmodby = :who, pmodwith = :entity
+    pmodtime = SYSDATE, pmodby = :who, pmodwith = :entity,
+    created = SYSDATE, creator = :who
     WHERE users_id = :users_id;
 
   if (dbms_errno)
@@ -1855,23 +1908,29 @@ int get_user_by_reservation(struct query *q, char **argv, client *cl,
 int update_container(struct query *q, char *argv[], client *cl)
 {
   EXEC SQL BEGIN DECLARE SECTION;
-  int cnt_id, acl_id, memacl_id, who;
+  int cnt_id, acl_id, memacl_id, who, flag;
   char name[CONTAINERS_NAME_SIZE], newchildname[CONTAINERS_NAME_SIZE];
   char* newname, *entity, *description, *location, *contact, *acl_type, *memacl_type;
   EXEC SQL END DECLARE SECTION;
   char* tmpchar;
   int cnt, childid;
   char childname[CONTAINERS_NAME_SIZE];
-
-  cnt_id = *(int *)argv[0];
-  newname = argv[1];
-  description = argv[2];
-  location = argv[3];
-  contact = argv[4];
-  acl_type = argv[5];
-  acl_id = *(int *)argv[6];
-  memacl_type = argv[7];
-  memacl_id = *(int *)argv[8];
+  char *qual;
+  int index = 0;
+
+  cnt_id = *(int *)argv[index++];
+  newname = argv[index++];
+
+  if (q->version >= 9)
+    flag = atoi(argv[index++]);
+
+  description = argv[index++];
+  location = argv[index++];
+  contact = argv[index++];
+  acl_type = argv[index++];
+  acl_id = *(int *)argv[index++];
+  memacl_type = argv[index++];
+  memacl_id = *(int *)argv[index++];
   entity = cl->entity;
   who = cl->client_id;
 
@@ -1882,6 +1941,10 @@ int update_container(struct query *q, char *argv[], client *cl)
   /* trim off the trailing spaces */
    strcpy(name, strtrim(name));
 
+   qual = xmalloc(MAX_FIELD_WIDTH);    
+   sprintf(qual, "name = '%s'", name);
+   incremental_before(CONTAINERS_TABLE, qual, argv);
+
   /* if we are renaming the container */
   if (strcmp(name, newname))
   {
@@ -1923,7 +1986,8 @@ int update_container(struct query *q, char *argv[], client *cl)
       EXEC SQL FETCH csr_ucon INTO :childname, :childid;
       if (sqlca.sqlcode)
              break;
-      
+
+      strcpy(childname, strtrim(childname));
       /* concatenate the new parent name with the existing sub-container name
        * we get the sub-containers new name */
       tmpchar = childname + strlen(name);
@@ -1945,15 +2009,30 @@ int update_container(struct query *q, char *argv[], client *cl)
   }
 
   /* update the remaining fields */
-  EXEC SQL UPDATE containers 
-    SET description = NVL(:description, CHR(0)), location = NVL(:location, CHR(0)), 
-      contact = NVL(:contact, CHR(0)), acl_type = :acl_type, acl_id = :acl_id, 
-      memacl_type = :memacl_type, memacl_id = :memacl_id, 
-      modtime = SYSDATE, modby = :who, modwith = :entity
-    WHERE cnt_id = :cnt_id;
+  if (q->version >= 9)
+  {
+       EXEC SQL UPDATE containers
+               SET publicflg= :flag, description = NVL(:description, CHR(0)), location = NVL(:location, CHR(0)),
+                       contact = NVL(:contact, CHR(0)), acl_type = :acl_type, acl_id = :acl_id,
+                       memacl_type = :memacl_type, memacl_id = :memacl_id,
+                       modtime = SYSDATE, modby = :who, modwith = :entity
+               WHERE cnt_id = :cnt_id;
+  }
+  else
+  {
+    EXEC SQL UPDATE containers
+               SET publicflg= :flag, description = NVL(:description, CHR(0)), location = NVL(:location, CHR(0)),
+                       contact = NVL(:contact, CHR(0)), acl_type = :acl_type, acl_id = :acl_id,
+                       memacl_type = :memacl_type, memacl_id = :memacl_id,
+                       modtime = SYSDATE, modby = :who, modwith = :entity
+               WHERE cnt_id = :cnt_id;
+  }
 
   if (dbms_errno)
     return mr_errcode;
+
+  sprintf(qual, "name = '%s'", newname);
+  incremental_after(CONTAINERS_TABLE, qual, argv);
     
   return MR_SUCCESS;
 }
@@ -1975,7 +2054,7 @@ int get_machines_of_container(struct query *q, char *argv[], client *cl,
   rargv[1] = containername;
 
   cnt_id = *(int *)argv[0];
-  isrecursive = *(int *)argv[1];
+  isrecursive = atoi(argv[1]);
 
   /* get the container name */
   
@@ -1992,7 +2071,8 @@ int get_machines_of_container(struct query *q, char *argv[], client *cl,
   if (!isrecursive)
     sprintf(tmp, "AND b.cnt_id = %d ", cnt_id);
   else
-    sprintf(tmp, "AND (b.cnt_id = %d OR b.name LIKE '%s/%%') ", cnt_id, containername);
+    sprintf(tmp, "AND (b.cnt_id = %d OR LOWER(b.name) LIKE LOWER('%s/%%')) ", 
+           cnt_id, containername);
 
   strcat(querystring, tmp);
   strcat(querystring, "ORDER BY b.name, a.name");
@@ -2029,14 +2109,14 @@ int get_subcontainers_of_container(struct query *q, char *argv[], client *cl,
   char *qs;
   EXEC SQL END DECLARE SECTION;
 
-  char querystring[512], tmp [256];
+  char querystring[2048], tmp [1024];
   char *rargv[1];
   int found = 0;
   
   rargv[0] = subcontainername;
 
   cnt_id = *(int *)argv[0];
-  isrecursive = *(int *)argv[1];
+  isrecursive = atoi(argv[1]);
 
   /* get the container name */
   
@@ -2050,10 +2130,10 @@ int get_subcontainers_of_container(struct query *q, char *argv[], client *cl,
   strcpy(querystring, "SELECT name FROM containers ");
   
   if (!isrecursive)
-    sprintf(tmp, "WHERE name LIKE '%s/%%' and name NOT LIKE '%s/%%/%%' ", containername, 
-        containername);
+    sprintf(tmp, "WHERE LOWER(name) LIKE LOWER('%s/%%') and LOWER(name) NOT LIKE LOWER('%s/%%/%%') ",
+           containername, containername);
   else
-    sprintf(tmp, "WHERE name LIKE '%s/%%' ", containername);
+    sprintf(tmp, "WHERE LOWER(name) LIKE LOWER('%s/%%') ", containername);
 
   strcat(querystring, tmp);
   strcat(querystring, "ORDER BY name");
@@ -2080,3 +2160,19 @@ int get_subcontainers_of_container(struct query *q, char *argv[], client *cl,
     return MR_NO_MATCH;
   return MR_SUCCESS;
 }
+
+int set_container_list(struct query *q, char *argv[], client *cl)
+{
+  EXEC SQL BEGIN DECLARE SECTION;
+  int cnt_id, list_id;
+  EXEC SQL END DECLARE SECTION;
+
+  cnt_id = *(int *)argv[0];
+  list_id = *(int *)argv[1];
+
+  EXEC SQL UPDATE containers SET list_id = :list_id WHERE cnt_id = :cnt_id;
+  if (dbms_errno)
+    return mr_errcode;
+
+  return MR_SUCCESS;
+}
This page took 0.045382 seconds and 4 git commands to generate.