network: Move EAPMethod property to a virtual method

This commit is contained in:
Robert Ancell 2019-11-07 10:20:34 +13:00 committed by Georges Basile Stavracas Neto
parent 2e8226a09c
commit 426896b7a2
8 changed files with 57 additions and 28 deletions

View file

@ -334,8 +334,8 @@ eap_method_fast_new (WirelessSecurity *ws_parent,
get_widget,
get_default_field,
get_password_flags_name,
destroy,
FALSE);
NULL,
destroy);
if (!parent)
return NULL;

View file

@ -218,8 +218,8 @@ eap_method_leap_new (WirelessSecurity *ws_parent,
get_widget,
get_default_field,
get_password_flags_name,
destroy,
FALSE);
NULL,
destroy);
if (!parent)
return NULL;

View file

@ -342,8 +342,8 @@ eap_method_peap_new (WirelessSecurity *ws_parent,
get_widget,
get_default_field,
get_password_flags_name,
destroy,
FALSE);
NULL,
destroy);
if (!parent)
return NULL;

View file

@ -140,11 +140,11 @@ fill_connection (EAPMethod *parent, NMConnection *connection, NMSettingSecretFla
/* If this is the main EAP method, clear any existing methods because the
* user-selected on will replace it.
*/
if (parent->phase2 == FALSE)
if (eap_method_get_phase2 (parent) == FALSE)
nm_setting_802_1x_clear_eap_methods (s_8021x);
eap_type = &eap_table[self->type];
if (parent->phase2) {
if (eap_method_get_phase2 (parent)) {
/* If the outer EAP method (TLS, TTLS, PEAP, etc) allows inner/phase2
* EAP methods (which only TTLS allows) *and* the inner/phase2 method
* supports being an inner EAP method, then set PHASE2_AUTHEAP.
@ -212,6 +212,13 @@ get_password_flags_name (EAPMethod *parent)
return NM_SETTING_802_1X_PASSWORD;
}
static const gboolean
get_phase2 (EAPMethod *parent)
{
EAPMethodSimple *self = (EAPMethodSimple *) parent;
return self->flags & EAP_METHOD_SIMPLE_FLAG_PHASE2;
}
static gboolean
stuff_changed (EAPMethodSimple *self)
{
@ -315,8 +322,8 @@ eap_method_simple_new (WirelessSecurity *ws_parent,
get_widget,
get_default_field,
get_password_flags_name,
destroy,
flags & EAP_METHOD_SIMPLE_FLAG_PHASE2);
get_phase2,
destroy);
if (!parent)
return NULL;

View file

@ -50,6 +50,7 @@ struct _EAPMethodTLS {
GtkFileChooserButton *user_cert_button;
GtkLabel *user_cert_label;
gboolean phase2;
const gchar *password_flags_name;
WirelessSecurity *sec_parent;
gboolean editing_connection;
@ -172,7 +173,7 @@ fill_connection (EAPMethod *parent, NMConnection *connection, NMSettingSecretFla
s_8021x = nm_connection_get_setting_802_1x (connection);
g_assert (s_8021x);
if (parent->phase2)
if (self->phase2)
g_object_set (s_8021x, NM_SETTING_802_1X_PHASE2_AUTH, "tls", NULL);
else
nm_setting_802_1x_add_eap_method (s_8021x, "tls");
@ -185,7 +186,7 @@ fill_connection (EAPMethod *parent, NMConnection *connection, NMSettingSecretFla
pk_filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (self->private_key_button));
g_assert (pk_filename);
if (parent->phase2) {
if (self->phase2) {
g_autoptr(GError) error = NULL;
if (!nm_setting_802_1x_set_phase2_private_key (s_8021x, pk_filename, password, NM_SETTING_802_1X_CK_SCHEME_PATH, &format, &error))
g_warning ("Couldn't read phase2 private key '%s': %s", pk_filename, error ? error->message : "(unknown)");
@ -217,7 +218,7 @@ fill_connection (EAPMethod *parent, NMConnection *connection, NMSettingSecretFla
g_assert (cc_filename);
format = NM_SETTING_802_1X_CK_FORMAT_UNKNOWN;
if (parent->phase2) {
if (self->phase2) {
g_autoptr(GError) error = NULL;
if (!nm_setting_802_1x_set_phase2_client_cert (s_8021x, cc_filename, NM_SETTING_802_1X_CK_SCHEME_PATH, &format, &error))
g_warning ("Couldn't read phase2 client certificate '%s': %s", cc_filename, error ? error->message : "(unknown)");
@ -232,7 +233,7 @@ fill_connection (EAPMethod *parent, NMConnection *connection, NMSettingSecretFla
ca_filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (self->ca_cert_button));
format = NM_SETTING_802_1X_CK_FORMAT_UNKNOWN;
if (parent->phase2) {
if (self->phase2) {
g_autoptr(GError) error = NULL;
if (!nm_setting_802_1x_set_phase2_ca_cert (s_8021x, ca_filename, NM_SETTING_802_1X_CK_SCHEME_PATH, &format, &error)) {
g_warning ("Couldn't read phase2 CA certificate '%s': %s", ca_filename, error ? error->message : "(unknown)");
@ -381,7 +382,7 @@ update_secrets (EAPMethod *parent, NMConnection *connection)
PathFunc path_func;
const char *filename;
if (parent->phase2) {
if (self->phase2) {
password_func = (HelperSecretFunc) nm_setting_802_1x_get_phase2_private_key_password;
scheme_func = nm_setting_802_1x_get_phase2_private_key_scheme;
path_func = nm_setting_802_1x_get_phase2_private_key_path;
@ -426,6 +427,13 @@ get_password_flags_name (EAPMethod *parent)
return self->password_flags_name;
}
static gboolean
get_phase2 (EAPMethod *parent)
{
EAPMethodTLS *self = (EAPMethodTLS *) parent;
return self->phase2;
}
EAPMethodTLS *
eap_method_tls_new (WirelessSecurity *ws_parent,
NMConnection *connection,
@ -446,12 +454,13 @@ eap_method_tls_new (WirelessSecurity *ws_parent,
get_widget,
get_default_field,
get_password_flags_name,
destroy,
phase2);
get_phase2,
destroy);
if (!parent)
return NULL;
self = (EAPMethodTLS *) parent;
self->phase2 = phase2;
self->password_flags_name = phase2 ?
NM_SETTING_802_1X_PHASE2_PRIVATE_KEY_PASSWORD :
NM_SETTING_802_1X_PRIVATE_KEY_PASSWORD;

View file

@ -395,8 +395,8 @@ eap_method_ttls_new (WirelessSecurity *ws_parent,
get_widget,
get_default_field,
get_password_flags_name,
destroy,
FALSE);
NULL,
destroy);
if (!parent)
return NULL;

View file

@ -74,6 +74,17 @@ eap_method_get_password_flags_name (EAPMethod *self)
return NULL;
}
gboolean
eap_method_get_phase2 (EAPMethod *self)
{
g_return_val_if_fail (self != NULL, FALSE);
if (self->get_phase2)
return self->get_phase2 (self);
else
return FALSE;
}
gboolean
eap_method_validate (EAPMethod *self, GError **error)
{
@ -145,8 +156,8 @@ eap_method_init (gsize obj_size,
EMGetWidgetFunc get_widget,
EMGetWidgetFunc get_default_field,
EMGetStringFunc get_password_flags_name,
EMDestroyFunc destroy,
gboolean phase2)
EMGetBooleanFunc get_phase2,
EMDestroyFunc destroy)
{
g_autoptr(EAPMethod) self = NULL;
@ -164,8 +175,8 @@ eap_method_init (gsize obj_size,
self->get_widget = get_widget;
self->get_default_field = get_default_field;
self->get_password_flags_name = get_password_flags_name;
self->get_phase2 = get_phase2;
self->destroy = destroy;
self->phase2 = phase2;
return g_steal_pointer (&self);
}
@ -528,7 +539,7 @@ eap_method_ca_cert_ignore_set (EAPMethod *self,
if (s_8021x) {
ignore = !ca_cert_error && filename == NULL;
g_object_set_data (G_OBJECT (s_8021x),
self->phase2 ? IGNORE_PHASE2_CA_CERT_TAG : IGNORE_CA_CERT_TAG,
eap_method_get_phase2 (self) ? IGNORE_PHASE2_CA_CERT_TAG : IGNORE_CA_CERT_TAG,
GUINT_TO_POINTER (ignore));
}
}
@ -549,7 +560,7 @@ eap_method_ca_cert_ignore_get (EAPMethod *self, NMConnection *connection)
s_8021x = nm_connection_get_setting_802_1x (connection);
if (s_8021x) {
return !!g_object_get_data (G_OBJECT (s_8021x),
self->phase2 ? IGNORE_PHASE2_CA_CERT_TAG : IGNORE_CA_CERT_TAG);
eap_method_get_phase2 (self) ? IGNORE_PHASE2_CA_CERT_TAG : IGNORE_CA_CERT_TAG);
}
return FALSE;
}

View file

@ -34,13 +34,12 @@ typedef void (*EMDestroyFunc) (EAPMethod *method);
typedef gboolean (*EMValidateFunc) (EAPMethod *method, GError **error);
typedef GtkWidget* (*EMGetWidgetFunc) (EAPMethod *method);
typedef const gchar* (*EMGetStringFunc) (EAPMethod *method);
typedef gboolean (*EMGetBooleanFunc) (EAPMethod *method);
struct _EAPMethod {
guint32 refcount;
gsize obj_size;
gboolean phase2;
EMAddToSizeGroupFunc add_to_size_group;
EMFillConnectionFunc fill_connection;
EMUpdateSecretsFunc update_secrets;
@ -48,6 +47,7 @@ struct _EAPMethod {
EMGetWidgetFunc get_widget;
EMGetWidgetFunc get_default_field;
EMGetStringFunc get_password_flags_name;
EMGetBooleanFunc get_phase2;
EMDestroyFunc destroy;
};
@ -60,6 +60,8 @@ GtkWidget *eap_method_get_default_field (EAPMethod *method);
const gchar *eap_method_get_password_flags_name (EAPMethod *method);
gboolean eap_method_get_phase2 (EAPMethod *method);
gboolean eap_method_validate (EAPMethod *method, GError **error);
void eap_method_add_to_size_group (EAPMethod *method, GtkSizeGroup *group);
@ -84,8 +86,8 @@ EAPMethod *eap_method_init (gsize obj_size,
EMGetWidgetFunc get_widget,
EMGetWidgetFunc get_default_field,
EMGetStringFunc get_password_flags_name,
EMDestroyFunc destroy,
gboolean phase2);
EMGetBooleanFunc get_phase2,
EMDestroyFunc destroy);
GtkFileFilter * eap_method_default_file_chooser_filter_new (gboolean privkey);