]> andersk Git - moira.git/blobdiff - server/qsupport.pc
Command line printer manipulation client, and build goo.
[moira.git] / server / qsupport.pc
index c6a1ac6875bc3d5e19006784a955bf65a7ca7edc..3ecbc28ca591f0a26048faafd30a9871bb237c44 100644 (file)
@@ -41,7 +41,9 @@ int qualified_get(struct query *q, char *argv[],
  * if type is POP, then box should be a machine, and its ID should be put in
  * pop_id.  If type is IMAP, then box should be a filesys, and its ID should
  * be put in pop_id.  If type is SMTP, then box should be a string and its
- * ID should be put in box_id.  If type is NONE, then box doesn't matter.
+ * ID should be put in box_id.  If type is EXCHANGE, then box should be a
+ * machine, and its ID should be put in exchange_id.  If type is NONE, then 
+ * box doesn't matter.
  */
 
 int set_pobox(struct query *q, char **argv, client *cl)
@@ -51,6 +53,7 @@ int set_pobox(struct query *q, char **argv, client *cl)
   char *box, potype[USERS_POTYPE_SIZE];
   EXEC SQL END DECLARE SECTION;
   int status;
+  char buffer[256];
 
   box = argv[2];
   user = *(int *)argv[0];
@@ -63,6 +66,9 @@ int set_pobox(struct query *q, char **argv, client *cl)
       (!strcmp(strtrim(potype), "SPLIT") && id))
     set_pop_usage(id, -1);
 
+  sprintf(buffer, "u.users_id = %d", user);
+  incremental_before(USERS_TABLE, buffer, 0);
+
   if (!strcmp(argv[1], "POP"))
     {
       status = name_to_id(box, MACHINE_TABLE, &id);
@@ -70,10 +76,20 @@ int set_pobox(struct query *q, char **argv, client *cl)
        return MR_MACHINE;
       else if (status)
        return status;
-      EXEC SQL UPDATE users SET potype = 'POP', pop_id = :id, imap_id = 0
-       WHERE users_id = :user;
+      EXEC SQL UPDATE users SET potype = 'POP', pop_id = :id, imap_id = 0,
+       exchange_id = 0 WHERE users_id = :user;
       set_pop_usage(id, 1);
     }
+  else if (!strcmp(argv[1], "EXCHANGE"))
+    {
+      status = name_to_id(box, MACHINE_TABLE, &id);
+      if (status == MR_NO_MATCH)
+       return MR_MACHINE;
+      else if (status)
+       return status;
+      EXEC SQL UPDATE users SET POTYPE = 'EXCHANGE', exchange_id = :id,
+       pop_id = 0, imap_id = 0 WHERE users_id = :user;
+    }
   else if (!strcmp(argv[1], "SMTP") || !strcmp(argv[1], "SPLIT"))
     {
       if (strchr(box, '/') || strchr(box, '|'))
@@ -104,8 +120,8 @@ int set_pobox(struct query *q, char **argv, client *cl)
        WHERE label = :box AND type = 'IMAP';
       if (sqlca.sqlcode)
        return MR_FILESYS;
-      EXEC SQL UPDATE users SET potype = 'IMAP', imap_id = :id, pop_id = 0
-       WHERE users_id = :user;
+      EXEC SQL UPDATE users SET potype = 'IMAP', imap_id = :id, pop_id = 0,
+       exchange_id = 0 WHERE users_id = :user;
     }
   else /* argv[1] == "NONE" */
     {
@@ -113,6 +129,8 @@ int set_pobox(struct query *q, char **argv, client *cl)
        WHERE users_id = :user;
     }
 
+  incremental_after(USERS_TABLE, buffer, 0);
+
   set_pobox_modtime(q, argv, cl);
   EXEC SQL UPDATE tblstats SET updates = updates + 1, modtime = SYSDATE
     WHERE table_name = 'users';
@@ -121,22 +139,27 @@ int set_pobox(struct query *q, char **argv, client *cl)
   return MR_SUCCESS;
 }
 
