Merge branch 'jennifer/march2016-patches'
authorJennifer Richards <jennifer@painless-security.com>
Mon, 20 Jun 2016 17:39:31 +0000 (13:39 -0400)
committerJennifer Richards <jennifer@painless-security.com>
Mon, 20 Jun 2016 17:39:31 +0000 (13:39 -0400)
Conflicts (both trivial):
common/tr_config.c
common/tr_name.c

common/tr_comm.c
common/tr_config.c
common/tr_name.c
include/tr_config.h
include/trust_router/tid.h
include/trust_router/tr_name.h
tid/tidc.c
tr/tr_main.c
trust_router.spec

index 08d6638..9b79850 100644 (file)
@@ -47,9 +47,9 @@ TR_IDP_REALM *tr_find_comm_idp (TR_COMM *comm, TR_NAME *idp_realm)
     return NULL;
   }
 
-  for (idp = comm->idp_realms; NULL != idp; idp = idp->next) {
+  for (idp = comm->idp_realms; NULL != idp; idp = idp->comm_next) {
     if (!tr_name_cmp (idp_realm, idp->realm_id)) {
-      tr_debug("tr_find_comm_idp: Found %s.", idp_realm->buf);
+      tr_debug("tr_find_comm_idp: Found IdP %s in community %s.", idp_realm->buf, comm->id->buf);
       return idp;
     }
   }
@@ -67,7 +67,7 @@ TR_RP_REALM *tr_find_comm_rp (TR_COMM *comm, TR_NAME *rp_realm)
 
   for (rp = comm->rp_realms; NULL != rp; rp = rp->next) {
     if (!tr_name_cmp (rp_realm, rp->realm_name)) {
-      tr_debug("tr_find_comm_idp: Found %s.", rp_realm->buf);
+      tr_debug("tr_find_comm_rp: Found RP %s in community %s.", rp_realm->buf, comm->id->buf);
       return rp;
     }
   }
index fbd5027..587a47c 100644 (file)
 #include <tr_filter.h>
 #include <trust_router/tr_constraint.h>
 
-void tr_print_config (FILE *stream, TR_CFG *cfg) {
-  fprintf(stream, "tr_print_config: Not yet implemented.");
-  return;
+void tr_print_config (TR_CFG *cfg) {
+  tr_notice("tr_print_config: Logging running trust router configuration.");
+  tr_print_comms(cfg->comms);
+}
+
+void tr_print_comms (TR_COMM *comm_list) {
+  TR_COMM *comm = NULL;
+
+  for (comm = comm_list; NULL != comm; comm = comm->next) {
+    tr_notice("tr_print_config: Community %s:", comm->id->buf);
+
+    tr_notice("tr_print_config:  - Member IdPs:");
+    tr_print_comm_idps(comm->idp_realms);
+
+    tr_notice("tr_print_config:  - Member RPs:");
+    tr_print_comm_rps(comm->rp_realms);
+  }
+}
+
+void tr_print_comm_idps (TR_IDP_REALM *idp_list) {
+  TR_IDP_REALM *idp = NULL;
+
+  for (idp = idp_list; NULL != idp; idp = idp->comm_next) {
+    tr_notice("tr_print_config:    - @%s", idp->realm_id->buf);
+  }
+}
+
+void tr_print_comm_rps(TR_RP_REALM *rp_list) {
+  TR_RP_REALM *rp = NULL;
+
+  for (rp = rp_list; NULL != rp; rp = rp->next) {
+    tr_notice("tr_print_config:    - %s", rp->realm_name->buf);
+  }
 }
 
 void tr_cfg_free (TR_CFG *cfg) {
@@ -649,6 +679,7 @@ static TR_CFG_RC tr_cfg_parse_idp_realms (TR_CFG *trc, json_t *jcfg)
 static TR_IDP_REALM *tr_cfg_parse_comm_idps (TR_CFG *trc, json_t *jidps, TR_CFG_RC *rc)
 {
   TR_IDP_REALM *idp = NULL;
+  TR_IDP_REALM *found_idp = NULL;
   TR_IDP_REALM *temp_idp = NULL;
   int i = 0;
 
@@ -661,7 +692,15 @@ static TR_IDP_REALM *tr_cfg_parse_comm_idps (TR_CFG *trc, json_t *jidps, TR_CFG_
   }
 
   for (i = 0; i < json_array_size(jidps); i++) {
-    if (NULL == (temp_idp = (tr_cfg_find_idp(trc, 
+    if (NULL == (temp_idp = talloc(trc, TR_IDP_REALM))) {
+      tr_debug("tr_cfg_parse_comm_idps: Can't allocate memory for IdP Realm.");
+      if (rc)
+       *rc = TR_CFG_NOMEM;
+      return NULL;
+    }
+    memset (temp_idp, 0, sizeof(TR_IDP_REALM));
+
+    if (NULL == (found_idp = (tr_cfg_find_idp(trc, 
                                             tr_new_name((char *)json_string_value(json_array_get(jidps, i))), 
                                             rc)))) {
       tr_debug("tr_cfg_parse_comm_idps: Unknown IDP %s.", 
@@ -669,6 +708,9 @@ static TR_IDP_REALM *tr_cfg_parse_comm_idps (TR_CFG *trc, json_t *jidps, TR_CFG_
       return NULL;
     }
 
+    // We *MUST* do a dereferenced copy here or the second community will corrupt the linked list we create here.
+    *temp_idp = *found_idp;
+
     temp_idp->comm_next = idp;
     idp = temp_idp;
   }
@@ -875,6 +917,7 @@ static char *join_paths(const char *p1, const char *p2) {
 /* Reads configuration files in config_dir ("" or "./" will use the current directory) */
 TR_CFG_RC tr_parse_config (TR_INSTANCE *tr, const char *config_dir, int n, struct dirent **cfg_files) {
   json_t *jcfg;
+  json_t *jser;
   json_error_t rc;
   char *file_with_path;
 
@@ -907,6 +950,15 @@ TR_CFG_RC tr_parse_config (TR_INSTANCE *tr, const char *config_dir, int n, struc
     }
     talloc_free(file_with_path); /* done with filename */
 
+    // Look for serial number and log it if it exists
+    if (NULL != (jser = json_object_get(jcfg, "serial_number"))) {
+      if (json_is_number(jser)) {
+        tr_notice("tr_read_config: Attempting to load revision %i of %s.",
+                  (int *) json_integer_value(jser),
+                  cfg_files[n]->d_name);
+      }
+    }
+
     if ((TR_CFG_SUCCESS != tr_cfg_parse_internal(tr->new_cfg, jcfg)) ||
         (TR_CFG_SUCCESS != tr_cfg_parse_rp_clients(tr->new_cfg, jcfg)) ||
         (TR_CFG_SUCCESS != tr_cfg_parse_idp_realms(tr->new_cfg, jcfg)) ||
index 7e8b14f..dccf0d4 100644 (file)
@@ -43,15 +43,15 @@ void tr_free_name (TR_NAME *name)
     free (name->buf);
     name->buf = NULL;
   }
-  
+
   free(name);
 }
 
-TR_NAME *tr_new_name (char *name) 
+TR_NAME *tr_new_name (const char *name) 
 {
   TR_NAME *new;
 
-  if (new = malloc(sizeof(TR_NAME))) { 
+  if (new = malloc(sizeof(TR_NAME))) {
     new->len = strlen(name);
     if (new->buf = malloc((new->len)+1)) {
       strcpy(new->buf, name);
@@ -60,7 +60,7 @@ TR_NAME *tr_new_name (char *name)
   return new;
 }
 
-TR_NAME *tr_dup_name (TR_NAME *from) 
+TR_NAME *tr_dup_name (TR_NAME *from)
 {
   TR_NAME *to;
 
@@ -110,4 +110,4 @@ char * tr_name_strdup(TR_NAME *src)
   return s;
 }
 
-  
+
index 28b0c05..8a04415 100644 (file)
@@ -84,7 +84,11 @@ TR_CFG_RC tr_parse_config (TR_INSTANCE *tr, const char *config_dir, int n, struc
 TR_CFG_RC tr_apply_new_config (TR_INSTANCE *tr);
 TR_CFG_RC tr_cfg_validate (TR_CFG *trc);
 void tr_cfg_free(TR_CFG *cfg);
-void tr_print_config(FILE *stream, TR_CFG *cfg);
+
+void tr_print_config(TR_CFG *cfg);
+void tr_print_comms(TR_COMM *comm_list);
+void tr_print_comm_idps(TR_IDP_REALM *idp_list);
+void tr_print_comm_rps(TR_RP_REALM *rp_list);
 
 TR_IDP_REALM *tr_cfg_find_idp (TR_CFG *tr_cfg, TR_NAME *idp_id, TR_CFG_RC *rc);
 TR_RP_CLIENT *tr_cfg_find_rp (TR_CFG *tr_cfg, TR_NAME *rp_gss, TR_CFG_RC *rc);
index 4d245b8..870d60c 100644 (file)
@@ -136,8 +136,8 @@ TR_EXPORT const TID_PATH *tid_srvr_get_path(const TID_SRVR_BLK *);
 
 /* TID Client functions, in tid/tidc.c */
 TR_EXPORT TIDC_INSTANCE *tidc_create (void);
-TR_EXPORT int tidc_open_connection (TIDC_INSTANCE *tidc, char *server, unsigned int port, gss_ctx_id_t *gssctx);
-TR_EXPORT int tidc_send_request (TIDC_INSTANCE *tidc, int conn, gss_ctx_id_t gssctx, char *rp_realm, char *realm, char *coi, TIDC_RESP_FUNC *resp_handler, void *cookie);
+TR_EXPORT int tidc_open_connection (TIDC_INSTANCE *tidc, const char *server, unsigned int port, gss_ctx_id_t *gssctx);
+TR_EXPORT int tidc_send_request (TIDC_INSTANCE *tidc, int conn, gss_ctx_id_t gssctx, const char *rp_realm, const char *realm, const char *coi, TIDC_RESP_FUNC *resp_handler, void *cookie);
 TR_EXPORT int tidc_fwd_request (TIDC_INSTANCE *tidc, TID_REQ *req, TIDC_RESP_FUNC *resp_handler, void *cookie);
 TR_EXPORT DH *tidc_get_dh(TIDC_INSTANCE *);
 TR_EXPORT DH *tidc_set_dh(TIDC_INSTANCE *, DH *);
@@ -146,7 +146,7 @@ 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, 
+                         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);
index 418edb5..e571e64 100644 (file)
@@ -44,7 +44,7 @@ typedef struct tr__name {
   int len;
 } TR_NAME;
 
-TR_EXPORT TR_NAME *tr_new_name (char *name);
+TR_EXPORT TR_NAME *tr_new_name (const char *name);
 TR_EXPORT TR_NAME *tr_dup_name (TR_NAME *from);
 TR_EXPORT void tr_free_name (TR_NAME *name);
 TR_EXPORT int tr_name_cmp (TR_NAME *one, TR_NAME *two);
index 62968fb..895fce6 100644 (file)
@@ -49,7 +49,7 @@ TIDC_INSTANCE *tidc_create ()
 {
   TIDC_INSTANCE *tidc = NULL;
 
-  if (NULL == (tidc = talloc_zero(NULL, TIDC_INSTANCE))) 
+  if (NULL == (tidc = talloc_zero(NULL, TIDC_INSTANCE)))
     return NULL;
 
   return tidc;
@@ -61,7 +61,7 @@ void tidc_destroy (TIDC_INSTANCE *tidc)
 }
 
 int tidc_open_connection (TIDC_INSTANCE *tidc, 
-                         char *server,
+                         const char *server,
                          unsigned int port,
                          gss_ctx_id_t *gssctx)
 {
@@ -71,7 +71,7 @@ int tidc_open_connection (TIDC_INSTANCE *tidc,
 
   if (0 == port)
     use_port = TID_PORT;
-  else 
+  else
     use_port = port;
 
   err = gsscon_connect(server, use_port, "trustidentity", &conn, gssctx);
@@ -82,12 +82,12 @@ int tidc_open_connection (TIDC_INSTANCE *tidc,
     return -1;
 }
 
-int tidc_send_request (TIDC_INSTANCE *tidc, 
-                      int conn, 
+int tidc_send_request (TIDC_INSTANCE *tidc,
+                      int conn,
                       gss_ctx_id_t gssctx,
-                      char *rp_realm,
-                      char *realm, 
-                      char *comm,
+                      const char *rp_realm,
+                      const char *realm, 
+                      const char *comm,
                       TIDC_RESP_FUNC *resp_handler,
                       void *cookie)
 {
@@ -119,8 +119,8 @@ int tidc_send_request (TIDC_INSTANCE *tidc,
   return rc;
 }
 
-int tidc_fwd_request (TIDC_INSTANCE *tidc, 
-                     TID_REQ *tid_req, 
+int tidc_fwd_request (TIDC_INSTANCE *tidc,
+                     TID_REQ *tid_req,
                      TIDC_RESP_FUNC *resp_handler,
                      void *cookie)
 {
@@ -142,7 +142,7 @@ int tidc_fwd_request (TIDC_INSTANCE *tidc,
   /* store the response function and cookie */
   // tid_req->resp_func = resp_handler;
   // tid_req->cookie = cookie;
-  
+
 
   /* Encode the request into a json string */
   if (!(req_buf = tr_msg_encode(msg))) {
@@ -154,7 +154,7 @@ int tidc_fwd_request (TIDC_INSTANCE *tidc,
   tr_debug( "%s\n", req_buf);
 
   /* Send the request over the connection */
-  if (err = gsscon_write_encrypted_token (tid_req->conn, tid_req->gssctx, req_buf, 
+  if (err = gsscon_write_encrypted_token (tid_req->conn, tid_req->gssctx, req_buf,
                                          strlen(req_buf))) {
     tr_err( "tidc_fwd_request: Error sending request over connection.\n");
     goto error;
@@ -183,7 +183,7 @@ int tidc_fwd_request (TIDC_INSTANCE *tidc,
     tr_err( "tidc_fwd_request: Error, no response in the response!\n");
     goto error;
   }
-  
+
   if (resp_handler)
     /* Call the caller's response function */
     (*resp_handler)(tidc, tid_req, tr_msg_get_resp(resp_msg), cookie);
index 78c0bb0..2590474 100644 (file)
@@ -364,6 +364,9 @@ int main (int argc, char *argv[])
     exit(1);
   }
 
+  /* print the loaded configuration */
+  tr_print_config(tr->active_cfg);
+
   /* initialize the trust path query server instance */
   if (0 == (tr->tids = tids_create ())) {
     tr_crit("Error initializing Trust Path Query Server instance.");
index 989a029..8a0cef3 100644 (file)
@@ -1,7 +1,7 @@
 %global optflags %{optflags} -Wno-parentheses
 Name:           trust_router
-Version:        1.5.1
-Release:        2%{?dist}
+Version:        1.5.2
+Release:        1%{?dist}
 Summary:        Moonshot Trust Router
 
 Group:          System Environment/Libraries
@@ -10,9 +10,10 @@ URL:            http://www.project-moonshot.org/
 Source0:        %{name}-%{version}.tar.gz
 BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
 
-BuildRequires:  krb5-devel , glib-devel
+BuildRequires:  krb5-devel, glib2-devel
 BuildRequires: jansson-devel >= 2.4
 BuildRequires: sqlite-devel, openssl-devel, libtalloc-devel
+BuildRequires: systemd
 Requires:       moonshot-gss-eap >= 0.9.3, sqlite
 
 %description
@@ -114,11 +115,12 @@ chmod 770 /var/log/trust_router
 %doc README
 %{_bindir}/*
 %{_datadir}/trust_router/schema.sql
-#/lib/systemd/system/tids.service
 
 %{_initrddir}/tids
 %{_initrddir}/trust_router
 
+%{_unitdir}/tids.service
+
 %config(noreplace) %{_sysconfdir}/sysconfig/tids
 %config(noreplace) %{_sysconfdir}/sysconfig/trust_router