| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
#include "nm_plugin.h" |
|---|
| 19 |
#include "nm_service.h" |
|---|
| 20 |
#include "nm_creds.h" |
|---|
| 21 |
|
|---|
| 22 |
#include <daemon.h> |
|---|
| 23 |
#include <processing/jobs/callback_job.h> |
|---|
| 24 |
|
|---|
| 25 |
#define CAP_DAC_OVERRIDE 1 |
|---|
| 26 |
|
|---|
| 27 |
typedef struct private_nm_plugin_t private_nm_plugin_t; |
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
struct private_nm_plugin_t { |
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
nm_plugin_t public; |
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
NMStrongswanPlugin *plugin; |
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 |
GMainLoop *loop; |
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 |
nm_creds_t *creds; |
|---|
| 53 |
}; |
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 |
|
|---|
| 57 |
|
|---|
| 58 |
static job_requeue_t run(private_nm_plugin_t *this) |
|---|
| 59 |
{ |
|---|
| 60 |
this->loop = g_main_loop_new(NULL, FALSE); |
|---|
| 61 |
g_main_loop_run(this->loop); |
|---|
| 62 |
g_main_loop_unref(this->loop); |
|---|
| 63 |
|
|---|
| 64 |
return JOB_REQUEUE_NONE; |
|---|
| 65 |
} |
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 |
|
|---|
| 70 |
static void destroy(private_nm_plugin_t *this) |
|---|
| 71 |
{ |
|---|
| 72 |
if (this->loop) |
|---|
| 73 |
{ |
|---|
| 74 |
g_main_loop_quit(this->loop); |
|---|
| 75 |
} |
|---|
| 76 |
if (this->plugin) |
|---|
| 77 |
{ |
|---|
| 78 |
g_object_unref(this->plugin); |
|---|
| 79 |
} |
|---|
| 80 |
charon->credentials->remove_set(charon->credentials, &this->creds->set); |
|---|
| 81 |
this->creds->destroy(this->creds); |
|---|
| 82 |
free(this); |
|---|
| 83 |
} |
|---|
| 84 |
|
|---|
| 85 |
|
|---|
| 86 |
|
|---|
| 87 |
|
|---|
| 88 |
plugin_t *plugin_create() |
|---|
| 89 |
{ |
|---|
| 90 |
private_nm_plugin_t *this = malloc_thing(private_nm_plugin_t); |
|---|
| 91 |
|
|---|
| 92 |
this->public.plugin.destroy = (void(*)(plugin_t*))destroy; |
|---|
| 93 |
|
|---|
| 94 |
this->loop = NULL; |
|---|
| 95 |
g_type_init (); |
|---|
| 96 |
if (!g_thread_supported()) |
|---|
| 97 |
{ |
|---|
| 98 |
g_thread_init(NULL); |
|---|
| 99 |
} |
|---|
| 100 |
|
|---|
| 101 |
this->creds = nm_creds_create(); |
|---|
| 102 |
charon->credentials->add_set(charon->credentials, &this->creds->set); |
|---|
| 103 |
this->plugin = nm_strongswan_plugin_new(this->creds); |
|---|
| 104 |
if (!this->plugin) |
|---|
| 105 |
{ |
|---|
| 106 |
DBG1(DBG_CFG, "DBUS binding failed"); |
|---|
| 107 |
destroy(this); |
|---|
| 108 |
return NULL; |
|---|
| 109 |
} |
|---|
| 110 |
|
|---|
| 111 |
|
|---|
| 112 |
charon->keep_cap(charon, CAP_DAC_OVERRIDE); |
|---|
| 113 |
|
|---|
| 114 |
charon->processor->queue_job(charon->processor, |
|---|
| 115 |
(job_t*)callback_job_create((callback_job_cb_t)run, this, NULL, NULL)); |
|---|
| 116 |
|
|---|
| 117 |
return &this->public.plugin; |
|---|
| 118 |
} |
|---|
| 119 |
|
|---|