diff options
Diffstat (limited to 'clients')
180 files changed, 7104 insertions, 2279 deletions
diff --git a/clients/cli/agent.c b/clients/cli/agent.c index 488b16f4..bbfe47fb 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->name, secret->prop_name); + pwd = nmc_readline ("%s (%s): ", secret->pretty_name, secret->entry_id); /* No password provided, cancel the secrets. */ if (!pwd) @@ -136,7 +136,6 @@ secrets_requested (NMSecretAgentSimple *agent, nm_secret_agent_simple_response (agent, request_id, NULL); } - static NMCResultCode do_agent_secret (NmCli *nmc, int argc, char **argv) { diff --git a/clients/cli/common.c b/clients/cli/common.c index 0f5aea57..e566de47 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 - 2014 Red Hat, Inc. + * Copyright 2012 - 2018 Red Hat, Inc. */ #include "nm-default.h" @@ -26,12 +26,10 @@ #include <stdio.h> #include <stdlib.h> #include <errno.h> -#include <termios.h> #include <sys/ioctl.h> #include <readline/readline.h> #include <readline/history.h> -#include "nm-utils/nm-hash-utils.h" #include "nm-vpn-helpers.h" #include "nm-client-utils.h" @@ -102,24 +100,19 @@ _ip_config_get_routes (NMIPConfig *cfg) } static gconstpointer -_metagen_ip4_config_get_fcn (const NMMetaEnvironment *environment, - gpointer environment_user_data, - const NmcMetaGenericInfo *info, - gpointer target, - NMMetaAccessorGetType get_type, - NMMetaAccessorGetFlags get_flags, - NMMetaAccessorGetOutFlags *out_flags, - gpointer *out_to_free) +_metagen_ip4_config_get_fcn (NMC_META_GENERIC_INFO_GET_FCN_ARGS) { NMIPConfig *cfg4 = target; GPtrArray *ptr_array; 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); + NMC_HANDLE_COLOR (NM_META_COLOR_NONE); + NM_SET_OUT (out_is_default, TRUE); switch (info->info_type) { case NMC_GENERIC_INFO_TYPE_IP4_CONFIG_ADDRESS: @@ -140,7 +133,9 @@ _metagen_ip4_config_get_fcn (const NMMetaEnvironment *environment, arr = NULL; goto arr_out; case NMC_GENERIC_INFO_TYPE_IP4_CONFIG_GATEWAY: - return nm_ip_config_get_gateway (cfg4); + str = nm_ip_config_get_gateway (cfg4); + NM_SET_OUT (out_is_default, !str); + return str; case NMC_GENERIC_INFO_TYPE_IP4_CONFIG_ROUTE: if (!NM_FLAGS_HAS (get_flags, NM_META_ACCESSOR_GET_FLAGS_ACCEPT_STRV)) return NULL; @@ -168,34 +163,31 @@ _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; } static gconstpointer -_metagen_ip6_config_get_fcn (const NMMetaEnvironment *environment, - gpointer environment_user_data, - const NmcMetaGenericInfo *info, - gpointer target, - NMMetaAccessorGetType get_type, - NMMetaAccessorGetFlags get_flags, - NMMetaAccessorGetOutFlags *out_flags, - gpointer *out_to_free) +_metagen_ip6_config_get_fcn (NMC_META_GENERIC_INFO_GET_FCN_ARGS) { NMIPConfig *cfg6 = target; GPtrArray *ptr_array; 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); + NMC_HANDLE_COLOR (NM_META_COLOR_NONE); + NM_SET_OUT (out_is_default, TRUE); switch (info->info_type) { case NMC_GENERIC_INFO_TYPE_IP6_CONFIG_ADDRESS: @@ -216,7 +208,9 @@ _metagen_ip6_config_get_fcn (const NMMetaEnvironment *environment, arr = NULL; goto arr_out; case NMC_GENERIC_INFO_TYPE_IP6_CONFIG_GATEWAY: - return nm_ip_config_get_gateway (cfg6); + str = nm_ip_config_get_gateway (cfg6); + NM_SET_OUT (out_is_default, !str); + return str; case NMC_GENERIC_INFO_TYPE_IP6_CONFIG_ROUTE: if (!NM_FLAGS_HAS (get_flags, NM_META_ACCESSOR_GET_FLAGS_ACCEPT_STRV)) return NULL; @@ -239,10 +233,12 @@ _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; @@ -259,11 +255,6 @@ const NmcMetaGenericInfo *const metagen_ip4_config[_NMC_GENERIC_INFO_TYPE_IP4_CO _METAGEN_IP4_CONFIG (NMC_GENERIC_INFO_TYPE_IP4_CONFIG_WINS, "WINS"), }; -static const NmcMetaGenericInfo *const metagen_ip4_config_group[] = { - NMC_META_GENERIC_WITH_NESTED ("IP4", metagen_ip4_config, .name_header = N_("GROUP")), - NULL, -}; - const NmcMetaGenericInfo *const metagen_ip6_config[_NMC_GENERIC_INFO_TYPE_IP6_CONFIG_NUM + 1] = { #define _METAGEN_IP6_CONFIG(type, name) \ [type] = NMC_META_GENERIC(name, .info_type = type, .get_fcn = _metagen_ip6_config_get_fcn) @@ -274,14 +265,9 @@ const NmcMetaGenericInfo *const metagen_ip6_config[_NMC_GENERIC_INFO_TYPE_IP6_CO _METAGEN_IP6_CONFIG (NMC_GENERIC_INFO_TYPE_IP6_CONFIG_DOMAIN, "DOMAIN"), }; -static const NmcMetaGenericInfo *const metagen_ip6_config_group[] = { - NMC_META_GENERIC_WITH_NESTED ("IP6", metagen_ip6_config, .name_header = N_("GROUP")), - NULL, -}; - /*****************************************************************************/ -const NmcMetaGenericInfo *const nmc_fields_dhcp4_config[] = { +const NmcMetaGenericInfo *const nmc_fields_dhcp_config[] = { NMC_META_GENERIC ("GROUP"), /* 0 */ NMC_META_GENERIC ("OPTION"), /* 1 */ NULL, @@ -297,12 +283,6 @@ const NmcMetaGenericInfo *const nmc_fields_ip6_config[] = { NULL, }; -const NmcMetaGenericInfo *const nmc_fields_dhcp6_config[] = { - NMC_META_GENERIC ("GROUP"), /* 0 */ - NMC_META_GENERIC ("OPTION"), /* 1 */ - NULL, -}; - gboolean print_ip4_config (NMIPConfig *cfg4, const NmcConfig *nmc_config, @@ -320,7 +300,7 @@ print_ip4_config (NMIPConfig *cfg4, if (!nmc_print (nmc_config, (gpointer[]) { cfg4, NULL }, NULL, - (const NMMetaAbstractInfo *const*) metagen_ip4_config_group, + NMC_META_GENERIC_GROUP ("IP4", metagen_ip4_config, N_("GROUP")), field_str, &error)) { return FALSE; @@ -346,7 +326,7 @@ print_ip6_config (NMIPConfig *cfg6, if (!nmc_print (nmc_config, (gpointer[]) { cfg6, NULL }, NULL, - (const NMMetaAbstractInfo *const*) metagen_ip6_config_group, + NMC_META_GENERIC_GROUP ("IP6", metagen_ip6_config, N_("GROUP")), field_str, &error)) { return FALSE; @@ -355,82 +335,37 @@ print_ip6_config (NMIPConfig *cfg6, } gboolean -print_dhcp4_config (NMDhcpConfig *dhcp4, - const NmcConfig *nmc_config, - const char *group_prefix, - const char *one_field) +print_dhcp_config (NMDhcpConfig *dhcp, + const NmcConfig *nmc_config, + const char *group_prefix, + const char *one_field) { GHashTable *table; const NMMetaAbstractInfo *const*tmpl; NmcOutputField *arr; - if (dhcp4 == NULL) + if (dhcp == NULL) return FALSE; - table = nm_dhcp_config_get_options (dhcp4); + table = nm_dhcp_config_get_options (dhcp); if (table) { - GHashTableIter table_iter; - gpointer key, value; char **options_arr = NULL; - int i = 0; NMC_OUTPUT_DATA_DEFINE_SCOPED (out); + gs_free const char **keys = NULL; + guint i, nkeys; - tmpl = (const NMMetaAbstractInfo *const*) nmc_fields_dhcp4_config; + tmpl = (const NMMetaAbstractInfo *const*) nmc_fields_dhcp_config; out_indices = parse_output_fields (one_field, tmpl, FALSE, NULL, NULL); arr = nmc_dup_fields_array (tmpl, NMC_OF_FLAG_FIELD_NAMES); g_ptr_array_add (out.output_data, arr); - options_arr = g_new (char *, g_hash_table_size (table) + 1); - g_hash_table_iter_init (&table_iter, table); - while (g_hash_table_iter_next (&table_iter, &key, &value)) - options_arr[i++] = g_strdup_printf ("%s = %s", (char *) key, (char *) value); - options_arr[i] = NULL; + keys = (const char **) g_hash_table_get_keys_as_array (table, &nkeys); + nm_utils_strv_sort (keys, nkeys); - arr = nmc_dup_fields_array (tmpl, NMC_OF_FLAG_SECTION_PREFIX); - set_val_strc (arr, 0, group_prefix); - set_val_arr (arr, 1, options_arr); - g_ptr_array_add (out.output_data, arr); - - print_data_prepare_width (out.output_data); - print_data (nmc_config, out_indices, NULL, 0, &out); - - return TRUE; - } - return FALSE; -} - -gboolean -print_dhcp6_config (NMDhcpConfig *dhcp6, - const NmcConfig *nmc_config, - const char *group_prefix, - const char *one_field) -{ - GHashTable *table; - const NMMetaAbstractInfo *const*tmpl; - NmcOutputField *arr; - - if (dhcp6 == NULL) - return FALSE; - - table = nm_dhcp_config_get_options (dhcp6); - if (table) { - GHashTableIter table_iter; - gpointer key, value; - char **options_arr = NULL; - int i = 0; - NMC_OUTPUT_DATA_DEFINE_SCOPED (out); - - tmpl = (const NMMetaAbstractInfo *const*) nmc_fields_dhcp6_config; - out_indices = parse_output_fields (one_field, - tmpl, FALSE, NULL, NULL); - arr = nmc_dup_fields_array (tmpl, NMC_OF_FLAG_FIELD_NAMES); - g_ptr_array_add (out.output_data, arr); - - options_arr = g_new (char *, g_hash_table_size (table) + 1); - g_hash_table_iter_init (&table_iter, table); - while (g_hash_table_iter_next (&table_iter, &key, &value)) - options_arr[i++] = g_strdup_printf ("%s = %s", (char *) key, (char *) value); + options_arr = g_new (char *, nkeys + 1); + for (i = 0; i < nkeys; i++) + options_arr[i] = g_strdup_printf ("%s = %s", keys[i], (const char *) g_hash_table_lookup (table, keys[i])); options_arr[i] = NULL; arr = nmc_dup_fields_array (tmpl, NMC_OF_FLAG_SECTION_PREFIX); @@ -451,8 +386,11 @@ print_dhcp6_config (NMDhcpConfig *dhcp6, * @connections: array of NMConnections to search in * @filter_type: "id", "uuid", "path" or %NULL * @filter_val: connection to find (connection name, UUID or path) - * @start: where to start in @list. The location is updated so that the function - * can be called multiple times (for connections with the same name). + * @out_result: if not NULL, attach all matching connection to this + * list. If necessary, a new array will be allocated. If the array + * already contains a connection, it will not be added a second time. + * All object are referenced by the array. If the function allocates + * a new array, it will set the free function to g_object_unref. * @complete: print possible completions * * Find a connection in @list according to @filter_val. @filter_type determines @@ -467,64 +405,153 @@ NMConnection * nmc_find_connection (const GPtrArray *connections, const char *filter_type, const char *filter_val, - int *start, + GPtrArray **out_result, gboolean complete) { NMConnection *connection; - NMConnection *found = NULL; - int i; - const char *id; - const char *uuid; - const char *path, *path_num; + NMConnection *best_candidate = NULL; + GPtrArray *result = out_result ? *out_result : NULL; + guint i, j; - for (i = start ? *start : 0; i < connections->len; i++) { - connection = NM_CONNECTION (connections->pdata[i]); + nm_assert (connections); + nm_assert (filter_val); - id = nm_connection_get_id (connection); - uuid = nm_connection_get_uuid (connection); - path = nm_connection_get_path (connection); - path_num = path ? strrchr (path, '/') + 1 : NULL; + for (i = 0; i < connections->len; i++) { + const char *v, *v_num; + + connection = NM_CONNECTION (connections->pdata[i]); /* When filter_type is NULL, compare connection ID (filter_val) * against all types. Otherwise, only compare against the specific * type. If 'path' filter type is specified, comparison against * numeric index (in addition to the whole path) is allowed. */ - if (!filter_type || strcmp (filter_type, "id") == 0) { + if (NM_IN_STRSET (filter_type, NULL, "id")) { + v = nm_connection_get_id (connection); if (complete) - nmc_complete_strings (filter_val, id, NULL); - if (strcmp (filter_val, id) == 0) + nmc_complete_strings (filter_val, v, NULL); + if (nm_streq0 (filter_val, v)) goto found; } - if (!filter_type || strcmp (filter_type, "uuid") == 0) { + if (NM_IN_STRSET (filter_type, NULL, "uuid")) { + v = nm_connection_get_uuid (connection); if (complete && (filter_type || *filter_val)) - nmc_complete_strings (filter_val, uuid, NULL); - if (strcmp (filter_val, uuid) == 0) + nmc_complete_strings (filter_val, v, NULL); + if (nm_streq0 (filter_val, v)) goto found; } - if (!filter_type || strcmp (filter_type, "path") == 0) { + if (NM_IN_STRSET (filter_type, NULL, "path")) { + v = nm_connection_get_path (connection); + v_num = nm_utils_dbus_path_get_last_component (v); if (complete && (filter_type || *filter_val)) - nmc_complete_strings (filter_val, path, filter_type ? path_num : NULL, NULL); - if (g_strcmp0 (filter_val, path) == 0 || (filter_type && g_strcmp0 (filter_val, path_num) == 0)) + nmc_complete_strings (filter_val, v, filter_type ? v_num : NULL, NULL); + if ( nm_streq0 (filter_val, v) + || (filter_type && nm_streq0 (filter_val, v_num))) goto found; } continue; found: - if (!start) + if (!out_result) return connection; - if (found) { - *start = i; - return found; + if (!best_candidate) + best_candidate = connection; + if (!result) + result = g_ptr_array_new_with_free_func (g_object_unref); + for (j = 0; j < result->len; j++) { + if (connection == result->pdata[j]) + break; + } + if (j == result->len) + g_ptr_array_add (result, g_object_ref (connection)); + } + + NM_SET_OUT (out_result, result); + return best_candidate; +} + +NMActiveConnection * +nmc_find_active_connection (const GPtrArray *active_cons, + const char *filter_type, + const char *filter_val, + GPtrArray **out_result, + gboolean complete) +{ + guint i, j; + NMActiveConnection *best_candidate = NULL; + GPtrArray *result = out_result ? *out_result : NULL; + + nm_assert (filter_val); + + for (i = 0; i < active_cons->len; i++) { + NMRemoteConnection *con; + NMActiveConnection *candidate = g_ptr_array_index (active_cons, i); + const char *v, *v_num; + + con = nm_active_connection_get_connection (candidate); + + /* When filter_type is NULL, compare connection ID (filter_val) + * against all types. Otherwise, only compare against the specific + * type. If 'path' or 'apath' filter types are specified, comparison + * against numeric index (in addition to the whole path) is allowed. + */ + if (NM_IN_STRSET (filter_type, NULL, "id")) { + v = nm_active_connection_get_id (candidate); + if (complete) + nmc_complete_strings (filter_val, v, NULL); + if (nm_streq0 (filter_val, v)) + goto found; + } + + if (NM_IN_STRSET (filter_type, NULL, "uuid")) { + v = nm_active_connection_get_uuid (candidate); + if (complete && (filter_type || *filter_val)) + nmc_complete_strings (filter_val, v, NULL); + if (nm_streq0 (filter_val, v)) + goto found; + } + + if (NM_IN_STRSET (filter_type, NULL, "path")) { + v = con ? nm_connection_get_path (NM_CONNECTION (con)) : NULL; + v_num = nm_utils_dbus_path_get_last_component (v); + if (complete && (filter_type || *filter_val)) + nmc_complete_strings (filter_val, v, filter_type ? v_num : NULL, NULL); + if ( nm_streq0 (filter_val, v) + || (filter_type && nm_streq0 (filter_val, v_num))) + goto found; + } + + if (NM_IN_STRSET (filter_type, NULL, "apath")) { + v = nm_object_get_path (NM_OBJECT (candidate)); + v_num = nm_utils_dbus_path_get_last_component (v); + if (complete && (filter_type || *filter_val)) + nmc_complete_strings (filter_val, v, filter_type ? v_num : NULL, NULL); + if ( nm_streq0 (filter_val, v) + || (filter_type && nm_streq0 (filter_val, v_num))) + goto found; + } + + continue; + +found: + if (!out_result) + return candidate; + if (!best_candidate) + best_candidate = candidate; + if (!result) + result = g_ptr_array_new_with_free_func (g_object_unref); + for (j = 0; j < result->len; j++) { + if (candidate == result->pdata[j]) + break; } - found = connection; + if (j == result->len) + g_ptr_array_add (result, g_object_ref (candidate)); } - if (start) - *start = 0; - return found; + NM_SET_OUT (out_result, result); + return best_candidate; } static gboolean @@ -532,10 +559,10 @@ vpn_openconnect_get_secrets (NMConnection *connection, GPtrArray *secrets) { GError *error = NULL; NMSettingVpn *s_vpn; - const char *vpn_type, *gw, *port; - char *cookie = NULL; - char *gateway = NULL; - char *gwcert = NULL; + const char *gw, *port; + gs_free char *cookie = NULL; + gs_free char *gateway = NULL; + gs_free char *gwcert = NULL; int status = 0; int i; gboolean ret; @@ -547,8 +574,7 @@ vpn_openconnect_get_secrets (NMConnection *connection, GPtrArray *secrets) return FALSE; s_vpn = nm_connection_get_setting_vpn (connection); - vpn_type = nm_setting_vpn_get_service_type (s_vpn); - if (g_strcmp0 (vpn_type, NM_DBUS_INTERFACE ".openconnect")) + if (!nm_streq0 (nm_setting_vpn_get_service_type (s_vpn), NM_SECRET_AGENT_VPN_TYPE_OPENCONNECT)) return FALSE; /* Get gateway and port */ @@ -571,34 +597,31 @@ vpn_openconnect_get_secrets (NMConnection *connection, GPtrArray *secrets) /* Append port to the host value */ if (gateway && port) { - char *tmp = gateway; - gateway = g_strdup_printf ("%s%s", gateway, port); - g_free (tmp); + gs_free char *tmp = gateway; + + gateway = g_strdup_printf ("%s%s", tmp, port); } /* Fill secrets to the array */ for (i = 0; i < secrets->len; i++) { NMSecretAgentSimpleSecret *secret = secrets->pdata[i]; - 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; - } + 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); } } - g_free (cookie); - g_free (gateway); - g_free (gwcert); return TRUE; } @@ -625,7 +648,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->prop_name))) { + if (pwds_hash && (pwd = g_hash_table_lookup (pwds_hash, secret->entry_id))) { pwd = g_strdup (pwd); } else { if (ask) { @@ -641,8 +664,10 @@ get_secrets_from_user (const char *request_id, } if (msg) g_print ("%s\n", msg); - pwd = nmc_readline_echo (secret->password ? echo_on : TRUE, - "%s (%s): ", secret->name, secret->prop_name); + pwd = nmc_readline_echo (secret->is_secret + ? echo_on + : TRUE, + "%s (%s): ", secret->pretty_name, secret->entry_id); if (!pwd) pwd = g_strdup (""); } else { @@ -650,7 +675,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->prop_name); + secret->entry_id); } } /* No password provided, cancel the secrets. */ @@ -883,6 +908,31 @@ 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: * @@ -894,29 +944,28 @@ nmc_readline_echo (gboolean echo_on, const char *prompt_fmt, ...) { va_list args; char *prompt, *str; - struct termios termios_orig, termios_new; + HISTORY_STATE *saved_history; + HISTORY_STATE passwd_history = { 0, }; va_start (args, prompt_fmt); prompt = g_strdup_vprintf (prompt_fmt, args); va_end (args); - /* Disable echoing characters */ + /* Hide the actual password */ if (!echo_on) { - tcgetattr (STDIN_FILENO, &termios_orig); - termios_new = termios_orig; - termios_new.c_lflag &= ~(ECHO); - tcsetattr (STDIN_FILENO, TCSADRAIN, &termios_new); + saved_history = history_get_history_state (); + history_set_history_state (&passwd_history); + rl_redisplay_function = nmc_secret_redisplay; } str = nmc_readline_helper (prompt); g_free (prompt); - /* Restore original terminal settings */ + /* Restore the non-hiding behavior */ if (!echo_on) { - tcsetattr (STDIN_FILENO, TCSADRAIN, &termios_orig); - /* New line - setting ECHONL | ICANON did not help */ - fprintf (stdout, "\n"); + rl_redisplay_function = rl_redisplay; + history_set_history_state (saved_history); } return str; @@ -1215,9 +1264,8 @@ 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 (c->usage && nmc_arg_is_help (*(argv+1))) { - if (!nmc->complete) - c->usage (); + if (!nmc->complete && c->usage && nmc_arg_is_help (*(argv+1))) { + c->usage (); g_simple_async_result_complete_in_idle (simple); g_object_unref (simple); } else { diff --git a/clients/cli/common.h b/clients/cli/common.h index 354b2a5f..8f4e47c2 100644 --- a/clients/cli/common.h +++ b/clients/cli/common.h @@ -27,15 +27,20 @@ gboolean print_ip4_config (NMIPConfig *cfg4, const NmcConfig *nmc_config, const char *one_field); gboolean print_ip6_config (NMIPConfig *cfg6, const NmcConfig *nmc_config, const char *group_prefix, const char *one_field); -gboolean print_dhcp4_config (NMDhcpConfig *dhcp4, const NmcConfig *nmc_config, const char *group_prefix, const char *one_field); -gboolean print_dhcp6_config (NMDhcpConfig *dhcp6, const NmcConfig *nmc_config, const char *group_prefix, const char *one_field); +gboolean print_dhcp_config (NMDhcpConfig *dhcp, const NmcConfig *nmc_config, const char *group_prefix, const char *one_field); NMConnection *nmc_find_connection (const GPtrArray *connections, const char *filter_type, const char *filter_val, - int *start, + GPtrArray **out_result, gboolean complete); +NMActiveConnection *nmc_find_active_connection (const GPtrArray *active_cons, + const char *filter_type, + const char *filter_val, + GPtrArray **out_result, + gboolean complete); + void nmc_secrets_requested (NMSecretAgentSimple *agent, const char *request_id, const char *title, @@ -78,8 +83,7 @@ void nmc_complete_bool (const char *prefix); const char *nmc_error_get_simple_message (GError *error); extern const NmcMetaGenericInfo *const metagen_ip4_config[]; -extern const NmcMetaGenericInfo *const nmc_fields_dhcp4_config[]; extern const NmcMetaGenericInfo *const nmc_fields_ip6_config[]; -extern const NmcMetaGenericInfo *const nmc_fields_dhcp6_config[]; +extern const NmcMetaGenericInfo *const nmc_fields_dhcp_config[]; #endif /* NMC_COMMON_H */ diff --git a/clients/cli/connections.c b/clients/cli/connections.c index e0f55c53..a4f129b6 100644 --- a/clients/cli/connections.c +++ b/clients/cli/connections.c @@ -14,7 +14,7 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright 2010 - 2017 Red Hat, Inc. + * Copyright 2010 - 2018 Red Hat, Inc. */ #include "nm-default.h" @@ -31,8 +31,6 @@ #include <readline/readline.h> #include <readline/history.h> -#include "nm-utils/nm-hash-utils.h" - #include "nm-client-utils.h" #include "nm-vpn-helpers.h" #include "nm-meta-setting-access.h" @@ -78,6 +76,82 @@ struct _OptionInfo { /*****************************************************************************/ +NM_UTILS_LOOKUP_STR_DEFINE_STATIC (active_connection_state_to_string, NMActiveConnectionState, + NM_UTILS_LOOKUP_DEFAULT (N_("unknown")), + NM_UTILS_LOOKUP_ITEM (NM_ACTIVE_CONNECTION_STATE_ACTIVATING, N_("activating")), + NM_UTILS_LOOKUP_ITEM (NM_ACTIVE_CONNECTION_STATE_ACTIVATED, N_("activated")), + NM_UTILS_LOOKUP_ITEM (NM_ACTIVE_CONNECTION_STATE_DEACTIVATING, N_("deactivating")), + NM_UTILS_LOOKUP_ITEM (NM_ACTIVE_CONNECTION_STATE_DEACTIVATED, N_("deactivated")), + NM_UTILS_LOOKUP_ITEM_IGNORE (NM_ACTIVE_CONNECTION_STATE_UNKNOWN), +) + +NM_UTILS_LOOKUP_STR_DEFINE_STATIC (vpn_connection_state_to_string, NMVpnConnectionState, + NM_UTILS_LOOKUP_DEFAULT (N_("unknown")), + NM_UTILS_LOOKUP_ITEM (NM_VPN_CONNECTION_STATE_PREPARE, N_("VPN connecting (prepare)")), + NM_UTILS_LOOKUP_ITEM (NM_VPN_CONNECTION_STATE_NEED_AUTH, N_("VPN connecting (need authentication)")), + NM_UTILS_LOOKUP_ITEM (NM_VPN_CONNECTION_STATE_CONNECT, N_("VPN connecting")), + NM_UTILS_LOOKUP_ITEM (NM_VPN_CONNECTION_STATE_IP_CONFIG_GET, N_("VPN connecting (getting IP configuration)")), + NM_UTILS_LOOKUP_ITEM (NM_VPN_CONNECTION_STATE_ACTIVATED, N_("VPN connected")), + NM_UTILS_LOOKUP_ITEM (NM_VPN_CONNECTION_STATE_FAILED, N_("VPN connection failed")), + NM_UTILS_LOOKUP_ITEM (NM_VPN_CONNECTION_STATE_DISCONNECTED, N_("VPN disconnected")), + NM_UTILS_LOOKUP_ITEM_IGNORE (NM_VPN_CONNECTION_STATE_UNKNOWN), +) + +/* Essentially a version of nm_setting_connection_get_connection_type() that + * prefers an alias instead of the settings name when in pretty print mode. + * That is so that we print "wifi" instead of "802-11-wireless" in "nmcli c". */ +static const char * +connection_type_pretty (const char *type, NMCPrintOutput print_output) +{ + const NMMetaSettingInfoEditor *editor; + int i; + + if (print_output == NMC_PRINT_TERSE) + return type; + + for (i = 0; i < _NM_META_SETTING_TYPE_NUM; i++) { + editor = &nm_meta_setting_infos_editor[i]; + if (strcmp (type, editor->general->setting_name) == 0) { + if (editor->alias) + return editor->alias; + break; + } + } + + return type; +} + +/* Caller has to free the returned string */ +static char * +get_ac_device_string (NMActiveConnection *active) +{ + GString *dev_str; + const GPtrArray *devices; + int i; + + if (!active) + return NULL; + + /* Get devices of the active connection */ + dev_str = g_string_new (NULL); + devices = nm_active_connection_get_devices (active); + for (i = 0; i < devices->len; i++) { + NMDevice *device = g_ptr_array_index (devices, i); + const char *dev_iface = nm_device_get_iface (device); + + if (dev_iface) { + g_string_append (dev_str, dev_iface); + g_string_append_c (dev_str, ','); + } + } + if (dev_str->len > 0) + g_string_truncate (dev_str, dev_str->len - 1); /* Cut off last ',' */ + + return g_string_free (dev_str, FALSE); +} + +/*****************************************************************************/ + const NmcMetaGenericInfo *const nmc_fields_con_show[] = { NMC_META_GENERIC ("NAME"), /* 0 */ NMC_META_GENERIC ("UUID"), /* 1 */ @@ -151,7 +225,6 @@ const NmcMetaGenericInfo *const nmc_fields_con_active_details_general[] = { // NM_SETTING_DUMMY_SETTING_NAME // NM_SETTING_WIMAX_SETTING_NAME - const NmcMetaGenericInfo *const nmc_fields_con_active_details_vpn[] = { NMC_META_GENERIC ("GROUP"), /* 0 */ NMC_META_GENERIC ("TYPE"), /* 1 */ @@ -166,9 +239,9 @@ const NmcMetaGenericInfo *const nmc_fields_con_active_details_vpn[] = { const NmcMetaGenericInfo *const nmc_fields_con_active_details_groups[] = { NMC_META_GENERIC_WITH_NESTED ("GENERAL", nmc_fields_con_active_details_general + 1), /* 0 */ NMC_META_GENERIC_WITH_NESTED ("IP4", metagen_ip4_config), /* 1 */ - NMC_META_GENERIC_WITH_NESTED ("DHCP4", nmc_fields_dhcp4_config + 1), /* 2 */ + NMC_META_GENERIC_WITH_NESTED ("DHCP4", nmc_fields_dhcp_config + 1), /* 2 */ NMC_META_GENERIC_WITH_NESTED ("IP6", nmc_fields_ip6_config + 1), /* 3 */ - NMC_META_GENERIC_WITH_NESTED ("DHCP6", nmc_fields_dhcp6_config + 1), /* 4 */ + NMC_META_GENERIC_WITH_NESTED ("DHCP6", nmc_fields_dhcp_config + 1), /* 4 */ NMC_META_GENERIC_WITH_NESTED ("VPN", nmc_fields_con_active_details_vpn + 1), /* 5 */ NULL, }; @@ -189,7 +262,10 @@ typedef struct { NMSetting *setting; const char *property; } TabCompletionInfo; -static TabCompletionInfo nmc_tab_completion = {NULL, NULL, NULL, NULL}; + +static TabCompletionInfo nmc_tab_completion; + +/*****************************************************************************/ static void usage (void) @@ -505,12 +581,8 @@ usage_connection_export (void) static void quit (void) { - if (progress_id) { - g_source_remove (progress_id); - progress_id = 0; + if (nm_clear_g_source (&progress_id)) nmc_terminal_erase_line (); - } - g_main_loop_quit (loop); } @@ -523,97 +595,38 @@ construct_header_name (const char *base, const char *spec) return g_strdup_printf ("%s (%s)", base, spec); } -static const char * -active_connection_state_to_string (NMActiveConnectionState state) -{ - switch (state) { - case NM_ACTIVE_CONNECTION_STATE_ACTIVATING: - return _("activating"); - case NM_ACTIVE_CONNECTION_STATE_ACTIVATED: - return _("activated"); - case NM_ACTIVE_CONNECTION_STATE_DEACTIVATING: - return _("deactivating"); - case NM_ACTIVE_CONNECTION_STATE_DEACTIVATED: - return _("deactivated"); - case NM_ACTIVE_CONNECTION_STATE_UNKNOWN: - default: - return _("unknown"); - } -} - -static const char * -vpn_connection_state_to_string (NMVpnConnectionState state) -{ - switch (state) { - case NM_VPN_CONNECTION_STATE_PREPARE: - return _("VPN connecting (prepare)"); - case NM_VPN_CONNECTION_STATE_NEED_AUTH: - return _("VPN connecting (need authentication)"); - case NM_VPN_CONNECTION_STATE_CONNECT: - return _("VPN connecting"); - case NM_VPN_CONNECTION_STATE_IP_CONFIG_GET: - return _("VPN connecting (getting IP configuration)"); - case NM_VPN_CONNECTION_STATE_ACTIVATED: - return _("VPN connected"); - case NM_VPN_CONNECTION_STATE_FAILED: - return _("VPN connection failed"); - case NM_VPN_CONNECTION_STATE_DISCONNECTED: - return _("VPN disconnected"); - default: - return _("unknown"); - } -} - -/* Caller has to free the returned string */ -static char * -get_ac_device_string (NMActiveConnection *active) -{ - GString *dev_str; - const GPtrArray *devices; - int i; - - if (!active) - return NULL; - - /* Get devices of the active connection */ - dev_str = g_string_new (NULL); - devices = nm_active_connection_get_devices (active); - for (i = 0; i < devices->len; i++) { - NMDevice *device = g_ptr_array_index (devices, i); - const char *dev_iface = nm_device_get_iface (device); - - if (dev_iface) { - g_string_append (dev_str, dev_iface); - g_string_append_c (dev_str, ','); - } - } - if (dev_str->len > 0) - g_string_truncate (dev_str, dev_str->len - 1); /* Cut off last ',' */ - - return g_string_free (dev_str, FALSE); -} - static NMActiveConnection * -get_ac_for_connection (const GPtrArray *active_cons, NMConnection *connection) +get_ac_for_connection (const GPtrArray *active_cons, NMConnection *connection, GPtrArray **out_result) { const char *con_path, *ac_con_path; - int i; - NMActiveConnection *ac = NULL; + guint i; + NMActiveConnection *best_candidate = NULL; + GPtrArray *result = out_result ? *out_result : NULL; - /* Is the connection active? */ con_path = nm_connection_get_path (connection); for (i = 0; i < active_cons->len; i++) { NMActiveConnection *candidate = g_ptr_array_index (active_cons, i); NMRemoteConnection *con; con = nm_active_connection_get_connection (candidate); - ac_con_path = con ? nm_connection_get_path (NM_CONNECTION (con)) : NULL; - if (!g_strcmp0 (ac_con_path, con_path)) { - ac = candidate; - break; + if (NM_CONNECTION (con) != connection) { + /* also compare the D-Bus paths. Why? I don't know. */ + ac_con_path = con ? nm_connection_get_path (NM_CONNECTION (con)) : NULL; + if (!nm_streq0 (ac_con_path, con_path)) + continue; } + + if (!out_result) + return candidate; + if (!best_candidate) + best_candidate = candidate; + if (!result) + result = g_ptr_array_new_with_free_func (g_object_unref); + g_ptr_array_add (result, g_object_ref (candidate)); } - return ac; + + NM_SET_OUT (out_result, result); + return best_candidate; } typedef struct { @@ -741,118 +754,17 @@ nmc_connection_profile_details (NMConnection *connection, NmCli *nmc) return TRUE; } -static NMActiveConnection * -find_active_connection (const GPtrArray *active_cons, - const GPtrArray *cons, - const char *filter_type, - const char *filter_val, - int *idx, - gboolean complete) -{ - int i; - int start = (idx && *idx > 0) ? *idx : 0; - const char *path, *a_path, *path_num, *a_path_num; - const char *id; - const char *uuid; - NMRemoteConnection *con; - NMActiveConnection *found = NULL; - - for (i = start; i < active_cons->len; i++) { - NMActiveConnection *candidate = g_ptr_array_index (active_cons, i); - - con = nm_active_connection_get_connection (candidate); - - id = nm_active_connection_get_id (candidate); - uuid = nm_active_connection_get_uuid (candidate); - path = con ? nm_connection_get_path (NM_CONNECTION (con)) : NULL; - path_num = path ? strrchr (path, '/') + 1 : NULL; - a_path = nm_object_get_path (NM_OBJECT (candidate)); - a_path_num = a_path ? strrchr (a_path, '/') + 1 : NULL; - - /* When filter_type is NULL, compare connection ID (filter_val) - * against all types. Otherwise, only compare against the specific - * type. If 'path' or 'apath' filter types are specified, comparison - * against numeric index (in addition to the whole path) is allowed. - */ - if (!filter_type || strcmp (filter_type, "id") == 0) { - if (complete) - nmc_complete_strings (filter_val, id, NULL); - if (strcmp (filter_val, id) == 0) - goto found; - } - - if (!filter_type || strcmp (filter_type, "uuid") == 0) { - if (complete && (filter_type || *filter_val)) - nmc_complete_strings (filter_val, uuid, NULL); - if (strcmp (filter_val, uuid) == 0) - goto found; - } - - if (!filter_type || strcmp (filter_type, "path") == 0) { - if (complete && (filter_type || *filter_val)) - nmc_complete_strings (filter_val, path, filter_type ? path_num : NULL, NULL); - if (g_strcmp0 (filter_val, path) == 0 || (filter_type && g_strcmp0 (filter_val, path_num) == 0)) - goto found; - } - - if (!filter_type || strcmp (filter_type, "apath") == 0) { - if (complete && (filter_type || *filter_val)) - nmc_complete_strings (filter_val, a_path, filter_type ? a_path_num : NULL, NULL); - if (g_strcmp0 (filter_val, a_path) == 0 || (filter_type && g_strcmp0 (filter_val, a_path_num) == 0)) - goto found; - } - - continue; -found: - if (!idx) - return candidate; - if (found) { - *idx = i; - return found; - } - found = candidate; - } - - if (idx) - *idx = 0; - return found; -} - -void -nmc_active_connection_state_to_color (NMActiveConnectionState state, NMMetaTermColor *color) +NMMetaColor +nmc_active_connection_state_to_color (NMActiveConnectionState state) { - *color = NM_META_TERM_COLOR_NORMAL; - if (state == NM_ACTIVE_CONNECTION_STATE_ACTIVATING) - *color = NM_META_TERM_COLOR_YELLOW; + return NM_META_COLOR_CONNECTION_ACTIVATING; else if (state == NM_ACTIVE_CONNECTION_STATE_ACTIVATED) - *color = NM_META_TERM_COLOR_GREEN; + return NM_META_COLOR_CONNECTION_ACTIVATED; else if (state > NM_ACTIVE_CONNECTION_STATE_ACTIVATED) - *color = NM_META_TERM_COLOR_RED; -} - -/* Essentially a version of nm_setting_connection_get_connection_type() that - * prefers an alias instead of the settings name when in pretty print mode. - * That is so that we print "wifi" instead of "802-11-wireless" in "nmcli c". */ -static const char * -connection_type_pretty (const char *type, NMCPrintOutput print_output) -{ - const NMMetaSettingInfoEditor *editor; - int i; - - if (print_output == NMC_PRINT_TERSE) - return type; - - for (i = 0; i < _NM_META_SETTING_TYPE_NUM; i++) { - editor = &nm_meta_setting_infos_editor[i]; - if (strcmp (type, editor->general->setting_name) == 0) { - if (editor->alias) - return editor->alias; - break; - } - } - - return type; + return NM_META_COLOR_CONNECTION_DISCONNECTING; + else + return NM_META_COLOR_CONNECTION_UNKNOWN; } static void @@ -871,19 +783,19 @@ fill_output_connection (NMConnection *connection, NMClient *client, NMCPrintOutp const char *ac_state = NULL; NMActiveConnectionState ac_state_int = NM_ACTIVE_CONNECTION_STATE_UNKNOWN; char *ac_dev = NULL; - NMMetaTermColor color; + NMMetaColor color; s_con = nm_connection_get_setting_connection (connection); g_assert (s_con); - ac = get_ac_for_connection (nm_client_get_active_connections (client), connection); + ac = get_ac_for_connection (nm_client_get_active_connections (client), connection, NULL); if (active_only && !ac) return; if (ac) { ac_path = nm_object_get_path (NM_OBJECT (ac)); ac_state_int = nm_active_connection_get_state (ac); - ac_state = active_connection_state_to_string (ac_state_int); + ac_state = gettext (active_connection_state_to_string (ac_state_int)); ac_dev = get_ac_device_string (ac); } @@ -900,7 +812,7 @@ fill_output_connection (NMConnection *connection, NMClient *client, NMCPrintOutp arr = nmc_dup_fields_array ((const NMMetaAbstractInfo *const*) nmc_fields_con_show, 0); /* Show active connections in color */ - nmc_active_connection_state_to_color (ac_state_int, &color); + color = nmc_active_connection_state_to_color (ac_state_int); set_val_color_all (arr, color); set_val_strc (arr, 0, nm_setting_connection_get_id (s_con)); @@ -951,7 +863,7 @@ fill_output_connection_for_invisible (NMActiveConnection *ac, NMCPrintOutput pri set_val_strc (arr, 12, ac_path); set_val_strc (arr, 13, NULL); - set_val_color_fmt_all (arr, NM_META_TERM_FORMAT_DIM); + set_val_color_all (arr, NM_META_COLOR_CONNECTION_INVISIBLE); g_ptr_array_add (output_data, arr); } @@ -978,7 +890,7 @@ fill_output_active_connection (NMActiveConnection *active, if (con) { con_path = nm_connection_get_path (NM_CONNECTION (con)); s_con = nm_connection_get_setting_connection (NM_CONNECTION (con)); - g_assert (s_con != NULL); + g_assert (s_con); con_zone = nm_setting_connection_get_zone (s_con); } @@ -1099,7 +1011,9 @@ static const gchar * get_vpn_data_item (NMConnection *connection, enum VpnDataItem vpn_data_item) { const char *key; - char *type = get_vpn_connection_type (connection); + gs_free char *type = NULL; + + type = get_vpn_connection_type (connection); switch (vpn_data_item) { case VPN_DATA_ITEM_GATEWAY: @@ -1112,7 +1026,6 @@ get_vpn_data_item (NMConnection *connection, enum VpnDataItem vpn_data_item) key = ""; break; } - g_free (type); return nm_setting_vpn_get_data_item (nm_connection_get_setting_vpn (connection), key); } @@ -1128,7 +1041,6 @@ 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; @@ -1182,7 +1094,6 @@ 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); @@ -1211,7 +1122,7 @@ nmc_active_connection_details (NMActiveConnection *acon, NmCli *nmc) gboolean b1 = FALSE; NMDhcpConfig *dhcp4 = nm_active_connection_get_dhcp4_config (acon); - b1 = print_dhcp4_config (dhcp4, &nmc->nmc_config, "DHCP4", group_fld); + b1 = print_dhcp_config (dhcp4, &nmc->nmc_config, "DHCP4", group_fld); was_output = was_output || b1; } @@ -1229,7 +1140,7 @@ nmc_active_connection_details (NMActiveConnection *acon, NmCli *nmc) gboolean b1 = FALSE; NMDhcpConfig *dhcp6 = nm_active_connection_get_dhcp6_config (acon); - b1 = print_dhcp6_config (dhcp6, &nmc->nmc_config, "DHCP6", group_fld); + b1 = print_dhcp_config (dhcp6, &nmc->nmc_config, "DHCP6", group_fld); was_output = was_output || b1; } @@ -1250,7 +1161,7 @@ nmc_active_connection_details (NMActiveConnection *acon, NmCli *nmc) con = NM_CONNECTION (nm_active_connection_get_connection (acon)); s_con = nm_connection_get_setting_connection (con); - g_assert (s_con != NULL); + g_assert (s_con); tmpl = (const NMMetaAbstractInfo *const*) nmc_fields_con_active_details_vpn; out_indices = parse_output_fields (group_fld, @@ -1278,13 +1189,15 @@ nmc_active_connection_details (NMActiveConnection *acon, NmCli *nmc) if (banner) banner_str = g_strescape (banner, ""); vpn_state = nm_vpn_connection_get_vpn_state (NM_VPN_CONNECTION (acon)); - vpn_state_str = g_strdup_printf ("%d - %s", vpn_state, vpn_connection_state_to_string (vpn_state)); + vpn_state_str = g_strdup_printf ("%d - %s", + vpn_state, + gettext (vpn_connection_state_to_string (vpn_state))); /* Add values */ arr = nmc_dup_fields_array (tmpl, NMC_OF_FLAG_SECTION_PREFIX); set_val_strc (arr, 0, nmc_fields_con_active_details_groups[5]->name); set_val_str (arr, 1, type_str); - set_val_strc (arr, 2, username ? username : get_vpn_data_item (con, VPN_DATA_ITEM_USERNAME)); + set_val_strc (arr, 2, username ?: get_vpn_data_item (con, VPN_DATA_ITEM_USERNAME)); set_val_strc (arr, 3, get_vpn_data_item (con, VPN_DATA_ITEM_GATEWAY)); set_val_str (arr, 4, banner_str); set_val_str (arr, 5, vpn_state_str); @@ -1439,34 +1352,34 @@ typedef struct { static int compare_connections (gconstpointer a, gconstpointer b, gpointer user_data) { - NMConnection *ca = *(NMConnection **)a; - NMConnection *cb = *(NMConnection **)b; + NMConnection *ca = *(NMConnection **) a; + NMConnection *cb = *(NMConnection **) b; + const NmcSortInfo *info = user_data; NMActiveConnection *aca, *acb; - NmcSortInfo *info = (NmcSortInfo *) user_data; - GArray *default_order = NULL; - const GArray *order; - NmcSortOrder item; - int cmp = 0, i; + const NmcSortOrder *order_arr; + guint i, order_len; const char *tmp1, *tmp2; unsigned long tmp1_int, tmp2_int; - if (info->order ) - order = info->order; - else { - NmcSortOrder def[] = { NMC_SORT_ACTIVE, NMC_SORT_NAME, NMC_SORT_PATH }; - int num = G_N_ELEMENTS (def); - default_order = g_array_sized_new (FALSE, FALSE, sizeof (NmcSortOrder), num); - g_array_append_vals (default_order, def, num); - order = default_order; + if (info->order) { + order_arr = &g_array_index (info->order, NmcSortOrder, 0); + order_len = info->order->len; + } else { + static const NmcSortOrder def[] = { NMC_SORT_ACTIVE, NMC_SORT_NAME, NMC_SORT_PATH }; + + order_arr = def; + order_len = G_N_ELEMENTS (def); } - for (i = 0; i < order->len; i++) { - item = g_array_index (order, NmcSortOrder, i); + for (i = 0; i < order_len; i++) { + NmcSortOrder item = order_arr[i]; + int cmp = 0; + switch (item) { case NMC_SORT_ACTIVE: case NMC_SORT_ACTIVE_INV: - aca = get_ac_for_connection (nm_client_get_active_connections (info->nmc->client), ca); - acb = get_ac_for_connection (nm_client_get_active_connections (info->nmc->client), cb); + aca = get_ac_for_connection (nm_client_get_active_connections (info->nmc->client), ca, NULL); + acb = get_ac_for_connection (nm_client_get_active_connections (info->nmc->client), cb, NULL); cmp = (aca && !acb) ? -1 : (!aca && acb) ? 1 : 0; if (item == NMC_SORT_ACTIVE_INV) cmp = -(cmp); @@ -1502,12 +1415,10 @@ compare_connections (gconstpointer a, gconstpointer b, gpointer user_data) break; } if (cmp != 0) - goto end; + return cmp; } -end: - if (default_order) - g_array_unref (default_order); - return cmp; + + return 0; } static GPtrArray * @@ -1559,7 +1470,7 @@ get_invisible_active_connections (NmCli *nmc) GPtrArray *invisibles; int a, c; - g_return_val_if_fail (nmc != NULL, NULL); + g_return_val_if_fail (nmc, NULL); invisibles = g_ptr_array_new (); acons = nm_client_get_active_connections (nmc->client); @@ -1589,18 +1500,18 @@ get_invisible_active_connections (NmCli *nmc) static GArray * parse_preferred_connection_order (const char *order, GError **error) { - char **strv, **iter; + gs_free const char **strv = NULL; + const char *const*iter; const char *str; GArray *order_arr; NmcSortOrder val; gboolean inverse, unique; int i; - strv = nmc_strsplit_set (order, ":", -1); - if (!strv || !*strv) { + strv = nm_utils_strsplit_set (order, ":"); + if (!strv) { g_set_error (error, NMCLI_ERROR, 0, _("incorrect string '%s' of '--order' option"), order); - g_strfreev (strv); return NULL; } @@ -1642,17 +1553,25 @@ parse_preferred_connection_order (const char *order, GError **error) g_array_append_val (order_arr, val); } - g_strfreev (strv); return order_arr; } static NMConnection * -get_connection (NmCli *nmc, int *argc, char ***argv, int *pos, GError **error) +get_connection (NmCli *nmc, + int *argc, + char ***argv, + const char **out_selector, + const char **out_value, + GPtrArray **out_result, + GError **error) { const GPtrArray *connections; NMConnection *connection = NULL; const char *selector = NULL; + NM_SET_OUT (out_selector, NULL); + NM_SET_OUT (out_value, NULL); + if (*argc == 0) { g_set_error_literal (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT, _("No connection specified")); @@ -1662,45 +1581,46 @@ 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 ( 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; + 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)--; } } + NM_SET_OUT (out_selector, selector); + NM_SET_OUT (out_value, **argv); + connections = nm_client_get_connections (nmc->client); - connection = nmc_find_connection (connections, selector, **argv, pos, + connection = nmc_find_connection (connections, selector, **argv, out_result, *argc == 1 && nmc->complete); if (!connection) { g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_NOT_FOUND, _("unknown connection '%s'"), **argv); } - /* If the caller wants multiple results (pos is set) and there are any, - * don't switch to next argument. - */ - if (!pos || !*pos) - next_arg (nmc, argc, argv, NULL); - + next_arg (nmc, argc, argv, NULL); return connection; } static NMCResultCode do_connections_show (NmCli *nmc, int argc, char **argv) { - GError *err = NULL; - char *profile_flds = NULL, *active_flds = NULL; + gs_free_error GError *err = NULL; + gs_free char *profile_flds = NULL; + gs_free char *active_flds = NULL; GPtrArray *invisibles, *sorted_cons; gboolean active_only = FALSE; - GArray *order = NULL; - int i, option; + gs_unref_array GArray *order = NULL; + guint i, j; + int option; /* check connection show options [--active] [--order <order spec>] */ while ((option = next_arg (nmc, &argc, &argv, "--active", "--order", NULL)) > 0) { @@ -1775,7 +1695,6 @@ do_connections_show (NmCli *nmc, int argc, char **argv) gboolean new_line = FALSE; gboolean without_fields = (nmc->required_fields == NULL); const GPtrArray *active_cons = nm_client_get_active_connections (nmc->client); - int pos = 0; /* multiline mode is default for 'connection show <ID>' */ if (!nmc->mode_specified) @@ -1784,8 +1703,8 @@ do_connections_show (NmCli *nmc, int argc, char **argv) /* Split required fields into the settings and active ones. */ if (!split_required_fields_for_con_show (nmc->required_fields, &profile_flds, &active_flds, &err)) goto finish; - g_free (nmc->required_fields); - nmc->required_fields = NULL; + + nm_clear_g_free (&nmc->required_fields); /* Before printing the connections check if we have a "--show-secret" * option after the connection ids */ @@ -1794,10 +1713,7 @@ do_connections_show (NmCli *nmc, int argc, char **argv) char **argv_cp = argv; do { - if ( nm_streq (*argv_cp, "id") - || nm_streq (*argv_cp, "uuid") - || nm_streq (*argv_cp, "path") - || nm_streq (*argv_cp, "apath")) { + if (NM_IN_STRSET (*argv_cp, "id", "uuid", "path", "apath")) { argc_cp--; argv_cp++; } @@ -1808,16 +1724,16 @@ do_connections_show (NmCli *nmc, int argc, char **argv) const GPtrArray *connections; gboolean res; NMConnection *con; - NMActiveConnection *acon = NULL; + gs_unref_object NMActiveConnection *explicit_acon = NULL; const char *selector = NULL; + gs_unref_ptrarray GPtrArray *found_cons = NULL; + gboolean explicit_acon_handled = FALSE; + guint i_found_cons; if (argc == 1 && nmc->complete) nmc_complete_strings (*argv, "id", "uuid", "path", "apath", NULL); - if ( strcmp (*argv, "id") == 0 - || strcmp (*argv, "uuid") == 0 - || strcmp (*argv, "path") == 0 - || strcmp (*argv, "apath") == 0) { + if (NM_IN_STRSET (*argv, "id", "uuid", "path", "apath")) { selector = *argv; argc--; argv++; @@ -1830,17 +1746,26 @@ do_connections_show (NmCli *nmc, int argc, char **argv) /* Try to find connection by id, uuid or path first */ connections = nm_client_get_connections (nmc->client); - con = nmc_find_connection (connections, selector, *argv, &pos, + con = nmc_find_connection (connections, selector, *argv, &found_cons, argc == 1 && nmc->complete); - if (!con && (!selector || strcmp (selector, "apath") == 0)) { + if ( !con + && NM_IN_STRSET (selector, NULL, "apath")) { /* Try apath too */ - acon = find_active_connection (active_cons, connections, "apath", *argv, NULL, - argc == 1 && nmc->complete); - if (acon) - con = NM_CONNECTION (nm_active_connection_get_connection (acon)); + explicit_acon = nmc_find_active_connection (active_cons, "apath", *argv, NULL, + argc == 1 && nmc->complete); + if (explicit_acon) { + if ( !selector + && !nm_streq0 (*argv, nm_object_get_path (NM_OBJECT (explicit_acon)))) { + /* we matched the apath based on the last component alone (note the full D-Bus path). + * That is how nmc_find_active_connection() works, if you pass in a selector. + * Reject it. */ + explicit_acon = NULL; + } + nm_g_object_ref (explicit_acon); + } } - if (!con && !acon) { + if (!con && !explicit_acon) { g_string_printf (nmc->return_text, _("Error: %s - no such connection profile."), *argv); nmc->return_value = NMC_RESULT_ERROR_NOT_FOUND; goto finish; @@ -1852,54 +1777,81 @@ do_connections_show (NmCli *nmc, int argc, char **argv) * may see only the active connection. */ - /* Filter only active connections */ - if (!acon) - acon = get_ac_for_connection (active_cons, con); - if (active_only && !acon) { - next_arg (nmc, &argc, &argv, NULL); - continue; - } - if (nmc->complete) { next_arg (nmc, &argc, &argv, NULL); continue; } - /* Show an empty line between connections */ - if (new_line) - g_print ("\n"); - - /* Show profile configuration */ - if (without_fields || profile_flds) { - if (con) { - nmc->required_fields = profile_flds; - if (nmc->nmc_config.show_secrets) - update_secrets_in_connection (NM_REMOTE_CONNECTION (con), con); - res = nmc_connection_profile_details (con, nmc); - nmc->required_fields = NULL; - if (!res) - goto finish; + explicit_acon_handled = FALSE; + i_found_cons = 0; + for (;;) { + gs_unref_ptrarray GPtrArray *found_acons = NULL; + + if (explicit_acon) { + if (explicit_acon_handled) + break; + explicit_acon_handled = TRUE; + /* the user referenced an "apath". In this case, we can only have at most one connection + * and one apath. */ + con = NM_CONNECTION (nm_active_connection_get_connection (explicit_acon)); + } else { + if (i_found_cons >= found_cons->len) + break; + con = found_cons->pdata[i_found_cons++]; + get_ac_for_connection (active_cons, con, &found_acons); } - } - /* If the profile is active, print also active details */ - if (without_fields || active_flds) { - if (acon) { - nmc->required_fields = active_flds; - res = nmc_active_connection_details (acon, nmc); - nmc->required_fields = NULL; - if (!res) - goto finish; + if (active_only && !explicit_acon && !found_acons) { + /* this connection is not interesting, we only print active ones. */ + continue; + } + + nm_assert (explicit_acon || con); + + if (new_line) + g_print ("\n"); + new_line = TRUE; + + if (without_fields || profile_flds) { + if (con) { + nmc->required_fields = profile_flds; + if (nmc->nmc_config.show_secrets) + update_secrets_in_connection (NM_REMOTE_CONNECTION (con), con); + res = nmc_connection_profile_details (con, nmc); + nmc->required_fields = NULL; + if (!res) + goto finish; + } + } + + if (without_fields || active_flds) { + guint l = explicit_acon ? 1 : (found_acons ? found_acons->len : 0); + + for (j = 0; j < l; j++) { + NMActiveConnection *acon; + + if (j > 0) { + /* if there are multiple active connections, separate them with newline. + * that is a bit odd, because we already separate connections with newlines, + * and commonly don't separate the connection from the first active connection. */ + g_print ("\n"); + } + + if (explicit_acon) + acon = explicit_acon; + else + acon = found_acons->pdata[j]; + + nmc->required_fields = active_flds; + res = nmc_active_connection_details (acon, nmc); + nmc->required_fields = NULL; + if (!res) + goto finish; + } } } - new_line = TRUE; - /* Take next argument. - * But for pos != NULL we have more connections of the same name, - * so process the same argument again. - */ - if (!pos) - next_arg (nmc, &argc, &argv, NULL); + next_arg (nmc, &argc, &argv, NULL); } } @@ -1907,12 +1859,7 @@ finish: if (err) { g_string_printf (nmc->return_text, _("Error: %s."), err->message); nmc->return_value = NMC_RESULT_ERROR_USER_INPUT; - g_error_free (err); } - g_free (profile_flds); - g_free (active_flds); - if (order) - g_array_unref (order); return nmc->return_value; } @@ -1925,8 +1872,8 @@ get_default_active_connection (NmCli *nmc, NMDevice **device) const GPtrArray *connections; int i; - g_return_val_if_fail (nmc != NULL, NULL); - g_return_val_if_fail (device != NULL, NULL); + g_return_val_if_fail (nmc, NULL); + g_return_val_if_fail (device, NULL); g_return_val_if_fail (*device == NULL, NULL); connections = nm_client_get_active_connections (nmc->client); @@ -1984,10 +1931,10 @@ find_device_for_connection (NmCli *nmc, const char *con_type; int i, j; - g_return_val_if_fail (nmc != NULL, FALSE); + g_return_val_if_fail (nmc, FALSE); g_return_val_if_fail (iface || ap || nsp, FALSE); - g_return_val_if_fail (device != NULL && *device == NULL, FALSE); - g_return_val_if_fail (spec_object != NULL && *spec_object == NULL, FALSE); + g_return_val_if_fail (device && *device == NULL, FALSE); + g_return_val_if_fail (spec_object && *spec_object == NULL, FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); s_con = nm_connection_get_setting_connection (connection); @@ -2042,8 +1989,10 @@ find_device_for_connection (NmCli *nmc, } found_device = dev; - if (ap && !strcmp (con_type, NM_SETTING_WIRELESS_SETTING_NAME) && NM_IS_DEVICE_WIFI (dev)) { - char *bssid_up = g_ascii_strup (ap, -1); + if ( ap + && nm_streq (con_type, NM_SETTING_WIRELESS_SETTING_NAME) + && NM_IS_DEVICE_WIFI (dev)) { + gs_free char *bssid_up = g_ascii_strup (ap, -1); const GPtrArray *aps = nm_device_wifi_get_access_points (NM_DEVICE_WIFI (dev)); found_device = NULL; /* Mark as not found; set to the device again later, only if AP matches */ @@ -2051,29 +2000,28 @@ find_device_for_connection (NmCli *nmc, NMAccessPoint *candidate_ap = g_ptr_array_index (aps, j); const char *candidate_bssid = nm_access_point_get_bssid (candidate_ap); - if (!strcmp (bssid_up, candidate_bssid)) { + if (nm_streq0 (bssid_up, candidate_bssid)) { found_device = dev; *spec_object = nm_object_get_path (NM_OBJECT (candidate_ap)); break; } } - g_free (bssid_up); } - } - if (found_device) { - *device = found_device; - return TRUE; - } else { - if (iface) + if (!found_device) { + if (iface) { g_set_error (error, NMCLI_ERROR, 0, _("device '%s' not compatible with connection '%s'"), iface, nm_setting_connection_get_id (s_con)); - else + } else { g_set_error (error, NMCLI_ERROR, 0, _("no device found for connection '%s'"), nm_setting_connection_get_id (s_con)); + } return FALSE; } + + *device = found_device; + return TRUE; } } @@ -2295,48 +2243,50 @@ activate_connection_cb (GObject *client, GAsyncResult *result, gpointer user_dat static GHashTable * parse_passwords (const char *passwd_file, GError **error) { - GHashTable *pwds_hash; - char *contents = NULL; + gs_unref_hashtable GHashTable *pwds_hash = NULL; + gs_free char *contents = NULL; gsize len = 0; GError *local_err = NULL; - char **lines, **iter; + gs_free const char **strv = NULL; + const char *const*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 pwds_hash; + return g_steal_pointer (&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; } - lines = nmc_strsplit_set (contents, "\r\n", -1); - for (iter = lines; *iter; iter++) { - pwd = strchr (*iter, ':'); + 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, ':'); if (!pwd) { g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT, _("missing colon in 'password' entry '%s'"), *iter); - goto failure; + return NULL; } *(pwd++) = '\0'; - prop = strchr (*iter, '.'); + prop = strchr (iter_s, '.'); if (!prop) { g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT, _("missing dot in 'password' entry '%s'"), *iter); - goto failure; + return NULL; } *(prop++) = '\0'; - setting = *iter; + setting = iter_s; while (g_ascii_isspace (*setting)) setting++; /* Accept wifi-sec or wifi instead of cumbersome '802-11-wireless-security' */ @@ -2345,25 +2295,15 @@ 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); - goto failure; + return NULL; } pwd_spec = g_strdup_printf ("%s.%s", setting, prop); g_hash_table_insert (pwds_hash, pwd_spec, g_strdup (pwd)); } - g_strfreev (lines); - g_free (contents); - return pwds_hash; - -failure: - g_strfreev (lines); - g_free (contents); - g_hash_table_destroy (pwds_hash); - return NULL; + return g_steal_pointer (&pwds_hash); } - - static gboolean nmc_activate_connection (NmCli *nmc, NMConnection *connection, @@ -2382,7 +2322,7 @@ nmc_activate_connection (NmCli *nmc, gboolean device_found; GError *local = NULL; - g_return_val_if_fail (nmc != NULL, FALSE); + g_return_val_if_fail (nmc, FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); if (connection && (ifname || ap || nsp)) { @@ -2482,7 +2422,7 @@ do_connection_up (NmCli *nmc, int argc, char **argv) } if (argc > 0 && strcmp (*argv, "ifname") != 0) { - connection = get_connection (nmc, argc_ptr, argv_ptr, NULL, &error); + connection = get_connection (nmc, argc_ptr, argv_ptr, NULL, NULL, NULL, &error); if (!connection) { g_string_printf (nmc->return_text, _("Error: %s."), error->message); return error->code; @@ -2561,20 +2501,108 @@ do_connection_up (NmCli *nmc, int argc, char **argv) return nmc->return_value; } +/*****************************************************************************/ + typedef struct { NmCli *nmc; - GSList *queue; + /* a list of object that is relevant for the callback. The object + * type differs, and depends on the type of callback. */ + GPtrArray *obj_list; guint timeout_id; GCancellable *cancellable; } ConnectionCbInfo; -static void connection_cb_info_finish (ConnectionCbInfo *info, - gpointer connection); +static void connection_removed_cb (NMClient *client, NMConnection *connection, ConnectionCbInfo *info); + +static void down_active_connection_state_cb (NMActiveConnection *active, + GParamSpec *pspec, + ConnectionCbInfo *info); + +static void +connection_cb_info_obj_list_destroy (ConnectionCbInfo *info, gpointer obj) +{ + nm_assert (info); + nm_assert (info->obj_list); + nm_assert (G_IS_OBJECT (obj)); + + g_signal_handlers_disconnect_by_func (obj, down_active_connection_state_cb, info); + g_object_unref (obj); +} + +static gssize +connection_cb_info_obj_list_idx (ConnectionCbInfo *info, gpointer obj) +{ + guint i; + + nm_assert (info); + nm_assert (info->obj_list); + nm_assert (G_IS_OBJECT (obj)); + + for (i = 0; i < info->obj_list->len; i++) { + if (info->obj_list->pdata[i] == obj) + return i; + } + return -1; +} + +static gpointer +connection_cb_info_obj_list_has (ConnectionCbInfo *info, gpointer obj) +{ + gssize idx; + + idx = connection_cb_info_obj_list_idx (info, obj); + if (idx >= 0) + return info->obj_list->pdata[idx]; + return NULL; +} + +static gpointer +connection_cb_info_obj_list_steal (ConnectionCbInfo *info, gpointer obj) +{ + gssize idx; + + idx = connection_cb_info_obj_list_idx (info, obj); + if (idx >= 0) { + g_ptr_array_remove_index (info->obj_list, idx); + return obj; + } + return NULL; +} + +static void +connection_cb_info_finish (ConnectionCbInfo *info, gpointer obj) +{ + if (obj) { + obj = connection_cb_info_obj_list_steal (info, obj); + if (obj) + connection_cb_info_obj_list_destroy (info, obj); + } else { + while (info->obj_list->len > 0) { + obj = info->obj_list->pdata[info->obj_list->len - 1]; + g_ptr_array_remove_index (info->obj_list, info->obj_list->len); + connection_cb_info_obj_list_destroy (info, obj); + } + } + + if (info->obj_list->len > 0) + return; + + nm_clear_g_source (&info->timeout_id); + nm_clear_g_cancellable (&info->cancellable); + + g_signal_handlers_disconnect_by_func (info->nmc->client, connection_removed_cb, info); + + g_slice_free (ConnectionCbInfo, info); + + quit (); +} + +/*****************************************************************************/ static void connection_removed_cb (NMClient *client, NMConnection *connection, ConnectionCbInfo *info) { - if (!g_slist_find (info->queue, connection)) + if (!connection_cb_info_obj_list_has (info, connection)) return; g_print (_("Connection '%s' (%s) successfully deleted.\n"), nm_connection_get_id (connection), @@ -2611,49 +2639,17 @@ connection_op_timeout_cb (gpointer user_data) return G_SOURCE_REMOVE; } -static void -destroy_queue_element (gpointer data) -{ - g_signal_handlers_disconnect_matched (data, G_SIGNAL_MATCH_FUNC, 0, 0, 0, - down_active_connection_state_cb, NULL); - g_object_unref (data); -} - -static void -connection_cb_info_finish (ConnectionCbInfo *info, gpointer connection) -{ - if (connection) { - info->queue = g_slist_remove (info->queue, connection); - g_object_unref (G_OBJECT (connection)); - } else { - g_slist_free_full (info->queue, destroy_queue_element); - info->queue = NULL; - } - - if (info->queue) - return; - - if (info->timeout_id) - g_source_remove (info->timeout_id); - - nm_clear_g_cancellable (&info->cancellable); - - g_signal_handlers_disconnect_by_func (info->nmc->client, connection_removed_cb, info); - g_slice_free (ConnectionCbInfo, info); - quit (); -} - static NMCResultCode do_connection_down (NmCli *nmc, int argc, char **argv) { NMActiveConnection *active; ConnectionCbInfo *info = NULL; const GPtrArray *active_cons; - GSList *queue = NULL, *iter, *next; - char **arg_arr = NULL; + gs_strfreev char **arg_arr = NULL; char **arg_ptr; int arg_num; - int idx = 0; + guint i; + gs_unref_ptrarray GPtrArray *found_active_cons = NULL; if (nmc->timeout == -1) nmc->timeout = 10; @@ -2674,108 +2670,88 @@ do_connection_down (NmCli *nmc, int argc, char **argv) } if (arg_num == 0) { g_string_printf (nmc->return_text, _("Error: No connection specified.")); - nmc->return_value = NMC_RESULT_ERROR_USER_INPUT; - goto finish; + NMC_RETURN (nmc, NMC_RESULT_ERROR_USER_INPUT); } } /* Get active connections */ active_cons = nm_client_get_active_connections (nmc->client); while (arg_num > 0) { - const GPtrArray *connections; const char *selector = NULL; if (arg_num == 1 && nmc->complete) nmc_complete_strings (*arg_ptr, "id", "uuid", "path", "apath", NULL); - if ( strcmp (*arg_ptr, "id") == 0 - || strcmp (*arg_ptr, "uuid") == 0 - || strcmp (*arg_ptr, "path") == 0 - || strcmp (*arg_ptr, "apath") == 0) { - + if (NM_IN_STRSET (*arg_ptr, "id", "uuid", "path", "apath")) { selector = *arg_ptr; arg_num--; arg_ptr++; if (!arg_num) { g_string_printf (nmc->return_text, _("Error: %s argument is missing."), selector); - nmc->return_value = NMC_RESULT_ERROR_USER_INPUT; - goto finish; + NMC_RETURN (nmc, NMC_RESULT_ERROR_USER_INPUT); } } - connections = nm_client_get_connections (nmc->client); - active = find_active_connection (active_cons, connections, selector, *arg_ptr, &idx, - arg_num == 1 && nmc->complete); - if (active) { - /* Check if the connection is unique. */ - /* Calling down for the same connection repeatedly would result in - * NM responding for the last D-Bus call only and we would stall. */ - if (!g_slist_find (queue, active)) - queue = g_slist_prepend (queue, g_object_ref (active)); - } else { + active = nmc_find_active_connection (active_cons, + selector, + *arg_ptr, + &found_active_cons, + arg_num == 1 && nmc->complete); + if (!active) { if (!nmc->complete) g_printerr (_("Error: '%s' is not an active connection.\n"), *arg_ptr); g_string_printf (nmc->return_text, _("Error: not all active connections found.")); nmc->return_value = NMC_RESULT_ERROR_NOT_FOUND; } - if (idx == 0) - next_arg (nmc->ask ? NULL : nmc, &arg_num, &arg_ptr, NULL); + next_arg (nmc->ask ? NULL : nmc, &arg_num, &arg_ptr, NULL); } - if (!queue) { + if (!found_active_cons) { g_string_printf (nmc->return_text, _("Error: no active connection provided.")); - nmc->return_value = NMC_RESULT_ERROR_NOT_FOUND; - goto finish; - } else if (nmc->complete) { - g_slist_free (queue); - goto finish; + NMC_RETURN (nmc, NMC_RESULT_ERROR_NOT_FOUND); } - queue = g_slist_reverse (queue); + nm_assert (found_active_cons->len > 0); + + if (nmc->complete) + return nmc->return_value; if (nmc->timeout > 0) { nmc->should_wait++; info = g_slice_new0 (ConnectionCbInfo); info->nmc = nmc; - info->queue = queue; - info->timeout_id = g_timeout_add_seconds (nmc->timeout, connection_op_timeout_cb, info); - } - - iter = queue; - while (iter) { - GError *error = NULL; - - next = g_slist_next (iter); - active = iter->data; - - if (info) { + info->obj_list = g_ptr_array_sized_new (found_active_cons->len); + for (i = 0; i < found_active_cons->len; i++) { + active = found_active_cons->pdata[i]; + g_ptr_array_add (info->obj_list, g_object_ref (active)); g_signal_connect (active, "notify::" NM_ACTIVE_CONNECTION_STATE, G_CALLBACK (down_active_connection_state_cb), info); } + info->timeout_id = g_timeout_add_seconds (nmc->timeout, connection_op_timeout_cb, info); + } + + for (i = 0; i < found_active_cons->len; i++) { + GError *error = NULL; + + active = found_active_cons->pdata[i]; - /* Now deactivate the connection */ if (!nm_client_deactivate_connection (nmc->client, active, NULL, &error)) { g_print (_("Connection '%s' deactivation failed: %s\n"), nm_active_connection_get_id (active), error->message); - g_error_free (error); + g_clear_error (&error); if (info) { g_signal_handlers_disconnect_by_func (active, down_active_connection_state_cb, info); - /* Remove the active connection from @queue */ connection_cb_info_finish (info, active); } } - - iter = next; } -finish: - g_strfreev (arg_arr); return nmc->return_value; } @@ -3339,7 +3315,7 @@ _dynamic_options_set (const NMMetaAbstractInfo *abstract_info, PropertyInfFlags v, v2; if (G_UNLIKELY (!cache)) - cache = g_hash_table_new (NULL, NULL); + cache = g_hash_table_new (nm_direct_hash, NULL); if (g_hash_table_lookup_extended (cache, (gpointer) abstract_info, NULL, &p)) v = GPOINTER_TO_UINT (p); @@ -3595,6 +3571,7 @@ set_property (NMConnection *connection, */ if (value) { unsigned long idx; + if (nmc_string_to_uint (value, TRUE, 0, G_MAXUINT32, &idx)) nmc_setting_remove_property_option (setting, property_name, NULL, idx, &local); else @@ -4265,7 +4242,7 @@ nmc_read_connection_properties (NmCli *nmc, return FALSE; if (!*argc && nmc->complete) - complete_property (setting, strv[1], value ? value : "", connection); + complete_property (setting, strv[1], value ?: "", connection); if (!set_property (connection, setting_name, strv[1], value, modifier, error)) return FALSE; @@ -4346,7 +4323,7 @@ nmc_read_connection_properties (NmCli *nmc, return FALSE; if (!*argc && nmc->complete) - complete_option (chosen, value ? value : "", connection); + complete_option (chosen, value ?: "", connection); if (!set_option (nmc, connection, chosen, value, error)) return FALSE; @@ -4457,8 +4434,8 @@ nmcli_con_add_tab_completion (const char *text, int start, int end) NMMetaSettingType s; char **match_array = NULL; rl_compentry_func_t *generator_func = NULL; - gs_free char *no = g_strdup_printf ("[%s]: ", gettext ("no")); - gs_free char *yes = g_strdup_printf ("[%s]: ", gettext ("yes")); + gs_free char *no = g_strdup_printf ("[%s]: ", _("no")); + gs_free char *yes = g_strdup_printf ("[%s]: ", _("yes")); /* Disable readline's default filename completion */ rl_attempted_completion_over = 1; @@ -4741,9 +4718,9 @@ again: static NMCResultCode do_connection_add (NmCli *nmc, int argc, char **argv) { - NMConnection *connection = NULL; + gs_unref_object NMConnection *connection = NULL; NMSettingConnection *s_con; - GError *error = NULL; + gs_free_error GError *error = NULL; AddConnectionInfo *info = NULL; gboolean save_bool = TRUE; gboolean seen_dash_dash = FALSE; @@ -4755,27 +4732,24 @@ do_connection_add (NmCli *nmc, int argc, char **argv) nmc->return_value = NMC_RESULT_SUCCESS; - /* Create a new connection object */ connection = nm_simple_connection_new (); - /* Build up the 'connection' setting */ s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); read_properties: + g_clear_error (&error); /* Get the arguments from the command line if any */ if (argc && !nmc_read_connection_properties (nmc, connection, &argc, &argv, &error)) { if (g_strcmp0 (*argv, "--") == 0 && !seen_dash_dash) { /* This is for compatibility with older nmcli that required * options and properties to be separated with "--" */ - g_clear_error (&error); seen_dash_dash = TRUE; next_arg (nmc, &argc, &argv, NULL); goto read_properties; } else if (g_strcmp0 (*argv, "save") == 0) { /* It would be better if "save" was a separate argument and not * mixed with properties, but there's not much we can do about it now. */ - g_clear_error (&error); argc--; argv++; if (!argc) { @@ -4785,11 +4759,11 @@ read_properties: nmc->return_value = NMC_RESULT_ERROR_USER_INPUT; goto finish; } + g_clear_error (&error); if (!nmc_string_to_bool (*argv, &save_bool, &error)) { g_string_printf (nmc->return_text, _("Error: 'save': %s."), error->message); nmc->return_value = NMC_RESULT_ERROR_USER_INPUT; - g_clear_error (&error); goto finish; } next_arg (nmc, &argc, &argv, NULL); @@ -4798,7 +4772,6 @@ read_properties: g_string_assign (nmc->return_text, error->message); nmc->return_value = error->code; - g_clear_error (&error); goto finish; } @@ -4908,9 +4881,6 @@ read_properties: finish: reset_options (); - if (connection) - g_object_unref (connection); - return nmc->return_value; } @@ -4962,15 +4932,7 @@ gen_nmcli_cmds_submenu (const char *text, int state) static char * gen_cmd_nmcli (const char *text, int state) { - const char *words[] = { "status-line", "save-confirmation", "show-secrets", "prompt-color", NULL }; - return nmc_rl_gen_func_basic (text, state, words); -} - -static char * -gen_cmd_nmcli_prompt_color (const char *text, int state) -{ - const char *words[] = { "normal", "black", "red", "green", "yellow", - "blue", "magenta", "cyan", "white", NULL }; + const char *words[] = { "status-line", "save-confirmation", "show-secrets", NULL }; return nmc_rl_gen_func_basic (text, state, words); } @@ -5286,8 +5248,6 @@ get_gen_func_cmd_nmcli (const char *str) return gen_func_bool_values; if (matches (str, "show-secrets")) return gen_func_bool_values; - if (matches (str, "prompt-color")) - return gen_cmd_nmcli_prompt_color; return NULL; } @@ -5889,50 +5849,80 @@ 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_utils_is_separator (cmd[0])) + cmd++; + if (!cmd[0]) + return; + + l = strcspn (cmd, " \t"); + arg0 = g_strndup (cmd, l); + cmd += l; + if (cmd[0]) { + while (nm_utils_is_separator (cmd[0])) + 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; - char **vec; + gs_free char *cmd_arg0 = NULL; + const char *cmd_argr; - 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; - } + _split_cmd (cmd, &cmd_arg0, &cmd_argr); + if (!cmd_arg0) + goto fail; - if (matches (vec[0], "goto")) + if (matches (cmd_arg0, "goto")) editor_cmd = NMC_EDITOR_MAIN_CMD_GOTO; - else if (matches (vec[0], "remove")) + else if (matches (cmd_arg0, "remove")) editor_cmd = NMC_EDITOR_MAIN_CMD_REMOVE; - else if (matches (vec[0], "set")) + else if (matches (cmd_arg0, "set")) editor_cmd = NMC_EDITOR_MAIN_CMD_SET; - else if (matches (vec[0], "describe")) + else if (matches (cmd_arg0, "describe")) editor_cmd = NMC_EDITOR_MAIN_CMD_DESCRIBE; - else if (matches (vec[0], "print")) + else if (matches (cmd_arg0, "print")) editor_cmd = NMC_EDITOR_MAIN_CMD_PRINT; - else if (matches (vec[0], "verify")) + else if (matches (cmd_arg0, "verify")) editor_cmd = NMC_EDITOR_MAIN_CMD_VERIFY; - else if (matches (vec[0], "save")) + else if (matches (cmd_arg0, "save")) editor_cmd = NMC_EDITOR_MAIN_CMD_SAVE; - else if (matches (vec[0], "activate")) + else if (matches (cmd_arg0, "activate")) editor_cmd = NMC_EDITOR_MAIN_CMD_ACTIVATE; - else if (matches (vec[0], "back")) + else if (matches (cmd_arg0, "back")) editor_cmd = NMC_EDITOR_MAIN_CMD_BACK; - else if (matches (vec[0], "help") || strcmp (vec[0], "?") == 0) + else if (matches (cmd_arg0, "help") || strcmp (cmd_arg0, "?") == 0) editor_cmd = NMC_EDITOR_MAIN_CMD_HELP; - else if (matches (vec[0], "quit")) + else if (matches (cmd_arg0, "quit")) editor_cmd = NMC_EDITOR_MAIN_CMD_QUIT; - else if (matches (vec[0], "nmcli")) + else if (matches (cmd_arg0, "nmcli")) editor_cmd = NMC_EDITOR_MAIN_CMD_NMCLI; + else + goto fail; - /* set pointer to command argument */ - if (cmd_arg) - *cmd_arg = vec[1] ? g_strstrip (g_strdup (vec[1])) : NULL; - - g_strfreev (vec); + NM_SET_OUT (cmd_arg, g_strdup (cmd_argr)); return editor_cmd; +fail: + NM_SET_OUT (cmd_arg, NULL); + return NMC_EDITOR_MAIN_CMD_UNKNOWN; } static void @@ -6081,40 +6071,39 @@ static NmcEditorSubCmd parse_editor_sub_cmd (const char *cmd, char **cmd_arg) { NmcEditorSubCmd editor_cmd = NMC_EDITOR_SUB_CMD_UNKNOWN; - char **vec; + gs_free char *cmd_arg0 = NULL; + const char *cmd_argr; - 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; - } + _split_cmd (cmd, &cmd_arg0, &cmd_argr); + if (!cmd_arg0) + goto fail; - if (matches (vec[0], "set")) + if (matches (cmd_arg0, "set")) editor_cmd = NMC_EDITOR_SUB_CMD_SET; - else if (matches (vec[0], "add")) + else if (matches (cmd_arg0, "add")) editor_cmd = NMC_EDITOR_SUB_CMD_ADD; - else if (matches (vec[0], "change")) + else if (matches (cmd_arg0, "change")) editor_cmd = NMC_EDITOR_SUB_CMD_CHANGE; - else if (matches (vec[0], "remove")) + else if (matches (cmd_arg0, "remove")) editor_cmd = NMC_EDITOR_SUB_CMD_REMOVE; - else if (matches (vec[0], "describe")) + else if (matches (cmd_arg0, "describe")) editor_cmd = NMC_EDITOR_SUB_CMD_DESCRIBE; - else if (matches (vec[0], "print")) + else if (matches (cmd_arg0, "print")) editor_cmd = NMC_EDITOR_SUB_CMD_PRINT; - else if (matches (vec[0], "back")) + else if (matches (cmd_arg0, "back")) editor_cmd = NMC_EDITOR_SUB_CMD_BACK; - else if (matches (vec[0], "help") || strcmp (vec[0], "?") == 0) + else if (matches (cmd_arg0, "help") || strcmp (cmd_arg0, "?") == 0) editor_cmd = NMC_EDITOR_SUB_CMD_HELP; - else if (matches (vec[0], "quit")) + else if (matches (cmd_arg0, "quit")) editor_cmd = NMC_EDITOR_SUB_CMD_QUIT; + else + goto fail; - /* set pointer to command argument */ - if (cmd_arg) - *cmd_arg = g_strdup (vec[1]); - - g_strfreev (vec); + NM_SET_OUT (cmd_arg, g_strdup (cmd_argr)); return editor_cmd; +fail: + NM_SET_OUT (cmd_arg, NULL); + return NMC_EDITOR_SUB_CMD_UNKNOWN; } static void @@ -6259,8 +6248,8 @@ static gboolean progress_activation_editor_cb (gpointer user_data) { MonitorACInfo *info = (MonitorACInfo *) user_data; - NMDevice *device = info->device; - NMActiveConnection *ac = info->ac; + gs_unref_object NMDevice *device = info->device; + gs_unref_object NMActiveConnection *ac = info->ac; NMActiveConnectionState ac_state; NMDeviceState dev_state; @@ -6277,12 +6266,12 @@ progress_activation_editor_cb (gpointer user_data) nmc_terminal_erase_line (); g_print (_("Connection successfully activated (D-Bus active path: %s)\n"), nm_object_get_path (NM_OBJECT (ac))); - goto finish; /* we are done */ + goto finish; } else if ( ac_state == NM_ACTIVE_CONNECTION_STATE_DEACTIVATED || dev_state == NM_DEVICE_STATE_FAILED) { nmc_terminal_erase_line (); g_print (_("Error: Connection activation failed.\n")); - goto finish; /* we are done */ + goto finish; } if (info->nmc->secret_agent) { @@ -6297,10 +6286,6 @@ progress_activation_editor_cb (gpointer user_data) finish: info->monitor_id = 0; - if (device) - g_object_unref (device); - if (ac) - g_object_unref (ac); return FALSE; } @@ -6405,7 +6390,7 @@ refresh_remote_connection (GWeakRef *weak, NMRemoteConnection **remote) { gboolean previous; - g_return_val_if_fail (remote != NULL, FALSE); + g_return_val_if_fail (remote, FALSE); previous = (*remote != NULL); if (*remote) @@ -6454,33 +6439,31 @@ property_edit_submenu (NmCli *nmc, const char *prop_name) { NmcEditorSubCmd cmdsub; - gboolean cmd_property_loop = TRUE; - gboolean should_quit = FALSE; - char *prop_val_user; gboolean set_result; GError *tmp_err = NULL; - char *prompt; - gboolean dirty; - GValue prop_g_value = G_VALUE_INIT; + gs_free char *prompt = NULL; gboolean temp_changes; - gboolean removed; /* Set global variable for use in TAB completion */ nmc_tab_completion.property = prop_name; - prompt = nmc_colorize (nmc->nmc_config.use_colors, nmc->editor_prompt_color, NM_META_TERM_FORMAT_NORMAL, - "nmcli %s.%s> ", + prompt = nmc_colorize (&nmc->nmc_config, NM_META_COLOR_PROMPT, "nmcli %s.%s> ", nm_setting_get_name (curr_setting), prop_name); - while (cmd_property_loop) { - char *cmd_property_user; - char *cmd_property_arg; + for (;;) { + gs_free char *cmd_property_user = NULL; + gs_free char *cmd_property_arg = NULL; + gs_free char *prop_val_user = NULL; + nm_auto_unset_gvalue GValue prop_g_value = G_VALUE_INIT; + gboolean removed; + gboolean dirty; /* Get the remote connection again, it may have disapeared */ removed = refresh_remote_connection (rem_con_weak, rem_con); - if (removed) + if (removed) { g_print (_("The connection profile has been removed from another client. " "You may type 'save' in the main menu to restore it.\n")); + } /* Connection is dirty? (not saved or differs from the saved) */ dirty = is_connection_dirty (connection, *rem_con); @@ -6489,7 +6472,7 @@ property_edit_submenu (NmCli *nmc, editor_show_status_line (connection, dirty, temp_changes); cmd_property_user = nmc_readline ("%s", prompt); - if (!cmd_property_user || *cmd_property_user == '\0') + if (!cmd_property_user || !*cmd_property_user) continue; cmdsub = parse_editor_sub_cmd (g_strstrip (cmd_property_user), &cmd_property_arg); @@ -6525,7 +6508,6 @@ property_edit_submenu (NmCli *nmc, } set_result = nmc_setting_set_property (curr_setting, prop_name, prop_val_user, &tmp_err); - g_free (prop_val_user); if (!set_result) { g_print (_("Error: failed to set '%s' property: %s\n"), prop_name, tmp_err->message); g_clear_error (&tmp_err); @@ -6536,8 +6518,6 @@ property_edit_submenu (NmCli *nmc, g_signal_handlers_unblock_matched (curr_setting, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, NULL); } } - if (G_IS_VALUE (&prop_g_value)) - g_value_unset (&prop_g_value); break; case NMC_EDITOR_SUB_CMD_CHANGE: @@ -6555,9 +6535,6 @@ property_edit_submenu (NmCli *nmc, nmc_property_set_gvalue (curr_setting, prop_name, &prop_g_value); g_signal_handlers_unblock_matched (curr_setting, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, NULL); } - g_free (prop_val_user); - if (G_IS_VALUE (&prop_g_value)) - g_value_unset (&prop_g_value); break; case NMC_EDITOR_SUB_CMD_REMOVE: @@ -6610,8 +6587,7 @@ property_edit_submenu (NmCli *nmc, case NMC_EDITOR_SUB_CMD_BACK: /* Set global variable for use in TAB completion */ nmc_tab_completion.property = NULL; - cmd_property_loop = FALSE; - break; + return TRUE; case NMC_EDITOR_SUB_CMD_HELP: editor_sub_usage (cmd_property_arg); @@ -6619,14 +6595,10 @@ property_edit_submenu (NmCli *nmc, case NMC_EDITOR_SUB_CMD_QUIT: if (is_connection_dirty (connection, *rem_con)) { - if (confirm_quit ()) { - cmd_property_loop = FALSE; - should_quit = TRUE; /* we will quit nmcli */ - } - } else { - cmd_property_loop = FALSE; - should_quit = TRUE; /* we will quit nmcli */ - } + if (confirm_quit ()) + return FALSE; + } else + return FALSE; break; case NMC_EDITOR_SUB_CMD_UNKNOWN: @@ -6634,12 +6606,7 @@ property_edit_submenu (NmCli *nmc, g_print (_("Unknown command: '%s'\n"), cmd_property_user); break; } - g_free (cmd_property_user); - g_free (cmd_property_arg); } - g_free (prompt); - - return !should_quit; } /* @@ -6650,29 +6617,26 @@ property_edit_submenu (NmCli *nmc, static void split_editor_main_cmd_args (const char *str, char **setting, char **property, char **value) { - char **args, **items; + gs_free char *cmd_arg0 = NULL; + const char *cmd_argr; + const char *s; - if (!str) - return; + NM_SET_OUT (setting, NULL); + NM_SET_OUT (property, NULL); + NM_SET_OUT (value, NULL); - 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); + _split_cmd (str, &cmd_arg0, &cmd_argr); + if (!cmd_arg0) + return; - if (value && args[1]) - *value = g_strstrip (g_strdup (args[1])); + 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)); } - g_strfreev (args); } static NMSetting * @@ -6793,7 +6757,7 @@ confirm_connection_saving (NMConnection *local, NMConnection *remote) return confirmed; } -typedef struct { +typedef struct { guint level; char *main_prompt; NMSetting *curr_setting; @@ -6802,14 +6766,13 @@ typedef struct { } NmcEditorMenuContext; static void -menu_switch_to_level0 (NmcColorOption color_option, +menu_switch_to_level0 (const NmcConfig *nmc_config, NmcEditorMenuContext *menu_ctx, - const char *prompt, - NMMetaTermColor prompt_color) + const char *prompt) { menu_ctx->level = 0; g_free (menu_ctx->main_prompt); - menu_ctx->main_prompt = nmc_colorize (color_option, prompt_color, NM_META_TERM_FORMAT_NORMAL, "%s", prompt); + menu_ctx->main_prompt = nmc_colorize (nmc_config, NM_META_COLOR_PROMPT, "%s", prompt); menu_ctx->curr_setting = NULL; g_strfreev (menu_ctx->valid_props); menu_ctx->valid_props = NULL; @@ -6818,16 +6781,14 @@ menu_switch_to_level0 (NmcColorOption color_option, } static void -menu_switch_to_level1 (NmcColorOption color_option, +menu_switch_to_level1 (const NmcConfig *nmc_config, NmcEditorMenuContext *menu_ctx, NMSetting *setting, - const char *setting_name, - NMMetaTermColor prompt_color) + const char *setting_name) { menu_ctx->level = 1; g_free (menu_ctx->main_prompt); - menu_ctx->main_prompt = nmc_colorize (color_option, prompt_color, NM_META_TERM_FORMAT_NORMAL, - "nmcli %s> ", setting_name); + menu_ctx->main_prompt = nmc_colorize (nmc_config, NM_META_COLOR_PROMPT, "nmcli %s> ", setting_name); menu_ctx->curr_setting = setting; g_strfreev (menu_ctx->valid_props); menu_ctx->valid_props = nmc_setting_get_valid_properties (menu_ctx->curr_setting); @@ -6850,7 +6811,6 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t gs_free char *valid_settings_str = NULL; const char *s_type = NULL; AddConnectionInfo *info = NULL; - gboolean dirty; gboolean temp_changes; GError *err1 = NULL; NmcEditorMenuContext menu_ctx = { 0 }; @@ -6865,8 +6825,7 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t valid_settings_str = get_valid_options_string (valid_settings_main, valid_settings_slave); g_print (_("You may edit the following settings: %s\n"), valid_settings_str); - menu_ctx.main_prompt = nmc_colorize (nmc->nmc_config.use_colors, nmc->editor_prompt_color, NM_META_TERM_FORMAT_NORMAL, - BASE_PROMPT); + menu_ctx.main_prompt = nmc_colorize (&nmc->nmc_config, NM_META_COLOR_PROMPT, BASE_PROMPT); /* Get remote connection */ con_tmp = nm_client_get_connection_by_uuid (nmc->client, @@ -6880,6 +6839,7 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t gs_free char *cmd_arg_s = NULL; gs_free char *cmd_arg_p = NULL; gs_free char *cmd_arg_v = NULL; + gboolean dirty; /* Connection is dirty? (not saved or differs from the saved) */ dirty = is_connection_dirty (connection, rem_con); @@ -6887,17 +6847,18 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t if (nmc->editor_status_line) editor_show_status_line (connection, dirty, temp_changes); - /* Read user input */ cmd_user = nmc_readline ("%s", menu_ctx.main_prompt); /* Get the remote connection again, it may have disapeared */ removed = refresh_remote_connection (&weak, &rem_con); - if (removed) + if (removed) { g_print (_("The connection profile has been removed from another client. " "You may type 'save' to restore it.\n")); + } - if (!cmd_user || *cmd_user == '\0') + if (!cmd_user || !*cmd_user) continue; + cmd = parse_editor_main_cmd (g_strstrip (cmd_user), &cmd_arg); split_editor_main_cmd_args (cmd_arg, &cmd_arg_s, &cmd_arg_p, &cmd_arg_v); @@ -7005,7 +6966,7 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t /* in top level - no setting selected yet */ const char *setting_name; NMSetting *setting; - const char *user_arg = cmd_arg_s ? cmd_arg_s : cmd_arg_p; + const char *user_arg = cmd_arg_s ?: cmd_arg_p; setting_name = ask_check_setting (user_arg, valid_settings_main, @@ -7042,7 +7003,7 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t nmc_tab_completion.setting = setting; /* Switch to level 1 */ - menu_switch_to_level1 (nmc->nmc_config.use_colors, &menu_ctx, setting, setting_name, nmc->editor_prompt_color); + menu_switch_to_level1 (&nmc->nmc_config, &menu_ctx, setting, setting_name); if (!cmd_arg_s) { g_print (_("You may edit the following properties: %s\n"), menu_ctx.valid_props_str); @@ -7097,7 +7058,7 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t /* cmd_arg_s != NULL means argument is "setting.property" */ descr_all = !cmd_arg_s && !menu_ctx.curr_setting; - user_s = descr_all ? cmd_arg_p : cmd_arg_s ? cmd_arg_s : NULL; + user_s = descr_all ? cmd_arg_p : cmd_arg_s; if (user_s) { ss = is_setting_valid (connection, valid_settings_main, @@ -7124,7 +7085,7 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t connection_remove_setting (connection, ss); if (ss == menu_ctx.curr_setting) { /* If we removed the setting we are in, go up */ - menu_switch_to_level0 (nmc->nmc_config.use_colors, &menu_ctx, BASE_PROMPT, nmc->editor_prompt_color); + menu_switch_to_level0 (&nmc->nmc_config, &menu_ctx, BASE_PROMPT); nmc_tab_completion.setting = NULL; /* for TAB completion */ } } else { @@ -7152,7 +7113,7 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t /* coverity[copy_paste_error] - suppress Coverity COPY_PASTE_ERROR defect */ if (ss == menu_ctx.curr_setting) { /* If we removed the setting we are in, go up */ - menu_switch_to_level0 (nmc->nmc_config.use_colors, &menu_ctx, BASE_PROMPT, nmc->editor_prompt_color); + menu_switch_to_level0 (&nmc->nmc_config, &menu_ctx, BASE_PROMPT); nmc_tab_completion.setting = NULL; /* for TAB completion */ } } else @@ -7190,7 +7151,7 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t /* cmd_arg_s != NULL means argument is "setting.property" */ descr_all = !cmd_arg_s && !menu_ctx.curr_setting; - user_s = descr_all ? cmd_arg_p : cmd_arg_s ? cmd_arg_s : NULL; + user_s = descr_all ? cmd_arg_p : cmd_arg_s; if (user_s) { ss = is_setting_valid (connection, valid_settings_main, @@ -7247,7 +7208,7 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t case NMC_EDITOR_MAIN_CMD_PRINT: /* Print current connection settings/properties */ if (cmd_arg) { - if (strcmp (cmd_arg, "all") == 0) + if (nm_streq (cmd_arg, "all")) editor_show_connection (connection, nmc); else { NMSetting *ss = NULL; @@ -7256,7 +7217,7 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t /* cmd_arg_s != NULL means argument is "setting.property" */ whole_setting = !cmd_arg_s && !menu_ctx.curr_setting; - user_s = whole_setting ? cmd_arg_p : cmd_arg_s ? cmd_arg_s : NULL; + user_s = whole_setting ? cmd_arg_p : cmd_arg_s; if (user_s) { const char *s_name; @@ -7508,7 +7469,7 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t case NMC_EDITOR_MAIN_CMD_BACK: /* Go back (up) an the menu */ if (menu_ctx.level == 1) { - menu_switch_to_level0 (nmc->nmc_config.use_colors, &menu_ctx, BASE_PROMPT, nmc->editor_prompt_color); + menu_switch_to_level0 (&nmc->nmc_config, &menu_ctx, BASE_PROMPT); nmc_tab_completion.setting = NULL; /* for TAB completion */ } break; @@ -7544,37 +7505,18 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t } else nmc->nmc_config_mutable.show_secrets = bb; } else if (cmd_arg_p && matches (cmd_arg_p, "prompt-color")) { - GError *tmp_err = NULL; - NMMetaTermColor color; - color = nmc_term_color_parse_string (cmd_arg_v ? g_strstrip (cmd_arg_v) : " ", &tmp_err); - if (tmp_err) { - g_print (_("Error: bad color: %s\n"), tmp_err->message); - g_clear_error (&tmp_err); - } else { - nmc->editor_prompt_color = color; - nm_clear_g_free (&menu_ctx.main_prompt); - if (menu_ctx.level == 0) { - menu_ctx.main_prompt = nmc_colorize (nmc->nmc_config.use_colors, nmc->editor_prompt_color, NM_META_TERM_FORMAT_NORMAL, - BASE_PROMPT); - } else { - menu_ctx.main_prompt = nmc_colorize (nmc->nmc_config.use_colors, nmc->editor_prompt_color, NM_META_TERM_FORMAT_NORMAL, - "nmcli %s> ", - nm_setting_get_name (menu_ctx.curr_setting)); - } - } + g_debug ("Ignoring erroneous --prompt-color argument. Use terminal-colors.d(5) to set the prompt color.\n"); } else if (!cmd_arg_p) { g_print (_("Current nmcli configuration:\n")); g_print ("status-line: %s\n" "save-confirmation: %s\n" - "show-secrets: %s\n" - "prompt-color: %d\n", + "show-secrets: %s\n", nmc->editor_status_line ? "yes" : "no", nmc->editor_save_confirmation ? "yes" : "no", - nmc->nmc_config.show_secrets ? "yes" : "no", - nmc->editor_prompt_color); + nmc->nmc_config.show_secrets ? "yes" : "no"); } else g_print (_("Invalid configuration option '%s'; allowed [%s]\n"), - cmd_arg_v ? cmd_arg_v : "", "status-line, save-confirmation, show-secrets, prompt-color"); + cmd_arg_v ?: "", "status-line, save-confirmation, show-secrets"); break; @@ -7645,7 +7587,7 @@ editor_init_new_connection (NmCli *nmc, NMConnection *connection, const char *sl g_object_set (s_con, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, - NM_SETTING_CONNECTION_MASTER, dev_ifname ? dev_ifname : "eth0", + NM_SETTING_CONNECTION_MASTER, dev_ifname ?: "eth0", NM_SETTING_CONNECTION_SLAVE_TYPE, slave_type, NULL); } else { @@ -7666,11 +7608,10 @@ editor_init_new_connection (NmCli *nmc, NMConnection *connection, const char *sl const char *dev_ifname = get_ethernet_device_name (nmc); g_object_set (NM_SETTING_VLAN (base_setting), - NM_SETTING_VLAN_PARENT, dev_ifname ? dev_ifname : "eth0", + NM_SETTING_VLAN_PARENT, dev_ifname ?: "eth0", NULL); } - setting = nm_meta_setting_info_editor_new_setting (&nm_meta_setting_infos_editor[NM_META_SETTING_TYPE_IP4_CONFIG], NM_META_ACCESSOR_SETTING_INIT_TYPE_CLI); nm_connection_add_setting (connection, setting); @@ -7731,28 +7672,24 @@ static NMCResultCode do_connection_edit (NmCli *nmc, int argc, char **argv) { const GPtrArray *connections; - NMConnection *connection = NULL; + gs_unref_object NMConnection *connection = NULL; NMSettingConnection *s_con; const char *connection_type; - char *uuid; - char *default_name = NULL; const char *type = NULL; - char *type_ask = NULL; const char *con_name = NULL; const char *con = NULL; const char *con_id = NULL; const char *con_uuid = NULL; const char *con_path = NULL; const char *selector = NULL; - char *tmp_str; - GError *error = NULL; + gs_free_error GError *error = NULL; GError *err1 = NULL; - nmc_arg_t exp_args[] = { {"type", TRUE, &type, FALSE}, - {"con-name", TRUE, &con_name, FALSE}, - {"id", TRUE, &con_id, FALSE}, - {"uuid", TRUE, &con_uuid, FALSE}, - {"path", TRUE, &con_path, FALSE}, - {NULL} }; + nmc_arg_t exp_args[] = { { "type", TRUE, &type, FALSE }, + { "con-name", TRUE, &con_name, FALSE }, + { "id", TRUE, &con_id, FALSE }, + { "uuid", TRUE, &con_uuid, FALSE }, + { "path", TRUE, &con_path, FALSE }, + { NULL } }; next_arg (nmc, &argc, &argv, NULL); if (argc == 1 && nmc->complete) @@ -7765,9 +7702,7 @@ do_connection_edit (NmCli *nmc, int argc, char **argv) else { if (!nmc_parse_args (exp_args, TRUE, &argc, &argv, &error)) { g_string_assign (nmc->return_text, error->message); - nmc->return_value = error->code; - g_clear_error (&error); - goto error; + NMC_RETURN (nmc, error->code); } } @@ -7794,8 +7729,7 @@ do_connection_edit (NmCli *nmc, int argc, char **argv) } else { g_string_printf (nmc->return_text, _("Error: only one of 'id', uuid, or 'path' can be provided.")); - nmc->return_value = NMC_RESULT_ERROR_USER_INPUT; - goto error; + NMC_RETURN (nmc, NMC_RESULT_ERROR_USER_INPUT); } } @@ -7805,12 +7739,11 @@ do_connection_edit (NmCli *nmc, int argc, char **argv) found_con = nmc_find_connection (connections, selector, con, NULL, nmc->complete); if (nmc->complete) - goto error; + return nmc->return_value; if (!found_con) { g_string_printf (nmc->return_text, _("Error: Unknown connection '%s'."), con); - nmc->return_value = NMC_RESULT_ERROR_NOT_FOUND; - goto error; + NMC_RETURN (nmc, NMC_RESULT_ERROR_NOT_FOUND); } /* Duplicate the connection and use that so that we need not @@ -7822,7 +7755,6 @@ do_connection_edit (NmCli *nmc, int argc, char **argv) update_secrets_in_connection (NM_REMOTE_CONNECTION (found_con), connection); s_con = nm_connection_get_setting_connection (connection); - g_assert (s_con); connection_type = nm_setting_connection_get_connection_type (s_con); if (type) @@ -7838,18 +7770,23 @@ do_connection_edit (NmCli *nmc, int argc, char **argv) editor_init_existing_connection (connection); } else { const char *slave_type = NULL; + gs_free char *uuid = NULL; + gs_free char *default_name = NULL; + gs_free char *tmp_str = NULL; /* New connection */ if (nmc->complete) { if (type && argc == 0) nmc_complete_connection_type (type); - goto error; + return nmc->return_value; } connection_type = check_valid_name_toplevel (type, &slave_type, &err1); tmp_str = get_valid_options_string_toplevel (); while (!connection_type) { + gs_free char *type_ask = NULL; + if (!type) g_print (_("Valid connection types: %s\n"), tmp_str); else @@ -7859,14 +7796,11 @@ do_connection_edit (NmCli *nmc, int argc, char **argv) type_ask = nmc_readline (EDITOR_PROMPT_CON_TYPE); type = type_ask = type_ask ? g_strstrip (type_ask) : NULL; connection_type = check_valid_name_toplevel (type_ask, &slave_type, &err1); - g_free (type_ask); } - g_free (tmp_str); + nm_clear_g_free (&tmp_str); - /* Create a new connection object */ connection = nm_simple_connection_new (); - /* Build up the 'connection' setting */ s_con = (NMSettingConnection *) nm_setting_connection_new (); uuid = nm_utils_uuid_generate (); if (con_name) @@ -7881,8 +7815,6 @@ do_connection_edit (NmCli *nmc, int argc, char **argv) NM_SETTING_CONNECTION_UUID, uuid, NM_SETTING_CONNECTION_TYPE, connection_type, NULL); - g_free (uuid); - g_free (default_name); nm_connection_add_setting (connection, NM_SETTING (s_con)); /* Initialize the new connection so that it is valid from the start */ @@ -7905,7 +7837,6 @@ do_connection_edit (NmCli *nmc, int argc, char **argv) g_print (_("Type 'describe [<setting>.<prop>]' for detailed property description.")); g_print ("\n\n"); - /* Set global variables for use in TAB completion */ nmc_tab_completion.nmc = nmc; nmc_tab_completion.con_type = g_strdup (connection_type); nmc_tab_completion.connection = connection; @@ -7913,15 +7844,9 @@ do_connection_edit (NmCli *nmc, int argc, char **argv) /* Run menu loop */ editor_menu_main (nmc, connection, connection_type); - if (connection) - g_object_unref (connection); - g_free (nmc_tab_completion.con_type); - - return nmc->return_value; - -error: - g_assert (!connection); - g_free (type_ask); + nmc_tab_completion.nmc = NULL; + nm_clear_g_free (&nmc_tab_completion.con_type); + nmc_tab_completion.connection = NULL; return nmc->return_value; } @@ -7931,8 +7856,8 @@ modify_connection_cb (GObject *connection, GAsyncResult *result, gpointer user_data) { - NmCli *nmc = (NmCli *) user_data; - GError *error = NULL; + NmCli *nmc = user_data; + gs_free_error GError *error = NULL; if (!nm_remote_connection_commit_changes_finish (NM_REMOTE_CONNECTION (connection), result, &error)) { @@ -7940,13 +7865,13 @@ modify_connection_cb (GObject *connection, _("Error: Failed to modify connection '%s': %s"), nm_connection_get_id (NM_CONNECTION (connection)), error->message); - g_error_free (error); nmc->return_value = NMC_RESULT_ERROR_UNKNOWN; } else { - if (nmc->nmc_config.print_output == NMC_PRINT_PRETTY) + if (nmc->nmc_config.print_output == NMC_PRINT_PRETTY) { g_print (_("Connection '%s' (%s) successfully modified.\n"), nm_connection_get_id (NM_CONNECTION (connection)), nm_connection_get_uuid (NM_CONNECTION (connection))); + } } quit (); } @@ -7958,20 +7883,18 @@ do_connection_modify (NmCli *nmc, { NMConnection *connection = NULL; NMRemoteConnection *rc = NULL; - GError *error = NULL; + gs_free_error GError *error = NULL; gboolean temporary = FALSE; - /* Check --temporary */ if (next_arg (nmc, &argc, &argv, "--temporary", NULL) > 0) { temporary = TRUE; next_arg (nmc, &argc, &argv, NULL); } - connection = get_connection (nmc, &argc, &argv, NULL, &error); + connection = get_connection (nmc, &argc, &argv, NULL, NULL, NULL, &error); if (!connection) { g_string_printf (nmc->return_text, _("Error: %s."), error->message); - nmc->return_value = error->code; - goto finish; + NMC_RETURN (nmc, error->code); } rc = nm_client_get_connection_by_uuid (nmc->client, @@ -7979,24 +7902,20 @@ do_connection_modify (NmCli *nmc, if (!rc) { g_string_printf (nmc->return_text, _("Error: Unknown connection '%s'."), nm_connection_get_uuid (connection)); - nmc->return_value = NMC_RESULT_ERROR_NOT_FOUND; - goto finish; + NMC_RETURN (nmc, NMC_RESULT_ERROR_NOT_FOUND); } if (!nmc_read_connection_properties (nmc, NM_CONNECTION (rc), &argc, &argv, &error)) { g_string_assign (nmc->return_text, error->message); - nmc->return_value = error->code; - g_clear_error (&error); - goto finish; + NMC_RETURN (nmc, error->code); } if (nmc->complete) - goto finish; + return nmc->return_value; update_connection (!temporary, rc, modify_connection_cb, nmc); nmc->should_wait++; -finish: return nmc->return_value; } @@ -8044,11 +7963,11 @@ static NMCResultCode do_connection_clone (NmCli *nmc, int argc, char **argv) { NMConnection *connection = NULL; - NMConnection *new_connection = NULL; + gs_unref_object NMConnection *new_connection = NULL; NMSettingConnection *s_con; CloneConnectionInfo *info; const char *new_name; - char *new_name_ask = NULL; + gs_free char *new_name_ask = NULL; char *uuid; gboolean temporary = FALSE; char **arg_arr = NULL; @@ -8078,15 +7997,14 @@ do_connection_clone (NmCli *nmc, int argc, char **argv) argc_ptr = &arg_num; } - connection = get_connection (nmc, argc_ptr, argv_ptr, NULL, &error); + connection = get_connection (nmc, argc_ptr, argv_ptr, NULL, NULL, NULL, &error); if (!connection) { g_string_printf (nmc->return_text, _("Error: %s."), error->message); - nmc->return_value = error->code; - goto finish; + NMC_RETURN (nmc, error->code); } if (nmc->complete) - goto finish; + return nmc->return_value; if (argv[0]) new_name = *argv; @@ -8094,14 +8012,12 @@ do_connection_clone (NmCli *nmc, int argc, char **argv) new_name = new_name_ask = nmc_readline (_("New connection name: ")); else { g_string_printf (nmc->return_text, _("Error: <new name> argument is missing.")); - nmc->return_value = NMC_RESULT_ERROR_USER_INPUT; - goto finish; + NMC_RETURN (nmc, NMC_RESULT_ERROR_USER_INPUT); } if (next_arg (nmc->ask ? NULL : nmc, argc_ptr, argv_ptr, NULL) == 0) { g_string_printf (nmc->return_text, _("Error: unknown extra argument: '%s'."), *argv); - nmc->return_value = NMC_RESULT_ERROR_USER_INPUT; - goto finish; + NMC_RETURN (nmc, NMC_RESULT_ERROR_USER_INPUT); } /* Copy the connection */ @@ -8133,11 +8049,6 @@ do_connection_clone (NmCli *nmc, int argc, char **argv) info); nmc->should_wait++; -finish: - if (new_connection) - g_object_unref (new_connection); - g_free (new_name_ask); - return nmc->return_value; } @@ -8167,12 +8078,12 @@ do_connection_delete (NmCli *nmc, int argc, char **argv) { NMConnection *connection; ConnectionCbInfo *info = NULL; - GSList *queue = NULL, *iter; - char **arg_arr = NULL, *old_arg; + gs_strfreev char **arg_arr = NULL; char **arg_ptr; + guint i; int arg_num; - GString *invalid_cons = NULL; - int pos = 0; + nm_auto_free_gstring GString *invalid_cons = NULL; + gs_unref_ptrarray GPtrArray *found_cons = NULL; GError *error = NULL; if (nmc->timeout == -1) @@ -8202,15 +8113,10 @@ do_connection_delete (NmCli *nmc, int argc, char **argv) } while (arg_num > 0) { - old_arg = *arg_ptr; - connection = get_connection (nmc, &arg_num, &arg_ptr, &pos, &error); - if (connection) { - /* Check if the connection is unique. */ - /* Calling delete for the same connection repeatedly would result in - * NM responding for the last D-Bus call only and we would stall. */ - if (!g_slist_find (queue, connection)) - queue = g_slist_prepend (queue, g_object_ref (connection)); - } else { + const char *cur_selector, *cur_value; + + connection = get_connection (nmc, &arg_num, &arg_ptr, &cur_selector, &cur_value, &found_cons, &error); + if (!connection) { if (!nmc->complete) g_printerr (_("Error: %s.\n"), error->message); g_string_printf (nmc->return_text, _("Error: not all connections found.")); @@ -8222,23 +8128,31 @@ do_connection_delete (NmCli *nmc, int argc, char **argv) if (!invalid_cons) invalid_cons = g_string_new (NULL); - g_string_append_printf (invalid_cons, "'%s', ", old_arg); + if (cur_selector) + g_string_append_printf (invalid_cons, "%s '%s', ", cur_selector, cur_value); + else + g_string_append_printf (invalid_cons, "'%s', ", cur_value); } } - if (!queue) { - g_string_printf (nmc->return_text, _("Error: No connection specified.")); - nmc->return_value = NMC_RESULT_ERROR_NOT_FOUND; - goto finish; - } else if (nmc->complete) { - g_slist_free (queue); + if (!found_cons) { + if (!invalid_cons) { + g_string_printf (nmc->return_text, _("Error: No connection specified.")); + nmc->return_value = NMC_RESULT_ERROR_NOT_FOUND; + } goto finish; } - queue = g_slist_reverse (queue); + + if (nmc->complete) + goto finish; info = g_slice_new0 (ConnectionCbInfo); info->nmc = nmc; - info->queue = queue; + info->obj_list = g_ptr_array_sized_new (found_cons->len); + for (i = 0; i < found_cons->len; i++) { + connection = found_cons->pdata[i]; + g_ptr_array_add (info->obj_list, g_object_ref (connection)); + } info->timeout_id = g_timeout_add_seconds (nmc->timeout, connection_op_timeout_cb, info); info->cancellable = g_cancellable_new (); @@ -8248,10 +8162,10 @@ do_connection_delete (NmCli *nmc, int argc, char **argv) g_signal_connect (nmc->client, NM_CLIENT_CONNECTION_REMOVED, G_CALLBACK (connection_removed_cb), info); - /* Now delete the connections */ - for (iter = queue; iter; iter = g_slist_next (iter)) - nm_remote_connection_delete_async (NM_REMOTE_CONNECTION (iter->data), + for (i = 0; i < found_cons->len; i++) { + nm_remote_connection_delete_async (NM_REMOTE_CONNECTION (found_cons->pdata[i]), info->cancellable, delete_cb, info); + } finish: if (invalid_cons) { @@ -8259,9 +8173,7 @@ finish: g_string_printf (nmc->return_text, _("Error: cannot delete unknown connection(s): %s."), invalid_cons->str); nmc->return_value = NMC_RESULT_ERROR_NOT_FOUND; - g_string_free (invalid_cons, TRUE); } - g_strfreev (arg_arr); return nmc->return_value; } @@ -8311,31 +8223,21 @@ static NMCResultCode do_connection_monitor (NmCli *nmc, int argc, char **argv) { GError *error = NULL; + guint i; + gs_unref_ptrarray GPtrArray *found_cons = NULL; + const GPtrArray *connections = NULL; next_arg (nmc, &argc, &argv, NULL); if (argc == 0) { /* No connections specified. Monitor all. */ - const GPtrArray *connections; - int i; /* nmc_do_cmd() should not call this with argc=0. */ g_assert (!nmc->complete); connections = nm_client_get_connections (nmc->client); - for (i = 0; i < connections->len; i++) - connection_watch (nmc, g_ptr_array_index (connections, i)); - - /* We'll watch the connection additions too, never exit. */ - nmc->should_wait++; - g_signal_connect (nmc->client, NM_CLIENT_CONNECTION_ADDED, G_CALLBACK (connection_added), nmc); } else { - /* Look up the specified connections and watch them. */ - NMConnection *connection; - int pos = 0; - - do { - connection = get_connection (nmc, &argc, &argv, &pos, &error); - if (!connection) { + while (argc > 0) { + if (!get_connection (nmc, &argc, &argv, NULL, NULL, &found_cons, &error)) { if (!nmc->complete) g_printerr (_("Error: %s.\n"), error->message); g_string_printf (nmc->return_text, _("Error: not all connections found.")); @@ -8345,8 +8247,17 @@ do_connection_monitor (NmCli *nmc, int argc, char **argv) if (nmc->complete) continue; - connection_watch (nmc, connection); - } while (argc > 0); + connections = found_cons; + } + } + + for (i = 0; i < connections->len; i++) + connection_watch (nmc, connections->pdata[i]); + + if (argc == 0) { + /* We'll watch the connection additions too, never exit. */ + nmc->should_wait++; + g_signal_connect (nmc->client, NM_CLIENT_CONNECTION_ADDED, G_CALLBACK (connection_added), nmc); } if (nmc->complete) @@ -8419,11 +8330,12 @@ do_connection_load (NmCli *nmc, int argc, char **argv) static NMCResultCode do_connection_import (NmCli *nmc, int argc, char **argv) { - GError *error = NULL; + gs_free_error GError *error = NULL; const char *type = NULL, *filename = NULL; - char *type_ask = NULL, *filename_ask = NULL; + gs_free char *type_ask = NULL; + gs_free char *filename_ask = NULL; AddConnectionInfo *info; - NMConnection *connection = NULL; + gs_unref_object NMConnection *connection = NULL; NMVpnEditorPlugin *plugin; gs_free char *service_type = NULL; gboolean temporary = FALSE; @@ -8434,7 +8346,6 @@ do_connection_import (NmCli *nmc, int argc, char **argv) next_arg (nmc, &argc, &argv, NULL); } - if (argc == 0) { /* nmc_do_cmd() should not call this with argc=0. */ g_assert (!nmc->complete); @@ -8446,8 +8357,7 @@ do_connection_import (NmCli *nmc, int argc, char **argv) filename = filename_ask = filename_ask ? g_strstrip (filename_ask) : NULL; } else { g_string_printf (nmc->return_text, _("Error: No arguments provided.")); - nmc->return_value = NMC_RESULT_ERROR_USER_INPUT; - goto finish; + NMC_RETURN (nmc, NMC_RESULT_ERROR_USER_INPUT); } } @@ -8460,8 +8370,7 @@ do_connection_import (NmCli *nmc, int argc, char **argv) argv++; if (!argc) { g_string_printf (nmc->return_text, _("Error: %s argument is missing."), *(argv-1)); - nmc->return_value = NMC_RESULT_ERROR_USER_INPUT; - goto finish; + NMC_RETURN (nmc, NMC_RESULT_ERROR_USER_INPUT); } if (argc == 1 && nmc->complete) @@ -8477,8 +8386,7 @@ do_connection_import (NmCli *nmc, int argc, char **argv) argv++; if (!argc) { g_string_printf (nmc->return_text, _("Error: %s argument is missing."), *(argv-1)); - nmc->return_value = NMC_RESULT_ERROR_USER_INPUT; - goto finish; + NMC_RETURN (nmc, NMC_RESULT_ERROR_USER_INPUT); } if (argc == 1 && nmc->complete) nmc->return_value = NMC_RESULT_COMPLETE_FILE; @@ -8488,32 +8396,28 @@ do_connection_import (NmCli *nmc, int argc, char **argv) g_printerr (_("Warning: 'file' already specified, ignoring extra one.\n")); } else { g_string_printf (nmc->return_text, _("Unknown parameter: %s"), *argv); - nmc->return_value = NMC_RESULT_ERROR_USER_INPUT; - goto finish; + NMC_RETURN (nmc, NMC_RESULT_ERROR_USER_INPUT); } next_arg (nmc, &argc, &argv, NULL); } if (nmc->complete) - goto finish; + return nmc->return_value; if (!type) { g_string_printf (nmc->return_text, _("Error: 'type' argument is required.")); - nmc->return_value = NMC_RESULT_ERROR_USER_INPUT; - goto finish; + NMC_RETURN (nmc, NMC_RESULT_ERROR_USER_INPUT); } if (!filename) { g_string_printf (nmc->return_text, _("Error: 'file' argument is required.")); - nmc->return_value = NMC_RESULT_ERROR_USER_INPUT; - goto finish; + NMC_RETURN (nmc, NMC_RESULT_ERROR_USER_INPUT); } service_type = nm_vpn_plugin_info_list_find_service_type (nm_vpn_get_plugin_infos (), type); if (!service_type) { g_string_printf (nmc->return_text, _("Error: failed to find VPN plugin for %s."), type); - nmc->return_value = NMC_RESULT_ERROR_UNKNOWN; - goto finish; + NMC_RETURN (nmc, NMC_RESULT_ERROR_UNKNOWN); } /* Import VPN configuration */ @@ -8521,16 +8425,14 @@ do_connection_import (NmCli *nmc, int argc, char **argv) if (!plugin) { g_string_printf (nmc->return_text, _("Error: failed to load VPN plugin: %s."), error->message); - nmc->return_value = NMC_RESULT_ERROR_UNKNOWN; - goto finish; + NMC_RETURN (nmc, NMC_RESULT_ERROR_UNKNOWN); } connection = nm_vpn_editor_plugin_import (plugin, filename, &error); if (!connection) { g_string_printf (nmc->return_text, _("Error: failed to import '%s': %s."), filename, error->message); - nmc->return_value = NMC_RESULT_ERROR_UNKNOWN; - goto finish; + NMC_RETURN (nmc, NMC_RESULT_ERROR_UNKNOWN); } info = g_malloc0 (sizeof (AddConnectionInfo)); @@ -8545,12 +8447,6 @@ do_connection_import (NmCli *nmc, int argc, char **argv) info); nmc->should_wait++; -finish: - if (connection) - g_object_unref (connection); - g_clear_error (&error); - g_free (type_ask); - g_free (filename_ask); return nmc->return_value; } @@ -8559,12 +8455,11 @@ do_connection_export (NmCli *nmc, int argc, char **argv) { NMConnection *connection = NULL; const char *out_name = NULL; - char *name_ask = NULL; - char *out_name_ask = NULL; + gs_free char *out_name_ask = NULL; const char *path = NULL; const char *type = NULL; NMVpnEditorPlugin *plugin; - GError *error = NULL; + gs_free_error GError *error = NULL; char tmpfile[] = "/tmp/nmcli-export-temp-XXXXXX"; char **arg_arr = NULL; int arg_num; @@ -8588,7 +8483,7 @@ do_connection_export (NmCli *nmc, int argc, char **argv) argc_ptr = &arg_num; } - connection = get_connection (nmc, argc_ptr, argv_ptr, NULL, &error); + connection = get_connection (nmc, argc_ptr, argv_ptr, NULL, NULL, NULL, &error); if (!connection) { g_string_printf (nmc->return_text, _("Error: %s."), error->message); nmc->return_value = error->code; @@ -8629,14 +8524,14 @@ do_connection_export (NmCli *nmc, int argc, char **argv) if (out_name) path = out_name; else { - int fd; + nm_auto_close int fd = -1; + fd = g_mkstemp (tmpfile); if (fd == -1) { g_string_printf (nmc->return_text, _("Error: failed to create temporary file %s."), tmpfile); nmc->return_value = NMC_RESULT_ERROR_UNKNOWN; goto finish; } - nm_close (fd); path = tmpfile; } @@ -8649,8 +8544,9 @@ do_connection_export (NmCli *nmc, int argc, char **argv) /* No output file -> copy data to stdout */ if (!out_name) { - char *contents = NULL; + gs_free char *contents = NULL; gsize len = 0; + if (!g_file_get_contents (path, &contents, &len, &error)) { g_string_printf (nmc->return_text, _("Error: failed to read temporary file '%s': %s."), path, error->message); @@ -8658,15 +8554,11 @@ do_connection_export (NmCli *nmc, int argc, char **argv) goto finish; } g_print ("%s", contents); - g_free (contents); } finish: if (!out_name && path) unlink (path); - g_clear_error (&error); - g_free (name_ask); - g_free (out_name_ask); return nmc->return_value; } diff --git a/clients/cli/connections.h b/clients/cli/connections.h index 01e78b02..591e9cda 100644 --- a/clients/cli/connections.h +++ b/clients/cli/connections.h @@ -14,7 +14,7 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * (C) Copyright 2010 - 2014 Red Hat, Inc. + * (C) Copyright 2010 - 2018 Red Hat, Inc. */ #ifndef NMC_CONNECTIONS_H @@ -33,7 +33,7 @@ nmc_read_connection_properties (NmCli *nmc, char ***argv, GError **error); -void nmc_active_connection_state_to_color (NMActiveConnectionState state, NMMetaTermColor *color); +NMMetaColor nmc_active_connection_state_to_color (NMActiveConnectionState state); extern const NmcMetaGenericInfo *const nmc_fields_con_show[]; extern const NmcMetaGenericInfo *const nmc_fields_con_active_details_general[]; diff --git a/clients/cli/devices.c b/clients/cli/devices.c index da969fbe..b99e606a 100644 --- a/clients/cli/devices.c +++ b/clients/cli/devices.c @@ -14,7 +14,7 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright 2010 - 2014 Red Hat, Inc. + * Copyright 2010 - 2018 Red Hat, Inc. */ #include "nm-default.h" @@ -51,7 +51,6 @@ const NmcMetaGenericInfo *const nmc_fields_dev_status[] = { }; #define NMC_FIELDS_DEV_STATUS_COMMON "DEVICE,TYPE,STATE,CONNECTION" - const NmcMetaGenericInfo *const nmc_fields_dev_show_general[] = { NMC_META_GENERIC ("NAME"), /* 0 */ NMC_META_GENERIC ("DEVICE"), /* 1 */ @@ -210,9 +209,9 @@ const NmcMetaGenericInfo *const nmc_fields_dev_show_sections[] = { NMC_META_GENERIC_WITH_NESTED ("WIMAX-PROPERTIES", nmc_fields_dev_show_wimax_prop + 1), /* 5 */ NMC_META_GENERIC_WITH_NESTED ("NSP", nmc_fields_dev_wimax_list + 1), /* 6 */ NMC_META_GENERIC_WITH_NESTED ("IP4", metagen_ip4_config), /* 7 */ - NMC_META_GENERIC_WITH_NESTED ("DHCP4", nmc_fields_dhcp4_config + 1), /* 8 */ + NMC_META_GENERIC_WITH_NESTED ("DHCP4", nmc_fields_dhcp_config + 1), /* 8 */ NMC_META_GENERIC_WITH_NESTED ("IP6", nmc_fields_ip6_config + 1), /* 9 */ - NMC_META_GENERIC_WITH_NESTED ("DHCP6", nmc_fields_dhcp6_config + 1), /* 10 */ + NMC_META_GENERIC_WITH_NESTED ("DHCP6", nmc_fields_dhcp_config + 1), /* 10 */ NMC_META_GENERIC_WITH_NESTED ("BOND", nmc_fields_dev_show_master_prop + 1), /* 11 */ NMC_META_GENERIC_WITH_NESTED ("TEAM", nmc_fields_dev_show_team_prop + 1), /* 12 */ NMC_META_GENERIC_WITH_NESTED ("BRIDGE", nmc_fields_dev_show_master_prop + 1), /* 13 */ @@ -451,11 +450,8 @@ usage_device_lldp (void) static void quit (void) { - if (progress_id) { - g_source_remove (progress_id); + if (nm_clear_g_source (&progress_id)) nmc_terminal_erase_line (); - } - g_main_loop_quit (loop); } @@ -711,22 +707,19 @@ sort_access_points (const GPtrArray *aps) return sorted; } -static void -wifi_signal_to_color (guint8 strength, NMMetaTermColor *color, NMMetaTermFormat *color_fmt) +static NMMetaColor +wifi_signal_to_color (guint8 strength) { - *color = NM_META_TERM_COLOR_NORMAL; - *color_fmt = NM_META_TERM_FORMAT_NORMAL; - if (strength > 80) - *color = NM_META_TERM_COLOR_GREEN; + return NM_META_COLOR_WIFI_SIGNAL_EXCELLENT; else if (strength > 55) - *color = NM_META_TERM_COLOR_YELLOW; + return NM_META_COLOR_WIFI_SIGNAL_GOOD; else if (strength > 30) - *color = NM_META_TERM_COLOR_MAGENTA; + return NM_META_COLOR_WIFI_SIGNAL_FAIR; else if (strength > 5) - *color = NM_META_TERM_COLOR_CYAN; + return NM_META_COLOR_WIFI_SIGNAL_POOR; else - *color_fmt = NM_META_TERM_FORMAT_DIM; + return NM_META_COLOR_WIFI_SIGNAL_UNKNOWN; } static char * @@ -799,8 +792,7 @@ fill_output_access_point (gpointer data, gpointer user_data) GString *security_str; char *ap_name; const char *sig_bars; - NMMetaTermColor color; - NMMetaTermFormat color_fmt; + NMMetaColor color; if (info->active_bssid) { const char *current_bssid = nm_access_point_get_bssid (ap); @@ -834,7 +826,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 = nm_utils_wifi_strength_bars (strength); + sig_bars = nmc_wifi_strength_bars (strength); security_str = g_string_new (NULL); @@ -886,11 +878,10 @@ fill_output_access_point (gpointer data, gpointer user_data) set_val_strc (arr, 16, nm_object_get_path (NM_OBJECT (ap))); /* Set colors */ - wifi_signal_to_color (strength, &color, &color_fmt); + color = wifi_signal_to_color (strength); set_val_color_all (arr, color); - set_val_color_fmt_all (arr, color_fmt); if (active) - arr[15].color = NM_META_TERM_COLOR_GREEN; + arr[15].color = NM_META_COLOR_CONNECTION_ACTIVATED; g_ptr_array_add (info->output_data, arr); @@ -1164,7 +1155,7 @@ show_device_info (NMDevice *device, NmCli *nmc) set_val_strc (arr, 6, nm_device_get_driver (device) ? nm_device_get_driver (device) : _("(unknown)")); set_val_strc (arr, 7, nm_device_get_driver_version (device)); set_val_strc (arr, 8, nm_device_get_firmware_version (device)); - set_val_strc (arr, 9, hwaddr ? hwaddr : _("(unknown)")); + set_val_strc (arr, 9, hwaddr ?: _("(unknown)")); set_val_str (arr, 10, mtu_str); set_val_str (arr, 11, state_str); set_val_str (arr, 12, reason_str); @@ -1272,7 +1263,7 @@ show_device_info (NMDevice *device, NmCli *nmc) } tmpl = (const NMMetaAbstractInfo *const*) nmc_fields_dev_wifi_list; - out_indices = parse_output_fields (section_fld ? section_fld : NMC_FIELDS_DEV_WIFI_LIST_FOR_DEV_LIST, + out_indices = parse_output_fields (section_fld ?: NMC_FIELDS_DEV_WIFI_LIST_FOR_DEV_LIST, tmpl, FALSE, NULL, NULL); arr = nmc_dup_fields_array (tmpl, NMC_OF_FLAG_FIELD_NAMES); g_ptr_array_add (out.output_data, arr); @@ -1332,7 +1323,7 @@ show_device_info (NMDevice *device, NmCli *nmc) /* DHCP4 */ if (dhcp4 && !strcasecmp (nmc_fields_dev_show_sections[section_idx]->name, nmc_fields_dev_show_sections[8]->name)) - was_output = print_dhcp4_config (dhcp4, &nmc->nmc_config, nmc_fields_dev_show_sections[8]->name, section_fld); + was_output = print_dhcp_config (dhcp4, &nmc->nmc_config, nmc_fields_dev_show_sections[8]->name, section_fld); /* IP6 */ if (cfg6 && !strcasecmp (nmc_fields_dev_show_sections[section_idx]->name, nmc_fields_dev_show_sections[9]->name)) @@ -1340,7 +1331,7 @@ show_device_info (NMDevice *device, NmCli *nmc) /* DHCP6 */ if (dhcp6 && !strcasecmp (nmc_fields_dev_show_sections[section_idx]->name, nmc_fields_dev_show_sections[10]->name)) - was_output = print_dhcp6_config (dhcp6, &nmc->nmc_config, nmc_fields_dev_show_sections[10]->name, section_fld); + was_output = print_dhcp_config (dhcp6, &nmc->nmc_config, nmc_fields_dev_show_sections[10]->name, section_fld); /* Bond specific information */ if (NM_IS_DEVICE_BOND (device)) { @@ -1467,20 +1458,19 @@ show_device_info (NMDevice *device, NmCli *nmc) return TRUE; } -void -nmc_device_state_to_color (NMDeviceState state, NMMetaTermColor *color, NMMetaTermFormat *color_fmt) +NMMetaColor +nmc_device_state_to_color (NMDeviceState state) { - *color = NM_META_TERM_COLOR_NORMAL; - *color_fmt = NM_META_TERM_FORMAT_NORMAL; - if (state <= NM_DEVICE_STATE_UNAVAILABLE) - *color_fmt= NM_META_TERM_FORMAT_DIM; + return NM_META_COLOR_DEVICE_UNAVAILABLE; else if (state == NM_DEVICE_STATE_DISCONNECTED) - *color = NM_META_TERM_COLOR_RED; + return NM_META_COLOR_DEVICE_DISCONNECTED; else if (state >= NM_DEVICE_STATE_PREPARE && state <= NM_DEVICE_STATE_SECONDARIES) - *color = NM_META_TERM_COLOR_YELLOW; + return NM_META_COLOR_DEVICE_ACTIVATING; else if (state == NM_DEVICE_STATE_ACTIVATED) - *color = NM_META_TERM_COLOR_GREEN; + return NM_META_COLOR_DEVICE_ACTIVATED; + + g_return_val_if_reached (NM_META_COLOR_DEVICE_UNKNOWN); } static void @@ -1488,8 +1478,7 @@ fill_output_device_status (NMDevice *device, GPtrArray *output_data) { NMActiveConnection *ac; NMDeviceState state; - NMMetaTermColor color; - NMMetaTermFormat color_fmt; + NMMetaColor color; NmcOutputField *arr = nmc_dup_fields_array ((const NMMetaAbstractInfo *const*) nmc_fields_dev_status, 0); @@ -1497,9 +1486,8 @@ fill_output_device_status (NMDevice *device, GPtrArray *output_data) ac = nm_device_get_active_connection (device); /* Show devices in color */ - nmc_device_state_to_color (state, &color, &color_fmt); + color = nmc_device_state_to_color (state); set_val_color_all (arr, color); - set_val_color_fmt_all (arr, color_fmt); set_val_strc (arr, 0, nm_device_get_iface (device)); set_val_strc (arr, 1, nm_device_get_type_description (device)); @@ -2410,12 +2398,11 @@ static void device_state (NMDevice *device, GParamSpec *pspec, NmCli *nmc) { NMDeviceState state = nm_device_get_state (device); - NMMetaTermColor color; - NMMetaTermFormat color_fmt; + NMMetaColor color; char *str; - nmc_device_state_to_color (state, &color, &color_fmt); - str = nmc_colorize (nmc->nmc_config.use_colors, color, color_fmt, "%s: %s\n", + color = nmc_device_state_to_color (state); + str = nmc_colorize (&nmc->nmc_config, color, "%s: %s\n", nm_device_get_iface (device), nmc_device_state_to_string (state)); @@ -2910,7 +2897,7 @@ do_device_wifi_connect_network (NmCli *nmc, int argc, char **argv) if (nmc->ask) { ssid_ask = nmc_readline (_("SSID or BSSID: ")); - param_user = ssid_ask ? ssid_ask : ""; + param_user = ssid_ask ?: ""; bssid1_arr = nm_utils_hwaddr_atoba (param_user, ETH_ALEN); } if (!ssid_ask) { @@ -3661,7 +3648,6 @@ do_device_wifi_rescan (NmCli *nmc, int argc, char **argv) goto finish; } - if (ssids->len) { g_variant_builder_init (&builder, G_VARIANT_TYPE_VARDICT); g_variant_builder_init (&array_builder, G_VARIANT_TYPE ("aay")); diff --git a/clients/cli/devices.h b/clients/cli/devices.h index 2c261bc7..c78680da 100644 --- a/clients/cli/devices.h +++ b/clients/cli/devices.h @@ -14,7 +14,7 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * (C) Copyright 2010 Red Hat, Inc. + * (C) Copyright 2010 - 2018 Red Hat, Inc. */ #ifndef NMC_DEVICES_H @@ -32,7 +32,7 @@ void monitor_devices (NmCli *nmc); NMDevice ** nmc_get_devices_sorted (NMClient *client); -void nmc_device_state_to_color (NMDeviceState state, NMMetaTermColor *color, NMMetaTermFormat *color_fmt); +NMMetaColor nmc_device_state_to_color (NMDeviceState state); extern const NmcMetaGenericInfo *const nmc_fields_dev_status[]; extern const NmcMetaGenericInfo *const nmc_fields_dev_show_general[]; diff --git a/clients/cli/general.c b/clients/cli/general.c index 7ac6b22c..841df8bd 100644 --- a/clients/cli/general.c +++ b/clients/cli/general.c @@ -14,7 +14,7 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright 2010 - 2017 Red Hat, Inc. + * Copyright 2010 - 2018 Red Hat, Inc. */ #include "nm-default.h" @@ -55,23 +55,26 @@ nm_state_to_string (NMState state) return _(nm_state_to_string_no_l10n (state)); } -static NMMetaTermColor +static NMMetaColor state_to_color (NMState state) { switch (state) { case NM_STATE_CONNECTING: - return NM_META_TERM_COLOR_YELLOW; + return NM_META_COLOR_STATE_CONNECTING; case NM_STATE_CONNECTED_LOCAL: + return NM_META_COLOR_STATE_CONNECTED_LOCAL; case NM_STATE_CONNECTED_SITE: + return NM_META_COLOR_STATE_CONNECTED_SITE; case NM_STATE_CONNECTED_GLOBAL: - return NM_META_TERM_COLOR_GREEN; + return NM_META_COLOR_STATE_CONNECTED_GLOBAL; case NM_STATE_DISCONNECTING: - return NM_META_TERM_COLOR_YELLOW; + return NM_META_COLOR_STATE_DISCONNECTING; case NM_STATE_ASLEEP: + return NM_META_COLOR_STATE_ASLEEP; case NM_STATE_DISCONNECTED: - return NM_META_TERM_COLOR_RED; + return NM_META_COLOR_STATE_DISCONNECTED; default: - return NM_META_TERM_COLOR_NORMAL; + return NM_META_COLOR_STATE_UNKNOWN; } } @@ -90,19 +93,20 @@ nm_connectivity_to_string (NMConnectivityState connectivity) return _(nm_connectivity_to_string_no_l10n (connectivity)); } -static NMMetaTermColor +static NMMetaColor connectivity_to_color (NMConnectivityState connectivity) { switch (connectivity) { case NM_CONNECTIVITY_NONE: - return NM_META_TERM_COLOR_RED; + return NM_META_COLOR_CONNECTIVITY_NONE; case NM_CONNECTIVITY_PORTAL: + return NM_META_COLOR_CONNECTIVITY_PORTAL; case NM_CONNECTIVITY_LIMITED: - return NM_META_TERM_COLOR_YELLOW; + return NM_META_COLOR_CONNECTIVITY_LIMITED; case NM_CONNECTIVITY_FULL: - return NM_META_TERM_COLOR_GREEN; + return NM_META_COLOR_CONNECTIVITY_FULL; default: - return NM_META_TERM_COLOR_NORMAL; + return NM_META_COLOR_CONNECTIVITY_UNKNOWN; } } @@ -155,11 +159,11 @@ NM_UTILS_LOOKUP_STR_DEFINE_STATIC (permission_result_to_string_no_l10n, NMClient NM_UTILS_LOOKUP_ITEM_IGNORE (NM_CLIENT_PERMISSION_RESULT_UNKNOWN), ); -_NM_UTILS_LOOKUP_DEFINE (static, permission_result_to_color, NMClientPermissionResult, NMMetaTermColor, - NM_UTILS_LOOKUP_DEFAULT (NM_META_TERM_COLOR_NORMAL), - NM_UTILS_LOOKUP_ITEM (NM_CLIENT_PERMISSION_RESULT_YES, NM_META_TERM_COLOR_GREEN), - NM_UTILS_LOOKUP_ITEM (NM_CLIENT_PERMISSION_RESULT_NO, NM_META_TERM_COLOR_RED), - NM_UTILS_LOOKUP_ITEM (NM_CLIENT_PERMISSION_RESULT_AUTH, NM_META_TERM_COLOR_YELLOW), +_NM_UTILS_LOOKUP_DEFINE (static, permission_result_to_color, NMClientPermissionResult, NMMetaColor, + NM_UTILS_LOOKUP_DEFAULT (NM_META_COLOR_PERMISSION_UNKNOWN), + NM_UTILS_LOOKUP_ITEM (NM_CLIENT_PERMISSION_RESULT_YES, NM_META_COLOR_PERMISSION_YES), + NM_UTILS_LOOKUP_ITEM (NM_CLIENT_PERMISSION_RESULT_NO, NM_META_COLOR_PERMISSION_NO), + NM_UTILS_LOOKUP_ITEM (NM_CLIENT_PERMISSION_RESULT_AUTH, NM_META_COLOR_PERMISSION_AUTH), NM_UTILS_LOOKUP_ITEM_IGNORE (NM_CLIENT_PERMISSION_RESULT_UNKNOWN), ); @@ -168,14 +172,7 @@ _NM_UTILS_LOOKUP_DEFINE (static, permission_result_to_color, NMClientPermissionR static const NmcMetaGenericInfo *const metagen_general_status[]; static gconstpointer -_metagen_general_status_get_fcn (const NMMetaEnvironment *environment, - gpointer environment_user_data, - const NmcMetaGenericInfo *info, - gpointer target, - NMMetaAccessorGetType get_type, - NMMetaAccessorGetFlags get_flags, - NMMetaAccessorGetOutFlags *out_flags, - gpointer *out_to_free) +_metagen_general_status_get_fcn (NMC_META_GENERIC_INFO_GET_FCN_ARGS) { NmCli *nmc = target; const char *value; @@ -185,26 +182,26 @@ _metagen_general_status_get_fcn (const NMMetaEnvironment *environment, switch (info->info_type) { case NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_RUNNING: - NMC_HANDLE_TERMFORMAT (NM_META_TERM_COLOR_NORMAL); + NMC_HANDLE_COLOR (NM_META_COLOR_NONE); value = N_("running"); goto translate_and_out; case NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_VERSION: - NMC_HANDLE_TERMFORMAT (NM_META_TERM_COLOR_NORMAL); + NMC_HANDLE_COLOR (NM_META_COLOR_NONE); value = nm_client_get_version (nmc->client); goto clone_and_out; case NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_STATE: state = nm_client_get_state (nmc->client); - NMC_HANDLE_TERMFORMAT (state_to_color (state)); + NMC_HANDLE_COLOR (state_to_color (state)); value = nm_state_to_string_no_l10n (state); goto translate_and_out; case NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_STARTUP: v_bool = nm_client_get_startup (nmc->client); - NMC_HANDLE_TERMFORMAT (v_bool ? NM_META_TERM_COLOR_YELLOW : NM_META_TERM_COLOR_GREEN); + NMC_HANDLE_COLOR (v_bool ? NM_META_COLOR_MANAGER_STARTING : NM_META_COLOR_MANAGER_RUNNING); value = v_bool ? N_("starting") : N_("started"); goto translate_and_out; case NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_CONNECTIVITY: connectivity = nm_client_get_connectivity (nmc->client); - NMC_HANDLE_TERMFORMAT (connectivity_to_color (connectivity)); + NMC_HANDLE_COLOR (connectivity_to_color (connectivity)); value = nm_connectivity_to_string_no_l10n (connectivity); goto translate_and_out; case NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_NETWORKING: @@ -233,7 +230,7 @@ _metagen_general_status_get_fcn (const NMMetaEnvironment *environment, g_return_val_if_reached (NULL); enabled_out: - NMC_HANDLE_TERMFORMAT (v_bool ? NM_META_TERM_COLOR_GREEN : NM_META_TERM_COLOR_RED); + NMC_HANDLE_COLOR (v_bool ? NM_META_COLOR_ENABLED : NM_META_COLOR_DISABLED); value = v_bool ? N_("enabled") : N_("disabled"); goto translate_and_out; @@ -275,14 +272,7 @@ static const NmcMetaGenericInfo *const metagen_general_status[_NMC_GENERIC_INFO_ /*****************************************************************************/ static gconstpointer -_metagen_general_permissions_get_fcn (const NMMetaEnvironment *environment, - gpointer environment_user_data, - const NmcMetaGenericInfo *info, - gpointer target, - NMMetaAccessorGetType get_type, - NMMetaAccessorGetFlags get_flags, - NMMetaAccessorGetOutFlags *out_flags, - gpointer *out_to_free) +_metagen_general_permissions_get_fcn (NMC_META_GENERIC_INFO_GET_FCN_ARGS) { NMClientPermission perm = GPOINTER_TO_UINT (target); NmCli *nmc = environment_user_data; @@ -291,11 +281,11 @@ _metagen_general_permissions_get_fcn (const NMMetaEnvironment *environment, switch (info->info_type) { case NMC_GENERIC_INFO_TYPE_GENERAL_PERMISSIONS_PERMISSION: - NMC_HANDLE_TERMFORMAT (NM_META_TERM_COLOR_NORMAL); + NMC_HANDLE_COLOR (NM_META_COLOR_NONE); return permission_to_string (perm); case NMC_GENERIC_INFO_TYPE_GENERAL_PERMISSIONS_VALUE: perm_result = nm_client_get_permission_result (nmc->client, perm); - NMC_HANDLE_TERMFORMAT (permission_result_to_color (perm_result)); + NMC_HANDLE_COLOR (permission_result_to_color (perm_result)); s = permission_result_to_string_no_l10n (perm_result); if (get_type == NM_META_ACCESSOR_GET_TYPE_PRETTY) return _(s); @@ -323,21 +313,14 @@ typedef struct { } GetGeneralLoggingData; static gconstpointer -_metagen_general_logging_get_fcn (const NMMetaEnvironment *environment, - gpointer environment_user_data, - const NmcMetaGenericInfo *info, - gpointer target, - NMMetaAccessorGetType get_type, - NMMetaAccessorGetFlags get_flags, - NMMetaAccessorGetOutFlags *out_flags, - gpointer *out_to_free) +_metagen_general_logging_get_fcn (NMC_META_GENERIC_INFO_GET_FCN_ARGS) { NmCli *nmc = environment_user_data; GetGeneralLoggingData *d = target; nm_assert (info->info_type < _NMC_GENERIC_INFO_TYPE_GENERAL_LOGGING_NUM); - NMC_HANDLE_TERMFORMAT (NM_META_TERM_COLOR_NORMAL); + NMC_HANDLE_COLOR (NM_META_COLOR_NONE); if (!d->initialized) { d->initialized = TRUE; @@ -513,8 +496,8 @@ show_nm_status (NmCli *nmc, const char *pretty_header_name, const char *print_fl { gs_free_error GError *error = NULL; const char *fields_str; - const char *fields_all = print_flds ? print_flds : NMC_FIELDS_NM_STATUS_ALL; - const char *fields_common = print_flds ? print_flds : NMC_FIELDS_NM_STATUS_COMMON; + const char *fields_all = print_flds ?: NMC_FIELDS_NM_STATUS_ALL; + const char *fields_common = print_flds ?: NMC_FIELDS_NM_STATUS_COMMON; if (!nmc->required_fields || strcasecmp (nmc->required_fields, "common") == 0) fields_str = fields_common; @@ -1083,9 +1066,8 @@ networkmanager_running (NMClient *client, GParamSpec *param, NmCli *nmc) char *str; running = nm_client_get_nm_running (client); - str = nmc_colorize (nmc->nmc_config.use_colors, - running ? NM_META_TERM_COLOR_GREEN : NM_META_TERM_COLOR_RED, - NM_META_TERM_FORMAT_NORMAL, + str = nmc_colorize (&nmc->nmc_config, + running ? NM_META_COLOR_MANAGER_RUNNING : NM_META_COLOR_MANAGER_STOPPED, running ? _("NetworkManager has started") : _("NetworkManager has stopped")); g_print ("%s\n", str); g_free (str); @@ -1125,7 +1107,7 @@ client_connectivity (NMClient *client, GParamSpec *param, NmCli *nmc) char *str; g_object_get (client, NM_CLIENT_CONNECTIVITY, &connectivity, NULL); - str = nmc_colorize (nmc->nmc_config.use_colors, connectivity_to_color (connectivity), NM_META_TERM_FORMAT_NORMAL, + str = nmc_colorize (&nmc->nmc_config, connectivity_to_color (connectivity), _("Connectivity is now '%s'\n"), nm_connectivity_to_string (connectivity)); g_print ("%s", str); g_free (str); @@ -1138,14 +1120,13 @@ client_state (NMClient *client, GParamSpec *param, NmCli *nmc) char *str; g_object_get (client, NM_CLIENT_STATE, &state, NULL); - str = nmc_colorize (nmc->nmc_config.use_colors, state_to_color (state), NM_META_TERM_FORMAT_NORMAL, + str = nmc_colorize (&nmc->nmc_config, state_to_color (state), _("Networkmanager is now in the '%s' state\n"), nm_state_to_string (state)); g_print ("%s", str); g_free (str); } - static void device_overview (NmCli *nmc, NMDevice *device) { @@ -1182,12 +1163,12 @@ device_overview (NmCli *nmc, NMDevice *device) if (!nm_device_get_autoconnect (device)) g_string_append_printf (outbuf, "%s, ", _("autoconnect")); if (nm_device_get_firmware_missing (device)) { - tmp = nmc_colorize (nmc->nmc_config.use_colors, NM_META_TERM_COLOR_RED, NM_META_TERM_FORMAT_NORMAL, _("fw missing")); + tmp = nmc_colorize (&nmc->nmc_config, NM_META_COLOR_DEVICE_FIRMWARE_MISSING, _("fw missing")); g_string_append_printf (outbuf, "%s, ", tmp); g_free (tmp); } if (nm_device_get_nm_plugin_missing (device)) { - tmp = nmc_colorize (nmc->nmc_config.use_colors, NM_META_TERM_COLOR_RED, NM_META_TERM_FORMAT_NORMAL, _("plugin missing")); + tmp = nmc_colorize (&nmc->nmc_config, NM_META_COLOR_DEVICE_PLUGIN_MISSING, _("plugin missing")); g_string_append_printf (outbuf, "%s, ", tmp); g_free (tmp); } @@ -1288,7 +1269,7 @@ do_overview (NmCli *nmc, int argc, char **argv) NMDevice **devices; const GPtrArray *p; NMActiveConnection *ac; - NMMetaTermColor color; + NMMetaColor color; NMDnsEntry *dns; char *tmp; int i; @@ -1312,8 +1293,8 @@ do_overview (NmCli *nmc, int argc, char **argv) continue; state = nm_active_connection_get_state (ac); - nmc_active_connection_state_to_color (state, &color); - tmp = nmc_colorize (nmc->nmc_config.use_colors, color, NM_META_TERM_FORMAT_NORMAL, _("%s VPN connection"), + color = nmc_active_connection_state_to_color (state); + tmp = nmc_colorize (&nmc->nmc_config, color, _("%s VPN connection"), nm_active_connection_get_id (ac)); g_print ("%s\n", tmp); g_free (tmp); @@ -1324,14 +1305,13 @@ do_overview (NmCli *nmc, int argc, char **argv) devices = nmc_get_devices_sorted (nmc->client); for (i = 0; devices[i]; i++) { - NMMetaTermFormat color_fmt; NMDeviceState state; ac = nm_device_get_active_connection (devices[i]); state = nm_device_get_state (devices[i]); - nmc_device_state_to_color (state, &color, &color_fmt); - tmp = nmc_colorize (nmc->nmc_config.use_colors, color, color_fmt, "%s: %s%s%s", + color = nmc_device_state_to_color (state); + tmp = nmc_colorize (&nmc->nmc_config, color, "%s: %s%s%s", nm_device_get_iface (devices[i]), nmc_device_state_to_string (state), ac ? " to " : "", @@ -1342,7 +1322,6 @@ do_overview (NmCli *nmc, int argc, char **argv) if (nm_device_get_description (devices[i]) && strcmp (nm_device_get_description (devices[i]), "")) g_print ("\t\"%s\"\n", nm_device_get_description (devices[i])); - device_overview (nmc, devices[i]); if (ac) ac_overview (nmc, ac); @@ -1415,7 +1394,7 @@ do_monitor (NmCli *nmc, int argc, char **argv) if (!nm_client_get_nm_running (nmc->client)) { char *str; - str = nmc_colorize (nmc->nmc_config.use_colors, NM_META_TERM_COLOR_RED, NM_META_TERM_FORMAT_NORMAL, + str = nmc_colorize (&nmc->nmc_config, NM_META_COLOR_MANAGER_STOPPED, _("Networkmanager is not running (waiting for it)\n")); g_print ("%s", str); g_free (str); diff --git a/clients/cli/meson.build b/clients/cli/meson.build new file mode 100644 index 00000000..9449ce63 --- /dev/null +++ b/clients/cli/meson.build @@ -0,0 +1,49 @@ +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 + [ + '-DSYSCONFDIR="@0@"'.format(nm_sysconfdir), + '-DG_LOG_DOMAIN="@0@"'.format(name), + '-DNMLOCALEDIR="@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 f5a66cdd..e9752952 100644 --- a/clients/cli/nmcli.c +++ b/clients/cli/nmcli.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 2010 - 2017 Red Hat, Inc. + * Copyright 2010 - 2018 Red Hat, Inc. */ #include "nm-default.h" @@ -36,8 +36,6 @@ #include "nm-client-utils.h" -#include "nm-utils/nm-hash-utils.h" - #include "polkit-agent.h" #include "utils.h" #include "common.h" @@ -53,8 +51,67 @@ # define NMCLI_VERSION VERSION #endif -/* Global NmCli object */ -NmCli nm_cli; +NmCli nm_cli = { + .client = NULL, + + .return_value = NMC_RESULT_SUCCESS, + + .timeout = -1, + + .secret_agent = NULL, + .pwds_hash = NULL, + .pk_listener = NULL, + + .should_wait = 0, + .nowait_flag = TRUE, + .nmc_config.print_output = NMC_PRINT_NORMAL, + .nmc_config.multiline_output = FALSE, + .mode_specified = FALSE, + .nmc_config.escape_values = TRUE, + .required_fields = NULL, + .ask = FALSE, + .complete = FALSE, + .nmc_config.show_secrets = FALSE, + .nmc_config.in_editor = FALSE, + .nmc_config.palette = { + [NM_META_COLOR_CONNECTION_ACTIVATED] = "32", + [NM_META_COLOR_CONNECTION_ACTIVATING] = "33", + [NM_META_COLOR_CONNECTION_DISCONNECTING] = "31", + [NM_META_COLOR_CONNECTION_INVISIBLE] = "2", + [NM_META_COLOR_CONNECTIVITY_FULL] = "32", + [NM_META_COLOR_CONNECTIVITY_LIMITED] = "33", + [NM_META_COLOR_CONNECTIVITY_NONE] = "31", + [NM_META_COLOR_CONNECTIVITY_PORTAL] = "33", + [NM_META_COLOR_DEVICE_ACTIVATED] = "32", + [NM_META_COLOR_DEVICE_ACTIVATING] = "33", + [NM_META_COLOR_DEVICE_DISCONNECTED] = "31", + [NM_META_COLOR_DEVICE_FIRMWARE_MISSING] = "31", + [NM_META_COLOR_DEVICE_PLUGIN_MISSING] = "31", + [NM_META_COLOR_DEVICE_UNAVAILABLE] = "2", + [NM_META_COLOR_MANAGER_RUNNING] = "32", + [NM_META_COLOR_MANAGER_STARTING] = "33", + [NM_META_COLOR_MANAGER_STOPPED] = "31", + [NM_META_COLOR_PERMISSION_AUTH] = "33", + [NM_META_COLOR_PERMISSION_NO] = "31", + [NM_META_COLOR_PERMISSION_YES] = "32", + [NM_META_COLOR_STATE_ASLEEP] = "31", + [NM_META_COLOR_STATE_CONNECTED_GLOBAL] = "32", + [NM_META_COLOR_STATE_CONNECTED_LOCAL] = "32", + [NM_META_COLOR_STATE_CONNECTED_SITE] = "32", + [NM_META_COLOR_STATE_CONNECTING] = "33", + [NM_META_COLOR_STATE_DISCONNECTED] = "31", + [NM_META_COLOR_STATE_DISCONNECTING] = "33", + [NM_META_COLOR_WIFI_SIGNAL_EXCELLENT] = "32", + [NM_META_COLOR_WIFI_SIGNAL_FAIR] = "35", + [NM_META_COLOR_WIFI_SIGNAL_GOOD] = "33", + [NM_META_COLOR_WIFI_SIGNAL_POOR] = "36", + [NM_META_COLOR_WIFI_SIGNAL_UNKNOWN] = "2", + [NM_META_COLOR_ENABLED] = "32", + [NM_META_COLOR_DISABLED] = "31", + }, + .editor_status_line = FALSE, + .editor_save_confirmation = TRUE, +}; /*****************************************************************************/ @@ -129,9 +186,8 @@ complete_fields (const char *option, const char *prefix) h = g_hash_table_new_full (nm_str_hash, g_str_equal, g_free, NULL); complete_field (h, metagen_ip4_config); - complete_field (h, nmc_fields_dhcp4_config); + complete_field (h, nmc_fields_dhcp_config); complete_field (h, nmc_fields_ip6_config); - complete_field (h, nmc_fields_dhcp6_config); complete_field (h, nmc_fields_con_show); complete_field (h, nmc_fields_con_active_details_general); complete_field (h, nmc_fields_con_active_details_vpn); @@ -186,6 +242,7 @@ 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" @@ -272,9 +329,299 @@ matches_arg (NmCli *nmc, int *argc, char ***argv, const char *pattern, char **ar return TRUE; } +/*************************************************************************************/ + +typedef enum { + NMC_USE_COLOR_AUTO, + NMC_USE_COLOR_YES, + NMC_USE_COLOR_NO, +} NmcColorOption; + +/* Checks whether a particular terminal-colors.d(5) file (.enabled, .disabled or .schem) + * exists. If contents is non-NULL, it returns the content. */ +static gboolean +check_colors_file (NmCli *nmc, NmcColorOption *color_option, + const char *base_dir, const char *name, const char *term, const char *type, + char **contents) +{ + char *filename; + gboolean exists; + + filename = g_strdup_printf ("%s/terminal-colors.d/%s%s%s%s%s", + base_dir, + name ? name : "", + term ? "@" : "", term ? term : "", + (name || term) ? "." : "", + type); + if (contents) + exists = g_file_get_contents (filename, contents, NULL, NULL); + else + exists = g_file_test (filename, G_FILE_TEST_EXISTS); + g_free (filename); + + return exists; +} + +static void +check_colors_files_for_term (NmCli *nmc, NmcColorOption *color_option, + const char *base_dir, const char *name, const char *term) +{ + if ( *color_option == NMC_USE_COLOR_AUTO + && check_colors_file (nmc, color_option, base_dir, name, term, "enable", NULL)) { + *color_option = NMC_USE_COLOR_YES; + } + + if ( *color_option == NMC_USE_COLOR_AUTO + && check_colors_file (nmc, color_option, base_dir, name, term, "disable", NULL)) { + *color_option = NMC_USE_COLOR_NO; + } + + if (*color_option == NMC_USE_COLOR_NO) { + /* No need to bother any further. */ + return; + } + + if (nmc->palette_buffer == NULL) + check_colors_file (nmc, color_option, base_dir, name, term, "schem", &nmc->palette_buffer); +} + +static void +check_colors_files_for_name (NmCli *nmc, NmcColorOption *color_option, + const char *base_dir, const char *name) +{ + const gchar *term; + + /* Take a shortcut if the directory is not there. */ + if (!g_file_test (base_dir, G_FILE_TEST_EXISTS)) + return; + + term = g_getenv ("TERM"); + if (term) + check_colors_files_for_term (nmc, color_option, base_dir, name, term); + check_colors_files_for_term (nmc, color_option, base_dir, name, NULL); +} + +static void +check_colors_files_for_base_dir (NmCli *nmc, NmcColorOption *color_option, + const char *base_dir) +{ + check_colors_files_for_name (nmc, color_option, base_dir, "nmcli"); + check_colors_files_for_name (nmc, color_option, base_dir, NULL); +} + +static const char * +resolve_color_alias (const char *color) +{ + static const struct { + const char *name; + const char *alias; + } aliases[] = { + { "reset", "0" }, + { "bold", "1" }, + { "white", "1;37" }, + { "halfbright", "2" }, + { "underscore", "4" }, + { "blink", "5" }, + { "reverse", "7" }, + { "black", "30" }, + { "red", "31" }, + { "green", "32" }, + { "brown", "33" }, + { "yellow", "33" }, /* well, yellow */ + { "blue", "34" }, + { "magenta", "35" }, + { "cyan", "36" }, + { "gray", "37" }, + { "darkgray", "90" }, + { "lightred", "91" }, + { "lightgreen", "92" }, + { "lightblue", "94" }, + { "lightmagenta", "95" }, + { "lightcyan", "96" }, + { "lightgray", "97" }, + }; + int i; + + /* Shortcut literal sequences. */ + if (g_ascii_isdigit (*color)) + return color; + + for (i = 0; i < G_N_ELEMENTS (aliases); i++) { + if (strcmp (color, aliases[i].name) == 0) + return aliases[i].alias; + } + + return color; +} + +static gboolean +parse_color_scheme (NmCli *nmc, GError **error) +{ + char *p = nmc->palette_buffer; + const char *name; + const char *color; + const char *map[_NM_META_COLOR_NUM] = { + [NM_META_COLOR_NONE] = NULL, + [NM_META_COLOR_CONNECTION_ACTIVATED] = "connection-activated", + [NM_META_COLOR_CONNECTION_ACTIVATING] = "connection-activating", + [NM_META_COLOR_CONNECTION_DISCONNECTING] = "connection-disconnecting", + [NM_META_COLOR_CONNECTION_INVISIBLE] = "connection-invisible", + [NM_META_COLOR_CONNECTION_UNKNOWN] = "connection-unknown", + [NM_META_COLOR_CONNECTIVITY_FULL] = "connectivity-full", + [NM_META_COLOR_CONNECTIVITY_LIMITED] = "connectivity-limited", + [NM_META_COLOR_CONNECTIVITY_NONE] = "connectivity-none", + [NM_META_COLOR_CONNECTIVITY_PORTAL] = "connectivity-portal", + [NM_META_COLOR_CONNECTIVITY_UNKNOWN] = "connectivity-unknown", + [NM_META_COLOR_DEVICE_ACTIVATED] = "device-activated", + [NM_META_COLOR_DEVICE_ACTIVATING] = "device-activating", + [NM_META_COLOR_DEVICE_DISCONNECTED] = "device-disconnected", + [NM_META_COLOR_DEVICE_FIRMWARE_MISSING] = "device-firmware-missing", + [NM_META_COLOR_DEVICE_PLUGIN_MISSING] = "device-plugin-missing", + [NM_META_COLOR_DEVICE_UNAVAILABLE] = "device-unavailable", + [NM_META_COLOR_DEVICE_UNKNOWN] = "device-unknown", + [NM_META_COLOR_MANAGER_RUNNING] = "manager-running", + [NM_META_COLOR_MANAGER_STARTING] = "manager-starting", + [NM_META_COLOR_MANAGER_STOPPED] = "manager-stopped", + [NM_META_COLOR_PERMISSION_AUTH] = "permission-auth", + [NM_META_COLOR_PERMISSION_NO] = "permission-no", + [NM_META_COLOR_PERMISSION_UNKNOWN] = "permission-unknown", + [NM_META_COLOR_PERMISSION_YES] = "permission-yes", + [NM_META_COLOR_PROMPT] = "prompt", + [NM_META_COLOR_STATE_ASLEEP] = "state-asleep", + [NM_META_COLOR_STATE_CONNECTED_GLOBAL] = "state-connected-global", + [NM_META_COLOR_STATE_CONNECTED_LOCAL] = "state-connected-local", + [NM_META_COLOR_STATE_CONNECTED_SITE] = "state-connected-site", + [NM_META_COLOR_STATE_CONNECTING] = "state-connecting", + [NM_META_COLOR_STATE_DISCONNECTED] = "state-disconnected", + [NM_META_COLOR_STATE_DISCONNECTING] = "state-disconnecting", + [NM_META_COLOR_STATE_UNKNOWN] = "state-unknown", + [NM_META_COLOR_WIFI_SIGNAL_EXCELLENT] = "wifi-signal-excellent", + [NM_META_COLOR_WIFI_SIGNAL_FAIR] = "wifi-signal-fair", + [NM_META_COLOR_WIFI_SIGNAL_GOOD] = "wifi-signal-good", + [NM_META_COLOR_WIFI_SIGNAL_POOR] = "wifi-signal-poor", + [NM_META_COLOR_WIFI_SIGNAL_UNKNOWN] = "wifi-signal-unknown", + [NM_META_COLOR_DISABLED] = "disabled", + [NM_META_COLOR_ENABLED] = "enabled", + }; + int i; + + /* This reads through the raw color scheme file contents, identifying the + * color names and sequences, putting in terminating NULs in place, so that + * pointers into the buffer can readily be used as strings in the palette. */ + while (1) { + /* Leading whitespace. */ + while (nm_utils_is_separator (*p) || *p == '\n') + p++; + + if (*p == '\0') + break; + + /* Comments. */ + if (*p == '#') { + while (*p != '\n' && *p != '\0') + p++; + continue; + } + + /* Color name. */ + name = p; + while (g_ascii_isgraph (*p)) + p++; + if (*p == '\0') { + g_set_error (error, NMCLI_ERROR, 0, + _("Unexpected end of file following '%s'\n"), name); + return FALSE; + } + + /* Separating whitespace. */ + if (!nm_utils_is_separator (*p)) { + *p = '\0'; + g_set_error (error, NMCLI_ERROR, 0, + _("Expected whitespace following '%s'\n"), name); + return FALSE; + } + while (nm_utils_is_separator (*p)) { + *p = '\0'; + p++; + } + + /* Color sequence. */ + color = p; + if (!g_ascii_isgraph (*p)) { + g_set_error (error, NMCLI_ERROR, 0, + _("Expected a value for '%s'\n"), name); + return FALSE; + } + while (g_ascii_isgraph (*p)) + p++; + + /* Trailing whitespace. */ + while (nm_utils_is_separator (*p)) { + *p = '\0'; + p++; + } + if (*p != '\0') { + if (*p != '\n') { + g_set_error (error, NMCLI_ERROR, 0, + _("Expected a line break following '%s'\n"), color); + return FALSE; + } + *p = '\0'; + p++; + } + + /* All good, set the palette entry. */ + for (i = NM_META_COLOR_NONE + 1; i < _NM_META_COLOR_NUM; i++) { + if (strcmp (map[i], name) == 0) { + nmc->nmc_config_mutable.palette[i] = resolve_color_alias (color); + break; + } + } + if (i == _NM_META_COLOR_NUM) + g_debug ("Ignoring an unrecognized color: '%s'\n", name); + } + + return TRUE; +} + +static void +set_colors (NmCli *nmc, NmcColorOption color_option) +{ + GError *error = NULL; + + if (color_option == NMC_USE_COLOR_AUTO) { + if ( g_strcmp0 (g_getenv ("TERM"), "dumb") == 0 + || !isatty (STDOUT_FILENO)) + color_option = NMC_USE_COLOR_NO; + } + + check_colors_files_for_base_dir (nmc, &color_option, g_get_user_config_dir ()); + check_colors_files_for_base_dir (nmc, &color_option, SYSCONFDIR); + + switch (color_option) { + case NMC_USE_COLOR_YES: + case NMC_USE_COLOR_AUTO: + nmc->nmc_config_mutable.use_colors = TRUE; + break; + case NMC_USE_COLOR_NO: + nmc->nmc_config_mutable.use_colors = FALSE; + break; + } + + if (nmc->nmc_config_mutable.use_colors && nmc->palette_buffer) { + if (!parse_color_scheme (nmc, &error)) { + g_debug ("Error parsing color scheme: %s", error->message); + g_error_free (error); + } + } +} + +/*************************************************************************************/ + static gboolean process_command_line (NmCli *nmc, int argc, char **argv) { + NmcColorOption colors = NMC_USE_COLOR_AUTO; char *base; base = strrchr (argv[0], '/'); @@ -297,9 +644,10 @@ process_command_line (NmCli *nmc, int argc, char **argv) break; if (argc == 1 && nmc->complete) { - nmc_complete_strings (argv[0], "--terse", "--pretty", "--mode", "--colors", "--escape", - "--fields", "--nocheck", "--get-values", - "--wait", "--version", "--help", NULL); + nmc_complete_strings (argv[0], "--terse", "--pretty", "--mode", "--overview", + "--colors", "--escape", + "--fields", "--nocheck", "--get-values", + "--wait", "--version", "--help", NULL); } if (argv[0][1] == '-' && argv[0][2] == '\0') { @@ -308,7 +656,9 @@ process_command_line (NmCli *nmc, int argc, char **argv) break; } - if (matches_arg (nmc, &argc, &argv, "-terse", NULL)) { + if (matches_arg (nmc, &argc, &argv, "-overview", NULL)) { + nmc->nmc_config_mutable.overview = TRUE; + } else 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; @@ -351,11 +701,11 @@ process_command_line (NmCli *nmc, int argc, char **argv) if (argc == 1 && nmc->complete) complete_option_with_value (argv[0], value, "yes", "no", "auto", NULL); if (matches (value, "auto")) - nmc->nmc_config_mutable.use_colors = NMC_USE_COLOR_AUTO; + colors = NMC_USE_COLOR_AUTO; else if (matches (value, "yes")) - nmc->nmc_config_mutable.use_colors = NMC_USE_COLOR_YES; + colors = NMC_USE_COLOR_YES; else if (matches (value, "no")) - nmc->nmc_config_mutable.use_colors = NMC_USE_COLOR_NO; + colors = NMC_USE_COLOR_NO; else { g_string_printf (nmc->return_text, _("Error: '%s' is not valid argument for '%s' option."), value, argv[0]); nmc->return_value = NMC_RESULT_ERROR_USER_INPUT; @@ -382,8 +732,8 @@ process_command_line (NmCli *nmc, int argc, char **argv) complete_fields (argv[0], value); nmc->required_fields = g_strdup (value); nmc->nmc_config_mutable.print_output = NMC_PRINT_TERSE; - /* We want fixed tabular mode here, but just set the mode specified and rely on the initialization - * in nmc_init: in this way we allow use of "-m multiline" to swap the output mode also if placed + /* We want fixed tabular mode here, but just set the mode specified and rely on defaults: + * in this way we allow use of "-m multiline" to swap the output mode also if placed * before the "-g <field>" option (-g may be still more practical and easy to remember than -t -f). */ nmc->mode_specified = TRUE; @@ -417,6 +767,12 @@ 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; + + set_colors (nmc, colors); + /* Now run the requested command */ nmc_do_cmd (nmc, nmcli_cmds, *argv, argc, argv); @@ -553,38 +909,6 @@ nmc_value_transforms_register (void) nmc_convert_bytes_to_string); } -/* Initialize NmCli structure - set default values */ -static void -nmc_init (NmCli *nmc) -{ - nmc->client = NULL; - - nmc->return_value = NMC_RESULT_SUCCESS; - nmc->return_text = g_string_new (_("Success")); - - nmc->timeout = -1; - - nmc->secret_agent = NULL; - nmc->pwds_hash = NULL; - nmc->pk_listener = NULL; - - nmc->should_wait = 0; - nmc->nowait_flag = TRUE; - nmc->nmc_config_mutable.print_output = NMC_PRINT_NORMAL; - nmc->nmc_config_mutable.multiline_output = FALSE; - nmc->mode_specified = FALSE; - nmc->nmc_config_mutable.escape_values = TRUE; - nmc->required_fields = NULL; - nmc->ask = FALSE; - nmc->complete = FALSE; - nmc->nmc_config_mutable.show_secrets = FALSE; - nmc->nmc_config_mutable.use_colors = NMC_USE_COLOR_AUTO; - nmc->nmc_config_mutable.in_editor = FALSE; - nmc->editor_status_line = FALSE; - nmc->editor_save_confirmation = TRUE; - nmc->editor_prompt_color = NM_META_TERM_COLOR_NORMAL; -} - static void nmc_cleanup (NmCli *nmc) { @@ -602,7 +926,7 @@ nmc_cleanup (NmCli *nmc) if (nmc->pwds_hash) g_hash_table_destroy (nmc->pwds_hash); - g_free (nmc->required_fields); + nm_clear_g_free (&nmc->required_fields); if (nmc->pager_pid > 0) { fclose (stdout); @@ -613,6 +937,8 @@ nmc_cleanup (NmCli *nmc) nmc->pager_pid = 0; } + nm_clear_g_free (&nmc->palette_buffer); + nmc_polkit_agent_fini (nmc); } @@ -624,19 +950,17 @@ main (int argc, char *argv[]) #ifdef GETTEXT_PACKAGE /* Set i18n stuff */ - bindtextdomain (GETTEXT_PACKAGE, NMCLI_LOCALEDIR); + bindtextdomain (GETTEXT_PACKAGE, NMLOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); #endif - nm_g_type_init (); - /* Save terminal settings */ tcgetattr (STDIN_FILENO, &termios_orig); nmc_value_transforms_register (); - nmc_init (&nm_cli); + nm_cli.return_text = g_string_new (_("Success")); loop = g_main_loop_new (NULL, FALSE); g_unix_signal_add (SIGTERM, signal_handler, GINT_TO_POINTER (SIGTERM)); diff --git a/clients/cli/nmcli.h b/clients/cli/nmcli.h index 874bca21..61bf86de 100644 --- a/clients/cli/nmcli.h +++ b/clients/cli/nmcli.h @@ -14,23 +14,16 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright 2010 - 2017 Red Hat, Inc. + * Copyright 2010 - 2018 Red Hat, Inc. */ #ifndef NMC_NMCLI_H #define NMC_NMCLI_H -#include "NetworkManager.h" #include "nm-secret-agent-old.h" - #include "nm-meta-setting-desc.h" -#if WITH_POLKIT_AGENT -#include "nm-polkit-listener.h" -#else -/* polkit agent is not available; define fake NMPolkitListener */ -typedef gpointer NMPolkitListener; -#endif +struct _NMPolkitListener; typedef char *(*NmcCompEntryFunc) (const char *, int); @@ -100,23 +93,18 @@ struct _NmcOutputField { gboolean value_is_array; /* Whether value is char** instead of char* */ gboolean free_value; /* Whether to free the value */ NmcOfFlags flags; /* Flags - whether and how to print values/field names/headers */ - NMMetaTermColor color; /* Use this color to print value */ - NMMetaTermFormat color_fmt; /* Use this terminal format to print value */ + NMMetaColor color; /* Use this color to print value */ }; -typedef enum { - NMC_USE_COLOR_AUTO, - NMC_USE_COLOR_YES, - NMC_USE_COLOR_NO, -} NmcColorOption; - typedef struct _NmcConfig { NMCPrintOutput print_output; /* Output mode */ - NmcColorOption use_colors; /* Whether to use colors for output: option '--color' */ + gboolean use_colors; /* Whether to use colors for output: option '--color' */ bool multiline_output; /* Multiline output instead of default tabular */ 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) */ + const char *palette[_NM_META_COLOR_NUM]; /* Color palette */ } NmcConfig; typedef struct _NmcOutputData { @@ -135,7 +123,7 @@ typedef struct _NmCli { NMSecretAgentOld *secret_agent; /* Secret agent */ GHashTable *pwds_hash; /* Hash table with passwords in passwd-file */ - NMPolkitListener *pk_listener ; /* polkit agent listener */ + struct _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 */ @@ -149,9 +137,15 @@ typedef struct _NmCli { gboolean complete; /* Autocomplete the command line */ gboolean editor_status_line; /* Whether to display status line in connection editor */ gboolean editor_save_confirmation; /* Whether to ask for confirmation on saving connections with 'autoconnect=yes' */ - NMMetaTermColor editor_prompt_color; /* Color of prompt in connection editor */ + + char *palette_buffer; /* Buffer with sequences for terminal-colors.d(5)-based coloring. */ } NmCli; +#define NMC_RETURN(nmc, rvalue) \ + G_STMT_START { \ + return ((nmc)->return_value = (rvalue)); \ + } G_STMT_END + extern NmCli nm_cli; /* Error quark for GError domain */ diff --git a/clients/cli/polkit-agent.c b/clients/cli/polkit-agent.c index ecd58ba5..338f0b15 100644 --- a/clients/cli/polkit-agent.c +++ b/clients/cli/polkit-agent.c @@ -19,8 +19,6 @@ #include "nm-default.h" -#if WITH_POLKIT_AGENT - #include "polkit-agent.h" #include <stdio.h> @@ -29,17 +27,18 @@ #include <unistd.h> #include "nm-polkit-listener.h" - #include "common.h" +#if WITH_POLKIT_AGENT static char * -polkit_request (const char *request, +polkit_request (NMPolkitListener *listener, + 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; @@ -62,28 +61,42 @@ polkit_request (const char *request, } static void -polkit_show_info (const char *text) +polkit_show_info (NMPolkitListener *listener, + const char *text, + gpointer user_data) { g_print (_("Authentication message: %s\n"), text); } static void -polkit_show_error (const char *text) +polkit_show_error (NMPolkitListener *listener, + const char *text, + gpointer user_data) { g_print (_("Authentication error: %s\n"), text); } static void -polkit_completed (gboolean gained_authorization) +polkit_completed (NMPolkitListener *listener, + gboolean gained_authorization, + gpointer user_data) { /* 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) { - PolkitAgentListener *listener; +#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; g_return_val_if_fail (error == NULL || *error == NULL, FALSE); @@ -91,24 +104,28 @@ nmc_polkit_agent_init (NmCli* nmc, gboolean for_session, GError **error) if (!listener) return FALSE; - 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); + nm_polkit_listener_set_vtable (listener, &vtable, nmc); - nmc->pk_listener = NM_POLKIT_LISTENER (listener); + nmc->pk_listener = listener; +#endif return TRUE; } void nmc_polkit_agent_fini (NmCli* nmc) { - g_clear_object (&nmc->pk_listener); +#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 } 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 */ @@ -121,30 +138,6 @@ 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 69275aad..01142ba2 100644 --- a/clients/cli/settings.c +++ b/clients/cli/settings.c @@ -313,16 +313,18 @@ _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; + gboolean modified = FALSE; - strv = nmc_strsplit_set (value, " \t,", 0); - if (!strv) + strv0 = nm_utils_strsplit_set (value, " \t,"); + if (!strv0) 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); @@ -472,6 +474,7 @@ 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); @@ -746,9 +749,9 @@ nmc_setting_get_property_desc (NMSetting *setting, const char *prop) return g_strdup_printf ("%s\n%s\n%s%s%s%s", setting_desc_title, - setting_desc ? setting_desc : "", + setting_desc ?: "", nmcli_nl, nmcli_desc_title, nmcli_nl, - nmcli_desc ? nmcli_desc : ""); + nmcli_desc ?: ""); } /* diff --git a/clients/cli/utils.c b/clients/cli/utils.c index f20e24ce..32c44e39 100644 --- a/clients/cli/utils.c +++ b/clients/cli/utils.c @@ -15,7 +15,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * Copyright 2010 Lennart Poettering - * Copyright 2010 - 2017 Red Hat, Inc. + * Copyright 2010 - 2018 Red Hat, Inc. */ #include "nm-default.h" @@ -75,6 +75,7 @@ _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; @@ -85,23 +86,25 @@ _meta_type_nmc_generic_info_get_fcn (const NMMetaAbstractInfo *abstract_info, if (!NM_IN_SET (get_type, NM_META_ACCESSOR_GET_TYPE_PARSABLE, NM_META_ACCESSOR_GET_TYPE_PRETTY, - NM_META_ACCESSOR_GET_TYPE_TERMFORMAT)) + NM_META_ACCESSOR_GET_TYPE_COLOR)) g_return_val_if_reached (NULL); - /* omitting the out_to_free value is only allowed for TERMFORMAT. */ - nm_assert (out_to_free || NM_IN_SET (get_type, NM_META_ACCESSOR_GET_TYPE_TERMFORMAT)); + /* omitting the out_to_free value is only allowed for COLOR. */ + nm_assert (out_to_free || NM_IN_SET (get_type, NM_META_ACCESSOR_GET_TYPE_COLOR)); if (info->get_fcn) { - return info->get_fcn (environment, environment_user_data, + return info->get_fcn (environment, + environment_user_data, info, target, get_type, get_flags, out_flags, + out_is_default, out_to_free); } if (info->nested) { - NMC_HANDLE_TERMFORMAT (NM_META_TERM_COLOR_NORMAL); + NMC_HANDLE_COLOR (NM_META_COLOR_NONE); return info->name; } @@ -117,37 +120,16 @@ const NMMetaType nmc_meta_type_generic_info = { /*****************************************************************************/ -static gboolean -use_colors (NmcColorOption color_option) -{ - if (color_option == NMC_USE_COLOR_AUTO) { - static NmcColorOption cached = NMC_USE_COLOR_AUTO; - - if (G_UNLIKELY (cached == NMC_USE_COLOR_AUTO)) { - if ( g_strcmp0 (g_getenv ("TERM"), "dumb") == 0 - || !isatty (STDOUT_FILENO)) - cached = NMC_USE_COLOR_NO; - else - cached = NMC_USE_COLOR_YES; - } - return cached == NMC_USE_COLOR_YES; - } - - return color_option == NMC_USE_COLOR_YES; -} - static const char * -colorize_string (NmcColorOption color_option, - NMMetaTermColor color, - NMMetaTermFormat color_fmt, +colorize_string (const NmcConfig *nmc_config, + NMMetaColor color, const char *str, char **out_to_free) { const char *out = str; - if ( use_colors (color_option) - && (color != NM_META_TERM_COLOR_NORMAL || color_fmt != NM_META_TERM_FORMAT_NORMAL)) { - *out_to_free = nmc_colorize (color_option, color, color_fmt, "%s", str); + if (nmc_config && nmc_config->use_colors) { + *out_to_free = nmc_colorize (nmc_config, color, "%s", str); out = *out_to_free; } @@ -202,7 +184,6 @@ next_arg (NmCli *nmc, int *argc, char ***argv, ...) if (*argc == 0) return -1; - va_start (args, argv); if (nmc && nmc->complete && *argc == 1) { @@ -389,118 +370,30 @@ nmc_terminal_show_progress (const char *str) const char slashes[4] = {'|', '/', '-', '\\'}; nmc_terminal_erase_line (); - g_print ("%c %s", slashes[idx++], str ? str : ""); + g_print ("%c %s", slashes[idx++], str ?: ""); fflush (stdout); if (idx == 4) idx = 0; } -const char * -nmc_term_color_sequence (NMMetaTermColor color) -{ - switch (color) { - case NM_META_TERM_COLOR_BLACK: - return "\33[30m"; - break; - case NM_META_TERM_COLOR_RED: - return "\33[31m"; - break; - case NM_META_TERM_COLOR_GREEN: - return "\33[32m"; - break; - case NM_META_TERM_COLOR_YELLOW: - return "\33[33m"; - break; - case NM_META_TERM_COLOR_BLUE: - return "\33[34m"; - break; - case NM_META_TERM_COLOR_MAGENTA: - return "\33[35m"; - break; - case NM_META_TERM_COLOR_CYAN: - return "\33[36m"; - break; - case NM_META_TERM_COLOR_WHITE: - return "\33[37m"; - break; - default: - return ""; - break; - } -} - -/* Parses @str for color as string or number */ -NMMetaTermColor -nmc_term_color_parse_string (const char *str, GError **error) -{ - unsigned long color_int; - static const char *colors[] = { "normal", "black", "red", "green", "yellow", - "blue", "magenta", "cyan", "white", NULL }; - - if (nmc_string_to_uint (str, TRUE, 0, 8, &color_int)) { - return (NMMetaTermColor) color_int; - } else { - const char *color, **p; - int i; - - color = nmc_string_is_valid (str, colors, error); - for (p = colors, i = 0; *p != NULL; p++, i++) { - if (*p == color) - return (NMMetaTermColor) i; - } - return -1; - } -} - -const char * -nmc_term_format_sequence (NMMetaTermFormat format) -{ - switch (format) { - case NM_META_TERM_FORMAT_BOLD: - return "\33[1m"; - break; - case NM_META_TERM_FORMAT_DIM: - return "\33[2m"; - break; - case NM_META_TERM_FORMAT_UNDERLINE: - return "\33[4m"; - break; - case NM_META_TERM_FORMAT_BLINK: - return "\33[5m"; - break; - case NM_META_TERM_FORMAT_REVERSE: - return "\33[7m"; - break; - case NM_META_TERM_FORMAT_HIDDEN: - return "\33[8m"; - break; - default: - return ""; - break; - } -} - char * -nmc_colorize (NmcColorOption color_option, NMMetaTermColor color, NMMetaTermFormat format, const char *fmt, ...) +nmc_colorize (const NmcConfig *nmc_config, NMMetaColor color, const char *fmt, ...) { va_list args; char *str, *colored; - const char *ansi_color, *color_end, *ansi_fmt, *format_end; - static const char *end_seq = "\33[0m"; + const char *ansi_seq = NULL; va_start (args, fmt); str = g_strdup_vprintf (fmt, args); va_end (args); - if (!use_colors (color_option)) - return str; + if (nmc_config->use_colors) + ansi_seq = nmc_config->palette[color]; - ansi_color = nmc_term_color_sequence (color); - ansi_fmt = nmc_term_format_sequence (format); - color_end = *ansi_color ? end_seq : ""; - format_end = *ansi_fmt ? end_seq : ""; + if (ansi_seq == NULL) + return str; - colored = g_strdup_printf ("%s%s%s%s%s", ansi_fmt, ansi_color, str, color_end, format_end); + colored = g_strdup_printf ("\33[%sm%s\33[0m", ansi_seq, str); g_free (str); return colored; } @@ -524,7 +417,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++; } @@ -603,9 +496,14 @@ 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; - arr = nmc_strsplit_set (line ? line : "", delim ? delim : " \t", 0); + arr0 = nm_utils_strsplit_set (line ?: "", delim ?: " \t"); + if (!arr0) + arr = g_new0 (char *, 1); + else + arr = g_strdupv ((char **) arr0); if (unquote) { int i = 0; @@ -613,7 +511,7 @@ nmc_string_to_arg_array (const char *line, const char *delim, gboolean unquote, size_t l; const char *quotes = "\"'"; - while (arr && arr[i]) { + while (arr[i]) { s = arr[i]; l = strlen (s); if (l >= 2) { @@ -628,7 +526,6 @@ nmc_string_to_arg_array (const char *line, const char *delim, gboolean unquote, *argv = arr; *argc = g_strv_length (arr); - return 0; } @@ -713,7 +610,7 @@ set_val_arrc (NmcOutputField fields_array[], guint32 idx, const char **value) } void -set_val_color_all (NmcOutputField fields_array[], NMMetaTermColor color) +set_val_color_all (NmcOutputField fields_array[], NMMetaColor color) { int i; @@ -722,16 +619,6 @@ set_val_color_all (NmcOutputField fields_array[], NMMetaTermColor color) } } -void -set_val_color_fmt_all (NmcOutputField fields_array[], NMMetaTermFormat format) -{ - int i; - - for (i = 0; fields_array[i].info; i++) { - fields_array[i].color_fmt = format; - } -} - /* * Free 'value' members in array of NmcOutputField */ @@ -998,6 +885,7 @@ typedef struct { const PrintDataCol *col; const char *title; bool title_to_free:1; + bool skip:1; int width; } PrintDataHeaderCell; @@ -1009,8 +897,7 @@ typedef enum { typedef struct { guint row_idx; const PrintDataHeaderCell *header_cell; - NMMetaTermColor term_color; - NMMetaTermFormat term_format; + NMMetaColor color; union { const char *plain; const char *const*strv; @@ -1096,6 +983,7 @@ _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 @@ -1130,10 +1018,11 @@ _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]; - const PrintDataHeaderCell *header_cell; + 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; @@ -1148,7 +1037,11 @@ _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) { @@ -1167,16 +1060,15 @@ _print_fill (const NmcConfig *nmc_config, cell->text_to_free = !!to_free; } - nm_meta_termformat_unpack (nm_meta_abstract_info_get (info, - nmc_meta_environment, - nmc_meta_environment_arg, - target, - NM_META_ACCESSOR_GET_TYPE_TERMFORMAT, - NM_META_ACCESSOR_GET_FLAGS_NONE, - &color_out_flags, - NULL), - &cell->term_color, - &cell->term_format); + cell->color = GPOINTER_TO_INT (nm_meta_abstract_info_get (info, + nmc_meta_environment, + nmc_meta_environment_arg, + target, + NM_META_ACCESSOR_GET_TYPE_COLOR, + NM_META_ACCESSOR_GET_FLAGS_NONE, + &color_out_flags, + NULL, + NULL)); if (cell->text_format == PRINT_DATA_CELL_FORMAT_TYPE_PLAIN) { if (pretty && (!cell->text.plain|| !cell->text.plain[0])) { @@ -1231,6 +1123,9 @@ _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. */ @@ -1358,9 +1253,7 @@ _print_do (const NmcConfig *nmc_config, gs_free char *text_to_free = NULL; const char *text; - text = colorize_string (nmc_config->use_colors, - cell->term_color, cell->term_format, - lines[i_lines], &text_to_free); + text = colorize_string (nmc_config, cell->color, lines[i_lines], &text_to_free); if (multiline) { gs_free char *prefix = NULL; @@ -1408,8 +1301,7 @@ _print_do (const NmcConfig *nmc_config, } if ( pretty - && ( i_row < row_len - 1 - || multiline)) { + && multiline) { gs_free char *line = NULL; g_print ("%s\n", (line = g_strnfill (ML_HEADER_WIDTH, '-'))); @@ -1489,7 +1381,7 @@ nmc_terminal_spawn_pager (const NmcConfig *nmc_config) if ( nm_cli.nmc_config.in_editor || nm_cli.pager_pid > 0 || nmc_config->print_output == NMC_PRINT_TERSE - || !use_colors (nmc_config->use_colors) + || !nmc_config->use_colors || g_strcmp0 (pager, "") == 0 || getauxval (AT_SECURE)) return; @@ -1560,7 +1452,7 @@ nmc_terminal_spawn_pager (const NmcConfig *nmc_config) /*****************************************************************************/ static const char * -get_value_to_print (NmcColorOption color_option, +get_value_to_print (const NmcConfig *nmc_config, const NmcOutputField *field, gboolean field_name, const char *not_set_str, @@ -1586,7 +1478,7 @@ get_value_to_print (NmcColorOption color_option, } /* colorize the value */ - out = colorize_string (color_option, field->color, field->color_fmt, value, out_to_free); + out = colorize_string (nmc_config, field->color, value, out_to_free); if (out && out == free_value) { nm_assert (!*out_to_free); @@ -1680,7 +1572,7 @@ print_required_fields (const NmcConfig *nmc_config, gs_free char *tmp = NULL; val = *p ?: not_set_str; - print_val = colorize_string (nmc_config->use_colors, field_values[idx].color, field_values[idx].color_fmt, + print_val = colorize_string (nmc_config, field_values[idx].color, val, &val_to_free); tmp = g_strdup_printf ("%s%s%s[%d]:", section_prefix ? (const char*) field_values[0].value : "", @@ -1701,7 +1593,7 @@ print_required_fields (const NmcConfig *nmc_config, /* value is a string */ val = val && *val ? val : not_set_str; - print_val = colorize_string (nmc_config->use_colors, field_values[idx].color, field_values[idx].color_fmt, + print_val = colorize_string (nmc_config, field_values[idx].color, val, &val_to_free); tmp = g_strdup_printf ("%s%s%s:", section_prefix ? hdr_name : "", @@ -1732,7 +1624,7 @@ print_required_fields (const NmcConfig *nmc_config, idx = g_array_index (indices, int, i); - value = get_value_to_print (nmc_config->use_colors, (NmcOutputField *) field_values+idx, field_names, + value = get_value_to_print (nmc_config, (NmcOutputField *) field_values+idx, field_names, not_set_str, &val_to_free); if (terse) { @@ -1805,7 +1697,7 @@ print_data_prepare_width (GPtrArray *output_data) row = g_ptr_array_index (output_data, j); field_names = row[0].flags & NMC_OF_FLAG_FIELD_NAMES; - value = get_value_to_print (NMC_USE_COLOR_NO, row+i, field_names, "--", &val_to_free); + value = get_value_to_print (NULL, row+i, field_names, "--", &val_to_free); len = nmc_string_screen_width (value, NULL); max_width = len > max_width ? len : max_width; } diff --git a/clients/cli/utils.h b/clients/cli/utils.h index ffc5b6f3..dc0ce083 100644 --- a/clients/cli/utils.h +++ b/clients/cli/utils.h @@ -14,7 +14,7 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright 2010 - 2017 Red Hat, Inc. + * Copyright 2010 - 2018 Red Hat, Inc. */ #ifndef NMC_UTILS_H @@ -41,11 +41,7 @@ char *ssid_to_hex (const char *str, gsize len); void nmc_terminal_erase_line (void); void nmc_terminal_show_progress (const char *str); void nmc_terminal_spawn_pager (const NmcConfig *nmc_config); -gboolean nmc_term_use_colors (NmcColorOption color_option); -const char *nmc_term_color_sequence (NMMetaTermColor color); -const char *nmc_term_format_sequence (NMMetaTermFormat format); -NMMetaTermColor nmc_term_color_parse_string (const char *str, GError **error); -char *nmc_colorize (NmcColorOption color_option, NMMetaTermColor color, NMMetaTermFormat format, const char * fmt, ...) _nm_printf (4, 5); +char *nmc_colorize (const NmcConfig *nmc_config, NMMetaColor color, const char * fmt, ...) _nm_printf (3, 4); void nmc_filter_out_colors_inplace (char *str); char *nmc_filter_out_colors (const char *str); char *nmc_get_user_input (const char *ask_str); @@ -53,14 +49,12 @@ 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); void set_val_arr (NmcOutputField fields_array[], guint32 index, char **value); void set_val_arrc (NmcOutputField fields_array[], guint32 index, const char **value); -void set_val_color_all (NmcOutputField fields_array[], NMMetaTermColor color); -void set_val_color_fmt_all (NmcOutputField fields_array[], NMMetaTermFormat format); +void set_val_color_all (NmcOutputField fields_array[], NMMetaColor color); void nmc_free_output_field_values (NmcOutputField fields_array[]); GArray *parse_output_fields (const char *fields_str, @@ -129,10 +123,10 @@ typedef enum { } NmcGenericInfoType; -#define NMC_HANDLE_TERMFORMAT(color) \ +#define NMC_HANDLE_COLOR(color) \ G_STMT_START { \ - if (get_type == NM_META_ACCESSOR_GET_TYPE_TERMFORMAT) \ - return nm_meta_termformat_pack ((color), NM_META_TERM_FORMAT_NORMAL); \ + if (get_type == NM_META_ACCESSOR_GET_TYPE_COLOR) \ + return GINT_TO_POINTER (color); \ } G_STMT_END struct _NmcMetaGenericInfo { @@ -144,14 +138,19 @@ struct _NmcMetaGenericInfo { const char *name; const char *name_header; const NmcMetaGenericInfo *const*nested; - gconstpointer (*get_fcn) (const NMMetaEnvironment *environment, - gpointer environment_user_data, - const NmcMetaGenericInfo *info, - gpointer target, - NMMetaAccessorGetType get_type, - NMMetaAccessorGetFlags get_flags, - NMMetaAccessorGetOutFlags *out_flags, - gpointer *out_to_free); + +#define NMC_META_GENERIC_INFO_GET_FCN_ARGS \ + const NMMetaEnvironment *environment, \ + gpointer environment_user_data, \ + const NmcMetaGenericInfo *info, \ + gpointer target, \ + NMMetaAccessorGetType get_type, \ + NMMetaAccessorGetFlags get_flags, \ + NMMetaAccessorGetOutFlags *out_flags, \ + gboolean *out_is_default, \ + gpointer *out_to_free + + gconstpointer (*get_fcn) (NMC_META_GENERIC_INFO_GET_FCN_ARGS); }; #define NMC_META_GENERIC(n, ...) \ @@ -164,6 +163,52 @@ struct _NmcMetaGenericInfo { #define NMC_META_GENERIC_WITH_NESTED(n, nest, ...) \ NMC_META_GENERIC (n, .nested = (nest), __VA_ARGS__) +#define NMC_META_GENERIC_GROUP(_group_name, _nested, _name_header) \ + ((const NMMetaAbstractInfo *const*) ((const NmcMetaGenericInfo *const[]) { \ + NMC_META_GENERIC_WITH_NESTED (_group_name,_nested, .name_header = _name_header), \ + NULL, \ + })) + +static inline const char * +nmc_meta_generic_get_str_i18n (const char *s, NMMetaAccessorGetType get_type) +{ + if (!NM_IN_SET (get_type, NM_META_ACCESSOR_GET_TYPE_PRETTY, + NM_META_ACCESSOR_GET_TYPE_PARSABLE)) + g_return_val_if_reached (NULL); + + if (!s) + return NULL; + if (get_type == NM_META_ACCESSOR_GET_TYPE_PRETTY) + return gettext (s); + return s; +} + +static inline const char * +nmc_meta_generic_get_bool (gboolean val, NMMetaAccessorGetType get_type) +{ + return nmc_meta_generic_get_str_i18n (val ? N_("yes") : N_("no"), get_type); +} + +static inline char * +nmc_meta_generic_get_enum_with_detail (gint64 enum_val, const char *str_val, NMMetaAccessorGetType get_type) +{ + if (!NM_IN_SET (get_type, NM_META_ACCESSOR_GET_TYPE_PRETTY, + NM_META_ACCESSOR_GET_TYPE_PARSABLE)) + g_return_val_if_reached (NULL); + + if (!str_val) { + /* Pass %NULL for only printing the numeric value. */ + return g_strdup_printf ("%lld", (long long) enum_val); + } + + /* note that this function will always print "$NUM ($NICK)", also in PARSABLE + * mode. That might not be desired, but it's done for certain properties to preserve + * previous behavior. */ + if (get_type == NM_META_ACCESSOR_GET_TYPE_PRETTY) + return g_strdup_printf (_("%lld (%s)"), (long long) enum_val, gettext (str_val)); + return g_strdup_printf ("%lld (%s)", (long long) enum_val, str_val); +} + /*****************************************************************************/ gboolean nmc_print (const NmcConfig *nmc_config, diff --git a/clients/common/meson.build b/clients/common/meson.build new file mode 100644 index 00000000..f0c81600 --- /dev/null +++ b/clients/common/meson.build @@ -0,0 +1,76 @@ +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"', +] + +libnmc_base = static_library( + 'nmc-base', + sources: shared_files_clients_common + files( + 'nm-client-utils.c', + 'nm-secret-agent-simple.c', + 'nm-vpn-helpers.c', + ), + dependencies: deps, + c_args: cflags +) + +libnmc_base_dep = declare_dependency( + include_directories: common_inc, + link_with: libnmc_base +) + +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 + +libnmc = static_library( + 'nmc', + sources: files( + 'nm-meta-setting-access.c', + 'nm-meta-setting-desc.c' + ) + shared_nm_utils_nm_meta_setting_c + [settings_docs_source], + 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 b6ec92de..fec6e33b 100644 --- a/clients/common/nm-client-utils.c +++ b/clients/common/nm-client-utils.c @@ -20,11 +20,53 @@ #include "nm-default.h" #include "nm-client-utils.h" +#include "nm-utils.h" #include "nm-device-bond.h" #include "nm-device-bridge.h" #include "nm-device-team.h" +/*****************************************************************************/ + +static int +_nmc_objects_sort_by_path_cmp (gconstpointer pa, gconstpointer pb, gpointer user_data) +{ + NMObject *a = *((NMObject **) pa); + NMObject *b = *((NMObject **) pb); + + NM_CMP_SELF (a, b); + NM_CMP_RETURN (nm_utils_dbus_path_cmp (nm_object_get_path (a), + nm_object_get_path (b))); + return 0; +} + +const NMObject ** +nmc_objects_sort_by_path (const NMObject *const* objs, gssize len) +{ + const NMObject **arr; + gsize i, l; + + if (len < 0) + l = NM_PTRARRAY_LEN (objs); + else + l = len; + + arr = g_new (const NMObject *, l + 1); + for (i = 0; i < l; i++) + arr[i] = objs[i]; + arr[l] = NULL; + + if (l > 1) { + g_qsort_with_data (arr, + l, + sizeof (gpointer), + _nmc_objects_sort_by_path_cmp, + NULL); + } + return arr; +} + +/*****************************************************************************/ /* * Convert string to unsigned integer. * If required, the resulting number is checked to be in the <min,max> range. @@ -69,7 +111,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"); @@ -100,7 +142,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"); @@ -133,10 +175,10 @@ 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; - const char *ret = NULL; + const char *partial_match = NULL; + gboolean ambiguous = FALSE; - g_return_val_if_fail (error == NULL || *error == NULL, NULL); + g_return_val_if_fail (!error || !*error, NULL); if (!input || !*input) goto finish; @@ -145,24 +187,34 @@ nmc_string_is_valid (const char *input, const char **allowed, GError **error) for (p = allowed; p && *p; p++) { p_len = strlen (*p); if (g_ascii_strncasecmp (input, *p, input_ln) == 0) { - if (input_ln == p_len) { - ret = *p; - break; - } - if (!prev_match) - ret = *p; - else { - g_set_error (error, 1, 1, _("'%s' is ambiguous (%s x %s)"), - input, ret, *p); - return NULL; - } - prev_match = TRUE; + if (input_ln == p_len) + return *p; + if (!partial_match) + partial_match = *p; + else + ambiguous = TRUE; } } + if (ambiguous) { + GString *candidates = g_string_new (""); + + for (p = allowed; *p; p++) { + if (g_ascii_strncasecmp (input, *p, input_ln) == 0) { + if (candidates->len > 0) + g_string_append (candidates, ", "); + g_string_append (candidates, *p); + } + } + g_set_error (error, 1, 1, _("'%s' is ambiguous: %s"), + input, candidates->str); + g_string_free (candidates, TRUE); + return NULL; + } finish: - if (ret == NULL) { + if (!partial_match) { char *valid_vals = g_strjoinv (", ", (char **) allowed); + if (!input || !*input) g_set_error (error, 1, 0, _("missing name, try one of [%s]"), valid_vals); else @@ -170,19 +222,8 @@ finish: g_free (valid_vals); } - 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); + return partial_match; } gboolean @@ -518,3 +559,72 @@ 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 ac18fe94..cc0b7330 100644 --- a/clients/common/nm-client-utils.h +++ b/clients/common/nm-client-utils.h @@ -30,9 +30,9 @@ typedef enum { NMC_TRI_STATE_UNKNOWN, } NMCTriStateValue; -const char *nmc_string_is_valid (const char *input, const char **allowed, GError **error); +const NMObject **nmc_objects_sort_by_path (const NMObject *const*objs, gssize len); -char **nmc_strsplit_set (const char *str, const char *delimiter, int max_tokens); +const char *nmc_string_is_valid (const char *input, const char **allowed, GError **error); gboolean nmc_string_to_uint (const char *str, gboolean range_check, @@ -44,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 it's own, at least not from this file. */ +/* FIXME: don't expose this function on its 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); @@ -56,4 +56,8 @@ 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 cd7ef783..a1bfed47 100644 --- a/clients/common/nm-meta-setting-access.c +++ b/clients/common/nm-meta-setting-access.c @@ -232,6 +232,7 @@ 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); @@ -240,6 +241,7 @@ 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); @@ -251,6 +253,7 @@ 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 54fc6c84..577cad78 100644 --- a/clients/common/nm-meta-setting-access.h +++ b/clients/common/nm-meta-setting-access.h @@ -58,6 +58,7 @@ 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 94404e90..2988b084 100644 --- a/clients/common/nm-meta-setting-desc.c +++ b/clients/common/nm-meta-setting-desc.c @@ -25,10 +25,8 @@ #include <arpa/inet.h> #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" @@ -118,7 +116,6 @@ _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; @@ -126,9 +123,11 @@ _parse_ip_route (int family, GError *local = NULL; gint64 metric = -1; guint i; - gs_strfreev char **routev = NULL; + gs_free const char **routev = NULL; gs_free char *str_clean = NULL; - char *dest; + gs_free char *dest_clone = NULL; + const char *dest; + const char *plen; 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] ...]'") @@ -138,8 +137,8 @@ _parse_ip_route (int family, nm_assert (!error || !*error); str_clean = g_strstrip (g_strdup (str)); - routev = nmc_strsplit_set (str_clean, " \t", 0); - if (!routev || !routev[0]) { + routev = nm_utils_strsplit_set (str_clean, " \t"); + if (!routev) { g_set_error (error, 1, 0, "'%s' is not valid. %s", str, ROUTE_SYNTAX); @@ -148,8 +147,13 @@ _parse_ip_route (int family, dest = routev[0]; plen = strchr (dest, '/'); /* prefix delimiter */ - if (plen) - *plen++ = '\0'; + if (plen) { + dest_clone = g_strdup (dest); + plen = &dest_clone[plen - dest]; + dest = dest_clone; + *((char *) plen) = '\0'; + plen++; + } prefix = MAX_PREFIX; if (plen) { if ((prefix = _nm_utils_ascii_str_to_int64 (plen, 10, 1, MAX_PREFIX, -1)) == -1) { @@ -296,7 +300,7 @@ static NMTeamLinkWatcher * _parse_team_link_watcher (const char *str, GError **error) { - gs_strfreev char **watcherv = NULL; + gs_free const char **watcherv = NULL; gs_free char *str_clean = NULL; guint i; gs_free const char *name = NULL; @@ -309,17 +313,17 @@ _parse_team_link_watcher (const char *str, nm_assert (!error || !*error); str_clean = g_strstrip (g_strdup (str)); - watcherv = nmc_strsplit_set (str_clean, " \t", 0); - if (!watcherv || !watcherv[0]) { + watcherv = nm_utils_strsplit_set (str_clean, " \t"); + if (!watcherv) { g_set_error (error, 1, 0, "'%s' is not valid", str); return NULL; } for (i = 0; watcherv[i]; i++) { - gs_strfreev char **pair = NULL; + gs_free const char **pair = NULL; - pair = nmc_strsplit_set (watcherv[i], "=", 0); - if (!pair[0]) { + pair = nm_utils_strsplit_set (watcherv[i], "="); + if (!pair) { g_set_error (error, 1, 0, "'%s' is not valid: %s", watcherv[i], "properties should be specified as 'key=value'"); return NULL; @@ -605,7 +609,6 @@ _get_text_hidden (NMMetaAccessorGetType get_type) return NM_META_TEXT_HIDDEN; } - /*****************************************************************************/ G_GNUC_PRINTF (4, 5) @@ -636,7 +639,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, 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, gboolean *out_is_default, 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 @@ -669,6 +672,33 @@ _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) { @@ -677,6 +707,7 @@ _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) @@ -692,6 +723,7 @@ _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); } @@ -699,6 +731,7 @@ 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; @@ -707,6 +740,7 @@ _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); @@ -732,13 +766,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_to_free); + return _get_fcn_gobject_impl (property_info, setting, get_type, out_is_default, out_to_free); } static gconstpointer _get_fcn_gobject_int (ARGS_GET_FCN) { - const GParamSpec *pspec; + GParamSpec *pspec; nm_auto_unset_gvalue GValue gval = G_VALUE_INIT; gint64 v; const NMMetaUtilsIntValueInfo *value_infos; @@ -751,6 +785,7 @@ _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); @@ -790,10 +825,11 @@ _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_to_free); + return _get_fcn_gobject_impl (property_info, setting, get_type, out_is_default, 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"; @@ -820,9 +856,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; @@ -833,6 +869,7 @@ _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 (); @@ -875,25 +912,26 @@ _get_fcn_gobject_enum (ARGS_GET_FCN) nm_assert (format_text || format_numeric); - gtype_prop = _gobject_property_get_gtype (G_OBJECT (setting), property_info->property_name); - - g_value_init (&gval, gtype_prop); + pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (setting), property_info->property_name); + g_return_val_if_fail (pspec, NULL); + 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 ( 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 ( 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 (!has_gtype) g_return_val_if_reached (NULL); v = g_value_get_int (&gval); } else v = g_value_get_enum (&gval); - } 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) { + } 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) { if (!has_gtype) g_return_val_if_reached (NULL); v = g_value_get_uint (&gval); @@ -903,7 +941,7 @@ _get_fcn_gobject_enum (ARGS_GET_FCN) g_return_val_if_reached (NULL); if (!has_gtype) { - gtype = gtype_prop; + gtype = pspec->value_type; gtype_class = g_steal_pointer (>ype_prop_class); } @@ -927,7 +965,9 @@ _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. */ - s = nm_utils_enum_to_str (gtype, (int) v); + 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); if (!format_numeric) RETURN_STR_TO_FREE (g_steal_pointer (&s)); @@ -1150,7 +1190,6 @@ _set_fcn_gobject_mac (ARGS_SET_FCN) else mode = NM_META_PROPERTY_TYPE_MAC_MODE_DEFAULT; - if (mode == NM_META_PROPERTY_TYPE_MAC_MODE_INFINIBAND) valid = nm_utils_hwaddr_valid (value, INFINIBAND_ALEN); else { @@ -1169,39 +1208,6 @@ _set_fcn_gobject_mac (ARGS_SET_FCN) } 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) { GType gtype = 0; @@ -1320,7 +1326,7 @@ _values_fcn_gobject_enum (ARGS_VALUES_FCN) gboolean has_minmax = FALSE; int min = G_MININT; int max = G_MAXINT; - char **v, **w; + char **v; if (property_info->property_typ_data) { if ( property_info->property_typ_data->subtype.gobject_enum.min @@ -1354,11 +1360,7 @@ _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 = (char **) nm_utils_enum_get_values (gtype, min, max); - if (v) { - for (w = v; *w; w++) - *w = g_strdup (*w); - } + v = nm_utils_strv_make_deep_copied (nm_utils_enum_get_values (gtype, min, max)); return (const char *const*) (*out_to_free = v); } @@ -1506,24 +1508,6 @@ vlan_priorities_to_string (NMSettingVlan *s_vlan, NMVlanPriorityMap map) } 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) { GString *flag_str; @@ -1573,18 +1557,19 @@ vpn_data_item (const char *key, const char *value, gpointer user_data) const char **valid_strv, \ GError **error) \ { \ - char **strv = NULL, **iter; \ + gs_free const char **strv = NULL; \ + gsize i; \ const char *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; \ + 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); \ } \ - set_func (s_macro (setting), item); \ } \ - g_strfreev (strv); \ return TRUE; \ } @@ -1592,43 +1577,42 @@ vpn_data_item (const char *key, const char *value, gpointer user_data) static gboolean \ def_func (ARGS_SET_FCN) \ { \ - char **strv = NULL, **iter; \ + gs_free const char **strv = NULL; \ + const char **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; \ \ - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); \ + nm_assert (!error || !*error); \ \ - strv = nmc_strsplit_set (value, ",", 0); \ + strv = nm_utils_strsplit_set (value, ","); \ for (iter = strv; iter && *iter; iter++) { \ - char *left = g_strstrip (*iter); \ + gs_free char *left_clone = g_strstrip (g_strdup (*iter)); \ + char *left = left_clone; \ char *right = strchr (left, '='); \ if (!right) { \ g_set_error (error, 1, 0, _("'%s' is not valid; use <option>=<value>"), *iter); \ - g_strfreev (strv); \ return FALSE; \ } \ *right++ = '\0'; \ + g_strchomp (left); \ \ if (valid_func1_p) { \ const char **valid_options = valid_func1_p (s_macro (setting)); \ - if (!(opt_name = nmc_string_is_valid (g_strstrip (left), valid_options, error))) { \ - g_strfreev (strv); \ + if (!(opt_name = nmc_string_is_valid (left, valid_options, error))) { \ return FALSE; \ } \ } else \ - opt_name = g_strstrip (left);\ + opt_name = left;\ \ - opt_val = g_strstrip (right); \ + opt_val = g_strchug (right); \ if (valid_func2_p) { \ if (!(opt_val = valid_func2_p ((const char *) left, (const char *) opt_val, error))) { \ - g_strfreev (strv); \ return FALSE; \ }\ }\ add_func (s_macro (setting), opt_name, opt_val); \ } \ - g_strfreev (strv); \ return TRUE; \ } @@ -1683,47 +1667,45 @@ vpn_data_item (const char *key, const char *value, gpointer user_data) def_func (ARGS_SET_FCN) \ { \ guint8 buf[32]; \ - char **list = NULL, **iter; \ - GSList *macaddr_blacklist = NULL; \ + gs_free const char **strv = NULL; \ + const char *const*iter; \ \ - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); \ + nm_assert (!error || !*error); \ \ - list = nmc_strsplit_set (value, " \t,", 0); \ - for (iter = list; iter && *iter; iter++) { \ + strv = nm_utils_strsplit_set (value, " \t,"); \ + for (iter = strv; strv && *iter; iter++) { \ if (!nm_utils_hwaddr_aton (*iter, buf, ETH_ALEN)) { \ g_set_error (error, 1, 0, _("'%s' is not a valid MAC"), *iter); \ - g_strfreev (list); \ - g_slist_free (macaddr_blacklist); \ return FALSE; \ } \ } \ \ - for (iter = list; iter && *iter; iter++) \ + for (iter = strv; strv && *iter; iter++) \ add_func (s_macro (setting), *iter); \ \ - g_strfreev (list); \ return TRUE; \ } - static gboolean -verify_string_list (char **strv, +verify_string_list (const char *const*strv, const char *prop, gboolean (*validate_func) (const char *), GError **error) { - char **iter; + const char *const*iter; - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + nm_assert (!error || !*error); - for (iter = strv; iter && *iter; iter++) { - if (**iter == '\0') - continue; - if (validate_func) { - if (!validate_func (*iter)) { - g_set_error (error, 1, 0, _("'%s' is not valid"), - *iter); - return FALSE; + if (strv) { + for (iter = strv; *iter; iter++) { + if (**iter == '\0') + continue; + if (validate_func) { + if (!validate_func (*iter)) { + g_set_error (error, 1, 0, _("'%s' is not valid"), + *iter); + return FALSE; + } } } } @@ -1779,7 +1761,7 @@ check_and_set_string (NMSetting *setting, { const char *checked_val; - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + nm_assert (!error || !*error); checked_val = nmc_string_is_valid (val, valid_strv, error); if (!checked_val) @@ -1794,7 +1776,7 @@ _set_fcn_gobject_flags (ARGS_SET_FCN) { unsigned long val_int; - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + nm_assert (!error || !*error); if (!nmc_string_to_uint (value, TRUE, 0, G_MAXUINT, &val_int)) { g_set_error (error, 1, 0, _("'%s' is not a valid number (or out of range)"), value); @@ -1814,7 +1796,7 @@ _set_fcn_gobject_ssid (ARGS_SET_FCN) { GBytes *ssid; - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + nm_assert (!error || !*error); if (strlen (value) > 32) { g_set_error (error, 1, 0, _("'%s' is not valid"), value); @@ -1830,7 +1812,7 @@ _set_fcn_gobject_ssid (ARGS_SET_FCN) static gboolean _set_fcn_gobject_ifname (ARGS_SET_FCN) { - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + nm_assert (!error || !*error); if (!nm_utils_is_valid_iface_name (value, error)) return FALSE; @@ -1892,14 +1874,13 @@ static gboolean nmc_property_set_bytes (NMSetting *setting, const char *prop, const char *value, GError **error) { gs_free char *val_strip = NULL; - gs_strfreev char **strv = NULL; - const char *delimiters = " \t,"; - char **iter; + gs_free const char **strv = NULL; + const char **iter; GBytes *bytes; GByteArray *array = NULL; gboolean success = TRUE; - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + nm_assert (!error || !*error); val_strip = g_strstrip (g_strdup (value)); @@ -1909,8 +1890,8 @@ nmc_property_set_bytes (NMSetting *setting, const char *prop, const char *value, goto done; /* Otherwise, consider the following format: AA b 0xCc D */ - strv = nmc_strsplit_set (val_strip, delimiters, 0); - array = g_byte_array_sized_new (g_strv_length (strv)); + strv = nm_utils_strsplit_set (val_strip, " \t"); + array = g_byte_array_sized_new (NM_PTRARRAY_LEN (strv)); for (iter = strv; iter && *iter; iter++) { int v; guint8 v8; @@ -1961,6 +1942,7 @@ _get_fcn_802_1x_ca_cert (ARGS_GET_FCN) break; } + NM_SET_OUT (out_is_default, !ca_cert_str || !ca_cert_str[0]); RETURN_STR_TO_FREE (ca_cert_str); } @@ -1989,6 +1971,7 @@ _get_fcn_802_1x_client_cert (ARGS_GET_FCN) break; } + NM_SET_OUT (out_is_default, !cert_str || !cert_str[0]); RETURN_STR_TO_FREE (cert_str); } @@ -2014,6 +1997,7 @@ _get_fcn_802_1x_phase2_ca_cert (ARGS_GET_FCN) break; } + NM_SET_OUT (out_is_default, !phase2_ca_cert_str || !phase2_ca_cert_str[0]); RETURN_STR_TO_FREE (phase2_ca_cert_str); } @@ -2042,6 +2026,7 @@ _get_fcn_802_1x_phase2_client_cert (ARGS_GET_FCN) break; } + NM_SET_OUT (out_is_default, !cert_str || !cert_str[0]); RETURN_STR_TO_FREE (cert_str); } @@ -2049,9 +2034,13 @@ static gconstpointer _get_fcn_802_1x_password_raw (ARGS_GET_FCN) { NMSetting8021x *s_8021X = NM_SETTING_802_1X (setting); + char *str; RETURN_UNSUPPORTED_GET_TYPE (); - RETURN_STR_TO_FREE (bytes_to_string (nm_setting_802_1x_get_password_raw (s_8021X))); + + str = bytes_to_string (nm_setting_802_1x_get_password_raw (s_8021X)); + NM_SET_OUT (out_is_default, !str || !str[0]); + RETURN_STR_TO_FREE (str); } static gconstpointer @@ -2079,6 +2068,7 @@ _get_fcn_802_1x_private_key (ARGS_GET_FCN) break; } + NM_SET_OUT (out_is_default, !key_str || !key_str[0]); RETURN_STR_TO_FREE (key_str); } @@ -2107,6 +2097,7 @@ _get_fcn_802_1x_phase2_private_key (ARGS_GET_FCN) break; } + NM_SET_OUT (out_is_default, !key_str || !key_str[0]); RETURN_STR_TO_FREE (key_str); } @@ -2114,15 +2105,16 @@ _get_fcn_802_1x_phase2_private_key (ARGS_GET_FCN) static gboolean \ def_func (ARGS_SET_FCN) \ { \ - char **strv = NULL; \ - guint i = 0; \ + const char **strv = NULL; \ + gsize i; \ \ - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); \ + nm_assert (error == NULL || *error == NULL); \ \ - strv = nmc_strsplit_set (value, " \t,", 0); \ - while (strv && strv[i]) \ - set_func (NM_SETTING_802_1X (setting), strv[i++]); \ - g_strfreev (strv); \ + strv = nm_utils_strsplit_set (value, " \t,"); \ + if (strv) { \ + for (i = 0; strv[i]; i++) \ + set_func (NM_SETTING_802_1X (setting), strv[i++]); \ + } \ return TRUE; \ } @@ -2149,29 +2141,27 @@ _get_fcn_802_1x_phase2_private_key (ARGS_GET_FCN) static gboolean \ def_func (ARGS_SET_FCN) \ { \ - char **strv = NULL; \ - char *val_strip = g_strstrip (g_strdup (value)); \ - char *p = val_strip; \ - const char *path, *password; \ + gs_free char *path = NULL; \ gs_free char *password_free = NULL; \ + char *password; \ NMSetting8021xCKScheme scheme = NM_SETTING_802_1X_CK_SCHEME_PATH; \ - gboolean success; \ \ - if (strncmp (val_strip, NM_SETTING_802_1X_CERT_SCHEME_PREFIX_PKCS11, NM_STRLEN (NM_SETTING_802_1X_CERT_SCHEME_PREFIX_PKCS11)) == 0) \ + value = nm_str_skip_leading_spaces (value); \ + \ + if (strncmp (value, NM_SETTING_802_1X_CERT_SCHEME_PREFIX_PKCS11, NM_STRLEN (NM_SETTING_802_1X_CERT_SCHEME_PREFIX_PKCS11)) == 0) \ scheme = NM_SETTING_802_1X_CK_SCHEME_PKCS11; \ - else if (strncmp (val_strip, NM_SETTING_802_1X_CERT_SCHEME_PREFIX_PATH, NM_STRLEN (NM_SETTING_802_1X_CERT_SCHEME_PREFIX_PATH)) == 0) \ - p += NM_STRLEN (NM_SETTING_802_1X_CERT_SCHEME_PREFIX_PATH); \ + else if (strncmp (value, NM_SETTING_802_1X_CERT_SCHEME_PREFIX_PATH, NM_STRLEN (NM_SETTING_802_1X_CERT_SCHEME_PREFIX_PATH)) == 0) \ + value += NM_STRLEN (NM_SETTING_802_1X_CERT_SCHEME_PREFIX_PATH); \ \ - strv = nmc_strsplit_set (p, " \t,", 2); \ - path = strv[0]; \ - if (g_strv_length (strv) == 2) \ - password = strv[1]; \ - else \ + path = g_strdup (value); \ + password = path + strcspn (path, " \t"); \ + if (password[0] != '\0') { \ + password[0] = '\0'; \ + while (nm_utils_is_separator (password[0])) \ + password++; \ + } else \ password = password_free = g_strdup (pwd_func (NM_SETTING_802_1X (setting))); \ - success = set_func (NM_SETTING_802_1X (setting), path, password, scheme, NULL, error); \ - g_free (val_strip); \ - g_strfreev (strv); \ - return success; \ + return set_func (NM_SETTING_802_1X (setting), path, password, scheme, NULL, error); \ } DEFINE_SETTER_STR_LIST_MULTI (check_and_add_eap_method, @@ -2301,6 +2291,7 @@ _get_fcn_bond_options (ARGS_GET_FCN) } g_string_truncate (bond_options_s, bond_options_s->len-1); /* chop off trailing ',' */ + NM_SET_OUT (out_is_default, bond_options_s->len == 0); RETURN_STR_TO_FREE (g_string_free (bond_options_s, FALSE)); } @@ -2404,6 +2395,9 @@ _get_fcn_connection_permissions (ARGS_GET_FCN) if (nm_setting_connection_get_permission (s_con, i, &perm_type, &perm_item, NULL)) g_string_append_printf (perm, "%s:%s,", perm_type, perm_item); } + + NM_SET_OUT (out_is_default, perm->len == 0); + if (perm->len > 0) { g_string_truncate (perm, perm->len-1); /* remove trailing , */ RETURN_STR_TO_FREE (g_string_free (perm, FALSE)); @@ -2503,25 +2497,20 @@ permissions_valid (const char *perm) static gboolean _set_fcn_connection_permissions (ARGS_SET_FCN) { - char **strv = NULL; - guint i = 0; + gs_free const char **strv = NULL; + gsize i; - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + nm_assert (!error || !*error); - strv = nmc_strsplit_set (value, " \t,", 0); - if (!verify_string_list (strv, property_info->property_name, permissions_valid, error)) { - g_strfreev (strv); + strv = nm_utils_strsplit_set (value, " \t,"); + if (!verify_string_list (strv, property_info->property_name, permissions_valid, error)) return FALSE; - } for (i = 0; strv && strv[i]; i++) { - const char *user; - - if (strncmp (strv[i], PERM_USER_PREFIX, strlen (PERM_USER_PREFIX)) == 0) - user = strv[i]+strlen (PERM_USER_PREFIX); - else - user = strv[i]; + const char *user = strv[i]; + if (strncmp (user, PERM_USER_PREFIX, NM_STRLEN (PERM_USER_PREFIX)) == 0) + user += NM_STRLEN (PERM_USER_PREFIX); nm_setting_connection_add_permission (NM_SETTING_CONNECTION (setting), "user", user, NULL); } @@ -2549,7 +2538,7 @@ DEFINE_REMOVER_INDEX_OR_VALUE (_remove_fcn_connection_permissions, static gboolean _set_fcn_connection_master (ARGS_SET_FCN) { - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + nm_assert (!error || !*error); if (!value) ; @@ -2635,15 +2624,13 @@ _complete_fcn_connection_master (ARGS_COMPLETE_FCN) static gboolean _set_fcn_connection_secondaries (ARGS_SET_FCN) { - gs_strfreev char **strv = NULL; - char **iter; + gs_free const char **strv = NULL; + const char *const*iter; - strv = nmc_strsplit_set (value, " \t,", 0); + strv = nm_utils_strsplit_set (value, " \t,"); if (strv) { - for (iter = strv; *iter; iter++) { - if (**iter) - nm_setting_connection_add_secondary (NM_SETTING_CONNECTION (setting), *iter); - } + for (iter = strv; *iter; iter++) + nm_setting_connection_add_secondary (NM_SETTING_CONNECTION (setting), *iter); } return TRUE; } @@ -2690,9 +2677,11 @@ _get_fcn_connection_metered (ARGS_GET_FCN) break; case NM_METERED_UNKNOWN: default: + NM_SET_OUT (out_is_default, TRUE); s = N_("unknown"); break; } + if (get_type == NM_META_ACCESSOR_GET_TYPE_PRETTY) return _(s); return s; @@ -2830,19 +2819,21 @@ DEFINE_DCB_UINT_GETTER (_get_fcn_dcb_priority_traffic_class, nm_setting_dcb_get_ static gboolean _set_fcn_dcb_flags (ARGS_SET_FCN) { - char **strv = NULL, **iter; NMSettingDcbFlags flags = NM_SETTING_DCB_FLAG_NONE; long int t; - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + nm_assert (!error || !*error); /* Check for overall hex numeric value */ t = _nm_utils_ascii_str_to_int64 (value, 0, 0, DCB_ALL_FLAGS, -1); if (t != -1) flags = (guint) t; else { + gs_free const char **strv = NULL; + const char *const*iter; + /* Check for individual flag numbers */ - strv = nmc_strsplit_set (value, " \t,", 0); + strv = nm_utils_strsplit_set (value, " \t,"); for (iter = strv; iter && *iter; iter++) { t = _nm_utils_ascii_str_to_int64 (*iter, 0, 0, DCB_ALL_FLAGS, -1); @@ -2865,7 +2856,6 @@ _set_fcn_dcb_flags (ARGS_SET_FCN) return FALSE; } } - g_strfreev (strv); } /* Validate the flags according to the property spec */ @@ -2901,7 +2891,7 @@ dcb_parse_uint_array (const char *val, *iter = g_strstrip (*iter); - num = _nm_utils_ascii_str_to_int64 (*iter, 10, 0, other ? other : max, -1); + num = _nm_utils_ascii_str_to_int64 (*iter, 10, 0, other ?: max, -1); /* If number is greater than 'max' it must equal 'other' */ if ( num == -1 @@ -2942,7 +2932,7 @@ _set_fcn_dcb_priority_flow_control (ARGS_SET_FCN) guint i = 0; guint nums[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + nm_assert (!error || !*error); if (!dcb_parse_uint_array (value, 1, 0, nums, error)) return FALSE; @@ -2960,7 +2950,7 @@ _set_fcn_dcb_priority_group_id (ARGS_SET_FCN) guint i = 0; guint nums[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + nm_assert (!error || !*error); if (!dcb_parse_uint_array (value, 7, 15, nums, error)) return FALSE; @@ -2978,7 +2968,7 @@ _set_fcn_dcb_priority_group_bandwidth (ARGS_SET_FCN) guint i = 0, sum = 0; guint nums[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + nm_assert (!error || !*error); if (!dcb_parse_uint_array (value, 100, 0, nums, error)) return FALSE; @@ -3003,7 +2993,7 @@ _set_fcn_dcb_priority_bandwidth (ARGS_SET_FCN) guint i = 0; guint nums[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + nm_assert (!error || !*error); if (!dcb_parse_uint_array (value, 100, 0, nums, error)) return FALSE; @@ -3021,7 +3011,7 @@ _set_fcn_dcb_priority_strict (ARGS_SET_FCN) guint i = 0; guint nums[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + nm_assert (!error || !*error); if (!dcb_parse_uint_array (value, 1, 0, nums, error)) return FALSE; @@ -3039,7 +3029,7 @@ _set_fcn_dcb_priority_traffic_class (ARGS_SET_FCN) guint i = 0; guint nums[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + nm_assert (!error || !*error); if (!dcb_parse_uint_array (value, 7, 0, nums, error)) return FALSE; @@ -3056,7 +3046,7 @@ _set_fcn_gsm_sim_operator_id (ARGS_SET_FCN) { const char *p = value; - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + nm_assert (!error || !*error); if (strlen (value) != 5 && strlen (value) != 6) { g_set_error_literal (error, 1, 0, _("SIM operator ID must be a 5 or 6 number MCCMNC code")); @@ -3082,7 +3072,7 @@ _set_fcn_infiniband_p_key (ARGS_SET_FCN) const gint64 INVALID = G_MININT64; gint64 p_key; - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + nm_assert (!error || !*error); if (nm_streq (value, "default")) p_key = -1; @@ -3098,7 +3088,6 @@ _set_fcn_infiniband_p_key (ARGS_SET_FCN) return TRUE; } - static gconstpointer _get_fcn_infiniband_p_key (ARGS_GET_FCN) { @@ -3109,12 +3098,14 @@ _get_fcn_infiniband_p_key (ARGS_GET_FCN) p_key = nm_setting_infiniband_get_p_key (s_infiniband); if (p_key == -1) { + NM_SET_OUT (out_is_default, TRUE); if (get_type != NM_META_ACCESSOR_GET_TYPE_PRETTY) return "default"; else return _("default"); - } else - RETURN_STR_TO_FREE (g_strdup_printf ("0x%04x", p_key)); + } + + RETURN_STR_TO_FREE (g_strdup_printf ("0x%04x", p_key)); } static gconstpointer @@ -3141,6 +3132,7 @@ _get_fcn_ip_config_addresses (ARGS_GET_FCN) nm_ip_address_get_prefix (addr)); } + NM_SET_OUT (out_is_default, num_addresses == 0); RETURN_STR_TO_FREE (g_string_free (printable, FALSE)); } @@ -3212,6 +3204,7 @@ _get_fcn_ip_config_routes (ARGS_GET_FCN) } } + NM_SET_OUT (out_is_default, num_routes == 0); RETURN_STR_TO_FREE (g_string_free (printable, FALSE)); } @@ -3237,22 +3230,22 @@ _set_fcn_ip4_config_method (ARGS_SET_FCN) static gboolean _set_fcn_ip4_config_dns (ARGS_SET_FCN) { - char **strv = NULL, **iter, *addr; - guint32 ip4_addr; + const char **strv = NULL; + const char *const*iter; + in_addr_t ip4_addr; - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + nm_assert (!error || !*error); - strv = nmc_strsplit_set (value, " \t,", 0); + strv = nm_utils_strsplit_set (value, " \t,"); for (iter = strv; iter && *iter; iter++) { - addr = g_strstrip (*iter); + gs_free char *addr = g_strstrip (g_strdup (*iter)); + if (inet_pton (AF_INET, addr, &ip4_addr) < 1) { g_set_error (error, 1, 0, _("invalid IPv4 address '%s'"), addr); - g_strfreev (strv); return FALSE; } nm_setting_ip_config_add_dns (NM_SETTING_IP_CONFIG (setting), addr); } - g_strfreev (strv); return TRUE; } @@ -3283,21 +3276,19 @@ DEFINE_REMOVER_INDEX_OR_VALUE (_remove_fcn_ipv4_config_dns, static gboolean _set_fcn_ip4_config_dns_search (ARGS_SET_FCN) { - char **strv = NULL; - guint i = 0; + gs_free const char **strv = NULL; + gsize i; - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + nm_assert (!error || !*error); - strv = nmc_strsplit_set (value, " \t,", 0); - if (!verify_string_list (strv, property_info->property_name, nmc_util_is_domain, error)) { - g_strfreev (strv); + strv = nm_utils_strsplit_set (value, " \t,"); + if (!verify_string_list (strv, property_info->property_name, nmc_util_is_domain, error)) return FALSE; - } - - while (strv && strv[i]) - nm_setting_ip_config_add_dns_search (NM_SETTING_IP_CONFIG (setting), strv[i++]); - g_strfreev (strv); + if (strv) { + for (i = 0; strv[i]; i++) + nm_setting_ip_config_add_dns_search (NM_SETTING_IP_CONFIG (setting), strv[i]); + } return TRUE; } @@ -3324,17 +3315,17 @@ DEFINE_REMOVER_INDEX_OR_VALUE (_remove_fcn_ipv4_config_dns_search, static gboolean _set_fcn_ip4_config_dns_options (ARGS_SET_FCN) { - char **strv = NULL; - guint i = 0; + gs_free const char **strv = NULL; + gsize i; - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + nm_assert (!error || !*error); nm_setting_ip_config_clear_dns_options (NM_SETTING_IP_CONFIG (setting), TRUE); - strv = nmc_strsplit_set (value, " \t,", 0); - while (strv && strv[i]) - nm_setting_ip_config_add_dns_option (NM_SETTING_IP_CONFIG (setting), strv[i++]); - g_strfreev (strv); - + strv = nm_utils_strsplit_set (value, " \t,"); + if (strv) { + for (i = 0; strv[i]; i++) + nm_setting_ip_config_add_dns_option (NM_SETTING_IP_CONFIG (setting), strv[i]); + } return TRUE; } @@ -3361,12 +3352,12 @@ DEFINE_REMOVER_INDEX_OR_VALUE (_remove_fcn_ipv4_config_dns_options, static gboolean _set_fcn_ip4_config_addresses (ARGS_SET_FCN) { - gs_strfreev char **strv = NULL; + gs_free const char **strv = NULL; const char *const*iter; NMIPAddress *ip4addr; - strv = nmc_strsplit_set (value, ",", 0); - for (iter = (const char *const*) strv; *iter; iter++) { + strv = nm_utils_strsplit_set (value, ","); + for (iter = strv; *iter; iter++) { ip4addr = _parse_ip_address (AF_INET, *iter, error); if (!ip4addr) return FALSE; @@ -3421,12 +3412,12 @@ _set_fcn_ip4_config_gateway (ARGS_SET_FCN) static gboolean _set_fcn_ip4_config_routes (ARGS_SET_FCN) { - gs_strfreev char **strv = NULL; + gs_free const char **strv = NULL; const char *const*iter; NMIPRoute *ip4route; - strv = nmc_strsplit_set (value, ",", 0); - for (iter = (const char *const*) strv; *iter; iter++) { + strv = nm_utils_strsplit_set (value, ","); + for (iter = strv; *iter; iter++) { ip4route = _parse_ip_route (AF_INET, *iter, error); if (!ip4route) return FALSE; @@ -3460,14 +3451,6 @@ DEFINE_REMOVER_INDEX_OR_VALUE (_remove_fcn_ipv4_config_routes, nm_setting_ip_config_remove_route, _validate_and_remove_ipv4_route) -static gconstpointer -_get_fcn_ip6_config_ip6_privacy (ARGS_GET_FCN) -{ - NMSettingIP6Config *s_ip6 = NM_SETTING_IP6_CONFIG (setting); - RETURN_UNSUPPORTED_GET_TYPE (); - RETURN_STR_TO_FREE (ip6_privacy_to_string (nm_setting_ip6_config_get_ip6_privacy (s_ip6), get_type)); -} - static const char *ipv6_valid_methods[] = { NM_SETTING_IP6_CONFIG_METHOD_IGNORE, NM_SETTING_IP6_CONFIG_METHOD_AUTO, @@ -3491,22 +3474,22 @@ _set_fcn_ip6_config_method (ARGS_SET_FCN) static gboolean _set_fcn_ip6_config_dns (ARGS_SET_FCN) { - char **strv = NULL, **iter, *addr; + gs_free const char **strv = NULL; + const char *const*iter; struct in6_addr ip6_addr; - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + nm_assert (!error || !*error); - strv = nmc_strsplit_set (value, " \t,", 0); + strv = nm_utils_strsplit_set (value, " \t,"); for (iter = strv; iter && *iter; iter++) { - addr = g_strstrip (*iter); + gs_free char *addr = g_strstrip (g_strdup (*iter)); + if (inet_pton (AF_INET6, addr, &ip6_addr) < 1) { g_set_error (error, 1, 0, _("invalid IPv6 address '%s'"), addr); - g_strfreev (strv); return FALSE; } nm_setting_ip_config_add_dns (NM_SETTING_IP_CONFIG (setting), addr); } - g_strfreev (strv); return TRUE; } @@ -3537,21 +3520,19 @@ DEFINE_REMOVER_INDEX_OR_VALUE (_remove_fcn_ipv6_config_dns, static gboolean _set_fcn_ip6_config_dns_search (ARGS_SET_FCN) { - char **strv = NULL; - guint i = 0; + gs_free const char **strv = NULL; + gsize i; - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + nm_assert (!error || !*error); - strv = nmc_strsplit_set (value, " \t,", 0); - if (!verify_string_list (strv, property_info->property_name, nmc_util_is_domain, error)) { - g_strfreev (strv); + strv = nm_utils_strsplit_set (value, " \t,"); + if (!verify_string_list (strv, property_info->property_name, nmc_util_is_domain, error)) return FALSE; - } - - while (strv && strv[i]) - nm_setting_ip_config_add_dns_search (NM_SETTING_IP_CONFIG (setting), strv[i++]); - g_strfreev (strv); + if (strv) { + for (i = 0; strv[i]; i++) + nm_setting_ip_config_add_dns_search (NM_SETTING_IP_CONFIG (setting), strv[i]); + } return TRUE; } @@ -3578,17 +3559,17 @@ DEFINE_REMOVER_INDEX_OR_VALUE (_remove_fcn_ipv6_config_dns_search, static gboolean _set_fcn_ip6_config_dns_options (ARGS_SET_FCN) { - char **strv = NULL; - guint i = 0; + gs_free const char **strv = NULL; + gsize i; - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + nm_assert (!error || !*error); nm_setting_ip_config_clear_dns_options (NM_SETTING_IP_CONFIG (setting), TRUE); - strv = nmc_strsplit_set (value, " \t,", 0); - while (strv && strv[i]) - nm_setting_ip_config_add_dns_option (NM_SETTING_IP_CONFIG (setting), strv[i++]); - g_strfreev (strv); - + strv = nm_utils_strsplit_set (value, " \t,"); + if (strv) { + for (i = 0; strv[i]; i++) + nm_setting_ip_config_add_dns_option (NM_SETTING_IP_CONFIG (setting), strv[i]); + } return TRUE; } @@ -3622,12 +3603,12 @@ _dns_options_is_default (NMSettingIPConfig *setting) static gboolean _set_fcn_ip6_config_addresses (ARGS_SET_FCN) { - gs_strfreev char **strv = NULL; + gs_free const char **strv = NULL; const char *const*iter; NMIPAddress *ip6addr; - strv = nmc_strsplit_set (value, ",", 0); - for (iter = (const char *const*) strv; *iter; iter++) { + strv = nm_utils_strsplit_set (value, ","); + for (iter = strv; strv && *iter; iter++) { ip6addr = _parse_ip_address (AF_INET6, *iter, error); if (!ip6addr) return FALSE; @@ -3682,12 +3663,12 @@ _set_fcn_ip6_config_gateway (ARGS_SET_FCN) static gboolean _set_fcn_ip6_config_routes (ARGS_SET_FCN) { - gs_strfreev char **strv = NULL; + gs_free const char **strv = NULL; const char *const*iter; NMIPRoute *ip6route; - strv = nmc_strsplit_set (value, ",", 0); - for (iter = (const char *const*) strv; *iter; iter++) { + strv = nm_utils_strsplit_set (value, ","); + for (iter = strv; strv && *iter; iter++) { ip6route = _parse_ip_route (AF_INET6, *iter, error); if (!ip6route) return FALSE; @@ -3721,29 +3702,6 @@ DEFINE_REMOVER_INDEX_OR_VALUE (_remove_fcn_ipv6_config_routes, nm_setting_ip_config_remove_route, _validate_and_remove_ipv6_route) -static gboolean -_set_fcn_ip6_config_ip6_privacy (ARGS_SET_FCN) -{ - unsigned long val_int; - - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - - if (!nmc_string_to_uint (value, FALSE, 0, 0, &val_int)) { - g_set_error (error, 1, 0, _("'%s' is not a number"), value); - return FALSE; - } - - if ( val_int != NM_SETTING_IP6_CONFIG_PRIVACY_DISABLED - && val_int != NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_PUBLIC_ADDR - && val_int != NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_TEMP_ADDR) { - g_set_error (error, 1, 0, _("'%s' is not valid; use 0, 1, or 2"), value); - return FALSE; - } - - g_object_set (setting, property_info->property_name, val_int, NULL); - return TRUE; -} - static gconstpointer _get_fcn_olpc_mesh_ssid (ARGS_GET_FCN) { @@ -3759,6 +3717,7 @@ _get_fcn_olpc_mesh_ssid (ARGS_GET_FCN) g_bytes_get_size (ssid)); } + NM_SET_OUT (out_is_default, !ssid_str); RETURN_STR_TO_FREE (ssid_str); } @@ -3767,7 +3726,7 @@ _set_fcn_olpc_mesh_channel (ARGS_SET_FCN) { unsigned long chan_int; - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + nm_assert (!error || !*error); if (!nmc_string_to_uint (value, TRUE, 1, 13, &chan_int)) { g_set_error (error, 1, 0, _("'%s' is not a valid channel; use <1-13>"), value); @@ -3814,6 +3773,7 @@ _get_fcn_tc_config_qdiscs (ARGS_GET_FCN) } } + NM_SET_OUT (out_is_default, num_qdiscs == 0); RETURN_STR_TO_FREE (g_string_free (printable, FALSE)); } @@ -3890,6 +3850,7 @@ _get_fcn_tc_config_tfilters (ARGS_GET_FCN) } } + NM_SET_OUT (out_is_default, num_tfilters == 0); RETURN_STR_TO_FREE (g_string_free (printable, FALSE)); } @@ -3969,18 +3930,15 @@ _is_valid_team_runner_tx_hash_element (const char *tx_hash_element, static gboolean _set_fcn_team_runner_tx_hash (ARGS_SET_FCN) { - char **strv = NULL; - char *const*iter; + gs_free const char **strv = NULL; + const char *const*iter; - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + nm_assert (!error || !*error); - strv = _nm_utils_strv_cleanup (g_strsplit_set (value, " \t,", 0), - TRUE, TRUE, TRUE); + strv = nm_utils_strsplit_set (value, " \t,"); for (iter = strv; strv && *iter; iter++) { - if (!_is_valid_team_runner_tx_hash_element (*iter, error)) { - g_strfreev (strv); + if (!_is_valid_team_runner_tx_hash_element (*iter, error)) return FALSE; - } } while (nm_setting_team_get_num_runner_tx_hash (NM_SETTING_TEAM (setting))) @@ -3988,7 +3946,6 @@ _set_fcn_team_runner_tx_hash (ARGS_SET_FCN) for (iter = strv; strv && *iter; iter++) nm_setting_team_add_runner_tx_hash (NM_SETTING_TEAM (setting), *iter); - g_strfreev (strv); return TRUE; } @@ -4038,19 +3995,20 @@ _get_fcn_team_link_watchers (ARGS_GET_FCN) } } + NM_SET_OUT (out_is_default, num_watchers == 0); RETURN_STR_TO_FREE (g_string_free (printable, FALSE)); } static gboolean _set_fcn_team_link_watchers (ARGS_SET_FCN) { - gs_strfreev char **strv = NULL; + gs_free const char **strv = NULL; const char *const*iter; NMTeamLinkWatcher *watcher; nm_setting_team_clear_link_watchers (NM_SETTING_TEAM (setting)); - strv = nmc_strsplit_set (value, ",", 0); - for (iter = (const char *const*) strv; *iter; iter++) { + strv = nm_utils_strsplit_set (value, ","); + for (iter = strv; strv && *iter; iter++) { watcher = _parse_team_link_watcher (*iter, error); if (!watcher) return FALSE; @@ -4111,19 +4069,20 @@ _get_fcn_team_port_link_watchers (ARGS_GET_FCN) } } + NM_SET_OUT (out_is_default, num_watchers == 0); RETURN_STR_TO_FREE (g_string_free (printable, FALSE)); } static gboolean _set_fcn_team_port_link_watchers (ARGS_SET_FCN) { - gs_strfreev char **strv = NULL; + gs_free const char **strv = NULL; const char *const*iter; NMTeamLinkWatcher *watcher; nm_setting_team_port_clear_link_watchers (NM_SETTING_TEAM_PORT (setting)); - strv = nmc_strsplit_set (value, ",", 0); - for (iter = (const char *const*) strv; *iter; iter++) { + strv = nm_utils_strsplit_set (value, ","); + for (iter = strv; strv && *iter; iter++) { watcher = _parse_team_link_watcher (*iter, error); if (!watcher) return FALSE; @@ -4163,24 +4122,39 @@ static gconstpointer _get_fcn_vlan_flags (ARGS_GET_FCN) { NMSettingVlan *s_vlan = NM_SETTING_VLAN (setting); + guint32 flags; + RETURN_UNSUPPORTED_GET_TYPE (); - RETURN_STR_TO_FREE (vlan_flags_to_string (nm_setting_vlan_get_flags (s_vlan), get_type)); + + flags = nm_setting_vlan_get_flags (s_vlan); + NM_SET_OUT (out_is_default, flags == 0); + RETURN_STR_TO_FREE (vlan_flags_to_string (flags, get_type)); } static gconstpointer _get_fcn_vlan_ingress_priority_map (ARGS_GET_FCN) { NMSettingVlan *s_vlan = NM_SETTING_VLAN (setting); + char *str; + RETURN_UNSUPPORTED_GET_TYPE (); - RETURN_STR_TO_FREE (vlan_priorities_to_string (s_vlan, NM_VLAN_INGRESS_MAP)); + + str = vlan_priorities_to_string (s_vlan, NM_VLAN_INGRESS_MAP); + NM_SET_OUT (out_is_default, !str || !str[0]); + RETURN_STR_TO_FREE (str); } static gconstpointer _get_fcn_vlan_egress_priority_map (ARGS_GET_FCN) { NMSettingVlan *s_vlan = NM_SETTING_VLAN (setting); + char *str; + RETURN_UNSUPPORTED_GET_TYPE (); - RETURN_STR_TO_FREE (vlan_priorities_to_string (s_vlan, NM_VLAN_EGRESS_MAP)); + + str = vlan_priorities_to_string (s_vlan, NM_VLAN_EGRESS_MAP); + NM_SET_OUT (out_is_default, !str || !str[0]); + RETURN_STR_TO_FREE (str); } static gboolean @@ -4303,7 +4277,7 @@ _get_fcn_vpn_data (ARGS_GET_FCN) data_item_str = g_string_new (NULL); nm_setting_vpn_foreach_data_item (s_vpn, &vpn_data_item, data_item_str); - + NM_SET_OUT (out_is_default, data_item_str->len == 0); RETURN_STR_TO_FREE (g_string_free (data_item_str, FALSE)); } @@ -4317,7 +4291,7 @@ _get_fcn_vpn_secrets (ARGS_GET_FCN) secret_str = g_string_new (NULL); nm_setting_vpn_foreach_secret (s_vpn, &vpn_data_item, secret_str); - + NM_SET_OUT (out_is_default, secret_str->len == 0); RETURN_STR_TO_FREE (g_string_free (secret_str, FALSE)); } @@ -4384,20 +4358,18 @@ DEFINE_REMOVER_INDEX_OR_VALUE (_remove_fcn_wired_mac_address_blacklist, static gboolean _set_fcn_wired_s390_subchannels (ARGS_SET_FCN) { - char **strv = NULL; - int len; + gs_free const char **strv = NULL; + gsize len; - strv = nmc_strsplit_set (value, " ,\t", 0); - len = g_strv_length (strv); + strv = nm_utils_strsplit_set (value, " ,\t"); + len = NM_PTRARRAY_LEN (strv); if (len != 2 && len != 3) { g_set_error (error, 1, 0, _("'%s' is not valid; 2 or 3 strings should be provided"), value); - g_strfreev (strv); return FALSE; } g_object_set (setting, property_info->property_name, strv, NULL); - g_strfreev (strv); return TRUE; } @@ -4445,7 +4417,6 @@ _describe_fcn_wired_s390_options (ARGS_DESCRIBE_FCN) return (*out_to_free = s); } - static gconstpointer _get_fcn_wireless_ssid (ARGS_GET_FCN) { @@ -4461,6 +4432,7 @@ _get_fcn_wireless_ssid (ARGS_GET_FCN) g_bytes_get_size (ssid)); } + NM_SET_OUT (out_is_default, !ssid_str || !ssid_str[0]); RETURN_STR_TO_FREE (ssid_str); } @@ -4469,7 +4441,7 @@ _set_fcn_wireless_channel (ARGS_SET_FCN) { unsigned long chan_int; - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + nm_assert (!error || !*error); if (!nmc_string_to_uint (value, FALSE, 0, 0, &chan_int)) { g_set_error (error, 1, 0, _("'%s' is not a valid channel"), value); @@ -4515,39 +4487,23 @@ DEFINE_REMOVER_INDEX_OR_VALUE (_remove_fcn_wireless_mac_address_blacklist, _validate_and_remove_wifi_mac_blacklist_item) static gconstpointer -_get_fcn_wireless_security_wep_key0 (ARGS_GET_FCN) +_get_fcn_wireless_security_wep_key (ARGS_GET_FCN) { NMSettingWirelessSecurity *s_wireless_sec = NM_SETTING_WIRELESS_SECURITY (setting); + char *key; + guint index; RETURN_UNSUPPORTED_GET_TYPE (); - RETURN_STR_TO_FREE (g_strdup (nm_setting_wireless_security_get_wep_key (s_wireless_sec, 0))); -} -static gconstpointer -_get_fcn_wireless_security_wep_key1 (ARGS_GET_FCN) -{ - NMSettingWirelessSecurity *s_wireless_sec = NM_SETTING_WIRELESS_SECURITY (setting); - - RETURN_UNSUPPORTED_GET_TYPE (); - RETURN_STR_TO_FREE (g_strdup (nm_setting_wireless_security_get_wep_key (s_wireless_sec, 1))); -} + nm_assert (g_str_has_prefix (property_info->property_name, "wep-key")); + nm_assert (NM_IN_SET (property_info->property_name[7], '0', '1', '2', '3')); + nm_assert (property_info->property_name[8] == '\0'); -static gconstpointer -_get_fcn_wireless_security_wep_key2 (ARGS_GET_FCN) -{ - NMSettingWirelessSecurity *s_wireless_sec = NM_SETTING_WIRELESS_SECURITY (setting); + index = property_info->property_name[7] - '0'; - RETURN_UNSUPPORTED_GET_TYPE (); - RETURN_STR_TO_FREE (g_strdup (nm_setting_wireless_security_get_wep_key (s_wireless_sec, 2))); -} - -static gconstpointer -_get_fcn_wireless_security_wep_key3 (ARGS_GET_FCN) -{ - NMSettingWirelessSecurity *s_wireless_sec = NM_SETTING_WIRELESS_SECURITY (setting); - - RETURN_UNSUPPORTED_GET_TYPE (); - RETURN_STR_TO_FREE (g_strdup (nm_setting_wireless_security_get_wep_key (s_wireless_sec, 3))); + key = g_strdup (nm_setting_wireless_security_get_wep_key (s_wireless_sec, index)); + NM_SET_OUT (out_is_default, !key); + RETURN_STR_TO_FREE (key); } static const char *wifi_sec_valid_protos[] = { "wpa", "rsn", NULL }; @@ -4665,7 +4621,7 @@ _set_fcn_wireless_wep_key (ARGS_SET_FCN) NMWepKeyType type; guint32 prev_idx, idx; - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + nm_assert (!error || !*error); /* Get currently set type */ type = nm_setting_wireless_security_get_wep_key_type (NM_SETTING_WIRELESS_SECURITY (setting)); @@ -4898,7 +4854,8 @@ static const NMMetaPropertyType _pt_gobject_mac = { static const NMMetaPropertyType _pt_gobject_secret_flags = { .get_fcn = _get_fcn_gobject_secret_flags, - .set_fcn = _set_fcn_gobject_secret_flags, + .set_fcn = _set_fcn_gobject_enum, + .values_fcn = _values_fcn_gobject_enum, }; static const NMMetaPropertyType _pt_gobject_enum = { @@ -4915,7 +4872,7 @@ static const NMMetaPropertyType _pt_gobject_devices = { /*****************************************************************************/ -#include "settings-docs.c" +#include "settings-docs.h" /*****************************************************************************/ @@ -4974,7 +4931,6 @@ static const NMMetaPropertyType _pt_gobject_devices = { "Example:\n" \ " name=arp_ping source-host=172.16.1.1 target-host=172.16.1.254, name=ethtool delay-up=3\n") - #define DEFINE_DCB_PROPRITY_PROPERTY_TYPE \ .property_type = &_pt_gobject_int, \ .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (gobject_int, \ @@ -5603,6 +5559,14 @@ static const NMMetaPropertyInfo *const property_infos_CONNECTION[] = { | NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PRETTY_TEXT, ), ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_CONNECTION_MDNS, + .property_type = &_pt_gobject_enum, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + PROPERTY_TYP_DATA_SUBTYPE (gobject_enum, + .get_gtype = nm_setting_connection_mdns_get_type, + ), + ), + ), NULL }; @@ -6085,9 +6049,18 @@ static const NMMetaPropertyInfo *const property_infos_IP6_CONFIG[] = { .property_type = &_pt_gobject_bool, ), PROPERTY_INFO_WITH_DESC (NM_SETTING_IP6_CONFIG_IP6_PRIVACY, - .property_type = DEFINE_PROPERTY_TYPE ( - .get_fcn = _get_fcn_ip6_config_ip6_privacy, - .set_fcn = _set_fcn_ip6_config_ip6_privacy, + .property_type = &_pt_gobject_enum, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (gobject_enum, + .value_infos_get = ENUM_VALUE_INFOS ( + { + .value = NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_PUBLIC_ADDR, + .nick = "enabled, prefer public IP", + }, + { + .value = NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_TEMP_ADDR, + .nick = "enabled, prefer temporary IP", + } + ), ), ), PROPERTY_INFO_WITH_DESC (NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE, @@ -6174,6 +6147,14 @@ static const NMMetaPropertyInfo *const property_infos_IP_TUNNEL[] = { PROPERTY_INFO_WITH_DESC (NM_SETTING_IP_TUNNEL_MTU, .property_type = &_pt_gobject_mtu, ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_IP_TUNNEL_FLAGS, + .property_type = &_pt_gobject_enum, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + PROPERTY_TYP_DATA_SUBTYPE (gobject_enum, + .get_gtype = nm_ip_tunnel_flags_get_type, + ), + ), + ), NULL }; @@ -7336,28 +7317,28 @@ static const NMMetaPropertyInfo *const property_infos_WIRELESS_SECURITY[] = { PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_SECURITY_WEP_KEY0, .is_secret = TRUE, .property_type = DEFINE_PROPERTY_TYPE ( - .get_fcn = _get_fcn_wireless_security_wep_key0, + .get_fcn = _get_fcn_wireless_security_wep_key, .set_fcn = _set_fcn_wireless_wep_key, ), ), PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_SECURITY_WEP_KEY1, .is_secret = TRUE, .property_type = DEFINE_PROPERTY_TYPE ( - .get_fcn = _get_fcn_wireless_security_wep_key1, + .get_fcn = _get_fcn_wireless_security_wep_key, .set_fcn = _set_fcn_wireless_wep_key, ), ), PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_SECURITY_WEP_KEY2, .is_secret = TRUE, .property_type = DEFINE_PROPERTY_TYPE ( - .get_fcn = _get_fcn_wireless_security_wep_key2, + .get_fcn = _get_fcn_wireless_security_wep_key, .set_fcn = _set_fcn_wireless_wep_key, ), ), PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_SECURITY_WEP_KEY3, .is_secret = TRUE, .property_type = DEFINE_PROPERTY_TYPE ( - .get_fcn = _get_fcn_wireless_security_wep_key3, + .get_fcn = _get_fcn_wireless_security_wep_key, .set_fcn = _set_fcn_wireless_wep_key, ), ), @@ -7402,6 +7383,14 @@ static const NMMetaPropertyInfo *const property_infos_WIRELESS_SECURITY[] = { ), ), ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_SECURITY_FILS, + .property_type = &_pt_gobject_enum, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + PROPERTY_TYP_DATA_SUBTYPE (gobject_enum, + .get_gtype = nm_setting_wireless_security_fils_get_type, + ), + ), + ), NULL }; @@ -7899,6 +7888,7 @@ _meta_type_setting_info_editor_get_fcn (const NMMetaAbstractInfo *abstract_info, NMMetaAccessorGetType get_type, NMMetaAccessorGetFlags get_flags, NMMetaAccessorGetOutFlags *out_flags, + gboolean *out_is_default, gpointer *out_to_free) { const NMMetaSettingInfoEditor *info = (const NMMetaSettingInfoEditor *) abstract_info; @@ -7924,6 +7914,7 @@ _meta_type_property_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 NMMetaPropertyInfo *info = (const NMMetaPropertyInfo *) abstract_info; @@ -7939,8 +7930,10 @@ _meta_type_property_info_get_fcn (const NMMetaAbstractInfo *abstract_info, nm_assert (out_to_free); if ( info->is_secret - && !NM_FLAGS_HAS (get_flags, NM_META_ACCESSOR_GET_FLAGS_SHOW_SECRETS)) + && !NM_FLAGS_HAS (get_flags, NM_META_ACCESSOR_GET_FLAGS_SHOW_SECRETS)) { + NM_SET_OUT (out_is_default, TRUE); return _get_text_hidden (get_type); + } return info->property_type->get_fcn (info, environment, @@ -7949,6 +7942,7 @@ _meta_type_property_info_get_fcn (const NMMetaAbstractInfo *abstract_info, get_type, get_flags, out_flags, + out_is_default, out_to_free); } diff --git a/clients/common/nm-meta-setting-desc.h b/clients/common/nm-meta-setting-desc.h index e61b1fc4..e7ab6e86 100644 --- a/clients/common/nm-meta-setting-desc.h +++ b/clients/common/nm-meta-setting-desc.h @@ -14,7 +14,7 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright 2010 - 2017 Red Hat, Inc. + * Copyright 2010 - 2018 Red Hat, Inc. */ #ifndef __NM_META_SETTING_DESC_H__ @@ -83,31 +83,54 @@ struct _NMDevice; #define NM_META_TEXT_PROMPT_PROXY_METHOD_CHOICES "(" NM_META_TEXT_WORD_NONE "/" NM_META_TEXT_WORD_AUTO ") [" NM_META_TEXT_WORD_NONE "]" typedef enum { - NM_META_TERM_COLOR_NORMAL = 0, - NM_META_TERM_COLOR_BLACK = 1, - NM_META_TERM_COLOR_RED = 2, - NM_META_TERM_COLOR_GREEN = 3, - NM_META_TERM_COLOR_YELLOW = 4, - NM_META_TERM_COLOR_BLUE = 5, - NM_META_TERM_COLOR_MAGENTA = 6, - NM_META_TERM_COLOR_CYAN = 7, - NM_META_TERM_COLOR_WHITE = 8, -} NMMetaTermColor; - -typedef enum { - NM_META_TERM_FORMAT_NORMAL = 0, - NM_META_TERM_FORMAT_BOLD = 1, - NM_META_TERM_FORMAT_DIM = 2, - NM_META_TERM_FORMAT_UNDERLINE = 3, - NM_META_TERM_FORMAT_BLINK = 4, - NM_META_TERM_FORMAT_REVERSE = 5, - NM_META_TERM_FORMAT_HIDDEN = 6, -} NMMetaTermFormat; + NM_META_COLOR_NONE = 0, + NM_META_COLOR_CONNECTION_ACTIVATED, + NM_META_COLOR_CONNECTION_ACTIVATING, + NM_META_COLOR_CONNECTION_DISCONNECTING, + NM_META_COLOR_CONNECTION_INVISIBLE, + NM_META_COLOR_CONNECTION_UNKNOWN, + NM_META_COLOR_CONNECTIVITY_FULL, + NM_META_COLOR_CONNECTIVITY_LIMITED, + NM_META_COLOR_CONNECTIVITY_NONE, + NM_META_COLOR_CONNECTIVITY_PORTAL, + NM_META_COLOR_CONNECTIVITY_UNKNOWN, + NM_META_COLOR_DEVICE_ACTIVATED, + NM_META_COLOR_DEVICE_ACTIVATING, + NM_META_COLOR_DEVICE_DISCONNECTED, + NM_META_COLOR_DEVICE_FIRMWARE_MISSING, + NM_META_COLOR_DEVICE_PLUGIN_MISSING, + NM_META_COLOR_DEVICE_UNAVAILABLE, + NM_META_COLOR_DEVICE_UNKNOWN, + NM_META_COLOR_MANAGER_RUNNING, + NM_META_COLOR_MANAGER_STARTING, + NM_META_COLOR_MANAGER_STOPPED, + NM_META_COLOR_PERMISSION_AUTH, + NM_META_COLOR_PERMISSION_NO, + NM_META_COLOR_PERMISSION_UNKNOWN, + NM_META_COLOR_PERMISSION_YES, + NM_META_COLOR_PROMPT, + NM_META_COLOR_STATE_ASLEEP, + NM_META_COLOR_STATE_CONNECTED_GLOBAL, + NM_META_COLOR_STATE_CONNECTED_LOCAL, + NM_META_COLOR_STATE_CONNECTED_SITE, + NM_META_COLOR_STATE_CONNECTING, + NM_META_COLOR_STATE_DISCONNECTED, + NM_META_COLOR_STATE_DISCONNECTING, + NM_META_COLOR_STATE_UNKNOWN, + NM_META_COLOR_WIFI_SIGNAL_EXCELLENT, + NM_META_COLOR_WIFI_SIGNAL_FAIR, + NM_META_COLOR_WIFI_SIGNAL_GOOD, + NM_META_COLOR_WIFI_SIGNAL_POOR, + NM_META_COLOR_WIFI_SIGNAL_UNKNOWN, + NM_META_COLOR_DISABLED, + NM_META_COLOR_ENABLED, + _NM_META_COLOR_NUM +} NMMetaColor; typedef enum { NM_META_ACCESSOR_GET_TYPE_PRETTY, NM_META_ACCESSOR_GET_TYPE_PARSABLE, - NM_META_ACCESSOR_GET_TYPE_TERMFORMAT, + NM_META_ACCESSOR_GET_TYPE_COLOR, } NMMetaAccessorGetType; typedef enum { @@ -115,32 +138,6 @@ typedef enum { NM_META_ACCESSOR_SETTING_INIT_TYPE_CLI, } NMMetaAccessorSettingInitType; -static inline void -nm_meta_termformat_unpack (gconstpointer value, NMMetaTermColor *out_color, NMMetaTermFormat *out_format) -{ - /* get_fcn() with NM_META_ACCESSOR_GET_TYPE_TERMFORMAT returns a pointer - * that encodes NMMetaTermColor and NMMetaTermFormat. Unpack it. */ - if (!value) { - /* by default, objects that don't support NM_META_ACCESSOR_GET_TYPE_TERMFORMAT - * return NULL. This allows for an explicit fallback value here... */ - NM_SET_OUT (out_color, NM_META_TERM_COLOR_NORMAL); - NM_SET_OUT (out_format, NM_META_TERM_FORMAT_NORMAL); - } else { - NM_SET_OUT (out_color, GPOINTER_TO_UINT (value) & 0xFF); - NM_SET_OUT (out_format, (GPOINTER_TO_UINT (value) & 0xFF00) >> 8); - } -} - -static inline gconstpointer -nm_meta_termformat_pack (NMMetaTermColor color, NMMetaTermFormat format) -{ - /* get_fcn() with NM_META_ACCESSOR_GET_TYPE_TERMFORMAT returns a pointer - * that encodes NMMetaTermColor and NMMetaTermFormat. Pack it. */ - return GUINT_TO_POINTER (((guint) 0x10000) | (((guint) color) & 0xFFu) | ((((guint) format) & 0xFFu) << 8)); -} - -#define NM_META_TERMFORMAT_DEFAULT() (nm_meta_termformat_pack (NM_META_TERM_COLOR_NORMAL, NM_META_TERM_FORMAT_NORMAL)) - typedef enum { NM_META_ACCESSOR_GET_FLAGS_NONE = 0, NM_META_ACCESSOR_GET_FLAGS_ACCEPT_STRV = (1LL << 0), @@ -181,7 +178,7 @@ typedef struct _NMMetaPropertyTypDataNested NMMetaPropertyTypDataNested; /* this gives some context information for virtual functions. * This command actually violates layering, and should be considered - * a hack. In the future, try to replace it's use. */ + * a hack. In the future, try to replace its use. */ struct _NMMetaOperationContext { NMConnection *connection; }; @@ -199,6 +196,7 @@ struct _NMMetaPropertyType { NMMetaAccessorGetType get_type, NMMetaAccessorGetFlags get_flags, NMMetaAccessorGetOutFlags *out_flags, + gboolean *out_is_default, gpointer *out_to_free); gboolean (*set_fcn) (const NMMetaPropertyInfo *property_info, const NMMetaEnvironment *environment, @@ -241,7 +239,8 @@ struct _NMMetaPropertyTypData { GType (*get_gtype) (void); int min; int max; - const struct _NMUtilsEnumValueInfo *value_infos; + const struct _NMUtilsEnumValueInfo *value_infos_get; /* nicks for get function */ + const struct _NMUtilsEnumValueInfo *value_infos; /* nicks for set function */ void (*pre_set_notify) (const NMMetaPropertyInfo *property_info, const NMMetaEnvironment *environment, gpointer environment_user_data, @@ -362,6 +361,7 @@ struct _NMMetaType { NMMetaAccessorGetType get_type, NMMetaAccessorGetFlags get_flags, NMMetaAccessorGetOutFlags *out_flags, + gboolean *out_is_defalt, gpointer *out_to_free); const char *const*(*complete_fcn) (const NMMetaAbstractInfo *info, const NMMetaEnvironment *environment, diff --git a/clients/common/nm-polkit-listener.c b/clients/common/nm-polkit-listener.c index 69f49062..300cf11e 100644 --- a/clients/common/nm-polkit-listener.c +++ b/clients/common/nm-polkit-listener.c @@ -33,15 +33,15 @@ #include "nm-default.h" +#include "nm-polkit-listener.h" + #include <string.h> #include <stdio.h> #include <stdlib.h> -#include "nm-polkit-listener.h" - -G_DEFINE_TYPE (NMPolkitListener, nm_polkit_listener, POLKIT_AGENT_TYPE_LISTENER) +#if WITH_POLKIT_AGENT -#define NM_POLKIT_LISTENER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_POLKIT_LISTENER, NMPolkitListenerPrivate)) +/*****************************************************************************/ typedef struct { gpointer reg_handle; /* handle of polkit agent registration */ @@ -56,14 +56,28 @@ typedef struct { char *icon_name; char *identity; - /* callbacks */ - NMPolkitListenerOnRequestFunc on_request_callback; - NMPolkitListenerOnShowInfoFunc on_show_info_callback; - NMPolkitListenerOnShowErrorFunc on_show_error_callback; - NMPolkitListenerOnCompletedFunc on_completed_callback; - gpointer request_callback_data; + const NMPolkitListenVtable *vtable; + gpointer vtable_user_data; } NMPolkitListenerPrivate; +G_DEFINE_TYPE (NMPolkitListener, nm_polkit_listener, POLKIT_AGENT_TYPE_LISTENER) + +#define NM_POLKIT_LISTENER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_POLKIT_LISTENER, NMPolkitListenerPrivate)) + +/*****************************************************************************/ + +void +nm_polkit_listener_set_vtable (NMPolkitListener *self, + const NMPolkitListenVtable *vtable, + gpointer user_data) +{ + NMPolkitListenerPrivate *priv = NM_POLKIT_LISTENER_GET_PRIVATE (self); + + priv->vtable = vtable; + priv->vtable_user_data = user_data; +} + +/*****************************************************************************/ static void on_request (PolkitAgentSession *session, @@ -71,20 +85,21 @@ on_request (PolkitAgentSession *session, gboolean echo_on, gpointer user_data) { - NMPolkitListenerPrivate *priv = NM_POLKIT_LISTENER_GET_PRIVATE (user_data); - char *response = NULL; - - if (priv->on_request_callback) { - response = priv->on_request_callback (request, priv->action_id, - priv->message, priv->icon_name, - priv->identity, echo_on, - priv->request_callback_data); + NMPolkitListener *self = NM_POLKIT_LISTENER (user_data); + NMPolkitListenerPrivate *priv = NM_POLKIT_LISTENER_GET_PRIVATE (self); + gs_free char *response = NULL; + + if (priv->vtable && priv->vtable->on_request) { + response = priv->vtable->on_request (self, + request, priv->action_id, + priv->message, priv->icon_name, + priv->identity, echo_on, + priv->vtable_user_data); } - if (response) { + if (response) polkit_agent_session_response (session, response); - g_free (response); - } else { + else { //FIXME: polkit_agent_session_cancel() should emit "completed", but it doesn't work for me ??? //polkit_agent_session_cancel (session); polkit_agent_session_response (session, ""); @@ -96,10 +111,13 @@ on_show_info (PolkitAgentSession *session, const char *text, gpointer user_data) { - NMPolkitListenerPrivate *priv = NM_POLKIT_LISTENER_GET_PRIVATE (user_data); + NMPolkitListener *self = NM_POLKIT_LISTENER (user_data); + NMPolkitListenerPrivate *priv = NM_POLKIT_LISTENER_GET_PRIVATE (self); - if (priv->on_show_info_callback) - priv->on_show_info_callback (text); + if (priv->vtable && priv->vtable->on_show_info) { + priv->vtable->on_show_info (self, text, + priv->vtable_user_data); + } } static void @@ -107,10 +125,13 @@ on_show_error (PolkitAgentSession *session, const char *text, gpointer user_data) { - NMPolkitListenerPrivate *priv = NM_POLKIT_LISTENER_GET_PRIVATE (user_data); + NMPolkitListener *self = NM_POLKIT_LISTENER (user_data); + NMPolkitListenerPrivate *priv = NM_POLKIT_LISTENER_GET_PRIVATE (self); - if (priv->on_show_error_callback) - priv->on_show_error_callback (text); + if (priv->vtable && priv->vtable->on_show_error) { + priv->vtable->on_show_error (self, text, + priv->vtable_user_data); + } } static void @@ -118,10 +139,13 @@ on_completed (PolkitAgentSession *session, gboolean gained_authorization, gpointer user_data) { - NMPolkitListenerPrivate *priv = NM_POLKIT_LISTENER_GET_PRIVATE (user_data); + NMPolkitListener *self = NM_POLKIT_LISTENER (user_data); + NMPolkitListenerPrivate *priv = NM_POLKIT_LISTENER_GET_PRIVATE (self); - if (priv->on_completed_callback) - priv->on_completed_callback (gained_authorization); + if (priv->vtable->on_completed) { + priv->vtable->on_completed (self, gained_authorization, + priv->vtable_user_data); + } g_simple_async_result_complete_in_idle (priv->simple); @@ -145,7 +169,8 @@ on_completed (PolkitAgentSession *session, static void on_cancelled (GCancellable *cancellable, gpointer user_data) { - NMPolkitListenerPrivate *priv = NM_POLKIT_LISTENER_GET_PRIVATE (user_data); + NMPolkitListener *self = NM_POLKIT_LISTENER (user_data); + NMPolkitListenerPrivate *priv = NM_POLKIT_LISTENER_GET_PRIVATE (self); polkit_agent_session_cancel (priv->active_session); } @@ -264,62 +289,37 @@ initiate_authentication_finish (PolkitAgentListener *listener, return !g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), error); } +/*****************************************************************************/ static void nm_polkit_listener_init (NMPolkitListener *agent) { } -static void -nm_polkit_listener_finalize (GObject *object) -{ - NMPolkitListenerPrivate *priv = NM_POLKIT_LISTENER_GET_PRIVATE (object); - - if (priv->reg_handle) - polkit_agent_listener_unregister (priv->reg_handle); - - g_free (priv->action_id); - g_free (priv->message); - g_free (priv->icon_name); - g_free (priv->identity); - - G_OBJECT_CLASS (nm_polkit_listener_parent_class)->finalize (object); -} - -static void -nm_polkit_listener_class_init (NMPolkitListenerClass *klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - PolkitAgentListenerClass *pkal_class = POLKIT_AGENT_LISTENER_CLASS (klass); - - g_type_class_add_private (klass, sizeof (NMPolkitListenerPrivate)); - - gobject_class->finalize = nm_polkit_listener_finalize; - - pkal_class->initiate_authentication = initiate_authentication; - pkal_class->initiate_authentication_finish = initiate_authentication_finish; -} - /** * nm_polkit_listener_new: * @for_session: %TRUE for registering the polkit agent for the user session, * %FALSE for registering it for the running process + * @vtable: mandatory callbacks + * @user_data: user-data pointer for callbacks * @error: location to store error, or %NULL * * Creates a new #NMPolkitListener and registers it as a polkit agent. * * Returns: a new #NMPolkitListener */ -PolkitAgentListener * -nm_polkit_listener_new (gboolean for_session, GError **error) +NMPolkitListener * +nm_polkit_listener_new (gboolean for_session, + GError **error) { - PolkitAgentListener *listener; + NMPolkitListener *listener; PolkitSubject* session; NMPolkitListenerPrivate *priv; - g_return_val_if_fail (error == NULL || *error == NULL, NULL); + g_return_val_if_fail (!error || !*error, NULL); listener = g_object_new (NM_TYPE_POLKIT_LISTENER, NULL); + priv = NM_POLKIT_LISTENER_GET_PRIVATE (listener); if (for_session) { @@ -329,7 +329,8 @@ nm_polkit_listener_new (gboolean for_session, GError **error) } else session = polkit_unix_process_new_for_owner (getpid (), 0, getuid ()); - priv->reg_handle = polkit_agent_listener_register (listener, POLKIT_AGENT_REGISTER_FLAGS_NONE, + priv->reg_handle = polkit_agent_listener_register (POLKIT_AGENT_LISTENER (listener), + POLKIT_AGENT_REGISTER_FLAGS_NONE, session, NULL, NULL, error); if (!priv->reg_handle) { g_object_unref (listener); @@ -340,77 +341,34 @@ nm_polkit_listener_new (gboolean for_session, GError **error) return listener; } -/** - * nm_polkit_listener_set_request_callback: - * @self: a #NMPolkitListener object - * @request_callback: callback to install for polkit requests - * @request_callback_data: usaer data passed to request_callback when it is called - * - * Set a callback for "request" signal. The callback will be invoked when polkit - * requests an authorization. - */ -void -nm_polkit_listener_set_request_callback (NMPolkitListener *self, - NMPolkitListenerOnRequestFunc request_callback, - gpointer request_callback_data) +static void +nm_polkit_listener_finalize (GObject *object) { - NMPolkitListenerPrivate *priv; + NMPolkitListenerPrivate *priv = NM_POLKIT_LISTENER_GET_PRIVATE (object); - g_return_if_fail (NM_IS_POLKIT_LISTENER (self)); + if (priv->reg_handle) + polkit_agent_listener_unregister (priv->reg_handle); - priv = NM_POLKIT_LISTENER_GET_PRIVATE (self); + g_free (priv->action_id); + g_free (priv->message); + g_free (priv->icon_name); + g_free (priv->identity); - priv->on_request_callback = request_callback; - priv->request_callback_data = request_callback_data; + G_OBJECT_CLASS (nm_polkit_listener_parent_class)->finalize (object); } -/** - * nm_polkit_listener_set_show_info_callback: - * @self: a #NMPolkitListener object - * @show_info_callback: callback to install for polkit show info trigger - * - * Set a callback for "show-info" signal. The callback will be invoked when polkit - * has an info text to display. - */ -void -nm_polkit_listener_set_show_info_callback (NMPolkitListener *self, - NMPolkitListenerOnShowInfoFunc show_info_callback) +static void +nm_polkit_listener_class_init (NMPolkitListenerClass *klass) { - g_return_if_fail (NM_IS_POLKIT_LISTENER (self)); + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + PolkitAgentListenerClass *pkal_class = POLKIT_AGENT_LISTENER_CLASS (klass); - NM_POLKIT_LISTENER_GET_PRIVATE (self)->on_show_info_callback = show_info_callback; -} + g_type_class_add_private (klass, sizeof (NMPolkitListenerPrivate)); -/** - * nm_polkit_listener_set_show_error_callback: - * @self: a #NMPolkitListener object - * @show_error_callback: callback to install for polkit show error trigger - * - * Set a callback for "show-error" signal. The callback will be invoked when polkit - * has an error text to display. - */ -void -nm_polkit_listener_set_show_error_callback (NMPolkitListener *self, - NMPolkitListenerOnShowErrorFunc show_error_callback) -{ - g_return_if_fail (NM_IS_POLKIT_LISTENER (self)); + gobject_class->finalize = nm_polkit_listener_finalize; - NM_POLKIT_LISTENER_GET_PRIVATE (self)->on_show_error_callback = show_error_callback; + pkal_class->initiate_authentication = initiate_authentication; + pkal_class->initiate_authentication_finish = initiate_authentication_finish; } -/** - * nm_polkit_listener_set_completed_callback: - * @self: a #NMPolkitListener object - * @completed_callback: callback to install for polkit completing authorization - * - * Set a callback for "completed" signal. The callback will be invoked when polkit - * completed the request. - */ -void -nm_polkit_listener_set_completed_callback (NMPolkitListener *self, - NMPolkitListenerOnCompletedFunc completed_callback) -{ - g_return_if_fail (NM_IS_POLKIT_LISTENER (self)); - - NM_POLKIT_LISTENER_GET_PRIVATE (self)->on_completed_callback = completed_callback; -} +#endif /* WITH_POLKIT_AGENT */ diff --git a/clients/common/nm-polkit-listener.h b/clients/common/nm-polkit-listener.h index a8256460..d69f8eca 100644 --- a/clients/common/nm-polkit-listener.h +++ b/clients/common/nm-polkit-listener.h @@ -19,6 +19,64 @@ #ifndef __NM_POLKIT_LISTENER_H__ #define __NM_POLKIT_LISTENER_H__ +#if WITH_POLKIT_AGENT + +typedef struct _NMPolkitListener NMPolkitListener; +typedef struct _NMPolkitListenerClass NMPolkitListenerClass; + +typedef struct { + + /* + * @request: the request asked by polkit agent + * @action_id: the action_id of the polkit request + * @message: the message of the polkit request + * @icon_name: the icon name of the polkit request + * @user: user name + * @echo_on: whether the response to the request should be echoed to the screen + * @user_data: user data for the callback + * + * Called as a result of a request by polkit. The function should obtain response + * to the request from user, i.e. get the password required. + */ + char *(*on_request) (NMPolkitListener *self, + const char *request, + const char *action_id, + const char *message, + const char *icon_name, + const char *user, + gboolean echo_on, + gpointer user_data); + + /* + * @text: the info text from polkit + * + * Called as a result of show-info signal by polkit. + */ + void (*on_show_info) (NMPolkitListener *self, + const char *text, + gpointer user_data); + + /* + * @text: the error text from polkit + * + * Called as a result of show-error signal by polkit. + */ + void (*on_show_error) (NMPolkitListener *self, + const char *text, + gpointer user_data); + + /* + * @gained_authorization: whether the autorization was successful + * + * Called as a result of completed signal by polkit. + */ + void (*on_completed) (NMPolkitListener *self, + gboolean gained_authorization, + gpointer user_data); +} NMPolkitListenVtable; + +/*****************************************************************************/ + #define POLKIT_AGENT_I_KNOW_API_IS_SUBJECT_TO_CHANGE #include <polkitagent/polkitagent.h> @@ -71,28 +129,23 @@ typedef void (*NMPolkitListenerOnShowErrorFunc) (const char *text); */ typedef void (*NMPolkitListenerOnCompletedFunc) (gboolean gained_authorization); - -typedef struct { +struct _NMPolkitListener { PolkitAgentListener parent; +}; -} NMPolkitListener; - -typedef struct { +struct _NMPolkitListenerClass { PolkitAgentListenerClass parent; - -} NMPolkitListenerClass; +}; GType nm_polkit_listener_get_type (void); -PolkitAgentListener* nm_polkit_listener_new (gboolean for_session, GError **error); -void nm_polkit_listener_set_request_callback (NMPolkitListener *self, - NMPolkitListenerOnRequestFunc request_callback, - gpointer request_callback_data); -void nm_polkit_listener_set_show_info_callback (NMPolkitListener *self, - NMPolkitListenerOnShowInfoFunc show_info_callback); -void nm_polkit_listener_set_show_error_callback (NMPolkitListener *self, - NMPolkitListenerOnShowErrorFunc show_error_callback); -void nm_polkit_listener_set_completed_callback (NMPolkitListener *self, - NMPolkitListenerOnCompletedFunc completed_callback); +NMPolkitListener *nm_polkit_listener_new (gboolean for_session, + GError **error); + +void nm_polkit_listener_set_vtable (NMPolkitListener *self, + const NMPolkitListenVtable *vtable, + gpointer user_data); + +#endif #endif /* __NM_POLKIT_LISTENER_H__ */ diff --git a/clients/common/nm-secret-agent-simple.c b/clients/common/nm-secret-agent-simple.c index 4ef1be23..4db57ca5 100644 --- a/clients/common/nm-secret-agent-simple.c +++ b/clients/common/nm-secret-agent-simple.c @@ -33,9 +33,6 @@ #include <string.h> -#include "nm-utils/nm-hash-utils.h" - -#include "NetworkManager.h" #include "nm-vpn-service-plugin.h" #include "nm-vpn-helpers.h" @@ -149,7 +146,6 @@ strv_has (gchar **haystack, typedef struct { NMSecretAgentSimpleSecret base; - NMSetting *setting; char *property; } NMSecretAgentSimpleSecretReal; @@ -159,11 +155,10 @@ nm_secret_agent_simple_secret_free (NMSecretAgentSimpleSecret *secret) { NMSecretAgentSimpleSecretReal *real = (NMSecretAgentSimpleSecretReal *)secret; - g_free (secret->name); - g_free (secret->prop_name); + g_free ((char *) secret->pretty_name); + g_free ((char *) secret->entry_id); g_free (secret->value); - g_free (secret->vpn_property); - g_free (secret->vpn_type); + g_free ((char *) secret->vpn_type); g_free (real->property); g_clear_object (&real->setting); @@ -171,33 +166,45 @@ nm_secret_agent_simple_secret_free (NMSecretAgentSimpleSecret *secret) } static NMSecretAgentSimpleSecret * -nm_secret_agent_simple_secret_new (const char *name, +nm_secret_agent_simple_secret_new (NMSecretAgentSecretType secret_type, + const char *pretty_name, NMSetting *setting, const char *property, - const char *vpn_property, - const char *vpn_type, - gboolean password) + const char *vpn_type) { NMSecretAgentSimpleSecretReal *real; + const char *vpn_prefix; + const char *value; + + nm_assert (property); + nm_assert (NM_IS_SETTING (setting)); real = g_slice_new0 (NMSecretAgentSimpleSecretReal); - real->base.name = g_strdup (name); - real->base.prop_name = vpn_property ? - g_strdup_printf ("%s.%s.%s", nm_setting_get_name (setting), property, vpn_property) : - g_strdup_printf ("%s.%s", nm_setting_get_name (setting), property); - real->base.vpn_property = g_strdup (vpn_property); - real->base.vpn_type = g_strdup (vpn_type); - real->base.password = password; - - if (setting) { - real->setting = g_object_ref (setting); - real->property = g_strdup (property); - - if (vpn_property) - real->base.value = g_strdup (nm_setting_vpn_get_secret (NM_SETTING_VPN (setting), vpn_property)); - else - g_object_get (setting, property, &real->base.value, NULL); + *((NMSecretAgentSecretType *) &real->base.secret_type) = secret_type; + real->setting = g_object_ref (setting); + real->base.pretty_name = g_strdup (pretty_name); + real->property = g_strdup (property); + switch (secret_type) { + case NM_SECRET_AGENT_SECRET_TYPE_PROPERTY: + case NM_SECRET_AGENT_SECRET_TYPE_SECRET: + nm_assert (!vpn_type); + nm_assert (g_object_class_find_property (G_OBJECT_GET_CLASS (setting), property)); + nm_assert ((secret_type == NM_SECRET_AGENT_SECRET_TYPE_SECRET) == nm_setting_get_secret_flags (setting, property, NULL, NULL)); + real->base.entry_id = g_strdup_printf ("%s.%s", nm_setting_get_name (setting), property); + g_object_get (setting, property, &real->base.value, NULL); + real->base.is_secret = (secret_type != NM_SECRET_AGENT_SECRET_TYPE_PROPERTY); + break; + case NM_SECRET_AGENT_SECRET_TYPE_VPN_SECRET: + vpn_prefix = NM_SECRET_AGENT_ENTRY_ID_PREFX_VPN_SECRET; + value = nm_setting_vpn_get_secret (NM_SETTING_VPN (setting), property); + real->base.entry_id = g_strdup_printf ("%s%s", vpn_prefix, property); + nm_assert (vpn_type); + real->base.vpn_type = g_strdup (vpn_type); + real->base.value = g_strdup (value); + real->base.is_secret = TRUE; + break; } + nm_assert (real->base.entry_id); return &real->base; } @@ -222,37 +229,33 @@ add_8021x_secrets (NMSecretAgentSimpleRequest *request, * is not visible here since we only care about phase2 authentication * (and don't even care of which one) */ - secret = nm_secret_agent_simple_secret_new (_("Username"), + secret = nm_secret_agent_simple_secret_new (NM_SECRET_AGENT_SECRET_TYPE_PROPERTY, + _("Username"), NM_SETTING (s_8021x), NM_SETTING_802_1X_IDENTITY, - NULL, - NULL, - FALSE); + NULL); g_ptr_array_add (secrets, secret); - secret = nm_secret_agent_simple_secret_new (_("Password"), + secret = nm_secret_agent_simple_secret_new (NM_SECRET_AGENT_SECRET_TYPE_SECRET, + _("Password"), NM_SETTING (s_8021x), NM_SETTING_802_1X_PASSWORD, - NULL, - NULL, - TRUE); + NULL); g_ptr_array_add (secrets, secret); return TRUE; } if (!strcmp (eap_method, "tls")) { - secret = nm_secret_agent_simple_secret_new (_("Identity"), + secret = nm_secret_agent_simple_secret_new (NM_SECRET_AGENT_SECRET_TYPE_PROPERTY, + _("Identity"), NM_SETTING (s_8021x), NM_SETTING_802_1X_IDENTITY, - NULL, - NULL, - FALSE); + NULL); g_ptr_array_add (secrets, secret); - secret = nm_secret_agent_simple_secret_new (_("Private key password"), + secret = nm_secret_agent_simple_secret_new (NM_SECRET_AGENT_SECRET_TYPE_SECRET, + _("Private key password"), NM_SETTING (s_8021x), NM_SETTING_802_1X_PRIVATE_KEY_PASSWORD, - NULL, - NULL, - TRUE); + NULL); g_ptr_array_add (secrets, secret); return TRUE; } @@ -272,12 +275,11 @@ add_wireless_secrets (NMSecretAgentSimpleRequest *request, return FALSE; if (!strcmp (key_mgmt, "wpa-none") || !strcmp (key_mgmt, "wpa-psk")) { - secret = nm_secret_agent_simple_secret_new (_("Password"), + secret = nm_secret_agent_simple_secret_new (NM_SECRET_AGENT_SECRET_TYPE_SECRET, + _("Password"), NM_SETTING (s_wsec), NM_SETTING_WIRELESS_SECURITY_PSK, - NULL, - NULL, - TRUE); + NULL); g_ptr_array_add (secrets, secret); return TRUE; } @@ -288,12 +290,11 @@ add_wireless_secrets (NMSecretAgentSimpleRequest *request, index = nm_setting_wireless_security_get_wep_tx_keyidx (s_wsec); key = g_strdup_printf ("wep-key%d", index); - secret = nm_secret_agent_simple_secret_new (_("Key"), + secret = nm_secret_agent_simple_secret_new (NM_SECRET_AGENT_SECRET_TYPE_SECRET, + _("Key"), NM_SETTING (s_wsec), key, - NULL, - NULL, - TRUE); + NULL); g_free (key); g_ptr_array_add (secrets, secret); @@ -302,12 +303,11 @@ add_wireless_secrets (NMSecretAgentSimpleRequest *request, if (!strcmp (key_mgmt, "iee8021x")) { if (!g_strcmp0 (nm_setting_wireless_security_get_auth_alg (s_wsec), "leap")) { - secret = nm_secret_agent_simple_secret_new (_("Password"), + secret = nm_secret_agent_simple_secret_new (NM_SECRET_AGENT_SECRET_TYPE_SECRET, + _("Password"), NM_SETTING (s_wsec), NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD, - NULL, - NULL, - TRUE); + NULL); g_ptr_array_add (secrets, secret); return TRUE; } else @@ -327,26 +327,23 @@ add_pppoe_secrets (NMSecretAgentSimpleRequest *request, NMSettingPppoe *s_pppoe = nm_connection_get_setting_pppoe (request->connection); NMSecretAgentSimpleSecret *secret; - secret = nm_secret_agent_simple_secret_new (_("Username"), + secret = nm_secret_agent_simple_secret_new (NM_SECRET_AGENT_SECRET_TYPE_PROPERTY, + _("Username"), NM_SETTING (s_pppoe), NM_SETTING_PPPOE_USERNAME, - NULL, - NULL, - FALSE); + NULL); g_ptr_array_add (secrets, secret); - secret = nm_secret_agent_simple_secret_new (_("Service"), + secret = nm_secret_agent_simple_secret_new (NM_SECRET_AGENT_SECRET_TYPE_PROPERTY, + _("Service"), NM_SETTING (s_pppoe), NM_SETTING_PPPOE_SERVICE, - NULL, - NULL, - FALSE); + NULL); g_ptr_array_add (secrets, secret); - secret = nm_secret_agent_simple_secret_new (_("Password"), + secret = nm_secret_agent_simple_secret_new (NM_SECRET_AGENT_SECRET_TYPE_SECRET, + _("Password"), NM_SETTING (s_pppoe), NM_SETTING_PPPOE_PASSWORD, - NULL, - NULL, - TRUE); + NULL); g_ptr_array_add (secrets, secret); return TRUE; } @@ -371,23 +368,27 @@ add_vpn_secret_helper (GPtrArray *secrets, NMSettingVpn *s_vpn, const char *name NMSettingSecretFlags flags; int i; - /* Check for duplicates */ - for (i = 0; i < secrets->len; i++) { - secret = secrets->pdata[i]; - - if (g_strcmp0 (secret->vpn_property, name) == 0) - return; - } - flags = get_vpn_secret_flags (s_vpn, name); if ( flags & NM_SETTING_SECRET_FLAG_AGENT_OWNED || flags & NM_SETTING_SECRET_FLAG_NOT_SAVED) { - secret = nm_secret_agent_simple_secret_new (ui_name, + secret = nm_secret_agent_simple_secret_new (NM_SECRET_AGENT_SECRET_TYPE_VPN_SECRET, + ui_name, NM_SETTING (s_vpn), - NM_SETTING_VPN_SECRETS, name, - nm_setting_vpn_get_service_type (s_vpn), - TRUE); + nm_setting_vpn_get_service_type (s_vpn)); + + /* Check for duplicates */ + for (i = 0; i < secrets->len; i++) { + NMSecretAgentSimpleSecret *s = secrets->pdata[i]; + + if ( s->secret_type == secret->secret_type + && nm_streq0 (s->vpn_type, secret->vpn_type) + && nm_streq0 (s->entry_id, secret->entry_id)) { + nm_secret_agent_simple_secret_free (secret); + return; + } + } + g_ptr_array_add (secrets, secret); } } @@ -469,10 +470,6 @@ request_secrets_from_ui (NMSecretAgentSimpleRequest *request) ok = add_wireless_secrets (request, secrets); } else if (nm_connection_is_type (request->connection, NM_SETTING_WIRED_SETTING_NAME)) { - NMSettingConnection *s_con; - - s_con = nm_connection_get_setting_connection (request->connection); - title = _("Wired 802.1X authentication"); msg = g_strdup_printf (_("Secrets are required to access the wired network '%s'"), nm_connection_get_id (request->connection)); @@ -491,24 +488,22 @@ request_secrets_from_ui (NMSecretAgentSimpleRequest *request) title = _("PIN code required"); msg = g_strdup (_("PIN code is needed for the mobile broadband device")); - secret = nm_secret_agent_simple_secret_new (_("PIN"), + secret = nm_secret_agent_simple_secret_new (NM_SECRET_AGENT_SECRET_TYPE_PROPERTY, + _("PIN"), NM_SETTING (s_gsm), NM_SETTING_GSM_PIN, - NULL, - NULL, - FALSE); + NULL); g_ptr_array_add (secrets, secret); } else { title = _("Mobile broadband network password"); msg = g_strdup_printf (_("A password is required to connect to '%s'."), nm_connection_get_id (request->connection)); - secret = nm_secret_agent_simple_secret_new (_("Password"), + secret = nm_secret_agent_simple_secret_new (NM_SECRET_AGENT_SECRET_TYPE_SECRET, + _("Password"), NM_SETTING (s_gsm), NM_SETTING_GSM_PASSWORD, - NULL, - NULL, - TRUE); + NULL); g_ptr_array_add (secrets, secret); } } else if (nm_connection_is_type (request->connection, NM_SETTING_MACSEC_SETTING_NAME)) { @@ -519,12 +514,11 @@ request_secrets_from_ui (NMSecretAgentSimpleRequest *request) if (nm_setting_macsec_get_mode (s_macsec) == NM_SETTING_MACSEC_MODE_PSK) { title = _("MACsec PSK authentication"); - secret = nm_secret_agent_simple_secret_new (_("MKA CAK"), + secret = nm_secret_agent_simple_secret_new (NM_SECRET_AGENT_SECRET_TYPE_SECRET, + _("MKA CAK"), NM_SETTING (s_macsec), NM_SETTING_MACSEC_MKA_CAK, - NULL, - NULL, - TRUE); + NULL); g_ptr_array_add (secrets, secret); } else { title = _("MACsec EAP authentication"); @@ -537,12 +531,11 @@ request_secrets_from_ui (NMSecretAgentSimpleRequest *request) msg = g_strdup_printf (_("A password is required to connect to '%s'."), nm_connection_get_id (request->connection)); - secret = nm_secret_agent_simple_secret_new (_("Password"), + secret = nm_secret_agent_simple_secret_new (NM_SECRET_AGENT_SECRET_TYPE_SECRET, + _("Password"), NM_SETTING (s_cdma), NM_SETTING_CDMA_PASSWORD, - NULL, - NULL, - TRUE); + NULL); g_ptr_array_add (secrets, secret); } else if (nm_connection_is_type (request->connection, NM_SETTING_BLUETOOTH_SETTING_NAME)) { NMSetting *setting = NULL; @@ -560,20 +553,15 @@ request_secrets_from_ui (NMSecretAgentSimpleRequest *request) msg = g_strdup_printf (_("A password is required to connect to '%s'."), nm_connection_get_id (request->connection)); - secret = nm_secret_agent_simple_secret_new (_("Password"), + secret = nm_secret_agent_simple_secret_new (NM_SECRET_AGENT_SECRET_TYPE_SECRET, + _("Password"), setting, "password", - NULL, - NULL, - TRUE); + NULL); g_ptr_array_add (secrets, secret); } else ok = FALSE; } else if (nm_connection_is_type (request->connection, NM_SETTING_VPN_SETTING_NAME)) { - NMSettingConnection *s_con; - - s_con = nm_connection_get_setting_connection (request->connection); - title = _("VPN password required"); msg = NULL; @@ -615,8 +603,6 @@ nm_secret_agent_simple_get_secrets (NMSecretAgentOld *agent, NMSecretAgentSimple *self = NM_SECRET_AGENT_SIMPLE (agent); NMSecretAgentSimplePrivate *priv = NM_SECRET_AGENT_SIMPLE_GET_PRIVATE (self); NMSecretAgentSimpleRequest *request; - NMSettingConnection *s_con; - const char *connection_type; char *request_id; GError *error; @@ -632,9 +618,6 @@ nm_secret_agent_simple_get_secrets (NMSecretAgentOld *agent, return; } - s_con = nm_connection_get_setting_connection (connection); - connection_type = nm_setting_connection_get_connection_type (s_con); - if (!(flags & NM_SECRET_AGENT_GET_SECRETS_FLAG_ALLOW_INTERACTION)) { /* We don't do stored passwords */ error = g_error_new (NM_SECRET_AGENT_ERROR, NM_SECRET_AGENT_ERROR_NO_SECRETS, @@ -692,9 +675,7 @@ nm_secret_agent_simple_response (NMSecretAgentSimple *self, GHashTable *settings; GHashTableIter iter; const char *name; - const char *vpn_secrets_base_name = NULL; - - g_variant_builder_init (&vpn_secrets_builder, G_VARIANT_TYPE ("a{ss}")); + gboolean has_vpn = FALSE; settings = g_hash_table_new (nm_str_hash, g_str_equal); for (i = 0; i < secrets->len; i++) { @@ -707,22 +688,27 @@ nm_secret_agent_simple_response (NMSecretAgentSimple *self, setting_builder); } - if (secret->base.vpn_property) { - /* VPN secrets need slightly different treatment. - * "secrets" property is actually a hash table of secrets. */ - vpn_secrets_base_name = secret->property; - g_variant_builder_add (&vpn_secrets_builder, "{ss}", - secret->base.vpn_property, secret->base.value); - } else { + switch (secret->base.secret_type) { + case NM_SECRET_AGENT_SECRET_TYPE_PROPERTY: + case NM_SECRET_AGENT_SECRET_TYPE_SECRET: g_variant_builder_add (setting_builder, "{sv}", secret->property, g_variant_new_string (secret->base.value)); + break; + case NM_SECRET_AGENT_SECRET_TYPE_VPN_SECRET: + if (!has_vpn) { + g_variant_builder_init (&vpn_secrets_builder, G_VARIANT_TYPE ("a{ss}")); + has_vpn = TRUE; + } + g_variant_builder_add (&vpn_secrets_builder, "{ss}", + secret->property, secret->base.value); + break; } } - if (vpn_secrets_base_name) { + if (has_vpn) { g_variant_builder_add (setting_builder, "{sv}", - vpn_secrets_base_name, + "secrets", g_variant_builder_end (&vpn_secrets_builder)); } diff --git a/clients/common/nm-secret-agent-simple.h b/clients/common/nm-secret-agent-simple.h index 2989723d..505987df 100644 --- a/clients/common/nm-secret-agent-simple.h +++ b/clients/common/nm-secret-agent-simple.h @@ -19,7 +19,6 @@ #ifndef __NM_SECRET_AGENT_SIMPLE_H__ #define __NM_SECRET_AGENT_SIMPLE_H__ -#include "NetworkManager.h" #include "nm-secret-agent-old.h" #define NM_TYPE_SECRET_AGENT_SIMPLE (nm_secret_agent_simple_get_type ()) @@ -42,13 +41,25 @@ typedef struct { } NMSecretAgentSimpleClass; +typedef enum { + NM_SECRET_AGENT_SECRET_TYPE_PROPERTY, + NM_SECRET_AGENT_SECRET_TYPE_SECRET, + NM_SECRET_AGENT_SECRET_TYPE_VPN_SECRET, +} NMSecretAgentSecretType; + typedef struct { - char *name, *prop_name, *value; - char *vpn_property; - char *vpn_type; - gboolean password; + const NMSecretAgentSecretType secret_type; + const char *pretty_name; + const char *entry_id; + char *value; + const char *vpn_type; + gboolean is_secret; } NMSecretAgentSimpleSecret; +#define NM_SECRET_AGENT_ENTRY_ID_PREFX_VPN_SECRET "vpn.secret." + +#define NM_SECRET_AGENT_VPN_TYPE_OPENCONNECT NM_DBUS_INTERFACE".openconnect" + GType nm_secret_agent_simple_get_type (void); NMSecretAgentOld *nm_secret_agent_simple_new (const char *name); diff --git a/clients/common/nm-vpn-helpers.c b/clients/common/nm-vpn-helpers.c index 15611c45..c3237f12 100644 --- a/clients/common/nm-vpn-helpers.c +++ b/clients/common/nm-vpn-helpers.c @@ -238,7 +238,7 @@ nm_vpn_openconnect_authenticate_helper (const char *host, * HOST='1.2.3.4' * FINGERPRINT='sha1:32bac90cf09a722e10ecc1942c67fe2ac8c21e2e' */ - strv = g_strsplit_set (output ? output : "", "\r\n", 0); + strv = g_strsplit_set (output ?: "", "\r\n", 0); for (iter = strv; iter && *iter; iter++) { _extract_variable_value (*iter, "COOKIE=", cookie); _extract_variable_value (*iter, "HOST=", gateway); diff --git a/clients/common/nm-vpn-helpers.h b/clients/common/nm-vpn-helpers.h index 9e3b8539..4c15faa1 100644 --- a/clients/common/nm-vpn-helpers.h +++ b/clients/common/nm-vpn-helpers.h @@ -19,8 +19,6 @@ #ifndef __NM_VPN_HELPERS_H__ #define __NM_VPN_HELPERS_H__ -#include "NetworkManager.h" - typedef struct { const char *name; const char *ui_name; diff --git a/clients/common/settings-docs.c b/clients/common/settings-docs.h index bf5753c5..06f96a4e 100644 --- a/clients/common/settings-docs.c +++ b/clients/common/settings-docs.h @@ -9,7 +9,7 @@ #define DESCRIBE_DOC_NM_SETTING_WIRELESS_CHANNEL N_("Wireless channel to use for the Wi-Fi connection. The device will only join (or create for Ad-Hoc networks) a Wi-Fi network on the specified channel. Because channel numbers overlap between bands, this property also requires the \"band\" property to be set.") #define DESCRIBE_DOC_NM_SETTING_WIRELESS_CLONED_MAC_ADDRESS N_("If specified, request that the device use this MAC address instead. This is known as MAC cloning or spoofing. Beside explicitly specifying a MAC address, the special values \"preserve\", \"permanent\", \"random\" and \"stable\" are supported. \"preserve\" means not to touch the MAC address on activation. \"permanent\" means to use the permanent hardware address of the device. \"random\" creates a random MAC address on each connect. \"stable\" creates a hashed MAC address based on connection.stable-id and a machine dependent key. If unspecified, the value can be overwritten via global defaults, see manual of NetworkManager.conf. If still unspecified, it defaults to \"preserve\" (older versions of NetworkManager may use a different default value). On D-Bus, this field is expressed as \"assigned-mac-address\" or the deprecated \"cloned-mac-address\".") #define DESCRIBE_DOC_NM_SETTING_WIRELESS_GENERATE_MAC_ADDRESS_MASK N_("With \"cloned-mac-address\" setting \"random\" or \"stable\", by default all bits of the MAC address are scrambled and a locally-administered, unicast MAC address is created. This property allows to specify that certain bits are fixed. Note that the least significant bit of the first MAC address will always be unset to create a unicast MAC address. If the property is NULL, it is eligible to be overwritten by a default connection setting. If the value is still NULL or an empty string, the default is to create a locally-administered, unicast MAC address. If the value contains one MAC address, this address is used as mask. The set bits of the mask are to be filled with the current MAC address of the device, while the unset bits are subject to randomization. Setting \"FE:FF:FF:00:00:00\" means to preserve the OUI of the current MAC address and only randomize the lower 3 bytes using the \"random\" or \"stable\" algorithm. If the value contains one additional MAC address after the mask, this address is used instead of the current MAC address to fill the bits that shall not be randomized. For example, a value of \"FE:FF:FF:00:00:00 68:F7:28:00:00:00\" will set the OUI of the MAC address to 68:F7:28, while the lower bits are randomized. A value of \"02:00:00:00:00:00 00:00:00:00:00:00\" will create a fully scrambled globally-administered, burned-in MAC address. If the value contains more than one additional MAC addresses, one of them is chosen randomly. For example, \"02:00:00:00:00:00 00:00:00:00:00:00 02:00:00:00:00:00\" will create a fully scrambled MAC address, randomly locally or globally administered.") -#define DESCRIBE_DOC_NM_SETTING_WIRELESS_HIDDEN N_("If TRUE, indicates this network is a non-broadcasting network that hides its SSID. In this case various workarounds may take place, such as probe-scanning the SSID for more reliable network discovery. However, these workarounds expose inherent insecurities with hidden SSID networks, and thus hidden SSID networks should be used with caution.") +#define DESCRIBE_DOC_NM_SETTING_WIRELESS_HIDDEN N_("If TRUE, indicates this network is a non-broadcasting network that hides its SSID. In this case various workarounds may take place, such as probe-scanning the SSID for more reliable network discovery. However, these workarounds expose inherent insecurities with hidden SSID networks, and thus hidden SSID networks should be used with caution. Note that marking the network as hidden may be a privacy issue for you, as the explicit probe-scans may be distinctly recognizable on the air.") #define DESCRIBE_DOC_NM_SETTING_WIRELESS_MAC_ADDRESS N_("If specified, this connection will only apply to the Wi-Fi device whose permanent MAC address matches. This property does not change the MAC address of the device (i.e. MAC spoofing).") #define DESCRIBE_DOC_NM_SETTING_WIRELESS_MAC_ADDRESS_BLACKLIST N_("A list of permanent MAC addresses of Wi-Fi devices to which this connection should never apply. Each MAC address should be given in the standard hex-digits-and-colons notation (eg \"00:11:22:33:44:55\").") #define DESCRIBE_DOC_NM_SETTING_WIRELESS_MAC_ADDRESS_RANDOMIZATION N_("One of NM_SETTING_MAC_RANDOMIZATION_DEFAULT (0) (never randomize unless the user has set a global default to randomize and the supplicant supports randomization), NM_SETTING_MAC_RANDOMIZATION_NEVER (1) (never randomize the MAC address), or NM_SETTING_MAC_RANDOMIZATION_ALWAYS (2) (always randomize the MAC address). This property is deprecated for 'cloned-mac-address'. Deprecated: 1") @@ -22,6 +22,7 @@ #define DESCRIBE_DOC_NM_SETTING_WIRELESS_SSID N_("SSID of the Wi-Fi network. Must be specified.") #define DESCRIBE_DOC_NM_SETTING_WIRELESS_TX_POWER N_("If non-zero, directs the device to use the specified transmit power. Units are dBm. This property is highly driver dependent and not all devices support setting a static transmit power.") #define DESCRIBE_DOC_NM_SETTING_WIRELESS_SECURITY_AUTH_ALG N_("When WEP is used (ie, key-mgmt = \"none\" or \"ieee8021x\") indicate the 802.11 authentication algorithm required by the AP here. One of \"open\" for Open System, \"shared\" for Shared Key, or \"leap\" for Cisco LEAP. When using Cisco LEAP (ie, key-mgmt = \"ieee8021x\" and auth-alg = \"leap\") the \"leap-username\" and \"leap-password\" properties must be specified.") +#define DESCRIBE_DOC_NM_SETTING_WIRELESS_SECURITY_FILS N_("Indicates whether Fast Initial Link Setup (802.11ai) must be enabled for the connection. One of NM_SETTING_WIRELESS_SECURITY_FILS_DEFAULT (0) (use global default value), NM_SETTING_WIRELESS_SECURITY_FILS_DISABLE (1) (disable FILS), NM_SETTING_WIRELESS_SECURITY_FILS_OPTIONAL (2) (enable FILS if the supplicant and the access point support it) or NM_SETTING_WIRELESS_SECURITY_FILS_REQUIRED (3) (enable FILS and fail if not supported). When set to NM_SETTING_WIRELESS_SECURITY_FILS_DEFAULT (0) and no global default is set, FILS will be optionally enabled.") #define DESCRIBE_DOC_NM_SETTING_WIRELESS_SECURITY_GROUP N_("A list of group/broadcast encryption algorithms which prevents connections to Wi-Fi networks that do not utilize one of the algorithms in the list. For maximum compatibility leave this property empty. Each list element may be one of \"wep40\", \"wep104\", \"tkip\", or \"ccmp\".") #define DESCRIBE_DOC_NM_SETTING_WIRELESS_SECURITY_KEY_MGMT N_("Key management used for the connection. One of \"none\" (WEP), \"ieee8021x\" (Dynamic WEP), \"wpa-none\" (Ad-Hoc WPA-PSK), \"wpa-psk\" (infrastructure WPA-PSK), or \"wpa-eap\" (WPA-Enterprise). This property must be set for any Wi-Fi connection that uses security.") #define DESCRIBE_DOC_NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD N_("The login password for legacy LEAP connections (ie, key-mgmt = \"ieee8021x\" and auth-alg = \"leap\").") @@ -118,7 +119,7 @@ #define DESCRIBE_DOC_NM_SETTING_BRIDGE_FORWARD_DELAY N_("The Spanning Tree Protocol (STP) forwarding delay, in seconds.") #define DESCRIBE_DOC_NM_SETTING_BRIDGE_GROUP_FORWARD_MASK N_("A mask of group addresses to forward. Usually, group addresses in the range from 01:80:C2:00:00:00 to 01:80:C2:00:00:0F are not forwarded according to standards. This property is a mask of 16 bits, each corresponding to a group address in that range that must be forwarded. The mask can't have bits 0, 1 or 2 set because they are used for STP, MAC pause frames and LACP.") #define DESCRIBE_DOC_NM_SETTING_BRIDGE_HELLO_TIME N_("The Spanning Tree Protocol (STP) hello time, in seconds.") -#define DESCRIBE_DOC_NM_SETTING_BRIDGE_MAC_ADDRESS N_("If specified, the MAC address of bridge. When creating a new bridge, this MAC address will be set. If this field is left unspecified, the \"ethernet.cloned-mac-address\" is referred instead to generate the initial MAC address. Note that setting \"ethernet.cloned-mac-address\" anyway overwrites the MAC address of the bridge later while activating the bridge. Hence, this property is deprecated.") +#define DESCRIBE_DOC_NM_SETTING_BRIDGE_MAC_ADDRESS N_("If specified, the MAC address of bridge. When creating a new bridge, this MAC address will be set. If this field is left unspecified, the \"ethernet.cloned-mac-address\" is referred instead to generate the initial MAC address. Note that setting \"ethernet.cloned-mac-address\" anyway overwrites the MAC address of the bridge later while activating the bridge. Hence, this property is deprecated. Deprecated: 1") #define DESCRIBE_DOC_NM_SETTING_BRIDGE_MAX_AGE N_("The Spanning Tree Protocol (STP) maximum message age, in seconds.") #define DESCRIBE_DOC_NM_SETTING_BRIDGE_MULTICAST_SNOOPING N_("Controls whether IGMP snooping is enabled for this bridge. Note that if snooping was automatically disabled due to hash collisions, the system may refuse to enable the feature until the collisions are resolved.") #define DESCRIBE_DOC_NM_SETTING_BRIDGE_NAME N_("The setting's name, which uniquely identifies the setting within the connection. Each setting type has a name unique to that type, for example \"ppp\" or \"wireless\" or \"wired\".") @@ -135,22 +136,23 @@ #define DESCRIBE_DOC_NM_SETTING_CDMA_PASSWORD_FLAGS N_("Flags indicating how to handle the \"password\" property.") #define DESCRIBE_DOC_NM_SETTING_CDMA_USERNAME N_("The username used to authenticate with the network, if required. Many providers do not require a username, or accept any username. But if a username is required, it is specified here.") #define DESCRIBE_DOC_NM_SETTING_CONNECTION_AUTH_RETRIES N_("The number of retries for the authentication. Zero means to try indefinitely; -1 means to use a global default. If the global default is not set, the authentication retries for 3 times before failing the connection. Currently this only applies to 802-1x authentication.") -#define DESCRIBE_DOC_NM_SETTING_CONNECTION_AUTOCONNECT N_("Whether or not the connection should be automatically connected by NetworkManager when the resources for the connection are available. TRUE to automatically activate the connection, FALSE to require manual intervention to activate the connection.") +#define DESCRIBE_DOC_NM_SETTING_CONNECTION_AUTOCONNECT N_("Whether or not the connection should be automatically connected by NetworkManager when the resources for the connection are available. TRUE to automatically activate the connection, FALSE to require manual intervention to activate the connection. Note that autoconnect is not implemented for VPN profiles. See \"secondaries\" as an alternative to automatically connect VPN profiles.") #define DESCRIBE_DOC_NM_SETTING_CONNECTION_AUTOCONNECT_PRIORITY N_("The autoconnect priority. If the connection is set to autoconnect, connections with higher priority will be preferred. Defaults to 0. The higher number means higher priority.") #define DESCRIBE_DOC_NM_SETTING_CONNECTION_AUTOCONNECT_RETRIES N_("The number of times a connection should be tried when autoactivating before giving up. Zero means forever, -1 means the global default (4 times if not overridden). Setting this to 1 means to try activation only once before blocking autoconnect. Note that after a timeout, NetworkManager will try to autoconnect again.") -#define DESCRIBE_DOC_NM_SETTING_CONNECTION_AUTOCONNECT_SLAVES N_("Whether or not slaves of this connection should be automatically brought up when NetworkManager activates this connection. This only has a real effect for master connections. The permitted values are: 0: leave slave connections untouched, 1: activate all the slave connections with this connection, -1: default. If -1 (default) is set, global connection.autoconnect-slaves is read to determine the real value. If it is default as well, this fallbacks to 0.") +#define DESCRIBE_DOC_NM_SETTING_CONNECTION_AUTOCONNECT_SLAVES N_("Whether or not slaves of this connection should be automatically brought up when NetworkManager activates this connection. This only has a real effect for master connections. The properties \"autoconnect\", \"autoconnect-priority\" and \"autoconnect-retries\" are unrelated to this setting. The permitted values are: 0: leave slave connections untouched, 1: activate all the slave connections with this connection, -1: default. If -1 (default) is set, global connection.autoconnect-slaves is read to determine the real value. If it is default as well, this fallbacks to 0.") #define DESCRIBE_DOC_NM_SETTING_CONNECTION_GATEWAY_PING_TIMEOUT N_("If greater than zero, delay success of IP addressing until either the timeout is reached, or an IP gateway replies to a ping.") #define DESCRIBE_DOC_NM_SETTING_CONNECTION_ID N_("A human readable unique identifier for the connection, like \"Work Wi-Fi\" or \"T-Mobile 3G\".") #define DESCRIBE_DOC_NM_SETTING_CONNECTION_INTERFACE_NAME N_("The name of the network interface this connection is bound to. If not set, then the connection can be attached to any interface of the appropriate type (subject to restrictions imposed by other settings). For software devices this specifies the name of the created device. For connection types where interface names cannot easily be made persistent (e.g. mobile broadband or USB Ethernet), this property should not be used. Setting this property restricts the interfaces a connection can be used with, and if interface names change or are reordered the connection may be applied to the wrong interface.") #define DESCRIBE_DOC_NM_SETTING_CONNECTION_LLDP N_("Whether LLDP is enabled for the connection.") #define DESCRIBE_DOC_NM_SETTING_CONNECTION_MASTER N_("Interface name of the master device or UUID of the master connection.") +#define DESCRIBE_DOC_NM_SETTING_CONNECTION_MDNS N_("Whether mDNS is enabled for the connection. The permitted values are: yes: register hostname and resolving for the connection, no: disable mDNS for the interface, resolve: do not register hostname but allow resolving of mDNS host names. When updating this property on a currently activated connection, the change takes effect immediately. This feature requires a plugin which supports mDNS. One such plugin is dns-systemd-resolved.") #define DESCRIBE_DOC_NM_SETTING_CONNECTION_METERED N_("Whether the connection is metered. When updating this property on a currently activated connection, the change takes effect immediately.") #define DESCRIBE_DOC_NM_SETTING_CONNECTION_NAME N_("The setting's name, which uniquely identifies the setting within the connection. Each setting type has a name unique to that type, for example \"ppp\" or \"wireless\" or \"wired\".") #define DESCRIBE_DOC_NM_SETTING_CONNECTION_PERMISSIONS N_("An array of strings defining what access a given user has to this connection. If this is NULL or empty, all users are allowed to access this connection; otherwise users are allowed if and only if they are in this list. When this is not empty, the connection can be active only when one of the specified users is logged into an active session. Each entry is of the form \"[type]:[id]:[reserved]\"; for example, \"user:dcbw:blah\". At this time only the \"user\" [type] is allowed. Any other values are ignored and reserved for future use. [id] is the username that this permission refers to, which may not contain the \":\" character. Any [reserved] information present must be ignored and is reserved for future use. All of [type], [id], and [reserved] must be valid UTF-8.") #define DESCRIBE_DOC_NM_SETTING_CONNECTION_READ_ONLY N_("FALSE if the connection can be modified using the provided settings service's D-Bus interface with the right privileges, or TRUE if the connection is read-only and cannot be modified.") #define DESCRIBE_DOC_NM_SETTING_CONNECTION_SECONDARIES N_("List of connection UUIDs that should be activated when the base connection itself is activated. Currently only VPN connections are supported.") #define DESCRIBE_DOC_NM_SETTING_CONNECTION_SLAVE_TYPE N_("Setting name of the device type of this slave's master connection (eg, \"bond\"), or NULL if this connection is not a slave.") -#define DESCRIBE_DOC_NM_SETTING_CONNECTION_STABLE_ID N_("Token to generate stable IDs for the connection. The stable-id is used for generating IPv6 stable private addresses with ipv6.addr-gen-mode=stable-privacy. It is also used to seed the generated cloned MAC address for ethernet.cloned-mac-address=stable and wifi.cloned-mac-address=stable. Note that also the interface name of the activating connection and a per-host secret key is included into the address generation so that the same stable-id on different hosts/devices yields different addresses. If the value is unset, an ID unique for the connection is used. Specifying a stable-id allows multiple connections to generate the same addresses. Another use is to generate IDs at runtime via dynamic substitutions. The '$' character is treated special to perform dynamic substitutions at runtime. Currently supported are \"${CONNECTION}\", \"${BOOT}\", \"${RANDOM}\". These effectively create unique IDs per-connection, per-boot, or every time. Any unrecognized patterns following '$' are treated verbatim, however are reserved for future use. You are thus advised to avoid '$' or escape it as \"$$\". For example, set it to \"${CONNECTION}/${BOOT}\" to create a unique id for this connection that changes with every reboot. Note that two connections only use the same effective id if their stable-id is also identical before performing dynamic substitutions.") +#define DESCRIBE_DOC_NM_SETTING_CONNECTION_STABLE_ID N_("This represents the identity of the connection used for various purposes. It allows to configure multiple profiles to share the identity. Also, the stable-id can contain placeholders that are substituted dynamically and deterministically depending on the context. The stable-id is used for generating IPv6 stable private addresses with ipv6.addr-gen-mode=stable-privacy. It is also used to seed the generated cloned MAC address for ethernet.cloned-mac-address=stable and wifi.cloned-mac-address=stable. It is also used as DHCP client identifier with ipv4.dhcp-client-id=stable. Note that depending on the context where it is used, other parameters are also seeded into the generation algorithm. For example, a per-host key is commonly also included, so that different systems end up generating different IDs. Or with ipv6.addr-gen-mode=stable-privacy, also the device's name is included, so that different interfaces yield different addresses. The '$' character is treated special to perform dynamic substitutions at runtime. Currently supported are \"${CONNECTION}\", \"${DEVICE}\", \"${BOOT}\", \"${RANDOM}\". These effectively create unique IDs per-connection, per-device, per-boot, or every time. Note that \"${DEVICE}\" corresponds the the interface name of the device. Any unrecognized patterns following '$' are treated verbatim, however are reserved for future use. You are thus advised to avoid '$' or escape it as \"$$\". For example, set it to \"${CONNECTION}-${BOOT}-${DEVICE}\" to create a unique id for this connection that changes with every reboot and differs depending on the interface where the profile activates. If the value is unset, a global connection default is consulted. If the value is still unset, the default is similar to \"${CONNECTION}\" and uses a unique, fixed ID for the connection.") #define DESCRIBE_DOC_NM_SETTING_CONNECTION_TIMESTAMP N_("The time, in seconds since the Unix Epoch, that the connection was last _successfully_ fully activated. NetworkManager updates the connection timestamp periodically when the connection is active to ensure that an active connection has the latest timestamp. The property is only meant for reading (changes to this property will not be preserved).") #define DESCRIBE_DOC_NM_SETTING_CONNECTION_TYPE N_("Base type of the connection. For hardware-dependent connections, should contain the setting name of the hardware-type specific setting (ie, \"802-3-ethernet\" or \"802-11-wireless\" or \"bluetooth\", etc), and for non-hardware dependent connections like VPN or otherwise, should contain the setting name of that setting type (ie, \"vpn\" or \"bridge\", etc).") #define DESCRIBE_DOC_NM_SETTING_CONNECTION_UUID N_("A universally unique identifier for the connection, for example generated with libuuid. It should be assigned when the connection is created, and never changed as long as the connection still applies to the same network. For example, it should not be changed when the \"id\" property or NMSettingIP4Config changes, but might need to be re-created when the Wi-Fi SSID, mobile broadband network provider, or \"type\" property changes. The UUID must be in the format \"2815492f-7e56-435e-b2e9-246bd7cdc664\" (ie, contains only hexadecimal characters and \"-\").") @@ -194,6 +196,7 @@ #define DESCRIBE_DOC_NM_SETTING_INFINIBAND_PARENT N_("The interface name of the parent device of this device. Normally NULL, but if the \"p_key\" property is set, then you must specify the base device by setting either this property or \"mac-address\".") #define DESCRIBE_DOC_NM_SETTING_INFINIBAND_TRANSPORT_MODE N_("The IP-over-InfiniBand transport mode. Either \"datagram\" or \"connected\".") #define DESCRIBE_DOC_NM_SETTING_IP_TUNNEL_ENCAPSULATION_LIMIT N_("How many additional levels of encapsulation are permitted to be prepended to packets. This property applies only to IPv6 tunnels.") +#define DESCRIBE_DOC_NM_SETTING_IP_TUNNEL_FLAGS N_("Tunnel flags. Currently the following values are supported: NM_IP_TUNNEL_FLAG_IP6_IGN_ENCAP_LIMIT (0x1), NM_IP_TUNNEL_FLAG_IP6_USE_ORIG_TCLASS (0x2), NM_IP_TUNNEL_FLAG_IP6_USE_ORIG_FLOWLABEL (0x4), NM_IP_TUNNEL_FLAG_IP6_MIP6_DEV (0x8), NM_IP_TUNNEL_FLAG_IP6_RCV_DSCP_COPY (0x10), NM_IP_TUNNEL_FLAG_IP6_USE_ORIG_FWMARK (0x20). They are valid only for IPv6 tunnels.") #define DESCRIBE_DOC_NM_SETTING_IP_TUNNEL_FLOW_LABEL N_("The flow label to assign to tunnel packets. This property applies only to IPv6 tunnels.") #define DESCRIBE_DOC_NM_SETTING_IP_TUNNEL_INPUT_KEY N_("The key used for tunnel input packets; the property is valid only for certain tunnel modes (GRE, IP6GRE). If empty, no key is used.") #define DESCRIBE_DOC_NM_SETTING_IP_TUNNEL_LOCAL N_("The local endpoint of the tunnel; the value can be empty, otherwise it must contain an IPv4 or IPv6 address.") @@ -207,16 +210,16 @@ #define DESCRIBE_DOC_NM_SETTING_IP_TUNNEL_TOS N_("The type of service (IPv4) or traffic class (IPv6) field to be set on tunneled packets.") #define DESCRIBE_DOC_NM_SETTING_IP_TUNNEL_TTL N_("The TTL to assign to tunneled packets. 0 is a special value meaning that packets inherit the TTL value.") #define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_ADDRESSES N_("Array of IP addresses.") -#define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DAD_TIMEOUT N_("Timeout in milliseconds used to check for the presence of duplicate IP addresses on the network. If an address conflict is detected, the activation will fail. A zero value means that no duplicate address detection is performed, -1 means the default value (either configuration ipvx.dad-timeout override or 3 seconds). A value greater than zero is a timeout in milliseconds.") -#define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DHCP_CLIENT_ID N_("A string sent to the DHCP server to identify the local machine which the DHCP server may use to customize the DHCP lease and options. When the property is a hex string ('aa:bb:cc') it is interpreted as a binary client ID, in which case the first byte is assumed to be the 'type' field as per RFC 2132 section 9.14 and the remaining bytes may be an hardware address (e.g. '01:xx:xx:xx:xx:xx:xx' where 1 is the Ethernet ARP type and the rest is a MAC address). If the property is not a hex string it is considered as a non-hardware-address client ID and the 'type' field is set to 0.") +#define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DAD_TIMEOUT N_("Timeout in milliseconds used to check for the presence of duplicate IP addresses on the network. If an address conflict is detected, the activation will fail. A zero value means that no duplicate address detection is performed, -1 means the default value (either configuration ipvx.dad-timeout override or zero). A value greater than zero is a timeout in milliseconds. The property is currently implemented only for IPv4.") +#define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DHCP_CLIENT_ID N_("A string sent to the DHCP server to identify the local machine which the DHCP server may use to customize the DHCP lease and options. When the property is a hex string ('aa:bb:cc') it is interpreted as a binary client ID, in which case the first byte is assumed to be the 'type' field as per RFC 2132 section 9.14 and the remaining bytes may be an hardware address (e.g. '01:xx:xx:xx:xx:xx:xx' where 1 is the Ethernet ARP type and the rest is a MAC address). If the property is not a hex string it is considered as a non-hardware-address client ID and the 'type' field is set to 0. The special values \"mac\" and \"perm-mac\" are supported, which use the current or permanent MAC address of the device to generate a client identifier with type ethernet type (01). Currently, these options only work for ethernet type of links. The special value \"stable\" is supported to generate a type 0 client identifier based on the stable-id (see connection.stable-id) and a per-host key. If unset, a globally configured default is used. If still unset, the client-id from the last lease is reused.") #define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DHCP_FQDN N_("If the \"dhcp-send-hostname\" property is TRUE, then the specified FQDN will be sent to the DHCP server when acquiring a lease. This property and \"dhcp-hostname\" are mutually exclusive and cannot be set at the same time.") #define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DHCP_HOSTNAME N_("If the \"dhcp-send-hostname\" property is TRUE, then the specified name will be sent to the DHCP server when acquiring a lease. This property and \"dhcp-fqdn\" are mutually exclusive and cannot be set at the same time.") #define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DHCP_SEND_HOSTNAME N_("If TRUE, a hostname is sent to the DHCP server when acquiring a lease. Some DHCP servers use this hostname to update DNS databases, essentially providing a static hostname for the computer. If the \"dhcp-hostname\" property is NULL and this property is TRUE, the current persistent hostname of the computer is sent.") #define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DHCP_TIMEOUT N_("A timeout for a DHCP transaction in seconds.") #define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DNS N_("Array of IP addresses of DNS servers.") #define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DNS_OPTIONS N_("Array of DNS options as described in man 5 resolv.conf. NULL means that the options are unset and left at the default. In this case NetworkManager will use default options. This is distinct from an empty list of properties.") -#define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DNS_PRIORITY N_("Intra-connection DNS priority. The relative priority to be used when determining the order of DNS servers in resolv.conf. A lower value means that servers will be on top of the file. Zero selects the default value, which is 50 for VPNs and 100 for other connections. Note that the priority is to order DNS settings for multiple active connections. It does not disambiguate multiple DNS servers within the same connection profile. For that, just specify the DNS servers in the desired order. When multiple devices have configurations with the same priority, the one with an active default route will be preferred. Note that when using dns=dnsmasq the order is meaningless since dnsmasq forwards queries to all known servers at the same time. Negative values have the special effect of excluding other configurations with a greater priority value; so in presence of at least a negative priority, only DNS servers from connections with the lowest priority value will be used.") -#define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DNS_SEARCH N_("Array of DNS search domains.") +#define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DNS_PRIORITY N_("DNS servers priority. The relative priority for DNS servers specified by this setting. A lower value is better (higher priority). Zero selects the default value, which is 50 for VPNs and 100 for other connections. Note that the priority is to order DNS settings for multiple active connections. It does not disambiguate multiple DNS servers within the same connection profile. When using dns=default, servers with higher priority will be on top of resolv.conf. To prioritize a given server over another one within the same connection, just specify them in the desired order. When multiple devices have configurations with the same priority, the one with an active default route will be preferred. Negative values have the special effect of excluding other configurations with a greater priority value; so in presence of at least a negative priority, only DNS servers from connections with the lowest priority value will be used. When using a DNS resolver that supports split-DNS as dns=dnsmasq or dns=systemd-resolved, each connection is used to query domains in its search list. Queries for domains not present in any search list are routed through connections having the '~.' special wildcard domain, which is added automatically to connections with the default route (or can be added manually). When multiple connections specify the same domain, the one with the highest priority (lowest numerical value) wins. If a connection specifies a domain which is subdomain of another domain with a negative DNS priority value, the subdomain is ignored.") +#define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DNS_SEARCH N_("Array of DNS search domains. Domains starting with a tilde ('~') are considered 'routing' domains and are used only to decide the interface over which a query must be forwarded; they are not used to complete unqualified host names.") #define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_GATEWAY N_("The gateway associated with this configuration. This is only meaningful if \"addresses\" is also set.") #define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_IGNORE_AUTO_DNS N_("When \"method\" is set to \"auto\" and this property to TRUE, automatically configured nameservers and search domains are ignored and only nameservers and search domains specified in the \"dns\" and \"dns-search\" properties, if any, are used.") #define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_IGNORE_AUTO_ROUTES N_("When \"method\" is set to \"auto\" and this property to TRUE, automatically configured routes are ignored and only routes specified in the \"routes\" property, if any, are used.") @@ -229,14 +232,14 @@ #define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_ROUTES N_("Array of IP routes.") #define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE N_("Configure method for creating the address for use with RFC4862 IPv6 Stateless Address Autoconfiguration. The permitted values are: NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE_EUI64 (0) or NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE_STABLE_PRIVACY (1). If the property is set to EUI64, the addresses will be generated using the interface tokens derived from hardware address. This makes the host part of the address to stay constant, making it possible to track host's presence when it changes networks. The address changes when the interface hardware is replaced. The value of stable-privacy enables use of cryptographically secure hash of a secret host-specific key along with the connection's stable-id and the network address as specified by RFC7217. This makes it impossible to use the address track host's presence, and makes the address stable when the network interface hardware is replaced. On D-Bus, the absence of an addr-gen-mode setting equals enabling stable-privacy. For keyfile plugin, the absence of the setting on disk means EUI64 so that the property doesn't change on upgrade from older versions. Note that this setting is distinct from the Privacy Extensions as configured by \"ip6-privacy\" property and it does not affect the temporary addresses configured with this option.") #define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_ADDRESSES N_("Array of IP addresses.") -#define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DAD_TIMEOUT N_("Timeout in milliseconds used to check for the presence of duplicate IP addresses on the network. If an address conflict is detected, the activation will fail. A zero value means that no duplicate address detection is performed, -1 means the default value (either configuration ipvx.dad-timeout override or 3 seconds). A value greater than zero is a timeout in milliseconds.") +#define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DAD_TIMEOUT N_("Timeout in milliseconds used to check for the presence of duplicate IP addresses on the network. If an address conflict is detected, the activation will fail. A zero value means that no duplicate address detection is performed, -1 means the default value (either configuration ipvx.dad-timeout override or zero). A value greater than zero is a timeout in milliseconds. The property is currently implemented only for IPv4.") #define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DHCP_HOSTNAME N_("If the \"dhcp-send-hostname\" property is TRUE, then the specified name will be sent to the DHCP server when acquiring a lease. This property and \"dhcp-fqdn\" are mutually exclusive and cannot be set at the same time.") #define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DHCP_SEND_HOSTNAME N_("If TRUE, a hostname is sent to the DHCP server when acquiring a lease. Some DHCP servers use this hostname to update DNS databases, essentially providing a static hostname for the computer. If the \"dhcp-hostname\" property is NULL and this property is TRUE, the current persistent hostname of the computer is sent.") #define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DHCP_TIMEOUT N_("A timeout for a DHCP transaction in seconds.") #define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DNS N_("Array of IP addresses of DNS servers.") #define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DNS_OPTIONS N_("Array of DNS options as described in man 5 resolv.conf. NULL means that the options are unset and left at the default. In this case NetworkManager will use default options. This is distinct from an empty list of properties.") -#define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DNS_PRIORITY N_("Intra-connection DNS priority. The relative priority to be used when determining the order of DNS servers in resolv.conf. A lower value means that servers will be on top of the file. Zero selects the default value, which is 50 for VPNs and 100 for other connections. Note that the priority is to order DNS settings for multiple active connections. It does not disambiguate multiple DNS servers within the same connection profile. For that, just specify the DNS servers in the desired order. When multiple devices have configurations with the same priority, the one with an active default route will be preferred. Note that when using dns=dnsmasq the order is meaningless since dnsmasq forwards queries to all known servers at the same time. Negative values have the special effect of excluding other configurations with a greater priority value; so in presence of at least a negative priority, only DNS servers from connections with the lowest priority value will be used.") -#define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DNS_SEARCH N_("Array of DNS search domains.") +#define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DNS_PRIORITY N_("DNS servers priority. The relative priority for DNS servers specified by this setting. A lower value is better (higher priority). Zero selects the default value, which is 50 for VPNs and 100 for other connections. Note that the priority is to order DNS settings for multiple active connections. It does not disambiguate multiple DNS servers within the same connection profile. When using dns=default, servers with higher priority will be on top of resolv.conf. To prioritize a given server over another one within the same connection, just specify them in the desired order. When multiple devices have configurations with the same priority, the one with an active default route will be preferred. Negative values have the special effect of excluding other configurations with a greater priority value; so in presence of at least a negative priority, only DNS servers from connections with the lowest priority value will be used. When using a DNS resolver that supports split-DNS as dns=dnsmasq or dns=systemd-resolved, each connection is used to query domains in its search list. Queries for domains not present in any search list are routed through connections having the '~.' special wildcard domain, which is added automatically to connections with the default route (or can be added manually). When multiple connections specify the same domain, the one with the highest priority (lowest numerical value) wins. If a connection specifies a domain which is subdomain of another domain with a negative DNS priority value, the subdomain is ignored.") +#define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DNS_SEARCH N_("Array of DNS search domains. Domains starting with a tilde ('~') are considered 'routing' domains and are used only to decide the interface over which a query must be forwarded; they are not used to complete unqualified host names.") #define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_GATEWAY N_("The gateway associated with this configuration. This is only meaningful if \"addresses\" is also set.") #define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_IGNORE_AUTO_DNS N_("When \"method\" is set to \"auto\" and this property to TRUE, automatically configured nameservers and search domains are ignored and only nameservers and search domains specified in the \"dns\" and \"dns-search\" properties, if any, are used.") #define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_IGNORE_AUTO_ROUTES N_("When \"method\" is set to \"auto\" and this property to TRUE, automatically configured routes are ignored and only routes specified in the \"routes\" property, if any, are used.") diff --git a/clients/common/settings-docs.c.in b/clients/common/settings-docs.h.in index bf5753c5..06f96a4e 100644 --- a/clients/common/settings-docs.c.in +++ b/clients/common/settings-docs.h.in @@ -9,7 +9,7 @@ #define DESCRIBE_DOC_NM_SETTING_WIRELESS_CHANNEL N_("Wireless channel to use for the Wi-Fi connection. The device will only join (or create for Ad-Hoc networks) a Wi-Fi network on the specified channel. Because channel numbers overlap between bands, this property also requires the \"band\" property to be set.") #define DESCRIBE_DOC_NM_SETTING_WIRELESS_CLONED_MAC_ADDRESS N_("If specified, request that the device use this MAC address instead. This is known as MAC cloning or spoofing. Beside explicitly specifying a MAC address, the special values \"preserve\", \"permanent\", \"random\" and \"stable\" are supported. \"preserve\" means not to touch the MAC address on activation. \"permanent\" means to use the permanent hardware address of the device. \"random\" creates a random MAC address on each connect. \"stable\" creates a hashed MAC address based on connection.stable-id and a machine dependent key. If unspecified, the value can be overwritten via global defaults, see manual of NetworkManager.conf. If still unspecified, it defaults to \"preserve\" (older versions of NetworkManager may use a different default value). On D-Bus, this field is expressed as \"assigned-mac-address\" or the deprecated \"cloned-mac-address\".") #define DESCRIBE_DOC_NM_SETTING_WIRELESS_GENERATE_MAC_ADDRESS_MASK N_("With \"cloned-mac-address\" setting \"random\" or \"stable\", by default all bits of the MAC address are scrambled and a locally-administered, unicast MAC address is created. This property allows to specify that certain bits are fixed. Note that the least significant bit of the first MAC address will always be unset to create a unicast MAC address. If the property is NULL, it is eligible to be overwritten by a default connection setting. If the value is still NULL or an empty string, the default is to create a locally-administered, unicast MAC address. If the value contains one MAC address, this address is used as mask. The set bits of the mask are to be filled with the current MAC address of the device, while the unset bits are subject to randomization. Setting \"FE:FF:FF:00:00:00\" means to preserve the OUI of the current MAC address and only randomize the lower 3 bytes using the \"random\" or \"stable\" algorithm. If the value contains one additional MAC address after the mask, this address is used instead of the current MAC address to fill the bits that shall not be randomized. For example, a value of \"FE:FF:FF:00:00:00 68:F7:28:00:00:00\" will set the OUI of the MAC address to 68:F7:28, while the lower bits are randomized. A value of \"02:00:00:00:00:00 00:00:00:00:00:00\" will create a fully scrambled globally-administered, burned-in MAC address. If the value contains more than one additional MAC addresses, one of them is chosen randomly. For example, \"02:00:00:00:00:00 00:00:00:00:00:00 02:00:00:00:00:00\" will create a fully scrambled MAC address, randomly locally or globally administered.") -#define DESCRIBE_DOC_NM_SETTING_WIRELESS_HIDDEN N_("If TRUE, indicates this network is a non-broadcasting network that hides its SSID. In this case various workarounds may take place, such as probe-scanning the SSID for more reliable network discovery. However, these workarounds expose inherent insecurities with hidden SSID networks, and thus hidden SSID networks should be used with caution.") +#define DESCRIBE_DOC_NM_SETTING_WIRELESS_HIDDEN N_("If TRUE, indicates this network is a non-broadcasting network that hides its SSID. In this case various workarounds may take place, such as probe-scanning the SSID for more reliable network discovery. However, these workarounds expose inherent insecurities with hidden SSID networks, and thus hidden SSID networks should be used with caution. Note that marking the network as hidden may be a privacy issue for you, as the explicit probe-scans may be distinctly recognizable on the air.") #define DESCRIBE_DOC_NM_SETTING_WIRELESS_MAC_ADDRESS N_("If specified, this connection will only apply to the Wi-Fi device whose permanent MAC address matches. This property does not change the MAC address of the device (i.e. MAC spoofing).") #define DESCRIBE_DOC_NM_SETTING_WIRELESS_MAC_ADDRESS_BLACKLIST N_("A list of permanent MAC addresses of Wi-Fi devices to which this connection should never apply. Each MAC address should be given in the standard hex-digits-and-colons notation (eg \"00:11:22:33:44:55\").") #define DESCRIBE_DOC_NM_SETTING_WIRELESS_MAC_ADDRESS_RANDOMIZATION N_("One of NM_SETTING_MAC_RANDOMIZATION_DEFAULT (0) (never randomize unless the user has set a global default to randomize and the supplicant supports randomization), NM_SETTING_MAC_RANDOMIZATION_NEVER (1) (never randomize the MAC address), or NM_SETTING_MAC_RANDOMIZATION_ALWAYS (2) (always randomize the MAC address). This property is deprecated for 'cloned-mac-address'. Deprecated: 1") @@ -22,6 +22,7 @@ #define DESCRIBE_DOC_NM_SETTING_WIRELESS_SSID N_("SSID of the Wi-Fi network. Must be specified.") #define DESCRIBE_DOC_NM_SETTING_WIRELESS_TX_POWER N_("If non-zero, directs the device to use the specified transmit power. Units are dBm. This property is highly driver dependent and not all devices support setting a static transmit power.") #define DESCRIBE_DOC_NM_SETTING_WIRELESS_SECURITY_AUTH_ALG N_("When WEP is used (ie, key-mgmt = \"none\" or \"ieee8021x\") indicate the 802.11 authentication algorithm required by the AP here. One of \"open\" for Open System, \"shared\" for Shared Key, or \"leap\" for Cisco LEAP. When using Cisco LEAP (ie, key-mgmt = \"ieee8021x\" and auth-alg = \"leap\") the \"leap-username\" and \"leap-password\" properties must be specified.") +#define DESCRIBE_DOC_NM_SETTING_WIRELESS_SECURITY_FILS N_("Indicates whether Fast Initial Link Setup (802.11ai) must be enabled for the connection. One of NM_SETTING_WIRELESS_SECURITY_FILS_DEFAULT (0) (use global default value), NM_SETTING_WIRELESS_SECURITY_FILS_DISABLE (1) (disable FILS), NM_SETTING_WIRELESS_SECURITY_FILS_OPTIONAL (2) (enable FILS if the supplicant and the access point support it) or NM_SETTING_WIRELESS_SECURITY_FILS_REQUIRED (3) (enable FILS and fail if not supported). When set to NM_SETTING_WIRELESS_SECURITY_FILS_DEFAULT (0) and no global default is set, FILS will be optionally enabled.") #define DESCRIBE_DOC_NM_SETTING_WIRELESS_SECURITY_GROUP N_("A list of group/broadcast encryption algorithms which prevents connections to Wi-Fi networks that do not utilize one of the algorithms in the list. For maximum compatibility leave this property empty. Each list element may be one of \"wep40\", \"wep104\", \"tkip\", or \"ccmp\".") #define DESCRIBE_DOC_NM_SETTING_WIRELESS_SECURITY_KEY_MGMT N_("Key management used for the connection. One of \"none\" (WEP), \"ieee8021x\" (Dynamic WEP), \"wpa-none\" (Ad-Hoc WPA-PSK), \"wpa-psk\" (infrastructure WPA-PSK), or \"wpa-eap\" (WPA-Enterprise). This property must be set for any Wi-Fi connection that uses security.") #define DESCRIBE_DOC_NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD N_("The login password for legacy LEAP connections (ie, key-mgmt = \"ieee8021x\" and auth-alg = \"leap\").") @@ -118,7 +119,7 @@ #define DESCRIBE_DOC_NM_SETTING_BRIDGE_FORWARD_DELAY N_("The Spanning Tree Protocol (STP) forwarding delay, in seconds.") #define DESCRIBE_DOC_NM_SETTING_BRIDGE_GROUP_FORWARD_MASK N_("A mask of group addresses to forward. Usually, group addresses in the range from 01:80:C2:00:00:00 to 01:80:C2:00:00:0F are not forwarded according to standards. This property is a mask of 16 bits, each corresponding to a group address in that range that must be forwarded. The mask can't have bits 0, 1 or 2 set because they are used for STP, MAC pause frames and LACP.") #define DESCRIBE_DOC_NM_SETTING_BRIDGE_HELLO_TIME N_("The Spanning Tree Protocol (STP) hello time, in seconds.") -#define DESCRIBE_DOC_NM_SETTING_BRIDGE_MAC_ADDRESS N_("If specified, the MAC address of bridge. When creating a new bridge, this MAC address will be set. If this field is left unspecified, the \"ethernet.cloned-mac-address\" is referred instead to generate the initial MAC address. Note that setting \"ethernet.cloned-mac-address\" anyway overwrites the MAC address of the bridge later while activating the bridge. Hence, this property is deprecated.") +#define DESCRIBE_DOC_NM_SETTING_BRIDGE_MAC_ADDRESS N_("If specified, the MAC address of bridge. When creating a new bridge, this MAC address will be set. If this field is left unspecified, the \"ethernet.cloned-mac-address\" is referred instead to generate the initial MAC address. Note that setting \"ethernet.cloned-mac-address\" anyway overwrites the MAC address of the bridge later while activating the bridge. Hence, this property is deprecated. Deprecated: 1") #define DESCRIBE_DOC_NM_SETTING_BRIDGE_MAX_AGE N_("The Spanning Tree Protocol (STP) maximum message age, in seconds.") #define DESCRIBE_DOC_NM_SETTING_BRIDGE_MULTICAST_SNOOPING N_("Controls whether IGMP snooping is enabled for this bridge. Note that if snooping was automatically disabled due to hash collisions, the system may refuse to enable the feature until the collisions are resolved.") #define DESCRIBE_DOC_NM_SETTING_BRIDGE_NAME N_("The setting's name, which uniquely identifies the setting within the connection. Each setting type has a name unique to that type, for example \"ppp\" or \"wireless\" or \"wired\".") @@ -135,22 +136,23 @@ #define DESCRIBE_DOC_NM_SETTING_CDMA_PASSWORD_FLAGS N_("Flags indicating how to handle the \"password\" property.") #define DESCRIBE_DOC_NM_SETTING_CDMA_USERNAME N_("The username used to authenticate with the network, if required. Many providers do not require a username, or accept any username. But if a username is required, it is specified here.") #define DESCRIBE_DOC_NM_SETTING_CONNECTION_AUTH_RETRIES N_("The number of retries for the authentication. Zero means to try indefinitely; -1 means to use a global default. If the global default is not set, the authentication retries for 3 times before failing the connection. Currently this only applies to 802-1x authentication.") -#define DESCRIBE_DOC_NM_SETTING_CONNECTION_AUTOCONNECT N_("Whether or not the connection should be automatically connected by NetworkManager when the resources for the connection are available. TRUE to automatically activate the connection, FALSE to require manual intervention to activate the connection.") +#define DESCRIBE_DOC_NM_SETTING_CONNECTION_AUTOCONNECT N_("Whether or not the connection should be automatically connected by NetworkManager when the resources for the connection are available. TRUE to automatically activate the connection, FALSE to require manual intervention to activate the connection. Note that autoconnect is not implemented for VPN profiles. See \"secondaries\" as an alternative to automatically connect VPN profiles.") #define DESCRIBE_DOC_NM_SETTING_CONNECTION_AUTOCONNECT_PRIORITY N_("The autoconnect priority. If the connection is set to autoconnect, connections with higher priority will be preferred. Defaults to 0. The higher number means higher priority.") #define DESCRIBE_DOC_NM_SETTING_CONNECTION_AUTOCONNECT_RETRIES N_("The number of times a connection should be tried when autoactivating before giving up. Zero means forever, -1 means the global default (4 times if not overridden). Setting this to 1 means to try activation only once before blocking autoconnect. Note that after a timeout, NetworkManager will try to autoconnect again.") -#define DESCRIBE_DOC_NM_SETTING_CONNECTION_AUTOCONNECT_SLAVES N_("Whether or not slaves of this connection should be automatically brought up when NetworkManager activates this connection. This only has a real effect for master connections. The permitted values are: 0: leave slave connections untouched, 1: activate all the slave connections with this connection, -1: default. If -1 (default) is set, global connection.autoconnect-slaves is read to determine the real value. If it is default as well, this fallbacks to 0.") +#define DESCRIBE_DOC_NM_SETTING_CONNECTION_AUTOCONNECT_SLAVES N_("Whether or not slaves of this connection should be automatically brought up when NetworkManager activates this connection. This only has a real effect for master connections. The properties \"autoconnect\", \"autoconnect-priority\" and \"autoconnect-retries\" are unrelated to this setting. The permitted values are: 0: leave slave connections untouched, 1: activate all the slave connections with this connection, -1: default. If -1 (default) is set, global connection.autoconnect-slaves is read to determine the real value. If it is default as well, this fallbacks to 0.") #define DESCRIBE_DOC_NM_SETTING_CONNECTION_GATEWAY_PING_TIMEOUT N_("If greater than zero, delay success of IP addressing until either the timeout is reached, or an IP gateway replies to a ping.") #define DESCRIBE_DOC_NM_SETTING_CONNECTION_ID N_("A human readable unique identifier for the connection, like \"Work Wi-Fi\" or \"T-Mobile 3G\".") #define DESCRIBE_DOC_NM_SETTING_CONNECTION_INTERFACE_NAME N_("The name of the network interface this connection is bound to. If not set, then the connection can be attached to any interface of the appropriate type (subject to restrictions imposed by other settings). For software devices this specifies the name of the created device. For connection types where interface names cannot easily be made persistent (e.g. mobile broadband or USB Ethernet), this property should not be used. Setting this property restricts the interfaces a connection can be used with, and if interface names change or are reordered the connection may be applied to the wrong interface.") #define DESCRIBE_DOC_NM_SETTING_CONNECTION_LLDP N_("Whether LLDP is enabled for the connection.") #define DESCRIBE_DOC_NM_SETTING_CONNECTION_MASTER N_("Interface name of the master device or UUID of the master connection.") +#define DESCRIBE_DOC_NM_SETTING_CONNECTION_MDNS N_("Whether mDNS is enabled for the connection. The permitted values are: yes: register hostname and resolving for the connection, no: disable mDNS for the interface, resolve: do not register hostname but allow resolving of mDNS host names. When updating this property on a currently activated connection, the change takes effect immediately. This feature requires a plugin which supports mDNS. One such plugin is dns-systemd-resolved.") #define DESCRIBE_DOC_NM_SETTING_CONNECTION_METERED N_("Whether the connection is metered. When updating this property on a currently activated connection, the change takes effect immediately.") #define DESCRIBE_DOC_NM_SETTING_CONNECTION_NAME N_("The setting's name, which uniquely identifies the setting within the connection. Each setting type has a name unique to that type, for example \"ppp\" or \"wireless\" or \"wired\".") #define DESCRIBE_DOC_NM_SETTING_CONNECTION_PERMISSIONS N_("An array of strings defining what access a given user has to this connection. If this is NULL or empty, all users are allowed to access this connection; otherwise users are allowed if and only if they are in this list. When this is not empty, the connection can be active only when one of the specified users is logged into an active session. Each entry is of the form \"[type]:[id]:[reserved]\"; for example, \"user:dcbw:blah\". At this time only the \"user\" [type] is allowed. Any other values are ignored and reserved for future use. [id] is the username that this permission refers to, which may not contain the \":\" character. Any [reserved] information present must be ignored and is reserved for future use. All of [type], [id], and [reserved] must be valid UTF-8.") #define DESCRIBE_DOC_NM_SETTING_CONNECTION_READ_ONLY N_("FALSE if the connection can be modified using the provided settings service's D-Bus interface with the right privileges, or TRUE if the connection is read-only and cannot be modified.") #define DESCRIBE_DOC_NM_SETTING_CONNECTION_SECONDARIES N_("List of connection UUIDs that should be activated when the base connection itself is activated. Currently only VPN connections are supported.") #define DESCRIBE_DOC_NM_SETTING_CONNECTION_SLAVE_TYPE N_("Setting name of the device type of this slave's master connection (eg, \"bond\"), or NULL if this connection is not a slave.") -#define DESCRIBE_DOC_NM_SETTING_CONNECTION_STABLE_ID N_("Token to generate stable IDs for the connection. The stable-id is used for generating IPv6 stable private addresses with ipv6.addr-gen-mode=stable-privacy. It is also used to seed the generated cloned MAC address for ethernet.cloned-mac-address=stable and wifi.cloned-mac-address=stable. Note that also the interface name of the activating connection and a per-host secret key is included into the address generation so that the same stable-id on different hosts/devices yields different addresses. If the value is unset, an ID unique for the connection is used. Specifying a stable-id allows multiple connections to generate the same addresses. Another use is to generate IDs at runtime via dynamic substitutions. The '$' character is treated special to perform dynamic substitutions at runtime. Currently supported are \"${CONNECTION}\", \"${BOOT}\", \"${RANDOM}\". These effectively create unique IDs per-connection, per-boot, or every time. Any unrecognized patterns following '$' are treated verbatim, however are reserved for future use. You are thus advised to avoid '$' or escape it as \"$$\". For example, set it to \"${CONNECTION}/${BOOT}\" to create a unique id for this connection that changes with every reboot. Note that two connections only use the same effective id if their stable-id is also identical before performing dynamic substitutions.") +#define DESCRIBE_DOC_NM_SETTING_CONNECTION_STABLE_ID N_("This represents the identity of the connection used for various purposes. It allows to configure multiple profiles to share the identity. Also, the stable-id can contain placeholders that are substituted dynamically and deterministically depending on the context. The stable-id is used for generating IPv6 stable private addresses with ipv6.addr-gen-mode=stable-privacy. It is also used to seed the generated cloned MAC address for ethernet.cloned-mac-address=stable and wifi.cloned-mac-address=stable. It is also used as DHCP client identifier with ipv4.dhcp-client-id=stable. Note that depending on the context where it is used, other parameters are also seeded into the generation algorithm. For example, a per-host key is commonly also included, so that different systems end up generating different IDs. Or with ipv6.addr-gen-mode=stable-privacy, also the device's name is included, so that different interfaces yield different addresses. The '$' character is treated special to perform dynamic substitutions at runtime. Currently supported are \"${CONNECTION}\", \"${DEVICE}\", \"${BOOT}\", \"${RANDOM}\". These effectively create unique IDs per-connection, per-device, per-boot, or every time. Note that \"${DEVICE}\" corresponds the the interface name of the device. Any unrecognized patterns following '$' are treated verbatim, however are reserved for future use. You are thus advised to avoid '$' or escape it as \"$$\". For example, set it to \"${CONNECTION}-${BOOT}-${DEVICE}\" to create a unique id for this connection that changes with every reboot and differs depending on the interface where the profile activates. If the value is unset, a global connection default is consulted. If the value is still unset, the default is similar to \"${CONNECTION}\" and uses a unique, fixed ID for the connection.") #define DESCRIBE_DOC_NM_SETTING_CONNECTION_TIMESTAMP N_("The time, in seconds since the Unix Epoch, that the connection was last _successfully_ fully activated. NetworkManager updates the connection timestamp periodically when the connection is active to ensure that an active connection has the latest timestamp. The property is only meant for reading (changes to this property will not be preserved).") #define DESCRIBE_DOC_NM_SETTING_CONNECTION_TYPE N_("Base type of the connection. For hardware-dependent connections, should contain the setting name of the hardware-type specific setting (ie, \"802-3-ethernet\" or \"802-11-wireless\" or \"bluetooth\", etc), and for non-hardware dependent connections like VPN or otherwise, should contain the setting name of that setting type (ie, \"vpn\" or \"bridge\", etc).") #define DESCRIBE_DOC_NM_SETTING_CONNECTION_UUID N_("A universally unique identifier for the connection, for example generated with libuuid. It should be assigned when the connection is created, and never changed as long as the connection still applies to the same network. For example, it should not be changed when the \"id\" property or NMSettingIP4Config changes, but might need to be re-created when the Wi-Fi SSID, mobile broadband network provider, or \"type\" property changes. The UUID must be in the format \"2815492f-7e56-435e-b2e9-246bd7cdc664\" (ie, contains only hexadecimal characters and \"-\").") @@ -194,6 +196,7 @@ #define DESCRIBE_DOC_NM_SETTING_INFINIBAND_PARENT N_("The interface name of the parent device of this device. Normally NULL, but if the \"p_key\" property is set, then you must specify the base device by setting either this property or \"mac-address\".") #define DESCRIBE_DOC_NM_SETTING_INFINIBAND_TRANSPORT_MODE N_("The IP-over-InfiniBand transport mode. Either \"datagram\" or \"connected\".") #define DESCRIBE_DOC_NM_SETTING_IP_TUNNEL_ENCAPSULATION_LIMIT N_("How many additional levels of encapsulation are permitted to be prepended to packets. This property applies only to IPv6 tunnels.") +#define DESCRIBE_DOC_NM_SETTING_IP_TUNNEL_FLAGS N_("Tunnel flags. Currently the following values are supported: NM_IP_TUNNEL_FLAG_IP6_IGN_ENCAP_LIMIT (0x1), NM_IP_TUNNEL_FLAG_IP6_USE_ORIG_TCLASS (0x2), NM_IP_TUNNEL_FLAG_IP6_USE_ORIG_FLOWLABEL (0x4), NM_IP_TUNNEL_FLAG_IP6_MIP6_DEV (0x8), NM_IP_TUNNEL_FLAG_IP6_RCV_DSCP_COPY (0x10), NM_IP_TUNNEL_FLAG_IP6_USE_ORIG_FWMARK (0x20). They are valid only for IPv6 tunnels.") #define DESCRIBE_DOC_NM_SETTING_IP_TUNNEL_FLOW_LABEL N_("The flow label to assign to tunnel packets. This property applies only to IPv6 tunnels.") #define DESCRIBE_DOC_NM_SETTING_IP_TUNNEL_INPUT_KEY N_("The key used for tunnel input packets; the property is valid only for certain tunnel modes (GRE, IP6GRE). If empty, no key is used.") #define DESCRIBE_DOC_NM_SETTING_IP_TUNNEL_LOCAL N_("The local endpoint of the tunnel; the value can be empty, otherwise it must contain an IPv4 or IPv6 address.") @@ -207,16 +210,16 @@ #define DESCRIBE_DOC_NM_SETTING_IP_TUNNEL_TOS N_("The type of service (IPv4) or traffic class (IPv6) field to be set on tunneled packets.") #define DESCRIBE_DOC_NM_SETTING_IP_TUNNEL_TTL N_("The TTL to assign to tunneled packets. 0 is a special value meaning that packets inherit the TTL value.") #define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_ADDRESSES N_("Array of IP addresses.") -#define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DAD_TIMEOUT N_("Timeout in milliseconds used to check for the presence of duplicate IP addresses on the network. If an address conflict is detected, the activation will fail. A zero value means that no duplicate address detection is performed, -1 means the default value (either configuration ipvx.dad-timeout override or 3 seconds). A value greater than zero is a timeout in milliseconds.") -#define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DHCP_CLIENT_ID N_("A string sent to the DHCP server to identify the local machine which the DHCP server may use to customize the DHCP lease and options. When the property is a hex string ('aa:bb:cc') it is interpreted as a binary client ID, in which case the first byte is assumed to be the 'type' field as per RFC 2132 section 9.14 and the remaining bytes may be an hardware address (e.g. '01:xx:xx:xx:xx:xx:xx' where 1 is the Ethernet ARP type and the rest is a MAC address). If the property is not a hex string it is considered as a non-hardware-address client ID and the 'type' field is set to 0.") +#define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DAD_TIMEOUT N_("Timeout in milliseconds used to check for the presence of duplicate IP addresses on the network. If an address conflict is detected, the activation will fail. A zero value means that no duplicate address detection is performed, -1 means the default value (either configuration ipvx.dad-timeout override or zero). A value greater than zero is a timeout in milliseconds. The property is currently implemented only for IPv4.") +#define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DHCP_CLIENT_ID N_("A string sent to the DHCP server to identify the local machine which the DHCP server may use to customize the DHCP lease and options. When the property is a hex string ('aa:bb:cc') it is interpreted as a binary client ID, in which case the first byte is assumed to be the 'type' field as per RFC 2132 section 9.14 and the remaining bytes may be an hardware address (e.g. '01:xx:xx:xx:xx:xx:xx' where 1 is the Ethernet ARP type and the rest is a MAC address). If the property is not a hex string it is considered as a non-hardware-address client ID and the 'type' field is set to 0. The special values \"mac\" and \"perm-mac\" are supported, which use the current or permanent MAC address of the device to generate a client identifier with type ethernet type (01). Currently, these options only work for ethernet type of links. The special value \"stable\" is supported to generate a type 0 client identifier based on the stable-id (see connection.stable-id) and a per-host key. If unset, a globally configured default is used. If still unset, the client-id from the last lease is reused.") #define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DHCP_FQDN N_("If the \"dhcp-send-hostname\" property is TRUE, then the specified FQDN will be sent to the DHCP server when acquiring a lease. This property and \"dhcp-hostname\" are mutually exclusive and cannot be set at the same time.") #define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DHCP_HOSTNAME N_("If the \"dhcp-send-hostname\" property is TRUE, then the specified name will be sent to the DHCP server when acquiring a lease. This property and \"dhcp-fqdn\" are mutually exclusive and cannot be set at the same time.") #define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DHCP_SEND_HOSTNAME N_("If TRUE, a hostname is sent to the DHCP server when acquiring a lease. Some DHCP servers use this hostname to update DNS databases, essentially providing a static hostname for the computer. If the \"dhcp-hostname\" property is NULL and this property is TRUE, the current persistent hostname of the computer is sent.") #define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DHCP_TIMEOUT N_("A timeout for a DHCP transaction in seconds.") #define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DNS N_("Array of IP addresses of DNS servers.") #define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DNS_OPTIONS N_("Array of DNS options as described in man 5 resolv.conf. NULL means that the options are unset and left at the default. In this case NetworkManager will use default options. This is distinct from an empty list of properties.") -#define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DNS_PRIORITY N_("Intra-connection DNS priority. The relative priority to be used when determining the order of DNS servers in resolv.conf. A lower value means that servers will be on top of the file. Zero selects the default value, which is 50 for VPNs and 100 for other connections. Note that the priority is to order DNS settings for multiple active connections. It does not disambiguate multiple DNS servers within the same connection profile. For that, just specify the DNS servers in the desired order. When multiple devices have configurations with the same priority, the one with an active default route will be preferred. Note that when using dns=dnsmasq the order is meaningless since dnsmasq forwards queries to all known servers at the same time. Negative values have the special effect of excluding other configurations with a greater priority value; so in presence of at least a negative priority, only DNS servers from connections with the lowest priority value will be used.") -#define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DNS_SEARCH N_("Array of DNS search domains.") +#define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DNS_PRIORITY N_("DNS servers priority. The relative priority for DNS servers specified by this setting. A lower value is better (higher priority). Zero selects the default value, which is 50 for VPNs and 100 for other connections. Note that the priority is to order DNS settings for multiple active connections. It does not disambiguate multiple DNS servers within the same connection profile. When using dns=default, servers with higher priority will be on top of resolv.conf. To prioritize a given server over another one within the same connection, just specify them in the desired order. When multiple devices have configurations with the same priority, the one with an active default route will be preferred. Negative values have the special effect of excluding other configurations with a greater priority value; so in presence of at least a negative priority, only DNS servers from connections with the lowest priority value will be used. When using a DNS resolver that supports split-DNS as dns=dnsmasq or dns=systemd-resolved, each connection is used to query domains in its search list. Queries for domains not present in any search list are routed through connections having the '~.' special wildcard domain, which is added automatically to connections with the default route (or can be added manually). When multiple connections specify the same domain, the one with the highest priority (lowest numerical value) wins. If a connection specifies a domain which is subdomain of another domain with a negative DNS priority value, the subdomain is ignored.") +#define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DNS_SEARCH N_("Array of DNS search domains. Domains starting with a tilde ('~') are considered 'routing' domains and are used only to decide the interface over which a query must be forwarded; they are not used to complete unqualified host names.") #define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_GATEWAY N_("The gateway associated with this configuration. This is only meaningful if \"addresses\" is also set.") #define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_IGNORE_AUTO_DNS N_("When \"method\" is set to \"auto\" and this property to TRUE, automatically configured nameservers and search domains are ignored and only nameservers and search domains specified in the \"dns\" and \"dns-search\" properties, if any, are used.") #define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_IGNORE_AUTO_ROUTES N_("When \"method\" is set to \"auto\" and this property to TRUE, automatically configured routes are ignored and only routes specified in the \"routes\" property, if any, are used.") @@ -229,14 +232,14 @@ #define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_ROUTES N_("Array of IP routes.") #define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE N_("Configure method for creating the address for use with RFC4862 IPv6 Stateless Address Autoconfiguration. The permitted values are: NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE_EUI64 (0) or NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE_STABLE_PRIVACY (1). If the property is set to EUI64, the addresses will be generated using the interface tokens derived from hardware address. This makes the host part of the address to stay constant, making it possible to track host's presence when it changes networks. The address changes when the interface hardware is replaced. The value of stable-privacy enables use of cryptographically secure hash of a secret host-specific key along with the connection's stable-id and the network address as specified by RFC7217. This makes it impossible to use the address track host's presence, and makes the address stable when the network interface hardware is replaced. On D-Bus, the absence of an addr-gen-mode setting equals enabling stable-privacy. For keyfile plugin, the absence of the setting on disk means EUI64 so that the property doesn't change on upgrade from older versions. Note that this setting is distinct from the Privacy Extensions as configured by \"ip6-privacy\" property and it does not affect the temporary addresses configured with this option.") #define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_ADDRESSES N_("Array of IP addresses.") -#define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DAD_TIMEOUT N_("Timeout in milliseconds used to check for the presence of duplicate IP addresses on the network. If an address conflict is detected, the activation will fail. A zero value means that no duplicate address detection is performed, -1 means the default value (either configuration ipvx.dad-timeout override or 3 seconds). A value greater than zero is a timeout in milliseconds.") +#define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DAD_TIMEOUT N_("Timeout in milliseconds used to check for the presence of duplicate IP addresses on the network. If an address conflict is detected, the activation will fail. A zero value means that no duplicate address detection is performed, -1 means the default value (either configuration ipvx.dad-timeout override or zero). A value greater than zero is a timeout in milliseconds. The property is currently implemented only for IPv4.") #define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DHCP_HOSTNAME N_("If the \"dhcp-send-hostname\" property is TRUE, then the specified name will be sent to the DHCP server when acquiring a lease. This property and \"dhcp-fqdn\" are mutually exclusive and cannot be set at the same time.") #define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DHCP_SEND_HOSTNAME N_("If TRUE, a hostname is sent to the DHCP server when acquiring a lease. Some DHCP servers use this hostname to update DNS databases, essentially providing a static hostname for the computer. If the \"dhcp-hostname\" property is NULL and this property is TRUE, the current persistent hostname of the computer is sent.") #define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DHCP_TIMEOUT N_("A timeout for a DHCP transaction in seconds.") #define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DNS N_("Array of IP addresses of DNS servers.") #define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DNS_OPTIONS N_("Array of DNS options as described in man 5 resolv.conf. NULL means that the options are unset and left at the default. In this case NetworkManager will use default options. This is distinct from an empty list of properties.") -#define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DNS_PRIORITY N_("Intra-connection DNS priority. The relative priority to be used when determining the order of DNS servers in resolv.conf. A lower value means that servers will be on top of the file. Zero selects the default value, which is 50 for VPNs and 100 for other connections. Note that the priority is to order DNS settings for multiple active connections. It does not disambiguate multiple DNS servers within the same connection profile. For that, just specify the DNS servers in the desired order. When multiple devices have configurations with the same priority, the one with an active default route will be preferred. Note that when using dns=dnsmasq the order is meaningless since dnsmasq forwards queries to all known servers at the same time. Negative values have the special effect of excluding other configurations with a greater priority value; so in presence of at least a negative priority, only DNS servers from connections with the lowest priority value will be used.") -#define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DNS_SEARCH N_("Array of DNS search domains.") +#define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DNS_PRIORITY N_("DNS servers priority. The relative priority for DNS servers specified by this setting. A lower value is better (higher priority). Zero selects the default value, which is 50 for VPNs and 100 for other connections. Note that the priority is to order DNS settings for multiple active connections. It does not disambiguate multiple DNS servers within the same connection profile. When using dns=default, servers with higher priority will be on top of resolv.conf. To prioritize a given server over another one within the same connection, just specify them in the desired order. When multiple devices have configurations with the same priority, the one with an active default route will be preferred. Negative values have the special effect of excluding other configurations with a greater priority value; so in presence of at least a negative priority, only DNS servers from connections with the lowest priority value will be used. When using a DNS resolver that supports split-DNS as dns=dnsmasq or dns=systemd-resolved, each connection is used to query domains in its search list. Queries for domains not present in any search list are routed through connections having the '~.' special wildcard domain, which is added automatically to connections with the default route (or can be added manually). When multiple connections specify the same domain, the one with the highest priority (lowest numerical value) wins. If a connection specifies a domain which is subdomain of another domain with a negative DNS priority value, the subdomain is ignored.") +#define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DNS_SEARCH N_("Array of DNS search domains. Domains starting with a tilde ('~') are considered 'routing' domains and are used only to decide the interface over which a query must be forwarded; they are not used to complete unqualified host names.") #define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_GATEWAY N_("The gateway associated with this configuration. This is only meaningful if \"addresses\" is also set.") #define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_IGNORE_AUTO_DNS N_("When \"method\" is set to \"auto\" and this property to TRUE, automatically configured nameservers and search domains are ignored and only nameservers and search domains specified in the \"dns\" and \"dns-search\" properties, if any, are used.") #define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_IGNORE_AUTO_ROUTES N_("When \"method\" is set to \"auto\" and this property to TRUE, automatically configured routes are ignored and only routes specified in the \"routes\" property, if any, are used.") diff --git a/clients/common/tests/meson.build b/clients/common/tests/meson.build new file mode 100644 index 00000000..cc357cdc --- /dev/null +++ b/clients/common/tests/meson.build @@ -0,0 +1,23 @@ +test_unit = 'test-general' + +deps = [ + libnm_dep, + libnmc_dep, + libnmc_base_dep, + nm_core_dep +] + +exe = executable( + 'clients-' + test_unit, + test_unit + '.c', + dependencies: deps, + c_args: clients_cflags + [ + '-DNETWORKMANAGER_COMPILATION_TEST', + ], +) + +test( + 'clients/' + test_unit, + test_script, + args: test_args + [exe.full_path()] +) diff --git a/clients/common/tests/test-general.c b/clients/common/tests/test-general.c index 64efd14d..8f96eb26 100644 --- a/clients/common/tests/test-general.c +++ b/clients/common/tests/test-general.c @@ -19,10 +19,6 @@ #include "nm-default.h" -#include "NetworkManager.h" - -#include "nm-utils/nm-hash-utils.h" - #include "nm-meta-setting-access.h" #include "nm-utils/nm-test-utils.h" @@ -90,7 +86,7 @@ test_client_meta_check (void) g_assert (pi->setting_info == info); g_assert (pi->property_name); - g_assert (nm_g_hash_table_add (property_names, (gpointer) pi->property_name)); + g_assert (g_hash_table_add (property_names, (gpointer) pi->property_name)); g_assert_cmpstr (pi->property_name, ==, pi->meta_type->get_name ((const NMMetaAbstractInfo *) pi, FALSE)); g_assert_cmpstr (pi->property_name, ==, pi->meta_type->get_name ((const NMMetaAbstractInfo *) pi, TRUE)); @@ -104,14 +100,14 @@ test_client_meta_check (void) if (info->valid_parts) { gsize i, l; - gs_unref_hashtable GHashTable *dup = g_hash_table_new (NULL, NULL); + gs_unref_hashtable GHashTable *dup = g_hash_table_new (nm_direct_hash, NULL); l = NM_PTRARRAY_LEN (info->valid_parts); g_assert (l >= 2); for (i = 0; info->valid_parts[i]; i++) { g_assert (info->valid_parts[i]->setting_info); - g_assert (nm_g_hash_table_add (dup, (gpointer) info->valid_parts[i]->setting_info)); + g_assert (g_hash_table_add (dup, (gpointer) info->valid_parts[i]->setting_info)); if (i == 0) { g_assert (info->valid_parts[i]->setting_info == &nm_meta_setting_infos_editor[NM_META_SETTING_TYPE_CONNECTION]); diff --git a/clients/meson.build b/clients/meson.build new file mode 100644 index 00000000..46e1f1cd --- /dev/null +++ b/clients/meson.build @@ -0,0 +1,35 @@ +name = 'nm-online' + +deps = [ + libnm_dep, + nm_core_dep +] + +clients_cflags = [ + '-DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_CLIENT', + '-DNMLOCALEDIR="@0@"'.format(nm_localedir), +] + +cflags = clients_cflags + [ + '-DG_LOG_DOMAIN="@0@"'.format(name), +] + +executable( + name, + name + '.c', + dependencies: deps, + c_args: cflags, + link_args: ldflags_linker_script_binary, + link_depends: linker_script_binary, + install: true +) + +subdir('common') + +if enable_nmcli + subdir('cli') +endif + +if enable_nmtui + subdir('tui') +endif diff --git a/clients/nm-online.c b/clients/nm-online.c index ee0b5249..77a11321 100644 --- a/clients/nm-online.c +++ b/clients/nm-online.c @@ -38,8 +38,6 @@ #include <getopt.h> #include <locale.h> -#include "NetworkManager.h" - #define PROGRESS_STEPS 15 #define EXIT_FAILURE_OFFLINE 1 @@ -246,8 +244,6 @@ main (int argc, char *argv[]) bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); - nm_g_type_init (); - data.start_timestamp_ms = _now_ms (); opt_ctx = g_option_context_new (NULL); diff --git a/clients/tests/test-client.check-on-disk/Makefile.am b/clients/tests/test-client.check-on-disk/Makefile.am new file mode 100644 index 00000000..aa49eda6 --- /dev/null +++ b/clients/tests/test-client.check-on-disk/Makefile.am @@ -0,0 +1,114 @@ +# generated with `NM_TEST_REGENERATE=1 make check` + +clients_tests_expected_files = \ + clients/tests/test-client.check-on-disk/test_001-001.expected \ + clients/tests/test-client.check-on-disk/test_001-002.expected \ + clients/tests/test-client.check-on-disk/test_001-003.expected \ + clients/tests/test-client.check-on-disk/test_001-004.expected \ + clients/tests/test-client.check-on-disk/test_001-005.expected \ + clients/tests/test-client.check-on-disk/test_001-006.expected \ + clients/tests/test-client.check-on-disk/test_001-007.expected \ + clients/tests/test-client.check-on-disk/test_001-008.expected \ + clients/tests/test-client.check-on-disk/test_001-009.expected \ + clients/tests/test-client.check-on-disk/test_001-010.expected \ + clients/tests/test-client.check-on-disk/test_001-011.expected \ + clients/tests/test-client.check-on-disk/test_001-012.expected \ + clients/tests/test-client.check-on-disk/test_001-013.expected \ + clients/tests/test-client.check-on-disk/test_001-014.expected \ + clients/tests/test-client.check-on-disk/test_001-015.expected \ + clients/tests/test-client.check-on-disk/test_001-016.expected \ + clients/tests/test-client.check-on-disk/test_001-017.expected \ + clients/tests/test-client.check-on-disk/test_001-018.expected \ + clients/tests/test-client.check-on-disk/test_001-019.expected \ + clients/tests/test-client.check-on-disk/test_001-020.expected \ + clients/tests/test-client.check-on-disk/test_001-021.expected \ + clients/tests/test-client.check-on-disk/test_001-022.expected \ + clients/tests/test-client.check-on-disk/test_001-023.expected \ + clients/tests/test-client.check-on-disk/test_001-024.expected \ + clients/tests/test-client.check-on-disk/test_001-025.expected \ + clients/tests/test-client.check-on-disk/test_001-026.expected \ + clients/tests/test-client.check-on-disk/test_002-001.expected \ + clients/tests/test-client.check-on-disk/test_002-002.expected \ + clients/tests/test-client.check-on-disk/test_002-003.expected \ + clients/tests/test-client.check-on-disk/test_002-004.expected \ + clients/tests/test-client.check-on-disk/test_002-005.expected \ + clients/tests/test-client.check-on-disk/test_002-006.expected \ + clients/tests/test-client.check-on-disk/test_002-007.expected \ + clients/tests/test-client.check-on-disk/test_002-008.expected \ + clients/tests/test-client.check-on-disk/test_002-009.expected \ + clients/tests/test-client.check-on-disk/test_002-010.expected \ + clients/tests/test-client.check-on-disk/test_002-011.expected \ + clients/tests/test-client.check-on-disk/test_002-012.expected \ + clients/tests/test-client.check-on-disk/test_002-013.expected \ + clients/tests/test-client.check-on-disk/test_002-014.expected \ + clients/tests/test-client.check-on-disk/test_002-015.expected \ + clients/tests/test-client.check-on-disk/test_002-016.expected \ + clients/tests/test-client.check-on-disk/test_002-017.expected \ + clients/tests/test-client.check-on-disk/test_002-018.expected \ + clients/tests/test-client.check-on-disk/test_002-019.expected \ + clients/tests/test-client.check-on-disk/test_002-020.expected \ + clients/tests/test-client.check-on-disk/test_002-021.expected \ + clients/tests/test-client.check-on-disk/test_002-022.expected \ + clients/tests/test-client.check-on-disk/test_002-023.expected \ + clients/tests/test-client.check-on-disk/test_002-024.expected \ + clients/tests/test-client.check-on-disk/test_003-001.expected \ + clients/tests/test-client.check-on-disk/test_003-002.expected \ + clients/tests/test-client.check-on-disk/test_003-003.expected \ + clients/tests/test-client.check-on-disk/test_003-004.expected \ + clients/tests/test-client.check-on-disk/test_003-005.expected \ + clients/tests/test-client.check-on-disk/test_003-006.expected \ + clients/tests/test-client.check-on-disk/test_003-007.expected \ + clients/tests/test-client.check-on-disk/test_003-008.expected \ + clients/tests/test-client.check-on-disk/test_003-009.expected \ + clients/tests/test-client.check-on-disk/test_003-010.expected \ + clients/tests/test-client.check-on-disk/test_003-011.expected \ + clients/tests/test-client.check-on-disk/test_003-012.expected \ + clients/tests/test-client.check-on-disk/test_003-013.expected \ + clients/tests/test-client.check-on-disk/test_003-014.expected \ + clients/tests/test-client.check-on-disk/test_003-015.expected \ + clients/tests/test-client.check-on-disk/test_003-016.expected \ + clients/tests/test-client.check-on-disk/test_003-017.expected \ + clients/tests/test-client.check-on-disk/test_003-018.expected \ + clients/tests/test-client.check-on-disk/test_003-019.expected \ + clients/tests/test-client.check-on-disk/test_003-020.expected \ + clients/tests/test-client.check-on-disk/test_003-021.expected \ + clients/tests/test-client.check-on-disk/test_003-022.expected \ + clients/tests/test-client.check-on-disk/test_003-023.expected \ + clients/tests/test-client.check-on-disk/test_003-024.expected \ + clients/tests/test-client.check-on-disk/test_003-025.expected \ + clients/tests/test-client.check-on-disk/test_003-026.expected \ + clients/tests/test-client.check-on-disk/test_003-027.expected \ + clients/tests/test-client.check-on-disk/test_003-028.expected \ + clients/tests/test-client.check-on-disk/test_003-029.expected \ + clients/tests/test-client.check-on-disk/test_003-030.expected \ + clients/tests/test-client.check-on-disk/test_003-031.expected \ + clients/tests/test-client.check-on-disk/test_003-032.expected \ + clients/tests/test-client.check-on-disk/test_003-033.expected \ + clients/tests/test-client.check-on-disk/test_003-034.expected \ + clients/tests/test-client.check-on-disk/test_003-035.expected \ + clients/tests/test-client.check-on-disk/test_003-036.expected \ + clients/tests/test-client.check-on-disk/test_003-037.expected \ + clients/tests/test-client.check-on-disk/test_003-038.expected \ + clients/tests/test-client.check-on-disk/test_003-039.expected \ + clients/tests/test-client.check-on-disk/test_003-040.expected \ + clients/tests/test-client.check-on-disk/test_003-041.expected \ + clients/tests/test-client.check-on-disk/test_003-042.expected \ + clients/tests/test-client.check-on-disk/test_003-043.expected \ + clients/tests/test-client.check-on-disk/test_003-044.expected \ + clients/tests/test-client.check-on-disk/test_003-045.expected \ + clients/tests/test-client.check-on-disk/test_003-046.expected \ + clients/tests/test-client.check-on-disk/test_003-047.expected \ + clients/tests/test-client.check-on-disk/test_003-048.expected \ + clients/tests/test-client.check-on-disk/test_003-049.expected \ + clients/tests/test-client.check-on-disk/test_003-050.expected \ + clients/tests/test-client.check-on-disk/test_003-051.expected \ + clients/tests/test-client.check-on-disk/test_003-052.expected \ + clients/tests/test-client.check-on-disk/test_003-053.expected \ + clients/tests/test-client.check-on-disk/test_003-054.expected \ + clients/tests/test-client.check-on-disk/test_004-001.expected \ + clients/tests/test-client.check-on-disk/test_004-002.expected \ + clients/tests/test-client.check-on-disk/test_004-003.expected \ + clients/tests/test-client.check-on-disk/test_004-004.expected \ + clients/tests/test-client.check-on-disk/test_004-005.expected \ + clients/tests/test-client.check-on-disk/test_004-006.expected \ + $(NULL) diff --git a/clients/tests/test-client.check-on-disk/test_001-001.expected b/clients/tests/test-client.check-on-disk/test_001-001.expected new file mode 100644 index 00000000..23f546bf --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_001-001.expected @@ -0,0 +1,19 @@ +location: clients/tests/test-client.py:651:test_001()/1 +cmd: $NMCLI +lang: C +returncode: 0 +stdout: 277 bytes +>>> +DNS configuration: + servers: 1.2.3.4 5.6.7.8 + +Use "nmcli device show" to get complete information about known devices and +"nmcli connection show" to get an overview on active connection profiles. + +Consult nmcli(1) and nmcli-examples(5) manual pages for complete usage details. + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_001-002.expected b/clients/tests/test-client.check-on-disk/test_001-002.expected new file mode 100644 index 00000000..bcbb86ee --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_001-002.expected @@ -0,0 +1,21 @@ +location: clients/tests/test-client.py:651:test_001()/2 +cmd: $NMCLI +lang: pl_PL.UTF-8 +returncode: 0 +stdout: 310 bytes +>>> +DNS configuration: + servers: 1.2.3.4 5.6.7.8 + +Polecenie „nmcli device show” wyświetli pełne informacje o znanych +urządzeniach, a „nmcli connection show” wyświetli przegląd aktywnych +profili połączeń. + +Strony podręcznika nmcli(1) i nmcli-examples(5) zawierają pełne informacje +o użyciu. + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_001-003.expected b/clients/tests/test-client.check-on-disk/test_001-003.expected new file mode 100644 index 00000000..f08e8df7 --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_001-003.expected @@ -0,0 +1,13 @@ +location: clients/tests/test-client.py:653:test_001()/3 +cmd: $NMCLI -f AP -mode multiline -p d show wlan0 +lang: C +returncode: 10 +stdout: 0 bytes +>>> + +<<< +stderr: 33 bytes +>>> +Error: Device 'wlan0' not found. + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_001-004.expected b/clients/tests/test-client.check-on-disk/test_001-004.expected new file mode 100644 index 00000000..1e01f6cd --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_001-004.expected @@ -0,0 +1,13 @@ +location: clients/tests/test-client.py:653:test_001()/4 +cmd: $NMCLI -f AP -mode multiline -p d show wlan0 +lang: pl_PL.UTF-8 +returncode: 10 +stdout: 0 bytes +>>> + +<<< +stderr: 49 bytes +>>> +Błąd: Nie odnaleziono urządzenia „wlan0”. + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_001-005.expected b/clients/tests/test-client.check-on-disk/test_001-005.expected new file mode 100644 index 00000000..c3ddbd52 --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_001-005.expected @@ -0,0 +1,13 @@ +location: clients/tests/test-client.py:655:test_001()/5 +cmd: $NMCLI c s +lang: C +returncode: 0 +stdout: 26 bytes +>>> +NAME UUID TYPE DEVICE + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_001-006.expected b/clients/tests/test-client.check-on-disk/test_001-006.expected new file mode 100644 index 00000000..6e1bbca1 --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_001-006.expected @@ -0,0 +1,13 @@ +location: clients/tests/test-client.py:655:test_001()/6 +cmd: $NMCLI c s +lang: pl_PL.UTF-8 +returncode: 0 +stdout: 26 bytes +>>> +NAME UUID TYPE DEVICE + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_001-007.expected b/clients/tests/test-client.check-on-disk/test_001-007.expected new file mode 100644 index 00000000..759cfe56 --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_001-007.expected @@ -0,0 +1,13 @@ +location: clients/tests/test-client.py:657:test_001()/7 +cmd: $NMCLI bogus s +lang: C +returncode: 2 +stdout: 0 bytes +>>> + +<<< +stderr: 68 bytes +>>> +Error: argument 'bogus' not understood. Try passing --help instead. + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_001-008.expected b/clients/tests/test-client.check-on-disk/test_001-008.expected new file mode 100644 index 00000000..ba4d941c --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_001-008.expected @@ -0,0 +1,13 @@ +location: clients/tests/test-client.py:657:test_001()/8 +cmd: $NMCLI bogus s +lang: pl_PL.UTF-8 +returncode: 2 +stdout: 0 bytes +>>> + +<<< +stderr: 87 bytes +>>> +Błąd: nie zrozumiano parametru „bogus”. Można użyć „--help” zamiast tego. + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_001-009.expected b/clients/tests/test-client.check-on-disk/test_001-009.expected new file mode 100644 index 00000000..2614409a --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_001-009.expected @@ -0,0 +1,29 @@ +location: clients/tests/test-client.py:665:test_001()/9 +cmd: $NMCLI general permissions +lang: C +returncode: 0 +stdout: 1275 bytes +>>> +PERMISSION VALUE +org.freedesktop.NetworkManager.enable-disable-network yes +org.freedesktop.NetworkManager.enable-disable-wifi yes +org.freedesktop.NetworkManager.enable-disable-wwan yes +org.freedesktop.NetworkManager.enable-disable-wimax yes +org.freedesktop.NetworkManager.sleep-wake no +org.freedesktop.NetworkManager.network-control yes +org.freedesktop.NetworkManager.wifi.share.protected yes +org.freedesktop.NetworkManager.wifi.share.open yes +org.freedesktop.NetworkManager.settings.modify.system yes +org.freedesktop.NetworkManager.settings.modify.own yes +org.freedesktop.NetworkManager.settings.modify.hostname yes +org.freedesktop.NetworkManager.settings.modify.global-dns no +org.freedesktop.NetworkManager.reload no +org.freedesktop.NetworkManager.checkpoint-rollback unknown +org.freedesktop.NetworkManager.enable-disable-statistics unknown +org.freedesktop.NetworkManager.enable-disable-connectivity-check unknown + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_001-010.expected b/clients/tests/test-client.check-on-disk/test_001-010.expected new file mode 100644 index 00000000..0c9f540f --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_001-010.expected @@ -0,0 +1,29 @@ +location: clients/tests/test-client.py:665:test_001()/10 +cmd: $NMCLI general permissions +lang: pl_PL.UTF-8 +returncode: 0 +stdout: 1292 bytes +>>> +PERMISSION VALUE +org.freedesktop.NetworkManager.enable-disable-network tak +org.freedesktop.NetworkManager.enable-disable-wifi tak +org.freedesktop.NetworkManager.enable-disable-wwan tak +org.freedesktop.NetworkManager.enable-disable-wimax tak +org.freedesktop.NetworkManager.sleep-wake nie +org.freedesktop.NetworkManager.network-control tak +org.freedesktop.NetworkManager.wifi.share.protected tak +org.freedesktop.NetworkManager.wifi.share.open tak +org.freedesktop.NetworkManager.settings.modify.system tak +org.freedesktop.NetworkManager.settings.modify.own tak +org.freedesktop.NetworkManager.settings.modify.hostname tak +org.freedesktop.NetworkManager.settings.modify.global-dns nie +org.freedesktop.NetworkManager.reload nie +org.freedesktop.NetworkManager.checkpoint-rollback nieznane +org.freedesktop.NetworkManager.enable-disable-statistics nieznane +org.freedesktop.NetworkManager.enable-disable-connectivity-check nieznane + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_001-011.expected b/clients/tests/test-client.check-on-disk/test_001-011.expected new file mode 100644 index 00000000..fc6cc6b6 --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_001-011.expected @@ -0,0 +1,33 @@ +location: clients/tests/test-client.py:665:test_001()/11 +cmd: $NMCLI --pretty general permissions +lang: C +returncode: 0 +stdout: 1472 bytes +>>> +============================== + NetworkManager permissions +============================== +PERMISSION VALUE +--------------------------------------------------------------------------------------------------------- +org.freedesktop.NetworkManager.enable-disable-network yes +org.freedesktop.NetworkManager.enable-disable-wifi yes +org.freedesktop.NetworkManager.enable-disable-wwan yes +org.freedesktop.NetworkManager.enable-disable-wimax yes +org.freedesktop.NetworkManager.sleep-wake no +org.freedesktop.NetworkManager.network-control yes +org.freedesktop.NetworkManager.wifi.share.protected yes +org.freedesktop.NetworkManager.wifi.share.open yes +org.freedesktop.NetworkManager.settings.modify.system yes +org.freedesktop.NetworkManager.settings.modify.own yes +org.freedesktop.NetworkManager.settings.modify.hostname yes +org.freedesktop.NetworkManager.settings.modify.global-dns no +org.freedesktop.NetworkManager.reload no +org.freedesktop.NetworkManager.checkpoint-rollback unknown +org.freedesktop.NetworkManager.enable-disable-statistics unknown +org.freedesktop.NetworkManager.enable-disable-connectivity-check unknown + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_001-012.expected b/clients/tests/test-client.check-on-disk/test_001-012.expected new file mode 100644 index 00000000..cb1793d2 --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_001-012.expected @@ -0,0 +1,33 @@ +location: clients/tests/test-client.py:665:test_001()/12 +cmd: $NMCLI --pretty general permissions +lang: pl_PL.UTF-8 +returncode: 0 +stdout: 1519 bytes +>>> +===================================== + Uprawnienia usługi NetworkManager +===================================== +PERMISSION VALUE +----------------------------------------------------------------------------------------------------------------- +org.freedesktop.NetworkManager.enable-disable-network tak +org.freedesktop.NetworkManager.enable-disable-wifi tak +org.freedesktop.NetworkManager.enable-disable-wwan tak +org.freedesktop.NetworkManager.enable-disable-wimax tak +org.freedesktop.NetworkManager.sleep-wake nie +org.freedesktop.NetworkManager.network-control tak +org.freedesktop.NetworkManager.wifi.share.protected tak +org.freedesktop.NetworkManager.wifi.share.open tak +org.freedesktop.NetworkManager.settings.modify.system tak +org.freedesktop.NetworkManager.settings.modify.own tak +org.freedesktop.NetworkManager.settings.modify.hostname tak +org.freedesktop.NetworkManager.settings.modify.global-dns nie +org.freedesktop.NetworkManager.reload nie +org.freedesktop.NetworkManager.checkpoint-rollback nieznane +org.freedesktop.NetworkManager.enable-disable-statistics nieznane +org.freedesktop.NetworkManager.enable-disable-connectivity-check nieznane + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_001-013.expected b/clients/tests/test-client.check-on-disk/test_001-013.expected new file mode 100644 index 00000000..1317ee13 --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_001-013.expected @@ -0,0 +1,28 @@ +location: clients/tests/test-client.py:665:test_001()/13 +cmd: $NMCLI --terse general permissions +lang: C +returncode: 0 +stdout: 899 bytes +>>> +org.freedesktop.NetworkManager.enable-disable-network:yes +org.freedesktop.NetworkManager.enable-disable-wifi:yes +org.freedesktop.NetworkManager.enable-disable-wwan:yes +org.freedesktop.NetworkManager.enable-disable-wimax:yes +org.freedesktop.NetworkManager.sleep-wake:no +org.freedesktop.NetworkManager.network-control:yes +org.freedesktop.NetworkManager.wifi.share.protected:yes +org.freedesktop.NetworkManager.wifi.share.open:yes +org.freedesktop.NetworkManager.settings.modify.system:yes +org.freedesktop.NetworkManager.settings.modify.own:yes +org.freedesktop.NetworkManager.settings.modify.hostname:yes +org.freedesktop.NetworkManager.settings.modify.global-dns:no +org.freedesktop.NetworkManager.reload:no +org.freedesktop.NetworkManager.checkpoint-rollback:unknown +org.freedesktop.NetworkManager.enable-disable-statistics:unknown +org.freedesktop.NetworkManager.enable-disable-connectivity-check:unknown + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_001-014.expected b/clients/tests/test-client.check-on-disk/test_001-014.expected new file mode 100644 index 00000000..73e62b7e --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_001-014.expected @@ -0,0 +1,28 @@ +location: clients/tests/test-client.py:665:test_001()/14 +cmd: $NMCLI --terse general permissions +lang: pl_PL.UTF-8 +returncode: 0 +stdout: 899 bytes +>>> +org.freedesktop.NetworkManager.enable-disable-network:yes +org.freedesktop.NetworkManager.enable-disable-wifi:yes +org.freedesktop.NetworkManager.enable-disable-wwan:yes +org.freedesktop.NetworkManager.enable-disable-wimax:yes +org.freedesktop.NetworkManager.sleep-wake:no +org.freedesktop.NetworkManager.network-control:yes +org.freedesktop.NetworkManager.wifi.share.protected:yes +org.freedesktop.NetworkManager.wifi.share.open:yes +org.freedesktop.NetworkManager.settings.modify.system:yes +org.freedesktop.NetworkManager.settings.modify.own:yes +org.freedesktop.NetworkManager.settings.modify.hostname:yes +org.freedesktop.NetworkManager.settings.modify.global-dns:no +org.freedesktop.NetworkManager.reload:no +org.freedesktop.NetworkManager.checkpoint-rollback:unknown +org.freedesktop.NetworkManager.enable-disable-statistics:unknown +org.freedesktop.NetworkManager.enable-disable-connectivity-check:unknown + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_001-015.expected b/clients/tests/test-client.check-on-disk/test_001-015.expected new file mode 100644 index 00000000..426d9834 --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_001-015.expected @@ -0,0 +1,29 @@ +location: clients/tests/test-client.py:665:test_001()/15 +cmd: $NMCLI --mode tabular general permissions +lang: C +returncode: 0 +stdout: 1275 bytes +>>> +PERMISSION VALUE +org.freedesktop.NetworkManager.enable-disable-network yes +org.freedesktop.NetworkManager.enable-disable-wifi yes +org.freedesktop.NetworkManager.enable-disable-wwan yes +org.freedesktop.NetworkManager.enable-disable-wimax yes +org.freedesktop.NetworkManager.sleep-wake no +org.freedesktop.NetworkManager.network-control yes +org.freedesktop.NetworkManager.wifi.share.protected yes +org.freedesktop.NetworkManager.wifi.share.open yes +org.freedesktop.NetworkManager.settings.modify.system yes +org.freedesktop.NetworkManager.settings.modify.own yes +org.freedesktop.NetworkManager.settings.modify.hostname yes +org.freedesktop.NetworkManager.settings.modify.global-dns no +org.freedesktop.NetworkManager.reload no +org.freedesktop.NetworkManager.checkpoint-rollback unknown +org.freedesktop.NetworkManager.enable-disable-statistics unknown +org.freedesktop.NetworkManager.enable-disable-connectivity-check unknown + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_001-016.expected b/clients/tests/test-client.check-on-disk/test_001-016.expected new file mode 100644 index 00000000..e501a8d3 --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_001-016.expected @@ -0,0 +1,29 @@ +location: clients/tests/test-client.py:665:test_001()/16 +cmd: $NMCLI --mode tabular general permissions +lang: pl_PL.UTF-8 +returncode: 0 +stdout: 1292 bytes +>>> +PERMISSION VALUE +org.freedesktop.NetworkManager.enable-disable-network tak +org.freedesktop.NetworkManager.enable-disable-wifi tak +org.freedesktop.NetworkManager.enable-disable-wwan tak +org.freedesktop.NetworkManager.enable-disable-wimax tak +org.freedesktop.NetworkManager.sleep-wake nie +org.freedesktop.NetworkManager.network-control tak +org.freedesktop.NetworkManager.wifi.share.protected tak +org.freedesktop.NetworkManager.wifi.share.open tak +org.freedesktop.NetworkManager.settings.modify.system tak +org.freedesktop.NetworkManager.settings.modify.own tak +org.freedesktop.NetworkManager.settings.modify.hostname tak +org.freedesktop.NetworkManager.settings.modify.global-dns nie +org.freedesktop.NetworkManager.reload nie +org.freedesktop.NetworkManager.checkpoint-rollback nieznane +org.freedesktop.NetworkManager.enable-disable-statistics nieznane +org.freedesktop.NetworkManager.enable-disable-connectivity-check nieznane + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_001-017.expected b/clients/tests/test-client.check-on-disk/test_001-017.expected new file mode 100644 index 00000000..ab38df97 --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_001-017.expected @@ -0,0 +1,33 @@ +location: clients/tests/test-client.py:665:test_001()/17 +cmd: $NMCLI --mode tabular --pretty general permissions +lang: C +returncode: 0 +stdout: 1472 bytes +>>> +============================== + NetworkManager permissions +============================== +PERMISSION VALUE +--------------------------------------------------------------------------------------------------------- +org.freedesktop.NetworkManager.enable-disable-network yes +org.freedesktop.NetworkManager.enable-disable-wifi yes +org.freedesktop.NetworkManager.enable-disable-wwan yes +org.freedesktop.NetworkManager.enable-disable-wimax yes +org.freedesktop.NetworkManager.sleep-wake no +org.freedesktop.NetworkManager.network-control yes +org.freedesktop.NetworkManager.wifi.share.protected yes +org.freedesktop.NetworkManager.wifi.share.open yes +org.freedesktop.NetworkManager.settings.modify.system yes +org.freedesktop.NetworkManager.settings.modify.own yes +org.freedesktop.NetworkManager.settings.modify.hostname yes +org.freedesktop.NetworkManager.settings.modify.global-dns no +org.freedesktop.NetworkManager.reload no +org.freedesktop.NetworkManager.checkpoint-rollback unknown +org.freedesktop.NetworkManager.enable-disable-statistics unknown +org.freedesktop.NetworkManager.enable-disable-connectivity-check unknown + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_001-018.expected b/clients/tests/test-client.check-on-disk/test_001-018.expected new file mode 100644 index 00000000..7bbf78f5 --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_001-018.expected @@ -0,0 +1,33 @@ +location: clients/tests/test-client.py:665:test_001()/18 +cmd: $NMCLI --mode tabular --pretty general permissions +lang: pl_PL.UTF-8 +returncode: 0 +stdout: 1519 bytes +>>> +===================================== + Uprawnienia usługi NetworkManager +===================================== +PERMISSION VALUE +----------------------------------------------------------------------------------------------------------------- +org.freedesktop.NetworkManager.enable-disable-network tak +org.freedesktop.NetworkManager.enable-disable-wifi tak +org.freedesktop.NetworkManager.enable-disable-wwan tak +org.freedesktop.NetworkManager.enable-disable-wimax tak +org.freedesktop.NetworkManager.sleep-wake nie +org.freedesktop.NetworkManager.network-control tak +org.freedesktop.NetworkManager.wifi.share.protected tak +org.freedesktop.NetworkManager.wifi.share.open tak +org.freedesktop.NetworkManager.settings.modify.system tak +org.freedesktop.NetworkManager.settings.modify.own tak +org.freedesktop.NetworkManager.settings.modify.hostname tak +org.freedesktop.NetworkManager.settings.modify.global-dns nie +org.freedesktop.NetworkManager.reload nie +org.freedesktop.NetworkManager.checkpoint-rollback nieznane +org.freedesktop.NetworkManager.enable-disable-statistics nieznane +org.freedesktop.NetworkManager.enable-disable-connectivity-check nieznane + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_001-019.expected b/clients/tests/test-client.check-on-disk/test_001-019.expected new file mode 100644 index 00000000..23692b05 --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_001-019.expected @@ -0,0 +1,28 @@ +location: clients/tests/test-client.py:665:test_001()/19 +cmd: $NMCLI --mode tabular --terse general permissions +lang: C +returncode: 0 +stdout: 899 bytes +>>> +org.freedesktop.NetworkManager.enable-disable-network:yes +org.freedesktop.NetworkManager.enable-disable-wifi:yes +org.freedesktop.NetworkManager.enable-disable-wwan:yes +org.freedesktop.NetworkManager.enable-disable-wimax:yes +org.freedesktop.NetworkManager.sleep-wake:no +org.freedesktop.NetworkManager.network-control:yes +org.freedesktop.NetworkManager.wifi.share.protected:yes +org.freedesktop.NetworkManager.wifi.share.open:yes +org.freedesktop.NetworkManager.settings.modify.system:yes +org.freedesktop.NetworkManager.settings.modify.own:yes +org.freedesktop.NetworkManager.settings.modify.hostname:yes +org.freedesktop.NetworkManager.settings.modify.global-dns:no +org.freedesktop.NetworkManager.reload:no +org.freedesktop.NetworkManager.checkpoint-rollback:unknown +org.freedesktop.NetworkManager.enable-disable-statistics:unknown +org.freedesktop.NetworkManager.enable-disable-connectivity-check:unknown + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_001-020.expected b/clients/tests/test-client.check-on-disk/test_001-020.expected new file mode 100644 index 00000000..b0987d67 --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_001-020.expected @@ -0,0 +1,28 @@ +location: clients/tests/test-client.py:665:test_001()/20 +cmd: $NMCLI --mode tabular --terse general permissions +lang: pl_PL.UTF-8 +returncode: 0 +stdout: 899 bytes +>>> +org.freedesktop.NetworkManager.enable-disable-network:yes +org.freedesktop.NetworkManager.enable-disable-wifi:yes +org.freedesktop.NetworkManager.enable-disable-wwan:yes +org.freedesktop.NetworkManager.enable-disable-wimax:yes +org.freedesktop.NetworkManager.sleep-wake:no +org.freedesktop.NetworkManager.network-control:yes +org.freedesktop.NetworkManager.wifi.share.protected:yes +org.freedesktop.NetworkManager.wifi.share.open:yes +org.freedesktop.NetworkManager.settings.modify.system:yes +org.freedesktop.NetworkManager.settings.modify.own:yes +org.freedesktop.NetworkManager.settings.modify.hostname:yes +org.freedesktop.NetworkManager.settings.modify.global-dns:no +org.freedesktop.NetworkManager.reload:no +org.freedesktop.NetworkManager.checkpoint-rollback:unknown +org.freedesktop.NetworkManager.enable-disable-statistics:unknown +org.freedesktop.NetworkManager.enable-disable-connectivity-check:unknown + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_001-021.expected b/clients/tests/test-client.check-on-disk/test_001-021.expected new file mode 100644 index 00000000..eb082c02 --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_001-021.expected @@ -0,0 +1,44 @@ +location: clients/tests/test-client.py:665:test_001()/21 +cmd: $NMCLI --mode multiline general permissions +lang: C +returncode: 0 +stdout: 2179 bytes +>>> +PERMISSION: org.freedesktop.NetworkManager.enable-disable-network +VALUE: yes +PERMISSION: org.freedesktop.NetworkManager.enable-disable-wifi +VALUE: yes +PERMISSION: org.freedesktop.NetworkManager.enable-disable-wwan +VALUE: yes +PERMISSION: org.freedesktop.NetworkManager.enable-disable-wimax +VALUE: yes +PERMISSION: org.freedesktop.NetworkManager.sleep-wake +VALUE: no +PERMISSION: org.freedesktop.NetworkManager.network-control +VALUE: yes +PERMISSION: org.freedesktop.NetworkManager.wifi.share.protected +VALUE: yes +PERMISSION: org.freedesktop.NetworkManager.wifi.share.open +VALUE: yes +PERMISSION: org.freedesktop.NetworkManager.settings.modify.system +VALUE: yes +PERMISSION: org.freedesktop.NetworkManager.settings.modify.own +VALUE: yes +PERMISSION: org.freedesktop.NetworkManager.settings.modify.hostname +VALUE: yes +PERMISSION: org.freedesktop.NetworkManager.settings.modify.global-dns +VALUE: no +PERMISSION: org.freedesktop.NetworkManager.reload +VALUE: no +PERMISSION: org.freedesktop.NetworkManager.checkpoint-rollback +VALUE: unknown +PERMISSION: org.freedesktop.NetworkManager.enable-disable-statistics +VALUE: unknown +PERMISSION: org.freedesktop.NetworkManager.enable-disable-connectivity-check +VALUE: unknown + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_001-022.expected b/clients/tests/test-client.check-on-disk/test_001-022.expected new file mode 100644 index 00000000..df002053 --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_001-022.expected @@ -0,0 +1,44 @@ +location: clients/tests/test-client.py:665:test_001()/22 +cmd: $NMCLI --mode multiline general permissions +lang: pl_PL.UTF-8 +returncode: 0 +stdout: 2185 bytes +>>> +PERMISSION: org.freedesktop.NetworkManager.enable-disable-network +VALUE: tak +PERMISSION: org.freedesktop.NetworkManager.enable-disable-wifi +VALUE: tak +PERMISSION: org.freedesktop.NetworkManager.enable-disable-wwan +VALUE: tak +PERMISSION: org.freedesktop.NetworkManager.enable-disable-wimax +VALUE: tak +PERMISSION: org.freedesktop.NetworkManager.sleep-wake +VALUE: nie +PERMISSION: org.freedesktop.NetworkManager.network-control +VALUE: tak +PERMISSION: org.freedesktop.NetworkManager.wifi.share.protected +VALUE: tak +PERMISSION: org.freedesktop.NetworkManager.wifi.share.open +VALUE: tak +PERMISSION: org.freedesktop.NetworkManager.settings.modify.system +VALUE: tak +PERMISSION: org.freedesktop.NetworkManager.settings.modify.own +VALUE: tak +PERMISSION: org.freedesktop.NetworkManager.settings.modify.hostname +VALUE: tak +PERMISSION: org.freedesktop.NetworkManager.settings.modify.global-dns +VALUE: nie +PERMISSION: org.freedesktop.NetworkManager.reload +VALUE: nie +PERMISSION: org.freedesktop.NetworkManager.checkpoint-rollback +VALUE: nieznane +PERMISSION: org.freedesktop.NetworkManager.enable-disable-statistics +VALUE: nieznane +PERMISSION: org.freedesktop.NetworkManager.enable-disable-connectivity-check +VALUE: nieznane + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_001-023.expected b/clients/tests/test-client.check-on-disk/test_001-023.expected new file mode 100644 index 00000000..55376eb9 --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_001-023.expected @@ -0,0 +1,63 @@ +location: clients/tests/test-client.py:665:test_001()/23 +cmd: $NMCLI --mode multiline --pretty general permissions +lang: C +returncode: 0 +stdout: 3672 bytes +>>> +=============================================================================== + NetworkManager permissions +=============================================================================== +PERMISSION: org.freedesktop.NetworkManager.enable-disable-network +VALUE: yes +------------------------------------------------------------------------------- +PERMISSION: org.freedesktop.NetworkManager.enable-disable-wifi +VALUE: yes +------------------------------------------------------------------------------- +PERMISSION: org.freedesktop.NetworkManager.enable-disable-wwan +VALUE: yes +------------------------------------------------------------------------------- +PERMISSION: org.freedesktop.NetworkManager.enable-disable-wimax +VALUE: yes +------------------------------------------------------------------------------- +PERMISSION: org.freedesktop.NetworkManager.sleep-wake +VALUE: no +------------------------------------------------------------------------------- +PERMISSION: org.freedesktop.NetworkManager.network-control +VALUE: yes +------------------------------------------------------------------------------- +PERMISSION: org.freedesktop.NetworkManager.wifi.share.protected +VALUE: yes +------------------------------------------------------------------------------- +PERMISSION: org.freedesktop.NetworkManager.wifi.share.open +VALUE: yes +------------------------------------------------------------------------------- +PERMISSION: org.freedesktop.NetworkManager.settings.modify.system +VALUE: yes +------------------------------------------------------------------------------- +PERMISSION: org.freedesktop.NetworkManager.settings.modify.own +VALUE: yes +------------------------------------------------------------------------------- +PERMISSION: org.freedesktop.NetworkManager.settings.modify.hostname +VALUE: yes +------------------------------------------------------------------------------- +PERMISSION: org.freedesktop.NetworkManager.settings.modify.global-dns +VALUE: no +------------------------------------------------------------------------------- +PERMISSION: org.freedesktop.NetworkManager.reload +VALUE: no +------------------------------------------------------------------------------- +PERMISSION: org.freedesktop.NetworkManager.checkpoint-rollback +VALUE: unknown +------------------------------------------------------------------------------- +PERMISSION: org.freedesktop.NetworkManager.enable-disable-statistics +VALUE: unknown +------------------------------------------------------------------------------- +PERMISSION: org.freedesktop.NetworkManager.enable-disable-connectivity-check +VALUE: unknown +------------------------------------------------------------------------------- + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_001-024.expected b/clients/tests/test-client.check-on-disk/test_001-024.expected new file mode 100644 index 00000000..10b3b04c --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_001-024.expected @@ -0,0 +1,63 @@ +location: clients/tests/test-client.py:665:test_001()/24 +cmd: $NMCLI --mode multiline --pretty general permissions +lang: pl_PL.UTF-8 +returncode: 0 +stdout: 3683 bytes +>>> +=============================================================================== + Uprawnienia usługi NetworkManager +=============================================================================== +PERMISSION: org.freedesktop.NetworkManager.enable-disable-network +VALUE: tak +------------------------------------------------------------------------------- +PERMISSION: org.freedesktop.NetworkManager.enable-disable-wifi +VALUE: tak +------------------------------------------------------------------------------- +PERMISSION: org.freedesktop.NetworkManager.enable-disable-wwan +VALUE: tak +------------------------------------------------------------------------------- +PERMISSION: org.freedesktop.NetworkManager.enable-disable-wimax +VALUE: tak +------------------------------------------------------------------------------- +PERMISSION: org.freedesktop.NetworkManager.sleep-wake +VALUE: nie +------------------------------------------------------------------------------- +PERMISSION: org.freedesktop.NetworkManager.network-control +VALUE: tak +------------------------------------------------------------------------------- +PERMISSION: org.freedesktop.NetworkManager.wifi.share.protected +VALUE: tak +------------------------------------------------------------------------------- +PERMISSION: org.freedesktop.NetworkManager.wifi.share.open +VALUE: tak +------------------------------------------------------------------------------- +PERMISSION: org.freedesktop.NetworkManager.settings.modify.system +VALUE: tak +------------------------------------------------------------------------------- +PERMISSION: org.freedesktop.NetworkManager.settings.modify.own +VALUE: tak +------------------------------------------------------------------------------- +PERMISSION: org.freedesktop.NetworkManager.settings.modify.hostname +VALUE: tak +------------------------------------------------------------------------------- +PERMISSION: org.freedesktop.NetworkManager.settings.modify.global-dns +VALUE: nie +------------------------------------------------------------------------------- +PERMISSION: org.freedesktop.NetworkManager.reload +VALUE: nie +------------------------------------------------------------------------------- +PERMISSION: org.freedesktop.NetworkManager.checkpoint-rollback +VALUE: nieznane +------------------------------------------------------------------------------- +PERMISSION: org.freedesktop.NetworkManager.enable-disable-statistics +VALUE: nieznane +------------------------------------------------------------------------------- +PERMISSION: org.freedesktop.NetworkManager.enable-disable-connectivity-check +VALUE: nieznane +------------------------------------------------------------------------------- + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_001-025.expected b/clients/tests/test-client.check-on-disk/test_001-025.expected new file mode 100644 index 00000000..687e62bf --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_001-025.expected @@ -0,0 +1,44 @@ +location: clients/tests/test-client.py:665:test_001()/25 +cmd: $NMCLI --mode multiline --terse general permissions +lang: C +returncode: 0 +stdout: 1171 bytes +>>> +PERMISSION:org.freedesktop.NetworkManager.enable-disable-network +VALUE:yes +PERMISSION:org.freedesktop.NetworkManager.enable-disable-wifi +VALUE:yes +PERMISSION:org.freedesktop.NetworkManager.enable-disable-wwan +VALUE:yes +PERMISSION:org.freedesktop.NetworkManager.enable-disable-wimax +VALUE:yes +PERMISSION:org.freedesktop.NetworkManager.sleep-wake +VALUE:no +PERMISSION:org.freedesktop.NetworkManager.network-control +VALUE:yes +PERMISSION:org.freedesktop.NetworkManager.wifi.share.protected +VALUE:yes +PERMISSION:org.freedesktop.NetworkManager.wifi.share.open +VALUE:yes +PERMISSION:org.freedesktop.NetworkManager.settings.modify.system +VALUE:yes +PERMISSION:org.freedesktop.NetworkManager.settings.modify.own +VALUE:yes +PERMISSION:org.freedesktop.NetworkManager.settings.modify.hostname +VALUE:yes +PERMISSION:org.freedesktop.NetworkManager.settings.modify.global-dns +VALUE:no +PERMISSION:org.freedesktop.NetworkManager.reload +VALUE:no +PERMISSION:org.freedesktop.NetworkManager.checkpoint-rollback +VALUE:unknown +PERMISSION:org.freedesktop.NetworkManager.enable-disable-statistics +VALUE:unknown +PERMISSION:org.freedesktop.NetworkManager.enable-disable-connectivity-check +VALUE:unknown + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_001-026.expected b/clients/tests/test-client.check-on-disk/test_001-026.expected new file mode 100644 index 00000000..1b01d876 --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_001-026.expected @@ -0,0 +1,44 @@ +location: clients/tests/test-client.py:665:test_001()/26 +cmd: $NMCLI --mode multiline --terse general permissions +lang: pl_PL.UTF-8 +returncode: 0 +stdout: 1171 bytes +>>> +PERMISSION:org.freedesktop.NetworkManager.enable-disable-network +VALUE:yes +PERMISSION:org.freedesktop.NetworkManager.enable-disable-wifi +VALUE:yes +PERMISSION:org.freedesktop.NetworkManager.enable-disable-wwan +VALUE:yes +PERMISSION:org.freedesktop.NetworkManager.enable-disable-wimax +VALUE:yes +PERMISSION:org.freedesktop.NetworkManager.sleep-wake +VALUE:no +PERMISSION:org.freedesktop.NetworkManager.network-control +VALUE:yes +PERMISSION:org.freedesktop.NetworkManager.wifi.share.protected +VALUE:yes +PERMISSION:org.freedesktop.NetworkManager.wifi.share.open +VALUE:yes +PERMISSION:org.freedesktop.NetworkManager.settings.modify.system +VALUE:yes +PERMISSION:org.freedesktop.NetworkManager.settings.modify.own +VALUE:yes +PERMISSION:org.freedesktop.NetworkManager.settings.modify.hostname +VALUE:yes +PERMISSION:org.freedesktop.NetworkManager.settings.modify.global-dns +VALUE:no +PERMISSION:org.freedesktop.NetworkManager.reload +VALUE:no +PERMISSION:org.freedesktop.NetworkManager.checkpoint-rollback +VALUE:unknown +PERMISSION:org.freedesktop.NetworkManager.enable-disable-statistics +VALUE:unknown +PERMISSION:org.freedesktop.NetworkManager.enable-disable-connectivity-check +VALUE:unknown + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_002-001.expected b/clients/tests/test-client.check-on-disk/test_002-001.expected new file mode 100644 index 00000000..5f3d7d6a --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_002-001.expected @@ -0,0 +1,18 @@ +location: clients/tests/test-client.py:670:test_002()/1 +cmd: $NMCLI d +lang: C +returncode: 0 +stdout: 258 bytes +>>> +DEVICE TYPE STATE CONNECTION +eth0 ethernet unavailable -- +eth1 ethernet unavailable -- +wlan0 wifi unavailable -- +wlan1 wifi unavailable -- +wlan1 wifi unavailable -- + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_002-002.expected b/clients/tests/test-client.check-on-disk/test_002-002.expected new file mode 100644 index 00000000..3bdc45e4 --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_002-002.expected @@ -0,0 +1,18 @@ +location: clients/tests/test-client.py:670:test_002()/2 +cmd: $NMCLI d +lang: pl_PL.UTF-8 +returncode: 0 +stdout: 263 bytes +>>> +DEVICE TYPE STATE CONNECTION +eth0 ethernet niedostępne -- +eth1 ethernet niedostępne -- +wlan0 wifi niedostępne -- +wlan1 wifi niedostępne -- +wlan1 wifi niedostępne -- + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_002-003.expected b/clients/tests/test-client.check-on-disk/test_002-003.expected new file mode 100644 index 00000000..e2e56101 --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_002-003.expected @@ -0,0 +1,18 @@ +location: clients/tests/test-client.py:672:test_002()/3 +cmd: $NMCLI -f all d +lang: C +returncode: 0 +stdout: 636 bytes +>>> +DEVICE TYPE STATE DBUS-PATH CONNECTION CON-UUID CON-PATH +eth0 ethernet unavailable /org/freedesktop/NetworkManager/Devices/1 -- -- -- +eth1 ethernet unavailable /org/freedesktop/NetworkManager/Devices/2 -- -- -- +wlan0 wifi unavailable /org/freedesktop/NetworkManager/Devices/3 -- -- -- +wlan1 wifi unavailable /org/freedesktop/NetworkManager/Devices/4 -- -- -- +wlan1 wifi unavailable /org/freedesktop/NetworkManager/Devices/5 -- -- -- + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_002-004.expected b/clients/tests/test-client.check-on-disk/test_002-004.expected new file mode 100644 index 00000000..0e884ed0 --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_002-004.expected @@ -0,0 +1,18 @@ +location: clients/tests/test-client.py:672:test_002()/4 +cmd: $NMCLI -f all d +lang: pl_PL.UTF-8 +returncode: 0 +stdout: 641 bytes +>>> +DEVICE TYPE STATE DBUS-PATH CONNECTION CON-UUID CON-PATH +eth0 ethernet niedostępne /org/freedesktop/NetworkManager/Devices/1 -- -- -- +eth1 ethernet niedostępne /org/freedesktop/NetworkManager/Devices/2 -- -- -- +wlan0 wifi niedostępne /org/freedesktop/NetworkManager/Devices/3 -- -- -- +wlan1 wifi niedostępne /org/freedesktop/NetworkManager/Devices/4 -- -- -- +wlan1 wifi niedostępne /org/freedesktop/NetworkManager/Devices/5 -- -- -- + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_002-005.expected b/clients/tests/test-client.check-on-disk/test_002-005.expected new file mode 100644 index 00000000..3d1440ea --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_002-005.expected @@ -0,0 +1,39 @@ +location: clients/tests/test-client.py:674:test_002()/5 +cmd: $NMCLI +lang: C +returncode: 0 +stdout: 621 bytes +>>> +eth0: unavailable + "eth0" + ethernet (virtual), 72:41:AB:90:41:5D, hw + +eth1: unavailable + "eth1" + ethernet (virtual), 1F:E6:D1:E6:1D:53, hw + +wlan0: unavailable + "wlan0" + wifi (virtual), 5A:88:5E:B6:90:40, hw + +wlan1: unavailable + "wlan1" + wifi (virtual), 7C:D4:69:31:67:0B, hw + +wlan1: unavailable + "wlan1" + wifi (virtual), 41:21:6B:F3:C9:4A, hw + +DNS configuration: + servers: 1.2.3.4 5.6.7.8 + +Use "nmcli device show" to get complete information about known devices and +"nmcli connection show" to get an overview on active connection profiles. + +Consult nmcli(1) and nmcli-examples(5) manual pages for complete usage details. + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_002-006.expected b/clients/tests/test-client.check-on-disk/test_002-006.expected new file mode 100644 index 00000000..a676f62d --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_002-006.expected @@ -0,0 +1,41 @@ +location: clients/tests/test-client.py:674:test_002()/6 +cmd: $NMCLI +lang: pl_PL.UTF-8 +returncode: 0 +stdout: 684 bytes +>>> +eth0: niedostępne + "eth0" + ethernet (virtual), 72:41:AB:90:41:5D, sprzęt + +eth1: niedostępne + "eth1" + ethernet (virtual), 1F:E6:D1:E6:1D:53, sprzęt + +wlan0: niedostępne + "wlan0" + wifi (virtual), 5A:88:5E:B6:90:40, sprzęt + +wlan1: niedostępne + "wlan1" + wifi (virtual), 7C:D4:69:31:67:0B, sprzęt + +wlan1: niedostępne + "wlan1" + wifi (virtual), 41:21:6B:F3:C9:4A, sprzęt + +DNS configuration: + servers: 1.2.3.4 5.6.7.8 + +Polecenie „nmcli device show” wyświetli pełne informacje o znanych +urządzeniach, a „nmcli connection show” wyświetli przegląd aktywnych +profili połączeń. + +Strony podręcznika nmcli(1) i nmcli-examples(5) zawierają pełne informacje +o użyciu. + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_002-007.expected b/clients/tests/test-client.check-on-disk/test_002-007.expected new file mode 100644 index 00000000..780e7f6e --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_002-007.expected @@ -0,0 +1,36 @@ +location: clients/tests/test-client.py:676:test_002()/7 +cmd: $NMCLI -f AP -mode multiline d show wlan0 +lang: C +returncode: 0 +stdout: 1107 bytes +>>> +AP[1].IN-USE: +AP[1].SSID: wlan0-ap-3 +AP[1].MODE: Infra +AP[1].CHAN: 1 +AP[1].RATE: 54 Mbit/s +AP[1].SIGNAL: 88 +AP[1].BARS: **** +AP[1].SECURITY: WPA1 WPA2 +AP[2].IN-USE: +AP[2].SSID: wlan0-ap-2 +AP[2].MODE: Infra +AP[2].CHAN: 1 +AP[2].RATE: 54 Mbit/s +AP[2].SIGNAL: 61 +AP[2].BARS: *** +AP[2].SECURITY: WPA1 WPA2 +AP[3].IN-USE: +AP[3].SSID: wlan0-ap-1 +AP[3].MODE: Infra +AP[3].CHAN: 1 +AP[3].RATE: 54 Mbit/s +AP[3].SIGNAL: 29 +AP[3].BARS: * +AP[3].SECURITY: WPA1 WPA2 + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_002-008.expected b/clients/tests/test-client.check-on-disk/test_002-008.expected new file mode 100644 index 00000000..c605e8e7 --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_002-008.expected @@ -0,0 +1,36 @@ +location: clients/tests/test-client.py:676:test_002()/8 +cmd: $NMCLI -f AP -mode multiline d show wlan0 +lang: pl_PL.UTF-8 +returncode: 0 +stdout: 1134 bytes +>>> +AP[1].IN-USE: +AP[1].SSID: wlan0-ap-3 +AP[1].MODE: Infrastruktura +AP[1].CHAN: 1 +AP[1].RATE: 54 Mb/s +AP[1].SIGNAL: 88 +AP[1].BARS: **** +AP[1].SECURITY: WPA1 WPA2 +AP[2].IN-USE: +AP[2].SSID: wlan0-ap-2 +AP[2].MODE: Infrastruktura +AP[2].CHAN: 1 +AP[2].RATE: 54 Mb/s +AP[2].SIGNAL: 61 +AP[2].BARS: *** +AP[2].SECURITY: WPA1 WPA2 +AP[3].IN-USE: +AP[3].SSID: wlan0-ap-1 +AP[3].MODE: Infrastruktura +AP[3].CHAN: 1 +AP[3].RATE: 54 Mb/s +AP[3].SIGNAL: 29 +AP[3].BARS: * +AP[3].SECURITY: WPA1 WPA2 + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_002-009.expected b/clients/tests/test-client.check-on-disk/test_002-009.expected new file mode 100644 index 00000000..bd1bbe90 --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_002-009.expected @@ -0,0 +1,42 @@ +location: clients/tests/test-client.py:677:test_002()/9 +cmd: $NMCLI -f AP -mode multiline -p d show wlan0 +lang: C +returncode: 0 +stdout: 1558 bytes +>>> +=============================================================================== + Device details (wlan0) +=============================================================================== +AP[1].IN-USE: +AP[1].SSID: wlan0-ap-3 +AP[1].MODE: Infra +AP[1].CHAN: 1 +AP[1].RATE: 54 Mbit/s +AP[1].SIGNAL: 88 +AP[1].BARS: **** +AP[1].SECURITY: WPA1 WPA2 +------------------------------------------------------------------------------- +AP[2].IN-USE: +AP[2].SSID: wlan0-ap-2 +AP[2].MODE: Infra +AP[2].CHAN: 1 +AP[2].RATE: 54 Mbit/s +AP[2].SIGNAL: 61 +AP[2].BARS: *** +AP[2].SECURITY: WPA1 WPA2 +------------------------------------------------------------------------------- +AP[3].IN-USE: +AP[3].SSID: wlan0-ap-1 +AP[3].MODE: Infra +AP[3].CHAN: 1 +AP[3].RATE: 54 Mbit/s +AP[3].SIGNAL: 29 +AP[3].BARS: * +AP[3].SECURITY: WPA1 WPA2 +------------------------------------------------------------------------------- + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_002-010.expected b/clients/tests/test-client.check-on-disk/test_002-010.expected new file mode 100644 index 00000000..d3c06c7b --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_002-010.expected @@ -0,0 +1,42 @@ +location: clients/tests/test-client.py:677:test_002()/10 +cmd: $NMCLI -f AP -mode multiline -p d show wlan0 +lang: pl_PL.UTF-8 +returncode: 0 +stdout: 1592 bytes +>>> +=============================================================================== + Informacje o urządzeniu (wlan0) +=============================================================================== +AP[1].IN-USE: +AP[1].SSID: wlan0-ap-3 +AP[1].MODE: Infrastruktura +AP[1].CHAN: 1 +AP[1].RATE: 54 Mb/s +AP[1].SIGNAL: 88 +AP[1].BARS: **** +AP[1].SECURITY: WPA1 WPA2 +------------------------------------------------------------------------------- +AP[2].IN-USE: +AP[2].SSID: wlan0-ap-2 +AP[2].MODE: Infrastruktura +AP[2].CHAN: 1 +AP[2].RATE: 54 Mb/s +AP[2].SIGNAL: 61 +AP[2].BARS: *** +AP[2].SECURITY: WPA1 WPA2 +------------------------------------------------------------------------------- +AP[3].IN-USE: +AP[3].SSID: wlan0-ap-1 +AP[3].MODE: Infrastruktura +AP[3].CHAN: 1 +AP[3].RATE: 54 Mb/s +AP[3].SIGNAL: 29 +AP[3].BARS: * +AP[3].SECURITY: WPA1 WPA2 +------------------------------------------------------------------------------- + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_002-011.expected b/clients/tests/test-client.check-on-disk/test_002-011.expected new file mode 100644 index 00000000..e943c114 --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_002-011.expected @@ -0,0 +1,36 @@ +location: clients/tests/test-client.py:678:test_002()/11 +cmd: $NMCLI -f AP -mode multiline -t d show wlan0 +lang: C +returncode: 0 +stdout: 435 bytes +>>> +AP[1].IN-USE: +AP[1].SSID:wlan0-ap-3 +AP[1].MODE:Infra +AP[1].CHAN:1 +AP[1].RATE:54 Mbit/s +AP[1].SIGNAL:88 +AP[1].BARS:**** +AP[1].SECURITY:WPA1 WPA2 +AP[2].IN-USE: +AP[2].SSID:wlan0-ap-2 +AP[2].MODE:Infra +AP[2].CHAN:1 +AP[2].RATE:54 Mbit/s +AP[2].SIGNAL:61 +AP[2].BARS:*** +AP[2].SECURITY:WPA1 WPA2 +AP[3].IN-USE: +AP[3].SSID:wlan0-ap-1 +AP[3].MODE:Infra +AP[3].CHAN:1 +AP[3].RATE:54 Mbit/s +AP[3].SIGNAL:29 +AP[3].BARS:* +AP[3].SECURITY:WPA1 WPA2 + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_002-012.expected b/clients/tests/test-client.check-on-disk/test_002-012.expected new file mode 100644 index 00000000..6e3e5d56 --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_002-012.expected @@ -0,0 +1,36 @@ +location: clients/tests/test-client.py:678:test_002()/12 +cmd: $NMCLI -f AP -mode multiline -t d show wlan0 +lang: pl_PL.UTF-8 +returncode: 0 +stdout: 462 bytes +>>> +AP[1].IN-USE: +AP[1].SSID:wlan0-ap-3 +AP[1].MODE:Infrastruktura +AP[1].CHAN:1 +AP[1].RATE:54 Mb/s +AP[1].SIGNAL:88 +AP[1].BARS:**** +AP[1].SECURITY:WPA1 WPA2 +AP[2].IN-USE: +AP[2].SSID:wlan0-ap-2 +AP[2].MODE:Infrastruktura +AP[2].CHAN:1 +AP[2].RATE:54 Mb/s +AP[2].SIGNAL:61 +AP[2].BARS:*** +AP[2].SECURITY:WPA1 WPA2 +AP[3].IN-USE: +AP[3].SSID:wlan0-ap-1 +AP[3].MODE:Infrastruktura +AP[3].CHAN:1 +AP[3].RATE:54 Mb/s +AP[3].SIGNAL:29 +AP[3].BARS:* +AP[3].SECURITY:WPA1 WPA2 + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_002-013.expected b/clients/tests/test-client.check-on-disk/test_002-013.expected new file mode 100644 index 00000000..a649addd --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_002-013.expected @@ -0,0 +1,16 @@ +location: clients/tests/test-client.py:679:test_002()/13 +cmd: $NMCLI -f AP -mode tabular d show wlan0 +lang: C +returncode: 0 +stdout: 304 bytes +>>> +NAME IN-USE SSID MODE CHAN RATE SIGNAL BARS SECURITY +AP[1] wlan0-ap-3 Infra 1 54 Mbit/s 88 **** WPA1 WPA2 +AP[2] wlan0-ap-2 Infra 1 54 Mbit/s 61 *** WPA1 WPA2 +AP[3] wlan0-ap-1 Infra 1 54 Mbit/s 29 * WPA1 WPA2 + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_002-014.expected b/clients/tests/test-client.check-on-disk/test_002-014.expected new file mode 100644 index 00000000..d2a8a667 --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_002-014.expected @@ -0,0 +1,16 @@ +location: clients/tests/test-client.py:679:test_002()/14 +cmd: $NMCLI -f AP -mode tabular d show wlan0 +lang: pl_PL.UTF-8 +returncode: 0 +stdout: 338 bytes +>>> +NAME IN-USE SSID MODE CHAN RATE SIGNAL BARS SECURITY +AP[1] wlan0-ap-3 Infrastruktura 1 54 Mb/s 88 **** WPA1 WPA2 +AP[2] wlan0-ap-2 Infrastruktura 1 54 Mb/s 61 *** WPA1 WPA2 +AP[3] wlan0-ap-1 Infrastruktura 1 54 Mb/s 29 * WPA1 WPA2 + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_002-015.expected b/clients/tests/test-client.check-on-disk/test_002-015.expected new file mode 100644 index 00000000..1b28741f --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_002-015.expected @@ -0,0 +1,20 @@ +location: clients/tests/test-client.py:680:test_002()/15 +cmd: $NMCLI -f AP -mode tabular -p d show wlan0 +lang: C +returncode: 0 +stdout: 460 bytes +>>> +========================== + Device details (wlan0) +========================== +NAME IN-USE SSID MODE CHAN RATE SIGNAL BARS SECURITY +---------------------------------------------------------------------------- +AP[1] wlan0-ap-3 Infra 1 54 Mbit/s 88 **** WPA1 WPA2 +AP[2] wlan0-ap-2 Infra 1 54 Mbit/s 61 *** WPA1 WPA2 +AP[3] wlan0-ap-1 Infra 1 54 Mbit/s 29 * WPA1 WPA2 + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_002-016.expected b/clients/tests/test-client.check-on-disk/test_002-016.expected new file mode 100644 index 00000000..a5970447 --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_002-016.expected @@ -0,0 +1,20 @@ +location: clients/tests/test-client.py:680:test_002()/16 +cmd: $NMCLI -f AP -mode tabular -p d show wlan0 +lang: pl_PL.UTF-8 +returncode: 0 +stdout: 530 bytes +>>> +=================================== + Informacje o urządzeniu (wlan0) +=================================== +NAME IN-USE SSID MODE CHAN RATE SIGNAL BARS SECURITY +----------------------------------------------------------------------------------- +AP[1] wlan0-ap-3 Infrastruktura 1 54 Mb/s 88 **** WPA1 WPA2 +AP[2] wlan0-ap-2 Infrastruktura 1 54 Mb/s 61 *** WPA1 WPA2 +AP[3] wlan0-ap-1 Infrastruktura 1 54 Mb/s 29 * WPA1 WPA2 + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_002-017.expected b/clients/tests/test-client.check-on-disk/test_002-017.expected new file mode 100644 index 00000000..61499b6d --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_002-017.expected @@ -0,0 +1,15 @@ +location: clients/tests/test-client.py:681:test_002()/17 +cmd: $NMCLI -f AP -mode tabular -t d show wlan0 +lang: C +returncode: 0 +stdout: 165 bytes +>>> +AP[1]: :wlan0-ap-3:Infra:1:54 Mbit/s:88:****:WPA1 WPA2 +AP[2]: :wlan0-ap-2:Infra:1:54 Mbit/s:61:*** :WPA1 WPA2 +AP[3]: :wlan0-ap-1:Infra:1:54 Mbit/s:29:* :WPA1 WPA2 + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_002-018.expected b/clients/tests/test-client.check-on-disk/test_002-018.expected new file mode 100644 index 00000000..bbac7a72 --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_002-018.expected @@ -0,0 +1,15 @@ +location: clients/tests/test-client.py:681:test_002()/18 +cmd: $NMCLI -f AP -mode tabular -t d show wlan0 +lang: pl_PL.UTF-8 +returncode: 0 +stdout: 192 bytes +>>> +AP[1]: :wlan0-ap-3:Infrastruktura:1:54 Mb/s:88:****:WPA1 WPA2 +AP[2]: :wlan0-ap-2:Infrastruktura:1:54 Mb/s:61:*** :WPA1 WPA2 +AP[3]: :wlan0-ap-1:Infrastruktura:1:54 Mb/s:29:* :WPA1 WPA2 + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_002-019.expected b/clients/tests/test-client.check-on-disk/test_002-019.expected new file mode 100644 index 00000000..0bcc5e9d --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_002-019.expected @@ -0,0 +1,21 @@ +location: clients/tests/test-client.py:683:test_002()/19 +cmd: $NMCLI -f ALL d wifi +lang: C +returncode: 0 +stdout: 1840 bytes +>>> +NAME SSID SSID-HEX BSSID MODE CHAN FREQ RATE SIGNAL BARS SECURITY WPA-FLAGS RSN-FLAGS DEVICE ACTIVE IN-USE DBUS-PATH +AP[1] wlan0-ap-3 776C616E302D61702D33 53:8C:FC:BD:7D:2B Infra 1 2412 MHz 54 Mbit/s 88 **** WPA1 WPA2 pair_tkip pair_ccmp group_tkip group_ccmp psk pair_tkip pair_ccmp group_tkip group_ccmp psk wlan0 no /org/freedesktop/NetworkManager/AccessPoint/3 +AP[2] wlan0-ap-2 776C616E302D61702D32 A1:A2:78:A7:C5:D5 Infra 1 2412 MHz 54 Mbit/s 61 *** WPA1 WPA2 pair_tkip pair_ccmp group_tkip group_ccmp psk pair_tkip pair_ccmp group_tkip group_ccmp psk wlan0 no /org/freedesktop/NetworkManager/AccessPoint/2 +AP[3] wlan0-ap-1 776C616E302D61702D31 81:28:C5:C2:E5:15 Infra 1 2412 MHz 54 Mbit/s 29 * WPA1 WPA2 pair_tkip pair_ccmp group_tkip group_ccmp psk pair_tkip pair_ccmp group_tkip group_ccmp psk wlan0 no /org/freedesktop/NetworkManager/AccessPoint/1 + +NAME SSID SSID-HEX BSSID MODE CHAN FREQ RATE SIGNAL BARS SECURITY WPA-FLAGS RSN-FLAGS DEVICE ACTIVE IN-USE DBUS-PATH +AP[1] wlan1-ap-4 776C616E312D61702D34 EA:62:1C:BD:C0:8F Infra 1 2412 MHz 54 Mbit/s 34 ** WPA1 WPA2 pair_tkip pair_ccmp group_tkip group_ccmp psk pair_tkip pair_ccmp group_tkip group_ccmp psk wlan1 no /org/freedesktop/NetworkManager/AccessPoint/4 + +NAME SSID SSID-HEX BSSID MODE CHAN FREQ RATE SIGNAL BARS SECURITY WPA-FLAGS RSN-FLAGS DEVICE ACTIVE IN-USE DBUS-PATH + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_002-020.expected b/clients/tests/test-client.check-on-disk/test_002-020.expected new file mode 100644 index 00000000..f433340e --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_002-020.expected @@ -0,0 +1,21 @@ +location: clients/tests/test-client.py:683:test_002()/20 +cmd: $NMCLI -f ALL d wifi +lang: pl_PL.UTF-8 +returncode: 0 +stdout: 1898 bytes +>>> +NAME SSID SSID-HEX BSSID MODE CHAN FREQ RATE SIGNAL BARS SECURITY WPA-FLAGS RSN-FLAGS DEVICE ACTIVE IN-USE DBUS-PATH +AP[1] wlan0-ap-3 776C616E302D61702D33 53:8C:FC:BD:7D:2B Infrastruktura 1 2412 MHz 54 Mb/s 88 **** WPA1 WPA2 pair_tkip pair_ccmp group_tkip group_ccmp psk pair_tkip pair_ccmp group_tkip group_ccmp psk wlan0 nie /org/freedesktop/NetworkManager/AccessPoint/3 +AP[2] wlan0-ap-2 776C616E302D61702D32 A1:A2:78:A7:C5:D5 Infrastruktura 1 2412 MHz 54 Mb/s 61 *** WPA1 WPA2 pair_tkip pair_ccmp group_tkip group_ccmp psk pair_tkip pair_ccmp group_tkip group_ccmp psk wlan0 nie /org/freedesktop/NetworkManager/AccessPoint/2 +AP[3] wlan0-ap-1 776C616E302D61702D31 81:28:C5:C2:E5:15 Infrastruktura 1 2412 MHz 54 Mb/s 29 * WPA1 WPA2 pair_tkip pair_ccmp group_tkip group_ccmp psk pair_tkip pair_ccmp group_tkip group_ccmp psk wlan0 nie /org/freedesktop/NetworkManager/AccessPoint/1 + +NAME SSID SSID-HEX BSSID MODE CHAN FREQ RATE SIGNAL BARS SECURITY WPA-FLAGS RSN-FLAGS DEVICE ACTIVE IN-USE DBUS-PATH +AP[1] wlan1-ap-4 776C616E312D61702D34 EA:62:1C:BD:C0:8F Infrastruktura 1 2412 MHz 54 Mb/s 34 ** WPA1 WPA2 pair_tkip pair_ccmp group_tkip group_ccmp psk pair_tkip pair_ccmp group_tkip group_ccmp psk wlan1 nie /org/freedesktop/NetworkManager/AccessPoint/4 + +NAME SSID SSID-HEX BSSID MODE CHAN FREQ RATE SIGNAL BARS SECURITY WPA-FLAGS RSN-FLAGS DEVICE ACTIVE IN-USE DBUS-PATH + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_002-021.expected b/clients/tests/test-client.check-on-disk/test_002-021.expected new file mode 100644 index 00000000..8dd7f647 --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_002-021.expected @@ -0,0 +1,14 @@ +location: clients/tests/test-client.py:685:test_002()/21 +cmd: $NMCLI c +lang: C +returncode: 0 +stdout: 126 bytes +>>> +NAME UUID TYPE DEVICE +con-1 5fcfd6d7-1e63-3332-8826-a7eda103792d ethernet -- + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_002-022.expected b/clients/tests/test-client.check-on-disk/test_002-022.expected new file mode 100644 index 00000000..25d7bed2 --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_002-022.expected @@ -0,0 +1,14 @@ +location: clients/tests/test-client.py:685:test_002()/22 +cmd: $NMCLI c +lang: pl_PL.UTF-8 +returncode: 0 +stdout: 126 bytes +>>> +NAME UUID TYPE DEVICE +con-1 5fcfd6d7-1e63-3332-8826-a7eda103792d ethernet -- + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_002-023.expected b/clients/tests/test-client.check-on-disk/test_002-023.expected new file mode 100644 index 00000000..43ce6419 --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_002-023.expected @@ -0,0 +1,33 @@ +location: clients/tests/test-client.py:687:test_002()/23 +cmd: $NMCLI c s con-1 +lang: C +returncode: 0 +stdout: 990 bytes +>>> +connection.id: con-1 +connection.uuid: 5fcfd6d7-1e63-3332-8826-a7eda103792d +connection.stable-id: -- +connection.type: 802-3-ethernet +connection.interface-name: -- +connection.autoconnect: yes +connection.autoconnect-priority: 0 +connection.autoconnect-retries: -1 (default) +connection.auth-retries: -1 +connection.timestamp: 0 +connection.read-only: no +connection.permissions: -- +connection.zone: -- +connection.master: -- +connection.slave-type: -- +connection.autoconnect-slaves: -1 (default) +connection.secondaries: -- +connection.gateway-ping-timeout: 0 +connection.metered: unknown +connection.lldp: default +connection.mdns: -1 (default) + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_002-024.expected b/clients/tests/test-client.check-on-disk/test_002-024.expected new file mode 100644 index 00000000..a5b7bc4a --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_002-024.expected @@ -0,0 +1,33 @@ +location: clients/tests/test-client.py:687:test_002()/24 +cmd: $NMCLI c s con-1 +lang: pl_PL.UTF-8 +returncode: 0 +stdout: 992 bytes +>>> +connection.id: con-1 +connection.uuid: 5fcfd6d7-1e63-3332-8826-a7eda103792d +connection.stable-id: -- +connection.type: 802-3-ethernet +connection.interface-name: -- +connection.autoconnect: tak +connection.autoconnect-priority: 0 +connection.autoconnect-retries: -1 (default) +connection.auth-retries: -1 +connection.timestamp: 0 +connection.read-only: nie +connection.permissions: -- +connection.zone: -- +connection.master: -- +connection.slave-type: -- +connection.autoconnect-slaves: -1 (default) +connection.secondaries: -- +connection.gateway-ping-timeout: 0 +connection.metered: nieznane +connection.lldp: default +connection.mdns: -1 (default) + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_003-001.expected b/clients/tests/test-client.check-on-disk/test_003-001.expected new file mode 100644 index 00000000..e131cb36 --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_003-001.expected @@ -0,0 +1,13 @@ +location: clients/tests/test-client.py:697:test_003()/1 +cmd: $NMCLI c add type ethernet ifname '*' con-name con-xx1 +lang: C +returncode: 0 +stdout: 80 bytes +>>> +Connection 'con-xx1' (UUID-con-xx1-REPLACED-REPLACED-REPLA) successfully added. + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_003-002.expected b/clients/tests/test-client.check-on-disk/test_003-002.expected new file mode 100644 index 00000000..9c9cfb2d --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_003-002.expected @@ -0,0 +1,15 @@ +location: clients/tests/test-client.py:700:test_003()/2 +cmd: $NMCLI c s +lang: C +returncode: 0 +stdout: 195 bytes +>>> +NAME UUID TYPE DEVICE +con-1 5fcfd6d7-1e63-3332-8826-a7eda103792d ethernet -- +con-xx1 UUID-con-xx1-REPLACED-REPLACED-REPLA ethernet -- + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_003-003.expected b/clients/tests/test-client.check-on-disk/test_003-003.expected new file mode 100644 index 00000000..882d1b4d --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_003-003.expected @@ -0,0 +1,15 @@ +location: clients/tests/test-client.py:700:test_003()/3 +cmd: $NMCLI c s +lang: pl_PL.UTF-8 +returncode: 0 +stdout: 195 bytes +>>> +NAME UUID TYPE DEVICE +con-1 5fcfd6d7-1e63-3332-8826-a7eda103792d ethernet -- +con-xx1 UUID-con-xx1-REPLACED-REPLACED-REPLA ethernet -- + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_003-004.expected b/clients/tests/test-client.check-on-disk/test_003-004.expected new file mode 100644 index 00000000..37c67f27 --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_003-004.expected @@ -0,0 +1,13 @@ +location: clients/tests/test-client.py:705:test_003()/4 +cmd: $NMCLI c add type ethernet ifname '*' +lang: C +returncode: 0 +stdout: 81 bytes +>>> +Connection 'ethernet' (UUID-ethernet-REPLACED-REPLACED-REPL) successfully added. + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_003-005.expected b/clients/tests/test-client.check-on-disk/test_003-005.expected new file mode 100644 index 00000000..15ef586b --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_003-005.expected @@ -0,0 +1,16 @@ +location: clients/tests/test-client.py:708:test_003()/5 +cmd: $NMCLI c s +lang: C +returncode: 0 +stdout: 264 bytes +>>> +NAME UUID TYPE DEVICE +con-1 5fcfd6d7-1e63-3332-8826-a7eda103792d ethernet -- +con-xx1 UUID-con-xx1-REPLACED-REPLACED-REPLA ethernet -- +ethernet UUID-ethernet-REPLACED-REPLACED-REPL ethernet -- + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_003-006.expected b/clients/tests/test-client.check-on-disk/test_003-006.expected new file mode 100644 index 00000000..cd89b202 --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_003-006.expected @@ -0,0 +1,16 @@ +location: clients/tests/test-client.py:708:test_003()/6 +cmd: $NMCLI c s +lang: pl_PL.UTF-8 +returncode: 0 +stdout: 264 bytes +>>> +NAME UUID TYPE DEVICE +con-1 5fcfd6d7-1e63-3332-8826-a7eda103792d ethernet -- +con-xx1 UUID-con-xx1-REPLACED-REPLACED-REPLA ethernet -- +ethernet UUID-ethernet-REPLACED-REPLACED-REPL ethernet -- + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_003-007.expected b/clients/tests/test-client.check-on-disk/test_003-007.expected new file mode 100644 index 00000000..c2e5a566 --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_003-007.expected @@ -0,0 +1,16 @@ +location: clients/tests/test-client.py:711:test_003()/7 +cmd: $NMCLI -f ALL c s +lang: C +returncode: 0 +stdout: 912 bytes +>>> +NAME UUID TYPE TIMESTAMP TIMESTAMP-REAL AUTOCONNECT AUTOCONNECT-PRIORITY READONLY DBUS-PATH ACTIVE DEVICE STATE ACTIVE-PATH SLAVE +con-1 5fcfd6d7-1e63-3332-8826-a7eda103792d ethernet 0 never yes 0 no /org/freedesktop/NetworkManager/Settings/Connection/1 no -- -- -- -- +con-xx1 UUID-con-xx1-REPLACED-REPLACED-REPLA ethernet 0 never yes 0 no /org/freedesktop/NetworkManager/Settings/Connection/2 no -- -- -- -- +ethernet UUID-ethernet-REPLACED-REPLACED-REPL ethernet 0 never yes 0 no /org/freedesktop/NetworkManager/Settings/Connection/3 no -- -- -- -- + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_003-008.expected b/clients/tests/test-client.check-on-disk/test_003-008.expected new file mode 100644 index 00000000..1100563f --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_003-008.expected @@ -0,0 +1,16 @@ +location: clients/tests/test-client.py:711:test_003()/8 +cmd: $NMCLI -f ALL c s +lang: pl_PL.UTF-8 +returncode: 0 +stdout: 912 bytes +>>> +NAME UUID TYPE TIMESTAMP TIMESTAMP-REAL AUTOCONNECT AUTOCONNECT-PRIORITY READONLY DBUS-PATH ACTIVE DEVICE STATE ACTIVE-PATH SLAVE +con-1 5fcfd6d7-1e63-3332-8826-a7eda103792d ethernet 0 nigdy tak 0 nie /org/freedesktop/NetworkManager/Settings/Connection/1 nie -- -- -- -- +con-xx1 UUID-con-xx1-REPLACED-REPLACED-REPLA ethernet 0 nigdy tak 0 nie /org/freedesktop/NetworkManager/Settings/Connection/2 nie -- -- -- -- +ethernet UUID-ethernet-REPLACED-REPLACED-REPL ethernet 0 nigdy tak 0 nie /org/freedesktop/NetworkManager/Settings/Connection/3 nie -- -- -- -- + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_003-009.expected b/clients/tests/test-client.check-on-disk/test_003-009.expected new file mode 100644 index 00000000..f3d9d292 --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_003-009.expected @@ -0,0 +1,22 @@ +location: clients/tests/test-client.py:715:test_003()/9 +cmd: $NMCLI --complete-args -f ALL c s '' +lang: C +returncode: 0 +stdout: 64 bytes +>>> + +--active +--order +apath +con-1 +con-xx1 +ethernet +help +id +path +uuid +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_003-010.expected b/clients/tests/test-client.check-on-disk/test_003-010.expected new file mode 100644 index 00000000..86c4dea0 --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_003-010.expected @@ -0,0 +1,22 @@ +location: clients/tests/test-client.py:715:test_003()/10 +cmd: $NMCLI --complete-args -f ALL c s '' +lang: pl_PL.UTF-8 +returncode: 0 +stdout: 64 bytes +>>> + +--active +--order +apath +con-1 +con-xx1 +ethernet +help +id +path +uuid +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_003-011.expected b/clients/tests/test-client.check-on-disk/test_003-011.expected new file mode 100644 index 00000000..3da70bbf --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_003-011.expected @@ -0,0 +1,13 @@ +location: clients/tests/test-client.py:728:test_003()/11 +cmd: $NMCLI con up ethernet ifname eth0 +lang: C +returncode: 0 +stdout: 106 bytes +>>> +Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/1) + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_003-012.expected b/clients/tests/test-client.check-on-disk/test_003-012.expected new file mode 100644 index 00000000..810ffc8b --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_003-012.expected @@ -0,0 +1,16 @@ +location: clients/tests/test-client.py:731:test_003()/12 +cmd: $NMCLI con +lang: C +returncode: 0 +stdout: 264 bytes +>>> +NAME UUID TYPE DEVICE +ethernet UUID-ethernet-REPLACED-REPLACED-REPL ethernet eth0 +con-1 5fcfd6d7-1e63-3332-8826-a7eda103792d ethernet -- +con-xx1 UUID-con-xx1-REPLACED-REPLACED-REPLA ethernet -- + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_003-013.expected b/clients/tests/test-client.check-on-disk/test_003-013.expected new file mode 100644 index 00000000..b17bbf28 --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_003-013.expected @@ -0,0 +1,16 @@ +location: clients/tests/test-client.py:731:test_003()/13 +cmd: $NMCLI con +lang: pl_PL.UTF-8 +returncode: 0 +stdout: 264 bytes +>>> +NAME UUID TYPE DEVICE +ethernet UUID-ethernet-REPLACED-REPLACED-REPL ethernet eth0 +con-1 5fcfd6d7-1e63-3332-8826-a7eda103792d ethernet -- +con-xx1 UUID-con-xx1-REPLACED-REPLACED-REPLA ethernet -- + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_003-014.expected b/clients/tests/test-client.check-on-disk/test_003-014.expected new file mode 100644 index 00000000..da785a2c --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_003-014.expected @@ -0,0 +1,16 @@ +location: clients/tests/test-client.py:734:test_003()/14 +cmd: $NMCLI -f ALL con +lang: C +returncode: 0 +stdout: 1084 bytes +>>> +NAME UUID TYPE TIMESTAMP TIMESTAMP-REAL AUTOCONNECT AUTOCONNECT-PRIORITY READONLY DBUS-PATH ACTIVE DEVICE STATE ACTIVE-PATH SLAVE +ethernet UUID-ethernet-REPLACED-REPLACED-REPL ethernet 0 never yes 0 no /org/freedesktop/NetworkManager/Settings/Connection/3 yes eth0 activated /org/freedesktop/NetworkManager/ActiveConnection/1 -- +con-1 5fcfd6d7-1e63-3332-8826-a7eda103792d ethernet 0 never yes 0 no /org/freedesktop/NetworkManager/Settings/Connection/1 no -- -- -- -- +con-xx1 UUID-con-xx1-REPLACED-REPLACED-REPLA ethernet 0 never yes 0 no /org/freedesktop/NetworkManager/Settings/Connection/2 no -- -- -- -- + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_003-015.expected b/clients/tests/test-client.check-on-disk/test_003-015.expected new file mode 100644 index 00000000..ad645f8f --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_003-015.expected @@ -0,0 +1,16 @@ +location: clients/tests/test-client.py:734:test_003()/15 +cmd: $NMCLI -f ALL con +lang: pl_PL.UTF-8 +returncode: 0 +stdout: 1088 bytes +>>> +NAME UUID TYPE TIMESTAMP TIMESTAMP-REAL AUTOCONNECT AUTOCONNECT-PRIORITY READONLY DBUS-PATH ACTIVE DEVICE STATE ACTIVE-PATH SLAVE +ethernet UUID-ethernet-REPLACED-REPLACED-REPL ethernet 0 nigdy tak 0 nie /org/freedesktop/NetworkManager/Settings/Connection/3 tak eth0 aktywowano /org/freedesktop/NetworkManager/ActiveConnection/1 -- +con-1 5fcfd6d7-1e63-3332-8826-a7eda103792d ethernet 0 nigdy tak 0 nie /org/freedesktop/NetworkManager/Settings/Connection/1 nie -- -- -- -- +con-xx1 UUID-con-xx1-REPLACED-REPLACED-REPLA ethernet 0 nigdy tak 0 nie /org/freedesktop/NetworkManager/Settings/Connection/2 nie -- -- -- -- + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_003-016.expected b/clients/tests/test-client.check-on-disk/test_003-016.expected new file mode 100644 index 00000000..8d68221f --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_003-016.expected @@ -0,0 +1,90 @@ +location: clients/tests/test-client.py:737:test_003()/16 +cmd: $NMCLI -f ALL con s ethernet +lang: C +returncode: 0 +stdout: 3516 bytes +>>> +connection.id: ethernet +connection.uuid: UUID-ethernet-REPLACED-REPLACED-REPL +connection.stable-id: -- +connection.type: 802-3-ethernet +connection.interface-name: -- +connection.autoconnect: yes +connection.autoconnect-priority: 0 +connection.autoconnect-retries: -1 (default) +connection.auth-retries: -1 +connection.timestamp: 0 +connection.read-only: no +connection.permissions: -- +connection.zone: -- +connection.master: -- +connection.slave-type: -- +connection.autoconnect-slaves: -1 (default) +connection.secondaries: -- +connection.gateway-ping-timeout: 0 +connection.metered: unknown +connection.lldp: default +connection.mdns: -1 (default) +802-3-ethernet.port: -- +802-3-ethernet.speed: 0 +802-3-ethernet.duplex: -- +802-3-ethernet.auto-negotiate: no +802-3-ethernet.mac-address: -- +802-3-ethernet.cloned-mac-address: -- +802-3-ethernet.generate-mac-address-mask:-- +802-3-ethernet.mac-address-blacklist: -- +802-3-ethernet.mtu: auto +802-3-ethernet.s390-subchannels: -- +802-3-ethernet.s390-nettype: -- +802-3-ethernet.s390-options: -- +802-3-ethernet.wake-on-lan: default +802-3-ethernet.wake-on-lan-password: -- +ipv4.method: auto +ipv4.dns: -- +ipv4.dns-search: -- +ipv4.dns-options: "" +ipv4.dns-priority: 0 +ipv4.addresses: -- +ipv4.gateway: -- +ipv4.routes: -- +ipv4.route-metric: -1 +ipv4.route-table: 0 (unspec) +ipv4.ignore-auto-routes: no +ipv4.ignore-auto-dns: no +ipv4.dhcp-client-id: -- +ipv4.dhcp-timeout: 0 (default) +ipv4.dhcp-send-hostname: yes +ipv4.dhcp-hostname: -- +ipv4.dhcp-fqdn: -- +ipv4.never-default: no +ipv4.may-fail: yes +ipv4.dad-timeout: -1 (default) +ipv6.method: auto +ipv6.dns: -- +ipv6.dns-search: -- +ipv6.dns-options: "" +ipv6.dns-priority: 0 +ipv6.addresses: -- +ipv6.gateway: -- +ipv6.routes: -- +ipv6.route-metric: -1 +ipv6.route-table: 0 (unspec) +ipv6.ignore-auto-routes: no +ipv6.ignore-auto-dns: no +ipv6.never-default: no +ipv6.may-fail: yes +ipv6.ip6-privacy: -1 (unknown) +ipv6.addr-gen-mode: stable-privacy +ipv6.dhcp-send-hostname: yes +ipv6.dhcp-hostname: -- +ipv6.token: -- +proxy.method: none +proxy.browser-only: no +proxy.pac-url: -- +proxy.pac-script: -- + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_003-017.expected b/clients/tests/test-client.check-on-disk/test_003-017.expected new file mode 100644 index 00000000..7e99138c --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_003-017.expected @@ -0,0 +1,90 @@ +location: clients/tests/test-client.py:737:test_003()/17 +cmd: $NMCLI -f ALL con s ethernet +lang: pl_PL.UTF-8 +returncode: 0 +stdout: 3534 bytes +>>> +connection.id: ethernet +connection.uuid: UUID-ethernet-REPLACED-REPLACED-REPL +connection.stable-id: -- +connection.type: 802-3-ethernet +connection.interface-name: -- +connection.autoconnect: tak +connection.autoconnect-priority: 0 +connection.autoconnect-retries: -1 (default) +connection.auth-retries: -1 +connection.timestamp: 0 +connection.read-only: nie +connection.permissions: -- +connection.zone: -- +connection.master: -- +connection.slave-type: -- +connection.autoconnect-slaves: -1 (default) +connection.secondaries: -- +connection.gateway-ping-timeout: 0 +connection.metered: nieznane +connection.lldp: default +connection.mdns: -1 (default) +802-3-ethernet.port: -- +802-3-ethernet.speed: 0 +802-3-ethernet.duplex: -- +802-3-ethernet.auto-negotiate: nie +802-3-ethernet.mac-address: -- +802-3-ethernet.cloned-mac-address: -- +802-3-ethernet.generate-mac-address-mask:-- +802-3-ethernet.mac-address-blacklist: -- +802-3-ethernet.mtu: automatyczne +802-3-ethernet.s390-subchannels: -- +802-3-ethernet.s390-nettype: -- +802-3-ethernet.s390-options: -- +802-3-ethernet.wake-on-lan: default +802-3-ethernet.wake-on-lan-password: -- +ipv4.method: auto +ipv4.dns: -- +ipv4.dns-search: -- +ipv4.dns-options: "" +ipv4.dns-priority: 0 +ipv4.addresses: -- +ipv4.gateway: -- +ipv4.routes: -- +ipv4.route-metric: -1 +ipv4.route-table: 0 (unspec) +ipv4.ignore-auto-routes: nie +ipv4.ignore-auto-dns: nie +ipv4.dhcp-client-id: -- +ipv4.dhcp-timeout: 0 (default) +ipv4.dhcp-send-hostname: tak +ipv4.dhcp-hostname: -- +ipv4.dhcp-fqdn: -- +ipv4.never-default: nie +ipv4.may-fail: tak +ipv4.dad-timeout: -1 (default) +ipv6.method: auto +ipv6.dns: -- +ipv6.dns-search: -- +ipv6.dns-options: "" +ipv6.dns-priority: 0 +ipv6.addresses: -- +ipv6.gateway: -- +ipv6.routes: -- +ipv6.route-metric: -1 +ipv6.route-table: 0 (unspec) +ipv6.ignore-auto-routes: nie +ipv6.ignore-auto-dns: nie +ipv6.never-default: nie +ipv6.may-fail: tak +ipv6.ip6-privacy: -1 (unknown) +ipv6.addr-gen-mode: stable-privacy +ipv6.dhcp-send-hostname: tak +ipv6.dhcp-hostname: -- +ipv6.token: -- +proxy.method: none +proxy.browser-only: nie +proxy.pac-url: -- +proxy.pac-script: -- + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_003-018.expected b/clients/tests/test-client.check-on-disk/test_003-018.expected new file mode 100644 index 00000000..bc74883d --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_003-018.expected @@ -0,0 +1,102 @@ +location: clients/tests/test-client.py:740:test_003()/18 +cmd: $NMCLI con s ethernet +lang: C +returncode: 0 +stdout: 4180 bytes +>>> +connection.id: ethernet +connection.uuid: UUID-ethernet-REPLACED-REPLACED-REPL +connection.stable-id: -- +connection.type: 802-3-ethernet +connection.interface-name: -- +connection.autoconnect: yes +connection.autoconnect-priority: 0 +connection.autoconnect-retries: -1 (default) +connection.auth-retries: -1 +connection.timestamp: 0 +connection.read-only: no +connection.permissions: -- +connection.zone: -- +connection.master: -- +connection.slave-type: -- +connection.autoconnect-slaves: -1 (default) +connection.secondaries: -- +connection.gateway-ping-timeout: 0 +connection.metered: unknown +connection.lldp: default +connection.mdns: -1 (default) +802-3-ethernet.port: -- +802-3-ethernet.speed: 0 +802-3-ethernet.duplex: -- +802-3-ethernet.auto-negotiate: no +802-3-ethernet.mac-address: -- +802-3-ethernet.cloned-mac-address: -- +802-3-ethernet.generate-mac-address-mask:-- +802-3-ethernet.mac-address-blacklist: -- +802-3-ethernet.mtu: auto +802-3-ethernet.s390-subchannels: -- +802-3-ethernet.s390-nettype: -- +802-3-ethernet.s390-options: -- +802-3-ethernet.wake-on-lan: default +802-3-ethernet.wake-on-lan-password: -- +ipv4.method: auto +ipv4.dns: -- +ipv4.dns-search: -- +ipv4.dns-options: "" +ipv4.dns-priority: 0 +ipv4.addresses: -- +ipv4.gateway: -- +ipv4.routes: -- +ipv4.route-metric: -1 +ipv4.route-table: 0 (unspec) +ipv4.ignore-auto-routes: no +ipv4.ignore-auto-dns: no +ipv4.dhcp-client-id: -- +ipv4.dhcp-timeout: 0 (default) +ipv4.dhcp-send-hostname: yes +ipv4.dhcp-hostname: -- +ipv4.dhcp-fqdn: -- +ipv4.never-default: no +ipv4.may-fail: yes +ipv4.dad-timeout: -1 (default) +ipv6.method: auto +ipv6.dns: -- +ipv6.dns-search: -- +ipv6.dns-options: "" +ipv6.dns-priority: 0 +ipv6.addresses: -- +ipv6.gateway: -- +ipv6.routes: -- +ipv6.route-metric: -1 +ipv6.route-table: 0 (unspec) +ipv6.ignore-auto-routes: no +ipv6.ignore-auto-dns: no +ipv6.never-default: no +ipv6.may-fail: yes +ipv6.ip6-privacy: -1 (unknown) +ipv6.addr-gen-mode: stable-privacy +ipv6.dhcp-send-hostname: yes +ipv6.dhcp-hostname: -- +ipv6.token: -- +proxy.method: none +proxy.browser-only: no +proxy.pac-url: -- +proxy.pac-script: -- +GENERAL.NAME: ethernet +GENERAL.UUID: UUID-ethernet-REPLACED-REPLACED-REPL +GENERAL.DEVICES: eth0 +GENERAL.STATE: activated +GENERAL.DEFAULT: no +GENERAL.DEFAULT6: no +GENERAL.SPEC-OBJECT: -- +GENERAL.VPN: no +GENERAL.DBUS-PATH: /org/freedesktop/NetworkManager/ActiveConnection/1 +GENERAL.CON-PATH: /org/freedesktop/NetworkManager/Settings/Connection/3 +GENERAL.ZONE: -- +GENERAL.MASTER-PATH: -- + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_003-019.expected b/clients/tests/test-client.check-on-disk/test_003-019.expected new file mode 100644 index 00000000..5e37312d --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_003-019.expected @@ -0,0 +1,102 @@ +location: clients/tests/test-client.py:740:test_003()/19 +cmd: $NMCLI con s ethernet +lang: pl_PL.UTF-8 +returncode: 0 +stdout: 4201 bytes +>>> +connection.id: ethernet +connection.uuid: UUID-ethernet-REPLACED-REPLACED-REPL +connection.stable-id: -- +connection.type: 802-3-ethernet +connection.interface-name: -- +connection.autoconnect: tak +connection.autoconnect-priority: 0 +connection.autoconnect-retries: -1 (default) +connection.auth-retries: -1 +connection.timestamp: 0 +connection.read-only: nie +connection.permissions: -- +connection.zone: -- +connection.master: -- +connection.slave-type: -- +connection.autoconnect-slaves: -1 (default) +connection.secondaries: -- +connection.gateway-ping-timeout: 0 +connection.metered: nieznane +connection.lldp: default +connection.mdns: -1 (default) +802-3-ethernet.port: -- +802-3-ethernet.speed: 0 +802-3-ethernet.duplex: -- +802-3-ethernet.auto-negotiate: nie +802-3-ethernet.mac-address: -- +802-3-ethernet.cloned-mac-address: -- +802-3-ethernet.generate-mac-address-mask:-- +802-3-ethernet.mac-address-blacklist: -- +802-3-ethernet.mtu: automatyczne +802-3-ethernet.s390-subchannels: -- +802-3-ethernet.s390-nettype: -- +802-3-ethernet.s390-options: -- +802-3-ethernet.wake-on-lan: default +802-3-ethernet.wake-on-lan-password: -- +ipv4.method: auto +ipv4.dns: -- +ipv4.dns-search: -- +ipv4.dns-options: "" +ipv4.dns-priority: 0 +ipv4.addresses: -- +ipv4.gateway: -- +ipv4.routes: -- +ipv4.route-metric: -1 +ipv4.route-table: 0 (unspec) +ipv4.ignore-auto-routes: nie +ipv4.ignore-auto-dns: nie +ipv4.dhcp-client-id: -- +ipv4.dhcp-timeout: 0 (default) +ipv4.dhcp-send-hostname: tak +ipv4.dhcp-hostname: -- +ipv4.dhcp-fqdn: -- +ipv4.never-default: nie +ipv4.may-fail: tak +ipv4.dad-timeout: -1 (default) +ipv6.method: auto +ipv6.dns: -- +ipv6.dns-search: -- +ipv6.dns-options: "" +ipv6.dns-priority: 0 +ipv6.addresses: -- +ipv6.gateway: -- +ipv6.routes: -- +ipv6.route-metric: -1 +ipv6.route-table: 0 (unspec) +ipv6.ignore-auto-routes: nie +ipv6.ignore-auto-dns: nie +ipv6.never-default: nie +ipv6.may-fail: tak +ipv6.ip6-privacy: -1 (unknown) +ipv6.addr-gen-mode: stable-privacy +ipv6.dhcp-send-hostname: tak +ipv6.dhcp-hostname: -- +ipv6.token: -- +proxy.method: none +proxy.browser-only: nie +proxy.pac-url: -- +proxy.pac-script: -- +GENERAL.NAME: ethernet +GENERAL.UUID: UUID-ethernet-REPLACED-REPLACED-REPL +GENERAL.DEVICES: eth0 +GENERAL.STATE: activated +GENERAL.DEFAULT: nie +GENERAL.DEFAULT6: nie +GENERAL.SPEC-OBJECT: -- +GENERAL.VPN: nie +GENERAL.DBUS-PATH: /org/freedesktop/NetworkManager/ActiveConnection/1 +GENERAL.CON-PATH: /org/freedesktop/NetworkManager/Settings/Connection/3 +GENERAL.ZONE: -- +GENERAL.MASTER-PATH: -- + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_003-020.expected b/clients/tests/test-client.check-on-disk/test_003-020.expected new file mode 100644 index 00000000..513985a5 --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_003-020.expected @@ -0,0 +1,19 @@ +location: clients/tests/test-client.py:743:test_003()/20 +cmd: $NMCLI -f ALL dev s eth0 +lang: C +returncode: 0 +stdout: 1056 bytes +>>> +DEVICE TYPE STATE DBUS-PATH CONNECTION CON-UUID CON-PATH +eth1 ethernet unavailable /org/freedesktop/NetworkManager/Devices/2 -- -- -- +wlan0 wifi unavailable /org/freedesktop/NetworkManager/Devices/3 -- -- -- +wlan1 wifi unavailable /org/freedesktop/NetworkManager/Devices/4 -- -- -- +wlan1 wifi unavailable /org/freedesktop/NetworkManager/Devices/5 -- -- -- +eth0 ethernet unavailable /org/freedesktop/NetworkManager/Devices/1 ethernet UUID-ethernet-REPLACED-REPLACED-REPL /org/freedesktop/NetworkManager/ActiveConnection/1 + +<<< +stderr: 24 bytes +>>> +Unknown parameter: eth0 + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_003-021.expected b/clients/tests/test-client.check-on-disk/test_003-021.expected new file mode 100644 index 00000000..6809f290 --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_003-021.expected @@ -0,0 +1,19 @@ +location: clients/tests/test-client.py:743:test_003()/21 +cmd: $NMCLI -f ALL dev s eth0 +lang: pl_PL.UTF-8 +returncode: 0 +stdout: 1061 bytes +>>> +DEVICE TYPE STATE DBUS-PATH CONNECTION CON-UUID CON-PATH +eth1 ethernet niedostępne /org/freedesktop/NetworkManager/Devices/2 -- -- -- +wlan0 wifi niedostępne /org/freedesktop/NetworkManager/Devices/3 -- -- -- +wlan1 wifi niedostępne /org/freedesktop/NetworkManager/Devices/4 -- -- -- +wlan1 wifi niedostępne /org/freedesktop/NetworkManager/Devices/5 -- -- -- +eth0 ethernet niedostępne /org/freedesktop/NetworkManager/Devices/1 ethernet UUID-ethernet-REPLACED-REPLACED-REPL /org/freedesktop/NetworkManager/ActiveConnection/1 + +<<< +stderr: 24 bytes +>>> +Nieznany parametr: eth0 + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_003-022.expected b/clients/tests/test-client.check-on-disk/test_003-022.expected new file mode 100644 index 00000000..57d4e4a8 --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_003-022.expected @@ -0,0 +1,42 @@ +location: clients/tests/test-client.py:746:test_003()/22 +cmd: $NMCLI -f ALL dev show eth0 +lang: C +returncode: 0 +stdout: 1487 bytes +>>> +GENERAL.DEVICE: eth0 +GENERAL.TYPE: ethernet +GENERAL.NM-TYPE: NMDeviceEthernet +GENERAL.VENDOR: -- +GENERAL.PRODUCT: -- +GENERAL.DRIVER: virtual +GENERAL.DRIVER-VERSION: -- +GENERAL.FIRMWARE-VERSION: -- +GENERAL.HWADDR: 72:41:AB:90:41:5D +GENERAL.MTU: 0 +GENERAL.STATE: 20 (unavailable) +GENERAL.REASON: 0 (No reason given) +GENERAL.UDI: /sys/devices/virtual/eth0 +GENERAL.IP-IFACE: -- +GENERAL.IS-SOFTWARE: no +GENERAL.NM-MANAGED: yes +GENERAL.AUTOCONNECT: yes +GENERAL.FIRMWARE-MISSING: no +GENERAL.NM-PLUGIN-MISSING: no +GENERAL.PHYS-PORT-ID: -- +GENERAL.CONNECTION: ethernet +GENERAL.CON-UUID: UUID-ethernet-REPLACED-REPLACED-REPL +GENERAL.CON-PATH: /org/freedesktop/NetworkManager/ActiveConnection/1 +GENERAL.METERED: unknown +CAPABILITIES.CARRIER-DETECT: no +CAPABILITIES.SPEED: 100 Mb/s +CAPABILITIES.IS-SOFTWARE: no +CAPABILITIES.SRIOV: no +WIRED-PROPERTIES.CARRIER: off +CONNECTIONS.AVAILABLE-CONNECTION-PATHS: -- + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_003-023.expected b/clients/tests/test-client.check-on-disk/test_003-023.expected new file mode 100644 index 00000000..0455374f --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_003-023.expected @@ -0,0 +1,42 @@ +location: clients/tests/test-client.py:746:test_003()/23 +cmd: $NMCLI -f ALL dev show eth0 +lang: pl_PL.UTF-8 +returncode: 0 +stdout: 1510 bytes +>>> +GENERAL.DEVICE: eth0 +GENERAL.TYPE: ethernet +GENERAL.NM-TYPE: NMDeviceEthernet +GENERAL.VENDOR: -- +GENERAL.PRODUCT: -- +GENERAL.DRIVER: virtual +GENERAL.DRIVER-VERSION: -- +GENERAL.FIRMWARE-VERSION: -- +GENERAL.HWADDR: 72:41:AB:90:41:5D +GENERAL.MTU: 0 +GENERAL.STATE: 20 (niedostępne) +GENERAL.REASON: 0 (Nie podano przyczyny) +GENERAL.UDI: /sys/devices/virtual/eth0 +GENERAL.IP-IFACE: -- +GENERAL.IS-SOFTWARE: nie +GENERAL.NM-MANAGED: tak +GENERAL.AUTOCONNECT: tak +GENERAL.FIRMWARE-MISSING: nie +GENERAL.NM-PLUGIN-MISSING: nie +GENERAL.PHYS-PORT-ID: -- +GENERAL.CONNECTION: ethernet +GENERAL.CON-UUID: UUID-ethernet-REPLACED-REPLACED-REPL +GENERAL.CON-PATH: /org/freedesktop/NetworkManager/ActiveConnection/1 +GENERAL.METERED: nieznane +CAPABILITIES.CARRIER-DETECT: nie +CAPABILITIES.SPEED: 100 Mb/s +CAPABILITIES.IS-SOFTWARE: nie +CAPABILITIES.SRIOV: nie +WIRED-PROPERTIES.CARRIER: wyłączone +CONNECTIONS.AVAILABLE-CONNECTION-PATHS: -- + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_003-024.expected b/clients/tests/test-client.check-on-disk/test_003-024.expected new file mode 100644 index 00000000..b20a45d4 --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_003-024.expected @@ -0,0 +1,13 @@ +location: clients/tests/test-client.py:728:test_003()/24 +cmd: $NMCLI con up ethernet ifname eth1 +lang: C +returncode: 0 +stdout: 106 bytes +>>> +Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/2) + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_003-025.expected b/clients/tests/test-client.check-on-disk/test_003-025.expected new file mode 100644 index 00000000..3806099b --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_003-025.expected @@ -0,0 +1,16 @@ +location: clients/tests/test-client.py:731:test_003()/25 +cmd: $NMCLI con +lang: C +returncode: 0 +stdout: 264 bytes +>>> +NAME UUID TYPE DEVICE +ethernet UUID-ethernet-REPLACED-REPLACED-REPL ethernet eth0 +con-1 5fcfd6d7-1e63-3332-8826-a7eda103792d ethernet -- +con-xx1 UUID-con-xx1-REPLACED-REPLACED-REPLA ethernet -- + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_003-026.expected b/clients/tests/test-client.check-on-disk/test_003-026.expected new file mode 100644 index 00000000..ee609134 --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_003-026.expected @@ -0,0 +1,16 @@ +location: clients/tests/test-client.py:731:test_003()/26 +cmd: $NMCLI con +lang: pl_PL.UTF-8 +returncode: 0 +stdout: 264 bytes +>>> +NAME UUID TYPE DEVICE +ethernet UUID-ethernet-REPLACED-REPLACED-REPL ethernet eth0 +con-1 5fcfd6d7-1e63-3332-8826-a7eda103792d ethernet -- +con-xx1 UUID-con-xx1-REPLACED-REPLACED-REPLA ethernet -- + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_003-027.expected b/clients/tests/test-client.check-on-disk/test_003-027.expected new file mode 100644 index 00000000..96924a42 --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_003-027.expected @@ -0,0 +1,16 @@ +location: clients/tests/test-client.py:734:test_003()/27 +cmd: $NMCLI -f ALL con +lang: C +returncode: 0 +stdout: 1084 bytes +>>> +NAME UUID TYPE TIMESTAMP TIMESTAMP-REAL AUTOCONNECT AUTOCONNECT-PRIORITY READONLY DBUS-PATH ACTIVE DEVICE STATE ACTIVE-PATH SLAVE +ethernet UUID-ethernet-REPLACED-REPLACED-REPL ethernet 0 never yes 0 no /org/freedesktop/NetworkManager/Settings/Connection/3 yes eth0 activated /org/freedesktop/NetworkManager/ActiveConnection/1 -- +con-1 5fcfd6d7-1e63-3332-8826-a7eda103792d ethernet 0 never yes 0 no /org/freedesktop/NetworkManager/Settings/Connection/1 no -- -- -- -- +con-xx1 UUID-con-xx1-REPLACED-REPLACED-REPLA ethernet 0 never yes 0 no /org/freedesktop/NetworkManager/Settings/Connection/2 no -- -- -- -- + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_003-028.expected b/clients/tests/test-client.check-on-disk/test_003-028.expected new file mode 100644 index 00000000..6065d1ea --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_003-028.expected @@ -0,0 +1,16 @@ +location: clients/tests/test-client.py:734:test_003()/28 +cmd: $NMCLI -f ALL con +lang: pl_PL.UTF-8 +returncode: 0 +stdout: 1088 bytes +>>> +NAME UUID TYPE TIMESTAMP TIMESTAMP-REAL AUTOCONNECT AUTOCONNECT-PRIORITY READONLY DBUS-PATH ACTIVE DEVICE STATE ACTIVE-PATH SLAVE +ethernet UUID-ethernet-REPLACED-REPLACED-REPL ethernet 0 nigdy tak 0 nie /org/freedesktop/NetworkManager/Settings/Connection/3 tak eth0 aktywowano /org/freedesktop/NetworkManager/ActiveConnection/1 -- +con-1 5fcfd6d7-1e63-3332-8826-a7eda103792d ethernet 0 nigdy tak 0 nie /org/freedesktop/NetworkManager/Settings/Connection/1 nie -- -- -- -- +con-xx1 UUID-con-xx1-REPLACED-REPLACED-REPLA ethernet 0 nigdy tak 0 nie /org/freedesktop/NetworkManager/Settings/Connection/2 nie -- -- -- -- + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_003-029.expected b/clients/tests/test-client.check-on-disk/test_003-029.expected new file mode 100644 index 00000000..ebb89619 --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_003-029.expected @@ -0,0 +1,90 @@ +location: clients/tests/test-client.py:737:test_003()/29 +cmd: $NMCLI -f ALL con s ethernet +lang: C +returncode: 0 +stdout: 3516 bytes +>>> +connection.id: ethernet +connection.uuid: UUID-ethernet-REPLACED-REPLACED-REPL +connection.stable-id: -- +connection.type: 802-3-ethernet +connection.interface-name: -- +connection.autoconnect: yes +connection.autoconnect-priority: 0 +connection.autoconnect-retries: -1 (default) +connection.auth-retries: -1 +connection.timestamp: 0 +connection.read-only: no +connection.permissions: -- +connection.zone: -- +connection.master: -- +connection.slave-type: -- +connection.autoconnect-slaves: -1 (default) +connection.secondaries: -- +connection.gateway-ping-timeout: 0 +connection.metered: unknown +connection.lldp: default +connection.mdns: -1 (default) +802-3-ethernet.port: -- +802-3-ethernet.speed: 0 +802-3-ethernet.duplex: -- +802-3-ethernet.auto-negotiate: no +802-3-ethernet.mac-address: -- +802-3-ethernet.cloned-mac-address: -- +802-3-ethernet.generate-mac-address-mask:-- +802-3-ethernet.mac-address-blacklist: -- +802-3-ethernet.mtu: auto +802-3-ethernet.s390-subchannels: -- +802-3-ethernet.s390-nettype: -- +802-3-ethernet.s390-options: -- +802-3-ethernet.wake-on-lan: default +802-3-ethernet.wake-on-lan-password: -- +ipv4.method: auto +ipv4.dns: -- +ipv4.dns-search: -- +ipv4.dns-options: "" +ipv4.dns-priority: 0 +ipv4.addresses: -- +ipv4.gateway: -- +ipv4.routes: -- +ipv4.route-metric: -1 +ipv4.route-table: 0 (unspec) +ipv4.ignore-auto-routes: no +ipv4.ignore-auto-dns: no +ipv4.dhcp-client-id: -- +ipv4.dhcp-timeout: 0 (default) +ipv4.dhcp-send-hostname: yes +ipv4.dhcp-hostname: -- +ipv4.dhcp-fqdn: -- +ipv4.never-default: no +ipv4.may-fail: yes +ipv4.dad-timeout: -1 (default) +ipv6.method: auto +ipv6.dns: -- +ipv6.dns-search: -- +ipv6.dns-options: "" +ipv6.dns-priority: 0 +ipv6.addresses: -- +ipv6.gateway: -- +ipv6.routes: -- +ipv6.route-metric: -1 +ipv6.route-table: 0 (unspec) +ipv6.ignore-auto-routes: no +ipv6.ignore-auto-dns: no +ipv6.never-default: no +ipv6.may-fail: yes +ipv6.ip6-privacy: -1 (unknown) +ipv6.addr-gen-mode: stable-privacy +ipv6.dhcp-send-hostname: yes +ipv6.dhcp-hostname: -- +ipv6.token: -- +proxy.method: none +proxy.browser-only: no +proxy.pac-url: -- +proxy.pac-script: -- + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_003-030.expected b/clients/tests/test-client.check-on-disk/test_003-030.expected new file mode 100644 index 00000000..adf743d8 --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_003-030.expected @@ -0,0 +1,90 @@ +location: clients/tests/test-client.py:737:test_003()/30 +cmd: $NMCLI -f ALL con s ethernet +lang: pl_PL.UTF-8 +returncode: 0 +stdout: 3534 bytes +>>> +connection.id: ethernet +connection.uuid: UUID-ethernet-REPLACED-REPLACED-REPL +connection.stable-id: -- +connection.type: 802-3-ethernet +connection.interface-name: -- +connection.autoconnect: tak +connection.autoconnect-priority: 0 +connection.autoconnect-retries: -1 (default) +connection.auth-retries: -1 +connection.timestamp: 0 +connection.read-only: nie +connection.permissions: -- +connection.zone: -- +connection.master: -- +connection.slave-type: -- +connection.autoconnect-slaves: -1 (default) +connection.secondaries: -- +connection.gateway-ping-timeout: 0 +connection.metered: nieznane +connection.lldp: default +connection.mdns: -1 (default) +802-3-ethernet.port: -- +802-3-ethernet.speed: 0 +802-3-ethernet.duplex: -- +802-3-ethernet.auto-negotiate: nie +802-3-ethernet.mac-address: -- +802-3-ethernet.cloned-mac-address: -- +802-3-ethernet.generate-mac-address-mask:-- +802-3-ethernet.mac-address-blacklist: -- +802-3-ethernet.mtu: automatyczne +802-3-ethernet.s390-subchannels: -- +802-3-ethernet.s390-nettype: -- +802-3-ethernet.s390-options: -- +802-3-ethernet.wake-on-lan: default +802-3-ethernet.wake-on-lan-password: -- +ipv4.method: auto +ipv4.dns: -- +ipv4.dns-search: -- +ipv4.dns-options: "" +ipv4.dns-priority: 0 +ipv4.addresses: -- +ipv4.gateway: -- +ipv4.routes: -- +ipv4.route-metric: -1 +ipv4.route-table: 0 (unspec) +ipv4.ignore-auto-routes: nie +ipv4.ignore-auto-dns: nie +ipv4.dhcp-client-id: -- +ipv4.dhcp-timeout: 0 (default) +ipv4.dhcp-send-hostname: tak +ipv4.dhcp-hostname: -- +ipv4.dhcp-fqdn: -- +ipv4.never-default: nie +ipv4.may-fail: tak +ipv4.dad-timeout: -1 (default) +ipv6.method: auto +ipv6.dns: -- +ipv6.dns-search: -- +ipv6.dns-options: "" +ipv6.dns-priority: 0 +ipv6.addresses: -- +ipv6.gateway: -- +ipv6.routes: -- +ipv6.route-metric: -1 +ipv6.route-table: 0 (unspec) +ipv6.ignore-auto-routes: nie +ipv6.ignore-auto-dns: nie +ipv6.never-default: nie +ipv6.may-fail: tak +ipv6.ip6-privacy: -1 (unknown) +ipv6.addr-gen-mode: stable-privacy +ipv6.dhcp-send-hostname: tak +ipv6.dhcp-hostname: -- +ipv6.token: -- +proxy.method: none +proxy.browser-only: nie +proxy.pac-url: -- +proxy.pac-script: -- + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_003-031.expected b/clients/tests/test-client.check-on-disk/test_003-031.expected new file mode 100644 index 00000000..cbf57afc --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_003-031.expected @@ -0,0 +1,115 @@ +location: clients/tests/test-client.py:740:test_003()/31 +cmd: $NMCLI con s ethernet +lang: C +returncode: 0 +stdout: 4845 bytes +>>> +connection.id: ethernet +connection.uuid: UUID-ethernet-REPLACED-REPLACED-REPL +connection.stable-id: -- +connection.type: 802-3-ethernet +connection.interface-name: -- +connection.autoconnect: yes +connection.autoconnect-priority: 0 +connection.autoconnect-retries: -1 (default) +connection.auth-retries: -1 +connection.timestamp: 0 +connection.read-only: no +connection.permissions: -- +connection.zone: -- +connection.master: -- +connection.slave-type: -- +connection.autoconnect-slaves: -1 (default) +connection.secondaries: -- +connection.gateway-ping-timeout: 0 +connection.metered: unknown +connection.lldp: default +connection.mdns: -1 (default) +802-3-ethernet.port: -- +802-3-ethernet.speed: 0 +802-3-ethernet.duplex: -- +802-3-ethernet.auto-negotiate: no +802-3-ethernet.mac-address: -- +802-3-ethernet.cloned-mac-address: -- +802-3-ethernet.generate-mac-address-mask:-- +802-3-ethernet.mac-address-blacklist: -- +802-3-ethernet.mtu: auto +802-3-ethernet.s390-subchannels: -- +802-3-ethernet.s390-nettype: -- +802-3-ethernet.s390-options: -- +802-3-ethernet.wake-on-lan: default +802-3-ethernet.wake-on-lan-password: -- +ipv4.method: auto +ipv4.dns: -- +ipv4.dns-search: -- +ipv4.dns-options: "" +ipv4.dns-priority: 0 +ipv4.addresses: -- +ipv4.gateway: -- +ipv4.routes: -- +ipv4.route-metric: -1 +ipv4.route-table: 0 (unspec) +ipv4.ignore-auto-routes: no +ipv4.ignore-auto-dns: no +ipv4.dhcp-client-id: -- +ipv4.dhcp-timeout: 0 (default) +ipv4.dhcp-send-hostname: yes +ipv4.dhcp-hostname: -- +ipv4.dhcp-fqdn: -- +ipv4.never-default: no +ipv4.may-fail: yes +ipv4.dad-timeout: -1 (default) +ipv6.method: auto +ipv6.dns: -- +ipv6.dns-search: -- +ipv6.dns-options: "" +ipv6.dns-priority: 0 +ipv6.addresses: -- +ipv6.gateway: -- +ipv6.routes: -- +ipv6.route-metric: -1 +ipv6.route-table: 0 (unspec) +ipv6.ignore-auto-routes: no +ipv6.ignore-auto-dns: no +ipv6.never-default: no +ipv6.may-fail: yes +ipv6.ip6-privacy: -1 (unknown) +ipv6.addr-gen-mode: stable-privacy +ipv6.dhcp-send-hostname: yes +ipv6.dhcp-hostname: -- +ipv6.token: -- +proxy.method: none +proxy.browser-only: no +proxy.pac-url: -- +proxy.pac-script: -- +GENERAL.NAME: ethernet +GENERAL.UUID: UUID-ethernet-REPLACED-REPLACED-REPL +GENERAL.DEVICES: eth0 +GENERAL.STATE: activated +GENERAL.DEFAULT: no +GENERAL.DEFAULT6: no +GENERAL.SPEC-OBJECT: -- +GENERAL.VPN: no +GENERAL.DBUS-PATH: /org/freedesktop/NetworkManager/ActiveConnection/1 +GENERAL.CON-PATH: /org/freedesktop/NetworkManager/Settings/Connection/3 +GENERAL.ZONE: -- +GENERAL.MASTER-PATH: -- + +GENERAL.NAME: ethernet +GENERAL.UUID: UUID-ethernet-REPLACED-REPLACED-REPL +GENERAL.DEVICES: eth1 +GENERAL.STATE: activated +GENERAL.DEFAULT: no +GENERAL.DEFAULT6: no +GENERAL.SPEC-OBJECT: -- +GENERAL.VPN: no +GENERAL.DBUS-PATH: /org/freedesktop/NetworkManager/ActiveConnection/2 +GENERAL.CON-PATH: /org/freedesktop/NetworkManager/Settings/Connection/3 +GENERAL.ZONE: -- +GENERAL.MASTER-PATH: -- + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_003-032.expected b/clients/tests/test-client.check-on-disk/test_003-032.expected new file mode 100644 index 00000000..e5d74a1b --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_003-032.expected @@ -0,0 +1,115 @@ +location: clients/tests/test-client.py:740:test_003()/32 +cmd: $NMCLI con s ethernet +lang: pl_PL.UTF-8 +returncode: 0 +stdout: 4869 bytes +>>> +connection.id: ethernet +connection.uuid: UUID-ethernet-REPLACED-REPLACED-REPL +connection.stable-id: -- +connection.type: 802-3-ethernet +connection.interface-name: -- +connection.autoconnect: tak +connection.autoconnect-priority: 0 +connection.autoconnect-retries: -1 (default) +connection.auth-retries: -1 +connection.timestamp: 0 +connection.read-only: nie +connection.permissions: -- +connection.zone: -- +connection.master: -- +connection.slave-type: -- +connection.autoconnect-slaves: -1 (default) +connection.secondaries: -- +connection.gateway-ping-timeout: 0 +connection.metered: nieznane +connection.lldp: default +connection.mdns: -1 (default) +802-3-ethernet.port: -- +802-3-ethernet.speed: 0 +802-3-ethernet.duplex: -- +802-3-ethernet.auto-negotiate: nie +802-3-ethernet.mac-address: -- +802-3-ethernet.cloned-mac-address: -- +802-3-ethernet.generate-mac-address-mask:-- +802-3-ethernet.mac-address-blacklist: -- +802-3-ethernet.mtu: automatyczne +802-3-ethernet.s390-subchannels: -- +802-3-ethernet.s390-nettype: -- +802-3-ethernet.s390-options: -- +802-3-ethernet.wake-on-lan: default +802-3-ethernet.wake-on-lan-password: -- +ipv4.method: auto +ipv4.dns: -- +ipv4.dns-search: -- +ipv4.dns-options: "" +ipv4.dns-priority: 0 +ipv4.addresses: -- +ipv4.gateway: -- +ipv4.routes: -- +ipv4.route-metric: -1 +ipv4.route-table: 0 (unspec) +ipv4.ignore-auto-routes: nie +ipv4.ignore-auto-dns: nie +ipv4.dhcp-client-id: -- +ipv4.dhcp-timeout: 0 (default) +ipv4.dhcp-send-hostname: tak +ipv4.dhcp-hostname: -- +ipv4.dhcp-fqdn: -- +ipv4.never-default: nie +ipv4.may-fail: tak +ipv4.dad-timeout: -1 (default) +ipv6.method: auto +ipv6.dns: -- +ipv6.dns-search: -- +ipv6.dns-options: "" +ipv6.dns-priority: 0 +ipv6.addresses: -- +ipv6.gateway: -- +ipv6.routes: -- +ipv6.route-metric: -1 +ipv6.route-table: 0 (unspec) +ipv6.ignore-auto-routes: nie +ipv6.ignore-auto-dns: nie +ipv6.never-default: nie +ipv6.may-fail: tak +ipv6.ip6-privacy: -1 (unknown) +ipv6.addr-gen-mode: stable-privacy +ipv6.dhcp-send-hostname: tak +ipv6.dhcp-hostname: -- +ipv6.token: -- +proxy.method: none +proxy.browser-only: nie +proxy.pac-url: -- +proxy.pac-script: -- +GENERAL.NAME: ethernet +GENERAL.UUID: UUID-ethernet-REPLACED-REPLACED-REPL +GENERAL.DEVICES: eth0 +GENERAL.STATE: activated +GENERAL.DEFAULT: nie +GENERAL.DEFAULT6: nie +GENERAL.SPEC-OBJECT: -- +GENERAL.VPN: nie +GENERAL.DBUS-PATH: /org/freedesktop/NetworkManager/ActiveConnection/1 +GENERAL.CON-PATH: /org/freedesktop/NetworkManager/Settings/Connection/3 +GENERAL.ZONE: -- +GENERAL.MASTER-PATH: -- + +GENERAL.NAME: ethernet +GENERAL.UUID: UUID-ethernet-REPLACED-REPLACED-REPL +GENERAL.DEVICES: eth1 +GENERAL.STATE: activated +GENERAL.DEFAULT: nie +GENERAL.DEFAULT6: nie +GENERAL.SPEC-OBJECT: -- +GENERAL.VPN: nie +GENERAL.DBUS-PATH: /org/freedesktop/NetworkManager/ActiveConnection/2 +GENERAL.CON-PATH: /org/freedesktop/NetworkManager/Settings/Connection/3 +GENERAL.ZONE: -- +GENERAL.MASTER-PATH: -- + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_003-033.expected b/clients/tests/test-client.check-on-disk/test_003-033.expected new file mode 100644 index 00000000..46b70521 --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_003-033.expected @@ -0,0 +1,19 @@ +location: clients/tests/test-client.py:743:test_003()/33 +cmd: $NMCLI -f ALL dev s eth0 +lang: C +returncode: 0 +stdout: 1056 bytes +>>> +DEVICE TYPE STATE DBUS-PATH CONNECTION CON-UUID CON-PATH +wlan0 wifi unavailable /org/freedesktop/NetworkManager/Devices/3 -- -- -- +wlan1 wifi unavailable /org/freedesktop/NetworkManager/Devices/4 -- -- -- +wlan1 wifi unavailable /org/freedesktop/NetworkManager/Devices/5 -- -- -- +eth0 ethernet unavailable /org/freedesktop/NetworkManager/Devices/1 ethernet UUID-ethernet-REPLACED-REPLACED-REPL /org/freedesktop/NetworkManager/ActiveConnection/1 +eth1 ethernet unavailable /org/freedesktop/NetworkManager/Devices/2 ethernet UUID-ethernet-REPLACED-REPLACED-REPL /org/freedesktop/NetworkManager/ActiveConnection/2 + +<<< +stderr: 24 bytes +>>> +Unknown parameter: eth0 + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_003-034.expected b/clients/tests/test-client.check-on-disk/test_003-034.expected new file mode 100644 index 00000000..77cc99fd --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_003-034.expected @@ -0,0 +1,19 @@ +location: clients/tests/test-client.py:743:test_003()/34 +cmd: $NMCLI -f ALL dev s eth0 +lang: pl_PL.UTF-8 +returncode: 0 +stdout: 1061 bytes +>>> +DEVICE TYPE STATE DBUS-PATH CONNECTION CON-UUID CON-PATH +wlan0 wifi niedostępne /org/freedesktop/NetworkManager/Devices/3 -- -- -- +wlan1 wifi niedostępne /org/freedesktop/NetworkManager/Devices/4 -- -- -- +wlan1 wifi niedostępne /org/freedesktop/NetworkManager/Devices/5 -- -- -- +eth0 ethernet niedostępne /org/freedesktop/NetworkManager/Devices/1 ethernet UUID-ethernet-REPLACED-REPLACED-REPL /org/freedesktop/NetworkManager/ActiveConnection/1 +eth1 ethernet niedostępne /org/freedesktop/NetworkManager/Devices/2 ethernet UUID-ethernet-REPLACED-REPLACED-REPL /org/freedesktop/NetworkManager/ActiveConnection/2 + +<<< +stderr: 24 bytes +>>> +Nieznany parametr: eth0 + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_003-035.expected b/clients/tests/test-client.check-on-disk/test_003-035.expected new file mode 100644 index 00000000..ae928657 --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_003-035.expected @@ -0,0 +1,42 @@ +location: clients/tests/test-client.py:746:test_003()/35 +cmd: $NMCLI -f ALL dev show eth0 +lang: C +returncode: 0 +stdout: 1487 bytes +>>> +GENERAL.DEVICE: eth0 +GENERAL.TYPE: ethernet +GENERAL.NM-TYPE: NMDeviceEthernet +GENERAL.VENDOR: -- +GENERAL.PRODUCT: -- +GENERAL.DRIVER: virtual +GENERAL.DRIVER-VERSION: -- +GENERAL.FIRMWARE-VERSION: -- +GENERAL.HWADDR: 72:41:AB:90:41:5D +GENERAL.MTU: 0 +GENERAL.STATE: 20 (unavailable) +GENERAL.REASON: 0 (No reason given) +GENERAL.UDI: /sys/devices/virtual/eth0 +GENERAL.IP-IFACE: -- +GENERAL.IS-SOFTWARE: no +GENERAL.NM-MANAGED: yes +GENERAL.AUTOCONNECT: yes +GENERAL.FIRMWARE-MISSING: no +GENERAL.NM-PLUGIN-MISSING: no +GENERAL.PHYS-PORT-ID: -- +GENERAL.CONNECTION: ethernet +GENERAL.CON-UUID: UUID-ethernet-REPLACED-REPLACED-REPL +GENERAL.CON-PATH: /org/freedesktop/NetworkManager/ActiveConnection/1 +GENERAL.METERED: unknown +CAPABILITIES.CARRIER-DETECT: no +CAPABILITIES.SPEED: 100 Mb/s +CAPABILITIES.IS-SOFTWARE: no +CAPABILITIES.SRIOV: no +WIRED-PROPERTIES.CARRIER: off +CONNECTIONS.AVAILABLE-CONNECTION-PATHS: -- + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_003-036.expected b/clients/tests/test-client.check-on-disk/test_003-036.expected new file mode 100644 index 00000000..11b511f7 --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_003-036.expected @@ -0,0 +1,42 @@ +location: clients/tests/test-client.py:746:test_003()/36 +cmd: $NMCLI -f ALL dev show eth0 +lang: pl_PL.UTF-8 +returncode: 0 +stdout: 1510 bytes +>>> +GENERAL.DEVICE: eth0 +GENERAL.TYPE: ethernet +GENERAL.NM-TYPE: NMDeviceEthernet +GENERAL.VENDOR: -- +GENERAL.PRODUCT: -- +GENERAL.DRIVER: virtual +GENERAL.DRIVER-VERSION: -- +GENERAL.FIRMWARE-VERSION: -- +GENERAL.HWADDR: 72:41:AB:90:41:5D +GENERAL.MTU: 0 +GENERAL.STATE: 20 (niedostępne) +GENERAL.REASON: 0 (Nie podano przyczyny) +GENERAL.UDI: /sys/devices/virtual/eth0 +GENERAL.IP-IFACE: -- +GENERAL.IS-SOFTWARE: nie +GENERAL.NM-MANAGED: tak +GENERAL.AUTOCONNECT: tak +GENERAL.FIRMWARE-MISSING: nie +GENERAL.NM-PLUGIN-MISSING: nie +GENERAL.PHYS-PORT-ID: -- +GENERAL.CONNECTION: ethernet +GENERAL.CON-UUID: UUID-ethernet-REPLACED-REPLACED-REPL +GENERAL.CON-PATH: /org/freedesktop/NetworkManager/ActiveConnection/1 +GENERAL.METERED: nieznane +CAPABILITIES.CARRIER-DETECT: nie +CAPABILITIES.SPEED: 100 Mb/s +CAPABILITIES.IS-SOFTWARE: nie +CAPABILITIES.SRIOV: nie +WIRED-PROPERTIES.CARRIER: wyłączone +CONNECTIONS.AVAILABLE-CONNECTION-PATHS: -- + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_003-037.expected b/clients/tests/test-client.check-on-disk/test_003-037.expected new file mode 100644 index 00000000..0346b310 --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_003-037.expected @@ -0,0 +1,16 @@ +location: clients/tests/test-client.py:755:test_003()/37 +cmd: $NMCLI -f ALL con +lang: C +returncode: 0 +stdout: 1096 bytes +>>> +NAME UUID TYPE TIMESTAMP TIMESTAMP-REAL AUTOCONNECT AUTOCONNECT-PRIORITY READONLY DBUS-PATH ACTIVE DEVICE STATE ACTIVE-PATH SLAVE +ethernet UUID-ethernet-REPLACED-REPLACED-REPL ethernet 0 never yes 0 no /org/freedesktop/NetworkManager/Settings/Connection/3 yes eth0 deactivating /org/freedesktop/NetworkManager/ActiveConnection/1 -- +con-1 5fcfd6d7-1e63-3332-8826-a7eda103792d ethernet 0 never yes 0 no /org/freedesktop/NetworkManager/Settings/Connection/1 no -- -- -- -- +con-xx1 UUID-con-xx1-REPLACED-REPLACED-REPLA ethernet 0 never yes 0 no /org/freedesktop/NetworkManager/Settings/Connection/2 no -- -- -- -- + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_003-038.expected b/clients/tests/test-client.check-on-disk/test_003-038.expected new file mode 100644 index 00000000..81c7c237 --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_003-038.expected @@ -0,0 +1,16 @@ +location: clients/tests/test-client.py:755:test_003()/38 +cmd: $NMCLI -f ALL con +lang: pl_PL.UTF-8 +returncode: 0 +stdout: 1104 bytes +>>> +NAME UUID TYPE TIMESTAMP TIMESTAMP-REAL AUTOCONNECT AUTOCONNECT-PRIORITY READONLY DBUS-PATH ACTIVE DEVICE STATE ACTIVE-PATH SLAVE +ethernet UUID-ethernet-REPLACED-REPLACED-REPL ethernet 0 nigdy tak 0 nie /org/freedesktop/NetworkManager/Settings/Connection/3 tak eth0 dezaktywowanie /org/freedesktop/NetworkManager/ActiveConnection/1 -- +con-1 5fcfd6d7-1e63-3332-8826-a7eda103792d ethernet 0 nigdy tak 0 nie /org/freedesktop/NetworkManager/Settings/Connection/1 nie -- -- -- -- +con-xx1 UUID-con-xx1-REPLACED-REPLACED-REPLA ethernet 0 nigdy tak 0 nie /org/freedesktop/NetworkManager/Settings/Connection/2 nie -- -- -- -- + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_003-039.expected b/clients/tests/test-client.check-on-disk/test_003-039.expected new file mode 100644 index 00000000..3640d0c9 --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_003-039.expected @@ -0,0 +1,16 @@ +location: clients/tests/test-client.py:758:test_003()/39 +cmd: $NMCLI -f UUID,TYPE con +lang: C +returncode: 0 +stdout: 192 bytes +>>> +UUID TYPE +UUID-ethernet-REPLACED-REPLACED-REPL ethernet +5fcfd6d7-1e63-3332-8826-a7eda103792d ethernet +UUID-con-xx1-REPLACED-REPLACED-REPLA ethernet + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_003-040.expected b/clients/tests/test-client.check-on-disk/test_003-040.expected new file mode 100644 index 00000000..fd263f55 --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_003-040.expected @@ -0,0 +1,16 @@ +location: clients/tests/test-client.py:758:test_003()/40 +cmd: $NMCLI -f UUID,TYPE con +lang: pl_PL.UTF-8 +returncode: 0 +stdout: 192 bytes +>>> +UUID TYPE +UUID-ethernet-REPLACED-REPLACED-REPL ethernet +5fcfd6d7-1e63-3332-8826-a7eda103792d ethernet +UUID-con-xx1-REPLACED-REPLACED-REPLA ethernet + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_003-041.expected b/clients/tests/test-client.check-on-disk/test_003-041.expected new file mode 100644 index 00000000..f61fb681 --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_003-041.expected @@ -0,0 +1,18 @@ +location: clients/tests/test-client.py:761:test_003()/41 +cmd: $NMCLI -f UUID,TYPE --mode multiline con +lang: C +returncode: 0 +stdout: 378 bytes +>>> +UUID: UUID-ethernet-REPLACED-REPLACED-REPL +TYPE: ethernet +UUID: 5fcfd6d7-1e63-3332-8826-a7eda103792d +TYPE: ethernet +UUID: UUID-con-xx1-REPLACED-REPLACED-REPLA +TYPE: ethernet + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_003-042.expected b/clients/tests/test-client.check-on-disk/test_003-042.expected new file mode 100644 index 00000000..6ea659e9 --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_003-042.expected @@ -0,0 +1,18 @@ +location: clients/tests/test-client.py:761:test_003()/42 +cmd: $NMCLI -f UUID,TYPE --mode multiline con +lang: pl_PL.UTF-8 +returncode: 0 +stdout: 378 bytes +>>> +UUID: UUID-ethernet-REPLACED-REPLACED-REPL +TYPE: ethernet +UUID: 5fcfd6d7-1e63-3332-8826-a7eda103792d +TYPE: ethernet +UUID: UUID-con-xx1-REPLACED-REPLACED-REPLA +TYPE: ethernet + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_003-043.expected b/clients/tests/test-client.check-on-disk/test_003-043.expected new file mode 100644 index 00000000..8f5aeb70 --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_003-043.expected @@ -0,0 +1,18 @@ +location: clients/tests/test-client.py:764:test_003()/43 +cmd: $NMCLI -f UUID,TYPE --mode multiline --terse con +lang: C +returncode: 0 +stdout: 186 bytes +>>> +UUID:UUID-ethernet-REPLACED-REPLACED-REPL +TYPE:802-3-ethernet +UUID:5fcfd6d7-1e63-3332-8826-a7eda103792d +TYPE:802-3-ethernet +UUID:UUID-con-xx1-REPLACED-REPLACED-REPLA +TYPE:802-3-ethernet + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_003-044.expected b/clients/tests/test-client.check-on-disk/test_003-044.expected new file mode 100644 index 00000000..fbe01dab --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_003-044.expected @@ -0,0 +1,18 @@ +location: clients/tests/test-client.py:764:test_003()/44 +cmd: $NMCLI -f UUID,TYPE --mode multiline --terse con +lang: pl_PL.UTF-8 +returncode: 0 +stdout: 186 bytes +>>> +UUID:UUID-ethernet-REPLACED-REPLACED-REPL +TYPE:802-3-ethernet +UUID:5fcfd6d7-1e63-3332-8826-a7eda103792d +TYPE:802-3-ethernet +UUID:UUID-con-xx1-REPLACED-REPLACED-REPLA +TYPE:802-3-ethernet + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_003-045.expected b/clients/tests/test-client.check-on-disk/test_003-045.expected new file mode 100644 index 00000000..5759e2f4 --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_003-045.expected @@ -0,0 +1,24 @@ +location: clients/tests/test-client.py:767:test_003()/45 +cmd: $NMCLI -f UUID,TYPE --mode multiline --pretty con +lang: C +returncode: 0 +stdout: 835 bytes +>>> +=============================================================================== + NetworkManager connection profiles +=============================================================================== +UUID: UUID-ethernet-REPLACED-REPLACED-REPL +TYPE: ethernet +------------------------------------------------------------------------------- +UUID: 5fcfd6d7-1e63-3332-8826-a7eda103792d +TYPE: ethernet +------------------------------------------------------------------------------- +UUID: UUID-con-xx1-REPLACED-REPLACED-REPLA +TYPE: ethernet +------------------------------------------------------------------------------- + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_003-046.expected b/clients/tests/test-client.check-on-disk/test_003-046.expected new file mode 100644 index 00000000..d853d487 --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_003-046.expected @@ -0,0 +1,24 @@ +location: clients/tests/test-client.py:767:test_003()/46 +cmd: $NMCLI -f UUID,TYPE --mode multiline --pretty con +lang: pl_PL.UTF-8 +returncode: 0 +stdout: 841 bytes +>>> +=============================================================================== + Profile połączeń usługi NetworkManager +=============================================================================== +UUID: UUID-ethernet-REPLACED-REPLACED-REPL +TYPE: ethernet +------------------------------------------------------------------------------- +UUID: 5fcfd6d7-1e63-3332-8826-a7eda103792d +TYPE: ethernet +------------------------------------------------------------------------------- +UUID: UUID-con-xx1-REPLACED-REPLACED-REPLA +TYPE: ethernet +------------------------------------------------------------------------------- + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_003-047.expected b/clients/tests/test-client.check-on-disk/test_003-047.expected new file mode 100644 index 00000000..6522c7b2 --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_003-047.expected @@ -0,0 +1,16 @@ +location: clients/tests/test-client.py:770:test_003()/47 +cmd: $NMCLI -f UUID,TYPE --mode tabular con +lang: C +returncode: 0 +stdout: 192 bytes +>>> +UUID TYPE +UUID-ethernet-REPLACED-REPLACED-REPL ethernet +5fcfd6d7-1e63-3332-8826-a7eda103792d ethernet +UUID-con-xx1-REPLACED-REPLACED-REPLA ethernet + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_003-048.expected b/clients/tests/test-client.check-on-disk/test_003-048.expected new file mode 100644 index 00000000..08d3ae95 --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_003-048.expected @@ -0,0 +1,16 @@ +location: clients/tests/test-client.py:770:test_003()/48 +cmd: $NMCLI -f UUID,TYPE --mode tabular con +lang: pl_PL.UTF-8 +returncode: 0 +stdout: 192 bytes +>>> +UUID TYPE +UUID-ethernet-REPLACED-REPLACED-REPL ethernet +5fcfd6d7-1e63-3332-8826-a7eda103792d ethernet +UUID-con-xx1-REPLACED-REPLACED-REPLA ethernet + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_003-049.expected b/clients/tests/test-client.check-on-disk/test_003-049.expected new file mode 100644 index 00000000..3f8f3060 --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_003-049.expected @@ -0,0 +1,15 @@ +location: clients/tests/test-client.py:773:test_003()/49 +cmd: $NMCLI -f UUID,TYPE --mode tabular --terse con +lang: C +returncode: 0 +stdout: 156 bytes +>>> +UUID-ethernet-REPLACED-REPLACED-REPL:802-3-ethernet +5fcfd6d7-1e63-3332-8826-a7eda103792d:802-3-ethernet +UUID-con-xx1-REPLACED-REPLACED-REPLA:802-3-ethernet + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_003-050.expected b/clients/tests/test-client.check-on-disk/test_003-050.expected new file mode 100644 index 00000000..dea01fd2 --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_003-050.expected @@ -0,0 +1,15 @@ +location: clients/tests/test-client.py:773:test_003()/50 +cmd: $NMCLI -f UUID,TYPE --mode tabular --terse con +lang: pl_PL.UTF-8 +returncode: 0 +stdout: 156 bytes +>>> +UUID-ethernet-REPLACED-REPLACED-REPL:802-3-ethernet +5fcfd6d7-1e63-3332-8826-a7eda103792d:802-3-ethernet +UUID-con-xx1-REPLACED-REPLACED-REPLA:802-3-ethernet + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_003-051.expected b/clients/tests/test-client.check-on-disk/test_003-051.expected new file mode 100644 index 00000000..7e4dd471 --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_003-051.expected @@ -0,0 +1,20 @@ +location: clients/tests/test-client.py:776:test_003()/51 +cmd: $NMCLI -f UUID,TYPE --mode tabular --pretty con +lang: C +returncode: 0 +stdout: 394 bytes +>>> +====================================== + NetworkManager connection profiles +====================================== +UUID TYPE +-------------------------------------------------------------------------------------- +UUID-ethernet-REPLACED-REPLACED-REPL ethernet +5fcfd6d7-1e63-3332-8826-a7eda103792d ethernet +UUID-con-xx1-REPLACED-REPLACED-REPLA ethernet + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_003-052.expected b/clients/tests/test-client.check-on-disk/test_003-052.expected new file mode 100644 index 00000000..3d6c2eca --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_003-052.expected @@ -0,0 +1,20 @@ +location: clients/tests/test-client.py:776:test_003()/52 +cmd: $NMCLI -f UUID,TYPE --mode tabular --pretty con +lang: pl_PL.UTF-8 +returncode: 0 +stdout: 414 bytes +>>> +========================================== + Profile połączeń usługi NetworkManager +========================================== +UUID TYPE +------------------------------------------------------------------------------------------ +UUID-ethernet-REPLACED-REPLACED-REPL ethernet +5fcfd6d7-1e63-3332-8826-a7eda103792d ethernet +UUID-con-xx1-REPLACED-REPLACED-REPLA ethernet + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_003-053.expected b/clients/tests/test-client.check-on-disk/test_003-053.expected new file mode 100644 index 00000000..dd92ec68 --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_003-053.expected @@ -0,0 +1,115 @@ +location: clients/tests/test-client.py:779:test_003()/53 +cmd: $NMCLI con s ethernet +lang: C +returncode: 0 +stdout: 4848 bytes +>>> +connection.id: ethernet +connection.uuid: UUID-ethernet-REPLACED-REPLACED-REPL +connection.stable-id: -- +connection.type: 802-3-ethernet +connection.interface-name: -- +connection.autoconnect: yes +connection.autoconnect-priority: 0 +connection.autoconnect-retries: -1 (default) +connection.auth-retries: -1 +connection.timestamp: 0 +connection.read-only: no +connection.permissions: -- +connection.zone: -- +connection.master: -- +connection.slave-type: -- +connection.autoconnect-slaves: -1 (default) +connection.secondaries: -- +connection.gateway-ping-timeout: 0 +connection.metered: unknown +connection.lldp: default +connection.mdns: -1 (default) +802-3-ethernet.port: -- +802-3-ethernet.speed: 0 +802-3-ethernet.duplex: -- +802-3-ethernet.auto-negotiate: no +802-3-ethernet.mac-address: -- +802-3-ethernet.cloned-mac-address: -- +802-3-ethernet.generate-mac-address-mask:-- +802-3-ethernet.mac-address-blacklist: -- +802-3-ethernet.mtu: auto +802-3-ethernet.s390-subchannels: -- +802-3-ethernet.s390-nettype: -- +802-3-ethernet.s390-options: -- +802-3-ethernet.wake-on-lan: default +802-3-ethernet.wake-on-lan-password: -- +ipv4.method: auto +ipv4.dns: -- +ipv4.dns-search: -- +ipv4.dns-options: "" +ipv4.dns-priority: 0 +ipv4.addresses: -- +ipv4.gateway: -- +ipv4.routes: -- +ipv4.route-metric: -1 +ipv4.route-table: 0 (unspec) +ipv4.ignore-auto-routes: no +ipv4.ignore-auto-dns: no +ipv4.dhcp-client-id: -- +ipv4.dhcp-timeout: 0 (default) +ipv4.dhcp-send-hostname: yes +ipv4.dhcp-hostname: -- +ipv4.dhcp-fqdn: -- +ipv4.never-default: no +ipv4.may-fail: yes +ipv4.dad-timeout: -1 (default) +ipv6.method: auto +ipv6.dns: -- +ipv6.dns-search: -- +ipv6.dns-options: "" +ipv6.dns-priority: 0 +ipv6.addresses: -- +ipv6.gateway: -- +ipv6.routes: -- +ipv6.route-metric: -1 +ipv6.route-table: 0 (unspec) +ipv6.ignore-auto-routes: no +ipv6.ignore-auto-dns: no +ipv6.never-default: no +ipv6.may-fail: yes +ipv6.ip6-privacy: -1 (unknown) +ipv6.addr-gen-mode: stable-privacy +ipv6.dhcp-send-hostname: yes +ipv6.dhcp-hostname: -- +ipv6.token: -- +proxy.method: none +proxy.browser-only: no +proxy.pac-url: -- +proxy.pac-script: -- +GENERAL.NAME: ethernet +GENERAL.UUID: UUID-ethernet-REPLACED-REPLACED-REPL +GENERAL.DEVICES: eth0 +GENERAL.STATE: deactivating +GENERAL.DEFAULT: no +GENERAL.DEFAULT6: no +GENERAL.SPEC-OBJECT: -- +GENERAL.VPN: no +GENERAL.DBUS-PATH: /org/freedesktop/NetworkManager/ActiveConnection/1 +GENERAL.CON-PATH: /org/freedesktop/NetworkManager/Settings/Connection/3 +GENERAL.ZONE: -- +GENERAL.MASTER-PATH: -- + +GENERAL.NAME: ethernet +GENERAL.UUID: UUID-ethernet-REPLACED-REPLACED-REPL +GENERAL.DEVICES: eth1 +GENERAL.STATE: activated +GENERAL.DEFAULT: no +GENERAL.DEFAULT6: no +GENERAL.SPEC-OBJECT: -- +GENERAL.VPN: no +GENERAL.DBUS-PATH: /org/freedesktop/NetworkManager/ActiveConnection/2 +GENERAL.CON-PATH: /org/freedesktop/NetworkManager/Settings/Connection/3 +GENERAL.ZONE: -- +GENERAL.MASTER-PATH: -- + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_003-054.expected b/clients/tests/test-client.check-on-disk/test_003-054.expected new file mode 100644 index 00000000..7379f872 --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_003-054.expected @@ -0,0 +1,115 @@ +location: clients/tests/test-client.py:779:test_003()/54 +cmd: $NMCLI con s ethernet +lang: pl_PL.UTF-8 +returncode: 0 +stdout: 4872 bytes +>>> +connection.id: ethernet +connection.uuid: UUID-ethernet-REPLACED-REPLACED-REPL +connection.stable-id: -- +connection.type: 802-3-ethernet +connection.interface-name: -- +connection.autoconnect: tak +connection.autoconnect-priority: 0 +connection.autoconnect-retries: -1 (default) +connection.auth-retries: -1 +connection.timestamp: 0 +connection.read-only: nie +connection.permissions: -- +connection.zone: -- +connection.master: -- +connection.slave-type: -- +connection.autoconnect-slaves: -1 (default) +connection.secondaries: -- +connection.gateway-ping-timeout: 0 +connection.metered: nieznane +connection.lldp: default +connection.mdns: -1 (default) +802-3-ethernet.port: -- +802-3-ethernet.speed: 0 +802-3-ethernet.duplex: -- +802-3-ethernet.auto-negotiate: nie +802-3-ethernet.mac-address: -- +802-3-ethernet.cloned-mac-address: -- +802-3-ethernet.generate-mac-address-mask:-- +802-3-ethernet.mac-address-blacklist: -- +802-3-ethernet.mtu: automatyczne +802-3-ethernet.s390-subchannels: -- +802-3-ethernet.s390-nettype: -- +802-3-ethernet.s390-options: -- +802-3-ethernet.wake-on-lan: default +802-3-ethernet.wake-on-lan-password: -- +ipv4.method: auto +ipv4.dns: -- +ipv4.dns-search: -- +ipv4.dns-options: "" +ipv4.dns-priority: 0 +ipv4.addresses: -- +ipv4.gateway: -- +ipv4.routes: -- +ipv4.route-metric: -1 +ipv4.route-table: 0 (unspec) +ipv4.ignore-auto-routes: nie +ipv4.ignore-auto-dns: nie +ipv4.dhcp-client-id: -- +ipv4.dhcp-timeout: 0 (default) +ipv4.dhcp-send-hostname: tak +ipv4.dhcp-hostname: -- +ipv4.dhcp-fqdn: -- +ipv4.never-default: nie +ipv4.may-fail: tak +ipv4.dad-timeout: -1 (default) +ipv6.method: auto +ipv6.dns: -- +ipv6.dns-search: -- +ipv6.dns-options: "" +ipv6.dns-priority: 0 +ipv6.addresses: -- +ipv6.gateway: -- +ipv6.routes: -- +ipv6.route-metric: -1 +ipv6.route-table: 0 (unspec) +ipv6.ignore-auto-routes: nie +ipv6.ignore-auto-dns: nie +ipv6.never-default: nie +ipv6.may-fail: tak +ipv6.ip6-privacy: -1 (unknown) +ipv6.addr-gen-mode: stable-privacy +ipv6.dhcp-send-hostname: tak +ipv6.dhcp-hostname: -- +ipv6.token: -- +proxy.method: none +proxy.browser-only: nie +proxy.pac-url: -- +proxy.pac-script: -- +GENERAL.NAME: ethernet +GENERAL.UUID: UUID-ethernet-REPLACED-REPLACED-REPL +GENERAL.DEVICES: eth0 +GENERAL.STATE: deactivating +GENERAL.DEFAULT: nie +GENERAL.DEFAULT6: nie +GENERAL.SPEC-OBJECT: -- +GENERAL.VPN: nie +GENERAL.DBUS-PATH: /org/freedesktop/NetworkManager/ActiveConnection/1 +GENERAL.CON-PATH: /org/freedesktop/NetworkManager/Settings/Connection/3 +GENERAL.ZONE: -- +GENERAL.MASTER-PATH: -- + +GENERAL.NAME: ethernet +GENERAL.UUID: UUID-ethernet-REPLACED-REPLACED-REPL +GENERAL.DEVICES: eth1 +GENERAL.STATE: activated +GENERAL.DEFAULT: nie +GENERAL.DEFAULT6: nie +GENERAL.SPEC-OBJECT: -- +GENERAL.VPN: nie +GENERAL.DBUS-PATH: /org/freedesktop/NetworkManager/ActiveConnection/2 +GENERAL.CON-PATH: /org/freedesktop/NetworkManager/Settings/Connection/3 +GENERAL.ZONE: -- +GENERAL.MASTER-PATH: -- + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_004-001.expected b/clients/tests/test-client.check-on-disk/test_004-001.expected new file mode 100644 index 00000000..0723731d --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_004-001.expected @@ -0,0 +1,13 @@ +location: clients/tests/test-client.py:789:test_004()/1 +cmd: $NMCLI c add type wifi ifname '*' ssid foobar con-name con-xx1 +lang: C +returncode: 0 +stdout: 80 bytes +>>> +Connection 'con-xx1' (UUID-con-xx1-REPLACED-REPLACED-REPLA) successfully added. + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_004-002.expected b/clients/tests/test-client.check-on-disk/test_004-002.expected new file mode 100644 index 00000000..37c88812 --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_004-002.expected @@ -0,0 +1,13 @@ +location: clients/tests/test-client.py:791:test_004()/2 +cmd: $NMCLI connection mod con-xx1 ip.gateway '' +lang: C +returncode: 2 +stdout: 0 bytes +>>> + +<<< +stderr: 75 bytes +>>> +Error: invalid or not allowed setting 'ip': 'ip' is ambiguous: ipv4, ipv6. + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_004-003.expected b/clients/tests/test-client.check-on-disk/test_004-003.expected new file mode 100644 index 00000000..e76bb0bf --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_004-003.expected @@ -0,0 +1,12 @@ +location: clients/tests/test-client.py:792:test_004()/3 +cmd: $NMCLI connection mod con-xx1 ipv4.gateway 172.16.0.1 +lang: C +returncode: 0 +stdout: 0 bytes +>>> + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_004-004.expected b/clients/tests/test-client.check-on-disk/test_004-004.expected new file mode 100644 index 00000000..17233cd1 --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_004-004.expected @@ -0,0 +1,12 @@ +location: clients/tests/test-client.py:793:test_004()/4 +cmd: $NMCLI connection mod con-xx1 ipv6.gateway ::99 +lang: C +returncode: 0 +stdout: 0 bytes +>>> + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_004-005.expected b/clients/tests/test-client.check-on-disk/test_004-005.expected new file mode 100644 index 00000000..a4b0a592 --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_004-005.expected @@ -0,0 +1,13 @@ +location: clients/tests/test-client.py:794:test_004()/5 +cmd: $NMCLI connection mod con-xx1 802.abc '' +lang: C +returncode: 2 +stdout: 0 bytes +>>> + +<<< +stderr: 116 bytes +>>> +Error: invalid or not allowed setting '802': '802' is ambiguous: 802-11-wireless, 802-11-wireless-security, 802-1x. + +<<< diff --git a/clients/tests/test-client.check-on-disk/test_004-006.expected b/clients/tests/test-client.check-on-disk/test_004-006.expected new file mode 100644 index 00000000..9fd5fe42 --- /dev/null +++ b/clients/tests/test-client.check-on-disk/test_004-006.expected @@ -0,0 +1,12 @@ +location: clients/tests/test-client.py:795:test_004()/6 +cmd: $NMCLI connection mod con-xx1 802-11-wireless.band a +lang: C +returncode: 0 +stdout: 0 bytes +>>> + +<<< +stderr: 0 bytes +>>> + +<<< diff --git a/clients/tests/test-client.py b/clients/tests/test-client.py new file mode 100755 index 00000000..a8e107a0 --- /dev/null +++ b/clients/tests/test-client.py @@ -0,0 +1,856 @@ +#!/usr/bin/env python + +from __future__ import print_function + +import sys + +try: + import gi + from gi.repository import GLib + + gi.require_version('NM', '1.0') + from gi.repository import NM +except Exception as e: + GLib = None + NM = None + +import os +import errno +import unittest +import socket +import itertools +import subprocess +import shlex +import re +import dbus +import time +import dbus.service +import dbus.mainloop.glib + +# The test can be configured via the following environment variables: +ENV_NM_TEST_CLIENT_BUILDDIR = 'NM_TEST_CLIENT_BUILDDIR' +ENV_NM_TEST_CLIENT_NMCLI_PATH = 'NM_TEST_CLIENT_NMCLI_PATH' +ENV_NM_TEST_CLIENT_CHECK_L10N = 'NM_TEST_CLIENT_CHECK_L10N' +ENV_NM_TEST_REGENERATE = 'NM_TEST_REGENERATE' + +############################################################################### + +class PathConfiguration: + + @staticmethod + def srcdir(): + # this is the directory where the test script itself lies. + # Based on this directory, we find other parts that we expect + # in the source repository. + return os.path.dirname(os.path.abspath(__file__)) + + @staticmethod + def top_srcdir(): + return os.path.abspath(PathConfiguration.srcdir() + "/../..") + + @staticmethod + def test_networkmanager_service_path(): + v = os.path.abspath(PathConfiguration.top_srcdir() + "/tools/test-networkmanager-service.py") + assert os.path.exists(v), ("Cannot find test server at \"%s\"" % (v)) + return v + +############################################################################### + +os.sys.path.append(os.path.abspath(PathConfiguration.top_srcdir() + '/examples/python')) +import nmex + +dbus_session_inited = False + +_DEFAULT_ARG = object() + +############################################################################### + +class Util: + + @staticmethod + def python_has_version(major, minor = 0): + return sys.version_info[0] > major \ + or ( sys.version_info[0] == major \ + and sys.version_info[1] >= minor) + + @staticmethod + def is_string(s): + if Util.python_has_version(3): + t = str + else: + t = basestring + return isinstance(s, t) + + _find_unsafe = re.compile(r'[^\w@%+=:,./-]', + re.ASCII if sys.version_info[0] >= 3 else 0).search + + @staticmethod + def quote(s): + if Util.python_has_version(3, 3): + return shlex.quote(s) + if not s: + return "''" + if Util._find_unsafe(s) is None: + return s + return "'" + s.replace("'", "'\"'\"'") + "'" + + @staticmethod + def popen_wait(p, timeout = None): + # wait() has a timeout argument only since 3.3 + if Util.python_has_version(3, 3): + return p.wait(timeout) + if timeout is None: + return p.wait() + start = nmex.nm_boot_time_ns() + while True: + if p.poll() is not None: + return p.returncode + if start + (timeout * 1000000000) < nmex.nm_boot_time_ns(): + raise Exception("timeout expired") + time.sleep(0.05) + + @staticmethod + def iter_single(itr, min_num = 1, max_num = 1): + itr = list(itr) + n = 0 + v = None + for c in itr: + n += 1 + if n > 1: + break + v = c + if n < min_num: + raise AssertionError("Expected at least %s elements, but %s found" % (min_num, n)) + if n > max_num: + raise AssertionError("Expected at most %s elements, but %s found" % (max_num, n)) + return v + + @staticmethod + def file_read(filename): + try: + with open(filename, 'rb') as f: + return f.read() + except: + return None + + @staticmethod + def replace_text(text, replace_arr): + if not replace_arr: + return text + text = [text] + for replace in replace_arr: + try: + v_search = replace[0]() + except TypeError: + v_search = replace[0] + assert v_search is None or Util.is_string(v_search) + if not v_search: + continue + v_replace = replace[1] + v_search = v_search.encode('utf-8') + v_replace = v_replace.encode('utf-8') + text2 = [] + for t in text: + if isinstance(t, tuple): + text2.append(t) + continue + t2 = t.split(v_search) + text2.append(t2[0]) + for t3 in t2[1:]: + text2.append( (v_replace,) ) + text2.append(t3) + text = text2 + return b''.join([(t[0] if isinstance(t, tuple) else t) for t in text]) + +############################################################################### + +class Configuration: + + def __init__(self): + self._values = {} + + def get(self, name): + v = self._values.get(name, None) + if name in self._values: + return v + if name == ENV_NM_TEST_CLIENT_BUILDDIR: + v = os.environ.get(ENV_NM_TEST_CLIENT_BUILDDIR, PathConfiguration.top_srcdir()) + if not os.path.isdir(v): + raise Exception("Missing builddir. Set NM_TEST_CLIENT_BUILDDIR?") + elif name == ENV_NM_TEST_CLIENT_NMCLI_PATH: + v = os.environ.get(ENV_NM_TEST_CLIENT_NMCLI_PATH, None) + if v is None: + try: + v = os.path.abspath(self.get(ENV_NM_TEST_CLIENT_BUILDDIR) + "/clients/cli/nmcli") + except: + pass + if not os.path.exists(v): + raise Exception("Missing nmcli binary. Set NM_TEST_CLIENT_NMCLI_PATH?") + elif name == ENV_NM_TEST_CLIENT_CHECK_L10N: + # if we test locales other than 'C', the output of nmcli depends on whether + # nmcli can load the translations. Unfortunately, I cannot find a way to + # make gettext use the po/*.gmo files from the build-dir. + # + # hence, such tests only work, if you also issue `make-install` + # + # Only by setting NM_TEST_CLIENT_CHECK_L10N=1, these tests are included + # as well. + v = (os.environ.get(ENV_NM_TEST_CLIENT_CHECK_L10N, '0') == '1') + elif name == ENV_NM_TEST_REGENERATE: + # in the "regenerate" mode, the tests will rewrite the files on disk against + # which we assert. That is useful, if there are intentional changes and + # we want to regenerate the expected output. + v = (os.environ.get(ENV_NM_TEST_REGENERATE, '0') == '1') + else: + raise Exception() + self._values[name] = v + return v + +conf = Configuration() + +############################################################################### + +class NMStubServer: + + @staticmethod + def _conn_get_main_object(conn): + try: + return conn.get_object('org.freedesktop.NetworkManager', '/org/freedesktop/NetworkManager') + except: + return None + + def __init__(self): + service_path = PathConfiguration.test_networkmanager_service_path() + self._conn = dbus.SessionBus() + p = subprocess.Popen([sys.executable, service_path], + stdin = subprocess.PIPE) + + start = nmex.nm_boot_time_ns() + while True: + if p.poll() is not None: + p.stdin.close() + if p.returncode == 77: + raise unittest.SkipTest('the stub service %s exited with status 77' % (service_path)) + raise Exception('the stub service %s exited unexpectedly' % (service_path)) + nmobj = self._conn_get_main_object(self._conn) + if nmobj is not None: + break + if (nmex.nm_boot_time_ns() - start) / 1000000 >= 2000: + p.stdin.close() + p.kill() + Util.popen_wait(p, 1000) + raise Exception("after starting stub service the D-Bus name was not claimed in time") + + self._nmobj = nmobj + self._nmiface = dbus.Interface(nmobj, "org.freedesktop.NetworkManager.LibnmGlibTest") + self._p = p + + def shutdown(self): + self._nmobj = None + self._nmiface = None + self._conn = None + self._p.stdin.close() + self._p.kill() + Util.popen_wait(self._p, 1000) + self._p = None + if self._conn_get_main_object(self._conn) is not None: + raise Exception("Stub service is not still here although it should shut down") + + class _MethodProxy: + def __init__(self, parent, method_name): + self._parent = parent + self._method_name = method_name + def __call__(self, *args, **kwargs): + dbus_iface = kwargs.pop('dbus_iface', None) + if dbus_iface is None: + dbus_iface = self._parent._nmiface + method = dbus_iface.get_dbus_method(self._method_name) + if kwargs: + # for convenience, we allow the caller to specify arguments + # as kwargs. In this case, we construct a a{sv} array as last argument. + kwargs2 = {} + args = list(args) + args.append(kwargs2) + for k in kwargs.keys(): + kwargs2[k] = kwargs[k] + return method(*args) + + def __getattr__(self, member): + if not member.startswith("op_"): + raise AttributeError(member) + return self._MethodProxy(self, member[3:]) + + def addConnection(self, connection, verify_connection = True): + return self.op_AddConnection(connection, verify_connection) + + def findConnectionUuid(self, con_id): + try: + u = Util.iter_single(self.op_FindConnections(con_id = con_id))[1] + assert u, ("Invalid uuid %s" % (u)) + except Exception as e: + raise AssertionError("Unexpectedly not found connection %s: %s" % (con_id, str(e))) + return u + + def setProperty(self, path, propname, value, iface_name = None): + if iface_name is None: + iface_name = '' + self.op_SetProperties([ + (path, [ + (iface_name, [ + (propname, value), + ]), + ]), + ]) + +############################################################################### + +class AsyncProcess(): + + def __init__(self, + args, + env, + complete_cb): + self._args = args + self._env = env + self._complete_cb = complete_cb + + def start(self): + if not hasattr(self, '_p'): + self._p = subprocess.Popen(self._args, + stdout = subprocess.PIPE, + stderr = subprocess.PIPE, + env = self._env) + + def wait(self): + + self.start() + + Util.popen_wait(self._p, 2000) + + (returncode, stdout, stderr) = (self._p.returncode, self._p.stdout.read(), self._p.stderr.read()) + + self._p.stdout.close() + self._p.stderr.close() + self._p = None + + self._complete_cb(self, returncode, stdout, stderr) + +############################################################################### + +file_list = [] + +class NmTestBase(unittest.TestCase): + pass + +class TestNmcli(NmTestBase): + + def call_nmcli_l(self, + args, + check_on_disk = _DEFAULT_ARG, + expected_returncode = _DEFAULT_ARG, + expected_stdout = _DEFAULT_ARG, + expected_stderr = _DEFAULT_ARG, + replace_stdout = None, + replace_stderr = None, + sort_lines_stdout = False, + extra_env = None, + sync_barrier = False): + frame = sys._getframe(1) + for lang in [ 'C', 'pl' ]: + self._call_nmcli(args, + lang, + check_on_disk, + expected_returncode, + expected_stdout, + expected_stderr, + replace_stdout, + replace_stderr, + sort_lines_stdout, + extra_env, + sync_barrier, + frame) + + + def call_nmcli(self, + args, + langs = None, + lang = None, + check_on_disk = _DEFAULT_ARG, + expected_returncode = _DEFAULT_ARG, + expected_stdout = _DEFAULT_ARG, + expected_stderr = _DEFAULT_ARG, + replace_stdout = None, + replace_stderr = None, + sort_lines_stdout = False, + extra_env = None, + sync_barrier = None): + + frame = sys._getframe(1) + + if langs is not None: + assert lang is None + else: + if lang is None: + lang = 'C' + langs = [lang] + + if sync_barrier is None: + sync_barrier = (len(langs) == 1) + + for lang in langs: + self._call_nmcli(args, + lang, + check_on_disk, + expected_returncode, + expected_stdout, + expected_stderr, + replace_stdout, + replace_stderr, + sort_lines_stdout, + extra_env, + sync_barrier, + frame) + + def _call_nmcli(self, + args, + lang, + check_on_disk, + expected_returncode, + expected_stdout, + expected_stderr, + replace_stdout, + replace_stderr, + sort_lines_stdout, + extra_env, + sync_barrier, + frame): + + if sync_barrier: + self.async_wait() + + calling_fcn = frame.f_code.co_name + calling_num = self._calling_num.get(calling_fcn, 0) + 1 + self._calling_num[calling_fcn] = calling_num + + test_name = '%s-%03d' % (calling_fcn, calling_num) + + # we cannot use frame.f_code.co_filename directly, because it might be different depending + # on where the file lies and which is CWD. We still want to give the location of + # the file, so that the user can easier find the source (when looking at the .expected files) + script_filename = 'clients/tests/test-client.py' + self.assertTrue(os.path.abspath(frame.f_code.co_filename).endswith(script_filename)) + + calling_location = '%s:%d:%s()/%d' % (script_filename, frame.f_lineno, frame.f_code.co_name, calling_num) + + if lang is None or lang == 'C': + lang = 'C' + language = '' + elif lang is 'de': + lang = 'de_DE.utf8' + language = 'de' + elif lang is 'pl': + lang = 'pl_PL.UTF-8' + language = 'pl' + else: + self.fail('invalid language %s' % (lang)) + + env = {} + if extra_env is not None: + for k, v in extra_env.items(): + env[k] = v + for k in ['LD_LIBRARY_PATH', + 'DBUS_SESSION_BUS_ADDRESS']: + val = os.environ.get(k, None) + if val is not None: + env[k] = val + env['LANG'] = lang + env['LANGUAGE'] = language + env['LIBNM_USE_SESSION_BUS'] = '1' + env['LIBNM_USE_NO_UDEV'] = '1' + env['TERM'] = 'linux' + + args = [conf.get(ENV_NM_TEST_CLIENT_NMCLI_PATH)] + list(args) + + if replace_stdout is not None: + replace_stdout = list(replace_stdout) + if replace_stderr is not None: + replace_stderr = list(replace_stderr) + + if check_on_disk is _DEFAULT_ARG: + check_on_disk = ( expected_returncode is _DEFAULT_ARG + and expected_stdout is _DEFAULT_ARG + and expected_stderr is _DEFAULT_ARG) + if expected_returncode is _DEFAULT_ARG: + expected_returncode = None + if expected_stdout is _DEFAULT_ARG: + expected_stdout = None + if expected_stderr is _DEFAULT_ARG: + expected_stderr = None + + def complete_cb(async_job, + returncode, + stdout, + stderr): + + stdout = Util.replace_text(stdout, replace_stdout) + stderr = Util.replace_text(stderr, replace_stderr) + + if sort_lines_stdout: + stdout = b'\n'.join(sorted(stdout.split(b'\n'))) + + ignore_l10n_diff = ( lang != 'C' + and not conf.get(ENV_NM_TEST_CLIENT_CHECK_L10N)) + + if expected_stderr is not None: + if expected_stderr != stderr: + if ignore_l10n_diff: + self._skip_test_for_l10n_diff.append(test_name) + else: + self.assertEqual(expected_stderr, stderr) + if expected_stdout is not None: + if expected_stdout != stdout: + if ignore_l10n_diff: + self._skip_test_for_l10n_diff.append(test_name) + else: + self.assertEqual(expected_stdout, stdout) + if expected_returncode is not None: + self.assertEqual(expected_returncode, returncode) + + dirname = PathConfiguration.srcdir() + '/test-client.check-on-disk' + basename = test_name + '.expected' + filename = os.path.abspath(dirname + '/' + basename) + + if not check_on_disk: + if os.path.exists(filename): + self.fail("The file '%s' exists, although we expect it not to." % (filename)) + return + + file_list.append(basename) + + content_old = Util.file_read(filename) + + content_new = ('location: %s\n' % (calling_location)).encode('utf8') + \ + ('cmd: $NMCLI %s\n' % (' '.join([Util.quote(a) for a in args[1:]]))).encode('utf8') + \ + ('lang: %s\n' % (lang)).encode('utf8') + \ + ('returncode: %d\n' % (returncode)).encode('utf8') + \ + ('stdout: %d bytes\n>>>\n' % (len(stdout))).encode('utf8') + \ + stdout + \ + ('\n<<<\nstderr: %d bytes\n>>>\n' % (len(stderr))).encode('utf8') + \ + stderr + \ + '\n<<<\n'.encode('utf8') + + w = conf.get(ENV_NM_TEST_REGENERATE) + + if content_old is not None: + if content_old == content_new: + return + + if not w: + if ignore_l10n_diff: + self._skip_test_for_l10n_diff.append(test_name) + return + print("\n\n\nThe file '%s' does not have the expected content:" % (filename)) + print("ACTUAL OUTPUT:\n[[%s]]\n" % (content_new)) + print("EXPECT OUTPUT:\n[[%s]]\n" % (content_old)) + print("Let the test write the file by rerunning with NM_TEST_REGENERATE=1\n\n") + raise AssertionError("Unexpected output of command, expected %s. Rerun test with NM_TEST_REGENERATE=1 to regenerate files" % (filename)) + else: + if not w: + self.fail("The file '%s' does not exist. Let the test write the file by rerunning with NM_TEST_REGENERATE=1" % (filename)) + + try: + if not os.path.exists(dirname): + os.makedirs(dirname) + with open(filename, 'wb') as content_file: + content_file.write(content_new) + except Exception as e: + self.fail("Failure to write '%s': %s" % (filename, e)) + + async_job = AsyncProcess(args = args, + env = env, + complete_cb = complete_cb) + + self._async_jobs.append(async_job) + + if sync_barrier: + self.async_wait() + else: + self.async_start() + + def async_start(self): + # limit number parallel running jobs + for async_job in self._async_jobs[0:10]: + async_job.start() + + def async_wait(self): + while self._async_jobs: + self.async_start() + self._async_jobs.pop(0).wait() + + def setUp(self): + if not dbus_session_inited: + self.skipTest("Own D-Bus session for testing is not initialized. Do you have dbus-run-session available?") + if NM is None: + self.skipTest("gi.NM is not available. Did you build with introspection?") + self.srv = NMStubServer() + self._calling_num = {} + self._skip_test_for_l10n_diff = [] + self._async_jobs = [] + + def tearDown(self): + self.async_wait() + self.srv.shutdown() + self.srv = None + self._calling_num = None + if self._skip_test_for_l10n_diff: + # nmcli loads translations from the installation path. This failure commonly + # happens because you did not install the binary in the --prefix, before + # running the test. Hence, translations are not available or differ. + msg = "Skipped asserting for localized tests %s. Set NM_TEST_CLIENT_CHECK_L10N=1 to force fail." % (','.join(self._skip_test_for_l10n_diff)) + if Util.python_has_version(3): + # python2 does not suppot skipping the test during tearDown() + self.skipTest(msg) + print(msg + "\n") + self._skip_test_for_l10n_diff = None + + def init_001(self): + self.srv.op_AddObj('WiredDevice', + iface = 'eth0') + self.srv.op_AddObj('WiredDevice', + iface = 'eth1') + self.srv.op_AddObj('WifiDevice', + iface = 'wlan0') + self.srv.op_AddObj('WifiDevice', + iface = 'wlan1') + + # add another device with an identical ifname. The D-Bus API itself + # does not enforce the ifnames are unique. + self.srv.op_AddObj('WifiDevice', + ident = 'wlan1/x', + iface = 'wlan1') + + self.srv.op_AddObj('WifiAp', + device = 'wlan0') + self.srv.op_AddObj('WifiAp', + device = 'wlan0') + self.srv.op_AddObj('WifiAp', + device = 'wlan0') + + self.srv.op_AddObj('WifiAp', + device = 'wlan1') + + self.srv.addConnection( { + 'connection': { + 'type': '802-3-ethernet', + 'id': 'con-1', + }, + }) + + def test_001(self): + + self.call_nmcli_l([]) + + self.call_nmcli_l(['-f', 'AP', '-mode', 'multiline', '-p', 'd', 'show', 'wlan0']) + + self.call_nmcli_l(['c', 's']) + + self.call_nmcli_l(['bogus', 's']) + + for mode in [[], + ['--mode', 'tabular'], + ['--mode', 'multiline']]: + for fmt in [[], + ['--pretty'], + ['--terse']]: + self.call_nmcli_l(mode + fmt + ['general', 'permissions']) + + def test_002(self): + self.init_001() + + self.call_nmcli_l(['d']) + + self.call_nmcli_l(['-f', 'all', 'd']) + + self.call_nmcli_l([]) + + self.call_nmcli_l(['-f', 'AP', '-mode', 'multiline', 'd', 'show', 'wlan0']) + self.call_nmcli_l(['-f', 'AP', '-mode', 'multiline', '-p', 'd', 'show', 'wlan0']) + self.call_nmcli_l(['-f', 'AP', '-mode', 'multiline', '-t', 'd', 'show', 'wlan0']) + self.call_nmcli_l(['-f', 'AP', '-mode', 'tabular', 'd', 'show', 'wlan0']) + self.call_nmcli_l(['-f', 'AP', '-mode', 'tabular', '-p', 'd', 'show', 'wlan0']) + self.call_nmcli_l(['-f', 'AP', '-mode', 'tabular', '-t', 'd', 'show', 'wlan0']) + + self.call_nmcli_l(['-f', 'ALL', 'd', 'wifi']) + + self.call_nmcli_l(['c']) + + self.call_nmcli_l(['c', 's', 'con-1']) + + def test_003(self): + self.init_001() + + replace_stdout = [] + + replace_stdout.append((lambda: self.srv.findConnectionUuid('con-xx1'), 'UUID-con-xx1-REPLACED-REPLACED-REPLA')) + + self.call_nmcli(['c', 'add', 'type', 'ethernet', 'ifname', '*', 'con-name', 'con-xx1'], + replace_stdout = replace_stdout) + + self.call_nmcli_l(['c', 's'], + replace_stdout = replace_stdout) + + replace_stdout.append((lambda: self.srv.findConnectionUuid('ethernet'), 'UUID-ethernet-REPLACED-REPLACED-REPL')) + + self.call_nmcli(['c', 'add', 'type', 'ethernet', 'ifname', '*'], + replace_stdout = replace_stdout) + + self.call_nmcli_l(['c', 's'], + replace_stdout = replace_stdout) + + self.call_nmcli_l(['-f', 'ALL', 'c', 's'], + replace_stdout = replace_stdout) + + self.call_nmcli_l(['--complete-args', '-f', 'ALL', 'c', 's', ''], + replace_stdout = replace_stdout, + sort_lines_stdout = True) + + # activate the same profile on multiple devices. Our stub-implmentation + # is fine with that... although NetworkManager service would reject + # such a configuration by deactivating the profile first. But note that + # that is only an internal behavior of NetworkManager service. The D-Bus + # API perfectly allows for one profile to be active multiple times. Also + # note, that there is always a short time where one profile goes down, + # while another is activating. Hence, while real NetworkManager commonly + # does not allow that multiple profiles *stay* connected at the same + # time, there is always the possibility that a profile is activating/active + # on a device, while also activating/deactivating in parallel. + for dev in ['eth0', 'eth1']: + self.call_nmcli(['con', 'up', 'ethernet', 'ifname', dev]) + + self.call_nmcli_l(['con'], + replace_stdout = replace_stdout) + + self.call_nmcli_l(['-f', 'ALL', 'con'], + replace_stdout = replace_stdout) + + self.call_nmcli_l(['-f', 'ALL', 'con', 's', 'ethernet'], + replace_stdout = replace_stdout) + + self.call_nmcli_l(['con', 's', 'ethernet'], + replace_stdout = replace_stdout) + + self.call_nmcli_l(['-f', 'ALL', 'dev', 's', 'eth0'], + replace_stdout = replace_stdout) + + self.call_nmcli_l(['-f', 'ALL', 'dev', 'show', 'eth0'], + replace_stdout = replace_stdout) + + self.async_wait() + + self.srv.setProperty('/org/freedesktop/NetworkManager/ActiveConnection/1', + 'State', + dbus.UInt32(NM.ActiveConnectionState.DEACTIVATING)) + + self.call_nmcli_l(['-f', 'ALL', 'con'], + replace_stdout = replace_stdout) + + self.call_nmcli_l(['-f', 'UUID,TYPE', 'con'], + replace_stdout = replace_stdout) + + self.call_nmcli_l(['-f', 'UUID,TYPE', '--mode', 'multiline', 'con'], + replace_stdout = replace_stdout) + + self.call_nmcli_l(['-f', 'UUID,TYPE', '--mode', 'multiline', '--terse', 'con'], + replace_stdout = replace_stdout) + + self.call_nmcli_l(['-f', 'UUID,TYPE', '--mode', 'multiline', '--pretty', 'con'], + replace_stdout = replace_stdout) + + self.call_nmcli_l(['-f', 'UUID,TYPE', '--mode', 'tabular', 'con'], + replace_stdout = replace_stdout) + + self.call_nmcli_l(['-f', 'UUID,TYPE', '--mode', 'tabular', '--terse', 'con'], + replace_stdout = replace_stdout) + + self.call_nmcli_l(['-f', 'UUID,TYPE', '--mode', 'tabular', '--pretty', 'con'], + replace_stdout = replace_stdout) + + self.call_nmcli_l(['con', 's', 'ethernet'], + replace_stdout = replace_stdout) + + def test_004(self): + self.init_001() + + replace_stdout = [] + + replace_stdout.append((lambda: self.srv.findConnectionUuid('con-xx1'), 'UUID-con-xx1-REPLACED-REPLACED-REPLA')) + + self.call_nmcli(['c', 'add', 'type', 'wifi', 'ifname', '*', 'ssid', 'foobar', 'con-name', 'con-xx1'], + replace_stdout = replace_stdout) + + self.call_nmcli(['connection', 'mod', 'con-xx1', 'ip.gateway', '']) + self.call_nmcli(['connection', 'mod', 'con-xx1', 'ipv4.gateway', '172.16.0.1']) + self.call_nmcli(['connection', 'mod', 'con-xx1', 'ipv6.gateway', '::99']) + self.call_nmcli(['connection', 'mod', 'con-xx1', '802.abc', '']) + self.call_nmcli(['connection', 'mod', 'con-xx1', '802-11-wireless.band', 'a']) + +############################################################################### + +def main(): + global dbus_session_inited + + if len(sys.argv) >= 2 and sys.argv[1] == '--started-with-dbus-session': + dbus_session_inited = True + del sys.argv[1] + + if not dbus_session_inited: + # we don't have yet our own dbus-session. Reexec ourself with + # a new dbus-session. + try: + try: + os.execlp('dbus-run-session', 'dbus-run-session', '--', sys.executable, __file__, '--started-with-dbus-session', *sys.argv[1:]) + except OSError as e: + if e.errno != errno.ENOENT: + raise + # we have no dbus-run-session in path? Fall-through + # to skip tests gracefully + else: + raise Exception('unknown error during exec') + except Exception as e: + assert False, ("Failure to re-exec dbus-run-session: %s" % (str(e))) + + if not dbus_session_inited: + # we still don't have a D-Bus session. Probably dbus-run-session is not available. + # retry with dbus-launch + if os.system('type dbus-launch 1>/dev/null') == 0: + try: + os.execlp('bash', 'bash', '-e', '-c', + 'eval `dbus-launch --sh-syntax`;\n' + \ + 'trap "kill $DBUS_SESSION_BUS_PID" EXIT;\n' + \ + '\n' + \ + ' '.join([Util.quote(a) for a in [sys.executable, __file__, '--started-with-dbus-session'] + sys.argv[1:]]) + ' \n' + \ + '') + except Exception as e: + m = str(e) + else: + m = 'unknown error' + assert False, ('Failure to re-exec to start script with dbus-launch: %s' % (m)) + + r = unittest.main(exit = False) + + if conf.get(ENV_NM_TEST_REGENERATE): + make_filename = PathConfiguration.srcdir() + '/test-client.check-on-disk/Makefile.am' + s_new = '# generated with `NM_TEST_REGENERATE=1 make check`\n' + \ + '\n' + \ + 'clients_tests_expected_files = \\\n' + \ + ''.join([('\tclients/tests/test-client.check-on-disk/%s \\\n' % f) for f in sorted(file_list)]) + \ + '\t$(NULL)\n' + s_new = s_new.encode('utf-8') + if s_new != Util.file_read(make_filename): + with open(make_filename, 'wb') as f: + f.write(s_new) + + sys.exit(not r.result.wasSuccessful()) + +if __name__ == '__main__': + main() diff --git a/clients/tui/meson.build b/clients/tui/meson.build new file mode 100644 index 00000000..40eb4b4a --- /dev/null +++ b/clients/tui/meson.build @@ -0,0 +1,72 @@ +name = 'nmtui' + +deps = [ + newt_dep, + nm_core_dep +] + +cflags = clients_cflags + [ + '-DG_LOG_DOMAIN="@0@"'.format(name), + '-DNMLOCALEDIR="@0@"'.format(nm_localedir) +] + +subdir('newt') + +sources = files( + 'nm-editor-bindings.c', + 'nm-editor-utils.c', + 'nmt-address-list.c', + 'nmt-connect-connection-list.c', + 'nmt-device-entry.c', + 'nmt-edit-connection-list.c', + 'nmt-editor.c', + 'nmt-editor-grid.c', + 'nmt-editor-page.c', + 'nmt-editor-page-device.c', + 'nmt-editor-section.c', + 'nmt-ip-entry.c', + 'nmt-mac-entry.c', + 'nmt-mtu-entry.c', + 'nmt-page-bond.c', + 'nmt-page-bridge.c', + 'nmt-page-bridge-port.c', + 'nmt-page-dsl.c', + 'nmt-page-ethernet.c', + 'nmt-page-infiniband.c', + 'nmt-page-ip4.c', + 'nmt-page-ip6.c', + 'nmt-page-ip-tunnel.c', + 'nmt-page-ppp.c', + 'nmt-page-team.c', + 'nmt-page-team-port.c', + 'nmt-page-vlan.c', + 'nmt-page-wifi.c', + 'nmt-password-dialog.c', + 'nmt-password-fields.c', + 'nmt-route-editor.c', + 'nmt-route-entry.c', + 'nmt-route-table.c', + 'nmt-slave-list.c', + 'nmtui.c', + 'nmtui-connect.c', + 'nmtui-edit.c', + 'nmtui-hostname.c', + 'nmt-utils.c', + 'nmt-widget-list.c' +) + +deps += [ + libnm_dep, + libnmc_base_dep, + libnmt_newt_dep +] + +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/tui/newt/meson.build b/clients/tui/newt/meson.build new file mode 100644 index 00000000..aeec39da --- /dev/null +++ b/clients/tui/newt/meson.build @@ -0,0 +1,35 @@ +sources = files( + 'nmt-newt-button-box.c', + 'nmt-newt-button.c', + 'nmt-newt-checkbox.c', + 'nmt-newt-component.c', + 'nmt-newt-container.c', + 'nmt-newt-entry.c', + 'nmt-newt-entry-numeric.c', + 'nmt-newt-form.c', + 'nmt-newt-grid.c', + 'nmt-newt-hacks.c', + 'nmt-newt-label.c', + 'nmt-newt-listbox.c', + 'nmt-newt-popup.c', + 'nmt-newt-section.c', + 'nmt-newt-separator.c', + 'nmt-newt-stack.c', + 'nmt-newt-textbox.c', + 'nmt-newt-toggle-button.c', + 'nmt-newt-utils.c', + 'nmt-newt-widget.c' +) + +libnmt_newt = static_library( + 'nmt-newt', + sources: sources + [libnm_enum[1]], + include_directories: libnm_inc, + dependencies: deps, + c_args: cflags +) + +libnmt_newt_dep = declare_dependency( + include_directories: include_directories('.'), + link_with: libnmt_newt +) diff --git a/clients/tui/newt/nmt-newt-button-box.h b/clients/tui/newt/nmt-newt-button-box.h index dec2c347..2dce1689 100644 --- a/clients/tui/newt/nmt-newt-button-box.h +++ b/clients/tui/newt/nmt-newt-button-box.h @@ -57,5 +57,4 @@ void nmt_newt_button_box_add_widget_start (NmtNewtButtonBox *bbox, void nmt_newt_button_box_add_widget_end (NmtNewtButtonBox *bbox, NmtNewtWidget *widget); - #endif /* NMT_NEWT_BUTTON_BOX_H */ diff --git a/clients/tui/newt/nmt-newt-section.c b/clients/tui/newt/nmt-newt-section.c index 38152c96..34073454 100644 --- a/clients/tui/newt/nmt-newt-section.c +++ b/clients/tui/newt/nmt-newt-section.c @@ -304,7 +304,7 @@ adjust_border_for_allocation (NmtNewtSectionPrivate *priv, label = nmt_newt_label_new (line_glyph); g_ptr_array_add (priv->border_line_labels, label); nmt_newt_grid_add (NMT_NEWT_GRID (priv->border_grid), label, 0, i + 1); - } else + } else nmt_newt_widget_set_visible (priv->border_line_labels->pdata[i], TRUE); } nmt_newt_widget_set_visible (priv->border_end_label, TRUE); diff --git a/clients/tui/newt/nmt-newt-utils.c b/clients/tui/newt/nmt-newt-utils.c index f37a851e..e8866500 100644 --- a/clients/tui/newt/nmt-newt-utils.c +++ b/clients/tui/newt/nmt-newt-utils.c @@ -65,9 +65,9 @@ nmt_newt_dialog_g_log_handler (const char *log_domain, } full_message = g_strdup_printf ("%s%s%s%s%s", - log_domain ? log_domain : "", + log_domain ?: "", log_domain && level_name ? " " : "", - level_name ? level_name : "", + level_name ?: "", log_domain || level_name ? ": " : "", message); @@ -87,7 +87,7 @@ nmt_newt_dialog_g_log_handler (const char *log_domain, newtGridSetField (grid, 0, 1, NEWT_GRID_COMPONENT, ok, 0, 1, 0, 0, NEWT_ANCHOR_RIGHT, 0); - newtGridWrappedWindow (grid, (char *) (level_name ? level_name : "")); + newtGridWrappedWindow (grid, (char *) (level_name ?: "")); newtGridFree (grid, TRUE); form = newtForm (NULL, NULL, 0); @@ -359,21 +359,11 @@ nmt_newt_edit_string (const char *data) goto done; } -#if GLIB_CHECK_VERSION (2, 34, 0) - G_GNUC_BEGIN_IGNORE_DEPRECATIONS if (!g_spawn_check_exit_status (status, &error)) { nmt_newt_message_dialog (_("Editor failed: %s"), error->message); g_error_free (error); goto done; } - G_GNUC_END_IGNORE_DEPRECATIONS -#else - if (WIFEXITED (status)) { - if (WEXITSTATUS (status) != 0) - nmt_newt_message_dialog (_("Editor failed with status %d"), WEXITSTATUS (status)); - } else if (WIFSIGNALED (status)) - nmt_newt_message_dialog (_("Editor failed with signal %d"), WTERMSIG (status)); -#endif if (!g_file_get_contents (filename, &new_data, NULL, &error)) { nmt_newt_message_dialog (_("Could not re-read file: %s"), error->message); @@ -386,5 +376,5 @@ nmt_newt_edit_string (const char *data) g_free (filename); return new_data; -} +} diff --git a/clients/tui/newt/nmt-newt-widget.c b/clients/tui/newt/nmt-newt-widget.c index 5602c062..94f3011e 100644 --- a/clients/tui/newt/nmt-newt-widget.c +++ b/clients/tui/newt/nmt-newt-widget.c @@ -311,7 +311,7 @@ nmt_newt_widget_real_activated (NmtNewtWidget *widget) if (priv->exit_on_activate) nmt_newt_form_quit (nmt_newt_widget_get_form (widget)); -} +} /** * nmt_newt_widget_activated: @@ -363,7 +363,7 @@ nmt_newt_widget_set_exit_on_activate (NmtNewtWidget *widget, priv->exit_on_activate = exit_on_activate; g_object_notify (G_OBJECT (widget), "exit-on-activate"); } -} +} /** * nmt_newt_widget_get_visible: diff --git a/clients/tui/nm-editor-bindings.h b/clients/tui/nm-editor-bindings.h index facbf1c6..72bd91e3 100644 --- a/clients/tui/nm-editor-bindings.h +++ b/clients/tui/nm-editor-bindings.h @@ -19,8 +19,6 @@ #ifndef NM_EDITOR_BINDINGS_H #define NM_EDITOR_BINDINGS_H -#include "NetworkManager.h" - void nm_editor_bindings_init (void); void nm_editor_bind_ip_addresses_with_prefix_to_strv (int family, diff --git a/clients/tui/nm-editor-utils.c b/clients/tui/nm-editor-utils.c index b71e9fbe..8fecefa8 100644 --- a/clients/tui/nm-editor-utils.c +++ b/clients/tui/nm-editor-utils.c @@ -27,8 +27,6 @@ #include "nm-default.h" -#include "NetworkManager.h" - #include "nm-editor-utils.h" #if 0 #include "nm-vpn-helpers.h" diff --git a/clients/tui/nm-editor-utils.h b/clients/tui/nm-editor-utils.h index 6f66edfe..e15cc5e8 100644 --- a/clients/tui/nm-editor-utils.h +++ b/clients/tui/nm-editor-utils.h @@ -19,8 +19,6 @@ #ifndef NM_EDITOR_UTILS_H #define NM_EDITOR_UTILS_H -#include "NetworkManager.h" - typedef struct { const char *name; GType setting_type; diff --git a/clients/tui/nmt-connect-connection-list.c b/clients/tui/nmt-connect-connection-list.c index 6e69a04b..ae633ec0 100644 --- a/clients/tui/nmt-connect-connection-list.c +++ b/clients/tui/nmt-connect-connection-list.c @@ -13,7 +13,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * - * Copyright 2013 Red Hat, Inc. + * Copyright 2013 - 2017 Red Hat, Inc. */ /** @@ -28,12 +28,9 @@ #include <stdlib.h> -#include "NetworkManager.h" - -#include "nm-utils/nm-hash-utils.h" - #include "nmtui.h" #include "nmt-connect-connection-list.h" +#include "nm-client-utils.h" G_DEFINE_TYPE (NmtConnectConnectionList, nmt_connect_connection_list, NMT_TYPE_NEWT_LISTBOX) @@ -310,7 +307,7 @@ add_connections_for_aps (NmtConnectDevice *nmtdev, } if (!nmtconn->name) - nmtconn->name = nmtconn->ssid ? nmtconn->ssid : "<unknown>"; + nmtconn->name = nmtconn->ssid ?: "<unknown>"; nmtdev->conns = g_slist_prepend (nmtdev->conns, nmtconn); } @@ -379,7 +376,7 @@ append_nmt_devices_for_virtual_devices (GSList *nmt_devices, g_free (name); else { nmtdev = g_slice_new0 (NmtConnectDevice); - nmtdev->name = name ? name : g_strdup ("Unknown"); + nmtdev->name = name ?: g_strdup("Unknown"); nmtdev->sort_order = sort_order; g_hash_table_insert (devices_by_name, nmtdev->name, nmtdev); @@ -527,7 +524,7 @@ nmt_connect_connection_list_rebuild (NmtConnectConnectionList *list) if (nmtconn->ap) { guint8 strength = nm_access_point_get_strength (nmtconn->ap); - strength_col = nm_utils_wifi_strength_bars (strength); + strength_col = nmc_wifi_strength_bars (strength); } else strength_col = NULL; @@ -536,7 +533,7 @@ nmt_connect_connection_list_rebuild (NmtConnectConnectionList *list) nmtconn->name, (int)(max_width - nmt_newt_text_width (nmtconn->name)), "", strength_col ? " " : "", - strength_col ? strength_col : ""); + strength_col ?: ""); nmt_newt_listbox_append (listbox, row, nmtconn); g_free (row); diff --git a/clients/tui/nmt-device-entry.c b/clients/tui/nmt-device-entry.c index be1ad492..a4d63e4f 100644 --- a/clients/tui/nmt-device-entry.c +++ b/clients/tui/nmt-device-entry.c @@ -40,8 +40,6 @@ #include <sys/socket.h> #include <linux/if_arp.h> -#include "NetworkManager.h" - #include "nmtui.h" #include "nmt-device-entry.h" diff --git a/clients/tui/nmt-device-entry.h b/clients/tui/nmt-device-entry.h index 9278244f..9c288822 100644 --- a/clients/tui/nmt-device-entry.h +++ b/clients/tui/nmt-device-entry.h @@ -21,8 +21,6 @@ #include "nmt-editor-grid.h" -#include "NetworkManager.h" - #define NMT_TYPE_DEVICE_ENTRY (nmt_device_entry_get_type ()) #define NMT_DEVICE_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NMT_TYPE_DEVICE_ENTRY, NmtDeviceEntry)) #define NMT_DEVICE_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NMT_TYPE_DEVICE_ENTRY, NmtDeviceEntryClass)) diff --git a/clients/tui/nmt-edit-connection-list.c b/clients/tui/nmt-edit-connection-list.c index e90140b3..356c0b4b 100644 --- a/clients/tui/nmt-edit-connection-list.c +++ b/clients/tui/nmt-edit-connection-list.c @@ -319,7 +319,6 @@ listbox_activated (NmtNewtWidget *listbox, gpointer list) edit_clicked (NMT_NEWT_BUTTON (priv->edit), list); } - static void connection_saved (GObject *conn, GAsyncResult *result, @@ -502,7 +501,7 @@ nmt_edit_connection_list_class_init (NmtEditConnectionListClass *list_class) G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS)); - + /** * NmtEditConnectionListFilter: * @list: the #NmtEditConnectionList diff --git a/clients/tui/nmt-edit-connection-list.h b/clients/tui/nmt-edit-connection-list.h index 9726e287..cb02ea4b 100644 --- a/clients/tui/nmt-edit-connection-list.h +++ b/clients/tui/nmt-edit-connection-list.h @@ -21,8 +21,6 @@ #include "nmt-newt.h" -#include "NetworkManager.h" - #define NMT_TYPE_EDIT_CONNECTION_LIST (nmt_edit_connection_list_get_type ()) #define NMT_EDIT_CONNECTION_LIST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NMT_TYPE_EDIT_CONNECTION_LIST, NmtEditConnectionList)) #define NMT_EDIT_CONNECTION_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NMT_TYPE_EDIT_CONNECTION_LIST, NmtEditConnectionListClass)) diff --git a/clients/tui/nmt-editor-grid.c b/clients/tui/nmt-editor-grid.c index a57e780b..bc8a7843 100644 --- a/clients/tui/nmt-editor-grid.c +++ b/clients/tui/nmt-editor-grid.c @@ -70,7 +70,7 @@ typedef struct { * Creates a new #NmtEditorGrid * * Returns: a new #NmtEditorGrid - */ + */ NmtNewtWidget * nmt_editor_grid_new (void) { @@ -369,7 +369,6 @@ nmt_editor_grid_size_request (NmtNewtWidget *widget, *width += 2; } - static void nmt_editor_grid_size_allocate (NmtNewtWidget *widget, int x, diff --git a/clients/tui/nmt-editor-page.h b/clients/tui/nmt-editor-page.h index 93a66155..687f84a7 100644 --- a/clients/tui/nmt-editor-page.h +++ b/clients/tui/nmt-editor-page.h @@ -19,8 +19,6 @@ #ifndef NMT_EDITOR_PAGE_H #define NMT_EDITOR_PAGE_H -#include "NetworkManager.h" - #include "nmt-editor-grid.h" #include "nmt-editor-section.h" diff --git a/clients/tui/nmt-editor.c b/clients/tui/nmt-editor.c index 515e3471..b18f23d5 100644 --- a/clients/tui/nmt-editor.c +++ b/clients/tui/nmt-editor.c @@ -153,7 +153,6 @@ page_saved (gpointer data, gpointer user_data) nmt_editor_page_saved (page); } - static void save_connection_and_exit (NmtNewtButton *button, gpointer user_data) diff --git a/clients/tui/nmt-editor.h b/clients/tui/nmt-editor.h index 5620c5e8..ea51723e 100644 --- a/clients/tui/nmt-editor.h +++ b/clients/tui/nmt-editor.h @@ -19,8 +19,6 @@ #ifndef NMT_EDITOR_H #define NMT_EDITOR_H -#include "NetworkManager.h" - #include "nmt-newt.h" #define NMT_TYPE_EDITOR (nmt_editor_get_type ()) diff --git a/clients/tui/nmt-mac-entry.c b/clients/tui/nmt-mac-entry.c index b954d2e0..23c2ab1c 100644 --- a/clients/tui/nmt-mac-entry.c +++ b/clients/tui/nmt-mac-entry.c @@ -32,10 +32,8 @@ #include <string.h> -#include "NetworkManager.h" #include "nm-common-macros.h" - G_DEFINE_TYPE (NmtMacEntry, nmt_mac_entry, NMT_TYPE_NEWT_ENTRY) #define NMT_MAC_ENTRY_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NMT_TYPE_MAC_ENTRY, NmtMacEntryPrivate)) diff --git a/clients/tui/nmt-page-bond.c b/clients/tui/nmt-page-bond.c index e39a4c96..1629c8b0 100644 --- a/clients/tui/nmt-page-bond.c +++ b/clients/tui/nmt-page-bond.c @@ -203,21 +203,21 @@ slaves_changed (GObject *object, nmt_newt_component_set_sensitive (NMT_NEWT_COMPONENT (priv->mode), TRUE); } -#define WIDGET_CHANGED_FUNC(widget, func, option) \ -static void \ -widget ## _widget_changed (GObject *object, \ - GParamSpec *pspec, \ - gpointer user_data) \ -{ \ - NmtPageBond *bond = NMT_PAGE_BOND (user_data); \ - NmtPageBondPrivate *priv = NMT_PAGE_BOND_GET_PRIVATE (bond); \ - \ - if (priv->updating) \ - return; \ - \ - priv->updating = TRUE; \ - nm_setting_bond_add_option (priv->s_bond, option, func (priv->widget)); \ - priv->updating = FALSE; \ +#define WIDGET_CHANGED_FUNC(widget, func, option) \ +static void \ +widget ## _widget_changed (GObject *object, \ + GParamSpec *pspec, \ + gpointer user_data) \ +{ \ + NmtPageBond *bond = NMT_PAGE_BOND (user_data); \ + NmtPageBondPrivate *priv = NMT_PAGE_BOND_GET_PRIVATE (bond); \ + \ + if (priv->updating) \ + return; \ + \ + priv->updating = TRUE; \ + nm_setting_bond_add_option (priv->s_bond, option, func (priv->widget)); \ + priv->updating = FALSE; \ } WIDGET_CHANGED_FUNC (primary, nmt_newt_entry_get_text, NM_SETTING_BOND_OPTION_PRIMARY) diff --git a/clients/tui/nmt-page-team-port.c b/clients/tui/nmt-page-team-port.c index af2221ad..0d40373d 100644 --- a/clients/tui/nmt-page-team-port.c +++ b/clients/tui/nmt-page-team-port.c @@ -68,7 +68,7 @@ edit_clicked (NmtNewtButton *button, NM_SETTING_TEAM_PORT_CONFIG, new_config, NULL); g_free (new_config); -} +} static void nmt_page_team_port_constructed (GObject *object) diff --git a/clients/tui/nmt-page-team.c b/clients/tui/nmt-page-team.c index 2523bd85..cfe12703 100644 --- a/clients/tui/nmt-page-team.c +++ b/clients/tui/nmt-page-team.c @@ -121,7 +121,7 @@ edit_clicked (NmtNewtButton *button, NM_SETTING_TEAM_CONFIG, new_config, NULL); g_free (new_config); -} +} static void nmt_page_team_constructed (GObject *object) diff --git a/clients/tui/nmt-page-wifi.c b/clients/tui/nmt-page-wifi.c index 35625fe4..00439c19 100644 --- a/clients/tui/nmt-page-wifi.c +++ b/clients/tui/nmt-page-wifi.c @@ -384,7 +384,6 @@ nmt_page_wifi_finalize (GObject *object) G_OBJECT_CLASS (nmt_page_wifi_parent_class)->finalize (object); } - static void nmt_page_wifi_class_init (NmtPageWifiClass *wifi_class) { diff --git a/clients/tui/nmt-password-dialog.c b/clients/tui/nmt-password-dialog.c index fb9567e6..16920fcf 100644 --- a/clients/tui/nmt-password-dialog.c +++ b/clients/tui/nmt-password-dialog.c @@ -144,12 +144,12 @@ nmt_password_dialog_constructed (GObject *object) NMSecretAgentSimpleSecret *secret = priv->secrets->pdata[i]; NmtNewtEntryFlags flags; - widget = nmt_newt_label_new (secret->name); + widget = nmt_newt_label_new (secret->pretty_name); nmt_newt_grid_add (secret_grid, widget, 0, i); nmt_newt_widget_set_padding (widget, 4, 0, 1, 0); flags = NMT_NEWT_ENTRY_NONEMPTY; - if (secret->password) + if (secret->is_secret) flags |= NMT_NEWT_ENTRY_PASSWORD; widget = nmt_newt_entry_new (30, flags); if (secret->value) diff --git a/clients/tui/nmt-route-editor.h b/clients/tui/nmt-route-editor.h index 8e63830e..d83523bc 100644 --- a/clients/tui/nmt-route-editor.h +++ b/clients/tui/nmt-route-editor.h @@ -19,8 +19,6 @@ #ifndef NMT_ROUTE_EDITOR_H #define NMT_ROUTE_EDITOR_H -#include "NetworkManager.h" - #include "nmt-newt.h" #define NMT_TYPE_ROUTE_EDITOR (nmt_route_editor_get_type ()) diff --git a/clients/tui/nmt-route-entry.c b/clients/tui/nmt-route-entry.c index 1b37389f..109759cc 100644 --- a/clients/tui/nmt-route-entry.c +++ b/clients/tui/nmt-route-entry.c @@ -32,8 +32,6 @@ #include <netinet/in.h> #include <stdlib.h> -#include "NetworkManager.h" - #include "nmt-route-entry.h" #include "nmt-ip-entry.h" @@ -154,7 +152,7 @@ static newtComponent nmt_route_entry_get_focus_component (NmtNewtWidget *widget) { NmtRouteEntryPrivate *priv = NMT_ROUTE_ENTRY_GET_PRIVATE (widget); - + return nmt_newt_widget_get_focus_component (priv->dest); } diff --git a/clients/tui/nmt-route-table.c b/clients/tui/nmt-route-table.c index a63f5205..c2e55542 100644 --- a/clients/tui/nmt-route-table.c +++ b/clients/tui/nmt-route-table.c @@ -30,8 +30,6 @@ #include <netinet/in.h> #include <stdlib.h> -#include "NetworkManager.h" - #include "nmt-route-table.h" #include "nmt-route-entry.h" #include "nmt-widget-list.h" @@ -163,12 +161,10 @@ remove_route (NmtWidgetList *list, gpointer table) { NmtRouteTablePrivate *priv = NMT_ROUTE_TABLE_GET_PRIVATE (table); - NMIPRoute *route; if (num >= priv->routes->len) return; - route = priv->routes->pdata[num]; g_ptr_array_remove_index (priv->routes, num); nmt_widget_list_set_length (list, priv->routes->len); diff --git a/clients/tui/nmt-slave-list.c b/clients/tui/nmt-slave-list.c index a8c31e05..893b7caf 100644 --- a/clients/tui/nmt-slave-list.c +++ b/clients/tui/nmt-slave-list.c @@ -26,8 +26,6 @@ #include "nm-default.h" -#include "NetworkManager.h" - #include "nmt-slave-list.h" G_DEFINE_TYPE (NmtSlaveList, nmt_slave_list, NMT_TYPE_EDIT_CONNECTION_LIST) diff --git a/clients/tui/nmt-utils.c b/clients/tui/nmt-utils.c index a8c1c5f0..7cd71be2 100644 --- a/clients/tui/nmt-utils.c +++ b/clients/tui/nmt-utils.c @@ -47,7 +47,7 @@ * * When the async callback is invoked, it should call * nmt_sync_op_complete_boolean() or nmt_sync_op_complete_pointer() to - * return a result or an error to the caller. + * return a result or an error to the caller. * * There is no free/clear function; any memory that needs to be freed * will have been returned to the caller from diff --git a/clients/tui/nmtui-connect.c b/clients/tui/nmtui-connect.c index 086e4bd3..2a954fb8 100644 --- a/clients/tui/nmtui-connect.c +++ b/clients/tui/nmtui-connect.c @@ -100,41 +100,38 @@ secrets_requested (NMSecretAgentSimple *agent, { NmtNewtForm *form; NMConnection *connection = NM_CONNECTION (user_data); - char *cookie = NULL; - char *gateway = NULL; - char *gwcert = NULL; int i; /* Get secrets for OpenConnect VPN */ - if (connection && nm_connection_is_type (connection, NM_SETTING_VPN_SETTING_NAME)) { + if ( connection + && nm_connection_is_type (connection, NM_SETTING_VPN_SETTING_NAME)) { NMSettingVpn *s_vpn = nm_connection_get_setting_vpn (connection); - const char *vpn_type = nm_setting_vpn_get_service_type (s_vpn); - if (!g_strcmp0 (vpn_type, NM_DBUS_INTERFACE ".openconnect")) { + if (nm_streq0 (nm_setting_vpn_get_service_type (s_vpn), NM_SECRET_AGENT_VPN_TYPE_OPENCONNECT)) { + gs_free char *cookie = NULL; + gs_free char *gateway = NULL; + gs_free char *gwcert = NULL; + openconnect_authenticate (connection, &cookie, &gateway, &gwcert); for (i = 0; i < secrets->len; i++) { NMSecretAgentSimpleSecret *secret = secrets->pdata[i]; - if (!g_strcmp0 (secret->vpn_type, NM_DBUS_INTERFACE ".openconnect")) { - 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; - } + 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); } } - g_free (cookie); - g_free (gateway); - g_free (gwcert); } } diff --git a/clients/tui/nmtui-edit.c b/clients/tui/nmtui-edit.c index a92e45a3..657724e3 100644 --- a/clients/tui/nmtui-edit.c +++ b/clients/tui/nmtui-edit.c @@ -27,8 +27,6 @@ #include <stdlib.h> -#include "NetworkManager.h" - #include "nmtui.h" #include "nmtui-edit.h" #include "nmt-edit-connection-list.h" diff --git a/clients/tui/nmtui-hostname.c b/clients/tui/nmtui-hostname.c index f8005502..2c4fb28e 100644 --- a/clients/tui/nmtui-hostname.c +++ b/clients/tui/nmtui-hostname.c @@ -112,7 +112,7 @@ nmtui_hostname (gboolean is_top, int argc, char **argv) nmt_sync_op_init (&op); nm_client_save_hostname_async (nm_client, hostname, NULL, hostname_set, &op); if (nmt_sync_op_wait_boolean (&op, &error)) { - /* Translators: this indicates the result. ie, "I have set the hostname to ..." */ + /* TRANSLATORS: this indicates the result. ie, "I have set the hostname to ..." */ nmt_newt_message_dialog (_("Set hostname to '%s'"), hostname); } else { nmt_newt_message_dialog (_("Unable to set hostname: %s"), error->message); diff --git a/clients/tui/nmtui.c b/clients/tui/nmtui.c index 70cad5d6..97c528e7 100644 --- a/clients/tui/nmtui.c +++ b/clients/tui/nmtui.c @@ -30,8 +30,6 @@ #include <stdlib.h> #include <string.h> -#include "NetworkManager.h" - #include "nmt-newt.h" #include "nm-editor-bindings.h" @@ -228,7 +226,7 @@ main (int argc, char **argv) int i; setlocale (LC_ALL, ""); - bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); + bindtextdomain (GETTEXT_PACKAGE, NMLOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); diff --git a/clients/tui/nmtui.h b/clients/tui/nmtui.h index efb59622..5ef8e82a 100644 --- a/clients/tui/nmtui.h +++ b/clients/tui/nmtui.h @@ -19,8 +19,6 @@ #ifndef NMTUI_H #define NMTUI_H -#include "NetworkManager.h" - extern NMClient *nm_client; void nmtui_quit (void); |