2 * Copyright (C) 2011-2012 Andreas Steffen
3 * HSR Hochschule fuer Technik Rapperswil
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>.
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
16 #include "imv_scanner_state.h"
18 #include <utils/lexparser.h>
19 #include <utils/debug.h>
21 typedef struct private_imv_scanner_state_t private_imv_scanner_state_t
;
24 * Private data of an imv_scanner_state_t object.
26 struct private_imv_scanner_state_t
{
29 * Public members of imv_scanner_state_t
31 imv_scanner_state_t
public;
36 TNC_ConnectionID connection_id
;
39 * TNCCS connection state
41 TNC_ConnectionState state
;
44 * Does the TNCCS connection support long message types?
49 * Does the TNCCS connection support exclusive delivery?
54 * Maximum PA-TNC message size for this TNCCS connection
56 u_int32_t max_msg_len
;
59 * IMV action recommendation
61 TNC_IMV_Action_Recommendation rec
;
64 * IMV evaluation result
66 TNC_IMV_Evaluation_Result eval
;
69 * String with list of ports that should be closed
71 char *violating_ports
;
74 * Local copy of the remediation instruction string
79 typedef struct entry_t entry_t
;
82 * Define an internal reason string entry
90 * Table of multi-lingual reason string entries
92 static entry_t reasons
[] = {
93 { "en", "Open server ports were detected" },
94 { "de", "Offene Serverports wurden festgestellt" },
95 { "fr", "Il y a des ports du serveur ouverts" },
96 { "pl", "Są otwarte porty serwera" }
100 * Table of multi-lingual remediation instruction string entries
102 static entry_t instructions
[] = {
103 { "en", "Please close the following server ports:" },
104 { "de", "Bitte schliessen Sie die folgenden Serverports:" },
105 { "fr", "Fermez les ports du serveur suivants s'il vous plait:" },
106 { "pl", "Proszę zamknąć następujące porty serwera:" }
109 METHOD(imv_state_t
, get_connection_id
, TNC_ConnectionID
,
110 private_imv_scanner_state_t
*this)
112 return this->connection_id
;
115 METHOD(imv_state_t
, has_long
, bool,
116 private_imv_scanner_state_t
*this)
118 return this->has_long
;
121 METHOD(imv_state_t
, has_excl
, bool,
122 private_imv_scanner_state_t
*this)
124 return this->has_excl
;
127 METHOD(imv_state_t
, set_flags
, void,
128 private_imv_scanner_state_t
*this, bool has_long
, bool has_excl
)
130 this->has_long
= has_long
;
131 this->has_excl
= has_excl
;
134 METHOD(imv_state_t
, set_max_msg_len
, void,
135 private_imv_scanner_state_t
*this, u_int32_t max_msg_len
)
137 this->max_msg_len
= max_msg_len
;
140 METHOD(imv_state_t
, get_max_msg_len
, u_int32_t
,
141 private_imv_scanner_state_t
*this)
143 return this->max_msg_len
;
146 METHOD(imv_state_t
, change_state
, void,
147 private_imv_scanner_state_t
*this, TNC_ConnectionState new_state
)
149 this->state
= new_state
;
152 METHOD(imv_state_t
, get_recommendation
, void,
153 private_imv_scanner_state_t
*this, TNC_IMV_Action_Recommendation
*rec
,
154 TNC_IMV_Evaluation_Result
*eval
)
160 METHOD(imv_state_t
, set_recommendation
, void,
161 private_imv_scanner_state_t
*this, TNC_IMV_Action_Recommendation rec
,
162 TNC_IMV_Evaluation_Result eval
)
168 METHOD(imv_state_t
, get_reason_string
, bool,
169 private_imv_scanner_state_t
*this, enumerator_t
*language_enumerator
,
170 char **reason_string
, char **reason_language
)
176 if (!this->violating_ports
)
181 /* set the default language */
182 *reason_language
= reasons
[0].lang
;
183 *reason_string
= reasons
[0].string
;
185 while (language_enumerator
->enumerate(language_enumerator
, &lang
))
187 for (i
= 0; i
< countof(reasons
); i
++)
189 if (streq(lang
, reasons
[i
].lang
))
192 *reason_language
= reasons
[i
].lang
;
193 *reason_string
= reasons
[i
].string
;
206 METHOD(imv_state_t
, get_remediation_instructions
, bool,
207 private_imv_scanner_state_t
*this, enumerator_t
*language_enumerator
,
208 char **string
, char **lang_code
)
214 if (!this->violating_ports
)
219 /* set the default language */
220 *lang_code
= instructions
[0].lang
;
221 *string
= instructions
[0].string
;
223 while (language_enumerator
->enumerate(language_enumerator
, &lang
))
225 for (i
= 0; i
< countof(instructions
); i
++)
227 if (streq(lang
, instructions
[i
].lang
))
230 *lang_code
= instructions
[i
].lang
;
231 *string
= instructions
[i
].string
;
240 this->instructions
= malloc(strlen(*string
) +
241 strlen(this->violating_ports
) + 1);
242 sprintf(this->instructions
, "%s%s", *string
, this->violating_ports
);
243 *string
= this->instructions
;
248 METHOD(imv_state_t
, destroy
, void,
249 private_imv_scanner_state_t
*this)
251 free(this->violating_ports
);
252 free(this->instructions
);
256 METHOD(imv_scanner_state_t
, set_violating_ports
, void,
257 private_imv_scanner_state_t
*this, char *ports
)
259 this->violating_ports
= strdup(ports
);
263 * Described in header.
265 imv_state_t
*imv_scanner_state_create(TNC_ConnectionID connection_id
)
267 private_imv_scanner_state_t
*this;
272 .get_connection_id
= _get_connection_id
,
273 .has_long
= _has_long
,
274 .has_excl
= _has_excl
,
275 .set_flags
= _set_flags
,
276 .set_max_msg_len
= _set_max_msg_len
,
277 .get_max_msg_len
= _get_max_msg_len
,
278 .change_state
= _change_state
,
279 .get_recommendation
= _get_recommendation
,
280 .set_recommendation
= _set_recommendation
,
281 .get_reason_string
= _get_reason_string
,
282 .get_remediation_instructions
= _get_remediation_instructions
,
285 .set_violating_ports
= _set_violating_ports
,
287 .state
= TNC_CONNECTION_STATE_CREATE
,
288 .rec
= TNC_IMV_ACTION_RECOMMENDATION_NO_RECOMMENDATION
,
289 .eval
= TNC_IMV_EVALUATION_RESULT_DONT_KNOW
,
290 .connection_id
= connection_id
,
293 return &this->public.interface
;