[patch 2/3] process dhcp-option DOMAIN
- From: groug free fr
- To: networkmanager-list gnome org
- Subject: [patch 2/3] process dhcp-option DOMAIN
- Date: Fri, 13 Oct 2006 00:00:02 +0200
This patch brings multiple domain support to nm-openvpn. If
--enable-nm-vpn-dbus-dict was passed to configure, domains are extracted
from the 'dhcp-option DOMAIN' varirables pushed by the openvpn server and put
them in an IP4 config message sent to the core nm.
Index: NetworkManager-cvs/vpn-daemons/openvpn/src/nm-openvpn-service-openvpn-helper.c
===================================================================
--- NetworkManager-cvs.orig/vpn-daemons/openvpn/src/nm-openvpn-service-openvpn-helper.c 2006-10-12 22:41:54.000000000 +0200
+++ NetworkManager-cvs/vpn-daemons/openvpn/src/nm-openvpn-service-openvpn-helper.c 2006-10-12 22:42:13.000000000 +0200
@@ -140,7 +140,8 @@ send_config_info (DBusConnection *con,
const char *str_ip4_ptpaddr,
const char *str_ip4_netmask,
const GPtrArray *gpa_ip4_dns,
- const GPtrArray *gpa_ip4_nbns
+ const GPtrArray *gpa_ip4_nbns,
+ const GPtrArray *gpa_ip4_domains
)
{
DBusMessage * message;
@@ -187,6 +188,7 @@ send_config_info (DBusConnection *con,
gpa_to_uint32arr (gpa_ip4_dns, &uint_ip4_dns, &uint_ip4_dns_len);
gpa_to_uint32arr (gpa_ip4_nbns, &uint_ip4_nbns, &uint_ip4_nbns_len);
+ gpa_to_uint32arr (gpa_ip4_nbns, &uint_ip4_nbns, &uint_ip4_nbns_len);
dbus_message_append_args (message, DBUS_TYPE_UINT32, &uint_vpn_gateway,
DBUS_TYPE_STRING, &str_tundev,
@@ -195,6 +197,7 @@ send_config_info (DBusConnection *con,
DBUS_TYPE_UINT32, &uint_ip4_netmask,
DBUS_TYPE_ARRAY, DBUS_TYPE_UINT32, &uint_ip4_dns, uint_ip4_dns_len,
DBUS_TYPE_ARRAY, DBUS_TYPE_UINT32, &uint_ip4_nbns, uint_ip4_nbns_len,
+ DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &gpa_ip4_domains->pdata, gpa_ip4_domains->len,
DBUS_TYPE_INVALID);
if (dbus_connection_send (con, message, NULL))
success = TRUE;
@@ -248,6 +251,7 @@ int main( int argc, char *argv[] )
char *ip4_netmask = NULL;
GPtrArray *ip4_dns = NULL;
GPtrArray *ip4_nbns = NULL;
+ GPtrArray *ip4_domains = NULL;
char **split = NULL;
char **item;
@@ -283,7 +287,8 @@ int main( int argc, char *argv[] )
ip4_dns = g_ptr_array_new();
ip4_nbns = g_ptr_array_new();
-
+ ip4_domains = g_ptr_array_new();
+
while (1) {
sprintf(envname, "foreign_option_%i", i++);
tmp = getenv( envname );
@@ -300,26 +305,38 @@ int main( int argc, char *argv[] )
if ( size != 3 ) continue;
if (strcmp( split[0], "dhcp-option") == 0) {
- // Interesting, now check if DNS or NBNS/WINS
+ // Interesting, now check if DNS or NBNS/WINS or DOMAIN
if (strcmp( split[1], "DNS") == 0) {
// DNS, push it!
g_ptr_array_add( ip4_dns, (gpointer) split[2] );
} else if (strcmp( split[1], "WINS") == 0) {
// WINS, push it!
- g_ptr_array_add( ip4_nbns, (gpointer) split[2] );
+ g_ptr_array_add( ip4_nbns, (gpointer) split[2] );
+ } else if (strcmp( split[1], "DOMAIN") == 0) {
+ // DOMAIN, push it!
+ if (!g_utf8_validate (split[2], -1, NULL)) {
+ nm_warning ("nm-openvpn-service-openvpn-helper received a domain that was not valid UTF-8. Ignored.");
+ continue;
+ }
+ g_ptr_array_add( ip4_domains, (gpointer) split[2] );
}
}
}
- }
+ }
}
#if 0
{
+ int j;
FILE *file = fopen ("/tmp/vpnstuff", "w");
fprintf (file, "VPNGATEWAY: '%s'\n", vpn_gateway);
fprintf (file, "TUNDEV: '%s'\n", tundev);
fprintf (file, "IP4_ADDRESS: '%s'\n", ip4_address);
fprintf (file, "IP4_NETMASK: '%s'\n", ip4_netmask);
+ for (j = 0; j < ip4_domains->len; j++) {
+ fprintf (file, "IP4_DOMAIN: '%s'\n",
+ (char*) ip4_domains->pdata[j]);
+ }
fclose (file);
}
#endif
@@ -346,13 +363,14 @@ int main( int argc, char *argv[] )
if (!send_config_info (con, vpn_gateway, tundev,
ip4_address, ip4_ptp, ip4_netmask,
- ip4_dns, ip4_nbns)) {
+ ip4_dns, ip4_nbns, ip4_domains)) {
exit_code = 1;
}
g_strfreev( split );
g_ptr_array_free( ip4_dns, TRUE );
g_ptr_array_free( ip4_nbns, TRUE );
+ g_ptr_array_free( ip4_domains, TRUE );
exit (exit_code);
}
Index: NetworkManager-cvs/vpn-daemons/openvpn/src/nm-openvpn-service.c
===================================================================
--- NetworkManager-cvs.orig/vpn-daemons/openvpn/src/nm-openvpn-service.c 2006-10-12 22:41:54.000000000 +0200
+++ NetworkManager-cvs/vpn-daemons/openvpn/src/nm-openvpn-service.c 2006-10-12 23:45:39.000000000 +0200
@@ -49,6 +49,9 @@
#include "nm-openvpn-service.h"
#include "nm-utils.h"
+#ifdef NM_VPN_USE_DBUS_DICT_INTERFACE
+#include "dbus-dict-helpers.h"
+#endif
#define NM_OPENVPN_HELPER_PATH BINDIR"/nm-openvpn-service-openvpn-helper"
@@ -1254,6 +1257,8 @@ nm_openvpn_dbus_process_helper_ip4_confi
guint32 ip4_dns_len;
guint32 * ip4_nbns;
guint32 ip4_nbns_len;
+ char ** ip4_domains;
+ guint32 ip4_domains_len;
guint32 mss;
gboolean success = FALSE;
char * empty = "";
@@ -1277,9 +1282,14 @@ nm_openvpn_dbus_process_helper_ip4_confi
DBUS_TYPE_UINT32, &ip4_netmask,
DBUS_TYPE_ARRAY, DBUS_TYPE_UINT32, &ip4_dns, &ip4_dns_len,
DBUS_TYPE_ARRAY, DBUS_TYPE_UINT32, &ip4_nbns, &ip4_nbns_len,
+ DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &ip4_domains, &ip4_domains_len,
DBUS_TYPE_INVALID))
{
DBusMessage *signal;
+#ifdef NM_VPN_USE_DBUS_DICT_INTERFACE
+ DBusMessageIter iter, iter_dict;
+ int i;
+#endif
if (!(signal = dbus_message_new_signal (NM_DBUS_PATH_OPENVPN, NM_DBUS_INTERFACE_OPENVPN, NM_DBUS_VPN_SIGNAL_IP4_CONFIG)))
{
@@ -1287,8 +1297,77 @@ nm_openvpn_dbus_process_helper_ip4_confi
goto out;
}
- /* OpenVPN does not care about the MSS */
- mss = 0;
+#ifdef NM_VPN_USE_DBUS_DICT_INTERFACE
+
+ dbus_message_iter_init_append (signal, &iter);
+ if (!nmu_dbus_dict_open_write (&iter, &iter_dict)) {
+ nm_warning ("dict open write failed!");
+ goto out;
+ }
+
+ if (!nmu_dbus_dict_append_uint32 (&iter_dict, "gateway", ip4_vpn_gateway)) {
+ nm_warning ("couldn't append gateway to dict");
+ goto out;
+ }
+
+ if (!nmu_dbus_dict_append_string (&iter_dict, "tundev", tundev)) {
+ nm_warning ("couldn't append tundev to dict");
+ goto out;
+ }
+
+ if (!nmu_dbus_dict_append_uint32 (&iter_dict, "local_addr", ip4_address)) {
+ nm_warning ("couldn't append local_address to dict");
+ goto out;
+ }
+
+ if (!nmu_dbus_dict_append_uint32 (&iter_dict, "ptp_addr", ip4_ptpaddr)) {
+ nm_warning ("couldn't append ptp_address to dict");
+ goto out;
+ }
+
+ if (!nmu_dbus_dict_append_uint32 (&iter_dict, "local_netmask", ip4_netmask)) {
+ nm_warning ("couldn't append local_netmask to dict");
+ goto out;
+ }
+
+ for (i=0; i < ip4_dns_len; i++) {
+ if (!nmu_dbus_dict_append_uint32 (&iter_dict, "dns_server", ip4_dns[i])) {
+ nm_warning ("couldn't append dns_server (number %d) to dict",i);
+ goto out;
+ }
+ }
+
+ for (i=0; i < ip4_nbns_len; i++) {
+ if (!nmu_dbus_dict_append_uint32 (&iter_dict, "nbns_server", ip4_dns[i])) {
+ nm_warning ("couldn't append nbns_server (number %d) to dict",i);
+ goto out;
+ }
+ }
+
+#if 0
+ {
+ FILE *file = fopen ("/tmp/domains", "w");
+ for (i = 0; i < ip4_domains_len; i++)
+ fprintf (file, "IP4_DOMAIN: '%s'\n", ip4_domains[i]);
+ fclose (file);
+ }
+#endif
+
+ for (i=0; i < ip4_domains_len; i++) {
+ if (!nmu_dbus_dict_append_string (&iter_dict, "dns_domain", ip4_domains[i])) {
+ nm_warning ("couldn't append dns_domain (number %d) to dict",i);
+ goto out;
+ }
+ }
+
+ if (!nmu_dbus_dict_close_write (&iter, &iter_dict)) {
+ nm_warning ("dict close write failed!");
+ goto out;
+ }
+
+#else
+ /* OpenVPN does not care about the MSS */
+ mss = 0;
dbus_message_append_args (signal,
DBUS_TYPE_UINT32, &ip4_vpn_gateway,
@@ -1302,7 +1381,7 @@ nm_openvpn_dbus_process_helper_ip4_confi
DBUS_TYPE_STRING, &empty,
DBUS_TYPE_STRING, &empty,
DBUS_TYPE_INVALID);
-
+#endif
if (!dbus_connection_send (data->con, signal, NULL))
{
nm_warning ("Could not raise the "NM_DBUS_VPN_SIGNAL_IP4_CONFIG" signal!");
Index: NetworkManager-cvs/vpn-daemons/openvpn/configure.in
===================================================================
--- NetworkManager-cvs.orig/vpn-daemons/openvpn/configure.in 2006-10-12 22:41:54.000000000 +0200
+++ NetworkManager-cvs/vpn-daemons/openvpn/configure.in 2006-10-12 22:42:13.000000000 +0200
@@ -78,6 +78,10 @@ PKG_CHECK_MODULES(GNOMEKEYRING, gnome-ke
AC_SUBST(GNOMEKEYRING_CFLAGS)
AC_SUBST(GNOMEKEYRING_LIBS)
+PKG_CHECK_MODULES(LIBNMUTIL, libnm-util)
+AC_SUBST(LIBNMUTIL_CFLAGS)
+AC_SUBST(LIBNMUTIL_LIBS)
+
AS_AC_EXPAND(LOCALSTATEDIR, $localstatedir)
AS_AC_EXPAND(SYSCONFDIR, $sysconfdir)
AS_AC_EXPAND(DATADIR, $datadir)
@@ -86,6 +90,12 @@ AS_AC_EXPAND(SBINDIR, $sbindir)
AS_AC_EXPAND(LIBDIR, $libdir)
AS_AC_EXPAND(LIBEXECDIR, $libexecdir)
+AC_ARG_ENABLE(nm-vpn-dbus-dict, [ --enable-nm-vpn-dbus-dict Build Plugin to use newer DBUS Dict NetworkManager VPN interface [default=no]], enable_nm_vpn_dbus_dict="$enableval", enable_nm_vpn_dbus_dict=no)
+if test "x$enable_nm_vpn_dbus_dict" = "xyes" ; then
+ NM_VPN_CFLAGS="-DNM_VPN_USE_DBUS_DICT_INTERFACE"
+fi
+AC_SUBST(NM_VPN_CFLAGS)
+
AC_ARG_ENABLE(more-warnings,
AC_HELP_STRING([--enable-more-warnings], [Maximum compiler warnings]),
set_more_warnings="$enableval",[
Index: NetworkManager-cvs/vpn-daemons/openvpn/src/Makefile.am
===================================================================
--- NetworkManager-cvs.orig/vpn-daemons/openvpn/src/Makefile.am 2006-10-12 22:41:54.000000000 +0200
+++ NetworkManager-cvs/vpn-daemons/openvpn/src/Makefile.am 2006-10-12 22:42:13.000000000 +0200
@@ -13,7 +13,9 @@ AM_CPPFLAGS = \
-DLIBDIR=\""$(libdir)"\" \
-DLIBEXECDIR=\""$(libexecdir)"\" \
-DLOCALSTATEDIR=\""$(localstatedir)"\" \
- -DDATADIR=\"$(datadir)\"
+ -DDATADIR=\"$(datadir)\" \
+ $(LIBNMUTIL_CFLAGS) \
+ @NM_VPN_CFLAGS@
bin_PROGRAMS = nm-openvpn-service nm-openvpn-service-openvpn-helper
@@ -26,7 +28,8 @@ nm_openvpn_service_SOURCES = \
nm_openvpn_service_LDADD = \
$(DBUS_LIBS) \
- $(GTHREAD_LIBS)
+ $(GTHREAD_LIBS) \
+ $(LIBNMUTIL_LIBS)
nm_openvpn_service_openvpn_helper_SOURCES = \
--
-gr0n6-
"Anarchy is about taking complete responsibility for yourself."
Alan Moore.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]