Add support for show communities monitoring request
authorJennifer Richards <jennifer@painless-security.com>
Thu, 19 Apr 2018 18:54:39 +0000 (14:54 -0400)
committerJennifer Richards <jennifer@painless-security.com>
Thu, 19 Apr 2018 18:54:39 +0000 (14:54 -0400)
12 files changed:
CMakeLists.txt
Makefile.am
common/tr_comm.c
common/tr_comm_encoders.c [new file with mode: 0644]
common/tr_idp.c
common/tr_idp_encoders.c [new file with mode: 0644]
common/tr_rp.c
include/tr_comm.h
include/tr_idp.h
include/tr_rp.h
tr/tr_trp_mons.c
tr/trmon_main.c

index 442aa97..0985721 100644 (file)
@@ -96,7 +96,7 @@ set(SOURCE_FILES
     trp/trp_upd.c
     trp/trpc.c
     trp/trps.c include/tr_name_internal.h mon/mon_req.c mon/mon_req_encode.c mon/mon_req_decode.c
-        mon/mon_resp.c mon/mon_common.c mon/mon_resp_encode.c mon/mon_resp_decode.c tr/tr_mon.c mon/mons.c include/tr_socket.h common/tr_gss.c include/tr_gss.h common/tr_config_internal.c mon/mons_handlers.c include/mons_handlers.h tr/tr_tid_mons.c tr/tr_tid_mons.c trp/trp_route.c include/trp_route.h trp/trp_rtable_encoders.c trp/trp_route_encoders.c trp/trp_peer.c include/trp_peer.h trp/trp_peer_encoders.c trp/trp_ptable_encoders.c)
+        mon/mon_resp.c mon/mon_common.c mon/mon_resp_encode.c mon/mon_resp_decode.c tr/tr_mon.c mon/mons.c include/tr_socket.h common/tr_gss.c include/tr_gss.h common/tr_config_internal.c mon/mons_handlers.c include/mons_handlers.h tr/tr_tid_mons.c tr/tr_tid_mons.c trp/trp_route.c include/trp_route.h trp/trp_rtable_encoders.c trp/trp_route_encoders.c trp/trp_peer.c include/trp_peer.h trp/trp_peer_encoders.c trp/trp_ptable_encoders.c common/tr_idp_encoders.c common/tr_comm_encoders.c)
 
 # Does not actually build!
 add_executable(trust_router ${SOURCE_FILES})
index 0c7ccba..d88ca77 100644 (file)
@@ -17,8 +17,10 @@ common_srcs = common/tr_name.c \
        common/tr_util.c \
        common/tr_apc.c \
        common/tr_comm.c \
+       common/tr_comm_encoders.c \
        common/tr_rp.c \
        common/tr_idp.c \
+       common/tr_idp_encoders.c \
        common/tr_filter.c \
        common/tr_gss_names.c \
        common/tr_socket.c \
