From 6e759de84152b3a9390d009ce9adbd06354dd69e Mon Sep 17 00:00:00 2001 From: Jennifer Richards Date: Mon, 7 May 2018 13:45:51 -0400 Subject: [PATCH] Move DH record from TR_GSSC_INSTANCE to TIDC_INSTANCE, where it belongs --- common/tr_gss_client.c | 25 +------------------------ include/mon_internal.h | 5 +---- include/tid_internal.h | 8 +++++--- include/tr_gss_client.h | 4 ---- mon/monc.c | 10 ---------- tid/tidc.c | 23 ++++++++++++++++++----- 6 files changed, 25 insertions(+), 50 deletions(-) diff --git a/common/tr_gss_client.c b/common/tr_gss_client.c index db9f380..7b61acb 100644 --- a/common/tr_gss_client.c +++ b/common/tr_gss_client.c @@ -40,29 +40,17 @@ #include #include -static int tr_gssc_destructor(void *obj) -{ - TR_GSSC_INSTANCE *tr_gssc=talloc_get_type_abort(obj, TR_GSSC_INSTANCE); - if (NULL!=tr_gssc) { - if (NULL!=tr_gssc->client_dh) - tr_destroy_dh_params(tr_gssc->client_dh); - } - return 0; -} - TR_GSSC_INSTANCE *tr_gssc_instance_new(TALLOC_CTX *mem_ctx) { TR_GSSC_INSTANCE *gssc=talloc(NULL, TR_GSSC_INSTANCE); if (gssc != NULL) { gssc->service_name = NULL; - gssc->client_dh = NULL; gssc->conn = -1; gssc->gss_ctx = talloc(gssc, gss_ctx_id_t); if (gssc->gss_ctx == NULL) { - talloc_free(gssc); /* before the destructor is set */ + talloc_free(gssc); return NULL; } - talloc_set_destructor((void *)gssc, tr_gssc_destructor); } return gssc; } @@ -145,14 +133,3 @@ cleanup: talloc_free(tmp_ctx); return resp_msg; } - -DH * tr_gssc_get_dh(TR_GSSC_INSTANCE *inst) -{ - return inst->client_dh; -} - -DH *tr_gssc_set_dh(TR_GSSC_INSTANCE *inst, DH *dh) -{ - inst->client_dh = dh; - return dh; -} diff --git a/include/mon_internal.h b/include/mon_internal.h index 29ea514..bbd7f1b 100644 --- a/include/mon_internal.h +++ b/include/mon_internal.h @@ -39,14 +39,13 @@ #include #include #include -#include +#include #include #include #include #include #include #include -#include #include /* Typedefs */ @@ -187,8 +186,6 @@ int mons_accept(MONS_INSTANCE *mons, int listen); /* monc.c */ MONC_INSTANCE *monc_new(TALLOC_CTX *mem_ctx); void monc_free(MONC_INSTANCE *monc); -DH *monc_get_dh(MONC_INSTANCE *inst); -DH *monc_set_dh(MONC_INSTANCE *inst, DH *dh); int monc_open_connection(MONC_INSTANCE *monc, const char *server, unsigned int port); MON_RESP *monc_send_request(TALLOC_CTX *mem_ctx, MONC_INSTANCE *monc, MON_REQ *req); diff --git a/include/tid_internal.h b/include/tid_internal.h index 8613eb8..ecaf647 100644 --- a/include/tid_internal.h +++ b/include/tid_internal.h @@ -35,11 +35,12 @@ #ifndef TID_INTERNAL_H #define TID_INTERNAL_H #include +#include -#include #include -#include -#include "tr_gss_client.h" +#include +#include +#include struct tid_srvr_blk { TID_SRVR_BLK *next; @@ -86,6 +87,7 @@ struct tid_req { struct tidc_instance { TR_GSSC_INSTANCE *gssc; + DH *client_dh; }; struct tid_process { diff --git a/include/tr_gss_client.h b/include/tr_gss_client.h index 25024a6..3353184 100644 --- a/include/tr_gss_client.h +++ b/include/tr_gss_client.h @@ -36,7 +36,6 @@ #define TRUST_ROUTER_TR_GSS_CLIENT_H #include -#include #include typedef struct tr_gssc_instance TR_GSSC_INSTANCE; @@ -44,7 +43,6 @@ typedef struct tr_gssc_instance TR_GSSC_INSTANCE; /* Client instance */ struct tr_gssc_instance { const char *service_name; - DH *client_dh; gss_ctx_id_t *gss_ctx; int conn; }; @@ -54,7 +52,5 @@ TR_GSSC_INSTANCE *tr_gssc_instance_new(TALLOC_CTX *mem_ctx); void tr_gssc_instance_free(TR_GSSC_INSTANCE *tr_gssc); int tr_gssc_open_connection(TR_GSSC_INSTANCE *gssc, const char *server, unsigned int port); TR_MSG *tr_gssc_exchange_msgs(TALLOC_CTX *mem_ctx, TR_GSSC_INSTANCE *gssc, TR_MSG *req_msg); -DH * tr_gssc_get_dh(TR_GSSC_INSTANCE *inst); -DH *tr_gssc_set_dh(TR_GSSC_INSTANCE *inst, DH *dh); #endif //TRUST_ROUTER_TR_GSS_CLIENT_H diff --git a/mon/monc.c b/mon/monc.c index 426b447..6e5b26a 100644 --- a/mon/monc.c +++ b/mon/monc.c @@ -98,13 +98,3 @@ cleanup: talloc_free(tmp_ctx); return resp; } - -DH *monc_get_dh(MONC_INSTANCE *inst) -{ - return tr_gssc_get_dh(inst->gssc); -} - -DH *monc_set_dh(MONC_INSTANCE *inst, DH *dh) -{ - return tr_gssc_set_dh(inst->gssc, dh); -} diff --git a/tid/tidc.c b/tid/tidc.c index 90335f0..1cff6f0 100644 --- a/tid/tidc.c +++ b/tid/tidc.c @@ -46,6 +46,17 @@ int tmp_len = 32; +static int tidc_destructor(void *obj) +{ + TIDC_INSTANCE *tidc=talloc_get_type_abort(obj, TIDC_INSTANCE); + if (NULL!=tidc) { + if (NULL!=tidc->client_dh) + tr_destroy_dh_params(tidc->client_dh); + } + return 0; +} + + /* creates struct in talloc null context */ TIDC_INSTANCE *tidc_create(void) { @@ -56,8 +67,9 @@ TIDC_INSTANCE *tidc_create(void) talloc_free(tidc); return NULL; } - tidc->gssc->service_name = "trustidentity"; + tidc->client_dh = NULL; + talloc_set_destructor((void *)tidc, tidc_destructor); } return tidc; } @@ -129,7 +141,7 @@ int tidc_send_request (TIDC_INSTANCE *tidc, goto error; } - tid_req->tidc_dh = tr_dh_dup(tidc->gssc->client_dh); + tid_req->tidc_dh = tr_dh_dup(tidc_get_dh(tidc)); /* generate an ID */ request_id = tr_random_id(NULL); @@ -219,12 +231,13 @@ int tidc_fwd_request(TIDC_INSTANCE *tidc, } -DH * tidc_get_dh(TIDC_INSTANCE *inst) +DH *tidc_get_dh(TIDC_INSTANCE *inst) { - return tr_gssc_get_dh(inst->gssc); + return inst->client_dh; } DH *tidc_set_dh(TIDC_INSTANCE *inst, DH *dh) { - return tr_gssc_set_dh(inst->gssc, dh); + inst->client_dh = dh; + return dh; } -- 2.1.4