diff --git a/.gitignore b/.gitignore index 46c69ace10..ba14639556 100644 --- a/.gitignore +++ b/.gitignore @@ -252,7 +252,6 @@ test-*.trs /src/settings/plugins/ibft/tests/test-ibft /src/settings/plugins/ifcfg-rh/nmdbus-ifcfg-rh.[ch] /src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh -/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh-utils /src/settings/plugins/ifnet/tests/test-ifnet /src/settings/plugins/ifupdown/tests/test-ifupdown /src/settings/plugins/keyfile/tests/test-keyfile @@ -281,4 +280,5 @@ test-*.trs /initscript/Slackware/rc.networkmanager /initscript/*/[Nn]etwork[Mm]anager /src/devices/wifi/tests/test-wifi-ap-utils +/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh-utils /src/settings/plugins/ifnet/tests/check_ifnet diff --git a/po/POTFILES.in b/po/POTFILES.in index 91ba0bc417..9606e77b41 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -172,5 +172,5 @@ src/nm-config.c src/nm-iface-helper.c src/nm-logging.c src/nm-manager.c -src/settings/plugins/ibft/plugin.c -src/settings/plugins/ifcfg-rh/reader.c +src/settings/plugins/ibft/nms-ibft-plugin.c +src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c diff --git a/shared/nm-utils/nm-macros-internal.h b/shared/nm-utils/nm-macros-internal.h index 1451053580..c072eef61a 100644 --- a/shared/nm-utils/nm-macros-internal.h +++ b/shared/nm-utils/nm-macros-internal.h @@ -615,6 +615,20 @@ nm_decode_version (guint version, guint *major, guint *minor, guint *micro) { } /*****************************************************************************/ +/* taken from systemd's DECIMAL_STR_MAX() + * + * Returns the number of chars needed to format variables of the + * specified type as a decimal string. Adds in extra space for a + * negative '-' prefix (hence works correctly on signed + * types). Includes space for the trailing NUL. */ +#define NM_DECIMAL_STR_MAX(type) \ + (2+(sizeof(type) <= 1 ? 3 : \ + sizeof(type) <= 2 ? 5 : \ + sizeof(type) <= 4 ? 10 : \ + sizeof(type) <= 8 ? 20 : sizeof(int[-2*(sizeof(type) > 8)]))) + +/*****************************************************************************/ + /* if @str is NULL, return "(null)". Otherwise, allocate a buffer using * alloca() of size @bufsize and fill it with @str. @str will be quoted with * single quote, and in case @str is too long, the final quote will be '^'. */ @@ -646,23 +660,27 @@ nm_decode_version (guint version, guint *major, guint *minor, guint *micro) { #define nm_sprintf_buf(buf, format, ...) ({ \ char * _buf = (buf); \ + int _buf_len; \ \ /* some static assert trying to ensure that the buffer is statically allocated. * It disallows a buffer size of sizeof(gpointer) to catch that. */ \ G_STATIC_ASSERT (G_N_ELEMENTS (buf) == sizeof (buf) && sizeof (buf) != sizeof (char *)); \ - g_snprintf (_buf, sizeof (buf), \ - ""format"", ##__VA_ARGS__); \ + _buf_len = g_snprintf (_buf, sizeof (buf), \ + ""format"", ##__VA_ARGS__); \ + nm_assert (_buf_len < sizeof (buf)); \ _buf; \ }) #define nm_sprintf_bufa(n_elements, format, ...) \ ({ \ char *_buf; \ + int _buf_len; \ \ G_STATIC_ASSERT (sizeof (char[MAX ((n_elements), 1)]) == (n_elements)); \ _buf = g_alloca (n_elements); \ - g_snprintf (_buf, n_elements, \ - ""format"", ##__VA_ARGS__); \ + _buf_len = g_snprintf (_buf, (n_elements), \ + ""format"", ##__VA_ARGS__); \ + nm_assert (_buf_len < (n_elements)); \ _buf; \ }) diff --git a/src/settings/plugins/ibft/Makefile.am b/src/settings/plugins/ibft/Makefile.am index 7a0957f80d..3ad3a19e46 100644 --- a/src/settings/plugins/ibft/Makefile.am +++ b/src/settings/plugins/ibft/Makefile.am @@ -4,11 +4,7 @@ SUBDIRS = . tests pkglib_LTLIBRARIES = libnm-settings-plugin-ibft.la -noinst_LTLIBRARIES = libibft-io.la - -libibft_io_la_SOURCES = \ - reader.c \ - reader.h +noinst_LTLIBRARIES = libnms-ibft-core.la AM_CPPFLAGS = \ -I$(top_srcdir)/src/ \ @@ -24,14 +20,26 @@ AM_CPPFLAGS = \ -DSYSCONFDIR=\"$(sysconfdir)\" \ -DSBINDIR=\"$(sbindir)\" -libnm_settings_plugin_ibft_la_SOURCES = \ - plugin.c \ - plugin.h \ - nm-ibft-connection.c \ - nm-ibft-connection.h +############################################################################### -libnm_settings_plugin_ibft_la_LDFLAGS = -module -avoid-version -libnm_settings_plugin_ibft_la_LIBADD = libibft-io.la +libnms_ibft_core_la_SOURCES = \ + nms-ibft-reader.c \ + nms-ibft-reader.h + +############################################################################### + +libnm_settings_plugin_ibft_la_SOURCES = \ + nms-ibft-plugin.c \ + nms-ibft-plugin.h \ + nms-ibft-connection.c \ + nms-ibft-connection.h + +libnm_settings_plugin_ibft_la_LDFLAGS = \ + -module -avoid-version + +libnm_settings_plugin_ibft_la_LIBADD = \ + libnms-ibft-core.la + +############################################################################### CLEANFILES = $(BUILT_SOURCES) - diff --git a/src/settings/plugins/ibft/nm-ibft-connection.h b/src/settings/plugins/ibft/nm-ibft-connection.h deleted file mode 100644 index 95494095be..0000000000 --- a/src/settings/plugins/ibft/nm-ibft-connection.h +++ /dev/null @@ -1,41 +0,0 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* NetworkManager system settings service - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Copyright 2014 Red Hat, Inc. - */ - -#ifndef NM_IBFT_CONNECTION_H -#define NM_IBFT_CONNECTION_H - -#include - -#define NM_TYPE_IBFT_CONNECTION (nm_ibft_connection_get_type ()) -#define NM_IBFT_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_IBFT_CONNECTION, NMIbftConnection)) -#define NM_IBFT_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_IBFT_CONNECTION, NMIbftConnectionClass)) -#define NM_IS_IBFT_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_IBFT_CONNECTION)) -#define NM_IS_IBFT_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_IBFT_CONNECTION)) -#define NM_IBFT_CONNECTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_IBFT_CONNECTION, NMIbftConnectionClass)) - -typedef struct _NMIbftConnection NMIbftConnection; -typedef struct _NMIbftConnectionClass NMIbftConnectionClass; - -GType nm_ibft_connection_get_type (void); - -NMIbftConnection *nm_ibft_connection_new (const GPtrArray *block, - GError **error); - -#endif /* NM_IBFT_CONNECTION_H */ diff --git a/src/settings/plugins/ibft/nm-ibft-connection.c b/src/settings/plugins/ibft/nms-ibft-connection.c similarity index 74% rename from src/settings/plugins/ibft/nm-ibft-connection.c rename to src/settings/plugins/ibft/nms-ibft-connection.c index 24cfdc19ad..834ba83408 100644 --- a/src/settings/plugins/ibft/nm-ibft-connection.c +++ b/src/settings/plugins/ibft/nms-ibft-connection.c @@ -20,45 +20,45 @@ #include "nm-default.h" -#include "nm-ibft-connection.h" +#include "nms-ibft-connection.h" #include #include #include #include -#include "reader.h" +#include "nms-ibft-reader.h" /*****************************************************************************/ -struct _NMIbftConnection { +struct _NMSIbftConnection { NMSettingsConnection parent; }; -struct _NMIbftConnectionClass { +struct _NMSIbftConnectionClass { NMSettingsConnectionClass parent; }; -G_DEFINE_TYPE (NMIbftConnection, nm_ibft_connection, NM_TYPE_SETTINGS_CONNECTION) +G_DEFINE_TYPE (NMSIbftConnection, nms_ibft_connection, NM_TYPE_SETTINGS_CONNECTION) /*****************************************************************************/ static void -nm_ibft_connection_init (NMIbftConnection *connection) +nms_ibft_connection_init (NMSIbftConnection *connection) { } -NMIbftConnection * -nm_ibft_connection_new (const GPtrArray *block, GError **error) +NMSIbftConnection * +nms_ibft_connection_new (const GPtrArray *block, GError **error) { NMConnection *source; GObject *object; - source = connection_from_block (block, error); + source = nms_ibft_reader_get_connection_from_block (block, error); if (!source) return NULL; - object = g_object_new (NM_TYPE_IBFT_CONNECTION, NULL); + object = g_object_new (NMS_TYPE_IBFT_CONNECTION, NULL); /* Update settings with what was read from iscsiadm */ if (!nm_settings_connection_replace_settings (NM_SETTINGS_CONNECTION (object), source, @@ -67,11 +67,11 @@ nm_ibft_connection_new (const GPtrArray *block, GError **error) error)) g_clear_object (&object); - return (NMIbftConnection *) object; + return (NMSIbftConnection *) object; } static void -nm_ibft_connection_class_init (NMIbftConnectionClass *ibft_connection_class) +nms_ibft_connection_class_init (NMSIbftConnectionClass *ibft_connection_class) { } diff --git a/src/settings/plugins/ibft/nms-ibft-connection.h b/src/settings/plugins/ibft/nms-ibft-connection.h new file mode 100644 index 0000000000..7b9061f777 --- /dev/null +++ b/src/settings/plugins/ibft/nms-ibft-connection.h @@ -0,0 +1,41 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/* NetworkManager system settings service + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Copyright 2014 Red Hat, Inc. + */ + +#ifndef __NMS_IBFT_CONNECTION_H__ +#define __NMS_IBFT_CONNECTION_H__ + +#include + +#define NMS_TYPE_IBFT_CONNECTION (nms_ibft_connection_get_type ()) +#define NMS_IBFT_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NMS_TYPE_IBFT_CONNECTION, NMSIbftConnection)) +#define NMS_IBFT_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NMS_TYPE_IBFT_CONNECTION, NMSIbftConnectionClass)) +#define NMS_IS_IBFT_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NMS_TYPE_IBFT_CONNECTION)) +#define NMS_IS_IBFT_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NMS_TYPE_IBFT_CONNECTION)) +#define NMS_IBFT_CONNECTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NMS_TYPE_IBFT_CONNECTION, NMSIbftConnectionClass)) + +typedef struct _NMSIbftConnection NMSIbftConnection; +typedef struct _NMSIbftConnectionClass NMSIbftConnectionClass; + +GType nms_ibft_connection_get_type (void); + +NMSIbftConnection *nms_ibft_connection_new (const GPtrArray *block, + GError **error); + +#endif /* __NMS_IBFT_CONNECTION_H__ */ diff --git a/src/settings/plugins/ibft/plugin.c b/src/settings/plugins/ibft/nms-ibft-plugin.c similarity index 77% rename from src/settings/plugins/ibft/plugin.c rename to src/settings/plugins/ibft/nms-ibft-plugin.c index c663e36110..95aa2f4623 100644 --- a/src/settings/plugins/ibft/plugin.c +++ b/src/settings/plugins/ibft/nms-ibft-plugin.c @@ -20,7 +20,7 @@ #include "nm-default.h" -#include "plugin.h" +#include "nms-ibft-plugin.h" #include #include @@ -31,57 +31,57 @@ #include "nm-settings-plugin.h" #include "NetworkManagerUtils.h" -#include "reader.h" -#include "nm-ibft-connection.h" +#include "nms-ibft-reader.h" +#include "nms-ibft-connection.h" /*****************************************************************************/ typedef struct { GHashTable *connections; /* uuid::connection */ gboolean initialized; -} SettingsPluginIbftPrivate; +} NMSIbftPluginPrivate; -struct _SettingsPluginIbft { +struct _NMSIbftPlugin { GObject parent; - SettingsPluginIbftPrivate _priv; + NMSIbftPluginPrivate _priv; }; -struct _SettingsPluginIbftClass { +struct _NMSIbftPluginClass { GObjectClass parent; }; static void settings_plugin_interface_init (NMSettingsPluginInterface *plugin_iface); -G_DEFINE_TYPE_EXTENDED (SettingsPluginIbft, settings_plugin_ibft, G_TYPE_OBJECT, 0, +G_DEFINE_TYPE_EXTENDED (NMSIbftPlugin, nms_ibft_plugin, G_TYPE_OBJECT, 0, G_IMPLEMENT_INTERFACE (NM_TYPE_SETTINGS_PLUGIN, settings_plugin_interface_init)) -#define SETTINGS_PLUGIN_IBFT_GET_PRIVATE(self) _NM_GET_PRIVATE (self, SettingsPluginIbft, SETTINGS_IS_PLUGIN_IBFT) +#define NMS_IBFT_PLUGIN_GET_PRIVATE(self) _NM_GET_PRIVATE (self, NMSIbftPlugin, NMS_IS_IBFT_PLUGIN) /*****************************************************************************/ -static SettingsPluginIbft *settings_plugin_ibft_get (void); +static NMSIbftPlugin *nms_ibft_plugin_get (void); -NM_DEFINE_SINGLETON_GETTER (SettingsPluginIbft, settings_plugin_ibft_get, SETTINGS_TYPE_PLUGIN_IBFT); +NM_DEFINE_SINGLETON_GETTER (NMSIbftPlugin, nms_ibft_plugin_get, NMS_TYPE_IBFT_PLUGIN); /*****************************************************************************/ static void -read_connections (SettingsPluginIbft *self) +read_connections (NMSIbftPlugin *self) { - SettingsPluginIbftPrivate *priv = SETTINGS_PLUGIN_IBFT_GET_PRIVATE (self); + NMSIbftPluginPrivate *priv = NMS_IBFT_PLUGIN_GET_PRIVATE (self); GSList *blocks = NULL, *iter; GError *error = NULL; - NMIbftConnection *connection; + NMSIbftConnection *connection; - if (!read_ibft_blocks ("/sbin/iscsiadm", &blocks, &error)) { + if (!nms_ibft_reader_load_blocks ("/sbin/iscsiadm", &blocks, &error)) { nm_log_dbg (LOGD_SETTINGS, "ibft: failed to read iscsiadm records: %s", error->message); g_error_free (error); return; } for (iter = blocks; iter; iter = iter->next) { - connection = nm_ibft_connection_new (iter->data, &error); + connection = nms_ibft_connection_new (iter->data, &error); if (connection) { nm_log_info (LOGD_SETTINGS, "ibft: read connection '%s'", nm_connection_get_id (NM_CONNECTION (connection))); @@ -100,11 +100,11 @@ read_connections (SettingsPluginIbft *self) static GSList * get_connections (NMSettingsPlugin *config) { - SettingsPluginIbft *self = SETTINGS_PLUGIN_IBFT (config); - SettingsPluginIbftPrivate *priv = SETTINGS_PLUGIN_IBFT_GET_PRIVATE (self); + NMSIbftPlugin *self = NMS_IBFT_PLUGIN (config); + NMSIbftPluginPrivate *priv = NMS_IBFT_PLUGIN_GET_PRIVATE (self); GSList *list = NULL; GHashTableIter iter; - NMIbftConnection *connection; + NMSIbftConnection *connection; if (!priv->initialized) { read_connections (self); @@ -148,9 +148,9 @@ init (NMSettingsPlugin *config) } static void -settings_plugin_ibft_init (SettingsPluginIbft *self) +nms_ibft_plugin_init (NMSIbftPlugin *self) { - SettingsPluginIbftPrivate *priv = SETTINGS_PLUGIN_IBFT_GET_PRIVATE (self); + NMSIbftPluginPrivate *priv = NMS_IBFT_PLUGIN_GET_PRIVATE (self); priv->connections = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref); } @@ -158,19 +158,19 @@ settings_plugin_ibft_init (SettingsPluginIbft *self) static void dispose (GObject *object) { - SettingsPluginIbft *self = SETTINGS_PLUGIN_IBFT (object); - SettingsPluginIbftPrivate *priv = SETTINGS_PLUGIN_IBFT_GET_PRIVATE (self); + NMSIbftPlugin *self = NMS_IBFT_PLUGIN (object); + NMSIbftPluginPrivate *priv = NMS_IBFT_PLUGIN_GET_PRIVATE (self); if (priv->connections) { g_hash_table_destroy (priv->connections); priv->connections = NULL; } - G_OBJECT_CLASS (settings_plugin_ibft_parent_class)->dispose (object); + G_OBJECT_CLASS (nms_ibft_plugin_parent_class)->dispose (object); } static void -settings_plugin_ibft_class_init (SettingsPluginIbftClass *req_class) +nms_ibft_plugin_class_init (NMSIbftPluginClass *req_class) { GObjectClass *object_class = G_OBJECT_CLASS (req_class); @@ -202,5 +202,5 @@ settings_plugin_interface_init (NMSettingsPluginInterface *plugin_iface) G_MODULE_EXPORT GObject * nm_settings_plugin_factory (void) { - return g_object_ref (settings_plugin_ibft_get ()); + return g_object_ref (nms_ibft_plugin_get ()); } diff --git a/src/settings/plugins/ibft/nms-ibft-plugin.h b/src/settings/plugins/ibft/nms-ibft-plugin.h new file mode 100644 index 0000000000..33a7620b09 --- /dev/null +++ b/src/settings/plugins/ibft/nms-ibft-plugin.h @@ -0,0 +1,36 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/* NetworkManager system settings service + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Copyright 2014 Red Hat, Inc. + */ + +#ifndef __NMS_IBFT_PLUGIN_H__ +#define __NMS_IBFT_PLUGIN_H__ + +#define NMS_TYPE_IBFT_PLUGIN (nms_ibft_plugin_get_type ()) +#define NMS_IBFT_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NMS_TYPE_IBFT_PLUGIN, NMSIbftPlugin)) +#define NMS_IBFT_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NMS_TYPE_IBFT_PLUGIN, NMSIbftPluginClass)) +#define NMS_IS_IBFT_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NMS_TYPE_IBFT_PLUGIN)) +#define NMS_IS_IBFT_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NMS_TYPE_IBFT_PLUGIN)) +#define NMS_IBFT_PLUGIN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NMS_TYPE_IBFT_PLUGIN, NMSIbftPluginClass)) + +typedef struct _NMSIbftPlugin NMSIbftPlugin; +typedef struct _NMSIbftPluginClass NMSIbftPluginClass; + +GType nms_ibft_plugin_get_type (void); + +#endif /* __NMS_IBFT_PLUGIN_H__ */ diff --git a/src/settings/plugins/ibft/reader.c b/src/settings/plugins/ibft/nms-ibft-reader.c similarity index 88% rename from src/settings/plugins/ibft/reader.c rename to src/settings/plugins/ibft/nms-ibft-reader.c index c39d875cf9..fa4d7ddb3d 100644 --- a/src/settings/plugins/ibft/reader.c +++ b/src/settings/plugins/ibft/nms-ibft-reader.c @@ -20,6 +20,8 @@ #include "nm-default.h" +#include "nms-ibft-reader.h" + #include #include #include @@ -35,7 +37,7 @@ #include "nm-platform.h" #include "NetworkManagerUtils.h" -#include "reader.h" +/*****************************************************************************/ #define PARSE_WARNING(msg...) nm_log_warn (LOGD_SETTINGS, " " msg) @@ -75,7 +77,7 @@ remove_most_whitespace (const char *src) #define TAG_END "# END RECORD" /** - * read_ibft_blocks: + * nms_ibft_reader_load_blocks: * @iscsiadm_path: path to iscsiadm program * @out_blocks: on return if successful, a #GSList of #GPtrArray, or %NULL on * failure @@ -88,9 +90,9 @@ remove_most_whitespace (const char *src) * Returns: %TRUE on success, %FALSE on errors */ gboolean -read_ibft_blocks (const char *iscsiadm_path, - GSList **out_blocks, - GError **error) +nms_ibft_reader_load_blocks (const char *iscsiadm_path, + GSList **out_blocks, + GError **error) { const char *argv[4] = { iscsiadm_path, "-m", "fw", NULL }; const char *envp[1] = { NULL }; @@ -205,20 +207,20 @@ match_iscsiadm_tag (const char *line, const char *tag) } /** - * parse_ibft_config: - * @data: an array of iscsiadm interface block lines + * nms_ibft_reader_parse_block: + * @block: an array of iscsiadm interface block lines * @error: return location for errors * @...: pairs of key (const char *) : location (const char **) indicating the * key to look for and the location to store the retrieved value in * * Parses an iscsiadm interface block into variables requested by the caller. * Callers should verify the returned data is complete and valid. Returned - * strings are owned by @data and should not be used after @data is freed. + * strings are owned by @block and should not be used after @block is freed. * * Returns: %TRUE if at least , %FALSE on failure */ gboolean -parse_ibft_config (const GPtrArray *data, GError **error, ...) +nms_ibft_reader_parse_block (const GPtrArray *block, GError **error, ...) { gboolean success = FALSE; const char **out_value, *p; @@ -226,16 +228,16 @@ parse_ibft_config (const GPtrArray *data, GError **error, ...) const char *key; guint i; - g_return_val_if_fail (data != NULL, FALSE); - g_return_val_if_fail (data->len > 0, FALSE); + g_return_val_if_fail (block != NULL, FALSE); + g_return_val_if_fail (block->len > 0, FALSE); /* Find requested keys and populate return values */ va_start (ap, error); while ((key = va_arg (ap, const char *))) { out_value = va_arg (ap, const char **); *out_value = NULL; - for (i = 0; i < data->len; i++) { - p = match_iscsiadm_tag (g_ptr_array_index (data, i), key); + for (i = 0; i < block->len; i++) { + p = match_iscsiadm_tag (g_ptr_array_index (block, i), key); if (p) { *out_value = p; success = TRUE; @@ -270,14 +272,14 @@ ip4_setting_add_from_block (const GPtrArray *block, g_assert (block); - if (!parse_ibft_config (block, error, - ISCSI_BOOTPROTO_TAG, &s_method, - ISCSI_IPADDR_TAG, &s_ipaddr, - ISCSI_SUBNET_TAG, &s_netmask, - ISCSI_GATEWAY_TAG, &s_gateway, - ISCSI_DNS1_TAG, &s_dns1, - ISCSI_DNS2_TAG, &s_dns2, - NULL)) + if (!nms_ibft_reader_parse_block (block, error, + ISCSI_BOOTPROTO_TAG, &s_method, + ISCSI_IPADDR_TAG, &s_ipaddr, + ISCSI_SUBNET_TAG, &s_netmask, + ISCSI_GATEWAY_TAG, &s_gateway, + ISCSI_DNS1_TAG, &s_dns1, + ISCSI_DNS2_TAG, &s_dns2, + NULL)) goto error; if (!s_method) { @@ -376,11 +378,11 @@ connection_setting_add (const GPtrArray *block, char *id, *uuid; const char *s_hwaddr = NULL, *s_ip4addr = NULL, *s_vlanid; - if (!parse_ibft_config (block, error, - ISCSI_VLAN_ID_TAG, &s_vlanid, - ISCSI_HWADDR_TAG, &s_hwaddr, - ISCSI_IPADDR_TAG, &s_ip4addr, - NULL)) + if (!nms_ibft_reader_parse_block (block, error, + ISCSI_VLAN_ID_TAG, &s_vlanid, + ISCSI_HWADDR_TAG, &s_hwaddr, + ISCSI_IPADDR_TAG, &s_ip4addr, + NULL)) return FALSE; if (!s_hwaddr) { g_set_error_literal (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, @@ -421,7 +423,7 @@ is_ibft_vlan_device (const GPtrArray *block) { char *s_vlan_id = NULL; - if (parse_ibft_config (block, NULL, ISCSI_VLAN_ID_TAG, &s_vlan_id, NULL)) { + if (nms_ibft_reader_parse_block (block, NULL, ISCSI_VLAN_ID_TAG, &s_vlan_id, NULL)) { g_assert (s_vlan_id); /* VLAN 0 is normally a valid VLAN ID, but in the iBFT case it @@ -449,7 +451,7 @@ vlan_setting_add_from_block (const GPtrArray *block, /* This won't fail since this function shouldn't be called unless the * iBFT VLAN ID exists and is > 0. */ - success = parse_ibft_config (block, NULL, ISCSI_VLAN_ID_TAG, &vlan_id_str, NULL); + success = nms_ibft_reader_parse_block (block, NULL, ISCSI_VLAN_ID_TAG, &vlan_id_str, NULL); g_assert (success); g_assert (vlan_id_str); @@ -479,7 +481,7 @@ wired_setting_add_from_block (const GPtrArray *block, g_assert (block); g_assert (connection); - if (!parse_ibft_config (block, NULL, ISCSI_HWADDR_TAG, &hwaddr, NULL)) { + if (!nms_ibft_reader_parse_block (block, NULL, ISCSI_HWADDR_TAG, &hwaddr, NULL)) { g_set_error_literal (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "iBFT: malformed iscsiadm record: missing " ISCSI_HWADDR_TAG); return FALSE; @@ -500,7 +502,7 @@ wired_setting_add_from_block (const GPtrArray *block, } NMConnection * -connection_from_block (const GPtrArray *block, GError **error) +nms_ibft_reader_get_connection_from_block (const GPtrArray *block, GError **error) { NMConnection *connection = NULL; gboolean is_vlan = FALSE; @@ -508,7 +510,7 @@ connection_from_block (const GPtrArray *block, GError **error) g_assert (block); - if (!parse_ibft_config (block, error, ISCSI_IFACE_TAG, &iface, NULL)) { + if (!nms_ibft_reader_parse_block (block, error, ISCSI_IFACE_TAG, &iface, NULL)) { g_set_error_literal (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "iBFT: malformed iscsiadm record: missing " ISCSI_IFACE_TAG); return NULL; diff --git a/src/settings/plugins/ibft/reader.h b/src/settings/plugins/ibft/nms-ibft-reader.h similarity index 65% rename from src/settings/plugins/ibft/reader.h rename to src/settings/plugins/ibft/nms-ibft-reader.h index 97ef0c71a8..e2be7b02f5 100644 --- a/src/settings/plugins/ibft/reader.h +++ b/src/settings/plugins/ibft/nms-ibft-reader.h @@ -18,18 +18,17 @@ * Copyright 2014 Red Hat, Inc. */ -#ifndef __READER_H__ -#define __READER_H__ +#ifndef __NMS_IBFT_READER_H__ +#define __NMS_IBFT_READER_H__ #include -gboolean read_ibft_blocks (const char *iscsiadm_path, - GSList **out_blocks, - GError **error); +gboolean nms_ibft_reader_load_blocks (const char *iscsiadm_path, + GSList **out_blocks, + GError **error); -NMConnection *connection_from_block (const GPtrArray *block, GError **error); +NMConnection *nms_ibft_reader_get_connection_from_block (const GPtrArray *block, GError **error); -/* For testcases */ -gboolean parse_ibft_config (const GPtrArray *data, GError **error, ...) G_GNUC_NULL_TERMINATED; +gboolean nms_ibft_reader_parse_block (const GPtrArray *block, GError **error, ...) G_GNUC_NULL_TERMINATED; -#endif /* __READER_H__ */ +#endif /* __NMS_IBFT_READER_H__ */ diff --git a/src/settings/plugins/ibft/plugin.h b/src/settings/plugins/ibft/plugin.h deleted file mode 100644 index 5c44a1c950..0000000000 --- a/src/settings/plugins/ibft/plugin.h +++ /dev/null @@ -1,37 +0,0 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* NetworkManager system settings service - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Copyright 2014 Red Hat, Inc. - */ - -#ifndef _PLUGIN_H_ -#define _PLUGIN_H_ - -#define SETTINGS_TYPE_PLUGIN_IBFT (settings_plugin_ibft_get_type ()) -#define SETTINGS_PLUGIN_IBFT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SETTINGS_TYPE_PLUGIN_IBFT, SettingsPluginIbft)) -#define SETTINGS_PLUGIN_IBFT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SETTINGS_TYPE_PLUGIN_IBFT, SettingsPluginIbftClass)) -#define SETTINGS_IS_PLUGIN_IBFT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SETTINGS_TYPE_PLUGIN_IBFT)) -#define SETTINGS_IS_PLUGIN_IBFT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SETTINGS_TYPE_PLUGIN_IBFT)) -#define SETTINGS_PLUGIN_IBFT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SETTINGS_TYPE_PLUGIN_IBFT, SettingsPluginIbftClass)) - -typedef struct _SettingsPluginIbft SettingsPluginIbft; -typedef struct _SettingsPluginIbftClass SettingsPluginIbftClass; - -GType settings_plugin_ibft_get_type (void); - -#endif /* _PLUGIN_H_ */ - diff --git a/src/settings/plugins/ibft/tests/Makefile.am b/src/settings/plugins/ibft/tests/Makefile.am index 2c8df42099..43df1ab77d 100644 --- a/src/settings/plugins/ibft/tests/Makefile.am +++ b/src/settings/plugins/ibft/tests/Makefile.am @@ -27,10 +27,10 @@ AM_LDFLAGS = \ noinst_PROGRAMS = test-ibft test_ibft_SOURCES = \ - test-ibft.c \ - ../reader.c + test-ibft.c test_ibft_LDADD = \ + $(top_builddir)/src/settings/plugins/ibft/libnms-ibft-core.la \ $(top_builddir)/src/libNetworkManager.la @VALGRIND_RULES@ diff --git a/src/settings/plugins/ibft/tests/test-ibft.c b/src/settings/plugins/ibft/tests/test-ibft.c index cab468dec9..3d61817612 100644 --- a/src/settings/plugins/ibft/tests/test-ibft.c +++ b/src/settings/plugins/ibft/tests/test-ibft.c @@ -32,7 +32,7 @@ #include "nm-core-internal.h" #include "NetworkManagerUtils.h" -#include "reader.h" +#include "nms-ibft-reader.h" #include "nm-test-utils-core.h" @@ -44,7 +44,7 @@ read_block (const char *iscsiadm_path, const char *expected_mac) GError *error = NULL; gboolean success; - success = read_ibft_blocks (iscsiadm_path, &blocks, &error); + success = nms_ibft_reader_load_blocks (iscsiadm_path, &blocks, &error); g_assert_no_error (error); g_assert (success); g_assert (blocks); @@ -52,7 +52,7 @@ read_block (const char *iscsiadm_path, const char *expected_mac) for (iter = blocks; iter; iter = iter->next) { const char *s_hwaddr = NULL; - if (!parse_ibft_config (iter->data, NULL, "iface.hwaddress", &s_hwaddr, NULL)) + if (!nms_ibft_reader_parse_block (iter->data, NULL, "iface.hwaddress", &s_hwaddr, NULL)) continue; g_assert (s_hwaddr); if (nm_utils_hwaddr_matches (s_hwaddr, -1, expected_mac, -1)) { @@ -80,7 +80,7 @@ test_read_ibft_dhcp (void) block = read_block (TEST_IBFT_DIR "/iscsiadm-test-dhcp", expected_mac_address); - connection = connection_from_block (block, &error); + connection = nms_ibft_reader_get_connection_from_block (block, &error); g_assert_no_error (error); nmtst_assert_connection_verifies_without_normalization (connection); @@ -127,7 +127,7 @@ test_read_ibft_static (void) block = read_block (TEST_IBFT_DIR "/iscsiadm-test-static", expected_mac_address); - connection = connection_from_block (block, &error); + connection = nms_ibft_reader_get_connection_from_block (block, &error); g_assert_no_error (error); nmtst_assert_connection_verifies_without_normalization (connection); @@ -183,7 +183,7 @@ test_read_ibft_malformed (gconstpointer user_data) g_test_expect_message ("NetworkManager", G_LOG_LEVEL_MESSAGE, "*malformed iscsiadm record*"); - success = read_ibft_blocks (iscsiadm_path, &blocks, &error); + success = nms_ibft_reader_load_blocks (iscsiadm_path, &blocks, &error); g_assert_no_error (error); g_assert (success); g_assert (blocks == NULL); @@ -204,7 +204,7 @@ test_read_ibft_bad_address (gconstpointer user_data) block = read_block (iscsiadm_path, expected_mac_address); - connection = connection_from_block (block, &error); + connection = nms_ibft_reader_get_connection_from_block (block, &error); g_assert_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION); g_assert (strstr (error->message, "iBFT: malformed iscsiadm record: invalid")); g_clear_error (&error); @@ -229,7 +229,7 @@ test_read_ibft_vlan (void) block = read_block (TEST_IBFT_DIR "/iscsiadm-test-vlan", expected_mac_address); - connection = connection_from_block (block, &error); + connection = nms_ibft_reader_get_connection_from_block (block, &error); g_assert_no_error (error); nmtst_assert_connection_verifies_without_normalization (connection); diff --git a/src/settings/plugins/ifcfg-rh/Makefile.am b/src/settings/plugins/ifcfg-rh/Makefile.am index 2792d68c62..44acd7f041 100644 --- a/src/settings/plugins/ifcfg-rh/Makefile.am +++ b/src/settings/plugins/ifcfg-rh/Makefile.am @@ -2,9 +2,35 @@ SUBDIRS = . tests @GNOME_CODE_COVERAGE_RULES@ -# See note about gdbus-codegen in introspection/Makefile.am +pkglib_LTLIBRARIES = \ + libnm-settings-plugin-ifcfg-rh.la -noinst_LTLIBRARIES = libnmdbus-ifcfg-rh.la +noinst_LTLIBRARIES = \ + libnmdbus-ifcfg-rh.la \ + libnms-ifcfg-rh-core.la + +BUILT_SOURCES = \ + nmdbus-ifcfg-rh.h \ + nmdbus-ifcfg-rh.c + +############################################################################### + +AM_CPPFLAGS = \ + -I$(top_srcdir)/src/ \ + -I$(top_srcdir)/src/platform \ + -I$(top_srcdir)/src/settings \ + -I$(top_srcdir)/shared \ + -I$(top_builddir)/shared \ + -I$(top_srcdir)/libnm-core \ + -I$(top_builddir)/libnm-core \ + -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \ + $(GLIB_CFLAGS) \ + $(NSS_CFLAGS) \ + -DG_LOG_DOMAIN=\""NetworkManager"\" \ + -DSYSCONFDIR=\"$(sysconfdir)\" \ + -DSBINDIR=\"$(sbindir)\" + +############################################################################### nodist_libnmdbus_ifcfg_rh_la_SOURCES = \ nmdbus-ifcfg-rh.c \ @@ -22,46 +48,35 @@ nmdbus-ifcfg-rh.h: nm-ifcfg-rh.xml nmdbus-ifcfg-rh.c: nmdbus-ifcfg-rh.h @true -BUILT_SOURCES = nmdbus-ifcfg-rh.h nmdbus-ifcfg-rh.c +############################################################################### -pkglib_LTLIBRARIES = libnm-settings-plugin-ifcfg-rh.la - -noinst_LTLIBRARIES += libifcfg-rh-io.la - -libifcfg_rh_io_la_SOURCES = \ +libnms_ifcfg_rh_core_la_SOURCES = \ + nms-ifcfg-rh-common.h \ shvar.c \ shvar.h \ - reader.c \ - reader.h \ - writer.c \ - writer.h \ - common.h \ - utils.c \ - utils.h + nms-ifcfg-rh-utils.c \ + nms-ifcfg-rh-utils.h \ + nms-ifcfg-rh-reader.c \ + nms-ifcfg-rh-reader.h \ + nms-ifcfg-rh-writer.c \ + nms-ifcfg-rh-writer.h -AM_CPPFLAGS = \ - -I$(top_srcdir)/src/ \ - -I$(top_srcdir)/src/platform \ - -I$(top_srcdir)/src/settings \ - -I$(top_srcdir)/shared \ - -I$(top_builddir)/shared \ - -I$(top_srcdir)/libnm-core \ - -I$(top_builddir)/libnm-core \ - -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \ - $(GLIB_CFLAGS) \ - $(NSS_CFLAGS) \ - -DG_LOG_DOMAIN=\""NetworkManager"\" \ - -DSYSCONFDIR=\"$(sysconfdir)\" \ - -DSBINDIR=\"$(sbindir)\" +############################################################################### -libnm_settings_plugin_ifcfg_rh_la_SOURCES = \ - plugin.c \ - plugin.h \ - nm-ifcfg-connection.c \ - nm-ifcfg-connection.h +libnm_settings_plugin_ifcfg_rh_la_SOURCES = + nms-ifcfg-rh-connection.c \ + nms-ifcfg-rh-connection.h \ + nms-ifcfg-rh-plugin.c \ + nms-ifcfg-rh-plugin.h -libnm_settings_plugin_ifcfg_rh_la_LDFLAGS = -module -avoid-version -libnm_settings_plugin_ifcfg_rh_la_LIBADD = libifcfg-rh-io.la libnmdbus-ifcfg-rh.la +libnm_settings_plugin_ifcfg_rh_la_LDFLAGS = \ + -module -avoid-version + +libnm_settings_plugin_ifcfg_rh_la_LIBADD = \ + libnms-ifcfg-rh-core.la \ + libnmdbus-ifcfg-rh.la + +############################################################################### dbusservicedir = $(DBUS_SYS_DIR) dbusservice_DATA = nm-ifcfg-rh.conf diff --git a/src/settings/plugins/ifcfg-rh/common.h b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-common.h similarity index 100% rename from src/settings/plugins/ifcfg-rh/common.h rename to src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-common.h diff --git a/src/settings/plugins/ifcfg-rh/nm-ifcfg-connection.c b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-connection.c similarity index 99% rename from src/settings/plugins/ifcfg-rh/nm-ifcfg-connection.c rename to src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-connection.c index 09c585a9da..e4afbc2dab 100644 --- a/src/settings/plugins/ifcfg-rh/nm-ifcfg-connection.c +++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-connection.c @@ -20,7 +20,7 @@ #include "nm-default.h" -#include "nm-ifcfg-connection.h" +#include "nms-ifcfg-rh-connection.h" #include #include @@ -36,13 +36,13 @@ #include "nm-setting-wireless-security.h" #include "nm-setting-8021x.h" #include "nm-platform.h" - -#include "common.h" -#include "nm-config.h" -#include "reader.h" -#include "writer.h" #include "nm-inotify-helper.h" -#include "utils.h" +#include "nm-config.h" + +#include "nms-ifcfg-rh-common.h" +#include "nms-ifcfg-rh-reader.h" +#include "nms-ifcfg-rh-writer.h" +#include "nms-ifcfg-rh-utils.h" /*****************************************************************************/ diff --git a/src/settings/plugins/ifcfg-rh/nm-ifcfg-connection.h b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-connection.h similarity index 100% rename from src/settings/plugins/ifcfg-rh/nm-ifcfg-connection.h rename to src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-connection.h diff --git a/src/settings/plugins/ifcfg-rh/plugin.c b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-plugin.c similarity index 99% rename from src/settings/plugins/ifcfg-rh/plugin.c rename to src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-plugin.c index 77bd32499f..7532da75e6 100644 --- a/src/settings/plugins/ifcfg-rh/plugin.c +++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-plugin.c @@ -23,7 +23,7 @@ #include "nm-default.h" -#include "plugin.h" +#include "nms-ifcfg-rh-plugin.h" #include #include @@ -39,12 +39,12 @@ #include "NetworkManagerUtils.h" #include "nm-exported-object.h" -#include "nm-ifcfg-connection.h" +#include "nms-ifcfg-rh-connection.h" +#include "nms-ifcfg-rh-common.h" +#include "nms-ifcfg-rh-reader.h" +#include "nms-ifcfg-rh-writer.h" +#include "nms-ifcfg-rh-utils.h" #include "shvar.h" -#include "common.h" -#include "reader.h" -#include "writer.h" -#include "utils.h" #include "nmdbus-ifcfg-rh.h" diff --git a/src/settings/plugins/ifcfg-rh/plugin.h b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-plugin.h similarity index 100% rename from src/settings/plugins/ifcfg-rh/plugin.h rename to src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-plugin.h diff --git a/src/settings/plugins/ifcfg-rh/reader.c b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c similarity index 99% rename from src/settings/plugins/ifcfg-rh/reader.c rename to src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c index c46a454633..5b9e8f34c0 100644 --- a/src/settings/plugins/ifcfg-rh/reader.c +++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c @@ -20,7 +20,7 @@ #include "nm-default.h" -#include "reader.h" +#include "nms-ifcfg-rh-reader.h" #include #include @@ -56,9 +56,9 @@ #include "nm-platform.h" #include "NetworkManagerUtils.h" -#include "common.h" +#include "nms-ifcfg-rh-common.h" +#include "nms-ifcfg-rh-utils.h" #include "shvar.h" -#include "utils.h" /*****************************************************************************/ @@ -145,7 +145,7 @@ make_connection_setting (const char *file, uuid = svGetValue (ifcfg, "UUID", FALSE); if (!uuid || !strlen (uuid)) { g_free (uuid); - uuid = nm_utils_uuid_generate_from_string (ifcfg->fileName, -1, NM_UTILS_UUID_TYPE_LEGACY, NULL); + uuid = nm_utils_uuid_generate_from_string (svFileGetName (ifcfg), -1, NM_UTILS_UUID_TYPE_LEGACY, NULL); } stable_id = svGetValue (ifcfg, "STABLE_ID", FALSE); @@ -1130,7 +1130,7 @@ make_ip4_setting (shvarFile *ifcfg, goto done; if (gateway && nm_setting_ip_config_get_num_addresses (s_ip4) == 0) { - gs_free char *f = g_path_get_basename (ifcfg->fileName); + gs_free char *f = g_path_get_basename (svFileGetName (ifcfg)); PARSE_WARNING ("ignoring GATEWAY (/etc/sysconfig/network) for %s " "because the connection has no static addresses", f); g_clear_pointer (&gateway, g_free); @@ -1204,13 +1204,13 @@ make_ip4_setting (shvarFile *ifcfg, NULL); /* Static routes - route- file */ - route_path = utils_get_route_path (ifcfg->fileName); + route_path = utils_get_route_path (svFileGetName (ifcfg)); if (utils_has_complex_routes (route_path)) { PARSE_WARNING ("'rule-' or 'rule6-' file is present; you will need to use a dispatcher script to apply these routes"); } else if (utils_has_route_file_new_syntax (route_path)) { /* Parse route file in new syntax */ - route_ifcfg = utils_get_route_ifcfg (ifcfg->fileName, FALSE); + route_ifcfg = utils_get_route_ifcfg (svFileGetName (ifcfg), FALSE); if (route_ifcfg) { for (i = 0; i < 256; i++) { NMIPRoute *route = NULL; @@ -1626,9 +1626,9 @@ make_ip6_setting (shvarFile *ifcfg, /* DNS searches ('DOMAIN' key) are read by make_ip4_setting() and included in NMSettingIPConfig */ - if (!utils_has_complex_routes (ifcfg->fileName)) { + if (!utils_has_complex_routes (svFileGetName (ifcfg))) { /* Read static routes from route6- file */ - route6_path = utils_get_route6_path (ifcfg->fileName); + route6_path = utils_get_route6_path (svFileGetName (ifcfg)); if (!read_route6_file (route6_path, s_ip6, error)) goto error; @@ -2596,7 +2596,7 @@ eap_tls_reader (const char *eap_method, ca_cert = svGetValue (ifcfg, ca_cert_key, FALSE); if (ca_cert) { - real_path = get_full_file_path (ifcfg->fileName, ca_cert); + real_path = get_full_file_path (svFileGetName (ifcfg), ca_cert); if (phase2) { if (!nm_setting_802_1x_set_phase2_ca_cert (s_8021x, real_path, @@ -2651,7 +2651,7 @@ eap_tls_reader (const char *eap_method, goto done; } - real_path = get_full_file_path (ifcfg->fileName, privkey); + real_path = get_full_file_path (svFileGetName (ifcfg), privkey); if (phase2) { if (!nm_setting_802_1x_set_phase2_private_key (s_8021x, real_path, @@ -2688,7 +2688,7 @@ eap_tls_reader (const char *eap_method, goto done; } - real_path = get_full_file_path (ifcfg->fileName, client_cert); + real_path = get_full_file_path (svFileGetName (ifcfg), client_cert); if (phase2) { if (!nm_setting_802_1x_set_phase2_client_cert (s_8021x, real_path, @@ -2738,7 +2738,7 @@ eap_peap_reader (const char *eap_method, ca_cert = svGetValue (ifcfg, "IEEE_8021X_CA_CERT", FALSE); if (ca_cert) { - real_cert_path = get_full_file_path (ifcfg->fileName, ca_cert); + real_cert_path = get_full_file_path (svFileGetName (ifcfg), ca_cert); if (!nm_setting_802_1x_set_ca_cert (s_8021x, real_cert_path, NM_SETTING_802_1X_CK_SCHEME_PATH, @@ -2842,7 +2842,7 @@ eap_ttls_reader (const char *eap_method, ca_cert = svGetValue (ifcfg, "IEEE_8021X_CA_CERT", FALSE); if (ca_cert) { - real_cert_path = get_full_file_path (ifcfg->fileName, ca_cert); + real_cert_path = get_full_file_path (svFileGetName (ifcfg), ca_cert); if (!nm_setting_802_1x_set_ca_cert (s_8021x, real_cert_path, NM_SETTING_802_1X_CK_SCHEME_PATH, @@ -2933,7 +2933,7 @@ eap_fast_reader (const char *eap_method, pac_file = svGetValue (ifcfg, "IEEE_8021X_PAC_FILE", FALSE); if (pac_file) { - real_pac_path = get_full_file_path (ifcfg->fileName, pac_file); + real_pac_path = get_full_file_path (svFileGetName (ifcfg), pac_file); g_object_set (s_8021x, NM_SETTING_802_1X_PAC_FILE, real_pac_path, NULL); } @@ -4971,7 +4971,7 @@ uuid_from_file (const char *filename) uuid = svGetValue (ifcfg, "UUID", FALSE); if (!uuid || !strlen (uuid)) { g_free (uuid); - uuid = nm_utils_uuid_generate_from_string (ifcfg->fileName, -1, NM_UTILS_UUID_TYPE_LEGACY, NULL); + uuid = nm_utils_uuid_generate_from_string (svFileGetName (ifcfg), -1, NM_UTILS_UUID_TYPE_LEGACY, NULL); } svCloseFile (ifcfg); diff --git a/src/settings/plugins/ifcfg-rh/reader.h b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.h similarity index 100% rename from src/settings/plugins/ifcfg-rh/reader.h rename to src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.h diff --git a/src/settings/plugins/ifcfg-rh/utils.c b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.c similarity index 99% rename from src/settings/plugins/ifcfg-rh/utils.c rename to src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.c index b9d52b7f4c..9cb44b19c6 100644 --- a/src/settings/plugins/ifcfg-rh/utils.c +++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.c @@ -20,7 +20,7 @@ #include "nm-default.h" -#include "utils.h" +#include "nms-ifcfg-rh-utils.h" #include #include @@ -28,7 +28,7 @@ #include "nm-core-internal.h" #include "NetworkManagerUtils.h" -#include "common.h" +#include "nms-ifcfg-rh-common.h" /* * utils_single_quote_string diff --git a/src/settings/plugins/ifcfg-rh/utils.h b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.h similarity index 100% rename from src/settings/plugins/ifcfg-rh/utils.h rename to src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.h diff --git a/src/settings/plugins/ifcfg-rh/writer.c b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c similarity index 91% rename from src/settings/plugins/ifcfg-rh/writer.c rename to src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c index 8dc4cbe2af..d43d8e926f 100644 --- a/src/settings/plugins/ifcfg-rh/writer.c +++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c @@ -20,7 +20,7 @@ #include "nm-default.h" -#include "writer.h" +#include "nms-ifcfg-rh-writer.h" #include #include @@ -47,10 +47,10 @@ #include "nm-core-internal.h" #include "NetworkManagerUtils.h" -#include "common.h" +#include "nms-ifcfg-rh-common.h" +#include "nms-ifcfg-rh-reader.h" +#include "nms-ifcfg-rh-utils.h" #include "shvar.h" -#include "reader.h" -#include "utils.h" /*****************************************************************************/ @@ -77,7 +77,7 @@ save_secret_flags (shvarFile *ifcfg, g_return_if_fail (key != NULL); if (flags == NM_SETTING_SECRET_FLAG_NONE) { - svSetValue (ifcfg, key, NULL, FALSE); + svUnsetValue (ifcfg, key); return; } @@ -114,27 +114,26 @@ set_secret (shvarFile *ifcfg, GError *error = NULL; /* Clear the secret from the ifcfg and the associated "keys" file */ - svSetValue (ifcfg, key, NULL, FALSE); + svUnsetValue (ifcfg, key); /* Save secret flags */ save_secret_flags (ifcfg, flags_key, flags); - keyfile = utils_get_keys_ifcfg (ifcfg->fileName, TRUE); + keyfile = utils_get_keys_ifcfg (svFileGetName (ifcfg), TRUE); if (!keyfile) { - _LOGW ("could not create ifcfg file for '%s'", ifcfg->fileName); + _LOGW ("could not create ifcfg file for '%s'", svFileGetName (ifcfg)); goto error; } - /* Clear the secret from the associated "keys" file */ - svSetValue (keyfile, key, NULL, FALSE); - /* Only write the secret if it's system owned and supposed to be saved */ if (flags == NM_SETTING_SECRET_FLAG_NONE) svSetValue (keyfile, key, value, verbatim); + else + svUnsetValue (keyfile, key); if (!svWriteFile (keyfile, 0600, &error)) { _LOGW ("could not update ifcfg file '%s': %s", - keyfile->fileName, error->message); + svFileGetName (keyfile), error->message); g_clear_error (&error); svCloseFile (keyfile); goto error; @@ -322,12 +321,12 @@ write_object (NMSetting8021x *s_8021x, * /etc/sysconfig/network-scripts/ca-cert-Test_Write_Wifi_WPA_EAP-TLS.der * will be deleted, but /etc/pki/tls/cert.pem will not. */ - standard_file = utils_cert_path (ifcfg->fileName, objtype->suffix); + standard_file = utils_cert_path (svFileGetName (ifcfg), objtype->suffix); if (g_file_test (standard_file, G_FILE_TEST_EXISTS)) ignored = unlink (standard_file); g_free (standard_file); - svSetValue (ifcfg, objtype->ifcfg_key, NULL, FALSE); + svUnsetValue (ifcfg, objtype->ifcfg_key); return TRUE; } @@ -345,7 +344,7 @@ write_object (NMSetting8021x *s_8021x, char *new_file; GError *write_error = NULL; - new_file = utils_cert_path (ifcfg->fileName, objtype->suffix); + new_file = utils_cert_path (svFileGetName (ifcfg), objtype->suffix); if (!new_file) { g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, "Could not create file path for %s / %s", @@ -471,7 +470,7 @@ write_8021x_setting (NMConnection *connection, if (!s_8021x) { /* If wired, clear KEY_MGMT */ if (wired) - svSetValue (ifcfg, "KEY_MGMT", NULL, FALSE); + svUnsetValue (ifcfg, "KEY_MGMT"); return TRUE; } @@ -485,7 +484,7 @@ write_8021x_setting (NMConnection *connection, if (value) tmp = g_ascii_strup (value, -1); } - svSetValue (ifcfg, "IEEE_8021X_EAP_METHODS", tmp ? tmp : NULL, FALSE); + svSetValue (ifcfg, "IEEE_8021X_EAP_METHODS", tmp, FALSE); g_free (tmp); svSetValue (ifcfg, "IEEE_8021X_IDENTITY", @@ -505,25 +504,25 @@ write_8021x_setting (NMConnection *connection, /* PEAP version */ value = nm_setting_802_1x_get_phase1_peapver (s_8021x); - svSetValue (ifcfg, "IEEE_8021X_PEAP_VERSION", NULL, FALSE); + svUnsetValue (ifcfg, "IEEE_8021X_PEAP_VERSION"); if (value && (!strcmp (value, "0") || !strcmp (value, "1"))) svSetValue (ifcfg, "IEEE_8021X_PEAP_VERSION", value, FALSE); /* Force new PEAP label */ value = nm_setting_802_1x_get_phase1_peaplabel (s_8021x); - svSetValue (ifcfg, "IEEE_8021X_PEAP_FORCE_NEW_LABEL", NULL, FALSE); + svUnsetValue (ifcfg, "IEEE_8021X_PEAP_FORCE_NEW_LABEL"); if (value && !strcmp (value, "1")) svSetValue (ifcfg, "IEEE_8021X_PEAP_FORCE_NEW_LABEL", "yes", FALSE); /* PAC file */ value = nm_setting_802_1x_get_pac_file (s_8021x); - svSetValue (ifcfg, "IEEE_8021X_PAC_FILE", NULL, FALSE); + svUnsetValue (ifcfg, "IEEE_8021X_PAC_FILE"); if (value) svSetValue (ifcfg, "IEEE_8021X_PAC_FILE", value, FALSE); /* FAST PAC provisioning */ value = nm_setting_802_1x_get_phase1_fast_provisioning (s_8021x); - svSetValue (ifcfg, "IEEE_8021X_FAST_PROVISIONING", NULL, FALSE); + svUnsetValue (ifcfg, "IEEE_8021X_FAST_PROVISIONING"); if (value) { if (strcmp (value, "1") == 0) svSetValue (ifcfg, "IEEE_8021X_FAST_PROVISIONING", "allow-unauth", FALSE); @@ -534,7 +533,7 @@ write_8021x_setting (NMConnection *connection, } /* Phase2 auth methods */ - svSetValue (ifcfg, "IEEE_8021X_INNER_AUTH_METHODS", NULL, FALSE); + svUnsetValue (ifcfg, "IEEE_8021X_INNER_AUTH_METHODS"); phase2_auth = g_string_new (NULL); value = nm_setting_802_1x_get_phase2_auth (s_8021x); @@ -568,7 +567,7 @@ write_8021x_setting (NMConnection *connection, nm_setting_802_1x_get_phase2_subject_match (s_8021x), FALSE); - svSetValue (ifcfg, "IEEE_8021X_ALTSUBJECT_MATCHES", NULL, FALSE); + svUnsetValue (ifcfg, "IEEE_8021X_ALTSUBJECT_MATCHES"); str = g_string_new (NULL); num = nm_setting_802_1x_get_num_altsubject_matches (s_8021x); for (i = 0; i < num; i++) { @@ -581,7 +580,7 @@ write_8021x_setting (NMConnection *connection, svSetValue (ifcfg, "IEEE_8021X_ALTSUBJECT_MATCHES", str->str, FALSE); g_string_free (str, TRUE); - svSetValue (ifcfg, "IEEE_8021X_PHASE2_ALTSUBJECT_MATCHES", NULL, FALSE); + svUnsetValue (ifcfg, "IEEE_8021X_PHASE2_ALTSUBJECT_MATCHES"); str = g_string_new (NULL); num = nm_setting_802_1x_get_num_phase2_altsubject_matches (s_8021x); for (i = 0; i < num; i++) { @@ -636,10 +635,10 @@ write_wireless_security_setting (NMConnection *connection, auth_alg = nm_setting_wireless_security_get_auth_alg (s_wsec); - svSetValue (ifcfg, "DEFAULTKEY", NULL, FALSE); + svUnsetValue (ifcfg, "DEFAULTKEY"); if (!strcmp (key_mgmt, "none")) { - svSetValue (ifcfg, "KEY_MGMT", NULL, FALSE); + svUnsetValue (ifcfg, "KEY_MGMT"); wep = TRUE; *no_8021x = TRUE; } else if (!strcmp (key_mgmt, "wpa-none") || !strcmp (key_mgmt, "wpa-psk")) { @@ -654,7 +653,7 @@ write_wireless_security_setting (NMConnection *connection, wpa = TRUE; } - svSetValue (ifcfg, "SECURITYMODE", NULL, FALSE); + svUnsetValue (ifcfg, "SECURITYMODE"); if (auth_alg) { if (!strcmp (auth_alg, "shared")) svSetValue (ifcfg, "SECURITYMODE", "restricted", FALSE); @@ -746,8 +745,8 @@ write_wireless_security_setting (NMConnection *connection, } /* WPA protos */ - svSetValue (ifcfg, "WPA_ALLOW_WPA", NULL, FALSE); - svSetValue (ifcfg, "WPA_ALLOW_WPA2", NULL, FALSE); + svUnsetValue (ifcfg, "WPA_ALLOW_WPA"); + svUnsetValue (ifcfg, "WPA_ALLOW_WPA2"); num = nm_setting_wireless_security_get_num_protos (s_wsec); for (i = 0; i < num; i++) { proto = nm_setting_wireless_security_get_proto (s_wsec, i); @@ -758,7 +757,7 @@ write_wireless_security_setting (NMConnection *connection, } /* WPA Pairwise ciphers */ - svSetValue (ifcfg, "CIPHER_PAIRWISE", NULL, FALSE); + svUnsetValue (ifcfg, "CIPHER_PAIRWISE"); str = g_string_new (NULL); num = nm_setting_wireless_security_get_num_pairwise (s_wsec); for (i = 0; i < num; i++) { @@ -780,7 +779,7 @@ write_wireless_security_setting (NMConnection *connection, g_string_free (str, TRUE); /* WPA Group ciphers */ - svSetValue (ifcfg, "CIPHER_GROUP", NULL, FALSE); + svUnsetValue (ifcfg, "CIPHER_GROUP"); str = g_string_new (NULL); num = nm_setting_wireless_security_get_num_groups (s_wsec); for (i = 0; i < num; i++) { @@ -858,7 +857,7 @@ write_wireless_setting (NMConnection *connection, nm_setting_wireless_get_generate_mac_address_mask (s_wireless), FALSE); - svSetValue (ifcfg, "HWADDR_BLACKLIST", NULL, FALSE); + svUnsetValue (ifcfg, "HWADDR_BLACKLIST"); macaddr_blacklist = nm_setting_wireless_get_mac_address_blacklist (s_wireless); if (macaddr_blacklist[0]) { char *blacklist_str; @@ -868,7 +867,7 @@ write_wireless_setting (NMConnection *connection, g_free (blacklist_str); } - svSetValue (ifcfg, "MTU", NULL, FALSE); + svUnsetValue (ifcfg, "MTU"); mtu = nm_setting_wireless_get_mtu (s_wireless); if (mtu) { tmp = g_strdup_printf ("%u", mtu); @@ -944,8 +943,8 @@ write_wireless_setting (NMConnection *connection, return FALSE; } - svSetValue (ifcfg, "CHANNEL", NULL, FALSE); - svSetValue (ifcfg, "BAND", NULL, FALSE); + svUnsetValue (ifcfg, "CHANNEL"); + svUnsetValue (ifcfg, "BAND"); chan = nm_setting_wireless_get_channel (s_wireless); if (chan) { tmp = g_strdup_printf ("%u", chan); @@ -963,8 +962,8 @@ write_wireless_setting (NMConnection *connection, * otherwise there's no way to detect WEP vs. open when WEP keys aren't * saved. */ - svSetValue (ifcfg, "DEFAULTKEY", NULL, FALSE); - svSetValue (ifcfg, "SECURITYMODE", NULL, FALSE); + svUnsetValue (ifcfg, "DEFAULTKEY"); + svUnsetValue (ifcfg, "SECURITYMODE"); if (nm_connection_get_setting_wireless_security (connection)) { if (!write_wireless_security_setting (connection, ifcfg, adhoc, no_8021x, error)) @@ -973,10 +972,10 @@ write_wireless_setting (NMConnection *connection, char *keys_path; /* Clear out wifi security keys */ - svSetValue (ifcfg, "KEY_MGMT", NULL, FALSE); - svSetValue (ifcfg, "IEEE_8021X_IDENTITY", NULL, FALSE); + svUnsetValue (ifcfg, "KEY_MGMT"); + svUnsetValue (ifcfg, "IEEE_8021X_IDENTITY"); set_secret (ifcfg, "IEEE_8021X_PASSWORD", NULL, "IEEE_8021X_PASSWORD_FLAGS", NM_SETTING_SECRET_FLAG_NONE, FALSE); - svSetValue (ifcfg, "SECURITYMODE", NULL, FALSE); + svUnsetValue (ifcfg, "SECURITYMODE"); /* Clear existing keys */ set_secret (ifcfg, "KEY", NULL, "WEP_KEY_FLAGS", NM_SETTING_SECRET_FLAG_NONE, FALSE); @@ -990,15 +989,15 @@ write_wireless_setting (NMConnection *connection, g_free (tmp); } - svSetValue (ifcfg, "DEFAULTKEY", NULL, FALSE); - svSetValue (ifcfg, "WPA_ALLOW_WPA", NULL, FALSE); - svSetValue (ifcfg, "WPA_ALLOW_WPA2", NULL, FALSE); - svSetValue (ifcfg, "CIPHER_PAIRWISE", NULL, FALSE); - svSetValue (ifcfg, "CIPHER_GROUP", NULL, FALSE); + svUnsetValue (ifcfg, "DEFAULTKEY"); + svUnsetValue (ifcfg, "WPA_ALLOW_WPA"); + svUnsetValue (ifcfg, "WPA_ALLOW_WPA2"); + svUnsetValue (ifcfg, "CIPHER_PAIRWISE"); + svUnsetValue (ifcfg, "CIPHER_GROUP"); set_secret (ifcfg, "WPA_PSK", NULL, "WPA_PSK_FLAGS", NM_SETTING_SECRET_FLAG_NONE, FALSE); /* Kill any old keys file */ - keys_path = utils_get_keys_path (ifcfg->fileName); + keys_path = utils_get_keys_path (svFileGetName (ifcfg)); (void) unlink (keys_path); g_free (keys_path); } @@ -1017,11 +1016,11 @@ write_wireless_setting (NMConnection *connection, break; default: case NM_SETTING_WIRELESS_POWERSAVE_DEFAULT: - svSetValue (ifcfg, "POWERSAVE", NULL, TRUE); + svUnsetValue (ifcfg, "POWERSAVE"); break; } - svSetValue (ifcfg, "MAC_ADDRESS_RANDOMIZATION", NULL, TRUE); + svUnsetValue (ifcfg, "MAC_ADDRESS_RANDOMIZATION"); switch (nm_setting_wireless_get_mac_address_randomization (s_wireless)) { case NM_SETTING_MAC_RANDOMIZATION_DEFAULT: svSetValue (ifcfg, "MAC_ADDRESS_RANDOMIZATION", "default", TRUE); @@ -1059,7 +1058,7 @@ write_infiniband_setting (NMConnection *connection, shvarFile *ifcfg, GError **e mac = nm_setting_infiniband_get_mac_address (s_infiniband); svSetValue (ifcfg, "HWADDR", mac, FALSE); - svSetValue (ifcfg, "MTU", NULL, FALSE); + svUnsetValue (ifcfg, "MTU"); mtu = nm_setting_infiniband_get_mtu (s_infiniband); if (mtu) { tmp = g_strdup_printf ("%u", mtu); @@ -1120,7 +1119,7 @@ write_wired_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) nm_setting_wired_get_generate_mac_address_mask (s_wired), FALSE); - svSetValue (ifcfg, "HWADDR_BLACKLIST", NULL, FALSE); + svUnsetValue (ifcfg, "HWADDR_BLACKLIST"); macaddr_blacklist = nm_setting_wired_get_mac_address_blacklist (s_wired); if (macaddr_blacklist[0]) { char *blacklist_str; @@ -1130,7 +1129,7 @@ write_wired_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) g_free (blacklist_str); } - svSetValue (ifcfg, "MTU", NULL, FALSE); + svUnsetValue (ifcfg, "MTU"); mtu = nm_setting_wired_get_mtu (s_wired); if (mtu) { tmp = g_strdup_printf ("%u", mtu); @@ -1138,7 +1137,7 @@ write_wired_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) g_free (tmp); } - svSetValue (ifcfg, "SUBCHANNELS", NULL, FALSE); + svUnsetValue (ifcfg, "SUBCHANNELS"); s390_subchannels = nm_setting_wired_get_s390_subchannels (s_wired); if (s390_subchannels) { int len = g_strv_length ((char **)s390_subchannels); @@ -1154,22 +1153,22 @@ write_wired_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) g_free (tmp); } - svSetValue (ifcfg, "NETTYPE", NULL, FALSE); + svUnsetValue (ifcfg, "NETTYPE"); nettype = nm_setting_wired_get_s390_nettype (s_wired); if (nettype) svSetValue (ifcfg, "NETTYPE", nettype, FALSE); - svSetValue (ifcfg, "PORTNAME", NULL, FALSE); + svUnsetValue (ifcfg, "PORTNAME"); portname = nm_setting_wired_get_s390_option_by_key (s_wired, "portname"); if (portname) svSetValue (ifcfg, "PORTNAME", portname, FALSE); - svSetValue (ifcfg, "CTCPROT", NULL, FALSE); + svUnsetValue (ifcfg, "CTCPROT"); ctcprot = nm_setting_wired_get_s390_option_by_key (s_wired, "ctcprot"); if (ctcprot) svSetValue (ifcfg, "CTCPROT", ctcprot, FALSE); - svSetValue (ifcfg, "OPTIONS", NULL, FALSE); + svUnsetValue (ifcfg, "OPTIONS"); num_opts = nm_setting_wired_get_num_s390_options (s_wired); if (s390_subchannels && num_opts) { str = g_string_sized_new (30); @@ -1194,7 +1193,7 @@ write_wired_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) if (wol == NM_SETTING_WIRED_WAKE_ON_LAN_IGNORE) svSetValueFull (ifcfg, "ETHTOOL_OPTS", "", FALSE); else if (wol == NM_SETTING_WIRED_WAKE_ON_LAN_DEFAULT) - svSetValue (ifcfg, "ETHTOOL_OPTS", NULL, FALSE); + svUnsetValue (ifcfg, "ETHTOOL_OPTS"); else { str = g_string_sized_new (30); g_string_append (str, "wol "); @@ -1279,7 +1278,7 @@ write_wired_for_virtual (NMConnection *connection, shvarFile *ifcfg) svSetValue (ifcfg, "MTU", tmp, FALSE); g_free (tmp); } else - svSetValue (ifcfg, "MTU", NULL, FALSE); + svUnsetValue (ifcfg, "MTU"); } return has_wired; } @@ -1344,9 +1343,9 @@ write_vlan_setting (NMConnection *connection, shvarFile *ifcfg, gboolean *wired, svSetValue (ifcfg, "VLAN_EGRESS_PRIORITY_MAP", tmp, FALSE); g_free (tmp); - svSetValue (ifcfg, "HWADDR", NULL, FALSE); - svSetValue (ifcfg, "MACADDR", NULL, FALSE); - svSetValue (ifcfg, "MTU", NULL, FALSE); + svUnsetValue (ifcfg, "HWADDR"); + svUnsetValue (ifcfg, "MACADDR"); + svUnsetValue (ifcfg, "MTU"); *wired = write_wired_for_virtual (connection, ifcfg); @@ -1375,7 +1374,7 @@ write_bonding_setting (NMConnection *connection, shvarFile *ifcfg, gboolean *wir } svSetValue (ifcfg, "DEVICE", iface, FALSE); - svSetValue (ifcfg, "BONDING_OPTS", NULL, FALSE); + svUnsetValue (ifcfg, "BONDING_OPTS"); num_opts = nm_setting_bond_get_num_options (s_bond); if (num_opts > 0) { @@ -1497,9 +1496,9 @@ write_bridge_setting (NMConnection *connection, shvarFile *ifcfg, GError **error } svSetValue (ifcfg, "DEVICE", iface, FALSE); - svSetValue (ifcfg, "BRIDGING_OPTS", NULL, FALSE); + svUnsetValue (ifcfg, "BRIDGING_OPTS"); svSetValue (ifcfg, "STP", "no", FALSE); - svSetValue (ifcfg, "DELAY", NULL, FALSE); + svUnsetValue (ifcfg, "DELAY"); mac = nm_setting_bridge_get_mac_address (s_bridge); svSetValue (ifcfg, "MACADDR", mac, FALSE); @@ -1568,7 +1567,7 @@ write_bridge_port_setting (NMConnection *connection, shvarFile *ifcfg, GError ** if (!s_port) return TRUE; - svSetValue (ifcfg, "BRIDGING_OPTS", NULL, FALSE); + svUnsetValue (ifcfg, "BRIDGING_OPTS"); /* Bridge options */ opts = g_string_sized_new (32); @@ -1616,19 +1615,16 @@ write_team_port_setting (NMConnection *connection, shvarFile *ifcfg, GError **er static void write_dcb_flags (shvarFile *ifcfg, const char *tag, NMSettingDcbFlags flags) { - char *prop; + char prop[NM_STRLEN ("DCB_xxxxxxxxxxxxxxxxxxxxxxx_yyyyyyyyyyyyyyyyyyyy")]; - prop = g_strdup_printf ("DCB_%s_ENABLE", tag); + nm_sprintf_buf (prop, "DCB_%s_ENABLE", tag); svSetValue (ifcfg, prop, (flags & NM_SETTING_DCB_FLAG_ENABLE) ? "yes" : NULL, FALSE); - g_free (prop); - prop = g_strdup_printf ("DCB_%s_ADVERTISE", tag); + nm_sprintf_buf (prop, "DCB_%s_ADVERTISE", tag); svSetValue (ifcfg, prop, (flags & NM_SETTING_DCB_FLAG_ADVERTISE) ? "yes" : NULL, FALSE); - g_free (prop); - prop = g_strdup_printf ("DCB_%s_WILLING", tag); + nm_sprintf_buf (prop, "DCB_%s_WILLING", tag); svSetValue (ifcfg, prop, (flags & NM_SETTING_DCB_FLAG_WILLING) ? "yes" : NULL, FALSE); - g_free (prop); } static void @@ -1637,16 +1633,15 @@ write_dcb_app (shvarFile *ifcfg, NMSettingDcbFlags flags, gint priority) { - char *prop, *tmp = NULL; + char prop[NM_STRLEN ("DCB_xxxxxxxxxxxxxxxxxxxxxxx_yyyyyyyyyyyyyyyyyyyy")]; write_dcb_flags (ifcfg, tag, flags); + nm_sprintf_buf (prop, "DCB_%s_PRIORITY", tag); if ((flags & NM_SETTING_DCB_FLAG_ENABLE) && (priority >= 0)) - tmp = g_strdup_printf ("%d", priority); - prop = g_strdup_printf ("DCB_%s_PRIORITY", tag); - svSetValue (ifcfg, prop, tmp, FALSE); - g_free (prop); - g_free (tmp); + svSetValueInt64 (ifcfg, prop, priority); + else + svUnsetValue (ifcfg, prop); } typedef gboolean (*DcbGetBoolFunc) (NMSettingDcb *, guint); @@ -1662,7 +1657,7 @@ write_dcb_bool_array (shvarFile *ifcfg, guint i; if (!(flags & NM_SETTING_DCB_FLAG_ENABLE)) { - svSetValue (ifcfg, key, NULL, FALSE); + svUnsetValue (ifcfg, key); return; } @@ -1685,7 +1680,7 @@ write_dcb_uint_array (shvarFile *ifcfg, guint i, num; if (!(flags & NM_SETTING_DCB_FLAG_ENABLE)) { - svSetValue (ifcfg, key, NULL, FALSE); + svUnsetValue (ifcfg, key); return; } @@ -1713,7 +1708,7 @@ write_dcb_percent_array (shvarFile *ifcfg, guint i; if (!(flags & NM_SETTING_DCB_FLAG_ENABLE)) { - svSetValue (ifcfg, key, NULL, FALSE); + svUnsetValue (ifcfg, key); return; } @@ -1763,7 +1758,7 @@ write_dcb_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) const char **iter; for (iter = clear_keys; *iter; iter++) - svSetValue (ifcfg, *iter, NULL, FALSE); + svUnsetValue (ifcfg, *iter); return TRUE; } @@ -1775,7 +1770,7 @@ write_dcb_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) if (nm_setting_dcb_get_app_fcoe_flags (s_dcb) & NM_SETTING_DCB_FLAG_ENABLE) svSetValue (ifcfg, KEY_DCB_APP_FCOE_MODE, nm_setting_dcb_get_app_fcoe_mode (s_dcb), FALSE); else - svSetValue (ifcfg, KEY_DCB_APP_FCOE_MODE, NULL, FALSE); + svUnsetValue (ifcfg, KEY_DCB_APP_FCOE_MODE); write_dcb_app (ifcfg, "APP_ISCSI", nm_setting_dcb_get_app_iscsi_flags (s_dcb), @@ -1828,7 +1823,7 @@ write_connection_setting (NMSettingConnection *s_con, shvarFile *ifcfg) g_free (tmp); /* Only save the value for master connections */ - svSetValue (ifcfg, "AUTOCONNECT_SLAVES", NULL, FALSE); + svUnsetValue (ifcfg, "AUTOCONNECT_SLAVES"); type = nm_setting_connection_get_connection_type (s_con); if ( !g_strcmp0 (type, NM_SETTING_BOND_SETTING_NAME) || !g_strcmp0 (type, NM_SETTING_TEAM_SETTING_NAME) @@ -1854,7 +1849,7 @@ write_connection_setting (NMSettingConnection *s_con, shvarFile *ifcfg) svSetValue (ifcfg, "LLDP", tmp, FALSE); /* Permissions */ - svSetValue (ifcfg, "USERS", NULL, FALSE); + svUnsetValue (ifcfg, "USERS"); n = nm_setting_connection_get_num_permissions (s_con); if (n > 0) { str = g_string_sized_new (n * 20); @@ -1886,7 +1881,7 @@ write_connection_setting (NMSettingConnection *s_con, shvarFile *ifcfg) v_bridge = master; else if (nm_setting_connection_is_slave_type (s_con, NM_SETTING_TEAM_SETTING_NAME)) { v_team_master = master; - svSetValue (ifcfg, "TYPE", NULL, FALSE); + svUnsetValue (ifcfg, "TYPE"); } } @@ -1900,10 +1895,10 @@ write_connection_setting (NMSettingConnection *s_con, shvarFile *ifcfg) else if (master && nm_setting_connection_is_slave_type (s_con, NM_SETTING_TEAM_SETTING_NAME)) svSetValue (ifcfg, "DEVICETYPE", TYPE_TEAM_PORT, FALSE); else - svSetValue (ifcfg, "DEVICETYPE", NULL, FALSE); + svUnsetValue (ifcfg, "DEVICETYPE"); /* secondary connection UUIDs */ - svSetValue (ifcfg, "SECONDARY_UUIDS", NULL, FALSE); + svUnsetValue (ifcfg, "SECONDARY_UUIDS"); n = nm_setting_connection_get_num_secondaries (s_con); if (n > 0) { str = g_string_sized_new (n * 37); @@ -1924,7 +1919,7 @@ write_connection_setting (NMSettingConnection *s_con, shvarFile *ifcfg) g_string_free (str, TRUE); } - svSetValue (ifcfg, "GATEWAY_PING_TIMEOUT", NULL, FALSE); + svUnsetValue (ifcfg, "GATEWAY_PING_TIMEOUT"); if (nm_setting_connection_get_gateway_ping_timeout (s_con)) { tmp = g_strdup_printf ("%" G_GUINT32_FORMAT, nm_setting_connection_get_gateway_ping_timeout (s_con)); svSetValue (ifcfg, "GATEWAY_PING_TIMEOUT", tmp, FALSE); @@ -1939,7 +1934,7 @@ write_connection_setting (NMSettingConnection *s_con, shvarFile *ifcfg) svSetValue (ifcfg, "CONNECTION_METERED", "no", FALSE); break; default: - svSetValue (ifcfg, "CONNECTION_METERED", NULL, FALSE); + svUnsetValue (ifcfg, "CONNECTION_METERED"); } } @@ -2010,9 +2005,9 @@ write_proxy_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) if (!s_proxy) return TRUE; - svSetValue (ifcfg, "BROWSER_ONLY", NULL, FALSE); - svSetValue (ifcfg, "PAC_URL", NULL, FALSE); - svSetValue (ifcfg, "PAC_SCRIPT", NULL, FALSE); + svUnsetValue (ifcfg, "BROWSER_ONLY"); + svUnsetValue (ifcfg, "PAC_URL"); + svUnsetValue (ifcfg, "PAC_SCRIPT"); method = nm_setting_proxy_get_method (s_proxy); switch (method) { @@ -2063,17 +2058,17 @@ write_ip4_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) * * Some IPv4 setting related options are not cleared, * for no strong reason. */ - svSetValue (ifcfg, "BOOTPROTO", NULL, FALSE); + svUnsetValue (ifcfg, "BOOTPROTO"); - svSetValue (ifcfg, "IPADDR", NULL, FALSE); - svSetValue (ifcfg, "PREFIX", NULL, FALSE); - svSetValue (ifcfg, "NETMASK", NULL, FALSE); - svSetValue (ifcfg, "GATEWAY", NULL, FALSE); + svUnsetValue (ifcfg, "IPADDR"); + svUnsetValue (ifcfg, "PREFIX"); + svUnsetValue (ifcfg, "NETMASK"); + svUnsetValue (ifcfg, "GATEWAY"); - svSetValue (ifcfg, "IPADDR0", NULL, FALSE); - svSetValue (ifcfg, "PREFIX0", NULL, FALSE); - svSetValue (ifcfg, "NETMASK0", NULL, FALSE); - svSetValue (ifcfg, "GATEWAY0", NULL, FALSE); + svUnsetValue (ifcfg, "IPADDR0"); + svUnsetValue (ifcfg, "PREFIX0"); + svUnsetValue (ifcfg, "NETMASK0"); + svUnsetValue (ifcfg, "GATEWAY0"); return TRUE; } @@ -2087,7 +2082,7 @@ write_ip4_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) int result; /* IPv4 disabled, clear IPv4 related parameters */ - svSetValue (ifcfg, "BOOTPROTO", NULL, FALSE); + svUnsetValue (ifcfg, "BOOTPROTO"); for (j = -1; j < 256; j++) { if (j == -1) { addr_key = g_strdup ("IPADDR"); @@ -2101,10 +2096,10 @@ write_ip4_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) gw_key = g_strdup_printf ("GATEWAY%d", j); } - svSetValue (ifcfg, addr_key, NULL, FALSE); - svSetValue (ifcfg, prefix_key, NULL, FALSE); - svSetValue (ifcfg, netmask_key, NULL, FALSE); - svSetValue (ifcfg, gw_key, NULL, FALSE); + svUnsetValue (ifcfg, addr_key); + svUnsetValue (ifcfg, prefix_key); + svUnsetValue (ifcfg, netmask_key); + svUnsetValue (ifcfg, gw_key); g_free (addr_key); g_free (prefix_key); @@ -2112,7 +2107,7 @@ write_ip4_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) g_free (gw_key); } - route_path = utils_get_route_path (ifcfg->fileName); + route_path = utils_get_route_path (svFileGetName (ifcfg)); result = unlink (route_path); g_free (route_path); return TRUE; @@ -2128,15 +2123,15 @@ write_ip4_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) svSetValue (ifcfg, "BOOTPROTO", "shared", FALSE); /* Clear out un-numbered IP address fields */ - svSetValue (ifcfg, "IPADDR", NULL, FALSE); - svSetValue (ifcfg, "PREFIX", NULL, FALSE); - svSetValue (ifcfg, "NETMASK", NULL, FALSE); - svSetValue (ifcfg, "GATEWAY", NULL, FALSE); + svUnsetValue (ifcfg, "IPADDR"); + svUnsetValue (ifcfg, "PREFIX"); + svUnsetValue (ifcfg, "NETMASK"); + svUnsetValue (ifcfg, "GATEWAY"); /* Clear out zero-indexed IP address fields */ - svSetValue (ifcfg, "IPADDR0", NULL, FALSE); - svSetValue (ifcfg, "PREFIX0", NULL, FALSE); - svSetValue (ifcfg, "NETMASK0", NULL, FALSE); - svSetValue (ifcfg, "GATEWAY0", NULL, FALSE); + svUnsetValue (ifcfg, "IPADDR0"); + svUnsetValue (ifcfg, "PREFIX0"); + svUnsetValue (ifcfg, "NETMASK0"); + svUnsetValue (ifcfg, "GATEWAY0"); /* Write out IPADDR, PREFIX, GATEWAY for current IP addresses * without labels. Unset obsolete NETMASK. @@ -2178,8 +2173,8 @@ write_ip4_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) svSetValue (ifcfg, prefix_key, tmp, FALSE); g_free (tmp); - svSetValue (ifcfg, netmask_key, NULL, FALSE); - svSetValue (ifcfg, gw_key, NULL, FALSE); + svUnsetValue (ifcfg, netmask_key); + svUnsetValue (ifcfg, gw_key); g_free (addr_key); g_free (prefix_key); @@ -2195,10 +2190,10 @@ write_ip4_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) netmask_key = g_strdup_printf ("NETMASK%d", n); gw_key = g_strdup_printf ("GATEWAY%d", n); - svSetValue (ifcfg, addr_key, NULL, FALSE); - svSetValue (ifcfg, prefix_key, NULL, FALSE); - svSetValue (ifcfg, netmask_key, NULL, FALSE); - svSetValue (ifcfg, gw_key, NULL, FALSE); + svUnsetValue (ifcfg, addr_key); + svUnsetValue (ifcfg, prefix_key); + svUnsetValue (ifcfg, netmask_key); + svUnsetValue (ifcfg, gw_key); g_free (addr_key); g_free (prefix_key); @@ -2215,7 +2210,7 @@ write_ip4_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) addr_key = g_strdup_printf ("DNS%d", i + 1); if (i >= num) - svSetValue (ifcfg, addr_key, NULL, FALSE); + svUnsetValue (ifcfg, addr_key); else { dns = nm_setting_ip_config_get_dns (s_ip4, i); svSetValue (ifcfg, addr_key, dns, FALSE); @@ -2234,16 +2229,16 @@ write_ip4_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) svSetValue (ifcfg, "DOMAIN", searches->str, FALSE); g_string_free (searches, TRUE); } else - svSetValue (ifcfg, "DOMAIN", NULL, FALSE); + svUnsetValue (ifcfg, "DOMAIN"); /* DEFROUTE; remember that it has the opposite meaning from never-default */ svSetValue (ifcfg, "DEFROUTE", nm_setting_ip_config_get_never_default (s_ip4) ? "no" : "yes", FALSE); - svSetValue (ifcfg, "PEERDNS", NULL, FALSE); - svSetValue (ifcfg, "PEERROUTES", NULL, FALSE); - svSetValue (ifcfg, "DHCP_CLIENT_ID", NULL, FALSE); + svUnsetValue (ifcfg, "PEERDNS"); + svUnsetValue (ifcfg, "PEERROUTES"); + svUnsetValue (ifcfg, "DHCP_CLIENT_ID"); if (!strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_AUTO)) { svSetValue (ifcfg, "PEERDNS", nm_setting_ip_config_get_ignore_auto_dns (s_ip4) ? "no" : "yes", @@ -2288,17 +2283,17 @@ write_ip4_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) g_free (tmp); /* Static routes - route- file */ - route_path = utils_get_route_path (ifcfg->fileName); + route_path = utils_get_route_path (svFileGetName (ifcfg)); if (!route_path) { g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, - "Could not get route file path for '%s'", ifcfg->fileName); + "Could not get route file path for '%s'", svFileGetName (ifcfg)); return FALSE; } if (utils_has_route_file_new_syntax (route_path)) { shvarFile *routefile; - routefile = utils_get_route_ifcfg (ifcfg->fileName, TRUE); + routefile = utils_get_route_ifcfg (svFileGetName (ifcfg), TRUE); if (!routefile) { g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, "Could not create route file '%s'", route_path); @@ -2320,10 +2315,10 @@ write_ip4_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) metric_key = g_strdup_printf ("METRIC%d", i); if (i >= num) { - svSetValue (routefile, addr_key, NULL, FALSE); - svSetValue (routefile, netmask_key, NULL, FALSE); - svSetValue (routefile, gw_key, NULL, FALSE); - svSetValue (routefile, metric_key, NULL, FALSE); + svUnsetValue (routefile, addr_key); + svUnsetValue (routefile, netmask_key); + svUnsetValue (routefile, gw_key); + svUnsetValue (routefile, metric_key); } else { route = nm_setting_ip_config_get_route (s_ip4, i); @@ -2339,7 +2334,7 @@ write_ip4_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) memset (buf, 0, sizeof (buf)); metric = nm_ip_route_get_metric (route); if (metric == -1) - svSetValue (routefile, metric_key, NULL, FALSE); + svUnsetValue (routefile, metric_key); else { tmp = g_strdup_printf ("%u", (guint32) metric); svSetValue (routefile, metric_key, tmp, FALSE); @@ -2366,7 +2361,7 @@ write_ip4_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) timeout = nm_setting_ip_config_get_dad_timeout (s_ip4); if (timeout < 0) - svSetValue (ifcfg, "ARPING_WAIT", NULL, FALSE); + svUnsetValue (ifcfg, "ARPING_WAIT"); else if (timeout == 0) svSetValue (ifcfg, "ARPING_WAIT", "0", FALSE); else { @@ -2378,7 +2373,7 @@ write_ip4_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) if (priority) svSetValueInt64 (ifcfg, "IPV4_DNS_PRIORITY", priority); else - svSetValue (ifcfg, "IPV4_DNS_PRIORITY", NULL, FALSE); + svUnsetValue (ifcfg, "IPV4_DNS_PRIORITY"); return TRUE; } @@ -2547,15 +2542,15 @@ write_ip6_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) * * Some IPv6 setting related options are not cleared, * for no strong reason. */ - svSetValue (ifcfg, "IPV6INIT", NULL, FALSE); - svSetValue (ifcfg, "IPV6_AUTOCONF", NULL, FALSE); - svSetValue (ifcfg, "DHCPV6C", NULL, FALSE); - svSetValue (ifcfg, "IPV6_DEFROUTE", NULL, FALSE); - svSetValue (ifcfg, "IPV6_PEERDNS", NULL, FALSE); - svSetValue (ifcfg, "IPV6_PEERROUTES", NULL, FALSE); - svSetValue (ifcfg, "IPV6_FAILURE_FATAL", NULL, FALSE); - svSetValue (ifcfg, "IPV6_ROUTE_METRIC", NULL, FALSE); - svSetValue (ifcfg, "IPV6_ADDR_GEN_MODE", NULL, FALSE); + svUnsetValue (ifcfg, "IPV6INIT"); + svUnsetValue (ifcfg, "IPV6_AUTOCONF"); + svUnsetValue (ifcfg, "DHCPV6C"); + svUnsetValue (ifcfg, "IPV6_DEFROUTE"); + svUnsetValue (ifcfg, "IPV6_PEERDNS"); + svUnsetValue (ifcfg, "IPV6_PEERROUTES"); + svUnsetValue (ifcfg, "IPV6_FAILURE_FATAL"); + svUnsetValue (ifcfg, "IPV6_ROUTE_METRIC"); + svUnsetValue (ifcfg, "IPV6_ADDR_GEN_MODE"); return TRUE; } @@ -2563,12 +2558,12 @@ write_ip6_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) g_assert (value); if (!strcmp (value, NM_SETTING_IP6_CONFIG_METHOD_IGNORE)) { svSetValue (ifcfg, "IPV6INIT", "no", FALSE); - svSetValue (ifcfg, "DHCPV6C", NULL, FALSE); + svUnsetValue (ifcfg, "DHCPV6C"); return TRUE; } else if (!strcmp (value, NM_SETTING_IP6_CONFIG_METHOD_AUTO)) { svSetValue (ifcfg, "IPV6INIT", "yes", FALSE); svSetValue (ifcfg, "IPV6_AUTOCONF", "yes", FALSE); - svSetValue (ifcfg, "DHCPV6C", NULL, FALSE); + svUnsetValue (ifcfg, "DHCPV6C"); } else if (!strcmp (value, NM_SETTING_IP6_CONFIG_METHOD_DHCP)) { const char *hostname; svSetValue (ifcfg, "IPV6INIT", "yes", FALSE); @@ -2580,14 +2575,14 @@ write_ip6_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) } else if (!strcmp (value, NM_SETTING_IP6_CONFIG_METHOD_MANUAL)) { svSetValue (ifcfg, "IPV6INIT", "yes", FALSE); svSetValue (ifcfg, "IPV6_AUTOCONF", "no", FALSE); - svSetValue (ifcfg, "DHCPV6C", NULL, FALSE); + svUnsetValue (ifcfg, "DHCPV6C"); } else if (!strcmp (value, NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL)) { svSetValue (ifcfg, "IPV6INIT", "yes", FALSE); svSetValue (ifcfg, "IPV6_AUTOCONF", "no", FALSE); - svSetValue (ifcfg, "DHCPV6C", NULL, FALSE); + svUnsetValue (ifcfg, "DHCPV6C"); } else if (!strcmp (value, NM_SETTING_IP6_CONFIG_METHOD_SHARED)) { svSetValue (ifcfg, "IPV6INIT", "yes", FALSE); - svSetValue (ifcfg, "DHCPV6C", NULL, FALSE); + svUnsetValue (ifcfg, "DHCPV6C"); /* TODO */ } @@ -2623,7 +2618,7 @@ write_ip6_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) addr_key = g_strdup_printf ("DNS%d", i + num4 + 1); if (i >= num) - svSetValue (ifcfg, addr_key, NULL, FALSE); + svUnsetValue (ifcfg, addr_key); else { dns = nm_setting_ip_config_get_dns (s_ip6, i); svSetValue (ifcfg, addr_key, dns, FALSE); @@ -2654,8 +2649,8 @@ write_ip6_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) else svSetValue (ifcfg, "IPV6_DEFROUTE", "yes", FALSE); - svSetValue (ifcfg, "IPV6_PEERDNS", NULL, FALSE); - svSetValue (ifcfg, "IPV6_PEERROUTES", NULL, FALSE); + svUnsetValue (ifcfg, "IPV6_PEERDNS"); + svUnsetValue (ifcfg, "IPV6_PEERROUTES"); if (!strcmp (value, NM_SETTING_IP6_CONFIG_METHOD_AUTO)) { svSetValue (ifcfg, "IPV6_PEERDNS", nm_setting_ip_config_get_ignore_auto_dns (s_ip6) ? "no" : "yes", @@ -2676,8 +2671,8 @@ write_ip6_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) g_free (tmp); /* IPv6 Privacy Extensions */ - svSetValue (ifcfg, "IPV6_PRIVACY", NULL, FALSE); - svSetValue (ifcfg, "IPV6_PRIVACY_PREFER_PUBLIC_IP", NULL, FALSE); + svUnsetValue (ifcfg, "IPV6_PRIVACY"); + svUnsetValue (ifcfg, "IPV6_PRIVACY_PREFER_PUBLIC_IP"); switch (nm_setting_ip6_config_get_ip6_privacy (NM_SETTING_IP6_CONFIG (s_ip6))){ case NM_SETTING_IP6_CONFIG_PRIVACY_DISABLED: svSetValue (ifcfg, "IPV6_PRIVACY", "no", FALSE); @@ -2701,7 +2696,7 @@ write_ip6_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) svSetValue (ifcfg, "IPV6_ADDR_GEN_MODE", tmp, FALSE); g_free (tmp); } else { - svSetValue (ifcfg, "IPV6_ADDR_GEN_MODE", NULL, FALSE); + svUnsetValue (ifcfg, "IPV6_ADDR_GEN_MODE"); } /* IPv6 tokenized interface identifier */ @@ -2712,13 +2707,13 @@ write_ip6_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) if (priority) svSetValueInt64 (ifcfg, "IPV6_DNS_PRIORITY", priority); else - svSetValue (ifcfg, "IPV6_DNS_PRIORITY", NULL, FALSE); + svUnsetValue (ifcfg, "IPV6_DNS_PRIORITY"); /* Static routes go to route6- file */ - route6_path = utils_get_route6_path (ifcfg->fileName); + route6_path = utils_get_route6_path (svFileGetName (ifcfg)); if (!route6_path) { g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, - "Could not get route6 file path for '%s'", ifcfg->fileName); + "Could not get route6 file path for '%s'", svFileGetName (ifcfg)); goto error; } write_route6_file (route6_path, s_ip6, error); @@ -2753,7 +2748,7 @@ write_res_options (NMConnection *connection, shvarFile *ifcfg, GError **error) if (!s_ip4) { /* slave-type: clear res-options */ - svSetValue (ifcfg, "RES_OPTIONS", NULL, FALSE); + svUnsetValue (ifcfg, "RES_OPTIONS"); return TRUE; } @@ -2786,7 +2781,7 @@ write_res_options (NMConnection *connection, shvarFile *ifcfg, GError **error) svSetValueFull (ifcfg, "RES_OPTIONS", value->str, FALSE); g_string_free (value, TRUE); } else - svSetValue (ifcfg, "RES_OPTIONS", NULL, FALSE); + svUnsetValue (ifcfg, "RES_OPTIONS"); return TRUE; } @@ -2935,8 +2930,8 @@ write_connection (NMConnection *connection, if (!write_proxy_setting (connection, ifcfg, error)) goto out; - svSetValue (ifcfg, "DHCP_HOSTNAME", NULL, FALSE); - svSetValue (ifcfg, "DHCP_FQDN", NULL, FALSE); + svUnsetValue (ifcfg, "DHCP_HOSTNAME"); + svUnsetValue (ifcfg, "DHCP_FQDN"); if (!write_ip4_setting (connection, ifcfg, error)) goto out; diff --git a/src/settings/plugins/ifcfg-rh/writer.h b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.h similarity index 100% rename from src/settings/plugins/ifcfg-rh/writer.h rename to src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.h diff --git a/src/settings/plugins/ifcfg-rh/shvar.c b/src/settings/plugins/ifcfg-rh/shvar.c index 75b19d5383..cc0eefeba2 100644 --- a/src/settings/plugins/ifcfg-rh/shvar.c +++ b/src/settings/plugins/ifcfg-rh/shvar.c @@ -38,6 +38,175 @@ #include "nm-core-internal.h" +/*****************************************************************************/ + +struct _shvarFile { + char *fileName; /* read-only */ + int fd; /* read-only */ + GList *lineList; /* read-only */ + GList *current; /* set implicitly or explicitly, points to element of lineList */ + gboolean modified; /* ignore */ +}; + +/*****************************************************************************/ + +/** + * svParseBoolean: + * @value: the input string + * @fallback: the fallback value + * + * Parses a string and returns the boolean value it contains or, + * in case no valid value is found, the fallback value. Valid values + * are: "yes", "true", "t", "y", "1" and "no", "false", "f", "n", "0". + * + * Returns: the parsed boolean value or @fallback. + */ +gint +svParseBoolean (const char *value, gint fallback) +{ + if (!value) + return fallback; + + if ( !g_ascii_strcasecmp ("yes", value) + || !g_ascii_strcasecmp ("true", value) + || !g_ascii_strcasecmp ("t", value) + || !g_ascii_strcasecmp ("y", value) + || !g_ascii_strcasecmp ("1", value)) + return TRUE; + else if ( !g_ascii_strcasecmp ("no", value) + || !g_ascii_strcasecmp ("false", value) + || !g_ascii_strcasecmp ("f", value) + || !g_ascii_strcasecmp ("n", value) + || !g_ascii_strcasecmp ("0", value)) + return FALSE; + + return fallback; +} + +/*****************************************************************************/ + +/* create a new string with all necessary characters escaped. + * caller must free returned string + */ +static const char escapees[] = "\"'\\$~`"; /* must be escaped */ +static const char spaces[] = " \t|&;()<>"; /* only require "" */ +static const char newlines[] = "\n\r"; /* will be removed */ + +const char * +svEscape (const char *s, char **to_free) +{ + char *new; + int i, j, mangle = 0, space = 0, newline = 0; + int newlen, slen; + + slen = strlen (s); + + for (i = 0; i < slen; i++) { + if (strchr (escapees, s[i])) + mangle++; + if (strchr (spaces, s[i])) + space++; + if (strchr (newlines, s[i])) + newline++; + } + if (!mangle && !space && !newline) { + *to_free = NULL; + return s; + } + + newlen = slen + mangle - newline + 3; /* 3 is extra ""\0 */ + new = g_malloc (newlen); + + j = 0; + new[j++] = '"'; + for (i = 0; i < slen; i++) { + if (strchr (newlines, s[i])) + continue; + if (strchr (escapees, s[i])) { + new[j++] = '\\'; + } + new[j++] = s[i]; + } + new[j++] = '"'; + new[j++] = '\0'; + g_assert (j == slen + mangle - newline + 3); + + *to_free = new; + return new; +} + +/* remove escaped characters in place */ +void +svUnescape (char *s) +{ + size_t len, idx_rd = 0, idx_wr = 0; + char c; + + len = strlen (s); + if (len < 2) { + if (s[0] == '\\') + s[0] = '\0'; + return; + } + + if ((s[0] == '"' || s[0] == '\'') && s[0] == s[len-1]) { + if (len == 2) { + s[0] = '\0'; + return; + } + if (len == 3) { + if (s[1] == '\\') { + s[0] = '\0'; + } else { + s[0] = s[1]; + s[1] = '\0'; + } + return; + } + s[--len] = '\0'; + idx_rd = 1; + } else { + /* seek for the first escape... */ + char *p = strchr (s, '\\'); + + if (!p) + return; + if (p[1] == '\0') { + p[0] = '\0'; + return; + } + idx_wr = idx_rd = (p - s); + } + + /* idx_rd points to the first escape. Walk the string and shift the + * characters from idx_rd to idx_wr. + */ + while ((c = s[idx_rd++])) { + if (c == '\\') { + if (s[idx_rd] == '\0') { + s[idx_wr] = '\0'; + return; + } + s[idx_wr++] = s[idx_rd++]; + continue; + } + s[idx_wr++] = c; + } + s[idx_wr] = '\0'; +} + +/*****************************************************************************/ + +const char * +svFileGetName (const shvarFile *s) +{ + nm_assert (s); + + return s->fileName; +} + +/*****************************************************************************/ + /* Open the file , returning a shvarFile on success and NULL on failure. * Add a wrinkle to let the caller specify whether or not to create the file * (actually, return a structure anyway) if it doesn't exist. @@ -136,114 +305,45 @@ svCreateFile (const char *name) return svOpenFileInternal (name, TRUE, NULL); } -/* remove escaped characters in place */ -void -svUnescape (char *s) +/*****************************************************************************/ + +static const char * +find_line (shvarFile *s, const char *key) { - size_t len, idx_rd = 0, idx_wr = 0; - char c; + const char *line; + gsize len; - len = strlen (s); - if (len < 2) { - if (s[0] == '\\') - s[0] = '\0'; - return; + len = strlen (key); + + for (s->current = s->lineList; s->current; s->current = s->current->next) { + line = s->current->data; + if (!strncmp (key, line, len) && line[len] == '=') + return line + len + 1; } - if ((s[0] == '"' || s[0] == '\'') && s[0] == s[len-1]) { - if (len == 2) { - s[0] = '\0'; - return; - } - if (len == 3) { - if (s[1] == '\\') { - s[0] = '\0'; - } else { - s[0] = s[1]; - s[1] = '\0'; - } - return; - } - s[--len] = '\0'; - idx_rd = 1; - } else { - /* seek for the first escape... */ - char *p = strchr (s, '\\'); - - if (!p) - return; - if (p[1] == '\0') { - p[0] = '\0'; - return; - } - idx_wr = idx_rd = (p - s); - } - - /* idx_rd points to the first escape. Walk the string and shift the - * characters from idx_rd to idx_wr. - */ - while ((c = s[idx_rd++])) { - if (c == '\\') { - if (s[idx_rd] == '\0') { - s[idx_wr] = '\0'; - return; - } - s[idx_wr++] = s[idx_rd++]; - continue; - } - s[idx_wr++] = c; - } - s[idx_wr] = '\0'; + return NULL; } -/* create a new string with all necessary characters escaped. - * caller must free returned string - */ -static const char escapees[] = "\"'\\$~`"; /* must be escaped */ -static const char spaces[] = " \t|&;()<>"; /* only require "" */ -static const char newlines[] = "\n\r"; /* will be removed */ - -const char * -svEscape (const char *s, char **to_free) +/* svGetValueFull() is identical to svGetValue() except that + * svGetValue() will never return an empty value (but %NULL instead). + * svGetValueFull() will return empty values if that is the value for the @key. */ +char * +svGetValueFull (shvarFile *s, const char *key, gboolean verbatim) { - char *new; - int i, j, mangle = 0, space = 0, newline = 0; - int newlen, slen; + const char *line_val; + char *value; - slen = strlen (s); + g_return_val_if_fail (s != NULL, NULL); + g_return_val_if_fail (key != NULL, NULL); - for (i = 0; i < slen; i++) { - if (strchr (escapees, s[i])) - mangle++; - if (strchr (spaces, s[i])) - space++; - if (strchr (newlines, s[i])) - newline++; - } - if (!mangle && !space && !newline) { - *to_free = NULL; - return s; - } + line_val = find_line (s, key); + if (!line_val) + return NULL; - newlen = slen + mangle - newline + 3; /* 3 is extra ""\0 */ - new = g_malloc (newlen); - - j = 0; - new[j++] = '"'; - for (i = 0; i < slen; i++) { - if (strchr (newlines, s[i])) - continue; - if (strchr (escapees, s[i])) { - new[j++] = '\\'; - } - new[j++] = s[i]; - } - new[j++] = '"'; - new[j++] = '\0'; - g_assert (j == slen + mangle - newline + 3); - - *to_free = new; - return new; + value = g_strchomp (g_strdup (line_val)); + if (!verbatim) + svUnescape (value); + return value; } /* Get the value associated with the key, and leave the current pointer @@ -263,68 +363,6 @@ svGetValue (shvarFile *s, const char *key, gboolean verbatim) return value; } -/* svGetValueFull() is identical to svGetValue() except that - * svGetValue() will never return an empty value (but %NULL instead). - * svGetValueFull() will return empty values if that is the value for the @key. */ -char * -svGetValueFull (shvarFile *s, const char *key, gboolean verbatim) -{ - char *value = NULL; - char *line; - guint len; - - g_return_val_if_fail (s != NULL, NULL); - g_return_val_if_fail (key != NULL, NULL); - - len = strlen (key); - - for (s->current = s->lineList; s->current; s->current = s->current->next) { - line = s->current->data; - if (!strncmp (key, line, len) && line[len] == '=') { - /* Strip trailing spaces before unescaping to preserve spaces quoted whitespace */ - value = g_strchomp (g_strdup (line + len + 1)); - if (!verbatim) - svUnescape (value); - break; - } - } - - return value; -} - -/** - * svParseBoolean: - * @value: the input string - * @fallback: the fallback value - * - * Parses a string and returns the boolean value it contains or, - * in case no valid value is found, the fallback value. Valid values - * are: "yes", "true", "t", "y", "1" and "no", "false", "f", "n", "0". - * - * Returns: the parsed boolean value or @fallback. - */ -gint -svParseBoolean (const char *value, gint fallback) -{ - if (!value) - return fallback; - - if ( !g_ascii_strcasecmp ("yes", value) - || !g_ascii_strcasecmp ("true", value) - || !g_ascii_strcasecmp ("t", value) - || !g_ascii_strcasecmp ("y", value) - || !g_ascii_strcasecmp ("1", value)) - return TRUE; - else if ( !g_ascii_strcasecmp ("no", value) - || !g_ascii_strcasecmp ("false", value) - || !g_ascii_strcasecmp ("f", value) - || !g_ascii_strcasecmp ("n", value) - || !g_ascii_strcasecmp ("0", value)) - return FALSE; - - return fallback; -} - /* svGetValueBoolean: * @s: fhe file * @key: the name of the key to read @@ -375,16 +413,7 @@ svGetValueInt64 (shvarFile *s, const char *key, guint base, gint64 min, gint64 m return result; } -/* Set the variable equal to the value . - * If does not exist, and the pointer is set, append - * the key=value pair after that line. Otherwise, append the pair - * to the bottom of the file. - */ -void -svSetValue (shvarFile *s, const char *key, const char *value, gboolean verbatim) -{ - svSetValueFull (s, key, value && value[0] ? value : NULL, verbatim); -} +/*****************************************************************************/ /* Same as svSetValue() but it preserves empty @value -- contrary to * svSetValue() for which "" effectively means to remove the value. */ @@ -404,11 +433,10 @@ svSetValueFull (shvarFile *s, const char *key, const char *value, gboolean verba newval = value; else newval = svEscape (value, &newval_free); - oldval = svGetValueFull (s, key, FALSE); if (!newval) { /* delete value */ - if (oldval) { + if (find_line (s, key)) { /* delete line */ s->lineList = g_list_remove_link (s->lineList, s->current); g_free (s->current->data); @@ -418,6 +446,8 @@ svSetValueFull (shvarFile *s, const char *key, const char *value, gboolean verba return; } + oldval = svGetValueFull (s, key, FALSE); + keyValue = g_strdup_printf ("%s=%s", key, newval); if (!oldval) { /* append line */ @@ -438,15 +468,35 @@ svSetValueFull (shvarFile *s, const char *key, const char *value, gboolean verba g_free (keyValue); } +/* Set the variable equal to the value . + * If does not exist, and the pointer is set, append + * the key=value pair after that line. Otherwise, append the pair + * to the bottom of the file. + */ +void +svSetValue (shvarFile *s, const char *key, const char *value, gboolean verbatim) +{ + svSetValueFull (s, key, value && value[0] ? value : NULL, verbatim); +} + void svSetValueInt64 (shvarFile *s, const char *key, gint64 value) { - gs_free char *v = NULL; + char buf[NM_DECIMAL_STR_MAX (value)]; - v = g_strdup_printf ("%"G_GINT64_FORMAT, value); - svSetValueFull (s, key, v, TRUE); + svSetValueFull (s, key, + nm_sprintf_buf (buf, "%"G_GINT64_FORMAT, value), + TRUE); } +void +svUnsetValue (shvarFile *s, const char *key) +{ + svSetValueFull (s, key, NULL, FALSE); +} + +/*****************************************************************************/ + /* Write the current contents iff modified. Returns FALSE on error * and TRUE on success. Do not write if no values have been modified. * The mode argument is only used if creating the file, not if diff --git a/src/settings/plugins/ifcfg-rh/shvar.h b/src/settings/plugins/ifcfg-rh/shvar.h index 97df81284a..14b2c5e8b4 100644 --- a/src/settings/plugins/ifcfg-rh/shvar.h +++ b/src/settings/plugins/ifcfg-rh/shvar.h @@ -32,14 +32,8 @@ #define _SHVAR_H typedef struct _shvarFile shvarFile; -struct _shvarFile { - char *fileName; /* read-only */ - int fd; /* read-only */ - GList *lineList; /* read-only */ - GList *current; /* set implicitly or explicitly, points to element of lineList */ - gboolean modified; /* ignore */ -}; +const char *svFileGetName (const shvarFile *s); /* Create the file , return a shvarFile (never fails) */ shvarFile *svCreateFile (const char *name); @@ -73,6 +67,7 @@ void svSetValue (shvarFile *s, const char *key, const char *value, gboolean verb void svSetValueFull (shvarFile *s, const char *key, const char *value, gboolean verbatim); void svSetValueInt64 (shvarFile *s, const char *key, gint64 value); +void svUnsetValue (shvarFile *s, const char *key); /* Write the current contents iff modified. Returns FALSE on error * and TRUE on success. Do not write if no values have been modified. diff --git a/src/settings/plugins/ifcfg-rh/tests/Makefile.am b/src/settings/plugins/ifcfg-rh/tests/Makefile.am index 134191c5d4..8315e494bf 100644 --- a/src/settings/plugins/ifcfg-rh/tests/Makefile.am +++ b/src/settings/plugins/ifcfg-rh/tests/Makefile.am @@ -28,31 +28,19 @@ AM_LDFLAGS = \ $(GLIB_LIBS) \ $(CODE_COVERAGE_LDFLAGS) -noinst_PROGRAMS = test-ifcfg-rh test-ifcfg-rh-utils +noinst_PROGRAMS = test-ifcfg-rh test_ifcfg_rh_SOURCES = \ - test-ifcfg-rh.c \ - ../reader.c \ - ../shvar.c \ - ../utils.c \ - ../writer.c + test-ifcfg-rh.c test_ifcfg_rh_LDADD = \ - $(top_builddir)/src/libNetworkManager.la - -test_ifcfg_rh_utils_SOURCES = \ - test-ifcfg-rh-utils.c \ - ../utils.c \ - ../shvar.c - -test_ifcfg_rh_utils_LDADD = \ + $(top_builddir)/src/settings/plugins/ifcfg-rh/libnms-ifcfg-rh-core.la \ $(top_builddir)/src/libNetworkManager.la @VALGRIND_RULES@ -TESTS = test-ifcfg-rh-utils test-ifcfg-rh +TESTS = test-ifcfg-rh check-local: $(call check_so_symbols,$(builddir)/../.libs/libnm-settings-plugin-ifcfg-rh.so) endif - diff --git a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh-utils.c b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh-utils.c deleted file mode 100644 index d2a348bb8b..0000000000 --- a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh-utils.c +++ /dev/null @@ -1,155 +0,0 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* NetworkManager system settings service - keyfile plugin - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Copyright (C) 2008 - 2011 Red Hat, Inc. - */ - -#include "nm-default.h" - -#include -#include -#include -#include - -#include "common.h" -#include "utils.h" - -#include "nm-test-utils-core.h" - -static void -test_get_ifcfg_name (const char *desc, - const char *path, - gboolean only_ifcfg, - const char *expected) -{ - const char *result; - - result = utils_get_ifcfg_name (path, only_ifcfg); - g_assert_cmpstr (result, ==, expected); -} - -static void -test_get_ifcfg_path (const char *desc, - const char *path, - const char *expected) -{ - char *result; - - result = utils_get_ifcfg_path (path); - g_assert_cmpstr (result, ==, expected); - g_free (result); -} - -static void -test_get_keys_path (const char *desc, - const char *path, - const char *expected) -{ - char *result; - - result = utils_get_keys_path (path); - g_assert_cmpstr (result, ==, expected); - g_free (result); -} - -static void -test_get_route_path (const char *desc, - const char *path, - const char *expected) -{ - char *result; - - result = utils_get_route_path (path); - g_assert_cmpstr (result, ==, expected); - g_free (result); -} - -static void -test_ignored (const char *desc, const char *path, gboolean expected_ignored) -{ - gboolean result; - - result = utils_should_ignore_file (path, FALSE); - g_assert (result == expected_ignored); -} - -static void -test_name (void) -{ - test_get_ifcfg_name ("get-ifcfg-name-bad", "/foo/bar/adfasdfadf", FALSE, NULL); - test_get_ifcfg_name ("get-ifcfg-name-good", "/foo/bar/ifcfg-FooBar", FALSE, "FooBar"); - test_get_ifcfg_name ("get-ifcfg-name-keys", "/foo/bar/keys-BlahLbah", FALSE, "BlahLbah"); - test_get_ifcfg_name ("get-ifcfg-name-route", "/foo/bar/route-Lalalala", FALSE, "Lalalala"); - test_get_ifcfg_name ("get-ifcfg-name-only-ifcfg-route", "/foo/bar/route-Lalalala", TRUE, NULL); - test_get_ifcfg_name ("get-ifcfg-name-only-ifcfg-keys", "/foo/bar/keys-Lalalala", TRUE, NULL); - test_get_ifcfg_name ("get-ifcfg-name-no-path-ifcfg", "ifcfg-Lalalala", FALSE, "Lalalala"); - test_get_ifcfg_name ("get-ifcfg-name-no-path-keys", "keys-Lalalala", FALSE, "Lalalala"); - test_get_ifcfg_name ("get-ifcfg-name-no-path-route", "route-Lalalala", FALSE, "Lalalala"); - - test_get_ifcfg_name ("get-ifcfg-name-bad2-ifcfg", "/foo/bar/asdfasifcfg-Foobar", FALSE, NULL); - test_get_ifcfg_name ("get-ifcfg-name-bad2-keys", "/foo/bar/asdfaskeys-Foobar", FALSE, NULL); - test_get_ifcfg_name ("get-ifcfg-name-bad2-route", "/foo/bar/asdfasroute-Foobar", FALSE, NULL); -} - -static void -test_path (void) -{ - test_get_ifcfg_path ("ifcfg-path-bad", "/foo/bar/adfasdfasdf", NULL); - test_get_ifcfg_path ("ifcfg-path-from-keys-no-path", "keys-BlahBlah", "ifcfg-BlahBlah"); - test_get_ifcfg_path ("ifcfg-path-from-keys", "/foo/bar/keys-BlahBlah", "/foo/bar/ifcfg-BlahBlah"); - test_get_ifcfg_path ("ifcfg-path-from-route", "/foo/bar/route-BlahBlah", "/foo/bar/ifcfg-BlahBlah"); - - test_get_keys_path ("keys-path-bad", "/foo/bar/asdfasdfasdfasdf", NULL); - test_get_keys_path ("keys-path-from-ifcfg-no-path", "ifcfg-FooBar", "keys-FooBar"); - test_get_keys_path ("keys-path-from-ifcfg", "/foo/bar/ifcfg-FooBar", "/foo/bar/keys-FooBar"); - test_get_keys_path ("keys-path-from-route", "/foo/bar/route-FooBar", "/foo/bar/keys-FooBar"); - - test_get_route_path ("route-path-bad", "/foo/bar/asdfasdfasdfasdf", NULL); - test_get_route_path ("route-path-from-ifcfg-no-path", "ifcfg-FooBar", "route-FooBar"); - test_get_route_path ("route-path-from-ifcfg", "/foo/bar/ifcfg-FooBar", "/foo/bar/route-FooBar"); - test_get_route_path ("route-path-from-keys", "/foo/bar/keys-FooBar", "/foo/bar/route-FooBar"); -} - -static void -test_ignore (void) -{ - test_ignored ("ignored-ifcfg", "ifcfg-FooBar", FALSE); - test_ignored ("ignored-keys", "keys-FooBar", FALSE); - test_ignored ("ignored-route", "route-FooBar", FALSE); - test_ignored ("ignored-bak", "ifcfg-FooBar" BAK_TAG, TRUE); - test_ignored ("ignored-tilde", "ifcfg-FooBar" TILDE_TAG, TRUE); - test_ignored ("ignored-orig", "ifcfg-FooBar" ORIG_TAG, TRUE); - test_ignored ("ignored-rej", "ifcfg-FooBar" REJ_TAG, TRUE); - test_ignored ("ignored-rpmnew", "ifcfg-FooBar" RPMNEW_TAG, TRUE); - test_ignored ("ignored-augnew", "ifcfg-FooBar" AUGNEW_TAG, TRUE); - test_ignored ("ignored-augtmp", "ifcfg-FooBar" AUGTMP_TAG, TRUE); -} - -NMTST_DEFINE (); - -int main (int argc, char **argv) -{ - nmtst_init_assert_logging (&argc, &argv, "INFO", "DEFAULT"); - - /* The tests */ - g_test_add_func ("/settings/plugins/ifcfg-rh/name", test_name); - g_test_add_func ("/settings/plugins/ifcfg-rh/path", test_path); - g_test_add_func ("/settings/plugins/ifcfg-rh/ignore", test_ignore); - - return g_test_run (); -} - diff --git a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c index b71f732d15..8a12805c99 100644 --- a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c +++ b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c @@ -50,10 +50,10 @@ #include "NetworkManagerUtils.h" -#include "common.h" -#include "reader.h" -#include "writer.h" -#include "utils.h" +#include "nms-ifcfg-rh-common.h" +#include "nms-ifcfg-rh-reader.h" +#include "nms-ifcfg-rh-writer.h" +#include "nms-ifcfg-rh-utils.h" #include "nm-test-utils-core.h" @@ -8850,6 +8850,120 @@ test_sit_read_ignore (void) /*****************************************************************************/ +static void +do_test_utils_name (const char *desc, + const char *path, + gboolean only_ifcfg, + const char *expected) +{ + const char *result; + + result = utils_get_ifcfg_name (path, only_ifcfg); + g_assert_cmpstr (result, ==, expected); +} + +static void +test_utils_name (void) +{ + do_test_utils_name ("get-ifcfg-name-bad", "/foo/bar/adfasdfadf", FALSE, NULL); + do_test_utils_name ("get-ifcfg-name-good", "/foo/bar/ifcfg-FooBar", FALSE, "FooBar"); + do_test_utils_name ("get-ifcfg-name-keys", "/foo/bar/keys-BlahLbah", FALSE, "BlahLbah"); + do_test_utils_name ("get-ifcfg-name-route", "/foo/bar/route-Lalalala", FALSE, "Lalalala"); + do_test_utils_name ("get-ifcfg-name-only-ifcfg-route", "/foo/bar/route-Lalalala", TRUE, NULL); + do_test_utils_name ("get-ifcfg-name-only-ifcfg-keys", "/foo/bar/keys-Lalalala", TRUE, NULL); + do_test_utils_name ("get-ifcfg-name-no-path-ifcfg", "ifcfg-Lalalala", FALSE, "Lalalala"); + do_test_utils_name ("get-ifcfg-name-no-path-keys", "keys-Lalalala", FALSE, "Lalalala"); + do_test_utils_name ("get-ifcfg-name-no-path-route", "route-Lalalala", FALSE, "Lalalala"); + + do_test_utils_name ("get-ifcfg-name-bad2-ifcfg", "/foo/bar/asdfasifcfg-Foobar", FALSE, NULL); + do_test_utils_name ("get-ifcfg-name-bad2-keys", "/foo/bar/asdfaskeys-Foobar", FALSE, NULL); + do_test_utils_name ("get-ifcfg-name-bad2-route", "/foo/bar/asdfasroute-Foobar", FALSE, NULL); +} + +/*****************************************************************************/ + +static void +do_test_utils_path_ifcfg (const char *desc, + const char *path, + const char *expected) +{ + char *result; + + result = utils_get_ifcfg_path (path); + g_assert_cmpstr (result, ==, expected); + g_free (result); +} + +static void +do_test_utils_path_keys (const char *desc, + const char *path, + const char *expected) +{ + char *result; + + result = utils_get_keys_path (path); + g_assert_cmpstr (result, ==, expected); + g_free (result); +} + +static void +do_test_utils_path_route (const char *desc, + const char *path, + const char *expected) +{ + char *result; + + result = utils_get_route_path (path); + g_assert_cmpstr (result, ==, expected); + g_free (result); +} + +static void +test_utils_path (void) +{ + do_test_utils_path_ifcfg ("ifcfg-path-bad", "/foo/bar/adfasdfasdf", NULL); + do_test_utils_path_ifcfg ("ifcfg-path-from-keys-no-path", "keys-BlahBlah", "ifcfg-BlahBlah"); + do_test_utils_path_ifcfg ("ifcfg-path-from-keys", "/foo/bar/keys-BlahBlah", "/foo/bar/ifcfg-BlahBlah"); + do_test_utils_path_ifcfg ("ifcfg-path-from-route", "/foo/bar/route-BlahBlah", "/foo/bar/ifcfg-BlahBlah"); + + do_test_utils_path_keys ("keys-path-bad", "/foo/bar/asdfasdfasdfasdf", NULL); + do_test_utils_path_keys ("keys-path-from-ifcfg-no-path", "ifcfg-FooBar", "keys-FooBar"); + do_test_utils_path_keys ("keys-path-from-ifcfg", "/foo/bar/ifcfg-FooBar", "/foo/bar/keys-FooBar"); + do_test_utils_path_keys ("keys-path-from-route", "/foo/bar/route-FooBar", "/foo/bar/keys-FooBar"); + + do_test_utils_path_route ("route-path-bad", "/foo/bar/asdfasdfasdfasdf", NULL); + do_test_utils_path_route ("route-path-from-ifcfg-no-path", "ifcfg-FooBar", "route-FooBar"); + do_test_utils_path_route ("route-path-from-ifcfg", "/foo/bar/ifcfg-FooBar", "/foo/bar/route-FooBar"); + do_test_utils_path_route ("route-path-from-keys", "/foo/bar/keys-FooBar", "/foo/bar/route-FooBar"); +} + +/*****************************************************************************/ + +static void +do_test_utils_ignored (const char *desc, const char *path, gboolean expected_ignored) +{ + gboolean result; + + result = utils_should_ignore_file (path, FALSE); + g_assert (result == expected_ignored); +} + +static void +test_utils_ignore (void) +{ + do_test_utils_ignored ("ignored-ifcfg", "ifcfg-FooBar", FALSE); + do_test_utils_ignored ("ignored-keys", "keys-FooBar", FALSE); + do_test_utils_ignored ("ignored-route", "route-FooBar", FALSE); + do_test_utils_ignored ("ignored-bak", "ifcfg-FooBar" BAK_TAG, TRUE); + do_test_utils_ignored ("ignored-tilde", "ifcfg-FooBar" TILDE_TAG, TRUE); + do_test_utils_ignored ("ignored-orig", "ifcfg-FooBar" ORIG_TAG, TRUE); + do_test_utils_ignored ("ignored-rej", "ifcfg-FooBar" REJ_TAG, TRUE); + do_test_utils_ignored ("ignored-rpmnew", "ifcfg-FooBar" RPMNEW_TAG, TRUE); + do_test_utils_ignored ("ignored-augnew", "ifcfg-FooBar" AUGNEW_TAG, TRUE); + do_test_utils_ignored ("ignored-augtmp", "ifcfg-FooBar" AUGTMP_TAG, TRUE); +} + +/*****************************************************************************/ #define TPATH "/settings/plugins/ifcfg-rh/" @@ -9098,6 +9212,9 @@ int main (int argc, char **argv) g_test_add_data_func (TPATH "wwan/write-gsm", GUINT_TO_POINTER (TRUE), test_write_mobile_broadband); g_test_add_data_func (TPATH "wwan/write-cdma", GUINT_TO_POINTER (FALSE), test_write_mobile_broadband); + g_test_add_func (TPATH "utils/name", test_utils_name); + g_test_add_func (TPATH "utils/path", test_utils_path); + g_test_add_func (TPATH "utils/ignore", test_utils_ignore); + return g_test_run (); } - diff --git a/src/settings/plugins/ifnet/Makefile.am b/src/settings/plugins/ifnet/Makefile.am index 0d90aad34e..f2a65d9622 100644 --- a/src/settings/plugins/ifnet/Makefile.am +++ b/src/settings/plugins/ifnet/Makefile.am @@ -16,26 +16,34 @@ AM_CPPFLAGS = \ -DSYSCONFDIR=\"$(sysconfdir)\" -DSBINDIR=\"$(sbindir)\" -pkglib_LTLIBRARIES = libnm-settings-plugin-ifnet.la +pkglib_LTLIBRARIES = \ + libnm-settings-plugin-ifnet.la -noinst_LTLIBRARIES = lib-ifnet-io.la +noinst_LTLIBRARIES = \ + libnms-ifnet-core.la + +############################################################################### + +libnms_ifnet_core_la_SOURCES = \ + nms-ifnet-net-parser.c\ + nms-ifnet-net-parser.h\ + nms-ifnet-connection-parser.c \ + nms-ifnet-connection-parser.h \ + nms-ifnet-net-utils.h\ + nms-ifnet-net-utils.c\ + nms-ifnet-wpa-parser.h\ + nms-ifnet-wpa-parser.c + +############################################################################### libnm_settings_plugin_ifnet_la_SOURCES = \ - nm-ifnet-connection.c \ - nm-ifnet-connection.h \ - plugin.c \ - plugin.h + nms-ifnet-connection.c \ + nms-ifnet-connection.h \ + nms-ifnet-plugin.c \ + nms-ifnet-plugin.h -libnm_settings_plugin_ifnet_la_LDFLAGS = -module -avoid-version +libnm_settings_plugin_ifnet_la_LDFLAGS = \ + -module -avoid-version -libnm_settings_plugin_ifnet_la_LIBADD = lib-ifnet-io.la - -lib_ifnet_io_la_SOURCES = \ - net_parser.c\ - net_parser.h\ - connection_parser.c \ - connection_parser.h \ - net_utils.h\ - net_utils.c\ - wpa_parser.h\ - wpa_parser.c +libnm_settings_plugin_ifnet_la_LIBADD = \ + libnms-ifnet-core.la diff --git a/src/settings/plugins/ifnet/connection_parser.c b/src/settings/plugins/ifnet/nms-ifnet-connection-parser.c similarity index 99% rename from src/settings/plugins/ifnet/connection_parser.c rename to src/settings/plugins/ifnet/nms-ifnet-connection-parser.c index 9917463f98..f336c1ccea 100644 --- a/src/settings/plugins/ifnet/connection_parser.c +++ b/src/settings/plugins/ifnet/nms-ifnet-connection-parser.c @@ -21,6 +21,8 @@ #include "nm-default.h" +#include "nms-ifnet-connection-parser.h" + #include #include #include @@ -30,10 +32,9 @@ #include "nm-core-internal.h" #include "NetworkManagerUtils.h" -#include "net_utils.h" -#include "wpa_parser.h" -#include "connection_parser.h" -#include "nm-ifnet-connection.h" +#include "nms-ifnet-net-utils.h" +#include "nms-ifnet-wpa-parser.h" +#include "nms-ifnet-connection.h" static char * connection_id_from_ifnet_name (const char *conn_name) diff --git a/src/settings/plugins/ifnet/connection_parser.h b/src/settings/plugins/ifnet/nms-ifnet-connection-parser.h similarity index 98% rename from src/settings/plugins/ifnet/connection_parser.h rename to src/settings/plugins/ifnet/nms-ifnet-connection-parser.h index 74213669de..e6c0e88c81 100644 --- a/src/settings/plugins/ifnet/connection_parser.h +++ b/src/settings/plugins/ifnet/nms-ifnet-connection-parser.h @@ -21,8 +21,10 @@ #ifndef _CONNECTION_PARSER_H #define _CONNECTION_PARSER_H + #include -#include "net_parser.h" + +#include "nms-ifnet-net-parser.h" gboolean ifnet_can_write_connection (NMConnection *connection, GError **error); diff --git a/src/settings/plugins/ifnet/nm-ifnet-connection.c b/src/settings/plugins/ifnet/nms-ifnet-connection.c similarity index 97% rename from src/settings/plugins/ifnet/nm-ifnet-connection.c rename to src/settings/plugins/ifnet/nms-ifnet-connection.c index 66a2f84893..bea5d11287 100644 --- a/src/settings/plugins/ifnet/nm-ifnet-connection.c +++ b/src/settings/plugins/ifnet/nms-ifnet-connection.c @@ -21,7 +21,7 @@ #include "nm-default.h" -#include "nm-ifnet-connection.h" +#include "nms-ifnet-connection.h" #include #include @@ -32,11 +32,11 @@ #include "nm-settings-connection.h" #include "nm-settings-plugin.h" -#include "connection_parser.h" -#include "net_parser.h" -#include "net_utils.h" -#include "wpa_parser.h" -#include "plugin.h" +#include "nms-ifnet-connection-parser.h" +#include "nms-ifnet-net-parser.h" +#include "nms-ifnet-net-utils.h" +#include "nms-ifnet-wpa-parser.h" +#include "nms-ifnet-plugin.h" /*****************************************************************************/ diff --git a/src/settings/plugins/ifnet/nm-ifnet-connection.h b/src/settings/plugins/ifnet/nms-ifnet-connection.h similarity index 98% rename from src/settings/plugins/ifnet/nm-ifnet-connection.h rename to src/settings/plugins/ifnet/nms-ifnet-connection.h index 490ba1f7a4..1718dcb93e 100644 --- a/src/settings/plugins/ifnet/nm-ifnet-connection.h +++ b/src/settings/plugins/ifnet/nms-ifnet-connection.h @@ -23,7 +23,8 @@ #define __NETWORKMANAGER_IFNET_CONNECTION_H__ #include -#include "net_parser.h" + +#include "nms-ifnet-net-parser.h" #define NM_TYPE_IFNET_CONNECTION (nm_ifnet_connection_get_type ()) #define NM_IFNET_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_IFNET_CONNECTION, NMIfnetConnection)) diff --git a/src/settings/plugins/ifnet/net_parser.c b/src/settings/plugins/ifnet/nms-ifnet-net-parser.c similarity index 99% rename from src/settings/plugins/ifnet/net_parser.c rename to src/settings/plugins/ifnet/nms-ifnet-net-parser.c index db5e7a13e7..e4b0ad6ba8 100644 --- a/src/settings/plugins/ifnet/net_parser.c +++ b/src/settings/plugins/ifnet/nms-ifnet-net-parser.c @@ -21,18 +21,18 @@ #include "nm-default.h" +#include "nms-ifnet-net-parser.h" + #include #include #include #include #include "nm-settings-plugin.h" - -#include "plugin.h" #include "nm-platform.h" -#include "net_parser.h" -#include "net_utils.h" +#include "nms-ifnet-plugin.h" +#include "nms-ifnet-net-utils.h" /* Save all the connection information */ static GHashTable *conn_table; diff --git a/src/settings/plugins/ifnet/net_parser.h b/src/settings/plugins/ifnet/nms-ifnet-net-parser.h similarity index 100% rename from src/settings/plugins/ifnet/net_parser.h rename to src/settings/plugins/ifnet/nms-ifnet-net-parser.h diff --git a/src/settings/plugins/ifnet/net_utils.c b/src/settings/plugins/ifnet/nms-ifnet-net-utils.c similarity index 99% rename from src/settings/plugins/ifnet/net_utils.c rename to src/settings/plugins/ifnet/nms-ifnet-net-utils.c index bd5d65d578..deb8cef3b2 100644 --- a/src/settings/plugins/ifnet/net_utils.c +++ b/src/settings/plugins/ifnet/nms-ifnet-net-utils.c @@ -21,6 +21,8 @@ #include "nm-default.h" +#include "nms-ifnet-net-utils.h" + #include #include #include @@ -30,9 +32,9 @@ #include "NetworkManagerUtils.h" #include "nm-settings-plugin.h" #include "nm-config.h" -#include "net_utils.h" -#include "wpa_parser.h" -#include "net_parser.h" + +#include "nms-ifnet-wpa-parser.h" +#include "nms-ifnet-net-parser.h" /* emit heading and tailing blank space, tab, character t */ gchar * diff --git a/src/settings/plugins/ifnet/net_utils.h b/src/settings/plugins/ifnet/nms-ifnet-net-utils.h similarity index 98% rename from src/settings/plugins/ifnet/net_utils.h rename to src/settings/plugins/ifnet/nms-ifnet-net-utils.h index 85a5cb1ca2..79d4464256 100644 --- a/src/settings/plugins/ifnet/net_utils.h +++ b/src/settings/plugins/ifnet/nms-ifnet-net-utils.h @@ -28,7 +28,8 @@ #include #include -#include "net_parser.h" + +#include "nms-ifnet-net-parser.h" #define has_default_ip4_route(conn_name) has_default_route((conn_name), &is_ip4_address) #define has_default_ip6_route(conn_name) has_default_route((conn_name), &is_ip6_address) diff --git a/src/settings/plugins/ifnet/plugin.c b/src/settings/plugins/ifnet/nms-ifnet-plugin.c similarity index 98% rename from src/settings/plugins/ifnet/plugin.c rename to src/settings/plugins/ifnet/nms-ifnet-plugin.c index f7688585a6..4835e3a554 100644 --- a/src/settings/plugins/ifnet/plugin.c +++ b/src/settings/plugins/ifnet/nms-ifnet-plugin.c @@ -22,7 +22,7 @@ #include "nm-default.h" -#include "plugin.h" +#include "nms-ifnet-plugin.h" #include #include @@ -34,11 +34,11 @@ #include "nm-config.h" #include "NetworkManagerUtils.h" -#include "nm-ifnet-connection.h" -#include "net_utils.h" -#include "net_parser.h" -#include "wpa_parser.h" -#include "connection_parser.h" +#include "nms-ifnet-connection.h" +#include "nms-ifnet-net-utils.h" +#include "nms-ifnet-net-parser.h" +#include "nms-ifnet-wpa-parser.h" +#include "nms-ifnet-connection-parser.h" #define IFNET_PLUGIN_NAME_PRINT "ifnet" #define IFNET_PLUGIN_INFO "(C) 1999-2010 Gentoo Foundation, Inc. To report bugs please use bugs.gentoo.org with [networkmanager] or [qiaomuf] prefix." diff --git a/src/settings/plugins/ifnet/plugin.h b/src/settings/plugins/ifnet/nms-ifnet-plugin.h similarity index 100% rename from src/settings/plugins/ifnet/plugin.h rename to src/settings/plugins/ifnet/nms-ifnet-plugin.h diff --git a/src/settings/plugins/ifnet/wpa_parser.c b/src/settings/plugins/ifnet/nms-ifnet-wpa-parser.c similarity index 99% rename from src/settings/plugins/ifnet/wpa_parser.c rename to src/settings/plugins/ifnet/nms-ifnet-wpa-parser.c index 505222ab51..1d654d5181 100644 --- a/src/settings/plugins/ifnet/wpa_parser.c +++ b/src/settings/plugins/ifnet/nms-ifnet-wpa-parser.c @@ -21,13 +21,15 @@ #include "nm-default.h" +#include "nms-ifnet-wpa-parser.h" + #include #include #include "nm-settings-plugin.h" -#include "wpa_parser.h" -#include "net_parser.h" -#include "net_utils.h" + +#include "nms-ifnet-net-parser.h" +#include "nms-ifnet-net-utils.h" /* Security information */ static GHashTable *wsec_table = NULL; diff --git a/src/settings/plugins/ifnet/wpa_parser.h b/src/settings/plugins/ifnet/nms-ifnet-wpa-parser.h similarity index 100% rename from src/settings/plugins/ifnet/wpa_parser.h rename to src/settings/plugins/ifnet/nms-ifnet-wpa-parser.h diff --git a/src/settings/plugins/ifnet/tests/Makefile.am b/src/settings/plugins/ifnet/tests/Makefile.am index bdecfa10e5..7ff38fa09c 100644 --- a/src/settings/plugins/ifnet/tests/Makefile.am +++ b/src/settings/plugins/ifnet/tests/Makefile.am @@ -24,17 +24,17 @@ AM_CPPFLAGS= \ -DSYSCONFDIR=\"nonexistent\" noinst_PROGRAMS = test-ifnet + test_ifnet_SOURCES = \ - test-ifnet.c \ - ../connection_parser.c \ - ../net_parser.c \ - ../net_utils.c \ - ../wpa_parser.c + test-ifnet.c test_ifnet_LDFLAGS = \ + $(GLIB_LDFLAGS) $(CODE_COVERAGE_LDFLAGS) -test_ifnet_LDADD = $(top_builddir)/src/libNetworkManager.la +test_ifnet_LDADD = \ + $(top_builddir)/src/settings/plugins/ifnet/libnms-ifnet-core.la \ + $(top_builddir)/src/libNetworkManager.la @VALGRIND_RULES@ TESTS = test-ifnet diff --git a/src/settings/plugins/ifnet/tests/test-ifnet.c b/src/settings/plugins/ifnet/tests/test-ifnet.c index 49f88f1c1c..7ab11ba55f 100644 --- a/src/settings/plugins/ifnet/tests/test-ifnet.c +++ b/src/settings/plugins/ifnet/tests/test-ifnet.c @@ -30,13 +30,13 @@ #include "nm-utils.h" +#include "nm-config.h" #include "nm-linux-platform.h" -#include "net_parser.h" -#include "net_utils.h" -#include "wpa_parser.h" -#include "connection_parser.h" -#include "nm-config.h" +#include "nms-ifnet-net-parser.h" +#include "nms-ifnet-net-utils.h" +#include "nms-ifnet-wpa-parser.h" +#include "nms-ifnet-connection-parser.h" #include "nm-test-utils-core.h" diff --git a/src/settings/plugins/ifupdown/Makefile.am b/src/settings/plugins/ifupdown/Makefile.am index dbea6be612..539b8a2fe6 100644 --- a/src/settings/plugins/ifupdown/Makefile.am +++ b/src/settings/plugins/ifupdown/Makefile.am @@ -15,22 +15,31 @@ AM_CPPFLAGS = \ $(GUDEV_CFLAGS) \ -DSYSCONFDIR=\"$(sysconfdir)\" -noinst_LTLIBRARIES = libifupdown-io.la +pkglib_LTLIBRARIES = \ + libnm-settings-plugin-ifupdown.la -libifupdown_io_la_SOURCES = \ - interface_parser.c \ - interface_parser.h \ - parser.c \ - parser.h +noinst_LTLIBRARIES = \ + libnms-ifupdown-core.la -pkglib_LTLIBRARIES = libnm-settings-plugin-ifupdown.la +############################################################################### + +libnms_ifupdown_core_la_SOURCES = \ + nms-ifupdown-interface-parser.c \ + nms-ifupdown-interface-parser.h \ + nms-ifupdown-parser.c \ + nms-ifupdown-parser.h + +############################################################################### libnm_settings_plugin_ifupdown_la_SOURCES = \ - nm-ifupdown-connection.c \ - nm-ifupdown-connection.h \ - plugin.c \ - plugin.h + nms-ifupdown-connection.c \ + nms-ifupdown-connection.h \ + nms-ifupdown-plugin.c \ + nms-ifupdown-plugin.h -libnm_settings_plugin_ifupdown_la_LDFLAGS = -module -avoid-version -libnm_settings_plugin_ifupdown_la_LIBADD = libifupdown-io.la +libnm_settings_plugin_ifupdown_la_LDFLAGS = \ + -module -avoid-version + +libnm_settings_plugin_ifupdown_la_LIBADD = \ + libnms-ifupdown-core.la diff --git a/src/settings/plugins/ifupdown/nm-ifupdown-connection.c b/src/settings/plugins/ifupdown/nms-ifupdown-connection.c similarity index 97% rename from src/settings/plugins/ifupdown/nm-ifupdown-connection.c rename to src/settings/plugins/ifupdown/nms-ifupdown-connection.c index 15d30079d2..1c3333bddd 100644 --- a/src/settings/plugins/ifupdown/nm-ifupdown-connection.c +++ b/src/settings/plugins/ifupdown/nms-ifupdown-connection.c @@ -22,7 +22,7 @@ #include "nm-default.h" -#include "nm-ifupdown-connection.h" +#include "nms-ifupdown-connection.h" #include #include @@ -32,7 +32,8 @@ #include "nm-setting-wireless-security.h" #include "nm-settings-connection.h" #include "nm-settings-plugin.h" -#include "parser.h" + +#include "nms-ifupdown-parser.h" /*****************************************************************************/ diff --git a/src/settings/plugins/ifupdown/nm-ifupdown-connection.h b/src/settings/plugins/ifupdown/nms-ifupdown-connection.h similarity index 97% rename from src/settings/plugins/ifupdown/nm-ifupdown-connection.h rename to src/settings/plugins/ifupdown/nms-ifupdown-connection.h index f710b1b6f3..107cd69697 100644 --- a/src/settings/plugins/ifupdown/nm-ifupdown-connection.h +++ b/src/settings/plugins/ifupdown/nms-ifupdown-connection.h @@ -26,7 +26,7 @@ #include -#include "interface_parser.h" +#include "nms-ifupdown-interface-parser.h" #define NM_TYPE_IFUPDOWN_CONNECTION (nm_ifupdown_connection_get_type ()) #define NM_IFUPDOWN_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_IFUPDOWN_CONNECTION, NMIfupdownConnection)) diff --git a/src/settings/plugins/ifupdown/interface_parser.c b/src/settings/plugins/ifupdown/nms-ifupdown-interface-parser.c similarity index 99% rename from src/settings/plugins/ifupdown/interface_parser.c rename to src/settings/plugins/ifupdown/nms-ifupdown-interface-parser.c index 764ba5c93d..df6d248c03 100644 --- a/src/settings/plugins/ifupdown/interface_parser.c +++ b/src/settings/plugins/ifupdown/nms-ifupdown-interface-parser.c @@ -22,7 +22,7 @@ #include "nm-default.h" -#include "interface_parser.h" +#include "nms-ifupdown-interface-parser.h" #include #include diff --git a/src/settings/plugins/ifupdown/interface_parser.h b/src/settings/plugins/ifupdown/nms-ifupdown-interface-parser.h similarity index 100% rename from src/settings/plugins/ifupdown/interface_parser.h rename to src/settings/plugins/ifupdown/nms-ifupdown-interface-parser.h diff --git a/src/settings/plugins/ifupdown/parser.c b/src/settings/plugins/ifupdown/nms-ifupdown-parser.c similarity index 99% rename from src/settings/plugins/ifupdown/parser.c rename to src/settings/plugins/ifupdown/nms-ifupdown-parser.c index 109018dd28..00d56508cc 100644 --- a/src/settings/plugins/ifupdown/parser.c +++ b/src/settings/plugins/ifupdown/nms-ifupdown-parser.c @@ -23,6 +23,8 @@ #include "nm-default.h" +#include "nms-ifupdown-parser.h" + #include #include #include @@ -32,14 +34,10 @@ #include "nm-core-internal.h" #include "nm-settings-plugin.h" -#include "parser.h" -#include "plugin.h" +#include "nms-ifupdown-plugin.h" +#include "nms-ifupdown-parser.h" -#define WPA_PMK_LEN 32 - -#include "parser.h" - static const gchar* _ifupdownplugin_guess_connection_type (if_block *block) { diff --git a/src/settings/plugins/ifupdown/parser.h b/src/settings/plugins/ifupdown/nms-ifupdown-parser.h similarity index 96% rename from src/settings/plugins/ifupdown/parser.h rename to src/settings/plugins/ifupdown/nms-ifupdown-parser.h index 549f1ad3fb..36e52e2cbc 100644 --- a/src/settings/plugins/ifupdown/parser.h +++ b/src/settings/plugins/ifupdown/nms-ifupdown-parser.h @@ -25,7 +25,8 @@ #define __PARSER_H__ #include -#include "interface_parser.h" + +#include "nms-ifupdown-interface-parser.h" gboolean ifupdown_update_connection_from_if_block (NMConnection *connection, diff --git a/src/settings/plugins/ifupdown/plugin.c b/src/settings/plugins/ifupdown/nms-ifupdown-plugin.c similarity index 99% rename from src/settings/plugins/ifupdown/plugin.c rename to src/settings/plugins/ifupdown/nms-ifupdown-plugin.c index abb9af146d..35ae88e9f3 100644 --- a/src/settings/plugins/ifupdown/plugin.c +++ b/src/settings/plugins/ifupdown/nms-ifupdown-plugin.c @@ -24,7 +24,7 @@ #include "nm-default.h" -#include "plugin.h" +#include "nms-ifupdown-plugin.h" #include #include @@ -43,9 +43,9 @@ #include "NetworkManagerUtils.h" #include "nm-config.h" -#include "interface_parser.h" -#include "nm-ifupdown-connection.h" -#include "parser.h" +#include "nms-ifupdown-interface-parser.h" +#include "nms-ifupdown-connection.h" +#include "nms-ifupdown-parser.h" #define ENI_INTERFACES_FILE "/etc/network/interfaces" diff --git a/src/settings/plugins/ifupdown/plugin.h b/src/settings/plugins/ifupdown/nms-ifupdown-plugin.h similarity index 100% rename from src/settings/plugins/ifupdown/plugin.h rename to src/settings/plugins/ifupdown/nms-ifupdown-plugin.h diff --git a/src/settings/plugins/ifupdown/tests/Makefile.am b/src/settings/plugins/ifupdown/tests/Makefile.am index 6a4dcdf800..80abf8a9e7 100644 --- a/src/settings/plugins/ifupdown/tests/Makefile.am +++ b/src/settings/plugins/ifupdown/tests/Makefile.am @@ -18,11 +18,14 @@ AM_CPPFLAGS = \ noinst_PROGRAMS = test-ifupdown test_ifupdown_SOURCES = \ - test-ifupdown.c \ - ../interface_parser.c \ - ../parser.c + test-ifupdown.c + +test_ifupdown_LDFLAGS = \ + $(GLIB_LDFLAGS) + $(CODE_COVERAGE_LDFLAGS) test_ifupdown_LDADD = \ + $(top_builddir)/src/settings/plugins/ifupdown/libnms-ifupdown-core.la \ $(top_builddir)/src/libNetworkManager.la @VALGRIND_RULES@ diff --git a/src/settings/plugins/ifupdown/tests/test-ifupdown.c b/src/settings/plugins/ifupdown/tests/test-ifupdown.c index 11b42c7149..eaf7a67f96 100644 --- a/src/settings/plugins/ifupdown/tests/test-ifupdown.c +++ b/src/settings/plugins/ifupdown/tests/test-ifupdown.c @@ -23,8 +23,9 @@ #include #include "nm-core-internal.h" -#include "interface_parser.h" -#include "parser.h" + +#include "nms-ifupdown-interface-parser.h" +#include "nms-ifupdown-parser.h" #include "nm-test-utils-core.h" diff --git a/src/settings/plugins/keyfile/tests/Makefile.am b/src/settings/plugins/keyfile/tests/Makefile.am index d7c48b1921..c0b67d1595 100644 --- a/src/settings/plugins/keyfile/tests/Makefile.am +++ b/src/settings/plugins/keyfile/tests/Makefile.am @@ -20,14 +20,17 @@ AM_CPPFLAGS = \ -DTEST_SCRATCH_DIR=\"$(abs_builddir)/keyfiles\" \ -DNMCONFDIR=\"nonexistent\" +AM_LDFLAGS = \ + $(GLIB_LIBS) \ + $(CODE_COVERAGE_LDFLAGS) + noinst_PROGRAMS = test-keyfile test_keyfile_SOURCES = \ test-keyfile.c test_keyfile_LDADD = \ - $(top_builddir)/src/libNetworkManager.la \ - $(CODE_COVERAGE_LDFLAGS) + $(top_builddir)/src/libNetworkManager.la @VALGRIND_RULES@ TESTS = test-keyfile