mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-14 16:00:18 +01:00
ifcfg-rh: fix writing LEAP connections
This commit is contained in:
parent
40c91efa21
commit
4eb2346b67
2 changed files with 136 additions and 1 deletions
|
|
@ -4207,6 +4207,140 @@ test_write_wifi_wep_adhoc (void)
|
|||
g_object_unref (reread);
|
||||
}
|
||||
|
||||
static void
|
||||
test_write_wifi_leap (void)
|
||||
{
|
||||
NMConnection *connection;
|
||||
NMConnection *reread;
|
||||
NMSettingConnection *s_con;
|
||||
NMSettingWireless *s_wifi;
|
||||
NMSettingWirelessSecurity *s_wsec;
|
||||
NMSettingIP4Config *s_ip4;
|
||||
char *uuid;
|
||||
gboolean success;
|
||||
GError *error = NULL;
|
||||
char *testfile = NULL;
|
||||
char *unmanaged = NULL;
|
||||
char *keyfile = NULL;
|
||||
gboolean ignore_error = FALSE;
|
||||
GByteArray *ssid;
|
||||
const unsigned char ssid_data[] = "blahblah";
|
||||
struct stat statbuf;
|
||||
|
||||
connection = nm_connection_new ();
|
||||
ASSERT (connection != NULL,
|
||||
"wifi-leap-write", "failed to allocate new connection");
|
||||
|
||||
/* Connection setting */
|
||||
s_con = (NMSettingConnection *) nm_setting_connection_new ();
|
||||
ASSERT (s_con != NULL,
|
||||
"wifi-leap-write", "failed to allocate new %s setting",
|
||||
NM_SETTING_CONNECTION_SETTING_NAME);
|
||||
nm_connection_add_setting (connection, NM_SETTING (s_con));
|
||||
|
||||
uuid = nm_utils_uuid_generate ();
|
||||
g_object_set (s_con,
|
||||
NM_SETTING_CONNECTION_ID, "Test Write Wifi LEAP",
|
||||
NM_SETTING_CONNECTION_UUID, uuid,
|
||||
NM_SETTING_CONNECTION_AUTOCONNECT, TRUE,
|
||||
NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME,
|
||||
NULL);
|
||||
g_free (uuid);
|
||||
|
||||
/* Wifi setting */
|
||||
s_wifi = (NMSettingWireless *) nm_setting_wireless_new ();
|
||||
ASSERT (s_wifi != NULL,
|
||||
"wifi-leap-write", "failed to allocate new %s setting",
|
||||
NM_SETTING_WIRELESS_SETTING_NAME);
|
||||
nm_connection_add_setting (connection, NM_SETTING (s_wifi));
|
||||
|
||||
ssid = g_byte_array_sized_new (sizeof (ssid_data));
|
||||
g_byte_array_append (ssid, ssid_data, sizeof (ssid_data));
|
||||
|
||||
g_object_set (s_wifi,
|
||||
NM_SETTING_WIRELESS_SSID, ssid,
|
||||
NM_SETTING_WIRELESS_MODE, "infrastructure",
|
||||
NM_SETTING_WIRELESS_SEC, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME,
|
||||
NULL);
|
||||
|
||||
g_byte_array_free (ssid, TRUE);
|
||||
|
||||
/* Wireless security setting */
|
||||
s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new ();
|
||||
ASSERT (s_wsec != NULL,
|
||||
"wifi-leap-write", "failed to allocate new %s setting",
|
||||
NM_SETTING_WIRELESS_SECURITY_SETTING_NAME);
|
||||
nm_connection_add_setting (connection, NM_SETTING (s_wsec));
|
||||
|
||||
g_object_set (s_wsec,
|
||||
NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "ieee8021x",
|
||||
NM_SETTING_WIRELESS_SECURITY_AUTH_ALG, "leap",
|
||||
NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME, "Bill Smith",
|
||||
NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD, "foobar22",
|
||||
NULL);
|
||||
|
||||
/* IP4 setting */
|
||||
s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
|
||||
ASSERT (s_ip4 != NULL,
|
||||
"wifi-leap-write", "failed to allocate new %s setting",
|
||||
NM_SETTING_IP4_CONFIG_SETTING_NAME);
|
||||
nm_connection_add_setting (connection, NM_SETTING (s_ip4));
|
||||
|
||||
g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
|
||||
|
||||
ASSERT (nm_connection_verify (connection, &error) == TRUE,
|
||||
"wifi-leap-write", "failed to verify connection: %s",
|
||||
(error && error->message) ? error->message : "(unknown)");
|
||||
|
||||
/* Save the ifcfg */
|
||||
success = writer_new_connection (connection,
|
||||
TEST_SCRATCH_DIR "/network-scripts/",
|
||||
&testfile,
|
||||
&error);
|
||||
ASSERT (success == TRUE,
|
||||
"wifi-leap-write", "failed to write connection to disk: %s",
|
||||
(error && error->message) ? error->message : "(unknown)");
|
||||
|
||||
ASSERT (testfile != NULL,
|
||||
"wifi-leap-write", "didn't get ifcfg file path back after writing connection");
|
||||
|
||||
/* re-read the connection for comparison */
|
||||
reread = connection_from_file (testfile,
|
||||
NULL,
|
||||
TYPE_WIRELESS,
|
||||
NULL,
|
||||
&unmanaged,
|
||||
&keyfile,
|
||||
&error,
|
||||
&ignore_error);
|
||||
unlink (testfile);
|
||||
|
||||
ASSERT (keyfile != NULL,
|
||||
"wifi-leap-write-reread", "expected keyfile for '%s'", testfile);
|
||||
|
||||
ASSERT (stat (keyfile, &statbuf) == 0,
|
||||
"wifi-leap-write-reread", "couldn't stat() '%s'", keyfile);
|
||||
ASSERT (S_ISREG (statbuf.st_mode),
|
||||
"wifi-leap-write-reread", "keyfile '%s' wasn't a normal file", keyfile);
|
||||
ASSERT ((statbuf.st_mode & 0077) == 0,
|
||||
"wifi-leap-write-reread", "keyfile '%s' wasn't readable only by its owner", keyfile);
|
||||
|
||||
unlink (keyfile);
|
||||
|
||||
ASSERT (reread != NULL,
|
||||
"wifi-leap-write-reread", "failed to read %s: %s", testfile, error->message);
|
||||
|
||||
ASSERT (nm_connection_verify (reread, &error),
|
||||
"wifi-leap-write-reread-verify", "failed to verify %s: %s", testfile, error->message);
|
||||
|
||||
ASSERT (nm_connection_compare (connection, reread, NM_SETTING_COMPARE_FLAG_EXACT) == TRUE,
|
||||
"wifi-leap-write", "written and re-read connection weren't the same.");
|
||||
|
||||
g_free (testfile);
|
||||
g_object_unref (connection);
|
||||
g_object_unref (reread);
|
||||
}
|
||||
|
||||
static void
|
||||
test_write_wifi_wpa_psk (const char *name,
|
||||
const char *test_name,
|
||||
|
|
@ -5671,6 +5805,7 @@ int main (int argc, char **argv)
|
|||
test_write_wifi_open_hex_ssid ();
|
||||
test_write_wifi_wep ();
|
||||
test_write_wifi_wep_adhoc ();
|
||||
test_write_wifi_leap ();
|
||||
test_write_wifi_wpa_psk ("Test Write Wifi WPA PSK",
|
||||
"wifi-wpa-psk-write",
|
||||
FALSE,
|
||||
|
|
|
|||
|
|
@ -575,7 +575,7 @@ write_wireless_security_setting (NMConnection *connection,
|
|||
svSetValue (ifcfg, "SECURITYMODE", "open", FALSE);
|
||||
else if (!strcmp (auth_alg, "leap")) {
|
||||
svSetValue (ifcfg, "SECURITYMODE", "leap", FALSE);
|
||||
svSetValue (ifcfg, "IEEE_8021X_USERNAME",
|
||||
svSetValue (ifcfg, "IEEE_8021X_IDENTITY",
|
||||
nm_setting_wireless_security_get_leap_username (s_wsec),
|
||||
FALSE);
|
||||
set_secret (ifcfg, "IEEE_8021X_PASSWORD",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue