2 * Copyright (C) 2014-2015 Andreas Steffen
4 * Copyright (C) secunet Security Networks AG
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 #include "imv_session_manager.h"
19 #include <tncif_names.h>
20 #include <tncif_identity.h>
22 #include <threading/mutex.h>
24 typedef struct private_imv_session_manager_t private_imv_session_manager_t
;
27 * Private data of a imv_session_manager_t object.
29 struct private_imv_session_manager_t
{
32 * Public imv_session_manager_t interface.
34 imv_session_manager_t
public;
39 linked_list_t
*sessions
;
42 * mutex used to lock session list
48 METHOD(imv_session_manager_t
, add_session
, imv_session_t
*,
49 private_imv_session_manager_t
*this, TNC_ConnectionID conn_id
,
50 linked_list_t
*ar_identities
)
52 enumerator_t
*enumerator
;
53 tncif_identity_t
*tnc_id
;
54 imv_session_t
*current
, *session
= NULL
;
56 this->mutex
->lock(this->mutex
);
58 /* check if a session has already been assigned */
59 enumerator
= this->sessions
->create_enumerator(this->sessions
);
60 while (enumerator
->enumerate(enumerator
, ¤t
))
62 if (conn_id
== current
->get_connection_id(current
))
68 enumerator
->destroy(enumerator
);
70 /* session already exists */
73 ar_identities
->destroy_offset(ar_identities
,
74 offsetof(tncif_identity_t
, destroy
));
75 this->mutex
->unlock(this->mutex
);
76 return session
->get_ref(session
);
79 /* Output list of Access Requestor identities */
80 enumerator
= ar_identities
->create_enumerator(ar_identities
);
81 while (enumerator
->enumerate(enumerator
, &tnc_id
))
83 pen_type_t id_type
, subject_type
, auth_type
;
84 uint32_t tcg_id_type
, tcg_subject_type
, tcg_auth_type
;
87 id_type
= tnc_id
->get_identity_type(tnc_id
);
88 id_value
= tnc_id
->get_identity_value(tnc_id
);
89 subject_type
= tnc_id
->get_subject_type(tnc_id
);
90 auth_type
= tnc_id
->get_auth_type(tnc_id
);
92 tcg_id_type
= (subject_type
.vendor_id
== PEN_TCG
) ?
93 id_type
.type
: TNC_SUBJECT_UNKNOWN
;
94 tcg_subject_type
= (subject_type
.vendor_id
== PEN_TCG
) ?
95 subject_type
.type
: TNC_SUBJECT_UNKNOWN
;
96 tcg_auth_type
= (auth_type
.vendor_id
== PEN_TCG
) ?
97 auth_type
.type
: TNC_AUTH_UNKNOWN
;
99 DBG2(DBG_IMV
, " %N AR identity '%.*s' of type %N authenticated by %N",
100 TNC_Subject_names
, tcg_subject_type
,
101 id_value
.len
, id_value
.ptr
,
102 TNC_Identity_names
, tcg_id_type
,
103 TNC_Authentication_names
, tcg_auth_type
);
105 enumerator
->destroy(enumerator
);
107 /* create a new session entry */
108 session
= imv_session_create(conn_id
, ar_identities
);
109 this->sessions
->insert_last(this->sessions
, session
);
111 this->mutex
->unlock(this->mutex
);
116 METHOD(imv_session_manager_t
, remove_session
, void,
117 private_imv_session_manager_t
*this, imv_session_t
*session
)
119 enumerator_t
*enumerator
;
120 imv_session_t
*current
;
122 this->mutex
->lock(this->mutex
);
123 enumerator
= this->sessions
->create_enumerator(this->sessions
);
124 while (enumerator
->enumerate(enumerator
, ¤t
))
126 if (current
== session
)
128 this->sessions
->remove_at(this->sessions
, enumerator
);
132 enumerator
->destroy(enumerator
);
133 this->mutex
->unlock(this->mutex
);
136 METHOD(imv_session_manager_t
, destroy
, void,
137 private_imv_session_manager_t
*this)
139 this->sessions
->destroy_offset(this->sessions
,
140 offsetof(imv_session_t
, destroy
));
141 this->mutex
->destroy(this->mutex
);
148 imv_session_manager_t
*imv_session_manager_create(void)
150 private_imv_session_manager_t
*this;
154 .add_session
= _add_session
,
155 .remove_session
= _remove_session
,
158 .sessions
= linked_list_create(),
159 .mutex
= mutex_create(MUTEX_TYPE_DEFAULT
),
162 return &this->public;