mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-29 11:30:12 +01:00
merge branch 'th/default-dns-options-bgo749648'
- some enhancements and bugfixes to ifcfg-rh utils - fix and refactoring nmcli value-to-string conversion - add new default value for dns-options https://bugzilla.gnome.org/show_bug.cgi?id=749648
This commit is contained in:
commit
ec972ad305
15 changed files with 607 additions and 463 deletions
|
|
@ -7357,7 +7357,7 @@ property_edit_submenu (NmCli *nmc,
|
|||
|
||||
case NMC_EDITOR_SUB_CMD_CHANGE:
|
||||
rl_startup_hook = nmc_rl_set_deftext;
|
||||
nmc_rl_pre_input_deftext = nmc_setting_get_property_out2in (curr_setting, prop_name, NULL);
|
||||
nmc_rl_pre_input_deftext = nmc_setting_get_property_parsable (curr_setting, prop_name, NULL);
|
||||
prop_val_user = nmc_readline (_("Edit '%s' value: "), prop_name);
|
||||
|
||||
nmc_property_get_gvalue (curr_setting, prop_name, &prop_g_value);
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -41,9 +41,9 @@ const char **nmc_setting_get_property_allowed_values (NMSetting *setting, const
|
|||
char *nmc_setting_get_property (NMSetting *setting,
|
||||
const char *prop,
|
||||
GError **error);
|
||||
char *nmc_setting_get_property_out2in (NMSetting *setting,
|
||||
const char *prop,
|
||||
GError **error);
|
||||
char *nmc_setting_get_property_parsable (NMSetting *setting,
|
||||
const char *prop,
|
||||
GError **error);
|
||||
gboolean nmc_setting_set_property (NMSetting *setting,
|
||||
const char *prop,
|
||||
const char *val,
|
||||
|
|
|
|||
|
|
@ -1424,9 +1424,33 @@ nm_setting_ip_config_clear_dns_searches (NMSettingIPConfig *setting)
|
|||
guint
|
||||
nm_setting_ip_config_get_num_dns_options (NMSettingIPConfig *setting)
|
||||
{
|
||||
NMSettingIPConfigPrivate *priv;
|
||||
|
||||
g_return_val_if_fail (NM_IS_SETTING_IP_CONFIG (setting), 0);
|
||||
|
||||
return NM_SETTING_IP_CONFIG_GET_PRIVATE (setting)->dns_options->len;
|
||||
priv = NM_SETTING_IP_CONFIG_GET_PRIVATE (setting);
|
||||
|
||||
return priv->dns_options ? priv->dns_options->len : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_setting_ip_config_has_dns_options:
|
||||
* @setting: the #NMSettingIPConfig
|
||||
*
|
||||
* NMSettingIPConfig can have a list of dns-options. If the list
|
||||
* is empty, there are two similar (but differentiated) states.
|
||||
* Either the options are explicitly set to have no values,
|
||||
* or the options are left undefined. The latter means to use
|
||||
* a default configuration, while the former explicitly means "no-options".
|
||||
*
|
||||
* Returns: whether DNS options are initalized or left unset (the default).
|
||||
**/
|
||||
gboolean
|
||||
nm_setting_ip_config_has_dns_options (NMSettingIPConfig *setting)
|
||||
{
|
||||
g_return_val_if_fail (NM_IS_SETTING_IP_CONFIG (setting), 0);
|
||||
|
||||
return !!NM_SETTING_IP_CONFIG_GET_PRIVATE (setting)->dns_options;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1446,6 +1470,7 @@ nm_setting_ip_config_get_dns_option (NMSettingIPConfig *setting, guint idx)
|
|||
g_return_val_if_fail (NM_IS_SETTING_IP_CONFIG (setting), NULL);
|
||||
|
||||
priv = NM_SETTING_IP_CONFIG_GET_PRIVATE (setting);
|
||||
g_return_val_if_fail (priv->dns_options, NULL);
|
||||
g_return_val_if_fail (idx < priv->dns_options->len, NULL);
|
||||
|
||||
return priv->dns_options->pdata[idx];
|
||||
|
|
@ -1470,6 +1495,9 @@ nm_setting_ip_config_next_valid_dns_option (NMSettingIPConfig *setting, guint id
|
|||
|
||||
priv = NM_SETTING_IP_CONFIG_GET_PRIVATE (setting);
|
||||
|
||||
if (!priv->dns_options)
|
||||
return -1;
|
||||
|
||||
for (; idx < priv->dns_options->len; idx++) {
|
||||
if (_nm_utils_dns_option_validate (priv->dns_options->pdata[idx], NULL, NULL,
|
||||
NM_IS_SETTING_IP6_CONFIG (setting),
|
||||
|
|
@ -1505,8 +1533,12 @@ nm_setting_ip_config_add_dns_option (NMSettingIPConfig *setting,
|
|||
return FALSE;
|
||||
|
||||
priv = NM_SETTING_IP_CONFIG_GET_PRIVATE (setting);
|
||||
if (_nm_utils_dns_option_find_idx (priv->dns_options, dns_option) >= 0)
|
||||
return FALSE;
|
||||
if (!priv->dns_options)
|
||||
priv->dns_options = g_ptr_array_new_with_free_func (g_free);
|
||||
else {
|
||||
if (_nm_utils_dns_option_find_idx (priv->dns_options, dns_option) >= 0)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
g_ptr_array_add (priv->dns_options, g_strdup (dns_option));
|
||||
g_object_notify (G_OBJECT (setting), NM_SETTING_IP_CONFIG_DNS_OPTIONS);
|
||||
|
|
@ -1530,6 +1562,7 @@ nm_setting_ip_config_remove_dns_option (NMSettingIPConfig *setting, int idx)
|
|||
g_return_if_fail (NM_IS_SETTING_IP_CONFIG (setting));
|
||||
|
||||
priv = NM_SETTING_IP_CONFIG_GET_PRIVATE (setting);
|
||||
g_return_if_fail (priv->dns_options);
|
||||
g_return_if_fail (idx < priv->dns_options->len);
|
||||
|
||||
g_ptr_array_remove_index (priv->dns_options, idx);
|
||||
|
|
@ -1559,6 +1592,9 @@ nm_setting_ip_config_remove_dns_option_by_value (NMSettingIPConfig *setting,
|
|||
g_return_val_if_fail (dns_option[0] != '\0', FALSE);
|
||||
|
||||
priv = NM_SETTING_IP_CONFIG_GET_PRIVATE (setting);
|
||||
if (!priv->dns_options)
|
||||
return FALSE;
|
||||
|
||||
i = _nm_utils_dns_option_find_idx (priv->dns_options, dns_option);
|
||||
if (i >= 0) {
|
||||
g_ptr_array_remove_index (priv->dns_options, i);
|
||||
|
|
@ -1572,20 +1608,35 @@ nm_setting_ip_config_remove_dns_option_by_value (NMSettingIPConfig *setting,
|
|||
/**
|
||||
* nm_setting_ip_config_clear_dns_options:
|
||||
* @setting: the #NMSettingIPConfig
|
||||
* @is_set: the dns-options can be either empty or unset (default).
|
||||
* Specify how to clear the options.
|
||||
*
|
||||
* Removes all configured DNS options.
|
||||
*
|
||||
* Since: 1.2
|
||||
**/
|
||||
void
|
||||
nm_setting_ip_config_clear_dns_options (NMSettingIPConfig *setting)
|
||||
nm_setting_ip_config_clear_dns_options (NMSettingIPConfig *setting, gboolean is_set)
|
||||
{
|
||||
NMSettingIPConfigPrivate *priv;
|
||||
|
||||
g_return_if_fail (NM_IS_SETTING_IP_CONFIG (setting));
|
||||
|
||||
priv = NM_SETTING_IP_CONFIG_GET_PRIVATE (setting);
|
||||
g_ptr_array_set_size (priv->dns_options, 0);
|
||||
if (!priv->dns_options) {
|
||||
if (!is_set)
|
||||
return;
|
||||
priv->dns_options = g_ptr_array_new_with_free_func (g_free);
|
||||
} else {
|
||||
if (!is_set) {
|
||||
g_ptr_array_unref (priv->dns_options);
|
||||
priv->dns_options = NULL;
|
||||
} else {
|
||||
if (priv->dns_options->len == 0)
|
||||
return;
|
||||
g_ptr_array_set_size (priv->dns_options, 0);
|
||||
}
|
||||
}
|
||||
g_object_notify (G_OBJECT (setting), NM_SETTING_IP_CONFIG_DNS_OPTIONS);
|
||||
}
|
||||
|
||||
|
|
@ -2155,7 +2206,7 @@ nm_setting_ip_config_init (NMSettingIPConfig *setting)
|
|||
|
||||
priv->dns = g_ptr_array_new_with_free_func (g_free);
|
||||
priv->dns_search = g_ptr_array_new_with_free_func (g_free);
|
||||
priv->dns_options = g_ptr_array_new_with_free_func (g_free);
|
||||
priv->dns_options = NULL;
|
||||
priv->addresses = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip_address_unref);
|
||||
priv->routes = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip_route_unref);
|
||||
}
|
||||
|
|
@ -2172,7 +2223,8 @@ finalize (GObject *object)
|
|||
|
||||
g_ptr_array_unref (priv->dns);
|
||||
g_ptr_array_unref (priv->dns_search);
|
||||
g_ptr_array_unref (priv->dns_options);
|
||||
if (priv->dns_options)
|
||||
g_ptr_array_unref (priv->dns_options);
|
||||
g_ptr_array_unref (priv->addresses);
|
||||
g_ptr_array_unref (priv->routes);
|
||||
|
||||
|
|
@ -2204,12 +2256,21 @@ set_property (GObject *object, guint prop_id,
|
|||
break;
|
||||
case PROP_DNS_OPTIONS:
|
||||
strv = g_value_get_boxed (value);
|
||||
g_ptr_array_unref (priv->dns_options);
|
||||
priv->dns_options = g_ptr_array_new_with_free_func (g_free);
|
||||
for (i = 0; strv && strv[i]; i++) {
|
||||
if ( _nm_utils_dns_option_validate (strv[i], NULL, NULL, FALSE, NULL)
|
||||
&& _nm_utils_dns_option_find_idx (priv->dns_options, strv[i]) < 0)
|
||||
g_ptr_array_add (priv->dns_options, g_strdup (strv[i]));
|
||||
if (!strv) {
|
||||
if (priv->dns_options) {
|
||||
g_ptr_array_unref (priv->dns_options);
|
||||
priv->dns_options = NULL;
|
||||
}
|
||||
} else {
|
||||
if (priv->dns_options)
|
||||
g_ptr_array_set_size (priv->dns_options, 0);
|
||||
else
|
||||
priv->dns_options = g_ptr_array_new_with_free_func (g_free);
|
||||
for (i = 0; strv[i]; i++) {
|
||||
if ( _nm_utils_dns_option_validate (strv[i], NULL, NULL, FALSE, NULL)
|
||||
&& _nm_utils_dns_option_find_idx (priv->dns_options, strv[i]) < 0)
|
||||
g_ptr_array_add (priv->dns_options, g_strdup (strv[i]));
|
||||
}
|
||||
}
|
||||
break;
|
||||
case PROP_ADDRESSES:
|
||||
|
|
@ -2276,7 +2337,7 @@ get_property (GObject *object, guint prop_id,
|
|||
g_value_take_boxed (value, _nm_utils_ptrarray_to_strv (priv->dns_search));
|
||||
break;
|
||||
case PROP_DNS_OPTIONS:
|
||||
g_value_take_boxed (value, _nm_utils_ptrarray_to_strv (priv->dns_options));
|
||||
g_value_take_boxed (value, priv->dns_options ? _nm_utils_ptrarray_to_strv (priv->dns_options) : NULL);
|
||||
break;
|
||||
case PROP_ADDRESSES:
|
||||
g_value_take_boxed (value, _nm_utils_copy_array (priv->addresses,
|
||||
|
|
@ -2402,6 +2463,10 @@ nm_setting_ip_config_class_init (NMSettingIPConfigClass *setting_class)
|
|||
*
|
||||
* Array of DNS options.
|
||||
*
|
||||
* %NULL means that the options are unset and left at the default.
|
||||
* In this case NetworkManager will use default options. This is
|
||||
* distinct from an empty list of properties.
|
||||
*
|
||||
* Since: 1.2
|
||||
**/
|
||||
g_object_class_install_property
|
||||
|
|
|
|||
|
|
@ -198,6 +198,7 @@ gboolean nm_setting_ip_config_remove_dns_search_by_value (NMSettingIPConfig
|
|||
void nm_setting_ip_config_clear_dns_searches (NMSettingIPConfig *setting);
|
||||
|
||||
guint nm_setting_ip_config_get_num_dns_options (NMSettingIPConfig *setting);
|
||||
gboolean nm_setting_ip_config_has_dns_options (NMSettingIPConfig *setting);
|
||||
const char *nm_setting_ip_config_get_dns_option (NMSettingIPConfig *setting,
|
||||
guint idx);
|
||||
gint nm_setting_ip_config_next_valid_dns_option (NMSettingIPConfig *setting,
|
||||
|
|
@ -208,7 +209,7 @@ void nm_setting_ip_config_remove_dns_option (NMSettingIPConfig
|
|||
int idx);
|
||||
gboolean nm_setting_ip_config_remove_dns_option_by_value (NMSettingIPConfig *setting,
|
||||
const char *dns_option);
|
||||
void nm_setting_ip_config_clear_dns_options (NMSettingIPConfig *setting);
|
||||
void nm_setting_ip_config_clear_dns_options (NMSettingIPConfig *setting, gboolean is_set);
|
||||
|
||||
guint nm_setting_ip_config_get_num_addresses (NMSettingIPConfig *setting);
|
||||
NMIPAddress *nm_setting_ip_config_get_address (NMSettingIPConfig *setting,
|
||||
|
|
|
|||
|
|
@ -1053,13 +1053,15 @@ compare_property (NMSetting *setting,
|
|||
property = nm_setting_class_find_property (NM_SETTING_GET_CLASS (setting), prop_spec->name);
|
||||
g_return_val_if_fail (property != NULL, FALSE);
|
||||
|
||||
value1 = get_property_for_dbus (setting, property, FALSE);
|
||||
value2 = get_property_for_dbus (other, property, FALSE);
|
||||
value1 = get_property_for_dbus (setting, property, TRUE);
|
||||
value2 = get_property_for_dbus (other, property, TRUE);
|
||||
|
||||
cmp = nm_property_compare (value1, value2);
|
||||
|
||||
g_variant_unref (value1);
|
||||
g_variant_unref (value2);
|
||||
if (value1)
|
||||
g_variant_unref (value1);
|
||||
if (value2)
|
||||
g_variant_unref (value2);
|
||||
|
||||
return cmp == 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3964,6 +3964,51 @@ typedef struct {
|
|||
const guint expected_len;
|
||||
} HexItem;
|
||||
|
||||
static void
|
||||
test_setting_compare_default_strv (void)
|
||||
{
|
||||
gs_unref_object NMConnection *c1 = NULL, *c2 = NULL;
|
||||
char **strv;
|
||||
NMSettingIPConfig *s_ip2, *s_ip1;
|
||||
gboolean compare;
|
||||
GHashTable *out_settings = NULL;
|
||||
|
||||
c1 = nmtst_create_minimal_connection ("test_compare_default_strv", NULL,
|
||||
NM_SETTING_WIRED_SETTING_NAME, NULL);
|
||||
nmtst_assert_connection_verifies_and_normalizable (c1);
|
||||
|
||||
c2 = nm_simple_connection_new_clone (c1);
|
||||
nmtst_assert_connection_verifies_without_normalization (c2);
|
||||
|
||||
nmtst_assert_connection_equals (c1, FALSE, c2, FALSE);
|
||||
|
||||
s_ip1 = nm_connection_get_setting_ip4_config (c1);
|
||||
s_ip2 = nm_connection_get_setting_ip4_config (c2);
|
||||
|
||||
nm_setting_ip_config_clear_dns_options (s_ip2, FALSE);
|
||||
g_object_get (G_OBJECT (s_ip2), NM_SETTING_IP_CONFIG_DNS_OPTIONS, &strv, NULL);
|
||||
g_assert (!strv);
|
||||
nmtst_assert_connection_equals (c1, FALSE, c2, FALSE);
|
||||
|
||||
nm_setting_ip_config_clear_dns_options (s_ip2, TRUE);
|
||||
g_object_get (G_OBJECT (s_ip2), NM_SETTING_IP_CONFIG_DNS_OPTIONS, &strv, NULL);
|
||||
g_assert (strv && !strv[0]);
|
||||
g_strfreev (strv);
|
||||
|
||||
compare = nm_setting_diff ((NMSetting *) s_ip1, (NMSetting *) s_ip2, NM_SETTING_COMPARE_FLAG_EXACT, FALSE, &out_settings);
|
||||
g_assert (!compare);
|
||||
g_assert (out_settings);
|
||||
g_assert (g_hash_table_contains (out_settings, NM_SETTING_IP_CONFIG_DNS_OPTIONS));
|
||||
g_hash_table_unref (out_settings);
|
||||
out_settings = NULL;
|
||||
|
||||
compare = nm_connection_diff (c1, c2, NM_SETTING_COMPARE_FLAG_EXACT, &out_settings);
|
||||
g_assert (!compare);
|
||||
g_assert (out_settings);
|
||||
g_hash_table_unref (out_settings);
|
||||
out_settings = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
test_hexstr2bin (void)
|
||||
{
|
||||
|
|
@ -4406,6 +4451,7 @@ int main (int argc, char **argv)
|
|||
g_test_add_func ("/core/general/test_setting_802_1x_changed_signal", test_setting_802_1x_changed_signal);
|
||||
g_test_add_func ("/core/general/test_setting_ip4_gateway", test_setting_ip4_gateway);
|
||||
g_test_add_func ("/core/general/test_setting_ip6_gateway", test_setting_ip6_gateway);
|
||||
g_test_add_func ("/core/general/test_setting_compare_default_strv", test_setting_compare_default_strv);
|
||||
|
||||
g_test_add_func ("/core/general/hexstr2bin", test_hexstr2bin);
|
||||
g_test_add_func ("/core/general/test_nm_utils_uuid_generate_from_string", test_nm_utils_uuid_generate_from_string);
|
||||
|
|
|
|||
|
|
@ -855,6 +855,7 @@ global:
|
|||
nm_setting_ip_config_clear_dns_options;
|
||||
nm_setting_ip_config_get_dns_option;
|
||||
nm_setting_ip_config_get_num_dns_options;
|
||||
nm_setting_ip_config_has_dns_options;
|
||||
nm_setting_ip_config_remove_dns_option;
|
||||
nm_setting_ip_config_remove_dns_option_by_value;
|
||||
nm_setting_wireless_get_powersave;
|
||||
|
|
|
|||
|
|
@ -677,6 +677,9 @@ parse_dns_options (NMSettingIPConfig *ip_config, char *value)
|
|||
if (!value)
|
||||
return;
|
||||
|
||||
if (!nm_setting_ip_config_has_dns_options (ip_config))
|
||||
nm_setting_ip_config_clear_dns_options (ip_config, TRUE);
|
||||
|
||||
options = g_strsplit (value, " ", 0);
|
||||
if (options) {
|
||||
char **item;
|
||||
|
|
@ -927,7 +930,7 @@ make_ip4_setting (shvarFile *ifcfg,
|
|||
/* Get the connection ifcfg device name and the global gateway device */
|
||||
value = svGetValue (ifcfg, "DEVICE", FALSE);
|
||||
gatewaydev = svGetValue (network_ifcfg, "GATEWAYDEV", FALSE);
|
||||
dns_options = svGetValue (network_ifcfg, "RES_OPTIONS", FALSE);
|
||||
dns_options = svGetValueFull (network_ifcfg, "RES_OPTIONS", FALSE);
|
||||
|
||||
/* If there was a global gateway device specified, then only connections
|
||||
* for that device can be the default connection.
|
||||
|
|
@ -1105,7 +1108,7 @@ make_ip4_setting (shvarFile *ifcfg,
|
|||
}
|
||||
|
||||
/* DNS options */
|
||||
value = svGetValue (ifcfg, "RES_OPTIONS", FALSE);
|
||||
value = svGetValueFull (ifcfg, "RES_OPTIONS", FALSE);
|
||||
parse_dns_options (s_ip4, value);
|
||||
parse_dns_options (s_ip4, dns_options);
|
||||
g_free (value);
|
||||
|
|
@ -1317,7 +1320,7 @@ make_ip6_setting (shvarFile *ifcfg,
|
|||
value = svGetValue (ifcfg, "DEVICE", FALSE);
|
||||
ipv6_defaultgw = svGetValue (network_ifcfg, "IPV6_DEFAULTGW", FALSE);
|
||||
ipv6_defaultdev = svGetValue (network_ifcfg, "IPV6_DEFAULTDEV", FALSE);
|
||||
dns_options = svGetValue (network_ifcfg, "RES_OPTIONS", FALSE);
|
||||
dns_options = svGetValueFull (network_ifcfg, "RES_OPTIONS", FALSE);
|
||||
|
||||
if (ipv6_defaultgw) {
|
||||
default_dev = strchr (ipv6_defaultgw, '%');
|
||||
|
|
@ -1515,7 +1518,7 @@ make_ip6_setting (shvarFile *ifcfg,
|
|||
}
|
||||
|
||||
/* DNS options */
|
||||
value = svGetValue (ifcfg, "RES_OPTIONS", FALSE);
|
||||
value = svGetValueFull (ifcfg, "RES_OPTIONS", FALSE);
|
||||
parse_dns_options (s_ip6, value);
|
||||
parse_dns_options (s_ip6, dns_options);
|
||||
g_free (value);
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@
|
|||
|
||||
#include "shvar.h"
|
||||
|
||||
#include "gsystem-local-alloc.h"
|
||||
#include "nm-core-internal.h"
|
||||
#include "nm-logging.h"
|
||||
|
||||
|
|
@ -206,8 +207,8 @@ static const char escapees[] = "\"'\\$~`"; /* must be escaped */
|
|||
static const char spaces[] = " \t|&;()<>"; /* only require "" */
|
||||
static const char newlines[] = "\n\r"; /* will be removed */
|
||||
|
||||
char *
|
||||
svEscape (const char *s)
|
||||
const char *
|
||||
svEscape (const char *s, char **to_free)
|
||||
{
|
||||
char *new;
|
||||
int i, j, mangle = 0, space = 0, newline = 0;
|
||||
|
|
@ -223,8 +224,10 @@ svEscape (const char *s)
|
|||
if (strchr (newlines, s[i]))
|
||||
newline++;
|
||||
}
|
||||
if (!mangle && !space && !newline)
|
||||
return strdup (s);
|
||||
if (!mangle && !space && !newline) {
|
||||
*to_free = NULL;
|
||||
return s;
|
||||
}
|
||||
|
||||
newlen = slen + mangle - newline + 3; /* 3 is extra ""\0 */
|
||||
new = g_malloc (newlen);
|
||||
|
|
@ -243,6 +246,7 @@ svEscape (const char *s)
|
|||
new[j++] = '\0';
|
||||
g_assert (j == slen + mangle - newline + 3);
|
||||
|
||||
*to_free = new;
|
||||
return new;
|
||||
}
|
||||
|
||||
|
|
@ -252,6 +256,22 @@ svEscape (const char *s)
|
|||
*/
|
||||
char *
|
||||
svGetValue (shvarFile *s, const char *key, gboolean verbatim)
|
||||
{
|
||||
char *value;
|
||||
|
||||
value = svGetValueFull (s, key, verbatim);
|
||||
if (value && !*value) {
|
||||
g_free (value);
|
||||
return NULL;
|
||||
}
|
||||
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;
|
||||
|
|
@ -276,12 +296,7 @@ svGetValue (shvarFile *s, const char *key, gboolean verbatim)
|
|||
}
|
||||
g_free (keyString);
|
||||
|
||||
if (value && value[0]) {
|
||||
return value;
|
||||
} else {
|
||||
g_free (value);
|
||||
return NULL;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
/* return TRUE if <key> resolves to any truth value (e.g. "yes", "y", "true")
|
||||
|
|
@ -330,7 +345,7 @@ svGetValueInt64 (shvarFile *s, const char *key, guint base, gint64 min, gint64 m
|
|||
gint64 result;
|
||||
int errsv;
|
||||
|
||||
tmp = svGetValue (s, key, FALSE);
|
||||
tmp = svGetValueFull (s, key, FALSE);
|
||||
if (!tmp) {
|
||||
errno = 0;
|
||||
return fallback;
|
||||
|
|
@ -354,20 +369,30 @@ svGetValueInt64 (shvarFile *s, const char *key, guint base, gint64 min, gint64 m
|
|||
void
|
||||
svSetValue (shvarFile *s, const char *key, const char *value, gboolean verbatim)
|
||||
{
|
||||
char *newval = NULL, *oldval = NULL;
|
||||
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. */
|
||||
void
|
||||
svSetValueFull (shvarFile *s, const char *key, const char *value, gboolean verbatim)
|
||||
{
|
||||
gs_free char *newval_free = NULL;
|
||||
gs_free char *oldval = NULL;
|
||||
const char *newval;
|
||||
char *keyValue;
|
||||
|
||||
g_return_if_fail (s != NULL);
|
||||
g_return_if_fail (key != NULL);
|
||||
/* value may be NULL */
|
||||
|
||||
if (value)
|
||||
newval = verbatim ? g_strdup (value) : svEscape (value);
|
||||
keyValue = g_strdup_printf ("%s=%s", key, newval ? newval : "");
|
||||
if (!value || verbatim)
|
||||
newval = value;
|
||||
else
|
||||
newval = svEscape (value, &newval_free);
|
||||
oldval = svGetValueFull (s, key, FALSE);
|
||||
|
||||
oldval = svGetValue (s, key, FALSE);
|
||||
|
||||
if (!newval || !newval[0]) {
|
||||
if (!newval) {
|
||||
/* delete value */
|
||||
if (oldval) {
|
||||
/* delete line */
|
||||
|
|
@ -376,15 +401,15 @@ svSetValue (shvarFile *s, const char *key, const char *value, gboolean verbatim)
|
|||
g_list_free_1 (s->current);
|
||||
s->modified = TRUE;
|
||||
}
|
||||
g_free (keyValue);
|
||||
goto end;
|
||||
return;
|
||||
}
|
||||
|
||||
keyValue = g_strdup_printf ("%s=%s", key, newval);
|
||||
if (!oldval) {
|
||||
/* append line */
|
||||
s->lineList = g_list_append (s->lineList, keyValue);
|
||||
s->modified = TRUE;
|
||||
goto end;
|
||||
return;
|
||||
}
|
||||
|
||||
if (strcmp (oldval, newval) != 0) {
|
||||
|
|
@ -397,11 +422,6 @@ svSetValue (shvarFile *s, const char *key, const char *value, gboolean verbatim)
|
|||
s->modified = TRUE;
|
||||
} else
|
||||
g_free (keyValue);
|
||||
|
||||
end:
|
||||
g_free (newval);
|
||||
g_free (oldval);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Write the current contents iff modified. Returns FALSE on error
|
||||
|
|
|
|||
|
|
@ -56,6 +56,7 @@ shvarFile *svOpenFile (const char *name, GError **error);
|
|||
* be freed by the caller.
|
||||
*/
|
||||
char *svGetValue (shvarFile *s, const char *key, gboolean verbatim);
|
||||
char *svGetValueFull (shvarFile *s, const char *key, gboolean verbatim);
|
||||
|
||||
/* return TRUE if <key> resolves to any truth value (e.g. "yes", "y", "true")
|
||||
* return FALSE if <key> resolves to any non-truth value (e.g. "no", "n", "false")
|
||||
|
|
@ -71,6 +72,7 @@ gint64 svGetValueInt64 (shvarFile *s, const char *key, guint base, gint64 min, g
|
|||
* to the top of the file.
|
||||
*/
|
||||
void svSetValue (shvarFile *s, const char *key, const char *value, gboolean verbatim);
|
||||
void svSetValueFull (shvarFile *s, const char *key, const char *value, gboolean verbatim);
|
||||
|
||||
|
||||
/* Write the current contents iff modified. Returns FALSE on error
|
||||
|
|
@ -84,8 +86,8 @@ gboolean svWriteFile (shvarFile *s, int mode, GError **error);
|
|||
/* Close the file descriptor (if open) and free the shvarFile. */
|
||||
void svCloseFile (shvarFile *s);
|
||||
|
||||
/* Return a new escaped string */
|
||||
char *svEscape (const char *s);
|
||||
/* Return @s unmodified or an escaped string */
|
||||
const char *svEscape (const char *s, char **to_free);
|
||||
|
||||
/* Unescape a string in-place */
|
||||
void svUnescape (char *s);
|
||||
|
|
|
|||
|
|
@ -18,3 +18,4 @@ IPV6ADDR=dead:beaf::1
|
|||
IPV6ADDR_SECONDARIES="dead:beaf::2/56"
|
||||
DNS3=1:2:3:4::a
|
||||
DNS4=1:2:3:4::b
|
||||
RES_OPTIONS=
|
||||
|
|
|
|||
|
|
@ -13,3 +13,4 @@ DNS2=4.2.2.2
|
|||
IPADDR=192.168.1.5
|
||||
NETMASK=255.255.255.0
|
||||
GATEWAY=192.168.1.1
|
||||
RES_OPTIONS=
|
||||
|
|
|
|||
|
|
@ -484,6 +484,9 @@ test_read_wired_static (const char *file,
|
|||
g_assert_cmpstr (nm_setting_ip_config_get_method (s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_MANUAL);
|
||||
g_assert (nm_setting_ip_config_get_may_fail (s_ip4));
|
||||
|
||||
g_assert (nm_setting_ip_config_has_dns_options (s_ip4));
|
||||
g_assert_cmpint (nm_setting_ip_config_get_num_dns_options (s_ip4), ==, 0);
|
||||
|
||||
/* DNS Addresses */
|
||||
g_assert_cmpint (nm_setting_ip_config_get_num_dns (s_ip4), ==, 2);
|
||||
g_assert_cmpstr (nm_setting_ip_config_get_dns (s_ip4, 0), ==, "4.2.2.1");
|
||||
|
|
@ -506,6 +509,9 @@ test_read_wired_static (const char *file,
|
|||
g_assert_cmpstr (nm_setting_ip_config_get_method (s_ip6), ==, NM_SETTING_IP6_CONFIG_METHOD_MANUAL);
|
||||
g_assert (nm_setting_ip_config_get_may_fail (s_ip6));
|
||||
|
||||
g_assert (nm_setting_ip_config_has_dns_options (s_ip6));
|
||||
g_assert_cmpint (nm_setting_ip_config_get_num_dns_options (s_ip6), ==, 0);
|
||||
|
||||
/* DNS Addresses */
|
||||
g_assert_cmpint (nm_setting_ip_config_get_num_dns (s_ip6), ==, 2);
|
||||
g_assert_cmpstr (nm_setting_ip_config_get_dns (s_ip6, 0), ==, "1:2:3:4::a");
|
||||
|
|
@ -525,6 +531,7 @@ test_read_wired_static (const char *file,
|
|||
g_assert_cmpstr (nm_ip_address_get_address (ip6_addr), ==, "dead:beaf::2");
|
||||
} else {
|
||||
g_assert_cmpstr (nm_setting_ip_config_get_method (s_ip6), ==, NM_SETTING_IP6_CONFIG_METHOD_IGNORE);
|
||||
g_assert (!nm_setting_ip_config_has_dns_options (s_ip6));
|
||||
}
|
||||
|
||||
g_object_unref (connection);
|
||||
|
|
@ -563,6 +570,9 @@ test_read_wired_static_no_prefix (gconstpointer user_data)
|
|||
g_assert (s_ip4);
|
||||
g_assert_cmpstr (nm_setting_ip_config_get_method (s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_MANUAL);
|
||||
|
||||
g_assert (!nm_setting_ip_config_has_dns_options (s_ip4));
|
||||
g_assert_cmpint (nm_setting_ip_config_get_num_dns_options (s_ip4), ==, 0);
|
||||
|
||||
g_assert_cmpint (nm_setting_ip_config_get_num_addresses (s_ip4), ==, 1);
|
||||
ip4_addr = nm_setting_ip_config_get_address (s_ip4, 0);
|
||||
g_assert (ip4_addr);
|
||||
|
|
@ -2635,11 +2645,11 @@ test_write_dns_options (void)
|
|||
unlink (testfile);
|
||||
|
||||
/* RES_OPTIONS is copied to both IPv4 and IPv6 settings */
|
||||
nm_setting_ip_config_clear_dns_options (s_ip4);
|
||||
nm_setting_ip_config_clear_dns_options (s_ip4, TRUE);
|
||||
nm_setting_ip_config_add_dns_option (s_ip4, "debug");
|
||||
nm_setting_ip_config_add_dns_option (s_ip4, "timeout:3");
|
||||
|
||||
nm_setting_ip_config_clear_dns_options (s_ip6);
|
||||
nm_setting_ip_config_clear_dns_options (s_ip6, TRUE);
|
||||
nm_setting_ip_config_add_dns_option (s_ip6, "debug");
|
||||
nm_setting_ip_config_add_dns_option (s_ip6, "timeout:3");
|
||||
|
||||
|
|
|
|||
|
|
@ -889,20 +889,22 @@ write_wireless_setting (NMConnection *connection,
|
|||
svSetValue (ifcfg, "ESSID", str->str, TRUE);
|
||||
g_string_free (str, TRUE);
|
||||
} else {
|
||||
const char *tmp_escaped;
|
||||
|
||||
/* Printable SSIDs always get quoted */
|
||||
memset (buf, 0, sizeof (buf));
|
||||
memcpy (buf, ssid_data, ssid_len);
|
||||
tmp = svEscape (buf);
|
||||
tmp_escaped = svEscape (buf, &tmp);
|
||||
|
||||
/* svEscape will usually quote the string, but just for consistency,
|
||||
* if svEscape doesn't quote the ESSID, we quote it ourselves.
|
||||
*/
|
||||
if (tmp[0] != '"' && tmp[strlen (tmp) - 1] != '"') {
|
||||
tmp2 = g_strdup_printf ("\"%s\"", tmp);
|
||||
if (tmp_escaped[0] != '"' && tmp_escaped[strlen (tmp_escaped) - 1] != '"') {
|
||||
tmp2 = g_strdup_printf ("\"%s\"", tmp_escaped);
|
||||
svSetValue (ifcfg, "ESSID", tmp2, TRUE);
|
||||
g_free (tmp2);
|
||||
} else
|
||||
svSetValue (ifcfg, "ESSID", tmp, TRUE);
|
||||
svSetValue (ifcfg, "ESSID", tmp_escaped, TRUE);
|
||||
g_free (tmp);
|
||||
}
|
||||
|
||||
|
|
@ -2504,14 +2506,16 @@ write_res_options (NMConnection *connection, shvarFile *ifcfg, GError **error)
|
|||
}
|
||||
}
|
||||
|
||||
if (array->len > 0) {
|
||||
if (array->len > 0
|
||||
|| (s_ip4 && nm_setting_ip_config_has_dns_options (s_ip4))
|
||||
|| (s_ip6 && nm_setting_ip_config_has_dns_options (s_ip6))) {
|
||||
value = g_string_new (NULL);
|
||||
for (i = 0; i < array->len; i++) {
|
||||
if (i > 0)
|
||||
g_string_append_c (value, ' ');
|
||||
g_string_append (value, array->pdata[i]);
|
||||
}
|
||||
svSetValue (ifcfg, "RES_OPTIONS", value->str, FALSE);
|
||||
svSetValueFull (ifcfg, "RES_OPTIONS", value->str, FALSE);
|
||||
g_string_free (value, TRUE);
|
||||
} else
|
||||
svSetValue (ifcfg, "RES_OPTIONS", NULL, FALSE);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue