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)
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);
}
}
/*
- * 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)
{
#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 *);
* @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;
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);
goto cleanup;
}
+ /* we successfully sent a response */
+ rc = TR_GSS_SUCCESS;
+
cleanup:
talloc_free(tmp_ctx);
+ return rc;
}
#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;
}
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;
-}
#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)
{
}
-/* 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();
#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)
{
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)
#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 */
enum mon_cmd {
MON_CMD_UNKNOWN=0,
- MON_CMD_RECONFIGURE,
MON_CMD_SHOW
};
/* 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);
#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;
struct tidc_instance {
TR_GSSC_INSTANCE *gssc;
+ DH *client_dh;
};
struct tid_process {
#include <syslog.h>
#include <sys/time.h>
#include <talloc.h>
-#include <gmodule.h>
+#include <glib.h>
#include <tr_comm.h>
#include <tr_rp.h>
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
#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;
/* Client instance */
struct tr_gssc_instance {
const char *service_name;
- DH *client_dh;
gss_ctx_id_t *gss_ctx;
int conn;
};
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
--- /dev/null
+/*
+ * 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
#include <talloc.h>
-#include <gmodule.h>
+#include <glib.h>
#include <string.h>
#include <mon_internal.h>
case MON_CMD_UNKNOWN:
return NULL;
- case MON_CMD_RECONFIGURE:
- return "reconfigure";
-
case MON_CMD_SHOW:
return "show";
}
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;
}
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";
#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
#include <mon_internal.h>
-// Monitoring request decoders
+/* Monitoring request decoders */
/**
* Decode a single option
&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;
}
#include <mon_internal.h>
-// Monitoring request encoders
+/* Monitoring request encoders */
/**
* Encode options array as a JSON array
* @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
/* 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;
#include <mon_internal.h>
-// Monitoring request message common code
+/* Monitoring response message common code */
/**
* Destructor used by talloc to ensure proper cleanup
#include <mon_internal.h>
-// Monitoring response decoder
+/* Monitoring response decoder */
/**
* Decode a JSON response
#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. */
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);
-}
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 */
}
/* Handlers for monitoring requests */
-#include <gmodule.h>
+#include <glib.h>
#include <tr_debug.h>
#include <mon_internal.h>
+++ /dev/null
-{"command": "reconfigure"}
+++ /dev/null
-{"code": 1, "message": "error"}
+++ /dev/null
-{"code": 0, "message": "success"}
#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()
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));
#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);
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");
#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;
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;
}
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)
{
talloc_free(tidc);
return NULL;
}
-
tidc->gssc->service_name = "trustidentity";
+ tidc->client_dh = NULL;
+ talloc_set_destructor((void *)tidc, tidc_destructor);
}
return 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);
}
-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;
}
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)
{
}
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);
{
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;
}
/* 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);
}
}
}
/* 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);
}
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:
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 */
};
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);
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:
#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)
{
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;
#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. */
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;
%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
#%{_bindir}/tidc-wrapper
#%{_bindir}/tids
#%{_bindir}/tids-wrapper
+#%{_bindir}/trmon
#%{_bindir}/trust_router
#%{_bindir}/trust_router-wrapper
%{_bindir}/*