#include <tid_internal.h>
#include <tr_msg.h>
#include <tr_debug.h>
+#include <tr_rand_id.h>
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)
{
talloc_free(tidc);
return NULL;
}
-
tidc->gssc->service_name = "trustidentity";
+ tidc->client_dh = NULL;
+ talloc_set_destructor((void *)tidc, tidc_destructor);
}
return tidc;
}
void *cookie)
{
TID_REQ *tid_req = NULL;
+ char *request_id = NULL;
int rc;
int orig_conn = 0;
gss_ctx_id_t *orig_gss_ctx = NULL;
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);
+ if (request_id) {
+ if (tid_req->request_id = tr_new_name(request_id))
+ tr_debug("tidc_send_request: Created TID request ID: %s", request_id);
+ else
+ tr_debug("tidc_send_request: Unable to set request ID, proceeding without one");
+ talloc_free(request_id);
+ } else
+ tr_debug("tidc_send_request: Failed to generate a TID request ID, proceeding without one");
rc = tidc_fwd_request(tidc, tid_req, resp_handler, cookie);
goto cleanup;
TALLOC_CTX *tmp_ctx = talloc_new(NULL);
TR_MSG *msg = NULL;
TR_MSG *resp_msg = NULL;
+ TID_RESP *tid_resp = NULL;
int rc = 0;
/* Create and populate a TID msg structure */
goto error;
/* TBD -- Check if this is actually a valid response */
- if (TID_RESPONSE != tr_msg_get_msg_type(resp_msg)) {
+ tid_resp = tr_msg_get_resp(resp_msg);
+ if (tid_resp == NULL) {
tr_err( "tidc_fwd_request: Error, no response in the response!\n");
goto error;
}
+ /* Check whether the request IDs matched and warn if not. Do nothing if we don't get
+ * an ID on the return - it is not mandatory to preserve that field. */
+ if (tid_req->request_id) {
+ if ((tid_resp->request_id)
+ && (tr_name_cmp(tid_resp->request_id, tid_req->request_id) != 0)) {
+ /* Requests present but do not match */
+ tr_warning("tidc_fwd_request: Sent request ID %.*s, received response for %.*s",
+ tid_req->request_id->len, tid_req->request_id->buf,
+ tid_resp->request_id->len, tid_resp->request_id->buf);
+ }
+ } else if (tid_resp->request_id) {
+ tr_warning("tidc_fwd_request: Sent request without ID, received response for %.*s",
+ tid_resp->request_id->len, tid_resp->request_id->buf);
+ }
+
if (resp_handler) {
/* Call the caller's response function. It must copy any data it needs before returning. */
tr_debug("tidc_fwd_request: calling response callback function.");
}
-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;
}