diff options
| author | Michael Biebl <biebl@debian.org> | 2010-11-29 00:47:11 +0100 |
|---|---|---|
| committer | Michael Biebl <biebl@debian.org> | 2010-11-29 00:47:11 +0100 |
| commit | 9fae01fa351805b2903e535736e06971bc0b925e (patch) | |
| tree | c19bccf84c9f894e50fae678ba6ee2b2044e2d30 /src/ppp-manager | |
Imported Upstream version 0.8.1 upstream/0.8.1
Diffstat (limited to 'src/ppp-manager')
| -rw-r--r-- | src/ppp-manager/Makefile.am | 58 | ||||
| -rw-r--r-- | src/ppp-manager/Makefile.in | 679 | ||||
| -rw-r--r-- | src/ppp-manager/nm-ppp-manager.c | 1058 | ||||
| -rw-r--r-- | src/ppp-manager/nm-ppp-manager.h | 80 | ||||
| -rw-r--r-- | src/ppp-manager/nm-ppp-status.h | 43 | ||||
| -rw-r--r-- | src/ppp-manager/nm-pppd-plugin.c | 359 | ||||
| -rw-r--r-- | src/ppp-manager/nm-pppd-plugin.h | 29 |
7 files changed, 2306 insertions, 0 deletions
diff --git a/src/ppp-manager/Makefile.am b/src/ppp-manager/Makefile.am new file mode 100644 index 00000000..2dc7ad94 --- /dev/null +++ b/src/ppp-manager/Makefile.am @@ -0,0 +1,58 @@ +INCLUDES = \ + -I${top_srcdir} \ + -I${top_srcdir}/include \ + -I${top_srcdir}/libnm-util \ + -I${top_srcdir}/src \ + -I${top_srcdir}/src/logging \ + -I${top_builddir}/marshallers + +noinst_LTLIBRARIES = libppp-manager.la + +libppp_manager_la_SOURCES = \ + nm-ppp-manager.c \ + nm-ppp-manager.h \ + nm-ppp-status.h + +nm-ppp-manager-glue.h: $(top_srcdir)/introspection/nm-ppp-manager.xml + dbus-binding-tool --prefix=nm_ppp_manager --mode=glib-server --output=$@ $< + +built_sources = nm-ppp-manager-glue.h + +$(libppp_manager_la_OBJECTS): $(built_sources) + +libppp_manager_la_CPPFLAGS = \ + $(DBUS_CFLAGS) \ + -DG_DISABLE_DEPRECATED \ + -DSYSCONFDIR=\"$(sysconfdir)\" \ + -DLIBDIR=\"$(libdir)\" \ + -DPLUGINDIR=\"$(PPPD_PLUGIN_DIR)\" + +libppp_manager_la_LIBADD = \ + $(top_builddir)/marshallers/libmarshallers.la \ + $(top_builddir)/src/logging/libnm-logging.la \ + $(DBUS_LIBS) \ + $(GLIB_LIBS) + +pppd_plugindir = $(PPPD_PLUGIN_DIR) +pppd_plugin_LTLIBRARIES = nm-pppd-plugin.la + +nm_pppd_plugin_la_SOURCES = \ + nm-pppd-plugin.c \ + nm-pppd-plugin.h \ + nm-ppp-status.h + +nm_pppd_plugin_la_CPPFLAGS = \ + $(DBUS_CFLAGS) \ + $(GLIB_CFLAGS) + +nm_pppd_plugin_la_LDFLAGS = -module -avoid-version + +nm_pppd_plugin_la_LIBADD = \ + $(top_builddir)/libnm-util/libnm-util.la \ + $(DBUS_LIBS) \ + $(GLIB_LIBS) + +BUILT_SOURCES = nm-ppp-manager-glue.h + +CLEANFILES = $(BUILT_SOURCES) + diff --git a/src/ppp-manager/Makefile.in b/src/ppp-manager/Makefile.in new file mode 100644 index 00000000..59cb32ba --- /dev/null +++ b/src/ppp-manager/Makefile.in @@ -0,0 +1,679 @@ +# Makefile.in generated by automake 1.11.1 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, +# Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +subdir = src/ppp-manager +DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/m4/compiler_warnings.m4 \ + $(top_srcdir)/m4/gtk-doc.m4 $(top_srcdir)/m4/intltool.m4 \ + $(top_srcdir)/m4/libnl-check.m4 $(top_srcdir)/m4/libtool.m4 \ + $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \ + $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \ + $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(install_sh) -d +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; +am__vpath_adj = case $$p in \ + $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ + *) f=$$p;; \ + esac; +am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`; +am__install_max = 40 +am__nobase_strip_setup = \ + srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'` +am__nobase_strip = \ + for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||" +am__nobase_list = $(am__nobase_strip_setup); \ + for p in $$list; do echo "$$p $$p"; done | \ + sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \ + $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \ + if (++n[$$2] == $(am__install_max)) \ + { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \ + END { for (dir in files) print dir, files[dir] }' +am__base_list = \ + sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ + sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' +am__installdirs = "$(DESTDIR)$(pppd_plugindir)" +LTLIBRARIES = $(noinst_LTLIBRARIES) $(pppd_plugin_LTLIBRARIES) +am__DEPENDENCIES_1 = +libppp_manager_la_DEPENDENCIES = \ + $(top_builddir)/marshallers/libmarshallers.la \ + $(top_builddir)/src/logging/libnm-logging.la \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) +am_libppp_manager_la_OBJECTS = libppp_manager_la-nm-ppp-manager.lo +libppp_manager_la_OBJECTS = $(am_libppp_manager_la_OBJECTS) +nm_pppd_plugin_la_DEPENDENCIES = \ + $(top_builddir)/libnm-util/libnm-util.la $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) +am_nm_pppd_plugin_la_OBJECTS = nm_pppd_plugin_la-nm-pppd-plugin.lo +nm_pppd_plugin_la_OBJECTS = $(am_nm_pppd_plugin_la_OBJECTS) +nm_pppd_plugin_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ + $(nm_pppd_plugin_la_LDFLAGS) $(LDFLAGS) -o $@ +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) +CCLD = $(CC) +LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \ + $(LDFLAGS) -o $@ +SOURCES = $(libppp_manager_la_SOURCES) $(nm_pppd_plugin_la_SOURCES) +DIST_SOURCES = $(libppp_manager_la_SOURCES) \ + $(nm_pppd_plugin_la_SOURCES) +ETAGS = etags +CTAGS = ctags +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +ACLOCAL_AMFLAGS = @ACLOCAL_AMFLAGS@ +ALL_LINGUAS = @ALL_LINGUAS@ +AMTAR = @AMTAR@ +AR = @AR@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CATALOGS = @CATALOGS@ +CATOBJEXT = @CATOBJEXT@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DATADIRNAME = @DATADIRNAME@ +DBUS_CFLAGS = @DBUS_CFLAGS@ +DBUS_LIBS = @DBUS_LIBS@ +DBUS_SYS_DIR = @DBUS_SYS_DIR@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DHCLIENT_PATH = @DHCLIENT_PATH@ +DHCPCD_PATH = @DHCPCD_PATH@ +DISABLE_DEPRECATED = @DISABLE_DEPRECATED@ +DSYMUTIL = @DSYMUTIL@ +DUMPBIN = @DUMPBIN@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +FGREP = @FGREP@ +GETTEXT_PACKAGE = @GETTEXT_PACKAGE@ +GIO_CFLAGS = @GIO_CFLAGS@ +GIO_LIBS = @GIO_LIBS@ +GLIB_CFLAGS = @GLIB_CFLAGS@ +GLIB_GENMARSHAL = @GLIB_GENMARSHAL@ +GLIB_LIBS = @GLIB_LIBS@ +GMODULE_CFLAGS = @GMODULE_CFLAGS@ +GMODULE_LIBS = @GMODULE_LIBS@ +GMOFILES = @GMOFILES@ +GMSGFMT = @GMSGFMT@ +GNUTLS_CFLAGS = @GNUTLS_CFLAGS@ +GNUTLS_LIBS = @GNUTLS_LIBS@ +GREP = @GREP@ +GTKDOC_CHECK = @GTKDOC_CHECK@ +GTKDOC_MKPDF = @GTKDOC_MKPDF@ +GTKDOC_REBASE = @GTKDOC_REBASE@ +GUDEV_CFLAGS = @GUDEV_CFLAGS@ +GUDEV_LIBS = @GUDEV_LIBS@ +HTML_DIR = @HTML_DIR@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +INSTOBJEXT = @INSTOBJEXT@ +INTLLIBS = @INTLLIBS@ +INTLTOOL_EXTRACT = @INTLTOOL_EXTRACT@ +INTLTOOL_MERGE = @INTLTOOL_MERGE@ +INTLTOOL_PERL = @INTLTOOL_PERL@ +INTLTOOL_UPDATE = @INTLTOOL_UPDATE@ +IPTABLES_PATH = @IPTABLES_PATH@ +LD = @LD@ +LDFLAGS = @LDFLAGS@ +LIBDL = @LIBDL@ +LIBGCRYPT_CFLAGS = @LIBGCRYPT_CFLAGS@ +LIBGCRYPT_CONFIG = @LIBGCRYPT_CONFIG@ +LIBGCRYPT_LIBS = @LIBGCRYPT_LIBS@ +LIBM = @LIBM@ +LIBNL_CFLAGS = @LIBNL_CFLAGS@ +LIBNL_LIBS = @LIBNL_LIBS@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LIPO = @LIPO@ +LN_S = @LN_S@ +LTLIBOBJS = @LTLIBOBJS@ +MAINT = @MAINT@ +MAKEINFO = @MAKEINFO@ +MKDIR_P = @MKDIR_P@ +MKINSTALLDIRS = @MKINSTALLDIRS@ +MSGFMT = @MSGFMT@ +MSGFMT_OPTS = @MSGFMT_OPTS@ +MSGMERGE = @MSGMERGE@ +NM = @NM@ +NMEDIT = @NMEDIT@ +NSS_CFLAGS = @NSS_CFLAGS@ +NSS_LIBS = @NSS_LIBS@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +OTOOL = @OTOOL@ +OTOOL64 = @OTOOL64@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PKG_CONFIG = @PKG_CONFIG@ +POFILES = @POFILES@ +POLKIT_CFLAGS = @POLKIT_CFLAGS@ +POLKIT_LIBS = @POLKIT_LIBS@ +POSUB = @POSUB@ +PO_IN_DATADIR_FALSE = @PO_IN_DATADIR_FALSE@ +PO_IN_DATADIR_TRUE = @PO_IN_DATADIR_TRUE@ +PPPD_PLUGIN_DIR = @PPPD_PLUGIN_DIR@ +RANLIB = @RANLIB@ +RESOLVCONF_PATH = @RESOLVCONF_PATH@ +SED = @SED@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +SYSTEM_CA_PATH = @SYSTEM_CA_PATH@ +UDEV_BASE_DIR = @UDEV_BASE_DIR@ +USE_NLS = @USE_NLS@ +UUID_CFLAGS = @UUID_CFLAGS@ +UUID_LIBS = @UUID_LIBS@ +VERSION = @VERSION@ +XGETTEXT = @XGETTEXT@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +lt_ECHO = @lt_ECHO@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +target_alias = @target_alias@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +INCLUDES = \ + -I${top_srcdir} \ + -I${top_srcdir}/include \ + -I${top_srcdir}/libnm-util \ + -I${top_srcdir}/src \ + -I${top_srcdir}/src/logging \ + -I${top_builddir}/marshallers + +noinst_LTLIBRARIES = libppp-manager.la +libppp_manager_la_SOURCES = \ + nm-ppp-manager.c \ + nm-ppp-manager.h \ + nm-ppp-status.h + +built_sources = nm-ppp-manager-glue.h +libppp_manager_la_CPPFLAGS = \ + $(DBUS_CFLAGS) \ + -DG_DISABLE_DEPRECATED \ + -DSYSCONFDIR=\"$(sysconfdir)\" \ + -DLIBDIR=\"$(libdir)\" \ + -DPLUGINDIR=\"$(PPPD_PLUGIN_DIR)\" + +libppp_manager_la_LIBADD = \ + $(top_builddir)/marshallers/libmarshallers.la \ + $(top_builddir)/src/logging/libnm-logging.la \ + $(DBUS_LIBS) \ + $(GLIB_LIBS) + +pppd_plugindir = $(PPPD_PLUGIN_DIR) +pppd_plugin_LTLIBRARIES = nm-pppd-plugin.la +nm_pppd_plugin_la_SOURCES = \ + nm-pppd-plugin.c \ + nm-pppd-plugin.h \ + nm-ppp-status.h + +nm_pppd_plugin_la_CPPFLAGS = \ + $(DBUS_CFLAGS) \ + $(GLIB_CFLAGS) + +nm_pppd_plugin_la_LDFLAGS = -module -avoid-version +nm_pppd_plugin_la_LIBADD = \ + $(top_builddir)/libnm-util/libnm-util.la \ + $(DBUS_LIBS) \ + $(GLIB_LIBS) + +BUILT_SOURCES = nm-ppp-manager-glue.h +CLEANFILES = $(BUILT_SOURCES) +all: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) all-am + +.SUFFIXES: +.SUFFIXES: .c .lo .o .obj +$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/ppp-manager/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --gnu src/ppp-manager/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): + +clean-noinstLTLIBRARIES: + -test -z "$(noinst_LTLIBRARIES)" || rm -f $(noinst_LTLIBRARIES) + @list='$(noinst_LTLIBRARIES)'; for p in $$list; do \ + dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \ + test "$$dir" != "$$p" || dir=.; \ + echo "rm -f \"$${dir}/so_locations\""; \ + rm -f "$${dir}/so_locations"; \ + done +install-pppd_pluginLTLIBRARIES: $(pppd_plugin_LTLIBRARIES) + @$(NORMAL_INSTALL) + test -z "$(pppd_plugindir)" || $(MKDIR_P) "$(DESTDIR)$(pppd_plugindir)" + @list='$(pppd_plugin_LTLIBRARIES)'; test -n "$(pppd_plugindir)" || list=; \ + list2=; for p in $$list; do \ + if test -f $$p; then \ + list2="$$list2 $$p"; \ + else :; fi; \ + done; \ + test -z "$$list2" || { \ + echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(pppd_plugindir)'"; \ + $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(pppd_plugindir)"; \ + } + +uninstall-pppd_pluginLTLIBRARIES: + @$(NORMAL_UNINSTALL) + @list='$(pppd_plugin_LTLIBRARIES)'; test -n "$(pppd_plugindir)" || list=; \ + for p in $$list; do \ + $(am__strip_dir) \ + echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(pppd_plugindir)/$$f'"; \ + $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(pppd_plugindir)/$$f"; \ + done + +clean-pppd_pluginLTLIBRARIES: + -test -z "$(pppd_plugin_LTLIBRARIES)" || rm -f $(pppd_plugin_LTLIBRARIES) + @list='$(pppd_plugin_LTLIBRARIES)'; for p in $$list; do \ + dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \ + test "$$dir" != "$$p" || dir=.; \ + echo "rm -f \"$${dir}/so_locations\""; \ + rm -f "$${dir}/so_locations"; \ + done +libppp-manager.la: $(libppp_manager_la_OBJECTS) $(libppp_manager_la_DEPENDENCIES) + $(LINK) $(libppp_manager_la_OBJECTS) $(libppp_manager_la_LIBADD) $(LIBS) +nm-pppd-plugin.la: $(nm_pppd_plugin_la_OBJECTS) $(nm_pppd_plugin_la_DEPENDENCIES) + $(nm_pppd_plugin_la_LINK) -rpath $(pppd_plugindir) $(nm_pppd_plugin_la_OBJECTS) $(nm_pppd_plugin_la_LIBADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libppp_manager_la-nm-ppp-manager.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nm_pppd_plugin_la-nm-pppd-plugin.Plo@am__quote@ + +.c.o: +@am__fastdepCC_TRUE@ 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 +@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@ $(COMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ `$(CYGPATH_W) '$<'` &&\ +@am__fastdepCC_TRUE@ $(am__mv) $$depbase.Tpo $$depbase.Po +@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@ $(LTCOMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\ +@am__fastdepCC_TRUE@ $(am__mv) $$depbase.Tpo $$depbase.Plo +@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 $@ $< + +libppp_manager_la-nm-ppp-manager.lo: nm-ppp-manager.c +@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libppp_manager_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libppp_manager_la-nm-ppp-manager.lo -MD -MP -MF $(DEPDIR)/libppp_manager_la-nm-ppp-manager.Tpo -c -o libppp_manager_la-nm-ppp-manager.lo `test -f 'nm-ppp-manager.c' || echo '$(srcdir)/'`nm-ppp-manager.c +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libppp_manager_la-nm-ppp-manager.Tpo $(DEPDIR)/libppp_manager_la-nm-ppp-manager.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='nm-ppp-manager.c' object='libppp_manager_la-nm-ppp-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) $(libppp_manager_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libppp_manager_la-nm-ppp-manager.lo `test -f 'nm-ppp-manager.c' || echo '$(srcdir)/'`nm-ppp-manager.c + +nm_pppd_plugin_la-nm-pppd-plugin.lo: nm-pppd-plugin.c +@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(nm_pppd_plugin_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT nm_pppd_plugin_la-nm-pppd-plugin.lo -MD -MP -MF $(DEPDIR)/nm_pppd_plugin_la-nm-pppd-plugin.Tpo -c -o nm_pppd_plugin_la-nm-pppd-plugin.lo `test -f 'nm-pppd-plugin.c' || echo '$(srcdir)/'`nm-pppd-plugin.c +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/nm_pppd_plugin_la-nm-pppd-plugin.Tpo $(DEPDIR)/nm_pppd_plugin_la-nm-pppd-plugin.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='nm-pppd-plugin.c' object='nm_pppd_plugin_la-nm-pppd-plugin.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) $(nm_pppd_plugin_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o nm_pppd_plugin_la-nm-pppd-plugin.lo `test -f 'nm-pppd-plugin.c' || echo '$(srcdir)/'`nm-pppd-plugin.c + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + mkid -fID $$unique +tags: TAGS + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + set x; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: CTAGS +CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d "$(distdir)/$$file"; then \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ + else \ + test -f "$(distdir)/$$file" \ + || cp -p $$d/$$file "$(distdir)/$$file" \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) check-am +all-am: Makefile $(LTLIBRARIES) +installdirs: + for dir in "$(DESTDIR)$(pppd_plugindir)"; do \ + test -z "$$dir" || $(MKDIR_P) "$$dir"; \ + done +install: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + -test -z "$(CLEANFILES)" || rm -f $(CLEANFILES) + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." + -test -z "$(BUILT_SOURCES)" || rm -f $(BUILT_SOURCES) +clean: clean-am + +clean-am: clean-generic clean-libtool clean-noinstLTLIBRARIES \ + clean-pppd_pluginLTLIBRARIES mostlyclean-am + +distclean: distclean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +install-data-am: install-pppd_pluginLTLIBRARIES + +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: + +install-html: install-html-am + +install-html-am: + +install-info: install-info-am + +install-info-am: + +install-man: + +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-pppd_pluginLTLIBRARIES + +.MAKE: all check install install-am install-strip + +.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ + clean-libtool clean-noinstLTLIBRARIES \ + clean-pppd_pluginLTLIBRARIES ctags distclean distclean-compile \ + distclean-generic distclean-libtool distclean-tags distdir dvi \ + dvi-am html html-am info info-am install install-am \ + install-data install-data-am install-dvi install-dvi-am \ + install-exec install-exec-am install-html install-html-am \ + install-info install-info-am install-man install-pdf \ + install-pdf-am install-pppd_pluginLTLIBRARIES install-ps \ + install-ps-am install-strip installcheck installcheck-am \ + installdirs maintainer-clean maintainer-clean-generic \ + mostlyclean mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool pdf pdf-am ps ps-am tags uninstall \ + uninstall-am uninstall-pppd_pluginLTLIBRARIES + + +nm-ppp-manager-glue.h: $(top_srcdir)/introspection/nm-ppp-manager.xml + dbus-binding-tool --prefix=nm_ppp_manager --mode=glib-server --output=$@ $< + +$(libppp_manager_la_OBJECTS): $(built_sources) + +# 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. +.NOEXPORT: diff --git a/src/ppp-manager/nm-ppp-manager.c b/src/ppp-manager/nm-ppp-manager.c new file mode 100644 index 00000000..148ad2cf --- /dev/null +++ b/src/ppp-manager/nm-ppp-manager.c @@ -0,0 +1,1058 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/* NetworkManager -- Network link manager + * + * 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., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Copyright (C) 2008 Novell, Inc. + * Copyright (C) 2008 - 2010 Red Hat, Inc. + */ + +#include <sys/types.h> +#include <sys/wait.h> +#include <signal.h> +#include <string.h> +#include <unistd.h> +#include <arpa/inet.h> +#include <stdlib.h> + +#include <errno.h> +#include <sys/socket.h> +#include <sys/ioctl.h> +#include <asm/types.h> +#include <net/if.h> +#include <sys/stat.h> + +#include <linux/ppp_defs.h> +#ifndef aligned_u64 +#define aligned_u64 unsigned long long __attribute__((aligned(8))) +#endif +#include <linux/if_ppp.h> + +#include "NetworkManager.h" +#include "nm-glib-compat.h" +#include "nm-ppp-manager.h" +#include "nm-setting-connection.h" +#include "nm-setting-ppp.h" +#include "nm-setting-pppoe.h" +#include "nm-setting-gsm.h" +#include "nm-setting-cdma.h" +#include "nm-dbus-manager.h" +#include "nm-logging.h" +#include "nm-marshal.h" + +static void impl_ppp_manager_need_secrets (NMPPPManager *manager, + DBusGMethodInvocation *context); + +static gboolean impl_ppp_manager_set_state (NMPPPManager *manager, + guint32 state, + GError **err); + +static gboolean impl_ppp_manager_set_ip4_config (NMPPPManager *manager, + GHashTable *config, + GError **err); + +#include "nm-ppp-manager-glue.h" + +#define NM_PPPD_PLUGIN PLUGINDIR "/nm-pppd-plugin.so" +#define PPP_MANAGER_SECRET_TRIES "ppp-manager-secret-tries" + +typedef struct { + GPid pid; + NMDBusManager *dbus_manager; + char *dbus_path; + + char *parent_iface; + + NMActRequest *act_req; + DBusGMethodInvocation *pending_secrets_context; + + guint32 ppp_watch_id; + guint32 ppp_timeout_handler; + + /* Monitoring */ + char *ip_iface; + int monitor_fd; + guint monitor_id; +} NMPPPManagerPrivate; + +#define NM_PPP_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_PPP_MANAGER, NMPPPManagerPrivate)) + +G_DEFINE_TYPE (NMPPPManager, nm_ppp_manager, G_TYPE_OBJECT) + +enum { + STATE_CHANGED, + IP4_CONFIG, + STATS, + + LAST_SIGNAL +}; + +static guint signals[LAST_SIGNAL] = { 0 }; + +enum { + PROP_0, + PROP_PARENT_IFACE, + LAST_PROP +}; + +typedef enum { + NM_PPP_MANAGER_ERROR_UNKOWN +} NMPPPManagerError; + +GQuark +nm_ppp_manager_error_quark (void) +{ + static GQuark quark; + + if (!quark) + quark = g_quark_from_static_string ("nm_ppp_manager_error"); + + return quark; +} + +static void +nm_ppp_manager_init (NMPPPManager *manager) +{ +} + +static GObject * +constructor (GType type, + guint n_construct_params, + GObjectConstructParam *construct_params) +{ + GObject *object; + NMPPPManagerPrivate *priv; + DBusGConnection *connection; + static guint32 counter = 0; + + object = G_OBJECT_CLASS (nm_ppp_manager_parent_class)->constructor (type, + n_construct_params, + construct_params); + if (!object) + return NULL; + + priv = NM_PPP_MANAGER_GET_PRIVATE (object); + priv->dbus_manager = nm_dbus_manager_get (); + if (!priv->dbus_manager) { + g_object_unref (object); + return NULL; + } + + connection = nm_dbus_manager_get_connection (priv->dbus_manager); + priv->dbus_path = g_strdup_printf (NM_DBUS_PATH "/PPP/%d", counter++); + dbus_g_connection_register_g_object (connection, priv->dbus_path, object); + + return object; +} + +static void +dispose (GObject *object) +{ + NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (object); + + nm_ppp_manager_stop (NM_PPP_MANAGER (object)); + + g_object_unref (priv->act_req); + g_object_unref (priv->dbus_manager); + + G_OBJECT_CLASS (nm_ppp_manager_parent_class)->dispose (object); +} + +static void +finalize (GObject *object) +{ + NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (object); + + g_free (priv->ip_iface); + g_free (priv->parent_iface); + + G_OBJECT_CLASS (nm_ppp_manager_parent_class)->finalize (object); +} + +static void +set_property (GObject *object, guint prop_id, + const GValue *value, GParamSpec *pspec) +{ + NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (object); + + switch (prop_id) { + case PROP_PARENT_IFACE: + if (priv->parent_iface) + g_free (priv->parent_iface); + priv->parent_iface = g_value_dup_string (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +get_property (GObject *object, guint prop_id, + GValue *value, GParamSpec *pspec) +{ + NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (object); + + switch (prop_id) { + case PROP_PARENT_IFACE: + g_value_set_string (value, priv->parent_iface); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +nm_ppp_manager_class_init (NMPPPManagerClass *manager_class) +{ + GObjectClass *object_class = G_OBJECT_CLASS (manager_class); + + g_type_class_add_private (manager_class, sizeof (NMPPPManagerPrivate)); + + object_class->constructor = constructor; + object_class->dispose = dispose; + object_class->finalize = finalize; + object_class->get_property = get_property; + object_class->set_property = set_property; + + /* Properties */ + g_object_class_install_property + (object_class, PROP_PARENT_IFACE, + g_param_spec_string (NM_PPP_MANAGER_PARENT_IFACE, + "ParentIface", + "Parent interface", + NULL, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); + + /* signals */ + signals[STATE_CHANGED] = + g_signal_new ("state-changed", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (NMPPPManagerClass, state_changed), + NULL, NULL, + g_cclosure_marshal_VOID__UINT, + G_TYPE_NONE, 1, + G_TYPE_UINT); + + signals[IP4_CONFIG] = + g_signal_new ("ip4-config", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (NMPPPManagerClass, ip4_config), + NULL, NULL, + _nm_marshal_VOID__STRING_OBJECT, + G_TYPE_NONE, 2, + G_TYPE_STRING, + G_TYPE_OBJECT); + + signals[STATS] = + g_signal_new ("stats", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (NMPPPManagerClass, stats), + NULL, NULL, + _nm_marshal_VOID__UINT_UINT, + G_TYPE_NONE, 2, + G_TYPE_UINT, G_TYPE_UINT); + + dbus_g_object_type_install_info (G_TYPE_FROM_CLASS (manager_class), + &dbus_glib_nm_ppp_manager_object_info); +} + +NMPPPManager * +nm_ppp_manager_new (const char *iface) +{ + g_return_val_if_fail (iface != NULL, NULL); + + return (NMPPPManager *) g_object_new (NM_TYPE_PPP_MANAGER, + NM_PPP_MANAGER_PARENT_IFACE, iface, + NULL); +} + +/*******************************************/ + +static gboolean +monitor_cb (gpointer user_data) +{ + NMPPPManager *manager = NM_PPP_MANAGER (user_data); + NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (manager); + struct ifpppstatsreq req; + + memset (&req, 0, sizeof (req)); + req.stats_ptr = (caddr_t) &req.stats; + + strncpy (req.ifr__name, priv->ip_iface, sizeof (req.ifr__name)); + if (ioctl (priv->monitor_fd, SIOCGPPPSTATS, &req) < 0) { + nm_log_warn (LOGD_PPP, "could not read ppp stats: %s", strerror (errno)); + } else { + g_signal_emit (manager, signals[STATS], 0, + req.stats.p.ppp_ibytes, + req.stats.p.ppp_obytes); + } + + return TRUE; +} + +static void +monitor_stats (NMPPPManager *manager) +{ + NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (manager); + + priv->monitor_fd = socket (AF_INET, SOCK_DGRAM, 0); + if (priv->monitor_fd > 0) + priv->monitor_id = g_timeout_add_seconds (5, monitor_cb, manager); + else + nm_log_warn (LOGD_PPP, "could not monitor PPP stats: %s", strerror (errno)); +} + +/*******************************************/ + +static void +remove_timeout_handler (NMPPPManager *manager) +{ + NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (manager); + + if (priv->ppp_timeout_handler) { + g_source_remove (priv->ppp_timeout_handler); + priv->ppp_timeout_handler = 0; + } +} + +static void +impl_ppp_manager_need_secrets (NMPPPManager *manager, + DBusGMethodInvocation *context) +{ + NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (manager); + NMConnection *connection; + NMSettingConnection *s_con; + const char *connection_type; + const char *setting_name; + guint32 tries; + GPtrArray *hints = NULL; + const char *hint1 = NULL, *hint2 = NULL; + + connection = nm_act_request_get_connection (priv->act_req); + + s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION)); + g_assert (s_con); + + connection_type = nm_setting_connection_get_connection_type (s_con); + g_assert (connection_type); + + nm_connection_clear_secrets (connection); + setting_name = nm_connection_need_secrets (connection, &hints); + if (!setting_name) { + NMSetting *setting; + + setting = nm_connection_get_setting_by_name (connection, connection_type); + if (setting) { + const char *username = NULL; + const char *password = NULL; + + /* FIXME: push this down to the settings and keep PPP manager generic */ + if (NM_IS_SETTING_PPPOE (setting)) { + username = nm_setting_pppoe_get_username (NM_SETTING_PPPOE (setting)); + password = nm_setting_pppoe_get_password (NM_SETTING_PPPOE (setting)); + } else if (NM_IS_SETTING_GSM (setting)) { + username = nm_setting_gsm_get_username (NM_SETTING_GSM (setting)); + password = nm_setting_gsm_get_password (NM_SETTING_GSM (setting)); + } else if (NM_IS_SETTING_CDMA (setting)) { + username = nm_setting_cdma_get_username (NM_SETTING_CDMA (setting)); + password = nm_setting_cdma_get_password (NM_SETTING_CDMA (setting)); + } + + /* If secrets are not required, send the existing username and password + * back to the PPP plugin immediately. + */ + priv->pending_secrets_context = context; + nm_ppp_manager_update_secrets (manager, + priv->parent_iface, + username ? username : "", + password ? password : "", + NULL); + } else { + GError *err = NULL; + + g_set_error (&err, NM_PPP_MANAGER_ERROR, NM_PPP_MANAGER_ERROR_UNKOWN, + "Missing type-specific setting; no secrets could be found."); + nm_log_warn (LOGD_PPP, "%s", err->message); + dbus_g_method_return_error (context, err); + } + return; + } + + /* Extract hints */ + if (hints) { + if (hints->len > 0) + hint1 = g_ptr_array_index (hints, 0); + if (hints->len > 1) + hint2 = g_ptr_array_index (hints, 1); + } + + tries = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (connection), PPP_MANAGER_SECRET_TRIES)); + /* Only ask for completely new secrets after retrying them once; some PPP + * servers (T-Mobile USA) appear to ask a few times when they actually don't + * even care what you pass back. + */ + nm_act_request_get_secrets (priv->act_req, + setting_name, + tries > 1 ? TRUE : FALSE, + SECRETS_CALLER_PPP, + hint1, + hint2); + g_object_set_data (G_OBJECT (connection), PPP_MANAGER_SECRET_TRIES, GUINT_TO_POINTER (++tries)); + priv->pending_secrets_context = context; + + if (hints) + g_ptr_array_free (hints, TRUE); +} + +static gboolean impl_ppp_manager_set_state (NMPPPManager *manager, + guint32 state, + GError **err) +{ + g_signal_emit (manager, signals[STATE_CHANGED], 0, state); + + return TRUE; +} + +static gboolean +impl_ppp_manager_set_ip4_config (NMPPPManager *manager, + GHashTable *config_hash, + GError **err) +{ + NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (manager); + NMConnection *connection; + NMSettingPPP *s_ppp; + NMIP4Config *config; + NMIP4Address *addr; + GValue *val; + int i; + + nm_log_info (LOGD_PPP, "PPP manager(IP Config Get) reply received."); + + remove_timeout_handler (manager); + + config = nm_ip4_config_new (); + addr = nm_ip4_address_new (); + nm_ip4_address_set_prefix (addr, 32); + + val = (GValue *) g_hash_table_lookup (config_hash, NM_PPP_IP4_CONFIG_GATEWAY); + if (val) { + nm_ip4_address_set_gateway (addr, g_value_get_uint (val)); + nm_ip4_config_set_ptp_address (config, g_value_get_uint (val)); + } + + val = (GValue *) g_hash_table_lookup (config_hash, NM_PPP_IP4_CONFIG_ADDRESS); + if (val) + nm_ip4_address_set_address (addr, g_value_get_uint (val)); + + val = (GValue *) g_hash_table_lookup (config_hash, NM_PPP_IP4_CONFIG_PREFIX); + if (val) + nm_ip4_address_set_prefix (addr, g_value_get_uint (val)); + + if (nm_ip4_address_get_address (addr) && nm_ip4_address_get_prefix (addr)) { + nm_ip4_config_take_address (config, addr); + } else { + nm_log_err (LOGD_PPP, "invalid IPv4 address received!"); + nm_ip4_address_unref (addr); + goto out; + } + + val = (GValue *) g_hash_table_lookup (config_hash, NM_PPP_IP4_CONFIG_DNS); + if (val) { + GArray *dns = (GArray *) g_value_get_boxed (val); + + for (i = 0; i < dns->len; i++) + nm_ip4_config_add_nameserver (config, g_array_index (dns, guint, i)); + } + + val = (GValue *) g_hash_table_lookup (config_hash, NM_PPP_IP4_CONFIG_WINS); + if (val) { + GArray *wins = (GArray *) g_value_get_boxed (val); + + for (i = 0; i < wins->len; i++) + nm_ip4_config_add_wins (config, g_array_index (wins, guint, i)); + } + + val = (GValue *) g_hash_table_lookup (config_hash, NM_PPP_IP4_CONFIG_INTERFACE); + if (!val || !G_VALUE_HOLDS_STRING (val)) { + nm_log_err (LOGD_PPP, "no interface received!"); + goto out; + } + priv->ip_iface = g_value_dup_string (val); + + /* Got successful IP4 config; obviously the secrets worked */ + connection = nm_act_request_get_connection (priv->act_req); + g_assert (connection); + g_object_set_data (G_OBJECT (connection), PPP_MANAGER_SECRET_TRIES, NULL); + + /* Merge in custom MTU */ + s_ppp = (NMSettingPPP *) nm_connection_get_setting (connection, NM_TYPE_SETTING_PPP); + if (s_ppp) { + guint32 mtu = nm_setting_ppp_get_mtu (s_ppp); + + if (mtu) + nm_ip4_config_set_mtu (config, mtu); + } + + /* Push the IP4 config up to the device */ + g_signal_emit (manager, signals[IP4_CONFIG], 0, priv->ip_iface, config); + + monitor_stats (manager); + + out: + g_object_unref (config); + + return TRUE; +} + +/*******************************************/ + + + +typedef struct { + GPtrArray *array; + GStringChunk *chunk; +} NMCmdLine; + +static NMCmdLine * +nm_cmd_line_new (void) +{ + NMCmdLine *cmd; + + cmd = g_slice_new (NMCmdLine); + cmd->array = g_ptr_array_new (); + cmd->chunk = g_string_chunk_new (1024); + + return cmd; +} + +static void +nm_cmd_line_destroy (NMCmdLine *cmd) +{ + g_ptr_array_free (cmd->array, TRUE); + g_string_chunk_free (cmd->chunk); + g_slice_free (NMCmdLine, cmd); +} + +static char * +nm_cmd_line_to_str (NMCmdLine *cmd) +{ + char *str; + + g_ptr_array_add (cmd->array, NULL); + str = g_strjoinv (" ", (gchar **) cmd->array->pdata); + g_ptr_array_remove_index (cmd->array, cmd->array->len - 1); + + return str; +} + +static void +nm_cmd_line_add_string (NMCmdLine *cmd, const char *str) +{ + g_ptr_array_add (cmd->array, g_string_chunk_insert (cmd->chunk, str)); +} + +static void +nm_cmd_line_add_int (NMCmdLine *cmd, int i) +{ + char *str; + + str = g_strdup_printf ("%d", i); + nm_cmd_line_add_string (cmd, str); + g_free (str); +} + +/*******************************************/ + +static inline const char * +nm_find_pppd (void) +{ + static const char *pppd_binary_paths[] = { + "/usr/local/sbin/pppd", + "/usr/sbin/pppd", + "/sbin/pppd", + NULL + }; + + const char **pppd_binary = pppd_binary_paths; + + while (*pppd_binary != NULL) { + if (g_file_test (*pppd_binary, G_FILE_TEST_EXISTS)) + break; + pppd_binary++; + } + + return *pppd_binary; +} + +static void +ppp_exit_code (guint pppd_exit_status, GPid pid) +{ + const char *msg; + + switch (pppd_exit_status) { + case 1: + msg = "Fatal pppd error"; + break; + case 2: + msg = "pppd options error"; + break; + case 3: + msg = "No root priv error"; + break; + case 4: + msg = "No ppp module error"; + break; + case 5: + msg = "pppd received a signal"; + break; + case 6: + msg = "Serial port lock failed"; + break; + case 7: + msg = "Serial port open failed"; + break; + case 8: + msg = "Connect script failed"; + break; + case 9: + msg = "Pty program error"; + break; + case 10: + msg = "PPP negotiation failed"; + break; + case 11: + msg = "Peer didn't authenticatie itself"; + break; + case 12: + msg = "Link idle: Idle Seconds reached."; + break; + case 13: + msg = "Connect time limit reached."; + break; + case 14: + msg = "Callback negotiated, call should come back."; + break; + case 15: + msg = "Lack of LCP echo responses"; + break; + case 16: + msg = "A modem hung up the phone"; + break; + case 17: + msg = "Loopback detected"; + break; + case 18: + msg = "The init script failed"; + break; + case 19: + msg = "Authentication error.\n" + "We failed to authenticate ourselves to the peer.\n" + "Maybe bad account or password?"; + break; + default: + msg = "Unknown error"; + } + + nm_log_warn (LOGD_PPP, "pppd pid %d exited with error: %s", pid, msg); +} + +static void +ppp_watch_cb (GPid pid, gint status, gpointer user_data) +{ + NMPPPManager *manager = NM_PPP_MANAGER (user_data); + NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (manager); + guint err; + + g_assert (pid == priv->pid); + + if (WIFEXITED (status)) { + err = WEXITSTATUS (status); + if (err != 0) + ppp_exit_code (err, priv->pid); + } else if (WIFSTOPPED (status)) { + nm_log_info (LOGD_PPP, "pppd pid %d stopped unexpectedly with signal %d", priv->pid, WSTOPSIG (status)); + } else if (WIFSIGNALED (status)) { + nm_log_info (LOGD_PPP, "pppd pid %d died with signal %d", priv->pid, WTERMSIG (status)); + } else + nm_log_info (LOGD_PPP, "pppd pid %d died from an unknown cause", priv->pid); + + nm_log_dbg (LOGD_PPP, "pppd pid %d cleaned up", priv->pid); + priv->pid = 0; + g_signal_emit (manager, signals[STATE_CHANGED], 0, NM_PPP_STATUS_DEAD); +} + +static gboolean +pppd_timed_out (gpointer data) +{ + NMPPPManager *manager = NM_PPP_MANAGER (data); + + nm_log_warn (LOGD_PPP, "pppd timed out or didn't initialize our dbus module"); + nm_ppp_manager_stop (manager); + + g_signal_emit (manager, signals[STATE_CHANGED], 0, NM_PPP_STATUS_DEAD); + + return FALSE; +} + +static NMCmdLine * +create_pppd_cmd_line (NMPPPManager *self, + NMSettingPPP *setting, + NMSettingPPPOE *pppoe, + const char *ppp_name, + GError **err) +{ + NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (self); + const char *ppp_binary; + NMCmdLine *cmd; + const char *ppp_debug; + + ppp_binary = nm_find_pppd (); + if (!ppp_binary) { + g_set_error (err, NM_PPP_MANAGER_ERROR, NM_PPP_MANAGER_ERROR, + "Could not find ppp binary."); + return NULL; + } + + /* Create pppd command line */ + cmd = nm_cmd_line_new (); + nm_cmd_line_add_string (cmd, ppp_binary); + + nm_cmd_line_add_string (cmd, "nodetach"); + nm_cmd_line_add_string (cmd, "lock"); + + /* NM handles setting the default route */ + nm_cmd_line_add_string (cmd, "nodefaultroute"); + + ppp_debug = getenv ("NM_PPP_DEBUG"); + if (ppp_debug) + nm_cmd_line_add_string (cmd, "debug"); + + if (ppp_name) { + nm_cmd_line_add_string (cmd, "user"); + nm_cmd_line_add_string (cmd, ppp_name); + } + + if (pppoe) { + char *dev_str; + const char *pppoe_service; + + nm_cmd_line_add_string (cmd, "plugin"); + nm_cmd_line_add_string (cmd, "rp-pppoe.so"); + + dev_str = g_strdup_printf ("nic-%s", priv->parent_iface); + nm_cmd_line_add_string (cmd, dev_str); + g_free (dev_str); + + pppoe_service = nm_setting_pppoe_get_service (pppoe); + if (pppoe_service) { + nm_cmd_line_add_string (cmd, "rp_pppoe_service"); + nm_cmd_line_add_string (cmd, pppoe_service); + } + } else { + nm_cmd_line_add_string (cmd, priv->parent_iface); + /* Don't send some random address as the local address */ + nm_cmd_line_add_string (cmd, "noipdefault"); + } + + if (nm_setting_ppp_get_baud (setting)) + nm_cmd_line_add_int (cmd, nm_setting_ppp_get_baud (setting)); + + /* noauth by default, because we certainly don't have any information + * with which to verify anything the peer gives us if we ask it to + * authenticate itself, which is what 'auth' really means. + */ + nm_cmd_line_add_string (cmd, "noauth"); + + if (nm_setting_ppp_get_refuse_eap (setting)) + nm_cmd_line_add_string (cmd, "refuse-eap"); + if (nm_setting_ppp_get_refuse_pap (setting)) + nm_cmd_line_add_string (cmd, "refuse-pap"); + if (nm_setting_ppp_get_refuse_chap (setting)) + nm_cmd_line_add_string (cmd, "refuse-chap"); + if (nm_setting_ppp_get_refuse_mschap (setting)) + nm_cmd_line_add_string (cmd, "refuse-mschap"); + if (nm_setting_ppp_get_refuse_mschapv2 (setting)) + nm_cmd_line_add_string (cmd, "refuse-mschap-v2"); + if (nm_setting_ppp_get_nobsdcomp (setting)) + nm_cmd_line_add_string (cmd, "nobsdcomp"); + if (nm_setting_ppp_get_nodeflate (setting)) + nm_cmd_line_add_string (cmd, "nodeflate"); + if (nm_setting_ppp_get_require_mppe (setting)) + nm_cmd_line_add_string (cmd, "require-mppe"); + if (nm_setting_ppp_get_require_mppe_128 (setting)) + nm_cmd_line_add_string (cmd, "require-mppe-128"); + if (nm_setting_ppp_get_mppe_stateful (setting)) + nm_cmd_line_add_string (cmd, "mppe-stateful"); + if (nm_setting_ppp_get_crtscts (setting)) + nm_cmd_line_add_string (cmd, "crtscts"); + + /* Always ask for DNS, we don't have to use them if the connection + * overrides the returned servers. + */ + nm_cmd_line_add_string (cmd, "usepeerdns"); + + if (nm_setting_ppp_get_mru (setting)) { + nm_cmd_line_add_string (cmd, "mru"); + nm_cmd_line_add_int (cmd, nm_setting_ppp_get_mru (setting)); + } + + if (nm_setting_ppp_get_mtu (setting)) { + nm_cmd_line_add_string (cmd, "mtu"); + nm_cmd_line_add_int (cmd, nm_setting_ppp_get_mtu (setting)); + } + + nm_cmd_line_add_string (cmd, "lcp-echo-failure"); + nm_cmd_line_add_int (cmd, nm_setting_ppp_get_lcp_echo_failure (setting)); + + nm_cmd_line_add_string (cmd, "lcp-echo-interval"); + nm_cmd_line_add_int (cmd, nm_setting_ppp_get_lcp_echo_interval (setting)); + + nm_cmd_line_add_string (cmd, "ipparam"); + nm_cmd_line_add_string (cmd, priv->dbus_path); + + nm_cmd_line_add_string (cmd, "plugin"); + nm_cmd_line_add_string (cmd, NM_PPPD_PLUGIN); + + return cmd; +} + +static void +pppd_child_setup (gpointer user_data G_GNUC_UNUSED) +{ + /* We are in the child process at this point */ + pid_t pid = getpid (); + setpgid (pid, pid); +} + +static void +pppoe_fill_defaults (NMSettingPPP *setting) +{ + if (!nm_setting_ppp_get_mtu (setting)) + g_object_set (setting, NM_SETTING_PPP_MTU, (guint32) 1492, NULL); + + if (!nm_setting_ppp_get_mru (setting)) + g_object_set (setting, NM_SETTING_PPP_MRU, (guint32) 1492, NULL); + + if (!nm_setting_ppp_get_lcp_echo_interval (setting)) + g_object_set (setting, NM_SETTING_PPP_LCP_ECHO_INTERVAL, (guint32) 20, NULL); + + if (!nm_setting_ppp_get_lcp_echo_failure (setting)) + g_object_set (setting, NM_SETTING_PPP_LCP_ECHO_FAILURE, (guint32) 3, NULL); + + g_object_set (setting, + NM_SETTING_PPP_NOAUTH, TRUE, + NM_SETTING_PPP_NODEFLATE, TRUE, + NULL); + + /* FIXME: These commented settings should be set as well, update NMSettingPPP first. */ +#if 0 + setting->noipdefault = TRUE; + setting->default_asyncmap = TRUE; + setting->defaultroute = TRUE; + setting->hide_password = TRUE; + setting->noaccomp = TRUE; + setting->nopcomp = TRUE; + setting->novj = TRUE; + setting->novjccomp = TRUE; +#endif +} + +gboolean +nm_ppp_manager_start (NMPPPManager *manager, + NMActRequest *req, + const char *ppp_name, + guint32 timeout_secs, + GError **err) +{ + NMPPPManagerPrivate *priv; + NMConnection *connection; + NMSettingPPP *s_ppp; + gboolean s_ppp_created = FALSE; + NMSettingPPPOE *pppoe_setting; + NMCmdLine *ppp_cmd; + char *cmd_str; + struct stat st; + int ignored; + + g_return_val_if_fail (NM_IS_PPP_MANAGER (manager), FALSE); + g_return_val_if_fail (NM_IS_ACT_REQUEST (req), FALSE); + + priv = NM_PPP_MANAGER_GET_PRIVATE (manager); + + priv->pid = 0; + + /* Make sure /dev/ppp exists (bgo #533064) */ + if (stat ("/dev/ppp", &st) || !S_ISCHR (st.st_mode)) + ignored = system ("/sbin/modprobe ppp_generic"); + + connection = nm_act_request_get_connection (req); + g_assert (connection); + + s_ppp = (NMSettingPPP *) nm_connection_get_setting (connection, NM_TYPE_SETTING_PPP); + if (!s_ppp) { + /* If the PPP settings are all default we may not have a PPP setting yet, + * so just make a default one here. + */ + s_ppp = NM_SETTING_PPP (nm_setting_ppp_new ()); + s_ppp_created = TRUE; + } + + pppoe_setting = (NMSettingPPPOE *) nm_connection_get_setting (connection, NM_TYPE_SETTING_PPPOE); + if (pppoe_setting) + pppoe_fill_defaults (s_ppp); + + ppp_cmd = create_pppd_cmd_line (manager, s_ppp, pppoe_setting, ppp_name, err); + if (!ppp_cmd) + goto out; + + g_ptr_array_add (ppp_cmd->array, NULL); + + nm_log_info (LOGD_PPP, "starting PPP connection"); + + cmd_str = nm_cmd_line_to_str (ppp_cmd); + nm_log_dbg (LOGD_PPP, "command line: %s", cmd_str); + g_free (cmd_str); + + priv->pid = 0; + if (!g_spawn_async (NULL, (char **) ppp_cmd->array->pdata, NULL, + G_SPAWN_DO_NOT_REAP_CHILD, + pppd_child_setup, + NULL, &priv->pid, err)) { + goto out; + } + + nm_log_info (LOGD_PPP, "pppd started with pid %d", priv->pid); + + priv->ppp_watch_id = g_child_watch_add (priv->pid, (GChildWatchFunc) ppp_watch_cb, manager); + priv->ppp_timeout_handler = g_timeout_add_seconds (timeout_secs, pppd_timed_out, manager); + priv->act_req = g_object_ref (req); + + out: + if (s_ppp_created) + g_object_unref (s_ppp); + + if (ppp_cmd) + nm_cmd_line_destroy (ppp_cmd); + + return priv->pid > 0; +} + +void +nm_ppp_manager_update_secrets (NMPPPManager *manager, + const char *device, + const char *username, + const char *password, + const char *error_message) +{ + NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (manager); + + g_return_if_fail (NM_IS_PPP_MANAGER (manager)); + g_return_if_fail (device != NULL); + g_return_if_fail (priv->pending_secrets_context != NULL); + + if (error_message) { + g_return_if_fail (username == NULL); + g_return_if_fail (password == NULL); + } else { + g_return_if_fail (username != NULL); + g_return_if_fail (password != NULL); + } + + if (error_message) { + GError *err = NULL; + + g_set_error (&err, NM_PPP_MANAGER_ERROR, NM_PPP_MANAGER_ERROR_UNKOWN, "%s", error_message); + nm_log_warn (LOGD_PPP, "%s", error_message); + dbus_g_method_return_error (priv->pending_secrets_context, err); + g_error_free (err); + } else { + /* This is sort of a hack but... + pppd plugin only ever needs username and password. + Passing the full connection there would mean some bloat: + the plugin would need to link against libnm-util just to parse this. + So instead, let's just send what it needs */ + + dbus_g_method_return (priv->pending_secrets_context, username, password); + } + priv->pending_secrets_context = NULL; +} + +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_PPP, "waiting for pppd pid %d to exit", pid); + waitpid (pid, NULL, 0); + nm_log_dbg (LOGD_PPP, "pppd pid %d cleaned up", pid); + + return FALSE; +} + +void +nm_ppp_manager_stop (NMPPPManager *manager) +{ + NMPPPManagerPrivate *priv; + + g_return_if_fail (NM_IS_PPP_MANAGER (manager)); + + priv = NM_PPP_MANAGER_GET_PRIVATE (manager); + + if (priv->monitor_id) { + g_source_remove (priv->monitor_id); + priv->monitor_id = 0; + } + + if (priv->monitor_fd) { + /* Get the stats one last time */ + monitor_cb (manager); + close (priv->monitor_fd); + priv->monitor_fd = 0; + } + + if (priv->ppp_timeout_handler) { + g_source_remove (priv->ppp_timeout_handler); + priv->ppp_timeout_handler = 0; + } + + if (priv->ppp_watch_id) { + g_source_remove (priv->ppp_watch_id); + priv->ppp_watch_id = 0; + } + + 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_PPP, "waiting for pppd pid %d to exit", priv->pid); + waitpid (priv->pid, NULL, 0); + nm_log_dbg (LOGD_PPP, "pppd pid %d cleaned up", priv->pid); + } + + priv->pid = 0; + } +} diff --git a/src/ppp-manager/nm-ppp-manager.h b/src/ppp-manager/nm-ppp-manager.h new file mode 100644 index 00000000..a0200973 --- /dev/null +++ b/src/ppp-manager/nm-ppp-manager.h @@ -0,0 +1,80 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/* NetworkManager -- Network link manager + * + * 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., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Copyright (C) 2008 Novell, Inc. + * Copyright (C) 2008 Red Hat, Inc. + */ + +#ifndef NM_PPP_MANAGER_H +#define NM_PPP_MANAGER_H + +#include <glib.h> +#include <glib-object.h> + +#include "nm-ppp-status.h" +#include "nm-activation-request.h" +#include "nm-connection.h" +#include "nm-ip4-config.h" +#include "nm-pppd-plugin.h" + +#define NM_TYPE_PPP_MANAGER (nm_ppp_manager_get_type ()) +#define NM_PPP_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_PPP_MANAGER, NMPPPManager)) +#define NM_PPP_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_PPP_MANAGER, NMPPPManagerClass)) +#define NM_IS_PPP_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_PPP_MANAGER)) +#define NM_IS_PPP_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), NM_TYPE_PPP_MANAGER)) +#define NM_PPP_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_PPP_MANAGER, NMPPPManagerClass)) + +#define NM_PPP_MANAGER_PARENT_IFACE "parent-iface" + +typedef struct { + GObject parent; +} NMPPPManager; + +typedef struct { + GObjectClass parent; + + /* Signals */ + void (*state_changed) (NMPPPManager *manager, NMPPPStatus status); + void (*ip4_config) (NMPPPManager *manager, const char *iface, NMIP4Config *config); + void (*stats) (NMPPPManager *manager, guint32 in_bytes, guint32 out_bytes); +} NMPPPManagerClass; + +GType nm_ppp_manager_get_type (void); + +NMPPPManager *nm_ppp_manager_new (const char *iface); + +gboolean nm_ppp_manager_start (NMPPPManager *manager, + NMActRequest *req, + const char *ppp_name, + guint32 timeout_secs, + GError **err); + +void nm_ppp_manager_update_secrets (NMPPPManager *manager, + const char *device, + const char *username, + const char *password, + const char *error_message); + +void nm_ppp_manager_stop (NMPPPManager *manager); + + +#define NM_PPP_MANAGER_ERROR nm_ppp_manager_error_quark() +#define NM_TYPE_PPP_MANAGER_ERROR (nm_ppp_manager_error_get_type ()) + +GQuark nm_ppp_manager_error_quark (void); + +#endif /* NM_PPP_MANAGER_H */ diff --git a/src/ppp-manager/nm-ppp-status.h b/src/ppp-manager/nm-ppp-status.h new file mode 100644 index 00000000..cfc7c393 --- /dev/null +++ b/src/ppp-manager/nm-ppp-status.h @@ -0,0 +1,43 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/* NetworkManager -- Network link manager + * + * 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., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Copyright (C) 2008 Novell, Inc. + * Copyright (C) 2008 Red Hat, Inc. + */ + +#ifndef NM_PPP_STATUS_H +#define NM_PPP_STATUS_H + +typedef enum { + NM_PPP_STATUS_UNKNOWN, + + NM_PPP_STATUS_DEAD, + NM_PPP_STATUS_INITIALIZE, + NM_PPP_STATUS_SERIALCONN, + NM_PPP_STATUS_DORMANT, + NM_PPP_STATUS_ESTABLISH, + NM_PPP_STATUS_AUTHENTICATE, + NM_PPP_STATUS_CALLBACK, + NM_PPP_STATUS_NETWORK, + NM_PPP_STATUS_RUNNING, + NM_PPP_STATUS_TERMINATE, + NM_PPP_STATUS_DISCONNECT, + NM_PPP_STATUS_HOLDOFF, + NM_PPP_STATUS_MASTER +} NMPPPStatus; + +#endif /* NM_PPP_STATUS_H */ diff --git a/src/ppp-manager/nm-pppd-plugin.c b/src/ppp-manager/nm-pppd-plugin.c new file mode 100644 index 00000000..c64bb87f --- /dev/null +++ b/src/ppp-manager/nm-pppd-plugin.c @@ -0,0 +1,359 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/* NetworkManager -- Network link manager + * + * 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., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Copyright (C) 2008 Novell, Inc. + * Copyright (C) 2008 Red Hat, Inc. + */ + +#include <string.h> +#include <pppd/pppd.h> +#include <pppd/fsm.h> +#include <pppd/ipcp.h> +#include <sys/socket.h> +#include <netinet/in.h> +#include <arpa/inet.h> +#include <glib.h> +#include <glib-object.h> +#include <dbus/dbus-glib.h> + +#include "NetworkManager.h" +#include "nm-pppd-plugin.h" +#include "nm-ppp-status.h" +#include "nm-dbus-glib-types.h" + +int plugin_init (void); + +char pppd_version[] = VERSION; + +static DBusGProxy *proxy = NULL; + +static void +nm_phasechange (void *data, int arg) +{ + NMPPPStatus ppp_status = NM_PPP_STATUS_UNKNOWN; + char *ppp_phase; + + g_return_if_fail (DBUS_IS_G_PROXY (proxy)); + + switch (arg) { + case PHASE_DEAD: + ppp_status = NM_PPP_STATUS_DEAD; + ppp_phase = "dead"; + break; + case PHASE_INITIALIZE: + ppp_status = NM_PPP_STATUS_INITIALIZE; + ppp_phase = "initialize"; + break; + case PHASE_SERIALCONN: + ppp_status = NM_PPP_STATUS_SERIALCONN; + ppp_phase = "serial connection"; + break; + case PHASE_DORMANT: + ppp_status = NM_PPP_STATUS_DORMANT; + ppp_phase = "dormant"; + break; + case PHASE_ESTABLISH: + ppp_status = NM_PPP_STATUS_ESTABLISH; + ppp_phase = "establish"; + break; + case PHASE_AUTHENTICATE: + ppp_status = NM_PPP_STATUS_AUTHENTICATE; + ppp_phase = "authenticate"; + break; + case PHASE_CALLBACK: + ppp_status = NM_PPP_STATUS_CALLBACK; + ppp_phase = "callback"; + break; + case PHASE_NETWORK: + ppp_status = NM_PPP_STATUS_NETWORK; + ppp_phase = "network"; + break; + case PHASE_RUNNING: + ppp_status = NM_PPP_STATUS_RUNNING; + ppp_phase = "running"; + break; + case PHASE_TERMINATE: + ppp_status = NM_PPP_STATUS_TERMINATE; + ppp_phase = "terminate"; + break; + case PHASE_DISCONNECT: + ppp_status = NM_PPP_STATUS_DISCONNECT; + ppp_phase = "disconnect"; + break; + case PHASE_HOLDOFF: + ppp_status = NM_PPP_STATUS_HOLDOFF; + ppp_phase = "holdoff"; + break; + case PHASE_MASTER: + ppp_status = NM_PPP_STATUS_MASTER; + ppp_phase = "master"; + break; + + default: + ppp_phase = "unknown"; + break; + } + + g_message ("nm-ppp-plugin: (%s): status %d / phase '%s'", + __func__, + ppp_status, + ppp_phase); + + if (ppp_status != NM_PPP_STATUS_UNKNOWN) { + dbus_g_proxy_call_no_reply (proxy, "SetState", + G_TYPE_UINT, ppp_status, G_TYPE_INVALID, + G_TYPE_INVALID); + } +} + +static GValue * +str_to_gvalue (const char *str) +{ + GValue *val; + + val = g_slice_new0 (GValue); + g_value_init (val, G_TYPE_STRING); + g_value_set_string (val, str); + + return val; +} + +static GValue * +uint_to_gvalue (guint32 i) +{ + GValue *val; + + val = g_slice_new0 (GValue); + g_value_init (val, G_TYPE_UINT); + g_value_set_uint (val, i); + + return val; +} + +static void +value_destroy (gpointer data) +{ + GValue *val = (GValue *) data; + + g_value_unset (val); + g_slice_free (GValue, val); +} + +static void +nm_ip_up (void *data, int arg) +{ + ipcp_options opts = ipcp_gotoptions[0]; + ipcp_options peer_opts = ipcp_hisoptions[0]; + GHashTable *hash; + GArray *array; + GValue *val; + guint32 pppd_made_up_address = htonl (0x0a404040 + ifunit); + + g_return_if_fail (DBUS_IS_G_PROXY (proxy)); + + g_message ("nm-ppp-plugin: (%s): ip-up event", __func__); + + if (!opts.ouraddr) { + g_warning ("nm-ppp-plugin: (%s): didn't receive an internal IP from pppd!", __func__); + nm_phasechange (NULL, PHASE_DEAD); + return; + } + + hash = g_hash_table_new_full (g_str_hash, g_str_equal, + NULL, value_destroy); + + g_hash_table_insert (hash, NM_PPP_IP4_CONFIG_INTERFACE, + str_to_gvalue (ifname)); + + g_hash_table_insert (hash, NM_PPP_IP4_CONFIG_ADDRESS, + uint_to_gvalue (opts.ouraddr)); + + /* Prefer the peer options remote address first, _unless_ pppd made the + * address up, at which point prefer the local options remote address, + * and if that's not right, use the made-up address as a last resort. + */ + if (peer_opts.hisaddr && (peer_opts.hisaddr != pppd_made_up_address)) { + g_hash_table_insert (hash, NM_PPP_IP4_CONFIG_GATEWAY, + uint_to_gvalue (peer_opts.hisaddr)); + } else if (opts.hisaddr) { + g_hash_table_insert (hash, NM_PPP_IP4_CONFIG_GATEWAY, + uint_to_gvalue (opts.hisaddr)); + } else if (peer_opts.hisaddr == pppd_made_up_address) { + /* As a last resort, use the made-up address */ + g_hash_table_insert (hash, NM_PPP_IP4_CONFIG_GATEWAY, + uint_to_gvalue (peer_opts.hisaddr)); + } + + g_hash_table_insert (hash, NM_PPP_IP4_CONFIG_PREFIX, uint_to_gvalue (32)); + + if (opts.dnsaddr[0] || opts.dnsaddr[1]) { + array = g_array_new (FALSE, FALSE, sizeof (guint32)); + + if (opts.dnsaddr[0]) + g_array_append_val (array, opts.dnsaddr[0]); + if (opts.dnsaddr[1]) + g_array_append_val (array, opts.dnsaddr[1]); + + val = g_slice_new0 (GValue); + g_value_init (val, DBUS_TYPE_G_UINT_ARRAY); + g_value_set_boxed (val, array); + + g_hash_table_insert (hash, NM_PPP_IP4_CONFIG_DNS, val); + } + + if (opts.winsaddr[0] || opts.winsaddr[1]) { + array = g_array_new (FALSE, FALSE, sizeof (guint32)); + + if (opts.winsaddr[0]) + g_array_append_val (array, opts.winsaddr[0]); + if (opts.winsaddr[1]) + g_array_append_val (array, opts.winsaddr[1]); + + val = g_slice_new0 (GValue); + g_value_init (val, DBUS_TYPE_G_UINT_ARRAY); + g_value_set_boxed (val, array); + + g_hash_table_insert (hash, NM_PPP_IP4_CONFIG_WINS, val); + } + + g_message ("nm-ppp-plugin: (%s): sending Ip4Config to NetworkManager...", __func__); + + dbus_g_proxy_call_no_reply (proxy, "SetIp4Config", + DBUS_TYPE_G_MAP_OF_VARIANT, hash, G_TYPE_INVALID, + G_TYPE_INVALID); + + g_hash_table_destroy (hash); +} + +static int +get_chap_check() +{ + return 1; +} + +static int +get_pap_check() +{ + return 1; +} + +static int +get_credentials (char *username, char *password) +{ + char *my_username = NULL; + char *my_password = NULL; + size_t len; + GError *err = NULL; + + if (username && !password) { + /* pppd is checking pap support; return 1 for supported */ + return 1; + } + + g_return_val_if_fail (DBUS_IS_G_PROXY (proxy), -1); + + g_message ("nm-ppp-plugin: (%s): passwd-hook, requesting credentials...", __func__); + + dbus_g_proxy_call (proxy, "NeedSecrets", &err, + G_TYPE_INVALID, + G_TYPE_STRING, &my_username, + G_TYPE_STRING, &my_password, + G_TYPE_INVALID); + + if (err) { + g_warning ("nm-ppp-plugin: (%s): could not get secrets: (%d) %s", + __func__, + err ? err->code : -1, + err->message ? err->message : "(unknown)"); + g_error_free (err); + return -1; + } + + g_message ("nm-ppp-plugin: (%s): got credentials from NetworkManager", __func__); + + if (my_username) { + len = strlen (my_username) + 1; + len = len < MAXNAMELEN ? len : MAXNAMELEN; + + strncpy (username, my_username, len); + username[len - 1] = '\0'; + + g_free (my_username); + } + + if (my_password) { + len = strlen (my_password) + 1; + len = len < MAXSECRETLEN ? len : MAXSECRETLEN; + + strncpy (password, my_password, len); + password[len - 1] = '\0'; + + g_free (my_password); + } + + return 1; +} + +static void +nm_exit_notify (void *data, int arg) +{ + g_return_if_fail (DBUS_IS_G_PROXY (proxy)); + + g_message ("nm-ppp-plugin: (%s): cleaning up", __func__); + + g_object_unref (proxy); + proxy = NULL; +} + +int +plugin_init (void) +{ + DBusGConnection *bus; + GError *err = NULL; + + g_type_init (); + + g_message ("nm-ppp-plugin: (%s): initializing", __func__); + + bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &err); + if (!bus) { + g_warning ("nm-pppd-plugin: (%s): couldn't connect to system bus: (%d) %s", + __func__, + err ? err->code : -1, + err && err->message ? err->message : "(unknown)"); + g_error_free (err); + return -1; + } + + /* NM passes in the object path of the corresponding PPPManager + * object as the 'ipparam' argument to pppd. + */ + proxy = dbus_g_proxy_new_for_name (bus, NM_DBUS_SERVICE, ipparam, NM_DBUS_INTERFACE_PPP); + + dbus_g_connection_unref (bus); + + chap_passwd_hook = get_credentials; + chap_check_hook = get_chap_check; + pap_passwd_hook = get_credentials; + pap_check_hook = get_pap_check; + + add_notifier (&phasechange, nm_phasechange, NULL); + add_notifier (&ip_up_notifier, nm_ip_up, NULL); + add_notifier (&exitnotify, nm_exit_notify, proxy); + + return 0; +} diff --git a/src/ppp-manager/nm-pppd-plugin.h b/src/ppp-manager/nm-pppd-plugin.h new file mode 100644 index 00000000..95a2a182 --- /dev/null +++ b/src/ppp-manager/nm-pppd-plugin.h @@ -0,0 +1,29 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/* NetworkManager -- Network link manager + * + * 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., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Copyright (C) 2008 Novell, Inc. + * Copyright (C) 2008 Red Hat, Inc. + */ + +#define NM_DBUS_INTERFACE_PPP "org.freedesktop.NetworkManager.PPP" + +#define NM_PPP_IP4_CONFIG_INTERFACE "interface" +#define NM_PPP_IP4_CONFIG_ADDRESS "address" +#define NM_PPP_IP4_CONFIG_PREFIX "prefix" +#define NM_PPP_IP4_CONFIG_GATEWAY "gateway" +#define NM_PPP_IP4_CONFIG_DNS "dns" +#define NM_PPP_IP4_CONFIG_WINS "wins" |