[1775] in Moira

home help back first fref pref prev next nref lref last post

Re: container stuff on ttsp -- Sorry, more changes

daemon@ATHENA.MIT.EDU (Qing Dong)
Thu Apr 26 16:30:13 2001

Message-Id: <200104262029.QAA21937@melbourne-city-street.mit.edu>
Date: Thu, 26 Apr 2001 16:24:44 -0400
To: Garry Zacheiss <zacheiss@mit.edu>
From: Qing Dong <dongq@MIT.EDU>
Cc: Garry Zacheiss <zacheiss@mit.edu>, moiradev@mit.edu
In-Reply-To: <200104261717.NAA10775@melbourne-city-street.mit.edu>
Mime-Version: 1.0
Content-Type: text/plain; charset="us-ascii"

When you do a  "EXEC SQL SELECT  name into :name FROM containers", 
the name is padded with spaces, right? I didn't know that, so I will have to
do a "strtrim" to the container names. Here are the new diffs. Hopefully
this is the 
last change I am going to make :).  

Thanks. 

Qing

Index: qaccess.pc
===================================================================
RCS file:
\\dongq-afs\all\athena.mit.edu\astaff\project\moiradev\repository/moira/serv
er/qaccess.pc,v
retrieving revision 2.22
diff -c -r2.22 qaccess.pc
*** qaccess.pc	2001/03/14 20:51:44	2.22
--- qaccess.pc	2001/04/26 20:05:10
***************
*** 619,621 ****
--- 619,684 ----
      return MR_PERM;
  }
  
+ /* access_container - check access for most container operations
+  *
+  * Inputs: argv[0] - cnt_id
+  *	    q - query name	  
+  *          cl - client name
+  *
+  * - check if that client is a member of the access control list
+  * - OR, if the query is add_machine_to_container or
delete_machine_from_container
+  *	check if the client is a memeber of the mem_acl list
+  * - if the query is update_container and the container is to be renamed and
+  *   it is a top-level container, only priviledged users can do it
+  */
+ 
+ int access_container(struct query *q, char *argv[], client *cl)
+ {
+   EXEC SQL BEGIN DECLARE SECTION;
+   int cnt_id, acl_id, memacl_id;
+   char acl_type[CONTAINERS_ACL_TYPE_SIZE],
memacl_type[CONTAINERS_ACL_TYPE_SIZE];
+   char name[CONTAINERS_NAME_SIZE], *newname;
+   EXEC SQL END DECLARE SECTION;
+   int status;
+ 
+   cnt_id = *(int *)argv[0];
+   
+   /* if amcn or dmcn, container id is the second argument */
+   if (strcmp(q->shortname, "amcn") == 0 || strcmp(q->shortname, "dmcn")
== 0)
+ 	cnt_id = *(int *)argv[1];
+ 
+   EXEC SQL SELECT acl_id, acl_type, memacl_id, memacl_type, name
+     INTO :acl_id, :acl_type, :memacl_id, :memacl_type, :name
+     FROM containers
+     WHERE cnt_id = :cnt_id;
+ 
+   if (sqlca.sqlerrd[2] != 1)
+     return MR_INTERNAL;
+ 
+    /* trim off the trailing spaces */
+    strcpy(name, strtrim(name));
+ 
+   /* if the query is update_container and the containers is to be renamed
+    * and it is a top-level container, only dbadmin can do it */
+   if (!strcmp(q->shortname, "ucon"))
+   {
+     newname = argv[1];
+     if (strcmp(name, newname) && strchr(name, '/') == NULL)
+       return MR_PERM;
+   }
+ 
+   /* check for client in access control list and return success right 
+    * away if it's there. */
+   if (find_member(acl_type, acl_id, cl))
+     return MR_SUCCESS;
+ 
+   /* If not amcn, dmcn, we lose. */
+   if (strcmp(q->shortname, "amcn") && strcmp(q->shortname, "dmcn"))
+     return MR_PERM;
+ 
+   if (find_member(memacl_type, memacl_id, cl))
+     return MR_SUCCESS;
+ 
+   /* Otherwise fail. */
+   return MR_PERM;
+ }


Index: qsetup.pc
===================================================================
RCS file:
\\dongq-afs\all\athena.mit.edu\astaff\project\moiradev\repository/moira/serv
er/qsetup.pc,v
retrieving revision 2.42
diff -c -r2.42 qsetup.pc
*** qsetup.pc	2000/12/19 07:32:46	2.42
--- qsetup.pc	2001/04/26 20:06:18
***************
*** 222,227 ****
--- 222,231 ----
    EXEC SQL DELETE FROM mcmap WHERE mach_id = :id;
    if (dbms_errno)
      return mr_errcode;
+ 
+   EXEC SQL DELETE FROM mcntmap WHERE mach_id = :id;
+   if (dbms_errno)
+     return mr_errcode;
    return MR_SUCCESS;
  }
  
***************
*** 1254,1259 ****
--- 1258,1299 ----
    if (cnt > 0)
      return MR_IN_USE;
  
+   return MR_SUCCESS;
+ }
+ 
+ int setup_dcon(struct query *q, char *argv[], client *cl)
+ {
+   EXEC SQL BEGIN DECLARE SECTION;
+   int id, cnt;
+   char containername[CONTAINERS_NAME_SIZE];
+   EXEC SQL END DECLARE SECTION;
+ 
+   id = *(int *)argv[0];
+   /* check to see if there are machines in this container */
+   EXEC SQL SELECT COUNT(mach_id) INTO :cnt FROM mcntmap
+     WHERE cnt_id = :id;
+   if (cnt > 0)
+     return MR_IN_USE;
+ 
+   /* check to see if there are subcontainers in this container */
+ 
+   /* get the container name */
+   
+   EXEC SQL SELECT name INTO :containername
+     FROM containers
+     WHERE cnt_id = :id; 
+ 
+   /* trim off the trailing spaces */
+    strcpy(containername, strtrim(containername));
+ 
+   EXEC SQL SELECT COUNT(cnt_id) INTO :cnt FROM containers
+     WHERE name LIKE :containername || '/' || '%';
+ 
+   if (cnt > 0)
+     return MR_IN_USE;
+ 
+   if (dbms_errno)
+     return mr_errcode;
    return MR_SUCCESS;
  }
  

Index: qsupport.pc
===================================================================
RCS file:
\\dongq-afs\all\athena.mit.edu\astaff\project\moiradev\repository/moira/serv
er/qsupport.pc,v
retrieving revision 2.32
diff -c -r2.32 qsupport.pc
*** qsupport.pc	2001/04/01 05:31:20	2.32
--- qsupport.pc	2001/04/26 20:08:37
***************
*** 1851,1853 ****
--- 1851,2082 ----
  
    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;
+   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];
+   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));
+ 
+   /* 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;
+       
+       /* 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 */
+   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 (dbms_errno)
+     return mr_errcode;
+     
+   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 = *(int *)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 b.name LIKE '%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[512], tmp [256];
+   char *rargv[1];
+   int found = 0;
+   
+   rargv[0] = subcontainername;
+ 
+   cnt_id = *(int *)argv[0];
+   isrecursive = *(int *)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 name LIKE '%s/%%' and name NOT LIKE '%s/%%/%%' ",
containername, 
+         containername);
+   else
+     sprintf(tmp, "WHERE name LIKE '%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;
+ }



home help back first fref pref prev next nref lref last post