index dd3c304..f8f91df 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, JANET(UK)
+ * Copyright (c) 2012-2018, JANET(UK)
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
diff --git a/common/tr_comm_encoders.c b/common/tr_comm_encoders.c
new file mode 100644 (file)
index 0000000..130f175
--- /dev/null
@@ -0,0 +1,256 @@
+/*
+ * Copyright (c) 2012-2018, JANET(UK)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of JANET(UK) nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include <jansson.h>
+#include <tr_idp.h>
+#include <tr_comm.h>
+#include <tr_util.h>
+#include <tr_debug.h>
+
+/* helper */
+static json_t *expiry_to_json_string(TR_COMM_MEMB *memb)
+{
+  struct timespec ts_zero = {0, 0};
+  char *s = NULL;
+  json_t *jstr = NULL;
+
+  if (tr_cmp_timespec(tr_comm_memb_get_expiry(memb), &ts_zero) == 0) {
+    s = strdup("");
+  } else {
+    s = timespec_to_str(tr_comm_memb_get_expiry(memb));
+  }
+
+  if (s) {
+    jstr = json_string(s);
+    free(s);
+  }
+
+  return jstr;
+}
+
+/**
+ * Get the provenance from the member, handling empty provenance safely
+ */
+static json_t *provenance_to_json(TR_COMM_MEMB *memb)
+{
+  json_t *prov = tr_comm_memb_get_provenance(memb);
+
+  if (prov) {
+    json_incref(prov);
+    return prov;
+  } else {
+    return json_array();
+  }
+}
+
+/* helper for below */
+#define OBJECT_SET_OR_FAIL(jobj, key, val)     \
+do {                                           \
+  if (val)                                     \
+    json_object_set_new((jobj),(key),(val));   \
+  else                                         \
+    goto cleanup;                              \
+} while (0)
+
+json_t *tr_comm_memb_to_json(TR_COMM_MEMB *memb)
+{
+  json_t *memb_json = NULL;
+  json_t *retval = NULL;
+
+  memb_json = json_object();
+  if (memb_json == NULL)
+    goto cleanup;
+
+  OBJECT_SET_OR_FAIL(memb_json, "realm",
+                     tr_name_to_json_string(tr_comm_memb_get_realm_id(memb)));
+  OBJECT_SET_OR_FAIL(memb_json, "expires",
+                     expiry_to_json_string(memb));
+  OBJECT_SET_OR_FAIL(memb_json, "announce_interval",
+                     json_integer(tr_comm_memb_get_interval(memb)));
+  OBJECT_SET_OR_FAIL(memb_json, "times_expired",
+                     json_integer(tr_comm_memb_get_times_expired(memb)));
+  OBJECT_SET_OR_FAIL(memb_json, "provenance",
+                     provenance_to_json(memb));
+
+  /* succeeded - set the return value and increment the reference count */
+  retval = memb_json;
+  json_incref(retval);
+
+cleanup:
+  if (memb_json)
+    json_decref(memb_json);
+  return retval;
+}
+
+json_t *tr_comm_idp_realms_to_json(TR_COMM_TABLE *ctable, TR_NAME *comm_name)
+{
+  json_t *jarray = json_array();
+  TR_COMM_ITER *iter = NULL;
+  TR_IDP_REALM *idp = NULL;
+  TR_COMM_MEMB *memb = NULL;
+
+  iter = tr_comm_iter_new(NULL);
+  idp = tr_idp_realm_iter_first(iter, ctable, comm_name);
+  while(idp) {
+    tr_debug("<<<<<<<<<<<<<<<<<<<<<<<<< GOT IDP REALM %s", tr_idp_realm_get_id(idp)->buf);
+    memb = tr_comm_table_find_idp_memb(ctable,
+                                       tr_idp_realm_get_id(idp),
+                                       comm_name);
+    tr_debug("<<<<<<<<<<<<<<<<<<<<<<<<< FOUND MEMB %p", memb);
+    json_array_append_new(jarray, tr_comm_memb_to_json(memb));
+    idp = tr_idp_realm_iter_next(iter);
+  }
+  tr_comm_iter_free(iter);
+
+  return jarray;
+}
+
+json_t *tr_comm_rp_realms_to_json(TR_COMM_TABLE *ctable, TR_NAME *comm_id)
+{
+  json_t *jarray = json_array();
+  TR_COMM_ITER *iter = NULL;
+  TR_RP_REALM *rp = NULL;
+  TR_COMM_MEMB *memb = NULL;
+
+  iter = tr_comm_iter_new(NULL);
+  rp = tr_rp_realm_iter_first(iter, ctable, comm_id);
+  while(rp) {
+    tr_debug("<<<<<<<<<<<<<<<<<<<<<<<<< GOT RP REALM ");
+    memb = tr_comm_table_find_rp_memb(ctable,
+                                      tr_rp_realm_get_id(rp),
+                                      comm_id);
+    json_array_append_new(jarray, tr_comm_memb_to_json(memb));
+    rp = tr_rp_realm_iter_next(iter);
+  }
+  tr_comm_iter_free(iter);
+
+  return jarray;
+}
+
+/**
+ * Convert TR_NAME n to a JSON string, returning the empty string if n is null
+ */
+static json_t *safe_name_to_json_string(TR_NAME *n)
+{
+  if (n)
+    return tr_name_to_json_string(n);
+  else
+    return json_string("");
+}
+
+json_t *tr_comm_to_json(TR_COMM_TABLE *ctable, TR_COMM *comm)
+{
+  json_t *comm_json = NULL;
+  json_t *retval = NULL;
+
+  comm_json = json_object();
+  if (comm_json == NULL)
+    goto cleanup;
+
+  OBJECT_SET_OR_FAIL(comm_json, "type",
+                     json_string(tr_comm_type_to_str(tr_comm_get_type(comm))));
+  if (tr_comm_get_type(comm) == TR_COMM_APC) {
+    OBJECT_SET_OR_FAIL(comm_json, "expiration_interval",
+                       json_integer(comm->expiration_interval));
+  } else {
+    /* just get the first apc */
+    OBJECT_SET_OR_FAIL(comm_json, "apc",
+                       tr_name_to_json_string(
+                           tr_apc_get_id(
+                               tr_comm_get_apcs(comm))));
+  }
+  OBJECT_SET_OR_FAIL(comm_json, "name",
+                     tr_name_to_json_string(tr_comm_get_id(comm)));
+  OBJECT_SET_OR_FAIL(comm_json, "owner_realm",
+                     safe_name_to_json_string(tr_comm_get_owner_realm(comm)));
+  OBJECT_SET_OR_FAIL(comm_json, "owner_contact",
+                     safe_name_to_json_string(tr_comm_get_owner_contact(comm)));
+
+  OBJECT_SET_OR_FAIL(comm_json, "idp_realms",
+                     tr_comm_idp_realms_to_json(ctable, tr_comm_get_id(comm)));
+  OBJECT_SET_OR_FAIL(comm_json, "rp_realms",
+                     tr_comm_rp_realms_to_json(ctable, tr_comm_get_id(comm)));
+
+  /* succeeded - set the return value and increment the reference count */
+  retval = comm_json;
+  json_incref(retval);
+
+  cleanup:
+  if (comm_json)
+    json_decref(comm_json);
+  return retval;
+}
+
+json_t *tr_comm_table_to_json(TR_COMM_TABLE *ctable)
+{
+  json_t *ctable_json = NULL;
+  json_t *retval = NULL;
+  json_t *comm_json = NULL;
+  TR_COMM_ITER *iter = NULL;
+  TR_COMM *comm = NULL;
+
+  ctable_json = json_array();
+  if (ctable_json == NULL)
+    goto cleanup;
+
+  iter = tr_comm_iter_new(NULL);
+  if (iter == NULL)
+    goto cleanup;
+
+  /* Iterate over communities in the table */
+  comm = tr_comm_table_iter_first(iter, ctable);
+  while (comm) {
+    comm_json = tr_comm_to_json(ctable, comm);
+
+    if (comm_json == NULL)
+      goto cleanup;
+
+    json_array_append_new(ctable_json, comm_json);
+    comm = tr_comm_table_iter_next(iter);
+  }
+
+  /* succeeded - set the return value and increment the reference count */
+  retval = ctable_json;
+  json_incref(retval);
+
+cleanup:
+  if (iter)
+    tr_comm_iter_free(iter);
+
+  if (ctable_json)
+    json_decref(ctable_json);
+
+  return retval;
+}
\ No newline at end of file
index 747397b..50a9330 100644 (file)
@@ -259,7 +259,7 @@ TR_IDP_REALM *tr_idp_realm_remove_func(TR_IDP_REALM *head, TR_IDP_REALM *remove)
   return head;
 }
 
