Annotation of embedaddon/strongswan/src/libimcv/imv/imv_session_manager.c, revision 1.1
1.1 ! misho 1: /*
! 2: * Copyright (C) 2014-2015 Andreas Steffen
! 3: * HSR Hochschule fuer Technik Rapperswil
! 4: *
! 5: * This program is free software; you can redistribute it and/or modify it
! 6: * under the terms of the GNU General Public License as published by the
! 7: * Free Software Foundation; either version 2 of the License, or (at your
! 8: * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
! 9: *
! 10: * This program is distributed in the hope that it will be useful, but
! 11: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
! 12: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
! 13: * for more details.
! 14: */
! 15:
! 16: #include "imv_session_manager.h"
! 17:
! 18: #include <tncif_names.h>
! 19: #include <tncif_identity.h>
! 20:
! 21: #include <threading/mutex.h>
! 22:
! 23: typedef struct private_imv_session_manager_t private_imv_session_manager_t;
! 24:
! 25: /**
! 26: * Private data of a imv_session_manager_t object.
! 27: */
! 28: struct private_imv_session_manager_t {
! 29:
! 30: /**
! 31: * Public imv_session_manager_t interface.
! 32: */
! 33: imv_session_manager_t public;
! 34:
! 35: /**
! 36: * Session list
! 37: */
! 38: linked_list_t *sessions;
! 39:
! 40: /**
! 41: * mutex used to lock session list
! 42: */
! 43: mutex_t *mutex;
! 44:
! 45: };
! 46:
! 47: METHOD(imv_session_manager_t, add_session, imv_session_t*,
! 48: private_imv_session_manager_t *this, TNC_ConnectionID conn_id,
! 49: linked_list_t *ar_identities)
! 50: {
! 51: enumerator_t *enumerator;
! 52: tncif_identity_t *tnc_id;
! 53: imv_session_t *current, *session = NULL;
! 54:
! 55: this->mutex->lock(this->mutex);
! 56:
! 57: /* check if a session has already been assigned */
! 58: enumerator = this->sessions->create_enumerator(this->sessions);
! 59: while (enumerator->enumerate(enumerator, ¤t))
! 60: {
! 61: if (conn_id == current->get_connection_id(current))
! 62: {
! 63: session = current;
! 64: break;
! 65: }
! 66: }
! 67: enumerator->destroy(enumerator);
! 68:
! 69: /* session already exists */
! 70: if (session)
! 71: {
! 72: ar_identities->destroy_offset(ar_identities,
! 73: offsetof(tncif_identity_t, destroy));
! 74: this->mutex->unlock(this->mutex);
! 75: return session->get_ref(session);
! 76: }
! 77:
! 78: /* Output list of Access Requestor identities */
! 79: enumerator = ar_identities->create_enumerator(ar_identities);
! 80: while (enumerator->enumerate(enumerator, &tnc_id))
! 81: {
! 82: pen_type_t id_type, subject_type, auth_type;
! 83: uint32_t tcg_id_type, tcg_subject_type, tcg_auth_type;
! 84: chunk_t id_value;
! 85:
! 86: id_type = tnc_id->get_identity_type(tnc_id);
! 87: id_value = tnc_id->get_identity_value(tnc_id);
! 88: subject_type = tnc_id->get_subject_type(tnc_id);
! 89: auth_type = tnc_id->get_auth_type(tnc_id);
! 90:
! 91: tcg_id_type = (subject_type.vendor_id == PEN_TCG) ?
! 92: id_type.type : TNC_SUBJECT_UNKNOWN;
! 93: tcg_subject_type = (subject_type.vendor_id == PEN_TCG) ?
! 94: subject_type.type : TNC_SUBJECT_UNKNOWN;
! 95: tcg_auth_type = (auth_type.vendor_id == PEN_TCG) ?
! 96: auth_type.type : TNC_AUTH_UNKNOWN;
! 97:
! 98: DBG2(DBG_IMV, " %N AR identity '%.*s' of type %N authenticated by %N",
! 99: TNC_Subject_names, tcg_subject_type,
! 100: id_value.len, id_value.ptr,
! 101: TNC_Identity_names, tcg_id_type,
! 102: TNC_Authentication_names, tcg_auth_type);
! 103: }
! 104: enumerator->destroy(enumerator);
! 105:
! 106: /* create a new session entry */
! 107: session = imv_session_create(conn_id, ar_identities);
! 108: this->sessions->insert_last(this->sessions, session);
! 109:
! 110: this->mutex->unlock(this->mutex);
! 111:
! 112: return session;
! 113: }
! 114:
! 115: METHOD(imv_session_manager_t, remove_session, void,
! 116: private_imv_session_manager_t *this, imv_session_t *session)
! 117: {
! 118: enumerator_t *enumerator;
! 119: imv_session_t *current;
! 120:
! 121: this->mutex->lock(this->mutex);
! 122: enumerator = this->sessions->create_enumerator(this->sessions);
! 123: while (enumerator->enumerate(enumerator, ¤t))
! 124: {
! 125: if (current == session)
! 126: {
! 127: this->sessions->remove_at(this->sessions, enumerator);
! 128: break;
! 129: }
! 130: }
! 131: enumerator->destroy(enumerator);
! 132: this->mutex->unlock(this->mutex);
! 133: }
! 134:
! 135: METHOD(imv_session_manager_t, destroy, void,
! 136: private_imv_session_manager_t *this)
! 137: {
! 138: this->sessions->destroy_offset(this->sessions,
! 139: offsetof(imv_session_t, destroy));
! 140: this->mutex->destroy(this->mutex);
! 141: free(this);
! 142: }
! 143:
! 144: /**
! 145: * See header
! 146: */
! 147: imv_session_manager_t *imv_session_manager_create(void)
! 148: {
! 149: private_imv_session_manager_t *this;
! 150:
! 151: INIT(this,
! 152: .public = {
! 153: .add_session = _add_session,
! 154: .remove_session = _remove_session,
! 155: .destroy = _destroy,
! 156: },
! 157: .sessions = linked_list_create(),
! 158: .mutex = mutex_create(MUTEX_TYPE_DEFAULT),
! 159: );
! 160:
! 161: return &this->public;
! 162: }
! 163:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>