diff options
author | Thomas Haller <thaller@redhat.com> | 2017-03-30 14:57:54 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2017-03-30 14:57:54 +0200 |
commit | 9033d084abc06538d42741cccc1e6931946bf721 (patch) | |
tree | c1f38ed28645fde792dfa8567ede0360c1c41329 | |
parent | 166988264f114344759e6faa08e3cadce87c62a6 (diff) | |
parent | 29bcfc25221fcbc63ce9bc7670097b07b7fab827 (diff) | |
download | NetworkManager-9033d084abc06538d42741cccc1e6931946bf721.tar.gz |
cli: merge branch 'th/cli-setting-metadata-bgo732292'
A larger refactoring of nmcli.
Splits out (a bit) the tracking of settings meta data. As such,
it goes towards what is proposed by bgo#732292.
Then, get rid (a bit) of the global data that is passed around.
33 files changed, 9057 insertions, 11071 deletions
diff --git a/Makefile.am b/Makefile.am index bacc616de4..a124c9a28d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -414,9 +414,10 @@ libnm_core_lib_h_pub_real = \ libnm_core_lib_h_pub_mkenums = \ libnm-core/nm-core-enum-types.h libnm_core_lib_h_priv = \ + shared/nm-utils/nm-enum-utils.h \ shared/nm-utils/nm-shared-utils.h \ shared/nm-utils/nm-udev-utils.h \ - shared/nm-setting-metadata.h \ + shared/nm-meta-setting.h \ libnm-core/crypto.h \ libnm-core/nm-connection-private.h \ libnm-core/nm-core-internal.h \ @@ -427,9 +428,10 @@ libnm_core_lib_h_priv = \ libnm-core/nm-setting-private.h \ libnm-core/nm-utils-private.h libnm_core_lib_c_real = \ + shared/nm-utils/nm-enum-utils.c \ shared/nm-utils/nm-shared-utils.c \ shared/nm-utils/nm-udev-utils.c \ - shared/nm-setting-metadata.c \ + shared/nm-meta-setting.c \ libnm-core/crypto.c \ libnm-core/nm-connection.c \ libnm-core/nm-dbus-utils.c \ @@ -3118,6 +3120,19 @@ bin_PROGRAMS += clients/cli/nmcli clients_cli_nmcli_SOURCES = \ \ + shared/nm-utils/nm-enum-utils.c \ + shared/nm-utils/nm-enum-utils.h \ + shared/nm-utils/nm-shared-utils.c \ + shared/nm-utils/nm-shared-utils.h \ + \ + shared/nm-meta-setting.c \ + shared/nm-meta-setting.h \ + \ + clients/common/nm-client-utils.c \ + clients/common/nm-client-utils.h \ + clients/common/nm-meta-setting-desc.c \ + clients/common/nm-meta-setting-desc.h \ + \ clients/cli/agent.c \ clients/cli/agent.h \ clients/cli/common.c \ diff --git a/clients/cli/agent.c b/clients/cli/agent.c index 4cbf7d2d37..183679a48c 100644 --- a/clients/cli/agent.c +++ b/clients/cli/agent.c @@ -125,7 +125,7 @@ secrets_requested (NMSecretAgentSimple *agent, NmCli *nmc = (NmCli *) user_data; gboolean success = FALSE; - if (nmc->print_output == NMC_PRINT_PRETTY) + if (nmc->nmc_config.print_output == NMC_PRINT_PRETTY) nmc_terminal_erase_line (); success = get_secrets_from_user (request_id, title, msg, secrets); diff --git a/clients/cli/common.c b/clients/cli/common.c index 3e28eee7a9..c17bc8194a 100644 --- a/clients/cli/common.c +++ b/clients/cli/common.c @@ -30,56 +30,60 @@ #include <readline/history.h> #include "nm-vpn-helpers.h" +#include "nm-client-utils.h" + #include "common.h" #include "utils.h" extern GMainLoop *loop; +#define OUTPUT_FIELD_WITH_NAME(n) { .name = N_ (n), } + /* Available fields for IPv4 group */ NmcOutputField nmc_fields_ip4_config[] = { - {"GROUP", N_("GROUP")}, /* 0 */ - {"ADDRESS", N_("ADDRESS")}, /* 1 */ - {"GATEWAY", N_("GATEWAY")}, /* 2 */ - {"ROUTE", N_("ROUTE")}, /* 3 */ - {"DNS", N_("DNS")}, /* 4 */ - {"DOMAIN", N_("DOMAIN")}, /* 5 */ - {"WINS", N_("WINS")}, /* 6 */ - {NULL, NULL} + OUTPUT_FIELD_WITH_NAME ("GROUP"), /* 0 */ + OUTPUT_FIELD_WITH_NAME ("ADDRESS"), /* 1 */ + OUTPUT_FIELD_WITH_NAME ("GATEWAY"), /* 2 */ + OUTPUT_FIELD_WITH_NAME ("ROUTE"), /* 3 */ + OUTPUT_FIELD_WITH_NAME ("DNS"), /* 4 */ + OUTPUT_FIELD_WITH_NAME ("DOMAIN"), /* 5 */ + OUTPUT_FIELD_WITH_NAME ("WINS"), /* 6 */ + { 0 } }; #define NMC_FIELDS_IP4_CONFIG_ALL "GROUP,ADDRESS,GATEWAY,ROUTE,DNS,DOMAIN,WINS" /* Available fields for DHCPv4 group */ NmcOutputField nmc_fields_dhcp4_config[] = { - {"GROUP", N_("GROUP")}, /* 0 */ - {"OPTION", N_("OPTION")}, /* 1 */ - {NULL, NULL} + OUTPUT_FIELD_WITH_NAME ("GROUP"), /* 0 */ + OUTPUT_FIELD_WITH_NAME ("OPTION"), /* 1 */ + { 0 } }; #define NMC_FIELDS_DHCP4_CONFIG_ALL "GROUP,OPTION" /* Available fields for IPv6 group */ NmcOutputField nmc_fields_ip6_config[] = { - {"GROUP", N_("GROUP")}, /* 0 */ - {"ADDRESS", N_("ADDRESS")}, /* 1 */ - {"GATEWAY", N_("GATEWAY")}, /* 2 */ - {"ROUTE", N_("ROUTE")}, /* 3 */ - {"DNS", N_("DNS")}, /* 4 */ - {"DOMAIN", N_("DOMAIN")}, /* 5 */ - {NULL, NULL} + OUTPUT_FIELD_WITH_NAME ("GROUP"), /* 0 */ + OUTPUT_FIELD_WITH_NAME ("ADDRESS"), /* 1 */ + OUTPUT_FIELD_WITH_NAME ("GATEWAY"), /* 2 */ + OUTPUT_FIELD_WITH_NAME ("ROUTE"), /* 3 */ + OUTPUT_FIELD_WITH_NAME ("DNS"), /* 4 */ + OUTPUT_FIELD_WITH_NAME ("DOMAIN"), /* 5 */ + { 0 } }; #define NMC_FIELDS_IP6_CONFIG_ALL "GROUP,ADDRESS,GATEWAY,ROUTE,DNS,DOMAIN" /* Available fields for DHCPv6 group */ NmcOutputField nmc_fields_dhcp6_config[] = { - {"GROUP", N_("GROUP")}, /* 0 */ - {"OPTION", N_("OPTION")}, /* 1 */ - {NULL, NULL} + OUTPUT_FIELD_WITH_NAME ("GROUP"), /* 0 */ + OUTPUT_FIELD_WITH_NAME ("OPTION"), /* 1 */ + { 0 } }; #define NMC_FIELDS_DHCP6_CONFIG_ALL "GROUP,OPTION" gboolean print_ip4_config (NMIPConfig *cfg4, - NmCli *nmc, + const NmcConfig *nmc_config, const char *group_prefix, const char *one_field) { @@ -92,16 +96,17 @@ print_ip4_config (NMIPConfig *cfg4, int i = 0; NmcOutputField *tmpl, *arr; size_t tmpl_len; + NMC_OUTPUT_DATA_DEFINE_SCOPED (out); if (cfg4 == NULL) return FALSE; tmpl = nmc_fields_ip4_config; tmpl_len = sizeof (nmc_fields_ip4_config); - nmc->print_fields.indices = parse_output_fields (one_field ? one_field : NMC_FIELDS_IP4_CONFIG_ALL, + out.print_fields.indices = parse_output_fields (one_field ? one_field : NMC_FIELDS_IP4_CONFIG_ALL, tmpl, FALSE, NULL, NULL); arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); - g_ptr_array_add (nmc->output_data, arr); + g_ptr_array_add (out.output_data, arr); /* addresses */ ptr_array = nm_ip_config_get_addresses (cfg4); @@ -156,19 +161,17 @@ print_ip4_config (NMIPConfig *cfg4, set_val_arr (arr, 4, dns_arr); set_val_arr (arr, 5, domain_arr); set_val_arr (arr, 6, wins_arr); - g_ptr_array_add (nmc->output_data, arr); + g_ptr_array_add (out.output_data, arr); - print_data (nmc); /* Print all data */ - - /* Remove any previous data */ - nmc_empty_output_fields (nmc); + print_data_prepare_width (out.output_data); + print_data (nmc_config, &out); return TRUE; } gboolean print_ip6_config (NMIPConfig *cfg6, - NmCli *nmc, + const NmcConfig *nmc_config, const char *group_prefix, const char *one_field) { @@ -180,16 +183,17 @@ print_ip6_config (NMIPConfig *cfg6, int i = 0; NmcOutputField *tmpl, *arr; size_t tmpl_len; + NMC_OUTPUT_DATA_DEFINE_SCOPED (out); if (cfg6 == NULL) return FALSE; tmpl = nmc_fields_ip6_config; tmpl_len = sizeof (nmc_fields_ip6_config); - nmc->print_fields.indices = parse_output_fields (one_field ? one_field : NMC_FIELDS_IP6_CONFIG_ALL, + out.print_fields.indices = parse_output_fields (one_field ? one_field : NMC_FIELDS_IP6_CONFIG_ALL, tmpl, FALSE, NULL, NULL); arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); - g_ptr_array_add (nmc->output_data, arr); + g_ptr_array_add (out.output_data, arr); /* addresses */ ptr_array = nm_ip_config_get_addresses (cfg6); @@ -240,19 +244,17 @@ print_ip6_config (NMIPConfig *cfg6, set_val_arr (arr, 3, route_arr); set_val_arr (arr, 4, dns_arr); set_val_arr (arr, 5, domain_arr); - g_ptr_array_add (nmc->output_data, arr); - - print_data (nmc); /* Print all data */ + g_ptr_array_add (out.output_data, arr); - /* Remove any previous data */ - nmc_empty_output_fields (nmc); + print_data_prepare_width (out.output_data); + print_data (nmc_config, &out); return TRUE; } gboolean print_dhcp4_config (NMDhcpConfig *dhcp4, - NmCli *nmc, + const NmcConfig *nmc_config, const char *group_prefix, const char *one_field) { @@ -269,13 +271,14 @@ print_dhcp4_config (NMDhcpConfig *dhcp4, gpointer key, value; char **options_arr = NULL; int i = 0; + NMC_OUTPUT_DATA_DEFINE_SCOPED (out); tmpl = nmc_fields_dhcp4_config; tmpl_len = sizeof (nmc_fields_dhcp4_config); - nmc->print_fields.indices = parse_output_fields (one_field ? one_field : NMC_FIELDS_DHCP4_CONFIG_ALL, - tmpl, FALSE, NULL, NULL); + out.print_fields.indices = parse_output_fields (one_field ? one_field : NMC_FIELDS_DHCP4_CONFIG_ALL, + tmpl, FALSE, NULL, NULL); arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); - g_ptr_array_add (nmc->output_data, arr); + 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); @@ -286,12 +289,10 @@ print_dhcp4_config (NMDhcpConfig *dhcp4, arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX); set_val_strc (arr, 0, group_prefix); set_val_arr (arr, 1, options_arr); - g_ptr_array_add (nmc->output_data, arr); + g_ptr_array_add (out.output_data, arr); - print_data (nmc); /* Print all data */ - - /* Remove any previous data */ - nmc_empty_output_fields (nmc); + print_data_prepare_width (out.output_data); + print_data (nmc_config, &out); return TRUE; } @@ -300,7 +301,7 @@ print_dhcp4_config (NMDhcpConfig *dhcp4, gboolean print_dhcp6_config (NMDhcpConfig *dhcp6, - NmCli *nmc, + const NmcConfig *nmc_config, const char *group_prefix, const char *one_field) { @@ -317,13 +318,14 @@ print_dhcp6_config (NMDhcpConfig *dhcp6, gpointer key, value; char **options_arr = NULL; int i = 0; + NMC_OUTPUT_DATA_DEFINE_SCOPED (out); tmpl = nmc_fields_dhcp6_config; tmpl_len = sizeof (nmc_fields_dhcp6_config); - nmc->print_fields.indices = parse_output_fields (one_field ? one_field : NMC_FIELDS_DHCP6_CONFIG_ALL, - tmpl, FALSE, NULL, NULL); + out.print_fields.indices = parse_output_fields (one_field ? one_field : NMC_FIELDS_DHCP6_CONFIG_ALL, + tmpl, FALSE, NULL, NULL); arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); - g_ptr_array_add (nmc->output_data, arr); + 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); @@ -334,205 +336,16 @@ print_dhcp6_config (NMDhcpConfig *dhcp6, arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX); set_val_strc (arr, 0, group_prefix); set_val_arr (arr, 1, options_arr); - g_ptr_array_add (nmc->output_data, arr); - - print_data (nmc); /* Print all data */ + g_ptr_array_add (out.output_data, arr); - /* Remove any previous data */ - nmc_empty_output_fields (nmc); + print_data_prepare_width (out.output_data); + print_data (nmc_config, &out); return TRUE; } return FALSE; } -/* - * Parse IP address from string to NMIPAddress stucture. - * ip_str is the IP address in the form address/prefix - */ -NMIPAddress * -nmc_parse_and_build_address (int family, const char *ip_str, GError **error) -{ - int max_prefix = (family == AF_INET) ? 32 : 128; - NMIPAddress *addr = NULL; - const char *ip; - char *tmp; - char *plen; - long int prefix; - GError *local = NULL; - - g_return_val_if_fail (ip_str != NULL, NULL); - g_return_val_if_fail (error == NULL || *error == NULL, NULL); - - tmp = g_strdup (ip_str); - plen = strchr (tmp, '/'); /* prefix delimiter */ - if (plen) - *plen++ = '\0'; - - ip = tmp; - - prefix = max_prefix; - if (plen) { - if (!nmc_string_to_int (plen, TRUE, 1, max_prefix, &prefix)) { - g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT, - _("invalid prefix '%s'; <1-%d> allowed"), plen, max_prefix); - goto finish; - } - } - - addr = nm_ip_address_new (family, ip, (guint32) prefix, &local); - if (!addr) { - g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT, - _("invalid IP address: %s"), local->message); - g_clear_error (&local); - } - -finish: - g_free (tmp); - return addr; -} - -/* - * nmc_parse_and_build_route: - * @family: AF_INET or AF_INET6 - * @str: route string to be parsed - * @error: location to store GError - * - * Parse route from string and return an #NMIPRoute - * - * Returns: a new #NMIPRoute or %NULL on error - */ -NMIPRoute * -nmc_parse_and_build_route (int family, - const char *str, - GError **error) -{ - int max_prefix = (family == AF_INET) ? 32 : 128; - char *plen = NULL; - const char *next_hop = NULL; - const char *canon_dest; - long int prefix = max_prefix; - unsigned long int tmp_ulong; - NMIPRoute *route = NULL; - gboolean success = FALSE; - GError *local = NULL; - gint64 metric = -1; - guint i, len; - gs_strfreev char **routev = NULL; - gs_free char *value = NULL; - gs_free char *dest = NULL; - gs_unref_hashtable GHashTable *attrs = NULL; - GHashTable *tmp_attrs; - - g_return_val_if_fail (family == AF_INET || family == AF_INET6, FALSE); - g_return_val_if_fail (str, FALSE); - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - - value = g_strdup (str); - routev = nmc_strsplit_set (g_strstrip (value), " \t", 0); - len = g_strv_length (routev); - if (len < 1) { - g_set_error (error, 1, 0, _("'%s' is not valid (the format is: ip[/prefix] [next-hop] [metric] [attr=val] [attr=val])"), - str); - goto finish; - } - - dest = g_strdup (routev[0]); - plen = strchr (dest, '/'); /* prefix delimiter */ - if (plen) - *plen++ = '\0'; - - if (plen) { - if (!nmc_string_to_int (plen, TRUE, 1, max_prefix, &prefix)) { - g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT, - _("invalid prefix '%s'; <1-%d> allowed"), - plen, max_prefix); - goto finish; - } - } - - for (i = 1; i < len; i++) { - if (nm_utils_ipaddr_valid (family, routev[i])) { - if (metric != -1 || attrs) { - g_set_error (error, 1, 0, _("the next hop ('%s') must be first"), routev[i]); - goto finish; - } - next_hop = routev[i]; - } else if (nmc_string_to_uint (routev[i], TRUE, 0, G_MAXUINT32, &tmp_ulong)) { - if (attrs) { - g_set_error (error, 1, 0, _("the metric ('%s') must be before attributes"), routev[i]); - goto finish; - } - metric = tmp_ulong; - } else if (strchr (routev[i], '=')) { - GHashTableIter iter; - char *iter_key; - GVariant *iter_value; - - tmp_attrs = nm_utils_parse_variant_attributes (routev[i], ' ', '=', FALSE, - nm_ip_route_get_variant_attribute_spec(), - error); - if (!tmp_attrs) { - g_prefix_error (error, "invalid option '%s': ", routev[i]); - goto finish; - } - - if (!attrs) - attrs = g_hash_table_new (g_str_hash, g_str_equal); - - g_hash_table_iter_init (&iter, tmp_attrs); - while (g_hash_table_iter_next (&iter, (gpointer *) &iter_key, (gpointer *) &iter_value)) { - if (!nm_ip_route_attribute_validate (iter_key, iter_value, family, NULL, error)) { - g_prefix_error (error, "%s: ", iter_key); - g_hash_table_unref (tmp_attrs); - goto finish; - } - g_hash_table_insert (attrs, iter_key, iter_value); - g_hash_table_iter_steal (&iter); - } - g_hash_table_unref (tmp_attrs); - } else { - g_set_error (error, 1, 0, _("unrecognized option '%s'"), routev[i]); - goto finish; - } - } - - route = nm_ip_route_new (family, dest, prefix, next_hop, metric, &local); - if (!route) { - g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT, - _("invalid route: %s"), local->message); - g_clear_error (&local); - goto finish; - } - - /* We don't accept default routes as NetworkManager handles it - * itself. But we have to check this after @route has normalized the - * dest string. - */ - canon_dest = nm_ip_route_get_dest (route); - if (!strcmp (canon_dest, "0.0.0.0") || !strcmp (canon_dest, "::")) { - g_set_error_literal (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT, - _("default route cannot be added (NetworkManager handles it by itself)")); - g_clear_pointer (&route, nm_ip_route_unref); - goto finish; - } - - if (attrs) { - GHashTableIter iter; - char *name; - GVariant *variant; - - g_hash_table_iter_init (&iter, attrs); - while (g_hash_table_iter_next (&iter, (gpointer *) &name, (gpointer *) &variant)) - nm_ip_route_set_attribute (route, name, variant); - } - - success = TRUE; - -finish: - return route; -} - const char * nmc_device_state_to_string (NMDeviceState state) { @@ -782,240 +595,6 @@ nmc_device_reason_to_string (NMDeviceStateReason reason) } } - -/* Max priority values from libnm-core/nm-setting-vlan.c */ -#define MAX_SKB_PRIO G_MAXUINT32 -#define MAX_8021P_PRIO 7 /* Max 802.1p priority */ - -/* - * Parse VLAN priority mappings from the following format: 2:1,3:4,7:3 - * and verify if the priority numbers are valid - * - * Return: string array with split maps, or NULL on error - * Caller is responsible for freeing the array. - */ -char ** -nmc_vlan_parse_priority_maps (const char *priority_map, - NMVlanPriorityMap map_type, - GError **error) -{ - char **mapping = NULL, **iter; - unsigned long from, to, from_max, to_max; - - g_return_val_if_fail (priority_map != NULL, NULL); - g_return_val_if_fail (error == NULL || *error == NULL, NULL); - - if (map_type == NM_VLAN_INGRESS_MAP) { - from_max = MAX_8021P_PRIO; - to_max = MAX_SKB_PRIO; - } else { - from_max = MAX_SKB_PRIO; - to_max = MAX_8021P_PRIO; - } - - mapping = g_strsplit (priority_map, ",", 0); - for (iter = mapping; iter && *iter; iter++) { - char *left, *right; - - left = g_strstrip (*iter); - right = strchr (left, ':'); - if (!right) { - g_set_error (error, 1, 0, _("invalid priority map '%s'"), *iter); - g_strfreev (mapping); - return NULL; - } - *right++ = '\0'; - - if (!nmc_string_to_uint (left, TRUE, 0, from_max, &from)) { - g_set_error (error, 1, 0, _("priority '%s' is not valid (<0-%ld>)"), - left, from_max); - g_strfreev (mapping); - return NULL; - } - if (!nmc_string_to_uint (right, TRUE, 0, to_max, &to)) { - g_set_error (error, 1, 0, _("priority '%s' is not valid (<0-%ld>)"), - right, to_max); - g_strfreev (mapping); - return NULL; - } - *(right-1) = ':'; /* Put back ':' */ - } - return mapping; -} - -const char * -nmc_bond_validate_mode (const char *mode, GError **error) -{ - unsigned long mode_int; - static const char *valid_modes[] = { "balance-rr", - "active-backup", - "balance-xor", - "broadcast", - "802.3ad", - "balance-tlb", - "balance-alb", - NULL }; - if (nmc_string_to_uint (mode, TRUE, 0, 6, &mode_int)) { - /* Translate bonding mode numbers to mode names: - * https://www.kernel.org/doc/Documentation/networking/bonding.txt - */ - return valid_modes[mode_int]; - } else - return nmc_string_is_valid (mode, valid_modes, error); -} - -/* - * nmc_team_check_config: - * @config: file name with team config, or raw team JSON config data - * @out_config: raw team JSON config data - * The value must be freed with g_free(). - * @error: location to store error, or %NUL - * - * Check team config from @config parameter and return the checked - * config in @out_config. - * - * Returns: %TRUE if the config is valid, %FALSE if it is invalid - */ -gboolean -nmc_team_check_config (const char *config, char **out_config, GError **error) -{ - enum { - _TEAM_CONFIG_TYPE_GUESS, - _TEAM_CONFIG_TYPE_FILE, - _TEAM_CONFIG_TYPE_JSON, - } desired_type = _TEAM_CONFIG_TYPE_GUESS; - const char *filename = NULL; - size_t c_len = 0; - gs_free char *config_clone = NULL; - - *out_config = NULL; - - if (!config || !config[0]) - return TRUE; - - if (g_str_has_prefix (config, "file://")) { - config += NM_STRLEN ("file://"); - desired_type = _TEAM_CONFIG_TYPE_FILE; - } else if (g_str_has_prefix (config, "json://")) { - config += NM_STRLEN ("json://"); - desired_type = _TEAM_CONFIG_TYPE_JSON; - } - - if (NM_IN_SET (desired_type, _TEAM_CONFIG_TYPE_FILE, _TEAM_CONFIG_TYPE_GUESS)) { - gs_free char *contents = NULL; - - if (!g_file_get_contents (config, &contents, &c_len, NULL)) { - if (desired_type == _TEAM_CONFIG_TYPE_FILE) { - g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT, - _("cannot read team config from file '%s'"), - config); - return FALSE; - } - } else { - if (c_len != strlen (contents)) { - g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT, - _("team config file '%s' contains non-valid utf-8"), - config); - return FALSE; - } - filename = config; - config = config_clone = g_steal_pointer (&contents); - } - } - - if (!nm_utils_is_json_object (config, NULL)) { - if (filename) { - g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT, - _("'%s' does not contain a valid team configuration"), filename); - } else { - g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT, - _("team configuration must be a JSON object")); - } - return FALSE; - } - - *out_config = (config == config_clone) - ? g_steal_pointer (&config_clone) - : g_strdup (config); - return TRUE; -} - -/* - * nmc_proxy_check_script: - * @script: file name with PAC script, or raw PAC Script data - * @out_script: raw PAC Script (with removed new-line characters) - * @error: location to store error, or %NULL - * - * Check PAC Script from @script parameter and return the checked/sanitized - * config in @out_script. - * - * Returns: %TRUE if the script is valid, %FALSE if it is invalid - */ -gboolean -nmc_proxy_check_script (const char *script, char **out_script, GError **error) -{ - enum { - _PAC_SCRIPT_TYPE_GUESS, - _PAC_SCRIPT_TYPE_FILE, - _PAC_SCRIPT_TYPE_JSON, - } desired_type = _PAC_SCRIPT_TYPE_GUESS; - const char *filename = NULL; - size_t c_len = 0; - gs_free char *script_clone = NULL; - - *out_script = NULL; - - if (!script || !script[0]) - return TRUE; - - if (g_str_has_prefix (script, "file://")) { - script += NM_STRLEN ("file://"); - desired_type = _PAC_SCRIPT_TYPE_FILE; - } else if (g_str_has_prefix (script, "js://")) { - script += NM_STRLEN ("js://"); - desired_type = _PAC_SCRIPT_TYPE_JSON; - } - - if (NM_IN_SET (desired_type, _PAC_SCRIPT_TYPE_FILE, _PAC_SCRIPT_TYPE_GUESS)) { - gs_free char *contents = NULL; - - if (!g_file_get_contents (script, &contents, &c_len, NULL)) { - if (desired_type == _PAC_SCRIPT_TYPE_FILE) { - g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT, - _("cannot read pac-script from file '%s'"), - script); - return FALSE; - } - } else { - if (c_len != strlen (contents)) { - g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT, - _("file '%s' contains non-valid utf-8"), - script); - return FALSE; - } - filename = script; - script = script_clone = g_steal_pointer (&contents); - } - } - - if ( !strstr (script, "FindProxyForURL") - || !g_utf8_validate (script, -1, NULL)) { - if (filename) { - g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT, - _("'%s' does not contain a valid PAC Script"), filename); - } else { - g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT, - _("Not a valid PAC Script")); - } - return FALSE; - } - - *out_script = (script == script_clone) - ? g_steal_pointer (&script_clone) - : g_strdup (script); - return TRUE; -} - /* * nmc_find_connection: * @connections: array of NMConnections to search in @@ -1260,7 +839,7 @@ nmc_secrets_requested (NMSecretAgentSimple *agent, gboolean success = FALSE; const GPtrArray *connections; - if (nmc->print_output == NMC_PRINT_PRETTY) + if (nmc->nmc_config.print_output == NMC_PRINT_PRETTY) nmc_terminal_erase_line (); /* Find the connection for the request */ @@ -1274,7 +853,7 @@ nmc_secrets_requested (NMSecretAgentSimple *agent, g_free (path); } - success = get_secrets_from_user (request_id, title, msg, connection, nmc->in_editor || nmc->ask, + success = get_secrets_from_user (request_id, title, msg, connection, nmc->nmc_config.in_editor || nmc->ask, nmc->show_secrets, nmc->pwds_hash, secrets); if (success) nm_secret_agent_simple_response (agent, request_id, secrets); @@ -1393,7 +972,7 @@ read_again: if (nmc_seen_sigint ()) { /* Ctrl-C */ nmc_clear_sigint (); - if ( nm_cli.in_editor + if ( nm_cli.nmc_config.in_editor || (rl_string && *rl_string)) { /* In editor, or the line is not empty */ /* Call readline again to get new prompt (repeat) */ @@ -1500,7 +1079,7 @@ nmc_readline_echo (gboolean echo_on, const char *prompt_fmt, ...) * See e.g. http://cnswww.cns.cwru.edu/php/chet/readline/readline.html#SEC49 */ char * -nmc_rl_gen_func_basic (const char *text, int state, const char **words) +nmc_rl_gen_func_basic (const char *text, int state, const char *const*words) { static int list_idx, len; const char *name; diff --git a/clients/cli/common.h b/clients/cli/common.h index 3a598f631c..ca4b030820 100644 --- a/clients/cli/common.h +++ b/clients/cli/common.h @@ -25,27 +25,15 @@ #include "nmcli.h" #include "nm-secret-agent-simple.h" -gboolean print_ip4_config (NMIPConfig *cfg4, NmCli *nmc, const char *group_prefix, const char *one_field); -gboolean print_ip6_config (NMIPConfig *cfg6, NmCli *nmc, const char *group_prefix, const char *one_field); -gboolean print_dhcp4_config (NMDhcpConfig *dhcp4, NmCli *nmc, const char *group_prefix, const char *one_field); -gboolean print_dhcp6_config (NMDhcpConfig *dhcp6, NmCli *nmc, const char *group_prefix, const char *one_field); - -NMIPAddress *nmc_parse_and_build_address (int family, const char *ip_str, GError **error); -NMIPRoute *nmc_parse_and_build_route (int family, const char *str, GError **error); +gboolean print_ip4_config (NMIPConfig *cfg4, const NmcConfig *nmc_config, const char *group_prefix, 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); const char * nmc_device_state_to_string (NMDeviceState state); const char * nmc_device_reason_to_string (NMDeviceStateReason reason); const char * nmc_device_metered_to_string (NMMetered value); -char ** -nmc_vlan_parse_priority_maps (const char *priority_map, - NMVlanPriorityMap map_type, - GError **error); - -const char *nmc_bond_validate_mode (const char *mode, GError **error); -gboolean nmc_team_check_config (const char *config, char **out_config, GError **error); -gboolean nmc_proxy_check_script (const char *script, char **out_script, GError **error); - NMConnection *nmc_find_connection (const GPtrArray *connections, const char *filter_type, const char *filter_val, @@ -65,7 +53,7 @@ char *nmc_unique_connection_name (const GPtrArray *connections, void nmc_cleanup_readline (void); char *nmc_readline (const char *prompt_fmt, ...) G_GNUC_PRINTF (1, 2); char *nmc_readline_echo (gboolean echo_on, const char *prompt_fmt, ...) G_GNUC_PRINTF (2, 3); -char *nmc_rl_gen_func_basic (const char *text, int state, const char **words); +char *nmc_rl_gen_func_basic (const char *text, int state, const char *const*words); char *nmc_rl_gen_func_ifnames (const char *text, int state); gboolean nmc_get_in_readline (void); void nmc_set_in_readline (gboolean in_readline); diff --git a/clients/cli/connections.c b/clients/cli/connections.c index 07c1cd23c1..be52b75034 100644 --- a/clients/cli/connections.c +++ b/clients/cli/connections.c @@ -29,6 +29,8 @@ #include <readline/readline.h> #include <readline/history.h> +#include "nm-client-utils.h" + #include "utils.h" #include "common.h" #include "settings.h" @@ -38,6 +40,9 @@ #include "polkit-agent.h" #include "nm-vpn-helpers.h" +#define OUTPUT_FIELD_WITH_NAME(n) { .name = N_ (n), } +#define OUTPUT_FIELD_WITH_FIELDS(n, fields) { .name = N_ (n), .group_list = fields + 1, } + typedef struct _OptionInfo OptionInfo; struct _OptionInfo { const char *setting_name; @@ -127,66 +132,70 @@ struct _OptionInfo { /* Available fields for 'connection show' */ NmcOutputField nmc_fields_con_show[] = { - {"NAME", N_("NAME")}, /* 0 */ - {"UUID", N_("UUID")}, /* 1 */ - {"TYPE", N_("TYPE")}, /* 2 */ - {"TIMESTAMP", N_("TIMESTAMP")}, /* 3 */ - {"TIMESTAMP-REAL", N_("TIMESTAMP-REAL")}, /* 4 */ - {"AUTOCONNECT", N_("AUTOCONNECT")}, /* 5 */ - {"AUTOCONNECT-PRIORITY", N_("AUTOCONNECT-PRIORITY")}, /* 6 */ - {"READONLY", N_("READONLY")}, /* 7 */ - {"DBUS-PATH", N_("DBUS-PATH")}, /* 8 */ - {"ACTIVE", N_("ACTIVE")}, /* 9 */ - {"DEVICE", N_("DEVICE")}, /* 10 */ - {"STATE", N_("STATE")}, /* 11 */ - {"ACTIVE-PATH", N_("ACTIVE-PATH")}, /* 12 */ - {"SLAVE", N_("SLAVE")}, /* 13 */ - {NULL, NULL} + OUTPUT_FIELD_WITH_NAME ("NAME"), /* 0 */ + OUTPUT_FIELD_WITH_NAME ("UUID"), /* 1 */ + OUTPUT_FIELD_WITH_NAME ("TYPE"), /* 2 */ + OUTPUT_FIELD_WITH_NAME ("TIMESTAMP"), /* 3 */ + OUTPUT_FIELD_WITH_NAME ("TIMESTAMP-REAL"), /* 4 */ + OUTPUT_FIELD_WITH_NAME ("AUTOCONNECT"), /* 5 */ + OUTPUT_FIELD_WITH_NAME ("AUTOCONNECT-PRIORITY"), /* 6 */ + OUTPUT_FIELD_WITH_NAME ("READONLY"), /* 7 */ + OUTPUT_FIELD_WITH_NAME ("DBUS-PATH"), /* 8 */ + OUTPUT_FIELD_WITH_NAME ("ACTIVE"), /* 9 */ + OUTPUT_FIELD_WITH_NAME ("DEVICE"), /* 10 */ + OUTPUT_FIELD_WITH_NAME ("STATE"), /* 11 */ + OUTPUT_FIELD_WITH_NAME ("ACTIVE-PATH"), /* 12 */ + OUTPUT_FIELD_WITH_NAME ("SLAVE"), /* 13 */ + { 0 } }; #define NMC_FIELDS_CON_SHOW_ALL "NAME,UUID,TYPE,TIMESTAMP,TIMESTAMP-REAL,AUTOCONNECT,AUTOCONNECT-PRIORITY,READONLY,DBUS-PATH,"\ "ACTIVE,DEVICE,STATE,ACTIVE-PATH,SLAVE" #define NMC_FIELDS_CON_SHOW_COMMON "NAME,UUID,TYPE,DEVICE" /* Helper macro to define fields */ -#define SETTING_FIELD(setting, props) { setting, N_(setting), 0, props, NULL, FALSE, FALSE, 0 } +#define OUTPUT_FIELD_WITH_SETTING(setting, setting_type) \ + { \ + .name = setting, \ + .setting_info = &nm_meta_setting_infos_editor[setting_type], \ + } /* Available settings for 'connection show <con>' - profile part */ NmcOutputField nmc_fields_settings_names[] = { - SETTING_FIELD (NM_SETTING_CONNECTION_SETTING_NAME, nmc_fields_setting_connection + 1), /* 0 */ - SETTING_FIELD (NM_SETTING_WIRED_SETTING_NAME, nmc_fields_setting_wired + 1), /* 1 */ - SETTING_FIELD (NM_SETTING_802_1X_SETTING_NAME, nmc_fields_setting_8021X + 1), /* 2 */ - SETTING_FIELD (NM_SETTING_WIRELESS_SETTING_NAME, nmc_fields_setting_wireless + 1), /* 3 */ - SETTING_FIELD (NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, nmc_fields_setting_wireless_security + 1), /* 4 */ - SETTING_FIELD (NM_SETTING_IP4_CONFIG_SETTING_NAME, nmc_fields_setting_ip4_config + 1), /* 5 */ - SETTING_FIELD (NM_SETTING_IP6_CONFIG_SETTING_NAME, nmc_fields_setting_ip6_config + 1), /* 6 */ - SETTING_FIELD (NM_SETTING_SERIAL_SETTING_NAME, nmc_fields_setting_serial + 1), /* 7 */ - SETTING_FIELD (NM_SETTING_PPP_SETTING_NAME, nmc_fields_setting_ppp + 1), /* 8 */ - SETTING_FIELD (NM_SETTING_PPPOE_SETTING_NAME, nmc_fields_setting_pppoe + 1), /* 9 */ - SETTING_FIELD (NM_SETTING_GSM_SETTING_NAME, nmc_fields_setting_gsm + 1), /* 10 */ - SETTING_FIELD (NM_SETTING_CDMA_SETTING_NAME, nmc_fields_setting_cdma + 1), /* 11 */ - SETTING_FIELD (NM_SETTING_BLUETOOTH_SETTING_NAME, nmc_fields_setting_bluetooth + 1), /* 12 */ - SETTING_FIELD (NM_SETTING_OLPC_MESH_SETTING_NAME, nmc_fields_setting_olpc_mesh + 1), /* 13 */ - SETTING_FIELD (NM_SETTING_VPN_SETTING_NAME, nmc_fields_setting_vpn + 1), /* 14 */ - SETTING_FIELD (NM_SETTING_WIMAX_SETTING_NAME, nmc_fields_setting_wimax + 1), /* 15 */ - SETTING_FIELD (NM_SETTING_INFINIBAND_SETTING_NAME, nmc_fields_setting_infiniband + 1), /* 16 */ - SETTING_FIELD (NM_SETTING_BOND_SETTING_NAME, nmc_fields_setting_bond + 1), /* 17 */ - SETTING_FIELD (NM_SETTING_VLAN_SETTING_NAME, nmc_fields_setting_vlan + 1), /* 18 */ - SETTING_FIELD (NM_SETTING_ADSL_SETTING_NAME, nmc_fields_setting_adsl + 1), /* 19 */ - SETTING_FIELD (NM_SETTING_BRIDGE_SETTING_NAME, nmc_fields_setting_bridge + 1), /* 20 */ - SETTING_FIELD (NM_SETTING_BRIDGE_PORT_SETTING_NAME, nmc_fields_setting_bridge_port + 1), /* 21 */ - SETTING_FIELD (NM_SETTING_TEAM_SETTING_NAME, nmc_fields_setting_team + 1), /* 22 */ - SETTING_FIELD (NM_SETTING_TEAM_PORT_SETTING_NAME, nmc_fields_setting_team_port + 1), /* 23 */ - SETTING_FIELD (NM_SETTING_DCB_SETTING_NAME, nmc_fields_setting_dcb + 1), /* 24 */ - SETTING_FIELD (NM_SETTING_TUN_SETTING_NAME, nmc_fields_setting_tun + 1), /* 25 */ - SETTING_FIELD (NM_SETTING_IP_TUNNEL_SETTING_NAME, nmc_fields_setting_ip_tunnel + 1), /* 26 */ - SETTING_FIELD (NM_SETTING_MACSEC_SETTING_NAME, nmc_fields_setting_macsec + 1), /* 27 */ - SETTING_FIELD (NM_SETTING_MACVLAN_SETTING_NAME, nmc_fields_setting_macvlan + 1), /* 28 */ - SETTING_FIELD (NM_SETTING_VXLAN_SETTING_NAME, nmc_fields_setting_vxlan + 1), /* 29 */ - SETTING_FIELD (NM_SETTING_PROXY_SETTING_NAME, nmc_fields_setting_proxy + 1), /* 30 */ - SETTING_FIELD (NM_SETTING_DUMMY_SETTING_NAME, nmc_fields_setting_dummy + 1), /* 31 */ - {NULL, NULL, 0, NULL, NULL, FALSE, FALSE, 0} + OUTPUT_FIELD_WITH_SETTING (NM_SETTING_CONNECTION_SETTING_NAME, NM_META_SETTING_TYPE_CONNECTION), /* 0 */ + OUTPUT_FIELD_WITH_SETTING (NM_SETTING_WIRED_SETTING_NAME, NM_META_SETTING_TYPE_WIRED), /* 1 */ + OUTPUT_FIELD_WITH_SETTING (NM_SETTING_802_1X_SETTING_NAME, NM_META_SETTING_TYPE_802_1X), /* 2 */ + OUTPUT_FIELD_WITH_SETTING (NM_SETTING_WIRELESS_SETTING_NAME, NM_META_SETTING_TYPE_WIRELESS), /* 3 */ + OUTPUT_FIELD_WITH_SETTING (NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, NM_META_SETTING_TYPE_WIRELESS_SECURITY), /* 4 */ + OUTPUT_FIELD_WITH_SETTING (NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_META_SETTING_TYPE_IP4_CONFIG), /* 5 */ + OUTPUT_FIELD_WITH_SETTING (NM_SETTING_IP6_CONFIG_SETTING_NAME, NM_META_SETTING_TYPE_IP6_CONFIG), /* 6 */ + OUTPUT_FIELD_WITH_SETTING (NM_SETTING_SERIAL_SETTING_NAME, NM_META_SETTING_TYPE_SERIAL), /* 7 */ + OUTPUT_FIELD_WITH_SETTING (NM_SETTING_PPP_SETTING_NAME, NM_META_SETTING_TYPE_PPP), /* 8 */ + OUTPUT_FIELD_WITH_SETTING (NM_SETTING_PPPOE_SETTING_NAME, NM_META_SETTING_TYPE_PPPOE), /* 9 */ + OUTPUT_FIELD_WITH_SETTING (NM_SETTING_GSM_SETTING_NAME, NM_META_SETTING_TYPE_GSM), /* 10 */ + OUTPUT_FIELD_WITH_SETTING (NM_SETTING_CDMA_SETTING_NAME, NM_META_SETTING_TYPE_CDMA), /* 11 */ + OUTPUT_FIELD_WITH_SETTING (NM_SETTING_BLUETOOTH_SETTING_NAME, NM_META_SETTING_TYPE_BLUETOOTH), /* 12 */ + OUTPUT_FIELD_WITH_SETTING (NM_SETTING_OLPC_MESH_SETTING_NAME, NM_META_SETTING_TYPE_OLPC_MESH), /* 13 */ + OUTPUT_FIELD_WITH_SETTING (NM_SETTING_VPN_SETTING_NAME, NM_META_SETTING_TYPE_VPN), /* 14 */ + OUTPUT_FIELD_WITH_SETTING (NM_SETTING_WIMAX_SETTING_NAME, NM_META_SETTING_TYPE_WIMAX), /* 15 */ + OUTPUT_FIELD_WITH_SETTING (NM_SETTING_INFINIBAND_SETTING_NAME, NM_META_SETTING_TYPE_INFINIBAND), /* 16 */ + OUTPUT_FIELD_WITH_SETTING (NM_SETTING_BOND_SETTING_NAME, NM_META_SETTING_TYPE_BOND), /* 17 */ + OUTPUT_FIELD_WITH_SETTING (NM_SETTING_VLAN_SETTING_NAME, NM_META_SETTING_TYPE_VLAN), /* 18 */ + OUTPUT_FIELD_WITH_SETTING (NM_SETTING_ADSL_SETTING_NAME, NM_META_SETTING_TYPE_ADSL), /* 19 */ + OUTPUT_FIELD_WITH_SETTING (NM_SETTING_BRIDGE_SETTING_NAME, NM_META_SETTING_TYPE_BRIDGE), /* 20 */ + OUTPUT_FIELD_WITH_SETTING (NM_SETTING_BRIDGE_PORT_SETTING_NAME, NM_META_SETTING_TYPE_BRIDGE_PORT), /* 21 */ + OUTPUT_FIELD_WITH_SETTING (NM_SETTING_TEAM_SETTING_NAME, NM_META_SETTING_TYPE_TEAM), /* 22 */ + OUTPUT_FIELD_WITH_SETTING (NM_SETTING_TEAM_PORT_SETTING_NAME, NM_META_SETTING_TYPE_TEAM_PORT), /* 23 */ + OUTPUT_FIELD_WITH_SETTING (NM_SETTING_DCB_SETTING_NAME, NM_META_SETTING_TYPE_DCB), /* 24 */ + OUTPUT_FIELD_WITH_SETTING (NM_SETTING_TUN_SETTING_NAME, NM_META_SETTING_TYPE_TUN), /* 25 */ + OUTPUT_FIELD_WITH_SETTING (NM_SETTING_IP_TUNNEL_SETTING_NAME, NM_META_SETTING_TYPE_IP_TUNNEL), /* 26 */ + OUTPUT_FIELD_WITH_SETTING (NM_SETTING_MACSEC_SETTING_NAME, NM_META_SETTING_TYPE_MACSEC), /* 27 */ + OUTPUT_FIELD_WITH_SETTING (NM_SETTING_MACVLAN_SETTING_NAME, NM_META_SETTING_TYPE_MACVLAN), /* 28 */ + OUTPUT_FIELD_WITH_SETTING (NM_SETTING_VXLAN_SETTING_NAME, NM_META_SETTING_TYPE_VXLAN), /* 29 */ + OUTPUT_FIELD_WITH_SETTING (NM_SETTING_PROXY_SETTING_NAME, NM_META_SETTING_TYPE_PROXY), /* 30 */ + OUTPUT_FIELD_WITH_SETTING (NM_SETTING_DUMMY_SETTING_NAME, NM_META_SETTING_TYPE_DUMMY), /* 31 */ + { 0 } }; -#define NMC_FIELDS_SETTINGS_NAMES_ALL_X NM_SETTING_CONNECTION_SETTING_NAME","\ +#define NMC_FIELDS_SETTINGS_NAMES_ALL NM_SETTING_CONNECTION_SETTING_NAME","\ NM_SETTING_WIRED_SETTING_NAME","\ NM_SETTING_802_1X_SETTING_NAME","\ NM_SETTING_WIRELESS_SETTING_NAME","\ @@ -216,25 +225,26 @@ NmcOutputField nmc_fields_settings_names[] = { NM_SETTING_MACVLAN_SETTING_NAME"," \ NM_SETTING_VXLAN_SETTING_NAME"," \ NM_SETTING_PROXY_SETTING_NAME -#define NMC_FIELDS_SETTINGS_NAMES_ALL NMC_FIELDS_SETTINGS_NAMES_ALL_X + // NM_SETTING_DUMMY_SETTING_NAME + // NM_SETTING_WIMAX_SETTING_NAME /* Active connection data */ /* Available fields for GENERAL group */ NmcOutputField nmc_fields_con_active_details_general[] = { - {"GROUP", N_("GROUP")}, /* 0 */ - {"NAME", N_("NAME")}, /* 1 */ - {"UUID", N_("UUID")}, /* 2 */ - {"DEVICES", N_("DEVICES")}, /* 3 */ - {"STATE", N_("STATE")}, /* 4 */ - {"DEFAULT", N_("DEFAULT")}, /* 5 */ - {"DEFAULT6", N_("DEFAULT6")}, /* 6 */ - {"SPEC-OBJECT", N_("SPEC-OBJECT")}, /* 7 */ - {"VPN", N_("VPN")}, /* 8 */ - {"DBUS-PATH", N_("DBUS-PATH")}, /* 9 */ - {"CON-PATH", N_("CON-PATH")}, /* 10 */ - {"ZONE", N_("ZONE")}, /* 11 */ - {"MASTER-PATH", N_("MASTER-PATH")}, /* 12 */ - {NULL, NULL} + OUTPUT_FIELD_WITH_NAME ("GROUP"), /* 0 */ + OUTPUT_FIELD_WITH_NAME ("NAME"), /* 1 */ + OUTPUT_FIELD_WITH_NAME ("UUID"), /* 2 */ + OUTPUT_FIELD_WITH_NAME ("DEVICES"), /* 3 */ + OUTPUT_FIELD_WITH_NAME ("STATE"), /* 4 */ + OUTPUT_FIELD_WITH_NAME ("DEFAULT"), /* 5 */ + OUTPUT_FIELD_WITH_NAME ("DEFAULT6"), /* 6 */ + OUTPUT_FIELD_WITH_NAME ("SPEC-OBJECT"), /* 7 */ + OUTPUT_FIELD_WITH_NAME ("VPN"), /* 8 */ + OUTPUT_FIELD_WITH_NAME ("DBUS-PATH"), /* 9 */ + OUTPUT_FIELD_WITH_NAME ("CON-PATH"), /* 10 */ + OUTPUT_FIELD_WITH_NAME ("ZONE"), /* 11 */ + OUTPUT_FIELD_WITH_NAME ("MASTER-PATH"), /* 12 */ + { 0 } }; #define NMC_FIELDS_CON_ACTIVE_DETAILS_GENERAL_ALL "GROUP,NAME,UUID,DEVICES,STATE,DEFAULT,DEFAULT6,"\ "VPN,ZONE,DBUS-PATH,CON-PATH,SPEC-OBJECT,MASTER-PATH" @@ -243,14 +253,14 @@ NmcOutputField nmc_fields_con_active_details_general[] = { /* Available fields for VPN group */ NmcOutputField nmc_fields_con_active_details_vpn[] = { - {"GROUP", N_("GROUP")}, /* 0 */ - {"TYPE", N_("TYPE")}, /* 1 */ - {"USERNAME", N_("USERNAME")}, /* 2 */ - {"GATEWAY", N_("GATEWAY")}, /* 3 */ - {"BANNER", N_("BANNER")}, /* 4 */ - {"VPN-STATE", N_("VPN-STATE")}, /* 5 */ - {"CFG", N_("CFG")}, /* 6 */ - {NULL, NULL} + OUTPUT_FIELD_WITH_NAME ("GROUP"), /* 0 */ + OUTPUT_FIELD_WITH_NAME ("TYPE"), /* 1 */ + OUTPUT_FIELD_WITH_NAME ("USERNAME"), /* 2 */ + OUTPUT_FIELD_WITH_NAME ("GATEWAY"), /* 3 */ + OUTPUT_FIELD_WITH_NAME ("BANNER"), /* 4 */ + OUTPUT_FIELD_WITH_NAME ("VPN-STATE"), /* 5 */ + OUTPUT_FIELD_WITH_NAME ("CFG"), /* 6 */ + { 0 } }; #define NMC_FIELDS_CON_ACTIVE_DETAILS_VPN_ALL "GROUP,TYPE,USERNAME,GATEWAY,BANNER,VPN-STATE,CFG" @@ -262,13 +272,13 @@ extern NmcOutputField nmc_fields_dhcp6_config[]; /* Available fields for 'connection show <con>' - active part */ NmcOutputField nmc_fields_con_active_details_groups[] = { - {"GENERAL", N_("GENERAL"), 0, nmc_fields_con_active_details_general + 1}, /* 0 */ - {"IP4", N_("IP4"), 0, nmc_fields_ip4_config + 1 }, /* 1 */ - {"DHCP4", N_("DHCP4"), 0, nmc_fields_dhcp4_config + 1 }, /* 2 */ - {"IP6", N_("IP6"), 0, nmc_fields_ip6_config + 1 }, /* 3 */ - {"DHCP6", N_("DHCP6"), 0, nmc_fields_dhcp6_config + 1 }, /* 4 */ - {"VPN", N_("VPN"), 0, nmc_fields_con_active_details_vpn + 1 }, /* 5 */ - {NULL, NULL, 0, NULL} + OUTPUT_FIELD_WITH_FIELDS ("GENERAL", nmc_fields_con_active_details_general), /* 0 */ + OUTPUT_FIELD_WITH_FIELDS ("IP4", nmc_fields_ip4_config), /* 1 */ + OUTPUT_FIELD_WITH_FIELDS ("DHCP4", nmc_fields_dhcp4_config), /* 2 */ + OUTPUT_FIELD_WITH_FIELDS ("IP6", nmc_fields_ip6_config), /* 3 */ + OUTPUT_FIELD_WITH_FIELDS ("DHCP6", nmc_fields_dhcp6_config), /* 4 */ + OUTPUT_FIELD_WITH_FIELDS ("VPN", nmc_fields_con_active_details_vpn), /* 5 */ + { 0 } }; #define NMC_FIELDS_CON_ACTIVE_DETAILS_ALL "GENERAL,IP4,DHCP4,IP6,DHCP6,VPN" @@ -780,12 +790,16 @@ nmc_connection_profile_details (NMConnection *connection, NmCli *nmc, gboolean s g_assert (print_settings_array); /* Main header */ - nmc->print_fields.header_name = (char *) construct_header_name (base_hdr, nm_connection_get_id (connection)); - nmc->print_fields.indices = parse_output_fields (NMC_FIELDS_SETTINGS_NAMES_ALL, - nmc_fields_settings_names, FALSE, NULL, NULL); + { + NMC_OUTPUT_DATA_DEFINE_SCOPED (out); - nmc_fields_settings_names[0].flags = NMC_OF_FLAG_MAIN_HEADER_ONLY; - print_required_fields (nmc, nmc_fields_settings_names); + out.print_fields.header_name = (char *) construct_header_name (base_hdr, nm_connection_get_id (connection)); + out.print_fields.indices = parse_output_fields (NMC_FIELDS_SETTINGS_NAMES_ALL, + nmc_fields_settings_names, FALSE, NULL, NULL); + + nmc_fields_settings_names[0].flags = NMC_OF_FLAG_MAIN_HEADER_ONLY; + print_required_fields (&nmc->nmc_config, &out.print_fields, nmc_fields_settings_names); + } /* Loop through the required settings and print them. */ for (i = 0; i < print_settings_array->len; i++) { @@ -793,19 +807,15 @@ nmc_connection_profile_details (NMConnection *connection, NmCli *nmc, gboolean s int section_idx = g_array_index (print_settings_array, int, i); const char *prop_name = (const char *) g_ptr_array_index (prop_array, i); - if (nmc->print_output != NMC_PRINT_TERSE && !nmc->multiline_output && was_output) + if (nmc->nmc_config.print_output != NMC_PRINT_TERSE && !nmc->nmc_config.multiline_output && was_output) g_print ("\n"); /* Empty line */ was_output = FALSE; - /* Remove any previous data */ - nmc_empty_output_fields (nmc); - setting = nm_connection_get_setting_by_name (connection, nmc_fields_settings_names[section_idx].name); if (setting) { setting_details (setting, nmc, prop_name, secrets); was_output = TRUE; - continue; } } @@ -907,7 +917,7 @@ nmc_active_connection_state_to_color (NMActiveConnectionState state, NmcTermColo } static void -fill_output_connection (NMConnection *connection, NmCli *nmc, gboolean active_only) +fill_output_connection (NMConnection *connection, NMClient *client, GPtrArray *output_data, gboolean active_only) { NMSettingConnection *s_con; guint64 timestamp; @@ -926,7 +936,7 @@ fill_output_connection (NMConnection *connection, NmCli *nmc, gboolean active_on s_con = nm_connection_get_setting_connection (connection); g_assert (s_con); - ac = get_ac_for_connection (nm_client_get_active_connections (nmc->client), connection); + ac = get_ac_for_connection (nm_client_get_active_connections (client), connection); if (active_only && !ac) return; @@ -970,11 +980,11 @@ fill_output_connection (NMConnection *connection, NmCli *nmc, gboolean active_on set_val_strc (arr, 12, ac_path); set_val_strc (arr, 13, nm_setting_connection_get_slave_type (s_con)); - g_ptr_array_add (nmc->output_data, arr); + g_ptr_array_add (output_data, arr); } static void -fill_output_connection_for_invisible (NMActiveConnection *ac, NmCli *nmc) +fill_output_connection_for_invisible (NMActiveConnection *ac, GPtrArray *output_data) { NmcOutputField *arr; const char *ac_path = NULL; @@ -1007,12 +1017,12 @@ fill_output_connection_for_invisible (NMActiveConnection *ac, NmCli *nmc) set_val_color_fmt_all (arr, NMC_TERM_FORMAT_DIM); - g_ptr_array_add (nmc->output_data, arr); + g_ptr_array_add (output_data, arr); } static void fill_output_active_connection (NMActiveConnection *active, - NmCli *nmc, + GPtrArray *output_data, gboolean with_group, guint32 o_flags) { @@ -1079,7 +1089,7 @@ fill_output_active_connection (NMActiveConnection *active, set_val_strc (arr, 12-idx_start, master ? nm_object_get_path (NM_OBJECT (master)) : NULL); set_val_strc (arr, 13-idx_start, s_con ? nm_setting_connection_get_slave_type (s_con) : NULL); - g_ptr_array_add (nmc->output_data, arr); + g_ptr_array_add (output_data, arr); g_string_free (dev_str, FALSE); } @@ -1207,40 +1217,44 @@ nmc_active_connection_details (NMActiveConnection *acon, NmCli *nmc) g_assert (print_groups); /* Main header */ - nmc->print_fields.header_name = (char *) construct_header_name (base_hdr, nm_active_connection_get_uuid (acon)); - nmc->print_fields.indices = parse_output_fields (NMC_FIELDS_CON_ACTIVE_DETAILS_ALL, - nmc_fields_con_active_details_groups, FALSE, NULL, NULL); + { + NMC_OUTPUT_DATA_DEFINE_SCOPED (out); - nmc_fields_con_active_details_groups[0].flags = NMC_OF_FLAG_MAIN_HEADER_ONLY; - print_required_fields (nmc, nmc_fields_con_active_details_groups); + out.print_fields.header_name = (char *) construct_header_name (base_hdr, nm_active_connection_get_uuid (acon)); + out.print_fields.indices = parse_output_fields (NMC_FIELDS_CON_ACTIVE_DETAILS_ALL, + nmc_fields_con_active_details_groups, FALSE, NULL, NULL); + + nmc_fields_con_active_details_groups[0].flags = NMC_OF_FLAG_MAIN_HEADER_ONLY; + print_required_fields (&nmc->nmc_config, &out.print_fields, nmc_fields_con_active_details_groups); + } /* Loop through the groups and print them. */ for (i = 0; i < print_groups->len; i++) { int group_idx = g_array_index (print_groups, int, i); char *group_fld = (char *) g_ptr_array_index (group_fields, i); - if (nmc->print_output != NMC_PRINT_TERSE && !nmc->multiline_output && was_output) + if (nmc->nmc_config.print_output != NMC_PRINT_TERSE && !nmc->nmc_config.multiline_output && was_output) g_print ("\n"); /* Empty line */ was_output = FALSE; - /* Remove any previous data */ - nmc_empty_output_fields (nmc); - /* GENERAL */ if (strcasecmp (nmc_fields_con_active_details_groups[group_idx].name, nmc_fields_con_active_details_groups[0].name) == 0) { + NMC_OUTPUT_DATA_DEFINE_SCOPED (out); + /* Add field names */ tmpl = nmc_fields_con_active_details_general; tmpl_len = sizeof (nmc_fields_con_active_details_general); - nmc->print_fields.indices = parse_output_fields (group_fld ? group_fld : NMC_FIELDS_CON_ACTIVE_DETAILS_GENERAL_ALL, - tmpl, FALSE, NULL, NULL); + out.print_fields.indices = parse_output_fields (group_fld ? group_fld : NMC_FIELDS_CON_ACTIVE_DETAILS_GENERAL_ALL, + tmpl, FALSE, NULL, NULL); arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); - g_ptr_array_add (nmc->output_data, arr); + g_ptr_array_add (out.output_data, arr); /* Fill in values */ - fill_output_active_connection (acon, nmc, TRUE, NMC_OF_FLAG_SECTION_PREFIX); + fill_output_active_connection (acon, out.output_data, TRUE, NMC_OF_FLAG_SECTION_PREFIX); - print_data (nmc); /* Print all data */ + print_data_prepare_width (out.output_data); + print_data (&nmc->nmc_config, &out); was_output = TRUE; } @@ -1250,7 +1264,7 @@ nmc_active_connection_details (NMActiveConnection *acon, NmCli *nmc) gboolean b1 = FALSE; NMIPConfig *cfg4 = nm_active_connection_get_ip4_config (acon); - b1 = print_ip4_config (cfg4, nmc, "IP4", group_fld); + b1 = print_ip4_config (cfg4, &nmc->nmc_config, "IP4", group_fld); was_output = was_output || b1; } @@ -1259,7 +1273,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, "DHCP4", group_fld); + b1 = print_dhcp4_config (dhcp4, &nmc->nmc_config, "DHCP4", group_fld); was_output = was_output || b1; } @@ -1268,7 +1282,7 @@ nmc_active_connection_details (NMActiveConnection *acon, NmCli *nmc) gboolean b1 = FALSE; NMIPConfig *cfg6 = nm_active_connection_get_ip6_config (acon); - b1 = print_ip6_config (cfg6, nmc, "IP6", group_fld); + b1 = print_ip6_config (cfg6, &nmc->nmc_config, "IP6", group_fld); was_output = was_output || b1; } @@ -1277,7 +1291,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, "DHCP6", group_fld); + b1 = print_dhcp6_config (dhcp6, &nmc->nmc_config, "DHCP6", group_fld); was_output = was_output || b1; } @@ -1293,6 +1307,7 @@ nmc_active_connection_details (NMActiveConnection *acon, NmCli *nmc) const char *username = NULL; char **vpn_data_array = NULL; guint32 items_num; + NMC_OUTPUT_DATA_DEFINE_SCOPED (out); con = NM_CONNECTION (nm_active_connection_get_connection (acon)); @@ -1301,10 +1316,10 @@ nmc_active_connection_details (NMActiveConnection *acon, NmCli *nmc) tmpl = nmc_fields_con_active_details_vpn; tmpl_len = sizeof (nmc_fields_con_active_details_vpn); - nmc->print_fields.indices = parse_output_fields (group_fld ? group_fld : NMC_FIELDS_CON_ACTIVE_DETAILS_VPN_ALL, - tmpl, FALSE, NULL, NULL); + out.print_fields.indices = parse_output_fields (group_fld ? group_fld : NMC_FIELDS_CON_ACTIVE_DETAILS_VPN_ALL, + tmpl, FALSE, NULL, NULL); arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); - g_ptr_array_add (nmc->output_data, arr); + g_ptr_array_add (out.output_data, arr); s_vpn = nm_connection_get_setting_vpn (con); if (s_vpn) { @@ -1337,9 +1352,10 @@ nmc_active_connection_details (NMActiveConnection *acon, NmCli *nmc) set_val_str (arr, 4, banner_str); set_val_str (arr, 5, vpn_state_str); set_val_arr (arr, 6, vpn_data_array); - g_ptr_array_add (nmc->output_data, arr); + g_ptr_array_add (out.output_data, arr); - print_data (nmc); /* Print all data */ + print_data_prepare_width (out.output_data); + print_data (&nmc->nmc_config, &out); was_output = TRUE; } } @@ -1784,6 +1800,7 @@ do_connections_show (NmCli *nmc, int argc, char **argv) char *fields_common = NMC_FIELDS_CON_SHOW_COMMON; NmcOutputField *tmpl, *arr; size_t tmpl_len; + NMC_OUTPUT_DATA_DEFINE_SCOPED (out); if (nmc->complete) goto finish; @@ -1797,31 +1814,32 @@ do_connections_show (NmCli *nmc, int argc, char **argv) tmpl = nmc_fields_con_show; tmpl_len = sizeof (nmc_fields_con_show); - nmc->print_fields.indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, &err); + out.print_fields.indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, &err); if (err) goto finish; /* Add headers */ - nmc->print_fields.header_name = active_only ? _("NetworkManager active profiles") : + out.print_fields.header_name = active_only ? _("NetworkManager active profiles") : _("NetworkManager connection profiles"); arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_MAIN_HEADER_ADD | NMC_OF_FLAG_FIELD_NAMES); - g_ptr_array_add (nmc->output_data, arr); + g_ptr_array_add (out.output_data, arr); /* There might be active connections not present in connection list * (e.g. private connections of a different user). Show them as well. */ invisibles = get_invisible_active_connections (nmc); for (i = 0; i < invisibles->len; i++) - fill_output_connection_for_invisible (invisibles->pdata[i], nmc); + fill_output_connection_for_invisible (invisibles->pdata[i], out.output_data); g_ptr_array_free (invisibles, TRUE); /* Sort the connections and fill the output data */ connections = nm_client_get_connections (nmc->client); sorted_cons = sort_connections (connections, nmc, order); for (i = 0; i < sorted_cons->len; i++) - fill_output_connection (sorted_cons->pdata[i], nmc, active_only); + fill_output_connection (sorted_cons->pdata[i], nmc->client, out.output_data, active_only); g_ptr_array_free (sorted_cons, TRUE); - print_data (nmc); /* Print all data */ + print_data_prepare_width (out.output_data); + print_data (&nmc->nmc_config, &out); } else { gboolean new_line = FALSE; gboolean without_fields = (nmc->required_fields == NULL); @@ -1830,7 +1848,7 @@ do_connections_show (NmCli *nmc, int argc, char **argv) /* multiline mode is default for 'connection show <ID>' */ if (!nmc->mode_specified) - nmc->multiline_output = TRUE; + nmc->nmc_config_mutable.multiline_output = TRUE; /* Split required fields into the settings and active ones. */ if (!split_required_fields_for_con_show (nmc->required_fields, &profile_flds, &active_flds, &err)) @@ -2178,7 +2196,7 @@ check_activated (ActivateConnectionInfo *info) } if (ac_state == NM_ACTIVE_CONNECTION_STATE_ACTIVATED) { - if (nmc->print_output == NMC_PRINT_PRETTY) + if (nmc->nmc_config.print_output == NMC_PRINT_PRETTY) nmc_terminal_erase_line (); g_print (_("Connection successfully activated (D-Bus active path: %s)\n"), nm_object_get_path (NM_OBJECT (active))); @@ -2218,7 +2236,7 @@ check_activated (ActivateConnectionInfo *info) || NM_IS_DEVICE_BRIDGE (device)) && dev_state >= NM_DEVICE_STATE_IP_CONFIG && dev_state <= NM_DEVICE_STATE_ACTIVATED) { - if (nmc->print_output == NMC_PRINT_PRETTY) + if (nmc->nmc_config.print_output == NMC_PRINT_PRETTY) nmc_terminal_erase_line (); g_print (_("Connection successfully activated (master waiting for slaves) (D-Bus active path: %s)\n"), nm_object_get_path (NM_OBJECT (active))); @@ -2348,7 +2366,7 @@ activate_connection_cb (GObject *client, GAsyncResult *result, gpointer user_dat if (nmc->nowait_flag || state == NM_ACTIVE_CONNECTION_STATE_ACTIVATED) { /* User doesn't want to wait or already activated */ if (state == NM_ACTIVE_CONNECTION_STATE_ACTIVATED) { - if (nmc->print_output == NMC_PRINT_PRETTY) + if (nmc->nmc_config.print_output == NMC_PRINT_PRETTY) nmc_terminal_erase_line (); g_print (_("Connection successfully activated (D-Bus active path: %s)\n"), nm_object_get_path (NM_OBJECT (active))); @@ -2368,7 +2386,7 @@ activate_connection_cb (GObject *client, GAsyncResult *result, gpointer user_dat } /* Start progress indication showing VPN states */ - if (nmc->print_output == NMC_PRINT_PRETTY) { + if (nmc->nmc_config.print_output == NMC_PRINT_PRETTY) { if (progress_id) g_source_remove (progress_id); progress_id = g_timeout_add (120, progress_active_connection_cb, active); @@ -2656,7 +2674,7 @@ do_connection_up (NmCli *nmc, int argc, char **argv) } /* Start progress indication */ - if (nmc->print_output == NMC_PRINT_PRETTY) + if (nmc->nmc_config.print_output == NMC_PRINT_PRETTY) progress_id = g_timeout_add (120, progress_cb, _("preparing")); return nmc->return_value; @@ -2691,7 +2709,7 @@ down_active_connection_state_cb (NMActiveConnection *active, if (nm_active_connection_get_state (active) < NM_ACTIVE_CONNECTION_STATE_DEACTIVATED) return; - if (info->nmc->print_output == NMC_PRINT_PRETTY) + if (info->nmc->nmc_config.print_output == NMC_PRINT_PRETTY) nmc_terminal_erase_line (); g_print (_("Connection '%s' successfully deactivated (D-Bus active path: %s)\n"), nm_active_connection_get_id (active), nm_object_get_path (NM_OBJECT (active))); @@ -3179,6 +3197,7 @@ get_valid_properties_string (const NameItem *array, { const NameItem *iter = array; const NmcOutputField *field_iter; + const NMMetaSettingInfoEditor *setting_info; const char *prop_name = NULL; GString *str; int i, j; @@ -3219,20 +3238,31 @@ get_valid_properties_string (const NameItem *array, g_assert (nmc_fields_settings_names[j].name); j++; } - field_iter = nmc_fields_settings_names[j].group; + field_iter = nmc_fields_settings_names[j].group_list; + setting_info = nmc_fields_settings_names[j].setting_info; j = 0; - while (field_iter[j].name) { + while (TRUE) { gchar *new; - const char *arg_name = field_iter[j].name; + const char *arg_name; + + if (field_iter) { + arg_name = field_iter[j].name; + if (!arg_name) + break; + } else { + if (j + 1 >= setting_info->properties_num) + break; + arg_name = setting_info->properties[j + 1].property_name; + } /* If required, expand the alias too */ if (!postfix && iter->alias) { if (modifier) g_string_append_c (str, modifier); new = g_strdup_printf ("%s.%s\n", - iter->alias, - arg_name); + iter->alias, + arg_name); g_string_append (str, new); g_free (new); } @@ -3245,8 +3275,8 @@ get_valid_properties_string (const NameItem *array, if (modifier) g_string_append_c (str, modifier); new = g_strdup_printf ("%s.%s\n", - prop_name, - arg_name); + prop_name, + arg_name); g_string_append (str, new); g_free (new); j++; @@ -5682,27 +5712,24 @@ should_complete_vpn_uuids (const char *prompt, const char *line) return _get_and_check_property (prompt, line, uuid_properties, NULL, NULL); } -static const char ** -get_allowed_property_values (void) +static const char *const* +get_allowed_property_values (char ***out_to_free) { - NMSetting *setting; - char *property; - const char **avals = NULL; + gs_unref_object NMSetting *setting = NULL; + gs_free char *property = NULL; + const char *const*avals = NULL; get_setting_and_property (rl_prompt, rl_line_buffer, &setting, &property); if (setting && property) - avals = nmc_setting_get_property_allowed_values (setting, property); - - if (setting) - g_object_unref (setting); - g_free (property); - + avals = nmc_setting_get_property_allowed_values (setting, property, out_to_free); return avals; } static gboolean should_complete_property_values (const char *prompt, const char *line, gboolean *multi) { + gs_strfreev char **to_free = NULL; + /* properties allowing multiple values */ const char *multi_props[] = { /* '802-1x' properties */ @@ -5718,10 +5745,9 @@ should_complete_property_values (const char *prompt, const char *line, gboolean NULL }; _get_and_check_property (prompt, line, NULL, multi_props, multi); - return get_allowed_property_values () != NULL; + return !!get_allowed_property_values (&to_free); } -//FIXME: this helper should go to libnm later static gboolean _setting_property_is_boolean (NMSetting *setting, const char *property_name) { @@ -5757,13 +5783,13 @@ should_complete_boolean (const char *prompt, const char *line) static char * gen_property_values (const char *text, int state) { - char *ret = NULL; - const char **avals; + gs_strfreev char **to_free = NULL; + const char *const*avals; - avals = get_allowed_property_values (); - if (avals) - ret = nmc_rl_gen_func_basic (text, state, avals); - return ret; + avals = get_allowed_property_values (&to_free); + if (!avals) + return NULL; + return nmc_rl_gen_func_basic (text, state, avals); } /* from readline */ @@ -5997,12 +6023,9 @@ save_history_cmds (const char *uuid) static void editor_show_connection (NMConnection *connection, NmCli *nmc) { - nmc->print_output = NMC_PRINT_PRETTY; - nmc->multiline_output = TRUE; - nmc->escape_values = 0; - - /* Remove any previous data */ - nmc_empty_output_fields (nmc); + nmc->nmc_config_mutable.print_output = NMC_PRINT_PRETTY; + nmc->nmc_config_mutable.multiline_output = TRUE; + nmc->nmc_config_mutable.escape_values = 0; nmc_connection_profile_details (connection, nmc, nmc->editor_show_secrets); } @@ -6013,12 +6036,9 @@ editor_show_setting (NMSetting *setting, NmCli *nmc) g_print (_("['%s' setting values]\n"), nm_setting_get_name (setting)); - nmc->print_output = NMC_PRINT_NORMAL; - nmc->multiline_output = TRUE; - nmc->escape_values = 0; - - /* Remove any previous data */ - nmc_empty_output_fields (nmc); + nmc->nmc_config_mutable.print_output = NMC_PRINT_NORMAL; + nmc->nmc_config_mutable.multiline_output = TRUE; + nmc->nmc_config_mutable.escape_values = 0; setting_details (setting, nmc, NULL, nmc->editor_show_secrets); } @@ -6606,7 +6626,7 @@ property_edit_submenu (NmCli *nmc, /* Set global variable for use in TAB completion */ nmc_tab_completion.property = prop_name; - prompt = nmc_colorize (nmc, nmc->editor_prompt_color, NMC_TERM_FORMAT_NORMAL, + prompt = nmc_colorize (nmc->nmc_config.use_colors, nmc->editor_prompt_color, NMC_TERM_FORMAT_NORMAL, "nmcli %s.%s> ", nm_setting_get_name (curr_setting), prop_name); @@ -6639,12 +6659,16 @@ property_edit_submenu (NmCli *nmc, * single values: : both SET and ADD sets the new value */ if (!cmd_property_arg) { - const char **avals = nmc_setting_get_property_allowed_values (curr_setting, prop_name); + gs_strfreev char **to_free = NULL; + const char *const*avals; + + avals = nmc_setting_get_property_allowed_values (curr_setting, prop_name, &to_free); if (avals) { - char *avals_str = nmc_util_strv_for_display (avals, FALSE); + gs_free char *avals_str = NULL; + + avals_str = nmc_util_strv_for_display (avals, FALSE); g_print (_("Allowed values for '%s' property: %s\n"), prop_name, avals_str); - g_free (avals_str); } prop_val_user = nmc_readline (_("Enter '%s' value: "), prop_name); } else @@ -6938,14 +6962,14 @@ typedef struct { } NmcEditorMenuContext; static void -menu_switch_to_level0 (NmCli *nmc, +menu_switch_to_level0 (NmcColorOption color_option, NmcEditorMenuContext *menu_ctx, const char *prompt, NmcTermColor prompt_color) { menu_ctx->level = 0; g_free (menu_ctx->main_prompt); - menu_ctx->main_prompt = nmc_colorize (nmc, prompt_color, NMC_TERM_FORMAT_NORMAL, "%s", prompt); + menu_ctx->main_prompt = nmc_colorize (color_option, prompt_color, NMC_TERM_FORMAT_NORMAL, "%s", prompt); menu_ctx->curr_setting = NULL; g_strfreev (menu_ctx->valid_props); menu_ctx->valid_props = NULL; @@ -6954,7 +6978,7 @@ menu_switch_to_level0 (NmCli *nmc, } static void -menu_switch_to_level1 (NmCli *nmc, +menu_switch_to_level1 (NmcColorOption color_option, NmcEditorMenuContext *menu_ctx, NMSetting *setting, const char *setting_name, @@ -6962,7 +6986,7 @@ menu_switch_to_level1 (NmCli *nmc, { menu_ctx->level = 1; g_free (menu_ctx->main_prompt); - menu_ctx->main_prompt = nmc_colorize (nmc, prompt_color, NMC_TERM_FORMAT_NORMAL, + menu_ctx->main_prompt = nmc_colorize (color_option, prompt_color, NMC_TERM_FORMAT_NORMAL, "nmcli %s> ", setting_name); menu_ctx->curr_setting = setting; g_strfreev (menu_ctx->valid_props); @@ -7008,7 +7032,7 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t g_print (_("You may edit the following settings: %s\n"), valid_settings_str); menu_ctx.level = 0; - menu_ctx.main_prompt = nmc_colorize (nmc, nmc->editor_prompt_color, NMC_TERM_FORMAT_NORMAL, + menu_ctx.main_prompt = nmc_colorize (nmc->nmc_config.use_colors, nmc->editor_prompt_color, NMC_TERM_FORMAT_NORMAL, BASE_PROMPT); menu_ctx.curr_setting = NULL; menu_ctx.valid_props = NULL; @@ -7049,9 +7073,10 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t /* Set property value */ if (!cmd_arg) { if (menu_ctx.level == 1) { + gs_strfreev char **avals_to_free = NULL; + gs_free char *prop_val_user = NULL; const char *prop_name; - char *prop_val_user = NULL; - const char **avals; + const char *const*avals; GError *tmp_err = NULL; prop_name = ask_check_property (cmd_arg, @@ -7060,12 +7085,13 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t if (!prop_name) break; - avals = nmc_setting_get_property_allowed_values (menu_ctx.curr_setting, prop_name); + avals = nmc_setting_get_property_allowed_values (menu_ctx.curr_setting, prop_name, &avals_to_free); if (avals) { - char *avals_str = nmc_util_strv_for_display (avals, FALSE); + gs_free char *avals_str = NULL; + + avals_str = nmc_util_strv_for_display (avals, FALSE); g_print (_("Allowed values for '%s' property: %s\n"), prop_name, avals_str); - g_free (avals_str); } prop_val_user = nmc_readline (_("Enter '%s' value: "), prop_name); @@ -7118,12 +7144,16 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t /* Ask for value */ if (!cmd_arg_v) { - const char **avals = nmc_setting_get_property_allowed_values (ss, prop_name); + gs_strfreev char **avals_to_free = NULL; + const char *const*avals; + + avals = nmc_setting_get_property_allowed_values (ss, prop_name, &avals_to_free); if (avals) { - char *avals_str = nmc_util_strv_for_display (avals, FALSE); + gs_free char *avals_str = NULL; + + avals_str = nmc_util_strv_for_display (avals, FALSE); g_print (_("Allowed values for '%s' property: %s\n"), prop_name, avals_str); - g_free (avals_str); } cmd_arg_v = nmc_readline (_("Enter '%s' value: "), prop_name); } @@ -7180,7 +7210,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, &menu_ctx, setting, setting_name, nmc->editor_prompt_color); + menu_switch_to_level1 (nmc->nmc_config.use_colors, &menu_ctx, setting, setting_name, nmc->editor_prompt_color); if (!cmd_arg_s) { g_print (_("You may edit the following properties: %s\n"), menu_ctx.valid_props_str); @@ -7261,7 +7291,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, &menu_ctx, BASE_PROMPT, nmc->editor_prompt_color); + menu_switch_to_level0 (nmc->nmc_config.use_colors, &menu_ctx, BASE_PROMPT, nmc->editor_prompt_color); nmc_tab_completion.setting = NULL; /* for TAB completion */ } } else { @@ -7287,7 +7317,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, &menu_ctx, BASE_PROMPT, nmc->editor_prompt_color); + menu_switch_to_level0 (nmc->nmc_config.use_colors, &menu_ctx, BASE_PROMPT, nmc->editor_prompt_color); nmc_tab_completion.setting = NULL; /* for TAB completion */ } } else @@ -7599,7 +7629,7 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t nmc->nowait_flag = FALSE; nmc->should_wait++; - nmc->print_output = NMC_PRINT_PRETTY; + nmc->nmc_config_mutable.print_output = NMC_PRINT_PRETTY; if (!nmc_activate_connection (nmc, NM_CONNECTION (rem_con), ifname, ap_nsp, ap_nsp, NULL, activate_connection_editor_cb, &tmp_err)) { g_print (_("Error: Cannot activate connection: %s.\n"), tmp_err->message); @@ -7638,7 +7668,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, &menu_ctx, BASE_PROMPT, nmc->editor_prompt_color); + menu_switch_to_level0 (nmc->nmc_config.use_colors, &menu_ctx, BASE_PROMPT, nmc->editor_prompt_color); nmc_tab_completion.setting = NULL; /* for TAB completion */ } break; @@ -7684,10 +7714,10 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t nmc->editor_prompt_color = color; g_free (menu_ctx.main_prompt); if (menu_ctx.level == 0) - menu_ctx.main_prompt = nmc_colorize (nmc, nmc->editor_prompt_color, NMC_TERM_FORMAT_NORMAL, + menu_ctx.main_prompt = nmc_colorize (nmc->nmc_config.use_colors, nmc->editor_prompt_color, NMC_TERM_FORMAT_NORMAL, BASE_PROMPT); else - menu_ctx.main_prompt = nmc_colorize (nmc, nmc->editor_prompt_color, NMC_TERM_FORMAT_NORMAL, + menu_ctx.main_prompt = nmc_colorize (nmc->nmc_config.use_colors, nmc->editor_prompt_color, NMC_TERM_FORMAT_NORMAL, "nmcli %s> ", nm_setting_get_name (menu_ctx.curr_setting)); } @@ -8024,7 +8054,7 @@ do_connection_edit (NmCli *nmc, int argc, char **argv) } /* nmcli runs the editor */ - nmc->in_editor = TRUE; + nmc->nmc_config_mutable.in_editor = TRUE; g_print ("\n"); g_print (_("===| nmcli interactive connection editor |===")); @@ -8077,7 +8107,7 @@ modify_connection_cb (GObject *connection, g_error_free (error); nmc->return_value = NMC_RESULT_ERROR_UNKNOWN; } else { - if (nmc->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))); diff --git a/clients/cli/devices.c b/clients/cli/devices.c index ce8febcc61..69c913a9d5 100644 --- a/clients/cli/devices.c +++ b/clients/cli/devices.c @@ -26,6 +26,8 @@ #include <readline/readline.h> #include "nm-secret-agent-simple.h" +#include "nm-client-utils.h" + #include "polkit-agent.h" #include "utils.h" #include "common.h" @@ -36,16 +38,19 @@ #define PROMPT_INTERFACE _("Interface: ") #define PROMPT_INTERFACES _("Interface(s): ") +#define OUTPUT_FIELD_WITH_NAME(n) { .name = N_ (n), } +#define OUTPUT_FIELD_WITH_FIELDS(n, fields) { .name = N_ (n), .group_list = fields + 1, } + /* Available fields for 'device status' */ NmcOutputField nmc_fields_dev_status[] = { - {"DEVICE", N_("DEVICE")}, /* 0 */ - {"TYPE", N_("TYPE")}, /* 1 */ - {"STATE", N_("STATE")}, /* 2 */ - {"DBUS-PATH", N_("DBUS-PATH")}, /* 3 */ - {"CONNECTION", N_("CONNECTION")}, /* 4 */ - {"CON-UUID", N_("CON-UUID")}, /* 5 */ - {"CON-PATH", N_("CON-PATH")}, /* 6 */ - {NULL, NULL} + OUTPUT_FIELD_WITH_NAME ("DEVICE"), /* 0 */ + OUTPUT_FIELD_WITH_NAME ("TYPE"), /* 1 */ + OUTPUT_FIELD_WITH_NAME ("STATE"), /* 2 */ + OUTPUT_FIELD_WITH_NAME ("DBUS-PATH"), /* 3 */ + OUTPUT_FIELD_WITH_NAME ("CONNECTION"), /* 4 */ + OUTPUT_FIELD_WITH_NAME ("CON-UUID"), /* 5 */ + OUTPUT_FIELD_WITH_NAME ("CON-PATH"), /* 6 */ + { 0 } }; #define NMC_FIELDS_DEV_STATUS_ALL "DEVICE,TYPE,STATE,DBUS-PATH,CONNECTION,CON-UUID,CON-PATH" #define NMC_FIELDS_DEV_STATUS_COMMON "DEVICE,TYPE,STATE,CONNECTION" @@ -53,32 +58,32 @@ NmcOutputField nmc_fields_dev_status[] = { /* Available fields for 'device show' - GENERAL part */ NmcOutputField nmc_fields_dev_show_general[] = { - {"NAME", N_("NAME")}, /* 0 */ - {"DEVICE", N_("DEVICE")}, /* 1 */ - {"TYPE", N_("TYPE")}, /* 2 */ - {"NM-TYPE", N_("NM-TYPE")}, /* 3 */ - {"VENDOR", N_("VENDOR")}, /* 4 */ - {"PRODUCT", N_("PRODUCT")}, /* 5 */ - {"DRIVER", N_("DRIVER")}, /* 6 */ - {"DRIVER-VERSION", N_("DRIVER-VERSION")}, /* 7 */ - {"FIRMWARE-VERSION", N_("FIRMWARE-VERSION")}, /* 8 */ - {"HWADDR", N_("HWADDR")}, /* 9 */ - {"MTU", N_("MTU")}, /* 10 */ - {"STATE", N_("STATE")}, /* 11 */ - {"REASON", N_("REASON")}, /* 12 */ - {"UDI", N_("UDI")}, /* 13 */ - {"IP-IFACE", N_("IP-IFACE")}, /* 14 */ - {"IS-SOFTWARE", N_("IS-SOFTWARE")}, /* 15 */ - {"NM-MANAGED", N_("NM-MANAGED")}, /* 16 */ - {"AUTOCONNECT", N_("AUTOCONNECT")}, /* 17 */ - {"FIRMWARE-MISSING", N_("FIRMWARE-MISSING")}, /* 18 */ - {"NM-PLUGIN-MISSING", N_("NM-PLUGIN-MISSING")}, /* 19 */ - {"PHYS-PORT-ID", N_("PHYS-PORT-ID")}, /* 20 */ - {"CONNECTION", N_("CONNECTION")}, /* 21 */ - {"CON-UUID", N_("CON-UUID")}, /* 22 */ - {"CON-PATH", N_("CON-PATH")}, /* 23 */ - {"METERED", N_("METERED")}, /* 24 */ - {NULL, NULL} + OUTPUT_FIELD_WITH_NAME ("NAME"), /* 0 */ + OUTPUT_FIELD_WITH_NAME ("DEVICE"), /* 1 */ + OUTPUT_FIELD_WITH_NAME ("TYPE"), /* 2 */ + OUTPUT_FIELD_WITH_NAME ("NM-TYPE"), /* 3 */ + OUTPUT_FIELD_WITH_NAME ("VENDOR"), /* 4 */ + OUTPUT_FIELD_WITH_NAME ("PRODUCT"), /* 5 */ + OUTPUT_FIELD_WITH_NAME ("DRIVER"), /* 6 */ + OUTPUT_FIELD_WITH_NAME ("DRIVER-VERSION"), /* 7 */ + OUTPUT_FIELD_WITH_NAME ("FIRMWARE-VERSION"), /* 8 */ + OUTPUT_FIELD_WITH_NAME ("HWADDR"), /* 9 */ + OUTPUT_FIELD_WITH_NAME ("MTU"), /* 10 */ + OUTPUT_FIELD_WITH_NAME ("STATE"), /* 11 */ + OUTPUT_FIELD_WITH_NAME ("REASON"), /* 12 */ + OUTPUT_FIELD_WITH_NAME ("UDI"), /* 13 */ + OUTPUT_FIELD_WITH_NAME ("IP-IFACE"), /* 14 */ + OUTPUT_FIELD_WITH_NAME ("IS-SOFTWARE"), /* 15 */ + OUTPUT_FIELD_WITH_NAME ("NM-MANAGED"), /* 16 */ + OUTPUT_FIELD_WITH_NAME ("AUTOCONNECT"), /* 17 */ + OUTPUT_FIELD_WITH_NAME ("FIRMWARE-MISSING"), /* 18 */ + OUTPUT_FIELD_WITH_NAME ("NM-PLUGIN-MISSING"), /* 19 */ + OUTPUT_FIELD_WITH_NAME ("PHYS-PORT-ID"), /* 20 */ + OUTPUT_FIELD_WITH_NAME ("CONNECTION"), /* 21 */ + OUTPUT_FIELD_WITH_NAME ("CON-UUID"), /* 22 */ + OUTPUT_FIELD_WITH_NAME ("CON-PATH"), /* 23 */ + OUTPUT_FIELD_WITH_NAME ("METERED"), /* 24 */ + { 0 } }; #define NMC_FIELDS_DEV_SHOW_GENERAL_ALL "NAME,DEVICE,TYPE,NM-TYPE,VENDOR,PRODUCT,DRIVER,DRIVER-VERSION,FIRMWARE-VERSION,HWADDR,MTU,"\ "STATE,REASON,UDI,IP-IFACE,IS-SOFTWARE,NM-MANAGED,AUTOCONNECT,FIRMWARE-MISSING,NM-PLUGIN-MISSING,"\ @@ -87,85 +92,85 @@ NmcOutputField nmc_fields_dev_show_general[] = { /* Available fields for 'device show' - CONNECTIONS part */ NmcOutputField nmc_fields_dev_show_connections[] = { - {"NAME", N_("NAME")}, /* 0 */ - {"AVAILABLE-CONNECTION-PATHS", N_("AVAILABLE-CONNECTION-PATHS")}, /* 1 */ - {"AVAILABLE-CONNECTIONS", N_("AVAILABLE-CONNECTIONS")}, /* 2 */ - {NULL, NULL} + OUTPUT_FIELD_WITH_NAME ("NAME"), /* 0 */ + OUTPUT_FIELD_WITH_NAME ("AVAILABLE-CONNECTION-PATHS"), /* 1 */ + OUTPUT_FIELD_WITH_NAME ("AVAILABLE-CONNECTIONS"), /* 2 */ + { 0 } }; #define NMC_FIELDS_DEV_SHOW_CONNECTIONS_ALL "NAME,AVAILABLE-CONNECTION-PATHS,AVAILABLE-CONNECTIONS" #define NMC_FIELDS_DEV_SHOW_CONNECTIONS_COMMON "NAME,AVAILABLE-CONNECTION-PATHS,AVAILABLE-CONNECTIONS" /* Available fields for 'device show' - CAPABILITIES part */ NmcOutputField nmc_fields_dev_show_cap[] = { - {"NAME", N_("NAME")}, /* 0 */ - {"CARRIER-DETECT", N_("CARRIER-DETECT")}, /* 1 */ - {"SPEED", N_("SPEED")}, /* 2 */ - {"IS-SOFTWARE", N_("IS-SOFTWARE")}, /* 3 */ - {NULL, NULL} + OUTPUT_FIELD_WITH_NAME ("NAME"), /* 0 */ + OUTPUT_FIELD_WITH_NAME ("CARRIER-DETECT"), /* 1 */ + OUTPUT_FIELD_WITH_NAME ("SPEED"), /* 2 */ + OUTPUT_FIELD_WITH_NAME ("IS-SOFTWARE"), /* 3 */ + { 0 } }; #define NMC_FIELDS_DEV_SHOW_CAP_ALL "NAME,CARRIER-DETECT,SPEED,IS-SOFTWARE" #define NMC_FIELDS_DEV_SHOW_CAP_COMMON "NAME,CARRIER-DETECT,SPEED,IS-SOFTWARE" /* Available fields for 'device show' - wired properties part */ NmcOutputField nmc_fields_dev_show_wired_prop[] = { - {"NAME", N_("NAME")}, /* 0 */ - {"CARRIER", N_("CARRIER")}, /* 1 */ - {"S390-SUBCHANNELS", N_("S390-SUBCHANNELS")}, /* 2 */ - {NULL, NULL} + OUTPUT_FIELD_WITH_NAME ("NAME"), /* 0 */ + OUTPUT_FIELD_WITH_NAME ("CARRIER"), /* 1 */ + OUTPUT_FIELD_WITH_NAME ("S390-SUBCHANNELS"), /* 2 */ + { 0 } }; #define NMC_FIELDS_DEV_SHOW_WIRED_PROP_ALL "NAME,CARRIER,S390-SUBCHANNELS" #define NMC_FIELDS_DEV_SHOW_WIRED_PROP_COMMON "NAME,CARRIER,S390-SUBCHANNELS" /* Available fields for 'device show' - wireless properties part */ NmcOutputField nmc_fields_dev_show_wifi_prop[] = { - {"NAME", N_("NAME")}, /* 0 */ - {"WEP", N_("WEP")}, /* 1 */ - {"WPA", N_("WPA")}, /* 2 */ - {"WPA2", N_("WPA2")}, /* 3 */ - {"TKIP", N_("TKIP")}, /* 4 */ - {"CCMP", N_("CCMP")}, /* 5 */ - {"AP", N_("AP")}, /* 6 */ - {"ADHOC", N_("ADHOC")}, /* 7 */ - {"2GHZ", N_("2GHZ")}, /* 8 */ - {"5GHZ", N_("5GHZ")}, /* 9 */ - {NULL, NULL} + OUTPUT_FIELD_WITH_NAME ("NAME"), /* 0 */ + OUTPUT_FIELD_WITH_NAME ("WEP"), /* 1 */ + OUTPUT_FIELD_WITH_NAME ("WPA"), /* 2 */ + OUTPUT_FIELD_WITH_NAME ("WPA2"), /* 3 */ + OUTPUT_FIELD_WITH_NAME ("TKIP"), /* 4 */ + OUTPUT_FIELD_WITH_NAME ("CCMP"), /* 5 */ + OUTPUT_FIELD_WITH_NAME ("AP"), /* 6 */ + OUTPUT_FIELD_WITH_NAME ("ADHOC"), /* 7 */ + OUTPUT_FIELD_WITH_NAME ("2GHZ"), /* 8 */ + OUTPUT_FIELD_WITH_NAME ("5GHZ"), /* 9 */ + { 0 } }; #define NMC_FIELDS_DEV_SHOW_WIFI_PROP_ALL "NAME,WEP,WPA,WPA2,TKIP,CCMP,AP,ADHOC,2GHZ,5GHZ" #define NMC_FIELDS_DEV_SHOW_WIFI_PROP_COMMON "NAME,WEP,WPA,WPA2,TKIP,CCMP,AP,ADHOC" /* Available fields for 'device show' - wimax properties part */ NmcOutputField nmc_fields_dev_show_wimax_prop[] = { - {"NAME", N_("NAME")}, /* 0 */ - {"CTR-FREQ", N_("CTR-FREQ")}, /* 1 */ - {"RSSI", N_("RSSI")}, /* 2 */ - {"CINR", N_("CINR")}, /* 3 */ - {"TX-POW", N_("TX-POW")}, /* 4 */ - {"BSID", N_("BSID")}, /* 5 */ - {NULL, NULL} + OUTPUT_FIELD_WITH_NAME ("NAME"), /* 0 */ + OUTPUT_FIELD_WITH_NAME ("CTR-FREQ"), /* 1 */ + OUTPUT_FIELD_WITH_NAME ("RSSI"), /* 2 */ + OUTPUT_FIELD_WITH_NAME ("CINR"), /* 3 */ + OUTPUT_FIELD_WITH_NAME ("TX-POW"), /* 4 */ + OUTPUT_FIELD_WITH_NAME ("BSID"), /* 5 */ + { 0 } }; #define NMC_FIELDS_DEV_SHOW_WIMAX_PROP_ALL "NAME,CTR-FREQ,RSSI,CINR,TX-POW,BSID" #define NMC_FIELDS_DEV_SHOW_WIMAX_PROP_COMMON "NAME,CTR-FREQ,RSSI,CINR,TX-POW,BSID" /* Available fields for 'device wifi list' */ NmcOutputField nmc_fields_dev_wifi_list[] = { - {"NAME", N_("NAME")}, /* 0 */ - {"SSID", N_("SSID")}, /* 1 */ - {"SSID-HEX", N_("SSID-HEX")}, /* 2 */ - {"BSSID", N_("BSSID")}, /* 3 */ - {"MODE", N_("MODE")}, /* 4 */ - {"CHAN", N_("CHAN")}, /* 5 */ - {"FREQ", N_("FREQ")}, /* 6 */ - {"RATE", N_("RATE")}, /* 7 */ - {"SIGNAL", N_("SIGNAL")}, /* 8 */ - {"BARS", N_("BARS")}, /* 9 */ - {"SECURITY", N_("SECURITY")}, /* 10 */ - {"WPA-FLAGS", N_("WPA-FLAGS")}, /* 11 */ - {"RSN-FLAGS", N_("RSN-FLAGS")}, /* 12 */ - {"DEVICE", N_("DEVICE")}, /* 13 */ - {"ACTIVE", N_("ACTIVE")}, /* 14 */ - {"IN-USE", N_("*")}, /* 15 */ - {"DBUS-PATH", N_("DBUS-PATH")}, /* 16 */ - {NULL, NULL} + OUTPUT_FIELD_WITH_NAME ("NAME"), /* 0 */ + OUTPUT_FIELD_WITH_NAME ("SSID"), /* 1 */ + OUTPUT_FIELD_WITH_NAME ("SSID-HEX"), /* 2 */ + OUTPUT_FIELD_WITH_NAME ("BSSID"), /* 3 */ + OUTPUT_FIELD_WITH_NAME ("MODE"), /* 4 */ + OUTPUT_FIELD_WITH_NAME ("CHAN"), /* 5 */ + OUTPUT_FIELD_WITH_NAME ("FREQ"), /* 6 */ + OUTPUT_FIELD_WITH_NAME ("RATE"), /* 7 */ + OUTPUT_FIELD_WITH_NAME ("SIGNAL"), /* 8 */ + OUTPUT_FIELD_WITH_NAME ("BARS"), /* 9 */ + OUTPUT_FIELD_WITH_NAME ("SECURITY"), /* 10 */ + OUTPUT_FIELD_WITH_NAME ("WPA-FLAGS"), /* 11 */ + OUTPUT_FIELD_WITH_NAME ("RSN-FLAGS"), /* 12 */ + OUTPUT_FIELD_WITH_NAME ("DEVICE"), /* 13 */ + OUTPUT_FIELD_WITH_NAME ("ACTIVE"), /* 14 */ + OUTPUT_FIELD_WITH_NAME ("*"), /* 15 */ + OUTPUT_FIELD_WITH_NAME ("DBUS-PATH"), /* 16 */ + { 0 } }; #define NMC_FIELDS_DEV_WIFI_LIST_ALL "SSID,SSID-HEX,BSSID,MODE,CHAN,FREQ,RATE,SIGNAL,BARS,SECURITY,"\ "WPA-FLAGS,RSN-FLAGS,DEVICE,ACTIVE,IN-USE,DBUS-PATH" @@ -174,14 +179,14 @@ NmcOutputField nmc_fields_dev_wifi_list[] = { /* Available fields for 'device wimax list' */ NmcOutputField nmc_fields_dev_wimax_list[] = { - {"NAME", N_("NAME")}, /* 0 */ - {"NSP", N_("NSP")}, /* 1 */ - {"SIGNAL", N_("SIGNAL")}, /* 2 */ - {"TYPE", N_("TYPE")}, /* 3 */ - {"DEVICE", N_("DEVICE")}, /* 4 */ - {"ACTIVE", N_("ACTIVE")}, /* 5 */ - {"DBUS-PATH", N_("DBUS-PATH")}, /* 6 */ - {NULL, NULL} + OUTPUT_FIELD_WITH_NAME ("NAME"), /* 0 */ + OUTPUT_FIELD_WITH_NAME ("NSP"), /* 1 */ + OUTPUT_FIELD_WITH_NAME ("SIGNAL"), /* 2 */ + OUTPUT_FIELD_WITH_NAME ("TYPE"), /* 3 */ + OUTPUT_FIELD_WITH_NAME ("DEVICE"), /* 4 */ + OUTPUT_FIELD_WITH_NAME ("ACTIVE"), /* 5 */ + OUTPUT_FIELD_WITH_NAME ("DBUS-PATH"), /* 6 */ + { 0 } }; #define NMC_FIELDS_DEV_WIMAX_LIST_ALL "NSP,SIGNAL,TYPE,DEVICE,ACTIVE,DBUS-PATH" #define NMC_FIELDS_DEV_WIMAX_LIST_COMMON "NSP,SIGNAL,TYPE,DEVICE,ACTIVE" @@ -189,38 +194,38 @@ NmcOutputField nmc_fields_dev_wimax_list[] = { /* Available fields for 'device show' - BOND, BRIDGE part */ NmcOutputField nmc_fields_dev_show_master_prop[] = { - {"NAME", N_("NAME")}, /* 0 */ - {"SLAVES", N_("SLAVES")}, /* 1 */ - {NULL, NULL} + OUTPUT_FIELD_WITH_NAME ("NAME"), /* 0 */ + OUTPUT_FIELD_WITH_NAME ("SLAVES"), /* 1 */ + { 0 } }; #define NMC_FIELDS_DEV_SHOW_MASTER_PROP_ALL "NAME,SLAVES" #define NMC_FIELDS_DEV_SHOW_MASTER_PROP_COMMON "NAME,SLAVES" /* Available fields for 'device show' - TEAM part */ NmcOutputField nmc_fields_dev_show_team_prop[] = { - {"NAME", N_("NAME")}, /* 0 */ - {"SLAVES", N_("SLAVES")}, /* 1 */ - {"CONFIG", N_("CONFIG")}, /* 2 */ - {NULL, NULL} + OUTPUT_FIELD_WITH_NAME ("NAME"), /* 0 */ + OUTPUT_FIELD_WITH_NAME ("SLAVES"), /* 1 */ + OUTPUT_FIELD_WITH_NAME ("CONFIG"), /* 2 */ + { 0 } }; #define NMC_FIELDS_DEV_SHOW_TEAM_PROP_ALL "NAME,SLAVES,CONFIG" #define NMC_FIELDS_DEV_SHOW_TEAM_PROP_COMMON "NAME,SLAVES,CONFIG" /* Available fields for 'device show' - VLAN part */ NmcOutputField nmc_fields_dev_show_vlan_prop[] = { - {"NAME", N_("NAME")}, /* 0 */ - {"PARENT", N_("PARENT")}, /* 1 */ - {"ID", N_("ID")}, /* 2 */ - {NULL, NULL} + OUTPUT_FIELD_WITH_NAME ("NAME"), /* 0 */ + OUTPUT_FIELD_WITH_NAME ("PARENT"), /* 1 */ + OUTPUT_FIELD_WITH_NAME ("ID"), /* 2 */ + { 0 } }; #define NMC_FIELDS_DEV_SHOW_VLAN_PROP_ALL "NAME,PARENT,ID" #define NMC_FIELDS_DEV_SHOW_VLAN_PROP_COMMON "NAME,PARENT,ID" /* Available fields for 'device show' - BLUETOOTH part */ NmcOutputField nmc_fields_dev_show_bluetooth[] = { - {"NAME", N_("NAME")}, /* 0 */ - {"CAPABILITIES", N_("CAPABILITIES")}, /* 1 */ - {NULL, NULL} + OUTPUT_FIELD_WITH_NAME ("NAME"), /* 0 */ + OUTPUT_FIELD_WITH_NAME ("CAPABILITIES"), /* 1 */ + { 0 } }; #define NMC_FIELDS_DEV_SHOW_BLUETOOTH_ALL "NAME,CAPABILITIES" #define NMC_FIELDS_DEV_SHOW_BLUETOOTH_COMMON "NAME,CAPABILITIES" @@ -233,24 +238,24 @@ extern NmcOutputField nmc_fields_dhcp6_config[]; /* Available sections for 'device show' */ NmcOutputField nmc_fields_dev_show_sections[] = { - {"GENERAL", N_("GENERAL"), 0, nmc_fields_dev_show_general + 1 }, /* 0 */ - {"CAPABILITIES", N_("CAPABILITIES"), 0, nmc_fields_dev_show_cap + 1 }, /* 1 */ - {"WIFI-PROPERTIES", N_("WIFI-PROPERTIES"), 0, nmc_fields_dev_show_wifi_prop + 1 }, /* 2 */ - {"AP", N_("AP"), 0, nmc_fields_dev_wifi_list + 1 }, /* 3 */ - {"WIRED-PROPERTIES", N_("WIRED-PROPERTIES"), 0, nmc_fields_dev_show_wired_prop + 1 }, /* 4 */ - {"WIMAX-PROPERTIES", N_("WIMAX-PROPERTIES"), 0, nmc_fields_dev_show_wimax_prop + 1 }, /* 5 */ - {"NSP", N_("NSP"), 0, nmc_fields_dev_wimax_list + 1 }, /* 6 */ - {"IP4", N_("IP4"), 0, nmc_fields_ip4_config + 1 }, /* 7 */ - {"DHCP4", N_("DHCP4"), 0, nmc_fields_dhcp4_config + 1 }, /* 8 */ - {"IP6", N_("IP6"), 0, nmc_fields_ip6_config + 1 }, /* 9 */ - {"DHCP6", N_("DHCP6"), 0, nmc_fields_dhcp6_config + 1 }, /* 10 */ - {"BOND", N_("BOND"), 0, nmc_fields_dev_show_master_prop + 1 }, /* 11 */ - {"TEAM", N_("TEAM"), 0, nmc_fields_dev_show_team_prop + 1 }, /* 12 */ - {"BRIDGE", N_("BRIDGE"), 0, nmc_fields_dev_show_master_prop + 1 }, /* 13 */ - {"VLAN", N_("VLAN"), 0, nmc_fields_dev_show_vlan_prop + 1 }, /* 14 */ - {"BLUETOOTH", N_("BLUETOOTH"), 0, nmc_fields_dev_show_bluetooth + 1 }, /* 15 */ - {"CONNECTIONS", N_("CONNECTIONS"), 0, nmc_fields_dev_show_connections + 1 }, /* 16 */ - {NULL, NULL, 0, NULL } + OUTPUT_FIELD_WITH_FIELDS ("GENERAL", nmc_fields_dev_show_general), /* 0 */ + OUTPUT_FIELD_WITH_FIELDS ("CAPABILITIES", nmc_fields_dev_show_cap), /* 1 */ + OUTPUT_FIELD_WITH_FIELDS ("WIFI-PROPERTIES", nmc_fields_dev_show_wifi_prop), /* 2 */ + OUTPUT_FIELD_WITH_FIELDS ("AP", nmc_fields_dev_wifi_list), /* 3 */ + OUTPUT_FIELD_WITH_FIELDS ("WIRED-PROPERTIES", nmc_fields_dev_show_wired_prop), /* 4 */ + OUTPUT_FIELD_WITH_FIELDS ("WIMAX-PROPERTIES", nmc_fields_dev_show_wimax_prop), /* 5 */ + OUTPUT_FIELD_WITH_FIELDS ("NSP", nmc_fields_dev_wimax_list), /* 6 */ + OUTPUT_FIELD_WITH_FIELDS ("IP4", nmc_fields_ip4_config), /* 7 */ + OUTPUT_FIELD_WITH_FIELDS ("DHCP4", nmc_fields_dhcp4_config), /* 8 */ + OUTPUT_FIELD_WITH_FIELDS ("IP6", nmc_fields_ip6_config), /* 9 */ + OUTPUT_FIELD_WITH_FIELDS ("DHCP6", nmc_fields_dhcp6_config), /* 10 */ + OUTPUT_FIELD_WITH_FIELDS ("BOND", nmc_fields_dev_show_master_prop), /* 11 */ + OUTPUT_FIELD_WITH_FIELDS ("TEAM", nmc_fields_dev_show_team_prop), /* 12 */ + OUTPUT_FIELD_WITH_FIELDS ("BRIDGE", nmc_fields_dev_show_master_prop), /* 13 */ + OUTPUT_FIELD_WITH_FIELDS ("VLAN", nmc_fields_dev_show_vlan_prop), /* 14 */ + OUTPUT_FIELD_WITH_FIELDS ("BLUETOOTH", nmc_fields_dev_show_bluetooth), /* 15 */ + OUTPUT_FIELD_WITH_FIELDS ("CONNECTIONS", nmc_fields_dev_show_connections), /* 16 */ + { 0 } }; #define NMC_FIELDS_DEV_SHOW_SECTIONS_ALL "GENERAL,CAPABILITIES,BOND,TEAM,BRIDGE,VLAN,WIFI-PROPERTIES,AP,WIRED-PROPERTIES,"\ "BLUETOOTH,CONNECTIONS,IP4,DHCP4,IP6,DHCP6" @@ -259,23 +264,23 @@ NmcOutputField nmc_fields_dev_show_sections[] = { /* Available fields for 'device lldp' */ NmcOutputField nmc_fields_dev_lldp_list[] = { - {"NAME", N_("NAME")}, /* 0 */ - {"DEVICE", N_("DEVICE")}, /* 1 */ - {"CHASSIS-ID", N_("CHASSIS-ID")}, /* 2 */ - {"PORT-ID", N_("PORT-ID")}, /* 3 */ - {"PORT-DESCRIPTION", N_("PORT-DESCRIPTION")}, /* 4 */ - {"SYSTEM-NAME", N_("SYSTEM-NAME")}, /* 5 */ - {"SYSTEM-DESCRIPTION", N_("SYSTEM-DESCRIPTION")}, /* 6 */ - {"SYSTEM-CAPABILITIES", N_("SYSTEM-CAPABILITIES")}, /* 7 */ - {"IEEE-802-1-PVID", N_("IEEE-802-1-PVID")}, /* 8 */ - {"IEEE-802-1-PPVID", N_("IEEE-802-1-PPVID")}, /* 9 */ - {"IEEE-802-1-PPVID-FLAGS", N_("IEEE-802-1-PPVID-FLAGS")}, /* 10 */ - {"IEEE-802-1-VID", N_("IEEE-802-1-VID")}, /* 11 */ - {"IEEE-802-1-VLAN-NAME", N_("IEEE-802-1-VLAN-NAME")}, /* 12 */ - {"DESTINATION", N_("DESTINATION")}, /* 13 */ - {"CHASSIS-ID-TYPE", N_("CHASSIS-ID-TYPE")}, /* 14 */ - {"PORT-ID-TYPE", N_("PORT-ID-TYPE")}, /* 15 */ - {NULL, NULL} + OUTPUT_FIELD_WITH_NAME ("NAME"), /* 0 */ + OUTPUT_FIELD_WITH_NAME ("DEVICE"), /* 1 */ + OUTPUT_FIELD_WITH_NAME ("CHASSIS-ID"), /* 2 */ + OUTPUT_FIELD_WITH_NAME ("PORT-ID"), /* 3 */ + OUTPUT_FIELD_WITH_NAME ("PORT-DESCRIPTION"), /* 4 */ + OUTPUT_FIELD_WITH_NAME ("SYSTEM-NAME"), /* 5 */ + OUTPUT_FIELD_WITH_NAME ("SYSTEM-DESCRIPTION"), /* 6 */ + OUTPUT_FIELD_WITH_NAME ("SYSTEM-CAPABILITIES"), /* 7 */ + OUTPUT_FIELD_WITH_NAME ("IEEE-802-1-PVID"), /* 8 */ + OUTPUT_FIELD_WITH_NAME ("IEEE-802-1-PPVID"), /* 9 */ + OUTPUT_FIELD_WITH_NAME ("IEEE-802-1-PPVID-FLAGS"), /* 10 */ + OUTPUT_FIELD_WITH_NAME ("IEEE-802-1-VID"), /* 11 */ + OUTPUT_FIELD_WITH_NAME ("IEEE-802-1-VLAN-NAME"), /* 12 */ + OUTPUT_FIELD_WITH_NAME ("DESTINATION"), /* 13 */ + OUTPUT_FIELD_WITH_NAME ("CHASSIS-ID-TYPE"), /* 14 */ + OUTPUT_FIELD_WITH_NAME ("PORT-ID-TYPE"), /* 15 */ + { 0 } }; #define NMC_FIELDS_DEV_LLDP_LIST_ALL "DEVICE,CHASSIS-ID,PORT-ID,PORT-DESCRIPTION,SYSTEM-NAME,SYSTEM-DESCRIPTION," \ "SYSTEM-CAPABILITIES,IEEE-802-1-PVID,IEEE-802-1-PPVID,IEEE-802-1-PPVID-FLAGS," \ @@ -761,6 +766,7 @@ typedef struct { guint32 output_flags; const char* active_bssid; const char* device; + GPtrArray *output_data; } APInfo; static void @@ -876,7 +882,7 @@ fill_output_access_point (gpointer data, gpointer user_data) if (active) arr[15].color = NMC_TERM_COLOR_GREEN; - g_ptr_array_add (info->nmc->output_data, arr); + g_ptr_array_add (info->output_data, arr); g_string_free (security_str, FALSE); } @@ -946,6 +952,7 @@ print_bond_bridge_info (NMDevice *device, int idx; NmcOutputField *tmpl, *arr; size_t tmpl_len; + NMC_OUTPUT_DATA_DEFINE_SCOPED (out); if (NM_IS_DEVICE_BOND (device)) slaves = nm_device_bond_get_slaves (NM_DEVICE_BOND (device)); @@ -969,20 +976,20 @@ print_bond_bridge_info (NMDevice *device, tmpl = nmc_fields_dev_show_master_prop; tmpl_len = sizeof (nmc_fields_dev_show_master_prop); - nmc->print_fields.indices = parse_output_fields (one_field ? one_field : NMC_FIELDS_DEV_SHOW_MASTER_PROP_ALL, - tmpl, FALSE, NULL, NULL); + out.print_fields.indices = parse_output_fields (one_field ? one_field : NMC_FIELDS_DEV_SHOW_MASTER_PROP_ALL, + tmpl, FALSE, NULL, NULL); arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); - g_ptr_array_add (nmc->output_data, arr); + g_ptr_array_add (out.output_data, arr); arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX); set_val_strc (arr, 0, group_prefix); /* i.e. BOND, TEAM, BRIDGE */ set_val_str (arr, 1, slaves_str->str); - g_ptr_array_add (nmc->output_data, arr); + g_ptr_array_add (out.output_data, arr); - print_data (nmc); /* Print all data */ + print_data_prepare_width (out.output_data); + print_data (&nmc->nmc_config, &out); g_string_free (slaves_str, FALSE); - nmc_empty_output_fields (nmc); return TRUE; } @@ -1017,6 +1024,7 @@ print_team_info (NMDevice *device, int idx; NmcOutputField *tmpl, *arr; size_t tmpl_len; + NMC_OUTPUT_DATA_DEFINE_SCOPED (out); if (NM_IS_DEVICE_TEAM (device)) slaves = nm_device_team_get_slaves (NM_DEVICE_TEAM (device)); @@ -1038,21 +1046,22 @@ print_team_info (NMDevice *device, tmpl = nmc_fields_dev_show_team_prop; tmpl_len = sizeof (nmc_fields_dev_show_team_prop); - nmc->print_fields.indices = parse_output_fields (one_field ? one_field : NMC_FIELDS_DEV_SHOW_TEAM_PROP_ALL, + out.print_fields.indices = parse_output_fields (one_field ? one_field : NMC_FIELDS_DEV_SHOW_TEAM_PROP_ALL, tmpl, FALSE, NULL, NULL); arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); - g_ptr_array_add (nmc->output_data, arr); + g_ptr_array_add (out.output_data, arr); arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX); set_val_strc (arr, 0, group_prefix); /* TEAM */ set_val_str (arr, 1, slaves_str->str); set_val_str (arr, 2, sanitize_team_config (nm_device_team_get_config (NM_DEVICE_TEAM (device)))); - g_ptr_array_add (nmc->output_data, arr); + g_ptr_array_add (out.output_data, arr); - print_data (nmc); /* Print all data */ + print_data_prepare_width (out.output_data); + print_data (&nmc->nmc_config, &out); g_string_free (slaves_str, FALSE); - nmc_empty_output_fields (nmc); + nmc_empty_output_fields (&out); return TRUE; } @@ -1061,7 +1070,6 @@ static gboolean show_device_info (NMDevice *device, NmCli *nmc) { GError *error = NULL; - APInfo *info; const char *hwaddr = NULL; NMDeviceState state = NM_DEVICE_STATE_UNKNOWN; NMDeviceStateReason reason = NM_DEVICE_STATE_REASON_NONE; @@ -1097,40 +1105,43 @@ show_device_info (NMDevice *device, NmCli *nmc) return FALSE; } - /* Main header (pretty only) */ - nmc->print_fields.header_name = (char *) construct_header_name (base_hdr, nm_device_get_iface (device)); + { + NMC_OUTPUT_DATA_DEFINE_SCOPED (out); - /* Lazy way to retrieve sorted array from 0 to the number of dev fields */ - nmc->print_fields.indices = parse_output_fields (NMC_FIELDS_DEV_SHOW_GENERAL_ALL, - nmc_fields_dev_show_general, FALSE, NULL, NULL); + /* Main header (pretty only) */ + out.print_fields.header_name = (char *) construct_header_name (base_hdr, nm_device_get_iface (device)); - nmc_fields_dev_show_general[0].flags = NMC_OF_FLAG_MAIN_HEADER_ONLY; - print_required_fields (nmc, nmc_fields_dev_show_general); + /* Lazy way to retrieve sorted array from 0 to the number of dev fields */ + out.print_fields.indices = parse_output_fields (NMC_FIELDS_DEV_SHOW_GENERAL_ALL, + nmc_fields_dev_show_general, FALSE, NULL, NULL); + + nmc_fields_dev_show_general[0].flags = NMC_OF_FLAG_MAIN_HEADER_ONLY; + print_required_fields (&nmc->nmc_config, &out.print_fields, nmc_fields_dev_show_general); + } /* Loop through the required sections and print them. */ for (k = 0; k < sections_array->len; k++) { int section_idx = g_array_index (sections_array, int, k); char *section_fld = (char *) g_ptr_array_index (fields_in_section, k); - if (nmc->print_output != NMC_PRINT_TERSE && !nmc->multiline_output && was_output) + if (nmc->nmc_config.print_output != NMC_PRINT_TERSE && !nmc->nmc_config.multiline_output && was_output) g_print ("\n"); /* Print empty line between groups in tabular mode */ was_output = FALSE; - /* Remove any previous data */ - nmc_empty_output_fields (nmc); - state = nm_device_get_state (device); reason = nm_device_get_state_reason (device); /* section GENERAL */ if (!strcasecmp (nmc_fields_dev_show_sections[section_idx].name, nmc_fields_dev_show_sections[0].name)) { + NMC_OUTPUT_DATA_DEFINE_SCOPED (out); + tmpl = nmc_fields_dev_show_general; tmpl_len = sizeof (nmc_fields_dev_show_general); - nmc->print_fields.indices = parse_output_fields (section_fld ? section_fld : NMC_FIELDS_DEV_SHOW_GENERAL_ALL, - tmpl, FALSE, NULL, NULL); + out.print_fields.indices = parse_output_fields (section_fld ? section_fld : NMC_FIELDS_DEV_SHOW_GENERAL_ALL, + tmpl, FALSE, NULL, NULL); arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); - g_ptr_array_add (nmc->output_data, arr); + g_ptr_array_add (out.output_data, arr); state_str = g_strdup_printf ("%d (%s)", state, nmc_device_state_to_string (state)); reason_str = g_strdup_printf ("%d (%s)", reason, nmc_device_reason_to_string (reason)); @@ -1164,20 +1175,23 @@ show_device_info (NMDevice *device, NmCli *nmc) set_val_strc (arr, 22, acon ? nm_active_connection_get_uuid (acon) : NULL); set_val_strc (arr, 23, acon ? nm_object_get_path (NM_OBJECT (acon)) : NULL); set_val_strc (arr, 24, nmc_device_metered_to_string (nm_device_get_metered (device))); - g_ptr_array_add (nmc->output_data, arr); + g_ptr_array_add (out.output_data, arr); - print_data (nmc); /* Print all data */ + print_data_prepare_width (out.output_data); + print_data (&nmc->nmc_config, &out); was_output = TRUE; } /* section CAPABILITIES */ if (!strcasecmp (nmc_fields_dev_show_sections[section_idx].name, nmc_fields_dev_show_sections[1].name)) { + NMC_OUTPUT_DATA_DEFINE_SCOPED (out); + tmpl = nmc_fields_dev_show_cap; tmpl_len = sizeof (nmc_fields_dev_show_cap); - nmc->print_fields.indices = parse_output_fields (section_fld ? section_fld : NMC_FIELDS_DEV_SHOW_CAP_ALL, - tmpl, FALSE, NULL, NULL); + out.print_fields.indices = parse_output_fields (section_fld ? section_fld : NMC_FIELDS_DEV_SHOW_CAP_ALL, + tmpl, FALSE, NULL, NULL); arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); - g_ptr_array_add (nmc->output_data, arr); + g_ptr_array_add (out.output_data, arr); caps = nm_device_get_capabilities (device); speed = 0; @@ -1196,9 +1210,10 @@ show_device_info (NMDevice *device, NmCli *nmc) set_val_strc (arr, 1, (caps & NM_DEVICE_CAP_CARRIER_DETECT) ? _("yes") : _("no")); set_val_str (arr, 2, speed_str); set_val_strc (arr, 3, (caps & NM_DEVICE_CAP_IS_SOFTWARE) ? _("yes") : _("no")); - g_ptr_array_add (nmc->output_data, arr); + g_ptr_array_add (out.output_data, arr); - print_data (nmc); /* Print all data */ + print_data_prepare_width (out.output_data); + print_data (&nmc->nmc_config, &out); was_output = TRUE; } @@ -1211,14 +1226,16 @@ show_device_info (NMDevice *device, NmCli *nmc) /* section WIFI-PROPERTIES */ if (!strcasecmp (nmc_fields_dev_show_sections[section_idx].name, nmc_fields_dev_show_sections[2].name)) { + NMC_OUTPUT_DATA_DEFINE_SCOPED (out); + wcaps = nm_device_wifi_get_capabilities (NM_DEVICE_WIFI (device)); tmpl = nmc_fields_dev_show_wifi_prop; tmpl_len = sizeof (nmc_fields_dev_show_wifi_prop); - nmc->print_fields.indices = parse_output_fields (section_fld ? section_fld : NMC_FIELDS_DEV_SHOW_WIFI_PROP_ALL, - tmpl, FALSE, NULL, NULL); + out.print_fields.indices = parse_output_fields (section_fld ? section_fld : NMC_FIELDS_DEV_SHOW_WIFI_PROP_ALL, + tmpl, FALSE, NULL, NULL); arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); - g_ptr_array_add (nmc->output_data, arr); + g_ptr_array_add (out.output_data, arr); arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX); set_val_strc (arr, 0, nmc_fields_dev_show_sections[2].name); /* "WIFI-PROPERTIES" */ @@ -1234,14 +1251,17 @@ show_device_info (NMDevice *device, NmCli *nmc) ((wcaps & NM_WIFI_DEVICE_CAP_FREQ_2GHZ) ? _("yes") : _("no"))); set_val_strc (arr, 9, !(wcaps & NM_WIFI_DEVICE_CAP_FREQ_VALID) ? _("unknown") : ((wcaps & NM_WIFI_DEVICE_CAP_FREQ_5GHZ) ? _("yes") : _("no"))); - g_ptr_array_add (nmc->output_data, arr); + g_ptr_array_add (out.output_data, arr); - print_data (nmc); /* Print all data */ + print_data_prepare_width (out.output_data); + print_data (&nmc->nmc_config, &out); was_output = TRUE; } /* section AP */ if (!strcasecmp (nmc_fields_dev_show_sections[section_idx].name, nmc_fields_dev_show_sections[3].name)) { + NMC_OUTPUT_DATA_DEFINE_SCOPED (out); + if (state == NM_DEVICE_STATE_ACTIVATED) { active_ap = nm_device_wifi_get_active_access_point (NM_DEVICE_WIFI (device)); active_bssid = active_ap ? nm_access_point_get_bssid (active_ap) : NULL; @@ -1249,42 +1269,51 @@ show_device_info (NMDevice *device, NmCli *nmc) tmpl = nmc_fields_dev_wifi_list; tmpl_len = sizeof (nmc_fields_dev_wifi_list); - nmc->print_fields.indices = parse_output_fields (section_fld ? section_fld : NMC_FIELDS_DEV_WIFI_LIST_FOR_DEV_LIST, - tmpl, FALSE, NULL, NULL); + out.print_fields.indices = parse_output_fields (section_fld ? section_fld : NMC_FIELDS_DEV_WIFI_LIST_FOR_DEV_LIST, + tmpl, FALSE, NULL, NULL); arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); - g_ptr_array_add (nmc->output_data, arr); + g_ptr_array_add (out.output_data, arr); + + { + APInfo info = { + .nmc = nmc, + .index = 1, + .output_flags = NMC_OF_FLAG_SECTION_PREFIX, + .active_bssid = active_bssid, + .device = nm_device_get_iface (device), + .output_data = out.output_data, + }; + + aps = sort_access_points (nm_device_wifi_get_access_points (NM_DEVICE_WIFI (device))); + g_ptr_array_foreach (aps, fill_output_access_point, &info); + g_ptr_array_free (aps, FALSE); + } - info = g_malloc0 (sizeof (APInfo)); - info->nmc = nmc; - info->index = 1; - info->output_flags = NMC_OF_FLAG_SECTION_PREFIX; - info->active_bssid = active_bssid; - info->device = nm_device_get_iface (device); - aps = sort_access_points (nm_device_wifi_get_access_points (NM_DEVICE_WIFI (device))); - g_ptr_array_foreach ((GPtrArray *) aps, fill_output_access_point, (gpointer) info); - g_ptr_array_free (aps, FALSE); - g_free (info); - print_data (nmc); /* Print all data */ + print_data_prepare_width (out.output_data); + print_data (&nmc->nmc_config, &out); was_output = TRUE; } } else if (NM_IS_DEVICE_ETHERNET (device)) { /* WIRED-PROPERTIES */ if (!strcasecmp (nmc_fields_dev_show_sections[section_idx].name, nmc_fields_dev_show_sections[4].name)) { + NMC_OUTPUT_DATA_DEFINE_SCOPED (out); + tmpl = nmc_fields_dev_show_wired_prop; tmpl_len = sizeof (nmc_fields_dev_show_wired_prop); - nmc->print_fields.indices = parse_output_fields (section_fld ? section_fld : NMC_FIELDS_DEV_SHOW_WIRED_PROP_ALL, - tmpl, FALSE, NULL, NULL); + out.print_fields.indices = parse_output_fields (section_fld ? section_fld : NMC_FIELDS_DEV_SHOW_WIRED_PROP_ALL, + tmpl, FALSE, NULL, NULL); arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); - g_ptr_array_add (nmc->output_data, arr); + g_ptr_array_add (out.output_data, arr); arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX); set_val_strc (arr, 0, nmc_fields_dev_show_sections[4].name); /* "WIRED-PROPERTIES" */ set_val_strc (arr, 1, (nm_device_ethernet_get_carrier (NM_DEVICE_ETHERNET (device))) ? _("on") : _("off")); set_val_arrc (arr, 2, ((const char **) nm_device_ethernet_get_s390_subchannels (NM_DEVICE_ETHERNET (device)))); - g_ptr_array_add (nmc->output_data, arr); + g_ptr_array_add (out.output_data, arr); - print_data (nmc); /* Print all data */ + print_data_prepare_width (out.output_data); + print_data (&nmc->nmc_config, &out); was_output = TRUE; } } @@ -1297,19 +1326,19 @@ show_device_info (NMDevice *device, NmCli *nmc) /* IP4 */ if (cfg4 && !strcasecmp (nmc_fields_dev_show_sections[section_idx].name, nmc_fields_dev_show_sections[7].name)) - was_output = print_ip4_config (cfg4, nmc, nmc_fields_dev_show_sections[7].name, section_fld); + was_output = print_ip4_config (cfg4, &nmc->nmc_config, nmc_fields_dev_show_sections[7].name, section_fld); /* 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_fields_dev_show_sections[8].name, section_fld); + was_output = print_dhcp4_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)) - was_output = print_ip6_config (cfg6, nmc, nmc_fields_dev_show_sections[9].name, section_fld); + was_output = print_ip6_config (cfg6, &nmc->nmc_config, nmc_fields_dev_show_sections[9].name, section_fld); /* 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_fields_dev_show_sections[10].name, section_fld); + was_output = print_dhcp6_config (dhcp6, &nmc->nmc_config, nmc_fields_dev_show_sections[10].name, section_fld); /* Bond specific information */ if (NM_IS_DEVICE_BOND (device)) { @@ -1334,21 +1363,23 @@ show_device_info (NMDevice *device, NmCli *nmc) if (!strcasecmp (nmc_fields_dev_show_sections[section_idx].name, nmc_fields_dev_show_sections[14].name)) { char * vlan_id_str = g_strdup_printf ("%u", nm_device_vlan_get_vlan_id (NM_DEVICE_VLAN (device))); NMDevice *parent = nm_device_vlan_get_parent (NM_DEVICE_VLAN (device)); + NMC_OUTPUT_DATA_DEFINE_SCOPED (out); tmpl = nmc_fields_dev_show_vlan_prop; tmpl_len = sizeof (nmc_fields_dev_show_vlan_prop); - nmc->print_fields.indices = parse_output_fields (section_fld ? section_fld : NMC_FIELDS_DEV_SHOW_VLAN_PROP_ALL, - tmpl, FALSE, NULL, NULL); + out.print_fields.indices = parse_output_fields (section_fld ? section_fld : NMC_FIELDS_DEV_SHOW_VLAN_PROP_ALL, + tmpl, FALSE, NULL, NULL); arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); - g_ptr_array_add (nmc->output_data, arr); + g_ptr_array_add (out.output_data, arr); arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX); set_val_strc (arr, 0, nmc_fields_dev_show_sections[14].name); /* "VLAN" */ set_val_strc (arr, 1, parent ? nm_device_get_iface (parent) : NULL); set_val_str (arr, 2, vlan_id_str); - g_ptr_array_add (nmc->output_data, arr); + g_ptr_array_add (out.output_data, arr); - print_data (nmc); /* Print all data */ + print_data_prepare_width (out.output_data); + print_data (&nmc->nmc_config, &out); was_output = TRUE; } @@ -1356,19 +1387,22 @@ show_device_info (NMDevice *device, NmCli *nmc) if (NM_IS_DEVICE_BT (device)) { if (!strcasecmp (nmc_fields_dev_show_sections[section_idx].name, nmc_fields_dev_show_sections[15].name)) { + NMC_OUTPUT_DATA_DEFINE_SCOPED (out); + tmpl = nmc_fields_dev_show_bluetooth; tmpl_len = sizeof (nmc_fields_dev_show_bluetooth); - nmc->print_fields.indices = parse_output_fields (section_fld ? section_fld : NMC_FIELDS_DEV_SHOW_BLUETOOTH_ALL, - tmpl, FALSE, NULL, NULL); + out.print_fields.indices = parse_output_fields (section_fld ? section_fld : NMC_FIELDS_DEV_SHOW_BLUETOOTH_ALL, + tmpl, FALSE, NULL, NULL); arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); - g_ptr_array_add (nmc->output_data, arr); + g_ptr_array_add (out.output_data, arr); arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX); set_val_strc (arr, 0, nmc_fields_dev_show_sections[15].name); /* "BLUETOOTH" */ set_val_str (arr, 1, bluetooth_caps_to_string (nm_device_bt_get_capabilities (NM_DEVICE_BT (device)))); - g_ptr_array_add (nmc->output_data, arr); + g_ptr_array_add (out.output_data, arr); - print_data (nmc); /* Print all data */ + print_data_prepare_width (out.output_data); + print_data (&nmc->nmc_config, &out); was_output = TRUE; } } @@ -1379,13 +1413,14 @@ show_device_info (NMDevice *device, NmCli *nmc) GString *ac_paths_str; char **ac_arr = NULL; int i; + NMC_OUTPUT_DATA_DEFINE_SCOPED (out); tmpl = nmc_fields_dev_show_connections; tmpl_len = sizeof (nmc_fields_dev_show_connections); - nmc->print_fields.indices = parse_output_fields (section_fld ? section_fld : NMC_FIELDS_DEV_SHOW_CONNECTIONS_ALL, - tmpl, FALSE, NULL, NULL); + out.print_fields.indices = parse_output_fields (section_fld ? section_fld : NMC_FIELDS_DEV_SHOW_CONNECTIONS_ALL, + tmpl, FALSE, NULL, NULL); arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); - g_ptr_array_add (nmc->output_data, arr); + g_ptr_array_add (out.output_data, arr); /* available-connections */ avail_cons = nm_device_get_available_connections (device); @@ -1415,9 +1450,10 @@ show_device_info (NMDevice *device, NmCli *nmc) set_val_strc (arr, 0, nmc_fields_dev_show_sections[16].name); /* "CONNECTIONS" */ set_val_str (arr, 1, ac_paths_str->str); set_val_arr (arr, 2, (ac_arr)); - g_ptr_array_add (nmc->output_data, arr); + g_ptr_array_add (out.output_data, arr); - print_data (nmc); /* Print all data */ + print_data_prepare_width (out.output_data); + print_data (&nmc->nmc_config, &out); g_string_free (ac_paths_str, FALSE); was_output = TRUE; @@ -1449,7 +1485,7 @@ nmc_device_state_to_color (NMDeviceState state, NmcTermColor *color, NmcTermForm } static void -fill_output_device_status (NMDevice *device, NmCli *nmc) +fill_output_device_status (NMDevice *device, GPtrArray *output_data) { NMActiveConnection *ac; NMDeviceState state; @@ -1475,7 +1511,7 @@ fill_output_device_status (NMDevice *device, NmCli *nmc) set_val_strc (arr, 5, ac ? nm_active_connection_get_uuid (ac) : NULL); set_val_strc (arr, 6, ac ? nm_object_get_path (NM_OBJECT (ac)) : NULL); - g_ptr_array_add (nmc->output_data, arr); + g_ptr_array_add (output_data, arr); } static NMCResultCode @@ -1489,6 +1525,7 @@ do_devices_status (NmCli *nmc, int argc, char **argv) char *fields_common = NMC_FIELDS_DEV_STATUS_COMMON; NmcOutputField *tmpl, *arr; size_t tmpl_len; + NMC_OUTPUT_DATA_DEFINE_SCOPED (out); /* Nothing to complete */ if (nmc->complete) @@ -1508,7 +1545,7 @@ do_devices_status (NmCli *nmc, int argc, char **argv) tmpl = nmc_fields_dev_status; tmpl_len = sizeof (nmc_fields_dev_status); - nmc->print_fields.indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, &error); + out.print_fields.indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, &error); if (error) { g_string_printf (nmc->return_text, _("Error: 'device status': %s"), error->message); @@ -1517,16 +1554,16 @@ do_devices_status (NmCli *nmc, int argc, char **argv) } /* Add headers */ - nmc->print_fields.header_name = _("Status of devices"); + out.print_fields.header_name = _("Status of devices"); arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_MAIN_HEADER_ADD | NMC_OF_FLAG_FIELD_NAMES); - g_ptr_array_add (nmc->output_data, arr); + g_ptr_array_add (out.output_data, arr); devices = nmc_get_devices_sorted (nmc->client); for (i = 0; devices[i]; i++) - fill_output_device_status (devices[i], nmc); + fill_output_device_status (devices[i], out.output_data); - /* Now print all data */ - print_data (nmc); + print_data_prepare_width (out.output_data); + print_data (&nmc->nmc_config, &out); g_free (devices); @@ -1539,7 +1576,7 @@ do_device_show (NmCli *nmc, int argc, char **argv) gs_free_error GError *error = NULL; if (!nmc->mode_specified) - nmc->multiline_output = TRUE; /* multiline mode is default for 'device show' */ + nmc->nmc_config_mutable.multiline_output = TRUE; /* multiline mode is default for 'device show' */ if (argc) { NMDevice *device; @@ -1568,7 +1605,6 @@ do_device_show (NmCli *nmc, int argc, char **argv) /* Show details for all devices */ for (i = 0; devices[i]; i++) { - nmc_empty_output_fields (nmc); if (!show_device_info (devices[i], nmc)) break; if (devices[i + 1]) @@ -1703,7 +1739,7 @@ add_and_activate_cb (GObject *client, if (nmc->nowait_flag || state == NM_ACTIVE_CONNECTION_STATE_ACTIVATED) { /* User doesn't want to wait or already activated */ if (state == NM_ACTIVE_CONNECTION_STATE_ACTIVATED) { - if (nmc->print_output == NMC_PRINT_PRETTY) + if (nmc->nmc_config.print_output == NMC_PRINT_PRETTY) nmc_terminal_erase_line (); if (info->hotspot) g_print (_("Connection with UUID '%s' created and activated on device '%s'\n"), @@ -1721,7 +1757,7 @@ add_and_activate_cb (GObject *client, g_timeout_add_seconds (nmc->timeout, timeout_cb, nmc); /* Exit if timeout expires */ - if (nmc->print_output == NMC_PRINT_PRETTY) + if (nmc->nmc_config.print_output == NMC_PRINT_PRETTY) progress_id = g_timeout_add (120, progress_cb, device); } } @@ -1795,7 +1831,7 @@ connect_device_cb (GObject *client, GAsyncResult *result, gpointer user_data) if (nmc->nowait_flag || state == NM_DEVICE_STATE_ACTIVATED) { /* Don't want to wait or device already activated */ - if (state == NM_DEVICE_STATE_ACTIVATED && nmc->print_output == NMC_PRINT_PRETTY) { + if (state == NM_DEVICE_STATE_ACTIVATED && nmc->nmc_config.print_output == NMC_PRINT_PRETTY) { nmc_terminal_erase_line (); g_print (_("Device '%s' has been connected.\n"), nm_device_get_iface (device)); } @@ -1874,7 +1910,7 @@ do_device_connect (NmCli *nmc, int argc, char **argv) info); /* Start progress indication */ - if (nmc->print_output == NMC_PRINT_PRETTY) + if (nmc->nmc_config.print_output == NMC_PRINT_PRETTY) progress_id = g_timeout_add (120, progress_cb, device); return nmc->return_value; @@ -1979,7 +2015,7 @@ reapply_device_cb (GObject *object, GAsyncResult *result, gpointer user_data) nmc->return_value = NMC_RESULT_ERROR_DEV_DISCONNECT; device_cb_info_finish (info, device); } else { - if (nmc->print_output == NMC_PRINT_PRETTY) + if (nmc->nmc_config.print_output == NMC_PRINT_PRETTY) nmc_terminal_erase_line (); g_print (_("Connection successfully reapplied to device '%s'.\n"), nm_device_get_iface (device)); @@ -2047,7 +2083,7 @@ modify_reapply_cb (GObject *object, GAsyncResult *result, gpointer user_data) g_error_free (error); nmc->return_value = NMC_RESULT_ERROR_DEV_DISCONNECT; } else { - if (nmc->print_output == NMC_PRINT_PRETTY) + if (nmc->nmc_config.print_output == NMC_PRINT_PRETTY) nmc_terminal_erase_line (); g_print (_("Connection successfully reapplied to device '%s'.\n"), nm_device_get_iface (device)); @@ -2150,7 +2186,7 @@ disconnect_device_cb (GObject *object, GAsyncResult *result, gpointer user_data) if (nmc->nowait_flag || state <= NM_DEVICE_STATE_DISCONNECTED) { /* Don't want to wait or device already disconnected */ if (state <= NM_DEVICE_STATE_DISCONNECTED) { - if (nmc->print_output == NMC_PRINT_PRETTY) + if (nmc->nmc_config.print_output == NMC_PRINT_PRETTY) nmc_terminal_erase_line (); g_print (_("Device '%s' successfully disconnected.\n"), nm_device_get_iface (device)); @@ -2378,7 +2414,7 @@ device_state (NMDevice *device, GParamSpec *pspec, NmCli *nmc) char *str; nmc_device_state_to_color (state, &color, &color_fmt); - str = nmc_colorize (nmc, color, color_fmt, "%s: %s\n", + str = nmc_colorize (nmc->nmc_config.use_colors, color, color_fmt, "%s: %s\n", nm_device_get_iface (device), nmc_device_state_to_string (state)); @@ -2464,12 +2500,11 @@ do_devices_monitor (NmCli *nmc, int argc, char **argv) } static void -show_access_point_info (NMDevice *device, NmCli *nmc) +show_access_point_info (NMDevice *device, NmCli *nmc, NmcOutputData *out) { NMAccessPoint *active_ap = NULL; const char *active_bssid = NULL; GPtrArray *aps; - APInfo *info; NmcOutputField *arr; if (nm_device_get_state (device) == NM_DEVICE_STATE_ACTIVATED) { @@ -2479,21 +2514,25 @@ show_access_point_info (NMDevice *device, NmCli *nmc) arr = nmc_dup_fields_array (nmc_fields_dev_wifi_list, sizeof (nmc_fields_dev_wifi_list), NMC_OF_FLAG_MAIN_HEADER_ADD | NMC_OF_FLAG_FIELD_NAMES); - g_ptr_array_add (nmc->output_data, arr); + g_ptr_array_add (out->output_data, arr); - info = g_malloc0 (sizeof (APInfo)); - info->nmc = nmc; - info->index = 1; - info->output_flags = 0; - info->active_bssid = active_bssid; - info->device = nm_device_get_iface (device); - aps = sort_access_points (nm_device_wifi_get_access_points (NM_DEVICE_WIFI (device))); - g_ptr_array_foreach ((GPtrArray *) aps, fill_output_access_point, (gpointer) info); - g_ptr_array_free (aps, FALSE); - - print_data (nmc); /* Print all data */ - nmc_empty_output_fields (nmc); - g_free (info); + { + APInfo info = { + .nmc = nmc, + .index = 1, + .output_flags = 0, + .active_bssid = active_bssid, + .device = nm_device_get_iface (device), + .output_data = out->output_data, + }; + + aps = sort_access_points (nm_device_wifi_get_access_points (NM_DEVICE_WIFI (device))); + g_ptr_array_foreach (aps, fill_output_access_point, &info); + g_ptr_array_free (aps, FALSE); + } + + print_data_prepare_width (out->output_data); + print_data (&nmc->nmc_config, out); } /* @@ -2626,6 +2665,7 @@ do_device_wifi_list (NmCli *nmc, int argc, char **argv) NmcOutputField *tmpl, *arr; size_t tmpl_len; const char *base_hdr = _("Wi-Fi scan list"); + NMC_OUTPUT_DATA_DEFINE_SCOPED (out); devices = nmc_get_devices_sorted (nmc->client); @@ -2669,7 +2709,7 @@ do_device_wifi_list (NmCli *nmc, int argc, char **argv) tmpl = nmc_fields_dev_wifi_list; tmpl_len = sizeof (nmc_fields_dev_wifi_list); - nmc->print_fields.indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, &error); + out.print_fields.indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, &error); if (error) { g_string_printf (nmc->return_text, _("Error: 'device wifi': %s"), error->message); @@ -2687,7 +2727,7 @@ do_device_wifi_list (NmCli *nmc, int argc, char **argv) return NMC_RESULT_ERROR_NOT_FOUND; } /* Main header name */ - nmc->print_fields.header_name = (char *) construct_header_name (base_hdr, ifname); + out.print_fields.header_name = (char *) construct_header_name (base_hdr, ifname); if (NM_IS_DEVICE_WIFI (device)) { if (bssid_user) { @@ -2710,7 +2750,7 @@ do_device_wifi_list (NmCli *nmc, int argc, char **argv) } /* Add headers (field names) */ arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_MAIN_HEADER_ADD | NMC_OF_FLAG_FIELD_NAMES); - g_ptr_array_add (nmc->output_data, arr); + g_ptr_array_add (out.output_data, arr); info = g_malloc0 (sizeof (APInfo)); info->nmc = nmc; @@ -2721,10 +2761,11 @@ do_device_wifi_list (NmCli *nmc, int argc, char **argv) fill_output_access_point (ap, info); - print_data (nmc); /* Print all data */ + print_data_prepare_width (out.output_data); + print_data (&nmc->nmc_config, &out); g_free (info); } else { - show_access_point_info (device, nmc); + show_access_point_info (device, nmc, &out); } } else { if ( nm_device_get_device_type (device) == NM_DEVICE_TYPE_GENERIC @@ -2752,11 +2793,11 @@ do_device_wifi_list (NmCli *nmc, int argc, char **argv) continue; /* Main header name */ - nmc->print_fields.header_name = (char *) construct_header_name (base_hdr, nm_device_get_iface (dev)); - nmc->print_fields.indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, NULL); + out.print_fields.header_name = (char *) construct_header_name (base_hdr, nm_device_get_iface (dev)); + out.print_fields.indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, NULL); arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_MAIN_HEADER_ADD | NMC_OF_FLAG_FIELD_NAMES); - g_ptr_array_add (nmc->output_data, arr); + g_ptr_array_add (out.output_data, arr); aps = nm_device_wifi_get_access_points (NM_DEVICE_WIFI (dev)); for (j = 0; j < aps->len; j++) { @@ -2781,8 +2822,9 @@ do_device_wifi_list (NmCli *nmc, int argc, char **argv) } if (empty_line) g_print ("\n"); /* Empty line between devices' APs */ - print_data (nmc); /* Print all data */ - nmc_empty_output_fields (nmc); + print_data_prepare_width (out.output_data); + print_data (&nmc->nmc_config, &out); + nmc_empty_output_fields (&out); empty_line = TRUE; } if (!ap) { @@ -2793,16 +2835,17 @@ do_device_wifi_list (NmCli *nmc, int argc, char **argv) } else { for (i = 0; devices[i]; i++) { NMDevice *dev = devices[i]; + NMC_OUTPUT_DATA_DEFINE_SCOPED (out2); /* Main header name */ - nmc->print_fields.header_name = (char *) construct_header_name (base_hdr, + out2.print_fields.header_name = (char *) construct_header_name (base_hdr, nm_device_get_iface (dev)); - nmc->print_fields.indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, NULL); + out2.print_fields.indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, NULL); if (NM_IS_DEVICE_WIFI (dev)) { if (empty_line) g_print ("\n"); /* Empty line between devices' APs */ - show_access_point_info (dev, nmc); + show_access_point_info (dev, nmc, &out2); empty_line = TRUE; } } @@ -3659,6 +3702,7 @@ show_device_lldp_list (NMDevice *device, NmCli *nmc, char *fields_str, int *coun size_t tmpl_len; const char *str; int i; + NMC_OUTPUT_DATA_DEFINE_SCOPED (out); neighbors = nm_device_get_lldp_neighbors (device); @@ -3669,11 +3713,11 @@ show_device_lldp_list (NMDevice *device, NmCli *nmc, char *fields_str, int *coun tmpl_len = sizeof (nmc_fields_dev_lldp_list); /* Main header name */ - nmc->print_fields.header_name = (char *) construct_header_name (_("Device LLDP neighbors"), - nm_device_get_iface (device)); - nmc->print_fields.indices = parse_output_fields (fields_str, nmc_fields_dev_lldp_list, FALSE, NULL, NULL); + out.print_fields.header_name = (char *) construct_header_name (_("Device LLDP neighbors"), + nm_device_get_iface (device)); + out.print_fields.indices = parse_output_fields (fields_str, nmc_fields_dev_lldp_list, FALSE, NULL, NULL); arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_MAIN_HEADER_ADD | NMC_OF_FLAG_FIELD_NAMES); - g_ptr_array_add (nmc->output_data, arr); + g_ptr_array_add (out.output_data, arr); for (i = 0; i < neighbors->len; i++) { NMLldpNeighbor *neighbor = neighbors->pdata[i]; @@ -3726,11 +3770,11 @@ show_device_lldp_list (NMDevice *device, NmCli *nmc, char *fields_str, int *coun if (nm_lldp_neighbor_get_attr_uint_value (neighbor, NM_LLDP_ATTR_PORT_ID_TYPE, &value)) set_val_strc (arr, 15, g_strdup_printf ("%u", value)); - g_ptr_array_add (nmc->output_data, arr); + g_ptr_array_add (out.output_data, arr); } - print_data (nmc); - nmc_empty_output_fields (nmc); + print_data_prepare_width (out.output_data); + print_data (&nmc->nmc_config, &out); return neighbors->len; } @@ -3742,6 +3786,7 @@ do_device_lldp_list (NmCli *nmc, int argc, char **argv) gs_free_error GError *error = NULL; char *fields_str; int counter = 0; + NMC_OUTPUT_DATA_DEFINE_SCOPED (out); while (argc > 0) { if (argc == 1 && nmc->complete) @@ -3775,7 +3820,7 @@ do_device_lldp_list (NmCli *nmc, int argc, char **argv) else fields_str = nmc->required_fields; - nmc->print_fields.indices = parse_output_fields (fields_str, nmc_fields_dev_lldp_list, FALSE, NULL, &error); + out.print_fields.indices = parse_output_fields (fields_str, nmc_fields_dev_lldp_list, FALSE, NULL, &error); if (error) { g_string_printf (nmc->return_text, _("Error: 'device lldp list': %s"), error->message); @@ -3786,16 +3831,13 @@ do_device_lldp_list (NmCli *nmc, int argc, char **argv) return nmc->return_value; if (device) { - nmc_empty_output_fields (nmc); show_device_lldp_list (device, nmc, fields_str, &counter); } else { NMDevice **devices = nmc_get_devices_sorted (nmc->client); int i; - for (i = 0; devices[i]; i++) { - nmc_empty_output_fields (nmc); + for (i = 0; devices[i]; i++) show_device_lldp_list (devices[i], nmc, fields_str, &counter); - } g_free (devices); } @@ -3812,7 +3854,7 @@ static NMCResultCode do_device_lldp (NmCli *nmc, int argc, char **argv) { if (!nmc->mode_specified) - nmc->multiline_output = TRUE; /* multiline mode is default for 'device lldp' */ + nmc->nmc_config_mutable.multiline_output = TRUE; /* multiline mode is default for 'device lldp' */ nmc_do_cmd (nmc, device_lldp_cmds, *argv, argc, argv); diff --git a/clients/cli/general.c b/clients/cli/general.c index 8e52dd29ca..5bffa92707 100644 --- a/clients/cli/general.c +++ b/clients/cli/general.c @@ -22,31 +22,35 @@ #include <string.h> #include <stdlib.h> +#include "nm-common-macros.h" + +#include "nm-client-utils.h" + #include "polkit-agent.h" #include "utils.h" #include "common.h" #include "general.h" #include "common.h" -#include "nm-common-macros.h" - #include "devices.h" #include "connections.h" +#define OUTPUT_FIELD_WITH_NAME(n) { .name = N_ (n), } + /* Available fields for 'general status' */ static NmcOutputField nmc_fields_nm_status[] = { - {"RUNNING", N_("RUNNING")}, /* 0 */ - {"VERSION", N_("VERSION")}, /* 1 */ - {"STATE", N_("STATE")}, /* 2 */ - {"STARTUP", N_("STARTUP")}, /* 3 */ - {"CONNECTIVITY", N_("CONNECTIVITY")}, /* 4 */ - {"NETWORKING", N_("NETWORKING")}, /* 5 */ - {"WIFI-HW", N_("WIFI-HW")}, /* 6 */ - {"WIFI", N_("WIFI")}, /* 7 */ - {"WWAN-HW", N_("WWAN-HW")}, /* 8 */ - {"WWAN", N_("WWAN")}, /* 9 */ - {"WIMAX-HW", N_("WIMAX-HW")}, /* 10 */ - {"WIMAX", N_("WIMAX")}, /* 11 */ - {NULL, NULL} + OUTPUT_FIELD_WITH_NAME ("RUNNING"), /* 0 */ + OUTPUT_FIELD_WITH_NAME ("VERSION"), /* 1 */ + OUTPUT_FIELD_WITH_NAME ("STATE"), /* 2 */ + OUTPUT_FIELD_WITH_NAME ("STARTUP"), /* 3 */ + OUTPUT_FIELD_WITH_NAME ("CONNECTIVITY"), /* 4 */ + OUTPUT_FIELD_WITH_NAME ("NETWORKING"), /* 5 */ + OUTPUT_FIELD_WITH_NAME ("WIFI-HW"), /* 6 */ + OUTPUT_FIELD_WITH_NAME ("WIFI"), /* 7 */ + OUTPUT_FIELD_WITH_NAME ("WWAN-HW"), /* 8 */ + OUTPUT_FIELD_WITH_NAME ("WWAN"), /* 9 */ + OUTPUT_FIELD_WITH_NAME ("WIMAX-HW"), /* 10 */ + OUTPUT_FIELD_WITH_NAME ("WIMAX"), /* 11 */ + { 0 } }; #define NMC_FIELDS_NM_STATUS_ALL "RUNNING,VERSION,STATE,STARTUP,CONNECTIVITY,NETWORKING,WIFI-HW,WIFI,WWAN-HW,WWAN" #define NMC_FIELDS_NM_STATUS_SWITCH "NETWORKING,WIFI-HW,WIFI,WWAN-HW,WWAN" @@ -61,18 +65,18 @@ static NmcOutputField nmc_fields_nm_status[] = { /* Available fields for 'general permissions' */ static NmcOutputField nmc_fields_nm_permissions[] = { - {"PERMISSION", N_("PERMISSION")}, /* 0 */ - {"VALUE", N_("VALUE")}, /* 1 */ - {NULL, NULL} + OUTPUT_FIELD_WITH_NAME ("PERMISSION"), /* 0 */ + OUTPUT_FIELD_WITH_NAME ("VALUE"), /* 1 */ + { 0 } }; #define NMC_FIELDS_NM_PERMISSIONS_ALL "PERMISSION,VALUE" #define NMC_FIELDS_NM_PERMISSIONS_COMMON "PERMISSION,VALUE" /* Available fields for 'general logging' */ static NmcOutputField nmc_fields_nm_logging[] = { - {"LEVEL", N_("LEVEL")}, /* 0 */ - {"DOMAINS", N_("DOMAINS")}, /* 1 */ - {NULL, NULL} + OUTPUT_FIELD_WITH_NAME ("LEVEL"), /* 0 */ + OUTPUT_FIELD_WITH_NAME ("DOMAINS"), /* 1 */ + { 0 } }; #define NMC_FIELDS_NM_LOGGING_ALL "LEVEL,DOMAINS" #define NMC_FIELDS_NM_LOGGING_COMMON "LEVEL,DOMAINS" @@ -321,6 +325,7 @@ show_nm_status (NmCli *nmc, const char *pretty_header_name, const char *print_fl const char *fields_common = print_flds ? print_flds : NMC_FIELDS_NM_STATUS_COMMON; NmcOutputField *tmpl, *arr; size_t tmpl_len; + NMC_OUTPUT_DATA_DEFINE_SCOPED (out); if (!nmc->required_fields || strcasecmp (nmc->required_fields, "common") == 0) fields_str = fields_common; @@ -331,7 +336,7 @@ show_nm_status (NmCli *nmc, const char *pretty_header_name, const char *print_fl tmpl = nmc_fields_nm_status; tmpl_len = sizeof (nmc_fields_nm_status); - nmc->print_fields.indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, &error); + out.print_fields.indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, &error); if (error) { g_string_printf (nmc->return_text, _("Error: only these fields are allowed: %s"), fields_all); @@ -349,9 +354,9 @@ show_nm_status (NmCli *nmc, const char *pretty_header_name, const char *print_fl wwan_hw_enabled = nm_client_wwan_hardware_get_enabled (nmc->client); wwan_enabled = nm_client_wwan_get_enabled (nmc->client); - nmc->print_fields.header_name = pretty_header_name ? (char *) pretty_header_name : _("NetworkManager status"); + out.print_fields.header_name = pretty_header_name ? (char *) pretty_header_name : _("NetworkManager status"); arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_MAIN_HEADER_ADD | NMC_OF_FLAG_FIELD_NAMES); - g_ptr_array_add (nmc->output_data, arr); + g_ptr_array_add (out.output_data, arr); arr = nmc_dup_fields_array (tmpl, tmpl_len, 0); set_val_strc (arr, 0, _("running")); @@ -375,9 +380,10 @@ show_nm_status (NmCli *nmc, const char *pretty_header_name, const char *print_fl arr[8].color = wwan_hw_enabled ? NMC_TERM_COLOR_GREEN : NMC_TERM_COLOR_RED; arr[9].color = wwan_enabled ? NMC_TERM_COLOR_GREEN : NMC_TERM_COLOR_RED; - g_ptr_array_add (nmc->output_data, arr); + g_ptr_array_add (out.output_data, arr); - print_data (nmc); /* Print all data */ + print_data_prepare_width (out.output_data); + print_data (&nmc->nmc_config, &out); return TRUE; } @@ -468,6 +474,7 @@ print_permissions (void *user_data) const char *fields_common = NMC_FIELDS_NM_PERMISSIONS_COMMON; NmcOutputField *tmpl, *arr; size_t tmpl_len; + NMC_OUTPUT_DATA_DEFINE_SCOPED (out); if (!nmc->required_fields || strcasecmp (nmc->required_fields, "common") == 0) fields_str = fields_common; @@ -478,7 +485,7 @@ print_permissions (void *user_data) tmpl = nmc_fields_nm_permissions; tmpl_len = sizeof (nmc_fields_nm_permissions); - nmc->print_fields.indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, &error); + out.print_fields.indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, &error); if (error) { g_string_printf (nmc->return_text, _("Error: 'general permissions': %s"), error->message); @@ -487,9 +494,9 @@ print_permissions (void *user_data) return FALSE; } - nmc->print_fields.header_name = _("NetworkManager permissions"); + out.print_fields.header_name = _("NetworkManager permissions"); arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_MAIN_HEADER_ADD | NMC_OF_FLAG_FIELD_NAMES); - g_ptr_array_add (nmc->output_data, arr); + g_ptr_array_add (out.output_data, arr); for (perm = NM_CLIENT_PERMISSION_NONE + 1; perm <= NM_CLIENT_PERMISSION_LAST; perm++) { @@ -498,9 +505,10 @@ print_permissions (void *user_data) arr = nmc_dup_fields_array (tmpl, tmpl_len, 0); set_val_strc (arr, 0, permission_to_string (perm)); set_val_strc (arr, 1, permission_result_to_string (perm_result)); - g_ptr_array_add (nmc->output_data, arr); + g_ptr_array_add (out.output_data, arr); } - print_data (nmc); /* Print all data */ + print_data_prepare_width (out.output_data); + print_data (&nmc->nmc_config, &out); quit (); return G_SOURCE_REMOVE; @@ -577,6 +585,7 @@ show_general_logging (NmCli *nmc) const char *fields_common = NMC_FIELDS_NM_LOGGING_COMMON; NmcOutputField *tmpl, *arr; size_t tmpl_len; + NMC_OUTPUT_DATA_DEFINE_SCOPED (out); if (!nmc->required_fields || strcasecmp (nmc->required_fields, "common") == 0) fields_str = fields_common; @@ -587,7 +596,7 @@ show_general_logging (NmCli *nmc) tmpl = nmc_fields_nm_logging; tmpl_len = sizeof (nmc_fields_nm_logging); - nmc->print_fields.indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, &error); + out.print_fields.indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, &error); if (error) { g_string_printf (nmc->return_text, _("Error: 'general logging': %s"), error->message); @@ -604,16 +613,17 @@ show_general_logging (NmCli *nmc) return FALSE; } - nmc->print_fields.header_name = _("NetworkManager logging"); + out.print_fields.header_name = _("NetworkManager logging"); arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_MAIN_HEADER_ADD | NMC_OF_FLAG_FIELD_NAMES); - g_ptr_array_add (nmc->output_data, arr); + g_ptr_array_add (out.output_data, arr); arr = nmc_dup_fields_array (tmpl, tmpl_len, 0); set_val_str (arr, 0, level); set_val_str (arr, 1, domains); - g_ptr_array_add (nmc->output_data, arr); + g_ptr_array_add (out.output_data, arr); - print_data (nmc); /* Print all data */ + print_data_prepare_width (out.output_data); + print_data (&nmc->nmc_config, &out); return TRUE; } @@ -782,8 +792,8 @@ nmc_switch_show (NmCli *nmc, const char *switch_name, const char *header) nmc->return_value = NMC_RESULT_ERROR_USER_INPUT; return FALSE; } - if (nmc->print_output == NMC_PRINT_NORMAL) - nmc->print_output = NMC_PRINT_TERSE; + if (nmc->nmc_config.print_output == NMC_PRINT_NORMAL) + nmc->nmc_config_mutable.print_output = NMC_PRINT_TERSE; if (!nmc->required_fields) nmc->required_fields = g_strdup (switch_name); @@ -1007,7 +1017,7 @@ networkmanager_running (NMClient *client, GParamSpec *param, NmCli *nmc) char *str; running = nm_client_get_nm_running (client); - str = nmc_colorize (nmc, + str = nmc_colorize (nmc->nmc_config.use_colors, running ? NMC_TERM_COLOR_GREEN : NMC_TERM_COLOR_RED, NMC_TERM_FORMAT_NORMAL, running ? _("NetworkManager has started") : _("NetworkManager has stopped")); @@ -1049,7 +1059,7 @@ client_connectivity (NMClient *client, GParamSpec *param, NmCli *nmc) char *str; g_object_get (client, NM_CLIENT_CONNECTIVITY, &connectivity, NULL); - str = nmc_colorize (nmc, connectivity_to_color (connectivity), NMC_TERM_FORMAT_NORMAL, + str = nmc_colorize (nmc->nmc_config.use_colors, connectivity_to_color (connectivity), NMC_TERM_FORMAT_NORMAL, _("Connectivity is now '%s'\n"), nm_connectivity_to_string (connectivity)); g_print ("%s", str); g_free (str); @@ -1062,7 +1072,7 @@ client_state (NMClient *client, GParamSpec *param, NmCli *nmc) char *str; g_object_get (client, NM_CLIENT_STATE, &state, NULL); - str = nmc_colorize (nmc, state_to_color (state), NMC_TERM_FORMAT_NORMAL, + str = nmc_colorize (nmc->nmc_config.use_colors, state_to_color (state), NMC_TERM_FORMAT_NORMAL, _("Networkmanager is now in the '%s' state\n"), nm_state_to_string (state)); g_print ("%s", str); @@ -1106,12 +1116,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_TERM_COLOR_RED, NMC_TERM_FORMAT_NORMAL, _("fw missing")); + tmp = nmc_colorize (nmc->nmc_config.use_colors, NMC_TERM_COLOR_RED, NMC_TERM_FORMAT_NORMAL, _("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_TERM_COLOR_RED, NMC_TERM_FORMAT_NORMAL, _("plugin missing")); + tmp = nmc_colorize (nmc->nmc_config.use_colors, NMC_TERM_COLOR_RED, NMC_TERM_FORMAT_NORMAL, _("plugin missing")); g_string_append_printf (outbuf, "%s, ", tmp); g_free (tmp); } @@ -1232,7 +1242,7 @@ do_overview (NmCli *nmc, int argc, char **argv) state = nm_active_connection_get_state (ac); nmc_active_connection_state_to_color (state, &color); - tmp = nmc_colorize (nmc, color, NMC_TERM_FORMAT_NORMAL, _("%s VPN connection"), + tmp = nmc_colorize (nmc->nmc_config.use_colors, color, NMC_TERM_FORMAT_NORMAL, _("%s VPN connection"), nm_active_connection_get_id (ac)); g_print ("%s\n", tmp); g_free (tmp); @@ -1250,7 +1260,7 @@ do_overview (NmCli *nmc, int argc, char **argv) state = nm_device_get_state (devices[i]); nmc_device_state_to_color (state, &color, &color_fmt); - tmp = nmc_colorize (nmc, color, color_fmt, "%s: %s%s%s", + tmp = nmc_colorize (nmc->nmc_config.use_colors, color, color_fmt, "%s: %s%s%s", nm_device_get_iface (devices[i]), nmc_device_state_to_string (state), ac ? " to " : "", @@ -1332,7 +1342,7 @@ do_monitor (NmCli *nmc, int argc, char **argv) if (!nm_client_get_nm_running (nmc->client)) { char *str; - str = nmc_colorize (nmc, NMC_TERM_COLOR_RED, NMC_TERM_FORMAT_NORMAL, + str = nmc_colorize (nmc->nmc_config.use_colors, NMC_TERM_COLOR_RED, NMC_TERM_FORMAT_NORMAL, _("Networkmanager is not running (waiting for it)\n")); g_print ("%s", str); g_free (str); diff --git a/clients/cli/nmcli.c b/clients/cli/nmcli.c index ee3f747b46..2553596459 100644 --- a/clients/cli/nmcli.c +++ b/clients/cli/nmcli.c @@ -32,6 +32,8 @@ #include <readline/readline.h> #include <readline/history.h> +#include "nm-client-utils.h" + #include "polkit-agent.h" #include "nmcli.h" #include "utils.h" @@ -66,7 +68,22 @@ struct termios termios_orig; NM_CACHED_QUARK_FCN ("nmcli-error-quark", nmcli_error_quark) static void -complete_field (GHashTable *h, const char *setting, NmcOutputField field[]) +complete_field_setting (GHashTable *h, NMMetaSettingType setting_type) +{ + const NMMetaSettingInfoEditor *setting_info = &nm_meta_setting_infos_editor[setting_type]; + guint i; + + for (i = 0; i < setting_info->properties_num; i++) { + if (setting_info->properties[i].is_name) + continue; + g_hash_table_add (h, g_strdup_printf ("%s.%s", + setting_info->general->setting_name, + setting_info->properties[i].property_name)); + } +} + +static void +complete_field (GHashTable *h, const char *setting, const NmcOutputField *field) { int i; @@ -100,7 +117,7 @@ complete_one (gpointer key, gpointer value, gpointer user_data) static void complete_fields (const char *prefix) { - + guint i; GHashTable *h; h = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); @@ -130,35 +147,8 @@ complete_fields (const char *prefix) complete_field (h, NULL, nmc_fields_dev_show_sections); complete_field (h, NULL, nmc_fields_dev_lldp_list); - complete_field (h, "connection", nmc_fields_setting_connection); - complete_field (h, "802-3-ethernet", nmc_fields_setting_wired); - complete_field (h, "802-1x", nmc_fields_setting_8021X); - complete_field (h, "802-11-wireless", nmc_fields_setting_wireless); - complete_field (h, "802-11-wireless-security", nmc_fields_setting_wireless_security); - complete_field (h, "ipv4", nmc_fields_setting_ip4_config); - complete_field (h, "ipv6", nmc_fields_setting_ip6_config); - complete_field (h, "serial", nmc_fields_setting_serial); - complete_field (h, "ppp", nmc_fields_setting_ppp); - complete_field (h, "pppoe", nmc_fields_setting_pppoe); - complete_field (h, "adsl", nmc_fields_setting_adsl); - complete_field (h, "gsm", nmc_fields_setting_gsm); - complete_field (h, "cdma", nmc_fields_setting_cdma); - complete_field (h, "bluetooth", nmc_fields_setting_bluetooth); - complete_field (h, "802-11-olpc-mesh", nmc_fields_setting_olpc_mesh); - complete_field (h, "vpn", nmc_fields_setting_vpn); - complete_field (h, "wimax", nmc_fields_setting_wimax); - complete_field (h, "infiniband", nmc_fields_setting_infiniband); - complete_field (h, "bond", nmc_fields_setting_bond); - complete_field (h, "vlan", nmc_fields_setting_vlan); - complete_field (h, "bridge", nmc_fields_setting_bridge); - complete_field (h, "bridge-port", nmc_fields_setting_bridge_port); - complete_field (h, "team", nmc_fields_setting_team); - complete_field (h, "team-port", nmc_fields_setting_team_port); - complete_field (h, "dcb", nmc_fields_setting_dcb); - complete_field (h, "tun", nmc_fields_setting_tun); - complete_field (h, "ip-tunnel", nmc_fields_setting_ip_tunnel); - complete_field (h, "macvlan", nmc_fields_setting_macvlan); - complete_field (h, "vxlan", nmc_fields_setting_vxlan); + for (i = 0; i < _NM_META_SETTING_TYPE_NUM; i++) + complete_field_setting (h, i); g_hash_table_foreach (h, complete_one, (gpointer) prefix); g_hash_table_destroy (h); @@ -245,31 +235,31 @@ process_command_line (NmCli *nmc, int argc, char **argv) } if (matches (opt, "-terse")) { - if (nmc->print_output == NMC_PRINT_TERSE) { + 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; return FALSE; } - else if (nmc->print_output == NMC_PRINT_PRETTY) { + else if (nmc->nmc_config.print_output == NMC_PRINT_PRETTY) { g_string_printf (nmc->return_text, _("Error: Option '--terse' is mutually exclusive with '--pretty'.")); nmc->return_value = NMC_RESULT_ERROR_USER_INPUT; return FALSE; } else - nmc->print_output = NMC_PRINT_TERSE; + nmc->nmc_config_mutable.print_output = NMC_PRINT_TERSE; } else if (matches (opt, "-pretty")) { - if (nmc->print_output == NMC_PRINT_PRETTY) { + if (nmc->nmc_config.print_output == NMC_PRINT_PRETTY) { g_string_printf (nmc->return_text, _("Error: Option '--pretty' is specified the second time.")); nmc->return_value = NMC_RESULT_ERROR_USER_INPUT; return FALSE; } - else if (nmc->print_output == NMC_PRINT_TERSE) { + else if (nmc->nmc_config.print_output == NMC_PRINT_TERSE) { g_string_printf (nmc->return_text, _("Error: Option '--pretty' is mutually exclusive with '--terse'.")); nmc->return_value = NMC_RESULT_ERROR_USER_INPUT; return FALSE; } else - nmc->print_output = NMC_PRINT_PRETTY; + nmc->nmc_config_mutable.print_output = NMC_PRINT_PRETTY; } else if (matches (opt, "-mode")) { nmc->mode_specified = TRUE; argc--; @@ -282,9 +272,9 @@ process_command_line (NmCli *nmc, int argc, char **argv) if (argc == 1 && nmc->complete) nmc_complete_strings (argv[0], "tabular", "multiline", NULL); if (matches (argv[0], "tabular")) - nmc->multiline_output = FALSE; + nmc->nmc_config_mutable.multiline_output = FALSE; else if (matches (argv[0], "multiline")) - nmc->multiline_output = TRUE; + nmc->nmc_config_mutable.multiline_output = TRUE; else { g_string_printf (nmc->return_text, _("Error: '%s' is not valid argument for '%s' option."), argv[0], opt); nmc->return_value = NMC_RESULT_ERROR_USER_INPUT; @@ -301,11 +291,11 @@ process_command_line (NmCli *nmc, int argc, char **argv) if (argc == 1 && nmc->complete) nmc_complete_strings (argv[0], "yes", "no", "auto", NULL); if (matches (argv[0], "auto")) - nmc->use_colors = NMC_USE_COLOR_AUTO; + nmc->nmc_config_mutable.use_colors = NMC_USE_COLOR_AUTO; else if (matches (argv[0], "yes")) - nmc->use_colors = NMC_USE_COLOR_YES; + nmc->nmc_config_mutable.use_colors = NMC_USE_COLOR_YES; else if (matches (argv[0], "no")) - nmc->use_colors = NMC_USE_COLOR_NO; + nmc->nmc_config_mutable.use_colors = NMC_USE_COLOR_NO; else { g_string_printf (nmc->return_text, _("Error: '%s' is not valid argument for '%s' option."), argv[0], opt); nmc->return_value = NMC_RESULT_ERROR_USER_INPUT; @@ -322,9 +312,9 @@ process_command_line (NmCli *nmc, int argc, char **argv) if (argc == 1 && nmc->complete) nmc_complete_strings (argv[0], "yes", "no", NULL); if (matches (argv[0], "yes")) - nmc->escape_values = TRUE; + nmc->nmc_config_mutable.escape_values = TRUE; else if (matches (argv[0], "no")) - nmc->escape_values = FALSE; + nmc->nmc_config_mutable.escape_values = FALSE; else { g_string_printf (nmc->return_text, _("Error: '%s' is not valid argument for '%s' option."), argv[0], opt); nmc->return_value = NMC_RESULT_ERROR_USER_INPUT; @@ -352,7 +342,7 @@ process_command_line (NmCli *nmc, int argc, char **argv) if (argc == 1 && nmc->complete) complete_fields (argv[0]); nmc->required_fields = g_strdup (argv[0]); - nmc->print_output = NMC_PRINT_TERSE; + 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 * before the "-g <field>" option (-g may be still more practical and easy to remember than -t -f). @@ -545,18 +535,16 @@ nmc_init (NmCli *nmc) nmc->should_wait = 0; nmc->nowait_flag = TRUE; - nmc->print_output = NMC_PRINT_NORMAL; - nmc->multiline_output = FALSE; + nmc->nmc_config_mutable.print_output = NMC_PRINT_NORMAL; + nmc->nmc_config_mutable.multiline_output = FALSE; nmc->mode_specified = FALSE; - nmc->escape_values = TRUE; + nmc->nmc_config_mutable.escape_values = TRUE; nmc->required_fields = NULL; - nmc->output_data = g_ptr_array_new_full (20, g_free); - memset (&nmc->print_fields, '\0', sizeof (NmcPrintFields)); nmc->ask = FALSE; nmc->complete = FALSE; nmc->show_secrets = FALSE; - nmc->use_colors = NMC_USE_COLOR_AUTO; - nmc->in_editor = 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_show_secrets = FALSE; @@ -579,8 +567,6 @@ nmc_cleanup (NmCli *nmc) g_hash_table_destroy (nmc->pwds_hash); g_free (nmc->required_fields); - nmc_empty_output_fields (nmc); - g_ptr_array_unref (nmc->output_data); nmc_polkit_agent_fini (nmc); } diff --git a/clients/cli/nmcli.h b/clients/cli/nmcli.h index 7e33e3a70a..1b9c3e72e1 100644 --- a/clients/cli/nmcli.h +++ b/clients/cli/nmcli.h @@ -104,17 +104,26 @@ typedef enum { #define NMC_OF_FLAG_MAIN_HEADER_ADD 0x00000004 /* Print main header in addition to values/field names */ #define NMC_OF_FLAG_MAIN_HEADER_ONLY 0x00000008 /* Print main header only */ +struct _NMMetaSettingInfoEditor; + typedef struct _NmcOutputField { const char *name; /* Field's name */ - const char *name_l10n; /* Field's name for translation */ int width; /* Width in screen columns */ - struct _NmcOutputField *group; /* Points to an array with available section field names if this is a section (group) field */ + const struct _NmcOutputField *group_list; /* Points to an array with available section field names if this is a section (group) field */ void *value; /* Value of current field - char* or char** (NULL-terminated array) */ gboolean value_is_array; /* Whether value is char** instead of char* */ gboolean free_value; /* Whether to free the value */ guint32 flags; /* Flags - whether and how to print values/field names/headers */ NmcTermColor color; /* Use this color to print value */ NmcTermFormat color_fmt; /* Use this terminal format to print value */ + + /* in a very particular case NmcOutputField is used in combination with + * the @group_list above. That list will go away (and the entire NmcOutputField + * should separate formatting-options, setting-metadata and output. + * + * For now, hack around that by alternatively providing a @setting_info instead + * of @group_list. */ + const struct _NMMetaSettingInfoEditor *setting_info; } NmcOutputField; typedef struct { @@ -129,6 +138,19 @@ typedef enum { 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 multiline_output; /* Multiline output instead of default tabular */ + gboolean escape_values; /* Whether to escape ':' and '\' in terse tabular mode */ + gboolean in_editor; /* Whether running the editor - nmcli con edit' */ +} NmcConfig; + +typedef struct _NmcOutputData { + GPtrArray *output_data; /* GPtrArray of arrays of NmcOutputField structs - accumulates data for output */ + NmcPrintFields print_fields; /* Structure with field indices to print */ +} NmcOutputData; + /* NmCli - main structure */ typedef struct _NmCli { NMClient *client; /* Pointer to NMClient of libnm */ @@ -144,18 +166,15 @@ typedef struct _NmCli { int should_wait; /* Semaphore indicating whether nmcli should not end or not yet */ gboolean nowait_flag; /* '--nowait' option; used for passing to callbacks */ - NMCPrintOutput print_output; /* Output mode */ - gboolean multiline_output; /* Multiline output instead of default tabular */ gboolean mode_specified; /* Whether tabular/multiline mode was specified via '--mode' option */ - NmcColorOption use_colors; /* Whether to use colors for output: option '--color' */ - gboolean escape_values; /* Whether to escape ':' and '\' in terse tabular mode */ + union { + const NmcConfig nmc_config; + NmcConfig nmc_config_mutable; + }; char *required_fields; /* Required fields in output: '--fields' option */ - GPtrArray *output_data; /* GPtrArray of arrays of NmcOutputField structs - accumulates data for output */ - NmcPrintFields print_fields; /* Structure with field indices to print */ gboolean ask; /* Ask for missing parameters: option '--ask' */ gboolean complete; /* Autocomplete the command line */ gboolean show_secrets; /* Whether to display secrets (both input and output): option '--show-secrets' */ - gboolean in_editor; /* Whether running the editor - nmcli con edit' */ 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' */ gboolean editor_show_secrets; /* Whether to display secrets in the editor' */ @@ -173,4 +192,11 @@ void nmc_clear_sigint (void); void nmc_set_sigquit_internal (void); void nmc_exit (void); +void nmc_empty_output_fields (NmcOutputData *output_data); + +#define NMC_OUTPUT_DATA_DEFINE_SCOPED(out) \ + nm_auto (nmc_empty_output_fields) NmcOutputData out = { \ + .output_data = g_ptr_array_new_full (20, g_free), \ + } + #endif /* NMC_NMCLI_H */ diff --git a/clients/cli/settings.c b/clients/cli/settings.c index 87b1f50f71..d38787e89c 100644 --- a/clients/cli/settings.c +++ b/clients/cli/settings.c @@ -25,5773 +25,155 @@ #include <arpa/inet.h> #include "nm-common-macros.h" -#include "utils.h" -#include "common.h" -#include "nm-vpn-helpers.h" - -/* Forward declarations */ -static char *wep_key_type_to_string (NMWepKeyType type); - -typedef enum { - NMC_PROPERTY_GET_PRETTY, - NMC_PROPERTY_GET_PARSABLE, -} NmcPropertyGetType; - -/* Helper macro to define fields */ -#define SETTING_FIELD(setting) { setting, N_(setting), 0, NULL, FALSE, FALSE, 0 } - -/* Available fields for NM_SETTING_CONNECTION_SETTING_NAME */ -NmcOutputField nmc_fields_setting_connection[] = { - SETTING_FIELD ("name"), /* 0 */ - SETTING_FIELD (NM_SETTING_CONNECTION_ID), /* 1 */ - SETTING_FIELD (NM_SETTING_CONNECTION_UUID), /* 2 */ - SETTING_FIELD (NM_SETTING_CONNECTION_STABLE_ID), /* 3 */ - SETTING_FIELD (NM_SETTING_CONNECTION_INTERFACE_NAME), /* 4 */ - SETTING_FIELD (NM_SETTING_CONNECTION_TYPE), /* 5 */ - SETTING_FIELD (NM_SETTING_CONNECTION_AUTOCONNECT), /* 6 */ - SETTING_FIELD (NM_SETTING_CONNECTION_AUTOCONNECT_PRIORITY), /* 7 */ - SETTING_FIELD (NM_SETTING_CONNECTION_AUTOCONNECT_RETRIES), /* 8 */ - SETTING_FIELD (NM_SETTING_CONNECTION_TIMESTAMP), /* 9 */ - SETTING_FIELD (NM_SETTING_CONNECTION_READ_ONLY), /* 10 */ - SETTING_FIELD (NM_SETTING_CONNECTION_PERMISSIONS), /* 11 */ - SETTING_FIELD (NM_SETTING_CONNECTION_ZONE), /* 12 */ - SETTING_FIELD (NM_SETTING_CONNECTION_MASTER), /* 13 */ - SETTING_FIELD (NM_SETTING_CONNECTION_SLAVE_TYPE), /* 14 */ - SETTING_FIELD (NM_SETTING_CONNECTION_AUTOCONNECT_SLAVES), /* 15 */ - SETTING_FIELD (NM_SETTING_CONNECTION_SECONDARIES), /* 16 */ - SETTING_FIELD (NM_SETTING_CONNECTION_GATEWAY_PING_TIMEOUT), /* 17 */ - SETTING_FIELD (NM_SETTING_CONNECTION_METERED), /* 18 */ - SETTING_FIELD (NM_SETTING_CONNECTION_LLDP), /* 19 */ - {NULL, NULL, 0, NULL, FALSE, FALSE, 0} -}; -#define NMC_FIELDS_SETTING_CONNECTION_ALL "name"","\ - NM_SETTING_CONNECTION_ID","\ - NM_SETTING_CONNECTION_UUID","\ - NM_SETTING_CONNECTION_STABLE_ID","\ - NM_SETTING_CONNECTION_INTERFACE_NAME","\ - NM_SETTING_CONNECTION_TYPE","\ - NM_SETTING_CONNECTION_AUTOCONNECT","\ - NM_SETTING_CONNECTION_AUTOCONNECT_PRIORITY","\ - NM_SETTING_CONNECTION_AUTOCONNECT_RETRIES","\ - NM_SETTING_CONNECTION_TIMESTAMP","\ - NM_SETTING_CONNECTION_READ_ONLY","\ - NM_SETTING_CONNECTION_PERMISSIONS","\ - NM_SETTING_CONNECTION_ZONE","\ - NM_SETTING_CONNECTION_MASTER","\ - NM_SETTING_CONNECTION_SLAVE_TYPE","\ - NM_SETTING_CONNECTION_AUTOCONNECT_SLAVES","\ - NM_SETTING_CONNECTION_SECONDARIES","\ - NM_SETTING_CONNECTION_GATEWAY_PING_TIMEOUT","\ - NM_SETTING_CONNECTION_METERED","\ - NM_SETTING_CONNECTION_LLDP - -/* Available fields for NM_SETTING_WIRED_SETTING_NAME */ -NmcOutputField nmc_fields_setting_wired[] = { - SETTING_FIELD ("name"), /* 0 */ - SETTING_FIELD (NM_SETTING_WIRED_PORT), /* 1 */ - SETTING_FIELD (NM_SETTING_WIRED_SPEED), /* 2 */ - SETTING_FIELD (NM_SETTING_WIRED_DUPLEX), /* 3 */ - SETTING_FIELD (NM_SETTING_WIRED_AUTO_NEGOTIATE), /* 4 */ - SETTING_FIELD (NM_SETTING_WIRED_MAC_ADDRESS), /* 5 */ - SETTING_FIELD (NM_SETTING_WIRED_CLONED_MAC_ADDRESS), /* 6 */ - SETTING_FIELD (NM_SETTING_WIRED_GENERATE_MAC_ADDRESS_MASK), /* 7 */ - SETTING_FIELD (NM_SETTING_WIRED_MAC_ADDRESS_BLACKLIST), /* 8 */ - SETTING_FIELD (NM_SETTING_WIRED_MTU), /* 9 */ - SETTING_FIELD (NM_SETTING_WIRED_S390_SUBCHANNELS), /* 10 */ - SETTING_FIELD (NM_SETTING_WIRED_S390_NETTYPE), /* 11 */ - SETTING_FIELD (NM_SETTING_WIRED_S390_OPTIONS), /* 12 */ - SETTING_FIELD (NM_SETTING_WIRED_WAKE_ON_LAN), /* 13 */ - SETTING_FIELD (NM_SETTING_WIRED_WAKE_ON_LAN_PASSWORD), /* 14 */ - {NULL, NULL, 0, NULL, FALSE, FALSE, 0} -}; -#define NMC_FIELDS_SETTING_WIRED_ALL "name"","\ - NM_SETTING_WIRED_PORT","\ - NM_SETTING_WIRED_SPEED","\ - NM_SETTING_WIRED_DUPLEX","\ - NM_SETTING_WIRED_AUTO_NEGOTIATE","\ - NM_SETTING_WIRED_MAC_ADDRESS","\ - NM_SETTING_WIRED_CLONED_MAC_ADDRESS","\ - NM_SETTING_WIRED_GENERATE_MAC_ADDRESS_MASK","\ - NM_SETTING_WIRED_MAC_ADDRESS_BLACKLIST","\ - NM_SETTING_WIRED_MTU","\ - NM_SETTING_WIRED_S390_SUBCHANNELS","\ - NM_SETTING_WIRED_S390_NETTYPE","\ - NM_SETTING_WIRED_S390_OPTIONS","\ - NM_SETTING_WIRED_WAKE_ON_LAN","\ - NM_SETTING_WIRED_WAKE_ON_LAN_PASSWORD - -/* Available fields for NM_SETTING_802_1X_SETTING_NAME */ -NmcOutputField nmc_fields_setting_8021X[] = { - SETTING_FIELD ("name"), /* 0 */ - SETTING_FIELD (NM_SETTING_802_1X_EAP), /* 1 */ - SETTING_FIELD (NM_SETTING_802_1X_IDENTITY), /* 2 */ - SETTING_FIELD (NM_SETTING_802_1X_ANONYMOUS_IDENTITY), /* 3 */ - SETTING_FIELD (NM_SETTING_802_1X_PAC_FILE), /* 4 */ - SETTING_FIELD (NM_SETTING_802_1X_CA_CERT), /* 5 */ - SETTING_FIELD (NM_SETTING_802_1X_CA_CERT_PASSWORD), /* 6 */ - SETTING_FIELD (NM_SETTING_802_1X_CA_CERT_PASSWORD_FLAGS), /* 7 */ - SETTING_FIELD (NM_SETTING_802_1X_CA_PATH), /* 8 */ - SETTING_FIELD (NM_SETTING_802_1X_SUBJECT_MATCH), /* 9 */ - SETTING_FIELD (NM_SETTING_802_1X_ALTSUBJECT_MATCHES), /* 10 */ - SETTING_FIELD (NM_SETTING_802_1X_DOMAIN_SUFFIX_MATCH), /* 11 */ - SETTING_FIELD (NM_SETTING_802_1X_CLIENT_CERT), /* 12 */ - SETTING_FIELD (NM_SETTING_802_1X_CLIENT_CERT_PASSWORD), /* 13 */ - SETTING_FIELD (NM_SETTING_802_1X_CLIENT_CERT_PASSWORD_FLAGS), /* 14 */ - SETTING_FIELD (NM_SETTING_802_1X_PHASE1_PEAPVER), /* 15 */ - SETTING_FIELD (NM_SETTING_802_1X_PHASE1_PEAPLABEL), /* 16 */ - SETTING_FIELD (NM_SETTING_802_1X_PHASE1_FAST_PROVISIONING), /* 17 */ - SETTING_FIELD (NM_SETTING_802_1X_PHASE1_AUTH_FLAGS), /* 18 */ - SETTING_FIELD (NM_SETTING_802_1X_PHASE2_AUTH), /* 19 */ - SETTING_FIELD (NM_SETTING_802_1X_PHASE2_AUTHEAP), /* 20 */ - SETTING_FIELD (NM_SETTING_802_1X_PHASE2_CA_CERT_PASSWORD), /* 21 */ - SETTING_FIELD (NM_SETTING_802_1X_PHASE2_CA_CERT_PASSWORD_FLAGS), /* 22 */ - SETTING_FIELD (NM_SETTING_802_1X_PHASE2_CA_CERT), /* 23 */ - SETTING_FIELD (NM_SETTING_802_1X_PHASE2_CA_PATH), /* 24 */ - SETTING_FIELD (NM_SETTING_802_1X_PHASE2_SUBJECT_MATCH), /* 25 */ - SETTING_FIELD (NM_SETTING_802_1X_PHASE2_ALTSUBJECT_MATCHES), /* 26 */ - SETTING_FIELD (NM_SETTING_802_1X_PHASE2_DOMAIN_SUFFIX_MATCH), /* 27 */ - SETTING_FIELD (NM_SETTING_802_1X_PHASE2_CLIENT_CERT), /* 28 */ - SETTING_FIELD (NM_SETTING_802_1X_PHASE2_CLIENT_CERT_PASSWORD), /* 29 */ - SETTING_FIELD (NM_SETTING_802_1X_PHASE2_CLIENT_CERT_PASSWORD_FLAGS), /* 30 */ - SETTING_FIELD (NM_SETTING_802_1X_PASSWORD), /* 31 */ - SETTING_FIELD (NM_SETTING_802_1X_PASSWORD_FLAGS), /* 32 */ - SETTING_FIELD (NM_SETTING_802_1X_PASSWORD_RAW), /* 33 */ - SETTING_FIELD (NM_SETTING_802_1X_PASSWORD_RAW_FLAGS), /* 34 */ - SETTING_FIELD (NM_SETTING_802_1X_PRIVATE_KEY), /* 35 */ - SETTING_FIELD (NM_SETTING_802_1X_PRIVATE_KEY_PASSWORD), /* 36 */ - SETTING_FIELD (NM_SETTING_802_1X_PRIVATE_KEY_PASSWORD_FLAGS), /* 37 */ - SETTING_FIELD (NM_SETTING_802_1X_PHASE2_PRIVATE_KEY), /* 38 */ - SETTING_FIELD (NM_SETTING_802_1X_PHASE2_PRIVATE_KEY_PASSWORD), /* 39 */ - SETTING_FIELD (NM_SETTING_802_1X_PHASE2_PRIVATE_KEY_PASSWORD_FLAGS), /* 40 */ - SETTING_FIELD (NM_SETTING_802_1X_PIN), /* 41 */ - SETTING_FIELD (NM_SETTING_802_1X_PIN_FLAGS), /* 42 */ - SETTING_FIELD (NM_SETTING_802_1X_SYSTEM_CA_CERTS), /* 43 */ - SETTING_FIELD (NM_SETTING_802_1X_AUTH_TIMEOUT), /* 44 */ - {NULL, NULL, 0, NULL, FALSE, FALSE, 0} -}; -#define NMC_FIELDS_SETTING_802_1X_ALL "name"","\ - NM_SETTING_802_1X_EAP","\ - NM_SETTING_802_1X_IDENTITY","\ - NM_SETTING_802_1X_ANONYMOUS_IDENTITY","\ - NM_SETTING_802_1X_PAC_FILE","\ - NM_SETTING_802_1X_CA_CERT","\ - NM_SETTING_802_1X_CA_CERT_PASSWORD","\ - NM_SETTING_802_1X_CA_CERT_PASSWORD_FLAGS","\ - NM_SETTING_802_1X_CA_PATH","\ - NM_SETTING_802_1X_SUBJECT_MATCH","\ - NM_SETTING_802_1X_ALTSUBJECT_MATCHES","\ - NM_SETTING_802_1X_DOMAIN_SUFFIX_MATCH","\ - NM_SETTING_802_1X_CLIENT_CERT","\ - NM_SETTING_802_1X_CLIENT_CERT_PASSWORD","\ - NM_SETTING_802_1X_CLIENT_CERT_PASSWORD_FLAGS","\ - NM_SETTING_802_1X_PHASE1_PEAPVER","\ - NM_SETTING_802_1X_PHASE1_PEAPLABEL","\ - NM_SETTING_802_1X_PHASE1_FAST_PROVISIONING","\ - NM_SETTING_802_1X_PHASE1_AUTH_FLAGS","\ - NM_SETTING_802_1X_PHASE2_AUTH","\ - NM_SETTING_802_1X_PHASE2_AUTHEAP","\ - NM_SETTING_802_1X_PHASE2_CA_CERT","\ - NM_SETTING_802_1X_PHASE2_CA_CERT_PASSWORD","\ - NM_SETTING_802_1X_PHASE2_CA_CERT_PASSWORD_FLAGS","\ - NM_SETTING_802_1X_PHASE2_CA_PATH","\ - NM_SETTING_802_1X_PHASE2_SUBJECT_MATCH","\ - NM_SETTING_802_1X_PHASE2_ALTSUBJECT_MATCHES","\ - NM_SETTING_802_1X_PHASE2_DOMAIN_SUFFIX_MATCH","\ - NM_SETTING_802_1X_PHASE2_CLIENT_CERT","\ - NM_SETTING_802_1X_PHASE2_CLIENT_CERT_PASSWORD","\ - NM_SETTING_802_1X_PHASE2_CLIENT_CERT_PASSWORD_FLAGS","\ - NM_SETTING_802_1X_PASSWORD","\ - NM_SETTING_802_1X_PASSWORD_FLAGS","\ - NM_SETTING_802_1X_PASSWORD_RAW","\ - NM_SETTING_802_1X_PASSWORD_RAW_FLAGS","\ - NM_SETTING_802_1X_PRIVATE_KEY","\ - NM_SETTING_802_1X_PRIVATE_KEY_PASSWORD","\ - NM_SETTING_802_1X_PRIVATE_KEY_PASSWORD_FLAGS","\ - NM_SETTING_802_1X_PHASE2_PRIVATE_KEY","\ - NM_SETTING_802_1X_PHASE2_PRIVATE_KEY_PASSWORD","\ - NM_SETTING_802_1X_PHASE2_PRIVATE_KEY_PASSWORD_FLAGS","\ - NM_SETTING_802_1X_PIN","\ - NM_SETTING_802_1X_PIN_FLAGS","\ - NM_SETTING_802_1X_SYSTEM_CA_CERTS","\ - NM_SETTING_802_1X_AUTH_TIMEOUT - -/* Available fields for NM_SETTING_WIRELESS_SETTING_NAME */ -NmcOutputField nmc_fields_setting_wireless[] = { - SETTING_FIELD ("name"), /* 0 */ - SETTING_FIELD (NM_SETTING_WIRELESS_SSID), /* 1 */ - SETTING_FIELD (NM_SETTING_WIRELESS_MODE), /* 2 */ - SETTING_FIELD (NM_SETTING_WIRELESS_BAND), /* 3 */ - SETTING_FIELD (NM_SETTING_WIRELESS_CHANNEL), /* 4 */ - SETTING_FIELD (NM_SETTING_WIRELESS_BSSID), /* 5 */ - SETTING_FIELD (NM_SETTING_WIRELESS_RATE), /* 6 */ - SETTING_FIELD (NM_SETTING_WIRELESS_TX_POWER), /* 7 */ - SETTING_FIELD (NM_SETTING_WIRELESS_MAC_ADDRESS), /* 8 */ - SETTING_FIELD (NM_SETTING_WIRELESS_CLONED_MAC_ADDRESS), /* 9 */ - SETTING_FIELD (NM_SETTING_WIRELESS_GENERATE_MAC_ADDRESS_MASK), /* 10 */ - SETTING_FIELD (NM_SETTING_WIRELESS_MAC_ADDRESS_BLACKLIST), /* 11 */ - SETTING_FIELD (NM_SETTING_WIRELESS_MAC_ADDRESS_RANDOMIZATION), /* 12 */ - SETTING_FIELD (NM_SETTING_WIRELESS_MTU), /* 13 */ - SETTING_FIELD (NM_SETTING_WIRELESS_SEEN_BSSIDS), /* 14 */ - SETTING_FIELD (NM_SETTING_WIRELESS_HIDDEN), /* 15 */ - SETTING_FIELD (NM_SETTING_WIRELESS_POWERSAVE), /* 16 */ - {NULL, NULL, 0, NULL, FALSE, FALSE, 0} -}; -#define NMC_FIELDS_SETTING_WIRELESS_ALL "name"","\ - NM_SETTING_WIRELESS_SSID","\ - NM_SETTING_WIRELESS_MODE","\ - NM_SETTING_WIRELESS_BAND","\ - NM_SETTING_WIRELESS_CHANNEL","\ - NM_SETTING_WIRELESS_BSSID","\ - NM_SETTING_WIRELESS_RATE","\ - NM_SETTING_WIRELESS_TX_POWER","\ - NM_SETTING_WIRELESS_MAC_ADDRESS","\ - NM_SETTING_WIRELESS_CLONED_MAC_ADDRESS","\ - NM_SETTING_WIRELESS_GENERATE_MAC_ADDRESS_MASK","\ - NM_SETTING_WIRELESS_MAC_ADDRESS_BLACKLIST","\ - NM_SETTING_WIRELESS_MAC_ADDRESS_RANDOMIZATION","\ - NM_SETTING_WIRELESS_MTU","\ - NM_SETTING_WIRELESS_SEEN_BSSIDS","\ - NM_SETTING_WIRELESS_HIDDEN"," \ - NM_SETTING_WIRELESS_POWERSAVE - -/* Available fields for NM_SETTING_WIRELESS_SECURITY_SETTING_NAME */ -NmcOutputField nmc_fields_setting_wireless_security[] = { - SETTING_FIELD ("name"), /* 0 */ - SETTING_FIELD (NM_SETTING_WIRELESS_SECURITY_KEY_MGMT), /* 1 */ - SETTING_FIELD (NM_SETTING_WIRELESS_SECURITY_WEP_TX_KEYIDX), /* 2 */ - SETTING_FIELD (NM_SETTING_WIRELESS_SECURITY_AUTH_ALG), /* 3 */ - SETTING_FIELD (NM_SETTING_WIRELESS_SECURITY_PROTO), /* 4 */ - SETTING_FIELD (NM_SETTING_WIRELESS_SECURITY_PAIRWISE), /* 5 */ - SETTING_FIELD (NM_SETTING_WIRELESS_SECURITY_GROUP), /* 6 */ - SETTING_FIELD (NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME), /* 7 */ - SETTING_FIELD (NM_SETTING_WIRELESS_SECURITY_WEP_KEY0), /* 8 */ - SETTING_FIELD (NM_SETTING_WIRELESS_SECURITY_WEP_KEY1), /* 9 */ - SETTING_FIELD (NM_SETTING_WIRELESS_SECURITY_WEP_KEY2), /* 10 */ - SETTING_FIELD (NM_SETTING_WIRELESS_SECURITY_WEP_KEY3), /* 11 */ - SETTING_FIELD (NM_SETTING_WIRELESS_SECURITY_WEP_KEY_FLAGS), /* 12 */ - SETTING_FIELD (NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE), /* 13 */ - SETTING_FIELD (NM_SETTING_WIRELESS_SECURITY_PSK), /* 14 */ - SETTING_FIELD (NM_SETTING_WIRELESS_SECURITY_PSK_FLAGS), /* 15 */ - SETTING_FIELD (NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD), /* 16 */ - SETTING_FIELD (NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD_FLAGS), /* 17 */ - {NULL, NULL, 0, NULL, FALSE, FALSE, 0} -}; -#define NMC_FIELDS_SETTING_WIRELESS_SECURITY_ALL "name"","\ - NM_SETTING_WIRELESS_SECURITY_KEY_MGMT","\ - NM_SETTING_WIRELESS_SECURITY_WEP_TX_KEYIDX","\ - NM_SETTING_WIRELESS_SECURITY_AUTH_ALG","\ - NM_SETTING_WIRELESS_SECURITY_PROTO","\ - NM_SETTING_WIRELESS_SECURITY_PAIRWISE","\ - NM_SETTING_WIRELESS_SECURITY_GROUP","\ - NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME","\ - NM_SETTING_WIRELESS_SECURITY_WEP_KEY0","\ - NM_SETTING_WIRELESS_SECURITY_WEP_KEY1","\ - NM_SETTING_WIRELESS_SECURITY_WEP_KEY2","\ - NM_SETTING_WIRELESS_SECURITY_WEP_KEY3","\ - NM_SETTING_WIRELESS_SECURITY_WEP_KEY_FLAGS","\ - NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE","\ - NM_SETTING_WIRELESS_SECURITY_PSK","\ - NM_SETTING_WIRELESS_SECURITY_PSK_FLAGS","\ - NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD","\ - NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD_FLAGS - -/* Available fields for NM_SETTING_IP4_CONFIG_SETTING_NAME */ -NmcOutputField nmc_fields_setting_ip4_config[] = { - SETTING_FIELD ("name"), /* 0 */ - SETTING_FIELD (NM_SETTING_IP_CONFIG_METHOD), /* 1 */ - SETTING_FIELD (NM_SETTING_IP_CONFIG_DNS), /* 2 */ - SETTING_FIELD (NM_SETTING_IP_CONFIG_DNS_SEARCH), /* 3 */ - SETTING_FIELD (NM_SETTING_IP_CONFIG_DNS_OPTIONS), /* 4 */ - SETTING_FIELD (NM_SETTING_IP_CONFIG_DNS_PRIORITY), /* 5 */ - SETTING_FIELD (NM_SETTING_IP_CONFIG_ADDRESSES), /* 6 */ - SETTING_FIELD (NM_SETTING_IP_CONFIG_GATEWAY), /* 7 */ - SETTING_FIELD (NM_SETTING_IP_CONFIG_ROUTES), /* 8 */ - SETTING_FIELD (NM_SETTING_IP_CONFIG_ROUTE_METRIC), /* 9 */ - SETTING_FIELD (NM_SETTING_IP_CONFIG_IGNORE_AUTO_ROUTES), /* 10 */ - SETTING_FIELD (NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS), /* 11 */ - SETTING_FIELD (NM_SETTING_IP4_CONFIG_DHCP_CLIENT_ID), /* 12 */ - SETTING_FIELD (NM_SETTING_IP_CONFIG_DHCP_TIMEOUT), /* 13 */ - SETTING_FIELD (NM_SETTING_IP_CONFIG_DHCP_SEND_HOSTNAME), /* 14 */ - SETTING_FIELD (NM_SETTING_IP_CONFIG_DHCP_HOSTNAME), /* 15 */ - SETTING_FIELD (NM_SETTING_IP4_CONFIG_DHCP_FQDN), /* 16 */ - SETTING_FIELD (NM_SETTING_IP_CONFIG_NEVER_DEFAULT), /* 17 */ - SETTING_FIELD (NM_SETTING_IP_CONFIG_MAY_FAIL), /* 18 */ - SETTING_FIELD (NM_SETTING_IP_CONFIG_DAD_TIMEOUT), /* 19 */ - {NULL, NULL, 0, NULL, FALSE, FALSE, 0} -}; -#define NMC_FIELDS_SETTING_IP4_CONFIG_ALL "name"","\ - NM_SETTING_IP_CONFIG_METHOD","\ - NM_SETTING_IP_CONFIG_DNS","\ - NM_SETTING_IP_CONFIG_DNS_SEARCH","\ - NM_SETTING_IP_CONFIG_DNS_OPTIONS","\ - NM_SETTING_IP_CONFIG_DNS_PRIORITY","\ - NM_SETTING_IP_CONFIG_ADDRESSES","\ - NM_SETTING_IP_CONFIG_GATEWAY","\ - NM_SETTING_IP_CONFIG_ROUTES","\ - NM_SETTING_IP_CONFIG_ROUTE_METRIC","\ - NM_SETTING_IP_CONFIG_IGNORE_AUTO_ROUTES","\ - NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS","\ - NM_SETTING_IP4_CONFIG_DHCP_CLIENT_ID","\ - NM_SETTING_IP_CONFIG_DHCP_TIMEOUT","\ - NM_SETTING_IP_CONFIG_DHCP_SEND_HOSTNAME","\ - NM_SETTING_IP_CONFIG_DHCP_HOSTNAME","\ - NM_SETTING_IP4_CONFIG_DHCP_FQDN","\ - NM_SETTING_IP_CONFIG_NEVER_DEFAULT","\ - NM_SETTING_IP_CONFIG_MAY_FAIL","\ - NM_SETTING_IP_CONFIG_DAD_TIMEOUT - -/* Available fields for NM_SETTING_IP6_CONFIG_SETTING_NAME */ -NmcOutputField nmc_fields_setting_ip6_config[] = { - SETTING_FIELD ("name"), /* 0 */ - SETTING_FIELD (NM_SETTING_IP_CONFIG_METHOD), /* 1 */ - SETTING_FIELD (NM_SETTING_IP_CONFIG_DNS), /* 2 */ - SETTING_FIELD (NM_SETTING_IP_CONFIG_DNS_SEARCH), /* 3 */ - SETTING_FIELD (NM_SETTING_IP_CONFIG_DNS_OPTIONS), /* 4 */ - SETTING_FIELD (NM_SETTING_IP_CONFIG_DNS_PRIORITY), /* 5 */ - SETTING_FIELD (NM_SETTING_IP_CONFIG_ADDRESSES), /* 6 */ - SETTING_FIELD (NM_SETTING_IP_CONFIG_GATEWAY), /* 7 */ - SETTING_FIELD (NM_SETTING_IP_CONFIG_ROUTES), /* 8 */ - SETTING_FIELD (NM_SETTING_IP_CONFIG_ROUTE_METRIC), /* 9 */ - SETTING_FIELD (NM_SETTING_IP_CONFIG_IGNORE_AUTO_ROUTES), /* 10 */ - SETTING_FIELD (NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS), /* 11 */ - SETTING_FIELD (NM_SETTING_IP_CONFIG_NEVER_DEFAULT), /* 12 */ - SETTING_FIELD (NM_SETTING_IP_CONFIG_MAY_FAIL), /* 13 */ - SETTING_FIELD (NM_SETTING_IP6_CONFIG_IP6_PRIVACY), /* 14 */ - SETTING_FIELD (NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE), /* 15 */ - SETTING_FIELD (NM_SETTING_IP_CONFIG_DHCP_SEND_HOSTNAME), /* 16 */ - SETTING_FIELD (NM_SETTING_IP_CONFIG_DHCP_HOSTNAME), /* 17 */ - SETTING_FIELD (NM_SETTING_IP6_CONFIG_TOKEN), /* 18 */ - {NULL, NULL, 0, NULL, FALSE, FALSE, 0} -}; -#define NMC_FIELDS_SETTING_IP6_CONFIG_ALL "name"","\ - NM_SETTING_IP_CONFIG_METHOD","\ - NM_SETTING_IP_CONFIG_DNS","\ - NM_SETTING_IP_CONFIG_DNS_SEARCH","\ - NM_SETTING_IP_CONFIG_DNS_OPTIONS","\ - NM_SETTING_IP_CONFIG_DNS_PRIORITY","\ - NM_SETTING_IP_CONFIG_ADDRESSES","\ - NM_SETTING_IP_CONFIG_GATEWAY","\ - NM_SETTING_IP_CONFIG_ROUTES","\ - NM_SETTING_IP_CONFIG_ROUTE_METRIC","\ - NM_SETTING_IP_CONFIG_IGNORE_AUTO_ROUTES","\ - NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS","\ - NM_SETTING_IP_CONFIG_NEVER_DEFAULT","\ - NM_SETTING_IP_CONFIG_MAY_FAIL","\ - NM_SETTING_IP6_CONFIG_IP6_PRIVACY","\ - NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE","\ - NM_SETTING_IP_CONFIG_DHCP_SEND_HOSTNAME","\ - NM_SETTING_IP_CONFIG_DHCP_HOSTNAME","\ - NM_SETTING_IP6_CONFIG_TOKEN - -/* Available fields for NM_SETTING_SERIAL_SETTING_NAME */ -NmcOutputField nmc_fields_setting_serial[] = { - SETTING_FIELD ("name"), /* 0 */ - SETTING_FIELD (NM_SETTING_SERIAL_BAUD), /* 1 */ - SETTING_FIELD (NM_SETTING_SERIAL_BITS), /* 2 */ - SETTING_FIELD (NM_SETTING_SERIAL_PARITY), /* 3 */ - SETTING_FIELD (NM_SETTING_SERIAL_STOPBITS), /* 4 */ - SETTING_FIELD (NM_SETTING_SERIAL_SEND_DELAY), /* 5 */ - {NULL, NULL, 0, NULL, FALSE, FALSE, 0} -}; -#define NMC_FIELDS_SETTING_SERIAL_ALL "name"","\ - NM_SETTING_SERIAL_BAUD","\ - NM_SETTING_SERIAL_BITS","\ - NM_SETTING_SERIAL_PARITY","\ - NM_SETTING_SERIAL_STOPBITS","\ - NM_SETTING_SERIAL_SEND_DELAY - -/* Available fields for NM_SETTING_PPP_SETTING_NAME */ -NmcOutputField nmc_fields_setting_ppp[] = { - SETTING_FIELD ("name"), /* 0 */ - SETTING_FIELD (NM_SETTING_PPP_NOAUTH), /* 1 */ - SETTING_FIELD (NM_SETTING_PPP_REFUSE_EAP), /* 2 */ - SETTING_FIELD (NM_SETTING_PPP_REFUSE_PAP), /* 3 */ - SETTING_FIELD (NM_SETTING_PPP_REFUSE_CHAP), /* 4 */ - SETTING_FIELD (NM_SETTING_PPP_REFUSE_MSCHAP), /* 5 */ - SETTING_FIELD (NM_SETTING_PPP_REFUSE_MSCHAPV2), /* 6 */ - SETTING_FIELD (NM_SETTING_PPP_NOBSDCOMP), /* 7 */ - SETTING_FIELD (NM_SETTING_PPP_NODEFLATE), /* 8 */ - SETTING_FIELD (NM_SETTING_PPP_NO_VJ_COMP), /* 9 */ - SETTING_FIELD (NM_SETTING_PPP_REQUIRE_MPPE), /* 10 */ - SETTING_FIELD (NM_SETTING_PPP_REQUIRE_MPPE_128), /* 11 */ - SETTING_FIELD (NM_SETTING_PPP_MPPE_STATEFUL), /* 12 */ - SETTING_FIELD (NM_SETTING_PPP_CRTSCTS), /* 13 */ - SETTING_FIELD (NM_SETTING_PPP_BAUD), /* 14 */ - SETTING_FIELD (NM_SETTING_PPP_MRU), /* 15 */ - SETTING_FIELD (NM_SETTING_PPP_MTU), /* 16 */ - SETTING_FIELD (NM_SETTING_PPP_LCP_ECHO_FAILURE), /* 17 */ - SETTING_FIELD (NM_SETTING_PPP_LCP_ECHO_INTERVAL), /* 18 */ - {NULL, NULL, 0, NULL, FALSE, FALSE, 0} -}; -#define NMC_FIELDS_SETTING_PPP_ALL "name"","\ - NM_SETTING_PPP_NOAUTH","\ - NM_SETTING_PPP_REFUSE_EAP","\ - NM_SETTING_PPP_REFUSE_PAP","\ - NM_SETTING_PPP_REFUSE_CHAP","\ - NM_SETTING_PPP_REFUSE_MSCHAP","\ - NM_SETTING_PPP_REFUSE_MSCHAPV2","\ - NM_SETTING_PPP_NOBSDCOMP","\ - NM_SETTING_PPP_NODEFLATE","\ - NM_SETTING_PPP_NO_VJ_COMP","\ - NM_SETTING_PPP_REQUIRE_MPPE","\ - NM_SETTING_PPP_REQUIRE_MPPE_128","\ - NM_SETTING_PPP_MPPE_STATEFUL","\ - NM_SETTING_PPP_CRTSCTS","\ - NM_SETTING_PPP_BAUD","\ - NM_SETTING_PPP_MRU","\ - NM_SETTING_PPP_MTU","\ - NM_SETTING_PPP_LCP_ECHO_FAILURE","\ - NM_SETTING_PPP_LCP_ECHO_INTERVAL - -/* Available fields for NM_SETTING_PPPOE_SETTING_NAME */ -NmcOutputField nmc_fields_setting_pppoe[] = { - SETTING_FIELD ("name"), /* 0 */ - SETTING_FIELD (NM_SETTING_PPPOE_SERVICE), /* 1 */ - SETTING_FIELD (NM_SETTING_PPPOE_USERNAME), /* 2 */ - SETTING_FIELD (NM_SETTING_PPPOE_PASSWORD), /* 3 */ - SETTING_FIELD (NM_SETTING_PPPOE_PASSWORD_FLAGS), /* 4 */ - {NULL, NULL, 0, NULL, FALSE, FALSE, 0} -}; -#define NMC_FIELDS_SETTING_PPPOE_ALL "name"","\ - NM_SETTING_PPPOE_SERVICE","\ - NM_SETTING_PPPOE_USERNAME","\ - NM_SETTING_PPPOE_PASSWORD","\ - NM_SETTING_PPPOE_PASSWORD_FLAGS - -/* Available fields for NM_SETTING_ADSL_SETTING_NAME */ -NmcOutputField nmc_fields_setting_adsl[] = { - SETTING_FIELD ("name"), /* 0 */ - SETTING_FIELD (NM_SETTING_ADSL_USERNAME), /* 1 */ - SETTING_FIELD (NM_SETTING_ADSL_PASSWORD), /* 2 */ - SETTING_FIELD (NM_SETTING_ADSL_PASSWORD_FLAGS), /* 3 */ - SETTING_FIELD (NM_SETTING_ADSL_PROTOCOL), /* 4 */ - SETTING_FIELD (NM_SETTING_ADSL_ENCAPSULATION), /* 5 */ - SETTING_FIELD (NM_SETTING_ADSL_VPI), /* 6 */ - SETTING_FIELD (NM_SETTING_ADSL_VCI), /* 7 */ - {NULL, NULL, 0, NULL, FALSE, FALSE, 0} -}; -#define NMC_FIELDS_SETTING_ADSL_ALL "name"","\ - NM_SETTING_ADSL_USERNAME","\ - NM_SETTING_ADSL_PASSWORD","\ - NM_SETTING_ADSL_PASSWORD_FLAGS","\ - NM_SETTING_ADSL_PROTOCOL","\ - NM_SETTING_ADSL_ENCAPSULATION","\ - NM_SETTING_ADSL_VPI","\ - NM_SETTING_ADSL_VCI - -/* Available fields for NM_SETTING_GSM_SETTING_NAME */ -NmcOutputField nmc_fields_setting_gsm[] = { - SETTING_FIELD ("name"), /* 0 */ - SETTING_FIELD (NM_SETTING_GSM_NUMBER), /* 1 */ - SETTING_FIELD (NM_SETTING_GSM_USERNAME), /* 2 */ - SETTING_FIELD (NM_SETTING_GSM_PASSWORD), /* 3 */ - SETTING_FIELD (NM_SETTING_GSM_PASSWORD_FLAGS), /* 4 */ - SETTING_FIELD (NM_SETTING_GSM_APN), /* 5 */ - SETTING_FIELD (NM_SETTING_GSM_NETWORK_ID), /* 6 */ - SETTING_FIELD (NM_SETTING_GSM_PIN), /* 7 */ - SETTING_FIELD (NM_SETTING_GSM_PIN_FLAGS), /* 8 */ - SETTING_FIELD (NM_SETTING_GSM_HOME_ONLY), /* 9 */ - SETTING_FIELD (NM_SETTING_GSM_DEVICE_ID), /* 10 */ - SETTING_FIELD (NM_SETTING_GSM_SIM_ID), /* 11 */ - SETTING_FIELD (NM_SETTING_GSM_SIM_OPERATOR_ID), /* 12 */ - SETTING_FIELD (NM_SETTING_GSM_MTU), /* 13 */ - {NULL, NULL, 0, NULL, FALSE, FALSE, 0} -}; -#define NMC_FIELDS_SETTING_GSM_ALL "name"","\ - NM_SETTING_GSM_NUMBER","\ - NM_SETTING_GSM_USERNAME","\ - NM_SETTING_GSM_PASSWORD","\ - NM_SETTING_GSM_PASSWORD_FLAGS","\ - NM_SETTING_GSM_APN","\ - NM_SETTING_GSM_NETWORK_ID","\ - NM_SETTING_GSM_PIN","\ - NM_SETTING_GSM_PIN_FLAGS","\ - NM_SETTING_GSM_HOME_ONLY","\ - NM_SETTING_GSM_DEVICE_ID","\ - NM_SETTING_GSM_SIM_ID","\ - NM_SETTING_GSM_SIM_OPERATOR_ID","\ - NM_SETTING_GSM_MTU - -/* Available fields for NM_SETTING_CDMA_SETTING_NAME */ -NmcOutputField nmc_fields_setting_cdma[] = { - SETTING_FIELD ("name"), /* 0 */ - SETTING_FIELD (NM_SETTING_CDMA_NUMBER), /* 1 */ - SETTING_FIELD (NM_SETTING_CDMA_USERNAME), /* 2 */ - SETTING_FIELD (NM_SETTING_CDMA_PASSWORD), /* 3 */ - SETTING_FIELD (NM_SETTING_CDMA_PASSWORD_FLAGS), /* 4 */ - SETTING_FIELD (NM_SETTING_CDMA_MTU), /* 5 */ - {NULL, NULL, 0, NULL, FALSE, FALSE, 0} -}; -#define NMC_FIELDS_SETTING_CDMA_ALL "name"","\ - NM_SETTING_CDMA_NUMBER","\ - NM_SETTING_CDMA_USERNAME","\ - NM_SETTING_CDMA_PASSWORD","\ - NM_SETTING_CDMA_PASSWORD_FLAGS","\ - NM_SETTING_CDMA_MTU - -/* Available fields for NM_SETTING_BLUETOOTH_SETTING_NAME */ -NmcOutputField nmc_fields_setting_bluetooth[] = { - SETTING_FIELD ("name"), /* 0 */ - SETTING_FIELD (NM_SETTING_BLUETOOTH_BDADDR), /* 1 */ - SETTING_FIELD (NM_SETTING_BLUETOOTH_TYPE), /* 2 */ - {NULL, NULL, 0, NULL, FALSE, FALSE, 0} -}; -#define NMC_FIELDS_SETTING_BLUETOOTH_ALL "name"","\ - NM_SETTING_BLUETOOTH_BDADDR","\ - NM_SETTING_BLUETOOTH_TYPE - -/* Available fields for NM_SETTING_OLPC_MESH_SETTING_NAME */ -NmcOutputField nmc_fields_setting_olpc_mesh[] = { - SETTING_FIELD ("name"), /* 0 */ - SETTING_FIELD (NM_SETTING_OLPC_MESH_SSID), /* 1 */ - SETTING_FIELD (NM_SETTING_OLPC_MESH_CHANNEL), /* 2 */ - SETTING_FIELD (NM_SETTING_OLPC_MESH_DHCP_ANYCAST_ADDRESS), /* 3 */ - {NULL, NULL, 0, NULL, FALSE, FALSE, 0} -}; -#define NMC_FIELDS_SETTING_OLPC_MESH_ALL "name"","\ - NM_SETTING_OLPC_MESH_SSID","\ - NM_SETTING_OLPC_MESH_CHANNEL","\ - NM_SETTING_OLPC_MESH_DHCP_ANYCAST_ADDRESS - -/* Available fields for NM_SETTING_VPN_SETTING_NAME */ -NmcOutputField nmc_fields_setting_vpn[] = { - SETTING_FIELD ("name"), /* 0 */ - SETTING_FIELD (NM_SETTING_VPN_SERVICE_TYPE), /* 1 */ - SETTING_FIELD (NM_SETTING_VPN_USER_NAME), /* 2 */ - SETTING_FIELD (NM_SETTING_VPN_DATA), /* 3 */ - SETTING_FIELD (NM_SETTING_VPN_SECRETS), /* 4 */ - SETTING_FIELD (NM_SETTING_VPN_PERSISTENT), /* 5 */ - SETTING_FIELD (NM_SETTING_VPN_TIMEOUT), /* 6 */ - {NULL, NULL, 0, NULL, FALSE, FALSE, 0} -}; -#define NMC_FIELDS_SETTING_VPN_ALL "name"","\ - NM_SETTING_VPN_SERVICE_TYPE","\ - NM_SETTING_VPN_USER_NAME","\ - NM_SETTING_VPN_DATA","\ - NM_SETTING_VPN_SECRETS","\ - NM_SETTING_VPN_PERSISTENT","\ - NM_SETTING_VPN_TIMEOUT - -/* Available fields for NM_SETTING_WIMAX_SETTING_NAME */ -NmcOutputField nmc_fields_setting_wimax[] = { - SETTING_FIELD ("name"), /* 0 */ - SETTING_FIELD (NM_SETTING_WIMAX_MAC_ADDRESS), /* 1 */ - SETTING_FIELD (NM_SETTING_WIMAX_NETWORK_NAME), /* 2 */ - {NULL, NULL, 0, NULL, FALSE, FALSE, 0} -}; -#define NMC_FIELDS_SETTING_WIMAX_ALL "name"","\ - NM_SETTING_WIMAX_MAC_ADDRESS","\ - NM_SETTING_WIMAX_NETWORK_NAME - -/* Available fields for NM_SETTING_INFINIBAND_SETTING_NAME */ -NmcOutputField nmc_fields_setting_infiniband[] = { - SETTING_FIELD ("name"), /* 0 */ - SETTING_FIELD (NM_SETTING_INFINIBAND_MAC_ADDRESS), /* 1 */ - SETTING_FIELD (NM_SETTING_INFINIBAND_MTU), /* 2 */ - SETTING_FIELD (NM_SETTING_INFINIBAND_TRANSPORT_MODE), /* 3 */ - SETTING_FIELD (NM_SETTING_INFINIBAND_P_KEY), /* 4 */ - SETTING_FIELD (NM_SETTING_INFINIBAND_PARENT), /* 5 */ - {NULL, NULL, 0, NULL, FALSE, FALSE, 0} -}; -#define NMC_FIELDS_SETTING_INFINIBAND_ALL "name"","\ - NM_SETTING_INFINIBAND_MAC_ADDRESS","\ - NM_SETTING_INFINIBAND_MTU"," \ - NM_SETTING_INFINIBAND_TRANSPORT_MODE"," \ - NM_SETTING_INFINIBAND_P_KEY"," \ - NM_SETTING_INFINIBAND_PARENT - -/* Available fields for NM_SETTING_BOND_SETTING_NAME */ -NmcOutputField nmc_fields_setting_bond[] = { - SETTING_FIELD ("name"), /* 0 */ - SETTING_FIELD (NM_SETTING_BOND_OPTIONS), /* 1 */ - {NULL, NULL, 0, NULL, FALSE, FALSE, 0} -}; -#define NMC_FIELDS_SETTING_BOND_ALL "name"","\ - NM_SETTING_BOND_OPTIONS - -/* Available fields for NM_SETTING_VLAN_SETTING_NAME */ -NmcOutputField nmc_fields_setting_vlan[] = { - SETTING_FIELD ("name"), /* 0 */ - SETTING_FIELD (NM_SETTING_VLAN_PARENT), /* 1 */ - SETTING_FIELD (NM_SETTING_VLAN_ID), /* 2 */ - SETTING_FIELD (NM_SETTING_VLAN_FLAGS), /* 3 */ - SETTING_FIELD (NM_SETTING_VLAN_INGRESS_PRIORITY_MAP), /* 4 */ - SETTING_FIELD (NM_SETTING_VLAN_EGRESS_PRIORITY_MAP), /* 5 */ - {NULL, NULL, 0, NULL, FALSE, FALSE, 0} -}; -#define NMC_FIELDS_SETTING_VLAN_ALL "name"","\ - NM_SETTING_VLAN_PARENT","\ - NM_SETTING_VLAN_ID","\ - NM_SETTING_VLAN_FLAGS","\ - NM_SETTING_VLAN_INGRESS_PRIORITY_MAP","\ - NM_SETTING_VLAN_EGRESS_PRIORITY_MAP - -/* Available fields for NM_SETTING_BRIDGE_SETTING_NAME */ -NmcOutputField nmc_fields_setting_bridge[] = { - SETTING_FIELD ("name"), /* 0 */ - SETTING_FIELD (NM_SETTING_BRIDGE_MAC_ADDRESS), /* 1 */ - SETTING_FIELD (NM_SETTING_BRIDGE_STP), /* 2 */ - SETTING_FIELD (NM_SETTING_BRIDGE_PRIORITY), /* 3 */ - SETTING_FIELD (NM_SETTING_BRIDGE_FORWARD_DELAY), /* 4 */ - SETTING_FIELD (NM_SETTING_BRIDGE_HELLO_TIME), /* 5 */ - SETTING_FIELD (NM_SETTING_BRIDGE_MAX_AGE), /* 6 */ - SETTING_FIELD (NM_SETTING_BRIDGE_AGEING_TIME), /* 7 */ - SETTING_FIELD (NM_SETTING_BRIDGE_MULTICAST_SNOOPING), /* 8 */ - {NULL, NULL, 0, NULL, FALSE, FALSE, 0} -}; -#define NMC_FIELDS_SETTING_BRIDGE_ALL "name"","\ - NM_SETTING_BRIDGE_MAC_ADDRESS","\ - NM_SETTING_BRIDGE_STP","\ - NM_SETTING_BRIDGE_PRIORITY","\ - NM_SETTING_BRIDGE_FORWARD_DELAY","\ - NM_SETTING_BRIDGE_HELLO_TIME","\ - NM_SETTING_BRIDGE_MAX_AGE","\ - NM_SETTING_BRIDGE_AGEING_TIME","\ - NM_SETTING_BRIDGE_MULTICAST_SNOOPING - -/* Available fields for NM_SETTING_BRIDGE_PORT_SETTING_NAME */ -NmcOutputField nmc_fields_setting_bridge_port[] = { - SETTING_FIELD ("name"), /* 0 */ - SETTING_FIELD (NM_SETTING_BRIDGE_PORT_PRIORITY), /* 1 */ - SETTING_FIELD (NM_SETTING_BRIDGE_PORT_PATH_COST), /* 2 */ - SETTING_FIELD (NM_SETTING_BRIDGE_PORT_HAIRPIN_MODE), /* 3 */ - {NULL, NULL, 0, NULL, FALSE, FALSE, 0} -}; -#define NMC_FIELDS_SETTING_BRIDGE_PORT_ALL "name"","\ - NM_SETTING_BRIDGE_PORT_PRIORITY","\ - NM_SETTING_BRIDGE_PORT_PATH_COST","\ - NM_SETTING_BRIDGE_PORT_HAIRPIN_MODE - -/* Available fields for NM_SETTING_TEAM_SETTING_NAME */ -NmcOutputField nmc_fields_setting_team[] = { - SETTING_FIELD ("name"), /* 0 */ - SETTING_FIELD (NM_SETTING_TEAM_CONFIG), /* 1 */ - {NULL, NULL, 0, NULL, FALSE, FALSE, 0} -}; -#define NMC_FIELDS_SETTING_TEAM_ALL "name"","\ - NM_SETTING_TEAM_CONFIG - -/* Available fields for NM_SETTING_TEAM_PORT_SETTING_NAME */ -NmcOutputField nmc_fields_setting_team_port[] = { - SETTING_FIELD ("name"), /* 0 */ - SETTING_FIELD (NM_SETTING_TEAM_PORT_CONFIG), /* 1 */ - {NULL, NULL, 0, NULL, FALSE, FALSE, 0} -}; -#define NMC_FIELDS_SETTING_TEAM_PORT_ALL "name"","\ - NM_SETTING_TEAM_PORT_CONFIG - -/* Available fields for NM_SETTING_DCB_SETTING_NAME */ -NmcOutputField nmc_fields_setting_dcb[] = { - SETTING_FIELD ("name"), /* 0 */ - SETTING_FIELD (NM_SETTING_DCB_APP_FCOE_FLAGS), /* 1 */ - SETTING_FIELD (NM_SETTING_DCB_APP_FCOE_PRIORITY), /* 2 */ - SETTING_FIELD (NM_SETTING_DCB_APP_FCOE_MODE), /* 3 */ - SETTING_FIELD (NM_SETTING_DCB_APP_ISCSI_FLAGS), /* 4 */ - SETTING_FIELD (NM_SETTING_DCB_APP_ISCSI_PRIORITY), /* 5 */ - SETTING_FIELD (NM_SETTING_DCB_APP_FIP_FLAGS), /* 6 */ - SETTING_FIELD (NM_SETTING_DCB_APP_FIP_PRIORITY), /* 7 */ - SETTING_FIELD (NM_SETTING_DCB_PRIORITY_FLOW_CONTROL_FLAGS), /* 8 */ - SETTING_FIELD (NM_SETTING_DCB_PRIORITY_FLOW_CONTROL), /* 9 */ - SETTING_FIELD (NM_SETTING_DCB_PRIORITY_GROUP_FLAGS), /* 10 */ - SETTING_FIELD (NM_SETTING_DCB_PRIORITY_GROUP_ID), /* 11 */ - SETTING_FIELD (NM_SETTING_DCB_PRIORITY_GROUP_BANDWIDTH), /* 12 */ - SETTING_FIELD (NM_SETTING_DCB_PRIORITY_BANDWIDTH), /* 13 */ - SETTING_FIELD (NM_SETTING_DCB_PRIORITY_STRICT_BANDWIDTH), /* 14 */ - SETTING_FIELD (NM_SETTING_DCB_PRIORITY_TRAFFIC_CLASS), /* 15 */ - {NULL, NULL, 0, NULL, FALSE, FALSE, 0} -}; -#define NMC_FIELDS_SETTING_DCB_ALL "name"","\ - NM_SETTING_DCB_APP_FCOE_FLAGS","\ - NM_SETTING_DCB_APP_FCOE_PRIORITY","\ - NM_SETTING_DCB_APP_FCOE_MODE","\ - NM_SETTING_DCB_APP_ISCSI_FLAGS","\ - NM_SETTING_DCB_APP_ISCSI_PRIORITY","\ - NM_SETTING_DCB_APP_FIP_FLAGS","\ - NM_SETTING_DCB_APP_FIP_PRIORITY","\ - NM_SETTING_DCB_PRIORITY_FLOW_CONTROL_FLAGS","\ - NM_SETTING_DCB_PRIORITY_FLOW_CONTROL","\ - NM_SETTING_DCB_PRIORITY_GROUP_FLAGS","\ - NM_SETTING_DCB_PRIORITY_GROUP_ID","\ - NM_SETTING_DCB_PRIORITY_GROUP_BANDWIDTH","\ - NM_SETTING_DCB_PRIORITY_BANDWIDTH","\ - NM_SETTING_DCB_PRIORITY_STRICT_BANDWIDTH","\ - NM_SETTING_DCB_PRIORITY_TRAFFIC_CLASS - -/* Available fields for NM_SETTING_DUMMY_SETTING_NAME */ -NmcOutputField nmc_fields_setting_dummy[] = { - SETTING_FIELD ("name"), /* 0 */ - {NULL, NULL, 0, NULL, FALSE, FALSE, 0} -}; -#define NMC_FIELDS_SETTING_DUMMY_ALL "name" - -/* Available fields for NM_SETTING_TUN_SETTING_NAME */ -NmcOutputField nmc_fields_setting_tun[] = { - SETTING_FIELD ("name"), /* 0 */ - SETTING_FIELD (NM_SETTING_TUN_MODE), /* 1 */ - SETTING_FIELD (NM_SETTING_TUN_OWNER), /* 2 */ - SETTING_FIELD (NM_SETTING_TUN_GROUP), /* 3 */ - SETTING_FIELD (NM_SETTING_TUN_PI), /* 4 */ - SETTING_FIELD (NM_SETTING_TUN_VNET_HDR), /* 5 */ - SETTING_FIELD (NM_SETTING_TUN_MULTI_QUEUE), /* 6 */ - {NULL, NULL, 0, NULL, FALSE, FALSE, 0} -}; -#define NMC_FIELDS_SETTING_TUN_ALL "name"","\ - NM_SETTING_TUN_MODE","\ - NM_SETTING_TUN_OWNER","\ - NM_SETTING_TUN_GROUP","\ - NM_SETTING_TUN_PI","\ - NM_SETTING_TUN_VNET_HDR","\ - NM_SETTING_TUN_MULTI_QUEUE - -/* Available fields for NM_SETTING_IP_TUNNEL_SETTING_NAME */ -NmcOutputField nmc_fields_setting_ip_tunnel[] = { - SETTING_FIELD ("name"), /* 0 */ - SETTING_FIELD (NM_SETTING_IP_TUNNEL_MODE), /* 1 */ - SETTING_FIELD (NM_SETTING_IP_TUNNEL_PARENT), /* 2 */ - SETTING_FIELD (NM_SETTING_IP_TUNNEL_LOCAL), /* 3 */ - SETTING_FIELD (NM_SETTING_IP_TUNNEL_REMOTE), /* 4 */ - SETTING_FIELD (NM_SETTING_IP_TUNNEL_TTL), /* 5 */ - SETTING_FIELD (NM_SETTING_IP_TUNNEL_TOS), /* 6 */ - SETTING_FIELD (NM_SETTING_IP_TUNNEL_PATH_MTU_DISCOVERY), /* 7 */ - SETTING_FIELD (NM_SETTING_IP_TUNNEL_INPUT_KEY), /* 8 */ - SETTING_FIELD (NM_SETTING_IP_TUNNEL_OUTPUT_KEY), /* 9 */ - SETTING_FIELD (NM_SETTING_IP_TUNNEL_ENCAPSULATION_LIMIT), /* 10 */ - SETTING_FIELD (NM_SETTING_IP_TUNNEL_FLOW_LABEL), /* 11 */ - SETTING_FIELD (NM_SETTING_IP_TUNNEL_MTU), /* 12 */ - {NULL, NULL, 0, NULL, FALSE, FALSE, 0} -}; -#define NMC_FIELDS_SETTING_IP_TUNNEL_ALL "name"","\ - NM_SETTING_IP_TUNNEL_MODE","\ - NM_SETTING_IP_TUNNEL_PARENT","\ - NM_SETTING_IP_TUNNEL_LOCAL","\ - NM_SETTING_IP_TUNNEL_REMOTE","\ - NM_SETTING_IP_TUNNEL_TTL","\ - NM_SETTING_IP_TUNNEL_TOS","\ - NM_SETTING_IP_TUNNEL_PATH_MTU_DISCOVERY","\ - NM_SETTING_IP_TUNNEL_INPUT_KEY","\ - NM_SETTING_IP_TUNNEL_OUTPUT_KEY","\ - NM_SETTING_IP_TUNNEL_ENCAPSULATION_LIMIT","\ - NM_SETTING_IP_TUNNEL_FLOW_LABEL","\ - NM_SETTING_IP_TUNNEL_MTU - -/* Available fields for NM_SETTING_MACSEC_SETTING_NAME */ -NmcOutputField nmc_fields_setting_macsec[] = { - SETTING_FIELD ("name"), /* 0 */ - SETTING_FIELD (NM_SETTING_MACSEC_PARENT), /* 1 */ - SETTING_FIELD (NM_SETTING_MACSEC_MODE), /* 2 */ - SETTING_FIELD (NM_SETTING_MACSEC_ENCRYPT), /* 3 */ - SETTING_FIELD (NM_SETTING_MACSEC_MKA_CAK), /* 4 */ - SETTING_FIELD (NM_SETTING_MACSEC_MKA_CAK_FLAGS), /* 5 */ - SETTING_FIELD (NM_SETTING_MACSEC_MKA_CKN), /* 6 */ - SETTING_FIELD (NM_SETTING_MACSEC_PORT), /* 7 */ - SETTING_FIELD (NM_SETTING_MACSEC_VALIDATION), /* 8 */ - {NULL, NULL, 0, NULL, FALSE, FALSE, 0} -}; -#define NMC_FIELDS_SETTING_MACSEC_ALL "name"","\ - NM_SETTING_MACSEC_PARENT","\ - NM_SETTING_MACSEC_MODE","\ - NM_SETTING_MACSEC_ENCRYPT","\ - NM_SETTING_MACSEC_MKA_CAK","\ - NM_SETTING_MACSEC_MKA_CAK_FLAGS","\ - NM_SETTING_MACSEC_MKA_CKN","\ - NM_SETTING_MACSEC_PORT","\ - NM_SETTING_MACSEC_VALIDATION - -/* Available fields for NM_SETTING_MACVLAN_SETTING_NAME */ -NmcOutputField nmc_fields_setting_macvlan[] = { - SETTING_FIELD ("name"), /* 0 */ - SETTING_FIELD (NM_SETTING_MACVLAN_PARENT), /* 1 */ - SETTING_FIELD (NM_SETTING_MACVLAN_MODE), /* 2 */ - SETTING_FIELD (NM_SETTING_MACVLAN_PROMISCUOUS), /* 3 */ - SETTING_FIELD (NM_SETTING_MACVLAN_TAP), /* 4 */ - {NULL, NULL, 0, NULL, FALSE, FALSE, 0} -}; -#define NMC_FIELDS_SETTING_MACVLAN_ALL "name"","\ - NM_SETTING_MACVLAN_PARENT","\ - NM_SETTING_MACVLAN_MODE","\ - NM_SETTING_MACVLAN_PROMISCUOUS","\ - NM_SETTING_MACVLAN_TAP - -/* Available fields for NM_SETTING_VXLAN_SETTING_NAME */ -NmcOutputField nmc_fields_setting_vxlan[] = { - SETTING_FIELD ("name"), /* 0 */ - SETTING_FIELD (NM_SETTING_VXLAN_PARENT), /* 1 */ - SETTING_FIELD (NM_SETTING_VXLAN_ID), /* 2 */ - SETTING_FIELD (NM_SETTING_VXLAN_LOCAL), /* 3 */ - SETTING_FIELD (NM_SETTING_VXLAN_REMOTE), /* 4 */ - SETTING_FIELD (NM_SETTING_VXLAN_SOURCE_PORT_MIN), /* 5 */ - SETTING_FIELD (NM_SETTING_VXLAN_SOURCE_PORT_MAX), /* 6 */ - SETTING_FIELD (NM_SETTING_VXLAN_DESTINATION_PORT), /* 7 */ - SETTING_FIELD (NM_SETTING_VXLAN_TOS), /* 8 */ - SETTING_FIELD (NM_SETTING_VXLAN_TTL), /* 9 */ - SETTING_FIELD (NM_SETTING_VXLAN_AGEING), /* 10 */ - SETTING_FIELD (NM_SETTING_VXLAN_LIMIT), /* 11 */ - SETTING_FIELD (NM_SETTING_VXLAN_LEARNING), /* 12 */ - SETTING_FIELD (NM_SETTING_VXLAN_PROXY), /* 13 */ - SETTING_FIELD (NM_SETTING_VXLAN_RSC), /* 14 */ - SETTING_FIELD (NM_SETTING_VXLAN_L2_MISS), /* 15 */ - SETTING_FIELD (NM_SETTING_VXLAN_L3_MISS), /* 16 */ - {NULL, NULL, 0, NULL, FALSE, FALSE, 0} -}; -#define NMC_FIELDS_SETTING_VXLAN_ALL "name"","\ - NM_SETTING_VXLAN_PARENT","\ - NM_SETTING_VXLAN_ID","\ - NM_SETTING_VXLAN_LOCAL","\ - NM_SETTING_VXLAN_REMOTE","\ - NM_SETTING_VXLAN_SOURCE_PORT_MIN","\ - NM_SETTING_VXLAN_SOURCE_PORT_MAX","\ - NM_SETTING_VXLAN_DESTINATION_PORT","\ - NM_SETTING_VXLAN_TOS","\ - NM_SETTING_VXLAN_TTL","\ - NM_SETTING_VXLAN_AGEING","\ - NM_SETTING_VXLAN_LIMIT","\ - NM_SETTING_VXLAN_LEARNING","\ - NM_SETTING_VXLAN_PROXY","\ - NM_SETTING_VXLAN_RSC","\ - NM_SETTING_VXLAN_L2_MISS","\ - NM_SETTING_VXLAN_L3_MISS - -/* Available fields for NM_SETTING_PROXY_SETTING_NAME */ -NmcOutputField nmc_fields_setting_proxy[] = { - SETTING_FIELD ("name"), /* 0 */ - SETTING_FIELD (NM_SETTING_PROXY_METHOD), /* 1 */ - SETTING_FIELD (NM_SETTING_PROXY_BROWSER_ONLY), /* 2 */ - SETTING_FIELD (NM_SETTING_PROXY_PAC_URL), /* 3 */ - SETTING_FIELD (NM_SETTING_PROXY_PAC_SCRIPT), /* 4 */ - {NULL, NULL, 0, NULL, FALSE, FALSE, 0} -}; -#define NMC_FIELDS_SETTING_PROXY_ALL "name"","\ - NM_SETTING_PROXY_METHOD","\ - NM_SETTING_PROXY_BROWSER_ONLY","\ - NM_SETTING_PROXY_PAC_URL","\ - NM_SETTING_PROXY_PAC_SCRIPT -/*----------------------------------------------------------------------------*/ -static char * -wep_key_type_to_string (NMWepKeyType type) -{ - switch (type) { - case NM_WEP_KEY_TYPE_KEY: - return g_strdup_printf (_("%d (key)"), type); - case NM_WEP_KEY_TYPE_PASSPHRASE: - return g_strdup_printf (_("%d (passphrase)"), type); - case NM_WEP_KEY_TYPE_UNKNOWN: - default: - return g_strdup_printf (_("%d (unknown)"), type); - } -} - -static char * -bytes_to_string (GBytes *bytes) -{ - const guint8 *data; - gsize len; - GString *cert = NULL; - int i; - - if (!bytes) - return NULL; - data = g_bytes_get_data (bytes, &len); - - cert = g_string_new (NULL); - for (i = 0; i < len; i++) - g_string_append_printf (cert, "%02X", data[i]); - - return g_string_free (cert, FALSE); -} - -static char * -vlan_flags_to_string (guint32 flags, NmcPropertyGetType get_type) -{ - GString *flag_str; - - if (get_type == NMC_PROPERTY_GET_PARSABLE) - return g_strdup_printf ("%u", flags); - - if (flags == 0) - return g_strdup (_("0 (NONE)")); - - flag_str = g_string_new (NULL); - g_string_printf (flag_str, "%d (", flags); - - if (flags & NM_VLAN_FLAG_REORDER_HEADERS) - g_string_append (flag_str, _("REORDER_HEADERS, ")); - if (flags & NM_VLAN_FLAG_GVRP) - g_string_append (flag_str, _("GVRP, ")); - if (flags & NM_VLAN_FLAG_LOOSE_BINDING) - g_string_append (flag_str, _("LOOSE_BINDING, ")); - if (flags & NM_VLAN_FLAG_MVRP) - g_string_append (flag_str, _("MVRP, ")); - - if (flag_str->str[flag_str->len-1] == '(') - g_string_append (flag_str, _("unknown")); - else - g_string_truncate (flag_str, flag_str->len-2); /* chop off trailing ', ' */ - - g_string_append_c (flag_str, ')'); - - return g_string_free (flag_str, FALSE); -} - -static char * -vlan_priorities_to_string (NMSettingVlan *s_vlan, NMVlanPriorityMap map) -{ - GString *priorities; - int i; - - priorities = g_string_new (NULL); - for (i = 0; i < nm_setting_vlan_get_num_priorities (s_vlan, map); i++) { - guint32 from, to; - - if (nm_setting_vlan_get_priority (s_vlan, map, i, &from, &to)) - g_string_append_printf (priorities, "%d:%d,", from, to); - } - if (priorities->len) - g_string_truncate (priorities, priorities->len-1); /* chop off trailing ',' */ - - return g_string_free (priorities, FALSE); -} - -static char * -ip6_privacy_to_string (NMSettingIP6ConfigPrivacy ip6_privacy, NmcPropertyGetType get_type) -{ - if (get_type == NMC_PROPERTY_GET_PARSABLE) - 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 * -autoconnect_slaves_to_string (NMSettingConnectionAutoconnectSlaves autoconnect_slaves, - NmcPropertyGetType get_type) -{ - if (get_type == NMC_PROPERTY_GET_PARSABLE) - return g_strdup_printf ("%d", autoconnect_slaves); - - switch (autoconnect_slaves) { - case NM_SETTING_CONNECTION_AUTOCONNECT_SLAVES_NO: - return g_strdup_printf (_("%d (no)"), autoconnect_slaves); - case NM_SETTING_CONNECTION_AUTOCONNECT_SLAVES_YES: - return g_strdup_printf (_("%d (yes)"), autoconnect_slaves); - case NM_SETTING_CONNECTION_AUTOCONNECT_SLAVES_DEFAULT: - default: - return g_strdup_printf (_("%d (default)"), autoconnect_slaves); - } -} - -static char * -secret_flags_to_string (guint32 flags, NmcPropertyGetType get_type) -{ - GString *flag_str; - - if (get_type == NMC_PROPERTY_GET_PARSABLE) - return g_strdup_printf ("%u", flags); - - if (flags == 0) - return g_strdup (_("0 (none)")); - - flag_str = g_string_new (NULL); - g_string_printf (flag_str, "%u (", flags); - - if (flags & NM_SETTING_SECRET_FLAG_AGENT_OWNED) - g_string_append (flag_str, _("agent-owned, ")); - if (flags & NM_SETTING_SECRET_FLAG_NOT_SAVED) - g_string_append (flag_str, _("not saved, ")); - if (flags & NM_SETTING_SECRET_FLAG_NOT_REQUIRED) - g_string_append (flag_str, _("not required, ")); - - if (flag_str->str[flag_str->len-1] == '(') - g_string_append (flag_str, _("unknown")); - else - g_string_truncate (flag_str, flag_str->len-2); /* chop off trailing ', ' */ - - g_string_append_c (flag_str, ')'); - - return g_string_free (flag_str, FALSE); -} - -static void -vpn_data_item (const char *key, const char *value, gpointer user_data) -{ - GString *ret_str = (GString *) user_data; - - if (ret_str->len != 0) - g_string_append (ret_str, ", "); - - g_string_append_printf (ret_str, "%s = %s", key, value); -} - - -/* generic helper macros for property functions */ -#define DEFINE_GETTER(func_name, property_name) \ - static char * \ - func_name (NMSetting *setting, NmcPropertyGetType get_type) \ - { \ - char *s; \ - GValue val = G_VALUE_INIT; \ - g_value_init (&val, G_TYPE_STRING); \ - g_object_get_property (G_OBJECT (setting), property_name, &val); \ - s = g_value_dup_string (&val); \ - g_value_unset (&val); \ - return s; \ - } - -#define DEFINE_GETTER_WITH_DEFAULT(func_name, property_name, check_is_default) \ - static char * \ - func_name (NMSetting *setting, NmcPropertyGetType get_type) \ - { \ - const char *s; \ - char *s_full; \ - GValue val = G_VALUE_INIT; \ - \ - if ((check_is_default)) { \ - if (get_type == NMC_PROPERTY_GET_PARSABLE) \ - return g_strdup (""); \ - return g_strdup (_("(default)")); \ - } \ - \ - g_value_init (&val, G_TYPE_STRING); \ - g_object_get_property (G_OBJECT (setting), property_name, &val); \ - s = g_value_get_string (&val); \ - if (get_type == NMC_PROPERTY_GET_PARSABLE) \ - s_full = g_strdup (s && *s ? s : " "); \ - else \ - s_full = s ? g_strdup_printf ("\"%s\"", s) : g_strdup (""); \ - g_value_unset (&val); \ - return s_full; \ - } - -#define DEFINE_SECRET_FLAGS_GETTER(func_name, property_name) \ - static char * \ - func_name (NMSetting *setting, NmcPropertyGetType get_type) \ - { \ - guint v; \ - GValue val = G_VALUE_INIT; \ - g_value_init (&val, G_TYPE_UINT); \ - g_object_get_property (G_OBJECT (setting), property_name, &val); \ - v = g_value_get_uint (&val); \ - g_value_unset (&val); \ - return secret_flags_to_string (v, get_type); \ - } - -#define DEFINE_SETTER_STR_LIST_MULTI(def_func, s_macro, set_func) \ - static gboolean \ - def_func (NMSetting *setting, \ - const char *prop, \ - const char *val, \ - const char **valid_strv, \ - GError **error) \ - { \ - char **strv = NULL, **iter; \ - const char *item; \ - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); \ - strv = nmc_strsplit_set (val, " \t,", 0); \ - for (iter = strv; iter && *iter; iter++) { \ - if (!(item = nmc_string_is_valid (g_strstrip (*iter), valid_strv, error))) { \ - g_strfreev (strv); \ - return FALSE; \ - } \ - set_func (s_macro (setting), item); \ - } \ - g_strfreev (strv); \ - return TRUE; \ - } - -#define DEFINE_SETTER_OPTIONS(def_func, s_macro, s_type, add_func, valid_func1, valid_func2) \ - static gboolean \ - def_func (NMSetting *setting, const char *prop, const char *val, GError **error) \ - { \ - char **strv = NULL, **iter; \ - const char **(*valid_func1_p) (s_type *) = valid_func1; \ - const char * (*valid_func2_p) (const char *, const char *, GError **) = valid_func2; \ - const char *opt_name, *opt_val; \ - \ - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); \ - \ - strv = nmc_strsplit_set (val, ",", 0); \ - for (iter = strv; iter && *iter; iter++) { \ - char *left = g_strstrip (*iter); \ - 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'; \ - \ - 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); \ - return FALSE; \ - } \ - } else \ - opt_name = g_strstrip (left);\ - \ - opt_val = g_strstrip (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; \ - } - -#define DEFINE_REMOVER_INDEX(def_func, s_macro, num_func, rem_func) \ - static gboolean \ - def_func (NMSetting *setting, const char *prop, const char *option, guint32 idx, GError **error) \ - { \ - guint32 num; \ - if (option) { \ - g_set_error (error, 1, 0, _("index '%s' is not valid"), option); \ - return FALSE; \ - } \ - num = num_func (s_macro (setting)); \ - if (num == 0) { \ - g_set_error_literal (error, 1, 0, _("no item to remove")); \ - return FALSE; \ - } \ - if (idx >= num) { \ - g_set_error (error, 1, 0, _("index '%d' is not in range <0-%d>"), idx, num - 1); \ - return FALSE; \ - } \ - rem_func (s_macro (setting), idx); \ - return TRUE; \ - } - -#define DEFINE_REMOVER_INDEX_OR_VALUE(def_func, s_macro, num_func, rem_func_idx, rem_func_val) \ - static gboolean \ - def_func (NMSetting *setting, const char *prop, const char *value, guint32 idx, GError **error) \ - { \ - guint32 num; \ - if (value) { \ - gboolean ret; \ - char *value_stripped = g_strstrip (g_strdup (value)); \ - ret = rem_func_val (s_macro (setting), value_stripped, error); \ - g_free (value_stripped); \ - return ret; \ - } \ - num = num_func (s_macro (setting)); \ - if (num == 0) { \ - g_set_error_literal (error, 1, 0, _("no item to remove")); \ - return FALSE; \ - } \ - if (idx >= num) { \ - g_set_error (error, 1, 0, _("index '%d' is not in range <0-%d>"), idx, num - 1); \ - return FALSE; \ - } \ - rem_func_idx (s_macro (setting), idx); \ - return TRUE; \ - } - -#define DEFINE_REMOVER_OPTION(def_func, s_macro, rem_func) \ - static gboolean \ - def_func (NMSetting *setting, const char *prop, const char *option, guint32 idx, GError **error) \ - { \ - gboolean success = FALSE; \ - if (option && *option) { \ - success = rem_func (s_macro (setting), option); \ - if (!success) \ - g_set_error (error, 1, 0, _("invalid option '%s'"), option); \ - } else \ - g_set_error_literal (error, 1, 0, _("missing option")); \ - return success; \ - } - -#define DEFINE_ALLOWED_VAL_FUNC(def_func, valid_values) \ - static const char ** \ - def_func (NMSetting *setting, const char *prop) \ - { \ - return valid_values; \ - } - -#define DEFINE_ALLOWED_FOR_ENUMS(def_func, get_type_func, min, max) \ - static const char ** \ - def_func (NMSetting *setting, const char *prop) \ - { \ - static const char **words = NULL; \ - if (G_UNLIKELY (!words)) \ - words = nm_utils_enum_get_values (get_type_func(), min, max); \ - return words; \ - } - -#define DEFINE_SETTER_MAC_BLACKLIST(def_func, s_macro, add_func) \ - static gboolean \ - def_func (NMSetting *setting, const char *prop, const char *val, GError **error) \ - { \ - guint8 buf[32]; \ - char **list = NULL, **iter; \ - GSList *macaddr_blacklist = NULL; \ - \ - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); \ - \ - list = nmc_strsplit_set (val, " \t,", 0); \ - for (iter = list; iter && *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++) \ - add_func (s_macro (setting), *iter); \ - \ - g_strfreev (list); \ - return TRUE; \ - } - - -static gboolean -verify_string_list (char **strv, - const char *prop, - gboolean (*validate_func) (const char *), - GError **error) -{ - char **iter; - - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - - 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; - } - } - } - return TRUE; -} - -/* Validate 'val' number against to int property spec */ -static gboolean -validate_int (NMSetting *setting, const char* prop, gint val, GError **error) -{ - GParamSpec *pspec; - GValue value = G_VALUE_INIT; - gboolean success = TRUE; - - g_value_init (&value, G_TYPE_INT); - g_value_set_int (&value, val); - pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (G_OBJECT (setting)), prop); - g_assert (G_IS_PARAM_SPEC (pspec)); - if (g_param_value_validate (pspec, &value)) { - GParamSpecInt *pspec_int = (GParamSpecInt *) pspec; - g_set_error (error, 1, 0, _("'%d' is not valid; use <%d-%d>"), - val, pspec_int->minimum, pspec_int->maximum); - success = FALSE; - } - g_value_unset (&value); - return success; -} - -static gboolean -validate_int64 (NMSetting *setting, const char* prop, gint64 val, GError **error) -{ - GParamSpec *pspec; - GValue value = G_VALUE_INIT; - gboolean success = TRUE; - - g_value_init (&value, G_TYPE_INT64); - g_value_set_int64 (&value, val); - pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (G_OBJECT (setting)), prop); - g_assert (G_IS_PARAM_SPEC (pspec)); - if (g_param_value_validate (pspec, &value)) { - GParamSpecInt64 *pspec_int = (GParamSpecInt64 *) pspec; - G_STATIC_ASSERT (sizeof (long long) >= sizeof (gint64)); - g_set_error (error, 1, 0, _("'%lld' is not valid; use <%lld-%lld>"), - (long long) val, (long long) pspec_int->minimum, (long long) pspec_int->maximum); - success = FALSE; - } - g_value_unset (&value); - return success; -} - -/* Validate 'val' number against to uint property spec */ -static gboolean -validate_uint (NMSetting *setting, const char* prop, guint val, GError **error) -{ - GParamSpec *pspec; - GValue value = G_VALUE_INIT; - gboolean success = TRUE; - - g_value_init (&value, G_TYPE_UINT); - g_value_set_uint (&value, val); - pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (G_OBJECT (setting)), prop); - g_assert (G_IS_PARAM_SPEC (pspec)); - if (g_param_value_validate (pspec, &value)) { - GParamSpecUInt *pspec_uint = (GParamSpecUInt *) pspec; - g_set_error (error, 1, 0, _("'%u' is not valid; use <%u-%u>"), - val, pspec_uint->minimum, pspec_uint->maximum); - success = FALSE; - } - g_value_unset (&value); - return success; -} - -static char * -flag_values_to_string (GFlagsValue *array, guint n) -{ - GString *str; - guint i; - - str = g_string_new (NULL); - for (i = 0; i < n; i++) - g_string_append_printf (str, "%u, ", array[i].value); - if (str->len) - g_string_truncate (str, str->len-2); /* chop off trailing ', ' */ - return g_string_free (str, FALSE); -} - -static gboolean -validate_flags (NMSetting *setting, const char* prop, guint val, GError **error) -{ - GParamSpec *pspec; - GValue value = G_VALUE_INIT; - gboolean success = TRUE; - - pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (G_OBJECT (setting)), prop); - g_assert (G_IS_PARAM_SPEC (pspec)); - - g_value_init (&value, pspec->value_type); - g_value_set_flags (&value, val); - - if (g_param_value_validate (pspec, &value)) { - GParamSpecFlags *pspec_flags = (GParamSpecFlags *) pspec; - char *flag_values = flag_values_to_string (pspec_flags->flags_class->values, - pspec_flags->flags_class->n_values); - g_set_error (error, 1, 0, _("'%u' flags are not valid; use combination of %s"), - val, flag_values); - g_free (flag_values); - success = FALSE; - } - g_value_unset (&value); - return success; -} - -static gboolean -check_and_set_string (NMSetting *setting, - const char *prop, - const char *val, - const char **valid_strv, - GError **error) -{ - const char *checked_val; - - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - - checked_val = nmc_string_is_valid (val, valid_strv, error); - if (!checked_val) - return FALSE; - - g_object_set (setting, prop, checked_val, NULL); - return TRUE; -} - -/* --- generic property setter functions --- */ -static gboolean -nmc_property_set_string (NMSetting *setting, const char *prop, const char *val, GError **error) -{ - g_object_set (setting, prop, val, NULL); - return TRUE; -} - -static gboolean -nmc_property_set_uint (NMSetting *setting, const char *prop, const char *val, GError **error) -{ - unsigned long val_int; - - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - - if (!nmc_string_to_uint (val, TRUE, 0, G_MAXUINT, &val_int)) { - g_set_error (error, 1, 0, _("'%s' is not a valid number (or out of range)"), val); - return FALSE; - } - - /* Validate the number according to the property spec */ - if (!validate_uint (setting, prop, (guint) val_int, error)) - return FALSE; - - g_object_set (setting, prop, (guint) val_int, NULL); - return TRUE; -} - -static gboolean -nmc_property_set_int (NMSetting *setting, const char *prop, const char *val, GError **error) -{ - long int val_int; - - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - - if (!nmc_string_to_int (val, TRUE, G_MININT, G_MAXINT, &val_int)) { - g_set_error (error, 1, 0, _("'%s' is not a valid number (or out of range)"), val); - return FALSE; - } - - /* Validate the number according to the property spec */ - if (!validate_int (setting, prop, (gint) val_int, error)) - return FALSE; - - g_object_set (setting, prop, (gint) val_int, NULL); - return TRUE; -} - -static gboolean -nmc_property_set_int64 (NMSetting *setting, const char *prop, const char *val, GError **error) -{ - long val_int; - - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - - if (!nmc_string_to_int (val, FALSE, 0, 0, &val_int)) { - g_set_error (error, 1, 0, _("'%s' is not a valid number (or out of range)"), val); - return FALSE; - } - - /* Validate the number according to the property spec */ - if (!validate_int64 (setting, prop, (gint64) val_int, error)) - return FALSE; - - g_object_set (setting, prop, (gint64) val_int, NULL); - return TRUE; -} - -static gboolean -nmc_property_set_flags (NMSetting *setting, const char *prop, const char *val, GError **error) -{ - unsigned long val_int; - - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - - if (!nmc_string_to_uint (val, TRUE, 0, G_MAXUINT, &val_int)) { - g_set_error (error, 1, 0, _("'%s' is not a valid number (or out of range)"), val); - return FALSE; - } - - /* Validate the flags according to the property spec */ - if (!validate_flags (setting, prop, (guint) val_int, error)) - return FALSE; - - g_object_set (setting, prop, (guint) val_int, NULL); - return TRUE; -} - -static gboolean -nmc_property_set_bool (NMSetting *setting, const char *prop, const char *val, GError **error) -{ - gboolean val_bool; - - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - - if (!nmc_string_to_bool (val, &val_bool, error)) - return FALSE; - - g_object_set (setting, prop, val_bool, NULL); - return TRUE; -} - -static gboolean -nmc_property_set_trilean (NMSetting *setting, const char *prop, const char *val, GError **error) -{ - long int val_int; - - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - - if (!nmc_string_to_int (val, TRUE, -1, 1, &val_int)) { - g_set_error (error, 1, 0, _("'%s' is not a valid value; use -1, 0 or 1"), val); - return FALSE; - } - - g_object_set (setting, prop, val_int, NULL); - return TRUE; -} - -static gboolean -nmc_property_set_ssid (NMSetting *setting, const char *prop, const char *val, GError **error) -{ - GBytes *ssid; - - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - - if (strlen (val) > 32) { - g_set_error (error, 1, 0, _("'%s' is not valid"), val); - return FALSE; - } - - ssid = g_bytes_new (val, strlen (val)); - g_object_set (setting, prop, ssid, NULL); - g_bytes_unref (ssid); - return TRUE; -} - -static gboolean -_property_set_mac (NMSetting *setting, const char *prop, const char *val, gboolean cloned_mac_addr, GError **error) -{ - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - - if ( (!cloned_mac_addr || !NM_CLONED_MAC_IS_SPECIAL (val)) - && !nm_utils_hwaddr_valid (val, ETH_ALEN)) { - g_set_error (error, 1, 0, _("'%s' is not a valid Ethernet MAC"), val); - return FALSE; - } - - g_object_set (setting, prop, val, NULL); - return TRUE; -} - -static gboolean -nmc_property_set_mac (NMSetting *setting, const char *prop, const char *val, GError **error) -{ - return _property_set_mac (setting, prop, val, FALSE, error); -} - -static gboolean -nmc_property_set_mac_cloned (NMSetting *setting, const char *prop, const char *val, GError **error) -{ - return _property_set_mac (setting, prop, val, TRUE, error); -} - -static gboolean -nmc_property_set_mtu (NMSetting *setting, const char *prop, const char *val, GError **error) -{ - const char *mtu = val; - - if (strcmp (mtu, "auto") == 0) - mtu = "0"; - - return nmc_property_set_uint (setting, prop, mtu, error); -} - -static gboolean -nmc_property_set_ifname (NMSetting *setting, const char *prop, const char *val, GError **error) -{ - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - - if (!nm_utils_is_valid_iface_name (val, error)) - return FALSE; - g_object_set (setting, prop, val, NULL); - return TRUE; -} - -#define ALL_SECRET_FLAGS \ - (NM_SETTING_SECRET_FLAG_NONE | \ - NM_SETTING_SECRET_FLAG_AGENT_OWNED | \ - NM_SETTING_SECRET_FLAG_NOT_SAVED | \ - NM_SETTING_SECRET_FLAG_NOT_REQUIRED) - -static gboolean -nmc_property_set_secret_flags (NMSetting *setting, const char *prop, const char *val, GError **error) -{ - char **strv = NULL, **iter; - unsigned long flags = 0, val_int; - - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - - strv = nmc_strsplit_set (val, " \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; - g_print (_("Warning: '%s' sum is higher than all flags => all flags set\n"), val); - } - - g_object_set (setting, prop, (guint) flags, NULL); - return TRUE; -} - -static gboolean -nmc_property_set_vpn_service (NMSetting *setting, const char *prop, const char *val, GError **error) -{ - gs_free char *service_name = NULL; - - service_name = nm_vpn_plugin_info_list_find_service_type (nm_vpn_get_plugin_infos (), val); - g_object_set (setting, prop, service_name ? : val, NULL); - return TRUE; -} - -static gboolean -nmc_util_is_domain (const char *domain) -{ - //FIXME: implement - return TRUE; -} - -static gboolean -nmc_property_set_byte_array (NMSetting *setting, const char *prop, const char *val, GError **error) -{ - char **strv = NULL, **iter; - char *val_strip; - const char *delimiters = " \t,"; - long int val_int; - GBytes *bytes; - GByteArray *array = NULL; - gboolean success = TRUE; - - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - - val_strip = g_strstrip (g_strdup (val)); - - /* First try hex string in the format of AAbbCCDd */ - bytes = nm_utils_hexstr2bin (val_strip); - if (bytes) { - array = g_bytes_unref_to_array (bytes); - 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)); - for (iter = strv; iter && *iter; iter++) { - if (!nmc_string_to_int_base (g_strstrip (*iter), 16, TRUE, 0, 255, &val_int)) { - g_set_error (error, 1, 0, _("'%s' is not a valid hex character"), *iter); - success = FALSE; - goto done; - } - g_byte_array_append (array, (const guint8 *) &val_int, 1); - } - -done: - if (success) - g_object_set (setting, prop, array, NULL); - - g_strfreev (strv); - if (array) - g_byte_array_free (array, TRUE); - return success; -} - -/* === GetFunc, SetFunc, RemoveFunc, DescribeFunc, ValuesFunc - functions for all properties of all settings === */ - -/* --- NM_SETTING_802_1X_SETTING_NAME property functions --- */ -DEFINE_GETTER (nmc_property_802_1X_get_eap, NM_SETTING_802_1X_EAP) -DEFINE_GETTER (nmc_property_802_1X_get_identity, NM_SETTING_802_1X_IDENTITY) -DEFINE_GETTER (nmc_property_802_1X_get_anonymous_identity, NM_SETTING_802_1X_ANONYMOUS_IDENTITY) -DEFINE_GETTER (nmc_property_802_1X_get_pac_file, NM_SETTING_802_1X_PAC_FILE) -DEFINE_GETTER (nmc_property_802_1X_get_ca_cert_password, NM_SETTING_802_1X_CA_CERT_PASSWORD) -DEFINE_SECRET_FLAGS_GETTER (nmc_property_802_1X_get_ca_cert_password_flags, NM_SETTING_802_1X_CA_CERT_PASSWORD_FLAGS) -DEFINE_GETTER (nmc_property_802_1X_get_ca_path, NM_SETTING_802_1X_CA_PATH) -DEFINE_GETTER (nmc_property_802_1X_get_subject_match, NM_SETTING_802_1X_SUBJECT_MATCH) -DEFINE_GETTER (nmc_property_802_1X_get_altsubject_matches, NM_SETTING_802_1X_ALTSUBJECT_MATCHES) -DEFINE_GETTER (nmc_property_802_1X_get_domain_suffix_match, NM_SETTING_802_1X_DOMAIN_SUFFIX_MATCH) -DEFINE_GETTER (nmc_property_802_1X_get_client_cert_password, NM_SETTING_802_1X_CLIENT_CERT_PASSWORD) -DEFINE_SECRET_FLAGS_GETTER (nmc_property_802_1X_get_client_cert_password_flags, NM_SETTING_802_1X_CLIENT_CERT_PASSWORD_FLAGS) -DEFINE_GETTER (nmc_property_802_1X_get_phase1_peapver, NM_SETTING_802_1X_PHASE1_PEAPVER) -DEFINE_GETTER (nmc_property_802_1X_get_phase1_peaplabel, NM_SETTING_802_1X_PHASE1_PEAPLABEL) -DEFINE_GETTER (nmc_property_802_1X_get_phase1_fast_provisioning, NM_SETTING_802_1X_PHASE1_FAST_PROVISIONING) -DEFINE_GETTER (nmc_property_802_1X_get_phase2_auth, NM_SETTING_802_1X_PHASE2_AUTH) -DEFINE_GETTER (nmc_property_802_1X_get_phase2_autheap, NM_SETTING_802_1X_PHASE2_AUTHEAP) -DEFINE_GETTER (nmc_property_802_1X_get_phase2_ca_cert_password, NM_SETTING_802_1X_PHASE2_CA_CERT_PASSWORD) -DEFINE_SECRET_FLAGS_GETTER (nmc_property_802_1X_get_phase2_ca_cert_password_flags, NM_SETTING_802_1X_PHASE2_CA_CERT_PASSWORD_FLAGS) -DEFINE_GETTER (nmc_property_802_1X_get_phase2_ca_path, NM_SETTING_802_1X_PHASE2_CA_PATH) -DEFINE_GETTER (nmc_property_802_1X_get_phase2_subject_match, NM_SETTING_802_1X_PHASE2_SUBJECT_MATCH) -DEFINE_GETTER (nmc_property_802_1X_get_phase2_altsubject_matches, NM_SETTING_802_1X_PHASE2_ALTSUBJECT_MATCHES) -DEFINE_GETTER (nmc_property_802_1X_get_phase2_domain_suffix_match, NM_SETTING_802_1X_PHASE2_DOMAIN_SUFFIX_MATCH) -DEFINE_GETTER (nmc_property_802_1X_get_phase2_client_cert_password, NM_SETTING_802_1X_PHASE2_CLIENT_CERT_PASSWORD) -DEFINE_SECRET_FLAGS_GETTER (nmc_property_802_1X_get_phase2_client_cert_password_flags, NM_SETTING_802_1X_PHASE2_CLIENT_CERT_PASSWORD_FLAGS) -DEFINE_GETTER (nmc_property_802_1X_get_password, NM_SETTING_802_1X_PASSWORD) -DEFINE_SECRET_FLAGS_GETTER (nmc_property_802_1X_get_password_flags, NM_SETTING_802_1X_PASSWORD_FLAGS) -DEFINE_SECRET_FLAGS_GETTER (nmc_property_802_1X_get_password_raw_flags, NM_SETTING_802_1X_PASSWORD_RAW_FLAGS) -DEFINE_GETTER (nmc_property_802_1X_get_private_key_password, NM_SETTING_802_1X_PRIVATE_KEY_PASSWORD) -DEFINE_SECRET_FLAGS_GETTER (nmc_property_802_1X_get_private_key_password_flags, NM_SETTING_802_1X_PRIVATE_KEY_PASSWORD_FLAGS) -DEFINE_GETTER (nmc_property_802_1X_get_phase2_private_key_password, NM_SETTING_802_1X_PHASE2_PRIVATE_KEY_PASSWORD) -DEFINE_SECRET_FLAGS_GETTER (nmc_property_802_1X_get_phase2_private_key_password_flags, NM_SETTING_802_1X_PHASE2_PRIVATE_KEY_PASSWORD_FLAGS) -DEFINE_GETTER (nmc_property_802_1X_get_pin, NM_SETTING_802_1X_PIN) -DEFINE_SECRET_FLAGS_GETTER (nmc_property_802_1X_get_pin_flags, NM_SETTING_802_1X_PIN_FLAGS) -DEFINE_GETTER (nmc_property_802_1X_get_system_ca_certs, NM_SETTING_802_1X_SYSTEM_CA_CERTS) -DEFINE_GETTER (nmc_property_802_1X_get_auth_timeout, NM_SETTING_802_1X_AUTH_TIMEOUT) - -static char * -nmc_property_802_1X_get_ca_cert (NMSetting *setting, NmcPropertyGetType get_type) -{ - NMSetting8021x *s_8021X = NM_SETTING_802_1X (setting); - char *ca_cert_str = NULL; - - switch (nm_setting_802_1x_get_ca_cert_scheme (s_8021X)) { - case NM_SETTING_802_1X_CK_SCHEME_BLOB: - ca_cert_str = bytes_to_string (nm_setting_802_1x_get_ca_cert_blob (s_8021X)); - break; - case NM_SETTING_802_1X_CK_SCHEME_PATH: - ca_cert_str = g_strdup (nm_setting_802_1x_get_ca_cert_path (s_8021X)); - break; - case NM_SETTING_802_1X_CK_SCHEME_PKCS11: - ca_cert_str = g_strdup (nm_setting_802_1x_get_ca_cert_uri (s_8021X)); - break; - case NM_SETTING_802_1X_CK_SCHEME_UNKNOWN: - break; - } - - return ca_cert_str; -} - -static char * -nmc_property_802_1X_get_client_cert (NMSetting *setting, - NmcPropertyGetType get_type, - gboolean show_secrets) -{ - NMSetting8021x *s_8021X = NM_SETTING_802_1X (setting); - char *cert_str = NULL; - - switch (nm_setting_802_1x_get_client_cert_scheme (s_8021X)) { - case NM_SETTING_802_1X_CK_SCHEME_BLOB: - if (show_secrets) - cert_str = bytes_to_string (nm_setting_802_1x_get_client_cert_blob (s_8021X)); - else - cert_str = g_strdup (_("<hidden>")); - break; - case NM_SETTING_802_1X_CK_SCHEME_PATH: - cert_str = g_strdup (nm_setting_802_1x_get_client_cert_path (s_8021X)); - break; - case NM_SETTING_802_1X_CK_SCHEME_PKCS11: - cert_str = g_strdup (nm_setting_802_1x_get_client_cert_uri (s_8021X)); - break; - case NM_SETTING_802_1X_CK_SCHEME_UNKNOWN: - break; - } - - return cert_str; -} - -static char * -nmc_property_802_1X_get_client_cert_full (NMSetting *setting, NmcPropertyGetType get_type) -{ - return nmc_property_802_1X_get_client_cert (setting, get_type, TRUE); -} - -static char * -nmc_property_802_1X_get_phase2_ca_cert (NMSetting *setting, NmcPropertyGetType get_type) -{ - NMSetting8021x *s_8021X = NM_SETTING_802_1X (setting); - char *phase2_ca_cert_str = NULL; - - switch (nm_setting_802_1x_get_phase2_ca_cert_scheme (s_8021X)) { - case NM_SETTING_802_1X_CK_SCHEME_BLOB: - phase2_ca_cert_str = bytes_to_string (nm_setting_802_1x_get_phase2_ca_cert_blob (s_8021X)); - break; - case NM_SETTING_802_1X_CK_SCHEME_PATH: - phase2_ca_cert_str = g_strdup (nm_setting_802_1x_get_phase2_ca_cert_path (s_8021X)); - break; - case NM_SETTING_802_1X_CK_SCHEME_PKCS11: - phase2_ca_cert_str = g_strdup (nm_setting_802_1x_get_phase2_ca_cert_uri (s_8021X)); - break; - case NM_SETTING_802_1X_CK_SCHEME_UNKNOWN: - break; - } - - return phase2_ca_cert_str; -} - -static char * -nmc_property_802_1X_get_phase2_client_cert (NMSetting *setting, - NmcPropertyGetType get_type, - gboolean show_secrets) -{ - NMSetting8021x *s_8021X = NM_SETTING_802_1X (setting); - char *cert_str = NULL; - - switch (nm_setting_802_1x_get_phase2_client_cert_scheme (s_8021X)) { - case NM_SETTING_802_1X_CK_SCHEME_BLOB: - if (show_secrets) - cert_str = bytes_to_string (nm_setting_802_1x_get_phase2_client_cert_blob (s_8021X)); - else - cert_str = g_strdup (_("<hidden>")); - break; - case NM_SETTING_802_1X_CK_SCHEME_PATH: - cert_str = g_strdup (nm_setting_802_1x_get_phase2_client_cert_path (s_8021X)); - break; - case NM_SETTING_802_1X_CK_SCHEME_PKCS11: - cert_str = g_strdup (nm_setting_802_1x_get_phase2_client_cert_uri (s_8021X)); - break; - case NM_SETTING_802_1X_CK_SCHEME_UNKNOWN: - break; - } - - return cert_str; -} - -static char * -nmc_property_802_1X_get_phase2_client_cert_full (NMSetting *setting, NmcPropertyGetType get_type) -{ - return nmc_property_802_1X_get_phase2_client_cert (setting, get_type, TRUE); -} - -static char * -nmc_property_802_1X_get_password_raw (NMSetting *setting, NmcPropertyGetType get_type) -{ - NMSetting8021x *s_8021X = NM_SETTING_802_1X (setting); - return bytes_to_string (nm_setting_802_1x_get_password_raw (s_8021X)); -} - -static char * -nmc_property_802_1X_get_private_key (NMSetting *setting, - NmcPropertyGetType get_type, - gboolean show_secrets) -{ - NMSetting8021x *s_8021X = NM_SETTING_802_1X (setting); - char *key_str = NULL; - - switch (nm_setting_802_1x_get_private_key_scheme (s_8021X)) { - case NM_SETTING_802_1X_CK_SCHEME_BLOB: - if (show_secrets) - key_str = bytes_to_string (nm_setting_802_1x_get_private_key_blob (s_8021X)); - else - key_str = g_strdup (_("<hidden>")); - break; - case NM_SETTING_802_1X_CK_SCHEME_PATH: - key_str = g_strdup (nm_setting_802_1x_get_private_key_path (s_8021X)); - break; - case NM_SETTING_802_1X_CK_SCHEME_PKCS11: - key_str = g_strdup (nm_setting_802_1x_get_private_key_uri (s_8021X)); - break; - case NM_SETTING_802_1X_CK_SCHEME_UNKNOWN: - break; - } - - return key_str; -} - -static char * -nmc_property_802_1X_get_private_key_full (NMSetting *setting, NmcPropertyGetType get_type) -{ - return nmc_property_802_1X_get_private_key (setting, get_type, TRUE); -} - -static char * -nmc_property_802_1X_get_phase2_private_key (NMSetting *setting, - NmcPropertyGetType get_type, - gboolean show_secrets) -{ - NMSetting8021x *s_8021X = NM_SETTING_802_1X (setting); - char *key_str = NULL; - - switch (nm_setting_802_1x_get_phase2_private_key_scheme (s_8021X)) { - case NM_SETTING_802_1X_CK_SCHEME_BLOB: - if (show_secrets) - key_str = bytes_to_string (nm_setting_802_1x_get_phase2_private_key_blob (s_8021X)); - else - key_str = g_strdup (_("<hidden>")); - break; - case NM_SETTING_802_1X_CK_SCHEME_PATH: - key_str = g_strdup (nm_setting_802_1x_get_phase2_private_key_path (s_8021X)); - break; - case NM_SETTING_802_1X_CK_SCHEME_PKCS11: - key_str = g_strdup (nm_setting_802_1x_get_phase2_private_key_uri (s_8021X)); - break; - case NM_SETTING_802_1X_CK_SCHEME_UNKNOWN: - break; - } - - return key_str; -} - -static char * -nmc_property_802_1X_get_phase2_private_key_full (NMSetting *setting, NmcPropertyGetType get_type) -{ - return nmc_property_802_1X_get_phase2_private_key (setting, get_type, TRUE); -} - -#define DEFINE_SETTER_STR_LIST(def_func, set_func) \ - static gboolean \ - def_func (NMSetting *setting, const char *prop, const char *val, GError **error) \ - { \ - char **strv = NULL; \ - guint i = 0; \ - \ - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); \ - \ - strv = nmc_strsplit_set (val, " \t,", 0); \ - while (strv && strv[i]) \ - set_func (NM_SETTING_802_1X (setting), strv[i++]); \ - g_strfreev (strv); \ - return TRUE; \ - } - -#define DEFINE_SETTER_CERT(def_func, set_func) \ - static gboolean \ - def_func (NMSetting *setting, const char *prop, const char *val, GError **error) \ - { \ - char *val_strip = g_strstrip (g_strdup (val)); \ - char *p = val_strip; \ - 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) \ - 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); \ - \ - success = set_func (NM_SETTING_802_1X (setting), p, scheme, NULL, error); \ - g_free (val_strip); \ - return success; \ - } - -#define DEFINE_SETTER_PRIV_KEY(def_func, pwd_func, set_func) \ - static gboolean \ - def_func (NMSetting *setting, const char *prop, const char *val, GError **error) \ - { \ - char **strv = NULL; \ - char *val_strip = g_strstrip (g_strdup (val)); \ - char *p = val_strip; \ - const char *path, *password; \ - gs_free char *password_free = NULL; \ - 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) \ - 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); \ - \ - strv = nmc_strsplit_set (p, " \t,", 2); \ - path = strv[0]; \ - if (g_strv_length (strv) == 2) \ - password = strv[1]; \ - 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; \ - } - -/* 'eap' */ -static const char *valid_eap[] = { "leap", "md5", "tls", "peap", "ttls", "sim", "fast", "pwd", NULL }; - -DEFINE_SETTER_STR_LIST_MULTI (check_and_add_802_1X_eap, - NM_SETTING_802_1X, - nm_setting_802_1x_add_eap_method) -static gboolean -nmc_property_802_1X_set_eap (NMSetting *setting, const char *prop, const char *val, GError **error) -{ - return check_and_add_802_1X_eap (setting, prop, val, valid_eap, error); -} - -static gboolean -_validate_and_remove_eap_method (NMSetting8021x *setting, - const char *eap, - GError **error) -{ - gboolean ret; - - ret = nm_setting_802_1x_remove_eap_method_by_value(setting, eap); - if (!ret) - g_set_error (error, 1, 0, _("the property doesn't contain EAP method '%s'"), eap); - return ret; -} -DEFINE_REMOVER_INDEX_OR_VALUE (nmc_property_802_1X_remove_eap, - NM_SETTING_802_1X, - nm_setting_802_1x_get_num_eap_methods, - nm_setting_802_1x_remove_eap_method, - _validate_and_remove_eap_method) - -DEFINE_ALLOWED_VAL_FUNC (nmc_property_802_1X_allowed_eap, valid_eap) - -/* 'ca-cert' */ -DEFINE_SETTER_CERT (nmc_property_802_1X_set_ca_cert, nm_setting_802_1x_set_ca_cert) - -static const char * -nmc_property_802_1X_describe_ca_cert (NMSetting *setting, const char *prop) -{ - return _("Enter file path to CA certificate (optionally prefixed with file://).\n" - " [file://]<file path>\n" - "Note that nmcli does not support specifying certificates as raw blob data.\n" - "Example: /home/cimrman/cacert.crt\n"); -} - -/* 'altsubject-matches' */ -DEFINE_SETTER_STR_LIST (nmc_property_802_1X_set_altsubject_matches, nm_setting_802_1x_add_altsubject_match) - -static gboolean -_validate_and_remove_altsubject_match (NMSetting8021x *setting, - const char *altsubject_match, - GError **error) -{ - gboolean ret; - - ret = nm_setting_802_1x_remove_altsubject_match_by_value (setting, altsubject_match); - if (!ret) - g_set_error (error, 1, 0, - _("the property doesn't contain alternative subject match '%s'"), - altsubject_match); - return ret; -} -DEFINE_REMOVER_INDEX_OR_VALUE (nmc_property_802_1X_remove_altsubject_matches, - NM_SETTING_802_1X, - nm_setting_802_1x_get_num_altsubject_matches, - nm_setting_802_1x_remove_altsubject_match, - _validate_and_remove_altsubject_match) - -/* 'client-cert' */ -DEFINE_SETTER_CERT (nmc_property_802_1X_set_client_cert, nm_setting_802_1x_set_client_cert) - -static const char * -nmc_property_802_1X_describe_client_cert (NMSetting *setting, const char *prop) -{ - return _("Enter file path to client certificate (optionally prefixed with file://).\n" - " [file://]<file path>\n" - "Note that nmcli does not support specifying certificates as raw blob data.\n" - "Example: /home/cimrman/jara.crt\n"); -} - -/* 'phase2-ca-cert' */ -DEFINE_SETTER_CERT (nmc_property_802_1X_set_phase2_ca_cert, nm_setting_802_1x_set_phase2_ca_cert) - -static const char * -nmc_property_802_1X_describe_phase2_ca_cert (NMSetting *setting, const char *prop) -{ - return _("Enter file path to CA certificate for inner authentication (optionally prefixed\n" - "with file://).\n" - " [file://]<file path>\n" - "Note that nmcli does not support specifying certificates as raw blob data.\n" - "Example: /home/cimrman/ca-zweite-phase.crt\n"); -} - -/* 'phase2-altsubject-matches' */ -DEFINE_SETTER_STR_LIST (nmc_property_802_1X_set_phase2_altsubject_matches, nm_setting_802_1x_add_phase2_altsubject_match) - -static gboolean -_validate_and_remove_phase2_altsubject_match (NMSetting8021x *setting, - const char *phase2_altsubject_match, - GError **error) -{ - gboolean ret; - - ret = nm_setting_802_1x_remove_phase2_altsubject_match_by_value (setting, phase2_altsubject_match); - if (!ret) - g_set_error (error, 1, 0, - _("the property doesn't contain \"phase2\" alternative subject match '%s'"), - phase2_altsubject_match); - return ret; -} -DEFINE_REMOVER_INDEX_OR_VALUE (nmc_property_802_1X_remove_phase2_altsubject_matches, - NM_SETTING_802_1X, - nm_setting_802_1x_get_num_phase2_altsubject_matches, - nm_setting_802_1x_remove_phase2_altsubject_match, - _validate_and_remove_phase2_altsubject_match) - -/* 'phase2-client-cert' */ -DEFINE_SETTER_CERT (nmc_property_802_1X_set_phase2_client_cert, nm_setting_802_1x_set_phase2_client_cert) - -static const char * -nmc_property_802_1X_describe_phase2_client_cert (NMSetting *setting, const char *prop) -{ - return _("Enter file path to client certificate for inner authentication (optionally prefixed\n" - "with file://).\n" - " [file://]<file path>\n" - "Note that nmcli does not support specifying certificates as raw blob data.\n" - "Example: /home/cimrman/jara-zweite-phase.crt\n"); -} - -/* 'private-key' */ -DEFINE_SETTER_PRIV_KEY (nmc_property_802_1X_set_private_key, - nm_setting_802_1x_get_private_key_password, - nm_setting_802_1x_set_private_key) - -/* 'phase2-private-key' */ -DEFINE_SETTER_PRIV_KEY (nmc_property_802_1X_set_phase2_private_key, - nm_setting_802_1x_get_phase2_private_key_password, - nm_setting_802_1x_set_phase2_private_key) - -static const char * -nmc_property_802_1X_describe_private_key (NMSetting *setting, const char *prop) -{ - return _("Enter path to a private key and the key password (if not set yet):\n" - " [file://]<file path> [<password>]\n" - "Note that nmcli does not support specifying private key as raw blob data.\n" - "Example: /home/cimrman/jara-priv-key Dardanely\n"); -} - -/* 'phase1-peapver' */ -static const char *_802_1X_valid_phase1_peapvers[] = { "0", "1", NULL }; - -static gboolean -nmc_property_802_1X_set_phase1_peapver (NMSetting *setting, const char *prop, const char *val, GError **error) -{ - return check_and_set_string (setting, prop, val, _802_1X_valid_phase1_peapvers, error); -} - -DEFINE_ALLOWED_VAL_FUNC (nmc_property_802_1X_allowed_phase1_peapver, _802_1X_valid_phase1_peapvers) - -/* 'phase1-peaplabel' */ -static const char *_802_1X_valid_phase1_peaplabels[] = { "0", "1", NULL }; - -static gboolean -nmc_property_802_1X_set_phase1_peaplabel (NMSetting *setting, const char *prop, const char *val, GError **error) -{ - return check_and_set_string (setting, prop, val, _802_1X_valid_phase1_peaplabels, error); -} - -DEFINE_ALLOWED_VAL_FUNC (nmc_property_802_1X_allowed_phase1_peaplabel, _802_1X_valid_phase1_peaplabels) - -/* 'phase1-fast-provisioning' */ -static const char *_802_1X_valid_phase1_fast_provisionings[] = { "0", "1", "2", "3", NULL }; - -static gboolean -nmc_property_802_1X_set_phase1_fast_provisioning (NMSetting *setting, const char *prop, const char *val, GError **error) -{ - return check_and_set_string (setting, prop, val, _802_1X_valid_phase1_fast_provisionings, error); -} - -DEFINE_ALLOWED_VAL_FUNC (nmc_property_802_1X_allowed_phase1_fast_provisioning, _802_1X_valid_phase1_fast_provisionings) - -/* 'phase2-auth' */ -static const char *_802_1X_valid_phase2_auths[] = - { "pap", "chap", "mschap", "mschapv2", "gtc", "otp", "md5", "tls", NULL }; - -static gboolean -nmc_property_802_1X_set_phase2_auth (NMSetting *setting, const char *prop, const char *val, GError **error) -{ - return check_and_set_string (setting, prop, val, _802_1X_valid_phase2_auths, error); -} - -DEFINE_ALLOWED_VAL_FUNC (nmc_property_802_1X_allowed_phase2_auth, _802_1X_valid_phase2_auths) - -/* 'phase2-autheap' */ -static const char *_802_1X_valid_phase2_autheaps[] = { "md5", "mschapv2", "otp", "gtc", "tls", NULL }; -static gboolean -nmc_property_802_1X_set_phase2_autheap (NMSetting *setting, const char *prop, const char *val, GError **error) -{ - return check_and_set_string (setting, prop, val, _802_1X_valid_phase2_autheaps, error); -} - -DEFINE_ALLOWED_VAL_FUNC (nmc_property_802_1X_allowed_phase2_autheap, _802_1X_valid_phase2_autheaps) - -/* 'password-raw' */ -static gboolean -nmc_property_802_1X_set_password_raw (NMSetting *setting, const char *prop, const char *val, GError **error) -{ - return nmc_property_set_byte_array (setting, prop, val, error); -} - -static const char * -nmc_property_802_1X_describe_password_raw (NMSetting *setting, const char *prop) -{ - return _("Enter bytes as a list of hexadecimal values.\n" - "Two formats are accepted:\n" - "(a) a string of hexadecimal digits, where each two digits represent one byte\n" - "(b) space-separated list of bytes written as hexadecimal digits " - "(with optional 0x/0X prefix, and optional leading 0).\n\n" - "Examples: ab0455a6ea3a74C2\n" - " ab 4 55 0xa6 ea 3a 74 C2\n"); -} - -static char * -nmc_property_802_1X_get_phase1_auth_flags (NMSetting *setting, NmcPropertyGetType get_type) -{ - NMSetting8021x *s_8021x = NM_SETTING_802_1X (setting); - NMSetting8021xAuthFlags flags; - char *tmp, *str; - - flags = nm_setting_802_1x_get_phase1_auth_flags (s_8021x); - tmp = nm_utils_enum_to_str (nm_setting_802_1x_auth_flags_get_type (), flags); - if (get_type == NMC_PROPERTY_GET_PARSABLE) - str = g_strdup_printf ("%s", tmp && *tmp ? tmp : "none"); - else - str = g_strdup_printf ("%d (%s)", flags, tmp && *tmp ? tmp : "none"); - g_free (tmp); - return str; -} - -static gboolean -nmc_property_802_1X_set_phase1_auth_flags (NMSetting *setting, const char *prop, - const char *val, GError **error) -{ - NMSetting8021xAuthFlags flags; - gs_free char *err_token = NULL; - gboolean ret; - long int t; - - if (nmc_string_to_int_base (val, 0, TRUE, - NM_SETTING_802_1X_AUTH_FLAGS_NONE, - NM_SETTING_802_1X_AUTH_FLAGS_ALL, - &t)) - flags = (NMSetting8021xAuthFlags) t; - else { - ret = nm_utils_enum_from_str (nm_setting_802_1x_auth_flags_get_type (), val, - (int *) &flags, &err_token); - - if (!ret) { - if (g_ascii_strcasecmp (err_token, "none") == 0) - flags = NM_SETTING_802_1X_AUTH_FLAGS_NONE; - else { - g_set_error (error, 1, 0, _("invalid option '%s', use a combination of [%s]"), - err_token, - nm_utils_enum_to_str (nm_setting_802_1x_auth_flags_get_type (), - NM_SETTING_802_1X_AUTH_FLAGS_ALL)); - return FALSE; - } - } - } - - g_object_set (setting, prop, (guint) flags, NULL); - return TRUE; -} - - -/* --- NM_SETTING_ADSL_SETTING_NAME property functions --- */ -DEFINE_GETTER (nmc_property_adsl_get_username, NM_SETTING_ADSL_USERNAME) -DEFINE_GETTER (nmc_property_adsl_get_password, NM_SETTING_ADSL_PASSWORD) -DEFINE_SECRET_FLAGS_GETTER (nmc_property_adsl_get_password_flags, NM_SETTING_ADSL_PASSWORD_FLAGS) -DEFINE_GETTER (nmc_property_adsl_get_protocol, NM_SETTING_ADSL_PROTOCOL) -DEFINE_GETTER (nmc_property_adsl_get_encapsulation, NM_SETTING_ADSL_ENCAPSULATION) -DEFINE_GETTER (nmc_property_adsl_get_vpi, NM_SETTING_ADSL_VPI) -DEFINE_GETTER (nmc_property_adsl_get_vci, NM_SETTING_ADSL_VCI) - -/* 'protocol' */ -static const char *adsl_valid_protocols[] = { - NM_SETTING_ADSL_PROTOCOL_PPPOA, - NM_SETTING_ADSL_PROTOCOL_PPPOE, - NM_SETTING_ADSL_PROTOCOL_IPOATM, - NULL -}; - -static gboolean -nmc_property_adsl_set_protocol (NMSetting *setting, const char *prop, const char *val, GError **error) -{ - return check_and_set_string (setting, prop, val, adsl_valid_protocols, error); -} - -DEFINE_ALLOWED_VAL_FUNC (nmc_property_adsl_allowed_protocol, adsl_valid_protocols) - -/* 'encapsulation' */ -static const char *adsl_valid_encapsulations[] = { - NM_SETTING_ADSL_ENCAPSULATION_VCMUX, - NM_SETTING_ADSL_ENCAPSULATION_LLC, - NULL -}; - -static gboolean -nmc_property_adsl_set_encapsulation (NMSetting *setting, const char *prop, const char *val, GError **error) -{ - return check_and_set_string (setting, prop, val, adsl_valid_encapsulations, error); -} - -DEFINE_ALLOWED_VAL_FUNC (nmc_property_adsl_allowed_encapsulation, adsl_valid_encapsulations) - - -/* --- NM_SETTING_BLUETOOTH_SETTING_NAME property functions --- */ -DEFINE_GETTER (nmc_property_bluetooth_get_bdaddr, NM_SETTING_BLUETOOTH_BDADDR) -DEFINE_GETTER (nmc_property_bluetooth_get_type, NM_SETTING_BLUETOOTH_TYPE) - -/* 'type' */ -static gboolean -nmc_property_bluetooth_set_type (NMSetting *setting, const char *prop, const char *val, GError **error) -{ - const char *types[] = { - NM_SETTING_BLUETOOTH_TYPE_DUN, - NM_SETTING_BLUETOOTH_TYPE_PANU, - NULL }; - - return check_and_set_string (setting, prop, val, types, error); -} - -/* --- NM_SETTING_BOND_SETTING_NAME property functions --- */ -/* 'options' */ -static char * -nmc_property_bond_get_options (NMSetting *setting, NmcPropertyGetType get_type) -{ - NMSettingBond *s_bond = NM_SETTING_BOND (setting); - GString *bond_options_s; - int i; - - bond_options_s = g_string_new (NULL); - for (i = 0; i < nm_setting_bond_get_num_options (s_bond); i++) { - const char *key, *value; - gs_free char *tmp_value = NULL; - char *p; - - nm_setting_bond_get_option (s_bond, i, &key, &value); - - if (nm_streq0 (key, NM_SETTING_BOND_OPTION_ARP_IP_TARGET)) { - value = tmp_value = g_strdup (value); - for (p = tmp_value; p && *p; p++) { - if (*p == ',') - *p = ' '; - } - } - - g_string_append_printf (bond_options_s, "%s=%s,", key, value); - } - g_string_truncate (bond_options_s, bond_options_s->len-1); /* chop off trailing ',' */ - - return g_string_free (bond_options_s, FALSE); -} - -/* example: miimon=100,mode=balance-rr, updelay=5 */ -static gboolean -_validate_and_remove_bond_option (NMSettingBond *setting, const char *option) -{ - const char *opt; - const char **valid_options; - - valid_options = nm_setting_bond_get_valid_options (setting); - opt = nmc_string_is_valid (option, valid_options, NULL); - - if (opt) - return nm_setting_bond_remove_option (setting, opt); - else - return FALSE; -} - -/* Validate bonding 'options' values */ -static const char * -_validate_bond_option_value (const char *option, const char *value, GError **error) -{ - if (!g_strcmp0 (option, NM_SETTING_BOND_OPTION_MODE)) - return nmc_bond_validate_mode (value, error); - - return value; -} - -static gboolean -_bond_add_option (NMSettingBond *setting, - const char *name, - const char *value) -{ - gs_free char *tmp_value = NULL; - char *p; - - if (nm_streq0 (name, NM_SETTING_BOND_OPTION_ARP_IP_TARGET)) { - value = tmp_value = g_strdup (value); - for (p = tmp_value; p && *p; p++) - if (*p == ' ') - *p = ','; - } - - return nm_setting_bond_add_option (setting, name, value); -} - -DEFINE_SETTER_OPTIONS (nmc_property_bond_set_options, - NM_SETTING_BOND, - NMSettingBond, - _bond_add_option, - nm_setting_bond_get_valid_options, - _validate_bond_option_value) -DEFINE_REMOVER_OPTION (nmc_property_bond_remove_option_options, - NM_SETTING_BOND, - _validate_and_remove_bond_option) - -static const char * -nmc_property_bond_describe_options (NMSetting *setting, const char *prop) -{ - static char *desc = NULL; - const char **valid_options; - char *options_str; - - if (G_UNLIKELY (desc == NULL)) { - valid_options = nm_setting_bond_get_valid_options (NM_SETTING_BOND (setting)); - options_str = g_strjoinv (", ", (char **) valid_options); - - desc = g_strdup_printf (_("Enter a list of bonding options formatted as:\n" - " option = <value>, option = <value>,... \n" - "Valid options are: %s\n" - "'mode' can be provided as a name or a number:\n" - "balance-rr = 0\n" - "active-backup = 1\n" - "balance-xor = 2\n" - "broadcast = 3\n" - "802.3ad = 4\n" - "balance-tlb = 5\n" - "balance-alb = 6\n\n" - "Example: mode=2,miimon=120\n"), options_str); - g_free (options_str); - } - return desc; -} - -static const char ** -nmc_property_bond_allowed_options (NMSetting *setting, const char *prop) -{ - return nm_setting_bond_get_valid_options (NM_SETTING_BOND (setting)); -} - - -/* --- NM_SETTING_BRIDGE_SETTING_NAME property functions --- */ -DEFINE_GETTER (nmc_property_bridge_get_mac_address, NM_SETTING_BRIDGE_MAC_ADDRESS) -DEFINE_GETTER (nmc_property_bridge_get_stp, NM_SETTING_BRIDGE_STP) -DEFINE_GETTER (nmc_property_bridge_get_priority, NM_SETTING_BRIDGE_PRIORITY) -DEFINE_GETTER (nmc_property_bridge_get_forward_delay, NM_SETTING_BRIDGE_FORWARD_DELAY) -DEFINE_GETTER (nmc_property_bridge_get_hello_time, NM_SETTING_BRIDGE_HELLO_TIME) -DEFINE_GETTER (nmc_property_bridge_get_max_age, NM_SETTING_BRIDGE_MAX_AGE) -DEFINE_GETTER (nmc_property_bridge_get_ageing_time, NM_SETTING_BRIDGE_AGEING_TIME) -DEFINE_GETTER (nmc_property_bridge_get_multicast_snooping, NM_SETTING_BRIDGE_MULTICAST_SNOOPING) - - -/* --- NM_SETTING_BRIDGE_PORT_SETTING_NAME property functions --- */ -DEFINE_GETTER (nmc_property_bridge_port_get_priority, NM_SETTING_BRIDGE_PORT_PRIORITY) -DEFINE_GETTER (nmc_property_bridge_port_get_path_cost, NM_SETTING_BRIDGE_PORT_PATH_COST) -DEFINE_GETTER (nmc_property_bridge_port_get_hairpin_mode, NM_SETTING_BRIDGE_PORT_HAIRPIN_MODE) - - -/* --- NM_SETTING_CDMA_SETTING_NAME property functions --- */ -DEFINE_GETTER (nmc_property_cdma_get_number, NM_SETTING_CDMA_NUMBER) -DEFINE_GETTER (nmc_property_cdma_get_username, NM_SETTING_CDMA_USERNAME) -DEFINE_GETTER (nmc_property_cdma_get_password, NM_SETTING_CDMA_PASSWORD) -DEFINE_GETTER (nmc_property_cdma_get_mtu, NM_SETTING_CDMA_MTU) - -DEFINE_SECRET_FLAGS_GETTER (nmc_property_cdma_get_password_flags, NM_SETTING_CDMA_PASSWORD_FLAGS) - - -/* --- NM_SETTING_CONNECTION_SETTING_NAME property functions --- */ -DEFINE_GETTER (nmc_property_connection_get_id, NM_SETTING_CONNECTION_ID) -DEFINE_GETTER (nmc_property_connection_get_uuid, NM_SETTING_CONNECTION_UUID) -DEFINE_GETTER (nmc_property_connection_get_stable_id, NM_SETTING_CONNECTION_STABLE_ID) -DEFINE_GETTER (nmc_property_connection_get_interface_name, NM_SETTING_CONNECTION_INTERFACE_NAME) -DEFINE_GETTER (nmc_property_connection_get_type, NM_SETTING_CONNECTION_TYPE) -DEFINE_GETTER (nmc_property_connection_get_autoconnect, NM_SETTING_CONNECTION_AUTOCONNECT) -DEFINE_GETTER (nmc_property_connection_get_autoconnect_priority, NM_SETTING_CONNECTION_AUTOCONNECT_PRIORITY) -DEFINE_GETTER (nmc_property_connection_get_timestamp, NM_SETTING_CONNECTION_TIMESTAMP) -DEFINE_GETTER (nmc_property_connection_get_read_only, NM_SETTING_CONNECTION_READ_ONLY) -static char * -nmc_property_connection_get_autoconnect_retries (NMSetting *setting, NmcPropertyGetType get_type) -{ - NMSettingConnection *s_con = NM_SETTING_CONNECTION (setting); - gint retries; - - retries = nm_setting_connection_get_autoconnect_retries (s_con); - if (get_type == NMC_PROPERTY_GET_PARSABLE) - return g_strdup_printf ("%d", retries); - - switch (retries) { - case -1: - return g_strdup_printf (_("%d (default)"), retries); - case 0: - return g_strdup_printf (_("%d (forever)"), retries); - default: - return g_strdup_printf ("%d", retries); - } -} - -static char * -nmc_property_connection_get_permissions (NMSetting *setting, NmcPropertyGetType get_type) -{ - NMSettingConnection *s_con = NM_SETTING_CONNECTION (setting); - GString *perm = NULL; - const char *perm_item; - const char *perm_type; - int i; - - perm = g_string_new (NULL); - for (i = 0; i < nm_setting_connection_get_num_permissions (s_con); i++) { - 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); - } - if (perm->len > 0) { - g_string_truncate (perm, perm->len-1); /* remove trailing , */ - return g_string_free (perm, FALSE); - } - - /* No value from get_permission */ - return g_string_free (perm, TRUE); -} - -DEFINE_GETTER (nmc_property_connection_get_zone, NM_SETTING_CONNECTION_ZONE) -DEFINE_GETTER (nmc_property_connection_get_master, NM_SETTING_CONNECTION_MASTER) -DEFINE_GETTER (nmc_property_connection_get_slave_type, NM_SETTING_CONNECTION_SLAVE_TYPE) - -static char * -nmc_property_connection_get_autoconnect_slaves (NMSetting *setting, NmcPropertyGetType get_type) -{ - NMSettingConnection *s_con = NM_SETTING_CONNECTION (setting); - return autoconnect_slaves_to_string (nm_setting_connection_get_autoconnect_slaves (s_con), get_type); -} - -DEFINE_GETTER (nmc_property_connection_get_secondaries, NM_SETTING_CONNECTION_SECONDARIES) -DEFINE_GETTER (nmc_property_connection_get_gateway_ping_timeout, NM_SETTING_CONNECTION_GATEWAY_PING_TIMEOUT) - -static gboolean -nmc_property_connection_set_type (NMSetting *setting, const char *prop, const char *val, GError **error) -{ - gs_free char *uuid = NULL; - - if (nm_setting_connection_get_uuid (NM_SETTING_CONNECTION (setting))) { - /* Don't allow setting type unless the connection is brand new. - * Just because it's a bad idea and the user wouldn't probably want that. - * No technical reason, really. - * Also, using uuid to see if the connection is brand new is a bit - * hacky: we can not see if the type is already set, because - * nmc_setting_set_property() is called only after the property - * we're setting (type) has been removed. */ - g_set_error (error, 1, 0, _("Can not change the connection type")); - return FALSE; - } - - uuid = nm_utils_uuid_generate (); - g_object_set (G_OBJECT (setting), - NM_SETTING_CONNECTION_UUID, uuid, - NULL); - - g_object_set (G_OBJECT (setting), prop, val, NULL); - return TRUE; -} - -#if 0 -/* - * Setting/removing UUID has been forbidden. - * Should it be enabled later, this function can be used. - */ -static gboolean -nmc_property_con_set_uuid (NMSetting *setting, const char *prop, const char *val, GError **error) -{ - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - - if (!nm_utils_is_uuid (val)) { - g_set_error (error, 1, 0, _("'%s' is not a valid UUID"), val); - return FALSE; - } - g_object_set (setting, prop, val, NULL); - return TRUE; -} -#endif - -/* 'permissions' */ -/* define from libnm-core/nm-setting-connection.c */ -#define PERM_USER_PREFIX "user:" - -static gboolean -permissions_valid (const char *perm) -{ - if (!perm || perm[0] == '\0') - return FALSE; - - if (strncmp (perm, PERM_USER_PREFIX, strlen (PERM_USER_PREFIX)) == 0) { - if ( strlen (perm) <= strlen (PERM_USER_PREFIX) - || strchr (perm + strlen (PERM_USER_PREFIX), ':')) - return FALSE; - } else { - if (strchr (perm, ':')) - return FALSE; - } - - return TRUE; -} - -static gboolean -nmc_property_connection_set_permissions (NMSetting *setting, const char *prop, const char *val, GError **error) -{ - char **strv = NULL; - guint i = 0; - - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - - strv = nmc_strsplit_set (val, " \t,", 0); - if (!verify_string_list (strv, prop, permissions_valid, error)) { - g_strfreev (strv); - 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]; - - nm_setting_connection_add_permission (NM_SETTING_CONNECTION (setting), "user", user, NULL); - } - - return TRUE; -} - -static gboolean -_validate_and_remove_connection_permission (NMSettingConnection *setting, - const char *perm, - GError **error) -{ - gboolean ret; - - ret = nm_setting_connection_remove_permission_by_value (setting, "user", perm, NULL); - if (!ret) - g_set_error (error, 1, 0, _("the property doesn't contain permission '%s'"), perm); - return ret; -} -DEFINE_REMOVER_INDEX_OR_VALUE (nmc_property_connection_remove_permissions, - NM_SETTING_CONNECTION, - nm_setting_connection_get_num_permissions, - nm_setting_connection_remove_permission, - _validate_and_remove_connection_permission) - -static const char * -nmc_property_connection_describe_permissions (NMSetting *setting, const char *prop) -{ - return _("Enter a list of user permissions. This is a list of user names formatted as:\n" - " [user:]<user name 1>, [user:]<user name 2>,...\n" - "The items can be separated by commas or spaces.\n\n" - "Example: alice bob charlie\n"); -} - -/* 'master' */ -static gboolean -nmc_property_con_set_master (NMSetting *setting, const char *prop, const char *val, GError **error) -{ - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - - if (!val) - ; - else if (!*val) - val = NULL; - else if ( !nm_utils_is_valid_iface_name (val, NULL) - && !nm_utils_is_uuid (val)) { - g_set_error (error, 1, 0, - _("'%s' is not valid master; use ifname or connection UUID"), - val); - return FALSE; - } - g_object_set (setting, prop, val, NULL); - return TRUE; -} - -/* 'slave-type' */ -static const char *con_valid_slave_types[] = { - NM_SETTING_BOND_SETTING_NAME, - NM_SETTING_BRIDGE_SETTING_NAME, - NM_SETTING_TEAM_SETTING_NAME, - NULL -}; - -static gboolean -nmc_property_con_set_slave_type (NMSetting *setting, const char *prop, const char *val, GError **error) -{ - return check_and_set_string (setting, prop, val, con_valid_slave_types, error); -} - - -DEFINE_ALLOWED_VAL_FUNC (nmc_property_con_allowed_slave_type, con_valid_slave_types) - -/* 'secondaries' */ -static gboolean -nmc_property_connection_set_secondaries (NMSetting *setting, const char *prop, const char *val, GError **error) -{ - const GPtrArray *connections; - NMConnection *con; - char **strv = NULL, **iter; - guint i = 0; - - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - - connections = nm_client_get_connections (nm_cli.client); - strv = nmc_strsplit_set (val, " \t,", 0); - for (iter = strv; iter && *iter; iter++) { - if (**iter == '\0') - continue; - - if (nm_utils_is_uuid (*iter)) { - con = nmc_find_connection (connections, "uuid", *iter, NULL, FALSE); - if (!con) - g_print (_("Warning: %s is not an UUID of any existing connection profile\n"), *iter); - else { - /* Currenly NM only supports VPN connections as secondaries */ - if (!nm_connection_is_type (con, NM_SETTING_VPN_SETTING_NAME)) { - g_set_error (error, 1, 0, _("'%s' is not a VPN connection profile"), *iter); - g_strfreev (strv); - return FALSE; - } - } - } else { - con = nmc_find_connection (connections, "id", *iter, NULL, FALSE); - if (!con) { - g_set_error (error, 1, 0, _("'%s' is not a name of any exiting profile"), *iter); - g_strfreev (strv); - return FALSE; - } - - /* Currenly NM only supports VPN connections as secondaries */ - if (!nm_connection_is_type (con, NM_SETTING_VPN_SETTING_NAME)) { - g_set_error (error, 1, 0, _("'%s' is not a VPN connection profile"), *iter); - g_strfreev (strv); - return FALSE; - } - - /* translate id to uuid */ - g_free (*iter); - *iter = g_strdup (nm_connection_get_uuid (con)); - } - } - - while (strv && strv[i]) - nm_setting_connection_add_secondary (NM_SETTING_CONNECTION (setting), strv[i++]); - g_strfreev (strv); - - return TRUE; -} - -static gboolean -_validate_and_remove_connection_secondary (NMSettingConnection *setting, - const char *secondary_uuid, - GError **error) -{ - gboolean ret; - - if (!nm_utils_is_uuid (secondary_uuid)) { - g_set_error (error, 1, 0, - _("the value '%s' is not a valid UUID"), secondary_uuid); - return FALSE; - } - - ret = nm_setting_connection_remove_secondary_by_value (setting, secondary_uuid); - if (!ret) - g_set_error (error, 1, 0, - _("the property doesn't contain UUID '%s'"), secondary_uuid); - return ret; -} -DEFINE_REMOVER_INDEX_OR_VALUE (nmc_property_connection_remove_secondaries, - NM_SETTING_CONNECTION, - nm_setting_connection_get_num_secondaries, - nm_setting_connection_remove_secondary, - _validate_and_remove_connection_secondary) - -static const char * -nmc_property_connection_describe_secondaries (NMSetting *setting, const char *prop) -{ - return _("Enter secondary connections that should be activated when this connection is\n" - "activated. Connections can be specified either by UUID or ID (name). nmcli\n" - "transparently translates names to UUIDs. Note that NetworkManager only supports\n" - "VPNs as secondary connections at the moment.\n" - "The items can be separated by commas or spaces.\n\n" - "Example: private-openvpn, fe6ba5d8-c2fc-4aae-b2e3-97efddd8d9a7\n"); -} - -/* 'metered' */ -static char * -nmc_property_connection_get_metered (NMSetting *setting, NmcPropertyGetType get_type) -{ - NMSettingConnection *s_conn = NM_SETTING_CONNECTION (setting); - - if (get_type == NMC_PROPERTY_GET_PARSABLE) { - switch (nm_setting_connection_get_metered (s_conn)) { - case NM_METERED_YES: - return g_strdup ("yes"); - case NM_METERED_NO: - return g_strdup ("no"); - case NM_METERED_UNKNOWN: - default: - return g_strdup ("unknown"); - } - } - switch (nm_setting_connection_get_metered (s_conn)) { - case NM_METERED_YES: - return g_strdup (_("yes")); - case NM_METERED_NO: - return g_strdup (_("no")); - case NM_METERED_UNKNOWN: - default: - return g_strdup (_("unknown")); - } -} - -static gboolean -nmc_property_connection_set_metered (NMSetting *setting, const char *prop, - const char *val, GError **error) -{ - NMMetered metered; - NMCTriStateValue ts_val; - - if (!nmc_string_to_tristate (val, &ts_val, error)) - return FALSE; - - switch (ts_val) { - case NMC_TRI_STATE_YES: - metered = NM_METERED_YES; - break; - case NMC_TRI_STATE_NO: - metered = NM_METERED_NO; - break; - case NMC_TRI_STATE_UNKNOWN: - metered = NM_METERED_UNKNOWN; - break; - default: - g_assert_not_reached(); - } - - g_object_set (setting, prop, metered, NULL); - return TRUE; -} - -static const char * -nmc_property_connection_describe_metered (NMSetting *setting, const char *prop) -{ - return _("Enter a value which indicates whether the connection is subject to a data\n" - "quota, usage costs or other limitations. Accepted options are:\n" - "'true','yes','on' to set the connection as metered\n" - "'false','no','off' to set the connection as not metered\n" - "'unknown' to let NetworkManager choose a value using some heuristics\n"); -} - -static const char *metered_valid_values[] = { "yes", "no", "unknown", NULL }; -DEFINE_ALLOWED_VAL_FUNC (nmc_property_connection_allowed_metered, metered_valid_values) - -/* 'lldp' */ -static char * -nmc_property_connection_get_lldp (NMSetting *setting, NmcPropertyGetType get_type) -{ - NMSettingConnection *s_conn = NM_SETTING_CONNECTION (setting); - NMSettingConnectionLldp lldp; - char *tmp, *str; - - lldp = nm_setting_connection_get_lldp (s_conn); - tmp = nm_utils_enum_to_str (nm_setting_connection_lldp_get_type (), lldp); - if (get_type == NMC_PROPERTY_GET_PARSABLE) - str = g_strdup_printf ("%s", tmp && *tmp ? tmp : "default"); - else - str = g_strdup_printf ("%d (%s)", lldp, tmp && *tmp ? tmp : "default"); - g_free (tmp); - return str; -} - -static gboolean -nmc_property_connection_set_lldp (NMSetting *setting, const char *prop, - const char *val, GError **error) -{ - NMSettingConnectionLldp lldp; - gboolean ret; - long int t; - - if (nmc_string_to_int_base (val, 0, TRUE, - NM_SETTING_CONNECTION_LLDP_DEFAULT, - NM_SETTING_CONNECTION_LLDP_ENABLE_RX, - &t)) - lldp = t; - else { - ret = nm_utils_enum_from_str (nm_setting_connection_lldp_get_type (), val, - (int *) &lldp, NULL); - - if (!ret) { - if (g_ascii_strcasecmp (val, "enable") == 0) - lldp = NM_SETTING_CONNECTION_LLDP_ENABLE_RX; - else { - g_set_error (error, 1, 0, _("invalid option '%s', use one of [%s]"), - val, "default,disable,enable-rx,enable"); - return FALSE; - } - } - } - - g_object_set (setting, prop, lldp, NULL); - return TRUE; -} - -static const char *lldp_valid_values[] = { "default", "disable", "enable-rx", NULL }; -DEFINE_ALLOWED_VAL_FUNC (nmc_property_connection_allowed_lldp, lldp_valid_values) - - -/* --- NM_SETTING_DCB_SETTING_NAME property functions --- */ -static char * -dcb_flags_to_string (NMSettingDcbFlags flags) -{ - GString *flag_str; - - if (flags == 0) - return g_strdup (_("0 (disabled)")); - - flag_str = g_string_new (NULL); - g_string_printf (flag_str, "%d (", flags); - - if (flags & NM_SETTING_DCB_FLAG_ENABLE) - g_string_append (flag_str, _("enabled, ")); - if (flags & NM_SETTING_DCB_FLAG_ADVERTISE) - g_string_append (flag_str, _("advertise, ")); - if (flags & NM_SETTING_DCB_FLAG_WILLING) - g_string_append (flag_str, _("willing, ")); - - if (flag_str->str[flag_str->len-1] == '(') - g_string_append (flag_str, _("unknown")); - else - g_string_truncate (flag_str, flag_str->len-2); /* chop off trailing ', ' */ - - g_string_append_c (flag_str, ')'); - - return g_string_free (flag_str, FALSE); -} - -#define DEFINE_DCB_FLAGS_GETTER(func_name, property_name) \ - static char * \ - func_name (NMSetting *setting, NmcPropertyGetType get_type) \ - { \ - guint v; \ - GValue val = G_VALUE_INIT; \ - g_value_init (&val, G_TYPE_UINT); \ - g_object_get_property (G_OBJECT (setting), property_name, &val); \ - v = g_value_get_uint (&val); \ - g_value_unset (&val); \ - return dcb_flags_to_string (v); \ - } - -static char * -dcb_app_priority_to_string (gint priority) -{ - return (priority == -1) ? g_strdup (_("-1 (unset)")) : g_strdup_printf ("%d", priority); -} - -#define DEFINE_DCB_APP_PRIORITY_GETTER(func_name, property_name) \ - static char * \ - func_name (NMSetting *setting, NmcPropertyGetType get_type) \ - { \ - int v; \ - GValue val = G_VALUE_INIT; \ - g_value_init (&val, G_TYPE_INT); \ - g_object_get_property (G_OBJECT (setting), property_name, &val); \ - v = g_value_get_int (&val); \ - g_value_unset (&val); \ - return dcb_app_priority_to_string (v); \ - } - -#define DEFINE_DCB_BOOL_GETTER(func_name, getter_func_name) \ - static char * \ - func_name (NMSetting *setting, NmcPropertyGetType get_type) \ - { \ - NMSettingDcb *s_dcb = NM_SETTING_DCB (setting); \ - GString *str; \ - guint i; \ - \ - str = g_string_new (NULL); \ - for (i = 0; i < 8; i++) { \ - if (getter_func_name (s_dcb, i)) \ - g_string_append_c (str, '1'); \ - else \ - g_string_append_c (str, '0'); \ -\ - if (i < 7) \ - g_string_append_c (str, ','); \ - } \ -\ - return g_string_free (str, FALSE); \ - } - -#define DEFINE_DCB_UINT_GETTER(func_name, getter_func_name) \ - static char * \ - func_name (NMSetting *setting, NmcPropertyGetType get_type) \ - { \ - NMSettingDcb *s_dcb = NM_SETTING_DCB (setting); \ - GString *str; \ - guint i; \ - \ - str = g_string_new (NULL); \ - for (i = 0; i < 8; i++) { \ - g_string_append_printf (str, "%u", getter_func_name (s_dcb, i)); \ - if (i < 7) \ - g_string_append_c (str, ','); \ - } \ -\ - return g_string_free (str, FALSE); \ - } - -DEFINE_DCB_FLAGS_GETTER (nmc_property_dcb_get_app_fcoe_flags, NM_SETTING_DCB_APP_FCOE_FLAGS) -DEFINE_DCB_APP_PRIORITY_GETTER (nmc_property_dcb_get_app_fcoe_priority, NM_SETTING_DCB_APP_FCOE_PRIORITY) -DEFINE_GETTER (nmc_property_dcb_get_app_fcoe_mode, NM_SETTING_DCB_APP_FCOE_MODE) -DEFINE_DCB_FLAGS_GETTER (nmc_property_dcb_get_app_iscsi_flags, NM_SETTING_DCB_APP_ISCSI_FLAGS) -DEFINE_DCB_APP_PRIORITY_GETTER (nmc_property_dcb_get_app_iscsi_priority, NM_SETTING_DCB_APP_ISCSI_PRIORITY) -DEFINE_DCB_FLAGS_GETTER (nmc_property_dcb_get_app_fip_flags, NM_SETTING_DCB_APP_FIP_FLAGS) -DEFINE_DCB_APP_PRIORITY_GETTER (nmc_property_dcb_get_app_fip_priority, NM_SETTING_DCB_APP_FIP_PRIORITY) - -DEFINE_DCB_FLAGS_GETTER (nmc_property_dcb_get_pfc_flags, NM_SETTING_DCB_PRIORITY_FLOW_CONTROL_FLAGS) -DEFINE_DCB_BOOL_GETTER (nmc_property_dcb_get_pfc, nm_setting_dcb_get_priority_flow_control) - -DEFINE_DCB_FLAGS_GETTER (nmc_property_dcb_get_pg_flags, NM_SETTING_DCB_PRIORITY_GROUP_FLAGS) -DEFINE_DCB_UINT_GETTER (nmc_property_dcb_get_pg_group_id, nm_setting_dcb_get_priority_group_id) -DEFINE_DCB_UINT_GETTER (nmc_property_dcb_get_pg_group_bandwidth, nm_setting_dcb_get_priority_group_bandwidth) -DEFINE_DCB_UINT_GETTER (nmc_property_dcb_get_pg_bandwidth, nm_setting_dcb_get_priority_bandwidth) -DEFINE_DCB_BOOL_GETTER (nmc_property_dcb_get_pg_strict, nm_setting_dcb_get_priority_strict_bandwidth) -DEFINE_DCB_UINT_GETTER (nmc_property_dcb_get_pg_traffic_class, nm_setting_dcb_get_priority_traffic_class) - -#define DCB_ALL_FLAGS (NM_SETTING_DCB_FLAG_ENABLE | NM_SETTING_DCB_FLAG_ADVERTISE | NM_SETTING_DCB_FLAG_WILLING) - -static gboolean -nmc_property_dcb_set_flags (NMSetting *setting, const char *prop, const char *val, GError **error) -{ - char **strv = NULL, **iter; - NMSettingDcbFlags flags = NM_SETTING_DCB_FLAG_NONE; - long int t; - - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - - /* Check for overall hex numeric value */ - if (nmc_string_to_int_base (val, 0, TRUE, 0, DCB_ALL_FLAGS, &t)) - flags = (guint) t; - else { - /* Check for individual flag numbers */ - strv = nmc_strsplit_set (val, " \t,", 0); - for (iter = strv; iter && *iter; iter++) { - if (!nmc_string_to_int_base (*iter, 0, TRUE, 0, DCB_ALL_FLAGS, &t)) - t = -1; - - if ( g_ascii_strcasecmp (*iter, "enable") == 0 - || g_ascii_strcasecmp (*iter, "enabled") == 0 - || t == NM_SETTING_DCB_FLAG_ENABLE) - flags |= NM_SETTING_DCB_FLAG_ENABLE; - else if ( g_ascii_strcasecmp (*iter, "advertise") == 0 - || t == NM_SETTING_DCB_FLAG_ADVERTISE) - flags |= NM_SETTING_DCB_FLAG_ADVERTISE; - else if ( g_ascii_strcasecmp (*iter, "willing") == 0 - || t == NM_SETTING_DCB_FLAG_WILLING) - flags |= NM_SETTING_DCB_FLAG_WILLING; - else if ( g_ascii_strcasecmp (*iter, "disable") == 0 - || g_ascii_strcasecmp (*iter, "disabled") == 0 - || t == 0) { - /* pass */ - } else { - g_set_error (error, 1, 0, _("'%s' is not a valid DCB flag"), *iter); - return FALSE; - } - } - g_strfreev (strv); - } - - /* Validate the flags according to the property spec */ - if (!validate_flags (setting, prop, (guint) flags, error)) - return FALSE; - - g_object_set (setting, prop, (guint) flags, NULL); - return TRUE; -} - -static gboolean -nmc_property_dcb_set_priority (NMSetting *setting, const char *prop, const char *val, GError **error) -{ - long int priority = 0; - - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - - if (!nmc_string_to_int (val, FALSE, -1, 7, &priority)) { - g_set_error (error, 1, 0, _("'%s' is not a DCB app priority"), val); - return FALSE; - } - - /* Validate the number according to the property spec */ - if (!validate_int (setting, prop, (gint) priority, error)) - return FALSE; - - g_object_set (setting, prop, (gint) priority, NULL); - return TRUE; -} - -static gboolean -dcb_parse_uint_array (const char *val, - guint max, - guint other, - guint *out_array, - GError **error) -{ - char **items, **iter; - guint i = 0; - - g_return_val_if_fail (out_array != NULL, FALSE); - - items = g_strsplit_set (val, ",", -1); - if (g_strv_length (items) != 8) { - g_set_error_literal (error, 1, 0, _("must contain 8 comma-separated numbers")); - goto error; - } - - for (iter = items; iter && *iter; iter++) { - long int num = 0; - gboolean success; - - *iter = g_strstrip (*iter); - success = nmc_string_to_int_base (*iter, 10, TRUE, 0, other ? other : max, &num); - - /* If number is greater than 'max' it must equal 'other' */ - if (success && other && (num > max) && (num != other)) - success = FALSE; - - if (!success) { - if (other) { - g_set_error (error, 1, 0, _("'%s' not a number between 0 and %u (inclusive) or %u"), - *iter, max, other); - } else { - g_set_error (error, 1, 0, _("'%s' not a number between 0 and %u (inclusive)"), - *iter, max); - } - goto error; - } - out_array[i++] = (guint) num; - } - - return TRUE; - -error: - g_strfreev (items); - return FALSE; -} - -static void -dcb_check_feature_enabled (NMSettingDcb *s_dcb, const char *flags_prop) -{ - NMSettingDcbFlags flags = NM_SETTING_DCB_FLAG_NONE; - - g_object_get (s_dcb, flags_prop, &flags, NULL); - if (!(flags & NM_SETTING_DCB_FLAG_ENABLE)) - g_print (_("Warning: changes will have no effect until '%s' includes 1 (enabled)\n\n"), flags_prop); -} - -static gboolean -nmc_property_dcb_set_pfc (NMSetting *setting, const char *prop, const char *val, GError **error) -{ - guint i = 0; - guint nums[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; - - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - - if (!dcb_parse_uint_array (val, 1, 0, nums, error)) - return FALSE; - - for (i = 0; i < 8; i++) - nm_setting_dcb_set_priority_flow_control (NM_SETTING_DCB (setting), i, !!nums[i]); - - dcb_check_feature_enabled (NM_SETTING_DCB (setting), NM_SETTING_DCB_PRIORITY_FLOW_CONTROL_FLAGS); - return TRUE; -} - -static gboolean -nmc_property_dcb_set_pg_group_id (NMSetting *setting, const char *prop, const char *val, GError **error) -{ - guint i = 0; - guint nums[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; - - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - - if (!dcb_parse_uint_array (val, 7, 15, nums, error)) - return FALSE; - - for (i = 0; i < 8; i++) - nm_setting_dcb_set_priority_group_id (NM_SETTING_DCB (setting), i, nums[i]); - - dcb_check_feature_enabled (NM_SETTING_DCB (setting), NM_SETTING_DCB_PRIORITY_GROUP_FLAGS); - return TRUE; -} - -static gboolean -nmc_property_dcb_set_pg_group_bandwidth (NMSetting *setting, const char *prop, const char *val, GError **error) -{ - 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); - - if (!dcb_parse_uint_array (val, 100, 0, nums, error)) - return FALSE; - - for (i = 0; i < 8; i++) - sum += nums[i]; - if (sum != 100) { - g_set_error_literal (error, 1, 0, _("bandwidth percentages must total 100%%")); - return FALSE; - } - - for (i = 0; i < 8; i++) - nm_setting_dcb_set_priority_group_bandwidth (NM_SETTING_DCB (setting), i, nums[i]); - - dcb_check_feature_enabled (NM_SETTING_DCB (setting), NM_SETTING_DCB_PRIORITY_GROUP_FLAGS); - return TRUE; -} - -static gboolean -nmc_property_dcb_set_pg_bandwidth (NMSetting *setting, const char *prop, const char *val, GError **error) -{ - guint i = 0; - guint nums[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; - - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - - if (!dcb_parse_uint_array (val, 100, 0, nums, error)) - return FALSE; - - for (i = 0; i < 8; i++) - nm_setting_dcb_set_priority_bandwidth (NM_SETTING_DCB (setting), i, nums[i]); - - dcb_check_feature_enabled (NM_SETTING_DCB (setting), NM_SETTING_DCB_PRIORITY_GROUP_FLAGS); - return TRUE; -} - -static gboolean -nmc_property_dcb_set_pg_strict (NMSetting *setting, const char *prop, const char *val, GError **error) -{ - guint i = 0; - guint nums[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; - - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - - if (!dcb_parse_uint_array (val, 1, 0, nums, error)) - return FALSE; - - for (i = 0; i < 8; i++) - nm_setting_dcb_set_priority_strict_bandwidth (NM_SETTING_DCB (setting), i, !!nums[i]); - - dcb_check_feature_enabled (NM_SETTING_DCB (setting), NM_SETTING_DCB_PRIORITY_GROUP_FLAGS); - return TRUE; -} - -static gboolean -nmc_property_dcb_set_pg_traffic_class (NMSetting *setting, const char *prop, const char *val, GError **error) -{ - guint i = 0; - guint nums[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; - - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - - if (!dcb_parse_uint_array (val, 7, 0, nums, error)) - return FALSE; - - for (i = 0; i < 8; i++) - nm_setting_dcb_set_priority_traffic_class (NM_SETTING_DCB (setting), i, nums[i]); - - dcb_check_feature_enabled (NM_SETTING_DCB (setting), NM_SETTING_DCB_PRIORITY_GROUP_FLAGS); - return TRUE; -} - -/* 'app-fcoe-mode' */ -static const char *_dcb_valid_fcoe_modes[] = { NM_SETTING_DCB_FCOE_MODE_FABRIC, - NM_SETTING_DCB_FCOE_MODE_VN2VN, - NULL }; - -static gboolean -nmc_property_dcb_set_app_fcoe_mode (NMSetting *setting, const char *prop, const char *val, GError **error) -{ - return check_and_set_string (setting, prop, val, _dcb_valid_fcoe_modes, error); -} - -DEFINE_ALLOWED_VAL_FUNC (nmc_property_dcb_allowed_app_fcoe_modes, _dcb_valid_fcoe_modes) - - -/* --- NM_SETTING_GSM_SETTING_NAME property functions --- */ -DEFINE_GETTER (nmc_property_gsm_get_number, NM_SETTING_GSM_NUMBER) -DEFINE_GETTER (nmc_property_gsm_get_username, NM_SETTING_GSM_USERNAME) -DEFINE_GETTER (nmc_property_gsm_get_password, NM_SETTING_GSM_PASSWORD) -DEFINE_SECRET_FLAGS_GETTER (nmc_property_gsm_get_password_flags, NM_SETTING_GSM_PASSWORD_FLAGS) -DEFINE_GETTER (nmc_property_gsm_get_apn, NM_SETTING_GSM_APN) -DEFINE_GETTER (nmc_property_gsm_get_network_id, NM_SETTING_GSM_NETWORK_ID) -DEFINE_GETTER (nmc_property_gsm_get_pin, NM_SETTING_GSM_PIN) -DEFINE_SECRET_FLAGS_GETTER (nmc_property_gsm_get_pin_flags, NM_SETTING_GSM_PIN_FLAGS) -DEFINE_GETTER (nmc_property_gsm_get_home_only, NM_SETTING_GSM_HOME_ONLY) -DEFINE_GETTER (nmc_property_gsm_get_device_id, NM_SETTING_GSM_DEVICE_ID) -DEFINE_GETTER (nmc_property_gsm_get_sim_id, NM_SETTING_GSM_SIM_ID) -DEFINE_GETTER (nmc_property_gsm_get_sim_operator_id, NM_SETTING_GSM_SIM_OPERATOR_ID) -DEFINE_GETTER (nmc_property_gsm_get_mtu, NM_SETTING_GSM_MTU) - -static gboolean -nmc_property_gsm_set_sim_operator_id (NMSetting *setting, const char *prop, const char *val, GError **error) -{ - const char *p = val; - - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - - if (strlen (val) != 5 && strlen (val) != 6) { - g_set_error_literal (error, 1, 0, _("SIM operator ID must be a 5 or 6 number MCCMNC code")); - return FALSE; - } - - while (p && *p) { - if (!g_ascii_isdigit (*p++)) { - g_set_error_literal (error, 1, 0, _("SIM operator ID must be a 5 or 6 number MCCMNC code")); - return FALSE; - } - } - g_object_set (G_OBJECT (setting), - NM_SETTING_GSM_SIM_OPERATOR_ID, - val, - NULL); - return TRUE; -} - - -/* --- NM_SETTING_INFINIBAND_SETTING_NAME property functions --- */ -DEFINE_GETTER (nmc_property_ib_get_mac_address, NM_SETTING_INFINIBAND_MAC_ADDRESS) -DEFINE_GETTER (nmc_property_ib_get_transport_mode, NM_SETTING_INFINIBAND_TRANSPORT_MODE) - -/* 'mac-address' */ -static gboolean -nmc_property_ib_set_mac (NMSetting *setting, const char *prop, const char *val, GError **error) -{ - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - - if (!nm_utils_hwaddr_valid (val, INFINIBAND_ALEN)) { - g_set_error (error, 1, 0, _("'%s' is not a valid InfiniBand MAC"), val); - return FALSE; - } - - g_object_set (setting, prop, val, NULL); - return TRUE; -} - -/* 'transport-mode' */ -static const char *ib_valid_transport_modes[] = { "datagram", "connected", NULL }; - -static gboolean -nmc_property_ib_set_transport_mode (NMSetting *setting, const char *prop, const char *val, GError **error) -{ - return check_and_set_string (setting, prop, val, ib_valid_transport_modes, error); -} - -DEFINE_ALLOWED_VAL_FUNC (nmc_property_ib_allowed_transport_mode, ib_valid_transport_modes) - -/* 'p-key' */ -static gboolean -nmc_property_ib_set_p_key (NMSetting *setting, const char *prop, const char *val, GError **error) -{ - gboolean p_key_valid = FALSE; - long p_key_int; - - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - - if (!strncasecmp (val, "0x", 2)) - p_key_valid = nmc_string_to_int_base (val + 2, 16, TRUE, 0, G_MAXUINT16, &p_key_int); - else - p_key_valid = nmc_string_to_int (val, TRUE, -1, G_MAXUINT16, &p_key_int); - - if (!p_key_valid) { - if (strcmp (val, "default") == 0) - p_key_int = -1; - else { - g_set_error (error, 1, 0, _("'%s' is not a valid IBoIP P_Key"), val); - return FALSE; - } - } - g_object_set (setting, prop, (gint) p_key_int, NULL); - return TRUE; -} - - -static char * -nmc_property_ib_get_mtu (NMSetting *setting, NmcPropertyGetType get_type) -{ - NMSettingInfiniband *s_infiniband = NM_SETTING_INFINIBAND (setting); - int mtu; - - mtu = nm_setting_infiniband_get_mtu (s_infiniband); - if (mtu == 0) - return g_strdup (_("auto")); - else - return g_strdup_printf ("%d", mtu); -} - -static char * -nmc_property_ib_get_p_key (NMSetting *setting, NmcPropertyGetType get_type) -{ - NMSettingInfiniband *s_infiniband = NM_SETTING_INFINIBAND (setting); - int p_key; - - p_key = nm_setting_infiniband_get_p_key (s_infiniband); - if (p_key == -1) - return g_strdup (_("default")); - else - return g_strdup_printf ("0x%04x", p_key); -} - -DEFINE_GETTER (nmc_property_ib_get_parent, NM_SETTING_INFINIBAND_PARENT) - - -/* --- NM_SETTING_IP_TUNNEL_SETTING_NAME property functions --- */ -DEFINE_GETTER (nmc_property_ip_tunnel_get_parent, NM_SETTING_IP_TUNNEL_PARENT); -DEFINE_GETTER (nmc_property_ip_tunnel_get_local, NM_SETTING_IP_TUNNEL_LOCAL); -DEFINE_GETTER (nmc_property_ip_tunnel_get_remote, NM_SETTING_IP_TUNNEL_REMOTE); -DEFINE_GETTER (nmc_property_ip_tunnel_get_ttl, NM_SETTING_IP_TUNNEL_TTL); -DEFINE_GETTER (nmc_property_ip_tunnel_get_tos, NM_SETTING_IP_TUNNEL_TOS); -DEFINE_GETTER (nmc_property_ip_tunnel_get_path_mtu_discovery, NM_SETTING_IP_TUNNEL_PATH_MTU_DISCOVERY); -DEFINE_GETTER (nmc_property_ip_tunnel_get_input_key, NM_SETTING_IP_TUNNEL_INPUT_KEY); -DEFINE_GETTER (nmc_property_ip_tunnel_get_output_key, NM_SETTING_IP_TUNNEL_OUTPUT_KEY); -DEFINE_GETTER (nmc_property_ip_tunnel_get_encapsulation_limit, NM_SETTING_IP_TUNNEL_ENCAPSULATION_LIMIT); -DEFINE_GETTER (nmc_property_ip_tunnel_get_flow_label, NM_SETTING_IP_TUNNEL_FLOW_LABEL); -DEFINE_GETTER (nmc_property_ip_tunnel_get_mtu, NM_SETTING_IP_TUNNEL_MTU); - -static char * -nmc_property_ip_tunnel_get_mode (NMSetting *setting, NmcPropertyGetType get_type) -{ - NMSettingIPTunnel *s_ip_tunnel = NM_SETTING_IP_TUNNEL (setting); - NMIPTunnelMode mode; - - mode = nm_setting_ip_tunnel_get_mode (s_ip_tunnel); - return nm_utils_enum_to_str (nm_ip_tunnel_mode_get_type (), mode); -} - -static gboolean -nmc_property_ip_tunnel_set_mode (NMSetting *setting, const char *prop, - const char *val, GError **error) -{ - NMIPTunnelMode mode; - gboolean ret; - - ret = nm_utils_enum_from_str (nm_ip_tunnel_mode_get_type(), val, - (int *) &mode, NULL); - - if (!ret) { - gs_free const char **values = NULL; - gs_free char *values_str = NULL; - - values = nm_utils_enum_get_values (nm_ip_tunnel_mode_get_type (), - NM_IP_TUNNEL_MODE_UNKNOWN + 1, - G_MAXINT); - values_str = g_strjoinv (",", (char **) values); - g_set_error (error, 1, 0, _("invalid mode '%s', use one of %s"), - val, values_str); - - return FALSE; - } - - g_object_set (setting, prop, mode, NULL); - return TRUE; -} - -DEFINE_ALLOWED_FOR_ENUMS (nmc_property_ip_tunnel_allowed_mode, - nm_ip_tunnel_mode_get_type, - NM_IP_TUNNEL_MODE_UNKNOWN + 1, G_MAXINT) - - -/* --- NM_SETTING_IP4_CONFIG_SETTING_NAME property functions --- */ -/* --- IP4 / IP6 shared functions --- */ -static NMIPAddress * -_parse_ip_address (int family, const char *address, GError **error) -{ - char *value = g_strdup (address); - NMIPAddress *ipaddr; - - ipaddr = nmc_parse_and_build_address (family, g_strstrip (value), error); - g_free (value); - return ipaddr; -} - -DEFINE_GETTER (nmc_property_ipv4_get_method, NM_SETTING_IP_CONFIG_METHOD) -DEFINE_GETTER (nmc_property_ipv4_get_dns, NM_SETTING_IP_CONFIG_DNS) -DEFINE_GETTER (nmc_property_ipv4_get_dns_search, NM_SETTING_IP_CONFIG_DNS_SEARCH) -DEFINE_GETTER_WITH_DEFAULT (nmc_property_ipv4_get_dns_options, NM_SETTING_IP_CONFIG_DNS_OPTIONS, !nm_setting_ip_config_has_dns_options ((NMSettingIPConfig *) setting)) -DEFINE_GETTER (nmc_property_ipv4_get_dns_priority, NM_SETTING_IP_CONFIG_DNS_PRIORITY) - -static char * -nmc_property_ip_get_addresses (NMSetting *setting, NmcPropertyGetType get_type) -{ - NMSettingIPConfig *s_ip = NM_SETTING_IP_CONFIG (setting); - GString *printable; - guint32 num_addresses, i; - NMIPAddress *addr; - - printable = g_string_new (NULL); - - num_addresses = nm_setting_ip_config_get_num_addresses (s_ip); - for (i = 0; i < num_addresses; i++) { - addr = nm_setting_ip_config_get_address (s_ip, i); - - if (printable->len > 0) - g_string_append (printable, ", "); - - g_string_append_printf (printable, "%s/%u", - nm_ip_address_get_address (addr), - nm_ip_address_get_prefix (addr)); - } - - return g_string_free (printable, FALSE); -} - -static char * -nmc_property_ipvx_get_routes (NMSetting *setting, NmcPropertyGetType get_type) -{ - NMSettingIPConfig *s_ip = NM_SETTING_IP_CONFIG (setting); - GString *printable; - guint32 num_routes, i; - NMIPRoute *route; - - printable = g_string_new (NULL); - - num_routes = nm_setting_ip_config_get_num_routes (s_ip); - for (i = 0; i < num_routes; i++) { - gs_free char *attr_str = NULL; - gs_strfreev char **attr_names = NULL; - gs_unref_hashtable GHashTable *hash = g_hash_table_new (g_str_hash, g_str_equal); - int j; - - route = nm_setting_ip_config_get_route (s_ip, i); - - attr_names = nm_ip_route_get_attribute_names (route); - for (j = 0; attr_names && attr_names[j]; j++) { - g_hash_table_insert (hash, attr_names[j], - nm_ip_route_get_attribute (route, attr_names[j])); - } - - attr_str = nm_utils_format_variant_attributes (hash, ' ', '='); - - if (get_type == NMC_PROPERTY_GET_PARSABLE) { - if (printable->len > 0) - g_string_append (printable, ", "); - - g_string_append_printf (printable, "%s/%u", - nm_ip_route_get_dest (route), - nm_ip_route_get_prefix (route)); - - if (nm_ip_route_get_next_hop (route)) - g_string_append_printf (printable, " %s", nm_ip_route_get_next_hop (route)); - if (nm_ip_route_get_metric (route) != -1) - g_string_append_printf (printable, " %u", (guint32) nm_ip_route_get_metric (route)); - if (attr_str) - g_string_append_printf (printable, " %s", attr_str); - } else { - - if (printable->len > 0) - g_string_append (printable, "; "); - - g_string_append (printable, "{ "); - - g_string_append_printf (printable, "ip = %s/%u", - nm_ip_route_get_dest (route), - nm_ip_route_get_prefix (route)); - - if (nm_ip_route_get_next_hop (route)) { - g_string_append_printf (printable, ", nh = %s", - nm_ip_route_get_next_hop (route)); - } - - if (nm_ip_route_get_metric (route) != -1) - g_string_append_printf (printable, ", mt = %u", (guint32) nm_ip_route_get_metric (route)); - if (attr_str) - g_string_append_printf (printable, " %s", attr_str); - - g_string_append (printable, " }"); - } - } - - return g_string_free (printable, FALSE); -} - -static char * -nmc_property_ipv4_get_routes (NMSetting *setting, NmcPropertyGetType get_type) -{ - return nmc_property_ipvx_get_routes (setting, get_type); -} - -DEFINE_GETTER (nmc_property_ipv4_get_gateway, NM_SETTING_IP_CONFIG_GATEWAY) -DEFINE_GETTER (nmc_property_ipv4_get_route_metric, NM_SETTING_IP_CONFIG_ROUTE_METRIC) -DEFINE_GETTER (nmc_property_ipv4_get_ignore_auto_routes, NM_SETTING_IP_CONFIG_IGNORE_AUTO_ROUTES) -DEFINE_GETTER (nmc_property_ipv4_get_ignore_auto_dns, NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS) -DEFINE_GETTER (nmc_property_ipv4_get_dhcp_client_id, NM_SETTING_IP4_CONFIG_DHCP_CLIENT_ID) -DEFINE_GETTER (nmc_property_ipv4_get_dhcp_timeout, NM_SETTING_IP_CONFIG_DHCP_TIMEOUT) -DEFINE_GETTER (nmc_property_ipv4_get_dhcp_send_hostname, NM_SETTING_IP_CONFIG_DHCP_SEND_HOSTNAME) -DEFINE_GETTER (nmc_property_ipv4_get_dhcp_hostname, NM_SETTING_IP_CONFIG_DHCP_HOSTNAME) -DEFINE_GETTER (nmc_property_ipv4_get_dhcp_fqdn, NM_SETTING_IP4_CONFIG_DHCP_FQDN) -DEFINE_GETTER (nmc_property_ipv4_get_never_default, NM_SETTING_IP_CONFIG_NEVER_DEFAULT) -DEFINE_GETTER (nmc_property_ipv4_get_may_fail, NM_SETTING_IP_CONFIG_MAY_FAIL) - -static char * -nmc_property_ipv4_get_dad_timeout (NMSetting *setting, NmcPropertyGetType get_type) -{ - NMSettingIPConfig *s_ip = NM_SETTING_IP_CONFIG (setting); - gint dad_timeout; - - dad_timeout = nm_setting_ip_config_get_dad_timeout (s_ip); - if (get_type == NMC_PROPERTY_GET_PARSABLE) - return g_strdup_printf ("%d", dad_timeout); - - switch (dad_timeout) { - case -1: - return g_strdup_printf (_("%d (default)"), dad_timeout); - case 0: - return g_strdup_printf (_("%d (off)"), dad_timeout); - default: - return g_strdup_printf ("%d", dad_timeout); - } -} - -/* 'method' */ -static const char *ipv4_valid_methods[] = { - NM_SETTING_IP4_CONFIG_METHOD_AUTO, - NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL, - NM_SETTING_IP4_CONFIG_METHOD_MANUAL, - NM_SETTING_IP4_CONFIG_METHOD_SHARED, - NM_SETTING_IP4_CONFIG_METHOD_DISABLED, - NULL -}; - -static gboolean -nmc_property_ipv4_set_method (NMSetting *setting, const char *prop, const char *val, GError **error) -{ - /* Silently accept "static" and convert to "manual" */ - if (val && strlen (val) > 1 && matches (val, "static")) - val = NM_SETTING_IP4_CONFIG_METHOD_MANUAL; - - return check_and_set_string (setting, prop, val, ipv4_valid_methods, error); -} - -DEFINE_ALLOWED_VAL_FUNC (nmc_property_ipv4_allowed_method, ipv4_valid_methods) - -/* 'dns' */ -static gboolean -nmc_property_ipv4_set_dns (NMSetting *setting, const char *prop, const char *val, GError **error) -{ - char **strv = NULL, **iter, *addr; - guint32 ip4_addr; - - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - - strv = nmc_strsplit_set (val, " \t,", 0); - for (iter = strv; iter && *iter; iter++) { - addr = g_strstrip (*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; -} - -static gboolean -_validate_and_remove_ipv4_dns (NMSettingIPConfig *setting, - const char *dns, - GError **error) -{ - guint32 ip4_addr; - gboolean ret; - - if (inet_pton (AF_INET, dns, &ip4_addr) < 1) { - g_set_error (error, 1, 0, _("invalid IPv4 address '%s'"), dns); - return FALSE; - } - - ret = nm_setting_ip_config_remove_dns_by_value (setting, dns); - if (!ret) - g_set_error (error, 1, 0, _("the property doesn't contain DNS server '%s'"), dns); - return ret; -} -DEFINE_REMOVER_INDEX_OR_VALUE (nmc_property_ipv4_remove_dns, - NM_SETTING_IP_CONFIG, - nm_setting_ip_config_get_num_dns, - nm_setting_ip_config_remove_dns, - _validate_and_remove_ipv4_dns) - -static const char * -nmc_property_ipv4_describe_dns (NMSetting *setting, const char *prop) -{ - return _("Enter a list of IPv4 addresses of DNS servers.\n\n" - "Example: 8.8.8.8, 8.8.4.4\n"); -} - -/* 'dns-search' */ -static gboolean -nmc_property_ipv4_set_dns_search (NMSetting *setting, const char *prop, const char *val, GError **error) -{ - char **strv = NULL; - guint i = 0; - - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - - strv = nmc_strsplit_set (val, " \t,", 0); - if (!verify_string_list (strv, prop, nmc_util_is_domain, error)) { - g_strfreev (strv); - return FALSE; - } - - while (strv && strv[i]) - nm_setting_ip_config_add_dns_search (NM_SETTING_IP_CONFIG (setting), strv[i++]); - g_strfreev (strv); - - return TRUE; -} - -static gboolean -_validate_and_remove_ipv4_dns_search (NMSettingIPConfig *setting, - const char *dns_search, - GError **error) -{ - gboolean ret; - - ret = nm_setting_ip_config_remove_dns_search_by_value (setting, dns_search); - if (!ret) - g_set_error (error, 1, 0, - _("the property doesn't contain DNS search domain '%s'"), - dns_search); - return ret; -} -DEFINE_REMOVER_INDEX_OR_VALUE (nmc_property_ipv4_remove_dns_search, - NM_SETTING_IP_CONFIG, - nm_setting_ip_config_get_num_dns_searches, - nm_setting_ip_config_remove_dns_search, - _validate_and_remove_ipv4_dns_search) - -/* 'dns-options' */ -static gboolean -nmc_property_ipv4_set_dns_options (NMSetting *setting, const char *prop, const char *val, GError **error) -{ - char **strv = NULL; - guint i = 0; - - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - - nm_setting_ip_config_clear_dns_options (NM_SETTING_IP_CONFIG (setting), TRUE); - strv = nmc_strsplit_set (val, " \t,", 0); - while (strv && strv[i]) - nm_setting_ip_config_add_dns_option (NM_SETTING_IP_CONFIG (setting), strv[i++]); - g_strfreev (strv); - - return TRUE; -} - -static gboolean -_validate_and_remove_ipv4_dns_option (NMSettingIPConfig *setting, - const char *dns_option, - GError **error) -{ - gboolean ret; - - ret = nm_setting_ip_config_remove_dns_option_by_value (setting, dns_option); - if (!ret) - g_set_error (error, 1, 0, - _("the property doesn't contain DNS option '%s'"), - dns_option); - return ret; -} -DEFINE_REMOVER_INDEX_OR_VALUE (nmc_property_ipv4_remove_dns_option, - NM_SETTING_IP_CONFIG, - nm_setting_ip_config_get_num_dns_options, - nm_setting_ip_config_remove_dns_option, - _validate_and_remove_ipv4_dns_option) - -/* 'addresses' */ -static NMIPAddress * -_parse_ipv4_address (const char *address, GError **error) -{ - return _parse_ip_address (AF_INET, address, error); -} - -static gboolean -nmc_property_ipv4_set_addresses (NMSetting *setting, const char *prop, const char *val, GError **error) -{ - char **strv = NULL, **iter; - NMIPAddress *ip4addr; - - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - - strv = nmc_strsplit_set (val, ",", 0); - for (iter = strv; iter && *iter; iter++) { - ip4addr = _parse_ipv4_address (*iter, error); - if (!ip4addr) { - g_strfreev (strv); - return FALSE; - } - nm_setting_ip_config_add_address (NM_SETTING_IP_CONFIG (setting), ip4addr); - nm_ip_address_unref (ip4addr); - } - g_strfreev (strv); - return TRUE; -} - -static gboolean -_validate_and_remove_ipv4_address (NMSettingIPConfig *setting, - const char *address, - GError **error) -{ - NMIPAddress *ip4addr; - gboolean ret; - - ip4addr = _parse_ipv4_address (address, error); - if (!ip4addr) - return FALSE; - - ret = nm_setting_ip_config_remove_address_by_value (setting, ip4addr); - if (!ret) - g_set_error (error, 1, 0, - _("the property doesn't contain IP address '%s'"), address); - nm_ip_address_unref (ip4addr); - return ret; -} -DEFINE_REMOVER_INDEX_OR_VALUE (nmc_property_ipv4_remove_addresses, - NM_SETTING_IP_CONFIG, - nm_setting_ip_config_get_num_addresses, - nm_setting_ip_config_remove_address, - _validate_and_remove_ipv4_address) - -static const char * -nmc_property_ipv4_describe_addresses (NMSetting *setting, const char *prop) -{ - return _("Enter a list of IPv4 addresses formatted as:\n" - " ip[/prefix], ip[/prefix],...\n" - "Missing prefix is regarded as prefix of 32.\n\n" - "Example: 192.168.1.5/24, 10.0.0.11/24\n"); -} - -/* 'gateway' */ -static gboolean -nmc_property_ipv4_set_gateway (NMSetting *setting, const char *prop, const char *val, GError **error) -{ - NMIPAddress *ip4addr; - - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - - if (strchr (val, '/')) { - g_set_error (error, 1, 0, - _("invalid gateway address '%s'"), val); - return FALSE; - } - ip4addr = _parse_ipv4_address (val, error); - if (!ip4addr) - return FALSE; - - g_object_set (setting, prop, val, NULL); - nm_ip_address_unref (ip4addr); - return TRUE; -} - -/* 'routes' */ -static NMIPRoute * -_parse_ipv4_route (const char *route, GError **error) -{ - return nmc_parse_and_build_route (AF_INET, route, error); -} - -static gboolean -nmc_property_ipv4_set_routes (NMSetting *setting, const char *prop, const char *val, GError **error) -{ - char **strv = NULL, **iter; - NMIPRoute *ip4route; - - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - - strv = nmc_strsplit_set (val, ",", 0); - for (iter = strv; iter && *iter; iter++) { - ip4route = _parse_ipv4_route (*iter, error); - if (!ip4route) { - g_strfreev (strv); - return FALSE; - } - nm_setting_ip_config_add_route (NM_SETTING_IP_CONFIG (setting), ip4route); - nm_ip_route_unref (ip4route); - } - g_strfreev (strv); - return TRUE; -} - -static gboolean -_validate_and_remove_ipv4_route (NMSettingIPConfig *setting, - const char *route, - GError **error) -{ - NMIPRoute *ip4route; - gboolean ret; - - ip4route = _parse_ipv4_route (route, error); - if (!ip4route) - return FALSE; - - ret = nm_setting_ip_config_remove_route_by_value (setting, ip4route); - if (!ret) - g_set_error (error, 1, 0, _("the property doesn't contain route '%s'"), route); - nm_ip_route_unref (ip4route); - return ret; -} -DEFINE_REMOVER_INDEX_OR_VALUE (nmc_property_ipv4_remove_routes, - NM_SETTING_IP_CONFIG, - nm_setting_ip_config_get_num_routes, - nm_setting_ip_config_remove_route, - _validate_and_remove_ipv4_route) - -static const char * -nmc_property_ipv4_describe_routes (NMSetting *setting, const char *prop) -{ - return _("Enter a list of IPv4 routes formatted as:\n" - " ip[/prefix] [next-hop] [metric],...\n\n" - "Missing prefix is regarded as a prefix of 32.\n" - "Missing next-hop is regarded as 0.0.0.0.\n" - "Missing metric means default (NM/kernel will set a default value).\n\n" - "Examples: 192.168.2.0/24 192.168.2.1 3, 10.1.0.0/16 10.0.0.254\n" - " 10.1.2.0/24\n"); -} - - -/* --- NM_SETTING_IP6_CONFIG_SETTING_NAME property functions --- */ -DEFINE_GETTER (nmc_property_ipv6_get_method, NM_SETTING_IP_CONFIG_METHOD) -DEFINE_GETTER (nmc_property_ipv6_get_dns, NM_SETTING_IP_CONFIG_DNS) -DEFINE_GETTER (nmc_property_ipv6_get_dns_search, NM_SETTING_IP_CONFIG_DNS_SEARCH) -DEFINE_GETTER_WITH_DEFAULT (nmc_property_ipv6_get_dns_options, NM_SETTING_IP_CONFIG_DNS_OPTIONS, !nm_setting_ip_config_has_dns_options ((NMSettingIPConfig *) setting)) -DEFINE_GETTER (nmc_property_ipv6_get_dns_priority, NM_SETTING_IP_CONFIG_DNS_PRIORITY) - -static char * -nmc_property_ipv6_get_routes (NMSetting *setting, NmcPropertyGetType get_type) -{ - return nmc_property_ipvx_get_routes (setting, get_type); -} - -DEFINE_GETTER (nmc_property_ipv6_get_gateway, NM_SETTING_IP_CONFIG_GATEWAY) -DEFINE_GETTER (nmc_property_ipv6_get_route_metric, NM_SETTING_IP_CONFIG_ROUTE_METRIC) -DEFINE_GETTER (nmc_property_ipv6_get_ignore_auto_routes, NM_SETTING_IP_CONFIG_IGNORE_AUTO_ROUTES) -DEFINE_GETTER (nmc_property_ipv6_get_ignore_auto_dns, NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS) -DEFINE_GETTER (nmc_property_ipv6_get_never_default, NM_SETTING_IP_CONFIG_NEVER_DEFAULT) -DEFINE_GETTER (nmc_property_ipv6_get_may_fail, NM_SETTING_IP_CONFIG_MAY_FAIL) -DEFINE_GETTER (nmc_property_ipv6_get_dhcp_send_hostname, NM_SETTING_IP_CONFIG_DHCP_SEND_HOSTNAME) -DEFINE_GETTER (nmc_property_ipv6_get_dhcp_hostname, NM_SETTING_IP_CONFIG_DHCP_HOSTNAME) -DEFINE_GETTER (nmc_property_ipv6_get_token, NM_SETTING_IP6_CONFIG_TOKEN) - -static char * -nmc_property_ipv6_get_ip6_privacy (NMSetting *setting, NmcPropertyGetType get_type) -{ - NMSettingIP6Config *s_ip6 = NM_SETTING_IP6_CONFIG (setting); - return ip6_privacy_to_string (nm_setting_ip6_config_get_ip6_privacy (s_ip6), get_type); -} - -/* 'method' */ -static const char *ipv6_valid_methods[] = { - NM_SETTING_IP6_CONFIG_METHOD_IGNORE, - NM_SETTING_IP6_CONFIG_METHOD_AUTO, - NM_SETTING_IP6_CONFIG_METHOD_DHCP, - NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL, - NM_SETTING_IP6_CONFIG_METHOD_MANUAL, - NM_SETTING_IP6_CONFIG_METHOD_SHARED, - NULL -}; - -static gboolean -nmc_property_ipv6_set_method (NMSetting *setting, const char *prop, const char *val, GError **error) -{ - /* Silently accept "static" and convert to "manual" */ - if (val && strlen (val) > 1 && matches (val, "static")) - val = NM_SETTING_IP6_CONFIG_METHOD_MANUAL; - - return check_and_set_string (setting, prop, val, ipv6_valid_methods, error); -} - -DEFINE_ALLOWED_VAL_FUNC (nmc_property_ipv6_allowed_method, ipv6_valid_methods) - -/* 'dns' */ -static gboolean -nmc_property_ipv6_set_dns (NMSetting *setting, const char *prop, const char *val, GError **error) -{ - char **strv = NULL, **iter, *addr; - struct in6_addr ip6_addr; - - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - - strv = nmc_strsplit_set (val, " \t,", 0); - for (iter = strv; iter && *iter; iter++) { - addr = g_strstrip (*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; -} - -static gboolean -_validate_and_remove_ipv6_dns (NMSettingIPConfig *setting, - const char *dns, - GError **error) -{ - struct in6_addr ip6_addr; - gboolean ret; - - if (inet_pton (AF_INET6, dns, &ip6_addr) < 1) { - g_set_error (error, 1, 0, _("invalid IPv6 address '%s'"), dns); - return FALSE; - } - - ret = nm_setting_ip_config_remove_dns_by_value (setting, dns); - if (!ret) - g_set_error (error, 1, 0, _("the property doesn't contain DNS server '%s'"), dns); - return ret; -} -DEFINE_REMOVER_INDEX_OR_VALUE (nmc_property_ipv6_remove_dns, - NM_SETTING_IP_CONFIG, - nm_setting_ip_config_get_num_dns, - nm_setting_ip_config_remove_dns, - _validate_and_remove_ipv6_dns) - -static const char * -nmc_property_ipv6_describe_dns (NMSetting *setting, const char *prop) -{ - return _("Enter a list of IPv6 addresses of DNS servers. If the IPv6 " - "configuration method is 'auto' these DNS servers are appended " - "to those (if any) returned by automatic configuration. DNS " - "servers cannot be used with the 'shared' or 'link-local' IPv6 " - "configuration methods, as there is no upstream network. In " - "all other IPv6 configuration methods, these DNS " - "servers are used as the only DNS servers for this connection.\n\n" - "Example: 2607:f0d0:1002:51::4, 2607:f0d0:1002:51::1\n"); -} - -/* 'dns-search' */ -static gboolean -nmc_property_ipv6_set_dns_search (NMSetting *setting, const char *prop, const char *val, GError **error) -{ - char **strv = NULL; - guint i = 0; - - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - - strv = nmc_strsplit_set (val, " \t,", 0); - if (!verify_string_list (strv, prop, nmc_util_is_domain, error)) { - g_strfreev (strv); - return FALSE; - } - - while (strv && strv[i]) - nm_setting_ip_config_add_dns_search (NM_SETTING_IP_CONFIG (setting), strv[i++]); - g_strfreev (strv); - - return TRUE; -} - -static gboolean -_validate_and_remove_ipv6_dns_search (NMSettingIPConfig *setting, - const char *dns_search, - GError **error) -{ - gboolean ret; - - ret = nm_setting_ip_config_remove_dns_search_by_value (setting, dns_search); - if (!ret) - g_set_error (error, 1, 0, - _("the property doesn't contain DNS search domain '%s'"), - dns_search); - return ret; -} -DEFINE_REMOVER_INDEX_OR_VALUE (nmc_property_ipv6_remove_dns_search, - NM_SETTING_IP_CONFIG, - nm_setting_ip_config_get_num_dns_searches, - nm_setting_ip_config_remove_dns_search, - _validate_and_remove_ipv6_dns_search) - -/* 'dns-options' */ -static gboolean -nmc_property_ipv6_set_dns_options (NMSetting *setting, const char *prop, const char *val, GError **error) -{ - char **strv = NULL; - guint i = 0; - - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - - nm_setting_ip_config_clear_dns_options (NM_SETTING_IP_CONFIG (setting), TRUE); - strv = nmc_strsplit_set (val, " \t,", 0); - while (strv && strv[i]) - nm_setting_ip_config_add_dns_option (NM_SETTING_IP_CONFIG (setting), strv[i++]); - g_strfreev (strv); - - return TRUE; -} - -static gboolean -_validate_and_remove_ipv6_dns_option (NMSettingIPConfig *setting, - const char *dns_option, - GError **error) -{ - gboolean ret; - - ret = nm_setting_ip_config_remove_dns_option_by_value (setting, dns_option); - if (!ret) - g_set_error (error, 1, 0, - _("the property doesn't contain DNS option '%s'"), - dns_option); - return ret; -} -DEFINE_REMOVER_INDEX_OR_VALUE (nmc_property_ipv6_remove_dns_option, - NM_SETTING_IP_CONFIG, - nm_setting_ip_config_get_num_dns_options, - nm_setting_ip_config_remove_dns_option, - _validate_and_remove_ipv6_dns_option) - -/* 'addresses' */ -static NMIPAddress * -_parse_ipv6_address (const char *address, GError **error) -{ - return _parse_ip_address (AF_INET6, address, error); -} - -static gboolean -nmc_property_ipv6_set_addresses (NMSetting *setting, const char *prop, const char *val, GError **error) -{ - char **strv = NULL, **iter; - NMIPAddress *ip6addr; - - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - - strv = nmc_strsplit_set (val, ",", 0); - for (iter = strv; iter && *iter; iter++) { - ip6addr = _parse_ipv6_address (*iter, error); - if (!ip6addr) { - g_strfreev (strv); - return FALSE; - } - nm_setting_ip_config_add_address (NM_SETTING_IP_CONFIG (setting), ip6addr); - nm_ip_address_unref (ip6addr); - } - g_strfreev (strv); - return TRUE; -} - -static gboolean -_validate_and_remove_ipv6_address (NMSettingIPConfig *setting, - const char *address, - GError **error) -{ - NMIPAddress *ip6addr; - gboolean ret; - - ip6addr = _parse_ipv6_address (address, error); - if (!ip6addr) - return FALSE; - - ret = nm_setting_ip_config_remove_address_by_value (setting, ip6addr); - if (!ret) - g_set_error (error, 1, 0, _("the property doesn't contain IP address '%s'"), address); - nm_ip_address_unref (ip6addr); - return ret; -} -DEFINE_REMOVER_INDEX_OR_VALUE (nmc_property_ipv6_remove_addresses, - NM_SETTING_IP_CONFIG, - nm_setting_ip_config_get_num_addresses, - nm_setting_ip_config_remove_address, - _validate_and_remove_ipv6_address) - -static const char * -nmc_property_ipv6_describe_addresses (NMSetting *setting, const char *prop) -{ - return _("Enter a list of IPv6 addresses formatted as:\n" - " ip[/prefix], ip[/prefix],...\n" - "Missing prefix is regarded as prefix of 128.\n\n" - "Example: 2607:f0d0:1002:51::4/64, 1050:0:0:0:5:600:300c:326b\n"); -} - -/* 'gateway' */ -static gboolean -nmc_property_ipv6_set_gateway (NMSetting *setting, const char *prop, const char *val, GError **error) -{ - NMIPAddress *ip6addr; - - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - - if (strchr (val, '/')) { - g_set_error (error, 1, 0, - _("invalid gateway address '%s'"), val); - return FALSE; - } - ip6addr = _parse_ipv6_address (val, error); - if (!ip6addr) - return FALSE; - - g_object_set (setting, prop, val, NULL); - nm_ip_address_unref (ip6addr); - return TRUE; -} - -/* 'routes' */ -static NMIPRoute * -_parse_ipv6_route (const char *route, GError **error) -{ - return nmc_parse_and_build_route (AF_INET6, route, error); -} - -static gboolean -nmc_property_ipv6_set_routes (NMSetting *setting, const char *prop, const char *val, GError **error) -{ - char **strv = NULL, **iter; - NMIPRoute *ip6route; - - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - - strv = nmc_strsplit_set (val, ",", 0); - for (iter = strv; iter && *iter; iter++) { - ip6route = _parse_ipv6_route (*iter, error); - if (!ip6route) { - g_strfreev (strv); - return FALSE; - } - nm_setting_ip_config_add_route (NM_SETTING_IP_CONFIG (setting), ip6route); - nm_ip_route_unref (ip6route); - } - g_strfreev (strv); - return TRUE; -} - -static gboolean -_validate_and_remove_ipv6_route (NMSettingIPConfig *setting, - const char *route, - GError **error) -{ - NMIPRoute *ip6route; - gboolean ret; - - ip6route = _parse_ipv6_route (route, error); - if (!ip6route) - return FALSE; - - ret = nm_setting_ip_config_remove_route_by_value (setting, ip6route); - if (!ret) - g_set_error (error, 1, 0, _("the property doesn't contain route '%s'"), route); - nm_ip_route_unref (ip6route); - return ret; -} -DEFINE_REMOVER_INDEX_OR_VALUE (nmc_property_ipv6_remove_routes, - NM_SETTING_IP_CONFIG, - nm_setting_ip_config_get_num_routes, - nm_setting_ip_config_remove_route, - _validate_and_remove_ipv6_route) - -static const char * -nmc_property_ipv6_describe_routes (NMSetting *setting, const char *prop) -{ - return _("Enter a list of IPv6 routes formatted as:\n" - " ip[/prefix] [next-hop] [metric],...\n\n" - "Missing prefix is regarded as a prefix of 128.\n" - "Missing next-hop is regarded as \"::\".\n" - "Missing metric means default (NM/kernel will set a default value).\n\n" - "Examples: 2001:db8:beef:2::/64 2001:db8:beef::2, 2001:db8:beef:3::/64 2001:db8:beef::3 2\n" - " abbe::/64 55\n"); -} - -static gboolean -nmc_property_ipv6_set_ip6_privacy (NMSetting *setting, const char *prop, const char *val, GError **error) -{ - unsigned long val_int; - - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - - if (!nmc_string_to_uint (val, FALSE, 0, 0, &val_int)) { - g_set_error (error, 1, 0, _("'%s' is not a number"), val); - 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"), val); - return FALSE; - } - - g_object_set (setting, prop, val_int, NULL); - return TRUE; -} - -/* 'addr_gen_mode' */ -static char * -nmc_property_ipv6_get_addr_gen_mode (NMSetting *setting, NmcPropertyGetType get_type) -{ - NMSettingIP6Config *s_ip6 = NM_SETTING_IP6_CONFIG (setting); - NMSettingIP6ConfigAddrGenMode addr_gen_mode; - - addr_gen_mode = nm_setting_ip6_config_get_addr_gen_mode (s_ip6); - return nm_utils_enum_to_str (nm_setting_ip6_config_addr_gen_mode_get_type (), addr_gen_mode); -} - - -static gboolean -nmc_property_ipv6_set_addr_gen_mode (NMSetting *setting, const char *prop, - const char *val, GError **error) -{ - NMSettingIP6ConfigAddrGenMode addr_gen_mode; - - if (!nm_utils_enum_from_str (nm_setting_ip6_config_addr_gen_mode_get_type (), val, - (int *) &addr_gen_mode, NULL)) { - g_set_error (error, 1, 0, _("invalid option '%s', use one of [%s]"), - val, "eui64,stable-privacy"); - return FALSE; - } - - g_object_set (setting, prop, addr_gen_mode, NULL); - return TRUE; -} - -DEFINE_ALLOWED_FOR_ENUMS (nmc_property_ipv6_allowed_addr_gen_mode, - nm_setting_ip6_config_addr_gen_mode_get_type, - G_MININT, G_MAXINT) - - -/* --- NM_SETTING_MACSEC_SETTING_NAME property functions --- */ -DEFINE_GETTER (nmc_property_macsec_get_parent, NM_SETTING_MACSEC_PARENT) -DEFINE_GETTER (nmc_property_macsec_get_encrypt, NM_SETTING_MACSEC_ENCRYPT) -DEFINE_GETTER (nmc_property_macsec_get_mka_cak, NM_SETTING_MACSEC_MKA_CAK) -DEFINE_SECRET_FLAGS_GETTER (nmc_property_macsec_get_mka_cak_flags, NM_SETTING_MACSEC_MKA_CAK_FLAGS) -DEFINE_GETTER (nmc_property_macsec_get_mka_ckn, NM_SETTING_MACSEC_MKA_CKN) -DEFINE_GETTER (nmc_property_macsec_get_port, NM_SETTING_MACSEC_PORT) - -/* 'mode' */ -static char * -nmc_property_macsec_get_mode (NMSetting *setting, NmcPropertyGetType get_type) -{ - NMSettingMacsec *s_macsec = NM_SETTING_MACSEC (setting); - NMSettingMacsecMode mode; - - mode = nm_setting_macsec_get_mode (s_macsec); - return nm_utils_enum_to_str (nm_setting_macsec_mode_get_type (), mode); -} - -static gboolean -nmc_property_macsec_set_mode (NMSetting *setting, const char *prop, - const char *val, GError **error) -{ - NMSettingMacsecMode mode; - gs_free char *options = NULL; - - if (!nm_utils_enum_from_str (nm_setting_macsec_mode_get_type (), val, - (int *) &mode, NULL)) { - options = g_strjoinv (",", - (char **) nm_utils_enum_get_values (nm_setting_macsec_mode_get_type (), - G_MININT, - G_MAXINT)); - g_set_error (error, 1, 0, _("invalid option '%s', use one of [%s]"), - val, options); - return FALSE; - } - - g_object_set (setting, prop, mode, NULL); - return TRUE; -} - -DEFINE_ALLOWED_FOR_ENUMS (nmc_property_macsec_allowed_mode, - nm_setting_macsec_mode_get_type, - G_MININT, G_MAXINT) - -/* 'validation' */ -static char * -nmc_property_macsec_get_validation (NMSetting *setting, NmcPropertyGetType get_type) -{ - NMSettingMacsec *s_macsec = NM_SETTING_MACSEC (setting); - NMSettingMacsecValidation validation; - - validation = nm_setting_macsec_get_validation (s_macsec); - return nm_utils_enum_to_str (nm_setting_macsec_validation_get_type (), validation); -} - -static gboolean -nmc_property_macsec_set_validation (NMSetting *setting, const char *prop, - const char *val, GError **error) -{ - NMSettingMacsecMode validation; - gs_free char *options = NULL; - - if (!nm_utils_enum_from_str (nm_setting_macsec_validation_get_type (), val, - (int *) &validation, NULL)) { - options = g_strjoinv (",", - (char **) nm_utils_enum_get_values (nm_setting_macsec_validation_get_type (), - G_MININT, - G_MAXINT)); - g_set_error (error, 1, 0, _("invalid option '%s', use one of [%s]"), - val, options); - return FALSE; - } - - g_object_set (setting, prop, validation, NULL); - return TRUE; -} - -DEFINE_ALLOWED_FOR_ENUMS (nmc_property_macsec_allowed_validation, - nm_setting_macsec_validation_get_type, - G_MININT, G_MAXINT) - - -/* --- NM_SETTING_MACVLAN_SETTING_NAME property functions --- */ -DEFINE_GETTER (nmc_property_macvlan_get_parent, NM_SETTING_MACVLAN_PARENT) -DEFINE_GETTER (nmc_property_macvlan_get_promiscuous, NM_SETTING_MACVLAN_PROMISCUOUS) -DEFINE_GETTER (nmc_property_macvlan_get_tap, NM_SETTING_MACVLAN_TAP) - -static char * -nmc_property_macvlan_get_mode (NMSetting *setting, NmcPropertyGetType get_type) -{ - NMSettingMacvlan *s_macvlan = NM_SETTING_MACVLAN (setting); - NMSettingMacvlanMode mode; - char *tmp, *str; - - mode = nm_setting_macvlan_get_mode (s_macvlan); - tmp = nm_utils_enum_to_str (nm_setting_macvlan_mode_get_type (), mode); - - if (get_type == NMC_PROPERTY_GET_PARSABLE) - str = g_strdup (tmp ? tmp : ""); - else - str = g_strdup_printf ("%d (%s)", mode, tmp ? tmp : ""); - g_free (tmp); - - return str; -} - -static gboolean -nmc_property_macvlan_set_mode (NMSetting *setting, const char *prop, - const char *val, GError **error) -{ - NMSettingMacvlanMode mode; - gs_free const char **options = NULL; - gs_free char *options_str = NULL; - long int t; - gboolean ret; - - if (nmc_string_to_int_base (val, 0, TRUE, 0, _NM_SETTING_MACVLAN_MODE_NUM - 1, &t)) - mode = (NMSettingMacvlanMode) t; - else { - ret = nm_utils_enum_from_str (nm_setting_macvlan_mode_get_type (), val, - (int *) &mode, NULL); - - if (!ret) { - options = nm_utils_enum_get_values (nm_setting_macvlan_mode_get_type(), - NM_SETTING_MACVLAN_MODE_UNKNOWN + 1, - G_MAXINT); - options_str = g_strjoinv (",", (char **) options); - g_set_error (error, 1, 0, _("invalid option '%s', use one of [%s]"), - val, options_str); - return FALSE; - } - } - - g_object_set (setting, prop, (guint) mode, NULL); - return TRUE; -} - -DEFINE_ALLOWED_FOR_ENUMS (nmc_property_macvlan_allowed_mode, - nm_setting_macvlan_mode_get_type, - NM_SETTING_MACVLAN_MODE_UNKNOWN + 1, G_MAXINT) - - -/* --- NM_SETTING_OLPC_MESH_SETTING_NAME property functions --- */ -DEFINE_GETTER (nmc_property_olpc_get_channel, NM_SETTING_OLPC_MESH_CHANNEL) -DEFINE_GETTER (nmc_property_olpc_get_anycast_address, NM_SETTING_OLPC_MESH_DHCP_ANYCAST_ADDRESS) - -static char * -nmc_property_olpc_get_ssid (NMSetting *setting, NmcPropertyGetType get_type) -{ - NMSettingOlpcMesh *s_olpc_mesh = NM_SETTING_OLPC_MESH (setting); - GBytes *ssid; - char *ssid_str = NULL; - - ssid = nm_setting_olpc_mesh_get_ssid (s_olpc_mesh); - if (ssid) { - ssid_str = nm_utils_ssid_to_utf8 (g_bytes_get_data (ssid, NULL), - g_bytes_get_size (ssid)); - } - - return ssid_str; -} - -static gboolean -nmc_property_olpc_set_channel (NMSetting *setting, const char *prop, const char *val, GError **error) -{ - unsigned long chan_int; - - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - - if (!nmc_string_to_uint (val, TRUE, 1, 13, &chan_int)) { - g_set_error (error, 1, 0, _("'%s' is not a valid channel; use <1-13>"), val); - return FALSE; - } - g_object_set (setting, prop, chan_int, NULL); - return TRUE; -} - - -/* --- NM_SETTING_PPP_SETTING_NAME property functions --- */ -DEFINE_GETTER (nmc_property_ppp_get_noauth, NM_SETTING_PPP_NOAUTH) -DEFINE_GETTER (nmc_property_ppp_get_refuse_eap, NM_SETTING_PPP_REFUSE_EAP) -DEFINE_GETTER (nmc_property_ppp_get_refuse_pap, NM_SETTING_PPP_REFUSE_PAP) -DEFINE_GETTER (nmc_property_ppp_get_refuse_chap, NM_SETTING_PPP_REFUSE_CHAP) -DEFINE_GETTER (nmc_property_ppp_get_refuse_mschap, NM_SETTING_PPP_REFUSE_MSCHAP) -DEFINE_GETTER (nmc_property_ppp_get_refuse_mschapv2, NM_SETTING_PPP_REFUSE_MSCHAPV2) -DEFINE_GETTER (nmc_property_ppp_get_nobsdcomp, NM_SETTING_PPP_NOBSDCOMP) -DEFINE_GETTER (nmc_property_ppp_get_nodeflate, NM_SETTING_PPP_NODEFLATE) -DEFINE_GETTER (nmc_property_ppp_get_no_vj_comp, NM_SETTING_PPP_NO_VJ_COMP) -DEFINE_GETTER (nmc_property_ppp_get_require_mppe, NM_SETTING_PPP_REQUIRE_MPPE) -DEFINE_GETTER (nmc_property_ppp_get_require_mppe_128, NM_SETTING_PPP_REQUIRE_MPPE_128) -DEFINE_GETTER (nmc_property_ppp_get_mppe_stateful, NM_SETTING_PPP_MPPE_STATEFUL) -DEFINE_GETTER (nmc_property_ppp_get_crtscts, NM_SETTING_PPP_CRTSCTS) -DEFINE_GETTER (nmc_property_ppp_get_baud, NM_SETTING_PPP_BAUD) -DEFINE_GETTER (nmc_property_ppp_get_mru, NM_SETTING_PPP_MRU) -DEFINE_GETTER (nmc_property_ppp_get_mtu, NM_SETTING_PPP_MTU) -DEFINE_GETTER (nmc_property_ppp_get_lcp_echo_failure, NM_SETTING_PPP_LCP_ECHO_FAILURE) -DEFINE_GETTER (nmc_property_ppp_get_lcp_echo_interval, NM_SETTING_PPP_LCP_ECHO_INTERVAL) - - -/* --- NM_SETTING_PPPOE_SETTING_NAME property functions --- */ -DEFINE_GETTER (nmc_property_pppoe_get_service, NM_SETTING_PPPOE_SERVICE) -DEFINE_GETTER (nmc_property_pppoe_get_username, NM_SETTING_PPPOE_USERNAME) -DEFINE_GETTER (nmc_property_pppoe_get_password, NM_SETTING_PPPOE_PASSWORD) -DEFINE_SECRET_FLAGS_GETTER (nmc_property_pppoe_get_password_flags, NM_SETTING_PPPOE_PASSWORD_FLAGS) - - -/* --- NM_SETTING_PROXY_SETTING_NAME property functions --- */ -DEFINE_GETTER (nmc_property_proxy_get_browser_only, NM_SETTING_PROXY_BROWSER_ONLY) -DEFINE_GETTER (nmc_property_proxy_get_pac_url, NM_SETTING_PROXY_PAC_URL) -DEFINE_GETTER (nmc_property_proxy_get_pac_script, NM_SETTING_PROXY_PAC_SCRIPT) - -static char * -nmc_property_proxy_get_method (NMSetting *setting, NmcPropertyGetType get_type) -{ - NMSettingProxy *s_proxy = NM_SETTING_PROXY (setting); - NMSettingProxyMethod method; - - method = nm_setting_proxy_get_method (s_proxy); - return nm_utils_enum_to_str (nm_setting_proxy_method_get_type (), method); -} - -static gboolean -nmc_property_proxy_set_method (NMSetting *setting, const char *prop, - const char *val, GError **error) -{ - int method; - gboolean ret; - - ret = nm_utils_enum_from_str (nm_setting_proxy_method_get_type(), val, - &method, NULL); - - if (!ret) { - gs_free const char **values = NULL; - gs_free char *values_str = NULL; - - values = nm_utils_enum_get_values (nm_setting_proxy_method_get_type (), - NM_SETTING_PROXY_METHOD_NONE, - G_MAXINT); - values_str = g_strjoinv (",", (char **) values); - g_set_error (error, 1, 0, _("invalid method '%s', use one of %s"), - val, values_str); - - return FALSE; - } - - g_object_set (setting, prop, method, NULL); - return TRUE; -} - -DEFINE_ALLOWED_FOR_ENUMS (nmc_property_proxy_allowed_method, - nm_setting_proxy_method_get_type, - NM_SETTING_PROXY_METHOD_NONE, G_MAXINT) - -static gboolean -nmc_property_proxy_set_pac_script (NMSetting *setting, const char *prop, - const char *val, GError **error) -{ - char *script = NULL; - - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - - if (!nmc_proxy_check_script (val, &script, error)) { - return FALSE; - } - g_object_set (setting, prop, script, NULL); - g_free (script); - return TRUE; -} - - -/* --- NM_SETTING_SERIAL_SETTING_NAME property functions --- */ -DEFINE_GETTER (nmc_property_serial_get_baud, NM_SETTING_SERIAL_BAUD) -DEFINE_GETTER (nmc_property_serial_get_bits, NM_SETTING_SERIAL_BITS) -DEFINE_GETTER (nmc_property_serial_get_stopbits, NM_SETTING_SERIAL_STOPBITS) -DEFINE_GETTER (nmc_property_serial_get_send_delay, NM_SETTING_SERIAL_SEND_DELAY) - -static char * -nmc_property_serial_get_parity (NMSetting *setting, NmcPropertyGetType get_type) -{ - NMSettingSerial *s_serial = NM_SETTING_SERIAL (setting); - - switch (nm_setting_serial_get_parity (s_serial)) { - case NM_SETTING_SERIAL_PARITY_EVEN: - return g_strdup ("even"); - case NM_SETTING_SERIAL_PARITY_ODD: - return g_strdup ("odd"); - default: - case NM_SETTING_SERIAL_PARITY_NONE: - return g_strdup ("none"); - } -} - -static gboolean -nmc_property_serial_set_parity (NMSetting *setting, const char *prop, const char *val, GError **error) -{ - NMSettingSerialParity parity; - - if (val[0] == 'E' || val[0] == 'e') - parity = NM_SETTING_SERIAL_PARITY_EVEN; - else if (val[0] == 'O' || val[0] == 'o') - parity = NM_SETTING_SERIAL_PARITY_ODD; - else if (val[0] == 'N' || val[0] == 'n') - parity = NM_SETTING_SERIAL_PARITY_NONE; - else { - g_set_error (error, 1, 0, _("'%s' is not valid; use [e, o, n]"), val); - return FALSE; - } - - g_object_set (setting, prop, parity, NULL); - return TRUE; -} - - -/* --- NM_SETTING_TEAM_SETTING_NAME property functions --- */ -DEFINE_GETTER (nmc_property_team_get_config, NM_SETTING_TEAM_CONFIG) - -static gboolean -nmc_property_team_set_config (NMSetting *setting, const char *prop, const char *val, GError **error) -{ - char *json = NULL; - - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - - if (!nmc_team_check_config (val, &json, error)) { - return FALSE; - } - g_object_set (setting, prop, json, NULL); - g_free (json); - return TRUE; -} - -static const char * -nmc_property_team_describe_config (NMSetting *setting, const char *prop) -{ - return _("nmcli can accepts both direct JSON configuration data and a file name containing " - "the configuration. In the latter case the file is read and the contents is put " - "into this property.\n\n" - "Examples: set team.config " - "{ \"device\": \"team0\", \"runner\": {\"name\": \"roundrobin\"}, \"ports\": {\"eth1\": {}, \"eth2\": {}} }\n" - " set team.config /etc/my-team.conf\n"); -} - - -/* --- NM_SETTING_TEAM_PORT_SETTING_NAME property functions --- */ -DEFINE_GETTER (nmc_property_team_port_get_config, NM_SETTING_TEAM_PORT_CONFIG) - - -/* --- NM_SETTING_TUN_SETTING_NAME property functions --- */ -DEFINE_GETTER (nmc_property_tun_get_owner, NM_SETTING_TUN_OWNER); -DEFINE_GETTER (nmc_property_tun_get_group, NM_SETTING_TUN_GROUP); -DEFINE_GETTER (nmc_property_tun_get_pi, NM_SETTING_TUN_PI); -DEFINE_GETTER (nmc_property_tun_get_vnet_hdr, NM_SETTING_TUN_VNET_HDR); -DEFINE_GETTER (nmc_property_tun_get_multi_queue, NM_SETTING_TUN_MULTI_QUEUE); - -static char * -nmc_property_tun_get_mode (NMSetting *setting, NmcPropertyGetType get_type) -{ - NMSettingTun *s_tun = NM_SETTING_TUN (setting); - NMSettingTunMode mode; - char *tmp, *str; - - mode = nm_setting_tun_get_mode (s_tun); - tmp = nm_utils_enum_to_str (nm_setting_tun_mode_get_type (), mode); - if (get_type == NMC_PROPERTY_GET_PARSABLE) - str = g_strdup_printf ("%s", tmp ? tmp : ""); - else - str = g_strdup_printf ("%d (%s)", mode, tmp ? tmp : ""); - g_free (tmp); - return str; -} - -static gboolean -nmc_property_tun_set_mode (NMSetting *setting, const char *prop, - const char *val, GError **error) -{ - NMSettingTunMode mode; - gboolean ret; - long int t; - - if (nmc_string_to_int_base (val, 0, TRUE, 0, NM_SETTING_TUN_MODE_TAP, &t)) - mode = (NMSettingTunMode) t; - else { - ret = nm_utils_enum_from_str (nm_setting_tun_mode_get_type (), val, - (int *) &mode, NULL); - - if (!ret) { - g_set_error (error, 1, 0, _("invalid option '%s', use '%s' or '%s'"), - val, "tun", "tap"); - return FALSE; - } - } - - g_object_set (setting, prop, (guint) mode, NULL); - return TRUE; -} - -static const char *tun_valid_modes[] = { "tun", "tap", "unknown", NULL }; - -DEFINE_ALLOWED_VAL_FUNC (nmc_property_tun_allowed_mode, tun_valid_modes) - - -/* --- NM_SETTING_VLAN_SETTING_NAME property functions --- */ -DEFINE_GETTER (nmc_property_vlan_get_parent, NM_SETTING_VLAN_PARENT) -DEFINE_GETTER (nmc_property_vlan_get_id, NM_SETTING_VLAN_ID) - -static char * -nmc_property_vlan_get_flags (NMSetting *setting, NmcPropertyGetType get_type) -{ - NMSettingVlan *s_vlan = NM_SETTING_VLAN (setting); - return vlan_flags_to_string (nm_setting_vlan_get_flags (s_vlan), get_type); -} - -static char * -nmc_property_vlan_get_ingress_priority_map (NMSetting *setting, NmcPropertyGetType get_type) -{ - NMSettingVlan *s_vlan = NM_SETTING_VLAN (setting); - return vlan_priorities_to_string (s_vlan, NM_VLAN_INGRESS_MAP); -} - -static char * -nmc_property_vlan_get_egress_priority_map (NMSetting *setting, NmcPropertyGetType get_type) -{ - NMSettingVlan *s_vlan = NM_SETTING_VLAN (setting); - return vlan_priorities_to_string (s_vlan, NM_VLAN_EGRESS_MAP); -} - -static gboolean -nmc_property_vlan_set_prio_map (NMSetting *setting, - const char *prop, - const char *val, - NMVlanPriorityMap map_type, - GError **error) -{ - char **prio_map, **p; - - prio_map = nmc_vlan_parse_priority_maps (val, map_type, error); - if (!prio_map) - return FALSE; - - for (p = prio_map; p && *p; p++) - nm_setting_vlan_add_priority_str (NM_SETTING_VLAN (setting), map_type, *p); - - g_strfreev (prio_map); - return TRUE; -} - -static gboolean -nmc_property_vlan_remove_prio_map (NMSetting *setting, - const char *prop, - guint32 idx, - NMVlanPriorityMap map_type, - GError **error) -{ - guint32 num; - - num = nm_setting_vlan_get_num_priorities (NM_SETTING_VLAN (setting), map_type); - if (num == 0) { - g_set_error_literal (error, 1, 0, _("no priority to remove")); - return FALSE; - } - if (idx >= num) { - g_set_error (error, 1, 0, _("index '%d' is not in the range of <0-%d>"), - idx, num - 1); - return FALSE; - } - - nm_setting_vlan_remove_priority (NM_SETTING_VLAN (setting), map_type, idx); - return TRUE; -} - -static gboolean -nmc_property_vlan_set_ingress_priority_map (NMSetting *setting, const char *prop, const char *val, GError **error) -{ - return nmc_property_vlan_set_prio_map (setting, prop, val, NM_VLAN_INGRESS_MAP, error); -} - -static gboolean -nmc_property_vlan_set_egress_priority_map (NMSetting *setting, const char *prop, const char *val, GError **error) -{ - return nmc_property_vlan_set_prio_map (setting, prop, val, NM_VLAN_EGRESS_MAP, error); -} - -static gboolean -nmc_property_vlan_remove_priority_map (NMSetting *setting, - const char *prop, - const char *value, - guint32 idx, - NMVlanPriorityMap map, - GError **error) -{ - /* If value != NULL, remove by value */ - if (value) { - gboolean ret; - char **prio_map; - char *val = g_strdup (value); - - prio_map = nmc_vlan_parse_priority_maps (val, map, error); - if (!prio_map) - return FALSE; - if (prio_map[1]) - g_print (_("Warning: only one mapping at a time is supported; taking the first one (%s)\n"), - prio_map[0]); - ret = nm_setting_vlan_remove_priority_str_by_value (NM_SETTING_VLAN (setting), - map, - prio_map[0]); - - if (!ret) - g_set_error (error, 1, 0, _("the property doesn't contain mapping '%s'"), prio_map[0]); - g_free (val); - g_strfreev (prio_map); - return ret; - } - - /* Else remove by index */ - return nmc_property_vlan_remove_prio_map (setting, prop, idx, map, error); -} - -static gboolean -nmc_property_vlan_remove_ingress_priority_map (NMSetting *setting, - const char *prop, - const char *value, - guint32 idx, - GError **error) -{ - return nmc_property_vlan_remove_priority_map (setting, - prop, - value, - idx, - NM_VLAN_INGRESS_MAP, - error); -} - -static gboolean -nmc_property_vlan_remove_egress_priority_map (NMSetting *setting, - const char *prop, - const char *value, - guint32 idx, - GError **error) -{ - return nmc_property_vlan_remove_priority_map (setting, - prop, - value, - idx, - NM_VLAN_EGRESS_MAP, - error); -} - - -/* --- NM_SETTING_VPN_SETTING_NAME property functions --- */ -DEFINE_GETTER (nmc_property_vpn_get_service_type, NM_SETTING_VPN_SERVICE_TYPE) -DEFINE_GETTER (nmc_property_vpn_get_user_name, NM_SETTING_VPN_USER_NAME) - -static char * -nmc_property_vpn_get_data (NMSetting *setting, NmcPropertyGetType get_type) -{ - NMSettingVpn *s_vpn = NM_SETTING_VPN (setting); - GString *data_item_str; +#include "nm-client-utils.h" +#include "nm-vpn-helpers.h" - data_item_str = g_string_new (NULL); - nm_setting_vpn_foreach_data_item (s_vpn, &vpn_data_item, data_item_str); +#include "utils.h" +#include "common.h" - return g_string_free (data_item_str, FALSE); -} +/*****************************************************************************/ -static char * -nmc_property_vpn_get_secrets (NMSetting *setting, NmcPropertyGetType get_type) +static const NMMetaSettingInfoEditor * +_meta_find_setting_info_by_name (const char *setting_name) { - NMSettingVpn *s_vpn = NM_SETTING_VPN (setting); - GString *secret_str; + const NMMetaSettingInfo *meta_setting_info; + const NMMetaSettingInfoEditor *setting_info; - secret_str = g_string_new (NULL); - nm_setting_vpn_foreach_secret (s_vpn, &vpn_data_item, secret_str); + g_return_val_if_fail (setting_name, NULL); - return g_string_free (secret_str, FALSE); -} - -DEFINE_GETTER (nmc_property_vpn_get_persistent, NM_SETTING_VPN_PERSISTENT) -DEFINE_GETTER (nmc_property_vpn_get_timeout, NM_SETTING_VPN_TIMEOUT) + meta_setting_info = nm_meta_setting_infos_by_name (setting_name); -/* Validate value of vpn 'data' and 'secret' options */ -static const char * -_validate_vpn_hash_value (const char *option, const char *value, GError **error) -{ - /* nm_setting_vpn_add_data_item() and nm_setting_vpn_add_secret() does not - * allow empty strings */ - if (!value || !*value) { - g_set_error (error, 1, 0, _("'%s' cannot be empty"), option); + if (!meta_setting_info) return NULL; - } - return value; -} - -/* 'data' */ -DEFINE_SETTER_OPTIONS (nmc_property_vpn_set_data, - NM_SETTING_VPN, - NMSettingVpn, - nm_setting_vpn_add_data_item, - NULL, - _validate_vpn_hash_value) -DEFINE_REMOVER_OPTION (nmc_property_vpn_remove_option_data, - NM_SETTING_VPN, - nm_setting_vpn_remove_data_item) - -/* 'secrets' */ -DEFINE_SETTER_OPTIONS (nmc_property_vpn_set_secrets, - NM_SETTING_VPN, - NMSettingVpn, - nm_setting_vpn_add_secret, - NULL, - _validate_vpn_hash_value) -DEFINE_REMOVER_OPTION (nmc_property_vpn_remove_option_secret, - NM_SETTING_VPN, - nm_setting_vpn_remove_secret) - - -/* --- NM_SETTING_VXLAN_SETTING_NAME property functions --- */ -DEFINE_GETTER (nmc_property_vxlan_get_parent, NM_SETTING_VXLAN_PARENT) -DEFINE_GETTER (nmc_property_vxlan_get_id, NM_SETTING_VXLAN_ID) -DEFINE_GETTER (nmc_property_vxlan_get_local, NM_SETTING_VXLAN_LOCAL) -DEFINE_GETTER (nmc_property_vxlan_get_remote, NM_SETTING_VXLAN_REMOTE) -DEFINE_GETTER (nmc_property_vxlan_get_source_port_min, NM_SETTING_VXLAN_SOURCE_PORT_MIN) -DEFINE_GETTER (nmc_property_vxlan_get_source_port_max, NM_SETTING_VXLAN_SOURCE_PORT_MAX) -DEFINE_GETTER (nmc_property_vxlan_get_destination_port, NM_SETTING_VXLAN_DESTINATION_PORT) -DEFINE_GETTER (nmc_property_vxlan_get_tos, NM_SETTING_VXLAN_TOS) -DEFINE_GETTER (nmc_property_vxlan_get_ttl, NM_SETTING_VXLAN_TTL) -DEFINE_GETTER (nmc_property_vxlan_get_ageing, NM_SETTING_VXLAN_AGEING) -DEFINE_GETTER (nmc_property_vxlan_get_limit, NM_SETTING_VXLAN_LIMIT) -DEFINE_GETTER (nmc_property_vxlan_get_learning, NM_SETTING_VXLAN_LEARNING) -DEFINE_GETTER (nmc_property_vxlan_get_proxy, NM_SETTING_VXLAN_PROXY) -DEFINE_GETTER (nmc_property_vxlan_get_rsc, NM_SETTING_VXLAN_RSC) -DEFINE_GETTER (nmc_property_vxlan_get_l2_miss, NM_SETTING_VXLAN_L2_MISS) -DEFINE_GETTER (nmc_property_vxlan_get_l3_miss, NM_SETTING_VXLAN_L3_MISS) - - -/* --- NM_SETTING_WIMAX_SETTING_NAME property functions --- */ -DEFINE_GETTER (nmc_property_wimax_get_network_name, NM_SETTING_WIMAX_NETWORK_NAME) -DEFINE_GETTER (nmc_property_wimax_get_mac_address, NM_SETTING_WIMAX_MAC_ADDRESS) - - -/* --- NM_SETTING_WIRED_SETTING_NAME property functions --- */ -DEFINE_GETTER (nmc_property_wired_get_port, NM_SETTING_WIRED_PORT) -DEFINE_GETTER (nmc_property_wired_get_auto_negotiate, NM_SETTING_WIRED_AUTO_NEGOTIATE) -DEFINE_GETTER (nmc_property_wired_get_mac_address, NM_SETTING_WIRED_MAC_ADDRESS) -DEFINE_GETTER (nmc_property_wired_get_cloned_mac_address, NM_SETTING_WIRED_CLONED_MAC_ADDRESS) -DEFINE_GETTER (nmc_property_wired_get_generate_mac_address_mask, NM_SETTING_WIRED_GENERATE_MAC_ADDRESS_MASK) -DEFINE_GETTER (nmc_property_wired_get_mac_address_blacklist, NM_SETTING_WIRED_MAC_ADDRESS_BLACKLIST) -DEFINE_GETTER (nmc_property_wired_get_s390_subchannels, NM_SETTING_WIRED_S390_SUBCHANNELS) -DEFINE_GETTER (nmc_property_wired_get_s390_nettype, NM_SETTING_WIRED_S390_NETTYPE) -DEFINE_GETTER (nmc_property_wired_get_s390_options, NM_SETTING_WIRED_S390_OPTIONS) -DEFINE_GETTER (nmc_property_wired_get_wake_on_lan_password, NM_SETTING_WIRED_WAKE_ON_LAN_PASSWORD) - -static char * -nmc_property_wired_get_speed (NMSetting *setting, NmcPropertyGetType get_type) -{ - NMSettingWired *s_wired = NM_SETTING_WIRED (setting); - guint32 speed; - - speed = nm_setting_wired_get_speed (s_wired); - return g_strdup_printf ("%d", speed); -} -static char * -nmc_property_wired_get_duplex (NMSetting *setting, NmcPropertyGetType get_type) -{ - NMSettingWired *s_wired = NM_SETTING_WIRED (setting); - const char *str; + g_return_val_if_fail (nm_streq0 (meta_setting_info->setting_name, setting_name), NULL); - str = nm_setting_wired_get_duplex (s_wired); - if (!str) + if (meta_setting_info->meta_type >= G_N_ELEMENTS (nm_meta_setting_infos_editor)) return NULL; - else - return g_strdup (str); - -} - -static char * -nmc_property_wired_get_mtu (NMSetting *setting, NmcPropertyGetType get_type) -{ - NMSettingWired *s_wired = NM_SETTING_WIRED (setting); - int mtu; - - mtu = nm_setting_wired_get_mtu (s_wired); - if (mtu == 0) - return g_strdup (_("auto")); - else - return g_strdup_printf ("%d", mtu); -} - -static char * -nmc_property_wired_get_wake_on_lan (NMSetting *setting, NmcPropertyGetType get_type) -{ - NMSettingWired *s_wired = NM_SETTING_WIRED (setting); - NMSettingWiredWakeOnLan wol; - char *tmp, *str; - - wol = nm_setting_wired_get_wake_on_lan (s_wired); - tmp = nm_utils_enum_to_str (nm_setting_wired_wake_on_lan_get_type (), wol); - if (get_type == NMC_PROPERTY_GET_PARSABLE) - str = g_strdup_printf ("%s", tmp && *tmp ? tmp : "none"); - else - str = g_strdup_printf ("%d (%s)", wol, tmp && *tmp ? tmp : "none"); - g_free (tmp); - return str; -} - -static gboolean -nmc_property_wired_set_wake_on_lan (NMSetting *setting, const char *prop, - const char *val, GError **error) -{ - NMSettingWiredWakeOnLan wol; - gs_free char *err_token = NULL; - gboolean ret; - long int t; - - if (nmc_string_to_int_base (val, 0, TRUE, 0, - NM_SETTING_WIRED_WAKE_ON_LAN_ALL - | NM_SETTING_WIRED_WAKE_ON_LAN_EXCLUSIVE_FLAGS, - &t)) - wol = (NMSettingWiredWakeOnLan) t; - else { - ret = nm_utils_enum_from_str (nm_setting_wired_wake_on_lan_get_type (), val, - (int *) &wol, &err_token); - - if (!ret) { - if ( g_ascii_strcasecmp (err_token, "none") == 0 - || g_ascii_strcasecmp (err_token, "disable") == 0 - || g_ascii_strcasecmp (err_token, "disabled") == 0) - wol = NM_SETTING_WIRED_WAKE_ON_LAN_NONE; - else { - g_set_error (error, 1, 0, _("invalid option '%s', use a combination of [%s] or 'ignore', 'default' or 'none'"), - err_token, - nm_utils_enum_to_str (nm_setting_wired_wake_on_lan_get_type (), - NM_SETTING_WIRED_WAKE_ON_LAN_ALL)); - return FALSE; - } - } - } - - if ( NM_FLAGS_ANY (wol, NM_SETTING_WIRED_WAKE_ON_LAN_EXCLUSIVE_FLAGS) - && !nm_utils_is_power_of_two (wol)) { - g_set_error_literal (error, 1, 0, _("'default' and 'ignore' are incompatible with other flags")); - return FALSE; - } - g_object_set (setting, prop, (guint) wol, NULL); - return TRUE; -} + setting_info = &nm_meta_setting_infos_editor[meta_setting_info->meta_type]; -#if 0 --/* -- * Do not allow setting 'port' for now. It is not implemented in -- * NM core, nor in ifcfg-rh plugin. Enable this when it gets done. -- */ -/* 'port' */ -static const char *wired_valid_ports[] = { "tp", "aui", "bnc", "mii", NULL }; + g_return_val_if_fail (setting_info->general == meta_setting_info, NULL); -static gboolean -nmc_property_wired_set_port (NMSetting *setting, const char *prop, const char *val, GError **error) -{ - return check_and_set_string (setting, prop, val, wired_valid_ports, error); + return setting_info; } -DEFINE_ALLOWED_VAL_FUNC (nmc_property_wired_allowed_port, wired_valid_ports) -#endif - -/* 'duplex' */ -static const char *wired_valid_duplexes[] = { "half", "full", NULL }; - -static gboolean -nmc_property_wired_set_duplex (NMSetting *setting, const char *prop, const char *val, GError **error) +static const NMMetaSettingInfoEditor * +_meta_find_setting_info_by_gtype (GType gtype) { - return check_and_set_string (setting, prop, val, wired_valid_duplexes, error); -} - -DEFINE_ALLOWED_VAL_FUNC (nmc_property_wired_allowed_duplex, wired_valid_duplexes) + const NMMetaSettingInfo *meta_setting_info; + const NMMetaSettingInfoEditor *setting_info; + meta_setting_info = nm_meta_setting_infos_by_gtype (gtype); -/* 'mac-address-blacklist' */ -DEFINE_SETTER_MAC_BLACKLIST (nmc_property_wired_set_mac_address_blacklist, - NM_SETTING_WIRED, - nm_setting_wired_add_mac_blacklist_item) - -static gboolean -_validate_and_remove_wired_mac_blacklist_item (NMSettingWired *setting, - const char *mac, - GError **error) -{ - gboolean ret; - guint8 buf[32]; - - if (!nm_utils_hwaddr_aton (mac, buf, ETH_ALEN)) { - g_set_error (error, 1, 0, _("'%s' is not a valid MAC address"), mac); - return FALSE; - } - - ret = nm_setting_wired_remove_mac_blacklist_item_by_value (setting, mac); - if (!ret) - g_set_error (error, 1, 0, _("the property doesn't contain MAC address '%s'"), mac); - return ret; -} -DEFINE_REMOVER_INDEX_OR_VALUE (nmc_property_wired_remove_mac_address_blacklist, - NM_SETTING_WIRED, - nm_setting_wired_get_num_mac_blacklist_items, - nm_setting_wired_remove_mac_blacklist_item, - _validate_and_remove_wired_mac_blacklist_item) - -/* 's390-subchannels' */ -static gboolean -nmc_property_wired_set_s390_subchannels (NMSetting *setting, const char *prop, const char *val, GError **error) -{ - char **strv = NULL; - int len; - - strv = nmc_strsplit_set (val, " ,\t", 0); - len = g_strv_length (strv); - if (len != 2 && len != 3) { - g_set_error (error, 1, 0, _("'%s' is not valid; 2 or 3 strings should be provided"), - val); - g_strfreev (strv); - return FALSE; - } - - g_object_set (setting, prop, strv, NULL); - g_strfreev (strv); - return TRUE; -} - -static const char * -nmc_property_wired_describe_s390_subchannels (NMSetting *setting, const char *prop) -{ - return _("Enter a list of subchannels (comma or space separated).\n\n" - "Example: 0.0.0e20 0.0.0e21 0.0.0e22\n"); -} - -/* 's390-nettype' */ -static const char *wired_valid_s390_nettypes[] = { "qeth", "lcs", "ctc", NULL }; - -static gboolean -nmc_property_wired_set_s390_nettype (NMSetting *setting, const char *prop, const char *val, GError **error) -{ - return check_and_set_string (setting, prop, val, wired_valid_s390_nettypes, error); -} - -DEFINE_ALLOWED_VAL_FUNC (nmc_property_wired_allowed_s390_nettype, wired_valid_s390_nettypes) - -/* 's390-options' */ -/* Validate value of 's390-options' */ -static const char * -_validate_s390_option_value (const char *option, const char *value, GError **error) -{ - /* nm_setting_wired_add_s390_option() requires value len in <1,199> interval */ - if (!value || !*value || strlen (value) >= 200) { - g_set_error (error, 1, 0, _("'%s' string value should consist of 1 - 199 characters"), option); + if (!meta_setting_info) return NULL; - } - return value; -} -DEFINE_SETTER_OPTIONS (nmc_property_wired_set_s390_options, - NM_SETTING_WIRED, - NMSettingWired, - nm_setting_wired_add_s390_option, - nm_setting_wired_get_valid_s390_options, - _validate_s390_option_value) -DEFINE_REMOVER_OPTION (nmc_property_wired_remove_option_s390_options, - NM_SETTING_WIRED, - nm_setting_wired_remove_s390_option) - -static const char ** -nmc_property_wired_allowed_s390_options (NMSetting *setting, const char *prop) -{ - return nm_setting_wired_get_valid_s390_options (NM_SETTING_WIRED (setting)); -} - -static const char * -nmc_property_wired_describe_s390_options (NMSetting *setting, const char *prop) -{ - static char *desc = NULL; - const char **valid_options; - char *options_str; - - if (G_UNLIKELY (desc == NULL)) { - valid_options = nm_setting_wired_get_valid_s390_options (NM_SETTING_WIRED (setting)); - options_str = g_strjoinv (", ", (char **) valid_options); - - desc = g_strdup_printf (_("Enter a list of S/390 options formatted as:\n" - " option = <value>, option = <value>,...\n" - "Valid options are: %s\n"), - options_str); - g_free (options_str); - } - return desc; -} - - -/* --- NM_SETTING_WIRELESS_SETTING_NAME property functions --- */ -DEFINE_GETTER (nmc_property_wireless_get_mode, NM_SETTING_WIRELESS_MODE) -DEFINE_GETTER (nmc_property_wireless_get_band, NM_SETTING_WIRELESS_BAND) -DEFINE_GETTER (nmc_property_wireless_get_channel, NM_SETTING_WIRELESS_CHANNEL) -DEFINE_GETTER (nmc_property_wireless_get_bssid, NM_SETTING_WIRELESS_BSSID) -DEFINE_GETTER (nmc_property_wireless_get_rate, NM_SETTING_WIRELESS_RATE) -DEFINE_GETTER (nmc_property_wireless_get_tx_power, NM_SETTING_WIRELESS_TX_POWER) -DEFINE_GETTER (nmc_property_wireless_get_mac_address, NM_SETTING_WIRELESS_MAC_ADDRESS) -DEFINE_GETTER (nmc_property_wireless_get_cloned_mac_address, NM_SETTING_WIRELESS_CLONED_MAC_ADDRESS) -DEFINE_GETTER (nmc_property_wireless_get_generate_mac_address_mask, NM_SETTING_WIRELESS_GENERATE_MAC_ADDRESS_MASK) -DEFINE_GETTER (nmc_property_wireless_get_mac_address_blacklist, NM_SETTING_WIRELESS_MAC_ADDRESS_BLACKLIST) -DEFINE_GETTER (nmc_property_wireless_get_seen_bssids, NM_SETTING_WIRELESS_SEEN_BSSIDS) -DEFINE_GETTER (nmc_property_wireless_get_hidden, NM_SETTING_WIRELESS_HIDDEN) - -static char * -nmc_property_wireless_get_ssid (NMSetting *setting, NmcPropertyGetType get_type) -{ - NMSettingWireless *s_wireless = NM_SETTING_WIRELESS (setting); - GBytes *ssid; - char *ssid_str = NULL; - - ssid = nm_setting_wireless_get_ssid (s_wireless); - if (ssid) { - ssid_str = nm_utils_ssid_to_utf8 (g_bytes_get_data (ssid, NULL), - g_bytes_get_size (ssid)); - } - - return ssid_str; -} - -static char * -nmc_property_wireless_get_mtu (NMSetting *setting, NmcPropertyGetType get_type) -{ - NMSettingWireless *s_wireless = NM_SETTING_WIRELESS (setting); - int mtu; - mtu = nm_setting_wireless_get_mtu (s_wireless); - if (mtu == 0) - return g_strdup (_("auto")); - else - return g_strdup_printf ("%d", mtu); -} + g_return_val_if_fail (meta_setting_info->get_setting_gtype, NULL); + g_return_val_if_fail (meta_setting_info->get_setting_gtype () == gtype, NULL); -static char * -nmc_property_wireless_get_powersave (NMSetting *setting, NmcPropertyGetType get_type) -{ - NMSettingWireless *s_wireless = NM_SETTING_WIRELESS (setting); - NMSettingWirelessPowersave powersave; - gs_free char *str = NULL; - char *ret; - - powersave = nm_setting_wireless_get_powersave (s_wireless); - str = nm_utils_enum_to_str (nm_setting_wireless_powersave_get_type (), powersave); - - if (get_type == NMC_PROPERTY_GET_PARSABLE) { - ret = str; - str = NULL; - return ret; - } else - return g_strdup_printf ("%s (%u)", str, powersave); -} + if (meta_setting_info->meta_type >= G_N_ELEMENTS (nm_meta_setting_infos_editor)) + return NULL; -static char * -nmc_property_wireless_get_mac_address_randomization (NMSetting *setting, NmcPropertyGetType get_type) -{ - NMSettingWireless *s_wifi = NM_SETTING_WIRELESS (setting); - NMSettingMacRandomization randomization = nm_setting_wireless_get_mac_address_randomization (s_wifi); - - if (randomization == NM_SETTING_MAC_RANDOMIZATION_DEFAULT) - return g_strdup (_("default")); - else if (randomization == NM_SETTING_MAC_RANDOMIZATION_NEVER) - return g_strdup (_("never")); - else if (randomization == NM_SETTING_MAC_RANDOMIZATION_ALWAYS) - return g_strdup_printf (_("always")); - else - return g_strdup_printf (_("unknown")); -} + setting_info = &nm_meta_setting_infos_editor[meta_setting_info->meta_type]; -/* 'mode' */ -static const char *wifi_valid_modes[] = { - NM_SETTING_WIRELESS_MODE_INFRA, - NM_SETTING_WIRELESS_MODE_ADHOC, - NM_SETTING_WIRELESS_MODE_AP, - NULL -}; + g_return_val_if_fail (setting_info->general == meta_setting_info, NULL); -static gboolean -nmc_property_wifi_set_mode (NMSetting *setting, const char *prop, const char *val, GError **error) -{ - return check_and_set_string (setting, prop, val, wifi_valid_modes, error); + return setting_info; } -DEFINE_ALLOWED_VAL_FUNC (nmc_property_wifi_allowed_mode, wifi_valid_modes) - -/* 'band' */ -static const char *wifi_valid_bands[] = { "a", "bg", NULL }; - -static gboolean -nmc_property_wifi_set_band (NMSetting *setting, const char *prop, const char *val, GError **error) +static const NMMetaSettingInfoEditor * +_meta_find_setting_info_by_setting (NMSetting *setting) { - return check_and_set_string (setting, prop, val, wifi_valid_bands, error); -} + const NMMetaSettingInfoEditor *setting_info; -DEFINE_ALLOWED_VAL_FUNC (nmc_property_wifi_allowed_band, wifi_valid_bands) + g_return_val_if_fail (NM_IS_SETTING (setting), NULL); -/* 'channel' */ -static gboolean -nmc_property_wifi_set_channel (NMSetting *setting, const char *prop, const char *val, GError **error) -{ - unsigned long chan_int; - - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + setting_info = _meta_find_setting_info_by_gtype (G_OBJECT_TYPE (setting)); - if (!nmc_string_to_uint (val, FALSE, 0, 0, &chan_int)) { - g_set_error (error, 1, 0, _("'%s' is not a valid channel"), val); - return FALSE; - } - - if ( !nm_utils_wifi_is_channel_valid (chan_int, "a") - && !nm_utils_wifi_is_channel_valid (chan_int, "bg")) { - g_set_error (error, 1, 0, _("'%ld' is not a valid channel"), chan_int); - return FALSE; - } - - g_object_set (setting, prop, chan_int, NULL); - return TRUE; -} - -/* 'mac-address-blacklist' */ -DEFINE_SETTER_MAC_BLACKLIST (nmc_property_wireless_set_mac_address_blacklist, - NM_SETTING_WIRELESS, - nm_setting_wireless_add_mac_blacklist_item) - -static gboolean -_validate_and_remove_wifi_mac_blacklist_item (NMSettingWireless *setting, - const char *mac, - GError **error) -{ - gboolean ret; - guint8 buf[32]; + if (!setting_info) + return NULL; - if (!nm_utils_hwaddr_aton (mac, buf, ETH_ALEN)) { - g_set_error (error, 1, 0, _("'%s' is not a valid MAC address"), mac); - return FALSE; - } + g_return_val_if_fail (setting_info == _meta_find_setting_info_by_name (nm_setting_get_name (setting)), NULL); - ret = nm_setting_wireless_remove_mac_blacklist_item_by_value (setting, mac); - if (!ret) - g_set_error (error, 1, 0, _("the property doesn't contain MAC address '%s'"), mac); - return ret; + return setting_info; } -DEFINE_REMOVER_INDEX_OR_VALUE (nmc_property_wireless_remove_mac_address_blacklist, - NM_SETTING_WIRELESS, - nm_setting_wireless_get_num_mac_blacklist_items, - nm_setting_wireless_remove_mac_blacklist_item, - _validate_and_remove_wifi_mac_blacklist_item) -/* 'powersave' */ -static gboolean -nmc_property_wireless_set_powersave (NMSetting *setting, const char *prop, const char *val, GError **error) +static const NMMetaPropertyInfo * +_meta_setting_info_find_property_info (const NMMetaSettingInfoEditor *setting_info, const char *property_name) { - NMSettingWirelessPowersave powersave; - gs_free const char **options = NULL; - gs_free char *options_str = NULL; - long int t; - gboolean ret; - - if (nmc_string_to_int_base (val, 0, TRUE, - NM_SETTING_WIRELESS_POWERSAVE_DEFAULT, - NM_SETTING_WIRELESS_POWERSAVE_LAST, - &t)) - powersave = (NMSettingWirelessPowersave) t; - else { - ret = nm_utils_enum_from_str (nm_setting_wireless_powersave_get_type (), - val, - (int *) &powersave, - NULL); - if (!ret) { - options = nm_utils_enum_get_values (nm_setting_wireless_powersave_get_type (), - NM_SETTING_WIRELESS_POWERSAVE_DEFAULT, - NM_SETTING_WIRELESS_POWERSAVE_LAST); - options_str = g_strjoinv (",", (char **) options); - g_set_error (error, 1, 0, _("invalid option '%s', use one of [%s]"), val, options_str); - return FALSE; - } - } + guint i; - g_object_set (setting, prop, (guint) powersave, NULL); - return TRUE; -} + g_return_val_if_fail (setting_info, NULL); + g_return_val_if_fail (property_name, NULL); -static gboolean -nmc_property_wireless_set_mac_address_randomization (NMSetting *setting, - const char *prop, - const char *val, - GError **error) -{ - NMSettingMacRandomization randomization; - gs_free char *err_token = NULL; - gboolean ret; - long int t; - - if (nmc_string_to_int_base (val, 0, TRUE, - NM_SETTING_MAC_RANDOMIZATION_DEFAULT, - NM_SETTING_MAC_RANDOMIZATION_ALWAYS, - &t)) - randomization = (NMSettingMacRandomization) t; - else { - ret = nm_utils_enum_from_str (nm_setting_mac_randomization_get_type (), - val, - (int *) &randomization, - &err_token); - - if (!ret) { - g_set_error (error, 1, 0, _("invalid option '%s', use 'default', 'never' or 'always'"), - err_token); - return FALSE; - } + for (i = 0; i < setting_info->properties_num; i++) { + if (nm_streq (setting_info->properties[i].property_name, property_name)) + return &setting_info->properties[i]; } - g_object_set (setting, prop, (guint) randomization, NULL); - return TRUE; -} - - -/* --- NM_SETTING_WIRELESS_SECURITY_SETTING_NAME property functions --- */ -DEFINE_GETTER (nmc_property_wifi_sec_get_key_mgmt, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT) -DEFINE_GETTER (nmc_property_wifi_sec_get_wep_tx_keyidx, NM_SETTING_WIRELESS_SECURITY_WEP_TX_KEYIDX) -DEFINE_GETTER (nmc_property_wifi_sec_get_auth_alg, NM_SETTING_WIRELESS_SECURITY_AUTH_ALG) -DEFINE_GETTER (nmc_property_wifi_sec_get_proto, NM_SETTING_WIRELESS_SECURITY_PROTO) -DEFINE_GETTER (nmc_property_wifi_sec_get_pairwise, NM_SETTING_WIRELESS_SECURITY_PAIRWISE) -DEFINE_GETTER (nmc_property_wifi_sec_get_group, NM_SETTING_WIRELESS_SECURITY_GROUP) -DEFINE_GETTER (nmc_property_wifi_sec_get_leap_username, NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME) -DEFINE_SECRET_FLAGS_GETTER (nmc_property_wifi_sec_get_wep_key_flags, NM_SETTING_WIRELESS_SECURITY_WEP_KEY_FLAGS) -DEFINE_GETTER (nmc_property_wifi_sec_get_psk, NM_SETTING_WIRELESS_SECURITY_PSK) -DEFINE_SECRET_FLAGS_GETTER (nmc_property_wifi_sec_get_psk_flags, NM_SETTING_WIRELESS_SECURITY_PSK_FLAGS) -DEFINE_GETTER (nmc_property_wifi_sec_get_leap_password, NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD) -DEFINE_SECRET_FLAGS_GETTER (nmc_property_wifi_sec_get_leap_password_flags, NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD_FLAGS) - -static char * -nmc_property_wifi_sec_get_wep_key0 (NMSetting *setting, NmcPropertyGetType get_type) -{ - NMSettingWirelessSecurity *s_wireless_sec = NM_SETTING_WIRELESS_SECURITY (setting); - return g_strdup (nm_setting_wireless_security_get_wep_key (s_wireless_sec, 0)); -} - -static char * -nmc_property_wifi_sec_get_wep_key1 (NMSetting *setting, NmcPropertyGetType get_type) -{ - NMSettingWirelessSecurity *s_wireless_sec = NM_SETTING_WIRELESS_SECURITY (setting); - return g_strdup (nm_setting_wireless_security_get_wep_key (s_wireless_sec, 1)); -} - -static char * -nmc_property_wifi_sec_get_wep_key2 (NMSetting *setting, NmcPropertyGetType get_type) -{ - NMSettingWirelessSecurity *s_wireless_sec = NM_SETTING_WIRELESS_SECURITY (setting); - return g_strdup (nm_setting_wireless_security_get_wep_key (s_wireless_sec, 2)); -} - -static char * -nmc_property_wifi_sec_get_wep_key3 (NMSetting *setting, NmcPropertyGetType get_type) -{ - NMSettingWirelessSecurity *s_wireless_sec = NM_SETTING_WIRELESS_SECURITY (setting); - return g_strdup (nm_setting_wireless_security_get_wep_key (s_wireless_sec, 3)); -} - -static char * -nmc_property_wifi_sec_get_wep_key_type (NMSetting *setting, NmcPropertyGetType get_type) -{ - NMSettingWirelessSecurity *s_wireless_sec = NM_SETTING_WIRELESS_SECURITY (setting); - return wep_key_type_to_string (nm_setting_wireless_security_get_wep_key_type (s_wireless_sec)); -} - -/* 'key-mgmt' */ -static const char *wifi_sec_valid_key_mgmts[] = { "none", "ieee8021x", "wpa-none", "wpa-psk", "wpa-eap", NULL }; - -static gboolean -nmc_property_wifi_sec_set_key_mgmt (NMSetting *setting, const char *prop, const char *val, GError **error) -{ - return check_and_set_string (setting, prop, val, wifi_sec_valid_key_mgmts, error); + return NULL; } -DEFINE_ALLOWED_VAL_FUNC (nmc_property_wifi_sec_allowed_key_mgmt, wifi_sec_valid_key_mgmts) - -/* 'auth-alg' */ -static const char *wifi_sec_valid_auth_algs[] = { "open", "shared", "leap", NULL }; - -static gboolean -nmc_property_wifi_sec_set_auth_alg (NMSetting *setting, const char *prop, const char *val, GError **error) +static const NMMetaPropertyInfo * +_meta_find_property_info_by_name (const char *setting_name, const char *property_name, const NMMetaSettingInfoEditor **out_setting_info) { - return check_and_set_string (setting, prop, val, wifi_sec_valid_auth_algs, error); -} - -DEFINE_ALLOWED_VAL_FUNC (nmc_property_wifi_sec_allowed_auth_alg, wifi_sec_valid_auth_algs) - -/* 'proto' */ -static const char *wifi_sec_valid_protos[] = { "wpa", "rsn", NULL }; + const NMMetaSettingInfoEditor *setting_info; -DEFINE_SETTER_STR_LIST_MULTI (check_and_add_wifi_sec_proto, - NM_SETTING_WIRELESS_SECURITY, - nm_setting_wireless_security_add_proto) + setting_info = _meta_find_setting_info_by_name (setting_name); -static gboolean -nmc_property_wifi_sec_set_proto (NMSetting *setting, const char *prop, const char *val, GError **error) -{ - return check_and_add_wifi_sec_proto (setting, prop, val, wifi_sec_valid_protos, error); + NM_SET_OUT (out_setting_info, setting_info); + if (!setting_info) + return NULL; + return _meta_setting_info_find_property_info (setting_info, property_name); } -static gboolean -_validate_and_remove_wifi_sec_proto (NMSettingWirelessSecurity *setting, - const char *proto, - GError **error) +static const NMMetaPropertyInfo * +_meta_find_property_info_by_setting (NMSetting *setting, const char *property_name, const NMMetaSettingInfoEditor **out_setting_info) { - gboolean ret; - const char *valid; - - valid = nmc_string_is_valid (proto, wifi_sec_valid_protos, error); - if (!valid) - return FALSE; - - ret = nm_setting_wireless_security_remove_proto_by_value (setting, proto); - if (!ret) - g_set_error (error, 1, 0, - _("the property doesn't contain protocol '%s'"), proto); - return ret; -} -DEFINE_REMOVER_INDEX_OR_VALUE (nmc_property_wifi_sec_remove_proto, - NM_SETTING_WIRELESS_SECURITY, - nm_setting_wireless_security_get_num_protos, - nm_setting_wireless_security_remove_proto, - _validate_and_remove_wifi_sec_proto) - -DEFINE_ALLOWED_VAL_FUNC (nmc_property_wifi_sec_allowed_proto, wifi_sec_valid_protos) + const NMMetaSettingInfoEditor *setting_info; + const NMMetaPropertyInfo *property_info; -/* 'pairwise' */ -static const char *wifi_sec_valid_pairwises[] = { "tkip", "ccmp", NULL }; + setting_info = _meta_find_setting_info_by_setting (setting); -DEFINE_SETTER_STR_LIST_MULTI (check_and_add_wifi_sec_pairwise, - NM_SETTING_WIRELESS_SECURITY, - nm_setting_wireless_security_add_pairwise) + NM_SET_OUT (out_setting_info, setting_info); + if (!setting_info) + return NULL; + property_info = _meta_setting_info_find_property_info (setting_info, property_name); -static gboolean -nmc_property_wifi_sec_set_pairwise (NMSetting *setting, const char *prop, const char *val, GError **error) -{ - return check_and_add_wifi_sec_pairwise (setting, prop, val, wifi_sec_valid_pairwises, error); -} + nm_assert (property_info == _meta_find_property_info_by_name (nm_setting_get_name (setting), property_name, NULL)); -static gboolean -_validate_and_remove_wifi_sec_pairwise (NMSettingWirelessSecurity *setting, - const char *pairwise, - GError **error) -{ - gboolean ret; - const char *valid; - - valid = nmc_string_is_valid (pairwise, wifi_sec_valid_pairwises, error); - if (!valid) - return FALSE; - - ret = nm_setting_wireless_security_remove_pairwise_by_value (setting, pairwise); - if (!ret) - g_set_error (error, 1, 0, - _("the property doesn't contain protocol '%s'"), pairwise); - return ret; + return property_info; } -DEFINE_REMOVER_INDEX_OR_VALUE (nmc_property_wifi_sec_remove_pairwise, - NM_SETTING_WIRELESS_SECURITY, - nm_setting_wireless_security_get_num_pairwise, - nm_setting_wireless_security_remove_pairwise, - _validate_and_remove_wifi_sec_pairwise) - -DEFINE_ALLOWED_VAL_FUNC (nmc_property_wifi_sec_allowed_pairwise, wifi_sec_valid_pairwises) - -/* 'group' */ -static const char *wifi_sec_valid_groups[] = { "wep40", "wep104", "tkip", "ccmp", NULL }; - -DEFINE_SETTER_STR_LIST_MULTI (check_and_add_wifi_sec_group, - NM_SETTING_WIRELESS_SECURITY, - nm_setting_wireless_security_add_group) -static gboolean -nmc_property_wifi_sec_set_group (NMSetting *setting, const char *prop, const char *val, GError **error) -{ - return check_and_add_wifi_sec_group (setting, prop, val, wifi_sec_valid_groups, error); -} +/*****************************************************************************/ -static gboolean -_validate_and_remove_wifi_sec_group (NMSettingWirelessSecurity *setting, - const char *group, - GError **error) +static const NmcOutputField * +_get_nmc_output_fields (const NMMetaSettingInfoEditor *setting_info) { - gboolean ret; - const char *valid; - - valid = nmc_string_is_valid (group, wifi_sec_valid_groups, error); - if (!valid) - return FALSE; - - ret = nm_setting_wireless_security_remove_group_by_value (setting, group); - if (!ret) - g_set_error (error, 1, 0, - _("the property doesn't contain protocol '%s'"), group); - return ret; -} -DEFINE_REMOVER_INDEX_OR_VALUE (nmc_property_wifi_sec_remove_group, - NM_SETTING_WIRELESS_SECURITY, - nm_setting_wireless_security_get_num_groups, - nm_setting_wireless_security_remove_group, - _validate_and_remove_wifi_sec_group) -DEFINE_ALLOWED_VAL_FUNC (nmc_property_wifi_sec_allowed_group, wifi_sec_valid_groups) - -/* 'wep-key' */ -static gboolean -nmc_property_wifi_set_wep_key (NMSetting *setting, const char *prop, const char *val, GError **error) -{ - NMWepKeyType guessed_type = NM_WEP_KEY_TYPE_UNKNOWN; - NMWepKeyType type; - guint32 prev_idx, idx; - - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - - /* Get currently set type */ - type = nm_setting_wireless_security_get_wep_key_type (NM_SETTING_WIRELESS_SECURITY (setting)); - - /* Guess key type */ - if (nm_utils_wep_key_valid (val, NM_WEP_KEY_TYPE_KEY)) - guessed_type = NM_WEP_KEY_TYPE_KEY; - else if (nm_utils_wep_key_valid (val, NM_WEP_KEY_TYPE_PASSPHRASE)) - guessed_type = NM_WEP_KEY_TYPE_PASSPHRASE; - - if (guessed_type == NM_WEP_KEY_TYPE_UNKNOWN) { - g_set_error (error, 1, 0, _("'%s' is not valid"), val); - return FALSE; - } + static NmcOutputField *fields[_NM_META_SETTING_TYPE_NUM + 1] = { }; + NmcOutputField **field; + guint i; - if (type != NM_WEP_KEY_TYPE_UNKNOWN && type != guessed_type) { - if (nm_utils_wep_key_valid (val, type)) - guessed_type = type; - else { - g_set_error (error, 1, 0, - _("'%s' not compatible with %s '%s', please change the key or set the right %s first."), - val, NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE, wep_key_type_to_string (type), - NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE); - return FALSE; - } - } - prev_idx = nm_setting_wireless_security_get_wep_tx_keyidx (NM_SETTING_WIRELESS_SECURITY (setting)); - idx = prop[strlen (prop) - 1] - '0'; - g_print (_("WEP key is guessed to be of '%s'\n"), wep_key_type_to_string (guessed_type)); - if (idx != prev_idx) - g_print (_("WEP key index set to '%d'\n"), idx); - - g_object_set (setting, prop, val, NULL); - g_object_set (setting, NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE, guessed_type, NULL); - if (idx != prev_idx) - g_object_set (setting, NM_SETTING_WIRELESS_SECURITY_WEP_TX_KEYIDX, idx, NULL); - return TRUE; -} + g_return_val_if_fail (setting_info, NULL); + g_return_val_if_fail (setting_info->general->meta_type < _NM_META_SETTING_TYPE_NUM, NULL); -/* 'wep-key-type' */ -static gboolean -nmc_property_wifi_set_wep_key_type (NMSetting *setting, const char *prop, const char *val, GError **error) -{ - unsigned long type_int; - const char *valid_wep_types[] = { "unknown", "key", "passphrase", NULL }; - const char *type_str = NULL; - const char *key0, *key1,* key2, *key3; - NMWepKeyType type = NM_WEP_KEY_TYPE_UNKNOWN; + field = &fields[setting_info->general->meta_type]; - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + if (G_UNLIKELY (!*field)) { + *field = g_new0 (NmcOutputField, setting_info->properties_num + 1); + for (i = 0; i < setting_info->properties_num; i++) { + NmcOutputField *f = &(*field)[i]; - if (!nmc_string_to_uint (val, TRUE, 0, 2, &type_int)) { - if (!(type_str = nmc_string_is_valid (val, valid_wep_types, NULL))) { - g_set_error (error, 1, 0, _("'%s' not among [0 (unknown), 1 (key), 2 (passphrase)]"), val); - return FALSE; + f->name = setting_info->properties[i].property_name; } - if (type_str == valid_wep_types[1]) - type = NM_WEP_KEY_TYPE_KEY; - else if (type_str == valid_wep_types[2]) - type = NM_WEP_KEY_TYPE_PASSPHRASE; - } else - type = (NMWepKeyType) type_int; - - /* Check type compatibility with set keys */ - key0 = nm_setting_wireless_security_get_wep_key (NM_SETTING_WIRELESS_SECURITY (setting), 0); - key1 = nm_setting_wireless_security_get_wep_key (NM_SETTING_WIRELESS_SECURITY (setting), 1); - key2 = nm_setting_wireless_security_get_wep_key (NM_SETTING_WIRELESS_SECURITY (setting), 2); - key3 = nm_setting_wireless_security_get_wep_key (NM_SETTING_WIRELESS_SECURITY (setting), 3); - if (key0 && !nm_utils_wep_key_valid (key0, type)) - g_print (_("Warning: '%s' is not compatible with '%s' type, please change or delete the key.\n"), - NM_SETTING_WIRELESS_SECURITY_WEP_KEY0, wep_key_type_to_string (type)); - if (key1 && !nm_utils_wep_key_valid (key1, type)) - g_print (_("Warning: '%s' is not compatible with '%s' type, please change or delete the key.\n"), - NM_SETTING_WIRELESS_SECURITY_WEP_KEY1, wep_key_type_to_string (type)); - if (key2 && !nm_utils_wep_key_valid (key2, type)) - g_print (_("Warning: '%s' is not compatible with '%s' type, please change or delete the key.\n"), - NM_SETTING_WIRELESS_SECURITY_WEP_KEY2, wep_key_type_to_string (type)); - if (key3 && !nm_utils_wep_key_valid (key3, type)) - g_print (_("Warning: '%s' is not compatible with '%s' type, please change or delete the key.\n"), - NM_SETTING_WIRELESS_SECURITY_WEP_KEY3, wep_key_type_to_string (type)); - - g_object_set (setting, prop, type, NULL); - return TRUE; -} - -static const char * -nmc_property_wifi_describe_wep_key_type (NMSetting *setting, const char *prop) -{ - static char *desc = NULL; - - if (G_UNLIKELY (desc == NULL)) { - desc = g_strdup_printf (_("Enter the type of WEP keys. The accepted values are: " - "0 or unknown, 1 or key, and 2 or passphrase.\n")); - } - return desc; -} - -/* 'psk' */ -static gboolean -nmc_property_wifi_set_psk (NMSetting *setting, const char *prop, const char *val, GError **error) -{ - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - - if (!nm_utils_wpa_psk_valid (val)) { - g_set_error (error, 1, 0, _("'%s' is not a valid PSK"), val); - return FALSE; } - g_object_set (setting, prop, val, NULL); - return TRUE; -} - -/*----------------------------------------------------------------------------*/ - -static void -nmc_value_transform_bool_string (const GValue *src_value, - GValue *dest_value) -{ - dest_value->data[0].v_pointer = g_strdup (src_value->data[0].v_int ? "yes" : "no"); -} -static void -nmc_value_transform_char_string (const GValue *src_value, - GValue *dest_value) -{ - dest_value->data[0].v_pointer = g_strdup_printf ("%c", src_value->data[0].v_uint); -} - -static void __attribute__((constructor)) -register_nmcli_value_transforms (void) -{ - g_value_register_transform_func (G_TYPE_BOOLEAN, G_TYPE_STRING, nmc_value_transform_bool_string); - g_value_register_transform_func (G_TYPE_CHAR, G_TYPE_STRING, nmc_value_transform_char_string); + return *field; } -/*----------------------------------------------------------------------------*/ - -/* Main hash table storing function pointer for manipulating properties */ -static GHashTable *nmc_properties = NULL; -typedef char * (*NmcPropertyGetFunc) (NMSetting *, NmcPropertyGetType); -typedef gboolean (*NmcPropertySetFunc) (NMSetting *, const char *, const char *, GError **); -typedef gboolean (*NmcPropertyRemoveFunc) (NMSetting *, const char *, const char *, guint32, GError **); -typedef const char * (*NmcPropertyDescribeFunc) (NMSetting *, const char *); -typedef const char ** (*NmcPropertyValuesFunc) (NMSetting *, const char *); - -typedef struct { - /* The order of the fields is important as they correspond - * to the order as _nmc_add_prop_funcs() passes the arguments. */ -#define NmcPropertyFuncsFields \ - NmcPropertyGetFunc get_func; /* func getting property values */ \ - NmcPropertySetFunc set_func; /* func adding/setting property values */ \ - NmcPropertyRemoveFunc remove_func; /* func removing items from container options */ \ - NmcPropertyDescribeFunc describe_func; /* func returning property description */ \ - NmcPropertyValuesFunc values_func; /* func returning allowed property values */ \ - ; - NmcPropertyFuncsFields -} NmcPropertyFuncs; +/*****************************************************************************/ NMSetting * nmc_setting_new_for_name (const char *name) @@ -6146,2258 +528,29 @@ nmc_setting_custom_init (NMSetting *setting) } } -/*----------------------------------------------------------------------------*/ - -static inline void -_nmc_add_prop_funcs (const char *key, - const NmcPropertyFuncs *item_init) -{ - NmcPropertyFuncs *item; - - item = g_malloc (sizeof (NmcPropertyFuncs)); - *item = *item_init; - g_hash_table_insert (nmc_properties, (gpointer) key, item); -} - -#define nmc_add_prop_funcs(key, ...) \ - G_STMT_START { \ - struct { \ - NmcPropertyFuncsFields; \ - /* The _dummy field is here so that the last argument can be always - * NULL. That means every call to nmc_add_prop_funcs() below ends - * with a separate line "NULL);". */ \ - gpointer _dummy; \ - } _item_init = { \ - __VA_ARGS__ \ - };\ - \ - nm_assert (_item_init._dummy == NULL); \ - _nmc_add_prop_funcs ("" key, (NmcPropertyFuncs *) &_item_init); \ - } G_STMT_END - -/* concatenate setting name and property name */ -#define GLUE(A,B) "" NM_SETTING_##A##_SETTING_NAME "" NM_SETTING_##A##_##B "" -#define GLUE_IP(A,B) "" NM_SETTING_IP##A##_CONFIG_SETTING_NAME "" NM_SETTING_IP_CONFIG_##B "" - -void -nmc_properties_init (void) -{ - if (G_LIKELY (nmc_properties)) - return; - - /* create properties hash table */ - nmc_properties = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_free); - - /* Add editable properties for NM_SETTING_802_1X_SETTING_NAME */ - nmc_add_prop_funcs (GLUE (802_1X, EAP), - nmc_property_802_1X_get_eap, - nmc_property_802_1X_set_eap, - nmc_property_802_1X_remove_eap, - NULL, - nmc_property_802_1X_allowed_eap, - NULL); - nmc_add_prop_funcs (GLUE (802_1X, IDENTITY), - nmc_property_802_1X_get_identity, - nmc_property_set_string, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (802_1X, ANONYMOUS_IDENTITY), - nmc_property_802_1X_get_anonymous_identity, - nmc_property_set_string, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (802_1X, PAC_FILE), - nmc_property_802_1X_get_pac_file, - nmc_property_set_string, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (802_1X, CA_CERT), - nmc_property_802_1X_get_ca_cert, - nmc_property_802_1X_set_ca_cert, - NULL, - nmc_property_802_1X_describe_ca_cert, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (802_1X, CA_CERT_PASSWORD), - nmc_property_802_1X_get_ca_cert_password, - nmc_property_set_string, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (802_1X, CA_CERT_PASSWORD_FLAGS), - nmc_property_802_1X_get_ca_cert_password_flags, - nmc_property_set_secret_flags, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (802_1X, CA_PATH), - nmc_property_802_1X_get_ca_path, - nmc_property_set_string, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (802_1X, SUBJECT_MATCH), - nmc_property_802_1X_get_subject_match, - nmc_property_set_string, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (802_1X, ALTSUBJECT_MATCHES), - nmc_property_802_1X_get_altsubject_matches, - nmc_property_802_1X_set_altsubject_matches, - nmc_property_802_1X_remove_altsubject_matches, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (802_1X, DOMAIN_SUFFIX_MATCH), - nmc_property_802_1X_get_domain_suffix_match, - nmc_property_set_string, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (802_1X, CLIENT_CERT), - nmc_property_802_1X_get_client_cert_full, - nmc_property_802_1X_set_client_cert, - NULL, - nmc_property_802_1X_describe_client_cert, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (802_1X, CLIENT_CERT_PASSWORD), - nmc_property_802_1X_get_client_cert_password, - nmc_property_set_string, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (802_1X, CLIENT_CERT_PASSWORD_FLAGS), - nmc_property_802_1X_get_client_cert_password_flags, - nmc_property_set_secret_flags, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (802_1X, PHASE1_PEAPVER), - nmc_property_802_1X_get_phase1_peapver, - nmc_property_802_1X_set_phase1_peapver, - NULL, - NULL, - nmc_property_802_1X_allowed_phase1_peapver, - NULL); - nmc_add_prop_funcs (GLUE (802_1X, PHASE1_PEAPLABEL), - nmc_property_802_1X_get_phase1_peaplabel, - nmc_property_802_1X_set_phase1_peaplabel, - NULL, - NULL, - nmc_property_802_1X_allowed_phase1_peaplabel, - NULL); - nmc_add_prop_funcs (GLUE (802_1X, PHASE1_FAST_PROVISIONING), - nmc_property_802_1X_get_phase1_fast_provisioning, - nmc_property_802_1X_set_phase1_fast_provisioning, - NULL, - NULL, - nmc_property_802_1X_allowed_phase1_fast_provisioning, - NULL); - nmc_add_prop_funcs (GLUE (802_1X, PHASE1_AUTH_FLAGS), - nmc_property_802_1X_get_phase1_auth_flags, - nmc_property_802_1X_set_phase1_auth_flags, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (802_1X, PHASE2_AUTH), - nmc_property_802_1X_get_phase2_auth, - nmc_property_802_1X_set_phase2_auth, - NULL, - NULL, - nmc_property_802_1X_allowed_phase2_auth, - NULL); - nmc_add_prop_funcs (GLUE (802_1X, PHASE2_AUTHEAP), - nmc_property_802_1X_get_phase2_autheap, - nmc_property_802_1X_set_phase2_autheap, - NULL, - NULL, - nmc_property_802_1X_allowed_phase2_autheap, - NULL); - nmc_add_prop_funcs (GLUE (802_1X, PHASE2_CA_CERT), - nmc_property_802_1X_get_phase2_ca_cert, - nmc_property_802_1X_set_phase2_ca_cert, - NULL, - nmc_property_802_1X_describe_phase2_ca_cert, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (802_1X, PHASE2_CA_CERT_PASSWORD), - nmc_property_802_1X_get_phase2_ca_cert_password, - nmc_property_set_string, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (802_1X, PHASE2_CA_CERT_PASSWORD_FLAGS), - nmc_property_802_1X_get_phase2_ca_cert_password_flags, - nmc_property_set_secret_flags, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (802_1X, PHASE2_CA_PATH), - nmc_property_802_1X_get_phase2_ca_path, - nmc_property_set_string, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (802_1X, PHASE2_SUBJECT_MATCH), - nmc_property_802_1X_get_phase2_subject_match, - nmc_property_set_string, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (802_1X, PHASE2_ALTSUBJECT_MATCHES), - nmc_property_802_1X_get_phase2_altsubject_matches, - nmc_property_802_1X_set_phase2_altsubject_matches, - nmc_property_802_1X_remove_phase2_altsubject_matches, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (802_1X, PHASE2_DOMAIN_SUFFIX_MATCH), - nmc_property_802_1X_get_phase2_domain_suffix_match, - nmc_property_set_string, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (802_1X, PHASE2_CLIENT_CERT), - nmc_property_802_1X_get_phase2_client_cert_full, - nmc_property_802_1X_set_phase2_client_cert, - NULL, - nmc_property_802_1X_describe_phase2_client_cert, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (802_1X, PHASE2_CLIENT_CERT_PASSWORD), - nmc_property_802_1X_get_phase2_client_cert_password, - nmc_property_set_string, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (802_1X, PHASE2_CLIENT_CERT_PASSWORD_FLAGS), - nmc_property_802_1X_get_phase2_client_cert_password_flags, - nmc_property_set_secret_flags, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (802_1X, PASSWORD), - nmc_property_802_1X_get_password, - nmc_property_set_string, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (802_1X, PASSWORD_FLAGS), - nmc_property_802_1X_get_password_flags, - nmc_property_set_secret_flags, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (802_1X, PASSWORD_RAW), - nmc_property_802_1X_get_password_raw, - nmc_property_802_1X_set_password_raw, - NULL, - nmc_property_802_1X_describe_password_raw, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (802_1X, PASSWORD_RAW_FLAGS), - nmc_property_802_1X_get_password_raw_flags, - nmc_property_set_secret_flags, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (802_1X, PRIVATE_KEY), - nmc_property_802_1X_get_private_key_full, - nmc_property_802_1X_set_private_key, - NULL, - nmc_property_802_1X_describe_private_key, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (802_1X, PRIVATE_KEY_PASSWORD), - nmc_property_802_1X_get_private_key_password, - nmc_property_set_string, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (802_1X, PRIVATE_KEY_PASSWORD_FLAGS), - nmc_property_802_1X_get_private_key_password_flags, - nmc_property_set_secret_flags, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (802_1X, PHASE2_PRIVATE_KEY), - nmc_property_802_1X_get_phase2_private_key_full, - nmc_property_802_1X_set_phase2_private_key, - NULL, - nmc_property_802_1X_describe_private_key, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (802_1X, PHASE2_PRIVATE_KEY_PASSWORD), - nmc_property_802_1X_get_phase2_private_key_password, - nmc_property_set_string, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (802_1X, PHASE2_PRIVATE_KEY_PASSWORD_FLAGS), - nmc_property_802_1X_get_phase2_private_key_password_flags, - nmc_property_set_secret_flags, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (802_1X, PIN), - nmc_property_802_1X_get_pin, - nmc_property_set_string, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (802_1X, PIN_FLAGS), - nmc_property_802_1X_get_pin_flags, - nmc_property_set_secret_flags, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (802_1X, SYSTEM_CA_CERTS), - nmc_property_802_1X_get_system_ca_certs, - nmc_property_set_bool, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (802_1X, AUTH_TIMEOUT), - nmc_property_802_1X_get_auth_timeout, - nmc_property_set_int, - NULL, - NULL, - NULL, - NULL); - - /* Add editable properties for NM_SETTING_ADSL_SETTING_NAME */ - nmc_add_prop_funcs (GLUE (ADSL, USERNAME), - nmc_property_adsl_get_username, - nmc_property_set_string, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (ADSL, PASSWORD), - nmc_property_adsl_get_password, - nmc_property_set_string, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (ADSL, PASSWORD_FLAGS), - nmc_property_adsl_get_password_flags, - nmc_property_set_secret_flags, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (ADSL, PROTOCOL), - nmc_property_adsl_get_protocol, - nmc_property_adsl_set_protocol, - NULL, - NULL, - nmc_property_adsl_allowed_protocol, - NULL); - nmc_add_prop_funcs (GLUE (ADSL, ENCAPSULATION), - nmc_property_adsl_get_encapsulation, - nmc_property_adsl_set_encapsulation, - NULL, - NULL, - nmc_property_adsl_allowed_encapsulation, - NULL); - nmc_add_prop_funcs (GLUE (ADSL, VPI), - nmc_property_adsl_get_vpi, - nmc_property_set_uint, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (ADSL, VCI), - nmc_property_adsl_get_vci, - nmc_property_set_uint, - NULL, - NULL, - NULL, - NULL); - - /* Add editable properties for NM_SETTING_BLUETOOTH_SETTING_NAME */ - nmc_add_prop_funcs (GLUE (BLUETOOTH, BDADDR), - nmc_property_bluetooth_get_bdaddr, - nmc_property_set_mac, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (BLUETOOTH, TYPE), - nmc_property_bluetooth_get_type, - nmc_property_bluetooth_set_type, - NULL, - NULL, - NULL, - NULL); - - /* Add editable properties for NM_SETTING_BOND_SETTING_NAME */ - nmc_add_prop_funcs (GLUE (BOND, OPTIONS), - nmc_property_bond_get_options, - nmc_property_bond_set_options, - nmc_property_bond_remove_option_options, - nmc_property_bond_describe_options, - nmc_property_bond_allowed_options, - NULL); - - /* Add editable properties for NM_SETTING_BRIDGE_SETTING_NAME */ - nmc_add_prop_funcs (GLUE (BRIDGE, MAC_ADDRESS), - nmc_property_bridge_get_mac_address, - nmc_property_set_mac, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (BRIDGE, STP), - nmc_property_bridge_get_stp, - nmc_property_set_bool, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (BRIDGE, PRIORITY), - nmc_property_bridge_get_priority, - nmc_property_set_uint, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (BRIDGE, FORWARD_DELAY), - nmc_property_bridge_get_forward_delay, - nmc_property_set_uint, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (BRIDGE, HELLO_TIME), - nmc_property_bridge_get_hello_time, - nmc_property_set_uint, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (BRIDGE, MAX_AGE), - nmc_property_bridge_get_max_age, - nmc_property_set_uint, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (BRIDGE, AGEING_TIME), - nmc_property_bridge_get_ageing_time, - nmc_property_set_uint, - NULL, - NULL, - NULL, - NULL); - - nmc_add_prop_funcs (GLUE (BRIDGE, MULTICAST_SNOOPING), - nmc_property_bridge_get_multicast_snooping, - nmc_property_set_bool, - NULL, - NULL, - NULL, - NULL); - - /* Add editable properties for NM_SETTING_BRIDGE_PORT_SETTING_NAME */ - nmc_add_prop_funcs (GLUE (BRIDGE_PORT, PRIORITY), - nmc_property_bridge_port_get_priority, - nmc_property_set_uint, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (BRIDGE_PORT, PATH_COST), - nmc_property_bridge_port_get_path_cost, - nmc_property_set_uint, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (BRIDGE_PORT, HAIRPIN_MODE), - nmc_property_bridge_port_get_hairpin_mode, - nmc_property_set_bool, - NULL, - NULL, - NULL, - NULL); - - /* Add editable properties for NM_SETTING_CDMA_SETTING_NAME */ - nmc_add_prop_funcs (GLUE (CDMA, NUMBER), - nmc_property_cdma_get_number, - nmc_property_set_string, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (CDMA, USERNAME), - nmc_property_cdma_get_username, - nmc_property_set_string, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (CDMA, PASSWORD), - nmc_property_cdma_get_password, - nmc_property_set_string, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (CDMA, PASSWORD_FLAGS), - nmc_property_cdma_get_password_flags, - nmc_property_set_secret_flags, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (CDMA, MTU), - nmc_property_cdma_get_mtu, - nmc_property_set_uint, - NULL, - NULL, - NULL, - NULL); - - /* Add editable properties for NM_SETTING_CONNECTION_SETTING_NAME */ - nmc_add_prop_funcs (GLUE (CONNECTION, ID), - nmc_property_connection_get_id, - nmc_property_set_string, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (CONNECTION, UUID), - nmc_property_connection_get_uuid, - NULL, /* forbid setting/removing UUID */ - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (CONNECTION, STABLE_ID), - nmc_property_connection_get_stable_id, - nmc_property_set_string, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (CONNECTION, INTERFACE_NAME), - nmc_property_connection_get_interface_name, - nmc_property_set_ifname, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (CONNECTION, TYPE), - nmc_property_connection_get_type, - nmc_property_connection_set_type, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (CONNECTION, AUTOCONNECT), - nmc_property_connection_get_autoconnect, - nmc_property_set_bool, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (CONNECTION, AUTOCONNECT_PRIORITY), - nmc_property_connection_get_autoconnect_priority, - nmc_property_set_int, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (CONNECTION, AUTOCONNECT_RETRIES), - nmc_property_connection_get_autoconnect_retries, - nmc_property_set_int, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (CONNECTION, TIMESTAMP), - nmc_property_connection_get_timestamp, - NULL, /* read-only */ - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (CONNECTION, READ_ONLY), - nmc_property_connection_get_read_only, - NULL, /* 'read-only' is read-only :-) */ - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (CONNECTION, PERMISSIONS), - nmc_property_connection_get_permissions, - nmc_property_connection_set_permissions, - nmc_property_connection_remove_permissions, - nmc_property_connection_describe_permissions, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (CONNECTION, ZONE), - nmc_property_connection_get_zone, - nmc_property_set_string, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (CONNECTION, MASTER), - nmc_property_connection_get_master, - nmc_property_con_set_master, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (CONNECTION, SLAVE_TYPE), - nmc_property_connection_get_slave_type, - nmc_property_con_set_slave_type, - NULL, - NULL, - nmc_property_con_allowed_slave_type, - NULL); - nmc_add_prop_funcs (GLUE (CONNECTION, AUTOCONNECT_SLAVES), - nmc_property_connection_get_autoconnect_slaves, - nmc_property_set_trilean, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (CONNECTION, SECONDARIES), - nmc_property_connection_get_secondaries, - nmc_property_connection_set_secondaries, - nmc_property_connection_remove_secondaries, - nmc_property_connection_describe_secondaries, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (CONNECTION, GATEWAY_PING_TIMEOUT), - nmc_property_connection_get_gateway_ping_timeout, - nmc_property_set_uint, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (CONNECTION, METERED), - nmc_property_connection_get_metered, - nmc_property_connection_set_metered, - NULL, - nmc_property_connection_describe_metered, - nmc_property_connection_allowed_metered, - NULL); - nmc_add_prop_funcs (GLUE (CONNECTION, LLDP), - nmc_property_connection_get_lldp, - nmc_property_connection_set_lldp, - NULL, - NULL, - nmc_property_connection_allowed_lldp, - NULL); - - /* Add editable properties for NM_SETTING_DCB_SETTING_NAME */ - nmc_add_prop_funcs (GLUE (DCB, APP_FCOE_FLAGS), - nmc_property_dcb_get_app_fcoe_flags, - nmc_property_dcb_set_flags, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (DCB, APP_FCOE_MODE), - nmc_property_dcb_get_app_fcoe_mode, - nmc_property_dcb_set_app_fcoe_mode, - NULL, - NULL, - nmc_property_dcb_allowed_app_fcoe_modes, - NULL); - nmc_add_prop_funcs (GLUE (DCB, APP_FCOE_PRIORITY), - nmc_property_dcb_get_app_fcoe_priority, - nmc_property_dcb_set_priority, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (DCB, APP_ISCSI_FLAGS), - nmc_property_dcb_get_app_iscsi_flags, - nmc_property_dcb_set_flags, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (DCB, APP_ISCSI_PRIORITY), - nmc_property_dcb_get_app_iscsi_priority, - nmc_property_dcb_set_priority, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (DCB, APP_FIP_FLAGS), - nmc_property_dcb_get_app_fip_flags, - nmc_property_dcb_set_flags, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (DCB, APP_FIP_PRIORITY), - nmc_property_dcb_get_app_fip_priority, - nmc_property_dcb_set_priority, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (DCB, PRIORITY_FLOW_CONTROL_FLAGS), - nmc_property_dcb_get_pfc_flags, - nmc_property_dcb_set_flags, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (DCB, PRIORITY_FLOW_CONTROL), - nmc_property_dcb_get_pfc, - nmc_property_dcb_set_pfc, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (DCB, PRIORITY_GROUP_FLAGS), - nmc_property_dcb_get_pg_flags, - nmc_property_dcb_set_flags, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (DCB, PRIORITY_GROUP_ID), - nmc_property_dcb_get_pg_group_id, - nmc_property_dcb_set_pg_group_id, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (DCB, PRIORITY_GROUP_BANDWIDTH), - nmc_property_dcb_get_pg_group_bandwidth, - nmc_property_dcb_set_pg_group_bandwidth, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (DCB, PRIORITY_BANDWIDTH), - nmc_property_dcb_get_pg_bandwidth, - nmc_property_dcb_set_pg_bandwidth, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (DCB, PRIORITY_STRICT_BANDWIDTH), - nmc_property_dcb_get_pg_strict, - nmc_property_dcb_set_pg_strict, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (DCB, PRIORITY_TRAFFIC_CLASS), - nmc_property_dcb_get_pg_traffic_class, - nmc_property_dcb_set_pg_traffic_class, - NULL, - NULL, - NULL, - NULL); - - /* Add editable properties for NM_SETTING_GSM_SETTING_NAME */ - nmc_add_prop_funcs (GLUE (GSM, NUMBER), - nmc_property_gsm_get_number, - nmc_property_set_string, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (GSM, USERNAME), - nmc_property_gsm_get_username, - nmc_property_set_string, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (GSM, PASSWORD), - nmc_property_gsm_get_password, - nmc_property_set_string, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (GSM, PASSWORD_FLAGS), - nmc_property_gsm_get_password_flags, - nmc_property_set_secret_flags, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (GSM, APN), - nmc_property_gsm_get_apn, - nmc_property_set_string, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (GSM, NETWORK_ID), - nmc_property_gsm_get_network_id, - nmc_property_set_string, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (GSM, PIN), - nmc_property_gsm_get_pin, - nmc_property_set_string, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (GSM, PIN_FLAGS), - nmc_property_gsm_get_pin_flags, - nmc_property_set_secret_flags, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (GSM, HOME_ONLY), - nmc_property_gsm_get_home_only, - nmc_property_set_bool, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (GSM, DEVICE_ID), - nmc_property_gsm_get_device_id, - nmc_property_set_string, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (GSM, SIM_ID), - nmc_property_gsm_get_sim_id, - nmc_property_set_string, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (GSM, SIM_OPERATOR_ID), - nmc_property_gsm_get_sim_operator_id, - nmc_property_gsm_set_sim_operator_id, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (GSM, MTU), - nmc_property_gsm_get_mtu, - nmc_property_set_uint, - NULL, - NULL, - NULL, - NULL); - - /* Add editable properties for NM_SETTING_INFINIBAND_SETTING_NAME */ - nmc_add_prop_funcs (GLUE (INFINIBAND, MAC_ADDRESS), - nmc_property_ib_get_mac_address, - nmc_property_ib_set_mac, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (INFINIBAND, MTU), - nmc_property_ib_get_mtu, - nmc_property_set_mtu, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (INFINIBAND, TRANSPORT_MODE), - nmc_property_ib_get_transport_mode, - nmc_property_ib_set_transport_mode, - NULL, - NULL, - nmc_property_ib_allowed_transport_mode, - NULL); - nmc_add_prop_funcs (GLUE (INFINIBAND, P_KEY), - nmc_property_ib_get_p_key, - nmc_property_ib_set_p_key, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (INFINIBAND, PARENT), - nmc_property_ib_get_parent, - nmc_property_set_ifname, - NULL, - NULL, - NULL, - NULL); - - /* Add editable properties for NM_SETTING_IP4_CONFIG_SETTING_NAME */ - nmc_add_prop_funcs (GLUE_IP (4, METHOD), - nmc_property_ipv4_get_method, - nmc_property_ipv4_set_method, - NULL, - NULL, - nmc_property_ipv4_allowed_method, - NULL); - nmc_add_prop_funcs (GLUE_IP (4, DNS), - nmc_property_ipv4_get_dns, - nmc_property_ipv4_set_dns, - nmc_property_ipv4_remove_dns, - nmc_property_ipv4_describe_dns, - NULL, - NULL); - nmc_add_prop_funcs (GLUE_IP (4, DNS_SEARCH), - nmc_property_ipv4_get_dns_search, - nmc_property_ipv4_set_dns_search, - nmc_property_ipv4_remove_dns_search, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE_IP (4, DNS_OPTIONS), - nmc_property_ipv4_get_dns_options, - nmc_property_ipv4_set_dns_options, - nmc_property_ipv4_remove_dns_option, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE_IP (4, DNS_PRIORITY), - nmc_property_ipv4_get_dns_priority, - nmc_property_set_int, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE_IP (4, ADDRESSES), - nmc_property_ip_get_addresses, - nmc_property_ipv4_set_addresses, - nmc_property_ipv4_remove_addresses, - nmc_property_ipv4_describe_addresses, - NULL, - NULL); - nmc_add_prop_funcs (GLUE_IP (4, GATEWAY), - nmc_property_ipv4_get_gateway, - nmc_property_ipv4_set_gateway, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE_IP (4, ROUTES), - nmc_property_ipv4_get_routes, - nmc_property_ipv4_set_routes, - nmc_property_ipv4_remove_routes, - nmc_property_ipv4_describe_routes, - NULL, - NULL); - nmc_add_prop_funcs (GLUE_IP (4, ROUTE_METRIC), - nmc_property_ipv4_get_route_metric, - nmc_property_set_int64, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE_IP (4, IGNORE_AUTO_ROUTES), - nmc_property_ipv4_get_ignore_auto_routes, - nmc_property_set_bool, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE_IP (4, IGNORE_AUTO_DNS), - nmc_property_ipv4_get_ignore_auto_dns, - nmc_property_set_bool, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (IP4_CONFIG, DHCP_CLIENT_ID), - nmc_property_ipv4_get_dhcp_client_id, - nmc_property_set_string, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE_IP (4, DHCP_TIMEOUT), - nmc_property_ipv4_get_dhcp_timeout, - nmc_property_set_int, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE_IP (4, DHCP_SEND_HOSTNAME), - nmc_property_ipv4_get_dhcp_send_hostname, - nmc_property_set_bool, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE_IP (4, DHCP_HOSTNAME), - nmc_property_ipv4_get_dhcp_hostname, - nmc_property_set_string, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (IP4_CONFIG, DHCP_FQDN), - nmc_property_ipv4_get_dhcp_fqdn, - nmc_property_set_string, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE_IP (4, NEVER_DEFAULT), - nmc_property_ipv4_get_never_default, - nmc_property_set_bool, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE_IP (4, MAY_FAIL), - nmc_property_ipv4_get_may_fail, - nmc_property_set_bool, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE_IP (4, DAD_TIMEOUT), - nmc_property_ipv4_get_dad_timeout, - nmc_property_set_int, - NULL, - NULL, - NULL, - NULL); - - /* Add editable properties for NM_SETTING_IP6_CONFIG_SETTING_NAME */ - nmc_add_prop_funcs (GLUE_IP (6, METHOD), - nmc_property_ipv6_get_method, - nmc_property_ipv6_set_method, - NULL, - NULL, - nmc_property_ipv6_allowed_method, - NULL); - nmc_add_prop_funcs (GLUE_IP (6, DNS), - nmc_property_ipv6_get_dns, - nmc_property_ipv6_set_dns, - nmc_property_ipv6_remove_dns, - nmc_property_ipv6_describe_dns, - NULL, - NULL); - nmc_add_prop_funcs (GLUE_IP (6, DNS_SEARCH), - nmc_property_ipv6_get_dns_search, - nmc_property_ipv6_set_dns_search, - nmc_property_ipv6_remove_dns_search, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE_IP (6, DNS_OPTIONS), - nmc_property_ipv6_get_dns_options, - nmc_property_ipv6_set_dns_options, - nmc_property_ipv6_remove_dns_option, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE_IP (6, DNS_PRIORITY), - nmc_property_ipv6_get_dns_priority, - nmc_property_set_int, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE_IP (6, ADDRESSES), - nmc_property_ip_get_addresses, - nmc_property_ipv6_set_addresses, - nmc_property_ipv6_remove_addresses, - nmc_property_ipv6_describe_addresses, - NULL, - NULL); - nmc_add_prop_funcs (GLUE_IP (6, GATEWAY), - nmc_property_ipv6_get_gateway, - nmc_property_ipv6_set_gateway, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE_IP (6, ROUTES), - nmc_property_ipv6_get_routes, - nmc_property_ipv6_set_routes, - nmc_property_ipv6_remove_routes, - nmc_property_ipv6_describe_routes, - NULL, - NULL); - nmc_add_prop_funcs (GLUE_IP (6, ROUTE_METRIC), - nmc_property_ipv6_get_route_metric, - nmc_property_set_int64, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE_IP (6, IGNORE_AUTO_ROUTES), - nmc_property_ipv6_get_ignore_auto_routes, - nmc_property_set_bool, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE_IP (6, IGNORE_AUTO_DNS), - nmc_property_ipv6_get_ignore_auto_dns, - nmc_property_set_bool, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE_IP (6, NEVER_DEFAULT), - nmc_property_ipv6_get_never_default, - nmc_property_set_bool, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE_IP (6, MAY_FAIL), - nmc_property_ipv6_get_may_fail, - nmc_property_set_bool, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (IP6_CONFIG, IP6_PRIVACY), - nmc_property_ipv6_get_ip6_privacy, - nmc_property_ipv6_set_ip6_privacy, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (IP6_CONFIG, ADDR_GEN_MODE), - nmc_property_ipv6_get_addr_gen_mode, - nmc_property_ipv6_set_addr_gen_mode, - NULL, - NULL, - nmc_property_ipv6_allowed_addr_gen_mode, - NULL); - nmc_add_prop_funcs (GLUE_IP (6, DHCP_SEND_HOSTNAME), - nmc_property_ipv6_get_dhcp_send_hostname, - nmc_property_set_bool, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE_IP (6, DHCP_HOSTNAME), - nmc_property_ipv6_get_dhcp_hostname, - nmc_property_set_string, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (IP6_CONFIG, TOKEN), - nmc_property_ipv6_get_token, - nmc_property_set_string, - NULL, - NULL, - NULL, - NULL); - - /* Add editable properties for NM_SETTING_OLPC_MESH_SETTING_NAME */ - nmc_add_prop_funcs (GLUE (OLPC_MESH, SSID), - nmc_property_olpc_get_ssid, - nmc_property_set_ssid, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (OLPC_MESH, CHANNEL), - nmc_property_olpc_get_channel, - nmc_property_olpc_set_channel, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (OLPC_MESH, DHCP_ANYCAST_ADDRESS), - nmc_property_olpc_get_anycast_address, - nmc_property_set_mac, - NULL, - NULL, - NULL, - NULL); - - /* Add editable properties for NM_SETTING_PPP_SETTING_NAME */ - nmc_add_prop_funcs (GLUE (PPP, NOAUTH), - nmc_property_ppp_get_noauth, - nmc_property_set_bool, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (PPP, REFUSE_EAP), - nmc_property_ppp_get_refuse_eap, - nmc_property_set_bool, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (PPP, REFUSE_PAP), - nmc_property_ppp_get_refuse_pap, - nmc_property_set_bool, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (PPP, REFUSE_CHAP), - nmc_property_ppp_get_refuse_chap, - nmc_property_set_bool, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (PPP, REFUSE_MSCHAP), - nmc_property_ppp_get_refuse_mschap, - nmc_property_set_bool, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (PPP, REFUSE_MSCHAPV2), - nmc_property_ppp_get_refuse_mschapv2, - nmc_property_set_bool, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (PPP, NOBSDCOMP), - nmc_property_ppp_get_nobsdcomp, - nmc_property_set_bool, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (PPP, NODEFLATE), - nmc_property_ppp_get_nodeflate, - nmc_property_set_bool, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (PPP, NO_VJ_COMP), - nmc_property_ppp_get_no_vj_comp, - nmc_property_set_bool, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (PPP, REQUIRE_MPPE), - nmc_property_ppp_get_require_mppe, - nmc_property_set_bool, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (PPP, REQUIRE_MPPE_128), - nmc_property_ppp_get_require_mppe_128, - nmc_property_set_bool, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (PPP, MPPE_STATEFUL), - nmc_property_ppp_get_mppe_stateful, - nmc_property_set_bool, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (PPP, CRTSCTS), - nmc_property_ppp_get_crtscts, - nmc_property_set_bool, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (PPP, BAUD), - nmc_property_ppp_get_baud, - nmc_property_set_uint, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (PPP, MRU), - nmc_property_ppp_get_mru, - nmc_property_set_uint, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (PPP, MTU), - nmc_property_ppp_get_mtu, - nmc_property_set_mtu, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (PPP, LCP_ECHO_FAILURE), - nmc_property_ppp_get_lcp_echo_failure, - nmc_property_set_uint, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (PPP, LCP_ECHO_INTERVAL), - nmc_property_ppp_get_lcp_echo_interval, - nmc_property_set_uint, - NULL, - NULL, - NULL, - NULL); - - /* Add editable properties for NM_SETTING_PPPOE_SETTING_NAME */ - nmc_add_prop_funcs (GLUE (PPPOE, SERVICE), - nmc_property_pppoe_get_service, - nmc_property_set_string, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (PPPOE, USERNAME), - nmc_property_pppoe_get_username, - nmc_property_set_string, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (PPPOE, PASSWORD), - nmc_property_pppoe_get_password, - nmc_property_set_string, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (PPPOE, PASSWORD_FLAGS), - nmc_property_pppoe_get_password_flags, - nmc_property_set_secret_flags, - NULL, - NULL, - NULL, - NULL); - - /* Add editable properties for NM_SETTING_SERIAL_SETTING_NAME */ - nmc_add_prop_funcs (GLUE (SERIAL, BAUD), - nmc_property_serial_get_baud, - nmc_property_set_uint, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (SERIAL, BITS), - nmc_property_serial_get_bits, - nmc_property_set_uint, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (SERIAL, PARITY), - nmc_property_serial_get_parity, - nmc_property_serial_set_parity, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (SERIAL, STOPBITS), - nmc_property_serial_get_stopbits, - nmc_property_set_uint, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (SERIAL, SEND_DELAY), - nmc_property_serial_get_send_delay, - nmc_property_set_uint, - NULL, - NULL, - NULL, - NULL); - - /* Add editable properties for NM_SETTING_TEAM_SETTING_NAME */ - nmc_add_prop_funcs (GLUE (TEAM, CONFIG), - nmc_property_team_get_config, - nmc_property_team_set_config, - NULL, - nmc_property_team_describe_config, - NULL, - NULL); - - /* Add editable properties for NM_SETTING_TEAM_PORT_SETTING_NAME */ - nmc_add_prop_funcs (GLUE (TEAM_PORT, CONFIG), - nmc_property_team_port_get_config, - nmc_property_team_set_config, - NULL, - nmc_property_team_describe_config, - NULL, - NULL); - - /* Add editable properties for NM_SETTING_VLAN_SETTING_NAME */ - nmc_add_prop_funcs (GLUE (VLAN, PARENT), - nmc_property_vlan_get_parent, - nmc_property_set_string, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (VLAN, ID), - nmc_property_vlan_get_id, - nmc_property_set_uint, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (VLAN, FLAGS), - nmc_property_vlan_get_flags, - nmc_property_set_flags, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (VLAN, INGRESS_PRIORITY_MAP), - nmc_property_vlan_get_ingress_priority_map, - nmc_property_vlan_set_ingress_priority_map, - nmc_property_vlan_remove_ingress_priority_map, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (VLAN, EGRESS_PRIORITY_MAP), - nmc_property_vlan_get_egress_priority_map, - nmc_property_vlan_set_egress_priority_map, - nmc_property_vlan_remove_egress_priority_map, - NULL, - NULL, - NULL); - - /* Add editable properties for NM_SETTING_VPN_SETTING_NAME */ - nmc_add_prop_funcs (GLUE (VPN, SERVICE_TYPE), - nmc_property_vpn_get_service_type, - nmc_property_set_vpn_service, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (VPN, USER_NAME), - nmc_property_vpn_get_user_name, - nmc_property_set_string, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (VPN, DATA), - nmc_property_vpn_get_data, - nmc_property_vpn_set_data, - nmc_property_vpn_remove_option_data, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (VPN, SECRETS), - nmc_property_vpn_get_secrets, - nmc_property_vpn_set_secrets, - nmc_property_vpn_remove_option_secret, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (VPN, PERSISTENT), - nmc_property_vpn_get_persistent, - nmc_property_set_bool, - NULL, - NULL, - NULL, - NULL); - - nmc_add_prop_funcs (GLUE (VPN, TIMEOUT), - nmc_property_vpn_get_timeout, - nmc_property_set_uint, - NULL, - NULL, - NULL, - NULL); - - /* Add editable properties for NM_SETTING_WIMAX_SETTING_NAME */ - nmc_add_prop_funcs (GLUE (WIMAX, NETWORK_NAME), - nmc_property_wimax_get_network_name, - nmc_property_set_string, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (WIMAX, MAC_ADDRESS), - nmc_property_wimax_get_mac_address, - nmc_property_set_mac, - NULL, - NULL, - NULL, - NULL); - - /* Add editable properties for NM_SETTING_WIRED_SETTING_NAME */ - nmc_add_prop_funcs (GLUE (WIRED, PORT), - nmc_property_wired_get_port, - NULL, /* nmc_property_wired_set_port, */ - NULL, - NULL, - NULL, /* nmc_property_wired_allowed_port, */ - NULL); - nmc_add_prop_funcs (GLUE (WIRED, SPEED), - nmc_property_wired_get_speed, - nmc_property_set_uint, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (WIRED, DUPLEX), - nmc_property_wired_get_duplex, - nmc_property_wired_set_duplex, - NULL, - NULL, - nmc_property_wired_allowed_duplex, - NULL); - nmc_add_prop_funcs (GLUE (WIRED, AUTO_NEGOTIATE), - nmc_property_wired_get_auto_negotiate, - nmc_property_set_bool, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (WIRED, MAC_ADDRESS), - nmc_property_wired_get_mac_address, - nmc_property_set_mac, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (WIRED, CLONED_MAC_ADDRESS), - nmc_property_wired_get_cloned_mac_address, - nmc_property_set_mac_cloned, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (WIRED, GENERATE_MAC_ADDRESS_MASK), - nmc_property_wired_get_generate_mac_address_mask, - nmc_property_set_string, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (WIRED, MAC_ADDRESS_BLACKLIST), - nmc_property_wired_get_mac_address_blacklist, - nmc_property_wired_set_mac_address_blacklist, - nmc_property_wired_remove_mac_address_blacklist, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (WIRED, MTU), - nmc_property_wired_get_mtu, - nmc_property_set_mtu, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (WIRED, S390_SUBCHANNELS), - nmc_property_wired_get_s390_subchannels, - nmc_property_wired_set_s390_subchannels, - NULL, - nmc_property_wired_describe_s390_subchannels, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (WIRED, S390_NETTYPE), - nmc_property_wired_get_s390_nettype, - nmc_property_wired_set_s390_nettype, - NULL, - NULL, - nmc_property_wired_allowed_s390_nettype, - NULL); - nmc_add_prop_funcs (GLUE (WIRED, S390_OPTIONS), - nmc_property_wired_get_s390_options, - nmc_property_wired_set_s390_options, - nmc_property_wired_remove_option_s390_options, - nmc_property_wired_describe_s390_options, - nmc_property_wired_allowed_s390_options, - NULL); - nmc_add_prop_funcs (GLUE (WIRED, WAKE_ON_LAN), - nmc_property_wired_get_wake_on_lan, - nmc_property_wired_set_wake_on_lan, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (WIRED, WAKE_ON_LAN_PASSWORD), - nmc_property_wired_get_wake_on_lan_password, - nmc_property_set_mac, - NULL, - NULL, - NULL, - NULL); - - /* Add editable properties for NM_SETTING_WIRELESS_SETTING_NAME */ - nmc_add_prop_funcs (GLUE (WIRELESS, SSID), - nmc_property_wireless_get_ssid, - nmc_property_set_ssid, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (WIRELESS, MODE), - nmc_property_wireless_get_mode, - nmc_property_wifi_set_mode, - NULL, - NULL, - nmc_property_wifi_allowed_mode, - NULL); - nmc_add_prop_funcs (GLUE (WIRELESS, BAND), - nmc_property_wireless_get_band, - nmc_property_wifi_set_band, - NULL, - NULL, - nmc_property_wifi_allowed_band, - NULL); - nmc_add_prop_funcs (GLUE (WIRELESS, CHANNEL), - nmc_property_wireless_get_channel, - nmc_property_wifi_set_channel, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (WIRELESS, BSSID), - nmc_property_wireless_get_bssid, - nmc_property_set_mac, - NULL, - NULL, - NULL, - NULL); - /* - * Do not allow setting 'rate' and 'tx-power'. They are not implemented in - * NM core, nor in ifcfg-rh plugin (thus not preserved over re-reading). - */ - nmc_add_prop_funcs (GLUE (WIRELESS, RATE), - nmc_property_wireless_get_rate, - NULL, /* editing rate disabled */ - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (WIRELESS, TX_POWER), - nmc_property_wireless_get_tx_power, - NULL, /* editing tx-power disabled */ - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (WIRELESS, MAC_ADDRESS), - nmc_property_wireless_get_mac_address, - nmc_property_set_mac, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (WIRELESS, CLONED_MAC_ADDRESS), - nmc_property_wireless_get_cloned_mac_address, - nmc_property_set_mac_cloned, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (WIRELESS, GENERATE_MAC_ADDRESS_MASK), - nmc_property_wireless_get_generate_mac_address_mask, - nmc_property_set_string, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (WIRELESS, MAC_ADDRESS_BLACKLIST), - nmc_property_wireless_get_mac_address_blacklist, - nmc_property_wireless_set_mac_address_blacklist, - nmc_property_wireless_remove_mac_address_blacklist, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (WIRELESS, SEEN_BSSIDS), - nmc_property_wireless_get_seen_bssids, - NULL, /* read-only */ - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (WIRELESS, MTU), - nmc_property_wireless_get_mtu, - nmc_property_set_mtu, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (WIRELESS, HIDDEN), - nmc_property_wireless_get_hidden, - nmc_property_set_bool, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (WIRELESS, POWERSAVE), - nmc_property_wireless_get_powersave, - nmc_property_wireless_set_powersave, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (WIRELESS, MAC_ADDRESS_RANDOMIZATION), - nmc_property_wireless_get_mac_address_randomization, - nmc_property_wireless_set_mac_address_randomization, - NULL, - NULL, - NULL, - NULL); - - /* Add editable properties for NM_SETTING_WIRELESS_SECURITY_SETTING_NAME */ - nmc_add_prop_funcs (GLUE (WIRELESS_SECURITY, KEY_MGMT), - nmc_property_wifi_sec_get_key_mgmt, - nmc_property_wifi_sec_set_key_mgmt, - NULL, - NULL, - nmc_property_wifi_sec_allowed_key_mgmt, - NULL); - nmc_add_prop_funcs (GLUE (WIRELESS_SECURITY, WEP_TX_KEYIDX), - nmc_property_wifi_sec_get_wep_tx_keyidx, - nmc_property_set_uint, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (WIRELESS_SECURITY, AUTH_ALG), - nmc_property_wifi_sec_get_auth_alg, - nmc_property_wifi_sec_set_auth_alg, - NULL, - NULL, - nmc_property_wifi_sec_allowed_auth_alg, - NULL); - nmc_add_prop_funcs (GLUE (WIRELESS_SECURITY, PROTO), - nmc_property_wifi_sec_get_proto, - nmc_property_wifi_sec_set_proto, - nmc_property_wifi_sec_remove_proto, - NULL, - nmc_property_wifi_sec_allowed_proto, - NULL); - nmc_add_prop_funcs (GLUE (WIRELESS_SECURITY, PAIRWISE), - nmc_property_wifi_sec_get_pairwise, - nmc_property_wifi_sec_set_pairwise, - nmc_property_wifi_sec_remove_pairwise, - NULL, - nmc_property_wifi_sec_allowed_pairwise, - NULL); - nmc_add_prop_funcs (GLUE (WIRELESS_SECURITY, GROUP), - nmc_property_wifi_sec_get_group, - nmc_property_wifi_sec_set_group, - nmc_property_wifi_sec_remove_group, - NULL, - nmc_property_wifi_sec_allowed_group, - NULL); - nmc_add_prop_funcs (GLUE (WIRELESS_SECURITY, LEAP_USERNAME), - nmc_property_wifi_sec_get_leap_username, - nmc_property_set_string, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (WIRELESS_SECURITY, WEP_KEY0), - nmc_property_wifi_sec_get_wep_key0, - nmc_property_wifi_set_wep_key, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (WIRELESS_SECURITY, WEP_KEY1), - nmc_property_wifi_sec_get_wep_key1, - nmc_property_wifi_set_wep_key, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (WIRELESS_SECURITY, WEP_KEY2), - nmc_property_wifi_sec_get_wep_key2, - nmc_property_wifi_set_wep_key, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (WIRELESS_SECURITY, WEP_KEY3), - nmc_property_wifi_sec_get_wep_key3, - nmc_property_wifi_set_wep_key, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (WIRELESS_SECURITY, WEP_KEY_FLAGS), - nmc_property_wifi_sec_get_wep_key_flags, - nmc_property_set_secret_flags, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (WIRELESS_SECURITY, WEP_KEY_TYPE), - nmc_property_wifi_sec_get_wep_key_type, - nmc_property_wifi_set_wep_key_type, - NULL, - nmc_property_wifi_describe_wep_key_type, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (WIRELESS_SECURITY, PSK), - nmc_property_wifi_sec_get_psk, - nmc_property_wifi_set_psk, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (WIRELESS_SECURITY, PSK_FLAGS), - nmc_property_wifi_sec_get_psk_flags, - nmc_property_set_secret_flags, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (WIRELESS_SECURITY, LEAP_PASSWORD), - nmc_property_wifi_sec_get_leap_password, - nmc_property_set_string, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (WIRELESS_SECURITY, LEAP_PASSWORD_FLAGS), - nmc_property_wifi_sec_get_leap_password_flags, - nmc_property_set_secret_flags, - NULL, - NULL, - NULL, - NULL); - - /* Add editable properties for NM_SETTING_TUN_SETTING_NAME */ - nmc_add_prop_funcs (GLUE (TUN, MODE), - nmc_property_tun_get_mode, - nmc_property_tun_set_mode, - NULL, - NULL, - nmc_property_tun_allowed_mode, - NULL); - nmc_add_prop_funcs (GLUE (TUN, OWNER), - nmc_property_tun_get_owner, - nmc_property_set_string, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (TUN, GROUP), - nmc_property_tun_get_group, - nmc_property_set_string, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (TUN, PI), - nmc_property_tun_get_pi, - nmc_property_set_bool, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (TUN, VNET_HDR), - nmc_property_tun_get_vnet_hdr, - nmc_property_set_bool, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (TUN, MULTI_QUEUE), - nmc_property_tun_get_multi_queue, - nmc_property_set_bool, - NULL, - NULL, - NULL, - NULL); - - /* Add editable properties for NM_SETTING_IP_TUNNEL_SETTING_NAME */ - nmc_add_prop_funcs (GLUE (IP_TUNNEL, MODE), - nmc_property_ip_tunnel_get_mode, - nmc_property_ip_tunnel_set_mode, - NULL, - NULL, - nmc_property_ip_tunnel_allowed_mode, - NULL); - nmc_add_prop_funcs (GLUE (IP_TUNNEL, PARENT), - nmc_property_ip_tunnel_get_parent, - nmc_property_set_string, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (IP_TUNNEL, LOCAL), - nmc_property_ip_tunnel_get_local, - nmc_property_set_string, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (IP_TUNNEL, REMOTE), - nmc_property_ip_tunnel_get_remote, - nmc_property_set_string, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (IP_TUNNEL, TTL), - nmc_property_ip_tunnel_get_ttl, - nmc_property_set_uint, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (IP_TUNNEL, TOS), - nmc_property_ip_tunnel_get_tos, - nmc_property_set_uint, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (IP_TUNNEL, PATH_MTU_DISCOVERY), - nmc_property_ip_tunnel_get_path_mtu_discovery, - nmc_property_set_bool, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (IP_TUNNEL, INPUT_KEY), - nmc_property_ip_tunnel_get_input_key, - nmc_property_set_string, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (IP_TUNNEL, OUTPUT_KEY), - nmc_property_ip_tunnel_get_output_key, - nmc_property_set_string, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (IP_TUNNEL, ENCAPSULATION_LIMIT), - nmc_property_ip_tunnel_get_encapsulation_limit, - nmc_property_set_uint, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (IP_TUNNEL, FLOW_LABEL), - nmc_property_ip_tunnel_get_flow_label, - nmc_property_set_uint, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (IP_TUNNEL, MTU), - nmc_property_ip_tunnel_get_mtu, - nmc_property_set_uint, - NULL, - NULL, - NULL, - NULL); - - /* Add editable properties for NM_SETTING_MACSEC_SETTING_NAME */ - nmc_add_prop_funcs (GLUE (MACSEC, PARENT), - nmc_property_macsec_get_parent, - nmc_property_set_string, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (MACSEC, MODE), - nmc_property_macsec_get_mode, - nmc_property_macsec_set_mode, - NULL, - NULL, - nmc_property_macsec_allowed_mode, - NULL); - nmc_add_prop_funcs (GLUE (MACSEC, ENCRYPT), - nmc_property_macsec_get_encrypt, - nmc_property_set_bool, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (MACSEC, MKA_CAK), - nmc_property_macsec_get_mka_cak, - nmc_property_set_string, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (MACSEC, MKA_CAK_FLAGS), - nmc_property_macsec_get_mka_cak_flags, - nmc_property_set_secret_flags, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (MACSEC, MKA_CKN), - nmc_property_macsec_get_mka_ckn, - nmc_property_set_string, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (MACSEC, PORT), - nmc_property_macsec_get_port, - nmc_property_set_int, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (MACSEC, VALIDATION), - nmc_property_macsec_get_validation, - nmc_property_macsec_set_validation, - NULL, - NULL, - nmc_property_macsec_allowed_validation, - NULL); - - /* Add editable properties for NM_SETTING_MACVLAN_SETTING_NAME */ - nmc_add_prop_funcs (GLUE (MACVLAN, PARENT), - nmc_property_macvlan_get_parent, - nmc_property_set_string, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (MACVLAN, MODE), - nmc_property_macvlan_get_mode, - nmc_property_macvlan_set_mode, - NULL, - NULL, - nmc_property_macvlan_allowed_mode, - NULL); - nmc_add_prop_funcs (GLUE (MACVLAN, PROMISCUOUS), - nmc_property_macvlan_get_promiscuous, - nmc_property_set_bool, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (MACVLAN, TAP), - nmc_property_macvlan_get_tap, - nmc_property_set_bool, - NULL, - NULL, - NULL, - NULL); - - /* Add editable properties for NM_SETTING_VXLAN_SETTING_NAME */ - nmc_add_prop_funcs (GLUE (VXLAN, PARENT), - nmc_property_vxlan_get_parent, - nmc_property_set_string, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (VXLAN, ID), - nmc_property_vxlan_get_id, - nmc_property_set_uint, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (VXLAN, LOCAL), - nmc_property_vxlan_get_local, - nmc_property_set_string, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (VXLAN, REMOTE), - nmc_property_vxlan_get_remote, - nmc_property_set_string, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (VXLAN, SOURCE_PORT_MIN), - nmc_property_vxlan_get_source_port_min, - nmc_property_set_uint, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (VXLAN, SOURCE_PORT_MAX), - nmc_property_vxlan_get_source_port_max, - nmc_property_set_uint, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (VXLAN, DESTINATION_PORT), - nmc_property_vxlan_get_destination_port, - nmc_property_set_uint, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (VXLAN, TOS), - nmc_property_vxlan_get_tos, - nmc_property_set_uint, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (VXLAN, TTL), - nmc_property_vxlan_get_ttl, - nmc_property_set_uint, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (VXLAN, AGEING), - nmc_property_vxlan_get_ageing, - nmc_property_set_uint, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (VXLAN, LIMIT), - nmc_property_vxlan_get_limit, - nmc_property_set_uint, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (VXLAN, LEARNING), - nmc_property_vxlan_get_learning, - nmc_property_set_bool, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (VXLAN, PROXY), - nmc_property_vxlan_get_proxy, - nmc_property_set_bool, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (VXLAN, RSC), - nmc_property_vxlan_get_rsc, - nmc_property_set_bool, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (VXLAN, L2_MISS), - nmc_property_vxlan_get_l2_miss, - nmc_property_set_bool, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (VXLAN, L3_MISS), - nmc_property_vxlan_get_l3_miss, - nmc_property_set_bool, - NULL, - NULL, - NULL, - NULL); - - /* Add editable properties for NM_SETTING_PROXY_SETTING_NAME */ - nmc_add_prop_funcs (GLUE (PROXY, METHOD), - nmc_property_proxy_get_method, - nmc_property_proxy_set_method, - NULL, - NULL, - nmc_property_proxy_allowed_method, - NULL); - nmc_add_prop_funcs (GLUE (PROXY, BROWSER_ONLY), - nmc_property_proxy_get_browser_only, - nmc_property_set_bool, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (PROXY, PAC_URL), - nmc_property_proxy_get_pac_url, - nmc_property_set_string, - NULL, - NULL, - NULL, - NULL); - nmc_add_prop_funcs (GLUE (PROXY, PAC_SCRIPT), - nmc_property_proxy_get_pac_script, - nmc_property_proxy_set_pac_script, - NULL, - NULL, - NULL, - NULL); -} - -void -nmc_properties_cleanup () -{ - if (nmc_properties) - g_hash_table_destroy (nmc_properties); -} - -static const NmcPropertyFuncs * -nmc_properties_find (const char *s_name, const char *p_name) -{ - char *key; - gsize p_l, s_l; - - nmc_properties_init (); - - s_l = strlen (s_name); - p_l = strlen (p_name); - key = g_alloca (s_l + p_l + 1); - memcpy (&key[ 0], s_name, s_l); - memcpy (&key[s_l], p_name, p_l + 1); - return (NmcPropertyFuncs *) g_hash_table_lookup (nmc_properties, key); -} +/*****************************************************************************/ static char * -get_property_val (NMSetting *setting, const char *prop, NmcPropertyGetType get_type, GError **error) +get_property_val (NMSetting *setting, const char *prop, NMMetaAccessorGetType get_type, gboolean show_secrets, GError **error) { - const NmcPropertyFuncs *item; + const NMMetaSettingInfoEditor *setting_info; + const NMMetaPropertyInfo *property_info; g_return_val_if_fail (NM_IS_SETTING (setting), FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - item = nmc_properties_find (nm_setting_get_name (setting), prop); - if (item && item->get_func) - return item->get_func (setting, get_type); + if ((property_info = _meta_find_property_info_by_setting (setting, prop, &setting_info))) { + if (property_info->is_name) { + /* Traditionally, the "name" property was not handled here. + * For the moment, skip it from get_property_val(). */ + } else if (property_info->property_type->get_fcn) { + return property_info->property_type->get_fcn (setting_info, + property_info, + setting, + get_type, + show_secrets); + } + } g_set_error_literal (error, 1, 0, _("don't know how to get the property value")); return NULL; @@ -8413,7 +566,7 @@ get_property_val (NMSetting *setting, const char *prop, NmcPropertyGetType get_t char * nmc_setting_get_property (NMSetting *setting, const char *prop, GError **error) { - return get_property_val (setting, prop, NMC_PROPERTY_GET_PRETTY, error); + return get_property_val (setting, prop, NM_META_ACCESSOR_GET_TYPE_PRETTY, TRUE, error); } /* @@ -8423,33 +576,44 @@ nmc_setting_get_property (NMSetting *setting, const char *prop, GError **error) char * nmc_setting_get_property_parsable (NMSetting *setting, const char *prop, GError **error) { - return get_property_val (setting, prop, NMC_PROPERTY_GET_PARSABLE, error); + return get_property_val (setting, prop, NM_META_ACCESSOR_GET_TYPE_PARSABLE, TRUE, error); } /* * Generic function for setting property value. * - * Sets property=val in setting by calling specialized functions. - * If val is NULL then default property value is set. + * Sets property=value in setting by calling specialized functions. + * If value is NULL then default property value is set. * * Returns: TRUE on success; FALSE on failure and sets error */ gboolean -nmc_setting_set_property (NMSetting *setting, const char *prop, const char *val, GError **error) +nmc_setting_set_property (NMSetting *setting, const char *prop, const char *value, GError **error) { - const NmcPropertyFuncs *item; + const NMMetaSettingInfoEditor *setting_info; + const NMMetaPropertyInfo *property_info; g_return_val_if_fail (NM_IS_SETTING (setting), FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - item = nmc_properties_find (nm_setting_get_name (setting), prop); - if (item && item->set_func) { - if (!val) { + if ((property_info = _meta_find_property_info_by_setting (setting, prop, &setting_info))) { + + if (!value) { /* No value argument sets default value */ nmc_property_set_default_value (setting, prop); return TRUE; } - return item->set_func (setting, prop, val, error); + + if (property_info->is_name) { + /* Traditionally, the "name" property was not handled here. + * For the moment, skip it from get_property_val(). */ + } else if (property_info->property_type->set_fcn) { + return property_info->property_type->set_fcn (setting_info, + property_info, + setting, + value, + error); + } } g_set_error_literal (error, 1, 0, _("the property can't be changed")); @@ -8482,16 +646,22 @@ nmc_property_set_default_value (NMSetting *setting, const char *prop) gboolean nmc_setting_reset_property (NMSetting *setting, const char *prop, GError **error) { - const NmcPropertyFuncs *item; + const NMMetaSettingInfoEditor *setting_info; + const NMMetaPropertyInfo *property_info; g_return_val_if_fail (NM_IS_SETTING (setting), FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - item = nmc_properties_find (nm_setting_get_name (setting), prop); - if (item && item->set_func) { - nmc_property_set_default_value (setting, prop); - return TRUE; + if ((property_info = _meta_find_property_info_by_setting (setting, prop, &setting_info))) { + if (property_info->is_name) { + /* Traditionally, the "name" property was not handled here. + * For the moment, skip it from get_property_val(). */ + } else if (property_info->property_type->set_fcn) { + nmc_property_set_default_value (setting, prop); + return TRUE; + } } + g_set_error_literal (error, 1, 0, _("the property can't be changed")); return FALSE; } @@ -8512,14 +682,25 @@ nmc_setting_remove_property_option (NMSetting *setting, guint32 idx, GError **error) { - const NmcPropertyFuncs *item; + const NMMetaSettingInfoEditor *setting_info; + const NMMetaPropertyInfo *property_info; g_return_val_if_fail (NM_IS_SETTING (setting), FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - item = nmc_properties_find (nm_setting_get_name (setting), prop); - if (item && item->remove_func) - return item->remove_func (setting, prop, option, idx, error); + if ((property_info = _meta_find_property_info_by_setting (setting, prop, &setting_info))) { + if (property_info->is_name) { + /* Traditionally, the "name" property was not handled here. + * For the moment, skip it from get_property_val(). */ + } else if (property_info->property_type->remove_fcn) { + return property_info->property_type->remove_fcn (setting_info, + property_info, + setting, + option, + idx, + error); + } + } return TRUE; } @@ -8555,20 +736,29 @@ nmc_setting_get_valid_properties (NMSetting *setting) return valid_props; } -/* - * Return allowed values for 'prop' as a string. - */ -const char ** -nmc_setting_get_property_allowed_values (NMSetting *setting, const char *prop) +const char *const* +nmc_setting_get_property_allowed_values (NMSetting *setting, const char *prop, char ***out_to_free) { - const NmcPropertyFuncs *item; + const NMMetaSettingInfoEditor *setting_info; + const NMMetaPropertyInfo *property_info; g_return_val_if_fail (NM_IS_SETTING (setting), FALSE); + g_return_val_if_fail (out_to_free, FALSE); - item = nmc_properties_find (nm_setting_get_name (setting), prop); - if (item && item->values_func) - return item->values_func (setting, prop); + *out_to_free = NULL; + + if ((property_info = _meta_find_property_info_by_setting (setting, prop, &setting_info))) { + if (property_info->is_name) { + /* Traditionally, the "name" property was not handled here. + * For the moment, skip it from get_property_val(). */ + } else if (property_info->property_type->values_fcn) { + return property_info->property_type->values_fcn (setting_info, + property_info, + out_to_free); + } else if (property_info->property_typ_data && property_info->property_typ_data->values_static) + return property_info->property_typ_data->values_static; + } return NULL; } @@ -8586,12 +776,14 @@ nmc_setting_get_property_allowed_values (NMSetting *setting, const char *prop) char * nmc_setting_get_property_desc (NMSetting *setting, const char *prop) { - const NmcPropertyFuncs *item; + gs_free char *desc_to_free = NULL; const char *setting_desc = NULL; const char *setting_desc_title = ""; const char *nmcli_desc = NULL; const char *nmcli_desc_title = ""; const char *nmcli_nl = ""; + const NMMetaSettingInfoEditor *setting_info; + const NMMetaPropertyInfo *property_info; g_return_val_if_fail (NM_IS_SETTING (setting), FALSE); @@ -8599,13 +791,25 @@ nmc_setting_get_property_desc (NMSetting *setting, const char *prop) if (setting_desc) setting_desc_title = _("[NM property description]"); - item = nmc_properties_find (nm_setting_get_name (setting), prop); - if (item && item->describe_func) { - nmcli_desc = item->describe_func (setting, prop); - nmcli_desc_title = _("[nmcli specific description]"); - nmcli_nl = "\n"; + if ((property_info = _meta_find_property_info_by_setting (setting, prop, &setting_info))) { + const char *desc = NULL; + + if (property_info->is_name) { + /* Traditionally, the "name" property was not handled here. + * For the moment, skip it from get_property_val(). */ + } else if (property_info->property_type->describe_fcn) { + desc = property_info->property_type->describe_fcn (setting_info, property_info, &desc_to_free); + } else + desc = property_info->describe_message; + + if (desc) { + nmcli_desc = _(desc); + nmcli_desc_title = _("[nmcli specific description]"); + nmcli_nl = "\n"; + } } + return g_strdup_printf ("%s\n%s\n%s%s%s%s", setting_desc_title, setting_desc ? setting_desc : "", @@ -8648,1271 +852,75 @@ nmc_property_set_gvalue (NMSetting *setting, const char *prop, GValue *value) return FALSE; } -/*----------------------------------------------------------------------------*/ - -#define GET_SECRET(show, setting, func, type) \ - (show ? func (setting, type) : g_strdup (_("<hidden>"))) - -static gboolean -setting_connection_details (NMSetting *setting, NmCli *nmc, - const char *one_prop, - gboolean secrets, - NmcPropertyGetType type) -{ - NMSettingConnection *s_con = NM_SETTING_CONNECTION (setting); - NmcOutputField *tmpl, *arr; - size_t tmpl_len; - - g_return_val_if_fail (NM_IS_SETTING_CONNECTION (s_con), FALSE); - - tmpl = nmc_fields_setting_connection; - tmpl_len = sizeof (nmc_fields_setting_connection); - nmc->print_fields.indices = parse_output_fields (one_prop ? one_prop : NMC_FIELDS_SETTING_CONNECTION_ALL, - tmpl, FALSE, NULL, NULL); - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); - g_ptr_array_add (nmc->output_data, arr); - - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX); - set_val_str (arr, 0, g_strdup (nm_setting_get_name (setting))); - set_val_str (arr, 1, nmc_property_connection_get_id (setting, type)); - set_val_str (arr, 2, nmc_property_connection_get_uuid (setting, type)); - set_val_str (arr, 3, nmc_property_connection_get_stable_id (setting, type)); - set_val_str (arr, 4, nmc_property_connection_get_interface_name (setting, type)); - set_val_str (arr, 5, nmc_property_connection_get_type (setting, type)); - set_val_str (arr, 6, nmc_property_connection_get_autoconnect (setting, type)); - set_val_str (arr, 7, nmc_property_connection_get_autoconnect_priority (setting, type)); - set_val_str (arr, 8, nmc_property_connection_get_autoconnect_retries (setting, type)); - set_val_str (arr, 9, nmc_property_connection_get_timestamp (setting, type)); - set_val_str (arr, 10, nmc_property_connection_get_read_only (setting, type)); - set_val_str (arr, 11, nmc_property_connection_get_permissions (setting, type)); - set_val_str (arr, 12, nmc_property_connection_get_zone (setting, type)); - set_val_str (arr, 13, nmc_property_connection_get_master (setting, type)); - set_val_str (arr, 14, nmc_property_connection_get_slave_type (setting, type)); - set_val_str (arr, 15, nmc_property_connection_get_autoconnect_slaves (setting, type)); - set_val_str (arr, 16, nmc_property_connection_get_secondaries (setting, type)); - set_val_str (arr, 17, nmc_property_connection_get_gateway_ping_timeout (setting, type)); - set_val_str (arr, 18, nmc_property_connection_get_metered (setting, type)); - set_val_str (arr, 19, nmc_property_connection_get_lldp (setting, type)); - g_ptr_array_add (nmc->output_data, arr); - - print_data (nmc); /* Print all data */ - - return TRUE; -} - -static gboolean -setting_wired_details (NMSetting *setting, - NmCli *nmc, - const char *one_prop, - gboolean secrets, - NmcPropertyGetType type) -{ - NMSettingWired *s_wired = NM_SETTING_WIRED (setting); - NmcOutputField *tmpl, *arr; - size_t tmpl_len; - - g_return_val_if_fail (NM_IS_SETTING_WIRED (s_wired), FALSE); - - tmpl = nmc_fields_setting_wired; - tmpl_len = sizeof (nmc_fields_setting_wired); - nmc->print_fields.indices = parse_output_fields (one_prop ? one_prop : NMC_FIELDS_SETTING_WIRED_ALL, - tmpl, FALSE, NULL, NULL); - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); - g_ptr_array_add (nmc->output_data, arr); - - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX); - set_val_str (arr, 0, g_strdup (nm_setting_get_name (setting))); - set_val_str (arr, 1, nmc_property_wired_get_port (setting, type)); - set_val_str (arr, 2, nmc_property_wired_get_speed (setting, type)); - set_val_str (arr, 3, nmc_property_wired_get_duplex (setting, type)); - set_val_str (arr, 4, nmc_property_wired_get_auto_negotiate (setting, type)); - set_val_str (arr, 5, nmc_property_wired_get_mac_address (setting, type)); - set_val_str (arr, 6, nmc_property_wired_get_cloned_mac_address (setting, type)); - set_val_str (arr, 7, nmc_property_wired_get_generate_mac_address_mask (setting, type)); - set_val_str (arr, 8, nmc_property_wired_get_mac_address_blacklist (setting, type)); - set_val_str (arr, 9, nmc_property_wired_get_mtu (setting, type)); - set_val_str (arr, 10, nmc_property_wired_get_s390_subchannels (setting, type)); - set_val_str (arr, 11, nmc_property_wired_get_s390_nettype (setting, type)); - set_val_str (arr, 12, nmc_property_wired_get_s390_options (setting, type)); - set_val_str (arr, 13, nmc_property_wired_get_wake_on_lan (setting, type)); - set_val_str (arr, 14, nmc_property_wired_get_wake_on_lan_password (setting, type)); - g_ptr_array_add (nmc->output_data, arr); - - print_data (nmc); /* Print all data */ - - return TRUE; -} - -static gboolean -setting_802_1X_details (NMSetting *setting, - NmCli *nmc, - const char *one_prop, - gboolean secrets, - NmcPropertyGetType type) -{ - NMSetting8021x *s_8021x = NM_SETTING_802_1X (setting); - NmcOutputField *tmpl, *arr; - size_t tmpl_len; - - g_return_val_if_fail (NM_IS_SETTING_802_1X (s_8021x), FALSE); - - tmpl = nmc_fields_setting_8021X; - tmpl_len = sizeof (nmc_fields_setting_8021X); - nmc->print_fields.indices = parse_output_fields (one_prop ? one_prop : NMC_FIELDS_SETTING_802_1X_ALL, - tmpl, FALSE, NULL, NULL); - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); - g_ptr_array_add (nmc->output_data, arr); - - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX); - set_val_str (arr, 0, g_strdup (nm_setting_get_name (setting))); - set_val_str (arr, 1, nmc_property_802_1X_get_eap (setting, type)); - set_val_str (arr, 2, nmc_property_802_1X_get_identity (setting, type)); - set_val_str (arr, 3, nmc_property_802_1X_get_anonymous_identity (setting, type)); - set_val_str (arr, 4, nmc_property_802_1X_get_pac_file (setting, type)); - set_val_str (arr, 5, nmc_property_802_1X_get_ca_cert (setting, type)); - set_val_str (arr, 6, GET_SECRET (secrets, setting, nmc_property_802_1X_get_ca_cert_password, type)); - set_val_str (arr, 7, nmc_property_802_1X_get_ca_cert_password_flags (setting, type)); - set_val_str (arr, 8, nmc_property_802_1X_get_ca_path (setting, type)); - set_val_str (arr, 9, nmc_property_802_1X_get_subject_match (setting, type)); - set_val_str (arr, 10, nmc_property_802_1X_get_altsubject_matches (setting, type)); - set_val_str (arr, 11, nmc_property_802_1X_get_domain_suffix_match (setting, type)); - set_val_str (arr, 12, nmc_property_802_1X_get_client_cert (setting, type, secrets)); - set_val_str (arr, 13, GET_SECRET (secrets, setting, nmc_property_802_1X_get_client_cert_password, type)); - set_val_str (arr, 14, nmc_property_802_1X_get_client_cert_password_flags (setting, type)); - set_val_str (arr, 15, nmc_property_802_1X_get_phase1_peapver (setting, type)); - set_val_str (arr, 16, nmc_property_802_1X_get_phase1_peaplabel (setting, type)); - set_val_str (arr, 17, nmc_property_802_1X_get_phase1_fast_provisioning (setting, type)); - set_val_str (arr, 18, nmc_property_802_1X_get_phase1_auth_flags (setting, type)); - set_val_str (arr, 19, nmc_property_802_1X_get_phase2_auth (setting, type)); - set_val_str (arr, 20, nmc_property_802_1X_get_phase2_autheap (setting, type)); - set_val_str (arr, 21, nmc_property_802_1X_get_phase2_ca_cert (setting, type)); - set_val_str (arr, 22, GET_SECRET (secrets, setting, nmc_property_802_1X_get_phase2_ca_cert_password, type)); - set_val_str (arr, 23, nmc_property_802_1X_get_phase2_ca_cert_password_flags (setting, type)); - set_val_str (arr, 24, nmc_property_802_1X_get_phase2_ca_path (setting, type)); - set_val_str (arr, 25, nmc_property_802_1X_get_phase2_subject_match (setting, type)); - set_val_str (arr, 26, nmc_property_802_1X_get_phase2_altsubject_matches (setting, type)); - set_val_str (arr, 27, nmc_property_802_1X_get_phase2_domain_suffix_match (setting, type)); - set_val_str (arr, 28, nmc_property_802_1X_get_phase2_client_cert (setting, type, secrets)); - set_val_str (arr, 29, GET_SECRET (secrets, setting, nmc_property_802_1X_get_phase2_client_cert_password, type)); - set_val_str (arr, 30, nmc_property_802_1X_get_phase2_client_cert_password_flags (setting, type)); - set_val_str (arr, 31, GET_SECRET (secrets, setting, nmc_property_802_1X_get_password, type)); - set_val_str (arr, 32, nmc_property_802_1X_get_password_flags (setting, type)); - set_val_str (arr, 33, GET_SECRET (secrets, setting, nmc_property_802_1X_get_password_raw, type)); - set_val_str (arr, 34, nmc_property_802_1X_get_password_raw_flags (setting, type)); - set_val_str (arr, 35, nmc_property_802_1X_get_private_key (setting, type, secrets)); - set_val_str (arr, 36, GET_SECRET (secrets, setting, nmc_property_802_1X_get_private_key_password, type)); - set_val_str (arr, 37, nmc_property_802_1X_get_private_key_password_flags (setting, type)); - set_val_str (arr, 38, nmc_property_802_1X_get_phase2_private_key (setting, type, secrets)); - set_val_str (arr, 39, GET_SECRET (secrets, setting, nmc_property_802_1X_get_phase2_private_key_password, type)); - set_val_str (arr, 40, nmc_property_802_1X_get_phase2_private_key_password_flags (setting, type)); - set_val_str (arr, 41, GET_SECRET (secrets, setting, nmc_property_802_1X_get_pin, type)); - set_val_str (arr, 42, nmc_property_802_1X_get_pin_flags (setting, type)); - set_val_str (arr, 43, nmc_property_802_1X_get_system_ca_certs (setting, type)); - set_val_str (arr, 44, nmc_property_802_1X_get_auth_timeout (setting, type)); - g_ptr_array_add (nmc->output_data, arr); - - print_data (nmc); /* Print all data */ - - return TRUE; -} - -static gboolean -setting_wireless_details (NMSetting *setting, - NmCli *nmc, - const char *one_prop, - gboolean secrets, - NmcPropertyGetType type) -{ - NMSettingWireless *s_wireless = NM_SETTING_WIRELESS (setting); - NmcOutputField *tmpl, *arr; - size_t tmpl_len; - - g_return_val_if_fail (NM_IS_SETTING_WIRELESS (s_wireless), FALSE); - - tmpl = nmc_fields_setting_wireless; - tmpl_len = sizeof (nmc_fields_setting_wireless); - nmc->print_fields.indices = parse_output_fields (one_prop ? one_prop : NMC_FIELDS_SETTING_WIRELESS_ALL, - tmpl, FALSE, NULL, NULL); - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); - g_ptr_array_add (nmc->output_data, arr); - - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX); - set_val_str (arr, 0, g_strdup (nm_setting_get_name (setting))); - set_val_str (arr, 1, nmc_property_wireless_get_ssid (setting, type)); - set_val_str (arr, 2, nmc_property_wireless_get_mode (setting, type)); - set_val_str (arr, 3, nmc_property_wireless_get_band (setting, type)); - set_val_str (arr, 4, nmc_property_wireless_get_channel (setting, type)); - set_val_str (arr, 5, nmc_property_wireless_get_bssid (setting, type)); - set_val_str (arr, 6, nmc_property_wireless_get_rate (setting, type)); - set_val_str (arr, 7, nmc_property_wireless_get_tx_power (setting, type)); - set_val_str (arr, 8, nmc_property_wireless_get_mac_address (setting, type)); - set_val_str (arr, 9, nmc_property_wireless_get_cloned_mac_address (setting, type)); - set_val_str (arr, 10, nmc_property_wireless_get_generate_mac_address_mask (setting, type)); - set_val_str (arr, 11, nmc_property_wireless_get_mac_address_blacklist (setting, type)); - set_val_str (arr, 12, nmc_property_wireless_get_mac_address_randomization (setting, type)); - set_val_str (arr, 13, nmc_property_wireless_get_mtu (setting, type)); - set_val_str (arr, 14, nmc_property_wireless_get_seen_bssids (setting, type)); - set_val_str (arr, 15, nmc_property_wireless_get_hidden (setting, type)); - set_val_str (arr, 16, nmc_property_wireless_get_powersave (setting, type)); - g_ptr_array_add (nmc->output_data, arr); - - print_data (nmc); /* Print all data */ - - return TRUE; -} - -static gboolean -setting_wireless_security_details (NMSetting *setting, - NmCli *nmc, - const char *one_prop, - gboolean secrets, - NmcPropertyGetType type) -{ - NMSettingWirelessSecurity *s_wireless_sec = NM_SETTING_WIRELESS_SECURITY (setting); - NmcOutputField *tmpl, *arr; - size_t tmpl_len; - - g_return_val_if_fail (NM_IS_SETTING_WIRELESS_SECURITY (s_wireless_sec), FALSE); - - tmpl = nmc_fields_setting_wireless_security; - tmpl_len = sizeof (nmc_fields_setting_wireless_security); - nmc->print_fields.indices = parse_output_fields (one_prop ? one_prop : NMC_FIELDS_SETTING_WIRELESS_SECURITY_ALL, - tmpl, FALSE, NULL, NULL); - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); - g_ptr_array_add (nmc->output_data, arr); - - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX); - set_val_str (arr, 0, g_strdup (nm_setting_get_name (setting))); - set_val_str (arr, 1, nmc_property_wifi_sec_get_key_mgmt (setting, type)); - set_val_str (arr, 2, nmc_property_wifi_sec_get_wep_tx_keyidx (setting, type)); - set_val_str (arr, 3, nmc_property_wifi_sec_get_auth_alg (setting, type)); - set_val_str (arr, 4, nmc_property_wifi_sec_get_proto (setting, type)); - set_val_str (arr, 5, nmc_property_wifi_sec_get_pairwise (setting, type)); - set_val_str (arr, 6, nmc_property_wifi_sec_get_group (setting, type)); - set_val_str (arr, 7, nmc_property_wifi_sec_get_leap_username (setting, type)); - set_val_str (arr, 8, GET_SECRET (secrets, setting, nmc_property_wifi_sec_get_wep_key0, type)); - set_val_str (arr, 9, GET_SECRET (secrets, setting, nmc_property_wifi_sec_get_wep_key1, type)); - set_val_str (arr, 10, GET_SECRET (secrets, setting, nmc_property_wifi_sec_get_wep_key2, type)); - set_val_str (arr, 11, GET_SECRET (secrets, setting, nmc_property_wifi_sec_get_wep_key3, type)); - set_val_str (arr, 12, nmc_property_wifi_sec_get_wep_key_flags (setting, type)); - set_val_str (arr, 13, nmc_property_wifi_sec_get_wep_key_type (setting, type)); - set_val_str (arr, 14, GET_SECRET (secrets, setting, nmc_property_wifi_sec_get_psk, type)); - set_val_str (arr, 15, nmc_property_wifi_sec_get_psk_flags (setting, type)); - set_val_str (arr, 16, GET_SECRET (secrets, setting, nmc_property_wifi_sec_get_leap_password, type)); - set_val_str (arr, 17, nmc_property_wifi_sec_get_leap_password_flags (setting, type)); - g_ptr_array_add (nmc->output_data, arr); - - print_data (nmc); /* Print all data */ - - return TRUE; -} - -static gboolean -setting_ip4_config_details (NMSetting *setting, - NmCli *nmc, - const char *one_prop, - gboolean secrets, - NmcPropertyGetType type) -{ - NMSettingIPConfig *s_ip4 = NM_SETTING_IP_CONFIG (setting); - NmcOutputField *tmpl, *arr; - size_t tmpl_len; - - g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (s_ip4), FALSE); - - tmpl = nmc_fields_setting_ip4_config; - tmpl_len = sizeof (nmc_fields_setting_ip4_config); - nmc->print_fields.indices = parse_output_fields (one_prop ? one_prop : NMC_FIELDS_SETTING_IP4_CONFIG_ALL, - tmpl, FALSE, NULL, NULL); - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); - g_ptr_array_add (nmc->output_data, arr); - - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX); - set_val_str (arr, 0, g_strdup (nm_setting_get_name (setting))); - set_val_str (arr, 1, nmc_property_ipv4_get_method (setting, type)); - set_val_str (arr, 2, nmc_property_ipv4_get_dns (setting, type)); - set_val_str (arr, 3, nmc_property_ipv4_get_dns_search (setting, type)); - set_val_str (arr, 4, nmc_property_ipv4_get_dns_options (setting, type)); - set_val_str (arr, 5, nmc_property_ipv4_get_dns_priority (setting, type)); - set_val_str (arr, 6, nmc_property_ip_get_addresses (setting, type)); - set_val_str (arr, 7, nmc_property_ipv4_get_gateway (setting, type)); - set_val_str (arr, 8, nmc_property_ipv4_get_routes (setting, type)); - set_val_str (arr, 9, nmc_property_ipv4_get_route_metric (setting, type)); - set_val_str (arr, 10, nmc_property_ipv4_get_ignore_auto_routes (setting, type)); - set_val_str (arr, 11, nmc_property_ipv4_get_ignore_auto_dns (setting, type)); - set_val_str (arr, 12, nmc_property_ipv4_get_dhcp_client_id (setting, type)); - set_val_str (arr, 13, nmc_property_ipv4_get_dhcp_timeout (setting, type)); - set_val_str (arr, 14, nmc_property_ipv4_get_dhcp_send_hostname (setting, type)); - set_val_str (arr, 15, nmc_property_ipv4_get_dhcp_hostname (setting, type)); - set_val_str (arr, 16, nmc_property_ipv4_get_dhcp_fqdn (setting, type)); - set_val_str (arr, 17, nmc_property_ipv4_get_never_default (setting, type)); - set_val_str (arr, 18, nmc_property_ipv4_get_may_fail (setting, type)); - set_val_str (arr, 19, nmc_property_ipv4_get_dad_timeout (setting, type)); - g_ptr_array_add (nmc->output_data, arr); - - print_data (nmc); /* Print all data */ - - return TRUE; -} - -static gboolean -setting_ip6_config_details (NMSetting *setting, - NmCli *nmc, - const char *one_prop, - gboolean secrets, - NmcPropertyGetType type) -{ - NMSettingIPConfig *s_ip6 = NM_SETTING_IP_CONFIG (setting); - NmcOutputField *tmpl, *arr; - size_t tmpl_len; - - g_return_val_if_fail (NM_IS_SETTING_IP6_CONFIG (s_ip6), FALSE); - - tmpl = nmc_fields_setting_ip6_config; - tmpl_len = sizeof (nmc_fields_setting_ip6_config); - nmc->print_fields.indices = parse_output_fields (one_prop ? one_prop : NMC_FIELDS_SETTING_IP6_CONFIG_ALL, - tmpl, FALSE, NULL, NULL); - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); - g_ptr_array_add (nmc->output_data, arr); - - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX); - set_val_str (arr, 0, g_strdup (nm_setting_get_name (setting))); - set_val_str (arr, 1, nmc_property_ipv6_get_method (setting, type)); - set_val_str (arr, 2, nmc_property_ipv6_get_dns (setting, type)); - set_val_str (arr, 3, nmc_property_ipv6_get_dns_search (setting, type)); - set_val_str (arr, 4, nmc_property_ipv6_get_dns_options (setting, type)); - set_val_str (arr, 5, nmc_property_ipv6_get_dns_priority (setting, type)); - set_val_str (arr, 6, nmc_property_ip_get_addresses (setting, type)); - set_val_str (arr, 7, nmc_property_ipv6_get_gateway (setting, type)); - set_val_str (arr, 8, nmc_property_ipv6_get_routes (setting, type)); - set_val_str (arr, 9, nmc_property_ipv6_get_route_metric (setting, type)); - set_val_str (arr, 10, nmc_property_ipv6_get_ignore_auto_routes (setting, type)); - set_val_str (arr, 11, nmc_property_ipv6_get_ignore_auto_dns (setting, type)); - set_val_str (arr, 12, nmc_property_ipv6_get_never_default (setting, type)); - set_val_str (arr, 13, nmc_property_ipv6_get_may_fail (setting, type)); - set_val_str (arr, 14, nmc_property_ipv6_get_ip6_privacy (setting, type)); - set_val_str (arr, 15, nmc_property_ipv6_get_addr_gen_mode (setting, type)); - set_val_str (arr, 16, nmc_property_ipv6_get_dhcp_send_hostname (setting, type)); - set_val_str (arr, 17, nmc_property_ipv6_get_dhcp_hostname (setting, type)); - set_val_str (arr, 18, nmc_property_ipv6_get_token (setting, type)); - g_ptr_array_add (nmc->output_data, arr); - - print_data (nmc); /* Print all data */ - - return TRUE; -} - -static gboolean -setting_serial_details (NMSetting *setting, - NmCli *nmc, - const char *one_prop, - gboolean secrets, - NmcPropertyGetType type) -{ - NMSettingSerial *s_serial = NM_SETTING_SERIAL (setting); - NmcOutputField *tmpl, *arr; - size_t tmpl_len; - - g_return_val_if_fail (NM_IS_SETTING_SERIAL (s_serial), FALSE); - - tmpl = nmc_fields_setting_serial; - tmpl_len = sizeof (nmc_fields_setting_serial); - nmc->print_fields.indices = parse_output_fields (one_prop ? one_prop : NMC_FIELDS_SETTING_SERIAL_ALL, - tmpl, FALSE, NULL, NULL); - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); - g_ptr_array_add (nmc->output_data, arr); - - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX); - set_val_str (arr, 0, g_strdup (nm_setting_get_name (setting))); - set_val_str (arr, 1, nmc_property_serial_get_baud (setting, type)); - set_val_str (arr, 2, nmc_property_serial_get_bits (setting, type)); - set_val_str (arr, 3, nmc_property_serial_get_parity (setting, type)); - set_val_str (arr, 4, nmc_property_serial_get_stopbits (setting, type)); - set_val_str (arr, 5, nmc_property_serial_get_send_delay (setting, type)); - g_ptr_array_add (nmc->output_data, arr); - - print_data (nmc); /* Print all data */ - - return TRUE; -} - -static gboolean -setting_ppp_details (NMSetting *setting, NmCli *nmc, - const char *one_prop, - gboolean secrets, - NmcPropertyGetType type) -{ - NMSettingPpp *s_ppp = NM_SETTING_PPP (setting); - NmcOutputField *tmpl, *arr; - size_t tmpl_len; - - g_return_val_if_fail (NM_IS_SETTING_PPP (s_ppp), FALSE); - - tmpl = nmc_fields_setting_ppp; - tmpl_len = sizeof (nmc_fields_setting_ppp); - nmc->print_fields.indices = parse_output_fields (one_prop ? one_prop : NMC_FIELDS_SETTING_PPP_ALL, - tmpl, FALSE, NULL, NULL); - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); - g_ptr_array_add (nmc->output_data, arr); - - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX); - set_val_str (arr, 0, g_strdup (nm_setting_get_name (setting))); - set_val_str (arr, 1, nmc_property_ppp_get_noauth (setting, type)); - set_val_str (arr, 2, nmc_property_ppp_get_refuse_eap (setting, type)); - set_val_str (arr, 3, nmc_property_ppp_get_refuse_pap (setting, type)); - set_val_str (arr, 4, nmc_property_ppp_get_refuse_chap (setting, type)); - set_val_str (arr, 5, nmc_property_ppp_get_refuse_mschap (setting, type)); - set_val_str (arr, 6, nmc_property_ppp_get_refuse_mschapv2 (setting, type)); - set_val_str (arr, 7, nmc_property_ppp_get_nobsdcomp (setting, type)); - set_val_str (arr, 8, nmc_property_ppp_get_nodeflate (setting, type)); - set_val_str (arr, 9, nmc_property_ppp_get_no_vj_comp (setting, type)); - set_val_str (arr, 10, nmc_property_ppp_get_require_mppe (setting, type)); - set_val_str (arr, 11, nmc_property_ppp_get_require_mppe_128 (setting, type)); - set_val_str (arr, 12, nmc_property_ppp_get_mppe_stateful (setting, type)); - set_val_str (arr, 13, nmc_property_ppp_get_crtscts (setting, type)); - set_val_str (arr, 14, nmc_property_ppp_get_baud (setting, type)); - set_val_str (arr, 15, nmc_property_ppp_get_mru (setting, type)); - set_val_str (arr, 16, nmc_property_ppp_get_mtu (setting, type)); - set_val_str (arr, 17, nmc_property_ppp_get_lcp_echo_failure (setting, type)); - set_val_str (arr, 18, nmc_property_ppp_get_lcp_echo_interval (setting, type)); - g_ptr_array_add (nmc->output_data, arr); - - print_data (nmc); /* Print all data */ - - return TRUE; -} - -static gboolean -setting_pppoe_details (NMSetting *setting, - NmCli *nmc, - const char *one_prop, - gboolean secrets, - NmcPropertyGetType type) -{ - NMSettingPppoe *s_pppoe = NM_SETTING_PPPOE (setting); - NmcOutputField *tmpl, *arr; - size_t tmpl_len; - - g_return_val_if_fail (NM_IS_SETTING_PPPOE (s_pppoe), FALSE); - - tmpl = nmc_fields_setting_pppoe; - tmpl_len = sizeof (nmc_fields_setting_pppoe); - nmc->print_fields.indices = parse_output_fields (one_prop ? one_prop : NMC_FIELDS_SETTING_PPPOE_ALL, - tmpl, FALSE, NULL, NULL); - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); - g_ptr_array_add (nmc->output_data, arr); - - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX); - set_val_str (arr, 0, g_strdup (nm_setting_get_name (setting))); - set_val_str (arr, 1, nmc_property_pppoe_get_service (setting, type)); - set_val_str (arr, 2, nmc_property_pppoe_get_username (setting, type)); - set_val_str (arr, 3, GET_SECRET (secrets, setting, nmc_property_pppoe_get_password, type)); - set_val_str (arr, 4, nmc_property_pppoe_get_password_flags (setting, type)); - g_ptr_array_add (nmc->output_data, arr); - - print_data (nmc); /* Print all data */ - - return TRUE; -} - -static gboolean -setting_gsm_details (NMSetting *setting, - NmCli *nmc, - const char *one_prop, - gboolean secrets, - NmcPropertyGetType type) -{ - NMSettingGsm *s_gsm = NM_SETTING_GSM (setting); - NmcOutputField *tmpl, *arr; - size_t tmpl_len; - - g_return_val_if_fail (NM_IS_SETTING_GSM (s_gsm), FALSE); - - tmpl = nmc_fields_setting_gsm; - tmpl_len = sizeof (nmc_fields_setting_gsm); - nmc->print_fields.indices = parse_output_fields (one_prop ? one_prop : NMC_FIELDS_SETTING_GSM_ALL, - tmpl, FALSE, NULL, NULL); - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); - g_ptr_array_add (nmc->output_data, arr); - - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX); - set_val_str (arr, 0, g_strdup (nm_setting_get_name (setting))); - set_val_str (arr, 1, nmc_property_gsm_get_number (setting, type)); - set_val_str (arr, 2, nmc_property_gsm_get_username (setting, type)); - set_val_str (arr, 3, GET_SECRET (secrets, setting, nmc_property_gsm_get_password, type)); - set_val_str (arr, 4, nmc_property_gsm_get_password_flags (setting, type)); - set_val_str (arr, 5, nmc_property_gsm_get_apn (setting, type)); - set_val_str (arr, 6, nmc_property_gsm_get_network_id (setting, type)); - set_val_str (arr, 7, GET_SECRET (secrets, setting, nmc_property_gsm_get_pin, type)); - set_val_str (arr, 8, nmc_property_gsm_get_pin_flags (setting, type)); - set_val_str (arr, 9, nmc_property_gsm_get_home_only (setting, type)); - set_val_str (arr, 10, nmc_property_gsm_get_device_id (setting, type)); - set_val_str (arr, 11, nmc_property_gsm_get_sim_id (setting, type)); - set_val_str (arr, 12, nmc_property_gsm_get_sim_operator_id (setting, type)); - set_val_str (arr, 13, nmc_property_gsm_get_mtu (setting, type)); - g_ptr_array_add (nmc->output_data, arr); - - print_data (nmc); /* Print all data */ - - return TRUE; -} - -static gboolean -setting_cdma_details (NMSetting *setting, - NmCli *nmc, - const char *one_prop, - gboolean secrets, - NmcPropertyGetType type) -{ - NMSettingCdma *s_cdma = NM_SETTING_CDMA (setting); - NmcOutputField *tmpl, *arr; - size_t tmpl_len; - - g_return_val_if_fail (NM_IS_SETTING_CDMA (s_cdma), FALSE); - - tmpl = nmc_fields_setting_cdma; - tmpl_len = sizeof (nmc_fields_setting_cdma); - nmc->print_fields.indices = parse_output_fields (one_prop ? one_prop : NMC_FIELDS_SETTING_CDMA_ALL, - tmpl, FALSE, NULL, NULL); - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); - g_ptr_array_add (nmc->output_data, arr); - - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX); - set_val_str (arr, 0, g_strdup (nm_setting_get_name (setting))); - set_val_str (arr, 1, nmc_property_cdma_get_number (setting, type)); - set_val_str (arr, 2, nmc_property_cdma_get_username (setting, type)); - set_val_str (arr, 3, GET_SECRET (secrets, setting, nmc_property_cdma_get_password, type)); - set_val_str (arr, 4, nmc_property_cdma_get_password_flags (setting, type)); - set_val_str (arr, 5, nmc_property_cdma_get_mtu (setting, type)); - g_ptr_array_add (nmc->output_data, arr); - - print_data (nmc); /* Print all data */ - - return TRUE; -} - -static gboolean -setting_bluetooth_details (NMSetting *setting, - NmCli *nmc, - const char *one_prop, - gboolean secrets, - NmcPropertyGetType type) -{ - NMSettingBluetooth *s_bluetooth = NM_SETTING_BLUETOOTH (setting); - NmcOutputField *tmpl, *arr; - size_t tmpl_len; - - g_return_val_if_fail (NM_IS_SETTING_BLUETOOTH (s_bluetooth), FALSE); - - tmpl = nmc_fields_setting_bluetooth; - tmpl_len = sizeof (nmc_fields_setting_bluetooth); - nmc->print_fields.indices = parse_output_fields (one_prop ? one_prop : NMC_FIELDS_SETTING_BLUETOOTH_ALL, - tmpl, FALSE, NULL, NULL); - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); - g_ptr_array_add (nmc->output_data, arr); - - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX); - set_val_str (arr, 0, g_strdup (nm_setting_get_name (setting))); - set_val_str (arr, 1, nmc_property_bluetooth_get_bdaddr (setting, type)); - set_val_str (arr, 2, nmc_property_bluetooth_get_type (setting, type)); - g_ptr_array_add (nmc->output_data, arr); - - print_data (nmc); /* Print all data */ - - return TRUE; -} - -static gboolean -setting_olpc_mesh_details (NMSetting *setting, - NmCli *nmc, - const char *one_prop, - gboolean secrets, - NmcPropertyGetType type) -{ - NMSettingOlpcMesh *s_olpc_mesh = NM_SETTING_OLPC_MESH (setting); - NmcOutputField *tmpl, *arr; - size_t tmpl_len; - - g_return_val_if_fail (NM_IS_SETTING_OLPC_MESH (s_olpc_mesh), FALSE); - - tmpl = nmc_fields_setting_olpc_mesh; - tmpl_len = sizeof (nmc_fields_setting_olpc_mesh); - nmc->print_fields.indices = parse_output_fields (one_prop ? one_prop : NMC_FIELDS_SETTING_OLPC_MESH_ALL, - tmpl, FALSE, NULL, NULL); - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); - g_ptr_array_add (nmc->output_data, arr); - - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX); - set_val_str (arr, 0, g_strdup (nm_setting_get_name (setting))); - set_val_str (arr, 1, nmc_property_olpc_get_ssid (setting, type)); - set_val_str (arr, 2, nmc_property_olpc_get_channel (setting, type)); - set_val_str (arr, 3, nmc_property_olpc_get_anycast_address (setting, type)); - g_ptr_array_add (nmc->output_data, arr); - - print_data (nmc); /* Print all data */ - - return TRUE; -} - -static gboolean -setting_vpn_details (NMSetting *setting, - NmCli *nmc, - const char *one_prop, - gboolean secrets, - NmcPropertyGetType type) -{ - NMSettingVpn *s_vpn = NM_SETTING_VPN (setting); - NmcOutputField *tmpl, *arr; - size_t tmpl_len; - - g_return_val_if_fail (NM_IS_SETTING_VPN (s_vpn), FALSE); - - tmpl = nmc_fields_setting_vpn; - tmpl_len = sizeof (nmc_fields_setting_vpn); - nmc->print_fields.indices = parse_output_fields (one_prop ? one_prop : NMC_FIELDS_SETTING_VPN_ALL, - tmpl, FALSE, NULL, NULL); - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); - g_ptr_array_add (nmc->output_data, arr); - - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX); - set_val_str (arr, 0, g_strdup (nm_setting_get_name (setting))); - set_val_str (arr, 1, nmc_property_vpn_get_service_type (setting, type)); - set_val_str (arr, 2, nmc_property_vpn_get_user_name (setting, type)); - set_val_str (arr, 3, nmc_property_vpn_get_data (setting, type)); - set_val_str (arr, 4, GET_SECRET (secrets, setting, nmc_property_vpn_get_secrets, type)); - set_val_str (arr, 5, nmc_property_vpn_get_persistent (setting, type)); - set_val_str (arr, 6, nmc_property_vpn_get_timeout (setting, type)); - g_ptr_array_add (nmc->output_data, arr); - - print_data (nmc); /* Print all data */ - - return TRUE; -} - -static gboolean -setting_wimax_details (NMSetting *setting, - NmCli *nmc, - const char *one_prop, - gboolean secrets, - NmcPropertyGetType type) -{ - NMSettingWimax *s_wimax = NM_SETTING_WIMAX (setting); - NmcOutputField *tmpl, *arr; - size_t tmpl_len; - - g_return_val_if_fail (NM_IS_SETTING_WIMAX (s_wimax), FALSE); - - tmpl = nmc_fields_setting_wimax; - tmpl_len = sizeof (nmc_fields_setting_wimax); - nmc->print_fields.indices = parse_output_fields (one_prop ? one_prop : NMC_FIELDS_SETTING_WIMAX_ALL, - tmpl, FALSE, NULL, NULL); - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); - g_ptr_array_add (nmc->output_data, arr); - - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX); - set_val_str (arr, 0, g_strdup (nm_setting_get_name (setting))); - set_val_str (arr, 1, nmc_property_wimax_get_mac_address (setting, type)); - set_val_str (arr, 2, nmc_property_wimax_get_network_name (setting, type)); - g_ptr_array_add (nmc->output_data, arr); - - print_data (nmc); /* Print all data */ - - return TRUE; -} - -static gboolean -setting_infiniband_details (NMSetting *setting, - NmCli *nmc, - const char *one_prop, - gboolean secrets, - NmcPropertyGetType type) -{ - NMSettingInfiniband *s_infiniband = NM_SETTING_INFINIBAND (setting); - NmcOutputField *tmpl, *arr; - size_t tmpl_len; - - g_return_val_if_fail (NM_IS_SETTING_INFINIBAND (s_infiniband), FALSE); - - tmpl = nmc_fields_setting_infiniband; - tmpl_len = sizeof (nmc_fields_setting_infiniband); - nmc->print_fields.indices = parse_output_fields (one_prop ? one_prop : NMC_FIELDS_SETTING_INFINIBAND_ALL, - tmpl, FALSE, NULL, NULL); - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); - g_ptr_array_add (nmc->output_data, arr); - - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX); - set_val_str (arr, 0, g_strdup (nm_setting_get_name (setting))); - set_val_str (arr, 1, nmc_property_ib_get_mac_address (setting, type)); - set_val_str (arr, 2, nmc_property_ib_get_mtu (setting, type)); - set_val_str (arr, 3, nmc_property_ib_get_transport_mode (setting, type)); - set_val_str (arr, 4, nmc_property_ib_get_p_key (setting, type)); - set_val_str (arr, 5, nmc_property_ib_get_parent (setting, type)); - g_ptr_array_add (nmc->output_data, arr); - - print_data (nmc); /* Print all data */ - - return TRUE; -} - -static gboolean -setting_bond_details (NMSetting *setting, - NmCli *nmc, - const char *one_prop, - gboolean secrets, - NmcPropertyGetType type) -{ - NMSettingBond *s_bond = NM_SETTING_BOND (setting); - NmcOutputField *tmpl, *arr; - size_t tmpl_len; - - g_return_val_if_fail (NM_IS_SETTING_BOND (s_bond), FALSE); - - tmpl = nmc_fields_setting_bond; - tmpl_len = sizeof (nmc_fields_setting_bond); - nmc->print_fields.indices = parse_output_fields (one_prop ? one_prop : NMC_FIELDS_SETTING_BOND_ALL, - tmpl, FALSE, NULL, NULL); - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); - g_ptr_array_add (nmc->output_data, arr); - - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX); - set_val_str (arr, 0, g_strdup (nm_setting_get_name (setting))); - set_val_str (arr, 1, nmc_property_bond_get_options (setting, type)); - g_ptr_array_add (nmc->output_data, arr); - - print_data (nmc); /* Print all data */ - - return TRUE; -} - -static gboolean -setting_vlan_details (NMSetting *setting, - NmCli *nmc, - const char *one_prop, - gboolean secrets, - NmcPropertyGetType type) -{ - NMSettingVlan *s_vlan = NM_SETTING_VLAN (setting); - NmcOutputField *tmpl, *arr; - size_t tmpl_len; - - g_return_val_if_fail (NM_IS_SETTING_VLAN (s_vlan), FALSE); - - tmpl = nmc_fields_setting_vlan; - tmpl_len = sizeof (nmc_fields_setting_vlan); - nmc->print_fields.indices = parse_output_fields (one_prop ? one_prop : NMC_FIELDS_SETTING_VLAN_ALL, - tmpl, FALSE, NULL, NULL); - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); - g_ptr_array_add (nmc->output_data, arr); - - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX); - set_val_str (arr, 0, g_strdup (nm_setting_get_name (setting))); - set_val_str (arr, 1, nmc_property_vlan_get_parent (setting, type)); - set_val_str (arr, 2, nmc_property_vlan_get_id (setting, type)); - set_val_str (arr, 3, nmc_property_vlan_get_flags (setting, type)); - set_val_str (arr, 4, nmc_property_vlan_get_ingress_priority_map (setting, type)); - set_val_str (arr, 5, nmc_property_vlan_get_egress_priority_map (setting, type)); - g_ptr_array_add (nmc->output_data, arr); - - print_data (nmc); /* Print all data */ - - return TRUE; -} - -static gboolean -setting_adsl_details (NMSetting *setting, - NmCli *nmc, - const char *one_prop, - gboolean secrets, - NmcPropertyGetType type) -{ - NMSettingAdsl *s_adsl = NM_SETTING_ADSL (setting); - NmcOutputField *tmpl, *arr; - size_t tmpl_len; - - g_return_val_if_fail (NM_IS_SETTING_ADSL (s_adsl), FALSE); - - tmpl = nmc_fields_setting_adsl; - tmpl_len = sizeof (nmc_fields_setting_adsl); - nmc->print_fields.indices = parse_output_fields (one_prop ? one_prop : NMC_FIELDS_SETTING_ADSL_ALL, - tmpl, FALSE, NULL, NULL); - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); - g_ptr_array_add (nmc->output_data, arr); - - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX); - set_val_str (arr, 0, g_strdup (nm_setting_get_name (setting))); - set_val_str (arr, 1, nmc_property_adsl_get_username (setting, type)); - set_val_str (arr, 2, GET_SECRET (secrets, setting, nmc_property_adsl_get_password, type)); - set_val_str (arr, 3, nmc_property_adsl_get_password_flags (setting, type)); - set_val_str (arr, 4, nmc_property_adsl_get_protocol (setting, type)); - set_val_str (arr, 5, nmc_property_adsl_get_encapsulation (setting, type)); - set_val_str (arr, 6, nmc_property_adsl_get_vpi (setting, type)); - set_val_str (arr, 7, nmc_property_adsl_get_vci (setting, type)); - g_ptr_array_add (nmc->output_data, arr); - - print_data (nmc); /* Print all data */ - - return TRUE; -} - -static gboolean -setting_bridge_details (NMSetting *setting, - NmCli *nmc, - const char *one_prop, - gboolean secrets, - NmcPropertyGetType type) -{ - NMSettingBridge *s_bridge = NM_SETTING_BRIDGE (setting); - NmcOutputField *tmpl, *arr; - size_t tmpl_len; +/*****************************************************************************/ - g_return_val_if_fail (NM_IS_SETTING_BRIDGE (s_bridge), FALSE); - - tmpl = nmc_fields_setting_bridge; - tmpl_len = sizeof (nmc_fields_setting_bridge); - nmc->print_fields.indices = parse_output_fields (one_prop ? one_prop : NMC_FIELDS_SETTING_BRIDGE_ALL, - tmpl, FALSE, NULL, NULL); - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); - g_ptr_array_add (nmc->output_data, arr); - - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX); - set_val_str (arr, 0, g_strdup (nm_setting_get_name (setting))); - set_val_str (arr, 1, nmc_property_bridge_get_mac_address (setting, type)); - set_val_str (arr, 2, nmc_property_bridge_get_stp (setting, type)); - set_val_str (arr, 3, nmc_property_bridge_get_priority (setting, type)); - set_val_str (arr, 4, nmc_property_bridge_get_forward_delay (setting, type)); - set_val_str (arr, 5, nmc_property_bridge_get_hello_time (setting, type)); - set_val_str (arr, 6, nmc_property_bridge_get_max_age (setting, type)); - set_val_str (arr, 7, nmc_property_bridge_get_ageing_time (setting, type)); - set_val_str (arr, 8, nmc_property_bridge_get_multicast_snooping (setting, type)); - g_ptr_array_add (nmc->output_data, arr); - - print_data (nmc); /* Print all data */ - - return TRUE; -} - -static gboolean -setting_bridge_port_details (NMSetting *setting, - NmCli *nmc, - const char *one_prop, - gboolean secrets, - NmcPropertyGetType type) -{ - NMSettingBridgePort *s_bridge_port = NM_SETTING_BRIDGE_PORT (setting); - NmcOutputField *tmpl, *arr; - size_t tmpl_len; - - g_return_val_if_fail (NM_IS_SETTING_BRIDGE_PORT (s_bridge_port), FALSE); - - tmpl = nmc_fields_setting_bridge_port; - tmpl_len = sizeof (nmc_fields_setting_bridge_port); - nmc->print_fields.indices = parse_output_fields (one_prop ? one_prop : NMC_FIELDS_SETTING_BRIDGE_PORT_ALL, - tmpl, FALSE, NULL, NULL); - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); - g_ptr_array_add (nmc->output_data, arr); - - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX); - set_val_str (arr, 0, g_strdup (nm_setting_get_name (setting))); - set_val_str (arr, 1, nmc_property_bridge_port_get_priority (setting, type)); - set_val_str (arr, 2, nmc_property_bridge_port_get_path_cost (setting, type)); - set_val_str (arr, 3, nmc_property_bridge_port_get_hairpin_mode (setting, type)); - g_ptr_array_add (nmc->output_data, arr); - - print_data (nmc); /* Print all data */ - - return TRUE; -} - -static gboolean -setting_team_details (NMSetting *setting, - NmCli *nmc, - const char *one_prop, - gboolean secrets, - NmcPropertyGetType type) -{ - NMSettingTeam *s_team = NM_SETTING_TEAM (setting); - NmcOutputField *tmpl, *arr; - size_t tmpl_len; - - g_return_val_if_fail (NM_IS_SETTING_TEAM (s_team), FALSE); - - tmpl = nmc_fields_setting_team; - tmpl_len = sizeof (nmc_fields_setting_team); - nmc->print_fields.indices = parse_output_fields (one_prop ? one_prop : NMC_FIELDS_SETTING_TEAM_ALL, - tmpl, FALSE, NULL, NULL); - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); - g_ptr_array_add (nmc->output_data, arr); - - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX); - set_val_str (arr, 0, g_strdup (nm_setting_get_name (setting))); - set_val_str (arr, 1, nmc_property_team_get_config (setting, type)); - g_ptr_array_add (nmc->output_data, arr); - - print_data (nmc); /* Print all data */ - - return TRUE; -} - -static gboolean -setting_team_port_details (NMSetting *setting, - NmCli *nmc, - const char *one_prop, - gboolean secrets, - NmcPropertyGetType type) -{ - NMSettingTeamPort *s_team_port = NM_SETTING_TEAM_PORT (setting); - NmcOutputField *tmpl, *arr; - size_t tmpl_len; - - g_return_val_if_fail (NM_IS_SETTING_TEAM_PORT (s_team_port), FALSE); - - tmpl = nmc_fields_setting_team_port; - tmpl_len = sizeof (nmc_fields_setting_team_port); - nmc->print_fields.indices = parse_output_fields (one_prop ? one_prop : NMC_FIELDS_SETTING_TEAM_PORT_ALL, - tmpl, FALSE, NULL, NULL); - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); - g_ptr_array_add (nmc->output_data, arr); - - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX); - set_val_str (arr, 0, g_strdup (nm_setting_get_name (setting))); - set_val_str (arr, 1, nmc_property_team_port_get_config (setting, type)); - g_ptr_array_add (nmc->output_data, arr); - - print_data (nmc); /* Print all data */ - - return TRUE; -} - -static gboolean -setting_dcb_details (NMSetting *setting, - NmCli *nmc, - const char *one_prop, - gboolean secrets, - NmcPropertyGetType type) -{ - NMSettingDcb *s_dcb = NM_SETTING_DCB (setting); - NmcOutputField *tmpl, *arr; - size_t tmpl_len; - - g_return_val_if_fail (NM_IS_SETTING_DCB (s_dcb), FALSE); - - tmpl = nmc_fields_setting_dcb; - tmpl_len = sizeof (nmc_fields_setting_dcb); - nmc->print_fields.indices = parse_output_fields (one_prop ? one_prop : NMC_FIELDS_SETTING_DCB_ALL, - tmpl, FALSE, NULL, NULL); - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); - g_ptr_array_add (nmc->output_data, arr); - - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX); - set_val_str (arr, 0, g_strdup (nm_setting_get_name (setting))); - set_val_str (arr, 1, nmc_property_dcb_get_app_fcoe_flags (setting, type)); - set_val_str (arr, 2, nmc_property_dcb_get_app_fcoe_priority (setting, type)); - set_val_str (arr, 3, nmc_property_dcb_get_app_fcoe_mode (setting, type)); - set_val_str (arr, 4, nmc_property_dcb_get_app_iscsi_flags (setting, type)); - set_val_str (arr, 5, nmc_property_dcb_get_app_iscsi_priority (setting, type)); - set_val_str (arr, 6, nmc_property_dcb_get_app_fip_flags (setting, type)); - set_val_str (arr, 7, nmc_property_dcb_get_app_fip_priority (setting, type)); - set_val_str (arr, 8, nmc_property_dcb_get_pfc_flags (setting, type)); - set_val_str (arr, 9, nmc_property_dcb_get_pfc (setting, type)); - set_val_str (arr, 10, nmc_property_dcb_get_pg_flags (setting, type)); - set_val_str (arr, 11, nmc_property_dcb_get_pg_group_id (setting, type)); - set_val_str (arr, 12, nmc_property_dcb_get_pg_group_bandwidth (setting, type)); - set_val_str (arr, 13, nmc_property_dcb_get_pg_bandwidth (setting, type)); - set_val_str (arr, 14, nmc_property_dcb_get_pg_strict (setting, type)); - set_val_str (arr, 15, nmc_property_dcb_get_pg_traffic_class (setting, type)); - g_ptr_array_add (nmc->output_data, arr); - - print_data (nmc); /* Print all data */ - - return TRUE; -} - -static gboolean -setting_tun_details (NMSetting *setting, - NmCli *nmc, - const char *one_prop, - gboolean secrets, - NmcPropertyGetType type) -{ - NMSettingTun *s_tun = NM_SETTING_TUN (setting); - NmcOutputField *tmpl, *arr; - size_t tmpl_len; - - g_return_val_if_fail (NM_IS_SETTING_TUN (s_tun), FALSE); - - tmpl = nmc_fields_setting_tun; - tmpl_len = sizeof (nmc_fields_setting_tun); - nmc->print_fields.indices = parse_output_fields (one_prop ? one_prop : NMC_FIELDS_SETTING_TUN_ALL, - tmpl, FALSE, NULL, NULL); - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); - g_ptr_array_add (nmc->output_data, arr); - - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX); - set_val_str (arr, 0, g_strdup (nm_setting_get_name (setting))); - set_val_str (arr, 1, nmc_property_tun_get_mode (setting, type)); - set_val_str (arr, 2, nmc_property_tun_get_owner (setting, type)); - set_val_str (arr, 3, nmc_property_tun_get_group (setting, type)); - set_val_str (arr, 4, nmc_property_tun_get_pi (setting, type)); - set_val_str (arr, 5, nmc_property_tun_get_vnet_hdr (setting, type)); - set_val_str (arr, 6, nmc_property_tun_get_multi_queue (setting, type)); - g_ptr_array_add (nmc->output_data, arr); - - print_data (nmc); /* Print all data */ - - return TRUE; -} - -static gboolean -setting_ip_tunnel_details (NMSetting *setting, - NmCli *nmc, - const char *one_prop, - gboolean secrets, - NmcPropertyGetType type) -{ - NMSettingIPTunnel *s_ip_tunnel = NM_SETTING_IP_TUNNEL (setting); - NmcOutputField *tmpl, *arr; - size_t tmpl_len; - - g_return_val_if_fail (NM_IS_SETTING_IP_TUNNEL (s_ip_tunnel), FALSE); - - tmpl = nmc_fields_setting_ip_tunnel; - tmpl_len = sizeof (nmc_fields_setting_ip_tunnel); - nmc->print_fields.indices = parse_output_fields (one_prop ? one_prop : NMC_FIELDS_SETTING_IP_TUNNEL_ALL, - tmpl, FALSE, NULL, NULL); - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); - g_ptr_array_add (nmc->output_data, arr); - - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX); - set_val_str (arr, 0, g_strdup (nm_setting_get_name (setting))); - set_val_str (arr, 1, nmc_property_ip_tunnel_get_mode (setting, type)); - set_val_str (arr, 2, nmc_property_ip_tunnel_get_parent (setting, type)); - set_val_str (arr, 3, nmc_property_ip_tunnel_get_local (setting, type)); - set_val_str (arr, 4, nmc_property_ip_tunnel_get_remote (setting, type)); - set_val_str (arr, 5, nmc_property_ip_tunnel_get_ttl (setting, type)); - set_val_str (arr, 6, nmc_property_ip_tunnel_get_tos (setting, type)); - set_val_str (arr, 7, nmc_property_ip_tunnel_get_path_mtu_discovery (setting, type)); - set_val_str (arr, 8, nmc_property_ip_tunnel_get_input_key (setting, type)); - set_val_str (arr, 9, nmc_property_ip_tunnel_get_output_key (setting, type)); - set_val_str (arr, 10, nmc_property_ip_tunnel_get_encapsulation_limit (setting, type)); - set_val_str (arr, 11, nmc_property_ip_tunnel_get_flow_label (setting, type)); - set_val_str (arr, 12, nmc_property_ip_tunnel_get_mtu (setting, type)); - g_ptr_array_add (nmc->output_data, arr); - - print_data (nmc); /* Print all data */ - - return TRUE; -} - -static gboolean -setting_macsec_details (NMSetting *setting, - NmCli *nmc, - const char *one_prop, - gboolean secrets, - NmcPropertyGetType type) +static char * +_all_properties (const NMMetaSettingInfoEditor *setting_info) { - NMSettingMacsec *s_macsec = NM_SETTING_MACSEC (setting); - NmcOutputField *tmpl, *arr; - size_t tmpl_len; - - g_return_val_if_fail (NM_IS_SETTING_MACSEC (s_macsec), FALSE); - - tmpl = nmc_fields_setting_macsec; - tmpl_len = sizeof (nmc_fields_setting_macsec); - nmc->print_fields.indices = parse_output_fields (one_prop ? one_prop : NMC_FIELDS_SETTING_MACSEC_ALL, - tmpl, FALSE, NULL, NULL); - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); - g_ptr_array_add (nmc->output_data, arr); - - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX); - set_val_str (arr, 0, g_strdup (nm_setting_get_name (setting))); - set_val_str (arr, 1, nmc_property_macsec_get_parent (setting, type)); - set_val_str (arr, 2, nmc_property_macsec_get_mode (setting, type)); - set_val_str (arr, 3, nmc_property_macsec_get_encrypt (setting, type)); - set_val_str (arr, 4, GET_SECRET (secrets, setting, nmc_property_macsec_get_mka_cak, type)); - set_val_str (arr, 5, nmc_property_macsec_get_mka_cak_flags (setting, type)); - set_val_str (arr, 6, nmc_property_macsec_get_mka_ckn (setting, type)); - set_val_str (arr, 7, nmc_property_macsec_get_port (setting, type)); - set_val_str (arr, 8, nmc_property_macsec_get_validation (setting, type)); - g_ptr_array_add (nmc->output_data, arr); - - print_data (nmc); /* Print all data */ + GString *str; + guint i; - return TRUE; + str = g_string_sized_new (250); + for (i = 0; i < setting_info->properties_num; i++) { + if (str->len) + g_string_append_c (str, ','); + g_string_append (str, setting_info->properties[i].property_name); + } + return g_string_free (str, FALSE); } -static gboolean -setting_macvlan_details (NMSetting *setting, - NmCli *nmc, - const char *one_prop, - gboolean secrets, - NmcPropertyGetType type) +gboolean +setting_details (NMSetting *setting, NmCli *nmc, const char *one_prop, gboolean show_secrets) { - NMSettingMacvlan *s_macvlan = NM_SETTING_MACVLAN (setting); - NmcOutputField *tmpl, *arr; + const NMMetaSettingInfo *meta_setting_info; + const NMMetaSettingInfoEditor *setting_info; + gs_free NmcOutputField *tmpl = NULL; + NmcOutputField *arr; + guint i; size_t tmpl_len; + gs_free char *s_all = NULL; + NMMetaAccessorGetType type = NM_META_ACCESSOR_GET_TYPE_PRETTY; + NMC_OUTPUT_DATA_DEFINE_SCOPED (out); - g_return_val_if_fail (NM_IS_SETTING_MACVLAN (s_macvlan), FALSE); + g_return_val_if_fail (NM_IS_SETTING (setting), FALSE); - tmpl = nmc_fields_setting_macvlan; - tmpl_len = sizeof (nmc_fields_setting_macvlan); - nmc->print_fields.indices = parse_output_fields (one_prop ? one_prop : NMC_FIELDS_SETTING_MACVLAN_ALL, - tmpl, FALSE, NULL, NULL); - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); - g_ptr_array_add (nmc->output_data, arr); + meta_setting_info = nm_meta_setting_infos_by_gtype (G_OBJECT_TYPE (setting)); + g_return_val_if_fail (meta_setting_info, FALSE); - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX); - set_val_str (arr, 0, g_strdup (nm_setting_get_name (setting))); - set_val_str (arr, 1, nmc_property_macvlan_get_parent (setting, type)); - set_val_str (arr, 2, nmc_property_macvlan_get_mode (setting, type)); - set_val_str (arr, 3, nmc_property_macvlan_get_promiscuous (setting, type)); - set_val_str (arr, 4, nmc_property_macvlan_get_tap (setting, type)); - g_ptr_array_add (nmc->output_data, arr); + setting_info = &nm_meta_setting_infos_editor[meta_setting_info->meta_type]; + g_return_val_if_fail (setting_info, FALSE); - print_data (nmc); /* Print all data */ + g_return_val_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (setting, setting_info->general->get_setting_gtype ()), FALSE); - return TRUE; -} - -static gboolean -setting_vxlan_details (NMSetting *setting, - NmCli *nmc, - const char *one_prop, - gboolean secrets, - NmcPropertyGetType type) -{ - NMSettingVxlan *s_vxlan = NM_SETTING_VXLAN (setting); - NmcOutputField *tmpl, *arr; - size_t tmpl_len; + if (nmc->nmc_config.print_output == NMC_PRINT_TERSE) + type = NM_META_ACCESSOR_GET_TYPE_PARSABLE; - g_return_val_if_fail (NM_IS_SETTING_VXLAN (s_vxlan), FALSE); + tmpl_len = sizeof (NmcOutputField) * (setting_info->properties_num + 1); + tmpl = g_memdup (_get_nmc_output_fields (setting_info), tmpl_len); - tmpl = nmc_fields_setting_vxlan; - tmpl_len = sizeof (nmc_fields_setting_vxlan); - nmc->print_fields.indices = parse_output_fields (one_prop ? one_prop : NMC_FIELDS_SETTING_VXLAN_ALL, + out.print_fields.indices = parse_output_fields (one_prop ?: (s_all = _all_properties (setting_info)), tmpl, FALSE, NULL, NULL); arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); - g_ptr_array_add (nmc->output_data, arr); + g_ptr_array_add (out.output_data, arr); arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX); - set_val_str (arr, 0, g_strdup (nm_setting_get_name (setting))); - set_val_str (arr, 1, nmc_property_vxlan_get_parent (setting, type)); - set_val_str (arr, 2, nmc_property_vxlan_get_id (setting, type)); - set_val_str (arr, 3, nmc_property_vxlan_get_local (setting, type)); - set_val_str (arr, 4, nmc_property_vxlan_get_remote (setting, type)); - set_val_str (arr, 5, nmc_property_vxlan_get_source_port_min (setting, type)); - set_val_str (arr, 6, nmc_property_vxlan_get_source_port_max (setting, type)); - set_val_str (arr, 7, nmc_property_vxlan_get_destination_port (setting, type)); - set_val_str (arr, 8, nmc_property_vxlan_get_tos (setting, type)); - set_val_str (arr, 9, nmc_property_vxlan_get_ttl (setting, type)); - set_val_str (arr, 10, nmc_property_vxlan_get_ageing (setting, type)); - set_val_str (arr, 11, nmc_property_vxlan_get_limit (setting, type)); - set_val_str (arr, 12, nmc_property_vxlan_get_learning (setting, type)); - set_val_str (arr, 13, nmc_property_vxlan_get_proxy (setting, type)); - set_val_str (arr, 14, nmc_property_vxlan_get_rsc (setting, type)); - set_val_str (arr, 15, nmc_property_vxlan_get_l2_miss (setting, type)); - set_val_str (arr, 16, nmc_property_vxlan_get_l3_miss (setting, type)); - g_ptr_array_add (nmc->output_data, arr); - - print_data (nmc); /* Print all data */ - - return TRUE; -} - -static gboolean -setting_proxy_details (NMSetting *setting, - NmCli *nmc, - const char *one_prop, - gboolean secrets, - NmcPropertyGetType type) -{ - NMSettingProxy *s_proxy = NM_SETTING_PROXY (setting); - NmcOutputField *tmpl, *arr; - size_t tmpl_len; - - g_return_val_if_fail (NM_IS_SETTING_PROXY (s_proxy), FALSE); + for (i = 0; i < setting_info->properties_num; i++) { + const NMMetaPropertyInfo *property_info = &setting_info->properties[i]; - tmpl = nmc_fields_setting_proxy; - tmpl_len = sizeof (nmc_fields_setting_proxy); - nmc->print_fields.indices = parse_output_fields (one_prop ? one_prop : NMC_FIELDS_SETTING_PROXY_ALL, - tmpl, FALSE, NULL, NULL); - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_FIELD_NAMES); - g_ptr_array_add (nmc->output_data, arr); + if (!property_info->is_secret || show_secrets) { + set_val_str (arr, i, property_info->property_type->get_fcn (setting_info, + property_info, + setting, + type, + show_secrets)); + } else + set_val_str (arr, i, g_strdup (_(NM_META_TEXT_HIDDEN))); + } - arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX); - set_val_str (arr, 0, g_strdup (nm_setting_get_name (setting))); - set_val_str (arr, 1, nmc_property_proxy_get_method (setting, type)); - set_val_str (arr, 2, nmc_property_proxy_get_browser_only (setting, type)); - set_val_str (arr, 3, nmc_property_proxy_get_pac_url (setting, type)); - set_val_str (arr, 4, nmc_property_proxy_get_pac_script (setting, type)); - g_ptr_array_add (nmc->output_data, arr); + g_ptr_array_add (out.output_data, arr); - print_data (nmc); /* Print all data */ + print_data_prepare_width (out.output_data); + print_data (&nmc->nmc_config, &out); return TRUE; } - -typedef struct { - const char *sname; - gboolean (*func) (NMSetting *setting, - NmCli *nmc, - const char *one_prop, - gboolean secrets, - NmcPropertyGetType type); -} SettingDetails; - -static const SettingDetails detail_printers[] = { - { NM_SETTING_CONNECTION_SETTING_NAME, setting_connection_details }, - { NM_SETTING_WIRED_SETTING_NAME, setting_wired_details }, - { NM_SETTING_802_1X_SETTING_NAME, setting_802_1X_details }, - { NM_SETTING_WIRELESS_SETTING_NAME, setting_wireless_details }, - { NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, setting_wireless_security_details }, - { NM_SETTING_IP4_CONFIG_SETTING_NAME, setting_ip4_config_details }, - { NM_SETTING_IP6_CONFIG_SETTING_NAME, setting_ip6_config_details }, - { NM_SETTING_SERIAL_SETTING_NAME, setting_serial_details }, - { NM_SETTING_PPP_SETTING_NAME, setting_ppp_details }, - { NM_SETTING_PPPOE_SETTING_NAME, setting_pppoe_details }, - { NM_SETTING_GSM_SETTING_NAME, setting_gsm_details }, - { NM_SETTING_CDMA_SETTING_NAME, setting_cdma_details }, - { NM_SETTING_BLUETOOTH_SETTING_NAME, setting_bluetooth_details }, - { NM_SETTING_OLPC_MESH_SETTING_NAME, setting_olpc_mesh_details }, - { NM_SETTING_VPN_SETTING_NAME, setting_vpn_details }, - { NM_SETTING_WIMAX_SETTING_NAME, setting_wimax_details }, - { NM_SETTING_INFINIBAND_SETTING_NAME, setting_infiniband_details }, - { NM_SETTING_BOND_SETTING_NAME, setting_bond_details }, - { NM_SETTING_VLAN_SETTING_NAME, setting_vlan_details }, - { NM_SETTING_ADSL_SETTING_NAME, setting_adsl_details }, - { NM_SETTING_BRIDGE_SETTING_NAME, setting_bridge_details }, - { NM_SETTING_BRIDGE_PORT_SETTING_NAME, setting_bridge_port_details }, - { NM_SETTING_TEAM_SETTING_NAME, setting_team_details }, - { NM_SETTING_TEAM_PORT_SETTING_NAME, setting_team_port_details }, - { NM_SETTING_DCB_SETTING_NAME, setting_dcb_details }, - { NM_SETTING_TUN_SETTING_NAME, setting_tun_details }, - { NM_SETTING_IP_TUNNEL_SETTING_NAME, setting_ip_tunnel_details }, - { NM_SETTING_MACSEC_SETTING_NAME, setting_macsec_details }, - { NM_SETTING_MACVLAN_SETTING_NAME, setting_macvlan_details }, - { NM_SETTING_VXLAN_SETTING_NAME, setting_vxlan_details }, - { NM_SETTING_PROXY_SETTING_NAME, setting_proxy_details }, - { NULL }, -}; - -gboolean -setting_details (NMSetting *setting, NmCli *nmc, const char *one_prop, gboolean secrets) -{ - const SettingDetails *iter = &detail_printers[0]; - NmcPropertyGetType type = NMC_PROPERTY_GET_PRETTY; - - g_return_val_if_fail (NM_IS_SETTING (setting), FALSE); - - if (nmc->print_output == NMC_PRINT_TERSE) - type = NMC_PROPERTY_GET_PARSABLE; - - while (iter->sname) { - if (nm_setting_lookup_type (iter->sname) == G_OBJECT_TYPE (setting)) - return iter->func (setting, nmc, one_prop, secrets, type); - iter++; - } - - g_assert_not_reached (); - return FALSE; -} - diff --git a/clients/cli/settings.h b/clients/cli/settings.h index f663aa46d4..7b99f8598d 100644 --- a/clients/cli/settings.h +++ b/clients/cli/settings.h @@ -20,13 +20,13 @@ #ifndef NMC_SETTINGS_H #define NMC_SETTINGS_H +#include "nm-meta-setting.h" +#include "nm-meta-setting-desc.h" + #include "nmcli.h" #include "utils.h" -/* --- Functions --- */ - -void nmc_properties_init (void); -void nmc_properties_cleanup (void); +/*****************************************************************************/ NMSetting *nmc_setting_new_for_name (const char *name); void nmc_setting_custom_init (NMSetting *setting); @@ -38,7 +38,7 @@ void nmc_setting_connection_connect_handlers (NMSettingConnection *setting, NMCo char **nmc_setting_get_valid_properties (NMSetting *setting); char *nmc_setting_get_property_desc (NMSetting *setting, const char *prop); -const char **nmc_setting_get_property_allowed_values (NMSetting *setting, const char *prop); +const char *const*nmc_setting_get_property_allowed_values (NMSetting *setting, const char *prop, char ***out_to_free); char *nmc_setting_get_property (NMSetting *setting, const char *prop, GError **error); @@ -64,37 +64,4 @@ gboolean nmc_property_set_gvalue (NMSetting *setting, const char *prop, GValue * gboolean setting_details (NMSetting *setting, NmCli *nmc, const char *one_prop, gboolean secrets); -extern NmcOutputField nmc_fields_setting_connection[]; -extern NmcOutputField nmc_fields_setting_wired[]; -extern NmcOutputField nmc_fields_setting_8021X[]; -extern NmcOutputField nmc_fields_setting_wireless[]; -extern NmcOutputField nmc_fields_setting_wireless_security[]; -extern NmcOutputField nmc_fields_setting_ip4_config[]; -extern NmcOutputField nmc_fields_setting_ip6_config[]; -extern NmcOutputField nmc_fields_setting_serial[]; -extern NmcOutputField nmc_fields_setting_ppp[]; -extern NmcOutputField nmc_fields_setting_pppoe[]; -extern NmcOutputField nmc_fields_setting_adsl[]; -extern NmcOutputField nmc_fields_setting_gsm[]; -extern NmcOutputField nmc_fields_setting_cdma[]; -extern NmcOutputField nmc_fields_setting_bluetooth[]; -extern NmcOutputField nmc_fields_setting_olpc_mesh[]; -extern NmcOutputField nmc_fields_setting_vpn[]; -extern NmcOutputField nmc_fields_setting_wimax[]; -extern NmcOutputField nmc_fields_setting_infiniband[]; -extern NmcOutputField nmc_fields_setting_bond[]; -extern NmcOutputField nmc_fields_setting_vlan[]; -extern NmcOutputField nmc_fields_setting_bridge[]; -extern NmcOutputField nmc_fields_setting_bridge_port[]; -extern NmcOutputField nmc_fields_setting_team[]; -extern NmcOutputField nmc_fields_setting_team_port[]; -extern NmcOutputField nmc_fields_setting_dcb[]; -extern NmcOutputField nmc_fields_setting_tun[]; -extern NmcOutputField nmc_fields_setting_ip_tunnel[]; -extern NmcOutputField nmc_fields_setting_macvlan[]; -extern NmcOutputField nmc_fields_setting_macsec[]; -extern NmcOutputField nmc_fields_setting_vxlan[]; -extern NmcOutputField nmc_fields_setting_proxy[]; -extern NmcOutputField nmc_fields_setting_dummy[]; - #endif /* NMC_SETTINGS_H */ diff --git a/clients/cli/utils.c b/clients/cli/utils.c index fbd643ffc4..30d04b6f12 100644 --- a/clients/cli/utils.c +++ b/clients/cli/utils.c @@ -27,17 +27,11 @@ #include <netinet/in.h> #include <arpa/inet.h> +#include "nm-client-utils.h" + #include "utils.h" #include "common.h" - -gboolean -matches (const char *cmd, const char *pattern) -{ - size_t len = strlen (cmd); - if (!len || len > strlen (pattern)) - return FALSE; - return memcmp (pattern, cmd, len) == 0; -} +#include "settings.h" static gboolean parse_global_arg (NmCli *nmc, const char *arg) @@ -319,24 +313,26 @@ nmc_term_format_sequence (NmcTermFormat format) } static gboolean -use_colors (NmCli *nmc) +use_colors (NmcColorOption color_option) { - if (nmc == NULL) - return FALSE; + if (color_option == NMC_USE_COLOR_AUTO) { + static NmcColorOption cached = NMC_USE_COLOR_AUTO; - if (nmc->use_colors == NMC_USE_COLOR_AUTO) { - if ( g_strcmp0 (g_getenv ("TERM"), "dumb") == 0 - || !isatty (fileno (stdout))) - nmc->use_colors = NMC_USE_COLOR_NO; - else - nmc->use_colors = NMC_USE_COLOR_YES; + if (G_UNLIKELY (cached == NMC_USE_COLOR_AUTO)) { + if ( g_strcmp0 (g_getenv ("TERM"), "dumb") == 0 + || !isatty (fileno (stdout))) + cached = NMC_USE_COLOR_NO; + else + cached = NMC_USE_COLOR_YES; + } + return cached == NMC_USE_COLOR_YES; } - return nmc->use_colors == NMC_USE_COLOR_YES; + return color_option == NMC_USE_COLOR_YES; } char * -nmc_colorize (NmCli *nmc, NmcTermColor color, NmcTermFormat format, const char *fmt, ...) +nmc_colorize (NmcColorOption color_option, NmcTermColor color, NmcTermFormat format, const char *fmt, ...) { va_list args; char *str, *colored; @@ -347,7 +343,7 @@ nmc_colorize (NmCli *nmc, NmcTermColor color, NmcTermFormat format, const char * str = g_strdup_vprintf (fmt, args); va_end (args); - if (!use_colors (nmc)) + if (!use_colors (color_option)) return str; ansi_color = nmc_term_color_sequence (color); @@ -426,137 +422,6 @@ nmc_filter_out_colors (const char *str) } /* - * Convert string to signed integer. - * If required, the resulting number is checked to be in the <min,max> range. - */ -gboolean -nmc_string_to_int_base (const char *str, - int base, - gboolean range_check, - long int min, - long int max, - long int *value) -{ - char *end; - long int tmp; - - errno = 0; - tmp = strtol (str, &end, base); - if (errno || *end != '\0' || (range_check && (tmp < min || tmp > max))) { - return FALSE; - } - *value = tmp; - return TRUE; -} - -/* - * Convert string to unsigned integer. - * If required, the resulting number is checked to be in the <min,max> range. - */ -gboolean -nmc_string_to_uint_base (const char *str, - int base, - gboolean range_check, - unsigned long int min, - unsigned long int max, - unsigned long int *value) -{ - char *end; - unsigned long int tmp; - - errno = 0; - tmp = strtoul (str, &end, base); - if (errno || *end != '\0' || (range_check && (tmp < min || tmp > max))) { - return FALSE; - } - *value = tmp; - return TRUE; -} - -gboolean -nmc_string_to_int (const char *str, - gboolean range_check, - long int min, - long int max, - long int *value) -{ - return nmc_string_to_int_base (str, 10, range_check, min, max, value); -} - -gboolean -nmc_string_to_uint (const char *str, - gboolean range_check, - unsigned long int min, - unsigned long int max, - unsigned long int *value) -{ - return nmc_string_to_uint_base (str, 10, range_check, min, max, value); -} - -gboolean -nmc_string_to_bool (const char *str, gboolean *val_bool, GError **error) -{ - const char *s_true[] = { "true", "yes", "on", NULL }; - const char *s_false[] = { "false", "no", "off", NULL }; - - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - - if (g_strcmp0 (str, "o") == 0) { - g_set_error (error, 1, 0, - /* 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"); - return FALSE; - } - - if (nmc_string_is_valid (str, s_true, NULL)) - *val_bool = TRUE; - else if (nmc_string_is_valid (str, s_false, NULL)) - *val_bool = FALSE; - else { - g_set_error (error, 1, 0, - _("'%s' is not valid; use [%s] or [%s]"), - str, "true, yes, on", "false, no, off"); - return FALSE; - } - return TRUE; -} - -gboolean -nmc_string_to_tristate (const char *str, NMCTriStateValue *val, GError **error) -{ - const char *s_true[] = { "true", "yes", "on", NULL }; - const char *s_false[] = { "false", "no", "off", NULL }; - const char *s_unknown[] = { "unknown", NULL }; - - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - - if (g_strcmp0 (str, "o") == 0) { - g_set_error (error, 1, 0, - /* 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"); - return FALSE; - } - - if (nmc_string_is_valid (str, s_true, NULL)) - *val = NMC_TRI_STATE_YES; - else if (nmc_string_is_valid (str, s_false, NULL)) - *val = NMC_TRI_STATE_NO; - else if (nmc_string_is_valid (str, s_unknown, NULL)) - *val = NMC_TRI_STATE_UNKNOWN; - else { - g_set_error (error, 1, 0, - _("'%s' is not valid; use [%s], [%s] or [%s]"), - str, "true, yes, on", "false, no, off", "unknown"); - return FALSE; - } - return TRUE; -} - -/* * Ask user for input and return the string. * The caller is responsible for freeing the returned string. */ @@ -619,64 +484,13 @@ nmc_string_to_arg_array (const char *line, const char *delim, gboolean unquote, } /* - * Check whether 'input' is contained in 'allowed' array. It performs case - * insensitive comparison and supports shortcut strings if they are unique. - * Returns: a pointer to found string in allowed array on success or NULL. - * On failure: error->code : 0 - string not found; 1 - string is ambiguous - */ -const char * -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; - - g_return_val_if_fail (error == NULL || *error == NULL, NULL); - - if (!input || !*input) - goto finish; - - input_ln = strlen (input); - 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; - } - } - -finish: - if (ret == NULL) { - 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 - g_set_error (error, 1, 0, _("'%s' not among [%s]"), input, valid_vals); - - g_free (valid_vals); - } - return ret; -} - -/* * Convert string array (char **) to description string in the form of: * "[string1, string2, ]" * * Returns: a newly allocated string. Caller must free it with g_free(). */ char * -nmc_util_strv_for_display (const char **strv, gboolean brackets) +nmc_util_strv_for_display (const char *const*strv, gboolean brackets) { GString *result; guint i = 0; @@ -697,31 +511,6 @@ nmc_util_strv_for_display (const char **strv, gboolean brackets) } /* - * 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) -{ - char **result; - uint i; - uint j; - - result = g_strsplit_set (str, delimiter, max_tokens); - - /* remove empty strings */ - for (i = 0; result && result[i]; i++) { - if (*(result[i]) == '\0') { - g_free (result[i]); - for (j = i; result[j]; j++) - result[j] = result[j + 1]; - i--; - } - } - return result; -} - -/* * Find out how many columns an UTF-8 string occupies on the screen. */ int @@ -869,16 +658,27 @@ parse_output_fields (const char *fields_str, for (i = 0; fields_array[i].name; i++) { if (strcasecmp (left, fields_array[i].name) == 0) { - NmcOutputField *valid_names = fields_array[i].group; + const NmcOutputField *valid_names = fields_array[i].group_list; + const NMMetaSettingInfoEditor *setting_info = fields_array[i].setting_info; + idx = i; - if (!right && !valid_names) { + if (!right && !valid_names && !setting_info) { found = TRUE; break; } - for (j = 0; valid_names && valid_names[j].name; j++) { - if (!right || strcasecmp (right, valid_names[j].name) == 0) { - found = TRUE; - break; + if (valid_names) { + for (j = 0; valid_names[j].name; j++) { + if (!right || strcasecmp (right, valid_names[j].name) == 0) { + found = TRUE; + break; + } + } + } else if (setting_info) { + for (j = 1; j < setting_info->properties_num; j++) { + if (!right || strcasecmp (right, setting_info->properties[j].property_name) == 0) { + found = TRUE; + break; + } } } if (found) @@ -946,11 +746,20 @@ nmc_get_allowed_fields (const NmcOutputField fields_array[], int group_idx) GString *allowed_fields = g_string_sized_new (256); int i; - if (group_idx != -1 && fields_array[group_idx].group) { - NmcOutputField *second_level = fields_array[group_idx].group; - for (i = 0; second_level[i].name; i++) + if (group_idx != -1 && fields_array[group_idx].group_list) { + const NmcOutputField *second_level = fields_array[group_idx].group_list; + + for (i = 0; second_level[i].name; i++) { g_string_append_printf (allowed_fields, "%s.%s,", fields_array[group_idx].name, second_level[i].name); + } + } else if (group_idx != -1 && fields_array[group_idx].setting_info) { + const NMMetaSettingInfoEditor *second_level = fields_array[group_idx].setting_info; + + for (i = 1; i < second_level->properties_num; i++) { + g_string_append_printf (allowed_fields, "%s.%s,", + fields_array[group_idx].name, second_level->properties[i].property_name); + } } else { for (i = 0; fields_array[i].name; i++) g_string_append_printf (allowed_fields, "%s,", fields_array[i].name); @@ -973,28 +782,28 @@ nmc_dup_fields_array (NmcOutputField fields[], size_t size, guint32 flags) } void -nmc_empty_output_fields (NmCli *nmc) +nmc_empty_output_fields (NmcOutputData *output_data) { guint i; /* Free values in field structure */ - for (i = 0; i < nmc->output_data->len; i++) { - NmcOutputField *fld_arr = g_ptr_array_index (nmc->output_data, i); + for (i = 0; i < output_data->output_data->len; i++) { + NmcOutputField *fld_arr = g_ptr_array_index (output_data->output_data, i); nmc_free_output_field_values (fld_arr); } /* Empty output_data array */ - if (nmc->output_data->len > 0) - g_ptr_array_remove_range (nmc->output_data, 0, nmc->output_data->len); + if (output_data->output_data->len > 0) + g_ptr_array_remove_range (output_data->output_data, 0, output_data->output_data->len); - if (nmc->print_fields.indices) { - g_array_free (nmc->print_fields.indices, TRUE); - nmc->print_fields.indices = NULL; + if (output_data->print_fields.indices) { + g_array_free (output_data->print_fields.indices, TRUE); + output_data->print_fields.indices = NULL; } } static const char * -colorize_string (NmCli *nmc, +colorize_string (NmcColorOption color_option, NmcTermColor color, NmcTermFormat color_fmt, const char *str, @@ -1002,9 +811,9 @@ colorize_string (NmCli *nmc, { const char *out = str; - if ( use_colors (nmc) + if ( use_colors (color_option) && (color != NMC_TERM_COLOR_NORMAL || color_fmt != NMC_TERM_FORMAT_NORMAL)) { - *out_to_free = nmc_colorize (nmc, color, color_fmt, "%s", str); + *out_to_free = nmc_colorize (color_option, color, color_fmt, "%s", str); out = *out_to_free; } @@ -1012,36 +821,38 @@ colorize_string (NmCli *nmc, } static const char * -get_value_to_print (NmCli *nmc, - NmcOutputField *field, +get_value_to_print (NmcColorOption color_option, + const NmcOutputField *field, gboolean field_name, const char *not_set_str, char **out_to_free) { gboolean is_array = field->value_is_array; - char *value; + const char *value; const char *out; - gboolean free_value; + gs_free char *free_value = NULL; + + nm_assert (out_to_free && !*out_to_free); if (field_name) - value = _(field->name_l10n); - else + value = _(field->name); + else { value = field->value ? (is_array - ? g_strjoinv (" | ", (char **) field->value) - : (*((char *) field->value) - ? (char *) field->value - : (char *) not_set_str)) - : (char *) not_set_str; - free_value = field->value && is_array && !field_name; + ? (free_value = g_strjoinv (" | ", (char **) field->value)) + : (*((const char *) field->value)) + ? field->value + : not_set_str) + : not_set_str; + } /* colorize the value */ - out = colorize_string (nmc, field->color, field->color_fmt, value, out_to_free); - if (*out_to_free) { - if (free_value) - g_free (value); - } else if (free_value) - *out_to_free = value; + out = colorize_string (color_option, field->color, field->color_fmt, value, out_to_free); + + if (out && out == free_value) { + nm_assert (!*out_to_free); + *out_to_free = g_steal_pointer (&free_value); + } return out; } @@ -1054,7 +865,7 @@ get_value_to_print (NmCli *nmc, * of 'field_values' array. */ void -print_required_fields (NmCli *nmc, const NmcOutputField field_values[]) +print_required_fields (const NmcConfig *nmc_config, const NmcPrintFields *print_fields, const NmcOutputField *field_values) { GString *str; int width1, width2; @@ -1063,11 +874,10 @@ print_required_fields (NmCli *nmc, const NmcOutputField field_values[]) char *indent_str; const char *not_set_str = "--"; int i; - const NmcPrintFields fields = nmc->print_fields; - gboolean multiline = nmc->multiline_output; - gboolean terse = (nmc->print_output == NMC_PRINT_TERSE); - gboolean pretty = (nmc->print_output == NMC_PRINT_PRETTY); - gboolean escape = nmc->escape_values; + gboolean multiline = nmc_config->multiline_output; + gboolean terse = (nmc_config->print_output == NMC_PRINT_TERSE); + gboolean pretty = (nmc_config->print_output == NMC_PRINT_PRETTY); + gboolean escape = nmc_config->escape_values; gboolean main_header_add = field_values[0].flags & NMC_OF_FLAG_MAIN_HEADER_ADD; gboolean main_header_only = field_values[0].flags & NMC_OF_FLAG_MAIN_HEADER_ONLY; gboolean field_names = field_values[0].flags & NMC_OF_FLAG_FIELD_NAMES; @@ -1080,7 +890,7 @@ print_required_fields (NmCli *nmc, const NmcOutputField field_values[]) /* --- Main header --- */ if (main_header && pretty) { - int header_width = nmc_string_screen_width (fields.header_name, NULL) + 4; + int header_width = nmc_string_screen_width (print_fields->header_name, NULL) + 4; if (multiline) { table_width = header_width < ML_HEADER_WIDTH ? ML_HEADER_WIDTH : header_width; @@ -1090,10 +900,10 @@ print_required_fields (NmCli *nmc, const NmcOutputField field_values[]) line = g_strnfill (table_width, '='); } - width1 = strlen (fields.header_name); - width2 = nmc_string_screen_width (fields.header_name, NULL); + width1 = strlen (print_fields->header_name); + width2 = nmc_string_screen_width (print_fields->header_name, NULL); g_print ("%s\n", line); - g_print ("%*s\n", (table_width + width2)/2 + width1 - width2, fields.header_name); + g_print ("%*s\n", (table_width + width2)/2 + width1 - width2, print_fields->header_name); g_print ("%s\n", line); g_free (line); } @@ -1110,9 +920,9 @@ print_required_fields (NmCli *nmc, const NmcOutputField field_values[]) if (multiline) { - for (i = 0; i < fields.indices->len; i++) { + for (i = 0; i < print_fields->indices->len; i++) { char *tmp; - int idx = g_array_index (fields.indices, int, i); + int idx = g_array_index (print_fields->indices, int, i); gboolean is_array = field_values[idx].value_is_array; /* section prefix can't be an array */ @@ -1129,12 +939,12 @@ print_required_fields (NmCli *nmc, const NmcOutputField field_values[]) for (p = (const char **) field_values[idx].value, j = 1; p && *p; p++, j++) { val = *p ? *p : not_set_str; - print_val = colorize_string (nmc, field_values[idx].color, field_values[idx].color_fmt, + print_val = colorize_string (nmc_config->use_colors, field_values[idx].color, field_values[idx].color_fmt, val, &val_to_free); tmp = g_strdup_printf ("%s%s%s[%d]:", section_prefix ? (const char*) field_values[0].value : "", section_prefix ? "." : "", - _(field_values[idx].name_l10n), + _(field_values[idx].name), j); width1 = strlen (tmp); width2 = nmc_string_screen_width (tmp, NULL); @@ -1149,12 +959,12 @@ print_required_fields (NmCli *nmc, const NmcOutputField field_values[]) gs_free char *val_to_free = NULL; val = val && *val ? val : not_set_str; - print_val = colorize_string (nmc, field_values[idx].color, field_values[idx].color_fmt, + print_val = colorize_string (nmc_config->use_colors, field_values[idx].color, field_values[idx].color_fmt, val, &val_to_free); tmp = g_strdup_printf ("%s%s%s:", section_prefix ? hdr_name : "", section_prefix ? "." : "", - _(field_values[idx].name_l10n)); + _(field_values[idx].name)); width1 = strlen (tmp); width2 = nmc_string_screen_width (tmp, NULL); g_print ("%-*s%s\n", terse ? 0 : ML_VALUE_INDENT+width1-width2, tmp, print_val); @@ -1174,10 +984,10 @@ print_required_fields (NmCli *nmc, const NmcOutputField field_values[]) str = g_string_new (NULL); - for (i = 0; i < fields.indices->len; i++) { - int idx = g_array_index (fields.indices, int, i); + for (i = 0; i < print_fields->indices->len; i++) { + int idx = g_array_index (print_fields->indices, int, i); gs_free char *val_to_free = NULL; - const char *value = get_value_to_print (nmc, (NmcOutputField *) field_values+idx, field_names, + const char *value = get_value_to_print (nmc_config->use_colors, (NmcOutputField *) field_values+idx, field_names, not_set_str, &val_to_free); if (terse) { @@ -1205,8 +1015,8 @@ print_required_fields (NmCli *nmc, const NmcOutputField field_values[]) /* Print actual values */ if (str->len > 0) { g_string_truncate (str, str->len-1); /* Chop off last column separator */ - if (fields.indent > 0) { - indent_str = g_strnfill (fields.indent, ' '); + if (print_fields->indent > 0) { + indent_str = g_strnfill (print_fields->indent, ' '); g_string_prepend (str, indent_str); g_free (indent_str); } @@ -1223,27 +1033,19 @@ print_required_fields (NmCli *nmc, const NmcOutputField field_values[]) g_string_free (str, TRUE); } -/* - * Print nmc->output_data - * - * It first finds out maximal string length in columns and fill the value to - * 'width' member of NmcOutputField, so that columns in tabular output are - * properly aligned. Then each object (row in tabular) is printed using - * print_required_fields() function. - */ void -print_data (NmCli *nmc) +print_data_prepare_width (GPtrArray *output_data) { int i, j; size_t len; NmcOutputField *row; int num_fields = 0; - if (!nmc->output_data || nmc->output_data->len < 1) + if (!output_data || output_data->len < 1) return; /* How many fields? */ - row = g_ptr_array_index (nmc->output_data, 0); + row = g_ptr_array_index (output_data, 0); while (row->name) { num_fields++; row++; @@ -1252,27 +1054,32 @@ print_data (NmCli *nmc) /* Find out maximal string lengths */ for (i = 0; i < num_fields; i++) { size_t max_width = 0; - for (j = 0; j < nmc->output_data->len; j++) { + for (j = 0; j < output_data->len; j++) { gboolean field_names; gs_free char * val_to_free = NULL; const char *value; - row = g_ptr_array_index (nmc->output_data, j); + row = g_ptr_array_index (output_data, j); field_names = row[0].flags & NMC_OF_FLAG_FIELD_NAMES; - value = get_value_to_print (NULL, row+i, field_names, "--", &val_to_free); + value = get_value_to_print (NMC_USE_COLOR_NO, row+i, field_names, "--", &val_to_free); len = nmc_string_screen_width (value, NULL); max_width = len > max_width ? len : max_width; } - for (j = 0; j < nmc->output_data->len; j++) { - row = g_ptr_array_index (nmc->output_data, j); + for (j = 0; j < output_data->len; j++) { + row = g_ptr_array_index (output_data, j); row[i].width = max_width + 1; } } +} + +void +print_data (const NmcConfig *nmc_config, const NmcOutputData *out) +{ + guint i; - /* Now we can print the data. */ - for (i = 0; i < nmc->output_data->len; i++) { - row = g_ptr_array_index (nmc->output_data, i); - print_required_fields (nmc, row); + for (i = 0; i < out->output_data->len; i++) { + print_required_fields (nmc_config, &out->print_fields, + g_ptr_array_index (out->output_data, i)); } } diff --git a/clients/cli/utils.h b/clients/cli/utils.h index d889962df7..cc7bc1f2fc 100644 --- a/clients/cli/utils.h +++ b/clients/cli/utils.h @@ -32,56 +32,25 @@ typedef struct { gboolean found; } nmc_arg_t; -typedef enum { - NMC_TRI_STATE_NO, - NMC_TRI_STATE_YES, - NMC_TRI_STATE_UNKNOWN, -} NMCTriStateValue; - /* === Functions === */ -gboolean matches (const char *cmd, const char *pattern); int next_arg (NmCli *nmc, int *argc, char ***argv); gboolean nmc_arg_is_help (const char *arg); gboolean nmc_arg_is_option (const char *arg, const char *opt_name); gboolean nmc_parse_args (nmc_arg_t *arg_arr, gboolean last, int *argc, char ***argv, GError **error); char *ssid_to_hex (const char *str, gsize len); -gboolean nmc_string_to_int_base (const char *str, - int base, - gboolean range_check, - long int min, - long int max, - long int *value); -gboolean nmc_string_to_uint_base (const char *str, - int base, - gboolean range_check, - unsigned long int min, - unsigned long int max, - unsigned long int *value); -gboolean nmc_string_to_int (const char *str, - gboolean range_check, - long int min, - long int max, - long int *value); -gboolean nmc_string_to_uint (const char *str, - gboolean range_check, - unsigned long int min, - unsigned long int max, - unsigned long int *value); -gboolean nmc_string_to_bool (const char *str, gboolean *val_bool, GError **error); -gboolean nmc_string_to_tristate (const char *str, NMCTriStateValue *val, GError **error); void nmc_terminal_erase_line (void); void nmc_terminal_show_progress (const char *str); const char *nmc_term_color_sequence (NmcTermColor color); const char *nmc_term_format_sequence (NmcTermFormat format); NmcTermColor nmc_term_color_parse_string (const char *str, GError **error); -char *nmc_colorize (NmCli *nmc, NmcTermColor color, NmcTermFormat format, const char * fmt, ...) _nm_printf (4, 5); +char *nmc_colorize (NmcColorOption color_option, NmcTermColor color, NmcTermFormat format, const char * fmt, ...) _nm_printf (4, 5); 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); int nmc_string_to_arg_array (const char *line, const char *delim, gboolean unquote, 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 **strv, gboolean brackets); +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); @@ -98,8 +67,9 @@ GArray *parse_output_fields (const char *fields_str, GError **error); char *nmc_get_allowed_fields (const NmcOutputField fields_array[], int group_idx); NmcOutputField *nmc_dup_fields_array (NmcOutputField fields[], size_t size, guint32 flags); -void nmc_empty_output_fields (NmCli *nmc); -void print_required_fields (NmCli *nmc, const NmcOutputField field_values[]); -void print_data (NmCli *nmc); +void nmc_empty_output_fields (NmcOutputData *output_data); +void print_required_fields (const NmcConfig *nmc_config, const NmcPrintFields *print_fields, const NmcOutputField field_values[]); +void print_data_prepare_width (GPtrArray *output_data); +void print_data (const NmcConfig *nmc_config, const NmcOutputData *out); #endif /* NMC_UTILS_H */ diff --git a/clients/common/nm-client-utils.c b/clients/common/nm-client-utils.c new file mode 100644 index 0000000000..6df143861a --- /dev/null +++ b/clients/common/nm-client-utils.c @@ -0,0 +1,239 @@ +/* nmcli - command-line tool to control NetworkManager + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * 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. + */ + +#include "nm-default.h" + +#include "nm-client-utils.h" + +/* + * Convert string to signed integer. + * If required, the resulting number is checked to be in the <min,max> range. + */ +gboolean +nmc_string_to_int_base (const char *str, + int base, + gboolean range_check, + long int min, + long int max, + long int *value) +{ + char *end; + long int tmp; + + errno = 0; + tmp = strtol (str, &end, base); + if (errno || *end != '\0' || (range_check && (tmp < min || tmp > max))) { + return FALSE; + } + *value = tmp; + return TRUE; +} + +/* + * Convert string to unsigned integer. + * If required, the resulting number is checked to be in the <min,max> range. + */ +gboolean +nmc_string_to_uint_base (const char *str, + int base, + gboolean range_check, + unsigned long int min, + unsigned long int max, + unsigned long int *value) +{ + char *end; + unsigned long int tmp; + + errno = 0; + tmp = strtoul (str, &end, base); + if (errno || *end != '\0' || (range_check && (tmp < min || tmp > max))) { + return FALSE; + } + *value = tmp; + return TRUE; +} + +gboolean +nmc_string_to_int (const char *str, + gboolean range_check, + long int min, + long int max, + long int *value) +{ + return nmc_string_to_int_base (str, 10, range_check, min, max, value); +} + +gboolean +nmc_string_to_uint (const char *str, + gboolean range_check, + unsigned long int min, + unsigned long int max, + unsigned long int *value) +{ + return nmc_string_to_uint_base (str, 10, range_check, min, max, value); +} + +gboolean +nmc_string_to_bool (const char *str, gboolean *val_bool, GError **error) +{ + const char *s_true[] = { "true", "yes", "on", NULL }; + const char *s_false[] = { "false", "no", "off", NULL }; + + g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + + if (g_strcmp0 (str, "o") == 0) { + g_set_error (error, 1, 0, + /* 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"); + return FALSE; + } + + if (nmc_string_is_valid (str, s_true, NULL)) + *val_bool = TRUE; + else if (nmc_string_is_valid (str, s_false, NULL)) + *val_bool = FALSE; + else { + g_set_error (error, 1, 0, + _("'%s' is not valid; use [%s] or [%s]"), + str, "true, yes, on", "false, no, off"); + return FALSE; + } + return TRUE; +} + +gboolean +nmc_string_to_tristate (const char *str, NMCTriStateValue *val, GError **error) +{ + const char *s_true[] = { "true", "yes", "on", NULL }; + const char *s_false[] = { "false", "no", "off", NULL }; + const char *s_unknown[] = { "unknown", NULL }; + + g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + + if (g_strcmp0 (str, "o") == 0) { + g_set_error (error, 1, 0, + /* 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"); + return FALSE; + } + + if (nmc_string_is_valid (str, s_true, NULL)) + *val = NMC_TRI_STATE_YES; + else if (nmc_string_is_valid (str, s_false, NULL)) + *val = NMC_TRI_STATE_NO; + else if (nmc_string_is_valid (str, s_unknown, NULL)) + *val = NMC_TRI_STATE_UNKNOWN; + else { + g_set_error (error, 1, 0, + _("'%s' is not valid; use [%s], [%s] or [%s]"), + str, "true, yes, on", "false, no, off", "unknown"); + return FALSE; + } + return TRUE; +} + +/* + * Check whether 'input' is contained in 'allowed' array. It performs case + * insensitive comparison and supports shortcut strings if they are unique. + * Returns: a pointer to found string in allowed array on success or NULL. + * On failure: error->code : 0 - string not found; 1 - string is ambiguous + */ +const char * +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; + + g_return_val_if_fail (error == NULL || *error == NULL, NULL); + + if (!input || !*input) + goto finish; + + input_ln = strlen (input); + 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; + } + } + +finish: + if (ret == NULL) { + 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 + g_set_error (error, 1, 0, _("'%s' not among [%s]"), input, valid_vals); + + 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) +{ + char **result; + uint i; + uint j; + + result = g_strsplit_set (str, delimiter, max_tokens); + + /* remove empty strings */ + for (i = 0; result && result[i]; i++) { + if (*(result[i]) == '\0') { + g_free (result[i]); + for (j = i; result[j]; j++) + result[j] = result[j + 1]; + i--; + } + } + return result; +} + +gboolean +matches (const char *cmd, const char *pattern) +{ + size_t len = strlen (cmd); + if (!len || len > strlen (pattern)) + return FALSE; + return memcmp (pattern, cmd, len) == 0; +} + diff --git a/clients/common/nm-client-utils.h b/clients/common/nm-client-utils.h new file mode 100644 index 0000000000..7f700f930f --- /dev/null +++ b/clients/common/nm-client-utils.h @@ -0,0 +1,63 @@ +/* nmcli - command-line tool to control NetworkManager + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * 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. + */ + +#ifndef __NM_CLIENT_UTILS_H__ +#define __NM_CLIENT_UTILS_H__ + +#include "nm-meta-setting.h" + + +typedef enum { + NMC_TRI_STATE_NO, + NMC_TRI_STATE_YES, + NMC_TRI_STATE_UNKNOWN, +} NMCTriStateValue; + +const char *nmc_string_is_valid (const char *input, const char **allowed, GError **error); + +char **nmc_strsplit_set (const char *str, const char *delimiter, int max_tokens); + +gboolean nmc_string_to_int_base (const char *str, + int base, + gboolean range_check, + long int min, + long int max, + long int *value); +gboolean nmc_string_to_uint_base (const char *str, + int base, + gboolean range_check, + unsigned long int min, + unsigned long int max, + unsigned long int *value); +gboolean nmc_string_to_int (const char *str, + gboolean range_check, + long int min, + long int max, + long int *value); +gboolean nmc_string_to_uint (const char *str, + gboolean range_check, + unsigned long int min, + unsigned long int max, + unsigned long int *value); +gboolean nmc_string_to_bool (const char *str, gboolean *val_bool, GError **error); +gboolean nmc_string_to_tristate (const char *str, NMCTriStateValue *val, GError **error); + +gboolean matches (const char *cmd, const char *pattern); + +#endif /* __NM_CLIENT_UTILS_H__ */ diff --git a/clients/common/nm-meta-setting-desc.c b/clients/common/nm-meta-setting-desc.c new file mode 100644 index 0000000000..9189572d3f --- /dev/null +++ b/clients/common/nm-meta-setting-desc.c @@ -0,0 +1,6681 @@ +/* nmcli - command-line tool to control NetworkManager + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * 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. + */ + +#include "nm-default.h" + +#include "nm-meta-setting-desc.h" + +#include <stdlib.h> +#include <arpa/inet.h> + +#include "nm-common-macros.h" +#include "nm-utils/nm-enum-utils.h" + +#include "nm-vpn-helpers.h" +#include "nm-client-utils.h" + +/*****************************************************************************/ + +/* FIXME: don't include headers from nmcli. And move all uses of NMClient out + * of there. */ + +/* FIXME: don't directly print any warnings. Instead, add a hook mechanism to notify + * the caller about warnings, error or whatever. + */ + +#include "nmcli.h" + +NMConnection * +nmc_find_connection (const GPtrArray *connections, + const char *filter_type, + const char *filter_val, + int *start, + gboolean complete); + +/*****************************************************************************/ + +static gboolean validate_int (NMSetting *setting, const char* prop, gint val, GError **error); +static gboolean validate_uint (NMSetting *setting, const char* prop, guint val, GError **error); +static gboolean validate_int64 (NMSetting *setting, const char* prop, gint64 val, GError **error); +static char *secret_flags_to_string (guint32 flags, NMMetaAccessorGetType get_type); + +#define ALL_SECRET_FLAGS \ + (NM_SETTING_SECRET_FLAG_NONE | \ + NM_SETTING_SECRET_FLAG_AGENT_OWNED | \ + NM_SETTING_SECRET_FLAG_NOT_SAVED | \ + NM_SETTING_SECRET_FLAG_NOT_REQUIRED) + +/*****************************************************************************/ + +static GType +_gobject_property_get_gtype (GObject *gobject, const char *property_name) +{ + GParamSpec *param_spec; + + param_spec = g_object_class_find_property (G_OBJECT_GET_CLASS (gobject), property_name); + if (param_spec) + return param_spec->value_type; + g_return_val_if_reached (G_TYPE_INVALID); +} + +static GType +_gtype_property_get_gtype (GType gtype, const char *property_name) +{ + /* given @gtype, a type for a GObject, lookup the property @property_name + * and return its value_type. */ + if (G_TYPE_IS_CLASSED (gtype)) { + GParamSpec *param_spec; + nm_auto_unref_gtypeclass GTypeClass *gtypeclass = g_type_class_ref (gtype); + + if (G_IS_OBJECT_CLASS (gtypeclass)) { + param_spec = g_object_class_find_property (G_OBJECT_CLASS (gtypeclass), property_name); + if (param_spec) + return param_spec->value_type; + } + } + g_return_val_if_reached (G_TYPE_INVALID); +} + +/*****************************************************************************/ + +/* + * Parse IP address from string to NMIPAddress stucture. + * ip_str is the IP address in the form address/prefix + */ +static NMIPAddress * +nmc_parse_and_build_address (int family, const char *ip_str, GError **error) +{ + int max_prefix = (family == AF_INET) ? 32 : 128; + NMIPAddress *addr = NULL; + const char *ip; + char *tmp; + char *plen; + long int prefix; + GError *local = NULL; + + g_return_val_if_fail (ip_str != NULL, NULL); + g_return_val_if_fail (error == NULL || *error == NULL, NULL); + + tmp = g_strdup (ip_str); + plen = strchr (tmp, '/'); /* prefix delimiter */ + if (plen) + *plen++ = '\0'; + + ip = tmp; + + prefix = max_prefix; + if (plen) { + if (!nmc_string_to_int (plen, TRUE, 1, max_prefix, &prefix)) { + g_set_error (error, NM_UTILS_ERROR, NM_UTILS_ERROR_INVALID_ARGUMENT, + _("invalid prefix '%s'; <1-%d> allowed"), plen, max_prefix); + goto finish; + } + } + + addr = nm_ip_address_new (family, ip, (guint32) prefix, &local); + if (!addr) { + g_set_error (error, NM_UTILS_ERROR, NM_UTILS_ERROR_INVALID_ARGUMENT, + _("invalid IP address: %s"), local->message); + g_clear_error (&local); + } + +finish: + g_free (tmp); + return addr; +} + +/* + * nmc_parse_and_build_route: + * @family: AF_INET or AF_INET6 + * @str: route string to be parsed + * @error: location to store GError + * + * Parse route from string and return an #NMIPRoute + * + * Returns: a new #NMIPRoute or %NULL on error + */ +static NMIPRoute * +nmc_parse_and_build_route (int family, + const char *str, + GError **error) +{ + int max_prefix = (family == AF_INET) ? 32 : 128; + char *plen = NULL; + const char *next_hop = NULL; + const char *canon_dest; + long int prefix = max_prefix; + unsigned long int tmp_ulong; + NMIPRoute *route = NULL; + gboolean success = FALSE; + GError *local = NULL; + gint64 metric = -1; + guint i, len; + gs_strfreev char **routev = NULL; + gs_free char *value = NULL; + gs_free char *dest = NULL; + gs_unref_hashtable GHashTable *attrs = NULL; + GHashTable *tmp_attrs; + + g_return_val_if_fail (family == AF_INET || family == AF_INET6, FALSE); + g_return_val_if_fail (str, FALSE); + g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + + value = g_strdup (str); + routev = nmc_strsplit_set (g_strstrip (value), " \t", 0); + len = g_strv_length (routev); + if (len < 1) { + g_set_error (error, 1, 0, _("'%s' is not valid (the format is: ip[/prefix] [next-hop] [metric] [attr=val] [attr=val])"), + str); + goto finish; + } + + dest = g_strdup (routev[0]); + plen = strchr (dest, '/'); /* prefix delimiter */ + if (plen) + *plen++ = '\0'; + + if (plen) { + if (!nmc_string_to_int (plen, TRUE, 1, max_prefix, &prefix)) { + g_set_error (error, NM_UTILS_ERROR, NM_UTILS_ERROR_INVALID_ARGUMENT, + _("invalid prefix '%s'; <1-%d> allowed"), + plen, max_prefix); + goto finish; + } + } + + for (i = 1; i < len; i++) { + if (nm_utils_ipaddr_valid (family, routev[i])) { + if (metric != -1 || attrs) { + g_set_error (error, 1, 0, _("the next hop ('%s') must be first"), routev[i]); + goto finish; + } + next_hop = routev[i]; + } else if (nmc_string_to_uint (routev[i], TRUE, 0, G_MAXUINT32, &tmp_ulong)) { + if (attrs) { + g_set_error (error, 1, 0, _("the metric ('%s') must be before attributes"), routev[i]); + goto finish; + } + metric = tmp_ulong; + } else if (strchr (routev[i], '=')) { + GHashTableIter iter; + char *iter_key; + GVariant *iter_value; + + tmp_attrs = nm_utils_parse_variant_attributes (routev[i], ' ', '=', FALSE, + nm_ip_route_get_variant_attribute_spec(), + error); + if (!tmp_attrs) { + g_prefix_error (error, "invalid option '%s': ", routev[i]); + goto finish; + } + + if (!attrs) + attrs = g_hash_table_new (g_str_hash, g_str_equal); + + g_hash_table_iter_init (&iter, tmp_attrs); + while (g_hash_table_iter_next (&iter, (gpointer *) &iter_key, (gpointer *) &iter_value)) { + if (!nm_ip_route_attribute_validate (iter_key, iter_value, family, NULL, error)) { + g_prefix_error (error, "%s: ", iter_key); + g_hash_table_unref (tmp_attrs); + goto finish; + } + g_hash_table_insert (attrs, iter_key, iter_value); + g_hash_table_iter_steal (&iter); + } + g_hash_table_unref (tmp_attrs); + } else { + g_set_error (error, 1, 0, _("unrecognized option '%s'"), routev[i]); + goto finish; + } + } + + route = nm_ip_route_new (family, dest, prefix, next_hop, metric, &local); + if (!route) { + g_set_error (error, NM_UTILS_ERROR, NM_UTILS_ERROR_INVALID_ARGUMENT, + _("invalid route: %s"), local->message); + g_clear_error (&local); + goto finish; + } + + /* We don't accept default routes as NetworkManager handles it + * itself. But we have to check this after @route has normalized the + * dest string. + */ + canon_dest = nm_ip_route_get_dest (route); + if (!strcmp (canon_dest, "0.0.0.0") || !strcmp (canon_dest, "::")) { + g_set_error_literal (error, NM_UTILS_ERROR, NM_UTILS_ERROR_INVALID_ARGUMENT, + _("default route cannot be added (NetworkManager handles it by itself)")); + g_clear_pointer (&route, nm_ip_route_unref); + goto finish; + } + + if (attrs) { + GHashTableIter iter; + char *name; + GVariant *variant; + + g_hash_table_iter_init (&iter, attrs); + while (g_hash_table_iter_next (&iter, (gpointer *) &name, (gpointer *) &variant)) + nm_ip_route_set_attribute (route, name, variant); + } + + success = TRUE; + +finish: + return route; +} + +/* Max priority values from libnm-core/nm-setting-vlan.c */ +#define MAX_SKB_PRIO G_MAXUINT32 +#define MAX_8021P_PRIO 7 /* Max 802.1p priority */ + +/* + * Parse VLAN priority mappings from the following format: 2:1,3:4,7:3 + * and verify if the priority numbers are valid + * + * Return: string array with split maps, or NULL on error + * Caller is responsible for freeing the array. + */ +static char ** +nmc_vlan_parse_priority_maps (const char *priority_map, + NMVlanPriorityMap map_type, + GError **error) +{ + char **mapping = NULL, **iter; + unsigned long from, to, from_max, to_max; + + g_return_val_if_fail (priority_map != NULL, NULL); + g_return_val_if_fail (error == NULL || *error == NULL, NULL); + + if (map_type == NM_VLAN_INGRESS_MAP) { + from_max = MAX_8021P_PRIO; + to_max = MAX_SKB_PRIO; + } else { + from_max = MAX_SKB_PRIO; + to_max = MAX_8021P_PRIO; + } + + mapping = g_strsplit (priority_map, ",", 0); + for (iter = mapping; iter && *iter; iter++) { + char *left, *right; + + left = g_strstrip (*iter); + right = strchr (left, ':'); + if (!right) { + g_set_error (error, 1, 0, _("invalid priority map '%s'"), *iter); + g_strfreev (mapping); + return NULL; + } + *right++ = '\0'; + + if (!nmc_string_to_uint (left, TRUE, 0, from_max, &from)) { + g_set_error (error, 1, 0, _("priority '%s' is not valid (<0-%ld>)"), + left, from_max); + g_strfreev (mapping); + return NULL; + } + if (!nmc_string_to_uint (right, TRUE, 0, to_max, &to)) { + g_set_error (error, 1, 0, _("priority '%s' is not valid (<0-%ld>)"), + right, to_max); + g_strfreev (mapping); + return NULL; + } + *(right-1) = ':'; /* Put back ':' */ + } + return mapping; +} + +/* + * nmc_proxy_check_script: + * @script: file name with PAC script, or raw PAC Script data + * @out_script: raw PAC Script (with removed new-line characters) + * @error: location to store error, or %NULL + * + * Check PAC Script from @script parameter and return the checked/sanitized + * config in @out_script. + * + * Returns: %TRUE if the script is valid, %FALSE if it is invalid + */ +static gboolean +nmc_proxy_check_script (const char *script, char **out_script, GError **error) +{ + enum { + _PAC_SCRIPT_TYPE_GUESS, + _PAC_SCRIPT_TYPE_FILE, + _PAC_SCRIPT_TYPE_JSON, + } desired_type = _PAC_SCRIPT_TYPE_GUESS; + const char *filename = NULL; + size_t c_len = 0; + gs_free char *script_clone = NULL; + + *out_script = NULL; + + if (!script || !script[0]) + return TRUE; + + if (g_str_has_prefix (script, "file://")) { + script += NM_STRLEN ("file://"); + desired_type = _PAC_SCRIPT_TYPE_FILE; + } else if (g_str_has_prefix (script, "js://")) { + script += NM_STRLEN ("js://"); + desired_type = _PAC_SCRIPT_TYPE_JSON; + } + + if (NM_IN_SET (desired_type, _PAC_SCRIPT_TYPE_FILE, _PAC_SCRIPT_TYPE_GUESS)) { + gs_free char *contents = NULL; + + if (!g_file_get_contents (script, &contents, &c_len, NULL)) { + if (desired_type == _PAC_SCRIPT_TYPE_FILE) { + g_set_error (error, NM_UTILS_ERROR, NM_UTILS_ERROR_INVALID_ARGUMENT, + _("cannot read pac-script from file '%s'"), + script); + return FALSE; + } + } else { + if (c_len != strlen (contents)) { + g_set_error (error, NM_UTILS_ERROR, NM_UTILS_ERROR_INVALID_ARGUMENT, + _("file '%s' contains non-valid utf-8"), + script); + return FALSE; + } + filename = script; + script = script_clone = g_steal_pointer (&contents); + } + } + + if ( !strstr (script, "FindProxyForURL") + || !g_utf8_validate (script, -1, NULL)) { + if (filename) { + g_set_error (error, NM_UTILS_ERROR, NM_UTILS_ERROR_INVALID_ARGUMENT, + _("'%s' does not contain a valid PAC Script"), filename); + } else { + g_set_error (error, NM_UTILS_ERROR, NM_UTILS_ERROR_INVALID_ARGUMENT, + _("Not a valid PAC Script")); + } + return FALSE; + } + + *out_script = (script == script_clone) + ? g_steal_pointer (&script_clone) + : g_strdup (script); + return TRUE; +} + +const char * +nmc_bond_validate_mode (const char *mode, GError **error) +{ + unsigned long mode_int; + static const char *valid_modes[] = { "balance-rr", + "active-backup", + "balance-xor", + "broadcast", + "802.3ad", + "balance-tlb", + "balance-alb", + NULL }; + if (nmc_string_to_uint (mode, TRUE, 0, 6, &mode_int)) { + /* Translate bonding mode numbers to mode names: + * https://www.kernel.org/doc/Documentation/networking/bonding.txt + */ + return valid_modes[mode_int]; + } else + return nmc_string_is_valid (mode, valid_modes, error); +} + +/* + * nmc_team_check_config: + * @config: file name with team config, or raw team JSON config data + * @out_config: raw team JSON config data + * The value must be freed with g_free(). + * @error: location to store error, or %NUL + * + * Check team config from @config parameter and return the checked + * config in @out_config. + * + * Returns: %TRUE if the config is valid, %FALSE if it is invalid + */ +static gboolean +nmc_team_check_config (const char *config, char **out_config, GError **error) +{ + enum { + _TEAM_CONFIG_TYPE_GUESS, + _TEAM_CONFIG_TYPE_FILE, + _TEAM_CONFIG_TYPE_JSON, + } desired_type = _TEAM_CONFIG_TYPE_GUESS; + const char *filename = NULL; + size_t c_len = 0; + gs_free char *config_clone = NULL; + + *out_config = NULL; + + if (!config || !config[0]) + return TRUE; + + if (g_str_has_prefix (config, "file://")) { + config += NM_STRLEN ("file://"); + desired_type = _TEAM_CONFIG_TYPE_FILE; + } else if (g_str_has_prefix (config, "json://")) { + config += NM_STRLEN ("json://"); + desired_type = _TEAM_CONFIG_TYPE_JSON; + } + + if (NM_IN_SET (desired_type, _TEAM_CONFIG_TYPE_FILE, _TEAM_CONFIG_TYPE_GUESS)) { + gs_free char *contents = NULL; + + if (!g_file_get_contents (config, &contents, &c_len, NULL)) { + if (desired_type == _TEAM_CONFIG_TYPE_FILE) { + g_set_error (error, NM_UTILS_ERROR, NM_UTILS_ERROR_INVALID_ARGUMENT, + _("cannot read team config from file '%s'"), + config); + return FALSE; + } + } else { + if (c_len != strlen (contents)) { + g_set_error (error, NM_UTILS_ERROR, NM_UTILS_ERROR_INVALID_ARGUMENT, + _("team config file '%s' contains non-valid utf-8"), + config); + return FALSE; + } + filename = config; + config = config_clone = g_steal_pointer (&contents); + } + } + + if (!nm_utils_is_json_object (config, NULL)) { + if (filename) { + g_set_error (error, NM_UTILS_ERROR, NM_UTILS_ERROR_INVALID_ARGUMENT, + _("'%s' does not contain a valid team configuration"), filename); + } else { + g_set_error (error, NM_UTILS_ERROR, NM_UTILS_ERROR_INVALID_ARGUMENT, + _("team configuration must be a JSON object")); + } + return FALSE; + } + + *out_config = (config == config_clone) + ? g_steal_pointer (&config_clone) + : g_strdup (config); + return TRUE; +} + +/*****************************************************************************/ + +#define ARGS_DESCRIBE_FCN \ + const NMMetaSettingInfoEditor *setting_info, const NMMetaPropertyInfo *property_info, char **out_to_free + +#define ARGS_GET_FCN \ + const NMMetaSettingInfoEditor *setting_info, const NMMetaPropertyInfo *property_info, NMSetting *setting, NMMetaAccessorGetType get_type, gboolean show_secrets + +#define ARGS_SET_FCN \ + const NMMetaSettingInfoEditor *setting_info, const NMMetaPropertyInfo *property_info, NMSetting *setting, const char *value, GError **error + +#define ARGS_REMOVE_FCN \ + const NMMetaSettingInfoEditor *setting_info, const NMMetaPropertyInfo *property_info, NMSetting *setting, const char *value, guint32 idx, GError **error + +#define ARGS_VALUES_FCN \ + const NMMetaSettingInfoEditor *setting_info, const NMMetaPropertyInfo *property_info, char ***out_to_free + +static char * +_get_fcn_name (ARGS_GET_FCN) +{ + nm_assert (nm_streq0 (nm_setting_get_name (setting), setting_info->general->setting_name)); + return g_strdup (setting_info->general->setting_name); +} + +static char * +_get_fcn_nmc_with_default (ARGS_GET_FCN) +{ + const char *s; + char *s_full; + GValue val = G_VALUE_INIT; + + if (property_info->property_typ_data->subtype.get_with_default.fcn (setting)) { + if (get_type == NM_META_ACCESSOR_GET_TYPE_PARSABLE) + return g_strdup (""); + return g_strdup (_("(default)")); + } + + g_value_init (&val, G_TYPE_STRING); + g_object_get_property (G_OBJECT (setting), property_info->property_name, &val); + s = g_value_get_string (&val); + if (get_type == NM_META_ACCESSOR_GET_TYPE_PARSABLE) + s_full = g_strdup (s && *s ? s : " "); + else + s_full = s ? g_strdup_printf ("\"%s\"", s) : g_strdup (""); + g_value_unset (&val); + return s_full; +} + +static char * +_get_fcn_gobject (ARGS_GET_FCN) +{ + char *s; + GValue val = G_VALUE_INIT; + + g_value_init (&val, G_TYPE_STRING); + g_object_get_property (G_OBJECT (setting), property_info->property_name, &val); + s = g_value_dup_string (&val); + g_value_unset (&val); + return s; +} + +static char * +_get_fcn_gobject_mtu (ARGS_GET_FCN) +{ + guint32 mtu; + + if ( !property_info->property_typ_data + || !property_info->property_typ_data->subtype.mtu.get_fcn) + return _get_fcn_gobject (setting_info, property_info, setting, get_type, show_secrets); + + mtu = property_info->property_typ_data->subtype.mtu.get_fcn (setting); + if (mtu == 0) { + if (get_type == NM_META_ACCESSOR_GET_TYPE_PARSABLE) + return g_strdup ("auto"); + else + return g_strdup (_("auto")); + } + return g_strdup_printf ("%u", (unsigned) mtu); +} + +static char * +_get_fcn_gobject_secret_flags (ARGS_GET_FCN) +{ + guint v; + GValue val = G_VALUE_INIT; + + g_value_init (&val, G_TYPE_UINT); + g_object_get_property (G_OBJECT (setting), property_info->property_name, &val); + v = g_value_get_uint (&val); + g_value_unset (&val); + return secret_flags_to_string (v, get_type); +} + +static char * +_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; + gboolean has_gtype = FALSE; + nm_auto_unset_gvalue GValue gval = G_VALUE_INIT; + gint64 v; + gboolean format_numeric = FALSE; + gboolean format_numeric_hex = FALSE; + gboolean format_numeric_hex_unknown = FALSE; + gboolean format_text = FALSE; + gboolean format_text_l10n = FALSE; + gs_free char *s = NULL; + char s_numeric[64]; + + if (property_info->property_typ_data) { + if (property_info->property_typ_data->subtype.gobject_enum.get_gtype) { + gtype = property_info->property_typ_data->subtype.gobject_enum.get_gtype (); + has_gtype = TRUE; + } + } + + if ( property_info->property_typ_data + && get_type == NM_META_ACCESSOR_GET_TYPE_PRETTY + && NM_FLAGS_ANY (property_info->property_typ_data->typ_flags, NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PRETTY_NUMERIC + | NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PRETTY_NUMERIC_HEX + | NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PRETTY_TEXT + | NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PRETTY_TEXT_L10N)) { + format_numeric_hex = NM_FLAGS_HAS (property_info->property_typ_data->typ_flags, NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PRETTY_NUMERIC_HEX); + format_numeric = format_numeric_hex || NM_FLAGS_HAS (property_info->property_typ_data->typ_flags, NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PRETTY_NUMERIC); + format_text_l10n = NM_FLAGS_HAS (property_info->property_typ_data->typ_flags, NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PRETTY_TEXT_L10N); + format_text = format_text_l10n || NM_FLAGS_HAS (property_info->property_typ_data->typ_flags, NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PRETTY_TEXT); + } else if ( property_info->property_typ_data + && get_type == NM_META_ACCESSOR_GET_TYPE_PARSABLE + && NM_FLAGS_ANY (property_info->property_typ_data->typ_flags, NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PARSABLE_NUMERIC + | NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PARSABLE_NUMERIC_HEX + | NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PARSABLE_TEXT)) { + format_numeric_hex = NM_FLAGS_HAS (property_info->property_typ_data->typ_flags, NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PARSABLE_NUMERIC_HEX); + format_numeric = format_numeric && NM_FLAGS_HAS (property_info->property_typ_data->typ_flags, NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PARSABLE_NUMERIC); + format_text = NM_FLAGS_HAS (property_info->property_typ_data->typ_flags, NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PARSABLE_TEXT); + } else if (get_type == NM_META_ACCESSOR_GET_TYPE_PRETTY) { + /* by default, output in format "%u (%s)" (with hex for flags and l10n). */ + format_numeric = TRUE; + format_numeric_hex_unknown = TRUE; + format_text = TRUE; + format_text_l10n = TRUE; + } else { + /* by default, output only numeric (with hex for flags). */ + format_numeric = TRUE; + format_numeric_hex_unknown = TRUE; + } + + 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); + + g_object_get_property (G_OBJECT (setting), property_info->property_name, &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 (!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) { + if (!has_gtype) + g_return_val_if_reached (NULL); + v = g_value_get_uint (&gval); + } else + v = g_value_get_flags (&gval); + } else + g_return_val_if_reached (NULL); + + if (!has_gtype) { + gtype = gtype_prop; + gtype_class = g_steal_pointer (>ype_prop_class); + } + + nm_assert (({ + nm_auto_unref_gtypeclass GTypeClass *t = NULL; + + ( G_TYPE_IS_CLASSED (gtype) + && (t = g_type_class_ref (gtype)) + && (G_IS_ENUM_CLASS (t) || G_IS_FLAGS_CLASS (t))); + })); + + if (format_numeric && !format_text) { + return format_numeric_hex + || ( format_numeric_hex_unknown + && !G_IS_ENUM_CLASS (gtype_class ?: (gtype_class = g_type_class_ref (gtype)))) + ? g_strdup_printf ("0x%"G_GINT64_FORMAT, v) + : g_strdup_printf ("%"G_GINT64_FORMAT, v); + } + + /* 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 (!format_numeric) + return g_steal_pointer (&s); + + if ( format_numeric_hex + || ( format_numeric_hex_unknown + && !G_IS_ENUM_CLASS (gtype_class ?: (gtype_class = g_type_class_ref (gtype))))) + nm_sprintf_buf (s_numeric, "0x%"G_GINT64_FORMAT, v); + else + nm_sprintf_buf (s_numeric, "%"G_GINT64_FORMAT, v); + + if (nm_streq0 (s, s_numeric)) + return g_steal_pointer (&s); + + if (format_text_l10n) + return g_strdup_printf (_("%s (%s)"), s_numeric, s); + else + return g_strdup_printf ("%s (%s)", s_numeric, s); +} + +/*****************************************************************************/ + +static gboolean +_set_fcn_gobject_string (ARGS_SET_FCN) +{ + if ( property_info->property_typ_data + && property_info->property_typ_data->values_static) { + value = nmc_string_is_valid (value, + (const char **) property_info->property_typ_data->values_static, + error); + if (!value) + return FALSE; + } + g_object_set (setting, property_info->property_name, value, NULL); + return TRUE; +} + +static gboolean +_set_fcn_gobject_bool (ARGS_SET_FCN) +{ + gboolean val_bool; + + if (!nmc_string_to_bool (value, &val_bool, error)) + return FALSE; + + g_object_set (setting, property_info->property_name, val_bool, NULL); + return TRUE; +} + +static gboolean +_set_fcn_gobject_trilean (ARGS_SET_FCN) +{ + long int val_int; + + g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + + if (!nmc_string_to_int (value, TRUE, -1, 1, &val_int)) { + g_set_error (error, 1, 0, _("'%s' is not a valid value; use -1, 0 or 1"), value); + return FALSE; + } + + g_object_set (setting, property_info->property_name, val_int, NULL); + return TRUE; +} + +static gboolean +_set_fcn_gobject_int (ARGS_SET_FCN) +{ + long int val_int; + + if (!nmc_string_to_int (value, TRUE, G_MININT, G_MAXINT, &val_int)) { + g_set_error (error, 1, 0, _("'%s' is not a valid number (or out of range)"), value); + return FALSE; + } + + /* Validate the number according to the property spec */ + if (!validate_int (setting, property_info->property_name, (gint) val_int, error)) + return FALSE; + + g_object_set (setting, property_info->property_name, (gint) val_int, NULL); + return TRUE; +} + +static gboolean +_set_fcn_gobject_int64 (ARGS_SET_FCN) +{ + long val_int; + + g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + + if (!nmc_string_to_int (value, FALSE, 0, 0, &val_int)) { + g_set_error (error, 1, 0, _("'%s' is not a valid number (or out of range)"), value); + return FALSE; + } + + /* Validate the number according to the property spec */ + if (!validate_int64 (setting, property_info->property_name, (gint64) val_int, error)) + return FALSE; + + g_object_set (setting, property_info->property_name, (gint64) val_int, NULL); + return TRUE; +} + +static gboolean +_set_fcn_gobject_uint (ARGS_SET_FCN) +{ + unsigned long val_int; + + g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + + 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); + return FALSE; + } + + /* Validate the number according to the property spec */ + if (!validate_uint (setting, property_info->property_name, (guint) val_int, error)) + return FALSE; + + g_object_set (setting, property_info->property_name, (guint) val_int, NULL); + return TRUE; +} + +static gboolean +_set_fcn_gobject_mtu (ARGS_SET_FCN) +{ + if (nm_streq0 (value, "auto")) + value = "0"; + return _set_fcn_gobject_uint (setting_info, property_info, setting, value, error); +} + +static gboolean +_set_fcn_gobject_mac (ARGS_SET_FCN) +{ + NMMetaPropertyTypeMacMode mode; + gboolean valid; + + if (property_info->property_typ_data) + mode = property_info->property_typ_data->subtype.mac.mode; + 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 { + valid = nm_utils_hwaddr_valid (value, ETH_ALEN) + || ( mode == NM_META_PROPERTY_TYPE_MAC_MODE_CLONED + && NM_CLONED_MAC_IS_SPECIAL (value)); + } + + if (!valid) { + g_set_error (error, 1, 0, _("'%s' is not a valid Ethernet MAC"), value); + return FALSE; + } + + g_object_set (setting, property_info->property_name, value, NULL); + return TRUE; +} + +static gboolean +_set_fcn_gobject_secret_flags (ARGS_SET_FCN) +{ + char **strv = NULL, **iter; + unsigned long flags = 0, val_int; + + g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + + strv = nmc_strsplit_set (value, " \t,", 0); + for (iter = strv; iter && *iter; iter++) { + if (!nmc_string_to_uint (*iter, TRUE, 0, ALL_SECRET_FLAGS, &val_int)) { + g_set_error (error, 1, 0, _("'%s' is not a valid flag number; use <0-%d>"), + *iter, ALL_SECRET_FLAGS); + g_strfreev (strv); + return FALSE; + } + flags += val_int; + } + g_strfreev (strv); + + /* Validate the flags number */ + if (flags > ALL_SECRET_FLAGS) { + flags = ALL_SECRET_FLAGS; + g_print (_("Warning: '%s' sum is higher than all flags => all flags set\n"), 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; + GType gtype_prop; + gboolean has_gtype = FALSE; + nm_auto_unset_gvalue GValue gval = G_VALUE_INIT; + int v; + + if (property_info->property_typ_data) { + if (property_info->property_typ_data->subtype.gobject_enum.get_gtype) { + gtype = property_info->property_typ_data->subtype.gobject_enum.get_gtype (); + has_gtype = TRUE; + } + } + + gtype_prop = _gobject_property_get_gtype (G_OBJECT (setting), property_info->property_name); + + if ( gtype_prop == G_TYPE_INT + || G_IS_ENUM_CLASS (gtype_prop)) { + if (gtype_prop == G_TYPE_INT) { + if (!has_gtype) + g_return_val_if_reached (FALSE); + } + } else if ( gtype_prop == G_TYPE_UINT + || G_IS_FLAGS_CLASS (gtype_prop)) { + if (gtype_prop == G_TYPE_UINT) { + if (!has_gtype) + g_return_val_if_reached (FALSE); + } + } else + g_return_val_if_reached (FALSE); + + if (!has_gtype) + gtype = gtype_prop; + + if (!_nm_utils_enum_from_str_full (gtype, value, &v, NULL, + property_info->property_typ_data + ? property_info->property_typ_data->subtype.gobject_enum.value_infos + : NULL)) + goto fail; + + g_value_init (&gval, gtype_prop); + if ( gtype_prop == G_TYPE_INT + || G_IS_ENUM_CLASS (gtype_prop)) { + if (gtype_prop == G_TYPE_INT) + g_value_set_int (&gval, v); + else + g_value_set_enum (&gval, v); + } else if ( gtype_prop == G_TYPE_UINT + || G_IS_FLAGS_CLASS (gtype_prop)) { + if (gtype_prop == G_TYPE_UINT) + g_value_set_uint (&gval, v); + else + g_value_set_flags (&gval, v); + } + if (!nm_g_object_set_property (G_OBJECT (setting), property_info->property_name, &gval, NULL)) + goto fail; + + return TRUE; + +fail: + if (error) { + gs_free const char **valid_all = NULL; + gs_free const char *valid_str = NULL; + int min = G_MININT; + int max = G_MAXINT; + + if (property_info->property_typ_data) { + if ( property_info->property_typ_data->subtype.gobject_enum.min + || property_info->property_typ_data->subtype.gobject_enum.max) { + min = property_info->property_typ_data->subtype.gobject_enum.min; + max = property_info->property_typ_data->subtype.gobject_enum.max; + } + } + + valid_all = nm_utils_enum_get_values (gtype, min, max); + valid_str = g_strjoinv (",", (char **) valid_all); + g_set_error (error, NM_UTILS_ERROR, NM_UTILS_ERROR_INVALID_ARGUMENT, + _("invalid option '%s', use one of [%s]"), + value, + valid_str); + } + return FALSE; +} + +/*****************************************************************************/ + +static const char *const* +_values_fcn_gobject_enum (ARGS_VALUES_FCN) +{ + GType gtype = 0; + gboolean has_gtype = FALSE; + int min = G_MININT; + int max = G_MAXINT; + char **v, **w; + + if (property_info->property_typ_data) { + if ( property_info->property_typ_data->subtype.gobject_enum.min + || property_info->property_typ_data->subtype.gobject_enum.max) { + min = property_info->property_typ_data->subtype.gobject_enum.min; + max = property_info->property_typ_data->subtype.gobject_enum.max; + } + if (property_info->property_typ_data->subtype.gobject_enum.get_gtype) { + gtype = property_info->property_typ_data->subtype.gobject_enum.get_gtype (); + has_gtype = TRUE; + } + } + + if (!has_gtype) { + gtype = _gtype_property_get_gtype (setting_info->general->get_setting_gtype (), + property_info->property_name); + } + + /* 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); + } + return (const char *const*) (*out_to_free = v); +} + +/*****************************************************************************/ + +static char * +wep_key_type_to_string (NMWepKeyType type) +{ + switch (type) { + case NM_WEP_KEY_TYPE_KEY: + return g_strdup_printf (_("%d (key)"), type); + case NM_WEP_KEY_TYPE_PASSPHRASE: + return g_strdup_printf (_("%d (passphrase)"), type); + case NM_WEP_KEY_TYPE_UNKNOWN: + default: + return g_strdup_printf (_("%d (unknown)"), type); + } +} + +static char * +bytes_to_string (GBytes *bytes) +{ + const guint8 *data; + gsize len; + GString *cert = NULL; + int i; + + if (!bytes) + return NULL; + data = g_bytes_get_data (bytes, &len); + + cert = g_string_new (NULL); + for (i = 0; i < len; i++) + g_string_append_printf (cert, "%02X", data[i]); + + return g_string_free (cert, FALSE); +} + +static char * +vlan_flags_to_string (guint32 flags, NMMetaAccessorGetType get_type) +{ + GString *flag_str; + + if (get_type == NM_META_ACCESSOR_GET_TYPE_PARSABLE) + return g_strdup_printf ("%u", flags); + + if (flags == 0) + return g_strdup (_("0 (NONE)")); + + flag_str = g_string_new (NULL); + g_string_printf (flag_str, "%d (", flags); + + if (flags & NM_VLAN_FLAG_REORDER_HEADERS) + g_string_append (flag_str, _("REORDER_HEADERS, ")); + if (flags & NM_VLAN_FLAG_GVRP) + g_string_append (flag_str, _("GVRP, ")); + if (flags & NM_VLAN_FLAG_LOOSE_BINDING) + g_string_append (flag_str, _("LOOSE_BINDING, ")); + if (flags & NM_VLAN_FLAG_MVRP) + g_string_append (flag_str, _("MVRP, ")); + + if (flag_str->str[flag_str->len-1] == '(') + g_string_append (flag_str, _("unknown")); + else + g_string_truncate (flag_str, flag_str->len-2); /* chop off trailing ', ' */ + + g_string_append_c (flag_str, ')'); + + return g_string_free (flag_str, FALSE); +} + +static char * +vlan_priorities_to_string (NMSettingVlan *s_vlan, NMVlanPriorityMap map) +{ + GString *priorities; + int i; + + priorities = g_string_new (NULL); + for (i = 0; i < nm_setting_vlan_get_num_priorities (s_vlan, map); i++) { + guint32 from, to; + + if (nm_setting_vlan_get_priority (s_vlan, map, i, &from, &to)) + g_string_append_printf (priorities, "%d:%d,", from, to); + } + if (priorities->len) + g_string_truncate (priorities, priorities->len-1); /* chop off trailing ',' */ + + return g_string_free (priorities, FALSE); +} + +static char * +ip6_privacy_to_string (NMSettingIP6ConfigPrivacy ip6_privacy, NMMetaAccessorGetType get_type) +{ + if (get_type == NM_META_ACCESSOR_GET_TYPE_PARSABLE) + 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 * +autoconnect_slaves_to_string (NMSettingConnectionAutoconnectSlaves autoconnect_slaves, + NMMetaAccessorGetType get_type) +{ + if (get_type == NM_META_ACCESSOR_GET_TYPE_PARSABLE) + return g_strdup_printf ("%d", autoconnect_slaves); + + switch (autoconnect_slaves) { + case NM_SETTING_CONNECTION_AUTOCONNECT_SLAVES_NO: + return g_strdup_printf (_("%d (no)"), autoconnect_slaves); + case NM_SETTING_CONNECTION_AUTOCONNECT_SLAVES_YES: + return g_strdup_printf (_("%d (yes)"), autoconnect_slaves); + case NM_SETTING_CONNECTION_AUTOCONNECT_SLAVES_DEFAULT: + default: + return g_strdup_printf (_("%d (default)"), autoconnect_slaves); + } +} + +static char * +secret_flags_to_string (guint32 flags, NMMetaAccessorGetType get_type) +{ + GString *flag_str; + + if (get_type == NM_META_ACCESSOR_GET_TYPE_PARSABLE) + return g_strdup_printf ("%u", flags); + + if (flags == 0) + return g_strdup (_("0 (none)")); + + flag_str = g_string_new (NULL); + g_string_printf (flag_str, "%u (", flags); + + if (flags & NM_SETTING_SECRET_FLAG_AGENT_OWNED) + g_string_append (flag_str, _("agent-owned, ")); + if (flags & NM_SETTING_SECRET_FLAG_NOT_SAVED) + g_string_append (flag_str, _("not saved, ")); + if (flags & NM_SETTING_SECRET_FLAG_NOT_REQUIRED) + g_string_append (flag_str, _("not required, ")); + + if (flag_str->str[flag_str->len-1] == '(') + g_string_append (flag_str, _("unknown")); + else + g_string_truncate (flag_str, flag_str->len-2); /* chop off trailing ', ' */ + + g_string_append_c (flag_str, ')'); + + return g_string_free (flag_str, FALSE); +} + +static void +vpn_data_item (const char *key, const char *value, gpointer user_data) +{ + GString *ret_str = (GString *) user_data; + + if (ret_str->len != 0) + g_string_append (ret_str, ", "); + + g_string_append_printf (ret_str, "%s = %s", key, value); +} + +#define DEFINE_SETTER_STR_LIST_MULTI(def_func, s_macro, set_func) \ + static gboolean \ + def_func (NMSetting *setting, \ + const char *prop, \ + const char *value, \ + const char **valid_strv, \ + GError **error) \ + { \ + char **strv = NULL, **iter; \ + 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; \ + } \ + set_func (s_macro (setting), item); \ + } \ + g_strfreev (strv); \ + return TRUE; \ + } + +#define DEFINE_SETTER_OPTIONS(def_func, s_macro, s_type, add_func, valid_func1, valid_func2) \ + static gboolean \ + def_func (ARGS_SET_FCN) \ + { \ + char **strv = NULL, **iter; \ + const char **(*valid_func1_p) (s_type *) = valid_func1; \ + const char * (*valid_func2_p) (const char *, const char *, GError **) = valid_func2; \ + const char *opt_name, *opt_val; \ + \ + g_return_val_if_fail (error == NULL || *error == NULL, FALSE); \ + \ + strv = nmc_strsplit_set (value, ",", 0); \ + for (iter = strv; iter && *iter; iter++) { \ + char *left = g_strstrip (*iter); \ + 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'; \ + \ + 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); \ + return FALSE; \ + } \ + } else \ + opt_name = g_strstrip (left);\ + \ + opt_val = g_strstrip (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; \ + } + +#define DEFINE_REMOVER_INDEX_OR_VALUE(def_func, s_macro, num_func, rem_func_idx, rem_func_val) \ + static gboolean \ + def_func (ARGS_REMOVE_FCN) \ + { \ + guint32 num; \ + if (value) { \ + gboolean ret; \ + char *value_stripped = g_strstrip (g_strdup (value)); \ + ret = rem_func_val (s_macro (setting), value_stripped, error); \ + g_free (value_stripped); \ + return ret; \ + } \ + num = num_func (s_macro (setting)); \ + if (num == 0) { \ + g_set_error_literal (error, 1, 0, _("no item to remove")); \ + return FALSE; \ + } \ + if (idx >= num) { \ + g_set_error (error, 1, 0, _("index '%d' is not in range <0-%d>"), idx, num - 1); \ + return FALSE; \ + } \ + rem_func_idx (s_macro (setting), idx); \ + return TRUE; \ + } + +#define DEFINE_REMOVER_OPTION(def_func, s_macro, rem_func) \ + static gboolean \ + def_func (ARGS_REMOVE_FCN) \ + { \ + gboolean success = FALSE; \ + if (value && *value) { \ + success = rem_func (s_macro (setting), value); \ + if (!success) \ + g_set_error (error, 1, 0, _("invalid option '%s'"), value); \ + } else \ + g_set_error_literal (error, 1, 0, _("missing option")); \ + return success; \ + } + +#define DEFINE_ALLOWED_VAL_FUNC(def_func, valid_values) \ + static const char *const* \ + def_func (NMSetting *setting, const char *prop) \ + { \ + return valid_values; \ + } + +#define DEFINE_SETTER_MAC_BLACKLIST(def_func, s_macro, add_func) \ + static gboolean \ + def_func (ARGS_SET_FCN) \ + { \ + guint8 buf[32]; \ + char **list = NULL, **iter; \ + GSList *macaddr_blacklist = NULL; \ + \ + g_return_val_if_fail (error == NULL || *error == NULL, FALSE); \ + \ + list = nmc_strsplit_set (value, " \t,", 0); \ + for (iter = list; iter && *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++) \ + add_func (s_macro (setting), *iter); \ + \ + g_strfreev (list); \ + return TRUE; \ + } + + +static gboolean +verify_string_list (char **strv, + const char *prop, + gboolean (*validate_func) (const char *), + GError **error) +{ + char **iter; + + g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + + 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; + } + } + } + return TRUE; +} + +static gboolean +validate_int (NMSetting *setting, const char* prop, gint val, GError **error) +{ + GParamSpec *pspec; + GValue value = G_VALUE_INIT; + gboolean success = TRUE; + + g_value_init (&value, G_TYPE_INT); + g_value_set_int (&value, val); + pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (G_OBJECT (setting)), prop); + g_assert (G_IS_PARAM_SPEC (pspec)); + if (g_param_value_validate (pspec, &value)) { + GParamSpecInt *pspec_int = (GParamSpecInt *) pspec; + g_set_error (error, 1, 0, _("'%d' is not valid; use <%d-%d>"), + val, pspec_int->minimum, pspec_int->maximum); + success = FALSE; + } + g_value_unset (&value); + return success; +} + +static gboolean +validate_int64 (NMSetting *setting, const char* prop, gint64 val, GError **error) +{ + GParamSpec *pspec; + GValue value = G_VALUE_INIT; + gboolean success = TRUE; + + g_value_init (&value, G_TYPE_INT64); + g_value_set_int64 (&value, val); + pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (G_OBJECT (setting)), prop); + g_assert (G_IS_PARAM_SPEC (pspec)); + if (g_param_value_validate (pspec, &value)) { + GParamSpecInt64 *pspec_int = (GParamSpecInt64 *) pspec; + G_STATIC_ASSERT (sizeof (long long) >= sizeof (gint64)); + g_set_error (error, 1, 0, _("'%lld' is not valid; use <%lld-%lld>"), + (long long) val, (long long) pspec_int->minimum, (long long) pspec_int->maximum); + success = FALSE; + } + g_value_unset (&value); + return success; +} + +static gboolean +validate_uint (NMSetting *setting, const char* prop, guint val, GError **error) +{ + GParamSpec *pspec; + GValue value = G_VALUE_INIT; + gboolean success = TRUE; + + g_value_init (&value, G_TYPE_UINT); + g_value_set_uint (&value, val); + pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (G_OBJECT (setting)), prop); + g_assert (G_IS_PARAM_SPEC (pspec)); + if (g_param_value_validate (pspec, &value)) { + GParamSpecUInt *pspec_uint = (GParamSpecUInt *) pspec; + g_set_error (error, 1, 0, _("'%u' is not valid; use <%u-%u>"), + val, pspec_uint->minimum, pspec_uint->maximum); + success = FALSE; + } + g_value_unset (&value); + return success; +} + +static char * +flag_values_to_string (GFlagsValue *array, guint n) +{ + GString *str; + guint i; + + str = g_string_new (NULL); + for (i = 0; i < n; i++) + g_string_append_printf (str, "%u, ", array[i].value); + if (str->len) + g_string_truncate (str, str->len-2); /* chop off trailing ', ' */ + return g_string_free (str, FALSE); +} + +static gboolean +validate_flags (NMSetting *setting, const char* prop, guint val, GError **error) +{ + GParamSpec *pspec; + GValue value = G_VALUE_INIT; + gboolean success = TRUE; + + pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (G_OBJECT (setting)), prop); + g_assert (G_IS_PARAM_SPEC (pspec)); + + g_value_init (&value, pspec->value_type); + g_value_set_flags (&value, val); + + if (g_param_value_validate (pspec, &value)) { + GParamSpecFlags *pspec_flags = (GParamSpecFlags *) pspec; + char *flag_values = flag_values_to_string (pspec_flags->flags_class->values, + pspec_flags->flags_class->n_values); + g_set_error (error, 1, 0, _("'%u' flags are not valid; use combination of %s"), + val, flag_values); + g_free (flag_values); + success = FALSE; + } + g_value_unset (&value); + return success; +} + +static gboolean +check_and_set_string (NMSetting *setting, + const char *prop, + const char *val, + const char **valid_strv, + GError **error) +{ + const char *checked_val; + + g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + + checked_val = nmc_string_is_valid (val, valid_strv, error); + if (!checked_val) + return FALSE; + + g_object_set (setting, prop, checked_val, NULL); + return TRUE; +} + +static gboolean +_set_fcn_gobject_flags (ARGS_SET_FCN) +{ + unsigned long val_int; + + g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + + 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); + return FALSE; + } + + /* Validate the flags according to the property spec */ + if (!validate_flags (setting, property_info->property_name, (guint) val_int, error)) + return FALSE; + + g_object_set (setting, property_info->property_name, (guint) val_int, NULL); + return TRUE; +} + +static gboolean +_set_fcn_gobject_ssid (ARGS_SET_FCN) +{ + GBytes *ssid; + + g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + + if (strlen (value) > 32) { + g_set_error (error, 1, 0, _("'%s' is not valid"), value); + return FALSE; + } + + ssid = g_bytes_new (value, strlen (value)); + g_object_set (setting, property_info->property_name, ssid, NULL); + g_bytes_unref (ssid); + return TRUE; +} + +static gboolean +_set_fcn_gobject_ifname (ARGS_SET_FCN) +{ + g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + + if (!nm_utils_is_valid_iface_name (value, error)) + return FALSE; + g_object_set (setting, property_info->property_name, value, NULL); + return TRUE; +} + +static gboolean +_set_fcn_vpn_service_type (ARGS_SET_FCN) +{ + gs_free char *service_name = NULL; + + service_name = nm_vpn_plugin_info_list_find_service_type (nm_vpn_get_plugin_infos (), value); + g_object_set (setting, property_info->property_name, service_name ? : value, NULL); + return TRUE; +} + +static gboolean +nmc_util_is_domain (const char *domain) +{ + //FIXME: implement + return TRUE; +} + +static gboolean +nmc_property_set_byte_array (NMSetting *setting, const char *prop, const char *value, GError **error) +{ + char **strv = NULL, **iter; + char *val_strip; + const char *delimiters = " \t,"; + long int val_int; + GBytes *bytes; + GByteArray *array = NULL; + gboolean success = TRUE; + + g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + + val_strip = g_strstrip (g_strdup (value)); + + /* First try hex string in the format of AAbbCCDd */ + bytes = nm_utils_hexstr2bin (val_strip); + if (bytes) { + array = g_bytes_unref_to_array (bytes); + 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)); + for (iter = strv; iter && *iter; iter++) { + if (!nmc_string_to_int_base (g_strstrip (*iter), 16, TRUE, 0, 255, &val_int)) { + g_set_error (error, 1, 0, _("'%s' is not a valid hex character"), *iter); + success = FALSE; + goto done; + } + g_byte_array_append (array, (const guint8 *) &val_int, 1); + } + +done: + if (success) + g_object_set (setting, prop, array, NULL); + + g_strfreev (strv); + if (array) + g_byte_array_free (array, TRUE); + return success; +} + +/*****************************************************************************/ + +static char * +_get_fcn_802_1x_ca_cert (ARGS_GET_FCN) +{ + NMSetting8021x *s_8021X = NM_SETTING_802_1X (setting); + char *ca_cert_str = NULL; + + switch (nm_setting_802_1x_get_ca_cert_scheme (s_8021X)) { + case NM_SETTING_802_1X_CK_SCHEME_BLOB: + ca_cert_str = bytes_to_string (nm_setting_802_1x_get_ca_cert_blob (s_8021X)); + break; + case NM_SETTING_802_1X_CK_SCHEME_PATH: + ca_cert_str = g_strdup (nm_setting_802_1x_get_ca_cert_path (s_8021X)); + break; + case NM_SETTING_802_1X_CK_SCHEME_PKCS11: + ca_cert_str = g_strdup (nm_setting_802_1x_get_ca_cert_uri (s_8021X)); + break; + case NM_SETTING_802_1X_CK_SCHEME_UNKNOWN: + break; + } + + return ca_cert_str; +} + +static char * +_get_fcn_802_1x_client_cert (ARGS_GET_FCN) +{ + NMSetting8021x *s_8021X = NM_SETTING_802_1X (setting); + char *cert_str = NULL; + + switch (nm_setting_802_1x_get_client_cert_scheme (s_8021X)) { + case NM_SETTING_802_1X_CK_SCHEME_BLOB: + if (show_secrets) + cert_str = bytes_to_string (nm_setting_802_1x_get_client_cert_blob (s_8021X)); + else + cert_str = g_strdup (_(NM_META_TEXT_HIDDEN)); + break; + case NM_SETTING_802_1X_CK_SCHEME_PATH: + cert_str = g_strdup (nm_setting_802_1x_get_client_cert_path (s_8021X)); + break; + case NM_SETTING_802_1X_CK_SCHEME_PKCS11: + cert_str = g_strdup (nm_setting_802_1x_get_client_cert_uri (s_8021X)); + break; + case NM_SETTING_802_1X_CK_SCHEME_UNKNOWN: + break; + } + + return cert_str; +} + +static char * +_get_fcn_802_1x_phase2_ca_cert (ARGS_GET_FCN) +{ + NMSetting8021x *s_8021X = NM_SETTING_802_1X (setting); + char *phase2_ca_cert_str = NULL; + + switch (nm_setting_802_1x_get_phase2_ca_cert_scheme (s_8021X)) { + case NM_SETTING_802_1X_CK_SCHEME_BLOB: + phase2_ca_cert_str = bytes_to_string (nm_setting_802_1x_get_phase2_ca_cert_blob (s_8021X)); + break; + case NM_SETTING_802_1X_CK_SCHEME_PATH: + phase2_ca_cert_str = g_strdup (nm_setting_802_1x_get_phase2_ca_cert_path (s_8021X)); + break; + case NM_SETTING_802_1X_CK_SCHEME_PKCS11: + phase2_ca_cert_str = g_strdup (nm_setting_802_1x_get_phase2_ca_cert_uri (s_8021X)); + break; + case NM_SETTING_802_1X_CK_SCHEME_UNKNOWN: + break; + } + + return phase2_ca_cert_str; +} + +static char * +_get_fcn_802_1x_phase2_client_cert (ARGS_GET_FCN) +{ + NMSetting8021x *s_8021X = NM_SETTING_802_1X (setting); + char *cert_str = NULL; + + switch (nm_setting_802_1x_get_phase2_client_cert_scheme (s_8021X)) { + case NM_SETTING_802_1X_CK_SCHEME_BLOB: + if (show_secrets) + cert_str = bytes_to_string (nm_setting_802_1x_get_phase2_client_cert_blob (s_8021X)); + else + cert_str = g_strdup (_(NM_META_TEXT_HIDDEN)); + break; + case NM_SETTING_802_1X_CK_SCHEME_PATH: + cert_str = g_strdup (nm_setting_802_1x_get_phase2_client_cert_path (s_8021X)); + break; + case NM_SETTING_802_1X_CK_SCHEME_PKCS11: + cert_str = g_strdup (nm_setting_802_1x_get_phase2_client_cert_uri (s_8021X)); + break; + case NM_SETTING_802_1X_CK_SCHEME_UNKNOWN: + break; + } + + return cert_str; +} + +static char * +_get_fcn_802_1x_password_raw (ARGS_GET_FCN) +{ + NMSetting8021x *s_8021X = NM_SETTING_802_1X (setting); + return bytes_to_string (nm_setting_802_1x_get_password_raw (s_8021X)); +} + +static char * +_get_fcn_802_1x_private_key (ARGS_GET_FCN) +{ + NMSetting8021x *s_8021X = NM_SETTING_802_1X (setting); + char *key_str = NULL; + + switch (nm_setting_802_1x_get_private_key_scheme (s_8021X)) { + case NM_SETTING_802_1X_CK_SCHEME_BLOB: + if (show_secrets) + key_str = bytes_to_string (nm_setting_802_1x_get_private_key_blob (s_8021X)); + else + key_str = g_strdup (_(NM_META_TEXT_HIDDEN)); + break; + case NM_SETTING_802_1X_CK_SCHEME_PATH: + key_str = g_strdup (nm_setting_802_1x_get_private_key_path (s_8021X)); + break; + case NM_SETTING_802_1X_CK_SCHEME_PKCS11: + key_str = g_strdup (nm_setting_802_1x_get_private_key_uri (s_8021X)); + break; + case NM_SETTING_802_1X_CK_SCHEME_UNKNOWN: + break; + } + + return key_str; +} + +static char * +_get_fcn_802_1x_phase2_private_key (ARGS_GET_FCN) +{ + NMSetting8021x *s_8021X = NM_SETTING_802_1X (setting); + char *key_str = NULL; + + switch (nm_setting_802_1x_get_phase2_private_key_scheme (s_8021X)) { + case NM_SETTING_802_1X_CK_SCHEME_BLOB: + if (show_secrets) + key_str = bytes_to_string (nm_setting_802_1x_get_phase2_private_key_blob (s_8021X)); + else + key_str = g_strdup (_(NM_META_TEXT_HIDDEN)); + break; + case NM_SETTING_802_1X_CK_SCHEME_PATH: + key_str = g_strdup (nm_setting_802_1x_get_phase2_private_key_path (s_8021X)); + break; + case NM_SETTING_802_1X_CK_SCHEME_PKCS11: + key_str = g_strdup (nm_setting_802_1x_get_phase2_private_key_uri (s_8021X)); + break; + case NM_SETTING_802_1X_CK_SCHEME_UNKNOWN: + break; + } + + return key_str; +} + +#define DEFINE_SETTER_STR_LIST(def_func, set_func) \ + static gboolean \ + def_func (ARGS_SET_FCN) \ + { \ + char **strv = NULL; \ + guint i = 0; \ + \ + g_return_val_if_fail (error == NULL || *error == NULL, FALSE); \ + \ + strv = nmc_strsplit_set (value, " \t,", 0); \ + while (strv && strv[i]) \ + set_func (NM_SETTING_802_1X (setting), strv[i++]); \ + g_strfreev (strv); \ + return TRUE; \ + } + +#define DEFINE_SETTER_CERT(def_func, set_func) \ + static gboolean \ + def_func (ARGS_SET_FCN) \ + { \ + char *val_strip = g_strstrip (g_strdup (value)); \ + char *p = val_strip; \ + 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) \ + 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); \ + \ + success = set_func (NM_SETTING_802_1X (setting), p, scheme, NULL, error); \ + g_free (val_strip); \ + return success; \ + } + +#define DEFINE_SETTER_PRIV_KEY(def_func, pwd_func, set_func) \ + 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 *password_free = NULL; \ + 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) \ + 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); \ + \ + strv = nmc_strsplit_set (p, " \t,", 2); \ + path = strv[0]; \ + if (g_strv_length (strv) == 2) \ + password = strv[1]; \ + 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; \ + } + +static gboolean +_validate_and_remove_eap_method (NMSetting8021x *setting, + const char *eap, + GError **error) +{ + gboolean ret; + + ret = nm_setting_802_1x_remove_eap_method_by_value(setting, eap); + if (!ret) + g_set_error (error, 1, 0, _("the property doesn't contain EAP method '%s'"), eap); + return ret; +} +DEFINE_REMOVER_INDEX_OR_VALUE (_remove_fcn_802_1x_eap, + NM_SETTING_802_1X, + nm_setting_802_1x_get_num_eap_methods, + nm_setting_802_1x_remove_eap_method, + _validate_and_remove_eap_method) + +DEFINE_SETTER_CERT (_set_fcn_802_1x_ca_cert, nm_setting_802_1x_set_ca_cert) + +DEFINE_SETTER_STR_LIST (_set_fcn_802_1x_altsubject_matches, nm_setting_802_1x_add_altsubject_match) + +static gboolean +_validate_and_remove_altsubject_match (NMSetting8021x *setting, + const char *altsubject_match, + GError **error) +{ + gboolean ret; + + ret = nm_setting_802_1x_remove_altsubject_match_by_value (setting, altsubject_match); + if (!ret) + g_set_error (error, 1, 0, + _("the property doesn't contain alternative subject match '%s'"), + altsubject_match); + return ret; +} +DEFINE_REMOVER_INDEX_OR_VALUE (_remove_fcn_802_1x_altsubject_matches, + NM_SETTING_802_1X, + nm_setting_802_1x_get_num_altsubject_matches, + nm_setting_802_1x_remove_altsubject_match, + _validate_and_remove_altsubject_match) + +DEFINE_SETTER_CERT (_set_fcn_802_1x_client_cert, nm_setting_802_1x_set_client_cert) + +DEFINE_SETTER_CERT (_set_fcn_802_1x_phase2_ca_cert, nm_setting_802_1x_set_phase2_ca_cert) + +DEFINE_SETTER_STR_LIST (_set_fcn_802_1x_phase2_altsubject_matches, nm_setting_802_1x_add_phase2_altsubject_match) + +static gboolean +_validate_and_remove_phase2_altsubject_match (NMSetting8021x *setting, + const char *phase2_altsubject_match, + GError **error) +{ + gboolean ret; + + ret = nm_setting_802_1x_remove_phase2_altsubject_match_by_value (setting, phase2_altsubject_match); + if (!ret) + g_set_error (error, 1, 0, + _("the property doesn't contain \"phase2\" alternative subject match '%s'"), + phase2_altsubject_match); + return ret; +} +DEFINE_REMOVER_INDEX_OR_VALUE (_remove_fcn_802_1x_phase2_altsubject_matches, + NM_SETTING_802_1X, + nm_setting_802_1x_get_num_phase2_altsubject_matches, + nm_setting_802_1x_remove_phase2_altsubject_match, + _validate_and_remove_phase2_altsubject_match) + +DEFINE_SETTER_CERT (_set_fcn_802_1x_phase2_client_cert, nm_setting_802_1x_set_phase2_client_cert) + +DEFINE_SETTER_PRIV_KEY (_set_fcn_802_1x_private_key, + nm_setting_802_1x_get_private_key_password, + nm_setting_802_1x_set_private_key) + +DEFINE_SETTER_PRIV_KEY (_set_fcn_802_1x_phase2_private_key, + nm_setting_802_1x_get_phase2_private_key_password, + nm_setting_802_1x_set_phase2_private_key) + +static gboolean +_set_fcn_802_1x_password_raw (ARGS_SET_FCN) +{ + return nmc_property_set_byte_array (setting, property_info->property_name, value, error); +} + +static char * +_get_fcn_bond_options (ARGS_GET_FCN) +{ + NMSettingBond *s_bond = NM_SETTING_BOND (setting); + GString *bond_options_s; + int i; + + bond_options_s = g_string_new (NULL); + for (i = 0; i < nm_setting_bond_get_num_options (s_bond); i++) { + const char *key, *value; + gs_free char *tmp_value = NULL; + char *p; + + nm_setting_bond_get_option (s_bond, i, &key, &value); + + if (nm_streq0 (key, NM_SETTING_BOND_OPTION_ARP_IP_TARGET)) { + value = tmp_value = g_strdup (value); + for (p = tmp_value; p && *p; p++) { + if (*p == ',') + *p = ' '; + } + } + + g_string_append_printf (bond_options_s, "%s=%s,", key, value); + } + g_string_truncate (bond_options_s, bond_options_s->len-1); /* chop off trailing ',' */ + + return g_string_free (bond_options_s, FALSE); +} + +/* example: miimon=100,mode=balance-rr, updelay=5 */ +static gboolean +_validate_and_remove_bond_option (NMSettingBond *setting, const char *option) +{ + const char *opt; + const char **valid_options; + + valid_options = nm_setting_bond_get_valid_options (setting); + opt = nmc_string_is_valid (option, valid_options, NULL); + + if (opt) + return nm_setting_bond_remove_option (setting, opt); + else + return FALSE; +} + +static const char * +_validate_bond_option_value (const char *option, const char *value, GError **error) +{ + if (!g_strcmp0 (option, NM_SETTING_BOND_OPTION_MODE)) + return nmc_bond_validate_mode (value, error); + + return value; +} + +static gboolean +_bond_add_option (NMSettingBond *setting, + const char *name, + const char *value) +{ + gs_free char *tmp_value = NULL; + char *p; + + if (nm_streq0 (name, NM_SETTING_BOND_OPTION_ARP_IP_TARGET)) { + value = tmp_value = g_strdup (value); + for (p = tmp_value; p && *p; p++) + if (*p == ' ') + *p = ','; + } + + return nm_setting_bond_add_option (setting, name, value); +} + +DEFINE_SETTER_OPTIONS (_set_fcn_bond_options, + NM_SETTING_BOND, + NMSettingBond, + _bond_add_option, + nm_setting_bond_get_valid_options, + _validate_bond_option_value) +DEFINE_REMOVER_OPTION (_remove_fcn_bond_options, + NM_SETTING_BOND, + _validate_and_remove_bond_option) + +static const char * +_describe_fcn_bond_options (ARGS_DESCRIBE_FCN) +{ + gs_free char *options_str = NULL; + const char **valid_options; + char *s; + + valid_options = nm_setting_bond_get_valid_options (NULL); + options_str = g_strjoinv (", ", (char **) valid_options); + + s = g_strdup_printf (_("Enter a list of bonding options formatted as:\n" + " option = <value>, option = <value>,... \n" + "Valid options are: %s\n" + "'mode' can be provided as a name or a number:\n" + "balance-rr = 0\n" + "active-backup = 1\n" + "balance-xor = 2\n" + "broadcast = 3\n" + "802.3ad = 4\n" + "balance-tlb = 5\n" + "balance-alb = 6\n\n" + "Example: mode=2,miimon=120\n"), options_str); + return (*out_to_free = s); +} + +static const char *const* +_values_fcn_bond_options (ARGS_VALUES_FCN) +{ + return nm_setting_bond_get_valid_options (NULL); +} + +static char * +_get_fcn_connection_autoconnect_retires (ARGS_GET_FCN) +{ + NMSettingConnection *s_con = NM_SETTING_CONNECTION (setting); + gint retries; + + retries = nm_setting_connection_get_autoconnect_retries (s_con); + if (get_type == NM_META_ACCESSOR_GET_TYPE_PARSABLE) + return g_strdup_printf ("%d", retries); + + switch (retries) { + case -1: + return g_strdup_printf (_("%d (default)"), retries); + case 0: + return g_strdup_printf (_("%d (forever)"), retries); + default: + return g_strdup_printf ("%d", retries); + } +} + +static char * +_get_fcn_connection_permissions (ARGS_GET_FCN) +{ + NMSettingConnection *s_con = NM_SETTING_CONNECTION (setting); + GString *perm = NULL; + const char *perm_item; + const char *perm_type; + int i; + + perm = g_string_new (NULL); + for (i = 0; i < nm_setting_connection_get_num_permissions (s_con); i++) { + 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); + } + if (perm->len > 0) { + g_string_truncate (perm, perm->len-1); /* remove trailing , */ + return g_string_free (perm, FALSE); + } + + /* No value from get_permission */ + return g_string_free (perm, TRUE); +} + +static char * +_get_fcn_connection_autoconnect_slaves (ARGS_GET_FCN) +{ + NMSettingConnection *s_con = NM_SETTING_CONNECTION (setting); + return autoconnect_slaves_to_string (nm_setting_connection_get_autoconnect_slaves (s_con), get_type); +} + +static gboolean +_set_fcn_connection_type (ARGS_SET_FCN) +{ + gs_free char *uuid = NULL; + + if (nm_setting_connection_get_uuid (NM_SETTING_CONNECTION (setting))) { + /* Don't allow setting type unless the connection is brand new. + * Just because it's a bad idea and the user wouldn't probably want that. + * No technical reason, really. + * Also, using uuid to see if the connection is brand new is a bit + * hacky: we can not see if the type is already set, because + * nmc_setting_set_property() is called only after the property + * we're setting (type) has been removed. */ + g_set_error (error, 1, 0, _("Can not change the connection type")); + return FALSE; + } + + uuid = nm_utils_uuid_generate (); + g_object_set (G_OBJECT (setting), + NM_SETTING_CONNECTION_UUID, uuid, + NULL); + + g_object_set (G_OBJECT (setting), property_info->property_name, value, NULL); + return TRUE; +} + +/* define from libnm-core/nm-setting-connection.c */ +#define PERM_USER_PREFIX "user:" + +static gboolean +permissions_valid (const char *perm) +{ + if (!perm || perm[0] == '\0') + return FALSE; + + if (strncmp (perm, PERM_USER_PREFIX, strlen (PERM_USER_PREFIX)) == 0) { + if ( strlen (perm) <= strlen (PERM_USER_PREFIX) + || strchr (perm + strlen (PERM_USER_PREFIX), ':')) + return FALSE; + } else { + if (strchr (perm, ':')) + return FALSE; + } + + return TRUE; +} + +static gboolean +_set_fcn_connection_permissions (ARGS_SET_FCN) +{ + char **strv = NULL; + guint i = 0; + + g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + + strv = nmc_strsplit_set (value, " \t,", 0); + if (!verify_string_list (strv, property_info->property_name, permissions_valid, error)) { + g_strfreev (strv); + 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]; + + nm_setting_connection_add_permission (NM_SETTING_CONNECTION (setting), "user", user, NULL); + } + + return TRUE; +} + +static gboolean +_validate_and_remove_connection_permission (NMSettingConnection *setting, + const char *perm, + GError **error) +{ + gboolean ret; + + ret = nm_setting_connection_remove_permission_by_value (setting, "user", perm, NULL); + if (!ret) + g_set_error (error, 1, 0, _("the property doesn't contain permission '%s'"), perm); + return ret; +} +DEFINE_REMOVER_INDEX_OR_VALUE (_remove_fcn_connection_permissions, + NM_SETTING_CONNECTION, + nm_setting_connection_get_num_permissions, + nm_setting_connection_remove_permission, + _validate_and_remove_connection_permission) + +static gboolean +_set_fcn_connection_master (ARGS_SET_FCN) +{ + g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + + if (!value) + ; + else if (!*value) + value = NULL; + else if ( !nm_utils_is_valid_iface_name (value, NULL) + && !nm_utils_is_uuid (value)) { + g_set_error (error, 1, 0, + _("'%s' is not valid master; use ifname or connection UUID"), + value); + return FALSE; + } + g_object_set (setting, property_info->property_name, value, NULL); + return TRUE; +} + +static gboolean +_set_fcn_connection_secondaries (ARGS_SET_FCN) +{ + const GPtrArray *connections; + NMConnection *con; + char **strv = NULL, **iter; + guint i = 0; + + connections = nm_client_get_connections (nm_cli.client); + strv = nmc_strsplit_set (value, " \t,", 0); + for (iter = strv; iter && *iter; iter++) { + if (**iter == '\0') + continue; + + if (nm_utils_is_uuid (*iter)) { + con = nmc_find_connection (connections, "uuid", *iter, NULL, FALSE); + if (!con) + g_print (_("Warning: %s is not an UUID of any existing connection profile\n"), *iter); + else { + /* Currenly NM only supports VPN connections as secondaries */ + if (!nm_connection_is_type (con, NM_SETTING_VPN_SETTING_NAME)) { + g_set_error (error, 1, 0, _("'%s' is not a VPN connection profile"), *iter); + g_strfreev (strv); + return FALSE; + } + } + } else { + con = nmc_find_connection (connections, "id", *iter, NULL, FALSE); + if (!con) { + g_set_error (error, 1, 0, _("'%s' is not a name of any exiting profile"), *iter); + g_strfreev (strv); + return FALSE; + } + + /* Currenly NM only supports VPN connections as secondaries */ + if (!nm_connection_is_type (con, NM_SETTING_VPN_SETTING_NAME)) { + g_set_error (error, 1, 0, _("'%s' is not a VPN connection profile"), *iter); + g_strfreev (strv); + return FALSE; + } + + /* translate id to uuid */ + g_free (*iter); + *iter = g_strdup (nm_connection_get_uuid (con)); + } + } + + while (strv && strv[i]) + nm_setting_connection_add_secondary (NM_SETTING_CONNECTION (setting), strv[i++]); + g_strfreev (strv); + + return TRUE; +} + +static gboolean +_validate_and_remove_connection_secondary (NMSettingConnection *setting, + const char *secondary_uuid, + GError **error) +{ + gboolean ret; + + if (!nm_utils_is_uuid (secondary_uuid)) { + g_set_error (error, 1, 0, + _("the value '%s' is not a valid UUID"), secondary_uuid); + return FALSE; + } + + ret = nm_setting_connection_remove_secondary_by_value (setting, secondary_uuid); + if (!ret) + g_set_error (error, 1, 0, + _("the property doesn't contain UUID '%s'"), secondary_uuid); + return ret; +} +DEFINE_REMOVER_INDEX_OR_VALUE (_remove_fcn_connection_secondaries, + NM_SETTING_CONNECTION, + nm_setting_connection_get_num_secondaries, + nm_setting_connection_remove_secondary, + _validate_and_remove_connection_secondary) + +static char * +_get_fcn_connection_metered (ARGS_GET_FCN) +{ + NMSettingConnection *s_conn = NM_SETTING_CONNECTION (setting); + + if (get_type == NM_META_ACCESSOR_GET_TYPE_PARSABLE) { + switch (nm_setting_connection_get_metered (s_conn)) { + case NM_METERED_YES: + return g_strdup ("yes"); + case NM_METERED_NO: + return g_strdup ("no"); + case NM_METERED_UNKNOWN: + default: + return g_strdup ("unknown"); + } + } + switch (nm_setting_connection_get_metered (s_conn)) { + case NM_METERED_YES: + return g_strdup (_("yes")); + case NM_METERED_NO: + return g_strdup (_("no")); + case NM_METERED_UNKNOWN: + default: + return g_strdup (_("unknown")); + } +} + +static gboolean +_set_fcn_connection_metered (ARGS_SET_FCN) +{ + NMMetered metered; + NMCTriStateValue ts_val; + + if (!nmc_string_to_tristate (value, &ts_val, error)) + return FALSE; + + switch (ts_val) { + case NMC_TRI_STATE_YES: + metered = NM_METERED_YES; + break; + case NMC_TRI_STATE_NO: + metered = NM_METERED_NO; + break; + case NMC_TRI_STATE_UNKNOWN: + metered = NM_METERED_UNKNOWN; + break; + default: + g_assert_not_reached(); + } + + g_object_set (setting, property_info->property_name, metered, NULL); + return TRUE; +} + +static char * +dcb_flags_to_string (NMSettingDcbFlags flags) +{ + GString *flag_str; + + if (flags == 0) + return g_strdup (_("0 (disabled)")); + + flag_str = g_string_new (NULL); + g_string_printf (flag_str, "%d (", flags); + + if (flags & NM_SETTING_DCB_FLAG_ENABLE) + g_string_append (flag_str, _("enabled, ")); + if (flags & NM_SETTING_DCB_FLAG_ADVERTISE) + g_string_append (flag_str, _("advertise, ")); + if (flags & NM_SETTING_DCB_FLAG_WILLING) + g_string_append (flag_str, _("willing, ")); + + if (flag_str->str[flag_str->len-1] == '(') + g_string_append (flag_str, _("unknown")); + else + g_string_truncate (flag_str, flag_str->len-2); /* chop off trailing ', ' */ + + g_string_append_c (flag_str, ')'); + + return g_string_free (flag_str, FALSE); +} + +#define DEFINE_DCB_FLAGS_GETTER(func_name, property_name) \ + static char * \ + func_name (ARGS_GET_FCN) \ + { \ + guint v; \ + GValue val = G_VALUE_INIT; \ + g_value_init (&val, G_TYPE_UINT); \ + g_object_get_property (G_OBJECT (setting), property_name, &val); \ + v = g_value_get_uint (&val); \ + g_value_unset (&val); \ + return dcb_flags_to_string (v); \ + } + +static char * +dcb_app_priority_to_string (gint priority) +{ + return (priority == -1) ? g_strdup (_("-1 (unset)")) : g_strdup_printf ("%d", priority); +} + +#define DEFINE_DCB_APP_PRIORITY_GETTER(func_name, property_name) \ + static char * \ + func_name (ARGS_GET_FCN) \ + { \ + int v; \ + GValue val = G_VALUE_INIT; \ + g_value_init (&val, G_TYPE_INT); \ + g_object_get_property (G_OBJECT (setting), property_name, &val); \ + v = g_value_get_int (&val); \ + g_value_unset (&val); \ + return dcb_app_priority_to_string (v); \ + } + +#define DEFINE_DCB_BOOL_GETTER(func_name, getter_func_name) \ + static char * \ + func_name (ARGS_GET_FCN) \ + { \ + NMSettingDcb *s_dcb = NM_SETTING_DCB (setting); \ + GString *str; \ + guint i; \ +\ + str = g_string_new (NULL); \ + for (i = 0; i < 8; i++) { \ + if (getter_func_name (s_dcb, i)) \ + g_string_append_c (str, '1'); \ + else \ + g_string_append_c (str, '0'); \ +\ + if (i < 7) \ + g_string_append_c (str, ','); \ + } \ +\ + return g_string_free (str, FALSE); \ + } + +#define DEFINE_DCB_UINT_GETTER(func_name, getter_func_name) \ + static char * \ + func_name (ARGS_GET_FCN) \ + { \ + NMSettingDcb *s_dcb = NM_SETTING_DCB (setting); \ + GString *str; \ + guint i; \ + \ + str = g_string_new (NULL); \ + for (i = 0; i < 8; i++) { \ + g_string_append_printf (str, "%u", getter_func_name (s_dcb, i)); \ + if (i < 7) \ + g_string_append_c (str, ','); \ + } \ +\ + return g_string_free (str, FALSE); \ + } + +DEFINE_DCB_FLAGS_GETTER (_get_fcn_dcb_app_fcoe_flags, NM_SETTING_DCB_APP_FCOE_FLAGS) +DEFINE_DCB_APP_PRIORITY_GETTER (_get_fcn_dcb_app_fcoe_priority, NM_SETTING_DCB_APP_FCOE_PRIORITY) +DEFINE_DCB_FLAGS_GETTER (_get_fcn_dcb_app_iscsi_flags, NM_SETTING_DCB_APP_ISCSI_FLAGS) +DEFINE_DCB_APP_PRIORITY_GETTER (_get_fcn_dcb_app_iscsi_priority, NM_SETTING_DCB_APP_ISCSI_PRIORITY) +DEFINE_DCB_FLAGS_GETTER (_get_fcn_dcb_app_fip_flags, NM_SETTING_DCB_APP_FIP_FLAGS) +DEFINE_DCB_APP_PRIORITY_GETTER (_get_fcn_dcb_app_fip_priority, NM_SETTING_DCB_APP_FIP_PRIORITY) + +DEFINE_DCB_FLAGS_GETTER (_get_fcn_dcb_priority_flow_control_flags, NM_SETTING_DCB_PRIORITY_FLOW_CONTROL_FLAGS) +DEFINE_DCB_BOOL_GETTER (_get_fcn_dcb_priority_flow_control, nm_setting_dcb_get_priority_flow_control) + +DEFINE_DCB_FLAGS_GETTER (_get_fcn_dcb_priority_group_flags, NM_SETTING_DCB_PRIORITY_GROUP_FLAGS) +DEFINE_DCB_UINT_GETTER (_get_fcn_dcb_priority_group_id, nm_setting_dcb_get_priority_group_id) +DEFINE_DCB_UINT_GETTER (_get_fcn_dcb_priority_group_bandwidth, nm_setting_dcb_get_priority_group_bandwidth) +DEFINE_DCB_UINT_GETTER (_get_fcn_dcb_priority_bandwidth, nm_setting_dcb_get_priority_bandwidth) +DEFINE_DCB_BOOL_GETTER (_get_fcn_dcb_priority_strict, nm_setting_dcb_get_priority_strict_bandwidth) +DEFINE_DCB_UINT_GETTER (_get_fcn_dcb_priority_traffic_class, nm_setting_dcb_get_priority_traffic_class) + +#define DCB_ALL_FLAGS (NM_SETTING_DCB_FLAG_ENABLE | NM_SETTING_DCB_FLAG_ADVERTISE | NM_SETTING_DCB_FLAG_WILLING) + +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); + + /* Check for overall hex numeric value */ + if (nmc_string_to_int_base (value, 0, TRUE, 0, DCB_ALL_FLAGS, &t)) + flags = (guint) t; + else { + /* Check for individual flag numbers */ + strv = nmc_strsplit_set (value, " \t,", 0); + for (iter = strv; iter && *iter; iter++) { + if (!nmc_string_to_int_base (*iter, 0, TRUE, 0, DCB_ALL_FLAGS, &t)) + t = -1; + + if ( g_ascii_strcasecmp (*iter, "enable") == 0 + || g_ascii_strcasecmp (*iter, "enabled") == 0 + || t == NM_SETTING_DCB_FLAG_ENABLE) + flags |= NM_SETTING_DCB_FLAG_ENABLE; + else if ( g_ascii_strcasecmp (*iter, "advertise") == 0 + || t == NM_SETTING_DCB_FLAG_ADVERTISE) + flags |= NM_SETTING_DCB_FLAG_ADVERTISE; + else if ( g_ascii_strcasecmp (*iter, "willing") == 0 + || t == NM_SETTING_DCB_FLAG_WILLING) + flags |= NM_SETTING_DCB_FLAG_WILLING; + else if ( g_ascii_strcasecmp (*iter, "disable") == 0 + || g_ascii_strcasecmp (*iter, "disabled") == 0 + || t == 0) { + /* pass */ + } else { + g_set_error (error, 1, 0, _("'%s' is not a valid DCB flag"), *iter); + return FALSE; + } + } + g_strfreev (strv); + } + + /* Validate the flags according to the property spec */ + if (!validate_flags (setting, property_info->property_name, (guint) flags, error)) + return FALSE; + + g_object_set (setting, property_info->property_name, (guint) flags, NULL); + return TRUE; +} + +static gboolean +_set_fcn_dcb_priority (ARGS_SET_FCN) +{ + long int priority = 0; + + g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + + if (!nmc_string_to_int (value, FALSE, -1, 7, &priority)) { + g_set_error (error, 1, 0, _("'%s' is not a DCB app priority"), value); + return FALSE; + } + + /* Validate the number according to the property spec */ + if (!validate_int (setting, property_info->property_name, (gint) priority, error)) + return FALSE; + + g_object_set (setting, property_info->property_name, (gint) priority, NULL); + return TRUE; +} + +static gboolean +dcb_parse_uint_array (const char *val, + guint max, + guint other, + guint *out_array, + GError **error) +{ + char **items, **iter; + guint i = 0; + + g_return_val_if_fail (out_array != NULL, FALSE); + + items = g_strsplit_set (val, ",", -1); + if (g_strv_length (items) != 8) { + g_set_error_literal (error, 1, 0, _("must contain 8 comma-separated numbers")); + goto error; + } + + for (iter = items; iter && *iter; iter++) { + long int num = 0; + gboolean success; + + *iter = g_strstrip (*iter); + success = nmc_string_to_int_base (*iter, 10, TRUE, 0, other ? other : max, &num); + + /* If number is greater than 'max' it must equal 'other' */ + if (success && other && (num > max) && (num != other)) + success = FALSE; + + if (!success) { + if (other) { + g_set_error (error, 1, 0, _("'%s' not a number between 0 and %u (inclusive) or %u"), + *iter, max, other); + } else { + g_set_error (error, 1, 0, _("'%s' not a number between 0 and %u (inclusive)"), + *iter, max); + } + goto error; + } + out_array[i++] = (guint) num; + } + + return TRUE; + +error: + g_strfreev (items); + return FALSE; +} + +static void +dcb_check_feature_enabled (NMSettingDcb *s_dcb, const char *flags_prop) +{ + NMSettingDcbFlags flags = NM_SETTING_DCB_FLAG_NONE; + + g_object_get (s_dcb, flags_prop, &flags, NULL); + if (!(flags & NM_SETTING_DCB_FLAG_ENABLE)) + g_print (_("Warning: changes will have no effect until '%s' includes 1 (enabled)\n\n"), flags_prop); +} + +static gboolean +_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); + + if (!dcb_parse_uint_array (value, 1, 0, nums, error)) + return FALSE; + + for (i = 0; i < 8; i++) + nm_setting_dcb_set_priority_flow_control (NM_SETTING_DCB (setting), i, !!nums[i]); + + dcb_check_feature_enabled (NM_SETTING_DCB (setting), NM_SETTING_DCB_PRIORITY_FLOW_CONTROL_FLAGS); + return TRUE; +} + +static gboolean +_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); + + if (!dcb_parse_uint_array (value, 7, 15, nums, error)) + return FALSE; + + for (i = 0; i < 8; i++) + nm_setting_dcb_set_priority_group_id (NM_SETTING_DCB (setting), i, nums[i]); + + dcb_check_feature_enabled (NM_SETTING_DCB (setting), NM_SETTING_DCB_PRIORITY_GROUP_FLAGS); + return TRUE; +} + +static gboolean +_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); + + if (!dcb_parse_uint_array (value, 100, 0, nums, error)) + return FALSE; + + for (i = 0; i < 8; i++) + sum += nums[i]; + if (sum != 100) { + g_set_error_literal (error, 1, 0, _("bandwidth percentages must total 100%%")); + return FALSE; + } + + for (i = 0; i < 8; i++) + nm_setting_dcb_set_priority_group_bandwidth (NM_SETTING_DCB (setting), i, nums[i]); + + dcb_check_feature_enabled (NM_SETTING_DCB (setting), NM_SETTING_DCB_PRIORITY_GROUP_FLAGS); + return TRUE; +} + +static gboolean +_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); + + if (!dcb_parse_uint_array (value, 100, 0, nums, error)) + return FALSE; + + for (i = 0; i < 8; i++) + nm_setting_dcb_set_priority_bandwidth (NM_SETTING_DCB (setting), i, nums[i]); + + dcb_check_feature_enabled (NM_SETTING_DCB (setting), NM_SETTING_DCB_PRIORITY_GROUP_FLAGS); + return TRUE; +} + +static gboolean +_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); + + if (!dcb_parse_uint_array (value, 1, 0, nums, error)) + return FALSE; + + for (i = 0; i < 8; i++) + nm_setting_dcb_set_priority_strict_bandwidth (NM_SETTING_DCB (setting), i, !!nums[i]); + + dcb_check_feature_enabled (NM_SETTING_DCB (setting), NM_SETTING_DCB_PRIORITY_GROUP_FLAGS); + return TRUE; +} + +static gboolean +_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); + + if (!dcb_parse_uint_array (value, 7, 0, nums, error)) + return FALSE; + + for (i = 0; i < 8; i++) + nm_setting_dcb_set_priority_traffic_class (NM_SETTING_DCB (setting), i, nums[i]); + + dcb_check_feature_enabled (NM_SETTING_DCB (setting), NM_SETTING_DCB_PRIORITY_GROUP_FLAGS); + return TRUE; +} + +static gboolean +_set_fcn_gsm_sim_operator_id (ARGS_SET_FCN) +{ + const char *p = value; + + g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + + 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")); + return FALSE; + } + + while (p && *p) { + if (!g_ascii_isdigit (*p++)) { + g_set_error_literal (error, 1, 0, _("SIM operator ID must be a 5 or 6 number MCCMNC code")); + return FALSE; + } + } + g_object_set (G_OBJECT (setting), + NM_SETTING_GSM_SIM_OPERATOR_ID, + value, + NULL); + return TRUE; +} + +static gboolean +_set_fcn_infiniband_p_key (ARGS_SET_FCN) +{ + gboolean p_key_valid = FALSE; + long p_key_int; + + g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + + if (!strncasecmp (value, "0x", 2)) + p_key_valid = nmc_string_to_int_base (value + 2, 16, TRUE, 0, G_MAXUINT16, &p_key_int); + else + p_key_valid = nmc_string_to_int (value, TRUE, -1, G_MAXUINT16, &p_key_int); + + if (!p_key_valid) { + if (strcmp (value, "default") == 0) + p_key_int = -1; + else { + g_set_error (error, 1, 0, _("'%s' is not a valid IBoIP P_Key"), value); + return FALSE; + } + } + g_object_set (setting, property_info->property_name, (gint) p_key_int, NULL); + return TRUE; +} + + +static char * +_get_fcn_infiniband_p_key (ARGS_GET_FCN) +{ + NMSettingInfiniband *s_infiniband = NM_SETTING_INFINIBAND (setting); + int p_key; + + p_key = nm_setting_infiniband_get_p_key (s_infiniband); + if (p_key == -1) { + if (get_type == NM_META_ACCESSOR_GET_TYPE_PARSABLE) + return g_strdup ("default"); + else + return g_strdup (_("default")); + } else + return g_strdup_printf ("0x%04x", p_key); +} + +static char * +_get_fcn_ip_tunnel_mode (ARGS_GET_FCN) +{ + NMSettingIPTunnel *s_ip_tunnel = NM_SETTING_IP_TUNNEL (setting); + NMIPTunnelMode mode; + + mode = nm_setting_ip_tunnel_get_mode (s_ip_tunnel); + return nm_utils_enum_to_str (nm_ip_tunnel_mode_get_type (), mode); +} + +static gboolean +_set_fcn_ip_tunnel_mode (ARGS_SET_FCN) +{ + NMIPTunnelMode mode; + gboolean ret; + + ret = nm_utils_enum_from_str (nm_ip_tunnel_mode_get_type(), value, + (int *) &mode, NULL); + + if (!ret) { + gs_free const char **values = NULL; + gs_free char *values_str = NULL; + + values = nm_utils_enum_get_values (nm_ip_tunnel_mode_get_type (), + NM_IP_TUNNEL_MODE_UNKNOWN + 1, + G_MAXINT); + values_str = g_strjoinv (",", (char **) values); + g_set_error (error, 1, 0, _("invalid mode '%s', use one of %s"), + value, values_str); + + return FALSE; + } + + g_object_set (setting, property_info->property_name, mode, NULL); + return TRUE; +} + +static NMIPAddress * +_parse_ip_address (int family, const char *address, GError **error) +{ + char *value = g_strdup (address); + NMIPAddress *ipaddr; + + ipaddr = nmc_parse_and_build_address (family, g_strstrip (value), error); + g_free (value); + return ipaddr; +} + +static char * +_get_fcn_ip_config_addresses (ARGS_GET_FCN) +{ + NMSettingIPConfig *s_ip = NM_SETTING_IP_CONFIG (setting); + GString *printable; + guint32 num_addresses, i; + NMIPAddress *addr; + + printable = g_string_new (NULL); + + num_addresses = nm_setting_ip_config_get_num_addresses (s_ip); + for (i = 0; i < num_addresses; i++) { + addr = nm_setting_ip_config_get_address (s_ip, i); + + if (printable->len > 0) + g_string_append (printable, ", "); + + g_string_append_printf (printable, "%s/%u", + nm_ip_address_get_address (addr), + nm_ip_address_get_prefix (addr)); + } + + return g_string_free (printable, FALSE); +} + +static char * +_get_fcn_ip_config_routes (ARGS_GET_FCN) +{ + NMSettingIPConfig *s_ip = NM_SETTING_IP_CONFIG (setting); + GString *printable; + guint32 num_routes, i; + NMIPRoute *route; + + printable = g_string_new (NULL); + + num_routes = nm_setting_ip_config_get_num_routes (s_ip); + for (i = 0; i < num_routes; i++) { + gs_free char *attr_str = NULL; + gs_strfreev char **attr_names = NULL; + gs_unref_hashtable GHashTable *hash = g_hash_table_new (g_str_hash, g_str_equal); + int j; + + route = nm_setting_ip_config_get_route (s_ip, i); + + attr_names = nm_ip_route_get_attribute_names (route); + for (j = 0; attr_names && attr_names[j]; j++) { + g_hash_table_insert (hash, attr_names[j], + nm_ip_route_get_attribute (route, attr_names[j])); + } + + attr_str = nm_utils_format_variant_attributes (hash, ' ', '='); + + if (get_type == NM_META_ACCESSOR_GET_TYPE_PARSABLE) { + if (printable->len > 0) + g_string_append (printable, ", "); + + g_string_append_printf (printable, "%s/%u", + nm_ip_route_get_dest (route), + nm_ip_route_get_prefix (route)); + + if (nm_ip_route_get_next_hop (route)) + g_string_append_printf (printable, " %s", nm_ip_route_get_next_hop (route)); + if (nm_ip_route_get_metric (route) != -1) + g_string_append_printf (printable, " %u", (guint32) nm_ip_route_get_metric (route)); + if (attr_str) + g_string_append_printf (printable, " %s", attr_str); + } else { + + if (printable->len > 0) + g_string_append (printable, "; "); + + g_string_append (printable, "{ "); + + g_string_append_printf (printable, "ip = %s/%u", + nm_ip_route_get_dest (route), + nm_ip_route_get_prefix (route)); + + if (nm_ip_route_get_next_hop (route)) { + g_string_append_printf (printable, ", nh = %s", + nm_ip_route_get_next_hop (route)); + } + + if (nm_ip_route_get_metric (route) != -1) + g_string_append_printf (printable, ", mt = %u", (guint32) nm_ip_route_get_metric (route)); + if (attr_str) + g_string_append_printf (printable, " %s", attr_str); + + g_string_append (printable, " }"); + } + } + + return g_string_free (printable, FALSE); +} + +static char * +_get_fcn_ip4_config_dad_timeout (ARGS_GET_FCN) +{ + NMSettingIPConfig *s_ip = NM_SETTING_IP_CONFIG (setting); + gint dad_timeout; + + dad_timeout = nm_setting_ip_config_get_dad_timeout (s_ip); + if (get_type == NM_META_ACCESSOR_GET_TYPE_PARSABLE) + return g_strdup_printf ("%d", dad_timeout); + + switch (dad_timeout) { + case -1: + return g_strdup_printf (_("%d (default)"), dad_timeout); + case 0: + return g_strdup_printf (_("%d (off)"), dad_timeout); + default: + return g_strdup_printf ("%d", dad_timeout); + } +} + +static const char *ipv4_valid_methods[] = { + NM_SETTING_IP4_CONFIG_METHOD_AUTO, + NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL, + NM_SETTING_IP4_CONFIG_METHOD_MANUAL, + NM_SETTING_IP4_CONFIG_METHOD_SHARED, + NM_SETTING_IP4_CONFIG_METHOD_DISABLED, + NULL +}; + +static gboolean +_set_fcn_ip4_config_method (ARGS_SET_FCN) +{ + /* Silently accept "static" and convert to "manual" */ + if (value && strlen (value) > 1 && matches (value, "static")) + value = NM_SETTING_IP4_CONFIG_METHOD_MANUAL; + + return check_and_set_string (setting, property_info->property_name, value, ipv4_valid_methods, error); +} + +static gboolean +_set_fcn_ip4_config_dns (ARGS_SET_FCN) +{ + char **strv = NULL, **iter, *addr; + guint32 ip4_addr; + + g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + + strv = nmc_strsplit_set (value, " \t,", 0); + for (iter = strv; iter && *iter; iter++) { + addr = g_strstrip (*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; +} + +static gboolean +_validate_and_remove_ipv4_dns (NMSettingIPConfig *setting, + const char *dns, + GError **error) +{ + guint32 ip4_addr; + gboolean ret; + + if (inet_pton (AF_INET, dns, &ip4_addr) < 1) { + g_set_error (error, 1, 0, _("invalid IPv4 address '%s'"), dns); + return FALSE; + } + + ret = nm_setting_ip_config_remove_dns_by_value (setting, dns); + if (!ret) + g_set_error (error, 1, 0, _("the property doesn't contain DNS server '%s'"), dns); + return ret; +} +DEFINE_REMOVER_INDEX_OR_VALUE (_remove_fcn_ipv4_config_dns, + NM_SETTING_IP_CONFIG, + nm_setting_ip_config_get_num_dns, + nm_setting_ip_config_remove_dns, + _validate_and_remove_ipv4_dns) + +static gboolean +_set_fcn_ip4_config_dns_search (ARGS_SET_FCN) +{ + char **strv = NULL; + guint i = 0; + + g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + + strv = nmc_strsplit_set (value, " \t,", 0); + if (!verify_string_list (strv, property_info->property_name, nmc_util_is_domain, error)) { + g_strfreev (strv); + return FALSE; + } + + while (strv && strv[i]) + nm_setting_ip_config_add_dns_search (NM_SETTING_IP_CONFIG (setting), strv[i++]); + g_strfreev (strv); + + return TRUE; +} + +static gboolean +_validate_and_remove_ipv4_dns_search (NMSettingIPConfig *setting, + const char *dns_search, + GError **error) +{ + gboolean ret; + + ret = nm_setting_ip_config_remove_dns_search_by_value (setting, dns_search); + if (!ret) + g_set_error (error, 1, 0, + _("the property doesn't contain DNS search domain '%s'"), + dns_search); + return ret; +} +DEFINE_REMOVER_INDEX_OR_VALUE (_remove_fcn_ipv4_config_dns_search, + NM_SETTING_IP_CONFIG, + nm_setting_ip_config_get_num_dns_searches, + nm_setting_ip_config_remove_dns_search, + _validate_and_remove_ipv4_dns_search) + +static gboolean +_set_fcn_ip4_config_dns_options (ARGS_SET_FCN) +{ + char **strv = NULL; + guint i = 0; + + g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + + 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); + + return TRUE; +} + +static gboolean +_validate_and_remove_ipv4_dns_option (NMSettingIPConfig *setting, + const char *dns_option, + GError **error) +{ + gboolean ret; + + ret = nm_setting_ip_config_remove_dns_option_by_value (setting, dns_option); + if (!ret) + g_set_error (error, 1, 0, + _("the property doesn't contain DNS option '%s'"), + dns_option); + return ret; +} +DEFINE_REMOVER_INDEX_OR_VALUE (_remove_fcn_ipv4_config_dns_options, + NM_SETTING_IP_CONFIG, + nm_setting_ip_config_get_num_dns_options, + nm_setting_ip_config_remove_dns_option, + _validate_and_remove_ipv4_dns_option) + +static NMIPAddress * +_parse_ipv4_address (const char *address, GError **error) +{ + return _parse_ip_address (AF_INET, address, error); +} + +static gboolean +_set_fcn_ip4_config_addresses (ARGS_SET_FCN) +{ + char **strv = NULL, **iter; + NMIPAddress *ip4addr; + + g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + + strv = nmc_strsplit_set (value, ",", 0); + for (iter = strv; iter && *iter; iter++) { + ip4addr = _parse_ipv4_address (*iter, error); + if (!ip4addr) { + g_strfreev (strv); + return FALSE; + } + nm_setting_ip_config_add_address (NM_SETTING_IP_CONFIG (setting), ip4addr); + nm_ip_address_unref (ip4addr); + } + g_strfreev (strv); + return TRUE; +} + +static gboolean +_validate_and_remove_ipv4_address (NMSettingIPConfig *setting, + const char *address, + GError **error) +{ + NMIPAddress *ip4addr; + gboolean ret; + + ip4addr = _parse_ipv4_address (address, error); + if (!ip4addr) + return FALSE; + + ret = nm_setting_ip_config_remove_address_by_value (setting, ip4addr); + if (!ret) + g_set_error (error, 1, 0, + _("the property doesn't contain IP address '%s'"), address); + nm_ip_address_unref (ip4addr); + return ret; +} +DEFINE_REMOVER_INDEX_OR_VALUE (_remove_fcn_ipv4_config_addresses, + NM_SETTING_IP_CONFIG, + nm_setting_ip_config_get_num_addresses, + nm_setting_ip_config_remove_address, + _validate_and_remove_ipv4_address) + +static gboolean +_set_fcn_ip4_config_gateway (ARGS_SET_FCN) +{ + NMIPAddress *ip4addr; + + g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + + if (strchr (value, '/')) { + g_set_error (error, 1, 0, + _("invalid gateway address '%s'"), value); + return FALSE; + } + ip4addr = _parse_ipv4_address (value, error); + if (!ip4addr) + return FALSE; + + g_object_set (setting, property_info->property_name, value, NULL); + nm_ip_address_unref (ip4addr); + return TRUE; +} + +static NMIPRoute * +_parse_ipv4_route (const char *route, GError **error) +{ + return nmc_parse_and_build_route (AF_INET, route, error); +} + +static gboolean +_set_fcn_ip4_config_routes (ARGS_SET_FCN) +{ + char **strv = NULL, **iter; + NMIPRoute *ip4route; + + g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + + strv = nmc_strsplit_set (value, ",", 0); + for (iter = strv; iter && *iter; iter++) { + ip4route = _parse_ipv4_route (*iter, error); + if (!ip4route) { + g_strfreev (strv); + return FALSE; + } + nm_setting_ip_config_add_route (NM_SETTING_IP_CONFIG (setting), ip4route); + nm_ip_route_unref (ip4route); + } + g_strfreev (strv); + return TRUE; +} + +static gboolean +_validate_and_remove_ipv4_route (NMSettingIPConfig *setting, + const char *route, + GError **error) +{ + NMIPRoute *ip4route; + gboolean ret; + + ip4route = _parse_ipv4_route (route, error); + if (!ip4route) + return FALSE; + + ret = nm_setting_ip_config_remove_route_by_value (setting, ip4route); + if (!ret) + g_set_error (error, 1, 0, _("the property doesn't contain route '%s'"), route); + nm_ip_route_unref (ip4route); + return ret; +} +DEFINE_REMOVER_INDEX_OR_VALUE (_remove_fcn_ipv4_config_routes, + NM_SETTING_IP_CONFIG, + nm_setting_ip_config_get_num_routes, + nm_setting_ip_config_remove_route, + _validate_and_remove_ipv4_route) + +static char * +_get_fcn_ip6_config_ip6_privacy (ARGS_GET_FCN) +{ + NMSettingIP6Config *s_ip6 = NM_SETTING_IP6_CONFIG (setting); + return 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, + NM_SETTING_IP6_CONFIG_METHOD_DHCP, + NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL, + NM_SETTING_IP6_CONFIG_METHOD_MANUAL, + NM_SETTING_IP6_CONFIG_METHOD_SHARED, + NULL +}; + +static gboolean +_set_fcn_ip6_config_method (ARGS_SET_FCN) +{ + /* Silently accept "static" and convert to "manual" */ + if (value && strlen (value) > 1 && matches (value, "static")) + value = NM_SETTING_IP6_CONFIG_METHOD_MANUAL; + + return check_and_set_string (setting, property_info->property_name, value, ipv6_valid_methods, error); +} + +static gboolean +_set_fcn_ip6_config_dns (ARGS_SET_FCN) +{ + char **strv = NULL, **iter, *addr; + struct in6_addr ip6_addr; + + g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + + strv = nmc_strsplit_set (value, " \t,", 0); + for (iter = strv; iter && *iter; iter++) { + addr = g_strstrip (*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; +} + +static gboolean +_validate_and_remove_ipv6_dns (NMSettingIPConfig *setting, + const char *dns, + GError **error) +{ + struct in6_addr ip6_addr; + gboolean ret; + + if (inet_pton (AF_INET6, dns, &ip6_addr) < 1) { + g_set_error (error, 1, 0, _("invalid IPv6 address '%s'"), dns); + return FALSE; + } + + ret = nm_setting_ip_config_remove_dns_by_value (setting, dns); + if (!ret) + g_set_error (error, 1, 0, _("the property doesn't contain DNS server '%s'"), dns); + return ret; +} +DEFINE_REMOVER_INDEX_OR_VALUE (_remove_fcn_ipv6_config_dns, + NM_SETTING_IP_CONFIG, + nm_setting_ip_config_get_num_dns, + nm_setting_ip_config_remove_dns, + _validate_and_remove_ipv6_dns) + +static gboolean +_set_fcn_ip6_config_dns_search (ARGS_SET_FCN) +{ + char **strv = NULL; + guint i = 0; + + g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + + strv = nmc_strsplit_set (value, " \t,", 0); + if (!verify_string_list (strv, property_info->property_name, nmc_util_is_domain, error)) { + g_strfreev (strv); + return FALSE; + } + + while (strv && strv[i]) + nm_setting_ip_config_add_dns_search (NM_SETTING_IP_CONFIG (setting), strv[i++]); + g_strfreev (strv); + + return TRUE; +} + +static gboolean +_validate_and_remove_ipv6_dns_search (NMSettingIPConfig *setting, + const char *dns_search, + GError **error) +{ + gboolean ret; + + ret = nm_setting_ip_config_remove_dns_search_by_value (setting, dns_search); + if (!ret) + g_set_error (error, 1, 0, + _("the property doesn't contain DNS search domain '%s'"), + dns_search); + return ret; +} +DEFINE_REMOVER_INDEX_OR_VALUE (_remove_fcn_ipv6_config_dns_search, + NM_SETTING_IP_CONFIG, + nm_setting_ip_config_get_num_dns_searches, + nm_setting_ip_config_remove_dns_search, + _validate_and_remove_ipv6_dns_search) + +static gboolean +_set_fcn_ip6_config_dns_options (ARGS_SET_FCN) +{ + char **strv = NULL; + guint i = 0; + + g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + + 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); + + return TRUE; +} + +static gboolean +_validate_and_remove_ipv6_dns_option (NMSettingIPConfig *setting, + const char *dns_option, + GError **error) +{ + gboolean ret; + + ret = nm_setting_ip_config_remove_dns_option_by_value (setting, dns_option); + if (!ret) + g_set_error (error, 1, 0, + _("the property doesn't contain DNS option '%s'"), + dns_option); + return ret; +} +DEFINE_REMOVER_INDEX_OR_VALUE (_remove_fcn_ipv6_config_dns_options, + NM_SETTING_IP_CONFIG, + nm_setting_ip_config_get_num_dns_options, + nm_setting_ip_config_remove_dns_option, + _validate_and_remove_ipv6_dns_option) + +static NMIPAddress * +_parse_ipv6_address (const char *address, GError **error) +{ + return _parse_ip_address (AF_INET6, address, error); +} + +static gboolean +_set_fcn_ip6_config_addresses (ARGS_SET_FCN) +{ + char **strv = NULL, **iter; + NMIPAddress *ip6addr; + + g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + + strv = nmc_strsplit_set (value, ",", 0); + for (iter = strv; iter && *iter; iter++) { + ip6addr = _parse_ipv6_address (*iter, error); + if (!ip6addr) { + g_strfreev (strv); + return FALSE; + } + nm_setting_ip_config_add_address (NM_SETTING_IP_CONFIG (setting), ip6addr); + nm_ip_address_unref (ip6addr); + } + g_strfreev (strv); + return TRUE; +} + +static gboolean +_validate_and_remove_ipv6_address (NMSettingIPConfig *setting, + const char *address, + GError **error) +{ + NMIPAddress *ip6addr; + gboolean ret; + + ip6addr = _parse_ipv6_address (address, error); + if (!ip6addr) + return FALSE; + + ret = nm_setting_ip_config_remove_address_by_value (setting, ip6addr); + if (!ret) + g_set_error (error, 1, 0, _("the property doesn't contain IP address '%s'"), address); + nm_ip_address_unref (ip6addr); + return ret; +} +DEFINE_REMOVER_INDEX_OR_VALUE (_remove_fcn_ipv6_config_addresses, + NM_SETTING_IP_CONFIG, + nm_setting_ip_config_get_num_addresses, + nm_setting_ip_config_remove_address, + _validate_and_remove_ipv6_address) + +static gboolean +_set_fcn_ip6_config_gateway (ARGS_SET_FCN) +{ + NMIPAddress *ip6addr; + + g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + + if (strchr (value, '/')) { + g_set_error (error, 1, 0, + _("invalid gateway address '%s'"), value); + return FALSE; + } + ip6addr = _parse_ipv6_address (value, error); + if (!ip6addr) + return FALSE; + + g_object_set (setting, property_info->property_name, value, NULL); + nm_ip_address_unref (ip6addr); + return TRUE; +} + +static NMIPRoute * +_parse_ipv6_route (const char *route, GError **error) +{ + return nmc_parse_and_build_route (AF_INET6, route, error); +} + +static gboolean +_set_fcn_ip6_config_routes (ARGS_SET_FCN) +{ + char **strv = NULL, **iter; + NMIPRoute *ip6route; + + g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + + strv = nmc_strsplit_set (value, ",", 0); + for (iter = strv; iter && *iter; iter++) { + ip6route = _parse_ipv6_route (*iter, error); + if (!ip6route) { + g_strfreev (strv); + return FALSE; + } + nm_setting_ip_config_add_route (NM_SETTING_IP_CONFIG (setting), ip6route); + nm_ip_route_unref (ip6route); + } + g_strfreev (strv); + return TRUE; +} + +static gboolean +_validate_and_remove_ipv6_route (NMSettingIPConfig *setting, + const char *route, + GError **error) +{ + NMIPRoute *ip6route; + gboolean ret; + + ip6route = _parse_ipv6_route (route, error); + if (!ip6route) + return FALSE; + + ret = nm_setting_ip_config_remove_route_by_value (setting, ip6route); + if (!ret) + g_set_error (error, 1, 0, _("the property doesn't contain route '%s'"), route); + nm_ip_route_unref (ip6route); + return ret; +} +DEFINE_REMOVER_INDEX_OR_VALUE (_remove_fcn_ipv6_config_routes, + NM_SETTING_IP_CONFIG, + nm_setting_ip_config_get_num_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 char * +_get_fcn_macsec_mode (ARGS_GET_FCN) +{ + NMSettingMacsec *s_macsec = NM_SETTING_MACSEC (setting); + NMSettingMacsecMode mode; + + mode = nm_setting_macsec_get_mode (s_macsec); + return nm_utils_enum_to_str (nm_setting_macsec_mode_get_type (), mode); +} + +static gboolean +_set_fcn_macsec_mode (ARGS_SET_FCN) +{ + NMSettingMacsecMode mode; + gs_free char *options = NULL; + + if (!nm_utils_enum_from_str (nm_setting_macsec_mode_get_type (), value, + (int *) &mode, NULL)) { + options = g_strjoinv (",", + (char **) nm_utils_enum_get_values (nm_setting_macsec_mode_get_type (), + G_MININT, + G_MAXINT)); + g_set_error (error, 1, 0, _("invalid option '%s', use one of [%s]"), + value, options); + return FALSE; + } + + g_object_set (setting, property_info->property_name, mode, NULL); + return TRUE; +} + +static char * +_get_fcn_macsec_validation (ARGS_GET_FCN) +{ + NMSettingMacsec *s_macsec = NM_SETTING_MACSEC (setting); + NMSettingMacsecValidation validation; + + validation = nm_setting_macsec_get_validation (s_macsec); + return nm_utils_enum_to_str (nm_setting_macsec_validation_get_type (), validation); +} + +static gboolean +_set_fcn_macsec_validation (ARGS_SET_FCN) +{ + NMSettingMacsecMode validation; + gs_free char *options = NULL; + + if (!nm_utils_enum_from_str (nm_setting_macsec_validation_get_type (), value, + (int *) &validation, NULL)) { + options = g_strjoinv (",", + (char **) nm_utils_enum_get_values (nm_setting_macsec_validation_get_type (), + G_MININT, + G_MAXINT)); + g_set_error (error, 1, 0, _("invalid option '%s', use one of [%s]"), + value, options); + return FALSE; + } + + g_object_set (setting, property_info->property_name, validation, NULL); + return TRUE; +} + +static char * +_get_fcn_macvlan_mode (ARGS_GET_FCN) +{ + NMSettingMacvlan *s_macvlan = NM_SETTING_MACVLAN (setting); + NMSettingMacvlanMode mode; + char *tmp, *str; + + mode = nm_setting_macvlan_get_mode (s_macvlan); + tmp = nm_utils_enum_to_str (nm_setting_macvlan_mode_get_type (), mode); + + if (get_type == NM_META_ACCESSOR_GET_TYPE_PARSABLE) + str = g_strdup (tmp ? tmp : ""); + else + str = g_strdup_printf ("%d (%s)", mode, tmp ? tmp : ""); + g_free (tmp); + + return str; +} + +static gboolean +_set_fcn_macvlan_mode (ARGS_SET_FCN) +{ + NMSettingMacvlanMode mode; + gs_free const char **options = NULL; + gs_free char *options_str = NULL; + long int t; + gboolean ret; + + if (nmc_string_to_int_base (value, 0, TRUE, 0, _NM_SETTING_MACVLAN_MODE_NUM - 1, &t)) + mode = (NMSettingMacvlanMode) t; + else { + ret = nm_utils_enum_from_str (nm_setting_macvlan_mode_get_type (), value, + (int *) &mode, NULL); + + if (!ret) { + options = nm_utils_enum_get_values (nm_setting_macvlan_mode_get_type(), + NM_SETTING_MACVLAN_MODE_UNKNOWN + 1, + G_MAXINT); + options_str = g_strjoinv (",", (char **) options); + g_set_error (error, 1, 0, _("invalid option '%s', use one of [%s]"), + value, options_str); + return FALSE; + } + } + + g_object_set (setting, property_info->property_name, (guint) mode, NULL); + return TRUE; +} + +static char * +_get_fcn_olpc_mesh_ssid (ARGS_GET_FCN) +{ + NMSettingOlpcMesh *s_olpc_mesh = NM_SETTING_OLPC_MESH (setting); + GBytes *ssid; + char *ssid_str = NULL; + + ssid = nm_setting_olpc_mesh_get_ssid (s_olpc_mesh); + if (ssid) { + ssid_str = nm_utils_ssid_to_utf8 (g_bytes_get_data (ssid, NULL), + g_bytes_get_size (ssid)); + } + + return ssid_str; +} + +static gboolean +_set_fcn_olpc_mesh_channel (ARGS_SET_FCN) +{ + unsigned long chan_int; + + g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + + 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); + return FALSE; + } + g_object_set (setting, property_info->property_name, chan_int, NULL); + return TRUE; +} + +static char * +_get_fcn_proxy_method (ARGS_GET_FCN) +{ + NMSettingProxy *s_proxy = NM_SETTING_PROXY (setting); + NMSettingProxyMethod method; + + method = nm_setting_proxy_get_method (s_proxy); + return nm_utils_enum_to_str (nm_setting_proxy_method_get_type (), method); +} + +static gboolean +_set_fcn_proxy_method (ARGS_SET_FCN) +{ + int method; + gboolean ret; + + ret = nm_utils_enum_from_str (nm_setting_proxy_method_get_type(), value, + &method, NULL); + + if (!ret) { + gs_free const char **values = NULL; + gs_free char *values_str = NULL; + + values = nm_utils_enum_get_values (nm_setting_proxy_method_get_type (), + NM_SETTING_PROXY_METHOD_NONE, + G_MAXINT); + values_str = g_strjoinv (",", (char **) values); + g_set_error (error, 1, 0, _("invalid method '%s', use one of %s"), + value, values_str); + + return FALSE; + } + + g_object_set (setting, property_info->property_name, method, NULL); + return TRUE; +} + +static gboolean +_set_fcn_proxy_pac_script (ARGS_SET_FCN) +{ + char *script = NULL; + + g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + + if (!nmc_proxy_check_script (value, &script, error)) { + return FALSE; + } + g_object_set (setting, property_info->property_name, script, NULL); + g_free (script); + return TRUE; +} + +static char * +_get_fcn_serial_parity (ARGS_GET_FCN) +{ + NMSettingSerial *s_serial = NM_SETTING_SERIAL (setting); + + switch (nm_setting_serial_get_parity (s_serial)) { + case NM_SETTING_SERIAL_PARITY_EVEN: + return g_strdup ("even"); + case NM_SETTING_SERIAL_PARITY_ODD: + return g_strdup ("odd"); + default: + case NM_SETTING_SERIAL_PARITY_NONE: + return g_strdup ("none"); + } +} + +static gboolean +_set_fcn_serial_parity (ARGS_SET_FCN) +{ + NMSettingSerialParity parity; + + if (value[0] == 'E' || value[0] == 'e') + parity = NM_SETTING_SERIAL_PARITY_EVEN; + else if (value[0] == 'O' || value[0] == 'o') + parity = NM_SETTING_SERIAL_PARITY_ODD; + else if (value[0] == 'N' || value[0] == 'n') + parity = NM_SETTING_SERIAL_PARITY_NONE; + else { + g_set_error (error, 1, 0, _("'%s' is not valid; use [e, o, n]"), value); + return FALSE; + } + + g_object_set (setting, property_info->property_name, parity, NULL); + return TRUE; +} + +static gboolean +_set_fcn_team_config (ARGS_SET_FCN) +{ + char *json = NULL; + + g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + + if (!nmc_team_check_config (value, &json, error)) { + return FALSE; + } + g_object_set (setting, property_info->property_name, json, NULL); + g_free (json); + return TRUE; +} + +static char * +_get_fcn_tun_mode (ARGS_GET_FCN) +{ + NMSettingTun *s_tun = NM_SETTING_TUN (setting); + NMSettingTunMode mode; + char *tmp, *str; + + mode = nm_setting_tun_get_mode (s_tun); + tmp = nm_utils_enum_to_str (nm_setting_tun_mode_get_type (), mode); + if (get_type == NM_META_ACCESSOR_GET_TYPE_PARSABLE) + str = g_strdup_printf ("%s", tmp ? tmp : ""); + else + str = g_strdup_printf ("%d (%s)", mode, tmp ? tmp : ""); + g_free (tmp); + return str; +} + +static gboolean +_set_fcn_tun_mode (ARGS_SET_FCN) +{ + NMSettingTunMode mode; + gboolean ret; + long int t; + + if (nmc_string_to_int_base (value, 0, TRUE, 0, NM_SETTING_TUN_MODE_TAP, &t)) + mode = (NMSettingTunMode) t; + else { + ret = nm_utils_enum_from_str (nm_setting_tun_mode_get_type (), value, + (int *) &mode, NULL); + + if (!ret) { + g_set_error (error, 1, 0, _("invalid option '%s', use '%s' or '%s'"), + value, "tun", "tap"); + return FALSE; + } + } + + g_object_set (setting, property_info->property_name, (guint) mode, NULL); + return TRUE; +} + +static char * +_get_fcn_vlan_flags (ARGS_GET_FCN) +{ + NMSettingVlan *s_vlan = NM_SETTING_VLAN (setting); + return vlan_flags_to_string (nm_setting_vlan_get_flags (s_vlan), get_type); +} + +static char * +_get_fcn_vlan_ingress_priority_map (ARGS_GET_FCN) +{ + NMSettingVlan *s_vlan = NM_SETTING_VLAN (setting); + return vlan_priorities_to_string (s_vlan, NM_VLAN_INGRESS_MAP); +} + +static char * +_get_fcn_vlan_egress_priority_map (ARGS_GET_FCN) +{ + NMSettingVlan *s_vlan = NM_SETTING_VLAN (setting); + return vlan_priorities_to_string (s_vlan, NM_VLAN_EGRESS_MAP); +} + +static gboolean +_set_vlan_xgress_priority_map (NMSetting *setting, + const char *value, + NMVlanPriorityMap map_type, + GError **error) +{ + char **prio_map, **p; + + prio_map = nmc_vlan_parse_priority_maps (value, map_type, error); + if (!prio_map) + return FALSE; + + for (p = prio_map; p && *p; p++) + nm_setting_vlan_add_priority_str (NM_SETTING_VLAN (setting), map_type, *p); + + g_strfreev (prio_map); + return TRUE; +} + +static gboolean +_set_fcn_vlan_ingress_priority_map (ARGS_SET_FCN) +{ + return _set_vlan_xgress_priority_map (setting, value, NM_VLAN_INGRESS_MAP, error); +} + +static gboolean +_set_fcn_vlan_egress_priority_map (ARGS_SET_FCN) +{ + return _set_vlan_xgress_priority_map (setting, value, NM_VLAN_EGRESS_MAP, error); +} + +static gboolean +_remove_vlan_xgress_priority_map (NMSetting *setting, + const NMMetaPropertyInfo *property_info, + const char *value, + guint32 idx, + NMVlanPriorityMap map_type, + GError **error) +{ + guint32 num; + + /* If value != NULL, remove by value */ + if (value) { + gboolean ret; + char **prio_map; + gs_free char *v = g_strdup (value); + + prio_map = nmc_vlan_parse_priority_maps (v, map_type, error); + if (!prio_map) + return FALSE; + if (prio_map[1]) + g_print (_("Warning: only one mapping at a time is supported; taking the first one (%s)\n"), + prio_map[0]); + ret = nm_setting_vlan_remove_priority_str_by_value (NM_SETTING_VLAN (setting), + map_type, + prio_map[0]); + + if (!ret) + g_set_error (error, 1, 0, _("the property doesn't contain mapping '%s'"), prio_map[0]); + g_strfreev (prio_map); + return ret; + } + + /* Else remove by index */ + num = nm_setting_vlan_get_num_priorities (NM_SETTING_VLAN (setting), map_type); + if (num == 0) { + g_set_error_literal (error, 1, 0, _("no priority to remove")); + return FALSE; + } + if (idx >= num) { + g_set_error (error, 1, 0, _("index '%d' is not in the range of <0-%d>"), + idx, num - 1); + return FALSE; + } + + nm_setting_vlan_remove_priority (NM_SETTING_VLAN (setting), map_type, idx); + return TRUE; +} + +static gboolean +_remove_fcn_vlan_ingress_priority_map (ARGS_REMOVE_FCN) +{ + return _remove_vlan_xgress_priority_map (setting, + property_info, + value, + idx, + NM_VLAN_INGRESS_MAP, + error); +} + +static gboolean +_remove_fcn_vlan_egress_priority_map (ARGS_REMOVE_FCN) +{ + return _remove_vlan_xgress_priority_map (setting, + property_info, + value, + idx, + NM_VLAN_EGRESS_MAP, + error); +} + +static char * +_get_fcn_vpn_data (ARGS_GET_FCN) +{ + NMSettingVpn *s_vpn = NM_SETTING_VPN (setting); + GString *data_item_str; + + data_item_str = g_string_new (NULL); + nm_setting_vpn_foreach_data_item (s_vpn, &vpn_data_item, data_item_str); + + return g_string_free (data_item_str, FALSE); +} + +static char * +_get_fcn_vpn_secrets (ARGS_GET_FCN) +{ + NMSettingVpn *s_vpn = NM_SETTING_VPN (setting); + GString *secret_str; + + secret_str = g_string_new (NULL); + nm_setting_vpn_foreach_secret (s_vpn, &vpn_data_item, secret_str); + + return g_string_free (secret_str, FALSE); +} + +static const char * +_validate_vpn_hash_value (const char *option, const char *value, GError **error) +{ + /* nm_setting_vpn_add_data_item() and nm_setting_vpn_add_secret() does not + * allow empty strings */ + if (!value || !*value) { + g_set_error (error, 1, 0, _("'%s' cannot be empty"), option); + return NULL; + } + return value; +} + +DEFINE_SETTER_OPTIONS (_set_fcn_vpn_data, + NM_SETTING_VPN, + NMSettingVpn, + nm_setting_vpn_add_data_item, + NULL, + _validate_vpn_hash_value) +DEFINE_REMOVER_OPTION (_remove_fcn_vpn_data, + NM_SETTING_VPN, + nm_setting_vpn_remove_data_item) + +DEFINE_SETTER_OPTIONS (_set_fcn_vpn_secrets, + NM_SETTING_VPN, + NMSettingVpn, + nm_setting_vpn_add_secret, + NULL, + _validate_vpn_hash_value) +DEFINE_REMOVER_OPTION (_remove_fcn_vpn_secrets, + NM_SETTING_VPN, + nm_setting_vpn_remove_secret) + +static char * +_get_fcn_wired_wake_on_lan (ARGS_GET_FCN) +{ + NMSettingWired *s_wired = NM_SETTING_WIRED (setting); + NMSettingWiredWakeOnLan wol; + char *tmp, *str; + + wol = nm_setting_wired_get_wake_on_lan (s_wired); + tmp = nm_utils_enum_to_str (nm_setting_wired_wake_on_lan_get_type (), wol); + if (get_type == NM_META_ACCESSOR_GET_TYPE_PARSABLE) + str = g_strdup_printf ("%s", tmp && *tmp ? tmp : "none"); + else + str = g_strdup_printf ("%d (%s)", wol, tmp && *tmp ? tmp : "none"); + g_free (tmp); + return str; +} + +static gboolean +_set_fcn_wired_wake_on_lan (ARGS_SET_FCN) +{ + NMSettingWiredWakeOnLan wol; + gs_free char *err_token = NULL; + gboolean ret; + long int t; + + if (nmc_string_to_int_base (value, 0, TRUE, 0, + NM_SETTING_WIRED_WAKE_ON_LAN_ALL + | NM_SETTING_WIRED_WAKE_ON_LAN_EXCLUSIVE_FLAGS, + &t)) + wol = (NMSettingWiredWakeOnLan) t; + else { + ret = nm_utils_enum_from_str (nm_setting_wired_wake_on_lan_get_type (), value, + (int *) &wol, &err_token); + + if (!ret) { + if ( g_ascii_strcasecmp (err_token, "none") == 0 + || g_ascii_strcasecmp (err_token, "disable") == 0 + || g_ascii_strcasecmp (err_token, "disabled") == 0) + wol = NM_SETTING_WIRED_WAKE_ON_LAN_NONE; + else { + g_set_error (error, 1, 0, _("invalid option '%s', use a combination of [%s] or 'ignore', 'default' or 'none'"), + err_token, + nm_utils_enum_to_str (nm_setting_wired_wake_on_lan_get_type (), + NM_SETTING_WIRED_WAKE_ON_LAN_ALL)); + return FALSE; + } + } + } + + if ( NM_FLAGS_ANY (wol, NM_SETTING_WIRED_WAKE_ON_LAN_EXCLUSIVE_FLAGS) + && !nm_utils_is_power_of_two (wol)) { + g_set_error_literal (error, 1, 0, _("'default' and 'ignore' are incompatible with other flags")); + return FALSE; + } + + g_object_set (setting, property_info->property_name, (guint) wol, NULL); + return TRUE; +} + +DEFINE_SETTER_MAC_BLACKLIST (_set_fcn_wired_mac_address_blacklist, + NM_SETTING_WIRED, + nm_setting_wired_add_mac_blacklist_item) + +static gboolean +_validate_and_remove_wired_mac_blacklist_item (NMSettingWired *setting, + const char *mac, + GError **error) +{ + gboolean ret; + guint8 buf[32]; + + if (!nm_utils_hwaddr_aton (mac, buf, ETH_ALEN)) { + g_set_error (error, 1, 0, _("'%s' is not a valid MAC address"), mac); + return FALSE; + } + + ret = nm_setting_wired_remove_mac_blacklist_item_by_value (setting, mac); + if (!ret) + g_set_error (error, 1, 0, _("the property doesn't contain MAC address '%s'"), mac); + return ret; +} +DEFINE_REMOVER_INDEX_OR_VALUE (_remove_fcn_wired_mac_address_blacklist, + NM_SETTING_WIRED, + nm_setting_wired_get_num_mac_blacklist_items, + nm_setting_wired_remove_mac_blacklist_item, + _validate_and_remove_wired_mac_blacklist_item) + +static gboolean +_set_fcn_wired_s390_subchannels (ARGS_SET_FCN) +{ + char **strv = NULL; + int len; + + strv = nmc_strsplit_set (value, " ,\t", 0); + len = g_strv_length (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; +} + +static const char * +_validate_s390_option_value (const char *option, const char *value, GError **error) +{ + /* nm_setting_wired_add_s390_option() requires value len in <1,199> interval */ + if (!value || !*value || strlen (value) >= 200) { + g_set_error (error, 1, 0, _("'%s' string value should consist of 1 - 199 characters"), option); + return NULL; + } + return value; +} +DEFINE_SETTER_OPTIONS (_set_fcn_wired_s390_options, + NM_SETTING_WIRED, + NMSettingWired, + nm_setting_wired_add_s390_option, + nm_setting_wired_get_valid_s390_options, + _validate_s390_option_value) +DEFINE_REMOVER_OPTION (_remove_fcn_wired_s390_options, + NM_SETTING_WIRED, + nm_setting_wired_remove_s390_option) + +static const char *const* +_values_fcn__wired_s390_options (ARGS_VALUES_FCN) +{ + return nm_setting_wired_get_valid_s390_options (NULL); +} + +static const char * +_describe_fcn_wired_s390_options (ARGS_DESCRIBE_FCN) +{ + gs_free char *options_str = NULL; + const char **valid_options; + char *s; + + valid_options = nm_setting_wired_get_valid_s390_options (NULL); + + options_str = g_strjoinv (", ", (char **) valid_options); + + s = g_strdup_printf (_("Enter a list of S/390 options formatted as:\n" + " option = <value>, option = <value>,...\n" + "Valid options are: %s\n"), + options_str); + return (*out_to_free = s); +} + + +static char * +_get_fcn_wireless_ssid (ARGS_GET_FCN) +{ + NMSettingWireless *s_wireless = NM_SETTING_WIRELESS (setting); + GBytes *ssid; + char *ssid_str = NULL; + + ssid = nm_setting_wireless_get_ssid (s_wireless); + if (ssid) { + ssid_str = nm_utils_ssid_to_utf8 (g_bytes_get_data (ssid, NULL), + g_bytes_get_size (ssid)); + } + + return ssid_str; +} + +static char * +_get_fcn_wireless_mac_address_randomization (ARGS_GET_FCN) +{ + NMSettingWireless *s_wifi = NM_SETTING_WIRELESS (setting); + NMSettingMacRandomization randomization = nm_setting_wireless_get_mac_address_randomization (s_wifi); + + if (randomization == NM_SETTING_MAC_RANDOMIZATION_DEFAULT) + return g_strdup (_("default")); + else if (randomization == NM_SETTING_MAC_RANDOMIZATION_NEVER) + return g_strdup (_("never")); + else if (randomization == NM_SETTING_MAC_RANDOMIZATION_ALWAYS) + return g_strdup_printf (_("always")); + else + return g_strdup_printf (_("unknown")); +} + +static gboolean +_set_fcn_wireless_channel (ARGS_SET_FCN) +{ + unsigned long chan_int; + + g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + + if (!nmc_string_to_uint (value, FALSE, 0, 0, &chan_int)) { + g_set_error (error, 1, 0, _("'%s' is not a valid channel"), value); + return FALSE; + } + + if ( !nm_utils_wifi_is_channel_valid (chan_int, "a") + && !nm_utils_wifi_is_channel_valid (chan_int, "bg")) { + g_set_error (error, 1, 0, _("'%ld' is not a valid channel"), chan_int); + return FALSE; + } + + g_object_set (setting, property_info->property_name, chan_int, NULL); + return TRUE; +} + +DEFINE_SETTER_MAC_BLACKLIST (_set_fcn_wireless_mac_address_blacklist, + NM_SETTING_WIRELESS, + nm_setting_wireless_add_mac_blacklist_item) + +static gboolean +_validate_and_remove_wifi_mac_blacklist_item (NMSettingWireless *setting, + const char *mac, + GError **error) +{ + gboolean ret; + guint8 buf[32]; + + if (!nm_utils_hwaddr_aton (mac, buf, ETH_ALEN)) { + g_set_error (error, 1, 0, _("'%s' is not a valid MAC address"), mac); + return FALSE; + } + + ret = nm_setting_wireless_remove_mac_blacklist_item_by_value (setting, mac); + if (!ret) + g_set_error (error, 1, 0, _("the property doesn't contain MAC address '%s'"), mac); + return ret; +} +DEFINE_REMOVER_INDEX_OR_VALUE (_remove_fcn_wireless_mac_address_blacklist, + NM_SETTING_WIRELESS, + nm_setting_wireless_get_num_mac_blacklist_items, + nm_setting_wireless_remove_mac_blacklist_item, + _validate_and_remove_wifi_mac_blacklist_item) + +static gboolean +_set_fcn_wireless_mac_address_randomization (ARGS_SET_FCN) +{ + NMSettingMacRandomization randomization; + gs_free char *err_token = NULL; + gboolean ret; + long int t; + + if (nmc_string_to_int_base (value, 0, TRUE, + NM_SETTING_MAC_RANDOMIZATION_DEFAULT, + NM_SETTING_MAC_RANDOMIZATION_ALWAYS, + &t)) + randomization = (NMSettingMacRandomization) t; + else { + ret = nm_utils_enum_from_str (nm_setting_mac_randomization_get_type (), + value, + (int *) &randomization, + &err_token); + + if (!ret) { + g_set_error (error, 1, 0, _("invalid option '%s', use 'default', 'never' or 'always'"), + err_token); + return FALSE; + } + } + + g_object_set (setting, property_info->property_name, (guint) randomization, NULL); + return TRUE; +} + +static char * +_get_fcn_wireless_security_wep_key0 (ARGS_GET_FCN) +{ + NMSettingWirelessSecurity *s_wireless_sec = NM_SETTING_WIRELESS_SECURITY (setting); + return g_strdup (nm_setting_wireless_security_get_wep_key (s_wireless_sec, 0)); +} + +static char * +_get_fcn_wireless_security_wep_key1 (ARGS_GET_FCN) +{ + NMSettingWirelessSecurity *s_wireless_sec = NM_SETTING_WIRELESS_SECURITY (setting); + return g_strdup (nm_setting_wireless_security_get_wep_key (s_wireless_sec, 1)); +} + +static char * +_get_fcn_wireless_security_wep_key2 (ARGS_GET_FCN) +{ + NMSettingWirelessSecurity *s_wireless_sec = NM_SETTING_WIRELESS_SECURITY (setting); + return g_strdup (nm_setting_wireless_security_get_wep_key (s_wireless_sec, 2)); +} + +static char * +_get_fcn_wireless_security_wep_key3 (ARGS_GET_FCN) +{ + NMSettingWirelessSecurity *s_wireless_sec = NM_SETTING_WIRELESS_SECURITY (setting); + return g_strdup (nm_setting_wireless_security_get_wep_key (s_wireless_sec, 3)); +} + +static char * +_get_fcn_wireless_security_wep_key_type (ARGS_GET_FCN) +{ + return wep_key_type_to_string (nm_setting_wireless_security_get_wep_key_type (NM_SETTING_WIRELESS_SECURITY (setting))); +} + +static const char *wifi_sec_valid_protos[] = { "wpa", "rsn", NULL }; + +DEFINE_SETTER_STR_LIST_MULTI (check_and_add_wifi_sec_proto, + NM_SETTING_WIRELESS_SECURITY, + nm_setting_wireless_security_add_proto) + +static gboolean +_set_fcn_wireless_security_proto (ARGS_SET_FCN) +{ + return check_and_add_wifi_sec_proto (setting, property_info->property_name, value, wifi_sec_valid_protos, error); +} + +static gboolean +_validate_and_remove_wifi_sec_proto (NMSettingWirelessSecurity *setting, + const char *proto, + GError **error) +{ + gboolean ret; + const char *valid; + + valid = nmc_string_is_valid (proto, wifi_sec_valid_protos, error); + if (!valid) + return FALSE; + + ret = nm_setting_wireless_security_remove_proto_by_value (setting, proto); + if (!ret) + g_set_error (error, 1, 0, + _("the property doesn't contain protocol '%s'"), proto); + return ret; +} +DEFINE_REMOVER_INDEX_OR_VALUE (_remove_fcn_wireless_security_proto, + NM_SETTING_WIRELESS_SECURITY, + nm_setting_wireless_security_get_num_protos, + nm_setting_wireless_security_remove_proto, + _validate_and_remove_wifi_sec_proto) + +static const char *wifi_sec_valid_pairwises[] = { "tkip", "ccmp", NULL }; + +DEFINE_SETTER_STR_LIST_MULTI (check_and_add_wifi_sec_pairwise, + NM_SETTING_WIRELESS_SECURITY, + nm_setting_wireless_security_add_pairwise) + +static gboolean +_set_fcn_wireless_security_pairwise (ARGS_SET_FCN) +{ + return check_and_add_wifi_sec_pairwise (setting, property_info->property_name, value, wifi_sec_valid_pairwises, error); +} + +static gboolean +_validate_and_remove_wifi_sec_pairwise (NMSettingWirelessSecurity *setting, + const char *pairwise, + GError **error) +{ + gboolean ret; + const char *valid; + + valid = nmc_string_is_valid (pairwise, wifi_sec_valid_pairwises, error); + if (!valid) + return FALSE; + + ret = nm_setting_wireless_security_remove_pairwise_by_value (setting, pairwise); + if (!ret) + g_set_error (error, 1, 0, + _("the property doesn't contain protocol '%s'"), pairwise); + return ret; +} +DEFINE_REMOVER_INDEX_OR_VALUE (_remove_fcn_wireless_security_pairwise, + NM_SETTING_WIRELESS_SECURITY, + nm_setting_wireless_security_get_num_pairwise, + nm_setting_wireless_security_remove_pairwise, + _validate_and_remove_wifi_sec_pairwise) + +static const char *wifi_sec_valid_groups[] = { "wep40", "wep104", "tkip", "ccmp", NULL }; + +DEFINE_SETTER_STR_LIST_MULTI (check_and_add_wifi_sec_group, + NM_SETTING_WIRELESS_SECURITY, + nm_setting_wireless_security_add_group) + +static gboolean +_set_fcn_wireless_security_group (ARGS_SET_FCN) +{ + return check_and_add_wifi_sec_group (setting, property_info->property_name, value, wifi_sec_valid_groups, error); +} + +static gboolean +_validate_and_remove_wifi_sec_group (NMSettingWirelessSecurity *setting, + const char *group, + GError **error) +{ + gboolean ret; + const char *valid; + + valid = nmc_string_is_valid (group, wifi_sec_valid_groups, error); + if (!valid) + return FALSE; + + ret = nm_setting_wireless_security_remove_group_by_value (setting, group); + if (!ret) + g_set_error (error, 1, 0, + _("the property doesn't contain protocol '%s'"), group); + return ret; +} +DEFINE_REMOVER_INDEX_OR_VALUE (_remove_fcn_wireless_security_group, + NM_SETTING_WIRELESS_SECURITY, + nm_setting_wireless_security_get_num_groups, + nm_setting_wireless_security_remove_group, + _validate_and_remove_wifi_sec_group) + +static gboolean +_set_fcn_wireless_wep_key (ARGS_SET_FCN) +{ + NMWepKeyType guessed_type = NM_WEP_KEY_TYPE_UNKNOWN; + NMWepKeyType type; + guint32 prev_idx, idx; + + g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + + /* Get currently set type */ + type = nm_setting_wireless_security_get_wep_key_type (NM_SETTING_WIRELESS_SECURITY (setting)); + + /* Guess key type */ + if (nm_utils_wep_key_valid (value, NM_WEP_KEY_TYPE_KEY)) + guessed_type = NM_WEP_KEY_TYPE_KEY; + else if (nm_utils_wep_key_valid (value, NM_WEP_KEY_TYPE_PASSPHRASE)) + guessed_type = NM_WEP_KEY_TYPE_PASSPHRASE; + + if (guessed_type == NM_WEP_KEY_TYPE_UNKNOWN) { + g_set_error (error, 1, 0, _("'%s' is not valid"), value); + return FALSE; + } + + if (type != NM_WEP_KEY_TYPE_UNKNOWN && type != guessed_type) { + if (nm_utils_wep_key_valid (value, type)) + guessed_type = type; + else { + g_set_error (error, 1, 0, + _("'%s' not compatible with %s '%s', please change the key or set the right %s first."), + value, NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE, wep_key_type_to_string (type), + NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE); + return FALSE; + } + } + prev_idx = nm_setting_wireless_security_get_wep_tx_keyidx (NM_SETTING_WIRELESS_SECURITY (setting)); + idx = property_info->property_name[strlen (property_info->property_name) - 1] - '0'; + g_print (_("WEP key is guessed to be of '%s'\n"), wep_key_type_to_string (guessed_type)); + if (idx != prev_idx) + g_print (_("WEP key index set to '%d'\n"), idx); + + g_object_set (setting, property_info->property_name, value, NULL); + g_object_set (setting, NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE, guessed_type, NULL); + if (idx != prev_idx) + g_object_set (setting, NM_SETTING_WIRELESS_SECURITY_WEP_TX_KEYIDX, idx, NULL); + return TRUE; +} + +static gboolean +_set_fcn_wireless_security_wep_key_type (ARGS_SET_FCN) +{ + unsigned long type_int; + const char *valid_wep_types[] = { "unknown", "key", "passphrase", NULL }; + const char *type_str = NULL; + const char *key0, *key1,* key2, *key3; + NMWepKeyType type = NM_WEP_KEY_TYPE_UNKNOWN; + + g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + + if (!nmc_string_to_uint (value, TRUE, 0, 2, &type_int)) { + if (!(type_str = nmc_string_is_valid (value, valid_wep_types, NULL))) { + g_set_error (error, 1, 0, _("'%s' not among [0 (unknown), 1 (key), 2 (passphrase)]"), value); + return FALSE; + } + if (type_str == valid_wep_types[1]) + type = NM_WEP_KEY_TYPE_KEY; + else if (type_str == valid_wep_types[2]) + type = NM_WEP_KEY_TYPE_PASSPHRASE; + } else + type = (NMWepKeyType) type_int; + + /* Check type compatibility with set keys */ + key0 = nm_setting_wireless_security_get_wep_key (NM_SETTING_WIRELESS_SECURITY (setting), 0); + key1 = nm_setting_wireless_security_get_wep_key (NM_SETTING_WIRELESS_SECURITY (setting), 1); + key2 = nm_setting_wireless_security_get_wep_key (NM_SETTING_WIRELESS_SECURITY (setting), 2); + key3 = nm_setting_wireless_security_get_wep_key (NM_SETTING_WIRELESS_SECURITY (setting), 3); + if (key0 && !nm_utils_wep_key_valid (key0, type)) + g_print (_("Warning: '%s' is not compatible with '%s' type, please change or delete the key.\n"), + NM_SETTING_WIRELESS_SECURITY_WEP_KEY0, wep_key_type_to_string (type)); + if (key1 && !nm_utils_wep_key_valid (key1, type)) + g_print (_("Warning: '%s' is not compatible with '%s' type, please change or delete the key.\n"), + NM_SETTING_WIRELESS_SECURITY_WEP_KEY1, wep_key_type_to_string (type)); + if (key2 && !nm_utils_wep_key_valid (key2, type)) + g_print (_("Warning: '%s' is not compatible with '%s' type, please change or delete the key.\n"), + NM_SETTING_WIRELESS_SECURITY_WEP_KEY2, wep_key_type_to_string (type)); + if (key3 && !nm_utils_wep_key_valid (key3, type)) + g_print (_("Warning: '%s' is not compatible with '%s' type, please change or delete the key.\n"), + NM_SETTING_WIRELESS_SECURITY_WEP_KEY3, wep_key_type_to_string (type)); + + g_object_set (setting, property_info->property_name, type, NULL); + return TRUE; +} + +static gboolean +_set_fcn_wireless_security_psk (ARGS_SET_FCN) +{ + if (!nm_utils_wpa_psk_valid (value)) { + g_set_error (error, 1, 0, _("'%s' is not a valid PSK"), value); + return FALSE; + } + g_object_set (setting, property_info->property_name, value, NULL); + return TRUE; +} + +/*****************************************************************************/ + +static void +nmc_value_transform_bool_string (const GValue *src_value, + GValue *dest_value) +{ + dest_value->data[0].v_pointer = g_strdup (src_value->data[0].v_int ? "yes" : "no"); +} + +static void +nmc_value_transform_char_string (const GValue *src_value, + GValue *dest_value) +{ + dest_value->data[0].v_pointer = g_strdup_printf ("%c", src_value->data[0].v_uint); +} + +static void __attribute__((constructor)) +register_nmcli_value_transforms (void) +{ + /* FIXME: we should not register a g-value transform function. Instead, our meta data + * should be able to access the values according to their type. + * + * Also, running code as a ((constructor)) is hightly unexpected and affects the + * entire binary. */ + g_value_register_transform_func (G_TYPE_BOOLEAN, G_TYPE_STRING, nmc_value_transform_bool_string); + g_value_register_transform_func (G_TYPE_CHAR, G_TYPE_STRING, nmc_value_transform_char_string); +} + +/*****************************************************************************/ + +#define DEFINE_PROPERTY_TYPE(...) \ + (&((NMMetaPropertyType) { __VA_ARGS__ } )) + +#define DEFINE_PROPERTY_TYP_DATA(...) \ + (&((NMMetaPropertyTypData) { __VA_ARGS__ } )) + +#define PROPERTY_TYP_DATA_SUBTYPE(stype, ...) \ + .subtype = { \ + .stype = { __VA_ARGS__ }, \ + } + +#define DEFINE_PROPERTY_TYP_DATA_SUBTYPE(stype, ...) \ + DEFINE_PROPERTY_TYP_DATA ( \ + PROPERTY_TYP_DATA_SUBTYPE (stype, __VA_ARGS__), \ + ) + +static const NMMetaPropertyType _pt_name = { + .get_fcn = _get_fcn_name, +}; + +static const NMMetaPropertyType _pt_gobject_readonly = { + .get_fcn = _get_fcn_gobject, +}; + +static const NMMetaPropertyType _pt_gobject_string = { + .get_fcn = _get_fcn_gobject, + .set_fcn = _set_fcn_gobject_string, +}; + +static const NMMetaPropertyType _pt_gobject_bool = { + .get_fcn = _get_fcn_gobject, + .set_fcn = _set_fcn_gobject_bool, +}; + +static const NMMetaPropertyType _pt_gobject_int = { + .get_fcn = _get_fcn_gobject, + .set_fcn = _set_fcn_gobject_int, +}; + +static const NMMetaPropertyType _pt_gobject_int64 = { + .get_fcn = _get_fcn_gobject, + .set_fcn = _set_fcn_gobject_int64, +}; + +static const NMMetaPropertyType _pt_gobject_uint = { + .get_fcn = _get_fcn_gobject, + .set_fcn = _set_fcn_gobject_uint, +}; + +static const NMMetaPropertyType _pt_gobject_mtu = { + .get_fcn = _get_fcn_gobject_mtu, + .set_fcn = _set_fcn_gobject_mtu, +}; + +static const NMMetaPropertyType _pt_gobject_mac = { + .get_fcn = _get_fcn_gobject, + .set_fcn = _set_fcn_gobject_mac, +}; + +static const NMMetaPropertyType _pt_gobject_secret_flags = { + .get_fcn = _get_fcn_gobject_secret_flags, + .set_fcn = _set_fcn_gobject_secret_flags, +}; + +static const NMMetaPropertyType _pt_gobject_enum = { + .get_fcn = _get_fcn_gobject_enum, + .set_fcn = _set_fcn_gobject_enum, + .values_fcn = _values_fcn_gobject_enum, +}; + +/*****************************************************************************/ + +/* FIXME: it is wrong to have a property-type "name". The name is a regular + * "property" of the setting. Also, this is redundant to the setting_name + * in NMMetaSettingInfo. */ +#define PROPERTY_INFO_NAME() \ + { \ + .property_name = N_ ("name"), \ + .is_name = TRUE, \ + .property_type = &_pt_name, \ + } + +#define VALUES_STATIC(...) (((const char *[]) { __VA_ARGS__, NULL })) + +#define ENUM_VALUE_INFOS(...) (((const NMUtilsEnumValueInfo []) { __VA_ARGS__, { 0 } })) + +#define GET_FCN_WITH_DEFAULT(type, func) \ + /* macro that returns @func as const (gboolean(*)(NMSetting*)) type, but checks + * that the actual type is (gboolean(*)(type *)). */ \ + ((gboolean (*) (NMSetting *)) ((sizeof (func == ((gboolean (*) (type *)) func))) ? func : func) ) + +#define MTU_GET_FCN(type, func) \ + /* macro that returns @func as const (guint32(*)(NMSetting*)) type, but checks + * that the actual type is (guint32(*)(type *)). */ \ + ((guint32 (*) (NMSetting *)) ((sizeof (func == ((guint32 (*) (type *)) func))) ? func : func) ) + +#define TEAM_DESCRIBE_MESSAGE \ + "nmcli can accepts both direct JSON configuration data and a file name containing " \ + "the configuration. In the latter case the file is read and the contents is put " \ + "into this property.\n\n" \ + "Examples: set team.config " \ + "{ \"device\": \"team0\", \"runner\": {\"name\": \"roundrobin\"}, \"ports\": {\"eth1\": {}, \"eth2\": {}} }\n" \ + " set team.config /etc/my-team.conf\n" + +static const NMMetaPropertyInfo property_infos_802_1x[] = { + PROPERTY_INFO_NAME(), + { + .property_name = N_ (NM_SETTING_802_1X_EAP), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_gobject, + .set_fcn = _set_fcn_gobject_string, + .remove_fcn = _remove_fcn_802_1x_eap, + ), + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + .values_static = VALUES_STATIC ("leap", "md5", "tls", "peap", "ttls", "sim", "fast", "pwd"), + ), + }, + { + .property_name = N_ (NM_SETTING_802_1X_IDENTITY), + .property_type = &_pt_gobject_string, + }, + { + .property_name = N_ (NM_SETTING_802_1X_ANONYMOUS_IDENTITY), + .property_type = &_pt_gobject_string, + }, + { + .property_name = N_ (NM_SETTING_802_1X_PAC_FILE), + .property_type = &_pt_gobject_string, + }, + { + .property_name = N_ (NM_SETTING_802_1X_CA_CERT), + .describe_message = + N_ ("Enter file path to CA certificate (optionally prefixed with file://).\n" + " [file://]<file path>\n" + "Note that nmcli does not support specifying certificates as raw blob data.\n" + "Example: /home/cimrman/cacert.crt\n"), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_802_1x_ca_cert, + .set_fcn = _set_fcn_802_1x_ca_cert, + ), + }, + { + .property_name = N_ (NM_SETTING_802_1X_CA_CERT_PASSWORD), + .is_secret = TRUE, + .property_type = &_pt_gobject_string, + }, + { + .property_name = N_ (NM_SETTING_802_1X_CA_CERT_PASSWORD_FLAGS), + .property_type = &_pt_gobject_secret_flags, + }, + { + .property_name = N_ (NM_SETTING_802_1X_CA_PATH), + .property_type = &_pt_gobject_string, + }, + { + .property_name = N_ (NM_SETTING_802_1X_SUBJECT_MATCH), + .property_type = &_pt_gobject_string, + }, + { + .property_name = N_ (NM_SETTING_802_1X_ALTSUBJECT_MATCHES), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_gobject, + .set_fcn = _set_fcn_802_1x_altsubject_matches, + .remove_fcn = _remove_fcn_802_1x_altsubject_matches, + ), + }, + { + .property_name = N_ (NM_SETTING_802_1X_DOMAIN_SUFFIX_MATCH), + .property_type = &_pt_gobject_string, + }, + { + .property_name = N_ (NM_SETTING_802_1X_CLIENT_CERT), + .describe_message = + N_ ("Enter file path to client certificate (optionally prefixed with file://).\n" + " [file://]<file path>\n" + "Note that nmcli does not support specifying certificates as raw blob data.\n" + "Example: /home/cimrman/jara.crt\n"), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_802_1x_client_cert, + .set_fcn = _set_fcn_802_1x_client_cert, + ), + }, + { + .property_name = N_ (NM_SETTING_802_1X_CLIENT_CERT_PASSWORD), + .is_secret = TRUE, + .property_type = &_pt_gobject_string, + }, + { + .property_name = N_ (NM_SETTING_802_1X_CLIENT_CERT_PASSWORD_FLAGS), + .property_type = &_pt_gobject_secret_flags, + }, + { + .property_name = N_ (NM_SETTING_802_1X_PHASE1_PEAPVER), + .property_type = &_pt_gobject_string, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + .values_static = VALUES_STATIC ("0", "1"), + ), + }, + { + .property_name = N_ (NM_SETTING_802_1X_PHASE1_PEAPLABEL), + .property_type = &_pt_gobject_string, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + .values_static = VALUES_STATIC ("0", "1"), + ), + }, + { + .property_name = N_ (NM_SETTING_802_1X_PHASE1_FAST_PROVISIONING), + .property_type = &_pt_gobject_string, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + .values_static = VALUES_STATIC ("0", "1", "2", "3"), + ), + }, + { + .property_name = N_ (NM_SETTING_802_1X_PHASE1_AUTH_FLAGS), + .property_type = &_pt_gobject_enum, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + PROPERTY_TYP_DATA_SUBTYPE (gobject_enum, + .get_gtype = nm_setting_802_1x_auth_flags_get_type, + ), + .typ_flags = NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PARSABLE_TEXT, + ), + }, + { + .property_name = N_ (NM_SETTING_802_1X_PHASE2_AUTH), + .property_type = &_pt_gobject_string, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + .values_static = VALUES_STATIC ("pap", "chap", "mschap", "mschapv2", "gtc", "otp", "md5", "tls"), + ), + }, + { + .property_name = N_ (NM_SETTING_802_1X_PHASE2_AUTHEAP), + .property_type = &_pt_gobject_string, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + .values_static = VALUES_STATIC ("md5", "mschapv2", "otp", "gtc", "tls"), + ), + }, + { + .property_name = N_ (NM_SETTING_802_1X_PHASE2_CA_CERT), + .describe_message = + N_ ("Enter file path to CA certificate for inner authentication (optionally prefixed\n" + "with file://).\n" + " [file://]<file path>\n" + "Note that nmcli does not support specifying certificates as raw blob data.\n" + "Example: /home/cimrman/ca-zweite-phase.crt\n"), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_802_1x_phase2_ca_cert, + .set_fcn = _set_fcn_802_1x_phase2_ca_cert, + ), + }, + { + .property_name = N_ (NM_SETTING_802_1X_PHASE2_CA_CERT_PASSWORD), + .is_secret = TRUE, + .property_type = &_pt_gobject_string, + }, + { + .property_name = N_ (NM_SETTING_802_1X_PHASE2_CA_CERT_PASSWORD_FLAGS), + .property_type = &_pt_gobject_secret_flags, + }, + { + .property_name = N_ (NM_SETTING_802_1X_PHASE2_CA_PATH), + .property_type = &_pt_gobject_string, + }, + { + .property_name = N_ (NM_SETTING_802_1X_PHASE2_SUBJECT_MATCH), + .property_type = &_pt_gobject_string, + }, + { + .property_name = N_ (NM_SETTING_802_1X_PHASE2_ALTSUBJECT_MATCHES), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_gobject, + .set_fcn = _set_fcn_802_1x_phase2_altsubject_matches, + .remove_fcn = _remove_fcn_802_1x_phase2_altsubject_matches, + ), + }, + { + .property_name = N_ (NM_SETTING_802_1X_PHASE2_DOMAIN_SUFFIX_MATCH), + .property_type = &_pt_gobject_string, + }, + { + .property_name = N_ (NM_SETTING_802_1X_PHASE2_CLIENT_CERT), + .describe_message = + N_ ("Enter file path to client certificate for inner authentication (optionally prefixed\n" + "with file://).\n" + " [file://]<file path>\n" + "Note that nmcli does not support specifying certificates as raw blob data.\n" + "Example: /home/cimrman/jara-zweite-phase.crt\n"), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_802_1x_phase2_client_cert, + .set_fcn = _set_fcn_802_1x_phase2_client_cert, + ), + }, + { + .property_name = N_ (NM_SETTING_802_1X_PHASE2_CLIENT_CERT_PASSWORD), + .is_secret = TRUE, + .property_type = &_pt_gobject_string, + }, + { + .property_name = N_ (NM_SETTING_802_1X_PHASE2_CLIENT_CERT_PASSWORD_FLAGS), + .property_type = &_pt_gobject_secret_flags, + }, + { + .property_name = N_ (NM_SETTING_802_1X_PASSWORD), + .is_secret = TRUE, + .property_type = &_pt_gobject_string, + }, + { + .property_name = N_ (NM_SETTING_802_1X_PASSWORD_FLAGS), + .property_type = &_pt_gobject_secret_flags, + }, + { + .property_name = N_ (NM_SETTING_802_1X_PASSWORD_RAW), + .is_secret = TRUE, + .describe_message = + N_ ("Enter bytes as a list of hexadecimal values.\n" + "Two formats are accepted:\n" + "(a) a string of hexadecimal digits, where each two digits represent one byte\n" + "(b) space-separated list of bytes written as hexadecimal digits " + "(with optional 0x/0X prefix, and optional leading 0).\n\n" + "Examples: ab0455a6ea3a74C2\n" + " ab 4 55 0xa6 ea 3a 74 C2\n"), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_802_1x_password_raw, + .set_fcn = _set_fcn_802_1x_password_raw, + ), + }, + { + .property_name = N_ (NM_SETTING_802_1X_PASSWORD_RAW_FLAGS), + .property_type = &_pt_gobject_secret_flags, + }, + { + .property_name = N_ (NM_SETTING_802_1X_PRIVATE_KEY), + .describe_message = + N_ ("Enter path to a private key and the key password (if not set yet):\n" + " [file://]<file path> [<password>]\n" + "Note that nmcli does not support specifying private key as raw blob data.\n" + "Example: /home/cimrman/jara-priv-key Dardanely\n"), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_802_1x_private_key, + .set_fcn = _set_fcn_802_1x_private_key, + ), + }, + { + .property_name = N_ (NM_SETTING_802_1X_PRIVATE_KEY_PASSWORD), + .is_secret = TRUE, + .property_type = &_pt_gobject_string, + }, + { + .property_name = N_ (NM_SETTING_802_1X_PRIVATE_KEY_PASSWORD_FLAGS), + .property_type = &_pt_gobject_secret_flags, + }, + { + .property_name = N_ (NM_SETTING_802_1X_PHASE2_PRIVATE_KEY), + .describe_message = + N_ ("Enter path to a private key and the key password (if not set yet):\n" + " [file://]<file path> [<password>]\n" + "Note that nmcli does not support specifying private key as raw blob data.\n" + "Example: /home/cimrman/jara-priv-key Dardanely\n"), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_802_1x_phase2_private_key, + .set_fcn = _set_fcn_802_1x_phase2_private_key, + ), + }, + { + .property_name = N_ (NM_SETTING_802_1X_PHASE2_PRIVATE_KEY_PASSWORD), + .is_secret = TRUE, + .property_type = &_pt_gobject_string, + }, + { + .property_name = N_ (NM_SETTING_802_1X_PHASE2_PRIVATE_KEY_PASSWORD_FLAGS), + .property_type = &_pt_gobject_secret_flags, + }, + { + .property_name = N_ (NM_SETTING_802_1X_PIN), + .is_secret = TRUE, + .property_type = &_pt_gobject_string, + }, + { + .property_name = N_ (NM_SETTING_802_1X_PIN_FLAGS), + .property_type = &_pt_gobject_secret_flags, + }, + { + .property_name = N_ (NM_SETTING_802_1X_SYSTEM_CA_CERTS), + .property_type = &_pt_gobject_bool, + }, + { + .property_name = N_ (NM_SETTING_802_1X_AUTH_TIMEOUT), + .property_type = &_pt_gobject_int, + }, +}; + +static const NMMetaPropertyInfo property_infos_adsl[] = { + PROPERTY_INFO_NAME(), + { + .property_name = N_ (NM_SETTING_ADSL_USERNAME), + .property_type = &_pt_gobject_string, + }, + { + .property_name = N_ (NM_SETTING_ADSL_PASSWORD), + .is_secret = TRUE, + .property_type = &_pt_gobject_string, + }, + { + .property_name = N_ (NM_SETTING_ADSL_PASSWORD_FLAGS), + .property_type = &_pt_gobject_secret_flags, + }, + { + .property_name = N_ (NM_SETTING_ADSL_PROTOCOL), + .property_type = &_pt_gobject_string, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + .values_static = VALUES_STATIC (NM_SETTING_ADSL_PROTOCOL_PPPOA, + NM_SETTING_ADSL_PROTOCOL_PPPOE, + NM_SETTING_ADSL_PROTOCOL_IPOATM), + ), + }, + { + .property_name = N_ (NM_SETTING_ADSL_ENCAPSULATION), + .property_type = &_pt_gobject_string, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + .values_static = VALUES_STATIC (NM_SETTING_ADSL_ENCAPSULATION_VCMUX, + NM_SETTING_ADSL_ENCAPSULATION_LLC), + ), + }, + { + .property_name = N_ (NM_SETTING_ADSL_VPI), + .property_type = &_pt_gobject_uint, + }, + { + .property_name = N_ (NM_SETTING_ADSL_VCI), + .property_type = &_pt_gobject_uint, + }, +}; + +static const NMMetaPropertyInfo property_infos_bluetooth[] = { + PROPERTY_INFO_NAME(), + { + .property_name = N_ (NM_SETTING_BLUETOOTH_BDADDR), + .property_type = &_pt_gobject_mac, + }, + { + .property_name = N_ (NM_SETTING_BLUETOOTH_TYPE), + .property_type = &_pt_gobject_string, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + .values_static = VALUES_STATIC (NM_SETTING_BLUETOOTH_TYPE_DUN, + NM_SETTING_BLUETOOTH_TYPE_PANU), + ), + }, +}; + +static const NMMetaPropertyInfo property_infos_bond[] = { + PROPERTY_INFO_NAME(), + { + .property_name = N_ (NM_SETTING_BOND_OPTIONS), + .property_type = DEFINE_PROPERTY_TYPE ( + .describe_fcn = _describe_fcn_bond_options, + .get_fcn = _get_fcn_bond_options, + .set_fcn = _set_fcn_bond_options, + .remove_fcn = _remove_fcn_bond_options, + .values_fcn = _values_fcn_bond_options, + ), + }, +}; + +static const NMMetaPropertyInfo property_infos_bridge[] = { + PROPERTY_INFO_NAME(), + { + .property_name = N_ (NM_SETTING_BRIDGE_MAC_ADDRESS), + .property_type = &_pt_gobject_mac, + }, + { + .property_name = N_ (NM_SETTING_BRIDGE_STP), + .property_type = &_pt_gobject_bool, + }, + { + .property_name = N_ (NM_SETTING_BRIDGE_PRIORITY), + .property_type = &_pt_gobject_uint, + }, + { + .property_name = N_ (NM_SETTING_BRIDGE_FORWARD_DELAY), + .property_type = &_pt_gobject_uint, + }, + { + .property_name = N_ (NM_SETTING_BRIDGE_HELLO_TIME), + .property_type = &_pt_gobject_uint, + }, + { + .property_name = N_ (NM_SETTING_BRIDGE_MAX_AGE), + .property_type = &_pt_gobject_uint, + }, + { + .property_name = N_ (NM_SETTING_BRIDGE_AGEING_TIME), + .property_type = &_pt_gobject_uint, + }, + { + .property_name = N_ (NM_SETTING_BRIDGE_MULTICAST_SNOOPING), + .property_type = &_pt_gobject_bool, + }, +}; + +static const NMMetaPropertyInfo property_infos_bridge_port[] = { + PROPERTY_INFO_NAME(), + { + .property_name = N_ (NM_SETTING_BRIDGE_PORT_PRIORITY), + .property_type = &_pt_gobject_uint, + }, + { + .property_name = N_ (NM_SETTING_BRIDGE_PORT_PATH_COST), + .property_type = &_pt_gobject_uint, + }, + { + .property_name = N_ (NM_SETTING_BRIDGE_PORT_HAIRPIN_MODE), + .property_type = &_pt_gobject_bool, + }, +}; + +static const NMMetaPropertyInfo property_infos_cdma[] = { + PROPERTY_INFO_NAME(), + { + .property_name = N_ (NM_SETTING_CDMA_NUMBER), + .property_type = &_pt_gobject_string, + }, + { + .property_name = N_ (NM_SETTING_CDMA_USERNAME), + .property_type = &_pt_gobject_string, + }, + { + .property_name = N_ (NM_SETTING_CDMA_PASSWORD), + .is_secret = TRUE, + .property_type = &_pt_gobject_string, + }, + { + .property_name = N_ (NM_SETTING_CDMA_PASSWORD_FLAGS), + .property_type = &_pt_gobject_secret_flags, + }, + { + .property_name = N_ (NM_SETTING_CDMA_MTU), + .property_type = &_pt_gobject_mtu, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (mtu, + .get_fcn = MTU_GET_FCN (NMSettingCdma, nm_setting_cdma_get_mtu), + ), + }, +}; + +static const NMMetaPropertyInfo property_infos_connection[] = { + PROPERTY_INFO_NAME(), + { + .property_name = N_ (NM_SETTING_CONNECTION_ID), + .property_type = &_pt_gobject_string, + }, + { + .property_name = N_ (NM_SETTING_CONNECTION_UUID), + .property_type = DEFINE_PROPERTY_TYPE ( .get_fcn = _get_fcn_gobject ), + }, + { + .property_name = N_ (NM_SETTING_CONNECTION_STABLE_ID), + .property_type = &_pt_gobject_string, + }, + { + .property_name = N_ (NM_SETTING_CONNECTION_INTERFACE_NAME), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_gobject, + .set_fcn = _set_fcn_gobject_ifname, + ), + }, + { + .property_name = N_ (NM_SETTING_CONNECTION_TYPE), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_gobject, + .set_fcn = _set_fcn_connection_type, + ), + }, + { + .property_name = N_ (NM_SETTING_CONNECTION_AUTOCONNECT), + .property_type = &_pt_gobject_bool, + }, + { + .property_name = N_ (NM_SETTING_CONNECTION_AUTOCONNECT_PRIORITY), + .property_type = &_pt_gobject_int, + }, + { + .property_name = N_ (NM_SETTING_CONNECTION_AUTOCONNECT_RETRIES), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_connection_autoconnect_retires, + .set_fcn = _set_fcn_gobject_int, + ), + }, + { + .property_name = N_ (NM_SETTING_CONNECTION_TIMESTAMP), + .property_type = &_pt_gobject_readonly, + }, + { + .property_name = N_ (NM_SETTING_CONNECTION_READ_ONLY), + .property_type = &_pt_gobject_readonly, + }, + { + .property_name = N_ (NM_SETTING_CONNECTION_PERMISSIONS), + .describe_message = + N_ ("Enter a list of user permissions. This is a list of user names formatted as:\n" + " [user:]<user name 1>, [user:]<user name 2>,...\n" + "The items can be separated by commas or spaces.\n\n" + "Example: alice bob charlie\n"), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_connection_permissions, + .set_fcn = _set_fcn_connection_permissions, + .remove_fcn = _remove_fcn_connection_permissions, + ), + }, + { + .property_name = N_ (NM_SETTING_CONNECTION_ZONE), + .property_type = &_pt_gobject_string, + }, + { + .property_name = N_ (NM_SETTING_CONNECTION_MASTER), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_gobject, + .set_fcn = _set_fcn_connection_master, + ), + }, + { + .property_name = N_ (NM_SETTING_CONNECTION_SLAVE_TYPE), + .property_type = &_pt_gobject_string, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + .values_static = VALUES_STATIC (NM_SETTING_BOND_SETTING_NAME, + NM_SETTING_BRIDGE_SETTING_NAME, + NM_SETTING_TEAM_SETTING_NAME), + ), + }, + { + .property_name = N_ (NM_SETTING_CONNECTION_AUTOCONNECT_SLAVES), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_connection_autoconnect_slaves, + .set_fcn = _set_fcn_gobject_trilean, + ), + }, + { + .property_name = N_ (NM_SETTING_CONNECTION_SECONDARIES), + .describe_message = + N_ ("Enter secondary connections that should be activated when this connection is\n" + "activated. Connections can be specified either by UUID or ID (name). nmcli\n" + "transparently translates names to UUIDs. Note that NetworkManager only supports\n" + "VPNs as secondary connections at the moment.\n" + "The items can be separated by commas or spaces.\n\n" + "Example: private-openvpn, fe6ba5d8-c2fc-4aae-b2e3-97efddd8d9a7\n"), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_gobject, + .set_fcn = _set_fcn_connection_secondaries, + .remove_fcn = _remove_fcn_connection_secondaries, + ), + }, + { + .property_name = N_ (NM_SETTING_CONNECTION_GATEWAY_PING_TIMEOUT), + .property_type = &_pt_gobject_uint, + }, + { + .property_name = N_ (NM_SETTING_CONNECTION_METERED), + .describe_message = + N_ ("Enter a value which indicates whether the connection is subject to a data\n" + "quota, usage costs or other limitations. Accepted options are:\n" + "'true','yes','on' to set the connection as metered\n" + "'false','no','off' to set the connection as not metered\n" + "'unknown' to let NetworkManager choose a value using some heuristics\n"), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_connection_metered, + .set_fcn = _set_fcn_connection_metered, + ), + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + .values_static = VALUES_STATIC ("yes", "no", "unknown"), + ), + }, + { + .property_name = N_ (NM_SETTING_CONNECTION_LLDP), + .property_type = &_pt_gobject_enum, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + PROPERTY_TYP_DATA_SUBTYPE (gobject_enum, + .get_gtype = nm_setting_connection_lldp_get_type, + .value_infos = ENUM_VALUE_INFOS ( + { + .value = NM_SETTING_CONNECTION_LLDP_ENABLE_RX, + .nick = "enable", + } + ), + ), + .typ_flags = NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PARSABLE_TEXT + | NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PRETTY_TEXT, + ), + }, +}; + +static const NMMetaPropertyInfo property_infos_dcb[] = { + PROPERTY_INFO_NAME(), + { + .property_name = N_ (NM_SETTING_DCB_APP_FCOE_FLAGS), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_dcb_app_fcoe_flags, + .set_fcn = _set_fcn_dcb_flags, + ), + }, + { + .property_name = N_ (NM_SETTING_DCB_APP_FCOE_PRIORITY), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_dcb_app_fcoe_priority, + .set_fcn = _set_fcn_dcb_priority, + ), + }, + { + .property_name = N_ (NM_SETTING_DCB_APP_FCOE_MODE), + .property_type = &_pt_gobject_string, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + .values_static = VALUES_STATIC (NM_SETTING_DCB_FCOE_MODE_FABRIC, + NM_SETTING_DCB_FCOE_MODE_VN2VN), + ), + }, + { + .property_name = N_ (NM_SETTING_DCB_APP_ISCSI_FLAGS), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_dcb_app_iscsi_flags, + .set_fcn = _set_fcn_dcb_flags, + ), + }, + { + .property_name = N_ (NM_SETTING_DCB_APP_ISCSI_PRIORITY), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_dcb_app_iscsi_priority, + .set_fcn = _set_fcn_dcb_priority, + ), + }, + { + .property_name = N_ (NM_SETTING_DCB_APP_FIP_FLAGS), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_dcb_app_fip_flags, + .set_fcn = _set_fcn_dcb_flags, + ), + }, + { + .property_name = N_ (NM_SETTING_DCB_APP_FIP_PRIORITY), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_dcb_app_fip_priority, + .set_fcn = _set_fcn_dcb_priority, + ), + }, + { + .property_name = N_ (NM_SETTING_DCB_PRIORITY_FLOW_CONTROL_FLAGS), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_dcb_priority_flow_control_flags, + .set_fcn = _set_fcn_dcb_flags, + ), + }, + { + .property_name = N_ (NM_SETTING_DCB_PRIORITY_FLOW_CONTROL), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_dcb_priority_flow_control, + .set_fcn = _set_fcn_dcb_priority_flow_control, + ), + }, + { + .property_name = N_ (NM_SETTING_DCB_PRIORITY_GROUP_FLAGS), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_dcb_priority_group_flags, + .set_fcn = _set_fcn_dcb_flags, + ), + }, + { + .property_name = N_ (NM_SETTING_DCB_PRIORITY_GROUP_ID), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_dcb_priority_group_id, + .set_fcn = _set_fcn_dcb_priority_group_id, + ), + }, + { + .property_name = N_ (NM_SETTING_DCB_PRIORITY_GROUP_BANDWIDTH), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_dcb_priority_group_bandwidth, + .set_fcn = _set_fcn_dcb_priority_group_bandwidth, + ), + }, + { + .property_name = N_ (NM_SETTING_DCB_PRIORITY_BANDWIDTH), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_dcb_priority_bandwidth, + .set_fcn = _set_fcn_dcb_priority_bandwidth, + ), + }, + { + .property_name = N_ (NM_SETTING_DCB_PRIORITY_STRICT_BANDWIDTH), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_dcb_priority_strict, + .set_fcn = _set_fcn_dcb_priority_strict, + ), + }, + { + .property_name = N_ (NM_SETTING_DCB_PRIORITY_TRAFFIC_CLASS), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_dcb_priority_traffic_class, + .set_fcn = _set_fcn_dcb_priority_traffic_class, + ), + }, +}; + +static const NMMetaPropertyInfo property_infos_dummy[] = { + PROPERTY_INFO_NAME(), +}; + +static const NMMetaPropertyInfo property_infos_gsm[] = { + PROPERTY_INFO_NAME(), + { + .property_name = N_ (NM_SETTING_GSM_NUMBER), + .property_type = &_pt_gobject_string, + }, + { + .property_name = N_ (NM_SETTING_GSM_USERNAME), + .property_type = &_pt_gobject_string, + }, + { + .property_name = N_ (NM_SETTING_GSM_PASSWORD), + .is_secret = TRUE, + .property_type = &_pt_gobject_string, + }, + { + .property_name = N_ (NM_SETTING_GSM_PASSWORD_FLAGS), + .property_type = &_pt_gobject_secret_flags, + }, + { + .property_name = N_ (NM_SETTING_GSM_APN), + .property_type = &_pt_gobject_string, + }, + { + .property_name = N_ (NM_SETTING_GSM_NETWORK_ID), + .property_type = &_pt_gobject_string, + }, + { + .property_name = N_ (NM_SETTING_GSM_PIN), + .is_secret = TRUE, + .property_type = &_pt_gobject_string, + }, + { + .property_name = N_ (NM_SETTING_GSM_PIN_FLAGS), + .property_type = &_pt_gobject_secret_flags, + }, + { + .property_name = N_ (NM_SETTING_GSM_HOME_ONLY), + .property_type = &_pt_gobject_bool, + }, + { + .property_name = N_ (NM_SETTING_GSM_DEVICE_ID), + .property_type = &_pt_gobject_string, + }, + { + .property_name = N_ (NM_SETTING_GSM_SIM_ID), + .property_type = &_pt_gobject_string, + }, + { + .property_name = N_ (NM_SETTING_GSM_SIM_OPERATOR_ID), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_gobject, + .set_fcn = _set_fcn_gsm_sim_operator_id, + ), + }, + { + .property_name = N_ (NM_SETTING_GSM_MTU), + .property_type = &_pt_gobject_mtu, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (mtu, + .get_fcn = MTU_GET_FCN (NMSettingGsm, nm_setting_gsm_get_mtu), + ), + }, +}; + +static const NMMetaPropertyInfo property_infos_infiniband[] = { + PROPERTY_INFO_NAME(), + { + .property_name = N_ (NM_SETTING_INFINIBAND_MAC_ADDRESS), + .property_type = &_pt_gobject_mac, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (mac, + .mode = NM_META_PROPERTY_TYPE_MAC_MODE_INFINIBAND, + ), + }, + { + .property_name = N_ (NM_SETTING_INFINIBAND_MTU), + .property_type = &_pt_gobject_mtu, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (mtu, + .get_fcn = MTU_GET_FCN (NMSettingInfiniband, nm_setting_infiniband_get_mtu), + ), + }, + { + .property_name = N_ (NM_SETTING_INFINIBAND_TRANSPORT_MODE), + .property_type = &_pt_gobject_string, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + .values_static = VALUES_STATIC ("datagram", "connected"), + ), + }, + { + .property_name = N_ (NM_SETTING_INFINIBAND_P_KEY), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_infiniband_p_key, + .set_fcn = _set_fcn_infiniband_p_key, + ), + }, + { + .property_name = N_ (NM_SETTING_INFINIBAND_PARENT), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_gobject, + .set_fcn = _set_fcn_gobject_ifname, + ), + }, +}; + +static const NMMetaPropertyInfo property_infos_ip4_config[] = { + PROPERTY_INFO_NAME(), + { + .property_name = N_ (NM_SETTING_IP_CONFIG_METHOD), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_gobject, + .set_fcn = _set_fcn_ip4_config_method, + ), + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + .values_static = ipv4_valid_methods, + ), + }, + { + .property_name = N_ (NM_SETTING_IP_CONFIG_DNS), + .describe_message = + N_ ("Enter a list of IPv4 addresses of DNS servers.\n\n" + "Example: 8.8.8.8, 8.8.4.4\n"), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_gobject, + .set_fcn = _set_fcn_ip4_config_dns, + .remove_fcn = _remove_fcn_ipv4_config_dns, + ), + }, + { + .property_name = N_ (NM_SETTING_IP_CONFIG_DNS_SEARCH), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_gobject, + .set_fcn = _set_fcn_ip4_config_dns_search, + .remove_fcn = _remove_fcn_ipv4_config_dns_search, + ), + }, + { + .property_name = N_ (NM_SETTING_IP_CONFIG_DNS_OPTIONS), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_nmc_with_default, + .set_fcn = _set_fcn_ip4_config_dns_options, + .remove_fcn = _remove_fcn_ipv4_config_dns_options, + ), + .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (get_with_default, + .fcn = GET_FCN_WITH_DEFAULT (NMSettingIPConfig, nm_setting_ip_config_has_dns_options), + ), + }, + { + .property_name = N_ (NM_SETTING_IP_CONFIG_DNS_PRIORITY), + .property_type = &_pt_gobject_int, + }, + { + .property_name = N_ (NM_SETTING_IP_CONFIG_ADDRESSES), + .describe_message = + N_ ("Enter a list of IPv4 addresses formatted as:\n" + " ip[/prefix], ip[/prefix],...\n" + "Missing prefix is regarded as prefix of 32.\n\n" + "Example: 192.168.1.5/24, 10.0.0.11/24\n"), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_ip_config_addresses, + .set_fcn = _set_fcn_ip4_config_addresses, + .remove_fcn = _remove_fcn_ipv4_config_addresses, + ), + }, + { + .property_name = N_ (NM_SETTING_IP_CONFIG_GATEWAY), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_gobject, + .set_fcn = _set_fcn_ip4_config_gateway, + ), + }, + { + .property_name = N_ (NM_SETTING_IP_CONFIG_ROUTES), + .describe_message = + N_ ("Enter a list of IPv4 routes formatted as:\n" + " ip[/prefix] [next-hop] [metric],...\n\n" + "Missing prefix is regarded as a prefix of 32.\n" + "Missing next-hop is regarded as 0.0.0.0.\n" + "Missing metric means default (NM/kernel will set a default value).\n\n" + "Examples: 192.168.2.0/24 192.168.2.1 3, 10.1.0.0/16 10.0.0.254\n" + " 10.1.2.0/24\n"), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_ip_config_routes, + .set_fcn = _set_fcn_ip4_config_routes, + .remove_fcn = _remove_fcn_ipv4_config_routes, + ), + }, + { + .property_name = N_ (NM_SETTING_IP_CONFIG_ROUTE_METRIC), + .property_type = &_pt_gobject_int64, + }, + { + .property_name = N_ (NM_SETTING_IP_CONFIG_IGNORE_AUTO_ROUTES), + .property_type = &_pt_gobject_bool, + }, + { + .property_name = N_ (NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS), + .property_type = &_pt_gobject_bool, + }, + { + .property_name = N_ (NM_SETTING_IP4_CONFIG_DHCP_CLIENT_ID), + .property_type = &_pt_gobject_string, + }, + { + .property_name = N_ (NM_SETTING_IP_CONFIG_DHCP_TIMEOUT), + .property_type = &_pt_gobject_int, + }, + { + .property_name = N_ (NM_SETTING_IP_CONFIG_DHCP_SEND_HOSTNAME), + .property_type = &_pt_gobject_bool, + }, + { + .property_name = N_ (NM_SETTING_IP_CONFIG_DHCP_HOSTNAME), + .property_type = &_pt_gobject_string, + }, + { + .property_name = N_ (NM_SETTING_IP4_CONFIG_DHCP_FQDN), + .property_type = &_pt_gobject_string, + }, + { + .property_name = N_ (NM_SETTING_IP_CONFIG_NEVER_DEFAULT), + .property_type = &_pt_gobject_bool, + }, + { + .property_name = N_ (NM_SETTING_IP_CONFIG_MAY_FAIL), + .property_type = &_pt_gobject_bool, + }, + { + .property_name = N_ (NM_SETTING_IP_CONFIG_DAD_TIMEOUT), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_ip4_config_dad_timeout, + .set_fcn = _set_fcn_gobject_int, + ), + }, +}; + +static const NMMetaPropertyInfo property_infos_ip6_config[] = { + PROPERTY_INFO_NAME(), + { + .property_name = N_ (NM_SETTING_IP_CONFIG_METHOD), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_gobject, + .set_fcn = _set_fcn_ip6_config_method, + ), + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + .values_static = ipv6_valid_methods, + ), + }, + { + .property_name = N_ (NM_SETTING_IP_CONFIG_DNS), + .describe_message = + N_ ("Enter a list of IPv6 addresses of DNS servers. If the IPv6 " + "configuration method is 'auto' these DNS servers are appended " + "to those (if any) returned by automatic configuration. DNS " + "servers cannot be used with the 'shared' or 'link-local' IPv6 " + "configuration methods, as there is no upstream network. In " + "all other IPv6 configuration methods, these DNS " + "servers are used as the only DNS servers for this connection.\n\n" + "Example: 2607:f0d0:1002:51::4, 2607:f0d0:1002:51::1\n"), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_gobject, + .set_fcn = _set_fcn_ip6_config_dns, + .remove_fcn = _remove_fcn_ipv6_config_dns, + ), + }, + { + .property_name = N_ (NM_SETTING_IP_CONFIG_DNS_SEARCH), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_gobject, + .set_fcn = _set_fcn_ip6_config_dns_search, + .remove_fcn = _remove_fcn_ipv6_config_dns_search, + ), + }, + { + .property_name = N_ (NM_SETTING_IP_CONFIG_DNS_OPTIONS), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_nmc_with_default, + .set_fcn = _set_fcn_ip6_config_dns_options, + .remove_fcn = _remove_fcn_ipv6_config_dns_options, + ), + .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (get_with_default, + .fcn = GET_FCN_WITH_DEFAULT (NMSettingIPConfig, nm_setting_ip_config_has_dns_options), + ), + }, + { + .property_name = N_ (NM_SETTING_IP_CONFIG_DNS_PRIORITY), + .property_type = &_pt_gobject_int, + }, + { + .property_name = N_ (NM_SETTING_IP_CONFIG_ADDRESSES), + .describe_message = + N_ ("Enter a list of IPv6 addresses formatted as:\n" + " ip[/prefix], ip[/prefix],...\n" + "Missing prefix is regarded as prefix of 128.\n\n" + "Example: 2607:f0d0:1002:51::4/64, 1050:0:0:0:5:600:300c:326b\n"), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_ip_config_addresses, + .set_fcn = _set_fcn_ip6_config_addresses, + .remove_fcn = _remove_fcn_ipv6_config_addresses, + ), + }, + { + .property_name = N_ (NM_SETTING_IP_CONFIG_GATEWAY), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_gobject, + .set_fcn = _set_fcn_ip6_config_gateway, + ), + }, + { + .property_name = N_ (NM_SETTING_IP_CONFIG_ROUTES), + .describe_message = + N_ ("Enter a list of IPv6 routes formatted as:\n" + " ip[/prefix] [next-hop] [metric],...\n\n" + "Missing prefix is regarded as a prefix of 128.\n" + "Missing next-hop is regarded as \"::\".\n" + "Missing metric means default (NM/kernel will set a default value).\n\n" + "Examples: 2001:db8:beef:2::/64 2001:db8:beef::2, 2001:db8:beef:3::/64 2001:db8:beef::3 2\n" + " abbe::/64 55\n"), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_ip_config_routes, + .set_fcn = _set_fcn_ip6_config_routes, + .remove_fcn = _remove_fcn_ipv6_config_routes, + ), + }, + { + .property_name = N_ (NM_SETTING_IP_CONFIG_ROUTE_METRIC), + .property_type = &_pt_gobject_int64, + }, + { + .property_name = N_ (NM_SETTING_IP_CONFIG_IGNORE_AUTO_ROUTES), + .property_type = &_pt_gobject_bool, + }, + { + .property_name = N_ (NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS), + .property_type = &_pt_gobject_bool, + }, + { + .property_name = N_ (NM_SETTING_IP_CONFIG_NEVER_DEFAULT), + .property_type = &_pt_gobject_bool, + }, + { + .property_name = N_ (NM_SETTING_IP_CONFIG_MAY_FAIL), + .property_type = &_pt_gobject_bool, + }, + { + .property_name = N_ (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_name = N_ (NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE), + .property_type = &_pt_gobject_enum, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + PROPERTY_TYP_DATA_SUBTYPE (gobject_enum, + .get_gtype = nm_setting_ip6_config_addr_gen_mode_get_type, + ), + .typ_flags = NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PARSABLE_TEXT + | NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PRETTY_TEXT, + ), + }, + { + .property_name = N_ (NM_SETTING_IP_CONFIG_DHCP_SEND_HOSTNAME), + .property_type = &_pt_gobject_bool, + }, + { + .property_name = N_ (NM_SETTING_IP_CONFIG_DHCP_HOSTNAME), + .property_type = &_pt_gobject_string, + }, + { + .property_name = N_ (NM_SETTING_IP6_CONFIG_TOKEN), + .property_type = &_pt_gobject_string, + }, +}; + +static const NMMetaPropertyInfo property_infos_ip_tunnel[] = { + PROPERTY_INFO_NAME(), + { + .property_name = N_ (NM_SETTING_IP_TUNNEL_MODE), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_ip_tunnel_mode, + .set_fcn = _set_fcn_ip_tunnel_mode, + .values_fcn = _values_fcn_gobject_enum, + ), + .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (gobject_enum, + .get_gtype = nm_ip_tunnel_mode_get_type, + .min = NM_IP_TUNNEL_MODE_UNKNOWN + 1, + .max = G_MAXINT, + ), + }, + { + .property_name = N_ (NM_SETTING_IP_TUNNEL_PARENT), + .property_type = &_pt_gobject_string, + }, + { + .property_name = N_ (NM_SETTING_IP_TUNNEL_LOCAL), + .property_type = &_pt_gobject_string, + }, + { + .property_name = N_ (NM_SETTING_IP_TUNNEL_REMOTE), + .property_type = &_pt_gobject_string, + }, + { + .property_name = N_ (NM_SETTING_IP_TUNNEL_TTL), + .property_type = &_pt_gobject_uint, + }, + { + .property_name = N_ (NM_SETTING_IP_TUNNEL_TOS), + .property_type = &_pt_gobject_uint, + }, + { + .property_name = N_ (NM_SETTING_IP_TUNNEL_PATH_MTU_DISCOVERY), + .property_type = &_pt_gobject_bool, + }, + { + .property_name = N_ (NM_SETTING_IP_TUNNEL_INPUT_KEY), + .property_type = &_pt_gobject_string, + }, + { + .property_name = N_ (NM_SETTING_IP_TUNNEL_OUTPUT_KEY), + .property_type = &_pt_gobject_string, + }, + { + .property_name = N_ (NM_SETTING_IP_TUNNEL_ENCAPSULATION_LIMIT), + .property_type = &_pt_gobject_uint, + }, + { + .property_name = N_ (NM_SETTING_IP_TUNNEL_FLOW_LABEL), + .property_type = &_pt_gobject_uint, + }, + { + .property_name = N_ (NM_SETTING_IP_TUNNEL_MTU), + .property_type = &_pt_gobject_mtu, + }, +}; + +static const NMMetaPropertyInfo property_infos_macsec[] = { + PROPERTY_INFO_NAME(), + { + .property_name = N_ (NM_SETTING_MACSEC_PARENT), + .property_type = &_pt_gobject_string, + }, + { + .property_name = N_ (NM_SETTING_MACSEC_MODE), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_macsec_mode, + .set_fcn = _set_fcn_macsec_mode, + .values_fcn = _values_fcn_gobject_enum, + ), + .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (gobject_enum, + .get_gtype = nm_setting_macsec_mode_get_type, + ), + }, + { + .property_name = N_ (NM_SETTING_MACSEC_ENCRYPT), + .property_type = &_pt_gobject_bool, + }, + { + .property_name = N_ (NM_SETTING_MACSEC_MKA_CAK), + .is_secret = TRUE, + .property_type = &_pt_gobject_string, + }, + { + .property_name = N_ (NM_SETTING_MACSEC_MKA_CAK_FLAGS), + .property_type = &_pt_gobject_secret_flags, + }, + { + .property_name = N_ (NM_SETTING_MACSEC_MKA_CKN), + .property_type = &_pt_gobject_string, + }, + { + .property_name = N_ (NM_SETTING_MACSEC_PORT), + .property_type = &_pt_gobject_int, + }, + { + .property_name = N_ (NM_SETTING_MACSEC_VALIDATION), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_macsec_validation, + .set_fcn = _set_fcn_macsec_validation, + .values_fcn = _values_fcn_gobject_enum, + ), + .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (gobject_enum, + .get_gtype = nm_setting_macsec_validation_get_type, + ), + }, +}; + +static const NMMetaPropertyInfo property_infos_macvlan[] = { + PROPERTY_INFO_NAME(), + { + .property_name = N_ (NM_SETTING_MACVLAN_PARENT), + .property_type = &_pt_gobject_string, + }, + { + .property_name = N_ (NM_SETTING_MACVLAN_MODE), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_macvlan_mode, + .set_fcn = _set_fcn_macvlan_mode, + .values_fcn = _values_fcn_gobject_enum, + ), + .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (gobject_enum, + .get_gtype = nm_setting_macvlan_mode_get_type, + .min = NM_SETTING_MACVLAN_MODE_UNKNOWN + 1, + .max = G_MAXINT, + ), + }, + { + .property_name = N_ (NM_SETTING_MACVLAN_PROMISCUOUS), + .property_type = &_pt_gobject_bool, + }, + { + .property_name = N_ (NM_SETTING_MACVLAN_TAP), + .property_type = &_pt_gobject_bool, + }, +}; + +static const NMMetaPropertyInfo property_infos_olpc_mesh[] = { + PROPERTY_INFO_NAME(), + { + .property_name = N_ (NM_SETTING_OLPC_MESH_SSID), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_olpc_mesh_ssid, + .set_fcn = _set_fcn_gobject_ssid, + ), + }, + { + .property_name = N_ (NM_SETTING_OLPC_MESH_CHANNEL), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_gobject, + .set_fcn = _set_fcn_olpc_mesh_channel, + ), + }, + { + .property_name = N_ (NM_SETTING_OLPC_MESH_DHCP_ANYCAST_ADDRESS), + .property_type = &_pt_gobject_mac, + }, +}; + +static const NMMetaPropertyInfo property_infos_pppoe[] = { + PROPERTY_INFO_NAME (), + { + .property_name = N_ (NM_SETTING_PPPOE_SERVICE), + .property_type = &_pt_gobject_string, + }, + { + .property_name = N_ (NM_SETTING_PPPOE_USERNAME), + .property_type = &_pt_gobject_string, + }, + { + .property_name = N_ (NM_SETTING_PPPOE_PASSWORD), + .is_secret = TRUE, + .property_type = &_pt_gobject_string, + }, + { + .property_name = N_ (NM_SETTING_PPPOE_PASSWORD_FLAGS), + .property_type = &_pt_gobject_secret_flags, + }, +}; + +static const NMMetaPropertyInfo property_infos_ppp[] = { + PROPERTY_INFO_NAME (), + { + .property_name = N_ (NM_SETTING_PPP_NOAUTH), + .property_type = &_pt_gobject_bool, + }, + { + .property_name = N_ (NM_SETTING_PPP_REFUSE_EAP), + .property_type = &_pt_gobject_bool, + }, + { + .property_name = N_ (NM_SETTING_PPP_REFUSE_PAP), + .property_type = &_pt_gobject_bool, + }, + { + .property_name = N_ (NM_SETTING_PPP_REFUSE_CHAP), + .property_type = &_pt_gobject_bool, + }, + { + .property_name = N_ (NM_SETTING_PPP_REFUSE_MSCHAP), + .property_type = &_pt_gobject_bool, + }, + { + .property_name = N_ (NM_SETTING_PPP_REFUSE_MSCHAPV2), + .property_type = &_pt_gobject_bool, + }, + { + .property_name = N_ (NM_SETTING_PPP_NOBSDCOMP), + .property_type = &_pt_gobject_bool, + }, + { + .property_name = N_ (NM_SETTING_PPP_NODEFLATE), + .property_type = &_pt_gobject_bool, + }, + { + .property_name = N_ (NM_SETTING_PPP_NO_VJ_COMP), + .property_type = &_pt_gobject_bool, + }, + { + .property_name = N_ (NM_SETTING_PPP_REQUIRE_MPPE), + .property_type = &_pt_gobject_bool, + }, + { + .property_name = N_ (NM_SETTING_PPP_REQUIRE_MPPE_128), + .property_type = &_pt_gobject_bool, + }, + { + .property_name = N_ (NM_SETTING_PPP_MPPE_STATEFUL), + .property_type = &_pt_gobject_bool, + }, + { + .property_name = N_ (NM_SETTING_PPP_CRTSCTS), + .property_type = &_pt_gobject_bool, + }, + { + .property_name = N_ (NM_SETTING_PPP_BAUD), + .property_type = &_pt_gobject_uint, + }, + { + .property_name = N_ (NM_SETTING_PPP_MRU), + .property_type = &_pt_gobject_uint, + }, + { + .property_name = N_ (NM_SETTING_PPP_MTU), + .property_type = &_pt_gobject_mtu, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (mtu, + .get_fcn = MTU_GET_FCN (NMSettingPpp, nm_setting_ppp_get_mtu), + ), + }, + { + .property_name = N_ (NM_SETTING_PPP_LCP_ECHO_FAILURE), + .property_type = &_pt_gobject_uint, + }, + { + .property_name = N_ (NM_SETTING_PPP_LCP_ECHO_INTERVAL), + .property_type = &_pt_gobject_uint, + }, +}; + +static const NMMetaPropertyInfo property_infos_proxy[] = { + PROPERTY_INFO_NAME(), + { + .property_name = N_ (NM_SETTING_PROXY_METHOD), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_proxy_method, + .set_fcn = _set_fcn_proxy_method, + .values_fcn = _values_fcn_gobject_enum, + ), + .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (gobject_enum, + .get_gtype = nm_setting_proxy_method_get_type, + .min = NM_SETTING_PROXY_METHOD_NONE, + .max = G_MAXINT, + ), + }, + { + .property_name = N_ (NM_SETTING_PROXY_BROWSER_ONLY), + .property_type = &_pt_gobject_bool + }, + { + .property_name = N_ (NM_SETTING_PROXY_PAC_URL), + .property_type = &_pt_gobject_string, + }, + { + .property_name = N_ (NM_SETTING_PROXY_PAC_SCRIPT), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_gobject, + .set_fcn = _set_fcn_proxy_pac_script, + ), + }, +}; + +static const NMMetaPropertyInfo property_infos_team[] = { + PROPERTY_INFO_NAME(), + { + .property_name = N_ (NM_SETTING_TEAM_CONFIG), + .describe_message = N_ (TEAM_DESCRIBE_MESSAGE), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_gobject, + .set_fcn = _set_fcn_team_config, + ), + }, +}; + +static const NMMetaPropertyInfo property_infos_team_port[] = { + PROPERTY_INFO_NAME(), + { + .property_name = N_ (NM_SETTING_TEAM_PORT_CONFIG), + .describe_message = N_ (TEAM_DESCRIBE_MESSAGE), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_gobject, + .set_fcn = _set_fcn_team_config, + ), + }, +}; + +static const NMMetaPropertyInfo property_infos_serial[] = { + PROPERTY_INFO_NAME(), + { + .property_name = N_ (NM_SETTING_SERIAL_BAUD), + .property_type = &_pt_gobject_uint, + }, + { + .property_name = N_ (NM_SETTING_SERIAL_BITS), + .property_type = &_pt_gobject_uint, + }, + { + .property_name = N_ (NM_SETTING_SERIAL_PARITY), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_serial_parity, + .set_fcn = _set_fcn_serial_parity, + ), + }, + { + .property_name = N_ (NM_SETTING_SERIAL_STOPBITS), + .property_type = &_pt_gobject_uint, + }, + { + .property_name = N_ (NM_SETTING_SERIAL_SEND_DELAY), + .property_type = &_pt_gobject_uint, + }, +}; + +static const NMMetaPropertyInfo property_infos_tun[] = { + PROPERTY_INFO_NAME(), + { + .property_name = N_ (NM_SETTING_TUN_MODE), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_tun_mode, + .set_fcn = _set_fcn_tun_mode, + ), + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + .values_static = VALUES_STATIC ("tun", "tap", "unknown"), + ), + }, + { + .property_name = N_ (NM_SETTING_TUN_OWNER), + .property_type = &_pt_gobject_string, + }, + { + .property_name = N_ (NM_SETTING_TUN_GROUP), + .property_type = &_pt_gobject_string, + }, + { + .property_name = N_ (NM_SETTING_TUN_PI), + .property_type = &_pt_gobject_bool, + }, + { + .property_name = N_ (NM_SETTING_TUN_VNET_HDR), + .property_type = &_pt_gobject_bool, + }, + { + .property_name = N_ (NM_SETTING_TUN_MULTI_QUEUE), + .property_type = &_pt_gobject_bool, + }, +}; + +static const NMMetaPropertyInfo property_infos_user[] = { + PROPERTY_INFO_NAME(), +}; + +static const NMMetaPropertyInfo property_infos_vlan[] = { + PROPERTY_INFO_NAME(), + { + .property_name = N_ (NM_SETTING_VLAN_PARENT), + .property_type = &_pt_gobject_string, + }, + { + .property_name = N_ (NM_SETTING_VLAN_ID), + .property_type = &_pt_gobject_uint, + }, + { + .property_name = N_ (NM_SETTING_VLAN_FLAGS), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_vlan_flags, + .set_fcn = _set_fcn_gobject_flags, + ), + }, + { + .property_name = N_ (NM_SETTING_VLAN_INGRESS_PRIORITY_MAP), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_vlan_ingress_priority_map, + .set_fcn = _set_fcn_vlan_ingress_priority_map, + .remove_fcn = _remove_fcn_vlan_ingress_priority_map, + ), + }, + { + .property_name = N_ (NM_SETTING_VLAN_EGRESS_PRIORITY_MAP), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_vlan_egress_priority_map, + .set_fcn = _set_fcn_vlan_egress_priority_map, + .remove_fcn = _remove_fcn_vlan_egress_priority_map, + ), + }, +}; + +static const NMMetaPropertyInfo property_infos_vpn[] = { + PROPERTY_INFO_NAME(), + { + .property_name = N_ (NM_SETTING_VPN_SERVICE_TYPE), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_gobject, + .set_fcn = _set_fcn_vpn_service_type, + ), + }, + { + .property_name = N_ (NM_SETTING_VPN_USER_NAME), + .property_type = &_pt_gobject_string, + }, + { + .property_name = N_ (NM_SETTING_VPN_DATA), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_vpn_data, + .set_fcn = _set_fcn_vpn_data, + .remove_fcn = _remove_fcn_vpn_data, + ), + }, + { + .property_name = N_ (NM_SETTING_VPN_SECRETS), + .is_secret = TRUE, + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_vpn_secrets, + .set_fcn = _set_fcn_vpn_secrets, + .remove_fcn = _remove_fcn_vpn_secrets, + ), + }, + { + .property_name = N_ (NM_SETTING_VPN_PERSISTENT), + .property_type = &_pt_gobject_bool, + }, + { + .property_name = N_ (NM_SETTING_VPN_TIMEOUT), + .property_type = &_pt_gobject_uint, + }, +}; + +static const NMMetaPropertyInfo property_infos_vxlan[] = { + PROPERTY_INFO_NAME(), + { + .property_name = N_ (NM_SETTING_VXLAN_PARENT), + .property_type = &_pt_gobject_string, + }, + { + .property_name = N_ (NM_SETTING_VXLAN_ID), + .property_type = &_pt_gobject_uint, + }, + { + .property_name = N_ (NM_SETTING_VXLAN_LOCAL), + .property_type = &_pt_gobject_string, + }, + { + .property_name = N_ (NM_SETTING_VXLAN_REMOTE), + .property_type = &_pt_gobject_string, + }, + { + .property_name = N_ (NM_SETTING_VXLAN_SOURCE_PORT_MIN), + .property_type = &_pt_gobject_uint, + }, + { + .property_name = N_ (NM_SETTING_VXLAN_SOURCE_PORT_MAX), + .property_type = &_pt_gobject_uint, + }, + { + .property_name = N_ (NM_SETTING_VXLAN_DESTINATION_PORT), + .property_type = &_pt_gobject_uint, + }, + { + .property_name = N_ (NM_SETTING_VXLAN_TOS), + .property_type = &_pt_gobject_uint, + }, + { + .property_name = N_ (NM_SETTING_VXLAN_TTL), + .property_type = &_pt_gobject_uint, + }, + { + .property_name = N_ (NM_SETTING_VXLAN_AGEING), + .property_type = &_pt_gobject_uint, + }, + { + .property_name = N_ (NM_SETTING_VXLAN_LIMIT), + .property_type = &_pt_gobject_uint, + }, + { + .property_name = N_ (NM_SETTING_VXLAN_LEARNING), + .property_type = &_pt_gobject_bool, + }, + { + .property_name = N_ (NM_SETTING_VXLAN_PROXY), + .property_type = &_pt_gobject_bool, + }, + { + .property_name = N_ (NM_SETTING_VXLAN_RSC), + .property_type = &_pt_gobject_bool, + }, + { + .property_name = N_ (NM_SETTING_VXLAN_L2_MISS), + .property_type = &_pt_gobject_bool, + }, + { + .property_name = N_ (NM_SETTING_VXLAN_L3_MISS), + .property_type = &_pt_gobject_bool, + }, +}; + +static const NMMetaPropertyInfo property_infos_wimax[] = { + PROPERTY_INFO_NAME(), + { + .property_name = N_ (NM_SETTING_WIMAX_MAC_ADDRESS), + .property_type = &_pt_gobject_string, + }, + { + .property_name = N_ (NM_SETTING_WIMAX_NETWORK_NAME), + .property_type = &_pt_gobject_mac, + }, +}; + +static const NMMetaPropertyInfo property_infos_wired[] = { + PROPERTY_INFO_NAME(), + { + .property_name = N_ (NM_SETTING_WIRED_PORT), + /* Do not allow setting 'port' for now. It is not implemented in + * NM core, nor in ifcfg-rh plugin. Enable this when it gets done. + * wired_valid_ports[] = { "tp", "aui", "bnc", "mii", NULL }; + */ + .property_type = &_pt_gobject_readonly, + }, + { + .property_name = N_ (NM_SETTING_WIRED_SPEED), + .property_type = &_pt_gobject_uint, + }, + { + .property_name = N_ (NM_SETTING_WIRED_DUPLEX), + .property_type = &_pt_gobject_string, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + .values_static = VALUES_STATIC ("half", "full"), + ), + }, + { + .property_name = N_ (NM_SETTING_WIRED_AUTO_NEGOTIATE), + .property_type = &_pt_gobject_bool, + }, + { + .property_name = N_ (NM_SETTING_WIRED_MAC_ADDRESS), + .property_type = &_pt_gobject_mac, + }, + { + .property_name = N_ (NM_SETTING_WIRED_CLONED_MAC_ADDRESS), + .property_type = &_pt_gobject_mac, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (mac, + .mode = NM_META_PROPERTY_TYPE_MAC_MODE_CLONED, + ), + }, + { + .property_name = N_ (NM_SETTING_WIRED_GENERATE_MAC_ADDRESS_MASK), + .property_type = &_pt_gobject_string, + }, + { + .property_name = N_ (NM_SETTING_WIRED_MAC_ADDRESS_BLACKLIST), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_gobject, + .set_fcn = _set_fcn_wired_mac_address_blacklist, + .remove_fcn = _remove_fcn_wired_mac_address_blacklist, + ), + }, + { + .property_name = N_ (NM_SETTING_WIRED_MTU), + .property_type = &_pt_gobject_mtu, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (mtu, + .get_fcn = MTU_GET_FCN (NMSettingWired, nm_setting_wired_get_mtu), + ), + }, + { + .property_name = N_ (NM_SETTING_WIRED_S390_SUBCHANNELS), + .describe_message = + N_ ("Enter a list of subchannels (comma or space separated).\n\n" + "Example: 0.0.0e20 0.0.0e21 0.0.0e22\n"), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_gobject, + .set_fcn = _set_fcn_wired_s390_subchannels, + ), + }, + { + .property_name = N_ (NM_SETTING_WIRED_S390_NETTYPE), + .property_type = &_pt_gobject_string, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + .values_static = VALUES_STATIC ("qeth", "lcs", "ctc"), + ), + }, + { + .property_name = N_ (NM_SETTING_WIRED_S390_OPTIONS), + .property_type = DEFINE_PROPERTY_TYPE ( + .describe_fcn = _describe_fcn_wired_s390_options, + .get_fcn = _get_fcn_gobject, + .set_fcn = _set_fcn_wired_s390_options, + .remove_fcn = _remove_fcn_wired_s390_options, + .values_fcn = _values_fcn__wired_s390_options, + ), + }, + { + .property_name = N_ (NM_SETTING_WIRED_WAKE_ON_LAN), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_wired_wake_on_lan, + .set_fcn = _set_fcn_wired_wake_on_lan, + ), + }, + { + .property_name = N_ (NM_SETTING_WIRED_WAKE_ON_LAN_PASSWORD), + .property_type = &_pt_gobject_mac, + }, +}; + +static const NMMetaPropertyInfo property_infos_wireless[] = { + PROPERTY_INFO_NAME(), + { + .property_name = N_ (NM_SETTING_WIRELESS_SSID), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_wireless_ssid, + .set_fcn = _set_fcn_gobject_ssid, + ), + }, + { + .property_name = N_ (NM_SETTING_WIRELESS_MODE), + .property_type = &_pt_gobject_string, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + .values_static = VALUES_STATIC (NM_SETTING_WIRELESS_MODE_INFRA, + NM_SETTING_WIRELESS_MODE_ADHOC, + NM_SETTING_WIRELESS_MODE_AP), + ), + }, + { + .property_name = N_ (NM_SETTING_WIRELESS_BAND), + .property_type = &_pt_gobject_string, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + .values_static = VALUES_STATIC ("a", "bg"), + ), + }, + { + .property_name = N_ (NM_SETTING_WIRELESS_CHANNEL), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_gobject, + .set_fcn = _set_fcn_wireless_channel, + ), + }, + { + .property_name = N_ (NM_SETTING_WIRELESS_BSSID), + .property_type = &_pt_gobject_mac, + }, + { + .property_name = N_ (NM_SETTING_WIRELESS_RATE), + /* Do not allow setting 'rate'. It is not implemented in NM core. */ + .property_type = &_pt_gobject_readonly, + }, + { + .property_name = N_ (NM_SETTING_WIRELESS_TX_POWER), + /* Do not allow setting 'tx-power'. It is not implemented in NM core. */ + .property_type = &_pt_gobject_readonly, + }, + { + .property_name = N_ (NM_SETTING_WIRELESS_MAC_ADDRESS), + .property_type = &_pt_gobject_mac, + }, + { + .property_name = N_ (NM_SETTING_WIRELESS_CLONED_MAC_ADDRESS), + .property_type = &_pt_gobject_mac, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (mac, + .mode = NM_META_PROPERTY_TYPE_MAC_MODE_CLONED, + ), + }, + { + .property_name = N_ (NM_SETTING_WIRELESS_GENERATE_MAC_ADDRESS_MASK), + .property_type = &_pt_gobject_string, + }, + { + .property_name = N_ (NM_SETTING_WIRELESS_MAC_ADDRESS_BLACKLIST), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_gobject, + .set_fcn = _set_fcn_wireless_mac_address_blacklist, + .remove_fcn = _remove_fcn_wireless_mac_address_blacklist, + ), + }, + { + .property_name = N_ (NM_SETTING_WIRELESS_MAC_ADDRESS_RANDOMIZATION), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_wireless_mac_address_randomization, + .set_fcn = _set_fcn_wireless_mac_address_randomization, + ), + }, + { + .property_name = N_ (NM_SETTING_WIRELESS_MTU), + .property_type = &_pt_gobject_mtu, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (mtu, + .get_fcn = MTU_GET_FCN (NMSettingWireless, nm_setting_wireless_get_mtu), + ), + }, + { + .property_name = N_ (NM_SETTING_WIRELESS_SEEN_BSSIDS), + .property_type = &_pt_gobject_readonly, + }, + { + .property_name = N_ (NM_SETTING_WIRELESS_HIDDEN), + .property_type = &_pt_gobject_bool, + }, + { + .property_name = N_ (NM_SETTING_WIRELESS_POWERSAVE), + .property_type = &_pt_gobject_enum, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + PROPERTY_TYP_DATA_SUBTYPE (gobject_enum, + .get_gtype = nm_setting_wireless_powersave_get_type, + ), + .typ_flags = NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PARSABLE_TEXT, + ), + }, +}; + +static const NMMetaPropertyInfo property_infos_wireless_security[] = { + PROPERTY_INFO_NAME(), + { + .property_name = N_ (NM_SETTING_WIRELESS_SECURITY_KEY_MGMT), + .property_type = &_pt_gobject_string, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + .values_static = VALUES_STATIC ("none", "ieee8021x", "wpa-none", "wpa-psk", "wpa-eap"), + ), + }, + { + .property_name = N_ (NM_SETTING_WIRELESS_SECURITY_WEP_TX_KEYIDX), + .property_type = &_pt_gobject_uint, + }, + { + .property_name = N_ (NM_SETTING_WIRELESS_SECURITY_AUTH_ALG), + .property_type = &_pt_gobject_string, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + .values_static = VALUES_STATIC ("open", "shared", "leap"), + ), + }, + { + .property_name = N_ (NM_SETTING_WIRELESS_SECURITY_PROTO), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_gobject, + .set_fcn = _set_fcn_wireless_security_proto, + .remove_fcn = _remove_fcn_wireless_security_proto, + ), + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + .values_static = wifi_sec_valid_protos, + ), + }, + { + .property_name = N_ (NM_SETTING_WIRELESS_SECURITY_PAIRWISE), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_gobject, + .set_fcn = _set_fcn_wireless_security_pairwise, + .remove_fcn = _remove_fcn_wireless_security_pairwise, + ), + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + .values_static = wifi_sec_valid_pairwises, + ), + }, + { + .property_name = N_ (NM_SETTING_WIRELESS_SECURITY_GROUP), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_gobject, + .set_fcn = _set_fcn_wireless_security_group, + .remove_fcn = _remove_fcn_wireless_security_group, + ), + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + .values_static = wifi_sec_valid_groups, + ), + }, + { + .property_name = N_ (NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME), + .property_type = &_pt_gobject_string, + }, + { + .property_name = N_ (NM_SETTING_WIRELESS_SECURITY_WEP_KEY0), + .is_secret = TRUE, + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_wireless_security_wep_key0, + .set_fcn = _set_fcn_wireless_wep_key, + ), + }, + { + .property_name = N_ (NM_SETTING_WIRELESS_SECURITY_WEP_KEY1), + .is_secret = TRUE, + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_wireless_security_wep_key1, + .set_fcn = _set_fcn_wireless_wep_key, + ), + }, + { + .property_name = N_ (NM_SETTING_WIRELESS_SECURITY_WEP_KEY2), + .is_secret = TRUE, + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_wireless_security_wep_key2, + .set_fcn = _set_fcn_wireless_wep_key, + ), + }, + { + .property_name = N_ (NM_SETTING_WIRELESS_SECURITY_WEP_KEY3), + .is_secret = TRUE, + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_wireless_security_wep_key3, + .set_fcn = _set_fcn_wireless_wep_key, + ), + }, + { + .property_name = N_ (NM_SETTING_WIRELESS_SECURITY_WEP_KEY_FLAGS), + .property_type = &_pt_gobject_secret_flags, + }, + { + .property_name = N_ (NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE), + .describe_message = + N_ ("Enter the type of WEP keys. The accepted values are: " + "0 or unknown, 1 or key, and 2 or passphrase.\n"), + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_wireless_security_wep_key_type, + .set_fcn = _set_fcn_wireless_security_wep_key_type, + ), + }, + { + .property_name = N_ (NM_SETTING_WIRELESS_SECURITY_PSK), + .is_secret = TRUE, + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_gobject, + .set_fcn = _set_fcn_wireless_security_psk, + ), + }, + { + .property_name = N_ (NM_SETTING_WIRELESS_SECURITY_PSK_FLAGS), + .property_type = &_pt_gobject_secret_flags, + }, + { + .property_name = N_ (NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD), + .is_secret = TRUE, + .property_type = &_pt_gobject_string, + }, + { + .property_name = N_ (NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD_FLAGS), + .property_type = &_pt_gobject_secret_flags, + }, +}; + +const NMMetaSettingInfoEditor nm_meta_setting_infos_editor[_NM_META_SETTING_TYPE_NUM] = { + [NM_META_SETTING_TYPE_802_1X] = { + .general = &nm_meta_setting_infos[NM_META_SETTING_TYPE_802_1X], + .properties = property_infos_802_1x, + .properties_num = G_N_ELEMENTS (property_infos_802_1x), + }, + [NM_META_SETTING_TYPE_ADSL] = { + .general = &nm_meta_setting_infos[NM_META_SETTING_TYPE_ADSL], + .properties = property_infos_adsl, + .properties_num = G_N_ELEMENTS (property_infos_adsl), + }, + [NM_META_SETTING_TYPE_BLUETOOTH] = { + .general = &nm_meta_setting_infos[NM_META_SETTING_TYPE_BLUETOOTH], + .properties = property_infos_bluetooth, + .properties_num = G_N_ELEMENTS (property_infos_bluetooth), + }, + [NM_META_SETTING_TYPE_BOND] = { + .general = &nm_meta_setting_infos[NM_META_SETTING_TYPE_BOND], + .properties = property_infos_bond, + .properties_num = G_N_ELEMENTS (property_infos_bond), + }, + [NM_META_SETTING_TYPE_BRIDGE] = { + .general = &nm_meta_setting_infos[NM_META_SETTING_TYPE_BRIDGE], + .properties = property_infos_bridge, + .properties_num = G_N_ELEMENTS (property_infos_bridge), + }, + [NM_META_SETTING_TYPE_BRIDGE_PORT] = { + .general = &nm_meta_setting_infos[NM_META_SETTING_TYPE_BRIDGE_PORT], + .properties = property_infos_bridge_port, + .properties_num = G_N_ELEMENTS (property_infos_bridge_port), + }, + [NM_META_SETTING_TYPE_CDMA] = { + .general = &nm_meta_setting_infos[NM_META_SETTING_TYPE_CDMA], + .properties = property_infos_cdma, + .properties_num = G_N_ELEMENTS (property_infos_cdma), + }, + [NM_META_SETTING_TYPE_CONNECTION] = { + .general = &nm_meta_setting_infos[NM_META_SETTING_TYPE_CONNECTION], + .properties = property_infos_connection, + .properties_num = G_N_ELEMENTS (property_infos_connection), + }, + [NM_META_SETTING_TYPE_DCB] = { + .general = &nm_meta_setting_infos[NM_META_SETTING_TYPE_DCB], + .properties = property_infos_dcb, + .properties_num = G_N_ELEMENTS (property_infos_dcb), + }, + [NM_META_SETTING_TYPE_DUMMY] = { + .general = &nm_meta_setting_infos[NM_META_SETTING_TYPE_DUMMY], + .properties = property_infos_dummy, + .properties_num = G_N_ELEMENTS (property_infos_dummy), + }, + [NM_META_SETTING_TYPE_GSM] = { + .general = &nm_meta_setting_infos[NM_META_SETTING_TYPE_GSM], + .properties = property_infos_gsm, + .properties_num = G_N_ELEMENTS (property_infos_gsm), + }, + [NM_META_SETTING_TYPE_INFINIBAND] = { + .general = &nm_meta_setting_infos[NM_META_SETTING_TYPE_INFINIBAND], + .properties = property_infos_infiniband, + .properties_num = G_N_ELEMENTS (property_infos_infiniband), + }, + [NM_META_SETTING_TYPE_IP4_CONFIG] = { + .general = &nm_meta_setting_infos[NM_META_SETTING_TYPE_IP4_CONFIG], + .properties = property_infos_ip4_config, + .properties_num = G_N_ELEMENTS (property_infos_ip4_config), + }, + [NM_META_SETTING_TYPE_IP6_CONFIG] = { + .general = &nm_meta_setting_infos[NM_META_SETTING_TYPE_IP6_CONFIG], + .properties = property_infos_ip6_config, + .properties_num = G_N_ELEMENTS (property_infos_ip6_config), + }, + [NM_META_SETTING_TYPE_IP_TUNNEL] = { + .general = &nm_meta_setting_infos[NM_META_SETTING_TYPE_IP_TUNNEL], + .properties = property_infos_ip_tunnel, + .properties_num = G_N_ELEMENTS (property_infos_ip_tunnel), + }, + [NM_META_SETTING_TYPE_MACSEC] = { + .general = &nm_meta_setting_infos[NM_META_SETTING_TYPE_MACSEC], + .properties = property_infos_macsec, + .properties_num = G_N_ELEMENTS (property_infos_macsec), + }, + [NM_META_SETTING_TYPE_MACVLAN] = { + .general = &nm_meta_setting_infos[NM_META_SETTING_TYPE_MACVLAN], + .properties = property_infos_macvlan, + .properties_num = G_N_ELEMENTS (property_infos_macvlan), + }, + [NM_META_SETTING_TYPE_OLPC_MESH] = { + .general = &nm_meta_setting_infos[NM_META_SETTING_TYPE_OLPC_MESH], + .properties = property_infos_olpc_mesh, + .properties_num = G_N_ELEMENTS (property_infos_olpc_mesh), + }, + [NM_META_SETTING_TYPE_PPPOE] = { + .general = &nm_meta_setting_infos[NM_META_SETTING_TYPE_PPPOE], + .properties = property_infos_pppoe, + .properties_num = G_N_ELEMENTS (property_infos_pppoe), + }, + [NM_META_SETTING_TYPE_PPP] = { + .general = &nm_meta_setting_infos[NM_META_SETTING_TYPE_PPP], + .properties = property_infos_ppp, + .properties_num = G_N_ELEMENTS (property_infos_ppp), + }, + [NM_META_SETTING_TYPE_PROXY] = { + .general = &nm_meta_setting_infos[NM_META_SETTING_TYPE_PROXY], + .properties = property_infos_proxy, + .properties_num = G_N_ELEMENTS (property_infos_proxy), + }, + [NM_META_SETTING_TYPE_SERIAL] = { + .general = &nm_meta_setting_infos[NM_META_SETTING_TYPE_SERIAL], + .properties = property_infos_serial, + .properties_num = G_N_ELEMENTS (property_infos_serial), + }, + [NM_META_SETTING_TYPE_TEAM] = { + .general = &nm_meta_setting_infos[NM_META_SETTING_TYPE_TEAM], + .properties = property_infos_team, + .properties_num = G_N_ELEMENTS (property_infos_team), + }, + [NM_META_SETTING_TYPE_TEAM_PORT] = { + .general = &nm_meta_setting_infos[NM_META_SETTING_TYPE_TEAM_PORT], + .properties = property_infos_team_port, + .properties_num = G_N_ELEMENTS (property_infos_team_port), + }, + [NM_META_SETTING_TYPE_TUN] = { + .general = &nm_meta_setting_infos[NM_META_SETTING_TYPE_TUN], + .properties = property_infos_tun, + .properties_num = G_N_ELEMENTS (property_infos_tun), + }, + [NM_META_SETTING_TYPE_USER] = { + .general = &nm_meta_setting_infos[NM_META_SETTING_TYPE_USER], + .properties = property_infos_user, + .properties_num = G_N_ELEMENTS (property_infos_user), + }, + [NM_META_SETTING_TYPE_VLAN] = { + .general = &nm_meta_setting_infos[NM_META_SETTING_TYPE_VLAN], + .properties = property_infos_vlan, + .properties_num = G_N_ELEMENTS (property_infos_vlan), + }, + [NM_META_SETTING_TYPE_VPN] = { + .general = &nm_meta_setting_infos[NM_META_SETTING_TYPE_VPN], + .properties = property_infos_vpn, + .properties_num = G_N_ELEMENTS (property_infos_vpn), + }, + [NM_META_SETTING_TYPE_VXLAN] = { + .general = &nm_meta_setting_infos[NM_META_SETTING_TYPE_VXLAN], + .properties = property_infos_vxlan, + .properties_num = G_N_ELEMENTS (property_infos_vxlan), + }, + [NM_META_SETTING_TYPE_WIMAX] = { + .general = &nm_meta_setting_infos[NM_META_SETTING_TYPE_WIMAX], + .properties = property_infos_wimax, + .properties_num = G_N_ELEMENTS (property_infos_wimax), + }, + [NM_META_SETTING_TYPE_WIRED] = { + .general = &nm_meta_setting_infos[NM_META_SETTING_TYPE_WIRED], + .properties = property_infos_wired, + .properties_num = G_N_ELEMENTS (property_infos_wired), + }, + [NM_META_SETTING_TYPE_WIRELESS] = { + .general = &nm_meta_setting_infos[NM_META_SETTING_TYPE_WIRELESS], + .properties = property_infos_wireless, + .properties_num = G_N_ELEMENTS (property_infos_wireless), + }, + [NM_META_SETTING_TYPE_WIRELESS_SECURITY] = { + .general = &nm_meta_setting_infos[NM_META_SETTING_TYPE_WIRELESS_SECURITY], + .properties = property_infos_wireless_security, + .properties_num = G_N_ELEMENTS (property_infos_wireless_security), + }, +}; + diff --git a/clients/common/nm-meta-setting-desc.h b/clients/common/nm-meta-setting-desc.h new file mode 100644 index 0000000000..fb92012297 --- /dev/null +++ b/clients/common/nm-meta-setting-desc.h @@ -0,0 +1,135 @@ +/* nmcli - command-line tool to control NetworkManager + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * 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. + */ + +#ifndef __NM_META_SETTING_DESC_H__ +#define __NM_META_SETTING_DESC_H__ + +#include "nm-meta-setting.h" + +#define NM_META_TEXT_HIDDEN "<hidden>" + +typedef enum { + NM_META_ACCESSOR_GET_TYPE_PRETTY, + NM_META_ACCESSOR_GET_TYPE_PARSABLE, +} NMMetaAccessorGetType; + +typedef enum { + NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PRETTY_NUMERIC = (1LL << 0), + NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PRETTY_NUMERIC_HEX = (1LL << 1), + NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PRETTY_TEXT = (1LL << 2), + NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PRETTY_TEXT_L10N = (1LL << 3), + NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PARSABLE_NUMERIC = (1LL << 4), + NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PARSABLE_NUMERIC_HEX = (1LL << 5), + NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PARSABLE_TEXT = (1LL << 6), +} NMMetaPropertyTypFlags; + +typedef enum { + NM_META_PROPERTY_TYPE_MAC_MODE_DEFAULT, + NM_META_PROPERTY_TYPE_MAC_MODE_CLONED, + NM_META_PROPERTY_TYPE_MAC_MODE_INFINIBAND, +} NMMetaPropertyTypeMacMode; + +typedef struct _NMMetaSettingInfoEditor NMMetaSettingInfoEditor; +typedef struct _NMMetaPropertyInfo NMMetaPropertyInfo; +typedef struct _NMMetaPropertyType NMMetaPropertyType; +typedef struct _NMMetaPropertyTypData NMMetaPropertyTypData; + +struct _NMMetaPropertyType { + + const char *(*describe_fcn) (const NMMetaSettingInfoEditor *setting_info, + const NMMetaPropertyInfo *property_info, + char **out_to_free); + + char *(*get_fcn) (const NMMetaSettingInfoEditor *setting_info, + const NMMetaPropertyInfo *property_info, + NMSetting *setting, + NMMetaAccessorGetType get_type, + gboolean show_secrets); + gboolean (*set_fcn) (const NMMetaSettingInfoEditor *setting_info, + const NMMetaPropertyInfo *property_info, + NMSetting *setting, + const char *value, + GError **error); + gboolean (*remove_fcn) (const NMMetaSettingInfoEditor *setting_info, + const NMMetaPropertyInfo *property_info, + NMSetting *setting, + const char *option, + guint32 idx, + GError **error); + + const char *const*(*values_fcn) (const NMMetaSettingInfoEditor *setting_info, + const NMMetaPropertyInfo *property_info, + char ***out_to_free); +}; + +struct _NMUtilsEnumValueInfo; + +struct _NMMetaPropertyTypData { + union { + struct { + gboolean (*fcn) (NMSetting *setting); + } get_with_default; + struct { + GType (*get_gtype) (void); + int min; + int max; + const struct _NMUtilsEnumValueInfo *value_infos; + } gobject_enum; + struct { + guint32 (*get_fcn) (NMSetting *setting); + } mtu; + struct { + NMMetaPropertyTypeMacMode mode; + } mac; + } subtype; + const char *const*values_static; + NMMetaPropertyTypFlags typ_flags; +}; + +struct _NMMetaPropertyInfo { + const char *property_name; + + /* the property list for now must contain as first field the + * "name", which isn't a regular property. This is required by + * NmcOutputField and this first field is ignored for the + * group_list/setting_info. */ + bool is_name:1; + + bool is_secret:1; + + const char *describe_message; + + const NMMetaPropertyType *property_type; + const NMMetaPropertyTypData *property_typ_data; +}; + +struct _NMMetaSettingInfoEditor { + const NMMetaSettingInfo *general; + /* the order of the properties matter. The first *must* be the + * "name", and then the order is as they are listed by default. */ + const NMMetaPropertyInfo *properties; + guint properties_num; +}; + +extern const NMMetaSettingInfoEditor nm_meta_setting_infos_editor[_NM_META_SETTING_TYPE_NUM]; + +/* FIXME: don't expose this function on it's own, at least not from this file. */ +const char *nmc_bond_validate_mode (const char *mode, GError **error); + +#endif /* __NM_META_SETTING_DESC_H__ */ diff --git a/libnm-core/nm-core-internal.h b/libnm-core/nm-core-internal.h index ac292bfc18..176c0600f9 100644 --- a/libnm-core/nm-core-internal.h +++ b/libnm-core/nm-core-internal.h @@ -204,8 +204,6 @@ gboolean _nm_utils_check_module_file (const char *name, gpointer user_data, GError **error); -char *_nm_utils_enum_to_str_full (GType type, int value, const char *sep); - #define NM_UTILS_UUID_TYPE_LEGACY 0 #define NM_UTILS_UUID_TYPE_VARIANT3 1 diff --git a/libnm-core/nm-keyfile-internal.h b/libnm-core/nm-keyfile-internal.h index be11a70807..5b709c025f 100644 --- a/libnm-core/nm-keyfile-internal.h +++ b/libnm-core/nm-keyfile-internal.h @@ -28,7 +28,7 @@ #include "nm-setting-8021x.h" #include "nm-core-internal.h" -#include "nm-setting-metadata.h" +#include "nm-meta-setting.h" /*****************************************************************************/ diff --git a/libnm-core/nm-setting-ip6-config.c b/libnm-core/nm-setting-ip6-config.c index 429f27c95c..fbeffe7e0b 100644 --- a/libnm-core/nm-setting-ip6-config.c +++ b/libnm-core/nm-setting-ip6-config.c @@ -224,7 +224,7 @@ verify (NMSetting *setting, NMConnection *connection, GError **error) NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_INVALID_PROPERTY, _("property is invalid")); - g_prefix_error (error, "%s.%s: ", NM_SETTING_IP6_CONFIG_SETTING_NAME, NM_SETTING_IP_CONFIG_METHOD); + g_prefix_error (error, "%s.%s: ", NM_SETTING_IP6_CONFIG_SETTING_NAME, NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE); return FALSE; } diff --git a/libnm-core/nm-setting-user.c b/libnm-core/nm-setting-user.c index 0d0817ef1e..2ba2eb84a6 100644 --- a/libnm-core/nm-setting-user.c +++ b/libnm-core/nm-setting-user.c @@ -438,7 +438,7 @@ set_property (GObject *object, guint prop_id, nm_clear_g_free (&priv->keys); return; } - g_hash_table_iter_init (&iter, priv->data); + g_hash_table_iter_init (&iter, data); while (g_hash_table_iter_next (&iter, (gpointer *) &key, (gpointer *) &val)) { if (!nm_setting_user_check_key (key, NULL)) g_return_if_reached (); diff --git a/libnm-core/nm-utils.c b/libnm-core/nm-utils.c index 1feee7ac2a..5c5b94c667 100644 --- a/libnm-core/nm-utils.c +++ b/libnm-core/nm-utils.c @@ -37,6 +37,7 @@ #include <jansson.h> #endif +#include "nm-utils/nm-enum-utils.h" #include "nm-common-macros.h" #include "nm-utils-private.h" #include "nm-setting-private.h" @@ -4249,263 +4250,6 @@ int _nm_utils_dns_option_find_idx (GPtrArray *array, const char *option) return -1; } -#define IS_FLAGS_SEPARATOR(ch) (NM_IN_SET ((ch), ' ', '\t', ',', '\n', '\r')) - -static gboolean -_is_hex_string (const char *str) -{ - return str[0] == '0' - && str[1] == 'x' - && str[2] - && NM_STRCHAR_ALL (&str[2], ch, g_ascii_isxdigit (ch)); -} - -static gboolean -_enum_is_valid_enum_nick (const char *str) -{ - return str[0] - && !NM_STRCHAR_ANY (str, ch, g_ascii_isspace (ch)) - && !NM_STRCHAR_ALL (str, ch, g_ascii_isdigit (ch)); -} - -static gboolean -_enum_is_valid_flags_nick (const char *str) -{ - return str[0] - && !NM_STRCHAR_ANY (str, ch, IS_FLAGS_SEPARATOR (ch)) - && !_is_hex_string (str); -} - -char * -_nm_utils_enum_to_str_full (GType type, - int value, - const char *flags_separator) -{ - GTypeClass *class; - char *ret; - - if ( flags_separator - && ( !flags_separator[0] - || NM_STRCHAR_ANY (flags_separator, ch, !IS_FLAGS_SEPARATOR (ch)))) - g_return_val_if_reached (NULL); - - class = g_type_class_ref (type); - - if (G_IS_ENUM_CLASS (class)) { - GEnumValue *enum_value; - - enum_value = g_enum_get_value (G_ENUM_CLASS (class), value); - if ( !enum_value - || !_enum_is_valid_enum_nick (enum_value->value_nick)) - ret = g_strdup_printf ("%d", value); - else - ret = strdup (enum_value->value_nick); - } else if (G_IS_FLAGS_CLASS (class)) { - GFlagsValue *flags_value; - GString *str = g_string_new (""); - - flags_separator = flags_separator ?: " "; - - while (value) { - flags_value = g_flags_get_first_value (G_FLAGS_CLASS (class), value); - if (str->len) - g_string_append (str, flags_separator); - if ( !flags_value - || !_enum_is_valid_flags_nick (flags_value->value_nick)) { - g_string_append_printf (str, "0x%x", (unsigned) value); - break; - } - g_string_append (str, flags_value->value_nick); - value &= ~flags_value->value; - } - ret = g_string_free (str, FALSE); - } else - g_return_val_if_reached (NULL); - - g_type_class_unref (class); - return ret; -} - -/** - * nm_utils_enum_to_str: - * @type: the %GType of the enum - * @value: the value to be translated - * - * Converts an enum value to its string representation. If the enum is a - * %G_TYPE_FLAGS the function returns a comma-separated list of matching values. - * If the enum is a %G_TYPE_ENUM and the given value is not valid the - * function returns %NULL. - * - * Returns: a newly allocated string or %NULL - * - * Since: 1.2 - */ -char * -nm_utils_enum_to_str (GType type, int value) -{ - return _nm_utils_enum_to_str_full (type, value, ", "); -} - -/** - * nm_utils_enum_from_str: - * @type: the %GType of the enum - * @str: the input string - * @out_value: (out) (allow-none): the output value - * @err_token: (out) (allow-none) (transfer full): location to store the first unrecognized token - * - * Converts a string to the matching enum value. - * - * If the enum is a %G_TYPE_FLAGS the function returns the logical OR of values - * matching the comma-separated tokens in the string; if an unknown token is found - * the function returns %FALSE and stores a pointer to a newly allocated string - * containing the unrecognized token in @err_token. - * - * Returns: %TRUE if the conversion was successful, %FALSE otherwise - * - * Since: 1.2 - */ -gboolean -nm_utils_enum_from_str (GType type, const char *str, - int *out_value, char **err_token) -{ - GTypeClass *class; - gboolean ret = FALSE; - int value = 0; - gs_free char *str_clone = NULL; - char *s; - gint64 v64; - - g_return_val_if_fail (str, FALSE); - - str_clone = strdup (str); - s = nm_str_skip_leading_spaces (str_clone); - g_strchomp (s); - - class = g_type_class_ref (type); - - if (G_IS_ENUM_CLASS (class)) { - GEnumValue *enum_value; - - if (s[0]) { - if (NM_STRCHAR_ALL (s, ch, g_ascii_isdigit (ch))) { - v64 = _nm_utils_ascii_str_to_int64 (s, 10, 0, G_MAXINT, -1); - if (v64 != -1) { - value = (int) v64; - ret = TRUE; - } - } else { - enum_value = g_enum_get_value_by_nick (G_ENUM_CLASS (class), s); - if (enum_value) { - value = enum_value->value; - ret = TRUE; - } - } - } - } else if (G_IS_FLAGS_CLASS (class)) { - GFlagsValue *flags_value; - - ret = TRUE; - while (s[0]) { - char *s_end; - - for (s_end = s; s_end[0]; s_end++) { - if (IS_FLAGS_SEPARATOR (s_end[0])) { - s_end[0] = '\0'; - s_end++; - break; - } - } - - if (s[0]) { - if (_is_hex_string (s)) { - v64 = _nm_utils_ascii_str_to_int64 (&s[2], 16, 0, G_MAXUINT, -1); - if (v64 == -1) { - ret = FALSE; - break; - } - value |= (int) v64; - } else { - flags_value = g_flags_get_value_by_nick (G_FLAGS_CLASS (class), s); - if (!flags_value) { - ret = FALSE; - break; - } - value |= flags_value->value; - } - } - - s = s_end; - } - } else - g_return_val_if_reached (FALSE); - - NM_SET_OUT (err_token, !ret && s[0] ? g_strdup (s) : NULL); - NM_SET_OUT (out_value, ret ? value : 0); - g_type_class_unref (class); - return ret; -} - -/** - * nm_utils_enum_get_values: - * @type: the %GType of the enum - * @from: the first element to be returned - * @to: the last element to be returned - * - * Returns the list of possible values for a given enum. - * - * Returns: (transfer container): a NULL-terminated dynamically-allocated array of static strings - * or %NULL on error - * - * Since: 1.2 - */ -const char **nm_utils_enum_get_values (GType type, gint from, gint to) -{ - GTypeClass *class; - GPtrArray *array; - gint i; - char sbuf[64]; - - class = g_type_class_ref (type); - array = g_ptr_array_new (); - - if (G_IS_ENUM_CLASS (class)) { - GEnumClass *enum_class = G_ENUM_CLASS (class); - GEnumValue *enum_value; - - for (i = 0; i < enum_class->n_values; i++) { - enum_value = &enum_class->values[i]; - if (enum_value->value >= from && enum_value->value <= to) { - if (_enum_is_valid_enum_nick (enum_value->value_nick)) - g_ptr_array_add (array, (gpointer) enum_value->value_nick); - else - g_ptr_array_add (array, (gpointer) g_intern_string (nm_sprintf_buf (sbuf, "%d", enum_value->value))); - } - } - } else if (G_IS_FLAGS_CLASS (class)) { - GFlagsClass *flags_class = G_FLAGS_CLASS (class); - GFlagsValue *flags_value; - - for (i = 0; i < flags_class->n_values; i++) { - flags_value = &flags_class->values[i]; - if (flags_value->value >= from && flags_value->value <= to) { - if (_enum_is_valid_flags_nick (flags_value->value_nick)) - g_ptr_array_add (array, (gpointer) flags_value->value_nick); - else - g_ptr_array_add (array, (gpointer) g_intern_string (nm_sprintf_buf (sbuf, "0x%x", (unsigned) flags_value->value))); - } - } - } else { - g_type_class_unref (class); - g_ptr_array_free (array, TRUE); - g_return_val_if_reached (NULL); - } - - g_type_class_unref (class); - g_ptr_array_add (array, NULL); - - return (const char **) g_ptr_array_free (array, FALSE); -} - #if WITH_JANSSON /** * nm_utils_is_json_object: diff --git a/libnm-core/tests/test-general.c b/libnm-core/tests/test-general.c index 87ef938913..0f65e8f6ae 100644 --- a/libnm-core/tests/test-general.c +++ b/libnm-core/tests/test-general.c @@ -5200,7 +5200,7 @@ static void test_nm_utils_enum (void) test_nm_utils_enum_to_str_do (bool_enum, NM_TEST_GENERAL_BOOL_ENUM_67, "67"); test_nm_utils_enum_to_str_do (bool_enum, NM_TEST_GENERAL_BOOL_ENUM_46, "64"); - test_nm_utils_enum_to_str_do (meta_flags, NM_TEST_GENERAL_META_FLAGS_NONE, ""); + test_nm_utils_enum_to_str_do (meta_flags, NM_TEST_GENERAL_META_FLAGS_NONE, "none"); test_nm_utils_enum_to_str_do (meta_flags, NM_TEST_GENERAL_META_FLAGS_BAZ, "baz"); test_nm_utils_enum_to_str_do (meta_flags, NM_TEST_GENERAL_META_FLAGS_FOO | NM_TEST_GENERAL_META_FLAGS_BAR | diff --git a/po/POTFILES.in b/po/POTFILES.in index 0a0d9b65f2..e2995e63c1 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -10,6 +10,8 @@ clients/cli/nmcli.c clients/cli/polkit-agent.c clients/cli/settings.c clients/cli/utils.c +clients/common/nm-client-utils.c +clients/common/nm-meta-setting-desc.c clients/common/nm-polkit-listener.c clients/common/nm-secret-agent-simple.c clients/common/nm-vpn-helpers.c diff --git a/shared/nm-meta-setting.c b/shared/nm-meta-setting.c new file mode 100644 index 0000000000..58bd3f1004 --- /dev/null +++ b/shared/nm-meta-setting.c @@ -0,0 +1,341 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ + +/* + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA. + * + * Copyright 2017 Red Hat, Inc. + */ + +#include "nm-default.h" + +#include "nm-meta-setting.h" + +#include "nm-setting-8021x.h" +#include "nm-setting-adsl.h" +#include "nm-setting-bluetooth.h" +#include "nm-setting-bond.h" +#include "nm-setting-bridge.h" +#include "nm-setting-bridge-port.h" +#include "nm-setting-cdma.h" +#include "nm-setting-connection.h" +#include "nm-setting-dcb.h" +#include "nm-setting-dummy.h" +#include "nm-setting-generic.h" +#include "nm-setting-gsm.h" +#include "nm-setting-infiniband.h" +#include "nm-setting-ip4-config.h" +#include "nm-setting-ip6-config.h" +#include "nm-setting-ip-config.h" +#include "nm-setting-ip-tunnel.h" +#include "nm-setting-macsec.h" +#include "nm-setting-macvlan.h" +#include "nm-setting-olpc-mesh.h" +#include "nm-setting-ppp.h" +#include "nm-setting-pppoe.h" +#include "nm-setting-proxy.h" +#include "nm-setting-serial.h" +#include "nm-setting-team.h" +#include "nm-setting-team-port.h" +#include "nm-setting-tun.h" +#include "nm-setting-user.h" +#include "nm-setting-vlan.h" +#include "nm-setting-vpn.h" +#include "nm-setting-vxlan.h" +#include "nm-setting-wimax.h" +#include "nm-setting-wired.h" +#include "nm-setting-wireless.h" +#include "nm-setting-wireless-security.h" + +/*****************************************************************************/ + +const NMSetting8021xSchemeVtable nm_setting_8021x_scheme_vtable[] = { + [NM_SETTING_802_1X_SCHEME_TYPE_CA_CERT] = { + .setting_key = NM_SETTING_802_1X_CA_CERT, + .scheme_func = nm_setting_802_1x_get_ca_cert_scheme, + .format_func = NULL, + .path_func = nm_setting_802_1x_get_ca_cert_path, + .blob_func = nm_setting_802_1x_get_ca_cert_blob, + .uri_func = nm_setting_802_1x_get_ca_cert_uri, + .passwd_func = nm_setting_802_1x_get_ca_cert_password, + .pwflag_func = nm_setting_802_1x_get_ca_cert_password_flags, + .file_suffix = "ca-cert", + }, + + [NM_SETTING_802_1X_SCHEME_TYPE_PHASE2_CA_CERT] = { + .setting_key = NM_SETTING_802_1X_PHASE2_CA_CERT, + .scheme_func = nm_setting_802_1x_get_phase2_ca_cert_scheme, + .format_func = NULL, + .path_func = nm_setting_802_1x_get_phase2_ca_cert_path, + .blob_func = nm_setting_802_1x_get_phase2_ca_cert_blob, + .uri_func = nm_setting_802_1x_get_phase2_ca_cert_uri, + .passwd_func = nm_setting_802_1x_get_phase2_ca_cert_password, + .pwflag_func = nm_setting_802_1x_get_phase2_ca_cert_password_flags, + .file_suffix = "inner-ca-cert", + }, + + [NM_SETTING_802_1X_SCHEME_TYPE_CLIENT_CERT] = { + .setting_key = NM_SETTING_802_1X_CLIENT_CERT, + .scheme_func = nm_setting_802_1x_get_client_cert_scheme, + .format_func = NULL, + .path_func = nm_setting_802_1x_get_client_cert_path, + .blob_func = nm_setting_802_1x_get_client_cert_blob, + .uri_func = nm_setting_802_1x_get_client_cert_uri, + .passwd_func = nm_setting_802_1x_get_client_cert_password, + .pwflag_func = nm_setting_802_1x_get_client_cert_password_flags, + .file_suffix = "client-cert", + }, + + [NM_SETTING_802_1X_SCHEME_TYPE_PHASE2_CLIENT_CERT] = { + .setting_key = NM_SETTING_802_1X_PHASE2_CLIENT_CERT, + .scheme_func = nm_setting_802_1x_get_phase2_client_cert_scheme, + .format_func = NULL, + .path_func = nm_setting_802_1x_get_phase2_client_cert_path, + .blob_func = nm_setting_802_1x_get_phase2_client_cert_blob, + .uri_func = nm_setting_802_1x_get_phase2_client_cert_uri, + .passwd_func = nm_setting_802_1x_get_phase2_client_cert_password, + .pwflag_func = nm_setting_802_1x_get_phase2_client_cert_password_flags, + .file_suffix = "inner-client-cert", + }, + + [NM_SETTING_802_1X_SCHEME_TYPE_PRIVATE_KEY] = { + .setting_key = NM_SETTING_802_1X_PRIVATE_KEY, + .scheme_func = nm_setting_802_1x_get_private_key_scheme, + .format_func = nm_setting_802_1x_get_private_key_format, + .path_func = nm_setting_802_1x_get_private_key_path, + .blob_func = nm_setting_802_1x_get_private_key_blob, + .uri_func = nm_setting_802_1x_get_private_key_uri, + .passwd_func = nm_setting_802_1x_get_private_key_password, + .pwflag_func = nm_setting_802_1x_get_private_key_password_flags, + .file_suffix = "private-key", + }, + + [NM_SETTING_802_1X_SCHEME_TYPE_PHASE2_PRIVATE_KEY] = { + .setting_key = NM_SETTING_802_1X_PHASE2_PRIVATE_KEY, + .scheme_func = nm_setting_802_1x_get_phase2_private_key_scheme, + .format_func = nm_setting_802_1x_get_phase2_private_key_format, + .path_func = nm_setting_802_1x_get_phase2_private_key_path, + .blob_func = nm_setting_802_1x_get_phase2_private_key_blob, + .uri_func = nm_setting_802_1x_get_phase2_private_key_uri, + .passwd_func = nm_setting_802_1x_get_phase2_private_key_password, + .pwflag_func = nm_setting_802_1x_get_phase2_private_key_password_flags, + .file_suffix = "inner-private-key", + }, + + [NM_SETTING_802_1X_SCHEME_TYPE_UNKNOWN] = { NULL }, +}; + +/*****************************************************************************/ + +const NMMetaSettingInfo nm_meta_setting_infos[] = { + [NM_META_SETTING_TYPE_802_1X] = { + .meta_type = NM_META_SETTING_TYPE_802_1X, + .setting_name = N_ (NM_SETTING_802_1X_SETTING_NAME), + .get_setting_gtype = nm_setting_802_1x_get_type, + }, + [NM_META_SETTING_TYPE_ADSL] = { + .meta_type = NM_META_SETTING_TYPE_ADSL, + .setting_name = N_ (NM_SETTING_ADSL_SETTING_NAME), + .get_setting_gtype = nm_setting_adsl_get_type, + }, + [NM_META_SETTING_TYPE_BLUETOOTH] = { + .meta_type = NM_META_SETTING_TYPE_BLUETOOTH, + .setting_name = N_ (NM_SETTING_BLUETOOTH_SETTING_NAME), + .get_setting_gtype = nm_setting_bluetooth_get_type, + }, + [NM_META_SETTING_TYPE_BOND] = { + .meta_type = NM_META_SETTING_TYPE_BOND, + .setting_name = N_ (NM_SETTING_BOND_SETTING_NAME), + .get_setting_gtype = nm_setting_bond_get_type, + }, + [NM_META_SETTING_TYPE_BRIDGE] = { + .meta_type = NM_META_SETTING_TYPE_BRIDGE, + .setting_name = N_ (NM_SETTING_BRIDGE_SETTING_NAME), + .get_setting_gtype = nm_setting_bridge_get_type, + }, + [NM_META_SETTING_TYPE_BRIDGE_PORT] = { + .meta_type = NM_META_SETTING_TYPE_BRIDGE_PORT, + .setting_name = N_ (NM_SETTING_BRIDGE_PORT_SETTING_NAME), + .get_setting_gtype = nm_setting_bridge_port_get_type, + }, + [NM_META_SETTING_TYPE_CDMA] = { + .meta_type = NM_META_SETTING_TYPE_CDMA, + .setting_name = N_ (NM_SETTING_CDMA_SETTING_NAME), + .get_setting_gtype = nm_setting_cdma_get_type, + }, + [NM_META_SETTING_TYPE_CONNECTION] = { + .meta_type = NM_META_SETTING_TYPE_CONNECTION, + .setting_name = N_ (NM_SETTING_CONNECTION_SETTING_NAME), + .get_setting_gtype = nm_setting_connection_get_type, + }, + [NM_META_SETTING_TYPE_DCB] = { + .meta_type = NM_META_SETTING_TYPE_DCB, + .setting_name = N_ (NM_SETTING_DCB_SETTING_NAME), + .get_setting_gtype = nm_setting_dcb_get_type, + }, + [NM_META_SETTING_TYPE_DUMMY] = { + .meta_type = NM_META_SETTING_TYPE_DUMMY, + .setting_name = N_ (NM_SETTING_DUMMY_SETTING_NAME), + .get_setting_gtype = nm_setting_dummy_get_type, + }, + [NM_META_SETTING_TYPE_GSM] = { + .meta_type = NM_META_SETTING_TYPE_GSM, + .setting_name = N_ (NM_SETTING_GSM_SETTING_NAME), + .get_setting_gtype = nm_setting_gsm_get_type, + }, + [NM_META_SETTING_TYPE_INFINIBAND] = { + .meta_type = NM_META_SETTING_TYPE_INFINIBAND, + .setting_name = N_ (NM_SETTING_INFINIBAND_SETTING_NAME), + .get_setting_gtype = nm_setting_infiniband_get_type, + }, + [NM_META_SETTING_TYPE_IP4_CONFIG] = { + .meta_type = NM_META_SETTING_TYPE_IP4_CONFIG, + .setting_name = N_ (NM_SETTING_IP4_CONFIG_SETTING_NAME), + .get_setting_gtype = nm_setting_ip4_config_get_type, + }, + [NM_META_SETTING_TYPE_IP6_CONFIG] = { + .meta_type = NM_META_SETTING_TYPE_IP6_CONFIG, + .setting_name = N_ (NM_SETTING_IP6_CONFIG_SETTING_NAME), + .get_setting_gtype = nm_setting_ip6_config_get_type, + }, + [NM_META_SETTING_TYPE_IP_TUNNEL] = { + .meta_type = NM_META_SETTING_TYPE_IP_TUNNEL, + .setting_name = N_ (NM_SETTING_IP_TUNNEL_SETTING_NAME), + .get_setting_gtype = nm_setting_ip_tunnel_get_type, + }, + [NM_META_SETTING_TYPE_MACSEC] = { + .meta_type = NM_META_SETTING_TYPE_MACSEC, + .setting_name = N_ (NM_SETTING_MACSEC_SETTING_NAME), + .get_setting_gtype = nm_setting_macsec_get_type, + }, + [NM_META_SETTING_TYPE_MACVLAN] = { + .meta_type = NM_META_SETTING_TYPE_MACVLAN, + .setting_name = N_ (NM_SETTING_MACVLAN_SETTING_NAME), + .get_setting_gtype = nm_setting_macvlan_get_type, + }, + [NM_META_SETTING_TYPE_OLPC_MESH] = { + .meta_type = NM_META_SETTING_TYPE_OLPC_MESH, + .setting_name = N_ (NM_SETTING_OLPC_MESH_SETTING_NAME), + .get_setting_gtype = nm_setting_olpc_mesh_get_type, + }, + [NM_META_SETTING_TYPE_PPPOE] = { + .meta_type = NM_META_SETTING_TYPE_PPPOE, + .setting_name = N_ (NM_SETTING_PPPOE_SETTING_NAME), + .get_setting_gtype = nm_setting_pppoe_get_type, + }, + [NM_META_SETTING_TYPE_PPP] = { + .meta_type = NM_META_SETTING_TYPE_PPP, + .setting_name = N_ (NM_SETTING_PPP_SETTING_NAME), + .get_setting_gtype = nm_setting_ppp_get_type, + }, + [NM_META_SETTING_TYPE_PROXY] = { + .meta_type = NM_META_SETTING_TYPE_PROXY, + .setting_name = N_ (NM_SETTING_PROXY_SETTING_NAME), + .get_setting_gtype = nm_setting_proxy_get_type, + }, + [NM_META_SETTING_TYPE_SERIAL] = { + .meta_type = NM_META_SETTING_TYPE_SERIAL, + .setting_name = N_ (NM_SETTING_SERIAL_SETTING_NAME), + .get_setting_gtype = nm_setting_serial_get_type, + }, + [NM_META_SETTING_TYPE_TEAM] = { + .meta_type = NM_META_SETTING_TYPE_TEAM, + .setting_name = N_ (NM_SETTING_TEAM_SETTING_NAME), + .get_setting_gtype = nm_setting_team_get_type, + }, + [NM_META_SETTING_TYPE_TEAM_PORT] = { + .meta_type = NM_META_SETTING_TYPE_TEAM_PORT, + .setting_name = N_ (NM_SETTING_TEAM_PORT_SETTING_NAME), + .get_setting_gtype = nm_setting_team_port_get_type, + }, + [NM_META_SETTING_TYPE_TUN] = { + .meta_type = NM_META_SETTING_TYPE_TUN, + .setting_name = N_ (NM_SETTING_TUN_SETTING_NAME), + .get_setting_gtype = nm_setting_tun_get_type, + }, + [NM_META_SETTING_TYPE_USER] = { + .meta_type = NM_META_SETTING_TYPE_USER, + .setting_name = N_ (NM_SETTING_USER_SETTING_NAME), + .get_setting_gtype = nm_setting_user_get_type, + }, + [NM_META_SETTING_TYPE_VLAN] = { + .meta_type = NM_META_SETTING_TYPE_VLAN, + .setting_name = N_ (NM_SETTING_VLAN_SETTING_NAME), + .get_setting_gtype = nm_setting_vlan_get_type, + }, + [NM_META_SETTING_TYPE_VPN] = { + .meta_type = NM_META_SETTING_TYPE_VPN, + .setting_name = N_ (NM_SETTING_VPN_SETTING_NAME), + .get_setting_gtype = nm_setting_vpn_get_type, + }, + [NM_META_SETTING_TYPE_VXLAN] = { + .meta_type = NM_META_SETTING_TYPE_VXLAN, + .setting_name = N_ (NM_SETTING_VXLAN_SETTING_NAME), + .get_setting_gtype = nm_setting_vxlan_get_type, + }, + [NM_META_SETTING_TYPE_WIMAX] = { + .meta_type = NM_META_SETTING_TYPE_WIMAX, + .setting_name = N_ (NM_SETTING_WIMAX_SETTING_NAME), + .get_setting_gtype = nm_setting_wimax_get_type, + }, + [NM_META_SETTING_TYPE_WIRED] = { + .meta_type = NM_META_SETTING_TYPE_WIRED, + .setting_name = N_ (NM_SETTING_WIRED_SETTING_NAME), + .get_setting_gtype = nm_setting_wired_get_type, + }, + [NM_META_SETTING_TYPE_WIRELESS] = { + .meta_type = NM_META_SETTING_TYPE_WIRELESS, + .setting_name = N_ (NM_SETTING_WIRELESS_SETTING_NAME), + .get_setting_gtype = nm_setting_wireless_get_type, + }, + [NM_META_SETTING_TYPE_WIRELESS_SECURITY] = { + .meta_type = NM_META_SETTING_TYPE_WIRELESS_SECURITY, + .setting_name = N_ (NM_SETTING_WIRELESS_SECURITY_SETTING_NAME), + .get_setting_gtype = nm_setting_wireless_security_get_type, + }, + + [NM_META_SETTING_TYPE_UNKNOWN] = { + .meta_type = NM_META_SETTING_TYPE_UNKNOWN, + .setting_name = NULL, + }, +}; + +const NMMetaSettingInfo * +nm_meta_setting_infos_by_name (const char *name) +{ + int i; + + if (name) { + for (i = 0; i < _NM_META_SETTING_TYPE_NUM; i++) { + if (nm_streq (nm_meta_setting_infos[i].setting_name, name)) + return &nm_meta_setting_infos[i]; + } + } + return NULL; +} + +const NMMetaSettingInfo * +nm_meta_setting_infos_by_gtype (GType gtype) +{ + int i; + + for (i = 0; i < _NM_META_SETTING_TYPE_NUM; i++) { + if (nm_meta_setting_infos[i].get_setting_gtype () == gtype) + return &nm_meta_setting_infos[i]; + } + return NULL; +} + +/*****************************************************************************/ diff --git a/shared/nm-setting-metadata.h b/shared/nm-meta-setting.h index 47e6e655eb..3d78a85045 100644 --- a/shared/nm-setting-metadata.h +++ b/shared/nm-meta-setting.h @@ -19,13 +19,26 @@ * Copyright 2017 Red Hat, Inc. */ -#ifndef __NM_SETTING_METADATA_H__ -#define __NM_SETTING_METADATA_H__ +#ifndef __NM_META_SETTING_H__ +#define __NM_META_SETTING_H__ #include "nm-setting-8021x.h" /*****************************************************************************/ +typedef enum { + NM_SETTING_802_1X_SCHEME_TYPE_CA_CERT, + NM_SETTING_802_1X_SCHEME_TYPE_PHASE2_CA_CERT, + NM_SETTING_802_1X_SCHEME_TYPE_CLIENT_CERT, + NM_SETTING_802_1X_SCHEME_TYPE_PHASE2_CLIENT_CERT, + NM_SETTING_802_1X_SCHEME_TYPE_PRIVATE_KEY, + NM_SETTING_802_1X_SCHEME_TYPE_PHASE2_PRIVATE_KEY, + + NM_SETTING_802_1X_SCHEME_TYPE_UNKNOWN, + + _NM_SETTING_802_1X_SCHEME_TYPE_NUM = NM_SETTING_802_1X_SCHEME_TYPE_UNKNOWN, +} NMSetting8021xSchemeType; + typedef struct { const char *setting_key; NMSetting8021xCKScheme (*scheme_func) (NMSetting8021x *setting); @@ -38,19 +51,61 @@ typedef struct { const char *file_suffix; } NMSetting8021xSchemeVtable; -enum { - NM_SETTING_802_1X_SCHEME_TYPE_CA_CERT, - NM_SETTING_802_1X_SCHEME_TYPE_PHASE2_CA_CERT, - NM_SETTING_802_1X_SCHEME_TYPE_CLIENT_CERT, - NM_SETTING_802_1X_SCHEME_TYPE_PHASE2_CLIENT_CERT, - NM_SETTING_802_1X_SCHEME_TYPE_PRIVATE_KEY, - NM_SETTING_802_1X_SCHEME_TYPE_PHASE2_PRIVATE_KEY, +extern const NMSetting8021xSchemeVtable nm_setting_8021x_scheme_vtable[_NM_SETTING_802_1X_SCHEME_TYPE_NUM + 1]; - NM_SETTING_802_1X_SCHEME_TYPE_UNKNOWN, -}; +/*****************************************************************************/ + +typedef enum { + NM_META_SETTING_TYPE_802_1X, + NM_META_SETTING_TYPE_ADSL, + NM_META_SETTING_TYPE_BLUETOOTH, + NM_META_SETTING_TYPE_BOND, + NM_META_SETTING_TYPE_BRIDGE, + NM_META_SETTING_TYPE_BRIDGE_PORT, + NM_META_SETTING_TYPE_CDMA, + NM_META_SETTING_TYPE_CONNECTION, + NM_META_SETTING_TYPE_DCB, + NM_META_SETTING_TYPE_DUMMY, + NM_META_SETTING_TYPE_GSM, + NM_META_SETTING_TYPE_INFINIBAND, + NM_META_SETTING_TYPE_IP4_CONFIG, + NM_META_SETTING_TYPE_IP6_CONFIG, + NM_META_SETTING_TYPE_IP_TUNNEL, + NM_META_SETTING_TYPE_MACSEC, + NM_META_SETTING_TYPE_MACVLAN, + NM_META_SETTING_TYPE_OLPC_MESH, + NM_META_SETTING_TYPE_PPP, + NM_META_SETTING_TYPE_PPPOE, + NM_META_SETTING_TYPE_PROXY, + NM_META_SETTING_TYPE_SERIAL, + NM_META_SETTING_TYPE_TEAM, + NM_META_SETTING_TYPE_TEAM_PORT, + NM_META_SETTING_TYPE_TUN, + NM_META_SETTING_TYPE_USER, + NM_META_SETTING_TYPE_VLAN, + NM_META_SETTING_TYPE_VPN, + NM_META_SETTING_TYPE_VXLAN, + NM_META_SETTING_TYPE_WIMAX, + NM_META_SETTING_TYPE_WIRED, + NM_META_SETTING_TYPE_WIRELESS, + NM_META_SETTING_TYPE_WIRELESS_SECURITY, + + NM_META_SETTING_TYPE_UNKNOWN, + + _NM_META_SETTING_TYPE_NUM = NM_META_SETTING_TYPE_UNKNOWN, +} NMMetaSettingType; + +typedef struct { + NMMetaSettingType meta_type; + const char *setting_name; + GType (*get_setting_gtype) (void); +} NMMetaSettingInfo; + +extern const NMMetaSettingInfo nm_meta_setting_infos[_NM_META_SETTING_TYPE_NUM + 1]; -extern const NMSetting8021xSchemeVtable nm_setting_8021x_scheme_vtable[NM_SETTING_802_1X_SCHEME_TYPE_UNKNOWN + 1]; +const NMMetaSettingInfo *nm_meta_setting_infos_by_name (const char *name); +const NMMetaSettingInfo *nm_meta_setting_infos_by_gtype (GType gtype); /*****************************************************************************/ -#endif /* __NM_SETTING_METADATA_H__ */ +#endif /* __NM_META_SETTING_H__ */ diff --git a/shared/nm-setting-metadata.c b/shared/nm-setting-metadata.c deleted file mode 100644 index a88fb69f17..0000000000 --- a/shared/nm-setting-metadata.c +++ /dev/null @@ -1,104 +0,0 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ - -/* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2017 Red Hat, Inc. - */ - -#include "nm-default.h" - -#include "nm-setting-metadata.h" - -/*****************************************************************************/ - -const NMSetting8021xSchemeVtable nm_setting_8021x_scheme_vtable[] = { - [NM_SETTING_802_1X_SCHEME_TYPE_CA_CERT] = { - .setting_key = NM_SETTING_802_1X_CA_CERT, - .scheme_func = nm_setting_802_1x_get_ca_cert_scheme, - .format_func = NULL, - .path_func = nm_setting_802_1x_get_ca_cert_path, - .blob_func = nm_setting_802_1x_get_ca_cert_blob, - .uri_func = nm_setting_802_1x_get_ca_cert_uri, - .passwd_func = nm_setting_802_1x_get_ca_cert_password, - .pwflag_func = nm_setting_802_1x_get_ca_cert_password_flags, - .file_suffix = "ca-cert", - }, - - [NM_SETTING_802_1X_SCHEME_TYPE_PHASE2_CA_CERT] = { - .setting_key = NM_SETTING_802_1X_PHASE2_CA_CERT, - .scheme_func = nm_setting_802_1x_get_phase2_ca_cert_scheme, - .format_func = NULL, - .path_func = nm_setting_802_1x_get_phase2_ca_cert_path, - .blob_func = nm_setting_802_1x_get_phase2_ca_cert_blob, - .uri_func = nm_setting_802_1x_get_phase2_ca_cert_uri, - .passwd_func = nm_setting_802_1x_get_phase2_ca_cert_password, - .pwflag_func = nm_setting_802_1x_get_phase2_ca_cert_password_flags, - .file_suffix = "inner-ca-cert", - }, - - [NM_SETTING_802_1X_SCHEME_TYPE_CLIENT_CERT] = { - .setting_key = NM_SETTING_802_1X_CLIENT_CERT, - .scheme_func = nm_setting_802_1x_get_client_cert_scheme, - .format_func = NULL, - .path_func = nm_setting_802_1x_get_client_cert_path, - .blob_func = nm_setting_802_1x_get_client_cert_blob, - .uri_func = nm_setting_802_1x_get_client_cert_uri, - .passwd_func = nm_setting_802_1x_get_client_cert_password, - .pwflag_func = nm_setting_802_1x_get_client_cert_password_flags, - .file_suffix = "client-cert", - }, - - [NM_SETTING_802_1X_SCHEME_TYPE_PHASE2_CLIENT_CERT] = { - .setting_key = NM_SETTING_802_1X_PHASE2_CLIENT_CERT, - .scheme_func = nm_setting_802_1x_get_phase2_client_cert_scheme, - .format_func = NULL, - .path_func = nm_setting_802_1x_get_phase2_client_cert_path, - .blob_func = nm_setting_802_1x_get_phase2_client_cert_blob, - .uri_func = nm_setting_802_1x_get_phase2_client_cert_uri, - .passwd_func = nm_setting_802_1x_get_phase2_client_cert_password, - .pwflag_func = nm_setting_802_1x_get_phase2_client_cert_password_flags, - .file_suffix = "inner-client-cert", - }, - - [NM_SETTING_802_1X_SCHEME_TYPE_PRIVATE_KEY] = { - .setting_key = NM_SETTING_802_1X_PRIVATE_KEY, - .scheme_func = nm_setting_802_1x_get_private_key_scheme, - .format_func = nm_setting_802_1x_get_private_key_format, - .path_func = nm_setting_802_1x_get_private_key_path, - .blob_func = nm_setting_802_1x_get_private_key_blob, - .uri_func = nm_setting_802_1x_get_private_key_uri, - .passwd_func = nm_setting_802_1x_get_private_key_password, - .pwflag_func = nm_setting_802_1x_get_private_key_password_flags, - .file_suffix = "private-key", - }, - - [NM_SETTING_802_1X_SCHEME_TYPE_PHASE2_PRIVATE_KEY] = { - .setting_key = NM_SETTING_802_1X_PHASE2_PRIVATE_KEY, - .scheme_func = nm_setting_802_1x_get_phase2_private_key_scheme, - .format_func = nm_setting_802_1x_get_phase2_private_key_format, - .path_func = nm_setting_802_1x_get_phase2_private_key_path, - .blob_func = nm_setting_802_1x_get_phase2_private_key_blob, - .uri_func = nm_setting_802_1x_get_phase2_private_key_uri, - .passwd_func = nm_setting_802_1x_get_phase2_private_key_password, - .pwflag_func = nm_setting_802_1x_get_phase2_private_key_password_flags, - .file_suffix = "inner-private-key", - }, - - [NM_SETTING_802_1X_SCHEME_TYPE_UNKNOWN] = { NULL }, -}; - -/*****************************************************************************/ diff --git a/shared/nm-utils/nm-enum-utils.c b/shared/nm-utils/nm-enum-utils.c new file mode 100644 index 0000000000..3eda9eeed3 --- /dev/null +++ b/shared/nm-utils/nm-enum-utils.c @@ -0,0 +1,346 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/* NetworkManager -- Network link manager + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA. + * + * (C) Copyright 2017 Red Hat, Inc. + */ + +#include "nm-default.h" + +#include "nm-enum-utils.h" + +/*****************************************************************************/ + +#define IS_FLAGS_SEPARATOR(ch) (NM_IN_SET ((ch), ' ', '\t', ',', '\n', '\r')) + +static gboolean +_is_hex_string (const char *str) +{ + return str[0] == '0' + && str[1] == 'x' + && str[2] + && NM_STRCHAR_ALL (&str[2], ch, g_ascii_isxdigit (ch)); +} + +static gboolean +_is_dec_string (const char *str) +{ + return str[0] + && NM_STRCHAR_ALL (&str[0], ch, g_ascii_isdigit (ch)); +} + +static gboolean +_enum_is_valid_enum_nick (const char *str) +{ + return str[0] + && !NM_STRCHAR_ANY (str, ch, g_ascii_isspace (ch)) + && !_is_dec_string (str) + && !_is_hex_string (str); +} + +static gboolean +_enum_is_valid_flags_nick (const char *str) +{ + return str[0] + && !NM_STRCHAR_ANY (str, ch, IS_FLAGS_SEPARATOR (ch)) + && !_is_dec_string (str) + && !_is_hex_string (str); +} + +char * +_nm_utils_enum_to_str_full (GType type, + int value, + const char *flags_separator) +{ + GTypeClass *class; + char *ret; + + if ( flags_separator + && ( !flags_separator[0] + || NM_STRCHAR_ANY (flags_separator, ch, !IS_FLAGS_SEPARATOR (ch)))) + g_return_val_if_reached (NULL); + + class = g_type_class_ref (type); + + if (G_IS_ENUM_CLASS (class)) { + GEnumValue *enum_value; + + enum_value = g_enum_get_value (G_ENUM_CLASS (class), value); + if ( !enum_value + || !_enum_is_valid_enum_nick (enum_value->value_nick)) + ret = g_strdup_printf ("%d", value); + else + ret = strdup (enum_value->value_nick); + } else if (G_IS_FLAGS_CLASS (class)) { + GFlagsValue *flags_value; + GString *str = g_string_new (""); + unsigned uvalue = (unsigned) value; + + flags_separator = flags_separator ?: " "; + + do { + flags_value = g_flags_get_first_value (G_FLAGS_CLASS (class), uvalue); + if (str->len) + g_string_append (str, flags_separator); + if ( !flags_value + || !_enum_is_valid_flags_nick (flags_value->value_nick)) { + if (uvalue) + g_string_append_printf (str, "0x%x", uvalue); + break; + } + g_string_append (str, flags_value->value_nick); + uvalue &= ~flags_value->value; + } while (uvalue); + ret = g_string_free (str, FALSE); + } else + g_return_val_if_reached (NULL); + + g_type_class_unref (class); + return ret; +} + +/** + * nm_utils_enum_to_str: + * @type: the %GType of the enum + * @value: the value to be translated + * + * Converts an enum value to its string representation. If the enum is a + * %G_TYPE_FLAGS the function returns a comma-separated list of matching values. + * If the value has no corresponding string representation, it is converted + * to a number. For enums it is converted to a decimal number, for flags + * to an (unsigned) hex number. + * + * Returns: a newly allocated string or %NULL + * + * Since: 1.2 + */ +char * +nm_utils_enum_to_str (GType type, int value) +{ + return _nm_utils_enum_to_str_full (type, value, ", "); +} + +/** + * nm_utils_enum_from_str: + * @type: the %GType of the enum + * @str: the input string + * @out_value: (out) (allow-none): the output value + * @err_token: (out) (allow-none) (transfer full): location to store the first unrecognized token + * + * Converts a string to the matching enum value. + * + * If the enum is a %G_TYPE_FLAGS the function returns the logical OR of values + * matching the comma-separated tokens in the string; if an unknown token is found + * the function returns %FALSE and stores a pointer to a newly allocated string + * containing the unrecognized token in @err_token. + * + * Returns: %TRUE if the conversion was successful, %FALSE otherwise + * + * Since: 1.2 + */ +gboolean +nm_utils_enum_from_str (GType type, const char *str, + int *out_value, char **err_token) +{ + return _nm_utils_enum_from_str_full (type, str, out_value, err_token, NULL); +} + +static const NMUtilsEnumValueInfo * +_find_value_info (const NMUtilsEnumValueInfo *value_infos, const char *needle) +{ + if (value_infos) { + for (; value_infos->nick; value_infos++) { + if (nm_streq (needle, value_infos->nick)) + return value_infos; + } + } + return NULL; +} + +gboolean +_nm_utils_enum_from_str_full (GType type, + const char *str, + int *out_value, + char **err_token, + const NMUtilsEnumValueInfo *value_infos) +{ + GTypeClass *class; + gboolean ret = FALSE; + int value = 0; + gs_free char *str_clone = NULL; + char *s; + gint64 v64; + const NMUtilsEnumValueInfo *nick; + + g_return_val_if_fail (str, FALSE); + + str_clone = strdup (str); + s = nm_str_skip_leading_spaces (str_clone); + g_strchomp (s); + + class = g_type_class_ref (type); + + if (G_IS_ENUM_CLASS (class)) { + GEnumValue *enum_value; + + if (s[0]) { + if (_is_hex_string (s)) { + v64 = _nm_utils_ascii_str_to_int64 (s, 16, 0, G_MAXUINT, -1); + if (v64 != -1) { + value = (int) v64; + ret = TRUE; + } + } else if (_is_dec_string (s)) { + v64 = _nm_utils_ascii_str_to_int64 (s, 10, 0, G_MAXUINT, -1); + if (v64 != -1) { + value = (int) v64; + ret = TRUE; + } + } else { + enum_value = g_enum_get_value_by_nick (G_ENUM_CLASS (class), s); + if (enum_value) { + value = enum_value->value; + ret = TRUE; + } else { + nick = _find_value_info (value_infos, s); + if (nick) { + value = nick->value; + ret = TRUE; + } + } + } + } + } else if (G_IS_FLAGS_CLASS (class)) { + GFlagsValue *flags_value; + unsigned uvalue = 0; + + ret = TRUE; + while (s[0]) { + char *s_end; + + for (s_end = s; s_end[0]; s_end++) { + if (IS_FLAGS_SEPARATOR (s_end[0])) { + s_end[0] = '\0'; + s_end++; + break; + } + } + + if (s[0]) { + if (_is_hex_string (s)) { + v64 = _nm_utils_ascii_str_to_int64 (&s[2], 16, 0, G_MAXUINT, -1); + if (v64 == -1) { + ret = FALSE; + break; + } + uvalue |= (unsigned) v64; + } else if (_is_dec_string (s)) { + v64 = _nm_utils_ascii_str_to_int64 (s, 10, 0, G_MAXUINT, -1); + if (v64 == -1) { + ret = FALSE; + break; + } + uvalue |= (unsigned) v64; + } else { + flags_value = g_flags_get_value_by_nick (G_FLAGS_CLASS (class), s); + if (flags_value) + uvalue |= flags_value->value; + else { + nick = _find_value_info (value_infos, s); + if (nick) + uvalue = (unsigned) nick->value; + else { + ret = FALSE; + break; + } + } + } + } + + s = s_end; + } + + value = (int) uvalue; + } else + g_return_val_if_reached (FALSE); + + NM_SET_OUT (err_token, !ret && s[0] ? g_strdup (s) : NULL); + NM_SET_OUT (out_value, ret ? value : 0); + g_type_class_unref (class); + return ret; +} + +/** + * nm_utils_enum_get_values: + * @type: the %GType of the enum + * @from: the first element to be returned + * @to: the last element to be returned + * + * Returns the list of possible values for a given enum. + * + * Returns: (transfer container): a NULL-terminated dynamically-allocated array of static strings + * or %NULL on error + * + * Since: 1.2 + */ +const char **nm_utils_enum_get_values (GType type, gint from, gint to) +{ + GTypeClass *class; + GPtrArray *array; + gint i; + char sbuf[64]; + + class = g_type_class_ref (type); + array = g_ptr_array_new (); + + if (G_IS_ENUM_CLASS (class)) { + GEnumClass *enum_class = G_ENUM_CLASS (class); + GEnumValue *enum_value; + + for (i = 0; i < enum_class->n_values; i++) { + enum_value = &enum_class->values[i]; + if (enum_value->value >= from && enum_value->value <= to) { + if (_enum_is_valid_enum_nick (enum_value->value_nick)) + g_ptr_array_add (array, (gpointer) enum_value->value_nick); + else + g_ptr_array_add (array, (gpointer) g_intern_string (nm_sprintf_buf (sbuf, "%d", enum_value->value))); + } + } + } else if (G_IS_FLAGS_CLASS (class)) { + GFlagsClass *flags_class = G_FLAGS_CLASS (class); + GFlagsValue *flags_value; + + for (i = 0; i < flags_class->n_values; i++) { + flags_value = &flags_class->values[i]; + if (flags_value->value >= from && flags_value->value <= to) { + if (_enum_is_valid_flags_nick (flags_value->value_nick)) + g_ptr_array_add (array, (gpointer) flags_value->value_nick); + else + g_ptr_array_add (array, (gpointer) g_intern_string (nm_sprintf_buf (sbuf, "0x%x", (unsigned) flags_value->value))); + } + } + } else { + g_type_class_unref (class); + g_ptr_array_free (array, TRUE); + g_return_val_if_reached (NULL); + } + + g_type_class_unref (class); + g_ptr_array_add (array, NULL); + + return (const char **) g_ptr_array_free (array, FALSE); +} diff --git a/shared/nm-utils/nm-enum-utils.h b/shared/nm-utils/nm-enum-utils.h new file mode 100644 index 0000000000..047fbc72b0 --- /dev/null +++ b/shared/nm-utils/nm-enum-utils.h @@ -0,0 +1,47 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/* NetworkManager -- Network link manager + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA. + * + * (C) Copyright 2017 Red Hat, Inc. + */ + +#ifndef __NM_ENUM_UTILS_H__ +#define __NM_ENUM_UTILS_H__ + +/*****************************************************************************/ + +typedef struct _NMUtilsEnumValueInfo { + /* currently, this is only used for _nm_utils_enum_from_str_full() to + * declare additional aliases for values. */ + const char *nick; + int value; +} NMUtilsEnumValueInfo; + +char *_nm_utils_enum_to_str_full (GType type, int value, const char *sep); +gboolean _nm_utils_enum_from_str_full (GType type, + const char *str, + int *out_value, + char **err_token, + const NMUtilsEnumValueInfo *value_infos); + +char *nm_utils_enum_to_str (GType type, int value); +gboolean nm_utils_enum_from_str (GType type, const char *str, int *out_value, char **err_token); +const char **nm_utils_enum_get_values (GType type, gint from, gint to); + +/*****************************************************************************/ + +#endif /* __NM_ENUM_UTILS_H__ */ diff --git a/shared/nm-utils/nm-macros-internal.h b/shared/nm-utils/nm-macros-internal.h index e1e3431a75..3f836a78d7 100644 --- a/shared/nm-utils/nm-macros-internal.h +++ b/shared/nm-utils/nm-macros-internal.h @@ -56,6 +56,14 @@ _nm_auto_unset_gvalue_impl (GValue *v) #define nm_auto_unset_gvalue nm_auto(_nm_auto_unset_gvalue_impl) static inline void +_nm_auto_unref_gtypeclass (GTypeClass **v) +{ + if (v && *v) + g_type_class_unref (*v); +} +#define nm_auto_unref_gtypeclass nm_auto(_nm_auto_unref_gtypeclass) + +static inline void _nm_auto_free_gstring_impl (GString **str) { if (*str) diff --git a/shared/nm-utils/nm-shared-utils.h b/shared/nm-utils/nm-shared-utils.h index f1f9f51833..b559401c8b 100644 --- a/shared/nm-utils/nm-shared-utils.h +++ b/shared/nm-utils/nm-shared-utils.h @@ -62,10 +62,12 @@ gint _nm_utils_ascii_str_to_bool (const char *str, * error reason. Depending on the usage, this might indicate a bug because * usually the target object should stay alive as long as there are pending * operations. + * @NM_UTILS_ERROR_INVALID_ARGUMENT: invalid argument. */ typedef enum { NM_UTILS_ERROR_UNKNOWN = 0, /*< nick=Unknown >*/ NM_UTILS_ERROR_CANCELLED_DISPOSING, /*< nick=CancelledDisposing >*/ + NM_UTILS_ERROR_INVALID_ARGUMENT, /*< nick=InvalidArgument >*/ } NMUtilsError; #define NM_UTILS_ERROR (nm_utils_error_quark ()) diff --git a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c index 8129f5cc13..8aa6b9e8f0 100644 --- a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c +++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c @@ -32,6 +32,7 @@ #include <unistd.h> #include <stdio.h> +#include "nm-utils/nm-enum-utils.h" #include "nm-manager.h" #include "nm-setting-connection.h" #include "nm-setting-wired.h" @@ -47,7 +48,7 @@ #include "nm-utils.h" #include "nm-core-internal.h" #include "NetworkManagerUtils.h" -#include "nm-setting-metadata.h" +#include "nm-meta-setting.h" #include "nms-ifcfg-rh-common.h" #include "nms-ifcfg-rh-reader.h" diff --git a/src/settings/plugins/ifnet/nms-ifnet-connection-parser.c b/src/settings/plugins/ifnet/nms-ifnet-connection-parser.c index c5129fea40..ed0a757fdb 100644 --- a/src/settings/plugins/ifnet/nms-ifnet-connection-parser.c +++ b/src/settings/plugins/ifnet/nms-ifnet-connection-parser.c @@ -31,7 +31,7 @@ #include "settings/nm-settings-plugin.h" #include "nm-core-internal.h" #include "NetworkManagerUtils.h" -#include "nm-setting-metadata.h" +#include "nm-meta-setting.h" #include "nms-ifnet-net-utils.h" #include "nms-ifnet-wpa-parser.h" |