-static int tr_idp_realm_apc_count(TR_IDP_REALM *idp)
+int tr_idp_realm_apc_count(TR_IDP_REALM *idp)
 {
   int ii=0;
   TR_APC *apc=idp->apcs;
@@ -270,7 +270,7 @@ static int tr_idp_realm_apc_count(TR_IDP_REALM *idp)
   return ii;
 }
 
-static int tr_idp_realm_aaa_server_count(TR_IDP_REALM *idp)
+int tr_idp_realm_aaa_server_count(TR_IDP_REALM *idp)
 {
   int ii=0;
   TR_AAA_SERVER *aaa=idp->aaa_servers;
@@ -281,84 +281,6 @@ static int tr_idp_realm_aaa_server_count(TR_IDP_REALM *idp)
   return ii;
 }
 
-static char *tr_aaa_server_to_str(TALLOC_CTX *mem_ctx, TR_AAA_SERVER *aaa)
-{
-  return talloc_strndup(mem_ctx, aaa->hostname->buf, aaa->hostname->len);
-}
-
-char *tr_idp_realm_to_str(TALLOC_CTX *mem_ctx, TR_IDP_REALM *idp)
-{
-  TALLOC_CTX *tmp_ctx=talloc_new(NULL);
-  char **s_aaa=NULL, *aaa_servers=NULL;
-  char **s_apc=NULL, *apcs=NULL;
-  int ii=0, aaa_servers_strlen=0, apcs_strlen=0;
-  int n_aaa_servers=tr_idp_realm_aaa_server_count(idp);
-  int n_apcs=tr_idp_realm_apc_count(idp);
-  TR_AAA_SERVER *aaa=NULL;
-  TR_APC *apc=NULL;
-  char *result=NULL;
-
-  /* get the AAA servers */
-  if (n_aaa_servers<=0)
-    aaa_servers=talloc_strdup(tmp_ctx, "");
-  else {
-    s_aaa=talloc_array(tmp_ctx, char *, n_aaa_servers);
-    for (aaa=idp->aaa_servers,ii=0; aaa!=NULL; aaa=aaa->next,ii++) {
-      s_aaa[ii]=tr_aaa_server_to_str(s_aaa, aaa);
-      aaa_servers_strlen+=strlen(s_aaa[ii]);
-    }
-
-    /* add space for comma-space separators */
-    aaa_servers_strlen+=2*(n_aaa_servers-1);
-
-    aaa_servers=talloc_array(tmp_ctx, char, aaa_servers_strlen+1);
-    aaa_servers[0]='\0';
-    for (ii=0; ii<n_aaa_servers; ii++) {
-      strcat(aaa_servers, s_aaa[ii]);
-      if (ii<(n_aaa_servers-1))
-        strcat(aaa_servers, ", ");
-    }
-    talloc_free(s_aaa);
-  }
-
-  /* get the APCs */
-  if (n_apcs<=0)
-    apcs=talloc_strdup(tmp_ctx, "");
-  else {
-    s_apc=talloc_array(tmp_ctx, char *, n_apcs);
-    for (apc=idp->apcs,ii=0; apc!=NULL; apc=apc->next,ii++) {
-      s_apc[ii]=tr_apc_to_str(s_apc, apc);
-      apcs_strlen+=strlen(s_apc[ii]);
-    }
-
-    /* add space for comma-space separators */
-    apcs_strlen+=2*(n_apcs-1);
-
-    apcs=talloc_array(tmp_ctx, char, apcs_strlen+1);
-    apcs[0]='\0';
-    for (ii=0; ii<n_apcs; ii++) {
-      strcat(apcs, s_apc[ii]);
-      if (ii<(n_apcs-1))
-        strcat(apcs, ", ");
-    }
-    talloc_free(s_apc);
-  }
-
-  result=talloc_asprintf(mem_ctx,
-                         "IDP realm: \"%.*s\""
-                         "  shared: %s"
-                         "  local: %s"
-                         "  AAA servers: %s"
-                         "  APCs: %s",
-                         idp->realm_id->len, idp->realm_id->buf,
-                         (idp->shared_config)?"yes":"no",
-                         (idp->origin==TR_REALM_LOCAL)?"yes":"no",
-                         aaa_servers,
-                         apcs);
-  talloc_free(tmp_ctx);
-  return result;
-}
-
 void tr_idp_realm_incref(TR_IDP_REALM *realm)
 {
   realm->refcount++;
diff --git a/common/tr_idp_encoders.c b/common/tr_idp_encoders.c
new file mode 100644 (file)
index 0000000..f31aa65
--- /dev/null
@@ -0,0 +1,121 @@
+/*
+ * Copyright (c) 2012-2018, JANET(UK)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of JANET(UK) nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include <talloc.h>
+#include <time.h>
+
+#include <tr_name_internal.h>
+#include <tr_idp.h>
+#include <tr_config.h>
+#include <tr_debug.h>
+
+static char *tr_aaa_server_to_str(TALLOC_CTX *mem_ctx, TR_AAA_SERVER *aaa)
+{
+  return talloc_strndup(mem_ctx, aaa->hostname->buf, aaa->hostname->len);
+}
+
+
+char *tr_idp_realm_to_str(TALLOC_CTX *mem_ctx, TR_IDP_REALM *idp)
+{
+  TALLOC_CTX *tmp_ctx=talloc_new(NULL);
+  char **s_aaa=NULL, *aaa_servers=NULL;
+  char **s_apc=NULL, *apcs=NULL;
+  int ii=0, aaa_servers_strlen=0, apcs_strlen=0;
+  int n_aaa_servers=tr_idp_realm_aaa_server_count(idp);
+  int n_apcs=tr_idp_realm_apc_count(idp);
+  TR_AAA_SERVER *aaa=NULL;
+  TR_APC *apc=NULL;
+  char *result=NULL;
+
+  /* get the AAA servers */
+  if (n_aaa_servers<=0)
+    aaa_servers=talloc_strdup(tmp_ctx, "");
+  else {
+    s_aaa=talloc_array(tmp_ctx, char *, n_aaa_servers);
+    for (aaa=idp->aaa_servers,ii=0; aaa!=NULL; aaa=aaa->next,ii++) {
+      s_aaa[ii]=tr_aaa_server_to_str(s_aaa, aaa);
+      aaa_servers_strlen+=strlen(s_aaa[ii]);
+    }
+
+    /* add space for comma-space separators */
+    aaa_servers_strlen+=2*(n_aaa_servers-1);
+
+    aaa_servers=talloc_array(tmp_ctx, char, aaa_servers_strlen+1);
+    aaa_servers[0]='\0';
+    for (ii=0; ii<n_aaa_servers; ii++) {
+      strcat(aaa_servers, s_aaa[ii]);
+      if (ii<(n_aaa_servers-1))
+        strcat(aaa_servers, ", ");
+    }
+    talloc_free(s_aaa);
+  }
+
+  /* get the APCs */
+  if (n_apcs<=0)
+    apcs=talloc_strdup(tmp_ctx, "");
+  else {
+    s_apc=talloc_array(tmp_ctx, char *, n_apcs);
+    for (apc=idp->apcs,ii=0; apc!=NULL; apc=apc->next,ii++) {
+      s_apc[ii]=tr_apc_to_str(s_apc, apc);
+      apcs_strlen+=strlen(s_apc[ii]);
+    }
+
+    /* add space for comma-space separators */
+    apcs_strlen+=2*(n_apcs-1);
+
+    apcs=talloc_array(tmp_ctx, char, apcs_strlen+1);
+    apcs[0]='\0';
+    for (ii=0; ii<n_apcs; ii++) {
+      strcat(apcs, s_apc[ii]);
+      if (ii<(n_apcs-1))
+        strcat(apcs, ", ");
+    }
+    talloc_free(s_apc);
+  }
+
+  result=talloc_asprintf(mem_ctx,
+                         "IDP realm: \"%.*s\""
+                         "  shared: %s"
+                         "  local: %s"
+                         "  AAA servers: %s"
+                         "  APCs: %s",
+                         idp->realm_id->len, idp->realm_id->buf,
+                         (idp->shared_config)?"yes":"no",
+                         (idp->origin==TR_REALM_LOCAL)?"yes":"no",
+                         aaa_servers,
+                         apcs);
+  talloc_free(tmp_ctx);
+  return result;
+}
+
index 6d0880a..a8988f6 100644 (file)
@@ -330,3 +330,8 @@ char *tr_rp_realm_to_str(TALLOC_CTX *mem_ctx, TR_RP_REALM *rp)
                          "RP realm: \"%.*s\"\n",
                          rp->realm_id->len, rp->realm_id->buf);
 }
