Allow the Trust Router's TIDS port to be set in the internal config.
authorMargaret Wasserman <mrw@painless-security.com>
Wed, 12 Mar 2014 12:29:25 +0000 (08:29 -0400)
committerMargaret Wasserman <mrw@painless-security.com>
Wed, 12 Mar 2014 12:29:25 +0000 (08:29 -0400)
common/tr_config.c
include/tr.h
include/tr_config.h
include/trust_router/tid.h
tid/example/tids_main.c
tid/tids.c
tr/manual.cfg
tr/tr_main.c

index 628db65..64ba9ae 100644 (file)
@@ -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);
index 5c01c4a..dd2b1bf 100644 (file)
@@ -40,8 +40,6 @@
 #include <tr_msg.h>
 #include <tr_rp.h>
 
-#define TRUST_ROUTER_PORT      12308
-
 typedef struct tr_instance {
   struct tr_cfg *new_cfg;      /* unapplied configuration */
   struct tr_cfg *active_cfg;
index b973372..1d5256b 100644 (file)
@@ -45,6 +45,8 @@
 #include <tr_comm.h>
 
 #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;
 
index ce2ad3d..76e2cdd 100644 (file)
@@ -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);
index 5495dc6..766c24f 100644 (file)
@@ -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);
 
index acdf332..26e14af 100644 (file)
@@ -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 */
index 3df6413..a1259ab 100644 (file)
@@ -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
index 9607ed9..d229e33 100644 (file)
@@ -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);
   }