mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-05 10:20:14 +01:00
2007-09-11 Dan Williams <dcbw@redhat.com>
* libnm-util/nm-connection.c - (nm_connection_update_secrets, need_secrets_check): move 802-11-wireless-security need_secrets checks to the setting object itself, where it belongs * libnm-util/nm-setting.c libnm-util/nm-setting.h - (nm_setting_need_secrets): new function - (setting_wireless_security_verify, nm_setting_wireless_security_new_from_hash): make 'key-mgmt' required - (setting_wireless_security_need_secrets): mostly copy code over from nm-connection.c git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@2784 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:
parent
2e4cabc55e
commit
e705a7082e
4 changed files with 129 additions and 80 deletions
15
ChangeLog
15
ChangeLog
|
|
@ -1,3 +1,18 @@
|
|||
2007-09-11 Dan Williams <dcbw@redhat.com>
|
||||
|
||||
* libnm-util/nm-connection.c
|
||||
- (nm_connection_update_secrets, need_secrets_check): move
|
||||
802-11-wireless-security need_secrets checks to the setting object
|
||||
itself, where it belongs
|
||||
|
||||
* libnm-util/nm-setting.c
|
||||
libnm-util/nm-setting.h
|
||||
- (nm_setting_need_secrets): new function
|
||||
- (setting_wireless_security_verify,
|
||||
nm_setting_wireless_security_new_from_hash): make 'key-mgmt' required
|
||||
- (setting_wireless_security_need_secrets): mostly copy code over
|
||||
from nm-connection.c
|
||||
|
||||
2007-09-11 Dan Williams <dcbw@redhat.com>
|
||||
|
||||
* libnm-util/nm-setting.c
|
||||
|
|
|
|||
|
|
@ -119,58 +119,6 @@ nm_connection_compare (NMConnection *connection, NMConnection *other)
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
static GPtrArray *
|
||||
wireless_sec_need_secrets (NMSettingWirelessSecurity *sec)
|
||||
{
|
||||
GPtrArray * secrets;
|
||||
|
||||
secrets = g_ptr_array_sized_new (4);
|
||||
if (!secrets) {
|
||||
g_warning ("Not enough memory to create required secrets array.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Static WEP */
|
||||
if (strcmp (sec->key_mgmt, "none") == 0) {
|
||||
if (!sec->wep_key0) {
|
||||
g_ptr_array_add (secrets, "wep_key0");
|
||||
return secrets;
|
||||
}
|
||||
if (sec->wep_tx_keyidx == 1 && !sec->wep_key1) {
|
||||
g_ptr_array_add (secrets, "wep_key1");
|
||||
return secrets;
|
||||
}
|
||||
if (sec->wep_tx_keyidx == 2 && !sec->wep_key2) {
|
||||
g_ptr_array_add (secrets, "wep_key2");
|
||||
return secrets;
|
||||
}
|
||||
if (sec->wep_tx_keyidx == 3 && !sec->wep_key3) {
|
||||
g_ptr_array_add (secrets, "wep_key3");
|
||||
return secrets;
|
||||
}
|
||||
goto no_secrets;
|
||||
}
|
||||
|
||||
if ( (strcmp (sec->key_mgmt, "wpa-none") == 0)
|
||||
|| (strcmp (sec->key_mgmt, "wpa-psk") == 0)) {
|
||||
if (!sec->psk) {
|
||||
g_ptr_array_add (secrets, "psk");
|
||||
return secrets;
|
||||
}
|
||||
goto no_secrets;
|
||||
}
|
||||
|
||||
if (strcmp (sec->key_mgmt, "wpa-eap") == 0) {
|
||||
// FIXME: implement
|
||||
goto no_secrets;
|
||||
}
|
||||
|
||||
no_secrets:
|
||||
if (secrets)
|
||||
g_ptr_array_free (secrets, TRUE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
nm_connection_update_secrets (NMConnection *connection,
|
||||
const char *setting_name,
|
||||
|
|
@ -196,38 +144,44 @@ nm_connection_update_secrets (NMConnection *connection,
|
|||
g_signal_emit (connection, signals[SECRETS_UPDATED], 0, setting_name);
|
||||
}
|
||||
|
||||
typedef struct NeedSecretsInfo {
|
||||
GPtrArray * secrets;
|
||||
char * setting_name;
|
||||
} NeedSecretsInfo;
|
||||
|
||||
static void
|
||||
need_secrets_check (gpointer key, gpointer data, gpointer user_data)
|
||||
{
|
||||
NMSetting *setting = (NMSetting *) data;
|
||||
NeedSecretsInfo * info = (NeedSecretsInfo *) user_data;
|
||||
|
||||
// FIXME: allow more than one setting to say it needs secrets
|
||||
if (info->secrets)
|
||||
return;
|
||||
|
||||
info->secrets = nm_setting_need_secrets (setting);
|
||||
if (info->secrets)
|
||||
info->setting_name = key;
|
||||
}
|
||||
|
||||
const char *
|
||||
nm_connection_need_secrets (NMConnection *connection)
|
||||
{
|
||||
NMConnectionPrivate *priv;
|
||||
NMSettingConnection *s_connection;
|
||||
NeedSecretsInfo info = { NULL, NULL };
|
||||
|
||||
g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL);
|
||||
|
||||
s_connection = (NMSettingConnection *) nm_connection_get_setting (connection, "connection");
|
||||
if (!s_connection)
|
||||
return NULL;
|
||||
priv = NM_CONNECTION_GET_PRIVATE (connection);
|
||||
g_hash_table_foreach (priv->settings, need_secrets_check, &info);
|
||||
|
||||
/* Wireless */
|
||||
if (strcmp (s_connection->devtype, "802-11-wireless") == 0) {
|
||||
NMSettingWireless *s_wireless;
|
||||
NMSettingWirelessSecurity *s_wireless_sec;
|
||||
GPtrArray * secrets = NULL;
|
||||
|
||||
s_wireless = (NMSettingWireless *) nm_connection_get_setting (connection, "802-11-wireless");
|
||||
if (!s_wireless || !s_wireless->security)
|
||||
return NULL;
|
||||
|
||||
s_wireless_sec = (NMSettingWirelessSecurity *) nm_connection_get_setting (connection, "802-11-wireless-security");
|
||||
if (!s_wireless_sec)
|
||||
return NULL;
|
||||
|
||||
secrets = wireless_sec_need_secrets (s_wireless_sec);
|
||||
if (secrets) {
|
||||
// FIXME: modify NeedSecrets message to include the actual secrets
|
||||
// required rather than just requesting all secrets for the setting
|
||||
g_ptr_array_free (secrets, TRUE);
|
||||
return "802-11-wireless-security";
|
||||
}
|
||||
// FIXME: do something with requested secrets rather than asking for
|
||||
// all of them. Maybe make info.secrets a hash table mapping
|
||||
// settings name :: [list of secrets key names].
|
||||
if (info.secrets) {
|
||||
g_ptr_array_free (info.secrets, TRUE);
|
||||
return info.setting_name;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
|
|
|||
|
|
@ -64,6 +64,16 @@ nm_setting_update_secrets (NMSetting *setting,
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
GPtrArray *
|
||||
nm_setting_need_secrets (NMSetting *setting)
|
||||
{
|
||||
g_return_val_if_fail (setting != NULL, NULL);
|
||||
|
||||
if (setting->need_secrets_fn)
|
||||
return setting->need_secrets_fn (setting);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
nm_setting_destroy (NMSetting *setting)
|
||||
{
|
||||
|
|
@ -801,8 +811,8 @@ setting_wireless_security_verify (NMSetting *setting, GHashTable *all_settings)
|
|||
const char *valid_phase1_peapver[] = { "0", "1", NULL };
|
||||
const char *valid_phase2_autheap[] = { "md5", "mschapv2", "otp", "gtc", "tls", "sim", NULL };
|
||||
|
||||
if (self->key_mgmt && !string_in_list (self->key_mgmt, valid_key_mgmt)) {
|
||||
g_warning ("Invalid key management");
|
||||
if (!self->key_mgmt || !string_in_list (self->key_mgmt, valid_key_mgmt)) {
|
||||
g_warning ("Missing or invalid key management");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
|
@ -1080,6 +1090,63 @@ setting_wireless_security_update_secrets (NMSetting *setting,
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
static GPtrArray *
|
||||
setting_wireless_security_need_secrets (NMSetting *setting)
|
||||
{
|
||||
NMSettingWirelessSecurity *self = (NMSettingWirelessSecurity *) setting;
|
||||
GPtrArray *secrets;
|
||||
|
||||
secrets = g_ptr_array_sized_new (4);
|
||||
if (!secrets) {
|
||||
g_warning ("Not enough memory to create required secrets array.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
g_assert (self->key_mgmt);
|
||||
|
||||
/* Static WEP */
|
||||
if (strcmp (self->key_mgmt, "none") == 0) {
|
||||
if (!self->wep_key0) {
|
||||
g_ptr_array_add (secrets, "wep_key0");
|
||||
return secrets;
|
||||
}
|
||||
if (self->wep_tx_keyidx == 1 && !self->wep_key1) {
|
||||
g_ptr_array_add (secrets, "wep_key1");
|
||||
return secrets;
|
||||
}
|
||||
if (self->wep_tx_keyidx == 2 && !self->wep_key2) {
|
||||
g_ptr_array_add (secrets, "wep_key2");
|
||||
return secrets;
|
||||
}
|
||||
if (self->wep_tx_keyidx == 3 && !self->wep_key3) {
|
||||
g_ptr_array_add (secrets, "wep_key3");
|
||||
return secrets;
|
||||
}
|
||||
goto no_secrets;
|
||||
}
|
||||
|
||||
if ( (strcmp (self->key_mgmt, "wpa-none") == 0)
|
||||
|| (strcmp (self->key_mgmt, "wpa-psk") == 0)) {
|
||||
if (!self->psk) {
|
||||
g_ptr_array_add (secrets, "psk");
|
||||
return secrets;
|
||||
}
|
||||
goto no_secrets;
|
||||
}
|
||||
|
||||
if (strcmp (self->key_mgmt, "wpa-eap") == 0) {
|
||||
// FIXME: implement
|
||||
goto no_secrets;
|
||||
}
|
||||
|
||||
return secrets;
|
||||
|
||||
no_secrets:
|
||||
if (secrets)
|
||||
g_ptr_array_free (secrets, TRUE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
NMSetting *
|
||||
nm_setting_wireless_security_new (void)
|
||||
{
|
||||
|
|
@ -1090,8 +1157,9 @@ nm_setting_wireless_security_new (void)
|
|||
setting->name = g_strdup ("802-11-wireless-security");
|
||||
setting->verify_fn = setting_wireless_security_verify;
|
||||
setting->hash_fn = setting_wireless_security_hash;
|
||||
setting->destroy_fn = setting_wireless_security_destroy;
|
||||
setting->update_secrets_fn = setting_wireless_security_update_secrets;
|
||||
setting->need_secrets_fn = setting_wireless_security_need_secrets;
|
||||
setting->destroy_fn = setting_wireless_security_destroy;
|
||||
|
||||
return setting;
|
||||
}
|
||||
|
|
@ -1109,8 +1177,12 @@ nm_setting_wireless_security_new_from_hash (GHashTable *settings)
|
|||
self = (NMSettingWirelessSecurity *) setting;
|
||||
|
||||
value = (GValue *) g_hash_table_lookup (settings, "key-mgmt");
|
||||
if (value && G_VALUE_HOLDS_STRING (value))
|
||||
if (value && G_VALUE_HOLDS_STRING (value)) {
|
||||
self->key_mgmt = g_strdup (g_value_get_string (value));
|
||||
} else {
|
||||
g_warning ("Missing or invalid key-mgmt");
|
||||
goto err;
|
||||
}
|
||||
|
||||
value = (GValue *) g_hash_table_lookup (settings, "wep-tx-keyidx");
|
||||
if (value && G_VALUE_HOLDS_UCHAR (value))
|
||||
|
|
@ -1203,6 +1275,10 @@ nm_setting_wireless_security_new_from_hash (GHashTable *settings)
|
|||
setting_wireless_security_update_secrets (setting, settings);
|
||||
|
||||
return setting;
|
||||
|
||||
err:
|
||||
setting_wireless_security_destroy (setting);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* PPP */
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@ typedef GHashTable *(*NMSettingToHashFn) (NMSetting *setting);
|
|||
typedef gboolean (*NMSettingUpdateSecretsFn) (NMSetting *setting,
|
||||
GHashTable *secrets);
|
||||
|
||||
typedef GPtrArray *(*NMSettingNeedSecretsFn) (NMSetting *setting);
|
||||
|
||||
typedef void (*NMSettingDestroyFn) (NMSetting *setting);
|
||||
|
||||
struct _NMSetting {
|
||||
|
|
@ -26,12 +28,14 @@ struct _NMSetting {
|
|||
NMSettingVerifyFn verify_fn;
|
||||
NMSettingToHashFn hash_fn;
|
||||
NMSettingUpdateSecretsFn update_secrets_fn;
|
||||
NMSettingNeedSecretsFn need_secrets_fn;
|
||||
NMSettingDestroyFn destroy_fn;
|
||||
};
|
||||
|
||||
gboolean nm_settings_verify (GHashTable *all_settings);
|
||||
GHashTable *nm_setting_to_hash (NMSetting *setting);
|
||||
gboolean nm_setting_update_secrets (NMSetting *setting, GHashTable *secrets);
|
||||
GPtrArray * nm_setting_need_secrets (NMSetting *setting);
|
||||
void nm_setting_destroy (NMSetting *setting);
|
||||
|
||||
/* Default, built-in settings */
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue