2008-07-31 11:16:14 +00:00
|
|
|
/*
|
2009-04-27 09:38:31 +00:00
|
|
|
* Copyright (C) 2008-2009 Martin Willi
|
2008-07-31 11:16:14 +00:00
|
|
|
* Hochschule fuer Technik Rapperswil
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2 of the License, or (at your
|
|
|
|
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "nm_plugin.h"
|
|
|
|
#include "nm_service.h"
|
2008-08-19 15:19:45 +00:00
|
|
|
#include "nm_creds.h"
|
2009-04-27 09:38:31 +00:00
|
|
|
#include "nm_handler.h"
|
2008-07-31 11:16:14 +00:00
|
|
|
|
2010-03-24 16:46:29 +00:00
|
|
|
#include <hydra.h>
|
2008-07-31 11:16:14 +00:00
|
|
|
#include <daemon.h>
|
|
|
|
#include <processing/jobs/callback_job.h>
|
|
|
|
|
2008-09-04 08:40:37 +00:00
|
|
|
#define CAP_DAC_OVERRIDE 1
|
|
|
|
|
2008-07-31 11:16:14 +00:00
|
|
|
typedef struct private_nm_plugin_t private_nm_plugin_t;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* private data of nm plugin
|
|
|
|
*/
|
|
|
|
struct private_nm_plugin_t {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* implements plugin interface
|
|
|
|
*/
|
|
|
|
nm_plugin_t public;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-08-20 11:44:47 +00:00
|
|
|
/**
|
|
|
|
* NetworkManager service (VPNPlugin)
|
|
|
|
*/
|
|
|
|
NMStrongswanPlugin *plugin;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-08-19 15:19:45 +00:00
|
|
|
/**
|
|
|
|
* Glib main loop for a thread, handles DBUS calls
|
|
|
|
*/
|
2008-07-31 11:16:14 +00:00
|
|
|
GMainLoop *loop;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-08-19 15:19:45 +00:00
|
|
|
/**
|
|
|
|
* credential set registered at the daemon
|
|
|
|
*/
|
|
|
|
nm_creds_t *creds;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2009-04-27 09:38:31 +00:00
|
|
|
/**
|
|
|
|
* attribute handler regeisterd at the daemon
|
|
|
|
*/
|
|
|
|
nm_handler_t *handler;
|
2008-07-31 11:16:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* NM plugin processing routine, creates and handles NMVPNPlugin
|
|
|
|
*/
|
|
|
|
static job_requeue_t run(private_nm_plugin_t *this)
|
|
|
|
{
|
2008-08-20 11:44:47 +00:00
|
|
|
this->loop = g_main_loop_new(NULL, FALSE);
|
|
|
|
g_main_loop_run(this->loop);
|
2008-07-31 11:16:14 +00:00
|
|
|
return JOB_REQUEUE_NONE;
|
|
|
|
}
|
|
|
|
|
2011-04-11 16:54:18 +00:00
|
|
|
METHOD(plugin_t, get_name, char*,
|
|
|
|
private_nm_plugin_t *this)
|
|
|
|
{
|
|
|
|
return "nm";
|
|
|
|
}
|
|
|
|
|
2011-04-11 14:41:25 +00:00
|
|
|
METHOD(plugin_t, destroy, void,
|
|
|
|
private_nm_plugin_t *this)
|
2008-07-31 11:16:14 +00:00
|
|
|
{
|
|
|
|
if (this->loop)
|
|
|
|
{
|
2009-06-09 13:13:10 +00:00
|
|
|
if (g_main_loop_is_running(this->loop))
|
|
|
|
{
|
|
|
|
g_main_loop_quit(this->loop);
|
|
|
|
}
|
|
|
|
g_main_loop_unref(this->loop);
|
2008-07-31 11:16:14 +00:00
|
|
|
}
|
2008-08-20 11:44:47 +00:00
|
|
|
if (this->plugin)
|
|
|
|
{
|
|
|
|
g_object_unref(this->plugin);
|
|
|
|
}
|
2010-07-05 09:54:25 +00:00
|
|
|
lib->credmgr->remove_set(lib->credmgr, &this->creds->set);
|
2010-03-24 16:46:29 +00:00
|
|
|
hydra->attributes->remove_handler(hydra->attributes, &this->handler->handler);
|
2008-08-19 15:19:45 +00:00
|
|
|
this->creds->destroy(this->creds);
|
2009-04-27 09:38:31 +00:00
|
|
|
this->handler->destroy(this->handler);
|
2008-07-31 11:16:14 +00:00
|
|
|
free(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* see header file
|
|
|
|
*/
|
2010-02-23 15:20:38 +00:00
|
|
|
plugin_t *nm_plugin_create()
|
2008-07-31 11:16:14 +00:00
|
|
|
{
|
2011-04-11 14:41:25 +00:00
|
|
|
private_nm_plugin_t *this;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-07-31 11:16:14 +00:00
|
|
|
g_type_init ();
|
|
|
|
if (!g_thread_supported())
|
|
|
|
{
|
|
|
|
g_thread_init(NULL);
|
|
|
|
}
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2011-04-11 14:41:25 +00:00
|
|
|
INIT(this,
|
|
|
|
.public = {
|
|
|
|
.plugin = {
|
2011-04-11 16:54:18 +00:00
|
|
|
.get_name = _get_name,
|
2011-04-11 17:12:45 +00:00
|
|
|
.reload = (void*)return_false,
|
2011-04-11 14:41:25 +00:00
|
|
|
.destroy = _destroy,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
.creds = nm_creds_create(),
|
|
|
|
.handler = nm_handler_create(),
|
|
|
|
.plugin = nm_strongswan_plugin_new(this->creds, this->handler),
|
|
|
|
);
|
|
|
|
|
2010-03-24 16:46:29 +00:00
|
|
|
hydra->attributes->add_handler(hydra->attributes, &this->handler->handler);
|
2010-07-05 09:54:25 +00:00
|
|
|
lib->credmgr->add_set(lib->credmgr, &this->creds->set);
|
2008-08-20 11:44:47 +00:00
|
|
|
if (!this->plugin)
|
|
|
|
{
|
|
|
|
DBG1(DBG_CFG, "DBUS binding failed");
|
|
|
|
destroy(this);
|
|
|
|
return NULL;
|
|
|
|
}
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-09-04 08:40:37 +00:00
|
|
|
/* bypass file permissions to read from users ssh-agent */
|
|
|
|
charon->keep_cap(charon, CAP_DAC_OVERRIDE);
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2010-07-15 12:49:41 +00:00
|
|
|
lib->processor->queue_job(lib->processor,
|
2011-05-05 08:51:11 +00:00
|
|
|
(job_t*)callback_job_create_with_prio((callback_job_cb_t)run,
|
|
|
|
this, NULL, NULL, JOB_PRIO_CRITICAL));
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-07-31 11:16:14 +00:00
|
|
|
return &this->public.plugin;
|
|
|
|
}
|
|
|
|
|