keyfile: fixups for msising settings for mobile broadband

This commit is contained in:
Dan Williams 2010-05-26 01:03:38 -07:00
parent d422ce42c4
commit 11d63b63f2
2 changed files with 146 additions and 6 deletions

View file

@ -34,6 +34,8 @@
#include <nm-setting-wireless.h>
#include <nm-setting-bluetooth.h>
#include <nm-setting-serial.h>
#include <nm-setting-gsm.h>
#include <nm-setting-cdma.h>
#include <nm-setting-ppp.h>
#include <arpa/inet.h>
#include <netinet/ether.h>
@ -998,12 +1000,13 @@ connection_from_file (const char *filename)
key_file = g_key_file_new ();
if (g_key_file_load_from_file (key_file, filename, G_KEY_FILE_NONE, &err)) {
NMSettingConnection *s_con;
NMSettingBluetooth *s_bt;
NMSetting *setting;
gchar **groups;
gsize length;
int i;
gboolean vpn_secrets = FALSE;
const char *ctype;
const char *ctype, *tmp;
connection = nm_connection_new ();
@ -1028,12 +1031,30 @@ connection_from_file (const char *filename)
if (s_con) {
ctype = nm_setting_connection_get_connection_type (s_con);
setting = nm_connection_get_setting_by_name (connection, ctype);
if (!setting && ctype) {
if (!strcmp (ctype, NM_SETTING_WIRED_SETTING_NAME))
setting = nm_setting_wired_new ();
if (ctype) {
gboolean add_serial = FALSE;
NMSetting *new_setting = NULL;
if (setting)
nm_connection_add_setting (connection, setting);
if (!setting && !strcmp (ctype, NM_SETTING_WIRED_SETTING_NAME))
new_setting = nm_setting_wired_new ();
else if (!strcmp (ctype, NM_SETTING_BLUETOOTH_SETTING_NAME)) {
s_bt = (NMSettingBluetooth *) nm_connection_get_setting (connection, NM_TYPE_SETTING_BLUETOOTH);
if (s_bt) {
tmp = nm_setting_bluetooth_get_connection_type (s_bt);
if (tmp && !strcmp (tmp, NM_SETTING_BLUETOOTH_TYPE_DUN))
add_serial = TRUE;
}
} else if (!strcmp (ctype, NM_SETTING_GSM_SETTING_NAME))
add_serial = TRUE;
else if (!strcmp (ctype, NM_SETTING_CDMA_SETTING_NAME))
add_serial = TRUE;
/* Bluetooth DUN, GSM, and CDMA connections require a serial setting */
if (add_serial && !nm_connection_get_setting (connection, NM_TYPE_SETTING_SERIAL))
new_setting = nm_setting_serial_new ();
if (new_setting)
nm_connection_add_setting (connection, new_setting);
}
}

View file

@ -1463,6 +1463,124 @@ test_read_bt_dun_connection (void)
g_object_unref (connection);
}
static void
test_write_bt_dun_connection (void)
{
NMConnection *connection;
NMSettingConnection *s_con;
NMSettingBluetooth *s_bt;
NMSettingIP4Config *s_ip4;
NMSettingGsm *s_gsm;
char *uuid;
GByteArray *bdaddr;
unsigned char tmpbdaddr[] = { 0xaa, 0xb9, 0xa1, 0x74, 0x55, 0x44 };
gboolean success;
NMConnection *reread;
char *testfile = NULL;
GError *error = NULL;
pid_t owner_grp;
uid_t owner_uid;
guint64 timestamp = 0x12344433L;
connection = nm_connection_new ();
ASSERT (connection != NULL,
"connection-write", "failed to allocate new connection");
/* Connection setting */
s_con = NM_SETTING_CONNECTION (nm_setting_connection_new ());
ASSERT (s_con != NULL,
"connection-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, "T-Mobile Funkadelic",
NM_SETTING_CONNECTION_UUID, uuid,
NM_SETTING_CONNECTION_AUTOCONNECT, FALSE,
NM_SETTING_CONNECTION_TYPE, NM_SETTING_BLUETOOTH_SETTING_NAME,
NM_SETTING_CONNECTION_TIMESTAMP, timestamp,
NULL);
g_free (uuid);
/* Bluetooth setting */
s_bt = NM_SETTING_BLUETOOTH (nm_setting_bluetooth_new ());
ASSERT (s_bt != NULL,
"connection-write", "failed to allocate new %s setting",
NM_SETTING_BLUETOOTH_SETTING_NAME);
nm_connection_add_setting (connection, NM_SETTING (s_bt));
bdaddr = g_byte_array_sized_new (ETH_ALEN);
g_byte_array_append (bdaddr, &tmpbdaddr[0], sizeof (tmpbdaddr));
g_object_set (s_bt,
NM_SETTING_BLUETOOTH_BDADDR, bdaddr,
NM_SETTING_BLUETOOTH_TYPE, NM_SETTING_BLUETOOTH_TYPE_DUN,
NULL);
g_byte_array_free (bdaddr, TRUE);
/* IP4 setting */
s_ip4 = NM_SETTING_IP4_CONFIG (nm_setting_ip4_config_new ());
ASSERT (s_ip4 != NULL,
"connection-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);
/* GSM setting */
s_gsm = NM_SETTING_GSM (nm_setting_gsm_new ());
ASSERT (s_gsm != NULL,
"connection-write", "failed to allocate new %s setting",
NM_SETTING_GSM_SETTING_NAME);
nm_connection_add_setting (connection, NM_SETTING (s_gsm));
g_object_set (s_gsm,
NM_SETTING_GSM_APN, "internet2.voicestream.com",
NM_SETTING_GSM_USERNAME, "george.clinton",
NM_SETTING_GSM_PASSWORD, "parliament",
NM_SETTING_GSM_NUMBER, "*99#",
NULL);
/* Serial setting */
nm_connection_add_setting (connection, nm_setting_serial_new ());
/* PPP setting */
nm_connection_add_setting (connection, nm_setting_ppp_new ());
/* Write out the connection */
owner_uid = geteuid ();
owner_grp = getegid ();
success = write_connection (connection, TEST_SCRATCH_DIR, owner_uid, owner_grp, &testfile, &error);
ASSERT (success == TRUE,
"connection-write", "failed to allocate write keyfile: %s",
error ? error->message : "(none)");
ASSERT (testfile != NULL,
"connection-write", "didn't get keyfile name back after writing connection");
/* Read the connection back in and compare it to the one we just wrote out */
reread = connection_from_file (testfile);
ASSERT (reread != NULL, "connection-write", "failed to re-read test connection");
ASSERT (nm_connection_compare (connection, reread, NM_SETTING_COMPARE_FLAG_EXACT) == TRUE,
"connection-write", "written and re-read connection weren't the same");
g_clear_error (&error);
unlink (testfile);
g_free (testfile);
g_object_unref (reread);
g_object_unref (connection);
}
int main (int argc, char **argv)
{
GError *error = NULL;
@ -1488,6 +1606,7 @@ int main (int argc, char **argv)
test_write_wireless_connection ();
test_read_bt_dun_connection ();
test_write_bt_dun_connection ();
base = g_path_get_basename (argv[0]);
fprintf (stdout, "%s: SUCCESS\n", base);