diff options
Diffstat (limited to 'src/settings/plugins/ifnet')
19 files changed, 825 insertions, 739 deletions
diff --git a/src/settings/plugins/ifnet/Makefile.am b/src/settings/plugins/ifnet/Makefile.am index 66d706b6a..a22ea557a 100644 --- a/src/settings/plugins/ifnet/Makefile.am +++ b/src/settings/plugins/ifnet/Makefile.am @@ -1,32 +1,37 @@ SUBDIRS = . tests -pkglib_LTLIBRARIES = libnm-settings-plugin-ifnet.la - -noinst_LTLIBRARIES = lib-ifnet-io.la +@GNOME_CODE_COVERAGE_RULES@ AM_CPPFLAGS = \ - -I$(top_srcdir)/src/wifi \ + -I$(top_srcdir)/src \ + -I$(top_srcdir)/src/config \ + -I$(top_srcdir)/src/logging \ + -I$(top_srcdir)/src/platform \ -I$(top_srcdir)/src/settings \ -I$(top_srcdir)/include \ -I$(top_builddir)/include \ -I$(top_srcdir)/libnm-glib \ -I$(top_srcdir)/libnm-util \ -I$(top_builddir)/libnm-util \ + -DG_LOG_DOMAIN=\""NetworkManager-ifnet"\" \ + -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ $(GLIB_CFLAGS) \ $(DBUS_CFLAGS) \ - -DSYSCONFDIR=\"$(sysconfdir)\" \ + $(POLKIT_CFLAGS) \ + $(GUDEV_CFLAGS) \ + -DSYSCONFDIR=\"$(sysconfdir)\" -DSBINDIR=\"$(sbindir)\" +pkglib_LTLIBRARIES = libnm-settings-plugin-ifnet.la + +noinst_LTLIBRARIES = lib-ifnet-io.la + libnm_settings_plugin_ifnet_la_SOURCES = \ nm-ifnet-connection.c \ nm-ifnet-connection.h \ plugin.c \ plugin.h -libnm_settings_plugin_ifnet_la_CPPFLAGS = \ - $(GUDEV_CFLAGS) \ - $(AM_CPPFLAGS) - libnm_settings_plugin_ifnet_la_LDFLAGS = -module -avoid-version libnm_settings_plugin_ifnet_la_LIBADD = \ @@ -44,9 +49,10 @@ lib_ifnet_io_la_SOURCES = \ net_utils.h\ net_utils.c\ wpa_parser.h\ - wpa_parser.c + wpa_parser.c \ + errors.h \ + errors.c lib_ifnet_io_la_LIBADD = \ - $(top_builddir)/src/wifi/libwifi-utils.la \ $(top_builddir)/libnm-util/libnm-util.la \ $(GLIB_LIBS) diff --git a/src/settings/plugins/ifnet/Makefile.in b/src/settings/plugins/ifnet/Makefile.in index f12de4fa3..6a6581896 100644 --- a/src/settings/plugins/ifnet/Makefile.in +++ b/src/settings/plugins/ifnet/Makefile.in @@ -82,7 +82,8 @@ subdir = src/settings/plugins/ifnet DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \ $(top_srcdir)/build-aux/depcomp ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 -am__aclocal_m4_deps = $(top_srcdir)/m4/compiler_warnings.m4 \ +am__aclocal_m4_deps = $(top_srcdir)/m4/ax_lib_readline.m4 \ + $(top_srcdir)/m4/compiler_warnings.m4 \ $(top_srcdir)/m4/gettext.m4 \ $(top_srcdir)/m4/gnome-code-coverage.m4 \ $(top_srcdir)/m4/gtk-doc.m4 $(top_srcdir)/m4/iconv.m4 \ @@ -131,10 +132,9 @@ am__installdirs = "$(DESTDIR)$(pkglibdir)" LTLIBRARIES = $(noinst_LTLIBRARIES) $(pkglib_LTLIBRARIES) am__DEPENDENCIES_1 = lib_ifnet_io_la_DEPENDENCIES = \ - $(top_builddir)/src/wifi/libwifi-utils.la \ $(top_builddir)/libnm-util/libnm-util.la $(am__DEPENDENCIES_1) am_lib_ifnet_io_la_OBJECTS = net_parser.lo connection_parser.lo \ - net_utils.lo wpa_parser.lo + net_utils.lo wpa_parser.lo errors.lo lib_ifnet_io_la_OBJECTS = $(am_lib_ifnet_io_la_OBJECTS) AM_V_lt = $(am__v_lt_@AM_V@) am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) @@ -144,9 +144,8 @@ libnm_settings_plugin_ifnet_la_DEPENDENCIES = \ $(top_builddir)/libnm-util/libnm-util.la \ $(top_builddir)/libnm-glib/libnm-glib.la lib-ifnet-io.la \ $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) -am_libnm_settings_plugin_ifnet_la_OBJECTS = \ - libnm_settings_plugin_ifnet_la-nm-ifnet-connection.lo \ - libnm_settings_plugin_ifnet_la-plugin.lo +am_libnm_settings_plugin_ifnet_la_OBJECTS = nm-ifnet-connection.lo \ + plugin.lo libnm_settings_plugin_ifnet_la_OBJECTS = \ $(am_libnm_settings_plugin_ifnet_la_OBJECTS) libnm_settings_plugin_ifnet_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \ @@ -283,12 +282,15 @@ CXXFLAGS = @CXXFLAGS@ CYGPATH_W = @CYGPATH_W@ DATADIRNAME = @DATADIRNAME@ DBUS_CFLAGS = @DBUS_CFLAGS@ +DBUS_GLIB_100_CFLAGS = @DBUS_GLIB_100_CFLAGS@ +DBUS_GLIB_100_LIBS = @DBUS_GLIB_100_LIBS@ 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@ DNSMASQ_PATH = @DNSMASQ_PATH@ DSYMUTIL = @DSYMUTIL@ @@ -313,7 +315,6 @@ 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@ @@ -358,12 +359,16 @@ LIBGCRYPT_LIBS = @LIBGCRYPT_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@ +LIBTEAMDCTL_CFLAGS = @LIBTEAMDCTL_CFLAGS@ +LIBTEAMDCTL_LIBS = @LIBTEAMDCTL_LIBS@ LIBTOOL = @LIBTOOL@ LIPO = @LIPO@ LN_S = @LN_S@ @@ -380,6 +385,8 @@ MOC = @MOC@ MSGFMT = @MSGFMT@ MSGFMT_015 = @MSGFMT_015@ MSGMERGE = @MSGMERGE@ +NEWT_CFLAGS = @NEWT_CFLAGS@ +NEWT_LIBS = @NEWT_LIBS@ NM = @NM@ NMEDIT = @NMEDIT@ NM_MAJOR_VERSION = @NM_MAJOR_VERSION@ @@ -407,11 +414,16 @@ 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@ +PPPOE_PATH = @PPPOE_PATH@ QT_CFLAGS = @QT_CFLAGS@ QT_LIBS = @QT_LIBS@ RANLIB = @RANLIB@ +READLINE_LIBS = @READLINE_LIBS@ SED = @SED@ +SELINUX_CFLAGS = @SELINUX_CFLAGS@ +SELINUX_LIBS = @SELINUX_LIBS@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ STRIP = @STRIP@ @@ -426,6 +438,7 @@ UDEV_BASE_DIR = @UDEV_BASE_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@ @@ -488,6 +501,7 @@ psdir = @psdir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ +subdirs = @subdirs@ sysconfdir = @sysconfdir@ systemdsystemunitdir = @systemdsystemunitdir@ target_alias = @target_alias@ @@ -498,32 +512,35 @@ with_dhclient = @with_dhclient@ with_dhcpcd = @with_dhcpcd@ with_netconfig = @with_netconfig@ with_resolvconf = @with_resolvconf@ +with_valgrind = @with_valgrind@ SUBDIRS = . tests -pkglib_LTLIBRARIES = libnm-settings-plugin-ifnet.la -noinst_LTLIBRARIES = lib-ifnet-io.la AM_CPPFLAGS = \ - -I$(top_srcdir)/src/wifi \ + -I$(top_srcdir)/src \ + -I$(top_srcdir)/src/config \ + -I$(top_srcdir)/src/logging \ + -I$(top_srcdir)/src/platform \ -I$(top_srcdir)/src/settings \ -I$(top_srcdir)/include \ -I$(top_builddir)/include \ -I$(top_srcdir)/libnm-glib \ -I$(top_srcdir)/libnm-util \ -I$(top_builddir)/libnm-util \ + -DG_LOG_DOMAIN=\""NetworkManager-ifnet"\" \ + -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ $(GLIB_CFLAGS) \ $(DBUS_CFLAGS) \ - -DSYSCONFDIR=\"$(sysconfdir)\" \ - -DSBINDIR=\"$(sbindir)\" + $(POLKIT_CFLAGS) \ + $(GUDEV_CFLAGS) \ + -DSYSCONFDIR=\"$(sysconfdir)\" +pkglib_LTLIBRARIES = libnm-settings-plugin-ifnet.la +noinst_LTLIBRARIES = lib-ifnet-io.la libnm_settings_plugin_ifnet_la_SOURCES = \ nm-ifnet-connection.c \ nm-ifnet-connection.h \ plugin.c \ plugin.h -libnm_settings_plugin_ifnet_la_CPPFLAGS = \ - $(GUDEV_CFLAGS) \ - $(AM_CPPFLAGS) - libnm_settings_plugin_ifnet_la_LDFLAGS = -module -avoid-version libnm_settings_plugin_ifnet_la_LIBADD = \ $(top_builddir)/libnm-util/libnm-util.la \ @@ -540,10 +557,11 @@ lib_ifnet_io_la_SOURCES = \ net_utils.h\ net_utils.c\ wpa_parser.h\ - wpa_parser.c + wpa_parser.c \ + errors.h \ + errors.c lib_ifnet_io_la_LIBADD = \ - $(top_builddir)/src/wifi/libwifi-utils.la \ $(top_builddir)/libnm-util/libnm-util.la \ $(GLIB_LIBS) @@ -641,10 +659,11 @@ distclean-compile: -rm -f *.tab.c @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/connection_parser.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libnm_settings_plugin_ifnet_la-nm-ifnet-connection.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libnm_settings_plugin_ifnet_la-plugin.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/errors.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/net_parser.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/net_utils.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nm-ifnet-connection.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/plugin.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/wpa_parser.Plo@am__quote@ .c.o: @@ -668,20 +687,6 @@ distclean-compile: @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $< -libnm_settings_plugin_ifnet_la-nm-ifnet-connection.lo: nm-ifnet-connection.c -@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libnm_settings_plugin_ifnet_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libnm_settings_plugin_ifnet_la-nm-ifnet-connection.lo -MD -MP -MF $(DEPDIR)/libnm_settings_plugin_ifnet_la-nm-ifnet-connection.Tpo -c -o libnm_settings_plugin_ifnet_la-nm-ifnet-connection.lo `test -f 'nm-ifnet-connection.c' || echo '$(srcdir)/'`nm-ifnet-connection.c -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libnm_settings_plugin_ifnet_la-nm-ifnet-connection.Tpo $(DEPDIR)/libnm_settings_plugin_ifnet_la-nm-ifnet-connection.Plo -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='nm-ifnet-connection.c' object='libnm_settings_plugin_ifnet_la-nm-ifnet-connection.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) $(libnm_settings_plugin_ifnet_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libnm_settings_plugin_ifnet_la-nm-ifnet-connection.lo `test -f 'nm-ifnet-connection.c' || echo '$(srcdir)/'`nm-ifnet-connection.c - -libnm_settings_plugin_ifnet_la-plugin.lo: plugin.c -@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libnm_settings_plugin_ifnet_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libnm_settings_plugin_ifnet_la-plugin.lo -MD -MP -MF $(DEPDIR)/libnm_settings_plugin_ifnet_la-plugin.Tpo -c -o libnm_settings_plugin_ifnet_la-plugin.lo `test -f 'plugin.c' || echo '$(srcdir)/'`plugin.c -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libnm_settings_plugin_ifnet_la-plugin.Tpo $(DEPDIR)/libnm_settings_plugin_ifnet_la-plugin.Plo -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='plugin.c' object='libnm_settings_plugin_ifnet_la-plugin.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) $(libnm_settings_plugin_ifnet_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libnm_settings_plugin_ifnet_la-plugin.lo `test -f 'plugin.c' || echo '$(srcdir)/'`plugin.c - mostlyclean-libtool: -rm -f *.lo @@ -970,6 +975,9 @@ uninstall-am: uninstall-pkglibLTLIBRARIES uninstall-am uninstall-pkglibLTLIBRARIES +@GNOME_CODE_COVERAGE_RULES@ + -DSBINDIR=\"$(sbindir)\" + # 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/ifnet/connection_parser.c b/src/settings/plugins/ifnet/connection_parser.c index da3f913dd..85873d5f7 100644 --- a/src/settings/plugins/ifnet/connection_parser.c +++ b/src/settings/plugins/ifnet/connection_parser.c @@ -37,38 +37,25 @@ #include <nm-setting-wireless.h> #include <nm-setting-8021x.h> #include <nm-system-config-interface.h> +#include <nm-logging.h> #include <nm-utils.h> #include "net_utils.h" #include "wpa_parser.h" #include "connection_parser.h" #include "nm-ifnet-connection.h" +#include "errors.h" -static void -update_connection_id (NMConnection *connection, const char *conn_name) +static char * +connection_id_from_ifnet_name (const char *conn_name) { - gchar *idstr = NULL; - gchar *uuid_base = NULL; - gchar *uuid = NULL; - int name_len; - NMSettingConnection *setting; - - name_len = strlen (conn_name); - if ((name_len > 2) && (g_str_has_prefix (conn_name, "0x"))) { - idstr = utils_hexstr2bin (conn_name + 2, name_len - 2); - } else - idstr = g_strdup_printf ("%s", conn_name); - uuid_base = idstr; - uuid = nm_utils_uuid_generate_from_string (uuid_base); - setting = nm_connection_get_setting_connection (connection); - g_object_set (setting, NM_SETTING_CONNECTION_ID, idstr, - NM_SETTING_CONNECTION_UUID, uuid, NULL); - PLUGIN_PRINT (IFNET_PLUGIN_NAME, - "update_connection_setting_from_config_block: name:%s, id:%s, uuid: %s", - conn_name, idstr, uuid); + int name_len = strlen (conn_name); - g_free (uuid); - g_free (idstr); + /* Convert a hex-encoded conn_name (only used for wifi SSIDs) to human-readable one */ + if ((name_len > 2) && (g_str_has_prefix (conn_name, "0x"))) + return nm_utils_hexstr2bin (conn_name + 2, name_len - 2); + + return g_strdup (conn_name); } static gboolean eap_simple_reader (const char *eap_method, @@ -112,6 +99,7 @@ typedef struct { static EAPReader eap_readers[] = { {"md5", eap_simple_reader, TRUE}, + {"pwd", eap_simple_reader, TRUE}, {"pap", eap_simple_reader, TRUE}, {"chap", eap_simple_reader, TRUE}, {"mschap", eap_simple_reader, TRUE}, @@ -213,11 +201,9 @@ eap_tls_reader (const char *eap_method, goto done; } } else { - PLUGIN_WARN (IFNET_PLUGIN_NAME, - " warning: missing %s for EAP" - " method '%s'; this is insecure!", - phase2 ? "IEEE_8021X_INNER_CA_CERT" : - "IEEE_8021X_CA_CERT", eap_method); + nm_log_warn (LOGD_SETTINGS, " missing %s for EAP method '%s'; this is insecure!", + phase2 ? "IEEE_8021X_INNER_CA_CERT" : + "IEEE_8021X_CA_CERT", eap_method); } /* Private key password */ @@ -323,9 +309,8 @@ eap_peap_reader (const char *eap_method, NULL, error)) goto done; } else { - PLUGIN_WARN (IFNET_PLUGIN_NAME, " warning: missing " - "IEEE_8021X_CA_CERT for EAP method '%s'; this is" - " insecure!", eap_method); + nm_log_warn (LOGD_SETTINGS, " missing IEEE_8021X_CA_CERT for EAP method '%s'; this is insecure!", + eap_method); } peapver = wpa_get_value (ssid, "phase1"); @@ -426,9 +411,8 @@ eap_ttls_reader (const char *eap_method, NULL, error)) goto done; } else { - PLUGIN_WARN (IFNET_PLUGIN_NAME, " warning: missing " - "IEEE_8021X_CA_CERT for EAP method '%s'; this is" - " insecure!", eap_method); + nm_log_warn (LOGD_SETTINGS, " missing IEEE_8021X_CA_CERT for EAP method '%s'; this is insecure!", + eap_method); } /* anonymous indentity for tls */ @@ -468,7 +452,7 @@ eap_ttls_reader (const char *eap_method, } else if ((pos = strstr (*iter, "mschapv2")) != NULL || (pos = strstr (*iter, "md5")) != NULL) { if (!eap_simple_reader (pos, ssid, s_8021x, TRUE, basepath, error)) { - PLUGIN_WARN (IFNET_PLUGIN_NAME, "SIMPLE ERROR"); + nm_log_warn (LOGD_SETTINGS, "SIMPLE ERROR"); goto done; } g_object_set (s_8021x, NM_SETTING_802_1X_PHASE2_AUTHEAP, @@ -508,8 +492,7 @@ guess_connection_type (const char *conn_name) if (!ret_type) ret_type = NM_SETTING_WIRED_SETTING_NAME; - PLUGIN_PRINT (IFNET_PLUGIN_NAME, - "guessed connection type (%s) = %s", conn_name, ret_type); + nm_log_info (LOGD_SETTINGS, "guessed connection type (%s) = %s", conn_name, ret_type); return ret_type; } @@ -552,9 +535,7 @@ make_wired_connection_setting (NMConnection *connection, errno = 0; mtu = strtol (value, NULL, 10); if (errno || mtu < 0 || mtu > 65535) { - PLUGIN_WARN (IFNET_PLUGIN_NAME, - " warning: invalid MTU '%s' for %s", - value, conn_name); + nm_log_warn (LOGD_SETTINGS, " invalid MTU '%s' for %s", value, conn_name); } else g_object_set (s_wired, NM_SETTING_WIRED_MTU, (guint32) mtu, NULL); @@ -628,8 +609,7 @@ make_ip4_setting (NMConnection *connection, g_object_unref (ip4_setting); return; } - PLUGIN_PRINT (IFNET_PLUGIN_NAME, "Using %s method for %s", - method, conn_name); + nm_log_info (LOGD_SETTINGS, "Using %s method for %s", method, conn_name); }else { iblock = convert_ip4_config_block (conn_name); if (!iblock) { @@ -655,8 +635,7 @@ make_ip4_setting (NMConnection *connection, NM_SETTING_IP4_CONFIG_IGNORE_AUTO_ROUTES, TRUE, NULL); if (!nm_setting_ip4_config_add_address (ip4_setting, ip4_addr)) - PLUGIN_WARN (IFNET_PLUGIN_NAME, - "ignoring duplicate IP4 address"); + nm_log_warn (LOGD_SETTINGS, "ignoring duplicate IP4 address"); nm_ip4_address_unref (ip4_addr); current_iblock = iblock; iblock = iblock->next; @@ -678,16 +657,14 @@ make_ip4_setting (NMConnection *connection, g_object_set (ip4_setting, NM_SETTING_IP4_CONFIG_DHCP_HOSTNAME, dhcp_hostname, NULL); - PLUGIN_PRINT (IFNET_PLUGIN_NAME, "DHCP hostname: %s", - dhcp_hostname); + nm_log_info (LOGD_SETTINGS, "DHCP hostname: %s", dhcp_hostname); g_free (dhcp_hostname); } if (client_id) { g_object_set (ip4_setting, NM_SETTING_IP4_CONFIG_DHCP_CLIENT_ID, client_id, NULL); - PLUGIN_PRINT (IFNET_PLUGIN_NAME, "DHCP client id: %s", - client_id); + nm_log_info (LOGD_SETTINGS, "DHCP client id: %s", client_id); g_free (client_id); } } @@ -710,10 +687,7 @@ make_ip4_setting (NMConnection *connection, for (item = searches; *item; item++) { if (strlen (*item)) { if (!nm_setting_ip4_config_add_dns_search (ip4_setting, *item)) - PLUGIN_WARN - (IFNET_PLUGIN_NAME, - " warning: duplicate DNS domain '%s'", - *item); + nm_log_warn (LOGD_SETTINGS, " duplicate DNS domain '%s'", *item); } } g_strfreev (searches); @@ -750,10 +724,8 @@ make_ip4_setting (NMConnection *connection, } if (!nm_setting_ip4_config_add_route (ip4_setting, route)) - PLUGIN_WARN (IFNET_PLUGIN_NAME, - "warning: duplicate IP4 route"); - PLUGIN_PRINT (IFNET_PLUGIN_NAME, - "new IP4 route:%d\n", iblock->ip); + nm_log_warn (LOGD_SETTINGS, "duplicate IP4 route"); + nm_log_info (LOGD_SETTINGS, "new IP4 route:%d\n", iblock->ip); nm_ip4_route_unref (route); @@ -782,11 +754,6 @@ make_ip6_setting (NMConnection *connection, gboolean never_default = !has_default_ip6_route (conn_name); s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new (); - if (!s_ip6) { - g_set_error (error, ifnet_plugin_error_quark (), 0, - "Could not allocate IP6 setting"); - return; - } value = ifnet_get_data (conn_name, "enable_ipv6"); if (value && is_true (value)) @@ -810,8 +777,7 @@ make_ip6_setting (NMConnection *connection, else // doesn't have "dhcp6" && has at least one ipv6 address method = NM_SETTING_IP6_CONFIG_METHOD_MANUAL; - PLUGIN_PRINT (IFNET_PLUGIN_NAME, "IPv6 for %s enabled, using %s", - conn_name, method); + nm_log_info (LOGD_SETTINGS, "IPv6 for %s enabled, using %s", conn_name, method); g_object_set (s_ip6, NM_SETTING_IP6_CONFIG_METHOD, method, @@ -837,13 +803,10 @@ make_ip6_setting (NMConnection *connection, nm_ip6_address_set_address (ip6_addr, iblock->ip); nm_ip6_address_set_prefix (ip6_addr, iblock->prefix); if (nm_setting_ip6_config_add_address (s_ip6, ip6_addr)) { - PLUGIN_PRINT (IFNET_PLUGIN_NAME, - "ipv6 addresses count: %d", - nm_setting_ip6_config_get_num_addresses - (s_ip6)); + nm_log_info (LOGD_SETTINGS, "ipv6 addresses count: %d", + nm_setting_ip6_config_get_num_addresses (s_ip6)); } else { - PLUGIN_WARN (IFNET_PLUGIN_NAME, - "ignoring duplicate IP4 address"); + nm_log_warn (LOGD_SETTINGS, "ignoring duplicate IP4 address"); } nm_ip6_address_unref (ip6_addr); current_iblock = iblock; @@ -893,10 +856,10 @@ make_ip6_setting (NMConnection *connection, nm_ip6_route_set_metric (route, (guint32) 1); } - if (!nm_setting_ip6_config_add_route (s_ip6, route)) - PLUGIN_WARN (IFNET_PLUGIN_NAME, - " warning: duplicate IP6 route"); - PLUGIN_PRINT (IFNET_PLUGIN_NAME, " info: new IP6 route"); + if (nm_setting_ip6_config_add_route (s_ip6, route)) + nm_log_info (LOGD_SETTINGS, " new IP6 route"); + else + nm_log_warn (LOGD_SETTINGS, " duplicate IP6 route"); nm_ip6_route_unref (route); current_iblock = iblock; @@ -910,8 +873,7 @@ done: error: g_object_unref (s_ip6); - PLUGIN_WARN (IFNET_PLUGIN_NAME, " warning: Ignore IPv6 for %s", - conn_name); + nm_log_warn (LOGD_SETTINGS, " Ignore IPv6 for %s", conn_name); return; } @@ -932,8 +894,7 @@ make_wireless_connection_setting (const char *conn_name, "ppp") != 0, NULL); type = ifnet_get_data (conn_name, "type"); if (strcmp (type, "ppp") == 0) { - PLUGIN_WARN (IFNET_PLUGIN_NAME, - "PPP over WIFI is not supported yet"); + nm_log_warn (LOGD_SETTINGS, "PPP over WIFI is not supported yet"); return NULL; } @@ -978,7 +939,7 @@ make_wireless_connection_setting (const char *conn_name, goto error; } - tmp = utils_hexstr2bin (p, value_len - 2); + tmp = nm_utils_hexstr2bin (p, value_len - 2); ssid_len = (value_len - 2) / 2; converted = g_malloc0 (ssid_len + 1); memcpy (converted, tmp, ssid_len); @@ -1013,7 +974,7 @@ make_wireless_connection_setting (const char *conn_name, g_object_set (wireless_setting, NM_SETTING_WIRELESS_MODE, mode, NULL); - PLUGIN_PRINT (IFNET_PLUGIN_NAME, "Using mode: %s", mode); + nm_log_info (LOGD_SETTINGS, "Using mode: %s", mode); } /* BSSID setting */ @@ -1042,17 +1003,14 @@ make_wireless_connection_setting (const char *conn_name, errno = 0; mtu = strtol (value, NULL, 10); if (errno || mtu < 0 || mtu > 50000) { - PLUGIN_WARN (IFNET_PLUGIN_NAME, - " warning: invalid MTU '%s' for %s", - value, conn_name); + nm_log_warn (LOGD_SETTINGS, " invalid MTU '%s' for %s", value, conn_name); } else g_object_set (wireless_setting, NM_SETTING_WIRELESS_MTU, (guint32) mtu, NULL); } - PLUGIN_PRINT (IFNET_PLUGIN_NAME, "wireless_setting added for %s", - conn_name); + nm_log_info (LOGD_SETTINGS, "wireless_setting added for %s", conn_name); return NM_SETTING (wireless_setting); error: if (wireless_setting) @@ -1146,7 +1104,7 @@ add_one_wep_key (const char *ssid, } - converted = utils_bin2hexstr (tmp, strlen (tmp), strlen (tmp) * 2); + converted = nm_utils_bin2hexstr (tmp, strlen (tmp), strlen (tmp) * 2); g_free (tmp); } else { g_set_error (error, ifnet_plugin_error_quark (), 0, @@ -1201,8 +1159,7 @@ make_wep_setting (const char *ssid, GError **error) g_object_set (s_wireless_sec, NM_SETTING_WIRELESS_SECURITY_WEP_TX_KEYIDX, default_key_idx, NULL); - PLUGIN_PRINT (IFNET_PLUGIN_NAME, - "Default key index: %d", default_key_idx); + nm_log_info (LOGD_SETTINGS, "Default key index: %d", default_key_idx); } else { g_set_error (error, ifnet_plugin_error_quark (), 0, "Invalid default WEP key '%s'", value); @@ -1240,14 +1197,12 @@ make_wep_setting (const char *ssid, GError **error) g_object_set (s_wireless_sec, NM_SETTING_WIRELESS_SECURITY_AUTH_ALG, "open", NULL); - PLUGIN_PRINT (IFNET_PLUGIN_NAME, - "WEP: Use open system authentication"); + nm_log_info (LOGD_SETTINGS, "WEP: Use open system authentication"); } else if (strcmp (auth_alg, "SHARED") == 0) { g_object_set (s_wireless_sec, NM_SETTING_WIRELESS_SECURITY_AUTH_ALG, "shared", NULL); - PLUGIN_PRINT (IFNET_PLUGIN_NAME, - "WEP: Use shared system authentication"); + nm_log_info (LOGD_SETTINGS, "WEP: Use shared system authentication"); } else { g_set_error (error, ifnet_plugin_error_quark (), 0, "Invalid WEP authentication algorithm '%s'", @@ -1292,7 +1247,7 @@ parse_wpa_psk (const char *psk, GError **error) return NULL; } - /* Passphrase must be between 10 and 66 characters in length becuase WPA + /* 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. @@ -1359,14 +1314,12 @@ fill_wpa_ciphers (const char *ssid, */ if (adhoc) { if (group && (i > 0)) { - PLUGIN_WARN (IFNET_PLUGIN_NAME, - " warning: ignoring group cipher '%s' (only one group cipher allowed in Ad-Hoc mode)", - *iter); + nm_log_warn (LOGD_SETTINGS, " ignoring group cipher '%s' (only one group cipher allowed in Ad-Hoc mode)", + *iter); continue; } else if (!group) { - PLUGIN_WARN (IFNET_PLUGIN_NAME, - " warning: ignoring pairwise cipher '%s' (pairwise not used in Ad-Hoc mode)", - *iter); + nm_log_warn (LOGD_SETTINGS, " ignoring pairwise cipher '%s' (pairwise not used in Ad-Hoc mode)", + *iter); continue; } } @@ -1390,10 +1343,9 @@ fill_wpa_ciphers (const char *ssid, else if (group && !strcmp (*iter, "WEP40")) nm_setting_wireless_security_add_group (wsec, "wep40"); else { - PLUGIN_WARN (IFNET_PLUGIN_NAME, - " warning: ignoring invalid %s cipher '%s'", - group ? "CIPHER_GROUP" : "CIPHER_PAIRWISE", - *iter); + nm_log_warn (LOGD_SETTINGS, " ignoring invalid %s cipher '%s'", + group ? "CIPHER_GROUP" : "CIPHER_PAIRWISE", + *iter); } } @@ -1440,10 +1392,8 @@ fill_8021x (const char *ssid, * used with TTLS or PEAP or whatever. */ if (wifi && eap->wifi_phase2_only) { - PLUGIN_WARN (IFNET_PLUGIN_NAME, - " warning: ignored invalid " - "IEEE_8021X_EAP_METHOD '%s'; not allowed for wifi.", - lower); + nm_log_warn (LOGD_SETTINGS, " ignored invalid IEEE_8021X_EAP_METHOD '%s'; not allowed for wifi.", + lower); goto next; } @@ -1460,9 +1410,7 @@ fill_8021x (const char *ssid, } if (!found) { - PLUGIN_WARN (IFNET_PLUGIN_NAME, - " warning: ignored unknown" - "IEEE_8021X_EAP_METHOD '%s'.", lower); + nm_log_warn (LOGD_SETTINGS, " ignored unknown IEEE_8021X_EAP_METHOD '%s'.", lower); } g_free (lower); } @@ -1586,8 +1534,7 @@ make_wireless_security_setting (const char *conn_name, "ppp") != 0, NULL); if (!wpa_get_value (conn_name, "ssid")) return NULL; - PLUGIN_PRINT (IFNET_PLUGIN_NAME, - "updating wireless security settings (%s).", conn_name); + nm_log_info (LOGD_SETTINGS, "updating wireless security settings (%s).", conn_name); ssid = conn_name; value = wpa_get_value (ssid, "mode"); @@ -1668,11 +1615,10 @@ ifnet_update_connection_from_config_block (const char *conn_name, NMSettingWirelessSecurity *wsec = NULL; gboolean auto_conn = TRUE; const char *value = NULL; + gchar *id, *uuid; gboolean success = FALSE; connection = nm_connection_new (); - if (!connection) - return NULL; setting = nm_connection_get_setting_connection (connection); if (!setting) { setting = NM_SETTING_CONNECTION (nm_setting_connection_new ()); @@ -1684,18 +1630,33 @@ ifnet_update_connection_from_config_block (const char *conn_name, value = ifnet_get_data (conn_name, "auto"); if (value && !strcmp (value, "false")) auto_conn = FALSE; - update_connection_id (connection, conn_name); - g_object_set (setting, NM_SETTING_CONNECTION_TYPE, type, - NM_SETTING_CONNECTION_READ_ONLY, FALSE, - NM_SETTING_CONNECTION_AUTOCONNECT, auto_conn, NULL); + + /* Try to read UUID from the ifnet block, otherwise generate UUID from + * the connection ID. + */ + id = connection_id_from_ifnet_name (conn_name); + uuid = g_strdup (ifnet_get_data (conn_name, "uuid")); + if (!uuid) + uuid = nm_utils_uuid_generate_from_string (id); + + g_object_set (setting, + NM_SETTING_CONNECTION_TYPE, type, + NM_SETTING_CONNECTION_ID, id, + NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_INTERFACE_NAME, conn_name, + NM_SETTING_CONNECTION_READ_ONLY, FALSE, + NM_SETTING_CONNECTION_AUTOCONNECT, auto_conn, + NULL); + nm_log_info (LOGD_SETTINGS, "name:%s, id:%s, uuid: %s", conn_name, id, uuid); + g_free (id); + g_free (uuid); if (!strcmp (NM_SETTING_WIRED_SETTING_NAME, type) || !strcmp (NM_SETTING_PPPOE_SETTING_NAME, type)) { /* wired setting */ make_wired_connection_setting (connection, conn_name, error); if (error && *error) { - PLUGIN_WARN (IFNET_PLUGIN_NAME, - "Found error: %s", (*error)->message); + nm_log_warn (LOGD_SETTINGS, "Found error: %s", (*error)->message); goto error; } /* pppoe setting */ @@ -1703,8 +1664,7 @@ ifnet_update_connection_from_config_block (const char *conn_name, make_pppoe_connection_setting (connection, conn_name, error); if (error && *error) { - PLUGIN_WARN (IFNET_PLUGIN_NAME, - "Found error: %s", (*error)->message); + nm_log_warn (LOGD_SETTINGS, "Found error: %s", (*error)->message); goto error; } } else if (!strcmp (NM_SETTING_WIRELESS_SETTING_NAME, type)) { @@ -1717,28 +1677,20 @@ ifnet_update_connection_from_config_block (const char *conn_name, nm_connection_add_setting (connection, wireless_setting); if (error && *error) { - PLUGIN_WARN (IFNET_PLUGIN_NAME, - "Found error: %s", (*error)->message); + nm_log_warn (LOGD_SETTINGS, "Found error: %s", (*error)->message); goto error; } /* wireless security setting */ wsec = make_wireless_security_setting (conn_name, basepath, &s_8021x, error); if (wsec) { - nm_connection_add_setting (connection, - NM_SETTING (wsec)); + nm_connection_add_setting (connection, NM_SETTING (wsec)); if (s_8021x) - nm_connection_add_setting (connection, - NM_SETTING - (s_8021x)); - g_object_set (wireless_setting, NM_SETTING_WIRELESS_SEC, - NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, - NULL); + nm_connection_add_setting (connection, NM_SETTING (s_8021x)); } if (error && *error) { - PLUGIN_WARN (IFNET_PLUGIN_NAME, - "Found error: %s", (*error)->message); + nm_log_warn (LOGD_SETTINGS, "Found error: %s", (*error)->message); goto error; } @@ -1748,21 +1700,22 @@ ifnet_update_connection_from_config_block (const char *conn_name, /* IPv4 setting */ make_ip4_setting (connection, conn_name, error); if (error && *error) { - PLUGIN_WARN (IFNET_PLUGIN_NAME, "Found error: %s", (*error)->message); + nm_log_warn (LOGD_SETTINGS, "Found error: %s", (*error)->message); goto error; } /* IPv6 setting */ make_ip6_setting (connection, conn_name, error); if (error && *error) { - PLUGIN_WARN (IFNET_PLUGIN_NAME, "Found error: %s", (*error)->message); + nm_log_warn (LOGD_SETTINGS, "Found error: %s", (*error)->message); goto error; } success = nm_connection_verify (connection, error); if (error && *error) - PLUGIN_WARN (IFNET_PLUGIN_NAME, "Found error: %s", (*error)->message); - PLUGIN_PRINT (IFNET_PLUGIN_NAME, "Connection verified %s:%d", conn_name, success); + nm_log_warn (LOGD_SETTINGS, "Found error: %s", (*error)->message); + else + nm_log_info (LOGD_SETTINGS, "Connection verified %s:%d", conn_name, success); if (!success) goto error; return connection; @@ -1899,10 +1852,8 @@ write_object (NMSetting8021x *s_8021x, } /* does not support writing encryption data now */ - if (blob) { - PLUGIN_WARN (IFNET_PLUGIN_NAME, - " warning: Currently we do not support certs writing."); - } + if (blob) + nm_log_warn (LOGD_SETTINGS, " Currently we do not support cert writing."); return TRUE; } @@ -2031,8 +1982,7 @@ write_8021x_setting (NMConnection *connection, return TRUE; } - PLUGIN_PRINT (IFNET_PLUGIN_NAME, "Adding 8021x setting for %s", - conn_name); + nm_log_info (LOGD_SETTINGS, "Adding 8021x setting for %s", conn_name); /* If wired, write KEY_MGMT */ if (wired) @@ -2149,7 +2099,7 @@ write_wireless_security_setting (NMConnection * connection, wpa_set_data (conn_name, "key_mgmt", "WPA-EAP"); wpa = TRUE; } else - PLUGIN_WARN (IFNET_PLUGIN_NAME, "Unknown key_mgmt: %s", key_mgmt); + nm_log_warn (LOGD_SETTINGS, "Unknown key_mgmt: %s", key_mgmt); if (auth_alg) { if (!strcmp (auth_alg, "shared")) @@ -2342,10 +2292,7 @@ write_wireless_setting (NMConnection *connection, ifnet_set_data (ssid_str, "mac", NULL); mac = nm_setting_wireless_get_mac_address (s_wireless); if (mac) { - tmp = g_strdup_printf ("%02X:%02X:%02X:%02X:%02X:%02X", - mac->data[0], mac->data[1], mac->data[2], - mac->data[3], mac->data[4], - mac->data[5]); + tmp = nm_utils_hwaddr_ntoa_len (mac->data, mac->len); ifnet_set_data (ssid_str, "mac", tmp); g_free (tmp); } @@ -2366,24 +2313,20 @@ write_wireless_setting (NMConnection *connection, wpa_set_data (ssid_str, "mode", "1"); adhoc = TRUE; } else { - PLUGIN_WARN (IFNET_PLUGIN_NAME, - "Invalid mode '%s' in '%s' setting", - mode, NM_SETTING_WIRELESS_SETTING_NAME); + nm_log_warn (LOGD_SETTINGS, "Invalid mode '%s' in '%s' setting", + mode, NM_SETTING_WIRELESS_SETTING_NAME); return FALSE; } wpa_set_data (ssid_str, "bssid", NULL); bssid = nm_setting_wireless_get_bssid (s_wireless); if (bssid) { - tmp = g_strdup_printf ("%02X:%02X:%02X:%02X:%02X:%02X", - bssid->data[0], bssid->data[1], - bssid->data[2], bssid->data[3], - bssid->data[4], bssid->data[5]); + tmp = nm_utils_hwaddr_ntoa_len (bssid->data, bssid->len); wpa_set_data (ssid_str, "bssid", tmp); g_free (tmp); } - if (nm_setting_wireless_get_security (s_wireless)) { + if (nm_connection_get_setting_wireless_security (connection)) { if (!write_wireless_security_setting (connection, ssid_str, adhoc, no_8021x, error)) return FALSE; @@ -2417,10 +2360,7 @@ write_wired_setting (NMConnection *connection, ifnet_set_data (conn_name, "mac", NULL); mac = nm_setting_wired_get_mac_address (s_wired); if (mac) { - tmp = g_strdup_printf ("%02X:%02X:%02X:%02X:%02X:%02X", - mac->data[0], mac->data[1], mac->data[2], - mac->data[3], mac->data[4], - mac->data[5]); + tmp = nm_utils_hwaddr_ntoa_len (mac->data, mac->len); ifnet_set_data (conn_name, "mac", tmp); g_free (tmp); } @@ -2438,14 +2378,6 @@ write_wired_setting (NMConnection *connection, return TRUE; } -static void -write_connection_setting (NMSettingConnection *s_con, const char *conn_name) -{ - ifnet_set_data (conn_name, "auto", - nm_setting_connection_get_autoconnect (s_con) ? "true" : - "false"); -} - static gboolean write_ip4_setting (NMConnection *connection, const char *conn_name, GError **error) { @@ -2819,16 +2751,11 @@ ifnet_update_parsers_by_connection (NMConnection *connection, gboolean wired = FALSE, pppoe = TRUE; const char *new_name = NULL; - s_con = - NM_SETTING_CONNECTION (nm_connection_get_setting - (connection, NM_TYPE_SETTING_CONNECTION)); - if (!s_con) { - g_set_error (error, ifnet_plugin_error_quark (), 0, - "Missing '%s' setting", - NM_SETTING_CONNECTION_SETTING_NAME); + if (!ifnet_can_write_connection (connection, error)) return FALSE; - } + s_con = nm_connection_get_setting_connection (connection); + g_assert (s_con); type = nm_setting_connection_get_connection_type (s_con); if (!type) { @@ -2887,11 +2814,11 @@ ifnet_update_parsers_by_connection (NMConnection *connection, } /* Connection Setting */ - write_connection_setting (s_con, conn_name); - - /* connection id will be displayed in nm-applet */ - update_connection_id (connection, conn_name); + ifnet_set_data (conn_name, "auto", + nm_setting_connection_get_autoconnect (s_con) ? "true" : "false"); + ifnet_set_data (conn_name, "uuid", nm_connection_get_uuid (connection)); + /* Write changes to disk */ success = ifnet_flush_to_file (config_file, out_backup); if (success) wpa_flush_to_file (wpa_file); @@ -2923,6 +2850,66 @@ ifnet_delete_connection_in_parsers (const char *conn_name, return result; } +static void +check_unsupported_secrets (NMSetting *setting, + const char *key, + const GValue *value, + GParamFlags flags, + gpointer user_data) +{ + gboolean *unsupported_secret = user_data; + + if (flags & NM_SETTING_PARAM_SECRET) { + NMSettingSecretFlags secret_flags = NM_SETTING_SECRET_FLAG_NONE; + + nm_setting_get_secret_flags (setting, key, &secret_flags, NULL); + if (secret_flags != NM_SETTING_SECRET_FLAG_NONE) + *unsupported_secret = TRUE; + } +} + +gboolean +ifnet_can_write_connection (NMConnection *connection, GError **error) +{ + NMSettingConnection *s_con; + gboolean has_unsupported_secrets = FALSE; + + s_con = nm_connection_get_setting_connection (connection); + g_assert (s_con); + + /* If the connection is not available for all users, ignore + * it as this plugin only deals with System Connections */ + if (nm_setting_connection_get_num_permissions (s_con)) { + g_set_error_literal (error, IFNET_PLUGIN_ERROR, 0, + "The ifnet plugin does not support non-system-wide connections."); + return FALSE; + } + + /* If the connection has flagged secrets, ignore + * it as this plugin does not deal with user agent service */ + nm_connection_for_each_setting_value (connection, + check_unsupported_secrets, + &has_unsupported_secrets); + if (has_unsupported_secrets) { + g_set_error_literal (error, IFNET_PLUGIN_ERROR, 0, + "The ifnet plugin only supports persistent system secrets."); + return FALSE; + } + + /* Only support wired, wifi, and PPPoE */ + if ( !nm_connection_is_type (connection, NM_SETTING_WIRED_SETTING_NAME) + && !nm_connection_is_type (connection, NM_SETTING_WIRELESS_SETTING_NAME) + && !nm_connection_is_type (connection, NM_SETTING_PPPOE_SETTING_NAME)) { + g_set_error (error, IFNET_PLUGIN_ERROR, 0, + "The ifnet plugin cannot write the connection '%s' (type '%s')", + nm_connection_get_id (connection), + nm_setting_connection_get_connection_type (s_con)); + return FALSE; + } + + return TRUE; +} + /* get the available wired name(eth*). */ static gchar * get_wired_name () @@ -3003,10 +2990,11 @@ get_wireless_name (NMConnection * connection) return result; } -char * +gboolean ifnet_add_new_connection (NMConnection *connection, const char *config_file, const char *wpa_file, + gchar **out_new_name, gchar **out_backup, GError **error) { @@ -3015,12 +3003,15 @@ ifnet_add_new_connection (NMConnection *connection, const char *type; gchar *new_type, *new_name = NULL; + if (!ifnet_can_write_connection (connection, error)) + return FALSE; + s_con = nm_connection_get_setting_connection (connection); g_assert (s_con); type = nm_setting_connection_get_connection_type (s_con); g_assert (type); - PLUGIN_PRINT (IFNET_PLUGIN_NAME, "Adding %s connection", type); + nm_log_info (LOGD_SETTINGS, "Adding %s connection", type); /* get name and type * Wireless type: wireless @@ -3055,11 +3046,14 @@ ifnet_add_new_connection (NMConnection *connection, error); } - PLUGIN_PRINT (IFNET_PLUGIN_NAME, "Added new connection: %s, result: %s", - new_name, success ? "success" : "fail"); + nm_log_info (LOGD_SETTINGS, "Added new connection: %s, result: %s", + new_name, success ? "success" : "fail"); out: - if (!success) + if (!success || !out_new_name) g_free (new_name); - return success ? new_name : NULL; + else if (out_new_name) + *out_new_name = new_name; + return success; } + diff --git a/src/settings/plugins/ifnet/connection_parser.h b/src/settings/plugins/ifnet/connection_parser.h index e8596a64e..74213669d 100644 --- a/src/settings/plugins/ifnet/connection_parser.h +++ b/src/settings/plugins/ifnet/connection_parser.h @@ -24,6 +24,8 @@ #include <nm-connection.h> #include "net_parser.h" +gboolean ifnet_can_write_connection (NMConnection *connection, GError **error); + NMConnection *ifnet_update_connection_from_config_block (const char *conn_name, const char *basepath, GError **error); @@ -42,9 +44,10 @@ gboolean ifnet_delete_connection_in_parsers (const char *conn_name, const char *wpa_file, gchar **out_backup); -char * ifnet_add_new_connection (NMConnection *connection, - const char *config_file, - const char *wpa_file, - gchar **out_backup, - GError ** error); +gboolean ifnet_add_new_connection (NMConnection *connection, + const char *config_file, + const char *wpa_file, + gchar **out_new_name, + gchar **out_backup, + GError ** error); #endif diff --git a/src/settings/plugins/ifnet/errors.c b/src/settings/plugins/ifnet/errors.c new file mode 100644 index 000000000..295db18ba --- /dev/null +++ b/src/settings/plugins/ifnet/errors.c @@ -0,0 +1,35 @@ +/* -*- 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 2013 Red Hat, Inc. + */ + +#include <glib.h> +#include "errors.h" + +GQuark +ifnet_plugin_error_quark (void) +{ + static GQuark error_quark = 0; + + if (G_UNLIKELY (error_quark == 0)) + error_quark = g_quark_from_static_string ("ifnet-plugin-error-quark"); + + return error_quark; +} + + diff --git a/src/settings/plugins/ifnet/errors.h b/src/settings/plugins/ifnet/errors.h new file mode 100644 index 000000000..52517d007 --- /dev/null +++ b/src/settings/plugins/ifnet/errors.h @@ -0,0 +1,30 @@ +/* -*- 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 2013 Red Hat, Inc. + */ + +#ifndef __ERRORS_H__ +#define __ERRORS_H__ + +#include <glib.h> + +#define IFNET_PLUGIN_ERROR (ifnet_plugin_error_quark ()) +GQuark ifnet_plugin_error_quark (void); + +#endif /* __ERRORS_H__ */ + diff --git a/src/settings/plugins/ifnet/net_parser.c b/src/settings/plugins/ifnet/net_parser.c index f37366afe..95add14fc 100644 --- a/src/settings/plugins/ifnet/net_parser.c +++ b/src/settings/plugins/ifnet/net_parser.c @@ -20,15 +20,15 @@ */ #include <string.h> -#include <nm-system-config-interface.h> #include <stdio.h> - #include <sys/ioctl.h> -#include <net/if.h> #include <unistd.h> +#include <nm-system-config-interface.h> +#include <nm-logging.h> + #include "plugin.h" -#include "wifi-utils.h" +#include "nm-platform.h" #include "net_parser.h" #include "net_utils.h" @@ -71,7 +71,7 @@ ifnet_add_network (const char *name, const char *type) if (ifnet_has_network (name)) return TRUE; if (add_new_connection_config (type, name)) { - PLUGIN_PRINT (IFNET_PLUGIN_NAME, "Adding network for %s", name); + nm_log_info (LOGD_SETTINGS, "Adding network for %s", name); net_parser_data_changed = TRUE; return TRUE; } @@ -129,24 +129,6 @@ is_global_setting (char *key) return 0; } -/* Find out whether the 'iface' is an interface */ -static gboolean -name_is_interface (const char *iface) -{ - int fd; - struct ifreq ifr; - gboolean is_iface = FALSE; - - fd = socket (PF_INET, SOCK_DGRAM, 0); - if (fd >= 0) { - strncpy (ifr.ifr_name, iface, IFNAMSIZ); - if (ioctl (fd, SIOCGIFHWADDR, &ifr) == 0) - is_iface = TRUE; - close (fd); - } - return is_iface; -} - /* Parse a complete line */ /* Connection type is determined here */ static void @@ -160,8 +142,7 @@ init_block_by_line (gchar * buf) key_value = g_strsplit (buf, "=", 2); if (g_strv_length (key_value) != 2) { - PLUGIN_WARN (IFNET_PLUGIN_NAME, "Can't handle this line: %s\n", - buf); + nm_log_warn (LOGD_SETTINGS, "Can't handle this line: %s\n", buf); g_strfreev (key_value); return; } @@ -171,7 +152,7 @@ init_block_by_line (gchar * buf) data = g_strdup (key_value[1]); tmp = strip_string (data, '"'); strip_string (tmp, '\''); - PLUGIN_PRINT (IFNET_PLUGIN_NAME, "global:%s-%s\n", key_value[0], tmp); + nm_log_info (LOGD_SETTINGS, "global:%s-%s\n", key_value[0], tmp); g_hash_table_insert (global_settings_table, g_strdup (key_value[0]), g_strdup (tmp)); g_strfreev (key_value); g_free (data); @@ -190,13 +171,16 @@ init_block_by_line (gchar * buf) else if (ignore_connection_name (pos)) { /* ignored connection */ conn = add_new_connection_config ("ignore", pos); - } else - if (name_is_interface (pos) && !wifi_utils_is_wifi (pos, NULL)) + } else { + int ifindex = nm_platform_link_get_ifindex (pos); + + if (ifindex && nm_platform_link_get_type (ifindex) != NM_LINK_TYPE_WIFI) /* wired connection */ conn = add_new_connection_config ("wired", pos); else /* wireless connection */ conn = add_new_connection_config ("wireless", pos); + } } data = g_strdup (key_value[1]); tmp = strip_string (data, '"'); @@ -223,34 +207,6 @@ destroy_connection_config (GHashTable * conn) g_hash_table_destroy (conn); } -/* Read settings from NetworkManager's config file */ -const char * -ifnet_get_global_setting (const char *group, const char *key) -{ - GError *error = NULL; - GKeyFile *keyfile = g_key_file_new (); - gchar *result = NULL; - const char *conf_file; - - /* Get confing file name from plugin. */ - conf_file = ifnet_plugin_get_conf_file (); - - if (!g_key_file_load_from_file (keyfile, - conf_file, - G_KEY_FILE_NONE, &error)) { - PLUGIN_WARN (IFNET_PLUGIN_NAME, - "loading system config file (%s) caused error: (%d) %s", - conf_file, - error ? error->code : -1, error - && error->message ? error->message : "(unknown)"); - } else { - result = g_key_file_get_string (keyfile, group, key, &error); - } - g_key_file_free (keyfile); - - return result; -} - static void strip_function (GIOChannel * channel, gchar * line) { @@ -308,8 +264,7 @@ is_function (gchar * line) for (i = 0; func_names[i]; i++) { if (g_str_has_prefix (line, func_names[i])) { - PLUGIN_PRINT (IFNET_PLUGIN_NAME, - "Ignoring function: %s", func_names[i]); + nm_log_info (LOGD_SETTINGS, "Ignoring function: %s", func_names[i]); return TRUE; } } @@ -353,8 +308,7 @@ ifnet_init (gchar * config_file) if (g_file_test (config_file, G_FILE_TEST_IS_REGULAR)) channel = g_io_channel_new_file (config_file, "r", NULL); if (channel == NULL) { - PLUGIN_WARN (IFNET_PLUGIN_NAME, - "Error: Can't open %s\n", config_file); + nm_log_warn (LOGD_SETTINGS, "Can't open %s", config_file); return FALSE; } @@ -483,7 +437,7 @@ ifnet_set_data (const char *conn_name, const char *key, const char *value) gchar * stripped = NULL; if (!conn) { - PLUGIN_WARN (IFNET_PLUGIN_NAME, "%s does not exsit!", conn_name); + nm_log_warn (LOGD_SETTINGS, "%s does not exist!", conn_name); return; } if (value){ @@ -611,13 +565,12 @@ ifnet_flush_to_file (const char *config_file, gchar **out_backup) channel = g_io_channel_new_file (config_file, "w", NULL); if (!channel) { - PLUGIN_WARN (IFNET_PLUGIN_NAME, - "Can't open file %s for writing", config_file); + nm_log_warn (LOGD_SETTINGS, "Can't open file %s for writing", config_file); g_free (backup); return FALSE; } g_hash_table_iter_init (&iter, global_settings_table); - PLUGIN_PRINT (IFNET_PLUGIN_NAME, "Writing to %s", config_file); + nm_log_info (LOGD_SETTINGS, "Writing to %s", config_file); g_io_channel_write_chars (channel, "#Generated by NetworkManager\n" "###### Global Configuration ######\n", @@ -633,8 +586,7 @@ ifnet_flush_to_file (const char *config_file, gchar **out_backup) g_free (out_line); } if (error && *error) { - PLUGIN_WARN (IFNET_PLUGIN_NAME, - "Found error: %s", (*error)->message); + nm_log_warn (LOGD_SETTINGS, "Found error: %s", (*error)->message); goto done; } @@ -680,8 +632,7 @@ ifnet_flush_to_file (const char *config_file, gchar **out_backup) } } if (error && *error) { - PLUGIN_WARN (IFNET_PLUGIN_NAME, - "Found error: %s", (*error)->message); + nm_log_warn (LOGD_SETTINGS, "Found error: %s", (*error)->message); goto done; } @@ -702,16 +653,14 @@ ifnet_flush_to_file (const char *config_file, gchar **out_backup) g_free (out_line); } if (error && *error) { - PLUGIN_WARN (IFNET_PLUGIN_NAME, - "Found error: %s", (*error)->message); + nm_log_warn (LOGD_SETTINGS, "Found error: %s", (*error)->message); goto done; } } g_io_channel_flush (channel, error); if (error && *error) { - PLUGIN_WARN (IFNET_PLUGIN_NAME, - "Found error: %s", (*error)->message); + nm_log_warn (LOGD_SETTINGS, "Found error: %s", (*error)->message); goto done; } result = TRUE; @@ -734,7 +683,7 @@ ifnet_delete_network (const char *conn_name) GHashTable *network = NULL; g_return_val_if_fail (conn_table != NULL && conn_name != NULL, FALSE); - PLUGIN_PRINT (IFNET_PLUGIN_NAME, "Deleting network for %s", conn_name); + nm_log_info (LOGD_SETTINGS, "Deleting network for %s", conn_name); network = g_hash_table_lookup (conn_table, conn_name); if (!network) return FALSE; diff --git a/src/settings/plugins/ifnet/net_parser.h b/src/settings/plugins/ifnet/net_parser.h index 47086c762..005207adf 100644 --- a/src/settings/plugins/ifnet/net_parser.h +++ b/src/settings/plugins/ifnet/net_parser.h @@ -34,7 +34,6 @@ void ifnet_destroy (void); GList *ifnet_get_connection_names (void); const char *ifnet_get_data (const char *conn_name, const char *key); const char *ifnet_get_global_data (const char *key); -const char *ifnet_get_global_setting (const char *group, const char *key); gboolean ifnet_has_network (const char *conn_name); /* Writer functions */ diff --git a/src/settings/plugins/ifnet/net_utils.c b/src/settings/plugins/ifnet/net_utils.c index 17eb16771..86ab8537d 100644 --- a/src/settings/plugins/ifnet/net_utils.c +++ b/src/settings/plugins/ifnet/net_utils.c @@ -25,6 +25,8 @@ #include <errno.h> #include <nm-utils.h> #include <nm-system-config-interface.h> +#include <nm-logging.h> +#include <nm-config.h> #include <gio/gio.h> #include "net_utils.h" #include "wpa_parser.h" @@ -94,99 +96,6 @@ is_true (const char *str) return FALSE; } -static int -hex2num (char c) -{ - if (c >= '0' && c <= '9') - return c - '0'; - if (c >= 'a' && c <= 'f') - return c - 'a' + 10; - if (c >= 'A' && c <= 'F') - return c - 'A' + 10; - return -1; -} - -static int -hex2byte (const char *hex) -{ - int a, b; - - a = hex2num (*hex++); - if (a < 0) - return -1; - b = hex2num (*hex++); - if (b < 0) - return -1; - return (a << 4) | b; -} - -/* free return value by caller */ -gchar * -utils_hexstr2bin (const gchar * hex, size_t len) -{ - size_t i; - int a; - const gchar *ipos = hex; - gchar *buf = NULL; - gchar *opos; - - /* Length must be a multiple of 2 */ - if ((len % 2) != 0) - return NULL; - - opos = buf = g_malloc0 ((len / 2) + 1); - for (i = 0; i < len; i += 2) { - a = hex2byte (ipos); - if (a < 0) { - g_free (buf); - return NULL; - } - *opos++ = a; - ipos += 2; - } - return buf; -} - -/* free return value by caller */ -gchar * -utils_bin2hexstr (const gchar * bytes, int len, int final_len) -{ - static gchar hex_digits[] = "0123456789abcdef"; - gchar *result; - int i; - gsize buflen = (len * 2) + 1; - - g_return_val_if_fail (bytes != NULL, NULL); - g_return_val_if_fail (len > 0, NULL); - g_return_val_if_fail (len < 4096, NULL); /* Arbitrary limit */ - if (final_len > -1) - g_return_val_if_fail (final_len < buflen, NULL); - - result = g_malloc0 (buflen); - for (i = 0; i < len; i++) { - result[2 * i] = hex_digits[(bytes[i] >> 4) & 0xf]; - result[2 * i + 1] = hex_digits[bytes[i] & 0xf]; - } - /* Cut converted key off at the correct length for this cipher type */ - if (final_len > -1) - result[final_len] = '\0'; - else - result[buflen - 1] = '\0'; - - return result; -} - -GQuark -ifnet_plugin_error_quark (void) -{ - static GQuark error_quark = 0; - - if (G_UNLIKELY (error_quark == 0)) - error_quark = - g_quark_from_static_string ("ifnet-plugin-error-quark"); - return error_quark; -} - static char * find_default_gateway_str (char *str) { @@ -445,7 +354,7 @@ static ip_block * create_ip4_block (gchar * ip) { ip_block *iblock = g_slice_new0 (ip_block); - struct in_addr tmp_ip4_addr; + guint32 tmp_ip4_addr; int i; guint length; gchar **ip_mask; @@ -458,7 +367,7 @@ create_ip4_block (gchar * ip) length = g_strv_length (ip_mask); if (!inet_pton (AF_INET, ip_mask[0], &tmp_ip4_addr)) goto error; - iblock->ip = tmp_ip4_addr.s_addr; + iblock->ip = tmp_ip4_addr; prefix = ip_mask[1]; i = 0; while (i < length && g_ascii_isdigit (prefix[i])) @@ -472,7 +381,7 @@ create_ip4_block (gchar * ip) length = g_strv_length (ip_mask); if (!inet_pton (AF_INET, ip_mask[0], &tmp_ip4_addr)) goto error; - iblock->ip = tmp_ip4_addr.s_addr; + iblock->ip = tmp_ip4_addr; i = 0; while (i < length && !strstr (ip_mask[++i], "netmask")) ; while (i < length && ip_mask[++i][0] == '\0') ; @@ -480,21 +389,18 @@ create_ip4_block (gchar * ip) goto error; if (!inet_pton (AF_INET, ip_mask[i], &tmp_ip4_addr)) goto error; - iblock->netmask = tmp_ip4_addr.s_addr; + iblock->netmask = tmp_ip4_addr; } else { g_slice_free (ip_block, iblock); if (!is_ip6_address (ip) && !strstr (ip, "dhcp")) - PLUGIN_WARN (IFNET_PLUGIN_NAME, - "Can't handle ipv4 address: %s, missing netmask or prefix", - ip); + nm_log_warn (LOGD_SETTINGS, "Can't handle ipv4 address: %s, missing netmask or prefix", ip); return NULL; } g_strfreev (ip_mask); return iblock; error: if (!is_ip6_address (ip)) - PLUGIN_WARN (IFNET_PLUGIN_NAME, "Can't handle IPv4 address: %s", - ip); + nm_log_warn (LOGD_SETTINGS, "Can't handle IPv4 address: %s", ip); g_strfreev (ip_mask); g_slice_free (ip_block, iblock); return NULL; @@ -528,8 +434,7 @@ create_ip6_block (gchar * ip) return iblock; error: if (!is_ip4_address (ip)) - PLUGIN_WARN (IFNET_PLUGIN_NAME, "Can't handle IPv6 address: %s", - ip); + nm_log_warn (LOGD_SETTINGS, "Can't handle IPv6 address: %s", ip); g_slice_free (ip6_block, iblock); g_slice_free (struct in6_addr, tmp_ip6_addr); @@ -541,14 +446,13 @@ static guint32 get_ip4_gateway (gchar * gateway) { gchar *tmp, *split; - struct in_addr tmp_ip4_addr; + guint32 tmp_ip4_addr; if (!gateway) return 0; tmp = find_gateway_str (gateway); if (!tmp) { - PLUGIN_WARN (IFNET_PLUGIN_NAME, - "Couldn't obtain gateway in \"%s\"", gateway); + nm_log_warn (LOGD_SETTINGS, "Couldn't obtain gateway in \"%s\"", gateway); return 0; } tmp = g_strdup (tmp); @@ -562,11 +466,10 @@ get_ip4_gateway (gchar * gateway) if (!inet_pton (AF_INET, tmp, &tmp_ip4_addr)) goto error; g_free (tmp); - return tmp_ip4_addr.s_addr; + return tmp_ip4_addr; error: if (!is_ip6_address (tmp)) - PLUGIN_WARN (IFNET_PLUGIN_NAME, "Can't handle IPv4 gateway: %s", - tmp); + nm_log_warn (LOGD_SETTINGS, "Can't handle IPv4 gateway: %s", tmp); g_free (tmp); return 0; } @@ -581,8 +484,7 @@ get_ip6_next_hop (gchar * next_hop) return 0; tmp = find_gateway_str (next_hop); if (!tmp) { - PLUGIN_WARN (IFNET_PLUGIN_NAME, - "Couldn't obtain next_hop in \"%s\"", next_hop); + nm_log_warn (LOGD_SETTINGS, "Couldn't obtain next_hop in \"%s\"", next_hop); return 0; } tmp = g_strdup (tmp); @@ -595,8 +497,7 @@ get_ip6_next_hop (gchar * next_hop) return tmp_ip6_addr; error: if (!is_ip4_address (tmp)) - PLUGIN_WARN (IFNET_PLUGIN_NAME, - "Can't handle IPv6 next_hop: %s", tmp); + nm_log_warn (LOGD_SETTINGS, "Can't handle IPv6 next_hop: %s", tmp); g_free (tmp); g_slice_free (struct in6_addr, tmp_ip6_addr); @@ -780,7 +681,7 @@ set_ip4_dns_servers (NMSettingIP4Config *s_ip4, const char *conn_name) const char *dns_servers; gchar **server_list, *stripped; guint length, i; - struct in_addr tmp_ip4_addr; + guint32 tmp_ip4_addr; guint32 new_dns; dns_servers = ifnet_get_data (conn_name, "dns_servers"); @@ -801,16 +702,12 @@ set_ip4_dns_servers (NMSettingIP4Config *s_ip4, const char *conn_name) continue; if (!inet_pton (AF_INET, server_list[i], &tmp_ip4_addr)) { if (!is_ip6_address (server_list[i])) - PLUGIN_WARN (IFNET_PLUGIN_NAME, - "ignored dns: %s\n", - server_list[i]); + nm_log_warn (LOGD_SETTINGS, "ignored dns: %s\n", server_list[i]); continue; } - new_dns = tmp_ip4_addr.s_addr; + new_dns = tmp_ip4_addr; if (new_dns && !nm_setting_ip4_config_add_dns (s_ip4, new_dns)) - PLUGIN_WARN (IFNET_PLUGIN_NAME, - "warning: duplicate DNS server %s", - server_list[i]); + nm_log_warn (LOGD_SETTINGS, "warning: duplicate DNS server %s", server_list[i]); } g_strfreev (server_list); } @@ -842,16 +739,12 @@ set_ip6_dns_servers (NMSettingIP6Config *s_ip6, const char *conn_name) continue; if (!inet_pton (AF_INET6, server_list[i], &tmp_ip6_addr)) { if (is_ip6_address (server_list[i])) - PLUGIN_WARN (IFNET_PLUGIN_NAME, - "ignored dns: %s\n", - server_list[i]); + nm_log_warn (LOGD_SETTINGS, "ignored dns: %s\n", server_list[i]); continue; } if (!IN6_IS_ADDR_UNSPECIFIED (&tmp_ip6_addr) && !nm_setting_ip6_config_add_dns (s_ip6, &tmp_ip6_addr)) - PLUGIN_WARN (IFNET_PLUGIN_NAME, - "warning: duplicate DNS server %s", - server_list[i]); + nm_log_warn (LOGD_SETTINGS, "warning: duplicate DNS server %s", server_list[i]); } g_strfreev (server_list); } @@ -882,7 +775,7 @@ get_dhcp_hostname_and_client_id (char **hostname, char **client_id) *hostname = NULL; *client_id = NULL; - dhcp_client = ifnet_get_global_setting ("main", "dhcp"); + dhcp_client = nm_config_get_dhcp_client (nm_config_get ()); if (dhcp_client) { if (!strcmp (dhcp_client, "dhclient")) g_file_get_contents (dhclient_conf, &contents, NULL, @@ -912,16 +805,14 @@ get_dhcp_hostname_and_client_id (char **hostname, char **client_id) if (tmp[0] != '\0') *hostname = g_strdup (tmp); else - PLUGIN_PRINT (IFNET_PLUGIN_NAME, - "dhcpcd hostname not defined, ignoring"); + nm_log_info (LOGD_SETTINGS, "dhcpcd hostname not defined, ignoring"); } else if (g_str_has_prefix (line, "clientid")) { tmp = line + strlen ("clientid"); g_strstrip (tmp); if (tmp[0] != '\0') *client_id = g_strdup (tmp); else - PLUGIN_PRINT (IFNET_PLUGIN_NAME, - "dhcpcd clientid not defined, ignoring"); + nm_log_info (LOGD_SETTINGS, "dhcpcd clientid not defined, ignoring"); } // dhclient.conf else if ((tmp = strstr (line, "send host-name")) != NULL) { @@ -932,8 +823,7 @@ get_dhcp_hostname_and_client_id (char **hostname, char **client_id) if (tmp[0] != '\0') *hostname = g_strdup (tmp); else - PLUGIN_PRINT (IFNET_PLUGIN_NAME, - "dhclient hostname not defined, ignoring"); + nm_log_info (LOGD_SETTINGS, "dhclient hostname not defined, ignoring"); } else if ((tmp = strstr (line, "send dhcp-client-identifier")) != NULL) { tmp += strlen ("send dhcp-client-identifier"); @@ -942,8 +832,7 @@ get_dhcp_hostname_and_client_id (char **hostname, char **client_id) if (tmp[0] != '\0') *client_id = g_strdup (tmp); else - PLUGIN_PRINT (IFNET_PLUGIN_NAME, - "dhclient clientid not defined, ignoring"); + nm_log_info (LOGD_SETTINGS, "dhclient clientid not defined, ignoring"); } } g_strfreev (all_lines); @@ -962,7 +851,7 @@ gchar *backup_file (const gchar* target) g_file_copy (source, backup, G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, error); if (error && *error) { - PLUGIN_WARN (IFNET_PLUGIN_NAME, "Backup failed: %s", (*error)->message); + nm_log_warn (LOGD_SETTINGS, "Backup failed: %s", (*error)->message); g_free (backup_path); backup_path = NULL; } diff --git a/src/settings/plugins/ifnet/net_utils.h b/src/settings/plugins/ifnet/net_utils.h index c2ed83a13..cee71d57e 100644 --- a/src/settings/plugins/ifnet/net_utils.h +++ b/src/settings/plugins/ifnet/net_utils.h @@ -67,10 +67,6 @@ void set_ip6_dns_servers (NMSettingIP6Config * s_ip6, const char *conn_name); gchar *strip_string (gchar *str, gchar t); gboolean is_managed (const char *conn_name); -GQuark ifnet_plugin_error_quark (void); -gchar *utils_hexstr2bin (const gchar * hex, size_t len); -gchar *utils_bin2hexstr (const gchar * bytes, int len, int final_len); - gboolean is_hex (const char *value); gboolean is_ascii (const char *value); gboolean is_true (const char *str); diff --git a/src/settings/plugins/ifnet/nm-ifnet-connection.c b/src/settings/plugins/ifnet/nm-ifnet-connection.c index 873a62ecd..478d6e32e 100644 --- a/src/settings/plugins/ifnet/nm-ifnet-connection.c +++ b/src/settings/plugins/ifnet/nm-ifnet-connection.c @@ -26,6 +26,7 @@ #include <nm-setting-wireless-security.h> #include <nm-settings-connection.h> #include <nm-system-config-interface.h> +#include <nm-logging.h> #include <nm-settings-error.h> #include "nm-ifnet-connection.h" #include "connection_parser.h" @@ -37,11 +38,6 @@ G_DEFINE_TYPE (NMIfnetConnection, nm_ifnet_connection, NM_TYPE_SETTINGS_CONNECTION) #define NM_IFNET_CONNECTION_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_IFNET_CONNECTION, NMIfnetConnectionPrivate)) -enum { - PROP_ZERO, - PROP_CONN_NAME, - _PROP_END, -}; enum { IFNET_SETUP_MONITORS, @@ -57,32 +53,35 @@ typedef struct { } NMIfnetConnectionPrivate; NMIfnetConnection * -nm_ifnet_connection_new (const char *conn_name, NMConnection *source) +nm_ifnet_connection_new (NMConnection *source, const char *conn_name) { NMConnection *tmp; GObject *object; GError *error = NULL; + gboolean update_unsaved = TRUE; - g_return_val_if_fail (conn_name != NULL, NULL); + g_return_val_if_fail (source || conn_name, NULL); if (source) tmp = g_object_ref (source); else { tmp = ifnet_update_connection_from_config_block (conn_name, NULL, &error); - if (!tmp){ + if (!tmp) { g_error_free (error); return NULL; } - } - object = (GObject *) g_object_new (NM_TYPE_IFNET_CONNECTION, NULL); - if (!object) { - g_object_unref (tmp); - return NULL; + /* If we just read the connection from disk, it's clearly not Unsaved */ + update_unsaved = FALSE; } + object = (GObject *) g_object_new (NM_TYPE_IFNET_CONNECTION, NULL); + g_assert (object); NM_IFNET_CONNECTION_GET_PRIVATE (object)->conn_name = g_strdup (conn_name); - nm_settings_connection_replace_settings (NM_SETTINGS_CONNECTION (object), tmp, NULL); + nm_settings_connection_replace_settings (NM_SETTINGS_CONNECTION (object), + tmp, + update_unsaved, + NULL); g_object_unref (tmp); return NM_IFNET_CONNECTION (object); @@ -93,6 +92,12 @@ nm_ifnet_connection_init (NMIfnetConnection * connection) { } +const char * +nm_ifnet_connection_get_conn_name (NMIfnetConnection *connection) +{ + return NM_IFNET_CONNECTION_GET_PRIVATE (connection)->conn_name; +} + static void commit_changes (NMSettingsConnection *connection, NMSettingsConnectionCommitFunc callback, @@ -101,29 +106,48 @@ commit_changes (NMSettingsConnection *connection, GError *error = NULL; NMIfnetConnectionPrivate *priv = NM_IFNET_CONNECTION_GET_PRIVATE (connection); gchar *new_name = NULL; + gboolean success = FALSE; g_signal_emit (connection, signals[IFNET_CANCEL_MONITORS], 0); - if (!ifnet_update_parsers_by_connection (NM_CONNECTION (connection), - priv->conn_name, - CONF_NET_FILE, - WPA_SUPPLICANT_CONF, - &new_name, - NULL, - &error)) { - PLUGIN_PRINT (IFNET_PLUGIN_NAME, "Failed to update %s", priv->conn_name); + + if (priv->conn_name) { + /* Existing connection; update it */ + success = ifnet_update_parsers_by_connection (NM_CONNECTION (connection), + priv->conn_name, + CONF_NET_FILE, + WPA_SUPPLICANT_CONF, + &new_name, + NULL, + &error); + } else { + /* New connection, add it */ + success = ifnet_add_new_connection (NM_CONNECTION (connection), + CONF_NET_FILE, + WPA_SUPPLICANT_CONF, + &new_name, + NULL, + &error); + if (success) + reload_parsers (); + } + + if (success) { + /* update connection name */ + g_assert (new_name); + g_free (priv->conn_name); + priv->conn_name = new_name; + + NM_SETTINGS_CONNECTION_CLASS (nm_ifnet_connection_parent_class)->commit_changes (connection, callback, user_data); + nm_log_info (LOGD_SETTINGS, "Successfully updated %s", priv->conn_name); + } else { + nm_log_warn (LOGD_SETTINGS, "Failed to update %s", + priv->conn_name ? priv->conn_name : + nm_connection_get_id (NM_CONNECTION (connection))); reload_parsers (); callback (connection, error, user_data); g_error_free (error); - g_signal_emit (connection, signals[IFNET_SETUP_MONITORS], 0); - return; } - g_free (priv->conn_name); - priv->conn_name = new_name; - - NM_SETTINGS_CONNECTION_CLASS (nm_ifnet_connection_parent_class)->commit_changes (connection, callback, user_data); - PLUGIN_PRINT (IFNET_PLUGIN_NAME, "Successfully updated %s", priv->conn_name); - g_signal_emit (connection, signals[IFNET_SETUP_MONITORS], 0); } @@ -136,31 +160,32 @@ do_delete (NMSettingsConnection *connection, NMIfnetConnectionPrivate *priv = NM_IFNET_CONNECTION_GET_PRIVATE (connection); g_signal_emit (connection, signals[IFNET_CANCEL_MONITORS], 0); - if (!ifnet_delete_connection_in_parsers (priv->conn_name, CONF_NET_FILE, WPA_SUPPLICANT_CONF, NULL)) { - PLUGIN_PRINT (IFNET_PLUGIN_NAME, "Failed to delete %s", - priv->conn_name); - reload_parsers (); - callback (connection, error, user_data); - g_error_free (error); - g_signal_emit (connection, signals[IFNET_SETUP_MONITORS], 0); - return; + + /* Only connections which exist in /etc/conf.d/net will have a conn_name */ + if (priv->conn_name) { + if (!ifnet_delete_connection_in_parsers (priv->conn_name, CONF_NET_FILE, WPA_SUPPLICANT_CONF, NULL)) { + nm_log_warn (LOGD_SETTINGS, "Failed to delete %s", priv->conn_name); + reload_parsers (); + callback (connection, error, user_data); + g_error_free (error); + g_signal_emit (connection, signals[IFNET_SETUP_MONITORS], 0); + return; + } } NM_SETTINGS_CONNECTION_CLASS (nm_ifnet_connection_parent_class)->delete (connection, callback, user_data); - PLUGIN_PRINT (IFNET_PLUGIN_NAME, "Successfully deleted %s", - priv->conn_name); g_signal_emit (connection, signals[IFNET_SETUP_MONITORS], 0); + + nm_log_info (LOGD_SETTINGS, "Successfully deleted %s", + priv->conn_name ? priv->conn_name : + nm_connection_get_id (NM_CONNECTION (connection))); } static void finalize (GObject * object) { - NMIfnetConnectionPrivate *priv = - NM_IFNET_CONNECTION_GET_PRIVATE (object); - g_return_if_fail (priv); - - g_free (priv->conn_name); + g_free (NM_IFNET_CONNECTION_GET_PRIVATE (object)->conn_name); G_OBJECT_CLASS (nm_ifnet_connection_parent_class)->finalize (object); } @@ -170,8 +195,7 @@ nm_ifnet_connection_class_init (NMIfnetConnectionClass * ifnet_connection_class) GObjectClass *object_class = G_OBJECT_CLASS (ifnet_connection_class); NMSettingsConnectionClass *settings_class = NM_SETTINGS_CONNECTION_CLASS (ifnet_connection_class); - g_type_class_add_private (ifnet_connection_class, - sizeof (NMIfnetConnectionPrivate)); + g_type_class_add_private (ifnet_connection_class, sizeof (NMIfnetConnectionPrivate)); object_class->finalize = finalize; settings_class->delete = do_delete; diff --git a/src/settings/plugins/ifnet/nm-ifnet-connection.h b/src/settings/plugins/ifnet/nm-ifnet-connection.h index 0647a94db..1cb67c341 100644 --- a/src/settings/plugins/ifnet/nm-ifnet-connection.h +++ b/src/settings/plugins/ifnet/nm-ifnet-connection.h @@ -44,8 +44,10 @@ typedef struct { GType nm_ifnet_connection_get_type (void); -NMIfnetConnection *nm_ifnet_connection_new (const char *conn_name, - NMConnection *source); +NMIfnetConnection *nm_ifnet_connection_new (NMConnection *source, + const char *conn_name); + +const char *nm_ifnet_connection_get_conn_name (NMIfnetConnection *connection); G_END_DECLS #endif /* NM_IFNET_CONNECTION_H */ diff --git a/src/settings/plugins/ifnet/plugin.c b/src/settings/plugins/ifnet/plugin.c index 5100ad3e4..ab07b8d62 100644 --- a/src/settings/plugins/ifnet/plugin.c +++ b/src/settings/plugins/ifnet/plugin.c @@ -31,7 +31,9 @@ #include "NetworkManager.h" #include "nm-system-config-interface.h" +#include "nm-logging.h" #include "nm-ifnet-connection.h" +#include "nm-config.h" #include "plugin.h" #include "net_utils.h" @@ -46,9 +48,8 @@ #define IFNET_KEY_FILE_KEY_MANAGED "managed" typedef struct { - GHashTable *config_connections; + GHashTable *connections; /* uuid::connection */ gchar *hostname; - char *conf_file; gboolean unmanaged_well_known; GFileMonitor *hostname_monitor; @@ -66,7 +67,7 @@ typedef struct { static void system_config_interface_init (NMSystemConfigInterface *class); -static void reload_connections (gpointer config); +static void reload_connections (NMSystemConfigInterface *config); G_DEFINE_TYPE_EXTENDED (SCPluginIfnet, sc_plugin_ifnet, G_TYPE_OBJECT, 0, G_IMPLEMENT_INTERFACE (NM_TYPE_SYSTEM_CONFIG_INTERFACE, system_config_interface_init)) @@ -95,8 +96,7 @@ update_system_hostname (gpointer config) g_object_notify (G_OBJECT (config), NM_SYSTEM_CONFIG_INTERFACE_HOSTNAME); - PLUGIN_PRINT (IFNET_PLUGIN_NAME, "Hostname updated to: %s", - priv->hostname); + nm_log_info (LOGD_SETTINGS, "Hostname updated to: %s", priv->hostname); } static void @@ -106,26 +106,29 @@ write_system_hostname (NMSystemConfigInterface * config, SCPluginIfnetPrivate *priv = SC_PLUGIN_IFNET_GET_PRIVATE (config); g_return_if_fail (newhostname); - PLUGIN_PRINT (IFNET_PLUGIN_NAME, "Write system hostname: %s", - newhostname); + nm_log_info (LOGD_SETTINGS, "Write system hostname: %s", newhostname); if (write_hostname (IFNET_SYSTEM_HOSTNAME_FILE, newhostname)) { g_free (priv->hostname); priv->hostname = g_strdup (newhostname); g_object_notify (G_OBJECT (config), NM_SYSTEM_CONFIG_INTERFACE_HOSTNAME); } else - PLUGIN_WARN (IFNET_PLUGIN_NAME, - "Write system hostname: %s failed", newhostname); + nm_log_warn (LOGD_SETTINGS, "Write system hostname: %s failed", newhostname); } static gboolean -is_managed_plugin () +is_managed_plugin (void) { - const char *result = NULL; - - result = ifnet_get_global_setting (IFNET_KEY_FILE_GROUP, IFNET_KEY_FILE_KEY_MANAGED); - if (result) - return is_true (result); + char *result = NULL; + + result = nm_config_get_value (nm_config_get (), + IFNET_KEY_FILE_GROUP, IFNET_KEY_FILE_KEY_MANAGED, + NULL); + if (result) { + gboolean ret = is_true (result); + g_free (result); + return ret; + } return IFNET_MANAGE_WELL_KNOWN_DEFAULT; } @@ -170,30 +173,12 @@ monitor_file_changes (const char *filename, info); g_signal_connect (monitor, "changed", G_CALLBACK (file_changed), info); - } else - PLUGIN_WARN (IFNET_PLUGIN_NAME, - "Monitoring %s failed, error: %s", filename, - error == NULL ? "nothing" : (*error)->message); - - return monitor; -} - -/* Callback for nm_settings_connection_replace_and_commit. Report any errors - * encountered when commiting connection settings updates. */ -static void -commit_cb (NMSettingsConnection *connection, GError *error, gpointer unused) -{ - if (error) { - PLUGIN_WARN (IFNET_PLUGIN_NAME, " error updating: %s", - (error && error->message) ? error->message : "(unknown)"); } else { - NMSettingConnection *s_con; - - s_con = nm_connection_get_setting_connection (NM_CONNECTION (connection)); - g_assert (s_con); - PLUGIN_PRINT (IFNET_PLUGIN_NAME, "Connection %s updated", - nm_setting_connection_get_id (s_con)); + nm_log_warn (LOGD_SETTINGS, "Monitoring %s failed, error: %s", filename, + error == NULL ? "nothing" : (*error)->message); } + + return monitor; } static void @@ -204,12 +189,15 @@ setup_monitors (NMIfnetConnection * connection, gpointer user_data) priv->hostname_monitor = monitor_file_changes (IFNET_SYSTEM_HOSTNAME_FILE, - update_system_hostname, user_data); - priv->net_monitor = - monitor_file_changes (CONF_NET_FILE, reload_connections, user_data); - priv->wpa_monitor = - monitor_file_changes (WPA_SUPPLICANT_CONF, reload_connections, - user_data); + update_system_hostname, user_data); + if (nm_config_get_monitor_connection_files (nm_config_get ())) { + priv->net_monitor = + monitor_file_changes (CONF_NET_FILE, (FileChangedFn) reload_connections, + user_data); + priv->wpa_monitor = + monitor_file_changes (WPA_SUPPLICANT_CONF, (FileChangedFn) reload_connections, + user_data); + } } static void @@ -233,17 +221,38 @@ cancel_monitors (NMIfnetConnection * connection, gpointer user_data) } static void -reload_connections (gpointer config) +connection_removed_cb (NMSettingsConnection *obj, gpointer user_data) +{ + g_hash_table_remove (SC_PLUGIN_IFNET_GET_PRIVATE (user_data)->connections, + nm_connection_get_uuid (NM_CONNECTION (obj))); +} + +static void +track_new_connection (SCPluginIfnet *self, NMIfnetConnection *connection) +{ + g_hash_table_insert (SC_PLUGIN_IFNET_GET_PRIVATE (self)->connections, + g_strdup (nm_connection_get_uuid (NM_CONNECTION (connection))), + g_object_ref (connection)); + g_signal_connect (connection, NM_SETTINGS_CONNECTION_REMOVED, + G_CALLBACK (connection_removed_cb), + self); +} + +static void +reload_connections (NMSystemConfigInterface *config) { SCPluginIfnet *self = SC_PLUGIN_IFNET (config); SCPluginIfnetPrivate *priv = SC_PLUGIN_IFNET_GET_PRIVATE (self); GList *conn_names = NULL, *n_iter = NULL; + gboolean auto_refresh = FALSE; + char *str_auto_refresh; + GError *error = NULL; /* save names for removing unused connections */ - GHashTable *new_conn_names = NULL; + GHashTable *new_connections = NULL; GHashTableIter iter; - gpointer key; - gpointer value; + const char *uuid; + NMSettingsConnection *candidate; if (priv->unmanaged_well_known) return; @@ -251,17 +260,26 @@ reload_connections (gpointer config) if (!reload_parsers ()) return; - PLUGIN_PRINT (IFNET_PLUGIN_NAME, "Loading connections"); + nm_log_info (LOGD_SETTINGS, "Loading connections"); + + str_auto_refresh = nm_config_get_value (nm_config_get (), + IFNET_KEY_FILE_GROUP, "auto_refresh", + NULL); + if (str_auto_refresh && is_true (str_auto_refresh)) + auto_refresh = TRUE; + g_free (str_auto_refresh); + new_connections = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_object_unref); + + /* Reread on-disk data and refresh in-memory connections from it */ conn_names = ifnet_get_connection_names (); - new_conn_names = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL); for (n_iter = conn_names; n_iter; n_iter = g_list_next (n_iter)) { NMIfnetConnection *new; NMIfnetConnection *old; const char *conn_name = n_iter->data; /* read the new connection */ - new = nm_ifnet_connection_new (conn_name, NULL); + new = nm_ifnet_connection_new (NULL, conn_name); if (!new) continue; @@ -270,129 +288,129 @@ reload_connections (gpointer config) g_signal_connect (G_OBJECT (new), "ifnet_cancel_monitors", G_CALLBACK (cancel_monitors), config); - old = g_hash_table_lookup (priv->config_connections, conn_name); + old = g_hash_table_lookup (priv->connections, + nm_connection_get_uuid (NM_CONNECTION (new))); if (old && new) { - const char *auto_refresh; - - auto_refresh = ifnet_get_global_setting (IFNET_KEY_FILE_GROUP, "auto_refresh"); - if (auto_refresh && is_true (auto_refresh)) { + if (auto_refresh) { + /* If connection has changed, remove the old one and add the + * new one to force a disconnect/reconnect with new settings + */ if (!nm_connection_compare (NM_CONNECTION (old), NM_CONNECTION (new), NM_SETTING_COMPARE_FLAG_IGNORE_AGENT_OWNED_SECRETS | NM_SETTING_COMPARE_FLAG_IGNORE_NOT_SAVED_SECRETS)) { - PLUGIN_PRINT (IFNET_PLUGIN_NAME, "Auto refreshing %s", conn_name); + nm_log_info (LOGD_SETTINGS, "Auto refreshing %s", conn_name); - /* Remove and re-add to disconnect and reconnect with new settings */ nm_settings_connection_signal_remove (NM_SETTINGS_CONNECTION (old)); - g_hash_table_remove (priv->config_connections, conn_name); - g_hash_table_insert (priv->config_connections, g_strdup (conn_name), new); + track_new_connection (self, new); if (is_managed_plugin () && is_managed (conn_name)) g_signal_emit_by_name (self, NM_SYSTEM_CONFIG_INTERFACE_CONNECTION_ADDED, new); } } else { /* Update existing connection with new settings */ - nm_settings_connection_replace_and_commit (NM_SETTINGS_CONNECTION (old), - NM_CONNECTION (new), - commit_cb, NULL); - g_object_unref (new); + if (!nm_settings_connection_replace_settings (NM_SETTINGS_CONNECTION (old), + NM_CONNECTION (new), + FALSE, /* don't set Unsaved */ + &error)) { + /* Shouldn't ever get here as 'new' was verified by the reader already */ + g_assert_no_error (error); + } + nm_log_info (LOGD_SETTINGS, "Connection %s updated", + nm_connection_get_id (NM_CONNECTION (new))); } g_signal_emit_by_name (self, NM_SYSTEM_CONFIG_INTERFACE_UNMANAGED_SPECS_CHANGED); } else if (new) { - g_hash_table_insert (priv->config_connections, g_strdup (conn_name), new); + track_new_connection (self, new); if (is_managed_plugin () && is_managed (conn_name)) g_signal_emit_by_name (self, NM_SYSTEM_CONFIG_INTERFACE_CONNECTION_ADDED, new); } - g_hash_table_insert (new_conn_names, (gpointer) conn_name, (gpointer) conn_name); - } - /* remove unused connections */ - g_hash_table_iter_init (&iter, priv->config_connections); - while (g_hash_table_iter_next (&iter, &key, &value)) { - if (!g_hash_table_lookup (new_conn_names, key)) { - nm_settings_connection_signal_remove (NM_SETTINGS_CONNECTION (value)); - g_hash_table_remove (priv->config_connections, key); - } + /* Track all valid connections so we can remove deleted ones later */ + g_hash_table_insert (new_connections, + (gpointer) nm_connection_get_uuid (NM_CONNECTION (new)), + new); } - g_hash_table_destroy (new_conn_names); - g_list_free (conn_names); -} -static void -check_flagged_secrets (NMSetting *setting, - const char *key, - const GValue *value, - GParamFlags flags, - gpointer user_data) -{ - gboolean *is_system_secret = user_data; - - if (flags & NM_SETTING_PARAM_SECRET) { - NMSettingSecretFlags secret_flags = NM_SETTING_SECRET_FLAG_NONE; - - nm_setting_get_secret_flags (setting, key, &secret_flags, NULL); - - if (secret_flags != NM_SETTING_SECRET_FLAG_NONE) { - *is_system_secret = TRUE; + /* remove deleted/unused connections */ + g_hash_table_iter_init (&iter, priv->connections); + while (g_hash_table_iter_next (&iter, (gpointer) &uuid, (gpointer) &candidate)) { + /* only saved connections (which have a conn_name) get removed; unsaved + * ones obviously don't exist in /etc/conf.d/net yet and shouldn't get + * blown away by net file changes. + */ + if ( nm_ifnet_connection_get_conn_name (NM_IFNET_CONNECTION (candidate)) + && !g_hash_table_lookup (new_connections, uuid)) { + nm_settings_connection_signal_remove (candidate); + g_hash_table_iter_remove (&iter); } } + g_hash_table_destroy (new_connections); + g_list_free (conn_names); } static NMSettingsConnection * add_connection (NMSystemConfigInterface *config, NMConnection *source, + gboolean save_to_disk, GError **error) { - NMIfnetConnection *connection = NULL; - char *conn_name; - gboolean has_flagged_secrets = FALSE; - NMSettingConnection *s_con; - - s_con = nm_connection_get_setting_connection (source); - g_assert (s_con); + SCPluginIfnetPrivate *priv = SC_PLUGIN_IFNET_GET_PRIVATE (config); + NMIfnetConnection *new = NULL; - /* If the connection is not available for all users, ignore - * it as this plugin only deals with System Connections */ - if (nm_setting_connection_get_num_permissions (s_con)) + /* Ensure we reject attempts to add the connection long before we're + * asked to write it to disk. + */ + if (!ifnet_can_write_connection (source, error)) return NULL; - /* If the connection has flagged secrets, ignore - * it as this plugin does not deal with user agent service */ - nm_connection_for_each_setting_value (source, check_flagged_secrets, &has_flagged_secrets); - - if (!has_flagged_secrets) { - conn_name = ifnet_add_new_connection (source, CONF_NET_FILE, WPA_SUPPLICANT_CONF, NULL, error); - if (conn_name) - connection = nm_ifnet_connection_new (conn_name, source); + if (save_to_disk) { + if (!ifnet_add_new_connection (source, CONF_NET_FILE, WPA_SUPPLICANT_CONF, NULL, NULL, error)) + return NULL; reload_connections (config); + new = g_hash_table_lookup (priv->connections, nm_connection_get_uuid (source)); + } else { + new = nm_ifnet_connection_new (source, NULL); + if (new) { + track_new_connection (SC_PLUGIN_IFNET (config), new); + /* track_new_connection refs 'new' */ + g_object_unref (new); + } } - return connection ? NM_SETTINGS_CONNECTION (connection) : NULL; + return (NMSettingsConnection *) new; } static void check_unmanaged (gpointer key, gpointer data, gpointer user_data) { + NMIfnetConnection *connection = NM_IFNET_CONNECTION (data); GSList **list = (GSList **) user_data; - gchar *conn_name = (gchar *) key; - const char *unmanaged_spec; + const char *mac, *conn_name; + char *unmanaged_spec; GSList *iter; + conn_name = nm_ifnet_connection_get_conn_name (connection); + if (is_managed (conn_name)) return; - PLUGIN_PRINT (IFNET_PLUGIN_NAME, "Checking unmanaged: %s", conn_name); - unmanaged_spec = ifnet_get_data (conn_name, "mac"); - if (!unmanaged_spec) - return; + + nm_log_info (LOGD_SETTINGS, "Checking unmanaged: %s", conn_name); + mac = ifnet_get_data (conn_name, "mac"); + if (mac) + unmanaged_spec = g_strdup_printf ("mac:%s", mac); + else + unmanaged_spec = g_strdup_printf ("interface-name:%s", conn_name); /* Just return if the unmanaged spec is already in the list */ for (iter = *list; iter; iter = g_slist_next (iter)) { - if (!strcmp ((char *) iter->data, unmanaged_spec)) + if (g_str_equal (iter->data, unmanaged_spec)) { + g_free (unmanaged_spec); return; + } } - PLUGIN_PRINT (IFNET_PLUGIN_NAME, "Add unmanaged: %s", unmanaged_spec); - *list = - g_slist_prepend (*list, g_strdup_printf ("mac:%s", unmanaged_spec)); + nm_log_info (LOGD_SETTINGS, "Add unmanaged: %s", unmanaged_spec); + *list = g_slist_prepend (*list, unmanaged_spec); } static GSList * @@ -401,68 +419,61 @@ get_unmanaged_specs (NMSystemConfigInterface * config) SCPluginIfnetPrivate *priv = SC_PLUGIN_IFNET_GET_PRIVATE (config); GSList *list = NULL; - g_return_val_if_fail (priv->config_connections != NULL, NULL); - PLUGIN_PRINT (IFNET_PLUGIN_NAME, "getting unmanaged specs..."); - g_hash_table_foreach (priv->config_connections, check_unmanaged, &list); + nm_log_info (LOGD_SETTINGS, "getting unmanaged specs..."); + g_hash_table_foreach (priv->connections, check_unmanaged, &list); return list; } static void -SCPluginIfnet_init (NMSystemConfigInterface * config) +init (NMSystemConfigInterface *config) { SCPluginIfnet *self = SC_PLUGIN_IFNET (config); SCPluginIfnetPrivate *priv = SC_PLUGIN_IFNET_GET_PRIVATE (self); - PLUGIN_PRINT (IFNET_PLUGIN_NAME, "Initializing!"); - if (!priv->config_connections) - priv->config_connections = - g_hash_table_new_full (g_str_hash, g_str_equal, g_free, - g_object_unref); + nm_log_info (LOGD_SETTINGS, "Initializing!"); + + priv->connections = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref); priv->unmanaged_well_known = !is_managed_plugin (); - PLUGIN_PRINT (IFNET_PLUGIN_NAME, "management mode: %s", - priv->unmanaged_well_known ? "unmanaged" : "managed"); - // GFileMonitor setup + nm_log_info (LOGD_SETTINGS, "management mode: %s", + priv->unmanaged_well_known ? "unmanaged" : "managed"); + setup_monitors (NULL, config); reload_connections (config); - /* Read hostname */ update_system_hostname (self); - PLUGIN_PRINT (IFNET_PLUGIN_NAME, "Initialzation complete!"); + nm_log_info (LOGD_SETTINGS, "Initialzation complete!"); } static GSList * -get_connections (NMSystemConfigInterface * config) +get_connections (NMSystemConfigInterface *config) { SCPluginIfnetPrivate *priv = SC_PLUGIN_IFNET_GET_PRIVATE (config); GSList *connections = NULL; GHashTableIter iter; - gpointer key, value; - - PLUGIN_PRINT (IFNET_PLUGIN_NAME, "(%d) ... get_connections.", - GPOINTER_TO_UINT (config)); - if (priv->unmanaged_well_known) { - PLUGIN_PRINT (IFNET_PLUGIN_NAME, - "(%d) ... get_connections (managed=false): return empty list.", - GPOINTER_TO_UINT (config)); - return NULL; - } + NMIfnetConnection *connection; + + nm_log_info (LOGD_SETTINGS, "(%p) ... get_connections.", config); - g_hash_table_iter_init (&iter, priv->config_connections); - while (g_hash_table_iter_next (&iter, &key, &value)) - if (is_managed ((gchar *) key)) - connections = g_slist_prepend (connections, value); - PLUGIN_PRINT (IFNET_PLUGIN_NAME, "(%d) connections count: %d", - GPOINTER_TO_UINT (config), g_slist_length (connections)); + g_hash_table_iter_init (&iter, priv->connections); + while (g_hash_table_iter_next (&iter, NULL, (gpointer) &connection)) { + const char *conn_name = nm_ifnet_connection_get_conn_name (connection); + + if (!conn_name || (!priv->unmanaged_well_known && is_managed (conn_name))) + connections = g_slist_prepend (connections, connection); + } + nm_log_info (LOGD_SETTINGS, "(%p) connections count: %d", + config, g_slist_length (connections)); return connections; } static void system_config_interface_init (NMSystemConfigInterface *class) { - class->init = SCPluginIfnet_init; + class->init = init; class->get_connections = get_connections; class->get_unmanaged_specs = get_unmanaged_specs; class->add_connection = add_connection; + class->reload_connections = reload_connections; } static void @@ -525,13 +536,14 @@ dispose (GObject * object) SCPluginIfnetPrivate *priv = SC_PLUGIN_IFNET_GET_PRIVATE (plugin); cancel_monitors (NULL, object); - if (priv->config_connections) { - g_hash_table_remove_all (priv->config_connections); - g_hash_table_destroy (priv->config_connections); + if (priv->connections) { + g_hash_table_destroy (priv->connections); + priv->connections = NULL; } g_free (priv->hostname); - g_free (priv->conf_file); + priv->hostname = NULL; + ifnet_destroy (); wpa_parser_destroy (); G_OBJECT_CLASS (sc_plugin_ifnet_parent_class)->dispose (object); @@ -565,35 +577,15 @@ sc_plugin_ifnet_class_init (SCPluginIfnetClass * req_class) NM_SYSTEM_CONFIG_INTERFACE_HOSTNAME); } -const char * -ifnet_plugin_get_conf_file (void) -{ - SCPluginIfnet *ifnet_plugin; - SCPluginIfnetPrivate *priv; - - /* Get config file name. Plugin's singleton has already been created - * with correct config file path, so the string passed here has no efect - * and we get the valid file name. - */ - ifnet_plugin = SC_PLUGIN_IFNET (nm_system_config_factory ("fake string")); - priv = SC_PLUGIN_IFNET_GET_PRIVATE (ifnet_plugin); - g_object_unref (ifnet_plugin); - - return priv->conf_file; -} - G_MODULE_EXPORT GObject * -nm_system_config_factory (const char *config_file) +nm_system_config_factory (void) { static SCPluginIfnet *singleton = NULL; SCPluginIfnetPrivate *priv; if (!singleton) { singleton = SC_PLUGIN_IFNET (g_object_new (SC_TYPE_PLUGIN_IFNET, NULL)); - if (singleton) { - priv = SC_PLUGIN_IFNET_GET_PRIVATE (singleton); - priv->conf_file = strdup (config_file); - } + priv = SC_PLUGIN_IFNET_GET_PRIVATE (singleton); } else g_object_ref (singleton); diff --git a/src/settings/plugins/ifnet/plugin.h b/src/settings/plugins/ifnet/plugin.h index 27e71eead..6ac0f482f 100644 --- a/src/settings/plugins/ifnet/plugin.h +++ b/src/settings/plugins/ifnet/plugin.h @@ -43,7 +43,5 @@ struct _SCPluginIfnetClass { GObjectClass parent; }; -const char * ifnet_plugin_get_conf_file (void); - GType sc_plugin_ifnet_get_type (void); #endif diff --git a/src/settings/plugins/ifnet/tests/Makefile.am b/src/settings/plugins/ifnet/tests/Makefile.am index 8d80b7308..f66a6a3dd 100644 --- a/src/settings/plugins/ifnet/tests/Makefile.am +++ b/src/settings/plugins/ifnet/tests/Makefile.am @@ -1,5 +1,7 @@ if ENABLE_TESTS +@GNOME_CODE_COVERAGE_RULES@ + AM_CPPFLAGS= \ -I$(srcdir)/../ \ -I$(top_srcdir)/libnm-glib \ @@ -7,19 +9,35 @@ AM_CPPFLAGS= \ -I$(top_builddir)/libnm-util \ -I$(top_srcdir)/include \ -I$(top_builddir)/include \ + -I$(top_srcdir)/src \ + -I$(top_srcdir)/src/config \ + -I$(top_srcdir)/src/logging \ -I$(top_srcdir)/src/settings \ + -I$(top_srcdir)/src/platform \ + -DG_LOG_DOMAIN=\""NetworkManager-ifnet"\" \ + -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ $(CHECK_CFLAGS) \ $(GLIB_CFLAGS) \ - -DTEST_WPA_SUPPLICANT_CONF='"$(srcdir)/wpa_supplicant.conf"' + $(DBUS_CFLAGS) \ + $(POLKIT_CFLAGS) \ + $(CODE_COVERAGE_CFLAGS) \ + -DTEST_WPA_SUPPLICANT_CONF='"$(srcdir)/wpa_supplicant.conf"' \ + -DSYSCONFDIR=\"nonexistent\" noinst_PROGRAMS = check_ifnet -check_ifnet_SOURCES = test_all.c +check_ifnet_SOURCES = \ + test_all.c \ + ../connection_parser.c \ + ../net_parser.c \ + ../net_utils.c \ + ../wpa_parser.c \ + ../errors.c + +check_ifnet_LDFLAGS = \ + $(CODE_COVERAGE_LDFLAGS) + +check_ifnet_LDADD = $(top_builddir)/src/libNetworkManager.la -check_ifnet_LDADD = $(top_builddir)/libnm-util/libnm-util.la \ - $(builddir)/../lib-ifnet-io.la \ - $(CHECK_LIBS) \ - $(GLIB_LIBS) \ - $(LIBM) check-local: check_ifnet $(abs_builddir)/check_ifnet $(abs_srcdir) $(abs_builddir) diff --git a/src/settings/plugins/ifnet/tests/Makefile.in b/src/settings/plugins/ifnet/tests/Makefile.in index 17ec85d0f..cd6042377 100644 --- a/src/settings/plugins/ifnet/tests/Makefile.in +++ b/src/settings/plugins/ifnet/tests/Makefile.in @@ -83,7 +83,8 @@ subdir = src/settings/plugins/ifnet/tests DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \ $(top_srcdir)/build-aux/depcomp ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 -am__aclocal_m4_deps = $(top_srcdir)/m4/compiler_warnings.m4 \ +am__aclocal_m4_deps = $(top_srcdir)/m4/ax_lib_readline.m4 \ + $(top_srcdir)/m4/compiler_warnings.m4 \ $(top_srcdir)/m4/gettext.m4 \ $(top_srcdir)/m4/gnome-code-coverage.m4 \ $(top_srcdir)/m4/gtk-doc.m4 $(top_srcdir)/m4/iconv.m4 \ @@ -102,18 +103,22 @@ CONFIG_HEADER = $(top_builddir)/config.h CONFIG_CLEAN_FILES = CONFIG_CLEAN_VPATH_FILES = PROGRAMS = $(noinst_PROGRAMS) -am__check_ifnet_SOURCES_DIST = test_all.c -@ENABLE_TESTS_TRUE@am_check_ifnet_OBJECTS = test_all.$(OBJEXT) +am__check_ifnet_SOURCES_DIST = test_all.c ../connection_parser.c \ + ../net_parser.c ../net_utils.c ../wpa_parser.c ../errors.c +@ENABLE_TESTS_TRUE@am_check_ifnet_OBJECTS = test_all.$(OBJEXT) \ +@ENABLE_TESTS_TRUE@ connection_parser.$(OBJEXT) \ +@ENABLE_TESTS_TRUE@ net_parser.$(OBJEXT) net_utils.$(OBJEXT) \ +@ENABLE_TESTS_TRUE@ wpa_parser.$(OBJEXT) errors.$(OBJEXT) check_ifnet_OBJECTS = $(am_check_ifnet_OBJECTS) -am__DEPENDENCIES_1 = @ENABLE_TESTS_TRUE@check_ifnet_DEPENDENCIES = \ -@ENABLE_TESTS_TRUE@ $(top_builddir)/libnm-util/libnm-util.la \ -@ENABLE_TESTS_TRUE@ $(builddir)/../lib-ifnet-io.la \ -@ENABLE_TESTS_TRUE@ $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) +@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 = +check_ifnet_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ + $(check_ifnet_LDFLAGS) $(LDFLAGS) -o $@ AM_V_P = $(am__v_P_@AM_V@) am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) am__v_P_0 = false @@ -200,12 +205,15 @@ CXXFLAGS = @CXXFLAGS@ CYGPATH_W = @CYGPATH_W@ DATADIRNAME = @DATADIRNAME@ DBUS_CFLAGS = @DBUS_CFLAGS@ +DBUS_GLIB_100_CFLAGS = @DBUS_GLIB_100_CFLAGS@ +DBUS_GLIB_100_LIBS = @DBUS_GLIB_100_LIBS@ 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@ DNSMASQ_PATH = @DNSMASQ_PATH@ DSYMUTIL = @DSYMUTIL@ @@ -230,7 +238,6 @@ 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@ @@ -275,12 +282,16 @@ LIBGCRYPT_LIBS = @LIBGCRYPT_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@ +LIBTEAMDCTL_CFLAGS = @LIBTEAMDCTL_CFLAGS@ +LIBTEAMDCTL_LIBS = @LIBTEAMDCTL_LIBS@ LIBTOOL = @LIBTOOL@ LIPO = @LIPO@ LN_S = @LN_S@ @@ -297,6 +308,8 @@ MOC = @MOC@ MSGFMT = @MSGFMT@ MSGFMT_015 = @MSGFMT_015@ MSGMERGE = @MSGMERGE@ +NEWT_CFLAGS = @NEWT_CFLAGS@ +NEWT_LIBS = @NEWT_LIBS@ NM = @NM@ NMEDIT = @NMEDIT@ NM_MAJOR_VERSION = @NM_MAJOR_VERSION@ @@ -324,11 +337,16 @@ 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@ +PPPOE_PATH = @PPPOE_PATH@ QT_CFLAGS = @QT_CFLAGS@ QT_LIBS = @QT_LIBS@ RANLIB = @RANLIB@ +READLINE_LIBS = @READLINE_LIBS@ SED = @SED@ +SELINUX_CFLAGS = @SELINUX_CFLAGS@ +SELINUX_LIBS = @SELINUX_LIBS@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ STRIP = @STRIP@ @@ -343,6 +361,7 @@ UDEV_BASE_DIR = @UDEV_BASE_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@ @@ -405,6 +424,7 @@ psdir = @psdir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ +subdirs = @subdirs@ sysconfdir = @sysconfdir@ systemdsystemunitdir = @systemdsystemunitdir@ target_alias = @target_alias@ @@ -415,6 +435,7 @@ with_dhclient = @with_dhclient@ with_dhcpcd = @with_dhcpcd@ with_netconfig = @with_netconfig@ with_resolvconf = @with_resolvconf@ +with_valgrind = @with_valgrind@ @ENABLE_TESTS_TRUE@AM_CPPFLAGS = \ @ENABLE_TESTS_TRUE@ -I$(srcdir)/../ \ @ENABLE_TESTS_TRUE@ -I$(top_srcdir)/libnm-glib \ @@ -422,18 +443,33 @@ with_resolvconf = @with_resolvconf@ @ENABLE_TESTS_TRUE@ -I$(top_builddir)/libnm-util \ @ENABLE_TESTS_TRUE@ -I$(top_srcdir)/include \ @ENABLE_TESTS_TRUE@ -I$(top_builddir)/include \ +@ENABLE_TESTS_TRUE@ -I$(top_srcdir)/src \ +@ENABLE_TESTS_TRUE@ -I$(top_srcdir)/src/config \ +@ENABLE_TESTS_TRUE@ -I$(top_srcdir)/src/logging \ @ENABLE_TESTS_TRUE@ -I$(top_srcdir)/src/settings \ +@ENABLE_TESTS_TRUE@ -I$(top_srcdir)/src/platform \ +@ENABLE_TESTS_TRUE@ -DG_LOG_DOMAIN=\""NetworkManager-ifnet"\" \ +@ENABLE_TESTS_TRUE@ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ @ENABLE_TESTS_TRUE@ $(CHECK_CFLAGS) \ @ENABLE_TESTS_TRUE@ $(GLIB_CFLAGS) \ -@ENABLE_TESTS_TRUE@ -DTEST_WPA_SUPPLICANT_CONF='"$(srcdir)/wpa_supplicant.conf"' - -@ENABLE_TESTS_TRUE@check_ifnet_SOURCES = test_all.c -@ENABLE_TESTS_TRUE@check_ifnet_LDADD = $(top_builddir)/libnm-util/libnm-util.la \ -@ENABLE_TESTS_TRUE@ $(builddir)/../lib-ifnet-io.la \ -@ENABLE_TESTS_TRUE@ $(CHECK_LIBS) \ -@ENABLE_TESTS_TRUE@ $(GLIB_LIBS) \ -@ENABLE_TESTS_TRUE@ $(LIBM) - +@ENABLE_TESTS_TRUE@ $(DBUS_CFLAGS) \ +@ENABLE_TESTS_TRUE@ $(POLKIT_CFLAGS) \ +@ENABLE_TESTS_TRUE@ $(CODE_COVERAGE_CFLAGS) \ +@ENABLE_TESTS_TRUE@ -DTEST_WPA_SUPPLICANT_CONF='"$(srcdir)/wpa_supplicant.conf"' \ +@ENABLE_TESTS_TRUE@ -DSYSCONFDIR=\"nonexistent\" + +@ENABLE_TESTS_TRUE@check_ifnet_SOURCES = \ +@ENABLE_TESTS_TRUE@ test_all.c \ +@ENABLE_TESTS_TRUE@ ../connection_parser.c \ +@ENABLE_TESTS_TRUE@ ../net_parser.c \ +@ENABLE_TESTS_TRUE@ ../net_utils.c \ +@ENABLE_TESTS_TRUE@ ../wpa_parser.c \ +@ENABLE_TESTS_TRUE@ ../errors.c + +@ENABLE_TESTS_TRUE@check_ifnet_LDFLAGS = \ +@ENABLE_TESTS_TRUE@ $(CODE_COVERAGE_LDFLAGS) + +@ENABLE_TESTS_TRUE@check_ifnet_LDADD = $(top_builddir)/src/libNetworkManager.la @ENABLE_TESTS_TRUE@EXTRA_DIST = \ @ENABLE_TESTS_TRUE@ hostname \ @ENABLE_TESTS_TRUE@ net \ @@ -488,7 +524,7 @@ clean-noinstPROGRAMS: check_ifnet$(EXEEXT): $(check_ifnet_OBJECTS) $(check_ifnet_DEPENDENCIES) $(EXTRA_check_ifnet_DEPENDENCIES) @rm -f check_ifnet$(EXEEXT) - $(AM_V_CCLD)$(LINK) $(check_ifnet_OBJECTS) $(check_ifnet_LDADD) $(LIBS) + $(AM_V_CCLD)$(check_ifnet_LINK) $(check_ifnet_OBJECTS) $(check_ifnet_LDADD) $(LIBS) mostlyclean-compile: -rm -f *.$(OBJEXT) @@ -496,7 +532,12 @@ mostlyclean-compile: distclean-compile: -rm -f *.tab.c +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/connection_parser.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/errors.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/net_parser.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/net_utils.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_all.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/wpa_parser.Po@am__quote@ .c.o: @am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< @@ -519,6 +560,76 @@ distclean-compile: @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $< +connection_parser.o: ../connection_parser.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT connection_parser.o -MD -MP -MF $(DEPDIR)/connection_parser.Tpo -c -o connection_parser.o `test -f '../connection_parser.c' || echo '$(srcdir)/'`../connection_parser.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/connection_parser.Tpo $(DEPDIR)/connection_parser.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='../connection_parser.c' object='connection_parser.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 connection_parser.o `test -f '../connection_parser.c' || echo '$(srcdir)/'`../connection_parser.c + +connection_parser.obj: ../connection_parser.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT connection_parser.obj -MD -MP -MF $(DEPDIR)/connection_parser.Tpo -c -o connection_parser.obj `if test -f '../connection_parser.c'; then $(CYGPATH_W) '../connection_parser.c'; else $(CYGPATH_W) '$(srcdir)/../connection_parser.c'; fi` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/connection_parser.Tpo $(DEPDIR)/connection_parser.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='../connection_parser.c' object='connection_parser.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 connection_parser.obj `if test -f '../connection_parser.c'; then $(CYGPATH_W) '../connection_parser.c'; else $(CYGPATH_W) '$(srcdir)/../connection_parser.c'; fi` + +net_parser.o: ../net_parser.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT net_parser.o -MD -MP -MF $(DEPDIR)/net_parser.Tpo -c -o net_parser.o `test -f '../net_parser.c' || echo '$(srcdir)/'`../net_parser.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/net_parser.Tpo $(DEPDIR)/net_parser.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='../net_parser.c' object='net_parser.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 net_parser.o `test -f '../net_parser.c' || echo '$(srcdir)/'`../net_parser.c + +net_parser.obj: ../net_parser.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT net_parser.obj -MD -MP -MF $(DEPDIR)/net_parser.Tpo -c -o net_parser.obj `if test -f '../net_parser.c'; then $(CYGPATH_W) '../net_parser.c'; else $(CYGPATH_W) '$(srcdir)/../net_parser.c'; fi` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/net_parser.Tpo $(DEPDIR)/net_parser.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='../net_parser.c' object='net_parser.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 net_parser.obj `if test -f '../net_parser.c'; then $(CYGPATH_W) '../net_parser.c'; else $(CYGPATH_W) '$(srcdir)/../net_parser.c'; fi` + +net_utils.o: ../net_utils.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT net_utils.o -MD -MP -MF $(DEPDIR)/net_utils.Tpo -c -o net_utils.o `test -f '../net_utils.c' || echo '$(srcdir)/'`../net_utils.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/net_utils.Tpo $(DEPDIR)/net_utils.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='../net_utils.c' object='net_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 net_utils.o `test -f '../net_utils.c' || echo '$(srcdir)/'`../net_utils.c + +net_utils.obj: ../net_utils.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT net_utils.obj -MD -MP -MF $(DEPDIR)/net_utils.Tpo -c -o net_utils.obj `if test -f '../net_utils.c'; then $(CYGPATH_W) '../net_utils.c'; else $(CYGPATH_W) '$(srcdir)/../net_utils.c'; fi` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/net_utils.Tpo $(DEPDIR)/net_utils.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='../net_utils.c' object='net_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 net_utils.obj `if test -f '../net_utils.c'; then $(CYGPATH_W) '../net_utils.c'; else $(CYGPATH_W) '$(srcdir)/../net_utils.c'; fi` + +wpa_parser.o: ../wpa_parser.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT wpa_parser.o -MD -MP -MF $(DEPDIR)/wpa_parser.Tpo -c -o wpa_parser.o `test -f '../wpa_parser.c' || echo '$(srcdir)/'`../wpa_parser.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/wpa_parser.Tpo $(DEPDIR)/wpa_parser.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='../wpa_parser.c' object='wpa_parser.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 wpa_parser.o `test -f '../wpa_parser.c' || echo '$(srcdir)/'`../wpa_parser.c + +wpa_parser.obj: ../wpa_parser.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT wpa_parser.obj -MD -MP -MF $(DEPDIR)/wpa_parser.Tpo -c -o wpa_parser.obj `if test -f '../wpa_parser.c'; then $(CYGPATH_W) '../wpa_parser.c'; else $(CYGPATH_W) '$(srcdir)/../wpa_parser.c'; fi` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/wpa_parser.Tpo $(DEPDIR)/wpa_parser.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='../wpa_parser.c' object='wpa_parser.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 wpa_parser.obj `if test -f '../wpa_parser.c'; then $(CYGPATH_W) '../wpa_parser.c'; else $(CYGPATH_W) '$(srcdir)/../wpa_parser.c'; fi` + +errors.o: ../errors.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT errors.o -MD -MP -MF $(DEPDIR)/errors.Tpo -c -o errors.o `test -f '../errors.c' || echo '$(srcdir)/'`../errors.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/errors.Tpo $(DEPDIR)/errors.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='../errors.c' object='errors.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 errors.o `test -f '../errors.c' || echo '$(srcdir)/'`../errors.c + +errors.obj: ../errors.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT errors.obj -MD -MP -MF $(DEPDIR)/errors.Tpo -c -o errors.obj `if test -f '../errors.c'; then $(CYGPATH_W) '../errors.c'; else $(CYGPATH_W) '$(srcdir)/../errors.c'; fi` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/errors.Tpo $(DEPDIR)/errors.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='../errors.c' object='errors.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 errors.obj `if test -f '../errors.c'; then $(CYGPATH_W) '../errors.c'; else $(CYGPATH_W) '$(srcdir)/../errors.c'; fi` + mostlyclean-libtool: -rm -f *.lo @@ -730,6 +841,9 @@ uninstall-am: mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ tags tags-am uninstall uninstall-am + +@ENABLE_TESTS_TRUE@@GNOME_CODE_COVERAGE_RULES@ + @ENABLE_TESTS_TRUE@check-local: check_ifnet @ENABLE_TESTS_TRUE@ $(abs_builddir)/check_ifnet $(abs_srcdir) $(abs_builddir) diff --git a/src/settings/plugins/ifnet/tests/net.all b/src/settings/plugins/ifnet/tests/net.all index a30a1b95e..285a4cdf2 100644 --- a/src/settings/plugins/ifnet/tests/net.all +++ b/src/settings/plugins/ifnet/tests/net.all @@ -327,7 +327,7 @@ arping_wait_lan=2 # Please ensure your VLAN IDs are NOT zero-padded vlans_eth0="1 2" -# You may not want to assign an IP the the physical interface, but we still +# You may not want to assign an IP to the physical interface, but we still # need it up. config_eth0=( "null" ) @@ -361,7 +361,7 @@ vlan_start_eth0="no" # To bond interfaces together slaves_bond0="eth0 eth1 eth2" -config_bond0=( "null" ) # You may not want to assign an IP the the bond +config_bond0=( "null" ) # You may not want to assign an IP to the bond # If any of the slaves require extra configuration - for example wireless or # ppp devices - we need to depend function on the bonded interfaces diff --git a/src/settings/plugins/ifnet/tests/test_all.c b/src/settings/plugins/ifnet/tests/test_all.c index 4c3126010..c320ed5f8 100644 --- a/src/settings/plugins/ifnet/tests/test_all.c +++ b/src/settings/plugins/ifnet/tests/test_all.c @@ -28,21 +28,31 @@ #include <unistd.h> #include <nm-utils.h> +#include "nm-linux-platform.h" +#include "nm-logging.h" + #include "net_parser.h" -#include "nm-test-helpers.h" #include "net_utils.h" #include "wpa_parser.h" #include "connection_parser.h" +#include "nm-config.h" -/* Fake config file function to make the linker happy */ -const char *ifnet_plugin_get_conf_file (void); +#include "nm-test-utils.h" -const char * -ifnet_plugin_get_conf_file (void) +/* Fake NMConfig handling; the values it returns don't matter, so this + * is easier than forcing it to read our own config file, etc. + */ +NMConfig * +nm_config_get (void) { - return "/etc/foo/barasdfasdfasdfasdf"; + return NULL; } +const char * +nm_config_get_dhcp_client (NMConfig *config) +{ + return "dhclient"; +} static void test_getdata () @@ -153,18 +163,18 @@ static void check_ip_block (ip_block * iblock, gchar * ip, gchar * netmask, gchar * gateway) { char *str; - struct in_addr tmp_ip4_addr; + guint32 tmp_ip4_addr; str = malloc (INET_ADDRSTRLEN); - tmp_ip4_addr.s_addr = iblock->ip; + tmp_ip4_addr = iblock->ip; inet_ntop (AF_INET, &tmp_ip4_addr, str, INET_ADDRSTRLEN); ASSERT (strcmp (ip, str) == 0, "check ip", "ip expected:%s, find:%s", ip, str); - tmp_ip4_addr.s_addr = iblock->netmask; + tmp_ip4_addr = iblock->netmask; inet_ntop (AF_INET, &tmp_ip4_addr, str, INET_ADDRSTRLEN); ASSERT (strcmp (netmask, str) == 0, "check netmask", "netmask expected:%s, find:%s", netmask, str); - tmp_ip4_addr.s_addr = iblock->gateway; + tmp_ip4_addr = iblock->gateway; inet_ntop (AF_INET, &tmp_ip4_addr, str, INET_ADDRSTRLEN); ASSERT (strcmp (gateway, str) == 0, "check gateway", "gateway expected:%s, find:%s", gateway, str); @@ -188,12 +198,19 @@ test_convert_ipv4_config_block () check_ip_block (iblock, "192.168.4.121", "255.255.255.0", "202.117.16.1"); destroy_ip_block (iblock); + + g_test_expect_message ("NetworkManager", G_LOG_LEVEL_WARNING, + "*Can't handle IPv4 address*202.117.16.1211*"); iblock = convert_ip4_config_block ("eth2"); + g_test_assert_expected_messages (); ASSERT (iblock != NULL && iblock->next == NULL, "convert error IPv4 address", "should only get one address"); check_ip_block (iblock, "192.168.4.121", "255.255.255.0", "0.0.0.0"); destroy_ip_block (iblock); + + g_test_expect_message ("NetworkManager", G_LOG_LEVEL_WARNING, + "*missing netmask or prefix*"); iblock = convert_ip4_config_block ("eth3"); ASSERT (iblock == NULL, "convert config_block", "convert error configuration"); @@ -274,7 +291,12 @@ test_new_connection () GError *error = NULL; NMConnection *connection; + g_test_expect_message ("NetworkManager", G_LOG_LEVEL_WARNING, + "*Can't handle IPv4 address*202.117.16.1211*"); + g_test_expect_message ("NetworkManager", G_LOG_LEVEL_WARNING, + "*Can't handle IPv6 address*202.117.16.1211*"); connection = ifnet_update_connection_from_config_block ("eth2", NULL, &error); + g_test_assert_expected_messages (); ASSERT (connection != NULL, "new connection", "new connection failed: %s", error ? error->message : "None"); @@ -366,13 +388,18 @@ test_add_connection (const char *basepath) char *backup = NULL; connection = ifnet_update_connection_from_config_block ("eth0", basepath, NULL); - ASSERT (ifnet_add_new_connection (connection, NET_GEN_NAME, SUP_GEN_NAME, &backup, NULL), + ASSERT (ifnet_add_new_connection (connection, NET_GEN_NAME, SUP_GEN_NAME, NULL, &backup, NULL), "add connection", "add connection failed: %s", "eth0"); kill_backup (&backup); g_object_unref (connection); + g_test_expect_message ("NetworkManager", G_LOG_LEVEL_WARNING, + "*Can't handle ipv4 address: brd, missing netmask or prefix*"); + g_test_expect_message ("NetworkManager", G_LOG_LEVEL_WARNING, + "*Can't handle ipv4 address: 202.117.16.255, missing netmask or prefix*"); connection = ifnet_update_connection_from_config_block ("myxjtu2", basepath, NULL); - ASSERT (ifnet_add_new_connection (connection, NET_GEN_NAME, SUP_GEN_NAME, &backup, NULL), + g_test_assert_expected_messages (); + ASSERT (ifnet_add_new_connection (connection, NET_GEN_NAME, SUP_GEN_NAME, NULL, &backup, NULL), "add connection", "add connection failed: %s", "myxjtu2"); kill_backup (&backup); g_object_unref (connection); @@ -416,17 +443,25 @@ test_missing_config () GError *error = NULL; NMConnection *connection; + g_test_expect_message ("NetworkManager", G_LOG_LEVEL_WARNING, + "*Unknown config for eth8*"); connection = ifnet_update_connection_from_config_block ("eth8", NULL, &error); + g_test_assert_expected_messages (); ASSERT (connection == NULL && error != NULL, "get connection", "get connection should fail with 'Unknown config for eth8'"); } +NMTST_DEFINE (); + int main (int argc, char **argv) { char *f; - g_type_init (); + nm_linux_platform_setup (); + + nmtst_init_assert_logging (&argc, &argv); + nm_logging_setup ("WARN", "DEFAULT", NULL, NULL); f = g_build_filename (argv[1], "net", NULL); ifnet_init (f); diff --git a/src/settings/plugins/ifnet/wpa_parser.c b/src/settings/plugins/ifnet/wpa_parser.c index e517bf125..748eb351d 100644 --- a/src/settings/plugins/ifnet/wpa_parser.c +++ b/src/settings/plugins/ifnet/wpa_parser.c @@ -22,6 +22,7 @@ #include <string.h> #include <stdlib.h> #include <nm-system-config-interface.h> +#include <nm-logging.h> #include "wpa_parser.h" #include "net_parser.h" #include "net_utils.h" @@ -236,8 +237,7 @@ add_global_data (gchar * line) g_strstrip (line); key_value = g_strsplit (line, "=", 2); if (g_strv_length (key_value) != 2) { - PLUGIN_WARN (IFNET_PLUGIN_NAME, "Can't handle this line: %s\n", - line); + nm_log_warn (LOGD_SETTINGS, "Can't handle this line: %s\n", line); g_strfreev (key_value); return; } @@ -262,9 +262,8 @@ wpa_parser_init (const char *wpa_supplicant_conf) channel = g_io_channel_new_file (wpa_supplicant_conf, "r", NULL); if (channel == NULL) { - PLUGIN_WARN (IFNET_PLUGIN_NAME, - "Can't open %s for wireless security", - wpa_supplicant_conf); + nm_log_warn (LOGD_SETTINGS, "Can't open %s for wireless security", + wpa_supplicant_conf); return; } @@ -380,12 +379,11 @@ wpa_flush_to_file (const char *config_file) channel = g_io_channel_new_file (config_file, "w", NULL); if (!channel) { - PLUGIN_WARN (IFNET_PLUGIN_NAME, - "Can't open file %s for writing", config_file); + nm_log_warn (LOGD_SETTINGS, "Can't open file %s for writing", config_file); return FALSE; } g_hash_table_iter_init (&iter, wsec_global_table); - PLUGIN_PRINT (IFNET_PLUGIN_NAME, "Writing to %s", config_file); + nm_log_info (LOGD_SETTINGS, "Writing to %s", config_file); g_io_channel_write_chars (channel, "#Generated by NetworkManager\n" "###### Global Configuration ######\n", @@ -402,8 +400,7 @@ wpa_flush_to_file (const char *config_file) g_free (out_line); } if (error && *error) { - PLUGIN_WARN (IFNET_PLUGIN_NAME, "Found error: %s", - (*error)->message); + nm_log_warn (LOGD_SETTINGS, "Found error: %s", (*error)->message); goto done; } g_io_channel_write_chars (channel, @@ -433,15 +430,13 @@ wpa_flush_to_file (const char *config_file) } if (error && *error) { - PLUGIN_WARN (IFNET_PLUGIN_NAME, "Found error: %s", - (*error)->message); + nm_log_warn (LOGD_SETTINGS, "Found error: %s", (*error)->message); goto done; } g_io_channel_flush (channel, error); if (error && *error) { - PLUGIN_WARN (IFNET_PLUGIN_NAME, "Found error: %s", - (*error)->message); + nm_log_warn (LOGD_SETTINGS, "Found error: %s", (*error)->message); goto done; } wpa_parser_data_changed = FALSE; @@ -504,8 +499,7 @@ wpa_add_security (const char *ssid) g_hash_table_new (g_str_hash, g_str_equal); gchar *ssid_i; - PLUGIN_PRINT (IFNET_PLUGIN_NAME, "Adding security for %s", - ssid); + nm_log_info (LOGD_SETTINGS, "Adding security for %s", ssid); if (g_str_has_prefix (ssid, "0x")) { /* hex ssid */ ssid_i = g_strdup (ssid + 2); @@ -528,7 +522,7 @@ wpa_delete_security (const char *ssid) gpointer old_key, old_value; g_return_val_if_fail (wsec_table != NULL && ssid != NULL, FALSE); - PLUGIN_PRINT (IFNET_PLUGIN_NAME, "Deleting security for %s", ssid); + nm_log_info (LOGD_SETTINGS, "Deleting security for %s", ssid); if (!g_hash_table_lookup_extended (wsec_table, ssid, &old_key, &old_value)) return FALSE; |