Commit 05e9de94 authored by Dan Williams's avatar Dan Williams

2008-06-12 Dan Williams <dcbw@redhat.com>

	Add a GError argument to nm_connection_verify() and nm_setting_verify(),
	and add error enums to each NMSetting subclass.  Each NMSetting subclass now
	returns a descriptive GError when verification fails.



git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@3751 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
parent 99ef1936
2008-06-12 Dan Williams <dcbw@redhat.com>
Add a GError argument to nm_connection_verify() and nm_setting_verify(),
and add error enums to each NMSetting subclass. Each NMSetting subclass now
returns a descriptive GError when verification fails.
2008-06-11 Dan Williams <dcbw@redhat.com>
Patch from Tambet Ingo <tambet@gmail.com>
......
......@@ -311,10 +311,15 @@ nm_dispatcher_action (Handler *h,
if (!d->persist)
d->quit_timeout = g_timeout_add (10000, quit_timeout_cb, NULL);
connection = nm_connection_new_from_hash (connection_hash);
connection = nm_connection_new_from_hash (connection_hash, error);
if (connection) {
if (!nm_connection_verify (connection))
g_warning ("Connection was invalid!");
g_warning ("%s: Invalid connection: '%s' / '%s' invalid: %d",
__func__,
g_type_name (nm_connection_lookup_setting_type_by_quark ((*error)->domain)),
(*error)->message, (*error)->code);
/* Don't fail on this error yet */
g_error_free (*error);
*error = NULL;
}
value = g_hash_table_lookup (device_props, NMD_DEVICE_PROPS_INTERFACE);
......
......@@ -121,7 +121,7 @@ constructor (GType type,
NMConnection *wrapped;
const char *service;
GHashTable *settings = NULL;
GError *err = NULL;
GError *error = NULL;
object = G_OBJECT_CLASS (nm_dbus_connection_parent_class)->constructor (type, n_construct_params, construct_params);
......@@ -146,17 +146,21 @@ constructor (GType type,
priv->path,
NM_DBUS_IFACE_SETTINGS_CONNECTION);
if (!org_freedesktop_NetworkManagerSettings_Connection_get_settings (priv->proxy, &settings, &err)) {
nm_warning ("Can not retrieve settings: %s", err->message);
g_error_free (err);
if (!org_freedesktop_NetworkManagerSettings_Connection_get_settings (priv->proxy, &settings, &error)) {
nm_warning ("Can not retrieve settings: %s", error->message);
g_error_free (error);
goto err;
}
wrapped = nm_connection_new_from_hash (settings);
wrapped = nm_connection_new_from_hash (settings, &error);
g_hash_table_destroy (settings);
if (!wrapped) {
nm_warning ("Invalid settings");
nm_warning ("Invalid connection: '%s' / '%s' invalid: %d",
g_type_name (nm_connection_lookup_setting_type_by_quark (error->domain)),
error->message,
error->code);
g_error_free (error);
goto err;
}
......
......@@ -321,14 +321,22 @@ nm_vpn_plugin_set_ip4_config (NMVPNPlugin *plugin,
static gboolean
impl_vpn_plugin_connect (NMVPNPlugin *plugin,
GHashTable *properties,
GError **err)
GError **error)
{
NMConnection *connection;
gboolean success;
gboolean success = FALSE;
connection = nm_connection_new_from_hash (properties);
success = nm_vpn_plugin_connect (plugin, connection, err);
g_object_unref (connection);
connection = nm_connection_new_from_hash (properties, error);
if (!connection) {
nm_warning ("%s: Invalid connection: '%s' / '%s' invalid: %d",
__func__,
g_type_name (nm_connection_lookup_setting_type_by_quark ((*error)->domain)),
(*error)->message,
(*error)->code);
} else {
success = nm_vpn_plugin_connect (plugin, connection, error);
g_object_unref (connection);
}
return success;
}
......@@ -344,17 +352,20 @@ impl_vpn_plugin_need_secrets (NMVPNPlugin *plugin,
char *sn = NULL;
GError *ns_err = NULL;
gboolean needed = FALSE;
GError *cnfh_err = NULL;
g_return_val_if_fail (NM_IS_VPN_PLUGIN (plugin), FALSE);
g_return_val_if_fail (properties != NULL, FALSE);
connection = nm_connection_new_from_hash (properties);
connection = nm_connection_new_from_hash (properties, &cnfh_err);
if (!connection) {
g_set_error (err,
NM_VPN_PLUGIN_ERROR,
NM_VPN_PLUGIN_ERROR_CONNECTION_INVALID,
"%s",
"The connection information was invalid.");
"The connection was invalid: '%s' / '%s' invalid: %d.",
g_type_name (nm_connection_lookup_setting_type_by_quark (cnfh_err->domain)),
cnfh_err->message, cnfh_err->code);
g_error_free (cnfh_err);
return FALSE;
}
......
......@@ -59,44 +59,98 @@ static struct SettingInfo {
const char *name;
GType type;
guint32 priority;
GQuark error_quark;
} default_map[DEFAULT_MAP_SIZE] = { { NULL } };
static void
register_one_setting (int i, const char *name, GType type, guint32 priority)
register_one_setting (const char *name, GType type, GQuark error_quark, guint32 priority)
{
g_return_if_fail (i >= 0);
static guint32 i = 0;
g_return_if_fail (i < DEFAULT_MAP_SIZE);
g_return_if_fail (default_map[i].name == NULL);
default_map[i].name = name;
default_map[i].type = type;
default_map[i].error_quark = error_quark;
default_map[i].priority = priority;
i++;
nm_setting_register (name, type);
}
static void
register_default_settings (void)
{
int i = 0;
nm_utils_register_value_transformations ();
if (G_LIKELY (default_map[0].name))
return;
register_one_setting (i++, NM_SETTING_CONNECTION_SETTING_NAME, NM_TYPE_SETTING_CONNECTION, 0);
register_one_setting (i++, NM_SETTING_WIRED_SETTING_NAME, NM_TYPE_SETTING_WIRED, 1);
register_one_setting (i++, NM_SETTING_WIRELESS_SETTING_NAME, NM_TYPE_SETTING_WIRELESS, 1);
register_one_setting (i++, NM_SETTING_GSM_SETTING_NAME, NM_TYPE_SETTING_GSM, 1);
register_one_setting (i++, NM_SETTING_CDMA_SETTING_NAME, NM_TYPE_SETTING_CDMA, 1);
register_one_setting (i++, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, NM_TYPE_SETTING_WIRELESS_SECURITY, 2);
register_one_setting (i++, NM_SETTING_SERIAL_SETTING_NAME, NM_TYPE_SETTING_SERIAL, 2);
register_one_setting (i++, NM_SETTING_PPP_SETTING_NAME, NM_TYPE_SETTING_PPP, 3);
register_one_setting (i++, NM_SETTING_PPPOE_SETTING_NAME, NM_TYPE_SETTING_PPPOE, 3);
register_one_setting (i++, NM_SETTING_802_1X_SETTING_NAME, NM_TYPE_SETTING_802_1X, 3);
register_one_setting (i++, NM_SETTING_VPN_SETTING_NAME, NM_TYPE_SETTING_VPN, 4);
register_one_setting (i++, NM_SETTING_VPN_PROPERTIES_SETTING_NAME, NM_TYPE_SETTING_VPN_PROPERTIES, 5);
register_one_setting (i++, NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_TYPE_SETTING_IP4_CONFIG, 6);
register_one_setting (NM_SETTING_CONNECTION_SETTING_NAME,
NM_TYPE_SETTING_CONNECTION,
NM_SETTING_CONNECTION_ERROR,
0);
register_one_setting (NM_SETTING_WIRED_SETTING_NAME,
NM_TYPE_SETTING_WIRED,
NM_SETTING_WIRED_ERROR,
1);
register_one_setting (NM_SETTING_WIRELESS_SETTING_NAME,
NM_TYPE_SETTING_WIRELESS,
NM_SETTING_WIRELESS_ERROR,
1);
register_one_setting (NM_SETTING_GSM_SETTING_NAME,
NM_TYPE_SETTING_GSM,
NM_SETTING_GSM_ERROR,
1);
register_one_setting (NM_SETTING_CDMA_SETTING_NAME,
NM_TYPE_SETTING_CDMA,
NM_SETTING_CDMA_ERROR,
1);
register_one_setting (NM_SETTING_WIRELESS_SECURITY_SETTING_NAME,
NM_TYPE_SETTING_WIRELESS_SECURITY,
NM_SETTING_WIRELESS_SECURITY_ERROR,
2);
register_one_setting (NM_SETTING_SERIAL_SETTING_NAME,
NM_TYPE_SETTING_SERIAL,
NM_SETTING_SERIAL_ERROR,
2);
register_one_setting (NM_SETTING_PPP_SETTING_NAME,
NM_TYPE_SETTING_PPP,
NM_SETTING_PPP_ERROR,
3);
register_one_setting (NM_SETTING_PPPOE_SETTING_NAME,
NM_TYPE_SETTING_PPPOE,
NM_SETTING_PPPOE_ERROR,
3);
register_one_setting (NM_SETTING_802_1X_SETTING_NAME,
NM_TYPE_SETTING_802_1X,
NM_SETTING_802_1X_ERROR,
3);
register_one_setting (NM_SETTING_VPN_SETTING_NAME,
NM_TYPE_SETTING_VPN,
NM_SETTING_VPN_ERROR,
4);
register_one_setting (NM_SETTING_VPN_PROPERTIES_SETTING_NAME,
NM_TYPE_SETTING_VPN_PROPERTIES,
NM_SETTING_VPN_PROPERTIES_ERROR,
5);
register_one_setting (NM_SETTING_IP4_CONFIG_SETTING_NAME,
NM_TYPE_SETTING_IP4_CONFIG,
NM_SETTING_IP4_CONFIG_ERROR,
6);
}
static guint32
......@@ -118,10 +172,11 @@ nm_setting_register (const char *name, GType type)
g_return_if_fail (name != NULL);
g_return_if_fail (G_TYPE_IS_INSTANTIATABLE (type));
if (!registered_settings)
if (G_UNLIKELY (!registered_settings)) {
registered_settings = g_hash_table_new_full (g_str_hash, g_str_equal,
(GDestroyNotify) g_free,
(GDestroyNotify) g_free);
(GDestroyNotify) g_free,
(GDestroyNotify) g_free);
}
if (g_hash_table_lookup (registered_settings, name))
g_warning ("Already have a creator function for '%s', overriding", name);
......@@ -155,6 +210,19 @@ nm_connection_lookup_setting_type (const char *name)
return type;
}
GType
nm_connection_lookup_setting_type_by_quark (GQuark error_quark)
{
int i;
for (i = 0; default_map[i].name; i++) {
if (default_map[i].error_quark == error_quark)
return default_map[i].type;
}
return G_TYPE_INVALID;
}
NMSetting *
nm_connection_create_setting (const char *name)
{
......@@ -230,14 +298,21 @@ gboolean
nm_connection_replace_settings (NMConnection *connection,
GHashTable *new_settings)
{
GError *error = NULL;
g_return_val_if_fail (NM_IS_CONNECTION (connection), FALSE);
g_return_val_if_fail (new_settings != NULL, FALSE);
g_hash_table_remove_all (NM_CONNECTION_GET_PRIVATE (connection)->settings);
g_hash_table_foreach (new_settings, parse_one_setting, connection);
if (!nm_connection_verify (connection)) {
g_warning ("Settings invalid.");
if (!nm_connection_verify (connection, &error)) {
g_warning ("%s: '%s' / '%s' invalid: %d",
__func__,
g_type_name (nm_connection_lookup_setting_type_by_quark (error->domain)),
error->message,
error->code);
g_error_free (error);
return FALSE;
}
......@@ -299,6 +374,7 @@ nm_connection_compare (NMConnection *connection,
typedef struct {
gboolean success;
GSList *all_settings;
GError **error;
} VerifySettingsInfo;
static void
......@@ -308,7 +384,7 @@ verify_one_setting (gpointer data, gpointer user_data)
VerifySettingsInfo *info = (VerifySettingsInfo *) user_data;
if (info->success)
info->success = nm_setting_verify (setting, info->all_settings);
info->success = nm_setting_verify (setting, info->all_settings, info->error);
}
static void
......@@ -320,13 +396,15 @@ hash_values_to_slist (gpointer key, gpointer value, gpointer user_data)
}
gboolean
nm_connection_verify (NMConnection *connection)
nm_connection_verify (NMConnection *connection, GError **error)
{
NMConnectionPrivate *priv;
NMSetting *connection_setting;
VerifySettingsInfo info;
g_return_val_if_fail (NM_IS_CONNECTION (connection), FALSE);
if (error)
g_return_val_if_fail (*error == NULL, FALSE);
priv = NM_CONNECTION_GET_PRIVATE (connection);
......@@ -338,13 +416,13 @@ nm_connection_verify (NMConnection *connection)
}
/* Now, run the verify function of each setting */
memset (&info, 0, sizeof (info));
info.success = TRUE;
info.all_settings = NULL;
info.error = error;
g_hash_table_foreach (priv->settings, hash_values_to_slist, &info.all_settings);
g_slist_foreach (info.all_settings, verify_one_setting, &info);
g_slist_free (info.all_settings);
return info.success;
}
......@@ -601,7 +679,7 @@ nm_connection_new (void)
}
NMConnection *
nm_connection_new_from_hash (GHashTable *hash)
nm_connection_new_from_hash (GHashTable *hash, GError **error)
{
NMConnection *connection;
NMConnectionPrivate *priv;
......@@ -613,7 +691,7 @@ nm_connection_new_from_hash (GHashTable *hash)
priv = NM_CONNECTION_GET_PRIVATE (connection);
if (!nm_connection_verify (connection)) {
if (!nm_connection_verify (connection, error)) {
g_object_unref (connection);
return NULL;
}
......
......@@ -39,7 +39,9 @@ typedef struct {
GType nm_connection_get_type (void);
NMConnection *nm_connection_new (void);
NMConnection *nm_connection_new_from_hash (GHashTable *hash);
NMConnection *nm_connection_new_from_hash (GHashTable *hash, GError **error);
void nm_connection_add_setting (NMConnection *connection,
NMSetting *setting);
......@@ -60,7 +62,7 @@ gboolean nm_connection_compare (NMConnection *connection,
NMConnection *other,
NMSettingCompareFlags flags);
gboolean nm_connection_verify (NMConnection *connection);
gboolean nm_connection_verify (NMConnection *connection, GError **error);
const char * nm_connection_need_secrets (NMConnection *connection,
GPtrArray **hints);
......@@ -97,6 +99,8 @@ void nm_setting_unregister (const char *name);
GType nm_connection_lookup_setting_type (const char *name);
GType nm_connection_lookup_setting_type_by_quark (GQuark error_quark);
G_END_DECLS
#endif /* NM_CONNECTION_H */
......@@ -9,6 +9,40 @@
#include "nm-dbus-glib-types.h"
#include "crypto.h"
GQuark
nm_setting_802_1x_error_quark (void)
{
static GQuark quark;
if (G_UNLIKELY (!quark))
quark = g_quark_from_static_string ("nm-setting-802-1x-error-quark");
return quark;
}
/* This should really be standard. */
#define ENUM_ENTRY(NAME, DESC) { NAME, "" #NAME "", DESC }
GType
nm_setting_802_1x_error_get_type (void)
{
static GType etype = 0;
if (etype == 0) {
static const GEnumValue values[] = {
/* Unknown error. */
ENUM_ENTRY (NM_SETTING_802_1X_ERROR_UNKNOWN, "UnknownError"),
/* The specified property was invalid. */
ENUM_ENTRY (NM_SETTING_802_1X_ERROR_INVALID_PROPERTY, "InvalidProperty"),
/* The specified property was missing and is required. */
ENUM_ENTRY (NM_SETTING_802_1X_ERROR_MISSING_PROPERTY, "MissingProperty"),
{ 0, 0, 0 }
};
etype = g_enum_register_static ("NMSetting8021xError", values);
}
return etype;
}
G_DEFINE_TYPE (NMSetting8021x, nm_setting_802_1x, NM_TYPE_SETTING)
enum {
......@@ -188,16 +222,34 @@ need_secrets_tls (NMSetting8021x *self,
}
static gboolean
verify_tls (NMSetting8021x *self, gboolean phase2)
verify_tls (NMSetting8021x *self, gboolean phase2, GError **error)
{
if (phase2) {
if (!self->phase2_client_cert || !self->phase2_client_cert->len) {
g_warning ("%s: phase2 client certificate invalid", __func__);
if (!self->phase2_client_cert) {
g_set_error (error,
NM_SETTING_802_1X_ERROR,
NM_SETTING_802_1X_ERROR_MISSING_PROPERTY,
NM_SETTING_802_1X_PHASE2_CLIENT_CERT);
return FALSE;
} else if (!self->phase2_client_cert->len) {
g_set_error (error,
NM_SETTING_802_1X_ERROR,
NM_SETTING_802_1X_ERROR_INVALID_PROPERTY,
NM_SETTING_802_1X_PHASE2_CLIENT_CERT);
return FALSE;
}
} else {
if (!self->client_cert || !self->client_cert->len) {
g_warning ("%s: client certificate invalid", __func__);
if (!self->client_cert) {
g_set_error (error,
NM_SETTING_802_1X_ERROR,
NM_SETTING_802_1X_ERROR_MISSING_PROPERTY,
NM_SETTING_802_1X_CLIENT_CERT);
return FALSE;
} else if (!self->client_cert->len) {
g_set_error (error,
NM_SETTING_802_1X_ERROR,
NM_SETTING_802_1X_ERROR_INVALID_PROPERTY,
NM_SETTING_802_1X_CLIENT_CERT);
return FALSE;
}
}
......@@ -206,15 +258,57 @@ verify_tls (NMSetting8021x *self, gboolean phase2)
}
static gboolean
verify_ttls (NMSetting8021x *self, gboolean phase2)
verify_ttls (NMSetting8021x *self, gboolean phase2, GError **error)
{
if (!self->identity && !self->anonymous_identity) {
g_warning ("%s: missing identity or anonymous identity", __func__);
if ( (!self->identity || !strlen (self->identity))
&& (!self->anonymous_identity || !strlen (self->anonymous_identity))) {
if (!self->identity) {
g_set_error (error,
NM_SETTING_802_1X_ERROR,
NM_SETTING_802_1X_ERROR_MISSING_PROPERTY,
NM_SETTING_802_1X_IDENTITY);
} else if (!strlen (self->identity)) {
g_set_error (error,
NM_SETTING_802_1X_ERROR,
NM_SETTING_802_1X_ERROR_INVALID_PROPERTY,
NM_SETTING_802_1X_IDENTITY);
} else if (!self->anonymous_identity) {
g_set_error (error,
NM_SETTING_802_1X_ERROR,
NM_SETTING_802_1X_ERROR_MISSING_PROPERTY,
NM_SETTING_802_1X_ANONYMOUS_IDENTITY);
} else {
g_set_error (error,
NM_SETTING_802_1X_ERROR,
NM_SETTING_802_1X_ERROR_INVALID_PROPERTY,
NM_SETTING_802_1X_ANONYMOUS_IDENTITY);
}
return FALSE;
}
if (!self->phase2_auth && !self->phase2_autheap) {
g_warning ("%s: missing phase2 auth method", __func__);
if ( (!self->phase2_auth || !strlen (self->phase2_auth))
&& (!self->phase2_autheap || !strlen (self->phase2_autheap))) {
if (!self->phase2_auth) {
g_set_error (error,
NM_SETTING_802_1X_ERROR,
NM_SETTING_802_1X_ERROR_MISSING_PROPERTY,
NM_SETTING_802_1X_PHASE2_AUTH);
} else if (!strlen (self->phase2_auth)) {
g_set_error (error,
NM_SETTING_802_1X_ERROR,
NM_SETTING_802_1X_ERROR_INVALID_PROPERTY,
NM_SETTING_802_1X_PHASE2_AUTH);
} else if (!self->phase2_autheap) {
g_set_error (error,
NM_SETTING_802_1X_ERROR,
NM_SETTING_802_1X_ERROR_MISSING_PROPERTY,
NM_SETTING_802_1X_PHASE2_AUTHEAP);
} else {
g_set_error (error,
NM_SETTING_802_1X_ERROR,
NM_SETTING_802_1X_ERROR_INVALID_PROPERTY,
NM_SETTING_802_1X_PHASE2_AUTHEAP);
}
return FALSE;
}
......@@ -222,9 +316,21 @@ verify_ttls (NMSetting8021x *self, gboolean phase2)
}
static gboolean
verify_identity (NMSetting8021x *self, gboolean phase2)
verify_identity (NMSetting8021x *self, gboolean phase2, GError **error)
{
return self->identity ? TRUE : FALSE;
if (!self->identity) {
g_set_error (error,
NM_SETTING_802_1X_ERROR,
NM_SETTING_802_1X_ERROR_MISSING_PROPERTY,
NM_SETTING_802_1X_IDENTITY);
} else if (!strlen (self->identity)) {
g_set_error (error,
NM_SETTING_802_1X_ERROR,
NM_SETTING_802_1X_ERROR_INVALID_PROPERTY,
NM_SETTING_802_1X_IDENTITY);
}
return TRUE;
}
/* Implemented below... */
......@@ -238,7 +344,8 @@ typedef void (*EAPMethodNeedSecretsFunc) (NMSetting8021x *self,
gboolean phase2);
typedef gboolean (*EAPMethodValidateFunc)(NMSetting8021x *self,
gboolean phase2);
gboolean phase2,
GError **error);
typedef struct {
const char *method;
......@@ -336,7 +443,7 @@ need_secrets (NMSetting *setting)
}
static gboolean
verify (NMSetting *setting, GSList *all_settings)
verify (NMSetting *setting, GSList *all_settings, GError **error)
{
NMSetting8021x *self = NM_SETTING_802_1X (setting);
const char *valid_eap[] = { "leap", "md5", "tls", "peap", "ttls", "sim", "fast", NULL };
......@@ -345,13 +452,22 @@ verify (NMSetting *setting, GSList *all_settings)
const char *valid_phase2_autheap[] = { "md5", "mschapv2", "otp", "gtc", "tls", NULL };
GSList *iter;
if (error)
g_return_val_if_fail (*error == NULL, FALSE);
if (!self->eap) {
g_warning ("Missing eap method");
g_set_error (error,
NM_SETTING_802_1X_ERROR,
NM_SETTING_802_1X_ERROR_MISSING_PROPERTY,
NM_SETTING_802_1X_EAP);
return FALSE;
}
if (!nm_utils_string_slist_validate (self->eap, valid_eap)) {
g_warning ("Invalid eap");
g_set_error (error,
NM_SETTING_802_1X_ERROR,
NM_SETTING_802_1X_ERROR_INVALID_PROPERTY,
NM_SETTING_802_1X_EAP);
return FALSE;
}
......@@ -364,7 +480,7 @@ verify (NMSetting *setting, GSList *all_settings)
if (eap_methods_table[i].v_func == NULL)
continue;
if (!strcmp (eap_methods_table[i].method, method)) {
if (!(*eap_methods_table[i].v_func) (self, FALSE))
if (!(*eap_methods_table[i].v_func) (self, FALSE, error))
return FALSE;
break;
}
......@@ -372,27 +488,42 @@ verify (NMSetting *setting, GSList *all_settings)
}
if (self->phase1_peapver && !nm_utils_string_in_list (self->phase1_peapver, valid_phase1_peapver)) {
g_warning ("Invalid phase1 peapver");
g_set_error (error,
NM_SETTING_802_1X_ERROR,
NM_SETTING_802_1X_ERROR_INVALID_PROPERTY,
NM_SETTING_802_1X_PHASE1_PEAPVER);
return FALSE;
}
if (self->phase1_peaplabel && strcmp (self->phase1_peaplabel, "1")) {
g_warning ("Invalid phase1 peaplabel");
g_set_error (error,
NM_SETTING_802_1X_ERROR,
NM_SETTING_802_1X_ERROR_INVALID_PROPERTY,
NM_SETTING_802_1X_PHASE1_PEAPLABEL);
return FALSE;
}
if (self->phase1_fast_provisioning && strcmp (self->phase1_fast_provisioning, "1")) {
g_warning ("Invalid phase1 fast provisioning");
g_set_error (error,
NM_SETTING_802_1X_ERROR,
NM_SETTING_802_1X_ERROR_INVALID_PROPERTY,
NM_SETTING_802_1X_PHASE1_FAST_PROVISIONING);
return FALSE;
}
if (self->phase2_auth && !nm_utils_string_in_list (self->phase2_auth, valid_phase2_auth)) {
g_warning ("Invalid phase2 authentication");
g_set_error (error,
NM_SETTING_802_1X_ERROR,
NM_SETTING_802_1X_ERROR_INVALID_PROPERTY,
NM_SETTING_802_1X_PHASE2_AUTH);
return FALSE;
}
if (self->phase2_autheap && !nm_utils_string_in_list (self->phase2_autheap, valid_phase2_autheap)) {
g_warning ("Invalid phase2 autheap");
g_set_error (error,
NM_SETTING_802_1X_ERROR,
NM_SETTING_802_1X_ERROR_INVALID_PROPERTY,
NM_SETTING_802_1X_PHASE2_AUTHEAP);
return FALSE;
}
......
......@@ -16,6 +16,20 @@ G_BEGIN_DECLS
#define NM_SETTING_802_1X_SETTING_NAME "802-1x"
typedef enum
{
NM_SETTING_802_1X_ERROR_UNKNOWN = 0,
NM_SETTING_802_1X_ERROR_INVALID_PROPERTY,
NM_SETTING_802_1X_ERROR_MISSING_PROPERTY
} NMSetting8021xError;
#define NM_TYPE_SETTING_802_1X_ERROR (nm_setting_802_1x_error_get_type ())
GType nm_setting_802_1x_error_get_type (void);
#define NM_SETTING_802_1X_ERROR nm_setting_802_1x_error_quark ()
GQuark nm_setting_802_1x_error_quark (void);
#define NM_SETTING_802_1X_EAP "eap"
#define NM_SETTING_802_1X_IDENTITY "identity"
#define NM_SETTING_802_1X_ANONYMOUS_IDENTITY "anonymous-identity"
......
......@@ -5,6 +5,42 @@
#include "nm-setting-serial.h"
#include "nm-utils.h"
GQuark
nm_setting_cdma_error_quark (void)
{
static GQuark quark;
if (G_UNLIKELY (!quark))
quark = g_quark_from_static_string ("nm-setting-cdma-error-quark");
return quark;
}
/* This should really be standard. */
#define ENUM_ENTRY(NAME, DESC) { NAME, "" #NAME "", DESC }
GType
nm_setting_cdma_error_get_type (void)
{
static GType etype = 0;
if (etype == 0) {
static const GEnumValue values[] = {
/* Unknown error. */
ENUM_ENTRY (NM_SETTING_CDMA_ERROR_UNKNOWN, "UnknownError"),
/* The specified property was invalid. */
ENUM_ENTRY (NM_SETTING_CDMA_ERROR_INVALID_PROPERTY, "InvalidProperty"),
/* The specified property was missing and is required. */
ENUM_ENTRY (NM_SETTING_CDMA_ERROR_MISSING_PROPERTY, "MissingProperty"),
/* The required serial setting is missing */
ENUM_ENTRY (NM_SETTING_CDMA_ERROR_MISSING_SERIAL_SETTING, "MissingSerialSetting"),
{ 0, 0, 0 }
};
etype = g_enum_register_static ("NMSettingCdmaError", values);
}
return etype;
}
G_DEFINE_TYPE (NMSettingCdma, nm_setting_cdma, NM_TYPE_SETTING)
enum {
......@@ -32,19 +68,31 @@ find_setting_by_name (gconstpointer a, gconstpointer b)
}
static gboolean
verify (NMSetting *setting, GSList *all_settings)
verify (NMSetting *setting, GSList *all_settings, GError **error)
{