config: drop global-dns.enable option in favor of .config.enable

No longer support disabling the global-dns configuration via the
"enable" option.

Instead, the user can put the entire dns-configuration in one separate
snippet, and disable it altogether with ".config.enable".
This commit is contained in:
Thomas Haller
2015-10-01 14:00:01 +02:00
parent 7182304684
commit da0ded4927
8 changed files with 32 additions and 30 deletions

View File

@@ -642,14 +642,6 @@ ipv6.ip6-privacy=1
connection-specific configuration.</para>
<para>
<variablelist>
<varlistentry>
<term><varname>enable</varname></term>
<listitem>
<para>
Whether the global DNS configuration should be used.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>searches</varname></term>
<listitem>

View File

@@ -731,7 +731,7 @@ load_global_dns (GKeyFile *keyfile, gboolean internal)
: NM_CONFIG_KEYFILE_GROUPPREFIX_GLOBAL_DNS_DOMAIN;
domain_prefix_len = strlen (domain_prefix);
if (!keyfile || !nm_config_keyfile_get_boolean (keyfile, group, NM_CONFIG_KEYFILE_KEY_GLOBAL_DNS_ENABLE, FALSE))
if (!nm_config_keyfile_has_global_dns_config (keyfile, internal))
return NULL;
conf = g_malloc0 (sizeof (NMGlobalDnsConfig));

View File

@@ -1066,6 +1066,34 @@ _keyfile_serialize_section (GKeyFile *keyfile, const char *group)
return g_string_free (str, FALSE);
}
gboolean
nm_config_keyfile_has_global_dns_config (GKeyFile *keyfile, gboolean internal)
{
gs_strfreev char **groups = NULL;
guint g;
const char *prefix;
if (!keyfile)
return FALSE;
if (g_key_file_has_group (keyfile,
internal
? NM_CONFIG_KEYFILE_GROUP_GLOBAL_DNS
: NM_CONFIG_KEYFILE_GROUP_INTERN_GLOBAL_DNS))
return TRUE;
groups = g_key_file_get_groups (keyfile, NULL);
if (!groups)
return FALSE;
prefix = internal ? NM_CONFIG_KEYFILE_GROUPPREFIX_INTERN_GLOBAL_DNS_DOMAIN : NM_CONFIG_KEYFILE_GROUPPREFIX_GLOBAL_DNS_DOMAIN;
for (g = 0; groups[g]; g++) {
if (g_str_has_prefix (groups[g], prefix))
return TRUE;
}
return FALSE;
}
/**
* intern_config_read:
* @filename: the filename where to store the internal config
@@ -1219,7 +1247,7 @@ out:
* deletion of options from user configuration may cause the
* internal options to appear again.
*/
if (nm_config_keyfile_get_boolean (keyfile_conf, NM_CONFIG_KEYFILE_GROUP_GLOBAL_DNS, NM_CONFIG_KEYFILE_KEY_GLOBAL_DNS_ENABLE, FALSE)) {
if (nm_config_keyfile_has_global_dns_config (keyfile_conf, FALSE)) {
if (g_key_file_remove_group (keyfile_intern, NM_CONFIG_KEYFILE_GROUP_INTERN_GLOBAL_DNS, NULL))
needs_rewrite = TRUE;
for (g = 0; groups && groups[g]; g++) {
@@ -1497,8 +1525,6 @@ nm_config_set_global_dns (NMConfig *self, NMGlobalDnsConfig *global_dns, GError
goto done;
/* Set new values */
g_key_file_set_string (keyfile, NM_CONFIG_KEYFILE_GROUP_INTERN_GLOBAL_DNS, NM_CONFIG_KEYFILE_KEY_GLOBAL_DNS_ENABLE, "yes");
nm_config_keyfile_set_string_list (keyfile, NM_CONFIG_KEYFILE_GROUP_INTERN_GLOBAL_DNS,
"searches", nm_global_dns_config_get_searches (global_dns),
-1);

View File

@@ -63,7 +63,6 @@ G_BEGIN_DECLS
#define NM_CONFIG_KEYFILE_GROUP_IFNET "ifnet"
#define NM_CONFIG_KEYFILE_KEY_LOGGING_BACKEND "backend"
#define NM_CONFIG_KEYFILE_KEY_GLOBAL_DNS_ENABLE "enable"
#define NM_CONFIG_KEYFILE_KEY_CONFIG_ENABLE "enable"
#define NM_CONFIG_KEYFILE_KEY_ATOMIC_SECTION_WAS ".was"
#define NM_CONFIG_KEYFILE_KEY_IFNET_AUTO_REFRESH "auto_refresh"
@@ -145,6 +144,8 @@ void nm_config_keyfile_set_string_list (GKeyFile *keyfile,
const char *key,
const char *const* strv,
gssize len);
gboolean nm_config_keyfile_has_global_dns_config (GKeyFile *keyfile, gboolean internal);
GSList *nm_config_get_match_spec (const GKeyFile *keyfile, const char *group, const char *key, gboolean *out_has_key);
void _nm_config_sort_groups (char **groups, gsize ngroups);

View File

@@ -30,7 +30,6 @@ TESTS = test-config
EXTRA_DIST = \
NetworkManager.conf \
bad.conf \
global-dns-disabled.conf \
global-dns-invalid.conf \
conf.d/00-overrides.conf \
conf.d/10-more.conf \

View File

@@ -1,8 +0,0 @@
[global-dns]
enable=no
searches=foo.com
options=timeout:5
[global-dns-domain-*]
servers=1.2.3.4
options=myoption

View File

@@ -1,7 +1,6 @@
# Invalid configuration, since there isn't a default domain section
[global-dns]
enable=yes
searches=foo.com
options=timeout:5

View File

@@ -305,13 +305,6 @@ test_config_global_dns (void)
g_object_unref (config);
/* Check that a file without "enable=yes" gives a NULL configuration */
config = setup_config (NULL, SRCDIR "/global-dns-disabled.conf", "", NULL,
"/no/such/dir", "", NULL);
dns = nm_config_data_get_global_dns_config (nm_config_get_data_orig (config));
g_assert (!dns);
g_object_unref (config);
/* Check that a file without a default domain section gives a NULL configuration */
config = setup_config (NULL, SRCDIR "/global-dns-invalid.conf", "", NULL,
"/no/such/dir", "", NULL);