diff options
author | Beniamino Galvani <bgalvani@redhat.com> | 2016-08-19 11:56:58 +0200 |
---|---|---|
committer | Beniamino Galvani <bgalvani@redhat.com> | 2016-08-20 10:45:55 +0200 |
commit | e9f96024ae0abc8530ed8bd63ee7e3a7e615f587 (patch) | |
tree | 1aa1106d7992f706ebeebf5508fcf6d07fc2f807 /clients | |
parent | a77ed0de9729ebcc9cb96d5bd1f4bd4da9d4e0d5 (diff) | |
download | NetworkManager-e9f96024ae0abc8530ed8bd63ee7e3a7e615f587.tar.gz |
cli: return sane error message for D-Bus policy permission errors
The error returned to users when a load_connection(s)/set_logging call
fails due to D-Bus policy denial is a bit obscure:
$ nmcli general logging level debug
Error: failed to set logging: Rejected send message, 4 matched rules;
type="method_call", sender=":1.233" (uid=1001 pid=27225 comm="nmcli
general logging level debug ")
interface="org.freedesktop.NetworkManager" member="SetLogging" error
name="(unset)" requested_reply="0" destination=":1.207" (uid=0
pid=25793 comm="/usr/sbin/NetworkManager --no-daemon ")
Convert it to a more comprehensible:
$ nmcli general logging level debug
Error: failed to set logging: access denied
https://bugzilla.redhat.com/show_bug.cgi?id=1362542
(cherry picked from commit 805925f9efbc910975104bebe1050f0c663b61f7)
Diffstat (limited to 'clients')
-rw-r--r-- | clients/cli/common.c | 16 | ||||
-rw-r--r-- | clients/cli/common.h | 2 | ||||
-rw-r--r-- | clients/cli/connections.c | 4 | ||||
-rw-r--r-- | clients/cli/general.c | 2 |
4 files changed, 21 insertions, 3 deletions
diff --git a/clients/cli/common.c b/clients/cli/common.c index 42ee1c88c3..f1ec46a11e 100644 --- a/clients/cli/common.c +++ b/clients/cli/common.c @@ -1512,3 +1512,19 @@ nmc_complete_bool (const char *prefix) nmc_complete_strings (prefix, "true", "yes", "on", "false", "no", "off", NULL); } + +/** + * nmc_error_get_simple_message: + * @error: a GError + * + * Returns a simplified message for some errors hard to understand. + */ +const char * +nmc_error_get_simple_message (GError *error) +{ + /* Return a clear message instead of the obscure D-Bus policy error */ + if (g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_ACCESS_DENIED)) + return _("access denied"); + else + return error->message; +} diff --git a/clients/cli/common.h b/clients/cli/common.h index 2450cdb950..579c44a7d0 100644 --- a/clients/cli/common.h +++ b/clients/cli/common.h @@ -86,6 +86,8 @@ void nmc_complete_strings (const char *prefix, ...) G_GNUC_NULL_TERMINATED; void nmc_complete_bool (const char *prefix); +const char *nmc_error_get_simple_message (GError *error); + extern NmcOutputField nmc_fields_ip4_config[]; extern NmcOutputField nmc_fields_dhcp4_config[]; extern NmcOutputField nmc_fields_ip6_config[]; diff --git a/clients/cli/connections.c b/clients/cli/connections.c index 7888523eda..bb4c51cb8c 100644 --- a/clients/cli/connections.c +++ b/clients/cli/connections.c @@ -8336,7 +8336,7 @@ do_connection_reload (NmCli *nmc, int argc, char **argv) if (!nm_client_reload_connections (nmc->client, NULL, &error)) { g_string_printf (nmc->return_text, _("Error: failed to reload connections: %s."), - error->message); + nmc_error_get_simple_message (error)); nmc->return_value = NMC_RESULT_ERROR_UNKNOWN; g_clear_error (&error); } @@ -8368,7 +8368,7 @@ do_connection_load (NmCli *nmc, int argc, char **argv) g_free (filenames); if (error) { g_string_printf (nmc->return_text, _("Error: failed to load connection: %s."), - error->message); + nmc_error_get_simple_message (error)); nmc->return_value = NMC_RESULT_ERROR_UNKNOWN; g_error_free (error); } diff --git a/clients/cli/general.c b/clients/cli/general.c index ccf2292af8..e97091251f 100644 --- a/clients/cli/general.c +++ b/clients/cli/general.c @@ -622,7 +622,7 @@ do_general_logging (NmCli *nmc, int argc, char **argv) nm_client_set_logging (nmc->client, level, domains, &error); if (error) { g_string_printf (nmc->return_text, _("Error: failed to set logging: %s"), - error->message); + nmc_error_get_simple_message (error)); return NMC_RESULT_ERROR_UNKNOWN; } } |