From 8e6d619c46ed50b8be7512dc1db42683f7f9073c Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 16 May 2016 15:06:44 +0200 Subject: [PATCH 01/11] ifcfg-rh: use _nm_utils_ascii_str_to_int64() in reader's get_uint()/get_int() functions --- src/settings/plugins/ifcfg-rh/reader.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/settings/plugins/ifcfg-rh/reader.c b/src/settings/plugins/ifcfg-rh/reader.c index 0596edc1ad..fb9b0fa8ad 100644 --- a/src/settings/plugins/ifcfg-rh/reader.c +++ b/src/settings/plugins/ifcfg-rh/reader.c @@ -64,12 +64,10 @@ static gboolean get_int (const char *str, int *value) { - char *e; - long int tmp; + gint64 tmp; - errno = 0; - tmp = strtol (str, &e, 0); - if (errno || *e != '\0' || tmp > G_MAXINT || tmp < G_MININT) + tmp = _nm_utils_ascii_str_to_int64 (str, 0, G_MININT, G_MAXINT, 0); + if (tmp == 0 && errno) return FALSE; *value = (int) tmp; return TRUE; @@ -78,14 +76,12 @@ get_int (const char *str, int *value) static gboolean get_uint (const char *str, guint32 *value) { - char *e; - long unsigned int tmp; + gint64 tmp; - errno = 0; - tmp = strtoul (str, &e, 0); - if (errno || *e != '\0') + tmp = _nm_utils_ascii_str_to_int64 (str, 0, 0, G_MAXUINT32, -1); + if (tmp == -1) return FALSE; - *value = (guint32) tmp; + *value = tmp; return TRUE; } @@ -2201,10 +2197,10 @@ make_wep_setting (shvarFile *ifcfg, } else { g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Invalid default WEP key '%s'", value); - g_free (value); + g_free (value); goto error; } - g_free (value); + g_free (value); } /* Read WEP key flags */ From ec639b5c63642752b260d02fe0ee6295c3a0577f Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 16 May 2016 15:10:16 +0200 Subject: [PATCH 02/11] ifcfg-rh: cast variadic arguments to proper int type --- src/settings/plugins/ifcfg-rh/reader.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/settings/plugins/ifcfg-rh/reader.c b/src/settings/plugins/ifcfg-rh/reader.c index fb9b0fa8ad..a2e8c46883 100644 --- a/src/settings/plugins/ifcfg-rh/reader.c +++ b/src/settings/plugins/ifcfg-rh/reader.c @@ -3782,7 +3782,7 @@ make_wired_setting (shvarFile *ifcfg, if (value) { if (get_int (value, &mtu)) { if (mtu >= 0 && mtu < 65536) - g_object_set (s_wired, NM_SETTING_WIRED_MTU, mtu, NULL); + g_object_set (s_wired, NM_SETTING_WIRED_MTU, (guint) mtu, NULL); } else { /* Shouldn't be fatal... */ PARSE_WARNING ("invalid MTU '%s'", value); @@ -4032,7 +4032,7 @@ make_infiniband_setting (shvarFile *ifcfg, if (value) { if (get_int (value, &mtu)) { if (mtu >= 0 && mtu < 65536) - g_object_set (s_infiniband, NM_SETTING_INFINIBAND_MTU, mtu, NULL); + g_object_set (s_infiniband, NM_SETTING_INFINIBAND_MTU, (guint) mtu, NULL); } else { /* Shouldn't be fatal... */ PARSE_WARNING ("invalid MTU '%s'", value); From 7328613d7bb3853095ac4d1e2949293a31e78fc9 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 16 May 2016 15:14:07 +0200 Subject: [PATCH 03/11] ifcfg-rh: don't use get_int() to parse MTU value And print a warning also if the value is out of range. --- src/settings/plugins/ifcfg-rh/reader.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/settings/plugins/ifcfg-rh/reader.c b/src/settings/plugins/ifcfg-rh/reader.c index a2e8c46883..60bf4ca40b 100644 --- a/src/settings/plugins/ifcfg-rh/reader.c +++ b/src/settings/plugins/ifcfg-rh/reader.c @@ -3773,20 +3773,19 @@ make_wired_setting (shvarFile *ifcfg, { NMSettingWired *s_wired; char *value = NULL; - int mtu; char *nettype; s_wired = NM_SETTING_WIRED (nm_setting_wired_new ()); value = svGetValue (ifcfg, "MTU", FALSE); if (value) { - if (get_int (value, &mtu)) { - if (mtu >= 0 && mtu < 65536) - g_object_set (s_wired, NM_SETTING_WIRED_MTU, (guint) mtu, NULL); - } else { - /* Shouldn't be fatal... */ + int mtu; + + mtu = _nm_utils_ascii_str_to_int64 (value, 0, 0, 65535, -1); + if (mtu >= 0) + g_object_set (s_wired, NM_SETTING_WIRED_MTU, (guint) mtu, NULL); + else PARSE_WARNING ("invalid MTU '%s'", value); - } g_free (value); } @@ -4024,19 +4023,18 @@ make_infiniband_setting (shvarFile *ifcfg, { NMSettingInfiniband *s_infiniband; char *value = NULL; - int mtu; s_infiniband = NM_SETTING_INFINIBAND (nm_setting_infiniband_new ()); value = svGetValue (ifcfg, "MTU", FALSE); if (value) { - if (get_int (value, &mtu)) { - if (mtu >= 0 && mtu < 65536) - g_object_set (s_infiniband, NM_SETTING_INFINIBAND_MTU, (guint) mtu, NULL); - } else { - /* Shouldn't be fatal... */ + int mtu; + + mtu = _nm_utils_ascii_str_to_int64 (value, 0, 0, 65535, -1); + if (mtu >= 0) + g_object_set (s_infiniband, NM_SETTING_INFINIBAND_MTU, (guint) mtu, NULL); + else PARSE_WARNING ("invalid MTU '%s'", value); - } g_free (value); } From 4b538ea8f12b35ec775fd1ba7c0d3118f8cb365d Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 16 May 2016 15:16:52 +0200 Subject: [PATCH 04/11] ifcfg-rh: replace uses of get_int() --- src/settings/plugins/ifcfg-rh/reader.c | 38 +++++++++----------------- 1 file changed, 13 insertions(+), 25 deletions(-) diff --git a/src/settings/plugins/ifcfg-rh/reader.c b/src/settings/plugins/ifcfg-rh/reader.c index 60bf4ca40b..f13ae5c814 100644 --- a/src/settings/plugins/ifcfg-rh/reader.c +++ b/src/settings/plugins/ifcfg-rh/reader.c @@ -61,18 +61,6 @@ #define PARSE_WARNING(msg...) nm_log_warn (LOGD_SETTINGS, " " msg) -static gboolean -get_int (const char *str, int *value) -{ - gint64 tmp; - - tmp = _nm_utils_ascii_str_to_int64 (str, 0, G_MININT, G_MAXINT, 0); - if (tmp == 0 && errno) - return FALSE; - *value = (int) tmp; - return TRUE; -} - static gboolean get_uint (const char *str, guint32 *value) { @@ -1693,10 +1681,9 @@ read_dcb_app (shvarFile *ifcfg, tmp = g_strdup_printf ("DCB_APP_%s_PRIORITY", app); val = svGetValue (ifcfg, tmp, FALSE); if (val) { - success = get_int (val, &priority); - if (success) - success = (priority >= 0 && priority <= 7); - if (!success) { + priority = _nm_utils_ascii_str_to_int64 (val, 0, 0, 7, -1); + if (priority < 0) { + success = FALSE; g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Invalid %s value '%s' (expected 0 - 7)", tmp, val); @@ -1836,7 +1823,6 @@ read_dcb_percent_array (shvarFile *ifcfg, char *val; gboolean success = FALSE; char **split = NULL, **iter; - int tmp; guint i, sum = 0; val = svGetValue (ifcfg, prop, FALSE); @@ -1859,7 +1845,10 @@ read_dcb_percent_array (shvarFile *ifcfg, } for (iter = split, i = 0; iter && *iter; iter++, i++) { - if (!get_int (*iter, &tmp) || tmp < 0 || tmp > 100) { + int tmp; + + tmp = _nm_utils_ascii_str_to_int64 (*iter, 0, 0, 100, -1); + if (tmp < 0) { PARSE_WARNING ("invalid %s percentage value '%s'", prop, *iter); g_set_error_literal (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "invalid percent element"); @@ -2181,7 +2170,7 @@ make_wep_setting (shvarFile *ifcfg, char *value; shvarFile *keys_ifcfg = NULL; int default_key_idx = 0; - gboolean has_default_key = FALSE, success; + gboolean has_default_key = FALSE; NMSettingSecretFlags key_flags; s_wsec = NM_SETTING_WIRELESS_SECURITY (nm_setting_wireless_security_new ()); @@ -2189,17 +2178,16 @@ make_wep_setting (shvarFile *ifcfg, value = svGetValue (ifcfg, "DEFAULTKEY", FALSE); if (value) { - success = get_int (value, &default_key_idx); - if (success && (default_key_idx >= 1) && (default_key_idx <= 4)) { - has_default_key = TRUE; - default_key_idx--; /* convert to [0...3] */ - g_object_set (s_wsec, NM_SETTING_WIRELESS_SECURITY_WEP_TX_KEYIDX, default_key_idx, NULL); - } else { + default_key_idx = _nm_utils_ascii_str_to_int64 (value, 0, 1, 4, 0); + if (default_key_idx == 0) { g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Invalid default WEP key '%s'", value); g_free (value); goto error; } + has_default_key = TRUE; + default_key_idx--; /* convert to [0...3] */ + g_object_set (s_wsec, NM_SETTING_WIRELESS_SECURITY_WEP_TX_KEYIDX, (guint) default_key_idx, NULL); g_free (value); } From a85c3db2f0ce908b19846c118f78c33a86dbadd9 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 16 May 2016 15:31:42 +0200 Subject: [PATCH 05/11] ifcfg-rh: use _nm_utils_ascii_str_to_int64() instead of strtol() --- src/settings/plugins/ifcfg-rh/reader.c | 78 +++++++++++--------------- 1 file changed, 33 insertions(+), 45 deletions(-) diff --git a/src/settings/plugins/ifcfg-rh/reader.c b/src/settings/plugins/ifcfg-rh/reader.c index f13ae5c814..300c0d4c26 100644 --- a/src/settings/plugins/ifcfg-rh/reader.c +++ b/src/settings/plugins/ifcfg-rh/reader.c @@ -226,15 +226,12 @@ make_connection_setting (const char *file, value = svGetValue (ifcfg, "GATEWAY_PING_TIMEOUT", FALSE); if (value) { - long int tmp; - guint32 timeout; + gint64 tmp; - errno = 0; - tmp = strtol (value, NULL, 10); - if (errno == 0 && tmp >= 0 && tmp < G_MAXINT32) { - timeout = (guint32) tmp; - g_object_set (s_con, NM_SETTING_CONNECTION_GATEWAY_PING_TIMEOUT, timeout, NULL); - } else + tmp = _nm_utils_ascii_str_to_int64 (value, 10, 0, G_MAXINT32 - 1, -1); + if (tmp >= 0) + g_object_set (s_con, NM_SETTING_CONNECTION_GATEWAY_PING_TIMEOUT, (guint) tmp, NULL); + else PARSE_WARNING ("invalid GATEWAY_PING_TIMEOUT time"); g_free (value); } @@ -525,7 +522,8 @@ read_route_file_legacy (const char *filename, NMSettingIPConfig *s_ip4, GError * char **lines = NULL, **iter; GRegex *regex_to1, *regex_to2, *regex_via, *regex_metric; GMatchInfo *match_info; - gint64 prefix_int, metric_int; + int prefix_int; + gint64 metric_int; gboolean success = FALSE; const char *pattern_empty = "^\\s*(\\#.*)?$"; @@ -593,9 +591,8 @@ read_route_file_legacy (const char *filename, NMSettingIPConfig *s_ip4, GError * g_match_info_free (match_info); prefix_int = 32; if (prefix) { - errno = 0; - prefix_int = strtol (prefix, NULL, 10); - if (errno || prefix_int <= 0 || prefix_int > 32) { + prefix_int = _nm_utils_ascii_str_to_int64 (prefix, 10, 1, 32, -1); + if (prefix_int == -1) { g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Invalid IP4 route destination prefix '%s'", prefix); g_free (prefix); @@ -625,9 +622,8 @@ read_route_file_legacy (const char *filename, NMSettingIPConfig *s_ip4, GError * metric_int = -1; if (g_match_info_matches (match_info)) { metric = g_match_info_fetch (match_info, 1); - errno = 0; - metric_int = strtol (metric, NULL, 10); - if (errno || metric_int < 0) { + metric_int = _nm_utils_ascii_str_to_int64 (metric, 10, 0, G_MAXUINT32, -1); + if (metric_int == -1) { g_match_info_free (match_info); g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Invalid IP4 route metric '%s'", metric); @@ -750,7 +746,8 @@ read_route6_file (const char *filename, NMSettingIPConfig *s_ip6, GError **error GRegex *regex_to1, *regex_to2, *regex_via, *regex_metric; GMatchInfo *match_info; char *dest = NULL, *prefix = NULL, *next_hop = NULL, *metric = NULL; - gint64 prefix_int, metric_int; + int prefix_int; + gint64 metric_int; gboolean success = FALSE; const char *pattern_empty = "^\\s*(\\#.*)?$"; @@ -812,9 +809,8 @@ read_route6_file (const char *filename, NMSettingIPConfig *s_ip6, GError **error g_match_info_free (match_info); prefix_int = 128; if (prefix) { - errno = 0; - prefix_int = strtol (prefix, NULL, 10); - if (errno || prefix_int <= 0 || prefix_int > 128) { + prefix_int = _nm_utils_ascii_str_to_int64 (prefix, 10, 1, 128, -1); + if (prefix_int == -1) { g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Invalid IP6 route destination prefix '%s'", prefix); g_free (dest); @@ -848,9 +844,8 @@ read_route6_file (const char *filename, NMSettingIPConfig *s_ip6, GError **error metric_int = -1; if (g_match_info_matches (match_info)) { metric = g_match_info_fetch (match_info, 1); - errno = 0; - metric_int = strtol (metric, NULL, 10); - if (errno || metric_int < 0 || metric_int > G_MAXUINT32) { + metric_int = _nm_utils_ascii_str_to_int64 (metric, 10, 0, G_MAXUINT32, -1); + if (metric_int == -1) { g_match_info_free (match_info); g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Invalid IP6 route metric '%s'", metric); @@ -3489,17 +3484,16 @@ make_wireless_setting (shvarFile *ifcfg, value = svGetValue (ifcfg, "MTU", FALSE); if (value) { - long int mtu; + int mtu; - errno = 0; - mtu = strtol (value, NULL, 10); - if (errno || mtu < 0 || mtu > 50000) { + mtu = _nm_utils_ascii_str_to_int64 (value, 10, 0, 50000, -1); + if (mtu == -1) { g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Invalid wireless MTU '%s'", value); g_free (value); goto error; } - g_object_set (s_wireless, NM_SETTING_WIRELESS_MTU, (guint32) mtu, NULL); + g_object_set (s_wireless, NM_SETTING_WIRELESS_MTU, (guint) mtu, NULL); g_free (value); } @@ -3944,9 +3938,9 @@ parse_infiniband_p_key (shvarFile *ifcfg, char **out_parent, GError **error) { - char *device = NULL, *physdev = NULL, *pkey_id = NULL, *end; + char *device = NULL, *physdev = NULL, *pkey_id = NULL; char *ifname = NULL; - guint32 id = G_MAXUINT32; + int id; gboolean ret = FALSE; device = svGetValue (ifcfg, "DEVICE", FALSE); @@ -3967,19 +3961,14 @@ parse_infiniband_p_key (shvarFile *ifcfg, goto done; } - if (g_str_has_prefix (pkey_id, "0x")) - id = strtoul (pkey_id, &end, 16); - else if (!g_str_has_prefix (pkey_id, "0")) - id = strtoul (pkey_id, &end, 10); - else - end = pkey_id; - if (end == pkey_id || *end || id > 0xFFFF) { + id = _nm_utils_ascii_str_to_int64 (pkey_id, 0, 0, 0xFFFF, -1); + if (id == -1) { PARSE_WARNING ("invalid InfiniBand PKEY_ID '%s'", pkey_id); goto done; } id = (id | 0x8000); - ifname = g_strdup_printf ("%s.%04x", physdev, id); + ifname = g_strdup_printf ("%s.%04x", physdev, (unsigned) id); if (strcmp (device, ifname) != 0) { PARSE_WARNING ("InfiniBand DEVICE (%s) does not match PHYSDEV+PKEY_ID (%s)", device, ifname); @@ -4646,16 +4635,14 @@ make_vlan_setting (shvarFile *ifcfg, char *iface_name = NULL; char *parent = NULL; const char *p = NULL; - char *end = NULL; - gint vlan_id = -1; + int vlan_id = -1; guint32 vlan_flags = 0; gint gvrp, reorder_hdr; value = svGetValue (ifcfg, "VLAN_ID", FALSE); if (value) { - errno = 0; - vlan_id = (gint) g_ascii_strtoll (value, NULL, 10); - if (vlan_id < 0 || vlan_id > 4096 || errno) { + vlan_id = _nm_utils_ascii_str_to_int64 (value, 10, 0, 4096, -1); + if (vlan_id == -1) { g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Invalid VLAN_ID '%s'", value); g_free (value); @@ -4699,12 +4686,13 @@ make_vlan_setting (shvarFile *ifcfg, } if (p) { + int device_vlan_id; + /* Grab VLAN ID from interface name; this takes precedence over the * separate VLAN_ID property for backwards compat. */ - - gint device_vlan_id = (gint) g_ascii_strtoll (p, &end, 10); - if (device_vlan_id >= 0 && device_vlan_id <= 4095 && end != p && !*end) + device_vlan_id = _nm_utils_ascii_str_to_int64 (p, 10, 0, 4095, -1); + if (device_vlan_id != -1) vlan_id = device_vlan_id; } } From c949e1c42944497c826a3d77b3aed1d697064c2b Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 16 May 2016 15:43:56 +0200 Subject: [PATCH 06/11] ifcfg-rh: reject vlan id of value 4096 Maybe we should also reject 0 and 4095, but for now leave it. --- src/settings/plugins/ifcfg-rh/reader.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/settings/plugins/ifcfg-rh/reader.c b/src/settings/plugins/ifcfg-rh/reader.c index 300c0d4c26..e5de03907b 100644 --- a/src/settings/plugins/ifcfg-rh/reader.c +++ b/src/settings/plugins/ifcfg-rh/reader.c @@ -4641,7 +4641,7 @@ make_vlan_setting (shvarFile *ifcfg, value = svGetValue (ifcfg, "VLAN_ID", FALSE); if (value) { - vlan_id = _nm_utils_ascii_str_to_int64 (value, 10, 0, 4096, -1); + vlan_id = _nm_utils_ascii_str_to_int64 (value, 10, 0, 4095, -1); if (vlan_id == -1) { g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Invalid VLAN_ID '%s'", value); From a519cc57b86815eece934c0a36e96aa2c0694386 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 16 May 2016 15:51:42 +0200 Subject: [PATCH 07/11] ifcfg-rh: use _NMLOG() macro in reader This gives every logging line a proper "ifcfg-rh" prefix. --- src/settings/plugins/ifcfg-rh/reader.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/settings/plugins/ifcfg-rh/reader.c b/src/settings/plugins/ifcfg-rh/reader.c index e5de03907b..f40f2f06a6 100644 --- a/src/settings/plugins/ifcfg-rh/reader.c +++ b/src/settings/plugins/ifcfg-rh/reader.c @@ -59,7 +59,21 @@ #include "reader.h" -#define PARSE_WARNING(msg...) nm_log_warn (LOGD_SETTINGS, " " msg) +/*****************************************************************************/ + +#define _NMLOG_DOMAIN LOGD_SETTINGS +#define _NMLOG_PREFIX_NAME "ifcfg-rh" +#define _NMLOG(level, ...) \ + G_STMT_START { \ + nm_log ((level), (_NMLOG_DOMAIN), \ + "%s" _NM_UTILS_MACRO_FIRST(__VA_ARGS__), \ + _NMLOG_PREFIX_NAME": " \ + _NM_UTILS_MACRO_REST(__VA_ARGS__)); \ + } G_STMT_END + +#define PARSE_WARNING(...) _LOGW ("%s" _NM_UTILS_MACRO_FIRST(__VA_ARGS__), " " _NM_UTILS_MACRO_REST(__VA_ARGS__)) + +/*****************************************************************************/ static gboolean get_uint (const char *str, guint32 *value) From f3bd778d6d31ea50752c380bafc86cf588e9ad99 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 16 May 2016 16:19:22 +0200 Subject: [PATCH 08/11] ifcfg-rh: use _NMLOG() macro in writer This gives every logging line a proper "ifcfg-rh" prefix. But drop the " " prefixes. --- src/settings/plugins/ifcfg-rh/writer.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/settings/plugins/ifcfg-rh/writer.c b/src/settings/plugins/ifcfg-rh/writer.c index 96ed1f1a60..e99676dbf5 100644 --- a/src/settings/plugins/ifcfg-rh/writer.c +++ b/src/settings/plugins/ifcfg-rh/writer.c @@ -53,6 +53,19 @@ #include "utils.h" #include "crypto.h" +/*****************************************************************************/ + +#define _NMLOG_DOMAIN LOGD_SETTINGS +#define _NMLOG_PREFIX_NAME "ifcfg-rh" +#define _NMLOG(level, ...) \ + G_STMT_START { \ + nm_log ((level), (_NMLOG_DOMAIN), \ + "%s" _NM_UTILS_MACRO_FIRST(__VA_ARGS__), \ + _NMLOG_PREFIX_NAME": " \ + _NM_UTILS_MACRO_REST(__VA_ARGS__)); \ + } G_STMT_END + +/*****************************************************************************/ static void save_secret_flags (shvarFile *ifcfg, @@ -100,7 +113,7 @@ set_secret (shvarFile *ifcfg, { shvarFile *keyfile; GError *error = NULL; - + /* Clear the secret from the ifcfg and the associated "keys" file */ svSetValue (ifcfg, key, NULL, FALSE); @@ -109,7 +122,7 @@ set_secret (shvarFile *ifcfg, keyfile = utils_get_keys_ifcfg (ifcfg->fileName, TRUE); if (!keyfile) { - nm_log_warn (LOGD_SETTINGS, " could not create ifcfg file for '%s'", ifcfg->fileName); + _LOGW ("could not create ifcfg file for '%s'", ifcfg->fileName); goto error; } @@ -121,8 +134,8 @@ set_secret (shvarFile *ifcfg, svSetValue (keyfile, key, value, verbatim); if (!svWriteFile (keyfile, 0600, &error)) { - nm_log_warn (LOGD_SETTINGS, " could not update ifcfg file '%s': %s", - keyfile->fileName, error->message); + _LOGW ("could not update ifcfg file '%s': %s", + keyfile->fileName, error->message); g_clear_error (&error); svCloseFile (keyfile); goto error; @@ -715,7 +728,7 @@ write_wireless_security_setting (NMConnection *connection, key = ascii_key; } } else { - nm_log_warn (LOGD_SETTINGS, " invalid WEP key '%s'", key); + _LOGW ("invalid WEP key '%s'", key); tmp = NULL; } From b503b376360cb05ecfc7f39ed4c4fe9f5a4b6ee5 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 16 May 2016 16:17:09 +0200 Subject: [PATCH 09/11] ifcfg-rh: don't print warning in svGetValueInt64() Having a simple accessor print warnings is not nice. At that point there is no context as to why we are trying to read the value. Note that the function already handles and expects invalid values, it's just not clear that printing warnings from a utility function is the right thing to do. Just ignore such cases silently (at this point). It's up to the caller to print a warning or whatever. --- src/settings/plugins/ifcfg-rh/shvar.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/settings/plugins/ifcfg-rh/shvar.c b/src/settings/plugins/ifcfg-rh/shvar.c index 4e756349ca..4031692817 100644 --- a/src/settings/plugins/ifcfg-rh/shvar.c +++ b/src/settings/plugins/ifcfg-rh/shvar.c @@ -38,8 +38,6 @@ #include "nm-core-internal.h" -#define PARSE_WARNING(msg...) nm_log_warn (LOGD_SETTINGS, " " msg) - /* 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. @@ -373,11 +371,10 @@ svGetValueInt64 (shvarFile *s, const char *key, guint base, gint64 min, gint64 m result = _nm_utils_ascii_str_to_int64 (tmp, base, min, max, fallback); errsv = errno; - if (errsv != 0) - PARSE_WARNING ("Error reading '%s' value '%s' as integer (%d)", key, tmp, errsv); g_free (tmp); + errno = errsv; return result; } From 4dcb5e5ba5fbb1048f93cd8396d704fb657e608c Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 16 May 2016 16:02:21 +0200 Subject: [PATCH 10/11] ifcfg-rh: cleanup includes - don't include "nm-default.h" from headers. All source files include this header as first. - drop G_BEGIN_DECLS/G_END_DECLS. This is not C++ nor public API. - drop unnecessary includes from header files. They are either not required, or already provided via "nm-default.h". - include in source files the corresponding header file as first after "nm-default.h". This should ensure that header files are self-contained (appart from "nm-default.h"). --- src/settings/plugins/ifcfg-rh/common.h | 4 +--- src/settings/plugins/ifcfg-rh/nm-ifcfg-connection.c | 3 ++- src/settings/plugins/ifcfg-rh/nm-ifcfg-connection.h | 8 ++------ src/settings/plugins/ifcfg-rh/plugin.c | 7 ++++--- src/settings/plugins/ifcfg-rh/plugin.h | 4 +--- src/settings/plugins/ifcfg-rh/reader.c | 4 ++-- src/settings/plugins/ifcfg-rh/reader.h | 5 +---- src/settings/plugins/ifcfg-rh/shvar.c | 4 ++-- src/settings/plugins/ifcfg-rh/shvar.h | 8 +------- src/settings/plugins/ifcfg-rh/utils.c | 3 ++- src/settings/plugins/ifcfg-rh/utils.h | 5 ++--- src/settings/plugins/ifcfg-rh/writer.c | 2 -- src/settings/plugins/ifcfg-rh/writer.h | 6 +----- 13 files changed, 21 insertions(+), 42 deletions(-) diff --git a/src/settings/plugins/ifcfg-rh/common.h b/src/settings/plugins/ifcfg-rh/common.h index 5d6ebe6d65..d850ac4e75 100644 --- a/src/settings/plugins/ifcfg-rh/common.h +++ b/src/settings/plugins/ifcfg-rh/common.h @@ -21,8 +21,6 @@ #ifndef __COMMON_H__ #define __COMMON_H__ -#include "nm-default.h" - #define IFCFG_TAG "ifcfg-" #define KEYS_TAG "keys-" #define ROUTE_TAG "route-" @@ -38,7 +36,7 @@ #define AUGNEW_TAG ".augnew" #define AUGTMP_TAG ".augtmp" -#define IFCFG_DIR SYSCONFDIR"/sysconfig/network-scripts" +#define IFCFG_DIR SYSCONFDIR "/sysconfig/network-scripts" #define IFCFG_PLUGIN_NAME "ifcfg-rh" #define IFCFG_PLUGIN_INFO "(c) 2007 - 2015 Red Hat, Inc. To report bugs please use the NetworkManager mailing list." diff --git a/src/settings/plugins/ifcfg-rh/nm-ifcfg-connection.c b/src/settings/plugins/ifcfg-rh/nm-ifcfg-connection.c index b9bbf6d5b0..3efd99a4c5 100644 --- a/src/settings/plugins/ifcfg-rh/nm-ifcfg-connection.c +++ b/src/settings/plugins/ifcfg-rh/nm-ifcfg-connection.c @@ -20,6 +20,8 @@ #include "nm-default.h" +#include "nm-ifcfg-connection.h" + #include #include @@ -37,7 +39,6 @@ #include "common.h" #include "nm-config.h" -#include "nm-ifcfg-connection.h" #include "reader.h" #include "writer.h" #include "nm-inotify-helper.h" diff --git a/src/settings/plugins/ifcfg-rh/nm-ifcfg-connection.h b/src/settings/plugins/ifcfg-rh/nm-ifcfg-connection.h index 44e0298772..57db059b00 100644 --- a/src/settings/plugins/ifcfg-rh/nm-ifcfg-connection.h +++ b/src/settings/plugins/ifcfg-rh/nm-ifcfg-connection.h @@ -21,10 +21,8 @@ #ifndef __NETWORKMANAGER_IFCFG_CONNECTION_H__ #define __NETWORKMANAGER_IFCFG_CONNECTION_H__ -G_BEGIN_DECLS - -#include -#include +#include "nm-dbus-interface.h" +#include "nm-settings-connection.h" #define NM_TYPE_IFCFG_CONNECTION (nm_ifcfg_connection_get_type ()) #define NM_IFCFG_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_IFCFG_CONNECTION, NMIfcfgConnection)) @@ -58,6 +56,4 @@ gboolean nm_ifcfg_connection_update (NMIfcfgConnection *self, GHashTable *new_settings, GError **error); -G_END_DECLS - #endif /* __NETWORKMANAGER_IFCFG_CONNECTION_H__ */ diff --git a/src/settings/plugins/ifcfg-rh/plugin.c b/src/settings/plugins/ifcfg-rh/plugin.c index 1fb6b78947..bda41234d7 100644 --- a/src/settings/plugins/ifcfg-rh/plugin.c +++ b/src/settings/plugins/ifcfg-rh/plugin.c @@ -23,6 +23,8 @@ #include "nm-default.h" +#include "plugin.h" + #include #include #include @@ -31,20 +33,19 @@ #include +#include "nm-dbus-compat.h" #include "nm-setting-connection.h" -#include "common.h" -#include "plugin.h" #include "nm-settings-plugin.h" #include "nm-config.h" #include "NetworkManagerUtils.h" #include "nm-ifcfg-connection.h" #include "shvar.h" +#include "common.h" #include "reader.h" #include "writer.h" #include "utils.h" -#include "nm-dbus-compat.h" #include "nm-exported-object.h" #include "nmdbus-ifcfg-rh.h" diff --git a/src/settings/plugins/ifcfg-rh/plugin.h b/src/settings/plugins/ifcfg-rh/plugin.h index eba734cff8..74c4b00a04 100644 --- a/src/settings/plugins/ifcfg-rh/plugin.h +++ b/src/settings/plugins/ifcfg-rh/plugin.h @@ -24,8 +24,6 @@ #ifndef _PLUGIN_H_ #define _PLUGIN_H_ -#include "nm-exported-object.h" - #define SETTINGS_TYPE_PLUGIN_IFCFG (settings_plugin_ifcfg_get_type ()) #define SETTINGS_PLUGIN_IFCFG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SETTINGS_TYPE_PLUGIN_IFCFG, SettingsPluginIfcfg)) #define SETTINGS_PLUGIN_IFCFG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SETTINGS_TYPE_PLUGIN_IFCFG, SettingsPluginIfcfgClass)) @@ -46,5 +44,5 @@ struct _SettingsPluginIfcfgClass { GType settings_plugin_ifcfg_get_type (void); -#endif /* _PLUGIN_H_ */ +#endif /* _PLUGIN_H_ */ diff --git a/src/settings/plugins/ifcfg-rh/reader.c b/src/settings/plugins/ifcfg-rh/reader.c index f40f2f06a6..240149b3e3 100644 --- a/src/settings/plugins/ifcfg-rh/reader.c +++ b/src/settings/plugins/ifcfg-rh/reader.c @@ -20,6 +20,8 @@ #include "nm-default.h" +#include "reader.h" + #include #include #include @@ -57,8 +59,6 @@ #include "shvar.h" #include "utils.h" -#include "reader.h" - /*****************************************************************************/ #define _NMLOG_DOMAIN LOGD_SETTINGS diff --git a/src/settings/plugins/ifcfg-rh/reader.h b/src/settings/plugins/ifcfg-rh/reader.h index 88f9a72007..35464474f2 100644 --- a/src/settings/plugins/ifcfg-rh/reader.h +++ b/src/settings/plugins/ifcfg-rh/reader.h @@ -21,10 +21,7 @@ #ifndef __READER_H__ #define __READER_H__ -#include - -#include "nm-default.h" -#include "shvar.h" +#include "nm-connection.h" NMConnection *connection_from_file (const char *filename, char **out_unhandled, diff --git a/src/settings/plugins/ifcfg-rh/shvar.c b/src/settings/plugins/ifcfg-rh/shvar.c index 4031692817..9931c79cf1 100644 --- a/src/settings/plugins/ifcfg-rh/shvar.c +++ b/src/settings/plugins/ifcfg-rh/shvar.c @@ -25,6 +25,8 @@ #include "nm-default.h" +#include "shvar.h" + #include #include #include @@ -34,8 +36,6 @@ #include #include -#include "shvar.h" - #include "nm-core-internal.h" /* Open the file , returning a shvarFile on success and NULL on failure. diff --git a/src/settings/plugins/ifcfg-rh/shvar.h b/src/settings/plugins/ifcfg-rh/shvar.h index 227a44db17..97df81284a 100644 --- a/src/settings/plugins/ifcfg-rh/shvar.h +++ b/src/settings/plugins/ifcfg-rh/shvar.h @@ -31,10 +31,6 @@ #ifndef _SHVAR_H #define _SHVAR_H -#include "nm-default.h" - -G_BEGIN_DECLS - typedef struct _shvarFile shvarFile; struct _shvarFile { char *fileName; /* read-only */ @@ -95,6 +91,4 @@ const char *svEscape (const char *s, char **to_free); /* Unescape a string in-place */ void svUnescape (char *s); -G_END_DECLS - -#endif /* ! _SHVAR_H */ +#endif /* _SHVAR_H */ diff --git a/src/settings/plugins/ifcfg-rh/utils.c b/src/settings/plugins/ifcfg-rh/utils.c index fda900b20e..b602a7d7c3 100644 --- a/src/settings/plugins/ifcfg-rh/utils.c +++ b/src/settings/plugins/ifcfg-rh/utils.c @@ -27,7 +27,8 @@ #include "nm-core-internal.h" #include "NetworkManagerUtils.h" -#include "shvar.h" + +#include "common.h" /* * utils_single_quote_string diff --git a/src/settings/plugins/ifcfg-rh/utils.h b/src/settings/plugins/ifcfg-rh/utils.h index 752d08a60b..b8b172e7ce 100644 --- a/src/settings/plugins/ifcfg-rh/utils.h +++ b/src/settings/plugins/ifcfg-rh/utils.h @@ -21,10 +21,9 @@ #ifndef _UTILS_H_ #define _UTILS_H_ -#include -#include "nm-default.h" +#include "nm-connection.h" + #include "shvar.h" -#include "common.h" #define NM_IFCFG_CONNECTION_LOG_PATH(path) ((path) ?: "in-memory") #define NM_IFCFG_CONNECTION_LOG_FMT "%s (%s,\"%s\")" diff --git a/src/settings/plugins/ifcfg-rh/writer.c b/src/settings/plugins/ifcfg-rh/writer.c index e99676dbf5..55ef2cc766 100644 --- a/src/settings/plugins/ifcfg-rh/writer.c +++ b/src/settings/plugins/ifcfg-rh/writer.c @@ -42,7 +42,6 @@ #include "nm-setting-vlan.h" #include "nm-setting-team.h" #include "nm-setting-team-port.h" -#include "nm-core-internal.h" #include "nm-utils.h" #include "nm-core-internal.h" #include "NetworkManagerUtils.h" @@ -51,7 +50,6 @@ #include "shvar.h" #include "reader.h" #include "utils.h" -#include "crypto.h" /*****************************************************************************/ diff --git a/src/settings/plugins/ifcfg-rh/writer.h b/src/settings/plugins/ifcfg-rh/writer.h index 69389361c9..97a9f25252 100644 --- a/src/settings/plugins/ifcfg-rh/writer.h +++ b/src/settings/plugins/ifcfg-rh/writer.h @@ -21,11 +21,7 @@ #ifndef _WRITER_H_ #define _WRITER_H_ -#include - -#include - -#include "nm-default.h" +#include "nm-connection.h" gboolean writer_can_write_connection (NMConnection *connection, GError **error); From 2d428bda35244baa1d2ba0732dedb9f04d67e465 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 16 May 2016 16:24:00 +0200 Subject: [PATCH 11/11] ifcfg-rh: remove unused define ERR_GET_MSG() --- src/settings/plugins/ifcfg-rh/plugin.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/settings/plugins/ifcfg-rh/plugin.c b/src/settings/plugins/ifcfg-rh/plugin.c index bda41234d7..1c0ce918b1 100644 --- a/src/settings/plugins/ifcfg-rh/plugin.c +++ b/src/settings/plugins/ifcfg-rh/plugin.c @@ -62,8 +62,6 @@ _NM_UTILS_MACRO_REST(__VA_ARGS__)); \ } G_STMT_END -#define ERR_GET_MSG(err) (((err) && (err)->message) ? (err)->message : "(unknown)") - static NMIfcfgConnection *update_connection (SettingsPluginIfcfg *plugin, NMConnection *source,