[patch 3/3] process dhcp-option DOMAIN
- From: groug free fr
- To: networkmanager-list gnome org
- Subject: [patch 3/3] process dhcp-option DOMAIN
- Date: Mon, 28 Aug 2006 00:00:03 +0200
This patch brings multiple domain support to nm-openvpn. It extracts domains
from the 'dhcp-option DOMAIN' varirables pushed by the openvpn server and put
them in the 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-08-28 15:20:52.000000000 +0200
+++ NetworkManager-cvs/vpn-daemons/openvpn/src/nm-openvpn-service-openvpn-helper.c 2006-08-28 15:22:40.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-08-28 15:20:52.000000000 +0200
+++ NetworkManager-cvs/vpn-daemons/openvpn/src/nm-openvpn-service.c 2006-08-28 15:22:40.000000000 +0200
@@ -1254,6 +1254,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,6 +1279,7 @@ 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;
@@ -1287,21 +1290,45 @@ nm_openvpn_dbus_process_helper_ip4_confi
goto out;
}
- /* OpenVPN does not care about the MSS */
- mss = 0;
+ /* OpenVPN does not care about the MSS */
+ mss = 0;
- dbus_message_append_args (signal,
- DBUS_TYPE_UINT32, &ip4_vpn_gateway,
- DBUS_TYPE_STRING, &tundev,
- DBUS_TYPE_UINT32, &ip4_address,
- DBUS_TYPE_UINT32, &ip4_ptpaddr,
- 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_UINT32, &mss,
- DBUS_TYPE_STRING, &empty,
- DBUS_TYPE_STRING, &empty,
- DBUS_TYPE_INVALID);
+#if 0
+ {
+ int i;
+ 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
+
+ if (ip4_domains_len)
+ dbus_message_append_args (signal,
+ DBUS_TYPE_UINT32, &ip4_vpn_gateway,
+ DBUS_TYPE_STRING, &tundev,
+ DBUS_TYPE_UINT32, &ip4_address,
+ DBUS_TYPE_UINT32, &ip4_ptpaddr,
+ 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_UINT32, &mss,
+ DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &ip4_domains, ip4_domains_len,
+ DBUS_TYPE_STRING, &empty,
+ DBUS_TYPE_INVALID);
+ else
+ dbus_message_append_args (signal,
+ DBUS_TYPE_UINT32, &ip4_vpn_gateway,
+ DBUS_TYPE_STRING, &tundev,
+ DBUS_TYPE_UINT32, &ip4_address,
+ DBUS_TYPE_UINT32, &ip4_ptpaddr,
+ 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_UINT32, &mss,
+ DBUS_TYPE_STRING, &empty,
+ DBUS_TYPE_STRING, &empty,
+ DBUS_TYPE_INVALID);
if (!dbus_connection_send (data->con, signal, NULL))
{
--
-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]