2 * Copyright (C) 2008-2009 Martin Willi
3 * 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 "nm_plugin.h"
17 #include "nm_service.h"
19 #include "nm_handler.h"
23 #include <processing/jobs/callback_job.h>
25 #define CAP_DAC_OVERRIDE 1
27 typedef struct private_nm_plugin_t private_nm_plugin_t
;
30 * private data of nm plugin
32 struct private_nm_plugin_t
{
35 * implements plugin interface
40 * NetworkManager service (VPNPlugin)
42 NMStrongswanPlugin
*plugin
;
45 * Glib main loop for a thread, handles DBUS calls
50 * credential set registered at the daemon
55 * attribute handler regeisterd at the daemon
57 nm_handler_t
*handler
;
61 * NM plugin processing routine, creates and handles NMVPNPlugin
63 static job_requeue_t
run(private_nm_plugin_t
*this)
65 this->loop
= g_main_loop_new(NULL
, FALSE
);
66 g_main_loop_run(this->loop
);
67 return JOB_REQUEUE_NONE
;
70 METHOD(plugin_t
, get_name
, char*,
71 private_nm_plugin_t
*this)
76 METHOD(plugin_t
, destroy
, void,
77 private_nm_plugin_t
*this)
81 if (g_main_loop_is_running(this->loop
))
83 g_main_loop_quit(this->loop
);
85 g_main_loop_unref(this->loop
);
89 g_object_unref(this->plugin
);
91 lib
->credmgr
->remove_set(lib
->credmgr
, &this->creds
->set
);
92 hydra
->attributes
->remove_handler(hydra
->attributes
, &this->handler
->handler
);
93 this->creds
->destroy(this->creds
);
94 this->handler
->destroy(this->handler
);
101 plugin_t
*nm_plugin_create()
103 private_nm_plugin_t
*this;
106 if (!g_thread_supported())
114 .get_name
= _get_name
,
115 .reload
= (void*)return_false
,
119 .creds
= nm_creds_create(),
120 .handler
= nm_handler_create(),
122 this->plugin
= nm_strongswan_plugin_new(this->creds
, this->handler
);
124 hydra
->attributes
->add_handler(hydra
->attributes
, &this->handler
->handler
);
125 lib
->credmgr
->add_set(lib
->credmgr
, &this->creds
->set
);
128 DBG1(DBG_CFG
, "DBUS binding failed");
133 /* bypass file permissions to read from users ssh-agent */
134 charon
->keep_cap(charon
, CAP_DAC_OVERRIDE
);
136 lib
->processor
->queue_job(lib
->processor
,
137 (job_t
*)callback_job_create_with_prio((callback_job_cb_t
)run
,
138 this, NULL
, NULL
, JOB_PRIO_CRITICAL
));
140 return &this->public.plugin
;