2 * Copyright (C) 2013-2014 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
19 #include "imv_os_agent.h"
20 #include "imv_os_state.h"
21 #include "imv_os_database.h"
24 #include <imv/imv_agent.h>
25 #include <imv/imv_msg.h>
26 #include <ietf/ietf_attr.h>
27 #include <ietf/ietf_attr_attr_request.h>
28 #include <ietf/ietf_attr_default_pwd_enabled.h>
29 #include <ietf/ietf_attr_fwd_enabled.h>
30 #include <ietf/ietf_attr_installed_packages.h>
31 #include <ietf/ietf_attr_numeric_version.h>
32 #include <ietf/ietf_attr_op_status.h>
33 #include <ietf/ietf_attr_pa_tnc_error.h>
34 #include <ietf/ietf_attr_product_info.h>
35 #include <ietf/ietf_attr_remediation_instr.h>
36 #include <ietf/ietf_attr_string_version.h>
37 #include <ita/ita_attr.h>
38 #include <ita/ita_attr_get_settings.h>
39 #include <ita/ita_attr_settings.h>
40 #include <ita/ita_attr_device_id.h>
41 #include "tcg/seg/tcg_seg_attr_max_size.h"
42 #include "tcg/seg/tcg_seg_attr_seg_env.h"
44 #include <tncif_names.h>
45 #include <tncif_pa_subtypes.h>
48 #include <utils/debug.h>
50 #define INSTALLED_PACKAGES_MAX_ATTR_SIZE 100000000
52 typedef struct private_imv_os_agent_t private_imv_os_agent_t
;
53 typedef enum imv_os_attr_t imv_os_attr_t
;
55 /* Subscribed PA-TNC message subtypes */
56 static pen_type_t msg_types
[] = {
57 { PEN_IETF
, PA_SUBTYPE_IETF_OPERATING_SYSTEM
}
60 static char unknown_source_str
[] = "install_non_market_apps";
63 * Flag set when corresponding attribute has been received
66 IMV_OS_ATTR_PRODUCT_INFORMATION
= (1<<0),
67 IMV_OS_ATTR_STRING_VERSION
= (1<<1),
68 IMV_OS_ATTR_NUMERIC_VERSION
= (1<<2),
69 IMV_OS_ATTR_OPERATIONAL_STATUS
= (1<<3),
70 IMV_OS_ATTR_FORWARDING_ENABLED
= (1<<4),
71 IMV_OS_ATTR_FACTORY_DEFAULT_PWD_ENABLED
= (1<<5),
72 IMV_OS_ATTR_DEVICE_ID
= (1<<6),
73 IMV_OS_ATTR_MUST
= (1<<7)-1,
74 IMV_OS_ATTR_INSTALLED_PACKAGES
= (1<<7),
75 IMV_OS_ATTR_SETTINGS
= (1<<8)
79 * Private data of an imv_os_agent_t object.
81 struct private_imv_os_agent_t
{
84 * Public members of imv_os_agent_t
86 imv_agent_if_t
public;
89 * IMV agent responsible for generic functions
96 imv_os_database_t
*db
;
100 METHOD(imv_agent_if_t
, bind_functions
, TNC_Result
,
101 private_imv_os_agent_t
*this, TNC_TNCS_BindFunctionPointer bind_function
)
103 return this->agent
->bind_functions(this->agent
, bind_function
);
106 METHOD(imv_agent_if_t
, notify_connection_change
, TNC_Result
,
107 private_imv_os_agent_t
*this, TNC_ConnectionID id
,
108 TNC_ConnectionState new_state
)
110 TNC_IMV_Action_Recommendation rec
;
112 imv_session_t
*session
;
116 case TNC_CONNECTION_STATE_CREATE
:
117 state
= imv_os_state_create(id
);
118 return this->agent
->create_state(this->agent
, state
);
119 case TNC_CONNECTION_STATE_DELETE
:
120 return this->agent
->delete_state(this->agent
, id
);
121 case TNC_CONNECTION_STATE_ACCESS_ALLOWED
:
122 case TNC_CONNECTION_STATE_ACCESS_ISOLATED
:
123 case TNC_CONNECTION_STATE_ACCESS_NONE
:
124 if (this->agent
->get_state(this->agent
, id
, &state
) && imcv_db
)
126 session
= state
->get_session(state
);
128 if (session
->get_policy_started(session
))
132 case TNC_CONNECTION_STATE_ACCESS_ALLOWED
:
133 rec
= TNC_IMV_ACTION_RECOMMENDATION_ALLOW
;
135 case TNC_CONNECTION_STATE_ACCESS_ISOLATED
:
136 rec
= TNC_IMV_ACTION_RECOMMENDATION_ISOLATE
;
138 case TNC_CONNECTION_STATE_ACCESS_NONE
:
140 rec
= TNC_IMV_ACTION_RECOMMENDATION_NO_ACCESS
;
142 imcv_db
->add_recommendation(imcv_db
, session
, rec
);
143 if (!imcv_db
->policy_script(imcv_db
, session
, FALSE
))
145 DBG1(DBG_IMV
, "error in policy script stop");
149 /* fall through to default state */
151 return this->agent
->change_state(this->agent
, id
, new_state
, NULL
);
156 * Process a received message
158 static TNC_Result
receive_msg(private_imv_os_agent_t
*this, imv_state_t
*state
,
162 imv_os_state_t
*os_state
;
163 imv_session_t
*session
;
164 imv_os_info_t
*os_info
= NULL
;
165 enumerator_t
*enumerator
;
169 chunk_t os_name
= chunk_empty
;
170 chunk_t os_version
= chunk_empty
;
171 bool fatal_error
= FALSE
, assessment
= FALSE
;
174 os_state
= (imv_os_state_t
*)state
;
175 session
= state
->get_session(state
);
176 os_info
= session
->get_os_info(session
);
178 /* generate an outgoing PA-TNC message - we might need it */
179 out_msg
= imv_msg_create_as_reply(in_msg
);
181 /* parse received PA-TNC message and handle local and remote errors */
182 result
= in_msg
->receive(in_msg
,out_msg
, &fatal_error
);
183 if (result
!= TNC_RESULT_SUCCESS
)
185 out_msg
->destroy(out_msg
);
189 /* analyze PA-TNC attributes */
190 enumerator
= in_msg
->create_attribute_enumerator(in_msg
);
191 while (enumerator
->enumerate(enumerator
, &attr
))
193 type
= attr
->get_type(attr
);
195 if (type
.vendor_id
== PEN_IETF
)
199 case IETF_ATTR_PRODUCT_INFORMATION
:
201 ietf_attr_product_info_t
*attr_cast
;
204 state
->set_action_flags(state
,
205 IMV_OS_ATTR_PRODUCT_INFORMATION
);
206 attr_cast
= (ietf_attr_product_info_t
*)attr
;
207 os_name
= attr_cast
->get_info(attr_cast
, &vendor_id
, NULL
);
208 os_info
->set_name(os_info
, os_name
);
210 if (vendor_id
!= PEN_IETF
)
212 DBG1(DBG_IMV
, "operating system name is '%.*s' "
213 "from vendor %N", os_name
.len
, os_name
.ptr
,
214 pen_names
, vendor_id
);
218 DBG1(DBG_IMV
, "operating system name is '%.*s'",
219 os_name
.len
, os_name
.ptr
);
223 case IETF_ATTR_STRING_VERSION
:
225 ietf_attr_string_version_t
*attr_cast
;
227 state
->set_action_flags(state
,
228 IMV_OS_ATTR_STRING_VERSION
);
229 attr_cast
= (ietf_attr_string_version_t
*)attr
;
230 os_version
= attr_cast
->get_version(attr_cast
, NULL
, NULL
);
231 os_info
->set_version(os_info
, os_version
);
235 DBG1(DBG_IMV
, "operating system version is '%.*s'",
236 os_version
.len
, os_version
.ptr
);
240 case IETF_ATTR_NUMERIC_VERSION
:
242 ietf_attr_numeric_version_t
*attr_cast
;
243 uint32_t major
, minor
;
245 state
->set_action_flags(state
,
246 IMV_OS_ATTR_NUMERIC_VERSION
);
247 attr_cast
= (ietf_attr_numeric_version_t
*)attr
;
248 attr_cast
->get_version(attr_cast
, &major
, &minor
);
249 DBG1(DBG_IMV
, "operating system numeric version is %d.%d",
253 case IETF_ATTR_OPERATIONAL_STATUS
:
255 ietf_attr_op_status_t
*attr_cast
;
256 op_status_t op_status
;
257 op_result_t op_result
;
260 state
->set_action_flags(state
,
261 IMV_OS_ATTR_OPERATIONAL_STATUS
);
262 attr_cast
= (ietf_attr_op_status_t
*)attr
;
263 op_status
= attr_cast
->get_status(attr_cast
);
264 op_result
= attr_cast
->get_result(attr_cast
);
265 last_boot
= attr_cast
->get_last_use(attr_cast
);
266 DBG1(DBG_IMV
, "operational status: %N, result: %N",
267 op_status_names
, op_status
, op_result_names
, op_result
);
268 DBG1(DBG_IMV
, "last boot: %T", &last_boot
, TRUE
);
271 case IETF_ATTR_FORWARDING_ENABLED
:
273 ietf_attr_fwd_enabled_t
*attr_cast
;
274 os_fwd_status_t fwd_status
;
276 state
->set_action_flags(state
,
277 IMV_OS_ATTR_FORWARDING_ENABLED
);
278 attr_cast
= (ietf_attr_fwd_enabled_t
*)attr
;
279 fwd_status
= attr_cast
->get_status(attr_cast
);
280 DBG1(DBG_IMV
, "IPv4 forwarding is %N",
281 os_fwd_status_names
, fwd_status
);
282 if (fwd_status
== OS_FWD_ENABLED
)
284 os_state
->set_os_settings(os_state
,
285 OS_SETTINGS_FWD_ENABLED
);
289 case IETF_ATTR_FACTORY_DEFAULT_PWD_ENABLED
:
291 ietf_attr_default_pwd_enabled_t
*attr_cast
;
292 bool default_pwd_status
;
294 state
->set_action_flags(state
,
295 IMV_OS_ATTR_FACTORY_DEFAULT_PWD_ENABLED
);
296 attr_cast
= (ietf_attr_default_pwd_enabled_t
*)attr
;
297 default_pwd_status
= attr_cast
->get_status(attr_cast
);
298 DBG1(DBG_IMV
, "factory default password is %sabled",
299 default_pwd_status ?
"en":"dis");
300 if (default_pwd_status
)
302 os_state
->set_os_settings(os_state
,
303 OS_SETTINGS_DEFAULT_PWD_ENABLED
);
307 case IETF_ATTR_INSTALLED_PACKAGES
:
309 ietf_attr_installed_packages_t
*attr_cast
;
313 state
->set_action_flags(state
,
314 IMV_OS_ATTR_INSTALLED_PACKAGES
);
319 attr_cast
= (ietf_attr_installed_packages_t
*)attr
;
321 e
= attr_cast
->create_enumerator(attr_cast
);
322 status
= this->db
->check_packages(this->db
, os_state
, e
);
325 if (status
== FAILED
)
327 state
->set_recommendation(state
,
328 TNC_IMV_ACTION_RECOMMENDATION_NO_RECOMMENDATION
,
329 TNC_IMV_EVALUATION_RESULT_ERROR
);
332 missing
= attr_cast
->get_count(attr_cast
);
333 os_state
->set_missing(os_state
, missing
);
334 attr_cast
->clear_packages(attr_cast
);
341 else if (type
.vendor_id
== PEN_ITA
)
345 case ITA_ATTR_SETTINGS
:
347 ita_attr_settings_t
*attr_cast
;
352 state
->set_action_flags(state
, IMV_OS_ATTR_SETTINGS
);
354 attr_cast
= (ita_attr_settings_t
*)attr
;
355 e
= attr_cast
->create_enumerator(attr_cast
);
356 while (e
->enumerate(e
, &name
, &value
))
358 if (streq(name
, unknown_source_str
) &&
359 chunk_equals(value
, chunk_from_chars('1')))
361 os_state
->set_os_settings(os_state
,
362 OS_SETTINGS_UNKNOWN_SOURCE
);
364 DBG1(DBG_IMV
, "setting '%s'\n %.*s",
365 name
, value
.len
, value
.ptr
);
370 case ITA_ATTR_DEVICE_ID
:
374 state
->set_action_flags(state
, IMV_OS_ATTR_DEVICE_ID
);
376 value
= attr
->get_value(attr
);
377 DBG1(DBG_IMV
, "device ID is %.*s", value
.len
, value
.ptr
);
378 session
->set_device_id(session
, value
);
386 enumerator
->destroy(enumerator
);
390 state
->set_recommendation(state
,
391 TNC_IMV_ACTION_RECOMMENDATION_NO_RECOMMENDATION
,
392 TNC_IMV_EVALUATION_RESULT_ERROR
);
398 os_state
->set_handshake_state(os_state
, IMV_OS_STATE_END
);
399 result
= out_msg
->send_assessment(out_msg
);
400 if (result
== TNC_RESULT_SUCCESS
)
402 result
= this->agent
->provide_recommendation(this->agent
, state
);
407 /* send PA-TNC message with the EXCL flag set */
408 result
= out_msg
->send(out_msg
, TRUE
);
410 out_msg
->destroy(out_msg
);
415 METHOD(imv_agent_if_t
, receive_message
, TNC_Result
,
416 private_imv_os_agent_t
*this, TNC_ConnectionID id
,
417 TNC_MessageType msg_type
, chunk_t msg
)
423 if (!this->agent
->get_state(this->agent
, id
, &state
))
425 return TNC_RESULT_FATAL
;
427 in_msg
= imv_msg_create_from_data(this->agent
, state
, id
, msg_type
, msg
);
428 result
= receive_msg(this, state
, in_msg
);
429 in_msg
->destroy(in_msg
);
434 METHOD(imv_agent_if_t
, receive_message_long
, TNC_Result
,
435 private_imv_os_agent_t
*this, TNC_ConnectionID id
,
436 TNC_UInt32 src_imc_id
, TNC_UInt32 dst_imv_id
,
437 TNC_VendorID msg_vid
, TNC_MessageSubtype msg_subtype
, chunk_t msg
)
443 if (!this->agent
->get_state(this->agent
, id
, &state
))
445 return TNC_RESULT_FATAL
;
447 in_msg
= imv_msg_create_from_long_data(this->agent
, state
, id
,
448 src_imc_id
, dst_imv_id
, msg_vid
, msg_subtype
, msg
);
449 result
= receive_msg(this, state
, in_msg
);
450 in_msg
->destroy(in_msg
);
457 * Build an IETF Attribute Request attribute for missing attributes
459 static pa_tnc_attr_t
* build_attr_request(uint32_t received
)
462 ietf_attr_attr_request_t
*attr_cast
;
464 attr
= ietf_attr_attr_request_create(PEN_RESERVED
, 0);
465 attr_cast
= (ietf_attr_attr_request_t
*)attr
;
467 if (!(received
& IMV_OS_ATTR_PRODUCT_INFORMATION
) ||
468 !(received
& IMV_OS_ATTR_STRING_VERSION
))
470 attr_cast
->add(attr_cast
, PEN_IETF
, IETF_ATTR_PRODUCT_INFORMATION
);
471 attr_cast
->add(attr_cast
, PEN_IETF
, IETF_ATTR_STRING_VERSION
);
473 if (!(received
& IMV_OS_ATTR_NUMERIC_VERSION
))
475 attr_cast
->add(attr_cast
, PEN_IETF
, IETF_ATTR_NUMERIC_VERSION
);
477 if (!(received
& IMV_OS_ATTR_OPERATIONAL_STATUS
))
479 attr_cast
->add(attr_cast
, PEN_IETF
, IETF_ATTR_OPERATIONAL_STATUS
);
481 if (!(received
& IMV_OS_ATTR_FORWARDING_ENABLED
))
483 attr_cast
->add(attr_cast
, PEN_IETF
, IETF_ATTR_FORWARDING_ENABLED
);
485 if (!(received
& IMV_OS_ATTR_FACTORY_DEFAULT_PWD_ENABLED
))
487 attr_cast
->add(attr_cast
, PEN_IETF
,
488 IETF_ATTR_FACTORY_DEFAULT_PWD_ENABLED
);
490 if (!(received
& IMV_OS_ATTR_DEVICE_ID
))
492 attr_cast
->add(attr_cast
, PEN_ITA
, ITA_ATTR_DEVICE_ID
);
498 METHOD(imv_agent_if_t
, batch_ending
, TNC_Result
,
499 private_imv_os_agent_t
*this, TNC_ConnectionID id
)
503 imv_session_t
*session
;
504 imv_workitem_t
*workitem
;
505 imv_os_state_t
*os_state
;
506 imv_os_handshake_state_t handshake_state
;
509 TNC_Result result
= TNC_RESULT_SUCCESS
;
510 bool no_workitems
= TRUE
;
511 enumerator_t
*enumerator
;
514 if (!this->agent
->get_state(this->agent
, id
, &state
))
516 return TNC_RESULT_FATAL
;
518 os_state
= (imv_os_state_t
*)state
;
519 handshake_state
= os_state
->get_handshake_state(os_state
);
520 received
= state
->get_action_flags(state
);
521 session
= state
->get_session(state
);
522 imv_id
= this->agent
->get_id(this->agent
);
524 if (handshake_state
== IMV_OS_STATE_END
)
526 return TNC_RESULT_SUCCESS
;
529 /* create an empty out message - we might need it */
530 out_msg
= imv_msg_create(this->agent
, state
, id
, imv_id
, TNC_IMCID_ANY
,
533 if (handshake_state
== IMV_OS_STATE_INIT
)
535 size_t max_attr_size
= INSTALLED_PACKAGES_MAX_ATTR_SIZE
;
537 seg_contract_t
*contract
;
538 seg_contract_manager_t
*contracts
;
541 /* Determine maximum PA-TNC attribute segment size */
542 max_seg_size
= state
->get_max_msg_len(state
)
544 - PA_TNC_ATTR_HEADER_SIZE
545 - TCG_SEG_ATTR_SEG_ENV_HEADER
546 - PA_TNC_ATTR_HEADER_SIZE
547 - TCG_SEG_ATTR_MAX_SIZE_SIZE
;
549 /* Announce support of PA-TNC segmentation to IMC */
550 contract
= seg_contract_create(msg_types
[0], max_attr_size
,
551 max_seg_size
, TRUE
, imv_id
, FALSE
);
552 contract
->get_info_string(contract
, buf
, BUF_LEN
, TRUE
);
553 DBG2(DBG_IMV
, "%s", buf
);
554 contracts
= state
->get_contracts(state
);
555 contracts
->add_contract(contracts
, contract
);
556 attr
= tcg_seg_attr_max_size_create(max_attr_size
, max_seg_size
, TRUE
);
557 out_msg
->add_attribute(out_msg
, attr
);
559 if ((received
& IMV_OS_ATTR_MUST
) != IMV_OS_ATTR_MUST
)
561 /* create attribute request for missing mandatory attributes */
562 out_msg
->add_attribute(out_msg
, build_attr_request(received
));
566 if (handshake_state
< IMV_OS_STATE_POLICY_START
)
568 if (session
->get_policy_started(session
))
570 /* the policy script has already been started by another IMV */
571 handshake_state
= IMV_OS_STATE_POLICY_START
;
575 if (((received
& IMV_OS_ATTR_PRODUCT_INFORMATION
) &&
576 (received
& IMV_OS_ATTR_STRING_VERSION
)) &&
577 ((received
& IMV_OS_ATTR_DEVICE_ID
) ||
578 (handshake_state
== IMV_OS_STATE_ATTR_REQ
)))
580 if (!session
->get_device_id(session
, NULL
))
582 session
->set_device_id(session
, chunk_empty
);
586 /* start the policy script */
587 if (!imcv_db
->policy_script(imcv_db
, session
, TRUE
))
589 DBG1(DBG_IMV
, "error in policy script start");
594 DBG2(DBG_IMV
, "no workitems available - "
595 "no evaluation possible");
596 state
->set_recommendation(state
,
597 TNC_IMV_ACTION_RECOMMENDATION_ALLOW
,
598 TNC_IMV_EVALUATION_RESULT_DONT_KNOW
);
599 session
->set_policy_started(session
, TRUE
);
601 handshake_state
= IMV_OS_STATE_POLICY_START
;
603 else if (handshake_state
== IMV_OS_STATE_ATTR_REQ
)
606 * both the IETF Product Information and IETF String Version
607 * attribute should have been present
609 state
->set_recommendation(state
,
610 TNC_IMV_ACTION_RECOMMENDATION_NO_RECOMMENDATION
,
611 TNC_IMV_EVALUATION_RESULT_ERROR
);
613 /* send assessment */
614 result
= out_msg
->send_assessment(out_msg
);
615 out_msg
->destroy(out_msg
);
617 if (result
!= TNC_RESULT_SUCCESS
)
621 return this->agent
->provide_recommendation(this->agent
, state
);
625 handshake_state
= IMV_OS_STATE_ATTR_REQ
;
628 os_state
->set_handshake_state(os_state
, handshake_state
);
631 if (handshake_state
== IMV_OS_STATE_POLICY_START
)
633 enumerator
= session
->create_workitem_enumerator(session
);
636 while (enumerator
->enumerate(enumerator
, &workitem
))
638 if (workitem
->get_imv_id(workitem
) != TNC_IMVID_ANY
)
643 switch (workitem
->get_type(workitem
))
645 case IMV_WORKITEM_PACKAGES
:
646 attr
= ietf_attr_attr_request_create(PEN_IETF
,
647 IETF_ATTR_INSTALLED_PACKAGES
);
648 out_msg
->add_attribute(out_msg
, attr
);
650 case IMV_WORKITEM_UNKNOWN_SOURCE
:
651 attr
= ita_attr_get_settings_create(unknown_source_str
);
652 out_msg
->add_attribute(out_msg
, attr
);
654 case IMV_WORKITEM_FORWARDING
:
655 case IMV_WORKITEM_DEFAULT_PWD
:
660 workitem
->set_imv_id(workitem
, imv_id
);
661 no_workitems
= FALSE
;
663 enumerator
->destroy(enumerator
);
667 DBG2(DBG_IMV
, "IMV %d has no workitems - "
668 "no evaluation requested", imv_id
);
669 state
->set_recommendation(state
,
670 TNC_IMV_ACTION_RECOMMENDATION_ALLOW
,
671 TNC_IMV_EVALUATION_RESULT_DONT_KNOW
);
673 handshake_state
= IMV_OS_STATE_WORKITEMS
;
674 os_state
->set_handshake_state(os_state
, handshake_state
);
678 if (handshake_state
== IMV_OS_STATE_WORKITEMS
)
680 TNC_IMV_Evaluation_Result eval
;
681 TNC_IMV_Action_Recommendation rec
;
682 char result_str
[BUF_LEN
];
685 enumerator
= session
->create_workitem_enumerator(session
);
686 while (enumerator
->enumerate(enumerator
, &workitem
))
688 if (workitem
->get_imv_id(workitem
) != imv_id
)
692 eval
= TNC_IMV_EVALUATION_RESULT_DONT_KNOW
;
694 switch (workitem
->get_type(workitem
))
696 case IMV_WORKITEM_PACKAGES
:
698 int count
, count_update
, count_blacklist
, count_ok
;
700 if (!(received
& IMV_OS_ATTR_INSTALLED_PACKAGES
) ||
701 os_state
->get_missing(os_state
) > 0)
705 os_state
->get_count(os_state
, &count
, &count_update
,
706 &count_blacklist
, &count_ok
);
707 fail
= count_update
|| count_blacklist
;
708 eval
= fail ? TNC_IMV_EVALUATION_RESULT_NONCOMPLIANT_MINOR
:
709 TNC_IMV_EVALUATION_RESULT_COMPLIANT
;
710 snprintf(result_str
, BUF_LEN
, "processed %d packages: "
711 "%d not updated, %d blacklisted, %d ok, "
713 count
, count_update
, count_blacklist
, count_ok
,
714 count
- count_update
- count_blacklist
- count_ok
);
717 case IMV_WORKITEM_UNKNOWN_SOURCE
:
718 if (!(received
& IMV_OS_ATTR_SETTINGS
))
722 fail
= os_state
->get_os_settings(os_state
) &
723 OS_SETTINGS_UNKNOWN_SOURCE
;
724 eval
= fail ? TNC_IMV_EVALUATION_RESULT_NONCOMPLIANT_MINOR
:
725 TNC_IMV_EVALUATION_RESULT_COMPLIANT
;
726 snprintf(result_str
, BUF_LEN
, "unknown sources%s enabled",
729 case IMV_WORKITEM_FORWARDING
:
730 if (!(received
& IMV_OS_ATTR_FORWARDING_ENABLED
))
734 fail
= os_state
->get_os_settings(os_state
) &
735 OS_SETTINGS_FWD_ENABLED
;
736 eval
= fail ? TNC_IMV_EVALUATION_RESULT_NONCOMPLIANT_MAJOR
:
737 TNC_IMV_EVALUATION_RESULT_COMPLIANT
;
738 snprintf(result_str
, BUF_LEN
, "forwarding%s enabled",
741 case IMV_WORKITEM_DEFAULT_PWD
:
742 if (!(received
& IMV_OS_ATTR_FACTORY_DEFAULT_PWD_ENABLED
))
746 fail
= os_state
->get_os_settings(os_state
) &
747 OS_SETTINGS_DEFAULT_PWD_ENABLED
;
748 eval
= fail ? TNC_IMV_EVALUATION_RESULT_NONCOMPLIANT_MAJOR
:
749 TNC_IMV_EVALUATION_RESULT_COMPLIANT
;
750 snprintf(result_str
, BUF_LEN
, "factory default password%s enabled",
756 if (eval
!= TNC_IMV_EVALUATION_RESULT_DONT_KNOW
)
758 session
->remove_workitem(session
, enumerator
);
759 rec
= workitem
->set_result(workitem
, result_str
, eval
);
760 state
->update_recommendation(state
, rec
, eval
);
761 imcv_db
->finalize_workitem(imcv_db
, workitem
);
762 workitem
->destroy(workitem
);
765 enumerator
->destroy(enumerator
);
767 /* finalized all workitems ? */
768 if (session
->get_workitem_count(session
, imv_id
) == 0)
770 os_state
->set_handshake_state(os_state
, IMV_OS_STATE_END
);
772 result
= out_msg
->send_assessment(out_msg
);
773 out_msg
->destroy(out_msg
);
774 if (result
!= TNC_RESULT_SUCCESS
)
778 return this->agent
->provide_recommendation(this->agent
, state
);
782 /* send non-empty PA-TNC message with excl flag not set */
783 if (out_msg
->get_attribute_count(out_msg
))
785 result
= out_msg
->send(out_msg
, FALSE
);
787 out_msg
->destroy(out_msg
);
792 METHOD(imv_agent_if_t
, solicit_recommendation
, TNC_Result
,
793 private_imv_os_agent_t
*this, TNC_ConnectionID id
)
797 if (!this->agent
->get_state(this->agent
, id
, &state
))
799 return TNC_RESULT_FATAL
;
801 return this->agent
->provide_recommendation(this->agent
, state
);
804 METHOD(imv_agent_if_t
, destroy
, void,
805 private_imv_os_agent_t
*this)
807 DESTROY_IF(this->agent
);
808 DESTROY_IF(this->db
);
813 * Described in header.
815 imv_agent_if_t
*imv_os_agent_create(const char *name
, TNC_IMVID id
,
816 TNC_Version
*actual_version
)
818 private_imv_os_agent_t
*this;
821 agent
= imv_agent_create(name
, msg_types
, countof(msg_types
), id
,
830 .bind_functions
= _bind_functions
,
831 .notify_connection_change
= _notify_connection_change
,
832 .receive_message
= _receive_message
,
833 .receive_message_long
= _receive_message_long
,
834 .batch_ending
= _batch_ending
,
835 .solicit_recommendation
= _solicit_recommendation
,
839 .db
= imv_os_database_create(imcv_db
),
842 return &this->public;