- tr_debug("tids_listen: TID Server listening on port %d", port);
- return conn;
-}
-
-/* returns EACCES if authorization is denied */
-static int tids_auth_cb(gss_name_t clientName, gss_buffer_t displayName,
- void *data)
-{
- struct tids_instance *inst = (struct tids_instance *) data;
- TR_NAME name ={(char *) displayName->value,
- displayName->length};
- int result=0;
-
- if (0!=inst->auth_handler(clientName, &name, inst->cookie)) {
- tr_debug("tids_auth_cb: client '%.*s' denied authorization.", name.len, name.buf);
- result=EACCES; /* denied */
- }
-
- return result;
-}
-
-/* returns 0 on authorization success, 1 on failure, or -1 in case of error */
-static int tids_auth_connection (TIDS_INSTANCE *inst,
- int conn,
- gss_ctx_id_t *gssctx)
-{
- int rc = 0;
- int auth, autherr = 0;
- gss_buffer_desc nameBuffer = {0, NULL};
- char *name = 0;
- int nameLen = 0;
-
- nameLen = asprintf(&name, "trustidentity@%s", inst->hostname);
- nameBuffer.length = nameLen;
- nameBuffer.value = name;
-
- if (rc = gsscon_passive_authenticate(conn, nameBuffer, gssctx, tids_auth_cb, inst)) {
- tr_debug("tids_auth_connection: Error from gsscon_passive_authenticate(), rc = %d.", rc);
- return -1;
- }
-
- if (rc = gsscon_authorize(*gssctx, &auth, &autherr)) {
- tr_debug("tids_auth_connection: Error from gsscon_authorize, rc = %d, autherr = %d.",
- rc, autherr);
- return -1;
- }
-
- if (auth)
- tr_debug("tids_auth_connection: Connection authenticated, conn = %d.", conn);
- else
- tr_debug("tids_auth_connection: Authentication failed, conn %d.", conn);
-
- return !auth;
-}
-
-static int tids_read_request (TIDS_INSTANCE *tids, int conn, gss_ctx_id_t *gssctx, TR_MSG **mreq)
-{
- int err;
- char *buf;
- size_t buflen = 0;
-
- if (err = gsscon_read_encrypted_token(conn, *gssctx, &buf, &buflen)) {
- if (buf)
- free(buf);
- return -1;
- }
-
- tr_debug("tids_read_request():Request Received, %u bytes.", (unsigned) buflen);
-
- /* Parse request */
- if (NULL == ((*mreq) = tr_msg_decode(buf, buflen))) {
- 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) {
- tr_debug("tids_read_request(): Not a TID Request, dropped.");
- return -1;