+
+json_t *tr_rp_realm_to_json(TR_RP_REALM *rp)
+{
+  return tr_name_to_json_string(tr_rp_realm_get_id(rp));
+}
\ No newline at end of file
index 5a770b8..2fd86f6 100644 (file)
@@ -226,4 +226,11 @@ TR_NAME *tr_realm_dup_id(TR_REALM *realm);
 const char *tr_realm_role_to_str(TR_REALM_ROLE role);
 TR_REALM_ROLE tr_realm_role_from_str(const char *s);
 
+/* tr_comm_encoders.c */
+json_t *tr_comm_memb_to_json(TR_COMM_MEMB *memb);
+json_t *tr_comm_to_json(TR_COMM_TABLE *ctable, TR_COMM *comm);
+json_t *tr_comm_table_to_json(TR_COMM_TABLE *ctable);
+json_t *tr_comm_rp_realms_to_json(TR_COMM_TABLE *ctable, TR_NAME *comm_id);
+json_t *tr_comm_idp_realms_to_json(TR_COMM_TABLE *ctable, TR_NAME *comm_name);
+
 #endif
index 951f7d7..917da85 100644 (file)
@@ -83,7 +83,8 @@ TR_IDP_REALM *tr_idp_realm_remove_func(TR_IDP_REALM *head, TR_IDP_REALM *remove)
 #define tr_idp_realm_remove(head,remove) ((head)=tr_idp_realm_remove_func((head),(remove)))
 TR_IDP_REALM *tr_idp_realm_sweep_func(TR_IDP_REALM *head);
 #define tr_idp_realm_sweep(head) ((head)=tr_idp_realm_sweep_func((head)))
