#include <tr.h>
#include <tr_comm.h>
#include <tr_rp.h>
+#include <tr_debug.h>
TR_IDP_REALM *tr_find_comm_idp (TR_COMM *comm, TR_NAME *idp_realm)
{
for (idp = comm->idp_realms; NULL != idp; idp = idp->next) {
if (!tr_name_cmp (idp_realm, idp->realm_id)) {
- fprintf(stderr, "tr_find_comm_idp: Found %s.\n", idp_realm->buf);
+ tr_debug("tr_find_comm_idp: Found %s.", idp_realm->buf);
return idp;
}
}
for (rp = comm->rp_realms; NULL != rp; rp = rp->next) {
if (!tr_name_cmp (rp_realm, rp->realm_name)) {
- fprintf(stderr, "tr_find_comm_idp: Found %s.\n", rp_realm->buf);
+ tr_debug("tr_find_comm_idp: Found %s.", rp_realm->buf);
return rp;
}
}
#include <talloc.h>
#include <assert.h>
#include <tid_internal.h>
+#include <tr_debug.h>
unsigned char tr_2048_dhprime[2048/8] = {
DH_check(dh, &dh_err);
if (0 != dh_err) {
- fprintf(stderr, "Warning: dh_check failed with %d", dh_err);
+ tr_warning("Warning: dh_check failed with %d", dh_err);
if (dh_err & DH_CHECK_P_NOT_PRIME)
- fprintf(stderr, ": p value is not prime\n");
+ tr_warning(": p value is not prime");
else if (dh_err & DH_CHECK_P_NOT_SAFE_PRIME)
- fprintf(stderr, ": p value is not a safe prime\n");
+ tr_warning(": p value is not a safe prime");
else if (dh_err & DH_UNABLE_TO_CHECK_GENERATOR)
- fprintf(stderr, ": unable to check the generator value\n");
+ tr_warning(": unable to check the generator value");
else if (dh_err & DH_NOT_SUITABLE_GENERATOR)
- fprintf (stderr, ": the g value is not a generator\n");
- else
- fprintf(stderr, "\n");
+ tr_warning(": the g value is not a generator");
+ else
+ tr_warning("unhandled error %i", dh_err);
}
-
+
return(dh);
}
-DH *tr_create_matching_dh (unsigned char *priv_key,
+DH *tr_create_matching_dh (unsigned char *priv_key,
size_t keylen,
DH *in_dh) {
DH *dh = NULL;
return NULL;
if (NULL == (dh = DH_new())) {
- fprintf(stderr, "Unable to allocate new DH structure.\n");
+ tr_crit("tr_create_matching_dh: unable to allocate new DH structure.");
return NULL;
}
if ((NULL == (dh->g = BN_dup(in_dh->g))) ||
(NULL == (dh->p = BN_dup(in_dh->p)))) {
DH_free(dh);
- fprintf(stderr, "Invalid dh parameter values, can't be duped.\n");
+ tr_debug("tr_create_matching_dh: Invalid dh parameter values, can't be duped.");
return NULL;
}
DH_generate_key(dh); /* generates the public key */
DH_check(dh, &dh_err);
if (0 != dh_err) {
- fprintf(stderr, "Warning: dh_check failed with %d", dh_err);
+ tr_warning("Warning: dh_check failed with %d", dh_err);
if (dh_err & DH_CHECK_P_NOT_PRIME)
- fprintf(stderr, ": p value is not prime\n");
+ tr_warning(": p value is not prime");
else if (dh_err & DH_CHECK_P_NOT_SAFE_PRIME)
- fprintf(stderr, ": p value is not a safe prime\n");
+ tr_warning(": p value is not a safe prime");
else if (dh_err & DH_UNABLE_TO_CHECK_GENERATOR)
- fprintf(stderr, ": unable to check the generator value\n");
+ tr_warning(": unable to check the generator value");
else if (dh_err & DH_NOT_SUITABLE_GENERATOR)
- fprintf (stderr, ": the g value is not a generator\n");
- else
- fprintf(stderr, "\n");
+ tr_warning(": the g value is not a generator");
+ else
+ tr_warning("unhandled error %i", dh_err);
}
-
+
return(dh);
}
if ((!pbuf) ||
(!pub_key) ||
(!priv_dh)) {
- fprintf(stderr, "tr_compute_dh_key(): Invalid parameters.\n");
+ tr_debug("tr_compute_dh_key: Invalid parameters.");
return(-1);
}
*pbuf = NULL;
buflen = DH_size(priv_dh);
buf = malloc(buflen);
if (buf == NULL) {
- fprintf(stderr, "out of memory\n");
+ tr_crit("tr_compute_dh_key: out of memory");
return -1;
}
json_t *jpub_key = NULL;
if (!(dh = malloc(sizeof(DH)))) {
- fprintf (stderr, "tr_msg_decode_dh(): Error allocating DH structure.\n");
+ tr_crit("tr_msg_decode_dh(): Error allocating DH structure.");
return NULL;
}
if ((NULL == (jp = json_object_get(jdh, "dh_p"))) ||
(NULL == (jg = json_object_get(jdh, "dh_g"))) ||
(NULL == (jpub_key = json_object_get(jdh, "dh_pub_key")))) {
- fprintf (stderr, "tr_msg_decode_dh(): Error parsing dh_info.\n");
+ tr_debug("tr_msg_decode_dh(): Error parsing dh_info.");
free(dh);
return NULL;
}
json_t *jdh = NULL;
if (!(treq =tid_req_new())) {
- fprintf (stderr, "tr_msg_decode_tidreq(): Error allocating TID_REQ structure.\n");
+ tr_crit("tr_msg_decode_tidreq(): Error allocating TID_REQ structure.");
return NULL;
}
if ((NULL == (jrp_realm = json_object_get(jreq, "rp_realm"))) ||
(NULL == (jrealm = json_object_get(jreq, "target_realm"))) ||
(NULL == (jcomm = json_object_get(jreq, "community")))) {
- fprintf (stderr, "tr_msg_decode(): Error parsing required fields.\n");
+ tr_debug("tr_msg_decode(): Error parsing required fields.");
tid_req_free(treq);
return NULL;
}
/* Get DH Info from the request */
if (NULL == (jdh = json_object_get(jreq, "dh_info"))) {
- fprintf (stderr, "tr_msg_decode(): Error parsing dh_info.\n");
+ tr_debug("tr_msg_decode(): Error parsing dh_info.");
tid_req_free(treq);
return NULL;
}
treq->cons = (TR_CONSTRAINT_SET *) json_object_get(jreq, "constraints");
if (treq->cons) {
if (!tr_constraint_set_validate(treq->cons)) {
- tr_debug("Constraint set validation failed\n");
+ tr_debug("Constraint set validation failed");
tid_req_free(treq);
return NULL;
}
json_t *jsrvr = NULL;
json_t *jstr = NULL;
- fprintf(stderr, "Encoding one server.\n");
+ tr_debug("Encoding one server.");
jsrvr = json_object();
json_object_set_new(jsrvr, "key_name", jstr);
json_object_set_new(jsrvr, "server_dh", tr_msg_encode_dh(srvr->aaa_server_dh));
- // fprintf(stderr,"tr_msg_encode_one_server(): jsrvr contains:\n");
- // fprintf(stderr,"%s\n", json_dumps(jsrvr, 0));
+ // tr_debug("tr_msg_encode_one_server(): jsrvr contains:");
+ // tr_debug("%s", json_dumps(jsrvr, 0));
return jsrvr;
}
if ((NULL == (jsrvr_addr = json_object_get(jsrvr, "server_addr"))) ||
(NULL == (jsrvr_kn = json_object_get(jsrvr, "key_name"))) ||
(NULL == (jsrvr_dh = json_object_get(jsrvr, "server_dh")))) {
- tr_debug("tr_msg_decode_one_server(): Error parsing required fields.\n");
+ tr_debug("tr_msg_decode_one_server(): Error parsing required fields.");
return -1;
}
}
}
- // fprintf(stderr,"tr_msg_encode_servers(): servers contains:\n");
- // fprintf(stderr,"%s\n", json_dumps(jservers, 0));
+ // tr_debug("tr_msg_encode_servers(): servers contains:");
+ // tr_debug("%s", json_dumps(jservers, 0));
return jservers;
}
size_t i, num_servers;
num_servers = json_array_size(jservers);
- fprintf(stderr, "tr_msg_decode_servers(): Number of servers = %u.\n", (unsigned) num_servers);
+ tr_debug("tr_msg_decode_servers(): Number of servers = %u.", (unsigned) num_servers);
if (0 == num_servers) {
- fprintf(stderr, "tr_msg_decode_servers(): Server array is empty.\n");
+ tr_debug("tr_msg_decode_servers(): Server array is empty.");
return NULL;
}
- servers = talloc_zero_array(ctx, TID_SRVR_BLK, num_servers);
+ servers = talloc_zero_array(ctx, TID_SRVR_BLK, num_servers);
for (i = 0; i < num_servers; i++) {
jsrvr = json_array_get(jservers, i);
}
if (NULL == resp->servers) {
- fprintf(stderr, "tr_msg_encode_tidresp(): No servers to encode.\n");
+ tr_debug("tr_msg_encode_tidresp(): No servers to encode.");
return jresp;
}
jservers = tr_msg_encode_servers(resp);
json_t *jerr_msg = NULL;
if (!(tresp = talloc_zero(NULL, TID_RESP))) {
- fprintf (stderr, "tr_msg_decode_tidresp(): Error allocating TID_RESP structure.\n");
+ tr_crit("tr_msg_decode_tidresp(): Error allocating TID_RESP structure.");
return NULL;
}
(!json_is_string(jrealm)) ||
(NULL == (jcomm = json_object_get(jresp, "comm"))) ||
(!json_is_string(jcomm))) {
- fprintf (stderr, "tr_msg_decode_tidresp(): Error parsing response.\n");
+ tr_debug("tr_msg_decode_tidresp(): Error parsing response.");
talloc_free(tresp);
return NULL;
}
if (0 == (strcmp(json_string_value(jresult), "success"))) {
- fprintf(stderr, "tr_msg_decode_tidresp(): Success! result = %s.\n", json_string_value(jresult));
+ tr_debug("tr_msg_decode_tidresp(): Success! result = %s.", json_string_value(jresult));
if ((NULL != (jservers = json_object_get(jresp, "servers"))) ||
(!json_is_array(jservers))) {
tresp->servers = tr_msg_decode_servers(tresp, jservers, &tresp->num_servers);
}
else {
tresp->result = TID_ERROR;
- fprintf(stderr, "tr_msg_decode_tidresp(): Error! result = %s.\n", json_string_value(jresult));
+ tr_debug("tr_msg_decode_tidresp(): Error! result = %s.", json_string_value(jresult));
if ((NULL != (jerr_msg = json_object_get(jresp, "err_msg"))) ||
(!json_is_string(jerr_msg))) {
tresp->err_msg = tr_new_name((char *)json_string_value(jerr_msg));
const char *mtype = NULL;
if (NULL == (jmsg = json_loadb(jbuf, buflen, JSON_DISABLE_EOF_CHECK, &rc))) {
- fprintf (stderr, "tr_msg_decode(): error loading object\n");
+ tr_debug("tr_msg_decode(): error loading object");
return NULL;
}
if (!(msg = malloc(sizeof(TR_MSG)))) {
- fprintf (stderr, "tr_msg_decode(): Error allocating TR_MSG structure.\n");
+ tr_debug("tr_msg_decode(): Error allocating TR_MSG structure.");
json_decref(jmsg);
return NULL;
}
if ((NULL == (jtype = json_object_get(jmsg, "msg_type"))) ||
(NULL == (jbody = json_object_get(jmsg, "msg_body")))) {
- fprintf (stderr, "tr_msg_decode(): Error parsing message header.\n");
+ tr_debug("tr_msg_decode(): Error parsing message header.");
json_decref(jmsg);
tr_msg_free_decoded(msg);
return NULL;
#include <tr_rp.h>
#include <tr_config.h>
#include <tr.h>
+#include <tr_debug.h>
TR_RP_CLIENT *tr_rp_client_lookup(TR_INSTANCE *tr, TR_NAME *gss_name) {
TR_RP_CLIENT *rp = NULL;
int i = 0;
if ((!tr) || (!tr->active_cfg) || (!gss_name)) {
- fprintf(stderr, "tr_rp_client_lookup: Bad parameters.\n");
+ tr_debug("tr_rp_client_lookup: Bad parameters.");
return NULL;
}
#include <talloc.h>
#include <gsscon.h>
+#include <tr_debug.h>
#include <tid_internal.h>
#include <trust_router/tr_dh.h>
int rc;
gss_ctx_id_t gssctx;
+ /* set logging levels */
talloc_set_log_stderr();
+ tr_log_threshold(LOG_CRIT);
+ tr_console_threshold(LOG_DEBUG);
+
/* Parse command-line arguments */
if (argc < 5 || argc > 6) {
tidc_print_usage(argv[0]);
int sqlite3_result;
if (!req->cons) {
- tr_debug("Request has no constraints, so no authorizations.\n");
+ tr_debug("Request has no constraints, so no authorizations.");
return 0;
}
intersected = tr_constraint_set_intersect(req, req->cons);
intersected, "realm",
&realm_wc, &realm_len))
return -1;
- tr_debug(" %u domain constraint matches and %u realm constraint matches\n",
+ tr_debug(" %u domain constraint matches and %u realm constraint matches",
(unsigned) domain_len, (unsigned) realm_len);
if (0 != sqlify_wc(req, domain_wc, domain_len, &error)) {
- tr_debug("Processing domain constraints: %s\n", error);
+ tr_debug("Processing domain constraints: %s", error);
return -1;
}else if (0 != sqlify_wc(req, realm_wc, realm_len, &error)) {
- tr_debug("Processing realm constraints: %s\n", error);
+ tr_debug("Processing realm constraints: %s", error);
return -1;
}
if (!authorization_insert) {
- tr_debug( " No database, no authorizations inserted\n");
+ tr_debug( " No database, no authorizations inserted");
return 0;
}
for (domain_index = 0; domain_index < domain_len; domain_index++)
sqlite3_bind_text(authorization_insert, 5, req->comm->buf, req->comm->len, SQLITE_TRANSIENT);
sqlite3_result = sqlite3_step(authorization_insert);
if (SQLITE_DONE != sqlite3_result)
- printf("sqlite3: failed to write to database\n");
+ tr_crit("sqlite3: failed to write to database");
sqlite3_reset(authorization_insert);
}
return 0;
size_t pub_digest_len;
- fprintf(stdout, "tids_req_handler: Request received! target_realm = %s, community = %s\n", req->realm->buf, req->comm->buf);
+ tr_debug("tids_req_handler: Request received! target_realm = %s, community = %s", req->realm->buf, req->comm->buf);
if (tids)
tids->req_count++;
if (!(resp) || !resp) {
- fprintf(stderr, "tids_req_handler: No response structure.\n");
+ tr_debug("tids_req_handler: No response structure.");
return -1;
}
/* Allocate a new server block */
if (NULL == (resp->servers = malloc(sizeof(TID_SRVR_BLK)))){
- fprintf(stderr, "tids_req_handler(): malloc failed.\n");
+ tr_crit("tids_req_handler(): malloc failed.");
return -1;
}
memset(resp->servers, 0, sizeof(TID_SRVR_BLK));
/* TBD -- Set up the server IP Address */
if (!(req) || !(req->tidc_dh)) {
- fprintf(stderr, "tids_req_handler(): No client DH info.\n");
+ tr_debug("tids_req_handler(): No client DH info.");
return -1;
}
if ((!req->tidc_dh->p) || (!req->tidc_dh->g)) {
- fprintf(stderr, "tids_req_handler(): NULL dh values.\n");
+ tr_debug("tids_req_handler: NULL dh values.");
return -1;
}
// 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))) {
- fprintf(stderr, "tids_req_handler(): Can't create server DH params.\n");
+ tr_debug("tids_req_handler: Can't create server DH params.");
return -1;
}
if (0 == inet_aton(tids->ipaddr, &(resp->servers->aaa_server_addr))) {
- fprintf(stderr, "tids_req_handler(): inet_aton() failed.\n");
+ tr_debug("tids_req_handler: inet_aton() failed.");
return -1;
}
if (0 > (s_keylen = tr_compute_dh_key(&s_keybuf,
req->tidc_dh->pub_key,
resp->servers->aaa_server_dh))) {
- fprintf(stderr, "tids_req_handler(): Key computation failed.");
+ tr_debug("tids_req_handler: Key computation failed.");
return -1;
}
if (0 != tr_dh_pub_hash(req,
&pub_digest, &pub_digest_len)) {
- tr_debug("Unable to digest client public key\n");
+ tr_debug("tids_req_handler: Unable to digest client public key");
return -1;
}
if (0 != handle_authorizations(req, pub_digest, pub_digest_len))
sqlite3_bind_blob(insert_stmt, 3, pub_digest, pub_digest_len, SQLITE_TRANSIENT);
sqlite3_result = sqlite3_step(insert_stmt);
if (SQLITE_DONE != sqlite3_result)
- printf("sqlite3: failed to write to database\n");
+ tr_crit("sqlite3: failed to write to database");
sqlite3_reset(insert_stmt);
}
fprintf(stdout, "Usage: %s <ip-address> <gss-name> <hostname> <database-name>\n", argv[0]);
exit(1);
}
+
+ /* set logging levels */
+ tr_log_threshold(LOG_CRIT);
+ tr_console_threshold(LOG_DEBUG);
+
ipaddr = (char *)argv[1];
gssname = tr_new_name((char *) argv[2]);
hostname = argv[3];
if (SQLITE_OK != sqlite3_open(argv[4], &db)) {
- fprintf(stdout, "Error opening database %s\n", argv[4]);
+ tr_crit("Error opening database %s", argv[4]);
exit(1);
}
sqlite3_busy_timeout( db, 1000);
/* Create a TID server instance */
if (NULL == (tids = tids_create())) {
- fprintf(stdout, "Unable to create TIDS instance, exiting.\n");
+ tr_crit("Unable to create TIDS instance, exiting.");
return 1;
}
/* Start-up the server, won't return unless there is an error. */
rc = tids_start(tids, &tids_req_handler , auth_handler, hostname, TID_PORT, gssname);
- fprintf(stdout, "Error in tids_start(), rc = %d. Exiting.\n", rc);
+ tr_crit("Error in tids_start(), rc = %d. Exiting.", rc);
/* Clean-up the TID server instance */
tids_destroy(tids);
#include <talloc.h>
#include <tid_internal.h>
+#include <tr_debug.h>
+
#include <jansson.h>
static int destroy_tid_req(TID_REQ *req)
TID_REQ *new_req = NULL;
if (NULL == (new_req = malloc(sizeof(TID_REQ)))) {
- fprintf(stderr, "tid_dup_req: Can't allocated duplicate request.\n");
+ tr_crit("tid_dup_req: Can't allocated duplicate request.");
return NULL;
}
if ((NULL == (new_req->rp_realm = tr_dup_name(orig_req->rp_realm))) ||
(NULL == (new_req->realm = tr_dup_name(orig_req->realm))) ||
(NULL == (new_req->comm = tr_dup_name(orig_req->comm)))) {
- fprintf(stderr, "tid_dup_req: Can't duplicate request (names).\n");
+ tr_crit("tid_dup_req: Can't duplicate request (names).");
}
if (orig_req->orig_coi) {
if (NULL == (new_req->orig_coi = tr_dup_name(orig_req->orig_coi))) {
- fprintf(stderr, "tid_dup_req: Can't duplicate request (orig_coi).\n");
+ tr_crit("tid_dup_req: Can't duplicate request (orig_coi).");
}
}
TID_RESP *resp;
if ((NULL == (resp = talloc_zero(req, TID_RESP)))) {
- fprintf(stderr, "tids_create_response: Error allocating response structure.\n");
+ tr_crit("tids_create_response: Error allocating response structure.");
return NULL;
}
if ((NULL == (resp->rp_realm = tr_dup_name(req->rp_realm))) ||
(NULL == (resp->realm = tr_dup_name(req->realm))) ||
(NULL == (resp->comm = tr_dup_name(req->comm)))) {
- fprintf(stderr, "tids_create_response: Error allocating fields in response.\n");
+ tr_crit("tids_create_response: Error allocating fields in response.");
return NULL;
}
if (req->orig_coi) {
if (NULL == (resp->orig_coi = tr_dup_name(req->orig_coi))) {
- fprintf(stderr, "tids_create_response: Error allocating fields in response.\n");
+ tr_crit("tids_create_response: Error allocating fields in response.");
return NULL;
}
}
} addr;
struct sockaddr_in *saddr = (struct sockaddr_in *) &addr.in4;
-
+
saddr->sin_port = htons (port);
saddr->sin_family = AF_INET;
saddr->sin_addr.s_addr = INADDR_ANY;
if (0 > (conn = socket (AF_INET, SOCK_STREAM, 0)))
return conn;
-
+
setsockopt(conn, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval));
if (0 > (rc = bind (conn, (struct sockaddr *) saddr, sizeof(struct sockaddr_in))))
return rc;
-
+
if (0 > (rc = listen(conn, 512)))
return rc;
-
- fprintf (stdout, "tids_listen: TID Server listening on port %d\n", port);
- return conn;
+
+ tr_debug("tids_listen: TID Server listening on port %d", port);
+ return conn;
}
static int tids_auth_cb(gss_name_t clientName, gss_buffer_t displayName,
nameBuffer.value = name;
if (rc = gsscon_passive_authenticate(conn, nameBuffer, gssctx, tids_auth_cb, inst)) {
- fprintf(stderr, "tids_auth_connection: Error from gsscon_passive_authenticate(), rc = %d.\n", rc);
+ tr_debug("tids_auth_connection: Error from gsscon_passive_authenticate(), rc = %d.", rc);
return -1;
}
if (rc = gsscon_authorize(*gssctx, &auth, &autherr)) {
- fprintf(stderr, "tids_auth_connection: Error from gsscon_authorize, rc = %d, autherr = %d.\n",
+ tr_debug("tids_auth_connection: Error from gsscon_authorize, rc = %d, autherr = %d.",
rc, autherr);
return -1;
}
if (auth)
- fprintf(stdout, "tids_auth_connection: Connection authenticated, conn = %d.\n", conn);
+ tr_debug("tids_auth_connection: Connection authenticated, conn = %d.", conn);
else
- fprintf(stderr, "tids_auth_connection: Authentication failed, conn %d.\n", conn);
+ tr_debug("tids_auth_connection: Authentication failed, conn %d.", conn);
return !auth;
}
return -1;
}
- fprintf(stdout, "tids_read_request():Request Received, %u bytes.\n", (unsigned) buflen);
+ tr_debug("tids_read_request():Request Received, %u bytes.", (unsigned) buflen);
/* Parse request */
if (NULL == ((*mreq) = tr_msg_decode(buf, buflen))) {
- fprintf(stderr, "tids_read_request():Error decoding request.\n");
+ tr_debug("tids_read_request():Error decoding request.");
free (buf);
return -1;
}
/* If this isn't a TID Request, just drop it. */
if (TID_REQUEST != (*mreq)->msg_type) {
- fprintf(stderr, "tids_read_request(): Not a TID Request, dropped.\n");
+ tr_debug("tids_read_request(): Not a TID Request, dropped.");
return -1;
}
(!tr_msg_get_req(mreq)->rp_realm) ||
(!tr_msg_get_req(mreq)->realm) ||
(!tr_msg_get_req(mreq)->comm)) {
- fprintf(stderr, "tids_handle_request():Not a valid TID Request.\n");
+ tr_notice("tids_handle_request(): Not a valid TID Request.");
resp->result = TID_ERROR;
resp->err_msg = tr_new_name("Bad request format");
return -1;
return 0;
if (NULL == (resp = tids_create_response(tids, req))) {
- fprintf(stderr, "tids_send_err_response: Can't create response.\n");
+ tr_crit("tids_send_err_response: Can't create response.");
return -1;
}
char *resp_buf;
if ((!tids) || (!req) || (!resp))
- fprintf (stderr, "tids_send_response: Invalid parameters.\n");
+ tr_debug("tids_send_response: Invalid parameters.");
/* Never send a second response if we already sent one. */
if (req->resp_sent)
mresp.msg_type = TID_RESPONSE;
tr_msg_set_resp(&mresp, resp);
-
+
if (NULL == (resp_buf = tr_msg_encode(&mresp))) {
+
fprintf(stderr, "tids_send_response: Error encoding json response.\n");
tr_audit_req(req);
return -1;
}
- fprintf(stderr, "tids_send_response: Encoded response:\n%s\n", resp_buf);
-
+ tr_debug("tids_send_response: Encoded response: %s", resp_buf);
+
/* If external logging is enabled, fire off a message */
/* TODO Can be moved to end once segfault in gsscon_write_encrypted_token fixed */
tr_audit_resp(resp);
/* Send the response over the connection */
if (err = gsscon_write_encrypted_token (req->conn, req->gssctx, resp_buf,
strlen(resp_buf) + 1)) {
- fprintf(stderr, "tids_send_response: Error sending response over connection.\n");
+ tr_notice("tids_send_response: Error sending response over connection.");
tr_audit_req(req);
gss_ctx_id_t gssctx = GSS_C_NO_CONTEXT;
if (tids_auth_connection(tids, conn, &gssctx)) {
- fprintf(stderr, "tids_handle_connection: Error authorizing TID Server connection.\n");
+ tr_notice("tids_handle_connection: Error authorizing TID Server connection.");
close(conn);
return;
}
- fprintf(stdout, "tids_handle_connection: Connection authorized!\n");
+ tr_debug("tids_handle_connection: Connection authorized!");
while (1) { /* continue until an error breaks us out */
if (0 > (rc = tids_read_request(tids, conn, &gssctx, &mreq))) {
- fprintf(stderr, "tids_handle_connection: Error from tids_read_request(), rc = %d.\n", rc);
+ tr_debug("tids_handle_connection: Error from tids_read_request(), rc = %d.", rc);
return;
} else if (0 == rc) {
continue;
/* Allocate a response structure and populate common fields */
if (NULL == (resp = tids_create_response (tids, tr_msg_get_req(mreq)))) {
- fprintf(stderr, "tids_handle_connection: Error creating response structure.\n");
+ tr_crit("tids_handle_connection: Error creating response structure.");
/* try to send an error */
- tids_send_err_response(tids, tr_msg_get_req(mreq), "Error creating response.\n");
+ tids_send_err_response(tids, tr_msg_get_req(mreq), "Error creating response.");
return;
}
if (0 > (rc = tids_handle_request(tids, mreq, resp))) {
- fprintf(stderr, "tids_handle_connection: Error from tids_handle_request(), rc = %d.\n", rc);
+ tr_debug("tids_handle_connection: Error from tids_handle_request(), rc = %d.", rc);
/* Fall through, to send the response, either way */
}
if (0 > (rc = tids_send_response(tids, tr_msg_get_req(mreq), resp))) {
- fprintf(stderr, "tids_handle_connection: Error from tids_send_response(), rc = %d.\n", rc);
+ tr_debug("tids_handle_connection: Error from tids_send_response(), rc = %d.", rc);
/* if we didn't already send a response, try to send a generic error. */
if (!tr_msg_get_req(mreq)->resp_sent)
- tids_send_err_response(tids, tr_msg_get_req(mreq), "Error sending response.\n");
+ tids_send_err_response(tids, tr_msg_get_req(mreq), "Error sending response.");
/* Fall through to free the response, either way. */
}
void tids_destroy (TIDS_INSTANCE *tids)
{
- /* close syslog connection if syslog is enabled */
+ /* clean up logfiles */
tr_log_close();
if (tids)
free(tids);
}
-
-
#include <tr_comm.h>
#include <tr_idp.h>
#include <tr_rp.h>
+#include <tr_debug.h>
/* Structure to hold TR instance and original request in one cookie */
typedef struct tr_resp_cookie {
TID_RESP *resp,
void *resp_cookie)
{
- fprintf(stderr, "tr_tidc_resp_handler: Response received (conn = %d)! Realm = %s, Community = %s.\n", ((TR_RESP_COOKIE *)resp_cookie)->orig_req->conn, resp->realm->buf, resp->comm->buf);
+ tr_debug("tr_tidc_resp_handler: Response received (conn = %d)! Realm = %s, Community = %s.", ((TR_RESP_COOKIE *)resp_cookie)->orig_req->conn, resp->realm->buf, resp->comm->buf);
req->resp_rcvd = 1;
/* TBD -- handle concatentation of multiple responses to single req */
int rc = 0;
if ((!tids) || (!orig_req) || (!resp) || (!tr)) {
- fprintf(stderr, "tids_req_handler: Bad parameters\n");
+ tr_debug("tr_tids_req_handler: Bad parameters");
return -1;
}
- fprintf(stdout, "tr_tids_req_handler: Request received (conn = %d)! Realm = %s, Comm = %s\n", orig_req->conn,
+ tr_debug("tr_tids_req_handler: Request received (conn = %d)! Realm = %s, Comm = %s", orig_req->conn,
orig_req->realm->buf, orig_req->comm->buf);
if (tids)
tids->req_count++;
/* Duplicate the request, so we can modify and forward it */
if (NULL == (fwd_req = tid_dup_req(orig_req))) {
- fprintf(stderr, "tr_tids_req_handler: Unable to duplicate request.\n");
+ tr_debug("tr_tids_req_handler: Unable to duplicate request.");
return -1;
}
if (NULL == (cfg_comm = tr_comm_lookup((TR_INSTANCE *)tids->cookie, orig_req->comm))) {
- fprintf(stderr, "tr_tids_req_hander: Request for unknown comm: %s.\n", orig_req->comm->buf);
+ 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;
}
if ((!((TR_INSTANCE *)tr)->rp_gss) ||
(!((TR_INSTANCE *)tr)->rp_gss->filter)) {
- fprintf(stderr, "tr_tids_req_handler: No GSS name for incoming request.\n");
+ 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)) ||
(TR_FILTER_ACTION_REJECT == oaction)) {
- fprintf(stderr, "tr_tids_req_handler: RP realm (%s) does not match RP Realm filter for GSS name\n", orig_req->rp_realm->buf);
+ 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");
return -1;
}
/* Check that the rp_realm is a member of the community in the request */
if (NULL == (tr_find_comm_rp(cfg_comm, orig_req->rp_realm))) {
- fprintf(stderr, "tr_tids_req_handler: RP Realm (%s) not member of community (%s).\n", orig_req->rp_realm->buf, orig_req->comm->buf);
+ tr_notice("tr_tids_req_handler: RP Realm (%s) not member of community (%s).", orig_req->rp_realm->buf, orig_req->comm->buf);
tids_send_err_response(tids, orig_req, "RP COI membership error");
return -1;
}
/* Map the comm in the request from a COI to an APC, if needed */
if (TR_COMM_COI == cfg_comm->type) {
- fprintf(stderr, "tr_tids_req_handler: Community was a COI, switching.\n");
+ tr_debug("tr_tids_req_handler: Community was a COI, switching.");
/* TBD -- In theory there can be more than one? How would that work? */
if ((!cfg_comm->apcs) || (!cfg_comm->apcs->id)) {
- fprintf(stderr, "No valid APC for COI %s.\n", orig_req->comm->buf);
+ tr_notice("No valid APC for COI %s.", orig_req->comm->buf);
tids_send_err_response(tids, orig_req, "No valid APC for community");
return -1;
}
/* Check that the APC is configured */
if (NULL == (cfg_apc = tr_comm_lookup((TR_INSTANCE *)tids->cookie, apc))) {
- fprintf(stderr, "tr_tids_req_hander: Request for unknown comm: %s.\n", apc->buf);
+ tr_notice("tr_tids_req_hander: Request for unknown comm: %s.", apc->buf);
tids_send_err_response(tids, orig_req, "Unknown APC");
return -1;
}
/* Check that rp_realm is a member of this APC */
if (NULL == (tr_find_comm_rp(cfg_apc, orig_req->rp_realm))) {
- fprintf(stderr, "tr_tids_req_hander: RP Realm (%s) not member of community (%s).\n", orig_req->rp_realm->buf, orig_req->comm->buf);
+ tr_notice("tr_tids_req_hander: RP Realm (%s) not member of community (%s).", orig_req->rp_realm->buf, orig_req->comm->buf);
tids_send_err_response(tids, orig_req, "RP APC membership error");
return -1;
}
if (NULL == (aaa_servers = tr_idp_aaa_server_lookup((TR_INSTANCE *)tids->cookie,
orig_req->realm,
orig_req->comm))) {
- fprintf(stderr, "tr_tids_req_handler: No AAA Servers for realm %s, defaulting.\n", orig_req->realm->buf);
+ tr_debug("tr_tids_req_handler: No AAA Servers for realm %s, defaulting.", orig_req->realm->buf);
if (NULL == (aaa_servers = tr_default_server_lookup ((TR_INSTANCE *)tids->cookie,
orig_req->comm))) {
- fprintf(stderr, "tr_tids_req_handler: No default AAA servers, discarded.\n");
- tids_send_err_response(tids, orig_req, "No path to AAA Server(s) for realm");
- return -1;
+ tr_notice("tr_tids_req_handler: No default AAA servers, discarded.");
+ tids_send_err_response(tids, orig_req, "No path to AAA Server(s) for realm");
+ return -1;
}
} else {
/* if we aren't defaulting, check idp coi and apc membership */
if (NULL == (tr_find_comm_idp(cfg_comm, fwd_req->realm))) {
- fprintf(stderr, "tr_tids_req_handler: IDP Realm (%s) not member of community (%s).\n", orig_req->realm->buf, orig_req->comm->buf);
+ tr_notice("tr_tids_req_handler: IDP Realm (%s) not member of community (%s).", orig_req->realm->buf, orig_req->comm->buf);
tids_send_err_response(tids, orig_req, "IDP community membership error");
return -1;
}
if ( cfg_apc && (NULL == (tr_find_comm_idp(cfg_apc, fwd_req->realm)))) {
- fprintf(stderr, "tr_tids_req_handler: IDP Realm (%s) not member of APC (%s).\n", orig_req->realm->buf, orig_req->comm->buf);
+ tr_notice("tr_tids_req_handler: IDP Realm (%s) not member of APC (%s).", orig_req->realm->buf, orig_req->comm->buf);
tids_send_err_response(tids, orig_req, "IDP APC membership error");
return -1;
}
/* Create a TID client instance */
if (NULL == (tidc = tidc_create())) {
- fprintf(stderr, "tr_tids_req_hander: Unable to allocate TIDC instance.\n");
+ tr_crit("tr_tids_req_hander: Unable to allocate TIDC instance.");
tids_send_err_response(tids, orig_req, "Memory allocation failure");
return -1;
}
aaa_servers->hostname->buf,
TID_PORT,
&(fwd_req->gssctx)))) {
- fprintf(stderr, "tr_tids_req_handler: Error in tidc_open_connection.\n");
+ tr_notice("tr_tids_req_handler: Error in tidc_open_connection.");
tids_send_err_response(tids, orig_req, "Can't open connection to next hop TIDS");
return -1;
};
/* Send a TID request */
if (0 > (rc = tidc_fwd_request(tidc, fwd_req, &tr_tidc_resp_handler, (void *)&resp_cookie))) {
- fprintf(stderr, "Error from tidc_fwd_request, rc = %d.\n", rc);
+ tr_notice("Error from tidc_fwd_request, rc = %d.", rc);
tids_send_err_response(tids, orig_req, "Can't forward request to next hop TIDS");
return -1;
}
TR_RP_CLIENT *rp;
if ((!client_name) || (!gss_name) || (!tr)) {
- fprintf(stderr, "tr_tidc_gss_handler: Bad parameters.\n");
+ tr_debug("tr_tidc_gss_handler: Bad parameters.");
return -1;
}
/* look up the RP client matching the GSS name */
if ((NULL == (rp = tr_rp_client_lookup(tr, gss_name)))) {
- fprintf(stderr, "tr_tids_gss_handler: Unknown GSS name %s\n", gss_name->buf);
+ tr_debug("tr_tids_gss_handler: Unknown GSS name %s", gss_name->buf);
return -1;
}
/* Store the rp client in the TR_INSTANCE structure for now...
* TBD -- fix me for new tasking model. */
((TR_INSTANCE *)tr)->rp_gss = rp;
- fprintf( stderr, "Client's GSS Name: %s\n", gss_name->buf);
+ tr_debug("Client's GSS Name: %s", gss_name->buf);
return 0;
}
/* create a Trust Router instance */
if (NULL == (tr = tr_create())) {
- fprintf(stderr, "Unable to create Trust Router instance, exiting.\n");
+ tr_crit("Unable to create Trust Router instance, exiting.");
return 1;
}
/* find the configuration files */
if (0 == (n = tr_find_config_files(&cfg_files))) {
- fprintf (stderr, "Can't locate configuration files, exiting.\n");
+ tr_crit("Can't locate configuration files, exiting.");
exit(1);
}
if (TR_CFG_SUCCESS != tr_parse_config(tr, n, cfg_files)) {
- fprintf (stderr, "Error decoding configuration information, exiting.\n");
+ tr_crit("Error decoding configuration information, exiting.");
exit(1);
}
/* apply initial configuration */
if (TR_CFG_SUCCESS != (rc = tr_apply_new_config(tr))) {
- fprintf (stderr, "Error applying configuration, rc = %d.\n", rc);
+ tr_crit("Error applying configuration, rc = %d.", rc);
exit(1);
}
/* initialize the trust path query server instance */
if (0 == (tr->tids = tids_create ())) {
- fprintf (stderr, "Error initializing Trust Path Query Server instance.\n");
+ tr_crit("Error initializing Trust Path Query Server instance.");
exit(1);
}
/* start the trust path query server, won't return unless fatal error. */
if (0 != (err = tids_start(tr->tids, &tr_tids_req_handler, &tr_tids_gss_handler, tr->active_cfg->internal->hostname, tr->active_cfg->internal->tids_port, (void *)tr))) {
- fprintf (stderr, "Error from Trust Path Query Server, err = %d.\n", err);
+ tr_crit("Error from Trust Path Query Server, err = %d.", err);
exit(err);
}