Removed strayed code fragment
[strongswan.git] / src / charon / plugins / nm / nm_plugin.c
1 /*
2 * Copyright (C) 2008-2009 Martin Willi
3 * Hochschule fuer Technik Rapperswil
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
16 #include "nm_plugin.h"
17 #include "nm_service.h"
18 #include "nm_creds.h"
19 #include "nm_handler.h"
20
21 #include <daemon.h>
22 #include <processing/jobs/callback_job.h>
23
24 #define CAP_DAC_OVERRIDE 1
25
26 typedef struct private_nm_plugin_t private_nm_plugin_t;
27
28 /**
29 * private data of nm plugin
30 */
31 struct private_nm_plugin_t {
32
33 /**
34 * implements plugin interface
35 */
36 nm_plugin_t public;
37
38 /**
39 * NetworkManager service (VPNPlugin)
40 */
41 NMStrongswanPlugin *plugin;
42
43 /**
44 * Glib main loop for a thread, handles DBUS calls
45 */
46 GMainLoop *loop;
47
48 /**
49 * credential set registered at the daemon
50 */
51 nm_creds_t *creds;
52
53 /**
54 * attribute handler regeisterd at the daemon
55 */
56 nm_handler_t *handler;
57 };
58
59 /**
60 * NM plugin processing routine, creates and handles NMVPNPlugin
61 */
62 static job_requeue_t run(private_nm_plugin_t *this)
63 {
64 this->loop = g_main_loop_new(NULL, FALSE);
65 g_main_loop_run(this->loop);
66 return JOB_REQUEUE_NONE;
67 }
68
69 /**
70 * Implementation of plugin_t.destroy
71 */
72 static void destroy(private_nm_plugin_t *this)
73 {
74 if (this->loop)
75 {
76 if (g_main_loop_is_running(this->loop))
77 {
78 g_main_loop_quit(this->loop);
79 }
80 g_main_loop_unref(this->loop);
81 }
82 if (this->plugin)
83 {
84 g_object_unref(this->plugin);
85 }
86 charon->credentials->remove_set(charon->credentials, &this->creds->set);
87 lib->attributes->remove_handler(lib->attributes, &this->handler->handler);
88 this->creds->destroy(this->creds);
89 this->handler->destroy(this->handler);
90 free(this);
91 }
92
93 /*
94 * see header file
95 */
96 plugin_t *nm_plugin_create()
97 {
98 private_nm_plugin_t *this = malloc_thing(private_nm_plugin_t);
99
100 this->public.plugin.destroy = (void(*)(plugin_t*))destroy;
101
102 this->loop = NULL;
103 g_type_init ();
104 if (!g_thread_supported())
105 {
106 g_thread_init(NULL);
107 }
108
109 this->creds = nm_creds_create();
110 this->handler = nm_handler_create();
111 lib->attributes->add_handler(lib->attributes, &this->handler->handler);
112 charon->credentials->add_set(charon->credentials, &this->creds->set);
113 this->plugin = nm_strongswan_plugin_new(this->creds, this->handler);
114 if (!this->plugin)
115 {
116 DBG1(DBG_CFG, "DBUS binding failed");
117 destroy(this);
118 return NULL;
119 }
120
121 /* bypass file permissions to read from users ssh-agent */
122 charon->keep_cap(charon, CAP_DAC_OVERRIDE);
123
124 charon->processor->queue_job(charon->processor,
125 (job_t*)callback_job_create((callback_job_cb_t)run, this, NULL, NULL));
126
127 return &this->public.plugin;
128 }
129