-/* set_pobox_pop: Revert to existing POP or IMAP pobox.
+/* set_pobox_pop: Revert to existing POP, IMAP, or EXCHANGE pobox.
  * Also take care of keeping track of the post office usage.
  */
 int set_pobox_pop(struct query *q, char **argv, client *cl)
 {
   EXEC SQL BEGIN DECLARE SECTION;
-  int id, pid, iid, mid;
+  int id, pid, iid, mid, eid;
   char type[USERS_POTYPE_SIZE];
   EXEC SQL END DECLARE SECTION;
+  char buffer[256];
 
   id = *(int *)argv[0];
-  EXEC SQL SELECT potype, pop_id, imap_id INTO :type, :pid, :iid
+  EXEC SQL SELECT potype, pop_id, imap_id, exchange_id
+    INTO :type, :pid, :iid, :eid
     FROM users WHERE users_id = :id;
-  if (sqlca.sqlerrd[2] == 0 || (pid == 0 && iid == 0))
+  if (sqlca.sqlerrd[2] == 0 || (pid == 0 && iid == 0 && eid == 0))
     return MR_MACHINE;
 
+  sprintf(buffer, "u.users_id = %d", id);
+  incremental_before(USERS_TABLE, buffer, 0);
+
   if (pid)
     {
       EXEC SQL SELECT mach_id INTO :mid FROM machine
@@ -147,7 +170,7 @@ int set_pobox_pop(struct query *q, char **argv, client *cl)
       if (!strcmp(strtrim(type), "POP"))
        set_pop_usage(mid, 1);
     }
-  else
+  else if (iid)
     {
       EXEC SQL SELECT filsys_id INTO :mid FROM filesys
        WHERE filsys_id = :iid;
@@ -155,6 +178,16 @@ int set_pobox_pop(struct query *q, char **argv, client *cl)
        return MR_MACHINE;
       EXEC SQL UPDATE users SET potype = 'IMAP' WHERE users_id = :id;
     }
+  else if (eid)
+    {
+      EXEC SQL SELECT mach_id INTO :mid FROM machine
+       WHERE mach_id = :eid;
+      if (sqlca.sqlerrd[2] == 0)
+       return MR_MACHINE;
+      EXEC SQL UPDATE users SET potype = 'EXCHANGE' WHERE users_id = :id;
+    }
+
+  incremental_after(USERS_TABLE, buffer, 0);
 
   set_pobox_modtime(q, argv, cl);
   EXEC SQL UPDATE tblstats SET updates = updates + 1, modtime = SYSDATE
@@ -169,7 +202,7 @@ int set_pobox_pop(struct query *q, char **argv, client *cl)
  * how many different ancestors a member is allowed to have.
  */
 
-#define MAXLISTDEPTH   1024
+#define MAXLISTDEPTH   3072
 
 int add_member_to_list(struct query *q, char **argv, client *cl)
 {
@@ -203,7 +236,7 @@ int add_member_to_list(struct query *q, char **argv, client *cl)
       status = id_to_name(mid, STRINGS_TABLE, &buf);
       if (status)
        return status;
-      if (strchr(buf, '/') || strchr(buf, '|'))
+      if (strchr(buf, '/') || strchr(buf, '|') || strchr(buf, ','))
        {
          free(buf);
          return MR_BAD_CHAR;
@@ -272,6 +305,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;
@@ -328,13 +364,13 @@ int add_member_to_list(struct query *q, char **argv, client *cl)
                {
                  EXEC SQL INSERT INTO imembers
                    (list_id, member_type, member_id, tag, direct, ref_count)
-                   VALUES (:lid, :mtype, :mid, :tag, 1, 1);
+                   VALUES (:lid, :mtype, :mid, :tag, 1, :ref);
                }
              else
                {
                  EXEC SQL INSERT INTO imembers
                    (list_id, member_type, member_id, tag, direct, ref_count)
-                   VALUES (:lid, :mtype, :mid, :tag, 0, 1);
+                   VALUES (:lid, :mtype, :mid, :tag, 0, :ref);
                }
              iargv[0] = (char *)lid;
              iargv[1] = mtype;
@@ -444,6 +480,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;
@@ -784,7 +823,8 @@ int get_ace_internal(char *atype, int aid,
   rargv[0] = "LIST";
   EXEC SQL DECLARE csr113 CURSOR FOR
     SELECT name FROM list
-    WHERE acl_type = :type AND acl_id = :id;
+    WHERE (acl_type = :type AND acl_id = :id)
+    OR (memacl_type = :type AND memacl_id = :id);
   if (dbms_errno)
     return mr_errcode;
   EXEC SQL OPEN csr113;
@@ -865,7 +905,8 @@ int get_ace_internal(char *atype, int aid,
     WHERE z.xmt_type = :type AND z.xmt_id = :id
     OR z.sub_type = :type AND z.sub_id = :id
     OR z.iws_type = :type AND z.iws_id = :id
-    OR z.iui_type = :type AND z.iui_id = :id;
+    OR z.iui_type = :type AND z.iui_id = :id
+    OR z.owner_type = :type AND z.owner_id = :id;
   if (dbms_errno)
     return mr_errcode;
   EXEC SQL OPEN csr116;
@@ -880,7 +921,41 @@ 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;
+
+  rargv[0] = "CONTAINER-MEMACL";
+  EXEC SQL DECLARE csr117d CURSOR FOR
+    SELECT name FROM containers c
+    WHERE c.memacl_type = :type AND c.memacl_id = :id;
+  if (dbms_errno)
+    return mr_errcode;
+  EXEC SQL OPEN csr117d;
+  while (1)
+    {
+      EXEC SQL FETCH csr117d INTO :name;
+      if (sqlca.sqlcode)
+       break;
+      (*action)(2, rargv, actarg);
+      found++;
+    }
+  EXEC SQL CLOSE csr117d;
+
   if (!found)
     return MR_NO_MATCH;
   return MR_SUCCESS;
@@ -1032,12 +1107,159 @@ int get_host_by_owner(struct query *q, char *argv[], client *cl,
   return MR_SUCCESS;
 }
 
+int guas_internal(char *atype, int aid,
+                 int (*action)(int, char *[], void *), void *actarg)
+{
+  char *rargv[1];
+  int found = 0;
+  EXEC SQL BEGIN DECLARE SECTION;
+  char login[USERS_LOGIN_SIZE], *type = atype;
+  int id = aid;
+  EXEC SQL END DECLARE SECTION;
+
+  rargv[0] = login;
+  EXEC SQL DECLARE csr115sp CURSOR FOR
+    SELECT login FROM users u
+    WHERE u.sponsor_type = :type
+    AND u.sponsor_id = :id;
+  if (dbms_errno)
+    return mr_errcode;
+  EXEC SQL OPEN csr115sp;
+  if (dbms_errno)
+    return mr_errcode;
+  while (1)
+    {
+      EXEC SQL FETCH csr115sp INTO :login;
+      if (sqlca.sqlcode)
+       break;
+      (*action)(1, rargv, actarg);
+      found++;
+    }
+  EXEC SQL CLOSE csr115sp;
+  
+  if (!found)
+    return MR_NO_MATCH;
+  return MR_SUCCESS;
+}
+
+/* get_user_account_by_sponsor - like gaus but limited to user accounts */
+int get_user_account_by_sponsor(struct query *q, char *argv[], client *cl,
+                               int (*action)(int, char *[], void *),
+                               void *actarg)
+{
+  int found = 0;
+  EXEC SQL BEGIN DECLARE SECTION;
+  char *atype;
+  int aid, listid, id;
+  EXEC SQL END DECLARE SECTION;
+  struct save_queue *sq;
+
+  atype = argv[0];
+  aid = *(int *)argv[1];
+  if (!strcmp(atype, "LIST") || !strcmp(atype, "USER") ||
+      !strcmp(atype, "KERBEROS"))
+    return guas_internal(atype, aid, action, actarg);
+
+  sq = sq_create();
+  if (!strcmp(atype, "RLIST"))
+    {
+      sq_save_data(sq, (void *)aid);
+      /* get all the list_id's of containing lists */
+      EXEC SQL DECLARE csr107sp CURSOR FOR
+       SELECT list_id FROM imembers
+       WHERE member_type = 'LIST' AND member_id = :aid;
+      if (dbms_errno)
+       return mr_errcode;
+      EXEC SQL OPEN csr107sp;
+      if (dbms_errno)
+       return mr_errcode;
+      while (1)
+       {
+         EXEC SQL FETCH csr107sp INTO :listid;
+         if (sqlca.sqlcode)
+           break;
+         sq_save_unique_data(sq, (void *)listid);
+       }
+      EXEC SQL CLOSE csr107sp;
+      /* now process each one */
+      while (sq_get_data(sq, &id))
+       {
+         if (guas_internal("LIST", id, action, actarg) == MR_SUCCESS)
+           found++;
+       }
+    }
+
+  if (!strcmp(atype, "RUSER"))
+    {
+      EXEC SQL DECLARE csr108sp CURSOR FOR
+       SELECT list_id FROM imembers
+       WHERE member_type = 'USER' AND member_id = :aid;
+      if (dbms_errno)
+       return mr_errcode;
+      EXEC SQL OPEN csr108sp;
+      if (dbms_errno)
+       return mr_errcode;
+      while (1)
+       {
+         EXEC SQL FETCH csr108sp INTO :listid;
+         if (sqlca.sqlcode)
+           break;
+         sq_save_data(sq, (void *)listid);
+       }
+      EXEC SQL CLOSE csr108sp;
+      /* now process each one */
+      while (sq_get_data(sq, &id))
+       {
+         if (guas_internal("LIST", id, action, actarg) == MR_SUCCESS)
+           found++;
+       }
+      if (guas_internal("USER", aid, action, actarg) == MR_SUCCESS)
+       found++;
+    }
+
+  if (!strcmp(atype, "RKERBEROS"))
+    {
+      EXEC SQL DECLARE csr109sp CURSOR FOR
+       SELECT list_id FROM imembers
+       WHERE member_type = 'KERBEROS' AND member_id = :aid;
+      if (dbms_errno)
+       return mr_errcode;
+      EXEC SQL OPEN csr109sp;
+      if (dbms_errno)
+       return mr_errcode;
+      while (1)
+       {
+         EXEC SQL FETCH csr109sp INTO :listid;
+         if (sqlca.sqlcode)
+           break;
+         sq_save_data(sq, (void *)listid);
+       }
+      EXEC SQL CLOSE csr109sp;
+      /* now process each one */
+      while (sq_get_data(sq, &id))
+       {
+         if (guas_internal("LIST", id, action, actarg) == MR_SUCCESS)
+           found++;
+       }
+      if (guas_internal("KERBEROS", aid, action, actarg) == MR_SUCCESS)
+       found++;
+    }
+
+  sq_destroy(sq);
+  if (dbms_errno)
+    return mr_errcode;
+  if (!found)
+    return MR_NO_MATCH;
+  return MR_SUCCESS;
+}
+
 /* 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,
@@ -1074,6 +1296,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;
@@ -1267,6 +1494,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;
 }
 
@@ -1392,7 +1641,7 @@ int qualified_get_serverhost(struct query *q, char *argv[], client *cl,
 /* 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
- * pobox type ("POP" = POP, "IMAP" or numeric = IMAP)
+ * pobox type ("POP" = POP, "IMAP" or numeric = IMAP, "EXCHANGE" = EXCHANGE)
  */
 
 int register_user(struct query *q, char **argv, client *cl)
@@ -1405,7 +1654,7 @@ int register_user(struct query *q, char **argv, client *cl)
   int ostatus, nstatus, fsidval, popid;
   int npid, tmp;
   int po_exists = 0;
-  static int m_id, def_quota, def_imap_quota, list_id;
+  static int m_id, def_quota, def_imap_quota, list_id, exchange_id;
   EXEC SQL END DECLARE SECTION;
   char buffer[256], *aargv[3];
 
@@ -1417,17 +1666,20 @@ int register_user(struct query *q, char **argv, client *cl)
       EXEC SQL SELECT mach_id INTO :m_id FROM machine
        WHERE name = 'ATHENA.MIT.EDU';
 
-      EXEC SQL SELECT value INTO :def_quota FROM numvalues
-       WHERE name = 'def_quota';
-      if (sqlca.sqlerrd[2] != 1)
-       return MR_NO_QUOTA;
-
-      EXEC SQL SELECT value INTO :def_imap_quota FROM numvalues
-       WHERE name = 'def_imap_quota';
-      if (sqlca.sqlerrd[2] != 1)
-       return MR_NO_QUOTA;
+      EXEC SQL SELECT mach_id INTO :exchange_id FROM machine
+       WHERE name = 'EXCHANGE.MIT.EDU';
     }
 
+  EXEC SQL SELECT value INTO :def_quota FROM numvalues
+    WHERE name = 'def_quota';
+  if (sqlca.sqlerrd[2] != 1)
+    return MR_NO_QUOTA;
+
+  EXEC SQL SELECT value INTO :def_imap_quota FROM numvalues
+    WHERE name = 'def_imap_quota';
+  if (sqlca.sqlerrd[2] != 1)
+    return MR_NO_QUOTA;
+
   entity = cl->entity;
   who = cl->client_id;
 
@@ -1438,7 +1690,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;
@@ -1452,6 +1705,15 @@ int register_user(struct query *q, char **argv, client *cl)
     return mr_errcode;
   if (rowcount > 0)
     return MR_IN_USE;
+
+  /* Remove this check when we're allowing username reuse again. */
+  EXEC SQL SELECT COUNT(login) INTO :rowcount FROM userhistory
+    WHERE login = :login;
+  if (dbms_errno)
+    return mr_errcode;
+  if (rowcount > 0)
+    return MR_IN_USE;
+
   EXEC SQL SELECT COUNT(name) INTO :rowcount FROM list
     WHERE LOWER(name) = :login;
   if (dbms_errno)
@@ -1474,13 +1736,9 @@ 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;
-      EXEC SQL SELECT count(potype) INTO :rowcount FROM users WHERE
-       login = :login AND potype = 'IMAP';
-      if (dbms_errno)
-       return mr_errcode;
-      if (rowcount > 0)
+      else
        po_exists = 1;
     }
   EXEC SQL SELECT COUNT(name) INTO :rowcount FROM alias
@@ -1534,6 +1792,13 @@ int register_user(struct query *q, char **argv, client *cl)
            WHERE users_id = :users_id;
          com_err(whoami, 0, "pobox set to POP:%s", strtrim(machname));
        }         
+      else if (!strcmp(potype, "EXCHANGE"))
+       {
+         EXEC SQL UPDATE users SET potype = 'EXCHANGE',
+           exchange_id = :exchange_id
+           WHERE users_id = :users_id;
+         com_err(whoami, 0, "pobox set to EXCHANGE:EXCHANGE.MIT.EDU");
+       }
       else
        {
       /* Select all IMAP nfsphys entries in order of increasing
@@ -1625,11 +1890,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)
@@ -1644,10 +1910,6 @@ int register_user(struct query *q, char **argv, client *cl)
   com_err(whoami, 0, "set login name to %s", login);
   incremental_after(USERS_TABLE, buffer, 0);
 
-  /* We've just changed the login name in the DB; recache it in case
-     the wrong thing got into the cache earlier. */
-  cache_entry(login, USERS_TABLE, users_id);
-
   /* create filesystem */
   if (set_next_object_id("filsys_id", FILESYS_TABLE, 0))
     return MR_NO_ID;
@@ -1857,3 +2119,275 @@ int get_user_by_reservation(struct query *q, char **argv, client *cl,
 
   return MR_SUCCESS;
 }
+
+int update_container(struct query *q, char *argv[], client *cl)
+{
+  EXEC SQL BEGIN DECLARE SECTION;
+  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];
+  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;
+
+  EXEC SQL SELECT name INTO :name
+    FROM containers
+    WHERE cnt_id = :cnt_id; 
+
+  /* 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))
+  {
+    /* make sure that only the name part of the name has been changed */
+    tmpchar = strrchr(name, '/');
+    /* not a top-level name */
+    if (tmpchar)
+    {
+      cnt = tmpchar - name + 1;
+      /* the parent part of the old and new name should be identical */
+      if (strncmp(name, newname, cnt))
+        return MR_NEW_CONTAINER_NAME;
+    }
+    /* top level name, new name should be a top level name too */
+    else
+    {
+      if (strrchr(newname, '/'))
+        return MR_NEW_CONTAINER_NAME;
+    }
+
+    /* update the name for this container */
+    EXEC SQL UPDATE containers
+      SET name = :newname
+    WHERE cnt_id = :cnt_id;
+
+    if (dbms_errno)
+      return mr_errcode;
+
+    /* get names for its child containers */
+    EXEC SQL DECLARE csr_ucon CURSOR FOR
+      SELECT name, cnt_id FROM containers WHERE name LIKE :name || '/' || '%';
+  
+    EXEC SQL OPEN csr_ucon;
+    if (dbms_errno)
+      return mr_errcode;
+
+    while (1)
+    {
+      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);
+      strcpy(newchildname, newname);
+      strcat(newchildname, tmpchar);
+
+      /* update the name */
+      EXEC SQL UPDATE containers
+        SET name = :newchildname, modtime = SYSDATE, modby = :who, modwith = :entity
+      WHERE cnt_id = :childid;
+
+      if (sqlca.sqlcode)
+        break;
+    }
+  
+    EXEC SQL CLOSE csr_ucon; 
+    if (dbms_errno)
+      return mr_errcode;
+  }
+
+  /* update the remaining fields */
+  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;
+}
+
+int get_machines_of_container(struct query *q, char *argv[], client *cl,
+                       int (*action)(int, char *[], void *), void *actarg)
+{
+  EXEC SQL BEGIN DECLARE SECTION;
+  int cnt_id, isrecursive;
+  char machinename[MACHINE_NAME_SIZE], containername[CONTAINERS_NAME_SIZE];
+  char *qs;
+  EXEC SQL END DECLARE SECTION;
+
+  char querystring[512], tmp [256];
+  char *rargv[2];
+  int found = 0;
+  
+  rargv[0] = machinename;
+  rargv[1] = containername;
+
+  cnt_id = *(int *)argv[0];
+  isrecursive = atoi(argv[1]);
+
+  /* get the container name */
+  
+  EXEC SQL SELECT name INTO :containername
+    FROM containers
+    WHERE cnt_id = :cnt_id; 
+
+  /* trim off the trailing spaces */
+  strcpy(containername, strtrim(containername));
+
+  strcpy(querystring, "SELECT a.name, b.name FROM machine a, containers b, mcntmap c ");
+  strcat(querystring, "WHERE a.mach_id = c.mach_id AND b.cnt_id = c.cnt_id ");
+  
+  if (!isrecursive)
+    sprintf(tmp, "AND b.cnt_id = %d ", cnt_id);
+  else
+    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");
+
+  qs = querystring;
+
+  EXEC SQL PREPARE stmt FROM :qs;
+  if (sqlca.sqlcode)
+    return MR_INTERNAL;
+  EXEC SQL DECLARE curs_gmnm CURSOR FOR stmt;
+  EXEC SQL OPEN curs_gmnm;
+  
+   while (1)
+       {
+         EXEC SQL FETCH curs_gmnm INTO :machinename, :containername;
+         if (sqlca.sqlcode)
+           break;
+         (*action)(2, rargv, actarg);
+         found++;
+       }
+
+  EXEC SQL CLOSE curs_gmnm;
+  if (!found)
+    return MR_NO_MATCH;
+  return MR_SUCCESS;
+}
+
+int get_subcontainers_of_container(struct query *q, char *argv[], client *cl,
+                       int (*action)(int, char *[], void *), void *actarg)
+{
+  EXEC SQL BEGIN DECLARE SECTION;
+  int cnt_id, isrecursive;
+  char containername[CONTAINERS_NAME_SIZE], subcontainername[CONTAINERS_NAME_SIZE];
+  char *qs;
+  EXEC SQL END DECLARE SECTION;
+
+  char querystring[2048], tmp [1024];
+  char *rargv[1];
+  int found = 0;
+  
+  rargv[0] = subcontainername;
+
+  cnt_id = *(int *)argv[0];
+  isrecursive = atoi(argv[1]);
+
+  /* get the container name */
+  
+  EXEC SQL SELECT name INTO :containername
+    FROM containers
+    WHERE cnt_id = :cnt_id; 
+
+  /* trim off the trailing spaces */
+  strcpy(containername, strtrim(containername));
+
+  strcpy(querystring, "SELECT name FROM containers ");
+  
+  if (!isrecursive)
+    sprintf(tmp, "WHERE LOWER(name) LIKE LOWER('%s/%%') and LOWER(name) NOT LIKE LOWER('%s/%%/%%') ",
+           containername, containername);
+  else
+    sprintf(tmp, "WHERE LOWER(name) LIKE LOWER('%s/%%') ", containername);
+
+  strcat(querystring, tmp);
+  strcat(querystring, "ORDER BY name");
+
+  qs = querystring;
+
+  EXEC SQL PREPARE stmt FROM :qs;
+  if (sqlca.sqlcode)
+    return MR_INTERNAL;
+  EXEC SQL DECLARE curs_gsoc CURSOR FOR stmt;
+  EXEC SQL OPEN curs_gsoc;
+  
+   while (1)
+       {
+         EXEC SQL FETCH curs_gsoc INTO :subcontainername;
+         if (sqlca.sqlcode)
+           break;
+         (*action)(1, rargv, actarg);
+         found++;
+       }
+
+  EXEC SQL CLOSE curs_gsoc;
+  if (!found)
+    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 1.855076 seconds and 4 git commands to generate.