]> andersk Git - moira.git/commitdiff
add get_host_by_owner (ghbo) query
authorzacheiss <zacheiss>
Thu, 30 Mar 2000 22:01:55 +0000 (22:01 +0000)
committerzacheiss <zacheiss>
Thu, 30 Mar 2000 22:01:55 +0000 (22:01 +0000)
server/mr_server.h
server/qsupport.pc
server/queries2.c

index 564244a835aa3589b4cb0093224eadb575d9cb54..b0c0a36cb1394332e83b8ac467545ae84a58ba11 100644 (file)
@@ -237,6 +237,8 @@ int do_user_reservation(struct query *q, char *argv[], client *cl);
 
 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 359237ffe70649435213f3a9e69e4e6363efad2f..129d18cf4a95552d7eca4045546205c2d895808e 100644 (file)
@@ -671,7 +671,7 @@ int get_ace_internal(char *atype, int aid,
   char *rargv[2];
   int found = 0;
   EXEC SQL BEGIN DECLARE SECTION;
-  char name[LIST_NAME_SIZE], *type = atype;
+  char name[MAX_FIELD_WIDTH], *type = atype;
   int id = aid;
   EXEC SQL END DECLARE SECTION;
 
@@ -781,49 +781,214 @@ int get_ace_internal(char *atype, int aid,
     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)
+  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 csr115;
-    if (dbms_errno)
+      EXEC SQL OPEN csr107q;
+      if (dbms_errno)
        return mr_errcode;
-    while (1)
-      {
-       EXEC SQL FETCH csr115 INTO :name;
-       if (sqlca.sqlcode)
-         break;
-       (*action)(2, rargv, actarg);
+      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++;
-      }
-    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);
+    }
+
+  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++;
-      }
-    EXEC SQL CLOSE csr116;
+    }
 
-    if (!found)
-      return MR_NO_MATCH;
-    return MR_SUCCESS;
+  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],
index 9d6dc9c22d080415135824a99ab4a2ab628b0bf6..a8970126dd0bb079238937960f849b7796f96759 100644 (file)
@@ -1185,6 +1185,28 @@ static struct validate gaus_validate = {
   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",
@@ -3740,6 +3762,23 @@ struct query Queries[] = {
     &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,
+  },
+
   {
     /* Q_QGLI - QUALIFIED_GET_LISTS */
     "qualified_get_lists",
This page took 0.924574 seconds and 5 git commands to generate.