Real syslog support for trust router
authorSam Hartman <hartmans@debian.org>
Tue, 10 Mar 2015 00:45:38 +0000 (20:45 -0400)
committerSam Hartman <hartmans@debian.org>
Tue, 10 Mar 2015 00:45:38 +0000 (20:45 -0400)
Merge branch 'logging_changes' of https://github.com/adam-bishop/trust_router

Conflicts:
common/tr_config.c
common/tr_msg.c
tr/tr_main.c

Makefile.am
common/tr_config.c
common/tr_msg.c
configure.ac
include/tid_internal.h
include/tr_comm.h
include/trust_router/tid.h
tid/tid_req.c
tid/tid_resp.c
tid/tidc.c
tr/tr_main.c

index 1010e42..1de53be 100644 (file)
@@ -1,8 +1,8 @@
 DISTCHECK_CONFIGURE_FLAGS = \
        --with-systemdsystemunitdir=$$dc_install_base/$(systemdsystemunitdir)
 bin_PROGRAMS= tr/trust_router tid/example/tidc tid/example/tids common/dh_test/tr_dh_test
-AM_CPPFLAGS=-I$(srcdir)/include
-AM_CFLAGS = -Wall -Werror=missing-prototypes -Werror -Wno-parentheses
+AM_CPPFLAGS=-I$(srcdir)/include $(GLIB_CFLAGS)
+AM_CFLAGS = -Wall -Werror=missing-prototypes -Werror -Wno-parentheses $(GLIB_CFLAGS)
 SUBDIRS = gsscon 
 common_srcs = common/tr_name.c \
        common/tr_constraint.c \
@@ -29,11 +29,11 @@ common/tr_filter.c \
 common/tr_rp.c \
 tr/tr.c
 
-tr_trust_router_LDADD = gsscon/libgsscon.la libtr_tid.la
+tr_trust_router_LDADD = gsscon/libgsscon.la libtr_tid.la $(GLIB_LIBS)
 
 tid_example_tidc_SOURCES = tid/example/tidc_main.c 
 
-tid_example_tidc_LDADD = gsscon/libgsscon.la libtr_tid.la
+tid_example_tidc_LDADD = gsscon/libgsscon.la libtr_tid.la $(GLIB_LIBS)
 
 tid_example_tids_SOURCES = tid/example/tids_main.c 
 
@@ -47,7 +47,7 @@ libtr_tid_la_SOURCES = tid/tids.c tid/tidc.c tid/tid_req.c tid/tid_resp.c \
 $(common_srcs)
 
 libtr_tid_la_CFLAGS = $(AM_CFLAGS) -fvisibility=hidden
-libtr_tid_la_LIBADD = gsscon/libgsscon.la
+libtr_tid_la_LIBADD = gsscon/libgsscon.la $(GLIB_LIBS)
 libtr_tid_la_LDFLAGS = $(AM_LDFLAGS) -version-info 2 -no-undefined
 
 pkginclude_HEADERS = include/trust_router/tid.h include/trust_router/tr_name.h \
index 9b5dca6..4cf5d7f 100644 (file)
@@ -728,13 +728,12 @@ static TR_COMM *tr_cfg_parse_one_comm (TR_CFG *trc, json_t *jcomm, TR_CFG_RC *rc
     return NULL;
   }
 
-  if (NULL == (comm = talloc(trc, TR_COMM))) {
-    tr_debug("tr_cfg_parse_one_comm: Out of memory.");
+  if (NULL == (comm = talloc_zero(trc, TR_COMM))) {
+    tr_crit("tr_cfg_parse_one_comm: Out of memory.");
     *rc = TR_CFG_NOMEM;
     return NULL;
   }
 
-  memset(comm, 0, sizeof(TR_COMM));
 
   if ((NULL == (jid = json_object_get(jcomm, "community_id"))) ||
       (!json_is_string(jid)) ||
@@ -784,10 +783,25 @@ static TR_COMM *tr_cfg_parse_one_comm (TR_CFG *trc, json_t *jcomm, TR_CFG_RC *rc
   if (TR_CFG_SUCCESS != *rc) {
     tr_debug("tr_cfg_parse_comm: Can't parse RP realms for comm %s .", comm->id->buf);
     tr_free_name(comm->id);
-    /* TBD -- free idps? */;
     return NULL;
   }
 
+  if (TR_COMM_APC == comm->type) {
+    json_t *jexpire  = json_object_get(jcomm, "expiration_interval");
+    comm->expiration_interval = 43200; /*30 days*/
+    if (jexpire) {
+       if (!json_is_integer(jexpire)) {
+         fprintf(stderr, "tr_parse_comm: expirae_interval is not an integer\n");
+         return NULL;
+       }
+       comm->expiration_interval = json_integer_value(jexpire);
+       if (comm->expiration_interval <= 10)
+         comm->expiration_interval = 11; /* Freeradius waits 10 minutes between successful TR queries*/
+       if (comm->expiration_interval > 129600) /* 90 days*/
+       comm->expiration_interval = 129600;
+    }
+  }
+  
   return comm;
 }
 
index 841e894..5754f0c 100644 (file)
@@ -224,6 +224,7 @@ static json_t *tr_msg_encode_one_server(TID_SRVR_BLK *srvr)
 {
   json_t *jsrvr = NULL;
   json_t *jstr = NULL;
+  gchar *time_str = g_time_val_to_iso8601(&srvr->key_expiration);
 
   tr_debug("Encoding one server.");
 
@@ -233,13 +234,16 @@ static json_t *tr_msg_encode_one_server(TID_SRVR_BLK *srvr)
   jstr = json_string(inet_ntoa(srvr->aaa_server_addr));
   json_object_set_new(jsrvr, "server_addr", jstr);
 
+  json_object_set_new(jsrvr,
+                     "key_expiration", json_string(time_str));
+  g_free(time_str);
   /* Server DH Block */
   jstr = json_string(srvr->key_name->buf);
   json_object_set_new(jsrvr, "key_name", jstr);
   json_object_set_new(jsrvr, "server_dh", tr_msg_encode_dh(srvr->aaa_server_dh));
-  
-  //  tr_debug("tr_msg_encode_one_server(): jsrvr contains:");
-  //  tr_debug("%s", json_dumps(jsrvr, 0));
+  if (srvr->path)
+    /* The path is owned by the srvr, so grab an extra ref*/
+    json_object_set(jsrvr, "path", srvr->path);
   return jsrvr;
 }
 
index 474468d..664e1ca 100644 (file)
@@ -18,6 +18,7 @@ AC_PROG_CC
                    AC_SUBST([systemdsystemunitdir], [$with_systemdsystemunitdir])
            fi
            AM_CONDITIONAL(HAVE_SYSTEMD, [test -n "$with_systemdsystemunitdir" -a "x$with_systemdsystemunitdir" != xno ])
+PKG_CHECK_MODULES([GLIB], [glib-2.0])
 
 AC_CHECK_LIB([gssapi_krb5], [gss_init_sec_context])
 AC_CHECK_LIB([com_err], [error_message])
index 0593425..94faa23 100644 (file)
@@ -1,38 +1,5 @@
 /*
- * Copyright (c) 2012-2014, 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.
- *
- */
-/*
- * Copyright (c) 2012, JANET(UK)
+ * Copyright (c) 2012-2015, JANET(UK)
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
 
 #ifndef TID_INTERNAL_H
 #define TID_INTERNAL_H
+#include <glib.h>
 #include <trust_router/tid.h>
 
 #include <jansson.h>
+
 struct tid_srvr_blk {
   struct in_addr aaa_server_addr;
   TR_NAME *key_name;
   DH *aaa_server_dh;           /* AAA server's public dh information */
+  GTimeVal key_expiration; /**< absolute time at which key expires*/
+  json_t *path;/**< Path of trust routers that the request traversed*/
 };
 
 struct tid_resp {
@@ -86,8 +57,9 @@ struct tid_resp {
   TR_NAME *orig_coi;
   TID_SRVR_BLK *servers;               /* array of servers */
   size_t num_servers;
-  /* TBD -- Trust Path Used */
+  json_t *error_path; /**< Path that a request generating an error traveled*/
 };
+
 struct tid_req {
   struct tid_req *next_req;
   int resp_sent;
@@ -102,8 +74,11 @@ struct tid_req {
   DH *tidc_dh;                 /* Client's public dh information */
   TIDC_RESP_FUNC *resp_func;
   void *cookie;
-  json_t *json_references; /** References to objects dereferenced on request destruction*/
+  time_t expiration_interval; /**< Time to key expire in minutes*/
+  json_t *json_references; /**< References to objects dereferenced on request destruction*/
+  json_t *path; /**< Path of systems this request has traversed; added by receiver*/
 };
+
 struct tidc_instance {
   TID_REQ *req_list;
   // TBD -- Do we still need a separate private key */
@@ -111,6 +86,7 @@ struct tidc_instance {
   // int priv_len;
   DH *client_dh;                       /* Client's DH struct with priv and pub keys */
 };
+
 struct tids_instance {
   int req_count;
   char *priv_key;
@@ -127,4 +103,5 @@ struct tids_instance {
     reference they already hold to the TID_REQ.*/
 void tid_req_cleanup_json(TID_REQ *, json_t *json);
 
+int tid_req_add_path(TID_REQ *, const char *this_system, unsigned port);
 #endif
index 717aafd..374227b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, JANET(UK)
+ * Copyright (c) 2012, 2015, JANET(UK)
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -52,6 +52,7 @@ typedef struct tr_comm {
   TR_APC *apcs;
   TR_IDP_REALM *idp_realms;
   TR_RP_REALM *rp_realms;
+  time_t expiration_interval; /*Minutes to key expiration; only valid for an APC*/
 } TR_COMM;
 
 TR_COMM *tr_comm_lookup(TR_INSTANCE *tr, TR_NAME *comm);
index 391faca..4d245b8 100644 (file)
@@ -55,6 +55,7 @@ typedef struct tid_srvr_blk  TID_SRVR_BLK;
 
 
 typedef struct _tr_constraint_set  TR_CONSTRAINT_SET;
+typedef struct _tid_path TID_PATH;
 
 typedef struct tid_resp TID_RESP;
 
@@ -114,11 +115,18 @@ TR_EXPORT TR_NAME *tid_resp_get_orig_coi(TID_RESP *resp);
 void tid_resp_set_orig_coi(TID_RESP *resp, TR_NAME *orig_coi);
 TR_EXPORT TID_SRVR_BLK *tid_resp_get_server(TID_RESP *resp, size_t index);
 TR_EXPORT size_t tid_resp_get_num_servers(const TID_RESP *resp);
+TR_EXPORT const TID_PATH *tid_resp_get_error_path(const TID_RESP *);
+
+/** Get either the error_path or the path of the first server block for
+ * a successful response*/
+TR_EXPORT const TID_PATH *tid_resp_get_a_path(const TID_RESP *);
 /* Server blocks*/
 TR_EXPORT void tid_srvr_get_address(const TID_SRVR_BLK *,
                                    const struct sockaddr **out_addr, size_t *out_sa_len);
 TR_EXPORT DH *tid_srvr_get_dh(TID_SRVR_BLK *);
 TR_EXPORT const TR_NAME *tid_srvr_get_key_name(const TID_SRVR_BLK *);
+TR_EXPORT const TID_PATH *tid_srvr_get_path(const TID_SRVR_BLK *);
+
 
 #define tid_resp_servers_foreach(RESP, SERVER, INDEX) \
   for (INDEX=0,SERVER=NULL;                                            \
index 7575352..a1a7a5a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, JANET(UK)
+ * Copyright (c) 2012, 2014-2015, JANET(UK)
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
 
 static int destroy_tid_req(TID_REQ *req)
 {
+  OM_uint32 minor;
   if (req->json_references)
     json_decref(req->json_references);
+  if (req->gssctx)
+    gss_delete_sec_context( &minor, &req->gssctx, NULL);
   return 0;
 }
 
@@ -210,6 +213,21 @@ void tid_req_free(TID_REQ *req)
   talloc_free(req);
 }
 
+int tid_req_add_path(TID_REQ *req,
+                    const char *this_system, unsigned port)
+{
+  char *path_element = talloc_asprintf(req, "%s:%u",
+                                      this_system, port);
+  if (!req->path) {
+    req->path = json_array();
+    if (!req->path)
+      return -1;
+    tid_req_cleanup_json(req, req->path);
+  }
+  return json_array_append( req->path, json_string(path_element));
+}
+
+
 
 void tid_srvr_get_address(const TID_SRVR_BLK *blk,
                          const struct sockaddr **out_addr,
index 14cc213..2611b3b 100644 (file)
@@ -112,3 +112,36 @@ size_t tid_resp_get_num_servers(const TID_RESP *resp)
   return resp->num_servers;
 }
 
+
+const TID_PATH *tid_srvr_get_path( const TID_SRVR_BLK *block)
+{
+  if (!block)
+    return NULL;
+  return (const TID_PATH *) block->path;
+}
+
+const TID_PATH *tid_resp_get_error_path( const TID_RESP *resp)
+{
+  if (!resp)
+    return NULL;
+  return (const TID_PATH *) resp->error_path;
+}
+
+const TID_PATH *tid_resp_get_a_path( const TID_RESP *const_resp)
+{
+  size_t index;
+  TID_SRVR_BLK *server;
+  TID_RESP *resp = (TID_RESP *) const_resp;
+  if (!resp)
+    return NULL;
+
+
+  if (resp->error_path)
+    return (const TID_PATH *) resp->error_path;
+  tid_resp_servers_foreach( resp, server, index) {
+    if (server->path)
+      return (const TID_PATH *) server->path;
+  }
+  return NULL;
+  
+}
index 649706c..bd88671 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, JANET(UK)
+ * Copyright (c) 2012, 2014-2015, JANET(UK)
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
index 9c8f909..c10843e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, JANET(UK)
+ * Copyright (c) 2012, 2015, JANET(UK)
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -70,7 +70,7 @@ static void tr_tidc_resp_handler (TIDC_INSTANCE *tidc,
 static int tr_tids_req_handler (TIDS_INSTANCE *tids,
                      TID_REQ *orig_req, 
                      TID_RESP *resp,
-                     void *tr)
+                     void *tr_in)
 {
   TIDC_INSTANCE *tidc = NULL;
   TR_RESP_COOKIE resp_cookie;
@@ -79,6 +79,7 @@ static int tr_tids_req_handler (TIDS_INSTANCE *tids,
   TID_REQ *fwd_req = NULL;
   TR_COMM *cfg_comm = NULL;
   TR_COMM *cfg_apc = NULL;
+  TR_INSTANCE *tr = (TR_INSTANCE *) tr_in;
   int oaction = TR_FILTER_ACTION_REJECT;
   int rc = 0;
 
@@ -98,7 +99,7 @@ static int tr_tids_req_handler (TIDS_INSTANCE *tids,
     return -1;
   }
 
-  if (NULL == (cfg_comm = tr_comm_lookup((TR_INSTANCE *)tids->cookie, orig_req->comm))) {
+  if (NULL == (cfg_comm = tr_comm_lookup(tids->cookie, orig_req->comm))) {
     tr_notice("tr_tids_req_hander: Request for unknown comm: %s.", orig_req->comm->buf);
     tids_send_err_response(tids, orig_req, "Unknown community");
     return -1;
@@ -107,14 +108,14 @@ static int tr_tids_req_handler (TIDS_INSTANCE *tids,
   /* Check that the rp_realm matches the filter for the GSS name that 
    * was received. */
 
-  if ((!((TR_INSTANCE *)tr)->rp_gss) || 
-      (!((TR_INSTANCE *)tr)->rp_gss->filter)) {
+  if ((!(tr)->rp_gss) || 
+      (!(tr)->rp_gss->filter)) {
     tr_notice("tr_tids_req_handler: No GSS name for incoming request.");
     tids_send_err_response(tids, orig_req, "No GSS name for request");
     return -1;
   }
 
-  if ((TR_FILTER_NO_MATCH == tr_filter_process_rp_permitted(orig_req->rp_realm, ((TR_INSTANCE *)tr)->rp_gss->filter, orig_req->cons, &fwd_req->cons, &oaction)) ||
+  if ((TR_FILTER_NO_MATCH == tr_filter_process_rp_permitted(orig_req->rp_realm, (tr)->rp_gss->filter, orig_req->cons, &fwd_req->cons, &oaction)) ||
       (TR_FILTER_ACTION_REJECT == oaction)) {
     tr_notice("tr_tids_req_handler: RP realm (%s) does not match RP Realm filter for GSS name", orig_req->rp_realm->buf);
     tids_send_err_response(tids, orig_req, "RP Realm filter error");
@@ -139,7 +140,7 @@ static int tr_tids_req_handler (TIDS_INSTANCE *tids,
     apc = tr_dup_name(cfg_comm->apcs->id);
 
     /* Check that the APC is configured */
-    if (NULL == (cfg_apc = tr_comm_lookup((TR_INSTANCE *)tids->cookie, apc))) {
+    if (NULL == (cfg_apc = tr_comm_lookup(tids->cookie, apc))) {
       tr_notice("tr_tids_req_hander: Request for unknown comm: %s.", apc->buf);
       tids_send_err_response(tids, orig_req, "Unknown APC");
       return -1;
@@ -184,6 +185,9 @@ static int tr_tids_req_handler (TIDS_INSTANCE *tids,
   /* send a TID request to the AAA server(s), and get the answer(s) */
   /* TBD -- Handle multiple servers */
 
+  if (cfg_apc)
+    fwd_req->expiration_interval = cfg_apc->expiration_interval;
+  else fwd_req->expiration_interval = cfg_comm->expiration_interval;
   /* Create a TID client instance */
   if (NULL == (tidc = tidc_create())) {
     tr_crit("tr_tids_req_hander: Unable to allocate TIDC instance.");
@@ -220,9 +224,10 @@ static int tr_tids_req_handler (TIDS_INSTANCE *tids,
 }
 
 static int tr_tids_gss_handler(gss_name_t client_name, TR_NAME *gss_name,
-                       void *tr)
+                       void *tr_in)
 {
   TR_RP_CLIENT *rp;
+  TR_INSTANCE *tr = (TR_INSTANCE *) tr_in;
 
   if ((!client_name) || (!gss_name) || (!tr)) {
     tr_debug("tr_tidc_gss_handler: Bad parameters.");
@@ -237,8 +242,9 @@ static int tr_tids_gss_handler(gss_name_t client_name, TR_NAME *gss_name,
 
   /* Store the rp client in the TR_INSTANCE structure for now... 
    * TBD -- fix me for new tasking model. */
-  ((TR_INSTANCE *)tr)->rp_gss = rp;
+  (tr)->rp_gss = rp;
   tr_debug("Client's GSS Name: %s", gss_name->buf);
+
   return 0;
 }