load xauth module via dlopen()
[strongswan.git] / src / pluto / xauth.c
1 /* Initialization and finalization of the dynamic XAUTH module
2 * Copyright (C) 2006 Andreas Steffen
3 * Hochschule fuer Technik Rapperswil, Switzerland
4 *
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>.
9 *
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
13 * for more details.
14 *
15 * RCSID $Id: xauth.c,v 1.1 2005/01/06 22:10:15 as Exp $
16 */
17
18 #include <dlfcn.h>
19
20 #include <freeswan.h>
21
22 #include "constants.h"
23 #include "defs.h"
24 #include "xauth.h"
25 #include "keys.h"
26 #include "log.h"
27
28 void
29 xauth_init(void)
30 {
31 #ifdef XAUTH_DEFAULT_LIB
32 xauth_module.handle = dlopen(XAUTH_DEFAULT_LIB, RTLD_NOW);
33
34 if (xauth_module.handle != NULL)
35 {
36 DBG(DBG_CONTROL,
37 DBG_log("xauth module '%s' loading'", XAUTH_DEFAULT_LIB)
38 )
39 xauth_module.get_secret = (bool (*) (const xauth_t*))
40 dlsym(xauth_module.handle, "get_secret");
41 DBG(DBG_CONTROL,
42 if (xauth_module.get_secret != NULL)
43 {
44 DBG_log("xauth module: found get_secret() function");
45 }
46 )
47 xauth_module.verify_secret = (bool (*) (const xauth_t*))
48 dlsym(xauth_module.handle, "verify_secret");
49 DBG(DBG_CONTROL,
50 if (xauth_module.verify_secret != NULL)
51 {
52 DBG_log("xauth module: found verify_secret() function");
53 }
54 )
55 }
56 #endif
57 /* any null function pointers will be filled in by default functions */
58 xauth_defaults();
59 }
60
61 void
62 xauth_finalize(void)
63 {
64 if (xauth_module.handle != NULL)
65 {
66 if (dlclose(xauth_module.handle))
67 {
68 plog("failed to unload xauth module");
69 }
70 else
71 {
72 DBG(DBG_CONTROL,
73 DBG_log("xauth module unloaded")
74 )
75 }
76 }
77 }