2008-10-29 Tambet Ingo <tambet@gmail.com>

Half of it by Dan Williams <dcbw@redhat.com>

	* libnm-util/libnm-util.ver
	libnm-util/nm-setting-vpn.c
	libnm-util/nm-setting-vpn.h
		- Make properties private and add accessor functions.

	* src/vpn-manager/nm-vpn-connection.c
	src/vpn-manager/nm-vpn-manager.c
	system-settings/plugins/keyfile/reader.c
	vpn-daemons/openvpn/properties/auth-helpers.c
	vpn-daemons/openvpn/properties/import-export.c
	vpn-daemons/openvpn/properties/nm-openvpn.c
	vpn-daemons/openvpn/src/nm-openvpn-service.c
	vpn-daemons/pptp/auth-dialog/main.c
	vpn-daemons/pptp/properties/advanced-dialog.c
	vpn-daemons/pptp/properties/nm-pptp.c
	vpn-daemons/pptp/src/nm-pptp-service.c
	vpn-daemons/vpnc/properties/nm-vpnc.c
	vpn-daemons/vpnc/src/nm-vpnc-service.c
		- Use VPN setting accessors.

git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@4232 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:
Tambet Ingo 2008-10-29 09:13:40 +00:00
parent 69713a8b93
commit 8f6eb995f9
17 changed files with 640 additions and 459 deletions

View file

@ -1,3 +1,27 @@
2008-10-29 Tambet Ingo <tambet@gmail.com>
Half of it by Dan Williams <dcbw@redhat.com>
* libnm-util/libnm-util.ver
libnm-util/nm-setting-vpn.c
libnm-util/nm-setting-vpn.h
- Make properties private and add accessor functions.
* src/vpn-manager/nm-vpn-connection.c
src/vpn-manager/nm-vpn-manager.c
system-settings/plugins/keyfile/reader.c
vpn-daemons/openvpn/properties/auth-helpers.c
vpn-daemons/openvpn/properties/import-export.c
vpn-daemons/openvpn/properties/nm-openvpn.c
vpn-daemons/openvpn/src/nm-openvpn-service.c
vpn-daemons/pptp/auth-dialog/main.c
vpn-daemons/pptp/properties/advanced-dialog.c
vpn-daemons/pptp/properties/nm-pptp.c
vpn-daemons/pptp/src/nm-pptp-service.c
vpn-daemons/vpnc/properties/nm-vpnc.c
vpn-daemons/vpnc/src/nm-vpnc-service.c
- Use VPN setting accessors.
2008-10-28 Dan Williams <dcbw@redhat.com> 2008-10-28 Dan Williams <dcbw@redhat.com>
Patch from Tambet Ingo <tambet@gmail.com> Patch from Tambet Ingo <tambet@gmail.com>

View file

@ -130,6 +130,16 @@ global:
nm_setting_vpn_error_quark; nm_setting_vpn_error_quark;
nm_setting_vpn_get_type; nm_setting_vpn_get_type;
nm_setting_vpn_new; nm_setting_vpn_new;
nm_setting_vpn_get_service_type;
nm_setting_vpn_get_user_name;
nm_setting_vpn_add_data_item;
nm_setting_vpn_foreach_data_item;
nm_setting_vpn_get_data_item;
nm_setting_vpn_remove_data_item;
nm_setting_vpn_add_secret;
nm_setting_vpn_foreach_secret;
nm_setting_vpn_get_secret;
nm_setting_vpn_remove_secret;
nm_setting_wired_error_get_type; nm_setting_wired_error_get_type;
nm_setting_wired_error_quark; nm_setting_wired_error_quark;
nm_setting_wired_get_type; nm_setting_wired_get_type;

View file

@ -66,6 +66,36 @@ nm_setting_vpn_error_get_type (void)
G_DEFINE_TYPE (NMSettingVPN, nm_setting_vpn, NM_TYPE_SETTING) G_DEFINE_TYPE (NMSettingVPN, nm_setting_vpn, NM_TYPE_SETTING)
#define NM_SETTING_VPN_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_VPN, NMSettingVPNPrivate))
typedef struct {
char *service_type;
/* username of the user requesting this connection, thus
* it's really only valid for user connections, and it also
* should never be saved out to persistent config.
*/
char *user_name;
/* The hash table is created at setting object
* init time and should not be replaced. It is
* a char * -> char * mapping, and both the key
* and value are owned by the hash table, and should
* be allocated with functions whose value can be
* freed with g_free(). Should not contain secrets.
*/
GHashTable *data;
/* The hash table is created at setting object
* init time and should not be replaced. It is
* a char * -> char * mapping, and both the key
* and value are owned by the hash table, and should
* be allocated with functions whose value can be
* freed with g_free(). Should contain secrets only.
*/
GHashTable *secrets;
} NMSettingVPNPrivate;
enum { enum {
PROP_0, PROP_0,
PROP_SERVICE_TYPE, PROP_SERVICE_TYPE,
@ -82,12 +112,104 @@ nm_setting_vpn_new (void)
return (NMSetting *) g_object_new (NM_TYPE_SETTING_VPN, NULL); return (NMSetting *) g_object_new (NM_TYPE_SETTING_VPN, NULL);
} }
const char *
nm_setting_vpn_get_service_type (NMSettingVPN *setting)
{
g_return_val_if_fail (NM_IS_SETTING_VPN (setting), NULL);
return NM_SETTING_VPN_GET_PRIVATE (setting)->service_type;
}
const char *
nm_setting_vpn_get_user_name (NMSettingVPN *setting)
{
g_return_val_if_fail (NM_IS_SETTING_VPN (setting), NULL);
return NM_SETTING_VPN_GET_PRIVATE (setting)->user_name;
}
void
nm_setting_vpn_add_data_item (NMSettingVPN *setting,
const char *key,
const char *item)
{
g_return_if_fail (NM_IS_SETTING_VPN (setting));
g_hash_table_insert (NM_SETTING_VPN_GET_PRIVATE (setting)->data,
g_strdup (key), g_strdup (item));
}
const char *
nm_setting_vpn_get_data_item (NMSettingVPN *setting, const char *key)
{
g_return_val_if_fail (NM_IS_SETTING_VPN (setting), NULL);
return (const char *) g_hash_table_lookup (NM_SETTING_VPN_GET_PRIVATE (setting)->data, key);
}
void
nm_setting_vpn_remove_data_item (NMSettingVPN *setting, const char *key)
{
g_return_if_fail (NM_IS_SETTING_VPN (setting));
g_hash_table_remove (NM_SETTING_VPN_GET_PRIVATE (setting)->data, key);
}
void
nm_setting_vpn_foreach_data_item (NMSettingVPN *setting,
VPNIterFunc func,
gpointer user_data)
{
g_return_if_fail (NM_IS_SETTING_VPN (setting));
g_hash_table_foreach (NM_SETTING_VPN_GET_PRIVATE (setting)->data,
(GHFunc) func, user_data);
}
void
nm_setting_vpn_add_secret (NMSettingVPN *setting,
const char *key,
const char *secret)
{
g_return_if_fail (NM_IS_SETTING_VPN (setting));
g_hash_table_insert (NM_SETTING_VPN_GET_PRIVATE (setting)->secrets,
g_strdup (key), g_strdup (secret));
}
const char *
nm_setting_vpn_get_secret (NMSettingVPN *setting, const char *key)
{
g_return_val_if_fail (NM_IS_SETTING_VPN (setting), NULL);
return (const char *) g_hash_table_lookup (NM_SETTING_VPN_GET_PRIVATE (setting)->secrets, key);
}
void
nm_setting_vpn_remove_secret (NMSettingVPN *setting, const char *key)
{
g_return_if_fail (NM_IS_SETTING_VPN (setting));
g_hash_table_remove (NM_SETTING_VPN_GET_PRIVATE (setting)->secrets, key);
}
void
nm_setting_vpn_foreach_secret (NMSettingVPN *setting,
VPNIterFunc func,
gpointer user_data)
{
g_return_if_fail (NM_IS_SETTING_VPN (setting));
g_hash_table_foreach (NM_SETTING_VPN_GET_PRIVATE (setting)->secrets,
(GHFunc) func, user_data);
}
static gboolean static gboolean
verify (NMSetting *setting, GSList *all_settings, GError **error) verify (NMSetting *setting, GSList *all_settings, GError **error)
{ {
NMSettingVPN *self = NM_SETTING_VPN (setting); NMSettingVPNPrivate *priv = NM_SETTING_VPN_GET_PRIVATE (setting);
if (!self->service_type) { if (!priv->service_type) {
g_set_error (error, g_set_error (error,
NM_SETTING_VPN_ERROR, NM_SETTING_VPN_ERROR,
NM_SETTING_VPN_ERROR_MISSING_PROPERTY, NM_SETTING_VPN_ERROR_MISSING_PROPERTY,
@ -95,7 +217,7 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
return FALSE; return FALSE;
} }
if (!strlen (self->service_type)) { if (!strlen (priv->service_type)) {
g_set_error (error, g_set_error (error,
NM_SETTING_VPN_ERROR, NM_SETTING_VPN_ERROR,
NM_SETTING_VPN_ERROR_INVALID_PROPERTY, NM_SETTING_VPN_ERROR_INVALID_PROPERTY,
@ -104,7 +226,7 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
} }
/* default username can be NULL, but can't be zero-length */ /* default username can be NULL, but can't be zero-length */
if (self->user_name && !strlen (self->user_name)) { if (priv->user_name && !strlen (priv->user_name)) {
g_set_error (error, g_set_error (error,
NM_SETTING_VPN_ERROR, NM_SETTING_VPN_ERROR,
NM_SETTING_VPN_ERROR_INVALID_PROPERTY, NM_SETTING_VPN_ERROR_INVALID_PROPERTY,
@ -118,13 +240,13 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
static void static void
update_one_secret (NMSetting *setting, const char *key, GValue *value) update_one_secret (NMSetting *setting, const char *key, GValue *value)
{ {
NMSettingVPN *self = NM_SETTING_VPN (setting); NMSettingVPNPrivate *priv = NM_SETTING_VPN_GET_PRIVATE (setting);
g_return_if_fail (key != NULL); g_return_if_fail (key != NULL);
g_return_if_fail (value != NULL); g_return_if_fail (value != NULL);
g_return_if_fail (G_VALUE_HOLDS_STRING (value)); g_return_if_fail (G_VALUE_HOLDS_STRING (value));
g_hash_table_insert (self->secrets, g_strdup (key), g_value_dup_string (value)); g_hash_table_insert (priv->secrets, g_strdup (key), g_value_dup_string (value));
} }
static void static void
@ -140,21 +262,22 @@ destroy_one_secret (gpointer data)
static void static void
nm_setting_vpn_init (NMSettingVPN *setting) nm_setting_vpn_init (NMSettingVPN *setting)
{ {
g_object_set (setting, NM_SETTING_NAME, NM_SETTING_VPN_SETTING_NAME, NULL); NMSettingVPNPrivate *priv = NM_SETTING_VPN_GET_PRIVATE (setting);
setting->data = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); g_object_set (setting, NM_SETTING_NAME, NM_SETTING_VPN_SETTING_NAME, NULL);
setting->secrets = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, destroy_one_secret); priv->data = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
priv->secrets = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, destroy_one_secret);
} }
static void static void
finalize (GObject *object) finalize (GObject *object)
{ {
NMSettingVPN *self = NM_SETTING_VPN (object); NMSettingVPNPrivate *priv = NM_SETTING_VPN_GET_PRIVATE (object);
g_free (self->service_type); g_free (priv->service_type);
g_free (self->user_name); g_free (priv->user_name);
g_hash_table_destroy (self->data); g_hash_table_destroy (priv->data);
g_hash_table_destroy (self->secrets); g_hash_table_destroy (priv->secrets);
G_OBJECT_CLASS (nm_setting_vpn_parent_class)->finalize (object); G_OBJECT_CLASS (nm_setting_vpn_parent_class)->finalize (object);
} }
@ -169,31 +292,31 @@ static void
set_property (GObject *object, guint prop_id, set_property (GObject *object, guint prop_id,
const GValue *value, GParamSpec *pspec) const GValue *value, GParamSpec *pspec)
{ {
NMSettingVPN *setting = NM_SETTING_VPN (object); NMSettingVPNPrivate *priv = NM_SETTING_VPN_GET_PRIVATE (object);
GHashTable *new_hash; GHashTable *new_hash;
switch (prop_id) { switch (prop_id) {
case PROP_SERVICE_TYPE: case PROP_SERVICE_TYPE:
g_free (setting->service_type); g_free (priv->service_type);
setting->service_type = g_value_dup_string (value); priv->service_type = g_value_dup_string (value);
break; break;
case PROP_USER_NAME: case PROP_USER_NAME:
g_free (setting->user_name); g_free (priv->user_name);
setting->user_name = g_value_dup_string (value); priv->user_name = g_value_dup_string (value);
break; break;
case PROP_DATA: case PROP_DATA:
/* Must make a deep copy of the hash table here... */ /* Must make a deep copy of the hash table here... */
g_hash_table_remove_all (setting->data); g_hash_table_remove_all (priv->data);
new_hash = g_value_get_boxed (value); new_hash = g_value_get_boxed (value);
if (new_hash) if (new_hash)
g_hash_table_foreach (new_hash, copy_hash, setting->data); g_hash_table_foreach (new_hash, copy_hash, priv->data);
break; break;
case PROP_SECRETS: case PROP_SECRETS:
/* Must make a deep copy of the hash table here... */ /* Must make a deep copy of the hash table here... */
g_hash_table_remove_all (setting->secrets); g_hash_table_remove_all (priv->secrets);
new_hash = g_value_get_boxed (value); new_hash = g_value_get_boxed (value);
if (new_hash) if (new_hash)
g_hash_table_foreach (new_hash, copy_hash, setting->secrets); g_hash_table_foreach (new_hash, copy_hash, priv->secrets);
break; break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@ -206,19 +329,20 @@ get_property (GObject *object, guint prop_id,
GValue *value, GParamSpec *pspec) GValue *value, GParamSpec *pspec)
{ {
NMSettingVPN *setting = NM_SETTING_VPN (object); NMSettingVPN *setting = NM_SETTING_VPN (object);
NMSettingVPNPrivate *priv = NM_SETTING_VPN_GET_PRIVATE (setting);
switch (prop_id) { switch (prop_id) {
case PROP_SERVICE_TYPE: case PROP_SERVICE_TYPE:
g_value_set_string (value, setting->service_type); g_value_set_string (value, nm_setting_vpn_get_service_type (setting));
break; break;
case PROP_USER_NAME: case PROP_USER_NAME:
g_value_set_string (value, setting->user_name); g_value_set_string (value, nm_setting_vpn_get_user_name (setting));
break; break;
case PROP_DATA: case PROP_DATA:
g_value_set_boxed (value, setting->data); g_value_set_boxed (value, priv->data);
break; break;
case PROP_SECRETS: case PROP_SECRETS:
g_value_set_boxed (value, setting->secrets); g_value_set_boxed (value, priv->secrets);
break; break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@ -232,6 +356,8 @@ nm_setting_vpn_class_init (NMSettingVPNClass *setting_class)
GObjectClass *object_class = G_OBJECT_CLASS (setting_class); GObjectClass *object_class = G_OBJECT_CLASS (setting_class);
NMSettingClass *parent_class = NM_SETTING_CLASS (setting_class); NMSettingClass *parent_class = NM_SETTING_CLASS (setting_class);
g_type_class_add_private (setting_class, sizeof (NMSettingVPNPrivate));
/* virtual methods */ /* virtual methods */
object_class->set_property = set_property; object_class->set_property = set_property;
object_class->get_property = get_property; object_class->get_property = get_property;

View file

@ -59,41 +59,41 @@ GQuark nm_setting_vpn_error_quark (void);
typedef struct { typedef struct {
NMSetting parent; NMSetting parent;
char *service_type;
/* username of the user requesting this connection, thus
* it's really only valid for user connections, and it also
* should never be saved out to persistent config.
*/
char *user_name;
/* The hash table is created at setting object
* init time and should not be replaced. It is
* a char * -> char * mapping, and both the key
* and value are owned by the hash table, and should
* be allocated with functions whose value can be
* freed with g_free(). Should not contain secrets.
*/
GHashTable *data;
/* The hash table is created at setting object
* init time and should not be replaced. It is
* a char * -> char * mapping, and both the key
* and value are owned by the hash table, and should
* be allocated with functions whose value can be
* freed with g_free(). Should contain secrets only.
*/
GHashTable *secrets;
} NMSettingVPN; } NMSettingVPN;
typedef struct { typedef struct {
NMSettingClass parent; NMSettingClass parent;
} NMSettingVPNClass; } NMSettingVPNClass;
typedef void (*VPNIterFunc) (const char *key, const char *value, gpointer user_data);
GType nm_setting_vpn_get_type (void); GType nm_setting_vpn_get_type (void);
NMSetting *nm_setting_vpn_new (void); NMSetting *nm_setting_vpn_new (void);
const char *nm_setting_vpn_get_service_type (NMSettingVPN *setting);
const char *nm_setting_vpn_get_user_name (NMSettingVPN *setting);
void nm_setting_vpn_add_data_item (NMSettingVPN *setting,
const char *key,
const char *item);
const char * nm_setting_vpn_get_data_item (NMSettingVPN *setting,
const char *key);
void nm_setting_vpn_remove_data_item (NMSettingVPN *setting,
const char *key);
void nm_setting_vpn_foreach_data_item (NMSettingVPN *setting,
VPNIterFunc func,
gpointer user_data);
void nm_setting_vpn_add_secret (NMSettingVPN *setting,
const char *key,
const char *secret);
const char * nm_setting_vpn_get_secret (NMSettingVPN *setting,
const char *key);
void nm_setting_vpn_remove_secret (NMSettingVPN *setting,
const char *key);
void nm_setting_vpn_foreach_secret (NMSettingVPN *setting,
VPNIterFunc func,
gpointer user_data);
G_END_DECLS G_END_DECLS

View file

@ -224,14 +224,14 @@ nm_vpn_connection_new (NMConnection *connection,
return vpn_connection; return vpn_connection;
} }
static char * static const char *
nm_vpn_connection_get_service (NMVPNConnection *connection) nm_vpn_connection_get_service (NMVPNConnection *connection)
{ {
NMVPNConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (connection); NMVPNConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (connection);
NMSettingVPN *setting; NMSettingVPN *setting;
setting = (NMSettingVPN *) nm_connection_get_setting (priv->connection, NM_TYPE_SETTING_VPN); setting = (NMSettingVPN *) nm_connection_get_setting (priv->connection, NM_TYPE_SETTING_VPN);
return setting->service_type; return nm_setting_vpn_get_service_type (setting);
} }
static void static void

View file

@ -152,6 +152,7 @@ nm_vpn_manager_activate_connection (NMVPNManager *manager,
NMVPNService *service; NMVPNService *service;
char *path = NULL; char *path = NULL;
NMVPNConnection *vpn; NMVPNConnection *vpn;
const char *service_type;
g_return_val_if_fail (NM_IS_VPN_MANAGER (manager), NULL); g_return_val_if_fail (NM_IS_VPN_MANAGER (manager), NULL);
g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL); g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL);
@ -181,9 +182,10 @@ nm_vpn_manager_activate_connection (NMVPNManager *manager,
vpn = NULL; vpn = NULL;
} }
service = nm_vpn_manager_get_service (manager, vpn_setting->service_type); service_type = nm_setting_vpn_get_service_type (vpn_setting);
service = nm_vpn_manager_get_service (manager, service_type);
if (!service) { if (!service) {
service = nm_vpn_service_new (vpn_setting->service_type); service = nm_vpn_service_new (service_type);
if (service) if (service)
nm_vpn_manager_add_service (manager, service); nm_vpn_manager_add_service (manager, service);
} }

View file

@ -310,10 +310,8 @@ read_hash_of_string (GKeyFile *file, NMSetting *setting, const char *key)
continue; continue;
if (NM_IS_SETTING_VPN (setting)) { if (NM_IS_SETTING_VPN (setting)) {
NMSettingVPN *s_vpn = NM_SETTING_VPN (setting);
if (strcmp (*iter, NM_SETTING_VPN_SERVICE_TYPE)) if (strcmp (*iter, NM_SETTING_VPN_SERVICE_TYPE))
g_hash_table_insert (s_vpn->data, g_strdup (*iter), g_strdup (value)); nm_setting_vpn_add_data_item (NM_SETTING_VPN (setting), *iter, value);
} }
g_free (value); g_free (value);
} }
@ -493,8 +491,10 @@ read_vpn_secrets (GKeyFile *file, NMSettingVPN *s_vpn)
char *secret; char *secret;
secret = g_key_file_get_string (file, VPN_SECRETS_GROUP, *iter, NULL); secret = g_key_file_get_string (file, VPN_SECRETS_GROUP, *iter, NULL);
if (secret) if (secret) {
g_hash_table_insert (s_vpn->secrets, g_strdup (*iter), secret); nm_setting_vpn_add_secret (s_vpn, *iter, secret);
g_free (secret);
}
} }
g_strfreev (keys); g_strfreev (keys);
} }

View file

@ -75,8 +75,7 @@ fill_password (GladeXML *xml,
if (s_vpn) { if (s_vpn) {
const char *tmp; const char *tmp;
tmp = g_hash_table_lookup (s_vpn->secrets, tmp = nm_setting_vpn_get_secret (s_vpn, priv_key_password ? NM_OPENVPN_KEY_CERTPASS : NM_OPENVPN_KEY_PASSWORD);
priv_key_password ? NM_OPENVPN_KEY_CERTPASS : NM_OPENVPN_KEY_PASSWORD);
if (tmp) if (tmp)
password = gnome_keyring_memory_strdup (tmp); password = gnome_keyring_memory_strdup (tmp);
} }
@ -161,8 +160,8 @@ tls_pw_init_auth_widget (GladeXML *xml,
_("Choose a Certificate Authority certificate...")); _("Choose a Certificate Authority certificate..."));
g_signal_connect (G_OBJECT (widget), "selection-changed", G_CALLBACK (changed_cb), user_data); g_signal_connect (G_OBJECT (widget), "selection-changed", G_CALLBACK (changed_cb), user_data);
if (s_vpn && s_vpn->data) { if (s_vpn) {
value = g_hash_table_lookup (s_vpn->data, NM_OPENVPN_KEY_CA); value = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_CA);
if (value && strlen (value)) if (value && strlen (value))
gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (widget), value); gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (widget), value);
} }
@ -180,8 +179,8 @@ tls_pw_init_auth_widget (GladeXML *xml,
_("Choose your personal certificate...")); _("Choose your personal certificate..."));
g_signal_connect (G_OBJECT (widget), "selection-changed", G_CALLBACK (changed_cb), user_data); g_signal_connect (G_OBJECT (widget), "selection-changed", G_CALLBACK (changed_cb), user_data);
if (s_vpn && s_vpn->data) { if (s_vpn) {
value = g_hash_table_lookup (s_vpn->data, NM_OPENVPN_KEY_CERT); value = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_CERT);
if (value && strlen (value)) if (value && strlen (value))
gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (widget), value); gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (widget), value);
} }
@ -198,8 +197,8 @@ tls_pw_init_auth_widget (GladeXML *xml,
_("Choose your private key...")); _("Choose your private key..."));
g_signal_connect (G_OBJECT (widget), "selection-changed", G_CALLBACK (changed_cb), user_data); g_signal_connect (G_OBJECT (widget), "selection-changed", G_CALLBACK (changed_cb), user_data);
if (s_vpn && s_vpn->data) { if (s_vpn) {
value = g_hash_table_lookup (s_vpn->data, NM_OPENVPN_KEY_KEY); value = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_KEY);
if (value && strlen (value)) if (value && strlen (value))
gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (widget), value); gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (widget), value);
} }
@ -211,8 +210,8 @@ tls_pw_init_auth_widget (GladeXML *xml,
g_free (tmp); g_free (tmp);
gtk_size_group_add_widget (group, widget); gtk_size_group_add_widget (group, widget);
if (s_vpn && s_vpn->data) { if (s_vpn) {
value = g_hash_table_lookup (s_vpn->data, NM_OPENVPN_KEY_USERNAME); value = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_USERNAME);
if (value && strlen (value)) if (value && strlen (value))
gtk_entry_set_text (GTK_ENTRY (widget), value); gtk_entry_set_text (GTK_ENTRY (widget), value);
} }
@ -251,16 +250,16 @@ sk_init_auth_widget (GladeXML *xml,
_("Choose an OpenVPN static key...")); _("Choose an OpenVPN static key..."));
g_signal_connect (G_OBJECT (widget), "selection-changed", G_CALLBACK (changed_cb), user_data); g_signal_connect (G_OBJECT (widget), "selection-changed", G_CALLBACK (changed_cb), user_data);
if (s_vpn && s_vpn->data) { if (s_vpn) {
value = g_hash_table_lookup (s_vpn->data, NM_OPENVPN_KEY_STATIC_KEY); value = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_STATIC_KEY);
if (value && strlen (value)) if (value && strlen (value))
gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (widget), value); gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (widget), value);
} }
store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT); store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT);
if (s_vpn && s_vpn->data) { if (s_vpn) {
value = g_hash_table_lookup (s_vpn->data, NM_OPENVPN_KEY_STATIC_KEY_DIRECTION); value = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_STATIC_KEY_DIRECTION);
if (value && strlen (value)) { if (value && strlen (value)) {
long int tmp; long int tmp;
@ -297,8 +296,8 @@ sk_init_auth_widget (GladeXML *xml,
widget = glade_xml_get_widget (xml, "sk_local_address_entry"); widget = glade_xml_get_widget (xml, "sk_local_address_entry");
gtk_size_group_add_widget (group, widget); gtk_size_group_add_widget (group, widget);
g_signal_connect (G_OBJECT (widget), "changed", G_CALLBACK (changed_cb), user_data); g_signal_connect (G_OBJECT (widget), "changed", G_CALLBACK (changed_cb), user_data);
if (s_vpn && s_vpn->data) { if (s_vpn) {
value = g_hash_table_lookup (s_vpn->data, NM_OPENVPN_KEY_LOCAL_IP); value = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_LOCAL_IP);
if (value && strlen (value)) if (value && strlen (value))
gtk_entry_set_text (GTK_ENTRY (widget), value); gtk_entry_set_text (GTK_ENTRY (widget), value);
} }
@ -437,7 +436,6 @@ update_from_filechooser (GladeXML *xml,
g_return_if_fail (prefix != NULL); g_return_if_fail (prefix != NULL);
g_return_if_fail (widget_name != NULL); g_return_if_fail (widget_name != NULL);
g_return_if_fail (s_vpn != NULL); g_return_if_fail (s_vpn != NULL);
g_return_if_fail (s_vpn->data != NULL);
tmp = g_strdup_printf ("%s_%s", prefix, widget_name); tmp = g_strdup_printf ("%s_%s", prefix, widget_name);
widget = glade_xml_get_widget (xml, tmp); widget = glade_xml_get_widget (xml, tmp);
@ -448,7 +446,7 @@ update_from_filechooser (GladeXML *xml,
return; return;
if (strlen (filename)) if (strlen (filename))
g_hash_table_insert (s_vpn->data, g_strdup (key), g_strdup (filename)); nm_setting_vpn_add_data_item (s_vpn, key, filename);
g_free (filename); g_free (filename);
} }
@ -471,18 +469,14 @@ update_username (GladeXML *xml, const char *prefix, NMSettingVPN *s_vpn)
g_return_if_fail (xml != NULL); g_return_if_fail (xml != NULL);
g_return_if_fail (prefix != NULL); g_return_if_fail (prefix != NULL);
g_return_if_fail (s_vpn != NULL); g_return_if_fail (s_vpn != NULL);
g_return_if_fail (s_vpn->data != NULL);
tmp = g_strdup_printf ("%s_username_entry", prefix); tmp = g_strdup_printf ("%s_username_entry", prefix);
widget = glade_xml_get_widget (xml, tmp); widget = glade_xml_get_widget (xml, tmp);
g_free (tmp); g_free (tmp);
str = gtk_entry_get_text (GTK_ENTRY (widget)); str = gtk_entry_get_text (GTK_ENTRY (widget));
if (str && strlen (str)) { if (str && strlen (str))
g_hash_table_insert (s_vpn->data, nm_setting_vpn_add_data_item (s_vpn, NM_OPENVPN_KEY_USERNAME, str);
g_strdup (NM_OPENVPN_KEY_USERNAME),
g_strdup (str));
}
} }
gboolean gboolean
@ -512,9 +506,9 @@ auth_widget_update_connection (GladeXML *xml,
gtk_tree_model_get (model, &iter, SK_DIR_COL_NUM, &direction, -1); gtk_tree_model_get (model, &iter, SK_DIR_COL_NUM, &direction, -1);
if (direction > -1) { if (direction > -1) {
g_hash_table_insert (s_vpn->data, char *tmp = g_strdup_printf ("%d", direction);
g_strdup (NM_OPENVPN_KEY_STATIC_KEY_DIRECTION), nm_setting_vpn_add_data_item (s_vpn, NM_OPENVPN_KEY_STATIC_KEY_DIRECTION, tmp);
g_strdup_printf ("%d", direction)); g_free (tmp);
} }
} }
} else } else
@ -733,17 +727,16 @@ static const char *advanced_keys[] = {
}; };
static void static void
copy_values (gpointer key, gpointer data, gpointer user_data) copy_values (const char *key, const char *value, gpointer user_data)
{ {
GHashTable *hash = (GHashTable *) user_data; GHashTable *hash = (GHashTable *) user_data;
const char *value = (const char *) data;
const char **i; const char **i;
for (i = &advanced_keys[0]; *i; i++) { for (i = &advanced_keys[0]; *i; i++) {
if (strcmp ((const char *) key, *i)) if (strcmp (key, *i))
continue; continue;
g_hash_table_insert (hash, g_strdup ((const char *) key), g_strdup (value)); g_hash_table_insert (hash, g_strdup (key), g_strdup (value));
} }
} }
@ -757,9 +750,7 @@ advanced_dialog_new_hash_from_connection (NMConnection *connection,
hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
s_vpn = (NMSettingVPN *) nm_connection_get_setting (connection, NM_TYPE_SETTING_VPN); s_vpn = (NMSettingVPN *) nm_connection_get_setting (connection, NM_TYPE_SETTING_VPN);
if (s_vpn && s_vpn->data) nm_setting_vpn_foreach_data_item (s_vpn, copy_values, hash);
g_hash_table_foreach (s_vpn->data, copy_values, hash);
return hash; return hash;
} }

