Commit ef491acf authored by Beniamino Galvani's avatar Beniamino Galvani

core: split nm_utils_format_con_diff_for_audit()

The function will be called to display in audit logs the changes done
to connections.
parent 1ba25fd1
......@@ -4311,3 +4311,31 @@ skip:
return result;
}
char *
nm_utils_format_con_diff_for_audit (GHashTable *diff)
{
GHashTable *setting_diff;
char *setting_name, *prop_name;
GHashTableIter iter, iter2;
GString *str;
str = g_string_sized_new (32);
g_hash_table_iter_init (&iter, diff);
while (g_hash_table_iter_next (&iter,
(gpointer *) &setting_name,
(gpointer *) &setting_diff)) {
if (!setting_diff)
continue;
g_hash_table_iter_init (&iter2, setting_diff);
while (g_hash_table_iter_next (&iter2, (gpointer *) &prop_name, NULL))
g_string_append_printf (str, "%s.%s,", setting_name, prop_name);
}
if (str->len)
str->str[str->len - 1] = '\0';
return g_string_free (str, FALSE);
}
......@@ -469,5 +469,7 @@ struct stat;
gboolean nm_utils_validate_plugin (const char *path, struct stat *stat, GError **error);
char **nm_utils_read_plugin_paths (const char *dirname, const char *prefix);
char *nm_utils_format_con_diff_for_audit (GHashTable *diff);
#endif /* __NM_CORE_UTILS_H__ */
......@@ -1653,49 +1653,6 @@ con_update_cb (NMSettingsConnection *self,
update_complete (self, info, error);
}
static char *
con_list_changed_props (NMConnection *old, NMConnection *new)
{
gs_unref_hashtable GHashTable *diff = NULL;
GHashTable *setting_diff;
char *setting_name, *prop_name;
GHashTableIter iter, iter2;
gboolean same;
GString *str;
same = nm_connection_diff (old, new,
NM_SETTING_COMPARE_FLAG_EXACT |
NM_SETTING_COMPARE_FLAG_DIFF_RESULT_NO_DEFAULT,
&diff);
if (same || !diff)
return NULL;
str = g_string_sized_new (32);
g_hash_table_iter_init (&iter, diff);
while (g_hash_table_iter_next (&iter,
(gpointer *) &setting_name,
(gpointer *) &setting_diff)) {
if (!setting_diff)
continue;
g_hash_table_iter_init (&iter2, setting_diff);
while (g_hash_table_iter_next (&iter2, (gpointer *) &prop_name, NULL)) {
g_string_append (str, setting_name);
g_string_append_c (str, '.');
g_string_append (str, prop_name);
g_string_append_c (str, ',');
}
}
if (str->len)
str->str[str->len - 1] = '\0';
return g_string_free (str, FALSE);
}
static void
update_auth_cb (NMSettingsConnection *self,
GDBusMethodInvocation *context,
......@@ -1736,8 +1693,17 @@ update_auth_cb (NMSettingsConnection *self,
update_agent_secrets_cache (self, info->new_settings);
}
if (nm_audit_manager_audit_enabled (nm_audit_manager_get ()))
info->audit_args = con_list_changed_props (NM_CONNECTION (self), info->new_settings);
if (nm_audit_manager_audit_enabled (nm_audit_manager_get ())) {
gs_unref_hashtable GHashTable *diff = NULL;
gboolean same;
same = nm_connection_diff (NM_CONNECTION (self), info->new_settings,
NM_SETTING_COMPARE_FLAG_EXACT |
NM_SETTING_COMPARE_FLAG_DIFF_RESULT_NO_DEFAULT,
&diff);
if (!same && diff)
info->audit_args = nm_utils_format_con_diff_for_audit (diff);
}
if (info->save_to_disk) {
nm_settings_connection_replace_and_commit (self,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment