2 * Copyright (C) 2009 Tobias Brunner
3 * Copyright (C) 2008 Martin Willi
4 * Hochschule fuer Technik Rapperswil
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
24 #include <utils/identification.h>
25 #include <utils/host.h>
27 #include <utils/leak_detective.h>
30 #define CHECKSUM_LIBRARY IPSEC_DIR"/libchecksum.so"
32 typedef struct private_library_t private_library_t
;
35 * private data of library
37 struct private_library_t
{
46 * Memory leak detective, if enabled
48 leak_detective_t
*detective
;
49 #endif /* LEAK_DETECTIVE */
58 * Implementation of library_t.destroy
62 private_library_t
*this = (private_library_t
*)lib
;
64 this->public.plugins
->destroy(this->public.plugins
);
65 this->public.settings
->destroy(this->public.settings
);
66 this->public.creds
->destroy(this->public.creds
);
67 this->public.crypto
->destroy(this->public.crypto
);
68 this->public.fetcher
->destroy(this->public.fetcher
);
69 this->public.db
->destroy(this->public.db
);
70 this->public.printf_hook
->destroy(this->public.printf_hook
);
71 if (this->public.integrity
)
73 this->public.integrity
->destroy(this->public.integrity
);
79 this->detective
->destroy(this->detective
);
81 #endif /* LEAK_DETECTIVE */
89 bool library_init(char *settings
)
92 private_library_t
*this = malloc_thing(private_library_t
);
95 lib
->leak_detective
= FALSE
;
98 this->detective
= leak_detective_create();
99 #endif /* LEAK_DETECTIVE */
101 pfh
= printf_hook_create();
102 this->public.printf_hook
= pfh
;
104 pfh
->add_handler(pfh
, 'b', mem_printf_hook
,
105 PRINTF_HOOK_ARGTYPE_POINTER
, PRINTF_HOOK_ARGTYPE_INT
,
106 PRINTF_HOOK_ARGTYPE_END
);
107 pfh
->add_handler(pfh
, 'B', chunk_printf_hook
,
108 PRINTF_HOOK_ARGTYPE_POINTER
, PRINTF_HOOK_ARGTYPE_END
);
109 pfh
->add_handler(pfh
, 'H', host_printf_hook
,
110 PRINTF_HOOK_ARGTYPE_POINTER
, PRINTF_HOOK_ARGTYPE_END
);
111 pfh
->add_handler(pfh
, 'N', enum_printf_hook
,
112 PRINTF_HOOK_ARGTYPE_POINTER
, PRINTF_HOOK_ARGTYPE_INT
,
113 PRINTF_HOOK_ARGTYPE_END
);
114 pfh
->add_handler(pfh
, 'T', time_printf_hook
,
115 PRINTF_HOOK_ARGTYPE_POINTER
, PRINTF_HOOK_ARGTYPE_INT
,
116 PRINTF_HOOK_ARGTYPE_END
);
117 pfh
->add_handler(pfh
, 'V', time_delta_printf_hook
,
118 PRINTF_HOOK_ARGTYPE_POINTER
, PRINTF_HOOK_ARGTYPE_POINTER
,
119 PRINTF_HOOK_ARGTYPE_END
);
120 pfh
->add_handler(pfh
, 'Y', identification_printf_hook
,
121 PRINTF_HOOK_ARGTYPE_POINTER
, PRINTF_HOOK_ARGTYPE_END
);
123 this->public.settings
= settings_create(settings
);
124 this->public.crypto
= crypto_factory_create();
125 this->public.creds
= credential_factory_create();
126 this->public.fetcher
= fetcher_manager_create();
127 this->public.db
= database_factory_create();
128 this->public.plugins
= plugin_loader_create();
129 this->public.integrity
= NULL
;
131 if (lib
->settings
->get_bool(lib
->settings
,
132 "libstrongswan.integrity_test", FALSE
))
134 this->public.integrity
= integrity_checker_create(CHECKSUM_LIBRARY
);
135 if (!lib
->integrity
->check_segment(lib
->integrity
,
136 "libstrongswan", library_init
))
138 DBG1("integrity check of libstrongswan failed");