2 * Copyright (C) 2012 Tobias Brunner
3 * Copyright (C) 2008-2009 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
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 nm_backend_t nm_backend_t
;
30 * Data for the NetworkManager backend.
35 * NetworkManager service (VPNPlugin)
37 NMStrongswanPlugin
*plugin
;
40 * Glib main loop for a thread, handles DBUS calls
45 * credential set registered at the daemon
50 * attribute handler regeisterd at the daemon
52 nm_handler_t
*handler
;
56 * Global (but private) instance of the NM backend.
58 static nm_backend_t
*nm_backend
= NULL
;
61 * NM plugin processing routine, creates and handles NMVPNPlugin
63 static job_requeue_t
run(nm_backend_t
*this)
65 this->loop
= g_main_loop_new(NULL
, FALSE
);
66 g_main_loop_run(this->loop
);
67 return JOB_REQUEUE_NONE
;
73 void nm_backend_deinit()
75 nm_backend_t
*this = nm_backend
;
83 if (g_main_loop_is_running(this->loop
))
85 g_main_loop_quit(this->loop
);
87 g_main_loop_unref(this->loop
);
91 g_object_unref(this->plugin
);
93 lib
->credmgr
->remove_set(lib
->credmgr
, &this->creds
->set
);
94 hydra
->attributes
->remove_handler(hydra
->attributes
, &this->handler
->handler
);
95 this->creds
->destroy(this->creds
);
96 this->handler
->destroy(this->handler
);
105 bool nm_backend_init()
110 if (!g_thread_supported())
116 .creds
= nm_creds_create(),
117 .handler
= nm_handler_create(),
119 this->plugin
= nm_strongswan_plugin_new(this->creds
, this->handler
);
122 hydra
->attributes
->add_handler(hydra
->attributes
, &this->handler
->handler
);
123 lib
->credmgr
->add_set(lib
->credmgr
, &this->creds
->set
);
126 DBG1(DBG_CFG
, "DBUS binding failed");
131 /* bypass file permissions to read from users ssh-agent */
132 charon
->keep_cap(charon
, CAP_DAC_OVERRIDE
);
134 lib
->processor
->queue_job(lib
->processor
,
135 (job_t
*)callback_job_create_with_prio((callback_job_cb_t
)run
,
136 this, NULL
, NULL
, JOB_PRIO_CRITICAL
));