[1479] in Moira

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

ghbo

daemon@ATHENA.MIT.EDU (Garry Zacheiss)
Thu Mar 23 16:26:28 2000

Message-Id: <200003232126.QAA01008@wing-commander.mit.edu>
To: moiradev@MIT.EDU
Date: Thu, 23 Mar 2000 16:26:21 EST
From: Garry Zacheiss <zacheiss@MIT.EDU>

	Following is an implementation of ghbo (get_host_by_owner), as
perpetually requested by the RCCs.  There'll be three messages: server
side changes, client side changes, and a change to the schema to build
an index on the owner_id in the machine table; the last isn't necessary
but makes "qy ghbo RUSER zacheiss" much more pleasant to run.

	Server side first:

Index: mr_server.h
===================================================================
RCS file: /afs/athena.mit.edu/astaff/project/moiradev/repository/moira/server/mr_server.h,v
retrieving revision 1.50
diff -c -r1.50 mr_server.h
*** mr_server.h	2000/01/28 00:03:33	1.50
--- mr_server.h	2000/03/23 21:16:50
***************
*** 237,242 ****
--- 237,244 ----
  
  int get_ace_use(struct query *q, char **argv, client *cl,
  		int (*action)(int, char *[], void *), void *actarg);
+ int get_host_by_owner(struct query *q, char **argv, client *cl,
+ 		int (*action)(int, char *[], void *), void *actarg);
  int qualified_get_lists(struct query *q, char **argv, client *cl,
  			int (*action)(int, char *[], void *), void *actarg);
  int get_members_of_list(struct query *q, char **argv, client *cl,
Index: qsupport.pc
===================================================================
RCS file: /afs/athena.mit.edu/astaff/project/moiradev/repository/moira/server/qsupport.pc,v
retrieving revision 2.22
diff -c -r2.22 qsupport.pc
*** qsupport.pc	2000/03/19 19:42:40	2.22
--- qsupport.pc	2000/03/23 21:18:12
***************
*** 671,677 ****
    char *rargv[2];
    int found = 0;
    EXEC SQL BEGIN DECLARE SECTION;
!   char name[LIST_NAME_SIZE], *type = atype;
    int id = aid;
    EXEC SQL END DECLARE SECTION;
  
--- 671,677 ----
    char *rargv[2];
    int found = 0;
    EXEC SQL BEGIN DECLARE SECTION;
!   char name[MACHINE_NAME_SIZE], *type = atype;
    int id = aid;
    EXEC SQL END DECLARE SECTION;
  
***************
*** 781,828 ****
      SELECT name FROM machine m, hostaccess ha
      WHERE m.mach_id = ha.mach_id AND ha.acl_type = :type
      AND ha.acl_id = :id;
!     if (dbms_errno)
  	return mr_errcode;
!     EXEC SQL OPEN csr115;
!     if (dbms_errno)
  	return mr_errcode;
!     while (1)
!       {
! 	EXEC SQL FETCH csr115 INTO :name;
! 	if (sqlca.sqlcode)
! 	  break;
! 	(*action)(2, rargv, actarg);
  	found++;
!       }
!     EXEC SQL CLOSE csr115;
  
!     rargv[0] = "ZEPHYR";
!     EXEC SQL DECLARE csr116 CURSOR FOR
!       SELECT class FROM zephyr z
!       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;
!     if (dbms_errno)
!       return mr_errcode;
!     EXEC SQL OPEN csr116;
!     if (dbms_errno)
!       return mr_errcode;
!     while (1)
!       {
! 	EXEC SQL FETCH csr116 INTO :name;
! 	if (sqlca.sqlcode)
! 	  break;
! 	(*action)(2, rargv, actarg);
  	found++;
!       }
!     EXEC SQL CLOSE csr116;
  
!     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
--- 781,993 ----
      SELECT name FROM machine m, hostaccess ha
      WHERE m.mach_id = ha.mach_id AND ha.acl_type = :type
      AND ha.acl_id = :id;
!   if (dbms_errno)
!     return mr_errcode;
!   EXEC SQL OPEN csr115;
!   if (dbms_errno)
!     return mr_errcode;
!   while (1)
!     {
!       EXEC SQL FETCH csr115 INTO :name;
!       if (sqlca.sqlcode)
! 	break;
!       (*action)(2, rargv, actarg);
!       found++;
!     }
!   EXEC SQL CLOSE csr115;
! 
!   rargv[0] = "MACHINE";
!   EXEC SQL DECLARE csr115a CURSOR FOR
!     SELECT name FROM machine m
!     WHERE m.owner_type = :type
!     AND m.owner_id = :id;
!   if (dbms_errno)
!     return mr_errcode;
!   EXEC SQL OPEN csr115a;
!   if (dbms_errno)
!     return mr_errcode;
!   while (1)
!     {
!       EXEC SQL FETCH csr115a INTO :name;
!       if (sqlca.sqlcode)
! 	break;
!       (*action)(2, rargv, actarg);
!       found++;
!     }
!   EXEC SQL CLOSE csr115a;
! 
!   rargv[0] = "ZEPHYR";
!   EXEC SQL DECLARE csr116 CURSOR FOR
!     SELECT class FROM zephyr z
!     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;
!   if (dbms_errno)
!     return mr_errcode;
!   EXEC SQL OPEN csr116;
!   if (dbms_errno)
!     return mr_errcode;
!   while (1)
!     {
!       EXEC SQL FETCH csr116 INTO :name;
!       if (sqlca.sqlcode)
! 	break;
!       (*action)(2, rargv, actarg);
!       found++;
!     }
!   EXEC SQL CLOSE csr116;
!   
!   if (!found)
!     return MR_NO_MATCH;
!   return MR_SUCCESS;
! }
! 
! /* ghbo_internal */
! int ghbo_internal(char *atype, int aid,
! 		  int (*action)(int, char *[], void *), void *actarg)
! {
!   char *rargv[1];
!   int found = 0;
!   EXEC SQL BEGIN DECLARE SECTION;
!   char name[MACHINE_NAME_SIZE], *type = atype;
!   int id = aid;
!   EXEC SQL END DECLARE SECTION;
! 
!   rargv[0] = name;
!   EXEC SQL DECLARE csr115b CURSOR FOR
!     SELECT name FROM machine m
!     WHERE m.owner_type = :type
!     AND m.owner_id = :id;
!   if (dbms_errno)
!     return mr_errcode;
!   EXEC SQL OPEN csr115b;
!   if (dbms_errno)
!     return mr_errcode;
!   while (1)
!     {
!       EXEC SQL FETCH csr115b INTO :name;
!       if (sqlca.sqlcode)
! 	break;
!       (*action)(1, rargv, actarg);
!       found++;
!     }
!   EXEC SQL CLOSE csr115b;
!   
!   if (!found)
!     return MR_NO_MATCH;
!   return MR_SUCCESS;
! }
! 
! /* get_host_by_owner - like gaus but limited to hosts */
! int get_host_by_owner(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 ghbo_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 csr107q CURSOR FOR
! 	SELECT list_id FROM imembers
! 	WHERE member_type = 'LIST' AND member_id = :aid;
!       if (dbms_errno)
! 	return mr_errcode;
!       EXEC SQL OPEN csr107q;
!       if (dbms_errno)
! 	return mr_errcode;
!       while (1)
! 	{
! 	  EXEC SQL FETCH csr107q INTO :listid;
! 	  if (sqlca.sqlcode)
! 	    break;
! 	  sq_save_unique_data(sq, (void *)listid);
! 	}
!       EXEC SQL CLOSE csr107q;
!       /* now process each one */
!       while (sq_get_data(sq, &id))
! 	{
! 	  if (ghbo_internal("LIST", id, action, actarg) == MR_SUCCESS)
! 	    found++;
! 	}
!     }
! 
!   if (!strcmp(atype, "RUSER"))
!     {
!       EXEC SQL DECLARE csr108q CURSOR FOR
! 	SELECT list_id FROM imembers
! 	WHERE member_type = 'USER' AND member_id = :aid;
!       if (dbms_errno)
  	return mr_errcode;
!       EXEC SQL OPEN csr108q;
!       if (dbms_errno)
  	return mr_errcode;
!       while (1)
! 	{
! 	  EXEC SQL FETCH csr108q INTO :listid;
! 	  if (sqlca.sqlcode)
! 	    break;
! 	  sq_save_data(sq, (void *)listid);
! 	}
!       EXEC SQL CLOSE csr108q;
!       /* now process each one */
!       while (sq_get_data(sq, &id))
! 	{
! 	  if (ghbo_internal("LIST", id, action, actarg) == MR_SUCCESS)
! 	    found++;
! 	}
!       if (ghbo_internal("USER", aid, action, actarg) == MR_SUCCESS)
  	found++;
!     }
  
