From 58f8be580039b0575b197b9573a1c92745d96d30 Mon Sep 17 00:00:00 2001 From: Michael Biebl Date: Tue, 17 Jan 2017 20:25:09 +0100 Subject: New upstream version 1.5.90 --- src/settings/plugins/ifcfg-rh/Makefile.am | 74 - src/settings/plugins/ifcfg-rh/Makefile.in | 1062 ---- src/settings/plugins/ifcfg-rh/common.h | 82 - .../plugins/ifcfg-rh/nm-ifcfg-connection.c | 566 --- .../plugins/ifcfg-rh/nm-ifcfg-connection.h | 59 - .../plugins/ifcfg-rh/nms-ifcfg-rh-common.h | 82 + .../plugins/ifcfg-rh/nms-ifcfg-rh-connection.c | 575 +++ .../plugins/ifcfg-rh/nms-ifcfg-rh-connection.h | 54 + .../plugins/ifcfg-rh/nms-ifcfg-rh-plugin.c | 1085 ++++ .../plugins/ifcfg-rh/nms-ifcfg-rh-plugin.h | 39 + .../plugins/ifcfg-rh/nms-ifcfg-rh-reader.c | 5361 ++++++++++++++++++++ .../plugins/ifcfg-rh/nms-ifcfg-rh-reader.h | 42 + src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.c | 365 ++ src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.h | 58 + .../plugins/ifcfg-rh/nms-ifcfg-rh-writer.c | 2965 +++++++++++ .../plugins/ifcfg-rh/nms-ifcfg-rh-writer.h | 39 + src/settings/plugins/ifcfg-rh/plugin.c | 1080 ---- src/settings/plugins/ifcfg-rh/plugin.h | 48 - src/settings/plugins/ifcfg-rh/reader.c | 5260 ------------------- src/settings/plugins/ifcfg-rh/reader.h | 42 - src/settings/plugins/ifcfg-rh/shvar.c | 1218 +++-- src/settings/plugins/ifcfg-rh/shvar.h | 26 +- src/settings/plugins/ifcfg-rh/tests/Makefile.am | 56 - src/settings/plugins/ifcfg-rh/tests/Makefile.in | 1371 ----- .../ifcfg-rh/tests/network-scripts/Makefile.am | 170 - .../ifcfg-rh/tests/network-scripts/Makefile.in | 776 --- .../network-scripts/ifcfg-test-misc-variables | 1 + .../network-scripts/ifcfg-test-read-proxy-basic | 15 + .../tests/network-scripts/ifcfg-test-wifi-wpa-psk | 2 +- .../ifcfg-test-wired-auto-negotiate-on | 22 + .../ifcfg-test-wired-dhcpv6-hostname-fallback | 12 + .../ifcfg-test-wired-unknown-ethtool-opt | 22 + .../network-scripts/ifcfg-test-write-unknown-1 | 8 + .../ifcfg-test-write-unknown-1.expected | 12 + .../network-scripts/ifcfg-test-write-unknown-2 | 3 + .../ifcfg-test-write-unknown-2.expected | 4 + .../network-scripts/ifcfg-test-write-unknown-3 | 3 + .../ifcfg-test-write-unknown-3.expected | 5 + .../network-scripts/ifcfg-test-write-unknown-4 | 36 + .../ifcfg-test-write-unknown-4.expected | 31 + .../tests/network-scripts/keys-test-wifi-wpa-psk-2 | 2 +- .../plugins/ifcfg-rh/tests/test-ifcfg-rh-utils.c | 155 - .../plugins/ifcfg-rh/tests/test-ifcfg-rh.c | 2256 ++++---- src/settings/plugins/ifcfg-rh/utils.c | 446 -- src/settings/plugins/ifcfg-rh/utils.h | 62 - src/settings/plugins/ifcfg-rh/writer.c | 2970 ----------- src/settings/plugins/ifcfg-rh/writer.h | 40 - 47 files changed, 12942 insertions(+), 15720 deletions(-) delete mode 100644 src/settings/plugins/ifcfg-rh/Makefile.am delete mode 100644 src/settings/plugins/ifcfg-rh/Makefile.in delete mode 100644 src/settings/plugins/ifcfg-rh/common.h delete mode 100644 src/settings/plugins/ifcfg-rh/nm-ifcfg-connection.c delete mode 100644 src/settings/plugins/ifcfg-rh/nm-ifcfg-connection.h create mode 100644 src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-common.h create mode 100644 src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-connection.c create mode 100644 src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-connection.h create mode 100644 src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-plugin.c create mode 100644 src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-plugin.h create mode 100644 src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c create mode 100644 src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.h create mode 100644 src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.c create mode 100644 src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.h create mode 100644 src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c create mode 100644 src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.h delete mode 100644 src/settings/plugins/ifcfg-rh/plugin.c delete mode 100644 src/settings/plugins/ifcfg-rh/plugin.h delete mode 100644 src/settings/plugins/ifcfg-rh/reader.c delete mode 100644 src/settings/plugins/ifcfg-rh/reader.h delete mode 100644 src/settings/plugins/ifcfg-rh/tests/Makefile.am delete mode 100644 src/settings/plugins/ifcfg-rh/tests/Makefile.in delete mode 100644 src/settings/plugins/ifcfg-rh/tests/network-scripts/Makefile.am delete mode 100644 src/settings/plugins/ifcfg-rh/tests/network-scripts/Makefile.in create mode 100644 src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-read-proxy-basic create mode 100644 src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-auto-negotiate-on create mode 100644 src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-dhcpv6-hostname-fallback create mode 100644 src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-unknown-ethtool-opt create mode 100644 src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-1 create mode 100644 src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-1.expected create mode 100644 src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-2 create mode 100644 src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-2.expected create mode 100644 src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-3 create mode 100644 src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-3.expected create mode 100644 src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-4 create mode 100644 src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-4.expected delete mode 100644 src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh-utils.c delete mode 100644 src/settings/plugins/ifcfg-rh/utils.c delete mode 100644 src/settings/plugins/ifcfg-rh/utils.h delete mode 100644 src/settings/plugins/ifcfg-rh/writer.c delete mode 100644 src/settings/plugins/ifcfg-rh/writer.h (limited to 'src/settings/plugins/ifcfg-rh') diff --git a/src/settings/plugins/ifcfg-rh/Makefile.am b/src/settings/plugins/ifcfg-rh/Makefile.am deleted file mode 100644 index d2899a26..00000000 --- a/src/settings/plugins/ifcfg-rh/Makefile.am +++ /dev/null @@ -1,74 +0,0 @@ -SUBDIRS = . tests - -@GNOME_CODE_COVERAGE_RULES@ - -# See note about gdbus-codegen in introspection/Makefile.am - -noinst_LTLIBRARIES = libnmdbus-ifcfg-rh.la - -nodist_libnmdbus_ifcfg_rh_la_SOURCES = \ - nmdbus-ifcfg-rh.c \ - nmdbus-ifcfg-rh.h - -libnmdbus_ifcfg_rh_la_CPPFLAGS = $(filter-out -DGLIB_VERSION_MAX_ALLOWED%,$(AM_CPPFLAGS)) - -nmdbus-ifcfg-rh.h: nm-ifcfg-rh.xml - $(AM_V_GEN) gdbus-codegen \ - --generate-c-code $(basename $@) \ - --c-namespace NMDBus \ - --interface-prefix com.redhat \ - $< - -nmdbus-ifcfg-rh.c: nmdbus-ifcfg-rh.h - @true - -BUILT_SOURCES = nmdbus-ifcfg-rh.h nmdbus-ifcfg-rh.c - -pkglib_LTLIBRARIES = libnm-settings-plugin-ifcfg-rh.la - -noinst_LTLIBRARIES += libifcfg-rh-io.la - -libifcfg_rh_io_la_SOURCES = \ - shvar.c \ - shvar.h \ - reader.c \ - reader.h \ - writer.c \ - writer.h \ - common.h \ - utils.c \ - utils.h - -AM_CPPFLAGS = \ - -I$(top_srcdir)/src/ \ - -I$(top_srcdir)/src/platform \ - -I$(top_srcdir)/src/settings \ - -I$(top_srcdir)/shared \ - -I$(top_builddir)/shared \ - -I$(top_srcdir)/libnm-core \ - -I$(top_builddir)/libnm-core \ - -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \ - $(GLIB_CFLAGS) \ - $(NSS_CFLAGS) \ - -DG_LOG_DOMAIN=\""NetworkManager-ifcfg-rh"\" \ - -DSYSCONFDIR=\"$(sysconfdir)\" \ - -DSBINDIR=\"$(sbindir)\" - -libnm_settings_plugin_ifcfg_rh_la_SOURCES = \ - plugin.c \ - plugin.h \ - nm-ifcfg-connection.c \ - nm-ifcfg-connection.h - -libnm_settings_plugin_ifcfg_rh_la_LDFLAGS = -module -avoid-version -libnm_settings_plugin_ifcfg_rh_la_LIBADD = libifcfg-rh-io.la libnmdbus-ifcfg-rh.la - -dbusservicedir = $(DBUS_SYS_DIR) -dbusservice_DATA = nm-ifcfg-rh.conf - -EXTRA_DIST = \ - $(dbusservice_DATA) \ - nm-ifcfg-rh.xml - -CLEANFILES = $(BUILT_SOURCES) - diff --git a/src/settings/plugins/ifcfg-rh/Makefile.in b/src/settings/plugins/ifcfg-rh/Makefile.in deleted file mode 100644 index 200289e5..00000000 --- a/src/settings/plugins/ifcfg-rh/Makefile.in +++ /dev/null @@ -1,1062 +0,0 @@ -# Makefile.in generated by automake 1.15 from Makefile.am. -# @configure_input@ - -# Copyright (C) 1994-2014 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@ -am__is_gnu_make = { \ - if test -z '$(MAKELEVEL)'; then \ - false; \ - elif test -n '$(MAKE_HOST)'; then \ - true; \ - elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \ - true; \ - else \ - false; \ - fi; \ -} -am__make_running_with_option = \ - case $${target_option-} in \ - ?) ;; \ - *) echo "am__make_running_with_option: internal error: invalid" \ - "target option '$${target_option-}' specified" >&2; \ - exit 1;; \ - esac; \ - has_opt=no; \ - sane_makeflags=$$MAKEFLAGS; \ - if $(am__is_gnu_make); then \ - sane_makeflags=$$MFLAGS; \ - else \ - case $$MAKEFLAGS in \ - *\\[\ \ ]*) \ - bs=\\; \ - sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \ - | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \ - esac; \ - fi; \ - skip_next=no; \ - strip_trailopt () \ - { \ - flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \ - }; \ - for flg in $$sane_makeflags; do \ - test $$skip_next = yes && { skip_next=no; continue; }; \ - case $$flg in \ - *=*|--*) continue;; \ - -*I) strip_trailopt 'I'; skip_next=yes;; \ - -*I?*) strip_trailopt 'I';; \ - -*O) strip_trailopt 'O'; skip_next=yes;; \ - -*O?*) strip_trailopt 'O';; \ - -*l) strip_trailopt 'l'; skip_next=yes;; \ - -*l?*) strip_trailopt 'l';; \ - -[dEDm]) skip_next=yes;; \ - -[JT]) skip_next=yes;; \ - esac; \ - case $$flg in \ - *$$target_option*) has_opt=yes; break;; \ - esac; \ - done; \ - test $$has_opt = yes -am__make_dryrun = (target_option=n; $(am__make_running_with_option)) -am__make_keepgoing = (target_option=k; $(am__make_running_with_option)) -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/settings/plugins/ifcfg-rh -ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 -am__aclocal_m4_deps = $(top_srcdir)/m4/attributes.m4 \ - $(top_srcdir)/m4/ax_lib_readline.m4 \ - $(top_srcdir)/m4/compiler_options.m4 \ - $(top_srcdir)/m4/gettext.m4 $(top_srcdir)/m4/git-sha-record.m4 \ - $(top_srcdir)/m4/gnome-code-coverage.m4 \ - $(top_srcdir)/m4/gtk-doc.m4 $(top_srcdir)/m4/iconv.m4 \ - $(top_srcdir)/m4/intlmacosx.m4 $(top_srcdir)/m4/intltool.m4 \ - $(top_srcdir)/m4/introspection.m4 $(top_srcdir)/m4/lib-ld.m4 \ - $(top_srcdir)/m4/lib-link.m4 $(top_srcdir)/m4/lib-prefix.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)/m4/nls.m4 \ - $(top_srcdir)/m4/po.m4 $(top_srcdir)/m4/progtest.m4 \ - $(top_srcdir)/m4/vapigen.m4 $(top_srcdir)/configure.ac -am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ - $(ACLOCAL_M4) -DIST_COMMON = $(srcdir)/Makefile.am $(am__DIST_COMMON) -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__uninstall_files_from_dir = { \ - test -z "$$files" \ - || { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \ - || { echo " ( cd '$$dir' && rm -f" $$files ")"; \ - $(am__cd) "$$dir" && rm -f $$files; }; \ - } -am__installdirs = "$(DESTDIR)$(pkglibdir)" \ - "$(DESTDIR)$(dbusservicedir)" -LTLIBRARIES = $(noinst_LTLIBRARIES) $(pkglib_LTLIBRARIES) -libifcfg_rh_io_la_LIBADD = -am_libifcfg_rh_io_la_OBJECTS = shvar.lo reader.lo writer.lo utils.lo -libifcfg_rh_io_la_OBJECTS = $(am_libifcfg_rh_io_la_OBJECTS) -AM_V_lt = $(am__v_lt_@AM_V@) -am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) -am__v_lt_0 = --silent -am__v_lt_1 = -libnm_settings_plugin_ifcfg_rh_la_DEPENDENCIES = libifcfg-rh-io.la \ - libnmdbus-ifcfg-rh.la -am_libnm_settings_plugin_ifcfg_rh_la_OBJECTS = plugin.lo \ - nm-ifcfg-connection.lo -libnm_settings_plugin_ifcfg_rh_la_OBJECTS = \ - $(am_libnm_settings_plugin_ifcfg_rh_la_OBJECTS) -libnm_settings_plugin_ifcfg_rh_la_LINK = $(LIBTOOL) $(AM_V_lt) \ - --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link \ - $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ - $(libnm_settings_plugin_ifcfg_rh_la_LDFLAGS) $(LDFLAGS) -o $@ -libnmdbus_ifcfg_rh_la_LIBADD = -nodist_libnmdbus_ifcfg_rh_la_OBJECTS = \ - libnmdbus_ifcfg_rh_la-nmdbus-ifcfg-rh.lo -libnmdbus_ifcfg_rh_la_OBJECTS = \ - $(nodist_libnmdbus_ifcfg_rh_la_OBJECTS) -AM_V_P = $(am__v_P_@AM_V@) -am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) -am__v_P_0 = false -am__v_P_1 = : -AM_V_GEN = $(am__v_GEN_@AM_V@) -am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@) -am__v_GEN_0 = @echo " GEN " $@; -am__v_GEN_1 = -AM_V_at = $(am__v_at_@AM_V@) -am__v_at_ = $(am__v_at_@AM_DEFAULT_V@) -am__v_at_0 = @ -am__v_at_1 = -DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) -depcomp = $(SHELL) $(top_srcdir)/build-aux/depcomp -am__depfiles_maybe = depfiles -am__mv = mv -f -COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ - $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ - $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \ - $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ - $(AM_CFLAGS) $(CFLAGS) -AM_V_CC = $(am__v_CC_@AM_V@) -am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@) -am__v_CC_0 = @echo " CC " $@; -am__v_CC_1 = -CCLD = $(CC) -LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ - $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ - $(AM_LDFLAGS) $(LDFLAGS) -o $@ -AM_V_CCLD = $(am__v_CCLD_@AM_V@) -am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@) -am__v_CCLD_0 = @echo " CCLD " $@; -am__v_CCLD_1 = -SOURCES = $(libifcfg_rh_io_la_SOURCES) \ - $(libnm_settings_plugin_ifcfg_rh_la_SOURCES) \ - $(nodist_libnmdbus_ifcfg_rh_la_SOURCES) -DIST_SOURCES = $(libifcfg_rh_io_la_SOURCES) \ - $(libnm_settings_plugin_ifcfg_rh_la_SOURCES) -RECURSIVE_TARGETS = all-recursive check-recursive cscopelist-recursive \ - ctags-recursive dvi-recursive html-recursive info-recursive \ - install-data-recursive install-dvi-recursive \ - install-exec-recursive install-html-recursive \ - install-info-recursive install-pdf-recursive \ - install-ps-recursive install-recursive installcheck-recursive \ - installdirs-recursive pdf-recursive ps-recursive \ - tags-recursive uninstall-recursive -am__can_run_installinfo = \ - case $$AM_UPDATE_INFO_DIR in \ - n|no|NO) false;; \ - *) (install-info --version) >/dev/null 2>&1;; \ - esac -DATA = $(dbusservice_DATA) -RECURSIVE_CLEAN_TARGETS = mostlyclean-recursive clean-recursive \ - distclean-recursive maintainer-clean-recursive -am__recursive_targets = \ - $(RECURSIVE_TARGETS) \ - $(RECURSIVE_CLEAN_TARGETS) \ - $(am__extra_recursive_targets) -AM_RECURSIVE_TARGETS = $(am__recursive_targets:-recursive=) TAGS CTAGS \ - distdir -am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) -# Read a list of newline-separated strings from the standard input, -# and print each of them once, without duplicates. Input order is -# *not* preserved. -am__uniquify_input = $(AWK) '\ - BEGIN { nonempty = 0; } \ - { items[$$0] = 1; nonempty = 1; } \ - END { if (nonempty) { for (i in items) print i; }; } \ -' -# Make sure the list of sources is unique. This is necessary because, -# e.g., the same source file might be shared among _SOURCES variables -# for different programs/libraries. -am__define_uniq_tagged_files = \ - list='$(am__tagged_files)'; \ - unique=`for i in $$list; do \ - if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ - done | $(am__uniquify_input)` -ETAGS = etags -CTAGS = ctags -DIST_SUBDIRS = $(SUBDIRS) -am__DIST_COMMON = $(srcdir)/Makefile.in \ - $(top_srcdir)/build-aux/depcomp -DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) -am__relativize = \ - dir0=`pwd`; \ - sed_first='s,^\([^/]*\)/.*$$,\1,'; \ - sed_rest='s,^[^/]*/*,,'; \ - sed_last='s,^.*/\([^/]*\)$$,\1,'; \ - sed_butlast='s,/*[^/]*$$,,'; \ - while test -n "$$dir1"; do \ - first=`echo "$$dir1" | sed -e "$$sed_first"`; \ - if test "$$first" != "."; then \ - if test "$$first" = ".."; then \ - dir2=`echo "$$dir0" | sed -e "$$sed_last"`/"$$dir2"; \ - dir0=`echo "$$dir0" | sed -e "$$sed_butlast"`; \ - else \ - first2=`echo "$$dir2" | sed -e "$$sed_first"`; \ - if test "$$first2" = "$$first"; then \ - dir2=`echo "$$dir2" | sed -e "$$sed_rest"`; \ - else \ - dir2="../$$dir2"; \ - fi; \ - dir0="$$dir0"/"$$first"; \ - fi; \ - fi; \ - dir1=`echo "$$dir1" | sed -e "$$sed_rest"`; \ - done; \ - reldir="$$dir2" -ACLOCAL = @ACLOCAL@ -ALL_LINGUAS = @ALL_LINGUAS@ -AMTAR = @AMTAR@ -AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ -AM_TESTS_FD_REDIRECT = @AM_TESTS_FD_REDIRECT@ -AR = @AR@ -AUTOCONF = @AUTOCONF@ -AUTOHEADER = @AUTOHEADER@ -AUTOMAKE = @AUTOMAKE@ -AWK = @AWK@ -BLUEZ5_CFLAGS = @BLUEZ5_CFLAGS@ -BLUEZ5_LIBS = @BLUEZ5_LIBS@ -CC = @CC@ -CCDEPMODE = @CCDEPMODE@ -CFLAGS = @CFLAGS@ -CODE_COVERAGE_CFLAGS = @CODE_COVERAGE_CFLAGS@ -CODE_COVERAGE_ENABLED = @CODE_COVERAGE_ENABLED@ -CODE_COVERAGE_LDFLAGS = @CODE_COVERAGE_LDFLAGS@ -CPP = @CPP@ -CPPFLAGS = @CPPFLAGS@ -CXX = @CXX@ -CXXCPP = @CXXCPP@ -CXXDEPMODE = @CXXDEPMODE@ -CXXFLAGS = @CXXFLAGS@ -CYGPATH_W = @CYGPATH_W@ -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@ -DISTRO_NETWORK_SERVICE = @DISTRO_NETWORK_SERVICE@ -DLLTOOL = @DLLTOOL@ -DL_LIBS = @DL_LIBS@ -DNSMASQ_PATH = @DNSMASQ_PATH@ -DNSSEC_TRIGGER_SCRIPT = @DNSSEC_TRIGGER_SCRIPT@ -DSYMUTIL = @DSYMUTIL@ -DUMPBIN = @DUMPBIN@ -ECHO_C = @ECHO_C@ -ECHO_N = @ECHO_N@ -ECHO_T = @ECHO_T@ -EGREP = @EGREP@ -EXEEXT = @EXEEXT@ -FGREP = @FGREP@ -GENHTML = @GENHTML@ -GETTEXT_MACRO_VERSION = @GETTEXT_MACRO_VERSION@ -GETTEXT_PACKAGE = @GETTEXT_PACKAGE@ -GLIB_CFLAGS = @GLIB_CFLAGS@ -GLIB_GENMARSHAL = @GLIB_GENMARSHAL@ -GLIB_LIBS = @GLIB_LIBS@ -GLIB_MAKEFILE = @GLIB_MAKEFILE@ -GLIB_MKENUMS = @GLIB_MKENUMS@ -GMSGFMT = @GMSGFMT@ -GMSGFMT_015 = @GMSGFMT_015@ -GNUTLS_CFLAGS = @GNUTLS_CFLAGS@ -GNUTLS_LIBS = @GNUTLS_LIBS@ -GREP = @GREP@ -GTKDOC_CHECK = @GTKDOC_CHECK@ -GTKDOC_CHECK_PATH = @GTKDOC_CHECK_PATH@ -GTKDOC_DEPS_CFLAGS = @GTKDOC_DEPS_CFLAGS@ -GTKDOC_DEPS_LIBS = @GTKDOC_DEPS_LIBS@ -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@ -INTLLIBS = @INTLLIBS@ -INTLTOOL_EXTRACT = @INTLTOOL_EXTRACT@ -INTLTOOL_MERGE = @INTLTOOL_MERGE@ -INTLTOOL_PERL = @INTLTOOL_PERL@ -INTLTOOL_UPDATE = @INTLTOOL_UPDATE@ -INTLTOOL_V_MERGE = @INTLTOOL_V_MERGE@ -INTLTOOL_V_MERGE_OPTIONS = @INTLTOOL_V_MERGE_OPTIONS@ -INTLTOOL__v_MERGE_ = @INTLTOOL__v_MERGE_@ -INTLTOOL__v_MERGE_0 = @INTLTOOL__v_MERGE_0@ -INTL_MACOSX_LIBS = @INTL_MACOSX_LIBS@ -INTROSPECTION_CFLAGS = @INTROSPECTION_CFLAGS@ -INTROSPECTION_COMPILER = @INTROSPECTION_COMPILER@ -INTROSPECTION_GENERATE = @INTROSPECTION_GENERATE@ -INTROSPECTION_GIRDIR = @INTROSPECTION_GIRDIR@ -INTROSPECTION_LIBS = @INTROSPECTION_LIBS@ -INTROSPECTION_MAKEFILE = @INTROSPECTION_MAKEFILE@ -INTROSPECTION_SCANNER = @INTROSPECTION_SCANNER@ -INTROSPECTION_TYPELIBDIR = @INTROSPECTION_TYPELIBDIR@ -IPTABLES_PATH = @IPTABLES_PATH@ -JANSSON_CFLAGS = @JANSSON_CFLAGS@ -JANSSON_LIBS = @JANSSON_LIBS@ -KERNEL_FIRMWARE_DIR = @KERNEL_FIRMWARE_DIR@ -LCOV = @LCOV@ -LD = @LD@ -LDFLAGS = @LDFLAGS@ -LIBAUDIT_CFLAGS = @LIBAUDIT_CFLAGS@ -LIBAUDIT_LIBS = @LIBAUDIT_LIBS@ -LIBICONV = @LIBICONV@ -LIBINTL = @LIBINTL@ -LIBM = @LIBM@ -LIBNDP_CFLAGS = @LIBNDP_CFLAGS@ -LIBNDP_LIBS = @LIBNDP_LIBS@ -LIBNL_CFLAGS = @LIBNL_CFLAGS@ -LIBNL_LIBS = @LIBNL_LIBS@ -LIBOBJS = @LIBOBJS@ -LIBS = @LIBS@ -LIBSOUP_CFLAGS = @LIBSOUP_CFLAGS@ -LIBSOUP_LIBS = @LIBSOUP_LIBS@ -LIBSYSTEMD_CFLAGS = @LIBSYSTEMD_CFLAGS@ -LIBSYSTEMD_LIBS = @LIBSYSTEMD_LIBS@ -LIBTEAMDCTL_CFLAGS = @LIBTEAMDCTL_CFLAGS@ -LIBTEAMDCTL_LIBS = @LIBTEAMDCTL_LIBS@ -LIBTOOL = @LIBTOOL@ -LIPO = @LIPO@ -LN_S = @LN_S@ -LOG_DRIVER = @LOG_DRIVER@ -LTLIBICONV = @LTLIBICONV@ -LTLIBINTL = @LTLIBINTL@ -LTLIBOBJS = @LTLIBOBJS@ -LT_SYS_LIBRARY_PATH = @LT_SYS_LIBRARY_PATH@ -MAINT = @MAINT@ -MAKEINFO = @MAKEINFO@ -MANIFEST_TOOL = @MANIFEST_TOOL@ -MKDIR_P = @MKDIR_P@ -MM_GLIB_CFLAGS = @MM_GLIB_CFLAGS@ -MM_GLIB_LIBS = @MM_GLIB_LIBS@ -MOC = @MOC@ -MSGFMT = @MSGFMT@ -MSGFMT_015 = @MSGFMT_015@ -MSGMERGE = @MSGMERGE@ -NEWT_CFLAGS = @NEWT_CFLAGS@ -NEWT_LIBS = @NEWT_LIBS@ -NM = @NM@ -NMEDIT = @NMEDIT@ -NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT = @NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT@ -NM_CONFIG_DEFAULT_DNS_RC_MANAGER = @NM_CONFIG_DEFAULT_DNS_RC_MANAGER@ -NM_CONFIG_DEFAULT_LOGGING_AUDIT_TEXT = @NM_CONFIG_DEFAULT_LOGGING_AUDIT_TEXT@ -NM_CONFIG_LOGGING_BACKEND_DEFAULT_TEXT = @NM_CONFIG_LOGGING_BACKEND_DEFAULT_TEXT@ -NM_MAJOR_VERSION = @NM_MAJOR_VERSION@ -NM_MICRO_VERSION = @NM_MICRO_VERSION@ -NM_MINOR_VERSION = @NM_MINOR_VERSION@ -NM_MODIFY_SYSTEM_POLICY = @NM_MODIFY_SYSTEM_POLICY@ -NM_VERSION = @NM_VERSION@ -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@ -PERL = @PERL@ -PKG_CONFIG = @PKG_CONFIG@ -PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ -PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ -POLKIT_CFLAGS = @POLKIT_CFLAGS@ -POLKIT_LIBS = @POLKIT_LIBS@ -POSUB = @POSUB@ -PPPD_PATH = @PPPD_PATH@ -PPPD_PLUGIN_DIR = @PPPD_PLUGIN_DIR@ -QT_CFLAGS = @QT_CFLAGS@ -QT_LIBS = @QT_LIBS@ -RANLIB = @RANLIB@ -READLINE_LIBS = @READLINE_LIBS@ -SANITIZERS = @SANITIZERS@ -SANITIZER_ENV = @SANITIZER_ENV@ -SED = @SED@ -SELINUX_CFLAGS = @SELINUX_CFLAGS@ -SELINUX_LIBS = @SELINUX_LIBS@ -SET_MAKE = @SET_MAKE@ -SHELL = @SHELL@ -STRIP = @STRIP@ -SYSTEMD_200_CFLAGS = @SYSTEMD_200_CFLAGS@ -SYSTEMD_200_LIBS = @SYSTEMD_200_LIBS@ -SYSTEMD_INHIBIT_CFLAGS = @SYSTEMD_INHIBIT_CFLAGS@ -SYSTEMD_INHIBIT_LIBS = @SYSTEMD_INHIBIT_LIBS@ -SYSTEMD_JOURNAL_CFLAGS = @SYSTEMD_JOURNAL_CFLAGS@ -SYSTEMD_JOURNAL_LIBS = @SYSTEMD_JOURNAL_LIBS@ -SYSTEMD_LOGIN_CFLAGS = @SYSTEMD_LOGIN_CFLAGS@ -SYSTEMD_LOGIN_LIBS = @SYSTEMD_LOGIN_LIBS@ -SYSTEM_CA_PATH = @SYSTEM_CA_PATH@ -UDEV_DIR = @UDEV_DIR@ -USE_NLS = @USE_NLS@ -UUID_CFLAGS = @UUID_CFLAGS@ -UUID_LIBS = @UUID_LIBS@ -VALGRIND_RULES = @VALGRIND_RULES@ -VAPIGEN = @VAPIGEN@ -VAPIGEN_MAKEFILE = @VAPIGEN_MAKEFILE@ -VAPIGEN_VAPIDIR = @VAPIGEN_VAPIDIR@ -VERSION = @VERSION@ -XGETTEXT = @XGETTEXT@ -XGETTEXT_015 = @XGETTEXT_015@ -XGETTEXT_EXTRA_OPTIONS = @XGETTEXT_EXTRA_OPTIONS@ -abs_builddir = @abs_builddir@ -abs_srcdir = @abs_srcdir@ -abs_top_builddir = @abs_top_builddir@ -abs_top_srcdir = @abs_top_srcdir@ -ac_ct_AR = @ac_ct_AR@ -ac_ct_CC = @ac_ct_CC@ -ac_ct_CXX = @ac_ct_CXX@ -ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ -ac_ct_RANLIB = @ac_ct_RANLIB@ -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@ -intltool__v_merge_options_ = @intltool__v_merge_options_@ -intltool__v_merge_options_0 = @intltool__v_merge_options_0@ -libdir = @libdir@ -libexecdir = @libexecdir@ -localedir = @localedir@ -localstatedir = @localstatedir@ -mandir = @mandir@ -mkdir_p = @mkdir_p@ -nmbinary = @nmbinary@ -nmconfdir = @nmconfdir@ -nmdatadir = @nmdatadir@ -nmlibdir = @nmlibdir@ -nmrundir = @nmrundir@ -nmstatedir = @nmstatedir@ -oldincludedir = @oldincludedir@ -pdfdir = @pdfdir@ -prefix = @prefix@ -program_transform_name = @program_transform_name@ -psdir = @psdir@ -runstatedir = @runstatedir@ -sbindir = @sbindir@ -sharedstatedir = @sharedstatedir@ -srcdir = @srcdir@ -subdirs = @subdirs@ -sysconfdir = @sysconfdir@ -systemdsystemunitdir = @systemdsystemunitdir@ -target_alias = @target_alias@ -top_build_prefix = @top_build_prefix@ -top_builddir = @top_builddir@ -top_srcdir = @top_srcdir@ -with_dhclient = @with_dhclient@ -with_dhcpcd = @with_dhcpcd@ -with_netconfig = @with_netconfig@ -with_resolvconf = @with_resolvconf@ -with_valgrind = @with_valgrind@ -SUBDIRS = . tests - -# See note about gdbus-codegen in introspection/Makefile.am -noinst_LTLIBRARIES = libnmdbus-ifcfg-rh.la libifcfg-rh-io.la -nodist_libnmdbus_ifcfg_rh_la_SOURCES = \ - nmdbus-ifcfg-rh.c \ - nmdbus-ifcfg-rh.h - -libnmdbus_ifcfg_rh_la_CPPFLAGS = $(filter-out -DGLIB_VERSION_MAX_ALLOWED%,$(AM_CPPFLAGS)) -BUILT_SOURCES = nmdbus-ifcfg-rh.h nmdbus-ifcfg-rh.c -pkglib_LTLIBRARIES = libnm-settings-plugin-ifcfg-rh.la -libifcfg_rh_io_la_SOURCES = \ - shvar.c \ - shvar.h \ - reader.c \ - reader.h \ - writer.c \ - writer.h \ - common.h \ - utils.c \ - utils.h - -AM_CPPFLAGS = \ - -I$(top_srcdir)/src/ \ - -I$(top_srcdir)/src/platform \ - -I$(top_srcdir)/src/settings \ - -I$(top_srcdir)/shared \ - -I$(top_builddir)/shared \ - -I$(top_srcdir)/libnm-core \ - -I$(top_builddir)/libnm-core \ - -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \ - $(GLIB_CFLAGS) \ - $(NSS_CFLAGS) \ - -DG_LOG_DOMAIN=\""NetworkManager-ifcfg-rh"\" \ - -DSYSCONFDIR=\"$(sysconfdir)\" \ - -DSBINDIR=\"$(sbindir)\" - -libnm_settings_plugin_ifcfg_rh_la_SOURCES = \ - plugin.c \ - plugin.h \ - nm-ifcfg-connection.c \ - nm-ifcfg-connection.h - -libnm_settings_plugin_ifcfg_rh_la_LDFLAGS = -module -avoid-version -libnm_settings_plugin_ifcfg_rh_la_LIBADD = libifcfg-rh-io.la libnmdbus-ifcfg-rh.la -dbusservicedir = $(DBUS_SYS_DIR) -dbusservice_DATA = nm-ifcfg-rh.conf -EXTRA_DIST = \ - $(dbusservice_DATA) \ - nm-ifcfg-rh.xml - -CLEANFILES = $(BUILT_SOURCES) -all: $(BUILT_SOURCES) - $(MAKE) $(AM_MAKEFLAGS) all-recursive - -.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/settings/plugins/ifcfg-rh/Makefile'; \ - $(am__cd) $(top_srcdir) && \ - $(AUTOMAKE) --gnu src/settings/plugins/ifcfg-rh/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)'; \ - locs=`for p in $$list; do echo $$p; done | \ - sed 's|^[^/]*$$|.|; s|/[^/]*$$||; s|$$|/so_locations|' | \ - sort -u`; \ - test -z "$$locs" || { \ - echo rm -f $${locs}; \ - rm -f $${locs}; \ - } - -install-pkglibLTLIBRARIES: $(pkglib_LTLIBRARIES) - @$(NORMAL_INSTALL) - @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 " $(MKDIR_P) '$(DESTDIR)$(pkglibdir)'"; \ - $(MKDIR_P) "$(DESTDIR)$(pkglibdir)" || exit 1; \ - 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)'; \ - locs=`for p in $$list; do echo $$p; done | \ - sed 's|^[^/]*$$|.|; s|/[^/]*$$||; s|$$|/so_locations|' | \ - sort -u`; \ - test -z "$$locs" || { \ - echo rm -f $${locs}; \ - rm -f $${locs}; \ - } - -libifcfg-rh-io.la: $(libifcfg_rh_io_la_OBJECTS) $(libifcfg_rh_io_la_DEPENDENCIES) $(EXTRA_libifcfg_rh_io_la_DEPENDENCIES) - $(AM_V_CCLD)$(LINK) $(libifcfg_rh_io_la_OBJECTS) $(libifcfg_rh_io_la_LIBADD) $(LIBS) - -libnm-settings-plugin-ifcfg-rh.la: $(libnm_settings_plugin_ifcfg_rh_la_OBJECTS) $(libnm_settings_plugin_ifcfg_rh_la_DEPENDENCIES) $(EXTRA_libnm_settings_plugin_ifcfg_rh_la_DEPENDENCIES) - $(AM_V_CCLD)$(libnm_settings_plugin_ifcfg_rh_la_LINK) -rpath $(pkglibdir) $(libnm_settings_plugin_ifcfg_rh_la_OBJECTS) $(libnm_settings_plugin_ifcfg_rh_la_LIBADD) $(LIBS) - -libnmdbus-ifcfg-rh.la: $(libnmdbus_ifcfg_rh_la_OBJECTS) $(libnmdbus_ifcfg_rh_la_DEPENDENCIES) $(EXTRA_libnmdbus_ifcfg_rh_la_DEPENDENCIES) - $(AM_V_CCLD)$(LINK) $(libnmdbus_ifcfg_rh_la_OBJECTS) $(libnmdbus_ifcfg_rh_la_LIBADD) $(LIBS) - -mostlyclean-compile: - -rm -f *.$(OBJEXT) - -distclean-compile: - -rm -f *.tab.c - -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libnmdbus_ifcfg_rh_la-nmdbus-ifcfg-rh.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nm-ifcfg-connection.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/plugin.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/reader.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/shvar.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/utils.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/writer.Plo@am__quote@ - -.c.o: -@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ $< - -.c.obj: -@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'` - -.c.lo: -@am__fastdepCC_TRUE@ $(AM_V_CC)$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $< - -libnmdbus_ifcfg_rh_la-nmdbus-ifcfg-rh.lo: nmdbus-ifcfg-rh.c -@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libnmdbus_ifcfg_rh_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libnmdbus_ifcfg_rh_la-nmdbus-ifcfg-rh.lo -MD -MP -MF $(DEPDIR)/libnmdbus_ifcfg_rh_la-nmdbus-ifcfg-rh.Tpo -c -o libnmdbus_ifcfg_rh_la-nmdbus-ifcfg-rh.lo `test -f 'nmdbus-ifcfg-rh.c' || echo '$(srcdir)/'`nmdbus-ifcfg-rh.c -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libnmdbus_ifcfg_rh_la-nmdbus-ifcfg-rh.Tpo $(DEPDIR)/libnmdbus_ifcfg_rh_la-nmdbus-ifcfg-rh.Plo -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='nmdbus-ifcfg-rh.c' object='libnmdbus_ifcfg_rh_la-nmdbus-ifcfg-rh.lo' libtool=yes @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libnmdbus_ifcfg_rh_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libnmdbus_ifcfg_rh_la-nmdbus-ifcfg-rh.lo `test -f 'nmdbus-ifcfg-rh.c' || echo '$(srcdir)/'`nmdbus-ifcfg-rh.c - -mostlyclean-libtool: - -rm -f *.lo - -clean-libtool: - -rm -rf .libs _libs -install-dbusserviceDATA: $(dbusservice_DATA) - @$(NORMAL_INSTALL) - @list='$(dbusservice_DATA)'; test -n "$(dbusservicedir)" || list=; \ - if test -n "$$list"; then \ - echo " $(MKDIR_P) '$(DESTDIR)$(dbusservicedir)'"; \ - $(MKDIR_P) "$(DESTDIR)$(dbusservicedir)" || exit 1; \ - fi; \ - for p in $$list; do \ - if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ - echo "$$d$$p"; \ - done | $(am__base_list) | \ - while read files; do \ - echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(dbusservicedir)'"; \ - $(INSTALL_DATA) $$files "$(DESTDIR)$(dbusservicedir)" || exit $$?; \ - done - -uninstall-dbusserviceDATA: - @$(NORMAL_UNINSTALL) - @list='$(dbusservice_DATA)'; test -n "$(dbusservicedir)" || list=; \ - files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \ - dir='$(DESTDIR)$(dbusservicedir)'; $(am__uninstall_files_from_dir) - -# This directory's subdirectories are mostly independent; you can cd -# into them and run 'make' without going through this Makefile. -# To change the values of 'make' variables: instead of editing Makefiles, -# (1) if the variable is set in 'config.status', edit 'config.status' -# (which will cause the Makefiles to be regenerated when you run 'make'); -# (2) otherwise, pass the desired values on the 'make' command line. -$(am__recursive_targets): - @fail=; \ - if $(am__make_keepgoing); then \ - failcom='fail=yes'; \ - else \ - failcom='exit 1'; \ - fi; \ - dot_seen=no; \ - target=`echo $@ | sed s/-recursive//`; \ - case "$@" in \ - distclean-* | maintainer-clean-*) list='$(DIST_SUBDIRS)' ;; \ - *) list='$(SUBDIRS)' ;; \ - esac; \ - for subdir in $$list; do \ - echo "Making $$target in $$subdir"; \ - if test "$$subdir" = "."; then \ - dot_seen=yes; \ - local_target="$$target-am"; \ - else \ - local_target="$$target"; \ - fi; \ - ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \ - || eval $$failcom; \ - done; \ - if test "$$dot_seen" = "no"; then \ - $(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \ - fi; test -z "$$fail" - -ID: $(am__tagged_files) - $(am__define_uniq_tagged_files); mkid -fID $$unique -tags: tags-recursive -TAGS: tags - -tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) - set x; \ - here=`pwd`; \ - if ($(ETAGS) --etags-include --version) >/dev/null 2>&1; then \ - include_option=--etags-include; \ - empty_fix=.; \ - else \ - include_option=--include; \ - empty_fix=; \ - fi; \ - list='$(SUBDIRS)'; for subdir in $$list; do \ - if test "$$subdir" = .; then :; else \ - test ! -f $$subdir/TAGS || \ - set "$$@" "$$include_option=$$here/$$subdir/TAGS"; \ - fi; \ - done; \ - $(am__define_uniq_tagged_files); \ - 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-recursive - -CTAGS: ctags -ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) - $(am__define_uniq_tagged_files); \ - 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" -cscopelist: cscopelist-recursive - -cscopelist-am: $(am__tagged_files) - list='$(am__tagged_files)'; \ - case "$(srcdir)" in \ - [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \ - *) sdir=$(subdir)/$(srcdir) ;; \ - esac; \ - for i in $$list; do \ - if test -f "$$i"; then \ - echo "$(subdir)/$$i"; \ - else \ - echo "$$sdir/$$i"; \ - fi; \ - done >> $(top_builddir)/cscope.files - -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 - @list='$(DIST_SUBDIRS)'; for subdir in $$list; do \ - if test "$$subdir" = .; then :; else \ - $(am__make_dryrun) \ - || test -d "$(distdir)/$$subdir" \ - || $(MKDIR_P) "$(distdir)/$$subdir" \ - || exit 1; \ - dir1=$$subdir; dir2="$(distdir)/$$subdir"; \ - $(am__relativize); \ - new_distdir=$$reldir; \ - dir1=$$subdir; dir2="$(top_distdir)"; \ - $(am__relativize); \ - new_top_distdir=$$reldir; \ - echo " (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) top_distdir="$$new_top_distdir" distdir="$$new_distdir" \\"; \ - echo " am__remove_distdir=: am__skip_length_check=: am__skip_mode_fix=: distdir)"; \ - ($(am__cd) $$subdir && \ - $(MAKE) $(AM_MAKEFLAGS) \ - top_distdir="$$new_top_distdir" \ - distdir="$$new_distdir" \ - am__remove_distdir=: \ - am__skip_length_check=: \ - am__skip_mode_fix=: \ - distdir) \ - || exit 1; \ - fi; \ - done -check-am: all-am -check: $(BUILT_SOURCES) - $(MAKE) $(AM_MAKEFLAGS) check-recursive -all-am: Makefile $(LTLIBRARIES) $(DATA) -installdirs: installdirs-recursive -installdirs-am: - for dir in "$(DESTDIR)$(pkglibdir)" "$(DESTDIR)$(dbusservicedir)"; do \ - test -z "$$dir" || $(MKDIR_P) "$$dir"; \ - done -install: $(BUILT_SOURCES) - $(MAKE) $(AM_MAKEFLAGS) install-recursive -install-exec: install-exec-recursive -install-data: install-data-recursive -uninstall: uninstall-recursive - -install-am: all-am - @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am - -installcheck: installcheck-recursive -install-strip: - if test -z '$(STRIP)'; then \ - $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ - install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ - install; \ - else \ - $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ - install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ - "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ - fi -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-recursive - -clean-am: clean-generic clean-libtool clean-noinstLTLIBRARIES \ - clean-pkglibLTLIBRARIES mostlyclean-am - -distclean: distclean-recursive - -rm -rf ./$(DEPDIR) - -rm -f Makefile -distclean-am: clean-am distclean-compile distclean-generic \ - distclean-tags - -dvi: dvi-recursive - -dvi-am: - -html: html-recursive - -html-am: - -info: info-recursive - -info-am: - -install-data-am: install-dbusserviceDATA - -install-dvi: install-dvi-recursive - -install-dvi-am: - -install-exec-am: install-pkglibLTLIBRARIES - -install-html: install-html-recursive - -install-html-am: - -install-info: install-info-recursive - -install-info-am: - -install-man: - -install-pdf: install-pdf-recursive - -install-pdf-am: - -install-ps: install-ps-recursive - -install-ps-am: - -installcheck-am: - -maintainer-clean: maintainer-clean-recursive - -rm -rf ./$(DEPDIR) - -rm -f Makefile -maintainer-clean-am: distclean-am maintainer-clean-generic - -mostlyclean: mostlyclean-recursive - -mostlyclean-am: mostlyclean-compile mostlyclean-generic \ - mostlyclean-libtool - -pdf: pdf-recursive - -pdf-am: - -ps: ps-recursive - -ps-am: - -uninstall-am: uninstall-dbusserviceDATA uninstall-pkglibLTLIBRARIES - -.MAKE: $(am__recursive_targets) all check install install-am \ - install-strip - -.PHONY: $(am__recursive_targets) CTAGS GTAGS TAGS all all-am check \ - check-am clean clean-generic clean-libtool \ - clean-noinstLTLIBRARIES clean-pkglibLTLIBRARIES cscopelist-am \ - ctags ctags-am 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-dbusserviceDATA 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 installdirs-am maintainer-clean \ - maintainer-clean-generic mostlyclean mostlyclean-compile \ - mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ - tags tags-am uninstall uninstall-am uninstall-dbusserviceDATA \ - uninstall-pkglibLTLIBRARIES - -.PRECIOUS: Makefile - - -@GNOME_CODE_COVERAGE_RULES@ - -nmdbus-ifcfg-rh.h: nm-ifcfg-rh.xml - $(AM_V_GEN) gdbus-codegen \ - --generate-c-code $(basename $@) \ - --c-namespace NMDBus \ - --interface-prefix com.redhat \ - $< - -nmdbus-ifcfg-rh.c: nmdbus-ifcfg-rh.h - @true - -# 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/settings/plugins/ifcfg-rh/common.h b/src/settings/plugins/ifcfg-rh/common.h deleted file mode 100644 index d850ac4e..00000000 --- a/src/settings/plugins/ifcfg-rh/common.h +++ /dev/null @@ -1,82 +0,0 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* NetworkManager system settings service - * - * 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 - 2013 Red Hat, Inc. - */ - -#ifndef __COMMON_H__ -#define __COMMON_H__ - -#define IFCFG_TAG "ifcfg-" -#define KEYS_TAG "keys-" -#define ROUTE_TAG "route-" -#define RULE_TAG "rule-" -#define ROUTE6_TAG "route6-" -#define RULE6_TAG "rule6-" - -#define BAK_TAG ".bak" -#define TILDE_TAG "~" -#define ORIG_TAG ".orig" -#define REJ_TAG ".rej" -#define RPMNEW_TAG ".rpmnew" -#define AUGNEW_TAG ".augnew" -#define AUGTMP_TAG ".augtmp" - -#define IFCFG_DIR SYSCONFDIR "/sysconfig/network-scripts" - -#define IFCFG_PLUGIN_NAME "ifcfg-rh" -#define IFCFG_PLUGIN_INFO "(c) 2007 - 2015 Red Hat, Inc. To report bugs please use the NetworkManager mailing list." - -#define TYPE_ETHERNET "Ethernet" -#define TYPE_WIRELESS "Wireless" -#define TYPE_INFINIBAND "InfiniBand" -#define TYPE_BRIDGE "Bridge" -#define TYPE_BOND "Bond" -#define TYPE_VLAN "Vlan" -#define TYPE_TEAM "Team" -#define TYPE_TEAM_PORT "TeamPort" - -#define SECRET_FLAG_AGENT "user" -#define SECRET_FLAG_NOT_SAVED "ask" -#define SECRET_FLAG_NOT_REQUIRED "unused" - -/* DCB key names */ -#define KEY_DCB_APP_FCOE_ENABLE "DCB_APP_FCOE_ENABLE" -#define KEY_DCB_APP_FCOE_ADVERTISE "DCB_APP_FCOE_ADVERTISE" -#define KEY_DCB_APP_FCOE_WILLING "DCB_APP_FCOE_WILLING" -#define KEY_DCB_APP_FCOE_MODE "DCB_APP_FCOE_MODE" -#define KEY_DCB_APP_ISCSI_ENABLE "DCB_APP_ISCSI_ENABLE" -#define KEY_DCB_APP_ISCSI_ADVERTISE "DCB_APP_ISCSI_ADVERTISE" -#define KEY_DCB_APP_ISCSI_WILLING "DCB_APP_ISCSI_WILLING" -#define KEY_DCB_APP_FIP_ENABLE "DCB_APP_FIP_ENABLE" -#define KEY_DCB_APP_FIP_ADVERTISE "DCB_APP_FIP_ADVERTISE" -#define KEY_DCB_APP_FIP_WILLING "DCB_APP_FIP_WILLING" -#define KEY_DCB_PFC_ENABLE "DCB_PFC_ENABLE" -#define KEY_DCB_PFC_ADVERTISE "DCB_PFC_ADVERTISE" -#define KEY_DCB_PFC_WILLING "DCB_PFC_WILLING" -#define KEY_DCB_PFC_UP "DCB_PFC_UP" -#define KEY_DCB_PG_ENABLE "DCB_PG_ENABLE" -#define KEY_DCB_PG_ADVERTISE "DCB_PG_ADVERTISE" -#define KEY_DCB_PG_WILLING "DCB_PG_WILLING" -#define KEY_DCB_PG_ID "DCB_PG_ID" -#define KEY_DCB_PG_PCT "DCB_PG_PCT" -#define KEY_DCB_PG_UPPCT "DCB_PG_UPPCT" -#define KEY_DCB_PG_STRICT "DCB_PG_STRICT" -#define KEY_DCB_PG_UP2TC "DCB_PG_UP2TC" - -#endif /* __COMMON_H__ */ - diff --git a/src/settings/plugins/ifcfg-rh/nm-ifcfg-connection.c b/src/settings/plugins/ifcfg-rh/nm-ifcfg-connection.c deleted file mode 100644 index a83bd35d..00000000 --- a/src/settings/plugins/ifcfg-rh/nm-ifcfg-connection.c +++ /dev/null @@ -1,566 +0,0 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* NetworkManager system settings service - * - * 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 - 2011 Red Hat, Inc. - */ - -#include "nm-default.h" - -#include "nm-ifcfg-connection.h" - -#include - -#include - -#include "nm-dbus-interface.h" -#include "nm-setting-connection.h" -#include "nm-setting-wired.h" -#include "nm-setting-wireless.h" -#include "nm-setting-gsm.h" -#include "nm-setting-cdma.h" -#include "nm-setting-pppoe.h" -#include "nm-setting-wireless-security.h" -#include "nm-setting-8021x.h" -#include "nm-platform.h" - -#include "common.h" -#include "nm-config.h" -#include "reader.h" -#include "writer.h" -#include "nm-inotify-helper.h" -#include "utils.h" - -G_DEFINE_TYPE (NMIfcfgConnection, nm_ifcfg_connection, NM_TYPE_SETTINGS_CONNECTION) - -#define NM_IFCFG_CONNECTION_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_IFCFG_CONNECTION, NMIfcfgConnectionPrivate)) - -typedef struct { - gulong ih_event_id; - - int file_wd; - - char *keyfile; - int keyfile_wd; - - char *routefile; - int routefile_wd; - - char *route6file; - int route6file_wd; - - char *unmanaged_spec; - char *unrecognized_spec; - - gulong devtimeout_link_changed_handler; - guint devtimeout_timeout_id; - - NMInotifyHelper *inotify_helper; -} NMIfcfgConnectionPrivate; - -enum { - PROP_0, - PROP_UNMANAGED_SPEC, - PROP_UNRECOGNIZED_SPEC, - LAST_PROP -}; - -/* Signals */ -enum { - IFCFG_CHANGED, - LAST_SIGNAL -}; - -static guint signals[LAST_SIGNAL] = { 0 }; - -static NMInotifyHelper * -_get_inotify_helper (NMIfcfgConnectionPrivate *priv) -{ - if (!priv->inotify_helper) - priv->inotify_helper = g_object_ref (nm_inotify_helper_get ()); - return priv->inotify_helper; -} - -static gboolean -devtimeout_ready (gpointer user_data) -{ - NMIfcfgConnection *self = user_data; - NMIfcfgConnectionPrivate *priv = NM_IFCFG_CONNECTION_GET_PRIVATE (self); - - priv->devtimeout_timeout_id = 0; - nm_settings_connection_set_ready (NM_SETTINGS_CONNECTION (self), TRUE); - return FALSE; -} - -static void -link_changed (NMPlatform *platform, NMPObjectType obj_type, int ifindex, const NMPlatformLink *link, - NMPlatformSignalChangeType change_type, - NMConnection *self) -{ - NMIfcfgConnectionPrivate *priv = NM_IFCFG_CONNECTION_GET_PRIVATE (self); - const char *ifname; - - ifname = nm_connection_get_interface_name (self); - if (g_strcmp0 (link->name, ifname) != 0) - return; - - if (change_type == NM_PLATFORM_SIGNAL_REMOVED) - return; - - nm_log_info (LOGD_SETTINGS, "Device %s appeared; connection '%s' now ready", - ifname, nm_connection_get_id (self)); - - g_signal_handler_disconnect (platform, priv->devtimeout_link_changed_handler); - priv->devtimeout_link_changed_handler = 0; - g_source_remove (priv->devtimeout_timeout_id); - - /* Don't declare the connection ready right away, since NMManager may not have - * started processing the device yet. - */ - priv->devtimeout_timeout_id = g_idle_add (devtimeout_ready, self); -} - -static gboolean -devtimeout_expired (gpointer user_data) -{ - NMIfcfgConnection *self = user_data; - NMIfcfgConnectionPrivate *priv = NM_IFCFG_CONNECTION_GET_PRIVATE (self); - - nm_log_info (LOGD_SETTINGS, "Device for connection '%s' did not appear before timeout", - nm_connection_get_id (NM_CONNECTION (self))); - - g_signal_handler_disconnect (NM_PLATFORM_GET, priv->devtimeout_link_changed_handler); - priv->devtimeout_link_changed_handler = 0; - priv->devtimeout_timeout_id = 0; - - nm_settings_connection_set_ready (NM_SETTINGS_CONNECTION (self), TRUE); - return FALSE; -} - -static void -nm_ifcfg_connection_check_devtimeout (NMIfcfgConnection *self) -{ - NMIfcfgConnectionPrivate *priv = NM_IFCFG_CONNECTION_GET_PRIVATE (self); - NMSettingConnection *s_con; - const char *ifname; - const char *filename; - guint devtimeout; - const NMPlatformLink *pllink; - - s_con = nm_connection_get_setting_connection (NM_CONNECTION (self)); - - if (!nm_setting_connection_get_autoconnect (s_con)) - return; - ifname = nm_setting_connection_get_interface_name (s_con); - if (!ifname) - return; - filename = nm_settings_connection_get_filename (NM_SETTINGS_CONNECTION (self)); - if (!filename) - return; - - pllink = nm_platform_link_get_by_ifname (NM_PLATFORM_GET, ifname); - if (pllink && pllink->initialized) - return; - - devtimeout = devtimeout_from_file (filename); - if (!devtimeout) - return; - - /* ONBOOT=yes, DEVICE and DEVTIMEOUT are set, but device is not present */ - nm_settings_connection_set_ready (NM_SETTINGS_CONNECTION (self), FALSE); - - nm_log_info (LOGD_SETTINGS, "Waiting %u seconds for %s to appear for connection '%s'", - devtimeout, ifname, nm_connection_get_id (NM_CONNECTION (self))); - - priv->devtimeout_link_changed_handler = - g_signal_connect (NM_PLATFORM_GET, NM_PLATFORM_SIGNAL_LINK_CHANGED, - G_CALLBACK (link_changed), self); - priv->devtimeout_timeout_id = g_timeout_add_seconds (devtimeout, devtimeout_expired, self); -} - -static void -files_changed_cb (NMInotifyHelper *ih, - struct inotify_event *evt, - const char *path, - gpointer user_data) -{ - NMIfcfgConnection *self = NM_IFCFG_CONNECTION (user_data); - NMIfcfgConnectionPrivate *priv = NM_IFCFG_CONNECTION_GET_PRIVATE (self); - - if ( (evt->wd != priv->file_wd) - && (evt->wd != priv->keyfile_wd) - && (evt->wd != priv->routefile_wd) - && (evt->wd != priv->route6file_wd)) - return; - - /* push the event up to the plugin */ - g_signal_emit (self, signals[IFCFG_CHANGED], 0); -} - -NMIfcfgConnection * -nm_ifcfg_connection_new (NMConnection *source, - const char *full_path, - GError **error, - gboolean *out_ignore_error) -{ - GObject *object; - NMConnection *tmp; - char *unhandled_spec = NULL; - const char *unmanaged_spec = NULL, *unrecognized_spec = NULL; - gboolean update_unsaved = TRUE; - - g_assert (source || full_path); - - if (out_ignore_error) - *out_ignore_error = FALSE; - - /* If we're given a connection already, prefer that instead of re-reading */ - if (source) - tmp = g_object_ref (source); - else { - tmp = connection_from_file (full_path, - &unhandled_spec, - error, - out_ignore_error); - if (!tmp) - return NULL; - - /* If we just read the connection from disk, it's clearly not Unsaved */ - update_unsaved = FALSE; - } - - if (unhandled_spec && g_str_has_prefix (unhandled_spec, "unmanaged:")) - unmanaged_spec = unhandled_spec + strlen ("unmanaged:"); - else if (unhandled_spec && g_str_has_prefix (unhandled_spec, "unrecognized:")) - unrecognized_spec = unhandled_spec + strlen ("unrecognized:"); - - object = (GObject *) g_object_new (NM_TYPE_IFCFG_CONNECTION, - NM_SETTINGS_CONNECTION_FILENAME, full_path, - NM_IFCFG_CONNECTION_UNMANAGED_SPEC, unmanaged_spec, - NM_IFCFG_CONNECTION_UNRECOGNIZED_SPEC, unrecognized_spec, - NULL); - /* Update our settings with what was read from the file */ - if (nm_settings_connection_replace_settings (NM_SETTINGS_CONNECTION (object), - tmp, - update_unsaved, - NULL, - error)) - nm_ifcfg_connection_check_devtimeout (NM_IFCFG_CONNECTION (object)); - else - g_clear_object (&object); - - g_object_unref (tmp); - g_free (unhandled_spec); - return (NMIfcfgConnection *) object; -} - -static void -path_watch_stop (NMIfcfgConnection *self) -{ - NMIfcfgConnectionPrivate *priv = NM_IFCFG_CONNECTION_GET_PRIVATE (self); - NMInotifyHelper *ih; - - ih = _get_inotify_helper (priv); - - nm_clear_g_signal_handler (ih, &priv->ih_event_id); - - if (priv->file_wd >= 0) { - nm_inotify_helper_remove_watch (ih, priv->file_wd); - priv->file_wd = -1; - } - - g_free (priv->keyfile); - priv->keyfile = NULL; - if (priv->keyfile_wd >= 0) { - nm_inotify_helper_remove_watch (ih, priv->keyfile_wd); - priv->keyfile_wd = -1; - } - - g_free (priv->routefile); - priv->routefile = NULL; - if (priv->routefile_wd >= 0) { - nm_inotify_helper_remove_watch (ih, priv->routefile_wd); - priv->routefile_wd = -1; - } - - g_free (priv->route6file); - priv->route6file = NULL; - if (priv->route6file_wd >= 0) { - nm_inotify_helper_remove_watch (ih, priv->route6file_wd); - priv->route6file_wd = -1; - } -} - -static void -filename_changed (GObject *object, - GParamSpec *pspec, - gpointer user_data) -{ - NMIfcfgConnection *self = NM_IFCFG_CONNECTION (object); - NMIfcfgConnectionPrivate *priv = NM_IFCFG_CONNECTION_GET_PRIVATE (self); - const char *ifcfg_path; - - path_watch_stop (self); - - ifcfg_path = nm_settings_connection_get_filename (NM_SETTINGS_CONNECTION (self)); - if (!ifcfg_path) - return; - - priv->keyfile = utils_get_keys_path (ifcfg_path); - priv->routefile = utils_get_route_path (ifcfg_path); - priv->route6file = utils_get_route6_path (ifcfg_path); - - if (nm_config_get_monitor_connection_files (nm_config_get ())) { - NMInotifyHelper *ih; - - ih = _get_inotify_helper (priv); - - priv->ih_event_id = g_signal_connect (ih, "event", G_CALLBACK (files_changed_cb), self); - priv->file_wd = nm_inotify_helper_add_watch (ih, ifcfg_path); - priv->keyfile_wd = nm_inotify_helper_add_watch (ih, priv->keyfile); - priv->routefile_wd = nm_inotify_helper_add_watch (ih, priv->routefile); - priv->route6file_wd = nm_inotify_helper_add_watch (ih, priv->route6file); - } -} - -const char * -nm_ifcfg_connection_get_unmanaged_spec (NMIfcfgConnection *self) -{ - g_return_val_if_fail (NM_IS_IFCFG_CONNECTION (self), NULL); - - return NM_IFCFG_CONNECTION_GET_PRIVATE (self)->unmanaged_spec; -} - -const char * -nm_ifcfg_connection_get_unrecognized_spec (NMIfcfgConnection *self) -{ - g_return_val_if_fail (NM_IS_IFCFG_CONNECTION (self), NULL); - - return NM_IFCFG_CONNECTION_GET_PRIVATE (self)->unrecognized_spec; -} - -static void -replace_and_commit (NMSettingsConnection *connection, - NMConnection *new_connection, - NMSettingsConnectionCommitFunc callback, - gpointer user_data) -{ - const char *filename; - GError *error = NULL; - - filename = nm_settings_connection_get_filename (connection); - if (filename && utils_has_complex_routes (filename)) { - if (callback) { - error = g_error_new_literal (NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, - "Cannot modify a connection that has an associated 'rule-' or 'rule6-' file"); - callback (connection, error, user_data); - g_clear_error (&error); - } - return; - } - - NM_SETTINGS_CONNECTION_CLASS (nm_ifcfg_connection_parent_class)->replace_and_commit (connection, new_connection, callback, user_data); -} - -static void -commit_changes (NMSettingsConnection *connection, - NMSettingsConnectionCommitReason commit_reason, - NMSettingsConnectionCommitFunc callback, - gpointer user_data) -{ - NMIfcfgConnectionPrivate *priv = NM_IFCFG_CONNECTION_GET_PRIVATE (connection); - GError *error = NULL; - NMConnection *reread; - gboolean same = FALSE, success = FALSE; - char *ifcfg_path = NULL; - const char *filename; - - /* To ensure we don't rewrite files that are only changed from other - * processes on-disk, read the existing connection back in and only rewrite - * it if it's really changed. - */ - filename = nm_settings_connection_get_filename (connection); - if (filename) { - gs_free char *unhandled = NULL; - - reread = connection_from_file (filename, &unhandled, NULL, NULL); - if (reread) { - same = nm_connection_compare (NM_CONNECTION (connection), - reread, - NM_SETTING_COMPARE_FLAG_IGNORE_AGENT_OWNED_SECRETS | - NM_SETTING_COMPARE_FLAG_IGNORE_NOT_SAVED_SECRETS); - g_object_unref (reread); - - /* Don't bother writing anything out if in-memory and on-disk data are the same */ - if (same) { - /* But chain up to parent to handle success - emits updated signal */ - NM_SETTINGS_CONNECTION_CLASS (nm_ifcfg_connection_parent_class)->commit_changes (connection, commit_reason, callback, user_data); - return; - } - } - - success = writer_update_connection (NM_CONNECTION (connection), - IFCFG_DIR, - filename, - priv->keyfile, - &error); - } else { - success = writer_new_connection (NM_CONNECTION (connection), - IFCFG_DIR, - &ifcfg_path, - &error); - if (success) { - nm_settings_connection_set_filename (connection, ifcfg_path); - g_free (ifcfg_path); - } - } - - if (success) { - /* Chain up to parent to handle success */ - NM_SETTINGS_CONNECTION_CLASS (nm_ifcfg_connection_parent_class)->commit_changes (connection, commit_reason, callback, user_data); - } else { - /* Otherwise immediate error */ - callback (connection, error, user_data); - g_error_free (error); - } -} - -static void -do_delete (NMSettingsConnection *connection, - NMSettingsConnectionDeleteFunc callback, - gpointer user_data) -{ - NMIfcfgConnectionPrivate *priv = NM_IFCFG_CONNECTION_GET_PRIVATE (connection); - const char *filename; - - filename = nm_settings_connection_get_filename (connection); - if (filename) { - g_unlink (filename); - if (priv->keyfile) - g_unlink (priv->keyfile); - if (priv->routefile) - g_unlink (priv->routefile); - if (priv->route6file) - g_unlink (priv->route6file); - } - - NM_SETTINGS_CONNECTION_CLASS (nm_ifcfg_connection_parent_class)->delete (connection, callback, user_data); -} - -/* GObject */ - -static void -nm_ifcfg_connection_init (NMIfcfgConnection *connection) -{ - g_signal_connect (connection, "notify::" NM_SETTINGS_CONNECTION_FILENAME, - G_CALLBACK (filename_changed), NULL); -} - -static void -set_property (GObject *object, guint prop_id, - const GValue *value, GParamSpec *pspec) -{ - NMIfcfgConnectionPrivate *priv = NM_IFCFG_CONNECTION_GET_PRIVATE (object); - - switch (prop_id) { - case PROP_UNMANAGED_SPEC: - priv->unmanaged_spec = g_value_dup_string (value); - break; - case PROP_UNRECOGNIZED_SPEC: - priv->unrecognized_spec = 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) -{ - NMIfcfgConnectionPrivate *priv = NM_IFCFG_CONNECTION_GET_PRIVATE (object); - - switch (prop_id) { - case PROP_UNMANAGED_SPEC: - g_value_set_string (value, priv->unmanaged_spec); - break; - case PROP_UNRECOGNIZED_SPEC: - g_value_set_string (value, priv->unrecognized_spec); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -dispose (GObject *object) -{ - NMIfcfgConnectionPrivate *priv = NM_IFCFG_CONNECTION_GET_PRIVATE (object); - - path_watch_stop (NM_IFCFG_CONNECTION (object)); - - nm_clear_g_signal_handler (NM_PLATFORM_GET, &priv->devtimeout_link_changed_handler); - nm_clear_g_source (&priv->devtimeout_timeout_id); - - g_clear_object (&priv->inotify_helper); - - g_clear_pointer (&priv->unmanaged_spec, g_free); - g_clear_pointer (&priv->unrecognized_spec, g_free); - - G_OBJECT_CLASS (nm_ifcfg_connection_parent_class)->dispose (object); -} - -static void -nm_ifcfg_connection_class_init (NMIfcfgConnectionClass *ifcfg_connection_class) -{ - GObjectClass *object_class = G_OBJECT_CLASS (ifcfg_connection_class); - NMSettingsConnectionClass *settings_class = NM_SETTINGS_CONNECTION_CLASS (ifcfg_connection_class); - - g_type_class_add_private (ifcfg_connection_class, sizeof (NMIfcfgConnectionPrivate)); - - /* Virtual methods */ - object_class->set_property = set_property; - object_class->get_property = get_property; - object_class->dispose = dispose; - settings_class->delete = do_delete; - settings_class->replace_and_commit = replace_and_commit; - settings_class->commit_changes = commit_changes; - - /* Properties */ - g_object_class_install_property - (object_class, PROP_UNMANAGED_SPEC, - g_param_spec_string (NM_IFCFG_CONNECTION_UNMANAGED_SPEC, "", "", - NULL, - G_PARAM_READWRITE | - G_PARAM_STATIC_STRINGS)); - g_object_class_install_property - (object_class, PROP_UNRECOGNIZED_SPEC, - g_param_spec_string (NM_IFCFG_CONNECTION_UNRECOGNIZED_SPEC, "", "", - NULL, - G_PARAM_READWRITE | - G_PARAM_STATIC_STRINGS)); - - signals[IFCFG_CHANGED] = - g_signal_new ("ifcfg-changed", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - 0, NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); -} - diff --git a/src/settings/plugins/ifcfg-rh/nm-ifcfg-connection.h b/src/settings/plugins/ifcfg-rh/nm-ifcfg-connection.h deleted file mode 100644 index 57db059b..00000000 --- a/src/settings/plugins/ifcfg-rh/nm-ifcfg-connection.h +++ /dev/null @@ -1,59 +0,0 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* NetworkManager system settings service - * - * 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 - 2011 Red Hat, Inc. - */ - -#ifndef __NETWORKMANAGER_IFCFG_CONNECTION_H__ -#define __NETWORKMANAGER_IFCFG_CONNECTION_H__ - -#include "nm-dbus-interface.h" -#include "nm-settings-connection.h" - -#define NM_TYPE_IFCFG_CONNECTION (nm_ifcfg_connection_get_type ()) -#define NM_IFCFG_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_IFCFG_CONNECTION, NMIfcfgConnection)) -#define NM_IFCFG_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_IFCFG_CONNECTION, NMIfcfgConnectionClass)) -#define NM_IS_IFCFG_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_IFCFG_CONNECTION)) -#define NM_IS_IFCFG_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_IFCFG_CONNECTION)) -#define NM_IFCFG_CONNECTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_IFCFG_CONNECTION, NMIfcfgConnectionClass)) - -#define NM_IFCFG_CONNECTION_UNMANAGED_SPEC "unmanaged-spec" -#define NM_IFCFG_CONNECTION_UNRECOGNIZED_SPEC "unrecognized-spec" - -typedef struct { - NMSettingsConnection parent; -} NMIfcfgConnection; - -typedef struct { - NMSettingsConnectionClass parent; -} NMIfcfgConnectionClass; - -GType nm_ifcfg_connection_get_type (void); - -NMIfcfgConnection *nm_ifcfg_connection_new (NMConnection *source, - const char *full_path, - GError **error, - gboolean *out_ignore_error); - -const char *nm_ifcfg_connection_get_unmanaged_spec (NMIfcfgConnection *self); -const char *nm_ifcfg_connection_get_unrecognized_spec (NMIfcfgConnection *self); - -gboolean nm_ifcfg_connection_update (NMIfcfgConnection *self, - GHashTable *new_settings, - GError **error); - -#endif /* __NETWORKMANAGER_IFCFG_CONNECTION_H__ */ diff --git a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-common.h b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-common.h new file mode 100644 index 00000000..d850ac4e --- /dev/null +++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-common.h @@ -0,0 +1,82 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/* NetworkManager system settings service + * + * 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 - 2013 Red Hat, Inc. + */ + +#ifndef __COMMON_H__ +#define __COMMON_H__ + +#define IFCFG_TAG "ifcfg-" +#define KEYS_TAG "keys-" +#define ROUTE_TAG "route-" +#define RULE_TAG "rule-" +#define ROUTE6_TAG "route6-" +#define RULE6_TAG "rule6-" + +#define BAK_TAG ".bak" +#define TILDE_TAG "~" +#define ORIG_TAG ".orig" +#define REJ_TAG ".rej" +#define RPMNEW_TAG ".rpmnew" +#define AUGNEW_TAG ".augnew" +#define AUGTMP_TAG ".augtmp" + +#define IFCFG_DIR SYSCONFDIR "/sysconfig/network-scripts" + +#define IFCFG_PLUGIN_NAME "ifcfg-rh" +#define IFCFG_PLUGIN_INFO "(c) 2007 - 2015 Red Hat, Inc. To report bugs please use the NetworkManager mailing list." + +#define TYPE_ETHERNET "Ethernet" +#define TYPE_WIRELESS "Wireless" +#define TYPE_INFINIBAND "InfiniBand" +#define TYPE_BRIDGE "Bridge" +#define TYPE_BOND "Bond" +#define TYPE_VLAN "Vlan" +#define TYPE_TEAM "Team" +#define TYPE_TEAM_PORT "TeamPort" + +#define SECRET_FLAG_AGENT "user" +#define SECRET_FLAG_NOT_SAVED "ask" +#define SECRET_FLAG_NOT_REQUIRED "unused" + +/* DCB key names */ +#define KEY_DCB_APP_FCOE_ENABLE "DCB_APP_FCOE_ENABLE" +#define KEY_DCB_APP_FCOE_ADVERTISE "DCB_APP_FCOE_ADVERTISE" +#define KEY_DCB_APP_FCOE_WILLING "DCB_APP_FCOE_WILLING" +#define KEY_DCB_APP_FCOE_MODE "DCB_APP_FCOE_MODE" +#define KEY_DCB_APP_ISCSI_ENABLE "DCB_APP_ISCSI_ENABLE" +#define KEY_DCB_APP_ISCSI_ADVERTISE "DCB_APP_ISCSI_ADVERTISE" +#define KEY_DCB_APP_ISCSI_WILLING "DCB_APP_ISCSI_WILLING" +#define KEY_DCB_APP_FIP_ENABLE "DCB_APP_FIP_ENABLE" +#define KEY_DCB_APP_FIP_ADVERTISE "DCB_APP_FIP_ADVERTISE" +#define KEY_DCB_APP_FIP_WILLING "DCB_APP_FIP_WILLING" +#define KEY_DCB_PFC_ENABLE "DCB_PFC_ENABLE" +#define KEY_DCB_PFC_ADVERTISE "DCB_PFC_ADVERTISE" +#define KEY_DCB_PFC_WILLING "DCB_PFC_WILLING" +#define KEY_DCB_PFC_UP "DCB_PFC_UP" +#define KEY_DCB_PG_ENABLE "DCB_PG_ENABLE" +#define KEY_DCB_PG_ADVERTISE "DCB_PG_ADVERTISE" +#define KEY_DCB_PG_WILLING "DCB_PG_WILLING" +#define KEY_DCB_PG_ID "DCB_PG_ID" +#define KEY_DCB_PG_PCT "DCB_PG_PCT" +#define KEY_DCB_PG_UPPCT "DCB_PG_UPPCT" +#define KEY_DCB_PG_STRICT "DCB_PG_STRICT" +#define KEY_DCB_PG_UP2TC "DCB_PG_UP2TC" + +#endif /* __COMMON_H__ */ + diff --git a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-connection.c b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-connection.c new file mode 100644 index 00000000..33f4847e --- /dev/null +++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-connection.c @@ -0,0 +1,575 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/* NetworkManager system settings service + * + * 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 - 2011 Red Hat, Inc. + */ + +#include "nm-default.h" + +#include "nms-ifcfg-rh-connection.h" + +#include +#include +#include + +#include "nm-dbus-interface.h" +#include "nm-setting-connection.h" +#include "nm-setting-wired.h" +#include "nm-setting-wireless.h" +#include "nm-setting-gsm.h" +#include "nm-setting-cdma.h" +#include "nm-setting-pppoe.h" +#include "nm-setting-wireless-security.h" +#include "nm-setting-8021x.h" +#include "platform/nm-platform.h" +#include "settings/nm-inotify-helper.h" +#include "nm-config.h" + +#include "nms-ifcfg-rh-common.h" +#include "nms-ifcfg-rh-reader.h" +#include "nms-ifcfg-rh-writer.h" +#include "nms-ifcfg-rh-utils.h" + +/*****************************************************************************/ + +NM_GOBJECT_PROPERTIES_DEFINE_BASE ( + PROP_UNMANAGED_SPEC, + PROP_UNRECOGNIZED_SPEC, +); + +enum { + IFCFG_CHANGED, + LAST_SIGNAL +}; + +static guint signals[LAST_SIGNAL] = { 0 }; + +typedef struct { + gulong ih_event_id; + + int file_wd; + + char *keyfile; + int keyfile_wd; + + char *routefile; + int routefile_wd; + + char *route6file; + int route6file_wd; + + char *unmanaged_spec; + char *unrecognized_spec; + + gulong devtimeout_link_changed_handler; + guint devtimeout_timeout_id; + + NMInotifyHelper *inotify_helper; +} NMIfcfgConnectionPrivate; + +struct _NMIfcfgConnection { + NMSettingsConnection parent; + NMIfcfgConnectionPrivate _priv; +}; + +struct _NMIfcfgConnectionClass { + NMSettingsConnectionClass parent; +}; + +G_DEFINE_TYPE (NMIfcfgConnection, nm_ifcfg_connection, NM_TYPE_SETTINGS_CONNECTION) + +#define NM_IFCFG_CONNECTION_GET_PRIVATE(self) _NM_GET_PRIVATE (self, NMIfcfgConnection, NM_IS_IFCFG_CONNECTION) + +/*****************************************************************************/ + +static NMInotifyHelper * +_get_inotify_helper (NMIfcfgConnectionPrivate *priv) +{ + if (!priv->inotify_helper) + priv->inotify_helper = g_object_ref (nm_inotify_helper_get ()); + return priv->inotify_helper; +} + +static gboolean +devtimeout_ready (gpointer user_data) +{ + NMIfcfgConnection *self = user_data; + NMIfcfgConnectionPrivate *priv = NM_IFCFG_CONNECTION_GET_PRIVATE (self); + + priv->devtimeout_timeout_id = 0; + nm_settings_connection_set_ready (NM_SETTINGS_CONNECTION (self), TRUE); + return FALSE; +} + +static void +link_changed (NMPlatform *platform, int obj_type_i, int ifindex, const NMPlatformLink *link, + int change_type_i, + NMConnection *self) +{ + const NMPlatformSignalChangeType change_type = change_type_i; + NMIfcfgConnectionPrivate *priv = NM_IFCFG_CONNECTION_GET_PRIVATE ((NMIfcfgConnection *) self); + const char *ifname; + + ifname = nm_connection_get_interface_name (self); + if (g_strcmp0 (link->name, ifname) != 0) + return; + + if (change_type == NM_PLATFORM_SIGNAL_REMOVED) + return; + + nm_log_info (LOGD_SETTINGS, "Device %s appeared; connection '%s' now ready", + ifname, nm_connection_get_id (self)); + + g_signal_handler_disconnect (platform, priv->devtimeout_link_changed_handler); + priv->devtimeout_link_changed_handler = 0; + g_source_remove (priv->devtimeout_timeout_id); + + /* Don't declare the connection ready right away, since NMManager may not have + * started processing the device yet. + */ + priv->devtimeout_timeout_id = g_idle_add (devtimeout_ready, self); +} + +static gboolean +devtimeout_expired (gpointer user_data) +{ + NMIfcfgConnection *self = user_data; + NMIfcfgConnectionPrivate *priv = NM_IFCFG_CONNECTION_GET_PRIVATE (self); + + nm_log_info (LOGD_SETTINGS, "Device for connection '%s' did not appear before timeout", + nm_connection_get_id (NM_CONNECTION (self))); + + g_signal_handler_disconnect (NM_PLATFORM_GET, priv->devtimeout_link_changed_handler); + priv->devtimeout_link_changed_handler = 0; + priv->devtimeout_timeout_id = 0; + + nm_settings_connection_set_ready (NM_SETTINGS_CONNECTION (self), TRUE); + return FALSE; +} + +static void +nm_ifcfg_connection_check_devtimeout (NMIfcfgConnection *self) +{ + NMIfcfgConnectionPrivate *priv = NM_IFCFG_CONNECTION_GET_PRIVATE (self); + NMSettingConnection *s_con; + const char *ifname; + const char *filename; + guint devtimeout; + const NMPlatformLink *pllink; + + s_con = nm_connection_get_setting_connection (NM_CONNECTION (self)); + + if (!nm_setting_connection_get_autoconnect (s_con)) + return; + ifname = nm_setting_connection_get_interface_name (s_con); + if (!ifname) + return; + filename = nm_settings_connection_get_filename (NM_SETTINGS_CONNECTION (self)); + if (!filename) + return; + + pllink = nm_platform_link_get_by_ifname (NM_PLATFORM_GET, ifname); + if (pllink && pllink->initialized) + return; + + devtimeout = devtimeout_from_file (filename); + if (!devtimeout) + return; + + /* ONBOOT=yes, DEVICE and DEVTIMEOUT are set, but device is not present */ + nm_settings_connection_set_ready (NM_SETTINGS_CONNECTION (self), FALSE); + + nm_log_info (LOGD_SETTINGS, "Waiting %u seconds for %s to appear for connection '%s'", + devtimeout, ifname, nm_connection_get_id (NM_CONNECTION (self))); + + priv->devtimeout_link_changed_handler = + g_signal_connect (NM_PLATFORM_GET, NM_PLATFORM_SIGNAL_LINK_CHANGED, + G_CALLBACK (link_changed), self); + priv->devtimeout_timeout_id = g_timeout_add_seconds (devtimeout, devtimeout_expired, self); +} + +static void +files_changed_cb (NMInotifyHelper *ih, + struct inotify_event *evt, + const char *path, + gpointer user_data) +{ + NMIfcfgConnection *self = NM_IFCFG_CONNECTION (user_data); + NMIfcfgConnectionPrivate *priv = NM_IFCFG_CONNECTION_GET_PRIVATE (self); + + if ( (evt->wd != priv->file_wd) + && (evt->wd != priv->keyfile_wd) + && (evt->wd != priv->routefile_wd) + && (evt->wd != priv->route6file_wd)) + return; + + /* push the event up to the plugin */ + g_signal_emit (self, signals[IFCFG_CHANGED], 0); +} + +static void +path_watch_stop (NMIfcfgConnection *self) +{ + NMIfcfgConnectionPrivate *priv = NM_IFCFG_CONNECTION_GET_PRIVATE (self); + NMInotifyHelper *ih; + + ih = _get_inotify_helper (priv); + + nm_clear_g_signal_handler (ih, &priv->ih_event_id); + + if (priv->file_wd >= 0) { + nm_inotify_helper_remove_watch (ih, priv->file_wd); + priv->file_wd = -1; + } + + g_free (priv->keyfile); + priv->keyfile = NULL; + if (priv->keyfile_wd >= 0) { + nm_inotify_helper_remove_watch (ih, priv->keyfile_wd); + priv->keyfile_wd = -1; + } + + g_free (priv->routefile); + priv->routefile = NULL; + if (priv->routefile_wd >= 0) { + nm_inotify_helper_remove_watch (ih, priv->routefile_wd); + priv->routefile_wd = -1; + } + + g_free (priv->route6file); + priv->route6file = NULL; + if (priv->route6file_wd >= 0) { + nm_inotify_helper_remove_watch (ih, priv->route6file_wd); + priv->route6file_wd = -1; + } +} + +static void +filename_changed (GObject *object, + GParamSpec *pspec, + gpointer user_data) +{ + NMIfcfgConnection *self = NM_IFCFG_CONNECTION (object); + NMIfcfgConnectionPrivate *priv = NM_IFCFG_CONNECTION_GET_PRIVATE (self); + const char *ifcfg_path; + + path_watch_stop (self); + + ifcfg_path = nm_settings_connection_get_filename (NM_SETTINGS_CONNECTION (self)); + if (!ifcfg_path) + return; + + priv->keyfile = utils_get_keys_path (ifcfg_path); + priv->routefile = utils_get_route_path (ifcfg_path); + priv->route6file = utils_get_route6_path (ifcfg_path); + + if (nm_config_get_monitor_connection_files (nm_config_get ())) { + NMInotifyHelper *ih; + + ih = _get_inotify_helper (priv); + + priv->ih_event_id = g_signal_connect (ih, "event", G_CALLBACK (files_changed_cb), self); + priv->file_wd = nm_inotify_helper_add_watch (ih, ifcfg_path); + priv->keyfile_wd = nm_inotify_helper_add_watch (ih, priv->keyfile); + priv->routefile_wd = nm_inotify_helper_add_watch (ih, priv->routefile); + priv->route6file_wd = nm_inotify_helper_add_watch (ih, priv->route6file); + } +} + +const char * +nm_ifcfg_connection_get_unmanaged_spec (NMIfcfgConnection *self) +{ + g_return_val_if_fail (NM_IS_IFCFG_CONNECTION (self), NULL); + + return NM_IFCFG_CONNECTION_GET_PRIVATE (self)->unmanaged_spec; +} + +const char * +nm_ifcfg_connection_get_unrecognized_spec (NMIfcfgConnection *self) +{ + g_return_val_if_fail (NM_IS_IFCFG_CONNECTION (self), NULL); + + return NM_IFCFG_CONNECTION_GET_PRIVATE (self)->unrecognized_spec; +} + +static void +replace_and_commit (NMSettingsConnection *connection, + NMConnection *new_connection, + NMSettingsConnectionCommitFunc callback, + gpointer user_data) +{ + const char *filename; + GError *error = NULL; + + filename = nm_settings_connection_get_filename (connection); + if (filename && utils_has_complex_routes (filename)) { + if (callback) { + error = g_error_new_literal (NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, + "Cannot modify a connection that has an associated 'rule-' or 'rule6-' file"); + callback (connection, error, user_data); + g_clear_error (&error); + } + return; + } + + NM_SETTINGS_CONNECTION_CLASS (nm_ifcfg_connection_parent_class)->replace_and_commit (connection, new_connection, callback, user_data); +} + +static void +commit_changes (NMSettingsConnection *connection, + NMSettingsConnectionCommitReason commit_reason, + NMSettingsConnectionCommitFunc callback, + gpointer user_data) +{ + GError *error = NULL; + NMConnection *reread; + gboolean same = FALSE, success = FALSE; + char *ifcfg_path = NULL; + const char *filename; + + /* To ensure we don't rewrite files that are only changed from other + * processes on-disk, read the existing connection back in and only rewrite + * it if it's really changed. + */ + filename = nm_settings_connection_get_filename (connection); + if (filename) { + gs_free char *unhandled = NULL; + + reread = connection_from_file (filename, &unhandled, NULL, NULL); + if (reread) { + same = nm_connection_compare (NM_CONNECTION (connection), + reread, + NM_SETTING_COMPARE_FLAG_IGNORE_AGENT_OWNED_SECRETS | + NM_SETTING_COMPARE_FLAG_IGNORE_NOT_SAVED_SECRETS); + g_object_unref (reread); + + /* Don't bother writing anything out if in-memory and on-disk data are the same */ + if (same) { + /* But chain up to parent to handle success - emits updated signal */ + NM_SETTINGS_CONNECTION_CLASS (nm_ifcfg_connection_parent_class)->commit_changes (connection, commit_reason, callback, user_data); + return; + } + } + + success = writer_update_connection (NM_CONNECTION (connection), + IFCFG_DIR, + filename, + &error); + } else { + success = writer_new_connection (NM_CONNECTION (connection), + IFCFG_DIR, + &ifcfg_path, + &error); + if (success) { + nm_settings_connection_set_filename (connection, ifcfg_path); + g_free (ifcfg_path); + } + } + + if (success) { + /* Chain up to parent to handle success */ + NM_SETTINGS_CONNECTION_CLASS (nm_ifcfg_connection_parent_class)->commit_changes (connection, commit_reason, callback, user_data); + } else { + /* Otherwise immediate error */ + callback (connection, error, user_data); + g_error_free (error); + } +} + +static void +do_delete (NMSettingsConnection *connection, + NMSettingsConnectionDeleteFunc callback, + gpointer user_data) +{ + NMIfcfgConnectionPrivate *priv = NM_IFCFG_CONNECTION_GET_PRIVATE ((NMIfcfgConnection *) connection); + const char *filename; + + filename = nm_settings_connection_get_filename (connection); + if (filename) { + g_unlink (filename); + if (priv->keyfile) + g_unlink (priv->keyfile); + if (priv->routefile) + g_unlink (priv->routefile); + if (priv->route6file) + g_unlink (priv->route6file); + } + + NM_SETTINGS_CONNECTION_CLASS (nm_ifcfg_connection_parent_class)->delete (connection, callback, user_data); +} + +/*****************************************************************************/ + +static void +get_property (GObject *object, guint prop_id, + GValue *value, GParamSpec *pspec) +{ + NMIfcfgConnectionPrivate *priv = NM_IFCFG_CONNECTION_GET_PRIVATE ((NMIfcfgConnection *) object); + + switch (prop_id) { + case PROP_UNMANAGED_SPEC: + g_value_set_string (value, priv->unmanaged_spec); + break; + case PROP_UNRECOGNIZED_SPEC: + g_value_set_string (value, priv->unrecognized_spec); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +set_property (GObject *object, guint prop_id, + const GValue *value, GParamSpec *pspec) +{ + NMIfcfgConnectionPrivate *priv = NM_IFCFG_CONNECTION_GET_PRIVATE ((NMIfcfgConnection *) object); + + switch (prop_id) { + case PROP_UNMANAGED_SPEC: + priv->unmanaged_spec = g_value_dup_string (value); + break; + case PROP_UNRECOGNIZED_SPEC: + priv->unrecognized_spec = g_value_dup_string (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +/*****************************************************************************/ + +static void +nm_ifcfg_connection_init (NMIfcfgConnection *connection) +{ + g_signal_connect (connection, "notify::" NM_SETTINGS_CONNECTION_FILENAME, + G_CALLBACK (filename_changed), NULL); +} + +NMIfcfgConnection * +nm_ifcfg_connection_new (NMConnection *source, + const char *full_path, + GError **error, + gboolean *out_ignore_error) +{ + GObject *object; + NMConnection *tmp; + char *unhandled_spec = NULL; + const char *unmanaged_spec = NULL, *unrecognized_spec = NULL; + gboolean update_unsaved = TRUE; + + g_assert (source || full_path); + + if (out_ignore_error) + *out_ignore_error = FALSE; + + /* If we're given a connection already, prefer that instead of re-reading */ + if (source) + tmp = g_object_ref (source); + else { + tmp = connection_from_file (full_path, + &unhandled_spec, + error, + out_ignore_error); + if (!tmp) + return NULL; + + /* If we just read the connection from disk, it's clearly not Unsaved */ + update_unsaved = FALSE; + } + + if (unhandled_spec && g_str_has_prefix (unhandled_spec, "unmanaged:")) + unmanaged_spec = unhandled_spec + strlen ("unmanaged:"); + else if (unhandled_spec && g_str_has_prefix (unhandled_spec, "unrecognized:")) + unrecognized_spec = unhandled_spec + strlen ("unrecognized:"); + + object = (GObject *) g_object_new (NM_TYPE_IFCFG_CONNECTION, + NM_SETTINGS_CONNECTION_FILENAME, full_path, + NM_IFCFG_CONNECTION_UNMANAGED_SPEC, unmanaged_spec, + NM_IFCFG_CONNECTION_UNRECOGNIZED_SPEC, unrecognized_spec, + NULL); + /* Update our settings with what was read from the file */ + if (nm_settings_connection_replace_settings (NM_SETTINGS_CONNECTION (object), + tmp, + update_unsaved, + NULL, + error)) + nm_ifcfg_connection_check_devtimeout (NM_IFCFG_CONNECTION (object)); + else + g_clear_object (&object); + + g_object_unref (tmp); + g_free (unhandled_spec); + return (NMIfcfgConnection *) object; +} + +static void +dispose (GObject *object) +{ + NMIfcfgConnectionPrivate *priv = NM_IFCFG_CONNECTION_GET_PRIVATE ((NMIfcfgConnection *) object); + + path_watch_stop (NM_IFCFG_CONNECTION (object)); + + nm_clear_g_signal_handler (NM_PLATFORM_GET, &priv->devtimeout_link_changed_handler); + nm_clear_g_source (&priv->devtimeout_timeout_id); + + g_clear_object (&priv->inotify_helper); + + g_clear_pointer (&priv->unmanaged_spec, g_free); + g_clear_pointer (&priv->unrecognized_spec, g_free); + + G_OBJECT_CLASS (nm_ifcfg_connection_parent_class)->dispose (object); +} + +static void +nm_ifcfg_connection_class_init (NMIfcfgConnectionClass *ifcfg_connection_class) +{ + GObjectClass *object_class = G_OBJECT_CLASS (ifcfg_connection_class); + NMSettingsConnectionClass *settings_class = NM_SETTINGS_CONNECTION_CLASS (ifcfg_connection_class); + + object_class->set_property = set_property; + object_class->get_property = get_property; + object_class->dispose = dispose; + + settings_class->delete = do_delete; + settings_class->replace_and_commit = replace_and_commit; + settings_class->commit_changes = commit_changes; + + obj_properties[PROP_UNMANAGED_SPEC] = + g_param_spec_string (NM_IFCFG_CONNECTION_UNMANAGED_SPEC, "", "", + NULL, + G_PARAM_READWRITE | + G_PARAM_STATIC_STRINGS); + + obj_properties[PROP_UNRECOGNIZED_SPEC] = + g_param_spec_string (NM_IFCFG_CONNECTION_UNRECOGNIZED_SPEC, "", "", + NULL, + G_PARAM_READWRITE | + G_PARAM_STATIC_STRINGS); + + g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties); + + signals[IFCFG_CHANGED] = + g_signal_new ("ifcfg-changed", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_LAST, + 0, NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, 0); +} + diff --git a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-connection.h b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-connection.h new file mode 100644 index 00000000..fd68f2d3 --- /dev/null +++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-connection.h @@ -0,0 +1,54 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/* NetworkManager system settings service + * + * 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 - 2011 Red Hat, Inc. + */ + +#ifndef __NETWORKMANAGER_IFCFG_CONNECTION_H__ +#define __NETWORKMANAGER_IFCFG_CONNECTION_H__ + +#include "nm-dbus-interface.h" +#include "settings/nm-settings-connection.h" + +#define NM_TYPE_IFCFG_CONNECTION (nm_ifcfg_connection_get_type ()) +#define NM_IFCFG_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_IFCFG_CONNECTION, NMIfcfgConnection)) +#define NM_IFCFG_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_IFCFG_CONNECTION, NMIfcfgConnectionClass)) +#define NM_IS_IFCFG_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_IFCFG_CONNECTION)) +#define NM_IS_IFCFG_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_IFCFG_CONNECTION)) +#define NM_IFCFG_CONNECTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_IFCFG_CONNECTION, NMIfcfgConnectionClass)) + +#define NM_IFCFG_CONNECTION_UNMANAGED_SPEC "unmanaged-spec" +#define NM_IFCFG_CONNECTION_UNRECOGNIZED_SPEC "unrecognized-spec" + +typedef struct _NMIfcfgConnection NMIfcfgConnection; +typedef struct _NMIfcfgConnectionClass NMIfcfgConnectionClass; + +GType nm_ifcfg_connection_get_type (void); + +NMIfcfgConnection *nm_ifcfg_connection_new (NMConnection *source, + const char *full_path, + GError **error, + gboolean *out_ignore_error); + +const char *nm_ifcfg_connection_get_unmanaged_spec (NMIfcfgConnection *self); +const char *nm_ifcfg_connection_get_unrecognized_spec (NMIfcfgConnection *self); + +gboolean nm_ifcfg_connection_update (NMIfcfgConnection *self, + GHashTable *new_settings, + GError **error); + +#endif /* __NETWORKMANAGER_IFCFG_CONNECTION_H__ */ diff --git a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-plugin.c b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-plugin.c new file mode 100644 index 00000000..414f593b --- /dev/null +++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-plugin.c @@ -0,0 +1,1085 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/* NetworkManager system settings service + * + * Dan Williams + * Søren Sandmann + * + * 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) 2007 - 2011 Red Hat, Inc. + */ + +#include "nm-default.h" + +#include "nms-ifcfg-rh-plugin.h" + +#include +#include +#include +#include +#include +#include + +#include "nm-dbus-compat.h" +#include "nm-setting-connection.h" +#include "settings/nm-settings-plugin.h" +#include "nm-config.h" +#include "NetworkManagerUtils.h" +#include "nm-exported-object.h" + +#include "nms-ifcfg-rh-connection.h" +#include "nms-ifcfg-rh-common.h" +#include "nms-ifcfg-rh-reader.h" +#include "nms-ifcfg-rh-writer.h" +#include "nms-ifcfg-rh-utils.h" +#include "shvar.h" + +#include "settings/plugins/ifcfg-rh/nmdbus-ifcfg-rh.h" + +#define IFCFGRH1_DBUS_SERVICE_NAME "com.redhat.ifcfgrh1" +#define IFCFGRH1_DBUS_OBJECT_PATH "/com/redhat/ifcfgrh1" + +/*****************************************************************************/ + +typedef struct { + NMConfig *config; + + struct { + GDBusConnection *connection; + GDBusInterfaceSkeleton *interface; + GCancellable *cancellable; + gulong signal_id; + } dbus; + + GHashTable *connections; /* uuid::connection */ + gboolean initialized; + + GFileMonitor *ifcfg_monitor; + gulong ifcfg_monitor_id; +} SettingsPluginIfcfgPrivate; + +struct _SettingsPluginIfcfg { + GObject parent; + SettingsPluginIfcfgPrivate _priv; +}; + +struct _SettingsPluginIfcfgClass { + GObjectClass parent; +}; + +static void settings_plugin_interface_init (NMSettingsPluginInterface *plugin_iface); + +G_DEFINE_TYPE_EXTENDED (SettingsPluginIfcfg, settings_plugin_ifcfg, G_TYPE_OBJECT, 0, + G_IMPLEMENT_INTERFACE (NM_TYPE_SETTINGS_PLUGIN, + settings_plugin_interface_init)) + +#define SETTINGS_PLUGIN_IFCFG_GET_PRIVATE(self) _NM_GET_PRIVATE (self, SettingsPluginIfcfg, SETTINGS_IS_PLUGIN_IFCFG) + +/*****************************************************************************/ + +static SettingsPluginIfcfg *settings_plugin_ifcfg_get (void); + +NM_DEFINE_SINGLETON_GETTER (SettingsPluginIfcfg, settings_plugin_ifcfg_get, SETTINGS_TYPE_PLUGIN_IFCFG); + +/*****************************************************************************/ + +#define _NMLOG_DOMAIN LOGD_SETTINGS +#define _NMLOG(level, ...) \ + G_STMT_START { \ + nm_log ((level), (_NMLOG_DOMAIN), \ + "%s" _NM_UTILS_MACRO_FIRST(__VA_ARGS__), \ + "ifcfg-rh: " \ + _NM_UTILS_MACRO_REST(__VA_ARGS__)); \ + } G_STMT_END + +/*****************************************************************************/ + +static NMIfcfgConnection *update_connection (SettingsPluginIfcfg *plugin, + NMConnection *source, + const char *full_path, + NMIfcfgConnection *connection, + gboolean protect_existing_connection, + GHashTable *protected_connections, + GError **error); + +/*****************************************************************************/ + +static void +connection_ifcfg_changed (NMIfcfgConnection *connection, gpointer user_data) +{ + SettingsPluginIfcfg *self = SETTINGS_PLUGIN_IFCFG (user_data); + SettingsPluginIfcfgPrivate *priv = SETTINGS_PLUGIN_IFCFG_GET_PRIVATE (self); + const char *path; + + path = nm_settings_connection_get_filename (NM_SETTINGS_CONNECTION (connection)); + g_return_if_fail (path != NULL); + + + if (!priv->ifcfg_monitor) { + _LOGD ("connection_ifcfg_changed("NM_IFCFG_CONNECTION_LOG_FMTD"): %s", NM_IFCFG_CONNECTION_LOG_ARGD (connection), "ignore event"); + return; + } + + _LOGD ("connection_ifcfg_changed("NM_IFCFG_CONNECTION_LOG_FMTD"): %s", NM_IFCFG_CONNECTION_LOG_ARGD (connection), "reload"); + + update_connection (self, NULL, path, connection, TRUE, NULL, NULL); +} + +static void +connection_removed_cb (NMSettingsConnection *obj, gpointer user_data) +{ + g_hash_table_remove (SETTINGS_PLUGIN_IFCFG_GET_PRIVATE ((SettingsPluginIfcfg *) user_data)->connections, + nm_connection_get_uuid (NM_CONNECTION (obj))); +} + +static void +remove_connection (SettingsPluginIfcfg *self, NMIfcfgConnection *connection) +{ + SettingsPluginIfcfgPrivate *priv = SETTINGS_PLUGIN_IFCFG_GET_PRIVATE (self); + gboolean unmanaged, unrecognized; + + g_return_if_fail (self != NULL); + g_return_if_fail (connection != NULL); + + _LOGI ("remove "NM_IFCFG_CONNECTION_LOG_FMT, NM_IFCFG_CONNECTION_LOG_ARG (connection)); + + unmanaged = !!nm_ifcfg_connection_get_unmanaged_spec (connection); + unrecognized = !!nm_ifcfg_connection_get_unrecognized_spec (connection); + + g_object_ref (connection); + g_hash_table_remove (priv->connections, nm_connection_get_uuid (NM_CONNECTION (connection))); + if (!unmanaged && !unrecognized) + nm_settings_connection_signal_remove (NM_SETTINGS_CONNECTION (connection), FALSE); + g_object_unref (connection); + + /* Emit changes _after_ removing the connection */ + if (unmanaged) + g_signal_emit_by_name (self, NM_SETTINGS_PLUGIN_UNMANAGED_SPECS_CHANGED); + if (unrecognized) + g_signal_emit_by_name (self, NM_SETTINGS_PLUGIN_UNRECOGNIZED_SPECS_CHANGED); +} + +static NMIfcfgConnection * +find_by_path (SettingsPluginIfcfg *self, const char *path) +{ + SettingsPluginIfcfgPrivate *priv = SETTINGS_PLUGIN_IFCFG_GET_PRIVATE (self); + GHashTableIter iter; + NMSettingsConnection *candidate = NULL; + + g_return_val_if_fail (path != NULL, NULL); + + g_hash_table_iter_init (&iter, priv->connections); + while (g_hash_table_iter_next (&iter, NULL, (gpointer) &candidate)) { + if (g_strcmp0 (path, nm_settings_connection_get_filename (candidate)) == 0) + return NM_IFCFG_CONNECTION (candidate); + } + return NULL; +} + +static NMIfcfgConnection * +update_connection (SettingsPluginIfcfg *self, + NMConnection *source, + const char *full_path, + NMIfcfgConnection *connection, + gboolean protect_existing_connection, + GHashTable *protected_connections, + GError **error) +{ + SettingsPluginIfcfgPrivate *priv = SETTINGS_PLUGIN_IFCFG_GET_PRIVATE (self); + NMIfcfgConnection *connection_new; + NMIfcfgConnection *connection_by_uuid; + GError *local = NULL; + const char *new_unmanaged = NULL, *old_unmanaged = NULL; + const char *new_unrecognized = NULL, *old_unrecognized = NULL; + gboolean unmanaged_changed = FALSE, unrecognized_changed = FALSE; + const char *uuid; + gboolean ignore_error = FALSE; + + g_return_val_if_fail (!source || NM_IS_CONNECTION (source), NULL); + g_return_val_if_fail (full_path || source, NULL); + + if (full_path) + _LOGD ("loading from file \"%s\"...", full_path); + + /* Create a NMIfcfgConnection instance, either by reading from @full_path or + * based on @source. */ + connection_new = nm_ifcfg_connection_new (source, full_path, &local, &ignore_error); + if (!connection_new) { + /* Unexpected failure. Probably the file is invalid? */ + if ( connection + && !protect_existing_connection + && (!protected_connections || !g_hash_table_contains (protected_connections, connection))) + remove_connection (self, connection); + if (!source) { + _NMLOG (ignore_error ? LOGL_DEBUG : LOGL_WARN, + "loading \"%s\" fails: %s", full_path, local ? local->message : "(unknown reason)"); + } + g_propagate_error (error, local); + return NULL; + } + + uuid = nm_connection_get_uuid (NM_CONNECTION (connection_new)); + connection_by_uuid = g_hash_table_lookup (priv->connections, uuid); + + if ( connection + && connection != connection_by_uuid) { + + if ( (protect_existing_connection && connection_by_uuid != NULL) + || (protected_connections && g_hash_table_contains (protected_connections, connection))) { + NMIfcfgConnection *conflicting = (protect_existing_connection && connection_by_uuid != NULL) ? connection_by_uuid : connection; + + if (source) + _LOGW ("cannot update protected connection "NM_IFCFG_CONNECTION_LOG_FMT" due to conflicting UUID %s", NM_IFCFG_CONNECTION_LOG_ARG (conflicting), uuid); + else + _LOGW ("cannot load %s due to conflicting UUID for "NM_IFCFG_CONNECTION_LOG_FMT, full_path, NM_IFCFG_CONNECTION_LOG_ARG (conflicting)); + g_object_unref (connection_new); + g_set_error_literal (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, + "Cannot update protected connection due to conflicting UUID"); + return NULL; + } + + /* The new connection has a different UUID then the original one that we + * are about to update. Remove @connection. */ + remove_connection (self, connection); + } + + /* Check if the found connection with the same UUID is not protected from updating. */ + if ( connection_by_uuid + && ( (!connection && protect_existing_connection) + || (protected_connections && g_hash_table_contains (protected_connections, connection_by_uuid)))) { + if (source) + _LOGW ("cannot update connection due to conflicting UUID for "NM_IFCFG_CONNECTION_LOG_FMT, NM_IFCFG_CONNECTION_LOG_ARG (connection_by_uuid)); + else + _LOGW ("cannot load %s due to conflicting UUID for "NM_IFCFG_CONNECTION_LOG_FMT, full_path, NM_IFCFG_CONNECTION_LOG_ARG (connection_by_uuid)); + g_object_unref (connection_new); + g_set_error_literal (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, + "Skip updating protected connection during reload"); + return NULL; + } + + /* Evaluate unmanaged/unrecognized flags. */ + if (connection_by_uuid) + old_unmanaged = nm_ifcfg_connection_get_unmanaged_spec (connection_by_uuid); + new_unmanaged = nm_ifcfg_connection_get_unmanaged_spec (connection_new); + unmanaged_changed = g_strcmp0 (old_unmanaged, new_unmanaged); + + if (connection_by_uuid) + old_unrecognized = nm_ifcfg_connection_get_unrecognized_spec (connection_by_uuid); + new_unrecognized = nm_ifcfg_connection_get_unrecognized_spec (connection_new); + unrecognized_changed = g_strcmp0 (old_unrecognized, new_unrecognized); + + if (connection_by_uuid) { + const char *old_path; + + old_path = nm_settings_connection_get_filename (NM_SETTINGS_CONNECTION (connection_by_uuid)); + + if ( !unmanaged_changed + && !unrecognized_changed + && nm_connection_compare (NM_CONNECTION (connection_by_uuid), + NM_CONNECTION (connection_new), + NM_SETTING_COMPARE_FLAG_IGNORE_AGENT_OWNED_SECRETS | + NM_SETTING_COMPARE_FLAG_IGNORE_NOT_SAVED_SECRETS)) { + if (old_path && g_strcmp0 (old_path, full_path) != 0) + _LOGI ("rename \"%s\" to "NM_IFCFG_CONNECTION_LOG_FMT" without other changes", nm_settings_connection_get_filename (NM_SETTINGS_CONNECTION (connection_by_uuid)), NM_IFCFG_CONNECTION_LOG_ARG (connection_new)); + } else { + + /******************************************************* + * UPDATE + *******************************************************/ + + if (source) + _LOGI ("update "NM_IFCFG_CONNECTION_LOG_FMT" from %s", NM_IFCFG_CONNECTION_LOG_ARG (connection_new), NM_IFCFG_CONNECTION_LOG_PATH (old_path)); + else if (!g_strcmp0 (old_path, nm_settings_connection_get_filename (NM_SETTINGS_CONNECTION (connection_new)))) + _LOGI ("update "NM_IFCFG_CONNECTION_LOG_FMT, NM_IFCFG_CONNECTION_LOG_ARG (connection_new)); + else if (old_path) + _LOGI ("rename \"%s\" to "NM_IFCFG_CONNECTION_LOG_FMT, old_path, NM_IFCFG_CONNECTION_LOG_ARG (connection_new)); + else + _LOGI ("update and persist "NM_IFCFG_CONNECTION_LOG_FMT, NM_IFCFG_CONNECTION_LOG_ARG (connection_new)); + + g_object_set (connection_by_uuid, + NM_IFCFG_CONNECTION_UNMANAGED_SPEC, new_unmanaged, + NM_IFCFG_CONNECTION_UNRECOGNIZED_SPEC, new_unrecognized, + NULL); + + if (!nm_settings_connection_replace_settings (NM_SETTINGS_CONNECTION (connection_by_uuid), + NM_CONNECTION (connection_new), + FALSE, /* don't set Unsaved */ + "ifcfg-update", + &local)) { + /* Shouldn't ever get here as 'connection_new' was verified by the reader already + * and the UUID did not change. */ + g_assert_not_reached (); + } + g_assert_no_error (local); + + if (new_unmanaged || new_unrecognized) { + if (!old_unmanaged && !old_unrecognized) { + g_object_ref (connection_by_uuid); + /* Unexport the connection by telling the settings service it's + * been removed. + */ + nm_settings_connection_signal_remove (NM_SETTINGS_CONNECTION (connection_by_uuid), TRUE); + /* Remove the path so that claim_connection() doesn't complain later when + * interface gets managed and connection is re-added. */ + nm_connection_set_path (NM_CONNECTION (connection_by_uuid), NULL); + + /* signal_remove() will end up removing the connection from our hash, + * so add it back now. + */ + g_hash_table_insert (priv->connections, + g_strdup (nm_connection_get_uuid (NM_CONNECTION (connection_by_uuid))), + connection_by_uuid); + } + } else { + if (old_unmanaged /* && !new_unmanaged */) { + _LOGI ("Managing connection "NM_IFCFG_CONNECTION_LOG_FMT" and its device because NM_CONTROLLED was true.", + NM_IFCFG_CONNECTION_LOG_ARG (connection_new)); + g_signal_emit_by_name (self, NM_SETTINGS_PLUGIN_CONNECTION_ADDED, connection_by_uuid); + } else if (old_unrecognized /* && !new_unrecognized */) { + _LOGI ("Managing connection "NM_IFCFG_CONNECTION_LOG_FMT" because it is now a recognized type.", + NM_IFCFG_CONNECTION_LOG_ARG (connection_new)); + g_signal_emit_by_name (self, NM_SETTINGS_PLUGIN_CONNECTION_ADDED, connection_by_uuid); + } + } + + if (unmanaged_changed) + g_signal_emit_by_name (self, NM_SETTINGS_PLUGIN_UNMANAGED_SPECS_CHANGED); + if (unrecognized_changed) + g_signal_emit_by_name (self, NM_SETTINGS_PLUGIN_UNRECOGNIZED_SPECS_CHANGED); + } + nm_settings_connection_set_filename (NM_SETTINGS_CONNECTION (connection_by_uuid), full_path); + g_object_unref (connection_new); + return connection_by_uuid; + } else { + + /******************************************************* + * ADD + *******************************************************/ + + if (source) + _LOGI ("add connection "NM_IFCFG_CONNECTION_LOG_FMT, NM_IFCFG_CONNECTION_LOG_ARG (connection_new)); + else + _LOGI ("new connection "NM_IFCFG_CONNECTION_LOG_FMT, NM_IFCFG_CONNECTION_LOG_ARG (connection_new)); + g_hash_table_insert (priv->connections, g_strdup (uuid), connection_new); + + g_signal_connect (connection_new, NM_SETTINGS_CONNECTION_REMOVED, + G_CALLBACK (connection_removed_cb), + self); + + if (nm_ifcfg_connection_get_unmanaged_spec (connection_new)) { + _LOGI ("Ignoring connection "NM_IFCFG_CONNECTION_LOG_FMT" due to NM_CONTROLLED=no. Unmanaged: %s.", + NM_IFCFG_CONNECTION_LOG_ARG (connection_new), + nm_ifcfg_connection_get_unmanaged_spec (connection_new)); + } else if (nm_ifcfg_connection_get_unrecognized_spec (connection_new)) + _LOGW ("Ignoring connection "NM_IFCFG_CONNECTION_LOG_FMT" of unrecognized type.", NM_IFCFG_CONNECTION_LOG_ARG (connection_new)); + + /* watch changes of ifcfg hardlinks */ + g_signal_connect (G_OBJECT (connection_new), "ifcfg-changed", + G_CALLBACK (connection_ifcfg_changed), self); + + if (!source) { + /* Only raise the signal if we were called without source, i.e. if we read the connection from file. + * Otherwise, we were called by add_connection() which does not expect the signal. */ + if (nm_ifcfg_connection_get_unmanaged_spec (connection_new)) + g_signal_emit_by_name (self, NM_SETTINGS_PLUGIN_UNMANAGED_SPECS_CHANGED); + else if (nm_ifcfg_connection_get_unrecognized_spec (connection_new)) + g_signal_emit_by_name (self, NM_SETTINGS_PLUGIN_UNRECOGNIZED_SPECS_CHANGED); + else + g_signal_emit_by_name (self, NM_SETTINGS_PLUGIN_CONNECTION_ADDED, connection_new); + } + return connection_new; + } +} + +static void +ifcfg_dir_changed (GFileMonitor *monitor, + GFile *file, + GFile *other_file, + GFileMonitorEvent event_type, + gpointer user_data) +{ + SettingsPluginIfcfg *plugin = SETTINGS_PLUGIN_IFCFG (user_data); + char *path, *ifcfg_path; + NMIfcfgConnection *connection; + + path = g_file_get_path (file); + + ifcfg_path = utils_detect_ifcfg_path (path, FALSE); + _LOGD ("ifcfg_dir_changed(%s) = %d // %s", path, event_type, ifcfg_path ? ifcfg_path : "(none)"); + if (ifcfg_path) { + connection = find_by_path (plugin, ifcfg_path); + switch (event_type) { + case G_FILE_MONITOR_EVENT_DELETED: + if (connection) + remove_connection (plugin, connection); + break; + case G_FILE_MONITOR_EVENT_CREATED: + case G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT: + /* Update or new */ + update_connection (plugin, NULL, ifcfg_path, connection, TRUE, NULL, NULL); + break; + default: + break; + } + g_free (ifcfg_path); + } + g_free (path); +} + +static void +setup_ifcfg_monitoring (SettingsPluginIfcfg *plugin) +{ + SettingsPluginIfcfgPrivate *priv = SETTINGS_PLUGIN_IFCFG_GET_PRIVATE (plugin); + GFile *file; + GFileMonitor *monitor; + + file = g_file_new_for_path (IFCFG_DIR "/"); + monitor = g_file_monitor_directory (file, G_FILE_MONITOR_NONE, NULL, NULL); + g_object_unref (file); + + if (monitor) { + priv->ifcfg_monitor_id = g_signal_connect (monitor, "changed", + G_CALLBACK (ifcfg_dir_changed), plugin); + priv->ifcfg_monitor = monitor; + } +} + +static GHashTable * +_paths_from_connections (GHashTable *connections) +{ + GHashTableIter iter; + NMIfcfgConnection *connection; + GHashTable *paths = g_hash_table_new (g_str_hash, g_str_equal); + + g_hash_table_iter_init (&iter, connections); + while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &connection)) { + const char *path = nm_settings_connection_get_filename (NM_SETTINGS_CONNECTION (connection)); + + if (path) + g_hash_table_add (paths, (void *) path); + } + return paths; +} + +static int +_sort_paths (const char **f1, const char **f2, GHashTable *paths) +{ + struct stat st; + gboolean c1, c2; + gint64 m1, m2; + + c1 = !!g_hash_table_contains (paths, *f1); + c2 = !!g_hash_table_contains (paths, *f2); + if (c1 != c2) + return c1 ? -1 : 1; + + m1 = stat (*f1, &st) == 0 ? (gint64) st.st_mtime : G_MININT64; + m2 = stat (*f2, &st) == 0 ? (gint64) st.st_mtime : G_MININT64; + if (m1 != m2) + return m1 > m2 ? -1 : 1; + + return strcmp (*f1, *f2); +} + +static void +read_connections (SettingsPluginIfcfg *plugin) +{ + SettingsPluginIfcfgPrivate *priv = SETTINGS_PLUGIN_IFCFG_GET_PRIVATE (plugin); + GDir *dir; + GError *err = NULL; + const char *item; + GHashTable *alive_connections; + GHashTableIter iter; + NMIfcfgConnection *connection; + GPtrArray *dead_connections = NULL; + guint i; + GPtrArray *filenames; + GHashTable *paths; + + dir = g_dir_open (IFCFG_DIR, 0, &err); + if (!dir) { + _LOGW ("Could not read directory '%s': %s", IFCFG_DIR, err->message); + g_error_free (err); + return; + } + + alive_connections = g_hash_table_new (NULL, NULL); + + filenames = g_ptr_array_new_with_free_func (g_free); + while ((item = g_dir_read_name (dir))) { + char *full_path, *real_path; + + full_path = g_build_filename (IFCFG_DIR, item, NULL); + real_path = utils_detect_ifcfg_path (full_path, TRUE); + + if (real_path) + g_ptr_array_add (filenames, real_path); + g_free (full_path); + } + g_dir_close (dir); + + /* While reloading, we don't replace connections that we already loaded while + * iterating over the files. + * + * To have sensible, reproducible behavior, sort the paths by last modification + * time prefering older files. + */ + paths = _paths_from_connections (priv->connections); + g_ptr_array_sort_with_data (filenames, (GCompareDataFunc) _sort_paths, paths); + g_hash_table_destroy (paths); + + for (i = 0; i < filenames->len; i++) { + connection = update_connection (plugin, NULL, filenames->pdata[i], NULL, FALSE, alive_connections, NULL); + if (connection) + g_hash_table_add (alive_connections, connection); + } + g_ptr_array_free (filenames, TRUE); + + g_hash_table_iter_init (&iter, priv->connections); + while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &connection)) { + if ( !g_hash_table_contains (alive_connections, connection) + && nm_settings_connection_get_filename (NM_SETTINGS_CONNECTION (connection))) { + if (!dead_connections) + dead_connections = g_ptr_array_new (); + g_ptr_array_add (dead_connections, connection); + } + } + g_hash_table_destroy (alive_connections); + + if (dead_connections) { + for (i = 0; i < dead_connections->len; i++) + remove_connection (plugin, dead_connections->pdata[i]); + g_ptr_array_free (dead_connections, TRUE); + } +} + +static GSList * +get_connections (NMSettingsPlugin *config) +{ + SettingsPluginIfcfg *plugin = SETTINGS_PLUGIN_IFCFG (config); + SettingsPluginIfcfgPrivate *priv = SETTINGS_PLUGIN_IFCFG_GET_PRIVATE (plugin); + GSList *list = NULL; + GHashTableIter iter; + NMIfcfgConnection *connection; + + if (!priv->initialized) { + if (nm_config_get_monitor_connection_files (nm_config_get ())) + setup_ifcfg_monitoring (plugin); + read_connections (plugin); + priv->initialized = TRUE; + } + + g_hash_table_iter_init (&iter, priv->connections); + while (g_hash_table_iter_next (&iter, NULL, (gpointer) &connection)) { + if ( !nm_ifcfg_connection_get_unmanaged_spec (connection) + && !nm_ifcfg_connection_get_unrecognized_spec (connection)) + list = g_slist_prepend (list, connection); + } + + return list; +} + +static gboolean +load_connection (NMSettingsPlugin *config, + const char *filename) +{ + SettingsPluginIfcfg *plugin = SETTINGS_PLUGIN_IFCFG (config); + NMIfcfgConnection *connection; + int dir_len = strlen (IFCFG_DIR); + char *ifcfg_path; + + if ( strncmp (filename, IFCFG_DIR, dir_len) != 0 + || filename[dir_len] != '/' + || strchr (filename + dir_len + 1, '/') != NULL) + return FALSE; + + /* get the real ifcfg-path. This allows us to properly + * handle load command using a route-* file etc. */ + ifcfg_path = utils_detect_ifcfg_path (filename, FALSE); + if (!ifcfg_path) + return FALSE; + + connection = find_by_path (plugin, ifcfg_path); + update_connection (plugin, NULL, ifcfg_path, connection, TRUE, NULL, NULL); + if (!connection) + connection = find_by_path (plugin, ifcfg_path); + + g_free (ifcfg_path); + return (connection != NULL); +} + +static void +reload_connections (NMSettingsPlugin *config) +{ + SettingsPluginIfcfg *plugin = SETTINGS_PLUGIN_IFCFG (config); + + read_connections (plugin); +} + +static GSList * +get_unhandled_specs (NMSettingsPlugin *config, + const char *property) +{ + SettingsPluginIfcfgPrivate *priv = SETTINGS_PLUGIN_IFCFG_GET_PRIVATE ((SettingsPluginIfcfg *) config); + GSList *list = NULL, *list_iter; + GHashTableIter iter; + gpointer connection; + char *spec; + gboolean found; + + g_hash_table_iter_init (&iter, priv->connections); + while (g_hash_table_iter_next (&iter, NULL, &connection)) { + g_object_get (connection, property, &spec, NULL); + if (spec) { + /* Ignore duplicates */ + for (list_iter = list, found = FALSE; list_iter; list_iter = g_slist_next (list_iter)) { + if (g_str_equal (list_iter->data, spec)) { + found = TRUE; + break; + } + } + if (found) + g_free (spec); + else + list = g_slist_prepend (list, spec); + } + } + return list; +} + +static GSList * +get_unmanaged_specs (NMSettingsPlugin *config) +{ + return get_unhandled_specs (config, NM_IFCFG_CONNECTION_UNMANAGED_SPEC); +} + +static GSList * +get_unrecognized_specs (NMSettingsPlugin *config) +{ + return get_unhandled_specs (config, NM_IFCFG_CONNECTION_UNRECOGNIZED_SPEC); +} + +static NMSettingsConnection * +add_connection (NMSettingsPlugin *config, + NMConnection *connection, + gboolean save_to_disk, + GError **error) +{ + SettingsPluginIfcfg *self = SETTINGS_PLUGIN_IFCFG (config); + gs_free char *path = NULL; + + /* Ensure we reject attempts to add the connection long before we're + * asked to write it to disk. + */ + if (!writer_can_write_connection (connection, error)) + return NULL; + + if (save_to_disk) { + if (!writer_new_connection (connection, IFCFG_DIR, &path, error)) + return NULL; + } + return NM_SETTINGS_CONNECTION (update_connection (self, connection, path, NULL, FALSE, NULL, error)); +} + +static void +impl_ifcfgrh_get_ifcfg_details (SettingsPluginIfcfg *plugin, + GDBusMethodInvocation *context, + const char *in_ifcfg) +{ + NMIfcfgConnection *connection; + NMSettingConnection *s_con; + const char *uuid; + const char *path; + gs_free char *ifcfg_path = NULL; + + if (!g_path_is_absolute (in_ifcfg)) { + g_dbus_method_invocation_return_error (context, + NM_SETTINGS_ERROR, + NM_SETTINGS_ERROR_INVALID_CONNECTION, + "ifcfg path '%s' is not absolute", in_ifcfg); + return; + } + + ifcfg_path = utils_detect_ifcfg_path (in_ifcfg, TRUE); + if (!ifcfg_path) { + g_dbus_method_invocation_return_error (context, + NM_SETTINGS_ERROR, + NM_SETTINGS_ERROR_INVALID_CONNECTION, + "ifcfg path '%s' is not an ifcfg base file", in_ifcfg); + return; + } + + connection = find_by_path (plugin, ifcfg_path); + if ( !connection + || nm_ifcfg_connection_get_unmanaged_spec (connection) + || nm_ifcfg_connection_get_unrecognized_spec (connection)) { + g_dbus_method_invocation_return_error (context, + NM_SETTINGS_ERROR, + NM_SETTINGS_ERROR_INVALID_CONNECTION, + "ifcfg file '%s' unknown", in_ifcfg); + return; + } + + s_con = nm_connection_get_setting_connection (NM_CONNECTION (connection)); + if (!s_con) { + g_dbus_method_invocation_return_error (context, + NM_SETTINGS_ERROR, + NM_SETTINGS_ERROR_FAILED, + "unable to retrieve the connection setting"); + return; + } + + uuid = nm_setting_connection_get_uuid (s_con); + if (!uuid) { + g_dbus_method_invocation_return_error (context, + NM_SETTINGS_ERROR, + NM_SETTINGS_ERROR_FAILED, + "unable to get the UUID"); + return; + } + + path = nm_connection_get_path (NM_CONNECTION (connection)); + if (!path) { + g_dbus_method_invocation_return_error (context, + NM_SETTINGS_ERROR, + NM_SETTINGS_ERROR_FAILED, + "unable to get the connection D-Bus path"); + return; + } + + g_dbus_method_invocation_return_value (context, + g_variant_new ("(so)", uuid, path)); +} + +/*****************************************************************************/ + +static void +_dbus_clear (SettingsPluginIfcfg *self) +{ + SettingsPluginIfcfgPrivate *priv = SETTINGS_PLUGIN_IFCFG_GET_PRIVATE (self); + + nm_clear_g_signal_handler (priv->dbus.connection, &priv->dbus.signal_id); + + nm_clear_g_cancellable (&priv->dbus.cancellable); + + if (priv->dbus.interface) { + g_dbus_interface_skeleton_unexport (priv->dbus.interface); + nm_exported_object_skeleton_release (priv->dbus.interface); + priv->dbus.interface = NULL; + } + + g_clear_object (&priv->dbus.connection); +} + +static void +_dbus_connection_closed (GDBusConnection *connection, + gboolean remote_peer_vanished, + GError *error, + gpointer user_data) +{ + _LOGW ("dbus: %s bus closed", IFCFGRH1_DBUS_SERVICE_NAME); + _dbus_clear (SETTINGS_PLUGIN_IFCFG (user_data)); + + /* Retry or recover? */ +} + +static void +_dbus_request_name_done (GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + GDBusConnection *connection = G_DBUS_CONNECTION (source_object); + SettingsPluginIfcfg *self; + SettingsPluginIfcfgPrivate *priv; + gs_free_error GError *error = NULL; + gs_unref_variant GVariant *ret = NULL; + guint32 result; + + ret = g_dbus_connection_call_finish (connection, res, &error); + if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) + return; + + self = SETTINGS_PLUGIN_IFCFG (user_data); + priv = SETTINGS_PLUGIN_IFCFG_GET_PRIVATE (self); + + g_clear_object (&priv->dbus.cancellable); + + if (!ret) { + _LOGW ("dbus: couldn't acquire D-Bus service: %s", error->message); + _dbus_clear (self); + return; + } + + g_variant_get (ret, "(u)", &result); + + if (result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) { + _LOGW ("dbus: couldn't acquire ifcfgrh1 D-Bus service (already taken)"); + _dbus_clear (self); + return; + } + + { + GType skeleton_type = NMDBUS_TYPE_IFCFGRH1_SKELETON; + gs_free char *method_name_get_ifcfg_details = NULL; + NMExportedObjectDBusMethodImpl methods[] = { + { + .method_name = (method_name_get_ifcfg_details = nm_exported_object_skeletonify_method_name ("GetIfcfgDetails")), + .impl = G_CALLBACK (impl_ifcfgrh_get_ifcfg_details), + }, + }; + + priv->dbus.interface = nm_exported_object_skeleton_create (skeleton_type, + g_type_class_peek (SETTINGS_TYPE_PLUGIN_IFCFG), + methods, + G_N_ELEMENTS (methods), + (GObject *) self); + + if (!g_dbus_interface_skeleton_export (priv->dbus.interface, + priv->dbus.connection, + IFCFGRH1_DBUS_OBJECT_PATH, + &error)) { + nm_exported_object_skeleton_release (priv->dbus.interface); + priv->dbus.interface = NULL; + _LOGW ("dbus: failed exporting interface: %s", error->message); + _dbus_clear (self); + return; + } + } + + _LOGD ("dbus: aquired D-Bus service %s and exported %s object", + IFCFGRH1_DBUS_SERVICE_NAME, + IFCFGRH1_DBUS_OBJECT_PATH); +} + +static void +_dbus_create_done (GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + SettingsPluginIfcfg *self; + SettingsPluginIfcfgPrivate *priv; + gs_free_error GError *error = NULL; + GDBusConnection *connection; + + connection = g_dbus_connection_new_for_address_finish (res, &error); + if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) + return; + + self = SETTINGS_PLUGIN_IFCFG (user_data); + priv = SETTINGS_PLUGIN_IFCFG_GET_PRIVATE (self); + + g_clear_object (&priv->dbus.cancellable); + + if (!connection) { + _LOGW ("dbus: couldn't initialize system bus: %s", error->message); + return; + } + + priv->dbus.connection = connection; + priv->dbus.cancellable = g_cancellable_new (); + + priv->dbus.signal_id = g_signal_connect (priv->dbus.connection, + "closed", + G_CALLBACK (_dbus_connection_closed), + self); + + g_dbus_connection_call (priv->dbus.connection, + DBUS_SERVICE_DBUS, + DBUS_PATH_DBUS, + DBUS_INTERFACE_DBUS, + "RequestName", + g_variant_new ("(su)", + IFCFGRH1_DBUS_SERVICE_NAME, + DBUS_NAME_FLAG_DO_NOT_QUEUE), + G_VARIANT_TYPE ("(u)"), + G_DBUS_CALL_FLAGS_NONE, + -1, + priv->dbus.cancellable, + _dbus_request_name_done, + self); +} + +static void +_dbus_setup (SettingsPluginIfcfg *self) +{ + SettingsPluginIfcfgPrivate *priv = SETTINGS_PLUGIN_IFCFG_GET_PRIVATE (self); + gs_free char *address = NULL; + gs_free_error GError *error = NULL; + + g_return_if_fail (!priv->dbus.connection); + + address = g_dbus_address_get_for_bus_sync (G_BUS_TYPE_SYSTEM, NULL, &error); + if (address == NULL) { + _LOGW ("dbus: failed getting address for system bus: %s", error->message); + return; + } + + priv->dbus.cancellable = g_cancellable_new (); + + g_dbus_connection_new_for_address (address, + G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT + | G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION, + NULL, + priv->dbus.cancellable, + _dbus_create_done, + self); +} + +static void +config_changed_cb (NMConfig *config, + NMConfigData *config_data, + NMConfigChangeFlags changes, + NMConfigData *old_data, + SettingsPluginIfcfg *self) +{ + /* If the dbus connection for some reason is borked the D-Bus service + * won't be offered. + * + * On SIGHUP and SIGUSR1 try to re-connect to D-Bus. So in the unlikely + * event that the D-Bus conneciton is broken, that allows for recovery + * without need for restarting NetworkManager. */ + if (NM_FLAGS_ANY (changes, NM_CONFIG_CHANGE_CAUSE_SIGHUP + | NM_CONFIG_CHANGE_CAUSE_SIGUSR1)) { + if (!SETTINGS_PLUGIN_IFCFG_GET_PRIVATE (self)->dbus.connection) + _dbus_setup (self); + } +} + +/*****************************************************************************/ + +static void +get_property (GObject *object, guint prop_id, + GValue *value, GParamSpec *pspec) +{ + switch (prop_id) { + case NM_SETTINGS_PLUGIN_PROP_NAME: + g_value_set_string (value, IFCFG_PLUGIN_NAME); + break; + case NM_SETTINGS_PLUGIN_PROP_INFO: + g_value_set_string (value, IFCFG_PLUGIN_INFO); + break; + case NM_SETTINGS_PLUGIN_PROP_CAPABILITIES: + g_value_set_uint (value, NM_SETTINGS_PLUGIN_CAP_MODIFY_CONNECTIONS); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +/*****************************************************************************/ + +static void +init (NMSettingsPlugin *config) +{ +} + +static void +settings_plugin_ifcfg_init (SettingsPluginIfcfg *plugin) +{ + SettingsPluginIfcfgPrivate *priv = SETTINGS_PLUGIN_IFCFG_GET_PRIVATE ((SettingsPluginIfcfg *) plugin); + + priv->connections = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref); +} + +static void +constructed (GObject *object) +{ + SettingsPluginIfcfg *self = SETTINGS_PLUGIN_IFCFG (object); + SettingsPluginIfcfgPrivate *priv = SETTINGS_PLUGIN_IFCFG_GET_PRIVATE (self); + + G_OBJECT_CLASS (settings_plugin_ifcfg_parent_class)->constructed (object); + + priv->config = nm_config_get (); + g_object_add_weak_pointer ((GObject *) priv->config, (gpointer *) &priv->config); + g_signal_connect (priv->config, + NM_CONFIG_SIGNAL_CONFIG_CHANGED, + G_CALLBACK (config_changed_cb), + self); + + _dbus_setup (self); +} + +static void +dispose (GObject *object) +{ + SettingsPluginIfcfg *self = SETTINGS_PLUGIN_IFCFG (object); + SettingsPluginIfcfgPrivate *priv = SETTINGS_PLUGIN_IFCFG_GET_PRIVATE (self); + + if (priv->config) { + g_object_remove_weak_pointer ((GObject *) priv->config, (gpointer *) &priv->config); + g_signal_handlers_disconnect_by_func (priv->config, config_changed_cb, self); + priv->config = NULL; + } + + _dbus_clear (self); + + if (priv->connections) { + g_hash_table_destroy (priv->connections); + priv->connections = NULL; + } + + if (priv->ifcfg_monitor) { + if (priv->ifcfg_monitor_id) + g_signal_handler_disconnect (priv->ifcfg_monitor, priv->ifcfg_monitor_id); + + g_file_monitor_cancel (priv->ifcfg_monitor); + g_object_unref (priv->ifcfg_monitor); + } + + G_OBJECT_CLASS (settings_plugin_ifcfg_parent_class)->dispose (object); +} + +static void +settings_plugin_ifcfg_class_init (SettingsPluginIfcfgClass *req_class) +{ + GObjectClass *object_class = G_OBJECT_CLASS (req_class); + + object_class->constructed = constructed; + object_class->dispose = dispose; + object_class->get_property = get_property; + + g_object_class_override_property (object_class, + NM_SETTINGS_PLUGIN_PROP_NAME, + NM_SETTINGS_PLUGIN_NAME); + + g_object_class_override_property (object_class, + NM_SETTINGS_PLUGIN_PROP_INFO, + NM_SETTINGS_PLUGIN_INFO); + + g_object_class_override_property (object_class, + NM_SETTINGS_PLUGIN_PROP_CAPABILITIES, + NM_SETTINGS_PLUGIN_CAPABILITIES); +} + +static void +settings_plugin_interface_init (NMSettingsPluginInterface *plugin_iface) +{ + plugin_iface->get_connections = get_connections; + plugin_iface->add_connection = add_connection; + plugin_iface->load_connection = load_connection; + plugin_iface->reload_connections = reload_connections; + plugin_iface->get_unmanaged_specs = get_unmanaged_specs; + plugin_iface->get_unrecognized_specs = get_unrecognized_specs; + plugin_iface->init = init; +} + +/*****************************************************************************/ + +G_MODULE_EXPORT GObject * +nm_settings_plugin_factory (void) +{ + return g_object_ref (settings_plugin_ifcfg_get ()); +} diff --git a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-plugin.h b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-plugin.h new file mode 100644 index 00000000..d815cc51 --- /dev/null +++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-plugin.h @@ -0,0 +1,39 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/* NetworkManager system settings service + * + * Dan Williams + * Søren Sandmann + * + * 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) 2007 - 2008 Red Hat, Inc. + */ + +#ifndef _PLUGIN_H_ +#define _PLUGIN_H_ + +#define SETTINGS_TYPE_PLUGIN_IFCFG (settings_plugin_ifcfg_get_type ()) +#define SETTINGS_PLUGIN_IFCFG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SETTINGS_TYPE_PLUGIN_IFCFG, SettingsPluginIfcfg)) +#define SETTINGS_PLUGIN_IFCFG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SETTINGS_TYPE_PLUGIN_IFCFG, SettingsPluginIfcfgClass)) +#define SETTINGS_IS_PLUGIN_IFCFG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SETTINGS_TYPE_PLUGIN_IFCFG)) +#define SETTINGS_IS_PLUGIN_IFCFG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SETTINGS_TYPE_PLUGIN_IFCFG)) +#define SETTINGS_PLUGIN_IFCFG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SETTINGS_TYPE_PLUGIN_IFCFG, SettingsPluginIfcfgClass)) + +typedef struct _SettingsPluginIfcfg SettingsPluginIfcfg; +typedef struct _SettingsPluginIfcfgClass SettingsPluginIfcfgClass; + +GType settings_plugin_ifcfg_get_type (void); + +#endif /* _PLUGIN_H_ */ diff --git a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c new file mode 100644 index 00000000..b64cad35 --- /dev/null +++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c @@ -0,0 +1,5361 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/* NetworkManager system settings service + * + * 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 2008 - 2015 Red Hat, Inc. + */ + +#include "nm-default.h" + +#include "nms-ifcfg-rh-reader.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "nm-connection.h" +#include "nm-dbus-interface.h" +#include "nm-setting-connection.h" +#include "nm-setting-ip4-config.h" +#include "nm-setting-vlan.h" +#include "nm-setting-ip6-config.h" +#include "nm-setting-wired.h" +#include "nm-setting-wireless.h" +#include "nm-setting-8021x.h" +#include "nm-setting-bond.h" +#include "nm-setting-team.h" +#include "nm-setting-team-port.h" +#include "nm-setting-bridge.h" +#include "nm-setting-bridge-port.h" +#include "nm-setting-dcb.h" +#include "nm-setting-proxy.h" +#include "nm-setting-generic.h" +#include "nm-core-internal.h" +#include "nm-utils.h" + +#include "platform/nm-platform.h" +#include "NetworkManagerUtils.h" + +#include "nms-ifcfg-rh-common.h" +#include "nms-ifcfg-rh-utils.h" +#include "shvar.h" + +/*****************************************************************************/ + +#define _NMLOG_DOMAIN LOGD_SETTINGS +#define _NMLOG_PREFIX_NAME "ifcfg-rh" +#define _NMLOG(level, ...) \ + G_STMT_START { \ + nm_log ((level), (_NMLOG_DOMAIN), \ + "%s" _NM_UTILS_MACRO_FIRST(__VA_ARGS__), \ + _NMLOG_PREFIX_NAME": " \ + _NM_UTILS_MACRO_REST(__VA_ARGS__)); \ + } G_STMT_END + +#define PARSE_WARNING(...) _LOGW ("%s" _NM_UTILS_MACRO_FIRST(__VA_ARGS__), " " _NM_UTILS_MACRO_REST(__VA_ARGS__)) + +/*****************************************************************************/ + +static gboolean +get_uint (const char *str, guint32 *value) +{ + gint64 tmp; + + tmp = _nm_utils_ascii_str_to_int64 (str, 0, 0, G_MAXUINT32, -1); + if (tmp == -1) + return FALSE; + *value = tmp; + return TRUE; +} + +static char * +make_connection_name (shvarFile *ifcfg, + const char *ifcfg_name, + const char *suggested, + const char *prefix) +{ + char *full_name = NULL, *name; + + /* If the ifcfg file already has a NAME, always use that */ + name = svGetValueString (ifcfg, "NAME"); + if (name && strlen (name)) + return name; + + /* Otherwise construct a new NAME */ + g_free (name); + if (!prefix) + prefix = _("System"); + + /* For cosmetic reasons, if the suggested name is the same as + * the ifcfg files name, don't use it. Mainly for wifi so that + * the SSID is shown in the connection ID instead of just "wlan0". + */ + if (suggested && strcmp (ifcfg_name, suggested)) + full_name = g_strdup_printf ("%s %s (%s)", prefix, suggested, ifcfg_name); + else + full_name = g_strdup_printf ("%s %s", prefix, ifcfg_name); + + return full_name; +} + +static NMSetting * +make_connection_setting (const char *file, + shvarFile *ifcfg, + const char *type, + const char *suggested, + const char *prefix) +{ + NMSettingConnection *s_con; + NMSettingConnectionLldp lldp; + const char *ifcfg_name = NULL; + char *new_id, *uuid = NULL, *zone = NULL, *value; + gs_free char *stable_id = NULL; + + ifcfg_name = utils_get_ifcfg_name (file, TRUE); + if (!ifcfg_name) + return NULL; + + s_con = NM_SETTING_CONNECTION (nm_setting_connection_new ()); + + new_id = make_connection_name (ifcfg, ifcfg_name, suggested, prefix); + g_object_set (s_con, NM_SETTING_CONNECTION_ID, new_id, NULL); + g_free (new_id); + + /* Try for a UUID key before falling back to hashing the file name */ + uuid = svGetValueString (ifcfg, "UUID"); + if (!uuid || !strlen (uuid)) { + g_free (uuid); + uuid = nm_utils_uuid_generate_from_string (svFileGetName (ifcfg), -1, NM_UTILS_UUID_TYPE_LEGACY, NULL); + } + + stable_id = svGetValueString (ifcfg, "STABLE_ID"); + + g_object_set (s_con, + NM_SETTING_CONNECTION_TYPE, type, + NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_STABLE_ID, stable_id, + NULL); + g_free (uuid); + + value = svGetValueString (ifcfg, "DEVICE"); + if (value) { + GError *error = NULL; + + if (nm_utils_is_valid_iface_name (value, &error)) { + g_object_set (s_con, + NM_SETTING_CONNECTION_INTERFACE_NAME, value, + NULL); + } else { + PARSE_WARNING ("invalid DEVICE name '%s': %s", value, error->message); + g_error_free (error); + } + g_free (value); + } + + value = svGetValueString (ifcfg, "LLDP"); + if (!g_strcmp0 (value, "rx")) + lldp = NM_SETTING_CONNECTION_LLDP_ENABLE_RX; + else + lldp = svParseBoolean (value, NM_SETTING_CONNECTION_LLDP_DEFAULT); + g_free (value); + + /* Missing ONBOOT is treated as "ONBOOT=true" by the old network service */ + g_object_set (s_con, + NM_SETTING_CONNECTION_AUTOCONNECT, + svGetValueBoolean (ifcfg, "ONBOOT", TRUE), + NM_SETTING_CONNECTION_AUTOCONNECT_PRIORITY, + (gint) svGetValueInt64 (ifcfg, "AUTOCONNECT_PRIORITY", 10, + NM_SETTING_CONNECTION_AUTOCONNECT_PRIORITY_MIN, + NM_SETTING_CONNECTION_AUTOCONNECT_PRIORITY_MAX, + NM_SETTING_CONNECTION_AUTOCONNECT_PRIORITY_DEFAULT), + NM_SETTING_CONNECTION_AUTOCONNECT_RETRIES, + (gint) svGetValueInt64 (ifcfg, "AUTOCONNECT_RETRIES", 10, + -1, G_MAXINT32, -1), + NM_SETTING_CONNECTION_AUTOCONNECT_SLAVES, + svGetValueBoolean (ifcfg, "AUTOCONNECT_SLAVES", NM_SETTING_CONNECTION_AUTOCONNECT_SLAVES_DEFAULT), + NM_SETTING_CONNECTION_LLDP, lldp, + NULL); + + value = svGetValueString (ifcfg, "USERS"); + if (value) { + char **items, **iter; + + items = g_strsplit_set (value, " ", -1); + for (iter = items; iter && *iter; iter++) { + if (strlen (*iter)) { + if (!nm_setting_connection_add_permission (s_con, "user", *iter, NULL)) + PARSE_WARNING ("invalid USERS item '%s'", *iter); + } + } + g_free (value); + g_strfreev (items); + } + + + zone = svGetValueString (ifcfg, "ZONE"); + if (!zone || !strlen (zone)) { + g_free (zone); + zone = NULL; + } + g_object_set (s_con, NM_SETTING_CONNECTION_ZONE, zone, NULL); + g_free (zone); + + value = svGetValueString (ifcfg, "SECONDARY_UUIDS"); + if (value) { + char **items, **iter; + + items = g_strsplit_set (value, " \t", -1); + for (iter = items; iter && *iter; iter++) { + if (strlen (*iter)) { + if (!nm_setting_connection_add_secondary (s_con, *iter)) + PARSE_WARNING ("secondary connection UUID '%s' already added", *iter); + } + } + g_free (value); + g_strfreev (items); + } + + value = svGetValueString (ifcfg, "BRIDGE_UUID"); + if (!value) + value = svGetValueString (ifcfg, "BRIDGE"); + if (value) { + const char *old_value; + + if ((old_value = nm_setting_connection_get_master (s_con))) { + PARSE_WARNING ("Already configured as slave of %s. Ignoring BRIDGE=\"%s\"", + old_value, value); + } else { + g_object_set (s_con, NM_SETTING_CONNECTION_MASTER, value, NULL); + g_object_set (s_con, NM_SETTING_CONNECTION_SLAVE_TYPE, + NM_SETTING_BRIDGE_SETTING_NAME, NULL); + } + g_free (value); + } + + value = svGetValueString (ifcfg, "GATEWAY_PING_TIMEOUT"); + if (value) { + gint64 tmp; + + tmp = _nm_utils_ascii_str_to_int64 (value, 10, 0, G_MAXINT32 - 1, -1); + if (tmp >= 0) + g_object_set (s_con, NM_SETTING_CONNECTION_GATEWAY_PING_TIMEOUT, (guint) tmp, NULL); + else + PARSE_WARNING ("invalid GATEWAY_PING_TIMEOUT time"); + g_free (value); + } + + switch (svGetValueBoolean (ifcfg, "CONNECTION_METERED", -1)) { + case TRUE: + g_object_set (s_con, NM_SETTING_CONNECTION_METERED, NM_METERED_YES, NULL); + break; + case FALSE: + g_object_set (s_con, NM_SETTING_CONNECTION_METERED, NM_METERED_NO, NULL); + break; + } + + return NM_SETTING (s_con); +} + +/* Returns TRUE on missing address or valid address */ +static gboolean +read_ip4_address (shvarFile *ifcfg, + const char *tag, + char **out_addr, + GError **error) +{ + char *value = NULL; + + g_return_val_if_fail (ifcfg != NULL, FALSE); + g_return_val_if_fail (tag != NULL, FALSE); + g_return_val_if_fail (out_addr != NULL, FALSE); + g_return_val_if_fail (!error || !*error, FALSE); + + *out_addr = NULL; + + value = svGetValueString (ifcfg, tag); + if (!value) + return TRUE; + + if (nm_utils_ipaddr_valid (AF_INET, value)) { + *out_addr = value; + return TRUE; + } else { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Invalid %s IP4 address '%s'", tag, value); + g_free (value); + return FALSE; + } +} + +static char * +get_numbered_tag (char *tag_name, int which) +{ + if (which == -1) + return g_strdup (tag_name); + return g_strdup_printf ("%s%u", tag_name, which); +} + +static gboolean +is_any_ip4_address_defined (shvarFile *ifcfg, int *idx) +{ + int i, ignore, *ret_idx;; + + ret_idx = idx ? idx : &ignore; + + for (i = -1; i <= 2; i++) { + char *tag; + char *value; + + tag = get_numbered_tag ("IPADDR", i); + value = svGetValueString (ifcfg, tag); + g_free (tag); + if (value) { + g_free (value); + *ret_idx = i; + return TRUE; + } + + tag = get_numbered_tag ("PREFIX", i); + value = svGetValueString (ifcfg, tag); + g_free(tag); + if (value) { + g_free (value); + *ret_idx = i; + return TRUE; + } + + tag = get_numbered_tag ("NETMASK", i); + value = svGetValueString (ifcfg, tag); + g_free(tag); + if (value) { + g_free (value); + *ret_idx = i; + return TRUE; + } + } + return FALSE; +} + +/* Returns TRUE on missing address or valid address */ +static gboolean +read_full_ip4_address (shvarFile *ifcfg, + gint32 which, + NMIPAddress *base_addr, + NMIPAddress **out_address, + char **out_gateway, + GError **error) +{ + char *ip_tag, *prefix_tag, *netmask_tag, *gw_tag; + char *ip = NULL; + int prefix = 0; + gboolean success = FALSE; + char *value; + guint32 tmp; + + g_return_val_if_fail (which >= -1, FALSE); + g_return_val_if_fail (ifcfg != NULL, FALSE); + g_return_val_if_fail (out_address != NULL, FALSE); + g_return_val_if_fail (*out_address == NULL, FALSE); + g_return_val_if_fail (!error || !*error, FALSE); + + ip_tag = get_numbered_tag ("IPADDR", which); + prefix_tag = get_numbered_tag ("PREFIX", which); + netmask_tag = get_numbered_tag ("NETMASK", which); + gw_tag = get_numbered_tag ("GATEWAY", which); + + /* IP address */ + if (!read_ip4_address (ifcfg, ip_tag, &ip, error)) + goto done; + if (!ip) { + if (base_addr) + ip = g_strdup (nm_ip_address_get_address (base_addr)); + else { + success = TRUE; + goto done; + } + } + + /* Gateway */ + if (out_gateway && !*out_gateway) { + if (!read_ip4_address (ifcfg, gw_tag, out_gateway, error)) + goto done; + } + + /* Prefix */ + value = svGetValueString (ifcfg, prefix_tag); + if (value) { + prefix = _nm_utils_ascii_str_to_int64 (value, 10, 0, 32, -1); + if (prefix < 0) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Invalid IP4 prefix '%s'", value); + g_free (value); + goto done; + } + g_free (value); + } else { + /* Fall back to NETMASK if no PREFIX was specified */ + if (!read_ip4_address (ifcfg, netmask_tag, &value, error)) + goto done; + if (value) { + inet_pton (AF_INET, value, &tmp); + prefix = nm_utils_ip4_netmask_to_prefix (tmp); + g_free (value); + } else { + if (base_addr) + prefix = nm_ip_address_get_prefix (base_addr); + else { + /* Try to autodetermine the prefix for the address' class */ + if (inet_pton (AF_INET, ip, &tmp) == 1) { + prefix = nm_utils_ip4_get_default_prefix (tmp); + + PARSE_WARNING ("missing %s, assuming %s/%d", prefix_tag, ip, prefix); + } else { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Missing IP4 prefix"); + goto done; + } + } + } + } + + *out_address = nm_ip_address_new (AF_INET, ip, prefix, error); + if (*out_address) + success = TRUE; + +done: + g_free (ip); + g_free (ip_tag); + g_free (prefix_tag); + g_free (netmask_tag); + g_free (gw_tag); + + return success; +} + +/* Returns TRUE on missing route or valid route */ +static gboolean +read_one_ip4_route (shvarFile *ifcfg, + guint32 which, + NMIPRoute **out_route, + GError **error) +{ + char *ip_tag, *netmask_tag, *gw_tag, *metric_tag, *value; + char *dest = NULL, *next_hop = NULL; + gint64 prefix, metric; + gboolean success = FALSE; + + g_return_val_if_fail (ifcfg != NULL, FALSE); + g_return_val_if_fail (out_route != NULL, FALSE); + g_return_val_if_fail (*out_route == NULL, FALSE); + g_return_val_if_fail (!error || !*error, FALSE); + + ip_tag = g_strdup_printf ("ADDRESS%u", which); + netmask_tag = g_strdup_printf ("NETMASK%u", which); + gw_tag = g_strdup_printf ("GATEWAY%u", which); + metric_tag = g_strdup_printf ("METRIC%u", which); + + /* Destination */ + if (!read_ip4_address (ifcfg, ip_tag, &dest, error)) + goto out; + if (!dest) { + /* Check whether IP is missing or 0.0.0.0 */ + char *val; + val = svGetValueString (ifcfg, ip_tag); + if (!val) { + *out_route = NULL; + success = TRUE; /* missing route = success */ + goto out; + } + g_free (val); + } + + /* Next hop */ + if (!read_ip4_address (ifcfg, gw_tag, &next_hop, error)) + goto out; + /* We don't make distinction between missing GATEWAY IP and 0.0.0.0 */ + + /* Prefix */ + if (!read_ip4_address (ifcfg, netmask_tag, &value, error)) + goto out; + if (value) { + guint32 netmask; + + inet_pton (AF_INET, value, &netmask); + prefix = nm_utils_ip4_netmask_to_prefix (netmask); + g_free (value); + if (prefix == 0 || netmask != nm_utils_ip4_prefix_to_netmask (prefix)) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Invalid IP4 netmask '%s' \"%s\"", netmask_tag, nm_utils_inet4_ntop (netmask, NULL)); + goto out; + } + } else { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Missing IP4 route element '%s'", netmask_tag); + goto out; + } + + /* Metric */ + value = svGetValueString (ifcfg, metric_tag); + if (value) { + metric = _nm_utils_ascii_str_to_int64 (value, 10, 0, G_MAXUINT32, -1); + if (metric < 0) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Invalid IP4 route metric '%s'", value); + g_free (value); + goto out; + } + g_free (value); + } else + metric = -1; + + *out_route = nm_ip_route_new (AF_INET, dest, prefix, next_hop, metric, error); + if (*out_route) + success = TRUE; + +out: + g_free (dest); + g_free (next_hop); + g_free (ip_tag); + g_free (netmask_tag); + g_free (gw_tag); + g_free (metric_tag); + return success; +} + +static gboolean +read_route_file_legacy (const char *filename, NMSettingIPConfig *s_ip4, GError **error) +{ + char *contents = NULL; + gsize len = 0; + char **lines = NULL, **iter; + GRegex *regex_to1, *regex_to2, *regex_via, *regex_metric; + GMatchInfo *match_info; + int prefix_int; + gint64 metric_int; + gboolean success = FALSE; + + const char *pattern_empty = "^\\s*(\\#.*)?$"; + const char *pattern_to1 = "^\\s*(\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}|default)" /* IP or 'default' keyword */ + "(?:/(\\d{1,2}))?"; /* optional prefix */ + const char *pattern_to2 = "to\\s+(\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}|default)" /* IP or 'default' keyword */ + "(?:/(\\d{1,2}))?"; /* optional prefix */ + const char *pattern_via = "via\\s+(\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3})"; /* IP of gateway */ + const char *pattern_metric = "metric\\s+(\\d+)"; /* metric */ + + g_return_val_if_fail (filename != NULL, FALSE); + g_return_val_if_fail (s_ip4 != NULL, FALSE); + g_return_val_if_fail (!error || !*error, FALSE); + + /* Read the route file */ + if (!g_file_get_contents (filename, &contents, &len, NULL) || !len) { + g_free (contents); + return TRUE; /* missing/empty = success */ + } + + /* Create regexes for pieces to be matched */ + regex_to1 = g_regex_new (pattern_to1, 0, 0, NULL); + regex_to2 = g_regex_new (pattern_to2, 0, 0, NULL); + regex_via = g_regex_new (pattern_via, 0, 0, NULL); + regex_metric = g_regex_new (pattern_metric, 0, 0, NULL); + + /* Iterate through file lines */ + lines = g_strsplit_set (contents, "\n\r", -1); + for (iter = lines; iter && *iter; iter++) { + gs_free char *next_hop = NULL, *dest = NULL; + char *prefix, *metric; + NMIPRoute *route; + + /* Skip empty lines */ + if (g_regex_match_simple (pattern_empty, *iter, 0, 0)) + continue; + + /* Destination */ + g_regex_match (regex_to1, *iter, 0, &match_info); + if (!g_match_info_matches (match_info)) { + g_match_info_free (match_info); + g_regex_match (regex_to2, *iter, 0, &match_info); + if (!g_match_info_matches (match_info)) { + g_match_info_free (match_info); + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Missing IP4 route destination address in record: '%s'", *iter); + goto error; + } + } + dest = g_match_info_fetch (match_info, 1); + if (!strcmp (dest, "default")) { + g_match_info_free (match_info); + PARSE_WARNING ("ignoring manual default route: '%s' (%s)", *iter, filename); + continue; + } + if (!nm_utils_ipaddr_valid (AF_INET, dest)) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Invalid IP4 route destination address '%s'", dest); + g_match_info_free (match_info); + goto error; + } + + /* Prefix - is optional; 32 if missing */ + prefix = g_match_info_fetch (match_info, 2); + g_match_info_free (match_info); + prefix_int = 32; + if (prefix) { + prefix_int = _nm_utils_ascii_str_to_int64 (prefix, 10, 1, 32, -1); + if (prefix_int == -1) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Invalid IP4 route destination prefix '%s'", prefix); + g_free (prefix); + goto error; + } + } + g_free (prefix); + + /* Next hop */ + g_regex_match (regex_via, *iter, 0, &match_info); + if (g_match_info_matches (match_info)) { + next_hop = g_match_info_fetch (match_info, 1); + if (!nm_utils_ipaddr_valid (AF_INET, next_hop)) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Invalid IP4 route gateway address '%s'", + next_hop); + g_match_info_free (match_info); + goto error; + } + } else { + /* we don't make distinction between missing GATEWAY IP and 0.0.0.0 */ + } + g_match_info_free (match_info); + + /* Metric */ + g_regex_match (regex_metric, *iter, 0, &match_info); + metric_int = -1; + if (g_match_info_matches (match_info)) { + metric = g_match_info_fetch (match_info, 1); + metric_int = _nm_utils_ascii_str_to_int64 (metric, 10, 0, G_MAXUINT32, -1); + if (metric_int == -1) { + g_match_info_free (match_info); + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Invalid IP4 route metric '%s'", metric); + g_free (metric); + goto error; + } + g_free (metric); + } + g_match_info_free (match_info); + + route = nm_ip_route_new (AF_INET, dest, prefix_int, next_hop, metric_int, error); + if (!route) + goto error; + if (!nm_setting_ip_config_add_route (s_ip4, route)) + PARSE_WARNING ("duplicate IP4 route"); + nm_ip_route_unref (route); + } + + success = TRUE; + +error: + g_free (contents); + g_strfreev (lines); + g_regex_unref (regex_to1); + g_regex_unref (regex_to2); + g_regex_unref (regex_via); + g_regex_unref (regex_metric); + + return success; +} + +static void +parse_dns_options (NMSettingIPConfig *ip_config, const char *value) +{ + char **options = NULL; + + g_return_if_fail (ip_config); + + if (!value) + return; + + if (!nm_setting_ip_config_has_dns_options (ip_config)) + nm_setting_ip_config_clear_dns_options (ip_config, TRUE); + + options = g_strsplit (value, " ", 0); + if (options) { + char **item; + for (item = options; *item; item++) { + if (strlen (*item)) { + if (!nm_setting_ip_config_add_dns_option (ip_config, *item)) + PARSE_WARNING ("can't add DNS option '%s'", *item); + } + } + g_strfreev (options); + } +} + +static gboolean +parse_full_ip6_address (shvarFile *ifcfg, + const char *addr_str, + int i, + NMIPAddress **out_address, + GError **error) +{ + char **list; + char *ip_val, *prefix_val; + int prefix; + gboolean success = FALSE; + + g_return_val_if_fail (addr_str != NULL, FALSE); + g_return_val_if_fail (out_address != NULL, FALSE); + g_return_val_if_fail (*out_address == NULL, FALSE); + g_return_val_if_fail (!error || !*error, FALSE); + + /* Split the address and prefix */ + list = g_strsplit_set (addr_str, "/", 2); + if (g_strv_length (list) < 1) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Invalid IP6 address '%s'", addr_str); + goto error; + } + + ip_val = list[0]; + + prefix_val = list[1]; + if (prefix_val) { + prefix = _nm_utils_ascii_str_to_int64 (prefix_val, 10, 0, 128, -1); + if (prefix < 0) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Invalid IP6 prefix '%s'", prefix_val); + goto error; + } + } else { + /* Missing prefix is treated as prefix of 64 */ + prefix = 64; + } + + *out_address = nm_ip_address_new (AF_INET6, ip_val, prefix, error); + if (*out_address) + success = TRUE; + +error: + g_strfreev (list); + return success; +} + +/* IPv6 address is very complex to describe completely by a regular expression, + * so don't try to, rather use looser syntax to comprise all possibilities + * NOTE: The regexes below don't describe all variants allowed by 'ip route add', + * namely destination IP without 'to' keyword is recognized just at line start. + */ +#define IPV6_ADDR_REGEX "[0-9A-Fa-f:.]+" + +static gboolean +read_route6_file (const char *filename, NMSettingIPConfig *s_ip6, GError **error) +{ + char *contents = NULL; + gsize len = 0; + char **lines = NULL, **iter; + GRegex *regex_to1, *regex_to2, *regex_via, *regex_metric; + GMatchInfo *match_info; + char *dest = NULL, *prefix = NULL, *next_hop = NULL, *metric = NULL; + int prefix_int; + gint64 metric_int; + gboolean success = FALSE; + + const char *pattern_empty = "^\\s*(\\#.*)?$"; + const char *pattern_to1 = "^\\s*(default|" IPV6_ADDR_REGEX ")" /* IPv6 or 'default' keyword */ + "(?:/(\\d{1,3}))?"; /* optional prefix */ + const char *pattern_to2 = "to\\s+(default|" IPV6_ADDR_REGEX ")" /* IPv6 or 'default' keyword */ + "(?:/(\\d{1,3}))?"; /* optional prefix */ + const char *pattern_via = "via\\s+(" IPV6_ADDR_REGEX ")"; /* IPv6 of gateway */ + const char *pattern_metric = "metric\\s+(\\d+)"; /* metric */ + + g_return_val_if_fail (filename != NULL, FALSE); + g_return_val_if_fail (s_ip6 != NULL, FALSE); + g_return_val_if_fail (!error || !*error, FALSE); + + /* Read the route file */ + if (!g_file_get_contents (filename, &contents, &len, NULL) || !len) { + g_free (contents); + return TRUE; /* missing/empty = success */ + } + + /* Create regexes for pieces to be matched */ + regex_to1 = g_regex_new (pattern_to1, 0, 0, NULL); + regex_to2 = g_regex_new (pattern_to2, 0, 0, NULL); + regex_via = g_regex_new (pattern_via, 0, 0, NULL); + regex_metric = g_regex_new (pattern_metric, 0, 0, NULL); + + /* Iterate through file lines */ + lines = g_strsplit_set (contents, "\n\r", -1); + for (iter = lines; iter && *iter; iter++) { + NMIPRoute *route; + + /* Skip empty lines */ + if (g_regex_match_simple (pattern_empty, *iter, 0, 0)) + continue; + + /* Destination */ + g_regex_match (regex_to1, *iter, 0, &match_info); + if (!g_match_info_matches (match_info)) { + g_match_info_free (match_info); + g_regex_match (regex_to2, *iter, 0, &match_info); + if (!g_match_info_matches (match_info)) { + g_match_info_free (match_info); + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Missing IP6 route destination address in record: '%s'", *iter); + goto error; + } + } + dest = g_match_info_fetch (match_info, 1); + if (!g_strcmp0 (dest, "default")) { + /* Ignore default route - NM handles it internally */ + g_clear_pointer (&dest, g_free); + g_match_info_free (match_info); + PARSE_WARNING ("ignoring manual default route: '%s' (%s)", *iter, filename); + continue; + } + + /* Prefix - is optional; 128 if missing */ + prefix = g_match_info_fetch (match_info, 2); + g_match_info_free (match_info); + prefix_int = 128; + if (prefix) { + prefix_int = _nm_utils_ascii_str_to_int64 (prefix, 10, 1, 128, -1); + if (prefix_int == -1) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Invalid IP6 route destination prefix '%s'", prefix); + g_free (dest); + g_free (prefix); + goto error; + } + } + g_free (prefix); + + /* Next hop */ + g_regex_match (regex_via, *iter, 0, &match_info); + if (g_match_info_matches (match_info)) { + next_hop = g_match_info_fetch (match_info, 1); + if (!nm_utils_ipaddr_valid (AF_INET6, next_hop)) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Invalid IPv6 route nexthop address '%s'", + next_hop); + g_match_info_free (match_info); + g_free (dest); + g_free (next_hop); + goto error; + } + } else { + /* Missing "via" is taken as :: */ + next_hop = NULL; + } + g_match_info_free (match_info); + + /* Metric */ + g_regex_match (regex_metric, *iter, 0, &match_info); + metric_int = -1; + if (g_match_info_matches (match_info)) { + metric = g_match_info_fetch (match_info, 1); + metric_int = _nm_utils_ascii_str_to_int64 (metric, 10, 0, G_MAXUINT32, -1); + if (metric_int == -1) { + g_match_info_free (match_info); + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Invalid IP6 route metric '%s'", metric); + g_free (dest); + g_free (next_hop); + g_free (metric); + goto error; + } + g_free (metric); + } + g_match_info_free (match_info); + + route = nm_ip_route_new (AF_INET6, dest, prefix_int, next_hop, metric_int, error); + g_free (dest); + g_free (next_hop); + if (!route) + goto error; + if (!nm_setting_ip_config_add_route (s_ip6, route)) + PARSE_WARNING ("duplicate IP6 route"); + nm_ip_route_unref (route); + } + + success = TRUE; + +error: + g_free (contents); + g_strfreev (lines); + g_regex_unref (regex_to1); + g_regex_unref (regex_to2); + g_regex_unref (regex_via); + g_regex_unref (regex_metric); + + return success; +} + +static NMSetting * +make_proxy_setting (shvarFile *ifcfg, GError **error) +{ + NMSettingProxy *s_proxy = NULL; + char *value = NULL; + NMSettingProxyMethod method; + + value = svGetValueString (ifcfg, "PROXY_METHOD"); + if (!value) + return NULL; + + if (!g_ascii_strcasecmp (value, "auto")) + method = NM_SETTING_PROXY_METHOD_AUTO; + else + method = NM_SETTING_PROXY_METHOD_NONE; + g_free (value); + + s_proxy = (NMSettingProxy *) nm_setting_proxy_new (); + + switch (method) { + case NM_SETTING_PROXY_METHOD_AUTO: + g_object_set (s_proxy, + NM_SETTING_PROXY_METHOD, (int) NM_SETTING_PROXY_METHOD_AUTO, + NULL); + + value = svGetValueString (ifcfg, "PAC_URL"); + if (value) { + value = g_strstrip (value); + g_object_set (s_proxy, NM_SETTING_PROXY_PAC_URL, value, NULL); + g_free (value); + } + + value = svGetValueString (ifcfg, "PAC_SCRIPT"); + if (value) { + value = g_strstrip (value); + g_object_set (s_proxy, NM_SETTING_PROXY_PAC_SCRIPT, value, NULL); + g_free (value); + } + + break; + case NM_SETTING_PROXY_METHOD_NONE: + g_object_set (s_proxy, + NM_SETTING_PROXY_METHOD, (int) NM_SETTING_PROXY_METHOD_NONE, + NULL); + break; + } + + value = svGetValueString (ifcfg, "BROWSER_ONLY"); + if (value) { + if (!g_ascii_strcasecmp (value, "yes")) + g_object_set (s_proxy, NM_SETTING_PROXY_BROWSER_ONLY, TRUE, NULL); + g_free (value); + } + + return NM_SETTING (s_proxy); +} + +static NMSetting * +make_ip4_setting (shvarFile *ifcfg, + const char *network_file, + GError **error) +{ + NMSettingIPConfig *s_ip4 = NULL; + char *value = NULL; + char *route_path = NULL; + char *method; + gs_free char *dns_options_free = NULL; + const char *dns_options = NULL; + gs_free char *gateway = NULL; + gint32 i; + shvarFile *network_ifcfg; + shvarFile *route_ifcfg; + gboolean never_default = FALSE; + gint64 timeout; + gint priority; + + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); + + /* First check if DEFROUTE is set for this device; DEFROUTE has the + * opposite meaning from never-default. The default if DEFROUTE is not + * specified is DEFROUTE=yes which means that this connection can be used + * as a default route + */ + never_default = !svGetValueBoolean (ifcfg, "DEFROUTE", TRUE); + + /* Then check if GATEWAYDEV; it's global and overrides DEFROUTE */ + network_ifcfg = svOpenFile (network_file, NULL); + if (network_ifcfg) { + char *gatewaydev; + + /* Get the connection ifcfg device name and the global gateway device */ + value = svGetValueString (ifcfg, "DEVICE"); + gatewaydev = svGetValueString (network_ifcfg, "GATEWAYDEV"); + dns_options = svGetValue (network_ifcfg, "RES_OPTIONS", &dns_options_free); + + /* If there was a global gateway device specified, then only connections + * for that device can be the default connection. + */ + if (gatewaydev && value) + never_default = !!strcmp (value, gatewaydev); + + g_free (gatewaydev); + g_free (value); + svCloseFile (network_ifcfg); + } + + value = svGetValueString (ifcfg, "BOOTPROTO"); + + if (!value || !*value || !g_ascii_strcasecmp (value, "none")) { + if (is_any_ip4_address_defined (ifcfg, NULL)) + method = NM_SETTING_IP4_CONFIG_METHOD_MANUAL; + else + method = NM_SETTING_IP4_CONFIG_METHOD_DISABLED; + } else if (!g_ascii_strcasecmp (value, "bootp") || !g_ascii_strcasecmp (value, "dhcp")) { + method = NM_SETTING_IP4_CONFIG_METHOD_AUTO; + } else if (!g_ascii_strcasecmp (value, "static")) { + if (is_any_ip4_address_defined (ifcfg, NULL)) + method = NM_SETTING_IP4_CONFIG_METHOD_MANUAL; + else + method = NM_SETTING_IP4_CONFIG_METHOD_DISABLED; + } else if (!g_ascii_strcasecmp (value, "autoip")) { + method = NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL; + } else if (!g_ascii_strcasecmp (value, "shared")) { + int idx; + + g_free (value); + g_object_set (s_ip4, + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_SHARED, + NM_SETTING_IP_CONFIG_NEVER_DEFAULT, never_default, + NULL); + /* 1 IP address is allowed for shared connections. Read it. */ + if (is_any_ip4_address_defined (ifcfg, &idx)) { + NMIPAddress *addr = NULL; + + if (!read_full_ip4_address (ifcfg, idx, NULL, &addr, NULL, error)) + goto done; + if (!read_ip4_address (ifcfg, "GATEWAY", &gateway, error)) + goto done; + (void) nm_setting_ip_config_add_address (s_ip4, addr); + nm_ip_address_unref (addr); + if (never_default) + PARSE_WARNING ("GATEWAY will be ignored when DEFROUTE is disabled"); + g_object_set (s_ip4, NM_SETTING_IP_CONFIG_GATEWAY, gateway, NULL); + } + return NM_SETTING (s_ip4); + } else { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Unknown BOOTPROTO '%s'", value); + g_free (value); + goto done; + } + g_free (value); + + g_object_set (s_ip4, + NM_SETTING_IP_CONFIG_METHOD, method, + NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS, !svGetValueBoolean (ifcfg, "PEERDNS", TRUE), + NM_SETTING_IP_CONFIG_IGNORE_AUTO_ROUTES, !svGetValueBoolean (ifcfg, "PEERROUTES", TRUE), + NM_SETTING_IP_CONFIG_NEVER_DEFAULT, never_default, + NM_SETTING_IP_CONFIG_MAY_FAIL, !svGetValueBoolean (ifcfg, "IPV4_FAILURE_FATAL", FALSE), + NM_SETTING_IP_CONFIG_ROUTE_METRIC, svGetValueInt64 (ifcfg, "IPV4_ROUTE_METRIC", 10, + -1, G_MAXUINT32, -1), + NULL); + + if (strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_DISABLED) == 0) + return NM_SETTING (s_ip4); + + /* Handle DHCP settings */ + value = svGetValueString (ifcfg, "DHCP_HOSTNAME"); + if (value && *value) + g_object_set (s_ip4, NM_SETTING_IP_CONFIG_DHCP_HOSTNAME, value, NULL); + g_free (value); + + value = svGetValueString (ifcfg, "DHCP_FQDN"); + if (value && *value) { + g_object_set (s_ip4, + NM_SETTING_IP_CONFIG_DHCP_HOSTNAME, NULL, + NM_SETTING_IP4_CONFIG_DHCP_FQDN, value, + NULL); + } + g_free (value); + + g_object_set (s_ip4, + NM_SETTING_IP_CONFIG_DHCP_SEND_HOSTNAME, svGetValueBoolean (ifcfg, "DHCP_SEND_HOSTNAME", TRUE), + NM_SETTING_IP_CONFIG_DHCP_TIMEOUT, svGetValueInt64 (ifcfg, "IPV4_DHCP_TIMEOUT", 10, 0, G_MAXINT32, 0), + NULL); + + value = svGetValueString (ifcfg, "DHCP_CLIENT_ID"); + if (value && strlen (value)) + g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_DHCP_CLIENT_ID, value, NULL); + g_free (value); + + /* Read static IP addresses. + * Read them even for AUTO method - in this case the addresses are + * added to the automatic ones. Note that this is not currently supported by + * the legacy 'network' service (ifup-eth). + */ + for (i = -1; i < 256; i++) { + NMIPAddress *addr = NULL; + + /* gateway will only be set if still unset. Hence, we don't leak gateway + * here by calling read_full_ip4_address() repeatedly */ + if (!read_full_ip4_address (ifcfg, i, NULL, &addr, &gateway, error)) + goto done; + + if (!addr) { + /* The first mandatory variable is 2-indexed (IPADDR2) + * Variables IPADDR, IPADDR0 and IPADDR1 are optional */ + if (i > 1) + break; + continue; + } + + if (!nm_setting_ip_config_add_address (s_ip4, addr)) + PARSE_WARNING ("duplicate IP4 address"); + nm_ip_address_unref (addr); + } + + /* Gateway */ + if (!gateway) { + network_ifcfg = svOpenFile (network_file, NULL); + if (network_ifcfg) { + gboolean read_success; + + read_success = read_ip4_address (network_ifcfg, "GATEWAY", &gateway, error); + svCloseFile (network_ifcfg); + if (!read_success) + goto done; + + if (gateway && nm_setting_ip_config_get_num_addresses (s_ip4) == 0) { + gs_free char *f = g_path_get_basename (svFileGetName (ifcfg)); + PARSE_WARNING ("ignoring GATEWAY (/etc/sysconfig/network) for %s " + "because the connection has no static addresses", f); + g_clear_pointer (&gateway, g_free); + } + } + } + g_object_set (s_ip4, NM_SETTING_IP_CONFIG_GATEWAY, gateway, NULL); + + if (gateway && never_default) + PARSE_WARNING ("GATEWAY will be ignored when DEFROUTE is disabled"); + + /* DNS servers + * Pick up just IPv4 addresses (IPv6 addresses are taken by make_ip6_setting()) + */ + for (i = 1; i <= 10; i++) { + char *tag; + + tag = g_strdup_printf ("DNS%u", i); + value = svGetValueString (ifcfg, tag); + if (value) { + if (nm_utils_ipaddr_valid (AF_INET, value)) { + if (!nm_setting_ip_config_add_dns (s_ip4, value)) + PARSE_WARNING ("duplicate DNS server %s", tag); + } else if (nm_utils_ipaddr_valid (AF_INET6, value)) { + /* Ignore IPv6 addresses */ + } else { + PARSE_WARNING ("invalid DNS server address %s", value); + g_free (tag); + g_free (value); + goto done; + } + + g_free (value); + } + + g_free (tag); + } + + /* DNS searches */ + value = svGetValueString (ifcfg, "DOMAIN"); + if (value) { + char **searches = NULL; + + searches = g_strsplit (value, " ", 0); + if (searches) { + char **item; + for (item = searches; *item; item++) { + if (strlen (*item)) { + if (!nm_setting_ip_config_add_dns_search (s_ip4, *item)) + PARSE_WARNING ("duplicate DNS domain '%s'", *item); + } + } + g_strfreev (searches); + } + g_free (value); + } + + /* DNS options */ + parse_dns_options (s_ip4, svGetValue (ifcfg, "RES_OPTIONS", &value)); + parse_dns_options (s_ip4, dns_options); + g_free (value); + + /* DNS priority */ + priority = svGetValueInt64 (ifcfg, "IPV4_DNS_PRIORITY", 10, G_MININT32, G_MAXINT32, 0); + g_object_set (s_ip4, + NM_SETTING_IP_CONFIG_DNS_PRIORITY, + priority, + NULL); + + /* Static routes - route- file */ + route_path = utils_get_route_path (svFileGetName (ifcfg)); + + if (utils_has_complex_routes (route_path)) { + PARSE_WARNING ("'rule-' or 'rule6-' file is present; you will need to use a dispatcher script to apply these routes"); + } else if (utils_has_route_file_new_syntax (route_path)) { + /* Parse route file in new syntax */ + route_ifcfg = utils_get_route_ifcfg (svFileGetName (ifcfg), FALSE); + if (route_ifcfg) { + for (i = 0; i < 256; i++) { + NMIPRoute *route = NULL; + + if (!read_one_ip4_route (route_ifcfg, i, &route, error)) { + svCloseFile (route_ifcfg); + goto done; + } + + if (!route) + break; + + if (!nm_setting_ip_config_add_route (s_ip4, route)) + PARSE_WARNING ("duplicate IP4 route"); + nm_ip_route_unref (route); + } + svCloseFile (route_ifcfg); + } + } else { + if (!read_route_file_legacy (route_path, s_ip4, error)) + goto done; + } + g_free (route_path); + + /* Legacy value NM used for a while but is incorrect (rh #459370) */ + if (!nm_setting_ip_config_get_num_dns_searches (s_ip4)) { + value = svGetValueString (ifcfg, "SEARCH"); + if (value) { + char **searches = NULL; + + searches = g_strsplit (value, " ", 0); + if (searches) { + char **item; + for (item = searches; *item; item++) { + if (strlen (*item)) { + if (!nm_setting_ip_config_add_dns_search (s_ip4, *item)) + PARSE_WARNING ("duplicate DNS search '%s'", *item); + } + } + g_strfreev (searches); + } + g_free (value); + } + } + + timeout = svGetValueInt64 (ifcfg, "ARPING_WAIT", 10, -1, + NM_SETTING_IP_CONFIG_DAD_TIMEOUT_MAX / 1000, -1); + g_object_set (s_ip4, NM_SETTING_IP_CONFIG_DAD_TIMEOUT, + (gint) (timeout <= 0 ? timeout : timeout * 1000), NULL); + + return NM_SETTING (s_ip4); + +done: + g_free (route_path); + g_object_unref (s_ip4); + return NULL; +} + +static void +read_aliases (NMSettingIPConfig *s_ip4, const char *filename) +{ + GDir *dir; + char *dirname, *base; + shvarFile *parsed; + NMIPAddress *base_addr = NULL; + GError *err = NULL; + + g_return_if_fail (s_ip4 != NULL); + g_return_if_fail (filename != NULL); + + if (nm_setting_ip_config_get_num_addresses (s_ip4) > 0) + base_addr = nm_setting_ip_config_get_address (s_ip4, 0); + + dirname = g_path_get_dirname (filename); + g_return_if_fail (dirname != NULL); + base = g_path_get_basename (filename); + g_return_if_fail (base != NULL); + + dir = g_dir_open (dirname, 0, &err); + if (dir) { + const char *item; + NMIPAddress *addr; + gboolean ok; + + while ((item = g_dir_read_name (dir))) { + char *full_path, *device; + const char *p; + + if (!utils_is_ifcfg_alias_file (item, base)) + continue; + + full_path = g_build_filename (dirname, item, NULL); + + p = strchr (item, ':'); + g_assert (p != NULL); /* we know this is true from utils_is_ifcfg_alias_file() */ + for (p++; *p; p++) { + if (!g_ascii_isalnum (*p) && *p != '_') + break; + } + if (*p) { + PARSE_WARNING ("ignoring alias file '%s' with invalid name", full_path); + g_free (full_path); + continue; + } + + parsed = svOpenFile (full_path, &err); + if (!parsed) { + PARSE_WARNING ("couldn't parse alias file '%s': %s", full_path, err->message); + g_free (full_path); + g_clear_error (&err); + continue; + } + + device = svGetValueString (parsed, "DEVICE"); + if (!device) { + PARSE_WARNING ("alias file '%s' has no DEVICE", full_path); + svCloseFile (parsed); + g_free (full_path); + continue; + } + /* We know that item starts with IFCFG_TAG from utils_is_ifcfg_alias_file() */ + if (strcmp (device, item + strlen (IFCFG_TAG)) != 0) { + PARSE_WARNING ("alias file '%s' has invalid DEVICE (%s) for filename", + full_path, device); + g_free (device); + svCloseFile (parsed); + g_free (full_path); + continue; + } + + addr = NULL; + ok = read_full_ip4_address (parsed, -1, base_addr, &addr, NULL, &err); + svCloseFile (parsed); + if (ok) { + nm_ip_address_set_attribute (addr, "label", g_variant_new_string (device)); + if (!nm_setting_ip_config_add_address (s_ip4, addr)) + PARSE_WARNING ("duplicate IP4 address in alias file %s", item); + } else { + PARSE_WARNING ("error reading IP4 address from alias file '%s': %s", + full_path, err ? err->message : "no address"); + g_clear_error (&err); + } + nm_ip_address_unref (addr); + + g_free (device); + g_free (full_path); + } + + g_dir_close (dir); + } else { + PARSE_WARNING ("can not read directory '%s': %s", dirname, err->message); + g_error_free (err); + } + + g_free (base); + g_free (dirname); +} + +static NMSetting * +make_ip6_setting (shvarFile *ifcfg, + const char *network_file, + GError **error) +{ + NMSettingIPConfig *s_ip6 = NULL; + char *value = NULL; + char *str_value; + char *route6_path = NULL; + gs_free char *dns_options_free = NULL; + const char *dns_options = NULL; + gboolean ipv6init, ipv6forwarding, dhcp6 = FALSE; + char *method = NM_SETTING_IP6_CONFIG_METHOD_MANUAL; + char *ipv6addr, *ipv6addr_secondaries; + char **list = NULL, **iter; + guint32 i; + gint priority; + shvarFile *network_ifcfg; + gboolean never_default = FALSE; + gboolean ip6_privacy = FALSE, ip6_privacy_prefer_public_ip; + NMSettingIP6ConfigPrivacy ip6_privacy_val; + NMSettingIP6ConfigAddrGenMode addr_gen_mode; + + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new (); + + /* First check if IPV6_DEFROUTE is set for this device; IPV6_DEFROUTE has the + * opposite meaning from never-default. The default if IPV6_DEFROUTE is not + * specified is IPV6_DEFROUTE=yes which means that this connection can be used + * as a default route + */ + never_default = !svGetValueBoolean (ifcfg, "IPV6_DEFROUTE", TRUE); + + /* Then check if IPV6_DEFAULTGW or IPV6_DEFAULTDEV is specified; + * they are global and override IPV6_DEFROUTE + * When both are set, the device specified in IPV6_DEFAULTGW takes preference. + */ + network_ifcfg = svOpenFile (network_file, NULL); + if (network_ifcfg) { + char *ipv6_defaultgw, *ipv6_defaultdev; + char *default_dev = NULL; + + /* Get the connection ifcfg device name and the global default route device */ + value = svGetValueString (ifcfg, "DEVICE"); + ipv6_defaultgw = svGetValueString (network_ifcfg, "IPV6_DEFAULTGW"); + ipv6_defaultdev = svGetValueString (network_ifcfg, "IPV6_DEFAULTDEV"); + dns_options = svGetValue (network_ifcfg, "RES_OPTIONS", &dns_options_free); + + if (ipv6_defaultgw) { + default_dev = strchr (ipv6_defaultgw, '%'); + if (default_dev) + default_dev++; + } + if (!default_dev) + default_dev = ipv6_defaultdev; + + /* If there was a global default route device specified, then only connections + * for that device can be the default connection. + */ + if (default_dev && value) + never_default = !!strcmp (value, default_dev); + + g_free (ipv6_defaultgw); + g_free (ipv6_defaultdev); + g_free (value); + svCloseFile (network_ifcfg); + } + + /* Find out method property */ + /* Is IPV6 enabled? Set method to "ignored", when not enabled */ + str_value = svGetValueString (ifcfg, "IPV6INIT"); + ipv6init = svGetValueBoolean (ifcfg, "IPV6INIT", FALSE); + if (!str_value) { + network_ifcfg = svOpenFile (network_file, NULL); + if (network_ifcfg) { + ipv6init = svGetValueBoolean (network_ifcfg, "IPV6INIT", FALSE); + svCloseFile (network_ifcfg); + } + } + g_free (str_value); + + if (!ipv6init) + method = NM_SETTING_IP6_CONFIG_METHOD_IGNORE; /* IPv6 is disabled */ + else { + ipv6forwarding = svGetValueBoolean (ifcfg, "IPV6FORWARDING", FALSE); + str_value = svGetValueString (ifcfg, "IPV6_AUTOCONF"); + dhcp6 = svGetValueBoolean (ifcfg, "DHCPV6C", FALSE); + + if (!g_strcmp0 (str_value, "shared")) + method = NM_SETTING_IP6_CONFIG_METHOD_SHARED; + else if (svParseBoolean (str_value, !ipv6forwarding)) + method = NM_SETTING_IP6_CONFIG_METHOD_AUTO; + else if (dhcp6) + method = NM_SETTING_IP6_CONFIG_METHOD_DHCP; + else { + /* IPV6_AUTOCONF=no and no IPv6 address -> method 'link-local' */ + g_free (str_value); + str_value = svGetValueString (ifcfg, "IPV6ADDR"); + if (!str_value) + str_value = svGetValueString (ifcfg, "IPV6ADDR_SECONDARIES"); + + if (!str_value) + method = NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL; + } + g_free (str_value); + } + /* TODO - handle other methods */ + + /* Read IPv6 Privacy Extensions configuration */ + str_value = svGetValueString (ifcfg, "IPV6_PRIVACY"); + if (str_value) { + ip6_privacy = svParseBoolean (str_value, FALSE); + if (!ip6_privacy) + ip6_privacy = (g_strcmp0 (str_value, "rfc4941") == 0) || + (g_strcmp0 (str_value, "rfc3041") == 0); + } + ip6_privacy_prefer_public_ip = svGetValueBoolean (ifcfg, "IPV6_PRIVACY_PREFER_PUBLIC_IP", FALSE); + ip6_privacy_val = str_value ? + (ip6_privacy ? + (ip6_privacy_prefer_public_ip ? NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_PUBLIC_ADDR : NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_TEMP_ADDR) : + NM_SETTING_IP6_CONFIG_PRIVACY_DISABLED) : + NM_SETTING_IP6_CONFIG_PRIVACY_UNKNOWN; + g_free (str_value); + + g_object_set (s_ip6, + NM_SETTING_IP_CONFIG_METHOD, method, + NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS, !svGetValueBoolean (ifcfg, "IPV6_PEERDNS", TRUE), + NM_SETTING_IP_CONFIG_IGNORE_AUTO_ROUTES, !svGetValueBoolean (ifcfg, "IPV6_PEERROUTES", TRUE), + NM_SETTING_IP_CONFIG_NEVER_DEFAULT, never_default, + NM_SETTING_IP_CONFIG_MAY_FAIL, !svGetValueBoolean (ifcfg, "IPV6_FAILURE_FATAL", FALSE), + NM_SETTING_IP_CONFIG_ROUTE_METRIC, svGetValueInt64 (ifcfg, "IPV6_ROUTE_METRIC", 10, + -1, G_MAXUINT32, -1), + NM_SETTING_IP6_CONFIG_IP6_PRIVACY, ip6_privacy_val, + NULL); + + /* Don't bother to read IP, DNS and routes when IPv6 is disabled */ + if (strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_IGNORE) == 0) + return NM_SETTING (s_ip6); + + value = svGetValueString (ifcfg, "DHCPV6_HOSTNAME"); + /* Use DHCP_HOSTNAME as fallback if it is in FQDN format and ipv6.method is + * auto or dhcp: this is required to support old ifcfg files + */ + if (!value && ( !strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_AUTO) + || !strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_DHCP))) { + value = svGetValueString (ifcfg, "DHCP_HOSTNAME"); + if (value && !strchr (value, '.')) + g_clear_pointer (&value, g_free); + } + if (value) + g_object_set (s_ip6, NM_SETTING_IP_CONFIG_DHCP_HOSTNAME, value, NULL); + g_free (value); + + g_object_set (s_ip6, NM_SETTING_IP_CONFIG_DHCP_SEND_HOSTNAME, + svGetValueBoolean (ifcfg, "DHCPV6_SEND_HOSTNAME", TRUE), NULL); + + /* Read static IP addresses. + * Read them even for AUTO and DHCP methods - in this case the addresses are + * added to the automatic ones. Note that this is not currently supported by + * the legacy 'network' service (ifup-eth). + */ + ipv6addr = svGetValueString (ifcfg, "IPV6ADDR"); + ipv6addr_secondaries = svGetValueString (ifcfg, "IPV6ADDR_SECONDARIES"); + + value = g_strjoin (ipv6addr && ipv6addr_secondaries ? " " : NULL, + ipv6addr ? ipv6addr : "", + ipv6addr_secondaries ? ipv6addr_secondaries : "", + NULL); + g_free (ipv6addr); + g_free (ipv6addr_secondaries); + + list = g_strsplit_set (value, " ", 0); + g_free (value); + for (iter = list, i = 0; iter && *iter; iter++, i++) { + NMIPAddress *addr = NULL; + + if (!parse_full_ip6_address (ifcfg, *iter, i, &addr, error)) { + g_strfreev (list); + goto error; + } + + if (!nm_setting_ip_config_add_address (s_ip6, addr)) + PARSE_WARNING ("duplicate IP6 address"); + nm_ip_address_unref (addr); + } + g_strfreev (list); + + /* Gateway */ + if (nm_setting_ip_config_get_num_addresses (s_ip6)) { + value = svGetValueString (ifcfg, "IPV6_DEFAULTGW"); + if (!value) { + /* If no gateway in the ifcfg, try global /etc/sysconfig/network instead */ + network_ifcfg = svOpenFile (network_file, NULL); + if (network_ifcfg) { + value = svGetValueString (network_ifcfg, "IPV6_DEFAULTGW"); + svCloseFile (network_ifcfg); + } + } + if (value) { + char *ptr; + if ((ptr = strchr (value, '%')) != NULL) + *ptr = '\0'; /* remove %interface prefix if present */ + if (!nm_utils_ipaddr_valid (AF_INET6, value)) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Invalid IP6 address '%s'", value); + g_free (value); + goto error; + } + + g_object_set (s_ip6, NM_SETTING_IP_CONFIG_GATEWAY, value, NULL); + g_free (value); + } + } + + /* IPv6 addressing mode configuration */ + str_value = svGetValueString (ifcfg, "IPV6_ADDR_GEN_MODE"); + if (str_value) { + if (nm_utils_enum_from_str (nm_setting_ip6_config_addr_gen_mode_get_type (), str_value, + (int *) &addr_gen_mode, NULL)) + g_object_set (s_ip6, NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE, addr_gen_mode, NULL); + else + PARSE_WARNING ("Invalid IPV6_ADDR_GEN_MODE"); + g_free (str_value); + } else { + g_object_set (s_ip6, + NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE, + NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE_EUI64, + NULL); + } + + /* IPv6 tokenized interface identifier */ + str_value = svGetValueString (ifcfg, "IPV6_TOKEN"); + if (str_value) { + g_object_set (s_ip6, NM_SETTING_IP6_CONFIG_TOKEN, str_value, NULL); + g_free (str_value); + } + + /* DNS servers + * Pick up just IPv6 addresses (IPv4 addresses are taken by make_ip4_setting()) + */ + for (i = 1; i <= 10; i++) { + char *tag; + + tag = g_strdup_printf ("DNS%u", i); + value = svGetValueString (ifcfg, tag); + if (!value) { + g_free (tag); + break; /* all done */ + } + + if (nm_utils_ipaddr_valid (AF_INET6, value)) { + if (!nm_setting_ip_config_add_dns (s_ip6, value)) + PARSE_WARNING ("duplicate DNS server %s", tag); + } else if (nm_utils_ipaddr_valid (AF_INET, value)) { + /* Ignore IPv4 addresses */ + } else { + PARSE_WARNING ("invalid DNS server address %s", value); + g_free (tag); + g_free (value); + goto error; + } + + g_free (tag); + g_free (value); + } + + /* DNS searches ('DOMAIN' key) are read by make_ip4_setting() and included in NMSettingIPConfig */ + + if (!utils_has_complex_routes (svFileGetName (ifcfg))) { + /* Read static routes from route6- file */ + route6_path = utils_get_route6_path (svFileGetName (ifcfg)); + if (!read_route6_file (route6_path, s_ip6, error)) + goto error; + + g_free (route6_path); + } + + /* DNS options */ + parse_dns_options (s_ip6, svGetValue (ifcfg, "RES_OPTIONS", &value)); + parse_dns_options (s_ip6, dns_options); + g_free (value); + + /* DNS priority */ + priority = svGetValueInt64 (ifcfg, "IPV6_DNS_PRIORITY", 10, G_MININT32, G_MAXINT32, 0); + g_object_set (s_ip6, + NM_SETTING_IP_CONFIG_DNS_PRIORITY, + priority, + NULL); + + return NM_SETTING (s_ip6); + +error: + g_free (route6_path); + g_object_unref (s_ip6); + return NULL; +} + +static void +check_if_bond_slave (shvarFile *ifcfg, + NMSettingConnection *s_con) +{ + char *value; + + value = svGetValueString (ifcfg, "MASTER_UUID"); + if (!value) + value = svGetValueString (ifcfg, "MASTER"); + + if (value) { + g_object_set (s_con, NM_SETTING_CONNECTION_MASTER, value, NULL); + g_object_set (s_con, + NM_SETTING_CONNECTION_SLAVE_TYPE, NM_SETTING_BOND_SETTING_NAME, + NULL); + g_free (value); + } + + /* We should be checking for SLAVE=yes as well, but NM used to not set that, + * so for backward-compatibility, we don't check. + */ +} + +static gboolean +check_if_team_slave (shvarFile *ifcfg, + NMSettingConnection *s_con) +{ + gs_free char *value = NULL; + + value = svGetValueString (ifcfg, "TEAM_MASTER_UUID"); + if (!value) + value = svGetValueString (ifcfg, "TEAM_MASTER"); + if (!value) + return FALSE; + + g_object_set (s_con, NM_SETTING_CONNECTION_MASTER, value, NULL); + g_object_set (s_con, NM_SETTING_CONNECTION_SLAVE_TYPE, NM_SETTING_TEAM_SETTING_NAME, NULL); + return TRUE; +} + +static void +check_if_slave (shvarFile *ifcfg, + NMSettingConnection *s_con) +{ + g_return_if_fail (NM_IS_SETTING_CONNECTION (s_con)); + + if (check_if_team_slave (ifcfg, s_con)) + return; + check_if_bond_slave (ifcfg, s_con); +} + +typedef struct { + const char *enable_key; + const char *advertise_key; + const char *willing_key; + const char *flags_prop; +} DcbFlagsProperty; + +enum { + DCB_APP_FCOE_FLAGS = 0, + DCB_APP_ISCSI_FLAGS = 1, + DCB_APP_FIP_FLAGS = 2, + DCB_PFC_FLAGS = 3, + DCB_PG_FLAGS = 4, +}; + +static DcbFlagsProperty dcb_flags_props[] = { + { KEY_DCB_APP_FCOE_ENABLE, KEY_DCB_APP_FCOE_ADVERTISE, KEY_DCB_APP_FCOE_WILLING, NM_SETTING_DCB_APP_FCOE_FLAGS }, + { KEY_DCB_APP_ISCSI_ENABLE, KEY_DCB_APP_ISCSI_ADVERTISE, KEY_DCB_APP_ISCSI_WILLING, NM_SETTING_DCB_APP_ISCSI_FLAGS }, + { KEY_DCB_APP_FIP_ENABLE, KEY_DCB_APP_FIP_ADVERTISE, KEY_DCB_APP_FIP_WILLING, NM_SETTING_DCB_APP_FIP_FLAGS }, + { KEY_DCB_PFC_ENABLE, KEY_DCB_PFC_ADVERTISE, KEY_DCB_PFC_WILLING, NM_SETTING_DCB_PRIORITY_FLOW_CONTROL_FLAGS }, + { KEY_DCB_PG_ENABLE, KEY_DCB_PG_ADVERTISE, KEY_DCB_PG_WILLING, NM_SETTING_DCB_PRIORITY_GROUP_FLAGS }, + { NULL }, +}; + +static NMSettingDcbFlags +read_dcb_flags (shvarFile *ifcfg, DcbFlagsProperty *property) +{ + NMSettingDcbFlags flags = NM_SETTING_DCB_FLAG_NONE; + + if (svGetValueBoolean (ifcfg, property->enable_key, FALSE)) + flags |= NM_SETTING_DCB_FLAG_ENABLE; + if (svGetValueBoolean (ifcfg, property->advertise_key, FALSE)) + flags |= NM_SETTING_DCB_FLAG_ADVERTISE; + if (svGetValueBoolean (ifcfg, property->willing_key, FALSE)) + flags |= NM_SETTING_DCB_FLAG_WILLING; + + return flags; +} + +static gboolean +read_dcb_app (shvarFile *ifcfg, + NMSettingDcb *s_dcb, + const char *app, + DcbFlagsProperty *flags_prop, + const char *priority_prop, + GError **error) +{ + NMSettingDcbFlags flags = NM_SETTING_DCB_FLAG_NONE; + char *tmp, *val; + gboolean success = TRUE; + int priority = -1; + + flags = read_dcb_flags (ifcfg, flags_prop); + + /* Priority */ + tmp = g_strdup_printf ("DCB_APP_%s_PRIORITY", app); + val = svGetValueString (ifcfg, tmp); + if (val) { + priority = _nm_utils_ascii_str_to_int64 (val, 0, 0, 7, -1); + if (priority < 0) { + success = FALSE; + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Invalid %s value '%s' (expected 0 - 7)", + tmp, val); + } + g_free (val); + + if (!(flags & NM_SETTING_DCB_FLAG_ENABLE)) + PARSE_WARNING ("ignoring DCB %s priority; app not enabled", app); + } + g_free (tmp); + + if (success) { + g_object_set (G_OBJECT (s_dcb), + flags_prop->flags_prop, flags, + priority_prop, (guint) priority, + NULL); + } + + return success; +} + +typedef void (*DcbSetBoolFunc) (NMSettingDcb *, guint, gboolean); + +static gboolean +read_dcb_bool_array (shvarFile *ifcfg, + NMSettingDcb *s_dcb, + NMSettingDcbFlags flags, + const char *prop, + const char *desc, + DcbSetBoolFunc set_func, + GError **error) +{ + char *val; + gboolean success = FALSE; + guint i; + + val = svGetValueString (ifcfg, prop); + if (!val) + return TRUE; + + if (!(flags & NM_SETTING_DCB_FLAG_ENABLE)) { + PARSE_WARNING ("ignoring %s; %s is not enabled", prop, desc); + success = TRUE; + goto out; + } + + val = g_strstrip (val); + if (strlen (val) != 8) { + PARSE_WARNING ("%s value '%s' must be 8 characters long", prop, val); + g_set_error_literal (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "boolean array must be 8 characters"); + goto out; + } + + /* All characters must be either 0 or 1 */ + for (i = 0; i < 8; i++) { + if (val[i] != '0' && val[i] != '1') { + PARSE_WARNING ("invalid %s value '%s': not all 0s and 1s", prop, val); + g_set_error_literal (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "invalid boolean digit"); + goto out; + } + set_func (s_dcb, i, (val[i] == '1')); + } + success = TRUE; + +out: + g_free (val); + return success; +} + +typedef void (*DcbSetUintFunc) (NMSettingDcb *, guint, guint); + +static gboolean +read_dcb_uint_array (shvarFile *ifcfg, + NMSettingDcb *s_dcb, + NMSettingDcbFlags flags, + const char *prop, + const char *desc, + gboolean f_allowed, + DcbSetUintFunc set_func, + GError **error) +{ + char *val; + gboolean success = FALSE; + guint i; + + val = svGetValueString (ifcfg, prop); + if (!val) + return TRUE; + + if (!(flags & NM_SETTING_DCB_FLAG_ENABLE)) { + PARSE_WARNING ("ignoring %s; %s is not enabled", prop, desc); + success = TRUE; + goto out; + } + + val = g_strstrip (val); + if (strlen (val) != 8) { + PARSE_WARNING ("%s value '%s' must be 8 characters long", prop, val); + g_set_error_literal (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "uint array must be 8 characters"); + goto out; + } + + /* All characters must be either 0 - 7 or (optionally) f */ + for (i = 0; i < 8; i++) { + if (val[i] >= '0' && val[i] <= '7') + set_func (s_dcb, i, val[i] - '0'); + else if (f_allowed && (val[i] == 'f' || val[i] == 'F')) + set_func (s_dcb, i, 15); + else { + PARSE_WARNING ("invalid %s value '%s': not 0 - 7%s", + prop, val, f_allowed ? " or 'f'" : ""); + g_set_error_literal (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "invalid uint digit"); + goto out; + } + } + success = TRUE; + +out: + g_free (val); + return success; +} + +static gboolean +read_dcb_percent_array (shvarFile *ifcfg, + NMSettingDcb *s_dcb, + NMSettingDcbFlags flags, + const char *prop, + const char *desc, + gboolean sum_pct, + DcbSetUintFunc set_func, + GError **error) +{ + char *val; + gboolean success = FALSE; + char **split = NULL, **iter; + guint i, sum = 0; + + val = svGetValueString (ifcfg, prop); + if (!val) + return TRUE; + + if (!(flags & NM_SETTING_DCB_FLAG_ENABLE)) { + PARSE_WARNING ("ignoring %s; %s is not enabled", prop, desc); + success = TRUE; + goto out; + } + + val = g_strstrip (val); + split = g_strsplit_set (val, ",", 0); + if (!split || (g_strv_length (split) != 8)) { + PARSE_WARNING ("invalid %s percentage list value '%s'", prop, val); + g_set_error_literal (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "percent array must be 8 elements"); + goto out; + } + + for (iter = split, i = 0; iter && *iter; iter++, i++) { + int tmp; + + tmp = _nm_utils_ascii_str_to_int64 (*iter, 0, 0, 100, -1); + if (tmp < 0) { + PARSE_WARNING ("invalid %s percentage value '%s'", prop, *iter); + g_set_error_literal (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "invalid percent element"); + goto out; + } + set_func (s_dcb, i, (guint) tmp); + sum += (guint) tmp; + } + + if (sum_pct && (sum != 100)) { + PARSE_WARNING ("%s percentages do not equal 100%%", prop); + g_set_error_literal (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "invalid percentage sum"); + goto out; + } + + success = TRUE; + +out: + if (split) + g_strfreev (split); + g_free (val); + return success; +} + +static gboolean +make_dcb_setting (shvarFile *ifcfg, + const char *network_file, + NMSetting **out_setting, + GError **error) +{ + NMSettingDcb *s_dcb = NULL; + gboolean dcb_on; + NMSettingDcbFlags flags = NM_SETTING_DCB_FLAG_NONE; + char *val; + + g_return_val_if_fail (out_setting != NULL, FALSE); + + dcb_on = !!svGetValueBoolean (ifcfg, "DCB", FALSE); + if (!dcb_on) + return TRUE; + + s_dcb = (NMSettingDcb *) nm_setting_dcb_new (); + g_assert (s_dcb); + + /* FCOE */ + if (!read_dcb_app (ifcfg, s_dcb, "FCOE", + &dcb_flags_props[DCB_APP_FCOE_FLAGS], + NM_SETTING_DCB_APP_FCOE_PRIORITY, + error)) { + g_object_unref (s_dcb); + return FALSE; + } + if (nm_setting_dcb_get_app_fcoe_flags (s_dcb) & NM_SETTING_DCB_FLAG_ENABLE) { + val = svGetValueString (ifcfg, KEY_DCB_APP_FCOE_MODE); + if (val) { + if (strcmp (val, NM_SETTING_DCB_FCOE_MODE_FABRIC) == 0 || + strcmp (val, NM_SETTING_DCB_FCOE_MODE_VN2VN) == 0) + g_object_set (G_OBJECT (s_dcb), NM_SETTING_DCB_APP_FCOE_MODE, val, NULL); + else { + PARSE_WARNING ("invalid FCoE mode '%s'", val); + g_set_error_literal (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "invalid FCoE mode"); + g_free (val); + g_object_unref (s_dcb); + return FALSE; + } + g_free (val); + } + } + + /* iSCSI */ + if (!read_dcb_app (ifcfg, s_dcb, "ISCSI", + &dcb_flags_props[DCB_APP_ISCSI_FLAGS], + NM_SETTING_DCB_APP_ISCSI_PRIORITY, + error)) { + g_object_unref (s_dcb); + return FALSE; + } + + /* FIP */ + if (!read_dcb_app (ifcfg, s_dcb, "FIP", + &dcb_flags_props[DCB_APP_FIP_FLAGS], + NM_SETTING_DCB_APP_FIP_PRIORITY, + error)) { + g_object_unref (s_dcb); + return FALSE; + } + + /* Priority Flow Control */ + flags = read_dcb_flags (ifcfg, &dcb_flags_props[DCB_PFC_FLAGS]); + g_object_set (G_OBJECT (s_dcb), NM_SETTING_DCB_PRIORITY_FLOW_CONTROL_FLAGS, flags, NULL); + + if (!read_dcb_bool_array (ifcfg, + s_dcb, + flags, + KEY_DCB_PFC_UP, + "PFC", + nm_setting_dcb_set_priority_flow_control, + error)) { + g_object_unref (s_dcb); + return FALSE; + } + + /* Priority Groups */ + flags = read_dcb_flags (ifcfg, &dcb_flags_props[DCB_PG_FLAGS]); + g_object_set (G_OBJECT (s_dcb), NM_SETTING_DCB_PRIORITY_GROUP_FLAGS, flags, NULL); + + if (!read_dcb_uint_array (ifcfg, + s_dcb, + flags, + KEY_DCB_PG_ID, + "PGID", + TRUE, + nm_setting_dcb_set_priority_group_id, + error)) { + g_object_unref (s_dcb); + return FALSE; + } + + /* Group bandwidth */ + if (!read_dcb_percent_array (ifcfg, + s_dcb, + flags, + KEY_DCB_PG_PCT, + "PGPCT", + TRUE, + nm_setting_dcb_set_priority_group_bandwidth, + error)) { + g_object_unref (s_dcb); + return FALSE; + } + + /* Priority bandwidth */ + if (!read_dcb_percent_array (ifcfg, + s_dcb, + flags, + KEY_DCB_PG_UPPCT, + "UPPCT", + FALSE, + nm_setting_dcb_set_priority_bandwidth, + error)) { + g_object_unref (s_dcb); + return FALSE; + } + + /* Strict Bandwidth */ + if (!read_dcb_bool_array (ifcfg, + s_dcb, + flags, + KEY_DCB_PG_STRICT, + "STRICT", + nm_setting_dcb_set_priority_strict_bandwidth, + error)) { + g_object_unref (s_dcb); + return FALSE; + } + + if (!read_dcb_uint_array (ifcfg, + s_dcb, + flags, + KEY_DCB_PG_UP2TC, + "UP2TC", + FALSE, + nm_setting_dcb_set_priority_traffic_class, + error)) { + g_object_unref (s_dcb); + return FALSE; + } + + *out_setting = NM_SETTING (s_dcb); + return TRUE; +} + +static gboolean +add_one_wep_key (shvarFile *ifcfg, + const char *shvar_key, + guint8 key_idx, + gboolean passphrase, + NMSettingWirelessSecurity *s_wsec, + GError **error) +{ + char *key = NULL; + char *value = NULL; + gboolean success = FALSE; + + g_return_val_if_fail (ifcfg != NULL, FALSE); + g_return_val_if_fail (shvar_key != NULL, FALSE); + g_return_val_if_fail (key_idx <= 3, FALSE); + g_return_val_if_fail (s_wsec != NULL, FALSE); + + value = svGetValueString (ifcfg, shvar_key); + if (!value || !strlen (value)) { + g_free (value); + return TRUE; + } + + /* Validate keys */ + if (passphrase) { + if (strlen (value) && strlen (value) < 64) { + key = g_strdup (value); + g_object_set (G_OBJECT (s_wsec), + NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE, + NM_WEP_KEY_TYPE_PASSPHRASE, + NULL); + } + } else { + if (strlen (value) == 10 || strlen (value) == 26) { + /* Hexadecimal WEP key */ + char *p = value; + + while (*p) { + if (!g_ascii_isxdigit (*p)) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Invalid hexadecimal WEP key."); + goto out; + } + p++; + } + key = g_strdup (value); + } else if ( !strncmp (value, "s:", 2) + && (strlen (value) == 7 || strlen (value) == 15)) { + /* ASCII key */ + char *p = value + 2; + + while (*p) { + if (!g_ascii_isprint ((int) (*p))) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Invalid ASCII WEP key."); + goto out; + } + p++; + } + + /* Remove 's:' prefix. + * Don't convert to hex string. wpa_supplicant takes 'wep_key0' option over D-Bus as byte array + * and converts it to hex string itself. Even though we convert hex string keys into a bin string + * before passing to wpa_supplicant, this prevents two unnecessary conversions. And mainly, + * ASCII WEP key doesn't change to HEX WEP key in UI, which could confuse users. + */ + key = g_strdup (value + 2); + } + } + + if (key) { + nm_setting_wireless_security_set_wep_key (s_wsec, key_idx, key); + g_free (key); + success = TRUE; + } else + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Invalid WEP key length."); + +out: + g_free (value); + return success; +} + +static gboolean +read_wep_keys (shvarFile *ifcfg, + guint8 def_idx, + NMSettingWirelessSecurity *s_wsec, + GError **error) +{ + /* Try hex/ascii keys first */ + if (!add_one_wep_key (ifcfg, "KEY1", 0, FALSE, s_wsec, error)) + return FALSE; + if (!add_one_wep_key (ifcfg, "KEY2", 1, FALSE, s_wsec, error)) + return FALSE; + if (!add_one_wep_key (ifcfg, "KEY3", 2, FALSE, s_wsec, error)) + return FALSE; + if (!add_one_wep_key (ifcfg, "KEY4", 3, FALSE, s_wsec, error)) + return FALSE; + if (!add_one_wep_key (ifcfg, "KEY", def_idx, FALSE, s_wsec, error)) + return FALSE; + + /* And then passphrases */ + if (!add_one_wep_key (ifcfg, "KEY_PASSPHRASE1", 0, TRUE, s_wsec, error)) + return FALSE; + if (!add_one_wep_key (ifcfg, "KEY_PASSPHRASE2", 1, TRUE, s_wsec, error)) + return FALSE; + if (!add_one_wep_key (ifcfg, "KEY_PASSPHRASE3", 2, TRUE, s_wsec, error)) + return FALSE; + if (!add_one_wep_key (ifcfg, "KEY_PASSPHRASE4", 3, TRUE, s_wsec, error)) + return FALSE; + + return TRUE; +} + +static NMSettingSecretFlags +read_secret_flags (shvarFile *ifcfg, const char *flags_key) +{ + NMSettingSecretFlags flags = NM_SETTING_SECRET_FLAG_NONE; + char *val; + + g_return_val_if_fail (flags_key != NULL, NM_SETTING_SECRET_FLAG_NONE); + g_return_val_if_fail (flags_key[0] != '\0', NM_SETTING_SECRET_FLAG_NONE); + g_return_val_if_fail (g_str_has_suffix (flags_key, "_FLAGS"), NM_SETTING_SECRET_FLAG_NONE); + + val = svGetValueString (ifcfg, flags_key); + if (val) { + if (strstr (val, SECRET_FLAG_AGENT)) + flags |= NM_SETTING_SECRET_FLAG_AGENT_OWNED; + if (strstr (val, SECRET_FLAG_NOT_SAVED)) + flags |= NM_SETTING_SECRET_FLAG_NOT_SAVED; + if (strstr (val, SECRET_FLAG_NOT_REQUIRED)) + flags |= NM_SETTING_SECRET_FLAG_NOT_REQUIRED; + + g_free (val); + } + return flags; +} + +static NMSetting * +make_wep_setting (shvarFile *ifcfg, + const char *file, + GError **error) +{ + NMSettingWirelessSecurity *s_wsec; + char *value; + shvarFile *keys_ifcfg = NULL; + int default_key_idx = 0; + gboolean has_default_key = FALSE; + NMSettingSecretFlags key_flags; + + s_wsec = NM_SETTING_WIRELESS_SECURITY (nm_setting_wireless_security_new ()); + g_object_set (s_wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "none", NULL); + + value = svGetValueString (ifcfg, "DEFAULTKEY"); + if (value) { + default_key_idx = _nm_utils_ascii_str_to_int64 (value, 0, 1, 4, 0); + if (default_key_idx == 0) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Invalid default WEP key '%s'", value); + g_free (value); + goto error; + } + has_default_key = TRUE; + default_key_idx--; /* convert to [0...3] */ + g_object_set (s_wsec, NM_SETTING_WIRELESS_SECURITY_WEP_TX_KEYIDX, (guint) default_key_idx, NULL); + g_free (value); + } + + /* Read WEP key flags */ + key_flags = read_secret_flags (ifcfg, "WEP_KEY_FLAGS"); + g_object_set (s_wsec, NM_SETTING_WIRELESS_SECURITY_WEP_KEY_FLAGS, key_flags, NULL); + + /* Read keys in the ifcfg file if they are system-owned */ + if (key_flags == NM_SETTING_SECRET_FLAG_NONE) { + if (!read_wep_keys (ifcfg, default_key_idx, s_wsec, error)) + goto error; + + /* Try to get keys from the "shadow" key file */ + keys_ifcfg = utils_get_keys_ifcfg (file, FALSE); + if (keys_ifcfg) { + if (!read_wep_keys (keys_ifcfg, default_key_idx, s_wsec, error)) { + svCloseFile (keys_ifcfg); + goto error; + } + svCloseFile (keys_ifcfg); + g_assert (error == NULL || *error == NULL); + } + } + + value = svGetValueString (ifcfg, "SECURITYMODE"); + if (value) { + char *lcase; + + lcase = g_ascii_strdown (value, -1); + g_free (value); + + if (!strcmp (lcase, "open")) { + g_object_set (s_wsec, NM_SETTING_WIRELESS_SECURITY_AUTH_ALG, "open", NULL); + } else if (!strcmp (lcase, "restricted")) { + g_object_set (s_wsec, NM_SETTING_WIRELESS_SECURITY_AUTH_ALG, "shared", NULL); + } else { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Invalid WEP authentication algorithm '%s'", + lcase); + g_free (lcase); + goto error; + } + g_free (lcase); + } + + /* If no WEP keys were given, and the keys are not agent-owned, and no + * default WEP key index was given, then the connection is unencrypted. + */ + if ( !nm_setting_wireless_security_get_wep_key (s_wsec, 0) + && !nm_setting_wireless_security_get_wep_key (s_wsec, 1) + && !nm_setting_wireless_security_get_wep_key (s_wsec, 2) + && !nm_setting_wireless_security_get_wep_key (s_wsec, 3) + && (has_default_key == FALSE) + && (key_flags == NM_SETTING_SECRET_FLAG_NONE)) { + const char *auth_alg; + + auth_alg = nm_setting_wireless_security_get_auth_alg (s_wsec); + if (auth_alg && !strcmp (auth_alg, "shared")) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "WEP Shared Key authentication is invalid for " + "unencrypted connections."); + goto error; + } + + /* Unencrypted */ + g_object_unref (s_wsec); + s_wsec = NULL; + } + + return (NMSetting *) s_wsec; + +error: + if (s_wsec) + g_object_unref (s_wsec); + return NULL; +} + +static gboolean +fill_wpa_ciphers (shvarFile *ifcfg, + NMSettingWirelessSecurity *wsec, + gboolean group, + gboolean adhoc) +{ + char *value = NULL, *p; + char **list = NULL, **iter; + int i = 0; + + p = value = svGetValueString (ifcfg, group ? "CIPHER_GROUP" : "CIPHER_PAIRWISE"); + if (!value) + return TRUE; + + list = g_strsplit_set (p, " ", 0); + for (iter = list; iter && *iter; iter++, i++) { + /* Ad-Hoc configurations cannot have pairwise ciphers, and can only + * have one group cipher. Ignore any additional group ciphers and + * any pairwise ciphers specified. + */ + if (adhoc) { + if (group && (i > 0)) { + PARSE_WARNING ("ignoring group cipher '%s' (only one group cipher allowed " + "in Ad-Hoc mode)", *iter); + continue; + } else if (!group) { + PARSE_WARNING ("ignoring pairwise cipher '%s' (pairwise not used " + "in Ad-Hoc mode)", *iter); + continue; + } + } + + if (!strcmp (*iter, "CCMP")) { + if (group) + nm_setting_wireless_security_add_group (wsec, "ccmp"); + else + nm_setting_wireless_security_add_pairwise (wsec, "ccmp"); + } else if (!strcmp (*iter, "TKIP")) { + if (group) + nm_setting_wireless_security_add_group (wsec, "tkip"); + else + nm_setting_wireless_security_add_pairwise (wsec, "tkip"); + } else if (group && !strcmp (*iter, "WEP104")) + nm_setting_wireless_security_add_group (wsec, "wep104"); + else if (group && !strcmp (*iter, "WEP40")) + nm_setting_wireless_security_add_group (wsec, "wep40"); + else { + PARSE_WARNING ("ignoring invalid %s cipher '%s'", + group ? "CIPHER_GROUP" : "CIPHER_PAIRWISE", + *iter); + } + } + + if (list) + g_strfreev (list); + g_free (value); + return TRUE; +} + +#define WPA_PMK_LEN 32 + +static char * +parse_wpa_psk (shvarFile *ifcfg, + const char *file, + GBytes *ssid, + GError **error) +{ + shvarFile *keys_ifcfg; + gs_free char *psk = NULL; + size_t plen; + + /* Passphrase must be between 10 and 66 characters in length because WPA + * hex keys are exactly 64 characters (no quoting), and WPA passphrases + * are between 8 and 63 characters (inclusive), plus optional quoting if + * the passphrase contains spaces. + */ + + /* Try to get keys from the "shadow" key file */ + keys_ifcfg = utils_get_keys_ifcfg (file, FALSE); + if (keys_ifcfg) { + psk = svGetValueString (keys_ifcfg, "WPA_PSK"); + svCloseFile (keys_ifcfg); + } + + /* Fall back to the original ifcfg */ + if (!psk) + psk = svGetValueString (ifcfg, "WPA_PSK"); + + if (!psk) + return NULL; + + plen = strlen (psk); + + if (plen == 64) { + /* Verify the hex PSK; 64 digits */ + if (!NM_STRCHAR_ALL (psk, ch, g_ascii_isxdigit (ch))) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Invalid WPA_PSK (contains non-hexadecimal characters)"); + return NULL; + } + } else { + if (plen < 8 || plen > 63) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Invalid WPA_PSK (passphrases must be between " + "8 and 63 characters long (inclusive))"); + return NULL; + } + } + + return g_steal_pointer (&psk); +} + +static gboolean +eap_simple_reader (const char *eap_method, + shvarFile *ifcfg, + shvarFile *keys, + NMSetting8021x *s_8021x, + gboolean phase2, + GError **error) +{ + NMSettingSecretFlags flags; + char *value; + + value = svGetValueString (ifcfg, "IEEE_8021X_IDENTITY"); + if (!value) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Missing IEEE_8021X_IDENTITY for EAP method '%s'.", + eap_method); + return FALSE; + } + g_object_set (s_8021x, NM_SETTING_802_1X_IDENTITY, value, NULL); + g_free (value); + + flags = read_secret_flags (ifcfg, "IEEE_8021X_PASSWORD_FLAGS"); + g_object_set (s_8021x, NM_SETTING_802_1X_PASSWORD_FLAGS, flags, NULL); + + /* Only read the password if it's system-owned */ + if (flags == NM_SETTING_SECRET_FLAG_NONE) { + value = svGetValueString (ifcfg, "IEEE_8021X_PASSWORD"); + if (!value && keys) { + /* Try the lookaside keys file */ + value = svGetValueString (keys, "IEEE_8021X_PASSWORD"); + } + + if (!value) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Missing IEEE_8021X_PASSWORD for EAP method '%s'.", + eap_method); + return FALSE; + } + + g_object_set (s_8021x, NM_SETTING_802_1X_PASSWORD, value, NULL); + g_free (value); + } + + return TRUE; +} + +static char * +get_full_file_path (const char *ifcfg_path, const char *file_path) +{ + const char *base = file_path; + char *p, *ret, *dirname; + + g_return_val_if_fail (ifcfg_path != NULL, NULL); + g_return_val_if_fail (file_path != NULL, NULL); + + if (file_path[0] == '/') + return g_strdup (file_path); + + p = strrchr (file_path, '/'); + if (p) + base = p + 1; + + dirname = g_path_get_dirname (ifcfg_path); + ret = g_build_path ("/", dirname, base, NULL); + g_free (dirname); + return ret; +} + +static gboolean +eap_tls_reader (const char *eap_method, + shvarFile *ifcfg, + shvarFile *keys, + NMSetting8021x *s_8021x, + gboolean phase2, + GError **error) +{ + char *value; + char *ca_cert = NULL; + char *real_path = NULL; + char *client_cert = NULL; + char *privkey = NULL; + char *privkey_password = NULL; + gboolean success = FALSE; + NMSetting8021xCKFormat privkey_format = NM_SETTING_802_1X_CK_FORMAT_UNKNOWN; + const char *ca_cert_key = phase2 ? "IEEE_8021X_INNER_CA_CERT" : "IEEE_8021X_CA_CERT"; + const char *pk_pw_key = phase2 ? "IEEE_8021X_INNER_PRIVATE_KEY_PASSWORD": "IEEE_8021X_PRIVATE_KEY_PASSWORD"; + const char *pk_key = phase2 ? "IEEE_8021X_INNER_PRIVATE_KEY" : "IEEE_8021X_PRIVATE_KEY"; + const char *cli_cert_key = phase2 ? "IEEE_8021X_INNER_CLIENT_CERT" : "IEEE_8021X_CLIENT_CERT"; + const char *pk_pw_flags_key = phase2 ? "IEEE_8021X_INNER_PRIVATE_KEY_PASSWORD_FLAGS": "IEEE_8021X_PRIVATE_KEY_PASSWORD_FLAGS"; + const char *pk_pw_flags_prop = phase2 ? NM_SETTING_802_1X_PHASE2_PRIVATE_KEY_PASSWORD_FLAGS : NM_SETTING_802_1X_PRIVATE_KEY_PASSWORD_FLAGS; + NMSettingSecretFlags flags; + + value = svGetValueString (ifcfg, "IEEE_8021X_IDENTITY"); + if (value) { + g_object_set (s_8021x, NM_SETTING_802_1X_IDENTITY, value, NULL); + g_free (value); + } + + ca_cert = svGetValueString (ifcfg, ca_cert_key); + if (ca_cert) { + real_path = get_full_file_path (svFileGetName (ifcfg), ca_cert); + if (phase2) { + if (!nm_setting_802_1x_set_phase2_ca_cert (s_8021x, + real_path, + NM_SETTING_802_1X_CK_SCHEME_PATH, + NULL, + error)) + goto done; + } else { + if (!nm_setting_802_1x_set_ca_cert (s_8021x, + real_path, + NM_SETTING_802_1X_CK_SCHEME_PATH, + NULL, + error)) + goto done; + } + g_free (real_path); + real_path = NULL; + } else { + PARSE_WARNING ("missing %s for EAP method '%s'; this is insecure!", + ca_cert_key, eap_method); + } + + /* Read and set private key password flags */ + flags = read_secret_flags (ifcfg, pk_pw_flags_key); + g_object_set (s_8021x, pk_pw_flags_prop, flags, NULL); + + /* Read the private key password if it's system-owned */ + if (flags == NM_SETTING_SECRET_FLAG_NONE) { + /* Private key password */ + privkey_password = svGetValueString (ifcfg, pk_pw_key); + if (!privkey_password && keys) { + /* Try the lookaside keys file */ + privkey_password = svGetValueString (keys, pk_pw_key); + } + + if (!privkey_password) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Missing %s for EAP method '%s'.", + pk_pw_key, + eap_method); + goto done; + } + } + + /* The private key itself */ + privkey = svGetValueString (ifcfg, pk_key); + if (!privkey) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Missing %s for EAP method '%s'.", + pk_key, + eap_method); + goto done; + } + + real_path = get_full_file_path (svFileGetName (ifcfg), privkey); + if (phase2) { + if (!nm_setting_802_1x_set_phase2_private_key (s_8021x, + real_path, + privkey_password, + NM_SETTING_802_1X_CK_SCHEME_PATH, + &privkey_format, + error)) + goto done; + } else { + if (!nm_setting_802_1x_set_private_key (s_8021x, + real_path, + privkey_password, + NM_SETTING_802_1X_CK_SCHEME_PATH, + &privkey_format, + error)) + goto done; + } + g_free (real_path); + real_path = NULL; + + /* Only set the client certificate if the private key is not PKCS#12 format, + * as NM (due to supplicant restrictions) requires. If the key was PKCS#12, + * then nm_setting_802_1x_set_private_key() already set the client certificate + * to the same value as the private key. + */ + if ( privkey_format == NM_SETTING_802_1X_CK_FORMAT_RAW_KEY + || privkey_format == NM_SETTING_802_1X_CK_FORMAT_X509) { + client_cert = svGetValueString (ifcfg, cli_cert_key); + if (!client_cert) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Missing %s for EAP method '%s'.", + cli_cert_key, + eap_method); + goto done; + } + + real_path = get_full_file_path (svFileGetName (ifcfg), client_cert); + if (phase2) { + if (!nm_setting_802_1x_set_phase2_client_cert (s_8021x, + real_path, + NM_SETTING_802_1X_CK_SCHEME_PATH, + NULL, + error)) + goto done; + } else { + if (!nm_setting_802_1x_set_client_cert (s_8021x, + real_path, + NM_SETTING_802_1X_CK_SCHEME_PATH, + NULL, + error)) + goto done; + } + g_free (real_path); + real_path = NULL; + } + + success = TRUE; + +done: + g_free (real_path); + g_free (ca_cert); + g_free (client_cert); + g_free (privkey); + g_free (privkey_password); + return success; +} + +static gboolean +eap_peap_reader (const char *eap_method, + shvarFile *ifcfg, + shvarFile *keys, + NMSetting8021x *s_8021x, + gboolean phase2, + GError **error) +{ + char *anon_ident = NULL; + char *ca_cert = NULL; + char *real_cert_path = NULL; + char *inner_auth = NULL; + char *peapver = NULL; + char *lower; + char **list = NULL, **iter; + gboolean success = FALSE; + + ca_cert = svGetValueString (ifcfg, "IEEE_8021X_CA_CERT"); + if (ca_cert) { + real_cert_path = get_full_file_path (svFileGetName (ifcfg), ca_cert); + if (!nm_setting_802_1x_set_ca_cert (s_8021x, + real_cert_path, + NM_SETTING_802_1X_CK_SCHEME_PATH, + NULL, + error)) + goto done; + } else { + PARSE_WARNING ("missing IEEE_8021X_CA_CERT for EAP method '%s'; this is insecure!", + eap_method); + } + + peapver = svGetValueString (ifcfg, "IEEE_8021X_PEAP_VERSION"); + if (peapver) { + if (!strcmp (peapver, "0")) + g_object_set (s_8021x, NM_SETTING_802_1X_PHASE1_PEAPVER, "0", NULL); + else if (!strcmp (peapver, "1")) + g_object_set (s_8021x, NM_SETTING_802_1X_PHASE1_PEAPVER, "1", NULL); + else { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Unknown IEEE_8021X_PEAP_VERSION value '%s'", + peapver); + goto done; + } + } + + if (svGetValueBoolean (ifcfg, "IEEE_8021X_PEAP_FORCE_NEW_LABEL", FALSE)) + g_object_set (s_8021x, NM_SETTING_802_1X_PHASE1_PEAPLABEL, "1", NULL); + + anon_ident = svGetValueString (ifcfg, "IEEE_8021X_ANON_IDENTITY"); + if (anon_ident && strlen (anon_ident)) + g_object_set (s_8021x, NM_SETTING_802_1X_ANONYMOUS_IDENTITY, anon_ident, NULL); + + inner_auth = svGetValueString (ifcfg, "IEEE_8021X_INNER_AUTH_METHODS"); + if (!inner_auth) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Missing IEEE_8021X_INNER_AUTH_METHODS."); + goto done; + } + + /* Handle options for the inner auth method */ + list = g_strsplit (inner_auth, " ", 0); + for (iter = list; iter && *iter; iter++) { + if (!strlen (*iter)) + continue; + + if ( !strcmp (*iter, "MSCHAPV2") + || !strcmp (*iter, "MD5") + || !strcmp (*iter, "GTC")) { + if (!eap_simple_reader (*iter, ifcfg, keys, s_8021x, TRUE, error)) + goto done; + } else if (!strcmp (*iter, "TLS")) { + if (!eap_tls_reader (*iter, ifcfg, keys, s_8021x, TRUE, error)) + goto done; + } else { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Unknown IEEE_8021X_INNER_AUTH_METHOD '%s'.", + *iter); + goto done; + } + + lower = g_ascii_strdown (*iter, -1); + g_object_set (s_8021x, NM_SETTING_802_1X_PHASE2_AUTH, lower, NULL); + g_free (lower); + break; + } + + if (!nm_setting_802_1x_get_phase2_auth (s_8021x)) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "No valid IEEE_8021X_INNER_AUTH_METHODS found."); + goto done; + } + + success = TRUE; + +done: + if (list) + g_strfreev (list); + g_free (inner_auth); + g_free (peapver); + g_free (real_cert_path); + g_free (ca_cert); + g_free (anon_ident); + return success; +} + +static gboolean +eap_ttls_reader (const char *eap_method, + shvarFile *ifcfg, + shvarFile *keys, + NMSetting8021x *s_8021x, + gboolean phase2, + GError **error) +{ + gboolean success = FALSE; + char *anon_ident = NULL; + char *ca_cert = NULL; + char *real_cert_path = NULL; + char *inner_auth = NULL; + char *tmp; + char **list = NULL, **iter; + + ca_cert = svGetValueString (ifcfg, "IEEE_8021X_CA_CERT"); + if (ca_cert) { + real_cert_path = get_full_file_path (svFileGetName (ifcfg), ca_cert); + if (!nm_setting_802_1x_set_ca_cert (s_8021x, + real_cert_path, + NM_SETTING_802_1X_CK_SCHEME_PATH, + NULL, + error)) + goto done; + } else { + PARSE_WARNING ("missing IEEE_8021X_CA_CERT for EAP method '%s'; this is insecure!", + eap_method); + } + + anon_ident = svGetValueString (ifcfg, "IEEE_8021X_ANON_IDENTITY"); + if (anon_ident && strlen (anon_ident)) + g_object_set (s_8021x, NM_SETTING_802_1X_ANONYMOUS_IDENTITY, anon_ident, NULL); + + tmp = svGetValueString (ifcfg, "IEEE_8021X_INNER_AUTH_METHODS"); + if (!tmp) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Missing IEEE_8021X_INNER_AUTH_METHODS."); + goto done; + } + + inner_auth = g_ascii_strdown (tmp, -1); + g_free (tmp); + + /* Handle options for the inner auth method */ + list = g_strsplit (inner_auth, " ", 0); + for (iter = list; iter && *iter; iter++) { + if (!strlen (*iter)) + continue; + + if ( !strcmp (*iter, "mschapv2") + || !strcmp (*iter, "mschap") + || !strcmp (*iter, "pap") + || !strcmp (*iter, "chap")) { + if (!eap_simple_reader (*iter, ifcfg, keys, s_8021x, TRUE, error)) + goto done; + g_object_set (s_8021x, NM_SETTING_802_1X_PHASE2_AUTH, *iter, NULL); + } else if (!strcmp (*iter, "eap-tls")) { + if (!eap_tls_reader (*iter, ifcfg, keys, s_8021x, TRUE, error)) + goto done; + g_object_set (s_8021x, NM_SETTING_802_1X_PHASE2_AUTHEAP, "tls", NULL); + } else if ( !strcmp (*iter, "eap-mschapv2") + || !strcmp (*iter, "eap-md5") + || !strcmp (*iter, "eap-gtc")) { + if (!eap_simple_reader (*iter, ifcfg, keys, s_8021x, TRUE, error)) + goto done; + g_object_set (s_8021x, NM_SETTING_802_1X_PHASE2_AUTHEAP, (*iter + NM_STRLEN ("eap-")), NULL); + } else { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Unknown IEEE_8021X_INNER_AUTH_METHOD '%s'.", + *iter); + goto done; + } + break; + } + + success = TRUE; + +done: + if (list) + g_strfreev (list); + g_free (inner_auth); + g_free (real_cert_path); + g_free (ca_cert); + g_free (anon_ident); + return success; +} + +static gboolean +eap_fast_reader (const char *eap_method, + shvarFile *ifcfg, + shvarFile *keys, + NMSetting8021x *s_8021x, + gboolean phase2, + GError **error) +{ + char *anon_ident = NULL; + char *pac_file = NULL; + char *real_pac_path = NULL; + char *inner_auth = NULL; + char *fast_provisioning = NULL; + char *lower; + char **list = NULL, **iter; + const char* pac_prov_str; + gboolean allow_unauth = FALSE, allow_auth = FALSE; + gboolean success = FALSE; + + pac_file = svGetValueString (ifcfg, "IEEE_8021X_PAC_FILE"); + if (pac_file) { + real_pac_path = get_full_file_path (svFileGetName (ifcfg), pac_file); + g_object_set (s_8021x, NM_SETTING_802_1X_PAC_FILE, real_pac_path, NULL); + } + + fast_provisioning = svGetValueString (ifcfg, "IEEE_8021X_FAST_PROVISIONING"); + if (fast_provisioning) { + list = g_strsplit_set (fast_provisioning, " \t", 0); + for (iter = list; iter && *iter; iter++) { + if (**iter == '\0') + continue; + if (strcmp (*iter, "allow-unauth") == 0) + allow_unauth = TRUE; + else if (strcmp (*iter, "allow-auth") == 0) + allow_auth = TRUE; + else { + PARSE_WARNING ("invalid IEEE_8021X_FAST_PROVISIONING '%s' " + "(space-separated list of these values [allow-auth, allow-unauth] expected)", + *iter); + } + } + g_strfreev (list); + list = NULL; + } + pac_prov_str = allow_unauth ? (allow_auth ? "3" : "1") : (allow_auth ? "2" : "0"); + g_object_set (s_8021x, NM_SETTING_802_1X_PHASE1_FAST_PROVISIONING, pac_prov_str, NULL); + + if (!pac_file && !(allow_unauth || allow_auth)) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "IEEE_8021X_PAC_FILE not provided and EAP-FAST automatic PAC provisioning disabled."); + goto done; + } + + anon_ident = svGetValueString (ifcfg, "IEEE_8021X_ANON_IDENTITY"); + if (anon_ident && strlen (anon_ident)) + g_object_set (s_8021x, NM_SETTING_802_1X_ANONYMOUS_IDENTITY, anon_ident, NULL); + + inner_auth = svGetValueString (ifcfg, "IEEE_8021X_INNER_AUTH_METHODS"); + if (!inner_auth) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Missing IEEE_8021X_INNER_AUTH_METHODS."); + goto done; + } + + /* Handle options for the inner auth method */ + list = g_strsplit (inner_auth, " ", 0); + for (iter = list; iter && *iter; iter++) { + if (!strlen (*iter)) + continue; + + if ( !strcmp (*iter, "MSCHAPV2") + || !strcmp (*iter, "GTC")) { + if (!eap_simple_reader (*iter, ifcfg, keys, s_8021x, TRUE, error)) + goto done; + } else { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Unknown IEEE_8021X_INNER_AUTH_METHOD '%s'.", + *iter); + goto done; + } + + lower = g_ascii_strdown (*iter, -1); + g_object_set (s_8021x, NM_SETTING_802_1X_PHASE2_AUTH, lower, NULL); + g_free (lower); + break; + } + + if (!nm_setting_802_1x_get_phase2_auth (s_8021x)) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "No valid IEEE_8021X_INNER_AUTH_METHODS found."); + goto done; + } + + success = TRUE; + +done: + g_strfreev (list); + g_free (inner_auth); + g_free (fast_provisioning); + g_free (real_pac_path); + g_free (pac_file); + g_free (anon_ident); + return success; +} + +typedef struct { + const char *method; + gboolean (*reader)(const char *eap_method, + shvarFile *ifcfg, + shvarFile *keys, + NMSetting8021x *s_8021x, + gboolean phase2, + GError **error); + gboolean wifi_phase2_only; +} EAPReader; + +static EAPReader eap_readers[] = { + { "md5", eap_simple_reader, TRUE }, + { "pap", eap_simple_reader, TRUE }, + { "chap", eap_simple_reader, TRUE }, + { "mschap", eap_simple_reader, TRUE }, + { "mschapv2", eap_simple_reader, TRUE }, + { "leap", eap_simple_reader, FALSE }, + { "pwd", eap_simple_reader, FALSE }, + { "tls", eap_tls_reader, FALSE }, + { "peap", eap_peap_reader, FALSE }, + { "ttls", eap_ttls_reader, FALSE }, + { "fast", eap_fast_reader, FALSE }, + { NULL, NULL } +}; + +static void +read_8021x_list_value (shvarFile *ifcfg, + const char *ifcfg_var_name, + NMSetting8021x *setting, + const char *prop_name) +{ + char *value; + char **strv; + + g_return_if_fail (ifcfg != NULL); + g_return_if_fail (ifcfg_var_name != NULL); + g_return_if_fail (prop_name != NULL); + + value = svGetValueString (ifcfg, ifcfg_var_name); + if (!value) + return; + + strv = g_strsplit_set (value, " \t", 0); + if (strv && strv[0]) + g_object_set (setting, prop_name, strv, NULL); + g_strfreev (strv); + g_free (value); +} + +static NMSetting8021x * +fill_8021x (shvarFile *ifcfg, + const char *file, + const char *key_mgmt, + gboolean wifi, + GError **error) +{ + NMSetting8021x *s_8021x; + shvarFile *keys = NULL; + char *value; + char **list = NULL, **iter; + + value = svGetValueString (ifcfg, "IEEE_8021X_EAP_METHODS"); + if (!value) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Missing IEEE_8021X_EAP_METHODS for key management '%s'", + key_mgmt); + return NULL; + } + + list = g_strsplit (value, " ", 0); + g_free (value); + + s_8021x = (NMSetting8021x *) nm_setting_802_1x_new (); + + /* Read in the lookaside keys file, if present */ + keys = utils_get_keys_ifcfg (file, FALSE); + + /* Validate and handle each EAP method */ + for (iter = list; iter && *iter; iter++) { + EAPReader *eap = &eap_readers[0]; + gboolean found = FALSE; + char *lower = NULL; + + lower = g_ascii_strdown (*iter, -1); + while (eap->method) { + if (strcmp (eap->method, lower)) + goto next; + + /* Some EAP methods don't provide keying material, thus they + * cannot be used with WiFi unless they are an inner method + * used with TTLS or PEAP or whatever. + */ + if (wifi && eap->wifi_phase2_only) { + PARSE_WARNING ("ignored invalid IEEE_8021X_EAP_METHOD '%s'; not allowed for wifi.", + lower); + goto next; + } + + /* Parse EAP method specific options */ + if (!(*eap->reader)(lower, ifcfg, keys, s_8021x, FALSE, error)) { + g_free (lower); + goto error; + } + nm_setting_802_1x_add_eap_method (s_8021x, lower); + found = TRUE; + break; + + next: + eap++; + } + + if (!found) + PARSE_WARNING ("ignored unknown IEEE_8021X_EAP_METHOD '%s'.", lower); + g_free (lower); + } + + if (nm_setting_802_1x_get_num_eap_methods (s_8021x) == 0) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "No valid EAP methods found in IEEE_8021X_EAP_METHODS."); + goto error; + } + + value = svGetValueString (ifcfg, "IEEE_8021X_SUBJECT_MATCH"); + g_object_set (s_8021x, NM_SETTING_802_1X_SUBJECT_MATCH, value, NULL); + g_free (value); + + value = svGetValueString (ifcfg, "IEEE_8021X_PHASE2_SUBJECT_MATCH"); + g_object_set (s_8021x, NM_SETTING_802_1X_PHASE2_SUBJECT_MATCH, value, NULL); + g_free (value); + + read_8021x_list_value (ifcfg, "IEEE_8021X_ALTSUBJECT_MATCHES", + s_8021x, NM_SETTING_802_1X_ALTSUBJECT_MATCHES); + read_8021x_list_value (ifcfg, "IEEE_8021X_PHASE2_ALTSUBJECT_MATCHES", + s_8021x, NM_SETTING_802_1X_PHASE2_ALTSUBJECT_MATCHES); + + value = svGetValueString (ifcfg, "IEEE_8021X_DOMAIN_SUFFIX_MATCH"); + g_object_set (s_8021x, NM_SETTING_802_1X_DOMAIN_SUFFIX_MATCH, value, NULL); + g_free (value); + value = svGetValueString (ifcfg, "IEEE_8021X_PHASE2_DOMAIN_SUFFIX_MATCH"); + g_object_set (s_8021x, NM_SETTING_802_1X_PHASE2_DOMAIN_SUFFIX_MATCH, value, NULL); + g_free (value); + + if (list) + g_strfreev (list); + if (keys) + svCloseFile (keys); + return s_8021x; + +error: + if (list) + g_strfreev (list); + if (keys) + svCloseFile (keys); + g_object_unref (s_8021x); + return NULL; +} + +static NMSetting * +make_wpa_setting (shvarFile *ifcfg, + const char *file, + GBytes *ssid, + gboolean adhoc, + NMSetting8021x **s_8021x, + GError **error) +{ + NMSettingWirelessSecurity *wsec; + char *value, *psk, *lower; + gboolean wpa_psk = FALSE, wpa_eap = FALSE, ieee8021x = FALSE; + + wsec = NM_SETTING_WIRELESS_SECURITY (nm_setting_wireless_security_new ()); + + value = svGetValueString (ifcfg, "KEY_MGMT"); + wpa_psk = !g_strcmp0 (value, "WPA-PSK"); + wpa_eap = !g_strcmp0 (value, "WPA-EAP"); + ieee8021x = !g_strcmp0 (value, "IEEE8021X"); + if (!wpa_psk && !wpa_eap && !ieee8021x) + goto error; /* Not WPA or Dynamic WEP */ + + /* Pairwise and Group ciphers (only relevant for WPA/RSN) */ + if (wpa_psk || wpa_eap) { + fill_wpa_ciphers (ifcfg, wsec, FALSE, adhoc); + fill_wpa_ciphers (ifcfg, wsec, TRUE, adhoc); + } + + /* WPA and/or RSN */ + if (adhoc) { + /* Ad-Hoc mode only supports WPA proto for now */ + nm_setting_wireless_security_add_proto (wsec, "wpa"); + } else { + char *allow_wpa, *allow_rsn; + + allow_wpa = svGetValueString (ifcfg, "WPA_ALLOW_WPA"); + allow_rsn = svGetValueString (ifcfg, "WPA_ALLOW_WPA2"); + + if (allow_wpa && svGetValueBoolean (ifcfg, "WPA_ALLOW_WPA", TRUE)) + nm_setting_wireless_security_add_proto (wsec, "wpa"); + if (allow_rsn && svGetValueBoolean (ifcfg, "WPA_ALLOW_WPA2", TRUE)) + nm_setting_wireless_security_add_proto (wsec, "rsn"); + + g_free (allow_wpa); + g_free (allow_rsn); + } + + if (wpa_psk) { + NMSettingSecretFlags psk_flags; + + psk_flags = read_secret_flags (ifcfg, "WPA_PSK_FLAGS"); + g_object_set (wsec, NM_SETTING_WIRELESS_SECURITY_PSK_FLAGS, psk_flags, NULL); + + /* Read PSK if it's system-owned */ + if (psk_flags == NM_SETTING_SECRET_FLAG_NONE) { + psk = parse_wpa_psk (ifcfg, file, ssid, error); + if (psk) { + g_object_set (wsec, NM_SETTING_WIRELESS_SECURITY_PSK, psk, NULL); + g_free (psk); + } else if (error) + goto error; + } + + if (adhoc) + g_object_set (wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "wpa-none", NULL); + else + g_object_set (wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "wpa-psk", NULL); + } else if (wpa_eap || ieee8021x) { + /* Adhoc mode is mutually exclusive with any 802.1x-based authentication */ + if (adhoc) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Ad-Hoc mode cannot be used with KEY_MGMT type '%s'", value); + goto error; + } + + *s_8021x = fill_8021x (ifcfg, file, value, TRUE, error); + if (!*s_8021x) + goto error; + + lower = g_ascii_strdown (value, -1); + g_object_set (wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, lower, NULL); + g_free (lower); + } else { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Unknown wireless KEY_MGMT type '%s'", value); + goto error; + } + + g_free (value); + + value = svGetValueString (ifcfg, "SECURITYMODE"); + if (NM_IN_STRSET (value, NULL, "open")) + g_object_set (wsec, NM_SETTING_WIRELESS_SECURITY_AUTH_ALG, value, NULL); + + g_free (value); + return (NMSetting *) wsec; + +error: + g_free (value); + if (wsec) + g_object_unref (wsec); + return NULL; +} + +static NMSetting * +make_leap_setting (shvarFile *ifcfg, + const char *file, + GError **error) +{ + NMSettingWirelessSecurity *wsec; + shvarFile *keys_ifcfg; + char *value; + NMSettingSecretFlags flags; + + wsec = NM_SETTING_WIRELESS_SECURITY (nm_setting_wireless_security_new ()); + + value = svGetValueString (ifcfg, "KEY_MGMT"); + if (!value || strcmp (value, "IEEE8021X")) + goto error; /* Not LEAP */ + + g_free (value); + value = svGetValueString (ifcfg, "SECURITYMODE"); + if (!value || strcasecmp (value, "leap")) + goto error; /* Not LEAP */ + + g_free (value); + + flags = read_secret_flags (ifcfg, "IEEE_8021X_PASSWORD_FLAGS"); + g_object_set (wsec, NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD_FLAGS, flags, NULL); + + /* Read LEAP password if it's system-owned */ + if (flags == NM_SETTING_SECRET_FLAG_NONE) { + value = svGetValueString (ifcfg, "IEEE_8021X_PASSWORD"); + if (!value) { + /* Try to get keys from the "shadow" key file */ + keys_ifcfg = utils_get_keys_ifcfg (file, FALSE); + if (keys_ifcfg) { + value = svGetValueString (keys_ifcfg, "IEEE_8021X_PASSWORD"); + svCloseFile (keys_ifcfg); + } + } + if (value && strlen (value)) + g_object_set (wsec, NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD, value, NULL); + g_free (value); + } + + value = svGetValueString (ifcfg, "IEEE_8021X_IDENTITY"); + if (!value || !strlen (value)) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Missing LEAP identity"); + goto error; + } + g_object_set (wsec, NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME, value, NULL); + g_free (value); + + g_object_set (wsec, + NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "ieee8021x", + NM_SETTING_WIRELESS_SECURITY_AUTH_ALG, "leap", + NULL); + + return (NMSetting *) wsec; + +error: + g_free (value); + if (wsec) + g_object_unref (wsec); + return NULL; +} + +static NMSetting * +make_wireless_security_setting (shvarFile *ifcfg, + const char *file, + GBytes *ssid, + gboolean adhoc, + NMSetting8021x **s_8021x, + GError **error) +{ + NMSetting *wsec; + + g_return_val_if_fail (error && !*error, NULL); + + if (!adhoc) { + wsec = make_leap_setting (ifcfg, file, error); + if (wsec) + return wsec; + else if (*error) + return NULL; + } + + wsec = make_wpa_setting (ifcfg, file, ssid, adhoc, s_8021x, error); + if (wsec) + return wsec; + else if (*error) + return NULL; + + wsec = make_wep_setting (ifcfg, file, error); + if (wsec) + return wsec; + else if (*error) + return NULL; + + return NULL; /* unencrypted */ +} + +static char ** +transform_hwaddr_blacklist (const char *blacklist) +{ + char **strv, **iter; + int shift = 0; + + strv = _nm_utils_strsplit_set (blacklist, " \t", 0); + for (iter = strv; iter && *iter; iter++) { + if (shift) { + *(iter - shift) = *iter; + *iter = NULL; + } + if (!nm_utils_hwaddr_valid (*(iter - shift), ETH_ALEN)) { + PARSE_WARNING ("invalid MAC in HWADDR_BLACKLIST '%s'", *(iter - shift)); + g_free (*(iter - shift)); + *(iter - shift) = NULL; + shift++; + } + } + return strv; +} + +static NMSetting * +make_wireless_setting (shvarFile *ifcfg, + GError **error) +{ + NMSettingWireless *s_wireless; + const char *cvalue; + char *value = NULL; + gint64 chan = 0; + NMSettingMacRandomization mac_randomization = NM_SETTING_MAC_RANDOMIZATION_NEVER; + NMSettingWirelessPowersave powersave = NM_SETTING_WIRELESS_POWERSAVE_DEFAULT; + + s_wireless = NM_SETTING_WIRELESS (nm_setting_wireless_new ()); + + value = svGetValueString (ifcfg, "HWADDR"); + if (value) { + value = g_strstrip (value); + g_object_set (s_wireless, NM_SETTING_WIRELESS_MAC_ADDRESS, value, NULL); + g_free (value); + } + + value = svGetValueString (ifcfg, "MACADDR"); + if (value) { + value = g_strstrip (value); + g_object_set (s_wireless, NM_SETTING_WIRELESS_CLONED_MAC_ADDRESS, value, NULL); + g_free (value); + } + + value = svGetValueString (ifcfg, "GENERATE_MAC_ADDRESS_MASK"); + g_object_set (s_wireless, NM_SETTING_WIRELESS_GENERATE_MAC_ADDRESS_MASK, value, NULL); + g_free (value); + + value = svGetValueString (ifcfg, "HWADDR_BLACKLIST"); + if (value) { + char **strv; + + strv = transform_hwaddr_blacklist (value); + g_object_set (s_wireless, NM_SETTING_WIRELESS_MAC_ADDRESS_BLACKLIST, strv, NULL); + g_strfreev (strv); + g_free (value); + } + + value = svGetValueString (ifcfg, "ESSID"); + if (value) { + gs_unref_bytes GBytes *bytes = NULL; + gsize ssid_len = 0; + gsize value_len = strlen (value); + + if ( value_len > 2 + && (value_len % 2) == 0 + && g_str_has_prefix (value, "0x") + && NM_STRCHAR_ALL (&value[2], ch, g_ascii_isxdigit (ch))) { + /* interpret the value as hex-digits iff value starts + * with "0x" followed by pairs of hex digits */ + bytes = nm_utils_hexstr2bin (&value[2]); + } else + bytes = g_bytes_new (value, value_len); + + ssid_len = g_bytes_get_size (bytes); + if (ssid_len > 32 || ssid_len == 0) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Invalid SSID '%s' (size %zu not between 1 and 32 inclusive)", + value, ssid_len); + g_free (value); + goto error; + } + + g_object_set (s_wireless, NM_SETTING_WIRELESS_SSID, bytes, NULL); + g_free (value); + } + + value = svGetValueString (ifcfg, "MODE"); + if (value) { + char *lcase; + const char *mode = NULL; + + lcase = g_ascii_strdown (value, -1); + g_free (value); + + if (!strcmp (lcase, "ad-hoc")) { + mode = "adhoc"; + } else if (!strcmp (lcase, "ap")) { + mode = "ap"; + } else if (!strcmp (lcase, "managed") || !strcmp (lcase, "auto")) { + mode = "infrastructure"; + } else { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Invalid mode '%s' (not 'Ad-Hoc', 'Ap', 'Managed', or 'Auto')", + lcase); + g_free (lcase); + goto error; + } + g_free (lcase); + + g_object_set (s_wireless, NM_SETTING_WIRELESS_MODE, mode, NULL); + } + + value = svGetValueString (ifcfg, "BSSID"); + if (value) { + value = g_strstrip (value); + g_object_set (s_wireless, NM_SETTING_WIRELESS_BSSID, value, NULL); + g_free (value); + } + + value = svGetValueString (ifcfg, "CHANNEL"); + if (value) { + errno = 0; + chan = _nm_utils_ascii_str_to_int64 (value, 10, 1, 196, 0); + if (errno || (chan == 0)) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Invalid wireless channel '%s'", value); + g_free (value); + goto error; + } + g_object_set (s_wireless, NM_SETTING_WIRELESS_CHANNEL, (guint32) chan, NULL); + g_free (value); + } + + value = svGetValueString (ifcfg, "BAND"); + if (value) { + if (!strcmp (value, "a")) { + if (chan && chan <= 14) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Band '%s' invalid for channel %u", value, (guint32) chan); + g_free (value); + goto error; + } + } else if (!strcmp (value, "bg")) { + if (chan && chan > 14) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Band '%s' invalid for channel %u", value, (guint32) chan); + g_free (value); + goto error; + } + } else { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Invalid wireless band '%s'", value); + g_free (value); + goto error; + } + g_object_set (s_wireless, NM_SETTING_WIRELESS_BAND, value, NULL); + g_free (value); + } else if (chan > 0) { + if (chan > 14) + g_object_set (s_wireless, NM_SETTING_WIRELESS_BAND, "a", NULL); + else + g_object_set (s_wireless, NM_SETTING_WIRELESS_BAND, "bg", NULL); + } + + value = svGetValueString (ifcfg, "MTU"); + if (value) { + int mtu; + + mtu = _nm_utils_ascii_str_to_int64 (value, 10, 0, 50000, -1); + if (mtu == -1) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Invalid wireless MTU '%s'", value); + g_free (value); + goto error; + } + g_object_set (s_wireless, NM_SETTING_WIRELESS_MTU, (guint) mtu, NULL); + g_free (value); + } + + g_object_set (s_wireless, + NM_SETTING_WIRELESS_HIDDEN, + svGetValueBoolean (ifcfg, "SSID_HIDDEN", FALSE), + NULL); + + cvalue = svGetValue (ifcfg, "POWERSAVE", &value); + if (cvalue) { + if (!strcmp (cvalue, "default")) + powersave = NM_SETTING_WIRELESS_POWERSAVE_DEFAULT; + else if (!strcmp (cvalue, "ignore")) + powersave = NM_SETTING_WIRELESS_POWERSAVE_IGNORE; + else if (!strcmp (cvalue, "disable") || !strcmp (cvalue, "no")) + powersave = NM_SETTING_WIRELESS_POWERSAVE_DISABLE; + else if (!strcmp (cvalue, "enable") || !strcmp (cvalue, "yes")) + powersave = NM_SETTING_WIRELESS_POWERSAVE_ENABLE; + else { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Invalid POWERSAVE value '%s'", cvalue); + g_free (value); + goto error; + } + g_free (value); + } + + g_object_set (s_wireless, + NM_SETTING_WIRELESS_POWERSAVE, + powersave, + NULL); + + cvalue = svGetValue (ifcfg, "MAC_ADDRESS_RANDOMIZATION", &value); + if (cvalue) { + if (strcmp (cvalue, "default") == 0) + mac_randomization = NM_SETTING_MAC_RANDOMIZATION_DEFAULT; + else if (strcmp (cvalue, "never") == 0) + mac_randomization = NM_SETTING_MAC_RANDOMIZATION_NEVER; + else if (strcmp (cvalue, "always") == 0) + mac_randomization = NM_SETTING_MAC_RANDOMIZATION_ALWAYS; + else { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Invalid MAC_ADDRESS_RANDOMIZATION value '%s'", cvalue); + g_free (value); + goto error; + } + g_free (value); + } else + mac_randomization = NM_SETTING_MAC_RANDOMIZATION_NEVER; + + g_object_set (s_wireless, + NM_SETTING_WIRELESS_MAC_ADDRESS_RANDOMIZATION, + mac_randomization, + NULL); + + return NM_SETTING (s_wireless); + +error: + if (s_wireless) + g_object_unref (s_wireless); + return NULL; +} + +static NMConnection * +wireless_connection_from_ifcfg (const char *file, + shvarFile *ifcfg, + GError **error) +{ + NMConnection *connection = NULL; + NMSetting *con_setting = NULL; + NMSetting *wireless_setting = NULL; + NMSetting8021x *s_8021x = NULL; + GBytes *ssid; + NMSetting *security_setting = NULL; + char *printable_ssid = NULL; + const char *mode; + gboolean adhoc = FALSE; + GError *local = NULL; + + g_return_val_if_fail (file != NULL, NULL); + g_return_val_if_fail (ifcfg != NULL, NULL); + g_return_val_if_fail (!error || !*error, NULL); + + connection = nm_simple_connection_new (); + + /* Wireless */ + wireless_setting = make_wireless_setting (ifcfg, error); + if (!wireless_setting) { + g_object_unref (connection); + return NULL; + } + nm_connection_add_setting (connection, wireless_setting); + + ssid = nm_setting_wireless_get_ssid (NM_SETTING_WIRELESS (wireless_setting)); + if (ssid) { + printable_ssid = nm_utils_ssid_to_utf8 (g_bytes_get_data (ssid, NULL), + g_bytes_get_size (ssid)); + } else + printable_ssid = g_strdup_printf ("unmanaged"); + + mode = nm_setting_wireless_get_mode (NM_SETTING_WIRELESS (wireless_setting)); + if (mode && !strcmp (mode, "adhoc")) + adhoc = TRUE; + + /* Wireless security */ + security_setting = make_wireless_security_setting (ifcfg, file, ssid, adhoc, &s_8021x, &local); + if (local) { + g_free (printable_ssid); + g_object_unref (connection); + g_propagate_error (error, local); + return NULL; + } + if (security_setting) { + nm_connection_add_setting (connection, security_setting); + if (s_8021x) + nm_connection_add_setting (connection, NM_SETTING (s_8021x)); + } + + /* Connection */ + con_setting = make_connection_setting (file, ifcfg, + NM_SETTING_WIRELESS_SETTING_NAME, + printable_ssid, NULL); + g_free (printable_ssid); + if (!con_setting) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Failed to create connection setting."); + g_object_unref (connection); + return NULL; + } + nm_connection_add_setting (connection, con_setting); + + return connection; +} + +static void +parse_ethtool_option_autoneg (const char *value, gboolean *out_autoneg) +{ + if (!value) { + PARSE_WARNING ("Auto-negotiation option missing"); + return; + } + + if (g_str_equal (value, "off")) + *out_autoneg = FALSE; + else if (g_str_equal (value, "on")) + *out_autoneg = TRUE; + else + PARSE_WARNING ("Auto-negotiation unknown value: %s", value); +} + +static void +parse_ethtool_option_speed (const char *value, guint32 *out_speed) +{ + if (!value) { + PARSE_WARNING ("Speed option missing"); + return; + } + + *out_speed = _nm_utils_ascii_str_to_int64 (value, 10, 0, G_MAXUINT32, 0); + if (errno) + PARSE_WARNING ("Speed value '%s' is invalid", value); +} + +static void +parse_ethtool_option_duplex (const char *value, const char **out_duplex) +{ + if (!value) { + PARSE_WARNING ("Duplex option missing"); + return; + } + + if (g_str_equal (value, "half")) + *out_duplex = "half"; + else if (g_str_equal (value, "full")) + *out_duplex = "full"; + else + PARSE_WARNING ("Duplex unknown value: %s", value); + +} + +static void +parse_ethtool_option_wol (const char *value, NMSettingWiredWakeOnLan *out_flags) +{ + NMSettingWiredWakeOnLan wol_flags = NM_SETTING_WIRED_WAKE_ON_LAN_NONE; + + if (!value) { + PARSE_WARNING ("Wake-on-LAN options missing"); + return; + } + + for (; *value; value++) { + switch (*value) { + case 'p': + wol_flags |= NM_SETTING_WIRED_WAKE_ON_LAN_PHY; + break; + case 'u': + wol_flags |= NM_SETTING_WIRED_WAKE_ON_LAN_UNICAST; + break; + case 'm': + wol_flags |= NM_SETTING_WIRED_WAKE_ON_LAN_MULTICAST; + break; + case 'b': + wol_flags |= NM_SETTING_WIRED_WAKE_ON_LAN_BROADCAST; + break; + case 'a': + wol_flags |= NM_SETTING_WIRED_WAKE_ON_LAN_ARP; + break; + case 'g': + wol_flags |= NM_SETTING_WIRED_WAKE_ON_LAN_MAGIC; + break; + case 's': + break; + case 'd': + wol_flags = NM_SETTING_WIRED_WAKE_ON_LAN_NONE; + break; + default: + PARSE_WARNING ("unrecognized Wake-on-LAN option '%c'", *value); + } + } + + *out_flags = wol_flags; +} + +static void parse_ethtool_option_sopass (const char *value, char **out_password) +{ + if (!value) { + PARSE_WARNING ("Wake-on-LAN password missing"); + return; + } + + g_clear_pointer (out_password, g_free); + if (!nm_utils_hwaddr_valid (value, ETH_ALEN)) { + PARSE_WARNING ("Wake-on-LAN password '%s' is invalid", value); + return; + } + + *out_password = g_strdup (value); +} + +static void +parse_ethtool_option (const char *value, + NMSettingWiredWakeOnLan *out_flags, + char **out_password, + gboolean *out_autoneg, + guint32 *out_speed, + const char **out_duplex) +{ + gs_strfreev char **words = NULL; + const char **iter = NULL, *opt_val, *opt; + + if (!value || !value[0]) + return; + + words = g_strsplit_set (value, "\t ", 0); + iter = (const char **) words; + + while (iter[0]) { + /* g_strsplit_set() returns empty tokens when extra spaces are found: skip them */ + if (!*iter[0]) { + iter++; + continue; + } + + opt = iter++[0]; + + /* skip over repeated space characters like to parse "wol d". */ + while (iter[0] && !*iter[0]) + iter++; + + opt_val = iter[0]; + + if (g_str_equal (opt, "autoneg")) + parse_ethtool_option_autoneg (opt_val, out_autoneg); + else if (g_str_equal (opt, "speed")) + parse_ethtool_option_speed (opt_val, out_speed); + else if (g_str_equal (opt, "duplex")) + parse_ethtool_option_duplex (opt_val, out_duplex); + else if (g_str_equal (opt, "wol")) + parse_ethtool_option_wol (opt_val, out_flags); + else if (g_str_equal (opt, "sopass")) + parse_ethtool_option_sopass (opt_val, out_password); + else { + /* Silently skip unknown options */ + continue; + } + + if (iter[0]) + iter++; + } +} + +static void +parse_ethtool_options (shvarFile *ifcfg, NMSettingWired *s_wired, const char *value) +{ + NMSettingWiredWakeOnLan wol_flags = NM_SETTING_WIRED_WAKE_ON_LAN_DEFAULT; + gs_free char *wol_password = NULL, *wol_value = NULL; + gboolean ignore_wol_password = FALSE, autoneg = FALSE; + guint32 speed = 0; + const char *duplex = NULL; + + if (value) { + gs_strfreev char **opts = NULL; + const char **iter; + + /* WAKE_ON_LAN_IGNORE is inferred from a specified but empty ETHTOOL_OPTS */ + if (!value[0]) + wol_flags = NM_SETTING_WIRED_WAKE_ON_LAN_IGNORE; + + opts = g_strsplit_set (value, ";", 0); + for (iter = (const char **) opts; iter[0]; iter++) { + /* in case of repeated wol_passwords, parse_ethtool_option() + * will do the right thing and clear wol_password before resetting. */ + parse_ethtool_option (iter[0], &wol_flags, &wol_password, &autoneg, &speed, &duplex); + } + } + + /* ETHTOOL_WAKE_ON_LAN = ignore overrides WoL settings in ETHTOOL_OPTS */ + wol_value = svGetValueString (ifcfg, "ETHTOOL_WAKE_ON_LAN"); + if (wol_value) { + if (strcmp (wol_value, "ignore") == 0) + wol_flags = NM_SETTING_WIRED_WAKE_ON_LAN_IGNORE; + else + PARSE_WARNING ("invalid ETHTOOL_WAKE_ON_LAN value '%s'", wol_value); + } + + if ( wol_password + && !NM_FLAGS_HAS (wol_flags, NM_SETTING_WIRED_WAKE_ON_LAN_MAGIC)) { + PARSE_WARNING ("Wake-on-LAN password not expected"); + ignore_wol_password = TRUE; + } + + g_object_set (s_wired, + NM_SETTING_WIRED_WAKE_ON_LAN, wol_flags, + NM_SETTING_WIRED_WAKE_ON_LAN_PASSWORD, ignore_wol_password ? NULL : wol_password, + NM_SETTING_WIRED_AUTO_NEGOTIATE, autoneg, + NM_SETTING_WIRED_SPEED, autoneg ? 0 : speed, + NM_SETTING_WIRED_DUPLEX, autoneg ? NULL : duplex, + NULL); +} + +static NMSetting * +make_wired_setting (shvarFile *ifcfg, + const char *file, + NMSetting8021x **s_8021x, + GError **error) +{ + NMSettingWired *s_wired; + char *value = NULL; + char *nettype; + + s_wired = NM_SETTING_WIRED (nm_setting_wired_new ()); + + value = svGetValueString (ifcfg, "MTU"); + if (value) { + int mtu; + + mtu = _nm_utils_ascii_str_to_int64 (value, 0, 0, 65535, -1); + if (mtu >= 0) + g_object_set (s_wired, NM_SETTING_WIRED_MTU, (guint) mtu, NULL); + else + PARSE_WARNING ("invalid MTU '%s'", value); + g_free (value); + } + + value = svGetValueString (ifcfg, "HWADDR"); + if (value) { + value = g_strstrip (value); + g_object_set (s_wired, NM_SETTING_WIRED_MAC_ADDRESS, value, NULL); + g_free (value); + } + + value = svGetValueString (ifcfg, "SUBCHANNELS"); + if (value) { + const char *p = value; + gboolean success = TRUE; + char **chans = NULL; + + /* basic sanity checks */ + while (*p) { + if (!g_ascii_isxdigit (*p) && (*p != ',') && (*p != '.')) { + PARSE_WARNING ("invalid SUBCHANNELS '%s'", value); + success = FALSE; + break; + } + p++; + } + + if (success) { + guint32 num_chans; + + chans = g_strsplit_set (value, ",", 0); + num_chans = g_strv_length (chans); + if (num_chans < 2 || num_chans > 3) { + PARSE_WARNING ("invalid SUBCHANNELS '%s' (%d channels, 2 or 3 expected)", + value, g_strv_length (chans)); + } else + g_object_set (s_wired, NM_SETTING_WIRED_S390_SUBCHANNELS, chans, NULL); + g_strfreev (chans); + } + g_free (value); + } + + value = svGetValueString (ifcfg, "PORTNAME"); + if (value && strlen (value)) { + nm_setting_wired_add_s390_option (s_wired, "portname", value); + } + g_free (value); + + value = svGetValueString (ifcfg, "CTCPROT"); + if (value && strlen (value)) + nm_setting_wired_add_s390_option (s_wired, "ctcprot", value); + g_free (value); + + nettype = svGetValueString (ifcfg, "NETTYPE"); + if (nettype && strlen (nettype)) { + if (!strcmp (nettype, "qeth") || !strcmp (nettype, "lcs") || !strcmp (nettype, "ctc")) + g_object_set (s_wired, NM_SETTING_WIRED_S390_NETTYPE, nettype, NULL); + else + PARSE_WARNING ("unknown s390 NETTYPE '%s'", nettype); + } + g_free (nettype); + + value = svGetValueString (ifcfg, "OPTIONS"); + if (value && strlen (value)) { + char **options, **iter; + + iter = options = g_strsplit_set (value, " ", 0); + while (iter && *iter) { + char *equals = strchr (*iter, '='); + gboolean valid = FALSE; + + if (equals) { + *equals = '\0'; + valid = nm_setting_wired_add_s390_option (s_wired, *iter, equals + 1); + } + if (!valid) + PARSE_WARNING ("invalid s390 OPTION '%s'", *iter); + iter++; + } + g_strfreev (options); + } + g_free (value); + + value = svGetValueString (ifcfg, "MACADDR"); + if (value) { + value = g_strstrip (value); + g_object_set (s_wired, NM_SETTING_WIRED_CLONED_MAC_ADDRESS, value, NULL); + g_free (value); + } + + value = svGetValueString (ifcfg, "GENERATE_MAC_ADDRESS_MASK"); + g_object_set (s_wired, NM_SETTING_WIRED_GENERATE_MAC_ADDRESS_MASK, value, NULL); + g_free (value); + + value = svGetValueString (ifcfg, "HWADDR_BLACKLIST"); + if (value) { + char **strv; + + strv = transform_hwaddr_blacklist (value); + g_object_set (s_wired, NM_SETTING_WIRED_MAC_ADDRESS_BLACKLIST, strv, NULL); + g_strfreev (strv); + g_free (value); + } + + value = svGetValueString (ifcfg, "KEY_MGMT"); + if (value) { + if (!strcmp (value, "IEEE8021X")) { + *s_8021x = fill_8021x (ifcfg, file, value, FALSE, error); + if (!*s_8021x) + goto error; + } else { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Unknown wired KEY_MGMT type '%s'", value); + goto error; + } + g_free (value); + } + + parse_ethtool_options (ifcfg, s_wired, + svGetValue (ifcfg, "ETHTOOL_OPTS", &value)); + g_free (value); + + return (NMSetting *) s_wired; + +error: + g_free (value); + g_object_unref (s_wired); + return NULL; +} + +static NMConnection * +wired_connection_from_ifcfg (const char *file, + shvarFile *ifcfg, + GError **error) +{ + NMConnection *connection = NULL; + NMSetting *con_setting = NULL; + NMSetting *wired_setting = NULL; + NMSetting8021x *s_8021x = NULL; + + g_return_val_if_fail (file != NULL, NULL); + g_return_val_if_fail (ifcfg != NULL, NULL); + + connection = nm_simple_connection_new (); + + con_setting = make_connection_setting (file, ifcfg, NM_SETTING_WIRED_SETTING_NAME, NULL, NULL); + if (!con_setting) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Failed to create connection setting."); + g_object_unref (connection); + return NULL; + } + check_if_slave (ifcfg, (NMSettingConnection *) con_setting); + nm_connection_add_setting (connection, con_setting); + + wired_setting = make_wired_setting (ifcfg, file, &s_8021x, error); + if (!wired_setting) { + g_object_unref (connection); + return NULL; + } + nm_connection_add_setting (connection, wired_setting); + + if (s_8021x) + nm_connection_add_setting (connection, NM_SETTING (s_8021x)); + + return connection; +} + +static gboolean +parse_infiniband_p_key (shvarFile *ifcfg, + int *out_p_key, + char **out_parent, + GError **error) +{ + char *device = NULL, *physdev = NULL, *pkey_id = NULL; + char *ifname = NULL; + int id; + gboolean ret = FALSE; + + device = svGetValueString (ifcfg, "DEVICE"); + if (!device) { + PARSE_WARNING ("InfiniBand connection specified PKEY but not DEVICE"); + goto done; + } + + physdev = svGetValueString (ifcfg, "PHYSDEV"); + if (!physdev) { + PARSE_WARNING ("InfiniBand connection specified PKEY but not PHYSDEV"); + goto done; + } + + pkey_id = svGetValueString (ifcfg, "PKEY_ID"); + if (!pkey_id) { + PARSE_WARNING ("InfiniBand connection specified PKEY but not PKEY_ID"); + goto done; + } + + id = _nm_utils_ascii_str_to_int64 (pkey_id, 0, 0, 0xFFFF, -1); + if (id == -1) { + PARSE_WARNING ("invalid InfiniBand PKEY_ID '%s'", pkey_id); + goto done; + } + id = (id | 0x8000); + + ifname = g_strdup_printf ("%s.%04x", physdev, (unsigned) id); + if (strcmp (device, ifname) != 0) { + PARSE_WARNING ("InfiniBand DEVICE (%s) does not match PHYSDEV+PKEY_ID (%s)", + device, ifname); + goto done; + } + + *out_p_key = id; + *out_parent = g_strdup (physdev); + ret = TRUE; + + done: + g_free (device); + g_free (physdev); + g_free (pkey_id); + g_free (ifname); + + if (!ret) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Failed to create InfiniBand setting."); + } + return ret; +} + + +static NMSetting * +make_infiniband_setting (shvarFile *ifcfg, + const char *file, + GError **error) +{ + NMSettingInfiniband *s_infiniband; + char *value = NULL; + + s_infiniband = NM_SETTING_INFINIBAND (nm_setting_infiniband_new ()); + + value = svGetValueString (ifcfg, "MTU"); + if (value) { + int mtu; + + mtu = _nm_utils_ascii_str_to_int64 (value, 0, 0, 65535, -1); + if (mtu >= 0) + g_object_set (s_infiniband, NM_SETTING_INFINIBAND_MTU, (guint) mtu, NULL); + else + PARSE_WARNING ("invalid MTU '%s'", value); + g_free (value); + } + + value = svGetValueString (ifcfg, "HWADDR"); + if (value) { + value = g_strstrip (value); + g_object_set (s_infiniband, NM_SETTING_INFINIBAND_MAC_ADDRESS, value, NULL); + g_free (value); + } + + if (svGetValueBoolean (ifcfg, "CONNECTED_MODE", FALSE)) + g_object_set (s_infiniband, NM_SETTING_INFINIBAND_TRANSPORT_MODE, "connected", NULL); + else + g_object_set (s_infiniband, NM_SETTING_INFINIBAND_TRANSPORT_MODE, "datagram", NULL); + + if (svGetValueBoolean (ifcfg, "PKEY", FALSE)) { + int p_key; + char *parent; + + if (!parse_infiniband_p_key (ifcfg, &p_key, &parent, error)) { + g_object_unref (s_infiniband); + return NULL; + } + + g_object_set (s_infiniband, + NM_SETTING_INFINIBAND_P_KEY, p_key, + NM_SETTING_INFINIBAND_PARENT, parent, + NULL); + } + + return (NMSetting *) s_infiniband; +} + +static NMConnection * +infiniband_connection_from_ifcfg (const char *file, + shvarFile *ifcfg, + GError **error) +{ + NMConnection *connection = NULL; + NMSetting *con_setting = NULL; + NMSetting *infiniband_setting = NULL; + + g_return_val_if_fail (file != NULL, NULL); + g_return_val_if_fail (ifcfg != NULL, NULL); + + connection = nm_simple_connection_new (); + + con_setting = make_connection_setting (file, ifcfg, NM_SETTING_INFINIBAND_SETTING_NAME, NULL, NULL); + if (!con_setting) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Failed to create connection setting."); + g_object_unref (connection); + return NULL; + } + check_if_slave (ifcfg, (NMSettingConnection *) con_setting); + nm_connection_add_setting (connection, con_setting); + + infiniband_setting = make_infiniband_setting (ifcfg, file, error); + if (!infiniband_setting) { + g_object_unref (connection); + return NULL; + } + nm_connection_add_setting (connection, infiniband_setting); + + return connection; +} + +static void +handle_bond_option (NMSettingBond *s_bond, + const char *key, + const char *value) +{ + char *sanitized = NULL, *j; + const char *p = value; + + /* Remove any quotes or +/- from arp_ip_target */ + if (!g_strcmp0 (key, NM_SETTING_BOND_OPTION_ARP_IP_TARGET) && value && value[0]) { + if (*p == '\'' || *p == '"') + p++; + j = sanitized = g_malloc0 (strlen (p) + 1); + while (*p) { + if (*p != '+' && *p != '-' && *p != '\'' && *p != '"') + *j++ = *p; + p++; + } + } + + if (!nm_setting_bond_add_option (s_bond, key, sanitized ? sanitized : value)) + PARSE_WARNING ("invalid bonding option '%s' = %s", + key, sanitized ? sanitized : value); + g_free (sanitized); +} + +static NMSetting * +make_bond_setting (shvarFile *ifcfg, + const char *file, + GError **error) +{ + NMSettingBond *s_bond; + char *value; + + s_bond = NM_SETTING_BOND (nm_setting_bond_new ()); + + value = svGetValueString (ifcfg, "DEVICE"); + if (!value || !strlen (value)) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "mandatory DEVICE keyword missing"); + goto error; + } + g_free (value); + + value = svGetValueString (ifcfg, "BONDING_OPTS"); + if (value) { + char **items, **iter; + + items = g_strsplit_set (value, " ", -1); + for (iter = items; iter && *iter; iter++) { + if (strlen (*iter)) { + char **keys, *key, *val; + + keys = g_strsplit_set (*iter, "=", 2); + if (keys && *keys) { + key = *keys; + val = *(keys + 1); + if (val && strlen(key) && strlen(val)) + handle_bond_option (s_bond, key, val); + } + + g_strfreev (keys); + } + } + g_free (value); + g_strfreev (items); + } + + return (NMSetting *) s_bond; + +error: + g_object_unref (s_bond); + return NULL; +} + +static NMConnection * +bond_connection_from_ifcfg (const char *file, + shvarFile *ifcfg, + GError **error) +{ + NMConnection *connection = NULL; + NMSetting *con_setting = NULL; + NMSetting *bond_setting = NULL; + NMSetting *wired_setting = NULL; + NMSetting8021x *s_8021x = NULL; + + g_return_val_if_fail (file != NULL, NULL); + g_return_val_if_fail (ifcfg != NULL, NULL); + + connection = nm_simple_connection_new (); + + con_setting = make_connection_setting (file, ifcfg, NM_SETTING_BOND_SETTING_NAME, NULL, _("Bond")); + if (!con_setting) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Failed to create connection setting."); + g_object_unref (connection); + return NULL; + } + nm_connection_add_setting (connection, con_setting); + + bond_setting = make_bond_setting (ifcfg, file, error); + if (!bond_setting) { + g_object_unref (connection); + return NULL; + } + nm_connection_add_setting (connection, bond_setting); + + wired_setting = make_wired_setting (ifcfg, file, &s_8021x, error); + if (!wired_setting) { + g_object_unref (connection); + return NULL; + } + nm_connection_add_setting (connection, wired_setting); + + if (s_8021x) + nm_connection_add_setting (connection, NM_SETTING (s_8021x)); + + return connection; +} + +/* Check 'error' for errors. Missing config (NULL return value) is a valid case. */ +static char * +read_team_config (shvarFile *ifcfg, const char *key, GError **error) +{ + gs_free_error GError *local_error = NULL; + gs_free char *value = NULL; + size_t l; + + value = svGetValueString (ifcfg, key); + if (!value) + return NULL; + + l = strlen (value); + if (l > 1*1024*1024) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "%s too long (size %zd)", key, l); + return NULL; + } + + if (!nm_utils_is_json_object (value, &local_error)) { + PARSE_WARNING ("ignoring invalid team configuration: %s", local_error->message); + return NULL; + } + + return g_steal_pointer (&value); +} + +static NMSetting * +make_team_setting (shvarFile *ifcfg, + const char *file, + GError **error) +{ + NMSettingTeam *s_team; + char *value; + GError *local_err = NULL; + + s_team = NM_SETTING_TEAM (nm_setting_team_new ()); + + value = svGetValueString (ifcfg, "DEVICE"); + if (!value || !strlen (value)) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "mandatory DEVICE keyword missing"); + goto error; + } + g_free (value); + + value = read_team_config (ifcfg, "TEAM_CONFIG", &local_err); + if (local_err) { + g_propagate_error (error, local_err); + goto error; + } + g_object_set (s_team, NM_SETTING_TEAM_CONFIG, value, NULL); + g_free (value); + + return (NMSetting *) s_team; + +error: + g_object_unref (s_team); + return NULL; +} + +static NMConnection * +team_connection_from_ifcfg (const char *file, + shvarFile *ifcfg, + GError **error) +{ + NMConnection *connection = NULL; + NMSetting *con_setting = NULL; + NMSetting *team_setting = NULL; + NMSetting *wired_setting = NULL; + NMSetting8021x *s_8021x = NULL; + + g_return_val_if_fail (file != NULL, NULL); + g_return_val_if_fail (ifcfg != NULL, NULL); + + connection = nm_simple_connection_new (); + + con_setting = make_connection_setting (file, ifcfg, NM_SETTING_TEAM_SETTING_NAME, NULL, _("Team")); + if (!con_setting) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Failed to create connection setting."); + g_object_unref (connection); + return NULL; + } + nm_connection_add_setting (connection, con_setting); + + team_setting = make_team_setting (ifcfg, file, error); + if (!team_setting) { + g_object_unref (connection); + return NULL; + } + nm_connection_add_setting (connection, team_setting); + + wired_setting = make_wired_setting (ifcfg, file, &s_8021x, error); + if (!wired_setting) { + g_object_unref (connection); + return NULL; + } + nm_connection_add_setting (connection, wired_setting); + + if (s_8021x) + nm_connection_add_setting (connection, NM_SETTING (s_8021x)); + + return connection; +} + +typedef void (*BridgeOptFunc) (NMSetting *setting, + gboolean stp, + const char *key, + const char *value); + +static void +handle_bridge_option (NMSetting *setting, + gboolean stp, + const char *key, + const char *value) +{ + guint32 u = 0; + + if (!strcmp (key, "priority")) { + if (stp == FALSE) { + PARSE_WARNING ("'priority' invalid when STP is disabled"); + } else if (get_uint (value, &u)) + g_object_set (setting, NM_SETTING_BRIDGE_PRIORITY, u, NULL); + else + PARSE_WARNING ("invalid priority value '%s'", value); + } else if (!strcmp (key, "hello_time")) { + if (stp == FALSE) { + PARSE_WARNING ("'hello_time' invalid when STP is disabled"); + } else if (get_uint (value, &u)) + g_object_set (setting, NM_SETTING_BRIDGE_HELLO_TIME, u, NULL); + else + PARSE_WARNING ("invalid hello_time value '%s'", value); + } else if (!strcmp (key, "max_age")) { + if (stp == FALSE) { + PARSE_WARNING ("'max_age' invalid when STP is disabled"); + } else if (get_uint (value, &u)) + g_object_set (setting, NM_SETTING_BRIDGE_MAX_AGE, u, NULL); + else + PARSE_WARNING ("invalid max_age value '%s'", value); + } else if (!strcmp (key, "ageing_time")) { + if (get_uint (value, &u)) + g_object_set (setting, NM_SETTING_BRIDGE_AGEING_TIME, u, NULL); + else + PARSE_WARNING ("invalid ageing_time value '%s'", value); + } else if (!strcmp (key, "multicast_snooping")) { + if (get_uint (value, &u)) + g_object_set (setting, NM_SETTING_BRIDGE_MULTICAST_SNOOPING, + (gboolean) u, NULL); + else + PARSE_WARNING ("invalid multicast_snooping value '%s'", value); + } else + PARSE_WARNING ("unhandled bridge option '%s'", key); +} + +static void +handle_bridging_opts (NMSetting *setting, + gboolean stp, + const char *value, + BridgeOptFunc func) +{ + char **items, **iter; + + items = g_strsplit_set (value, " ", -1); + for (iter = items; iter && *iter; iter++) { + if (strlen (*iter)) { + char **keys, *key, *val; + + keys = g_strsplit_set (*iter, "=", 2); + if (keys && *keys) { + key = *keys; + val = *(keys + 1); + if (val && strlen(key) && strlen(val)) + func (setting, stp, key, val); + } + + g_strfreev (keys); + } + } + g_strfreev (items); +} + +static NMSetting * +make_bridge_setting (shvarFile *ifcfg, + const char *file, + GError **error) +{ + NMSettingBridge *s_bridge; + char *value; + guint32 u; + gboolean stp = FALSE; + gboolean stp_set = FALSE; + + s_bridge = NM_SETTING_BRIDGE (nm_setting_bridge_new ()); + + value = svGetValueString (ifcfg, "DEVICE"); + if (!value || !strlen (value)) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "mandatory DEVICE keyword missing"); + goto error; + } + g_free (value); + + value = svGetValueString (ifcfg, "MACADDR"); + if (value) { + value = g_strstrip (value); + g_object_set (s_bridge, NM_SETTING_BRIDGE_MAC_ADDRESS, value, NULL); + g_free (value); + } + + value = svGetValueString (ifcfg, "STP"); + if (value) { + if (!strcasecmp (value, "on") || !strcasecmp (value, "yes")) { + g_object_set (s_bridge, NM_SETTING_BRIDGE_STP, TRUE, NULL); + stp = TRUE; + stp_set = TRUE; + } else if (!strcasecmp (value, "off") || !strcasecmp (value, "no")) { + g_object_set (s_bridge, NM_SETTING_BRIDGE_STP, FALSE, NULL); + stp_set = TRUE; + } else + PARSE_WARNING ("invalid STP value '%s'", value); + g_free (value); + } + + if (!stp_set) { + /* Missing or invalid STP property means "no" */ + g_object_set (s_bridge, NM_SETTING_BRIDGE_STP, FALSE, NULL); + } + + value = svGetValueString (ifcfg, "DELAY"); + if (value) { + if (stp) { + if (get_uint (value, &u)) + g_object_set (s_bridge, NM_SETTING_BRIDGE_FORWARD_DELAY, u, NULL); + else + PARSE_WARNING ("invalid forward delay value '%s'", value); + } else + PARSE_WARNING ("DELAY invalid when STP is disabled"); + g_free (value); + } + + value = svGetValueString (ifcfg, "BRIDGING_OPTS"); + if (value) { + handle_bridging_opts (NM_SETTING (s_bridge), stp, value, handle_bridge_option); + g_free (value); + } + + return (NMSetting *) s_bridge; + +error: + g_object_unref (s_bridge); + return NULL; +} + +static NMConnection * +bridge_connection_from_ifcfg (const char *file, + shvarFile *ifcfg, + GError **error) +{ + NMConnection *connection = NULL; + NMSetting *con_setting = NULL; + NMSetting *bridge_setting = NULL; + + g_return_val_if_fail (file != NULL, NULL); + g_return_val_if_fail (ifcfg != NULL, NULL); + + connection = nm_simple_connection_new (); + + con_setting = make_connection_setting (file, ifcfg, NM_SETTING_BRIDGE_SETTING_NAME, NULL, _("Bridge")); + if (!con_setting) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Failed to create connection setting."); + g_object_unref (connection); + return NULL; + } + nm_connection_add_setting (connection, con_setting); + + bridge_setting = make_bridge_setting (ifcfg, file, error); + if (!bridge_setting) { + g_object_unref (connection); + return NULL; + } + nm_connection_add_setting (connection, bridge_setting); + + return connection; +} + +static void +handle_bridge_port_option (NMSetting *setting, + gboolean stp, + const char *key, + const char *value) +{ + guint32 u = 0; + + if (!strcmp (key, "priority")) { + if (get_uint (value, &u)) + g_object_set (setting, NM_SETTING_BRIDGE_PORT_PRIORITY, u, NULL); + else + PARSE_WARNING ("invalid priority value '%s'", value); + } else if (!strcmp (key, "path_cost")) { + if (get_uint (value, &u)) + g_object_set (setting, NM_SETTING_BRIDGE_PORT_PATH_COST, u, NULL); + else + PARSE_WARNING ("invalid path_cost value '%s'", value); + } else if (!strcmp (key, "hairpin_mode")) { + if (!strcasecmp (value, "on") || !strcasecmp (value, "yes") || !strcmp (value, "1")) + g_object_set (setting, NM_SETTING_BRIDGE_PORT_HAIRPIN_MODE, TRUE, NULL); + else if (!strcasecmp (value, "off") || !strcasecmp (value, "no")) + g_object_set (setting, NM_SETTING_BRIDGE_PORT_HAIRPIN_MODE, FALSE, NULL); + else + PARSE_WARNING ("invalid hairpin_mode value '%s'", value); + } else + PARSE_WARNING ("unhandled bridge port option '%s'", key); +} + +static NMSetting * +make_bridge_port_setting (shvarFile *ifcfg) +{ + NMSetting *s_port = NULL; + char *value; + + g_return_val_if_fail (ifcfg != NULL, FALSE); + + value = svGetValueString (ifcfg, "BRIDGE_UUID"); + if (!value) + value = svGetValueString (ifcfg, "BRIDGE"); + if (value) { + g_free (value); + + s_port = nm_setting_bridge_port_new (); + value = svGetValueString (ifcfg, "BRIDGING_OPTS"); + if (value) + handle_bridging_opts (s_port, FALSE, value, handle_bridge_port_option); + g_free (value); + } + + return s_port; +} + +static NMSetting * +make_team_port_setting (shvarFile *ifcfg) +{ + NMSetting *s_port = NULL; + char *value; + GError *error = NULL; + + value = read_team_config (ifcfg, "TEAM_PORT_CONFIG", &error); + if (value) { + s_port = nm_setting_team_port_new (); + g_object_set (s_port, NM_SETTING_TEAM_PORT_CONFIG, value, NULL); + g_free (value); + } else if (error) { + PARSE_WARNING ("%s", error->message); + g_error_free (error); + } + + return s_port; +} + +static gboolean +is_bond_device (const char *name, shvarFile *parsed) +{ + g_return_val_if_fail (name != NULL, FALSE); + g_return_val_if_fail (parsed != NULL, FALSE); + + if (svGetValueBoolean (parsed, "BONDING_MASTER", FALSE)) + return TRUE; + + return FALSE; +} + +static gboolean +is_vlan_device (const char *name, shvarFile *parsed) +{ + g_return_val_if_fail (name != NULL, FALSE); + g_return_val_if_fail (parsed != NULL, FALSE); + + if (svGetValueBoolean (parsed, "VLAN", FALSE)) + return TRUE; + + return FALSE; +} + +static gboolean +is_wifi_device (const char *name, shvarFile *parsed) +{ + int ifindex; + + g_return_val_if_fail (name != NULL, FALSE); + g_return_val_if_fail (parsed != NULL, FALSE); + + ifindex = nm_platform_link_get_ifindex (NM_PLATFORM_GET, name); + if (ifindex == 0) + return FALSE; + + return nm_platform_link_get_type (NM_PLATFORM_GET, ifindex) == NM_LINK_TYPE_WIFI; +} + +static void +parse_prio_map_list (NMSettingVlan *s_vlan, + shvarFile *ifcfg, + const char *key, + NMVlanPriorityMap map) +{ + char *value; + gchar **list = NULL, **iter; + + value = svGetValueString (ifcfg, key); + if (!value) + return; + + list = g_strsplit_set (value, ",", -1); + g_free (value); + + for (iter = list; iter && *iter; iter++) { + if (!*iter || !strchr (*iter, ':')) + continue; + + if (!nm_setting_vlan_add_priority_str (s_vlan, map, *iter)) + PARSE_WARNING ("invalid %s priority map item '%s'", key, *iter); + } + g_strfreev (list); +} + +static NMSetting * +make_vlan_setting (shvarFile *ifcfg, + const char *file, + GError **error) +{ + NMSettingVlan *s_vlan = NULL; + char *value = NULL; + char *iface_name = NULL; + char *parent = NULL; + const char *p = NULL; + int vlan_id = -1; + guint32 vlan_flags = 0; + gint gvrp, reorder_hdr; + + value = svGetValueString (ifcfg, "VLAN_ID"); + if (value) { + vlan_id = _nm_utils_ascii_str_to_int64 (value, 10, 0, 4095, -1); + if (vlan_id == -1) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Invalid VLAN_ID '%s'", value); + g_free (value); + return NULL; + } + g_free (value); + } + + /* Need DEVICE if we don't have a separate VLAN_ID property */ + iface_name = svGetValueString (ifcfg, "DEVICE"); + if (!iface_name && vlan_id < 0) { + g_set_error_literal (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Missing DEVICE property; cannot determine VLAN ID."); + return NULL; + } + + s_vlan = NM_SETTING_VLAN (nm_setting_vlan_new ()); + + /* Parent interface from PHYSDEV takes precedence if it exists */ + parent = svGetValueString (ifcfg, "PHYSDEV"); + + if (iface_name) { + p = strchr (iface_name, '.'); + if (p) { + /* eth0.43; PHYSDEV is assumed from it if unknown */ + if (!parent) { + parent = g_strndup (iface_name, p - iface_name); + if (g_str_has_prefix (parent, "vlan")) { + /* Like initscripts, if no PHYSDEV and we get an obviously + * invalid parent interface from DEVICE, fail. + */ + g_free (parent); + parent = NULL; + } + } + p++; + } else { + /* format like vlan43; PHYSDEV must be set */ + if (g_str_has_prefix (iface_name, "vlan")) + p = iface_name + 4; + } + + if (p) { + int device_vlan_id; + + /* Grab VLAN ID from interface name; this takes precedence over the + * separate VLAN_ID property for backwards compat. + */ + device_vlan_id = _nm_utils_ascii_str_to_int64 (p, 10, 0, 4095, -1); + if (device_vlan_id != -1) + vlan_id = device_vlan_id; + } + } + + if (vlan_id < 0) { + g_set_error_literal (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Failed to determine VLAN ID from DEVICE or VLAN_ID."); + goto error; + } + g_object_set (s_vlan, NM_SETTING_VLAN_ID, vlan_id, NULL); + + if (parent == NULL) { + g_set_error_literal (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Failed to determine VLAN parent from DEVICE or PHYSDEV"); + goto error; + } + g_object_set (s_vlan, NM_SETTING_VLAN_PARENT, parent, NULL); + g_clear_pointer (&parent, g_free); + + vlan_flags |= NM_VLAN_FLAG_REORDER_HEADERS; + + gvrp = svGetValueBoolean (ifcfg, "GVRP", -1); + if (gvrp > 0) + vlan_flags |= NM_VLAN_FLAG_GVRP; + + value = svGetValueString (ifcfg, "VLAN_FLAGS"); + if (value) { + gs_strfreev char **strv = NULL; + char **ptr; + + strv = g_strsplit_set (value, ", ", 0); + + for (ptr = strv; ptr && *ptr; ptr++) { + if (nm_streq (*ptr, "GVRP") && gvrp == -1) + vlan_flags |= NM_VLAN_FLAG_GVRP; + if (nm_streq (*ptr, "LOOSE_BINDING")) + vlan_flags |= NM_VLAN_FLAG_LOOSE_BINDING; + if (nm_streq (*ptr, "NO_REORDER_HDR")) + vlan_flags &= ~NM_VLAN_FLAG_REORDER_HEADERS; + } + } + + reorder_hdr = svGetValueBoolean (ifcfg, "REORDER_HDR", -1); + if ( reorder_hdr != -1 + && reorder_hdr != NM_FLAGS_HAS (vlan_flags, NM_VLAN_FLAG_REORDER_HEADERS)) + PARSE_WARNING ("REORDER_HDR key is deprecated, use VLAN_FLAGS"); + + if (svGetValueBoolean (ifcfg, "MVRP", FALSE)) + vlan_flags |= NM_VLAN_FLAG_MVRP; + + g_object_set (s_vlan, NM_SETTING_VLAN_FLAGS, vlan_flags, NULL); + g_free (value); + + parse_prio_map_list (s_vlan, ifcfg, "VLAN_INGRESS_PRIORITY_MAP", NM_VLAN_INGRESS_MAP); + parse_prio_map_list (s_vlan, ifcfg, "VLAN_EGRESS_PRIORITY_MAP", NM_VLAN_EGRESS_MAP); + + g_free (iface_name); + + return (NMSetting *) s_vlan; + +error: + g_free (parent); + g_free (iface_name); + g_object_unref (s_vlan); + return NULL; +} + +static NMConnection * +vlan_connection_from_ifcfg (const char *file, + shvarFile *ifcfg, + GError **error) +{ + NMConnection *connection = NULL; + NMSetting *con_setting = NULL; + NMSetting *wired_setting = NULL; + NMSetting *vlan_setting = NULL; + NMSetting8021x *s_8021x = NULL; + + g_return_val_if_fail (file != NULL, NULL); + g_return_val_if_fail (ifcfg != NULL, NULL); + + connection = nm_simple_connection_new (); + + con_setting = make_connection_setting (file, ifcfg, NM_SETTING_VLAN_SETTING_NAME, NULL, "Vlan"); + if (!con_setting) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Failed to create connection setting."); + g_object_unref (connection); + return NULL; + } + check_if_slave (ifcfg, (NMSettingConnection *) con_setting); + nm_connection_add_setting (connection, con_setting); + + vlan_setting = make_vlan_setting (ifcfg, file, error); + if (!vlan_setting) { + g_object_unref (connection); + return NULL; + } + nm_connection_add_setting (connection, vlan_setting); + + wired_setting = make_wired_setting (ifcfg, file, &s_8021x, error); + if (!wired_setting) { + g_object_unref (connection); + return NULL; + } + nm_connection_add_setting (connection, wired_setting); + + if (s_8021x) + nm_connection_add_setting (connection, NM_SETTING (s_8021x)); + + return connection; +} + +static NMConnection * +create_unhandled_connection (const char *filename, shvarFile *ifcfg, + const char *type, char **out_spec) +{ + NMConnection *connection; + NMSetting *s_con; + char *value; + + nm_assert (out_spec && !*out_spec); + + connection = nm_simple_connection_new (); + + /* Get NAME, UUID, etc. We need to set a connection type (generic) and add + * an empty type-specific setting as well, to make sure it passes + * nm_connection_verify() later. + */ + s_con = make_connection_setting (filename, ifcfg, NM_SETTING_GENERIC_SETTING_NAME, + NULL, NULL); + nm_connection_add_setting (connection, s_con); + + nm_connection_add_setting (connection, nm_setting_generic_new ()); + + /* Get a spec */ + value = svGetValueString (ifcfg, "HWADDR"); + if (value) { + char *lower = g_ascii_strdown (value, -1); + *out_spec = g_strdup_printf ("%s:mac:%s", type, lower); + g_free (lower); + g_free (value); + return connection; + } + + value = svGetValueString (ifcfg, "SUBCHANNELS"); + if (value) { + *out_spec = g_strdup_printf ("%s:s390-subchannels:%s", type, value); + g_free (value); + return connection; + } + + value = svGetValueString (ifcfg, "DEVICE"); + if (value) { + *out_spec = g_strdup_printf ("%s:interface-name:%s", type, value); + g_free (value); + return connection; + } + + g_object_unref (connection); + return NULL; +} + +char * +uuid_from_file (const char *filename) +{ + const char *ifcfg_name = NULL; + shvarFile *ifcfg; + char *uuid; + + g_return_val_if_fail (filename != NULL, NULL); + + ifcfg_name = utils_get_ifcfg_name (filename, TRUE); + if (!ifcfg_name) + return NULL; + + ifcfg = svOpenFile (filename, NULL); + if (!ifcfg) + return NULL; + + /* Try for a UUID key before falling back to hashing the file name */ + uuid = svGetValueString (ifcfg, "UUID"); + if (!uuid || !strlen (uuid)) { + g_free (uuid); + uuid = nm_utils_uuid_generate_from_string (svFileGetName (ifcfg), -1, NM_UTILS_UUID_TYPE_LEGACY, NULL); + } + + svCloseFile (ifcfg); + return uuid; +} + +static void +check_dns_search_domains (shvarFile *ifcfg, NMSetting *s_ip4, NMSetting *s_ip6) +{ + if (!s_ip6) + return; + + /* If there is no IPv4 config or it doesn't contain DNS searches, + * read DOMAIN and put the domains into IPv6. + */ + if (!s_ip4 || nm_setting_ip_config_get_num_dns_searches (NM_SETTING_IP_CONFIG (s_ip4)) == 0) { + /* DNS searches */ + char *value = svGetValueString (ifcfg, "DOMAIN"); + if (value) { + char **searches = g_strsplit (value, " ", 0); + if (searches) { + char **item; + for (item = searches; *item; item++) { + if (strlen (*item)) { + if (!nm_setting_ip_config_add_dns_search (NM_SETTING_IP_CONFIG (s_ip6), *item)) + PARSE_WARNING ("duplicate DNS domain '%s'", *item); + } + } + g_strfreev (searches); + } + g_free (value); + } + } +} + +static NMConnection * +connection_from_file_full (const char *filename, + const char *network_file, /* for unit tests only */ + const char *test_type, /* for unit tests only */ + char **out_unhandled, + GError **error, + gboolean *out_ignore_error) +{ + NMConnection *connection = NULL; + shvarFile *parsed; + gs_free char *type = NULL; + char *devtype, *bootproto; + NMSetting *s_ip4, *s_ip6, *s_proxy, *s_port, *s_dcb = NULL; + const char *ifcfg_name = NULL; + + g_return_val_if_fail (filename != NULL, NULL); + g_return_val_if_fail (out_unhandled && !*out_unhandled, NULL); + + /* Non-NULL only for unit tests; normally use /etc/sysconfig/network */ + if (!network_file) + network_file = SYSCONFDIR "/sysconfig/network"; + + ifcfg_name = utils_get_ifcfg_name (filename, TRUE); + if (!ifcfg_name) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Ignoring connection '%s' because it's not an ifcfg file.", filename); + return NULL; + } + + parsed = svOpenFile (filename, error); + if (!parsed) + return NULL; + + if (!svGetValueBoolean (parsed, "NM_CONTROLLED", TRUE)) { + connection = create_unhandled_connection (filename, parsed, "unmanaged", out_unhandled); + if (!connection) + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, + "NM_CONTROLLED was false but device was not uniquely identified; device will be managed"); + goto done; + } + + /* iBFT is handled by the iBFT settings plugin */ + bootproto = svGetValueString (parsed, "BOOTPROTO"); + if (bootproto && !g_ascii_strcasecmp (bootproto, "ibft")) { + if (out_ignore_error) + *out_ignore_error = TRUE; + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Ignoring iBFT configuration"); + g_free (bootproto); + goto done; + } + g_free (bootproto); + + devtype = svGetValueString (parsed, "DEVICETYPE"); + if (devtype) { + if (!strcasecmp (devtype, TYPE_TEAM)) + type = g_strdup (TYPE_TEAM); + else if (!strcasecmp (devtype, TYPE_TEAM_PORT)) + type = g_strdup (TYPE_ETHERNET); + g_free (devtype); + } + if (!type) { + gs_free char *t = NULL; + + /* Team and TeamPort types are also accepted by the mere + * presense of TEAM_CONFIG/TEAM_MASTER. They don't require + * DEVICETYPE. */ + t = svGetValueString (parsed, "TEAM_CONFIG"); + if (t) + type = g_strdup (TYPE_TEAM); + } + + if (!type) + type = svGetValueString (parsed, "TYPE"); + + if (!type) { + gs_free char *tmp = NULL; + char *device; + + if ((tmp = svGetValueString (parsed, "IPV6TUNNELIPV4"))) { + if (out_ignore_error) + *out_ignore_error = TRUE; + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Ignoring unsupported connection due to IPV6TUNNELIPV4"); + goto done; + } + + device = svGetValueString (parsed, "DEVICE"); + if (!device) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "File '%s' had neither TYPE nor DEVICE keys.", filename); + goto done; + } + g_assert (device[0]); + + if (!strcmp (device, "lo")) { + if (out_ignore_error) + *out_ignore_error = TRUE; + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Ignoring loopback device config."); + g_free (device); + goto done; + } + + if (!test_type) { + if (is_bond_device (device, parsed)) + type = g_strdup (TYPE_BOND); + else if (is_vlan_device (device, parsed)) + type = g_strdup (TYPE_VLAN); + else if (is_wifi_device (device, parsed)) + type = g_strdup (TYPE_WIRELESS); + else { + gs_free char *p_path = NULL; + char *p_device; + gsize i; + + /* network-functions detects DEVICETYPE based on the ifcfg-* name and the existence + * of a ifup script: + * [ -z "$DEVICETYPE" ] && DEVICETYPE=$(echo ${DEVICE} | sed "s/[0-9]*$//") + * later... + * OTHERSCRIPT="/etc/sysconfig/network-scripts/ifup-${DEVICETYPE}" + * */ +#define IFUP_PATH_PREFIX "/etc/sysconfig/network-scripts/ifup-" + i = strlen (device); + p_path = g_malloc (NM_STRLEN (IFUP_PATH_PREFIX) + i + 1); + p_device = &p_path[NM_STRLEN (IFUP_PATH_PREFIX)]; + memcpy (p_device, device, i + 1); + + /* strip trailing numbers */ + while (i >= 1) { + i--; + if (p_device[i] < '0' || p_device[i] > '9') + break; + p_device[i] = '\0'; + } + + if (nm_streq (p_device, "eth")) + type = g_strdup (TYPE_ETHERNET); + else if (nm_streq (p_device, "wireless")) + type = g_strdup (TYPE_WIRELESS); + else if (p_device[0]) { + memcpy (p_path, IFUP_PATH_PREFIX, NM_STRLEN (IFUP_PATH_PREFIX)); + if (access (p_path, X_OK) == 0) { + /* for all other types, this is not something we want to handle. */ + if (out_ignore_error) + *out_ignore_error = TRUE; + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Ignore script for unknown device type which has a matching %s script", + p_path); + goto done; + } + } + + if (!type) + type = g_strdup (TYPE_ETHERNET); + } + } else { + /* For the unit tests, there won't necessarily be any + * adapters of the connection's type in the system so the + * type can't be tested with ioctls. + */ + type = g_strdup (test_type); + } + + g_free (device); + } else { + /* Check for IBM s390 CTC devices and call them Ethernet */ + if (g_strcmp0 (type, "CTC") == 0) { + g_free (type); + type = g_strdup (TYPE_ETHERNET); + } + } + + if (svGetValueBoolean (parsed, "BONDING_MASTER", FALSE) && + strcasecmp (type, TYPE_BOND)) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "BONDING_MASTER=yes key only allowed in TYPE=bond connections"); + goto done; + } + + /* Construct the connection */ + if (!strcasecmp (type, TYPE_ETHERNET)) + connection = wired_connection_from_ifcfg (filename, parsed, error); + else if (!strcasecmp (type, TYPE_WIRELESS)) + connection = wireless_connection_from_ifcfg (filename, parsed, error); + else if (!strcasecmp (type, TYPE_INFINIBAND)) + connection = infiniband_connection_from_ifcfg (filename, parsed, error); + else if (!strcasecmp (type, TYPE_BOND)) + connection = bond_connection_from_ifcfg (filename, parsed, error); + else if (!strcasecmp (type, TYPE_TEAM)) + connection = team_connection_from_ifcfg (filename, parsed, error); + else if (!strcasecmp (type, TYPE_VLAN)) + connection = vlan_connection_from_ifcfg (filename, parsed, error); + else if (!strcasecmp (type, TYPE_BRIDGE)) + connection = bridge_connection_from_ifcfg (filename, parsed, error); + else { + connection = create_unhandled_connection (filename, parsed, "unrecognized", out_unhandled); + if (!connection) + PARSE_WARNING ("connection type was unrecognized but device was not uniquely identified; device may be managed"); + goto done; + } + + if (!connection) + goto done; + + s_ip6 = make_ip6_setting (parsed, network_file, error); + if (!s_ip6) { + g_object_unref (connection); + connection = NULL; + goto done; + } else + nm_connection_add_setting (connection, s_ip6); + + s_ip4 = make_ip4_setting (parsed, network_file, error); + if (!s_ip4) { + g_object_unref (connection); + connection = NULL; + goto done; + } else { + read_aliases (NM_SETTING_IP_CONFIG (s_ip4), filename); + nm_connection_add_setting (connection, s_ip4); + } + + /* There is only one DOMAIN variable and it is read and put to IPv4 config + * But if IPv4 is disabled or the config fails for some reason, we read + * DOMAIN and put the values into IPv6 config instead. + */ + check_dns_search_domains (parsed, s_ip4, s_ip6); + + s_proxy = make_proxy_setting (parsed, error); + if (s_proxy) + nm_connection_add_setting (connection, s_proxy); + + /* Bridge port? */ + s_port = make_bridge_port_setting (parsed); + if (s_port) + nm_connection_add_setting (connection, s_port); + + /* Team port? */ + s_port = make_team_port_setting (parsed); + if (s_port) + nm_connection_add_setting (connection, s_port); + + if (!make_dcb_setting (parsed, network_file, &s_dcb, error)) { + g_object_unref (connection); + connection = NULL; + goto done; + } + if (s_dcb) + nm_connection_add_setting (connection, s_dcb); + + if (!nm_connection_normalize (connection, NULL, NULL, error)) { + g_object_unref (connection); + connection = NULL; + } + +done: + svCloseFile (parsed); + return connection; +} + +NMConnection * +connection_from_file (const char *filename, + char **out_unhandled, + GError **error, + gboolean *out_ignore_error) +{ + return connection_from_file_full (filename, NULL, NULL, + out_unhandled, + error, + out_ignore_error); +} + +NMConnection * +connection_from_file_test (const char *filename, + const char *network_file, + const char *test_type, + char **out_unhandled, + GError **error) +{ + return connection_from_file_full (filename, + network_file, + test_type, + out_unhandled, + error, + NULL); +} + +guint +devtimeout_from_file (const char *filename) +{ + shvarFile *ifcfg; + char *devtimeout_str; + guint devtimeout; + + g_return_val_if_fail (filename != NULL, 0); + + ifcfg = svOpenFile (filename, NULL); + if (!ifcfg) + return 0; + + devtimeout_str = svGetValueString (ifcfg, "DEVTIMEOUT"); + if (devtimeout_str) { + devtimeout = _nm_utils_ascii_str_to_int64 (devtimeout_str, 10, 0, G_MAXUINT, 0); + g_free (devtimeout_str); + } else + devtimeout = 0; + + svCloseFile (ifcfg); + + return devtimeout; +} diff --git a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.h b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.h new file mode 100644 index 00000000..35464474 --- /dev/null +++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.h @@ -0,0 +1,42 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/* NetworkManager system settings service + * + * 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 Red Hat, Inc. + */ + +#ifndef __READER_H__ +#define __READER_H__ + +#include "nm-connection.h" + +NMConnection *connection_from_file (const char *filename, + char **out_unhandled, + GError **error, + gboolean *out_ignore_error); + +char *uuid_from_file (const char *filename); + +guint devtimeout_from_file (const char *filename); + +/* for test-ifcfg-rh */ +NMConnection *connection_from_file_test (const char *filename, + const char *network_file, + const char *test_type, + char **out_unhandled, + GError **error); + +#endif /* __READER_H__ */ diff --git a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.c b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.c new file mode 100644 index 00000000..d1c00976 --- /dev/null +++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.c @@ -0,0 +1,365 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/* NetworkManager system settings service + * + * 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 - 2012 Red Hat, Inc. + */ + +#include "nm-default.h" + +#include "nms-ifcfg-rh-utils.h" + +#include +#include + +#include "nm-core-internal.h" +#include "NetworkManagerUtils.h" + +#include "nms-ifcfg-rh-common.h" + +/* + * Check ';[a-fA-F0-9]{8}' file suffix used for temporary files by rpm when + * installing packages. + * + * Implementation taken from upstart. + */ +static gboolean +check_rpm_temp_suffix (const char *path) +{ + const char *ptr; + + g_return_val_if_fail (path != NULL, FALSE); + + /* Matches *;[a-fA-F0-9]{8}; used by rpm */ + ptr = strrchr (path, ';'); + if (ptr && (strspn (ptr + 1, "abcdefABCDEF0123456789") == 8) + && (! ptr[9])) + return TRUE; + return FALSE; +} + +static gboolean +check_suffix (const char *base, const char *tag) +{ + int len, tag_len; + + g_return_val_if_fail (base != NULL, TRUE); + g_return_val_if_fail (tag != NULL, TRUE); + + len = strlen (base); + tag_len = strlen (tag); + if ((len > tag_len) && !strcasecmp (base + len - tag_len, tag)) + return TRUE; + return FALSE; +} + +gboolean +utils_should_ignore_file (const char *filename, gboolean only_ifcfg) +{ + gs_free char *base = NULL; + + g_return_val_if_fail (filename != NULL, TRUE); + + base = g_path_get_basename (filename); + + /* Only handle ifcfg, keys, and routes files */ + if (strncmp (base, IFCFG_TAG, strlen (IFCFG_TAG)) != 0) { + if (only_ifcfg) + return TRUE; + else if ( strncmp (base, KEYS_TAG, strlen (KEYS_TAG)) != 0 + && strncmp (base, ROUTE_TAG, strlen (ROUTE_TAG)) != 0 + && strncmp (base, ROUTE6_TAG, strlen (ROUTE6_TAG)) != 0) + return TRUE; + } + + /* But not those that have certain suffixes */ + if ( check_suffix (base, BAK_TAG) + || check_suffix (base, TILDE_TAG) + || check_suffix (base, ORIG_TAG) + || check_suffix (base, REJ_TAG) + || check_suffix (base, RPMNEW_TAG) + || check_suffix (base, AUGNEW_TAG) + || check_suffix (base, AUGTMP_TAG) + || check_rpm_temp_suffix (base)) + return TRUE; + + return FALSE; +} + +char * +utils_cert_path (const char *parent, const char *suffix) +{ + const char *name; + char *dir, *path; + + g_return_val_if_fail (parent != NULL, NULL); + g_return_val_if_fail (suffix != NULL, NULL); + + name = utils_get_ifcfg_name (parent, FALSE); + dir = g_path_get_dirname (parent); + path = g_strdup_printf ("%s/%s-%s", dir, name, suffix); + g_free (dir); + return path; +} + +const char * +utils_get_ifcfg_name (const char *file, gboolean only_ifcfg) +{ + const char *name; + + g_return_val_if_fail (file != NULL, NULL); + + name = strrchr (file, '/'); + if (!name) + name = file; + else + name++; + if (!*name) + return NULL; + +#define MATCH_TAG_AND_RETURN(name, TAG) \ + G_STMT_START { \ + if (strncmp (name, TAG, NM_STRLEN (TAG)) == 0) { \ + name += NM_STRLEN (TAG); \ + if (name[0] == '\0') \ + return NULL; \ + else \ + return name; \ + } \ + } G_STMT_END + + /* Do not detect alias files and return 'eth0:0' instead of 'eth0'. + * Unfortunately, we cannot be sure that our files don't contain colons, + * so we cannot reject files with colons. + * + * Instead, you must not call utils_get_ifcfg_name() with an alias file + * or files that are ignored. */ + MATCH_TAG_AND_RETURN (name, IFCFG_TAG); + if (!only_ifcfg) { + MATCH_TAG_AND_RETURN (name, KEYS_TAG); + MATCH_TAG_AND_RETURN (name, ROUTE_TAG); + MATCH_TAG_AND_RETURN (name, ROUTE6_TAG); + } + + return NULL; +} + +/* Used to get any ifcfg/extra file path from any other ifcfg/extra path + * in the form . + */ +static char * +utils_get_extra_path (const char *parent, const char *tag) +{ + char *item_path = NULL, *dirname; + const char *name; + + g_return_val_if_fail (parent != NULL, NULL); + g_return_val_if_fail (tag != NULL, NULL); + + dirname = g_path_get_dirname (parent); + if (!dirname) + return NULL; + + name = utils_get_ifcfg_name (parent, FALSE); + if (name) { + if (!strcmp (dirname, ".")) + item_path = g_strdup_printf ("%s%s", tag, name); + else + item_path = g_strdup_printf ("%s/%s%s", dirname, tag, name); + } + g_free (dirname); + + return item_path; +} + +char * +utils_get_ifcfg_path (const char *parent) +{ + return utils_get_extra_path (parent, IFCFG_TAG); +} + +char * +utils_get_keys_path (const char *parent) +{ + return utils_get_extra_path (parent, KEYS_TAG); +} + +char * +utils_get_route_path (const char *parent) +{ + return utils_get_extra_path (parent, ROUTE_TAG); +} + +char * +utils_get_route6_path (const char *parent) +{ + return utils_get_extra_path (parent, ROUTE6_TAG); +} + +shvarFile * +utils_get_extra_ifcfg (const char *parent, const char *tag, gboolean should_create) +{ + shvarFile *ifcfg = NULL; + char *path; + + path = utils_get_extra_path (parent, tag); + if (!path) + return NULL; + + if (should_create && !g_file_test (path, G_FILE_TEST_EXISTS)) + ifcfg = svCreateFile (path); + + if (!ifcfg) + ifcfg = svOpenFile (path, NULL); + + g_free (path); + return ifcfg; +} + +shvarFile * +utils_get_keys_ifcfg (const char *parent, gboolean should_create) +{ + return utils_get_extra_ifcfg (parent, KEYS_TAG, should_create); +} + +shvarFile * +utils_get_route_ifcfg (const char *parent, gboolean should_create) +{ + return utils_get_extra_ifcfg (parent, ROUTE_TAG, should_create); +} + +shvarFile * +utils_get_route6_ifcfg (const char *parent, gboolean should_create) +{ + return utils_get_extra_ifcfg (parent, ROUTE6_TAG, should_create); +} + +/* Finds out if route file has new or older format + * Returns TRUE - new syntax (ADDRESS=a.b.c.d ...), error opening file or empty + * FALSE - older syntax, i.e. argument to 'ip route add' (1.2.3.0/24 via 11.22.33.44) + */ +gboolean +utils_has_route_file_new_syntax (const char *filename) +{ + char *contents = NULL; + gsize len = 0; + gboolean ret = FALSE; + const char *pattern = "^[[:space:]]*ADDRESS[0-9]+="; + + g_return_val_if_fail (filename != NULL, TRUE); + + if (!g_file_get_contents (filename, &contents, &len, NULL)) + return TRUE; + + if (len <= 0) { + ret = TRUE; + goto gone; + } + + if (g_regex_match_simple (pattern, contents, G_REGEX_MULTILINE, 0)) + ret = TRUE; + +gone: + g_free (contents); + return ret; +} + +gboolean +utils_has_complex_routes (const char *filename) +{ + char *rules; + + g_return_val_if_fail (filename != NULL, TRUE); + + rules = utils_get_extra_path (filename, RULE_TAG); + if (g_file_test (rules, G_FILE_TEST_EXISTS)) { + g_free (rules); + return TRUE; + } + g_free (rules); + + rules = utils_get_extra_path (filename, RULE6_TAG); + if (g_file_test (rules, G_FILE_TEST_EXISTS)) { + g_free (rules); + return TRUE; + } + g_free (rules); + + return FALSE; +} + +/* Find out if the 'alias' file name might be an alias file for 'ifcfg' file name, + * or any alias when 'ifcfg' is NULL. Does not check that it's actually a valid + * alias name; that happens in reader.c + */ +gboolean +utils_is_ifcfg_alias_file (const char *alias, const char *ifcfg) +{ + g_return_val_if_fail (alias != NULL, FALSE); + + if (strncmp (alias, IFCFG_TAG, strlen (IFCFG_TAG))) + return FALSE; + + if (ifcfg) { + size_t len = strlen (ifcfg); + + return (strncmp (alias, ifcfg, len) == 0 && alias[len] == ':'); + } else { + return (strchr (alias, ':') != NULL); + } +} + +char * +utils_detect_ifcfg_path (const char *path, gboolean only_ifcfg) +{ + gs_free char *base = NULL; + char *ptr, *ifcfg = NULL; + + g_return_val_if_fail (path != NULL, NULL); + + if (utils_should_ignore_file (path, only_ifcfg)) + return NULL; + + base = g_path_get_basename (path); + + if (strncmp (base, IFCFG_TAG, NM_STRLEN (IFCFG_TAG)) == 0) { + if (base[NM_STRLEN (IFCFG_TAG)] == '\0') + return NULL; + if (utils_is_ifcfg_alias_file (base, NULL)) { + ifcfg = g_strdup (path); + ptr = strrchr (ifcfg, ':'); + if (ptr && ptr > ifcfg) { + *ptr = '\0'; + if (g_file_test (ifcfg, G_FILE_TEST_EXISTS)) { + /* the file has a colon, so it is probably an alias. + * To be ~more~ certain that this is an alias file, + * check whether a corresponding base file exists. */ + if (only_ifcfg) { + g_free (ifcfg); + return NULL; + } + return ifcfg; + } + } + g_free (ifcfg); + } + return g_strdup (path); + } + + if (only_ifcfg) + return NULL; + return utils_get_ifcfg_path (path); +} diff --git a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.h b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.h new file mode 100644 index 00000000..af0469e6 --- /dev/null +++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.h @@ -0,0 +1,58 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/* NetworkManager system settings service + * + * 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 - 2012 Red Hat, Inc. + */ + +#ifndef _UTILS_H_ +#define _UTILS_H_ + +#include "nm-connection.h" + +#include "shvar.h" + +#define NM_IFCFG_CONNECTION_LOG_PATH(path) ((path) ?: "in-memory") +#define NM_IFCFG_CONNECTION_LOG_FMT "%s (%s,\"%s\")" +#define NM_IFCFG_CONNECTION_LOG_ARG(con) NM_IFCFG_CONNECTION_LOG_PATH (nm_settings_connection_get_filename ((NMSettingsConnection *) (con))), nm_connection_get_uuid ((NMConnection *) (con)), nm_connection_get_id ((NMConnection *) (con)) +#define NM_IFCFG_CONNECTION_LOG_FMTD "%s (%s,\"%s\",%p)" +#define NM_IFCFG_CONNECTION_LOG_ARGD(con) NM_IFCFG_CONNECTION_LOG_PATH (nm_settings_connection_get_filename ((NMSettingsConnection *) (con))), nm_connection_get_uuid ((NMConnection *) (con)), nm_connection_get_id ((NMConnection *) (con)), (con) + +char *utils_cert_path (const char *parent, const char *suffix); + +const char *utils_get_ifcfg_name (const char *file, gboolean only_ifcfg); + +gboolean utils_should_ignore_file (const char *filename, gboolean only_ifcfg); + +char *utils_get_ifcfg_path (const char *parent); +char *utils_get_keys_path (const char *parent); +char *utils_get_route_path (const char *parent); +char *utils_get_route6_path (const char *parent); + +shvarFile *utils_get_extra_ifcfg (const char *parent, const char *tag, gboolean should_create); +shvarFile *utils_get_keys_ifcfg (const char *parent, gboolean should_create); +shvarFile *utils_get_route_ifcfg (const char *parent, gboolean should_create); +shvarFile *utils_get_route6_ifcfg (const char *parent, gboolean should_create); + +gboolean utils_has_route_file_new_syntax (const char *filename); +gboolean utils_has_complex_routes (const char *filename); + +gboolean utils_is_ifcfg_alias_file (const char *alias, const char *ifcfg); + +char *utils_detect_ifcfg_path (const char *path, gboolean only_ifcfg); + +#endif /* _UTILS_H_ */ + diff --git a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c new file mode 100644 index 00000000..90a8e7ac --- /dev/null +++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c @@ -0,0 +1,2965 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/* NetworkManager system settings service - keyfile plugin + * + * 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 2009 - 2015 Red Hat, Inc. + */ + +#include "nm-default.h" + +#include "nms-ifcfg-rh-writer.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "nm-manager.h" +#include "nm-setting-connection.h" +#include "nm-setting-wired.h" +#include "nm-setting-wireless.h" +#include "nm-setting-8021x.h" +#include "nm-setting-proxy.h" +#include "nm-setting-ip4-config.h" +#include "nm-setting-ip6-config.h" +#include "nm-setting-pppoe.h" +#include "nm-setting-vlan.h" +#include "nm-setting-team.h" +#include "nm-setting-team-port.h" +#include "nm-utils.h" +#include "nm-core-internal.h" +#include "NetworkManagerUtils.h" + +#include "nms-ifcfg-rh-common.h" +#include "nms-ifcfg-rh-reader.h" +#include "nms-ifcfg-rh-utils.h" +#include "shvar.h" + +/*****************************************************************************/ + +#define _NMLOG_DOMAIN LOGD_SETTINGS +#define _NMLOG_PREFIX_NAME "ifcfg-rh" +#define _NMLOG(level, ...) \ + G_STMT_START { \ + nm_log ((level), (_NMLOG_DOMAIN), \ + "%s" _NM_UTILS_MACRO_FIRST(__VA_ARGS__), \ + _NMLOG_PREFIX_NAME": " \ + _NM_UTILS_MACRO_REST(__VA_ARGS__)); \ + } G_STMT_END + +/*****************************************************************************/ + +static void +save_secret_flags (shvarFile *ifcfg, + const char *key, + NMSettingSecretFlags flags) +{ + GString *str; + + g_return_if_fail (ifcfg != NULL); + g_return_if_fail (key != NULL); + + if (flags == NM_SETTING_SECRET_FLAG_NONE) { + svUnsetValue (ifcfg, key); + return; + } + + /* Convert flags bitfield into string representation */ + str = g_string_sized_new (20); + if (flags & NM_SETTING_SECRET_FLAG_AGENT_OWNED) + g_string_append (str, SECRET_FLAG_AGENT); + + if (flags & NM_SETTING_SECRET_FLAG_NOT_SAVED) { + if (str->len) + g_string_append_c (str, ' '); + g_string_append (str, SECRET_FLAG_NOT_SAVED); + } + + if (flags & NM_SETTING_SECRET_FLAG_NOT_REQUIRED) { + if (str->len) + g_string_append_c (str, ' '); + g_string_append (str, SECRET_FLAG_NOT_REQUIRED); + } + + svSetValueString (ifcfg, key, str->len ? str->str : NULL); + g_string_free (str, TRUE); +} + +static void +set_secret (shvarFile *ifcfg, + const char *key, + const char *value, + const char *flags_key, + NMSettingSecretFlags flags) +{ + shvarFile *keyfile; + GError *error = NULL; + + /* Clear the secret from the ifcfg and the associated "keys" file */ + svUnsetValue (ifcfg, key); + + /* Save secret flags */ + save_secret_flags (ifcfg, flags_key, flags); + + keyfile = utils_get_keys_ifcfg (svFileGetName (ifcfg), TRUE); + if (!keyfile) { + _LOGW ("could not create ifcfg file for '%s'", svFileGetName (ifcfg)); + goto error; + } + + /* Only write the secret if it's system owned and supposed to be saved */ + if (flags == NM_SETTING_SECRET_FLAG_NONE) + svSetValueString (keyfile, key, value); + else + svUnsetValue (keyfile, key); + + if (!svWriteFile (keyfile, 0600, &error)) { + _LOGW ("could not update ifcfg file '%s': %s", + svFileGetName (keyfile), error->message); + g_clear_error (&error); + svCloseFile (keyfile); + goto error; + } + svCloseFile (keyfile); + return; + +error: + /* Try setting the secret in the actual ifcfg */ + svSetValueString (ifcfg, key, value); +} + +typedef struct ObjectType { + const char *setting_key; + NMSetting8021xCKScheme (*scheme_func)(NMSetting8021x *setting); + const char * (*path_func) (NMSetting8021x *setting); + GBytes * (*blob_func) (NMSetting8021x *setting); + const char *ifcfg_key; + const char *suffix; +} ObjectType; + +static const ObjectType ca_type = { + NM_SETTING_802_1X_CA_CERT, + nm_setting_802_1x_get_ca_cert_scheme, + nm_setting_802_1x_get_ca_cert_path, + nm_setting_802_1x_get_ca_cert_blob, + "IEEE_8021X_CA_CERT", + "ca-cert.der" +}; + +static const ObjectType phase2_ca_type = { + NM_SETTING_802_1X_PHASE2_CA_CERT, + nm_setting_802_1x_get_phase2_ca_cert_scheme, + nm_setting_802_1x_get_phase2_ca_cert_path, + nm_setting_802_1x_get_phase2_ca_cert_blob, + "IEEE_8021X_INNER_CA_CERT", + "inner-ca-cert.der" +}; + +static const ObjectType client_type = { + NM_SETTING_802_1X_CLIENT_CERT, + nm_setting_802_1x_get_client_cert_scheme, + nm_setting_802_1x_get_client_cert_path, + nm_setting_802_1x_get_client_cert_blob, + "IEEE_8021X_CLIENT_CERT", + "client-cert.der" +}; + +static const ObjectType phase2_client_type = { + NM_SETTING_802_1X_PHASE2_CLIENT_CERT, + nm_setting_802_1x_get_phase2_client_cert_scheme, + nm_setting_802_1x_get_phase2_client_cert_path, + nm_setting_802_1x_get_phase2_client_cert_blob, + "IEEE_8021X_INNER_CLIENT_CERT", + "inner-client-cert.der" +}; + +static const ObjectType pk_type = { + NM_SETTING_802_1X_PRIVATE_KEY, + nm_setting_802_1x_get_private_key_scheme, + nm_setting_802_1x_get_private_key_path, + nm_setting_802_1x_get_private_key_blob, + "IEEE_8021X_PRIVATE_KEY", + "private-key.pem" +}; + +static const ObjectType phase2_pk_type = { + NM_SETTING_802_1X_PHASE2_PRIVATE_KEY, + nm_setting_802_1x_get_phase2_private_key_scheme, + nm_setting_802_1x_get_phase2_private_key_path, + nm_setting_802_1x_get_phase2_private_key_blob, + "IEEE_8021X_INNER_PRIVATE_KEY", + "inner-private-key.pem" +}; + +static const ObjectType p12_type = { + NM_SETTING_802_1X_PRIVATE_KEY, + nm_setting_802_1x_get_private_key_scheme, + nm_setting_802_1x_get_private_key_path, + nm_setting_802_1x_get_private_key_blob, + "IEEE_8021X_PRIVATE_KEY", + "private-key.p12" +}; + +static const ObjectType phase2_p12_type = { + NM_SETTING_802_1X_PHASE2_PRIVATE_KEY, + nm_setting_802_1x_get_phase2_private_key_scheme, + nm_setting_802_1x_get_phase2_private_key_path, + nm_setting_802_1x_get_phase2_private_key_blob, + "IEEE_8021X_INNER_PRIVATE_KEY", + "inner-private-key.p12" +}; + +static gboolean +write_object (NMSetting8021x *s_8021x, + shvarFile *ifcfg, + const ObjectType *objtype, + GError **error) +{ + NMSetting8021xCKScheme scheme; + const char *path = NULL; + GBytes *blob = NULL; + + g_return_val_if_fail (ifcfg != NULL, FALSE); + g_return_val_if_fail (objtype != NULL, FALSE); + + scheme = (*(objtype->scheme_func))(s_8021x); + switch (scheme) { + case NM_SETTING_802_1X_CK_SCHEME_UNKNOWN: + break; + case NM_SETTING_802_1X_CK_SCHEME_BLOB: + blob = (*(objtype->blob_func))(s_8021x); + break; + case NM_SETTING_802_1X_CK_SCHEME_PATH: + path = (*(objtype->path_func))(s_8021x); + break; + default: + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, + "Unhandled certificate object scheme"); + return FALSE; + } + + /* If certificate/private key wasn't sent, the connection may no longer be + * 802.1x and thus we clear out the paths and certs. + */ + if (!path && !blob) { + char *standard_file; + int ignored; + + /* Since no cert/private key is now being used, delete any standard file + * that was created for this connection, but leave other files alone. + * Thus, for example, + * /etc/sysconfig/network-scripts/ca-cert-Test_Write_Wifi_WPA_EAP-TLS.der + * will be deleted, but /etc/pki/tls/cert.pem will not. + */ + standard_file = utils_cert_path (svFileGetName (ifcfg), objtype->suffix); + if (g_file_test (standard_file, G_FILE_TEST_EXISTS)) + ignored = unlink (standard_file); + g_free (standard_file); + + svUnsetValue (ifcfg, objtype->ifcfg_key); + return TRUE; + } + + /* If the object path was specified, prefer that over any raw cert data that + * may have been sent. + */ + if (path) { + svSetValueString (ifcfg, objtype->ifcfg_key, path); + return TRUE; + } + + /* If it's raw certificate data, write the data out to the standard file */ + if (blob) { + gboolean success; + char *new_file; + GError *write_error = NULL; + + new_file = utils_cert_path (svFileGetName (ifcfg), objtype->suffix); + if (!new_file) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, + "Could not create file path for %s / %s", + NM_SETTING_802_1X_SETTING_NAME, objtype->setting_key); + return FALSE; + } + + /* Write the raw certificate data out to the standard file so that we + * can use paths from now on instead of pushing around the certificate + * data itself. + */ + success = nm_utils_file_set_contents (new_file, + (const char *) g_bytes_get_data (blob, NULL), + g_bytes_get_size (blob), + 0600, + &write_error); + if (success) { + svSetValueString (ifcfg, objtype->ifcfg_key, new_file); + g_free (new_file); + return TRUE; + } else { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, + "Could not write certificate/key for %s / %s: %s", + NM_SETTING_802_1X_SETTING_NAME, objtype->setting_key, + (write_error && write_error->message) ? write_error->message : "(unknown)"); + g_clear_error (&write_error); + } + g_free (new_file); + } + + return FALSE; +} + +static gboolean +write_8021x_certs (NMSetting8021x *s_8021x, + gboolean phase2, + shvarFile *ifcfg, + GError **error) +{ + const char *password = NULL; + gboolean success = FALSE, is_pkcs12 = FALSE; + const ObjectType *otype = NULL; + NMSettingSecretFlags flags = NM_SETTING_SECRET_FLAG_NONE; + + /* CA certificate */ + if (!write_object (s_8021x, ifcfg, phase2 ? &phase2_ca_type : &ca_type, error)) + return FALSE; + + /* Private key */ + if (phase2) { + otype = &phase2_pk_type; + if (nm_setting_802_1x_get_phase2_private_key_format (s_8021x) == NM_SETTING_802_1X_CK_FORMAT_PKCS12) { + otype = &phase2_p12_type; + is_pkcs12 = TRUE; + } + password = nm_setting_802_1x_get_phase2_private_key_password (s_8021x); + flags = nm_setting_802_1x_get_phase2_private_key_password_flags (s_8021x); + } else { + otype = &pk_type; + if (nm_setting_802_1x_get_private_key_format (s_8021x) == NM_SETTING_802_1X_CK_FORMAT_PKCS12) { + otype = &p12_type; + is_pkcs12 = TRUE; + } + password = nm_setting_802_1x_get_private_key_password (s_8021x); + flags = nm_setting_802_1x_get_private_key_password_flags (s_8021x); + } + + /* Save the private key */ + if (!write_object (s_8021x, ifcfg, otype, error)) + goto out; + + /* Private key password */ + if (phase2) { + set_secret (ifcfg, + "IEEE_8021X_INNER_PRIVATE_KEY_PASSWORD", + password, + "IEEE_8021X_INNER_PRIVATE_KEY_PASSWORD_FLAGS", + flags); + } else { + set_secret (ifcfg, + "IEEE_8021X_PRIVATE_KEY_PASSWORD", + password, + "IEEE_8021X_PRIVATE_KEY_PASSWORD_FLAGS", + flags); + } + + /* Client certificate */ + if (is_pkcs12) { + /* Don't need a client certificate with PKCS#12 since the file is both + * the client certificate and the private key in one file. + */ + svSetValueString (ifcfg, + phase2 ? "IEEE_8021X_INNER_CLIENT_CERT" : "IEEE_8021X_CLIENT_CERT", + NULL); + } else { + /* Save the client certificate */ + if (!write_object (s_8021x, ifcfg, phase2 ? &phase2_client_type : &client_type, error)) + goto out; + } + + success = TRUE; + +out: + return success; +} + +static gboolean +write_8021x_setting (NMConnection *connection, + shvarFile *ifcfg, + gboolean wired, + GError **error) +{ + NMSetting8021x *s_8021x; + const char *value, *match; + char *tmp = NULL; + gboolean success = FALSE; + GString *phase2_auth; + GString *str; + guint32 i, num; + + s_8021x = nm_connection_get_setting_802_1x (connection); + if (!s_8021x) { + /* If wired, clear KEY_MGMT */ + if (wired) + svUnsetValue (ifcfg, "KEY_MGMT"); + return TRUE; + } + + /* If wired, write KEY_MGMT */ + if (wired) + svSetValueString (ifcfg, "KEY_MGMT", "IEEE8021X"); + + /* EAP method */ + if (nm_setting_802_1x_get_num_eap_methods (s_8021x)) { + value = nm_setting_802_1x_get_eap_method (s_8021x, 0); + if (value) + tmp = g_ascii_strup (value, -1); + } + svSetValueString (ifcfg, "IEEE_8021X_EAP_METHODS", tmp); + g_free (tmp); + + svSetValueString (ifcfg, "IEEE_8021X_IDENTITY", + nm_setting_802_1x_get_identity (s_8021x)); + + svSetValueString (ifcfg, "IEEE_8021X_ANON_IDENTITY", + nm_setting_802_1x_get_anonymous_identity (s_8021x)); + + set_secret (ifcfg, + "IEEE_8021X_PASSWORD", + nm_setting_802_1x_get_password (s_8021x), + "IEEE_8021X_PASSWORD_FLAGS", + nm_setting_802_1x_get_password_flags (s_8021x)); + + /* PEAP version */ + value = nm_setting_802_1x_get_phase1_peapver (s_8021x); + svUnsetValue (ifcfg, "IEEE_8021X_PEAP_VERSION"); + if (value && (!strcmp (value, "0") || !strcmp (value, "1"))) + svSetValueString (ifcfg, "IEEE_8021X_PEAP_VERSION", value); + + /* Force new PEAP label */ + value = nm_setting_802_1x_get_phase1_peaplabel (s_8021x); + svUnsetValue (ifcfg, "IEEE_8021X_PEAP_FORCE_NEW_LABEL"); + if (value && !strcmp (value, "1")) + svSetValueString (ifcfg, "IEEE_8021X_PEAP_FORCE_NEW_LABEL", "yes"); + + /* PAC file */ + value = nm_setting_802_1x_get_pac_file (s_8021x); + svUnsetValue (ifcfg, "IEEE_8021X_PAC_FILE"); + if (value) + svSetValueString (ifcfg, "IEEE_8021X_PAC_FILE", value); + + /* FAST PAC provisioning */ + value = nm_setting_802_1x_get_phase1_fast_provisioning (s_8021x); + svUnsetValue (ifcfg, "IEEE_8021X_FAST_PROVISIONING"); + if (value) { + if (strcmp (value, "1") == 0) + svSetValueString (ifcfg, "IEEE_8021X_FAST_PROVISIONING", "allow-unauth"); + else if (strcmp (value, "2") == 0) + svSetValueString (ifcfg, "IEEE_8021X_FAST_PROVISIONING", "allow-auth"); + else if (strcmp (value, "3") == 0) + svSetValueString (ifcfg, "IEEE_8021X_FAST_PROVISIONING", "allow-unauth allow-auth"); + } + + /* Phase2 auth methods */ + svUnsetValue (ifcfg, "IEEE_8021X_INNER_AUTH_METHODS"); + phase2_auth = g_string_new (NULL); + + value = nm_setting_802_1x_get_phase2_auth (s_8021x); + if (value) { + tmp = g_ascii_strup (value, -1); + g_string_append (phase2_auth, tmp); + g_free (tmp); + } + + value = nm_setting_802_1x_get_phase2_autheap (s_8021x); + if (value) { + if (phase2_auth->len) + g_string_append_c (phase2_auth, ' '); + + tmp = g_ascii_strup (value, -1); + g_string_append_printf (phase2_auth, "EAP-%s", tmp); + g_free (tmp); + } + + svSetValueString (ifcfg, "IEEE_8021X_INNER_AUTH_METHODS", + phase2_auth->len ? phase2_auth->str : NULL); + + g_string_free (phase2_auth, TRUE); + + svSetValueString (ifcfg, "IEEE_8021X_SUBJECT_MATCH", + nm_setting_802_1x_get_subject_match (s_8021x)); + + svSetValueString (ifcfg, "IEEE_8021X_PHASE2_SUBJECT_MATCH", + nm_setting_802_1x_get_phase2_subject_match (s_8021x)); + + svUnsetValue (ifcfg, "IEEE_8021X_ALTSUBJECT_MATCHES"); + str = g_string_new (NULL); + num = nm_setting_802_1x_get_num_altsubject_matches (s_8021x); + for (i = 0; i < num; i++) { + if (i > 0) + g_string_append_c (str, ' '); + match = nm_setting_802_1x_get_altsubject_match (s_8021x, i); + g_string_append (str, match); + } + if (str->len > 0) + svSetValueString (ifcfg, "IEEE_8021X_ALTSUBJECT_MATCHES", str->str); + g_string_free (str, TRUE); + + svUnsetValue (ifcfg, "IEEE_8021X_PHASE2_ALTSUBJECT_MATCHES"); + str = g_string_new (NULL); + num = nm_setting_802_1x_get_num_phase2_altsubject_matches (s_8021x); + for (i = 0; i < num; i++) { + if (i > 0) + g_string_append_c (str, ' '); + match = nm_setting_802_1x_get_phase2_altsubject_match (s_8021x, i); + g_string_append (str, match); + } + if (str->len > 0) + svSetValueString (ifcfg, "IEEE_8021X_PHASE2_ALTSUBJECT_MATCHES", str->str); + g_string_free (str, TRUE); + + svSetValueString (ifcfg, "IEEE_8021X_DOMAIN_SUFFIX_MATCH", + nm_setting_802_1x_get_domain_suffix_match (s_8021x)); + svSetValueString (ifcfg, "IEEE_8021X_PHASE2_DOMAIN_SUFFIX_MATCH", + nm_setting_802_1x_get_phase2_domain_suffix_match (s_8021x)); + + success = write_8021x_certs (s_8021x, FALSE, ifcfg, error); + if (success) { + /* phase2/inner certs */ + success = write_8021x_certs (s_8021x, TRUE, ifcfg, error); + } + + return success; +} + +static gboolean +write_wireless_security_setting (NMConnection *connection, + shvarFile *ifcfg, + gboolean adhoc, + gboolean *no_8021x, + GError **error) +{ + NMSettingWirelessSecurity *s_wsec; + const char *key_mgmt, *auth_alg, *key, *proto, *cipher; + const char *psk = NULL; + gboolean wep = FALSE, wpa = FALSE, dynamic_wep = FALSE; + char *tmp; + guint32 i, num; + GString *str; + + s_wsec = nm_connection_get_setting_wireless_security (connection); + if (!s_wsec) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, + "Missing '%s' setting", NM_SETTING_WIRELESS_SECURITY_SETTING_NAME); + return FALSE; + } + + key_mgmt = nm_setting_wireless_security_get_key_mgmt (s_wsec); + g_assert (key_mgmt); + + auth_alg = nm_setting_wireless_security_get_auth_alg (s_wsec); + + svUnsetValue (ifcfg, "DEFAULTKEY"); + + if (!strcmp (key_mgmt, "none")) { + svUnsetValue (ifcfg, "KEY_MGMT"); + wep = TRUE; + *no_8021x = TRUE; + } else if (!strcmp (key_mgmt, "wpa-none") || !strcmp (key_mgmt, "wpa-psk")) { + svSetValueString (ifcfg, "KEY_MGMT", "WPA-PSK"); + wpa = TRUE; + *no_8021x = TRUE; + } else if (!strcmp (key_mgmt, "ieee8021x")) { + svSetValueString (ifcfg, "KEY_MGMT", "IEEE8021X"); + dynamic_wep = TRUE; + } else if (!strcmp (key_mgmt, "wpa-eap")) { + svSetValueString (ifcfg, "KEY_MGMT", "WPA-EAP"); + wpa = TRUE; + } + + svUnsetValue (ifcfg, "SECURITYMODE"); + if (auth_alg) { + if (!strcmp (auth_alg, "shared")) + svSetValueString (ifcfg, "SECURITYMODE", "restricted"); + else if (!strcmp (auth_alg, "open")) + svSetValueString (ifcfg, "SECURITYMODE", "open"); + else if (!strcmp (auth_alg, "leap")) { + svSetValueString (ifcfg, "SECURITYMODE", "leap"); + svSetValueString (ifcfg, "IEEE_8021X_IDENTITY", + nm_setting_wireless_security_get_leap_username (s_wsec)); + set_secret (ifcfg, + "IEEE_8021X_PASSWORD", + nm_setting_wireless_security_get_leap_password (s_wsec), + "IEEE_8021X_PASSWORD_FLAGS", + nm_setting_wireless_security_get_leap_password_flags (s_wsec)); + *no_8021x = TRUE; + } + } + + /* WEP keys */ + + /* Clear any default key */ + set_secret (ifcfg, "KEY", NULL, "WEP_KEY_FLAGS", NM_SETTING_SECRET_FLAG_NONE); + + /* Clear existing keys */ + for (i = 0; i < 4; i++) { + tmp = g_strdup_printf ("KEY_PASSPHRASE%d", i + 1); + set_secret (ifcfg, tmp, NULL, "WEP_KEY_FLAGS", NM_SETTING_SECRET_FLAG_NONE); + g_free (tmp); + + tmp = g_strdup_printf ("KEY%d", i + 1); + set_secret (ifcfg, tmp, NULL, "WEP_KEY_FLAGS", NM_SETTING_SECRET_FLAG_NONE); + g_free (tmp); + } + + /* And write the new ones out */ + if (wep) { + /* Default WEP TX key index */ + tmp = g_strdup_printf ("%d", nm_setting_wireless_security_get_wep_tx_keyidx (s_wsec) + 1); + svSetValueString (ifcfg, "DEFAULTKEY", tmp); + g_free (tmp); + + for (i = 0; i < 4; i++) { + NMWepKeyType key_type; + + key = nm_setting_wireless_security_get_wep_key (s_wsec, i); + if (key) { + char *ascii_key = NULL; + + /* Passphrase needs a different ifcfg key since with WEP, there + * are some passphrases that are indistinguishable from WEP hex + * keys. + */ + key_type = nm_setting_wireless_security_get_wep_key_type (s_wsec); + if (key_type == NM_WEP_KEY_TYPE_UNKNOWN) { + if (nm_utils_wep_key_valid (key, NM_WEP_KEY_TYPE_KEY)) + key_type = NM_WEP_KEY_TYPE_KEY; + else if (nm_utils_wep_key_valid (key, NM_WEP_KEY_TYPE_PASSPHRASE)) + key_type = NM_WEP_KEY_TYPE_PASSPHRASE; + } + if (key_type == NM_WEP_KEY_TYPE_PASSPHRASE) + tmp = g_strdup_printf ("KEY_PASSPHRASE%d", i + 1); + else if (key_type == NM_WEP_KEY_TYPE_KEY) { + tmp = g_strdup_printf ("KEY%d", i + 1); + + /* Add 's:' prefix for ASCII keys */ + if (strlen (key) == 5 || strlen (key) == 13) { + ascii_key = g_strdup_printf ("s:%s", key); + key = ascii_key; + } + } else { + _LOGW ("invalid WEP key '%s'", key); + tmp = NULL; + } + + if (tmp) { + set_secret (ifcfg, + tmp, + key, + "WEP_KEY_FLAGS", + nm_setting_wireless_security_get_wep_key_flags (s_wsec)); + } + g_free (tmp); + g_free (ascii_key); + } + } + } + + /* WPA protos */ + svUnsetValue (ifcfg, "WPA_ALLOW_WPA"); + svUnsetValue (ifcfg, "WPA_ALLOW_WPA2"); + num = nm_setting_wireless_security_get_num_protos (s_wsec); + for (i = 0; i < num; i++) { + proto = nm_setting_wireless_security_get_proto (s_wsec, i); + if (proto && !strcmp (proto, "wpa")) + svSetValueString (ifcfg, "WPA_ALLOW_WPA", "yes"); + else if (proto && !strcmp (proto, "rsn")) + svSetValueString (ifcfg, "WPA_ALLOW_WPA2", "yes"); + } + + /* WPA Pairwise ciphers */ + svUnsetValue (ifcfg, "CIPHER_PAIRWISE"); + str = g_string_new (NULL); + num = nm_setting_wireless_security_get_num_pairwise (s_wsec); + for (i = 0; i < num; i++) { + if (i > 0) + g_string_append_c (str, ' '); + cipher = nm_setting_wireless_security_get_pairwise (s_wsec, i); + + /* Don't write out WEP40 or WEP104 if for some reason they are set; they + * are not valid pairwise ciphers. + */ + if (strcmp (cipher, "wep40") && strcmp (cipher, "wep104")) { + tmp = g_ascii_strup (cipher, -1); + g_string_append (str, tmp); + g_free (tmp); + } + } + if (strlen (str->str) && (dynamic_wep == FALSE)) + svSetValueString (ifcfg, "CIPHER_PAIRWISE", str->str); + g_string_free (str, TRUE); + + /* WPA Group ciphers */ + svUnsetValue (ifcfg, "CIPHER_GROUP"); + str = g_string_new (NULL); + num = nm_setting_wireless_security_get_num_groups (s_wsec); + for (i = 0; i < num; i++) { + if (i > 0) + g_string_append_c (str, ' '); + cipher = nm_setting_wireless_security_get_group (s_wsec, i); + tmp = g_ascii_strup (cipher, -1); + g_string_append (str, tmp); + g_free (tmp); + } + if (strlen (str->str) && (dynamic_wep == FALSE)) + svSetValueString (ifcfg, "CIPHER_GROUP", str->str); + g_string_free (str, TRUE); + + if (wpa) + psk = nm_setting_wireless_security_get_psk (s_wsec); + + set_secret (ifcfg, + "WPA_PSK", + psk, + "WPA_PSK_FLAGS", + wpa ? nm_setting_wireless_security_get_psk_flags (s_wsec) : NM_SETTING_SECRET_FLAG_NONE); + + return TRUE; +} + +static gboolean +write_wireless_setting (NMConnection *connection, + shvarFile *ifcfg, + gboolean *no_8021x, + GError **error) +{ + NMSettingWireless *s_wireless; + char *tmp; + GBytes *ssid; + const guint8 *ssid_data; + gsize ssid_len; + const char *mode, *bssid; + const char *device_mac, *cloned_mac; + guint32 mtu, chan, i; + gboolean adhoc = FALSE, hex_ssid = FALSE; + const char * const *macaddr_blacklist; + + s_wireless = nm_connection_get_setting_wireless (connection); + if (!s_wireless) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, + "Missing '%s' setting", NM_SETTING_WIRELESS_SETTING_NAME); + return FALSE; + } + + device_mac = nm_setting_wireless_get_mac_address (s_wireless); + svSetValueString (ifcfg, "HWADDR", device_mac); + + cloned_mac = nm_setting_wireless_get_cloned_mac_address (s_wireless); + svSetValueString (ifcfg, "MACADDR", cloned_mac); + + svSetValueString (ifcfg, "GENERATE_MAC_ADDRESS_MASK", + nm_setting_wireless_get_generate_mac_address_mask (s_wireless)); + + svUnsetValue (ifcfg, "HWADDR_BLACKLIST"); + macaddr_blacklist = nm_setting_wireless_get_mac_address_blacklist (s_wireless); + if (macaddr_blacklist[0]) { + char *blacklist_str; + + blacklist_str = g_strjoinv (" ", (char **) macaddr_blacklist); + svSetValueString (ifcfg, "HWADDR_BLACKLIST", blacklist_str); + g_free (blacklist_str); + } + + svUnsetValue (ifcfg, "MTU"); + mtu = nm_setting_wireless_get_mtu (s_wireless); + if (mtu) { + tmp = g_strdup_printf ("%u", mtu); + svSetValueString (ifcfg, "MTU", tmp); + g_free (tmp); + } + + ssid = nm_setting_wireless_get_ssid (s_wireless); + if (!ssid) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, + "Missing SSID in '%s' setting", NM_SETTING_WIRELESS_SETTING_NAME); + return FALSE; + } + ssid_data = g_bytes_get_data (ssid, &ssid_len); + if (!ssid_len || ssid_len > 32) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, + "Invalid SSID in '%s' setting", NM_SETTING_WIRELESS_SETTING_NAME); + return FALSE; + } + + /* If the SSID contains any non-printable characters, we need to use the + * hex notation of the SSID instead. + */ + if ( ssid_len > 2 + && ssid_data[0] == '0' + && ssid_data[1] == 'x') { + hex_ssid = TRUE; + for (i = 2; i < ssid_len; i++) { + if (!g_ascii_isxdigit (ssid_data[i])) { + hex_ssid = FALSE; + break; + } + } + } + if (!hex_ssid) { + for (i = 0; i < ssid_len; i++) { + if (!g_ascii_isprint (ssid_data[i])) { + hex_ssid = TRUE; + break; + } + } + } + + if (hex_ssid) { + GString *str; + + /* Hex SSIDs don't get quoted */ + str = g_string_sized_new (ssid_len * 2 + 3); + g_string_append (str, "0x"); + for (i = 0; i < ssid_len; i++) + g_string_append_printf (str, "%02X", ssid_data[i]); + svSetValueString (ifcfg, "ESSID", str->str); + g_string_free (str, TRUE); + } else { + char buf[33]; + + nm_assert (ssid_len <= 32); + memcpy (buf, ssid_data, ssid_len); + buf[ssid_len] = '\0'; + svSetValueString (ifcfg, "ESSID", buf); + } + + mode = nm_setting_wireless_get_mode (s_wireless); + if (!mode || !strcmp (mode, "infrastructure")) { + svSetValueString (ifcfg, "MODE", "Managed"); + } else if (!strcmp (mode, "adhoc")) { + svSetValueString (ifcfg, "MODE", "Ad-Hoc"); + adhoc = TRUE; + } else if (!strcmp (mode, "ap")) { + svSetValueString (ifcfg, "MODE", "Ap"); + } else { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, + "Invalid mode '%s' in '%s' setting", + mode, NM_SETTING_WIRELESS_SETTING_NAME); + return FALSE; + } + + svUnsetValue (ifcfg, "CHANNEL"); + svUnsetValue (ifcfg, "BAND"); + chan = nm_setting_wireless_get_channel (s_wireless); + if (chan) { + tmp = g_strdup_printf ("%u", chan); + svSetValueString (ifcfg, "CHANNEL", tmp); + g_free (tmp); + } else { + /* Band only set if channel is not, since channel implies band */ + svSetValueString (ifcfg, "BAND", nm_setting_wireless_get_band (s_wireless)); + } + + bssid = nm_setting_wireless_get_bssid (s_wireless); + svSetValueString (ifcfg, "BSSID", bssid); + + /* Ensure DEFAULTKEY and SECURITYMODE are cleared unless there's security; + * otherwise there's no way to detect WEP vs. open when WEP keys aren't + * saved. + */ + svUnsetValue (ifcfg, "DEFAULTKEY"); + svUnsetValue (ifcfg, "SECURITYMODE"); + + if (nm_connection_get_setting_wireless_security (connection)) { + if (!write_wireless_security_setting (connection, ifcfg, adhoc, no_8021x, error)) + return FALSE; + } else { + char *keys_path; + + /* Clear out wifi security keys */ + svUnsetValue (ifcfg, "KEY_MGMT"); + svUnsetValue (ifcfg, "IEEE_8021X_IDENTITY"); + set_secret (ifcfg, "IEEE_8021X_PASSWORD", NULL, "IEEE_8021X_PASSWORD_FLAGS", NM_SETTING_SECRET_FLAG_NONE); + svUnsetValue (ifcfg, "SECURITYMODE"); + + /* Clear existing keys */ + set_secret (ifcfg, "KEY", NULL, "WEP_KEY_FLAGS", NM_SETTING_SECRET_FLAG_NONE); + for (i = 0; i < 4; i++) { + tmp = g_strdup_printf ("KEY_PASSPHRASE%d", i + 1); + set_secret (ifcfg, tmp, NULL, "WEP_KEY_FLAGS", NM_SETTING_SECRET_FLAG_NONE); + g_free (tmp); + + tmp = g_strdup_printf ("KEY%d", i + 1); + set_secret (ifcfg, tmp, NULL, "WEP_KEY_FLAGS", NM_SETTING_SECRET_FLAG_NONE); + g_free (tmp); + } + + svUnsetValue (ifcfg, "DEFAULTKEY"); + svUnsetValue (ifcfg, "WPA_ALLOW_WPA"); + svUnsetValue (ifcfg, "WPA_ALLOW_WPA2"); + svUnsetValue (ifcfg, "CIPHER_PAIRWISE"); + svUnsetValue (ifcfg, "CIPHER_GROUP"); + set_secret (ifcfg, "WPA_PSK", NULL, "WPA_PSK_FLAGS", NM_SETTING_SECRET_FLAG_NONE); + + /* Kill any old keys file */ + keys_path = utils_get_keys_path (svFileGetName (ifcfg)); + (void) unlink (keys_path); + g_free (keys_path); + } + + svSetValueString (ifcfg, "SSID_HIDDEN", nm_setting_wireless_get_hidden (s_wireless) ? "yes" : NULL); + + switch (nm_setting_wireless_get_powersave (s_wireless)) { + case NM_SETTING_WIRELESS_POWERSAVE_IGNORE: + svSetValueString (ifcfg, "POWERSAVE", "ignore"); + break; + case NM_SETTING_WIRELESS_POWERSAVE_DISABLE: + svSetValueString (ifcfg, "POWERSAVE", "disable"); + break; + case NM_SETTING_WIRELESS_POWERSAVE_ENABLE: + svSetValueString (ifcfg, "POWERSAVE", "enable"); + break; + default: + case NM_SETTING_WIRELESS_POWERSAVE_DEFAULT: + svUnsetValue (ifcfg, "POWERSAVE"); + break; + } + + svUnsetValue (ifcfg, "MAC_ADDRESS_RANDOMIZATION"); + switch (nm_setting_wireless_get_mac_address_randomization (s_wireless)) { + case NM_SETTING_MAC_RANDOMIZATION_DEFAULT: + svSetValueString (ifcfg, "MAC_ADDRESS_RANDOMIZATION", "default"); + break; + case NM_SETTING_MAC_RANDOMIZATION_ALWAYS: + svSetValueString (ifcfg, "MAC_ADDRESS_RANDOMIZATION", "always"); + break; + default: + case NM_SETTING_MAC_RANDOMIZATION_NEVER: + svSetValueString (ifcfg, "MAC_ADDRESS_RANDOMIZATION", "never"); + break; + } + + svSetValueString (ifcfg, "TYPE", TYPE_WIRELESS); + + return TRUE; +} + +static gboolean +write_infiniband_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) +{ + NMSettingInfiniband *s_infiniband; + char *tmp; + const char *mac, *transport_mode, *parent; + guint32 mtu; + int p_key; + + s_infiniband = nm_connection_get_setting_infiniband (connection); + if (!s_infiniband) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, + "Missing '%s' setting", NM_SETTING_INFINIBAND_SETTING_NAME); + return FALSE; + } + + mac = nm_setting_infiniband_get_mac_address (s_infiniband); + svSetValueString (ifcfg, "HWADDR", mac); + + svUnsetValue (ifcfg, "MTU"); + mtu = nm_setting_infiniband_get_mtu (s_infiniband); + if (mtu) { + tmp = g_strdup_printf ("%u", mtu); + svSetValueString (ifcfg, "MTU", tmp); + g_free (tmp); + } + + transport_mode = nm_setting_infiniband_get_transport_mode (s_infiniband); + svSetValueBoolean (ifcfg, "CONNECTED_MODE", nm_streq (transport_mode, "connected")); + + p_key = nm_setting_infiniband_get_p_key (s_infiniband); + if (p_key != -1) { + svSetValueString (ifcfg, "PKEY", "yes"); + tmp = g_strdup_printf ("%u", p_key); + svSetValueString (ifcfg, "PKEY_ID", tmp); + g_free (tmp); + + parent = nm_setting_infiniband_get_parent (s_infiniband); + if (parent) + svSetValueString (ifcfg, "PHYSDEV", parent); + } + + svSetValueString (ifcfg, "TYPE", TYPE_INFINIBAND); + + return TRUE; +} + +static gboolean +write_wired_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) +{ + NMSettingWired *s_wired; + const char *device_mac, *cloned_mac; + char *tmp; + const char *nettype, *portname, *ctcprot, *s390_key, *s390_val, *duplex; + guint32 mtu, num_opts, speed, i; + const char *const *s390_subchannels; + GString *str = NULL; + const char * const *macaddr_blacklist; + gboolean auto_negotiate; + NMSettingWiredWakeOnLan wol; + const char *wol_password; + + s_wired = nm_connection_get_setting_wired (connection); + if (!s_wired) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, + "Missing '%s' setting", NM_SETTING_WIRED_SETTING_NAME); + return FALSE; + } + + device_mac = nm_setting_wired_get_mac_address (s_wired); + svSetValueString (ifcfg, "HWADDR", device_mac); + + cloned_mac = nm_setting_wired_get_cloned_mac_address (s_wired); + svSetValueString (ifcfg, "MACADDR", cloned_mac); + + svSetValueString (ifcfg, "GENERATE_MAC_ADDRESS_MASK", + nm_setting_wired_get_generate_mac_address_mask (s_wired)); + + svUnsetValue (ifcfg, "HWADDR_BLACKLIST"); + macaddr_blacklist = nm_setting_wired_get_mac_address_blacklist (s_wired); + if (macaddr_blacklist[0]) { + char *blacklist_str; + + blacklist_str = g_strjoinv (" ", (char **) macaddr_blacklist); + svSetValueString (ifcfg, "HWADDR_BLACKLIST", blacklist_str); + g_free (blacklist_str); + } + + svUnsetValue (ifcfg, "MTU"); + mtu = nm_setting_wired_get_mtu (s_wired); + if (mtu) { + tmp = g_strdup_printf ("%u", mtu); + svSetValueString (ifcfg, "MTU", tmp); + g_free (tmp); + } + + svUnsetValue (ifcfg, "SUBCHANNELS"); + s390_subchannels = nm_setting_wired_get_s390_subchannels (s_wired); + if (s390_subchannels) { + int len = g_strv_length ((char **)s390_subchannels); + + tmp = NULL; + if (len == 2) { + tmp = g_strdup_printf ("%s,%s", s390_subchannels[0], s390_subchannels[1]); + } else if (len == 3) { + tmp = g_strdup_printf ("%s,%s,%s", s390_subchannels[0], s390_subchannels[1], + s390_subchannels[2]); + } + svSetValueString (ifcfg, "SUBCHANNELS", tmp); + g_free (tmp); + } + + svUnsetValue (ifcfg, "NETTYPE"); + nettype = nm_setting_wired_get_s390_nettype (s_wired); + if (nettype) + svSetValueString (ifcfg, "NETTYPE", nettype); + + svUnsetValue (ifcfg, "PORTNAME"); + portname = nm_setting_wired_get_s390_option_by_key (s_wired, "portname"); + if (portname) + svSetValueString (ifcfg, "PORTNAME", portname); + + svUnsetValue (ifcfg, "CTCPROT"); + ctcprot = nm_setting_wired_get_s390_option_by_key (s_wired, "ctcprot"); + if (ctcprot) + svSetValueString (ifcfg, "CTCPROT", ctcprot); + + svUnsetValue (ifcfg, "OPTIONS"); + num_opts = nm_setting_wired_get_num_s390_options (s_wired); + if (s390_subchannels && num_opts) { + str = g_string_sized_new (30); + for (i = 0; i < num_opts; i++) { + nm_setting_wired_get_s390_option (s_wired, i, &s390_key, &s390_val); + + /* portname is handled separately */ + if (!strcmp (s390_key, "portname") || !strcmp (s390_key, "ctcprot")) + continue; + + if (str->len) + g_string_append_c (str, ' '); + g_string_append_printf (str, "%s=%s", s390_key, s390_val); + } + if (str->len) + svSetValueString (ifcfg, "OPTIONS", str->str); + g_string_free (str, TRUE); + } + + /* Stuff ETHTOOL_OPT with required options */ + str = NULL; + auto_negotiate = nm_setting_wired_get_auto_negotiate (s_wired); + /* autoneg off + speed 0 + duplex NULL, means we want NM + * to skip link configuration which is default. So write + * down link config only if we have auto-negotiate true or + * a valid value for one among speed and duplex. + */ + if (auto_negotiate) { + str = g_string_sized_new (64); + g_string_printf (str, "autoneg on"); + } else { + speed = nm_setting_wired_get_speed (s_wired); + duplex = nm_setting_wired_get_duplex (s_wired); + if (speed || duplex) { + str = g_string_sized_new (64); + g_string_printf (str, "autoneg off"); + if (speed) + g_string_append_printf (str, " speed %u", speed); + if (duplex) + g_string_append_printf (str, " duplex %s", duplex); + } + } + + wol = nm_setting_wired_get_wake_on_lan (s_wired); + wol_password = nm_setting_wired_get_wake_on_lan_password (s_wired); + + if (wol == NM_SETTING_WIRED_WAKE_ON_LAN_IGNORE) + svSetValue (ifcfg, "ETHTOOL_WAKE_ON_LAN", "ignore"); + else if (wol == NM_SETTING_WIRED_WAKE_ON_LAN_DEFAULT) { + if (!str) + svUnsetValue (ifcfg, "ETHTOOL_OPTS"); + } else { + if (!str) + str = g_string_sized_new (30); + else + g_string_append (str, " "); + + g_string_append (str, "wol "); + + if (NM_FLAGS_HAS (wol, NM_SETTING_WIRED_WAKE_ON_LAN_PHY)) + g_string_append (str, "p"); + if (NM_FLAGS_HAS (wol, NM_SETTING_WIRED_WAKE_ON_LAN_UNICAST)) + g_string_append (str, "u"); + if (NM_FLAGS_HAS (wol, NM_SETTING_WIRED_WAKE_ON_LAN_MULTICAST)) + g_string_append (str, "m"); + if (NM_FLAGS_HAS (wol, NM_SETTING_WIRED_WAKE_ON_LAN_BROADCAST)) + g_string_append (str, "b"); + if (NM_FLAGS_HAS (wol, NM_SETTING_WIRED_WAKE_ON_LAN_ARP)) + g_string_append (str, "a"); + if (NM_FLAGS_HAS (wol, NM_SETTING_WIRED_WAKE_ON_LAN_MAGIC)) + g_string_append (str, "g"); + + if (!NM_FLAGS_ANY (wol, NM_SETTING_WIRED_WAKE_ON_LAN_ALL)) + g_string_append (str, "d"); + + if (wol_password && NM_FLAGS_HAS (wol, NM_SETTING_WIRED_WAKE_ON_LAN_MAGIC)) + g_string_append_printf (str, "s sopass %s", wol_password); + } + if (str) { + svSetValueString (ifcfg, "ETHTOOL_OPTS", str->str); + g_string_free (str, TRUE); + } + /* End ETHTOOL_OPT stuffing */ + + svSetValueString (ifcfg, "TYPE", TYPE_ETHERNET); + + return TRUE; +} + +static char * +vlan_priority_maplist_to_stringlist (NMSettingVlan *s_vlan, NMVlanPriorityMap map) +{ + char **strlist; + char *value; + + if (map == NM_VLAN_INGRESS_MAP) + g_object_get (G_OBJECT (s_vlan), NM_SETTING_VLAN_INGRESS_PRIORITY_MAP, &strlist, NULL); + else if (map == NM_VLAN_EGRESS_MAP) + g_object_get (G_OBJECT (s_vlan), NM_SETTING_VLAN_EGRESS_PRIORITY_MAP, &strlist, NULL); + else + return NULL; + + if (strlist[0]) + value = g_strjoinv (",", strlist); + else + value = NULL; + g_strfreev (strlist); + + return value; +} + +static gboolean +write_wired_for_virtual (NMConnection *connection, shvarFile *ifcfg) +{ + NMSettingWired *s_wired; + gboolean has_wired = FALSE; + + s_wired = nm_connection_get_setting_wired (connection); + if (s_wired) { + const char *device_mac, *cloned_mac; + char *tmp; + guint32 mtu; + + has_wired = TRUE; + + device_mac = nm_setting_wired_get_mac_address (s_wired); + svSetValueString (ifcfg, "HWADDR", device_mac); + + cloned_mac = nm_setting_wired_get_cloned_mac_address (s_wired); + svSetValueString (ifcfg, "MACADDR", cloned_mac); + + svSetValueString (ifcfg, "GENERATE_MAC_ADDRESS_MASK", + nm_setting_wired_get_generate_mac_address_mask (s_wired)); + + mtu = nm_setting_wired_get_mtu (s_wired); + if (mtu) { + tmp = g_strdup_printf ("%u", mtu); + svSetValueString (ifcfg, "MTU", tmp); + g_free (tmp); + } else + svUnsetValue (ifcfg, "MTU"); + } + return has_wired; +} + +static gboolean +write_vlan_setting (NMConnection *connection, shvarFile *ifcfg, gboolean *wired, GError **error) +{ + NMSettingVlan *s_vlan; + NMSettingConnection *s_con; + char *tmp; + guint32 vlan_flags = 0; + gsize s_buf_len; + char s_buf[50], *s_buf_ptr; + + s_con = nm_connection_get_setting_connection (connection); + if (!s_con) { + g_set_error_literal (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, + "Missing connection setting"); + return FALSE; + } + + s_vlan = nm_connection_get_setting_vlan (connection); + if (!s_vlan) { + g_set_error_literal (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, + "Missing VLAN setting"); + return FALSE; + } + + svSetValueString (ifcfg, "VLAN", "yes"); + svSetValueString (ifcfg, "TYPE", TYPE_VLAN); + svSetValueString (ifcfg, "DEVICE", nm_setting_connection_get_interface_name (s_con)); + svSetValueString (ifcfg, "PHYSDEV", nm_setting_vlan_get_parent (s_vlan)); + + tmp = g_strdup_printf ("%d", nm_setting_vlan_get_id (s_vlan)); + svSetValueString (ifcfg, "VLAN_ID", tmp); + g_free (tmp); + + vlan_flags = nm_setting_vlan_get_flags (s_vlan); + svSetValueBoolean (ifcfg, "REORDER_HDR", NM_FLAGS_HAS (vlan_flags, NM_VLAN_FLAG_REORDER_HEADERS)); + svSetValueBoolean (ifcfg, "GVRP", NM_FLAGS_HAS (vlan_flags, NM_VLAN_FLAG_GVRP)); + + nm_utils_strbuf_init (s_buf, &s_buf_ptr, &s_buf_len); + + if (NM_FLAGS_HAS (vlan_flags, NM_VLAN_FLAG_LOOSE_BINDING)) + nm_utils_strbuf_append_str (&s_buf_ptr, &s_buf_len, "LOOSE_BINDING"); + if (!NM_FLAGS_HAS (vlan_flags, NM_VLAN_FLAG_REORDER_HEADERS)) + nm_utils_strbuf_append (&s_buf_ptr, &s_buf_len, "%sNO_REORDER_HDR", s_buf[0] ? "," : ""); + + svSetValueString (ifcfg, "VLAN_FLAGS", s_buf); + + svSetValueBoolean (ifcfg, "MVRP", NM_FLAGS_HAS (vlan_flags, NM_VLAN_FLAG_MVRP)); + + tmp = vlan_priority_maplist_to_stringlist (s_vlan, NM_VLAN_INGRESS_MAP); + svSetValueString (ifcfg, "VLAN_INGRESS_PRIORITY_MAP", tmp); + g_free (tmp); + + tmp = vlan_priority_maplist_to_stringlist (s_vlan, NM_VLAN_EGRESS_MAP); + svSetValueString (ifcfg, "VLAN_EGRESS_PRIORITY_MAP", tmp); + g_free (tmp); + + svUnsetValue (ifcfg, "HWADDR"); + svUnsetValue (ifcfg, "MACADDR"); + svUnsetValue (ifcfg, "MTU"); + + *wired = write_wired_for_virtual (connection, ifcfg); + + return TRUE; +} + +static gboolean +write_bonding_setting (NMConnection *connection, shvarFile *ifcfg, gboolean *wired, GError **error) +{ + NMSettingBond *s_bond; + const char *iface; + guint32 i, num_opts; + + s_bond = nm_connection_get_setting_bond (connection); + if (!s_bond) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, + "Missing '%s' setting", NM_SETTING_BOND_SETTING_NAME); + return FALSE; + } + + iface = nm_connection_get_interface_name (connection); + if (!iface) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, + "Missing interface name"); + return FALSE; + } + + svSetValueString (ifcfg, "DEVICE", iface); + svUnsetValue (ifcfg, "BONDING_OPTS"); + + num_opts = nm_setting_bond_get_num_options (s_bond); + if (num_opts > 0) { + GString *str = g_string_sized_new (64); + + for (i = 0; i < nm_setting_bond_get_num_options (s_bond); i++) { + const char *key, *value; + + if (!nm_setting_bond_get_option (s_bond, i, &key, &value)) + continue; + + if (str->len) + g_string_append_c (str, ' '); + + g_string_append_printf (str, "%s=%s", key, value); + } + + if (str->len) + svSetValueString (ifcfg, "BONDING_OPTS", str->str); + + g_string_free (str, TRUE); + } + + svSetValueString (ifcfg, "TYPE", TYPE_BOND); + svSetValueString (ifcfg, "BONDING_MASTER", "yes"); + + *wired = write_wired_for_virtual (connection, ifcfg); + + return TRUE; +} + +static gboolean +write_team_setting (NMConnection *connection, shvarFile *ifcfg, gboolean *wired, GError **error) +{ + NMSettingTeam *s_team; + const char *iface; + const char *config; + + s_team = nm_connection_get_setting_team (connection); + if (!s_team) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, + "Missing '%s' setting", NM_SETTING_TEAM_SETTING_NAME); + return FALSE; + } + + iface = nm_connection_get_interface_name (connection); + if (!iface) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, + "Missing interface name"); + return FALSE; + } + + svSetValueString (ifcfg, "DEVICE", iface); + config = nm_setting_team_get_config (s_team); + svSetValueString (ifcfg, "TEAM_CONFIG", config); + + *wired = write_wired_for_virtual (connection, ifcfg); + + return TRUE; +} + +static guint32 +get_setting_default_uint (NMSetting *setting, const char *prop) +{ + GParamSpec *pspec; + GValue val = G_VALUE_INIT; + guint32 ret = 0; + + pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (setting), prop); + g_assert (pspec); + g_value_init (&val, pspec->value_type); + g_param_value_set_default (pspec, &val); + g_assert (G_VALUE_HOLDS_UINT (&val)); + ret = g_value_get_uint (&val); + g_value_unset (&val); + return ret; +} + +static gboolean +get_setting_default_boolean (NMSetting *setting, const char *prop) +{ + GParamSpec *pspec; + GValue val = G_VALUE_INIT; + gboolean ret = 0; + + pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (setting), prop); + g_assert (pspec); + g_value_init (&val, pspec->value_type); + g_param_value_set_default (pspec, &val); + g_assert (G_VALUE_HOLDS_BOOLEAN (&val)); + ret = g_value_get_boolean (&val); + g_value_unset (&val); + return ret; +} + +static gboolean +write_bridge_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) +{ + NMSettingBridge *s_bridge; + const char *iface; + guint32 i; + gboolean b; + GString *opts; + const char *mac; + char *s; + + s_bridge = nm_connection_get_setting_bridge (connection); + if (!s_bridge) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, + "Missing '%s' setting", NM_SETTING_BRIDGE_SETTING_NAME); + return FALSE; + } + + iface = nm_connection_get_interface_name (connection); + if (!iface) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, + "Missing interface name"); + return FALSE; + } + + svSetValueString (ifcfg, "DEVICE", iface); + svUnsetValue (ifcfg, "BRIDGING_OPTS"); + svSetValueBoolean (ifcfg, "STP", FALSE); + svUnsetValue (ifcfg, "DELAY"); + + mac = nm_setting_bridge_get_mac_address (s_bridge); + svSetValueString (ifcfg, "MACADDR", mac); + + /* Bridge options */ + opts = g_string_sized_new (32); + + if (nm_setting_bridge_get_stp (s_bridge)) { + svSetValueString (ifcfg, "STP", "yes"); + + i = nm_setting_bridge_get_forward_delay (s_bridge); + if (i != get_setting_default_uint (NM_SETTING (s_bridge), NM_SETTING_BRIDGE_FORWARD_DELAY)) { + s = g_strdup_printf ("%u", i); + svSetValueString (ifcfg, "DELAY", s); + g_free (s); + } + + g_string_append_printf (opts, "priority=%u", nm_setting_bridge_get_priority (s_bridge)); + + i = nm_setting_bridge_get_hello_time (s_bridge); + if (i != get_setting_default_uint (NM_SETTING (s_bridge), NM_SETTING_BRIDGE_HELLO_TIME)) { + if (opts->len) + g_string_append_c (opts, ' '); + g_string_append_printf (opts, "hello_time=%u", i); + } + + i = nm_setting_bridge_get_max_age (s_bridge); + if (i != get_setting_default_uint (NM_SETTING (s_bridge), NM_SETTING_BRIDGE_MAX_AGE)) { + if (opts->len) + g_string_append_c (opts, ' '); + g_string_append_printf (opts, "max_age=%u", i); + } + } + + i = nm_setting_bridge_get_ageing_time (s_bridge); + if (i != get_setting_default_uint (NM_SETTING (s_bridge), NM_SETTING_BRIDGE_AGEING_TIME)) { + if (opts->len) + g_string_append_c (opts, ' '); + g_string_append_printf (opts, "ageing_time=%u", i); + } + + b = nm_setting_bridge_get_multicast_snooping (s_bridge); + if (b != get_setting_default_boolean (NM_SETTING (s_bridge), NM_SETTING_BRIDGE_MULTICAST_SNOOPING)) { + if (opts->len) + g_string_append_c (opts, ' '); + g_string_append_printf (opts, "multicast_snooping=%u", (guint32) b); + } + + if (opts->len) + svSetValueString (ifcfg, "BRIDGING_OPTS", opts->str); + g_string_free (opts, TRUE); + + svSetValueString (ifcfg, "TYPE", TYPE_BRIDGE); + + return TRUE; +} + +static gboolean +write_bridge_port_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) +{ + NMSettingBridgePort *s_port; + guint32 i; + GString *opts; + + s_port = nm_connection_get_setting_bridge_port (connection); + if (!s_port) + return TRUE; + + svUnsetValue (ifcfg, "BRIDGING_OPTS"); + + /* Bridge options */ + opts = g_string_sized_new (32); + + i = nm_setting_bridge_port_get_priority (s_port); + if (i != get_setting_default_uint (NM_SETTING (s_port), NM_SETTING_BRIDGE_PORT_PRIORITY)) + g_string_append_printf (opts, "priority=%u", i); + + i = nm_setting_bridge_port_get_path_cost (s_port); + if (i != get_setting_default_uint (NM_SETTING (s_port), NM_SETTING_BRIDGE_PORT_PATH_COST)) { + if (opts->len) + g_string_append_c (opts, ' '); + g_string_append_printf (opts, "path_cost=%u", i); + } + + if (nm_setting_bridge_port_get_hairpin_mode (s_port)) { + if (opts->len) + g_string_append_c (opts, ' '); + g_string_append_printf (opts, "hairpin_mode=1"); + } + + if (opts->len) + svSetValueString (ifcfg, "BRIDGING_OPTS", opts->str); + g_string_free (opts, TRUE); + + return TRUE; +} + +static gboolean +write_team_port_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) +{ + NMSettingTeamPort *s_port; + const char *config; + + s_port = nm_connection_get_setting_team_port (connection); + if (!s_port) + return TRUE; + + config = nm_setting_team_port_get_config (s_port); + svSetValueString (ifcfg, "TEAM_PORT_CONFIG", config); + + return TRUE; +} + +static void +write_dcb_flags (shvarFile *ifcfg, const char *tag, NMSettingDcbFlags flags) +{ + char prop[NM_STRLEN ("DCB_xxxxxxxxxxxxxxxxxxxxxxx_yyyyyyyyyyyyyyyyyyyy")]; + + nm_sprintf_buf (prop, "DCB_%s_ENABLE", tag); + svSetValueString (ifcfg, prop, (flags & NM_SETTING_DCB_FLAG_ENABLE) ? "yes" : NULL); + + nm_sprintf_buf (prop, "DCB_%s_ADVERTISE", tag); + svSetValueString (ifcfg, prop, (flags & NM_SETTING_DCB_FLAG_ADVERTISE) ? "yes" : NULL); + + nm_sprintf_buf (prop, "DCB_%s_WILLING", tag); + svSetValueString (ifcfg, prop, (flags & NM_SETTING_DCB_FLAG_WILLING) ? "yes" : NULL); +} + +static void +write_dcb_app (shvarFile *ifcfg, + const char *tag, + NMSettingDcbFlags flags, + gint priority) +{ + char prop[NM_STRLEN ("DCB_xxxxxxxxxxxxxxxxxxxxxxx_yyyyyyyyyyyyyyyyyyyy")]; + + write_dcb_flags (ifcfg, tag, flags); + + nm_sprintf_buf (prop, "DCB_%s_PRIORITY", tag); + if ((flags & NM_SETTING_DCB_FLAG_ENABLE) && (priority >= 0)) + svSetValueInt64 (ifcfg, prop, priority); + else + svUnsetValue (ifcfg, prop); +} + +typedef gboolean (*DcbGetBoolFunc) (NMSettingDcb *, guint); + +static void +write_dcb_bool_array (shvarFile *ifcfg, + const char *key, + NMSettingDcb *s_dcb, + NMSettingDcbFlags flags, + DcbGetBoolFunc get_func) +{ + char str[9]; + guint i; + + if (!(flags & NM_SETTING_DCB_FLAG_ENABLE)) { + svUnsetValue (ifcfg, key); + return; + } + + str[8] = 0; + for (i = 0; i < 8; i++) + str[i] = get_func (s_dcb, i) ? '1' : '0'; + svSetValueString (ifcfg, key, str); +} + +typedef guint (*DcbGetUintFunc) (NMSettingDcb *, guint); + +static void +write_dcb_uint_array (shvarFile *ifcfg, + const char *key, + NMSettingDcb *s_dcb, + NMSettingDcbFlags flags, + DcbGetUintFunc get_func) +{ + char str[9]; + guint i, num; + + if (!(flags & NM_SETTING_DCB_FLAG_ENABLE)) { + svUnsetValue (ifcfg, key); + return; + } + + str[8] = 0; + for (i = 0; i < 8; i++) { + num = get_func (s_dcb, i); + if (num < 10) + str[i] = '0' + num; + else if (num == 15) + str[i] = 'f'; + else + g_assert_not_reached (); + } + svSetValueString (ifcfg, key, str); +} + +static void +write_dcb_percent_array (shvarFile *ifcfg, + const char *key, + NMSettingDcb *s_dcb, + NMSettingDcbFlags flags, + DcbGetUintFunc get_func) +{ + GString *str; + guint i; + + if (!(flags & NM_SETTING_DCB_FLAG_ENABLE)) { + svUnsetValue (ifcfg, key); + return; + } + + str = g_string_sized_new (30); + for (i = 0; i < 8; i++) { + if (str->len) + g_string_append_c (str, ','); + g_string_append_printf (str, "%d", get_func (s_dcb, i)); + } + svSetValueString (ifcfg, key, str->str); + g_string_free (str, TRUE); +} + +static gboolean +write_dcb_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) +{ + NMSettingDcb *s_dcb; + NMSettingDcbFlags flags; + + s_dcb = nm_connection_get_setting_dcb (connection); + if (!s_dcb) { + static const char *clear_keys[] = { + "DCB", + KEY_DCB_APP_FCOE_ENABLE, + KEY_DCB_APP_FCOE_ADVERTISE, + KEY_DCB_APP_FCOE_WILLING, + KEY_DCB_APP_FCOE_MODE, + KEY_DCB_APP_ISCSI_ENABLE, + KEY_DCB_APP_ISCSI_ADVERTISE, + KEY_DCB_APP_ISCSI_WILLING, + KEY_DCB_APP_FIP_ENABLE, + KEY_DCB_APP_FIP_ADVERTISE, + KEY_DCB_APP_FIP_WILLING, + KEY_DCB_PFC_ENABLE, + KEY_DCB_PFC_ADVERTISE, + KEY_DCB_PFC_WILLING, + KEY_DCB_PFC_UP, + KEY_DCB_PG_ENABLE, + KEY_DCB_PG_ADVERTISE, + KEY_DCB_PG_WILLING, + KEY_DCB_PG_ID, + KEY_DCB_PG_PCT, + KEY_DCB_PG_UPPCT, + KEY_DCB_PG_STRICT, + KEY_DCB_PG_UP2TC, + NULL }; + const char **iter; + + for (iter = clear_keys; *iter; iter++) + svUnsetValue (ifcfg, *iter); + return TRUE; + } + + svSetValueString (ifcfg, "DCB", "yes"); + + write_dcb_app (ifcfg, "APP_FCOE", + nm_setting_dcb_get_app_fcoe_flags (s_dcb), + nm_setting_dcb_get_app_fcoe_priority (s_dcb)); + if (nm_setting_dcb_get_app_fcoe_flags (s_dcb) & NM_SETTING_DCB_FLAG_ENABLE) + svSetValueString (ifcfg, KEY_DCB_APP_FCOE_MODE, nm_setting_dcb_get_app_fcoe_mode (s_dcb)); + else + svUnsetValue (ifcfg, KEY_DCB_APP_FCOE_MODE); + + write_dcb_app (ifcfg, "APP_ISCSI", + nm_setting_dcb_get_app_iscsi_flags (s_dcb), + nm_setting_dcb_get_app_iscsi_priority (s_dcb)); + write_dcb_app (ifcfg, "APP_FIP", + nm_setting_dcb_get_app_fip_flags (s_dcb), + nm_setting_dcb_get_app_fip_priority (s_dcb)); + + write_dcb_flags (ifcfg, "PFC", nm_setting_dcb_get_priority_flow_control_flags (s_dcb)); + write_dcb_bool_array (ifcfg, KEY_DCB_PFC_UP, s_dcb, + nm_setting_dcb_get_priority_flow_control_flags (s_dcb), + nm_setting_dcb_get_priority_flow_control); + + flags = nm_setting_dcb_get_priority_group_flags (s_dcb); + write_dcb_flags (ifcfg, "PG", flags); + write_dcb_uint_array (ifcfg, KEY_DCB_PG_ID, s_dcb, flags, nm_setting_dcb_get_priority_group_id); + write_dcb_percent_array (ifcfg, KEY_DCB_PG_PCT, s_dcb, flags, nm_setting_dcb_get_priority_group_bandwidth); + write_dcb_percent_array (ifcfg, KEY_DCB_PG_UPPCT, s_dcb, flags, nm_setting_dcb_get_priority_bandwidth); + write_dcb_bool_array (ifcfg, KEY_DCB_PG_STRICT, s_dcb, flags, nm_setting_dcb_get_priority_strict_bandwidth); + write_dcb_uint_array (ifcfg, KEY_DCB_PG_UP2TC, s_dcb, flags, nm_setting_dcb_get_priority_traffic_class); + + return TRUE; +} + +static void +write_connection_setting (NMSettingConnection *s_con, shvarFile *ifcfg) +{ + guint32 n, i; + GString *str; + const char *master, *master_iface = NULL, *type; + char *tmp; + gint i_int; + + svSetValueString (ifcfg, "NAME", nm_setting_connection_get_id (s_con)); + svSetValueString (ifcfg, "UUID", nm_setting_connection_get_uuid (s_con)); + svSetValueString (ifcfg, "STABLE_ID", nm_setting_connection_get_stable_id (s_con)); + svSetValueString (ifcfg, "DEVICE", nm_setting_connection_get_interface_name (s_con)); + svSetValueBoolean (ifcfg, "ONBOOT", nm_setting_connection_get_autoconnect (s_con)); + + i_int = nm_setting_connection_get_autoconnect_priority (s_con); + tmp = i_int != NM_SETTING_CONNECTION_AUTOCONNECT_PRIORITY_DEFAULT + ? g_strdup_printf ("%d", i_int) : NULL; + svSetValueString (ifcfg, "AUTOCONNECT_PRIORITY", tmp); + g_free (tmp); + + i_int = nm_setting_connection_get_autoconnect_retries (s_con); + tmp = i_int != -1 ? g_strdup_printf ("%d", i_int) : NULL; + svSetValueString (ifcfg, "AUTOCONNECT_RETRIES", tmp); + g_free (tmp); + + /* Only save the value for master connections */ + type = nm_setting_connection_get_connection_type (s_con); + if ( !g_strcmp0 (type, NM_SETTING_BOND_SETTING_NAME) + || !g_strcmp0 (type, NM_SETTING_TEAM_SETTING_NAME) + || !g_strcmp0 (type, NM_SETTING_BRIDGE_SETTING_NAME)) { + NMSettingConnectionAutoconnectSlaves autoconnect_slaves; + autoconnect_slaves = nm_setting_connection_get_autoconnect_slaves (s_con); + svSetValueString (ifcfg, "AUTOCONNECT_SLAVES", + autoconnect_slaves == NM_SETTING_CONNECTION_AUTOCONNECT_SLAVES_YES ? "yes" : + autoconnect_slaves == NM_SETTING_CONNECTION_AUTOCONNECT_SLAVES_NO ? "no" : NULL); + } else + svUnsetValue (ifcfg, "AUTOCONNECT_SLAVES"); + + switch (nm_setting_connection_get_lldp (s_con)) { + case NM_SETTING_CONNECTION_LLDP_ENABLE_RX: + tmp = "rx"; + break; + case NM_SETTING_CONNECTION_LLDP_DISABLE: + tmp = "no"; + break; + default: + tmp = NULL; + } + svSetValueString (ifcfg, "LLDP", tmp); + + /* Permissions */ + svUnsetValue (ifcfg, "USERS"); + n = nm_setting_connection_get_num_permissions (s_con); + if (n > 0) { + str = g_string_sized_new (n * 20); + + for (i = 0; i < n; i++) { + const char *puser = NULL; + + /* Items separated by space for consistency with eg + * IPV6ADDR_SECONDARIES and DOMAIN. + */ + if (str->len) + g_string_append_c (str, ' '); + + if (nm_setting_connection_get_permission (s_con, i, NULL, &puser, NULL)) + g_string_append (str, puser); + } + svSetValueString (ifcfg, "USERS", str->str); + g_string_free (str, TRUE); + } + + svSetValueString (ifcfg, "ZONE", nm_setting_connection_get_zone(s_con)); + + svSetValueString (ifcfg, "MASTER_UUID", NULL); + svSetValueString (ifcfg, "MASTER", NULL); + svSetValueString (ifcfg, "SLAVE", NULL); + svSetValueString (ifcfg, "BRIDGE_UUID", NULL); + svSetValueString (ifcfg, "BRIDGE", NULL); + svSetValueString (ifcfg, "TEAM_MASTER_UUID", NULL); + svSetValueString (ifcfg, "TEAM_MASTER", NULL); + + master = nm_setting_connection_get_master (s_con); + if (master) { + /* The reader prefers the *_UUID variants, however we still try to resolve + * it into an interface name, so that legacy tooling is not confused. */ + if (!nm_utils_get_testing ()) { + /* This is conditional for easier testing. */ + master_iface = nm_manager_iface_for_uuid (nm_manager_get (), master); + } + if (!master_iface) { + master_iface = master; + master = NULL; + + } + + if (nm_setting_connection_is_slave_type (s_con, NM_SETTING_BOND_SETTING_NAME)) { + svSetValueString (ifcfg, "MASTER_UUID", master); + svSetValueString (ifcfg, "MASTER", master_iface); + svSetValueString (ifcfg, "SLAVE", "yes"); + } else if (nm_setting_connection_is_slave_type (s_con, NM_SETTING_BRIDGE_SETTING_NAME)) { + svSetValueString (ifcfg, "BRIDGE_UUID", master); + svSetValueString (ifcfg, "BRIDGE", master_iface); + } else if (nm_setting_connection_is_slave_type (s_con, NM_SETTING_TEAM_SETTING_NAME)) { + svSetValueString (ifcfg, "TEAM_MASTER_UUID", master); + svSetValueString (ifcfg, "TEAM_MASTER", master_iface); + svUnsetValue (ifcfg, "TYPE"); + } + } + + if (nm_streq0 (type, NM_SETTING_TEAM_SETTING_NAME)) + svSetValueString (ifcfg, "DEVICETYPE", TYPE_TEAM); + else if (master_iface && nm_setting_connection_is_slave_type (s_con, NM_SETTING_TEAM_SETTING_NAME)) + svSetValueString (ifcfg, "DEVICETYPE", TYPE_TEAM_PORT); + else + svUnsetValue (ifcfg, "DEVICETYPE"); + + /* secondary connection UUIDs */ + svUnsetValue (ifcfg, "SECONDARY_UUIDS"); + n = nm_setting_connection_get_num_secondaries (s_con); + if (n > 0) { + str = g_string_sized_new (n * 37); + + for (i = 0; i < n; i++) { + const char *uuid; + + /* Items separated by space for consistency with eg + * IPV6ADDR_SECONDARIES and DOMAIN. + */ + if (str->len) + g_string_append_c (str, ' '); + + if ((uuid = nm_setting_connection_get_secondary (s_con, i)) != NULL) + g_string_append (str, uuid); + } + svSetValueString (ifcfg, "SECONDARY_UUIDS", str->str); + g_string_free (str, TRUE); + } + + svUnsetValue (ifcfg, "GATEWAY_PING_TIMEOUT"); + if (nm_setting_connection_get_gateway_ping_timeout (s_con)) { + tmp = g_strdup_printf ("%" G_GUINT32_FORMAT, nm_setting_connection_get_gateway_ping_timeout (s_con)); + svSetValueString (ifcfg, "GATEWAY_PING_TIMEOUT", tmp); + g_free (tmp); + } + + switch (nm_setting_connection_get_metered (s_con)) { + case NM_METERED_YES: + svSetValueString (ifcfg, "CONNECTION_METERED", "yes"); + break; + case NM_METERED_NO: + svSetValueString (ifcfg, "CONNECTION_METERED", "no"); + break; + default: + svUnsetValue (ifcfg, "CONNECTION_METERED"); + } +} + +static gboolean +write_route_file_legacy (const char *filename, NMSettingIPConfig *s_ip4, GError **error) +{ + const char *dest, *next_hop; + char **route_items; + char *route_contents; + NMIPRoute *route; + guint32 prefix; + gint64 metric; + guint32 i, num; + gboolean success = FALSE; + + g_return_val_if_fail (filename != NULL, FALSE); + g_return_val_if_fail (s_ip4 != NULL, FALSE); + g_return_val_if_fail (error != NULL, FALSE); + g_return_val_if_fail (*error == NULL, FALSE); + + num = nm_setting_ip_config_get_num_routes (s_ip4); + if (num == 0) { + unlink (filename); + return TRUE; + } + + route_items = g_malloc0 (sizeof (char*) * (num + 1)); + for (i = 0; i < num; i++) { + route = nm_setting_ip_config_get_route (s_ip4, i); + + dest = nm_ip_route_get_dest (route); + prefix = nm_ip_route_get_prefix (route); + next_hop = nm_ip_route_get_next_hop (route); + metric = nm_ip_route_get_metric (route); + + if (metric == -1) + route_items[i] = g_strdup_printf ("%s/%u via %s\n", dest, prefix, next_hop); + else + route_items[i] = g_strdup_printf ("%s/%u via %s metric %u\n", dest, prefix, next_hop, (guint32) metric); + } + route_items[num] = NULL; + route_contents = g_strjoinv (NULL, route_items); + g_strfreev (route_items); + + if (!g_file_set_contents (filename, route_contents, -1, NULL)) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, + "Writing route file '%s' failed", filename); + goto error; + } + + success = TRUE; + +error: + g_free (route_contents); + + return success; +} + +static gboolean +write_proxy_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) +{ + NMSettingProxy *s_proxy; + NMSettingProxyMethod method; + const char *pac_url, *pac_script; + + s_proxy = nm_connection_get_setting_proxy (connection); + if (!s_proxy) + return TRUE; + + svUnsetValue (ifcfg, "BROWSER_ONLY"); + svUnsetValue (ifcfg, "PAC_URL"); + svUnsetValue (ifcfg, "PAC_SCRIPT"); + + method = nm_setting_proxy_get_method (s_proxy); + switch (method) { + case NM_SETTING_PROXY_METHOD_AUTO: + svSetValueString (ifcfg, "PROXY_METHOD", "auto"); + + pac_url = nm_setting_proxy_get_pac_url (s_proxy); + if (pac_url) + svSetValueString (ifcfg, "PAC_URL", pac_url); + + pac_script = nm_setting_proxy_get_pac_script (s_proxy); + if (pac_script) + svSetValueString (ifcfg, "PAC_SCRIPT", pac_script); + + break; + case NM_SETTING_PROXY_METHOD_NONE: + svSetValueString (ifcfg, "PROXY_METHOD", "none"); + break; + } + + svSetValueBoolean (ifcfg, "BROWSER_ONLY", nm_setting_proxy_get_browser_only (s_proxy)); + + return TRUE; +} + +static gboolean +write_ip4_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) +{ + NMSettingIPConfig *s_ip4; + const char *value; + char *addr_key, *prefix_key, *netmask_key, *gw_key, *metric_key, *tmp; + char *route_path = NULL; + gint32 j; + guint32 i, n, num; + gint64 route_metric; + gint priority; + int timeout; + GString *searches; + const char *method = NULL; + + s_ip4 = nm_connection_get_setting_ip4_config (connection); + if (!s_ip4) { + /* slave-type: clear IPv4 settings. + * + * Some IPv4 setting related options are not cleared, + * for no strong reason. */ + svUnsetValue (ifcfg, "BOOTPROTO"); + + svUnsetValue (ifcfg, "IPADDR"); + svUnsetValue (ifcfg, "PREFIX"); + svUnsetValue (ifcfg, "NETMASK"); + svUnsetValue (ifcfg, "GATEWAY"); + + svUnsetValue (ifcfg, "IPADDR0"); + svUnsetValue (ifcfg, "PREFIX0"); + svUnsetValue (ifcfg, "NETMASK0"); + svUnsetValue (ifcfg, "GATEWAY0"); + return TRUE; + } + + method = nm_setting_ip_config_get_method (s_ip4); + + /* Missing IP4 setting is assumed to be DHCP */ + if (!method) + method = NM_SETTING_IP4_CONFIG_METHOD_AUTO; + + if (!strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_DISABLED)) { + int result; + + /* IPv4 disabled, clear IPv4 related parameters */ + svUnsetValue (ifcfg, "BOOTPROTO"); + for (j = -1; j < 256; j++) { + if (j == -1) { + addr_key = g_strdup ("IPADDR"); + prefix_key = g_strdup ("PREFIX"); + netmask_key = g_strdup ("NETMASK"); + gw_key = g_strdup ("GATEWAY"); + } else { + addr_key = g_strdup_printf ("IPADDR%d", j); + prefix_key = g_strdup_printf ("PREFIX%d", j); + netmask_key = g_strdup_printf ("NETMASK%d", j); + gw_key = g_strdup_printf ("GATEWAY%d", j); + } + + svUnsetValue (ifcfg, addr_key); + svUnsetValue (ifcfg, prefix_key); + svUnsetValue (ifcfg, netmask_key); + svUnsetValue (ifcfg, gw_key); + + g_free (addr_key); + g_free (prefix_key); + g_free (netmask_key); + g_free (gw_key); + } + + route_path = utils_get_route_path (svFileGetName (ifcfg)); + result = unlink (route_path); + g_free (route_path); + return TRUE; + } + + if (!strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_AUTO)) + svSetValueString (ifcfg, "BOOTPROTO", "dhcp"); + else if (!strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_MANUAL)) + svSetValueString (ifcfg, "BOOTPROTO", "none"); + else if (!strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL)) + svSetValueString (ifcfg, "BOOTPROTO", "autoip"); + else if (!strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_SHARED)) + svSetValueString (ifcfg, "BOOTPROTO", "shared"); + + /* Clear out un-numbered IP address fields */ + svUnsetValue (ifcfg, "IPADDR"); + svUnsetValue (ifcfg, "PREFIX"); + svUnsetValue (ifcfg, "NETMASK"); + svUnsetValue (ifcfg, "GATEWAY"); + /* Clear out zero-indexed IP address fields */ + svUnsetValue (ifcfg, "IPADDR0"); + svUnsetValue (ifcfg, "PREFIX0"); + svUnsetValue (ifcfg, "NETMASK0"); + svUnsetValue (ifcfg, "GATEWAY0"); + + /* Write out IPADDR, PREFIX, GATEWAY for current IP addresses + * without labels. Unset obsolete NETMASK. + */ + num = nm_setting_ip_config_get_num_addresses (s_ip4); + for (i = n = 0; i < num; i++) { + NMIPAddress *addr; + + addr = nm_setting_ip_config_get_address (s_ip4, i); + + if (i > 0) { + GVariant *label; + + label = nm_ip_address_get_attribute (addr, "label"); + if (label) + continue; + } + + if (n == 0) { + /* Instead of index 0 use un-numbered variables. + * It's needed for compatibility with ifup that only recognizes 'GATEAWAY' + * See https://bugzilla.redhat.com/show_bug.cgi?id=771673 + * and https://bugzilla.redhat.com/show_bug.cgi?id=1105770 + */ + addr_key = g_strdup ("IPADDR"); + prefix_key = g_strdup ("PREFIX"); + netmask_key = g_strdup ("NETMASK"); + gw_key = g_strdup ("GATEWAY"); + } else { + addr_key = g_strdup_printf ("IPADDR%d", n); + prefix_key = g_strdup_printf ("PREFIX%d", n); + netmask_key = g_strdup_printf ("NETMASK%d", n); + gw_key = g_strdup_printf ("GATEWAY%d", n); + } + + svSetValueString (ifcfg, addr_key, nm_ip_address_get_address (addr)); + + tmp = g_strdup_printf ("%u", nm_ip_address_get_prefix (addr)); + svSetValueString (ifcfg, prefix_key, tmp); + g_free (tmp); + + svUnsetValue (ifcfg, netmask_key); + svUnsetValue (ifcfg, gw_key); + + g_free (addr_key); + g_free (prefix_key); + g_free (netmask_key); + g_free (gw_key); + n++; + } + + /* Clear remaining IPADDR, etc */ + for (; n < 256; n++) { + addr_key = g_strdup_printf ("IPADDR%d", n); + prefix_key = g_strdup_printf ("PREFIX%d", n); + netmask_key = g_strdup_printf ("NETMASK%d", n); + gw_key = g_strdup_printf ("GATEWAY%d", n); + + svUnsetValue (ifcfg, addr_key); + svUnsetValue (ifcfg, prefix_key); + svUnsetValue (ifcfg, netmask_key); + svUnsetValue (ifcfg, gw_key); + + g_free (addr_key); + g_free (prefix_key); + g_free (netmask_key); + g_free (gw_key); + } + + svSetValueString (ifcfg, "GATEWAY", nm_setting_ip_config_get_gateway (s_ip4)); + + num = nm_setting_ip_config_get_num_dns (s_ip4); + for (i = 0; i < 254; i++) { + const char *dns; + + addr_key = g_strdup_printf ("DNS%d", i + 1); + + if (i >= num) + svUnsetValue (ifcfg, addr_key); + else { + dns = nm_setting_ip_config_get_dns (s_ip4, i); + svSetValueString (ifcfg, addr_key, dns); + } + g_free (addr_key); + } + + num = nm_setting_ip_config_get_num_dns_searches (s_ip4); + if (num > 0) { + searches = g_string_new (NULL); + for (i = 0; i < num; i++) { + if (i > 0) + g_string_append_c (searches, ' '); + g_string_append (searches, nm_setting_ip_config_get_dns_search (s_ip4, i)); + } + svSetValueString (ifcfg, "DOMAIN", searches->str); + g_string_free (searches, TRUE); + } else + svUnsetValue (ifcfg, "DOMAIN"); + + /* DEFROUTE; remember that it has the opposite meaning from never-default */ + svSetValueBoolean (ifcfg, "DEFROUTE", !nm_setting_ip_config_get_never_default (s_ip4)); + + /* Missing PEERDNS means TRUE, so write it only when is FALSE */ + svSetValueString (ifcfg, "PEERDNS", + nm_setting_ip_config_get_ignore_auto_dns (s_ip4) ? "no" : NULL); + /* Missing PEERROUTES means TRUE, so write it only when is FALSE */ + svSetValueString (ifcfg, "PEERROUTES", + nm_setting_ip_config_get_ignore_auto_routes (s_ip4) ? "no" : NULL); + + value = nm_setting_ip_config_get_dhcp_hostname (s_ip4); + svSetValueString (ifcfg, "DHCP_HOSTNAME", value); + + value = nm_setting_ip4_config_get_dhcp_fqdn (NM_SETTING_IP4_CONFIG (s_ip4)); + svSetValueString (ifcfg, "DHCP_FQDN", value); + + /* Missing DHCP_SEND_HOSTNAME means TRUE, and we prefer not write it explicitly + * in that case, because it is NM-specific variable + */ + svSetValueString (ifcfg, "DHCP_SEND_HOSTNAME", + nm_setting_ip_config_get_dhcp_send_hostname (s_ip4) ? NULL : "no"); + + value = nm_setting_ip4_config_get_dhcp_client_id (NM_SETTING_IP4_CONFIG (s_ip4)); + svSetValueString (ifcfg, "DHCP_CLIENT_ID", value); + + timeout = nm_setting_ip_config_get_dhcp_timeout (s_ip4); + tmp = timeout ? g_strdup_printf ("%d", timeout) : NULL; + svSetValueString (ifcfg, "IPV4_DHCP_TIMEOUT", tmp); + g_free (tmp); + + svSetValueBoolean (ifcfg, "IPV4_FAILURE_FATAL", !nm_setting_ip_config_get_may_fail (s_ip4)); + + route_metric = nm_setting_ip_config_get_route_metric (s_ip4); + tmp = route_metric != -1 ? g_strdup_printf ("%"G_GINT64_FORMAT, route_metric) : NULL; + svSetValueString (ifcfg, "IPV4_ROUTE_METRIC", tmp); + g_free (tmp); + + /* Static routes - route- file */ + route_path = utils_get_route_path (svFileGetName (ifcfg)); + if (!route_path) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, + "Could not get route file path for '%s'", svFileGetName (ifcfg)); + return FALSE; + } + + if (utils_has_route_file_new_syntax (route_path)) { + shvarFile *routefile; + + routefile = utils_get_route_ifcfg (svFileGetName (ifcfg), TRUE); + if (!routefile) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, + "Could not create route file '%s'", route_path); + g_free (route_path); + return FALSE; + } + g_free (route_path); + + num = nm_setting_ip_config_get_num_routes (s_ip4); + for (i = 0; i < 256; i++) { + char buf[INET_ADDRSTRLEN]; + NMIPRoute *route; + guint32 netmask; + gint64 metric; + + addr_key = g_strdup_printf ("ADDRESS%d", i); + netmask_key = g_strdup_printf ("NETMASK%d", i); + gw_key = g_strdup_printf ("GATEWAY%d", i); + metric_key = g_strdup_printf ("METRIC%d", i); + + if (i >= num) { + svUnsetValue (routefile, addr_key); + svUnsetValue (routefile, netmask_key); + svUnsetValue (routefile, gw_key); + svUnsetValue (routefile, metric_key); + } else { + route = nm_setting_ip_config_get_route (s_ip4, i); + + svSetValueString (routefile, addr_key, nm_ip_route_get_dest (route)); + + memset (buf, 0, sizeof (buf)); + netmask = nm_utils_ip4_prefix_to_netmask (nm_ip_route_get_prefix (route)); + inet_ntop (AF_INET, (const void *) &netmask, &buf[0], sizeof (buf)); + svSetValueString (routefile, netmask_key, &buf[0]); + + svSetValueString (routefile, gw_key, nm_ip_route_get_next_hop (route)); + + memset (buf, 0, sizeof (buf)); + metric = nm_ip_route_get_metric (route); + if (metric == -1) + svUnsetValue (routefile, metric_key); + else { + tmp = g_strdup_printf ("%u", (guint32) metric); + svSetValueString (routefile, metric_key, tmp); + g_free (tmp); + } + } + + g_free (addr_key); + g_free (netmask_key); + g_free (gw_key); + g_free (metric_key); + } + if (!svWriteFile (routefile, 0644, error)) { + svCloseFile (routefile); + return FALSE; + } + svCloseFile (routefile); + } else { + write_route_file_legacy (route_path, s_ip4, error); + g_free (route_path); + if (error && *error) + return FALSE; + } + + timeout = nm_setting_ip_config_get_dad_timeout (s_ip4); + if (timeout < 0) + svUnsetValue (ifcfg, "ARPING_WAIT"); + else if (timeout == 0) + svSetValueString (ifcfg, "ARPING_WAIT", "0"); + else { + /* Round the value up to next integer */ + svSetValueInt64 (ifcfg, "ARPING_WAIT", (timeout - 1) / 1000 + 1); + } + + priority = nm_setting_ip_config_get_dns_priority (s_ip4); + if (priority) + svSetValueInt64 (ifcfg, "IPV4_DNS_PRIORITY", priority); + else + svUnsetValue (ifcfg, "IPV4_DNS_PRIORITY"); + + return TRUE; +} + +static void +write_ip4_aliases (NMConnection *connection, char *base_ifcfg_path) +{ + NMSettingIPConfig *s_ip4; + gs_free char *base_ifcfg_dir = NULL, *base_ifcfg_name = NULL; + const char*base_name; + int i, num, base_ifcfg_name_len, base_name_len; + GDir *dir; + + base_ifcfg_dir = g_path_get_dirname (base_ifcfg_path); + base_ifcfg_name = g_path_get_basename (base_ifcfg_path); + base_ifcfg_name_len = strlen (base_ifcfg_name); + if (!g_str_has_prefix (base_ifcfg_name, IFCFG_TAG)) + g_return_if_reached (); + base_name = base_ifcfg_name + strlen (IFCFG_TAG); + base_name_len = strlen (base_name); + + /* Remove all existing aliases for this file first */ + dir = g_dir_open (base_ifcfg_dir, 0, NULL); + if (dir) { + const char *item; + + while ((item = g_dir_read_name (dir))) { + char *full_path; + + if ( strncmp (item, base_ifcfg_name, base_ifcfg_name_len) != 0 + || item[base_ifcfg_name_len] != ':') + continue; + + full_path = g_build_filename (base_ifcfg_dir, item, NULL); + unlink (full_path); + g_free (full_path); + } + + g_dir_close (dir); + } + + s_ip4 = nm_connection_get_setting_ip4_config (connection); + if (!s_ip4) { + /* slave-type: no alias files */ + return; + } + + num = nm_setting_ip_config_get_num_addresses (s_ip4); + for (i = 0; i < num; i++) { + GVariant *label_var; + const char *label, *p; + char *path, *tmp; + NMIPAddress *addr; + shvarFile *ifcfg; + + addr = nm_setting_ip_config_get_address (s_ip4, i); + + label_var = nm_ip_address_get_attribute (addr, "label"); + if (!label_var) + continue; + label = g_variant_get_string (label_var, NULL); + if ( strncmp (label, base_name, base_name_len) != 0 + || label[base_name_len] != ':') + continue; + + for (p = label; *p; p++) { + if (!g_ascii_isalnum (*p) && *p != '_' && *p != ':') + break; + } + if (*p) + continue; + + path = g_strdup_printf ("%s%s", base_ifcfg_path, label + base_name_len); + ifcfg = svCreateFile (path); + g_free (path); + + svSetValueString (ifcfg, "DEVICE", label); + + addr = nm_setting_ip_config_get_address (s_ip4, i); + svSetValueString (ifcfg, "IPADDR", nm_ip_address_get_address (addr)); + + tmp = g_strdup_printf ("%u", nm_ip_address_get_prefix (addr)); + svSetValueString (ifcfg, "PREFIX", tmp); + g_free (tmp); + + svWriteFile (ifcfg, 0644, NULL); + svCloseFile (ifcfg); + } +} + +static gboolean +write_route6_file (const char *filename, NMSettingIPConfig *s_ip6, GError **error) +{ + char **route_items; + char *route_contents; + NMIPRoute *route; + guint32 i, num; + gboolean success = FALSE; + + g_return_val_if_fail (filename != NULL, FALSE); + g_return_val_if_fail (s_ip6 != NULL, FALSE); + g_return_val_if_fail (error != NULL, FALSE); + g_return_val_if_fail (*error == NULL, FALSE); + + num = nm_setting_ip_config_get_num_routes (s_ip6); + if (num == 0) { + unlink (filename); + return TRUE; + } + + route_items = g_malloc0 (sizeof (char*) * (num + 1)); + for (i = 0; i < num; i++) { + route = nm_setting_ip_config_get_route (s_ip6, i); + + if (nm_ip_route_get_metric (route) == -1) { + route_items[i] = g_strdup_printf ("%s/%u via %s\n", + nm_ip_route_get_dest (route), + nm_ip_route_get_prefix (route), + nm_ip_route_get_next_hop (route)); + } else { + route_items[i] = g_strdup_printf ("%s/%u via %s metric %u\n", + nm_ip_route_get_dest (route), + nm_ip_route_get_prefix (route), + nm_ip_route_get_next_hop (route), + (guint32) nm_ip_route_get_metric (route)); + } + } + route_items[num] = NULL; + route_contents = g_strjoinv (NULL, route_items); + g_strfreev (route_items); + + if (!g_file_set_contents (filename, route_contents, -1, NULL)) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, + "Writing route6 file '%s' failed", filename); + goto error; + } + + success = TRUE; + +error: + g_free (route_contents); + return success; +} + +static void +write_ip6_setting_dhcp_hostname (NMSettingIPConfig *s_ip6, shvarFile *ifcfg) +{ + const char *hostname; + + hostname = nm_setting_ip_config_get_dhcp_hostname (s_ip6); + svSetValueString (ifcfg, "DHCPV6_HOSTNAME", hostname); + + /* Missing DHCPV6_SEND_HOSTNAME means TRUE, and we prefer not write it + * explicitly in that case, because it is NM-specific variable + */ + if (nm_setting_ip_config_get_dhcp_send_hostname (s_ip6)) + svUnsetValue (ifcfg, "DHCPV6_SEND_HOSTNAME"); + else + svSetValueString (ifcfg, "DHCPV6_SEND_HOSTNAME", "no"); +} + +static gboolean +write_ip6_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) +{ + NMSettingIPConfig *s_ip6; + NMSettingIPConfig *s_ip4; + const char *value; + char *addr_key; + char *tmp; + guint32 i, num, num4; + gint priority; + GString *searches; + NMIPAddress *addr; + const char *dns; + gint64 route_metric; + GString *ip_str1, *ip_str2, *ip_ptr; + char *route6_path; + NMSettingIP6ConfigAddrGenMode addr_gen_mode; + + s_ip6 = nm_connection_get_setting_ip6_config (connection); + if (!s_ip6) { + /* slave-type: clear IPv6 settings + * + * Some IPv6 setting related options are not cleared, + * for no strong reason. */ + svUnsetValue (ifcfg, "IPV6INIT"); + svUnsetValue (ifcfg, "IPV6_AUTOCONF"); + svUnsetValue (ifcfg, "DHCPV6C"); + svUnsetValue (ifcfg, "DHCPV6_HOSTNAME"); + svUnsetValue (ifcfg, "DHCPV6_SEND_HOSTNAME"); + svUnsetValue (ifcfg, "IPV6_DEFROUTE"); + svUnsetValue (ifcfg, "IPV6_PEERDNS"); + svUnsetValue (ifcfg, "IPV6_PEERROUTES"); + svUnsetValue (ifcfg, "IPV6_FAILURE_FATAL"); + svUnsetValue (ifcfg, "IPV6_ROUTE_METRIC"); + svUnsetValue (ifcfg, "IPV6_ADDR_GEN_MODE"); + return TRUE; + } + + value = nm_setting_ip_config_get_method (s_ip6); + g_assert (value); + if (!strcmp (value, NM_SETTING_IP6_CONFIG_METHOD_IGNORE)) { + svSetValueString (ifcfg, "IPV6INIT", "no"); + svUnsetValue (ifcfg, "DHCPV6C"); + return TRUE; + } else if (!strcmp (value, NM_SETTING_IP6_CONFIG_METHOD_AUTO)) { + svSetValueString (ifcfg, "IPV6INIT", "yes"); + svSetValueString (ifcfg, "IPV6_AUTOCONF", "yes"); + svUnsetValue (ifcfg, "DHCPV6C"); + } else if (!strcmp (value, NM_SETTING_IP6_CONFIG_METHOD_DHCP)) { + svSetValueString (ifcfg, "IPV6INIT", "yes"); + svSetValueString (ifcfg, "IPV6_AUTOCONF", "no"); + svSetValueString (ifcfg, "DHCPV6C", "yes"); + } else if (!strcmp (value, NM_SETTING_IP6_CONFIG_METHOD_MANUAL)) { + svSetValueString (ifcfg, "IPV6INIT", "yes"); + svSetValueString (ifcfg, "IPV6_AUTOCONF", "no"); + svUnsetValue (ifcfg, "DHCPV6C"); + } else if (!strcmp (value, NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL)) { + svSetValueString (ifcfg, "IPV6INIT", "yes"); + svSetValueString (ifcfg, "IPV6_AUTOCONF", "no"); + svUnsetValue (ifcfg, "DHCPV6C"); + } else if (!strcmp (value, NM_SETTING_IP6_CONFIG_METHOD_SHARED)) { + svSetValueString (ifcfg, "IPV6INIT", "yes"); + svSetValueString (ifcfg, "IPV6_AUTOCONF", "shared"); + svUnsetValue (ifcfg, "DHCPV6C"); + } + + write_ip6_setting_dhcp_hostname (s_ip6, ifcfg); + + /* Write out IP addresses */ + num = nm_setting_ip_config_get_num_addresses (s_ip6); + ip_str1 = g_string_new (NULL); + ip_str2 = g_string_new (NULL); + for (i = 0; i < num; i++) { + if (i == 0) + ip_ptr = ip_str1; + else + ip_ptr = ip_str2; + + addr = nm_setting_ip_config_get_address (s_ip6, i); + + if (i > 1) + g_string_append_c (ip_ptr, ' '); /* separate addresses in IPV6ADDR_SECONDARIES */ + g_string_append_printf (ip_ptr, "%s/%u", + nm_ip_address_get_address (addr), + nm_ip_address_get_prefix (addr)); + } + svSetValueString (ifcfg, "IPV6ADDR", ip_str1->str); + svSetValueString (ifcfg, "IPV6ADDR_SECONDARIES", ip_str2->str); + svSetValueString (ifcfg, "IPV6_DEFAULTGW", nm_setting_ip_config_get_gateway (s_ip6)); + g_string_free (ip_str1, TRUE); + g_string_free (ip_str2, TRUE); + + /* Write out DNS - 'DNS' key is used both for IPv4 and IPv6 */ + s_ip4 = nm_connection_get_setting_ip4_config (connection); + num4 = s_ip4 ? nm_setting_ip_config_get_num_dns (s_ip4) : 0; /* from where to start with IPv6 entries */ + num = nm_setting_ip_config_get_num_dns (s_ip6); + for (i = 0; i < 254; i++) { + addr_key = g_strdup_printf ("DNS%d", i + num4 + 1); + + if (i >= num) + svUnsetValue (ifcfg, addr_key); + else { + dns = nm_setting_ip_config_get_dns (s_ip6, i); + svSetValueString (ifcfg, addr_key, dns); + } + g_free (addr_key); + } + + /* Write out DNS domains - 'DOMAIN' key is shared for both IPv4 and IPv6 domains */ + num = nm_setting_ip_config_get_num_dns_searches (s_ip6); + if (num > 0) { + char *ip4_domains; + ip4_domains = svGetValueString (ifcfg, "DOMAIN"); + searches = g_string_new (ip4_domains); + for (i = 0; i < num; i++) { + if (searches->len > 0) + g_string_append_c (searches, ' '); + g_string_append (searches, nm_setting_ip_config_get_dns_search (s_ip6, i)); + } + svSetValueString (ifcfg, "DOMAIN", searches->str); + g_string_free (searches, TRUE); + g_free (ip4_domains); + } + + + /* handle IPV6_DEFROUTE */ + /* IPV6_DEFROUTE has the opposite meaning from 'never-default' */ + if (nm_setting_ip_config_get_never_default(s_ip6)) + svSetValueString (ifcfg, "IPV6_DEFROUTE", "no"); + else + svSetValueString (ifcfg, "IPV6_DEFROUTE", "yes"); + + svSetValueString (ifcfg, "IPV6_PEERDNS", + nm_setting_ip_config_get_ignore_auto_dns (s_ip6) ? "no" : NULL); + + svSetValueString (ifcfg, "IPV6_PEERROUTES", + nm_setting_ip_config_get_ignore_auto_routes (s_ip6) ? "no" : NULL); + + svSetValueString (ifcfg, "IPV6_FAILURE_FATAL", + nm_setting_ip_config_get_may_fail (s_ip6) ? "no" : "yes"); + + route_metric = nm_setting_ip_config_get_route_metric (s_ip6); + tmp = route_metric != -1 ? g_strdup_printf ("%"G_GINT64_FORMAT, route_metric) : NULL; + svSetValueString (ifcfg, "IPV6_ROUTE_METRIC", tmp); + g_free (tmp); + + /* IPv6 Privacy Extensions */ + svUnsetValue (ifcfg, "IPV6_PRIVACY"); + svUnsetValue (ifcfg, "IPV6_PRIVACY_PREFER_PUBLIC_IP"); + switch (nm_setting_ip6_config_get_ip6_privacy (NM_SETTING_IP6_CONFIG (s_ip6))){ + case NM_SETTING_IP6_CONFIG_PRIVACY_DISABLED: + svSetValueString (ifcfg, "IPV6_PRIVACY", "no"); + break; + case NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_PUBLIC_ADDR: + svSetValueString (ifcfg, "IPV6_PRIVACY", "rfc3041"); + svSetValueString (ifcfg, "IPV6_PRIVACY_PREFER_PUBLIC_IP", "yes"); + break; + case NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_TEMP_ADDR: + svSetValueString (ifcfg, "IPV6_PRIVACY", "rfc3041"); + break; + default: + break; + } + + /* IPv6 Address generation mode */ + addr_gen_mode = nm_setting_ip6_config_get_addr_gen_mode (NM_SETTING_IP6_CONFIG (s_ip6)); + if (addr_gen_mode != NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE_EUI64) { + tmp = nm_utils_enum_to_str (nm_setting_ip6_config_addr_gen_mode_get_type (), + addr_gen_mode); + svSetValueString (ifcfg, "IPV6_ADDR_GEN_MODE", tmp); + g_free (tmp); + } else { + svUnsetValue (ifcfg, "IPV6_ADDR_GEN_MODE"); + } + + /* IPv6 tokenized interface identifier */ + value = nm_setting_ip6_config_get_token (NM_SETTING_IP6_CONFIG (s_ip6)); + svSetValueString (ifcfg, "IPV6_TOKEN", value); + + priority = nm_setting_ip_config_get_dns_priority (s_ip6); + if (priority) + svSetValueInt64 (ifcfg, "IPV6_DNS_PRIORITY", priority); + else + svUnsetValue (ifcfg, "IPV6_DNS_PRIORITY"); + + /* Static routes go to route6- file */ + route6_path = utils_get_route6_path (svFileGetName (ifcfg)); + if (!route6_path) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, + "Could not get route6 file path for '%s'", svFileGetName (ifcfg)); + goto error; + } + write_route6_file (route6_path, s_ip6, error); + g_free (route6_path); + if (error && *error) + goto error; + + return TRUE; + +error: + return FALSE; +} + +static void +add_dns_option (GPtrArray *array, const char *option) +{ + if (_nm_utils_dns_option_find_idx (array, option) < 0) + g_ptr_array_add (array, (gpointer) option); +} + +static gboolean +write_res_options (NMConnection *connection, shvarFile *ifcfg, GError **error) +{ + NMSettingIPConfig *s_ip6; + NMSettingIPConfig *s_ip4; + const char *method; + int i, num_options; + gs_unref_ptrarray GPtrArray *array = NULL; + GString *value; + + s_ip4 = nm_connection_get_setting_ip4_config (connection); + + if (!s_ip4) { + /* slave-type: clear res-options */ + svUnsetValue (ifcfg, "RES_OPTIONS"); + return TRUE; + } + + array = g_ptr_array_new (); + + method = nm_setting_ip_config_get_method (s_ip4); + if (g_strcmp0 (method, NM_SETTING_IP4_CONFIG_METHOD_DISABLED)) { + num_options = nm_setting_ip_config_get_num_dns_options (s_ip4); + for (i = 0; i < num_options; i++) + add_dns_option (array, nm_setting_ip_config_get_dns_option (s_ip4, i)); + } + + s_ip6 = nm_connection_get_setting_ip6_config (connection); + method = nm_setting_ip_config_get_method (s_ip6); + if (g_strcmp0 (method, NM_SETTING_IP6_CONFIG_METHOD_IGNORE)) { + num_options = nm_setting_ip_config_get_num_dns_options (s_ip6); + for (i = 0; i < num_options; i++) + add_dns_option (array, nm_setting_ip_config_get_dns_option (s_ip6, i)); + } + + if ( array->len > 0 + || nm_setting_ip_config_has_dns_options (s_ip4) + || nm_setting_ip_config_has_dns_options (s_ip6)) { + value = g_string_new (NULL); + for (i = 0; i < array->len; i++) { + if (i > 0) + g_string_append_c (value, ' '); + g_string_append (value, array->pdata[i]); + } + svSetValue (ifcfg, "RES_OPTIONS", value->str); + g_string_free (value, TRUE); + } else + svUnsetValue (ifcfg, "RES_OPTIONS"); + + return TRUE; +} + +static char * +escape_id (const char *id) +{ + char *escaped = g_strdup (id); + char *p = escaped; + + /* Escape random stuff */ + while (*p) { + if (*p == ' ') + *p = '_'; + else if (strchr ("\\][|/=()!:", *p)) + *p = '-'; + p++; + } + + return escaped; +} + +static gboolean +write_connection (NMConnection *connection, + const char *ifcfg_dir, + const char *filename, + char **out_filename, + GError **error) +{ + NMSettingConnection *s_con; + gboolean success = FALSE; + shvarFile *ifcfg = NULL; + char *ifcfg_name = NULL; + const char *type; + gboolean no_8021x = FALSE; + gboolean wired = FALSE; + + nm_assert (NM_IS_CONNECTION (connection)); + nm_assert (nm_connection_verify (connection, NULL)); + + if (!writer_can_write_connection (connection, error)) + return FALSE; + + s_con = nm_connection_get_setting_connection (connection); + g_assert (s_con); + + if (filename) { + /* For existing connections, 'filename' should be full path to ifcfg file */ + ifcfg = svOpenFile (filename, error); + if (!ifcfg) + return FALSE; + + ifcfg_name = g_strdup (filename); + } else { + char *escaped; + + escaped = escape_id (nm_setting_connection_get_id (s_con)); + ifcfg_name = g_strdup_printf ("%s/ifcfg-%s", ifcfg_dir, escaped); + + /* If a file with this path already exists then we need another name. + * Multiple connections can have the same ID (ie if two connections with + * the same ID are visible to different users) but of course can't have + * the same path. + */ + if (g_file_test (ifcfg_name, G_FILE_TEST_EXISTS)) { + guint32 idx = 0; + + g_free (ifcfg_name); + while (idx++ < 500) { + ifcfg_name = g_strdup_printf ("%s/ifcfg-%s-%u", ifcfg_dir, escaped, idx); + if (g_file_test (ifcfg_name, G_FILE_TEST_EXISTS) == FALSE) + break; + g_free (ifcfg_name); + ifcfg_name = NULL; + } + } + g_free (escaped); + + if (ifcfg_name == NULL) { + g_set_error_literal (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, + "Failed to find usable ifcfg file name"); + return FALSE; + } + + ifcfg = svCreateFile (ifcfg_name); + } + + type = nm_setting_connection_get_connection_type (s_con); + if (!type) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, + "Missing connection type!"); + goto out; + } + + if (!strcmp (type, NM_SETTING_WIRED_SETTING_NAME)) { + // FIXME: can't write PPPoE at this time + if (nm_connection_get_setting_pppoe (connection)) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, + "Can't write connection type '%s'", + NM_SETTING_PPPOE_SETTING_NAME); + goto out; + } + + if (!write_wired_setting (connection, ifcfg, error)) + goto out; + wired = TRUE; + } else if (!strcmp (type, NM_SETTING_VLAN_SETTING_NAME)) { + if (!write_vlan_setting (connection, ifcfg, &wired, error)) + goto out; + } else if (!strcmp (type, NM_SETTING_WIRELESS_SETTING_NAME)) { + if (!write_wireless_setting (connection, ifcfg, &no_8021x, error)) + goto out; + } else if (!strcmp (type, NM_SETTING_INFINIBAND_SETTING_NAME)) { + if (!write_infiniband_setting (connection, ifcfg, error)) + goto out; + } else if (!strcmp (type, NM_SETTING_BOND_SETTING_NAME)) { + if (!write_bonding_setting (connection, ifcfg, &wired, error)) + goto out; + } else if (!strcmp (type, NM_SETTING_TEAM_SETTING_NAME)) { + if (!write_team_setting (connection, ifcfg, &wired, error)) + goto out; + } else if (!strcmp (type, NM_SETTING_BRIDGE_SETTING_NAME)) { + if (!write_bridge_setting (connection, ifcfg, error)) + goto out; + } else { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, + "Can't write connection type '%s'", type); + goto out; + } + + if (!no_8021x) { + if (!write_8021x_setting (connection, ifcfg, wired, error)) + goto out; + } + + if (!write_bridge_port_setting (connection, ifcfg, error)) + goto out; + + if (!write_team_port_setting (connection, ifcfg, error)) + goto out; + + if (!write_dcb_setting (connection, ifcfg, error)) + goto out; + + if (!write_proxy_setting (connection, ifcfg, error)) + goto out; + + svUnsetValue (ifcfg, "DHCP_HOSTNAME"); + svUnsetValue (ifcfg, "DHCP_FQDN"); + + if (!write_ip4_setting (connection, ifcfg, error)) + goto out; + write_ip4_aliases (connection, ifcfg_name); + + if (!write_ip6_setting (connection, ifcfg, error)) + goto out; + + if (!write_res_options (connection, ifcfg, error)) + goto out; + + write_connection_setting (s_con, ifcfg); + + if (!svWriteFile (ifcfg, 0644, error)) + goto out; + + /* Only return the filename if this was a newly written ifcfg */ + if (out_filename && !filename) + *out_filename = g_strdup (ifcfg_name); + + success = TRUE; + +out: + if (ifcfg) + svCloseFile (ifcfg); + g_free (ifcfg_name); + return success; +} + +gboolean +writer_can_write_connection (NMConnection *connection, GError **error) +{ + NMSettingConnection *s_con; + + if ( ( nm_connection_is_type (connection, NM_SETTING_WIRED_SETTING_NAME) + && !nm_connection_get_setting_pppoe (connection)) + || nm_connection_is_type (connection, NM_SETTING_VLAN_SETTING_NAME) + || nm_connection_is_type (connection, NM_SETTING_WIRELESS_SETTING_NAME) + || nm_connection_is_type (connection, NM_SETTING_INFINIBAND_SETTING_NAME) + || nm_connection_is_type (connection, NM_SETTING_BOND_SETTING_NAME) + || nm_connection_is_type (connection, NM_SETTING_TEAM_SETTING_NAME) + || nm_connection_is_type (connection, NM_SETTING_BRIDGE_SETTING_NAME)) + return TRUE; + + s_con = nm_connection_get_setting_connection (connection); + g_assert (s_con); + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, + "The ifcfg-rh plugin cannot write the connection '%s' (type '%s' pppoe %d)", + nm_connection_get_id (connection), + nm_setting_connection_get_connection_type (s_con), + !!nm_connection_get_setting_pppoe (connection)); + return FALSE; +} + +gboolean +writer_new_connection (NMConnection *connection, + const char *ifcfg_dir, + char **out_filename, + GError **error) +{ + return write_connection (connection, ifcfg_dir, NULL, out_filename, error); +} + +gboolean +writer_update_connection (NMConnection *connection, + const char *ifcfg_dir, + const char *filename, + GError **error) +{ + if (utils_has_complex_routes (filename)) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, + "Cannot modify a connection that has an associated 'rule-' or 'rule6-' file"); + return FALSE; + } + + return write_connection (connection, ifcfg_dir, filename, NULL, error); +} + diff --git a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.h b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.h new file mode 100644 index 00000000..2662f79b --- /dev/null +++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.h @@ -0,0 +1,39 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/* NetworkManager system settings service - keyfile plugin + * + * 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) 2009 Red Hat, Inc. + */ + +#ifndef _WRITER_H_ +#define _WRITER_H_ + +#include "nm-connection.h" + +gboolean writer_can_write_connection (NMConnection *connection, + GError **error); + +gboolean writer_new_connection (NMConnection *connection, + const char *ifcfg_dir, + char **out_filename, + GError **error); + +gboolean writer_update_connection (NMConnection *connection, + const char *ifcfg_dir, + const char *filename, + GError **error); + +#endif /* _WRITER_H_ */ diff --git a/src/settings/plugins/ifcfg-rh/plugin.c b/src/settings/plugins/ifcfg-rh/plugin.c deleted file mode 100644 index c2956d22..00000000 --- a/src/settings/plugins/ifcfg-rh/plugin.c +++ /dev/null @@ -1,1080 +0,0 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* NetworkManager system settings service - * - * Dan Williams - * Søren Sandmann - * - * 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) 2007 - 2011 Red Hat, Inc. - */ - -#include "nm-default.h" - -#include "plugin.h" - -#include -#include -#include -#include -#include - -#include - -#include "nm-dbus-compat.h" -#include "nm-setting-connection.h" - -#include "nm-settings-plugin.h" -#include "nm-config.h" -#include "NetworkManagerUtils.h" - -#include "nm-ifcfg-connection.h" -#include "shvar.h" -#include "common.h" -#include "reader.h" -#include "writer.h" -#include "utils.h" -#include "nm-exported-object.h" - -#include "nmdbus-ifcfg-rh.h" - -#define IFCFGRH1_DBUS_SERVICE_NAME "com.redhat.ifcfgrh1" -#define IFCFGRH1_DBUS_OBJECT_PATH "/com/redhat/ifcfgrh1" - -#define _NMLOG_DOMAIN LOGD_SETTINGS -#define _NMLOG(level, ...) \ - G_STMT_START { \ - nm_log ((level), (_NMLOG_DOMAIN), \ - "%s" _NM_UTILS_MACRO_FIRST(__VA_ARGS__), \ - "ifcfg-rh: " \ - _NM_UTILS_MACRO_REST(__VA_ARGS__)); \ - } G_STMT_END - - -static NMIfcfgConnection *update_connection (SettingsPluginIfcfg *plugin, - NMConnection *source, - const char *full_path, - NMIfcfgConnection *connection, - gboolean protect_existing_connection, - GHashTable *protected_connections, - GError **error); - -static void settings_plugin_interface_init (NMSettingsPluginInterface *plugin_iface); - -G_DEFINE_TYPE_EXTENDED (SettingsPluginIfcfg, settings_plugin_ifcfg, G_TYPE_OBJECT, 0, - G_IMPLEMENT_INTERFACE (NM_TYPE_SETTINGS_PLUGIN, - settings_plugin_interface_init)) - -#define SETTINGS_PLUGIN_IFCFG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), SETTINGS_TYPE_PLUGIN_IFCFG, SettingsPluginIfcfgPrivate)) - - -typedef struct { - NMConfig *config; - - struct { - GDBusConnection *connection; - GDBusInterfaceSkeleton *interface; - GCancellable *cancellable; - gulong signal_id; - } dbus; - - GHashTable *connections; /* uuid::connection */ - gboolean initialized; - - GFileMonitor *ifcfg_monitor; - gulong ifcfg_monitor_id; -} SettingsPluginIfcfgPrivate; - -static SettingsPluginIfcfg *settings_plugin_ifcfg_get (void); -NM_DEFINE_SINGLETON_GETTER (SettingsPluginIfcfg, settings_plugin_ifcfg_get, SETTINGS_TYPE_PLUGIN_IFCFG); - -static void -connection_ifcfg_changed (NMIfcfgConnection *connection, gpointer user_data) -{ - SettingsPluginIfcfg *self = SETTINGS_PLUGIN_IFCFG (user_data); - SettingsPluginIfcfgPrivate *priv = SETTINGS_PLUGIN_IFCFG_GET_PRIVATE (self); - const char *path; - - path = nm_settings_connection_get_filename (NM_SETTINGS_CONNECTION (connection)); - g_return_if_fail (path != NULL); - - - if (!priv->ifcfg_monitor) { - _LOGD ("connection_ifcfg_changed("NM_IFCFG_CONNECTION_LOG_FMTD"): %s", NM_IFCFG_CONNECTION_LOG_ARGD (connection), "ignore event"); - return; - } - - _LOGD ("connection_ifcfg_changed("NM_IFCFG_CONNECTION_LOG_FMTD"): %s", NM_IFCFG_CONNECTION_LOG_ARGD (connection), "reload"); - - update_connection (self, NULL, path, connection, TRUE, NULL, NULL); -} - -static void -connection_removed_cb (NMSettingsConnection *obj, gpointer user_data) -{ - g_hash_table_remove (SETTINGS_PLUGIN_IFCFG_GET_PRIVATE (user_data)->connections, - nm_connection_get_uuid (NM_CONNECTION (obj))); -} - -static void -remove_connection (SettingsPluginIfcfg *self, NMIfcfgConnection *connection) -{ - SettingsPluginIfcfgPrivate *priv = SETTINGS_PLUGIN_IFCFG_GET_PRIVATE (self); - gboolean unmanaged, unrecognized; - - g_return_if_fail (self != NULL); - g_return_if_fail (connection != NULL); - - _LOGI ("remove "NM_IFCFG_CONNECTION_LOG_FMT, NM_IFCFG_CONNECTION_LOG_ARG (connection)); - - unmanaged = !!nm_ifcfg_connection_get_unmanaged_spec (connection); - unrecognized = !!nm_ifcfg_connection_get_unrecognized_spec (connection); - - g_object_ref (connection); - g_hash_table_remove (priv->connections, nm_connection_get_uuid (NM_CONNECTION (connection))); - if (!unmanaged && !unrecognized) - nm_settings_connection_signal_remove (NM_SETTINGS_CONNECTION (connection)); - g_object_unref (connection); - - /* Emit changes _after_ removing the connection */ - if (unmanaged) - g_signal_emit_by_name (self, NM_SETTINGS_PLUGIN_UNMANAGED_SPECS_CHANGED); - if (unrecognized) - g_signal_emit_by_name (self, NM_SETTINGS_PLUGIN_UNRECOGNIZED_SPECS_CHANGED); -} - -static NMIfcfgConnection * -find_by_path (SettingsPluginIfcfg *self, const char *path) -{ - SettingsPluginIfcfgPrivate *priv = SETTINGS_PLUGIN_IFCFG_GET_PRIVATE (self); - GHashTableIter iter; - NMSettingsConnection *candidate = NULL; - - g_return_val_if_fail (path != NULL, NULL); - - g_hash_table_iter_init (&iter, priv->connections); - while (g_hash_table_iter_next (&iter, NULL, (gpointer) &candidate)) { - if (g_strcmp0 (path, nm_settings_connection_get_filename (candidate)) == 0) - return NM_IFCFG_CONNECTION (candidate); - } - return NULL; -} - -static NMIfcfgConnection * -update_connection (SettingsPluginIfcfg *self, - NMConnection *source, - const char *full_path, - NMIfcfgConnection *connection, - gboolean protect_existing_connection, - GHashTable *protected_connections, - GError **error) -{ - SettingsPluginIfcfgPrivate *priv = SETTINGS_PLUGIN_IFCFG_GET_PRIVATE (self); - NMIfcfgConnection *connection_new; - NMIfcfgConnection *connection_by_uuid; - GError *local = NULL; - const char *new_unmanaged = NULL, *old_unmanaged = NULL; - const char *new_unrecognized = NULL, *old_unrecognized = NULL; - gboolean unmanaged_changed = FALSE, unrecognized_changed = FALSE; - const char *uuid; - gboolean ignore_error = FALSE; - - g_return_val_if_fail (!source || NM_IS_CONNECTION (source), NULL); - g_return_val_if_fail (full_path || source, NULL); - - if (full_path) - _LOGD ("loading from file \"%s\"...", full_path); - - /* Create a NMIfcfgConnection instance, either by reading from @full_path or - * based on @source. */ - connection_new = nm_ifcfg_connection_new (source, full_path, &local, &ignore_error); - if (!connection_new) { - /* Unexpected failure. Probably the file is invalid? */ - if ( connection - && !protect_existing_connection - && (!protected_connections || !g_hash_table_contains (protected_connections, connection))) - remove_connection (self, connection); - if (!source) { - _NMLOG (ignore_error ? LOGL_DEBUG : LOGL_WARN, - "loading \"%s\" fails: %s", full_path, local ? local->message : "(unknown reason)"); - } - g_propagate_error (error, local); - return NULL; - } - - uuid = nm_connection_get_uuid (NM_CONNECTION (connection_new)); - connection_by_uuid = g_hash_table_lookup (priv->connections, uuid); - - if ( connection - && connection != connection_by_uuid) { - - if ( (protect_existing_connection && connection_by_uuid != NULL) - || (protected_connections && g_hash_table_contains (protected_connections, connection))) { - NMIfcfgConnection *conflicting = (protect_existing_connection && connection_by_uuid != NULL) ? connection_by_uuid : connection; - - if (source) - _LOGW ("cannot update protected connection "NM_IFCFG_CONNECTION_LOG_FMT" due to conflicting UUID %s", NM_IFCFG_CONNECTION_LOG_ARG (conflicting), uuid); - else - _LOGW ("cannot load %s due to conflicting UUID for "NM_IFCFG_CONNECTION_LOG_FMT, full_path, NM_IFCFG_CONNECTION_LOG_ARG (conflicting)); - g_object_unref (connection_new); - g_set_error_literal (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, - "Cannot update protected connection due to conflicting UUID"); - return NULL; - } - - /* The new connection has a different UUID then the original one that we - * are about to update. Remove @connection. */ - remove_connection (self, connection); - } - - /* Check if the found connection with the same UUID is not protected from updating. */ - if ( connection_by_uuid - && ( (!connection && protect_existing_connection) - || (protected_connections && g_hash_table_contains (protected_connections, connection_by_uuid)))) { - if (source) - _LOGW ("cannot update connection due to conflicting UUID for "NM_IFCFG_CONNECTION_LOG_FMT, NM_IFCFG_CONNECTION_LOG_ARG (connection_by_uuid)); - else - _LOGW ("cannot load %s due to conflicting UUID for "NM_IFCFG_CONNECTION_LOG_FMT, full_path, NM_IFCFG_CONNECTION_LOG_ARG (connection_by_uuid)); - g_object_unref (connection_new); - g_set_error_literal (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, - "Skip updating protected connection during reload"); - return NULL; - } - - /* Evaluate unmanaged/unrecognized flags. */ - if (connection_by_uuid) - old_unmanaged = nm_ifcfg_connection_get_unmanaged_spec (connection_by_uuid); - new_unmanaged = nm_ifcfg_connection_get_unmanaged_spec (connection_new); - unmanaged_changed = g_strcmp0 (old_unmanaged, new_unmanaged); - - if (connection_by_uuid) - old_unrecognized = nm_ifcfg_connection_get_unrecognized_spec (connection_by_uuid); - new_unrecognized = nm_ifcfg_connection_get_unrecognized_spec (connection_new); - unrecognized_changed = g_strcmp0 (old_unrecognized, new_unrecognized); - - if (connection_by_uuid) { - const char *old_path; - - old_path = nm_settings_connection_get_filename (NM_SETTINGS_CONNECTION (connection_by_uuid)); - - if ( !unmanaged_changed - && !unrecognized_changed - && nm_connection_compare (NM_CONNECTION (connection_by_uuid), - NM_CONNECTION (connection_new), - NM_SETTING_COMPARE_FLAG_IGNORE_AGENT_OWNED_SECRETS | - NM_SETTING_COMPARE_FLAG_IGNORE_NOT_SAVED_SECRETS)) { - if (old_path && g_strcmp0 (old_path, full_path) != 0) - _LOGI ("rename \"%s\" to "NM_IFCFG_CONNECTION_LOG_FMT" without other changes", nm_settings_connection_get_filename (NM_SETTINGS_CONNECTION (connection_by_uuid)), NM_IFCFG_CONNECTION_LOG_ARG (connection_new)); - } else { - - /******************************************************* - * UPDATE - *******************************************************/ - - if (source) - _LOGI ("update "NM_IFCFG_CONNECTION_LOG_FMT" from %s", NM_IFCFG_CONNECTION_LOG_ARG (connection_new), NM_IFCFG_CONNECTION_LOG_PATH (old_path)); - else if (!g_strcmp0 (old_path, nm_settings_connection_get_filename (NM_SETTINGS_CONNECTION (connection_new)))) - _LOGI ("update "NM_IFCFG_CONNECTION_LOG_FMT, NM_IFCFG_CONNECTION_LOG_ARG (connection_new)); - else if (old_path) - _LOGI ("rename \"%s\" to "NM_IFCFG_CONNECTION_LOG_FMT, old_path, NM_IFCFG_CONNECTION_LOG_ARG (connection_new)); - else - _LOGI ("update and persist "NM_IFCFG_CONNECTION_LOG_FMT, NM_IFCFG_CONNECTION_LOG_ARG (connection_new)); - - g_object_set (connection_by_uuid, - NM_IFCFG_CONNECTION_UNMANAGED_SPEC, new_unmanaged, - NM_IFCFG_CONNECTION_UNRECOGNIZED_SPEC, new_unrecognized, - NULL); - - if (!nm_settings_connection_replace_settings (NM_SETTINGS_CONNECTION (connection_by_uuid), - NM_CONNECTION (connection_new), - FALSE, /* don't set Unsaved */ - "ifcfg-update", - &local)) { - /* Shouldn't ever get here as 'connection_new' was verified by the reader already - * and the UUID did not change. */ - g_assert_not_reached (); - } - g_assert_no_error (local); - - if (new_unmanaged || new_unrecognized) { - if (!old_unmanaged && !old_unrecognized) { - g_object_ref (connection_by_uuid); - /* Unexport the connection by telling the settings service it's - * been removed. - */ - nm_settings_connection_signal_remove (NM_SETTINGS_CONNECTION (connection_by_uuid)); - /* Remove the path so that claim_connection() doesn't complain later when - * interface gets managed and connection is re-added. */ - nm_connection_set_path (NM_CONNECTION (connection_by_uuid), NULL); - - /* signal_remove() will end up removing the connection from our hash, - * so add it back now. - */ - g_hash_table_insert (priv->connections, - g_strdup (nm_connection_get_uuid (NM_CONNECTION (connection_by_uuid))), - connection_by_uuid); - } - } else { - if (old_unmanaged /* && !new_unmanaged */) { - _LOGI ("Managing connection "NM_IFCFG_CONNECTION_LOG_FMT" and its device because NM_CONTROLLED was true.", - NM_IFCFG_CONNECTION_LOG_ARG (connection_new)); - g_signal_emit_by_name (self, NM_SETTINGS_PLUGIN_CONNECTION_ADDED, connection_by_uuid); - } else if (old_unrecognized /* && !new_unrecognized */) { - _LOGI ("Managing connection "NM_IFCFG_CONNECTION_LOG_FMT" because it is now a recognized type.", - NM_IFCFG_CONNECTION_LOG_ARG (connection_new)); - g_signal_emit_by_name (self, NM_SETTINGS_PLUGIN_CONNECTION_ADDED, connection_by_uuid); - } - } - - if (unmanaged_changed) - g_signal_emit_by_name (self, NM_SETTINGS_PLUGIN_UNMANAGED_SPECS_CHANGED); - if (unrecognized_changed) - g_signal_emit_by_name (self, NM_SETTINGS_PLUGIN_UNRECOGNIZED_SPECS_CHANGED); - } - nm_settings_connection_set_filename (NM_SETTINGS_CONNECTION (connection_by_uuid), full_path); - g_object_unref (connection_new); - return connection_by_uuid; - } else { - - /******************************************************* - * ADD - *******************************************************/ - - if (source) - _LOGI ("add connection "NM_IFCFG_CONNECTION_LOG_FMT, NM_IFCFG_CONNECTION_LOG_ARG (connection_new)); - else - _LOGI ("new connection "NM_IFCFG_CONNECTION_LOG_FMT, NM_IFCFG_CONNECTION_LOG_ARG (connection_new)); - g_hash_table_insert (priv->connections, g_strdup (uuid), connection_new); - - g_signal_connect (connection_new, NM_SETTINGS_CONNECTION_REMOVED, - G_CALLBACK (connection_removed_cb), - self); - - if (nm_ifcfg_connection_get_unmanaged_spec (connection_new)) { - _LOGI ("Ignoring connection "NM_IFCFG_CONNECTION_LOG_FMT" due to NM_CONTROLLED=no. Unmanaged: %s.", - NM_IFCFG_CONNECTION_LOG_ARG (connection_new), - nm_ifcfg_connection_get_unmanaged_spec (connection_new)); - } else if (nm_ifcfg_connection_get_unrecognized_spec (connection_new)) - _LOGW ("Ignoring connection "NM_IFCFG_CONNECTION_LOG_FMT" of unrecognized type.", NM_IFCFG_CONNECTION_LOG_ARG (connection_new)); - - /* watch changes of ifcfg hardlinks */ - g_signal_connect (G_OBJECT (connection_new), "ifcfg-changed", - G_CALLBACK (connection_ifcfg_changed), self); - - if (!source) { - /* Only raise the signal if we were called without source, i.e. if we read the connection from file. - * Otherwise, we were called by add_connection() which does not expect the signal. */ - if (nm_ifcfg_connection_get_unmanaged_spec (connection_new)) - g_signal_emit_by_name (self, NM_SETTINGS_PLUGIN_UNMANAGED_SPECS_CHANGED); - else if (nm_ifcfg_connection_get_unrecognized_spec (connection_new)) - g_signal_emit_by_name (self, NM_SETTINGS_PLUGIN_UNRECOGNIZED_SPECS_CHANGED); - else - g_signal_emit_by_name (self, NM_SETTINGS_PLUGIN_CONNECTION_ADDED, connection_new); - } - return connection_new; - } -} - -static void -ifcfg_dir_changed (GFileMonitor *monitor, - GFile *file, - GFile *other_file, - GFileMonitorEvent event_type, - gpointer user_data) -{ - SettingsPluginIfcfg *plugin = SETTINGS_PLUGIN_IFCFG (user_data); - char *path, *ifcfg_path; - NMIfcfgConnection *connection; - - path = g_file_get_path (file); - - ifcfg_path = utils_detect_ifcfg_path (path, FALSE); - _LOGD ("ifcfg_dir_changed(%s) = %d // %s", path, event_type, ifcfg_path ? ifcfg_path : "(none)"); - if (ifcfg_path) { - connection = find_by_path (plugin, ifcfg_path); - switch (event_type) { - case G_FILE_MONITOR_EVENT_DELETED: - if (connection) - remove_connection (plugin, connection); - break; - case G_FILE_MONITOR_EVENT_CREATED: - case G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT: - /* Update or new */ - update_connection (plugin, NULL, ifcfg_path, connection, TRUE, NULL, NULL); - break; - default: - break; - } - g_free (ifcfg_path); - } - g_free (path); -} - -static void -setup_ifcfg_monitoring (SettingsPluginIfcfg *plugin) -{ - SettingsPluginIfcfgPrivate *priv = SETTINGS_PLUGIN_IFCFG_GET_PRIVATE (plugin); - GFile *file; - GFileMonitor *monitor; - - file = g_file_new_for_path (IFCFG_DIR "/"); - monitor = g_file_monitor_directory (file, G_FILE_MONITOR_NONE, NULL, NULL); - g_object_unref (file); - - if (monitor) { - priv->ifcfg_monitor_id = g_signal_connect (monitor, "changed", - G_CALLBACK (ifcfg_dir_changed), plugin); - priv->ifcfg_monitor = monitor; - } -} - -static GHashTable * -_paths_from_connections (GHashTable *connections) -{ - GHashTableIter iter; - NMIfcfgConnection *connection; - GHashTable *paths = g_hash_table_new (g_str_hash, g_str_equal); - - g_hash_table_iter_init (&iter, connections); - while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &connection)) { - const char *path = nm_settings_connection_get_filename (NM_SETTINGS_CONNECTION (connection)); - - if (path) - g_hash_table_add (paths, (void *) path); - } - return paths; -} - -static int -_sort_paths (const char **f1, const char **f2, GHashTable *paths) -{ - struct stat st; - gboolean c1, c2; - gint64 m1, m2; - - c1 = !!g_hash_table_contains (paths, *f1); - c2 = !!g_hash_table_contains (paths, *f2); - if (c1 != c2) - return c1 ? -1 : 1; - - m1 = stat (*f1, &st) == 0 ? (gint64) st.st_mtime : G_MININT64; - m2 = stat (*f2, &st) == 0 ? (gint64) st.st_mtime : G_MININT64; - if (m1 != m2) - return m1 > m2 ? -1 : 1; - - return strcmp (*f1, *f2); -} - -static void -read_connections (SettingsPluginIfcfg *plugin) -{ - SettingsPluginIfcfgPrivate *priv = SETTINGS_PLUGIN_IFCFG_GET_PRIVATE (plugin); - GDir *dir; - GError *err = NULL; - const char *item; - GHashTable *alive_connections; - GHashTableIter iter; - NMIfcfgConnection *connection; - GPtrArray *dead_connections = NULL; - guint i; - GPtrArray *filenames; - GHashTable *paths; - - dir = g_dir_open (IFCFG_DIR, 0, &err); - if (!dir) { - _LOGW ("Could not read directory '%s': %s", IFCFG_DIR, err->message); - g_error_free (err); - return; - } - - alive_connections = g_hash_table_new (NULL, NULL); - - filenames = g_ptr_array_new_with_free_func (g_free); - while ((item = g_dir_read_name (dir))) { - char *full_path, *real_path; - - full_path = g_build_filename (IFCFG_DIR, item, NULL); - real_path = utils_detect_ifcfg_path (full_path, TRUE); - - if (real_path) - g_ptr_array_add (filenames, real_path); - g_free (full_path); - } - g_dir_close (dir); - - /* While reloading, we don't replace connections that we already loaded while - * iterating over the files. - * - * To have sensible, reproducible behavior, sort the paths by last modification - * time prefering older files. - */ - paths = _paths_from_connections (priv->connections); - g_ptr_array_sort_with_data (filenames, (GCompareDataFunc) _sort_paths, paths); - g_hash_table_destroy (paths); - - for (i = 0; i < filenames->len; i++) { - connection = update_connection (plugin, NULL, filenames->pdata[i], NULL, FALSE, alive_connections, NULL); - if (connection) - g_hash_table_add (alive_connections, connection); - } - g_ptr_array_free (filenames, TRUE); - - g_hash_table_iter_init (&iter, priv->connections); - while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &connection)) { - if ( !g_hash_table_contains (alive_connections, connection) - && nm_settings_connection_get_filename (NM_SETTINGS_CONNECTION (connection))) { - if (!dead_connections) - dead_connections = g_ptr_array_new (); - g_ptr_array_add (dead_connections, connection); - } - } - g_hash_table_destroy (alive_connections); - - if (dead_connections) { - for (i = 0; i < dead_connections->len; i++) - remove_connection (plugin, dead_connections->pdata[i]); - g_ptr_array_free (dead_connections, TRUE); - } -} - -static GSList * -get_connections (NMSettingsPlugin *config) -{ - SettingsPluginIfcfg *plugin = SETTINGS_PLUGIN_IFCFG (config); - SettingsPluginIfcfgPrivate *priv = SETTINGS_PLUGIN_IFCFG_GET_PRIVATE (plugin); - GSList *list = NULL; - GHashTableIter iter; - NMIfcfgConnection *connection; - - if (!priv->initialized) { - if (nm_config_get_monitor_connection_files (nm_config_get ())) - setup_ifcfg_monitoring (plugin); - read_connections (plugin); - priv->initialized = TRUE; - } - - g_hash_table_iter_init (&iter, priv->connections); - while (g_hash_table_iter_next (&iter, NULL, (gpointer) &connection)) { - if ( !nm_ifcfg_connection_get_unmanaged_spec (connection) - && !nm_ifcfg_connection_get_unrecognized_spec (connection)) - list = g_slist_prepend (list, connection); - } - - return list; -} - -static gboolean -load_connection (NMSettingsPlugin *config, - const char *filename) -{ - SettingsPluginIfcfg *plugin = SETTINGS_PLUGIN_IFCFG (config); - NMIfcfgConnection *connection; - int dir_len = strlen (IFCFG_DIR); - char *ifcfg_path; - - if ( strncmp (filename, IFCFG_DIR, dir_len) != 0 - || filename[dir_len] != '/' - || strchr (filename + dir_len + 1, '/') != NULL) - return FALSE; - - /* get the real ifcfg-path. This allows us to properly - * handle load command using a route-* file etc. */ - ifcfg_path = utils_detect_ifcfg_path (filename, FALSE); - if (!ifcfg_path) - return FALSE; - - connection = find_by_path (plugin, ifcfg_path); - update_connection (plugin, NULL, ifcfg_path, connection, TRUE, NULL, NULL); - if (!connection) - connection = find_by_path (plugin, ifcfg_path); - - g_free (ifcfg_path); - return (connection != NULL); -} - -static void -reload_connections (NMSettingsPlugin *config) -{ - SettingsPluginIfcfg *plugin = SETTINGS_PLUGIN_IFCFG (config); - - read_connections (plugin); -} - -static GSList * -get_unhandled_specs (NMSettingsPlugin *config, - const char *property) -{ - SettingsPluginIfcfgPrivate *priv = SETTINGS_PLUGIN_IFCFG_GET_PRIVATE (config); - GSList *list = NULL, *list_iter; - GHashTableIter iter; - gpointer connection; - char *spec; - gboolean found; - - g_hash_table_iter_init (&iter, priv->connections); - while (g_hash_table_iter_next (&iter, NULL, &connection)) { - g_object_get (connection, property, &spec, NULL); - if (spec) { - /* Ignore duplicates */ - for (list_iter = list, found = FALSE; list_iter; list_iter = g_slist_next (list_iter)) { - if (g_str_equal (list_iter->data, spec)) { - found = TRUE; - break; - } - } - if (found) - g_free (spec); - else - list = g_slist_prepend (list, spec); - } - } - return list; -} - -static GSList * -get_unmanaged_specs (NMSettingsPlugin *config) -{ - return get_unhandled_specs (config, NM_IFCFG_CONNECTION_UNMANAGED_SPEC); -} - -static GSList * -get_unrecognized_specs (NMSettingsPlugin *config) -{ - return get_unhandled_specs (config, NM_IFCFG_CONNECTION_UNRECOGNIZED_SPEC); -} - -static NMSettingsConnection * -add_connection (NMSettingsPlugin *config, - NMConnection *connection, - gboolean save_to_disk, - GError **error) -{ - SettingsPluginIfcfg *self = SETTINGS_PLUGIN_IFCFG (config); - gs_free char *path = NULL; - - /* Ensure we reject attempts to add the connection long before we're - * asked to write it to disk. - */ - if (!writer_can_write_connection (connection, error)) - return NULL; - - if (save_to_disk) { - if (!writer_new_connection (connection, IFCFG_DIR, &path, error)) - return NULL; - } - return NM_SETTINGS_CONNECTION (update_connection (self, connection, path, NULL, FALSE, NULL, error)); -} - -static void -impl_ifcfgrh_get_ifcfg_details (SettingsPluginIfcfg *plugin, - GDBusMethodInvocation *context, - const char *in_ifcfg) -{ - NMIfcfgConnection *connection; - NMSettingConnection *s_con; - const char *uuid; - const char *path; - gs_free char *ifcfg_path = NULL; - - if (!g_path_is_absolute (in_ifcfg)) { - g_dbus_method_invocation_return_error (context, - NM_SETTINGS_ERROR, - NM_SETTINGS_ERROR_INVALID_CONNECTION, - "ifcfg path '%s' is not absolute", in_ifcfg); - return; - } - - ifcfg_path = utils_detect_ifcfg_path (in_ifcfg, TRUE); - if (!ifcfg_path) { - g_dbus_method_invocation_return_error (context, - NM_SETTINGS_ERROR, - NM_SETTINGS_ERROR_INVALID_CONNECTION, - "ifcfg path '%s' is not an ifcfg base file", in_ifcfg); - return; - } - - connection = find_by_path (plugin, ifcfg_path); - if ( !connection - || nm_ifcfg_connection_get_unmanaged_spec (connection) - || nm_ifcfg_connection_get_unrecognized_spec (connection)) { - g_dbus_method_invocation_return_error (context, - NM_SETTINGS_ERROR, - NM_SETTINGS_ERROR_INVALID_CONNECTION, - "ifcfg file '%s' unknown", in_ifcfg); - return; - } - - s_con = nm_connection_get_setting_connection (NM_CONNECTION (connection)); - if (!s_con) { - g_dbus_method_invocation_return_error (context, - NM_SETTINGS_ERROR, - NM_SETTINGS_ERROR_FAILED, - "unable to retrieve the connection setting"); - return; - } - - uuid = nm_setting_connection_get_uuid (s_con); - if (!uuid) { - g_dbus_method_invocation_return_error (context, - NM_SETTINGS_ERROR, - NM_SETTINGS_ERROR_FAILED, - "unable to get the UUID"); - return; - } - - path = nm_connection_get_path (NM_CONNECTION (connection)); - if (!path) { - g_dbus_method_invocation_return_error (context, - NM_SETTINGS_ERROR, - NM_SETTINGS_ERROR_FAILED, - "unable to get the connection D-Bus path"); - return; - } - - g_dbus_method_invocation_return_value (context, - g_variant_new ("(so)", uuid, path)); -} - -/*****************************************************************************/ - -static void -_dbus_clear (SettingsPluginIfcfg *self) -{ - SettingsPluginIfcfgPrivate *priv = SETTINGS_PLUGIN_IFCFG_GET_PRIVATE (self); - - nm_clear_g_signal_handler (priv->dbus.connection, &priv->dbus.signal_id); - - nm_clear_g_cancellable (&priv->dbus.cancellable); - - if (priv->dbus.interface) { - g_dbus_interface_skeleton_unexport (priv->dbus.interface); - nm_exported_object_skeleton_release (priv->dbus.interface); - priv->dbus.interface = NULL; - } - - g_clear_object (&priv->dbus.connection); -} - -static void -_dbus_connection_closed (GDBusConnection *connection, - gboolean remote_peer_vanished, - GError *error, - gpointer user_data) -{ - _LOGW ("dbus: %s bus closed", IFCFGRH1_DBUS_SERVICE_NAME); - _dbus_clear (SETTINGS_PLUGIN_IFCFG (user_data)); - - /* Retry or recover? */ -} - -static void -_dbus_request_name_done (GObject *source_object, - GAsyncResult *res, - gpointer user_data) -{ - GDBusConnection *connection = G_DBUS_CONNECTION (source_object); - SettingsPluginIfcfg *self; - SettingsPluginIfcfgPrivate *priv; - gs_free_error GError *error = NULL; - gs_unref_variant GVariant *ret = NULL; - guint32 result; - - ret = g_dbus_connection_call_finish (connection, res, &error); - if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) - return; - - self = SETTINGS_PLUGIN_IFCFG (user_data); - priv = SETTINGS_PLUGIN_IFCFG_GET_PRIVATE (self); - - g_clear_object (&priv->dbus.cancellable); - - if (!ret) { - _LOGW ("dbus: couldn't acquire D-Bus service: %s", error->message); - _dbus_clear (self); - return; - } - - g_variant_get (ret, "(u)", &result); - - if (result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) { - _LOGW ("dbus: couldn't acquire ifcfgrh1 D-Bus service (already taken)"); - _dbus_clear (self); - return; - } - - { - GType skeleton_type = NMDBUS_TYPE_IFCFGRH1_SKELETON; - gs_free char *method_name_get_ifcfg_details = NULL; - NMExportedObjectDBusMethodImpl methods[] = { - { - .method_name = (method_name_get_ifcfg_details = nm_exported_object_skeletonify_method_name ("GetIfcfgDetails")), - .impl = G_CALLBACK (impl_ifcfgrh_get_ifcfg_details), - }, - }; - - priv->dbus.interface = nm_exported_object_skeleton_create (skeleton_type, - g_type_class_peek (SETTINGS_TYPE_PLUGIN_IFCFG), - methods, - G_N_ELEMENTS (methods), - (GObject *) self); - - if (!g_dbus_interface_skeleton_export (priv->dbus.interface, - priv->dbus.connection, - IFCFGRH1_DBUS_OBJECT_PATH, - &error)) { - nm_exported_object_skeleton_release (priv->dbus.interface); - priv->dbus.interface = NULL; - _LOGW ("dbus: failed exporting interface: %s", error->message); - _dbus_clear (self); - return; - } - } - - _LOGD ("dbus: aquired D-Bus service %s and exported %s object", - IFCFGRH1_DBUS_SERVICE_NAME, - IFCFGRH1_DBUS_OBJECT_PATH); -} - -static void -_dbus_create_done (GObject *source_object, - GAsyncResult *res, - gpointer user_data) -{ - SettingsPluginIfcfg *self; - SettingsPluginIfcfgPrivate *priv; - gs_free_error GError *error = NULL; - GDBusConnection *connection; - - connection = g_dbus_connection_new_for_address_finish (res, &error); - if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) - return; - - self = SETTINGS_PLUGIN_IFCFG (user_data); - priv = SETTINGS_PLUGIN_IFCFG_GET_PRIVATE (self); - - g_clear_object (&priv->dbus.cancellable); - - if (!connection) { - _LOGW ("dbus: couldn't initialize system bus: %s", error->message); - return; - } - - priv->dbus.connection = connection; - priv->dbus.cancellable = g_cancellable_new (); - - priv->dbus.signal_id = g_signal_connect (priv->dbus.connection, - "closed", - G_CALLBACK (_dbus_connection_closed), - self); - - g_dbus_connection_call (priv->dbus.connection, - DBUS_SERVICE_DBUS, - DBUS_PATH_DBUS, - DBUS_INTERFACE_DBUS, - "RequestName", - g_variant_new ("(su)", - IFCFGRH1_DBUS_SERVICE_NAME, - DBUS_NAME_FLAG_DO_NOT_QUEUE), - G_VARIANT_TYPE ("(u)"), - G_DBUS_CALL_FLAGS_NONE, - -1, - priv->dbus.cancellable, - _dbus_request_name_done, - self); -} - -static void -_dbus_setup (SettingsPluginIfcfg *self) -{ - SettingsPluginIfcfgPrivate *priv = SETTINGS_PLUGIN_IFCFG_GET_PRIVATE (self); - gs_free char *address = NULL; - gs_free_error GError *error = NULL; - - g_return_if_fail (!priv->dbus.connection); - - address = g_dbus_address_get_for_bus_sync (G_BUS_TYPE_SYSTEM, NULL, &error); - if (address == NULL) { - _LOGW ("dbus: failed getting address for system bus: %s", error->message); - return; - } - - priv->dbus.cancellable = g_cancellable_new (); - - g_dbus_connection_new_for_address (address, - G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT - | G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION, - NULL, - priv->dbus.cancellable, - _dbus_create_done, - self); -} - -static void -config_changed_cb (NMConfig *config, - NMConfigData *config_data, - NMConfigChangeFlags changes, - NMConfigData *old_data, - SettingsPluginIfcfg *self) -{ - /* If the dbus connection for some reason is borked the D-Bus service - * won't be offered. - * - * On SIGHUP and SIGUSR1 try to re-connect to D-Bus. So in the unlikely - * event that the D-Bus conneciton is broken, that allows for recovery - * without need for restarting NetworkManager. */ - if (NM_FLAGS_ANY (changes, NM_CONFIG_CHANGE_CAUSE_SIGHUP - | NM_CONFIG_CHANGE_CAUSE_SIGUSR1)) { - if (!SETTINGS_PLUGIN_IFCFG_GET_PRIVATE (self)->dbus.connection) - _dbus_setup (self); - } -} - -/*****************************************************************************/ - -static void -init (NMSettingsPlugin *config) -{ -} - -static void -settings_plugin_ifcfg_init (SettingsPluginIfcfg *plugin) -{ - SettingsPluginIfcfgPrivate *priv = SETTINGS_PLUGIN_IFCFG_GET_PRIVATE (plugin); - - priv->connections = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref); -} - -static void -constructed (GObject *object) -{ - SettingsPluginIfcfg *self = SETTINGS_PLUGIN_IFCFG (object); - SettingsPluginIfcfgPrivate *priv = SETTINGS_PLUGIN_IFCFG_GET_PRIVATE (self); - - G_OBJECT_CLASS (settings_plugin_ifcfg_parent_class)->constructed (object); - - priv->config = nm_config_get (); - g_object_add_weak_pointer ((GObject *) priv->config, (gpointer *) &priv->config); - g_signal_connect (priv->config, - NM_CONFIG_SIGNAL_CONFIG_CHANGED, - G_CALLBACK (config_changed_cb), - self); - - _dbus_setup (self); -} - -static void -dispose (GObject *object) -{ - SettingsPluginIfcfg *self = SETTINGS_PLUGIN_IFCFG (object); - SettingsPluginIfcfgPrivate *priv = SETTINGS_PLUGIN_IFCFG_GET_PRIVATE (self); - - if (priv->config) { - g_object_remove_weak_pointer ((GObject *) priv->config, (gpointer *) &priv->config); - g_signal_handlers_disconnect_by_func (priv->config, config_changed_cb, self); - priv->config = NULL; - } - - _dbus_clear (self); - - if (priv->connections) { - g_hash_table_destroy (priv->connections); - priv->connections = NULL; - } - - if (priv->ifcfg_monitor) { - if (priv->ifcfg_monitor_id) - g_signal_handler_disconnect (priv->ifcfg_monitor, priv->ifcfg_monitor_id); - - g_file_monitor_cancel (priv->ifcfg_monitor); - g_object_unref (priv->ifcfg_monitor); - } - - G_OBJECT_CLASS (settings_plugin_ifcfg_parent_class)->dispose (object); -} - -static void -get_property (GObject *object, guint prop_id, - GValue *value, GParamSpec *pspec) -{ - switch (prop_id) { - case NM_SETTINGS_PLUGIN_PROP_NAME: - g_value_set_string (value, IFCFG_PLUGIN_NAME); - break; - case NM_SETTINGS_PLUGIN_PROP_INFO: - g_value_set_string (value, IFCFG_PLUGIN_INFO); - break; - case NM_SETTINGS_PLUGIN_PROP_CAPABILITIES: - g_value_set_uint (value, NM_SETTINGS_PLUGIN_CAP_MODIFY_CONNECTIONS); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -set_property (GObject *object, guint prop_id, - const GValue *value, GParamSpec *pspec) -{ - switch (prop_id) { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -settings_plugin_ifcfg_class_init (SettingsPluginIfcfgClass *req_class) -{ - GObjectClass *object_class = G_OBJECT_CLASS (req_class); - - g_type_class_add_private (req_class, sizeof (SettingsPluginIfcfgPrivate)); - - object_class->constructed = constructed; - object_class->dispose = dispose; - object_class->get_property = get_property; - object_class->set_property = set_property; - - g_object_class_override_property (object_class, - NM_SETTINGS_PLUGIN_PROP_NAME, - NM_SETTINGS_PLUGIN_NAME); - - g_object_class_override_property (object_class, - NM_SETTINGS_PLUGIN_PROP_INFO, - NM_SETTINGS_PLUGIN_INFO); - - g_object_class_override_property (object_class, - NM_SETTINGS_PLUGIN_PROP_CAPABILITIES, - NM_SETTINGS_PLUGIN_CAPABILITIES); -} - -static void -settings_plugin_interface_init (NMSettingsPluginInterface *plugin_iface) -{ - /* interface implementation */ - plugin_iface->get_connections = get_connections; - plugin_iface->add_connection = add_connection; - plugin_iface->load_connection = load_connection; - plugin_iface->reload_connections = reload_connections; - plugin_iface->get_unmanaged_specs = get_unmanaged_specs; - plugin_iface->get_unrecognized_specs = get_unrecognized_specs; - plugin_iface->init = init; -} - -G_MODULE_EXPORT GObject * -nm_settings_plugin_factory (void) -{ - return g_object_ref (settings_plugin_ifcfg_get ()); -} diff --git a/src/settings/plugins/ifcfg-rh/plugin.h b/src/settings/plugins/ifcfg-rh/plugin.h deleted file mode 100644 index 74c4b00a..00000000 --- a/src/settings/plugins/ifcfg-rh/plugin.h +++ /dev/null @@ -1,48 +0,0 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* NetworkManager system settings service - * - * Dan Williams - * Søren Sandmann - * - * 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) 2007 - 2008 Red Hat, Inc. - */ - -#ifndef _PLUGIN_H_ -#define _PLUGIN_H_ - -#define SETTINGS_TYPE_PLUGIN_IFCFG (settings_plugin_ifcfg_get_type ()) -#define SETTINGS_PLUGIN_IFCFG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SETTINGS_TYPE_PLUGIN_IFCFG, SettingsPluginIfcfg)) -#define SETTINGS_PLUGIN_IFCFG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SETTINGS_TYPE_PLUGIN_IFCFG, SettingsPluginIfcfgClass)) -#define SETTINGS_IS_PLUGIN_IFCFG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SETTINGS_TYPE_PLUGIN_IFCFG)) -#define SETTINGS_IS_PLUGIN_IFCFG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SETTINGS_TYPE_PLUGIN_IFCFG)) -#define SETTINGS_PLUGIN_IFCFG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SETTINGS_TYPE_PLUGIN_IFCFG, SettingsPluginIfcfgClass)) - -typedef struct _SettingsPluginIfcfg SettingsPluginIfcfg; -typedef struct _SettingsPluginIfcfgClass SettingsPluginIfcfgClass; - -struct _SettingsPluginIfcfg { - GObject parent; -}; - -struct _SettingsPluginIfcfgClass { - GObjectClass parent; -}; - -GType settings_plugin_ifcfg_get_type (void); - -#endif /* _PLUGIN_H_ */ - diff --git a/src/settings/plugins/ifcfg-rh/reader.c b/src/settings/plugins/ifcfg-rh/reader.c deleted file mode 100644 index 5a351cfa..00000000 --- a/src/settings/plugins/ifcfg-rh/reader.c +++ /dev/null @@ -1,5260 +0,0 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* NetworkManager system settings service - * - * 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 2008 - 2015 Red Hat, Inc. - */ - -#include "nm-default.h" - -#include "reader.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "nm-connection.h" -#include "nm-dbus-interface.h" -#include "nm-setting-connection.h" -#include "nm-setting-ip4-config.h" -#include "nm-setting-vlan.h" -#include "nm-setting-ip6-config.h" -#include "nm-setting-wired.h" -#include "nm-setting-wireless.h" -#include "nm-setting-8021x.h" -#include "nm-setting-bond.h" -#include "nm-setting-team.h" -#include "nm-setting-team-port.h" -#include "nm-setting-bridge.h" -#include "nm-setting-bridge-port.h" -#include "nm-setting-dcb.h" -#include "nm-setting-generic.h" -#include "nm-core-internal.h" -#include "nm-utils.h" - -#include "nm-platform.h" -#include "NetworkManagerUtils.h" - -#include "common.h" -#include "shvar.h" -#include "utils.h" - -/*****************************************************************************/ - -#define _NMLOG_DOMAIN LOGD_SETTINGS -#define _NMLOG_PREFIX_NAME "ifcfg-rh" -#define _NMLOG(level, ...) \ - G_STMT_START { \ - nm_log ((level), (_NMLOG_DOMAIN), \ - "%s" _NM_UTILS_MACRO_FIRST(__VA_ARGS__), \ - _NMLOG_PREFIX_NAME": " \ - _NM_UTILS_MACRO_REST(__VA_ARGS__)); \ - } G_STMT_END - -#define PARSE_WARNING(...) _LOGW ("%s" _NM_UTILS_MACRO_FIRST(__VA_ARGS__), " " _NM_UTILS_MACRO_REST(__VA_ARGS__)) - -/*****************************************************************************/ - -static gboolean -get_uint (const char *str, guint32 *value) -{ - gint64 tmp; - - tmp = _nm_utils_ascii_str_to_int64 (str, 0, 0, G_MAXUINT32, -1); - if (tmp == -1) - return FALSE; - *value = tmp; - return TRUE; -} - -static char * -make_connection_name (shvarFile *ifcfg, - const char *ifcfg_name, - const char *suggested, - const char *prefix) -{ - char *full_name = NULL, *name; - - /* If the ifcfg file already has a NAME, always use that */ - name = svGetValue (ifcfg, "NAME", FALSE); - if (name && strlen (name)) - return name; - - /* Otherwise construct a new NAME */ - g_free (name); - if (!prefix) - prefix = _("System"); - - /* For cosmetic reasons, if the suggested name is the same as - * the ifcfg files name, don't use it. Mainly for wifi so that - * the SSID is shown in the connection ID instead of just "wlan0". - */ - if (suggested && strcmp (ifcfg_name, suggested)) - full_name = g_strdup_printf ("%s %s (%s)", prefix, suggested, ifcfg_name); - else - full_name = g_strdup_printf ("%s %s", prefix, ifcfg_name); - - return full_name; -} - -static NMSetting * -make_connection_setting (const char *file, - shvarFile *ifcfg, - const char *type, - const char *suggested, - const char *prefix) -{ - NMSettingConnection *s_con; - NMSettingConnectionLldp lldp; - const char *ifcfg_name = NULL; - char *new_id, *uuid = NULL, *zone = NULL, *value; - gs_free char *stable_id = NULL; - - ifcfg_name = utils_get_ifcfg_name (file, TRUE); - if (!ifcfg_name) - return NULL; - - s_con = NM_SETTING_CONNECTION (nm_setting_connection_new ()); - - new_id = make_connection_name (ifcfg, ifcfg_name, suggested, prefix); - g_object_set (s_con, NM_SETTING_CONNECTION_ID, new_id, NULL); - g_free (new_id); - - /* Try for a UUID key before falling back to hashing the file name */ - uuid = svGetValue (ifcfg, "UUID", FALSE); - if (!uuid || !strlen (uuid)) { - g_free (uuid); - uuid = nm_utils_uuid_generate_from_string (ifcfg->fileName, -1, NM_UTILS_UUID_TYPE_LEGACY, NULL); - } - - stable_id = svGetValue (ifcfg, "STABLE_ID", FALSE); - - g_object_set (s_con, - NM_SETTING_CONNECTION_TYPE, type, - NM_SETTING_CONNECTION_UUID, uuid, - NM_SETTING_CONNECTION_STABLE_ID, stable_id, - NULL); - g_free (uuid); - - value = svGetValue (ifcfg, "DEVICE", FALSE); - if (value) { - if (nm_utils_iface_valid_name (value)) { - g_object_set (s_con, - NM_SETTING_CONNECTION_INTERFACE_NAME, value, - NULL); - } else - PARSE_WARNING ("invalid DEVICE name '%s'", value); - g_free (value); - } - - value = svGetValue (ifcfg, "LLDP", FALSE); - if (!g_strcmp0 (value, "rx")) - lldp = NM_SETTING_CONNECTION_LLDP_ENABLE_RX; - else - lldp = svParseBoolean (value, NM_SETTING_CONNECTION_LLDP_DEFAULT); - g_free (value); - - /* Missing ONBOOT is treated as "ONBOOT=true" by the old network service */ - g_object_set (s_con, - NM_SETTING_CONNECTION_AUTOCONNECT, - svGetValueBoolean (ifcfg, "ONBOOT", TRUE), - NM_SETTING_CONNECTION_AUTOCONNECT_PRIORITY, - (gint) svGetValueInt64 (ifcfg, "AUTOCONNECT_PRIORITY", 10, - NM_SETTING_CONNECTION_AUTOCONNECT_PRIORITY_MIN, - NM_SETTING_CONNECTION_AUTOCONNECT_PRIORITY_MAX, - NM_SETTING_CONNECTION_AUTOCONNECT_PRIORITY_DEFAULT), - NM_SETTING_CONNECTION_AUTOCONNECT_SLAVES, - svGetValueBoolean (ifcfg, "AUTOCONNECT_SLAVES", NM_SETTING_CONNECTION_AUTOCONNECT_SLAVES_DEFAULT), - NM_SETTING_CONNECTION_LLDP, lldp, - NULL); - - value = svGetValue (ifcfg, "USERS", FALSE); - if (value) { - char **items, **iter; - - items = g_strsplit_set (value, " ", -1); - for (iter = items; iter && *iter; iter++) { - if (strlen (*iter)) { - if (!nm_setting_connection_add_permission (s_con, "user", *iter, NULL)) - PARSE_WARNING ("invalid USERS item '%s'", *iter); - } - } - g_free (value); - g_strfreev (items); - } - - - zone = svGetValue(ifcfg, "ZONE", FALSE); - if (!zone || !strlen (zone)) { - g_free (zone); - zone = NULL; - } - g_object_set (s_con, NM_SETTING_CONNECTION_ZONE, zone, NULL); - g_free (zone); - - value = svGetValue (ifcfg, "SECONDARY_UUIDS", FALSE); - if (value) { - char **items, **iter; - - items = g_strsplit_set (value, " \t", -1); - for (iter = items; iter && *iter; iter++) { - if (strlen (*iter)) { - if (!nm_setting_connection_add_secondary (s_con, *iter)) - PARSE_WARNING ("secondary connection UUID '%s' already added", *iter); - } - } - g_free (value); - g_strfreev (items); - } - - value = svGetValue (ifcfg, "BRIDGE", FALSE); - if (value) { - const char *old_value; - - if ((old_value = nm_setting_connection_get_master (s_con))) { - PARSE_WARNING ("Already configured as slave of %s. Ignoring BRIDGE=\"%s\"", - old_value, value); - } else { - g_object_set (s_con, NM_SETTING_CONNECTION_MASTER, value, NULL); - g_object_set (s_con, NM_SETTING_CONNECTION_SLAVE_TYPE, - NM_SETTING_BRIDGE_SETTING_NAME, NULL); - } - g_free (value); - } - - value = svGetValue (ifcfg, "GATEWAY_PING_TIMEOUT", FALSE); - if (value) { - gint64 tmp; - - tmp = _nm_utils_ascii_str_to_int64 (value, 10, 0, G_MAXINT32 - 1, -1); - if (tmp >= 0) - g_object_set (s_con, NM_SETTING_CONNECTION_GATEWAY_PING_TIMEOUT, (guint) tmp, NULL); - else - PARSE_WARNING ("invalid GATEWAY_PING_TIMEOUT time"); - g_free (value); - } - - switch (svGetValueBoolean (ifcfg, "CONNECTION_METERED", -1)) { - case TRUE: - g_object_set (s_con, NM_SETTING_CONNECTION_METERED, NM_METERED_YES, NULL); - break; - case FALSE: - g_object_set (s_con, NM_SETTING_CONNECTION_METERED, NM_METERED_NO, NULL); - break; - } - - return NM_SETTING (s_con); -} - -/* Returns TRUE on missing address or valid address */ -static gboolean -read_ip4_address (shvarFile *ifcfg, - const char *tag, - char **out_addr, - GError **error) -{ - char *value = NULL; - - g_return_val_if_fail (ifcfg != NULL, FALSE); - g_return_val_if_fail (tag != NULL, FALSE); - g_return_val_if_fail (out_addr != NULL, FALSE); - g_return_val_if_fail (!error || !*error, FALSE); - - *out_addr = NULL; - - value = svGetValue (ifcfg, tag, FALSE); - if (!value) - return TRUE; - - if (nm_utils_ipaddr_valid (AF_INET, value)) { - *out_addr = value; - return TRUE; - } else { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Invalid %s IP4 address '%s'", tag, value); - g_free (value); - return FALSE; - } -} - -static char * -get_numbered_tag (char *tag_name, int which) -{ - if (which == -1) - return g_strdup (tag_name); - return g_strdup_printf ("%s%u", tag_name, which); -} - -static gboolean -is_any_ip4_address_defined (shvarFile *ifcfg, int *idx) -{ - int i, ignore, *ret_idx;; - - ret_idx = idx ? idx : &ignore; - - for (i = -1; i <= 2; i++) { - char *tag; - char *value; - - tag = get_numbered_tag ("IPADDR", i); - value = svGetValue (ifcfg, tag, FALSE); - g_free (tag); - if (value) { - g_free (value); - *ret_idx = i; - return TRUE; - } - - tag = get_numbered_tag ("PREFIX", i); - value = svGetValue (ifcfg, tag, FALSE); - g_free(tag); - if (value) { - g_free (value); - *ret_idx = i; - return TRUE; - } - - tag = get_numbered_tag ("NETMASK", i); - value = svGetValue (ifcfg, tag, FALSE); - g_free(tag); - if (value) { - g_free (value); - *ret_idx = i; - return TRUE; - } - } - return FALSE; -} - -/* Returns TRUE on missing address or valid address */ -static gboolean -read_full_ip4_address (shvarFile *ifcfg, - gint32 which, - NMIPAddress *base_addr, - NMIPAddress **out_address, - char **out_gateway, - GError **error) -{ - char *ip_tag, *prefix_tag, *netmask_tag, *gw_tag; - char *ip = NULL; - int prefix = 0; - gboolean success = FALSE; - char *value; - guint32 tmp; - - g_return_val_if_fail (which >= -1, FALSE); - g_return_val_if_fail (ifcfg != NULL, FALSE); - g_return_val_if_fail (out_address != NULL, FALSE); - g_return_val_if_fail (*out_address == NULL, FALSE); - g_return_val_if_fail (!error || !*error, FALSE); - - ip_tag = get_numbered_tag ("IPADDR", which); - prefix_tag = get_numbered_tag ("PREFIX", which); - netmask_tag = get_numbered_tag ("NETMASK", which); - gw_tag = get_numbered_tag ("GATEWAY", which); - - /* IP address */ - if (!read_ip4_address (ifcfg, ip_tag, &ip, error)) - goto done; - if (!ip) { - if (base_addr) - ip = g_strdup (nm_ip_address_get_address (base_addr)); - else { - success = TRUE; - goto done; - } - } - - /* Gateway */ - if (out_gateway && !*out_gateway) { - if (!read_ip4_address (ifcfg, gw_tag, out_gateway, error)) - goto done; - } - - /* Prefix */ - value = svGetValue (ifcfg, prefix_tag, FALSE); - if (value) { - prefix = _nm_utils_ascii_str_to_int64 (value, 10, 0, 32, -1); - if (prefix < 0) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Invalid IP4 prefix '%s'", value); - g_free (value); - goto done; - } - g_free (value); - } else { - /* Fall back to NETMASK if no PREFIX was specified */ - if (!read_ip4_address (ifcfg, netmask_tag, &value, error)) - goto done; - if (value) { - inet_pton (AF_INET, value, &tmp); - prefix = nm_utils_ip4_netmask_to_prefix (tmp); - g_free (value); - } else { - if (base_addr) - prefix = nm_ip_address_get_prefix (base_addr); - else { - /* Try to autodetermine the prefix for the address' class */ - if (inet_pton (AF_INET, ip, &tmp) == 1) { - prefix = nm_utils_ip4_get_default_prefix (tmp); - - PARSE_WARNING ("missing %s, assuming %s/%d", prefix_tag, ip, prefix); - } else { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Missing IP4 prefix"); - goto done; - } - } - } - } - - *out_address = nm_ip_address_new (AF_INET, ip, prefix, error); - if (*out_address) - success = TRUE; - -done: - g_free (ip); - g_free (ip_tag); - g_free (prefix_tag); - g_free (netmask_tag); - g_free (gw_tag); - - return success; -} - -/* Returns TRUE on missing route or valid route */ -static gboolean -read_one_ip4_route (shvarFile *ifcfg, - guint32 which, - NMIPRoute **out_route, - GError **error) -{ - char *ip_tag, *netmask_tag, *gw_tag, *metric_tag, *value; - char *dest = NULL, *next_hop = NULL; - gint64 prefix, metric; - gboolean success = FALSE; - - g_return_val_if_fail (ifcfg != NULL, FALSE); - g_return_val_if_fail (out_route != NULL, FALSE); - g_return_val_if_fail (*out_route == NULL, FALSE); - g_return_val_if_fail (!error || !*error, FALSE); - - ip_tag = g_strdup_printf ("ADDRESS%u", which); - netmask_tag = g_strdup_printf ("NETMASK%u", which); - gw_tag = g_strdup_printf ("GATEWAY%u", which); - metric_tag = g_strdup_printf ("METRIC%u", which); - - /* Destination */ - if (!read_ip4_address (ifcfg, ip_tag, &dest, error)) - goto out; - if (!dest) { - /* Check whether IP is missing or 0.0.0.0 */ - char *val; - val = svGetValue (ifcfg, ip_tag, FALSE); - if (!val) { - *out_route = NULL; - success = TRUE; /* missing route = success */ - goto out; - } - g_free (val); - } - - /* Next hop */ - if (!read_ip4_address (ifcfg, gw_tag, &next_hop, error)) - goto out; - /* We don't make distinction between missing GATEWAY IP and 0.0.0.0 */ - - /* Prefix */ - if (!read_ip4_address (ifcfg, netmask_tag, &value, error)) - goto out; - if (value) { - guint32 netmask; - - inet_pton (AF_INET, value, &netmask); - prefix = nm_utils_ip4_netmask_to_prefix (netmask); - g_free (value); - if (prefix == 0 || netmask != nm_utils_ip4_prefix_to_netmask (prefix)) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Invalid IP4 netmask '%s' \"%s\"", netmask_tag, nm_utils_inet4_ntop (netmask, NULL)); - goto out; - } - } else { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Missing IP4 route element '%s'", netmask_tag); - goto out; - } - - /* Metric */ - value = svGetValue (ifcfg, metric_tag, FALSE); - if (value) { - metric = _nm_utils_ascii_str_to_int64 (value, 10, 0, G_MAXUINT32, -1); - if (metric < 0) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Invalid IP4 route metric '%s'", value); - g_free (value); - goto out; - } - g_free (value); - } else - metric = -1; - - *out_route = nm_ip_route_new (AF_INET, dest, prefix, next_hop, metric, error); - if (*out_route) - success = TRUE; - -out: - g_free (dest); - g_free (next_hop); - g_free (ip_tag); - g_free (netmask_tag); - g_free (gw_tag); - g_free (metric_tag); - return success; -} - -static gboolean -read_route_file_legacy (const char *filename, NMSettingIPConfig *s_ip4, GError **error) -{ - char *contents = NULL; - gsize len = 0; - char **lines = NULL, **iter; - GRegex *regex_to1, *regex_to2, *regex_via, *regex_metric; - GMatchInfo *match_info; - int prefix_int; - gint64 metric_int; - gboolean success = FALSE; - - const char *pattern_empty = "^\\s*(\\#.*)?$"; - const char *pattern_to1 = "^\\s*(\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}|default)" /* IP or 'default' keyword */ - "(?:/(\\d{1,2}))?"; /* optional prefix */ - const char *pattern_to2 = "to\\s+(\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}|default)" /* IP or 'default' keyword */ - "(?:/(\\d{1,2}))?"; /* optional prefix */ - const char *pattern_via = "via\\s+(\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3})"; /* IP of gateway */ - const char *pattern_metric = "metric\\s+(\\d+)"; /* metric */ - - g_return_val_if_fail (filename != NULL, FALSE); - g_return_val_if_fail (s_ip4 != NULL, FALSE); - g_return_val_if_fail (!error || !*error, FALSE); - - /* Read the route file */ - if (!g_file_get_contents (filename, &contents, &len, NULL) || !len) { - g_free (contents); - return TRUE; /* missing/empty = success */ - } - - /* Create regexes for pieces to be matched */ - regex_to1 = g_regex_new (pattern_to1, 0, 0, NULL); - regex_to2 = g_regex_new (pattern_to2, 0, 0, NULL); - regex_via = g_regex_new (pattern_via, 0, 0, NULL); - regex_metric = g_regex_new (pattern_metric, 0, 0, NULL); - - /* Iterate through file lines */ - lines = g_strsplit_set (contents, "\n\r", -1); - for (iter = lines; iter && *iter; iter++) { - gs_free char *next_hop = NULL, *dest = NULL; - char *prefix, *metric; - NMIPRoute *route; - - /* Skip empty lines */ - if (g_regex_match_simple (pattern_empty, *iter, 0, 0)) - continue; - - /* Destination */ - g_regex_match (regex_to1, *iter, 0, &match_info); - if (!g_match_info_matches (match_info)) { - g_match_info_free (match_info); - g_regex_match (regex_to2, *iter, 0, &match_info); - if (!g_match_info_matches (match_info)) { - g_match_info_free (match_info); - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Missing IP4 route destination address in record: '%s'", *iter); - goto error; - } - } - dest = g_match_info_fetch (match_info, 1); - if (!strcmp (dest, "default")) { - g_match_info_free (match_info); - PARSE_WARNING ("ignoring manual default route: '%s' (%s)", *iter, filename); - continue; - } - if (!nm_utils_ipaddr_valid (AF_INET, dest)) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Invalid IP4 route destination address '%s'", dest); - g_match_info_free (match_info); - goto error; - } - - /* Prefix - is optional; 32 if missing */ - prefix = g_match_info_fetch (match_info, 2); - g_match_info_free (match_info); - prefix_int = 32; - if (prefix) { - prefix_int = _nm_utils_ascii_str_to_int64 (prefix, 10, 1, 32, -1); - if (prefix_int == -1) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Invalid IP4 route destination prefix '%s'", prefix); - g_free (prefix); - goto error; - } - } - g_free (prefix); - - /* Next hop */ - g_regex_match (regex_via, *iter, 0, &match_info); - if (g_match_info_matches (match_info)) { - next_hop = g_match_info_fetch (match_info, 1); - if (!nm_utils_ipaddr_valid (AF_INET, next_hop)) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Invalid IP4 route gateway address '%s'", - next_hop); - g_match_info_free (match_info); - goto error; - } - } else { - /* we don't make distinction between missing GATEWAY IP and 0.0.0.0 */ - } - g_match_info_free (match_info); - - /* Metric */ - g_regex_match (regex_metric, *iter, 0, &match_info); - metric_int = -1; - if (g_match_info_matches (match_info)) { - metric = g_match_info_fetch (match_info, 1); - metric_int = _nm_utils_ascii_str_to_int64 (metric, 10, 0, G_MAXUINT32, -1); - if (metric_int == -1) { - g_match_info_free (match_info); - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Invalid IP4 route metric '%s'", metric); - g_free (metric); - goto error; - } - g_free (metric); - } - g_match_info_free (match_info); - - route = nm_ip_route_new (AF_INET, dest, prefix_int, next_hop, metric_int, error); - if (!route) - goto error; - if (!nm_setting_ip_config_add_route (s_ip4, route)) - PARSE_WARNING ("duplicate IP4 route"); - nm_ip_route_unref (route); - } - - success = TRUE; - -error: - g_free (contents); - g_strfreev (lines); - g_regex_unref (regex_to1); - g_regex_unref (regex_to2); - g_regex_unref (regex_via); - g_regex_unref (regex_metric); - - return success; -} - -static void -parse_dns_options (NMSettingIPConfig *ip_config, char *value) -{ - char **options = NULL; - - g_return_if_fail (ip_config); - - if (!value) - return; - - if (!nm_setting_ip_config_has_dns_options (ip_config)) - nm_setting_ip_config_clear_dns_options (ip_config, TRUE); - - options = g_strsplit (value, " ", 0); - if (options) { - char **item; - for (item = options; *item; item++) { - if (strlen (*item)) { - if (!nm_setting_ip_config_add_dns_option (ip_config, *item)) - PARSE_WARNING ("can't add DNS option '%s'", *item); - } - } - g_strfreev (options); - } -} - -static gboolean -parse_full_ip6_address (shvarFile *ifcfg, - const char *addr_str, - int i, - NMIPAddress **out_address, - GError **error) -{ - char **list; - char *ip_val, *prefix_val; - int prefix; - gboolean success = FALSE; - - g_return_val_if_fail (addr_str != NULL, FALSE); - g_return_val_if_fail (out_address != NULL, FALSE); - g_return_val_if_fail (*out_address == NULL, FALSE); - g_return_val_if_fail (!error || !*error, FALSE); - - /* Split the address and prefix */ - list = g_strsplit_set (addr_str, "/", 2); - if (g_strv_length (list) < 1) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Invalid IP6 address '%s'", addr_str); - goto error; - } - - ip_val = list[0]; - - prefix_val = list[1]; - if (prefix_val) { - prefix = _nm_utils_ascii_str_to_int64 (prefix_val, 10, 0, 128, -1); - if (prefix < 0) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Invalid IP6 prefix '%s'", prefix_val); - goto error; - } - } else { - /* Missing prefix is treated as prefix of 64 */ - prefix = 64; - } - - *out_address = nm_ip_address_new (AF_INET6, ip_val, prefix, error); - if (*out_address) - success = TRUE; - -error: - g_strfreev (list); - return success; -} - -/* IPv6 address is very complex to describe completely by a regular expression, - * so don't try to, rather use looser syntax to comprise all possibilities - * NOTE: The regexes below don't describe all variants allowed by 'ip route add', - * namely destination IP without 'to' keyword is recognized just at line start. - */ -#define IPV6_ADDR_REGEX "[0-9A-Fa-f:.]+" - -static gboolean -read_route6_file (const char *filename, NMSettingIPConfig *s_ip6, GError **error) -{ - char *contents = NULL; - gsize len = 0; - char **lines = NULL, **iter; - GRegex *regex_to1, *regex_to2, *regex_via, *regex_metric; - GMatchInfo *match_info; - char *dest = NULL, *prefix = NULL, *next_hop = NULL, *metric = NULL; - int prefix_int; - gint64 metric_int; - gboolean success = FALSE; - - const char *pattern_empty = "^\\s*(\\#.*)?$"; - const char *pattern_to1 = "^\\s*(default|" IPV6_ADDR_REGEX ")" /* IPv6 or 'default' keyword */ - "(?:/(\\d{1,3}))?"; /* optional prefix */ - const char *pattern_to2 = "to\\s+(default|" IPV6_ADDR_REGEX ")" /* IPv6 or 'default' keyword */ - "(?:/(\\d{1,3}))?"; /* optional prefix */ - const char *pattern_via = "via\\s+(" IPV6_ADDR_REGEX ")"; /* IPv6 of gateway */ - const char *pattern_metric = "metric\\s+(\\d+)"; /* metric */ - - g_return_val_if_fail (filename != NULL, FALSE); - g_return_val_if_fail (s_ip6 != NULL, FALSE); - g_return_val_if_fail (!error || !*error, FALSE); - - /* Read the route file */ - if (!g_file_get_contents (filename, &contents, &len, NULL) || !len) { - g_free (contents); - return TRUE; /* missing/empty = success */ - } - - /* Create regexes for pieces to be matched */ - regex_to1 = g_regex_new (pattern_to1, 0, 0, NULL); - regex_to2 = g_regex_new (pattern_to2, 0, 0, NULL); - regex_via = g_regex_new (pattern_via, 0, 0, NULL); - regex_metric = g_regex_new (pattern_metric, 0, 0, NULL); - - /* Iterate through file lines */ - lines = g_strsplit_set (contents, "\n\r", -1); - for (iter = lines; iter && *iter; iter++) { - NMIPRoute *route; - - /* Skip empty lines */ - if (g_regex_match_simple (pattern_empty, *iter, 0, 0)) - continue; - - /* Destination */ - g_regex_match (regex_to1, *iter, 0, &match_info); - if (!g_match_info_matches (match_info)) { - g_match_info_free (match_info); - g_regex_match (regex_to2, *iter, 0, &match_info); - if (!g_match_info_matches (match_info)) { - g_match_info_free (match_info); - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Missing IP6 route destination address in record: '%s'", *iter); - goto error; - } - } - dest = g_match_info_fetch (match_info, 1); - if (!g_strcmp0 (dest, "default")) { - /* Ignore default route - NM handles it internally */ - g_clear_pointer (&dest, g_free); - g_match_info_free (match_info); - PARSE_WARNING ("ignoring manual default route: '%s' (%s)", *iter, filename); - continue; - } - - /* Prefix - is optional; 128 if missing */ - prefix = g_match_info_fetch (match_info, 2); - g_match_info_free (match_info); - prefix_int = 128; - if (prefix) { - prefix_int = _nm_utils_ascii_str_to_int64 (prefix, 10, 1, 128, -1); - if (prefix_int == -1) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Invalid IP6 route destination prefix '%s'", prefix); - g_free (dest); - g_free (prefix); - goto error; - } - } - g_free (prefix); - - /* Next hop */ - g_regex_match (regex_via, *iter, 0, &match_info); - if (g_match_info_matches (match_info)) { - next_hop = g_match_info_fetch (match_info, 1); - if (!nm_utils_ipaddr_valid (AF_INET6, next_hop)) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Invalid IPv6 route nexthop address '%s'", - next_hop); - g_match_info_free (match_info); - g_free (dest); - g_free (next_hop); - goto error; - } - } else { - /* Missing "via" is taken as :: */ - next_hop = NULL; - } - g_match_info_free (match_info); - - /* Metric */ - g_regex_match (regex_metric, *iter, 0, &match_info); - metric_int = -1; - if (g_match_info_matches (match_info)) { - metric = g_match_info_fetch (match_info, 1); - metric_int = _nm_utils_ascii_str_to_int64 (metric, 10, 0, G_MAXUINT32, -1); - if (metric_int == -1) { - g_match_info_free (match_info); - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Invalid IP6 route metric '%s'", metric); - g_free (dest); - g_free (next_hop); - g_free (metric); - goto error; - } - g_free (metric); - } - g_match_info_free (match_info); - - route = nm_ip_route_new (AF_INET6, dest, prefix_int, next_hop, metric_int, error); - g_free (dest); - g_free (next_hop); - if (!route) - goto error; - if (!nm_setting_ip_config_add_route (s_ip6, route)) - PARSE_WARNING ("duplicate IP6 route"); - nm_ip_route_unref (route); - } - - success = TRUE; - -error: - g_free (contents); - g_strfreev (lines); - g_regex_unref (regex_to1); - g_regex_unref (regex_to2); - g_regex_unref (regex_via); - g_regex_unref (regex_metric); - - return success; -} - - -static NMSetting * -make_ip4_setting (shvarFile *ifcfg, - const char *network_file, - GError **error) -{ - NMSettingIPConfig *s_ip4 = NULL; - char *value = NULL; - char *route_path = NULL; - char *method; - char *dns_options = NULL; - gs_free char *gateway = NULL; - gint32 i; - shvarFile *network_ifcfg; - shvarFile *route_ifcfg; - gboolean never_default = FALSE; - gint64 timeout; - gint priority; - - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); - - /* First check if DEFROUTE is set for this device; DEFROUTE has the - * opposite meaning from never-default. The default if DEFROUTE is not - * specified is DEFROUTE=yes which means that this connection can be used - * as a default route - */ - never_default = !svGetValueBoolean (ifcfg, "DEFROUTE", TRUE); - - /* Then check if GATEWAYDEV; it's global and overrides DEFROUTE */ - network_ifcfg = svOpenFile (network_file, NULL); - if (network_ifcfg) { - char *gatewaydev; - - /* Get the connection ifcfg device name and the global gateway device */ - value = svGetValue (ifcfg, "DEVICE", FALSE); - gatewaydev = svGetValue (network_ifcfg, "GATEWAYDEV", FALSE); - dns_options = svGetValueFull (network_ifcfg, "RES_OPTIONS", FALSE); - - /* If there was a global gateway device specified, then only connections - * for that device can be the default connection. - */ - if (gatewaydev && value) - never_default = !!strcmp (value, gatewaydev); - - g_free (gatewaydev); - g_free (value); - svCloseFile (network_ifcfg); - } - - value = svGetValue (ifcfg, "BOOTPROTO", FALSE); - - if (!value || !*value || !g_ascii_strcasecmp (value, "none")) { - if (is_any_ip4_address_defined (ifcfg, NULL)) - method = NM_SETTING_IP4_CONFIG_METHOD_MANUAL; - else - method = NM_SETTING_IP4_CONFIG_METHOD_DISABLED; - } else if (!g_ascii_strcasecmp (value, "bootp") || !g_ascii_strcasecmp (value, "dhcp")) { - method = NM_SETTING_IP4_CONFIG_METHOD_AUTO; - } else if (!g_ascii_strcasecmp (value, "static")) { - if (is_any_ip4_address_defined (ifcfg, NULL)) - method = NM_SETTING_IP4_CONFIG_METHOD_MANUAL; - else - method = NM_SETTING_IP4_CONFIG_METHOD_DISABLED; - } else if (!g_ascii_strcasecmp (value, "autoip")) { - method = NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL; - } else if (!g_ascii_strcasecmp (value, "shared")) { - int idx; - - g_free (value); - g_object_set (s_ip4, - NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_SHARED, - NM_SETTING_IP_CONFIG_NEVER_DEFAULT, never_default, - NULL); - /* 1 IP address is allowed for shared connections. Read it. */ - if (is_any_ip4_address_defined (ifcfg, &idx)) { - NMIPAddress *addr = NULL; - - if (!read_full_ip4_address (ifcfg, idx, NULL, &addr, NULL, error)) - goto done; - if (!read_ip4_address (ifcfg, "GATEWAY", &gateway, error)) - goto done; - (void) nm_setting_ip_config_add_address (s_ip4, addr); - nm_ip_address_unref (addr); - if (never_default) - PARSE_WARNING ("GATEWAY will be ignored when DEFROUTE is disabled"); - g_object_set (s_ip4, NM_SETTING_IP_CONFIG_GATEWAY, gateway, NULL); - } - return NM_SETTING (s_ip4); - } else { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Unknown BOOTPROTO '%s'", value); - g_free (value); - goto done; - } - g_free (value); - - g_object_set (s_ip4, - NM_SETTING_IP_CONFIG_METHOD, method, - NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS, !svGetValueBoolean (ifcfg, "PEERDNS", TRUE), - NM_SETTING_IP_CONFIG_IGNORE_AUTO_ROUTES, !svGetValueBoolean (ifcfg, "PEERROUTES", TRUE), - NM_SETTING_IP_CONFIG_NEVER_DEFAULT, never_default, - NM_SETTING_IP_CONFIG_MAY_FAIL, !svGetValueBoolean (ifcfg, "IPV4_FAILURE_FATAL", FALSE), - NM_SETTING_IP_CONFIG_ROUTE_METRIC, svGetValueInt64 (ifcfg, "IPV4_ROUTE_METRIC", 10, - -1, G_MAXUINT32, -1), - NULL); - - if (strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_DISABLED) == 0) - return NM_SETTING (s_ip4); - - /* Handle DHCP settings */ - if (!strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_AUTO)) { - value = svGetValue (ifcfg, "DHCP_HOSTNAME", FALSE); - if (value && *value) - g_object_set (s_ip4, NM_SETTING_IP_CONFIG_DHCP_HOSTNAME, value, NULL); - g_free (value); - - value = svGetValue (ifcfg, "DHCP_FQDN", FALSE); - if (value && *value) { - g_object_set (s_ip4, - NM_SETTING_IP_CONFIG_DHCP_HOSTNAME, NULL, - NM_SETTING_IP4_CONFIG_DHCP_FQDN, value, - NULL); - } - g_free (value); - - g_object_set (s_ip4, - NM_SETTING_IP_CONFIG_DHCP_SEND_HOSTNAME, svGetValueBoolean (ifcfg, "DHCP_SEND_HOSTNAME", TRUE), - NM_SETTING_IP_CONFIG_DHCP_TIMEOUT, svGetValueInt64 (ifcfg, "IPV4_DHCP_TIMEOUT", 10, 0, G_MAXINT32, 0), - NULL); - - value = svGetValue (ifcfg, "DHCP_CLIENT_ID", FALSE); - if (value && strlen (value)) - g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_DHCP_CLIENT_ID, value, NULL); - g_free (value); - } - - /* Read static IP addresses. - * Read them even for AUTO method - in this case the addresses are - * added to the automatic ones. Note that this is not currently supported by - * the legacy 'network' service (ifup-eth). - */ - for (i = -1; i < 256; i++) { - NMIPAddress *addr = NULL; - - /* gateway will only be set if still unset. Hence, we don't leak gateway - * here by calling read_full_ip4_address() repeatedly */ - if (!read_full_ip4_address (ifcfg, i, NULL, &addr, &gateway, error)) - goto done; - - if (!addr) { - /* The first mandatory variable is 2-indexed (IPADDR2) - * Variables IPADDR, IPADDR0 and IPADDR1 are optional */ - if (i > 1) - break; - continue; - } - - if (!nm_setting_ip_config_add_address (s_ip4, addr)) - PARSE_WARNING ("duplicate IP4 address"); - nm_ip_address_unref (addr); - } - - /* Gateway */ - if (!gateway) { - network_ifcfg = svOpenFile (network_file, NULL); - if (network_ifcfg) { - gboolean read_success; - - read_success = read_ip4_address (network_ifcfg, "GATEWAY", &gateway, error); - svCloseFile (network_ifcfg); - if (!read_success) - goto done; - - if (gateway && nm_setting_ip_config_get_num_addresses (s_ip4) == 0) { - gs_free char *f = g_path_get_basename (ifcfg->fileName); - PARSE_WARNING ("ignoring GATEWAY (/etc/sysconfig/network) for %s " - "because the connection has no static addresses", f); - g_clear_pointer (&gateway, g_free); - } - } - } - g_object_set (s_ip4, NM_SETTING_IP_CONFIG_GATEWAY, gateway, NULL); - - if (gateway && never_default) - PARSE_WARNING ("GATEWAY will be ignored when DEFROUTE is disabled"); - - /* DNS servers - * Pick up just IPv4 addresses (IPv6 addresses are taken by make_ip6_setting()) - */ - for (i = 1; i <= 10; i++) { - char *tag; - - tag = g_strdup_printf ("DNS%u", i); - value = svGetValue (ifcfg, tag, FALSE); - if (value) { - if (nm_utils_ipaddr_valid (AF_INET, value)) { - if (!nm_setting_ip_config_add_dns (s_ip4, value)) - PARSE_WARNING ("duplicate DNS server %s", tag); - } else if (nm_utils_ipaddr_valid (AF_INET6, value)) { - /* Ignore IPv6 addresses */ - } else { - PARSE_WARNING ("invalid DNS server address %s", value); - g_free (tag); - g_free (value); - goto done; - } - - g_free (value); - } - - g_free (tag); - } - - /* DNS searches */ - value = svGetValue (ifcfg, "DOMAIN", FALSE); - if (value) { - char **searches = NULL; - - searches = g_strsplit (value, " ", 0); - if (searches) { - char **item; - for (item = searches; *item; item++) { - if (strlen (*item)) { - if (!nm_setting_ip_config_add_dns_search (s_ip4, *item)) - PARSE_WARNING ("duplicate DNS domain '%s'", *item); - } - } - g_strfreev (searches); - } - g_free (value); - } - - /* DNS options */ - value = svGetValueFull (ifcfg, "RES_OPTIONS", FALSE); - parse_dns_options (s_ip4, value); - parse_dns_options (s_ip4, dns_options); - g_free (value); - g_free (dns_options); - dns_options = NULL; - - /* DNS priority */ - priority = svGetValueInt64 (ifcfg, "IPV4_DNS_PRIORITY", 10, G_MININT32, G_MAXINT32, 0); - g_object_set (s_ip4, - NM_SETTING_IP_CONFIG_DNS_PRIORITY, - priority, - NULL); - - /* Static routes - route- file */ - route_path = utils_get_route_path (ifcfg->fileName); - - if (utils_has_complex_routes (route_path)) { - PARSE_WARNING ("'rule-' or 'rule6-' file is present; you will need to use a dispatcher script to apply these routes"); - } else if (utils_has_route_file_new_syntax (route_path)) { - /* Parse route file in new syntax */ - route_ifcfg = utils_get_route_ifcfg (ifcfg->fileName, FALSE); - if (route_ifcfg) { - for (i = 0; i < 256; i++) { - NMIPRoute *route = NULL; - - if (!read_one_ip4_route (route_ifcfg, i, &route, error)) { - svCloseFile (route_ifcfg); - goto done; - } - - if (!route) - break; - - if (!nm_setting_ip_config_add_route (s_ip4, route)) - PARSE_WARNING ("duplicate IP4 route"); - nm_ip_route_unref (route); - } - svCloseFile (route_ifcfg); - } - } else { - if (!read_route_file_legacy (route_path, s_ip4, error)) - goto done; - } - g_free (route_path); - - /* Legacy value NM used for a while but is incorrect (rh #459370) */ - if (!nm_setting_ip_config_get_num_dns_searches (s_ip4)) { - value = svGetValue (ifcfg, "SEARCH", FALSE); - if (value) { - char **searches = NULL; - - searches = g_strsplit (value, " ", 0); - if (searches) { - char **item; - for (item = searches; *item; item++) { - if (strlen (*item)) { - if (!nm_setting_ip_config_add_dns_search (s_ip4, *item)) - PARSE_WARNING ("duplicate DNS search '%s'", *item); - } - } - g_strfreev (searches); - } - g_free (value); - } - } - - timeout = svGetValueInt64 (ifcfg, "ARPING_WAIT", 10, -1, - NM_SETTING_IP_CONFIG_DAD_TIMEOUT_MAX / 1000, -1); - g_object_set (s_ip4, NM_SETTING_IP_CONFIG_DAD_TIMEOUT, - (gint) (timeout <= 0 ? timeout : timeout * 1000), NULL); - - return NM_SETTING (s_ip4); - -done: - g_free (dns_options); - g_free (route_path); - g_object_unref (s_ip4); - return NULL; -} - -static void -read_aliases (NMSettingIPConfig *s_ip4, const char *filename) -{ - GDir *dir; - char *dirname, *base; - shvarFile *parsed; - NMIPAddress *base_addr = NULL; - GError *err = NULL; - - g_return_if_fail (s_ip4 != NULL); - g_return_if_fail (filename != NULL); - - if (nm_setting_ip_config_get_num_addresses (s_ip4) > 0) - base_addr = nm_setting_ip_config_get_address (s_ip4, 0); - - dirname = g_path_get_dirname (filename); - g_return_if_fail (dirname != NULL); - base = g_path_get_basename (filename); - g_return_if_fail (base != NULL); - - dir = g_dir_open (dirname, 0, &err); - if (dir) { - const char *item; - NMIPAddress *addr; - gboolean ok; - - while ((item = g_dir_read_name (dir))) { - char *full_path, *device; - const char *p; - - if (!utils_is_ifcfg_alias_file (item, base)) - continue; - - full_path = g_build_filename (dirname, item, NULL); - - p = strchr (item, ':'); - g_assert (p != NULL); /* we know this is true from utils_is_ifcfg_alias_file() */ - for (p++; *p; p++) { - if (!g_ascii_isalnum (*p) && *p != '_') - break; - } - if (*p) { - PARSE_WARNING ("ignoring alias file '%s' with invalid name", full_path); - g_free (full_path); - continue; - } - - parsed = svOpenFile (full_path, &err); - if (!parsed) { - PARSE_WARNING ("couldn't parse alias file '%s': %s", full_path, err->message); - g_free (full_path); - g_clear_error (&err); - continue; - } - - device = svGetValue (parsed, "DEVICE", FALSE); - if (!device) { - PARSE_WARNING ("alias file '%s' has no DEVICE", full_path); - svCloseFile (parsed); - g_free (full_path); - continue; - } - /* We know that item starts with IFCFG_TAG from utils_is_ifcfg_alias_file() */ - if (strcmp (device, item + strlen (IFCFG_TAG)) != 0) { - PARSE_WARNING ("alias file '%s' has invalid DEVICE (%s) for filename", - full_path, device); - g_free (device); - svCloseFile (parsed); - g_free (full_path); - continue; - } - - addr = NULL; - ok = read_full_ip4_address (parsed, -1, base_addr, &addr, NULL, &err); - svCloseFile (parsed); - if (ok) { - nm_ip_address_set_attribute (addr, "label", g_variant_new_string (device)); - if (!nm_setting_ip_config_add_address (s_ip4, addr)) - PARSE_WARNING ("duplicate IP4 address in alias file %s", item); - } else { - PARSE_WARNING ("error reading IP4 address from alias file '%s': %s", - full_path, err ? err->message : "no address"); - g_clear_error (&err); - } - nm_ip_address_unref (addr); - - g_free (device); - g_free (full_path); - } - - g_dir_close (dir); - } else { - PARSE_WARNING ("can not read directory '%s': %s", dirname, err->message); - g_error_free (err); - } - - g_free (base); - g_free (dirname); -} - -static NMSetting * -make_ip6_setting (shvarFile *ifcfg, - const char *network_file, - GError **error) -{ - NMSettingIPConfig *s_ip6 = NULL; - char *value = NULL; - char *str_value; - char *route6_path = NULL; - char *dns_options = NULL; - gboolean ipv6init, ipv6forwarding, ipv6_autoconf, dhcp6 = FALSE; - char *method = NM_SETTING_IP6_CONFIG_METHOD_MANUAL; - char *ipv6addr, *ipv6addr_secondaries; - char **list = NULL, **iter; - guint32 i; - gint priority; - shvarFile *network_ifcfg; - gboolean never_default = FALSE; - gboolean ip6_privacy = FALSE, ip6_privacy_prefer_public_ip; - NMSettingIP6ConfigPrivacy ip6_privacy_val; - NMSettingIP6ConfigAddrGenMode addr_gen_mode; - char *tmp; - - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new (); - - /* First check if IPV6_DEFROUTE is set for this device; IPV6_DEFROUTE has the - * opposite meaning from never-default. The default if IPV6_DEFROUTE is not - * specified is IPV6_DEFROUTE=yes which means that this connection can be used - * as a default route - */ - never_default = !svGetValueBoolean (ifcfg, "IPV6_DEFROUTE", TRUE); - - /* Then check if IPV6_DEFAULTGW or IPV6_DEFAULTDEV is specified; - * they are global and override IPV6_DEFROUTE - * When both are set, the device specified in IPV6_DEFAULTGW takes preference. - */ - network_ifcfg = svOpenFile (network_file, NULL); - if (network_ifcfg) { - char *ipv6_defaultgw, *ipv6_defaultdev; - char *default_dev = NULL; - - /* Get the connection ifcfg device name and the global default route device */ - value = svGetValue (ifcfg, "DEVICE", FALSE); - ipv6_defaultgw = svGetValue (network_ifcfg, "IPV6_DEFAULTGW", FALSE); - ipv6_defaultdev = svGetValue (network_ifcfg, "IPV6_DEFAULTDEV", FALSE); - dns_options = svGetValueFull (network_ifcfg, "RES_OPTIONS", FALSE); - - if (ipv6_defaultgw) { - default_dev = strchr (ipv6_defaultgw, '%'); - if (default_dev) - default_dev++; - } - if (!default_dev) - default_dev = ipv6_defaultdev; - - /* If there was a global default route device specified, then only connections - * for that device can be the default connection. - */ - if (default_dev && value) - never_default = !!strcmp (value, default_dev); - - g_free (ipv6_defaultgw); - g_free (ipv6_defaultdev); - g_free (value); - svCloseFile (network_ifcfg); - } - - /* Find out method property */ - /* Is IPV6 enabled? Set method to "ignored", when not enabled */ - str_value = svGetValue (ifcfg, "IPV6INIT", FALSE); - ipv6init = svGetValueBoolean (ifcfg, "IPV6INIT", FALSE); - if (!str_value) { - network_ifcfg = svOpenFile (network_file, NULL); - if (network_ifcfg) { - ipv6init = svGetValueBoolean (network_ifcfg, "IPV6INIT", FALSE); - svCloseFile (network_ifcfg); - } - } - g_free (str_value); - - if (!ipv6init) - method = NM_SETTING_IP6_CONFIG_METHOD_IGNORE; /* IPv6 is disabled */ - else { - ipv6forwarding = svGetValueBoolean (ifcfg, "IPV6FORWARDING", FALSE); - ipv6_autoconf = svGetValueBoolean (ifcfg, "IPV6_AUTOCONF", !ipv6forwarding); - dhcp6 = svGetValueBoolean (ifcfg, "DHCPV6C", FALSE); - - if (ipv6_autoconf) - method = NM_SETTING_IP6_CONFIG_METHOD_AUTO; - else if (dhcp6) - method = NM_SETTING_IP6_CONFIG_METHOD_DHCP; - else { - /* IPV6_AUTOCONF=no and no IPv6 address -> method 'link-local' */ - str_value = svGetValue (ifcfg, "IPV6ADDR", FALSE); - if (!str_value) - str_value = svGetValue (ifcfg, "IPV6ADDR_SECONDARIES", FALSE); - - if (!str_value) - method = NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL; - g_free (str_value); - } - } - /* TODO - handle other methods */ - - /* Read IPv6 Privacy Extensions configuration */ - tmp = svGetValue (ifcfg, "IPV6_PRIVACY", FALSE); - if (tmp) { - ip6_privacy = svGetValueBoolean (ifcfg, "IPV6_PRIVACY", FALSE); - if (!ip6_privacy) - ip6_privacy = g_strcmp0 (tmp, "rfc4941") == 0 || - g_strcmp0 (tmp, "rfc3041") == 0; - } - ip6_privacy_prefer_public_ip = svGetValueBoolean (ifcfg, "IPV6_PRIVACY_PREFER_PUBLIC_IP", FALSE); - ip6_privacy_val = tmp ? - (ip6_privacy ? - (ip6_privacy_prefer_public_ip ? NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_PUBLIC_ADDR : NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_TEMP_ADDR) : - NM_SETTING_IP6_CONFIG_PRIVACY_DISABLED) : - NM_SETTING_IP6_CONFIG_PRIVACY_UNKNOWN; - g_free (tmp); - - g_object_set (s_ip6, - NM_SETTING_IP_CONFIG_METHOD, method, - NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS, !svGetValueBoolean (ifcfg, "IPV6_PEERDNS", TRUE), - NM_SETTING_IP_CONFIG_IGNORE_AUTO_ROUTES, !svGetValueBoolean (ifcfg, "IPV6_PEERROUTES", TRUE), - NM_SETTING_IP_CONFIG_NEVER_DEFAULT, never_default, - NM_SETTING_IP_CONFIG_MAY_FAIL, !svGetValueBoolean (ifcfg, "IPV6_FAILURE_FATAL", FALSE), - NM_SETTING_IP_CONFIG_ROUTE_METRIC, svGetValueInt64 (ifcfg, "IPV6_ROUTE_METRIC", 10, - -1, G_MAXUINT32, -1), - NM_SETTING_IP6_CONFIG_IP6_PRIVACY, ip6_privacy_val, - NULL); - - /* Don't bother to read IP, DNS and routes when IPv6 is disabled */ - if (strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_IGNORE) == 0) - return NM_SETTING (s_ip6); - - if ( !strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_AUTO) - || !strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_DHCP)) { - /* METHOD_AUTO may trigger DHCPv6, so save the hostname to send to DHCP */ - value = svGetValue (ifcfg, "DHCP_HOSTNAME", FALSE); - if (value && value[0]) - g_object_set (s_ip6, NM_SETTING_IP_CONFIG_DHCP_HOSTNAME, value, NULL); - g_free (value); - } - - /* Read static IP addresses. - * Read them even for AUTO and DHCP methods - in this case the addresses are - * added to the automatic ones. Note that this is not currently supported by - * the legacy 'network' service (ifup-eth). - */ - ipv6addr = svGetValue (ifcfg, "IPV6ADDR", FALSE); - ipv6addr_secondaries = svGetValue (ifcfg, "IPV6ADDR_SECONDARIES", FALSE); - - value = g_strjoin (ipv6addr && ipv6addr_secondaries ? " " : NULL, - ipv6addr ? ipv6addr : "", - ipv6addr_secondaries ? ipv6addr_secondaries : "", - NULL); - g_free (ipv6addr); - g_free (ipv6addr_secondaries); - - list = g_strsplit_set (value, " ", 0); - g_free (value); - for (iter = list, i = 0; iter && *iter; iter++, i++) { - NMIPAddress *addr = NULL; - - if (!parse_full_ip6_address (ifcfg, *iter, i, &addr, error)) { - g_strfreev (list); - goto error; - } - - if (!nm_setting_ip_config_add_address (s_ip6, addr)) - PARSE_WARNING ("duplicate IP6 address"); - nm_ip_address_unref (addr); - } - g_strfreev (list); - - /* Gateway */ - if (nm_setting_ip_config_get_num_addresses (s_ip6)) { - value = svGetValue (ifcfg, "IPV6_DEFAULTGW", FALSE); - if (!value) { - /* If no gateway in the ifcfg, try global /etc/sysconfig/network instead */ - network_ifcfg = svOpenFile (network_file, NULL); - if (network_ifcfg) { - value = svGetValue (network_ifcfg, "IPV6_DEFAULTGW", FALSE); - svCloseFile (network_ifcfg); - } - } - if (value) { - char *ptr; - if ((ptr = strchr (value, '%')) != NULL) - *ptr = '\0'; /* remove %interface prefix if present */ - if (!nm_utils_ipaddr_valid (AF_INET6, value)) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Invalid IP6 address '%s'", value); - g_free (value); - goto error; - } - - g_object_set (s_ip6, NM_SETTING_IP_CONFIG_GATEWAY, value, NULL); - g_free (value); - } - } - - /* IPv6 addressing mode configuration */ - tmp = svGetValue (ifcfg, "IPV6_ADDR_GEN_MODE", FALSE); - if (tmp) { - if (nm_utils_enum_from_str (nm_setting_ip6_config_addr_gen_mode_get_type (), tmp, - (int *) &addr_gen_mode, NULL)) - g_object_set (s_ip6, NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE, addr_gen_mode, NULL); - else - PARSE_WARNING ("Invalid IPV6_ADDR_GEN_MODE"); - g_free (tmp); - } else { - g_object_set (s_ip6, - NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE, - NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE_EUI64, - NULL); - } - - /* IPv6 tokenized interface identifier */ - tmp = svGetValue (ifcfg, "IPV6_TOKEN", FALSE); - if (tmp) { - g_object_set (s_ip6, NM_SETTING_IP6_CONFIG_TOKEN, tmp, NULL); - g_free (tmp); - } - - /* DNS servers - * Pick up just IPv6 addresses (IPv4 addresses are taken by make_ip4_setting()) - */ - for (i = 1; i <= 10; i++) { - char *tag; - - tag = g_strdup_printf ("DNS%u", i); - value = svGetValue (ifcfg, tag, FALSE); - if (!value) { - g_free (tag); - break; /* all done */ - } - - if (nm_utils_ipaddr_valid (AF_INET6, value)) { - if (!nm_setting_ip_config_add_dns (s_ip6, value)) - PARSE_WARNING ("duplicate DNS server %s", tag); - } else if (nm_utils_ipaddr_valid (AF_INET, value)) { - /* Ignore IPv4 addresses */ - } else { - PARSE_WARNING ("invalid DNS server address %s", value); - g_free (tag); - g_free (value); - goto error; - } - - g_free (tag); - g_free (value); - } - - /* DNS searches ('DOMAIN' key) are read by make_ip4_setting() and included in NMSettingIPConfig */ - - if (!utils_has_complex_routes (ifcfg->fileName)) { - /* Read static routes from route6- file */ - route6_path = utils_get_route6_path (ifcfg->fileName); - if (!read_route6_file (route6_path, s_ip6, error)) - goto error; - - g_free (route6_path); - } - - /* DNS options */ - value = svGetValueFull (ifcfg, "RES_OPTIONS", FALSE); - parse_dns_options (s_ip6, value); - parse_dns_options (s_ip6, dns_options); - g_free (value); - g_free (dns_options); - - /* DNS priority */ - priority = svGetValueInt64 (ifcfg, "IPV6_DNS_PRIORITY", 10, G_MININT32, G_MAXINT32, 0); - g_object_set (s_ip6, - NM_SETTING_IP_CONFIG_DNS_PRIORITY, - priority, - NULL); - - return NM_SETTING (s_ip6); - -error: - g_free (dns_options); - g_free (route6_path); - g_object_unref (s_ip6); - return NULL; -} - -static void -check_if_bond_slave (shvarFile *ifcfg, - NMSettingConnection *s_con) -{ - char *value; - - value = svGetValue (ifcfg, "MASTER", FALSE); - if (value) { - g_object_set (s_con, NM_SETTING_CONNECTION_MASTER, value, NULL); - g_object_set (s_con, - NM_SETTING_CONNECTION_SLAVE_TYPE, NM_SETTING_BOND_SETTING_NAME, - NULL); - g_free (value); - } - - /* We should be checking for SLAVE=yes as well, but NM used to not set that, - * so for backward-compatibility, we don't check. - */ -} - -static gboolean -check_if_team_slave (shvarFile *ifcfg, - NMSettingConnection *s_con) -{ - gs_free char *value = NULL; - - value = svGetValue (ifcfg, "TEAM_MASTER", FALSE); - if (!value) - return FALSE; - g_object_set (s_con, NM_SETTING_CONNECTION_MASTER, value, NULL); - g_object_set (s_con, NM_SETTING_CONNECTION_SLAVE_TYPE, NM_SETTING_TEAM_SETTING_NAME, NULL); - return TRUE; -} - -static void -check_if_slave (shvarFile *ifcfg, - NMSettingConnection *s_con) -{ - g_return_if_fail (NM_IS_SETTING_CONNECTION (s_con)); - - if (check_if_team_slave (ifcfg, s_con)) - return; - check_if_bond_slave (ifcfg, s_con); -} - -typedef struct { - const char *enable_key; - const char *advertise_key; - const char *willing_key; - const char *flags_prop; -} DcbFlagsProperty; - -enum { - DCB_APP_FCOE_FLAGS = 0, - DCB_APP_ISCSI_FLAGS = 1, - DCB_APP_FIP_FLAGS = 2, - DCB_PFC_FLAGS = 3, - DCB_PG_FLAGS = 4, -}; - -static DcbFlagsProperty dcb_flags_props[] = { - { KEY_DCB_APP_FCOE_ENABLE, KEY_DCB_APP_FCOE_ADVERTISE, KEY_DCB_APP_FCOE_WILLING, NM_SETTING_DCB_APP_FCOE_FLAGS }, - { KEY_DCB_APP_ISCSI_ENABLE, KEY_DCB_APP_ISCSI_ADVERTISE, KEY_DCB_APP_ISCSI_WILLING, NM_SETTING_DCB_APP_ISCSI_FLAGS }, - { KEY_DCB_APP_FIP_ENABLE, KEY_DCB_APP_FIP_ADVERTISE, KEY_DCB_APP_FIP_WILLING, NM_SETTING_DCB_APP_FIP_FLAGS }, - { KEY_DCB_PFC_ENABLE, KEY_DCB_PFC_ADVERTISE, KEY_DCB_PFC_WILLING, NM_SETTING_DCB_PRIORITY_FLOW_CONTROL_FLAGS }, - { KEY_DCB_PG_ENABLE, KEY_DCB_PG_ADVERTISE, KEY_DCB_PG_WILLING, NM_SETTING_DCB_PRIORITY_GROUP_FLAGS }, - { NULL }, -}; - -static NMSettingDcbFlags -read_dcb_flags (shvarFile *ifcfg, DcbFlagsProperty *property) -{ - NMSettingDcbFlags flags = NM_SETTING_DCB_FLAG_NONE; - - if (svGetValueBoolean (ifcfg, property->enable_key, FALSE)) - flags |= NM_SETTING_DCB_FLAG_ENABLE; - if (svGetValueBoolean (ifcfg, property->advertise_key, FALSE)) - flags |= NM_SETTING_DCB_FLAG_ADVERTISE; - if (svGetValueBoolean (ifcfg, property->willing_key, FALSE)) - flags |= NM_SETTING_DCB_FLAG_WILLING; - - return flags; -} - -static gboolean -read_dcb_app (shvarFile *ifcfg, - NMSettingDcb *s_dcb, - const char *app, - DcbFlagsProperty *flags_prop, - const char *priority_prop, - GError **error) -{ - NMSettingDcbFlags flags = NM_SETTING_DCB_FLAG_NONE; - char *tmp, *val; - gboolean success = TRUE; - int priority = -1; - - flags = read_dcb_flags (ifcfg, flags_prop); - - /* Priority */ - tmp = g_strdup_printf ("DCB_APP_%s_PRIORITY", app); - val = svGetValue (ifcfg, tmp, FALSE); - if (val) { - priority = _nm_utils_ascii_str_to_int64 (val, 0, 0, 7, -1); - if (priority < 0) { - success = FALSE; - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Invalid %s value '%s' (expected 0 - 7)", - tmp, val); - } - g_free (val); - - if (!(flags & NM_SETTING_DCB_FLAG_ENABLE)) - PARSE_WARNING ("ignoring DCB %s priority; app not enabled", app); - } - g_free (tmp); - - if (success) { - g_object_set (G_OBJECT (s_dcb), - flags_prop->flags_prop, flags, - priority_prop, (guint) priority, - NULL); - } - - return success; -} - -typedef void (*DcbSetBoolFunc) (NMSettingDcb *, guint, gboolean); - -static gboolean -read_dcb_bool_array (shvarFile *ifcfg, - NMSettingDcb *s_dcb, - NMSettingDcbFlags flags, - const char *prop, - const char *desc, - DcbSetBoolFunc set_func, - GError **error) -{ - char *val; - gboolean success = FALSE; - guint i; - - val = svGetValue (ifcfg, prop, FALSE); - if (!val) - return TRUE; - - if (!(flags & NM_SETTING_DCB_FLAG_ENABLE)) { - PARSE_WARNING ("ignoring %s; %s is not enabled", prop, desc); - success = TRUE; - goto out; - } - - val = g_strstrip (val); - if (strlen (val) != 8) { - PARSE_WARNING ("%s value '%s' must be 8 characters long", prop, val); - g_set_error_literal (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "boolean array must be 8 characters"); - goto out; - } - - /* All characters must be either 0 or 1 */ - for (i = 0; i < 8; i++) { - if (val[i] != '0' && val[i] != '1') { - PARSE_WARNING ("invalid %s value '%s': not all 0s and 1s", prop, val); - g_set_error_literal (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "invalid boolean digit"); - goto out; - } - set_func (s_dcb, i, (val[i] == '1')); - } - success = TRUE; - -out: - g_free (val); - return success; -} - -typedef void (*DcbSetUintFunc) (NMSettingDcb *, guint, guint); - -static gboolean -read_dcb_uint_array (shvarFile *ifcfg, - NMSettingDcb *s_dcb, - NMSettingDcbFlags flags, - const char *prop, - const char *desc, - gboolean f_allowed, - DcbSetUintFunc set_func, - GError **error) -{ - char *val; - gboolean success = FALSE; - guint i; - - val = svGetValue (ifcfg, prop, FALSE); - if (!val) - return TRUE; - - if (!(flags & NM_SETTING_DCB_FLAG_ENABLE)) { - PARSE_WARNING ("ignoring %s; %s is not enabled", prop, desc); - success = TRUE; - goto out; - } - - val = g_strstrip (val); - if (strlen (val) != 8) { - PARSE_WARNING ("%s value '%s' must be 8 characters long", prop, val); - g_set_error_literal (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "uint array must be 8 characters"); - goto out; - } - - /* All characters must be either 0 - 7 or (optionally) f */ - for (i = 0; i < 8; i++) { - if (val[i] >= '0' && val[i] <= '7') - set_func (s_dcb, i, val[i] - '0'); - else if (f_allowed && (val[i] == 'f' || val[i] == 'F')) - set_func (s_dcb, i, 15); - else { - PARSE_WARNING ("invalid %s value '%s': not 0 - 7%s", - prop, val, f_allowed ? " or 'f'" : ""); - g_set_error_literal (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "invalid uint digit"); - goto out; - } - } - success = TRUE; - -out: - g_free (val); - return success; -} - -static gboolean -read_dcb_percent_array (shvarFile *ifcfg, - NMSettingDcb *s_dcb, - NMSettingDcbFlags flags, - const char *prop, - const char *desc, - gboolean sum_pct, - DcbSetUintFunc set_func, - GError **error) -{ - char *val; - gboolean success = FALSE; - char **split = NULL, **iter; - guint i, sum = 0; - - val = svGetValue (ifcfg, prop, FALSE); - if (!val) - return TRUE; - - if (!(flags & NM_SETTING_DCB_FLAG_ENABLE)) { - PARSE_WARNING ("ignoring %s; %s is not enabled", prop, desc); - success = TRUE; - goto out; - } - - val = g_strstrip (val); - split = g_strsplit_set (val, ",", 0); - if (!split || (g_strv_length (split) != 8)) { - PARSE_WARNING ("invalid %s percentage list value '%s'", prop, val); - g_set_error_literal (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "percent array must be 8 elements"); - goto out; - } - - for (iter = split, i = 0; iter && *iter; iter++, i++) { - int tmp; - - tmp = _nm_utils_ascii_str_to_int64 (*iter, 0, 0, 100, -1); - if (tmp < 0) { - PARSE_WARNING ("invalid %s percentage value '%s'", prop, *iter); - g_set_error_literal (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "invalid percent element"); - goto out; - } - set_func (s_dcb, i, (guint) tmp); - sum += (guint) tmp; - } - - if (sum_pct && (sum != 100)) { - PARSE_WARNING ("%s percentages do not equal 100%%", prop); - g_set_error_literal (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "invalid percentage sum"); - goto out; - } - - success = TRUE; - -out: - if (split) - g_strfreev (split); - g_free (val); - return success; -} - -static gboolean -make_dcb_setting (shvarFile *ifcfg, - const char *network_file, - NMSetting **out_setting, - GError **error) -{ - NMSettingDcb *s_dcb = NULL; - gboolean dcb_on; - NMSettingDcbFlags flags = NM_SETTING_DCB_FLAG_NONE; - char *val; - - g_return_val_if_fail (out_setting != NULL, FALSE); - - dcb_on = !!svGetValueBoolean (ifcfg, "DCB", FALSE); - if (!dcb_on) - return TRUE; - - s_dcb = (NMSettingDcb *) nm_setting_dcb_new (); - g_assert (s_dcb); - - /* FCOE */ - if (!read_dcb_app (ifcfg, s_dcb, "FCOE", - &dcb_flags_props[DCB_APP_FCOE_FLAGS], - NM_SETTING_DCB_APP_FCOE_PRIORITY, - error)) { - g_object_unref (s_dcb); - return FALSE; - } - if (nm_setting_dcb_get_app_fcoe_flags (s_dcb) & NM_SETTING_DCB_FLAG_ENABLE) { - val = svGetValue (ifcfg, KEY_DCB_APP_FCOE_MODE, FALSE); - if (val) { - if (strcmp (val, NM_SETTING_DCB_FCOE_MODE_FABRIC) == 0 || - strcmp (val, NM_SETTING_DCB_FCOE_MODE_VN2VN) == 0) - g_object_set (G_OBJECT (s_dcb), NM_SETTING_DCB_APP_FCOE_MODE, val, NULL); - else { - PARSE_WARNING ("invalid FCoE mode '%s'", val); - g_set_error_literal (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "invalid FCoE mode"); - g_free (val); - g_object_unref (s_dcb); - return FALSE; - } - g_free (val); - } - } - - /* iSCSI */ - if (!read_dcb_app (ifcfg, s_dcb, "ISCSI", - &dcb_flags_props[DCB_APP_ISCSI_FLAGS], - NM_SETTING_DCB_APP_ISCSI_PRIORITY, - error)) { - g_object_unref (s_dcb); - return FALSE; - } - - /* FIP */ - if (!read_dcb_app (ifcfg, s_dcb, "FIP", - &dcb_flags_props[DCB_APP_FIP_FLAGS], - NM_SETTING_DCB_APP_FIP_PRIORITY, - error)) { - g_object_unref (s_dcb); - return FALSE; - } - - /* Priority Flow Control */ - flags = read_dcb_flags (ifcfg, &dcb_flags_props[DCB_PFC_FLAGS]); - g_object_set (G_OBJECT (s_dcb), NM_SETTING_DCB_PRIORITY_FLOW_CONTROL_FLAGS, flags, NULL); - - if (!read_dcb_bool_array (ifcfg, - s_dcb, - flags, - KEY_DCB_PFC_UP, - "PFC", - nm_setting_dcb_set_priority_flow_control, - error)) { - g_object_unref (s_dcb); - return FALSE; - } - - /* Priority Groups */ - flags = read_dcb_flags (ifcfg, &dcb_flags_props[DCB_PG_FLAGS]); - g_object_set (G_OBJECT (s_dcb), NM_SETTING_DCB_PRIORITY_GROUP_FLAGS, flags, NULL); - - if (!read_dcb_uint_array (ifcfg, - s_dcb, - flags, - KEY_DCB_PG_ID, - "PGID", - TRUE, - nm_setting_dcb_set_priority_group_id, - error)) { - g_object_unref (s_dcb); - return FALSE; - } - - /* Group bandwidth */ - if (!read_dcb_percent_array (ifcfg, - s_dcb, - flags, - KEY_DCB_PG_PCT, - "PGPCT", - TRUE, - nm_setting_dcb_set_priority_group_bandwidth, - error)) { - g_object_unref (s_dcb); - return FALSE; - } - - /* Priority bandwidth */ - if (!read_dcb_percent_array (ifcfg, - s_dcb, - flags, - KEY_DCB_PG_UPPCT, - "UPPCT", - FALSE, - nm_setting_dcb_set_priority_bandwidth, - error)) { - g_object_unref (s_dcb); - return FALSE; - } - - /* Strict Bandwidth */ - if (!read_dcb_bool_array (ifcfg, - s_dcb, - flags, - KEY_DCB_PG_STRICT, - "STRICT", - nm_setting_dcb_set_priority_strict_bandwidth, - error)) { - g_object_unref (s_dcb); - return FALSE; - } - - if (!read_dcb_uint_array (ifcfg, - s_dcb, - flags, - KEY_DCB_PG_UP2TC, - "UP2TC", - FALSE, - nm_setting_dcb_set_priority_traffic_class, - error)) { - g_object_unref (s_dcb); - return FALSE; - } - - *out_setting = NM_SETTING (s_dcb); - return TRUE; -} - -static gboolean -add_one_wep_key (shvarFile *ifcfg, - const char *shvar_key, - guint8 key_idx, - gboolean passphrase, - NMSettingWirelessSecurity *s_wsec, - GError **error) -{ - char *key = NULL; - char *value = NULL; - gboolean success = FALSE; - - g_return_val_if_fail (ifcfg != NULL, FALSE); - g_return_val_if_fail (shvar_key != NULL, FALSE); - g_return_val_if_fail (key_idx <= 3, FALSE); - g_return_val_if_fail (s_wsec != NULL, FALSE); - - value = svGetValue (ifcfg, shvar_key, FALSE); - if (!value || !strlen (value)) { - g_free (value); - return TRUE; - } - - /* Validate keys */ - if (passphrase) { - if (strlen (value) && strlen (value) < 64) { - key = g_strdup (value); - g_object_set (G_OBJECT (s_wsec), - NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE, - NM_WEP_KEY_TYPE_PASSPHRASE, - NULL); - } - } else { - if (strlen (value) == 10 || strlen (value) == 26) { - /* Hexadecimal WEP key */ - char *p = value; - - while (*p) { - if (!g_ascii_isxdigit (*p)) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Invalid hexadecimal WEP key."); - goto out; - } - p++; - } - key = g_strdup (value); - } else if ( !strncmp (value, "s:", 2) - && (strlen (value) == 7 || strlen (value) == 15)) { - /* ASCII key */ - char *p = value + 2; - - while (*p) { - if (!g_ascii_isprint ((int) (*p))) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Invalid ASCII WEP key."); - goto out; - } - p++; - } - - /* Remove 's:' prefix. - * Don't convert to hex string. wpa_supplicant takes 'wep_key0' option over D-Bus as byte array - * and converts it to hex string itself. Even though we convert hex string keys into a bin string - * before passing to wpa_supplicant, this prevents two unnecessary conversions. And mainly, - * ASCII WEP key doesn't change to HEX WEP key in UI, which could confuse users. - */ - key = g_strdup (value + 2); - } - } - - if (key) { - nm_setting_wireless_security_set_wep_key (s_wsec, key_idx, key); - g_free (key); - success = TRUE; - } else - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Invalid WEP key length."); - -out: - g_free (value); - return success; -} - -static gboolean -read_wep_keys (shvarFile *ifcfg, - guint8 def_idx, - NMSettingWirelessSecurity *s_wsec, - GError **error) -{ - /* Try hex/ascii keys first */ - if (!add_one_wep_key (ifcfg, "KEY1", 0, FALSE, s_wsec, error)) - return FALSE; - if (!add_one_wep_key (ifcfg, "KEY2", 1, FALSE, s_wsec, error)) - return FALSE; - if (!add_one_wep_key (ifcfg, "KEY3", 2, FALSE, s_wsec, error)) - return FALSE; - if (!add_one_wep_key (ifcfg, "KEY4", 3, FALSE, s_wsec, error)) - return FALSE; - if (!add_one_wep_key (ifcfg, "KEY", def_idx, FALSE, s_wsec, error)) - return FALSE; - - /* And then passphrases */ - if (!add_one_wep_key (ifcfg, "KEY_PASSPHRASE1", 0, TRUE, s_wsec, error)) - return FALSE; - if (!add_one_wep_key (ifcfg, "KEY_PASSPHRASE2", 1, TRUE, s_wsec, error)) - return FALSE; - if (!add_one_wep_key (ifcfg, "KEY_PASSPHRASE3", 2, TRUE, s_wsec, error)) - return FALSE; - if (!add_one_wep_key (ifcfg, "KEY_PASSPHRASE4", 3, TRUE, s_wsec, error)) - return FALSE; - - return TRUE; -} - -static NMSettingSecretFlags -read_secret_flags (shvarFile *ifcfg, const char *flags_key) -{ - NMSettingSecretFlags flags = NM_SETTING_SECRET_FLAG_NONE; - char *val; - - g_return_val_if_fail (flags_key != NULL, NM_SETTING_SECRET_FLAG_NONE); - g_return_val_if_fail (flags_key[0] != '\0', NM_SETTING_SECRET_FLAG_NONE); - g_return_val_if_fail (g_str_has_suffix (flags_key, "_FLAGS"), NM_SETTING_SECRET_FLAG_NONE); - - val = svGetValue (ifcfg, flags_key, FALSE); - if (val) { - if (strstr (val, SECRET_FLAG_AGENT)) - flags |= NM_SETTING_SECRET_FLAG_AGENT_OWNED; - if (strstr (val, SECRET_FLAG_NOT_SAVED)) - flags |= NM_SETTING_SECRET_FLAG_NOT_SAVED; - if (strstr (val, SECRET_FLAG_NOT_REQUIRED)) - flags |= NM_SETTING_SECRET_FLAG_NOT_REQUIRED; - - g_free (val); - } - return flags; -} - -static NMSetting * -make_wep_setting (shvarFile *ifcfg, - const char *file, - GError **error) -{ - NMSettingWirelessSecurity *s_wsec; - char *value; - shvarFile *keys_ifcfg = NULL; - int default_key_idx = 0; - gboolean has_default_key = FALSE; - NMSettingSecretFlags key_flags; - - s_wsec = NM_SETTING_WIRELESS_SECURITY (nm_setting_wireless_security_new ()); - g_object_set (s_wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "none", NULL); - - value = svGetValue (ifcfg, "DEFAULTKEY", FALSE); - if (value) { - default_key_idx = _nm_utils_ascii_str_to_int64 (value, 0, 1, 4, 0); - if (default_key_idx == 0) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Invalid default WEP key '%s'", value); - g_free (value); - goto error; - } - has_default_key = TRUE; - default_key_idx--; /* convert to [0...3] */ - g_object_set (s_wsec, NM_SETTING_WIRELESS_SECURITY_WEP_TX_KEYIDX, (guint) default_key_idx, NULL); - g_free (value); - } - - /* Read WEP key flags */ - key_flags = read_secret_flags (ifcfg, "WEP_KEY_FLAGS"); - g_object_set (s_wsec, NM_SETTING_WIRELESS_SECURITY_WEP_KEY_FLAGS, key_flags, NULL); - - /* Read keys in the ifcfg file if they are system-owned */ - if (key_flags == NM_SETTING_SECRET_FLAG_NONE) { - if (!read_wep_keys (ifcfg, default_key_idx, s_wsec, error)) - goto error; - - /* Try to get keys from the "shadow" key file */ - keys_ifcfg = utils_get_keys_ifcfg (file, FALSE); - if (keys_ifcfg) { - if (!read_wep_keys (keys_ifcfg, default_key_idx, s_wsec, error)) { - svCloseFile (keys_ifcfg); - goto error; - } - svCloseFile (keys_ifcfg); - g_assert (error == NULL || *error == NULL); - } - } - - value = svGetValue (ifcfg, "SECURITYMODE", FALSE); - if (value) { - char *lcase; - - lcase = g_ascii_strdown (value, -1); - g_free (value); - - if (!strcmp (lcase, "open")) { - g_object_set (s_wsec, NM_SETTING_WIRELESS_SECURITY_AUTH_ALG, "open", NULL); - } else if (!strcmp (lcase, "restricted")) { - g_object_set (s_wsec, NM_SETTING_WIRELESS_SECURITY_AUTH_ALG, "shared", NULL); - } else { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Invalid WEP authentication algorithm '%s'", - lcase); - g_free (lcase); - goto error; - } - g_free (lcase); - } - - /* If no WEP keys were given, and the keys are not agent-owned, and no - * default WEP key index was given, then the connection is unencrypted. - */ - if ( !nm_setting_wireless_security_get_wep_key (s_wsec, 0) - && !nm_setting_wireless_security_get_wep_key (s_wsec, 1) - && !nm_setting_wireless_security_get_wep_key (s_wsec, 2) - && !nm_setting_wireless_security_get_wep_key (s_wsec, 3) - && (has_default_key == FALSE) - && (key_flags == NM_SETTING_SECRET_FLAG_NONE)) { - const char *auth_alg; - - auth_alg = nm_setting_wireless_security_get_auth_alg (s_wsec); - if (auth_alg && !strcmp (auth_alg, "shared")) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "WEP Shared Key authentication is invalid for " - "unencrypted connections."); - goto error; - } - - /* Unencrypted */ - g_object_unref (s_wsec); - s_wsec = NULL; - } - - return (NMSetting *) s_wsec; - -error: - if (s_wsec) - g_object_unref (s_wsec); - return NULL; -} - -static gboolean -fill_wpa_ciphers (shvarFile *ifcfg, - NMSettingWirelessSecurity *wsec, - gboolean group, - gboolean adhoc) -{ - char *value = NULL, *p; - char **list = NULL, **iter; - int i = 0; - - p = value = svGetValue (ifcfg, group ? "CIPHER_GROUP" : "CIPHER_PAIRWISE", TRUE); - if (!value) - return TRUE; - - /* Strip quotes */ - if (p[0] == '"') - p++; - if (p[strlen (p) - 1] == '"') - p[strlen (p) - 1] = '\0'; - - list = g_strsplit_set (p, " ", 0); - for (iter = list; iter && *iter; iter++, i++) { - /* Ad-Hoc configurations cannot have pairwise ciphers, and can only - * have one group cipher. Ignore any additional group ciphers and - * any pairwise ciphers specified. - */ - if (adhoc) { - if (group && (i > 0)) { - PARSE_WARNING ("ignoring group cipher '%s' (only one group cipher allowed " - "in Ad-Hoc mode)", *iter); - continue; - } else if (!group) { - PARSE_WARNING ("ignoring pairwise cipher '%s' (pairwise not used " - "in Ad-Hoc mode)", *iter); - continue; - } - } - - if (!strcmp (*iter, "CCMP")) { - if (group) - nm_setting_wireless_security_add_group (wsec, "ccmp"); - else - nm_setting_wireless_security_add_pairwise (wsec, "ccmp"); - } else if (!strcmp (*iter, "TKIP")) { - if (group) - nm_setting_wireless_security_add_group (wsec, "tkip"); - else - nm_setting_wireless_security_add_pairwise (wsec, "tkip"); - } else if (group && !strcmp (*iter, "WEP104")) - nm_setting_wireless_security_add_group (wsec, "wep104"); - else if (group && !strcmp (*iter, "WEP40")) - nm_setting_wireless_security_add_group (wsec, "wep40"); - else { - PARSE_WARNING ("ignoring invalid %s cipher '%s'", - group ? "CIPHER_GROUP" : "CIPHER_PAIRWISE", - *iter); - } - } - - if (list) - g_strfreev (list); - g_free (value); - return TRUE; -} - -#define WPA_PMK_LEN 32 - -static char * -parse_wpa_psk (shvarFile *ifcfg, - const char *file, - GBytes *ssid, - GError **error) -{ - shvarFile *keys_ifcfg; - char *psk = NULL, *p, *hashed = NULL; - size_t plen; - gboolean quoted = FALSE; - - /* Passphrase must be between 10 and 66 characters in length because WPA - * hex keys are exactly 64 characters (no quoting), and WPA passphrases - * are between 8 and 63 characters (inclusive), plus optional quoting if - * the passphrase contains spaces. - */ - - /* Try to get keys from the "shadow" key file */ - keys_ifcfg = utils_get_keys_ifcfg (file, FALSE); - if (keys_ifcfg) { - psk = svGetValue (keys_ifcfg, "WPA_PSK", TRUE); - svCloseFile (keys_ifcfg); - } - - /* Fall back to the original ifcfg */ - if (!psk) - psk = svGetValue (ifcfg, "WPA_PSK", TRUE); - - if (!psk) - return NULL; - - p = psk; - plen = strlen (p); - - if ( (plen >= 2 && (p[0] == '"' || p[0] == '\'') && p[0] == p[plen - 1]) - || (plen >= 3 && p[0] == '$' && p[1] == '\'' && p[1] == p[plen - 1])) - quoted = TRUE; - - if (!quoted && (strlen (psk) == 64)) { - /* Verify the hex PSK; 64 digits */ - while (*p) { - if (!g_ascii_isxdigit (*p++)) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Invalid WPA_PSK (contains non-hexadecimal characters)"); - goto out; - } - } - hashed = g_strdup (psk); - } else { - /* Prior to 4f6eef9e77265484555663cf666cde4fa8323469 and - * 28e2e446868b94b92edc4a82aa0bf1e3eda8ec54 the writer may not have - * properly quoted passphrases, so just handle anything that's unquoted - * and between 8 and 63 characters as a passphrase. - */ - - /* Get rid of the quotes */ - hashed = utils_single_unquote_string (p); - - /* Length check */ - if (strlen (hashed) < 8 || strlen (hashed) > 63) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Invalid WPA_PSK (passphrases must be between " - "8 and 63 characters long (inclusive))"); - g_free (hashed); - hashed = NULL; - goto out; - } - } - - if (!hashed) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Invalid WPA_PSK (doesn't look like a passphrase or hex key)"); - goto out; - } - -out: - g_free (psk); - return hashed; -} - -static gboolean -eap_simple_reader (const char *eap_method, - shvarFile *ifcfg, - shvarFile *keys, - NMSetting8021x *s_8021x, - gboolean phase2, - GError **error) -{ - NMSettingSecretFlags flags; - char *value; - - value = svGetValue (ifcfg, "IEEE_8021X_IDENTITY", FALSE); - if (!value) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Missing IEEE_8021X_IDENTITY for EAP method '%s'.", - eap_method); - return FALSE; - } - g_object_set (s_8021x, NM_SETTING_802_1X_IDENTITY, value, NULL); - g_free (value); - - flags = read_secret_flags (ifcfg, "IEEE_8021X_PASSWORD_FLAGS"); - g_object_set (s_8021x, NM_SETTING_802_1X_PASSWORD_FLAGS, flags, NULL); - - /* Only read the password if it's system-owned */ - if (flags == NM_SETTING_SECRET_FLAG_NONE) { - value = svGetValue (ifcfg, "IEEE_8021X_PASSWORD", FALSE); - if (!value && keys) { - /* Try the lookaside keys file */ - value = svGetValue (keys, "IEEE_8021X_PASSWORD", FALSE); - } - - if (!value) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Missing IEEE_8021X_PASSWORD for EAP method '%s'.", - eap_method); - return FALSE; - } - - g_object_set (s_8021x, NM_SETTING_802_1X_PASSWORD, value, NULL); - g_free (value); - } - - return TRUE; -} - -static char * -get_full_file_path (const char *ifcfg_path, const char *file_path) -{ - const char *base = file_path; - char *p, *ret, *dirname; - - g_return_val_if_fail (ifcfg_path != NULL, NULL); - g_return_val_if_fail (file_path != NULL, NULL); - - if (file_path[0] == '/') - return g_strdup (file_path); - - p = strrchr (file_path, '/'); - if (p) - base = p + 1; - - dirname = g_path_get_dirname (ifcfg_path); - ret = g_build_path ("/", dirname, base, NULL); - g_free (dirname); - return ret; -} - -static gboolean -eap_tls_reader (const char *eap_method, - shvarFile *ifcfg, - shvarFile *keys, - NMSetting8021x *s_8021x, - gboolean phase2, - GError **error) -{ - char *value; - char *ca_cert = NULL; - char *real_path = NULL; - char *client_cert = NULL; - char *privkey = NULL; - char *privkey_password = NULL; - gboolean success = FALSE; - NMSetting8021xCKFormat privkey_format = NM_SETTING_802_1X_CK_FORMAT_UNKNOWN; - const char *ca_cert_key = phase2 ? "IEEE_8021X_INNER_CA_CERT" : "IEEE_8021X_CA_CERT"; - const char *pk_pw_key = phase2 ? "IEEE_8021X_INNER_PRIVATE_KEY_PASSWORD": "IEEE_8021X_PRIVATE_KEY_PASSWORD"; - const char *pk_key = phase2 ? "IEEE_8021X_INNER_PRIVATE_KEY" : "IEEE_8021X_PRIVATE_KEY"; - const char *cli_cert_key = phase2 ? "IEEE_8021X_INNER_CLIENT_CERT" : "IEEE_8021X_CLIENT_CERT"; - const char *pk_pw_flags_key = phase2 ? "IEEE_8021X_INNER_PRIVATE_KEY_PASSWORD_FLAGS": "IEEE_8021X_PRIVATE_KEY_PASSWORD_FLAGS"; - const char *pk_pw_flags_prop = phase2 ? NM_SETTING_802_1X_PHASE2_PRIVATE_KEY_PASSWORD_FLAGS : NM_SETTING_802_1X_PRIVATE_KEY_PASSWORD_FLAGS; - NMSettingSecretFlags flags; - - value = svGetValue (ifcfg, "IEEE_8021X_IDENTITY", FALSE); - if (!value) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Missing IEEE_8021X_IDENTITY for EAP method '%s'.", - eap_method); - return FALSE; - } - g_object_set (s_8021x, NM_SETTING_802_1X_IDENTITY, value, NULL); - g_free (value); - - ca_cert = svGetValue (ifcfg, ca_cert_key, FALSE); - if (ca_cert) { - real_path = get_full_file_path (ifcfg->fileName, ca_cert); - if (phase2) { - if (!nm_setting_802_1x_set_phase2_ca_cert (s_8021x, - real_path, - NM_SETTING_802_1X_CK_SCHEME_PATH, - NULL, - error)) - goto done; - } else { - if (!nm_setting_802_1x_set_ca_cert (s_8021x, - real_path, - NM_SETTING_802_1X_CK_SCHEME_PATH, - NULL, - error)) - goto done; - } - g_free (real_path); - real_path = NULL; - } else { - PARSE_WARNING ("missing %s for EAP method '%s'; this is insecure!", - ca_cert_key, eap_method); - } - - /* Read and set private key password flags */ - flags = read_secret_flags (ifcfg, pk_pw_flags_key); - g_object_set (s_8021x, pk_pw_flags_prop, flags, NULL); - - /* Read the private key password if it's system-owned */ - if (flags == NM_SETTING_SECRET_FLAG_NONE) { - /* Private key password */ - privkey_password = svGetValue (ifcfg, pk_pw_key, FALSE); - if (!privkey_password && keys) { - /* Try the lookaside keys file */ - privkey_password = svGetValue (keys, pk_pw_key, FALSE); - } - - if (!privkey_password) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Missing %s for EAP method '%s'.", - pk_pw_key, - eap_method); - goto done; - } - } - - /* The private key itself */ - privkey = svGetValue (ifcfg, pk_key, FALSE); - if (!privkey) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Missing %s for EAP method '%s'.", - pk_key, - eap_method); - goto done; - } - - real_path = get_full_file_path (ifcfg->fileName, privkey); - if (phase2) { - if (!nm_setting_802_1x_set_phase2_private_key (s_8021x, - real_path, - privkey_password, - NM_SETTING_802_1X_CK_SCHEME_PATH, - &privkey_format, - error)) - goto done; - } else { - if (!nm_setting_802_1x_set_private_key (s_8021x, - real_path, - privkey_password, - NM_SETTING_802_1X_CK_SCHEME_PATH, - &privkey_format, - error)) - goto done; - } - g_free (real_path); - real_path = NULL; - - /* Only set the client certificate if the private key is not PKCS#12 format, - * as NM (due to supplicant restrictions) requires. If the key was PKCS#12, - * then nm_setting_802_1x_set_private_key() already set the client certificate - * to the same value as the private key. - */ - if ( privkey_format == NM_SETTING_802_1X_CK_FORMAT_RAW_KEY - || privkey_format == NM_SETTING_802_1X_CK_FORMAT_X509) { - client_cert = svGetValue (ifcfg, cli_cert_key, FALSE); - if (!client_cert) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Missing %s for EAP method '%s'.", - cli_cert_key, - eap_method); - goto done; - } - - real_path = get_full_file_path (ifcfg->fileName, client_cert); - if (phase2) { - if (!nm_setting_802_1x_set_phase2_client_cert (s_8021x, - real_path, - NM_SETTING_802_1X_CK_SCHEME_PATH, - NULL, - error)) - goto done; - } else { - if (!nm_setting_802_1x_set_client_cert (s_8021x, - real_path, - NM_SETTING_802_1X_CK_SCHEME_PATH, - NULL, - error)) - goto done; - } - g_free (real_path); - real_path = NULL; - } - - success = TRUE; - -done: - g_free (real_path); - g_free (ca_cert); - g_free (client_cert); - g_free (privkey); - g_free (privkey_password); - return success; -} - -static gboolean -eap_peap_reader (const char *eap_method, - shvarFile *ifcfg, - shvarFile *keys, - NMSetting8021x *s_8021x, - gboolean phase2, - GError **error) -{ - char *anon_ident = NULL; - char *ca_cert = NULL; - char *real_cert_path = NULL; - char *inner_auth = NULL; - char *peapver = NULL; - char *lower; - char **list = NULL, **iter; - gboolean success = FALSE; - - ca_cert = svGetValue (ifcfg, "IEEE_8021X_CA_CERT", FALSE); - if (ca_cert) { - real_cert_path = get_full_file_path (ifcfg->fileName, ca_cert); - if (!nm_setting_802_1x_set_ca_cert (s_8021x, - real_cert_path, - NM_SETTING_802_1X_CK_SCHEME_PATH, - NULL, - error)) - goto done; - } else { - PARSE_WARNING ("missing IEEE_8021X_CA_CERT for EAP method '%s'; this is insecure!", - eap_method); - } - - peapver = svGetValue (ifcfg, "IEEE_8021X_PEAP_VERSION", FALSE); - if (peapver) { - if (!strcmp (peapver, "0")) - g_object_set (s_8021x, NM_SETTING_802_1X_PHASE1_PEAPVER, "0", NULL); - else if (!strcmp (peapver, "1")) - g_object_set (s_8021x, NM_SETTING_802_1X_PHASE1_PEAPVER, "1", NULL); - else { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Unknown IEEE_8021X_PEAP_VERSION value '%s'", - peapver); - goto done; - } - } - - if (svGetValueBoolean (ifcfg, "IEEE_8021X_PEAP_FORCE_NEW_LABEL", FALSE)) - g_object_set (s_8021x, NM_SETTING_802_1X_PHASE1_PEAPLABEL, "1", NULL); - - anon_ident = svGetValue (ifcfg, "IEEE_8021X_ANON_IDENTITY", FALSE); - if (anon_ident && strlen (anon_ident)) - g_object_set (s_8021x, NM_SETTING_802_1X_ANONYMOUS_IDENTITY, anon_ident, NULL); - - inner_auth = svGetValue (ifcfg, "IEEE_8021X_INNER_AUTH_METHODS", FALSE); - if (!inner_auth) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Missing IEEE_8021X_INNER_AUTH_METHODS."); - goto done; - } - - /* Handle options for the inner auth method */ - list = g_strsplit (inner_auth, " ", 0); - for (iter = list; iter && *iter; iter++) { - if (!strlen (*iter)) - continue; - - if ( !strcmp (*iter, "MSCHAPV2") - || !strcmp (*iter, "MD5") - || !strcmp (*iter, "GTC")) { - if (!eap_simple_reader (*iter, ifcfg, keys, s_8021x, TRUE, error)) - goto done; - } else if (!strcmp (*iter, "TLS")) { - if (!eap_tls_reader (*iter, ifcfg, keys, s_8021x, TRUE, error)) - goto done; - } else { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Unknown IEEE_8021X_INNER_AUTH_METHOD '%s'.", - *iter); - goto done; - } - - lower = g_ascii_strdown (*iter, -1); - g_object_set (s_8021x, NM_SETTING_802_1X_PHASE2_AUTH, lower, NULL); - g_free (lower); - break; - } - - if (!nm_setting_802_1x_get_phase2_auth (s_8021x)) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "No valid IEEE_8021X_INNER_AUTH_METHODS found."); - goto done; - } - - success = TRUE; - -done: - if (list) - g_strfreev (list); - g_free (inner_auth); - g_free (peapver); - g_free (real_cert_path); - g_free (ca_cert); - g_free (anon_ident); - return success; -} - -static gboolean -eap_ttls_reader (const char *eap_method, - shvarFile *ifcfg, - shvarFile *keys, - NMSetting8021x *s_8021x, - gboolean phase2, - GError **error) -{ - gboolean success = FALSE; - char *anon_ident = NULL; - char *ca_cert = NULL; - char *real_cert_path = NULL; - char *inner_auth = NULL; - char *tmp; - char **list = NULL, **iter; - - ca_cert = svGetValue (ifcfg, "IEEE_8021X_CA_CERT", FALSE); - if (ca_cert) { - real_cert_path = get_full_file_path (ifcfg->fileName, ca_cert); - if (!nm_setting_802_1x_set_ca_cert (s_8021x, - real_cert_path, - NM_SETTING_802_1X_CK_SCHEME_PATH, - NULL, - error)) - goto done; - } else { - PARSE_WARNING ("missing IEEE_8021X_CA_CERT for EAP method '%s'; this is insecure!", - eap_method); - } - - anon_ident = svGetValue (ifcfg, "IEEE_8021X_ANON_IDENTITY", FALSE); - if (anon_ident && strlen (anon_ident)) - g_object_set (s_8021x, NM_SETTING_802_1X_ANONYMOUS_IDENTITY, anon_ident, NULL); - - tmp = svGetValue (ifcfg, "IEEE_8021X_INNER_AUTH_METHODS", FALSE); - if (!tmp) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Missing IEEE_8021X_INNER_AUTH_METHODS."); - goto done; - } - - inner_auth = g_ascii_strdown (tmp, -1); - g_free (tmp); - - /* Handle options for the inner auth method */ - list = g_strsplit (inner_auth, " ", 0); - for (iter = list; iter && *iter; iter++) { - if (!strlen (*iter)) - continue; - - if ( !strcmp (*iter, "mschapv2") - || !strcmp (*iter, "mschap") - || !strcmp (*iter, "pap") - || !strcmp (*iter, "chap")) { - if (!eap_simple_reader (*iter, ifcfg, keys, s_8021x, TRUE, error)) - goto done; - g_object_set (s_8021x, NM_SETTING_802_1X_PHASE2_AUTH, *iter, NULL); - } else if (!strcmp (*iter, "eap-tls")) { - if (!eap_tls_reader (*iter, ifcfg, keys, s_8021x, TRUE, error)) - goto done; - g_object_set (s_8021x, NM_SETTING_802_1X_PHASE2_AUTHEAP, "tls", NULL); - } else if ( !strcmp (*iter, "eap-mschapv2") - || !strcmp (*iter, "eap-md5") - || !strcmp (*iter, "eap-gtc")) { - if (!eap_simple_reader (*iter, ifcfg, keys, s_8021x, TRUE, error)) - goto done; - g_object_set (s_8021x, NM_SETTING_802_1X_PHASE2_AUTHEAP, (*iter + NM_STRLEN ("eap-")), NULL); - } else { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Unknown IEEE_8021X_INNER_AUTH_METHOD '%s'.", - *iter); - goto done; - } - break; - } - - success = TRUE; - -done: - if (list) - g_strfreev (list); - g_free (inner_auth); - g_free (real_cert_path); - g_free (ca_cert); - g_free (anon_ident); - return success; -} - -static gboolean -eap_fast_reader (const char *eap_method, - shvarFile *ifcfg, - shvarFile *keys, - NMSetting8021x *s_8021x, - gboolean phase2, - GError **error) -{ - char *anon_ident = NULL; - char *pac_file = NULL; - char *real_pac_path = NULL; - char *inner_auth = NULL; - char *fast_provisioning = NULL; - char *lower; - char **list = NULL, **iter; - const char* pac_prov_str; - gboolean allow_unauth = FALSE, allow_auth = FALSE; - gboolean success = FALSE; - - pac_file = svGetValue (ifcfg, "IEEE_8021X_PAC_FILE", FALSE); - if (pac_file) { - real_pac_path = get_full_file_path (ifcfg->fileName, pac_file); - g_object_set (s_8021x, NM_SETTING_802_1X_PAC_FILE, real_pac_path, NULL); - } - - fast_provisioning = svGetValue (ifcfg, "IEEE_8021X_FAST_PROVISIONING", FALSE); - if (fast_provisioning) { - list = g_strsplit_set (fast_provisioning, " \t", 0); - for (iter = list; iter && *iter; iter++) { - if (**iter == '\0') - continue; - if (strcmp (*iter, "allow-unauth") == 0) - allow_unauth = TRUE; - else if (strcmp (*iter, "allow-auth") == 0) - allow_auth = TRUE; - else { - PARSE_WARNING ("invalid IEEE_8021X_FAST_PROVISIONING '%s' " - "(space-separated list of these values [allow-auth, allow-unauth] expected)", - *iter); - } - } - g_strfreev (list); - list = NULL; - } - pac_prov_str = allow_unauth ? (allow_auth ? "3" : "1") : (allow_auth ? "2" : "0"); - g_object_set (s_8021x, NM_SETTING_802_1X_PHASE1_FAST_PROVISIONING, pac_prov_str, NULL); - - if (!pac_file && !(allow_unauth || allow_auth)) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "IEEE_8021X_PAC_FILE not provided and EAP-FAST automatic PAC provisioning disabled."); - goto done; - } - - anon_ident = svGetValue (ifcfg, "IEEE_8021X_ANON_IDENTITY", FALSE); - if (anon_ident && strlen (anon_ident)) - g_object_set (s_8021x, NM_SETTING_802_1X_ANONYMOUS_IDENTITY, anon_ident, NULL); - - inner_auth = svGetValue (ifcfg, "IEEE_8021X_INNER_AUTH_METHODS", FALSE); - if (!inner_auth) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Missing IEEE_8021X_INNER_AUTH_METHODS."); - goto done; - } - - /* Handle options for the inner auth method */ - list = g_strsplit (inner_auth, " ", 0); - for (iter = list; iter && *iter; iter++) { - if (!strlen (*iter)) - continue; - - if ( !strcmp (*iter, "MSCHAPV2") - || !strcmp (*iter, "GTC")) { - if (!eap_simple_reader (*iter, ifcfg, keys, s_8021x, TRUE, error)) - goto done; - } else { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Unknown IEEE_8021X_INNER_AUTH_METHOD '%s'.", - *iter); - goto done; - } - - lower = g_ascii_strdown (*iter, -1); - g_object_set (s_8021x, NM_SETTING_802_1X_PHASE2_AUTH, lower, NULL); - g_free (lower); - break; - } - - if (!nm_setting_802_1x_get_phase2_auth (s_8021x)) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "No valid IEEE_8021X_INNER_AUTH_METHODS found."); - goto done; - } - - success = TRUE; - -done: - g_strfreev (list); - g_free (inner_auth); - g_free (fast_provisioning); - g_free (real_pac_path); - g_free (pac_file); - g_free (anon_ident); - return success; -} - -typedef struct { - const char *method; - gboolean (*reader)(const char *eap_method, - shvarFile *ifcfg, - shvarFile *keys, - NMSetting8021x *s_8021x, - gboolean phase2, - GError **error); - gboolean wifi_phase2_only; -} EAPReader; - -static EAPReader eap_readers[] = { - { "md5", eap_simple_reader, TRUE }, - { "pap", eap_simple_reader, TRUE }, - { "chap", eap_simple_reader, TRUE }, - { "mschap", eap_simple_reader, TRUE }, - { "mschapv2", eap_simple_reader, TRUE }, - { "leap", eap_simple_reader, FALSE }, - { "pwd", eap_simple_reader, FALSE }, - { "tls", eap_tls_reader, FALSE }, - { "peap", eap_peap_reader, FALSE }, - { "ttls", eap_ttls_reader, FALSE }, - { "fast", eap_fast_reader, FALSE }, - { NULL, NULL } -}; - -static void -read_8021x_list_value (shvarFile *ifcfg, - const char *ifcfg_var_name, - NMSetting8021x *setting, - const char *prop_name) -{ - char *value; - char **strv; - - g_return_if_fail (ifcfg != NULL); - g_return_if_fail (ifcfg_var_name != NULL); - g_return_if_fail (prop_name != NULL); - - value = svGetValue (ifcfg, ifcfg_var_name, FALSE); - if (!value) - return; - - strv = g_strsplit_set (value, " \t", 0); - if (strv && strv[0]) - g_object_set (setting, prop_name, strv, NULL); - g_strfreev (strv); - g_free (value); -} - -static NMSetting8021x * -fill_8021x (shvarFile *ifcfg, - const char *file, - const char *key_mgmt, - gboolean wifi, - GError **error) -{ - NMSetting8021x *s_8021x; - shvarFile *keys = NULL; - char *value; - char **list = NULL, **iter; - - value = svGetValue (ifcfg, "IEEE_8021X_EAP_METHODS", FALSE); - if (!value) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Missing IEEE_8021X_EAP_METHODS for key management '%s'", - key_mgmt); - return NULL; - } - - list = g_strsplit (value, " ", 0); - g_free (value); - - s_8021x = (NMSetting8021x *) nm_setting_802_1x_new (); - - /* Read in the lookaside keys file, if present */ - keys = utils_get_keys_ifcfg (file, FALSE); - - /* Validate and handle each EAP method */ - for (iter = list; iter && *iter; iter++) { - EAPReader *eap = &eap_readers[0]; - gboolean found = FALSE; - char *lower = NULL; - - lower = g_ascii_strdown (*iter, -1); - while (eap->method) { - if (strcmp (eap->method, lower)) - goto next; - - /* Some EAP methods don't provide keying material, thus they - * cannot be used with WiFi unless they are an inner method - * used with TTLS or PEAP or whatever. - */ - if (wifi && eap->wifi_phase2_only) { - PARSE_WARNING ("ignored invalid IEEE_8021X_EAP_METHOD '%s'; not allowed for wifi.", - lower); - goto next; - } - - /* Parse EAP method specific options */ - if (!(*eap->reader)(lower, ifcfg, keys, s_8021x, FALSE, error)) { - g_free (lower); - goto error; - } - nm_setting_802_1x_add_eap_method (s_8021x, lower); - found = TRUE; - break; - - next: - eap++; - } - - if (!found) - PARSE_WARNING ("ignored unknown IEEE_8021X_EAP_METHOD '%s'.", lower); - g_free (lower); - } - - if (nm_setting_802_1x_get_num_eap_methods (s_8021x) == 0) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "No valid EAP methods found in IEEE_8021X_EAP_METHODS."); - goto error; - } - - value = svGetValue (ifcfg, "IEEE_8021X_SUBJECT_MATCH", FALSE); - g_object_set (s_8021x, NM_SETTING_802_1X_SUBJECT_MATCH, value, NULL); - g_free (value); - - value = svGetValue (ifcfg, "IEEE_8021X_PHASE2_SUBJECT_MATCH", FALSE); - g_object_set (s_8021x, NM_SETTING_802_1X_PHASE2_SUBJECT_MATCH, value, NULL); - g_free (value); - - read_8021x_list_value (ifcfg, "IEEE_8021X_ALTSUBJECT_MATCHES", - s_8021x, NM_SETTING_802_1X_ALTSUBJECT_MATCHES); - read_8021x_list_value (ifcfg, "IEEE_8021X_PHASE2_ALTSUBJECT_MATCHES", - s_8021x, NM_SETTING_802_1X_PHASE2_ALTSUBJECT_MATCHES); - - value = svGetValue (ifcfg, "IEEE_8021X_DOMAIN_SUFFIX_MATCH", FALSE); - g_object_set (s_8021x, NM_SETTING_802_1X_DOMAIN_SUFFIX_MATCH, value, NULL); - g_free (value); - value = svGetValue (ifcfg, "IEEE_8021X_PHASE2_DOMAIN_SUFFIX_MATCH", FALSE); - g_object_set (s_8021x, NM_SETTING_802_1X_PHASE2_DOMAIN_SUFFIX_MATCH, value, NULL); - g_free (value); - - if (list) - g_strfreev (list); - if (keys) - svCloseFile (keys); - return s_8021x; - -error: - if (list) - g_strfreev (list); - if (keys) - svCloseFile (keys); - g_object_unref (s_8021x); - return NULL; -} - -static NMSetting * -make_wpa_setting (shvarFile *ifcfg, - const char *file, - GBytes *ssid, - gboolean adhoc, - NMSetting8021x **s_8021x, - GError **error) -{ - NMSettingWirelessSecurity *wsec; - char *value, *psk, *lower; - gboolean wpa_psk = FALSE, wpa_eap = FALSE, ieee8021x = FALSE; - - wsec = NM_SETTING_WIRELESS_SECURITY (nm_setting_wireless_security_new ()); - - value = svGetValue (ifcfg, "KEY_MGMT", FALSE); - wpa_psk = !g_strcmp0 (value, "WPA-PSK"); - wpa_eap = !g_strcmp0 (value, "WPA-EAP"); - ieee8021x = !g_strcmp0 (value, "IEEE8021X"); - if (!wpa_psk && !wpa_eap && !ieee8021x) - goto error; /* Not WPA or Dynamic WEP */ - - /* Pairwise and Group ciphers (only relevant for WPA/RSN) */ - if (wpa_psk || wpa_eap) { - fill_wpa_ciphers (ifcfg, wsec, FALSE, adhoc); - fill_wpa_ciphers (ifcfg, wsec, TRUE, adhoc); - } - - /* WPA and/or RSN */ - if (adhoc) { - /* Ad-Hoc mode only supports WPA proto for now */ - nm_setting_wireless_security_add_proto (wsec, "wpa"); - } else { - char *allow_wpa, *allow_rsn; - - allow_wpa = svGetValue (ifcfg, "WPA_ALLOW_WPA", FALSE); - allow_rsn = svGetValue (ifcfg, "WPA_ALLOW_WPA2", FALSE); - - if (allow_wpa && svGetValueBoolean (ifcfg, "WPA_ALLOW_WPA", TRUE)) - nm_setting_wireless_security_add_proto (wsec, "wpa"); - if (allow_rsn && svGetValueBoolean (ifcfg, "WPA_ALLOW_WPA2", TRUE)) - nm_setting_wireless_security_add_proto (wsec, "rsn"); - - g_free (allow_wpa); - g_free (allow_rsn); - } - - if (wpa_psk) { - NMSettingSecretFlags psk_flags; - - psk_flags = read_secret_flags (ifcfg, "WPA_PSK_FLAGS"); - g_object_set (wsec, NM_SETTING_WIRELESS_SECURITY_PSK_FLAGS, psk_flags, NULL); - - /* Read PSK if it's system-owned */ - if (psk_flags == NM_SETTING_SECRET_FLAG_NONE) { - psk = parse_wpa_psk (ifcfg, file, ssid, error); - if (psk) { - g_object_set (wsec, NM_SETTING_WIRELESS_SECURITY_PSK, psk, NULL); - g_free (psk); - } else if (error) - goto error; - } - - if (adhoc) - g_object_set (wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "wpa-none", NULL); - else - g_object_set (wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "wpa-psk", NULL); - } else if (wpa_eap || ieee8021x) { - /* Adhoc mode is mutually exclusive with any 802.1x-based authentication */ - if (adhoc) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Ad-Hoc mode cannot be used with KEY_MGMT type '%s'", value); - goto error; - } - - *s_8021x = fill_8021x (ifcfg, file, value, TRUE, error); - if (!*s_8021x) - goto error; - - lower = g_ascii_strdown (value, -1); - g_object_set (wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, lower, NULL); - g_free (lower); - } else { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Unknown wireless KEY_MGMT type '%s'", value); - goto error; - } - - g_free (value); - - value = svGetValue (ifcfg, "SECURITYMODE", FALSE); - if (NM_IN_STRSET (value, NULL, "open")) - g_object_set (wsec, NM_SETTING_WIRELESS_SECURITY_AUTH_ALG, value, NULL); - - g_free (value); - return (NMSetting *) wsec; - -error: - g_free (value); - if (wsec) - g_object_unref (wsec); - return NULL; -} - -static NMSetting * -make_leap_setting (shvarFile *ifcfg, - const char *file, - GError **error) -{ - NMSettingWirelessSecurity *wsec; - shvarFile *keys_ifcfg; - char *value; - NMSettingSecretFlags flags; - - wsec = NM_SETTING_WIRELESS_SECURITY (nm_setting_wireless_security_new ()); - - value = svGetValue (ifcfg, "KEY_MGMT", FALSE); - if (!value || strcmp (value, "IEEE8021X")) - goto error; /* Not LEAP */ - - g_free (value); - value = svGetValue (ifcfg, "SECURITYMODE", FALSE); - if (!value || strcasecmp (value, "leap")) - goto error; /* Not LEAP */ - - g_free (value); - - flags = read_secret_flags (ifcfg, "IEEE_8021X_PASSWORD_FLAGS"); - g_object_set (wsec, NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD_FLAGS, flags, NULL); - - /* Read LEAP password if it's system-owned */ - if (flags == NM_SETTING_SECRET_FLAG_NONE) { - value = svGetValue (ifcfg, "IEEE_8021X_PASSWORD", FALSE); - if (!value) { - /* Try to get keys from the "shadow" key file */ - keys_ifcfg = utils_get_keys_ifcfg (file, FALSE); - if (keys_ifcfg) { - value = svGetValue (keys_ifcfg, "IEEE_8021X_PASSWORD", FALSE); - svCloseFile (keys_ifcfg); - } - } - if (value && strlen (value)) - g_object_set (wsec, NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD, value, NULL); - g_free (value); - } - - value = svGetValue (ifcfg, "IEEE_8021X_IDENTITY", FALSE); - if (!value || !strlen (value)) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Missing LEAP identity"); - goto error; - } - g_object_set (wsec, NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME, value, NULL); - g_free (value); - - g_object_set (wsec, - NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "ieee8021x", - NM_SETTING_WIRELESS_SECURITY_AUTH_ALG, "leap", - NULL); - - return (NMSetting *) wsec; - -error: - g_free (value); - if (wsec) - g_object_unref (wsec); - return NULL; -} - -static NMSetting * -make_wireless_security_setting (shvarFile *ifcfg, - const char *file, - GBytes *ssid, - gboolean adhoc, - NMSetting8021x **s_8021x, - GError **error) -{ - NMSetting *wsec; - - g_return_val_if_fail (error && !*error, NULL); - - if (!adhoc) { - wsec = make_leap_setting (ifcfg, file, error); - if (wsec) - return wsec; - else if (*error) - return NULL; - } - - wsec = make_wpa_setting (ifcfg, file, ssid, adhoc, s_8021x, error); - if (wsec) - return wsec; - else if (*error) - return NULL; - - wsec = make_wep_setting (ifcfg, file, error); - if (wsec) - return wsec; - else if (*error) - return NULL; - - return NULL; /* unencrypted */ -} - -static char ** -transform_hwaddr_blacklist (const char *blacklist) -{ - char **strv, **iter; - int shift = 0; - - strv = _nm_utils_strsplit_set (blacklist, " \t", 0); - for (iter = strv; iter && *iter; iter++) { - if (shift) { - *(iter - shift) = *iter; - *iter = NULL; - } - if (!nm_utils_hwaddr_valid (*(iter - shift), ETH_ALEN)) { - PARSE_WARNING ("invalid MAC in HWADDR_BLACKLIST '%s'", *(iter - shift)); - g_free (*(iter - shift)); - *(iter - shift) = NULL; - shift++; - } - } - return strv; -} - -static NMSetting * -make_wireless_setting (shvarFile *ifcfg, - GError **error) -{ - NMSettingWireless *s_wireless; - char *value = NULL; - gint64 chan = 0; - NMSettingMacRandomization mac_randomization = NM_SETTING_MAC_RANDOMIZATION_NEVER; - NMSettingWirelessPowersave powersave = NM_SETTING_WIRELESS_POWERSAVE_DEFAULT; - - s_wireless = NM_SETTING_WIRELESS (nm_setting_wireless_new ()); - - value = svGetValue (ifcfg, "HWADDR", FALSE); - if (value) { - value = g_strstrip (value); - g_object_set (s_wireless, NM_SETTING_WIRELESS_MAC_ADDRESS, value, NULL); - g_free (value); - } - - value = svGetValue (ifcfg, "MACADDR", FALSE); - if (value) { - value = g_strstrip (value); - g_object_set (s_wireless, NM_SETTING_WIRELESS_CLONED_MAC_ADDRESS, value, NULL); - g_free (value); - } - - value = svGetValue (ifcfg, "GENERATE_MAC_ADDRESS_MASK", FALSE); - g_object_set (s_wireless, NM_SETTING_WIRELESS_GENERATE_MAC_ADDRESS_MASK, value, NULL); - g_free (value); - - value = svGetValue (ifcfg, "HWADDR_BLACKLIST", FALSE); - if (value) { - char **strv; - - strv = transform_hwaddr_blacklist (value); - g_object_set (s_wireless, NM_SETTING_WIRELESS_MAC_ADDRESS_BLACKLIST, strv, NULL); - g_strfreev (strv); - g_free (value); - } - - value = svGetValue (ifcfg, "ESSID", TRUE); - if (value) { - GBytes *bytes = NULL; - gsize ssid_len = 0; - gsize value_len = strlen (value); - - if ( (value_len >= 2) - && (value[0] == '"') - && (value[value_len - 1] == '"')) { - /* Strip the quotes and unescape */ - char *p = value + 1; - - value[value_len - 1] = '\0'; - svUnescape (p); - bytes = g_bytes_new (p, strlen (p)); - } else if ((value_len > 2) && (strncmp (value, "0x", 2) == 0)) { - /* Hex representation */ - if (value_len % 2) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Invalid SSID '%s' size (looks like hex but length not multiple of 2)", - value); - g_free (value); - goto error; - } - - bytes = nm_utils_hexstr2bin (value); - if (!bytes) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Invalid SSID '%s' (looks like hex SSID but isn't)", - value); - g_free (value); - goto error; - } - } else - bytes = g_bytes_new (value, value_len); - - ssid_len = g_bytes_get_size (bytes); - if (ssid_len > 32 || ssid_len == 0) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Invalid SSID '%s' (size %zu not between 1 and 32 inclusive)", - value, ssid_len); - g_bytes_unref (bytes); - g_free (value); - goto error; - } - - g_object_set (s_wireless, NM_SETTING_WIRELESS_SSID, bytes, NULL); - g_bytes_unref (bytes); - g_free (value); - } - - value = svGetValue (ifcfg, "MODE", FALSE); - if (value) { - char *lcase; - const char *mode = NULL; - - lcase = g_ascii_strdown (value, -1); - g_free (value); - - if (!strcmp (lcase, "ad-hoc")) { - mode = "adhoc"; - } else if (!strcmp (lcase, "ap")) { - mode = "ap"; - } else if (!strcmp (lcase, "managed") || !strcmp (lcase, "auto")) { - mode = "infrastructure"; - } else { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Invalid mode '%s' (not 'Ad-Hoc', 'Ap', 'Managed', or 'Auto')", - lcase); - g_free (lcase); - goto error; - } - g_free (lcase); - - g_object_set (s_wireless, NM_SETTING_WIRELESS_MODE, mode, NULL); - } - - value = svGetValue (ifcfg, "BSSID", FALSE); - if (value) { - value = g_strstrip (value); - g_object_set (s_wireless, NM_SETTING_WIRELESS_BSSID, value, NULL); - g_free (value); - } - - value = svGetValue (ifcfg, "CHANNEL", FALSE); - if (value) { - errno = 0; - chan = _nm_utils_ascii_str_to_int64 (value, 10, 1, 196, 0); - if (errno || (chan == 0)) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Invalid wireless channel '%s'", value); - g_free (value); - goto error; - } - g_object_set (s_wireless, NM_SETTING_WIRELESS_CHANNEL, (guint32) chan, NULL); - g_free (value); - } - - value = svGetValue (ifcfg, "BAND", FALSE); - if (value) { - if (!strcmp (value, "a")) { - if (chan && chan <= 14) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Band '%s' invalid for channel %u", value, (guint32) chan); - g_free (value); - goto error; - } - } else if (!strcmp (value, "bg")) { - if (chan && chan > 14) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Band '%s' invalid for channel %u", value, (guint32) chan); - g_free (value); - goto error; - } - } else { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Invalid wireless band '%s'", value); - g_free (value); - goto error; - } - g_object_set (s_wireless, NM_SETTING_WIRELESS_BAND, value, NULL); - g_free (value); - } else if (chan > 0) { - if (chan > 14) - g_object_set (s_wireless, NM_SETTING_WIRELESS_BAND, "a", NULL); - else - g_object_set (s_wireless, NM_SETTING_WIRELESS_BAND, "bg", NULL); - } - - value = svGetValue (ifcfg, "MTU", FALSE); - if (value) { - int mtu; - - mtu = _nm_utils_ascii_str_to_int64 (value, 10, 0, 50000, -1); - if (mtu == -1) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Invalid wireless MTU '%s'", value); - g_free (value); - goto error; - } - g_object_set (s_wireless, NM_SETTING_WIRELESS_MTU, (guint) mtu, NULL); - g_free (value); - } - - g_object_set (s_wireless, - NM_SETTING_WIRELESS_HIDDEN, - svGetValueBoolean (ifcfg, "SSID_HIDDEN", FALSE), - NULL); - - value = svGetValueFull (ifcfg, "POWERSAVE", FALSE); - if (value) { - if (!strcmp (value, "default")) - powersave = NM_SETTING_WIRELESS_POWERSAVE_DEFAULT; - else if (!strcmp (value, "ignore")) - powersave = NM_SETTING_WIRELESS_POWERSAVE_IGNORE; - else if (!strcmp (value, "disable") || !strcmp (value, "no")) - powersave = NM_SETTING_WIRELESS_POWERSAVE_DISABLE; - else if (!strcmp (value, "enable") || !strcmp (value, "yes")) - powersave = NM_SETTING_WIRELESS_POWERSAVE_ENABLE; - else { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Invalid POWERSAVE value '%s'", value); - g_free (value); - goto error; - } - g_free (value); - } - - g_object_set (s_wireless, - NM_SETTING_WIRELESS_POWERSAVE, - powersave, - NULL); - - value = svGetValueFull (ifcfg, "MAC_ADDRESS_RANDOMIZATION", FALSE); - if (value) { - if (strcmp (value, "default") == 0) - mac_randomization = NM_SETTING_MAC_RANDOMIZATION_DEFAULT; - else if (strcmp (value, "never") == 0) - mac_randomization = NM_SETTING_MAC_RANDOMIZATION_NEVER; - else if (strcmp (value, "always") == 0) - mac_randomization = NM_SETTING_MAC_RANDOMIZATION_ALWAYS; - else { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Invalid MAC_ADDRESS_RANDOMIZATION value '%s'", value); - g_free (value); - goto error; - } - g_free (value); - } else - mac_randomization = NM_SETTING_MAC_RANDOMIZATION_NEVER; - - g_object_set (s_wireless, - NM_SETTING_WIRELESS_MAC_ADDRESS_RANDOMIZATION, - mac_randomization, - NULL); - - return NM_SETTING (s_wireless); - -error: - if (s_wireless) - g_object_unref (s_wireless); - return NULL; -} - -static NMConnection * -wireless_connection_from_ifcfg (const char *file, - shvarFile *ifcfg, - GError **error) -{ - NMConnection *connection = NULL; - NMSetting *con_setting = NULL; - NMSetting *wireless_setting = NULL; - NMSetting8021x *s_8021x = NULL; - GBytes *ssid; - NMSetting *security_setting = NULL; - char *printable_ssid = NULL; - const char *mode; - gboolean adhoc = FALSE; - GError *local = NULL; - - g_return_val_if_fail (file != NULL, NULL); - g_return_val_if_fail (ifcfg != NULL, NULL); - g_return_val_if_fail (!error || !*error, NULL); - - connection = nm_simple_connection_new (); - - /* Wireless */ - wireless_setting = make_wireless_setting (ifcfg, error); - if (!wireless_setting) { - g_object_unref (connection); - return NULL; - } - nm_connection_add_setting (connection, wireless_setting); - - ssid = nm_setting_wireless_get_ssid (NM_SETTING_WIRELESS (wireless_setting)); - if (ssid) { - printable_ssid = nm_utils_ssid_to_utf8 (g_bytes_get_data (ssid, NULL), - g_bytes_get_size (ssid)); - } else - printable_ssid = g_strdup_printf ("unmanaged"); - - mode = nm_setting_wireless_get_mode (NM_SETTING_WIRELESS (wireless_setting)); - if (mode && !strcmp (mode, "adhoc")) - adhoc = TRUE; - - /* Wireless security */ - security_setting = make_wireless_security_setting (ifcfg, file, ssid, adhoc, &s_8021x, &local); - if (local) { - g_free (printable_ssid); - g_object_unref (connection); - g_propagate_error (error, local); - return NULL; - } - if (security_setting) { - nm_connection_add_setting (connection, security_setting); - if (s_8021x) - nm_connection_add_setting (connection, NM_SETTING (s_8021x)); - } - - /* Connection */ - con_setting = make_connection_setting (file, ifcfg, - NM_SETTING_WIRELESS_SETTING_NAME, - printable_ssid, NULL); - g_free (printable_ssid); - if (!con_setting) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Failed to create connection setting."); - g_object_unref (connection); - return NULL; - } - nm_connection_add_setting (connection, con_setting); - - return connection; -} - -static void -parse_ethtool_option (const char *value, NMSettingWiredWakeOnLan *out_flags, char **out_password) -{ - gs_strfreev char **words = NULL; - const char **iter = NULL, *flag; - - if (!value || !value[0]) - return; - - words = g_strsplit_set (value, "\t ", 0); - iter = (const char **) words; - - while (iter[0]) { - gboolean is_wol; - - if (g_str_equal (iter[0], "wol")) - is_wol = TRUE; - else if (g_str_equal (iter[0], "sopass")) - is_wol = FALSE; - else { - /* Silently skip unknown options */ - iter++; - continue; - } - - iter++; - - /* g_strsplit_set() returns empty tokens, meaning that we must skip over repeated - * space characters like to parse "wol d". */ - while (iter[0] && !*iter[0]) - iter++; - - if (is_wol) { - NMSettingWiredWakeOnLan wol_flags = NM_SETTING_WIRED_WAKE_ON_LAN_NONE; - - if (!iter[0]) { - PARSE_WARNING ("Wake-on-LAN options missing"); - break; - } - - for (flag = iter[0]; *flag; flag++) { - switch (*flag) { - case 'p': - wol_flags |= NM_SETTING_WIRED_WAKE_ON_LAN_PHY; - break; - case 'u': - wol_flags |= NM_SETTING_WIRED_WAKE_ON_LAN_UNICAST; - break; - case 'm': - wol_flags |= NM_SETTING_WIRED_WAKE_ON_LAN_MULTICAST; - break; - case 'b': - wol_flags |= NM_SETTING_WIRED_WAKE_ON_LAN_BROADCAST; - break; - case 'a': - wol_flags |= NM_SETTING_WIRED_WAKE_ON_LAN_ARP; - break; - case 'g': - wol_flags |= NM_SETTING_WIRED_WAKE_ON_LAN_MAGIC; - break; - case 's': - break; - case 'd': - wol_flags = NM_SETTING_WIRED_WAKE_ON_LAN_NONE; - break; - default: - PARSE_WARNING ("unrecognized Wake-on-LAN option '%c'", *flag); - } - } - - *out_flags = wol_flags; - } else { - if (!iter[0]) { - PARSE_WARNING ("Wake-on-LAN password missing"); - break; - } - - g_clear_pointer (out_password, g_free); - if (nm_utils_hwaddr_valid (iter[0], ETH_ALEN)) - *out_password = g_strdup (iter[0]); - else - PARSE_WARNING ("Wake-on-LAN password '%s' is invalid", iter[0]); - } - iter++; - } -} - -static void -parse_ethtool_options (shvarFile *ifcfg, NMSettingWired *s_wired, const char *value) -{ - NMSettingWiredWakeOnLan wol_flags = NM_SETTING_WIRED_WAKE_ON_LAN_DEFAULT; - gs_free char *wol_password = NULL; - gboolean ignore_wol_password = FALSE; - - if (value) { - gs_strfreev char **opts = NULL; - const char **iter; - - wol_flags = NM_SETTING_WIRED_WAKE_ON_LAN_IGNORE; - - opts = g_strsplit_set (value, ";", 0); - for (iter = (const char **) opts; iter[0]; iter++) { - /* in case of repeated wol_passwords, parse_ethtool_option() - * will do the right thing and clear wol_password before resetting. */ - parse_ethtool_option (iter[0], &wol_flags, &wol_password); - } - } - - if ( wol_password - && !NM_FLAGS_HAS (wol_flags, NM_SETTING_WIRED_WAKE_ON_LAN_MAGIC)) { - PARSE_WARNING ("Wake-on-LAN password not expected"); - ignore_wol_password = TRUE; - } - g_object_set (s_wired, - NM_SETTING_WIRED_WAKE_ON_LAN, wol_flags, - NM_SETTING_WIRED_WAKE_ON_LAN_PASSWORD, ignore_wol_password ? NULL : wol_password, - NULL); -} - -static NMSetting * -make_wired_setting (shvarFile *ifcfg, - const char *file, - NMSetting8021x **s_8021x, - GError **error) -{ - NMSettingWired *s_wired; - char *value = NULL; - char *nettype; - - s_wired = NM_SETTING_WIRED (nm_setting_wired_new ()); - - value = svGetValue (ifcfg, "MTU", FALSE); - if (value) { - int mtu; - - mtu = _nm_utils_ascii_str_to_int64 (value, 0, 0, 65535, -1); - if (mtu >= 0) - g_object_set (s_wired, NM_SETTING_WIRED_MTU, (guint) mtu, NULL); - else - PARSE_WARNING ("invalid MTU '%s'", value); - g_free (value); - } - - value = svGetValue (ifcfg, "HWADDR", FALSE); - if (value) { - value = g_strstrip (value); - g_object_set (s_wired, NM_SETTING_WIRED_MAC_ADDRESS, value, NULL); - g_free (value); - } - - value = svGetValue (ifcfg, "SUBCHANNELS", FALSE); - if (value) { - const char *p = value; - gboolean success = TRUE; - char **chans = NULL; - - /* basic sanity checks */ - while (*p) { - if (!g_ascii_isxdigit (*p) && (*p != ',') && (*p != '.')) { - PARSE_WARNING ("invalid SUBCHANNELS '%s'", value); - success = FALSE; - break; - } - p++; - } - - if (success) { - guint32 num_chans; - - chans = g_strsplit_set (value, ",", 0); - num_chans = g_strv_length (chans); - if (num_chans < 2 || num_chans > 3) { - PARSE_WARNING ("invalid SUBCHANNELS '%s' (%d channels, 2 or 3 expected)", - value, g_strv_length (chans)); - } else - g_object_set (s_wired, NM_SETTING_WIRED_S390_SUBCHANNELS, chans, NULL); - g_strfreev (chans); - } - g_free (value); - } - - value = svGetValue (ifcfg, "PORTNAME", FALSE); - if (value && strlen (value)) { - nm_setting_wired_add_s390_option (s_wired, "portname", value); - } - g_free (value); - - value = svGetValue (ifcfg, "CTCPROT", FALSE); - if (value && strlen (value)) - nm_setting_wired_add_s390_option (s_wired, "ctcprot", value); - g_free (value); - - nettype = svGetValue (ifcfg, "NETTYPE", FALSE); - if (nettype && strlen (nettype)) { - if (!strcmp (nettype, "qeth") || !strcmp (nettype, "lcs") || !strcmp (nettype, "ctc")) - g_object_set (s_wired, NM_SETTING_WIRED_S390_NETTYPE, nettype, NULL); - else - PARSE_WARNING ("unknown s390 NETTYPE '%s'", nettype); - } - g_free (nettype); - - value = svGetValue (ifcfg, "OPTIONS", FALSE); - if (value && strlen (value)) { - char **options, **iter; - - iter = options = g_strsplit_set (value, " ", 0); - while (iter && *iter) { - char *equals = strchr (*iter, '='); - gboolean valid = FALSE; - - if (equals) { - *equals = '\0'; - valid = nm_setting_wired_add_s390_option (s_wired, *iter, equals + 1); - } - if (!valid) - PARSE_WARNING ("invalid s390 OPTION '%s'", *iter); - iter++; - } - g_strfreev (options); - } - g_free (value); - - value = svGetValue (ifcfg, "MACADDR", FALSE); - if (value) { - value = g_strstrip (value); - g_object_set (s_wired, NM_SETTING_WIRED_CLONED_MAC_ADDRESS, value, NULL); - g_free (value); - } - - value = svGetValue (ifcfg, "GENERATE_MAC_ADDRESS_MASK", FALSE); - g_object_set (s_wired, NM_SETTING_WIRED_GENERATE_MAC_ADDRESS_MASK, value, NULL); - g_free (value); - - value = svGetValue (ifcfg, "HWADDR_BLACKLIST", FALSE); - if (value) { - char **strv; - - strv = transform_hwaddr_blacklist (value); - g_object_set (s_wired, NM_SETTING_WIRED_MAC_ADDRESS_BLACKLIST, strv, NULL); - g_strfreev (strv); - g_free (value); - } - - value = svGetValue (ifcfg, "KEY_MGMT", FALSE); - if (value) { - if (!strcmp (value, "IEEE8021X")) { - *s_8021x = fill_8021x (ifcfg, file, value, FALSE, error); - if (!*s_8021x) - goto error; - } else { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Unknown wired KEY_MGMT type '%s'", value); - goto error; - } - g_free (value); - } - - value = svGetValueFull (ifcfg, "ETHTOOL_OPTS", FALSE); - parse_ethtool_options (ifcfg, s_wired, value); - g_free (value); - - return (NMSetting *) s_wired; - -error: - g_free (value); - g_object_unref (s_wired); - return NULL; -} - -static NMConnection * -wired_connection_from_ifcfg (const char *file, - shvarFile *ifcfg, - GError **error) -{ - NMConnection *connection = NULL; - NMSetting *con_setting = NULL; - NMSetting *wired_setting = NULL; - NMSetting8021x *s_8021x = NULL; - - g_return_val_if_fail (file != NULL, NULL); - g_return_val_if_fail (ifcfg != NULL, NULL); - - connection = nm_simple_connection_new (); - - con_setting = make_connection_setting (file, ifcfg, NM_SETTING_WIRED_SETTING_NAME, NULL, NULL); - if (!con_setting) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Failed to create connection setting."); - g_object_unref (connection); - return NULL; - } - check_if_slave (ifcfg, (NMSettingConnection *) con_setting); - nm_connection_add_setting (connection, con_setting); - - wired_setting = make_wired_setting (ifcfg, file, &s_8021x, error); - if (!wired_setting) { - g_object_unref (connection); - return NULL; - } - nm_connection_add_setting (connection, wired_setting); - - if (s_8021x) - nm_connection_add_setting (connection, NM_SETTING (s_8021x)); - - return connection; -} - -static gboolean -parse_infiniband_p_key (shvarFile *ifcfg, - int *out_p_key, - char **out_parent, - GError **error) -{ - char *device = NULL, *physdev = NULL, *pkey_id = NULL; - char *ifname = NULL; - int id; - gboolean ret = FALSE; - - device = svGetValue (ifcfg, "DEVICE", FALSE); - if (!device) { - PARSE_WARNING ("InfiniBand connection specified PKEY but not DEVICE"); - goto done; - } - - physdev = svGetValue (ifcfg, "PHYSDEV", FALSE); - if (!physdev) { - PARSE_WARNING ("InfiniBand connection specified PKEY but not PHYSDEV"); - goto done; - } - - pkey_id = svGetValue (ifcfg, "PKEY_ID", FALSE); - if (!pkey_id) { - PARSE_WARNING ("InfiniBand connection specified PKEY but not PKEY_ID"); - goto done; - } - - id = _nm_utils_ascii_str_to_int64 (pkey_id, 0, 0, 0xFFFF, -1); - if (id == -1) { - PARSE_WARNING ("invalid InfiniBand PKEY_ID '%s'", pkey_id); - goto done; - } - id = (id | 0x8000); - - ifname = g_strdup_printf ("%s.%04x", physdev, (unsigned) id); - if (strcmp (device, ifname) != 0) { - PARSE_WARNING ("InfiniBand DEVICE (%s) does not match PHYSDEV+PKEY_ID (%s)", - device, ifname); - goto done; - } - - *out_p_key = id; - *out_parent = g_strdup (physdev); - ret = TRUE; - - done: - g_free (device); - g_free (physdev); - g_free (pkey_id); - g_free (ifname); - - if (!ret) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Failed to create InfiniBand setting."); - } - return ret; -} - - -static NMSetting * -make_infiniband_setting (shvarFile *ifcfg, - const char *file, - GError **error) -{ - NMSettingInfiniband *s_infiniband; - char *value = NULL; - - s_infiniband = NM_SETTING_INFINIBAND (nm_setting_infiniband_new ()); - - value = svGetValue (ifcfg, "MTU", FALSE); - if (value) { - int mtu; - - mtu = _nm_utils_ascii_str_to_int64 (value, 0, 0, 65535, -1); - if (mtu >= 0) - g_object_set (s_infiniband, NM_SETTING_INFINIBAND_MTU, (guint) mtu, NULL); - else - PARSE_WARNING ("invalid MTU '%s'", value); - g_free (value); - } - - value = svGetValue (ifcfg, "HWADDR", FALSE); - if (value) { - value = g_strstrip (value); - g_object_set (s_infiniband, NM_SETTING_INFINIBAND_MAC_ADDRESS, value, NULL); - g_free (value); - } - - if (svGetValueBoolean (ifcfg, "CONNECTED_MODE", FALSE)) - g_object_set (s_infiniband, NM_SETTING_INFINIBAND_TRANSPORT_MODE, "connected", NULL); - else - g_object_set (s_infiniband, NM_SETTING_INFINIBAND_TRANSPORT_MODE, "datagram", NULL); - - if (svGetValueBoolean (ifcfg, "PKEY", FALSE)) { - int p_key; - char *parent; - - if (!parse_infiniband_p_key (ifcfg, &p_key, &parent, error)) { - g_object_unref (s_infiniband); - return NULL; - } - - g_object_set (s_infiniband, - NM_SETTING_INFINIBAND_P_KEY, p_key, - NM_SETTING_INFINIBAND_PARENT, parent, - NULL); - } - - return (NMSetting *) s_infiniband; -} - -static NMConnection * -infiniband_connection_from_ifcfg (const char *file, - shvarFile *ifcfg, - GError **error) -{ - NMConnection *connection = NULL; - NMSetting *con_setting = NULL; - NMSetting *infiniband_setting = NULL; - - g_return_val_if_fail (file != NULL, NULL); - g_return_val_if_fail (ifcfg != NULL, NULL); - - connection = nm_simple_connection_new (); - - con_setting = make_connection_setting (file, ifcfg, NM_SETTING_INFINIBAND_SETTING_NAME, NULL, NULL); - if (!con_setting) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Failed to create connection setting."); - g_object_unref (connection); - return NULL; - } - check_if_slave (ifcfg, (NMSettingConnection *) con_setting); - nm_connection_add_setting (connection, con_setting); - - infiniband_setting = make_infiniband_setting (ifcfg, file, error); - if (!infiniband_setting) { - g_object_unref (connection); - return NULL; - } - nm_connection_add_setting (connection, infiniband_setting); - - return connection; -} - -static void -handle_bond_option (NMSettingBond *s_bond, - const char *key, - const char *value) -{ - char *sanitized = NULL, *j; - const char *p = value; - - /* Remove any quotes or +/- from arp_ip_target */ - if (!g_strcmp0 (key, NM_SETTING_BOND_OPTION_ARP_IP_TARGET) && value && value[0]) { - if (*p == '\'' || *p == '"') - p++; - j = sanitized = g_malloc0 (strlen (p) + 1); - while (*p) { - if (*p != '+' && *p != '-' && *p != '\'' && *p != '"') - *j++ = *p; - p++; - } - } - - if (!nm_setting_bond_add_option (s_bond, key, sanitized ? sanitized : value)) - PARSE_WARNING ("invalid bonding option '%s' = %s", - key, sanitized ? sanitized : value); - g_free (sanitized); -} - -static NMSetting * -make_bond_setting (shvarFile *ifcfg, - const char *file, - GError **error) -{ - NMSettingBond *s_bond; - char *value; - - s_bond = NM_SETTING_BOND (nm_setting_bond_new ()); - - value = svGetValue (ifcfg, "DEVICE", FALSE); - if (!value || !strlen (value)) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "mandatory DEVICE keyword missing"); - goto error; - } - g_free (value); - - value = svGetValue (ifcfg, "BONDING_OPTS", FALSE); - if (value) { - char **items, **iter; - - items = g_strsplit_set (value, " ", -1); - for (iter = items; iter && *iter; iter++) { - if (strlen (*iter)) { - char **keys, *key, *val; - - keys = g_strsplit_set (*iter, "=", 2); - if (keys && *keys) { - key = *keys; - val = *(keys + 1); - if (val && strlen(key) && strlen(val)) - handle_bond_option (s_bond, key, val); - } - - g_strfreev (keys); - } - } - g_free (value); - g_strfreev (items); - } - - return (NMSetting *) s_bond; - -error: - g_object_unref (s_bond); - return NULL; -} - -static NMConnection * -bond_connection_from_ifcfg (const char *file, - shvarFile *ifcfg, - GError **error) -{ - NMConnection *connection = NULL; - NMSetting *con_setting = NULL; - NMSetting *bond_setting = NULL; - NMSetting *wired_setting = NULL; - NMSetting8021x *s_8021x = NULL; - - g_return_val_if_fail (file != NULL, NULL); - g_return_val_if_fail (ifcfg != NULL, NULL); - - connection = nm_simple_connection_new (); - - con_setting = make_connection_setting (file, ifcfg, NM_SETTING_BOND_SETTING_NAME, NULL, _("Bond")); - if (!con_setting) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Failed to create connection setting."); - g_object_unref (connection); - return NULL; - } - nm_connection_add_setting (connection, con_setting); - - bond_setting = make_bond_setting (ifcfg, file, error); - if (!bond_setting) { - g_object_unref (connection); - return NULL; - } - nm_connection_add_setting (connection, bond_setting); - - wired_setting = make_wired_setting (ifcfg, file, &s_8021x, error); - if (!wired_setting) { - g_object_unref (connection); - return NULL; - } - nm_connection_add_setting (connection, wired_setting); - - if (s_8021x) - nm_connection_add_setting (connection, NM_SETTING (s_8021x)); - - return connection; -} - -/* Check 'error' for errors. Missing config (NULL return value) is a valid case. */ -static char * -read_team_config (shvarFile *ifcfg, const char *key, GError **error) -{ - gs_free_error GError *local_error = NULL; - char *value; - size_t l; - - /* FIXME: validate the JSON at some point */ - value = svGetValue (ifcfg, key, TRUE); - if (!value) - return NULL; - - /* No reason Team config should be over 20k. The config is read - * verbatim, length-checked, then unescaped. svUnescape() does not - * deal well with extremely long strings. - */ - l = strlen (value); - if (l > 20000) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "%s too long (size %zd)", key, l); - g_free (value); - return NULL; - } - svUnescape (value); - - if (value && value[0] && !_nm_utils_check_valid_json (value, &local_error)) { - PARSE_WARNING ("ignoring invalid team configuration: %s", local_error->message); - g_clear_pointer (&value, g_free); - } - - return value; -} - -static NMSetting * -make_team_setting (shvarFile *ifcfg, - const char *file, - GError **error) -{ - NMSettingTeam *s_team; - char *value; - GError *local_err = NULL; - - s_team = NM_SETTING_TEAM (nm_setting_team_new ()); - - value = svGetValue (ifcfg, "DEVICE", FALSE); - if (!value || !strlen (value)) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "mandatory DEVICE keyword missing"); - goto error; - } - g_free (value); - - value = read_team_config (ifcfg, "TEAM_CONFIG", &local_err); - if (local_err) { - g_propagate_error (error, local_err); - goto error; - } - g_object_set (s_team, NM_SETTING_TEAM_CONFIG, value, NULL); - g_free (value); - - return (NMSetting *) s_team; - -error: - g_object_unref (s_team); - return NULL; -} - -static NMConnection * -team_connection_from_ifcfg (const char *file, - shvarFile *ifcfg, - GError **error) -{ - NMConnection *connection = NULL; - NMSetting *con_setting = NULL; - NMSetting *team_setting = NULL; - NMSetting *wired_setting = NULL; - NMSetting8021x *s_8021x = NULL; - - g_return_val_if_fail (file != NULL, NULL); - g_return_val_if_fail (ifcfg != NULL, NULL); - - connection = nm_simple_connection_new (); - - con_setting = make_connection_setting (file, ifcfg, NM_SETTING_TEAM_SETTING_NAME, NULL, _("Team")); - if (!con_setting) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Failed to create connection setting."); - g_object_unref (connection); - return NULL; - } - nm_connection_add_setting (connection, con_setting); - - team_setting = make_team_setting (ifcfg, file, error); - if (!team_setting) { - g_object_unref (connection); - return NULL; - } - nm_connection_add_setting (connection, team_setting); - - wired_setting = make_wired_setting (ifcfg, file, &s_8021x, error); - if (!wired_setting) { - g_object_unref (connection); - return NULL; - } - nm_connection_add_setting (connection, wired_setting); - - if (s_8021x) - nm_connection_add_setting (connection, NM_SETTING (s_8021x)); - - return connection; -} - -typedef void (*BridgeOptFunc) (NMSetting *setting, - gboolean stp, - const char *key, - const char *value); - -static void -handle_bridge_option (NMSetting *setting, - gboolean stp, - const char *key, - const char *value) -{ - guint32 u = 0; - - if (!strcmp (key, "priority")) { - if (stp == FALSE) { - PARSE_WARNING ("'priority' invalid when STP is disabled"); - } else if (get_uint (value, &u)) - g_object_set (setting, NM_SETTING_BRIDGE_PRIORITY, u, NULL); - else - PARSE_WARNING ("invalid priority value '%s'", value); - } else if (!strcmp (key, "hello_time")) { - if (stp == FALSE) { - PARSE_WARNING ("'hello_time' invalid when STP is disabled"); - } else if (get_uint (value, &u)) - g_object_set (setting, NM_SETTING_BRIDGE_HELLO_TIME, u, NULL); - else - PARSE_WARNING ("invalid hello_time value '%s'", value); - } else if (!strcmp (key, "max_age")) { - if (stp == FALSE) { - PARSE_WARNING ("'max_age' invalid when STP is disabled"); - } else if (get_uint (value, &u)) - g_object_set (setting, NM_SETTING_BRIDGE_MAX_AGE, u, NULL); - else - PARSE_WARNING ("invalid max_age value '%s'", value); - } else if (!strcmp (key, "ageing_time")) { - if (get_uint (value, &u)) - g_object_set (setting, NM_SETTING_BRIDGE_AGEING_TIME, u, NULL); - else - PARSE_WARNING ("invalid ageing_time value '%s'", value); - } else if (!strcmp (key, "multicast_snooping")) { - if (get_uint (value, &u)) - g_object_set (setting, NM_SETTING_BRIDGE_MULTICAST_SNOOPING, - (gboolean) u, NULL); - else - PARSE_WARNING ("invalid multicast_snooping value '%s'", value); - } else - PARSE_WARNING ("unhandled bridge option '%s'", key); -} - -static void -handle_bridging_opts (NMSetting *setting, - gboolean stp, - const char *value, - BridgeOptFunc func) -{ - char **items, **iter; - - items = g_strsplit_set (value, " ", -1); - for (iter = items; iter && *iter; iter++) { - if (strlen (*iter)) { - char **keys, *key, *val; - - keys = g_strsplit_set (*iter, "=", 2); - if (keys && *keys) { - key = *keys; - val = *(keys + 1); - if (val && strlen(key) && strlen(val)) - func (setting, stp, key, val); - } - - g_strfreev (keys); - } - } - g_strfreev (items); -} - -static NMSetting * -make_bridge_setting (shvarFile *ifcfg, - const char *file, - GError **error) -{ - NMSettingBridge *s_bridge; - char *value; - guint32 u; - gboolean stp = FALSE; - gboolean stp_set = FALSE; - - s_bridge = NM_SETTING_BRIDGE (nm_setting_bridge_new ()); - - value = svGetValue (ifcfg, "DEVICE", FALSE); - if (!value || !strlen (value)) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "mandatory DEVICE keyword missing"); - goto error; - } - g_free (value); - - value = svGetValue (ifcfg, "MACADDR", FALSE); - if (value) { - value = g_strstrip (value); - g_object_set (s_bridge, NM_SETTING_BRIDGE_MAC_ADDRESS, value, NULL); - g_free (value); - } - - value = svGetValue (ifcfg, "STP", FALSE); - if (value) { - if (!strcasecmp (value, "on") || !strcasecmp (value, "yes")) { - g_object_set (s_bridge, NM_SETTING_BRIDGE_STP, TRUE, NULL); - stp = TRUE; - stp_set = TRUE; - } else if (!strcasecmp (value, "off") || !strcasecmp (value, "no")) { - g_object_set (s_bridge, NM_SETTING_BRIDGE_STP, FALSE, NULL); - stp_set = TRUE; - } else - PARSE_WARNING ("invalid STP value '%s'", value); - g_free (value); - } - - if (!stp_set) { - /* Missing or invalid STP property means "no" */ - g_object_set (s_bridge, NM_SETTING_BRIDGE_STP, FALSE, NULL); - } - - value = svGetValue (ifcfg, "DELAY", FALSE); - if (value) { - if (stp) { - if (get_uint (value, &u)) - g_object_set (s_bridge, NM_SETTING_BRIDGE_FORWARD_DELAY, u, NULL); - else - PARSE_WARNING ("invalid forward delay value '%s'", value); - } else - PARSE_WARNING ("DELAY invalid when STP is disabled"); - g_free (value); - } - - value = svGetValue (ifcfg, "BRIDGING_OPTS", FALSE); - if (value) { - handle_bridging_opts (NM_SETTING (s_bridge), stp, value, handle_bridge_option); - g_free (value); - } - - return (NMSetting *) s_bridge; - -error: - g_object_unref (s_bridge); - return NULL; -} - -static NMConnection * -bridge_connection_from_ifcfg (const char *file, - shvarFile *ifcfg, - GError **error) -{ - NMConnection *connection = NULL; - NMSetting *con_setting = NULL; - NMSetting *bridge_setting = NULL; - - g_return_val_if_fail (file != NULL, NULL); - g_return_val_if_fail (ifcfg != NULL, NULL); - - connection = nm_simple_connection_new (); - - con_setting = make_connection_setting (file, ifcfg, NM_SETTING_BRIDGE_SETTING_NAME, NULL, _("Bridge")); - if (!con_setting) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Failed to create connection setting."); - g_object_unref (connection); - return NULL; - } - nm_connection_add_setting (connection, con_setting); - - bridge_setting = make_bridge_setting (ifcfg, file, error); - if (!bridge_setting) { - g_object_unref (connection); - return NULL; - } - nm_connection_add_setting (connection, bridge_setting); - - return connection; -} - -static void -handle_bridge_port_option (NMSetting *setting, - gboolean stp, - const char *key, - const char *value) -{ - guint32 u = 0; - - if (!strcmp (key, "priority")) { - if (get_uint (value, &u)) - g_object_set (setting, NM_SETTING_BRIDGE_PORT_PRIORITY, u, NULL); - else - PARSE_WARNING ("invalid priority value '%s'", value); - } else if (!strcmp (key, "path_cost")) { - if (get_uint (value, &u)) - g_object_set (setting, NM_SETTING_BRIDGE_PORT_PATH_COST, u, NULL); - else - PARSE_WARNING ("invalid path_cost value '%s'", value); - } else if (!strcmp (key, "hairpin_mode")) { - if (!strcasecmp (value, "on") || !strcasecmp (value, "yes") || !strcmp (value, "1")) - g_object_set (setting, NM_SETTING_BRIDGE_PORT_HAIRPIN_MODE, TRUE, NULL); - else if (!strcasecmp (value, "off") || !strcasecmp (value, "no")) - g_object_set (setting, NM_SETTING_BRIDGE_PORT_HAIRPIN_MODE, FALSE, NULL); - else - PARSE_WARNING ("invalid hairpin_mode value '%s'", value); - } else - PARSE_WARNING ("unhandled bridge port option '%s'", key); -} - -static NMSetting * -make_bridge_port_setting (shvarFile *ifcfg) -{ - NMSetting *s_port = NULL; - char *value; - - g_return_val_if_fail (ifcfg != NULL, FALSE); - - value = svGetValue (ifcfg, "BRIDGE", FALSE); - if (value) { - g_free (value); - - s_port = nm_setting_bridge_port_new (); - value = svGetValue (ifcfg, "BRIDGING_OPTS", FALSE); - if (value) - handle_bridging_opts (s_port, FALSE, value, handle_bridge_port_option); - g_free (value); - } - - return s_port; -} - -static NMSetting * -make_team_port_setting (shvarFile *ifcfg) -{ - NMSetting *s_port = NULL; - char *value; - GError *error = NULL; - - value = read_team_config (ifcfg, "TEAM_PORT_CONFIG", &error); - if (value) { - s_port = nm_setting_team_port_new (); - g_object_set (s_port, NM_SETTING_TEAM_PORT_CONFIG, value, NULL); - g_free (value); - } else if (error) { - PARSE_WARNING ("%s", error->message); - g_error_free (error); - } - - return s_port; -} - -static gboolean -is_bond_device (const char *name, shvarFile *parsed) -{ - g_return_val_if_fail (name != NULL, FALSE); - g_return_val_if_fail (parsed != NULL, FALSE); - - if (svGetValueBoolean (parsed, "BONDING_MASTER", FALSE)) - return TRUE; - - return FALSE; -} - -static gboolean -is_vlan_device (const char *name, shvarFile *parsed) -{ - g_return_val_if_fail (name != NULL, FALSE); - g_return_val_if_fail (parsed != NULL, FALSE); - - if (svGetValueBoolean (parsed, "VLAN", FALSE)) - return TRUE; - - return FALSE; -} - -static gboolean -is_wifi_device (const char *name, shvarFile *parsed) -{ - int ifindex; - - g_return_val_if_fail (name != NULL, FALSE); - g_return_val_if_fail (parsed != NULL, FALSE); - - ifindex = nm_platform_link_get_ifindex (NM_PLATFORM_GET, name); - if (ifindex == 0) - return FALSE; - - return nm_platform_link_get_type (NM_PLATFORM_GET, ifindex) == NM_LINK_TYPE_WIFI; -} - -static void -parse_prio_map_list (NMSettingVlan *s_vlan, - shvarFile *ifcfg, - const char *key, - NMVlanPriorityMap map) -{ - char *value; - gchar **list = NULL, **iter; - - value = svGetValue (ifcfg, key, FALSE); - if (!value) - return; - - list = g_strsplit_set (value, ",", -1); - g_free (value); - - for (iter = list; iter && *iter; iter++) { - if (!*iter || !strchr (*iter, ':')) - continue; - - if (!nm_setting_vlan_add_priority_str (s_vlan, map, *iter)) - PARSE_WARNING ("invalid %s priority map item '%s'", key, *iter); - } - g_strfreev (list); -} - -static NMSetting * -make_vlan_setting (shvarFile *ifcfg, - const char *file, - GError **error) -{ - NMSettingVlan *s_vlan = NULL; - char *value = NULL; - char *iface_name = NULL; - char *parent = NULL; - const char *p = NULL; - int vlan_id = -1; - guint32 vlan_flags = 0; - gint gvrp, reorder_hdr; - - value = svGetValue (ifcfg, "VLAN_ID", FALSE); - if (value) { - vlan_id = _nm_utils_ascii_str_to_int64 (value, 10, 0, 4095, -1); - if (vlan_id == -1) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Invalid VLAN_ID '%s'", value); - g_free (value); - return NULL; - } - g_free (value); - } - - /* Need DEVICE if we don't have a separate VLAN_ID property */ - iface_name = svGetValue (ifcfg, "DEVICE", FALSE); - if (!iface_name && vlan_id < 0) { - g_set_error_literal (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Missing DEVICE property; cannot determine VLAN ID."); - return NULL; - } - - s_vlan = NM_SETTING_VLAN (nm_setting_vlan_new ()); - - /* Parent interface from PHYSDEV takes precedence if it exists */ - parent = svGetValue (ifcfg, "PHYSDEV", FALSE); - - if (iface_name) { - p = strchr (iface_name, '.'); - if (p) { - /* eth0.43; PHYSDEV is assumed from it if unknown */ - if (!parent) { - parent = g_strndup (iface_name, p - iface_name); - if (g_str_has_prefix (parent, "vlan")) { - /* Like initscripts, if no PHYSDEV and we get an obviously - * invalid parent interface from DEVICE, fail. - */ - g_free (parent); - parent = NULL; - } - } - p++; - } else { - /* format like vlan43; PHYSDEV must be set */ - if (g_str_has_prefix (iface_name, "vlan")) - p = iface_name + 4; - } - - if (p) { - int device_vlan_id; - - /* Grab VLAN ID from interface name; this takes precedence over the - * separate VLAN_ID property for backwards compat. - */ - device_vlan_id = _nm_utils_ascii_str_to_int64 (p, 10, 0, 4095, -1); - if (device_vlan_id != -1) - vlan_id = device_vlan_id; - } - } - - if (vlan_id < 0) { - g_set_error_literal (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Failed to determine VLAN ID from DEVICE or VLAN_ID."); - goto error; - } - g_object_set (s_vlan, NM_SETTING_VLAN_ID, vlan_id, NULL); - - if (parent == NULL) { - g_set_error_literal (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Failed to determine VLAN parent from DEVICE or PHYSDEV"); - goto error; - } - g_object_set (s_vlan, NM_SETTING_VLAN_PARENT, parent, NULL); - g_clear_pointer (&parent, g_free); - - vlan_flags |= NM_VLAN_FLAG_REORDER_HEADERS; - - gvrp = svGetValueBoolean (ifcfg, "GVRP", -1); - if (gvrp > 0) - vlan_flags |= NM_VLAN_FLAG_GVRP; - - value = svGetValue (ifcfg, "VLAN_FLAGS", FALSE); - if (value) { - gs_strfreev char **strv = NULL; - char **ptr; - - strv = g_strsplit_set (value, ", ", 0); - - for (ptr = strv; ptr && *ptr; ptr++) { - if (nm_streq (*ptr, "GVRP") && gvrp == -1) - vlan_flags |= NM_VLAN_FLAG_GVRP; - if (nm_streq (*ptr, "LOOSE_BINDING")) - vlan_flags |= NM_VLAN_FLAG_LOOSE_BINDING; - if (nm_streq (*ptr, "NO_REORDER_HDR")) - vlan_flags &= ~NM_VLAN_FLAG_REORDER_HEADERS; - } - } - - reorder_hdr = svGetValueBoolean (ifcfg, "REORDER_HDR", -1); - if ( reorder_hdr != -1 - && reorder_hdr != NM_FLAGS_HAS (vlan_flags, NM_VLAN_FLAG_REORDER_HEADERS)) - PARSE_WARNING ("REORDER_HDR key is deprecated, use VLAN_FLAGS"); - - if (svGetValueBoolean (ifcfg, "MVRP", FALSE)) - vlan_flags |= NM_VLAN_FLAG_MVRP; - - g_object_set (s_vlan, NM_SETTING_VLAN_FLAGS, vlan_flags, NULL); - g_free (value); - - parse_prio_map_list (s_vlan, ifcfg, "VLAN_INGRESS_PRIORITY_MAP", NM_VLAN_INGRESS_MAP); - parse_prio_map_list (s_vlan, ifcfg, "VLAN_EGRESS_PRIORITY_MAP", NM_VLAN_EGRESS_MAP); - - g_free (iface_name); - - return (NMSetting *) s_vlan; - -error: - g_free (parent); - g_free (iface_name); - g_object_unref (s_vlan); - return NULL; -} - -static NMConnection * -vlan_connection_from_ifcfg (const char *file, - shvarFile *ifcfg, - GError **error) -{ - NMConnection *connection = NULL; - NMSetting *con_setting = NULL; - NMSetting *wired_setting = NULL; - NMSetting *vlan_setting = NULL; - NMSetting8021x *s_8021x = NULL; - - g_return_val_if_fail (file != NULL, NULL); - g_return_val_if_fail (ifcfg != NULL, NULL); - - connection = nm_simple_connection_new (); - - con_setting = make_connection_setting (file, ifcfg, NM_SETTING_VLAN_SETTING_NAME, NULL, "Vlan"); - if (!con_setting) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Failed to create connection setting."); - g_object_unref (connection); - return NULL; - } - check_if_slave (ifcfg, (NMSettingConnection *) con_setting); - nm_connection_add_setting (connection, con_setting); - - vlan_setting = make_vlan_setting (ifcfg, file, error); - if (!vlan_setting) { - g_object_unref (connection); - return NULL; - } - nm_connection_add_setting (connection, vlan_setting); - - wired_setting = make_wired_setting (ifcfg, file, &s_8021x, error); - if (!wired_setting) { - g_object_unref (connection); - return NULL; - } - nm_connection_add_setting (connection, wired_setting); - - if (s_8021x) - nm_connection_add_setting (connection, NM_SETTING (s_8021x)); - - return connection; -} - -static NMConnection * -create_unhandled_connection (const char *filename, shvarFile *ifcfg, - const char *type, char **out_spec) -{ - NMConnection *connection; - NMSetting *s_con; - char *value; - - nm_assert (out_spec && !*out_spec); - - connection = nm_simple_connection_new (); - - /* Get NAME, UUID, etc. We need to set a connection type (generic) and add - * an empty type-specific setting as well, to make sure it passes - * nm_connection_verify() later. - */ - s_con = make_connection_setting (filename, ifcfg, NM_SETTING_GENERIC_SETTING_NAME, - NULL, NULL); - nm_connection_add_setting (connection, s_con); - - nm_connection_add_setting (connection, nm_setting_generic_new ()); - - /* Get a spec */ - value = svGetValue (ifcfg, "HWADDR", FALSE); - if (value) { - char *lower = g_ascii_strdown (value, -1); - *out_spec = g_strdup_printf ("%s:mac:%s", type, lower); - g_free (lower); - g_free (value); - return connection; - } - - value = svGetValue (ifcfg, "SUBCHANNELS", FALSE); - if (value) { - *out_spec = g_strdup_printf ("%s:s390-subchannels:%s", type, value); - g_free (value); - return connection; - } - - value = svGetValue (ifcfg, "DEVICE", FALSE); - if (value) { - *out_spec = g_strdup_printf ("%s:interface-name:%s", type, value); - g_free (value); - return connection; - } - - g_object_unref (connection); - return NULL; -} - -char * -uuid_from_file (const char *filename) -{ - const char *ifcfg_name = NULL; - shvarFile *ifcfg; - char *uuid; - - g_return_val_if_fail (filename != NULL, NULL); - - ifcfg_name = utils_get_ifcfg_name (filename, TRUE); - if (!ifcfg_name) - return NULL; - - ifcfg = svOpenFile (filename, NULL); - if (!ifcfg) - return NULL; - - /* Try for a UUID key before falling back to hashing the file name */ - uuid = svGetValue (ifcfg, "UUID", FALSE); - if (!uuid || !strlen (uuid)) { - g_free (uuid); - uuid = nm_utils_uuid_generate_from_string (ifcfg->fileName, -1, NM_UTILS_UUID_TYPE_LEGACY, NULL); - } - - svCloseFile (ifcfg); - return uuid; -} - -static void -check_dns_search_domains (shvarFile *ifcfg, NMSetting *s_ip4, NMSetting *s_ip6) -{ - if (!s_ip6) - return; - - /* If there is no IPv4 config or it doesn't contain DNS searches, - * read DOMAIN and put the domains into IPv6. - */ - if (!s_ip4 || nm_setting_ip_config_get_num_dns_searches (NM_SETTING_IP_CONFIG (s_ip4)) == 0) { - /* DNS searches */ - char *value = svGetValue (ifcfg, "DOMAIN", FALSE); - if (value) { - char **searches = g_strsplit (value, " ", 0); - if (searches) { - char **item; - for (item = searches; *item; item++) { - if (strlen (*item)) { - if (!nm_setting_ip_config_add_dns_search (NM_SETTING_IP_CONFIG (s_ip6), *item)) - PARSE_WARNING ("duplicate DNS domain '%s'", *item); - } - } - g_strfreev (searches); - } - g_free (value); - } - } -} - -static NMConnection * -connection_from_file_full (const char *filename, - const char *network_file, /* for unit tests only */ - const char *test_type, /* for unit tests only */ - char **out_unhandled, - GError **error, - gboolean *out_ignore_error) -{ - NMConnection *connection = NULL; - shvarFile *parsed; - gs_free char *type = NULL; - char *devtype, *bootproto; - NMSetting *s_ip4, *s_ip6, *s_port, *s_dcb = NULL; - const char *ifcfg_name = NULL; - - g_return_val_if_fail (filename != NULL, NULL); - g_return_val_if_fail (out_unhandled && !*out_unhandled, NULL); - - /* Non-NULL only for unit tests; normally use /etc/sysconfig/network */ - if (!network_file) - network_file = SYSCONFDIR "/sysconfig/network"; - - ifcfg_name = utils_get_ifcfg_name (filename, TRUE); - if (!ifcfg_name) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Ignoring connection '%s' because it's not an ifcfg file.", filename); - return NULL; - } - - parsed = svOpenFile (filename, error); - if (!parsed) - return NULL; - - if (!svGetValueBoolean (parsed, "NM_CONTROLLED", TRUE)) { - connection = create_unhandled_connection (filename, parsed, "unmanaged", out_unhandled); - if (!connection) - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, - "NM_CONTROLLED was false but device was not uniquely identified; device will be managed"); - goto done; - } - - /* iBFT is handled by the iBFT settings plugin */ - bootproto = svGetValue (parsed, "BOOTPROTO", FALSE); - if (bootproto && !g_ascii_strcasecmp (bootproto, "ibft")) { - if (out_ignore_error) - *out_ignore_error = TRUE; - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Ignoring iBFT configuration"); - g_free (bootproto); - goto done; - } - g_free (bootproto); - - devtype = svGetValue (parsed, "DEVICETYPE", FALSE); - if (devtype) { - if (!strcasecmp (devtype, TYPE_TEAM)) - type = g_strdup (TYPE_TEAM); - else if (!strcasecmp (devtype, TYPE_TEAM_PORT)) - type = g_strdup (TYPE_ETHERNET); - g_free (devtype); - } - if (!type) { - gs_free char *t = NULL; - - /* Team and TeamPort types are also accepted by the mere - * presense of TEAM_CONFIG/TEAM_MASTER. They don't require - * DEVICETYPE. */ - t = svGetValue (parsed, "TEAM_CONFIG", FALSE); - if (t) - type = g_strdup (TYPE_TEAM); - } - - if (!type) - type = svGetValue (parsed, "TYPE", FALSE); - - if (!type) { - gs_free char *tmp = NULL; - char *device; - - if ((tmp = svGetValue (parsed, "IPV6TUNNELIPV4", FALSE))) { - if (out_ignore_error) - *out_ignore_error = TRUE; - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Ignoring unsupported connection due to IPV6TUNNELIPV4"); - goto done; - } - - device = svGetValue (parsed, "DEVICE", FALSE); - if (!device) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "File '%s' had neither TYPE nor DEVICE keys.", filename); - goto done; - } - g_assert (device[0]); - - if (!strcmp (device, "lo")) { - if (out_ignore_error) - *out_ignore_error = TRUE; - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Ignoring loopback device config."); - g_free (device); - goto done; - } - - if (!test_type) { - if (is_bond_device (device, parsed)) - type = g_strdup (TYPE_BOND); - else if (is_vlan_device (device, parsed)) - type = g_strdup (TYPE_VLAN); - else if (is_wifi_device (device, parsed)) - type = g_strdup (TYPE_WIRELESS); - else { - gs_free char *p_path = NULL; - char *p_device; - gsize i; - - /* network-functions detects DEVICETYPE based on the ifcfg-* name and the existence - * of a ifup script: - * [ -z "$DEVICETYPE" ] && DEVICETYPE=$(echo ${DEVICE} | sed "s/[0-9]*$//") - * later... - * OTHERSCRIPT="/etc/sysconfig/network-scripts/ifup-${DEVICETYPE}" - * */ -#define IFUP_PATH_PREFIX "/etc/sysconfig/network-scripts/ifup-" - i = strlen (device); - p_path = g_malloc (NM_STRLEN (IFUP_PATH_PREFIX) + i + 1); - p_device = &p_path[NM_STRLEN (IFUP_PATH_PREFIX)]; - memcpy (p_device, device, i + 1); - - /* strip trailing numbers */ - while (i >= 1) { - i--; - if (p_device[i] < '0' || p_device[i] > '9') - break; - p_device[i] = '\0'; - } - - if (nm_streq (p_device, "eth")) - type = g_strdup (TYPE_ETHERNET); - else if (nm_streq (p_device, "wireless")) - type = g_strdup (TYPE_WIRELESS); - else if (p_device[0]) { - memcpy (p_path, IFUP_PATH_PREFIX, NM_STRLEN (IFUP_PATH_PREFIX)); - if (access (p_path, X_OK) == 0) { - /* for all other types, this is not something we want to handle. */ - if (out_ignore_error) - *out_ignore_error = TRUE; - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "Ignore script for unknown device type which has a matching %s script", - p_path); - goto done; - } - } - - if (!type) - type = g_strdup (TYPE_ETHERNET); - } - } else { - /* For the unit tests, there won't necessarily be any - * adapters of the connection's type in the system so the - * type can't be tested with ioctls. - */ - type = g_strdup (test_type); - } - - g_free (device); - } else { - /* Check for IBM s390 CTC devices and call them Ethernet */ - if (g_strcmp0 (type, "CTC") == 0) { - g_free (type); - type = g_strdup (TYPE_ETHERNET); - } - } - - if (svGetValueBoolean (parsed, "BONDING_MASTER", FALSE) && - strcasecmp (type, TYPE_BOND)) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, - "BONDING_MASTER=yes key only allowed in TYPE=bond connections"); - goto done; - } - - /* Construct the connection */ - if (!strcasecmp (type, TYPE_ETHERNET)) - connection = wired_connection_from_ifcfg (filename, parsed, error); - else if (!strcasecmp (type, TYPE_WIRELESS)) - connection = wireless_connection_from_ifcfg (filename, parsed, error); - else if (!strcasecmp (type, TYPE_INFINIBAND)) - connection = infiniband_connection_from_ifcfg (filename, parsed, error); - else if (!strcasecmp (type, TYPE_BOND)) - connection = bond_connection_from_ifcfg (filename, parsed, error); - else if (!strcasecmp (type, TYPE_TEAM)) - connection = team_connection_from_ifcfg (filename, parsed, error); - else if (!strcasecmp (type, TYPE_VLAN)) - connection = vlan_connection_from_ifcfg (filename, parsed, error); - else if (!strcasecmp (type, TYPE_BRIDGE)) - connection = bridge_connection_from_ifcfg (filename, parsed, error); - else { - connection = create_unhandled_connection (filename, parsed, "unrecognized", out_unhandled); - if (!connection) - PARSE_WARNING ("connection type was unrecognized but device was not uniquely identified; device may be managed"); - goto done; - } - - if (!connection) - goto done; - - s_ip6 = make_ip6_setting (parsed, network_file, error); - if (!s_ip6) { - g_object_unref (connection); - connection = NULL; - goto done; - } else - nm_connection_add_setting (connection, s_ip6); - - s_ip4 = make_ip4_setting (parsed, network_file, error); - if (!s_ip4) { - g_object_unref (connection); - connection = NULL; - goto done; - } else { - read_aliases (NM_SETTING_IP_CONFIG (s_ip4), filename); - nm_connection_add_setting (connection, s_ip4); - } - - /* There is only one DOMAIN variable and it is read and put to IPv4 config - * But if IPv4 is disabled or the config fails for some reason, we read - * DOMAIN and put the values into IPv6 config instead. - */ - check_dns_search_domains (parsed, s_ip4, s_ip6); - - /* Bridge port? */ - s_port = make_bridge_port_setting (parsed); - if (s_port) - nm_connection_add_setting (connection, s_port); - - /* Team port? */ - s_port = make_team_port_setting (parsed); - if (s_port) - nm_connection_add_setting (connection, s_port); - - if (!make_dcb_setting (parsed, network_file, &s_dcb, error)) { - g_object_unref (connection); - connection = NULL; - goto done; - } - if (s_dcb) - nm_connection_add_setting (connection, s_dcb); - - if (!nm_connection_normalize (connection, NULL, NULL, error)) { - g_object_unref (connection); - connection = NULL; - } - -done: - svCloseFile (parsed); - return connection; -} - -NMConnection * -connection_from_file (const char *filename, - char **out_unhandled, - GError **error, - gboolean *out_ignore_error) -{ - return connection_from_file_full (filename, NULL, NULL, - out_unhandled, - error, - out_ignore_error); -} - -NMConnection * -connection_from_file_test (const char *filename, - const char *network_file, - const char *test_type, - char **out_unhandled, - GError **error) -{ - return connection_from_file_full (filename, - network_file, - test_type, - out_unhandled, - error, - NULL); -} - -guint -devtimeout_from_file (const char *filename) -{ - shvarFile *ifcfg; - char *devtimeout_str; - guint devtimeout; - - g_return_val_if_fail (filename != NULL, 0); - - ifcfg = svOpenFile (filename, NULL); - if (!ifcfg) - return 0; - - devtimeout_str = svGetValue (ifcfg, "DEVTIMEOUT", FALSE); - if (devtimeout_str) { - devtimeout = _nm_utils_ascii_str_to_int64 (devtimeout_str, 10, 0, G_MAXUINT, 0); - g_free (devtimeout_str); - } else - devtimeout = 0; - - svCloseFile (ifcfg); - - return devtimeout; -} diff --git a/src/settings/plugins/ifcfg-rh/reader.h b/src/settings/plugins/ifcfg-rh/reader.h deleted file mode 100644 index 35464474..00000000 --- a/src/settings/plugins/ifcfg-rh/reader.h +++ /dev/null @@ -1,42 +0,0 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* NetworkManager system settings service - * - * 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 Red Hat, Inc. - */ - -#ifndef __READER_H__ -#define __READER_H__ - -#include "nm-connection.h" - -NMConnection *connection_from_file (const char *filename, - char **out_unhandled, - GError **error, - gboolean *out_ignore_error); - -char *uuid_from_file (const char *filename); - -guint devtimeout_from_file (const char *filename); - -/* for test-ifcfg-rh */ -NMConnection *connection_from_file_test (const char *filename, - const char *network_file, - const char *test_type, - char **out_unhandled, - GError **error); - -#endif /* __READER_H__ */ diff --git a/src/settings/plugins/ifcfg-rh/shvar.c b/src/settings/plugins/ifcfg-rh/shvar.c index a865c7df..65bcc0d9 100644 --- a/src/settings/plugins/ifcfg-rh/shvar.c +++ b/src/settings/plugins/ifcfg-rh/shvar.c @@ -37,292 +37,901 @@ #include #include "nm-core-internal.h" +#include "nm-core-utils.h" + +/*****************************************************************************/ + +typedef struct { + /* There are three cases: + * + * 1) the line is not a valid variable assignment (that is, it doesn't + * start with a "FOO=" with possible whitespace prefix). + * In that case, @key and @key_with_prefix are %NULL, and the entire + * original line is in @line. Such entries are ignored for the most part. + * + * 2) if the line can be parsed with a "FOO=" assignment, then @line contains + * the part after '=', @key_with_prefix contains the key "FOO" with possible + * whitespace prefix, and @key points into @key_with_prefix skipping over the + * whitespace. + * + * 3) like 2, but if the value was deleted via svSetValue(), the entry is not removed, + * but only marked for deletion. That is done by clearing @line but preserving + * @key/@key_with_prefix. + * */ + char *line; + const char *key; + char *key_with_prefix; +} shvarLine; -/* Open the file , returning a shvarFile on success and NULL on failure. - * Add a wrinkle to let the caller specify whether or not to create the file - * (actually, return a structure anyway) if it doesn't exist. +struct _shvarFile { + char *fileName; + int fd; + GList *lineList; + gboolean modified; +}; + +/*****************************************************************************/ + +/** + * svParseBoolean: + * @value: the input string + * @fallback: the fallback value + * + * Parses a string and returns the boolean value it contains or, + * in case no valid value is found, the fallback value. Valid values + * are: "yes", "true", "t", "y", "1" and "no", "false", "f", "n", "0". + * + * Returns: the parsed boolean value or @fallback. */ -static shvarFile * -svOpenFileInternal (const char *name, gboolean create, GError **error) +gint +svParseBoolean (const char *value, gint fallback) { - shvarFile *s = NULL; - gboolean closefd = FALSE; - int errsv = 0; + if (!value) + return fallback; - s = g_slice_new0 (shvarFile); + if ( !g_ascii_strcasecmp ("yes", value) + || !g_ascii_strcasecmp ("true", value) + || !g_ascii_strcasecmp ("t", value) + || !g_ascii_strcasecmp ("y", value) + || !g_ascii_strcasecmp ("1", value)) + return TRUE; + else if ( !g_ascii_strcasecmp ("no", value) + || !g_ascii_strcasecmp ("false", value) + || !g_ascii_strcasecmp ("f", value) + || !g_ascii_strcasecmp ("n", value) + || !g_ascii_strcasecmp ("0", value)) + return FALSE; - s->fd = -1; - if (create) - s->fd = open (name, O_RDWR | O_CLOEXEC); /* NOT O_CREAT */ + return fallback; +} - if (!create || s->fd == -1) { - /* try read-only */ - s->fd = open (name, O_RDONLY | O_CLOEXEC); /* NOT O_CREAT */ - if (s->fd == -1) - errsv = errno; - else - closefd = TRUE; - } - s->fileName = g_strdup (name); +/*****************************************************************************/ - if (s->fd != -1) { - struct stat buf; - char *arena, *p, *q; - ssize_t nread, total = 0; +static gboolean +_shell_is_name (const char *key, gssize len) +{ + gssize i; - if (fstat (s->fd, &buf) < 0) { - errsv = errno; - goto bail; + /* whether @key is a valid identifier (name). */ + if (!key || len == 0) + return FALSE; + if ( !g_ascii_isalpha (key[0]) + && key[0] != '_') + return FALSE; + for (i = 1; TRUE; i++) { + if (len < 0) { + if (!key[i]) + return TRUE; + } else { + if (i >= len) + return TRUE; } - arena = g_malloc (buf.st_size + 1); - arena[buf.st_size] = '\0'; + if ( !g_ascii_isalnum (key[i]) + && key[i] != '_') + return FALSE; + } +} - while (total < buf.st_size) { - nread = read (s->fd, arena + total, buf.st_size - total); - if (nread == -1 && errno == EINTR) - continue; - if (nread <= 0) { - errsv = errno; - g_free (arena); - goto bail; - } - total += nread; - } +/*****************************************************************************/ + +/* like g_strescape(), except that it also escapes '\''' *sigh*. + * + * While at it, add $''. */ +static char * +_escape_ansic (const char *source) +{ + const char *p; + gchar *dest; + gchar *q; + + nm_assert (source); - /* we'd use g_strsplit() here, but we want a list, not an array */ - for (p = arena; (q = strchr (p, '\n')) != NULL; p = q + 1) - s->lineList = g_list_append (s->lineList, g_strndup (p, q - p)); - g_free (arena); - - /* closefd is set if we opened the file read-only, so go ahead and - * close it, because we can't write to it anyway - */ - if (closefd) { - close (s->fd); - s->fd = -1; + p = (const char *) source; + /* Each source byte needs maximally four destination chars (\777) */ + q = dest = g_malloc (strlen (source) * 4 + 1 + 3); + + *q++ = '$'; + *q++ = '\''; + + while (*p) { + switch (*p) { + case '\b': + *q++ = '\\'; + *q++ = 'b'; + break; + case '\f': + *q++ = '\\'; + *q++ = 'f'; + break; + case '\n': + *q++ = '\\'; + *q++ = 'n'; + break; + case '\r': + *q++ = '\\'; + *q++ = 'r'; + break; + case '\t': + *q++ = '\\'; + *q++ = 't'; + break; + case '\v': + *q++ = '\\'; + *q++ = 'v'; + break; + case '\\': + case '"': + case '\'': + *q++ = '\\'; + *q++ = *p; + break; + default: + if ((*p < ' ') || (*p >= 0177)) { + *q++ = '\\'; + *q++ = '0' + (((*p) >> 6) & 07); + *q++ = '0' + (((*p) >> 3) & 07); + *q++ = '0' + ((*p) & 07); + } else + *q++ = *p; + break; } + p++; + } + *q++ = '\''; + *q++ = '\0'; + + nm_assert (q - dest <= strlen (source) * 4 + 1 + 3); + + return dest; +} + +/*****************************************************************************/ + +#define _char_req_escape(ch) NM_IN_SET (ch, '\"', '\\', '$', '`') +#define _char_req_escape_old(ch) NM_IN_SET (ch, '\"', '\\', '\'', '$', '`', '~') +#define _char_req_quotes(ch) NM_IN_SET (ch, ' ', '\'', '~', '\t', '|', '&', ';', '(', ')', '<', '>') + +const char * +svEscape (const char *s, char **to_free) +{ + char *new; + gsize mangle = 0; + gboolean requires_quotes = FALSE; + int newlen; + size_t i, j, slen; + slen = strlen (s); + + for (i = 0; i < slen; i++) { + if (_char_req_escape (s[i])) + mangle++; + else if (_char_req_quotes (s[i])) + requires_quotes = TRUE; + else if (s[i] < ' ') { + /* if the string contains newline we can only express it using ANSI C quotation + * (as we don't support line continuation). + * Additionally, ANSI control characters look odd with regular quotation, so handle + * them too. */ + return (*to_free = _escape_ansic (s)); + } + } + if (!mangle && !requires_quotes) { + *to_free = NULL; return s; } - if (create) - return s; + newlen = slen + mangle + 3; /* 3 is extra ""\0 */ + new = g_malloc (newlen); - bail: - if (s->fd != -1) - close (s->fd); - g_free (s->fileName); - g_slice_free (shvarFile, s); + j = 0; + new[j++] = '"'; + for (i = 0; i < slen; i++) { + if (_char_req_escape (s[i])) + new[j++] = '\\'; + new[j++] = s[i]; + } + new[j++] = '"'; + new[j++] = '\0'; - g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errsv), - "Could not read file '%s': %s", - name, errsv ? strerror (errsv) : "Unknown error"); - return NULL; + nm_assert (j == slen + mangle + 3); + + *to_free = new; + return new; } -/* Open the file , return shvarFile on success, NULL on failure */ -shvarFile * -svOpenFile (const char *name, GError **error) +static gboolean +_looks_like_old_svescaped (const char *value) { - return svOpenFileInternal (name, FALSE, error); + gsize k; + + if (value[0] != '"') + return FALSE; + + for (k = 1; ; k++) { + if (value[k] == '\0') + return FALSE; + if (!_char_req_escape_old (value[k])) + continue; + + if (value[k] == '"') + return (value[k + 1] == '\0'); + else if (value[k] == '\\') { + k++; + if (!_char_req_escape_old (value[k])) + return FALSE; + } else + return FALSE; + } } -/* Create a new file structure, returning actual data if the file exists, - * and a suitable starting point if it doesn't. - */ -shvarFile * -svCreateFile (const char *name) +static gboolean +_ch_octal_is (char ch) { - return svOpenFileInternal (name, TRUE, NULL); + return ch >= '0' && ch < '8'; } -/* remove escaped characters in place */ -void -svUnescape (char *s) +static guint8 +_ch_octal_get (char ch) { - size_t len, idx_rd = 0, idx_wr = 0; - char c; + nm_assert (_ch_octal_is (ch)); + return (ch - '0'); +} - len = strlen (s); - if (len < 2) { - if (s[0] == '\\') - s[0] = '\0'; - return; +static gboolean +_ch_hex_is (char ch) +{ + return g_ascii_isxdigit (ch); +} + +static guint8 +_ch_hex_get (char ch) +{ + nm_assert (_ch_hex_is (ch)); + return ch <= '9' ? ch - '0' : (ch & 0x4F) - 'A' + 10; +} + +static void +_gstr_init (GString **str, const char *value, gsize i) +{ + nm_assert (str); + nm_assert (value); + + if (!(*str)) { + /* if @str is not yet initialized, it allocates + * a new GString and copies @i characters from + * @value over. + * + * Unescaping usually does not extend the length of a string, + * so we might be tempted to allocate a fixed buffer of length + * (strlen(value)+CONST). + * However, due to $'\Ux' escapes, the maxium length is some + * (FACTOR*strlen(value) + CONST), which is non trivial to get + * right in all cases. Also, we would have to provision for the + * very unlikely extreme case. + * Instead, use a GString buffer which can grow as needed. But for an + * initial guess, strlen(value) is a good start */ + *str = g_string_new_len (NULL, strlen (value) + 3); + if (i) + g_string_append_len (*str, value, i); } +} + +const char * +svUnescape (const char *value, char **to_free) +{ + gsize i, j; + GString *str = NULL; + int looks_like_old_svescaped = -1; + + /* we handle bash syntax here (note that ifup has #!/bin/bash. + * Thus, see https://www.gnu.org/software/bash/manual/html_node/Quoting.html#Quoting */ + + /* @value shall start with the first character after "FOO=" */ + + nm_assert (value); + nm_assert (to_free); + + /* we don't expect any newlines. They must be filtered out before-hand. + * We also don't support line continuation. */ + nm_assert (!NM_STRCHAR_ANY (value, ch, ch == '\n')); + + i = 0; + while (TRUE) { + + if (value[i] == '\0') + goto out_value; + + if ( g_ascii_isspace (value[i]) + || value[i] == ';') { + gboolean has_semicolon = (value[i] == ';'); + + /* starting with space is only allowed, if the entire + * string consists of spaces (possibly terminated by a comment). + * This disallows for example + * LANG=C ls -1 + * LANG= ls -1 + * but allows + * LANG= #comment + * + * As a special case, we also allow one trailing semicolon, as long + * it is only followed by whitespace or a #-comment. + * FOO=; + * FOO=a; + * FOO=b ; #hallo + */ + j = i + 1; + while ( g_ascii_isspace (value[j]) + || ( !has_semicolon + && (has_semicolon = (value[j] == ';')))) + j++; + if (!NM_IN_SET (value[j], '\0', '#')) + goto out_error; + goto out_value; + } - if ((s[0] == '"' || s[0] == '\'') && s[0] == s[len-1]) { - if (len == 2) { - s[0] = '\0'; - return; + if (value[i] == '\\') { + /* backslash escape */ + _gstr_init (&str, value, i); + i++; + if (G_UNLIKELY (value[i] == '\0')) { + /* we don't support line continuation */ + goto out_error; + } + g_string_append_c (str, value[i]); + i++; + goto loop1_next; } - if (len == 3) { - if (s[1] == '\\') { - s[0] = '\0'; - } else { - s[0] = s[1]; - s[1] = '\0'; + + if (value[i] == '\'') { + /* single quotes */ + _gstr_init (&str, value, i); + i++; + j = i; + while (TRUE) { + if (value[j] == '\0') { + /* unterminated single quote. We don't support line continuation */ + goto out_error; + } + if (value[j] == '\'') + break; + j++; } - return; + g_string_append_len (str, &value[i], j - i); + i = j + 1; + goto loop1_next; } - s[--len] = '\0'; - idx_rd = 1; - } else { - /* seek for the first escape... */ - char *p = strchr (s, '\\'); - - if (!p) - return; - if (p[1] == '\0') { - p[0] = '\0'; - return; + + if (value[i] == '"') { + /* double quotes */ + _gstr_init (&str, value, i); + i++; + while (TRUE) { + if (value[i] == '"') { + i++; + break; + } + if (value[i] == '\0') { + /* unterminated double quote. We don't support line continuation. */ + goto out_error; + } + if (NM_IN_SET (value[i], '`', '$')) { + /* we don't support shell expansion. */ + goto out_error; + } + if (value[i] == '\\') { + i++; + if (value[i] == '\0') { + /* we don't support line continuation */ + goto out_error; + } + if (NM_IN_SET (value[i], '$', '`', '"', '\\')) { + /* Drop the backslash. */ + } else if (NM_IN_SET (value[i], '\'', '~')) { + /* '\'' and '~' in double qoutes are not handled special by shell. + * However, old versions of svEscape() would wrongly use double-quoting + * with backslash escaping for these characters (expecting svUnescape() + * to remove the backslash). + * + * In order to preserve previous behavior, we continue to read such + * strings different then shell does. */ + + /* Actually, we can relax this. Old svEscape() escaped the entire value + * in a particular way with double quotes. + * If the value doesn't exactly look like something as created by svEscape(), + * don't do the compat hack and preserve the backslash. */ + if (looks_like_old_svescaped < 0) + looks_like_old_svescaped = _looks_like_old_svescaped (value); + if (!looks_like_old_svescaped) + g_string_append_c (str, '\\'); + } else + g_string_append_c (str, '\\'); + } + g_string_append_c (str, value[i]); + i++; + } + goto loop1_next; } - idx_wr = idx_rd = (p - s); - } - /* idx_rd points to the first escape. Walk the string and shift the - * characters from idx_rd to idx_wr. - */ - while ((c = s[idx_rd++])) { - if (c == '\\') { - if (s[idx_rd] == '\0') { - s[idx_wr] = '\0'; - return; + if ( value[i] == '$' + && value[i + 1] == '\'') { + /* ANSI-C Quoting */ + _gstr_init (&str, value, i); + i += 2; + while (TRUE) { + char ch; + + if (value[i] == '\'') { + i++; + break; + } + if (value[i] == '\0') { + /* unterminated double quote. We don't support line continuation. */ + goto out_error; + } + if (value[i] == '\\') { + + i++; + if (value[i] == '\0') { + /* we don't support line continuation */ + goto out_error; + } + switch (value[i]) { + case 'a': ch = '\a'; break; + case 'b': ch = '\b'; break; + case 'e': ch = '\e'; break; + case 'E': ch = '\E'; break; + case 'f': ch = '\f'; break; + case 'n': ch = '\n'; break; + case 'r': ch = '\r'; break; + case 't': ch = '\t'; break; + case 'v': ch = '\v'; break; + case '?': ch = '\?'; break; + case '"': ch = '"'; break; + case '\\': ch = '\\'; break; + case '\'': ch = '\''; break; + default: + if (_ch_octal_is (value[i])) { + guint v; + + v = _ch_octal_get (value[i]); + i++; + if (_ch_octal_is (value[i])) { + v = (v * 8) + _ch_octal_get (value[i]); + i++; + if (_ch_octal_is (value[i])) { + v = (v * 8) + _ch_octal_get (value[i]); + i++; + } + } + /* like bash, we cut too large numbers off. E.g. A=$'\772' becomes 0xfa */ + g_string_append_c (str, (guint8) v); + } else if (NM_IN_SET (value[i], 'x', 'u', 'U')) { + const char escape_type = value[i]; + int max_digits = escape_type == 'x' ? 2 : escape_type == 'u' ? 4 : 8; + guint64 v; + + i++; + if (!_ch_hex_is (value[i])) { + /* missing hex value after "\x" escape. This is treated like no escaping. */ + g_string_append_c (str, '\\'); + g_string_append_c (str, escape_type); + } else { + v = _ch_hex_get (value[i]); + i++; + + while (--max_digits > 0) { + if (!_ch_hex_is (value[i])) + break; + v = v * 16 + _ch_hex_get (value[i]); + i++; + } + if (escape_type == 'x') + g_string_append_c (str, v); + else { + /* we treat the unicode escapes as utf-8 encoded values. */ + g_string_append_unichar (str, v); + } + } + } else { + g_string_append_c (str, '\\'); + g_string_append_c (str, value[i]); + i++; + } + goto loop_ansic_next; + } + } else + ch = value[i]; + g_string_append_c (str, ch); + i++; +loop_ansic_next: ; } - s[idx_wr++] = s[idx_rd++]; - continue; + goto loop1_next; + } + + if (NM_IN_SET (value[i], '|', '&', '(', ')', '<', '>')) { + /* shell metacharacters are not supported without quoting. + * Note that ';' is already handled above. */ + goto out_error; + } + + /* an unquoted, regular character. Just consume it directly. */ + if (str) + g_string_append_c (str, value[i]); + i++; + +loop1_next: ; + } + + nm_assert_not_reached (); + +out_value: + if (i == 0) { + nm_assert (!str); + *to_free = NULL; + return ""; + } + + if (str) { + if (str->len == 0 || str->str[0] == '\0') { + g_string_free (str, TRUE); + *to_free = NULL; + return ""; + } else { + *to_free = g_string_free (str, FALSE); + return *to_free; } - s[idx_wr++] = c; } - s[idx_wr] = '\0'; + + if (value[i] != '\0') { + *to_free = g_strndup (value, i); + return *to_free; + } + + *to_free = NULL; + return value; + +out_error: + if (str) + g_string_free (str, TRUE); + *to_free = NULL; + return NULL; } -/* create a new string with all necessary characters escaped. - * caller must free returned string - */ -static const char escapees[] = "\"'\\$~`"; /* must be escaped */ -static const char spaces[] = " \t|&;()<>"; /* only require "" */ -static const char newlines[] = "\n\r"; /* will be removed */ +/*****************************************************************************/ + +static shvarFile * +svFile_new (const char *name) +{ + shvarFile *s; + + s = g_slice_new0 (shvarFile); + s->fd = -1; + s->fileName = g_strdup (name); + return s; +} const char * -svEscape (const char *s, char **to_free) +svFileGetName (const shvarFile *s) { - char *new; - int i, j, mangle = 0, space = 0, newline = 0; - int newlen, slen; + nm_assert (s); - slen = strlen (s); + return s->fileName; +} - for (i = 0; i < slen; i++) { - if (strchr (escapees, s[i])) - mangle++; - if (strchr (spaces, s[i])) - space++; - if (strchr (newlines, s[i])) - newline++; - } - if (!mangle && !space && !newline) { - *to_free = NULL; - return s; +void +svFileSetName (shvarFile *s, const char *fileName) +{ + g_free (s->fileName); + s->fileName = g_strdup (fileName); +} + +void +svFileSetModified (shvarFile *s) +{ + s->modified = TRUE; +} + +/*****************************************************************************/ + +static void +ASSERT_shvarLine (const shvarLine *line) +{ +#if NM_MORE_ASSERTS > 5 + const char *s, *s2; + + nm_assert (line); + if (!line->key) { + nm_assert (line->line); + nm_assert (!line->key_with_prefix); + s = nm_str_skip_leading_spaces (line->line); + s2 = strchr (s, '='); + nm_assert (!s2 || !_shell_is_name (s, s2 - s)); + } else { + nm_assert (line->key_with_prefix); + nm_assert (line->key == nm_str_skip_leading_spaces (line->key_with_prefix)); + nm_assert (_shell_is_name (line->key, -1)); } +#endif +} - newlen = slen + mangle - newline + 3; /* 3 is extra ""\0 */ - new = g_malloc (newlen); +static shvarLine * +line_new_parse (const char *value, gsize len) +{ + shvarLine *line; + gsize k, e; - j = 0; - new[j++] = '"'; - for (i = 0; i < slen; i++) { - if (strchr (newlines, s[i])) + nm_assert (value); + + line = g_slice_new0 (shvarLine); + + for (k = 0; k < len; k++) { + if (g_ascii_isspace (value[k])) continue; - if (strchr (escapees, s[i])) { - new[j++] = '\\'; + + if ( g_ascii_isalpha (value[k]) + || value[k] == '_') { + for (e = k + 1; e < len; e++) { + if (value[e] == '=') { + nm_assert (_shell_is_name (&value[k], e - k)); + line->line = g_strndup (&value[e + 1], len - e - 1); + line->key_with_prefix = g_strndup (value, e); + line->key = &line->key_with_prefix[k]; + ASSERT_shvarLine (line); + return line; + } + if ( !g_ascii_isalnum (value[e]) + && value[e] != '_') + break; + } } - new[j++] = s[i]; + break; } - new[j++] = '"'; - new[j++] = '\0'; - g_assert (j == slen + mangle - newline + 3); + line->line = g_strndup (value, len); + ASSERT_shvarLine (line); + return line; +} - *to_free = new; - return new; +static shvarLine * +line_new_build (const char *key, const char *value) +{ + char *value_escaped = NULL; + shvarLine *line; + + value = svEscape (value, &value_escaped); + + line = g_slice_new (shvarLine); + line->line = value_escaped ?: g_strdup (value); + line->key_with_prefix = g_strdup (key); + line->key = line->key_with_prefix; + ASSERT_shvarLine (line); + return line; } -/* Get the value associated with the key, and leave the current pointer - * pointing at the line containing the value. The char* returned MUST - * be freed by the caller. +static gboolean +line_set (shvarLine *line, const char *value) +{ + char *value_escaped = NULL; + gboolean changed = FALSE; + + ASSERT_shvarLine (line); + nm_assert (line->key); + + if (line->key != line->key_with_prefix) { + memmove (line->key_with_prefix, line->key, strlen (line->key) + 1); + line->key = line->key_with_prefix; + changed = TRUE; + ASSERT_shvarLine (line); + } + + value = svEscape (value, &value_escaped); + + if (line->line) { + if (nm_streq (value, line->line)) { + g_free (value_escaped); + return changed; + } + g_free (line->line); + } + + line->line = value_escaped ?: g_strdup (value); + ASSERT_shvarLine (line); + return TRUE; +} + +static void +line_free (shvarLine *line) +{ + ASSERT_shvarLine (line); + g_free (line->line); + g_free (line->key_with_prefix); + g_slice_free (shvarLine, line); +} + +/*****************************************************************************/ + +/* Open the file , returning a shvarFile on success and NULL on failure. + * Add a wrinkle to let the caller specify whether or not to create the file + * (actually, return a structure anyway) if it doesn't exist. */ -char * -svGetValue (shvarFile *s, const char *key, gboolean verbatim) +static shvarFile * +svOpenFileInternal (const char *name, gboolean create, GError **error) { - char *value; + shvarFile *s; + gboolean closefd = FALSE; + int errsv = 0; + char *arena; + const char *p, *q; + GError *local = NULL; + nm_auto_close int fd = -1; + GList *lineList = NULL; + + if (create) + fd = open (name, O_RDWR | O_CLOEXEC); /* NOT O_CREAT */ + if (fd < 0) { + /* try read-only */ + fd = open (name, O_RDONLY | O_CLOEXEC); /* NOT O_CREAT */ + if (fd < 0) + errsv = errno; + else + closefd = TRUE; + } - value = svGetValueFull (s, key, verbatim); - if (value && !*value) { - g_free (value); + if (fd < 0) { + if (create) + return svFile_new (name); + + g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errsv), + "Could not read file '%s': %s", + name, strerror (errsv)); return NULL; } - return value; + + if (nm_utils_fd_get_contents (fd, + 10 * 1024 * 1024, + &arena, + NULL, + &local) < 0) { + g_set_error (error, G_FILE_ERROR, + local->domain == G_FILE_ERROR ? local->code : G_FILE_ERROR_FAILED, + "Could not read file '%s': %s", + name, local->message); + g_error_free (local); + return NULL; + } + + for (p = arena; (q = strchr (p, '\n')) != NULL; p = q + 1) + lineList = g_list_prepend (lineList, line_new_parse (p, q - p)); + if (p[0]) + lineList = g_list_prepend (lineList, line_new_parse (p, strlen (p))); + g_free (arena); + lineList = g_list_reverse (lineList); + + s = svFile_new (name); + s->lineList = lineList; + + /* closefd is set if we opened the file read-only, so go ahead and + * close it, because we can't write to it anyway */ + if (!closefd) { + s->fd = fd; + fd = -1; + } + + return s; } -/* svGetValueFull() is identical to svGetValue() except that - * svGetValue() will never return an empty value (but %NULL instead). - * svGetValueFull() will return empty values if that is the value for the @key. */ -char * -svGetValueFull (shvarFile *s, const char *key, gboolean verbatim) +/* Open the file , return shvarFile on success, NULL on failure */ +shvarFile * +svOpenFile (const char *name, GError **error) { - char *value = NULL; - char *line; - guint len; + return svOpenFileInternal (name, FALSE, error); +} - g_return_val_if_fail (s != NULL, NULL); - g_return_val_if_fail (key != NULL, NULL); +/* Create a new file structure, returning actual data if the file exists, + * and a suitable starting point if it doesn't. + */ +shvarFile * +svCreateFile (const char *name) +{ + return svOpenFileInternal (name, TRUE, NULL); +} - len = strlen (key); +/*****************************************************************************/ - for (s->current = s->lineList; s->current; s->current = s->current->next) { - line = s->current->data; - if (!strncmp (key, line, len) && line[len] == '=') { - /* Strip trailing spaces before unescaping to preserve spaces quoted whitespace */ - value = g_strchomp (g_strdup (line + len + 1)); - if (!verbatim) - svUnescape (value); - break; - } +static const GList * +shlist_find (const GList *current, const char *key) +{ + nm_assert (_shell_is_name (key, -1)); + + if (current) { + do { + shvarLine *line = current->data; + + ASSERT_shvarLine (line); + if (line->key && nm_streq (line->key, key)) + return current; + current = current->next; + } while (current); + } + return NULL; +} + +/*****************************************************************************/ + +static const char * +_svGetValue (shvarFile *s, const char *key, char **to_free) +{ + const GList *current, *last; + const shvarLine *line; + + nm_assert (s); + nm_assert (_shell_is_name (key, -1)); + nm_assert (to_free); + + last = NULL; + current = s->lineList; + while ((current = shlist_find (current, key))) { + last = current; + current = current->next; + } + if (last) { + line = last->data; + if (line->line) + return svUnescape (line->line, to_free); } + *to_free = NULL; + return NULL; +} - return value; +const char * +svGetValue (shvarFile *s, const char *key, char **to_free) +{ + g_return_val_if_fail (s != NULL, NULL); + g_return_val_if_fail (key != NULL, NULL); + g_return_val_if_fail (to_free, NULL); + + return _svGetValue (s, key, to_free); } -/** - * svParseBoolean: - * @value: the input string - * @fallback: the fallback value - * - * Parses a string and returns the boolean value it contains or, - * in case no valid value is found, the fallback value. Valid values - * are: "yes", "true", "t", "y", "1" and "no", "false", "f", "n", "0". - * - * Returns: the parsed boolean value or @fallback. +/* Get the value associated with the key, and leave the current pointer + * pointing at the line containing the value. The char* returned MUST + * be freed by the caller. */ -gint -svParseBoolean (const char *value, gint fallback) +char * +svGetValueString (shvarFile *s, const char *key) { - if (!value) - return fallback; + char *to_free; + const char *value; - if ( !g_ascii_strcasecmp ("yes", value) - || !g_ascii_strcasecmp ("true", value) - || !g_ascii_strcasecmp ("t", value) - || !g_ascii_strcasecmp ("y", value) - || !g_ascii_strcasecmp ("1", value)) - return TRUE; - else if ( !g_ascii_strcasecmp ("no", value) - || !g_ascii_strcasecmp ("false", value) - || !g_ascii_strcasecmp ("f", value) - || !g_ascii_strcasecmp ("n", value) - || !g_ascii_strcasecmp ("0", value)) - return FALSE; - - return fallback; + value = _svGetValue (s, key, &to_free); + if (!value) { + nm_assert (!to_free); + return NULL; + } + if (!value[0]) { + nm_assert (!to_free); + return NULL; + } + return to_free ?: g_strdup (value); } /* svGetValueBoolean: @@ -337,10 +946,11 @@ svParseBoolean (const char *value, gint fallback) gint svGetValueBoolean (shvarFile *s, const char *key, gint fallback) { - gs_free char *tmp = NULL; + gs_free char *to_free = NULL; + const char *value; - tmp = svGetValue (s, key, FALSE); - return svParseBoolean (tmp, fallback); + value = _svGetValue (s, key, &to_free); + return svParseBoolean (value, fallback); } /* svGetValueInt64: @@ -356,97 +966,108 @@ svGetValueBoolean (shvarFile *s, const char *key, gint fallback) gint64 svGetValueInt64 (shvarFile *s, const char *key, guint base, gint64 min, gint64 max, gint64 fallback) { - char *tmp; + char *to_free; + const char *value; gint64 result; int errsv; - tmp = svGetValueFull (s, key, FALSE); - if (!tmp) { - errno = 0; + value = _svGetValue (s, key, &to_free); + if (!value) { + nm_assert (!to_free); + /* indicate that the key does not exist (or has a syntax error + * and svUnescape() failed). */ + errno = ENOKEY; return fallback; } - result = _nm_utils_ascii_str_to_int64 (tmp, base, min, max, fallback); - errsv = errno; - - g_free (tmp); - - errno = errsv; + result = _nm_utils_ascii_str_to_int64 (value, base, min, max, fallback); + if (to_free) { + errsv = errno; + g_free (to_free); + errno = errsv; + } return result; } -/* Set the variable equal to the value . - * If does not exist, and the pointer is set, append - * the key=value pair after that line. Otherwise, append the pair - * to the bottom of the file. - */ -void -svSetValue (shvarFile *s, const char *key, const char *value, gboolean verbatim) -{ - svSetValueFull (s, key, value && value[0] ? value : NULL, verbatim); -} +/*****************************************************************************/ -/* Same as svSetValue() but it preserves empty @value -- contrary to - * svSetValue() for which "" effectively means to remove the value. */ +/* Same as svSetValueString() but it preserves empty @value -- contrary to + * svSetValueString() for which "" effectively means to remove the value. */ void -svSetValueFull (shvarFile *s, const char *key, const char *value, gboolean verbatim) +svSetValue (shvarFile *s, const char *key, const char *value) { - gs_free char *newval_free = NULL; - gs_free char *oldval = NULL; - const char *newval; - char *keyValue; + GList *current, *last; g_return_if_fail (s != NULL); g_return_if_fail (key != NULL); - /* value may be NULL */ - - if (!value || verbatim) - newval = value; - else - newval = svEscape (value, &newval_free); - oldval = svGetValueFull (s, key, FALSE); - - if (!newval) { - /* delete value */ - if (oldval) { - /* delete line */ - s->lineList = g_list_remove_link (s->lineList, s->current); - g_free (s->current->data); - g_list_free_1 (s->current); + + nm_assert (_shell_is_name (key, -1)); + + last = NULL; + current = s->lineList; + while ((current = (GList *) shlist_find (current, key))) { + if (last) { + /* if we find multiple entries for the same key, we can + * delete all but the last. */ + line_free (last->data); + s->lineList = g_list_delete_link (s->lineList, last); s->modified = TRUE; } - return; + last = current; + current = current->next; } - keyValue = g_strdup_printf ("%s=%s", key, newval); - if (!oldval) { - /* append line */ - s->lineList = g_list_append (s->lineList, keyValue); - s->modified = TRUE; - return; + if (!value) { + if (last) { + shvarLine *line = last->data; + + if (nm_clear_g_free (&line->line)) + s->modified = TRUE; + } + } else { + if (!last) { + s->lineList = g_list_append (s->lineList, line_new_build (key, value)); + s->modified = TRUE; + } else { + if (line_set (last->data, value)) + s->modified = TRUE; + } } +} - if (strcmp (oldval, newval) != 0) { - /* change line */ - if (s->current) { - g_free (s->current->data); - s->current->data = keyValue; - } else - s->lineList = g_list_append (s->lineList, keyValue); - s->modified = TRUE; - } else - g_free (keyValue); +/* Set the variable equal to the value . + * If does not exist, and the pointer is set, append + * the key=value pair after that line. Otherwise, append the pair + * to the bottom of the file. + */ +void +svSetValueString (shvarFile *s, const char *key, const char *value) +{ + svSetValue (s, key, value && value[0] ? value : NULL); } void svSetValueInt64 (shvarFile *s, const char *key, gint64 value) { - gs_free char *v = NULL; + char buf[NM_DECIMAL_STR_MAX (value)]; + + svSetValue (s, key, nm_sprintf_buf (buf, "%"G_GINT64_FORMAT, value)); +} - v = g_strdup_printf ("%"G_GINT64_FORMAT, value); - svSetValueFull (s, key, v, TRUE); +void +svSetValueBoolean (shvarFile *s, const char *key, gboolean value) +{ + svSetValue (s, key, value ? "yes" : "no"); } +void +svUnsetValue (shvarFile *s, const char *key) +{ + svSetValue (s, key, NULL); +} + +/*****************************************************************************/ + /* Write the current contents iff modified. Returns FALSE on error * and TRUE on success. Do not write if no values have been modified. * The mode argument is only used if creating the file, not if @@ -458,6 +1079,7 @@ svWriteFile (shvarFile *s, int mode, GError **error) { FILE *f; int tmpfd; + const GList *current; if (s->modified) { if (s->fd == -1) @@ -490,9 +1112,36 @@ svWriteFile (shvarFile *s, int mode, GError **error) } f = fdopen (tmpfd, "w"); fseek (f, 0, SEEK_SET); - for (s->current = s->lineList; s->current; s->current = s->current->next) { - char *line = s->current->data; - fprintf (f, "%s\n", line); + for (current = s->lineList; current; current = current->next) { + const shvarLine *line = current->data; + const char *str; + char *s_tmp; + gboolean valid_value; + + ASSERT_shvarLine (line); + + if (!line->key) { + str = nm_str_skip_leading_spaces (line->line); + if (NM_IN_SET (str[0], '\0', '#')) + fprintf (f, "%s\n", line->line); + else + fprintf (f, "#NM: %s\n", line->line); + continue; + } + + if (!line->line) + continue; + + /* we check that the assignment can be properly unescaped. */ + valid_value = !!svUnescape (line->line, &s_tmp); + g_free (s_tmp); + + if (valid_value) + fprintf (f, "%s=%s\n", line->key_with_prefix, line->line); + else { + fprintf (f, "%s=\n", line->key); + fprintf (f, "#NM: %s=%s\n", line->key_with_prefix, line->line); + } } fclose (f); } @@ -500,8 +1149,6 @@ svWriteFile (shvarFile *s, int mode, GError **error) return TRUE; } - -/* Close the file descriptor (if open) and free the shvarFile. */ void svCloseFile (shvarFile *s) { @@ -509,8 +1156,7 @@ svCloseFile (shvarFile *s) if (s->fd != -1) close (s->fd); - g_free (s->fileName); - g_list_free_full (s->lineList, g_free); /* implicitly frees s->current */ + g_list_free_full (s->lineList, (GDestroyNotify) line_free); g_slice_free (shvarFile, s); } diff --git a/src/settings/plugins/ifcfg-rh/shvar.h b/src/settings/plugins/ifcfg-rh/shvar.h index 97df8128..a6498fce 100644 --- a/src/settings/plugins/ifcfg-rh/shvar.h +++ b/src/settings/plugins/ifcfg-rh/shvar.h @@ -32,14 +32,11 @@ #define _SHVAR_H typedef struct _shvarFile shvarFile; -struct _shvarFile { - char *fileName; /* read-only */ - int fd; /* read-only */ - GList *lineList; /* read-only */ - GList *current; /* set implicitly or explicitly, points to element of lineList */ - gboolean modified; /* ignore */ -}; +const char *svFileGetName (const shvarFile *s); +void svFileSetName (shvarFile *s, const char *fileName); + +void svFileSetModified (shvarFile *s); /* Create the file , return a shvarFile (never fails) */ shvarFile *svCreateFile (const char *name); @@ -51,8 +48,8 @@ shvarFile *svOpenFile (const char *name, GError **error); * pointing at the line containing the value. The char* returned MUST * be freed by the caller. */ -char *svGetValue (shvarFile *s, const char *key, gboolean verbatim); -char *svGetValueFull (shvarFile *s, const char *key, gboolean verbatim); +const char *svGetValue (shvarFile *s, const char *key, char **to_free); +char *svGetValueString (shvarFile *s, const char *key); gint svParseBoolean (const char *value, gint def); @@ -69,10 +66,12 @@ gint64 svGetValueInt64 (shvarFile *s, const char *key, guint base, gint64 min, g * the key=value pair after that line. Otherwise, prepend the pair * to the top of the file. */ -void svSetValue (shvarFile *s, const char *key, const char *value, gboolean verbatim); -void svSetValueFull (shvarFile *s, const char *key, const char *value, gboolean verbatim); +void svSetValueString (shvarFile *s, const char *key, const char *value); +void svSetValue (shvarFile *s, const char *key, const char *value); +void svSetValueBoolean (shvarFile *s, const char *key, gboolean value); void svSetValueInt64 (shvarFile *s, const char *key, gint64 value); +void svUnsetValue (shvarFile *s, const char *key); /* Write the current contents iff modified. Returns FALSE on error * and TRUE on success. Do not write if no values have been modified. @@ -85,10 +84,7 @@ gboolean svWriteFile (shvarFile *s, int mode, GError **error); /* Close the file descriptor (if open) and free the shvarFile. */ void svCloseFile (shvarFile *s); -/* Return @s unmodified or an escaped string */ const char *svEscape (const char *s, char **to_free); - -/* Unescape a string in-place */ -void svUnescape (char *s); +const char *svUnescape (const char *s, char **to_free); #endif /* _SHVAR_H */ diff --git a/src/settings/plugins/ifcfg-rh/tests/Makefile.am b/src/settings/plugins/ifcfg-rh/tests/Makefile.am deleted file mode 100644 index fedbd93f..00000000 --- a/src/settings/plugins/ifcfg-rh/tests/Makefile.am +++ /dev/null @@ -1,56 +0,0 @@ -if ENABLE_TESTS - -SUBDIRS=network-scripts - -@GNOME_CODE_COVERAGE_RULES@ - -AM_CPPFLAGS = \ - $(GLIB_CFLAGS) \ - $(CODE_COVERAGE_CFLAGS) \ - -I$(top_srcdir)/shared \ - -I$(top_builddir)/shared \ - -I$(top_srcdir)/libnm-core \ - -I$(top_builddir)/libnm-core \ - -I$(top_srcdir)/src/ \ - -I$(top_srcdir)/src/platform \ - -I$(top_srcdir)/src/settings \ - -I$(srcdir)/../ \ - -DG_LOG_DOMAIN=\""NetworkManager-ifcfg-rh"\" \ - -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \ - -DTEST_IFCFG_DIR=\"$(abs_srcdir)\" \ - -DTEST_SCRATCH_DIR=\"$(abs_builddir)/\" \ - -DSYSCONFDIR=\"nonexistent\" \ - -DSBINDIR=\"nonexistent\" - -AM_LDFLAGS = \ - $(GLIB_LIBS) \ - $(CODE_COVERAGE_LDFLAGS) - -noinst_PROGRAMS = test-ifcfg-rh test-ifcfg-rh-utils - -test_ifcfg_rh_SOURCES = \ - test-ifcfg-rh.c \ - ../reader.c \ - ../shvar.c \ - ../utils.c \ - ../writer.c - -test_ifcfg_rh_LDADD = \ - $(top_builddir)/src/libNetworkManager.la - -test_ifcfg_rh_utils_SOURCES = \ - test-ifcfg-rh-utils.c \ - ../utils.c \ - ../shvar.c - -test_ifcfg_rh_utils_LDADD = \ - $(top_builddir)/src/libNetworkManager.la - -@VALGRIND_RULES@ -TESTS = test-ifcfg-rh-utils test-ifcfg-rh - -check-local: - LD_BIND_NOW=1 LD_PRELOAD=$(builddir)/../.libs/libnm-settings-plugin-ifcfg-rh.so $(top_builddir)/src/NetworkManager --version >/dev/null - -endif - diff --git a/src/settings/plugins/ifcfg-rh/tests/Makefile.in b/src/settings/plugins/ifcfg-rh/tests/Makefile.in deleted file mode 100644 index f2ce157b..00000000 --- a/src/settings/plugins/ifcfg-rh/tests/Makefile.in +++ /dev/null @@ -1,1371 +0,0 @@ -# Makefile.in generated by automake 1.15 from Makefile.am. -# @configure_input@ - -# Copyright (C) 1994-2014 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@ -am__is_gnu_make = { \ - if test -z '$(MAKELEVEL)'; then \ - false; \ - elif test -n '$(MAKE_HOST)'; then \ - true; \ - elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \ - true; \ - else \ - false; \ - fi; \ -} -am__make_running_with_option = \ - case $${target_option-} in \ - ?) ;; \ - *) echo "am__make_running_with_option: internal error: invalid" \ - "target option '$${target_option-}' specified" >&2; \ - exit 1;; \ - esac; \ - has_opt=no; \ - sane_makeflags=$$MAKEFLAGS; \ - if $(am__is_gnu_make); then \ - sane_makeflags=$$MFLAGS; \ - else \ - case $$MAKEFLAGS in \ - *\\[\ \ ]*) \ - bs=\\; \ - sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \ - | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \ - esac; \ - fi; \ - skip_next=no; \ - strip_trailopt () \ - { \ - flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \ - }; \ - for flg in $$sane_makeflags; do \ - test $$skip_next = yes && { skip_next=no; continue; }; \ - case $$flg in \ - *=*|--*) continue;; \ - -*I) strip_trailopt 'I'; skip_next=yes;; \ - -*I?*) strip_trailopt 'I';; \ - -*O) strip_trailopt 'O'; skip_next=yes;; \ - -*O?*) strip_trailopt 'O';; \ - -*l) strip_trailopt 'l'; skip_next=yes;; \ - -*l?*) strip_trailopt 'l';; \ - -[dEDm]) skip_next=yes;; \ - -[JT]) skip_next=yes;; \ - esac; \ - case $$flg in \ - *$$target_option*) has_opt=yes; break;; \ - esac; \ - done; \ - test $$has_opt = yes -am__make_dryrun = (target_option=n; $(am__make_running_with_option)) -am__make_keepgoing = (target_option=k; $(am__make_running_with_option)) -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@ -@ENABLE_TESTS_TRUE@noinst_PROGRAMS = test-ifcfg-rh$(EXEEXT) \ -@ENABLE_TESTS_TRUE@ test-ifcfg-rh-utils$(EXEEXT) -@ENABLE_TESTS_TRUE@TESTS = test-ifcfg-rh-utils$(EXEEXT) \ -@ENABLE_TESTS_TRUE@ test-ifcfg-rh$(EXEEXT) -subdir = src/settings/plugins/ifcfg-rh/tests -ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 -am__aclocal_m4_deps = $(top_srcdir)/m4/attributes.m4 \ - $(top_srcdir)/m4/ax_lib_readline.m4 \ - $(top_srcdir)/m4/compiler_options.m4 \ - $(top_srcdir)/m4/gettext.m4 $(top_srcdir)/m4/git-sha-record.m4 \ - $(top_srcdir)/m4/gnome-code-coverage.m4 \ - $(top_srcdir)/m4/gtk-doc.m4 $(top_srcdir)/m4/iconv.m4 \ - $(top_srcdir)/m4/intlmacosx.m4 $(top_srcdir)/m4/intltool.m4 \ - $(top_srcdir)/m4/introspection.m4 $(top_srcdir)/m4/lib-ld.m4 \ - $(top_srcdir)/m4/lib-link.m4 $(top_srcdir)/m4/lib-prefix.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)/m4/nls.m4 \ - $(top_srcdir)/m4/po.m4 $(top_srcdir)/m4/progtest.m4 \ - $(top_srcdir)/m4/vapigen.m4 $(top_srcdir)/configure.ac -am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ - $(ACLOCAL_M4) -DIST_COMMON = $(srcdir)/Makefile.am $(am__DIST_COMMON) -mkinstalldirs = $(install_sh) -d -CONFIG_HEADER = $(top_builddir)/config.h -CONFIG_CLEAN_FILES = -CONFIG_CLEAN_VPATH_FILES = -PROGRAMS = $(noinst_PROGRAMS) -am__test_ifcfg_rh_SOURCES_DIST = test-ifcfg-rh.c ../reader.c \ - ../shvar.c ../utils.c ../writer.c -@ENABLE_TESTS_TRUE@am_test_ifcfg_rh_OBJECTS = test-ifcfg-rh.$(OBJEXT) \ -@ENABLE_TESTS_TRUE@ reader.$(OBJEXT) shvar.$(OBJEXT) \ -@ENABLE_TESTS_TRUE@ utils.$(OBJEXT) writer.$(OBJEXT) -test_ifcfg_rh_OBJECTS = $(am_test_ifcfg_rh_OBJECTS) -@ENABLE_TESTS_TRUE@test_ifcfg_rh_DEPENDENCIES = \ -@ENABLE_TESTS_TRUE@ $(top_builddir)/src/libNetworkManager.la -AM_V_lt = $(am__v_lt_@AM_V@) -am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) -am__v_lt_0 = --silent -am__v_lt_1 = -am__test_ifcfg_rh_utils_SOURCES_DIST = test-ifcfg-rh-utils.c \ - ../utils.c ../shvar.c -@ENABLE_TESTS_TRUE@am_test_ifcfg_rh_utils_OBJECTS = \ -@ENABLE_TESTS_TRUE@ test-ifcfg-rh-utils.$(OBJEXT) \ -@ENABLE_TESTS_TRUE@ utils.$(OBJEXT) shvar.$(OBJEXT) -test_ifcfg_rh_utils_OBJECTS = $(am_test_ifcfg_rh_utils_OBJECTS) -@ENABLE_TESTS_TRUE@test_ifcfg_rh_utils_DEPENDENCIES = \ -@ENABLE_TESTS_TRUE@ $(top_builddir)/src/libNetworkManager.la -AM_V_P = $(am__v_P_@AM_V@) -am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) -am__v_P_0 = false -am__v_P_1 = : -AM_V_GEN = $(am__v_GEN_@AM_V@) -am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@) -am__v_GEN_0 = @echo " GEN " $@; -am__v_GEN_1 = -AM_V_at = $(am__v_at_@AM_V@) -am__v_at_ = $(am__v_at_@AM_DEFAULT_V@) -am__v_at_0 = @ -am__v_at_1 = -DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) -depcomp = $(SHELL) $(top_srcdir)/build-aux/depcomp -am__depfiles_maybe = depfiles -am__mv = mv -f -COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ - $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ - $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \ - $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ - $(AM_CFLAGS) $(CFLAGS) -AM_V_CC = $(am__v_CC_@AM_V@) -am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@) -am__v_CC_0 = @echo " CC " $@; -am__v_CC_1 = -CCLD = $(CC) -LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ - $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ - $(AM_LDFLAGS) $(LDFLAGS) -o $@ -AM_V_CCLD = $(am__v_CCLD_@AM_V@) -am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@) -am__v_CCLD_0 = @echo " CCLD " $@; -am__v_CCLD_1 = -SOURCES = $(test_ifcfg_rh_SOURCES) $(test_ifcfg_rh_utils_SOURCES) -DIST_SOURCES = $(am__test_ifcfg_rh_SOURCES_DIST) \ - $(am__test_ifcfg_rh_utils_SOURCES_DIST) -RECURSIVE_TARGETS = all-recursive check-recursive cscopelist-recursive \ - ctags-recursive dvi-recursive html-recursive info-recursive \ - install-data-recursive install-dvi-recursive \ - install-exec-recursive install-html-recursive \ - install-info-recursive install-pdf-recursive \ - install-ps-recursive install-recursive installcheck-recursive \ - installdirs-recursive pdf-recursive ps-recursive \ - tags-recursive uninstall-recursive -am__can_run_installinfo = \ - case $$AM_UPDATE_INFO_DIR in \ - n|no|NO) false;; \ - *) (install-info --version) >/dev/null 2>&1;; \ - esac -RECURSIVE_CLEAN_TARGETS = mostlyclean-recursive clean-recursive \ - distclean-recursive maintainer-clean-recursive -am__recursive_targets = \ - $(RECURSIVE_TARGETS) \ - $(RECURSIVE_CLEAN_TARGETS) \ - $(am__extra_recursive_targets) -AM_RECURSIVE_TARGETS = $(am__recursive_targets:-recursive=) TAGS CTAGS \ - check recheck distdir -am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) -# Read a list of newline-separated strings from the standard input, -# and print each of them once, without duplicates. Input order is -# *not* preserved. -am__uniquify_input = $(AWK) '\ - BEGIN { nonempty = 0; } \ - { items[$$0] = 1; nonempty = 1; } \ - END { if (nonempty) { for (i in items) print i; }; } \ -' -# Make sure the list of sources is unique. This is necessary because, -# e.g., the same source file might be shared among _SOURCES variables -# for different programs/libraries. -am__define_uniq_tagged_files = \ - list='$(am__tagged_files)'; \ - unique=`for i in $$list; do \ - if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ - done | $(am__uniquify_input)` -ETAGS = etags -CTAGS = ctags -am__tty_colors_dummy = \ - mgn= red= grn= lgn= blu= brg= std=; \ - am__color_tests=no -am__tty_colors = { \ - $(am__tty_colors_dummy); \ - if test "X$(AM_COLOR_TESTS)" = Xno; then \ - am__color_tests=no; \ - elif test "X$(AM_COLOR_TESTS)" = Xalways; then \ - am__color_tests=yes; \ - elif test "X$$TERM" != Xdumb && { test -t 1; } 2>/dev/null; then \ - am__color_tests=yes; \ - fi; \ - if test $$am__color_tests = yes; then \ - red=''; \ - grn=''; \ - lgn=''; \ - blu=''; \ - mgn=''; \ - brg=''; \ - std=''; \ - fi; \ -} -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__uninstall_files_from_dir = { \ - test -z "$$files" \ - || { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \ - || { echo " ( cd '$$dir' && rm -f" $$files ")"; \ - $(am__cd) "$$dir" && rm -f $$files; }; \ - } -am__recheck_rx = ^[ ]*:recheck:[ ]* -am__global_test_result_rx = ^[ ]*:global-test-result:[ ]* -am__copy_in_global_log_rx = ^[ ]*:copy-in-global-log:[ ]* -# A command that, given a newline-separated list of test names on the -# standard input, print the name of the tests that are to be re-run -# upon "make recheck". -am__list_recheck_tests = $(AWK) '{ \ - recheck = 1; \ - while ((rc = (getline line < ($$0 ".trs"))) != 0) \ - { \ - if (rc < 0) \ - { \ - if ((getline line2 < ($$0 ".log")) < 0) \ - recheck = 0; \ - break; \ - } \ - else if (line ~ /$(am__recheck_rx)[nN][Oo]/) \ - { \ - recheck = 0; \ - break; \ - } \ - else if (line ~ /$(am__recheck_rx)[yY][eE][sS]/) \ - { \ - break; \ - } \ - }; \ - if (recheck) \ - print $$0; \ - close ($$0 ".trs"); \ - close ($$0 ".log"); \ -}' -# A command that, given a newline-separated list of test names on the -# standard input, create the global log from their .trs and .log files. -am__create_global_log = $(AWK) ' \ -function fatal(msg) \ -{ \ - print "fatal: making $@: " msg | "cat >&2"; \ - exit 1; \ -} \ -function rst_section(header) \ -{ \ - print header; \ - len = length(header); \ - for (i = 1; i <= len; i = i + 1) \ - printf "="; \ - printf "\n\n"; \ -} \ -{ \ - copy_in_global_log = 1; \ - global_test_result = "RUN"; \ - while ((rc = (getline line < ($$0 ".trs"))) != 0) \ - { \ - if (rc < 0) \ - fatal("failed to read from " $$0 ".trs"); \ - if (line ~ /$(am__global_test_result_rx)/) \ - { \ - sub("$(am__global_test_result_rx)", "", line); \ - sub("[ ]*$$", "", line); \ - global_test_result = line; \ - } \ - else if (line ~ /$(am__copy_in_global_log_rx)[nN][oO]/) \ - copy_in_global_log = 0; \ - }; \ - if (copy_in_global_log) \ - { \ - rst_section(global_test_result ": " $$0); \ - while ((rc = (getline line < ($$0 ".log"))) != 0) \ - { \ - if (rc < 0) \ - fatal("failed to read from " $$0 ".log"); \ - print line; \ - }; \ - printf "\n"; \ - }; \ - close ($$0 ".trs"); \ - close ($$0 ".log"); \ -}' -# Restructured Text title. -am__rst_title = { sed 's/.*/ & /;h;s/./=/g;p;x;s/ *$$//;p;g' && echo; } -# Solaris 10 'make', and several other traditional 'make' implementations, -# pass "-e" to $(SHELL), and POSIX 2008 even requires this. Work around it -# by disabling -e (using the XSI extension "set +e") if it's set. -am__sh_e_setup = case $$- in *e*) set +e;; esac -# Default flags passed to test drivers. -am__common_driver_flags = \ - --color-tests "$$am__color_tests" \ - --enable-hard-errors "$$am__enable_hard_errors" \ - --expect-failure "$$am__expect_failure" -# To be inserted before the command running the test. Creates the -# directory for the log if needed. Stores in $dir the directory -# containing $f, in $tst the test, in $log the log. Executes the -# developer- defined test setup AM_TESTS_ENVIRONMENT (if any), and -# passes TESTS_ENVIRONMENT. Set up options for the wrapper that -# will run the test scripts (or their associated LOG_COMPILER, if -# thy have one). -am__check_pre = \ -$(am__sh_e_setup); \ -$(am__vpath_adj_setup) $(am__vpath_adj) \ -$(am__tty_colors); \ -srcdir=$(srcdir); export srcdir; \ -case "$@" in \ - */*) am__odir=`echo "./$@" | sed 's|/[^/]*$$||'`;; \ - *) am__odir=.;; \ -esac; \ -test "x$$am__odir" = x"." || test -d "$$am__odir" \ - || $(MKDIR_P) "$$am__odir" || exit $$?; \ -if test -f "./$$f"; then dir=./; \ -elif test -f "$$f"; then dir=; \ -else dir="$(srcdir)/"; fi; \ -tst=$$dir$$f; log='$@'; \ -if test -n '$(DISABLE_HARD_ERRORS)'; then \ - am__enable_hard_errors=no; \ -else \ - am__enable_hard_errors=yes; \ -fi; \ -case " $(XFAIL_TESTS) " in \ - *[\ \ ]$$f[\ \ ]* | *[\ \ ]$$dir$$f[\ \ ]*) \ - am__expect_failure=yes;; \ - *) \ - am__expect_failure=no;; \ -esac; \ -$(AM_TESTS_ENVIRONMENT) $(TESTS_ENVIRONMENT) -# A shell command to get the names of the tests scripts with any registered -# extension removed (i.e., equivalently, the names of the test logs, with -# the '.log' extension removed). The result is saved in the shell variable -# '$bases'. This honors runtime overriding of TESTS and TEST_LOGS. Sadly, -# we cannot use something simpler, involving e.g., "$(TEST_LOGS:.log=)", -# since that might cause problem with VPATH rewrites for suffix-less tests. -# See also 'test-harness-vpath-rewrite.sh' and 'test-trs-basic.sh'. -am__set_TESTS_bases = \ - bases='$(TEST_LOGS)'; \ - bases=`for i in $$bases; do echo $$i; done | sed 's/\.log$$//'`; \ - bases=`echo $$bases` -RECHECK_LOGS = $(TEST_LOGS) -TEST_SUITE_LOG = test-suite.log -TEST_EXTENSIONS = @EXEEXT@ .test -LOG_COMPILE = $(LOG_COMPILER) $(AM_LOG_FLAGS) $(LOG_FLAGS) -am__set_b = \ - case '$@' in \ - */*) \ - case '$*' in \ - */*) b='$*';; \ - *) b=`echo '$@' | sed 's/\.log$$//'`; \ - esac;; \ - *) \ - b='$*';; \ - esac -am__test_logs1 = $(TESTS:=.log) -am__test_logs2 = $(am__test_logs1:@EXEEXT@.log=.log) -TEST_LOGS = $(am__test_logs2:.test.log=.log) -TEST_LOG_DRIVER = $(SHELL) $(top_srcdir)/build-aux/test-driver -TEST_LOG_COMPILE = $(TEST_LOG_COMPILER) $(AM_TEST_LOG_FLAGS) \ - $(TEST_LOG_FLAGS) -DIST_SUBDIRS = network-scripts -am__DIST_COMMON = $(srcdir)/Makefile.in \ - $(top_srcdir)/build-aux/depcomp \ - $(top_srcdir)/build-aux/test-driver -DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) -am__relativize = \ - dir0=`pwd`; \ - sed_first='s,^\([^/]*\)/.*$$,\1,'; \ - sed_rest='s,^[^/]*/*,,'; \ - sed_last='s,^.*/\([^/]*\)$$,\1,'; \ - sed_butlast='s,/*[^/]*$$,,'; \ - while test -n "$$dir1"; do \ - first=`echo "$$dir1" | sed -e "$$sed_first"`; \ - if test "$$first" != "."; then \ - if test "$$first" = ".."; then \ - dir2=`echo "$$dir0" | sed -e "$$sed_last"`/"$$dir2"; \ - dir0=`echo "$$dir0" | sed -e "$$sed_butlast"`; \ - else \ - first2=`echo "$$dir2" | sed -e "$$sed_first"`; \ - if test "$$first2" = "$$first"; then \ - dir2=`echo "$$dir2" | sed -e "$$sed_rest"`; \ - else \ - dir2="../$$dir2"; \ - fi; \ - dir0="$$dir0"/"$$first"; \ - fi; \ - fi; \ - dir1=`echo "$$dir1" | sed -e "$$sed_rest"`; \ - done; \ - reldir="$$dir2" -ACLOCAL = @ACLOCAL@ -ALL_LINGUAS = @ALL_LINGUAS@ -AMTAR = @AMTAR@ -AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ -AM_TESTS_FD_REDIRECT = @AM_TESTS_FD_REDIRECT@ -AR = @AR@ -AUTOCONF = @AUTOCONF@ -AUTOHEADER = @AUTOHEADER@ -AUTOMAKE = @AUTOMAKE@ -AWK = @AWK@ -BLUEZ5_CFLAGS = @BLUEZ5_CFLAGS@ -BLUEZ5_LIBS = @BLUEZ5_LIBS@ -CC = @CC@ -CCDEPMODE = @CCDEPMODE@ -CFLAGS = @CFLAGS@ -CODE_COVERAGE_CFLAGS = @CODE_COVERAGE_CFLAGS@ -CODE_COVERAGE_ENABLED = @CODE_COVERAGE_ENABLED@ -CODE_COVERAGE_LDFLAGS = @CODE_COVERAGE_LDFLAGS@ -CPP = @CPP@ -CPPFLAGS = @CPPFLAGS@ -CXX = @CXX@ -CXXCPP = @CXXCPP@ -CXXDEPMODE = @CXXDEPMODE@ -CXXFLAGS = @CXXFLAGS@ -CYGPATH_W = @CYGPATH_W@ -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@ -DISTRO_NETWORK_SERVICE = @DISTRO_NETWORK_SERVICE@ -DLLTOOL = @DLLTOOL@ -DL_LIBS = @DL_LIBS@ -DNSMASQ_PATH = @DNSMASQ_PATH@ -DNSSEC_TRIGGER_SCRIPT = @DNSSEC_TRIGGER_SCRIPT@ -DSYMUTIL = @DSYMUTIL@ -DUMPBIN = @DUMPBIN@ -ECHO_C = @ECHO_C@ -ECHO_N = @ECHO_N@ -ECHO_T = @ECHO_T@ -EGREP = @EGREP@ -EXEEXT = @EXEEXT@ -FGREP = @FGREP@ -GENHTML = @GENHTML@ -GETTEXT_MACRO_VERSION = @GETTEXT_MACRO_VERSION@ -GETTEXT_PACKAGE = @GETTEXT_PACKAGE@ -GLIB_CFLAGS = @GLIB_CFLAGS@ -GLIB_GENMARSHAL = @GLIB_GENMARSHAL@ -GLIB_LIBS = @GLIB_LIBS@ -GLIB_MAKEFILE = @GLIB_MAKEFILE@ -GLIB_MKENUMS = @GLIB_MKENUMS@ -GMSGFMT = @GMSGFMT@ -GMSGFMT_015 = @GMSGFMT_015@ -GNUTLS_CFLAGS = @GNUTLS_CFLAGS@ -GNUTLS_LIBS = @GNUTLS_LIBS@ -GREP = @GREP@ -GTKDOC_CHECK = @GTKDOC_CHECK@ -GTKDOC_CHECK_PATH = @GTKDOC_CHECK_PATH@ -GTKDOC_DEPS_CFLAGS = @GTKDOC_DEPS_CFLAGS@ -GTKDOC_DEPS_LIBS = @GTKDOC_DEPS_LIBS@ -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@ -INTLLIBS = @INTLLIBS@ -INTLTOOL_EXTRACT = @INTLTOOL_EXTRACT@ -INTLTOOL_MERGE = @INTLTOOL_MERGE@ -INTLTOOL_PERL = @INTLTOOL_PERL@ -INTLTOOL_UPDATE = @INTLTOOL_UPDATE@ -INTLTOOL_V_MERGE = @INTLTOOL_V_MERGE@ -INTLTOOL_V_MERGE_OPTIONS = @INTLTOOL_V_MERGE_OPTIONS@ -INTLTOOL__v_MERGE_ = @INTLTOOL__v_MERGE_@ -INTLTOOL__v_MERGE_0 = @INTLTOOL__v_MERGE_0@ -INTL_MACOSX_LIBS = @INTL_MACOSX_LIBS@ -INTROSPECTION_CFLAGS = @INTROSPECTION_CFLAGS@ -INTROSPECTION_COMPILER = @INTROSPECTION_COMPILER@ -INTROSPECTION_GENERATE = @INTROSPECTION_GENERATE@ -INTROSPECTION_GIRDIR = @INTROSPECTION_GIRDIR@ -INTROSPECTION_LIBS = @INTROSPECTION_LIBS@ -INTROSPECTION_MAKEFILE = @INTROSPECTION_MAKEFILE@ -INTROSPECTION_SCANNER = @INTROSPECTION_SCANNER@ -INTROSPECTION_TYPELIBDIR = @INTROSPECTION_TYPELIBDIR@ -IPTABLES_PATH = @IPTABLES_PATH@ -JANSSON_CFLAGS = @JANSSON_CFLAGS@ -JANSSON_LIBS = @JANSSON_LIBS@ -KERNEL_FIRMWARE_DIR = @KERNEL_FIRMWARE_DIR@ -LCOV = @LCOV@ -LD = @LD@ -LDFLAGS = @LDFLAGS@ -LIBAUDIT_CFLAGS = @LIBAUDIT_CFLAGS@ -LIBAUDIT_LIBS = @LIBAUDIT_LIBS@ -LIBICONV = @LIBICONV@ -LIBINTL = @LIBINTL@ -LIBM = @LIBM@ -LIBNDP_CFLAGS = @LIBNDP_CFLAGS@ -LIBNDP_LIBS = @LIBNDP_LIBS@ -LIBNL_CFLAGS = @LIBNL_CFLAGS@ -LIBNL_LIBS = @LIBNL_LIBS@ -LIBOBJS = @LIBOBJS@ -LIBS = @LIBS@ -LIBSOUP_CFLAGS = @LIBSOUP_CFLAGS@ -LIBSOUP_LIBS = @LIBSOUP_LIBS@ -LIBSYSTEMD_CFLAGS = @LIBSYSTEMD_CFLAGS@ -LIBSYSTEMD_LIBS = @LIBSYSTEMD_LIBS@ -LIBTEAMDCTL_CFLAGS = @LIBTEAMDCTL_CFLAGS@ -LIBTEAMDCTL_LIBS = @LIBTEAMDCTL_LIBS@ -LIBTOOL = @LIBTOOL@ -LIPO = @LIPO@ -LN_S = @LN_S@ -LOG_DRIVER = @LOG_DRIVER@ -LTLIBICONV = @LTLIBICONV@ -LTLIBINTL = @LTLIBINTL@ -LTLIBOBJS = @LTLIBOBJS@ -LT_SYS_LIBRARY_PATH = @LT_SYS_LIBRARY_PATH@ -MAINT = @MAINT@ -MAKEINFO = @MAKEINFO@ -MANIFEST_TOOL = @MANIFEST_TOOL@ -MKDIR_P = @MKDIR_P@ -MM_GLIB_CFLAGS = @MM_GLIB_CFLAGS@ -MM_GLIB_LIBS = @MM_GLIB_LIBS@ -MOC = @MOC@ -MSGFMT = @MSGFMT@ -MSGFMT_015 = @MSGFMT_015@ -MSGMERGE = @MSGMERGE@ -NEWT_CFLAGS = @NEWT_CFLAGS@ -NEWT_LIBS = @NEWT_LIBS@ -NM = @NM@ -NMEDIT = @NMEDIT@ -NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT = @NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT@ -NM_CONFIG_DEFAULT_DNS_RC_MANAGER = @NM_CONFIG_DEFAULT_DNS_RC_MANAGER@ -NM_CONFIG_DEFAULT_LOGGING_AUDIT_TEXT = @NM_CONFIG_DEFAULT_LOGGING_AUDIT_TEXT@ -NM_CONFIG_LOGGING_BACKEND_DEFAULT_TEXT = @NM_CONFIG_LOGGING_BACKEND_DEFAULT_TEXT@ -NM_MAJOR_VERSION = @NM_MAJOR_VERSION@ -NM_MICRO_VERSION = @NM_MICRO_VERSION@ -NM_MINOR_VERSION = @NM_MINOR_VERSION@ -NM_MODIFY_SYSTEM_POLICY = @NM_MODIFY_SYSTEM_POLICY@ -NM_VERSION = @NM_VERSION@ -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@ -PERL = @PERL@ -PKG_CONFIG = @PKG_CONFIG@ -PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ -PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ -POLKIT_CFLAGS = @POLKIT_CFLAGS@ -POLKIT_LIBS = @POLKIT_LIBS@ -POSUB = @POSUB@ -PPPD_PATH = @PPPD_PATH@ -PPPD_PLUGIN_DIR = @PPPD_PLUGIN_DIR@ -QT_CFLAGS = @QT_CFLAGS@ -QT_LIBS = @QT_LIBS@ -RANLIB = @RANLIB@ -READLINE_LIBS = @READLINE_LIBS@ -SANITIZERS = @SANITIZERS@ -SANITIZER_ENV = @SANITIZER_ENV@ -SED = @SED@ -SELINUX_CFLAGS = @SELINUX_CFLAGS@ -SELINUX_LIBS = @SELINUX_LIBS@ -SET_MAKE = @SET_MAKE@ -SHELL = @SHELL@ -STRIP = @STRIP@ -SYSTEMD_200_CFLAGS = @SYSTEMD_200_CFLAGS@ -SYSTEMD_200_LIBS = @SYSTEMD_200_LIBS@ -SYSTEMD_INHIBIT_CFLAGS = @SYSTEMD_INHIBIT_CFLAGS@ -SYSTEMD_INHIBIT_LIBS = @SYSTEMD_INHIBIT_LIBS@ -SYSTEMD_JOURNAL_CFLAGS = @SYSTEMD_JOURNAL_CFLAGS@ -SYSTEMD_JOURNAL_LIBS = @SYSTEMD_JOURNAL_LIBS@ -SYSTEMD_LOGIN_CFLAGS = @SYSTEMD_LOGIN_CFLAGS@ -SYSTEMD_LOGIN_LIBS = @SYSTEMD_LOGIN_LIBS@ -SYSTEM_CA_PATH = @SYSTEM_CA_PATH@ -UDEV_DIR = @UDEV_DIR@ -USE_NLS = @USE_NLS@ -UUID_CFLAGS = @UUID_CFLAGS@ -UUID_LIBS = @UUID_LIBS@ -VALGRIND_RULES = @VALGRIND_RULES@ -VAPIGEN = @VAPIGEN@ -VAPIGEN_MAKEFILE = @VAPIGEN_MAKEFILE@ -VAPIGEN_VAPIDIR = @VAPIGEN_VAPIDIR@ -VERSION = @VERSION@ -XGETTEXT = @XGETTEXT@ -XGETTEXT_015 = @XGETTEXT_015@ -XGETTEXT_EXTRA_OPTIONS = @XGETTEXT_EXTRA_OPTIONS@ -abs_builddir = @abs_builddir@ -abs_srcdir = @abs_srcdir@ -abs_top_builddir = @abs_top_builddir@ -abs_top_srcdir = @abs_top_srcdir@ -ac_ct_AR = @ac_ct_AR@ -ac_ct_CC = @ac_ct_CC@ -ac_ct_CXX = @ac_ct_CXX@ -ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ -ac_ct_RANLIB = @ac_ct_RANLIB@ -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@ -intltool__v_merge_options_ = @intltool__v_merge_options_@ -intltool__v_merge_options_0 = @intltool__v_merge_options_0@ -libdir = @libdir@ -libexecdir = @libexecdir@ -localedir = @localedir@ -localstatedir = @localstatedir@ -mandir = @mandir@ -mkdir_p = @mkdir_p@ -nmbinary = @nmbinary@ -nmconfdir = @nmconfdir@ -nmdatadir = @nmdatadir@ -nmlibdir = @nmlibdir@ -nmrundir = @nmrundir@ -nmstatedir = @nmstatedir@ -oldincludedir = @oldincludedir@ -pdfdir = @pdfdir@ -prefix = @prefix@ -program_transform_name = @program_transform_name@ -psdir = @psdir@ -runstatedir = @runstatedir@ -sbindir = @sbindir@ -sharedstatedir = @sharedstatedir@ -srcdir = @srcdir@ -subdirs = @subdirs@ -sysconfdir = @sysconfdir@ -systemdsystemunitdir = @systemdsystemunitdir@ -target_alias = @target_alias@ -top_build_prefix = @top_build_prefix@ -top_builddir = @top_builddir@ -top_srcdir = @top_srcdir@ -with_dhclient = @with_dhclient@ -with_dhcpcd = @with_dhcpcd@ -with_netconfig = @with_netconfig@ -with_resolvconf = @with_resolvconf@ -with_valgrind = @with_valgrind@ -@ENABLE_TESTS_TRUE@SUBDIRS = network-scripts -@ENABLE_TESTS_TRUE@AM_CPPFLAGS = \ -@ENABLE_TESTS_TRUE@ $(GLIB_CFLAGS) \ -@ENABLE_TESTS_TRUE@ $(CODE_COVERAGE_CFLAGS) \ -@ENABLE_TESTS_TRUE@ -I$(top_srcdir)/shared \ -@ENABLE_TESTS_TRUE@ -I$(top_builddir)/shared \ -@ENABLE_TESTS_TRUE@ -I$(top_srcdir)/libnm-core \ -@ENABLE_TESTS_TRUE@ -I$(top_builddir)/libnm-core \ -@ENABLE_TESTS_TRUE@ -I$(top_srcdir)/src/ \ -@ENABLE_TESTS_TRUE@ -I$(top_srcdir)/src/platform \ -@ENABLE_TESTS_TRUE@ -I$(top_srcdir)/src/settings \ -@ENABLE_TESTS_TRUE@ -I$(srcdir)/../ \ -@ENABLE_TESTS_TRUE@ -DG_LOG_DOMAIN=\""NetworkManager-ifcfg-rh"\" \ -@ENABLE_TESTS_TRUE@ -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \ -@ENABLE_TESTS_TRUE@ -DTEST_IFCFG_DIR=\"$(abs_srcdir)\" \ -@ENABLE_TESTS_TRUE@ -DTEST_SCRATCH_DIR=\"$(abs_builddir)/\" \ -@ENABLE_TESTS_TRUE@ -DSYSCONFDIR=\"nonexistent\" \ -@ENABLE_TESTS_TRUE@ -DSBINDIR=\"nonexistent\" - -@ENABLE_TESTS_TRUE@AM_LDFLAGS = \ -@ENABLE_TESTS_TRUE@ $(GLIB_LIBS) \ -@ENABLE_TESTS_TRUE@ $(CODE_COVERAGE_LDFLAGS) - -@ENABLE_TESTS_TRUE@test_ifcfg_rh_SOURCES = \ -@ENABLE_TESTS_TRUE@ test-ifcfg-rh.c \ -@ENABLE_TESTS_TRUE@ ../reader.c \ -@ENABLE_TESTS_TRUE@ ../shvar.c \ -@ENABLE_TESTS_TRUE@ ../utils.c \ -@ENABLE_TESTS_TRUE@ ../writer.c - -@ENABLE_TESTS_TRUE@test_ifcfg_rh_LDADD = \ -@ENABLE_TESTS_TRUE@ $(top_builddir)/src/libNetworkManager.la - -@ENABLE_TESTS_TRUE@test_ifcfg_rh_utils_SOURCES = \ -@ENABLE_TESTS_TRUE@ test-ifcfg-rh-utils.c \ -@ENABLE_TESTS_TRUE@ ../utils.c \ -@ENABLE_TESTS_TRUE@ ../shvar.c - -@ENABLE_TESTS_TRUE@test_ifcfg_rh_utils_LDADD = \ -@ENABLE_TESTS_TRUE@ $(top_builddir)/src/libNetworkManager.la - -all: all-recursive - -.SUFFIXES: -.SUFFIXES: .c .lo .log .o .obj .test .test$(EXEEXT) .trs -$(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/settings/plugins/ifcfg-rh/tests/Makefile'; \ - $(am__cd) $(top_srcdir) && \ - $(AUTOMAKE) --gnu src/settings/plugins/ifcfg-rh/tests/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-noinstPROGRAMS: - @list='$(noinst_PROGRAMS)'; test -n "$$list" || exit 0; \ - echo " rm -f" $$list; \ - rm -f $$list || exit $$?; \ - test -n "$(EXEEXT)" || exit 0; \ - list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \ - echo " rm -f" $$list; \ - rm -f $$list - -test-ifcfg-rh$(EXEEXT): $(test_ifcfg_rh_OBJECTS) $(test_ifcfg_rh_DEPENDENCIES) $(EXTRA_test_ifcfg_rh_DEPENDENCIES) - @rm -f test-ifcfg-rh$(EXEEXT) - $(AM_V_CCLD)$(LINK) $(test_ifcfg_rh_OBJECTS) $(test_ifcfg_rh_LDADD) $(LIBS) - -test-ifcfg-rh-utils$(EXEEXT): $(test_ifcfg_rh_utils_OBJECTS) $(test_ifcfg_rh_utils_DEPENDENCIES) $(EXTRA_test_ifcfg_rh_utils_DEPENDENCIES) - @rm -f test-ifcfg-rh-utils$(EXEEXT) - $(AM_V_CCLD)$(LINK) $(test_ifcfg_rh_utils_OBJECTS) $(test_ifcfg_rh_utils_LDADD) $(LIBS) - -mostlyclean-compile: - -rm -f *.$(OBJEXT) - -distclean-compile: - -rm -f *.tab.c - -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/reader.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/shvar.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test-ifcfg-rh-utils.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test-ifcfg-rh.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/utils.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/writer.Po@am__quote@ - -.c.o: -@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ $< - -.c.obj: -@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'` - -.c.lo: -@am__fastdepCC_TRUE@ $(AM_V_CC)$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $< - -reader.o: ../reader.c -@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT reader.o -MD -MP -MF $(DEPDIR)/reader.Tpo -c -o reader.o `test -f '../reader.c' || echo '$(srcdir)/'`../reader.c -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/reader.Tpo $(DEPDIR)/reader.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='../reader.c' object='reader.o' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o reader.o `test -f '../reader.c' || echo '$(srcdir)/'`../reader.c - -reader.obj: ../reader.c -@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT reader.obj -MD -MP -MF $(DEPDIR)/reader.Tpo -c -o reader.obj `if test -f '../reader.c'; then $(CYGPATH_W) '../reader.c'; else $(CYGPATH_W) '$(srcdir)/../reader.c'; fi` -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/reader.Tpo $(DEPDIR)/reader.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='../reader.c' object='reader.obj' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o reader.obj `if test -f '../reader.c'; then $(CYGPATH_W) '../reader.c'; else $(CYGPATH_W) '$(srcdir)/../reader.c'; fi` - -shvar.o: ../shvar.c -@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT shvar.o -MD -MP -MF $(DEPDIR)/shvar.Tpo -c -o shvar.o `test -f '../shvar.c' || echo '$(srcdir)/'`../shvar.c -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/shvar.Tpo $(DEPDIR)/shvar.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='../shvar.c' object='shvar.o' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o shvar.o `test -f '../shvar.c' || echo '$(srcdir)/'`../shvar.c - -shvar.obj: ../shvar.c -@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT shvar.obj -MD -MP -MF $(DEPDIR)/shvar.Tpo -c -o shvar.obj `if test -f '../shvar.c'; then $(CYGPATH_W) '../shvar.c'; else $(CYGPATH_W) '$(srcdir)/../shvar.c'; fi` -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/shvar.Tpo $(DEPDIR)/shvar.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='../shvar.c' object='shvar.obj' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o shvar.obj `if test -f '../shvar.c'; then $(CYGPATH_W) '../shvar.c'; else $(CYGPATH_W) '$(srcdir)/../shvar.c'; fi` - -utils.o: ../utils.c -@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT utils.o -MD -MP -MF $(DEPDIR)/utils.Tpo -c -o utils.o `test -f '../utils.c' || echo '$(srcdir)/'`../utils.c -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/utils.Tpo $(DEPDIR)/utils.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='../utils.c' object='utils.o' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o utils.o `test -f '../utils.c' || echo '$(srcdir)/'`../utils.c - -utils.obj: ../utils.c -@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT utils.obj -MD -MP -MF $(DEPDIR)/utils.Tpo -c -o utils.obj `if test -f '../utils.c'; then $(CYGPATH_W) '../utils.c'; else $(CYGPATH_W) '$(srcdir)/../utils.c'; fi` -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/utils.Tpo $(DEPDIR)/utils.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='../utils.c' object='utils.obj' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o utils.obj `if test -f '../utils.c'; then $(CYGPATH_W) '../utils.c'; else $(CYGPATH_W) '$(srcdir)/../utils.c'; fi` - -writer.o: ../writer.c -@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT writer.o -MD -MP -MF $(DEPDIR)/writer.Tpo -c -o writer.o `test -f '../writer.c' || echo '$(srcdir)/'`../writer.c -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/writer.Tpo $(DEPDIR)/writer.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='../writer.c' object='writer.o' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o writer.o `test -f '../writer.c' || echo '$(srcdir)/'`../writer.c - -writer.obj: ../writer.c -@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT writer.obj -MD -MP -MF $(DEPDIR)/writer.Tpo -c -o writer.obj `if test -f '../writer.c'; then $(CYGPATH_W) '../writer.c'; else $(CYGPATH_W) '$(srcdir)/../writer.c'; fi` -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/writer.Tpo $(DEPDIR)/writer.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='../writer.c' object='writer.obj' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o writer.obj `if test -f '../writer.c'; then $(CYGPATH_W) '../writer.c'; else $(CYGPATH_W) '$(srcdir)/../writer.c'; fi` - -mostlyclean-libtool: - -rm -f *.lo - -clean-libtool: - -rm -rf .libs _libs - -# This directory's subdirectories are mostly independent; you can cd -# into them and run 'make' without going through this Makefile. -# To change the values of 'make' variables: instead of editing Makefiles, -# (1) if the variable is set in 'config.status', edit 'config.status' -# (which will cause the Makefiles to be regenerated when you run 'make'); -# (2) otherwise, pass the desired values on the 'make' command line. -$(am__recursive_targets): - @fail=; \ - if $(am__make_keepgoing); then \ - failcom='fail=yes'; \ - else \ - failcom='exit 1'; \ - fi; \ - dot_seen=no; \ - target=`echo $@ | sed s/-recursive//`; \ - case "$@" in \ - distclean-* | maintainer-clean-*) list='$(DIST_SUBDIRS)' ;; \ - *) list='$(SUBDIRS)' ;; \ - esac; \ - for subdir in $$list; do \ - echo "Making $$target in $$subdir"; \ - if test "$$subdir" = "."; then \ - dot_seen=yes; \ - local_target="$$target-am"; \ - else \ - local_target="$$target"; \ - fi; \ - ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \ - || eval $$failcom; \ - done; \ - if test "$$dot_seen" = "no"; then \ - $(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \ - fi; test -z "$$fail" - -ID: $(am__tagged_files) - $(am__define_uniq_tagged_files); mkid -fID $$unique -tags: tags-recursive -TAGS: tags - -tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) - set x; \ - here=`pwd`; \ - if ($(ETAGS) --etags-include --version) >/dev/null 2>&1; then \ - include_option=--etags-include; \ - empty_fix=.; \ - else \ - include_option=--include; \ - empty_fix=; \ - fi; \ - list='$(SUBDIRS)'; for subdir in $$list; do \ - if test "$$subdir" = .; then :; else \ - test ! -f $$subdir/TAGS || \ - set "$$@" "$$include_option=$$here/$$subdir/TAGS"; \ - fi; \ - done; \ - $(am__define_uniq_tagged_files); \ - 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-recursive - -CTAGS: ctags -ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) - $(am__define_uniq_tagged_files); \ - 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" -cscopelist: cscopelist-recursive - -cscopelist-am: $(am__tagged_files) - list='$(am__tagged_files)'; \ - case "$(srcdir)" in \ - [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \ - *) sdir=$(subdir)/$(srcdir) ;; \ - esac; \ - for i in $$list; do \ - if test -f "$$i"; then \ - echo "$(subdir)/$$i"; \ - else \ - echo "$$sdir/$$i"; \ - fi; \ - done >> $(top_builddir)/cscope.files - -distclean-tags: - -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags - -# Recover from deleted '.trs' file; this should ensure that -# "rm -f foo.log; make foo.trs" re-run 'foo.test', and re-create -# both 'foo.log' and 'foo.trs'. Break the recipe in two subshells -# to avoid problems with "make -n". -.log.trs: - rm -f $< $@ - $(MAKE) $(AM_MAKEFLAGS) $< - -# Leading 'am--fnord' is there to ensure the list of targets does not -# expand to empty, as could happen e.g. with make check TESTS=''. -am--fnord $(TEST_LOGS) $(TEST_LOGS:.log=.trs): $(am__force_recheck) -am--force-recheck: - @: - -$(TEST_SUITE_LOG): $(TEST_LOGS) - @$(am__set_TESTS_bases); \ - am__f_ok () { test -f "$$1" && test -r "$$1"; }; \ - redo_bases=`for i in $$bases; do \ - am__f_ok $$i.trs && am__f_ok $$i.log || echo $$i; \ - done`; \ - if test -n "$$redo_bases"; then \ - redo_logs=`for i in $$redo_bases; do echo $$i.log; done`; \ - redo_results=`for i in $$redo_bases; do echo $$i.trs; done`; \ - if $(am__make_dryrun); then :; else \ - rm -f $$redo_logs && rm -f $$redo_results || exit 1; \ - fi; \ - fi; \ - if test -n "$$am__remaking_logs"; then \ - echo "fatal: making $(TEST_SUITE_LOG): possible infinite" \ - "recursion detected" >&2; \ - elif test -n "$$redo_logs"; then \ - am__remaking_logs=yes $(MAKE) $(AM_MAKEFLAGS) $$redo_logs; \ - fi; \ - if $(am__make_dryrun); then :; else \ - st=0; \ - errmsg="fatal: making $(TEST_SUITE_LOG): failed to create"; \ - for i in $$redo_bases; do \ - test -f $$i.trs && test -r $$i.trs \ - || { echo "$$errmsg $$i.trs" >&2; st=1; }; \ - test -f $$i.log && test -r $$i.log \ - || { echo "$$errmsg $$i.log" >&2; st=1; }; \ - done; \ - test $$st -eq 0 || exit 1; \ - fi - @$(am__sh_e_setup); $(am__tty_colors); $(am__set_TESTS_bases); \ - ws='[ ]'; \ - results=`for b in $$bases; do echo $$b.trs; done`; \ - test -n "$$results" || results=/dev/null; \ - all=` grep "^$$ws*:test-result:" $$results | wc -l`; \ - pass=` grep "^$$ws*:test-result:$$ws*PASS" $$results | wc -l`; \ - fail=` grep "^$$ws*:test-result:$$ws*FAIL" $$results | wc -l`; \ - skip=` grep "^$$ws*:test-result:$$ws*SKIP" $$results | wc -l`; \ - xfail=`grep "^$$ws*:test-result:$$ws*XFAIL" $$results | wc -l`; \ - xpass=`grep "^$$ws*:test-result:$$ws*XPASS" $$results | wc -l`; \ - error=`grep "^$$ws*:test-result:$$ws*ERROR" $$results | wc -l`; \ - if test `expr $$fail + $$xpass + $$error` -eq 0; then \ - success=true; \ - else \ - success=false; \ - fi; \ - br='==================='; br=$$br$$br$$br$$br; \ - result_count () \ - { \ - if test x"$$1" = x"--maybe-color"; then \ - maybe_colorize=yes; \ - elif test x"$$1" = x"--no-color"; then \ - maybe_colorize=no; \ - else \ - echo "$@: invalid 'result_count' usage" >&2; exit 4; \ - fi; \ - shift; \ - desc=$$1 count=$$2; \ - if test $$maybe_colorize = yes && test $$count -gt 0; then \ - color_start=$$3 color_end=$$std; \ - else \ - color_start= color_end=; \ - fi; \ - echo "$${color_start}# $$desc $$count$${color_end}"; \ - }; \ - create_testsuite_report () \ - { \ - result_count $$1 "TOTAL:" $$all "$$brg"; \ - result_count $$1 "PASS: " $$pass "$$grn"; \ - result_count $$1 "SKIP: " $$skip "$$blu"; \ - result_count $$1 "XFAIL:" $$xfail "$$lgn"; \ - result_count $$1 "FAIL: " $$fail "$$red"; \ - result_count $$1 "XPASS:" $$xpass "$$red"; \ - result_count $$1 "ERROR:" $$error "$$mgn"; \ - }; \ - { \ - echo "$(PACKAGE_STRING): $(subdir)/$(TEST_SUITE_LOG)" | \ - $(am__rst_title); \ - create_testsuite_report --no-color; \ - echo; \ - echo ".. contents:: :depth: 2"; \ - echo; \ - for b in $$bases; do echo $$b; done \ - | $(am__create_global_log); \ - } >$(TEST_SUITE_LOG).tmp || exit 1; \ - mv $(TEST_SUITE_LOG).tmp $(TEST_SUITE_LOG); \ - if $$success; then \ - col="$$grn"; \ - else \ - col="$$red"; \ - test x"$$VERBOSE" = x || cat $(TEST_SUITE_LOG); \ - fi; \ - echo "$${col}$$br$${std}"; \ - echo "$${col}Testsuite summary for $(PACKAGE_STRING)$${std}"; \ - echo "$${col}$$br$${std}"; \ - create_testsuite_report --maybe-color; \ - echo "$$col$$br$$std"; \ - if $$success; then :; else \ - echo "$${col}See $(subdir)/$(TEST_SUITE_LOG)$${std}"; \ - if test -n "$(PACKAGE_BUGREPORT)"; then \ - echo "$${col}Please report to $(PACKAGE_BUGREPORT)$${std}"; \ - fi; \ - echo "$$col$$br$$std"; \ - fi; \ - $$success || exit 1 - -check-TESTS: - @list='$(RECHECK_LOGS)'; test -z "$$list" || rm -f $$list - @list='$(RECHECK_LOGS:.log=.trs)'; test -z "$$list" || rm -f $$list - @test -z "$(TEST_SUITE_LOG)" || rm -f $(TEST_SUITE_LOG) - @set +e; $(am__set_TESTS_bases); \ - log_list=`for i in $$bases; do echo $$i.log; done`; \ - trs_list=`for i in $$bases; do echo $$i.trs; done`; \ - log_list=`echo $$log_list`; trs_list=`echo $$trs_list`; \ - $(MAKE) $(AM_MAKEFLAGS) $(TEST_SUITE_LOG) TEST_LOGS="$$log_list"; \ - exit $$?; -recheck: all - @test -z "$(TEST_SUITE_LOG)" || rm -f $(TEST_SUITE_LOG) - @set +e; $(am__set_TESTS_bases); \ - bases=`for i in $$bases; do echo $$i; done \ - | $(am__list_recheck_tests)` || exit 1; \ - log_list=`for i in $$bases; do echo $$i.log; done`; \ - log_list=`echo $$log_list`; \ - $(MAKE) $(AM_MAKEFLAGS) $(TEST_SUITE_LOG) \ - am__force_recheck=am--force-recheck \ - TEST_LOGS="$$log_list"; \ - exit $$? -test-ifcfg-rh-utils.log: test-ifcfg-rh-utils$(EXEEXT) - @p='test-ifcfg-rh-utils$(EXEEXT)'; \ - b='test-ifcfg-rh-utils'; \ - $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ - --log-file $$b.log --trs-file $$b.trs \ - $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ - "$$tst" $(AM_TESTS_FD_REDIRECT) -test-ifcfg-rh.log: test-ifcfg-rh$(EXEEXT) - @p='test-ifcfg-rh$(EXEEXT)'; \ - b='test-ifcfg-rh'; \ - $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ - --log-file $$b.log --trs-file $$b.trs \ - $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ - "$$tst" $(AM_TESTS_FD_REDIRECT) -.test.log: - @p='$<'; \ - $(am__set_b); \ - $(am__check_pre) $(TEST_LOG_DRIVER) --test-name "$$f" \ - --log-file $$b.log --trs-file $$b.trs \ - $(am__common_driver_flags) $(AM_TEST_LOG_DRIVER_FLAGS) $(TEST_LOG_DRIVER_FLAGS) -- $(TEST_LOG_COMPILE) \ - "$$tst" $(AM_TESTS_FD_REDIRECT) -@am__EXEEXT_TRUE@.test$(EXEEXT).log: -@am__EXEEXT_TRUE@ @p='$<'; \ -@am__EXEEXT_TRUE@ $(am__set_b); \ -@am__EXEEXT_TRUE@ $(am__check_pre) $(TEST_LOG_DRIVER) --test-name "$$f" \ -@am__EXEEXT_TRUE@ --log-file $$b.log --trs-file $$b.trs \ -@am__EXEEXT_TRUE@ $(am__common_driver_flags) $(AM_TEST_LOG_DRIVER_FLAGS) $(TEST_LOG_DRIVER_FLAGS) -- $(TEST_LOG_COMPILE) \ -@am__EXEEXT_TRUE@ "$$tst" $(AM_TESTS_FD_REDIRECT) - -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 - @list='$(DIST_SUBDIRS)'; for subdir in $$list; do \ - if test "$$subdir" = .; then :; else \ - $(am__make_dryrun) \ - || test -d "$(distdir)/$$subdir" \ - || $(MKDIR_P) "$(distdir)/$$subdir" \ - || exit 1; \ - dir1=$$subdir; dir2="$(distdir)/$$subdir"; \ - $(am__relativize); \ - new_distdir=$$reldir; \ - dir1=$$subdir; dir2="$(top_distdir)"; \ - $(am__relativize); \ - new_top_distdir=$$reldir; \ - echo " (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) top_distdir="$$new_top_distdir" distdir="$$new_distdir" \\"; \ - echo " am__remove_distdir=: am__skip_length_check=: am__skip_mode_fix=: distdir)"; \ - ($(am__cd) $$subdir && \ - $(MAKE) $(AM_MAKEFLAGS) \ - top_distdir="$$new_top_distdir" \ - distdir="$$new_distdir" \ - am__remove_distdir=: \ - am__skip_length_check=: \ - am__skip_mode_fix=: \ - distdir) \ - || exit 1; \ - fi; \ - done -@ENABLE_TESTS_FALSE@check-local: -check-am: all-am - $(MAKE) $(AM_MAKEFLAGS) check-TESTS check-local -check: check-recursive -all-am: Makefile $(PROGRAMS) -installdirs: installdirs-recursive -installdirs-am: -install: install-recursive -install-exec: install-exec-recursive -install-data: install-data-recursive -uninstall: uninstall-recursive - -install-am: all-am - @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am - -installcheck: installcheck-recursive -install-strip: - if test -z '$(STRIP)'; then \ - $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ - install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ - install; \ - else \ - $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ - install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ - "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ - fi -mostlyclean-generic: - -test -z "$(TEST_LOGS)" || rm -f $(TEST_LOGS) - -test -z "$(TEST_LOGS:.log=.trs)" || rm -f $(TEST_LOGS:.log=.trs) - -test -z "$(TEST_SUITE_LOG)" || rm -f $(TEST_SUITE_LOG) - -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-recursive - -clean-am: clean-generic clean-libtool clean-noinstPROGRAMS \ - mostlyclean-am - -distclean: distclean-recursive - -rm -rf ./$(DEPDIR) - -rm -f Makefile -distclean-am: clean-am distclean-compile distclean-generic \ - distclean-tags - -dvi: dvi-recursive - -dvi-am: - -html: html-recursive - -html-am: - -info: info-recursive - -info-am: - -install-data-am: - -install-dvi: install-dvi-recursive - -install-dvi-am: - -install-exec-am: - -install-html: install-html-recursive - -install-html-am: - -install-info: install-info-recursive - -install-info-am: - -install-man: - -install-pdf: install-pdf-recursive - -install-pdf-am: - -install-ps: install-ps-recursive - -install-ps-am: - -installcheck-am: - -maintainer-clean: maintainer-clean-recursive - -rm -rf ./$(DEPDIR) - -rm -f Makefile -maintainer-clean-am: distclean-am maintainer-clean-generic - -mostlyclean: mostlyclean-recursive - -mostlyclean-am: mostlyclean-compile mostlyclean-generic \ - mostlyclean-libtool - -pdf: pdf-recursive - -pdf-am: - -ps: ps-recursive - -ps-am: - -uninstall-am: - -.MAKE: $(am__recursive_targets) check-am install-am install-strip - -.PHONY: $(am__recursive_targets) CTAGS GTAGS TAGS all all-am check \ - check-TESTS check-am check-local clean clean-generic \ - clean-libtool clean-noinstPROGRAMS cscopelist-am ctags \ - ctags-am 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-ps install-ps-am install-strip installcheck \ - installcheck-am installdirs installdirs-am maintainer-clean \ - maintainer-clean-generic mostlyclean mostlyclean-compile \ - mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ - recheck tags tags-am uninstall uninstall-am - -.PRECIOUS: Makefile - - -@ENABLE_TESTS_TRUE@@GNOME_CODE_COVERAGE_RULES@ - -@ENABLE_TESTS_TRUE@@VALGRIND_RULES@ - -@ENABLE_TESTS_TRUE@check-local: -@ENABLE_TESTS_TRUE@ LD_BIND_NOW=1 LD_PRELOAD=$(builddir)/../.libs/libnm-settings-plugin-ifcfg-rh.so $(top_builddir)/src/NetworkManager --version >/dev/null - -# 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/settings/plugins/ifcfg-rh/tests/network-scripts/Makefile.am b/src/settings/plugins/ifcfg-rh/tests/network-scripts/Makefile.am deleted file mode 100644 index de9c1ed7..00000000 --- a/src/settings/plugins/ifcfg-rh/tests/network-scripts/Makefile.am +++ /dev/null @@ -1,170 +0,0 @@ -EXTRA_DIST = \ - ifcfg-test-minimal \ - ifcfg-test-misc-variables \ - ifcfg-test-variables-corner-cases-1 \ - ifcfg-test-nm-controlled \ - ifcfg-test-nm-controlled-unrecognized \ - ifcfg-test-unrecognized \ - ifcfg-test-wired-static \ - ifcfg-test-wired-static-bootproto \ - ifcfg-test-wired-dhcp \ - ifcfg-test-wired-dhcp-plus-ip \ - ifcfg-test-wired-shared-plus-ip \ - ifcfg-test-wired-dhcp-send-hostname \ - ifcfg-test-wired-dhcp6-only \ - ifcfg-test-wired-autoip \ - ifcfg-test-wired-global-gateway \ - network-test-wired-global-gateway \ - ifcfg-test-wired-global-gateway-ignore \ - network-test-wired-global-gateway-ignore \ - ifcfg-test-wired-obsolete-gateway-n \ - ifcfg-test-wired-never-default \ - network-test-wired-never-default \ - ifcfg-test-wired-defroute-no \ - ifcfg-test-wired-defroute-no-gatewaydev-yes \ - network-test-wired-defroute-no-gatewaydev-yes \ - ifcfg-test-wired-8021x-peap-mschapv2 \ - keys-test-wired-8021x-peap-mschapv2 \ - ifcfg-test-wired-8021x-tls-agent \ - ifcfg-test-wired-8021x-tls-always \ - ifcfg-test-wired-802-1X-subj-matches \ - ifcfg-test-wired-802-1x-ttls-eapgtc \ - ifcfg-test-onboot-no \ - ifcfg-test-noip \ - ifcfg-test-wifi-open \ - ifcfg-test-wifi-open-auto \ - ifcfg-test-wifi-open-ssid-quoted \ - ifcfg-test-wifi-open-ssid-long-quoted \ - ifcfg-test-wifi-open-ssid-hex \ - ifcfg-test-wifi-open-ssid-long-hex \ - ifcfg-test-wifi-open-ssid-bad-hex \ - ifcfg-test-wifi-wep \ - keys-test-wifi-wep \ - ifcfg-test-wifi-wep-adhoc \ - keys-test-wifi-wep-adhoc \ - ifcfg-test-wifi-wep-eap-ttls-chap \ - keys-test-wifi-wep-eap-ttls-chap \ - ifcfg-test-wifi-leap \ - keys-test-wifi-leap \ - ifcfg-test-wifi-leap-agent \ - ifcfg-test-wifi-leap-always-ask \ - ifcfg-test-wifi-wpa-psk \ - keys-test-wifi-wpa-psk \ - ifcfg-test-wifi-wpa-psk-2 \ - keys-test-wifi-wpa-psk-2 \ - ifcfg-test-wifi-wpa-psk-unquoted \ - keys-test-wifi-wpa-psk-unquoted \ - ifcfg-test-wifi-wpa-psk-unquoted2 \ - keys-test-wifi-wpa-psk-unquoted2 \ - ifcfg-test-wifi-wpa-psk-adhoc \ - keys-test-wifi-wpa-psk-adhoc \ - ifcfg-test-wifi-wpa-psk-hex \ - keys-test-wifi-wpa-psk-hex \ - ifcfg-test-wifi-wpa-eap-tls \ - keys-test-wifi-wpa-eap-tls \ - ifcfg-test-wifi-wpa-eap-ttls-tls \ - keys-test-wifi-wpa-eap-ttls-tls \ - ifcfg-test-wifi-hidden \ - ifcfg-test-wifi-band-a \ - ifcfg-test-wifi-band-a-channel-mismatch \ - ifcfg-test-wifi-band-bg-channel-mismatch \ - ifcfg-test-wifi-mac-random-always \ - ifcfg-test-wifi-mac-random-never \ - ifcfg-test-wifi-mac-random-default \ - ifcfg-test-wifi-mac-random-missing \ - test_ca_cert.pem \ - test1_key_and_cert.pem \ - ifcfg-test-ibft \ - ifcfg-test-static-routes-legacy \ - route-test-static-routes-legacy \ - ifcfg-test-sit-ignore \ - ifcfg-test-wired-static-routes \ - route-test-wired-static-routes \ - ifcfg-test-wired-static-routes-legacy \ - route-test-wired-static-routes-legacy \ - ifcfg-test-wired-ipv4-manual-1 \ - ifcfg-test-wired-ipv4-manual-2 \ - ifcfg-test-wired-ipv4-manual-3 \ - ifcfg-test-wired-ipv4-manual-4 \ - ifcfg-test-wired-ipv6-manual \ - route6-test-wired-ipv6-manual \ - ifcfg-test-wired-static-no-prefix-8 \ - ifcfg-test-wired-static-no-prefix-16 \ - ifcfg-test-wired-static-no-prefix-24 \ - ifcfg-test-wired-ipv6-only \ - ifcfg-test-wifi-wep-passphrase \ - keys-test-wifi-wep-passphrase \ - ifcfg-test-wifi-wep-40-ascii \ - keys-test-wifi-wep-40-ascii \ - ifcfg-test-wifi-wep-104-ascii \ - keys-test-wifi-wep-104-ascii \ - ifcfg-test-wired-qeth-static \ - ifcfg-test-wired-ctc-static \ - ifcfg-test-bridge-main \ - ifcfg-test-bridge-component \ - ifcfg-test-bridge-missing-stp \ - ifcfg-test-vlan-interface \ - ifcfg-test-vlan-only-vlanid \ - ifcfg-test-vlan-only-device \ - ifcfg-test-vlan-physdev \ - ifcfg-test-vlan-reorder-hdr-1 \ - ifcfg-test-vlan-reorder-hdr-2 \ - ifcfg-test-vlan-flags-1 \ - ifcfg-test-vlan-flags-2 \ - ifcfg-test-wifi-wep-no-keys \ - ifcfg-test-permissions \ - ifcfg-test-wifi-wep-agent-keys \ - ifcfg-test-wifi-dynamic-wep-leap \ - keys-test-wifi-dynamic-wep-leap \ - ifcfg-test-infiniband \ - ifcfg-test-bond-main \ - ifcfg-test-bond-slave \ - ifcfg-test-bond-slave-ib \ - ifcfg-test-bond-mode-numeric \ - ifcfg-test-dcb \ - ifcfg-test-dcb-default-app-priorities \ - ifcfg-test-dcb-bad-booleans \ - ifcfg-test-dcb-short-booleans \ - ifcfg-test-dcb-bad-uints \ - ifcfg-test-dcb-short-uints \ - ifcfg-test-dcb-bad-percent \ - ifcfg-test-dcb-short-percent \ - ifcfg-test-dcb-pgpct-not-100 \ - ifcfg-test-fcoe-fabric \ - ifcfg-test-fcoe-vn2vn \ - ifcfg-test-team-master-1 \ - ifcfg-test-team-master-2 \ - ifcfg-test-team-master-invalid \ - ifcfg-test-team-port-1 \ - ifcfg-test-team-port-2 \ - ifcfg-test-team-port-empty-config \ - ifcfg-test-vlan-trailing-spaces \ - ifcfg-test-dns-options \ - ifcfg-test-wired-wake-on-lan \ - ifcfg-test-wired-ipv6-only-1 - -# make target dependencies can't have colons in their names, which ends up -# meaning that we can't add the alias files to EXTRA_DIST -ALIAS_FILES = \ - ifcfg-aliasem0 \ - ifcfg-aliasem0:1 \ - ifcfg-aliasem0:2 \ - ifcfg-aliasem0:99 \ - ifcfg-aliasem1 \ - ifcfg-aliasem1:1 \ - ifcfg-aliasem2 \ - ifcfg-aliasem2:1 - -dist-hook: - @for f in $(ALIAS_FILES); do \ - cp $(abs_srcdir)/$$f $(distdir)/; \ - done - -check-local: - @for f in $(EXTRA_DIST) $(ALIAS_FILES); do \ - chmod 0600 $(abs_srcdir)/$$f; \ - done - -# Make the special temp dir for some written connections - mkdir -p $(abs_builddir)/tmp - diff --git a/src/settings/plugins/ifcfg-rh/tests/network-scripts/Makefile.in b/src/settings/plugins/ifcfg-rh/tests/network-scripts/Makefile.in deleted file mode 100644 index 583f0809..00000000 --- a/src/settings/plugins/ifcfg-rh/tests/network-scripts/Makefile.in +++ /dev/null @@ -1,776 +0,0 @@ -# Makefile.in generated by automake 1.15 from Makefile.am. -# @configure_input@ - -# Copyright (C) 1994-2014 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@ -am__is_gnu_make = { \ - if test -z '$(MAKELEVEL)'; then \ - false; \ - elif test -n '$(MAKE_HOST)'; then \ - true; \ - elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \ - true; \ - else \ - false; \ - fi; \ -} -am__make_running_with_option = \ - case $${target_option-} in \ - ?) ;; \ - *) echo "am__make_running_with_option: internal error: invalid" \ - "target option '$${target_option-}' specified" >&2; \ - exit 1;; \ - esac; \ - has_opt=no; \ - sane_makeflags=$$MAKEFLAGS; \ - if $(am__is_gnu_make); then \ - sane_makeflags=$$MFLAGS; \ - else \ - case $$MAKEFLAGS in \ - *\\[\ \ ]*) \ - bs=\\; \ - sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \ - | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \ - esac; \ - fi; \ - skip_next=no; \ - strip_trailopt () \ - { \ - flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \ - }; \ - for flg in $$sane_makeflags; do \ - test $$skip_next = yes && { skip_next=no; continue; }; \ - case $$flg in \ - *=*|--*) continue;; \ - -*I) strip_trailopt 'I'; skip_next=yes;; \ - -*I?*) strip_trailopt 'I';; \ - -*O) strip_trailopt 'O'; skip_next=yes;; \ - -*O?*) strip_trailopt 'O';; \ - -*l) strip_trailopt 'l'; skip_next=yes;; \ - -*l?*) strip_trailopt 'l';; \ - -[dEDm]) skip_next=yes;; \ - -[JT]) skip_next=yes;; \ - esac; \ - case $$flg in \ - *$$target_option*) has_opt=yes; break;; \ - esac; \ - done; \ - test $$has_opt = yes -am__make_dryrun = (target_option=n; $(am__make_running_with_option)) -am__make_keepgoing = (target_option=k; $(am__make_running_with_option)) -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/settings/plugins/ifcfg-rh/tests/network-scripts -ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 -am__aclocal_m4_deps = $(top_srcdir)/m4/attributes.m4 \ - $(top_srcdir)/m4/ax_lib_readline.m4 \ - $(top_srcdir)/m4/compiler_options.m4 \ - $(top_srcdir)/m4/gettext.m4 $(top_srcdir)/m4/git-sha-record.m4 \ - $(top_srcdir)/m4/gnome-code-coverage.m4 \ - $(top_srcdir)/m4/gtk-doc.m4 $(top_srcdir)/m4/iconv.m4 \ - $(top_srcdir)/m4/intlmacosx.m4 $(top_srcdir)/m4/intltool.m4 \ - $(top_srcdir)/m4/introspection.m4 $(top_srcdir)/m4/lib-ld.m4 \ - $(top_srcdir)/m4/lib-link.m4 $(top_srcdir)/m4/lib-prefix.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)/m4/nls.m4 \ - $(top_srcdir)/m4/po.m4 $(top_srcdir)/m4/progtest.m4 \ - $(top_srcdir)/m4/vapigen.m4 $(top_srcdir)/configure.ac -am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ - $(ACLOCAL_M4) -DIST_COMMON = $(srcdir)/Makefile.am $(am__DIST_COMMON) -mkinstalldirs = $(install_sh) -d -CONFIG_HEADER = $(top_builddir)/config.h -CONFIG_CLEAN_FILES = -CONFIG_CLEAN_VPATH_FILES = -AM_V_P = $(am__v_P_@AM_V@) -am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) -am__v_P_0 = false -am__v_P_1 = : -AM_V_GEN = $(am__v_GEN_@AM_V@) -am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@) -am__v_GEN_0 = @echo " GEN " $@; -am__v_GEN_1 = -AM_V_at = $(am__v_at_@AM_V@) -am__v_at_ = $(am__v_at_@AM_DEFAULT_V@) -am__v_at_0 = @ -am__v_at_1 = -SOURCES = -DIST_SOURCES = -am__can_run_installinfo = \ - case $$AM_UPDATE_INFO_DIR in \ - n|no|NO) false;; \ - *) (install-info --version) >/dev/null 2>&1;; \ - esac -am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) -am__DIST_COMMON = $(srcdir)/Makefile.in -DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) -ACLOCAL = @ACLOCAL@ -ALL_LINGUAS = @ALL_LINGUAS@ -AMTAR = @AMTAR@ -AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ -AM_TESTS_FD_REDIRECT = @AM_TESTS_FD_REDIRECT@ -AR = @AR@ -AUTOCONF = @AUTOCONF@ -AUTOHEADER = @AUTOHEADER@ -AUTOMAKE = @AUTOMAKE@ -AWK = @AWK@ -BLUEZ5_CFLAGS = @BLUEZ5_CFLAGS@ -BLUEZ5_LIBS = @BLUEZ5_LIBS@ -CC = @CC@ -CCDEPMODE = @CCDEPMODE@ -CFLAGS = @CFLAGS@ -CODE_COVERAGE_CFLAGS = @CODE_COVERAGE_CFLAGS@ -CODE_COVERAGE_ENABLED = @CODE_COVERAGE_ENABLED@ -CODE_COVERAGE_LDFLAGS = @CODE_COVERAGE_LDFLAGS@ -CPP = @CPP@ -CPPFLAGS = @CPPFLAGS@ -CXX = @CXX@ -CXXCPP = @CXXCPP@ -CXXDEPMODE = @CXXDEPMODE@ -CXXFLAGS = @CXXFLAGS@ -CYGPATH_W = @CYGPATH_W@ -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@ -DISTRO_NETWORK_SERVICE = @DISTRO_NETWORK_SERVICE@ -DLLTOOL = @DLLTOOL@ -DL_LIBS = @DL_LIBS@ -DNSMASQ_PATH = @DNSMASQ_PATH@ -DNSSEC_TRIGGER_SCRIPT = @DNSSEC_TRIGGER_SCRIPT@ -DSYMUTIL = @DSYMUTIL@ -DUMPBIN = @DUMPBIN@ -ECHO_C = @ECHO_C@ -ECHO_N = @ECHO_N@ -ECHO_T = @ECHO_T@ -EGREP = @EGREP@ -EXEEXT = @EXEEXT@ -FGREP = @FGREP@ -GENHTML = @GENHTML@ -GETTEXT_MACRO_VERSION = @GETTEXT_MACRO_VERSION@ -GETTEXT_PACKAGE = @GETTEXT_PACKAGE@ -GLIB_CFLAGS = @GLIB_CFLAGS@ -GLIB_GENMARSHAL = @GLIB_GENMARSHAL@ -GLIB_LIBS = @GLIB_LIBS@ -GLIB_MAKEFILE = @GLIB_MAKEFILE@ -GLIB_MKENUMS = @GLIB_MKENUMS@ -GMSGFMT = @GMSGFMT@ -GMSGFMT_015 = @GMSGFMT_015@ -GNUTLS_CFLAGS = @GNUTLS_CFLAGS@ -GNUTLS_LIBS = @GNUTLS_LIBS@ -GREP = @GREP@ -GTKDOC_CHECK = @GTKDOC_CHECK@ -GTKDOC_CHECK_PATH = @GTKDOC_CHECK_PATH@ -GTKDOC_DEPS_CFLAGS = @GTKDOC_DEPS_CFLAGS@ -GTKDOC_DEPS_LIBS = @GTKDOC_DEPS_LIBS@ -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@ -INTLLIBS = @INTLLIBS@ -INTLTOOL_EXTRACT = @INTLTOOL_EXTRACT@ -INTLTOOL_MERGE = @INTLTOOL_MERGE@ -INTLTOOL_PERL = @INTLTOOL_PERL@ -INTLTOOL_UPDATE = @INTLTOOL_UPDATE@ -INTLTOOL_V_MERGE = @INTLTOOL_V_MERGE@ -INTLTOOL_V_MERGE_OPTIONS = @INTLTOOL_V_MERGE_OPTIONS@ -INTLTOOL__v_MERGE_ = @INTLTOOL__v_MERGE_@ -INTLTOOL__v_MERGE_0 = @INTLTOOL__v_MERGE_0@ -INTL_MACOSX_LIBS = @INTL_MACOSX_LIBS@ -INTROSPECTION_CFLAGS = @INTROSPECTION_CFLAGS@ -INTROSPECTION_COMPILER = @INTROSPECTION_COMPILER@ -INTROSPECTION_GENERATE = @INTROSPECTION_GENERATE@ -INTROSPECTION_GIRDIR = @INTROSPECTION_GIRDIR@ -INTROSPECTION_LIBS = @INTROSPECTION_LIBS@ -INTROSPECTION_MAKEFILE = @INTROSPECTION_MAKEFILE@ -INTROSPECTION_SCANNER = @INTROSPECTION_SCANNER@ -INTROSPECTION_TYPELIBDIR = @INTROSPECTION_TYPELIBDIR@ -IPTABLES_PATH = @IPTABLES_PATH@ -JANSSON_CFLAGS = @JANSSON_CFLAGS@ -JANSSON_LIBS = @JANSSON_LIBS@ -KERNEL_FIRMWARE_DIR = @KERNEL_FIRMWARE_DIR@ -LCOV = @LCOV@ -LD = @LD@ -LDFLAGS = @LDFLAGS@ -LIBAUDIT_CFLAGS = @LIBAUDIT_CFLAGS@ -LIBAUDIT_LIBS = @LIBAUDIT_LIBS@ -LIBICONV = @LIBICONV@ -LIBINTL = @LIBINTL@ -LIBM = @LIBM@ -LIBNDP_CFLAGS = @LIBNDP_CFLAGS@ -LIBNDP_LIBS = @LIBNDP_LIBS@ -LIBNL_CFLAGS = @LIBNL_CFLAGS@ -LIBNL_LIBS = @LIBNL_LIBS@ -LIBOBJS = @LIBOBJS@ -LIBS = @LIBS@ -LIBSOUP_CFLAGS = @LIBSOUP_CFLAGS@ -LIBSOUP_LIBS = @LIBSOUP_LIBS@ -LIBSYSTEMD_CFLAGS = @LIBSYSTEMD_CFLAGS@ -LIBSYSTEMD_LIBS = @LIBSYSTEMD_LIBS@ -LIBTEAMDCTL_CFLAGS = @LIBTEAMDCTL_CFLAGS@ -LIBTEAMDCTL_LIBS = @LIBTEAMDCTL_LIBS@ -LIBTOOL = @LIBTOOL@ -LIPO = @LIPO@ -LN_S = @LN_S@ -LOG_DRIVER = @LOG_DRIVER@ -LTLIBICONV = @LTLIBICONV@ -LTLIBINTL = @LTLIBINTL@ -LTLIBOBJS = @LTLIBOBJS@ -LT_SYS_LIBRARY_PATH = @LT_SYS_LIBRARY_PATH@ -MAINT = @MAINT@ -MAKEINFO = @MAKEINFO@ -MANIFEST_TOOL = @MANIFEST_TOOL@ -MKDIR_P = @MKDIR_P@ -MM_GLIB_CFLAGS = @MM_GLIB_CFLAGS@ -MM_GLIB_LIBS = @MM_GLIB_LIBS@ -MOC = @MOC@ -MSGFMT = @MSGFMT@ -MSGFMT_015 = @MSGFMT_015@ -MSGMERGE = @MSGMERGE@ -NEWT_CFLAGS = @NEWT_CFLAGS@ -NEWT_LIBS = @NEWT_LIBS@ -NM = @NM@ -NMEDIT = @NMEDIT@ -NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT = @NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT@ -NM_CONFIG_DEFAULT_DNS_RC_MANAGER = @NM_CONFIG_DEFAULT_DNS_RC_MANAGER@ -NM_CONFIG_DEFAULT_LOGGING_AUDIT_TEXT = @NM_CONFIG_DEFAULT_LOGGING_AUDIT_TEXT@ -NM_CONFIG_LOGGING_BACKEND_DEFAULT_TEXT = @NM_CONFIG_LOGGING_BACKEND_DEFAULT_TEXT@ -NM_MAJOR_VERSION = @NM_MAJOR_VERSION@ -NM_MICRO_VERSION = @NM_MICRO_VERSION@ -NM_MINOR_VERSION = @NM_MINOR_VERSION@ -NM_MODIFY_SYSTEM_POLICY = @NM_MODIFY_SYSTEM_POLICY@ -NM_VERSION = @NM_VERSION@ -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@ -PERL = @PERL@ -PKG_CONFIG = @PKG_CONFIG@ -PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ -PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ -POLKIT_CFLAGS = @POLKIT_CFLAGS@ -POLKIT_LIBS = @POLKIT_LIBS@ -POSUB = @POSUB@ -PPPD_PATH = @PPPD_PATH@ -PPPD_PLUGIN_DIR = @PPPD_PLUGIN_DIR@ -QT_CFLAGS = @QT_CFLAGS@ -QT_LIBS = @QT_LIBS@ -RANLIB = @RANLIB@ -READLINE_LIBS = @READLINE_LIBS@ -SANITIZERS = @SANITIZERS@ -SANITIZER_ENV = @SANITIZER_ENV@ -SED = @SED@ -SELINUX_CFLAGS = @SELINUX_CFLAGS@ -SELINUX_LIBS = @SELINUX_LIBS@ -SET_MAKE = @SET_MAKE@ -SHELL = @SHELL@ -STRIP = @STRIP@ -SYSTEMD_200_CFLAGS = @SYSTEMD_200_CFLAGS@ -SYSTEMD_200_LIBS = @SYSTEMD_200_LIBS@ -SYSTEMD_INHIBIT_CFLAGS = @SYSTEMD_INHIBIT_CFLAGS@ -SYSTEMD_INHIBIT_LIBS = @SYSTEMD_INHIBIT_LIBS@ -SYSTEMD_JOURNAL_CFLAGS = @SYSTEMD_JOURNAL_CFLAGS@ -SYSTEMD_JOURNAL_LIBS = @SYSTEMD_JOURNAL_LIBS@ -SYSTEMD_LOGIN_CFLAGS = @SYSTEMD_LOGIN_CFLAGS@ -SYSTEMD_LOGIN_LIBS = @SYSTEMD_LOGIN_LIBS@ -SYSTEM_CA_PATH = @SYSTEM_CA_PATH@ -UDEV_DIR = @UDEV_DIR@ -USE_NLS = @USE_NLS@ -UUID_CFLAGS = @UUID_CFLAGS@ -UUID_LIBS = @UUID_LIBS@ -VALGRIND_RULES = @VALGRIND_RULES@ -VAPIGEN = @VAPIGEN@ -VAPIGEN_MAKEFILE = @VAPIGEN_MAKEFILE@ -VAPIGEN_VAPIDIR = @VAPIGEN_VAPIDIR@ -VERSION = @VERSION@ -XGETTEXT = @XGETTEXT@ -XGETTEXT_015 = @XGETTEXT_015@ -XGETTEXT_EXTRA_OPTIONS = @XGETTEXT_EXTRA_OPTIONS@ -abs_builddir = @abs_builddir@ -abs_srcdir = @abs_srcdir@ -abs_top_builddir = @abs_top_builddir@ -abs_top_srcdir = @abs_top_srcdir@ -ac_ct_AR = @ac_ct_AR@ -ac_ct_CC = @ac_ct_CC@ -ac_ct_CXX = @ac_ct_CXX@ -ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ -ac_ct_RANLIB = @ac_ct_RANLIB@ -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@ -intltool__v_merge_options_ = @intltool__v_merge_options_@ -intltool__v_merge_options_0 = @intltool__v_merge_options_0@ -libdir = @libdir@ -libexecdir = @libexecdir@ -localedir = @localedir@ -localstatedir = @localstatedir@ -mandir = @mandir@ -mkdir_p = @mkdir_p@ -nmbinary = @nmbinary@ -nmconfdir = @nmconfdir@ -nmdatadir = @nmdatadir@ -nmlibdir = @nmlibdir@ -nmrundir = @nmrundir@ -nmstatedir = @nmstatedir@ -oldincludedir = @oldincludedir@ -pdfdir = @pdfdir@ -prefix = @prefix@ -program_transform_name = @program_transform_name@ -psdir = @psdir@ -runstatedir = @runstatedir@ -sbindir = @sbindir@ -sharedstatedir = @sharedstatedir@ -srcdir = @srcdir@ -subdirs = @subdirs@ -sysconfdir = @sysconfdir@ -systemdsystemunitdir = @systemdsystemunitdir@ -target_alias = @target_alias@ -top_build_prefix = @top_build_prefix@ -top_builddir = @top_builddir@ -top_srcdir = @top_srcdir@ -with_dhclient = @with_dhclient@ -with_dhcpcd = @with_dhcpcd@ -with_netconfig = @with_netconfig@ -with_resolvconf = @with_resolvconf@ -with_valgrind = @with_valgrind@ -EXTRA_DIST = \ - ifcfg-test-minimal \ - ifcfg-test-misc-variables \ - ifcfg-test-variables-corner-cases-1 \ - ifcfg-test-nm-controlled \ - ifcfg-test-nm-controlled-unrecognized \ - ifcfg-test-unrecognized \ - ifcfg-test-wired-static \ - ifcfg-test-wired-static-bootproto \ - ifcfg-test-wired-dhcp \ - ifcfg-test-wired-dhcp-plus-ip \ - ifcfg-test-wired-shared-plus-ip \ - ifcfg-test-wired-dhcp-send-hostname \ - ifcfg-test-wired-dhcp6-only \ - ifcfg-test-wired-autoip \ - ifcfg-test-wired-global-gateway \ - network-test-wired-global-gateway \ - ifcfg-test-wired-global-gateway-ignore \ - network-test-wired-global-gateway-ignore \ - ifcfg-test-wired-obsolete-gateway-n \ - ifcfg-test-wired-never-default \ - network-test-wired-never-default \ - ifcfg-test-wired-defroute-no \ - ifcfg-test-wired-defroute-no-gatewaydev-yes \ - network-test-wired-defroute-no-gatewaydev-yes \ - ifcfg-test-wired-8021x-peap-mschapv2 \ - keys-test-wired-8021x-peap-mschapv2 \ - ifcfg-test-wired-8021x-tls-agent \ - ifcfg-test-wired-8021x-tls-always \ - ifcfg-test-wired-802-1X-subj-matches \ - ifcfg-test-wired-802-1x-ttls-eapgtc \ - ifcfg-test-onboot-no \ - ifcfg-test-noip \ - ifcfg-test-wifi-open \ - ifcfg-test-wifi-open-auto \ - ifcfg-test-wifi-open-ssid-quoted \ - ifcfg-test-wifi-open-ssid-long-quoted \ - ifcfg-test-wifi-open-ssid-hex \ - ifcfg-test-wifi-open-ssid-long-hex \ - ifcfg-test-wifi-open-ssid-bad-hex \ - ifcfg-test-wifi-wep \ - keys-test-wifi-wep \ - ifcfg-test-wifi-wep-adhoc \ - keys-test-wifi-wep-adhoc \ - ifcfg-test-wifi-wep-eap-ttls-chap \ - keys-test-wifi-wep-eap-ttls-chap \ - ifcfg-test-wifi-leap \ - keys-test-wifi-leap \ - ifcfg-test-wifi-leap-agent \ - ifcfg-test-wifi-leap-always-ask \ - ifcfg-test-wifi-wpa-psk \ - keys-test-wifi-wpa-psk \ - ifcfg-test-wifi-wpa-psk-2 \ - keys-test-wifi-wpa-psk-2 \ - ifcfg-test-wifi-wpa-psk-unquoted \ - keys-test-wifi-wpa-psk-unquoted \ - ifcfg-test-wifi-wpa-psk-unquoted2 \ - keys-test-wifi-wpa-psk-unquoted2 \ - ifcfg-test-wifi-wpa-psk-adhoc \ - keys-test-wifi-wpa-psk-adhoc \ - ifcfg-test-wifi-wpa-psk-hex \ - keys-test-wifi-wpa-psk-hex \ - ifcfg-test-wifi-wpa-eap-tls \ - keys-test-wifi-wpa-eap-tls \ - ifcfg-test-wifi-wpa-eap-ttls-tls \ - keys-test-wifi-wpa-eap-ttls-tls \ - ifcfg-test-wifi-hidden \ - ifcfg-test-wifi-band-a \ - ifcfg-test-wifi-band-a-channel-mismatch \ - ifcfg-test-wifi-band-bg-channel-mismatch \ - ifcfg-test-wifi-mac-random-always \ - ifcfg-test-wifi-mac-random-never \ - ifcfg-test-wifi-mac-random-default \ - ifcfg-test-wifi-mac-random-missing \ - test_ca_cert.pem \ - test1_key_and_cert.pem \ - ifcfg-test-ibft \ - ifcfg-test-static-routes-legacy \ - route-test-static-routes-legacy \ - ifcfg-test-sit-ignore \ - ifcfg-test-wired-static-routes \ - route-test-wired-static-routes \ - ifcfg-test-wired-static-routes-legacy \ - route-test-wired-static-routes-legacy \ - ifcfg-test-wired-ipv4-manual-1 \ - ifcfg-test-wired-ipv4-manual-2 \ - ifcfg-test-wired-ipv4-manual-3 \ - ifcfg-test-wired-ipv4-manual-4 \ - ifcfg-test-wired-ipv6-manual \ - route6-test-wired-ipv6-manual \ - ifcfg-test-wired-static-no-prefix-8 \ - ifcfg-test-wired-static-no-prefix-16 \ - ifcfg-test-wired-static-no-prefix-24 \ - ifcfg-test-wired-ipv6-only \ - ifcfg-test-wifi-wep-passphrase \ - keys-test-wifi-wep-passphrase \ - ifcfg-test-wifi-wep-40-ascii \ - keys-test-wifi-wep-40-ascii \ - ifcfg-test-wifi-wep-104-ascii \ - keys-test-wifi-wep-104-ascii \ - ifcfg-test-wired-qeth-static \ - ifcfg-test-wired-ctc-static \ - ifcfg-test-bridge-main \ - ifcfg-test-bridge-component \ - ifcfg-test-bridge-missing-stp \ - ifcfg-test-vlan-interface \ - ifcfg-test-vlan-only-vlanid \ - ifcfg-test-vlan-only-device \ - ifcfg-test-vlan-physdev \ - ifcfg-test-vlan-reorder-hdr-1 \ - ifcfg-test-vlan-reorder-hdr-2 \ - ifcfg-test-vlan-flags-1 \ - ifcfg-test-vlan-flags-2 \ - ifcfg-test-wifi-wep-no-keys \ - ifcfg-test-permissions \ - ifcfg-test-wifi-wep-agent-keys \ - ifcfg-test-wifi-dynamic-wep-leap \ - keys-test-wifi-dynamic-wep-leap \ - ifcfg-test-infiniband \ - ifcfg-test-bond-main \ - ifcfg-test-bond-slave \ - ifcfg-test-bond-slave-ib \ - ifcfg-test-bond-mode-numeric \ - ifcfg-test-dcb \ - ifcfg-test-dcb-default-app-priorities \ - ifcfg-test-dcb-bad-booleans \ - ifcfg-test-dcb-short-booleans \ - ifcfg-test-dcb-bad-uints \ - ifcfg-test-dcb-short-uints \ - ifcfg-test-dcb-bad-percent \ - ifcfg-test-dcb-short-percent \ - ifcfg-test-dcb-pgpct-not-100 \ - ifcfg-test-fcoe-fabric \ - ifcfg-test-fcoe-vn2vn \ - ifcfg-test-team-master-1 \ - ifcfg-test-team-master-2 \ - ifcfg-test-team-master-invalid \ - ifcfg-test-team-port-1 \ - ifcfg-test-team-port-2 \ - ifcfg-test-team-port-empty-config \ - ifcfg-test-vlan-trailing-spaces \ - ifcfg-test-dns-options \ - ifcfg-test-wired-wake-on-lan \ - ifcfg-test-wired-ipv6-only-1 - - -# make target dependencies can't have colons in their names, which ends up -# meaning that we can't add the alias files to EXTRA_DIST -ALIAS_FILES = \ - ifcfg-aliasem0 \ - ifcfg-aliasem0:1 \ - ifcfg-aliasem0:2 \ - ifcfg-aliasem0:99 \ - ifcfg-aliasem1 \ - ifcfg-aliasem1:1 \ - ifcfg-aliasem2 \ - ifcfg-aliasem2:1 - -all: all-am - -.SUFFIXES: -$(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/settings/plugins/ifcfg-rh/tests/network-scripts/Makefile'; \ - $(am__cd) $(top_srcdir) && \ - $(AUTOMAKE) --gnu src/settings/plugins/ifcfg-rh/tests/network-scripts/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): - -mostlyclean-libtool: - -rm -f *.lo - -clean-libtool: - -rm -rf .libs _libs -tags TAGS: - -ctags CTAGS: - -cscope cscopelist: - - -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 - $(MAKE) $(AM_MAKEFLAGS) \ - top_distdir="$(top_distdir)" distdir="$(distdir)" \ - dist-hook -check-am: all-am - $(MAKE) $(AM_MAKEFLAGS) check-local -check: check-am -all-am: Makefile -installdirs: -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: - if test -z '$(STRIP)'; then \ - $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ - install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ - install; \ - else \ - $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ - install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ - "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ - fi -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 mostlyclean-am - -distclean: distclean-am - -rm -f Makefile -distclean-am: clean-am distclean-generic - -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-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 -f Makefile -maintainer-clean-am: distclean-am maintainer-clean-generic - -mostlyclean: mostlyclean-am - -mostlyclean-am: mostlyclean-generic mostlyclean-libtool - -pdf: pdf-am - -pdf-am: - -ps: ps-am - -ps-am: - -uninstall-am: - -.MAKE: check-am install-am install-strip - -.PHONY: all all-am check check-am check-local clean clean-generic \ - clean-libtool cscopelist-am ctags-am dist-hook distclean \ - distclean-generic distclean-libtool 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-ps install-ps-am install-strip installcheck \ - installcheck-am installdirs maintainer-clean \ - maintainer-clean-generic mostlyclean mostlyclean-generic \ - mostlyclean-libtool pdf pdf-am ps ps-am tags-am uninstall \ - uninstall-am - -.PRECIOUS: Makefile - - -dist-hook: - @for f in $(ALIAS_FILES); do \ - cp $(abs_srcdir)/$$f $(distdir)/; \ - done - -check-local: - @for f in $(EXTRA_DIST) $(ALIAS_FILES); do \ - chmod 0600 $(abs_srcdir)/$$f; \ - done - -# Make the special temp dir for some written connections - mkdir -p $(abs_builddir)/tmp - -# 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/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-misc-variables b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-misc-variables index c7892a21..1b10cddb 100644 --- a/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-misc-variables +++ b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-misc-variables @@ -1,3 +1,4 @@ DEVICE=eth0 HWADDR_BLACKLIST="00:16:41:11:22:88 00:16:41:11:22:99 XX:aa:invalid 6A:5D:5A:FA:DD:F0" +AUTOCONNECT_RETRIES=100 diff --git a/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-read-proxy-basic b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-read-proxy-basic new file mode 100644 index 00000000..e2cf6c21 --- /dev/null +++ b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-read-proxy-basic @@ -0,0 +1,15 @@ +# Intel Corporation 82540EP Gigabit Ethernet Controller (Mobile) +TYPE=Ethernet +DEVICE=eth0 +HWADDR=00:11:22:33:44:ee +BOOTPROTO=dhcp +ONBOOT=yes +USERCTL=yes +IPV6INIT=no +NM_CONTROLLED=yes +PEERDNS=no + +# proxy configuration +PROXY_METHOD=auto +PAC_URL=http://wpad.mycompany.com/wpad.dat +BROWSER_ONLY=yes diff --git a/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-wpa-psk b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-wpa-psk index 2119ba8e..a78051aa 100644 --- a/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-wpa-psk +++ b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-wpa-psk @@ -16,4 +16,4 @@ CIPHER_GROUP="TKIP CCMP WEP40 WEP104" KEY_MGMT=WPA-PSK WPA_ALLOW_WPA=yes WPA_ALLOW_WPA2=yes - +LAST_ENTRY=no-newline \ No newline at end of file diff --git a/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-auto-negotiate-on b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-auto-negotiate-on new file mode 100644 index 00000000..d0b50775 --- /dev/null +++ b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-auto-negotiate-on @@ -0,0 +1,22 @@ +# Intel Corporation 82540EP Gigabit Ethernet Controller (Mobile) +TYPE=Ethernet +DEVICE=eth0 +HWADDR=00:11:22:33:44:ee +BOOTPROTO=none +ONBOOT=yes +USERCTL=yes +MTU=1492 +NM_CONTROLLED=yes +DNS1=4.2.2.1 +DNS2=4.2.2.2 +IPADDR=192.168.1.5 +NETMASK=255.255.255.0 +GATEWAY=192.168.1.1 +IPV6INIT=yes +IPV6_AUTOCONF=no +IPV6ADDR=dead:beaf::1 +IPV6ADDR_SECONDARIES="dead:beaf::2/56" +DNS3=1:2:3:4::a +DNS4=1:2:3:4::b +RES_OPTIONS= +ETHTOOL_OPTS="wol apgs sopass 00:11:22:33:44:55 autoneg on speed 100" diff --git a/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-dhcpv6-hostname-fallback b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-dhcpv6-hostname-fallback new file mode 100644 index 00000000..d38e762e --- /dev/null +++ b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-dhcpv6-hostname-fallback @@ -0,0 +1,12 @@ +# Intel Corporation 82540EP Gigabit Ethernet Controller (Mobile) +TYPE=Ethernet +DEVICE=eth0 +HWADDR=00:11:22:33:44:ee +BOOTPROTO=dhcp +ONBOOT=yes +IPV6INIT=yes +IPV6_AUTOCONF=yes +USERCTL=yes +NM_CONTROLLED=yes +PEERDNS=no +DHCP_HOSTNAME="fully.qualified.domain" diff --git a/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-unknown-ethtool-opt b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-unknown-ethtool-opt new file mode 100644 index 00000000..861dd41f --- /dev/null +++ b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-unknown-ethtool-opt @@ -0,0 +1,22 @@ +# Intel Corporation 82540EP Gigabit Ethernet Controller (Mobile) +TYPE=Ethernet +DEVICE=eth0 +HWADDR=00:11:22:33:44:ee +BOOTPROTO=none +ONBOOT=yes +USERCTL=yes +MTU=1492 +NM_CONTROLLED=yes +DNS1=4.2.2.1 +DNS2=4.2.2.2 +IPADDR=192.168.1.5 +NETMASK=255.255.255.0 +GATEWAY=192.168.1.1 +IPV6INIT=yes +IPV6_AUTOCONF=no +IPV6ADDR=dead:beaf::1 +IPV6ADDR_SECONDARIES="dead:beaf::2/56" +DNS3=1:2:3:4::a +DNS4=1:2:3:4::b +RES_OPTIONS= +ETHTOOL_OPTS="unknown1 wol apgs sopass 00:11:22:33:44:55 unkwnown2 opt2 unknown3" diff --git a/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-1 b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-1 new file mode 100644 index 00000000..c927389e --- /dev/null +++ b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-1 @@ -0,0 +1,8 @@ +FOO='val + bar=3' +wrong line + F2=b + F3='b +XXX=adf' + XXX2=val2 +' diff --git a/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-1.expected b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-1.expected new file mode 100644 index 00000000..568b2efc --- /dev/null +++ b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-1.expected @@ -0,0 +1,12 @@ +FOO= +#NM: FOO='val +bar= +#NM: bar=3' +#NM: wrong line + F2=b +F3= +#NM: F3='b +XXX= +#NM: XXX=adf' + XXX2=val2 +#NM: ' diff --git a/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-2 b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-2 new file mode 100644 index 00000000..850149b2 --- /dev/null +++ b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-2 @@ -0,0 +1,3 @@ +FOO=' +BAR=a +' diff --git a/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-2.expected b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-2.expected new file mode 100644 index 00000000..6ec53c17 --- /dev/null +++ b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-2.expected @@ -0,0 +1,4 @@ +FOO= +#NM: FOO=' +BAR=a +#NM: ' diff --git a/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-3 b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-3 new file mode 100644 index 00000000..3d198e00 --- /dev/null +++ b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-3 @@ -0,0 +1,3 @@ +FOO=' +BAR=" +' diff --git a/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-3.expected b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-3.expected new file mode 100644 index 00000000..d2b27eb3 --- /dev/null +++ b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-3.expected @@ -0,0 +1,5 @@ +FOO= +#NM: FOO=' +BAR= +#NM: BAR=" +#NM: ' diff --git a/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-4 b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-4 new file mode 100644 index 00000000..a7156e33 --- /dev/null +++ b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-4 @@ -0,0 +1,36 @@ +# test what happens with multiple defines of a name. +# +# Note that svGetValue() will return "l4x", which +# isn't correct in terms of shell-parsing. But we +# don't consider only line-by-line, thus this is +# expected. +# +# Also note that setting NAME will replace the last +# occurance, and delete all previous once. + +#L1 +NAME=l2 + +#L2 +NAME=l3 + +some_key1='' +some_key2=$'\U0x' +some_key3=$'x\U0' + +#L4 +NAME=' +NAME=l4x +' + +#Lx-1 +NAME2=not-visible +#Lx-2 +NAME2='invalid +#Lx-3 + +#Ly-1 +NAME3='invalid +#Ly-2 +NAME3=name3-value +#Ly-3 diff --git a/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-4.expected b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-4.expected new file mode 100644 index 00000000..674df840 --- /dev/null +++ b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-4.expected @@ -0,0 +1,31 @@ +# test what happens with multiple defines of a name. +# +# Note that svGetValue() will return "l4x", which +# isn't correct in terms of shell-parsing. But we +# don't consider only line-by-line, thus this is +# expected. +# +# Also note that setting NAME will replace the last +# occurance, and delete all previous once. + +#L1 + +#L2 + +some_key1='' +some_key2=$'\U0x' +some_key3=$'x\U0' + +#L4 +NAME=set-by-test1 +#NM: ' + +#Lx-1 +#Lx-2 +NAME2=set-by-test2 +#Lx-3 + +#Ly-1 +#Ly-2 +NAME3=set-by-test3 +#Ly-3 diff --git a/src/settings/plugins/ifcfg-rh/tests/network-scripts/keys-test-wifi-wpa-psk-2 b/src/settings/plugins/ifcfg-rh/tests/network-scripts/keys-test-wifi-wpa-psk-2 index 6a63e817..995721dd 100644 --- a/src/settings/plugins/ifcfg-rh/tests/network-scripts/keys-test-wifi-wpa-psk-2 +++ b/src/settings/plugins/ifcfg-rh/tests/network-scripts/keys-test-wifi-wpa-psk-2 @@ -1,2 +1,2 @@ -WPA_PSK=$'They\'re really saying I love you. >>`<< \' +WPA_PSK="They're really saying I love you. >>\`<< '" diff --git a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh-utils.c b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh-utils.c deleted file mode 100644 index d2a348bb..00000000 --- a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh-utils.c +++ /dev/null @@ -1,155 +0,0 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* NetworkManager system settings service - keyfile plugin - * - * 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 - 2011 Red Hat, Inc. - */ - -#include "nm-default.h" - -#include -#include -#include -#include - -#include "common.h" -#include "utils.h" - -#include "nm-test-utils-core.h" - -static void -test_get_ifcfg_name (const char *desc, - const char *path, - gboolean only_ifcfg, - const char *expected) -{ - const char *result; - - result = utils_get_ifcfg_name (path, only_ifcfg); - g_assert_cmpstr (result, ==, expected); -} - -static void -test_get_ifcfg_path (const char *desc, - const char *path, - const char *expected) -{ - char *result; - - result = utils_get_ifcfg_path (path); - g_assert_cmpstr (result, ==, expected); - g_free (result); -} - -static void -test_get_keys_path (const char *desc, - const char *path, - const char *expected) -{ - char *result; - - result = utils_get_keys_path (path); - g_assert_cmpstr (result, ==, expected); - g_free (result); -} - -static void -test_get_route_path (const char *desc, - const char *path, - const char *expected) -{ - char *result; - - result = utils_get_route_path (path); - g_assert_cmpstr (result, ==, expected); - g_free (result); -} - -static void -test_ignored (const char *desc, const char *path, gboolean expected_ignored) -{ - gboolean result; - - result = utils_should_ignore_file (path, FALSE); - g_assert (result == expected_ignored); -} - -static void -test_name (void) -{ - test_get_ifcfg_name ("get-ifcfg-name-bad", "/foo/bar/adfasdfadf", FALSE, NULL); - test_get_ifcfg_name ("get-ifcfg-name-good", "/foo/bar/ifcfg-FooBar", FALSE, "FooBar"); - test_get_ifcfg_name ("get-ifcfg-name-keys", "/foo/bar/keys-BlahLbah", FALSE, "BlahLbah"); - test_get_ifcfg_name ("get-ifcfg-name-route", "/foo/bar/route-Lalalala", FALSE, "Lalalala"); - test_get_ifcfg_name ("get-ifcfg-name-only-ifcfg-route", "/foo/bar/route-Lalalala", TRUE, NULL); - test_get_ifcfg_name ("get-ifcfg-name-only-ifcfg-keys", "/foo/bar/keys-Lalalala", TRUE, NULL); - test_get_ifcfg_name ("get-ifcfg-name-no-path-ifcfg", "ifcfg-Lalalala", FALSE, "Lalalala"); - test_get_ifcfg_name ("get-ifcfg-name-no-path-keys", "keys-Lalalala", FALSE, "Lalalala"); - test_get_ifcfg_name ("get-ifcfg-name-no-path-route", "route-Lalalala", FALSE, "Lalalala"); - - test_get_ifcfg_name ("get-ifcfg-name-bad2-ifcfg", "/foo/bar/asdfasifcfg-Foobar", FALSE, NULL); - test_get_ifcfg_name ("get-ifcfg-name-bad2-keys", "/foo/bar/asdfaskeys-Foobar", FALSE, NULL); - test_get_ifcfg_name ("get-ifcfg-name-bad2-route", "/foo/bar/asdfasroute-Foobar", FALSE, NULL); -} - -static void -test_path (void) -{ - test_get_ifcfg_path ("ifcfg-path-bad", "/foo/bar/adfasdfasdf", NULL); - test_get_ifcfg_path ("ifcfg-path-from-keys-no-path", "keys-BlahBlah", "ifcfg-BlahBlah"); - test_get_ifcfg_path ("ifcfg-path-from-keys", "/foo/bar/keys-BlahBlah", "/foo/bar/ifcfg-BlahBlah"); - test_get_ifcfg_path ("ifcfg-path-from-route", "/foo/bar/route-BlahBlah", "/foo/bar/ifcfg-BlahBlah"); - - test_get_keys_path ("keys-path-bad", "/foo/bar/asdfasdfasdfasdf", NULL); - test_get_keys_path ("keys-path-from-ifcfg-no-path", "ifcfg-FooBar", "keys-FooBar"); - test_get_keys_path ("keys-path-from-ifcfg", "/foo/bar/ifcfg-FooBar", "/foo/bar/keys-FooBar"); - test_get_keys_path ("keys-path-from-route", "/foo/bar/route-FooBar", "/foo/bar/keys-FooBar"); - - test_get_route_path ("route-path-bad", "/foo/bar/asdfasdfasdfasdf", NULL); - test_get_route_path ("route-path-from-ifcfg-no-path", "ifcfg-FooBar", "route-FooBar"); - test_get_route_path ("route-path-from-ifcfg", "/foo/bar/ifcfg-FooBar", "/foo/bar/route-FooBar"); - test_get_route_path ("route-path-from-keys", "/foo/bar/keys-FooBar", "/foo/bar/route-FooBar"); -} - -static void -test_ignore (void) -{ - test_ignored ("ignored-ifcfg", "ifcfg-FooBar", FALSE); - test_ignored ("ignored-keys", "keys-FooBar", FALSE); - test_ignored ("ignored-route", "route-FooBar", FALSE); - test_ignored ("ignored-bak", "ifcfg-FooBar" BAK_TAG, TRUE); - test_ignored ("ignored-tilde", "ifcfg-FooBar" TILDE_TAG, TRUE); - test_ignored ("ignored-orig", "ifcfg-FooBar" ORIG_TAG, TRUE); - test_ignored ("ignored-rej", "ifcfg-FooBar" REJ_TAG, TRUE); - test_ignored ("ignored-rpmnew", "ifcfg-FooBar" RPMNEW_TAG, TRUE); - test_ignored ("ignored-augnew", "ifcfg-FooBar" AUGNEW_TAG, TRUE); - test_ignored ("ignored-augtmp", "ifcfg-FooBar" AUGTMP_TAG, TRUE); -} - -NMTST_DEFINE (); - -int main (int argc, char **argv) -{ - nmtst_init_assert_logging (&argc, &argv, "INFO", "DEFAULT"); - - /* The tests */ - g_test_add_func ("/settings/plugins/ifcfg-rh/name", test_name); - g_test_add_func ("/settings/plugins/ifcfg-rh/path", test_path); - g_test_add_func ("/settings/plugins/ifcfg-rh/ignore", test_ignore); - - return g_test_run (); -} - diff --git a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c index 9ed48beb..1a8439f6 100644 --- a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c +++ b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c @@ -50,15 +50,60 @@ #include "NetworkManagerUtils.h" -#include "common.h" -#include "reader.h" -#include "writer.h" -#include "utils.h" +#include "settings/plugins/ifcfg-rh/nms-ifcfg-rh-common.h" +#include "settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.h" +#include "settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.h" +#include "settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.h" #include "nm-test-utils-core.h" +#define TEST_SCRATCH_DIR_TMP TEST_SCRATCH_DIR"/network-scripts/tmp" + /*****************************************************************************/ +#define _svOpenFile(testfile) \ + ({ \ + shvarFile *_f; \ + GError *_error = NULL; \ + const char *_testfile = (testfile); \ + \ + g_assert (_testfile); \ + _f = svOpenFile (_testfile, &_error); \ + nmtst_assert_success (_f, _error); \ + _f; \ + }) + +#define _svGetValue_check(f, key, expected_value) \ + G_STMT_START { \ + const char *_val; \ + gs_free char *_to_free = NULL; \ + gs_free char *_val_string = NULL; \ + shvarFile *const _f = (f); \ + const char *const _key = (key); \ + \ + _val_string = svGetValueString (_f, _key); \ + _val = svGetValue (_f, _key, &_to_free); \ + g_assert_cmpstr (_val, ==, (expected_value)); \ + g_assert ( (!_val_string && (!_val || !_val[0])) \ + || ( _val_string && nm_streq0 (_val, _val_string))); \ + } G_STMT_END + +#define _writer_update_connection(connection, ifcfg_dir, filename) \ + G_STMT_START { \ + NMConnection *_connection = (connection); \ + const char *_ifcfg_dir = (ifcfg_dir); \ + const char *_filename = (filename); \ + GError *_error = NULL; \ + gboolean _success; \ + \ + g_assert (NM_IS_CONNECTION (connection)); \ + g_assert (_ifcfg_dir && _ifcfg_dir[0]); \ + g_assert (_filename && _filename[0]); \ + \ + _success = writer_update_connection (_connection, _ifcfg_dir, _filename, &_error); \ + nmtst_assert_success (_success, _error); \ + } G_STMT_END + static NMConnection * _connection_from_file (const char *filename, const char *network_file, @@ -273,6 +318,7 @@ test_read_basic (void) g_assert_cmpstr (nm_setting_connection_get_id (s_con), ==, "System test-minimal"); g_assert_cmpint (nm_setting_connection_get_timestamp (s_con), ==, 0); g_assert (nm_setting_connection_get_autoconnect (s_con)); + g_assert_cmpint (nm_setting_connection_get_autoconnect_retries (s_con), ==, -1); /* UUID can't be tested if the ifcfg does not contain the UUID key, because * the UUID is generated on the full path of the ifcfg file, which can change @@ -326,6 +372,7 @@ test_read_miscellaneous_variables (void) g_assert (s_con); g_assert_cmpint (nm_setting_connection_get_timestamp (s_con), ==, expected_timestamp); g_assert (nm_setting_connection_get_autoconnect (s_con)); + g_assert_cmpint (nm_setting_connection_get_autoconnect_retries (s_con), ==, 100); /* ===== WIRED SETTING ===== */ s_wired = nm_connection_get_setting_wired (connection); @@ -363,8 +410,8 @@ test_read_variables_corner_cases (void) /* ===== CONNECTION SETTING ===== */ s_con = nm_connection_get_setting_connection (connection); g_assert (s_con); - g_assert_cmpstr (nm_setting_connection_get_id (s_con), ==, "\""); - g_assert_cmpstr (nm_setting_connection_get_zone (s_con), ==, "'"); + g_assert_cmpstr (nm_setting_connection_get_id (s_con), ==, "System test-variables-corner-cases-1"); + g_assert_cmpstr (nm_setting_connection_get_zone (s_con), ==, NULL); g_assert_cmpint (nm_setting_connection_get_timestamp (s_con), ==, 0); g_assert (nm_setting_connection_get_autoconnect (s_con)); @@ -449,7 +496,7 @@ test_read_unrecognized (void) /* ===== CONNECTION SETTING ===== */ s_con = nm_connection_get_setting_connection (connection); g_assert (s_con); - g_assert_cmpstr (nm_setting_connection_get_id (s_con), ==, "U Can't Touch This"); + g_assert_cmpstr (nm_setting_connection_get_id (s_con), ==, "System test-unrecognized"); g_assert_cmpint (nm_setting_connection_get_timestamp (s_con), ==, expected_timestamp); g_object_unref (connection); @@ -1493,9 +1540,10 @@ test_read_wired_8021x_tls_secret_flags (gconstpointer test_data) static void test_read_write_802_1X_subj_matches (void) { - NMConnection *connection, *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSetting8021x *s_8021x; - char *written = NULL; g_test_expect_message ("NetworkManager", G_LOG_LEVEL_MESSAGE, "*missing IEEE_8021X_CA_CERT*peap*"); @@ -1521,14 +1569,12 @@ test_read_write_802_1X_subj_matches (void) _writer_new_connection (connection, TEST_SCRATCH_DIR "/network-scripts/", - &written); + &testfile); g_test_expect_message ("NetworkManager", G_LOG_LEVEL_MESSAGE, "*missing IEEE_8021X_CA_CERT*peap*"); - reread = _connection_from_file (written, NULL, TYPE_ETHERNET, NULL); + reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); g_test_assert_expected_messages (); - unlink (written); - g_free (written); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); @@ -1547,9 +1593,6 @@ test_read_write_802_1X_subj_matches (void) g_assert_cmpint (nm_setting_802_1x_get_num_phase2_altsubject_matches (s_8021x), ==, 2); g_assert_cmpstr (nm_setting_802_1x_get_phase2_altsubject_match (s_8021x, 0), ==, "x.yourdomain.tld"); g_assert_cmpstr (nm_setting_802_1x_get_phase2_altsubject_match (s_8021x, 1), ==, "y.yourdomain.tld"); - - g_object_unref (connection); - g_object_unref (reread); } static void @@ -1741,14 +1784,12 @@ test_read_dns_options (void) static void test_clear_master (void) { + nmtst_auto_unlinkfile char *testfile = NULL; + gs_free char *keyfile = NULL; + gs_unref_object NMConnection *connection = NULL; NMSettingConnection *s_con; - NMConnection *connection; char *unmanaged = NULL; - char *testfile = NULL, *keyfile; - GError *error = NULL; - gboolean success; shvarFile *f; - char *val; /* 1. load the bridge slave connection from disk */ connection = _connection_from_file (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-bridge-component", @@ -1776,47 +1817,33 @@ test_clear_master (void) g_assert_cmpstr (nm_setting_connection_get_slave_type (s_con), ==, NULL); /* 4. update the connection on disk */ + _writer_update_connection (connection, + TEST_SCRATCH_DIR "/network-scripts/", + testfile); keyfile = utils_get_keys_path (testfile); - success = writer_update_connection (connection, - TEST_SCRATCH_DIR "/network-scripts/", - testfile, - keyfile, - &error); - g_assert_no_error (error); - g_assert (success); - unlink (keyfile); - g_free (keyfile); + g_assert (!g_file_test (keyfile, G_FILE_TEST_EXISTS)); /* 5. check that BRIDGE variable has been removed */ - f = svOpenFile (testfile, &error); - g_assert_no_error (error); - g_assert (f); - - val = svGetValue (f, "BRIDGE", FALSE); - g_assert (!val); + f = _svOpenFile (testfile); + _svGetValue_check (f, "BRIDGE", NULL); svCloseFile (f); - - unlink (testfile); - g_free (testfile); - g_object_unref (connection); } static void test_write_dns_options (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWired *s_wired; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; static const char *mac = "31:33:33:37:be:cd"; guint32 mtu = 1492; - char *uuid; NMIPAddress *addr; NMIPAddress *addr6; GError *error = NULL; - char *testfile = NULL; connection = nm_simple_connection_new (); @@ -1824,14 +1851,12 @@ test_write_dns_options (void) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test DNS options", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, NULL); - g_free (uuid); /* Wired setting */ s_wired = (NMSettingWired *) nm_setting_wired_new (); @@ -1882,7 +1907,6 @@ test_write_dns_options (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); - unlink (testfile); /* RES_OPTIONS is copied to both IPv4 and IPv6 settings */ nm_setting_ip_config_clear_dns_options (s_ip4, TRUE); @@ -1894,10 +1918,6 @@ test_write_dns_options (void) nm_setting_ip_config_add_dns_option (s_ip6, "timeout:3"); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_object_unref (connection); - g_object_unref (reread); } static void @@ -2022,6 +2042,30 @@ test_read_wifi_open_ssid_hex (void) g_object_unref (connection); } +static void +test_read_wifi_open_ssid_hex_bad (void) +{ + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection *s_con; + NMSettingWireless *s_wireless; + GBytes *ssid; + const char *expected_ssid = "0x626cxx"; + + connection = _connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wifi-open-ssid-bad-hex", + NULL, TYPE_WIRELESS, NULL); + + s_con = nm_connection_get_setting_connection (connection); + g_assert (s_con); + g_assert_cmpstr (nm_setting_connection_get_id (s_con), ==, "System 0x626cxx (test-wifi-open-ssid-bad-hex)"); + + s_wireless = nm_connection_get_setting_wireless (connection); + g_assert (s_wireless); + + ssid = nm_setting_wireless_get_ssid (s_wireless); + g_assert (ssid); + g_assert_cmpmem (g_bytes_get_data (ssid, NULL), g_bytes_get_size (ssid), expected_ssid, strlen (expected_ssid)); +} + static void test_read_wifi_open_ssid_bad (gconstpointer data) { @@ -2386,6 +2430,16 @@ test_read_wifi_leap_secret_flags (gconstpointer test_data) g_object_unref (connection); } +static void +test_ifcfg_no_trailing_newline (void) +{ + shvarFile *sv; + + sv = _svOpenFile (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-wifi-wpa-psk"); + _svGetValue_check (sv, "LAST_ENTRY", "no-newline"); + svCloseFile (sv); +} + static void test_read_wifi_wpa_psk (void) { @@ -2535,7 +2589,7 @@ test_read_wifi_wpa_psk_2 (void) s_wsec = nm_connection_get_setting_wireless_security (connection); g_assert (s_wsec); - g_assert_cmpstr (nm_setting_wireless_security_get_psk (s_wsec), ==, "They're really saying I love you. >>`<< \\"); + g_assert_cmpstr (nm_setting_wireless_security_get_psk (s_wsec), ==, "They're really saying I love you. >>`<< '"); g_object_unref (connection); } @@ -2574,12 +2628,10 @@ test_read_wifi_wpa_psk_unquoted (void) static void test_read_wifi_wpa_psk_unquoted2 (void) { - /* Ensure a quoted 64-character WPA passphrase will fail since passphrases - * must be between 8 and 63 ASCII characters inclusive per the WPA spec. - */ + gs_unref_object NMConnection *connection = NULL; - _connection_from_file_fail (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-wifi-wpa-psk-unquoted2", - NULL, TYPE_WIRELESS, NULL); + connection = _connection_from_file (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-wifi-wpa-psk-unquoted2", + NULL, TYPE_WIRELESS, NULL); } static void @@ -2932,6 +2984,81 @@ test_read_wired_wake_on_lan (void) g_object_unref (connection); } +static void +test_read_wired_auto_negotiate_off (void) +{ + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection *s_con; + NMSettingWired *s_wired; + + connection = _connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wired-wake-on-lan", + NULL, TYPE_ETHERNET, NULL); + + s_con = nm_connection_get_setting_connection (connection); + g_assert (s_con); + g_assert_cmpstr (nm_setting_connection_get_connection_type (s_con), ==, NM_SETTING_WIRED_SETTING_NAME); + + s_wired = nm_connection_get_setting_wired (connection); + g_assert (s_wired); + + g_assert (!nm_setting_wired_get_auto_negotiate (s_wired)); + g_assert_cmpint (nm_setting_wired_get_speed (s_wired), ==, 100); + g_assert_cmpstr (nm_setting_wired_get_duplex (s_wired), ==, "full"); +} + +static void +test_read_wired_auto_negotiate_on (void) +{ + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection *s_con; + NMSettingWired *s_wired; + + connection = _connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wired-auto-negotiate-on", + NULL, TYPE_ETHERNET, NULL); + + s_con = nm_connection_get_setting_connection (connection); + g_assert (s_con); + g_assert_cmpstr (nm_setting_connection_get_connection_type (s_con), ==, NM_SETTING_WIRED_SETTING_NAME); + + s_wired = nm_connection_get_setting_wired (connection); + g_assert (s_wired); + + g_assert (nm_setting_wired_get_auto_negotiate (s_wired)); + g_assert_cmpint (nm_setting_wired_get_speed (s_wired), ==, 0); + g_assert_cmpstr (nm_setting_wired_get_duplex (s_wired), ==, NULL); +} + +static void +test_read_wired_unknown_ethtool_opt (void) +{ + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection *s_con; + NMSettingWired *s_wired; + + connection = _connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wired-unknown-ethtool-opt", + NULL, TYPE_ETHERNET, NULL); + + s_con = nm_connection_get_setting_connection (connection); + g_assert (s_con); + g_assert_cmpstr (nm_setting_connection_get_connection_type (s_con), ==, NM_SETTING_WIRED_SETTING_NAME); + + s_wired = nm_connection_get_setting_wired (connection); + g_assert (s_wired); + + g_assert (!nm_setting_wired_get_auto_negotiate (s_wired)); + g_assert (!nm_setting_wired_get_speed (s_wired)); + g_assert (!nm_setting_wired_get_duplex (s_wired)); + + g_assert_cmpint (nm_setting_wired_get_wake_on_lan (s_wired), + ==, + NM_SETTING_WIRED_WAKE_ON_LAN_ARP | + NM_SETTING_WIRED_WAKE_ON_LAN_PHY | + NM_SETTING_WIRED_WAKE_ON_LAN_MAGIC); + g_assert_cmpstr (nm_setting_wired_get_wake_on_lan_password (s_wired), + ==, + "00:11:22:33:44:55"); +} + static void test_read_wifi_hidden (void) { @@ -2956,11 +3083,11 @@ test_read_wifi_hidden (void) static void test_write_wifi_hidden (void) { - NMConnection *connection, *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWireless *s_wifi; - char *uuid, *testfile = NULL, *val; - GError *error = NULL; shvarFile *f; GBytes *ssid; const unsigned char ssid_data[] = { 0x54, 0x65, 0x73, 0x74, 0x20, 0x53, 0x53, 0x49, 0x44 }; @@ -2971,13 +3098,11 @@ test_write_wifi_hidden (void) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write WiFi Hidden", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); - g_free (uuid); /* Wifi setting */ s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); @@ -2999,33 +3124,21 @@ test_write_wifi_hidden (void) TEST_SCRATCH_DIR "/network-scripts/", &testfile); - f = svOpenFile (testfile, &error); - g_assert_no_error (error); - g_assert (f); - - /* re-read the file to check that what key was written. */ - val = svGetValue (f, "SSID_HIDDEN", FALSE); - g_assert (val); - g_assert_cmpstr (val, ==, "yes"); - g_free (val); + f = _svOpenFile (testfile); + _svGetValue_check (f, "SSID_HIDDEN", "yes"); svCloseFile (f); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); - unlink (testfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_object_unref (connection); - g_object_unref (reread); } static void test_read_wifi_mac_random (gconstpointer user_data) { - NMConnection *connection; + gs_unref_object NMConnection *connection = NULL; + gs_free char *path = NULL; NMSettingWireless *s_wifi; - char *path; const char *name; gpointer value_p; NMSettingMacRandomization value; @@ -3035,23 +3148,21 @@ test_read_wifi_mac_random (gconstpointer user_data) path = g_strdup_printf (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wifi-mac-random-%s", name); connection = _connection_from_file (path, NULL, TYPE_WIRELESS, NULL); - g_free (path); s_wifi = nm_connection_get_setting_wireless (connection); g_assert (s_wifi); g_assert_cmpint (nm_setting_wireless_get_mac_address_randomization (s_wifi), ==, value); - - g_object_unref (connection); } static void test_write_wifi_mac_random (gconstpointer user_data) { - NMConnection *connection, *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWireless *s_wifi; - char *uuid, *testfile = NULL, *val; - GError *error = NULL; + char *val; shvarFile *f; GBytes *ssid; const unsigned char ssid_data[] = { 0x54, 0x65, 0x73, 0x74, 0x20, 0x53, 0x53, 0x49, 0x44 }; @@ -3070,14 +3181,12 @@ test_write_wifi_mac_random (gconstpointer user_data) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); val = g_strdup_printf ("Test Write WiFi MAC %s", name); g_object_set (s_con, NM_SETTING_CONNECTION_ID, val, - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); - g_free (uuid); g_free (val); /* Wifi setting */ @@ -3098,35 +3207,25 @@ test_write_wifi_mac_random (gconstpointer user_data) TEST_SCRATCH_DIR "/network-scripts/", &testfile); - f = svOpenFile (testfile, &error); - g_assert_no_error (error); - g_assert (f); - - /* re-read the file to check that what key was written. */ - val = svGetValue (f, "MAC_ADDRESS_RANDOMIZATION", FALSE); - g_assert_cmpstr (val, ==, write_expected); - g_free (val); + f = _svOpenFile (testfile); + _svGetValue_check (f, "MAC_ADDRESS_RANDOMIZATION", write_expected); svCloseFile (f); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); - unlink (testfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_object_unref (connection); - g_object_unref (reread); } static void test_write_wired_wake_on_lan (void) { - NMConnection *connection, *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWired *s_wired; NMSettingWiredWakeOnLan wol; - char *uuid, *testfile = NULL, *val; - GError *error = NULL; + char *val; shvarFile *f; connection = nm_simple_connection_new (); @@ -3135,13 +3234,11 @@ test_write_wired_wake_on_lan (void) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write Wired Wake-on-LAN", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, NULL); - g_free (uuid); /* Wired setting */ s_wired = (NMSettingWired *) nm_setting_wired_new (); @@ -3162,12 +3259,8 @@ test_write_wired_wake_on_lan (void) TEST_SCRATCH_DIR "/network-scripts/", &testfile); - f = svOpenFile (testfile, &error); - g_assert_no_error (error); - g_assert (f); - - /* re-read the file to check that the key was written. */ - val = svGetValue (f, "ETHTOOL_OPTS", FALSE); + f = _svOpenFile (testfile); + val = svGetValueString (f, "ETHTOOL_OPTS"); g_assert (val); g_assert (strstr (val, "wol")); g_assert (strstr (val, "sopass 00:00:00:11:22:33")); @@ -3175,13 +3268,78 @@ test_write_wired_wake_on_lan (void) svCloseFile (f); reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); - unlink (testfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); +} - g_free (testfile); - g_object_unref (connection); - g_object_unref (reread); +static void +test_write_wired_auto_negotiate_off (void) +{ + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; + NMSettingWired *s_wired; + char *val; + shvarFile *f; + + connection = nmtst_create_minimal_connection ("Test Write Wired Auto-Negotiate", NULL, NM_SETTING_WIRED_SETTING_NAME, NULL); + s_wired = nm_connection_get_setting_wired (connection); + g_object_set (s_wired, + NM_SETTING_WIRED_AUTO_NEGOTIATE, FALSE, + NM_SETTING_WIRED_DUPLEX, "half", + NM_SETTING_WIRED_SPEED, 10, + NULL); + + _writer_new_connection (connection, + TEST_SCRATCH_DIR "/network-scripts/", + &testfile); + + f = _svOpenFile (testfile); + val = svGetValueString (f, "ETHTOOL_OPTS"); + g_assert (val); + g_assert (strstr (val, "autoneg off")); + g_assert (strstr (val, "speed 10")); + g_assert (strstr (val, "duplex half")); + g_free (val); + svCloseFile (f); + + reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); + + nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); +} + +static void +test_write_wired_auto_negotiate_on (void) +{ + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; + NMSettingWired *s_wired; + char *val; + shvarFile *f; + + connection = nmtst_create_minimal_connection ("Test Write Wired Auto-Negotiate", NULL, NM_SETTING_WIRED_SETTING_NAME, NULL); + s_wired = nm_connection_get_setting_wired (connection); + g_object_set (s_wired, + NM_SETTING_WIRED_AUTO_NEGOTIATE, TRUE, + NULL); + + _writer_new_connection (connection, + TEST_SCRATCH_DIR "/network-scripts/", + &testfile); + + f = _svOpenFile (testfile); + val = svGetValueString (f, "ETHTOOL_OPTS"); + g_assert (val); + g_assert (strstr (val, "autoneg on")); + g_assert (!strstr (val, "speed")); + g_assert (!strstr (val, "duplex")); + g_free (val); + svCloseFile (f); + + reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); + + nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); } static void @@ -3208,11 +3366,11 @@ test_read_wifi_band_a (void) static void test_write_wifi_band_a (void) { - NMConnection *connection, *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWireless *s_wifi; - char *uuid, *testfile = NULL, *val; - GError *error = NULL; shvarFile *f; GBytes *ssid; const unsigned char ssid_data[] = { 0x54, 0x65, 0x73, 0x74, 0x20, 0x53, 0x53, 0x49, 0x44 }; @@ -3223,13 +3381,11 @@ test_write_wifi_band_a (void) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write WiFi Band A", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); - g_free (uuid); /* Wifi setting */ s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); @@ -3251,25 +3407,13 @@ test_write_wifi_band_a (void) TEST_SCRATCH_DIR "/network-scripts/", &testfile); - f = svOpenFile (testfile, &error); - g_assert_no_error (error); - g_assert (f); - - /* re-read the file to check that what key was written. */ - val = svGetValue (f, "BAND", FALSE); - g_assert (val); - g_assert_cmpstr (val, ==, "a"); - g_free (val); + f = _svOpenFile (testfile); + _svGetValue_check (f, "BAND", "a"); svCloseFile (f); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); - unlink (testfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_object_unref (connection); - g_object_unref (reread); } static void @@ -3510,19 +3654,18 @@ test_read_wifi_wep_agent_keys (void) static void test_write_wired_static (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *route6file = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWired *s_wired; NMSettingIPConfig *s_ip4, *reread_s_ip4; NMSettingIPConfig *s_ip6, *reread_s_ip6; - char *uuid; NMIPAddress *addr; NMIPAddress *addr6; NMIPRoute *route6; GError *error = NULL; - char *testfile = NULL; - char *route6file = NULL; connection = nm_simple_connection_new (); @@ -3530,14 +3673,13 @@ test_write_wired_static (void) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write Wired Static", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, + NM_SETTING_CONNECTION_AUTOCONNECT_RETRIES, 1, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, NULL); - g_free (uuid); /* Wired setting */ s_wired = (NMSettingWired *) nm_setting_wired_new (); @@ -3627,9 +3769,9 @@ test_write_wired_static (void) _writer_new_connection (connection, TEST_SCRATCH_DIR "/network-scripts/", &testfile); + route6file = utils_get_route6_path (testfile); reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); - unlink (testfile); /* FIXME: currently DNS domains from IPv6 setting are stored in 'DOMAIN' key in ifcfg-file * However after re-reading they are dropped into IPv4 setting. @@ -3645,28 +3787,21 @@ test_write_wired_static (void) g_assert_cmpint (nm_setting_ip_config_get_route_metric (reread_s_ip4), ==, 204); g_assert_cmpint (nm_setting_ip_config_get_route_metric (reread_s_ip6), ==, 206); - nmtst_assert_connection_equals (connection, FALSE, reread, FALSE); - - route6file = utils_get_route6_path (testfile); - unlink (route6file); + nm_connection_add_setting (connection, nm_setting_proxy_new ()); - g_free (testfile); - g_free (route6file); - g_object_unref (connection); - g_object_unref (reread); + nmtst_assert_connection_equals (connection, FALSE, reread, FALSE); } static void test_write_wired_dhcp (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWired *s_wired; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - char *uuid; - char *testfile = NULL; connection = nm_simple_connection_new (); @@ -3674,14 +3809,12 @@ test_write_wired_dhcp (void) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write Wired DHCP", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, NULL); - g_free (uuid); /* Wired setting */ s_wired = (NMSettingWired *) nm_setting_wired_new (); @@ -3715,46 +3848,38 @@ test_write_wired_dhcp (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); - unlink (testfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_object_unref (connection); - g_object_unref (reread); } static void test_write_wired_dhcp_plus_ip (void) { - NMConnection *connection, *reread; - char *written = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; connection = _connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wired-dhcp-plus-ip", NULL, TYPE_ETHERNET, NULL); _writer_new_connection (connection, TEST_SCRATCH_DIR "/network-scripts/", - &written); + &testfile); - reread = _connection_from_file (written, NULL, TYPE_ETHERNET, NULL); - unlink (written); - g_free (written); + reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_object_unref (connection); - g_object_unref (reread); } static void test_read_write_wired_dhcp_send_hostname (void) { - NMConnection *connection, *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; const char * dhcp_hostname = "kamil-patka"; - char *written = NULL; connection = _connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wired-dhcp-send-hostname", NULL, TYPE_ETHERNET, NULL); @@ -3766,7 +3891,7 @@ test_read_write_wired_dhcp_send_hostname (void) g_assert (s_ip6); g_assert (nm_setting_ip_config_get_dhcp_send_hostname (s_ip4) == TRUE); g_assert_cmpstr (nm_setting_ip_config_get_dhcp_hostname (s_ip4), ==, "svata-pulec"); - g_assert_cmpstr (nm_setting_ip_config_get_dhcp_hostname (s_ip6), ==, "svata-pulec"); + g_assert (!nm_setting_ip_config_get_dhcp_hostname (s_ip6)); /* Set dhcp-send-hostname=false dhcp-hostname="kamil-patka" and write the connection. */ g_object_set (s_ip4, NM_SETTING_IP_CONFIG_DHCP_SEND_HOSTNAME, FALSE, NULL); @@ -3775,11 +3900,9 @@ test_read_write_wired_dhcp_send_hostname (void) _writer_new_connection (connection, TEST_SCRATCH_DIR "/network-scripts/", - &written); + &testfile); - reread = _connection_from_file (written, NULL, TYPE_ETHERNET, NULL); - unlink (written); - g_free (written); + reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); @@ -3791,24 +3914,35 @@ test_read_write_wired_dhcp_send_hostname (void) g_assert (nm_setting_ip_config_get_dhcp_send_hostname (s_ip4) == FALSE); g_assert_cmpstr (nm_setting_ip_config_get_dhcp_hostname (s_ip4), ==, dhcp_hostname); g_assert_cmpstr (nm_setting_ip_config_get_dhcp_hostname (s_ip6), ==, dhcp_hostname); +} - g_object_unref (connection); - g_object_unref (reread); +static void +test_read_wired_dhcpv6_hostname_fallback (void) +{ + gs_unref_object NMConnection *connection = NULL; + NMSettingIPConfig *s_ip6; + + connection = _connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wired-dhcpv6-hostname-fallback", + NULL, TYPE_ETHERNET, NULL); + + s_ip6 = nm_connection_get_setting_ip6_config (connection); + g_assert (s_ip6); + g_assert (nm_setting_ip_config_get_dhcp_send_hostname (s_ip6) == TRUE); + g_assert_cmpstr (nm_setting_ip_config_get_dhcp_hostname (s_ip6), ==, "fully.qualified.domain"); } static void test_write_wired_static_ip6_only (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWired *s_wired; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - char *uuid; NMIPAddress *addr6; GError *error = NULL; - char *testfile = NULL; connection = nm_simple_connection_new (); @@ -3816,14 +3950,12 @@ test_write_wired_static_ip6_only (void) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write Wired Static IP6 Only", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, NULL); - g_free (uuid); /* Wired setting */ s_wired = (NMSettingWired *) nm_setting_wired_new (); @@ -3863,13 +3995,8 @@ test_write_wired_static_ip6_only (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); - unlink (testfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_object_unref (connection); - g_object_unref (reread); } /* Test writing an IPv6 config with varying gateway address. @@ -3883,19 +4010,19 @@ test_write_wired_static_ip6_only (void) static void test_write_wired_static_ip6_only_gw (gconstpointer user_data) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWired *s_wired; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - char *uuid; NMIPAddress *addr6; GError *error = NULL; - char *testfile = NULL; char *id = NULL; - char *written_ifcfg_gateway; + gs_free char *written_ifcfg_gateway = NULL; const char *gateway6 = user_data; + shvarFile *ifcfg; connection = nm_simple_connection_new (); @@ -3903,15 +4030,13 @@ test_write_wired_static_ip6_only_gw (gconstpointer user_data) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); id = g_strdup_printf ("Test Write Wired Static IP6 Only With Gateway %s", gateway6 ? gateway6 : "NULL"); g_object_set (s_con, NM_SETTING_CONNECTION_ID, id, - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, NULL); - g_free (uuid); g_free (id); /* Wired setting */ @@ -3956,17 +4081,9 @@ test_write_wired_static_ip6_only_gw (gconstpointer user_data) nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - { - /* re-read the file to check that what key was written. */ - shvarFile *ifcfg = svOpenFile (testfile, &error); - - g_assert_no_error (error); - g_assert (ifcfg); - written_ifcfg_gateway = svGetValue (ifcfg, "IPV6_DEFAULTGW", FALSE); - svCloseFile (ifcfg); - } - - unlink (testfile); + ifcfg = _svOpenFile (testfile); + written_ifcfg_gateway = svGetValueString (ifcfg, "IPV6_DEFAULTGW"); + svCloseFile (ifcfg); /* access the gateway from the loaded connection. */ s_ip6 = nm_connection_get_setting_ip6_config (reread); @@ -3983,23 +4100,19 @@ test_write_wired_static_ip6_only_gw (gconstpointer user_data) g_assert_cmpstr (nm_setting_ip_config_get_gateway (s_ip6), ==, gateway6); g_assert_cmpstr (written_ifcfg_gateway, ==, gateway6); } - - g_free (testfile); - g_free (written_ifcfg_gateway); - g_object_unref (connection); - g_object_unref (reread); } static void test_read_write_static_routes_legacy (void) { - NMConnection *connection, *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *routefile = NULL; + gs_free char *route6file = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWired *s_wired; NMSettingIPConfig *s_ip4; - char *testfile = NULL; - char *routefile = NULL; - char *route6file = NULL; const char *tmp; connection = _connection_from_file (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-static-routes-legacy", @@ -4035,40 +4148,31 @@ test_read_write_static_routes_legacy (void) * source tree and for 'make distcheck'. */ _writer_new_connection (connection, - TEST_SCRATCH_DIR "/network-scripts/tmp", + TEST_SCRATCH_DIR_TMP, &testfile); reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); - unlink (testfile); routefile = utils_get_route_path (testfile); - unlink (routefile); route6file = utils_get_route6_path (testfile); - unlink (route6file); + g_assert (!g_file_test (route6file, G_FILE_TEST_EXISTS)); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_free (routefile); - g_free (route6file); - g_object_unref (connection); - g_object_unref (reread); } static void test_write_wired_static_routes (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *routefile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWired *s_wired; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - char *uuid; NMIPAddress *addr; NMIPRoute *route; GError *error = NULL; - char *testfile = NULL; - char *routefile = NULL; connection = nm_simple_connection_new (); @@ -4076,14 +4180,12 @@ test_write_wired_static_routes (void) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write Wired Static Routes", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, NULL); - g_free (uuid); /* Wired setting */ s_wired = (NMSettingWired *) nm_setting_wired_new (); @@ -4146,34 +4248,26 @@ test_write_wired_static_routes (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); - unlink (testfile); routefile = utils_get_route_path (testfile); - unlink (routefile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_free (routefile); - g_object_unref (connection); - g_object_unref (reread); -} +} static void test_write_wired_dhcp_8021x_peap_mschapv2 (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *keyfile = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWired *s_wired; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; NMSetting8021x *s_8021x; - char *uuid; gboolean success; GError *error = NULL; - char *testfile = NULL; - char *keyfile = NULL; connection = nm_simple_connection_new (); @@ -4181,14 +4275,12 @@ test_write_wired_dhcp_8021x_peap_mschapv2 (void) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write Wired DHCP 802.1x PEAP MSCHAPv2", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, NULL); - g_free (uuid); /* Wired setting */ s_wired = (NMSettingWired *) nm_setting_wired_new (); @@ -4238,34 +4330,26 @@ test_write_wired_dhcp_8021x_peap_mschapv2 (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); - unlink (testfile); - - keyfile = utils_get_keys_path (testfile); - unlink (keyfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - g_free (testfile); - g_free (keyfile); - g_object_unref (connection); - g_object_unref (reread); + keyfile = utils_get_keys_path (testfile); } static void test_write_wired_8021x_tls (gconstpointer test_data) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_free char *keyfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWired *s_wired; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; NMSetting8021x *s_8021x; - char *uuid; gboolean success; GError *error = NULL; - char *testfile = NULL; - char *keyfile = NULL; NMSetting8021xCKFormat format = NM_SETTING_802_1X_CK_FORMAT_UNKNOWN; const char *pw; char *tmp; @@ -4278,36 +4362,29 @@ test_write_wired_8021x_tls (gconstpointer test_data) flags = GPOINTER_TO_INT (flags_p); connection = nm_simple_connection_new (); - g_assert (connection != NULL); /* Connection setting */ s_con = (NMSettingConnection *) nm_setting_connection_new (); - g_assert (s_con); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write Wired 802.1x TLS Blobs", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, NULL); - g_free (uuid); /* Wired setting */ s_wired = (NMSettingWired *) nm_setting_wired_new (); - g_assert (s_wired); nm_connection_add_setting (connection, NM_SETTING (s_wired)); /* IP4 setting */ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); - g_assert (s_ip4); g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); /* IP6 setting */ s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new (); - g_assert (s_ip6); g_object_set (s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE, @@ -4316,7 +4393,6 @@ test_write_wired_8021x_tls (gconstpointer test_data) /* 802.1x setting */ s_8021x = (NMSetting8021x *) nm_setting_802_1x_new (); - g_assert (s_8021x); nm_connection_add_setting (connection, NM_SETTING (s_8021x)); g_object_set (s_8021x, NM_SETTING_802_1X_IDENTITY, "Bill Smith", NULL); @@ -4365,9 +4441,9 @@ test_write_wired_8021x_tls (gconstpointer test_data) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); - unlink (testfile); + keyfile = utils_get_keys_path (testfile); - unlink (keyfile); + nmtst_file_unlink_if_exists (keyfile); /* Ensure the reread connection's certificates and private key are paths; no * matter what scheme was used in the original connection they will be read @@ -4411,21 +4487,16 @@ test_write_wired_8021x_tls (gconstpointer test_data) /* Clean up created certs and keys */ tmp = utils_cert_path (testfile, "ca-cert.der"); - unlink (tmp); + nmtst_file_unlink_if_exists (tmp); g_free (tmp); tmp = utils_cert_path (testfile, "client-cert.der"); - unlink (tmp); + nmtst_file_unlink_if_exists (tmp); g_free (tmp); tmp = utils_cert_path (testfile, "private-key.pem"); - unlink (tmp); + nmtst_file_unlink_if_exists (tmp); g_free (tmp); - - g_free (testfile); - g_free (keyfile); - g_object_unref (connection); - g_object_unref (reread); } #define TEST_SCRATCH_ALIAS_BASE TEST_SCRATCH_DIR "/network-scripts/ifcfg-alias0" @@ -4433,45 +4504,43 @@ test_write_wired_8021x_tls (gconstpointer test_data) static void test_write_wired_aliases (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWired *s_wired; NMSettingIPConfig *s_ip4; - char *uuid; int num_addresses = 4; const char *ip[] = { "1.1.1.1", "1.1.1.2", "1.1.1.3", "1.1.1.4" }; const char *label[] = { NULL, "alias0:2", NULL, "alias0:3" }; NMIPAddress *addr; GError *error = NULL; - char *testfile = NULL; shvarFile *ifcfg; int i, j; + nmtst_file_unlink_if_exists (TEST_SCRATCH_ALIAS_BASE ":2"); + nmtst_file_unlink_if_exists (TEST_SCRATCH_ALIAS_BASE ":3"); + nmtst_file_unlink_if_exists (TEST_SCRATCH_ALIAS_BASE ":5"); + connection = nm_simple_connection_new (); g_assert (connection); /* Connection setting */ s_con = (NMSettingConnection *) nm_setting_connection_new (); - g_assert (s_con); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "alias0", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, NULL); - g_free (uuid); /* Wired setting */ s_wired = (NMSettingWired *) nm_setting_wired_new (); - g_assert (s_wired); nm_connection_add_setting (connection, NM_SETTING (s_wired)); /* IP4 setting */ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); - g_assert (s_ip4); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); g_object_set (s_ip4, @@ -4493,15 +4562,15 @@ test_write_wired_aliases (void) /* Create some pre-existing alias files, to make sure they get overwritten / deleted. */ ifcfg = svCreateFile (TEST_SCRATCH_ALIAS_BASE ":2"); - svSetValue (ifcfg, "DEVICE", "alias0:2", FALSE); - svSetValue (ifcfg, "IPADDR", "192.168.1.2", FALSE); + svSetValueString (ifcfg, "DEVICE", "alias0:2"); + svSetValueString (ifcfg, "IPADDR", "192.168.1.2"); svWriteFile (ifcfg, 0644, NULL); svCloseFile (ifcfg); g_assert (g_file_test (TEST_SCRATCH_ALIAS_BASE ":2", G_FILE_TEST_EXISTS)); ifcfg = svCreateFile (TEST_SCRATCH_ALIAS_BASE ":5"); - svSetValue (ifcfg, "DEVICE", "alias0:5", FALSE); - svSetValue (ifcfg, "IPADDR", "192.168.1.5", FALSE); + svSetValueString (ifcfg, "DEVICE", "alias0:5"); + svSetValueString (ifcfg, "IPADDR", "192.168.1.5"); svWriteFile (ifcfg, 0644, NULL); svCloseFile (ifcfg); g_assert (g_file_test (TEST_SCRATCH_ALIAS_BASE ":5", G_FILE_TEST_EXISTS)); @@ -4516,9 +4585,8 @@ test_write_wired_aliases (void) g_assert (!g_file_test (TEST_SCRATCH_ALIAS_BASE ":5", G_FILE_TEST_EXISTS)); reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); - unlink (testfile); - unlink (TEST_SCRATCH_ALIAS_BASE ":2"); - unlink (TEST_SCRATCH_ALIAS_BASE ":3"); + nmtst_file_unlink (TEST_SCRATCH_ALIAS_BASE ":2"); + nmtst_file_unlink (TEST_SCRATCH_ALIAS_BASE ":3"); /* nm_connection_compare() is not guaranteed to succeed, because the * aliases get read back in essentially random order. So just @@ -4555,20 +4623,17 @@ test_write_wired_aliases (void) /* Gateway */ g_assert_cmpstr (nm_setting_ip_config_get_gateway (s_ip4), ==, "1.1.1.1"); - - g_free (testfile); - g_object_unref (connection); - g_object_unref (reread); } static void test_write_gateway (void) { - NMConnection *connection, *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWired *s_wired; NMSettingIPConfig *s_ip4; - char *uuid, *testfile = NULL, *val; GError *error = NULL; shvarFile *f; NMIPAddress *addr; @@ -4579,13 +4644,11 @@ test_write_gateway (void) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write Static Addresses Gateway", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, NULL); - g_free (uuid); /* Wired setting */ s_wired = (NMSettingWired *) nm_setting_wired_new (); @@ -4617,77 +4680,37 @@ test_write_gateway (void) TEST_SCRATCH_DIR "/network-scripts/", &testfile); - f = svOpenFile (testfile, &error); - g_assert_no_error (error); - g_assert (f); - - /* re-read the file to check that the keys was written as IPADDR, GATEWAY and IPADDR1, GATEWAY1 */ - val = svGetValue (f, "IPADDR", FALSE); - g_assert (val); - g_assert_cmpstr (val, ==, "1.1.1.3"); - g_free (val); - - val = svGetValue (f, "IPADDR1", FALSE); - g_assert (val); - g_assert_cmpstr (val, ==, "2.2.2.5"); - g_free (val); - - val = svGetValue (f, "IPADDR0", FALSE); - g_assert (val == NULL); - - val = svGetValue (f, "PREFIX", FALSE); - g_assert (val); - g_assert_cmpstr (val, ==, "24"); - g_free (val); - - val = svGetValue (f, "PREFIX1", FALSE); - g_assert (val); - g_assert_cmpstr (val, ==, "24"); - g_free (val); - - val = svGetValue (f, "PREFIX0", FALSE); - g_assert (val == NULL); - - val = svGetValue (f, "GATEWAY", FALSE); - g_assert (val); - g_assert_cmpstr (val, ==, "1.1.1.254"); - g_free (val); - - val = svGetValue (f, "GATEWAY0", FALSE); - g_assert (val == NULL); - - val = svGetValue (f, "GATEWAY1", FALSE); - g_assert (val == NULL); - + f = _svOpenFile (testfile); + _svGetValue_check (f, "IPADDR", "1.1.1.3"); + _svGetValue_check (f, "IPADDR1", "2.2.2.5"); + _svGetValue_check (f, "IPADDR0", NULL); + _svGetValue_check (f, "PREFIX", "24"); + _svGetValue_check (f, "PREFIX1", "24"); + _svGetValue_check (f, "PREFIX0", NULL); + _svGetValue_check (f, "GATEWAY", "1.1.1.254"); + _svGetValue_check (f, "GATEWAY0", NULL); + _svGetValue_check (f, "GATEWAY1", NULL); svCloseFile (f); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); - unlink (testfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_object_unref (connection); - g_object_unref (reread); } static void test_write_wifi_open (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - char *uuid; - GError *error = NULL; - char *testfile = NULL; GBytes *ssid; const unsigned char ssid_data[] = { 0x54, 0x65, 0x73, 0x74, 0x20, 0x53, 0x53, 0x49, 0x44 }; shvarFile *ifcfg; - char *tmp; connection = nm_simple_connection_new (); @@ -4695,14 +4718,12 @@ test_write_wifi_open (void) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write Wifi Open", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); - g_free (uuid); /* Wifi setting */ s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); @@ -4745,39 +4766,23 @@ test_write_wifi_open (void) reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); - /* Now make sure that the ESSID item isn't double-quoted (rh #606518) */ - ifcfg = svOpenFile (testfile, &error); - g_assert_no_error (error); - g_assert (ifcfg != NULL); - - tmp = svGetValue (ifcfg, "ESSID", TRUE); - g_assert (tmp); - - g_assert (strncmp (tmp, "\"\"", 2) != 0); - - g_free (tmp); + ifcfg = _svOpenFile (testfile); + _svGetValue_check (ifcfg, "ESSID", "Test SSID"); svCloseFile (ifcfg); - unlink (testfile); - nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_object_unref (connection); - g_object_unref (reread); } static void test_write_wifi_open_hex_ssid (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - char *uuid; - char *testfile = NULL; GBytes *ssid; const unsigned char ssid_data[] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd }; @@ -4787,14 +4792,12 @@ test_write_wifi_open_hex_ssid (void) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write Wifi Open Hex SSID", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); - g_free (uuid); /* Wifi setting */ s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); @@ -4831,28 +4834,22 @@ test_write_wifi_open_hex_ssid (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); - unlink (testfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_object_unref (connection); - g_object_unref (reread); } static void test_write_wifi_wep (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *keyfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - char *uuid; - char *testfile = NULL; - char *keyfile = NULL; GBytes *ssid; const char *ssid_data = "blahblah"; struct stat statbuf; @@ -4863,14 +4860,12 @@ test_write_wifi_wep (void) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write Wifi WEP", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); - g_free (uuid); /* Wifi setting */ s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); @@ -4921,36 +4916,28 @@ test_write_wifi_wep (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); - unlink (testfile); keyfile = utils_get_keys_path (testfile); g_assert_cmpint (stat (keyfile, &statbuf), ==, 0); g_assert (S_ISREG (statbuf.st_mode)); g_assert_cmpint ((statbuf.st_mode & 0077), ==, 0); - unlink (keyfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_free (keyfile); - g_object_unref (connection); - g_object_unref (reread); } static void test_write_wifi_wep_adhoc (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *keyfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - char *uuid; GError *error = NULL; - char *testfile = NULL; - char *keyfile = NULL; GBytes *ssid; const char *ssid_data = "blahblah"; struct stat statbuf; @@ -4962,14 +4949,12 @@ test_write_wifi_wep_adhoc (void) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write Wifi WEP AdHoc", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); - g_free (uuid); /* Wifi setting */ s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); @@ -5024,35 +5009,27 @@ test_write_wifi_wep_adhoc (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); - unlink (testfile); keyfile = utils_get_keys_path (testfile); g_assert_cmpint (stat (keyfile, &statbuf), ==, 0); g_assert (S_ISREG (statbuf.st_mode)); g_assert_cmpint ((statbuf.st_mode & 0077), ==, 0); - unlink (keyfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_free (keyfile); - g_object_unref (connection); - g_object_unref (reread); } static void test_write_wifi_wep_passphrase (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *keyfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - char *uuid; - char *testfile = NULL; - char *keyfile = NULL; GBytes *ssid; const char *ssid_data = "blahblah"; struct stat statbuf; @@ -5063,14 +5040,12 @@ test_write_wifi_wep_passphrase (void) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write Wifi WEP Passphrase", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); - g_free (uuid); /* Wifi setting */ s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); @@ -5119,35 +5094,27 @@ test_write_wifi_wep_passphrase (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); - unlink (testfile); keyfile = utils_get_keys_path (testfile); g_assert_cmpint (stat (keyfile, &statbuf), ==, 0); g_assert (S_ISREG (statbuf.st_mode)); g_assert_cmpint ((statbuf.st_mode & 0077), ==, 0); - unlink (keyfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_free (keyfile); - g_object_unref (connection); - g_object_unref (reread); } static void test_write_wifi_wep_40_ascii (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *keyfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - char *uuid; - char *testfile = NULL; - char *keyfile = NULL; GBytes *ssid; const char *ssid_data = "blahblah40"; struct stat statbuf; @@ -5158,14 +5125,12 @@ test_write_wifi_wep_40_ascii (void) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write Wifi WEP 40 ASCII", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); - g_free (uuid); /* Wifi setting */ s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); @@ -5216,35 +5181,27 @@ test_write_wifi_wep_40_ascii (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); - unlink (testfile); keyfile = utils_get_keys_path (testfile); g_assert_cmpint (stat (keyfile, &statbuf), ==, 0); g_assert (S_ISREG (statbuf.st_mode)); g_assert_cmpint ((statbuf.st_mode & 0077), ==, 0); - unlink (keyfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_free (keyfile); - g_object_unref (connection); - g_object_unref (reread); } static void test_write_wifi_wep_104_ascii (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *keyfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - char *uuid; - char *testfile = NULL; - char *keyfile = NULL; GBytes *ssid; const char *ssid_data = "blahblah104"; struct stat statbuf; @@ -5255,14 +5212,12 @@ test_write_wifi_wep_104_ascii (void) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write Wifi WEP 104 ASCII", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); - g_free (uuid); /* Wifi setting */ s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); @@ -5313,36 +5268,27 @@ test_write_wifi_wep_104_ascii (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); - unlink (testfile); keyfile = utils_get_keys_path (testfile); g_assert_cmpint (stat (keyfile, &statbuf), ==, 0); g_assert (S_ISREG (statbuf.st_mode)); g_assert_cmpint ((statbuf.st_mode & 0077), ==, 0); - unlink (keyfile); - nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_free (keyfile); - g_object_unref (connection); - g_object_unref (reread); } static void test_write_wifi_leap (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *keyfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - char *uuid; - char *testfile = NULL; - char *keyfile = NULL; GBytes *ssid; const char *ssid_data = "blahblah"; struct stat statbuf; @@ -5353,14 +5299,12 @@ test_write_wifi_leap (void) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write Wifi LEAP", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); - g_free (uuid); /* Wifi setting */ s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); @@ -5408,35 +5352,27 @@ test_write_wifi_leap (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); - unlink (testfile); keyfile = utils_get_keys_path (testfile); g_assert_cmpint (stat (keyfile, &statbuf), ==, 0); g_assert (S_ISREG (statbuf.st_mode)); g_assert_cmpint ((statbuf.st_mode & 0077), ==, 0); - unlink (keyfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_free (keyfile); - g_object_unref (connection); - g_object_unref (reread); } static void test_write_wifi_leap_secret_flags (gconstpointer data) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_free char *keyfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - char *uuid; - char *testfile = NULL; - char *keyfile = NULL; GBytes *ssid; const char *ssid_data = "blahblah"; NMSettingSecretFlags flags = GPOINTER_TO_UINT (data); @@ -5446,20 +5382,16 @@ test_write_wifi_leap_secret_flags (gconstpointer data) /* Connection setting */ s_con = (NMSettingConnection *) nm_setting_connection_new (); - g_assert (s_con); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write Wifi LEAP Secret Flags", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); - g_free (uuid); /* Wifi setting */ s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); - g_assert (s_wifi); nm_connection_add_setting (connection, NM_SETTING (s_wifi)); ssid = g_bytes_new (ssid_data, strlen (ssid_data)); @@ -5471,7 +5403,6 @@ test_write_wifi_leap_secret_flags (gconstpointer data) /* Wireless security setting */ s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new (); - g_assert (s_wsec); nm_connection_add_setting (connection, NM_SETTING (s_wsec)); g_object_set (s_wsec, @@ -5484,13 +5415,11 @@ test_write_wifi_leap_secret_flags (gconstpointer data) /* IP4 setting */ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); - g_assert (s_ip4); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); /* IP6 setting */ s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new (); - g_assert (s_ip6); nm_connection_add_setting (connection, NM_SETTING (s_ip6)); g_object_set (s_ip6, @@ -5505,7 +5434,6 @@ test_write_wifi_leap_secret_flags (gconstpointer data) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); - unlink (testfile); /* No key should be written out since the secret is not system owned */ keyfile = utils_get_keys_path (testfile); @@ -5516,26 +5444,20 @@ test_write_wifi_leap_secret_flags (gconstpointer data) */ g_object_set (s_wsec, NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD, NULL, NULL); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_free (keyfile); - g_object_unref (connection); - g_object_unref (reread); } static void test_write_wifi_wpa_psk (gconstpointer test_data) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *keyfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - char *uuid; - char *testfile = NULL; - char *keyfile = NULL; GBytes *ssid; const char *ssid_data = "blahblah"; struct { @@ -5553,14 +5475,12 @@ test_write_wifi_wpa_psk (gconstpointer test_data) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, args.name, - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); - g_free (uuid); /* Wifi setting */ s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); @@ -5621,33 +5541,25 @@ test_write_wifi_wpa_psk (gconstpointer test_data) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); - unlink (testfile); keyfile = utils_get_keys_path (testfile); - unlink (keyfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_free (keyfile); - g_object_unref (connection); - g_object_unref (reread); } static void test_write_wifi_wpa_psk_adhoc (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *keyfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - char *uuid; GError *error = NULL; - char *testfile = NULL; - char *keyfile = NULL; GBytes *ssid; const char *ssid_data = "blahblah"; NMIPAddress *addr; @@ -5658,14 +5570,12 @@ test_write_wifi_wpa_psk_adhoc (void) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write Wifi WPA PSK", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); - g_free (uuid); /* Wifi setting */ s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); @@ -5727,35 +5637,27 @@ test_write_wifi_wpa_psk_adhoc (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); - unlink (testfile); keyfile = utils_get_keys_path (testfile); - unlink (keyfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_free (keyfile); - g_object_unref (connection); - g_object_unref (reread); } static void test_write_wifi_wpa_eap_tls (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *keyfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; NMSetting8021x *s_8021x; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - char *uuid; gboolean success; GError *error = NULL; - char *testfile = NULL; - char *keyfile = NULL; GBytes *ssid; const char *ssid_data = "blahblah"; @@ -5765,14 +5667,12 @@ test_write_wifi_wpa_eap_tls (void) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write Wifi WPA EAP-TLS", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); - g_free (uuid); /* Wifi setting */ s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); @@ -5848,35 +5748,27 @@ test_write_wifi_wpa_eap_tls (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); - unlink (testfile); keyfile = utils_get_keys_path (testfile); - unlink (keyfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_free (keyfile); - g_object_unref (connection); - g_object_unref (reread); } static void test_write_wifi_wpa_eap_ttls_tls (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *keyfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; NMSetting8021x *s_8021x; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - char *uuid; gboolean success; GError *error = NULL; - char *testfile = NULL; - char *keyfile = NULL; GBytes *ssid; const char *ssid_data = "blahblah"; @@ -5886,14 +5778,12 @@ test_write_wifi_wpa_eap_ttls_tls (void) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write Wifi WPA EAP-TTLS (TLS)", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); - g_free (uuid); /* Wifi setting */ s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); @@ -5985,35 +5875,27 @@ test_write_wifi_wpa_eap_ttls_tls (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); - unlink (testfile); keyfile = utils_get_keys_path (testfile); - unlink (keyfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_free (keyfile); - g_object_unref (connection); - g_object_unref (reread); } static void test_write_wifi_wpa_eap_ttls_mschapv2 (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *keyfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; NMSetting8021x *s_8021x; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - char *uuid; gboolean success; GError *error = NULL; - char *testfile = NULL; - char *keyfile = NULL; GBytes *ssid; const char *ssid_data = "blahblah"; @@ -6023,14 +5905,12 @@ test_write_wifi_wpa_eap_ttls_mschapv2 (void) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write Wifi WPA EAP-TTLS (MSCHAPv2)", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); - g_free (uuid); /* Wifi setting */ s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); @@ -6099,34 +5979,24 @@ test_write_wifi_wpa_eap_ttls_mschapv2 (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); - unlink (testfile); - - keyfile = utils_get_keys_path (testfile); - unlink (keyfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - g_free (testfile); - g_free (keyfile); - g_object_unref (connection); - g_object_unref (reread); + keyfile = utils_get_keys_path (testfile); } static void test_write_wifi_wpa_then_open (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_free char *keyfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - char *uuid; - gboolean success; - GError *error = NULL; - char *testfile = NULL; - char *keyfile = NULL; GBytes *ssid; const char *ssid_data = "blahblah"; @@ -6135,25 +6005,20 @@ test_write_wifi_wpa_then_open (void) */ connection = nm_simple_connection_new (); - g_assert (connection); /* Connection setting */ s_con = (NMSettingConnection *) nm_setting_connection_new (); - g_assert (s_con); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "random wifi connection", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); - g_free (uuid); /* Wifi setting */ s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); - g_assert (s_wifi); nm_connection_add_setting (connection, NM_SETTING (s_wifi)); ssid = g_bytes_new (ssid_data, strlen (ssid_data)); @@ -6167,7 +6032,6 @@ test_write_wifi_wpa_then_open (void) /* Wireless security setting */ s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new (); - g_assert (s_wsec); nm_connection_add_setting (connection, NM_SETTING (s_wsec)); g_object_set (s_wsec, @@ -6185,16 +6049,12 @@ test_write_wifi_wpa_then_open (void) /* IP4 setting */ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); - g_assert (s_ip4); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); - g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); /* IP6 setting */ s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new (); - g_assert (s_ip6); nm_connection_add_setting (connection, NM_SETTING (s_ip6)); - g_object_set (s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE, @@ -6218,51 +6078,30 @@ test_write_wifi_wpa_then_open (void) nm_connection_remove_setting (connection, NM_TYPE_SETTING_WIRELESS_SECURITY); /* Write it back out */ + _writer_update_connection (connection, + TEST_SCRATCH_DIR "/network-scripts/", + testfile); keyfile = utils_get_keys_path (testfile); - success = writer_update_connection (connection, - TEST_SCRATCH_DIR "/network-scripts/", - testfile, - keyfile, - &error); - g_assert_no_error (error); - g_assert (success); - - unlink (keyfile); - g_free (keyfile); - keyfile = NULL; + g_assert (!g_file_test (keyfile, G_FILE_TEST_EXISTS)); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); - unlink (testfile); - - /* No keyfile since it's an open connection this time */ - keyfile = utils_get_keys_path (testfile); - g_assert (g_file_test (keyfile, G_FILE_TEST_EXISTS) == FALSE); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - unlink (testfile); - g_free (testfile); - g_free (keyfile); - g_object_unref (reread); - - g_object_unref (connection); } static void test_write_wifi_wpa_then_wep_with_perms (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *keyfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - char *uuid; gboolean success; - GError *error = NULL; - char *testfile = NULL; - char *keyfile = NULL; GBytes *ssid; char **perms; const char *ssid_data = "SomeSSID"; @@ -6276,25 +6115,21 @@ test_write_wifi_wpa_then_wep_with_perms (void) /* Connection setting */ s_con = (NMSettingConnection *) nm_setting_connection_new (); - g_assert (s_con); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); perms = g_strsplit ("user:superman:", ",", -1); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "random wifi connection 2", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_PERMISSIONS, perms, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); - g_free (uuid); g_strfreev (perms); g_assert_cmpint (nm_setting_connection_get_num_permissions (s_con), ==, 1); /* Wifi setting */ s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); - g_assert (s_wifi); nm_connection_add_setting (connection, NM_SETTING (s_wifi)); ssid = g_bytes_new (ssid_data, strlen (ssid_data)); @@ -6308,7 +6143,6 @@ test_write_wifi_wpa_then_wep_with_perms (void) /* Wireless security setting */ s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new (); - g_assert (s_wsec); nm_connection_add_setting (connection, NM_SETTING (s_wsec)); g_object_set (s_wsec, @@ -6326,14 +6160,12 @@ test_write_wifi_wpa_then_wep_with_perms (void) /* IP4 setting */ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); - g_assert (s_ip4); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); /* IP6 setting */ s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new (); - g_assert (s_ip6); nm_connection_add_setting (connection, NM_SETTING (s_ip6)); g_object_set (s_ip6, @@ -6357,7 +6189,6 @@ test_write_wifi_wpa_then_wep_with_perms (void) /* Now change the connection to WEP and recheck */ s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new (); - g_assert (s_wsec); nm_connection_add_setting (connection, NM_SETTING (s_wsec)); g_object_set (s_wsec, @@ -6366,17 +6197,9 @@ test_write_wifi_wpa_then_wep_with_perms (void) nm_setting_wireless_security_set_wep_key (s_wsec, 0, "abraka dabra"); /* Write it back out */ - keyfile = utils_get_keys_path (testfile); - success = writer_update_connection (connection, - TEST_SCRATCH_DIR "/network-scripts/", - testfile, - keyfile, - &error); - g_assert_no_error (error); - g_assert (success); - - g_free (keyfile); - keyfile = NULL; + _writer_update_connection (connection, + TEST_SCRATCH_DIR "/network-scripts/", + testfile); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); @@ -6387,55 +6210,38 @@ test_write_wifi_wpa_then_wep_with_perms (void) g_assert (success); keyfile = utils_get_keys_path (testfile); - unlink (keyfile); - unlink (testfile); - g_free (keyfile); - - g_free (testfile); - g_object_unref (reread); - - g_object_unref (connection); } static void test_write_wifi_dynamic_wep_leap (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *keyfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; NMSetting8021x *s_8021x; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - char *uuid; - GError *error = NULL; - char *testfile = NULL; - char *keyfile = NULL; GBytes *ssid; const char *ssid_data = "blahblah"; shvarFile *ifcfg; - char *tmp; connection = nm_simple_connection_new (); - g_assert (connection); /* Connection setting */ s_con = (NMSettingConnection *) nm_setting_connection_new (); - g_assert (s_con); nm_connection_add_setting (connection, NM_SETTING (s_con)); - - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write Wifi Dynamic WEP LEAP", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); - g_free (uuid); /* Wifi setting */ s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); - g_assert (s_wifi); nm_connection_add_setting (connection, NM_SETTING (s_wifi)); ssid = g_bytes_new (ssid_data, strlen (ssid_data)); @@ -6449,14 +6255,12 @@ test_write_wifi_dynamic_wep_leap (void) /* Wireless security setting */ s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new (); - g_assert (s_wsec); nm_connection_add_setting (connection, NM_SETTING (s_wsec)); g_object_set (s_wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "ieee8021x", NULL); /* Wireless security setting */ s_8021x = (NMSetting8021x *) nm_setting_802_1x_new (); - g_assert (s_8021x); nm_connection_add_setting (connection, NM_SETTING (s_8021x)); nm_setting_802_1x_add_eap_method (s_8021x, "leap"); @@ -6468,13 +6272,11 @@ test_write_wifi_dynamic_wep_leap (void) /* IP4 setting */ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); - g_assert (s_ip4); g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); /* IP6 setting */ s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new (); - g_assert (s_ip6); nm_connection_add_setting (connection, NM_SETTING (s_ip6)); g_object_set (s_ip6, @@ -6491,7 +6293,6 @@ test_write_wifi_dynamic_wep_leap (void) reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); keyfile = utils_get_keys_path (testfile); - unlink (keyfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); @@ -6499,38 +6300,23 @@ test_write_wifi_dynamic_wep_leap (void) * did not get written. Check first that the auth alg is not set to "LEAP" * and next that the only IEEE 802.1x EAP method is "LEAP". */ - ifcfg = svOpenFile (testfile, &error); - g_assert_no_error (error); - g_assert (ifcfg); - tmp = svGetValue (ifcfg, "SECURITYMODE", FALSE); - g_assert_cmpstr (tmp, ==, NULL); - g_free (tmp); - - tmp = svGetValue (ifcfg, "IEEE_8021X_EAP_METHODS", FALSE); - g_assert_cmpstr (tmp, ==, "LEAP"); - g_free (tmp); - + ifcfg = _svOpenFile (testfile); + _svGetValue_check (ifcfg, "SECURITYMODE", NULL); + _svGetValue_check (ifcfg, "IEEE_8021X_EAP_METHODS", "LEAP"); svCloseFile (ifcfg); - unlink (testfile); - - g_free (testfile); - g_free (keyfile); - g_object_unref (connection); - g_object_unref (reread); } static void test_write_wired_qeth_dhcp (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWired *s_wired; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - char *uuid; char **subchans; - char *testfile = NULL; connection = nm_simple_connection_new (); @@ -6538,14 +6324,12 @@ test_write_wired_qeth_dhcp (void) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write Wired qeth Static", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, NULL); - g_free (uuid); /* Wired setting */ s_wired = (NMSettingWired *) nm_setting_wired_new (); @@ -6587,50 +6371,37 @@ test_write_wired_qeth_dhcp (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); - unlink (testfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_object_unref (connection); - g_object_unref (reread); } static void test_write_wired_ctc_dhcp (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWired *s_wired; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - char *uuid; char **subchans; - GError *error = NULL; - char *testfile = NULL; shvarFile *ifcfg; - char *tmp; connection = nm_simple_connection_new (); - g_assert (connection); /* Connection setting */ s_con = (NMSettingConnection *) nm_setting_connection_new (); - g_assert (s_con); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write Wired ctc Static", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, NULL); - g_free (uuid); /* Wired setting */ s_wired = (NMSettingWired *) nm_setting_wired_new (); - g_assert (s_wired); nm_connection_add_setting (connection, NM_SETTING (s_wired)); subchans = g_strsplit ("0.0.600,0.0.601", ",", -1); @@ -6643,13 +6414,11 @@ test_write_wired_ctc_dhcp (void) /* IP4 setting */ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); - g_assert (s_ip4); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); /* IP6 setting */ s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new (); - g_assert (s_ip6); nm_connection_add_setting (connection, NM_SETTING (s_ip6)); g_object_set (s_ip6, @@ -6664,43 +6433,30 @@ test_write_wired_ctc_dhcp (void) &testfile); /* Ensure the CTCPROT item gets written out as it's own option */ - ifcfg = svOpenFile (testfile, &error); - g_assert_no_error (error); - g_assert (ifcfg); + ifcfg = _svOpenFile (testfile); - tmp = svGetValue (ifcfg, "CTCPROT", TRUE); - g_assert (tmp); - g_assert_cmpstr (tmp, ==, "0"); - g_free (tmp); + _svGetValue_check (ifcfg, "CTCPROT", "0"); /* And that it's not in the generic OPTIONS string */ - tmp = svGetValue (ifcfg, "OPTIONS", TRUE); - g_assert (tmp == NULL); - g_free (tmp); + _svGetValue_check (ifcfg, "OPTIONS", NULL); svCloseFile (ifcfg); reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); - unlink (testfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_object_unref (connection); - g_object_unref (reread); } static void test_write_permissions (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWired *s_wired; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - char *uuid; - char *testfile = NULL; connection = nm_simple_connection_new (); @@ -6708,14 +6464,12 @@ test_write_permissions (void) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write Permissions", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, NULL); - g_free (uuid); nm_setting_connection_add_permission (s_con, "user", "blahblah", NULL); nm_setting_connection_add_permission (s_con, "user", "foobar", NULL); @@ -6749,55 +6503,44 @@ test_write_permissions (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); - unlink (testfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_object_unref (connection); - g_object_unref (reread); } static void test_write_wifi_wep_agent_keys (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - char *uuid; const char *str_ssid = "foobarbaz"; GBytes *ssid; - char *testfile = NULL; connection = nm_simple_connection_new (); g_assert (connection != NULL); /* Connection setting */ s_con = (NMSettingConnection *) nm_setting_connection_new (); - g_assert (s_con); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write Wifi WEP Agent Owned", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); - g_free (uuid); /* IP4 setting */ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); - g_assert (s_ip4); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); /* IP6 setting */ s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new (); - g_assert (s_ip6); nm_connection_add_setting (connection, NM_SETTING (s_ip6)); g_object_set (s_ip6, @@ -6807,7 +6550,6 @@ test_write_wifi_wep_agent_keys (void) /* Wifi setting */ s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); - g_assert (s_wifi); nm_connection_add_setting (connection, NM_SETTING (s_wifi)); ssid = g_bytes_new (str_ssid, strlen (str_ssid)); @@ -6819,7 +6561,6 @@ test_write_wifi_wep_agent_keys (void) /* Wifi security setting */ s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new (); - g_assert (s_wsec); nm_connection_add_setting (connection, NM_SETTING (s_wsec)); g_object_set (s_wsec, @@ -6836,7 +6577,6 @@ test_write_wifi_wep_agent_keys (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); - unlink (testfile); /* Remove the WEP key from the original, because it should not have been * written out to disk as it was agent-owned. The new connection should @@ -6849,10 +6589,6 @@ test_write_wifi_wep_agent_keys (void) NULL); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_object_unref (connection); - g_object_unref (reread); } static void @@ -6864,7 +6600,6 @@ test_write_wired_pppoe (void) NMSettingIPConfig *s_ip4; NMSettingPppoe *s_pppoe; NMSettingPpp *s_ppp; - char *uuid; GError *error = NULL; connection = nm_simple_connection_new (); @@ -6873,14 +6608,12 @@ test_write_wired_pppoe (void) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write Wired PPPoE", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, NULL); - g_free (uuid); /* Wired setting */ s_wired = (NMSettingWired *) nm_setting_wired_new (); @@ -6925,7 +6658,6 @@ test_write_vpn (void) NMSettingConnection *s_con; NMSettingIPConfig *s_ip4; NMSettingVpn *s_vpn; - char *uuid; GError *error = NULL; connection = nm_simple_connection_new (); @@ -6934,14 +6666,12 @@ test_write_vpn (void) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write VPN", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_VPN_SETTING_NAME, NULL); - g_free (uuid); /* VPN setting */ s_vpn = (NMSettingVpn *) nm_setting_vpn_new (); @@ -6983,7 +6713,6 @@ test_write_mobile_broadband (gconstpointer data) NMSettingCdma *s_cdma; NMSettingPpp *s_ppp; NMSettingSerial *s_serial; - char *uuid; GError *error = NULL; gboolean gsm = GPOINTER_TO_UINT (data); @@ -6993,14 +6722,12 @@ test_write_mobile_broadband (gconstpointer data) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, gsm ? "Test Write GSM" : "Test Write CDMA", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, gsm ? NM_SETTING_GSM_SETTING_NAME : NM_SETTING_CDMA_SETTING_NAME, NULL); - g_free (uuid); if (gsm) { /* GSM setting */ @@ -7085,39 +6812,34 @@ test_read_bridge_main (void) static void test_write_bridge_main (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingBridge *s_bridge; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - char *uuid; NMIPAddress *addr; static const char *mac = "31:33:33:37:be:cd"; GError *error = NULL; - char *testfile = NULL; connection = nm_simple_connection_new (); g_assert (connection); /* Connection setting */ s_con = (NMSettingConnection *) nm_setting_connection_new (); - g_assert (s_con); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write Bridge Main", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_INTERFACE_NAME, "br0", NM_SETTING_CONNECTION_TYPE, NM_SETTING_BRIDGE_SETTING_NAME, NULL); - g_free (uuid); /* bridge setting */ s_bridge = (NMSettingBridge *) nm_setting_bridge_new (); - g_assert (s_bridge); nm_connection_add_setting (connection, NM_SETTING (s_bridge)); g_object_set (s_bridge, @@ -7126,7 +6848,6 @@ test_write_bridge_main (void) /* IP4 setting */ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); - g_assert (s_ip4); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); g_object_set (s_ip4, @@ -7142,13 +6863,14 @@ test_write_bridge_main (void) /* IP6 setting */ s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new (); - g_assert (s_ip6); nm_connection_add_setting (connection, NM_SETTING (s_ip6)); g_object_set (s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, NULL); + nm_connection_add_setting (connection, nm_setting_proxy_new ()); + nmtst_assert_connection_verifies_without_normalization (connection); _writer_new_connection (connection, @@ -7156,13 +6878,8 @@ test_write_bridge_main (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_BRIDGE, NULL); - unlink (testfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_object_unref (connection); - g_object_unref (reread); } static void @@ -7192,38 +6909,33 @@ test_read_bridge_component (void) static void test_write_bridge_component (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWired *s_wired; NMSetting *s_port; static const char *mac = "31:33:33:37:be:cd"; guint32 mtu = 1492; - char *uuid; - char *testfile = NULL; connection = nm_simple_connection_new (); g_assert (connection); /* Connection setting */ s_con = (NMSettingConnection *) nm_setting_connection_new (); - g_assert (s_con); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write Bridge Component", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, NM_SETTING_CONNECTION_MASTER, "br0", NM_SETTING_CONNECTION_SLAVE_TYPE, NM_SETTING_BRIDGE_SETTING_NAME, NULL); - g_free (uuid); /* Wired setting */ s_wired = (NMSettingWired *) nm_setting_wired_new (); - g_assert (s_wired); nm_connection_add_setting (connection, NM_SETTING (s_wired)); g_object_set (s_wired, @@ -7246,13 +6958,8 @@ test_write_bridge_component (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); - unlink (testfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_object_unref (connection); - g_object_unref (reread); } static void @@ -7485,78 +7192,64 @@ test_read_vlan_flags_2 (void) static void test_write_vlan (void) { - NMConnection *connection; - char *written = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; connection = _connection_from_file (TEST_IFCFG_VLAN_INTERFACE, NULL, TYPE_VLAN, NULL); _writer_new_connection (connection, TEST_SCRATCH_DIR "/network-scripts/", - &written); - - unlink (written); - g_free (written); - - g_object_unref (connection); + &testfile); } static void test_write_vlan_flags (void) { - NMConnection *connection, *reread; - char *written = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; connection = _connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-vlan-flags-2", NULL, TYPE_VLAN, NULL); _writer_new_connection (connection, TEST_SCRATCH_DIR "/network-scripts/", - &written); - - reread = _connection_from_file (written, NULL, TYPE_ETHERNET, NULL); + &testfile); - unlink (written); - g_free (written); + reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_object_unref (connection); - g_object_unref (reread); } static void test_write_vlan_only_vlanid (void) { - NMConnection *connection, *reread; - char *written = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; connection = _connection_from_file (TEST_IFCFG_VLAN_ONLY_VLANID, NULL, TYPE_VLAN, NULL); _writer_new_connection (connection, TEST_SCRATCH_DIR "/network-scripts/", - &written); + &testfile); - reread = _connection_from_file (written, NULL, TYPE_ETHERNET, NULL); - unlink (written); - g_free (written); + reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_object_unref (connection); - g_object_unref (reread); } static void test_write_vlan_reorder_hdr (void) { - NMConnection *connection, *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingVlan *s_vlan; NMSettingWired *s_wired; - char *uuid; - char *testfile = NULL; connection = nm_simple_connection_new (); @@ -7564,14 +7257,12 @@ test_write_vlan_reorder_hdr (void) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write VLAN reorder_hdr", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, FALSE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_VLAN_SETTING_NAME, NULL); - g_free (uuid); /* Wired setting */ s_wired = (NMSettingWired *) nm_setting_wired_new (); @@ -7592,51 +7283,40 @@ test_write_vlan_reorder_hdr (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); - unlink (testfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_object_unref (connection); - g_object_unref (reread); - g_free (testfile); } static void test_write_ethernet_missing_ipv6 (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWired *s_wired; NMSettingIPConfig *s_ip4; - char *uuid; - char *testfile = NULL; connection = nm_simple_connection_new (); g_assert (connection); /* Connection setting */ s_con = (NMSettingConnection *) nm_setting_connection_new (); - g_assert (s_con); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write Ethernet Without IPv6 Setting", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, NULL); - g_free (uuid); /* Wired setting */ s_wired = (NMSettingWired *) nm_setting_wired_new (); - g_assert (s_wired); nm_connection_add_setting (connection, NM_SETTING (s_wired)); /* IP4 setting */ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); - g_assert (s_ip4); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, @@ -7658,13 +7338,8 @@ test_write_ethernet_missing_ipv6 (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); - unlink (testfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_object_unref (connection); - g_object_unref (reread); } static void @@ -7701,17 +7376,16 @@ test_read_bond_main (void) static void test_write_bond_main (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingBond *s_bond; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; NMSettingWired *s_wired; - char *uuid; NMIPAddress *addr; GError *error = NULL; - char *testfile = NULL; connection = nm_simple_connection_new (); @@ -7719,15 +7393,13 @@ test_write_bond_main (void) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write Bond Main", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_INTERFACE_NAME, "bond0", NM_SETTING_CONNECTION_TYPE, NM_SETTING_BOND_SETTING_NAME, NULL); - g_free (uuid); /* Wired setting */ s_wired = (NMSettingWired *) nm_setting_wired_new (); @@ -7760,6 +7432,8 @@ test_write_bond_main (void) NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, NULL); + nm_connection_add_setting (connection, nm_setting_proxy_new ()); + nmtst_assert_connection_verifies_without_normalization (connection); _writer_new_connection (connection, @@ -7767,13 +7441,8 @@ test_write_bond_main (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_BOND, NULL); - unlink (testfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_object_unref (connection); - g_object_unref (reread); } static void @@ -7799,14 +7468,13 @@ test_read_bond_slave (void) static void test_write_bond_slave (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWired *s_wired; static const char *mac = "31:33:33:37:be:cd"; guint32 mtu = 1492; - char *uuid; - char *testfile = NULL; connection = nm_simple_connection_new (); @@ -7814,16 +7482,14 @@ test_write_bond_slave (void) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write Bond Slave", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, NM_SETTING_CONNECTION_MASTER, "bond0", NM_SETTING_CONNECTION_SLAVE_TYPE, NM_SETTING_BOND_SETTING_NAME, NULL); - g_free (uuid); /* Wired setting */ s_wired = (NMSettingWired *) nm_setting_wired_new (); @@ -7841,13 +7507,8 @@ test_write_bond_slave (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); - unlink (testfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_object_unref (connection); - g_object_unref (reread); } static void @@ -7885,18 +7546,17 @@ test_read_infiniband (void) static void test_write_infiniband (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingInfiniband *s_infiniband; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; const char *mac = "80:00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff:00:11:22"; guint32 mtu = 65520; - char *uuid; NMIPAddress *addr; GError *error = NULL; - char *testfile = NULL; connection = nm_simple_connection_new (); @@ -7904,14 +7564,12 @@ test_write_infiniband (void) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write InfiniBand", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_INFINIBAND_SETTING_NAME, NULL); - g_free (uuid); /* InfiniBand setting */ s_infiniband = (NMSettingInfiniband *) nm_setting_infiniband_new (); @@ -7953,19 +7611,14 @@ test_write_infiniband (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_INFINIBAND, NULL); - unlink (testfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_object_unref (connection); - g_object_unref (reread); } static void test_read_bond_slave_ib (void) { - NMConnection *connection; + gs_unref_object NMConnection *connection = NULL; NMSettingConnection *s_con; connection = _connection_from_file (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-bond-slave-ib", @@ -7975,22 +7628,18 @@ test_read_bond_slave_ib (void) g_assert (s_con); g_assert_cmpstr (nm_setting_connection_get_master (s_con), ==, "bond0"); - g_assert_cmpstr (nm_setting_connection_get_slave_type (s_con), ==, NM_SETTING_BOND_SETTING_NAME); - - g_object_unref (connection); } static void test_write_bond_slave_ib (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingInfiniband *s_infiniband; static const char *mac = "80:00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff:00:11:22"; - char *uuid; - char *testfile = NULL; connection = nm_simple_connection_new (); @@ -7998,16 +7647,14 @@ test_write_bond_slave_ib (void) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write Bond Slave InfiniBand", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_INFINIBAND_SETTING_NAME, NM_SETTING_CONNECTION_MASTER, "bond0", NM_SETTING_CONNECTION_SLAVE_TYPE, NM_SETTING_BOND_SETTING_NAME, NULL); - g_free (uuid); /* InfiniBand setting */ s_infiniband = (NMSettingInfiniband *) nm_setting_infiniband_new (); @@ -8026,13 +7673,8 @@ test_write_bond_slave_ib (void) &testfile); reread = _connection_from_file (testfile, NULL, NULL, NULL); - unlink (testfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_object_unref (connection); - g_object_unref (reread); } static void @@ -8122,14 +7764,15 @@ test_read_dcb_basic (void) static void test_write_dcb_basic (void) { - NMConnection *connection, *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWired *s_wired; NMSettingDcb *s_dcb; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; guint i; - char *uuid, *testfile; const guint group_ids[8] = { 4, 0xF, 6, 0xF, 1, 7, 3, 0xF }; const guint group_bandwidths[8] = { 10, 20, 15, 10, 2, 3, 35, 5 }; const guint bandwidths[8] = { 10, 20, 30, 40, 50, 10, 0, 25 }; @@ -8141,14 +7784,12 @@ test_write_dcb_basic (void) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (G_OBJECT (s_con), NM_SETTING_CONNECTION_ID, "dcb-test", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, NM_SETTING_CONNECTION_INTERFACE_NAME, "eth0", NULL); - g_free (uuid); /* Wired setting */ s_wired = (NMSettingWired *) nm_setting_wired_new (); @@ -8194,19 +7835,14 @@ test_write_dcb_basic (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); - unlink (testfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_object_unref (connection); - g_object_unref (reread); - g_free (testfile); } static void test_read_dcb_default_app_priorities (void) { - NMConnection *connection; + gs_unref_object NMConnection *connection = NULL; NMSettingDcb *s_dcb; connection = _connection_from_file (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-dcb-default-app-priorities", @@ -8223,8 +7859,6 @@ test_read_dcb_default_app_priorities (void) g_assert_cmpint (nm_setting_dcb_get_app_fip_flags (s_dcb), ==, NM_SETTING_DCB_FLAG_ENABLE); g_assert_cmpint (nm_setting_dcb_get_app_fip_priority (s_dcb), ==, -1); - - g_object_unref (connection); } static void @@ -8335,49 +7969,45 @@ test_read_dcb_pgpct_not_100 (void) static void test_read_fcoe_mode (gconstpointer user_data) { + gs_unref_object NMConnection *connection = NULL; + gs_free char *file = NULL; const char *expected_mode = user_data; - NMConnection *connection; NMSettingDcb *s_dcb; - char *file; file = g_strdup_printf (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-fcoe-%s", expected_mode); connection = _connection_from_file (file, NULL, TYPE_ETHERNET, NULL); - g_free (file); s_dcb = nm_connection_get_setting_dcb (connection); g_assert (s_dcb); g_assert_cmpint (nm_setting_dcb_get_app_fcoe_flags (s_dcb), ==, NM_SETTING_DCB_FLAG_ENABLE); g_assert_cmpstr (nm_setting_dcb_get_app_fcoe_mode (s_dcb), ==, expected_mode); - - g_object_unref (connection); } static void test_write_fcoe_mode (gconstpointer user_data) { + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; const char *expected_mode = user_data; - NMConnection *connection, *reread; - GError *error = NULL; NMSettingConnection *s_con; NMSettingWired *s_wired; NMSettingDcb *s_dcb; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - char *uuid, *testfile; + shvarFile *ifcfg; connection = nm_simple_connection_new (); s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (G_OBJECT (s_con), NM_SETTING_CONNECTION_ID, "fcoe-test", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, NM_SETTING_CONNECTION_INTERFACE_NAME, "eth0", NULL); - g_free (uuid); /* Wired setting */ s_wired = (NMSettingWired *) nm_setting_wired_new (); @@ -8407,26 +8037,13 @@ test_write_fcoe_mode (gconstpointer user_data) TEST_SCRATCH_DIR "/network-scripts/", &testfile); - { - shvarFile *ifcfg = svOpenFile (testfile, &error); - char *written_mode; - - g_assert_no_error (error); - g_assert (ifcfg); - written_mode = svGetValue (ifcfg, "DCB_APP_FCOE_MODE", FALSE); - svCloseFile (ifcfg); - g_assert_cmpstr (written_mode, ==, expected_mode); - g_free (written_mode); - } + ifcfg = _svOpenFile (testfile); + _svGetValue_check (ifcfg, "DCB_APP_FCOE_MODE", expected_mode); + svCloseFile (ifcfg); reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); - unlink (testfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_object_unref (connection); - g_object_unref (reread); - g_free (testfile); } static void @@ -8481,16 +8098,15 @@ test_read_team_master_invalid (gconstpointer user_data) static void test_write_team_master (void) { - NMConnection *connection, *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingTeam *s_team; NMSettingWired *s_wired; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - char *uuid, *testfile = NULL, *val; - GError *error = NULL; const char *expected_config = "{ \"device\": \"team0\", \"link_watch\": { \"name\": \"ethtool\" } }"; - const char *escaped_expected_config = "\"{ \\\"device\\\": \\\"team0\\\", \\\"link_watch\\\": { \\\"name\\\": \\\"ethtool\\\" } }\""; shvarFile *f; connection = nm_simple_connection_new (); @@ -8499,14 +8115,12 @@ test_write_team_master (void) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write Team Master", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_INTERFACE_NAME, "team0", NM_SETTING_CONNECTION_TYPE, NM_SETTING_TEAM_SETTING_NAME, NULL); - g_free (uuid); /* Team setting */ s_team = (NMSettingTeam *) nm_setting_team_new (); @@ -8522,7 +8136,6 @@ test_write_team_master (void) /* IP4 setting */ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); - g_assert (s_ip4); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); g_object_set (s_ip4, @@ -8531,43 +8144,28 @@ test_write_team_master (void) /* IP6 setting */ s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new (); - g_assert (s_ip6); nm_connection_add_setting (connection, NM_SETTING (s_ip6)); g_object_set (s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO, NULL); + nm_connection_add_setting (connection, nm_setting_proxy_new ()); + nmtst_assert_connection_verifies_without_normalization (connection); _writer_new_connection (connection, TEST_SCRATCH_DIR "/network-scripts/", &testfile); - f = svOpenFile (testfile, &error); - g_assert_no_error (error); - g_assert (f); - - /* re-read the file to check that what key was written. */ - val = svGetValue (f, "DEVICETYPE", FALSE); - g_assert (val); - g_assert_cmpstr (val, ==, "Team"); - g_free (val); - val = svGetValue (f, "TEAM_CONFIG", TRUE); - g_assert (val); - g_assert_cmpstr (val, ==, escaped_expected_config); - g_free (val); + f = _svOpenFile (testfile); + _svGetValue_check (f, "DEVICETYPE", "Team"); + _svGetValue_check (f, "TEAM_CONFIG", expected_config); svCloseFile (f); reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); - unlink (testfile); - nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_object_unref (connection); - g_object_unref (reread); } static void @@ -8596,14 +8194,13 @@ test_read_team_port (gconstpointer user_data) static void test_write_team_port (void) { - NMConnection *connection, *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingTeamPort *s_team_port; NMSettingWired *s_wired; - char *uuid, *testfile = NULL, *val; - GError *error = NULL; const char *expected_config = "{ \"p4p1\": { \"prio\": -10, \"sticky\": true } }"; - const char *escaped_expected_config = "\"{ \\\"p4p1\\\": { \\\"prio\\\": -10, \\\"sticky\\\": true } }\""; shvarFile *f; connection = nm_simple_connection_new (); @@ -8612,15 +8209,13 @@ test_write_team_port (void) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write Team Port", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, NM_SETTING_CONNECTION_MASTER, "team0", NM_SETTING_CONNECTION_SLAVE_TYPE, NM_SETTING_TEAM_SETTING_NAME, NULL); - g_free (uuid); /* Team setting */ s_team_port = (NMSettingTeamPort *) nm_setting_team_port_new (); @@ -8637,36 +8232,17 @@ test_write_team_port (void) TEST_SCRATCH_DIR "/network-scripts/", &testfile); - f = svOpenFile (testfile, &error); - g_assert_no_error (error); - g_assert (f); - - /* re-read the file to check that what key was written. */ - val = svGetValue (f, "TYPE", FALSE); - g_assert (!val); - val = svGetValue (f, "DEVICETYPE", FALSE); - g_assert (val); - g_assert_cmpstr (val, ==, "TeamPort"); - g_free (val); - val = svGetValue (f, "TEAM_PORT_CONFIG", TRUE); - g_assert (val); - g_assert_cmpstr (val, ==, escaped_expected_config); - g_free (val); - val = svGetValue (f, "TEAM_MASTER", TRUE); - g_assert (val); - g_assert_cmpstr (val, ==, "team0"); - g_free (val); + f = _svOpenFile (testfile); + _svGetValue_check (f, "TYPE", NULL); + _svGetValue_check (f, "DEVICETYPE", "TeamPort"); + _svGetValue_check (f, "TEAM_PORT_CONFIG", expected_config); + _svGetValue_check (f, "TEAM_MASTER", "team0"); svCloseFile (f); reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); - unlink (testfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_object_unref (connection); - g_object_unref (reread); } static void @@ -8692,108 +8268,456 @@ test_read_team_port_empty_config (void) g_object_unref (connection); } -/* Old algorithm for "remove escaped characters in place". - * - * This function is obsolete because it has O(n^2) runtime - * complexity and got replaced. Keep it here for testing, - * that both functions behave identical. - **/ -static void -svUnescape_On2 (char *s) -{ - int len, i; - - len = strlen(s); - if (len >= 2 && (s[0] == '"' || s[0] == '\'') && s[0] == s[len-1]) { - i = len - 2; - if (i == 0) - s[0] = '\0'; - else { - memmove(s, s+1, i); - s[i+1] = '\0'; - len = i; - } +static void +test_read_proxy_basic (void) +{ + NMConnection *connection; + NMSettingProxy *s_proxy; + + /* Test basic proxy configuration */ + + connection = _connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-read-proxy-basic", + NULL, TYPE_ETHERNET, NULL); + + /* ===== Proxy setting ===== */ + s_proxy = nm_connection_get_setting_proxy (connection); + g_assert (s_proxy); + + /* Proxy method */ + g_assert_cmpint (nm_setting_proxy_get_method (s_proxy), ==, NM_SETTING_PROXY_METHOD_AUTO); + g_assert (nm_setting_proxy_get_browser_only (s_proxy)); + g_assert_cmpstr (nm_setting_proxy_get_pac_url (s_proxy), ==, "http://wpad.mycompany.com/wpad.dat"); + + g_object_unref (connection); +} + +static void +test_write_proxy_basic (void) +{ + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; + NMSettingConnection *s_con; + NMSettingWired *s_wired; + NMSettingProxy *s_proxy; + const char *expected_url = "https://wpad.neverland.org/wpad.dat"; + shvarFile *f; + + connection = nm_simple_connection_new (); + + /* Connection setting */ + s_con = (NMSettingConnection *) nm_setting_connection_new (); + nm_connection_add_setting (connection, NM_SETTING (s_con)); + + g_object_set (s_con, + NM_SETTING_CONNECTION_ID, "Test Write Proxy Basic", + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), + NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, + NULL); + + /* Proxy setting */ + s_proxy = (NMSettingProxy *) nm_setting_proxy_new (); + nm_connection_add_setting (connection, NM_SETTING (s_proxy)); + g_object_set (s_proxy, NM_SETTING_PROXY_METHOD, NM_SETTING_PROXY_METHOD_AUTO, NULL); + g_object_set (s_proxy, NM_SETTING_PROXY_PAC_URL, expected_url, NULL); + + /* Wired setting */ + s_wired = (NMSettingWired *) nm_setting_wired_new (); + nm_connection_add_setting (connection, NM_SETTING (s_wired)); + + nmtst_assert_connection_verifies (connection); + + _writer_new_connection (connection, + TEST_SCRATCH_DIR "/network-scripts/", + &testfile); + + f = _svOpenFile (testfile); + _svGetValue_check (f, "TYPE", "Ethernet"); + _svGetValue_check (f, "PROXY_METHOD", "auto"); + _svGetValue_check (f, "PAC_URL", expected_url); + svCloseFile (f); + + reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, + NULL); + + nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); +} + +/*****************************************************************************/ + +static const char * +_svUnescape (const char *str, char **to_free) +{ + const char *s; + gs_free char *str_free = NULL; + + g_assert (str); + g_assert (to_free); + + if (str[0] == '\0') { + /* avoid static string "" */ + str = (str_free = g_strdup (str)); } - for (i = 0; i < len; i++) { - if (s[i] == '\\') { - memmove(s+i, s+i+1, len-(i+1)); - len--; - } - s[len] = '\0'; + + s = svUnescape (str, to_free); + if (*to_free) { + g_assert (s == *to_free); + g_assert (s[0]); + } else { + g_assert ( s == NULL + || (!s[0] && (s < str || s > strchr (str, '\0'))) + || ( s[0] && s >= str && s <= strchr (str, '\0') )); } + return s; } +typedef struct { + const char *val; + const char *exp; + bool can_concat:1; + bool needs_ascii_separator:1; +} UnescapeTestData; + static void -test_svUnescape_assert (const char *str) +do_svUnescape_assert (const char *str, const char *expected) { - char *s1 = g_strdup (str); - char *s2 = g_strdup (str); + gs_free char *to_free = NULL; + const char *s; + + s = _svUnescape (str, &to_free); + g_assert_cmpstr (s, ==, expected); - svUnescape (s1); - svUnescape_On2 (s2); + /* check we can make a round-trip */ + if (expected) { + gs_free char *s1_free = NULL; + gs_free char *s2_free = NULL; + const char *s1, *s2; - g_assert_cmpstr (s1, ==, s2); + s1 = svEscape (expected, &s1_free); + g_assert (s1); - g_free (s1); - g_free (s2); + s2 = _svUnescape (s1, &s2_free); + g_assert (s2); + + g_assert_cmpstr (s2, ==, expected); + } +} + +static void +do_svUnescape_combine_ansi_append (GString *str_val, GString *str_exp, const UnescapeTestData *data, gboolean honor_needs_ascii_separator) +{ + g_string_append (str_val, data->val); + g_string_append (str_exp, data->exp); + if (honor_needs_ascii_separator && data->needs_ascii_separator) { + /* the string has an open escape sequence. We must ensure that when + * combining it with another sequence, that they don't merge into + * something diffent. for example "\xa" + "a" must not result in + * "\xaa". Instead, we add a space in between to get "\xa a". */ + g_string_append (str_val, " "); + g_string_append (str_exp, " "); + } +} + +static void +do_svUnescape_combine_ansi (GString *str_val, GString *str_exp, const UnescapeTestData *data_ansi, gsize data_len, gssize idx) +{ + gsize i, j; + + g_string_set_size (str_val, 0); + g_string_set_size (str_exp, 0); + g_string_append (str_val, "$'"); + if (idx < 0) { + for (i = -idx; i > 0; i--) { + j = nmtst_get_rand_int () % data_len; + if (!data_ansi[j].can_concat) { + i++; + continue; + } + do_svUnescape_combine_ansi_append (str_val, str_exp, &data_ansi[j], i > 1); + } + } else { + g_assert_cmpint (idx, <, data_len); + do_svUnescape_combine_ansi_append (str_val, str_exp, &data_ansi[idx], FALSE); + } + g_string_append (str_val, "'"); } static void test_svUnescape (void) { - int len, repeat, i, k; - GRand *r = g_rand_new (); - guint32 seed = g_random_int (); - - g_rand_set_seed (r, seed); - - test_svUnescape_assert (""); - test_svUnescape_assert ("'"); - test_svUnescape_assert ("\""); - test_svUnescape_assert ("\\"); - test_svUnescape_assert ("x"); - test_svUnescape_assert (" "); - test_svUnescape_assert ("' '"); - test_svUnescape_assert ("'x'"); - test_svUnescape_assert ("\'some string\'"); - test_svUnescape_assert ("Bob outside LAN"); - test_svUnescape_assert ("{ \"device\": \"team0\", \"link_watch\": { \"name\": \"ethtool\" } }"); - - for (len = 1; len < 25; len++) { - char *s = g_new0 (char, len+1); - - for (repeat = 0; repeat < MAX (4*len, 20); repeat++) { - - /* fill the entire string with random. */ - for (i = 0; i < len; i++) - s[i] = g_rand_int (r); - - /* randomly place escape characters into the string */ - k = g_rand_int (r) % (len); - while (k-- > 0) - s[g_rand_int (r) % len] = '\\'; - - if (len > 1) { - /* quote the string. */ - k = g_rand_int (r) % (10); - if (k < 4) { - char quote = k < 2 ? '"' : '\''; - - s[0] = quote; - s[len-1] = quote; - } +#define V0(v_value, v_expected) { .val = ""v_value"", .exp = v_expected, .can_concat = FALSE, } +#define V1(v_value, v_expected) { .val = ""v_value"", .exp = v_expected, .can_concat = !!v_expected, } +#define V2(v_value, v_expected) { .val = ""v_value"", .exp = v_expected, .can_concat = TRUE, .needs_ascii_separator = TRUE, } + const UnescapeTestData data_full[] = { + V1 ("", ""), + V0 ("'", NULL), + V1 ("'x'", "x"), + V1 ("' '", " "), + V1 ("'x'", "x"), + V0 ("\"", NULL), + V0 ("\\", NULL), + V0 (" ", ""), + V0 (" ", ""), + V0 ("a; #", "a"), + V0 (" ; #", ""), + V0 ("; ", ""), + V0 ("; ;", NULL), + V0 (" ; a #", NULL), + V0 (" ; a;; #", NULL), + V0 ("a; ; #", NULL), + V0 ("\t # ", ""), + V0 ("\t #a", ""), + V0 ("\t #a\r", ""), + V0 ("\r", ""), + V1 ("\\\"", "\""), + V1 ("\\`", "`"), + V1 ("\\$", "$"), + V1 ("\\\\", "\\"), + V1 ("\\a", "a"), + V1 ("\\b", "b"), + V1 ("\\'", "'"), + V1 ("\\~", "~"), + V1 ("\\\t", "\t"), + V1 ("\"\\\"\"", "\""), + V1 ("\"\\`\"", "`"), + V1 ("\"\\$\"", "$"), + V1 ("\"\\\\\"", "\\"), + V1 ("\"\\a\"", "\\a"), + V1 ("\"\\b\"", "\\b"), + V1 ("\"\\\t\"", "\\\t"), + V0 ("ab\r", "ab"), + V0 ("a'b'\r ", "ab"), + V0 ("a'b' \r", "ab"), + V0 ("a#b", "a#b"), + V0 ("#b", "#b"), + V1 ("\'some string\'", "some string"), + V0 ("Bob outside LAN", NULL), + V1 ("x", "x"), + V1 ("'{ \"device\": \"team0\", \"link_watch\": { \"name\": \"ethtool\" } }'", + "{ \"device\": \"team0\", \"link_watch\": { \"name\": \"ethtool\" } }"), + V1 ("x\"\"b", "xb"), + V1 ("x\"c\"b", "xcb"), + V1 ("\"c\"b", "cb"), + V1 ("\"c\"\\'b", "c'b"), + V1 ("$''", ""), + V1 ("$'\\n'", "\n"), + V0 ("$'\\'", NULL), + V1 ("$'\\x'", "\\x"), + V1 ("$'\\xa'", "\xa"), + V0 ("$'\\x0'", ""), + V1 ("$'\\x12'", "\x12"), + V1 ("$'\\x12A'", "\x12""A"), + V1 ("$'\\x12t'", "\x12t"), + V1 ("\"aa\\\"\"", "aa\""), + V1 ("\"aa\\\"b\"c", "aa\"bc"), + V1 ("\"aa\\\"\"b", "aa\"b"), + + /* the following is not shell behavior, but kept for backward compatibility + * with old svEscape(). */ + V0 ("\"\\'\"", "'"), + V0 ("\"\\~\"", "~"), + V0 ("\"b\\~b\"", "b~b"), + V0 ("\"\\~\\~\"", "~~"), + V0 ("\"\\~\\'\"", "~'"), + + /* the following is shell-behavior, because it doesn't look like written + * by old svEscape(). */ + V1 ("\"\\~~\"", "\\~~"), + V1 ("\"\\a\\'\"", "\\a\\'"), + V1 ("x\"\\~\"", "x\\~"), + V1 ("\"\\'\"''", "\\'"), + V0 ("\"b\\~b\" ", "b\\~b"), + V1 ("\"b\\~b\"x", "b\\~bx"), + }; + const UnescapeTestData data_ansi[] = { + /* strings inside $''. They cannot be compared directly, but must + * be wrapped by do_svUnescape_combine_ansi(). */ + V1 ("", ""), + V1 ("a", "a"), + V1 ("b", "b"), + V1 ("x", "x"), + V1 (" ", " "), + V1 ("\\a", "\a"), + V1 ("\\b", "\b"), + V1 ("\\e", "\e"), + V1 ("\\E", "\E"), + V1 ("\\f", "\f"), + V1 ("\\n", "\n"), + V1 ("\\r", "\r"), + V1 ("\\t", "\t"), + V1 ("\\v", "\v"), + V1 ("\\\\", "\\"), + V1 ("\\'", "'"), + V1 ("\\\"", "\""), + V1 ("\\?", "\?"), + V1 ("\\?", "?"), + V2 ("\\8", "\\8"), + V2 ("\\1", "\1"), + V1 ("\\1A", "\1A"), + V1 ("\\18", "\18"), + V2 ("\\01", "\1"), + V1 ("\\001", "\1"), + V0 ("\\008", ""), + V1 ("\\018", "\0018"), + V0 ("\\08", ""), + V1 ("\\18", "\0018"), + V1 ("\\x", "\\x"), + V2 ("\\xa", "\xa"), + V1 ("\\x12", "\x12"), + V1 ("\\x12A", "\x12""A"), + V1 ("\\x12a", "\x12""a"), + V1 ("\\x12t", "\x12t"), + V1 ("\\x1a", "\x1a"), + V1 ("\\x1A", "\x1A"), + V1 ("\\ut", "\\ut"), + V2 ("\\ua", "\xa"), + V1 ("\\uat", "\xat"), + V2 ("\\uab", "\xc2\xab"), + V1 ("\\uabt", "\xc2\xabt"), + V2 ("\\uabc", "\xe0\xaa\xbc"), + V1 ("\\uabct", "\xe0\xaa\xbct"), + V2 ("\\uabcd", "\xea\xaf\x8d"), + V1 ("\\uabcdt", "\xea\xaf\x8dt"), + V2 ("\\uabcde", "\xea\xaf\x8d""e"), + V1 ("\\uabcdet", "\xea\xaf\x8d""et"), + V1 ("\\Ut", "\\Ut"), + V2 ("\\Ua", "\xa"), + V1 ("\\Uat", "\xat"), + V2 ("\\Uab", "\xc2\xab"), + V1 ("\\Uabt", "\xc2\xabt"), + V2 ("\\Uabc", "\xe0\xaa\xbc"), + V1 ("\\Uabct", "\xe0\xaa\xbct"), + V2 ("\\Uabcd", "\xea\xaf\x8d"), + V1 ("\\Uabcdt", "\xea\xaf\x8dt"), + V2 ("\\Uabcde", "\xf2\xab\xb3\x9e"), + V1 ("\\Uabcdet", "\xf2\xab\xb3\x9et"), + V2 ("\\Uabcde0", "\xf8\xaa\xbc\xb7\xa0"), + V1 ("\\Uabcde0t", "\xf8\xaa\xbc\xb7\xa0t"), + V2 ("\\Uabcde01", "\xfc\x8a\xaf\x8d\xb8\x81"), + V1 ("\\Uabcde01t", "\xfc\x8a\xaf\x8d\xb8\x81t"), + V2 ("\\U0abcde01", "\xfc\x8a\xaf\x8d\xb8\x81"), + V1 ("\\U0abcde01t", "\xfc\x8a\xaf\x8d\xb8\x81t"), + V1 ("\\U00abcde01", "\xf8\xaa\xbc\xb7\xa0""1"), + V1 ("\\U00abcde01t", "\xf8\xaa\xbc\xb7\xa0""1t"), + + /* control-x sequence is not supported */ + V1 ("\\c", "\\c"), + V1 ("\\c1", "\\c1"), + }; +#undef V0 +#undef V1 +#undef V2 + gsize i; + nm_auto_free_gstring GString *str_val = g_string_new (NULL); + nm_auto_free_gstring GString *str_val2 = g_string_new (NULL); + nm_auto_free_gstring GString *str_exp = g_string_new (NULL); + nm_auto_free_gstring GString *str_exp2 = g_string_new (NULL); + + do_svUnescape_assert ( "' '' '", " "); + + for (i = 0; i < G_N_ELEMENTS (data_full); i++) + do_svUnescape_assert (data_full[i].val, data_full[i].exp); + + for (i = 0; i < G_N_ELEMENTS (data_ansi); i++) { + do_svUnescape_combine_ansi (str_val, str_exp, data_ansi, G_N_ELEMENTS (data_ansi), i); + do_svUnescape_assert (str_val->str, str_exp->str); + } + + /* different values can be just concatenated... */ + for (i = 0; i < 200; i++) { + gsize num_concat = (nmtst_get_rand_int () % 5) + 2; + + g_string_set_size (str_val, 0); + g_string_set_size (str_exp, 0); + + while (num_concat > 0) { + gsize idx; + + if ((nmtst_get_rand_int () % 3 == 0)) { + do_svUnescape_combine_ansi (str_val2, str_exp2, data_ansi, G_N_ELEMENTS (data_ansi), -((int) ((nmtst_get_rand_int () % 5) + 1))); + continue; } - /*g_message (">>%s<<", s);*/ - test_svUnescape_assert (s); + idx = nmtst_get_rand_int () % G_N_ELEMENTS (data_full); + if (!data_full[idx].can_concat) + continue; + g_string_append (str_val, data_full[idx].val); + g_string_append (str_exp, data_full[idx].exp); + num_concat--; + } + + switch (nmtst_get_rand_int () % 3) { + case 0: + g_string_append (str_val, " "); + break; + case 1: + g_string_append (str_val, " "); + break; + } + switch (nmtst_get_rand_int () % 3) { + case 0: + g_string_append (str_val, " #"); + break; + case 1: + g_string_append (str_val, " #foo"); + break; } + do_svUnescape_assert (str_val->str, str_exp->str); + } +} + +/*****************************************************************************/ + +static void +test_write_unknown (gconstpointer test_data) +{ + nmtst_auto_unlinkfile char *filename_tmp_1 = g_strdup (TEST_SCRATCH_DIR_TMP"/tmp-1"); + const char *testfile = test_data; + gs_free char *testfile_expected = g_strconcat (testfile, ".expected", NULL); + shvarFile *sv; + gs_free_error GError *error = NULL; + gboolean success; + gs_free char *file_contents_out = NULL; + gs_free char *file_contents_exp = NULL; + + sv = _svOpenFile (testfile); + + svFileSetName (sv, filename_tmp_1); + svFileSetModified (sv); - g_free (s); + if (g_str_has_suffix (testfile, "ifcfg-test-write-unknown-4")) { + _svGetValue_check (sv, "NAME", "l4x"); + _svGetValue_check (sv, "NAME2", NULL); + _svGetValue_check (sv, "NAME3", "name3-value"); + + svSetValue (sv, "NAME", "set-by-test1"); + svSetValue (sv, "NAME2", NULL); + svSetValue (sv, "NAME2", "set-by-test2"); + svSetValue (sv, "NAME3", "set-by-test3"); + + _svGetValue_check (sv, "some_key", NULL); + _svGetValue_check (sv, "some_key1", ""); + _svGetValue_check (sv, "some_key2", ""); + _svGetValue_check (sv, "some_key3", "x"); + + _svGetValue_check (sv, "NAME", "set-by-test1"); + _svGetValue_check (sv, "NAME2", "set-by-test2"); + _svGetValue_check (sv, "NAME3", "set-by-test3"); } - g_rand_free (r); + success = svWriteFile (sv, 0644, &error); + nmtst_assert_success (success, error); + + file_contents_out = nmtst_file_get_contents (filename_tmp_1); + file_contents_exp = nmtst_file_get_contents (testfile_expected); + + g_assert_cmpstr (file_contents_out, ==, file_contents_exp); + + svCloseFile (sv); } +/*****************************************************************************/ + static void test_read_vlan_trailing_spaces (void) { @@ -8842,10 +8766,123 @@ test_sit_read_ignore (void) /*****************************************************************************/ +static void +do_test_utils_name (const char *desc, + const char *path, + gboolean only_ifcfg, + const char *expected) +{ + const char *result; + + result = utils_get_ifcfg_name (path, only_ifcfg); + g_assert_cmpstr (result, ==, expected); +} + +static void +test_utils_name (void) +{ + do_test_utils_name ("get-ifcfg-name-bad", "/foo/bar/adfasdfadf", FALSE, NULL); + do_test_utils_name ("get-ifcfg-name-good", "/foo/bar/ifcfg-FooBar", FALSE, "FooBar"); + do_test_utils_name ("get-ifcfg-name-keys", "/foo/bar/keys-BlahLbah", FALSE, "BlahLbah"); + do_test_utils_name ("get-ifcfg-name-route", "/foo/bar/route-Lalalala", FALSE, "Lalalala"); + do_test_utils_name ("get-ifcfg-name-only-ifcfg-route", "/foo/bar/route-Lalalala", TRUE, NULL); + do_test_utils_name ("get-ifcfg-name-only-ifcfg-keys", "/foo/bar/keys-Lalalala", TRUE, NULL); + do_test_utils_name ("get-ifcfg-name-no-path-ifcfg", "ifcfg-Lalalala", FALSE, "Lalalala"); + do_test_utils_name ("get-ifcfg-name-no-path-keys", "keys-Lalalala", FALSE, "Lalalala"); + do_test_utils_name ("get-ifcfg-name-no-path-route", "route-Lalalala", FALSE, "Lalalala"); + + do_test_utils_name ("get-ifcfg-name-bad2-ifcfg", "/foo/bar/asdfasifcfg-Foobar", FALSE, NULL); + do_test_utils_name ("get-ifcfg-name-bad2-keys", "/foo/bar/asdfaskeys-Foobar", FALSE, NULL); + do_test_utils_name ("get-ifcfg-name-bad2-route", "/foo/bar/asdfasroute-Foobar", FALSE, NULL); +} + +/*****************************************************************************/ + +static void +do_test_utils_path_ifcfg (const char *desc, + const char *path, + const char *expected) +{ + char *result; + + result = utils_get_ifcfg_path (path); + g_assert_cmpstr (result, ==, expected); + g_free (result); +} + +static void +do_test_utils_path_keys (const char *desc, + const char *path, + const char *expected) +{ + char *result; + + result = utils_get_keys_path (path); + g_assert_cmpstr (result, ==, expected); + g_free (result); +} + +static void +do_test_utils_path_route (const char *desc, + const char *path, + const char *expected) +{ + char *result; + + result = utils_get_route_path (path); + g_assert_cmpstr (result, ==, expected); + g_free (result); +} + +static void +test_utils_path (void) +{ + do_test_utils_path_ifcfg ("ifcfg-path-bad", "/foo/bar/adfasdfasdf", NULL); + do_test_utils_path_ifcfg ("ifcfg-path-from-keys-no-path", "keys-BlahBlah", "ifcfg-BlahBlah"); + do_test_utils_path_ifcfg ("ifcfg-path-from-keys", "/foo/bar/keys-BlahBlah", "/foo/bar/ifcfg-BlahBlah"); + do_test_utils_path_ifcfg ("ifcfg-path-from-route", "/foo/bar/route-BlahBlah", "/foo/bar/ifcfg-BlahBlah"); + + do_test_utils_path_keys ("keys-path-bad", "/foo/bar/asdfasdfasdfasdf", NULL); + do_test_utils_path_keys ("keys-path-from-ifcfg-no-path", "ifcfg-FooBar", "keys-FooBar"); + do_test_utils_path_keys ("keys-path-from-ifcfg", "/foo/bar/ifcfg-FooBar", "/foo/bar/keys-FooBar"); + do_test_utils_path_keys ("keys-path-from-route", "/foo/bar/route-FooBar", "/foo/bar/keys-FooBar"); + + do_test_utils_path_route ("route-path-bad", "/foo/bar/asdfasdfasdfasdf", NULL); + do_test_utils_path_route ("route-path-from-ifcfg-no-path", "ifcfg-FooBar", "route-FooBar"); + do_test_utils_path_route ("route-path-from-ifcfg", "/foo/bar/ifcfg-FooBar", "/foo/bar/route-FooBar"); + do_test_utils_path_route ("route-path-from-keys", "/foo/bar/keys-FooBar", "/foo/bar/route-FooBar"); +} + +/*****************************************************************************/ + +static void +do_test_utils_ignored (const char *desc, const char *path, gboolean expected_ignored) +{ + gboolean result; + + result = utils_should_ignore_file (path, FALSE); + g_assert (result == expected_ignored); +} + +static void +test_utils_ignore (void) +{ + do_test_utils_ignored ("ignored-ifcfg", "ifcfg-FooBar", FALSE); + do_test_utils_ignored ("ignored-keys", "keys-FooBar", FALSE); + do_test_utils_ignored ("ignored-route", "route-FooBar", FALSE); + do_test_utils_ignored ("ignored-bak", "ifcfg-FooBar" BAK_TAG, TRUE); + do_test_utils_ignored ("ignored-tilde", "ifcfg-FooBar" TILDE_TAG, TRUE); + do_test_utils_ignored ("ignored-orig", "ifcfg-FooBar" ORIG_TAG, TRUE); + do_test_utils_ignored ("ignored-rej", "ifcfg-FooBar" REJ_TAG, TRUE); + do_test_utils_ignored ("ignored-rpmnew", "ifcfg-FooBar" RPMNEW_TAG, TRUE); + do_test_utils_ignored ("ignored-augnew", "ifcfg-FooBar" AUGNEW_TAG, TRUE); + do_test_utils_ignored ("ignored-augtmp", "ifcfg-FooBar" AUGTMP_TAG, TRUE); +} + +/*****************************************************************************/ #define TPATH "/settings/plugins/ifcfg-rh/" -#define TEST_IFCFG_WIFI_OPEN_SSID_BAD_HEX TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wifi-open-ssid-bad-hex" #define TEST_IFCFG_WIFI_OPEN_SSID_LONG_QUOTED TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wifi-open-ssid-long-quoted" #define TEST_IFCFG_WIFI_OPEN_SSID_LONG_HEX TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wifi-open-ssid-long-hex" @@ -8857,7 +8894,16 @@ int main (int argc, char **argv) { nmtst_init_assert_logging (&argc, &argv, "INFO", "DEFAULT"); + if (g_mkdir_with_parents (TEST_SCRATCH_DIR_TMP, 0755) != 0) + g_error ("failure to create test directory \"%s\": %s", TEST_SCRATCH_DIR_TMP, g_strerror (errno)); + g_test_add_func (TPATH "svUnescape", test_svUnescape); + + g_test_add_data_func (TPATH "write-unknown/1", TEST_IFCFG_DIR"/network-scripts/ifcfg-test-write-unknown-1", test_write_unknown); + g_test_add_data_func (TPATH "write-unknown/2", TEST_IFCFG_DIR"/network-scripts/ifcfg-test-write-unknown-2", test_write_unknown); + g_test_add_data_func (TPATH "write-unknown/3", TEST_IFCFG_DIR"/network-scripts/ifcfg-test-write-unknown-3", test_write_unknown); + g_test_add_data_func (TPATH "write-unknown/4", TEST_IFCFG_DIR"/network-scripts/ifcfg-test-write-unknown-4", test_write_unknown); + g_test_add_func (TPATH "vlan-trailing-spaces", test_read_vlan_trailing_spaces); g_test_add_func (TPATH "unmanaged", test_read_unmanaged); @@ -8883,6 +8929,7 @@ int main (int argc, char **argv) g_test_add_func (TPATH "read-dhcp-plus-ip", test_read_wired_dhcp_plus_ip); g_test_add_func (TPATH "read-shared-plus-ip", test_read_wired_shared_plus_ip); g_test_add_func (TPATH "read-dhcp-send-hostname", test_read_write_wired_dhcp_send_hostname); + g_test_add_func (TPATH "read-dhcpv6-hostname-fallback", test_read_wired_dhcpv6_hostname_fallback); g_test_add_func (TPATH "read-global-gateway", test_read_wired_global_gateway); g_test_add_func (TPATH "read-global-gateway-ignore", test_read_wired_global_gateway_ignore); g_test_add_func (TPATH "read-obsolete-gateway-n", test_read_wired_obsolete_gateway_n); @@ -8919,7 +8966,7 @@ int main (int argc, char **argv) g_test_add_func (TPATH "wifi/read/open", test_read_wifi_open); g_test_add_func (TPATH "wifi/read/open/auto", test_read_wifi_open_auto); g_test_add_func (TPATH "wifi/read/open/hex-ssid", test_read_wifi_open_ssid_hex); - g_test_add_data_func (TPATH "wifi/read/open-ssid/bad-hex", TEST_IFCFG_WIFI_OPEN_SSID_BAD_HEX, test_read_wifi_open_ssid_bad); + g_test_add_func (TPATH "wifi/read/open-ssid/bad-hex", test_read_wifi_open_ssid_hex_bad); g_test_add_data_func (TPATH "wifi/read/open-ssid/long-hex", TEST_IFCFG_WIFI_OPEN_SSID_LONG_HEX, test_read_wifi_open_ssid_bad); g_test_add_data_func (TPATH "wifi/read/open-ssid/long-quoted", TEST_IFCFG_WIFI_OPEN_SSID_LONG_QUOTED, test_read_wifi_open_ssid_bad); g_test_add_func (TPATH "wifi/read/open/quoted-ssid", test_read_wifi_open_ssid_quoted); @@ -8970,6 +9017,9 @@ int main (int argc, char **argv) g_test_add_func (TPATH "vlan/read/reorder-hdr-1", test_read_vlan_reorder_hdr_1); g_test_add_func (TPATH "vlan/read/reorder-hdr-2", test_read_vlan_reorder_hdr_2); g_test_add_func (TPATH "wired/read/read-wake-on-lan", test_read_wired_wake_on_lan); + g_test_add_func (TPATH "wired/read/read-auto-negotiate-off", test_read_wired_auto_negotiate_off); + g_test_add_func (TPATH "wired/read/read-auto-negotiate-on", test_read_wired_auto_negotiate_on); + g_test_add_func (TPATH "wired/read/unkwnown-ethtool-opt", test_read_wired_unknown_ethtool_opt); g_test_add_func (TPATH "wired/write/static", test_write_wired_static); g_test_add_func (TPATH "wired/write/static-ip6-only", test_write_wired_static_ip6_only); @@ -8989,6 +9039,8 @@ int main (int argc, char **argv) g_test_add_func (TPATH "wired/write-aliases", test_write_wired_aliases); g_test_add_func (TPATH "ipv4/write-static-addresses-GATEWAY", test_write_gateway); g_test_add_func (TPATH "wired/write-wake-on-lan", test_write_wired_wake_on_lan); + g_test_add_func (TPATH "wired/write-auto-negotiate-off", test_write_wired_auto_negotiate_off); + g_test_add_func (TPATH "wired/write-auto-negotiate-on", test_write_wired_auto_negotiate_on); g_test_add_func (TPATH "wifi/write/open", test_write_wifi_open); g_test_add_func (TPATH "wifi/write/open/hex-ssid", test_write_wifi_open_hex_ssid); g_test_add_func (TPATH "wifi/write/wep", test_write_wifi_wep); @@ -9082,6 +9134,9 @@ int main (int argc, char **argv) g_test_add_func (TPATH "team/write-port", test_write_team_port); g_test_add_func (TPATH "team/read-port-empty-config", test_read_team_port_empty_config); + g_test_add_func (TPATH "proxy/read-proxy-basic", test_read_proxy_basic); + g_test_add_func (TPATH "proxy/write-proxy-basic", test_write_proxy_basic); + g_test_add_func (TPATH "sit/read/ignore", test_sit_read_ignore); /* Stuff we expect to fail for now */ @@ -9090,6 +9145,11 @@ int main (int argc, char **argv) g_test_add_data_func (TPATH "wwan/write-gsm", GUINT_TO_POINTER (TRUE), test_write_mobile_broadband); g_test_add_data_func (TPATH "wwan/write-cdma", GUINT_TO_POINTER (FALSE), test_write_mobile_broadband); + g_test_add_func (TPATH "no-trailing-newline", test_ifcfg_no_trailing_newline); + + g_test_add_func (TPATH "utils/name", test_utils_name); + g_test_add_func (TPATH "utils/path", test_utils_path); + g_test_add_func (TPATH "utils/ignore", test_utils_ignore); + return g_test_run (); } - diff --git a/src/settings/plugins/ifcfg-rh/utils.c b/src/settings/plugins/ifcfg-rh/utils.c deleted file mode 100644 index b9d52b7f..00000000 --- a/src/settings/plugins/ifcfg-rh/utils.c +++ /dev/null @@ -1,446 +0,0 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* NetworkManager system settings service - * - * 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 - 2012 Red Hat, Inc. - */ - -#include "nm-default.h" - -#include "utils.h" - -#include -#include - -#include "nm-core-internal.h" -#include "NetworkManagerUtils.h" - -#include "common.h" - -/* - * utils_single_quote_string - * - * Put string inside single quotes and remove CR, LF characters. If single quote - * is present, escape it with a backslash and prepend the whole string with $ - * in order to have $'string'. That allows us to use single quote inside - * single quotes without breaking bash syntax. (man bash, section QUOTING). - * - * Caller is responsible for freeing the returned string. - */ -char * -utils_single_quote_string (const char *str) -{ - static const char *drop_chars = "\r\n"; /* drop CR and LF */ - static const char escape_char = '\\'; /* escape char is backslash */ - static const char quote_char = '\''; /* quote char is single quote */ - size_t i, slen, j = 0; - size_t drop = 0, extra = 0; - char *new_str; - - slen = strlen (str); - for (i = 0; i < slen; i++) { - if (str[i] == quote_char) - extra++; - if (strchr (drop_chars, str[i])) - drop++; - } - new_str = g_malloc0 (slen + extra - drop + 4); /* 4 is for $''\0*/ - - if (extra > 0) - new_str[j++] = '$'; - new_str[j++] = quote_char; - for (i = 0; i < slen; i++) { - if (strchr (drop_chars, str[i])) - continue; - if (str[i] == quote_char) - new_str[j++] = escape_char; - new_str[j++] = str[i]; - } - new_str[j] = quote_char; - - return new_str; -} - -/* - * utils_single_unquote_string - * - * Remove string from single (or double) quotes, and remove escaping of '. - * Also remove first $ if the string is in the form of $'string'. - * - * Caller is responsible for freeing the returned string. - */ -char * -utils_single_unquote_string (const char *str) -{ - static const char escape_char = '\\'; /* escape char is backslash */ - static const char q_char = '\''; /* quote char is single quote */ - static const char dq_char = '"'; /* double quote char */ - size_t i, slen, j = 0, quote = 0, dollar = 0; - char *new_str; - - slen = strlen (str); - new_str = g_malloc0 (slen + 1); - - if ( (slen >= 2 && (str[0] == dq_char || str[0] == q_char) && str[0] == str[slen-1]) - || (slen >= 3 && str[0] == '$' && str[1] == q_char && str[1] == str[slen-1])) { - quote = 1; - if (str[0] == '$') dollar = 1; - } - - i = quote + dollar; - while (i < slen - quote) { - if (str[i] == escape_char && str[i+1] == q_char && i+1 < slen-quote) - i++; - new_str[j++] = str[i++]; - } - new_str[j] = '\0'; - - return new_str; -} - -/* - * Check ';[a-fA-F0-9]{8}' file suffix used for temporary files by rpm when - * installing packages. - * - * Implementation taken from upstart. - */ -static gboolean -check_rpm_temp_suffix (const char *path) -{ - const char *ptr; - - g_return_val_if_fail (path != NULL, FALSE); - - /* Matches *;[a-fA-F0-9]{8}; used by rpm */ - ptr = strrchr (path, ';'); - if (ptr && (strspn (ptr + 1, "abcdefABCDEF0123456789") == 8) - && (! ptr[9])) - return TRUE; - return FALSE; -} - -static gboolean -check_suffix (const char *base, const char *tag) -{ - int len, tag_len; - - g_return_val_if_fail (base != NULL, TRUE); - g_return_val_if_fail (tag != NULL, TRUE); - - len = strlen (base); - tag_len = strlen (tag); - if ((len > tag_len) && !strcasecmp (base + len - tag_len, tag)) - return TRUE; - return FALSE; -} - -gboolean -utils_should_ignore_file (const char *filename, gboolean only_ifcfg) -{ - gs_free char *base = NULL; - - g_return_val_if_fail (filename != NULL, TRUE); - - base = g_path_get_basename (filename); - - /* Only handle ifcfg, keys, and routes files */ - if (strncmp (base, IFCFG_TAG, strlen (IFCFG_TAG)) != 0) { - if (only_ifcfg) - return TRUE; - else if ( strncmp (base, KEYS_TAG, strlen (KEYS_TAG)) != 0 - && strncmp (base, ROUTE_TAG, strlen (ROUTE_TAG)) != 0 - && strncmp (base, ROUTE6_TAG, strlen (ROUTE6_TAG)) != 0) - return TRUE; - } - - /* But not those that have certain suffixes */ - if ( check_suffix (base, BAK_TAG) - || check_suffix (base, TILDE_TAG) - || check_suffix (base, ORIG_TAG) - || check_suffix (base, REJ_TAG) - || check_suffix (base, RPMNEW_TAG) - || check_suffix (base, AUGNEW_TAG) - || check_suffix (base, AUGTMP_TAG) - || check_rpm_temp_suffix (base)) - return TRUE; - - return FALSE; -} - -char * -utils_cert_path (const char *parent, const char *suffix) -{ - const char *name; - char *dir, *path; - - g_return_val_if_fail (parent != NULL, NULL); - g_return_val_if_fail (suffix != NULL, NULL); - - name = utils_get_ifcfg_name (parent, FALSE); - dir = g_path_get_dirname (parent); - path = g_strdup_printf ("%s/%s-%s", dir, name, suffix); - g_free (dir); - return path; -} - -const char * -utils_get_ifcfg_name (const char *file, gboolean only_ifcfg) -{ - const char *name; - - g_return_val_if_fail (file != NULL, NULL); - - name = strrchr (file, '/'); - if (!name) - name = file; - else - name++; - if (!*name) - return NULL; - -#define MATCH_TAG_AND_RETURN(name, TAG) \ - G_STMT_START { \ - if (strncmp (name, TAG, NM_STRLEN (TAG)) == 0) { \ - name += NM_STRLEN (TAG); \ - if (name[0] == '\0') \ - return NULL; \ - else \ - return name; \ - } \ - } G_STMT_END - - /* Do not detect alias files and return 'eth0:0' instead of 'eth0'. - * Unfortunately, we cannot be sure that our files don't contain colons, - * so we cannot reject files with colons. - * - * Instead, you must not call utils_get_ifcfg_name() with an alias file - * or files that are ignored. */ - MATCH_TAG_AND_RETURN (name, IFCFG_TAG); - if (!only_ifcfg) { - MATCH_TAG_AND_RETURN (name, KEYS_TAG); - MATCH_TAG_AND_RETURN (name, ROUTE_TAG); - MATCH_TAG_AND_RETURN (name, ROUTE6_TAG); - } - - return NULL; -} - -/* Used to get any ifcfg/extra file path from any other ifcfg/extra path - * in the form . - */ -static char * -utils_get_extra_path (const char *parent, const char *tag) -{ - char *item_path = NULL, *dirname; - const char *name; - - g_return_val_if_fail (parent != NULL, NULL); - g_return_val_if_fail (tag != NULL, NULL); - - dirname = g_path_get_dirname (parent); - if (!dirname) - return NULL; - - name = utils_get_ifcfg_name (parent, FALSE); - if (name) { - if (!strcmp (dirname, ".")) - item_path = g_strdup_printf ("%s%s", tag, name); - else - item_path = g_strdup_printf ("%s/%s%s", dirname, tag, name); - } - g_free (dirname); - - return item_path; -} - -char * -utils_get_ifcfg_path (const char *parent) -{ - return utils_get_extra_path (parent, IFCFG_TAG); -} - -char * -utils_get_keys_path (const char *parent) -{ - return utils_get_extra_path (parent, KEYS_TAG); -} - -char * -utils_get_route_path (const char *parent) -{ - return utils_get_extra_path (parent, ROUTE_TAG); -} - -char * -utils_get_route6_path (const char *parent) -{ - return utils_get_extra_path (parent, ROUTE6_TAG); -} - -shvarFile * -utils_get_extra_ifcfg (const char *parent, const char *tag, gboolean should_create) -{ - shvarFile *ifcfg = NULL; - char *path; - - path = utils_get_extra_path (parent, tag); - if (!path) - return NULL; - - if (should_create && !g_file_test (path, G_FILE_TEST_EXISTS)) - ifcfg = svCreateFile (path); - - if (!ifcfg) - ifcfg = svOpenFile (path, NULL); - - g_free (path); - return ifcfg; -} - -shvarFile * -utils_get_keys_ifcfg (const char *parent, gboolean should_create) -{ - return utils_get_extra_ifcfg (parent, KEYS_TAG, should_create); -} - -shvarFile * -utils_get_route_ifcfg (const char *parent, gboolean should_create) -{ - return utils_get_extra_ifcfg (parent, ROUTE_TAG, should_create); -} - -shvarFile * -utils_get_route6_ifcfg (const char *parent, gboolean should_create) -{ - return utils_get_extra_ifcfg (parent, ROUTE6_TAG, should_create); -} - -/* Finds out if route file has new or older format - * Returns TRUE - new syntax (ADDRESS=a.b.c.d ...), error opening file or empty - * FALSE - older syntax, i.e. argument to 'ip route add' (1.2.3.0/24 via 11.22.33.44) - */ -gboolean -utils_has_route_file_new_syntax (const char *filename) -{ - char *contents = NULL; - gsize len = 0; - gboolean ret = FALSE; - const char *pattern = "^[[:space:]]*ADDRESS[0-9]+="; - - g_return_val_if_fail (filename != NULL, TRUE); - - if (!g_file_get_contents (filename, &contents, &len, NULL)) - return TRUE; - - if (len <= 0) { - ret = TRUE; - goto gone; - } - - if (g_regex_match_simple (pattern, contents, G_REGEX_MULTILINE, 0)) - ret = TRUE; - -gone: - g_free (contents); - return ret; -} - -gboolean -utils_has_complex_routes (const char *filename) -{ - char *rules; - - g_return_val_if_fail (filename != NULL, TRUE); - - rules = utils_get_extra_path (filename, RULE_TAG); - if (g_file_test (rules, G_FILE_TEST_EXISTS)) { - g_free (rules); - return TRUE; - } - g_free (rules); - - rules = utils_get_extra_path (filename, RULE6_TAG); - if (g_file_test (rules, G_FILE_TEST_EXISTS)) { - g_free (rules); - return TRUE; - } - g_free (rules); - - return FALSE; -} - -/* Find out if the 'alias' file name might be an alias file for 'ifcfg' file name, - * or any alias when 'ifcfg' is NULL. Does not check that it's actually a valid - * alias name; that happens in reader.c - */ -gboolean -utils_is_ifcfg_alias_file (const char *alias, const char *ifcfg) -{ - g_return_val_if_fail (alias != NULL, FALSE); - - if (strncmp (alias, IFCFG_TAG, strlen (IFCFG_TAG))) - return FALSE; - - if (ifcfg) { - size_t len = strlen (ifcfg); - - return (strncmp (alias, ifcfg, len) == 0 && alias[len] == ':'); - } else { - return (strchr (alias, ':') != NULL); - } -} - -char * -utils_detect_ifcfg_path (const char *path, gboolean only_ifcfg) -{ - gs_free char *base = NULL; - char *ptr, *ifcfg = NULL; - - g_return_val_if_fail (path != NULL, NULL); - - if (utils_should_ignore_file (path, only_ifcfg)) - return NULL; - - base = g_path_get_basename (path); - - if (strncmp (base, IFCFG_TAG, NM_STRLEN (IFCFG_TAG)) == 0) { - if (base[NM_STRLEN (IFCFG_TAG)] == '\0') - return NULL; - if (utils_is_ifcfg_alias_file (base, NULL)) { - ifcfg = g_strdup (path); - ptr = strrchr (ifcfg, ':'); - if (ptr && ptr > ifcfg) { - *ptr = '\0'; - if (g_file_test (ifcfg, G_FILE_TEST_EXISTS)) { - /* the file has a colon, so it is probably an alias. - * To be ~more~ certain that this is an alias file, - * check whether a corresponding base file exists. */ - if (only_ifcfg) { - g_free (ifcfg); - return NULL; - } - return ifcfg; - } - } - g_free (ifcfg); - } - return g_strdup (path); - } - - if (only_ifcfg) - return NULL; - return utils_get_ifcfg_path (path); -} diff --git a/src/settings/plugins/ifcfg-rh/utils.h b/src/settings/plugins/ifcfg-rh/utils.h deleted file mode 100644 index c105487a..00000000 --- a/src/settings/plugins/ifcfg-rh/utils.h +++ /dev/null @@ -1,62 +0,0 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* NetworkManager system settings service - * - * 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 - 2012 Red Hat, Inc. - */ - -#ifndef _UTILS_H_ -#define _UTILS_H_ - -#include "nm-connection.h" - -#include "shvar.h" - -#define NM_IFCFG_CONNECTION_LOG_PATH(path) ((path) ?: "in-memory") -#define NM_IFCFG_CONNECTION_LOG_FMT "%s (%s,\"%s\")" -#define NM_IFCFG_CONNECTION_LOG_ARG(con) NM_IFCFG_CONNECTION_LOG_PATH (nm_settings_connection_get_filename ((NMSettingsConnection *) (con))), nm_connection_get_uuid ((NMConnection *) (con)), nm_connection_get_id ((NMConnection *) (con)) -#define NM_IFCFG_CONNECTION_LOG_FMTD "%s (%s,\"%s\",%p)" -#define NM_IFCFG_CONNECTION_LOG_ARGD(con) NM_IFCFG_CONNECTION_LOG_PATH (nm_settings_connection_get_filename ((NMSettingsConnection *) (con))), nm_connection_get_uuid ((NMConnection *) (con)), nm_connection_get_id ((NMConnection *) (con)), (con) - -char *utils_single_quote_string (const char *str); - -char *utils_single_unquote_string (const char *str); - -char *utils_cert_path (const char *parent, const char *suffix); - -const char *utils_get_ifcfg_name (const char *file, gboolean only_ifcfg); - -gboolean utils_should_ignore_file (const char *filename, gboolean only_ifcfg); - -char *utils_get_ifcfg_path (const char *parent); -char *utils_get_keys_path (const char *parent); -char *utils_get_route_path (const char *parent); -char *utils_get_route6_path (const char *parent); - -shvarFile *utils_get_extra_ifcfg (const char *parent, const char *tag, gboolean should_create); -shvarFile *utils_get_keys_ifcfg (const char *parent, gboolean should_create); -shvarFile *utils_get_route_ifcfg (const char *parent, gboolean should_create); -shvarFile *utils_get_route6_ifcfg (const char *parent, gboolean should_create); - -gboolean utils_has_route_file_new_syntax (const char *filename); -gboolean utils_has_complex_routes (const char *filename); - -gboolean utils_is_ifcfg_alias_file (const char *alias, const char *ifcfg); - -char *utils_detect_ifcfg_path (const char *path, gboolean only_ifcfg); - -#endif /* _UTILS_H_ */ - diff --git a/src/settings/plugins/ifcfg-rh/writer.c b/src/settings/plugins/ifcfg-rh/writer.c deleted file mode 100644 index dcc48f2a..00000000 --- a/src/settings/plugins/ifcfg-rh/writer.c +++ /dev/null @@ -1,2970 +0,0 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* NetworkManager system settings service - keyfile plugin - * - * 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 2009 - 2015 Red Hat, Inc. - */ - -#include "nm-default.h" - -#include "writer.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "nm-setting-connection.h" -#include "nm-setting-wired.h" -#include "nm-setting-wireless.h" -#include "nm-setting-8021x.h" -#include "nm-setting-ip4-config.h" -#include "nm-setting-ip6-config.h" -#include "nm-setting-pppoe.h" -#include "nm-setting-vlan.h" -#include "nm-setting-team.h" -#include "nm-setting-team-port.h" -#include "nm-utils.h" -#include "nm-core-internal.h" -#include "NetworkManagerUtils.h" - -#include "common.h" -#include "shvar.h" -#include "reader.h" -#include "utils.h" - -/*****************************************************************************/ - -#define _NMLOG_DOMAIN LOGD_SETTINGS -#define _NMLOG_PREFIX_NAME "ifcfg-rh" -#define _NMLOG(level, ...) \ - G_STMT_START { \ - nm_log ((level), (_NMLOG_DOMAIN), \ - "%s" _NM_UTILS_MACRO_FIRST(__VA_ARGS__), \ - _NMLOG_PREFIX_NAME": " \ - _NM_UTILS_MACRO_REST(__VA_ARGS__)); \ - } G_STMT_END - -/*****************************************************************************/ - -static void -save_secret_flags (shvarFile *ifcfg, - const char *key, - NMSettingSecretFlags flags) -{ - GString *str; - - g_return_if_fail (ifcfg != NULL); - g_return_if_fail (key != NULL); - - if (flags == NM_SETTING_SECRET_FLAG_NONE) { - svSetValue (ifcfg, key, NULL, FALSE); - return; - } - - /* Convert flags bitfield into string representation */ - str = g_string_sized_new (20); - if (flags & NM_SETTING_SECRET_FLAG_AGENT_OWNED) - g_string_append (str, SECRET_FLAG_AGENT); - - if (flags & NM_SETTING_SECRET_FLAG_NOT_SAVED) { - if (str->len) - g_string_append_c (str, ' '); - g_string_append (str, SECRET_FLAG_NOT_SAVED); - } - - if (flags & NM_SETTING_SECRET_FLAG_NOT_REQUIRED) { - if (str->len) - g_string_append_c (str, ' '); - g_string_append (str, SECRET_FLAG_NOT_REQUIRED); - } - - svSetValue (ifcfg, key, str->len ? str->str : NULL, FALSE); - g_string_free (str, TRUE); -} - -static void -set_secret (shvarFile *ifcfg, - const char *key, - const char *value, - const char *flags_key, - NMSettingSecretFlags flags, - gboolean verbatim) -{ - shvarFile *keyfile; - GError *error = NULL; - - /* Clear the secret from the ifcfg and the associated "keys" file */ - svSetValue (ifcfg, key, NULL, FALSE); - - /* Save secret flags */ - save_secret_flags (ifcfg, flags_key, flags); - - keyfile = utils_get_keys_ifcfg (ifcfg->fileName, TRUE); - if (!keyfile) { - _LOGW ("could not create ifcfg file for '%s'", ifcfg->fileName); - goto error; - } - - /* Clear the secret from the associated "keys" file */ - svSetValue (keyfile, key, NULL, FALSE); - - /* Only write the secret if it's system owned and supposed to be saved */ - if (flags == NM_SETTING_SECRET_FLAG_NONE) - svSetValue (keyfile, key, value, verbatim); - - if (!svWriteFile (keyfile, 0600, &error)) { - _LOGW ("could not update ifcfg file '%s': %s", - keyfile->fileName, error->message); - g_clear_error (&error); - svCloseFile (keyfile); - goto error; - } - svCloseFile (keyfile); - return; - -error: - /* Try setting the secret in the actual ifcfg */ - svSetValue (ifcfg, key, value, FALSE); -} - -static gboolean -write_secret_file (const char *path, - const char *data, - gsize len, - GError **error) -{ - char *tmppath; - int fd = -1, written; - gboolean success = FALSE; - mode_t saved_umask; - - tmppath = g_malloc0 (strlen (path) + 10); - memcpy (tmppath, path, strlen (path)); - strcat (tmppath, ".XXXXXX"); - - /* Only readable by root */ - saved_umask = umask (S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); - - errno = 0; - fd = mkstemp (tmppath); - if (fd < 0) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, - "Could not create temporary file for '%s': %d", - path, errno); - goto out; - } - - errno = 0; - written = write (fd, data, len); - if (written != len) { - close (fd); - unlink (tmppath); - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, - "Could not write temporary file for '%s': %d", - path, errno); - goto out; - } - close (fd); - - /* Try to rename */ - errno = 0; - if (rename (tmppath, path)) { - unlink (tmppath); - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, - "Could not rename temporary file to '%s': %d", - path, errno); - goto out; - } - success = TRUE; - -out: - umask (saved_umask); - g_free (tmppath); - return success; -} - -typedef struct ObjectType { - const char *setting_key; - NMSetting8021xCKScheme (*scheme_func)(NMSetting8021x *setting); - const char * (*path_func) (NMSetting8021x *setting); - GBytes * (*blob_func) (NMSetting8021x *setting); - const char *ifcfg_key; - const char *suffix; -} ObjectType; - -static const ObjectType ca_type = { - NM_SETTING_802_1X_CA_CERT, - nm_setting_802_1x_get_ca_cert_scheme, - nm_setting_802_1x_get_ca_cert_path, - nm_setting_802_1x_get_ca_cert_blob, - "IEEE_8021X_CA_CERT", - "ca-cert.der" -}; - -static const ObjectType phase2_ca_type = { - NM_SETTING_802_1X_PHASE2_CA_CERT, - nm_setting_802_1x_get_phase2_ca_cert_scheme, - nm_setting_802_1x_get_phase2_ca_cert_path, - nm_setting_802_1x_get_phase2_ca_cert_blob, - "IEEE_8021X_INNER_CA_CERT", - "inner-ca-cert.der" -}; - -static const ObjectType client_type = { - NM_SETTING_802_1X_CLIENT_CERT, - nm_setting_802_1x_get_client_cert_scheme, - nm_setting_802_1x_get_client_cert_path, - nm_setting_802_1x_get_client_cert_blob, - "IEEE_8021X_CLIENT_CERT", - "client-cert.der" -}; - -static const ObjectType phase2_client_type = { - NM_SETTING_802_1X_PHASE2_CLIENT_CERT, - nm_setting_802_1x_get_phase2_client_cert_scheme, - nm_setting_802_1x_get_phase2_client_cert_path, - nm_setting_802_1x_get_phase2_client_cert_blob, - "IEEE_8021X_INNER_CLIENT_CERT", - "inner-client-cert.der" -}; - -static const ObjectType pk_type = { - NM_SETTING_802_1X_PRIVATE_KEY, - nm_setting_802_1x_get_private_key_scheme, - nm_setting_802_1x_get_private_key_path, - nm_setting_802_1x_get_private_key_blob, - "IEEE_8021X_PRIVATE_KEY", - "private-key.pem" -}; - -static const ObjectType phase2_pk_type = { - NM_SETTING_802_1X_PHASE2_PRIVATE_KEY, - nm_setting_802_1x_get_phase2_private_key_scheme, - nm_setting_802_1x_get_phase2_private_key_path, - nm_setting_802_1x_get_phase2_private_key_blob, - "IEEE_8021X_INNER_PRIVATE_KEY", - "inner-private-key.pem" -}; - -static const ObjectType p12_type = { - NM_SETTING_802_1X_PRIVATE_KEY, - nm_setting_802_1x_get_private_key_scheme, - nm_setting_802_1x_get_private_key_path, - nm_setting_802_1x_get_private_key_blob, - "IEEE_8021X_PRIVATE_KEY", - "private-key.p12" -}; - -static const ObjectType phase2_p12_type = { - NM_SETTING_802_1X_PHASE2_PRIVATE_KEY, - nm_setting_802_1x_get_phase2_private_key_scheme, - nm_setting_802_1x_get_phase2_private_key_path, - nm_setting_802_1x_get_phase2_private_key_blob, - "IEEE_8021X_INNER_PRIVATE_KEY", - "inner-private-key.p12" -}; - -static gboolean -write_object (NMSetting8021x *s_8021x, - shvarFile *ifcfg, - const ObjectType *objtype, - GError **error) -{ - NMSetting8021xCKScheme scheme; - const char *path = NULL; - GBytes *blob = NULL; - - g_return_val_if_fail (ifcfg != NULL, FALSE); - g_return_val_if_fail (objtype != NULL, FALSE); - - scheme = (*(objtype->scheme_func))(s_8021x); - switch (scheme) { - case NM_SETTING_802_1X_CK_SCHEME_BLOB: - blob = (*(objtype->blob_func))(s_8021x); - break; - case NM_SETTING_802_1X_CK_SCHEME_PATH: - path = (*(objtype->path_func))(s_8021x); - break; - default: - break; - } - - /* If certificate/private key wasn't sent, the connection may no longer be - * 802.1x and thus we clear out the paths and certs. - */ - if (!path && !blob) { - char *standard_file; - int ignored; - - /* Since no cert/private key is now being used, delete any standard file - * that was created for this connection, but leave other files alone. - * Thus, for example, - * /etc/sysconfig/network-scripts/ca-cert-Test_Write_Wifi_WPA_EAP-TLS.der - * will be deleted, but /etc/pki/tls/cert.pem will not. - */ - standard_file = utils_cert_path (ifcfg->fileName, objtype->suffix); - if (g_file_test (standard_file, G_FILE_TEST_EXISTS)) - ignored = unlink (standard_file); - g_free (standard_file); - - svSetValue (ifcfg, objtype->ifcfg_key, NULL, FALSE); - return TRUE; - } - - /* If the object path was specified, prefer that over any raw cert data that - * may have been sent. - */ - if (path) { - svSetValue (ifcfg, objtype->ifcfg_key, path, FALSE); - return TRUE; - } - - /* If it's raw certificate data, write the data out to the standard file */ - if (blob) { - gboolean success; - char *new_file; - GError *write_error = NULL; - - new_file = utils_cert_path (ifcfg->fileName, objtype->suffix); - if (!new_file) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, - "Could not create file path for %s / %s", - NM_SETTING_802_1X_SETTING_NAME, objtype->setting_key); - return FALSE; - } - - /* Write the raw certificate data out to the standard file so that we - * can use paths from now on instead of pushing around the certificate - * data itself. - */ - success = write_secret_file (new_file, - (const char *) g_bytes_get_data (blob, NULL), - g_bytes_get_size (blob), - &write_error); - if (success) { - svSetValue (ifcfg, objtype->ifcfg_key, new_file, FALSE); - g_free (new_file); - return TRUE; - } else { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, - "Could not write certificate/key for %s / %s: %s", - NM_SETTING_802_1X_SETTING_NAME, objtype->setting_key, - (write_error && write_error->message) ? write_error->message : "(unknown)"); - g_clear_error (&write_error); - } - g_free (new_file); - } - - return FALSE; -} - -static gboolean -write_8021x_certs (NMSetting8021x *s_8021x, - gboolean phase2, - shvarFile *ifcfg, - GError **error) -{ - const char *password = NULL; - gboolean success = FALSE, is_pkcs12 = FALSE; - const ObjectType *otype = NULL; - NMSettingSecretFlags flags = NM_SETTING_SECRET_FLAG_NONE; - - /* CA certificate */ - if (!write_object (s_8021x, ifcfg, phase2 ? &phase2_ca_type : &ca_type, error)) - return FALSE; - - /* Private key */ - if (phase2) { - otype = &phase2_pk_type; - if (nm_setting_802_1x_get_phase2_private_key_format (s_8021x) == NM_SETTING_802_1X_CK_FORMAT_PKCS12) { - otype = &phase2_p12_type; - is_pkcs12 = TRUE; - } - password = nm_setting_802_1x_get_phase2_private_key_password (s_8021x); - flags = nm_setting_802_1x_get_phase2_private_key_password_flags (s_8021x); - } else { - otype = &pk_type; - if (nm_setting_802_1x_get_private_key_format (s_8021x) == NM_SETTING_802_1X_CK_FORMAT_PKCS12) { - otype = &p12_type; - is_pkcs12 = TRUE; - } - password = nm_setting_802_1x_get_private_key_password (s_8021x); - flags = nm_setting_802_1x_get_private_key_password_flags (s_8021x); - } - - /* Save the private key */ - if (!write_object (s_8021x, ifcfg, otype, error)) - goto out; - - /* Private key password */ - if (phase2) { - set_secret (ifcfg, - "IEEE_8021X_INNER_PRIVATE_KEY_PASSWORD", - password, - "IEEE_8021X_INNER_PRIVATE_KEY_PASSWORD_FLAGS", - flags, - FALSE); - } else { - set_secret (ifcfg, - "IEEE_8021X_PRIVATE_KEY_PASSWORD", - password, - "IEEE_8021X_PRIVATE_KEY_PASSWORD_FLAGS", - flags, - FALSE); - } - - /* Client certificate */ - if (is_pkcs12) { - /* Don't need a client certificate with PKCS#12 since the file is both - * the client certificate and the private key in one file. - */ - svSetValue (ifcfg, - phase2 ? "IEEE_8021X_INNER_CLIENT_CERT" : "IEEE_8021X_CLIENT_CERT", - NULL, FALSE); - } else { - /* Save the client certificate */ - if (!write_object (s_8021x, ifcfg, phase2 ? &phase2_client_type : &client_type, error)) - goto out; - } - - success = TRUE; - -out: - return success; -} - -static gboolean -write_8021x_setting (NMConnection *connection, - shvarFile *ifcfg, - gboolean wired, - GError **error) -{ - NMSetting8021x *s_8021x; - const char *value, *match; - char *tmp = NULL; - gboolean success = FALSE; - GString *phase2_auth; - GString *str; - guint32 i, num; - - s_8021x = nm_connection_get_setting_802_1x (connection); - if (!s_8021x) { - /* If wired, clear KEY_MGMT */ - if (wired) - svSetValue (ifcfg, "KEY_MGMT", NULL, FALSE); - return TRUE; - } - - /* If wired, write KEY_MGMT */ - if (wired) - svSetValue (ifcfg, "KEY_MGMT", "IEEE8021X", FALSE); - - /* EAP method */ - if (nm_setting_802_1x_get_num_eap_methods (s_8021x)) { - value = nm_setting_802_1x_get_eap_method (s_8021x, 0); - if (value) - tmp = g_ascii_strup (value, -1); - } - svSetValue (ifcfg, "IEEE_8021X_EAP_METHODS", tmp ? tmp : NULL, FALSE); - g_free (tmp); - - svSetValue (ifcfg, "IEEE_8021X_IDENTITY", - nm_setting_802_1x_get_identity (s_8021x), - FALSE); - - svSetValue (ifcfg, "IEEE_8021X_ANON_IDENTITY", - nm_setting_802_1x_get_anonymous_identity (s_8021x), - FALSE); - - set_secret (ifcfg, - "IEEE_8021X_PASSWORD", - nm_setting_802_1x_get_password (s_8021x), - "IEEE_8021X_PASSWORD_FLAGS", - nm_setting_802_1x_get_password_flags (s_8021x), - FALSE); - - /* PEAP version */ - value = nm_setting_802_1x_get_phase1_peapver (s_8021x); - svSetValue (ifcfg, "IEEE_8021X_PEAP_VERSION", NULL, FALSE); - if (value && (!strcmp (value, "0") || !strcmp (value, "1"))) - svSetValue (ifcfg, "IEEE_8021X_PEAP_VERSION", value, FALSE); - - /* Force new PEAP label */ - value = nm_setting_802_1x_get_phase1_peaplabel (s_8021x); - svSetValue (ifcfg, "IEEE_8021X_PEAP_FORCE_NEW_LABEL", NULL, FALSE); - if (value && !strcmp (value, "1")) - svSetValue (ifcfg, "IEEE_8021X_PEAP_FORCE_NEW_LABEL", "yes", FALSE); - - /* PAC file */ - value = nm_setting_802_1x_get_pac_file (s_8021x); - svSetValue (ifcfg, "IEEE_8021X_PAC_FILE", NULL, FALSE); - if (value) - svSetValue (ifcfg, "IEEE_8021X_PAC_FILE", value, FALSE); - - /* FAST PAC provisioning */ - value = nm_setting_802_1x_get_phase1_fast_provisioning (s_8021x); - svSetValue (ifcfg, "IEEE_8021X_FAST_PROVISIONING", NULL, FALSE); - if (value) { - if (strcmp (value, "1") == 0) - svSetValue (ifcfg, "IEEE_8021X_FAST_PROVISIONING", "allow-unauth", FALSE); - else if (strcmp (value, "2") == 0) - svSetValue (ifcfg, "IEEE_8021X_FAST_PROVISIONING", "allow-auth", FALSE); - else if (strcmp (value, "3") == 0) - svSetValue (ifcfg, "IEEE_8021X_FAST_PROVISIONING", "allow-unauth allow-auth", FALSE); - } - - /* Phase2 auth methods */ - svSetValue (ifcfg, "IEEE_8021X_INNER_AUTH_METHODS", NULL, FALSE); - phase2_auth = g_string_new (NULL); - - value = nm_setting_802_1x_get_phase2_auth (s_8021x); - if (value) { - tmp = g_ascii_strup (value, -1); - g_string_append (phase2_auth, tmp); - g_free (tmp); - } - - value = nm_setting_802_1x_get_phase2_autheap (s_8021x); - if (value) { - if (phase2_auth->len) - g_string_append_c (phase2_auth, ' '); - - tmp = g_ascii_strup (value, -1); - g_string_append_printf (phase2_auth, "EAP-%s", tmp); - g_free (tmp); - } - - svSetValue (ifcfg, "IEEE_8021X_INNER_AUTH_METHODS", - phase2_auth->len ? phase2_auth->str : NULL, - FALSE); - - g_string_free (phase2_auth, TRUE); - - svSetValue (ifcfg, "IEEE_8021X_SUBJECT_MATCH", - nm_setting_802_1x_get_subject_match (s_8021x), - FALSE); - - svSetValue (ifcfg, "IEEE_8021X_PHASE2_SUBJECT_MATCH", - nm_setting_802_1x_get_phase2_subject_match (s_8021x), - FALSE); - - svSetValue (ifcfg, "IEEE_8021X_ALTSUBJECT_MATCHES", NULL, FALSE); - str = g_string_new (NULL); - num = nm_setting_802_1x_get_num_altsubject_matches (s_8021x); - for (i = 0; i < num; i++) { - if (i > 0) - g_string_append_c (str, ' '); - match = nm_setting_802_1x_get_altsubject_match (s_8021x, i); - g_string_append (str, match); - } - if (str->len > 0) - svSetValue (ifcfg, "IEEE_8021X_ALTSUBJECT_MATCHES", str->str, FALSE); - g_string_free (str, TRUE); - - svSetValue (ifcfg, "IEEE_8021X_PHASE2_ALTSUBJECT_MATCHES", NULL, FALSE); - str = g_string_new (NULL); - num = nm_setting_802_1x_get_num_phase2_altsubject_matches (s_8021x); - for (i = 0; i < num; i++) { - if (i > 0) - g_string_append_c (str, ' '); - match = nm_setting_802_1x_get_phase2_altsubject_match (s_8021x, i); - g_string_append (str, match); - } - if (str->len > 0) - svSetValue (ifcfg, "IEEE_8021X_PHASE2_ALTSUBJECT_MATCHES", str->str, FALSE); - g_string_free (str, TRUE); - - svSetValue (ifcfg, "IEEE_8021X_DOMAIN_SUFFIX_MATCH", - nm_setting_802_1x_get_domain_suffix_match (s_8021x), - FALSE); - svSetValue (ifcfg, "IEEE_8021X_PHASE2_DOMAIN_SUFFIX_MATCH", - nm_setting_802_1x_get_phase2_domain_suffix_match (s_8021x), - FALSE); - - success = write_8021x_certs (s_8021x, FALSE, ifcfg, error); - if (success) { - /* phase2/inner certs */ - success = write_8021x_certs (s_8021x, TRUE, ifcfg, error); - } - - return success; -} - -static gboolean -write_wireless_security_setting (NMConnection *connection, - shvarFile *ifcfg, - gboolean adhoc, - gboolean *no_8021x, - GError **error) -{ - NMSettingWirelessSecurity *s_wsec; - const char *key_mgmt, *auth_alg, *key, *proto, *cipher, *psk; - gboolean wep = FALSE, wpa = FALSE, dynamic_wep = FALSE; - char *tmp; - guint32 i, num; - GString *str; - - s_wsec = nm_connection_get_setting_wireless_security (connection); - if (!s_wsec) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, - "Missing '%s' setting", NM_SETTING_WIRELESS_SECURITY_SETTING_NAME); - return FALSE; - } - - key_mgmt = nm_setting_wireless_security_get_key_mgmt (s_wsec); - g_assert (key_mgmt); - - auth_alg = nm_setting_wireless_security_get_auth_alg (s_wsec); - - svSetValue (ifcfg, "DEFAULTKEY", NULL, FALSE); - - if (!strcmp (key_mgmt, "none")) { - svSetValue (ifcfg, "KEY_MGMT", NULL, FALSE); - wep = TRUE; - *no_8021x = TRUE; - } else if (!strcmp (key_mgmt, "wpa-none") || !strcmp (key_mgmt, "wpa-psk")) { - svSetValue (ifcfg, "KEY_MGMT", "WPA-PSK", FALSE); - wpa = TRUE; - *no_8021x = TRUE; - } else if (!strcmp (key_mgmt, "ieee8021x")) { - svSetValue (ifcfg, "KEY_MGMT", "IEEE8021X", FALSE); - dynamic_wep = TRUE; - } else if (!strcmp (key_mgmt, "wpa-eap")) { - svSetValue (ifcfg, "KEY_MGMT", "WPA-EAP", FALSE); - wpa = TRUE; - } - - svSetValue (ifcfg, "SECURITYMODE", NULL, FALSE); - if (auth_alg) { - if (!strcmp (auth_alg, "shared")) - svSetValue (ifcfg, "SECURITYMODE", "restricted", FALSE); - else if (!strcmp (auth_alg, "open")) - svSetValue (ifcfg, "SECURITYMODE", "open", FALSE); - else if (!strcmp (auth_alg, "leap")) { - svSetValue (ifcfg, "SECURITYMODE", "leap", FALSE); - svSetValue (ifcfg, "IEEE_8021X_IDENTITY", - nm_setting_wireless_security_get_leap_username (s_wsec), - FALSE); - set_secret (ifcfg, - "IEEE_8021X_PASSWORD", - nm_setting_wireless_security_get_leap_password (s_wsec), - "IEEE_8021X_PASSWORD_FLAGS", - nm_setting_wireless_security_get_leap_password_flags (s_wsec), - FALSE); - *no_8021x = TRUE; - } - } - - /* WEP keys */ - - /* Clear any default key */ - set_secret (ifcfg, "KEY", NULL, "WEP_KEY_FLAGS", NM_SETTING_SECRET_FLAG_NONE, FALSE); - - /* Clear existing keys */ - for (i = 0; i < 4; i++) { - tmp = g_strdup_printf ("KEY_PASSPHRASE%d", i + 1); - set_secret (ifcfg, tmp, NULL, "WEP_KEY_FLAGS", NM_SETTING_SECRET_FLAG_NONE, FALSE); - g_free (tmp); - - tmp = g_strdup_printf ("KEY%d", i + 1); - set_secret (ifcfg, tmp, NULL, "WEP_KEY_FLAGS", NM_SETTING_SECRET_FLAG_NONE, FALSE); - g_free (tmp); - } - - /* And write the new ones out */ - if (wep) { - /* Default WEP TX key index */ - tmp = g_strdup_printf ("%d", nm_setting_wireless_security_get_wep_tx_keyidx (s_wsec) + 1); - svSetValue (ifcfg, "DEFAULTKEY", tmp, FALSE); - g_free (tmp); - - for (i = 0; i < 4; i++) { - NMWepKeyType key_type; - - key = nm_setting_wireless_security_get_wep_key (s_wsec, i); - if (key) { - char *ascii_key = NULL; - - /* Passphrase needs a different ifcfg key since with WEP, there - * are some passphrases that are indistinguishable from WEP hex - * keys. - */ - key_type = nm_setting_wireless_security_get_wep_key_type (s_wsec); - if (key_type == NM_WEP_KEY_TYPE_UNKNOWN) { - if (nm_utils_wep_key_valid (key, NM_WEP_KEY_TYPE_KEY)) - key_type = NM_WEP_KEY_TYPE_KEY; - else if (nm_utils_wep_key_valid (key, NM_WEP_KEY_TYPE_PASSPHRASE)) - key_type = NM_WEP_KEY_TYPE_PASSPHRASE; - } - if (key_type == NM_WEP_KEY_TYPE_PASSPHRASE) - tmp = g_strdup_printf ("KEY_PASSPHRASE%d", i + 1); - else if (key_type == NM_WEP_KEY_TYPE_KEY) { - tmp = g_strdup_printf ("KEY%d", i + 1); - - /* Add 's:' prefix for ASCII keys */ - if (strlen (key) == 5 || strlen (key) == 13) { - ascii_key = g_strdup_printf ("s:%s", key); - key = ascii_key; - } - } else { - _LOGW ("invalid WEP key '%s'", key); - tmp = NULL; - } - - if (tmp) { - set_secret (ifcfg, - tmp, - key, - "WEP_KEY_FLAGS", - nm_setting_wireless_security_get_wep_key_flags (s_wsec), - FALSE); - } - g_free (tmp); - g_free (ascii_key); - } - } - } - - /* WPA protos */ - svSetValue (ifcfg, "WPA_ALLOW_WPA", NULL, FALSE); - svSetValue (ifcfg, "WPA_ALLOW_WPA2", NULL, FALSE); - num = nm_setting_wireless_security_get_num_protos (s_wsec); - for (i = 0; i < num; i++) { - proto = nm_setting_wireless_security_get_proto (s_wsec, i); - if (proto && !strcmp (proto, "wpa")) - svSetValue (ifcfg, "WPA_ALLOW_WPA", "yes", FALSE); - else if (proto && !strcmp (proto, "rsn")) - svSetValue (ifcfg, "WPA_ALLOW_WPA2", "yes", FALSE); - } - - /* WPA Pairwise ciphers */ - svSetValue (ifcfg, "CIPHER_PAIRWISE", NULL, FALSE); - str = g_string_new (NULL); - num = nm_setting_wireless_security_get_num_pairwise (s_wsec); - for (i = 0; i < num; i++) { - if (i > 0) - g_string_append_c (str, ' '); - cipher = nm_setting_wireless_security_get_pairwise (s_wsec, i); - - /* Don't write out WEP40 or WEP104 if for some reason they are set; they - * are not valid pairwise ciphers. - */ - if (strcmp (cipher, "wep40") && strcmp (cipher, "wep104")) { - tmp = g_ascii_strup (cipher, -1); - g_string_append (str, tmp); - g_free (tmp); - } - } - if (strlen (str->str) && (dynamic_wep == FALSE)) - svSetValue (ifcfg, "CIPHER_PAIRWISE", str->str, FALSE); - g_string_free (str, TRUE); - - /* WPA Group ciphers */ - svSetValue (ifcfg, "CIPHER_GROUP", NULL, FALSE); - str = g_string_new (NULL); - num = nm_setting_wireless_security_get_num_groups (s_wsec); - for (i = 0; i < num; i++) { - if (i > 0) - g_string_append_c (str, ' '); - cipher = nm_setting_wireless_security_get_group (s_wsec, i); - tmp = g_ascii_strup (cipher, -1); - g_string_append (str, tmp); - g_free (tmp); - } - if (strlen (str->str) && (dynamic_wep == FALSE)) - svSetValue (ifcfg, "CIPHER_GROUP", str->str, FALSE); - g_string_free (str, TRUE); - - /* WPA Passphrase */ - if (wpa) { - char *quoted = NULL; - - psk = nm_setting_wireless_security_get_psk (s_wsec); - if (psk && (strlen (psk) != 64)) { - /* Quote the PSK since it's a passphrase */ - quoted = utils_single_quote_string (psk); - } - set_secret (ifcfg, - "WPA_PSK", - quoted ? quoted : psk, - "WPA_PSK_FLAGS", - nm_setting_wireless_security_get_psk_flags (s_wsec), - TRUE); - g_free (quoted); - } else { - set_secret (ifcfg, - "WPA_PSK", - NULL, - "WPA_PSK_FLAGS", - NM_SETTING_SECRET_FLAG_NONE, - FALSE); - } - - return TRUE; -} - -static gboolean -write_wireless_setting (NMConnection *connection, - shvarFile *ifcfg, - gboolean *no_8021x, - GError **error) -{ - NMSettingWireless *s_wireless; - char *tmp, *tmp2; - GBytes *ssid; - const guint8 *ssid_data; - gsize ssid_len; - const char *mode, *bssid; - const char *device_mac, *cloned_mac; - char buf[33]; - guint32 mtu, chan, i; - gboolean adhoc = FALSE, hex_ssid = FALSE; - const char * const *macaddr_blacklist; - - s_wireless = nm_connection_get_setting_wireless (connection); - if (!s_wireless) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, - "Missing '%s' setting", NM_SETTING_WIRELESS_SETTING_NAME); - return FALSE; - } - - device_mac = nm_setting_wireless_get_mac_address (s_wireless); - svSetValue (ifcfg, "HWADDR", device_mac, FALSE); - - cloned_mac = nm_setting_wireless_get_cloned_mac_address (s_wireless); - svSetValue (ifcfg, "MACADDR", cloned_mac, FALSE); - - svSetValue (ifcfg, "GENERATE_MAC_ADDRESS_MASK", - nm_setting_wireless_get_generate_mac_address_mask (s_wireless), - FALSE); - - svSetValue (ifcfg, "HWADDR_BLACKLIST", NULL, FALSE); - macaddr_blacklist = nm_setting_wireless_get_mac_address_blacklist (s_wireless); - if (macaddr_blacklist[0]) { - char *blacklist_str; - - blacklist_str = g_strjoinv (" ", (char **) macaddr_blacklist); - svSetValue (ifcfg, "HWADDR_BLACKLIST", blacklist_str, FALSE); - g_free (blacklist_str); - } - - svSetValue (ifcfg, "MTU", NULL, FALSE); - mtu = nm_setting_wireless_get_mtu (s_wireless); - if (mtu) { - tmp = g_strdup_printf ("%u", mtu); - svSetValue (ifcfg, "MTU", tmp, FALSE); - g_free (tmp); - } - - ssid = nm_setting_wireless_get_ssid (s_wireless); - if (!ssid) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, - "Missing SSID in '%s' setting", NM_SETTING_WIRELESS_SETTING_NAME); - return FALSE; - } - ssid_data = g_bytes_get_data (ssid, &ssid_len); - if (!ssid_len || ssid_len > 32) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, - "Invalid SSID in '%s' setting", NM_SETTING_WIRELESS_SETTING_NAME); - return FALSE; - } - - /* If the SSID contains any non-printable characters, we need to use the - * hex notation of the SSID instead. - */ - for (i = 0; i < ssid_len; i++) { - if (!g_ascii_isprint (ssid_data[i])) { - hex_ssid = TRUE; - break; - } - } - - if (hex_ssid) { - GString *str; - - /* Hex SSIDs don't get quoted */ - str = g_string_sized_new (ssid_len * 2 + 3); - g_string_append (str, "0x"); - for (i = 0; i < ssid_len; i++) - g_string_append_printf (str, "%02X", ssid_data[i]); - svSetValue (ifcfg, "ESSID", str->str, TRUE); - g_string_free (str, TRUE); - } else { - const char *tmp_escaped; - - /* Printable SSIDs always get quoted */ - memset (buf, 0, sizeof (buf)); - memcpy (buf, ssid_data, ssid_len); - tmp_escaped = svEscape (buf, &tmp); - - /* svEscape will usually quote the string, but just for consistency, - * if svEscape doesn't quote the ESSID, we quote it ourselves. - */ - if (tmp_escaped[0] != '"' && tmp_escaped[strlen (tmp_escaped) - 1] != '"') { - tmp2 = g_strdup_printf ("\"%s\"", tmp_escaped); - svSetValue (ifcfg, "ESSID", tmp2, TRUE); - g_free (tmp2); - } else - svSetValue (ifcfg, "ESSID", tmp_escaped, TRUE); - g_free (tmp); - } - - mode = nm_setting_wireless_get_mode (s_wireless); - if (!mode || !strcmp (mode, "infrastructure")) { - svSetValue (ifcfg, "MODE", "Managed", FALSE); - } else if (!strcmp (mode, "adhoc")) { - svSetValue (ifcfg, "MODE", "Ad-Hoc", FALSE); - adhoc = TRUE; - } else if (!strcmp (mode, "ap")) { - svSetValue (ifcfg, "MODE", "Ap", FALSE); - } else { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, - "Invalid mode '%s' in '%s' setting", - mode, NM_SETTING_WIRELESS_SETTING_NAME); - return FALSE; - } - - svSetValue (ifcfg, "CHANNEL", NULL, FALSE); - svSetValue (ifcfg, "BAND", NULL, FALSE); - chan = nm_setting_wireless_get_channel (s_wireless); - if (chan) { - tmp = g_strdup_printf ("%u", chan); - svSetValue (ifcfg, "CHANNEL", tmp, FALSE); - g_free (tmp); - } else { - /* Band only set if channel is not, since channel implies band */ - svSetValue (ifcfg, "BAND", nm_setting_wireless_get_band (s_wireless), FALSE); - } - - bssid = nm_setting_wireless_get_bssid (s_wireless); - svSetValue (ifcfg, "BSSID", bssid, FALSE); - - /* Ensure DEFAULTKEY and SECURITYMODE are cleared unless there's security; - * otherwise there's no way to detect WEP vs. open when WEP keys aren't - * saved. - */ - svSetValue (ifcfg, "DEFAULTKEY", NULL, FALSE); - svSetValue (ifcfg, "SECURITYMODE", NULL, FALSE); - - if (nm_connection_get_setting_wireless_security (connection)) { - if (!write_wireless_security_setting (connection, ifcfg, adhoc, no_8021x, error)) - return FALSE; - } else { - char *keys_path; - - /* Clear out wifi security keys */ - svSetValue (ifcfg, "KEY_MGMT", NULL, FALSE); - svSetValue (ifcfg, "IEEE_8021X_IDENTITY", NULL, FALSE); - set_secret (ifcfg, "IEEE_8021X_PASSWORD", NULL, "IEEE_8021X_PASSWORD_FLAGS", NM_SETTING_SECRET_FLAG_NONE, FALSE); - svSetValue (ifcfg, "SECURITYMODE", NULL, FALSE); - - /* Clear existing keys */ - set_secret (ifcfg, "KEY", NULL, "WEP_KEY_FLAGS", NM_SETTING_SECRET_FLAG_NONE, FALSE); - for (i = 0; i < 4; i++) { - tmp = g_strdup_printf ("KEY_PASSPHRASE%d", i + 1); - set_secret (ifcfg, tmp, NULL, "WEP_KEY_FLAGS", NM_SETTING_SECRET_FLAG_NONE, FALSE); - g_free (tmp); - - tmp = g_strdup_printf ("KEY%d", i + 1); - set_secret (ifcfg, tmp, NULL, "WEP_KEY_FLAGS", NM_SETTING_SECRET_FLAG_NONE, FALSE); - g_free (tmp); - } - - svSetValue (ifcfg, "DEFAULTKEY", NULL, FALSE); - svSetValue (ifcfg, "WPA_ALLOW_WPA", NULL, FALSE); - svSetValue (ifcfg, "WPA_ALLOW_WPA2", NULL, FALSE); - svSetValue (ifcfg, "CIPHER_PAIRWISE", NULL, FALSE); - svSetValue (ifcfg, "CIPHER_GROUP", NULL, FALSE); - set_secret (ifcfg, "WPA_PSK", NULL, "WPA_PSK_FLAGS", NM_SETTING_SECRET_FLAG_NONE, FALSE); - - /* Kill any old keys file */ - keys_path = utils_get_keys_path (ifcfg->fileName); - (void) unlink (keys_path); - g_free (keys_path); - } - - svSetValue (ifcfg, "SSID_HIDDEN", nm_setting_wireless_get_hidden (s_wireless) ? "yes" : NULL, TRUE); - - switch (nm_setting_wireless_get_powersave (s_wireless)) { - case NM_SETTING_WIRELESS_POWERSAVE_IGNORE: - svSetValue (ifcfg, "POWERSAVE", "ignore", TRUE); - break; - case NM_SETTING_WIRELESS_POWERSAVE_DISABLE: - svSetValue (ifcfg, "POWERSAVE", "disable", TRUE); - break; - case NM_SETTING_WIRELESS_POWERSAVE_ENABLE: - svSetValue (ifcfg, "POWERSAVE", "enable", TRUE); - break; - default: - case NM_SETTING_WIRELESS_POWERSAVE_DEFAULT: - svSetValue (ifcfg, "POWERSAVE", NULL, TRUE); - break; - } - - svSetValue (ifcfg, "MAC_ADDRESS_RANDOMIZATION", NULL, TRUE); - switch (nm_setting_wireless_get_mac_address_randomization (s_wireless)) { - case NM_SETTING_MAC_RANDOMIZATION_DEFAULT: - svSetValue (ifcfg, "MAC_ADDRESS_RANDOMIZATION", "default", TRUE); - break; - case NM_SETTING_MAC_RANDOMIZATION_ALWAYS: - svSetValue (ifcfg, "MAC_ADDRESS_RANDOMIZATION", "always", TRUE); - break; - default: - case NM_SETTING_MAC_RANDOMIZATION_NEVER: - svSetValue (ifcfg, "MAC_ADDRESS_RANDOMIZATION", "never", TRUE); - break; - } - - svSetValue (ifcfg, "TYPE", TYPE_WIRELESS, FALSE); - - return TRUE; -} - -static gboolean -write_infiniband_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) -{ - NMSettingInfiniband *s_infiniband; - char *tmp; - const char *mac, *transport_mode, *parent; - guint32 mtu; - int p_key; - - s_infiniband = nm_connection_get_setting_infiniband (connection); - if (!s_infiniband) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, - "Missing '%s' setting", NM_SETTING_INFINIBAND_SETTING_NAME); - return FALSE; - } - - mac = nm_setting_infiniband_get_mac_address (s_infiniband); - svSetValue (ifcfg, "HWADDR", mac, FALSE); - - svSetValue (ifcfg, "MTU", NULL, FALSE); - mtu = nm_setting_infiniband_get_mtu (s_infiniband); - if (mtu) { - tmp = g_strdup_printf ("%u", mtu); - svSetValue (ifcfg, "MTU", tmp, FALSE); - g_free (tmp); - } - - transport_mode = nm_setting_infiniband_get_transport_mode (s_infiniband); - svSetValue (ifcfg, "CONNECTED_MODE", - strcmp (transport_mode, "connected") == 0 ? "yes" : "no", - FALSE); - - p_key = nm_setting_infiniband_get_p_key (s_infiniband); - if (p_key != -1) { - svSetValue (ifcfg, "PKEY", "yes", FALSE); - tmp = g_strdup_printf ("%u", p_key); - svSetValue (ifcfg, "PKEY_ID", tmp, FALSE); - g_free (tmp); - - parent = nm_setting_infiniband_get_parent (s_infiniband); - if (parent) - svSetValue (ifcfg, "PHYSDEV", parent, FALSE); - } - - svSetValue (ifcfg, "TYPE", TYPE_INFINIBAND, FALSE); - - return TRUE; -} - -static gboolean -write_wired_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) -{ - NMSettingWired *s_wired; - const char *device_mac, *cloned_mac; - char *tmp; - const char *nettype, *portname, *ctcprot, *s390_key, *s390_val; - guint32 mtu, num_opts, i; - const char *const *s390_subchannels; - GString *str; - const char * const *macaddr_blacklist; - NMSettingWiredWakeOnLan wol; - const char *wol_password; - - s_wired = nm_connection_get_setting_wired (connection); - if (!s_wired) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, - "Missing '%s' setting", NM_SETTING_WIRED_SETTING_NAME); - return FALSE; - } - - device_mac = nm_setting_wired_get_mac_address (s_wired); - svSetValue (ifcfg, "HWADDR", device_mac, FALSE); - - cloned_mac = nm_setting_wired_get_cloned_mac_address (s_wired); - svSetValue (ifcfg, "MACADDR", cloned_mac, FALSE); - - svSetValue (ifcfg, "GENERATE_MAC_ADDRESS_MASK", - nm_setting_wired_get_generate_mac_address_mask (s_wired), - FALSE); - - svSetValue (ifcfg, "HWADDR_BLACKLIST", NULL, FALSE); - macaddr_blacklist = nm_setting_wired_get_mac_address_blacklist (s_wired); - if (macaddr_blacklist[0]) { - char *blacklist_str; - - blacklist_str = g_strjoinv (" ", (char **) macaddr_blacklist); - svSetValue (ifcfg, "HWADDR_BLACKLIST", blacklist_str, FALSE); - g_free (blacklist_str); - } - - svSetValue (ifcfg, "MTU", NULL, FALSE); - mtu = nm_setting_wired_get_mtu (s_wired); - if (mtu) { - tmp = g_strdup_printf ("%u", mtu); - svSetValue (ifcfg, "MTU", tmp, FALSE); - g_free (tmp); - } - - svSetValue (ifcfg, "SUBCHANNELS", NULL, FALSE); - s390_subchannels = nm_setting_wired_get_s390_subchannels (s_wired); - if (s390_subchannels) { - int len = g_strv_length ((char **)s390_subchannels); - - tmp = NULL; - if (len == 2) { - tmp = g_strdup_printf ("%s,%s", s390_subchannels[0], s390_subchannels[1]); - } else if (len == 3) { - tmp = g_strdup_printf ("%s,%s,%s", s390_subchannels[0], s390_subchannels[1], - s390_subchannels[2]); - } - svSetValue (ifcfg, "SUBCHANNELS", tmp, FALSE); - g_free (tmp); - } - - svSetValue (ifcfg, "NETTYPE", NULL, FALSE); - nettype = nm_setting_wired_get_s390_nettype (s_wired); - if (nettype) - svSetValue (ifcfg, "NETTYPE", nettype, FALSE); - - svSetValue (ifcfg, "PORTNAME", NULL, FALSE); - portname = nm_setting_wired_get_s390_option_by_key (s_wired, "portname"); - if (portname) - svSetValue (ifcfg, "PORTNAME", portname, FALSE); - - svSetValue (ifcfg, "CTCPROT", NULL, FALSE); - ctcprot = nm_setting_wired_get_s390_option_by_key (s_wired, "ctcprot"); - if (ctcprot) - svSetValue (ifcfg, "CTCPROT", ctcprot, FALSE); - - svSetValue (ifcfg, "OPTIONS", NULL, FALSE); - num_opts = nm_setting_wired_get_num_s390_options (s_wired); - if (s390_subchannels && num_opts) { - str = g_string_sized_new (30); - for (i = 0; i < num_opts; i++) { - nm_setting_wired_get_s390_option (s_wired, i, &s390_key, &s390_val); - - /* portname is handled separately */ - if (!strcmp (s390_key, "portname") || !strcmp (s390_key, "ctcprot")) - continue; - - if (str->len) - g_string_append_c (str, ' '); - g_string_append_printf (str, "%s=%s", s390_key, s390_val); - } - if (str->len) - svSetValue (ifcfg, "OPTIONS", str->str, FALSE); - g_string_free (str, TRUE); - } - - wol = nm_setting_wired_get_wake_on_lan (s_wired); - wol_password = nm_setting_wired_get_wake_on_lan_password (s_wired); - if (wol == NM_SETTING_WIRED_WAKE_ON_LAN_IGNORE) - svSetValueFull (ifcfg, "ETHTOOL_OPTS", "", FALSE); - else if (wol == NM_SETTING_WIRED_WAKE_ON_LAN_DEFAULT) - svSetValue (ifcfg, "ETHTOOL_OPTS", NULL, FALSE); - else { - str = g_string_sized_new (30); - g_string_append (str, "wol "); - - if (NM_FLAGS_HAS (wol, NM_SETTING_WIRED_WAKE_ON_LAN_PHY)) - g_string_append (str, "p"); - if (NM_FLAGS_HAS (wol, NM_SETTING_WIRED_WAKE_ON_LAN_UNICAST)) - g_string_append (str, "u"); - if (NM_FLAGS_HAS (wol, NM_SETTING_WIRED_WAKE_ON_LAN_MULTICAST)) - g_string_append (str, "m"); - if (NM_FLAGS_HAS (wol, NM_SETTING_WIRED_WAKE_ON_LAN_BROADCAST)) - g_string_append (str, "b"); - if (NM_FLAGS_HAS (wol, NM_SETTING_WIRED_WAKE_ON_LAN_ARP)) - g_string_append (str, "a"); - if (NM_FLAGS_HAS (wol, NM_SETTING_WIRED_WAKE_ON_LAN_MAGIC)) - g_string_append (str, "g"); - - if (!NM_FLAGS_ANY (wol, NM_SETTING_WIRED_WAKE_ON_LAN_ALL)) - g_string_append (str, "d"); - - if (wol_password && NM_FLAGS_HAS (wol, NM_SETTING_WIRED_WAKE_ON_LAN_MAGIC)) - g_string_append_printf (str, "s sopass %s", wol_password); - - svSetValue (ifcfg, "ETHTOOL_OPTS", str->str, FALSE); - g_string_free (str, TRUE); - } - - svSetValue (ifcfg, "TYPE", TYPE_ETHERNET, FALSE); - - return TRUE; -} - -static char * -vlan_priority_maplist_to_stringlist (NMSettingVlan *s_vlan, NMVlanPriorityMap map) -{ - char **strlist; - char *value; - - if (map == NM_VLAN_INGRESS_MAP) - g_object_get (G_OBJECT (s_vlan), NM_SETTING_VLAN_INGRESS_PRIORITY_MAP, &strlist, NULL); - else if (map == NM_VLAN_EGRESS_MAP) - g_object_get (G_OBJECT (s_vlan), NM_SETTING_VLAN_EGRESS_PRIORITY_MAP, &strlist, NULL); - else - return NULL; - - if (strlist[0]) - value = g_strjoinv (",", strlist); - else - value = NULL; - g_strfreev (strlist); - - return value; -} - -static gboolean -write_wired_for_virtual (NMConnection *connection, shvarFile *ifcfg) -{ - NMSettingWired *s_wired; - gboolean has_wired = FALSE; - - s_wired = nm_connection_get_setting_wired (connection); - if (s_wired) { - const char *device_mac, *cloned_mac; - char *tmp; - guint32 mtu; - - has_wired = TRUE; - - device_mac = nm_setting_wired_get_mac_address (s_wired); - svSetValue (ifcfg, "HWADDR", device_mac, FALSE); - - cloned_mac = nm_setting_wired_get_cloned_mac_address (s_wired); - svSetValue (ifcfg, "MACADDR", cloned_mac, FALSE); - - svSetValue (ifcfg, "GENERATE_MAC_ADDRESS_MASK", - nm_setting_wired_get_generate_mac_address_mask (s_wired), - FALSE); - - mtu = nm_setting_wired_get_mtu (s_wired); - if (mtu) { - tmp = g_strdup_printf ("%u", mtu); - svSetValue (ifcfg, "MTU", tmp, FALSE); - g_free (tmp); - } else - svSetValue (ifcfg, "MTU", NULL, FALSE); - } - return has_wired; -} - -static gboolean -write_vlan_setting (NMConnection *connection, shvarFile *ifcfg, gboolean *wired, GError **error) -{ - NMSettingVlan *s_vlan; - NMSettingConnection *s_con; - char *tmp; - guint32 vlan_flags = 0; - gsize s_buf_len; - char s_buf[50], *s_buf_ptr; - - s_con = nm_connection_get_setting_connection (connection); - if (!s_con) { - g_set_error_literal (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, - "Missing connection setting"); - return FALSE; - } - - s_vlan = nm_connection_get_setting_vlan (connection); - if (!s_vlan) { - g_set_error_literal (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, - "Missing VLAN setting"); - return FALSE; - } - - svSetValue (ifcfg, "VLAN", "yes", FALSE); - svSetValue (ifcfg, "TYPE", TYPE_VLAN, FALSE); - svSetValue (ifcfg, "DEVICE", nm_setting_connection_get_interface_name (s_con), FALSE); - svSetValue (ifcfg, "PHYSDEV", nm_setting_vlan_get_parent (s_vlan), FALSE); - - tmp = g_strdup_printf ("%d", nm_setting_vlan_get_id (s_vlan)); - svSetValue (ifcfg, "VLAN_ID", tmp, FALSE); - g_free (tmp); - - vlan_flags = nm_setting_vlan_get_flags (s_vlan); - if (vlan_flags & NM_VLAN_FLAG_REORDER_HEADERS) - svSetValue (ifcfg, "REORDER_HDR", "yes", FALSE); - else - svSetValue (ifcfg, "REORDER_HDR", "no", FALSE); - - svSetValue (ifcfg, "GVRP", vlan_flags & NM_VLAN_FLAG_GVRP ? "yes" : "no", FALSE); - - nm_utils_strbuf_init (s_buf, &s_buf_ptr, &s_buf_len); - - if (NM_FLAGS_HAS (vlan_flags, NM_VLAN_FLAG_LOOSE_BINDING)) - nm_utils_strbuf_append_str (&s_buf_ptr, &s_buf_len, "LOOSE_BINDING"); - if (!NM_FLAGS_HAS (vlan_flags, NM_VLAN_FLAG_REORDER_HEADERS)) - nm_utils_strbuf_append (&s_buf_ptr, &s_buf_len, "%sNO_REORDER_HDR", s_buf[0] ? "," : ""); - - svSetValue (ifcfg, "VLAN_FLAGS", s_buf, FALSE); - - svSetValue (ifcfg, "MVRP", vlan_flags & NM_VLAN_FLAG_MVRP ? "yes" : "no", FALSE); - - tmp = vlan_priority_maplist_to_stringlist (s_vlan, NM_VLAN_INGRESS_MAP); - svSetValue (ifcfg, "VLAN_INGRESS_PRIORITY_MAP", tmp, FALSE); - g_free (tmp); - - tmp = vlan_priority_maplist_to_stringlist (s_vlan, NM_VLAN_EGRESS_MAP); - svSetValue (ifcfg, "VLAN_EGRESS_PRIORITY_MAP", tmp, FALSE); - g_free (tmp); - - svSetValue (ifcfg, "HWADDR", NULL, FALSE); - svSetValue (ifcfg, "MACADDR", NULL, FALSE); - svSetValue (ifcfg, "MTU", NULL, FALSE); - - *wired = write_wired_for_virtual (connection, ifcfg); - - return TRUE; -} - -static gboolean -write_bonding_setting (NMConnection *connection, shvarFile *ifcfg, gboolean *wired, GError **error) -{ - NMSettingBond *s_bond; - const char *iface; - guint32 i, num_opts; - - s_bond = nm_connection_get_setting_bond (connection); - if (!s_bond) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, - "Missing '%s' setting", NM_SETTING_BOND_SETTING_NAME); - return FALSE; - } - - iface = nm_connection_get_interface_name (connection); - if (!iface) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, - "Missing interface name"); - return FALSE; - } - - svSetValue (ifcfg, "DEVICE", iface, FALSE); - svSetValue (ifcfg, "BONDING_OPTS", NULL, FALSE); - - num_opts = nm_setting_bond_get_num_options (s_bond); - if (num_opts > 0) { - GString *str = g_string_sized_new (64); - - for (i = 0; i < nm_setting_bond_get_num_options (s_bond); i++) { - const char *key, *value; - - if (!nm_setting_bond_get_option (s_bond, i, &key, &value)) - continue; - - if (str->len) - g_string_append_c (str, ' '); - - g_string_append_printf (str, "%s=%s", key, value); - } - - if (str->len) - svSetValue (ifcfg, "BONDING_OPTS", str->str, FALSE); - - g_string_free (str, TRUE); - } - - svSetValue (ifcfg, "TYPE", TYPE_BOND, FALSE); - svSetValue (ifcfg, "BONDING_MASTER", "yes", FALSE); - - *wired = write_wired_for_virtual (connection, ifcfg); - - return TRUE; -} - -static gboolean -write_team_setting (NMConnection *connection, shvarFile *ifcfg, gboolean *wired, GError **error) -{ - NMSettingTeam *s_team; - const char *iface; - const char *config; - - s_team = nm_connection_get_setting_team (connection); - if (!s_team) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, - "Missing '%s' setting", NM_SETTING_TEAM_SETTING_NAME); - return FALSE; - } - - iface = nm_connection_get_interface_name (connection); - if (!iface) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, - "Missing interface name"); - return FALSE; - } - - svSetValue (ifcfg, "DEVICE", iface, FALSE); - config = nm_setting_team_get_config (s_team); - svSetValue (ifcfg, "TEAM_CONFIG", config, FALSE); - - *wired = write_wired_for_virtual (connection, ifcfg); - - return TRUE; -} - -static guint32 -get_setting_default_uint (NMSetting *setting, const char *prop) -{ - GParamSpec *pspec; - GValue val = G_VALUE_INIT; - guint32 ret = 0; - - pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (setting), prop); - g_assert (pspec); - g_value_init (&val, pspec->value_type); - g_param_value_set_default (pspec, &val); - g_assert (G_VALUE_HOLDS_UINT (&val)); - ret = g_value_get_uint (&val); - g_value_unset (&val); - return ret; -} - -static gboolean -get_setting_default_boolean (NMSetting *setting, const char *prop) -{ - GParamSpec *pspec; - GValue val = G_VALUE_INIT; - gboolean ret = 0; - - pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (setting), prop); - g_assert (pspec); - g_value_init (&val, pspec->value_type); - g_param_value_set_default (pspec, &val); - g_assert (G_VALUE_HOLDS_BOOLEAN (&val)); - ret = g_value_get_boolean (&val); - g_value_unset (&val); - return ret; -} - -static gboolean -write_bridge_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) -{ - NMSettingBridge *s_bridge; - const char *iface; - guint32 i; - gboolean b; - GString *opts; - const char *mac; - char *s; - - s_bridge = nm_connection_get_setting_bridge (connection); - if (!s_bridge) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, - "Missing '%s' setting", NM_SETTING_BRIDGE_SETTING_NAME); - return FALSE; - } - - iface = nm_connection_get_interface_name (connection); - if (!iface) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, - "Missing interface name"); - return FALSE; - } - - svSetValue (ifcfg, "DEVICE", iface, FALSE); - svSetValue (ifcfg, "BRIDGING_OPTS", NULL, FALSE); - svSetValue (ifcfg, "STP", "no", FALSE); - svSetValue (ifcfg, "DELAY", NULL, FALSE); - - mac = nm_setting_bridge_get_mac_address (s_bridge); - svSetValue (ifcfg, "MACADDR", mac, FALSE); - - /* Bridge options */ - opts = g_string_sized_new (32); - - if (nm_setting_bridge_get_stp (s_bridge)) { - svSetValue (ifcfg, "STP", "yes", FALSE); - - i = nm_setting_bridge_get_forward_delay (s_bridge); - if (i != get_setting_default_uint (NM_SETTING (s_bridge), NM_SETTING_BRIDGE_FORWARD_DELAY)) { - s = g_strdup_printf ("%u", i); - svSetValue (ifcfg, "DELAY", s, FALSE); - g_free (s); - } - - g_string_append_printf (opts, "priority=%u", nm_setting_bridge_get_priority (s_bridge)); - - i = nm_setting_bridge_get_hello_time (s_bridge); - if (i != get_setting_default_uint (NM_SETTING (s_bridge), NM_SETTING_BRIDGE_HELLO_TIME)) { - if (opts->len) - g_string_append_c (opts, ' '); - g_string_append_printf (opts, "hello_time=%u", i); - } - - i = nm_setting_bridge_get_max_age (s_bridge); - if (i != get_setting_default_uint (NM_SETTING (s_bridge), NM_SETTING_BRIDGE_MAX_AGE)) { - if (opts->len) - g_string_append_c (opts, ' '); - g_string_append_printf (opts, "max_age=%u", i); - } - } - - i = nm_setting_bridge_get_ageing_time (s_bridge); - if (i != get_setting_default_uint (NM_SETTING (s_bridge), NM_SETTING_BRIDGE_AGEING_TIME)) { - if (opts->len) - g_string_append_c (opts, ' '); - g_string_append_printf (opts, "ageing_time=%u", i); - } - - b = nm_setting_bridge_get_multicast_snooping (s_bridge); - if (b != get_setting_default_boolean (NM_SETTING (s_bridge), NM_SETTING_BRIDGE_MULTICAST_SNOOPING)) { - if (opts->len) - g_string_append_c (opts, ' '); - g_string_append_printf (opts, "multicast_snooping=%u", (guint32) b); - } - - if (opts->len) - svSetValue (ifcfg, "BRIDGING_OPTS", opts->str, FALSE); - g_string_free (opts, TRUE); - - svSetValue (ifcfg, "TYPE", TYPE_BRIDGE, FALSE); - - return TRUE; -} - -static gboolean -write_bridge_port_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) -{ - NMSettingBridgePort *s_port; - guint32 i; - GString *opts; - - s_port = nm_connection_get_setting_bridge_port (connection); - if (!s_port) - return TRUE; - - svSetValue (ifcfg, "BRIDGING_OPTS", NULL, FALSE); - - /* Bridge options */ - opts = g_string_sized_new (32); - - i = nm_setting_bridge_port_get_priority (s_port); - if (i != get_setting_default_uint (NM_SETTING (s_port), NM_SETTING_BRIDGE_PORT_PRIORITY)) - g_string_append_printf (opts, "priority=%u", i); - - i = nm_setting_bridge_port_get_path_cost (s_port); - if (i != get_setting_default_uint (NM_SETTING (s_port), NM_SETTING_BRIDGE_PORT_PATH_COST)) { - if (opts->len) - g_string_append_c (opts, ' '); - g_string_append_printf (opts, "path_cost=%u", i); - } - - if (nm_setting_bridge_port_get_hairpin_mode (s_port)) { - if (opts->len) - g_string_append_c (opts, ' '); - g_string_append_printf (opts, "hairpin_mode=1"); - } - - if (opts->len) - svSetValue (ifcfg, "BRIDGING_OPTS", opts->str, FALSE); - g_string_free (opts, TRUE); - - return TRUE; -} - -static gboolean -write_team_port_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) -{ - NMSettingTeamPort *s_port; - const char *config; - - s_port = nm_connection_get_setting_team_port (connection); - if (!s_port) - return TRUE; - - config = nm_setting_team_port_get_config (s_port); - svSetValue (ifcfg, "TEAM_PORT_CONFIG", config, FALSE); - - return TRUE; -} - -static void -write_dcb_flags (shvarFile *ifcfg, const char *tag, NMSettingDcbFlags flags) -{ - char *prop; - - prop = g_strdup_printf ("DCB_%s_ENABLE", tag); - svSetValue (ifcfg, prop, (flags & NM_SETTING_DCB_FLAG_ENABLE) ? "yes" : NULL, FALSE); - g_free (prop); - - prop = g_strdup_printf ("DCB_%s_ADVERTISE", tag); - svSetValue (ifcfg, prop, (flags & NM_SETTING_DCB_FLAG_ADVERTISE) ? "yes" : NULL, FALSE); - g_free (prop); - - prop = g_strdup_printf ("DCB_%s_WILLING", tag); - svSetValue (ifcfg, prop, (flags & NM_SETTING_DCB_FLAG_WILLING) ? "yes" : NULL, FALSE); - g_free (prop); -} - -static void -write_dcb_app (shvarFile *ifcfg, - const char *tag, - NMSettingDcbFlags flags, - gint priority) -{ - char *prop, *tmp = NULL; - - write_dcb_flags (ifcfg, tag, flags); - - if ((flags & NM_SETTING_DCB_FLAG_ENABLE) && (priority >= 0)) - tmp = g_strdup_printf ("%d", priority); - prop = g_strdup_printf ("DCB_%s_PRIORITY", tag); - svSetValue (ifcfg, prop, tmp, FALSE); - g_free (prop); - g_free (tmp); -} - -typedef gboolean (*DcbGetBoolFunc) (NMSettingDcb *, guint); - -static void -write_dcb_bool_array (shvarFile *ifcfg, - const char *key, - NMSettingDcb *s_dcb, - NMSettingDcbFlags flags, - DcbGetBoolFunc get_func) -{ - char str[9]; - guint i; - - if (!(flags & NM_SETTING_DCB_FLAG_ENABLE)) { - svSetValue (ifcfg, key, NULL, FALSE); - return; - } - - str[8] = 0; - for (i = 0; i < 8; i++) - str[i] = get_func (s_dcb, i) ? '1' : '0'; - svSetValue (ifcfg, key, str, FALSE); -} - -typedef guint (*DcbGetUintFunc) (NMSettingDcb *, guint); - -static void -write_dcb_uint_array (shvarFile *ifcfg, - const char *key, - NMSettingDcb *s_dcb, - NMSettingDcbFlags flags, - DcbGetUintFunc get_func) -{ - char str[9]; - guint i, num; - - if (!(flags & NM_SETTING_DCB_FLAG_ENABLE)) { - svSetValue (ifcfg, key, NULL, FALSE); - return; - } - - str[8] = 0; - for (i = 0; i < 8; i++) { - num = get_func (s_dcb, i); - if (num < 10) - str[i] = '0' + num; - else if (num == 15) - str[i] = 'f'; - else - g_assert_not_reached (); - } - svSetValue (ifcfg, key, str, FALSE); -} - -static void -write_dcb_percent_array (shvarFile *ifcfg, - const char *key, - NMSettingDcb *s_dcb, - NMSettingDcbFlags flags, - DcbGetUintFunc get_func) -{ - GString *str; - guint i; - - if (!(flags & NM_SETTING_DCB_FLAG_ENABLE)) { - svSetValue (ifcfg, key, NULL, FALSE); - return; - } - - str = g_string_sized_new (30); - for (i = 0; i < 8; i++) { - if (str->len) - g_string_append_c (str, ','); - g_string_append_printf (str, "%d", get_func (s_dcb, i)); - } - svSetValue (ifcfg, key, str->str, FALSE); - g_string_free (str, TRUE); -} - -static gboolean -write_dcb_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) -{ - NMSettingDcb *s_dcb; - NMSettingDcbFlags flags; - - s_dcb = nm_connection_get_setting_dcb (connection); - if (!s_dcb) { - static const char *clear_keys[] = { - "DCB", - KEY_DCB_APP_FCOE_ENABLE, - KEY_DCB_APP_FCOE_ADVERTISE, - KEY_DCB_APP_FCOE_WILLING, - KEY_DCB_APP_FCOE_MODE, - KEY_DCB_APP_ISCSI_ENABLE, - KEY_DCB_APP_ISCSI_ADVERTISE, - KEY_DCB_APP_ISCSI_WILLING, - KEY_DCB_APP_FIP_ENABLE, - KEY_DCB_APP_FIP_ADVERTISE, - KEY_DCB_APP_FIP_WILLING, - KEY_DCB_PFC_ENABLE, - KEY_DCB_PFC_ADVERTISE, - KEY_DCB_PFC_WILLING, - KEY_DCB_PFC_UP, - KEY_DCB_PG_ENABLE, - KEY_DCB_PG_ADVERTISE, - KEY_DCB_PG_WILLING, - KEY_DCB_PG_ID, - KEY_DCB_PG_PCT, - KEY_DCB_PG_UPPCT, - KEY_DCB_PG_STRICT, - KEY_DCB_PG_UP2TC, - NULL }; - const char **iter; - - for (iter = clear_keys; *iter; iter++) - svSetValue (ifcfg, *iter, NULL, FALSE); - return TRUE; - } - - svSetValue (ifcfg, "DCB", "yes", FALSE); - - write_dcb_app (ifcfg, "APP_FCOE", - nm_setting_dcb_get_app_fcoe_flags (s_dcb), - nm_setting_dcb_get_app_fcoe_priority (s_dcb)); - if (nm_setting_dcb_get_app_fcoe_flags (s_dcb) & NM_SETTING_DCB_FLAG_ENABLE) - svSetValue (ifcfg, KEY_DCB_APP_FCOE_MODE, nm_setting_dcb_get_app_fcoe_mode (s_dcb), FALSE); - else - svSetValue (ifcfg, KEY_DCB_APP_FCOE_MODE, NULL, FALSE); - - write_dcb_app (ifcfg, "APP_ISCSI", - nm_setting_dcb_get_app_iscsi_flags (s_dcb), - nm_setting_dcb_get_app_iscsi_priority (s_dcb)); - write_dcb_app (ifcfg, "APP_FIP", - nm_setting_dcb_get_app_fip_flags (s_dcb), - nm_setting_dcb_get_app_fip_priority (s_dcb)); - - write_dcb_flags (ifcfg, "PFC", nm_setting_dcb_get_priority_flow_control_flags (s_dcb)); - write_dcb_bool_array (ifcfg, KEY_DCB_PFC_UP, s_dcb, - nm_setting_dcb_get_priority_flow_control_flags (s_dcb), - nm_setting_dcb_get_priority_flow_control); - - flags = nm_setting_dcb_get_priority_group_flags (s_dcb); - write_dcb_flags (ifcfg, "PG", flags); - write_dcb_uint_array (ifcfg, KEY_DCB_PG_ID, s_dcb, flags, nm_setting_dcb_get_priority_group_id); - write_dcb_percent_array (ifcfg, KEY_DCB_PG_PCT, s_dcb, flags, nm_setting_dcb_get_priority_group_bandwidth); - write_dcb_percent_array (ifcfg, KEY_DCB_PG_UPPCT, s_dcb, flags, nm_setting_dcb_get_priority_bandwidth); - write_dcb_bool_array (ifcfg, KEY_DCB_PG_STRICT, s_dcb, flags, nm_setting_dcb_get_priority_strict_bandwidth); - write_dcb_uint_array (ifcfg, KEY_DCB_PG_UP2TC, s_dcb, flags, nm_setting_dcb_get_priority_traffic_class); - - return TRUE; -} - -static void -write_connection_setting (NMSettingConnection *s_con, shvarFile *ifcfg) -{ - guint32 n, i; - GString *str; - const char *master, *type; - char *tmp; - gint i_int; - const char *v_master = NULL; - const char *v_slave = NULL; - const char *v_bridge = NULL; - const char *v_team_master = NULL; - - svSetValue (ifcfg, "NAME", nm_setting_connection_get_id (s_con), FALSE); - svSetValue (ifcfg, "UUID", nm_setting_connection_get_uuid (s_con), FALSE); - svSetValue (ifcfg, "STABLE_ID", nm_setting_connection_get_stable_id (s_con), FALSE); - svSetValue (ifcfg, "DEVICE", nm_setting_connection_get_interface_name (s_con), FALSE); - svSetValue (ifcfg, "ONBOOT", - nm_setting_connection_get_autoconnect (s_con) ? "yes" : "no", - FALSE); - - i_int = nm_setting_connection_get_autoconnect_priority (s_con); - tmp = i_int != NM_SETTING_CONNECTION_AUTOCONNECT_PRIORITY_DEFAULT - ? g_strdup_printf ("%d", i_int) : NULL; - svSetValue (ifcfg, "AUTOCONNECT_PRIORITY", tmp, FALSE); - g_free (tmp); - - /* Only save the value for master connections */ - svSetValue (ifcfg, "AUTOCONNECT_SLAVES", NULL, FALSE); - type = nm_setting_connection_get_connection_type (s_con); - if ( !g_strcmp0 (type, NM_SETTING_BOND_SETTING_NAME) - || !g_strcmp0 (type, NM_SETTING_TEAM_SETTING_NAME) - || !g_strcmp0 (type, NM_SETTING_BRIDGE_SETTING_NAME)) { - NMSettingConnectionAutoconnectSlaves autoconnect_slaves; - autoconnect_slaves = nm_setting_connection_get_autoconnect_slaves (s_con); - svSetValue (ifcfg, "AUTOCONNECT_SLAVES", - autoconnect_slaves == NM_SETTING_CONNECTION_AUTOCONNECT_SLAVES_YES ? "yes" : - autoconnect_slaves == NM_SETTING_CONNECTION_AUTOCONNECT_SLAVES_NO ? "no" : NULL, - FALSE); - } - - switch (nm_setting_connection_get_lldp (s_con)) { - case NM_SETTING_CONNECTION_LLDP_ENABLE_RX: - tmp = "rx"; - break; - case NM_SETTING_CONNECTION_LLDP_DISABLE: - tmp = "no"; - break; - default: - tmp = NULL; - } - svSetValue (ifcfg, "LLDP", tmp, FALSE); - - /* Permissions */ - svSetValue (ifcfg, "USERS", NULL, FALSE); - n = nm_setting_connection_get_num_permissions (s_con); - if (n > 0) { - str = g_string_sized_new (n * 20); - - for (i = 0; i < n; i++) { - const char *puser = NULL; - - /* Items separated by space for consistency with eg - * IPV6ADDR_SECONDARIES and DOMAIN. - */ - if (str->len) - g_string_append_c (str, ' '); - - if (nm_setting_connection_get_permission (s_con, i, NULL, &puser, NULL)) - g_string_append (str, puser); - } - svSetValue (ifcfg, "USERS", str->str, FALSE); - g_string_free (str, TRUE); - } - - svSetValue (ifcfg, "ZONE", nm_setting_connection_get_zone(s_con), FALSE); - - master = nm_setting_connection_get_master (s_con); - if (master) { - if (nm_setting_connection_is_slave_type (s_con, NM_SETTING_BOND_SETTING_NAME)) { - v_master = master; - v_slave = "yes"; - } else if (nm_setting_connection_is_slave_type (s_con, NM_SETTING_BRIDGE_SETTING_NAME)) - v_bridge = master; - else if (nm_setting_connection_is_slave_type (s_con, NM_SETTING_TEAM_SETTING_NAME)) { - v_team_master = master; - svSetValue (ifcfg, "TYPE", NULL, FALSE); - } - } - - svSetValue (ifcfg, "MASTER", v_master, FALSE); - svSetValue (ifcfg, "SLAVE", v_slave, FALSE); - svSetValue (ifcfg, "BRIDGE", v_bridge, FALSE); - svSetValue (ifcfg, "TEAM_MASTER", v_team_master, FALSE); - - if (nm_streq0 (type, NM_SETTING_TEAM_SETTING_NAME)) - svSetValue (ifcfg, "DEVICETYPE", TYPE_TEAM, FALSE); - else if (master && nm_setting_connection_is_slave_type (s_con, NM_SETTING_TEAM_SETTING_NAME)) - svSetValue (ifcfg, "DEVICETYPE", TYPE_TEAM_PORT, FALSE); - else - svSetValue (ifcfg, "DEVICETYPE", NULL, FALSE); - - /* secondary connection UUIDs */ - svSetValue (ifcfg, "SECONDARY_UUIDS", NULL, FALSE); - n = nm_setting_connection_get_num_secondaries (s_con); - if (n > 0) { - str = g_string_sized_new (n * 37); - - for (i = 0; i < n; i++) { - const char *uuid; - - /* Items separated by space for consistency with eg - * IPV6ADDR_SECONDARIES and DOMAIN. - */ - if (str->len) - g_string_append_c (str, ' '); - - if ((uuid = nm_setting_connection_get_secondary (s_con, i)) != NULL) - g_string_append (str, uuid); - } - svSetValue (ifcfg, "SECONDARY_UUIDS", str->str, FALSE); - g_string_free (str, TRUE); - } - - svSetValue (ifcfg, "GATEWAY_PING_TIMEOUT", NULL, FALSE); - if (nm_setting_connection_get_gateway_ping_timeout (s_con)) { - tmp = g_strdup_printf ("%" G_GUINT32_FORMAT, nm_setting_connection_get_gateway_ping_timeout (s_con)); - svSetValue (ifcfg, "GATEWAY_PING_TIMEOUT", tmp, FALSE); - g_free (tmp); - } - - switch (nm_setting_connection_get_metered (s_con)) { - case NM_METERED_YES: - svSetValue (ifcfg, "CONNECTION_METERED", "yes", FALSE); - break; - case NM_METERED_NO: - svSetValue (ifcfg, "CONNECTION_METERED", "no", FALSE); - break; - default: - svSetValue (ifcfg, "CONNECTION_METERED", NULL, FALSE); - } -} - -static gboolean -write_route_file_legacy (const char *filename, NMSettingIPConfig *s_ip4, GError **error) -{ - const char *dest, *next_hop; - char **route_items; - char *route_contents; - NMIPRoute *route; - guint32 prefix; - gint64 metric; - guint32 i, num; - gboolean success = FALSE; - - g_return_val_if_fail (filename != NULL, FALSE); - g_return_val_if_fail (s_ip4 != NULL, FALSE); - g_return_val_if_fail (error != NULL, FALSE); - g_return_val_if_fail (*error == NULL, FALSE); - - num = nm_setting_ip_config_get_num_routes (s_ip4); - if (num == 0) { - unlink (filename); - return TRUE; - } - - route_items = g_malloc0 (sizeof (char*) * (num + 1)); - for (i = 0; i < num; i++) { - route = nm_setting_ip_config_get_route (s_ip4, i); - - dest = nm_ip_route_get_dest (route); - prefix = nm_ip_route_get_prefix (route); - next_hop = nm_ip_route_get_next_hop (route); - metric = nm_ip_route_get_metric (route); - - if (metric == -1) - route_items[i] = g_strdup_printf ("%s/%u via %s\n", dest, prefix, next_hop); - else - route_items[i] = g_strdup_printf ("%s/%u via %s metric %u\n", dest, prefix, next_hop, (guint32) metric); - } - route_items[num] = NULL; - route_contents = g_strjoinv (NULL, route_items); - g_strfreev (route_items); - - if (!g_file_set_contents (filename, route_contents, -1, NULL)) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, - "Writing route file '%s' failed", filename); - goto error; - } - - success = TRUE; - -error: - g_free (route_contents); - - return success; -} - -static gboolean -write_ip4_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) -{ - NMSettingIPConfig *s_ip4; - const char *value; - char *addr_key, *prefix_key, *netmask_key, *gw_key, *metric_key, *tmp; - char *route_path = NULL; - gint32 j; - guint32 i, n, num; - gint64 route_metric; - gint priority; - int timeout; - GString *searches; - const char *method = NULL; - - s_ip4 = nm_connection_get_setting_ip4_config (connection); - if (!s_ip4) { - /* slave-type: clear IPv4 settings. - * - * Some IPv4 setting related options are not cleared, - * for no strong reason. */ - svSetValue (ifcfg, "BOOTPROTO", NULL, FALSE); - - svSetValue (ifcfg, "IPADDR", NULL, FALSE); - svSetValue (ifcfg, "PREFIX", NULL, FALSE); - svSetValue (ifcfg, "NETMASK", NULL, FALSE); - svSetValue (ifcfg, "GATEWAY", NULL, FALSE); - - svSetValue (ifcfg, "IPADDR0", NULL, FALSE); - svSetValue (ifcfg, "PREFIX0", NULL, FALSE); - svSetValue (ifcfg, "NETMASK0", NULL, FALSE); - svSetValue (ifcfg, "GATEWAY0", NULL, FALSE); - return TRUE; - } - - method = nm_setting_ip_config_get_method (s_ip4); - - /* Missing IP4 setting is assumed to be DHCP */ - if (!method) - method = NM_SETTING_IP4_CONFIG_METHOD_AUTO; - - if (!strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_DISABLED)) { - int result; - - /* IPv4 disabled, clear IPv4 related parameters */ - svSetValue (ifcfg, "BOOTPROTO", NULL, FALSE); - for (j = -1; j < 256; j++) { - if (j == -1) { - addr_key = g_strdup ("IPADDR"); - prefix_key = g_strdup ("PREFIX"); - netmask_key = g_strdup ("NETMASK"); - gw_key = g_strdup ("GATEWAY"); - } else { - addr_key = g_strdup_printf ("IPADDR%d", j); - prefix_key = g_strdup_printf ("PREFIX%d", j); - netmask_key = g_strdup_printf ("NETMASK%d", j); - gw_key = g_strdup_printf ("GATEWAY%d", j); - } - - svSetValue (ifcfg, addr_key, NULL, FALSE); - svSetValue (ifcfg, prefix_key, NULL, FALSE); - svSetValue (ifcfg, netmask_key, NULL, FALSE); - svSetValue (ifcfg, gw_key, NULL, FALSE); - - g_free (addr_key); - g_free (prefix_key); - g_free (netmask_key); - g_free (gw_key); - } - - route_path = utils_get_route_path (ifcfg->fileName); - result = unlink (route_path); - g_free (route_path); - return TRUE; - } - - if (!strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_AUTO)) - svSetValue (ifcfg, "BOOTPROTO", "dhcp", FALSE); - else if (!strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_MANUAL)) - svSetValue (ifcfg, "BOOTPROTO", "none", FALSE); - else if (!strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL)) - svSetValue (ifcfg, "BOOTPROTO", "autoip", FALSE); - else if (!strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_SHARED)) - svSetValue (ifcfg, "BOOTPROTO", "shared", FALSE); - - /* Clear out un-numbered IP address fields */ - svSetValue (ifcfg, "IPADDR", NULL, FALSE); - svSetValue (ifcfg, "PREFIX", NULL, FALSE); - svSetValue (ifcfg, "NETMASK", NULL, FALSE); - svSetValue (ifcfg, "GATEWAY", NULL, FALSE); - /* Clear out zero-indexed IP address fields */ - svSetValue (ifcfg, "IPADDR0", NULL, FALSE); - svSetValue (ifcfg, "PREFIX0", NULL, FALSE); - svSetValue (ifcfg, "NETMASK0", NULL, FALSE); - svSetValue (ifcfg, "GATEWAY0", NULL, FALSE); - - /* Write out IPADDR, PREFIX, GATEWAY for current IP addresses - * without labels. Unset obsolete NETMASK. - */ - num = nm_setting_ip_config_get_num_addresses (s_ip4); - for (i = n = 0; i < num; i++) { - NMIPAddress *addr; - - addr = nm_setting_ip_config_get_address (s_ip4, i); - - if (i > 0) { - GVariant *label; - - label = nm_ip_address_get_attribute (addr, "label"); - if (label) - continue; - } - - if (n == 0) { - /* Instead of index 0 use un-numbered variables. - * It's needed for compatibility with ifup that only recognizes 'GATEAWAY' - * See https://bugzilla.redhat.com/show_bug.cgi?id=771673 - * and https://bugzilla.redhat.com/show_bug.cgi?id=1105770 - */ - addr_key = g_strdup ("IPADDR"); - prefix_key = g_strdup ("PREFIX"); - netmask_key = g_strdup ("NETMASK"); - gw_key = g_strdup ("GATEWAY"); - } else { - addr_key = g_strdup_printf ("IPADDR%d", n); - prefix_key = g_strdup_printf ("PREFIX%d", n); - netmask_key = g_strdup_printf ("NETMASK%d", n); - gw_key = g_strdup_printf ("GATEWAY%d", n); - } - - svSetValue (ifcfg, addr_key, nm_ip_address_get_address (addr), FALSE); - - tmp = g_strdup_printf ("%u", nm_ip_address_get_prefix (addr)); - svSetValue (ifcfg, prefix_key, tmp, FALSE); - g_free (tmp); - - svSetValue (ifcfg, netmask_key, NULL, FALSE); - svSetValue (ifcfg, gw_key, NULL, FALSE); - - g_free (addr_key); - g_free (prefix_key); - g_free (netmask_key); - g_free (gw_key); - n++; - } - - /* Clear remaining IPADDR, etc */ - for (; n < 256; n++) { - addr_key = g_strdup_printf ("IPADDR%d", n); - prefix_key = g_strdup_printf ("PREFIX%d", n); - netmask_key = g_strdup_printf ("NETMASK%d", n); - gw_key = g_strdup_printf ("GATEWAY%d", n); - - svSetValue (ifcfg, addr_key, NULL, FALSE); - svSetValue (ifcfg, prefix_key, NULL, FALSE); - svSetValue (ifcfg, netmask_key, NULL, FALSE); - svSetValue (ifcfg, gw_key, NULL, FALSE); - - g_free (addr_key); - g_free (prefix_key); - g_free (netmask_key); - g_free (gw_key); - } - - svSetValue (ifcfg, "GATEWAY", nm_setting_ip_config_get_gateway (s_ip4), FALSE); - - num = nm_setting_ip_config_get_num_dns (s_ip4); - for (i = 0; i < 254; i++) { - const char *dns; - - addr_key = g_strdup_printf ("DNS%d", i + 1); - - if (i >= num) - svSetValue (ifcfg, addr_key, NULL, FALSE); - else { - dns = nm_setting_ip_config_get_dns (s_ip4, i); - svSetValue (ifcfg, addr_key, dns, FALSE); - } - g_free (addr_key); - } - - num = nm_setting_ip_config_get_num_dns_searches (s_ip4); - if (num > 0) { - searches = g_string_new (NULL); - for (i = 0; i < num; i++) { - if (i > 0) - g_string_append_c (searches, ' '); - g_string_append (searches, nm_setting_ip_config_get_dns_search (s_ip4, i)); - } - svSetValue (ifcfg, "DOMAIN", searches->str, FALSE); - g_string_free (searches, TRUE); - } else - svSetValue (ifcfg, "DOMAIN", NULL, FALSE); - - /* DEFROUTE; remember that it has the opposite meaning from never-default */ - svSetValue (ifcfg, "DEFROUTE", - nm_setting_ip_config_get_never_default (s_ip4) ? "no" : "yes", - FALSE); - - svSetValue (ifcfg, "PEERDNS", NULL, FALSE); - svSetValue (ifcfg, "PEERROUTES", NULL, FALSE); - svSetValue (ifcfg, "DHCP_CLIENT_ID", NULL, FALSE); - if (!strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_AUTO)) { - svSetValue (ifcfg, "PEERDNS", - nm_setting_ip_config_get_ignore_auto_dns (s_ip4) ? "no" : "yes", - FALSE); - - svSetValue (ifcfg, "PEERROUTES", - nm_setting_ip_config_get_ignore_auto_routes (s_ip4) ? "no" : "yes", - FALSE); - - value = nm_setting_ip_config_get_dhcp_hostname (s_ip4); - if (value) - svSetValue (ifcfg, "DHCP_HOSTNAME", value, FALSE); - - value = nm_setting_ip4_config_get_dhcp_fqdn (NM_SETTING_IP4_CONFIG (s_ip4)); - if (value) - svSetValue (ifcfg, "DHCP_FQDN", value, FALSE); - - /* Missing DHCP_SEND_HOSTNAME means TRUE, and we prefer not write it explicitly - * in that case, because it is NM-specific variable - */ - svSetValue (ifcfg, "DHCP_SEND_HOSTNAME", - nm_setting_ip_config_get_dhcp_send_hostname (s_ip4) ? NULL : "no", - FALSE); - - value = nm_setting_ip4_config_get_dhcp_client_id (NM_SETTING_IP4_CONFIG (s_ip4)); - if (value) - svSetValue (ifcfg, "DHCP_CLIENT_ID", value, FALSE); - - timeout = nm_setting_ip_config_get_dhcp_timeout (s_ip4); - tmp = timeout ? g_strdup_printf ("%d", timeout) : NULL; - svSetValue (ifcfg, "IPV4_DHCP_TIMEOUT", tmp, FALSE); - g_free (tmp); - } - - svSetValue (ifcfg, "IPV4_FAILURE_FATAL", - nm_setting_ip_config_get_may_fail (s_ip4) ? "no" : "yes", - FALSE); - - route_metric = nm_setting_ip_config_get_route_metric (s_ip4); - tmp = route_metric != -1 ? g_strdup_printf ("%"G_GINT64_FORMAT, route_metric) : NULL; - svSetValue (ifcfg, "IPV4_ROUTE_METRIC", tmp, FALSE); - g_free (tmp); - - /* Static routes - route- file */ - route_path = utils_get_route_path (ifcfg->fileName); - if (!route_path) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, - "Could not get route file path for '%s'", ifcfg->fileName); - return FALSE; - } - - if (utils_has_route_file_new_syntax (route_path)) { - shvarFile *routefile; - - routefile = utils_get_route_ifcfg (ifcfg->fileName, TRUE); - if (!routefile) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, - "Could not create route file '%s'", route_path); - g_free (route_path); - return FALSE; - } - g_free (route_path); - - num = nm_setting_ip_config_get_num_routes (s_ip4); - for (i = 0; i < 256; i++) { - char buf[INET_ADDRSTRLEN]; - NMIPRoute *route; - guint32 netmask; - gint64 metric; - - addr_key = g_strdup_printf ("ADDRESS%d", i); - netmask_key = g_strdup_printf ("NETMASK%d", i); - gw_key = g_strdup_printf ("GATEWAY%d", i); - metric_key = g_strdup_printf ("METRIC%d", i); - - if (i >= num) { - svSetValue (routefile, addr_key, NULL, FALSE); - svSetValue (routefile, netmask_key, NULL, FALSE); - svSetValue (routefile, gw_key, NULL, FALSE); - svSetValue (routefile, metric_key, NULL, FALSE); - } else { - route = nm_setting_ip_config_get_route (s_ip4, i); - - svSetValue (routefile, addr_key, nm_ip_route_get_dest (route), FALSE); - - memset (buf, 0, sizeof (buf)); - netmask = nm_utils_ip4_prefix_to_netmask (nm_ip_route_get_prefix (route)); - inet_ntop (AF_INET, (const void *) &netmask, &buf[0], sizeof (buf)); - svSetValue (routefile, netmask_key, &buf[0], FALSE); - - svSetValue (routefile, gw_key, nm_ip_route_get_next_hop (route), FALSE); - - memset (buf, 0, sizeof (buf)); - metric = nm_ip_route_get_metric (route); - if (metric == -1) - svSetValue (routefile, metric_key, NULL, FALSE); - else { - tmp = g_strdup_printf ("%u", (guint32) metric); - svSetValue (routefile, metric_key, tmp, FALSE); - g_free (tmp); - } - } - - g_free (addr_key); - g_free (netmask_key); - g_free (gw_key); - g_free (metric_key); - } - if (!svWriteFile (routefile, 0644, error)) { - svCloseFile (routefile); - return FALSE; - } - svCloseFile (routefile); - } else { - write_route_file_legacy (route_path, s_ip4, error); - g_free (route_path); - if (error && *error) - return FALSE; - } - - timeout = nm_setting_ip_config_get_dad_timeout (s_ip4); - if (timeout < 0) - svSetValue (ifcfg, "ARPING_WAIT", NULL, FALSE); - else if (timeout == 0) - svSetValue (ifcfg, "ARPING_WAIT", "0", FALSE); - else { - /* Round the value up to next integer */ - svSetValueInt64 (ifcfg, "ARPING_WAIT", (timeout - 1) / 1000 + 1); - } - - priority = nm_setting_ip_config_get_dns_priority (s_ip4); - if (priority) - svSetValueInt64 (ifcfg, "IPV4_DNS_PRIORITY", priority); - else - svSetValue (ifcfg, "IPV4_DNS_PRIORITY", NULL, FALSE); - - return TRUE; -} - -static void -write_ip4_aliases (NMConnection *connection, char *base_ifcfg_path) -{ - NMSettingIPConfig *s_ip4; - gs_free char *base_ifcfg_dir = NULL, *base_ifcfg_name = NULL; - const char*base_name; - int i, num, base_ifcfg_name_len, base_name_len; - GDir *dir; - - base_ifcfg_dir = g_path_get_dirname (base_ifcfg_path); - base_ifcfg_name = g_path_get_basename (base_ifcfg_path); - base_ifcfg_name_len = strlen (base_ifcfg_name); - if (!g_str_has_prefix (base_ifcfg_name, IFCFG_TAG)) - g_return_if_reached (); - base_name = base_ifcfg_name + strlen (IFCFG_TAG); - base_name_len = strlen (base_name); - - /* Remove all existing aliases for this file first */ - dir = g_dir_open (base_ifcfg_dir, 0, NULL); - if (dir) { - const char *item; - - while ((item = g_dir_read_name (dir))) { - char *full_path; - - if ( strncmp (item, base_ifcfg_name, base_ifcfg_name_len) != 0 - || item[base_ifcfg_name_len] != ':') - continue; - - full_path = g_build_filename (base_ifcfg_dir, item, NULL); - unlink (full_path); - g_free (full_path); - } - - g_dir_close (dir); - } - - s_ip4 = nm_connection_get_setting_ip4_config (connection); - if (!s_ip4) { - /* slave-type: no alias files */ - return; - } - - num = nm_setting_ip_config_get_num_addresses (s_ip4); - for (i = 0; i < num; i++) { - GVariant *label_var; - const char *label, *p; - char *path, *tmp; - NMIPAddress *addr; - shvarFile *ifcfg; - - addr = nm_setting_ip_config_get_address (s_ip4, i); - - label_var = nm_ip_address_get_attribute (addr, "label"); - if (!label_var) - continue; - label = g_variant_get_string (label_var, NULL); - if ( strncmp (label, base_name, base_name_len) != 0 - || label[base_name_len] != ':') - continue; - - for (p = label; *p; p++) { - if (!g_ascii_isalnum (*p) && *p != '_' && *p != ':') - break; - } - if (*p) - continue; - - path = g_strdup_printf ("%s%s", base_ifcfg_path, label + base_name_len); - ifcfg = svCreateFile (path); - g_free (path); - - svSetValue (ifcfg, "DEVICE", label, FALSE); - - addr = nm_setting_ip_config_get_address (s_ip4, i); - svSetValue (ifcfg, "IPADDR", nm_ip_address_get_address (addr), FALSE); - - tmp = g_strdup_printf ("%u", nm_ip_address_get_prefix (addr)); - svSetValue (ifcfg, "PREFIX", tmp, FALSE); - g_free (tmp); - - svWriteFile (ifcfg, 0644, NULL); - svCloseFile (ifcfg); - } -} - -static gboolean -write_route6_file (const char *filename, NMSettingIPConfig *s_ip6, GError **error) -{ - char **route_items; - char *route_contents; - NMIPRoute *route; - guint32 i, num; - gboolean success = FALSE; - - g_return_val_if_fail (filename != NULL, FALSE); - g_return_val_if_fail (s_ip6 != NULL, FALSE); - g_return_val_if_fail (error != NULL, FALSE); - g_return_val_if_fail (*error == NULL, FALSE); - - num = nm_setting_ip_config_get_num_routes (s_ip6); - if (num == 0) { - unlink (filename); - return TRUE; - } - - route_items = g_malloc0 (sizeof (char*) * (num + 1)); - for (i = 0; i < num; i++) { - route = nm_setting_ip_config_get_route (s_ip6, i); - - if (nm_ip_route_get_metric (route) == -1) { - route_items[i] = g_strdup_printf ("%s/%u via %s\n", - nm_ip_route_get_dest (route), - nm_ip_route_get_prefix (route), - nm_ip_route_get_next_hop (route)); - } else { - route_items[i] = g_strdup_printf ("%s/%u via %s metric %u\n", - nm_ip_route_get_dest (route), - nm_ip_route_get_prefix (route), - nm_ip_route_get_next_hop (route), - (guint32) nm_ip_route_get_metric (route)); - } - } - route_items[num] = NULL; - route_contents = g_strjoinv (NULL, route_items); - g_strfreev (route_items); - - if (!g_file_set_contents (filename, route_contents, -1, NULL)) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, - "Writing route6 file '%s' failed", filename); - goto error; - } - - success = TRUE; - -error: - g_free (route_contents); - return success; -} - -static gboolean -write_ip6_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) -{ - NMSettingIPConfig *s_ip6; - NMSettingIPConfig *s_ip4; - const char *value; - char *addr_key; - char *tmp; - guint32 i, num, num4; - gint priority; - GString *searches; - NMIPAddress *addr; - const char *dns; - gint64 route_metric; - GString *ip_str1, *ip_str2, *ip_ptr; - char *route6_path; - NMSettingIP6ConfigAddrGenMode addr_gen_mode; - - s_ip6 = nm_connection_get_setting_ip6_config (connection); - if (!s_ip6) { - /* slave-type: clear IPv6 settings - * - * Some IPv6 setting related options are not cleared, - * for no strong reason. */ - svSetValue (ifcfg, "IPV6INIT", NULL, FALSE); - svSetValue (ifcfg, "IPV6_AUTOCONF", NULL, FALSE); - svSetValue (ifcfg, "DHCPV6C", NULL, FALSE); - svSetValue (ifcfg, "IPV6_DEFROUTE", NULL, FALSE); - svSetValue (ifcfg, "IPV6_PEERDNS", NULL, FALSE); - svSetValue (ifcfg, "IPV6_PEERROUTES", NULL, FALSE); - svSetValue (ifcfg, "IPV6_FAILURE_FATAL", NULL, FALSE); - svSetValue (ifcfg, "IPV6_ROUTE_METRIC", NULL, FALSE); - svSetValue (ifcfg, "IPV6_ADDR_GEN_MODE", NULL, FALSE); - return TRUE; - } - - value = nm_setting_ip_config_get_method (s_ip6); - g_assert (value); - if (!strcmp (value, NM_SETTING_IP6_CONFIG_METHOD_IGNORE)) { - svSetValue (ifcfg, "IPV6INIT", "no", FALSE); - svSetValue (ifcfg, "DHCPV6C", NULL, FALSE); - return TRUE; - } else if (!strcmp (value, NM_SETTING_IP6_CONFIG_METHOD_AUTO)) { - svSetValue (ifcfg, "IPV6INIT", "yes", FALSE); - svSetValue (ifcfg, "IPV6_AUTOCONF", "yes", FALSE); - svSetValue (ifcfg, "DHCPV6C", NULL, FALSE); - } else if (!strcmp (value, NM_SETTING_IP6_CONFIG_METHOD_DHCP)) { - const char *hostname; - svSetValue (ifcfg, "IPV6INIT", "yes", FALSE); - svSetValue (ifcfg, "IPV6_AUTOCONF", "no", FALSE); - svSetValue (ifcfg, "DHCPV6C", "yes", FALSE); - hostname = nm_setting_ip_config_get_dhcp_hostname (s_ip6); - if (hostname) - svSetValue (ifcfg, "DHCP_HOSTNAME", hostname, FALSE); - } else if (!strcmp (value, NM_SETTING_IP6_CONFIG_METHOD_MANUAL)) { - svSetValue (ifcfg, "IPV6INIT", "yes", FALSE); - svSetValue (ifcfg, "IPV6_AUTOCONF", "no", FALSE); - svSetValue (ifcfg, "DHCPV6C", NULL, FALSE); - } else if (!strcmp (value, NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL)) { - svSetValue (ifcfg, "IPV6INIT", "yes", FALSE); - svSetValue (ifcfg, "IPV6_AUTOCONF", "no", FALSE); - svSetValue (ifcfg, "DHCPV6C", NULL, FALSE); - } else if (!strcmp (value, NM_SETTING_IP6_CONFIG_METHOD_SHARED)) { - svSetValue (ifcfg, "IPV6INIT", "yes", FALSE); - svSetValue (ifcfg, "DHCPV6C", NULL, FALSE); - /* TODO */ - } - - /* Write out IP addresses */ - num = nm_setting_ip_config_get_num_addresses (s_ip6); - ip_str1 = g_string_new (NULL); - ip_str2 = g_string_new (NULL); - for (i = 0; i < num; i++) { - if (i == 0) - ip_ptr = ip_str1; - else - ip_ptr = ip_str2; - - addr = nm_setting_ip_config_get_address (s_ip6, i); - - if (i > 1) - g_string_append_c (ip_ptr, ' '); /* separate addresses in IPV6ADDR_SECONDARIES */ - g_string_append_printf (ip_ptr, "%s/%u", - nm_ip_address_get_address (addr), - nm_ip_address_get_prefix (addr)); - } - svSetValue (ifcfg, "IPV6ADDR", ip_str1->str, FALSE); - svSetValue (ifcfg, "IPV6ADDR_SECONDARIES", ip_str2->str, FALSE); - svSetValue (ifcfg, "IPV6_DEFAULTGW", nm_setting_ip_config_get_gateway (s_ip6), FALSE); - g_string_free (ip_str1, TRUE); - g_string_free (ip_str2, TRUE); - - /* Write out DNS - 'DNS' key is used both for IPv4 and IPv6 */ - s_ip4 = nm_connection_get_setting_ip4_config (connection); - num4 = s_ip4 ? nm_setting_ip_config_get_num_dns (s_ip4) : 0; /* from where to start with IPv6 entries */ - num = nm_setting_ip_config_get_num_dns (s_ip6); - for (i = 0; i < 254; i++) { - addr_key = g_strdup_printf ("DNS%d", i + num4 + 1); - - if (i >= num) - svSetValue (ifcfg, addr_key, NULL, FALSE); - else { - dns = nm_setting_ip_config_get_dns (s_ip6, i); - svSetValue (ifcfg, addr_key, dns, FALSE); - } - g_free (addr_key); - } - - /* Write out DNS domains - 'DOMAIN' key is shared for both IPv4 and IPv6 domains */ - num = nm_setting_ip_config_get_num_dns_searches (s_ip6); - if (num > 0) { - char *ip4_domains; - ip4_domains = svGetValue (ifcfg, "DOMAIN", FALSE); - searches = g_string_new (ip4_domains); - for (i = 0; i < num; i++) { - if (searches->len > 0) - g_string_append_c (searches, ' '); - g_string_append (searches, nm_setting_ip_config_get_dns_search (s_ip6, i)); - } - svSetValue (ifcfg, "DOMAIN", searches->str, FALSE); - g_string_free (searches, TRUE); - g_free (ip4_domains); - } - - /* handle IPV6_DEFROUTE */ - /* IPV6_DEFROUTE has the opposite meaning from 'never-default' */ - if (nm_setting_ip_config_get_never_default(s_ip6)) - svSetValue (ifcfg, "IPV6_DEFROUTE", "no", FALSE); - else - svSetValue (ifcfg, "IPV6_DEFROUTE", "yes", FALSE); - - svSetValue (ifcfg, "IPV6_PEERDNS", NULL, FALSE); - svSetValue (ifcfg, "IPV6_PEERROUTES", NULL, FALSE); - if (!strcmp (value, NM_SETTING_IP6_CONFIG_METHOD_AUTO)) { - svSetValue (ifcfg, "IPV6_PEERDNS", - nm_setting_ip_config_get_ignore_auto_dns (s_ip6) ? "no" : "yes", - FALSE); - - svSetValue (ifcfg, "IPV6_PEERROUTES", - nm_setting_ip_config_get_ignore_auto_routes (s_ip6) ? "no" : "yes", - FALSE); - } - - svSetValue (ifcfg, "IPV6_FAILURE_FATAL", - nm_setting_ip_config_get_may_fail (s_ip6) ? "no" : "yes", - FALSE); - - route_metric = nm_setting_ip_config_get_route_metric (s_ip6); - tmp = route_metric != -1 ? g_strdup_printf ("%"G_GINT64_FORMAT, route_metric) : NULL; - svSetValue (ifcfg, "IPV6_ROUTE_METRIC", tmp, FALSE); - g_free (tmp); - - /* IPv6 Privacy Extensions */ - svSetValue (ifcfg, "IPV6_PRIVACY", NULL, FALSE); - svSetValue (ifcfg, "IPV6_PRIVACY_PREFER_PUBLIC_IP", NULL, FALSE); - switch (nm_setting_ip6_config_get_ip6_privacy (NM_SETTING_IP6_CONFIG (s_ip6))){ - case NM_SETTING_IP6_CONFIG_PRIVACY_DISABLED: - svSetValue (ifcfg, "IPV6_PRIVACY", "no", FALSE); - break; - case NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_PUBLIC_ADDR: - svSetValue (ifcfg, "IPV6_PRIVACY", "rfc3041", FALSE); - svSetValue (ifcfg, "IPV6_PRIVACY_PREFER_PUBLIC_IP", "yes", FALSE); - break; - case NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_TEMP_ADDR: - svSetValue (ifcfg, "IPV6_PRIVACY", "rfc3041", FALSE); - break; - default: - break; - } - - /* IPv6 Address generation mode */ - addr_gen_mode = nm_setting_ip6_config_get_addr_gen_mode (NM_SETTING_IP6_CONFIG (s_ip6)); - if (addr_gen_mode != NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE_EUI64) { - tmp = nm_utils_enum_to_str (nm_setting_ip6_config_addr_gen_mode_get_type (), - addr_gen_mode); - svSetValue (ifcfg, "IPV6_ADDR_GEN_MODE", tmp, FALSE); - g_free (tmp); - } else { - svSetValue (ifcfg, "IPV6_ADDR_GEN_MODE", NULL, FALSE); - } - - /* IPv6 tokenized interface identifier */ - value = nm_setting_ip6_config_get_token (NM_SETTING_IP6_CONFIG (s_ip6)); - svSetValue (ifcfg, "IPV6_TOKEN", value, FALSE); - - priority = nm_setting_ip_config_get_dns_priority (s_ip6); - if (priority) - svSetValueInt64 (ifcfg, "IPV6_DNS_PRIORITY", priority); - else - svSetValue (ifcfg, "IPV6_DNS_PRIORITY", NULL, FALSE); - - /* Static routes go to route6- file */ - route6_path = utils_get_route6_path (ifcfg->fileName); - if (!route6_path) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, - "Could not get route6 file path for '%s'", ifcfg->fileName); - goto error; - } - write_route6_file (route6_path, s_ip6, error); - g_free (route6_path); - if (error && *error) - goto error; - - return TRUE; - -error: - return FALSE; -} - -static void -add_dns_option (GPtrArray *array, const char *option) -{ - if (_nm_utils_dns_option_find_idx (array, option) < 0) - g_ptr_array_add (array, (gpointer) option); -} - -static gboolean -write_res_options (NMConnection *connection, shvarFile *ifcfg, GError **error) -{ - NMSettingIPConfig *s_ip6; - NMSettingIPConfig *s_ip4; - const char *method; - int i, num_options; - gs_unref_ptrarray GPtrArray *array = NULL; - GString *value; - - s_ip4 = nm_connection_get_setting_ip4_config (connection); - - if (!s_ip4) { - /* slave-type: clear res-options */ - svSetValue (ifcfg, "RES_OPTIONS", NULL, FALSE); - return TRUE; - } - - array = g_ptr_array_new (); - - method = nm_setting_ip_config_get_method (s_ip4); - if (g_strcmp0 (method, NM_SETTING_IP4_CONFIG_METHOD_DISABLED)) { - num_options = nm_setting_ip_config_get_num_dns_options (s_ip4); - for (i = 0; i < num_options; i++) - add_dns_option (array, nm_setting_ip_config_get_dns_option (s_ip4, i)); - } - - s_ip6 = nm_connection_get_setting_ip6_config (connection); - method = nm_setting_ip_config_get_method (s_ip6); - if (g_strcmp0 (method, NM_SETTING_IP6_CONFIG_METHOD_IGNORE)) { - num_options = nm_setting_ip_config_get_num_dns_options (s_ip6); - for (i = 0; i < num_options; i++) - add_dns_option (array, nm_setting_ip_config_get_dns_option (s_ip6, i)); - } - - if ( array->len > 0 - || nm_setting_ip_config_has_dns_options (s_ip4) - || nm_setting_ip_config_has_dns_options (s_ip6)) { - value = g_string_new (NULL); - for (i = 0; i < array->len; i++) { - if (i > 0) - g_string_append_c (value, ' '); - g_string_append (value, array->pdata[i]); - } - svSetValueFull (ifcfg, "RES_OPTIONS", value->str, FALSE); - g_string_free (value, TRUE); - } else - svSetValue (ifcfg, "RES_OPTIONS", NULL, FALSE); - - return TRUE; -} - -static char * -escape_id (const char *id) -{ - char *escaped = g_strdup (id); - char *p = escaped; - - /* Escape random stuff */ - while (*p) { - if (*p == ' ') - *p = '_'; - else if (strchr ("\\][|/=()!:", *p)) - *p = '-'; - p++; - } - - return escaped; -} - -static gboolean -write_connection (NMConnection *connection, - const char *ifcfg_dir, - const char *filename, - const char *keyfile, - char **out_filename, - GError **error) -{ - NMSettingConnection *s_con; - gboolean success = FALSE; - shvarFile *ifcfg = NULL; - char *ifcfg_name = NULL; - const char *type; - gboolean no_8021x = FALSE; - gboolean wired = FALSE; - - nm_assert (NM_IS_CONNECTION (connection)); - nm_assert (nm_connection_verify (connection, NULL)); - - if (!writer_can_write_connection (connection, error)) - return FALSE; - - s_con = nm_connection_get_setting_connection (connection); - g_assert (s_con); - - if (filename) { - /* For existing connections, 'filename' should be full path to ifcfg file */ - ifcfg = svOpenFile (filename, error); - if (!ifcfg) - return FALSE; - - ifcfg_name = g_strdup (filename); - } else { - char *escaped; - - escaped = escape_id (nm_setting_connection_get_id (s_con)); - ifcfg_name = g_strdup_printf ("%s/ifcfg-%s", ifcfg_dir, escaped); - - /* If a file with this path already exists then we need another name. - * Multiple connections can have the same ID (ie if two connections with - * the same ID are visible to different users) but of course can't have - * the same path. - */ - if (g_file_test (ifcfg_name, G_FILE_TEST_EXISTS)) { - guint32 idx = 0; - - g_free (ifcfg_name); - while (idx++ < 500) { - ifcfg_name = g_strdup_printf ("%s/ifcfg-%s-%u", ifcfg_dir, escaped, idx); - if (g_file_test (ifcfg_name, G_FILE_TEST_EXISTS) == FALSE) - break; - g_free (ifcfg_name); - ifcfg_name = NULL; - } - } - g_free (escaped); - - if (ifcfg_name == NULL) { - g_set_error_literal (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, - "Failed to find usable ifcfg file name"); - return FALSE; - } - - ifcfg = svCreateFile (ifcfg_name); - } - - type = nm_setting_connection_get_connection_type (s_con); - if (!type) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, - "Missing connection type!"); - goto out; - } - - if (!strcmp (type, NM_SETTING_WIRED_SETTING_NAME)) { - // FIXME: can't write PPPoE at this time - if (nm_connection_get_setting_pppoe (connection)) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, - "Can't write connection type '%s'", - NM_SETTING_PPPOE_SETTING_NAME); - goto out; - } - - if (!write_wired_setting (connection, ifcfg, error)) - goto out; - wired = TRUE; - } else if (!strcmp (type, NM_SETTING_VLAN_SETTING_NAME)) { - if (!write_vlan_setting (connection, ifcfg, &wired, error)) - goto out; - } else if (!strcmp (type, NM_SETTING_WIRELESS_SETTING_NAME)) { - if (!write_wireless_setting (connection, ifcfg, &no_8021x, error)) - goto out; - } else if (!strcmp (type, NM_SETTING_INFINIBAND_SETTING_NAME)) { - if (!write_infiniband_setting (connection, ifcfg, error)) - goto out; - } else if (!strcmp (type, NM_SETTING_BOND_SETTING_NAME)) { - if (!write_bonding_setting (connection, ifcfg, &wired, error)) - goto out; - } else if (!strcmp (type, NM_SETTING_TEAM_SETTING_NAME)) { - if (!write_team_setting (connection, ifcfg, &wired, error)) - goto out; - } else if (!strcmp (type, NM_SETTING_BRIDGE_SETTING_NAME)) { - if (!write_bridge_setting (connection, ifcfg, error)) - goto out; - } else { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, - "Can't write connection type '%s'", type); - goto out; - } - - if (!no_8021x) { - if (!write_8021x_setting (connection, ifcfg, wired, error)) - goto out; - } - - if (!write_bridge_port_setting (connection, ifcfg, error)) - goto out; - - if (!write_team_port_setting (connection, ifcfg, error)) - goto out; - - if (!write_dcb_setting (connection, ifcfg, error)) - goto out; - - svSetValue (ifcfg, "DHCP_HOSTNAME", NULL, FALSE); - svSetValue (ifcfg, "DHCP_FQDN", NULL, FALSE); - - if (!write_ip4_setting (connection, ifcfg, error)) - goto out; - write_ip4_aliases (connection, ifcfg_name); - - if (!write_ip6_setting (connection, ifcfg, error)) - goto out; - - if (!write_res_options (connection, ifcfg, error)) - goto out; - - write_connection_setting (s_con, ifcfg); - - if (!svWriteFile (ifcfg, 0644, error)) - goto out; - - /* Only return the filename if this was a newly written ifcfg */ - if (out_filename && !filename) - *out_filename = g_strdup (ifcfg_name); - - success = TRUE; - -out: - if (ifcfg) - svCloseFile (ifcfg); - g_free (ifcfg_name); - return success; -} - -gboolean -writer_can_write_connection (NMConnection *connection, GError **error) -{ - NMSettingConnection *s_con; - - if ( ( nm_connection_is_type (connection, NM_SETTING_WIRED_SETTING_NAME) - && !nm_connection_get_setting_pppoe (connection)) - || nm_connection_is_type (connection, NM_SETTING_VLAN_SETTING_NAME) - || nm_connection_is_type (connection, NM_SETTING_WIRELESS_SETTING_NAME) - || nm_connection_is_type (connection, NM_SETTING_INFINIBAND_SETTING_NAME) - || nm_connection_is_type (connection, NM_SETTING_BOND_SETTING_NAME) - || nm_connection_is_type (connection, NM_SETTING_TEAM_SETTING_NAME) - || nm_connection_is_type (connection, NM_SETTING_BRIDGE_SETTING_NAME)) - return TRUE; - - s_con = nm_connection_get_setting_connection (connection); - g_assert (s_con); - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, - "The ifcfg-rh plugin cannot write the connection '%s' (type '%s' pppoe %d)", - nm_connection_get_id (connection), - nm_setting_connection_get_connection_type (s_con), - !!nm_connection_get_setting_pppoe (connection)); - return FALSE; -} - -gboolean -writer_new_connection (NMConnection *connection, - const char *ifcfg_dir, - char **out_filename, - GError **error) -{ - return write_connection (connection, ifcfg_dir, NULL, NULL, out_filename, error); -} - -gboolean -writer_update_connection (NMConnection *connection, - const char *ifcfg_dir, - const char *filename, - const char *keyfile, - GError **error) -{ - if (utils_has_complex_routes (filename)) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, - "Cannot modify a connection that has an associated 'rule-' or 'rule6-' file"); - return FALSE; - } - - return write_connection (connection, ifcfg_dir, filename, keyfile, NULL, error); -} - diff --git a/src/settings/plugins/ifcfg-rh/writer.h b/src/settings/plugins/ifcfg-rh/writer.h deleted file mode 100644 index 97a9f252..00000000 --- a/src/settings/plugins/ifcfg-rh/writer.h +++ /dev/null @@ -1,40 +0,0 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* NetworkManager system settings service - keyfile plugin - * - * 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) 2009 Red Hat, Inc. - */ - -#ifndef _WRITER_H_ -#define _WRITER_H_ - -#include "nm-connection.h" - -gboolean writer_can_write_connection (NMConnection *connection, - GError **error); - -gboolean writer_new_connection (NMConnection *connection, - const char *ifcfg_dir, - char **out_filename, - GError **error); - -gboolean writer_update_connection (NMConnection *connection, - const char *ifcfg_dir, - const char *filename, - const char *keyfile, - GError **error); - -#endif /* _WRITER_H_ */ -- cgit 1.3.0-6-gf8a5