mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-25 03:40:07 +01:00
2007-09-12 Tambet Ingo <tambet@gmail.com>
* src/nm-vpnc-service.[ch]: Rewrite. Derive from NMVPNPlugin.
* src/nm-vpnc-service-vpnc-helper.c: Rewrite using dbus-glib.
* auth-dialog/main.c: Populate the properties hash with the
* passwords.
* properties/nm-vpnc.c: The VPN connection properties are all
* hash tables now.
* src/nm-utils.[ch]: Remove. Use the same things from
* libnm-util.
* configure.in: Check libnm_glib module as well now that we use
* NMVPNPlugin.
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@2797 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:
parent
594dd3f208
commit
be3a380b08
11 changed files with 537 additions and 1724 deletions
|
|
@ -1,3 +1,17 @@
|
|||
2007-09-12 Tambet Ingo <tambet@gmail.com>
|
||||
|
||||
* src/nm-vpnc-service.[ch]: Rewrite. Derive from NMVPNPlugin.
|
||||
|
||||
* src/nm-vpnc-service-vpnc-helper.c: Rewrite using dbus-glib.
|
||||
|
||||
* auth-dialog/main.c: Populate the properties hash with the passwords.
|
||||
|
||||
* properties/nm-vpnc.c: The VPN connection properties are all hash tables now.
|
||||
|
||||
* src/nm-utils.[ch]: Remove. Use the same things from libnm-util.
|
||||
|
||||
* configure.in: Check libnm_glib module as well now that we use NMVPNPlugin.
|
||||
|
||||
2007-08-15 Tambet Ingo <tambet@gmail.com>
|
||||
|
||||
* nm-vpnc-service.name.in: Use upper-case macro names as that's what the
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ INCLUDES = -I${top_srcdir} -I${top_srcdir}/utils
|
|||
libexec_PROGRAMS = nm-vpnc-auth-dialog
|
||||
|
||||
nm_vpnc_auth_dialog_CPPFLAGS = \
|
||||
$(NM_UTILS_CFLAGS) \
|
||||
$(GTHREAD_CFLAGS) \
|
||||
$(GTK_CFLAGS) \
|
||||
$(LIBGNOMEUI_CFLAGS) \
|
||||
|
|
|
|||
|
|
@ -29,10 +29,9 @@
|
|||
#include <libgnomeui/libgnomeui.h>
|
||||
#include <gnome-keyring.h>
|
||||
|
||||
#include "../src/nm-vpnc-service.h"
|
||||
#include "gnome-two-password-dialog.h"
|
||||
|
||||
#define VPN_SERVICE "org.freedesktop.NetworkManager.vpnc"
|
||||
|
||||
static GSList *
|
||||
lookup_pass (const char *vpn_name, const char *vpn_service, gboolean *is_session)
|
||||
{
|
||||
|
|
@ -222,12 +221,10 @@ get_passwords (const char *vpn_name, const char *vpn_service, gboolean retry)
|
|||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
GSList *i;
|
||||
GSList *passwords;
|
||||
static gboolean retry = FALSE;
|
||||
static gchar *vpn_name = NULL;
|
||||
static gchar *vpn_service = NULL;
|
||||
GError *error = NULL;
|
||||
GOptionContext *context;
|
||||
GnomeProgram *program;
|
||||
GOptionEntry entries[] =
|
||||
|
|
@ -260,8 +257,8 @@ main (int argc, char *argv[])
|
|||
goto out;
|
||||
}
|
||||
|
||||
if (strcmp (vpn_service, VPN_SERVICE) != 0) {
|
||||
fprintf (stderr, "This dialog only works with the '%s' service\n", VPN_SERVICE);
|
||||
if (strcmp (vpn_service, NM_DBUS_SERVICE_VPNC) != 0) {
|
||||
fprintf (stderr, "This dialog only works with the '%s' service\n", NM_DBUS_SERVICE_VPNC);
|
||||
goto out;
|
||||
}
|
||||
|
||||
|
|
@ -270,11 +267,11 @@ main (int argc, char *argv[])
|
|||
goto out;
|
||||
|
||||
/* dump the passwords to stdout */
|
||||
for (i = passwords; i != NULL; i = g_slist_next (i)) {
|
||||
char *password = (char *) i->data;
|
||||
printf ("%s\n", password);
|
||||
}
|
||||
|
||||
printf ("%s\n%s\n", NM_VPNC_KEY_SECRET, (char *) passwords->data);
|
||||
printf ("%s\n%s\n", NM_VPNC_KEY_XAUTH_PASSWORD, (char *) passwords->next->data);
|
||||
printf ("\n\n");
|
||||
|
||||
/* for good measure, flush stdout since Kansas is going Bye-Bye */
|
||||
fflush (stdout);
|
||||
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ if test x"$with_gnome" != xno; then
|
|||
AC_SUBST(GNOMEKEYRING_LIBS)
|
||||
fi
|
||||
|
||||
PKG_CHECK_MODULES(NM_UTILS, NetworkManager >= 0.7.0 libnm-util)
|
||||
PKG_CHECK_MODULES(NM_UTILS, NetworkManager >= 0.7.0 libnm-util libnm_glib)
|
||||
AC_SUBST(NM_UTILS_CFLAGS)
|
||||
AC_SUBST(NM_UTILS_LIBS)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
/* -*- Mode: C; tab-width: 5; indent-tabs-mode: t; c-basic-offset: 5 -*- */
|
||||
/***************************************************************************
|
||||
* CVSID: $Id$
|
||||
*
|
||||
|
|
@ -25,6 +26,7 @@
|
|||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <glib/gi18n-lib.h>
|
||||
#include <string.h>
|
||||
#include <glade/glade.h>
|
||||
|
|
@ -32,6 +34,7 @@
|
|||
#define NM_VPN_API_SUBJECT_TO_CHANGE
|
||||
|
||||
#include <nm-vpn-ui-interface.h>
|
||||
#include "../src/nm-vpnc-service.h"
|
||||
#include "pcf-file.h"
|
||||
|
||||
typedef struct _NetworkManagerVpnUIImpl NetworkManagerVpnUIImpl;
|
||||
|
|
@ -97,47 +100,49 @@ impl_get_service_name (NetworkManagerVpnUI *self)
|
|||
return "org.freedesktop.NetworkManager.vpnc";
|
||||
}
|
||||
|
||||
static GtkWidget *
|
||||
impl_get_widget (NetworkManagerVpnUI *self, GSList *properties, GSList *routes, const char *connection_name)
|
||||
static void
|
||||
set_property (gpointer key, gpointer val, gpointer user_data)
|
||||
{
|
||||
NetworkManagerVpnUIImpl *impl = (NetworkManagerVpnUIImpl *) user_data;
|
||||
const char *name = (const char *) key;
|
||||
GValue *value = (GValue *) val;
|
||||
|
||||
if (!strcmp (name, NM_VPNC_KEY_GATEWAY)) {
|
||||
gtk_entry_set_text (impl->w_gateway, g_value_get_string (value));
|
||||
} else if (!strcmp (name, NM_VPNC_KEY_ID)) {
|
||||
gtk_entry_set_text (impl->w_group_name, g_value_get_string (value));
|
||||
} else if (!strcmp (name, NM_VPNC_KEY_XAUTH_USER)) {
|
||||
gtk_entry_set_text (impl->w_username, g_value_get_string (value));
|
||||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (impl->w_use_alternate_username), TRUE);
|
||||
gtk_widget_set_sensitive (GTK_WIDGET (impl->w_username), TRUE);
|
||||
} else if (!strcmp (name, NM_VPNC_KEY_DOMAIN)) {
|
||||
gtk_entry_set_text (impl->w_domain, g_value_get_string (value));
|
||||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (impl->w_use_domain), TRUE);
|
||||
gtk_widget_set_sensitive (GTK_WIDGET (impl->w_domain), TRUE);
|
||||
} else if (!strcmp (name, NM_VPNC_KEY_NAT_KEEPALIVE)) {
|
||||
gtk_entry_set_text (impl->w_keepalive, g_value_get_string (value));
|
||||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (impl->w_use_keepalive), TRUE);
|
||||
gtk_widget_set_sensitive (GTK_WIDGET (impl->w_keepalive), TRUE);
|
||||
} else if (!strcmp (name, NM_VPNC_KEY_DISABLE_NAT)) {
|
||||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (impl->w_disable_natt), g_value_get_boolean (value));
|
||||
} else if (!strcmp (name, NM_VPNC_KEY_SINGLE_DES)) {
|
||||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (impl->w_enable_singledes), g_value_get_boolean (value));
|
||||
}
|
||||
}
|
||||
|
||||
static GtkWidget *
|
||||
impl_get_widget (NetworkManagerVpnUI *self, GHashTable *properties, GSList *routes, const char *connection_name)
|
||||
{
|
||||
GSList *i;
|
||||
NetworkManagerVpnUIImpl *impl = (NetworkManagerVpnUIImpl *) self->data;
|
||||
GSList *i;
|
||||
|
||||
vpnc_clear_widget (impl);
|
||||
|
||||
if (connection_name != NULL)
|
||||
gtk_entry_set_text (impl->w_connection_name, connection_name);
|
||||
|
||||
for (i = properties; i != NULL && g_slist_next (i) != NULL; i = g_slist_next (g_slist_next (i))) {
|
||||
const char *key;
|
||||
const char *value;
|
||||
|
||||
key = i->data;
|
||||
value = (g_slist_next (i))->data;
|
||||
|
||||
if (strcmp (key, "IPSec gateway") == 0) {
|
||||
gtk_entry_set_text (impl->w_gateway, value);
|
||||
} else if (strcmp (key, "IPSec ID") == 0) {
|
||||
gtk_entry_set_text (impl->w_group_name, value);
|
||||
} else if (strcmp (key, "Xauth username") == 0) {
|
||||
gtk_entry_set_text (impl->w_username, value);
|
||||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (impl->w_use_alternate_username), TRUE);
|
||||
gtk_widget_set_sensitive (GTK_WIDGET (impl->w_username), TRUE);
|
||||
} else if (strcmp (key, "Domain") == 0) {
|
||||
gtk_entry_set_text (impl->w_domain, value);
|
||||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (impl->w_use_domain), TRUE);
|
||||
gtk_widget_set_sensitive (GTK_WIDGET (impl->w_domain), TRUE);
|
||||
} else if (strcmp (key, "NAT-Keepalive packet interval") == 0) {
|
||||
gtk_entry_set_text (impl->w_keepalive, value);
|
||||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (impl->w_use_keepalive), TRUE);
|
||||
gtk_widget_set_sensitive (GTK_WIDGET (impl->w_keepalive), TRUE);
|
||||
} else if (strcmp (key, "Disable NAT Traversal") == 0) {
|
||||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (impl->w_disable_natt), TRUE);
|
||||
} else if (strcmp (key, "Enable Single DES") == 0) {
|
||||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (impl->w_enable_singledes), TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
if (properties)
|
||||
g_hash_table_foreach (properties, set_property, self);
|
||||
|
||||
if (routes != NULL) {
|
||||
GString *route_str;
|
||||
|
|
@ -164,15 +169,36 @@ impl_get_widget (NetworkManagerVpnUI *self, GSList *properties, GSList *routes,
|
|||
return impl->widget;
|
||||
}
|
||||
|
||||
static GSList *
|
||||
impl_get_properties (NetworkManagerVpnUI *self)
|
||||
static GValue *
|
||||
str_to_gvalue (const char *str)
|
||||
{
|
||||
GValue *value;
|
||||
|
||||
value = g_slice_new0 (GValue);
|
||||
g_value_init (value, G_TYPE_STRING);
|
||||
g_value_set_string (value, str);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
static GValue *
|
||||
bool_to_gvalue (gboolean b)
|
||||
{
|
||||
GValue *value;
|
||||
|
||||
value = g_slice_new0 (GValue);
|
||||
g_value_init (value, G_TYPE_BOOLEAN);
|
||||
g_value_set_boolean (value, b);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
impl_get_properties (NetworkManagerVpnUI *self, GHashTable *properties)
|
||||
{
|
||||
GSList *data;
|
||||
NetworkManagerVpnUIImpl *impl = (NetworkManagerVpnUIImpl *) self->data;
|
||||
const char *connectionname;
|
||||
const char *gateway;
|
||||
const char *groupname;
|
||||
const char *secret;
|
||||
gboolean use_alternate_username;
|
||||
const char *username;
|
||||
gboolean use_keepalive;
|
||||
|
|
@ -182,7 +208,6 @@ impl_get_properties (NetworkManagerVpnUI *self)
|
|||
gboolean enable_singledes;
|
||||
const char *domain;
|
||||
|
||||
connectionname = gtk_entry_get_text (impl->w_connection_name);
|
||||
gateway = gtk_entry_get_text (impl->w_gateway);
|
||||
groupname = gtk_entry_get_text (impl->w_group_name);
|
||||
use_alternate_username = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (impl->w_use_alternate_username));
|
||||
|
|
@ -194,33 +219,21 @@ impl_get_properties (NetworkManagerVpnUI *self)
|
|||
enable_singledes = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (impl->w_enable_singledes));
|
||||
domain = gtk_entry_get_text (impl->w_domain);
|
||||
|
||||
data = NULL;
|
||||
data = g_slist_append (data, g_strdup ("IPSec gateway"));
|
||||
data = g_slist_append (data, g_strdup (gateway));
|
||||
data = g_slist_append (data, g_strdup ("IPSec ID"));
|
||||
data = g_slist_append (data, g_strdup (groupname));
|
||||
if (use_alternate_username) {
|
||||
data = g_slist_append (data, g_strdup ("Xauth username"));
|
||||
data = g_slist_append (data, g_strdup (username));
|
||||
}
|
||||
if (use_domain) {
|
||||
data = g_slist_append (data, g_strdup ("Domain"));
|
||||
data = g_slist_append (data, g_strdup (domain));
|
||||
}
|
||||
if (use_keepalive) {
|
||||
data = g_slist_append (data, g_strdup ("NAT-Keepalive packet interval"));
|
||||
data = g_slist_append (data, g_strdup (keepalive));
|
||||
}
|
||||
if (enable_singledes) {
|
||||
data = g_slist_append (data, g_strdup ("Enable Single DES"));
|
||||
data = g_slist_append (data, g_strdup (""));
|
||||
}
|
||||
if (disable_natt) {
|
||||
data = g_slist_append (data, g_strdup ("Disable NAT Traversal"));
|
||||
data = g_slist_append (data, g_strdup (""));
|
||||
}
|
||||
g_hash_table_insert (properties, NM_VPNC_KEY_GATEWAY, str_to_gvalue (gateway));
|
||||
g_hash_table_insert (properties, NM_VPNC_KEY_ID, str_to_gvalue (groupname));
|
||||
|
||||
return data;
|
||||
if (use_alternate_username)
|
||||
g_hash_table_insert (properties, NM_VPNC_KEY_XAUTH_USER, str_to_gvalue (username));
|
||||
if (use_domain)
|
||||
g_hash_table_insert (properties, NM_VPNC_KEY_DOMAIN, str_to_gvalue (domain));
|
||||
if (use_keepalive)
|
||||
g_hash_table_insert (properties, NM_VPNC_KEY_NAT_KEEPALIVE, str_to_gvalue (keepalive));
|
||||
if (enable_singledes)
|
||||
g_hash_table_insert (properties, NM_VPNC_KEY_SINGLE_DES, bool_to_gvalue (TRUE));
|
||||
if (disable_natt)
|
||||
g_hash_table_insert (properties, NM_VPNC_KEY_DISABLE_NAT, bool_to_gvalue (TRUE));
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static GSList *
|
||||
|
|
@ -702,10 +715,14 @@ impl_import_file (NetworkManagerVpnUI *self, const char *path)
|
|||
}
|
||||
|
||||
static gboolean
|
||||
export_to_file (NetworkManagerVpnUIImpl *impl, const char *path,
|
||||
GSList *properties, GSList *routes, const char *connection_name)
|
||||
export_to_file (NetworkManagerVpnUIImpl *impl,
|
||||
const char *path,
|
||||
GHashTable *properties,
|
||||
GSList *routes,
|
||||
const char *connection_name)
|
||||
{
|
||||
FILE *f;
|
||||
GValue *val;
|
||||
GSList *i;
|
||||
const char *gateway = NULL;
|
||||
const char *keepalive = "0";
|
||||
|
|
@ -719,30 +736,33 @@ export_to_file (NetworkManagerVpnUIImpl *impl, const char *path,
|
|||
|
||||
/*printf ("in export_to_file; path='%s'\n", path);*/
|
||||
|
||||
for (i = properties; i != NULL && g_slist_next (i) != NULL; i = g_slist_next (g_slist_next (i))) {
|
||||
const char *key;
|
||||
const char *value;
|
||||
val = (GValue *) g_hash_table_lookup (properties, NM_VPNC_KEY_GATEWAY);
|
||||
if (val)
|
||||
gateway = g_value_get_string (val);
|
||||
|
||||
key = i->data;
|
||||
value = (g_slist_next (i))->data;
|
||||
val = (GValue *) g_hash_table_lookup (properties, NM_VPNC_KEY_ID);
|
||||
if (val)
|
||||
groupname = g_value_get_string (val);
|
||||
|
||||
if (strcmp (key, "IPSec gateway") == 0) {
|
||||
gateway = value;
|
||||
} else if (strcmp (key, "IPSec ID") == 0) {
|
||||
groupname = value;
|
||||
} else if (strcmp (key, "Xauth username") == 0) {
|
||||
username = value;
|
||||
} else if (strcmp (key, "Domain") == 0) {
|
||||
domain = value;
|
||||
} else if (strcmp (key, "Disable NAT Traversal") == 0) {
|
||||
enablenat = "0";
|
||||
} else if (strcmp (key, "Enable Single DES") == 0) {
|
||||
singledes = "1";
|
||||
} else if (strcmp (key, "NAT-Keepalive packet interval") == 0) {
|
||||
keepalive = value;
|
||||
}
|
||||
}
|
||||
val = (GValue *) g_hash_table_lookup (properties, NM_VPNC_KEY_XAUTH_USER);
|
||||
if (val)
|
||||
username = g_value_get_string (val);
|
||||
|
||||
val = (GValue *) g_hash_table_lookup (properties, NM_VPNC_KEY_DOMAIN);
|
||||
if (val)
|
||||
domain = g_value_get_string (val);
|
||||
|
||||
val = (GValue *) g_hash_table_lookup (properties, NM_VPNC_KEY_DISABLE_NAT);
|
||||
if (val)
|
||||
enablenat = g_value_get_boolean (val) ? "0" : "1";
|
||||
|
||||
val = (GValue *) g_hash_table_lookup (properties, NM_VPNC_KEY_SINGLE_DES);
|
||||
if (val)
|
||||
singledes = g_value_get_boolean (val) ? "1" : "0";
|
||||
|
||||
val = (GValue *) g_hash_table_lookup (properties, NM_VPNC_KEY_NAT_KEEPALIVE);
|
||||
if (val)
|
||||
keepalive = g_value_get_string (val);
|
||||
|
||||
if (routes != NULL) {
|
||||
GString *str;
|
||||
|
|
@ -828,7 +848,7 @@ out:
|
|||
|
||||
|
||||
static gboolean
|
||||
impl_export (NetworkManagerVpnUI *self, GSList *properties, GSList *routes, const char *connection_name)
|
||||
impl_export (NetworkManagerVpnUI *self, GHashTable *properties, GSList *routes, const char *connection_name)
|
||||
{
|
||||
char *suggested_name;
|
||||
char *path = NULL;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
INCLUDES = -I${top_srcdir} -I${top_srcdir}/utils -I${top_srcdir}/vpn-daemons/vpnc
|
||||
INCLUDES = -I${top_srcdir}
|
||||
|
||||
AM_CPPFLAGS = \
|
||||
$(DBUS_CFLAGS) \
|
||||
|
|
@ -20,15 +20,14 @@ bin_PROGRAMS = nm-vpnc-service nm-vpnc-service-vpnc-helper
|
|||
|
||||
nm_vpnc_service_SOURCES = \
|
||||
nm-vpnc-service.c \
|
||||
nm-vpnc-service.h \
|
||||
nm-utils.c \
|
||||
nm-utils.h
|
||||
nm-vpnc-service.h
|
||||
|
||||
|
||||
nm_vpnc_service_LDADD = \
|
||||
$(DBUS_LIBS) \
|
||||
$(GTHREAD_LIBS) \
|
||||
$(NM_UTILS_LIBS)
|
||||
$(NM_UTILS_LIBS) \
|
||||
-lnm_glib_vpn
|
||||
|
||||
|
||||
nm_vpnc_service_vpnc_helper_SOURCES = \
|
||||
|
|
|
|||
|
|
@ -1,132 +0,0 @@
|
|||
/* NetworkManager -- Network link manager
|
||||
*
|
||||
* Ray Strode <rstrode@redhat.com>
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* (C) Copyright 2005 Red Hat, Inc.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <glib.h>
|
||||
#include "nm-utils.h"
|
||||
|
||||
gchar *nm_dbus_escape_object_path (const gchar *utf8_string)
|
||||
{
|
||||
const gchar *p;
|
||||
gchar *object_path;
|
||||
GString *string;
|
||||
|
||||
g_return_val_if_fail (utf8_string != NULL, NULL);
|
||||
g_return_val_if_fail (g_utf8_validate (utf8_string, -1, NULL), NULL);
|
||||
|
||||
string = g_string_sized_new ((strlen (utf8_string) + 1) * 6);
|
||||
|
||||
for (p = utf8_string; *p != '\0'; p = g_utf8_next_char (p))
|
||||
{
|
||||
gunichar character;
|
||||
|
||||
character = g_utf8_get_char (p);
|
||||
|
||||
if (((character >= ((gunichar) 'a')) &&
|
||||
(character <= ((gunichar) 'z'))) ||
|
||||
((character >= ((gunichar) 'A')) &&
|
||||
(character <= ((gunichar) 'Z'))) ||
|
||||
((character >= ((gunichar) '0')) &&
|
||||
(character <= ((gunichar) '9'))) ||
|
||||
(character == ((gunichar) '/')))
|
||||
{
|
||||
g_string_append_c (string, (gchar) character);
|
||||
continue;
|
||||
}
|
||||
|
||||
g_string_append_printf (string, "_%x_", character);
|
||||
}
|
||||
|
||||
object_path = string->str;
|
||||
|
||||
g_string_free (string, FALSE);
|
||||
|
||||
return object_path;
|
||||
}
|
||||
|
||||
gchar *nm_dbus_unescape_object_path (const gchar *object_path)
|
||||
{
|
||||
const gchar *p;
|
||||
gchar *utf8_string;
|
||||
GString *string;
|
||||
|
||||
g_return_val_if_fail (object_path != NULL, NULL);
|
||||
|
||||
string = g_string_sized_new (strlen (object_path) + 1);
|
||||
|
||||
for (p = object_path; *p != '\0'; p++)
|
||||
{
|
||||
const gchar *q;
|
||||
gchar *hex_digits, *end, utf8_character[6] = { '\0' };
|
||||
gint utf8_character_size;
|
||||
gunichar character;
|
||||
gulong hex_value;
|
||||
|
||||
if (*p != '_')
|
||||
{
|
||||
g_string_append_c (string, *p);
|
||||
continue;
|
||||
}
|
||||
|
||||
q = strchr (p + 1, '_');
|
||||
|
||||
if ((q == NULL) || (q == p + 1))
|
||||
{
|
||||
g_string_free (string, TRUE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
hex_digits = g_strndup (p + 1, (q - 1) - p);
|
||||
|
||||
hex_value = strtoul (hex_digits, &end, 16);
|
||||
|
||||
character = (gunichar) hex_value;
|
||||
|
||||
if (((hex_value == G_MAXLONG) && (errno == ERANGE)) ||
|
||||
(hex_value > G_MAXUINT32) ||
|
||||
(*end != '\0') ||
|
||||
(!g_unichar_validate (character)))
|
||||
{
|
||||
g_free (hex_digits);
|
||||
g_string_free (string, TRUE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
utf8_character_size =
|
||||
g_unichar_to_utf8 (character, utf8_character);
|
||||
|
||||
g_assert (utf8_character_size > 0);
|
||||
|
||||
g_string_append_len (string, utf8_character,
|
||||
utf8_character_size);
|
||||
|
||||
p = q;
|
||||
}
|
||||
|
||||
utf8_string = string->str;
|
||||
|
||||
g_string_free (string, FALSE);
|
||||
|
||||
return utf8_string;
|
||||
}
|
||||
|
|
@ -1,131 +0,0 @@
|
|||
/* NetworkManager -- Network link manager
|
||||
*
|
||||
* Ray Strode <rstrode@redhat.com>
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* (C) Copyright 2005 Red Hat, Inc.
|
||||
*/
|
||||
|
||||
#ifndef NM_UTILS_H
|
||||
#define NM_UTILS_H
|
||||
|
||||
#include <glib.h>
|
||||
#include <execinfo.h>
|
||||
|
||||
#define nm_print_backtrace() \
|
||||
G_STMT_START \
|
||||
{ \
|
||||
void *_call_stack[512]; \
|
||||
int _call_stack_size; \
|
||||
char **_symbols; \
|
||||
_call_stack_size = backtrace (_call_stack, \
|
||||
G_N_ELEMENTS (_call_stack)); \
|
||||
_symbols = backtrace_symbols (_call_stack, _call_stack_size); \
|
||||
if (_symbols != NULL) \
|
||||
{ \
|
||||
int _i; \
|
||||
_i = 0; \
|
||||
g_critical ("traceback:\n"); \
|
||||
while (_i < _call_stack_size) \
|
||||
{ \
|
||||
g_critical ("\t%s\n", _symbols[_i]); \
|
||||
_i++; \
|
||||
} \
|
||||
free (_symbols); \
|
||||
} \
|
||||
} \
|
||||
G_STMT_END
|
||||
|
||||
#define nm_get_timestamp(timestamp) \
|
||||
G_STMT_START \
|
||||
{ \
|
||||
GTimeVal _tv; \
|
||||
g_get_current_time (&_tv); \
|
||||
*timestamp = (_tv.tv_sec * (1.0 * G_USEC_PER_SEC) + \
|
||||
_tv.tv_usec) / G_USEC_PER_SEC; \
|
||||
} \
|
||||
G_STMT_END
|
||||
|
||||
#define nm_info(fmt, args...) \
|
||||
G_STMT_START \
|
||||
{ \
|
||||
g_message ("<information>\t" fmt "\n", ##args); \
|
||||
} G_STMT_END
|
||||
|
||||
#define nm_info_str(fmt_str, args...) \
|
||||
G_STMT_START \
|
||||
{ \
|
||||
g_message ("<information>\t%s\n", fmt_str, ##args); \
|
||||
} G_STMT_END
|
||||
|
||||
#define nm_debug(fmt, args...) \
|
||||
G_STMT_START \
|
||||
{ \
|
||||
gdouble _timestamp; \
|
||||
nm_get_timestamp (&_timestamp); \
|
||||
g_debug ("<debug info>\t[%f] %s (): " fmt "\n", _timestamp, \
|
||||
G_STRFUNC, ##args); \
|
||||
} G_STMT_END
|
||||
|
||||
#define nm_debug_str(fmt_str, args...) \
|
||||
G_STMT_START \
|
||||
{ \
|
||||
gdouble _timestamp; \
|
||||
nm_get_timestamp (&_timestamp); \
|
||||
g_debug ("<debug info>\t[%f] %s (): %s\n", _timestamp, \
|
||||
G_STRFUNC, fmt_str, ##args); \
|
||||
} G_STMT_END
|
||||
|
||||
#define nm_warning(fmt, args...) \
|
||||
G_STMT_START \
|
||||
{ \
|
||||
g_warning ("<WARNING>\t %s (): " fmt "\n", \
|
||||
G_STRFUNC, ##args); \
|
||||
} G_STMT_END
|
||||
|
||||
#define nm_warning_str(fmt_str, args...) \
|
||||
G_STMT_START \
|
||||
{ \
|
||||
g_warning ("<WARNING>\t %s (): %s\n", \
|
||||
G_STRFUNC, fmt_str, ##args); \
|
||||
} G_STMT_END
|
||||
|
||||
#define nm_error(fmt, args...) \
|
||||
G_STMT_START \
|
||||
{ \
|
||||
gdouble _timestamp; \
|
||||
nm_get_timestamp (&_timestamp); \
|
||||
g_critical ("<ERROR>\t[%f] %s (): " fmt "\n", _timestamp, \
|
||||
G_STRFUNC, ##args); \
|
||||
nm_print_backtrace (); \
|
||||
G_BREAKPOINT (); \
|
||||
} G_STMT_END
|
||||
|
||||
#define nm_error_str(fmt_str, args...) \
|
||||
G_STMT_START \
|
||||
{ \
|
||||
gdouble _timestamp; \
|
||||
nm_get_timestamp (&_timestamp); \
|
||||
g_critical ("<ERROR>\t[%f] %s (): %s\n", _timestamp, \
|
||||
G_STRFUNC, fmt_str, ##args); \
|
||||
nm_print_backtrace (); \
|
||||
G_BREAKPOINT (); \
|
||||
} G_STMT_END
|
||||
|
||||
gchar *nm_dbus_escape_object_path (const gchar *utf8_string);
|
||||
gchar *nm_dbus_unescape_object_path (const gchar *object_path);
|
||||
|
||||
#endif /* NM_UTILS_H */
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
/* -*- Mode: C; tab-width: 5; indent-tabs-mode: t; c-basic-offset: 5 -*- */
|
||||
/* nm-vpnc-service - vpnc integration with NetworkManager
|
||||
*
|
||||
* Dan Williams <dcbw@redhat.com>
|
||||
|
|
@ -34,170 +35,136 @@
|
|||
#include "nm-vpnc-service.h"
|
||||
#include "nm-utils.h"
|
||||
|
||||
|
||||
/*
|
||||
* send_config_error
|
||||
*
|
||||
* Notify nm-vpnc-service of a config error from 'vpnc'.
|
||||
*
|
||||
*/
|
||||
static void send_config_error (DBusConnection *con, const char *item)
|
||||
static void
|
||||
helper_failed (DBusGConnection *connection, const char *reason)
|
||||
{
|
||||
DBusMessage *message;
|
||||
DBusGProxy *proxy;
|
||||
GError *err = NULL;
|
||||
|
||||
g_return_if_fail (con != NULL);
|
||||
g_return_if_fail (item != NULL);
|
||||
nm_warning ("nm-nvpnc-service-vpnc-helper did not receive a valid %s from vpnc", reason);
|
||||
|
||||
if (!(message = dbus_message_new_method_call (NM_DBUS_SERVICE_VPNC, NM_DBUS_PATH_VPNC, NM_DBUS_INTERFACE_VPNC, "signalConfigError")))
|
||||
{
|
||||
nm_warning ("send_config_error(): Couldn't allocate the dbus message");
|
||||
return;
|
||||
proxy = dbus_g_proxy_new_for_name (connection,
|
||||
NM_DBUS_SERVICE_VPNC,
|
||||
NM_VPN_DBUS_PLUGIN_PATH,
|
||||
NM_VPN_DBUS_PLUGIN_INTERFACE);
|
||||
|
||||
dbus_g_proxy_call (proxy, "SetFailure", &err,
|
||||
G_TYPE_STRING, reason,
|
||||
G_TYPE_INVALID,
|
||||
G_TYPE_INVALID);
|
||||
|
||||
if (err) {
|
||||
nm_warning ("Could not send failure information: %s", err->message);
|
||||
g_error_free (err);
|
||||
}
|
||||
|
||||
dbus_message_append_args (message, DBUS_TYPE_STRING, &item, DBUS_TYPE_INVALID);
|
||||
if (!dbus_connection_send (con, message, NULL))
|
||||
nm_warning ("send_config_error(): could not send dbus message");
|
||||
g_object_unref (proxy);
|
||||
|
||||
dbus_message_unref (message);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* send_config_info
|
||||
*
|
||||
* Send IP config info to nm-vpnc-service
|
||||
*
|
||||
*/
|
||||
static gboolean send_config_info (DBusConnection *con, const char *str_vpn_gateway,
|
||||
const char *tundev,
|
||||
const char *str_internal_ip4_address,
|
||||
const char *str_internal_ip4_netmask,
|
||||
const char *str_internal_ip4_dns,
|
||||
const char *str_internal_ip4_nbns,
|
||||
const char *cisco_def_domain,
|
||||
const char *cisco_banner)
|
||||
static void
|
||||
send_ip4_config (DBusGConnection *connection, GHashTable *config)
|
||||
{
|
||||
DBusGProxy *proxy;
|
||||
GError *err = NULL;
|
||||
|
||||
proxy = dbus_g_proxy_new_for_name (connection,
|
||||
NM_DBUS_SERVICE_VPNC,
|
||||
NM_VPN_DBUS_PLUGIN_PATH,
|
||||
NM_VPN_DBUS_PLUGIN_INTERFACE);
|
||||
|
||||
dbus_g_proxy_call (proxy, "SetIp4Config", &err,
|
||||
dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE),
|
||||
config,
|
||||
G_TYPE_INVALID,
|
||||
G_TYPE_INVALID);
|
||||
|
||||
if (err) {
|
||||
nm_warning ("Could not send failure information: %s", err->message);
|
||||
g_error_free (err);
|
||||
}
|
||||
|
||||
g_object_unref (proxy);
|
||||
}
|
||||
|
||||
static GValue *
|
||||
str_to_gvalue (const char *str, gboolean try_convert)
|
||||
{
|
||||
GValue *val;
|
||||
|
||||
/* Empty */
|
||||
if (!str || strlen (str) < 1)
|
||||
return NULL;
|
||||
|
||||
if (!g_utf8_validate (str, -1, NULL)) {
|
||||
if (try_convert && !(str = g_convert (str, -1, "ISO-8859-1", "UTF-8", NULL, NULL, NULL)))
|
||||
str = g_convert (str, -1, "C", "UTF-8", NULL, NULL, NULL);
|
||||
|
||||
if (!str)
|
||||
/* Invalid */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
val = g_new (GValue, 1);
|
||||
g_value_init (val, G_TYPE_STRING);
|
||||
g_value_set_string (val, str);
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
static GValue *
|
||||
addr_to_gvalue (const char *str)
|
||||
{
|
||||
DBusMessage * message;
|
||||
struct in_addr temp_addr;
|
||||
guint32 uint_vpn_gateway = 0;
|
||||
guint32 uint_internal_ip4_address = 0;
|
||||
guint32 uint_internal_ip4_netmask = 0xFFFFFFFF; /* Default mask of 255.255.255.255 */
|
||||
guint32 * uint_internal_ip4_dns = NULL;
|
||||
guint32 uint_internal_ip4_dns_len = 0;
|
||||
guint32 * uint_internal_ip4_nbns = NULL;
|
||||
guint32 uint_internal_ip4_nbns_len = 0;
|
||||
char ** split;
|
||||
char ** item;
|
||||
guint32 num_valid = 0, i;
|
||||
gboolean success = FALSE;
|
||||
GValue *val;
|
||||
|
||||
g_return_val_if_fail (con != NULL, FALSE);
|
||||
/* Empty */
|
||||
if (!str || strlen (str) < 1)
|
||||
return NULL;
|
||||
|
||||
if (!(message = dbus_message_new_method_call (NM_DBUS_SERVICE_VPNC, NM_DBUS_PATH_VPNC, NM_DBUS_INTERFACE_VPNC, "signalIP4Config")))
|
||||
{
|
||||
nm_warning ("send_config_error(): Couldn't allocate the dbus message");
|
||||
return FALSE;
|
||||
}
|
||||
if (!inet_aton (str, &temp_addr))
|
||||
return NULL;
|
||||
|
||||
/* Convert IPv4 address arguments from strings into numbers */
|
||||
if (!inet_aton (str_vpn_gateway, &temp_addr))
|
||||
{
|
||||
nm_warning ("nm-vpnc-service-vpnc-helper didn't receive a valid VPN Gateway from vpnc.");
|
||||
send_config_error (con, "VPN Gateway");
|
||||
goto out;
|
||||
}
|
||||
uint_vpn_gateway = temp_addr.s_addr;
|
||||
val = g_new (GValue, 1);
|
||||
g_value_init (val, G_TYPE_UINT);
|
||||
g_value_set_uint (val, temp_addr.s_addr);
|
||||
|
||||
if (!inet_aton (str_internal_ip4_address, &temp_addr))
|
||||
{
|
||||
nm_warning ("nm-vpnc-service-vpnc-helper didn't receive a valid Internal IP4 Address from vpnc.");
|
||||
send_config_error (con, "IP4 Address");
|
||||
goto out;
|
||||
}
|
||||
uint_internal_ip4_address = temp_addr.s_addr;
|
||||
|
||||
if (strlen (str_internal_ip4_netmask) && inet_aton (str_internal_ip4_netmask, &temp_addr))
|
||||
uint_internal_ip4_netmask = temp_addr.s_addr;
|
||||
|
||||
if (strlen (str_internal_ip4_dns))
|
||||
{
|
||||
if ((split = g_strsplit (str_internal_ip4_dns, " ", -1)))
|
||||
{
|
||||
/* Pass over the array first to determine how many valid entries there are */
|
||||
num_valid = 0;
|
||||
for (item = split; *item; item++)
|
||||
if (inet_aton (*item, &temp_addr))
|
||||
num_valid++;
|
||||
|
||||
/* Do the actual string->int conversion and assign to the array. */
|
||||
if (num_valid > 0)
|
||||
{
|
||||
uint_internal_ip4_dns = g_new0 (guint32, num_valid);
|
||||
for (item = split, i = 0; *item; item++, i++)
|
||||
if (inet_aton (*item, &temp_addr))
|
||||
uint_internal_ip4_dns[i] = temp_addr.s_addr;
|
||||
}
|
||||
|
||||
g_strfreev (split);
|
||||
uint_internal_ip4_dns_len = num_valid;
|
||||
}
|
||||
}
|
||||
if (!uint_internal_ip4_dns)
|
||||
{
|
||||
uint_internal_ip4_dns = g_malloc0 (sizeof (guint32));
|
||||
uint_internal_ip4_dns[0] = 0;
|
||||
uint_internal_ip4_dns_len = 1;
|
||||
}
|
||||
|
||||
if (strlen (str_internal_ip4_nbns))
|
||||
{
|
||||
if ((split = g_strsplit (str_internal_ip4_nbns, " ", -1)))
|
||||
{
|
||||
/* Pass over the array first to determine how many valid entries there are */
|
||||
num_valid = 0;
|
||||
for (item = split; *item; item++)
|
||||
if (inet_aton (*item, &temp_addr))
|
||||
num_valid++;
|
||||
|
||||
/* Do the actual string->int conversion and assign to the array. */
|
||||
if (num_valid > 0)
|
||||
{
|
||||
uint_internal_ip4_nbns = g_new0 (guint32, num_valid);
|
||||
for (item = split, i = 0; *item; item++, i++)
|
||||
if (inet_aton (*item, &temp_addr))
|
||||
uint_internal_ip4_nbns[i] = temp_addr.s_addr;
|
||||
}
|
||||
|
||||
g_strfreev (split);
|
||||
uint_internal_ip4_nbns_len = num_valid;
|
||||
}
|
||||
}
|
||||
if (!uint_internal_ip4_nbns)
|
||||
{
|
||||
uint_internal_ip4_nbns = g_malloc0 (sizeof (guint32));
|
||||
uint_internal_ip4_nbns[0] = 0;
|
||||
uint_internal_ip4_nbns_len = 1;
|
||||
}
|
||||
|
||||
dbus_message_append_args (message, DBUS_TYPE_UINT32, &uint_vpn_gateway,
|
||||
DBUS_TYPE_STRING, &tundev,
|
||||
DBUS_TYPE_UINT32, &uint_internal_ip4_address,
|
||||
DBUS_TYPE_UINT32, &uint_internal_ip4_netmask,
|
||||
DBUS_TYPE_ARRAY, DBUS_TYPE_UINT32, &uint_internal_ip4_dns, uint_internal_ip4_dns_len,
|
||||
DBUS_TYPE_ARRAY, DBUS_TYPE_UINT32, &uint_internal_ip4_nbns, uint_internal_ip4_nbns_len,
|
||||
DBUS_TYPE_STRING, &cisco_def_domain,
|
||||
DBUS_TYPE_STRING, &cisco_banner, DBUS_TYPE_INVALID);
|
||||
if (dbus_connection_send (con, message, NULL))
|
||||
success = TRUE;
|
||||
else
|
||||
nm_warning ("send_config_error(): could not send dbus message");
|
||||
|
||||
dbus_message_unref (message);
|
||||
|
||||
out:
|
||||
return success;
|
||||
return val;
|
||||
}
|
||||
|
||||
static GValue *
|
||||
addr_list_to_gvalue (const char *str)
|
||||
{
|
||||
GValue *val;
|
||||
char **split;
|
||||
int i;
|
||||
struct in_addr temp_addr;
|
||||
GSList *list = NULL;
|
||||
|
||||
/* Empty */
|
||||
if (!str || strlen (str) < 1)
|
||||
return NULL;
|
||||
|
||||
split = g_strsplit (str, " ", -1);
|
||||
for (i = 0; split[i]; i++) {
|
||||
if (inet_aton (split[i], &temp_addr))
|
||||
list = g_slist_append (list, GUINT_TO_POINTER (temp_addr.s_addr));
|
||||
else {
|
||||
g_strfreev (split);
|
||||
g_slist_free (list);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
g_strfreev (split);
|
||||
|
||||
val = g_new0 (GValue, 1);
|
||||
g_value_init (val, dbus_g_type_get_collection ("GSList", G_TYPE_UINT));
|
||||
g_value_set_boxed (val, list);
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
/*
|
||||
* Environment variables passed back from 'vpnc':
|
||||
|
|
@ -212,119 +179,80 @@ out:
|
|||
* CISCO_BANNER -- banner from server
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* main
|
||||
*
|
||||
*/
|
||||
int main( int argc, char *argv[] )
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
DBusConnection * con;
|
||||
DBusError error;
|
||||
char * reason = NULL;
|
||||
char * vpn_gateway = NULL;
|
||||
char * tundev = NULL;
|
||||
char * internal_ip4_address = NULL;
|
||||
char * internal_ip4_netmask = NULL;
|
||||
char * internal_ip4_dns = NULL;
|
||||
char * internal_ip4_nbns = NULL;
|
||||
char * cisco_def_domain = NULL;
|
||||
char * cisco_banner = NULL;
|
||||
DBusGConnection *connection;
|
||||
char *tmp;
|
||||
GHashTable *config;
|
||||
GValue *val;
|
||||
GError *err = NULL;
|
||||
|
||||
g_type_init ();
|
||||
if (!g_thread_supported ())
|
||||
g_thread_init (NULL);
|
||||
|
||||
dbus_error_init (&error);
|
||||
con = dbus_bus_get (DBUS_BUS_SYSTEM, &error);
|
||||
if ((con == NULL) || dbus_error_is_set (&error))
|
||||
{
|
||||
nm_warning ("Could not get the system bus. Make sure the message bus daemon is running?");
|
||||
exit (1);
|
||||
}
|
||||
dbus_connection_set_exit_on_disconnect (con, FALSE);
|
||||
|
||||
/* vpnc 0.3.3 gives us a "reason" code. If we are given one,
|
||||
* don't proceed unless its "connect".
|
||||
*/
|
||||
reason = getenv ("reason");
|
||||
if (reason && strcmp (reason, "connect") != 0)
|
||||
tmp = getenv ("reason");
|
||||
if (tmp && strcmp (tmp, "connect") != 0)
|
||||
exit (0);
|
||||
|
||||
vpn_gateway = getenv ("VPNGATEWAY");
|
||||
tundev = getenv ("TUNDEV");
|
||||
internal_ip4_address = getenv ("INTERNAL_IP4_ADDRESS");
|
||||
internal_ip4_netmask = getenv ("INTERNAL_IP4_NETMASK");
|
||||
internal_ip4_dns = getenv ("INTERNAL_IP4_DNS");
|
||||
internal_ip4_nbns = getenv ("INTERNAL_IP4_NBNS");
|
||||
cisco_def_domain = getenv ("CISCO_DEF_DOMAIN");
|
||||
cisco_banner = getenv ("CISCO_BANNER");
|
||||
|
||||
#if 0
|
||||
{
|
||||
FILE *file = fopen ("/tmp/vpnstuff", "w");
|
||||
fprintf (file, "VPNGATEWAY: '%s'\n", vpn_gateway);
|
||||
fprintf (file, "TUNDEF: '%s'\n", tundev);
|
||||
fprintf (file, "INTERNAL_IP4_ADDRESS: '%s'\n", internal_ip4_address);
|
||||
fprintf (file, "INTERNAL_IP4_NETMASK: '%s'\n", internal_ip4_netmask);
|
||||
fprintf (file, "INTERNAL_IP4_DNS: '%s'\n", internal_ip4_dns);
|
||||
fprintf (file, "INTERNAL_IP4_NBNS: '%s'\n", internal_ip4_nbns);
|
||||
fprintf (file, "CISCO_DEF_DOMAIN: '%s'\n", cisco_def_domain);
|
||||
fprintf (file, "CISCO_BANNER: '%s'\n", cisco_banner);
|
||||
fclose (file);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!vpn_gateway)
|
||||
{
|
||||
nm_warning ("nm-vpnc-service-vpnc-helper didn't receive a VPN Gateway from vpnc.");
|
||||
send_config_error (con, "VPN Gateway");
|
||||
exit (1);
|
||||
}
|
||||
if (!tundev || !g_utf8_validate (tundev, -1, NULL))
|
||||
{
|
||||
nm_warning ("nm-vpnc-service-vpnc-helper didn't receive a Tunnel Device from vpnc, or the tunnel device was not valid UTF-8.");
|
||||
send_config_error (con, "Tunnel Device");
|
||||
exit (1);
|
||||
}
|
||||
if (!internal_ip4_address)
|
||||
{
|
||||
nm_warning ("nm-vpnc-service-vpnc-helper didn't receive an Internal IP4 Address from vpnc.");
|
||||
send_config_error (con, "IP4 Address");
|
||||
connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &err);
|
||||
if (!connection) {
|
||||
nm_warning ("Could not get the system bus: %s", err->message);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
if (!internal_ip4_netmask)
|
||||
internal_ip4_netmask = g_strdup ("");
|
||||
if (!internal_ip4_dns)
|
||||
internal_ip4_dns = g_strdup ("");
|
||||
if (!internal_ip4_nbns)
|
||||
internal_ip4_nbns = g_strdup ("");
|
||||
config = g_hash_table_new (g_str_hash, g_str_equal);
|
||||
|
||||
/* Ensure strings from network are UTF-8 */
|
||||
if (cisco_def_domain && !g_utf8_validate (cisco_def_domain, -1, NULL))
|
||||
{
|
||||
if (!(cisco_def_domain = g_convert (cisco_def_domain, -1, "ISO-8859-1", "UTF-8", NULL, NULL, NULL)))
|
||||
cisco_def_domain = g_convert (cisco_def_domain, -1, "C", "UTF-8", NULL, NULL, NULL);
|
||||
}
|
||||
if (!cisco_def_domain)
|
||||
cisco_def_domain = g_strdup ("");
|
||||
/* Gateway */
|
||||
val = addr_to_gvalue (getenv ("VPNGATEWAY"));
|
||||
if (val)
|
||||
g_hash_table_insert (config, NM_VPN_PLUGIN_IP4_CONFIG_GATEWAY, val);
|
||||
else
|
||||
helper_failed (connection, "VPN Gateway");
|
||||
|
||||
if (cisco_banner && !g_utf8_validate (cisco_banner, -1, NULL))
|
||||
{
|
||||
if (!(cisco_banner = g_convert (cisco_banner, -1, "ISO-8859-1", "UTF-8", NULL, NULL, NULL)))
|
||||
cisco_banner = g_convert (cisco_banner, -1, "C", "UTF-8", NULL, NULL, NULL);
|
||||
}
|
||||
if (!cisco_banner)
|
||||
cisco_banner = g_strdup ("");
|
||||
/* Tunnel device */
|
||||
val = str_to_gvalue (getenv ("TUNDEV"), FALSE);
|
||||
if (val)
|
||||
g_hash_table_insert (config, NM_VPN_PLUGIN_IP4_CONFIG_TUNDEV, val);
|
||||
else
|
||||
helper_failed (connection, "Tunnel Device");
|
||||
|
||||
/* IP address */
|
||||
val = addr_to_gvalue (getenv ("INTERNAL_IP4_ADDRESS"));
|
||||
if (val)
|
||||
g_hash_table_insert (config, NM_VPN_PLUGIN_IP4_CONFIG_ADDRESS, val);
|
||||
else
|
||||
helper_failed (connection, "IP4 Address");
|
||||
|
||||
/* Netmask */
|
||||
val = addr_to_gvalue (getenv ("INTERNAL_IP4_NETMASK"));
|
||||
if (val)
|
||||
g_hash_table_insert (config, NM_VPN_PLUGIN_IP4_CONFIG_NETMASK, val);
|
||||
|
||||
/* DNS */
|
||||
val = addr_list_to_gvalue (getenv ("INTERNAL_IP4_DNS"));
|
||||
if (val)
|
||||
g_hash_table_insert (config, NM_VPN_PLUGIN_IP4_CONFIG_DNS, val);
|
||||
|
||||
/* WINS servers */
|
||||
val = addr_list_to_gvalue (getenv ("INTERNAL_IP4_NBNS"));
|
||||
if (val)
|
||||
g_hash_table_insert (config, NM_VPN_PLUGIN_IP4_CONFIG_NBNS, val);
|
||||
|
||||
/* Default domain */
|
||||
val = str_to_gvalue (getenv ("CISCO_DEF_DOMAIN"), TRUE);
|
||||
if (val)
|
||||
g_hash_table_insert (config, NM_VPN_PLUGIN_IP4_CONFIG_DOMAIN, val);
|
||||
|
||||
/* Banner */
|
||||
val = str_to_gvalue (getenv ("CISCO_BANNER"), TRUE);
|
||||
if (val)
|
||||
g_hash_table_insert (config, NM_VPN_PLUGIN_IP4_CONFIG_BANNER, val);
|
||||
|
||||
/* Send the config info to nm-vpnc-service */
|
||||
if (!send_config_info (con, vpn_gateway, tundev, internal_ip4_address, internal_ip4_netmask,
|
||||
internal_ip4_dns, internal_ip4_nbns, cisco_def_domain, cisco_banner))
|
||||
{
|
||||
exit (1);
|
||||
}
|
||||
send_ip4_config (connection, config);
|
||||
|
||||
exit (0);
|
||||
}
|
||||
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -1,29 +1,50 @@
|
|||
/* nm-vpnc-service - vpnc integration with NetworkManager
|
||||
*
|
||||
* Dan Williams <dcbw@redhat.com>
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* (C) Copyright 2005 Red Hat, Inc.
|
||||
*/
|
||||
/* -*- Mode: C; tab-width: 5; indent-tabs-mode: t; c-basic-offset: 5 -*- */
|
||||
|
||||
#ifndef NM_VPNC_SERVICE_H
|
||||
#define NM_VPNC_SERVICE_H
|
||||
#ifndef NM_VPNC_PLUGIN_H
|
||||
#define NM_VPNC_PLUGIN_H
|
||||
|
||||
#define NM_DBUS_SERVICE_VPNC "org.freedesktop.NetworkManager.vpnc"
|
||||
#define NM_DBUS_INTERFACE_VPNC "org.freedesktop.NetworkManager.vpnc"
|
||||
#define NM_DBUS_PATH_VPNC "/org/freedesktop/NetworkManager/vpnc"
|
||||
#include <glib/gtypes.h>
|
||||
#include <glib-object.h>
|
||||
#include <nm-vpn-plugin.h>
|
||||
|
||||
#endif
|
||||
#define NM_TYPE_VPNC_PLUGIN (nm_vpnc_plugin_get_type ())
|
||||
#define NM_VPNC_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_VPNC_PLUGIN, NMVPNCPlugin))
|
||||
#define NM_VPNC_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_VPNC_PLUGIN, NMVPNCPluginClass))
|
||||
#define NM_IS_VPNC_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_VPNC_PLUGIN))
|
||||
#define NM_IS_VPNC_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), NM_TYPE_VPNC_PLUGIN))
|
||||
#define NM_VPNC_PLUGIN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_VPNC_PLUGIN, NMVPNCPluginClass))
|
||||
|
||||
#define NM_DBUS_SERVICE_VPNC "org.freedesktop.NetworkManager.vpnc"
|
||||
#define NM_DBUS_INTERFACE_VPNC "org.freedesktop.NetworkManager.vpnc"
|
||||
#define NM_DBUS_PATH_VPNC "/org/freedesktop/NetworkManager/vpnc"
|
||||
|
||||
#define NM_VPNC_KEY_GATEWAY "IPSec gateway"
|
||||
#define NM_VPNC_KEY_ID "IPSec ID"
|
||||
#define NM_VPNC_KEY_SECRET "IPSec secret"
|
||||
#define NM_VPNC_KEY_XAUTH_USER "Xauth username"
|
||||
#define NM_VPNC_KEY_XAUTH_PASSWORD "Xauth password"
|
||||
#define NM_VPNC_KEY_UDP_ENCAPS "UDP Encapsulate"
|
||||
#define NM_VPNC_KEY_UDP_ENCAPS_PORT "UDP Encapsulation Port"
|
||||
#define NM_VPNC_KEY_DOMAIN "Domain"
|
||||
#define NM_VPNC_KEY_DHGROUP "IKE DH Group"
|
||||
#define NM_VPNC_KEY_PERFECT_FORWARD "Perfect Forward Secrecy"
|
||||
#define NM_VPNC_KEY_APP_VERSION "Application Version"
|
||||
#define NM_VPNC_KEY_REKEYING "Rekeying interval"
|
||||
#define NM_VPNC_KEY_NAT_KEEPALIVE "NAT-Keepalive package interval"
|
||||
#define NM_VPNC_KEY_DISABLE_NAT "Disable NAT Traversal"
|
||||
#define NM_VPNC_KEY_SINGLE_DES "Enable Single DES"
|
||||
|
||||
|
||||
typedef struct {
|
||||
NMVPNPlugin parent;
|
||||
} NMVPNCPlugin;
|
||||
|
||||
typedef struct {
|
||||
NMVPNPluginClass parent;
|
||||
} NMVPNCPluginClass;
|
||||
|
||||
GType nm_vpnc_plugin_get_type (void);
|
||||
|
||||
NMVPNCPlugin *nm_vpnc_plugin_new (void);
|
||||
|
||||
#endif /* NM_VPNC_PLUGIN_H */
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue