diff options
Diffstat (limited to 'src/nmcli/devices.c')
| -rw-r--r-- | src/nmcli/devices.c | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/src/nmcli/devices.c b/src/nmcli/devices.c index c160fff6..d408b47f 100644 --- a/src/nmcli/devices.c +++ b/src/nmcli/devices.c @@ -17,6 +17,7 @@ #include <linux/if_ether.h> #include "libnm-glib-aux/nm-secret-utils.h" +#include "libnm-glib-aux/nm-random-utils.h" #include "common.h" #include "connections.h" #include "libnmc-base/nm-client-utils.h" @@ -4090,7 +4091,7 @@ generate_ssid_for_hotspot(void) return ssid_bytes; } -#define WPA_PASSKEY_SIZE 8 +#define WPA_PASSKEY_SIZE 12 static void generate_wpa_key(char *key, size_t len) { @@ -4099,13 +4100,14 @@ generate_wpa_key(char *key, size_t len) g_return_if_fail(key); g_return_if_fail(len > WPA_PASSKEY_SIZE); - /* generate a 8-chars ASCII WPA key */ for (i = 0; i < WPA_PASSKEY_SIZE; i++) { int c; - c = g_random_int_range(33, 126); - /* too many non alphanumeric characters are hard to remember for humans */ - while (!g_ascii_isalnum(c)) - c = g_random_int_range(33, 126); + + do { + c = nm_random_u64_range_full(48, 122, TRUE); + /* skip characters that look similar */ + } while (NM_IN_SET(c, '1', 'l', 'I', '0', 'O', 'Q', '8', 'B', '5', 'S') + || !g_ascii_isalnum(c)); key[i] = (char) c; } @@ -4124,7 +4126,8 @@ generate_wep_key(char *key, size_t len) /* generate a 10-digit hex WEP key */ for (i = 0; i < 10; i++) { int digit; - digit = g_random_int_range(0, 16); + + digit = nm_random_u64_range_full(0, 16, TRUE); key[i] = hexdigits[digit]; } key[10] = '\0'; @@ -4138,7 +4141,7 @@ set_wireless_security_for_hotspot(NMSettingWirelessSecurity *s_wsec, gboolean show_password, GError **error) { - char generated_key[11]; + char generated_key[20]; const char *key; const char *key_mgmt; @@ -4264,6 +4267,8 @@ create_hotspot_conn(const GPtrArray *connections, NMSettingIPConfig *s_ip4, *s_ip6; NMSettingProxy *s_proxy; + nm_assert(channel_int == -1 || band); + connection = nm_simple_connection_new(); s_con = (NMSettingConnection *) nm_setting_connection_new(); nm_connection_add_setting(connection, NM_SETTING(s_con)); @@ -4294,6 +4299,8 @@ create_hotspot_conn(const GPtrArray *connections, NM_SETTING_WIRELESS_BAND, band, NULL); + } else if (band) { + g_object_set(s_wifi, NM_SETTING_WIRELESS_BAND, band, NULL); } s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new(); @@ -4439,13 +4446,6 @@ do_device_wifi_hotspot(const NMCCommand *cmd, NmCli *nmc, int argc, const char * if (nmc->complete) return; - /* Verify band and channel parameters */ - if (!channel) { - if (g_strcmp0(band, "bg") == 0) - channel = "1"; - if (g_strcmp0(band, "a") == 0) - channel = "7"; - } if (channel) { unsigned long int value; |