Merge pull request #82 from painless-security/jennifer/pull_req_feedback
authorJennifer Richards <jennifer@painless-security.com>
Mon, 7 May 2018 18:48:22 +0000 (14:48 -0400)
committerGitHub <noreply@github.com>
Mon, 7 May 2018 18:48:22 +0000 (14:48 -0400)
Incorporate feedback from monitoring code reviews

38 files changed:
CMakeLists.txt
common/tr_config.c
common/tr_config_encoders.c
common/tr_filter_encoders.c
common/tr_gss.c
common/tr_gss_client.c
common/tr_idp_encoders.c
common/tr_rp_client_encoders.c
configure.ac
include/mon_internal.h
include/tid_internal.h
include/tr_config.h
include/tr_gss.h
include/tr_gss_client.h
include/tr_json_util.h [new file with mode: 0644]
mon/mon_common.c
mon/mon_req.c
mon/mon_req_decode.c
mon/mon_req_encode.c
mon/mon_resp.c
mon/mon_resp_decode.c
mon/mon_resp_encode.c
mon/monc.c
mon/mons.c
mon/mons_handlers.c
mon/tests/req_reconfigure.test [deleted file]
mon/tests/resp_reconfigure_error.test [deleted file]
mon/tests/resp_reconfigure_success.test [deleted file]
mon/tests/test_mon_req_decode.c
mon/tests/test_mon_req_encode.c
mon/tests/test_mon_resp_encode.c
tid/tidc.c
tid/tids.c
tr/trmon_main.c
tr/trpc_main.c
trp/trp_peer_encoders.c
trp/trp_route_encoders.c
trust_router.spec

index 1221d67..2aa60bc 100644 (file)
@@ -96,19 +96,19 @@ 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 common/tr_idp_encoders.c common/tr_comm_encoders.c common/tr_rp_client.c include/tr_rp_client.h common/tr_rp_client_encoders.c common/tr_filter_encoders.c common/tr_config_encoders.c common/tr_config_filters.c common/tr_config_realms.c common/tr_config_rp_clients.c common/tr_config_orgs.c common/tr_config_comms.c common/tr_list.c include/tr_list.h include/tr_constraint_internal.h)
+        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 common/tr_rp_client.c include/tr_rp_client.h common/tr_rp_client_encoders.c common/tr_filter_encoders.c common/tr_config_encoders.c common/tr_config_filters.c common/tr_config_realms.c common/tr_config_rp_clients.c common/tr_config_orgs.c common/tr_config_comms.c common/tr_list.c include/tr_list.h include/tr_constraint_internal.h include/tr_json_util.h)
 
 # Does not actually build!
 add_executable(trust_router ${SOURCE_FILES})
 
-add_executable(trmon mon/monc.c tr/trmon_main.c common/tr_gss_client.c include/tr_gss_client.h)
+add_executable(trmon mon/monc.c tr/trmon_main.c common/tr_gss_client.c include/tr_gss_client.h include/tr_json_util.h)
 
 # Test build targets - for debugging
-add_executable(test_mon_req_encode mon/mon_common.c mon/mon_req.c mon/tests/test_mon_req_encode.c mon/mon_req_encode.c)
+add_executable(test_mon_req_encode mon/mon_common.c mon/mon_req.c mon/tests/test_mon_req_encode.c mon/mon_req_encode.c include/tr_json_util.h)
 target_link_libraries(test_mon_req_encode jansson talloc glib-2.0)
 
-add_executable(test_mon_req_decode mon/mon_common.c mon/mon_req.c mon/tests/test_mon_req_decode.c mon/mon_req_decode.c)
+add_executable(test_mon_req_decode mon/mon_common.c mon/mon_req.c mon/tests/test_mon_req_decode.c mon/mon_req_decode.c include/tr_json_util.h)
 target_link_libraries(test_mon_req_decode jansson talloc glib-2.0)
 
-add_executable(test_mon_resp_encode mon/mon_common.c mon/mon_req.c mon/mon_resp.c mon/mon_resp_encode.c common/tr_name.c mon/tests/test_mon_resp_encode.c)
+add_executable(test_mon_resp_encode mon/mon_common.c mon/mon_req.c mon/mon_resp.c mon/mon_resp_encode.c common/tr_name.c mon/tests/test_mon_resp_encode.c include/tr_json_util.h)
 target_link_libraries(test_mon_resp_encode jansson talloc glib-2.0)
