diff options
author | Beniamino Galvani <bgalvani@redhat.com> | 2018-11-05 17:35:48 +0100 |
---|---|---|
committer | Beniamino Galvani <bgalvani@redhat.com> | 2018-11-29 15:28:59 +0100 |
commit | 39100a872ff7e592f527cf8578e860f15bad9aac (patch) | |
tree | 3d7084b3df1de8dde23c15074ffbdc472fcd8467 | |
parent | f15b837de6c0fb1ade951597678a0659b7723ec7 (diff) | |
download | NetworkManager-bg/log-connections-keyfile.tar.gz |
settings: print connections in keyfile format at startupbg/log-connections-keyfile
At startup we log the content of all connections which is often useful
for debugging purposes. However many composite properties are
displayed as just an address, which is not helpful at all:
++ ipv4.method = 'manual'
++ ipv4.addresses = ((GPtrArray*) 0x55ec61566380)
++ ipv4.routes = ((GPtrArray*) 0x55ec61566380)
...
Instead, let's display connections in out native persistence format -
the keyfile format - hiding secrets.
-rw-r--r-- | src/settings/nm-settings.c | 70 |
1 files changed, 64 insertions, 6 deletions
diff --git a/src/settings/nm-settings.c b/src/settings/nm-settings.c index 29a943b0ed..08f1b57930 100644 --- a/src/settings/nm-settings.c +++ b/src/settings/nm-settings.c @@ -78,6 +78,8 @@ #include "NetworkManagerUtils.h" #include "nm-dispatcher.h" #include "nm-hostname-manager.h" +#include "nm-keyfile-internal.h" +#include "nm-keyfile-utils.h" /*****************************************************************************/ @@ -893,6 +895,29 @@ openconnect_migrate_hack (NMConnection *connection) } } +static gboolean +write_handler (NMConnection *connection, + GKeyFile *keyfile, + NMKeyfileWriteType type, + void *type_data, + void *user_data, + GError **error) +{ + if (type == NM_KEYFILE_WRITE_TYPE_SECRET) { + NMKeyfileWriteTypeDataSecret *data = type_data; + const char *alias; + + alias = nm_keyfile_plugin_get_alias_for_setting_name (data->setting_name); + + g_key_file_set_string (keyfile, + alias ?: data->setting_name, + data->key, + "<hidden>"); + return TRUE; + } + return FALSE; +} + static void claim_connection (NMSettings *self, NMSettingsConnection *sett_conn) { @@ -978,12 +1003,45 @@ claim_connection (NMSettings *self, NMSettingsConnection *sett_conn) path = nm_dbus_object_export (NM_DBUS_OBJECT (sett_conn)); - nm_utils_log_connection_diff (nm_settings_connection_get_connection (sett_conn), - NULL, - LOGL_DEBUG, - LOGD_CORE, - "new connection", "++ ", - path); + if (nm_logging_enabled (LOGL_DEBUG, LOGD_CORE)) { + GKeyFile *key_file; + NMConnection *conn; + const char *conn_type; + + conn = nm_settings_connection_get_connection (sett_conn); + conn_type = nm_connection_get_connection_type (conn); + + nm_log (LOGL_DEBUG, LOGD_CORE, NULL, NULL, + "connection '%s' (%p/%s/%s%s%s):%s%s%s", + nm_settings_connection_get_id (sett_conn), + conn, G_OBJECT_TYPE_NAME (conn), + NM_PRINT_FMT_QUOTE_STRING (conn_type), + NM_PRINT_FMT_QUOTED (path, " [", path, "]", "")); + + key_file = nm_keyfile_write (conn, write_handler, NULL, &error); + if (key_file) { + char **groups, **keys; + guint g, k; + + groups = g_key_file_get_groups (key_file, NULL); + for (g = 0; groups && groups[g]; g++) { + keys = g_key_file_get_keys (key_file, groups[g], NULL, NULL); + for (k = 0; keys && keys[k]; k++) { + nm_log (LOGL_DEBUG, LOGD_CORE, NULL, NULL, + " %s.%s = %s", + groups[g], + keys[k], + g_key_file_get_string (key_file, groups[g], keys[k], NULL)); + } + g_free (keys); + } + g_free (groups); + } else { + nm_log (LOGL_DEBUG, LOGD_CORE, NULL, NULL, + "ERROR: can't display connection as keyfile: %s", error->message); + g_clear_error (&error); + } + } /* Only emit the individual connection-added signal after connections * have been initially loaded. |