iter = tr_comm_iter_new(NULL);
realm = tr_realm_iter_first(iter, ctable, comm_name);
+
+ /* Do not display the full realm json here, only the name and info relevant to the community listing */
while(realm) {
if (realm->role == role) {
realm_json = json_object();
#include <talloc.h>
#include <time.h>
+#include <jansson.h>
#include <tr_name_internal.h>
#include <tr_idp.h>
return result;
}
+
+/* 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)
+
+#define ARRAY_APPEND_OR_FAIL(jary, val) \
+do { \
+ if (val) \
+ json_array_append_new((jary),(val)); \
+ else \
+ goto cleanup; \
+} while (0)
+
+static json_t *tr_apcs_to_json(TR_APC *apcs)
+{
+ json_t *jarray = json_array();
+ json_t *retval = NULL;
+ TR_APC_ITER *iter = tr_apc_iter_new(NULL);
+ TR_APC *apc = NULL;
+
+ if ((jarray == NULL) || (iter == NULL))
+ goto cleanup;
+
+ apc = tr_apc_iter_first(iter, apcs);
+ while (apc) {
+ ARRAY_APPEND_OR_FAIL(jarray, tr_name_to_json_string(tr_apc_get_id(apc)));
+ apc = tr_apc_iter_next(iter);
+ }
+
+ /* success */
+ retval = jarray;
+ json_incref(retval);
+
+cleanup:
+ if (jarray)
+ json_decref(jarray);
+
+ return retval;
+}
+
+static json_t *tr_aaa_server_to_json(TR_AAA_SERVER *aaa)
+{
+ char *hostname = tr_name_strdup(aaa->hostname);
+ char *s = NULL;
+ json_t *jstr = NULL;
+
+ if (hostname == NULL)
+ return NULL;
+
+ s = talloc_asprintf(NULL, "%s:%d", hostname, TID_PORT);
+ if (s) {
+ jstr = json_string(s);
+ talloc_free(s);
+ }
+ return jstr;
+}
+
+static json_t *tr_aaa_servers_to_json(TR_AAA_SERVER *aaas)
+{
+ json_t *jarray = json_array();
+ json_t *retval = NULL;
+ TR_AAA_SERVER_ITER *iter = tr_aaa_server_iter_new(NULL);
+ TR_AAA_SERVER *aaa = NULL;
+
+ if ((jarray == NULL) || (iter == NULL))
+ goto cleanup;
+
+ aaa = tr_aaa_server_iter_first(iter, aaas);
+ while (aaa) {
+ ARRAY_APPEND_OR_FAIL(jarray, tr_aaa_server_to_json(aaa));
+ aaa = tr_aaa_server_iter_next(iter);
+ }
+
+ /* success */
+ retval = jarray;
+ json_incref(retval);
+
+cleanup:
+ if (jarray)
+ json_decref(jarray);
+
+ return retval;
+}
+
+static json_t *tr_idp_realm_to_json(TR_IDP_REALM *idp)
+{
+ json_t *idp_json = json_object();
+ json_t *retval = NULL;
+
+ if (idp_json == NULL)
+ goto cleanup;
+
+
+ /* success */
+ retval = idp_json;
+ json_incref(retval);
+
+ OBJECT_SET_OR_FAIL(idp_json, "realm",
+ tr_name_to_json_string(tr_idp_realm_get_id(idp)));
+ OBJECT_SET_OR_FAIL(idp_json, "discovered",
+ json_boolean(idp->origin == TR_REALM_DISCOVERED));
+ OBJECT_SET_OR_FAIL(idp_json, "apcs",
+ tr_apcs_to_json(tr_idp_realm_get_apcs(idp)));
+ OBJECT_SET_OR_FAIL(idp_json, "aaa_servers",
+ tr_aaa_servers_to_json(idp->aaa_servers));
+ OBJECT_SET_OR_FAIL(idp_json, "shared_config",
+ json_boolean(idp->shared_config));
+cleanup:
+ if (idp_json)
+ json_decref(idp_json);
+
+ return retval;
+}
+
+json_t *tr_idp_realms_to_json(TR_IDP_REALM *idps)
+{
+ {
+ json_t *jarray = json_array();
+ json_t *retval = NULL;
+ TR_IDP_REALM *this = NULL;
+
+ if (jarray == NULL)
+ goto cleanup;
+
+ for (this=idps; this != NULL; this=this->next)
+ ARRAY_APPEND_OR_FAIL(jarray, tr_idp_realm_to_json(this));
+
+ /* success */
+ retval = jarray;
+ json_incref(retval);
+
+ cleanup:
+ if (jarray)
+ json_decref(jarray);
+
+ return retval;
+ }
+
+}
\ No newline at end of file
// Dynamic trust router state
OPT_TYPE_SHOW_ROUTES,
OPT_TYPE_SHOW_PEERS,
- OPT_TYPE_SHOW_COMMUNITIES
+ OPT_TYPE_SHOW_COMMUNITIES,
+ OPT_TYPE_SHOW_REALMS,
+ OPT_TYPE_SHOW_RP_CLIENTS
};
struct mon_opt {
/* 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);
+json_t *tr_idp_realms_to_json(TR_IDP_REALM *idp);
#endif
case OPT_TYPE_SHOW_COMMUNITIES:
return "communities";
+
+ case OPT_TYPE_SHOW_REALMS:
+ return "realms";
+
+ case OPT_TYPE_SHOW_RP_CLIENTS:
+ return "rp_clients";
}
return NULL;
}
return_if_matches(s, OPT_TYPE_SHOW_ROUTES);
return_if_matches(s, OPT_TYPE_SHOW_PEERS);
return_if_matches(s, OPT_TYPE_SHOW_COMMUNITIES);
+ return_if_matches(s, OPT_TYPE_SHOW_REALMS);
+ return_if_matches(s, OPT_TYPE_SHOW_RP_CLIENTS);
return OPT_TYPE_UNKNOWN;
}
#undef return_if_matches
#include <trp_rtable.h>
#include <trp_ptable.h>
#include <tr_comm.h>
+#include <tr_idp.h>
#include <mon_internal.h>
#include <mons_handlers.h>
return (*response_ptr == NULL) ? MON_NOMEM : MON_SUCCESS;
}
+static MON_RC handle_show_realms(void *cookie, json_t **response_ptr)
+{
+ TRPS_INSTANCE *trps = talloc_get_type_abort(cookie, TRPS_INSTANCE);
+
+ *response_ptr = tr_idp_realms_to_json(trps->ctable->idp_realms);
+ return (*response_ptr == NULL) ? MON_NOMEM : MON_SUCCESS;
+}
+
void tr_trp_register_mons_handlers(TRPS_INSTANCE *trps, MONS_INSTANCE *mons)
{
mons_register_handler(mons,
mons_register_handler(mons,
MON_CMD_SHOW, OPT_TYPE_SHOW_COMMUNITIES,
handle_show_communities, trps);
+ mons_register_handler(mons,
+ MON_CMD_SHOW, OPT_TYPE_SHOW_REALMS,
+ handle_show_realms, trps);
}
OBJECT_SET_OR_FAIL(peer_json, "server",
server_to_json_string(trp_peer_get_server(peer),
trp_peer_get_port(peer)));
+ OBJECT_SET_OR_FAIL(peer_json, "servicename",
+ tr_name_to_json_string(trp_peer_get_servicename(peer)));
OBJECT_SET_OR_FAIL(peer_json, "linkcost",
json_integer(trp_peer_get_linkcost(peer)));
OBJECT_SET_OR_FAIL(peer_json, "connected_to",
json_boolean(trp_peer_get_outgoing_status(peer) == PEER_CONNECTED));
OBJECT_SET_OR_FAIL(peer_json, "connected_from",
json_boolean(trp_peer_get_incoming_status(peer) == PEER_CONNECTED));
- OBJECT_SET_OR_FAIL(peer_json, "servicename",
- tr_name_to_json_string(trp_peer_get_servicename(peer)));
- OBJECT_SET_OR_FAIL(peer_json, "allowed_credentials",
- gss_names_to_json_array(trp_peer_get_gss_names(peer)));
OBJECT_SET_OR_FAIL(peer_json, "last_connection_attempt",
last_attempt_to_json_string(peer));
+ OBJECT_SET_OR_FAIL(peer_json, "allowed_credentials",
+ gss_names_to_json_array(trp_peer_get_gss_names(peer)));
/* succeeded - set the return value and increment the reference count */
retval = peer_json;