diff options
| author | Michael Biebl <biebl@debian.org> | 2019-09-06 09:25:17 +0200 |
|---|---|---|
| committer | Michael Biebl <biebl@debian.org> | 2019-09-06 09:25:17 +0200 |
| commit | 555dfa331e295a3a687a7cc6870e1349ffed8f26 (patch) | |
| tree | aebc4e1ffa38b05780f0c1fe39bf78ca63c979c6 /src/settings | |
| parent | 5c79b900b59a5ad162ecc836e424468207ff031e (diff) | |
New upstream version 1.20.2 upstream/1.20.2
Diffstat (limited to 'src/settings')
| -rw-r--r-- | src/settings/nm-agent-manager.c | 2 | ||||
| -rw-r--r-- | src/settings/nm-settings-connection.c | 4 | ||||
| -rw-r--r-- | src/settings/nm-settings.c | 48 | ||||
| -rw-r--r-- | src/settings/plugins/ifupdown/nms-ifupdown-plugin.c | 2 | ||||
| -rw-r--r-- | src/settings/plugins/keyfile/nms-keyfile-writer.c | 71 |
5 files changed, 74 insertions, 53 deletions
diff --git a/src/settings/nm-agent-manager.c b/src/settings/nm-agent-manager.c index 2f9827d5..db0e021c 100644 --- a/src/settings/nm-agent-manager.c +++ b/src/settings/nm-agent-manager.c @@ -392,7 +392,7 @@ agent_manager_register_with_capabilities (NMAgentManager *self, if (!subject) { error = g_error_new_literal (NM_AGENT_MANAGER_ERROR, NM_AGENT_MANAGER_ERROR_PERMISSION_DENIED, - "Unable to determine request sender and UID."); + NM_UTILS_ERROR_MSG_REQ_UID_UKNOWN); goto done; } sender_uid = nm_auth_subject_get_unix_process_uid (subject); diff --git a/src/settings/nm-settings-connection.c b/src/settings/nm-settings-connection.c index 25a27e68..ed0cb8e8 100644 --- a/src/settings/nm-settings-connection.c +++ b/src/settings/nm-settings-connection.c @@ -1235,7 +1235,7 @@ pk_auth_cb (NMAuthManager *auth_manager, } else if (nm_auth_call_result_eval (is_authorized, is_challenge, auth_error) != NM_AUTH_CALL_RESULT_YES) { error = g_error_new_literal (NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_PERMISSION_DENIED, - "Insufficient privileges"); + NM_UTILS_ERROR_MSG_INSUFF_PRIV); } auth_data->callback (self, @@ -1268,7 +1268,7 @@ _new_auth_subject (GDBusMethodInvocation *context, GError **error) g_set_error_literal (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_PERMISSION_DENIED, - "Unable to determine UID of request."); + NM_UTILS_ERROR_MSG_REQ_UID_UKNOWN); } return subject; diff --git a/src/settings/nm-settings.c b/src/settings/nm-settings.c index 42a7bca0..4bdcb522 100644 --- a/src/settings/nm-settings.c +++ b/src/settings/nm-settings.c @@ -2421,7 +2421,7 @@ pk_add_cb (NMAuthChain *chain, if (result != NM_AUTH_CALL_RESULT_YES) { error = g_error_new_literal (NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_PERMISSION_DENIED, - "Insufficient privileges."); + NM_UTILS_ERROR_MSG_INSUFF_PRIV); } else { /* Authorized */ connection = nm_auth_chain_get_data (chain, "connection"); @@ -2521,7 +2521,7 @@ nm_settings_add_connection_dbus (NMSettings *self, if (!chain) { error = g_error_new_literal (NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_PERMISSION_DENIED, - "Unable to authenticate the request."); + NM_UTILS_ERROR_MSG_REQ_AUTH_FAILED); goto done; } @@ -2605,7 +2605,7 @@ settings_add_connection_helper (NMSettings *self, g_dbus_method_invocation_return_error_literal (context, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_PERMISSION_DENIED, - "Unable to determine UID of request."); + NM_UTILS_ERROR_MSG_REQ_UID_UKNOWN); return; } @@ -2946,7 +2946,7 @@ impl_settings_get_connection_by_uuid (NMDBusObject *obj, if (!subject) { error = g_error_new_literal (NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_PERMISSION_DENIED, - "Unable to determine UID of request."); + NM_UTILS_ERROR_MSG_REQ_UID_UKNOWN); goto error; } @@ -3288,15 +3288,14 @@ pk_hostname_cb (NMAuthChain *chain, c_list_unlink (nm_auth_chain_parent_lst_list (chain)); result = nm_auth_chain_get_result (chain, NM_AUTH_PERMISSION_SETTINGS_MODIFY_HOSTNAME); + hostname = nm_auth_chain_get_data (chain, "hostname"); /* If our NMSettingsConnection is already gone, do nothing */ if (result != NM_AUTH_CALL_RESULT_YES) { error = g_error_new_literal (NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_PERMISSION_DENIED, - "Insufficient privileges."); + NM_UTILS_ERROR_MSG_INSUFF_PRIV); } else { - hostname = nm_auth_chain_get_data (chain, "hostname"); - if (!nm_hostname_manager_write_hostname (priv->hostname_manager, hostname)) { error = g_error_new_literal (NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, @@ -3304,6 +3303,12 @@ pk_hostname_cb (NMAuthChain *chain, } } + nm_audit_log_control_op (NM_AUDIT_OP_HOSTNAME_SAVE, + hostname, + !error, + nm_auth_chain_get_subject (chain), + error ? error->message : NULL); + if (error) g_dbus_method_invocation_take_error (context, error); else @@ -3323,30 +3328,39 @@ impl_settings_save_hostname (NMDBusObject *obj, NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE (self); NMAuthChain *chain; const char *hostname; + const char *error_reason; + int error_code; g_variant_get (parameters, "(&s)", &hostname); /* Minimal validation of the hostname */ if (!nm_hostname_manager_validate_hostname (hostname)) { - g_dbus_method_invocation_return_error_literal (invocation, - NM_SETTINGS_ERROR, - NM_SETTINGS_ERROR_INVALID_HOSTNAME, - "The hostname was too long or contained invalid characters."); - return; + error_code = NM_SETTINGS_ERROR_INVALID_HOSTNAME; + error_reason = "The hostname was too long or contained invalid characters"; + goto err; } chain = nm_auth_chain_new_context (invocation, pk_hostname_cb, self); if (!chain) { - g_dbus_method_invocation_return_error_literal (invocation, - NM_SETTINGS_ERROR, - NM_SETTINGS_ERROR_PERMISSION_DENIED, - "Unable to authenticate the request."); - return; + error_code = NM_SETTINGS_ERROR_PERMISSION_DENIED; + error_reason = NM_UTILS_ERROR_MSG_REQ_AUTH_FAILED; + goto err; } c_list_link_tail (&priv->auth_lst_head, nm_auth_chain_parent_lst_list (chain)); nm_auth_chain_add_call (chain, NM_AUTH_PERMISSION_SETTINGS_MODIFY_HOSTNAME, TRUE); nm_auth_chain_set_data (chain, "hostname", g_strdup (hostname), g_free); + return; +err: + nm_audit_log_control_op (NM_AUDIT_OP_HOSTNAME_SAVE, + hostname, + FALSE, + invocation, + error_reason); + g_dbus_method_invocation_return_error_literal (invocation, + NM_SETTINGS_ERROR, + error_code, + error_reason); } /*****************************************************************************/ diff --git a/src/settings/plugins/ifupdown/nms-ifupdown-plugin.c b/src/settings/plugins/ifupdown/nms-ifupdown-plugin.c index 475ecbb6..e663ab8a 100644 --- a/src/settings/plugins/ifupdown/nms-ifupdown-plugin.c +++ b/src/settings/plugins/ifupdown/nms-ifupdown-plugin.c @@ -89,6 +89,8 @@ static GHashTable *load_eni_ifaces (NMSIfupdownPlugin *self); static void _storage_data_destroy (StorageData *sd) { + if (!sd) + return; nm_g_object_unref (sd->connection); nm_g_object_unref (sd->storage); g_slice_free (StorageData, sd); diff --git a/src/settings/plugins/keyfile/nms-keyfile-writer.c b/src/settings/plugins/keyfile/nms-keyfile-writer.c index 5fbbb7a1..abd3f1f4 100644 --- a/src/settings/plugins/keyfile/nms-keyfile-writer.c +++ b/src/settings/plugins/keyfile/nms-keyfile-writer.c @@ -126,6 +126,10 @@ cert_writer (NMConnection *connection, new_path = g_strdup_printf ("%s/%s-%s.%s", info->keyfile_dir, nm_connection_get_uuid (connection), cert_data->vtable->file_suffix, ext); + /* FIXME(keyfile-parse-in-memory): writer must not access/write to the file system before + * being sure that the entire profile can be written and all circumstances are good to + * proceed. That means, while writing we must only collect the blogs in-memory, and write + * them all in the end together (or not at all). */ success = nm_utils_file_set_contents (new_path, (const char *) blob_data, blob_len, 0600, &local); if (success) { @@ -193,10 +197,12 @@ _internal_write_connection (NMConnection *connection, gs_free char *path = NULL; const char *id; WriteInfo info = { 0 }; - GError *local_err = NULL; + gs_free_error GError *local_err = NULL; int errsv; gboolean rename; int i_path; + gs_unref_object NMConnection *reread = NULL; + gboolean reread_same = FALSE; g_return_val_if_fail (!out_path || !*out_path, FALSE); g_return_val_if_fail (keyfile_dir && keyfile_dir[0] == '/', FALSE); @@ -309,12 +315,40 @@ _internal_write_connection (NMConnection *connection, return FALSE; } + if ( out_reread + || out_reread_same) { + gs_free_error GError *reread_error = NULL; + + reread = nms_keyfile_reader_from_keyfile (kf_file, path, NULL, profile_dir, FALSE, &reread_error); + + if ( !reread + || !nm_connection_normalize (reread, NULL, NULL, &reread_error)) { + nm_log_err (LOGD_SETTINGS, "BUG: the profile cannot be stored in keyfile format without becoming unusable: %s", reread_error->message); + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, + "keyfile writer produces an invalid connection: %s", + reread_error->message); + nm_assert_not_reached (); + return FALSE; + } + + if (out_reread_same) { + reread_same = !!nm_connection_compare (reread, connection, NM_SETTING_COMPARE_FLAG_EXACT); + + nm_assert (reread_same == nm_connection_compare (connection, reread, NM_SETTING_COMPARE_FLAG_EXACT)); + nm_assert (reread_same == ({ + gs_unref_hashtable GHashTable *_settings = NULL; + + ( nm_connection_diff (reread, connection, NM_SETTING_COMPARE_FLAG_EXACT, &_settings) + && !_settings); + })); + } + } + nm_utils_file_set_contents (path, kf_content_buf, kf_content_len, 0600, &local_err); if (local_err) { g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, "error writing to file '%s': %s", path, local_err->message); - g_error_free (local_err); return FALSE; } @@ -335,36 +369,8 @@ _internal_write_connection (NMConnection *connection, && !nm_streq (path, existing_path)) unlink (existing_path); - if (out_reread || out_reread_same) { - gs_unref_object NMConnection *reread = NULL; - gboolean reread_same = FALSE; - - reread = nms_keyfile_reader_from_keyfile (kf_file, path, NULL, profile_dir, FALSE, NULL); - - nm_assert (NM_IS_CONNECTION (reread)); - - if ( reread - && !nm_connection_normalize (reread, NULL, NULL, NULL)) { - nm_assert_not_reached (); - g_clear_object (&reread); - } - - if (reread && out_reread_same) { - reread_same = !!nm_connection_compare (reread, connection, NM_SETTING_COMPARE_FLAG_EXACT); - - nm_assert (reread_same == nm_connection_compare (connection, reread, NM_SETTING_COMPARE_FLAG_EXACT)); - nm_assert (reread_same == ({ - gs_unref_hashtable GHashTable *_settings = NULL; - - ( nm_connection_diff (reread, connection, NM_SETTING_COMPARE_FLAG_EXACT, &_settings) - && !_settings); - })); - } - - NM_SET_OUT (out_reread, g_steal_pointer (&reread)); - NM_SET_OUT (out_reread_same, reread_same); - } - + NM_SET_OUT (out_reread, g_steal_pointer (&reread)); + NM_SET_OUT (out_reread_same, reread_same); NM_SET_OUT (out_path, g_steal_pointer (&path)); return TRUE; @@ -439,4 +445,3 @@ nms_keyfile_writer_test_connection (NMConnection *connection, out_reread_same, error); } - |