nmcli: fix "device wifi connect" command with existing connection

Executing this command twice, or when a connection profile already
exists for the SSID:

  nmcli device wifi connect $SSID password $PASSWORD

returns error:

  Error: 802-11-wireless-security.key-mgmt: property is missing.

When setting the password nmcli was wiping the existing wireless
security setting.

Fixes: c8ff1b30fb ('nmcli/dev: use secret agent for nmcli d [wifi] connect')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/1688
This commit is contained in:
Beniamino Galvani 2025-12-03 18:24:58 +01:00
parent 8e0825f9cd
commit 3a4e18e302

View file

@ -4041,6 +4041,7 @@ do_device_wifi_connect(const NMCCommand *cmd, NmCli *nmc, int argc, const char *
if (password) {
if (!connection)
connection = nm_simple_connection_new();
s_wsec = nm_connection_get_setting_wireless_security(connection);
if (!s_wsec) {
s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new();
nm_connection_add_setting(connection, NM_SETTING(s_wsec));