From a424740cc7859cf1d4118ce36c77133952a9c581 Mon Sep 17 00:00:00 2001 From: Sam Hartman Date: Wed, 16 Jul 2014 11:17:52 -0400 Subject: [PATCH] ABI/API break: pas in TID_RESP * to handler Previously, we passed in TID_RESP ** to the request handler. However the request handlers assumed that the response was allocated. We don't want responses allocated in the handler, so make it a single pointer. note that the existing handler interface is probably inappropriate for an event-loop-based trust router. --- Makefile.am | 2 +- include/trust_router/tid.h | 2 +- tid/example/tids_main.c | 18 +++++++++--------- tid/tids.c | 20 ++++++++++---------- tr/tr_main.c | 4 ++-- 5 files changed, 23 insertions(+), 23 deletions(-) diff --git a/Makefile.am b/Makefile.am index 7f9f9cf..9fbe65a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -44,7 +44,7 @@ $(common_srcs) libtr_tid_la_CFLAGS = $(AM_CFLAGS) -fvisibility=hidden libtr_tid_la_LIBADD = gsscon/libgsscon.la -libtr_tid_la_LDFLAGS = $(AM_LDFLAGS) -version-info 1 -no-undefined +libtr_tid_la_LDFLAGS = $(AM_LDFLAGS) -version-info 2 -no-undefined pkginclude_HEADERS = include/trust_router/tid.h include/trust_router/tr_name.h \ include/trust_router/tr_dh.h \ diff --git a/include/trust_router/tid.h b/include/trust_router/tid.h index 43057db..60b5dbd 100644 --- a/include/trust_router/tid.h +++ b/include/trust_router/tid.h @@ -67,7 +67,7 @@ typedef void (TIDC_RESP_FUNC)(TIDC_INSTANCE *, TID_REQ *, TID_RESP *, void *); -typedef int (TIDS_REQ_FUNC)(TIDS_INSTANCE *, TID_REQ *, TID_RESP **, void *); +typedef int (TIDS_REQ_FUNC)(TIDS_INSTANCE *, TID_REQ *, TID_RESP *, void *); typedef int (tids_auth_func)(gss_name_t client_name, TR_NAME *display_name, void *cookie); diff --git a/tid/example/tids_main.c b/tid/example/tids_main.c index dba6185..e920874 100644 --- a/tid/example/tids_main.c +++ b/tid/example/tids_main.c @@ -152,7 +152,7 @@ static int handle_authorizations(TID_REQ *req, const unsigned char *dh_hash, static int tids_req_handler (TIDS_INSTANCE *tids, TID_REQ *req, - TID_RESP **resp, + TID_RESP *resp, void *cookie) { unsigned char *s_keybuf = NULL; @@ -166,18 +166,18 @@ static int tids_req_handler (TIDS_INSTANCE *tids, if (tids) tids->req_count++; - if (!(resp) || !(*resp)) { + if (!(resp) || !resp) { fprintf(stderr, "tids_req_handler: No response structure.\n"); return -1; } /* Allocate a new server block */ - if (NULL == ((*resp)->servers = malloc(sizeof(TID_SRVR_BLK)))){ + if (NULL == (resp->servers = malloc(sizeof(TID_SRVR_BLK)))){ fprintf(stderr, "tids_req_handler(): malloc failed.\n"); return -1; } - memset((*resp)->servers, 0, sizeof(TID_SRVR_BLK)); - (*resp)->num_servers = 1; + memset(resp->servers, 0, sizeof(TID_SRVR_BLK)); + resp->num_servers = 1; /* TBD -- Set up the server IP Address */ @@ -195,12 +195,12 @@ static int tids_req_handler (TIDS_INSTANCE *tids, // fprintf(stderr, "Generating the server DH block.\n"); // fprintf(stderr, "...from client DH block, dh_g = %s, dh_p = %s.\n", BN_bn2hex(req->tidc_dh->g), BN_bn2hex(req->tidc_dh->p)); - if (NULL == ((*resp)->servers->aaa_server_dh = tr_create_matching_dh(NULL, 0, req->tidc_dh))) { + if (NULL == (resp->servers->aaa_server_dh = tr_create_matching_dh(NULL, 0, req->tidc_dh))) { fprintf(stderr, "tids_req_handler(): Can't create server DH params.\n"); return -1; } - if (0 == inet_aton(tids->ipaddr, &((*resp)->servers->aaa_server_addr))) { + if (0 == inet_aton(tids->ipaddr, &(resp->servers->aaa_server_addr))) { fprintf(stderr, "tids_req_handler(): inet_aton() failed.\n"); return -1; } @@ -208,14 +208,14 @@ static int tids_req_handler (TIDS_INSTANCE *tids, /* Set the key name */ if (-1 == create_key_id(key_id, sizeof(key_id))) return -1; - (*resp)->servers->key_name = tr_new_name(key_id); + resp->servers->key_name = tr_new_name(key_id); /* Generate the server key */ // fprintf(stderr, "Generating the server key.\n"); if (0 > (s_keylen = tr_compute_dh_key(&s_keybuf, req->tidc_dh->pub_key, - (*resp)->servers->aaa_server_dh))) { + resp->servers->aaa_server_dh))) { fprintf(stderr, "tids_req_handler(): Key computation failed."); return -1; } diff --git a/tid/tids.c b/tid/tids.c index 79a96ca..36d4e68 100644 --- a/tid/tids.c +++ b/tid/tids.c @@ -192,7 +192,7 @@ static int tids_read_request (TIDS_INSTANCE *tids, int conn, gss_ctx_id_t *gssct return buflen; } -static int tids_handle_request (TIDS_INSTANCE *tids, TR_MSG *mreq, TID_RESP **resp) +static int tids_handle_request (TIDS_INSTANCE *tids, TR_MSG *mreq, TID_RESP *resp) { int rc; @@ -202,23 +202,23 @@ static int tids_handle_request (TIDS_INSTANCE *tids, TR_MSG *mreq, TID_RESP **re (!mreq->tid_req->realm) || (!mreq->tid_req->comm)) { fprintf(stderr, "tids_handle_request():Not a valid TID Request.\n"); - (*resp)->result = TID_ERROR; - (*resp)->err_msg = tr_new_name("Bad request format"); + resp->result = TID_ERROR; + resp->err_msg = tr_new_name("Bad request format"); return -1; } /* Call the caller's request handler */ /* TBD -- Handle different error returns/msgs */ - if (0 > (rc = (*tids->req_handler)(tids, mreq->tid_req, &(*resp), tids->cookie))) { + if (0 > (rc = (*tids->req_handler)(tids, mreq->tid_req, resp, tids->cookie))) { /* set-up an error response */ - (*resp)->result = TID_ERROR; - if (!(*resp)->err_msg) /* Use msg set by handler, if any */ - (*resp)->err_msg = tr_new_name("Internal processing error"); + resp->result = TID_ERROR; + if (!resp->err_msg) /* Use msg set by handler, if any */ + resp->err_msg = tr_new_name("Internal processing error"); } else { /* set-up a success response */ - (*resp)->result = TID_SUCCESS; - (*resp)->err_msg = NULL; /* No error msg on successful return */ + resp->result = TID_SUCCESS; + resp->err_msg = NULL; /* No error msg on successful return */ } return rc; @@ -321,7 +321,7 @@ static void tids_handle_connection (TIDS_INSTANCE *tids, int conn) return; } - if (0 > (rc = tids_handle_request(tids, mreq, &resp))) { + if (0 > (rc = tids_handle_request(tids, mreq, resp))) { fprintf(stderr, "tids_handle_connection: Error from tids_handle_request(), rc = %d.\n", rc); /* Fall through, to send the response, either way */ } diff --git a/tr/tr_main.c b/tr/tr_main.c index c39b7dc..24fbcba 100644 --- a/tr/tr_main.c +++ b/tr/tr_main.c @@ -68,7 +68,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, + TID_RESP *resp, void *tr) { TIDC_INSTANCE *tidc = NULL; @@ -81,7 +81,7 @@ static int tr_tids_req_handler (TIDS_INSTANCE *tids, int oaction = TR_FILTER_ACTION_REJECT; int rc = 0; - if ((!tids) || (!orig_req) || (!resp) || (!(*resp)) || (!tr)) { + if ((!tids) || (!orig_req) || (!resp) || (!tr)) { fprintf(stderr, "tids_req_handler: Bad parameters\n"); return -1; } -- 2.1.4