summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2015-10-09 18:16:42 +0200
committerThomas Haller <thaller@redhat.com>2015-10-09 18:32:44 +0200
commitda60e2bee9582ae5df5f4b27629e31d456fe50c7 (patch)
treecc96ff1adeb440eabc7e3b6823dfced3e6b3706d
parentf4ec8db1aee55f0ab5228998e75cc662e70775cf (diff)
downloadNetworkManager-th/keyfile-path-bgo755995.tar.gz
keyfile: make the keyfile location configurableth/keyfile-path-bgo755995
https://bugzilla.gnome.org/show_bug.cgi?id=755995
-rw-r--r--configure.ac3
-rw-r--r--man/NetworkManager.conf.xml.in8
-rw-r--r--src/nm-config.h1
-rw-r--r--src/settings/plugins/keyfile/plugin.c12
-rw-r--r--src/settings/plugins/keyfile/utils.c21
-rw-r--r--src/settings/plugins/keyfile/utils.h4
-rw-r--r--src/settings/plugins/keyfile/writer.c2
7 files changed, 42 insertions, 9 deletions
diff --git a/configure.ac b/configure.ac
index 386c1e84b1..e7d3ed9279 100644
--- a/configure.ac
+++ b/configure.ac
@@ -138,6 +138,9 @@ if test "$enable_ifcfg_rh" = "yes"; then
fi
AC_SUBST(DISTRO_NETWORK_SERVICE)
+AC_SUBST(NM_CONFIG_KEYFILE_PATH_DEFAULT, "${sysconfdir}/$PACKAGE/system-connections", [The keyfile directory])
+AC_DEFINE_UNQUOTED(NM_CONFIG_KEYFILE_PATH_DEFAULT, "$NM_CONFIG_KEYFILE_PATH_DEFAULT", [The keyfile directory])
+
# Code coverage
GNOME_CODE_COVERAGE
diff --git a/man/NetworkManager.conf.xml.in b/man/NetworkManager.conf.xml.in
index f7bcd1a359..fe9a2ba2d1 100644
--- a/man/NetworkManager.conf.xml.in
+++ b/man/NetworkManager.conf.xml.in
@@ -336,6 +336,14 @@ no-auto-default=*
system configuration files according to build options.
</para></listitem>
</varlistentry>
+ <varlistentry>
+ <term><varname>path</varname></term>
+ <listitem>
+ <para>The location where keyfiles are read and stored.
+ This defaults to "<literal>@NM_CONFIG_KEYFILE_PATH_DEFAULT@</literal>".
+ </para>
+ </listitem>
+ </varlistentry>
<varlistentry>
<term><varname>unmanaged-devices</varname></term>
<listitem><para>Set devices that should be ignored by
diff --git a/src/nm-config.h b/src/nm-config.h
index eb195138bd..7ea65d397e 100644
--- a/src/nm-config.h
+++ b/src/nm-config.h
@@ -65,6 +65,7 @@ G_BEGIN_DECLS
#define NM_CONFIG_KEYFILE_KEY_LOGGING_BACKEND "backend"
#define NM_CONFIG_KEYFILE_KEY_CONFIG_ENABLE "enable"
#define NM_CONFIG_KEYFILE_KEY_ATOMIC_SECTION_WAS ".was"
+#define NM_CONFIG_KEYFILE_KEY_KEYFILE_PATH "path"
#define NM_CONFIG_KEYFILE_KEY_IFNET_AUTO_REFRESH "auto_refresh"
#define NM_CONFIG_KEYFILE_KEY_IFNET_MANAGED "managed"
#define NM_CONFIG_KEYFILE_KEY_IFUPDOWN_MANAGED "managed"
diff --git a/src/settings/plugins/keyfile/plugin.c b/src/settings/plugins/keyfile/plugin.c
index 39a3d6480e..1ecce71a35 100644
--- a/src/settings/plugins/keyfile/plugin.c
+++ b/src/settings/plugins/keyfile/plugin.c
@@ -334,7 +334,7 @@ setup_monitoring (NMSettingsPlugin *config)
GFileMonitor *monitor;
if (nm_config_get_monitor_connection_files (nm_config_get ())) {
- file = g_file_new_for_path (KEYFILE_DIR);
+ file = g_file_new_for_path (nm_keyfile_plugin_get_path ());
monitor = g_file_monitor_directory (file, G_FILE_MONITOR_NONE, NULL, NULL);
g_object_unref (file);
@@ -403,10 +403,10 @@ read_connections (NMSettingsPlugin *config)
GPtrArray *filenames;
GHashTable *paths;
- dir = g_dir_open (KEYFILE_DIR, 0, &error);
+ dir = g_dir_open (nm_keyfile_plugin_get_path (), 0, &error);
if (!dir) {
nm_log_warn (LOGD_SETTINGS, "keyfile: cannot read directory '%s': (%d) %s",
- KEYFILE_DIR,
+ nm_keyfile_plugin_get_path (),
error ? error->code : -1,
error && error->message ? error->message : "(unknown)");
g_clear_error (&error);
@@ -419,7 +419,7 @@ read_connections (NMSettingsPlugin *config)
while ((item = g_dir_read_name (dir))) {
if (nm_keyfile_plugin_utils_should_ignore_file (item))
continue;
- g_ptr_array_add (filenames, g_build_filename (KEYFILE_DIR, item, NULL));
+ g_ptr_array_add (filenames, g_build_filename (nm_keyfile_plugin_get_path (), item, NULL));
}
g_dir_close (dir);
@@ -479,9 +479,9 @@ load_connection (NMSettingsPlugin *config,
{
SettingsPluginKeyfile *self = SETTINGS_PLUGIN_KEYFILE (config);
NMKeyfileConnection *connection;
- int dir_len = strlen (KEYFILE_DIR);
+ int dir_len = strlen (nm_keyfile_plugin_get_path ());
- if ( strncmp (filename, KEYFILE_DIR, dir_len) != 0
+ if ( strncmp (filename, nm_keyfile_plugin_get_path (), dir_len) != 0
|| filename[dir_len] != '/'
|| strchr (filename + dir_len + 1, '/') != NULL)
return FALSE;
diff --git a/src/settings/plugins/keyfile/utils.c b/src/settings/plugins/keyfile/utils.c
index 4300b0dcb4..de538bca47 100644
--- a/src/settings/plugins/keyfile/utils.c
+++ b/src/settings/plugins/keyfile/utils.c
@@ -27,6 +27,7 @@
#include <nm-setting-wired.h>
#include <nm-setting-wireless.h>
#include <nm-setting-wireless-security.h>
+#include "nm-config.h"
static const char temp_letters[] =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
@@ -144,3 +145,23 @@ nm_keyfile_plugin_utils_escape_filename (const char *filename)
return g_string_free (str, FALSE);;
}
+/*****************************************************************************/
+
+const char *
+nm_keyfile_plugin_get_path (void)
+{
+ static char *path = NULL;
+
+ if (G_UNLIKELY (!path)) {
+ path = nm_config_data_get_value (NM_CONFIG_GET_DATA_ORIG,
+ NM_CONFIG_KEYFILE_GROUP_KEYFILE,
+ NM_CONFIG_KEYFILE_KEY_KEYFILE_PATH,
+ NM_CONFIG_GET_VALUE_STRIP | NM_CONFIG_GET_VALUE_NO_EMPTY);
+ if (!path)
+ path = g_strdup (""NM_CONFIG_KEYFILE_PATH_DEFAULT"");
+ }
+ return path;
+}
+
+/*****************************************************************************/
+
diff --git a/src/settings/plugins/keyfile/utils.h b/src/settings/plugins/keyfile/utils.h
index 79fb670705..0b2b6f4e5e 100644
--- a/src/settings/plugins/keyfile/utils.h
+++ b/src/settings/plugins/keyfile/utils.h
@@ -27,8 +27,6 @@
#define KEYFILE_PLUGIN_NAME "keyfile"
#define KEYFILE_PLUGIN_INFO "(c) 2007 - 2015 Red Hat, Inc. To report bugs please use the NetworkManager mailing list."
-#define KEYFILE_DIR NMCONFDIR "/system-connections"
-
#define NM_KEYFILE_CONNECTION_LOG_PATH(path) str_if_set (path,"in-memory")
#define NM_KEYFILE_CONNECTION_LOG_FMT "%s (%s,\"%s\")"
#define NM_KEYFILE_CONNECTION_LOG_ARG(con) NM_KEYFILE_CONNECTION_LOG_PATH (nm_settings_connection_get_filename ((NMSettingsConnection *) (con))), nm_connection_get_uuid ((NMConnection *) (con)), nm_connection_get_id ((NMConnection *) (con))
@@ -39,5 +37,7 @@ gboolean nm_keyfile_plugin_utils_should_ignore_file (const char *filename);
char *nm_keyfile_plugin_utils_escape_filename (const char *filename);
+const char *nm_keyfile_plugin_get_path (void);
+
#endif /* _UTILS_H_ */
diff --git a/src/settings/plugins/keyfile/writer.c b/src/settings/plugins/keyfile/writer.c
index 5c671a592b..db00b06104 100644
--- a/src/settings/plugins/keyfile/writer.c
+++ b/src/settings/plugins/keyfile/writer.c
@@ -366,7 +366,7 @@ nm_keyfile_plugin_write_connection (NMConnection *connection,
GError **error)
{
return _internal_write_connection (connection,
- KEYFILE_DIR,
+ nm_keyfile_plugin_get_path (),
0, 0,
existing_path,
force_rename,