Exemplo n.º 1
0
static void
secrets_requested (NMConnectionItem *item,
                   NMConnection *connection,
                   const char *setting_name,
                   const char **hints,
                   gboolean ask_user,
                   NMNewSecretsRequestedFunc callback,
                   gpointer callback_data)
{
    GtkWidget *dialog;
    SecretsRequestInfo *info;

    dialog = nma_wireless_dialog_new (nm_connection_item_get_client (item),
                                      connection,
                                      nm_device_item_get_device (NM_DEVICE_ITEM (item)),
                                      nm_wifi_item_get_ap (NM_WIFI_ITEM (item)));

    info = g_new (SecretsRequestInfo, 1);
    info->callback = callback;
    info->callback_data = callback_data;

    g_signal_connect (dialog, "done", G_CALLBACK (connection_secrets_response_cb), info);
    nma_wireless_dialog_show (NMA_WIRELESS_DIALOG (dialog));
}
void
cc_network_panel_connect_to_8021x_network (CcNetworkPanel   *panel,
        NMClient         *client,
        NMRemoteSettings *settings,
        NMDevice         *device,
        const gchar      *arg_access_point)
{
    NMConnection *connection;
    NMSettingConnection *s_con;
    NMSettingWireless *s_wifi;
    NMSettingWirelessSecurity *s_wsec;
    NMSetting8021x *s_8021x;
    NM80211ApSecurityFlags wpa_flags, rsn_flags;
    GtkWidget *dialog;
    char *uuid;
    NMAccessPoint *ap;

    g_debug ("connect to 8021x wifi");
    ap = nm_device_wifi_get_access_point_by_path (NM_DEVICE_WIFI (device), arg_access_point);
    if (ap == NULL) {
        g_warning ("didn't find access point with path %s", arg_access_point);
        return;
    }

    /* If the AP is WPA[2]-Enterprise then we need to set up a minimal 802.1x
    * setting and ask the user for more information.
     */
    rsn_flags = nm_access_point_get_rsn_flags (ap);
    wpa_flags = nm_access_point_get_wpa_flags (ap);
    if (!(rsn_flags & NM_802_11_AP_SEC_KEY_MGMT_802_1X)
            && !(wpa_flags & NM_802_11_AP_SEC_KEY_MGMT_802_1X)) {
        g_warning ("Network panel loaded with connect-8021x-wifi but the "
                   "access point does not support 802.1x");
        return;
    }

    connection = nm_connection_new ();

    /* Need a UUID for the "always ask" stuff in the Dialog of Doom */
    s_con = (NMSettingConnection *) nm_setting_connection_new ();
    uuid = nm_utils_uuid_generate ();
    g_object_set (s_con, NM_SETTING_CONNECTION_UUID, uuid, NULL);
    g_free (uuid);
    nm_connection_add_setting (connection, NM_SETTING (s_con));

    s_wifi = (NMSettingWireless *) nm_setting_wireless_new ();
    nm_connection_add_setting (connection, NM_SETTING (s_wifi));
    g_object_set (s_wifi,
                  NM_SETTING_WIRELESS_SSID, nm_access_point_get_ssid (ap),
                  NM_SETTING_WIRELESS_SEC, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME,
                  NULL);

    s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new ();
    g_object_set (s_wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "wpa-eap", NULL);
    nm_connection_add_setting (connection, NM_SETTING (s_wsec));

    s_8021x = (NMSetting8021x *) nm_setting_802_1x_new ();
    nm_setting_802_1x_add_eap_method (s_8021x, "ttls");
    g_object_set (s_8021x, NM_SETTING_802_1X_PHASE2_AUTH, "mschapv2", NULL);
    nm_connection_add_setting (connection, NM_SETTING (s_8021x));

    dialog = nma_wireless_dialog_new (client, settings, connection, device, ap, FALSE);
    show_wireless_dialog (panel, client, settings, dialog);
}