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 /system-settings/plugins/ifupdown | |
Imported Upstream version 0.8.1 upstream/0.8.1
Diffstat (limited to 'system-settings/plugins/ifupdown')
| -rw-r--r-- | system-settings/plugins/ifupdown/Makefile.am | 34 | ||||
| -rw-r--r-- | system-settings/plugins/ifupdown/Makefile.in | 657 | ||||
| -rw-r--r-- | system-settings/plugins/ifupdown/interface_parser.c | 215 | ||||
| -rw-r--r-- | system-settings/plugins/ifupdown/interface_parser.h | 57 | ||||
| -rw-r--r-- | system-settings/plugins/ifupdown/nm-ifupdown-connection.c | 187 | ||||
| -rw-r--r-- | system-settings/plugins/ifupdown/nm-ifupdown-connection.h | 55 | ||||
| -rw-r--r-- | system-settings/plugins/ifupdown/parser.c | 577 | ||||
| -rw-r--r-- | system-settings/plugins/ifupdown/parser.h | 34 | ||||
| -rw-r--r-- | system-settings/plugins/ifupdown/plugin.c | 681 | ||||
| -rw-r--r-- | system-settings/plugins/ifupdown/plugin.h | 53 |
10 files changed, 2550 insertions, 0 deletions
diff --git a/system-settings/plugins/ifupdown/Makefile.am b/system-settings/plugins/ifupdown/Makefile.am new file mode 100644 index 00000000..ec503115 --- /dev/null +++ b/system-settings/plugins/ifupdown/Makefile.am @@ -0,0 +1,34 @@ + +INCLUDES = \ + -I$(top_srcdir)/src/system-settings \ + -I$(top_srcdir)/include \ + -I$(top_srcdir)/libnm-glib \ + -I$(top_srcdir)/libnm-util + +pkglib_LTLIBRARIES = libnm-settings-plugin-ifupdown.la + +libnm_settings_plugin_ifupdown_la_SOURCES = \ + interface_parser.c \ + interface_parser.h \ + nm-ifupdown-connection.c \ + nm-ifupdown-connection.h \ + parser.c \ + parser.h \ + plugin.c \ + plugin.h + +libnm_settings_plugin_ifupdown_la_CPPFLAGS = \ + $(GLIB_CFLAGS) \ + $(GMODULE_CFLAGS) \ + $(DBUS_CFLAGS) \ + $(GUDEV_CFLAGS) \ + -DG_DISABLE_DEPRECATED \ + -DSYSCONFDIR=\"$(sysconfdir)\" + +libnm_settings_plugin_ifupdown_la_LDFLAGS = -module -avoid-version +libnm_settings_plugin_ifupdown_la_LIBADD = \ + $(top_builddir)/libnm-util/libnm-util.la \ + $(GLIB_LIBS) \ + $(GMODULE_LIBS) \ + $(GUDEV_LIBS) + diff --git a/system-settings/plugins/ifupdown/Makefile.in b/system-settings/plugins/ifupdown/Makefile.in new file mode 100644 index 00000000..6c3a6ae7 --- /dev/null +++ b/system-settings/plugins/ifupdown/Makefile.in @@ -0,0 +1,657 @@ +# 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 = system-settings/plugins/ifupdown +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)$(pkglibdir)" +LTLIBRARIES = $(pkglib_LTLIBRARIES) +am__DEPENDENCIES_1 = +libnm_settings_plugin_ifupdown_la_DEPENDENCIES = \ + $(top_builddir)/libnm-util/libnm-util.la $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) +am_libnm_settings_plugin_ifupdown_la_OBJECTS = \ + libnm_settings_plugin_ifupdown_la-interface_parser.lo \ + libnm_settings_plugin_ifupdown_la-nm-ifupdown-connection.lo \ + libnm_settings_plugin_ifupdown_la-parser.lo \ + libnm_settings_plugin_ifupdown_la-plugin.lo +libnm_settings_plugin_ifupdown_la_OBJECTS = \ + $(am_libnm_settings_plugin_ifupdown_la_OBJECTS) +libnm_settings_plugin_ifupdown_la_LINK = $(LIBTOOL) --tag=CC \ + $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \ + $(AM_CFLAGS) $(CFLAGS) \ + $(libnm_settings_plugin_ifupdown_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 = $(libnm_settings_plugin_ifupdown_la_SOURCES) +DIST_SOURCES = $(libnm_settings_plugin_ifupdown_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)/src/system-settings \ + -I$(top_srcdir)/include \ + -I$(top_srcdir)/libnm-glib \ + -I$(top_srcdir)/libnm-util + +pkglib_LTLIBRARIES = libnm-settings-plugin-ifupdown.la +libnm_settings_plugin_ifupdown_la_SOURCES = \ + interface_parser.c \ + interface_parser.h \ + nm-ifupdown-connection.c \ + nm-ifupdown-connection.h \ + parser.c \ + parser.h \ + plugin.c \ + plugin.h + +libnm_settings_plugin_ifupdown_la_CPPFLAGS = \ + $(GLIB_CFLAGS) \ + $(GMODULE_CFLAGS) \ + $(DBUS_CFLAGS) \ + $(GUDEV_CFLAGS) \ + -DG_DISABLE_DEPRECATED \ + -DSYSCONFDIR=\"$(sysconfdir)\" + +libnm_settings_plugin_ifupdown_la_LDFLAGS = -module -avoid-version +libnm_settings_plugin_ifupdown_la_LIBADD = \ + $(top_builddir)/libnm-util/libnm-util.la \ + $(GLIB_LIBS) \ + $(GMODULE_LIBS) \ + $(GUDEV_LIBS) + +all: 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 system-settings/plugins/ifupdown/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --gnu system-settings/plugins/ifupdown/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): +install-pkglibLTLIBRARIES: $(pkglib_LTLIBRARIES) + @$(NORMAL_INSTALL) + test -z "$(pkglibdir)" || $(MKDIR_P) "$(DESTDIR)$(pkglibdir)" + @list='$(pkglib_LTLIBRARIES)'; test -n "$(pkglibdir)" || 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)$(pkglibdir)'"; \ + $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(pkglibdir)"; \ + } + +uninstall-pkglibLTLIBRARIES: + @$(NORMAL_UNINSTALL) + @list='$(pkglib_LTLIBRARIES)'; test -n "$(pkglibdir)" || list=; \ + for p in $$list; do \ + $(am__strip_dir) \ + echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(pkglibdir)/$$f'"; \ + $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(pkglibdir)/$$f"; \ + done + +clean-pkglibLTLIBRARIES: + -test -z "$(pkglib_LTLIBRARIES)" || rm -f $(pkglib_LTLIBRARIES) + @list='$(pkglib_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 +libnm-settings-plugin-ifupdown.la: $(libnm_settings_plugin_ifupdown_la_OBJECTS) $(libnm_settings_plugin_ifupdown_la_DEPENDENCIES) + $(libnm_settings_plugin_ifupdown_la_LINK) -rpath $(pkglibdir) $(libnm_settings_plugin_ifupdown_la_OBJECTS) $(libnm_settings_plugin_ifupdown_la_LIBADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libnm_settings_plugin_ifupdown_la-interface_parser.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libnm_settings_plugin_ifupdown_la-nm-ifupdown-connection.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libnm_settings_plugin_ifupdown_la-parser.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libnm_settings_plugin_ifupdown_la-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 $@ $< + +libnm_settings_plugin_ifupdown_la-interface_parser.lo: interface_parser.c +@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libnm_settings_plugin_ifupdown_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libnm_settings_plugin_ifupdown_la-interface_parser.lo -MD -MP -MF $(DEPDIR)/libnm_settings_plugin_ifupdown_la-interface_parser.Tpo -c -o libnm_settings_plugin_ifupdown_la-interface_parser.lo `test -f 'interface_parser.c' || echo '$(srcdir)/'`interface_parser.c +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libnm_settings_plugin_ifupdown_la-interface_parser.Tpo $(DEPDIR)/libnm_settings_plugin_ifupdown_la-interface_parser.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='interface_parser.c' object='libnm_settings_plugin_ifupdown_la-interface_parser.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) $(libnm_settings_plugin_ifupdown_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libnm_settings_plugin_ifupdown_la-interface_parser.lo `test -f 'interface_parser.c' || echo '$(srcdir)/'`interface_parser.c + +libnm_settings_plugin_ifupdown_la-nm-ifupdown-connection.lo: nm-ifupdown-connection.c +@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libnm_settings_plugin_ifupdown_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libnm_settings_plugin_ifupdown_la-nm-ifupdown-connection.lo -MD -MP -MF $(DEPDIR)/libnm_settings_plugin_ifupdown_la-nm-ifupdown-connection.Tpo -c -o libnm_settings_plugin_ifupdown_la-nm-ifupdown-connection.lo `test -f 'nm-ifupdown-connection.c' || echo '$(srcdir)/'`nm-ifupdown-connection.c +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libnm_settings_plugin_ifupdown_la-nm-ifupdown-connection.Tpo $(DEPDIR)/libnm_settings_plugin_ifupdown_la-nm-ifupdown-connection.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='nm-ifupdown-connection.c' object='libnm_settings_plugin_ifupdown_la-nm-ifupdown-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) $(libnm_settings_plugin_ifupdown_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libnm_settings_plugin_ifupdown_la-nm-ifupdown-connection.lo `test -f 'nm-ifupdown-connection.c' || echo '$(srcdir)/'`nm-ifupdown-connection.c + +libnm_settings_plugin_ifupdown_la-parser.lo: parser.c +@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libnm_settings_plugin_ifupdown_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libnm_settings_plugin_ifupdown_la-parser.lo -MD -MP -MF $(DEPDIR)/libnm_settings_plugin_ifupdown_la-parser.Tpo -c -o libnm_settings_plugin_ifupdown_la-parser.lo `test -f 'parser.c' || echo '$(srcdir)/'`parser.c +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libnm_settings_plugin_ifupdown_la-parser.Tpo $(DEPDIR)/libnm_settings_plugin_ifupdown_la-parser.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='parser.c' object='libnm_settings_plugin_ifupdown_la-parser.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) $(libnm_settings_plugin_ifupdown_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libnm_settings_plugin_ifupdown_la-parser.lo `test -f 'parser.c' || echo '$(srcdir)/'`parser.c + +libnm_settings_plugin_ifupdown_la-plugin.lo: plugin.c +@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libnm_settings_plugin_ifupdown_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libnm_settings_plugin_ifupdown_la-plugin.lo -MD -MP -MF $(DEPDIR)/libnm_settings_plugin_ifupdown_la-plugin.Tpo -c -o libnm_settings_plugin_ifupdown_la-plugin.lo `test -f 'plugin.c' || echo '$(srcdir)/'`plugin.c +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libnm_settings_plugin_ifupdown_la-plugin.Tpo $(DEPDIR)/libnm_settings_plugin_ifupdown_la-plugin.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='plugin.c' object='libnm_settings_plugin_ifupdown_la-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) $(libnm_settings_plugin_ifupdown_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libnm_settings_plugin_ifupdown_la-plugin.lo `test -f 'plugin.c' || echo '$(srcdir)/'`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: check-am +all-am: Makefile $(LTLIBRARIES) +installdirs: + for dir in "$(DESTDIR)$(pkglibdir)"; do \ + test -z "$$dir" || $(MKDIR_P) "$$dir"; \ + done +install: 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: + +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." +clean: clean-am + +clean-am: clean-generic clean-libtool clean-pkglibLTLIBRARIES \ + 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-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: install-pkglibLTLIBRARIES + +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-pkglibLTLIBRARIES + +.MAKE: install-am install-strip + +.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ + clean-libtool clean-pkglibLTLIBRARIES 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-pkglibLTLIBRARIES \ + 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-pkglibLTLIBRARIES + + +# 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/system-settings/plugins/ifupdown/interface_parser.c b/system-settings/plugins/ifupdown/interface_parser.c new file mode 100644 index 00000000..f28cf7ca --- /dev/null +++ b/system-settings/plugins/ifupdown/interface_parser.c @@ -0,0 +1,215 @@ +/* -*- Mode: C; tab-width: 5; indent-tabs-mode: t; c-basic-offset: 5 -*- */ +/* NetworkManager -- Network link manager + * + * Tom Parker <palfrey@tevp.net> + * + * 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. + * + * (C) Copyright 2004 Tom Parker + */ + + +#include "interface_parser.h" +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include "nm-utils.h" + +if_block* first; +if_block* last; + +if_data* last_data; + +void add_block(const char *type, const char* name) +{ + if_block *ret = (if_block*)calloc(1,sizeof(struct _if_block)); + ret->name = g_strdup(name); + ret->type = g_strdup(type); + if (first == NULL) + first = last = ret; + else + { + last->next = ret; + last = ret; + } + last_data = NULL; + //printf("added block '%s' with type '%s'\n",name,type); +} + +void add_data(const char *key,const char *data) +{ + if_data *ret; + + // Check if there is a block where we can attach our data + if (first == NULL) + return; + + ret = (if_data*) calloc(1,sizeof(struct _if_data)); + ret->key = g_strdup(key); + ret->data = g_strdup(data); + + if (last->info == NULL) + { + last->info = ret; + last_data = ret; + } + else + { + last_data->next = ret; + last_data = last_data->next; + } + //printf("added data '%s' with key '%s'\n",data,key); +} + +#define SPACE_OR_TAB(string,ret) {ret = strchr(string,' ');ret=(ret == NULL?strchr(string,'\t'):ret);} + +void ifparser_init(void) +{ + FILE *inp = fopen(ENI_INTERFACES_FILE, "r"); + int ret = 0; + char *line; + char *space; + char rline[255]; + + if (inp == NULL) + { + nm_warning ("Error: Can't open %s\n", ENI_INTERFACES_FILE); + return; + } + first = last = NULL; + while(1) + { + line = space = NULL; + ret = fscanf(inp,"%255[^\n]\n",rline); + if (ret == EOF) + break; + // If the line did not match, skip it + if (ret == 0) { + char *ignored; + + ignored = fgets(rline, 255, inp); + continue; + } + + line = rline; + while(line[0] == ' ') + line++; + if (line[0]=='#' || line[0]=='\0') + continue; + + SPACE_OR_TAB(line,space) + if (space == NULL) + { + nm_warning ("Error: Can't parse interface line '%s'\n",line); + continue; + } + space[0] = '\0'; + + // There are four different stanzas: + // iface, mapping, auto and allow-*. Create a block for each of them. + if (strcmp(line,"iface")==0) + { + char *space2 = strchr(space+1,' '); + if (space2 == NULL) + { + nm_warning ("Error: Can't parse iface line '%s'\n",space+1); + continue; + } + space2[0]='\0'; + add_block(line,space+1); + + if (space2[1]!='\0') + { + space = strchr(space2+1,' '); + if (space == NULL) + { + nm_warning ("Error: Can't parse data '%s'\n",space2+1); + continue; + } + space[0] = '\0'; + add_data(space2+1,space+1); + } + } + else if (strcmp(line,"auto")==0) + add_block(line,space+1); + else if (strcmp(line,"mapping")==0) + add_block(line,space+1); + else if (strncmp(line,"allow-",6)==0) + add_block(line,space+1); + else + add_data(line,space+1); + + //printf("line: '%s' ret=%d\n",rline,ret); + } + fclose(inp); +} + +void _destroy_data(if_data *ifd) +{ + if (ifd == NULL) + return; + _destroy_data(ifd->next); + free(ifd->key); + free(ifd->data); + free(ifd); + return; +} + +void _destroy_block(if_block* ifb) +{ + if (ifb == NULL) + return; + _destroy_block(ifb->next); + _destroy_data(ifb->info); + free(ifb->name); + free(ifb->type); + free(ifb); + return; +} + +void ifparser_destroy(void) +{ + _destroy_block(first); + first = last = NULL; +} + +if_block *ifparser_getfirst(void) +{ + return first; +} + +if_block *ifparser_getif(const char* iface) +{ + if_block *curr = first; + while(curr!=NULL) + { + if (strcmp(curr->type,"iface")==0 && strcmp(curr->name,iface)==0) + return curr; + curr = curr->next; + } + return NULL; +} + +const char *ifparser_getkey(if_block* iface, const char *key) +{ + if_data *curr = iface->info; + while(curr!=NULL) + { + if (strcmp(curr->key,key)==0) + return curr->data; + curr = curr->next; + } + return NULL; +} diff --git a/system-settings/plugins/ifupdown/interface_parser.h b/system-settings/plugins/ifupdown/interface_parser.h new file mode 100644 index 00000000..52b98d04 --- /dev/null +++ b/system-settings/plugins/ifupdown/interface_parser.h @@ -0,0 +1,57 @@ +/* -*- Mode: C; tab-width: 5; indent-tabs-mode: t; c-basic-offset: 5 -*- */ +/* NetworkManager -- Network link manager + * + * Tom Parker <palfrey@tevp.net> + * + * 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. + * + * (C) Copyright 2004 Tom Parker + */ + + +#ifndef _INTERFACE_PARSER_H +#define _INTERFACE_PARSER_H + +#include "config.h" + +#define ENI_INTERFACES_FILE "/etc/network/interfaces" + +typedef struct _if_data +{ + char *key; + char *data; + struct _if_data *next; +} if_data; + +typedef struct _if_block +{ + char *type; + char *name; + if_data *info; + struct _if_block *next; +} if_block; + +void ifparser_init(void); +void ifparser_destroy(void); + +if_block *ifparser_getif(const char* iface); +if_block *ifparser_getfirst(void); +const char *ifparser_getkey(if_block* iface, const char *key); + +void add_block(const char *type, const char* name); +void add_data(const char *key,const char *data); +void _destroy_data(if_data *ifd); +void _destroy_block(if_block* ifb); +#endif diff --git a/system-settings/plugins/ifupdown/nm-ifupdown-connection.c b/system-settings/plugins/ifupdown/nm-ifupdown-connection.c new file mode 100644 index 00000000..ad9a479a --- /dev/null +++ b/system-settings/plugins/ifupdown/nm-ifupdown-connection.c @@ -0,0 +1,187 @@ +/* -*- Mode: C; tab-width: 5; indent-tabs-mode: t; c-basic-offset: 5 -*- */ + +/* NetworkManager system settings service (ifupdown) + * + * Alexander Sack <asac@ubuntu.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * (C) Copyright 2007,2008 Canonical Ltd. + */ + +#include <string.h> +#include <glib/gstdio.h> +#include <NetworkManager.h> +#include <nm-utils.h> +#include <nm-setting-wireless-security.h> +#include <nm-sysconfig-connection.h> +#include <nm-system-config-interface.h> +#include <nm-system-config-error.h> +#include "nm-ifupdown-connection.h" +#include "parser.h" + +G_DEFINE_TYPE (NMIfupdownConnection, nm_ifupdown_connection, NM_TYPE_SYSCONFIG_CONNECTION) + +#define NM_IFUPDOWN_CONNECTION_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_IFUPDOWN_CONNECTION, NMIfupdownConnectionPrivate)) + +typedef struct { + if_block *ifblock; +} NMIfupdownConnectionPrivate; + +enum { + PROP_ZERO, + PROP_IFBLOCK, + _PROP_END, +}; + + +NMIfupdownConnection* +nm_ifupdown_connection_new (if_block *block) +{ + g_return_val_if_fail (block != NULL, NULL); + + return (NMIfupdownConnection *) g_object_new (NM_TYPE_IFUPDOWN_CONNECTION, + NM_IFUPDOWN_CONNECTION_IFBLOCK, block, + NULL); +} + +static void +get_secrets (NMExportedConnection *exported, + const gchar *setting_name, + const gchar **hints, + gboolean request_new, + DBusGMethodInvocation *context) +{ + GError *error = NULL; + + PLUGIN_PRINT ("SCPlugin-Ifupdown", "get_secrets() for setting_name:'%s'", setting_name); + + /* FIXME: Only wifi secrets are supported for now */ + if (strcmp (setting_name, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME)) { + g_set_error (&error, + NM_SYSCONFIG_SETTINGS_ERROR, + NM_SYSCONFIG_SETTINGS_ERROR_GENERAL, + "%s.%d - security setting name not supported '%s'.", + __FILE__, __LINE__, setting_name); + PLUGIN_PRINT ("SCPlugin-Ifupdown", "%s", error->message); + dbus_g_method_return_error (context, error); + g_error_free (error); + return; + } + + NM_EXPORTED_CONNECTION_CLASS (nm_ifupdown_connection_parent_class)->get_secrets (exported, setting_name, hints, request_new, context); +} + +static void +nm_ifupdown_connection_init (NMIfupdownConnection *connection) +{ +} + +static GObject * +constructor (GType type, + guint n_construct_params, + GObjectConstructParam *construct_params) +{ + GObject *object; + NMIfupdownConnectionPrivate *priv; + GError *error = NULL; + + object = G_OBJECT_CLASS (nm_ifupdown_connection_parent_class)->constructor (type, n_construct_params, construct_params); + g_return_val_if_fail (object, NULL); + + priv = NM_IFUPDOWN_CONNECTION_GET_PRIVATE (object); + if (!priv) { + g_warning ("%s.%d - no private instance.", __FILE__, __LINE__); + goto err; + } + if (!priv->ifblock) { + g_warning ("(ifupdown) ifblock not provided to constructor."); + goto err; + } + + if (!ifupdown_update_connection_from_if_block (NM_CONNECTION (object), priv->ifblock, &error)) { + g_warning ("%s.%d - invalid connection read from /etc/network/interfaces: (%d) %s", + __FILE__, + __LINE__, + error ? error->code : -1, + error && error->message ? error->message : "(unknown)"); + goto err; + } + + return object; + + err: + g_object_unref (object); + return NULL; +} + +static void +set_property (GObject *object, guint prop_id, + const GValue *value, GParamSpec *pspec) +{ + NMIfupdownConnectionPrivate *priv = NM_IFUPDOWN_CONNECTION_GET_PRIVATE (object); + g_return_if_fail (priv); + + switch (prop_id) { + case PROP_IFBLOCK: + priv->ifblock = g_value_get_pointer (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) +{ + NMIfupdownConnectionPrivate *priv = NM_IFUPDOWN_CONNECTION_GET_PRIVATE (object); + g_return_if_fail (priv); + + switch (prop_id) { + case PROP_IFBLOCK: + g_value_set_pointer (value, priv->ifblock); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +nm_ifupdown_connection_class_init (NMIfupdownConnectionClass *ifupdown_connection_class) +{ + GObjectClass *object_class = G_OBJECT_CLASS (ifupdown_connection_class); + NMExportedConnectionClass *connection_class = NM_EXPORTED_CONNECTION_CLASS (ifupdown_connection_class); + + g_type_class_add_private (ifupdown_connection_class, sizeof (NMIfupdownConnectionPrivate)); + + /* Virtual methods */ + object_class->constructor = constructor; + object_class->set_property = set_property; + object_class->get_property = get_property; + + connection_class->get_secrets = get_secrets; + + /* Properties */ + g_object_class_install_property + (object_class, PROP_IFBLOCK, + g_param_spec_pointer (NM_IFUPDOWN_CONNECTION_IFBLOCK, + "ifblock", + "", + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); +} + diff --git a/system-settings/plugins/ifupdown/nm-ifupdown-connection.h b/system-settings/plugins/ifupdown/nm-ifupdown-connection.h new file mode 100644 index 00000000..4eb20e50 --- /dev/null +++ b/system-settings/plugins/ifupdown/nm-ifupdown-connection.h @@ -0,0 +1,55 @@ +/* -*- Mode: C; tab-width: 5; indent-tabs-mode: t; c-basic-offset: 5 -*- */ + +/* NetworkManager system settings service (ifupdown) + * + * Alexander Sack <asac@ubuntu.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * (C) Copyright 2008 Canonical Ltd. + */ + +#ifndef NM_IFUPDOWN_CONNECTION_H +#define NM_IFUPDOWN_CONNECTION_H + +#include <nm-sysconfig-connection.h> +#include "interface_parser.h" + +G_BEGIN_DECLS + +#define NM_TYPE_IFUPDOWN_CONNECTION (nm_ifupdown_connection_get_type ()) +#define NM_IFUPDOWN_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_IFUPDOWN_CONNECTION, NMIfupdownConnection)) +#define NM_IFUPDOWN_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_IFUPDOWN_CONNECTION, NMIfupdownConnectionClass)) +#define NM_IS_IFUPDOWN_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_IFUPDOWN_CONNECTION)) +#define NM_IS_IFUPDOWN_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), NM_TYPE_IFUPDOWN_CONNECTION)) +#define NM_IFUPDOWN_CONNECTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_IFUPDOWN_CONNECTION, NMIfupdownConnectionClass)) + +#define NM_IFUPDOWN_CONNECTION_IFBLOCK "ifblock" + +typedef struct { + NMExportedConnection parent; +} NMIfupdownConnection; + +typedef struct { + NMExportedConnectionClass parent; +} NMIfupdownConnectionClass; + +GType nm_ifupdown_connection_get_type (void); + +NMIfupdownConnection *nm_ifupdown_connection_new (if_block *block); + +G_END_DECLS + +#endif /* NM_IFUPDOWN_CONNECTION_H */ diff --git a/system-settings/plugins/ifupdown/parser.c b/system-settings/plugins/ifupdown/parser.c new file mode 100644 index 00000000..dc2f8abf --- /dev/null +++ b/system-settings/plugins/ifupdown/parser.c @@ -0,0 +1,577 @@ +/* -*- Mode: C; tab-width: 5; indent-tabs-mode: t; c-basic-offset: 5 -*- */ + +/* NetworkManager system settings service (ifupdown) + * + * Alexander Sack <asac@ubuntu.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * (C) Copyright 2008 Canonical Ltd. + */ + +#include <string.h> +#include <arpa/inet.h> +#include <stdlib.h> +#include <errno.h> + +#include <nm-connection.h> +#include <NetworkManager.h> +#include <nm-setting-connection.h> +#include <nm-setting-ip4-config.h> +#include <nm-setting-ppp.h> +#include <nm-setting-wired.h> +#include <nm-setting-wireless.h> +#include <nm-setting-8021x.h> +#include <nm-system-config-interface.h> +#include <nm-utils.h> + +#include "parser.h" +#include "plugin.h" + + +#define WPA_PMK_LEN 32 + +#include "parser.h" + +static const gchar* +_ifupdownplugin_guess_connection_type (if_block *block) +{ + if_data *curr = block->info; + const gchar* ret_type = NULL; + const gchar* value = ifparser_getkey(block, "inet"); + if(value && !strcmp("ppp", value)) { + ret_type = NM_SETTING_PPP_SETTING_NAME; + } + + while(!ret_type && curr) { + if(!strncmp("wireless-", curr->key, strlen("wireless-")) || + !strncmp("wpa-", curr->key, strlen("wpa-"))) { + ret_type = NM_SETTING_WIRELESS_SETTING_NAME; + } + curr = curr->next; + } + + if(!ret_type) + ret_type = NM_SETTING_WIRED_SETTING_NAME; + + PLUGIN_PRINT("SCPluginIfupdown", + "guessed connection type (%s) = %s", + block->name, ret_type); + return ret_type; +} + + +struct _Mapping { + const gchar *domain; + const gpointer target; +}; + +static gpointer +map_by_mapping(struct _Mapping *mapping, const gchar *key) +{ + struct _Mapping *curr = mapping; + while(curr->domain) { + if(!strcmp(curr->domain, key)) + return curr->target; + curr++; + } + return NULL; +} + +static void +update_wireless_setting_from_if_block(NMConnection *connection, + if_block *block) +{ + gint wpa_l= strlen("wpa-"); + gint wireless_l= strlen("wireless-"); + + if_data *curr = block->info; + const gchar* value = ifparser_getkey (block, "inet"); + struct _Mapping mapping[] = { + {"ssid", "ssid"}, + { NULL, NULL} + }; + + NMSettingWireless *wireless_setting = NULL; + + if(value && !strcmp("ppp", value)) { + return; + } + + PLUGIN_PRINT ("SCPlugin-Ifupdown", "update wireless settings (%s).", block->name); + wireless_setting = NM_SETTING_WIRELESS(nm_setting_wireless_new()); + + while(curr) { + if(strlen(curr->key) > wireless_l && + !strncmp("wireless-", curr->key, wireless_l)) { + const gchar* newkey = map_by_mapping(mapping, curr->key+wireless_l); + PLUGIN_PRINT ("SCPlugin-Ifupdown", "wireless setting key: %s='%s'", + newkey, curr->data); + if(newkey && !strcmp("ssid", newkey)) { + GByteArray *ssid; + gint len = strlen(curr->data); + + ssid = g_byte_array_sized_new (len); + g_byte_array_append (ssid, (const guint8 *) curr->data, len); + g_object_set (wireless_setting, NM_SETTING_WIRELESS_SSID, ssid, NULL); + g_byte_array_free (ssid, TRUE); + PLUGIN_PRINT("SCPlugin-Ifupdown", "setting wireless ssid = %d", len); + } else { + g_object_set(wireless_setting, + newkey, curr->data, + NULL); + } + } else if(strlen(curr->key) > wpa_l && + !strncmp("wpa-", curr->key, wpa_l)) { + const gchar* newkey = map_by_mapping(mapping, curr->key+wpa_l); + + if(newkey && !strcmp("ssid", newkey)) { + GByteArray *ssid; + gint len = strlen(curr->data); + + ssid = g_byte_array_sized_new (len); + g_byte_array_append (ssid, (const guint8 *) curr->data, len); + g_object_set (wireless_setting, NM_SETTING_WIRELESS_SSID, ssid, NULL); + g_byte_array_free (ssid, TRUE); + PLUGIN_PRINT("SCPlugin-Ifupdown", "setting wpa ssid = %d", len); + } else if(newkey) { + + g_object_set(wireless_setting, + newkey, curr->data, + NULL); + PLUGIN_PRINT ("SCPlugin-Ifupdown", "setting wpa newkey(%s)=data(%s)", newkey, curr->data); + } + } + curr = curr->next; + } + nm_connection_add_setting(connection, (NMSetting*) wireless_setting); +} + +typedef gchar* (*IfupdownStrDupeFunc) (gpointer value, gpointer data); +typedef gpointer (*IfupdownStrToTypeFunc) (const gchar* value); + +static char* +normalize_dupe_wireless_key (gpointer value, gpointer data) { + char* valuec = value; + char* endc = valuec + strlen (valuec); + char* delim = valuec; + char* next = delim; + char* result = malloc (strlen (valuec) + 1); + char* result_cur = result; + + while (*delim && (next = strchr (delim, '-')) != NULL) { + if (next == delim) { + delim++; + continue; + } + strncpy (result_cur, delim, next - delim); + result_cur += next - delim; + delim = next + 1; + } + if (*delim && strlen (valuec) > GPOINTER_TO_UINT(delim - valuec)) { + strncpy (result_cur, delim, endc - delim); + result_cur += endc - delim; + } + *result_cur = '\0'; + return result; +} + +static char* +normalize_dupe (gpointer value, gpointer data) { + return g_strdup(value); +} + +static char* +normalize_tolower (gpointer value, gpointer data) { + return g_ascii_strdown(value, -1); +} + +static char *normalize_psk (gpointer value, gpointer data) +{ + if (strlen (value) >= 8 && strlen (value) <= 64) + return g_strdup (value); + return NULL; +} + +static gpointer +string_to_gpointerint(const gchar* data) +{ + gint result = (gint) strtol (data, NULL, 10); + return GINT_TO_POINTER(result); +} + +static gpointer +string_to_glist_of_strings(const gchar* data) +{ + GSList *ret = NULL; + gchar *string = (gchar*) data; + while(string) { + gchar* next = NULL; + if( (next = strchr(string, ' ')) || + (next = strchr(string, '\t')) || + (next = strchr(string, '\0')) ) { + + gchar *part = g_strndup(string, (next - string)); + ret = g_slist_append(ret, part); + if (*next) + string = next+1; + else + string = NULL; + } else { + string = NULL; + } + } + return ret; +} + +static void +slist_free_all(gpointer slist) +{ + GSList *list = (GSList *) slist; + g_slist_foreach (list, (GFunc) g_free, NULL); + g_slist_free (list); +} + +static void +update_wireless_security_setting_from_if_block(NMConnection *connection, + if_block *block) +{ + gint wpa_l= strlen("wpa-"); + gint wireless_l= strlen("wireless-"); + if_data *curr = block->info; + const gchar* value = ifparser_getkey (block, "inet"); + struct _Mapping mapping[] = { + {"psk", "psk"}, + {"identity", "leap-username"}, + {"password", "leap-password"}, + {"key", "wep-key0"}, + {"key-mgmt", "key-mgmt"}, + {"group", "group"}, + {"pairwise", "pairwise"}, + {"proto", "proto"}, + {"pin", "pin"}, + {"wep-key0", "wep-key0"}, + {"wep-key1", "wep-key1"}, + {"wep-key2", "wep-key2"}, + {"wep-key3", "wep-key3"}, + {"wep-tx-keyidx", "wep-tx-keyidx"}, + { NULL, NULL} + }; + + struct _Mapping dupe_mapping[] = { + {"psk", normalize_psk}, + {"identity", normalize_dupe}, + {"password", normalize_dupe}, + {"key", normalize_dupe_wireless_key}, + {"key-mgmt", normalize_tolower}, + {"group", normalize_tolower}, + {"pairwise", normalize_tolower}, + {"proto", normalize_tolower}, + {"pin", normalize_dupe}, + {"wep-key0", normalize_dupe_wireless_key}, + {"wep-key1", normalize_dupe_wireless_key}, + {"wep-key2", normalize_dupe_wireless_key}, + {"wep-key3", normalize_dupe_wireless_key}, + {"wep-tx-keyidx", normalize_dupe}, + { NULL, NULL} + }; + + struct _Mapping type_mapping[] = { + {"group", string_to_glist_of_strings}, + {"pairwise", string_to_glist_of_strings}, + {"proto", string_to_glist_of_strings}, + {"wep-tx-keyidx", string_to_gpointerint}, + { NULL, NULL} + }; + + struct _Mapping free_type_mapping[] = { + {"group", slist_free_all}, + {"pairwise", slist_free_all}, + {"proto", slist_free_all}, + { NULL, NULL} + }; + + NMSettingWirelessSecurity *wireless_security_setting; + NMSettingWireless *s_wireless; + gboolean security = FALSE; + + if(value && !strcmp("ppp", value)) { + return; + } + + s_wireless = NM_SETTING_WIRELESS(nm_connection_get_setting(connection, + NM_TYPE_SETTING_WIRELESS)); + g_return_if_fail(s_wireless); + + PLUGIN_PRINT ("SCPlugin-Ifupdown","update wireless security settings (%s).", block->name); + wireless_security_setting = + NM_SETTING_WIRELESS_SECURITY(nm_setting_wireless_security_new()); + + while(curr) { + if(strlen(curr->key) > wireless_l && + !strncmp("wireless-", curr->key, wireless_l)) { + + gchar *property_value = NULL; + gpointer typed_property_value = NULL; + const gchar* newkey = map_by_mapping(mapping, curr->key+wireless_l); + IfupdownStrDupeFunc dupe_func = map_by_mapping (dupe_mapping, curr->key+wireless_l); + IfupdownStrToTypeFunc type_map_func = map_by_mapping (type_mapping, curr->key+wireless_l); + GFreeFunc free_func = map_by_mapping (free_type_mapping, curr->key+wireless_l); + if(!newkey || !dupe_func) { + g_warning("no (wireless) mapping found for key: %s", curr->key); + goto next; + } + property_value = (*dupe_func) (curr->data, connection); + PLUGIN_PRINT ("SCPlugin-Ifupdown", "setting wireless security key: %s=%s", + newkey, property_value); + + if (type_map_func) { + errno = 0; + typed_property_value = (*type_map_func) (property_value); + if(errno) + goto wireless_next; + } + + g_object_set(wireless_security_setting, + newkey, typed_property_value ? typed_property_value : property_value, + NULL); + security = TRUE; + + wireless_next: + g_free(property_value); + if (typed_property_value && free_func) + (*free_func) (typed_property_value); + + } else if(strlen(curr->key) > wpa_l && + !strncmp("wpa-", curr->key, wpa_l)) { + + gchar *property_value = NULL; + gpointer typed_property_value = NULL; + const gchar* newkey = map_by_mapping(mapping, curr->key+wpa_l); + IfupdownStrDupeFunc dupe_func = map_by_mapping (dupe_mapping, curr->key+wpa_l); + IfupdownStrToTypeFunc type_map_func = map_by_mapping (type_mapping, curr->key+wpa_l); + GFreeFunc free_func = map_by_mapping (free_type_mapping, curr->key+wpa_l); + if(!newkey || !dupe_func) { + goto next; + } + property_value = (*dupe_func) (curr->data, connection); + PLUGIN_PRINT ("SCPlugin-Ifupdown", "setting wpa security key: %s=%s", + newkey, +#ifdef DEBUG_SECRETS + property_value +#else // DEBUG_SECRETS + !strcmp("key", newkey) || + !strcmp("leap-password", newkey) || + !strcmp("pin", newkey) || + !strcmp("psk", newkey) || + !strcmp("wep-key0", newkey) || + !strcmp("wep-key1", newkey) || + !strcmp("wep-key2", newkey) || + !strcmp("wep-key3", newkey) || + NULL ? + "<omitted>" : property_value +#endif // DEBUG_SECRETS + ); + + if (type_map_func) { + errno = 0; + typed_property_value = (*type_map_func) (property_value); + if(errno) + goto wpa_next; + } + + g_object_set(wireless_security_setting, + newkey, typed_property_value ? typed_property_value : property_value, + NULL); + security = TRUE; + + wpa_next: + g_free(property_value); + if (free_func && typed_property_value) + (*free_func) (typed_property_value); + } + next: + curr = curr->next; + } + + + if(security) { + nm_connection_add_setting(connection, NM_SETTING(wireless_security_setting)); + g_object_set(s_wireless, NM_SETTING_WIRELESS_SEC, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, NULL); + } + +} + +static void +update_wired_setting_from_if_block(NMConnection *connection, + if_block *block) +{ + NMSettingWired *s_wired = NULL; + s_wired = NM_SETTING_WIRED(nm_setting_wired_new()); + nm_connection_add_setting(connection, NM_SETTING(s_wired)); +} + +static GQuark +eni_plugin_error_quark() { + static GQuark error_quark = 0; + + if(!error_quark) { + error_quark = g_quark_from_static_string ("eni-plugin-error-quark"); + } + + return error_quark; +} + + +static void +update_ip4_setting_from_if_block(NMConnection *connection, + if_block *block) +{ + + NMSettingIP4Config *ip4_setting = NM_SETTING_IP4_CONFIG (nm_setting_ip4_config_new()); + const char *type = ifparser_getkey(block, "inet"); + gboolean is_static = type && !strcmp("static", type); + + if(!is_static) { + g_object_set(ip4_setting, + NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, + NULL); + } else { + struct in_addr tmp_ip4_addr; + NMIP4Address *ip4_addr = nm_ip4_address_new (); + + const char *address_v = ifparser_getkey(block, "address"); + const char *netmask_v = ifparser_getkey(block, "netmask"); + const char *gateway_v = ifparser_getkey(block, "gateway"); + const char *nameserver_v = ifparser_getkey(block, "dns-nameserver"); + const char *nameservers_v = ifparser_getkey(block, "dns-nameservers"); + GSList* nameservers_list = NULL; + GSList* nameservers_list_i = NULL; + GError *error = NULL; + + if(nameservers_v) + nameservers_list_i = nameservers_list = string_to_glist_of_strings (nameservers_v); + if(nameserver_v) + nameservers_list_i = nameservers_list = g_slist_append(nameservers_list, g_strdup(nameserver_v)); + + if (!address_v) + address_v = g_strdup ("0.0.0.0"); + + if (inet_pton (AF_INET, address_v, &tmp_ip4_addr)) + nm_ip4_address_set_address (ip4_addr, tmp_ip4_addr.s_addr); + else + g_set_error (&error, eni_plugin_error_quark (), 0, + "Invalid %s IP4 address '%s'", "address", address_v); + if (!netmask_v) + netmask_v = g_strdup( "255.255.255.255"); + + if (inet_pton (AF_INET, netmask_v, &tmp_ip4_addr)) + nm_ip4_address_set_prefix (ip4_addr, nm_utils_ip4_netmask_to_prefix(tmp_ip4_addr.s_addr)); + else + g_set_error (&error, eni_plugin_error_quark (), 0, + "Invalid %s IP4 address '%s'", "netmask", netmask_v); + + if (!gateway_v) + gateway_v = g_strdup (address_v); + + if (inet_pton (AF_INET, gateway_v, &tmp_ip4_addr)) + nm_ip4_address_set_gateway (ip4_addr, tmp_ip4_addr.s_addr); + else + g_set_error (&error, eni_plugin_error_quark (), 0, + "Invalid %s IP4 address '%s'", "gateway", gateway_v); + + if (nm_setting_ip4_config_add_address (ip4_setting, ip4_addr)) { + PLUGIN_PRINT("SCPlugin-Ifupdown", "addresses count: %d", + nm_setting_ip4_config_get_num_addresses (ip4_setting)); + } else { + PLUGIN_PRINT("SCPlugin-Ifupdown", "ignoring duplicate IP4 address"); + } + + while(nameservers_list_i) { + gchar *dns = nameservers_list_i->data; + nameservers_list_i = nameservers_list_i -> next; + if(!dns) + continue; + if (inet_pton (AF_INET, dns, &tmp_ip4_addr)) { + if (!nm_setting_ip4_config_add_dns (ip4_setting, tmp_ip4_addr.s_addr)) + PLUGIN_PRINT("SCPlugin-Ifupdown", "ignoring duplicate DNS server '%s'", dns); + } else + g_set_error (&error, eni_plugin_error_quark (), 0, + "Invalid %s IP4 address nameserver '%s'", "nameserver", dns); + } + if (!nm_setting_ip4_config_get_num_dns (ip4_setting)) + PLUGIN_PRINT("SCPlugin-Ifupdown", "No dns-nameserver configured in /etc/network/interfaces"); + + g_object_set(ip4_setting, + NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL, + NULL); + + g_slist_foreach (nameservers_list, (GFunc) g_free, NULL); + g_slist_free (nameservers_list); + } + + nm_connection_add_setting(connection, NM_SETTING(ip4_setting)); +} + +gboolean +ifupdown_update_connection_from_if_block (NMConnection *connection, + if_block *block, + GError **error) +{ + const char *type = NULL; + char *idstr = NULL; + char *uuid_base = NULL; + char *uuid = NULL; + NMSettingConnection *s_con; + gboolean success = FALSE; + + s_con = (NMSettingConnection *) nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION); + if(!s_con) { + s_con = NM_SETTING_CONNECTION (nm_setting_connection_new()); + g_assert (s_con); + nm_connection_add_setting (connection, NM_SETTING (s_con)); + } + + type = _ifupdownplugin_guess_connection_type (block); + idstr = g_strconcat ("Ifupdown (", block->name, ")", NULL); + uuid_base = idstr; + + uuid = nm_utils_uuid_generate_from_string (uuid_base); + g_object_set (s_con, + NM_SETTING_CONNECTION_TYPE, type, + NM_SETTING_CONNECTION_ID, idstr, + NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_READ_ONLY, TRUE, + NM_SETTING_CONNECTION_AUTOCONNECT, FALSE, + NULL); + g_free (uuid); + + PLUGIN_PRINT("SCPlugin-Ifupdown", "update_connection_setting_from_if_block: name:%s, type:%s, id:%s, uuid: %s", + block->name, type, idstr, nm_setting_connection_get_uuid (s_con)); + + if (!strcmp (NM_SETTING_WIRED_SETTING_NAME, type)) + update_wired_setting_from_if_block (connection, block); + else if (!strcmp (NM_SETTING_WIRELESS_SETTING_NAME, type)) { + update_wireless_setting_from_if_block (connection, block); + update_wireless_security_setting_from_if_block (connection, block); + } + + update_ip4_setting_from_if_block (connection, block); + + success = nm_connection_verify (connection, error); + + g_free (idstr); + return success; +} diff --git a/system-settings/plugins/ifupdown/parser.h b/system-settings/plugins/ifupdown/parser.h new file mode 100644 index 00000000..6aebb8c7 --- /dev/null +++ b/system-settings/plugins/ifupdown/parser.h @@ -0,0 +1,34 @@ +/* -*- Mode: C; tab-width: 5; indent-tabs-mode: t; c-basic-offset: 5 -*- */ + +/* NetworkManager system settings service (ifupdown) + * + * Alexander Sack <asac@ubuntu.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * (C) Copyright 2008 Canonical Ltd. + */ + +#include <nm-connection.h> +#include "interface_parser.h" + +G_BEGIN_DECLS + +gboolean +ifupdown_update_connection_from_if_block (NMConnection *connection, + if_block *block, + GError **error); + +G_END_DECLS diff --git a/system-settings/plugins/ifupdown/plugin.c b/system-settings/plugins/ifupdown/plugin.c new file mode 100644 index 00000000..e2358b9f --- /dev/null +++ b/system-settings/plugins/ifupdown/plugin.c @@ -0,0 +1,681 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ + +/* NetworkManager system settings service (ifupdown) + * + * Alexander Sack <asac@ubuntu.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * (C) Copyright 2007,2008 Canonical Ltd. + * (C) Copyright 2009 Red Hat, Inc. + */ + +#include <string.h> +#include <sys/inotify.h> + +#include <net/ethernet.h> +#include <netinet/ether.h> + +#include <gmodule.h> +#include <glib-object.h> +#include <glib/gi18n.h> +#include <glib.h> +#include <nm-setting-connection.h> + +#include "interface_parser.h" + +#include "NetworkManager.h" +#include "nm-system-config-interface.h" +#include "nm-setting-ip4-config.h" +#include "nm-setting-wireless.h" +#include "nm-setting-wired.h" +#include "nm-setting-ppp.h" + +#include "nm-ifupdown-connection.h" +#include "plugin.h" +#include "parser.h" +#include "nm-inotify-helper.h" + +#include <nm-utils.h> + +#include <arpa/inet.h> + +#define G_UDEV_API_IS_SUBJECT_TO_CHANGE +#include <gudev/gudev.h> + +#define IFUPDOWN_PLUGIN_NAME "ifupdown" +#define IFUPDOWN_PLUGIN_INFO "(C) 2008 Canonical Ltd. To report bugs please use the NetworkManager mailing list." +#define IFUPDOWN_SYSTEM_HOSTNAME_FILE "/etc/hostname" + +#define IFUPDOWN_SYSTEM_SETTINGS_KEY_FILE SYSCONFDIR "/NetworkManager/NetworkManager.conf" +#define IFUPDOWN_OLD_SYSTEM_SETTINGS_KEY_FILE SYSCONFDIR "/NetworkManager/nm-system-settings.conf" + +#define IFUPDOWN_KEY_FILE_GROUP "ifupdown" +#define IFUPDOWN_KEY_FILE_KEY_MANAGED "managed" +#define IFUPDOWN_UNMANAGE_WELL_KNOWN_DEFAULT TRUE + +/* #define ALWAYS_UNMANAGE TRUE */ +#ifndef ALWAYS_UNMANAGE +# define ALWAYS_UNMANAGE FALSE +#endif + +typedef struct { + GUdevClient *client; + + GHashTable *iface_connections; + gchar* hostname; + + GHashTable *well_known_interfaces; + GHashTable *well_known_ifaces; + gboolean unmanage_well_known; + const char *conf_file; + + gulong inotify_event_id; + int inotify_system_hostname_wd; +} SCPluginIfupdownPrivate; + +static void +system_config_interface_init (NMSystemConfigInterface *system_config_interface_class); + +G_DEFINE_TYPE_EXTENDED (SCPluginIfupdown, sc_plugin_ifupdown, G_TYPE_OBJECT, 0, + G_IMPLEMENT_INTERFACE (NM_TYPE_SYSTEM_CONFIG_INTERFACE, + system_config_interface_init)) + +#define SC_PLUGIN_IFUPDOWN_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), SC_TYPE_PLUGIN_IFUPDOWN, SCPluginIfupdownPrivate)) + +static void +sc_plugin_ifupdown_class_init (SCPluginIfupdownClass *req_class); + +static void +SCPluginIfupdown_init (NMSystemConfigInterface *config); + +/* Returns the plugins currently known list of connections. The returned + * list is freed by the system settings service. + */ +static GSList* +SCPluginIfupdown_get_connections (NMSystemConfigInterface *config); + +/* + * Return a list of device specifications which NetworkManager should not + * manage. Returned list will be freed by the system settings service, and + * each element must be allocated using g_malloc() or its variants. + */ +static GSList* +SCPluginIfupdown_get_unmanaged_specs (NMSystemConfigInterface *config); + + +/* GObject */ +static void +GObject__get_property (GObject *object, guint prop_id, + GValue *value, GParamSpec *pspec); + +static void +GObject__set_property (GObject *object, guint prop_id, + const GValue *value, GParamSpec *pspec); + +static void +GObject__dispose (GObject *object); + +/* other helpers */ +static const char * +get_hostname (NMSystemConfigInterface *config); + + +static void +update_system_hostname(NMInotifyHelper *inotify_helper, + struct inotify_event *evt, + const char *path, + NMSystemConfigInterface *config); + + +static void +system_config_interface_init (NMSystemConfigInterface *system_config_interface_class) +{ + system_config_interface_class->init = SCPluginIfupdown_init; + system_config_interface_class->get_connections = SCPluginIfupdown_get_connections; + system_config_interface_class->get_unmanaged_specs = SCPluginIfupdown_get_unmanaged_specs; +} + +static void +sc_plugin_ifupdown_class_init (SCPluginIfupdownClass *req_class) +{ + GObjectClass *object_class = G_OBJECT_CLASS (req_class); + + g_type_class_add_private (req_class, sizeof (SCPluginIfupdownPrivate)); + + object_class->dispose = GObject__dispose; + object_class->get_property = GObject__get_property; + object_class->set_property = GObject__set_property; + + g_object_class_override_property (object_class, + NM_SYSTEM_CONFIG_INTERFACE_PROP_NAME, + NM_SYSTEM_CONFIG_INTERFACE_NAME); + + g_object_class_override_property (object_class, + NM_SYSTEM_CONFIG_INTERFACE_PROP_INFO, + NM_SYSTEM_CONFIG_INTERFACE_INFO); + + g_object_class_override_property (object_class, + NM_SYSTEM_CONFIG_INTERFACE_PROP_CAPABILITIES, + NM_SYSTEM_CONFIG_INTERFACE_CAPABILITIES); + + g_object_class_override_property (object_class, + NM_SYSTEM_CONFIG_INTERFACE_PROP_HOSTNAME, + NM_SYSTEM_CONFIG_INTERFACE_HOSTNAME); +} + +static void +ignore_cb (NMSettingsConnectionInterface *connection, + GError *error, + gpointer user_data) +{ +} + +static void +bind_device_to_connection (SCPluginIfupdown *self, + GUdevDevice *device, + NMIfupdownConnection *exported) +{ + GByteArray *mac_address; + NMSetting *s_wired = NULL; + NMSetting *s_wifi = NULL; + const char *iface, *address; + struct ether_addr *tmp_mac; + + iface = g_udev_device_get_name (device); + if (!iface) { + PLUGIN_WARN ("SCPluginIfupdown", "failed to get ifname for device."); + return; + } + + address = g_udev_device_get_sysfs_attr (device, "address"); + if (!address || !strlen (address)) { + PLUGIN_WARN ("SCPluginIfupdown", "failed to get MAC address for %s", iface); + return; + } + + tmp_mac = ether_aton (address); + if (!tmp_mac) { + PLUGIN_WARN ("SCPluginIfupdown", "failed to parse MAC address '%s' for %s", + address, iface); + return; + } + + mac_address = g_byte_array_sized_new (ETH_ALEN); + g_byte_array_append (mac_address, &(tmp_mac->ether_addr_octet[0]), ETH_ALEN); + + s_wired = nm_connection_get_setting (NM_CONNECTION (exported), NM_TYPE_SETTING_WIRED); + s_wifi = nm_connection_get_setting (NM_CONNECTION (exported), NM_TYPE_SETTING_WIRELESS); + if (s_wired) { + PLUGIN_PRINT ("SCPluginIfupdown", "locking wired connection setting"); + g_object_set (s_wired, NM_SETTING_WIRED_MAC_ADDRESS, mac_address, NULL); + } else if (s_wifi) { + PLUGIN_PRINT ("SCPluginIfupdown", "locking wireless connection setting"); + g_object_set (s_wifi, NM_SETTING_WIRELESS_MAC_ADDRESS, mac_address, NULL); + } + g_byte_array_free (mac_address, TRUE); + + nm_settings_connection_interface_update (NM_SETTINGS_CONNECTION_INTERFACE (exported), + ignore_cb, + NULL); +} + +static void +udev_device_added (SCPluginIfupdown *self, GUdevDevice *device) +{ + SCPluginIfupdownPrivate *priv = SC_PLUGIN_IFUPDOWN_GET_PRIVATE (self); + const char *iface, *path; + NMIfupdownConnection *exported; + + iface = g_udev_device_get_name (device); + path = g_udev_device_get_sysfs_path (device); + if (!iface || !path) + return; + + PLUGIN_PRINT("SCPlugin-Ifupdown", + "devices added (path: %s, iface: %s)", path, iface); + + /* if we have a configured connection for this particular iface + * we want to either unmanage the device or lock it + */ + exported = (NMIfupdownConnection *) g_hash_table_lookup (priv->iface_connections, iface); + if (!exported && !g_hash_table_lookup (priv->well_known_interfaces, iface)) { + PLUGIN_PRINT("SCPlugin-Ifupdown", + "device added (path: %s, iface: %s): no ifupdown configuration found.", path, iface); + return; + } + + g_hash_table_insert (priv->well_known_ifaces, g_strdup (iface), g_object_ref (device)); + + if (exported) + bind_device_to_connection (self, device, exported); + + if (ALWAYS_UNMANAGE || priv->unmanage_well_known) + g_signal_emit_by_name (G_OBJECT (self), NM_SYSTEM_CONFIG_INTERFACE_UNMANAGED_SPECS_CHANGED); +} + +static void +udev_device_removed (SCPluginIfupdown *self, GUdevDevice *device) +{ + SCPluginIfupdownPrivate *priv = SC_PLUGIN_IFUPDOWN_GET_PRIVATE (self); + const char *iface, *path; + + iface = g_udev_device_get_name (device); + path = g_udev_device_get_sysfs_path (device); + if (!iface || !path) + return; + + PLUGIN_PRINT("SCPlugin-Ifupdown", + "devices removed (path: %s, iface: %s)", path, iface); + + if (!g_hash_table_remove (priv->well_known_ifaces, iface)) + return; + + if (ALWAYS_UNMANAGE || priv->unmanage_well_known) + g_signal_emit_by_name (G_OBJECT (self), NM_SYSTEM_CONFIG_INTERFACE_UNMANAGED_SPECS_CHANGED); +} + +static void +handle_uevent (GUdevClient *client, + const char *action, + GUdevDevice *device, + gpointer user_data) +{ + SCPluginIfupdown *self = SC_PLUGIN_IFUPDOWN (user_data); + const char *subsys; + + g_return_if_fail (action != NULL); + + /* A bit paranoid */ + subsys = g_udev_device_get_subsystem (device); + g_return_if_fail (subsys != NULL); + g_return_if_fail (strcmp (subsys, "net") == 0); + + if (!strcmp (action, "add")) + udev_device_added (self, device); + else if (!strcmp (action, "remove")) + udev_device_removed (self, device); +} + +static void +SCPluginIfupdown_init (NMSystemConfigInterface *config) +{ + SCPluginIfupdown *self = SC_PLUGIN_IFUPDOWN (config); + SCPluginIfupdownPrivate *priv = SC_PLUGIN_IFUPDOWN_GET_PRIVATE (self); + GHashTable *auto_ifaces; + if_block *block = NULL; + NMInotifyHelper *inotify_helper; + GKeyFile* keyfile; + GError *error = NULL; + GList *keys, *iter; + const char *subsys[2] = { "net", NULL }; + + auto_ifaces = g_hash_table_new (g_str_hash, g_str_equal); + + if(!priv->iface_connections) + priv->iface_connections = g_hash_table_new (g_str_hash, g_str_equal); + + if(!priv->well_known_ifaces) + priv->well_known_ifaces = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref); + + if(!priv->well_known_interfaces) + priv->well_known_interfaces = g_hash_table_new (g_str_hash, g_str_equal); + + PLUGIN_PRINT("SCPlugin-Ifupdown", "init!"); + + priv->client = g_udev_client_new (subsys); + if (!priv->client) { + PLUGIN_WARN ("SCPlugin-Ifupdown", " error initializing libgudev"); + } else + g_signal_connect (priv->client, "uevent", G_CALLBACK (handle_uevent), self); + + priv->unmanage_well_known = IFUPDOWN_UNMANAGE_WELL_KNOWN_DEFAULT; + + inotify_helper = nm_inotify_helper_get (); + priv->inotify_event_id = g_signal_connect (inotify_helper, + "event", + G_CALLBACK (update_system_hostname), + config); + + priv->inotify_system_hostname_wd = + nm_inotify_helper_add_watch (inotify_helper, IFUPDOWN_SYSTEM_HOSTNAME_FILE); + + update_system_hostname (inotify_helper, NULL, NULL, config); + + /* Read in all the interfaces */ + ifparser_init (); + block = ifparser_getfirst (); + while (block) { + if(!strcmp ("auto", block->type) || !strcmp ("allow-hotplug", block->type)) + g_hash_table_insert (auto_ifaces, block->name, GUINT_TO_POINTER (1)); + else if (!strcmp ("iface", block->type) && strcmp ("lo", block->name)) { + NMIfupdownConnection *exported; + + /* Remove any connection for this block that was previously found */ + exported = g_hash_table_lookup (priv->iface_connections, block->name); + if (exported) { + nm_settings_connection_interface_delete (NM_SETTINGS_CONNECTION_INTERFACE (exported), + ignore_cb, + NULL); + g_hash_table_remove (priv->iface_connections, block->name); + } + + /* add the new connection */ + exported = nm_ifupdown_connection_new (block); + if (exported) { + g_hash_table_insert (priv->iface_connections, block->name, exported); + g_hash_table_insert (priv->well_known_interfaces, block->name, "known"); + } + } else if (!strcmp ("mapping", block->type)) { + g_hash_table_insert (priv->well_known_interfaces, block->name, "known"); + } + block = block->next; + } + + /* Make 'auto' interfaces autoconnect=TRUE */ + keys = g_hash_table_get_keys (priv->iface_connections); + for (iter = keys; iter; iter = g_list_next (iter)) { + NMIfupdownConnection *exported; + NMSetting *setting; + + if (!g_hash_table_lookup (auto_ifaces, iter->data)) + continue; + + exported = g_hash_table_lookup (priv->iface_connections, iter->data); + setting = NM_SETTING (nm_connection_get_setting (NM_CONNECTION (exported), NM_TYPE_SETTING_CONNECTION)); + g_object_set (setting, NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NULL); + + nm_settings_connection_interface_update (NM_SETTINGS_CONNECTION_INTERFACE (exported), + ignore_cb, + NULL); + + PLUGIN_PRINT("SCPlugin-Ifupdown", "autoconnect"); + } + g_list_free (keys); + g_hash_table_destroy (auto_ifaces); + + /* Find the config file */ + if (g_file_test (IFUPDOWN_SYSTEM_SETTINGS_KEY_FILE, G_FILE_TEST_EXISTS)) + priv->conf_file = IFUPDOWN_SYSTEM_SETTINGS_KEY_FILE; + else + priv->conf_file = IFUPDOWN_OLD_SYSTEM_SETTINGS_KEY_FILE; + + keyfile = g_key_file_new (); + if (!g_key_file_load_from_file (keyfile, + priv->conf_file, + G_KEY_FILE_NONE, + &error)) { + nm_info ("loading system config file (%s) caused error: (%d) %s", + priv->conf_file, + error ? error->code : -1, + error && error->message ? error->message : "(unknown)"); + } else { + gboolean manage_well_known; + error = NULL; + + manage_well_known = g_key_file_get_boolean (keyfile, + IFUPDOWN_KEY_FILE_GROUP, + IFUPDOWN_KEY_FILE_KEY_MANAGED, + &error); + if (error) { + nm_info ("getting keyfile key '%s' in group '%s' failed: (%d) %s", + IFUPDOWN_KEY_FILE_GROUP, + IFUPDOWN_KEY_FILE_KEY_MANAGED, + error ? error->code : -1, + error && error->message ? error->message : "(unknown)"); + } else + priv->unmanage_well_known = !manage_well_known; + } + PLUGIN_PRINT ("SCPluginIfupdown", "management mode: %s", priv->unmanage_well_known ? "unmanaged" : "managed"); + if (keyfile) + g_key_file_free (keyfile); + + /* Add well-known interfaces */ + keys = g_udev_client_query_by_subsystem (priv->client, "net"); + for (iter = keys; iter; iter = g_list_next (iter)) { + udev_device_added (self, G_UDEV_DEVICE (iter->data)); + g_object_unref (G_UDEV_DEVICE (iter->data)); + } + g_list_free (keys); + + /* Now if we're running in managed mode, let NM know there are new connections */ + if (!priv->unmanage_well_known) { + GList *con_list = g_hash_table_get_values (priv->iface_connections); + GList *cl_iter; + + for (cl_iter = con_list; cl_iter; cl_iter = g_list_next (cl_iter)) { + g_signal_emit_by_name (self, + NM_SYSTEM_CONFIG_INTERFACE_CONNECTION_ADDED, + NM_EXPORTED_CONNECTION (cl_iter->data)); + } + g_list_free (con_list); + } + + PLUGIN_PRINT("SCPlugin-Ifupdown", "end _init."); +} + + +/* Returns the plugins currently known list of connections. The returned + * list is freed by the system settings service. + */ +static GSList* +SCPluginIfupdown_get_connections (NMSystemConfigInterface *config) +{ + SCPluginIfupdownPrivate *priv = SC_PLUGIN_IFUPDOWN_GET_PRIVATE (config); + GSList *connections = NULL; + GHashTableIter iter; + gpointer value; + + PLUGIN_PRINT("SCPlugin-Ifupdown", "(%d) ... get_connections.", GPOINTER_TO_UINT(config)); + + if(priv->unmanage_well_known) { + PLUGIN_PRINT("SCPlugin-Ifupdown", "(%d) ... get_connections (managed=false): return empty list.", GPOINTER_TO_UINT(config)); + return NULL; + } + + g_hash_table_iter_init (&iter, priv->iface_connections); + while (g_hash_table_iter_next (&iter, NULL, &value)) + connections = g_slist_prepend (connections, value); + + PLUGIN_PRINT("SCPlugin-Ifupdown", "(%d) connections count: %d", GPOINTER_TO_UINT(config), g_slist_length(connections)); + return connections; +} + +/* + * Return a list of device specifications which NetworkManager should not + * manage. Returned list will be freed by the system settings service, and + * each element must be allocated using g_malloc() or its variants. + */ +static GSList* +SCPluginIfupdown_get_unmanaged_specs (NMSystemConfigInterface *config) +{ + SCPluginIfupdownPrivate *priv = SC_PLUGIN_IFUPDOWN_GET_PRIVATE (config); + GSList *specs = NULL; + GHashTableIter iter; + gpointer value; + + if (!ALWAYS_UNMANAGE && !priv->unmanage_well_known) + return NULL; + + PLUGIN_PRINT("Ifupdown", "get unmanaged devices count: %d", + g_hash_table_size (priv->well_known_ifaces)); + + g_hash_table_iter_init (&iter, priv->well_known_ifaces); + while (g_hash_table_iter_next (&iter, NULL, &value)) { + GUdevDevice *device = G_UDEV_DEVICE (value); + const char *address; + + address = g_udev_device_get_sysfs_attr (device, "address"); + if (address) + specs = g_slist_append (specs, g_strdup_printf ("mac:%s", address)); + } + return specs; +} + + +static const char * +get_hostname (NMSystemConfigInterface *config) +{ + SCPluginIfupdownPrivate *priv = SC_PLUGIN_IFUPDOWN_GET_PRIVATE (config); + return priv->hostname; +} + +static void +update_system_hostname(NMInotifyHelper *inotify_helper, + struct inotify_event *evt, + const char *path, + NMSystemConfigInterface *config) +{ + SCPluginIfupdownPrivate *priv = SC_PLUGIN_IFUPDOWN_GET_PRIVATE (config); + gchar *hostname_file = NULL; + gsize hostname_file_len = 0; + GError *error = NULL; + + PLUGIN_PRINT ("SCPlugin-Ifupdown", "update_system_hostname"); + + if (evt && evt->wd != priv->inotify_system_hostname_wd) + return; + + if(!g_file_get_contents ( IFUPDOWN_SYSTEM_HOSTNAME_FILE, + &hostname_file, + &hostname_file_len, + &error)) { + nm_warning ("update_system_hostname() - couldn't read " + IFUPDOWN_SYSTEM_HOSTNAME_FILE " (%d/%s)", + error->code, error->message); + return; + } + + if (priv->hostname) + g_free(priv->hostname); + + priv->hostname = g_strstrip(hostname_file); + + g_object_notify (G_OBJECT (config), NM_SYSTEM_CONFIG_INTERFACE_HOSTNAME); +} + +static void +write_system_hostname(NMSystemConfigInterface *config, + const char *newhostname) +{ + GError *error = NULL; + SCPluginIfupdownPrivate *priv = SC_PLUGIN_IFUPDOWN_GET_PRIVATE (config); + PLUGIN_PRINT ("SCPlugin-Ifupdown", "write_system_hostname: %s", newhostname); + + g_return_if_fail (newhostname); + + if(!g_file_set_contents ( IFUPDOWN_SYSTEM_HOSTNAME_FILE, + newhostname, + -1, + &error)) { + nm_warning ("update_system_hostname() - couldn't write hostname (%s) to " + IFUPDOWN_SYSTEM_HOSTNAME_FILE " (%d/%s)", + newhostname, error->code, error->message); + } else { + priv->hostname = g_strdup (newhostname); + } + g_object_notify (G_OBJECT (config), NM_SYSTEM_CONFIG_INTERFACE_HOSTNAME); +} + + +static void +sc_plugin_ifupdown_init (SCPluginIfupdown *plugin) +{ +} + +static void +GObject__get_property (GObject *object, guint prop_id, + GValue *value, GParamSpec *pspec) +{ + NMSystemConfigInterface *self = NM_SYSTEM_CONFIG_INTERFACE (object); + + switch (prop_id) { + case NM_SYSTEM_CONFIG_INTERFACE_PROP_NAME: + g_value_set_string (value, IFUPDOWN_PLUGIN_NAME); + break; + case NM_SYSTEM_CONFIG_INTERFACE_PROP_INFO: + g_value_set_string (value, IFUPDOWN_PLUGIN_INFO); + break; + case NM_SYSTEM_CONFIG_INTERFACE_PROP_CAPABILITIES: + g_value_set_uint (value, NM_SYSTEM_CONFIG_INTERFACE_CAP_MODIFY_HOSTNAME); + break; + case NM_SYSTEM_CONFIG_INTERFACE_PROP_HOSTNAME: + { + g_value_set_string (value, get_hostname(self)); + break; + } + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +GObject__set_property (GObject *object, guint prop_id, + const GValue *value, GParamSpec *pspec) +{ + switch (prop_id) { + case NM_SYSTEM_CONFIG_INTERFACE_PROP_HOSTNAME: + { + const gchar *hostname = g_value_get_string (value); + if (hostname && strlen (hostname) < 1) + hostname = NULL; + write_system_hostname(NM_SYSTEM_CONFIG_INTERFACE(object), + hostname); + break; + } + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +GObject__dispose (GObject *object) +{ + SCPluginIfupdown *plugin = SC_PLUGIN_IFUPDOWN (object); + SCPluginIfupdownPrivate *priv = SC_PLUGIN_IFUPDOWN_GET_PRIVATE (plugin); + NMInotifyHelper *inotify_helper = nm_inotify_helper_get (); + + g_signal_handler_disconnect (inotify_helper, priv->inotify_event_id); + + if (priv->inotify_system_hostname_wd >= 0) + nm_inotify_helper_remove_watch (inotify_helper, priv->inotify_system_hostname_wd); + + if (priv->well_known_ifaces) + g_hash_table_destroy(priv->well_known_ifaces); + + if (priv->well_known_interfaces) + g_hash_table_destroy(priv->well_known_interfaces); + + if (priv->client) + g_object_unref (priv->client); + + G_OBJECT_CLASS (sc_plugin_ifupdown_parent_class)->dispose (object); +} + +G_MODULE_EXPORT GObject * +nm_system_config_factory (void) +{ + static SCPluginIfupdown *singleton = NULL; + + if (!singleton) + singleton = SC_PLUGIN_IFUPDOWN (g_object_new (SC_TYPE_PLUGIN_IFUPDOWN, NULL)); + else + g_object_ref (singleton); + + return G_OBJECT (singleton); +} + diff --git a/system-settings/plugins/ifupdown/plugin.h b/system-settings/plugins/ifupdown/plugin.h new file mode 100644 index 00000000..09f8767a --- /dev/null +++ b/system-settings/plugins/ifupdown/plugin.h @@ -0,0 +1,53 @@ +/* -*- Mode: C; tab-width: 5; indent-tabs-mode: t; c-basic-offset: 5 -*- */ + +/* NetworkManager system settings service (ifupdown) + * + * Alexander Sack <asac@ubuntu.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * (C) Copyright 2008 Canonical Ltd. + */ + +#ifndef _PLUGIN_H_ +#define _PLUGIN_H_ + +#include <glib-object.h> + +#define PLUGIN_NAME "ifupdown" + +#define SC_TYPE_PLUGIN_IFUPDOWN (sc_plugin_ifupdown_get_type ()) +#define SC_PLUGIN_IFUPDOWN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SC_TYPE_PLUGIN_IFUPDOWN, SCPluginIfupdown)) +#define SC_PLUGIN_IFUPDOWN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SC_TYPE_PLUGIN_IFUPDOWN, SCPluginIfupdownClass)) +#define SC_IS_PLUGIN_IFUPDOWN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SC_TYPE_PLUGIN_IFUPDOWN)) +#define SC_IS_PLUGIN_IFUPDOWN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), SC_TYPE_PLUGIN_IFUPDOWN)) +#define SC_PLUGIN_IFUPDOWN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SC_TYPE_PLUGIN_IFUPDOWN, SCPluginIfupdownClass)) + +typedef struct _SCPluginIfupdown SCPluginIfupdown; +typedef struct _SCPluginIfupdownClass SCPluginIfupdownClass; + +struct _SCPluginIfupdown { + GObject parent; +}; + +struct _SCPluginIfupdownClass { + GObjectClass parent; +}; + +GType sc_plugin_ifupdown_get_type (void); + +GQuark ifupdown_plugin_error_quark (void); + +#endif /* _PLUGIN_H_ */ |