mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-02-04 04:50:30 +01:00
2006-10-13 Dan Williams <dcbw@redhat.com>
* src/supplicant-manager/Makefile.am - Add new files * src/supplicant-manager/nm-supplicant-manager.[ch]: - Make it a minimal GObject * src/supplicant-manager/nm-supplicant-settings-verify.[ch]: - Verify settings destined for wpa_supplicant * src/supplicant-manager/nm-supplicant-connection.[ch]: - Minimal GObject to track wpa_supplicant controlled device connections git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@2060 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:
parent
4af9c4d9a1
commit
129d0ca46d
8 changed files with 626 additions and 2 deletions
15
ChangeLog
15
ChangeLog
|
|
@ -1,3 +1,18 @@
|
|||
2006-10-13 Dan Williams <dcbw@redhat.com>
|
||||
|
||||
* src/supplicant-manager/Makefile.am
|
||||
- Add new files
|
||||
|
||||
* src/supplicant-manager/nm-supplicant-manager.[ch]:
|
||||
- Make it a minimal GObject
|
||||
|
||||
* src/supplicant-manager/nm-supplicant-settings-verify.[ch]:
|
||||
- Verify settings destined for wpa_supplicant
|
||||
|
||||
* src/supplicant-manager/nm-supplicant-connection.[ch]:
|
||||
- Minimal GObject to track wpa_supplicant controlled device
|
||||
connections
|
||||
|
||||
2006-10-13 Wouter Bolsterlee <wbolster@gnome.org>
|
||||
|
||||
* gnome/applet/applet.c: (nma_update_info),
|
||||
|
|
|
|||
|
|
@ -2,7 +2,13 @@ INCLUDES = -I${top_srcdir}/utils -I${top_srcdir}/src -I${top_srcdir}/include
|
|||
|
||||
noinst_LTLIBRARIES = libsupplicant-manager.la
|
||||
|
||||
libsupplicant_manager_la_SOURCES = nm-supplicant-manager.h nm-supplicant-manager.c
|
||||
libsupplicant_manager_la_SOURCES = \
|
||||
nm-supplicant-manager.h \
|
||||
nm-supplicant-manager.c \
|
||||
nm-supplicant-connection.h \
|
||||
nm-supplicant-connection.c \
|
||||
nm-supplicant-settings-verify.h \
|
||||
nm-supplicant-settings-verify.c
|
||||
|
||||
libsupplicant_manager_la_CPPFLAGS = \
|
||||
$(DBUS_CFLAGS) \
|
||||
|
|
|
|||
191
src/supplicant-manager/nm-supplicant-connection.c
Normal file
191
src/supplicant-manager/nm-supplicant-connection.c
Normal file
|
|
@ -0,0 +1,191 @@
|
|||
/* NetworkManager -- Network link manager
|
||||
*
|
||||
* Dan Williams <dcbw@redhat.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* (C) Copyright 2006 Red Hat, Inc.
|
||||
*/
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include "nm-supplicant-connection.h"
|
||||
#include "nm-supplicant-settings-verify.h"
|
||||
#include "nm-utils.h"
|
||||
|
||||
#define NM_SUPPLICANT_CONNECTION_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), \
|
||||
NM_TYPE_SUPPLICANT_CONNECTION, \
|
||||
NMSupplicantConnectionPrivate))
|
||||
|
||||
|
||||
static void nm_supplicant_connection_set_device (NMSupplicantConnection *con,
|
||||
NMDevice *dev);
|
||||
|
||||
|
||||
struct _NMSupplicantConnectionPrivate
|
||||
{
|
||||
NMDevice *dev;
|
||||
GHashTable *config;
|
||||
gboolean dispose_has_run;
|
||||
};
|
||||
|
||||
NMSupplicantConnection *
|
||||
nm_supplicant_connection_new (NMDevice *dev)
|
||||
{
|
||||
NMSupplicantConnection * scfg;
|
||||
|
||||
g_return_val_if_fail (dev != NULL, NULL);
|
||||
|
||||
scfg = g_object_new (NM_TYPE_SUPPLICANT_CONNECTION, NULL);
|
||||
nm_supplicant_connection_set_device (scfg, dev);
|
||||
return scfg;
|
||||
}
|
||||
|
||||
static void
|
||||
nm_supplicant_connection_init (NMSupplicantConnection * self)
|
||||
{
|
||||
self->priv = NM_SUPPLICANT_CONNECTION_GET_PRIVATE (self);
|
||||
self->priv->config = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
|
||||
g_free);
|
||||
self->priv->dispose_has_run = FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
nm_supplicant_connection_set_device (NMSupplicantConnection *self,
|
||||
NMDevice *dev)
|
||||
{
|
||||
g_return_if_fail (self != NULL);
|
||||
g_return_if_fail (dev != NULL);
|
||||
|
||||
g_object_ref (G_OBJECT (dev));
|
||||
self->priv->dev = dev;
|
||||
}
|
||||
|
||||
gboolean
|
||||
nm_supplicant_connection_add_option (NMSupplicantConnection *self,
|
||||
const char * key,
|
||||
const char * value)
|
||||
{
|
||||
g_return_val_if_fail (self != NULL, FALSE);
|
||||
g_return_val_if_fail (key != NULL, FALSE);
|
||||
g_return_val_if_fail (value != NULL, FALSE);
|
||||
|
||||
if (!nm_supplicant_settings_verify_setting (key, value)) {
|
||||
nm_debug ("Key '%s' and/or value '%s' invalid.", key, value);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (g_hash_table_lookup (self->priv->config, key)) {
|
||||
nm_debug ("Key '%s' already in table.", key);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
g_hash_table_insert (self->priv->config, g_strdup (key), g_strdup (value));
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
nm_supplicant_connection_remove_option (NMSupplicantConnection *self,
|
||||
const char * key)
|
||||
{
|
||||
g_return_val_if_fail (self != NULL, FALSE);
|
||||
g_return_val_if_fail (key != NULL, FALSE);
|
||||
|
||||
return g_hash_table_remove (self->priv->config, key);
|
||||
}
|
||||
|
||||
static void
|
||||
nm_supplicant_connection_dispose (GObject *object)
|
||||
{
|
||||
NMSupplicantConnection * self = NM_SUPPLICANT_CONNECTION (object);
|
||||
NMSupplicantConnectionClass * klass;
|
||||
GObjectClass * parent_class;
|
||||
|
||||
if (self->priv->dispose_has_run)
|
||||
/* If dispose did already run, return. */
|
||||
return;
|
||||
|
||||
/* Make sure dispose does not run twice. */
|
||||
self->priv->dispose_has_run = TRUE;
|
||||
|
||||
/*
|
||||
* In dispose, you are supposed to free all types referenced from this
|
||||
* object which might themselves hold a reference to self. Generally,
|
||||
* the most simple solution is to unref all members on which you own a
|
||||
* reference.
|
||||
*/
|
||||
if (self->priv->dev) {
|
||||
g_object_unref (G_OBJECT (self->priv->dev));
|
||||
self->priv->dev = NULL;
|
||||
}
|
||||
|
||||
/* Chain up to the parent class */
|
||||
klass = NM_SUPPLICANT_CONNECTION_CLASS (g_type_class_peek (NM_TYPE_SUPPLICANT_CONNECTION));
|
||||
parent_class = G_OBJECT_CLASS (g_type_class_peek_parent (klass));
|
||||
parent_class->dispose (object);
|
||||
}
|
||||
|
||||
static void
|
||||
nm_supplicant_connection_finalize (GObject *object)
|
||||
{
|
||||
NMSupplicantConnection * self = NM_SUPPLICANT_CONNECTION (object);
|
||||
NMSupplicantConnectionClass * klass;
|
||||
GObjectClass * parent_class;
|
||||
|
||||
/* Complete object destruction */
|
||||
g_hash_table_destroy (self->priv->config);
|
||||
|
||||
/* Chain up to the parent class */
|
||||
klass = NM_SUPPLICANT_CONNECTION_CLASS (g_type_class_peek (NM_TYPE_SUPPLICANT_CONNECTION));
|
||||
parent_class = G_OBJECT_CLASS (g_type_class_peek_parent (klass));
|
||||
parent_class->finalize (object);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
nm_supplicant_connection_class_init (NMSupplicantConnectionClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
|
||||
object_class->dispose = nm_supplicant_connection_dispose;
|
||||
object_class->finalize = nm_supplicant_connection_finalize;
|
||||
|
||||
g_type_class_add_private (object_class, sizeof (NMSupplicantConnectionPrivate));
|
||||
}
|
||||
|
||||
GType
|
||||
nm_supplicant_connection_get_type (void)
|
||||
{
|
||||
static GType type = 0;
|
||||
if (type == 0) {
|
||||
static const GTypeInfo info = {
|
||||
sizeof (NMSupplicantConnectionClass),
|
||||
NULL, /* base_init */
|
||||
NULL, /* base_finalize */
|
||||
(GClassInitFunc) nm_supplicant_connection_class_init,
|
||||
NULL, /* class_finalize */
|
||||
NULL, /* class_data */
|
||||
sizeof (NMSupplicantConnection),
|
||||
0, /* n_preallocs */
|
||||
(GInstanceInitFunc) nm_supplicant_connection_init,
|
||||
NULL /* value_table */
|
||||
};
|
||||
|
||||
type = g_type_register_static (G_TYPE_OBJECT,
|
||||
"NMSupplicantConnection",
|
||||
&info, 0);
|
||||
}
|
||||
return type;
|
||||
}
|
||||
70
src/supplicant-manager/nm-supplicant-connection.h
Normal file
70
src/supplicant-manager/nm-supplicant-connection.h
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
/* NetworkManager -- Network link manager
|
||||
*
|
||||
* Dan Williams <dcbw@redhat.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* (C) Copyright 2006 Red Hat, Inc.
|
||||
*/
|
||||
|
||||
#ifndef NM_SUPPLICANT_CONNECTION_H
|
||||
#define NM_SUPPLICANT_CONNECTION_H
|
||||
|
||||
#include <glib-object.h>
|
||||
#include "nm-device.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define NM_TYPE_SUPPLICANT_CONNECTION (nm_supplicant_connection_get_type ())
|
||||
#define NM_SUPPLICANT_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_SUPPLICANT_CONNECTION, NMSupplicantConnection))
|
||||
#define NM_SUPPLICANT_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_SUPPLICANT_CONNECTION, NMSupplicantConnectionClass))
|
||||
#define NM_IS_SUPPLICANT_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_SUPPLICANT_CONNECTION))
|
||||
#define NM_IS_SUPPLICANT_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_SUPPLICANT_CONNECTION))
|
||||
#define NM_SUPPLICANT_CONNECTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_SUPPLICANT_CONNECTION, NMSupplicantConnectionClass))
|
||||
|
||||
typedef struct _NMSupplicantConnection NMSupplicantConnection;
|
||||
typedef struct _NMSupplicantConnectionClass NMSupplicantConnectionClass;
|
||||
typedef struct _NMSupplicantConnectionPrivate NMSupplicantConnectionPrivate;
|
||||
|
||||
struct _NMSupplicantConnection
|
||||
{
|
||||
GObject parent;
|
||||
|
||||
/*< private >*/
|
||||
NMSupplicantConnectionPrivate *priv;
|
||||
};
|
||||
|
||||
struct _NMSupplicantConnectionClass
|
||||
{
|
||||
GObjectClass parent;
|
||||
|
||||
/* class members */
|
||||
};
|
||||
|
||||
|
||||
GType nm_supplicant_connection_get_type (void);
|
||||
|
||||
NMSupplicantConnection * nm_supplicant_connection_new (NMDevice *dev);
|
||||
|
||||
gboolean nm_supplicant_connection_add_option (NMSupplicantConnection *scfg,
|
||||
const char * key,
|
||||
const char * value);
|
||||
|
||||
gboolean nm_supplicant_connection_remove_option (NMSupplicantConnection *self,
|
||||
const char * key);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* NM_SUPPLICANT_CONNECTION_H */
|
||||
|
|
@ -19,8 +19,71 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include <glib.h>
|
||||
#include <dbus/dbus.h>
|
||||
#include "nm-supplicant-manager.h"
|
||||
#include "nm-device.h"
|
||||
|
||||
#define NM_SUPPLICANT_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), \
|
||||
NM_TYPE_SUPPLICANT_MANAGER, \
|
||||
NMSupplicantManagerPrivate))
|
||||
|
||||
struct _NMSupplicantManagerPrivate {
|
||||
gboolean running;
|
||||
gboolean dispose_has_run;
|
||||
};
|
||||
|
||||
|
||||
NMSupplicantManager *
|
||||
nm_supplicant_manager_new (void)
|
||||
{
|
||||
NMSupplicantManager * mgr;
|
||||
|
||||
mgr = g_object_new (NM_TYPE_SUPPLICANT_MANAGER, NULL);
|
||||
return mgr;
|
||||
}
|
||||
|
||||
static void
|
||||
nm_supplicant_manager_init (NMSupplicantManager * self)
|
||||
{
|
||||
self->priv = NM_SUPPLICANT_MANAGER_GET_PRIVATE (self);
|
||||
self->priv->running = FALSE;
|
||||
self->priv->dispose_has_run = FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
nm_supplicant_manager_class_init (NMSupplicantManagerClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
|
||||
/*
|
||||
object_class->dispose = nm_supplicant_manager_dispose;
|
||||
object_class->finalize = nm_supplicant_manager_finalize;
|
||||
*/
|
||||
|
||||
g_type_class_add_private (object_class, sizeof (NMSupplicantManagerPrivate));
|
||||
}
|
||||
|
||||
GType
|
||||
nm_supplicant_manager_get_type (void)
|
||||
{
|
||||
static GType type = 0;
|
||||
if (type == 0) {
|
||||
static const GTypeInfo info = {
|
||||
sizeof (NMSupplicantManagerClass),
|
||||
NULL, /* base_init */
|
||||
NULL, /* base_finalize */
|
||||
(GClassInitFunc) nm_supplicant_manager_class_init,
|
||||
NULL, /* class_finalize */
|
||||
NULL, /* class_data */
|
||||
sizeof (NMSupplicantManager),
|
||||
0, /* n_preallocs */
|
||||
(GInstanceInitFunc) nm_supplicant_manager_init,
|
||||
NULL /* value_table */
|
||||
};
|
||||
|
||||
type = g_type_register_static (G_TYPE_OBJECT,
|
||||
"NMSupplicantManager",
|
||||
&info, 0);
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,42 @@
|
|||
#ifndef NM_SUPPLICANT_MANAGER_H
|
||||
#define NM_SUPPLICANT_MANAGER_H
|
||||
|
||||
#include <glib-object.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define NM_TYPE_SUPPLICANT_MANAGER (nm_supplicant_manager_get_type ())
|
||||
#define NM_SUPPLICANT_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_SUPPLICANT_MANAGER, NMSupplicantManager))
|
||||
#define NM_SUPPLICANT_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_SUPPLICANT_MANAGER, NMSupplicantManagerClass))
|
||||
#define NM_IS_SUPPLICANT_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_SUPPLICANT_MANAGER))
|
||||
#define NM_IS_SUPPLICANT_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_SUPPLICANT_MANAGER))
|
||||
#define NM_SUPPLICANT_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_SUPPLICANT_MANAGER, NMSupplicantManagerClass))
|
||||
|
||||
typedef struct _NMSupplicantManager NMSupplicantManager;
|
||||
typedef struct _NMSupplicantManagerClass NMSupplicantManagerClass;
|
||||
typedef struct _NMSupplicantManagerPrivate NMSupplicantManagerPrivate;
|
||||
|
||||
struct _NMSupplicantManager
|
||||
{
|
||||
GObject parent;
|
||||
|
||||
/*< private >*/
|
||||
NMSupplicantManagerPrivate *priv;
|
||||
};
|
||||
|
||||
struct NMAccessPoint;
|
||||
struct wpa_ctrl;
|
||||
|
||||
struct _NMSupplicantManagerClass
|
||||
{
|
||||
GObjectClass parent;
|
||||
|
||||
/* class members */
|
||||
};
|
||||
|
||||
GType nm_supplicant_manager_get_type (void);
|
||||
|
||||
NMSupplicantManager * nm_supplicant_manager_new (void);
|
||||
|
||||
|
||||
#endif /* NM_SUPPLICANT_MANAGER_H */
|
||||
|
|
|
|||
212
src/supplicant-manager/nm-supplicant-settings-verify.c
Normal file
212
src/supplicant-manager/nm-supplicant-settings-verify.c
Normal file
|
|
@ -0,0 +1,212 @@
|
|||
/* NetworkManager -- Network link manager
|
||||
*
|
||||
* Dan Williams <dcbw@redhat.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* (C) Copyright 2006 Red Hat, Inc.
|
||||
*/
|
||||
|
||||
#include <glib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "nm-supplicant-settings-verify.h"
|
||||
|
||||
enum OptType {
|
||||
TYPE_INT = 0,
|
||||
TYPE_STRING,
|
||||
TYPE_KEYWORD
|
||||
};
|
||||
|
||||
struct Opt {
|
||||
const char * key;
|
||||
const enum OptType type;
|
||||
const gint32 int_low; /* Inclusive */
|
||||
const gint32 int_high; /* Inclusive */
|
||||
const gboolean str_allowed_multiple;
|
||||
const char ** str_allowed;
|
||||
};
|
||||
|
||||
|
||||
static gboolean validate_type_int (const struct Opt * opt, const char * value);
|
||||
static gboolean validate_type_string (const struct Opt * opt, const char * value);
|
||||
static gboolean validate_type_keyword (const struct Opt * opt, const char * value);
|
||||
|
||||
typedef gboolean (*validate_func)(const struct Opt *, const char *);
|
||||
|
||||
struct validate_entry {
|
||||
const enum OptType type;
|
||||
const validate_func func;
|
||||
};
|
||||
|
||||
static const struct validate_entry validate_table[] = {
|
||||
{ TYPE_INT, validate_type_int },
|
||||
{ TYPE_STRING, validate_type_string },
|
||||
{ TYPE_KEYWORD, validate_type_keyword },
|
||||
};
|
||||
|
||||
|
||||
const char * pairwise_allowed[] = { "CCMP", "TKIP", "NONE", NULL };
|
||||
const char * group_allowed[] = { "CCMP", "TKIP", "WEP104", "WEP40", NULL };
|
||||
const char * proto_allowed[] = { "WPA", "RSN", NULL };
|
||||
const char * key_mgmt_allowed[] = { "WPA-PSK", "WPA-EAP", "IEEE8021X",
|
||||
"NONE", NULL };
|
||||
const char * auth_alg_allowed[] = { "OPEN", "SHARED", "LEAP", NULL };
|
||||
const char * eap_allowed[] = { "MD5", "TLS", "PEAP", "TTLS", "SIM",
|
||||
"PSK", NULL };
|
||||
const char * phase1_allowed[] = {"peapver=0", "peapver=1", "peaplabel=1",
|
||||
"peap_outer_success=0", "include_tls_length=1",
|
||||
"sim_min_num_chal=3", NULL };
|
||||
const char * phase2_allowed[] = {"auth=MSCHAPV2", "auth=PAP", "autheap=TLS",
|
||||
"autheap=MSCHAPV2", "autheap=MD5", NULL };
|
||||
|
||||
static const struct Opt opt_table[] = {
|
||||
{ "ssid", TYPE_STRING, 0, 0, FALSE, NULL },
|
||||
{ "bssid", TYPE_STRING, 0, 0, FALSE, NULL },
|
||||
{ "scan_ssid", TYPE_INT, 0, 1, FALSE, NULL },
|
||||
{ "mode", TYPE_INT, 0, 1, FALSE, NULL },
|
||||
{ "auth_alg", TYPE_KEYWORD, 0, 0, FALSE, auth_alg_allowed },
|
||||
{ "psk", TYPE_STRING, 0, 0, FALSE, NULL },
|
||||
{ "pairwise", TYPE_KEYWORD, 0, 0, FALSE, pairwise_allowed },
|
||||
{ "group", TYPE_KEYWORD, 0, 0, FALSE, group_allowed },
|
||||
{ "proto", TYPE_KEYWORD, 0, 0, FALSE, proto_allowed },
|
||||
{ "key_mgmt", TYPE_KEYWORD, 0, 0, FALSE, key_mgmt_allowed },
|
||||
{ "wep_key0", TYPE_STRING, 0, 0, FALSE, NULL },
|
||||
{ "wep_key1", TYPE_STRING, 0, 0, FALSE, NULL },
|
||||
{ "wep_key2", TYPE_STRING, 0, 0, FALSE, NULL },
|
||||
{ "wep_key3", TYPE_STRING, 0, 0, FALSE, NULL },
|
||||
{ "wep_tx_keyidx", TYPE_INT, 0, 3, FALSE, NULL },
|
||||
{ "eapol_flags", TYPE_INT, 0, 3, FALSE, NULL },
|
||||
{ "eap", TYPE_KEYWORD, 0, 0, FALSE, eap_allowed },
|
||||
{ "identity", TYPE_STRING, 0, 0, FALSE, NULL },
|
||||
{ "password", TYPE_STRING, 0, 0, FALSE, NULL },
|
||||
{ "ca_cert", TYPE_STRING, 0, 0, FALSE, NULL },
|
||||
{ "client_cert", TYPE_STRING, 0, 0, FALSE, NULL },
|
||||
{ "private_key", TYPE_STRING, 0, 0, FALSE, NULL },
|
||||
{ "private_key_passwd", TYPE_STRING, 0, 0, FALSE, NULL },
|
||||
{ "phase1", TYPE_KEYWORD, 0, 0, TRUE, phase1_allowed },
|
||||
{ "phase2", TYPE_KEYWORD, 0, 0, TRUE, phase2_allowed },
|
||||
{ "anonymous_identity", TYPE_STRING, 0, 0, FALSE, NULL },
|
||||
{ "ca_cert2", TYPE_STRING, 0, 0, FALSE, NULL },
|
||||
{ "client_cert2", TYPE_STRING, 0, 0, FALSE, NULL },
|
||||
{ "private_key2", TYPE_STRING, 0, 0, FALSE, NULL },
|
||||
{ "private_key2_passwd",TYPE_STRING, 0, 0, FALSE, NULL },
|
||||
{ "pin", TYPE_STRING, 0, 0, FALSE, NULL },
|
||||
{ "pcsc", TYPE_STRING, 0, 0, FALSE, NULL },
|
||||
{ "nai", TYPE_STRING, 0, 0, FALSE, NULL },
|
||||
{ "eappsk", TYPE_STRING, 0, 0, FALSE, NULL },
|
||||
{ "pac_file", TYPE_STRING, 0, 0, FALSE, NULL },
|
||||
{ "engine", TYPE_INT, 0, 1, FALSE, NULL },
|
||||
{ "engine_id", TYPE_STRING, 0, 0, FALSE, NULL },
|
||||
{ "key_id", TYPE_STRING, 0, 0, FALSE, NULL },
|
||||
};
|
||||
|
||||
|
||||
static gboolean
|
||||
validate_type_int (const struct Opt * opt, const char * value)
|
||||
{
|
||||
long int intval;
|
||||
|
||||
g_return_val_if_fail (opt != NULL, FALSE);
|
||||
g_return_val_if_fail (value != NULL, FALSE);
|
||||
|
||||
errno = 0;
|
||||
intval = strtol (value, NULL, 10);
|
||||
if (errno != 0)
|
||||
return FALSE;
|
||||
|
||||
/* strtol returns a long, but we are dealing with ints */
|
||||
if (intval > INT_MAX || intval < INT_MIN)
|
||||
return FALSE;
|
||||
if (intval > opt->int_high || intval < opt->int_low)
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
validate_type_string (const struct Opt * opt, const char * value)
|
||||
{
|
||||
g_return_val_if_fail (opt != NULL, FALSE);
|
||||
g_return_val_if_fail (value != NULL, FALSE);
|
||||
|
||||
/* FIXME: what can we do with a string other than length? */
|
||||
if (strlen (value) > PATH_MAX)
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
validate_type_keyword (const struct Opt * opt, const char * value)
|
||||
{
|
||||
char ** allowed;
|
||||
gchar ** candidates = NULL;
|
||||
char ** candidate;
|
||||
gboolean found = FALSE;
|
||||
|
||||
g_return_val_if_fail (opt != NULL, FALSE);
|
||||
g_return_val_if_fail (value != NULL, FALSE);
|
||||
|
||||
candidates = g_strsplit (value, " ", 0);
|
||||
if (!candidates)
|
||||
goto out;
|
||||
|
||||
/* validate each space-separated word in 'value' */
|
||||
for (candidate = candidates; *candidate; candidate++, found = FALSE) {
|
||||
for (allowed = (char **) opt->str_allowed; *allowed; allowed++) {
|
||||
if (strcmp (*candidate, *allowed) == 0) {
|
||||
found = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found)
|
||||
break;
|
||||
}
|
||||
|
||||
out:
|
||||
g_strfreev (candidates);
|
||||
return found;
|
||||
}
|
||||
|
||||
gboolean
|
||||
nm_supplicant_settings_verify_setting (const char * key,
|
||||
const char * value)
|
||||
{
|
||||
gboolean valid = FALSE;
|
||||
int opt_count = sizeof (opt_table) / sizeof (opt_table[0]);
|
||||
int val_count = sizeof (validate_table) / sizeof (validate_table[0]);
|
||||
int i, j;
|
||||
|
||||
g_return_val_if_fail (key != NULL, FALSE);
|
||||
g_return_val_if_fail (value != NULL, FALSE);
|
||||
|
||||
for (i = 0; i < opt_count && !valid; i++) {
|
||||
if (strcmp (opt_table[i].key, key) != 0)
|
||||
continue;
|
||||
|
||||
for (j = 0; j < val_count; j++) {
|
||||
if (validate_table[j].type == opt_table[i].type) {
|
||||
valid = (*(validate_table[j].func))(&opt_table[i], value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return valid;
|
||||
}
|
||||
31
src/supplicant-manager/nm-supplicant-settings-verify.h
Normal file
31
src/supplicant-manager/nm-supplicant-settings-verify.h
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
/* NetworkManager -- Network link manager
|
||||
*
|
||||
* Dan Williams <dcbw@redhat.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* (C) Copyright 2006 Red Hat, Inc.
|
||||
*/
|
||||
|
||||
#ifndef NM_SUPPLICANT_SETTINGS_VERIFY_H
|
||||
#define NM_SUPPLICANT_SETTINGS_VERIFY_H
|
||||
|
||||
gboolean nm_supplicant_settings_verify_setting (const char * key,
|
||||
const char * value);
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /* NM_SUPPLICANT_SETTINGS_VERIFY_H */
|
||||
Loading…
Add table
Reference in a new issue