View file

@ -60,11 +60,11 @@ static gboolean
handle_path_item (const char *line, handle_path_item (const char *line,
const char *tag, const char *tag,
const char *key, const char *key,
GHashTable *hash, NMSettingVPN *s_vpn,
const char *path, const char *path,
char **leftover) char **leftover)
{ {
char *tmp, *file, *unquoted, *p, *full_path; char *tmp, *file, *unquoted, *p, *full_path = NULL;
gboolean quoted = FALSE; gboolean quoted = FALSE;
if (leftover) if (leftover)
@ -110,7 +110,7 @@ handle_path_item (const char *line,
if (leftover && *file) if (leftover && *file)
*leftover = file + 1; *leftover = file + 1;
g_hash_table_insert (hash, g_strdup (key), g_strdup (unquoted)); nm_setting_vpn_add_data_item (s_vpn, key, unquoted);
g_free (unquoted); g_free (unquoted);
out: out:
@ -138,7 +138,7 @@ get_args (const char *line)
} }
static void static void
handle_direction (const char *tag, const char *key, char *leftover, GHashTable *hash) handle_direction (const char *tag, const char *key, char *leftover, NMSettingVPN *s_vpn)
{ {
glong direction; glong direction;
@ -153,9 +153,9 @@ handle_direction (const char *tag, const char *key, char *leftover, GHashTable *
direction = strtol (leftover, NULL, 10); direction = strtol (leftover, NULL, 10);
if (errno == 0) { if (errno == 0) {
if (direction == 0) if (direction == 0)
g_hash_table_insert (hash, g_strdup (key), g_strdup ("0")); nm_setting_vpn_add_data_item (s_vpn, key, "0");
else if (direction == 1) else if (direction == 1)
g_hash_table_insert (hash, g_strdup (key), g_strdup ("1")); nm_setting_vpn_add_data_item (s_vpn, key, "1");
} else } else
g_warning ("%s: unknown %s direction '%s'", __func__, tag, leftover); g_warning ("%s: unknown %s direction '%s'", __func__, tag, leftover);
} }
@ -179,7 +179,8 @@ do_import (const char *path, char **lines, GError **error)
nm_connection_add_setting (connection, NM_SETTING (s_con)); nm_connection_add_setting (connection, NM_SETTING (s_con));
s_vpn = NM_SETTING_VPN (nm_setting_vpn_new ()); s_vpn = NM_SETTING_VPN (nm_setting_vpn_new ());
s_vpn->service_type = g_strdup (NM_DBUS_SERVICE_OPENVPN);
g_object_set (s_vpn, NM_SETTING_VPN_SERVICE_TYPE, NM_DBUS_SERVICE_OPENVPN, NULL);
/* Get the default path for ca, cert, key file, these files maybe /* Get the default path for ca, cert, key file, these files maybe
* in same path with the configuration file */ * in same path with the configuration file */
@ -209,9 +210,7 @@ do_import (const char *path, char **lines, GError **error)
if (strstr (*line, "tun")) { if (strstr (*line, "tun")) {
/* ignore; default is tun */ /* ignore; default is tun */
} else if (strstr (*line, "tap")) { } else if (strstr (*line, "tap")) {
g_hash_table_insert (s_vpn->data, nm_setting_vpn_add_data_item (s_vpn, NM_OPENVPN_KEY_TAP_DEV, "yes");
g_strdup (NM_OPENVPN_KEY_TAP_DEV),
g_strdup ("yes"));
} else } else
g_warning ("%s: unknown dev option '%s'", __func__, *line); g_warning ("%s: unknown dev option '%s'", __func__, *line);
@ -222,9 +221,7 @@ do_import (const char *path, char **lines, GError **error)
if (strstr (*line, "udp")) { if (strstr (*line, "udp")) {
/* ignore; udp is default */ /* ignore; udp is default */
} else if (strstr (*line, "tcp")) { } else if (strstr (*line, "tcp")) {
g_hash_table_insert (s_vpn->data, nm_setting_vpn_add_data_item (s_vpn, NM_OPENVPN_KEY_PROTO_TCP, "yes");
g_strdup (NM_OPENVPN_KEY_PROTO_TCP),
g_strdup ("yes"));
} else } else
g_warning ("%s: unknown proto option '%s'", __func__, *line); g_warning ("%s: unknown proto option '%s'", __func__, *line);
@ -232,9 +229,7 @@ do_import (const char *path, char **lines, GError **error)
} }
if (!strncmp (*line, COMP_TAG, strlen (COMP_TAG))) { if (!strncmp (*line, COMP_TAG, strlen (COMP_TAG))) {
g_hash_table_insert (s_vpn->data, nm_setting_vpn_add_data_item (s_vpn, NM_OPENVPN_KEY_COMP_LZO, "yes");
g_strdup (NM_OPENVPN_KEY_COMP_LZO),
g_strdup ("yes"));
continue; continue;
} }
@ -244,9 +239,7 @@ do_import (const char *path, char **lines, GError **error)
continue; continue;
if (g_strv_length (items) >= 1) { if (g_strv_length (items) >= 1) {
g_hash_table_insert (s_vpn->data, nm_setting_vpn_add_data_item (s_vpn, NM_OPENVPN_KEY_REMOTE, items[0]);
g_strdup (NM_OPENVPN_KEY_REMOTE),
g_strdup (items[0]));
have_remote = TRUE; have_remote = TRUE;
if (g_strv_length (items) >= 2) { if (g_strv_length (items) >= 2) {
@ -255,44 +248,44 @@ do_import (const char *path, char **lines, GError **error)
errno = 0; errno = 0;
port = strtol (items[1], NULL, 10); port = strtol (items[1], NULL, 10);
if ((errno == 0) && (port > 0) && (port < 65536)) { if ((errno == 0) && (port > 0) && (port < 65536)) {
g_hash_table_insert (s_vpn->data, char *tmp = g_strdup_printf ("%d", (guint32) port);
g_strdup (NM_OPENVPN_KEY_PORT), nm_setting_vpn_add_data_item (s_vpn, NM_OPENVPN_KEY_PORT, tmp);
g_strdup_printf ("%d", (guint32) port)); g_free (tmp);
} else } else
g_warning ("%s: invalid remote port in option '%s'", __func__, *line); g_warning ("%s: invalid remote port in option '%s'", __func__, *line);
} }
} }
g_strfreev (items); g_strfreev (items);
if (!g_hash_table_lookup (s_vpn->data, NM_OPENVPN_KEY_REMOTE)) if (!nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_REMOTE))
g_warning ("%s: unknown remote option '%s'", __func__, *line); g_warning ("%s: unknown remote option '%s'", __func__, *line);
continue; continue;
} }
if (handle_path_item (*line, CA_TAG, NM_OPENVPN_KEY_CA, s_vpn->data, default_path, NULL)) if (handle_path_item (*line, CA_TAG, NM_OPENVPN_KEY_CA, s_vpn, default_path, NULL))
continue; continue;
if (handle_path_item (*line, CERT_TAG, NM_OPENVPN_KEY_CERT, s_vpn->data, default_path, NULL)) if (handle_path_item (*line, CERT_TAG, NM_OPENVPN_KEY_CERT, s_vpn, default_path, NULL))
continue; continue;
if (handle_path_item (*line, KEY_TAG, NM_OPENVPN_KEY_KEY, s_vpn->data, default_path, NULL)) if (handle_path_item (*line, KEY_TAG, NM_OPENVPN_KEY_KEY, s_vpn, default_path, NULL))
continue; continue;
if (handle_path_item (*line, SECRET_TAG, NM_OPENVPN_KEY_STATIC_KEY, if (handle_path_item (*line, SECRET_TAG, NM_OPENVPN_KEY_STATIC_KEY,
s_vpn->data, default_path, &leftover)) { s_vpn, default_path, &leftover)) {
handle_direction ("secret", handle_direction ("secret",
NM_OPENVPN_KEY_STATIC_KEY_DIRECTION, NM_OPENVPN_KEY_STATIC_KEY_DIRECTION,
leftover, leftover,
s_vpn->data); s_vpn);
continue; continue;
} }
if (handle_path_item (*line, TLS_AUTH_TAG, NM_OPENVPN_KEY_TA, if (handle_path_item (*line, TLS_AUTH_TAG, NM_OPENVPN_KEY_TA,
s_vpn->data, default_path, &leftover)) { s_vpn, default_path, &leftover)) {
handle_direction ("tls-auth", handle_direction ("tls-auth",
NM_OPENVPN_KEY_TA_DIR, NM_OPENVPN_KEY_TA_DIR,
leftover, leftover,
s_vpn->data); s_vpn);
continue; continue;
} }
@ -301,11 +294,9 @@ do_import (const char *path, char **lines, GError **error)
if (!items) if (!items)
continue; continue;
if (g_strv_length (items)) { if (g_strv_length (items))
g_hash_table_insert (s_vpn->data, nm_setting_vpn_add_data_item (s_vpn, NM_OPENVPN_KEY_CIPHER, items[0]);
g_strdup (NM_OPENVPN_KEY_CIPHER),
g_strdup (items[0]));
}
g_strfreev (items); g_strfreev (items);
continue; continue;
} }
@ -316,12 +307,8 @@ do_import (const char *path, char **lines, GError **error)
continue; continue;
if (g_strv_length (items) == 2) { if (g_strv_length (items) == 2) {
g_hash_table_insert (s_vpn->data, nm_setting_vpn_add_data_item (s_vpn, NM_OPENVPN_KEY_LOCAL_IP, items[0]);
g_strdup (NM_OPENVPN_KEY_LOCAL_IP), nm_setting_vpn_add_data_item (s_vpn, NM_OPENVPN_KEY_REMOTE_IP, items[1]);
g_strdup (items[0]));
g_hash_table_insert (s_vpn->data,
g_strdup (NM_OPENVPN_KEY_REMOTE_IP),
g_strdup (items[1]));
} else } else
g_warning ("%s: unknown ifconfig option '%s'", __func__, *line); g_warning ("%s: unknown ifconfig option '%s'", __func__, *line);
g_strfreev (items); g_strfreev (items);
@ -332,7 +319,7 @@ do_import (const char *path, char **lines, GError **error)
have_pass = TRUE; have_pass = TRUE;
} }
if (g_hash_table_lookup (s_vpn->data, NM_OPENVPN_KEY_STATIC_KEY)) if (nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_STATIC_KEY))
have_sk = TRUE; have_sk = TRUE;
if (!have_client && !have_sk) { if (!have_client && !have_sk) {
@ -352,12 +339,12 @@ do_import (const char *path, char **lines, GError **error)
} else { } else {
gboolean have_certs = FALSE, have_ca = FALSE; gboolean have_certs = FALSE, have_ca = FALSE;
if (g_hash_table_lookup (s_vpn->data, NM_OPENVPN_KEY_CA)) if (nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_CA))
have_ca = TRUE; have_ca = TRUE;
if ( have_ca if ( have_ca
&& g_hash_table_lookup (s_vpn->data, NM_OPENVPN_KEY_CERT) && nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_CERT)
&& g_hash_table_lookup (s_vpn->data, NM_OPENVPN_KEY_KEY)) && nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_KEY))
have_certs = TRUE; have_certs = TRUE;
/* Determine connection type */ /* Determine connection type */
@ -374,9 +361,7 @@ do_import (const char *path, char **lines, GError **error)
if (!ctype) if (!ctype)
ctype = NM_OPENVPN_CONTYPE_TLS; ctype = NM_OPENVPN_CONTYPE_TLS;
g_hash_table_insert (s_vpn->data, nm_setting_vpn_add_data_item (s_vpn, NM_OPENVPN_KEY_CONNECTION_TYPE, ctype);
g_strdup (NM_OPENVPN_KEY_CONNECTION_TYPE),
g_strdup (ctype));
} }
g_free (default_path); g_free (default_path);

View file

@ -285,7 +285,7 @@ init_plugin_ui (OpenvpnPluginUiWidget *self, NMConnection *connection, GError **
return FALSE; return FALSE;
gtk_size_group_add_widget (priv->group, widget); gtk_size_group_add_widget (priv->group, widget);
if (s_vpn) { if (s_vpn) {
value = g_hash_table_lookup (s_vpn->data, NM_OPENVPN_KEY_REMOTE); value = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_REMOTE);
if (value) if (value)
gtk_entry_set_text (GTK_ENTRY (widget), value); gtk_entry_set_text (GTK_ENTRY (widget), value);
} }
@ -298,8 +298,8 @@ init_plugin_ui (OpenvpnPluginUiWidget *self, NMConnection *connection, GError **
store = gtk_list_store_new (3, G_TYPE_STRING, G_TYPE_INT, G_TYPE_STRING); store = gtk_list_store_new (3, G_TYPE_STRING, G_TYPE_INT, G_TYPE_STRING);
if (s_vpn && s_vpn->data) { if (s_vpn) {
contype = g_hash_table_lookup (s_vpn->data, NM_OPENVPN_KEY_CONNECTION_TYPE); contype = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_CONNECTION_TYPE);
if (contype) { if (contype) {
if ( strcmp (contype, NM_OPENVPN_CONTYPE_TLS) if ( strcmp (contype, NM_OPENVPN_CONTYPE_TLS)
&& strcmp (contype, NM_OPENVPN_CONTYPE_STATIC_KEY) && strcmp (contype, NM_OPENVPN_CONTYPE_STATIC_KEY)
@ -392,10 +392,10 @@ get_widget (NMVpnPluginUiWidgetInterface *iface)
static void static void
hash_copy_advanced (gpointer key, gpointer data, gpointer user_data) hash_copy_advanced (gpointer key, gpointer data, gpointer user_data)
{ {
GHashTable *hash = (GHashTable *) user_data; NMSettingVPN *s_vpn = NM_SETTING_VPN (user_data);
const char *value = (const char *) data; const char *value = (const char *) data;
g_hash_table_insert (hash, g_strdup ((const char *) key), g_strdup (value)); nm_setting_vpn_add_data_item (s_vpn, (const char *) key, value);
} }
static const char * static const char *
@ -431,27 +431,22 @@ update_connection (NMVpnPluginUiWidgetInterface *iface,
return FALSE; return FALSE;
s_vpn = NM_SETTING_VPN (nm_setting_vpn_new ()); s_vpn = NM_SETTING_VPN (nm_setting_vpn_new ());
s_vpn->service_type = g_strdup (NM_DBUS_SERVICE_OPENVPN); g_object_set (s_vpn, NM_SETTING_VPN_SERVICE_TYPE, NM_DBUS_SERVICE_OPENVPN, NULL);
/* Gateway */ /* Gateway */
widget = glade_xml_get_widget (priv->xml, "gateway_entry"); widget = glade_xml_get_widget (priv->xml, "gateway_entry");
str = (char *) gtk_entry_get_text (GTK_ENTRY (widget)); str = (char *) gtk_entry_get_text (GTK_ENTRY (widget));
if (str && strlen (str)) { if (str && strlen (str))
g_hash_table_insert (s_vpn->data, nm_setting_vpn_add_data_item (s_vpn, NM_OPENVPN_KEY_REMOTE, str);
g_strdup (NM_OPENVPN_KEY_REMOTE),
g_strdup (str));
}
auth_type = get_auth_type (priv->xml); auth_type = get_auth_type (priv->xml);
if (auth_type) { if (auth_type) {
g_hash_table_insert (s_vpn->data, nm_setting_vpn_add_data_item (s_vpn, NM_OPENVPN_KEY_CONNECTION_TYPE, auth_type);
g_strdup (NM_OPENVPN_KEY_CONNECTION_TYPE),
g_strdup (auth_type));
auth_widget_update_connection (priv->xml, auth_type, s_vpn); auth_widget_update_connection (priv->xml, auth_type, s_vpn);
} }
if (priv->advanced) if (priv->advanced)
g_hash_table_foreach (priv->advanced, hash_copy_advanced, s_vpn->data); g_hash_table_foreach (priv->advanced, hash_copy_advanced, s_vpn);
nm_connection_add_setting (connection, NM_SETTING (s_vpn)); nm_connection_add_setting (connection, NM_SETTING (s_vpn));
valid = TRUE; valid = TRUE;

View file

@ -100,6 +100,10 @@ static ValidProperty valid_properties[] = {
{ NM_OPENVPN_KEY_TA, G_TYPE_STRING, 0, 0, FALSE }, { NM_OPENVPN_KEY_TA, G_TYPE_STRING, 0, 0, FALSE },
{ NM_OPENVPN_KEY_TA_DIR, G_TYPE_INT, 0, 1, FALSE }, { NM_OPENVPN_KEY_TA_DIR, G_TYPE_INT, 0, 1, FALSE },
{ NM_OPENVPN_KEY_USERNAME, G_TYPE_STRING, 0, 0, FALSE }, { NM_OPENVPN_KEY_USERNAME, G_TYPE_STRING, 0, 0, FALSE },
{ NULL, G_TYPE_NONE, FALSE }
};
static ValidProperty valid_secrets[] = {
{ NM_OPENVPN_KEY_PASSWORD, G_TYPE_STRING, 0, 0, FALSE }, { NM_OPENVPN_KEY_PASSWORD, G_TYPE_STRING, 0, 0, FALSE },
{ NM_OPENVPN_KEY_CERTPASS, G_TYPE_STRING, 0, 0, FALSE }, { NM_OPENVPN_KEY_CERTPASS, G_TYPE_STRING, 0, 0, FALSE },
{ NM_OPENVPN_KEY_NOSECRET, G_TYPE_STRING, 0, 0, FALSE }, { NM_OPENVPN_KEY_NOSECRET, G_TYPE_STRING, 0, 0, FALSE },
@ -123,83 +127,94 @@ validate_address (const char *address)
return TRUE; return TRUE;
} }
typedef struct ValidateInfo {
ValidProperty *table;
GError **error;
gboolean have_items;
} ValidateInfo;
static void static void
validate_one_property (gpointer key, gpointer value, gpointer user_data) validate_one_property (const char *key, const char *value, gpointer user_data)
{ {
GError **error = (GError **) user_data; ValidateInfo *info = (ValidateInfo *) user_data;
int i; int i;
if (*error) if (*(info->error))
return; return;
info->have_items = TRUE;
/* 'name' is the setting name; always allowed but unused */ /* 'name' is the setting name; always allowed but unused */
if (!strcmp ((char *) key, NM_SETTING_NAME)) if (!strcmp (key, NM_SETTING_NAME))
return; return;
for (i = 0; valid_properties[i].name; i++) { for (i = 0; info->table[i].name; i++) {
ValidProperty prop = valid_properties[i]; ValidProperty prop = info->table[i];
long int tmp; long int tmp;
if (strcmp (prop.name, (char *) key)) if (strcmp (prop.name, key))
continue; continue;
switch (prop.type) { switch (prop.type) {
case G_TYPE_STRING: case G_TYPE_STRING:
if (!prop.address || validate_address ((const char *) value)) if (!prop.address || validate_address (value))
return; /* valid */ return; /* valid */
g_set_error (error, g_set_error (info->error,
NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR,
NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS, NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS,
"invalid address '%s'", "invalid address '%s'",
(const char *) key); key);
break; break;
case G_TYPE_INT: case G_TYPE_INT:
errno = 0; errno = 0;
tmp = strtol ((char *) value, NULL, 10); tmp = strtol (value, NULL, 10);
if (errno == 0 && tmp >= prop.int_min && tmp <= prop.int_max) if (errno == 0 && tmp >= prop.int_min && tmp <= prop.int_max)
return; /* valid */ return; /* valid */
g_set_error (error, g_set_error (info->error,
NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR,
NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS, NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS,
"invalid integer property '%s' or out of range [%d -> %d]", "invalid integer property '%s' or out of range [%d -> %d]",
(const char *) key, prop.int_min, prop.int_max); key, prop.int_min, prop.int_max);
break; break;
case G_TYPE_BOOLEAN: case G_TYPE_BOOLEAN:
if (!strcmp ((char *) value, "yes") || !strcmp ((char *) value, "no")) if (!strcmp (value, "yes") || !strcmp (value, "no"))
return; /* valid */ return; /* valid */
g_set_error (error, g_set_error (info->error,
NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR,
NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS, NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS,
"invalid boolean property '%s' (not yes or no)", "invalid boolean property '%s' (not yes or no)",
(const char *) key); key);
break; break;
default: default:
g_set_error (error, g_set_error (info->error,
NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR,
NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS, NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS,
"unhandled property '%s' type %s", "unhandled property '%s' type %s",
(const char *) key, g_type_name (prop.type)); key, g_type_name (prop.type));
break; break;
} }
} }
/* Did not find the property from valid_properties or the type did not match */ /* Did not find the property from valid_properties or the type did not match */
if (!valid_properties[i].name) { if (!info->table[i].name) {
g_set_error (error, g_set_error (info->error,
NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR,
NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS, NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS,
"property '%s' invalid or not supported", "property '%s' invalid or not supported",
(const char *) key); key);
} }
} }
static gboolean static gboolean
nm_openvpn_properties_validate (GHashTable *properties, GError **error) nm_openvpn_properties_validate (NMSettingVPN *s_vpn, GError **error)
{ {
if (g_hash_table_size (properties) < 1) { ValidateInfo info = { &valid_properties[0], error, FALSE };
nm_setting_vpn_foreach_data_item (s_vpn, validate_one_property, &info);
if (!info.have_items) {
g_set_error (error, g_set_error (error,
NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR,
NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS, NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS,
@ -208,7 +223,23 @@ nm_openvpn_properties_validate (GHashTable *properties, GError **error)
return FALSE; return FALSE;
} }
g_hash_table_foreach (properties, validate_one_property, error); return *error ? FALSE : TRUE;
}
static gboolean
nm_openvpn_secrets_validate (NMSettingVPN *s_vpn, GError **error)
{
ValidateInfo info = { &valid_secrets[0], error, FALSE };
nm_setting_vpn_foreach_secret (s_vpn, validate_one_property, &info);
if (!info.have_items) {
g_set_error (error,
NM_VPN_PLUGIN_ERROR,
NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS,
"%s",
"No VPN secrets!");
return FALSE;
}
return *error ? FALSE : TRUE; return *error ? FALSE : TRUE;
} }
@ -262,7 +293,7 @@ handle_management_socket (NMVPNPlugin *plugin,
NMVPNPluginFailure *out_failure) NMVPNPluginFailure *out_failure)
{ {
NMOpenvpnPluginIOData *io_data = NM_OPENVPN_PLUGIN_GET_PRIVATE (plugin)->io_data; NMOpenvpnPluginIOData *io_data = NM_OPENVPN_PLUGIN_GET_PRIVATE (plugin)->io_data;
gboolean again = TRUE, success = TRUE; gboolean again = TRUE;
char *str = NULL, *auth, *buf; char *str = NULL, *auth, *buf;
gsize written; gsize written;
@ -471,11 +502,8 @@ openvpn_watch_cb (GPid pid, gint status, gpointer user_data)
} }
static const char * static const char *
get_connection_type (GHashTable *properties) validate_connection_type (const char *ctype)
{ {
const char *ctype;
ctype = g_hash_table_lookup (properties, NM_OPENVPN_KEY_CONNECTION_TYPE);
if (ctype) { if (ctype) {
if ( !strcmp (ctype, NM_OPENVPN_CONTYPE_TLS) if ( !strcmp (ctype, NM_OPENVPN_CONTYPE_TLS)
|| !strcmp (ctype, NM_OPENVPN_CONTYPE_STATIC_KEY) || !strcmp (ctype, NM_OPENVPN_CONTYPE_STATIC_KEY)
@ -483,7 +511,6 @@ get_connection_type (GHashTable *properties)
|| !strcmp (ctype, NM_OPENVPN_CONTYPE_PASSWORD_TLS)) || !strcmp (ctype, NM_OPENVPN_CONTYPE_PASSWORD_TLS))
return ctype; return ctype;
} }
return NULL; return NULL;
} }
@ -543,8 +570,7 @@ add_openvpn_arg_int (GPtrArray *args, const char *arg)
static gboolean static gboolean
nm_openvpn_start_openvpn_binary (NMOpenvpnPlugin *plugin, nm_openvpn_start_openvpn_binary (NMOpenvpnPlugin *plugin,
GHashTable *properties, NMSettingVPN *s_vpn,
GHashTable *secrets,
const char *default_username, const char *default_username,
GError **error) GError **error)
{ {
@ -565,7 +591,8 @@ nm_openvpn_start_openvpn_binary (NMOpenvpnPlugin *plugin,
return FALSE; return FALSE;
} }
connection_type = get_connection_type (properties); tmp = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_CONNECTION_TYPE);
connection_type = validate_connection_type (tmp);
if (!connection_type) { if (!connection_type) {
g_set_error (error, g_set_error (error,
NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR,
@ -578,13 +605,13 @@ nm_openvpn_start_openvpn_binary (NMOpenvpnPlugin *plugin,
args = g_ptr_array_new (); args = g_ptr_array_new ();
add_openvpn_arg (args, openvpn_binary); add_openvpn_arg (args, openvpn_binary);
tmp = g_hash_table_lookup (properties, NM_OPENVPN_KEY_REMOTE); tmp = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_REMOTE);
if (tmp && strlen (tmp)) { if (tmp && strlen (tmp)) {
add_openvpn_arg (args, "--remote"); add_openvpn_arg (args, "--remote");
add_openvpn_arg (args, tmp); add_openvpn_arg (args, tmp);
} }
tmp = g_hash_table_lookup (properties, NM_OPENVPN_KEY_COMP_LZO); tmp = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_COMP_LZO);
if (tmp && !strcmp (tmp, "yes")) if (tmp && !strcmp (tmp, "yes"))
add_openvpn_arg (args, "--comp-lzo"); add_openvpn_arg (args, "--comp-lzo");
@ -592,7 +619,7 @@ nm_openvpn_start_openvpn_binary (NMOpenvpnPlugin *plugin,
/* Device, either tun or tap */ /* Device, either tun or tap */
add_openvpn_arg (args, "--dev"); add_openvpn_arg (args, "--dev");
tmp = g_hash_table_lookup (properties, NM_OPENVPN_KEY_TAP_DEV); tmp = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_TAP_DEV);
if (tmp && !strcmp (tmp, "yes")) if (tmp && !strcmp (tmp, "yes"))
add_openvpn_arg (args, "tap"); add_openvpn_arg (args, "tap");
else else
@ -600,7 +627,7 @@ nm_openvpn_start_openvpn_binary (NMOpenvpnPlugin *plugin,
/* Protocol, either tcp or udp */ /* Protocol, either tcp or udp */
add_openvpn_arg (args, "--proto"); add_openvpn_arg (args, "--proto");
tmp = g_hash_table_lookup (properties, NM_OPENVPN_KEY_PROTO_TCP); tmp = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_PROTO_TCP);
if (tmp && !strcmp (tmp, "yes")) if (tmp && !strcmp (tmp, "yes"))
add_openvpn_arg (args, "tcp-client"); add_openvpn_arg (args, "tcp-client");
else else
@ -608,7 +635,7 @@ nm_openvpn_start_openvpn_binary (NMOpenvpnPlugin *plugin,
/* Port */ /* Port */
add_openvpn_arg (args, "--port"); add_openvpn_arg (args, "--port");
tmp = g_hash_table_lookup (properties, NM_OPENVPN_KEY_PORT); tmp = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_PORT);
if (tmp && strlen (tmp)) { if (tmp && strlen (tmp)) {
if (!add_openvpn_arg_int (args, tmp)) { if (!add_openvpn_arg_int (args, tmp)) {
g_set_error (error, g_set_error (error,
@ -625,19 +652,19 @@ nm_openvpn_start_openvpn_binary (NMOpenvpnPlugin *plugin,
} }
/* Cipher */ /* Cipher */
tmp = g_hash_table_lookup (properties, NM_OPENVPN_KEY_CIPHER); tmp = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_CIPHER);
if (tmp && strlen (tmp)) { if (tmp && strlen (tmp)) {
add_openvpn_arg (args, "--cipher"); add_openvpn_arg (args, "--cipher");
add_openvpn_arg (args, tmp); add_openvpn_arg (args, tmp);
} }
/* TA */ /* TA */
tmp = g_hash_table_lookup (properties, NM_OPENVPN_KEY_TA); tmp = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_TA);
if (tmp && strlen (tmp)) { if (tmp && strlen (tmp)) {
add_openvpn_arg (args, "--tls-auth"); add_openvpn_arg (args, "--tls-auth");
add_openvpn_arg (args, tmp); add_openvpn_arg (args, tmp);
tmp = g_hash_table_lookup (properties, NM_OPENVPN_KEY_TA_DIR); tmp = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_TA_DIR);
if (tmp && strlen (tmp)) if (tmp && strlen (tmp))
add_openvpn_arg (args, tmp); add_openvpn_arg (args, tmp);
} }
@ -677,37 +704,37 @@ nm_openvpn_start_openvpn_binary (NMOpenvpnPlugin *plugin,
if (!strcmp (connection_type, NM_OPENVPN_CONTYPE_TLS)) { if (!strcmp (connection_type, NM_OPENVPN_CONTYPE_TLS)) {
add_openvpn_arg (args, "--client"); add_openvpn_arg (args, "--client");
tmp = g_hash_table_lookup (properties, NM_OPENVPN_KEY_CA); tmp = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_CA);
if (tmp && strlen (tmp)) { if (tmp && strlen (tmp)) {
add_openvpn_arg (args, "--ca"); add_openvpn_arg (args, "--ca");
add_openvpn_arg (args, tmp); add_openvpn_arg (args, tmp);
} }
tmp = g_hash_table_lookup (properties, NM_OPENVPN_KEY_CERT); tmp = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_CERT);
if (tmp && strlen (tmp)) { if (tmp && strlen (tmp)) {
add_openvpn_arg (args, "--cert"); add_openvpn_arg (args, "--cert");
add_openvpn_arg (args, tmp); add_openvpn_arg (args, tmp);
} }
tmp = g_hash_table_lookup (properties, NM_OPENVPN_KEY_KEY); tmp = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_KEY);
if (tmp && strlen (tmp)) { if (tmp && strlen (tmp)) {
add_openvpn_arg (args, "--key"); add_openvpn_arg (args, "--key");
add_openvpn_arg (args, tmp); add_openvpn_arg (args, tmp);
} }
} else if (!strcmp (connection_type, NM_OPENVPN_CONTYPE_STATIC_KEY)) { } else if (!strcmp (connection_type, NM_OPENVPN_CONTYPE_STATIC_KEY)) {
tmp = g_hash_table_lookup (properties, NM_OPENVPN_KEY_STATIC_KEY); tmp = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_STATIC_KEY);
if (tmp && strlen (tmp)) { if (tmp && strlen (tmp)) {
add_openvpn_arg (args, "--secret"); add_openvpn_arg (args, "--secret");
add_openvpn_arg (args, tmp); add_openvpn_arg (args, tmp);
tmp = g_hash_table_lookup (properties, NM_OPENVPN_KEY_STATIC_KEY_DIRECTION); tmp = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_STATIC_KEY_DIRECTION);
if (tmp && strlen (tmp)) if (tmp && strlen (tmp))
add_openvpn_arg (args, tmp); add_openvpn_arg (args, tmp);
} }
add_openvpn_arg (args, "--ifconfig"); add_openvpn_arg (args, "--ifconfig");
tmp = g_hash_table_lookup (properties, NM_OPENVPN_KEY_LOCAL_IP); tmp = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_LOCAL_IP);
if (!tmp) { if (!tmp) {
/* Insufficient data (FIXME: this should really be detected when validating the properties */ /* Insufficient data (FIXME: this should really be detected when validating the properties */
g_set_error (error, g_set_error (error,
@ -720,7 +747,7 @@ nm_openvpn_start_openvpn_binary (NMOpenvpnPlugin *plugin,
} }
add_openvpn_arg (args, tmp); add_openvpn_arg (args, tmp);
tmp = g_hash_table_lookup (properties, NM_OPENVPN_KEY_REMOTE_IP); tmp = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_REMOTE_IP);
if (!tmp) { if (!tmp) {
/* Insufficient data (FIXME: this should really be detected when validating the properties */ /* Insufficient data (FIXME: this should really be detected when validating the properties */
g_set_error (error, g_set_error (error,
@ -738,7 +765,7 @@ nm_openvpn_start_openvpn_binary (NMOpenvpnPlugin *plugin,
/* Use user/path authentication */ /* Use user/path authentication */
add_openvpn_arg (args, "--auth-user-pass"); add_openvpn_arg (args, "--auth-user-pass");
tmp = g_hash_table_lookup (properties, NM_OPENVPN_KEY_CA); tmp = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_CA);
if (tmp && strlen (tmp)) { if (tmp && strlen (tmp)) {
add_openvpn_arg (args, "--ca"); add_openvpn_arg (args, "--ca");
add_openvpn_arg (args, tmp); add_openvpn_arg (args, tmp);
@ -746,19 +773,19 @@ nm_openvpn_start_openvpn_binary (NMOpenvpnPlugin *plugin,
} else if (!strcmp (connection_type, NM_OPENVPN_CONTYPE_PASSWORD_TLS)) { } else if (!strcmp (connection_type, NM_OPENVPN_CONTYPE_PASSWORD_TLS)) {
add_openvpn_arg (args, "--client"); add_openvpn_arg (args, "--client");
tmp = g_hash_table_lookup (properties, NM_OPENVPN_KEY_CA); tmp = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_CA);
if (tmp && strlen (tmp)) { if (tmp && strlen (tmp)) {
add_openvpn_arg (args, "--ca"); add_openvpn_arg (args, "--ca");
add_openvpn_arg (args, tmp); add_openvpn_arg (args, tmp);
} }
tmp = g_hash_table_lookup (properties, NM_OPENVPN_KEY_CERT); tmp = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_CERT);
if (tmp && strlen (tmp)) { if (tmp && strlen (tmp)) {
add_openvpn_arg (args, "--cert"); add_openvpn_arg (args, "--cert");
add_openvpn_arg (args, tmp); add_openvpn_arg (args, tmp);
} }
tmp = g_hash_table_lookup (properties, NM_OPENVPN_KEY_KEY); tmp = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_KEY);
if (tmp && strlen (tmp)) { if (tmp && strlen (tmp)) {
add_openvpn_arg (args, "--key"); add_openvpn_arg (args, "--key");
add_openvpn_arg (args, tmp); add_openvpn_arg (args, tmp);
@ -805,16 +832,16 @@ nm_openvpn_start_openvpn_binary (NMOpenvpnPlugin *plugin,
io_data = g_new0 (NMOpenvpnPluginIOData, 1); io_data = g_new0 (NMOpenvpnPluginIOData, 1);
tmp = g_hash_table_lookup (properties, NM_OPENVPN_KEY_USERNAME); tmp = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_USERNAME);
io_data->username = tmp ? g_strdup (tmp) : NULL; io_data->username = tmp ? g_strdup (tmp) : NULL;
/* Use the default username if it wasn't overridden by the user */ /* Use the default username if it wasn't overridden by the user */
if (!io_data->username && default_username) if (!io_data->username && default_username)
io_data->username = g_strdup (default_username); io_data->username = g_strdup (default_username);
tmp = g_hash_table_lookup (secrets, NM_OPENVPN_KEY_PASSWORD); tmp = nm_setting_vpn_get_secret (s_vpn, NM_OPENVPN_KEY_PASSWORD);
io_data->password = tmp ? g_strdup (tmp) : NULL; io_data->password = tmp ? g_strdup (tmp) : NULL;
tmp = g_hash_table_lookup (secrets, NM_OPENVPN_KEY_CERTPASS); tmp = nm_setting_vpn_get_secret (s_vpn, NM_OPENVPN_KEY_CERTPASS);
io_data->priv_key_pass = tmp ? g_strdup (tmp) : NULL; io_data->priv_key_pass = tmp ? g_strdup (tmp) : NULL;
priv->io_data = io_data; priv->io_data = io_data;
@ -832,6 +859,8 @@ real_connect (NMVPNPlugin *plugin,
{ {
NMSettingVPN *s_vpn; NMSettingVPN *s_vpn;
const char *connection_type; const char *connection_type;
const char *user_name;
const char *tmp;
s_vpn = NM_SETTING_VPN (nm_connection_get_setting (connection, NM_TYPE_SETTING_VPN)); s_vpn = NM_SETTING_VPN (nm_connection_get_setting (connection, NM_TYPE_SETTING_VPN));
if (!s_vpn) { if (!s_vpn) {
@ -843,12 +872,14 @@ real_connect (NMVPNPlugin *plugin,
return FALSE; return FALSE;
} }
connection_type = get_connection_type (s_vpn->data); user_name = nm_setting_vpn_get_user_name (s_vpn);
tmp = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_CONNECTION_TYPE);
connection_type = validate_connection_type (tmp);
/* Need a username for any password-based connection types */ /* Need a username for any password-based connection types */
if ( !strcmp (connection_type, NM_OPENVPN_CONTYPE_PASSWORD_TLS) if ( !strcmp (connection_type, NM_OPENVPN_CONTYPE_PASSWORD_TLS)
|| !strcmp (connection_type, NM_OPENVPN_CONTYPE_PASSWORD)) { || !strcmp (connection_type, NM_OPENVPN_CONTYPE_PASSWORD)) {
if (!s_vpn->user_name && !g_hash_table_lookup (s_vpn->data, NM_OPENVPN_KEY_USERNAME)) { if (!user_name && !nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_USERNAME)) {
g_set_error (error, g_set_error (error,
NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR,
NM_VPN_PLUGIN_ERROR_CONNECTION_INVALID, NM_VPN_PLUGIN_ERROR_CONNECTION_INVALID,
@ -858,22 +889,18 @@ real_connect (NMVPNPlugin *plugin,
} }
} }
/* Validate the properties and secrets */ /* Validate the properties */
if (!nm_openvpn_properties_validate (s_vpn->data, error)) if (!nm_openvpn_properties_validate (s_vpn, error))
return FALSE; return FALSE;
/* Static Key doesn't need secrets; the rest do */ /* Static Key doesn't need secrets; the rest do */
if (strcmp (connection_type, NM_OPENVPN_CONTYPE_STATIC_KEY)) { if (strcmp (connection_type, NM_OPENVPN_CONTYPE_STATIC_KEY)) {
if (!nm_openvpn_properties_validate (s_vpn->secrets, error)) if (!nm_openvpn_secrets_validate (s_vpn, error))
return FALSE; return FALSE;
} }
/* Finally try to start OpenVPN */ /* Finally try to start OpenVPN */
if (!nm_openvpn_start_openvpn_binary (NM_OPENVPN_PLUGIN (plugin), if (!nm_openvpn_start_openvpn_binary (NM_OPENVPN_PLUGIN (plugin), s_vpn, user_name, error))
s_vpn->data,
s_vpn->secrets,
s_vpn->user_name,
error))
return FALSE; return FALSE;
return TRUE; return TRUE;
@ -888,6 +915,7 @@ real_need_secrets (NMVPNPlugin *plugin,
NMSettingVPN *s_vpn; NMSettingVPN *s_vpn;
const char *connection_type; const char *connection_type;
gboolean need_secrets = FALSE; gboolean need_secrets = FALSE;
const char *tmp;
g_return_val_if_fail (NM_IS_VPN_PLUGIN (plugin), FALSE); g_return_val_if_fail (NM_IS_VPN_PLUGIN (plugin), FALSE);
g_return_val_if_fail (NM_IS_CONNECTION (connection), FALSE); g_return_val_if_fail (NM_IS_CONNECTION (connection), FALSE);
@ -902,21 +930,23 @@ real_need_secrets (NMVPNPlugin *plugin,
return FALSE; return FALSE;
} }
connection_type = get_connection_type (s_vpn->data); tmp = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_CONNECTION_TYPE);
connection_type = validate_connection_type (tmp);
if (!strcmp (connection_type, NM_OPENVPN_CONTYPE_PASSWORD_TLS)) { if (!strcmp (connection_type, NM_OPENVPN_CONTYPE_PASSWORD_TLS)) {
/* Will require a password and maybe private key password */ /* Will require a password and maybe private key password */
if (!g_hash_table_lookup (s_vpn->secrets, NM_OPENVPN_KEY_CERTPASS)) if (!nm_setting_vpn_get_secret (s_vpn, NM_OPENVPN_KEY_CERTPASS))
need_secrets = TRUE; need_secrets = TRUE;
if (!g_hash_table_lookup (s_vpn->secrets, NM_OPENVPN_KEY_PASSWORD)) if (!nm_setting_vpn_get_secret (s_vpn, NM_OPENVPN_KEY_PASSWORD))
need_secrets = TRUE; need_secrets = TRUE;
} else if (!strcmp (connection_type, NM_OPENVPN_CONTYPE_PASSWORD)) { } else if (!strcmp (connection_type, NM_OPENVPN_CONTYPE_PASSWORD)) {
/* Will require a password */ /* Will require a password */
if (!g_hash_table_lookup (s_vpn->secrets, NM_OPENVPN_KEY_PASSWORD)) if (!nm_setting_vpn_get_secret (s_vpn, NM_OPENVPN_KEY_PASSWORD))
need_secrets = TRUE; need_secrets = TRUE;
} else if (!strcmp (connection_type, NM_OPENVPN_CONTYPE_TLS)) { } else if (!strcmp (connection_type, NM_OPENVPN_CONTYPE_TLS)) {
/* May require private key password */ /* May require private key password */
if (!g_hash_table_lookup (s_vpn->secrets, NM_OPENVPN_KEY_CERTPASS)) if (!nm_setting_vpn_get_secret (s_vpn, NM_OPENVPN_KEY_CERTPASS))
need_secrets = TRUE; need_secrets = TRUE;
} }

View file

@ -171,7 +171,7 @@ main (int argc, char *argv[])
if (password) { if (password) {
memset (password, 0, strlen (password)); memset (password, 0, strlen (password));
g_free (password); gnome_keyring_memory_free (password);
} }
exit_status = 0; exit_status = 0;

View file

@ -70,16 +70,15 @@ static const char *advanced_keys[] = {
}; };
static void static void
copy_values (gpointer key, gpointer data, gpointer user_data) copy_values (const char *key, const char *value, gpointer user_data)
{ {
GHashTable *hash = (GHashTable *) user_data; GHashTable *hash = (GHashTable *) user_data;
const char **i; const char **i;
for (i = &advanced_keys[0]; *i; i++) { for (i = &advanced_keys[0]; *i; i++) {
if (strcmp ((const char *) key, *i)) if (strcmp (key, *i))
continue; continue;
g_hash_table_insert (hash, g_strdup (key), g_strdup (value));
g_hash_table_insert (hash, g_strdup ((const char *) key), g_strdup ((const char *) data));
} }
} }
@ -93,9 +92,7 @@ advanced_dialog_new_hash_from_connection (NMConnection *connection,
hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
s_vpn = (NMSettingVPN *) nm_connection_get_setting (connection, NM_TYPE_SETTING_VPN); s_vpn = (NMSettingVPN *) nm_connection_get_setting (connection, NM_TYPE_SETTING_VPN);
if (s_vpn && s_vpn->data) nm_setting_vpn_foreach_data_item (s_vpn, copy_values, hash);
g_hash_table_foreach (s_vpn->data, copy_values, hash);
return hash; return hash;
} }

View file

@ -128,8 +128,6 @@ check_validity (PptpPluginUiWidget *self, GError **error)
PptpPluginUiWidgetPrivate *priv = PPTP_PLUGIN_UI_WIDGET_GET_PRIVATE (self); PptpPluginUiWidgetPrivate *priv = PPTP_PLUGIN_UI_WIDGET_GET_PRIVATE (self);
GtkWidget *widget; GtkWidget *widget;
const char *str; const char *str;
GtkTreeModel *model;
GtkTreeIter iter;
widget = glade_xml_get_widget (priv->xml, "gateway_entry"); widget = glade_xml_get_widget (priv->xml, "gateway_entry");
str = gtk_entry_get_text (GTK_ENTRY (widget)); str = gtk_entry_get_text (GTK_ENTRY (widget));
@ -153,8 +151,6 @@ stuff_changed_cb (GtkWidget *widget, gpointer user_data)
static void static void
advanced_dialog_close_cb (GtkWidget *dialog, gpointer user_data) advanced_dialog_close_cb (GtkWidget *dialog, gpointer user_data)
{ {
PptpPluginUiWidget *self = PPTP_PLUGIN_UI_WIDGET (user_data);
gtk_widget_hide (dialog); gtk_widget_hide (dialog);
/* gtk_widget_destroy() will remove the window from the window group */ /* gtk_widget_destroy() will remove the window from the window group */
gtk_widget_destroy (dialog); gtk_widget_destroy (dialog);
@ -189,7 +185,7 @@ advanced_button_clicked_cb (GtkWidget *button, gpointer user_data)
{ {
PptpPluginUiWidget *self = PPTP_PLUGIN_UI_WIDGET (user_data); PptpPluginUiWidget *self = PPTP_PLUGIN_UI_WIDGET (user_data);
PptpPluginUiWidgetPrivate *priv = PPTP_PLUGIN_UI_WIDGET_GET_PRIVATE (self); PptpPluginUiWidgetPrivate *priv = PPTP_PLUGIN_UI_WIDGET_GET_PRIVATE (self);
GtkWidget *dialog, *toplevel, *widget; GtkWidget *dialog, *toplevel;
toplevel = gtk_widget_get_toplevel (priv->widget); toplevel = gtk_widget_get_toplevel (priv->widget);
g_return_if_fail (GTK_WIDGET_TOPLEVEL (toplevel)); g_return_if_fail (GTK_WIDGET_TOPLEVEL (toplevel));
@ -251,7 +247,7 @@ fill_password (GladeXML *xml,
if (s_vpn) { if (s_vpn) {
const gchar *tmp = NULL; const gchar *tmp = NULL;
tmp = g_hash_table_lookup (s_vpn->secrets, password_type); tmp = nm_setting_vpn_get_secret (s_vpn, password_type);
if (tmp) if (tmp)
password = gnome_keyring_memory_strdup (tmp); password = gnome_keyring_memory_strdup (tmp);
} }
@ -299,9 +295,6 @@ init_plugin_ui (PptpPluginUiWidget *self, NMConnection *connection, GError **err
PptpPluginUiWidgetPrivate *priv = PPTP_PLUGIN_UI_WIDGET_GET_PRIVATE (self); PptpPluginUiWidgetPrivate *priv = PPTP_PLUGIN_UI_WIDGET_GET_PRIVATE (self);
NMSettingVPN *s_vpn; NMSettingVPN *s_vpn;
GtkWidget *widget; GtkWidget *widget;
GtkListStore *store;
GtkTreeIter iter;
int active = -1;
const char *value; const char *value;
s_vpn = (NMSettingVPN *) nm_connection_get_setting (connection, NM_TYPE_SETTING_VPN); s_vpn = (NMSettingVPN *) nm_connection_get_setting (connection, NM_TYPE_SETTING_VPN);
@ -313,7 +306,7 @@ init_plugin_ui (PptpPluginUiWidget *self, NMConnection *connection, GError **err
return FALSE; return FALSE;
gtk_size_group_add_widget (priv->group, widget); gtk_size_group_add_widget (priv->group, widget);
if (s_vpn) { if (s_vpn) {
value = g_hash_table_lookup (s_vpn->data, NM_PPTP_KEY_GATEWAY); value = nm_setting_vpn_get_data_item (s_vpn, NM_PPTP_KEY_GATEWAY);
if (value && strlen (value)) if (value && strlen (value))
gtk_entry_set_text (GTK_ENTRY (widget), value); gtk_entry_set_text (GTK_ENTRY (widget), value);
} }
@ -324,7 +317,7 @@ init_plugin_ui (PptpPluginUiWidget *self, NMConnection *connection, GError **err
return FALSE; return FALSE;
gtk_size_group_add_widget (priv->group, widget); gtk_size_group_add_widget (priv->group, widget);
if (s_vpn) { if (s_vpn) {
value = g_hash_table_lookup (s_vpn->data, NM_PPTP_KEY_USER); value = nm_setting_vpn_get_data_item (s_vpn, NM_PPTP_KEY_USER);
if (value && strlen (value)) if (value && strlen (value))
gtk_entry_set_text (GTK_ENTRY (widget), value); gtk_entry_set_text (GTK_ENTRY (widget), value);
} }
@ -335,7 +328,7 @@ init_plugin_ui (PptpPluginUiWidget *self, NMConnection *connection, GError **err
return FALSE; return FALSE;
gtk_size_group_add_widget (priv->group, widget); gtk_size_group_add_widget (priv->group, widget);
if (s_vpn) { if (s_vpn) {
value = g_hash_table_lookup (s_vpn->data, NM_PPTP_KEY_DOMAIN); value = nm_setting_vpn_get_data_item (s_vpn, NM_PPTP_KEY_DOMAIN);
if (value && strlen (value)) if (value && strlen (value))
gtk_entry_set_text (GTK_ENTRY (widget), value); gtk_entry_set_text (GTK_ENTRY (widget), value);
} }
@ -367,9 +360,9 @@ get_widget (NMVpnPluginUiWidgetInterface *iface)
static void static void
hash_copy_advanced (gpointer key, gpointer data, gpointer user_data) hash_copy_advanced (gpointer key, gpointer data, gpointer user_data)
{ {
GHashTable *hash = (GHashTable *) user_data; NMSettingVPN *s_vpn = NM_SETTING_VPN (user_data);
g_hash_table_insert (hash, g_strdup ((const char *) key), g_strdup ((const char *) data)); nm_setting_vpn_add_data_item (s_vpn, (const char *) key, (const char *) data);
} }
static gboolean static gboolean
@ -382,41 +375,38 @@ update_connection (NMVpnPluginUiWidgetInterface *iface,
NMSettingVPN *s_vpn; NMSettingVPN *s_vpn;
GtkWidget *widget; GtkWidget *widget;
const char *str; const char *str;
GtkTreeModel *model;
GtkTreeIter iter;
gboolean valid = FALSE; gboolean valid = FALSE;
if (!check_validity (self, error)) if (!check_validity (self, error))
return FALSE; return FALSE;
s_vpn = NM_SETTING_VPN (nm_setting_vpn_new ()); s_vpn = NM_SETTING_VPN (nm_setting_vpn_new ());
s_vpn->service_type = g_strdup (NM_DBUS_SERVICE_PPTP); g_object_set (s_vpn, NM_SETTING_VPN_SERVICE_TYPE, NM_DBUS_SERVICE_PPTP, NULL);
/* Gateway */ /* Gateway */
widget = glade_xml_get_widget (priv->xml, "gateway_entry"); widget = glade_xml_get_widget (priv->xml, "gateway_entry");
str = gtk_entry_get_text (GTK_ENTRY (widget)); str = gtk_entry_get_text (GTK_ENTRY (widget));
if (str && strlen (str)) if (str && strlen (str))
g_hash_table_insert (s_vpn->data, g_strdup (NM_PPTP_KEY_GATEWAY), g_strdup (str)); nm_setting_vpn_add_data_item (s_vpn, NM_PPTP_KEY_GATEWAY, str);
/* Username */ /* Username */
widget = glade_xml_get_widget (priv->xml, "user_entry"); widget = glade_xml_get_widget (priv->xml, "user_entry");
str = gtk_entry_get_text (GTK_ENTRY (widget)); str = gtk_entry_get_text (GTK_ENTRY (widget));
if (str && strlen (str)) if (str && strlen (str))
g_hash_table_insert (s_vpn->data, g_strdup (NM_PPTP_KEY_USER), g_strdup (str)); nm_setting_vpn_add_data_item (s_vpn, NM_PPTP_KEY_USER, str);
/* Domain */ /* Domain */
widget = glade_xml_get_widget (priv->xml, "domain_entry"); widget = glade_xml_get_widget (priv->xml, "domain_entry");
str = gtk_entry_get_text (GTK_ENTRY (widget)); str = gtk_entry_get_text (GTK_ENTRY (widget));
if (str && strlen (str)) if (str && strlen (str))
g_hash_table_insert (s_vpn->data, g_strdup (NM_PPTP_KEY_DOMAIN), g_strdup (str)); nm_setting_vpn_add_data_item (s_vpn, NM_PPTP_KEY_DOMAIN, str);
if (priv->advanced) if (priv->advanced)
g_hash_table_foreach (priv->advanced, hash_copy_advanced, s_vpn->data); g_hash_table_foreach (priv->advanced, hash_copy_advanced, s_vpn);
nm_connection_add_setting (connection, NM_SETTING (s_vpn)); nm_connection_add_setting (connection, NM_SETTING (s_vpn));
valid = TRUE; valid = TRUE;
done:
return valid; return valid;
} }

View file

@ -239,7 +239,7 @@ nm_pptp_ppp_service_cache_credentials (NMPptpPppService *self,
memset (priv->password, 0, sizeof (priv->password)); memset (priv->password, 0, sizeof (priv->password));
s_vpn = (NMSettingVPN *) nm_connection_get_setting (connection, NM_TYPE_SETTING_VPN); s_vpn = (NMSettingVPN *) nm_connection_get_setting (connection, NM_TYPE_SETTING_VPN);
if (!s_vpn || !s_vpn->secrets || !s_vpn->data) { if (!s_vpn) {
g_set_error (error, g_set_error (error,
NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR,
NM_VPN_PLUGIN_ERROR_CONNECTION_INVALID, NM_VPN_PLUGIN_ERROR_CONNECTION_INVALID,
@ -249,8 +249,9 @@ nm_pptp_ppp_service_cache_credentials (NMPptpPppService *self,
} }
/* Username; try PPTP specific username first, then generic username */ /* Username; try PPTP specific username first, then generic username */
username = g_hash_table_lookup (s_vpn->data, NM_PPTP_KEY_USER); username = nm_setting_vpn_get_data_item (s_vpn, NM_PPTP_KEY_USER);
if (username && strlen (username)) { if (username && strlen (username)) {
/* FIXME: This check makes about 0 sense. */
if (!username || !strlen (username)) { if (!username || !strlen (username)) {
g_set_error (error, g_set_error (error,
NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR,
@ -260,7 +261,7 @@ nm_pptp_ppp_service_cache_credentials (NMPptpPppService *self,
return FALSE; return FALSE;
} }
} else { } else {
username = s_vpn->user_name; username = nm_setting_vpn_get_user_name (s_vpn);
if (!username || !strlen (username)) { if (!username || !strlen (username)) {
g_set_error (error, g_set_error (error,
NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR,
@ -271,7 +272,7 @@ nm_pptp_ppp_service_cache_credentials (NMPptpPppService *self,
} }
} }
password = g_hash_table_lookup (s_vpn->secrets, NM_PPTP_KEY_PASSWORD); password = nm_setting_vpn_get_secret (s_vpn, NM_PPTP_KEY_PASSWORD);
if (!password || !strlen (password)) { if (!password || !strlen (password)) {
g_set_error (error, g_set_error (error,
NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR,
@ -281,7 +282,7 @@ nm_pptp_ppp_service_cache_credentials (NMPptpPppService *self,
return FALSE; return FALSE;
} }
domain = g_hash_table_lookup (s_vpn->data, NM_PPTP_KEY_DOMAIN); domain = nm_setting_vpn_get_data_item (s_vpn, NM_PPTP_KEY_DOMAIN);
if (domain && strlen (domain)) if (domain && strlen (domain))
memcpy (priv->domain, domain, strlen (domain)); memcpy (priv->domain, domain, strlen (domain));
@ -373,7 +374,6 @@ typedef struct {
static ValidProperty valid_properties[] = { static ValidProperty valid_properties[] = {
{ NM_PPTP_KEY_GATEWAY, G_TYPE_STRING, TRUE }, { NM_PPTP_KEY_GATEWAY, G_TYPE_STRING, TRUE },
{ NM_PPTP_KEY_USER, G_TYPE_STRING, FALSE }, { NM_PPTP_KEY_USER, G_TYPE_STRING, FALSE },
{ NM_PPTP_KEY_PASSWORD, G_TYPE_STRING, FALSE },
{ NM_PPTP_KEY_DOMAIN, G_TYPE_STRING, FALSE }, { NM_PPTP_KEY_DOMAIN, G_TYPE_STRING, FALSE },
{ NM_PPTP_KEY_REFUSE_EAP, G_TYPE_BOOLEAN, FALSE }, { NM_PPTP_KEY_REFUSE_EAP, G_TYPE_BOOLEAN, FALSE },
{ NM_PPTP_KEY_REFUSE_PAP, G_TYPE_BOOLEAN, FALSE }, { NM_PPTP_KEY_REFUSE_PAP, G_TYPE_BOOLEAN, FALSE },
@ -392,6 +392,11 @@ static ValidProperty valid_properties[] = {
{ NULL, G_TYPE_NONE, FALSE } { NULL, G_TYPE_NONE, FALSE }
}; };
static ValidProperty valid_secrets[] = {
{ NM_PPTP_KEY_PASSWORD, G_TYPE_STRING, FALSE },
{ NULL, G_TYPE_NONE, FALSE }
};
static gboolean static gboolean
validate_gateway (const char *gateway) validate_gateway (const char *gateway)
{ {
@ -410,88 +415,97 @@ validate_gateway (const char *gateway)
return TRUE; return TRUE;
} }
typedef struct ValidateInfo {
ValidProperty *table;
GError **error;
gboolean have_items;
} ValidateInfo;
static void static void
validate_one_property (gpointer key, gpointer value, gpointer user_data) validate_one_property (const char *key, const char *value, gpointer user_data)
{ {
GError **error = (GError **) user_data; ValidateInfo *info = (ValidateInfo *) user_data;
int i; int i;
if (*error) if (*(info->error))
return; return;
info->have_items = TRUE;
/* 'name' is the setting name; always allowed but unused */ /* 'name' is the setting name; always allowed but unused */
if (!strcmp ((char *) key, NM_SETTING_NAME)) if (!strcmp (key, NM_SETTING_NAME))
return; return;
for (i = 0; valid_properties[i].name; i++) { for (i = 0; info->table[i].name; i++) {
ValidProperty prop = valid_properties[i]; ValidProperty prop = info->table[i];
long int tmp; long int tmp;
if (strcmp (prop.name, (char *) key)) if (strcmp (prop.name, key))
continue; continue;
switch (prop.type) { switch (prop.type) {
case G_TYPE_STRING: case G_TYPE_STRING:
if ( !strcmp (prop.name, NM_PPTP_KEY_GATEWAY) if ( !strcmp (prop.name, NM_PPTP_KEY_GATEWAY)
&& !validate_gateway (value)) { && !validate_gateway (value)) {
g_set_error (error, g_set_error (info->error,
NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR,
NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS, NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS,
"invalid gateway '%s'", "invalid gateway '%s'",
(const char *) key); key);
return; return;
} }
return; /* valid */ return; /* valid */
case G_TYPE_UINT: case G_TYPE_UINT:
errno = 0; errno = 0;
tmp = strtol ((char *) value, NULL, 10); tmp = strtol (value, NULL, 10);
if (errno == 0) if (errno == 0)
return; /* valid */ return; /* valid */
g_set_error (error, g_set_error (info->error,
NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR,
NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS, NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS,
"invalid integer property '%s'", "invalid integer property '%s'",
(const char *) key); key);
break; break;
case G_TYPE_BOOLEAN: case G_TYPE_BOOLEAN:
if (!strcmp ((char *) value, "yes") || !strcmp ((char *) value, "no")) if (!strcmp (value, "yes") || !strcmp (value, "no"))
return; /* valid */ return; /* valid */
g_set_error (error, g_set_error (info->error,
NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR,
NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS, NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS,
"invalid boolean property '%s' (not yes or no)", "invalid boolean property '%s' (not yes or no)",
(const char *) key); key);
break; break;
default: default:
g_set_error (error, g_set_error (info->error,
NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR,
NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS, NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS,
"unhandled property '%s' type %s", "unhandled property '%s' type %s",
(const char *) key, g_type_name (prop.type)); key, g_type_name (prop.type));
break; break;
} }
} }
/* Did not find the property from valid_properties or the type did not match */ /* Did not find the property from valid_properties or the type did not match */
if (!valid_properties[i].name) { if (!info->table[i].name) {
g_set_error (error, g_set_error (info->error,
NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR,
NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS, NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS,
"property '%s' invalid or not supported", "property '%s' invalid or not supported",
(const char *) key); key);
} }
} }
static gboolean static gboolean
nm_pptp_properties_validate (GHashTable *properties, nm_pptp_properties_validate (NMSettingVPN *s_vpn,
gboolean check_required,
GError **error) GError **error)
{ {
ValidateInfo info = { &valid_properties[0], error, FALSE };
int i; int i;
if (g_hash_table_size (properties) < 1) { nm_setting_vpn_foreach_data_item (s_vpn, validate_one_property, &info);
if (!info.have_items) {
g_set_error (error, g_set_error (error,
NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR,
NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS, NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS,
@ -500,34 +514,49 @@ nm_pptp_properties_validate (GHashTable *properties,
return FALSE; return FALSE;
} }
g_hash_table_foreach (properties, validate_one_property, error);
if (*error) if (*error)
return FALSE; return FALSE;
if (check_required) { /* Ensure required properties exist */
/* Ensure required properties exist */ for (i = 0; valid_properties[i].name; i++) {
for (i = 0; valid_properties[i].name; i++) { ValidProperty prop = valid_properties[i];
ValidProperty prop = valid_properties[i]; const char *value;
const char *value;
if (!prop.required) if (!prop.required)
continue; continue;
value = g_hash_table_lookup (properties, prop.name); value = nm_setting_vpn_get_data_item (s_vpn, prop.name);
if (!value || !strlen (value)) { if (!value || !strlen (value)) {
g_set_error (error, g_set_error (error,
NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR,
NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS, NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS,
"Missing required option '%s'.", "Missing required option '%s'.",
prop.name); prop.name);
return FALSE; return FALSE;
}
} }
} }
return TRUE; return TRUE;
} }
static gboolean
nm_pptp_secrets_validate (NMSettingVPN *s_vpn, GError **error)
{
ValidateInfo info = { &valid_secrets[0], error, FALSE };
nm_setting_vpn_foreach_secret (s_vpn, validate_one_property, &info);
if (!info.have_items) {
g_set_error (error,
NM_VPN_PLUGIN_ERROR,
NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS,
"%s",
"No VPN secrets!");
return FALSE;
}
return *error ? FALSE : TRUE;
}
static void static void
pppd_watch_cb (GPid pid, gint status, gpointer user_data) pppd_watch_cb (GPid pid, gint status, gpointer user_data)
{ {
@ -650,7 +679,6 @@ construct_pppd_args (NMPptpPlugin *plugin,
GPtrArray *args = NULL; GPtrArray *args = NULL;
const char *value, *pptp_binary; const char *value, *pptp_binary;
char *ipparam, *tmp; char *ipparam, *tmp;
gboolean set = FALSE;
pptp_binary = nm_find_pptp (); pptp_binary = nm_find_pptp ();
if (!pptp_binary) { if (!pptp_binary) {
@ -666,7 +694,7 @@ construct_pppd_args (NMPptpPlugin *plugin,
g_ptr_array_add (args, (gpointer) g_strdup (pppd)); g_ptr_array_add (args, (gpointer) g_strdup (pppd));
/* PPTP options */ /* PPTP options */
value = g_hash_table_lookup (s_vpn->data, NM_PPTP_KEY_GATEWAY); value = nm_setting_vpn_get_data_item (s_vpn, NM_PPTP_KEY_GATEWAY);
if (!value || !strlen (value)) { if (!value || !strlen (value)) {
g_set_error (error, g_set_error (error,
NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR,
@ -692,55 +720,55 @@ construct_pppd_args (NMPptpPlugin *plugin,
g_ptr_array_add (args, (gpointer) g_strdup ("noipdefault")); g_ptr_array_add (args, (gpointer) g_strdup ("noipdefault"));
g_ptr_array_add (args, (gpointer) g_strdup ("nodefaultroute")); g_ptr_array_add (args, (gpointer) g_strdup ("nodefaultroute"));
value = g_hash_table_lookup (s_vpn->data, NM_PPTP_KEY_REFUSE_EAP); value = nm_setting_vpn_get_data_item (s_vpn, NM_PPTP_KEY_REFUSE_EAP);
if (value && !strcmp (value, "yes")) if (value && !strcmp (value, "yes"))
g_ptr_array_add (args, (gpointer) g_strdup ("refuse-eap")); g_ptr_array_add (args, (gpointer) g_strdup ("refuse-eap"));
value = g_hash_table_lookup (s_vpn->data, NM_PPTP_KEY_REFUSE_PAP); value = nm_setting_vpn_get_data_item (s_vpn, NM_PPTP_KEY_REFUSE_PAP);
if (value && !strcmp (value, "yes")) if (value && !strcmp (value, "yes"))
g_ptr_array_add (args, (gpointer) g_strdup ("refuse-pap")); g_ptr_array_add (args, (gpointer) g_strdup ("refuse-pap"));
value = g_hash_table_lookup (s_vpn->data, NM_PPTP_KEY_REFUSE_CHAP); value = nm_setting_vpn_get_data_item (s_vpn, NM_PPTP_KEY_REFUSE_CHAP);
if (value && !strcmp (value, "yes")) if (value && !strcmp (value, "yes"))
g_ptr_array_add (args, (gpointer) g_strdup ("refuse-chap")); g_ptr_array_add (args, (gpointer) g_strdup ("refuse-chap"));
value = g_hash_table_lookup (s_vpn->data, NM_PPTP_KEY_REFUSE_MSCHAP); value = nm_setting_vpn_get_data_item (s_vpn, NM_PPTP_KEY_REFUSE_MSCHAP);
if (value && !strcmp (value, "yes")) if (value && !strcmp (value, "yes"))
g_ptr_array_add (args, (gpointer) g_strdup ("refuse-mschap")); g_ptr_array_add (args, (gpointer) g_strdup ("refuse-mschap"));
value = g_hash_table_lookup (s_vpn->data, NM_PPTP_KEY_REFUSE_MSCHAPV2); value = nm_setting_vpn_get_data_item (s_vpn, NM_PPTP_KEY_REFUSE_MSCHAPV2);
if (value && !strcmp (value, "yes")) if (value && !strcmp (value, "yes"))
g_ptr_array_add (args, (gpointer) g_strdup ("refuse-mschap-v2")); g_ptr_array_add (args, (gpointer) g_strdup ("refuse-mschap-v2"));
value = g_hash_table_lookup (s_vpn->data, NM_PPTP_KEY_REQUIRE_MPPE); value = nm_setting_vpn_get_data_item (s_vpn, NM_PPTP_KEY_REQUIRE_MPPE);
if (value && !strcmp (value, "yes")) if (value && !strcmp (value, "yes"))
g_ptr_array_add (args, (gpointer) g_strdup ("require-mppe")); g_ptr_array_add (args, (gpointer) g_strdup ("require-mppe"));
value = g_hash_table_lookup (s_vpn->data, NM_PPTP_KEY_REQUIRE_MPPE_40); value = nm_setting_vpn_get_data_item (s_vpn, NM_PPTP_KEY_REQUIRE_MPPE_40);
if (value && !strcmp (value, "yes")) if (value && !strcmp (value, "yes"))
g_ptr_array_add (args, (gpointer) g_strdup ("require-mppe-40")); g_ptr_array_add (args, (gpointer) g_strdup ("require-mppe-40"));
value = g_hash_table_lookup (s_vpn->data, NM_PPTP_KEY_REQUIRE_MPPE_128); value = nm_setting_vpn_get_data_item (s_vpn, NM_PPTP_KEY_REQUIRE_MPPE_128);
if (value && !strcmp (value, "yes")) if (value && !strcmp (value, "yes"))
g_ptr_array_add (args, (gpointer) g_strdup ("require-mppe-128")); g_ptr_array_add (args, (gpointer) g_strdup ("require-mppe-128"));
value = g_hash_table_lookup (s_vpn->data, NM_PPTP_KEY_MPPE_STATEFUL); value = nm_setting_vpn_get_data_item (s_vpn, NM_PPTP_KEY_MPPE_STATEFUL);
if (value && !strcmp (value, "yes")) if (value && !strcmp (value, "yes"))
g_ptr_array_add (args, (gpointer) g_strdup ("mppe-stateful")); g_ptr_array_add (args, (gpointer) g_strdup ("mppe-stateful"));
value = g_hash_table_lookup (s_vpn->data, NM_PPTP_KEY_NOBSDCOMP); value = nm_setting_vpn_get_data_item (s_vpn, NM_PPTP_KEY_NOBSDCOMP);
if (value && !strcmp (value, "yes")) if (value && !strcmp (value, "yes"))
g_ptr_array_add (args, (gpointer) g_strdup ("nobsdcomp")); g_ptr_array_add (args, (gpointer) g_strdup ("nobsdcomp"));
value = g_hash_table_lookup (s_vpn->data, NM_PPTP_KEY_NODEFLATE); value = nm_setting_vpn_get_data_item (s_vpn, NM_PPTP_KEY_NODEFLATE);
if (value && !strcmp (value, "yes")) if (value && !strcmp (value, "yes"))
g_ptr_array_add (args, (gpointer) g_strdup ("nodeflate")); g_ptr_array_add (args, (gpointer) g_strdup ("nodeflate"));
value = g_hash_table_lookup (s_vpn->data, NM_PPTP_KEY_NO_VJ_COMP); value = nm_setting_vpn_get_data_item (s_vpn, NM_PPTP_KEY_NO_VJ_COMP);
if (value && !strcmp (value, "yes")) if (value && !strcmp (value, "yes"))
g_ptr_array_add (args, (gpointer) g_strdup ("novj")); g_ptr_array_add (args, (gpointer) g_strdup ("novj"));
value = g_hash_table_lookup (s_vpn->data, NM_PPTP_KEY_LCP_ECHO_FAILURE); value = nm_setting_vpn_get_data_item (s_vpn, NM_PPTP_KEY_LCP_ECHO_FAILURE);
if (value && strlen (value)) { if (value && strlen (value)) {
long int tmp_int; long int tmp_int;
@ -760,7 +788,7 @@ construct_pppd_args (NMPptpPlugin *plugin,
g_ptr_array_add (args, (gpointer) g_strdup ("0")); g_ptr_array_add (args, (gpointer) g_strdup ("0"));
} }
value = g_hash_table_lookup (s_vpn->data, NM_PPTP_KEY_LCP_ECHO_INTERVAL); value = nm_setting_vpn_get_data_item (s_vpn, NM_PPTP_KEY_LCP_ECHO_INTERVAL);
if (value && strlen (value)) { if (value && strlen (value)) {
long int tmp_int; long int tmp_int;
@ -890,10 +918,10 @@ real_connect (NMVPNPlugin *plugin,
s_vpn = NM_SETTING_VPN (nm_connection_get_setting (connection, NM_TYPE_SETTING_VPN)); s_vpn = NM_SETTING_VPN (nm_connection_get_setting (connection, NM_TYPE_SETTING_VPN));
g_assert (s_vpn); g_assert (s_vpn);
if (!nm_pptp_properties_validate (s_vpn->data, TRUE, error)) if (!nm_pptp_properties_validate (s_vpn, error))
return FALSE; return FALSE;
if (!nm_pptp_properties_validate (s_vpn->secrets, FALSE, error)) if (!nm_pptp_secrets_validate (s_vpn, error))
return FALSE; return FALSE;
/* Start our pppd plugin helper service */ /* Start our pppd plugin helper service */
@ -937,16 +965,8 @@ real_need_secrets (NMVPNPlugin *plugin,
g_return_val_if_fail (NM_IS_CONNECTION (connection), FALSE); g_return_val_if_fail (NM_IS_CONNECTION (connection), FALSE);
s_vpn = NM_SETTING_VPN (nm_connection_get_setting (connection, NM_TYPE_SETTING_VPN)); s_vpn = NM_SETTING_VPN (nm_connection_get_setting (connection, NM_TYPE_SETTING_VPN));
if (!s_vpn || !s_vpn->secrets) {
g_set_error (error,
NM_VPN_PLUGIN_ERROR,
NM_VPN_PLUGIN_ERROR_CONNECTION_INVALID,
"%s",
"Could not process the request because the VPN connection settings were invalid.");
return FALSE;
}
if (!g_hash_table_lookup (s_vpn->secrets, NM_PPTP_KEY_PASSWORD)) { if (!nm_setting_vpn_get_secret (s_vpn, NM_PPTP_KEY_PASSWORD)) {
*setting_name = NM_SETTING_VPN_SETTING_NAME; *setting_name = NM_SETTING_VPN_SETTING_NAME;
return TRUE; return TRUE;
} }

View file

@ -177,11 +177,11 @@ fill_vpn_passwords (VpncPluginUiWidget *self, NMConnection *connection)
if (nm_connection_get_scope (connection) == NM_CONNECTION_SCOPE_SYSTEM) { if (nm_connection_get_scope (connection) == NM_CONNECTION_SCOPE_SYSTEM) {
s_vpn = (NMSettingVPN *) nm_connection_get_setting (connection, NM_TYPE_SETTING_VPN); s_vpn = (NMSettingVPN *) nm_connection_get_setting (connection, NM_TYPE_SETTING_VPN);
if (s_vpn) { if (s_vpn) {
tmp = g_hash_table_lookup (s_vpn->secrets, NM_VPNC_KEY_XAUTH_PASSWORD); tmp = nm_setting_vpn_get_secret (s_vpn, NM_VPNC_KEY_XAUTH_PASSWORD);
if (tmp) if (tmp)
password = gnome_keyring_memory_strdup (tmp); password = gnome_keyring_memory_strdup (tmp);
tmp = g_hash_table_lookup (s_vpn->secrets, NM_VPNC_KEY_SECRET); tmp = nm_setting_vpn_get_secret (s_vpn, NM_VPNC_KEY_SECRET);
if (tmp) if (tmp)
group_password = gnome_keyring_memory_strdup (tmp); group_password = gnome_keyring_memory_strdup (tmp);
} }
@ -245,7 +245,7 @@ init_plugin_ui (VpncPluginUiWidget *self, NMConnection *connection, GError **err
GtkWidget *widget; GtkWidget *widget;
GtkListStore *store; GtkListStore *store;
GtkTreeIter iter; GtkTreeIter iter;
char *value; const char *value;
int active = -1; int active = -1;
const char *natt_mode = NULL; const char *natt_mode = NULL;
@ -257,7 +257,7 @@ init_plugin_ui (VpncPluginUiWidget *self, NMConnection *connection, GError **err
g_return_val_if_fail (widget != NULL, FALSE); g_return_val_if_fail (widget != NULL, FALSE);
gtk_size_group_add_widget (priv->group, GTK_WIDGET (widget)); gtk_size_group_add_widget (priv->group, GTK_WIDGET (widget));
if (s_vpn) { if (s_vpn) {
value = g_hash_table_lookup (s_vpn->data, NM_VPNC_KEY_GATEWAY); value = nm_setting_vpn_get_data_item (s_vpn, NM_VPNC_KEY_GATEWAY);
if (value && strlen (value)) if (value && strlen (value))
gtk_entry_set_text (GTK_ENTRY (widget), value); gtk_entry_set_text (GTK_ENTRY (widget), value);
} }
@ -267,7 +267,7 @@ init_plugin_ui (VpncPluginUiWidget *self, NMConnection *connection, GError **err
g_return_val_if_fail (widget != NULL, FALSE); g_return_val_if_fail (widget != NULL, FALSE);
gtk_size_group_add_widget (priv->group, GTK_WIDGET (widget)); gtk_size_group_add_widget (priv->group, GTK_WIDGET (widget));
if (s_vpn) { if (s_vpn) {
value = g_hash_table_lookup (s_vpn->data, NM_VPNC_KEY_ID); value = nm_setting_vpn_get_data_item (s_vpn, NM_VPNC_KEY_ID);
if (value && strlen (value)) if (value && strlen (value))
gtk_entry_set_text (GTK_ENTRY (widget), value); gtk_entry_set_text (GTK_ENTRY (widget), value);
} }
@ -285,7 +285,7 @@ init_plugin_ui (VpncPluginUiWidget *self, NMConnection *connection, GError **err
gtk_list_store_append (store, &iter); gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter, 0, _("Weak (use with caution)"), -1); gtk_list_store_set (store, &iter, 0, _("Weak (use with caution)"), -1);
if (s_vpn && (active < 0)) { if (s_vpn && (active < 0)) {
value = g_hash_table_lookup (s_vpn->data, NM_VPNC_KEY_SINGLE_DES); value = nm_setting_vpn_get_data_item (s_vpn, NM_VPNC_KEY_SINGLE_DES);
if (value && !strcmp (value, "yes")) if (value && !strcmp (value, "yes"))
active = 1; active = 1;
} }
@ -293,7 +293,7 @@ init_plugin_ui (VpncPluginUiWidget *self, NMConnection *connection, GError **err
gtk_list_store_append (store, &iter); gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter, 0, _("None (completely insecure)"), -1); gtk_list_store_set (store, &iter, 0, _("None (completely insecure)"), -1);
if (s_vpn && (active < 0)) { if (s_vpn && (active < 0)) {
value = g_hash_table_lookup (s_vpn->data, NM_VPNC_KEY_NO_ENCRYPTION); value = nm_setting_vpn_get_data_item (s_vpn, NM_VPNC_KEY_NO_ENCRYPTION);
if (value && !strcmp (value, "yes")) if (value && !strcmp (value, "yes"))
active = 2; active = 2;
} }
@ -307,7 +307,7 @@ init_plugin_ui (VpncPluginUiWidget *self, NMConnection *connection, GError **err
g_return_val_if_fail (widget != NULL, FALSE); g_return_val_if_fail (widget != NULL, FALSE);
gtk_size_group_add_widget (priv->group, GTK_WIDGET (widget)); gtk_size_group_add_widget (priv->group, GTK_WIDGET (widget));
if (s_vpn) { if (s_vpn) {
value = g_hash_table_lookup (s_vpn->data, NM_VPNC_KEY_XAUTH_USER); value = nm_setting_vpn_get_data_item (s_vpn, NM_VPNC_KEY_XAUTH_USER);
if (value && strlen (value)) if (value && strlen (value))
gtk_entry_set_text (GTK_ENTRY (widget), value); gtk_entry_set_text (GTK_ENTRY (widget), value);
} }
@ -317,7 +317,7 @@ init_plugin_ui (VpncPluginUiWidget *self, NMConnection *connection, GError **err
g_return_val_if_fail (widget != NULL, FALSE); g_return_val_if_fail (widget != NULL, FALSE);
gtk_size_group_add_widget (priv->group, GTK_WIDGET (widget)); gtk_size_group_add_widget (priv->group, GTK_WIDGET (widget));
if (s_vpn) { if (s_vpn) {
value = g_hash_table_lookup (s_vpn->data, NM_VPNC_KEY_DOMAIN); value = nm_setting_vpn_get_data_item (s_vpn, NM_VPNC_KEY_DOMAIN);
if (value && strlen (value)) if (value && strlen (value))
gtk_entry_set_text (GTK_ENTRY (widget), value); gtk_entry_set_text (GTK_ENTRY (widget), value);
} }
@ -326,7 +326,7 @@ init_plugin_ui (VpncPluginUiWidget *self, NMConnection *connection, GError **err
active = -1; active = -1;
store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_STRING); store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_STRING);
if (s_vpn) if (s_vpn)
natt_mode = g_hash_table_lookup (s_vpn->data, NM_VPNC_KEY_NAT_TRAVERSAL_MODE); natt_mode = nm_setting_vpn_get_data_item (s_vpn, NM_VPNC_KEY_NAT_TRAVERSAL_MODE);
gtk_list_store_append (store, &iter); gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter, 0, _("NAT-T (default)"), 1, NM_VPNC_NATT_MODE_NATT, -1); gtk_list_store_set (store, &iter, 0, _("NAT-T (default)"), 1, NM_VPNC_NATT_MODE_NATT, -1);
@ -360,7 +360,7 @@ init_plugin_ui (VpncPluginUiWidget *self, NMConnection *connection, GError **err
widget = glade_xml_get_widget (priv->xml, "disable_dpd_checkbutton"); widget = glade_xml_get_widget (priv->xml, "disable_dpd_checkbutton");
g_return_val_if_fail (widget != NULL, FALSE); g_return_val_if_fail (widget != NULL, FALSE);
if (s_vpn) { if (s_vpn) {
value = g_hash_table_lookup (s_vpn->data, NM_VPNC_KEY_DPD_IDLE_TIMEOUT); value = nm_setting_vpn_get_data_item (s_vpn, NM_VPNC_KEY_DPD_IDLE_TIMEOUT);
if (value) { if (value) {
long int tmp; long int tmp;
@ -412,53 +412,37 @@ update_connection (NMVpnPluginUiWidgetInterface *iface,
return FALSE; return FALSE;
s_vpn = NM_SETTING_VPN (nm_setting_vpn_new ()); s_vpn = NM_SETTING_VPN (nm_setting_vpn_new ());
s_vpn->service_type = g_strdup (NM_DBUS_SERVICE_VPNC); g_object_set (s_vpn, NM_SETTING_VPN_SERVICE_TYPE, NM_DBUS_SERVICE_VPNC, NULL);
/* Gateway */ /* Gateway */
widget = glade_xml_get_widget (priv->xml, "gateway_entry"); widget = glade_xml_get_widget (priv->xml, "gateway_entry");
str = (char *) gtk_entry_get_text (GTK_ENTRY (widget)); str = (char *) gtk_entry_get_text (GTK_ENTRY (widget));
if (str && strlen (str)) { if (str && strlen (str))
g_hash_table_insert (s_vpn->data, nm_setting_vpn_add_data_item (s_vpn, NM_VPNC_KEY_GATEWAY, str);
g_strdup (NM_VPNC_KEY_GATEWAY),
g_strdup (str));
}
/* Group name */ /* Group name */
widget = glade_xml_get_widget (priv->xml, "group_entry"); widget = glade_xml_get_widget (priv->xml, "group_entry");
str = (char *) gtk_entry_get_text (GTK_ENTRY (widget)); str = (char *) gtk_entry_get_text (GTK_ENTRY (widget));
if (str && strlen (str)) { if (str && strlen (str))
g_hash_table_insert (s_vpn->data, nm_setting_vpn_add_data_item (s_vpn, NM_VPNC_KEY_ID, str);
g_strdup (NM_VPNC_KEY_ID),
g_strdup (str));
}
widget = glade_xml_get_widget (priv->xml, "user_entry"); widget = glade_xml_get_widget (priv->xml, "user_entry");
str = (char *) gtk_entry_get_text (GTK_ENTRY (widget)); str = (char *) gtk_entry_get_text (GTK_ENTRY (widget));
if (str && strlen (str)) { if (str && strlen (str))
g_hash_table_insert (s_vpn->data, nm_setting_vpn_add_data_item (s_vpn, NM_VPNC_KEY_XAUTH_USER, str);
g_strdup (NM_VPNC_KEY_XAUTH_USER),
g_strdup (str));
}
widget = glade_xml_get_widget (priv->xml, "domain_entry"); widget = glade_xml_get_widget (priv->xml, "domain_entry");
str = (char *) gtk_entry_get_text (GTK_ENTRY (widget)); str = (char *) gtk_entry_get_text (GTK_ENTRY (widget));
if (str && strlen (str)) { if (str && strlen (str))
g_hash_table_insert (s_vpn->data, nm_setting_vpn_add_data_item (s_vpn, NM_VPNC_KEY_DOMAIN, str);
g_strdup (NM_VPNC_KEY_DOMAIN),
g_strdup (str));
}
widget = glade_xml_get_widget (priv->xml, "encryption_combo"); widget = glade_xml_get_widget (priv->xml, "encryption_combo");
switch (gtk_combo_box_get_active (GTK_COMBO_BOX (widget))) { switch (gtk_combo_box_get_active (GTK_COMBO_BOX (widget))) {
case ENC_TYPE_WEAK: case ENC_TYPE_WEAK:
g_hash_table_insert (s_vpn->data, nm_setting_vpn_add_data_item (s_vpn, NM_VPNC_KEY_SINGLE_DES, "yes");
g_strdup (NM_VPNC_KEY_SINGLE_DES),
g_strdup ("yes"));
break; break;
case ENC_TYPE_NONE: case ENC_TYPE_NONE:
g_hash_table_insert (s_vpn->data, nm_setting_vpn_add_data_item (s_vpn, NM_VPNC_KEY_NO_ENCRYPTION, "yes");
g_strdup (NM_VPNC_KEY_NO_ENCRYPTION),
g_strdup ("yes"));
break; break;
case ENC_TYPE_SECURE: case ENC_TYPE_SECURE:
default: default:
@ -471,29 +455,22 @@ update_connection (NMVpnPluginUiWidgetInterface *iface,
const char *mode; const char *mode;
gtk_tree_model_get (model, &iter, 1, &mode, -1); gtk_tree_model_get (model, &iter, 1, &mode, -1);
g_hash_table_insert (s_vpn->data, nm_setting_vpn_add_data_item (s_vpn, NM_VPNC_KEY_NAT_TRAVERSAL_MODE, mode);
g_strdup (NM_VPNC_KEY_NAT_TRAVERSAL_MODE), } else
g_strdup (mode)); nm_setting_vpn_add_data_item (s_vpn, NM_VPNC_KEY_NAT_TRAVERSAL_MODE, NM_VPNC_NATT_MODE_NATT);
} else {
g_hash_table_insert (s_vpn->data,
g_strdup (NM_VPNC_KEY_NAT_TRAVERSAL_MODE),
g_strdup (NM_VPNC_NATT_MODE_NATT));
}
widget = glade_xml_get_widget (priv->xml, "disable_dpd_checkbutton"); widget = glade_xml_get_widget (priv->xml, "disable_dpd_checkbutton");
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget))) { if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget))) {
g_hash_table_insert (s_vpn->data, nm_setting_vpn_add_data_item (s_vpn, NM_VPNC_KEY_DPD_IDLE_TIMEOUT, "0");
g_strdup (NM_VPNC_KEY_DPD_IDLE_TIMEOUT),
g_strdup ("0"));
} else { } else {
/* If DPD was disabled and now the user wishes to enable it, just /* If DPD was disabled and now the user wishes to enable it, just
* don't pass the DPD_IDLE_TIMEOUT option to vpnc and thus use the * don't pass the DPD_IDLE_TIMEOUT option to vpnc and thus use the
* default DPD idle time. Otherwise keep the original DPD idle timeout. * default DPD idle time. Otherwise keep the original DPD idle timeout.
*/ */
if (priv->orig_dpd_timeout >= 10) { if (priv->orig_dpd_timeout >= 10) {
g_hash_table_insert (s_vpn->data, char *tmp = g_strdup_printf ("%d", priv->orig_dpd_timeout);
g_strdup (NM_VPNC_KEY_DPD_IDLE_TIMEOUT), nm_setting_vpn_add_data_item (s_vpn, NM_VPNC_KEY_DPD_IDLE_TIMEOUT, tmp);
g_strdup_printf ("%d", priv->orig_dpd_timeout)); g_free (tmp);
} }
} }
@ -504,20 +481,14 @@ update_connection (NMVpnPluginUiWidgetInterface *iface,
/* User password */ /* User password */
widget = glade_xml_get_widget (priv->xml, "user_password_entry"); widget = glade_xml_get_widget (priv->xml, "user_password_entry");
str = (char *) gtk_entry_get_text (GTK_ENTRY (widget)); str = (char *) gtk_entry_get_text (GTK_ENTRY (widget));
if (str && strlen (str)) { if (str && strlen (str))
g_hash_table_insert (s_vpn->secrets, nm_setting_vpn_add_secret (s_vpn, NM_VPNC_KEY_XAUTH_PASSWORD, str);
g_strdup (NM_VPNC_KEY_XAUTH_PASSWORD),
g_strdup (str));
}
/* Group password */ /* Group password */
widget = glade_xml_get_widget (priv->xml, "group_password_entry"); widget = glade_xml_get_widget (priv->xml, "group_password_entry");
str = (char *) gtk_entry_get_text (GTK_ENTRY (widget)); str = (char *) gtk_entry_get_text (GTK_ENTRY (widget));
if (str && strlen (str)) { if (str && strlen (str))
g_hash_table_insert (s_vpn->secrets, nm_setting_vpn_add_secret (s_vpn, NM_VPNC_KEY_SECRET, str);
g_strdup (NM_VPNC_KEY_SECRET),
g_strdup (str));
}
} }
nm_connection_add_setting (connection, NM_SETTING (s_vpn)); nm_connection_add_setting (connection, NM_SETTING (s_vpn));
@ -728,7 +699,7 @@ import (NMVpnPluginUiInterface *iface, const char *path, GError **error)
nm_connection_add_setting (connection, NM_SETTING (s_con)); nm_connection_add_setting (connection, NM_SETTING (s_con));
s_vpn = NM_SETTING_VPN (nm_setting_vpn_new ()); s_vpn = NM_SETTING_VPN (nm_setting_vpn_new ());
s_vpn->service_type = g_strdup (VPNC_PLUGIN_SERVICE); g_object_set (s_vpn, NM_SETTING_VPN_SERVICE_TYPE, NM_DBUS_SERVICE_VPNC, NULL);
nm_connection_add_setting (connection, NM_SETTING (s_vpn)); nm_connection_add_setting (connection, NM_SETTING (s_vpn));
/* Connection name */ /* Connection name */
@ -743,7 +714,7 @@ import (NMVpnPluginUiInterface *iface, const char *path, GError **error)
/* Gateway */ /* Gateway */
if ((buf = pcf_file_lookup_value (pcf, "main", "Host"))) if ((buf = pcf_file_lookup_value (pcf, "main", "Host")))
g_hash_table_insert (s_vpn->data, g_strdup (NM_VPNC_KEY_GATEWAY), g_strdup (buf)); nm_setting_vpn_add_data_item (s_vpn, NM_VPNC_KEY_GATEWAY, buf);
else { else {
g_set_error (error, 0, 0, "does not look like a %s VPN connection (no Host)", g_set_error (error, 0, 0, "does not look like a %s VPN connection (no Host)",
VPNC_PLUGIN_NAME); VPNC_PLUGIN_NAME);
@ -753,7 +724,7 @@ import (NMVpnPluginUiInterface *iface, const char *path, GError **error)
/* Group name */ /* Group name */
if ((buf = pcf_file_lookup_value (pcf, "main", "GroupName"))) if ((buf = pcf_file_lookup_value (pcf, "main", "GroupName")))
g_hash_table_insert (s_vpn->data, g_strdup (NM_VPNC_KEY_ID), g_strdup (buf)); nm_setting_vpn_add_data_item (s_vpn, NM_VPNC_KEY_ID, buf);
else { else {
g_set_error (error, 0, 0, "does not look like a %s VPN connection (no GroupName)", g_set_error (error, 0, 0, "does not look like a %s VPN connection (no GroupName)",
VPNC_PLUGIN_NAME); VPNC_PLUGIN_NAME);
@ -766,23 +737,23 @@ import (NMVpnPluginUiInterface *iface, const char *path, GError **error)
buf = pcf_file_lookup_value (pcf, "main", "UserName"); buf = pcf_file_lookup_value (pcf, "main", "UserName");
have_value = buf == NULL ? FALSE : strlen (buf) > 0; have_value = buf == NULL ? FALSE : strlen (buf) > 0;
if (have_value) if (have_value)
g_hash_table_insert (s_vpn->data, g_strdup (NM_VPNC_KEY_XAUTH_USER), g_strdup (buf)); nm_setting_vpn_add_data_item (s_vpn, NM_VPNC_KEY_XAUTH_USER, buf);
buf = pcf_file_lookup_value (pcf, "main", "NTDomain"); buf = pcf_file_lookup_value (pcf, "main", "NTDomain");
have_value = buf == NULL ? FALSE : strlen (buf) > 0; have_value = buf == NULL ? FALSE : strlen (buf) > 0;
if (have_value) if (have_value)
g_hash_table_insert (s_vpn->data, g_strdup (NM_VPNC_KEY_DOMAIN), g_strdup (buf)); nm_setting_vpn_add_data_item (s_vpn, NM_VPNC_KEY_DOMAIN, buf);
buf = pcf_file_lookup_value (pcf, "main", "SingleDES"); buf = pcf_file_lookup_value (pcf, "main", "SingleDES");
have_value = (buf == NULL ? FALSE : strcmp (buf, "0") != 0); have_value = (buf == NULL ? FALSE : strcmp (buf, "0") != 0);
if (have_value) if (have_value)
g_hash_table_insert (s_vpn->data, g_strdup (NM_VPNC_KEY_SINGLE_DES), g_strdup ("yes")); nm_setting_vpn_add_data_item (s_vpn, NM_VPNC_KEY_SINGLE_DES, "yes");
/* Default is enabled, only disabled if explicit EnableNat=0 exists */ /* Default is enabled, only disabled if explicit EnableNat=0 exists */
buf = pcf_file_lookup_value (pcf, "main", "EnableNat"); buf = pcf_file_lookup_value (pcf, "main", "EnableNat");
have_value = (buf ? strncmp (buf, "0", 1) == 0 : FALSE); have_value = (buf ? strncmp (buf, "0", 1) == 0 : FALSE);
if (have_value) if (have_value)
g_hash_table_insert (s_vpn->data, g_strdup (NM_VPNC_KEY_NAT_TRAVERSAL_MODE), g_strdup (NM_VPNC_NATT_MODE_NATT)); nm_setting_vpn_add_data_item (s_vpn, NM_VPNC_KEY_NAT_TRAVERSAL_MODE, NM_VPNC_NATT_MODE_NATT);
if ((buf = pcf_file_lookup_value (pcf, "main", "PeerTimeout"))) { if ((buf = pcf_file_lookup_value (pcf, "main", "PeerTimeout"))) {
long int val; long int val;
@ -790,9 +761,9 @@ import (NMVpnPluginUiInterface *iface, const char *path, GError **error)
errno = 0; errno = 0;
val = strtol (buf, NULL, 10); val = strtol (buf, NULL, 10);
if ((errno == 0) && ((val == 0) || ((val >= 10) && (val <= 86400)))) { if ((errno == 0) && ((val == 0) || ((val >= 10) && (val <= 86400)))) {
g_hash_table_insert (s_vpn->data, char *tmp = g_strdup_printf ("%d", (gint) val);
g_strdup (NM_VPNC_KEY_DPD_IDLE_TIMEOUT), nm_setting_vpn_add_data_item (s_vpn, NM_VPNC_KEY_DPD_IDLE_TIMEOUT, tmp);
g_strdup_printf ("%d", (gint) val)); g_free (tmp);
} }
} }
@ -855,10 +826,6 @@ export (NMVpnPluginUiInterface *iface,
s_ip4 = (NMSettingIP4Config *) nm_connection_get_setting (connection, NM_TYPE_SETTING_IP4_CONFIG); s_ip4 = (NMSettingIP4Config *) nm_connection_get_setting (connection, NM_TYPE_SETTING_IP4_CONFIG);
s_vpn = (NMSettingVPN *) nm_connection_get_setting (connection, NM_TYPE_SETTING_VPN); s_vpn = (NMSettingVPN *) nm_connection_get_setting (connection, NM_TYPE_SETTING_VPN);
if (!s_vpn || !s_vpn->data) {
g_set_error (error, 0, 0, "connection was incomplete");
return FALSE;
}
f = fopen (path, "w"); f = fopen (path, "w");
if (!f) { if (!f) {
@ -866,7 +833,7 @@ export (NMVpnPluginUiInterface *iface,
return FALSE; return FALSE;
} }
value = g_hash_table_lookup (s_vpn->data, NM_VPNC_KEY_GATEWAY); value = nm_setting_vpn_get_data_item (s_vpn, NM_VPNC_KEY_GATEWAY);
if (value && strlen (value)) if (value && strlen (value))
gateway = value; gateway = value;
else { else {
@ -874,7 +841,7 @@ export (NMVpnPluginUiInterface *iface,
goto done; goto done;
} }
value = g_hash_table_lookup (s_vpn->data, NM_VPNC_KEY_ID); value = nm_setting_vpn_get_data_item (s_vpn, NM_VPNC_KEY_ID);
if (value && strlen (value)) if (value && strlen (value))
groupname = value; groupname = value;
else { else {
@ -882,23 +849,23 @@ export (NMVpnPluginUiInterface *iface,
goto done; goto done;
} }
value = g_hash_table_lookup (s_vpn->data, NM_VPNC_KEY_XAUTH_USER); value = nm_setting_vpn_get_data_item (s_vpn, NM_VPNC_KEY_XAUTH_USER);
if (value && strlen (value)) if (value && strlen (value))
username = value; username = value;
value = g_hash_table_lookup (s_vpn->data, NM_VPNC_KEY_DOMAIN); value = nm_setting_vpn_get_data_item (s_vpn, NM_VPNC_KEY_DOMAIN);
if (value && strlen (value)) if (value && strlen (value))
domain = value; domain = value;
value = g_hash_table_lookup (s_vpn->data, NM_VPNC_KEY_SINGLE_DES); value = nm_setting_vpn_get_data_item (s_vpn, NM_VPNC_KEY_SINGLE_DES);
if (value && !strcmp (value, "yes")) if (value && !strcmp (value, "yes"))
singledes = TRUE; singledes = TRUE;
value = g_hash_table_lookup (s_vpn->data, NM_VPNC_KEY_NAT_TRAVERSAL_MODE); value = nm_setting_vpn_get_data_item (s_vpn, NM_VPNC_KEY_NAT_TRAVERSAL_MODE);
if (value && strlen (value) && strcmp (value, NM_VPNC_NATT_MODE_NONE)) if (value && strlen (value) && strcmp (value, NM_VPNC_NATT_MODE_NONE))
enablenat = TRUE; enablenat = TRUE;
value = g_hash_table_lookup (s_vpn->data, NM_VPNC_KEY_DPD_IDLE_TIMEOUT); value = nm_setting_vpn_get_data_item (s_vpn, NM_VPNC_KEY_DPD_IDLE_TIMEOUT);
if (value && strlen (value)) if (value && strlen (value))
peertimeout = value; peertimeout = value;

View file

@ -45,9 +45,7 @@ typedef struct {
static ValidProperty valid_properties[] = { static ValidProperty valid_properties[] = {
{ NM_VPNC_KEY_GATEWAY, G_TYPE_STRING, 0, 0 }, { NM_VPNC_KEY_GATEWAY, G_TYPE_STRING, 0, 0 },
{ NM_VPNC_KEY_ID, G_TYPE_STRING, 0, 0 }, { NM_VPNC_KEY_ID, G_TYPE_STRING, 0, 0 },
{ NM_VPNC_KEY_SECRET, G_TYPE_STRING, 0, 0 },
{ NM_VPNC_KEY_XAUTH_USER, G_TYPE_STRING, 0, 0 }, { NM_VPNC_KEY_XAUTH_USER, G_TYPE_STRING, 0, 0 },
{ NM_VPNC_KEY_XAUTH_PASSWORD, G_TYPE_STRING, 0, 0 },
{ NM_VPNC_KEY_DOMAIN, G_TYPE_STRING, 0, 0 }, { NM_VPNC_KEY_DOMAIN, G_TYPE_STRING, 0, 0 },
{ NM_VPNC_KEY_DHGROUP, G_TYPE_STRING, 0, 0 }, { NM_VPNC_KEY_DHGROUP, G_TYPE_STRING, 0, 0 },
{ NM_VPNC_KEY_PERFECT_FORWARD, G_TYPE_STRING, 0, 0 }, { NM_VPNC_KEY_PERFECT_FORWARD, G_TYPE_STRING, 0, 0 },
@ -62,24 +60,38 @@ static ValidProperty valid_properties[] = {
{ NULL, G_TYPE_NONE, 0, 0 } { NULL, G_TYPE_NONE, 0, 0 }
}; };
static ValidProperty valid_secrets[] = {
{ NM_VPNC_KEY_SECRET, G_TYPE_STRING, 0, 0 },
{ NM_VPNC_KEY_XAUTH_PASSWORD, G_TYPE_STRING, 0, 0 },
{ NULL, G_TYPE_NONE, 0, 0 }
};
typedef struct ValidateInfo {
ValidProperty *table;
GError **error;
gboolean have_items;
} ValidateInfo;
static void static void
validate_one_property (gpointer key, gpointer value, gpointer user_data) validate_one_property (const char *key, const char *value, gpointer user_data)
{ {
GError **error = (GError **) user_data; ValidateInfo *info = (ValidateInfo *) user_data;
int i; int i;
if (*error) if (*(info->error))
return; return;
info->have_items = TRUE;
/* 'name' is the setting name; always allowed but unused */ /* 'name' is the setting name; always allowed but unused */
if (!strcmp ((char *) key, NM_SETTING_NAME)) if (!strcmp (key, NM_SETTING_NAME))
return; return;
for (i = 0; valid_properties[i].name; i++) { for (i = 0; info->table[i].name; i++) {
ValidProperty prop = valid_properties[i]; ValidProperty prop = info->table[i];
long int tmp; long int tmp;
if (strcmp (prop.name, (char *) key)) if (strcmp (prop.name, key))
continue; continue;
switch (prop.type) { switch (prop.type) {
@ -87,50 +99,53 @@ validate_one_property (gpointer key, gpointer value, gpointer user_data)
return; /* valid */ return; /* valid */
case G_TYPE_INT: case G_TYPE_INT:
errno = 0; errno = 0;
tmp = strtol ((char *) value, NULL, 10); tmp = strtol (value, NULL, 10);
if (errno == 0 && tmp >= prop.int_min && tmp <= prop.int_max) if (errno == 0 && tmp >= prop.int_min && tmp <= prop.int_max)
return; /* valid */ return; /* valid */
g_set_error (error, g_set_error (info->error,
NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR,
NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS, NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS,
"invalid integer property '%s' or out of range [%d -> %d]", "invalid integer property '%s' or out of range [%d -> %d]",
(const char *) key, prop.int_min, prop.int_max); key, prop.int_min, prop.int_max);
break; break;
case G_TYPE_BOOLEAN: case G_TYPE_BOOLEAN:
if (!strcmp ((char *) value, "yes") || !strcmp ((char *) value, "no")) if (!strcmp (value, "yes") || !strcmp (value, "no"))
return; /* valid */ return; /* valid */
g_set_error (error, g_set_error (info->error,
NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR,
NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS, NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS,
"invalid boolean property '%s' (not yes or no)", "invalid boolean property '%s' (not yes or no)",
(const char *) key); key);
break; break;
default: default:
g_set_error (error, g_set_error (info->error,
NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR,
NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS, NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS,
"unhandled property '%s' type %s", "unhandled property '%s' type %s",
(const char *) key, g_type_name (prop.type)); key, g_type_name (prop.type));
break; break;
} }
} }
/* Did not find the property from valid_properties or the type did not match */ /* Did not find the property from valid_properties or the type did not match */
if (!valid_properties[i].name) { if (!info->table[i].name) {
g_set_error (error, g_set_error (info->error,
NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR,
NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS, NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS,
"property '%s' invalid or not supported", "property '%s' invalid or not supported",
(const char *) key); key);
} }
} }
static gboolean static gboolean
nm_vpnc_properties_validate (GHashTable *properties, GError **error) nm_vpnc_properties_validate (NMSettingVPN *s_vpn, GError **error)
{ {
if (g_hash_table_size (properties) < 1) { ValidateInfo info = { &valid_properties[0], error, FALSE };
nm_setting_vpn_foreach_data_item (s_vpn, validate_one_property, &info);
if (!info.have_items) {
g_set_error (error, g_set_error (error,
NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR,
NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS, NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS,
@ -139,7 +154,23 @@ nm_vpnc_properties_validate (GHashTable *properties, GError **error)
return FALSE; return FALSE;
} }
g_hash_table_foreach (properties, validate_one_property, error); return *error ? FALSE : TRUE;
}
static gboolean
nm_vpnc_secrets_validate (NMSettingVPN *s_vpn, GError **error)
{
ValidateInfo info = { &valid_secrets[0], error, FALSE };
nm_setting_vpn_foreach_secret (s_vpn, validate_one_property, &info);
if (!info.have_items) {
g_set_error (error,
NM_VPN_PLUGIN_ERROR,
NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS,
"%s",
"No VPN secrets!");
return FALSE;
}
return *error ? FALSE : TRUE; return *error ? FALSE : TRUE;
} }
@ -257,7 +288,7 @@ typedef struct {
} WriteConfigInfo; } WriteConfigInfo;
static void static void
write_one_property (gpointer key, gpointer value, gpointer user_data) write_one_property (const char *key, const char *value, gpointer user_data)
{ {
WriteConfigInfo *info = (WriteConfigInfo *) user_data; WriteConfigInfo *info = (WriteConfigInfo *) user_data;
GType type = G_TYPE_INVALID; GType type = G_TYPE_INVALID;
@ -271,8 +302,19 @@ write_one_property (gpointer key, gpointer value, gpointer user_data)
ValidProperty prop = valid_properties[i]; ValidProperty prop = valid_properties[i];
if (!strcmp (prop.name, (char *) key)) { if (!strcmp (prop.name, (char *) key)) {
/* Property is ok */ /* Property is ok */
type = prop.type; type = prop.type;
break;
}
}
/* Try the valid secrets table */
for (i = 0; type == G_TYPE_INVALID && valid_secrets[i].name; i++) {
ValidProperty prop = valid_secrets[i];
if (!strcmp (prop.name, (char *) key)) {
/* Property is ok */
type = prop.type;
break; break;
} }
} }
@ -319,14 +361,15 @@ write_one_property (gpointer key, gpointer value, gpointer user_data)
static gboolean static gboolean
nm_vpnc_config_write (gint vpnc_fd, nm_vpnc_config_write (gint vpnc_fd,
const char *default_user_name, NMSettingVPN *s_vpn,
GHashTable *properties,
GHashTable *secrets,
GError **error) GError **error)
{ {
WriteConfigInfo *info; WriteConfigInfo *info;
const char *props_user_name; const char *props_username;
const char *props_natt_mode; const char *props_natt_mode;
const char *default_username;
default_username = nm_setting_vpn_get_user_name (s_vpn);
write_config_option (vpnc_fd, "Script " NM_VPNC_HELPER_PATH "\n"); write_config_option (vpnc_fd, "Script " NM_VPNC_HELPER_PATH "\n");
@ -335,17 +378,17 @@ nm_vpnc_config_write (gint vpnc_fd,
NM_VPNC_UDP_ENCAPSULATION_PORT); NM_VPNC_UDP_ENCAPSULATION_PORT);
/* Fill username if it's not present */ /* Fill username if it's not present */
props_user_name = g_hash_table_lookup (properties, NM_VPNC_KEY_XAUTH_USER); props_username = nm_setting_vpn_get_data_item (s_vpn, NM_VPNC_KEY_XAUTH_USER);
if ( default_user_name if ( default_username
&& strlen (default_user_name) && strlen (default_username)
&& (!props_user_name || !strlen (props_user_name))) { && (!props_username || !strlen (props_username))) {
write_config_option (vpnc_fd, write_config_option (vpnc_fd,
NM_VPNC_KEY_XAUTH_USER " %s\n", NM_VPNC_KEY_XAUTH_USER " %s\n",
default_user_name); default_username);
} }
/* Use NAT-T by default */ /* Use NAT-T by default */
props_natt_mode = g_hash_table_lookup (properties, NM_VPNC_KEY_NAT_TRAVERSAL_MODE); props_natt_mode = nm_setting_vpn_get_data_item (s_vpn, NM_VPNC_KEY_NAT_TRAVERSAL_MODE);
if (!props_natt_mode || !strlen (props_natt_mode)) { if (!props_natt_mode || !strlen (props_natt_mode)) {
write_config_option (vpnc_fd, write_config_option (vpnc_fd,
NM_VPNC_KEY_NAT_TRAVERSAL_MODE " %s\n", NM_VPNC_KEY_NAT_TRAVERSAL_MODE " %s\n",
@ -354,8 +397,8 @@ nm_vpnc_config_write (gint vpnc_fd,
info = g_malloc0 (sizeof (WriteConfigInfo)); info = g_malloc0 (sizeof (WriteConfigInfo));
info->fd = vpnc_fd; info->fd = vpnc_fd;
g_hash_table_foreach (properties, write_one_property, info); nm_setting_vpn_foreach_data_item (s_vpn, write_one_property, info);
g_hash_table_foreach (secrets, write_one_property, info); nm_setting_vpn_foreach_secret (s_vpn, write_one_property, info);
*error = info->error; *error = info->error;
g_free (info); g_free (info);
@ -373,16 +416,17 @@ real_connect (NMVPNPlugin *plugin,
s_vpn = NM_SETTING_VPN (nm_connection_get_setting (connection, NM_TYPE_SETTING_VPN)); s_vpn = NM_SETTING_VPN (nm_connection_get_setting (connection, NM_TYPE_SETTING_VPN));
g_assert (s_vpn); g_assert (s_vpn);
if (!nm_vpnc_properties_validate (s_vpn->data, error))
if (!nm_vpnc_properties_validate (s_vpn, error))
goto out; goto out;
if (!nm_vpnc_properties_validate (s_vpn->secrets, error)) if (!nm_vpnc_secrets_validate (s_vpn, error))
goto out; goto out;
vpnc_fd = nm_vpnc_start_vpnc_binary (NM_VPNC_PLUGIN (plugin), error); vpnc_fd = nm_vpnc_start_vpnc_binary (NM_VPNC_PLUGIN (plugin), error);
if (vpnc_fd < 0) if (vpnc_fd < 0)
goto out; goto out;
if (!nm_vpnc_config_write (vpnc_fd, s_vpn->user_name, s_vpn->data, s_vpn->secrets, error)) if (!nm_vpnc_config_write (vpnc_fd, s_vpn, error))
goto out; goto out;
success = TRUE; success = TRUE;
@ -416,11 +460,11 @@ real_need_secrets (NMVPNPlugin *plugin,
// FIXME: there are some configurations where both passwords are not // FIXME: there are some configurations where both passwords are not
// required. Make sure they work somehow. // required. Make sure they work somehow.
if (!g_hash_table_lookup (s_vpn->secrets, NM_VPNC_KEY_SECRET)) { if (!nm_setting_vpn_get_secret (s_vpn, NM_VPNC_KEY_SECRET)) {
*setting_name = NM_SETTING_VPN_SETTING_NAME; *setting_name = NM_SETTING_VPN_SETTING_NAME;
return TRUE; return TRUE;
} }
if (!g_hash_table_lookup (s_vpn->secrets, NM_VPNC_KEY_XAUTH_PASSWORD)) { if (!nm_setting_vpn_get_secret (s_vpn, NM_VPNC_KEY_XAUTH_PASSWORD)) {
*setting_name = NM_SETTING_VPN_SETTING_NAME; *setting_name = NM_SETTING_VPN_SETTING_NAME;
return TRUE; return TRUE;
} }