-char *tr_idp_realm_to_str(TALLOC_CTX *mem_ctx, TR_IDP_REALM *idp);
+int tr_idp_realm_aaa_server_count(TR_IDP_REALM *idp);
+int tr_idp_realm_apc_count(TR_IDP_REALM *idp);
 void tr_idp_realm_incref(TR_IDP_REALM *realm);
 void tr_idp_realm_decref(TR_IDP_REALM *realm);
 
@@ -98,4 +99,8 @@ TR_AAA_SERVER *tr_aaa_server_iter_next(TR_AAA_SERVER_ITER *iter);
 TR_AAA_SERVER *tr_idp_aaa_server_lookup(TR_IDP_REALM *idp_realms, TR_NAME *idp_realm_name, TR_NAME *comm, int *shared_out);
 TR_AAA_SERVER *tr_default_server_lookup(TR_AAA_SERVER *default_servers, TR_NAME *comm);
 
+/* tr_idp_encoders.c */
+char *tr_idp_realm_to_str(TALLOC_CTX *mem_ctx, TR_IDP_REALM *idp);
+json_t *tr_idp_realm_to_json(TR_IDP_REALM *idp);
+
 #endif
index a9e56df..abf476b 100644 (file)
@@ -85,5 +85,6 @@ void tr_rp_realm_incref(TR_RP_REALM *realm);
 void tr_rp_realm_decref(TR_RP_REALM *realm);
 
 char *tr_rp_realm_to_str(TALLOC_CTX *mem_ctx, TR_RP_REALM *rp);
+json_t *tr_rp_realm_to_json(TR_RP_REALM *rp);
 
 #endif
index d11076e..f57154d 100644 (file)
@@ -39,6 +39,7 @@
 #include <tr_trp.h>
 #include <trp_rtable.h>
 #include <trp_ptable.h>
+#include <tr_comm.h>
 #include <mon_internal.h>
 #include <mons_handlers.h>
 
@@ -58,6 +59,14 @@ static MON_RC handle_show_peers(void *cookie, json_t **response_ptr)
   return (*response_ptr == NULL) ? MON_NOMEM : MON_SUCCESS;
 }
 
+static MON_RC handle_show_communities(void *cookie, json_t **response_ptr)
+{
+  TRPS_INSTANCE *trps = talloc_get_type_abort(cookie, TRPS_INSTANCE);
+
+  *response_ptr = tr_comm_table_to_json(trps->ctable);
+  return (*response_ptr == NULL) ? MON_NOMEM : MON_SUCCESS;
+}
+
 void tr_trp_register_mons_handlers(TRPS_INSTANCE *trps, MONS_INSTANCE *mons)
 {
   mons_register_handler(mons,
@@ -66,4 +75,7 @@ void tr_trp_register_mons_handlers(TRPS_INSTANCE *trps, MONS_INSTANCE *mons)
   mons_register_handler(mons,
                         MON_CMD_SHOW, OPT_TYPE_SHOW_PEERS,
                         handle_show_peers, trps);
+  mons_register_handler(mons,
+                        MON_CMD_SHOW, OPT_TYPE_SHOW_COMMUNITIES,
+                        handle_show_communities, trps);
 }
index 440391e..e6d4253 100644 (file)
@@ -206,7 +206,7 @@ int main(int argc, char *argv[])
   }
 
   /* Print the JSON to stdout */
-  json_dumpf(mon_resp_encode(resp), stdout, JSON_INDENT(4) | JSON_SORT_KEYS);
+  json_dumpf(mon_resp_encode(resp), stdout, JSON_INDENT(4));
   printf("\n");
 
   /* success */