index 8c0f577..2ddda12 100644 (file)
@@ -310,13 +310,13 @@ static json_t **tr_cfg_parse_config_files(TALLOC_CTX *mem_ctx, unsigned int n_fi
 
     this_file->serial = get_cfg_serial(jcfgs[ii]);
     if (this_file->serial != TR_CFG_INVALID_SERIAL) {
-      tr_notice("tr_parse_one_config_file: Attempting to load revision %"
+      tr_notice("tr_parse_config_files: Attempting to load revision %"
                     JSON_INTEGER_FORMAT
                     " of '%s'.",
                 this_file->serial,
                 this_file->name);
     } else {
-      tr_notice("tr_parse_one_config_file: Attempting to load '%s'.",
+      tr_notice("tr_parse_config_files: Attempting to load '%s'.",
                 this_file->name);
     }
   }
index 47331d9..a6307cd 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, JANET(UK)
+ * Copyright (c) 2018, JANET(UK)
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
 
 #include <jansson.h>
 #include <tr_config.h>
-
-/* 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)
+#include <tr_json_util.h>
 
 static json_t *tr_cfg_file_to_json(TR_CFG_FILE *cfg_file)
 {
index 932be9e..a69685d 100644 (file)
 
 #include <tr_filter.h>
 #include <tr_constraint_internal.h>
-
-/* 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)
-
+#include <tr_json_util.h>
 
 typedef json_t *(ITEM_ENCODER_FUNC)(void *);
 
index e7902ee..d576449 100644 (file)
@@ -214,13 +214,13 @@ static int tr_gss_write_resp(int conn, gss_ctx_id_t gssctx, const char *resp)
  * @param req_cb callback to handle the request and produce the response
  * @param req_cookie cookie for the req_cb
  */
-void tr_gss_handle_connection(int conn,
-                              const char *acceptor_service,
-                              const char *acceptor_hostname,
-                              TR_GSS_AUTH_FN auth_cb,
-                              void *auth_cookie,
-                              TR_GSS_HANDLE_REQ_FN req_cb,
-                              void *req_cookie)
+TR_GSS_RC tr_gss_handle_connection(int conn,
+                                   const char *acceptor_service,
+                                   const char *acceptor_hostname,
+                                   TR_GSS_AUTH_FN auth_cb,
+                                   void *auth_cookie,
+                                   TR_GSS_HANDLE_REQ_FN req_cb,
+                                   void *req_cookie)
 {
   TALLOC_CTX *tmp_ctx = talloc_new(NULL);
   gss_ctx_id_t gssctx = GSS_C_NO_CONTEXT;
@@ -229,6 +229,7 @@ void tr_gss_handle_connection(int conn,
   TR_MSG *req_msg = NULL;
   TR_MSG *resp_msg = NULL;
   char *resp_str = NULL;
+  TR_GSS_RC rc = TR_GSS_ERROR;
 
   tr_debug("tr_gss_handle_connection: Attempting to accept %s connection on fd %d.",
            acceptor_service, conn);
@@ -294,6 +295,10 @@ void tr_gss_handle_connection(int conn,
     goto cleanup;
   }
 
+  /* we successfully sent a response */
+  rc = TR_GSS_SUCCESS;
+
 cleanup:
   talloc_free(tmp_ctx);
+  return rc;
 }
index db9f380..7b61acb 100644 (file)
 #include <tr_debug.h>
 #include <tr_gss_client.h>
 
-static int tr_gssc_destructor(void *obj)
-{
-  TR_GSSC_INSTANCE *tr_gssc=talloc_get_type_abort(obj, TR_GSSC_INSTANCE);
-  if (NULL!=tr_gssc) {
-    if (NULL!=tr_gssc->client_dh)
-      tr_destroy_dh_params(tr_gssc->client_dh);
-  }
-  return 0;
-}
-
 TR_GSSC_INSTANCE *tr_gssc_instance_new(TALLOC_CTX *mem_ctx)
 {
   TR_GSSC_INSTANCE *gssc=talloc(NULL, TR_GSSC_INSTANCE);
   if (gssc != NULL) {
     gssc->service_name = NULL;
-    gssc->client_dh = NULL;
     gssc->conn = -1;
     gssc->gss_ctx = talloc(gssc, gss_ctx_id_t);
     if (gssc->gss_ctx == NULL) {
-      talloc_free(gssc); /* before the destructor is set */
+      talloc_free(gssc);
       return NULL;
     }
-    talloc_set_destructor((void *)gssc, tr_gssc_destructor);
   }
   return gssc;
 }
@@ -145,14 +133,3 @@ cleanup:
   talloc_free(tmp_ctx);
   return resp_msg;
 }
-
-DH * tr_gssc_get_dh(TR_GSSC_INSTANCE *inst)
-{
-  return inst->client_dh;
-}
-
-DH *tr_gssc_set_dh(TR_GSSC_INSTANCE *inst, DH *dh)
-{
-  inst->client_dh = dh;
-  return dh;
-}
index 2167ea9..72acd15 100644 (file)
@@ -40,6 +40,7 @@
 #include <tr_idp.h>
 #include <tr_config.h>
 #include <tr_debug.h>
+#include <tr_json_util.h>
 
 static char *tr_aaa_server_to_str(TALLOC_CTX *mem_ctx, TR_AAA_SERVER *aaa)
 {
@@ -121,23 +122,6 @@ char *tr_idp_realm_to_str(TALLOC_CTX *mem_ctx, TR_IDP_REALM *idp)
 }
 
 
-/* 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();
index 6a7bda9..020962a 100644 (file)
 
 #include <tr_gss_names.h>
 #include <tr_rp_client.h>
-
-/* 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)
+#include <tr_json_util.h>
 
 static json_t *tr_rp_client_to_json(TR_RP_CLIENT *rp_client)
 {
index 6b4639c..615a392 100644 (file)
@@ -1,5 +1,5 @@
 AC_PREREQ(2.63)
-AC_INIT([trust_router],[3.4.0~1],
+AC_INIT([trust_router],[3.4.0~2],
 [bugs@project-moonshot.org])
 AC_CONFIG_MACRO_DIR(m4)
 AC_CONFIG_AUX_DIR(build-aux)
index 29ea514..6e42750 100644 (file)
 #include <talloc.h>
 #include <stdint.h>
 #include <jansson.h>
-#include <gmodule.h>
+#include <glib.h>
 #include <gssapi.h>
 #include <trust_router/tid.h>
 #include <trp_internal.h>
 #include <tr_gss_names.h>
 #include <tr_gss_client.h>
 #include <tr_name_internal.h>
-#include <trust_router/tr_dh.h>
 #include <mon.h>
 
 /* Typedefs */
@@ -79,7 +78,6 @@ enum mon_rc {
 
 enum mon_cmd {
   MON_CMD_UNKNOWN=0,
-  MON_CMD_RECONFIGURE,
   MON_CMD_SHOW
 };
 
@@ -187,8 +185,6 @@ int mons_accept(MONS_INSTANCE *mons, int listen);
 /* monc.c */
 MONC_INSTANCE *monc_new(TALLOC_CTX *mem_ctx);
 void monc_free(MONC_INSTANCE *monc);
-DH *monc_get_dh(MONC_INSTANCE *inst);
-DH *monc_set_dh(MONC_INSTANCE *inst, DH *dh);
 int monc_open_connection(MONC_INSTANCE *monc, const char *server, unsigned int port);
 MON_RESP *monc_send_request(TALLOC_CTX *mem_ctx, MONC_INSTANCE *monc, MON_REQ *req);
 
index 8613eb8..ecaf647 100644 (file)
 #ifndef TID_INTERNAL_H
 #define TID_INTERNAL_H
 #include <glib.h>
+#include <jansson.h>
 
-#include <tr_rp.h>
 #include <trust_router/tid.h>
-#include <jansson.h>
-#include "tr_gss_client.h"
+#include <trust_router/tr_dh.h>
+#include <tr_rp.h>
+#include <tr_gss_client.h>
 
 struct tid_srvr_blk {
   TID_SRVR_BLK *next;
@@ -86,6 +87,7 @@ struct tid_req {
 
 struct tidc_instance {
   TR_GSSC_INSTANCE *gssc;
+  DH *client_dh;
 };
 
 struct tid_process {
index 30317de..8dc66c4 100644 (file)
@@ -41,7 +41,7 @@
 #include <syslog.h>
 #include <sys/time.h>
 #include <talloc.h>
-#include <gmodule.h>
+#include <glib.h>
 
 #include <tr_comm.h>
 #include <tr_rp.h>
index 850f51b..e0cf770 100644 (file)
 typedef int (TR_GSS_AUTH_FN)(gss_name_t, TR_NAME *, void *);
 typedef TR_MSG *(TR_GSS_HANDLE_REQ_FN)(TALLOC_CTX *, TR_MSG *, void *);
 
-void tr_gss_handle_connection(int conn, const char *acceptor_service, const char *acceptor_hostname, TR_GSS_AUTH_FN auth_cb,
-                              void *auth_cookie, TR_GSS_HANDLE_REQ_FN req_cb, void *req_cookie);
+typedef enum tr_gss_rc {
+  TR_GSS_SUCCESS = 0, /* success */
+  TR_GSS_ERROR,       /* unspecified error */
+} TR_GSS_RC;
+
+TR_GSS_RC tr_gss_handle_connection(int conn,
+                                   const char *acceptor_service,
+                                   const char *acceptor_hostname,
+                                   TR_GSS_AUTH_FN auth_cb,
+                                   void *auth_cookie,
+                                   TR_GSS_HANDLE_REQ_FN req_cb,
+                                   void *req_cookie);
 
 #endif //TRUST_ROUTER_TR_GSS_H
index 25024a6..3353184 100644 (file)
@@ -36,7 +36,6 @@
 #define TRUST_ROUTER_TR_GSS_CLIENT_H
 
 #include <gssapi.h>
-#include <trust_router/tr_dh.h>
 #include <tr_msg.h>
 
 typedef struct tr_gssc_instance TR_GSSC_INSTANCE;
@@ -44,7 +43,6 @@ typedef struct tr_gssc_instance TR_GSSC_INSTANCE;
 /* Client instance */
 struct tr_gssc_instance {
   const char *service_name;
-  DH *client_dh;
   gss_ctx_id_t *gss_ctx;
   int conn;
 };
@@ -54,7 +52,5 @@ TR_GSSC_INSTANCE *tr_gssc_instance_new(TALLOC_CTX *mem_ctx);
 void tr_gssc_instance_free(TR_GSSC_INSTANCE *tr_gssc);
 int tr_gssc_open_connection(TR_GSSC_INSTANCE *gssc, const char *server, unsigned int port);
 TR_MSG *tr_gssc_exchange_msgs(TALLOC_CTX *mem_ctx, TR_GSSC_INSTANCE *gssc, TR_MSG *req_msg);
-DH * tr_gssc_get_dh(TR_GSSC_INSTANCE *inst);
-DH *tr_gssc_set_dh(TR_GSSC_INSTANCE *inst, DH *dh);
 
 #endif //TRUST_ROUTER_TR_GSS_CLIENT_H
diff --git a/include/tr_json_util.h b/include/tr_json_util.h
new file mode 100644 (file)
index 0000000..3573a88
--- /dev/null
@@ -0,0 +1,89 @@
+/*
+ * Copyright (c) 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.
+ *
+ */
+
+/* Utilities for working with JSON/jansson */
+
+#ifndef TRUST_ROUTER_TR_JSON_UTIL_H
+#define TRUST_ROUTER_TR_JSON_UTIL_H
+
+/**
+ * @def OBJECT_SET_OR_FAIL(job, key, val)
+ * Add a key/value pair to an object or jump to the cleanup label
+ * if the value is null.
+ *
+ * @param jobj JSON object instance to receive the key/value pair
+ * @param key key to set
+ * @param val value to set
+ */
+#define OBJECT_SET_OR_FAIL(jobj, key, val)     \
+do {                                           \
+  if (val)                                     \
+    json_object_set_new((jobj),(key),(val));   \
+  else                                         \
+    goto cleanup;                              \
+} while (0)
+
+/**
+ * @def OBJECT_SET_OR_SKIP(job, key, val)
+ * Add a key/value pair to an object only if it is non-null.
+ *
+ * @param jobj JSON object instance to receive the key/value pair
+ * @param key key to set
+ * @param val value to set
+ */
+#define OBJECT_SET_OR_SKIP(jobj, key, val)     \
+do {                                           \
+  if (val)                                     \
+    json_object_set_new((jobj),(key),(val));   \
+} while (0)
+
+
+/**
+ * @def ARRAY_APPEND_OR_FAIL(job, key, val)
+ * Append a value to an array or jump to the cleanup label
+ * if the value is null.
+ *
+ * @param jobj JSON array instance to receive the value
+ * @param val value to set
+ */
+#define ARRAY_APPEND_OR_FAIL(jary, val)        \
+do {                                           \
+  if (val)                                     \
+    json_array_append_new((jary),(val));       \
+  else                                         \
+    goto cleanup;                              \
+} while (0)
+
+
+#endif //TRUST_ROUTER_TR_JSON_UTIL_H
index a237b5d..3ca8d16 100644 (file)
@@ -34,7 +34,7 @@
 
 
 #include <talloc.h>
-#include <gmodule.h>
+#include <glib.h>
 #include <string.h>
 
 #include <mon_internal.h>
@@ -50,9 +50,6 @@ const char *mon_cmd_to_string(MON_CMD cmd)
     case MON_CMD_UNKNOWN:
       return NULL;
 
-    case MON_CMD_RECONFIGURE:
-      return "reconfigure";
-
     case MON_CMD_SHOW:
       return "show";
   }
@@ -68,7 +65,6 @@ const char *mon_cmd_to_string(MON_CMD cmd)
 
 MON_CMD mon_cmd_from_string(const char *s)
 {
-  return_if_matches(s, MON_CMD_RECONFIGURE);
   return_if_matches(s, MON_CMD_SHOW);
   return MON_CMD_UNKNOWN;
 }
@@ -94,13 +90,13 @@ const char *mon_opt_type_to_string(MON_OPT_TYPE opt_type)
       return "uptime";
 
     case OPT_TYPE_SHOW_TID_REQ_COUNT:
-      return "tid_req_count";
+      return "tid_reqs_processed";
 
     case OPT_TYPE_SHOW_TID_REQ_ERR_COUNT:
-      return "tid_req_error_count";
+      return "tid_error_count";
 
     case OPT_TYPE_SHOW_TID_REQ_PENDING:
-      return "tid_req_pending";
+      return "tid_reqs_pending";
 
     case OPT_TYPE_SHOW_ROUTES:
       return "routes";
index bffa92e..e7cc43b 100644 (file)
 
 
 #include <talloc.h>
-#include <gmodule.h>
+#include <glib.h>
 
 #include <mon_internal.h>
 
-// Monitoring request message common code
+/* Monitoring request message common code */
 
 /**
  * Destructor used by talloc to ensure proper cleanup
index 21bb64b..2d05620 100644 (file)
@@ -38,7 +38,7 @@
 
 #include <mon_internal.h>
 
-// Monitoring request decoders
+/* Monitoring request decoders */
 
 /**
  * Decode a single option
@@ -98,7 +98,9 @@ static MON_RC mon_options_decode(json_t *opts_json, MON_REQ *req)
                            &opt) != MON_SUCCESS) {
       return MON_NOPARSE;
     }
-    mon_req_add_option(req, opt.type);
+    if (MON_SUCCESS != mon_req_add_option(req, opt.type)){
+      return MON_NOPARSE;
+    }
   }
   return MON_SUCCESS;
 }
index 5bcf8b2..12e408c 100644 (file)
@@ -39,7 +39,7 @@
 
 #include <mon_internal.h>
 
-// Monitoring request encoders
+/* Monitoring request encoders */
 
 /**
  * Encode options array as a JSON array
@@ -54,7 +54,7 @@
  * @param opts array of options
  * @return reference to a JSON array of options
  */
-static json_t *mon_opts_decode(GArray *opts)
+static json_t *mon_opts_encode(GArray *opts)
 {
   json_t *array_json = json_array(); // the array of options
   json_t *opt_json = NULL; // individual option JSON object
@@ -142,7 +142,7 @@ json_t *mon_req_encode(MON_REQ *req)
 
   /* If we have options, add them to the object */
   if (req->options->len > 0) {
-    opts_json = mon_opts_decode(req->options);
+    opts_json = mon_opts_encode(req->options);
     if (opts_json == NULL) {
       json_decref(req_json);
       return NULL;
index f0729ad..3049eaa 100644 (file)
@@ -38,7 +38,7 @@
 
 #include <mon_internal.h>
 
-// Monitoring request message common code
+/* Monitoring response message common code */
 
 /**
  * Destructor used by talloc to ensure proper cleanup
index 83b0ac3..c6ca379 100644 (file)
@@ -38,7 +38,7 @@
 
 #include <mon_internal.h>
 
-// Monitoring response decoder
+/* Monitoring response decoder */
 
 /**
  * Decode a JSON response
index 7e41c65..515fb7a 100644 (file)
@@ -37,6 +37,8 @@
 
 #include <mon_internal.h>
 
+/* Monitoring response encoder */
+
 /* Helper for encoding. Adds a newly allocated JSON object to
  * jobj. If the allocation or setting fails, returns NULL after
  * cleaning up. */
index 426b447..6e5b26a 100644 (file)
@@ -98,13 +98,3 @@ cleanup:
   talloc_free(tmp_ctx);
   return resp;
 }
-
-DH *monc_get_dh(MONC_INSTANCE *inst)
-{
-  return tr_gssc_get_dh(inst->gssc);
-}
-
-DH *monc_set_dh(MONC_INSTANCE *inst, DH *dh)
-{
-  return tr_gssc_set_dh(inst->gssc, dh);
-}
index cb70d3b..b0a0400 100644 (file)
@@ -237,11 +237,23 @@ int mons_accept(MONS_INSTANCE *mons, int listen)
 
   if (pid == 0) {
     close(listen);
-    tr_gss_handle_connection(conn,
-                             "trustmonitor", mons->hostname, /* acceptor name */
-                             mons->auth_handler, mons->cookie, /* auth callback and cookie */
-                             mons_req_cb, mons /* req callback and cookie */
-    );
+    switch(tr_gss_handle_connection(conn,
+                                    "trustmonitor", mons->hostname, /* acceptor name */
+                                    mons->auth_handler, mons->cookie, /* auth callback and cookie */
+                                    mons_req_cb, mons /* req callback and cookie */
+    )) {
+      case TR_GSS_SUCCESS:
+        /* do nothing */
+        break;
+
+      case TR_GSS_ERROR:
+        tr_debug("mons_accept: Error returned by tr_gss_handle_connection()");
+        break;
+
+      default:
+        tr_err("mons_accept: Unexpected value returned by tr_gss_handle_connection()");
+        break;
+    }
     close(conn);
     exit(0); /* exit to kill forked child process */
   }
index 5e19db0..24cce1f 100644 (file)
@@ -34,7 +34,7 @@
 
 /* Handlers for monitoring requests */
 
-#include <gmodule.h>
+#include <glib.h>
 
 #include <tr_debug.h>
 #include <mon_internal.h>
diff --git a/mon/tests/req_reconfigure.test b/mon/tests/req_reconfigure.test
deleted file mode 100644 (file)
index 75f1690..0000000
+++ /dev/null
@@ -1 +0,0 @@
-{"command": "reconfigure"}
diff --git a/mon/tests/resp_reconfigure_error.test b/mon/tests/resp_reconfigure_error.test
deleted file mode 100644 (file)
index 3344bb1..0000000
+++ /dev/null
@@ -1 +0,0 @@
-{"code": 1, "message": "error"}
diff --git a/mon/tests/resp_reconfigure_success.test b/mon/tests/resp_reconfigure_success.test
deleted file mode 100644 (file)
index 392c2e0..0000000
+++ /dev/null
@@ -1 +0,0 @@
-{"code": 0, "message": "success"}
index 19ad64d..7c76b18 100644 (file)
 #include <mon_internal.h>
 
 /**
- * @return reconfigure command
- */
-static MON_REQ *reconfigure()
-{
-  MON_REQ *req = mon_req_new(NULL, MON_CMD_RECONFIGURE);
-  assert(req);
-  return req;
-}
-
-/**
  * @return show command with no options
  */
 static MON_REQ *show_plain()
@@ -124,9 +114,6 @@ static int run_test(const char *filename, MON_REQ *(generator)())
 int main(void)
 {
 
-  // Test reconfigure command
-  assert(run_test("req_reconfigure.test", reconfigure));
-
   // Test show command with no options
   assert(run_test("req_show_no_options.test", show_plain));
 
index d3ae49c..eb48ce9 100644 (file)
 
 #define JSON_DUMP_OPTS 0
 
-static char *reconfigure()
-{
-  MON_REQ *req = mon_req_new(NULL, MON_CMD_RECONFIGURE);
-  json_t *req_json = mon_req_encode(req);
-  char *result = json_dumps(req_json, JSON_DUMP_OPTS);
-  assert(req);
-  assert(req_json);
-  assert(result);
-  json_decref(req_json);
-  mon_req_free(req);
-  return result;
-}
-
 static char *show_plain()
 {
   MON_REQ *req = mon_req_new(NULL, MON_CMD_SHOW);
@@ -81,14 +68,6 @@ int main(void)
   MON_OPT_TYPE opts[10];
   char *expected = NULL;
 
-  // Test reconfigure command
-  s = reconfigure();
-  expected = read_file("req_reconfigure.test");
-  assert(expected);
-  assert(strcmp(expected, s) == 0);
-  free(s);
-  free(expected);
-
   // Test show without options
   s = show_plain();
   expected = read_file("req_show_no_options.test");
index 6945b76..c9d6d2c 100644 (file)
 
 #define JSON_DUMP_OPTS 0
 
-static char *reconfigure(MON_RESP_CODE code, const char *message)
-{
-  MON_REQ *req = NULL;
-  MON_RESP *resp = NULL;
-  json_t *resp_json = NULL;
-  char *result = NULL;
-
-  req = mon_req_new(NULL, MON_CMD_RECONFIGURE);
-  assert(req);
-
-  resp = mon_resp_new(NULL, code, message, NULL);
-  assert(resp);
-
-  resp_json = mon_resp_encode(resp);
-  assert(resp_json);
-
-  result = json_dumps(resp_json, JSON_DUMP_OPTS);
-  assert(result);
-
-  json_decref(resp_json);
-  mon_resp_free(resp);
-  mon_req_free(req);
-  return result;
-}
-
-static char *reconfigure_success()
-{
-  return reconfigure(MON_RESP_SUCCESS, "success");
-}
-
-static char *reconfigure_error()
-{
-  return reconfigure(MON_RESP_ERROR, "error");
-}
-
 static char *show_success()
 {
   MON_REQ *req = NULL;
@@ -123,8 +88,6 @@ int run_test(const char *filename, char *(generator)())
 
 int main(void)
 {
-  assert(run_test("resp_reconfigure_success.test", reconfigure_success));
-  assert(run_test("resp_reconfigure_error.test", reconfigure_error));
   assert(run_test("resp_show_success.test", show_success));
   return 0;
 }
index 90335f0..1cff6f0 100644 (file)
 
 int tmp_len = 32;
 
+static int tidc_destructor(void *obj)
+{
+  TIDC_INSTANCE *tidc=talloc_get_type_abort(obj, TIDC_INSTANCE);
+  if (NULL!=tidc) {
+    if (NULL!=tidc->client_dh)
+      tr_destroy_dh_params(tidc->client_dh);
+  }
+  return 0;
+}
+
+
 /* creates struct in talloc null context */
 TIDC_INSTANCE *tidc_create(void)
 {
@@ -56,8 +67,9 @@ TIDC_INSTANCE *tidc_create(void)
       talloc_free(tidc);
       return NULL;
     }
-
     tidc->gssc->service_name = "trustidentity";
+    tidc->client_dh = NULL;
+    talloc_set_destructor((void *)tidc, tidc_destructor);
   }
   return tidc;
 }
@@ -129,7 +141,7 @@ int tidc_send_request (TIDC_INSTANCE *tidc,
     goto error;
   }
 
-  tid_req->tidc_dh = tr_dh_dup(tidc->gssc->client_dh);
+  tid_req->tidc_dh = tr_dh_dup(tidc_get_dh(tidc));
 
   /* generate an ID */
   request_id = tr_random_id(NULL);
@@ -219,12 +231,13 @@ int tidc_fwd_request(TIDC_INSTANCE *tidc,
 }
 
 
-DH * tidc_get_dh(TIDC_INSTANCE *inst)
+DH *tidc_get_dh(TIDC_INSTANCE *inst)
 {
-  return tr_gssc_get_dh(inst->gssc);
+  return inst->client_dh;
 }
 
 DH *tidc_set_dh(TIDC_INSTANCE *inst, DH *dh)
 {
-  return tr_gssc_set_dh(inst->gssc, dh);
+  inst->client_dh = dh;
+  return dh;
 }
index 74e790e..0569333 100644 (file)
@@ -397,6 +397,54 @@ nfds_t tids_get_listener(TIDS_INSTANCE *tids,
   return (int)n_fd;
 }
 
+/* Strings used to report results from the handler process. The
+ * TIDS_MAX_MESSAGE_LEN must be longer than the longest message, including
+ * null termination (i.e., strlen() + 1) */
+#define TIDS_MAX_MESSAGE_LEN (10)
+#define TIDS_SUCCESS_MESSAGE "OK"
+#define TIDS_ERROR_MESSAGE   "ERR"
+
+/**
+ * Process to handle an incoming TIDS request
+ *
+ * This should be run in the child process after a fork(). Handles
+ * the request, writes the result to result_fd, and terminates via exit().
+ * Never returns to the caller.
+ *
+ * @param tids TID server instance
+ * @param conn_fd file descriptor for the incoming connection
+ * @param result_fd writable file descriptor for the result, or 0 to disable reporting
+ */
+static void tids_handle_proc(TIDS_INSTANCE *tids, int conn_fd, int result_fd)
+{
+  const char *response_message = NULL;
+
+  switch(tr_gss_handle_connection(conn_fd,
+                                  "trustidentity", tids->hostname, /* acceptor name */
+                                  tids->auth_handler, tids->cookie, /* auth callback and cookie */
+                                  tids_req_cb, tids /* req callback and cookie */
+  )) {
+    case TR_GSS_SUCCESS:
+      response_message = TIDS_SUCCESS_MESSAGE;
+      break;
+
+    case TR_GSS_ERROR:
+    default:
+      response_message = TIDS_ERROR_MESSAGE;
+      break;
+  }
+
+  if (0 != result_fd) {
+    /* write strlen + 1 to include the null termination */
+    if (write(result_fd, response_message, strlen(response_message) + 1) < 0)
+      tr_err("tids_accept: child process unable to write to pipe");
+  }
+
+  close(result_fd);
+  close(conn_fd);
+  exit(0); /* exit to kill forked child process */
+}
+
 /* Accept and process a connection on a port opened with tids_get_listener() */
 int tids_accept(TIDS_INSTANCE *tids, int listen)
 {
@@ -422,26 +470,22 @@ int tids_accept(TIDS_INSTANCE *tids, int listen)
   }
 
   if (pid == 0) {
-    close(pipe_fd[0]); /* child only writes */
-    close(listen);
-    tr_gss_handle_connection(conn,
-                             "trustidentity", tids->hostname, /* acceptor name */
-                             tids->auth_handler, tids->cookie, /* auth callback and cookie */
-                             tids_req_cb, tids /* req callback and cookie */
-    );
-    if (write(pipe_fd[1], "OK\0", 3) < 0)
-      tr_crit("tids_accept: child process unable to write to pipe");
-    close(pipe_fd[1]);
-    close(conn);
-    exit(0); /* exit to kill forked child process */
+    /* Only the child process gets here */
+    close(pipe_fd[0]); /* close the read end of the pipe, the child only writes */
+    close(listen); /* close the child process's handle on the listen port */
+
+    tids_handle_proc(tids, conn, pipe_fd[1]); /* never returns */
   }
 
   /* Only the parent process gets here */
-  close(pipe_fd[1]); /* parent only listens */
-  close(conn); /* connection belongs to the child */
+  close(pipe_fd[1]); /* close the write end of the pipe, the parent only listens */
+  close(conn); /* connection belongs to the child, so close parent's handle */
+
+  /* remember the PID of our child process */
+  tr_info("tids_accept: Spawned TID process %d to handle incoming connection.", pid);
   tp.pid = pid;
   tp.read_fd = pipe_fd[0];
-  g_array_append_val(tids->pids, tp); /* remember the PID of our child process */
+  g_array_append_val(tids->pids, tp);
 
   /* clean up any processes that have completed */
   tids_sweep_procs(tids);
@@ -463,7 +507,7 @@ void tids_sweep_procs(TIDS_INSTANCE *tids)
 {
   guint ii;
   struct tid_process tp = {0};
-  char result[10] = {0};
+  char result[TIDS_MAX_MESSAGE_LEN] = {0};
   ssize_t result_len;
   int status;
   int wait_rc;
@@ -506,15 +550,15 @@ void tids_sweep_procs(TIDS_INSTANCE *tids)
     }
 
     /* read the pipe - if the TID request worked, it will have written status before terminating */
-    result_len = read(tp.read_fd, result, sizeof(result)/sizeof(result[0]));
+    result_len = read(tp.read_fd, result, TIDS_MAX_MESSAGE_LEN);
     close(tp.read_fd);
 
-    if ((result_len > 0) && (strcmp(result, "OK") == 0)) {
+    if ((result_len > 0) && (strcmp(result, TIDS_SUCCESS_MESSAGE) == 0)) {
       tids->req_count++;
-      tr_debug("tids_sweep_procs: TID process %d succeeded", tp.pid);
+      tr_info("tids_sweep_procs: TID process %d exited successfully.", tp.pid);
     } else {
       tids->error_count++;
-      tr_debug("tids_sweep_procs: TID process %d failed", tp.pid);
+      tr_info("tids_sweep_procs: TID process %d exited with an error.", tp.pid);
     }
   }
 }
index e6d4253..761b433 100644 (file)
@@ -44,7 +44,7 @@
 /* command-line option setup */
 static void print_version_info(void)
 {
-  printf("Moonshot TR Monitoring Client %s\n\n", PACKAGE_VERSION);
+  printf("Moonshot Trust Router Monitoring Client %s\n\n", PACKAGE_VERSION);
 }
 
 
@@ -52,7 +52,7 @@ static void print_version_info(void)
 const char *argp_program_bug_address=PACKAGE_BUGREPORT; /* bug reporting address */
 
 /* doc strings */
-static const char doc[]=PACKAGE_NAME " - Moonshot TR Monitoring Client";
+static const char doc[]=PACKAGE_NAME " - Moonshot Trust Router Monitoring Client";
 static const char arg_doc[]="<server> <port> <command> [<option> ...]"; /* string describing arguments, if any */
 
 /* define the options here. Fields are:
@@ -170,21 +170,13 @@ int main(int argc, char *argv[])
   tr_log_threshold(LOG_CRIT);
   tr_console_threshold(LOG_WARNING);
 
-  /* Create a MON client instance & the client DH */
+  /* Create a MON client instance */
   monc = monc_new(main_ctx);
   if (monc == NULL) {
     printf("Error allocating client instance.\n");
     goto cleanup;
   }
 
-
-  /* fill in the DH parameters */
-  monc_set_dh(monc, tr_create_dh_params(NULL, 0));
-  if (monc_get_dh(monc) == NULL) {
-    printf("Error creating client DH params.\n");
-    goto cleanup;
-  }
-
   /* Set-up MON connection */
   if (0 != monc_open_connection(monc, opts.server, opts.port)) {
     /* Handle error */
@@ -193,8 +185,14 @@ int main(int argc, char *argv[])
   };
 
   req = mon_req_new(main_ctx, opts.command);
-  for (ii=0; ii < opts.n_options; ii++)
-    mon_req_add_option(req, opts.options[ii]);
+  for (ii=0; ii < opts.n_options; ii++) {
+    if (MON_SUCCESS != mon_req_add_option(req, opts.options[ii])) {
+      printf("Error adding option '%s' to request. Request not sent.\n",
+             mon_opt_type_to_string(opts.options[ii]));
+      goto cleanup;
+    }
+
+  }
 
   /* Send a MON request and get the response */
   resp = monc_send_request(main_ctx, monc, req);
index f04b4dd..039bf51 100644 (file)
@@ -49,7 +49,7 @@
 const char *argp_program_bug_address=PACKAGE_BUGREPORT; /* bug reporting address */
 
 /* doc strings */
-static const char doc[]=PACKAGE_NAME " - TRP Client";
+static const char doc[]=PACKAGE_NAME " - Moonshot Trust Router TRP Client";
 static const char arg_doc[]="<message> <server> [<port>]"; /* string describing arguments, if any */
 
 /* define the options here. Fields are:
index b169e17..a1cc64f 100644 (file)
@@ -38,6 +38,7 @@
 #include <tr_gss_names.h>
 #include <trp_peer.h>
 #include <tr_util.h>
+#include <tr_json_util.h>
 
 char *trp_peer_to_str(TALLOC_CTX *memctx, TRP_PEER *peer, const char *sep)
 {
@@ -76,15 +77,6 @@ static json_t *last_attempt_to_json_string(TRP_PEER *peer)
   return jstr;
 }
 
-/* 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 *trp_peer_to_json(TRP_PEER *peer)
 {
   json_t *peer_json = NULL;
index c954a81..7cbb3ac 100644 (file)
@@ -44,6 +44,7 @@
 #include <trp_rtable.h>
 #include <trust_router/trp.h>
 #include <tr_util.h>
+#include <tr_json_util.h>
 
 /* Pretty print a route table entry to a newly allocated string. If sep is NULL,
  * returns comma+space separated string. */
@@ -103,21 +104,6 @@ static json_t *expiry_to_json_string(TRP_ROUTE *route)
   return jstr;
 }
 
-/* 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 OBJECT_SET_OR_SKIP(jobj, key, val)     \
-do {                                           \
-  if (val)                                     \
-    json_object_set_new((jobj),(key),(val));   \
-} while (0)
-
 json_t *trp_route_to_json(TRP_ROUTE *route)
 {
   json_t *route_json = NULL;
index b962bcd..2283be0 100644 (file)
@@ -1,6 +1,6 @@
 %global optflags %{optflags} -Wno-parentheses
 Name:           trust_router
-Version:        3.4.0~1
+Version:        3.4.0~2
 Release:        1%{?dist}
 Summary:        Moonshot Trust Router
 
@@ -118,6 +118,7 @@ chmod 770 /var/log/trust_router
 #%{_bindir}/tidc-wrapper
 #%{_bindir}/tids
 #%{_bindir}/tids-wrapper
+#%{_bindir}/trmon
 #%{_bindir}/trust_router
 #%{_bindir}/trust_router-wrapper
 %{_bindir}/*