From ee9c73a923909e23a649407be77e25235d769e25 Mon Sep 17 00:00:00 2001 From: Michael Biebl Date: Fri, 11 May 2018 22:08:45 +0200 Subject: New upstream version 1.10.8 --- clients/cli/agent.c | 2 +- clients/cli/common.c | 129 ++---- clients/cli/connections.c | 238 +++++----- clients/cli/devices.c | 7 +- clients/cli/general.c | 3 - clients/cli/meson.build | 48 -- clients/cli/nmcli.c | 20 +- clients/cli/nmcli.h | 12 +- clients/cli/polkit-agent.c | 73 +-- clients/cli/settings.c | 9 +- clients/cli/utils.c | 27 +- clients/cli/utils.h | 2 +- clients/common/meson.build | 81 ---- clients/common/nm-client-utils.c | 106 +---- clients/common/nm-client-utils.h | 8 +- clients/common/nm-meta-setting-access.c | 3 - clients/common/nm-meta-setting-access.h | 1 - clients/common/nm-meta-setting-desc.c | 718 +++++++++++++++--------------- clients/common/nm-meta-setting-desc.h | 7 +- clients/common/nm-polkit-listener.c | 214 +++++---- clients/common/nm-polkit-listener.h | 86 +--- clients/common/nm-secret-agent-simple.c | 236 +++++----- clients/common/nm-secret-agent-simple.h | 21 +- clients/common/nm-vpn-helpers.h | 2 + clients/common/settings-docs.c | 387 ++++++++++++++++ clients/common/settings-docs.c.in | 387 ++++++++++++++++ clients/common/settings-docs.h | 390 ---------------- clients/common/settings-docs.h.in | 390 ---------------- clients/common/tests/meson.build | 23 - clients/common/tests/test-general.c | 10 +- clients/meson.build | 35 -- clients/nm-online.c | 4 + clients/tui/meson.build | 72 --- clients/tui/newt/meson.build | 35 -- clients/tui/newt/nmt-newt-section.c | 2 +- clients/tui/newt/nmt-newt-utils.c | 12 +- clients/tui/newt/nmt-newt-widget.c | 4 +- clients/tui/nm-editor-bindings.h | 2 + clients/tui/nm-editor-utils.c | 2 + clients/tui/nm-editor-utils.h | 2 + clients/tui/nmt-connect-connection-list.c | 9 +- clients/tui/nmt-device-entry.c | 2 + clients/tui/nmt-device-entry.h | 2 + clients/tui/nmt-edit-connection-list.c | 2 +- clients/tui/nmt-edit-connection-list.h | 2 + clients/tui/nmt-editor-grid.c | 2 +- clients/tui/nmt-editor-page.h | 2 + clients/tui/nmt-editor.h | 2 + clients/tui/nmt-mac-entry.c | 1 + clients/tui/nmt-page-bond.c | 30 +- clients/tui/nmt-page-team-port.c | 2 +- clients/tui/nmt-page-team.c | 2 +- clients/tui/nmt-password-dialog.c | 4 +- clients/tui/nmt-route-editor.h | 2 + clients/tui/nmt-route-entry.c | 4 +- clients/tui/nmt-route-table.c | 4 + clients/tui/nmt-slave-list.c | 2 + clients/tui/nmt-utils.c | 2 +- clients/tui/nmtui-connect.c | 43 +- clients/tui/nmtui-edit.c | 2 + clients/tui/nmtui-hostname.c | 2 +- clients/tui/nmtui.c | 2 + clients/tui/nmtui.h | 2 + 63 files changed, 1781 insertions(+), 2156 deletions(-) delete mode 100644 clients/cli/meson.build delete mode 100644 clients/common/meson.build create mode 100644 clients/common/settings-docs.c create mode 100644 clients/common/settings-docs.c.in delete mode 100644 clients/common/settings-docs.h delete mode 100644 clients/common/settings-docs.h.in delete mode 100644 clients/common/tests/meson.build delete mode 100644 clients/meson.build delete mode 100644 clients/tui/meson.build delete mode 100644 clients/tui/newt/meson.build (limited to 'clients') diff --git a/clients/cli/agent.c b/clients/cli/agent.c index 46725c94..488b16f4 100644 --- a/clients/cli/agent.c +++ b/clients/cli/agent.c @@ -104,7 +104,7 @@ get_secrets_from_user (const char *request_id, rl_startup_hook = set_deftext; pre_input_deftext = g_strdup (secret->value); } - pwd = nmc_readline ("%s (%s): ", secret->pretty_name, secret->entry_id); + pwd = nmc_readline ("%s (%s): ", secret->name, secret->prop_name); /* No password provided, cancel the secrets. */ if (!pwd) diff --git a/clients/cli/common.c b/clients/cli/common.c index 81a3183d..0f5aea57 100644 --- a/clients/cli/common.c +++ b/clients/cli/common.c @@ -16,7 +16,7 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright 2012 - 2017 Red Hat, Inc. + * Copyright 2012 - 2014 Red Hat, Inc. */ #include "nm-default.h" @@ -26,10 +26,12 @@ #include #include #include +#include #include #include #include +#include "nm-utils/nm-hash-utils.h" #include "nm-vpn-helpers.h" #include "nm-client-utils.h" @@ -107,7 +109,6 @@ _metagen_ip4_config_get_fcn (const NMMetaEnvironment *environment, NMMetaAccessorGetType get_type, NMMetaAccessorGetFlags get_flags, NMMetaAccessorGetOutFlags *out_flags, - gboolean *out_is_default, gpointer *out_to_free) { NMIPConfig *cfg4 = target; @@ -115,12 +116,10 @@ _metagen_ip4_config_get_fcn (const NMMetaEnvironment *environment, char **arr; const char *const*arrc; guint i = 0; - const char *str; nm_assert (info->info_type < _NMC_GENERIC_INFO_TYPE_IP4_CONFIG_NUM); NMC_HANDLE_TERMFORMAT (NM_META_TERM_COLOR_NORMAL); - NM_SET_OUT (out_is_default, TRUE); switch (info->info_type) { case NMC_GENERIC_INFO_TYPE_IP4_CONFIG_ADDRESS: @@ -141,9 +140,7 @@ _metagen_ip4_config_get_fcn (const NMMetaEnvironment *environment, arr = NULL; goto arr_out; case NMC_GENERIC_INFO_TYPE_IP4_CONFIG_GATEWAY: - str = nm_ip_config_get_gateway (cfg4); - NM_SET_OUT (out_is_default, !str); - return str; + return nm_ip_config_get_gateway (cfg4); case NMC_GENERIC_INFO_TYPE_IP4_CONFIG_ROUTE: if (!NM_FLAGS_HAS (get_flags, NM_META_ACCESSOR_GET_FLAGS_ACCEPT_STRV)) return NULL; @@ -171,12 +168,10 @@ _metagen_ip4_config_get_fcn (const NMMetaEnvironment *environment, g_return_val_if_reached (NULL); arrc_out: - NM_SET_OUT (out_is_default, !arrc || !arrc[0]); *out_flags |= NM_META_ACCESSOR_GET_OUT_FLAGS_STRV; return arrc; arr_out: - NM_SET_OUT (out_is_default, !arr || !arr[0]); *out_flags |= NM_META_ACCESSOR_GET_OUT_FLAGS_STRV; *out_to_free = arr; return arr; @@ -190,7 +185,6 @@ _metagen_ip6_config_get_fcn (const NMMetaEnvironment *environment, NMMetaAccessorGetType get_type, NMMetaAccessorGetFlags get_flags, NMMetaAccessorGetOutFlags *out_flags, - gboolean *out_is_default, gpointer *out_to_free) { NMIPConfig *cfg6 = target; @@ -198,12 +192,10 @@ _metagen_ip6_config_get_fcn (const NMMetaEnvironment *environment, char **arr; const char *const*arrc; guint i = 0; - const char *str; nm_assert (info->info_type < _NMC_GENERIC_INFO_TYPE_IP6_CONFIG_NUM); NMC_HANDLE_TERMFORMAT (NM_META_TERM_COLOR_NORMAL); - NM_SET_OUT (out_is_default, TRUE); switch (info->info_type) { case NMC_GENERIC_INFO_TYPE_IP6_CONFIG_ADDRESS: @@ -224,9 +216,7 @@ _metagen_ip6_config_get_fcn (const NMMetaEnvironment *environment, arr = NULL; goto arr_out; case NMC_GENERIC_INFO_TYPE_IP6_CONFIG_GATEWAY: - str = nm_ip_config_get_gateway (cfg6); - NM_SET_OUT (out_is_default, !str); - return str; + return nm_ip_config_get_gateway (cfg6); case NMC_GENERIC_INFO_TYPE_IP6_CONFIG_ROUTE: if (!NM_FLAGS_HAS (get_flags, NM_META_ACCESSOR_GET_FLAGS_ACCEPT_STRV)) return NULL; @@ -249,12 +239,10 @@ _metagen_ip6_config_get_fcn (const NMMetaEnvironment *environment, g_return_val_if_reached (NULL); arrc_out: - NM_SET_OUT (out_is_default, !arrc || !arrc[0]); *out_flags |= NM_META_ACCESSOR_GET_OUT_FLAGS_STRV; return arrc; arr_out: - NM_SET_OUT (out_is_default, !arr || !arr[0]); *out_flags |= NM_META_ACCESSOR_GET_OUT_FLAGS_STRV; *out_to_free = arr; return arr; @@ -544,10 +532,10 @@ vpn_openconnect_get_secrets (NMConnection *connection, GPtrArray *secrets) { GError *error = NULL; NMSettingVpn *s_vpn; - const char *gw, *port; - gs_free char *cookie = NULL; - gs_free char *gateway = NULL; - gs_free char *gwcert = NULL; + const char *vpn_type, *gw, *port; + char *cookie = NULL; + char *gateway = NULL; + char *gwcert = NULL; int status = 0; int i; gboolean ret; @@ -559,7 +547,8 @@ vpn_openconnect_get_secrets (NMConnection *connection, GPtrArray *secrets) return FALSE; s_vpn = nm_connection_get_setting_vpn (connection); - if (!nm_streq0 (nm_setting_vpn_get_service_type (s_vpn), NM_SECRET_AGENT_VPN_TYPE_OPENCONNECT)) + vpn_type = nm_setting_vpn_get_service_type (s_vpn); + if (g_strcmp0 (vpn_type, NM_DBUS_INTERFACE ".openconnect")) return FALSE; /* Get gateway and port */ @@ -582,31 +571,34 @@ vpn_openconnect_get_secrets (NMConnection *connection, GPtrArray *secrets) /* Append port to the host value */ if (gateway && port) { - gs_free char *tmp = gateway; - - gateway = g_strdup_printf ("%s%s", tmp, port); + char *tmp = gateway; + gateway = g_strdup_printf ("%s%s", gateway, port); + g_free (tmp); } /* Fill secrets to the array */ for (i = 0; i < secrets->len; i++) { NMSecretAgentSimpleSecret *secret = secrets->pdata[i]; - if (secret->secret_type != NM_SECRET_AGENT_SECRET_TYPE_VPN_SECRET) - continue; - if (!nm_streq0 (secret->vpn_type, NM_SECRET_AGENT_VPN_TYPE_OPENCONNECT)) - continue; - - if (nm_streq0 (secret->entry_id, NM_SECRET_AGENT_ENTRY_ID_PREFX_VPN_SECRET "cookie")) { - g_free (secret->value); - secret->value = g_steal_pointer (&cookie); - } else if (nm_streq0 (secret->entry_id, NM_SECRET_AGENT_ENTRY_ID_PREFX_VPN_SECRET "gateway")) { - g_free (secret->value); - secret->value = g_steal_pointer (&gateway); - } else if (nm_streq0 (secret->entry_id, NM_SECRET_AGENT_ENTRY_ID_PREFX_VPN_SECRET "gwcert")) { - g_free (secret->value); - secret->value = g_steal_pointer (&gwcert); + if (!g_strcmp0 (secret->vpn_type, vpn_type)) { + if (!g_strcmp0 (secret->vpn_property, "cookie")) { + g_free (secret->value); + secret->value = cookie; + cookie = NULL; + } else if (!g_strcmp0 (secret->vpn_property, "gateway")) { + g_free (secret->value); + secret->value = gateway; + gateway = NULL; + } else if (!g_strcmp0 (secret->vpn_property, "gwcert")) { + g_free (secret->value); + secret->value = gwcert; + gwcert = NULL; + } } } + g_free (cookie); + g_free (gateway); + g_free (gwcert); return TRUE; } @@ -633,7 +625,7 @@ get_secrets_from_user (const char *request_id, /* First try to find the password in provided passwords file, * then ask user. */ - if (pwds_hash && (pwd = g_hash_table_lookup (pwds_hash, secret->entry_id))) { + if (pwds_hash && (pwd = g_hash_table_lookup (pwds_hash, secret->prop_name))) { pwd = g_strdup (pwd); } else { if (ask) { @@ -649,10 +641,8 @@ get_secrets_from_user (const char *request_id, } if (msg) g_print ("%s\n", msg); - pwd = nmc_readline_echo (secret->is_secret - ? echo_on - : TRUE, - "%s (%s): ", secret->pretty_name, secret->entry_id); + pwd = nmc_readline_echo (secret->password ? echo_on : TRUE, + "%s (%s): ", secret->name, secret->prop_name); if (!pwd) pwd = g_strdup (""); } else { @@ -660,7 +650,7 @@ get_secrets_from_user (const char *request_id, g_print ("%s\n", msg); g_printerr (_("Warning: password for '%s' not given in 'passwd-file' " "and nmcli cannot ask without '--ask' option.\n"), - secret->entry_id); + secret->prop_name); } } /* No password provided, cancel the secrets. */ @@ -893,31 +883,6 @@ nmc_readline (const char *prompt_fmt, ...) return str; } -static void -nmc_secret_redisplay (void) -{ - int save_point = rl_point; - int save_end = rl_end; - char *save_line_buffer = rl_line_buffer; - const char *subst = nmc_password_subst_char (); - int subst_len = strlen (subst); - int i; - - rl_point = g_utf8_strlen (save_line_buffer, save_point) * subst_len; - rl_end = g_utf8_strlen (rl_line_buffer, -1) * subst_len; - rl_line_buffer = g_slice_alloc (rl_end + 1); - - for (i = 0; i + subst_len <= rl_end; i += subst_len) - memcpy (&rl_line_buffer[i], subst, subst_len); - rl_line_buffer[i] = '\0'; - - rl_redisplay (); - g_slice_free1 (rl_end + 1, rl_line_buffer); - rl_line_buffer = save_line_buffer; - rl_end = save_end; - rl_point = save_point; -} - /** * nmc_readline_echo: * @@ -929,28 +894,29 @@ nmc_readline_echo (gboolean echo_on, const char *prompt_fmt, ...) { va_list args; char *prompt, *str; - HISTORY_STATE *saved_history; - HISTORY_STATE passwd_history = { 0, }; + struct termios termios_orig, termios_new; va_start (args, prompt_fmt); prompt = g_strdup_vprintf (prompt_fmt, args); va_end (args); - /* Hide the actual password */ + /* Disable echoing characters */ if (!echo_on) { - saved_history = history_get_history_state (); - history_set_history_state (&passwd_history); - rl_redisplay_function = nmc_secret_redisplay; + tcgetattr (STDIN_FILENO, &termios_orig); + termios_new = termios_orig; + termios_new.c_lflag &= ~(ECHO); + tcsetattr (STDIN_FILENO, TCSADRAIN, &termios_new); } str = nmc_readline_helper (prompt); g_free (prompt); - /* Restore the non-hiding behavior */ + /* Restore original terminal settings */ if (!echo_on) { - rl_redisplay_function = rl_redisplay; - history_set_history_state (saved_history); + tcsetattr (STDIN_FILENO, TCSADRAIN, &termios_orig); + /* New line - setting ECHONL | ICANON did not help */ + fprintf (stdout, "\n"); } return str; @@ -1249,8 +1215,9 @@ nmc_do_cmd (NmCli *nmc, const NMCCommand cmds[], const char *cmd, int argc, char /* A valid command was specified. */ if (c->usage && argc == 2 && nmc->complete) nmc_complete_help (*(argv+1)); - if (!nmc->complete && c->usage && nmc_arg_is_help (*(argv+1))) { - c->usage (); + if (c->usage && nmc_arg_is_help (*(argv+1))) { + if (!nmc->complete) + c->usage (); g_simple_async_result_complete_in_idle (simple); g_object_unref (simple); } else { diff --git a/clients/cli/connections.c b/clients/cli/connections.c index 705d3c25..e0f55c53 100644 --- a/clients/cli/connections.c +++ b/clients/cli/connections.c @@ -31,6 +31,8 @@ #include #include +#include "nm-utils/nm-hash-utils.h" + #include "nm-client-utils.h" #include "nm-vpn-helpers.h" #include "nm-meta-setting-access.h" @@ -503,8 +505,12 @@ usage_connection_export (void) static void quit (void) { - if (nm_clear_g_source (&progress_id)) + if (progress_id) { + g_source_remove (progress_id); + progress_id = 0; nmc_terminal_erase_line (); + } + g_main_loop_quit (loop); } @@ -1122,6 +1128,7 @@ nmc_active_connection_details (NMActiveConnection *acon, NmCli *nmc) const char *fields_str = NULL; const NMMetaAbstractInfo *const*tmpl; NmcOutputField *arr; + size_t tmpl_len; const char *base_hdr = _("Activate connection details"); gboolean was_output = FALSE; @@ -1175,6 +1182,7 @@ nmc_active_connection_details (NMActiveConnection *acon, NmCli *nmc) /* Add field names */ tmpl = (const NMMetaAbstractInfo *const*) nmc_fields_con_active_details_general; + tmpl_len = sizeof (nmc_fields_con_active_details_general); out_indices = parse_output_fields (group_fld, tmpl, FALSE, NULL, NULL); arr = nmc_dup_fields_array (tmpl, NMC_OF_FLAG_FIELD_NAMES); @@ -1581,18 +1589,18 @@ get_invisible_active_connections (NmCli *nmc) static GArray * parse_preferred_connection_order (const char *order, GError **error) { - gs_free const char **strv = NULL; - const char *const*iter; + char **strv, **iter; const char *str; GArray *order_arr; NmcSortOrder val; gboolean inverse, unique; int i; - strv = nm_utils_strsplit_set (order, ":"); - if (!strv) { + strv = nmc_strsplit_set (order, ":", -1); + if (!strv || !*strv) { g_set_error (error, NMCLI_ERROR, 0, _("incorrect string '%s' of '--order' option"), order); + g_strfreev (strv); return NULL; } @@ -1634,6 +1642,7 @@ parse_preferred_connection_order (const char *order, GError **error) g_array_append_val (order_arr, val); } + g_strfreev (strv); return order_arr; } @@ -1653,17 +1662,16 @@ get_connection (NmCli *nmc, int *argc, char ***argv, int *pos, GError **error) if (*argc == 1 && nmc->complete) nmc_complete_strings (**argv, "id", "uuid", "path", NULL); - if (NM_IN_STRSET (**argv, "id", "uuid", "path")) { - if (*argc == 1) { - if (!nmc->complete) { - g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT, - _("%s argument is missing"), selector); - return NULL; - } - } else { - selector = **argv; - (*argv)++; - (*argc)--; + if ( strcmp (**argv, "id") == 0 + || strcmp (**argv, "uuid") == 0 + || strcmp (**argv, "path") == 0) { + selector = **argv; + (*argc)--; + (*argv)++; + if (!*argc) { + g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT, + _("%s argument is missing"), selector); + return NULL; } } @@ -2287,50 +2295,48 @@ activate_connection_cb (GObject *client, GAsyncResult *result, gpointer user_dat static GHashTable * parse_passwords (const char *passwd_file, GError **error) { - gs_unref_hashtable GHashTable *pwds_hash = NULL; - gs_free char *contents = NULL; + GHashTable *pwds_hash; + char *contents = NULL; gsize len = 0; GError *local_err = NULL; - gs_free const char **strv = NULL; - const char *const*iter; + char **lines, **iter; char *pwd_spec, *pwd, *prop; const char *setting; pwds_hash = g_hash_table_new_full (nm_str_hash, g_str_equal, g_free, g_free); if (!passwd_file) - return g_steal_pointer (&pwds_hash); + return pwds_hash; - /* Read the passwords file */ + /* Read the passwords file */ if (!g_file_get_contents (passwd_file, &contents, &len, &local_err)) { g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT, _("failed to read passwd-file '%s': %s"), passwd_file, local_err->message); g_error_free (local_err); + g_hash_table_destroy (pwds_hash); return NULL; } - strv = nm_utils_strsplit_set (contents, "\r\n"); - for (iter = strv; *iter; iter++) { - gs_free char *iter_s = g_strdup (*iter); - - pwd = strchr (iter_s, ':'); + lines = nmc_strsplit_set (contents, "\r\n", -1); + for (iter = lines; *iter; iter++) { + pwd = strchr (*iter, ':'); if (!pwd) { g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT, _("missing colon in 'password' entry '%s'"), *iter); - return NULL; + goto failure; } *(pwd++) = '\0'; - prop = strchr (iter_s, '.'); + prop = strchr (*iter, '.'); if (!prop) { g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT, _("missing dot in 'password' entry '%s'"), *iter); - return NULL; + goto failure; } *(prop++) = '\0'; - setting = iter_s; + setting = *iter; while (g_ascii_isspace (*setting)) setting++; /* Accept wifi-sec or wifi instead of cumbersome '802-11-wireless-security' */ @@ -2339,13 +2345,21 @@ parse_passwords (const char *passwd_file, GError **error) if (nm_setting_lookup_type (setting) == G_TYPE_INVALID) { g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT, _("invalid setting name in 'password' entry '%s'"), setting); - return NULL; + goto failure; } pwd_spec = g_strdup_printf ("%s.%s", setting, prop); g_hash_table_insert (pwds_hash, pwd_spec, g_strdup (pwd)); } - return g_steal_pointer (&pwds_hash); + g_strfreev (lines); + g_free (contents); + return pwds_hash; + +failure: + g_strfreev (lines); + g_free (contents); + g_hash_table_destroy (pwds_hash); + return NULL; } @@ -3325,7 +3339,7 @@ _dynamic_options_set (const NMMetaAbstractInfo *abstract_info, PropertyInfFlags v, v2; if (G_UNLIKELY (!cache)) - cache = g_hash_table_new (nm_direct_hash, NULL); + cache = g_hash_table_new (NULL, NULL); if (g_hash_table_lookup_extended (cache, (gpointer) abstract_info, NULL, &p)) v = GPOINTER_TO_UINT (p); @@ -5875,80 +5889,50 @@ typedef enum { NMC_EDITOR_MAIN_CMD_QUIT, } NmcEditorMainCmd; -static void -_split_cmd (const char *cmd, char **out_arg0, const char **out_argr) -{ - gs_free char *arg0 = NULL; - const char *argr = NULL; - gsize l; - - NM_SET_OUT (out_arg0, NULL); - NM_SET_OUT (out_argr, NULL); - - if (!cmd) - return; - while (NM_IN_SET (cmd[0], ' ', '\t')) - cmd++; - if (!cmd[0]) - return; - - l = strcspn (cmd, " \t"); - arg0 = g_strndup (cmd, l); - cmd += l; - if (cmd[0]) { - while (NM_IN_SET (cmd[0], ' ', '\t')) - cmd++; - if (cmd[0]) - argr = cmd; - } - - NM_SET_OUT (out_arg0, g_steal_pointer (&arg0)); - NM_SET_OUT (out_argr, argr); -} - static NmcEditorMainCmd parse_editor_main_cmd (const char *cmd, char **cmd_arg) { NmcEditorMainCmd editor_cmd = NMC_EDITOR_MAIN_CMD_UNKNOWN; - gs_free char *cmd_arg0 = NULL; - const char *cmd_argr; + char **vec; - _split_cmd (cmd, &cmd_arg0, &cmd_argr); - if (!cmd_arg0) - goto fail; + vec = nmc_strsplit_set (cmd, " \t", 2); + if (g_strv_length (vec) < 1) { + if (cmd_arg) + *cmd_arg = NULL; + return NMC_EDITOR_MAIN_CMD_UNKNOWN; + } - if (matches (cmd_arg0, "goto")) + if (matches (vec[0], "goto")) editor_cmd = NMC_EDITOR_MAIN_CMD_GOTO; - else if (matches (cmd_arg0, "remove")) + else if (matches (vec[0], "remove")) editor_cmd = NMC_EDITOR_MAIN_CMD_REMOVE; - else if (matches (cmd_arg0, "set")) + else if (matches (vec[0], "set")) editor_cmd = NMC_EDITOR_MAIN_CMD_SET; - else if (matches (cmd_arg0, "describe")) + else if (matches (vec[0], "describe")) editor_cmd = NMC_EDITOR_MAIN_CMD_DESCRIBE; - else if (matches (cmd_arg0, "print")) + else if (matches (vec[0], "print")) editor_cmd = NMC_EDITOR_MAIN_CMD_PRINT; - else if (matches (cmd_arg0, "verify")) + else if (matches (vec[0], "verify")) editor_cmd = NMC_EDITOR_MAIN_CMD_VERIFY; - else if (matches (cmd_arg0, "save")) + else if (matches (vec[0], "save")) editor_cmd = NMC_EDITOR_MAIN_CMD_SAVE; - else if (matches (cmd_arg0, "activate")) + else if (matches (vec[0], "activate")) editor_cmd = NMC_EDITOR_MAIN_CMD_ACTIVATE; - else if (matches (cmd_arg0, "back")) + else if (matches (vec[0], "back")) editor_cmd = NMC_EDITOR_MAIN_CMD_BACK; - else if (matches (cmd_arg0, "help") || strcmp (cmd_arg0, "?") == 0) + else if (matches (vec[0], "help") || strcmp (vec[0], "?") == 0) editor_cmd = NMC_EDITOR_MAIN_CMD_HELP; - else if (matches (cmd_arg0, "quit")) + else if (matches (vec[0], "quit")) editor_cmd = NMC_EDITOR_MAIN_CMD_QUIT; - else if (matches (cmd_arg0, "nmcli")) + else if (matches (vec[0], "nmcli")) editor_cmd = NMC_EDITOR_MAIN_CMD_NMCLI; - else - goto fail; - NM_SET_OUT (cmd_arg, g_strdup (cmd_argr)); + /* set pointer to command argument */ + if (cmd_arg) + *cmd_arg = vec[1] ? g_strstrip (g_strdup (vec[1])) : NULL; + + g_strfreev (vec); return editor_cmd; -fail: - NM_SET_OUT (cmd_arg, NULL); - return NMC_EDITOR_MAIN_CMD_UNKNOWN; } static void @@ -6097,39 +6081,40 @@ static NmcEditorSubCmd parse_editor_sub_cmd (const char *cmd, char **cmd_arg) { NmcEditorSubCmd editor_cmd = NMC_EDITOR_SUB_CMD_UNKNOWN; - gs_free char *cmd_arg0 = NULL; - const char *cmd_argr; + char **vec; - _split_cmd (cmd, &cmd_arg0, &cmd_argr); - if (!cmd_arg0) - goto fail; + vec = nmc_strsplit_set (cmd, " \t", 2); + if (g_strv_length (vec) < 1) { + if (cmd_arg) + *cmd_arg = NULL; + return NMC_EDITOR_SUB_CMD_UNKNOWN; + } - if (matches (cmd_arg0, "set")) + if (matches (vec[0], "set")) editor_cmd = NMC_EDITOR_SUB_CMD_SET; - else if (matches (cmd_arg0, "add")) + else if (matches (vec[0], "add")) editor_cmd = NMC_EDITOR_SUB_CMD_ADD; - else if (matches (cmd_arg0, "change")) + else if (matches (vec[0], "change")) editor_cmd = NMC_EDITOR_SUB_CMD_CHANGE; - else if (matches (cmd_arg0, "remove")) + else if (matches (vec[0], "remove")) editor_cmd = NMC_EDITOR_SUB_CMD_REMOVE; - else if (matches (cmd_arg0, "describe")) + else if (matches (vec[0], "describe")) editor_cmd = NMC_EDITOR_SUB_CMD_DESCRIBE; - else if (matches (cmd_arg0, "print")) + else if (matches (vec[0], "print")) editor_cmd = NMC_EDITOR_SUB_CMD_PRINT; - else if (matches (cmd_arg0, "back")) + else if (matches (vec[0], "back")) editor_cmd = NMC_EDITOR_SUB_CMD_BACK; - else if (matches (cmd_arg0, "help") || strcmp (cmd_arg0, "?") == 0) + else if (matches (vec[0], "help") || strcmp (vec[0], "?") == 0) editor_cmd = NMC_EDITOR_SUB_CMD_HELP; - else if (matches (cmd_arg0, "quit")) + else if (matches (vec[0], "quit")) editor_cmd = NMC_EDITOR_SUB_CMD_QUIT; - else - goto fail; - NM_SET_OUT (cmd_arg, g_strdup (cmd_argr)); + /* set pointer to command argument */ + if (cmd_arg) + *cmd_arg = g_strdup (vec[1]); + + g_strfreev (vec); return editor_cmd; -fail: - NM_SET_OUT (cmd_arg, NULL); - return NMC_EDITOR_SUB_CMD_UNKNOWN; } static void @@ -6665,26 +6650,29 @@ property_edit_submenu (NmCli *nmc, static void split_editor_main_cmd_args (const char *str, char **setting, char **property, char **value) { - gs_free char *cmd_arg0 = NULL; - const char *cmd_argr; - const char *s; + char **args, **items; - NM_SET_OUT (setting, NULL); - NM_SET_OUT (property, NULL); - NM_SET_OUT (value, NULL); - - _split_cmd (str, &cmd_arg0, &cmd_argr); - if (!cmd_arg0) + if (!str) return; - NM_SET_OUT (value, g_strdup (cmd_argr)); - s = strchr (cmd_arg0, '.'); - if (s && s > cmd_arg0) { - NM_SET_OUT (setting, g_strndup (cmd_arg0, s - cmd_arg0)); - NM_SET_OUT (property, g_strdup (&s[1])); - } else { - NM_SET_OUT (property, g_steal_pointer (&cmd_arg0)); + args = nmc_strsplit_set (str, " \t", 2); + if (args[0]) { + items = nmc_strsplit_set (args[0], ".", 2); + if (g_strv_length (items) == 2) { + if (setting) + *setting = g_strdup (items[0]); + if (property) + *property = g_strdup (items[1]); + } else { + if (property) + *property = g_strdup (items[0]); + } + g_strfreev (items); + + if (value && args[1]) + *value = g_strstrip (g_strdup (args[1])); } + g_strfreev (args); } static NMSetting * @@ -6805,7 +6793,7 @@ confirm_connection_saving (NMConnection *local, NMConnection *remote) return confirmed; } -typedef struct { +typedef struct { guint level; char *main_prompt; NMSetting *curr_setting; diff --git a/clients/cli/devices.c b/clients/cli/devices.c index a43861fa..da969fbe 100644 --- a/clients/cli/devices.c +++ b/clients/cli/devices.c @@ -451,8 +451,11 @@ usage_device_lldp (void) static void quit (void) { - if (nm_clear_g_source (&progress_id)) + if (progress_id) { + g_source_remove (progress_id); nmc_terminal_erase_line (); + } + g_main_loop_quit (loop); } @@ -831,7 +834,7 @@ fill_output_access_point (gpointer data, gpointer user_data) strength_str = g_strdup_printf ("%u", strength); wpa_flags_str = ap_wpa_rsn_flags_to_string (wpa_flags); rsn_flags_str = ap_wpa_rsn_flags_to_string (rsn_flags); - sig_bars = nmc_wifi_strength_bars (strength); + sig_bars = nm_utils_wifi_strength_bars (strength); security_str = g_string_new (NULL); diff --git a/clients/cli/general.c b/clients/cli/general.c index 647ee5fc..7ac6b22c 100644 --- a/clients/cli/general.c +++ b/clients/cli/general.c @@ -175,7 +175,6 @@ _metagen_general_status_get_fcn (const NMMetaEnvironment *environment, NMMetaAccessorGetType get_type, NMMetaAccessorGetFlags get_flags, NMMetaAccessorGetOutFlags *out_flags, - gboolean *out_is_default, gpointer *out_to_free) { NmCli *nmc = target; @@ -283,7 +282,6 @@ _metagen_general_permissions_get_fcn (const NMMetaEnvironment *environment, NMMetaAccessorGetType get_type, NMMetaAccessorGetFlags get_flags, NMMetaAccessorGetOutFlags *out_flags, - gboolean *out_is_default, gpointer *out_to_free) { NMClientPermission perm = GPOINTER_TO_UINT (target); @@ -332,7 +330,6 @@ _metagen_general_logging_get_fcn (const NMMetaEnvironment *environment, NMMetaAccessorGetType get_type, NMMetaAccessorGetFlags get_flags, NMMetaAccessorGetOutFlags *out_flags, - gboolean *out_is_default, gpointer *out_to_free) { NmCli *nmc = environment_user_data; diff --git a/clients/cli/meson.build b/clients/cli/meson.build deleted file mode 100644 index 65317a0a..00000000 --- a/clients/cli/meson.build +++ /dev/null @@ -1,48 +0,0 @@ -name = 'nmcli' - -# FIXME: nmcli-completion should be renamed to nmcli -install_data( - 'nmcli-completion', - install_dir: join_paths(nm_datadir, 'bash-completion', 'completions') -) - -sources = files( - 'agent.c', - 'common.c', - 'connections.c', - 'devices.c', - 'general.c', - 'nmcli.c', - 'polkit-agent.c', - 'settings.c', - 'utils.c' -) - -deps = [ - libnm_dep, - libnmc_base_dep, - libnmc_dep, - nm_core_dep, - readline_dep -] - -cflags = clients_cflags + [ - '-DG_LOG_DOMAIN="@0@"'.format(name), - '-DNMCLI_LOCALEDIR="@0@"'.format(nm_localedir) -] - -if enable_polkit_agent - sources += nm_polkit_listener - - deps += polkit_agent_dep -endif - -executable( - name, - sources, - dependencies: deps, - c_args: cflags, - link_args: ldflags_linker_script_binary, - link_depends: linker_script_binary, - install: true -) diff --git a/clients/cli/nmcli.c b/clients/cli/nmcli.c index ec23ff43..f5a66cdd 100644 --- a/clients/cli/nmcli.c +++ b/clients/cli/nmcli.c @@ -36,6 +36,8 @@ #include "nm-client-utils.h" +#include "nm-utils/nm-hash-utils.h" + #include "polkit-agent.h" #include "utils.h" #include "common.h" @@ -184,7 +186,6 @@ usage (void) g_printerr (_("Usage: nmcli [OPTIONS] OBJECT { COMMAND | help }\n" "\n" "OPTIONS\n" - " -o[verview] overview mode (hide default values)\n" " -t[erse] terse output\n" " -p[retty] pretty output\n" " -m[ode] tabular|multiline output mode\n" @@ -296,10 +297,9 @@ process_command_line (NmCli *nmc, int argc, char **argv) break; if (argc == 1 && nmc->complete) { - nmc_complete_strings (argv[0], "--terse", "--pretty", "--mode", "--overview", - "--colors", "--escape", - "--fields", "--nocheck", "--get-values", - "--wait", "--version", "--help", NULL); + nmc_complete_strings (argv[0], "--terse", "--pretty", "--mode", "--colors", "--escape", + "--fields", "--nocheck", "--get-values", + "--wait", "--version", "--help", NULL); } if (argv[0][1] == '-' && argv[0][2] == '\0') { @@ -308,9 +308,7 @@ process_command_line (NmCli *nmc, int argc, char **argv) break; } - if (matches_arg (nmc, &argc, &argv, "-overview", NULL)) { - nmc->nmc_config_mutable.overview = TRUE; - } else if (matches_arg (nmc, &argc, &argv, "-terse", NULL)) { + if (matches_arg (nmc, &argc, &argv, "-terse", NULL)) { if (nmc->nmc_config.print_output == NMC_PRINT_TERSE) { g_string_printf (nmc->return_text, _("Error: Option '--terse' is specified the second time.")); nmc->return_value = NMC_RESULT_ERROR_USER_INPUT; @@ -419,10 +417,6 @@ process_command_line (NmCli *nmc, int argc, char **argv) next_arg (nmc, &argc, &argv, NULL); } - /* Ignore --overview when fields are set explicitly */ - if (nmc->required_fields) - nmc->nmc_config_mutable.overview = FALSE; - /* Now run the requested command */ nmc_do_cmd (nmc, nmcli_cmds, *argv, argc, argv); @@ -635,6 +629,8 @@ main (int argc, char *argv[]) textdomain (GETTEXT_PACKAGE); #endif + nm_g_type_init (); + /* Save terminal settings */ tcgetattr (STDIN_FILENO, &termios_orig); diff --git a/clients/cli/nmcli.h b/clients/cli/nmcli.h index 0f3d29cd..874bca21 100644 --- a/clients/cli/nmcli.h +++ b/clients/cli/nmcli.h @@ -20,10 +20,17 @@ #ifndef NMC_NMCLI_H #define NMC_NMCLI_H +#include "NetworkManager.h" #include "nm-secret-agent-old.h" + #include "nm-meta-setting-desc.h" -struct _NMPolkitListener; +#if WITH_POLKIT_AGENT +#include "nm-polkit-listener.h" +#else +/* polkit agent is not available; define fake NMPolkitListener */ +typedef gpointer NMPolkitListener; +#endif typedef char *(*NmcCompEntryFunc) (const char *, int); @@ -110,7 +117,6 @@ typedef struct _NmcConfig { bool escape_values; /* Whether to escape ':' and '\' in terse tabular mode */ bool in_editor; /* Whether running the editor - nmcli con edit' */ bool show_secrets; /* Whether to display secrets (both input and output): option '--show-secrets' */ - bool overview; /* Overview mode (hide default values) */ } NmcConfig; typedef struct _NmcOutputData { @@ -129,7 +135,7 @@ typedef struct _NmCli { NMSecretAgentOld *secret_agent; /* Secret agent */ GHashTable *pwds_hash; /* Hash table with passwords in passwd-file */ - struct _NMPolkitListener *pk_listener; /* polkit agent listener */ + NMPolkitListener *pk_listener ; /* polkit agent listener */ int should_wait; /* Semaphore indicating whether nmcli should not end or not yet */ gboolean nowait_flag; /* '--nowait' option; used for passing to callbacks */ diff --git a/clients/cli/polkit-agent.c b/clients/cli/polkit-agent.c index 338f0b15..ecd58ba5 100644 --- a/clients/cli/polkit-agent.c +++ b/clients/cli/polkit-agent.c @@ -19,6 +19,8 @@ #include "nm-default.h" +#if WITH_POLKIT_AGENT + #include "polkit-agent.h" #include @@ -27,18 +29,17 @@ #include #include "nm-polkit-listener.h" + #include "common.h" -#if WITH_POLKIT_AGENT static char * -polkit_request (NMPolkitListener *listener, - const char *request, +polkit_request (const char *request, const char *action_id, const char *message, const char *icon_name, const char *user, gboolean echo_on, - gpointer user_data) + gpointer user_data) { char *response, *tmp, *p; @@ -61,42 +62,28 @@ polkit_request (NMPolkitListener *listener, } static void -polkit_show_info (NMPolkitListener *listener, - const char *text, - gpointer user_data) +polkit_show_info (const char *text) { g_print (_("Authentication message: %s\n"), text); } static void -polkit_show_error (NMPolkitListener *listener, - const char *text, - gpointer user_data) +polkit_show_error (const char *text) { g_print (_("Authentication error: %s\n"), text); } static void -polkit_completed (NMPolkitListener *listener, - gboolean gained_authorization, - gpointer user_data) +polkit_completed (gboolean gained_authorization) { /* We don't print anything here. The outcome will be evident from * the operation result anyway. */ } -#endif gboolean nmc_polkit_agent_init (NmCli* nmc, gboolean for_session, GError **error) { -#if WITH_POLKIT_AGENT - static const NMPolkitListenVtable vtable = { - .on_request = polkit_request, - .on_show_info = polkit_show_info, - .on_show_error = polkit_show_error, - .on_completed = polkit_completed, - }; - NMPolkitListener *listener; + PolkitAgentListener *listener; g_return_val_if_fail (error == NULL || *error == NULL, FALSE); @@ -104,28 +91,24 @@ nmc_polkit_agent_init (NmCli* nmc, gboolean for_session, GError **error) if (!listener) return FALSE; - nm_polkit_listener_set_vtable (listener, &vtable, nmc); + nm_polkit_listener_set_request_callback (NM_POLKIT_LISTENER (listener), polkit_request, nmc); + nm_polkit_listener_set_show_info_callback (NM_POLKIT_LISTENER (listener), polkit_show_info); + nm_polkit_listener_set_show_error_callback (NM_POLKIT_LISTENER (listener), polkit_show_error); + nm_polkit_listener_set_completed_callback (NM_POLKIT_LISTENER (listener), polkit_completed); - nmc->pk_listener = listener; -#endif + nmc->pk_listener = NM_POLKIT_LISTENER (listener); return TRUE; } void nmc_polkit_agent_fini (NmCli* nmc) { -#if WITH_POLKIT_AGENT - if (nmc->pk_listener) { - nm_polkit_listener_set_vtable (nmc->pk_listener, NULL, NULL); - g_clear_object (&nmc->pk_listener); - } -#endif + g_clear_object (&nmc->pk_listener); } gboolean nmc_start_polkit_agent_start_try (NmCli *nmc) { -#if WITH_POLKIT_AGENT GError *error = NULL; /* We don't register polkit agent at all when running non-interactively */ @@ -138,6 +121,30 @@ nmc_start_polkit_agent_start_try (NmCli *nmc) g_error_free (error); return FALSE; } -#endif return TRUE; } + +#else +/* polkit agent is not avalable; implement stub functions. */ + +#include "nmcli.h" +#include "polkit-agent.h" + +gboolean +nmc_polkit_agent_init (NmCli* nmc, gboolean for_session, GError **error) +{ + return TRUE; +} + +void +nmc_polkit_agent_fini (NmCli* nmc) +{ +} + +gboolean +nmc_start_polkit_agent_start_try (NmCli *nmc) +{ + return TRUE; +} + +#endif /* #if WITH_POLKIT_AGENT */ diff --git a/clients/cli/settings.c b/clients/cli/settings.c index 5c3deead..69275aad 100644 --- a/clients/cli/settings.c +++ b/clients/cli/settings.c @@ -313,18 +313,16 @@ _set_fcn_precheck_connection_secondaries (const char *value, { const GPtrArray *connections; NMConnection *con; - gs_free const char **strv0 = NULL; gs_strfreev char **strv = NULL; char **iter; - gboolean modified = FALSE; + gboolean modified; - strv0 = nm_utils_strsplit_set (value, " \t,"); - if (!strv0) + strv = nmc_strsplit_set (value, " \t,", 0); + if (!strv) return TRUE; connections = nm_client_get_connections (nm_cli.client); - strv = g_strdupv ((char **) strv0); for (iter = strv; *iter; iter++) { if (nm_utils_is_uuid (*iter)) { con = nmc_find_connection (connections, "uuid", *iter, NULL, FALSE); @@ -474,7 +472,6 @@ get_property_val (NMSetting *setting, const char *prop, NMMetaAccessorGetType ge get_type, show_secrets ? NM_META_ACCESSOR_GET_FLAGS_SHOW_SECRETS : 0, &out_flags, - NULL, (gpointer *) &to_free); nm_assert (!out_flags); return to_free ?: g_strdup (value); diff --git a/clients/cli/utils.c b/clients/cli/utils.c index 71fdcf30..f20e24ce 100644 --- a/clients/cli/utils.c +++ b/clients/cli/utils.c @@ -75,7 +75,6 @@ _meta_type_nmc_generic_info_get_fcn (const NMMetaAbstractInfo *abstract_info, NMMetaAccessorGetType get_type, NMMetaAccessorGetFlags get_flags, NMMetaAccessorGetOutFlags *out_flags, - gboolean *out_is_default, gpointer *out_to_free) { const NmcMetaGenericInfo *info = (const NmcMetaGenericInfo *) abstract_info; @@ -98,7 +97,6 @@ _meta_type_nmc_generic_info_get_fcn (const NMMetaAbstractInfo *abstract_info, get_type, get_flags, out_flags, - out_is_default, out_to_free); } @@ -526,7 +524,7 @@ nmc_count_color_escape_chars (const char *start, const char *end) inside = TRUE; if (inside) num++; - if (*start == 'm') + if (*start == 'm') inside = FALSE; start++; } @@ -605,14 +603,9 @@ int nmc_string_to_arg_array (const char *line, const char *delim, gboolean unquote, char ***argv, int *argc) { - gs_free const char **arr0 = NULL; char **arr; - arr0 = nm_utils_strsplit_set (line ?: "", delim ?: " \t"); - if (!arr0) - arr = g_new0 (char *, 1); - else - arr = g_strdupv ((char **) arr0); + arr = nmc_strsplit_set (line ? line : "", delim ? delim : " \t", 0); if (unquote) { int i = 0; @@ -620,7 +613,7 @@ nmc_string_to_arg_array (const char *line, const char *delim, gboolean unquote, size_t l; const char *quotes = "\"'"; - while (arr[i]) { + while (arr && arr[i]) { s = arr[i]; l = strlen (s); if (l >= 2) { @@ -635,6 +628,7 @@ nmc_string_to_arg_array (const char *line, const char *delim, gboolean unquote, *argv = arr; *argc = g_strv_length (arr); + return 0; } @@ -1004,7 +998,6 @@ typedef struct { const PrintDataCol *col; const char *title; bool title_to_free:1; - bool skip:1; int width; } PrintDataHeaderCell; @@ -1103,7 +1096,6 @@ _print_fill (const NmcConfig *nmc_config, header_cell->col_idx = col_idx; header_cell->col = col; - header_cell->skip = FALSE; header_cell->title = nm_meta_abstract_info_get_name (info, TRUE); if ( nmc_config->multiline_output @@ -1138,11 +1130,10 @@ _print_fill (const NmcConfig *nmc_config, for (i_col = 0; i_col < header_row->len; i_col++) { char *to_free = NULL; PrintDataCell *cell = &cells_line[i_col]; - PrintDataHeaderCell *header_cell; + const PrintDataHeaderCell *header_cell; const NMMetaAbstractInfo *info; NMMetaAccessorGetOutFlags text_out_flags, color_out_flags; gconstpointer value; - gboolean is_default; header_cell = &g_array_index (header_row, PrintDataHeaderCell, i_col); info = header_cell->col->selection_item->info; @@ -1157,11 +1148,7 @@ _print_fill (const NmcConfig *nmc_config, text_get_type, text_get_flags, &text_out_flags, - &is_default, (gpointer *) &to_free); - - header_cell->skip = nmc_config->overview && is_default; - if (NM_FLAGS_HAS (text_out_flags, NM_META_ACCESSOR_GET_OUT_FLAGS_STRV)) { if (value) { if (nmc_config->multiline_output) { @@ -1187,7 +1174,6 @@ _print_fill (const NmcConfig *nmc_config, NM_META_ACCESSOR_GET_TYPE_TERMFORMAT, NM_META_ACCESSOR_GET_FLAGS_NONE, &color_out_flags, - NULL, NULL), &cell->term_color, &cell->term_format); @@ -1245,9 +1231,6 @@ _print_skip_column (const NmcConfig *nmc_config, selection_item = header_cell->col->selection_item; info = selection_item->info; - if (header_cell->skip) - return TRUE; - if (nmc_config->multiline_output) { if (info->meta_type == &nm_meta_type_setting_info_editor) { /* we skip the "name" entry for the setting in multiline output. */ diff --git a/clients/cli/utils.h b/clients/cli/utils.h index c92c4e2e..ffc5b6f3 100644 --- a/clients/cli/utils.h +++ b/clients/cli/utils.h @@ -53,6 +53,7 @@ int nmc_string_to_arg_array (const char *line, const char *delim, gboolean unquo char ***argv, int *argc); const char *nmc_string_is_valid (const char *input, const char **allowed, GError **error); char * nmc_util_strv_for_display (const char *const*strv, gboolean brackets); +char **nmc_strsplit_set (const char *str, const char *delimiter, int max_tokens); int nmc_string_screen_width (const char *start, const char *end); void set_val_str (NmcOutputField fields_array[], guint32 index, char *value); void set_val_strc (NmcOutputField fields_array[], guint32 index, const char *value); @@ -150,7 +151,6 @@ struct _NmcMetaGenericInfo { NMMetaAccessorGetType get_type, NMMetaAccessorGetFlags get_flags, NMMetaAccessorGetOutFlags *out_flags, - gboolean *out_is_default, gpointer *out_to_free); }; diff --git a/clients/common/meson.build b/clients/common/meson.build deleted file mode 100644 index ea26bccf..00000000 --- a/clients/common/meson.build +++ /dev/null @@ -1,81 +0,0 @@ -common_inc = include_directories('.') - -nm_polkit_listener = files('nm-polkit-listener.c') - -deps = [ - libnm_dep, - nm_core_dep -] - -cflags = clients_cflags + [ - '-DG_LOG_DOMAIN="libnmc"', -] - -sources = shared_utils + files( - 'nm-client-utils.c', - 'nm-secret-agent-simple.c', - 'nm-vpn-helpers.c' -) - -libnmc_base = static_library( - 'nmc-base', - sources: sources, - dependencies: deps, - c_args: cflags -) - -libnmc_base_dep = declare_dependency( - include_directories: common_inc, - link_with: libnmc_base -) - -sources = shared_meta_setting + files( - 'nm-meta-setting-access.c', - 'nm-meta-setting-desc.c' -) - -settings_docs = 'settings-docs.h' - -if enable_introspection - settings_docs_source = custom_target( - settings_docs, - input: nm_property_docs, - output: settings_docs, - command: [xsltproc, '--output', '@OUTPUT@', join_paths(meson.current_source_dir(), 'settings-docs.xsl'), '@INPUT@'] - ) - - # FIXME: if enabled the check happens even if the settings_docs_source is not set - ''' - if get_option('check_settings_docs') - res = run_command(find_program('cmp'), '-s', settings_docs + '.in', settings_docs_source.full_path()) - if res.returncode() != 0 - message('The generated file ' + settings_docs_source.full_path() + ' differs from the source file ' + settings_docs + '.in' + '. You probably should copy the generated file over to the source file. You can skip this test by setting -Dcheck_settings_docs=false') - endif - endif - ''' -else - settings_docs_source = configure_file( - input: settings_docs + '.in', - output: settings_docs, - configuration: configuration_data() - ) -endif -sources += settings_docs_source - -libnmc = static_library( - 'nmc', - sources: sources, - dependencies: deps, - c_args: cflags, - link_with: libnmc_base, - link_depends: settings_docs_source -) - -libnmc_dep = declare_dependency( - include_directories: common_inc, - link_with: libnmc -) - -if (enable_introspection or enable_nmtui) and enable_tests - subdir('tests') -endif diff --git a/clients/common/nm-client-utils.c b/clients/common/nm-client-utils.c index b4b4c1b9..b6ec92de 100644 --- a/clients/common/nm-client-utils.c +++ b/clients/common/nm-client-utils.c @@ -20,7 +20,6 @@ #include "nm-default.h" #include "nm-client-utils.h" -#include "nm-utils.h" #include "nm-device-bond.h" #include "nm-device-bridge.h" @@ -70,7 +69,7 @@ nmc_string_to_bool (const char *str, gboolean *val_bool, GError **error) if (g_strcmp0 (str, "o") == 0) { g_set_error (error, 1, 0, - /* TRANSLATORS: the first %s is the partial value entered by + /* Translators: the first %s is the partial value entered by * the user, the second %s a list of compatible values. */ _("'%s' is ambiguous (%s)"), str, "on x off"); @@ -101,7 +100,7 @@ nmc_string_to_tristate (const char *str, NMCTriStateValue *val, GError **error) if (g_strcmp0 (str, "o") == 0) { g_set_error (error, 1, 0, - /* TRANSLATORS: the first %s is the partial value entered by + /* Translators: the first %s is the partial value entered by * the user, the second %s a list of compatible values. */ _("'%s' is ambiguous (%s)"), str, "on x off"); @@ -134,7 +133,7 @@ nmc_string_is_valid (const char *input, const char **allowed, GError **error) { const char **p; size_t input_ln, p_len; - gboolean prev_match = FALSE, ambiguous = FALSE; + gboolean prev_match = FALSE; const char *ret = NULL; g_return_val_if_fail (error == NULL || *error == NULL, NULL); @@ -148,21 +147,19 @@ nmc_string_is_valid (const char *input, const char **allowed, GError **error) if (g_ascii_strncasecmp (input, *p, input_ln) == 0) { if (input_ln == p_len) { ret = *p; - ambiguous = FALSE; break; } - if (!prev_match) { + if (!prev_match) ret = *p; - prev_match = TRUE; - } else - ambiguous = TRUE; + else { + g_set_error (error, 1, 1, _("'%s' is ambiguous (%s x %s)"), + input, ret, *p); + return NULL; + } + prev_match = TRUE; } } - if (ambiguous) { - g_set_error (error, 1, 1, _("'%s' is ambiguous (%s x %s)"), - input, ret, *p); - return NULL; - } + finish: if (ret == NULL) { char *valid_vals = g_strjoinv (", ", (char **) allowed); @@ -176,6 +173,18 @@ finish: return ret; } +/* + * Wrapper function for g_strsplit_set() that removes empty strings + * from the vector as they are not useful in most cases. + */ +char ** +nmc_strsplit_set (const char *str, const char *delimiter, int max_tokens) +{ + /* remove empty strings */ + return _nm_utils_strv_cleanup (g_strsplit_set (str, delimiter, max_tokens), + FALSE, TRUE, FALSE); +} + gboolean matches (const char *cmd, const char *pattern) { @@ -509,72 +518,3 @@ nmc_activation_get_effective_state (NMActiveConnection *active, return ac_state; } - -static gboolean -can_show_graphics (void) -{ - static gboolean can_show_graphics_set = FALSE; - gboolean can_show_graphics = TRUE; - char *locale_str; - - if (G_LIKELY (can_show_graphics_set)) - return can_show_graphics; - - if (!g_get_charset (NULL)) { - /* Non-UTF-8 locale */ - locale_str = g_locale_from_utf8 ("\342\226\202\342\226\204\342\226\206\342\226\210", -1, NULL, NULL, NULL); - if (locale_str) - g_free (locale_str); - else - can_show_graphics = FALSE; - } - - /* The linux console font typically doesn't have characters we need */ - if (g_strcmp0 (g_getenv ("TERM"), "linux") == 0) - can_show_graphics = FALSE; - - return can_show_graphics; -} - -/** - * nmc_wifi_strength_bars: - * @strength: the access point strength, from 0 to 100 - * - * Converts @strength into a 4-character-wide graphical representation of - * strength suitable for printing to stdout. If the current locale and terminal - * support it, this will use unicode graphics characters to represent - * "bars". Otherwise it will use 0 to 4 asterisks. - * - * Returns: the graphical representation of the access point strength - */ -const char * -nmc_wifi_strength_bars (guint8 strength) -{ - if (!can_show_graphics ()) - return nm_utils_wifi_strength_bars (strength); - - if (strength > 80) - return /* ▂▄▆█ */ "\342\226\202\342\226\204\342\226\206\342\226\210"; - else if (strength > 55) - return /* ▂▄▆_ */ "\342\226\202\342\226\204\342\226\206_"; - else if (strength > 30) - return /* ▂▄__ */ "\342\226\202\342\226\204__"; - else if (strength > 5) - return /* ▂___ */ "\342\226\202___"; - else - return /* ____ */ "____"; -} - -/** - * nmc_utils_password_subst_char: - * - * Returns: the string substituted when hiding actual password glyphs - */ -const char * -nmc_password_subst_char (void) -{ - if (can_show_graphics ()) - return "\u2022"; /* Bullet */ - else - return "*"; -} diff --git a/clients/common/nm-client-utils.h b/clients/common/nm-client-utils.h index cd662765..ac18fe94 100644 --- a/clients/common/nm-client-utils.h +++ b/clients/common/nm-client-utils.h @@ -32,6 +32,8 @@ typedef enum { const char *nmc_string_is_valid (const char *input, const char **allowed, GError **error); +char **nmc_strsplit_set (const char *str, const char *delimiter, int max_tokens); + gboolean nmc_string_to_uint (const char *str, gboolean range_check, unsigned long int min, @@ -42,7 +44,7 @@ gboolean nmc_string_to_tristate (const char *str, NMCTriStateValue *val, GError gboolean matches (const char *cmd, const char *pattern); -/* FIXME: don't expose this function on its own, at least not from this file. */ +/* FIXME: don't expose this function on it's own, at least not from this file. */ const char *nmc_bond_validate_mode (const char *mode, GError **error); const char *nm_active_connection_state_reason_to_string (NMActiveConnectionStateReason reason); @@ -54,8 +56,4 @@ NMActiveConnectionState nmc_activation_get_effective_state (NMActiveConnection * NMDevice *device, const char **reason); -const char *nmc_wifi_strength_bars (guint8 strength); - -const char *nmc_password_subst_char (void); - #endif /* __NM_CLIENT_UTILS_H__ */ diff --git a/clients/common/nm-meta-setting-access.c b/clients/common/nm-meta-setting-access.c index a1bfed47..cd7ef783 100644 --- a/clients/common/nm-meta-setting-access.c +++ b/clients/common/nm-meta-setting-access.c @@ -232,7 +232,6 @@ nm_meta_abstract_info_get (const NMMetaAbstractInfo *abstract_info, NMMetaAccessorGetType get_type, NMMetaAccessorGetFlags get_flags, NMMetaAccessorGetOutFlags *out_flags, - gboolean *out_is_default, gpointer *out_to_free) { nm_assert (abstract_info); @@ -241,7 +240,6 @@ nm_meta_abstract_info_get (const NMMetaAbstractInfo *abstract_info, nm_assert (out_flags); *out_flags = NM_META_ACCESSOR_GET_OUT_FLAGS_NONE; - NM_SET_OUT (out_is_default, FALSE); if (!abstract_info->meta_type->get_fcn) g_return_val_if_reached (NULL); @@ -253,7 +251,6 @@ nm_meta_abstract_info_get (const NMMetaAbstractInfo *abstract_info, get_type, get_flags, out_flags, - out_is_default, out_to_free); } diff --git a/clients/common/nm-meta-setting-access.h b/clients/common/nm-meta-setting-access.h index 577cad78..54fc6c84 100644 --- a/clients/common/nm-meta-setting-access.h +++ b/clients/common/nm-meta-setting-access.h @@ -58,7 +58,6 @@ gconstpointer nm_meta_abstract_info_get (const NMMetaAbstractInfo *abstract_info NMMetaAccessorGetType get_type, NMMetaAccessorGetFlags get_flags, NMMetaAccessorGetOutFlags *out_flags, - gboolean *out_is_default, gpointer *out_to_free); const char *const*nm_meta_abstract_info_complete (const NMMetaAbstractInfo *abstract_info, diff --git a/clients/common/nm-meta-setting-desc.c b/clients/common/nm-meta-setting-desc.c index ede95a10..94404e90 100644 --- a/clients/common/nm-meta-setting-desc.c +++ b/clients/common/nm-meta-setting-desc.c @@ -25,8 +25,10 @@ #include #include "nm-common-macros.h" +#include "nm-utils/nm-hash-utils.h" #include "nm-utils/nm-enum-utils.h" +#include "NetworkManager.h" #include "nm-vpn-helpers.h" #include "nm-client-utils.h" #include "nm-meta-setting-access.h" @@ -116,6 +118,7 @@ _parse_ip_route (int family, GError **error) { const int MAX_PREFIX = (family == AF_INET) ? 32 : 128; + char *plen = NULL; const char *next_hop = NULL; const char *canon_dest; int prefix; @@ -123,11 +126,9 @@ _parse_ip_route (int family, GError *local = NULL; gint64 metric = -1; guint i; - gs_free const char **routev = NULL; + gs_strfreev char **routev = NULL; gs_free char *str_clean = NULL; - gs_free char *dest_clone = NULL; - const char *dest; - const char *plen; + char *dest; gs_unref_hashtable GHashTable *attrs = NULL; GHashTable *tmp_attrs; #define ROUTE_SYNTAX _("The valid syntax is: 'ip[/prefix] [next-hop] [metric] [attribute=val]... [,ip[/prefix] ...]'") @@ -137,8 +138,8 @@ _parse_ip_route (int family, nm_assert (!error || !*error); str_clean = g_strstrip (g_strdup (str)); - routev = nm_utils_strsplit_set (str_clean, " \t"); - if (!routev) { + routev = nmc_strsplit_set (str_clean, " \t", 0); + if (!routev || !routev[0]) { g_set_error (error, 1, 0, "'%s' is not valid. %s", str, ROUTE_SYNTAX); @@ -147,13 +148,8 @@ _parse_ip_route (int family, dest = routev[0]; plen = strchr (dest, '/'); /* prefix delimiter */ - if (plen) { - dest_clone = g_strdup (dest); - plen = &dest_clone[plen - dest]; - dest = dest_clone; - *((char *) plen) = '\0'; - plen++; - } + if (plen) + *plen++ = '\0'; prefix = MAX_PREFIX; if (plen) { if ((prefix = _nm_utils_ascii_str_to_int64 (plen, 10, 1, MAX_PREFIX, -1)) == -1) { @@ -300,7 +296,7 @@ static NMTeamLinkWatcher * _parse_team_link_watcher (const char *str, GError **error) { - gs_free const char **watcherv = NULL; + gs_strfreev char **watcherv = NULL; gs_free char *str_clean = NULL; guint i; gs_free const char *name = NULL; @@ -313,17 +309,17 @@ _parse_team_link_watcher (const char *str, nm_assert (!error || !*error); str_clean = g_strstrip (g_strdup (str)); - watcherv = nm_utils_strsplit_set (str_clean, " \t"); - if (!watcherv) { + watcherv = nmc_strsplit_set (str_clean, " \t", 0); + if (!watcherv || !watcherv[0]) { g_set_error (error, 1, 0, "'%s' is not valid", str); return NULL; } for (i = 0; watcherv[i]; i++) { - gs_free const char **pair = NULL; + gs_strfreev char **pair = NULL; - pair = nm_utils_strsplit_set (watcherv[i], "="); - if (!pair) { + pair = nmc_strsplit_set (watcherv[i], "=", 0); + if (!pair[0]) { g_set_error (error, 1, 0, "'%s' is not valid: %s", watcherv[i], "properties should be specified as 'key=value'"); return NULL; @@ -640,7 +636,7 @@ _env_warn_fcn (const NMMetaEnvironment *environment, const NMMetaPropertyInfo *property_info, char **out_to_free #define ARGS_GET_FCN \ - const NMMetaPropertyInfo *property_info, const NMMetaEnvironment *environment, gpointer environment_user_data, NMSetting *setting, NMMetaAccessorGetType get_type, NMMetaAccessorGetFlags get_flags, NMMetaAccessorGetOutFlags *out_flags, gboolean *out_is_default, gpointer *out_to_free + const NMMetaPropertyInfo *property_info, const NMMetaEnvironment *environment, gpointer environment_user_data, NMSetting *setting, NMMetaAccessorGetType get_type, NMMetaAccessorGetFlags get_flags, NMMetaAccessorGetOutFlags *out_flags, gpointer *out_to_free #define ARGS_SET_FCN \ const NMMetaPropertyInfo *property_info, const NMMetaEnvironment *environment, gpointer environment_user_data, NMSetting *setting, const char *value, GError **error @@ -673,33 +669,6 @@ _env_warn_fcn (const NMMetaEnvironment *environment, return ((*(out_to_free)) = _val); \ } G_STMT_END -static gboolean -property_is_default (NMSetting *setting, const char *prop_name) -{ - nm_auto_unset_gvalue GValue v = G_VALUE_INIT; - GParamSpec *pspec; - GHashTable *ht; - char **strv; - - pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (G_OBJECT (setting)), - prop_name); - if (!G_IS_PARAM_SPEC (pspec)) - g_return_val_if_reached (FALSE); - - g_value_init (&v, pspec->value_type); - g_object_get_property (G_OBJECT (setting), prop_name, &v); - - if (pspec->value_type == G_TYPE_STRV) { - strv = g_value_get_boxed (&v); - return !strv || !strv[0]; - } else if (pspec->value_type == G_TYPE_HASH_TABLE) { - ht = g_value_get_boxed (&v); - return !ht || !g_hash_table_size (ht); - } - - return g_param_value_defaults (pspec, &v); -} - static gconstpointer _get_fcn_nmc_with_default (ARGS_GET_FCN) { @@ -708,7 +677,6 @@ _get_fcn_nmc_with_default (ARGS_GET_FCN) GValue val = G_VALUE_INIT; RETURN_UNSUPPORTED_GET_TYPE (); - NM_SET_OUT (out_is_default, property_is_default (setting, property_info->property_name)); if (property_info->property_typ_data->subtype.get_with_default.fcn (setting)) { if (get_type == NM_META_ACCESSOR_GET_TYPE_PRETTY) @@ -724,7 +692,6 @@ _get_fcn_nmc_with_default (ARGS_GET_FCN) else s_full = g_strdup (s && *s ? s : " "); g_value_unset (&val); - RETURN_STR_TO_FREE (s_full); } @@ -732,7 +699,6 @@ static gconstpointer _get_fcn_gobject_impl (const NMMetaPropertyInfo *property_info, NMSetting *setting, NMMetaAccessorGetType get_type, - gboolean *out_is_default, gpointer *out_to_free) { char *s; @@ -741,7 +707,6 @@ _get_fcn_gobject_impl (const NMMetaPropertyInfo *property_info, nm_auto_unset_gvalue GValue val = G_VALUE_INIT; RETURN_UNSUPPORTED_GET_TYPE (); - NM_SET_OUT (out_is_default, property_is_default (setting, property_info->property_name)); gtype_prop = _gobject_property_get_gtype (G_OBJECT (setting), property_info->property_name); @@ -767,13 +732,13 @@ _get_fcn_gobject_impl (const NMMetaPropertyInfo *property_info, static gconstpointer _get_fcn_gobject (ARGS_GET_FCN) { - return _get_fcn_gobject_impl (property_info, setting, get_type, out_is_default, out_to_free); + return _get_fcn_gobject_impl (property_info, setting, get_type, out_to_free); } static gconstpointer _get_fcn_gobject_int (ARGS_GET_FCN) { - GParamSpec *pspec; + const GParamSpec *pspec; nm_auto_unset_gvalue GValue gval = G_VALUE_INIT; gint64 v; const NMMetaUtilsIntValueInfo *value_infos; @@ -786,7 +751,6 @@ _get_fcn_gobject_int (ARGS_GET_FCN) g_value_init (&gval, pspec->value_type); g_object_get_property (G_OBJECT (setting), property_info->property_name, &gval); - NM_SET_OUT (out_is_default, g_param_value_defaults (pspec, &gval)); switch (pspec->value_type) { case G_TYPE_INT: v = g_value_get_int (&gval); @@ -826,11 +790,10 @@ _get_fcn_gobject_mtu (ARGS_GET_FCN) if ( !property_info->property_typ_data || !property_info->property_typ_data->subtype.mtu.get_fcn) - return _get_fcn_gobject_impl (property_info, setting, get_type, out_is_default, out_to_free); + return _get_fcn_gobject_impl (property_info, setting, get_type, out_to_free); mtu = property_info->property_typ_data->subtype.mtu.get_fcn (setting); if (mtu == 0) { - NM_SET_OUT (out_is_default, TRUE); if (get_type == NM_META_ACCESSOR_GET_TYPE_PRETTY) return _("auto"); return "auto"; @@ -857,9 +820,9 @@ static gconstpointer _get_fcn_gobject_enum (ARGS_GET_FCN) { GType gtype = 0; + GType gtype_prop; nm_auto_unref_gtypeclass GTypeClass *gtype_class = NULL; nm_auto_unref_gtypeclass GTypeClass *gtype_prop_class = NULL; - const struct _NMUtilsEnumValueInfo *value_infos = NULL; gboolean has_gtype = FALSE; nm_auto_unset_gvalue GValue gval = G_VALUE_INIT; gint64 v; @@ -870,7 +833,6 @@ _get_fcn_gobject_enum (ARGS_GET_FCN) gboolean format_text_l10n = FALSE; gs_free char *s = NULL; char s_numeric[64]; - GParamSpec *pspec; RETURN_UNSUPPORTED_GET_TYPE (); @@ -913,26 +875,25 @@ _get_fcn_gobject_enum (ARGS_GET_FCN) nm_assert (format_text || format_numeric); - pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (setting), property_info->property_name); - g_return_val_if_fail (pspec, NULL); + gtype_prop = _gobject_property_get_gtype (G_OBJECT (setting), property_info->property_name); + + g_value_init (&gval, gtype_prop); - g_value_init (&gval, pspec->value_type); g_object_get_property (G_OBJECT (setting), property_info->property_name, &gval); - NM_SET_OUT (out_is_default, g_param_value_defaults (pspec, &gval)); - if ( pspec->value_type == G_TYPE_INT - || ( G_TYPE_IS_CLASSED (pspec->value_type) - && G_IS_ENUM_CLASS ((gtype_prop_class ?: (gtype_prop_class = g_type_class_ref (pspec->value_type)))))) { - if (pspec->value_type == G_TYPE_INT) { + if ( gtype_prop == G_TYPE_INT + || ( G_TYPE_IS_CLASSED (gtype_prop) + && G_IS_ENUM_CLASS ((gtype_prop_class ?: (gtype_prop_class = g_type_class_ref (gtype_prop)))))) { + if (gtype_prop == G_TYPE_INT) { if (!has_gtype) g_return_val_if_reached (NULL); v = g_value_get_int (&gval); } else v = g_value_get_enum (&gval); - } else if ( pspec->value_type == G_TYPE_UINT - || ( G_TYPE_IS_CLASSED (pspec->value_type) - && G_IS_FLAGS_CLASS ((gtype_prop_class ?: (gtype_prop_class = g_type_class_ref (pspec->value_type)))))) { - if (pspec->value_type == G_TYPE_UINT) { + } else if ( gtype_prop == G_TYPE_UINT + || ( G_TYPE_IS_CLASSED (gtype_prop) + && G_IS_FLAGS_CLASS ((gtype_prop_class ?: (gtype_prop_class = g_type_class_ref (gtype_prop)))))) { + if (gtype_prop == G_TYPE_UINT) { if (!has_gtype) g_return_val_if_reached (NULL); v = g_value_get_uint (&gval); @@ -942,7 +903,7 @@ _get_fcn_gobject_enum (ARGS_GET_FCN) g_return_val_if_reached (NULL); if (!has_gtype) { - gtype = pspec->value_type; + gtype = gtype_prop; gtype_class = g_steal_pointer (>ype_prop_class); } @@ -966,9 +927,7 @@ _get_fcn_gobject_enum (ARGS_GET_FCN) /* the gobject_enum.value_infos are currently ignored for the getter. They * only declare additional aliases for the setter. */ - if (property_info->property_typ_data) - value_infos = property_info->property_typ_data->subtype.gobject_enum.value_infos_get; - s = _nm_utils_enum_to_str_full (gtype, (int) v, ", ", value_infos); + s = nm_utils_enum_to_str (gtype, (int) v); if (!format_numeric) RETURN_STR_TO_FREE (g_steal_pointer (&s)); @@ -1209,6 +1168,39 @@ _set_fcn_gobject_mac (ARGS_SET_FCN) return TRUE; } +static gboolean +_set_fcn_gobject_secret_flags (ARGS_SET_FCN) +{ + char **strv = NULL, **iter; + unsigned long flags = 0, val_int; + + g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + + strv = nmc_strsplit_set (value, " \t,", 0); + for (iter = strv; iter && *iter; iter++) { + if (!nmc_string_to_uint (*iter, TRUE, 0, ALL_SECRET_FLAGS, &val_int)) { + g_set_error (error, 1, 0, _("'%s' is not a valid flag number; use <0-%d>"), + *iter, ALL_SECRET_FLAGS); + g_strfreev (strv); + return FALSE; + } + flags += val_int; + } + g_strfreev (strv); + + /* Validate the flags number */ + if (flags > ALL_SECRET_FLAGS) { + flags = ALL_SECRET_FLAGS; + _env_warn_fcn (environment, environment_user_data, + NM_META_ENV_WARN_LEVEL_WARN, + N_("'%s' sum is higher than all flags => all flags set"), + value); + } + + g_object_set (setting, property_info->property_name, (guint) flags, NULL); + return TRUE; +} + static gboolean _set_fcn_gobject_enum (ARGS_SET_FCN) { @@ -1328,7 +1320,7 @@ _values_fcn_gobject_enum (ARGS_VALUES_FCN) gboolean has_minmax = FALSE; int min = G_MININT; int max = G_MAXINT; - char **v; + char **v, **w; if (property_info->property_typ_data) { if ( property_info->property_typ_data->subtype.gobject_enum.min @@ -1362,7 +1354,11 @@ _values_fcn_gobject_enum (ARGS_VALUES_FCN) /* the gobject_enum.value_infos are currently ignored for the list of * values. They only declare additional (hidden) aliases for the setter. */ - v = nm_utils_strv_make_deep_copied (nm_utils_enum_get_values (gtype, min, max)); + v = (char **) nm_utils_enum_get_values (gtype, min, max); + if (v) { + for (w = v; *w; w++) + *w = g_strdup (*w); + } return (const char *const*) (*out_to_free = v); } @@ -1509,6 +1505,24 @@ vlan_priorities_to_string (NMSettingVlan *s_vlan, NMVlanPriorityMap map) return g_string_free (priorities, FALSE); } +static char * +ip6_privacy_to_string (NMSettingIP6ConfigPrivacy ip6_privacy, NMMetaAccessorGetType get_type) +{ + if (get_type != NM_META_ACCESSOR_GET_TYPE_PRETTY) + return g_strdup_printf ("%d", ip6_privacy); + + switch (ip6_privacy) { + case NM_SETTING_IP6_CONFIG_PRIVACY_DISABLED: + return g_strdup_printf (_("%d (disabled)"), ip6_privacy); + case NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_PUBLIC_ADDR: + return g_strdup_printf (_("%d (enabled, prefer public IP)"), ip6_privacy); + case NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_TEMP_ADDR: + return g_strdup_printf (_("%d (enabled, prefer temporary IP)"), ip6_privacy); + default: + return g_strdup_printf (_("%d (unknown)"), ip6_privacy); + } +} + static char * secret_flags_to_string (guint32 flags, NMMetaAccessorGetType get_type) { @@ -1559,19 +1573,18 @@ vpn_data_item (const char *key, const char *value, gpointer user_data) const char **valid_strv, \ GError **error) \ { \ - gs_free const char **strv = NULL; \ - gsize i; \ + char **strv = NULL, **iter; \ const char *item; \ - nm_assert (!error || !*error); \ - strv = nm_utils_strsplit_set (value, " \t,"); \ - if (strv) { \ - for (i = 0; strv[i]; i++) { \ - if (!(item = nmc_string_is_valid (strv[i], valid_strv, error))) { \ - return FALSE; \ - } \ - set_func (s_macro (setting), item); \ + g_return_val_if_fail (error == NULL || *error == NULL, FALSE); \ + strv = nmc_strsplit_set (value, " \t,", 0); \ + for (iter = strv; iter && *iter; iter++) { \ + if (!(item = nmc_string_is_valid (g_strstrip (*iter), valid_strv, error))) { \ + g_strfreev (strv); \ + return FALSE; \ } \ + set_func (s_macro (setting), item); \ } \ + g_strfreev (strv); \ return TRUE; \ } @@ -1579,42 +1592,43 @@ vpn_data_item (const char *key, const char *value, gpointer user_data) static gboolean \ def_func (ARGS_SET_FCN) \ { \ - gs_free const char **strv = NULL; \ - const char **iter; \ + char **strv = NULL, **iter; \ const char **(*valid_func1_p) (s_type *) = valid_func1; \ const char * (*valid_func2_p) (const char *, const char *, GError **) = valid_func2; \ const char *opt_name, *opt_val; \ \ - nm_assert (!error || !*error); \ + g_return_val_if_fail (error == NULL || *error == NULL, FALSE); \ \ - strv = nm_utils_strsplit_set (value, ","); \ + strv = nmc_strsplit_set (value, ",", 0); \ for (iter = strv; iter && *iter; iter++) { \ - gs_free char *left_clone = g_strstrip (g_strdup (*iter)); \ - char *left = left_clone; \ + char *left = g_strstrip (*iter); \ char *right = strchr (left, '='); \ if (!right) { \ g_set_error (error, 1, 0, _("'%s' is not valid; use