diff options
| author | Michael Biebl <biebl@debian.org> | 2010-11-29 19:00:22 +0100 |
|---|---|---|
| committer | Michael Biebl <biebl@debian.org> | 2010-11-29 19:00:22 +0100 |
| commit | a6b89d35fabd9f5934b84d7cde22e9268f92c3d3 (patch) | |
| tree | 9e44755880d5933fcc90c6008d4585a76298a1bd /src/vpn-manager | |
| parent | 9fae01fa351805b2903e535736e06971bc0b925e (diff) | |
Imported Upstream version 0.8.2 upstream/0.8.2
Diffstat (limited to 'src/vpn-manager')
| -rw-r--r-- | src/vpn-manager/Makefile.am | 6 | ||||
| -rw-r--r-- | src/vpn-manager/Makefile.in | 73 | ||||
| -rw-r--r-- | src/vpn-manager/nm-vpn-connection.c | 59 | ||||
| -rw-r--r-- | src/vpn-manager/nm-vpn-manager.c | 342 | ||||
| -rw-r--r-- | src/vpn-manager/nm-vpn-manager.h | 3 | ||||
| -rw-r--r-- | src/vpn-manager/nm-vpn-service.c | 308 | ||||
| -rw-r--r-- | src/vpn-manager/nm-vpn-service.h | 14 |
7 files changed, 503 insertions, 302 deletions
diff --git a/src/vpn-manager/Makefile.am b/src/vpn-manager/Makefile.am index 56e4a4ce..b0692d70 100644 --- a/src/vpn-manager/Makefile.am +++ b/src/vpn-manager/Makefile.am @@ -5,7 +5,7 @@ INCLUDES = \ -I${top_srcdir}/src/logging \ -I${top_srcdir}/src \ -I${top_builddir}/marshallers \ - -I${top_srcdir}/src/named-manager \ + -I${top_srcdir}/src/dns-manager \ -DVPN_NAME_FILES_DIR=\""$(sysconfdir)/NetworkManager/VPN"\" @@ -32,10 +32,10 @@ libvpn_manager_la_LIBADD = \ $(GLIB_LIBS) nm-vpn-connection-glue.h: $(top_srcdir)/introspection/nm-vpn-connection.xml - dbus-binding-tool --prefix=nm_vpn_connection --mode=glib-server --output=$@ $< + $(AM_V_GEN) dbus-binding-tool --prefix=nm_vpn_connection --mode=glib-server --output=$@ $< nm-vpn-plugin-bindings.h: $(top_srcdir)/introspection/nm-vpn-plugin.xml - dbus-binding-tool --prefix=nm_vpn_plugin --mode=glib-client --output=$@ $< + $(AM_V_GEN) dbus-binding-tool --prefix=nm_vpn_plugin --mode=glib-client --output=$@ $< BUILT_SOURCES = \ diff --git a/src/vpn-manager/Makefile.in b/src/vpn-manager/Makefile.in index dc1ba727..e0a4f4ed 100644 --- a/src/vpn-manager/Makefile.in +++ b/src/vpn-manager/Makefile.in @@ -60,19 +60,35 @@ am_libvpn_manager_la_OBJECTS = libvpn_manager_la-nm-vpn-manager.lo \ libvpn_manager_la-nm-vpn-service.lo \ libvpn_manager_la-nm-vpn-connection.lo libvpn_manager_la_OBJECTS = $(am_libvpn_manager_la_OBJECTS) +AM_V_lt = $(am__v_lt_$(V)) +am__v_lt_ = $(am__v_lt_$(AM_DEFAULT_VERBOSITY)) +am__v_lt_0 = --silent DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) depcomp = $(SHELL) $(top_srcdir)/depcomp am__depfiles_maybe = depfiles am__mv = mv -f COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ - --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ - $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \ + $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ + $(AM_CFLAGS) $(CFLAGS) +AM_V_CC = $(am__v_CC_$(V)) +am__v_CC_ = $(am__v_CC_$(AM_DEFAULT_VERBOSITY)) +am__v_CC_0 = @echo " CC " $@; +AM_V_at = $(am__v_at_$(V)) +am__v_at_ = $(am__v_at_$(AM_DEFAULT_VERBOSITY)) +am__v_at_0 = @ CCLD = $(CC) -LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ - --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \ - $(LDFLAGS) -o $@ +LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ + $(AM_LDFLAGS) $(LDFLAGS) -o $@ +AM_V_CCLD = $(am__v_CCLD_$(V)) +am__v_CCLD_ = $(am__v_CCLD_$(AM_DEFAULT_VERBOSITY)) +am__v_CCLD_0 = @echo " CCLD " $@; +AM_V_GEN = $(am__v_GEN_$(V)) +am__v_GEN_ = $(am__v_GEN_$(AM_DEFAULT_VERBOSITY)) +am__v_GEN_0 = @echo " GEN " $@; SOURCES = $(libvpn_manager_la_SOURCES) DIST_SOURCES = $(libvpn_manager_la_SOURCES) ETAGS = etags @@ -82,6 +98,7 @@ ACLOCAL = @ACLOCAL@ ACLOCAL_AMFLAGS = @ACLOCAL_AMFLAGS@ ALL_LINGUAS = @ALL_LINGUAS@ AMTAR = @AMTAR@ +AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ AR = @AR@ AUTOCONF = @AUTOCONF@ AUTOHEADER = @AUTOHEADER@ @@ -102,6 +119,7 @@ DBUS_SYS_DIR = @DBUS_SYS_DIR@ DEFS = @DEFS@ DEPDIR = @DEPDIR@ DHCLIENT_PATH = @DHCLIENT_PATH@ +DHCLIENT_VERSION = @DHCLIENT_VERSION@ DHCPCD_PATH = @DHCPCD_PATH@ DISABLE_DEPRECATED = @DISABLE_DEPRECATED@ DSYMUTIL = @DSYMUTIL@ @@ -143,6 +161,7 @@ INTLTOOL_MERGE = @INTLTOOL_MERGE@ INTLTOOL_PERL = @INTLTOOL_PERL@ INTLTOOL_UPDATE = @INTLTOOL_UPDATE@ IPTABLES_PATH = @IPTABLES_PATH@ +KERNEL_FIRMWARE_DIR = @KERNEL_FIRMWARE_DIR@ LD = @LD@ LDFLAGS = @LDFLAGS@ LIBDL = @LIBDL@ @@ -182,6 +201,8 @@ PACKAGE_URL = @PACKAGE_URL@ PACKAGE_VERSION = @PACKAGE_VERSION@ PATH_SEPARATOR = @PATH_SEPARATOR@ PKG_CONFIG = @PKG_CONFIG@ +PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ +PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ POFILES = @POFILES@ POLKIT_CFLAGS = @POLKIT_CFLAGS@ POLKIT_LIBS = @POLKIT_LIBS@ @@ -238,7 +259,6 @@ libdir = @libdir@ libexecdir = @libexecdir@ localedir = @localedir@ localstatedir = @localstatedir@ -lt_ECHO = @lt_ECHO@ mandir = @mandir@ mkdir_p = @mkdir_p@ oldincludedir = @oldincludedir@ @@ -250,6 +270,7 @@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ sysconfdir = @sysconfdir@ +systemdsystemunitdir = @systemdsystemunitdir@ target_alias = @target_alias@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ @@ -261,7 +282,7 @@ INCLUDES = \ -I${top_srcdir}/src/logging \ -I${top_srcdir}/src \ -I${top_builddir}/marshallers \ - -I${top_srcdir}/src/named-manager \ + -I${top_srcdir}/src/dns-manager \ -DVPN_NAME_FILES_DIR=\""$(sysconfdir)/NetworkManager/VPN"\" noinst_LTLIBRARIES = libvpn-manager.la @@ -335,7 +356,7 @@ clean-noinstLTLIBRARIES: rm -f "$${dir}/so_locations"; \ done libvpn-manager.la: $(libvpn_manager_la_OBJECTS) $(libvpn_manager_la_DEPENDENCIES) - $(LINK) $(libvpn_manager_la_OBJECTS) $(libvpn_manager_la_LIBADD) $(LIBS) + $(AM_V_CCLD)$(LINK) $(libvpn_manager_la_OBJECTS) $(libvpn_manager_la_LIBADD) $(LIBS) mostlyclean-compile: -rm -f *.$(OBJEXT) @@ -348,49 +369,55 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libvpn_manager_la-nm-vpn-service.Plo@am__quote@ .c.o: -@am__fastdepCC_TRUE@ depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\ +@am__fastdepCC_TRUE@ $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\ @am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\ @am__fastdepCC_TRUE@ $(am__mv) $$depbase.Tpo $$depbase.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(COMPILE) -c -o $@ $< .c.obj: -@am__fastdepCC_TRUE@ depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.obj$$||'`;\ +@am__fastdepCC_TRUE@ $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.obj$$||'`;\ @am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ `$(CYGPATH_W) '$<'` &&\ @am__fastdepCC_TRUE@ $(am__mv) $$depbase.Tpo $$depbase.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'` .c.lo: -@am__fastdepCC_TRUE@ depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.lo$$||'`;\ +@am__fastdepCC_TRUE@ $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.lo$$||'`;\ @am__fastdepCC_TRUE@ $(LTCOMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\ @am__fastdepCC_TRUE@ $(am__mv) $$depbase.Tpo $$depbase.Plo +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $< libvpn_manager_la-nm-vpn-manager.lo: nm-vpn-manager.c -@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libvpn_manager_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libvpn_manager_la-nm-vpn-manager.lo -MD -MP -MF $(DEPDIR)/libvpn_manager_la-nm-vpn-manager.Tpo -c -o libvpn_manager_la-nm-vpn-manager.lo `test -f 'nm-vpn-manager.c' || echo '$(srcdir)/'`nm-vpn-manager.c -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libvpn_manager_la-nm-vpn-manager.Tpo $(DEPDIR)/libvpn_manager_la-nm-vpn-manager.Plo +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libvpn_manager_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libvpn_manager_la-nm-vpn-manager.lo -MD -MP -MF $(DEPDIR)/libvpn_manager_la-nm-vpn-manager.Tpo -c -o libvpn_manager_la-nm-vpn-manager.lo `test -f 'nm-vpn-manager.c' || echo '$(srcdir)/'`nm-vpn-manager.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libvpn_manager_la-nm-vpn-manager.Tpo $(DEPDIR)/libvpn_manager_la-nm-vpn-manager.Plo +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='nm-vpn-manager.c' object='libvpn_manager_la-nm-vpn-manager.lo' libtool=yes @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libvpn_manager_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libvpn_manager_la-nm-vpn-manager.lo `test -f 'nm-vpn-manager.c' || echo '$(srcdir)/'`nm-vpn-manager.c +@am__fastdepCC_FALSE@ $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libvpn_manager_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libvpn_manager_la-nm-vpn-manager.lo `test -f 'nm-vpn-manager.c' || echo '$(srcdir)/'`nm-vpn-manager.c libvpn_manager_la-nm-vpn-service.lo: nm-vpn-service.c -@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libvpn_manager_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libvpn_manager_la-nm-vpn-service.lo -MD -MP -MF $(DEPDIR)/libvpn_manager_la-nm-vpn-service.Tpo -c -o libvpn_manager_la-nm-vpn-service.lo `test -f 'nm-vpn-service.c' || echo '$(srcdir)/'`nm-vpn-service.c -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libvpn_manager_la-nm-vpn-service.Tpo $(DEPDIR)/libvpn_manager_la-nm-vpn-service.Plo +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libvpn_manager_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libvpn_manager_la-nm-vpn-service.lo -MD -MP -MF $(DEPDIR)/libvpn_manager_la-nm-vpn-service.Tpo -c -o libvpn_manager_la-nm-vpn-service.lo `test -f 'nm-vpn-service.c' || echo '$(srcdir)/'`nm-vpn-service.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libvpn_manager_la-nm-vpn-service.Tpo $(DEPDIR)/libvpn_manager_la-nm-vpn-service.Plo +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='nm-vpn-service.c' object='libvpn_manager_la-nm-vpn-service.lo' libtool=yes @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libvpn_manager_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libvpn_manager_la-nm-vpn-service.lo `test -f 'nm-vpn-service.c' || echo '$(srcdir)/'`nm-vpn-service.c +@am__fastdepCC_FALSE@ $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libvpn_manager_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libvpn_manager_la-nm-vpn-service.lo `test -f 'nm-vpn-service.c' || echo '$(srcdir)/'`nm-vpn-service.c libvpn_manager_la-nm-vpn-connection.lo: nm-vpn-connection.c -@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libvpn_manager_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libvpn_manager_la-nm-vpn-connection.lo -MD -MP -MF $(DEPDIR)/libvpn_manager_la-nm-vpn-connection.Tpo -c -o libvpn_manager_la-nm-vpn-connection.lo `test -f 'nm-vpn-connection.c' || echo '$(srcdir)/'`nm-vpn-connection.c -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libvpn_manager_la-nm-vpn-connection.Tpo $(DEPDIR)/libvpn_manager_la-nm-vpn-connection.Plo +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libvpn_manager_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libvpn_manager_la-nm-vpn-connection.lo -MD -MP -MF $(DEPDIR)/libvpn_manager_la-nm-vpn-connection.Tpo -c -o libvpn_manager_la-nm-vpn-connection.lo `test -f 'nm-vpn-connection.c' || echo '$(srcdir)/'`nm-vpn-connection.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libvpn_manager_la-nm-vpn-connection.Tpo $(DEPDIR)/libvpn_manager_la-nm-vpn-connection.Plo +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='nm-vpn-connection.c' object='libvpn_manager_la-nm-vpn-connection.lo' libtool=yes @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libvpn_manager_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libvpn_manager_la-nm-vpn-connection.lo `test -f 'nm-vpn-connection.c' || echo '$(srcdir)/'`nm-vpn-connection.c +@am__fastdepCC_FALSE@ $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libvpn_manager_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libvpn_manager_la-nm-vpn-connection.lo `test -f 'nm-vpn-connection.c' || echo '$(srcdir)/'`nm-vpn-connection.c mostlyclean-libtool: -rm -f *.lo @@ -601,10 +628,10 @@ uninstall-am: nm-vpn-connection-glue.h: $(top_srcdir)/introspection/nm-vpn-connection.xml - dbus-binding-tool --prefix=nm_vpn_connection --mode=glib-server --output=$@ $< + $(AM_V_GEN) dbus-binding-tool --prefix=nm_vpn_connection --mode=glib-server --output=$@ $< nm-vpn-plugin-bindings.h: $(top_srcdir)/introspection/nm-vpn-plugin.xml - dbus-binding-tool --prefix=nm_vpn_plugin --mode=glib-client --output=$@ $< + $(AM_V_GEN) dbus-binding-tool --prefix=nm_vpn_plugin --mode=glib-client --output=$@ $< # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. diff --git a/src/vpn-manager/nm-vpn-connection.c b/src/vpn-manager/nm-vpn-connection.c index 7eae972e..cf844992 100644 --- a/src/vpn-manager/nm-vpn-connection.c +++ b/src/vpn-manager/nm-vpn-connection.c @@ -44,7 +44,7 @@ #include "nm-properties-changed-signal.h" #include "nm-dbus-glib-types.h" #include "NetworkManagerUtils.h" -#include "nm-named-manager.h" +#include "nm-dns-manager.h" #include "nm-netlink-monitor.h" #include "nm-glib-compat.h" @@ -78,7 +78,7 @@ typedef struct { guint ipconfig_timeout; NMIP4Config *ip4_config; guint32 ip4_internal_gw; - char *tundev; + char *ip_iface; char *banner; struct rtnl_route *gw_route; @@ -134,7 +134,7 @@ nm_vpn_connection_set_vpn_state (NMVPNConnection *connection, /* Save ip_iface since when the VPN goes down it may get freed * before we're done with it. */ - ip_iface = g_strdup (priv->tundev); + ip_iface = g_strdup (priv->ip_iface); /* Set the NMActiveConnection state based on VPN state */ switch (vpn_state) { @@ -350,7 +350,7 @@ ip_address_to_string (guint32 numeric) static void print_vpn_config (NMIP4Config *config, guint32 internal_gw, - const char *tundev, + const char *ip_iface, const char *banner) { NMIP4Address *addr; @@ -364,7 +364,7 @@ print_vpn_config (NMIP4Config *config, nm_log_info (LOGD_VPN, "VPN Gateway: %s", ip_address_to_string (nm_ip4_address_get_gateway (addr))); if (internal_gw) nm_log_info (LOGD_VPN, "Internal Gateway: %s", ip_address_to_string (internal_gw)); - nm_log_info (LOGD_VPN, "Tunnel Device: %s", tundev); + nm_log_info (LOGD_VPN, "Tunnel Device: %s", ip_iface); nm_log_info (LOGD_VPN, "Internal IP4 Address: %s", ip_address_to_string (nm_ip4_address_get_address (addr))); nm_log_info (LOGD_VPN, "Internal IP4 Prefix: %d", nm_ip4_address_get_prefix (addr)); nm_log_info (LOGD_VPN, "Internal IP4 Point-to-Point Address: %s", @@ -382,6 +382,9 @@ print_vpn_config (NMIP4Config *config, ip_address_to_string (nm_ip4_route_get_next_hop (route))); } + nm_log_info (LOGD_VPN, "Forbid Default Route: %s", + nm_ip4_config_get_never_default (config) ? "yes" : "no"); + num = nm_ip4_config_get_num_nameservers (config); for (i = 0; i < num; i++) { nm_log_info (LOGD_VPN, "Internal IP4 DNS: %s", @@ -425,7 +428,7 @@ nm_vpn_connection_ip4_config_get (DBusGProxy *proxy, val = (GValue *) g_hash_table_lookup (config_hash, NM_VPN_PLUGIN_IP4_CONFIG_TUNDEV); if (val) - priv->tundev = g_strdup (g_value_get_string (val)); + priv->ip_iface = g_strdup (g_value_get_string (val)); else { nm_log_err (LOGD_VPN, "invalid or missing tunnel device received!"); goto error; @@ -527,24 +530,28 @@ nm_vpn_connection_ip4_config_get (DBusGProxy *proxy, g_slist_free (routes); } - print_vpn_config (config, priv->ip4_internal_gw, priv->tundev, priv->banner); + val = (GValue *) g_hash_table_lookup (config_hash, NM_VPN_PLUGIN_IP4_CONFIG_NEVER_DEFAULT); + if (val && G_VALUE_HOLDS_BOOLEAN (val)) + nm_ip4_config_set_never_default (config, g_value_get_boolean (val)); + + print_vpn_config (config, priv->ip4_internal_gw, priv->ip_iface, priv->banner); /* Merge in user overrides from the NMConnection's IPv4 setting */ s_ip4 = NM_SETTING_IP4_CONFIG (nm_connection_get_setting (priv->connection, NM_TYPE_SETTING_IP4_CONFIG)); nm_utils_merge_ip4_config (config, s_ip4); - nm_system_device_set_up_down_with_iface (priv->tundev, TRUE, NULL); + nm_system_device_set_up_down_with_iface (priv->ip_iface, TRUE, NULL); - if (nm_system_apply_ip4_config (priv->tundev, config, 0, NM_IP4_COMPARE_FLAG_ALL)) { - NMNamedManager *named_mgr; + if (nm_system_apply_ip4_config (priv->ip_iface, config, 0, NM_IP4_COMPARE_FLAG_ALL)) { + NMDnsManager *dns_mgr; /* Add any explicit route to the VPN gateway through the parent device */ priv->gw_route = nm_system_add_ip4_vpn_gateway_route (priv->parent_dev, config); /* Add the VPN to DNS */ - named_mgr = nm_named_manager_get (); - nm_named_manager_add_ip4_config (named_mgr, priv->tundev, config, NM_NAMED_IP_CONFIG_TYPE_VPN); - g_object_unref (named_mgr); + dns_mgr = nm_dns_manager_get (NULL); + nm_dns_manager_add_ip4_config (dns_mgr, priv->ip_iface, config, NM_DNS_IP_CONFIG_TYPE_VPN); + g_object_unref (dns_mgr); priv->ip4_config = config; @@ -735,7 +742,7 @@ nm_vpn_connection_get_ip_iface (NMVPNConnection *connection) { g_return_val_if_fail (NM_IS_VPN_CONNECTION (connection), NULL); - return NM_VPN_CONNECTION_GET_PRIVATE (connection)->tundev; + return NM_VPN_CONNECTION_GET_PRIVATE (connection)->ip_iface; } NMDevice * @@ -883,21 +890,21 @@ vpn_cleanup (NMVPNConnection *connection) { NMVPNConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (connection); - if (priv->tundev) { - nm_system_device_set_up_down_with_iface (priv->tundev, FALSE, NULL); + if (priv->ip_iface) { + nm_system_device_set_up_down_with_iface (priv->ip_iface, FALSE, NULL); /* FIXME: use AF_UNSPEC here when we have IPv6 support */ - nm_system_device_flush_routes_with_iface (priv->tundev, AF_INET); - nm_system_device_flush_addresses_with_iface (priv->tundev); + nm_system_device_flush_routes_with_iface (priv->ip_iface, AF_INET); + nm_system_device_flush_addresses_with_iface (priv->ip_iface); } if (priv->ip4_config) { NMIP4Config *parent_config; - NMNamedManager *named_mgr; + NMDnsManager *dns_mgr; /* Remove attributes of the VPN's IP4 Config */ - named_mgr = nm_named_manager_get (); - nm_named_manager_remove_ip4_config (named_mgr, priv->tundev, priv->ip4_config); - g_object_unref (named_mgr); + dns_mgr = nm_dns_manager_get (NULL); + nm_dns_manager_remove_ip4_config (dns_mgr, priv->ip_iface, priv->ip4_config); + g_object_unref (dns_mgr); /* Remove any previously added VPN gateway host route */ if (priv->gw_route) @@ -925,9 +932,9 @@ vpn_cleanup (NMVPNConnection *connection) priv->banner = NULL; } - if (priv->tundev) { - g_free (priv->tundev); - priv->tundev = NULL; + if (priv->ip_iface) { + g_free (priv->ip_iface); + priv->ip_iface = NULL; } /* Clear out connection secrets to ensure that the settings service @@ -1031,7 +1038,7 @@ finalize (GObject *object) NMVPNConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (object); g_free (priv->banner); - g_free (priv->tundev); + g_free (priv->ip_iface); g_free (priv->ac_path); G_OBJECT_CLASS (nm_vpn_connection_parent_class)->finalize (object); diff --git a/src/vpn-manager/nm-vpn-manager.c b/src/vpn-manager/nm-vpn-manager.c index 221a8b54..4b58be0d 100644 --- a/src/vpn-manager/nm-vpn-manager.c +++ b/src/vpn-manager/nm-vpn-manager.c @@ -15,11 +15,12 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright (C) 2005 - 2008 Red Hat, Inc. + * Copyright (C) 2005 - 2010 Red Hat, Inc. * Copyright (C) 2006 - 2008 Novell, Inc. */ #include <string.h> +#include <gio/gio.h> #include "nm-vpn-manager.h" #include "nm-vpn-service.h" @@ -28,13 +29,18 @@ #include "nm-dbus-manager.h" #include "NetworkManagerVPN.h" #include "nm-marshal.h" +#include "nm-logging.h" G_DEFINE_TYPE (NMVPNManager, nm_vpn_manager, G_TYPE_OBJECT) #define NM_VPN_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_VPN_MANAGER, NMVPNManagerPrivate)) typedef struct { - GSList *services; + gboolean disposed; + + GHashTable *services; + GFileMonitor *monitor; + guint monitor_id; } NMVPNManagerPrivate; enum { @@ -81,53 +87,42 @@ nm_vpn_manager_error_get_type (void) } - static NMVPNService * -nm_vpn_manager_get_service (NMVPNManager *manager, const char *service_name) +get_service_by_namefile (NMVPNManager *self, const char *namefile) { - GSList *iter; + NMVPNManagerPrivate *priv = NM_VPN_MANAGER_GET_PRIVATE (self); + GHashTableIter iter; + gpointer data; - for (iter = NM_VPN_MANAGER_GET_PRIVATE (manager)->services; iter; iter = iter->next) { - NMVPNService *service = NM_VPN_SERVICE (iter->data); + g_return_val_if_fail (namefile, NULL); + g_return_val_if_fail (g_path_is_absolute (namefile), NULL); - if (!strcmp (service_name, nm_vpn_service_get_name (service))) - return g_object_ref (service); - } + g_hash_table_iter_init (&iter, priv->services); + while (g_hash_table_iter_next (&iter, NULL, &data)) { + NMVPNService *candidate = NM_VPN_SERVICE (data); + const char *service_namefile; + service_namefile = nm_vpn_service_get_name_file (candidate); + if (!strcmp (namefile, service_namefile)) + return candidate; + } return NULL; } -static void -remove_service (gpointer data, GObject *service) -{ - NMVPNManagerPrivate *priv = NM_VPN_MANAGER_GET_PRIVATE (data); - - priv->services = g_slist_remove (priv->services, service); -} - -static void -nm_vpn_manager_add_service (NMVPNManager *manager, NMVPNService *service) -{ - NMVPNManagerPrivate *priv = NM_VPN_MANAGER_GET_PRIVATE (manager); - - priv->services = g_slist_prepend (priv->services, service); - g_object_weak_ref (G_OBJECT (service), remove_service, manager); -} - static NMVPNConnection * -find_active_vpn_connection_by_connection (NMVPNManager *manager, NMConnection *connection) +find_active_vpn_connection_by_connection (NMVPNManager *self, NMConnection *connection) { - NMVPNManagerPrivate *priv; - GSList *iter; + NMVPNManagerPrivate *priv = NM_VPN_MANAGER_GET_PRIVATE (self); + GHashTableIter iter; + gpointer data; + GSList *connections, *elt; - g_return_val_if_fail (NM_IS_VPN_MANAGER (manager), NULL); + g_return_val_if_fail (connection, NULL); g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL); - priv = NM_VPN_MANAGER_GET_PRIVATE (manager); - for (iter = priv->services; iter; iter = g_slist_next (iter)) { - GSList *connections, *elt; - - connections = nm_vpn_service_get_active_connections (NM_VPN_SERVICE (iter->data)); + g_hash_table_iter_init (&iter, priv->services); + while (g_hash_table_iter_next (&iter, NULL, &data)) { + connections = nm_vpn_service_get_active_connections (NM_VPN_SERVICE (data)); for (elt = connections; elt; elt = g_slist_next (elt)) { NMVPNConnection *vpn = NM_VPN_CONNECTION (elt->data); @@ -169,7 +164,7 @@ nm_vpn_manager_activate_connection (NMVPNManager *manager, NMSettingVPN *vpn_setting; NMVPNService *service; NMVPNConnection *vpn = NULL; - const char *service_type; + const char *service_name; g_return_val_if_fail (NM_IS_VPN_MANAGER (manager), NULL); g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL); @@ -199,78 +194,78 @@ nm_vpn_manager_activate_connection (NMVPNManager *manager, vpn = NULL; } - service_type = nm_setting_vpn_get_service_type (vpn_setting); - service = nm_vpn_manager_get_service (manager, service_type); + service_name = nm_setting_vpn_get_service_type (vpn_setting); + g_assert (service_name); + service = g_hash_table_lookup (NM_VPN_MANAGER_GET_PRIVATE (manager)->services, service_name); if (!service) { - service = nm_vpn_service_new (service_type); - if (service) - nm_vpn_manager_add_service (manager, service); - } - - if (service) { - vpn = nm_vpn_service_activate (service, connection, act_request, device, error); - if (vpn) { - g_signal_connect (vpn, "vpn-state-changed", - G_CALLBACK (connection_vpn_state_changed), - manager); - } - } else { g_set_error (error, NM_VPN_MANAGER_ERROR, NM_VPN_MANAGER_ERROR_SERVICE_INVALID, - "%s", "The VPN service was invalid."); + "The VPN service '%s' was not installed.", + service_name); + return NULL; + } + + vpn = nm_vpn_service_activate (service, connection, act_request, device, error); + if (vpn) { + g_signal_connect (vpn, "vpn-state-changed", + G_CALLBACK (connection_vpn_state_changed), + manager); } return vpn; } gboolean -nm_vpn_manager_deactivate_connection (NMVPNManager *manager, +nm_vpn_manager_deactivate_connection (NMVPNManager *self, const char *path, NMVPNConnectionStateReason reason) { NMVPNManagerPrivate *priv; - GSList *iter; - gboolean found = FALSE; + GHashTableIter iter; + gpointer data; + GSList *active, *elt; - g_return_val_if_fail (NM_IS_VPN_MANAGER (manager), FALSE); + g_return_val_if_fail (self, FALSE); + g_return_val_if_fail (NM_IS_VPN_MANAGER (self), FALSE); g_return_val_if_fail (path != NULL, FALSE); - priv = NM_VPN_MANAGER_GET_PRIVATE (manager); - for (iter = priv->services; iter; iter = g_slist_next (iter)) { - GSList *connections, *elt; - - connections = nm_vpn_service_get_active_connections (NM_VPN_SERVICE (iter->data)); - for (elt = connections; elt; elt = g_slist_next (elt)) { + priv = NM_VPN_MANAGER_GET_PRIVATE (self); + g_hash_table_iter_init (&iter, priv->services); + while (g_hash_table_iter_next (&iter, NULL, &data)) { + active = nm_vpn_service_get_active_connections (NM_VPN_SERVICE (data)); + for (elt = active; elt; elt = g_slist_next (elt)) { NMVPNConnection *vpn = NM_VPN_CONNECTION (elt->data); const char *vpn_path; vpn_path = nm_vpn_connection_get_active_connection_path (vpn); if (!strcmp (path, vpn_path)) { nm_vpn_connection_disconnect (vpn, reason); - found = TRUE; + return TRUE; } } } - return found ? TRUE : FALSE; + return FALSE; } void -nm_vpn_manager_add_active_connections (NMVPNManager *manager, +nm_vpn_manager_add_active_connections (NMVPNManager *self, NMConnection *filter, GPtrArray *array) { NMVPNManagerPrivate *priv; - GSList *iter; + GHashTableIter iter; + gpointer data; + GSList *active, *elt; - g_return_if_fail (NM_IS_VPN_MANAGER (manager)); + g_return_if_fail (self); + g_return_if_fail (NM_IS_VPN_MANAGER (self)); g_return_if_fail (array != NULL); - priv = NM_VPN_MANAGER_GET_PRIVATE (manager); - for (iter = priv->services; iter; iter = g_slist_next (iter)) { - GSList *active, *elt; - - active = nm_vpn_service_get_active_connections (NM_VPN_SERVICE (iter->data)); + priv = NM_VPN_MANAGER_GET_PRIVATE (self); + g_hash_table_iter_init (&iter, priv->services); + while (g_hash_table_iter_next (&iter, NULL, &data)) { + active = nm_vpn_service_get_active_connections (NM_VPN_SERVICE (data)); for (elt = active; elt; elt = g_slist_next (elt)) { NMVPNConnection *vpn = NM_VPN_CONNECTION (elt->data); const char *path; @@ -284,26 +279,155 @@ nm_vpn_manager_add_active_connections (NMVPNManager *manager, } GSList * -nm_vpn_manager_get_active_connections (NMVPNManager *manager) +nm_vpn_manager_get_active_connections (NMVPNManager *self) { NMVPNManagerPrivate *priv; - GSList *iter; - GSList *list = NULL; + GHashTableIter iter; + gpointer data; + GSList *list = NULL, *active, *elt; + + g_return_val_if_fail (self, NULL); + g_return_val_if_fail (NM_IS_VPN_MANAGER (self), NULL); + + priv = NM_VPN_MANAGER_GET_PRIVATE (self); + g_hash_table_iter_init (&iter, priv->services); + while (g_hash_table_iter_next (&iter, NULL, &data)) { + active = nm_vpn_service_get_active_connections (NM_VPN_SERVICE (data)); + for (elt = active; elt; elt = g_slist_next (elt)) + list = g_slist_append (list, g_object_ref (G_OBJECT (elt->data))); + } + return list; +} + +NMConnection * +nm_vpn_manager_get_connection_for_active (NMVPNManager *manager, + const char *active_path) +{ + NMVPNManagerPrivate *priv; + GHashTableIter iter; + gpointer data; + GSList *active, *elt; g_return_val_if_fail (NM_IS_VPN_MANAGER (manager), NULL); priv = NM_VPN_MANAGER_GET_PRIVATE (manager); - for (iter = priv->services; iter; iter = g_slist_next (iter)) { - GSList *active, *elt; + g_hash_table_iter_init (&iter, priv->services); + while (g_hash_table_iter_next (&iter, NULL, &data)) { + active = nm_vpn_service_get_active_connections (NM_VPN_SERVICE (data)); + for (elt = active; elt; elt = g_slist_next (elt)) { + NMVPNConnection *vpn = NM_VPN_CONNECTION (elt->data); + const char *ac_path; - active = nm_vpn_service_get_active_connections (NM_VPN_SERVICE (iter->data)); - for (elt = active; elt; elt = g_slist_next (elt)) - list = g_slist_append (list, g_object_ref (NM_VPN_CONNECTION (elt->data))); + ac_path = nm_vpn_connection_get_active_connection_path (vpn); + if (ac_path && !strcmp (ac_path, active_path)) + return nm_vpn_connection_get_connection (vpn); + } } - return list; + return NULL; } +static char * +service_name_from_file (const char *path) +{ + GKeyFile *kf = NULL; + char *service_name = NULL; + + g_return_val_if_fail (g_path_is_absolute (path), NULL); + + if (!g_str_has_suffix (path, ".name")) + return NULL; + + kf = g_key_file_new (); + if (g_key_file_load_from_file (kf, path, G_KEY_FILE_NONE, NULL)) + service_name = g_key_file_get_string (kf, VPN_CONNECTION_GROUP, "service", NULL); + + g_key_file_free (kf); + return service_name; +} + +static void +try_add_service (NMVPNManager *self, const char *namefile) +{ + NMVPNManagerPrivate *priv = NM_VPN_MANAGER_GET_PRIVATE (self); + NMVPNService *service = NULL; + GError *error = NULL; + const char *service_name; + char *tmp; + + g_return_if_fail (g_path_is_absolute (namefile)); + + /* Make sure we don't add dupes */ + tmp = service_name_from_file (namefile); + if (tmp) + service = g_hash_table_lookup (priv->services, tmp); + g_free (tmp); + if (service) + return; + + /* New service, add it */ + service = nm_vpn_service_new (namefile, &error); + if (!service) { + nm_log_warn (LOGD_VPN, "failed to load VPN service file %s: (%d) %s", + error ? error->code : -1, + error && error->message ? error->message : "(unknown)"); + g_clear_error (&error); + return; + } + + service_name = nm_vpn_service_get_dbus_service (service); + g_hash_table_insert (priv->services, (char *) service_name, service); + nm_log_info (LOGD_VPN, "VPN: loaded %s", service_name, service); +} + +static void +vpn_dir_changed (GFileMonitor *monitor, + GFile *file, + GFile *other_file, + GFileMonitorEvent event_type, + gpointer user_data) +{ + NMVPNManager *self = NM_VPN_MANAGER (user_data); + NMVPNManagerPrivate *priv = NM_VPN_MANAGER_GET_PRIVATE (self); + NMVPNService *service; + char *path; + + path = g_file_get_path (file); + if (!g_str_has_suffix (path, ".name")) { + g_free (path); + return; + } + + switch (event_type) { + case G_FILE_MONITOR_EVENT_DELETED: + nm_log_dbg (LOGD_VPN, "service file %s deleted", path); + + service = get_service_by_namefile (self, path); + if (service) { + const char *service_name = nm_vpn_service_get_dbus_service (service); + + /* Stop active VPN connections and destroy the service */ + nm_vpn_service_connections_stop (service, TRUE, + NM_VPN_CONNECTION_STATE_REASON_SERVICE_STOPPED); + nm_log_info (LOGD_VPN, "VPN: unloaded %s", service_name, service); + g_hash_table_remove (priv->services, service_name); + } + break; + case G_FILE_MONITOR_EVENT_CREATED: + case G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT: + nm_log_dbg (LOGD_VPN, "service file %s created or modified", path); + try_add_service (self, path); + break; + default: + nm_log_dbg (LOGD_VPN, "service file %s change event %d", path, event_type); + break; + } + + g_free (path); +} + +/******************************************************************************/ + NMVPNManager * nm_vpn_manager_get (void) { @@ -318,21 +442,61 @@ nm_vpn_manager_get (void) return singleton; } -/******************************************************************************/ - static void -nm_vpn_manager_init (NMVPNManager *manager) +nm_vpn_manager_init (NMVPNManager *self) { + NMVPNManagerPrivate *priv = NM_VPN_MANAGER_GET_PRIVATE (self); + GFile *file; + GDir *dir; + const char *fn; + char *path; + + priv->services = g_hash_table_new_full (g_str_hash, g_str_equal, + NULL, g_object_unref); + + /* Watch the VPN directory for changes */ + file = g_file_new_for_path (VPN_NAME_FILES_DIR "/"); + priv->monitor = g_file_monitor_directory (file, G_FILE_MONITOR_NONE, NULL, NULL); + g_object_unref (file); + if (priv->monitor) { + priv->monitor_id = g_signal_connect (priv->monitor, "changed", + G_CALLBACK (vpn_dir_changed), self); + } + + /* Load VPN service files */ + dir = g_dir_open (VPN_NAME_FILES_DIR, 0, NULL); + if (dir) { + while ((fn = g_dir_read_name (dir))) { + /* only parse filenames that end with .name */ + if (g_str_has_suffix (fn, ".name")) { + path = g_build_filename (VPN_NAME_FILES_DIR, fn, NULL); + try_add_service (self, path); + g_free (path); + } + } + g_dir_close (dir); + } } static void -finalize (GObject *object) +dispose (GObject *object) { NMVPNManagerPrivate *priv = NM_VPN_MANAGER_GET_PRIVATE (object); - g_slist_foreach (priv->services, (GFunc) g_object_unref, NULL); + if (!priv->disposed) { + priv->disposed = TRUE; + + if (priv->monitor) { + if (priv->monitor_id) + g_signal_handler_disconnect (priv->monitor, priv->monitor_id); + g_file_monitor_cancel (priv->monitor); + g_object_unref (priv->monitor); + } + + g_hash_table_destroy (priv->services); + } - G_OBJECT_CLASS (nm_vpn_manager_parent_class)->finalize (object); + G_OBJECT_CLASS (nm_vpn_manager_parent_class)->dispose (object); } static void @@ -343,7 +507,7 @@ nm_vpn_manager_class_init (NMVPNManagerClass *manager_class) g_type_class_add_private (manager_class, sizeof (NMVPNManagerPrivate)); /* virtual methods */ - object_class->finalize = finalize; + object_class->dispose = dispose; /* signals */ signals[CONNECTION_ACTIVATED] = diff --git a/src/vpn-manager/nm-vpn-manager.h b/src/vpn-manager/nm-vpn-manager.h index d07aa250..f14844a9 100644 --- a/src/vpn-manager/nm-vpn-manager.h +++ b/src/vpn-manager/nm-vpn-manager.h @@ -83,4 +83,7 @@ void nm_vpn_manager_add_active_connections (NMVPNManager *manager, GSList *nm_vpn_manager_get_active_connections (NMVPNManager *manager); +NMConnection *nm_vpn_manager_get_connection_for_active (NMVPNManager *manager, + const char *active_path); + #endif /* NM_VPN_VPN_MANAGER_H */ diff --git a/src/vpn-manager/nm-vpn-service.c b/src/vpn-manager/nm-vpn-service.c index bdbb3774..3d44d900 100644 --- a/src/vpn-manager/nm-vpn-service.c +++ b/src/vpn-manager/nm-vpn-service.c @@ -15,10 +15,11 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright (C) 2005 - 2008 Red Hat, Inc. + * Copyright (C) 2005 - 2010 Red Hat, Inc. * Copyright (C) 2005 - 2008 Novell, Inc. */ +#include <config.h> #include <glib.h> #include <string.h> #include <dbus/dbus.h> @@ -36,125 +37,94 @@ G_DEFINE_TYPE (NMVPNService, nm_vpn_service, G_TYPE_OBJECT) typedef struct { + gboolean disposed; + NMDBusManager *dbus_mgr; char *name; char *dbus_service; char *program; + char *namefile; GPid pid; GSList *connections; - guint service_start_timeout; - guint service_child_watch; + guint start_timeout; + guint quit_timeout; + guint child_watch; gulong name_owner_id; } NMVPNServicePrivate; #define NM_VPN_SERVICE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_VPN_SERVICE, NMVPNServicePrivate)) -#define VPN_CONNECTION_GROUP "VPN Connection" - -static GKeyFile * -find_service_file (const char *name) -{ - GDir *dir; - const char *fn; - GKeyFile *key_file = NULL; - - dir = g_dir_open (VPN_NAME_FILES_DIR, 0, NULL); - if (!dir) - return NULL; - - while ((fn = g_dir_read_name (dir))) { - char *path; - gboolean found = FALSE; - - /* only parse filenames that end with .name */ - if (!g_str_has_suffix (fn, ".name")) - continue; - - key_file = g_key_file_new (); - path = g_build_filename (VPN_NAME_FILES_DIR, fn, NULL); - - if (g_key_file_load_from_file (key_file, path, G_KEY_FILE_NONE, NULL)) { - gchar *val; - - val = g_key_file_get_string (key_file, VPN_CONNECTION_GROUP, "service", NULL); - if (val) { - if (!strcmp (val, name)) - found = TRUE; - g_free (val); - } - } - - g_free (path); - - if (found) - break; - - g_key_file_free (key_file); - key_file = NULL; - } - - g_dir_close (dir); - - return key_file; -} - NMVPNService * -nm_vpn_service_new (const char *name) +nm_vpn_service_new (const char *namefile, GError **error) { - GKeyFile *key_file; - NMVPNService *service = NULL; - NMVPNServicePrivate *priv; - char *dbus_service = NULL; - char *program = NULL; - gboolean success = FALSE; + NMVPNService *self = NULL; + GKeyFile *kf; + char *dbus_service = NULL, *program = NULL, *name = NULL; - g_return_val_if_fail (name != NULL, NULL); + g_return_val_if_fail (namefile != NULL, NULL); + g_return_val_if_fail (g_path_is_absolute (namefile), NULL); - key_file = find_service_file (name); - if (!key_file) + kf = g_key_file_new (); + if (!g_key_file_load_from_file (kf, namefile, G_KEY_FILE_NONE, error)) { + g_key_file_free (kf); return NULL; + } - dbus_service = g_key_file_get_string (key_file, VPN_CONNECTION_GROUP, "service", NULL); - if (!dbus_service) + dbus_service = g_key_file_get_string (kf, VPN_CONNECTION_GROUP, "service", NULL); + if (!dbus_service) { + g_set_error (error, 0, 0, "VPN service file %s had no 'service' key", namefile); goto out; + } - program = g_key_file_get_string (key_file, VPN_CONNECTION_GROUP, "program", NULL); - if (!program) + program = g_key_file_get_string (kf, VPN_CONNECTION_GROUP, "program", NULL); + if (!program) { + g_set_error (error, 0, 0, "VPN service file %s had no 'program' key", namefile); goto out; + } - service = (NMVPNService *) g_object_new (NM_TYPE_VPN_SERVICE, NULL); - if (!service) + name = g_key_file_get_string (kf, VPN_CONNECTION_GROUP, "name", NULL); + if (!name) { + g_set_error (error, 0, 0, "VPN service file %s had no 'name' key", namefile); goto out; + } - priv = NM_VPN_SERVICE_GET_PRIVATE (service); - - priv->name = g_strdup (name); - priv->dbus_service = dbus_service; - priv->program = program; + self = (NMVPNService *) g_object_new (NM_TYPE_VPN_SERVICE, NULL); + if (!self) { + g_set_error (error, 0, 0, "out of memory creating VPN service object"); + goto out; + } - success = TRUE; + NM_VPN_SERVICE_GET_PRIVATE (self)->name = g_strdup (name); + NM_VPN_SERVICE_GET_PRIVATE (self)->dbus_service = g_strdup (dbus_service); + NM_VPN_SERVICE_GET_PRIVATE (self)->program = g_strdup (program); + NM_VPN_SERVICE_GET_PRIVATE (self)->namefile = g_strdup (namefile); out: - g_key_file_free (key_file); + g_key_file_free (kf); + g_free (dbus_service); + g_free (program); + g_free (name); + return self; +} - if (!success) { - g_free (dbus_service); - g_free (program); - } +const char * +nm_vpn_service_get_dbus_service (NMVPNService *service) +{ + g_return_val_if_fail (NM_IS_VPN_SERVICE (service), NULL); - return service; + return NM_VPN_SERVICE_GET_PRIVATE (service)->dbus_service; } const char * -nm_vpn_service_get_name (NMVPNService *service) +nm_vpn_service_get_name_file (NMVPNService *service) { g_return_val_if_fail (NM_IS_VPN_SERVICE (service), NULL); - return NM_VPN_SERVICE_GET_PRIVATE (service)->name; + return NM_VPN_SERVICE_GET_PRIVATE (service)->namefile; } -static void +void nm_vpn_service_connections_stop (NMVPNService *service, gboolean fail, NMVPNConnectionStateReason reason) @@ -175,6 +145,17 @@ nm_vpn_service_connections_stop (NMVPNService *service, g_slist_free (copy); } +static void +clear_quit_timeout (NMVPNService *self) +{ + NMVPNServicePrivate *priv = NM_VPN_SERVICE_GET_PRIVATE (self); + + if (priv->quit_timeout) { + g_source_remove (priv->quit_timeout); + priv->quit_timeout = 0; + } +} + /* * nm_vpn_service_child_setup * @@ -200,21 +181,22 @@ vpn_service_watch_cb (GPid pid, gint status, gpointer user_data) if (err != 0) { nm_log_warn (LOGD_VPN, "VPN service '%s' exited with error: %d", - nm_vpn_service_get_name (service), WSTOPSIG (status)); + priv->name, WSTOPSIG (status)); } } else if (WIFSTOPPED (status)) { nm_log_warn (LOGD_VPN, "VPN service '%s' stopped unexpectedly with signal %d", - nm_vpn_service_get_name (service), WSTOPSIG (status)); + priv->name, WSTOPSIG (status)); } else if (WIFSIGNALED (status)) { nm_log_warn (LOGD_VPN, "VPN service '%s' died with signal %d", - nm_vpn_service_get_name (service), WTERMSIG (status)); + priv->name, WTERMSIG (status)); } else { nm_log_warn (LOGD_VPN, "VPN service '%s' died from an unknown cause", - nm_vpn_service_get_name (service)); + priv->name); } priv->pid = 0; - priv->service_child_watch = 0; + priv->child_watch = 0; + clear_quit_timeout (service); nm_vpn_service_connections_stop (service, TRUE, NM_VPN_CONNECTION_STATE_REASON_SERVICE_STOPPED); } @@ -222,14 +204,12 @@ vpn_service_watch_cb (GPid pid, gint status, gpointer user_data) static gboolean nm_vpn_service_timeout (gpointer data) { - NMVPNService *service = NM_VPN_SERVICE (data); - - nm_log_warn (LOGD_VPN, "VPN service '%s' did not start in time, cancelling connections", - nm_vpn_service_get_name (service)); - - NM_VPN_SERVICE_GET_PRIVATE (service)->service_start_timeout = 0; - nm_vpn_service_connections_stop (service, TRUE, NM_VPN_CONNECTION_STATE_REASON_SERVICE_START_TIMEOUT); + NMVPNService *self = NM_VPN_SERVICE (data); + NMVPNServicePrivate *priv = NM_VPN_SERVICE_GET_PRIVATE (self); + nm_log_warn (LOGD_VPN, "VPN service '%s' start timed out", priv->name); + priv->start_timeout = 0; + nm_vpn_service_connections_stop (self, TRUE, NM_VPN_CONNECTION_STATE_REASON_SERVICE_START_TIMEOUT); return FALSE; } @@ -253,13 +233,15 @@ nm_vpn_service_daemon_exec (NMVPNService *service, GError **error) &spawn_error); if (success) { nm_log_info (LOGD_VPN, "VPN service '%s' started (%s), PID %d", - nm_vpn_service_get_name (service), priv->dbus_service, priv->pid); + priv->name, priv->dbus_service, priv->pid); - priv->service_child_watch = g_child_watch_add (priv->pid, vpn_service_watch_cb, service); - priv->service_start_timeout = g_timeout_add_seconds (5, nm_vpn_service_timeout, service); + priv->child_watch = g_child_watch_add (priv->pid, vpn_service_watch_cb, service); + priv->start_timeout = g_timeout_add_seconds (5, nm_vpn_service_timeout, service); } else { nm_log_warn (LOGD_VPN, "VPN service '%s': could not launch the VPN service. error: (%d) %s.", - nm_vpn_service_get_name (service), spawn_error->code, spawn_error->message); + priv->name, + spawn_error ? spawn_error->code : -1, + spawn_error && spawn_error->message ? spawn_error->message : "(unknown)"); g_set_error (error, NM_VPN_MANAGER_ERROR, NM_VPN_MANAGER_ERROR_SERVICE_START_FAILED, @@ -274,9 +256,40 @@ nm_vpn_service_daemon_exec (NMVPNService *service, GError **error) } static gboolean -destroy_service (gpointer data) +ensure_killed (gpointer data) +{ + int pid = GPOINTER_TO_INT (data); + + if (kill (pid, 0) == 0) + kill (pid, SIGKILL); + + /* ensure the child is reaped */ + nm_log_dbg (LOGD_VPN, "waiting for VPN service pid %d to exit", pid); + waitpid (pid, NULL, 0); + nm_log_dbg (LOGD_VPN, "VPN service pid %d cleaned up", pid); + + return FALSE; +} + +static gboolean +service_quit (gpointer user_data) { - g_object_unref (data); + NMVPNServicePrivate *priv = NM_VPN_SERVICE_GET_PRIVATE (user_data); + + if (priv->pid) { + if (kill (priv->pid, SIGTERM) == 0) + g_timeout_add_seconds (2, ensure_killed, GINT_TO_POINTER (priv->pid)); + else { + kill (priv->pid, SIGKILL); + + /* ensure the child is reaped */ + nm_log_dbg (LOGD_VPN, "waiting for VPN service pid %d to exit", priv->pid); + waitpid (priv->pid, NULL, 0); + nm_log_dbg (LOGD_VPN, "VPN service pid %d cleaned up", priv->pid); + } + priv->pid = 0; + } + priv->quit_timeout = 0; return FALSE; } @@ -297,8 +310,9 @@ connection_vpn_state_changed (NMVPNConnection *connection, g_object_unref (connection); if (priv->connections == NULL) { - /* schedule a timeout (10 seconds) to destroy the service */ - g_timeout_add_seconds (10, destroy_service, user_data); + /* Tell the service to quit in a few seconds */ + if (!priv->quit_timeout) + priv->quit_timeout = g_timeout_add_seconds (5, service_quit, user_data); } break; default: @@ -325,6 +339,8 @@ nm_vpn_service_activate (NMVPNService *service, priv = NM_VPN_SERVICE_GET_PRIVATE (service); + clear_quit_timeout (service); + vpn = nm_vpn_connection_new (connection, act_request, device); g_signal_connect (vpn, "vpn-state-changed", G_CALLBACK (connection_vpn_state_changed), @@ -335,9 +351,8 @@ nm_vpn_service_activate (NMVPNService *service, if (nm_dbus_manager_name_has_owner (priv->dbus_mgr, priv->dbus_service)) { // FIXME: fill in error when errors happen nm_vpn_connection_activate (vpn); - } else if (priv->service_start_timeout == 0) { - nm_log_info (LOGD_VPN, "Starting VPN service '%s'...", - nm_vpn_service_get_name (service)); + } else if (priv->start_timeout == 0) { + nm_log_info (LOGD_VPN, "Starting VPN service '%s'...", priv->name); if (!nm_vpn_service_daemon_exec (service, error)) vpn = NULL; } @@ -364,14 +379,15 @@ nm_vpn_service_name_owner_changed (NMDBusManager *mgr, NMVPNServicePrivate *priv = NM_VPN_SERVICE_GET_PRIVATE (service); gboolean old_owner_good; gboolean new_owner_good; + GSList *iter; if (strcmp (name, priv->dbus_service)) return; /* Service changed, no need to wait for the timeout any longer */ - if (priv->service_start_timeout) { - g_source_remove (priv->service_start_timeout); - priv->service_start_timeout = 0; + if (priv->start_timeout) { + g_source_remove (priv->start_timeout); + priv->start_timeout = 0; } old_owner_good = (old && (strlen (old) > 0)); @@ -379,18 +395,14 @@ nm_vpn_service_name_owner_changed (NMDBusManager *mgr, if (!old_owner_good && new_owner_good) { /* service just appeared */ - GSList *iter; - - nm_log_info (LOGD_VPN, "VPN service '%s' appeared, activating connections", - nm_vpn_service_get_name (service)); + nm_log_info (LOGD_VPN, "VPN service '%s' appeared; activating connections", priv->name); + clear_quit_timeout (service); for (iter = priv->connections; iter; iter = iter->next) nm_vpn_connection_activate (NM_VPN_CONNECTION (iter->data)); - } else if (old_owner_good && !new_owner_good) { /* service went away */ - nm_log_info (LOGD_VPN, "VPN service '%s' disappeared, cancelling connections", - nm_vpn_service_get_name (service)); + nm_log_info (LOGD_VPN, "VPN service '%s' disappeared", priv->name); nm_vpn_service_connections_stop (service, TRUE, NM_VPN_CONNECTION_STATE_REASON_SERVICE_STOPPED); } } @@ -398,40 +410,28 @@ nm_vpn_service_name_owner_changed (NMDBusManager *mgr, /******************************************************************************/ static void -nm_vpn_service_init (NMVPNService *service) +nm_vpn_service_init (NMVPNService *self) { - NMVPNServicePrivate *priv = NM_VPN_SERVICE_GET_PRIVATE (service); + NMVPNServicePrivate *priv = NM_VPN_SERVICE_GET_PRIVATE (self); priv->dbus_mgr = nm_dbus_manager_get (); - priv->name_owner_id = g_signal_connect (priv->dbus_mgr, "name-owner-changed", - G_CALLBACK (nm_vpn_service_name_owner_changed), - service); -} - -static gboolean -ensure_killed (gpointer data) -{ - int pid = GPOINTER_TO_INT (data); - - if (kill (pid, 0) == 0) - kill (pid, SIGKILL); - - /* ensure the child is reaped */ - nm_log_dbg (LOGD_VPN, "waiting for VPN service pid %d to exit", pid); - waitpid (pid, NULL, 0); - nm_log_dbg (LOGD_VPN, "VPN service pid %d cleaned up", pid); - - return FALSE; + G_CALLBACK (nm_vpn_service_name_owner_changed), + self); } static void -finalize (GObject *object) +dispose (GObject *object) { - NMVPNServicePrivate *priv = NM_VPN_SERVICE_GET_PRIVATE (object); + NMVPNService *self = NM_VPN_SERVICE (object); + NMVPNServicePrivate *priv = NM_VPN_SERVICE_GET_PRIVATE (self); - if (priv->service_start_timeout) - g_source_remove (priv->service_start_timeout); + if (priv->disposed) + goto out; + priv->disposed = TRUE; + + if (priv->start_timeout) + g_source_remove (priv->start_timeout); nm_vpn_service_connections_stop (NM_VPN_SERVICE (object), FALSE, @@ -439,31 +439,21 @@ finalize (GObject *object) g_signal_handler_disconnect (priv->dbus_mgr, priv->name_owner_id); - if (priv->service_child_watch) - g_source_remove (priv->service_child_watch); + if (priv->child_watch) + g_source_remove (priv->child_watch); - if (priv->pid) { - if (kill (priv->pid, SIGTERM) == 0) - g_timeout_add_seconds (2, ensure_killed, GINT_TO_POINTER (priv->pid)); - else { - kill (priv->pid, SIGKILL); - - /* ensure the child is reaped */ - nm_log_dbg (LOGD_VPN, "waiting for VPN service pid %d to exit", priv->pid); - waitpid (priv->pid, NULL, 0); - nm_log_dbg (LOGD_VPN, "VPN service pid %d cleaned up", priv->pid); - } - - priv->pid = 0; - } + clear_quit_timeout (self); + service_quit (self); g_object_unref (priv->dbus_mgr); g_free (priv->name); g_free (priv->dbus_service); g_free (priv->program); + g_free (priv->namefile); - G_OBJECT_CLASS (nm_vpn_service_parent_class)->finalize (object); +out: + G_OBJECT_CLASS (nm_vpn_service_parent_class)->dispose (object); } static void @@ -474,5 +464,5 @@ nm_vpn_service_class_init (NMVPNServiceClass *service_class) g_type_class_add_private (service_class, sizeof (NMVPNServicePrivate)); /* virtual methods */ - object_class->finalize = finalize; + object_class->dispose = dispose; } diff --git a/src/vpn-manager/nm-vpn-service.h b/src/vpn-manager/nm-vpn-service.h index 9c5e0eef..c7c1b036 100644 --- a/src/vpn-manager/nm-vpn-service.h +++ b/src/vpn-manager/nm-vpn-service.h @@ -35,6 +35,8 @@ #define NM_IS_VPN_SERVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), NM_TYPE_VPN_SERVICE)) #define NM_VPN_SERVICE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_VPN_SERVICE, NMVPNServiceClass)) +#define VPN_CONNECTION_GROUP "VPN Connection" + typedef struct { GObject parent; } NMVPNService; @@ -45,9 +47,13 @@ typedef struct { GType nm_vpn_service_get_type (void); -NMVPNService * nm_vpn_service_new (const char *service_name); +NMVPNService * nm_vpn_service_new (const char *namefile, GError **error); + +/* Returns the VPN service's D-Bus service name */ +const char *nm_vpn_service_get_dbus_service (NMVPNService *service); -const char * nm_vpn_service_get_name (NMVPNService *service); +/* Returns the path of the VPN service's .name file */ +const char *nm_vpn_service_get_name_file (NMVPNService *service); NMVPNConnection * nm_vpn_service_activate (NMVPNService *service, NMConnection *connection, @@ -57,4 +63,8 @@ NMVPNConnection * nm_vpn_service_activate (NMVPNService *service, GSList * nm_vpn_service_get_active_connections (NMVPNService *service); +void nm_vpn_service_connections_stop (NMVPNService *service, + gboolean fail, + NMVPNConnectionStateReason reason); + #endif /* NM_VPN_VPN_SERVICE_H */ |