From 6d0224da56b57446291c021b55f782cc6777f24c Mon Sep 17 00:00:00 2001 From: Margaret Wasserman Date: Wed, 12 Mar 2014 08:29:25 -0400 Subject: [PATCH] Allow the Trust Router's TIDS port to be set in the internal config. --- common/tr_config.c | 12 ++++++++++++ include/tr.h | 2 -- include/tr_config.h | 3 +++ include/trust_router/tid.h | 4 ++-- tid/example/tids_main.c | 2 +- tid/tids.c | 3 ++- tr/manual.cfg | 3 ++- tr/tr_main.c | 2 +- 8 files changed, 23 insertions(+), 8 deletions(-) diff --git a/common/tr_config.c b/common/tr_config.c index 628db65..64ba9ae 100644 --- a/common/tr_config.c +++ b/common/tr_config.c @@ -66,6 +66,7 @@ TR_CFG_RC tr_apply_new_config (TR_INSTANCE *tr) { static TR_CFG_RC tr_cfg_parse_internal (TR_INSTANCE *tr, json_t *jcfg) { json_t *jint = NULL; json_t *jmtd = NULL; + json_t *jtp = NULL; json_t *jhname = NULL; if ((!tr) || (!tr->new_cfg) || (!jcfg)) @@ -88,6 +89,17 @@ static TR_CFG_RC tr_cfg_parse_internal (TR_INSTANCE *tr, json_t *jcfg) { /* If not configured, use the default */ tr->new_cfg->internal->max_tree_depth = TR_DEFAULT_MAX_TREE_DEPTH; } + if (NULL != (jtp = json_object_get(jint, "tids_port"))) { + if (json_is_number(jtp)) { + tr->new_cfg->internal->tids_port = json_integer_value(jtp); + } else { + fprintf(stderr,"tr_cfg_parse_internal: Parsing error, port is not a number.\n"); + return TR_CFG_NOPARSE; + } + } else { + /* If not configured, use the default */ + tr->new_cfg->internal->tids_port = TR_DEFAULT_TIDS_PORT; + } if (NULL != (jhname = json_object_get(jint, "hostname"))) { if (json_is_string(jhname)) { tr->new_cfg->internal->hostname = json_string_value(jhname); diff --git a/include/tr.h b/include/tr.h index 5c01c4a..dd2b1bf 100644 --- a/include/tr.h +++ b/include/tr.h @@ -40,8 +40,6 @@ #include #include -#define TRUST_ROUTER_PORT 12308 - typedef struct tr_instance { struct tr_cfg *new_cfg; /* unapplied configuration */ struct tr_cfg *active_cfg; diff --git a/include/tr_config.h b/include/tr_config.h index b973372..1d5256b 100644 --- a/include/tr_config.h +++ b/include/tr_config.h @@ -45,6 +45,8 @@ #include #define TR_DEFAULT_MAX_TREE_DEPTH 12 +#define TR_DEFAULT_TR_PORT 12308 +#define TR_DEFAULT_TIDS_PORT 12309 typedef enum tr_cfg_rc { TR_CFG_SUCCESS = 0, /* No error */ @@ -56,6 +58,7 @@ typedef enum tr_cfg_rc { typedef struct tr_cfg_internal { unsigned int max_tree_depth; + unsigned int tids_port; const char *hostname; } TR_CFG_INTERNAL; diff --git a/include/trust_router/tid.h b/include/trust_router/tid.h index ce2ad3d..76e2cdd 100644 --- a/include/trust_router/tid.h +++ b/include/trust_router/tid.h @@ -166,8 +166,8 @@ TR_EXPORT void tidc_destroy (TIDC_INSTANCE *tidc); /* TID Server functions, in tid/tids.c */ TR_EXPORT TIDS_INSTANCE *tids_create (void); TR_EXPORT int tids_start (TIDS_INSTANCE *tids, TIDS_REQ_FUNC *req_handler, - tids_auth_func *auth_handler, const char *hostname, - void *cookie); + tids_auth_func *auth_handler, const char *hostname, + unsigned int port, void *cookie); TR_EXPORT int tids_send_response (TIDS_INSTANCE *tids, TID_REQ *req, TID_RESP *resp); TR_EXPORT int tids_send_err_response (TIDS_INSTANCE *tids, TID_REQ *req, const char *err_msg); TR_EXPORT void tids_destroy (TIDS_INSTANCE *tids); diff --git a/tid/example/tids_main.c b/tid/example/tids_main.c index 5495dc6..766c24f 100644 --- a/tid/example/tids_main.c +++ b/tid/example/tids_main.c @@ -189,7 +189,7 @@ int main (int argc, tids->ipaddr = ipaddr; /* Start-up the server, won't return unless there is an error. */ - rc = tids_start(tids, &tids_req_handler , auth_handler, hostname, gssname); + rc = tids_start(tids, &tids_req_handler , auth_handler, hostname, TID_PORT, gssname); fprintf(stdout, "Error in tids_start(), rc = %d. Exiting.\n", rc); diff --git a/tid/tids.c b/tid/tids.c index acdf332..26e14af 100644 --- a/tid/tids.c +++ b/tid/tids.c @@ -351,13 +351,14 @@ int tids_start (TIDS_INSTANCE *tids, TIDS_REQ_FUNC *req_handler, tids_auth_func *auth_handler, const char *hostname, + unsigned int port, void *cookie) { int listen = -1; int conn = -1; pid_t pid; - if (0 > (listen = tids_listen(tids, TID_PORT))) + if (0 > (listen = tids_listen(tids, port))) perror ("Error from tids_listen()"); /* store the caller's request handler & cookie */ diff --git a/tr/manual.cfg b/tr/manual.cfg index 3df6413..a1259ab 100644 --- a/tr/manual.cfg +++ b/tr/manual.cfg @@ -1,2 +1,3 @@ {"tr_internal":{"max_tree_depth": 4, - "hostname":"tr.painless-security.com"}} \ No newline at end of file + "tids_port": 12309, + "hostname":"moonshot-proxy.local"}} \ No newline at end of file diff --git a/tr/tr_main.c b/tr/tr_main.c index 9607ed9..d229e33 100644 --- a/tr/tr_main.c +++ b/tr/tr_main.c @@ -279,7 +279,7 @@ int main (int argc, const char *argv[]) } /* start the trust path query server, won't return unless fatal error. */ - if (0 != (err = tids_start(tr->tids, &tr_tids_req_handler, &tr_tids_gss_handler, tr->active_cfg->internal->hostname, (void *)tr))) { + if (0 != (err = tids_start(tr->tids, &tr_tids_req_handler, &tr_tids_gss_handler, tr->active_cfg->internal->hostname, tr->active_cfg->internal->tids_port, (void *)tr))) { fprintf (stderr, "Error from Trust Path Query Server, err = %d.\n", err); exit(err); } -- 2.1.4