keyfile: make the keyfile location configurable

https://bugzilla.gnome.org/show_bug.cgi?id=755995
This commit is contained in:
Thomas Haller 2015-10-09 18:16:42 +02:00
parent 0c0cdb1c46
commit 2144457fab
7 changed files with 42 additions and 9 deletions

View file

@ -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

View file

@ -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

View file

@ -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"

View file

@ -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;

View file

@ -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;
}
/*****************************************************************************/

View file

@ -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_ */

View file

@ -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,