#include <poll.h>
#include <tr_debug.h>
+#include <tr_util.h>
#include <tid_internal.h>
#include <trust_router/tr_constraint.h>
#include <trust_router/tr_dh.h>
if (SQLITE_DONE != sqlite3_result)
tr_crit("sqlite3: failed to write to database");
sqlite3_reset(authorization_insert);
+ sqlite3_clear_bindings(authorization_insert);
}
return 0;
}
unsigned char *s_keybuf = NULL;
int s_keylen = 0;
char key_id[12];
- unsigned char *pub_digest;
+ unsigned char *pub_digest=NULL;
size_t pub_digest_len;
/* Allocate a new server block */
- if (NULL == (resp->servers = talloc_zero(resp, TID_SRVR_BLK))){
- tr_crit("tids_req_handler(): malloc failed.");
+ tid_srvr_blk_add(resp->servers, tid_srvr_blk_new(resp));
+ if (NULL==resp->servers) {
+ tr_crit("tids_req_handler(): unable to allocate server block.");
return -1;
}
- resp->num_servers = 1;
-
/* TBD -- Set up the server IP Address */
if (!(req) || !(req->tidc_dh)) {
return -1;
}
- resp->servers->aaa_server_addr=tids->ipaddr;
+ resp->servers->aaa_server_addr=talloc_strdup(resp->servers, tids->ipaddr);
/* Set the key name */
if (-1 == create_key_id(key_id, sizeof(key_id)))
}
if (0 != handle_authorizations(req, pub_digest, pub_digest_len))
return -1;
- resp->servers->path = req->path;
+ tid_srvr_blk_set_path(resp->servers, req->path);
+
if (req->expiration_interval < 1)
req->expiration_interval = 1;
g_get_current_time(&resp->servers->key_expiration);
if (NULL != insert_stmt) {
int sqlite3_result;
gchar *expiration_str = g_time_val_to_iso8601(&resp->servers->key_expiration);
- sqlite3_bind_text(insert_stmt, 1, key_id, -1, SQLITE_TRANSIENT);
+ sqlite3_bind_text(insert_stmt, 1, key_id, -1, SQLITE_TRANSIENT);
sqlite3_bind_blob(insert_stmt, 2, s_keybuf, s_keylen, SQLITE_TRANSIENT);
sqlite3_bind_blob(insert_stmt, 3, pub_digest, pub_digest_len, SQLITE_TRANSIENT);
- sqlite3_bind_text(insert_stmt, 4, expiration_str, -1, SQLITE_TRANSIENT);
+ sqlite3_bind_text(insert_stmt, 4, expiration_str, -1, SQLITE_TRANSIENT);
+ g_free(expiration_str); /* bind_text already made its own copy */
sqlite3_result = sqlite3_step(insert_stmt);
if (SQLITE_DONE != sqlite3_result)
tr_crit("sqlite3: failed to write to database");
sqlite3_reset(insert_stmt);
+ sqlite3_clear_bindings(insert_stmt);
}
/* Print out the key. */
// }
// fprintf(stderr, "\n");
+ if (s_keybuf!=NULL)
+ free(s_keybuf);
+
+ if (pub_digest!=NULL)
+ talloc_free(pub_digest);
+
return s_keylen;
}