store detected improper OS settings in database
[strongswan.git] / src / libpts / libpts.c
1 /*
2 * Copyright (C) 2011 Andreas Steffen, HSR Hochschule fuer Technik Rapperswil
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * for more details.
13 */
14
15 #include "libpts.h"
16 #include "tcg/tcg_attr.h"
17 #include "pts/components/pts_component.h"
18 #include "pts/components/pts_component_manager.h"
19 #include "pts/components/tcg/tcg_comp_func_name.h"
20 #include "pts/components/ita/ita_comp_func_name.h"
21 #include "pts/components/ita/ita_comp_ima.h"
22 #include "pts/components/ita/ita_comp_tboot.h"
23 #include "pts/components/ita/ita_comp_tgrub.h"
24
25 #include <imcv.h>
26 #include <utils/debug.h>
27
28 /**
29 * PTS Functional Component manager
30 */
31 pts_component_manager_t *pts_components;
32
33 /**
34 * Reference count for IMC/IMV instances
35 */
36 static refcount_t libpts_ref = 0;
37
38 /**
39 * Described in header.
40 */
41 bool libpts_init(void)
42 {
43 if (libpts_ref == 0)
44 {
45 if (!imcv_pa_tnc_attributes)
46 {
47 return FALSE;
48 }
49 imcv_pa_tnc_attributes->add_vendor(imcv_pa_tnc_attributes, PEN_TCG,
50 tcg_attr_create_from_data, tcg_attr_names);
51
52 pts_components = pts_component_manager_create();
53 pts_components->add_vendor(pts_components, PEN_TCG,
54 pts_tcg_comp_func_names, PTS_TCG_QUALIFIER_TYPE_SIZE,
55 pts_tcg_qualifier_flag_names, pts_tcg_qualifier_type_names);
56 pts_components->add_vendor(pts_components, PEN_ITA,
57 pts_ita_comp_func_names, PTS_ITA_QUALIFIER_TYPE_SIZE,
58 pts_ita_qualifier_flag_names, pts_ita_qualifier_type_names);
59
60 pts_components->add_component(pts_components, PEN_ITA,
61 PTS_ITA_COMP_FUNC_NAME_TGRUB,
62 pts_ita_comp_tgrub_create);
63 pts_components->add_component(pts_components, PEN_ITA,
64 PTS_ITA_COMP_FUNC_NAME_TBOOT,
65 pts_ita_comp_tboot_create);
66 pts_components->add_component(pts_components, PEN_ITA,
67 PTS_ITA_COMP_FUNC_NAME_IMA,
68 pts_ita_comp_ima_create);
69
70 DBG1(DBG_LIB, "libpts initialized");
71 }
72 ref_get(&libpts_ref);
73
74 return TRUE;
75 }
76
77 /**
78 * Described in header.
79 */
80 void libpts_deinit(void)
81 {
82 if (ref_put(&libpts_ref))
83 {
84 pts_components->remove_vendor(pts_components, PEN_TCG);
85 pts_components->remove_vendor(pts_components, PEN_ITA);
86 pts_components->destroy(pts_components);
87
88 if (!imcv_pa_tnc_attributes)
89 {
90 return;
91 }
92 imcv_pa_tnc_attributes->remove_vendor(imcv_pa_tnc_attributes, PEN_TCG);
93 DBG1(DBG_LIB, "libpts terminated");
94 }
95 }
96