!   if (!strcmp(atype, "RKERBEROS"))
!     {
!       EXEC SQL DECLARE csr109q CURSOR FOR
! 	SELECT list_id FROM imembers
! 	WHERE member_type = 'KERBEROS' AND member_id = :aid;
!       if (dbms_errno)
! 	return mr_errcode;
!       EXEC SQL OPEN csr109q;
!       if (dbms_errno)
! 	return mr_errcode;
!       while (1)
! 	{
! 	  EXEC SQL FETCH csr109q INTO :listid;
! 	  if (sqlca.sqlcode)
! 	    break;
! 	  sq_save_data(sq, (void *)listid);
! 	}
!       EXEC SQL CLOSE csr109q;
!       /* now process each one */
!       while (sq_get_data(sq, &id))
! 	{
! 	  if (ghbo_internal("LIST", id, action, actarg) == MR_SUCCESS)
! 	    found++;
! 	}
!       if (ghbo_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
Index: queries2.c
===================================================================
RCS file: /afs/athena.mit.edu/astaff/project/moiradev/repository/moira/server/queries2.c,v
retrieving revision 2.68
diff -c -r2.68 queries2.c
*** queries2.c	2000/01/28 00:03:36	2.68
--- queries2.c	2000/03/22 01:41:54
***************
*** 1185,1190 ****
--- 1185,1212 ----
    get_ace_use,
  };
  
+ static char *ghbo_fields[] = {
+   "ace_type", "ace_name",
+   "name",
+ };
+ 
+ static struct valobj ghbo_valobj[] = {
+   {V_TYPE, 0, 0, "gaus", 0, MR_TYPE},
+   {V_TYPEDATA, 1, 0, 0, 0, MR_NO_MATCH},
+ };
+ 
+ static struct validate ghbo_validate = {
+   ghbo_valobj,
+   2,
+   0,
+   0,
+   0,
+   0,
+   access_member,
+   0,
+   get_host_by_owner,
+ };
+ 
  static char *qgli_fields[] = {
    "active", "publicflg", "hidden", "maillist", "grouplist",
    "list",
***************
*** 3738,3743 ****
--- 3760,3782 ----
      2,
      NULL,
      &gaus_validate,
+   },
+ 
+   {
+     /* Q_GHBO - GET_HOST_BY_OWNER */
+     "get_host_by_owner",
+     "ghbo",
+     2,
+     RETRIEVE,
+     0,
+     0,
+     0,
+     ghbo_fields,
+     1,
+     0,
+     2,
+     NULL,
+     &ghbo_validate,
    },
  
    {

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