1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 2 of the License, or (at your option) any later version.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the
15 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 * Boston, MA 02110-1301 USA.
18 * Copyright 2007 - 2013 Red Hat, Inc.
19 * Copyright 2007 - 2008 Novell, Inc.
22 #include "nm-default.h"
28 #include "nm-setting-vpn.h"
30 #include "nm-utils-private.h"
31 #include "nm-setting-private.h"
34 * SECTION:nm-setting-vpn
35 * @short_description: Describes connection properties for Virtual Private Networks
37 * The #NMSettingVpn object is a #NMSetting subclass that describes properties
38 * necessary for connection to Virtual Private Networks. NetworkManager uses
39 * a plugin architecture to allow easier use of new VPN types, and this
40 * setting abstracts the configuration for those plugins. Since the configuration
41 * options are only known to the VPN plugins themselves, the VPN configuration
42 * options are stored as key/value pairs of strings rather than GObject
46 G_DEFINE_TYPE_WITH_CODE (NMSettingVpn, nm_setting_vpn, NM_TYPE_SETTING,
47 _nm_register_setting (VPN, 1))
48 NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_VPN)
50 #define NM_SETTING_VPN_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_VPN, NMSettingVpnPrivate))
55 /* username of the user requesting this connection, thus
56 * it's really only valid for user connections, and it also
57 * should never be saved out to persistent config.
61 /* Whether the VPN stays up across link changes, until the user
62 * explicitly disconnects it.
66 /* The hash table is created at setting object
67 * init time and should not be replaced. It is
68 * a char * -> char * mapping, and both the key
69 * and value are owned by the hash table, and should
70 * be allocated with functions whose value can be
71 * freed with g_free(). Should not contain secrets.
75 /* The hash table is created at setting object
76 * init time and should not be replaced. It is
77 * a char * -> char * mapping, and both the key
78 * and value are owned by the hash table, and should
79 * be allocated with functions whose value can be
80 * freed with g_free(). Should contain secrets only.
84 /* Timeout for the VPN service to establish the connection */
86 } NMSettingVpnPrivate;
101 * nm_setting_vpn_new:
103 * Creates a new #NMSettingVpn object with default values.
105 * Returns: (transfer full): the new empty #NMSettingVpn object
108 nm_setting_vpn_new (void)
110 return (NMSetting *) g_object_new (NM_TYPE_SETTING_VPN, NULL);
114 * nm_setting_vpn_get_service_type:
115 * @setting: the #NMSettingVpn
117 * Returns the service name of the VPN, which identifies the specific VPN
118 * plugin that should be used to connect to this VPN.
120 * Returns: the VPN plugin's service name
123 nm_setting_vpn_get_service_type (NMSettingVpn *setting)
125 g_return_val_if_fail (NM_IS_SETTING_VPN (setting), NULL);
127 return NM_SETTING_VPN_GET_PRIVATE (setting)->service_type;
131 * nm_setting_vpn_get_user_name:
132 * @setting: the #NMSettingVpn
134 * Returns: the #NMSettingVpn:user-name property of the setting
137 nm_setting_vpn_get_user_name (NMSettingVpn *setting)
139 g_return_val_if_fail (NM_IS_SETTING_VPN (setting), NULL);
141 return NM_SETTING_VPN_GET_PRIVATE (setting)->user_name;
145 * nm_setting_vpn_get_persistent:
146 * @setting: the #NMSettingVpn
148 * Returns: the #NMSettingVpn:persistent property of the setting
151 nm_setting_vpn_get_persistent (NMSettingVpn *setting)
153 g_return_val_if_fail (NM_IS_SETTING_VPN (setting), FALSE);
155 return NM_SETTING_VPN_GET_PRIVATE (setting)->persistent;
159 * nm_setting_vpn_get_num_data_items:
160 * @setting: the #NMSettingVpn
162 * Gets number of key/value pairs of VPN configuration data.
164 * Returns: the number of VPN plugin specific configuration data items
167 nm_setting_vpn_get_num_data_items (NMSettingVpn *setting)
169 g_return_val_if_fail (NM_IS_SETTING_VPN (setting), 0);
171 return g_hash_table_size (NM_SETTING_VPN_GET_PRIVATE (setting)->data);
175 * nm_setting_vpn_add_data_item:
176 * @setting: the #NMSettingVpn
177 * @key: a name that uniquely identifies the given value @item
178 * @item: the value to be referenced by @key
180 * Establishes a relationship between @key and @item internally in the
181 * setting which may be retrieved later. Should not be used to store passwords
182 * or other secrets, which is what nm_setting_vpn_add_secret() is for.
185 nm_setting_vpn_add_data_item (NMSettingVpn *setting,
189 g_return_if_fail (NM_IS_SETTING_VPN (setting));
190 g_return_if_fail (key != NULL);
191 g_return_if_fail (strlen (key) > 0);
192 g_return_if_fail (item != NULL);
193 g_return_if_fail (strlen (item) > 0);
195 g_hash_table_insert (NM_SETTING_VPN_GET_PRIVATE (setting)->data,
196 g_strdup (key), g_strdup (item));
197 g_object_notify (G_OBJECT (setting), NM_SETTING_VPN_DATA);
201 * nm_setting_vpn_get_data_item:
202 * @setting: the #NMSettingVpn
203 * @key: the name of the data item to retrieve
205 * Retrieves the data item of a key/value relationship previously established
206 * by nm_setting_vpn_add_data_item().
208 * Returns: the data item, if any
211 nm_setting_vpn_get_data_item (NMSettingVpn *setting, const char *key)
213 g_return_val_if_fail (NM_IS_SETTING_VPN (setting), NULL);
215 return (const char *) g_hash_table_lookup (NM_SETTING_VPN_GET_PRIVATE (setting)->data, key);
219 * nm_setting_vpn_remove_data_item:
220 * @setting: the #NMSettingVpn
221 * @key: the name of the data item to remove
223 * Deletes a key/value relationship previously established by
224 * nm_setting_vpn_add_data_item().
226 * Returns: %TRUE if the data item was found and removed from the internal list,
227 * %FALSE if it was not.
230 nm_setting_vpn_remove_data_item (NMSettingVpn *setting, const char *key)
234 g_return_val_if_fail (NM_IS_SETTING_VPN (setting), FALSE);
236 found = g_hash_table_remove (NM_SETTING_VPN_GET_PRIVATE (setting)->data, key);
238 g_object_notify (G_OBJECT (setting), NM_SETTING_VPN_DATA);
243 foreach_item_helper (GHashTable *hash,
248 GSList *copied = NULL, *siter;
250 g_return_if_fail (hash != NULL);
252 /* Grab keys and copy them so that the callback func can modify
253 * the hash table items if it wants to.
255 keys = g_hash_table_get_keys (hash);
256 for (liter = keys; liter; liter = g_list_next (liter))
257 copied = g_slist_prepend (copied, g_strdup (liter->data));
258 copied = g_slist_reverse (copied);
261 for (siter = copied; siter; siter = g_slist_next (siter)) {
264 value = g_hash_table_lookup (hash, siter->data);
265 func (siter->data, value, user_data);
268 g_slist_free_full (copied, g_free);
272 * nm_setting_vpn_foreach_data_item:
273 * @setting: a #NMSettingVpn
274 * @func: (scope call): an user provided function
275 * @user_data: data to be passed to @func
277 * Iterates all data items stored in this setting. It is safe to add, remove,
278 * and modify data items inside @func, though any additions or removals made
279 * during iteration will not be part of the iteration.
282 nm_setting_vpn_foreach_data_item (NMSettingVpn *setting,
286 g_return_if_fail (NM_IS_SETTING_VPN (setting));
288 foreach_item_helper (NM_SETTING_VPN_GET_PRIVATE (setting)->data, func, user_data);
292 * nm_setting_vpn_get_num_secrets:
293 * @setting: the #NMSettingVpn
295 * Gets number of VPN plugin specific secrets in the setting.
297 * Returns: the number of VPN plugin specific secrets
300 nm_setting_vpn_get_num_secrets (NMSettingVpn *setting)
302 g_return_val_if_fail (NM_IS_SETTING_VPN (setting), 0);
304 return g_hash_table_size (NM_SETTING_VPN_GET_PRIVATE (setting)->secrets);
308 * nm_setting_vpn_add_secret:
309 * @setting: the #NMSettingVpn
310 * @key: a name that uniquely identifies the given secret @secret
311 * @secret: the secret to be referenced by @key
313 * Establishes a relationship between @key and @secret internally in the
314 * setting which may be retrieved later.
317 nm_setting_vpn_add_secret (NMSettingVpn *setting,
321 g_return_if_fail (NM_IS_SETTING_VPN (setting));
322 g_return_if_fail (key != NULL);
323 g_return_if_fail (strlen (key) > 0);
324 g_return_if_fail (secret != NULL);
325 g_return_if_fail (strlen (secret) > 0);
327 g_hash_table_insert (NM_SETTING_VPN_GET_PRIVATE (setting)->secrets,
328 g_strdup (key), g_strdup (secret));
329 g_object_notify (G_OBJECT (setting), NM_SETTING_VPN_SECRETS);
333 * nm_setting_vpn_get_secret:
334 * @setting: the #NMSettingVpn
335 * @key: the name of the secret to retrieve
337 * Retrieves the secret of a key/value relationship previously established
338 * by nm_setting_vpn_add_secret().
340 * Returns: the secret, if any
343 nm_setting_vpn_get_secret (NMSettingVpn *setting, const char *key)
345 g_return_val_if_fail (NM_IS_SETTING_VPN (setting), NULL);
347 return (const char *) g_hash_table_lookup (NM_SETTING_VPN_GET_PRIVATE (setting)->secrets, key);
351 * nm_setting_vpn_remove_secret:
352 * @setting: the #NMSettingVpn
353 * @key: the name of the secret to remove
355 * Deletes a key/value relationship previously established by
356 * nm_setting_vpn_add_secret().
358 * Returns: %TRUE if the secret was found and removed from the internal list,
359 * %FALSE if it was not.
362 nm_setting_vpn_remove_secret (NMSettingVpn *setting, const char *key)
366 g_return_val_if_fail (NM_IS_SETTING_VPN (setting), FALSE);
368 found = g_hash_table_remove (NM_SETTING_VPN_GET_PRIVATE (setting)->secrets, key);
370 g_object_notify (G_OBJECT (setting), NM_SETTING_VPN_SECRETS);
375 * nm_setting_vpn_foreach_secret:
376 * @setting: a #NMSettingVpn
377 * @func: (scope call): an user provided function
378 * @user_data: data to be passed to @func
380 * Iterates all secrets stored in this setting. It is safe to add, remove,
381 * and modify secrets inside @func, though any additions or removals made during
382 * iteration will not be part of the iteration.
385 nm_setting_vpn_foreach_secret (NMSettingVpn *setting,
389 g_return_if_fail (NM_IS_SETTING_VPN (setting));
391 foreach_item_helper (NM_SETTING_VPN_GET_PRIVATE (setting)->secrets, func, user_data);
395 * nm_setting_vpn_get_timeout:
396 * @setting: the #NMSettingVpn
398 * Returns: the #NMSettingVpn:timeout property of the setting
403 nm_setting_vpn_get_timeout (NMSettingVpn *setting)
405 g_return_val_if_fail (NM_IS_SETTING_VPN (setting), 0);
407 return NM_SETTING_VPN_GET_PRIVATE (setting)->timeout;
411 verify (NMSetting *setting, NMConnection *connection, GError **error)
413 NMSettingVpnPrivate *priv = NM_SETTING_VPN_GET_PRIVATE (setting);
415 if (!priv->service_type) {
416 g_set_error_literal (error,
418 NM_CONNECTION_ERROR_MISSING_PROPERTY,
419 _("property is missing"));
420 g_prefix_error (error, "%s.%s: ", NM_SETTING_VPN_SETTING_NAME, NM_SETTING_VPN_SERVICE_TYPE);
424 if (!strlen (priv->service_type)) {
425 g_set_error_literal (error,
427 NM_CONNECTION_ERROR_INVALID_PROPERTY,
428 _("property is empty"));
429 g_prefix_error (error, "%s.%s: ", NM_SETTING_VPN_SETTING_NAME, NM_SETTING_VPN_SERVICE_TYPE);
433 /* default username can be NULL, but can't be zero-length */
434 if (priv->user_name && !strlen (priv->user_name)) {
435 g_set_error_literal (error,
437 NM_CONNECTION_ERROR_INVALID_PROPERTY,
438 _("property is empty"));
439 g_prefix_error (error, "%s.%s: ", NM_SETTING_VPN_SETTING_NAME, NM_SETTING_VPN_USER_NAME);
446 static NMSettingUpdateSecretResult
447 update_secret_string (NMSetting *setting,
452 NMSettingVpnPrivate *priv = NM_SETTING_VPN_GET_PRIVATE (setting);
454 g_return_val_if_fail (key != NULL, NM_SETTING_UPDATE_SECRET_ERROR);
455 g_return_val_if_fail (value != NULL, NM_SETTING_UPDATE_SECRET_ERROR);
457 if (!value || !strlen (value)) {
458 g_set_error (error, NM_CONNECTION_ERROR,
459 NM_CONNECTION_ERROR_INVALID_PROPERTY,
460 _("secret was empty"));
461 g_prefix_error (error, "%s.%s: ", NM_SETTING_VPN_SETTING_NAME, key);
462 return NM_SETTING_UPDATE_SECRET_ERROR;
465 if (g_strcmp0 (g_hash_table_lookup (priv->secrets, key), value) == 0)
466 return NM_SETTING_UPDATE_SECRET_SUCCESS_UNCHANGED;
468 g_hash_table_insert (priv->secrets, g_strdup (key), g_strdup (value));
469 return NM_SETTING_UPDATE_SECRET_SUCCESS_MODIFIED;
472 static NMSettingUpdateSecretResult
473 update_secret_dict (NMSetting *setting,
477 NMSettingVpnPrivate *priv = NM_SETTING_VPN_GET_PRIVATE (setting);
479 const char *name, *value;
480 NMSettingUpdateSecretResult result = NM_SETTING_UPDATE_SECRET_SUCCESS_UNCHANGED;
482 g_return_val_if_fail (secrets != NULL, NM_SETTING_UPDATE_SECRET_ERROR);
484 /* Make sure the items are valid */
485 g_variant_iter_init (&iter, secrets);
486 while (g_variant_iter_next (&iter, "{&s&s}", &name, &value)) {
487 if (!name || !strlen (name)) {
488 g_set_error_literal (error, NM_CONNECTION_ERROR,
489 NM_CONNECTION_ERROR_INVALID_SETTING,
490 _("setting contained a secret with an empty name"));
491 g_prefix_error (error, "%s: ", NM_SETTING_VPN_SETTING_NAME);
492 return NM_SETTING_UPDATE_SECRET_ERROR;
495 if (!value || !strlen (value)) {
496 g_set_error (error, NM_CONNECTION_ERROR,
497 NM_CONNECTION_ERROR_INVALID_PROPERTY,
498 _("secret value was empty"));
499 g_prefix_error (error, "%s.%s: ", NM_SETTING_VPN_SETTING_NAME, name);
500 return NM_SETTING_UPDATE_SECRET_ERROR;
504 /* Now add the items to the settings' secrets list */
505 g_variant_iter_init (&iter, secrets);
506 while (g_variant_iter_next (&iter, "{&s&s}", &name, &value)) {
508 g_warn_if_fail (value != NULL);
511 if (strlen (value) == 0) {
512 g_warn_if_fail (strlen (value) > 0);
516 if (g_strcmp0 (g_hash_table_lookup (priv->secrets, name), value) == 0)
519 g_hash_table_insert (priv->secrets, g_strdup (name), g_strdup (value));
520 result = NM_SETTING_UPDATE_SECRET_SUCCESS_MODIFIED;
527 update_one_secret (NMSetting *setting, const char *key, GVariant *value, GError **error)
529 NMSettingUpdateSecretResult success = NM_SETTING_UPDATE_SECRET_ERROR;
531 g_return_val_if_fail (key != NULL, NM_SETTING_UPDATE_SECRET_ERROR);
532 g_return_val_if_fail (value != NULL, NM_SETTING_UPDATE_SECRET_ERROR);
534 if (g_variant_is_of_type (value, G_VARIANT_TYPE_STRING)) {
535 /* Passing the string properties individually isn't correct, and won't
536 * produce the correct result, but for some reason that's how it used
537 * to be done. So even though it's not correct, keep the code around
538 * for compatibility's sake.
540 success = update_secret_string (setting, key, g_variant_get_string (value, NULL), error);
541 } else if (g_variant_is_of_type (value, G_VARIANT_TYPE ("a{ss}"))) {
542 if (strcmp (key, NM_SETTING_VPN_SECRETS) != 0) {
543 g_set_error_literal (error, NM_CONNECTION_ERROR,
544 NM_CONNECTION_ERROR_PROPERTY_NOT_SECRET,
545 _("not a secret property"));
546 g_prefix_error (error, "%s.%s ", NM_SETTING_VPN_SETTING_NAME, key);
548 success = update_secret_dict (setting, value, error);
550 g_set_error_literal (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_INVALID_PROPERTY,
551 _("secret is not of correct type"));
552 g_prefix_error (error, "%s.%s: ", NM_SETTING_VPN_SETTING_NAME, key);
555 if (success == NM_SETTING_UPDATE_SECRET_SUCCESS_MODIFIED)
556 g_object_notify (G_OBJECT (setting), NM_SETTING_VPN_SECRETS);
562 get_secret_flags (NMSetting *setting,
563 const char *secret_name,
564 gboolean verify_secret,
565 NMSettingSecretFlags *out_flags,
568 NMSettingVpnPrivate *priv = NM_SETTING_VPN_GET_PRIVATE (setting);
569 gboolean success = FALSE;
573 NMSettingSecretFlags flags = NM_SETTING_SECRET_FLAG_NONE;
575 flags_key = g_strdup_printf ("%s-flags", secret_name);
576 if (g_hash_table_lookup_extended (priv->data, flags_key, NULL, &val)) {
578 tmp = strtoul ((const char *) val, NULL, 10);
579 if ((errno == 0) && (tmp <= NM_SETTING_SECRET_FLAGS_ALL)) {
580 flags = (NMSettingSecretFlags) tmp;
585 NM_CONNECTION_ERROR_INVALID_PROPERTY,
586 _("failed to convert value '%s' to uint"),
588 g_prefix_error (error, "%s.%s: ", NM_SETTING_VPN_SETTING_NAME, flags_key);
591 g_set_error_literal (error,
593 NM_CONNECTION_ERROR_MISSING_PROPERTY,
594 _("secret flags property not found"));
595 g_prefix_error (error, "%s.%s: ", NM_SETTING_VPN_SETTING_NAME, flags_key);
604 set_secret_flags (NMSetting *setting,
605 const char *secret_name,
606 gboolean verify_secret,
607 NMSettingSecretFlags flags,
610 g_hash_table_insert (NM_SETTING_VPN_GET_PRIVATE (setting)->data,
611 g_strdup_printf ("%s-flags", secret_name),
612 g_strdup_printf ("%u", flags));
613 g_object_notify (G_OBJECT (setting), NM_SETTING_VPN_SECRETS);
618 need_secrets (NMSetting *setting)
620 /* Assume that VPN connections need secrets since they almost always will */
621 return g_ptr_array_sized_new (1);
625 compare_one_secret (NMSettingVpn *a,
627 NMSettingCompareFlags flags)
629 GHashTable *a_secrets, *b_secrets;
631 const char *key, *val;
633 a_secrets = NM_SETTING_VPN_GET_PRIVATE (a)->secrets;
634 b_secrets = NM_SETTING_VPN_GET_PRIVATE (b)->secrets;
636 g_hash_table_iter_init (&iter, a_secrets);
637 while (g_hash_table_iter_next (&iter, (gpointer) &key, (gpointer) &val)) {
638 NMSettingSecretFlags a_secret_flags = NM_SETTING_SECRET_FLAG_NONE;
639 NMSettingSecretFlags b_secret_flags = NM_SETTING_SECRET_FLAG_NONE;
641 nm_setting_get_secret_flags (NM_SETTING (a), key, &a_secret_flags, NULL);
642 nm_setting_get_secret_flags (NM_SETTING (b), key, &b_secret_flags, NULL);
644 /* If the secret flags aren't the same, the settings aren't the same */
645 if (a_secret_flags != b_secret_flags)
648 if ( (flags & NM_SETTING_COMPARE_FLAG_IGNORE_AGENT_OWNED_SECRETS)
649 && (a_secret_flags & NM_SETTING_SECRET_FLAG_AGENT_OWNED))
652 if ( (flags & NM_SETTING_COMPARE_FLAG_IGNORE_NOT_SAVED_SECRETS)
653 && (a_secret_flags & NM_SETTING_SECRET_FLAG_NOT_SAVED))
656 /* Now compare the values themselves */
657 if (g_strcmp0 (val, nm_setting_vpn_get_secret (b, key)) != 0)
665 compare_property (NMSetting *setting,
667 const GParamSpec *prop_spec,
668 NMSettingCompareFlags flags)
672 /* We only need to treat the 'secrets' property specially */
673 if (g_strcmp0 (prop_spec->name, NM_SETTING_VPN_SECRETS) != 0)
674 return NM_SETTING_CLASS (nm_setting_vpn_parent_class)->compare_property (setting, other, prop_spec, flags);
676 /* Compare A to B to ensure everything in A is found in B */
677 same = compare_one_secret (NM_SETTING_VPN (setting), NM_SETTING_VPN (other), flags);
679 /* And then B to A to ensure everything in B is also found in A */
680 same = compare_one_secret (NM_SETTING_VPN (other), NM_SETTING_VPN (setting), flags);
687 clear_secrets_with_flags (NMSetting *setting,
689 NMSettingClearSecretsWithFlagsFn func,
692 NMSettingVpnPrivate *priv = NM_SETTING_VPN_GET_PRIVATE (setting);
695 gboolean changed = TRUE;
697 if (priv->secrets == NULL)
700 /* Iterate through secrets hash and check each entry */
701 g_hash_table_iter_init (&iter, priv->secrets);
702 while (g_hash_table_iter_next (&iter, (gpointer) &secret, NULL)) {
703 NMSettingSecretFlags flags = NM_SETTING_SECRET_FLAG_NONE;
705 nm_setting_get_secret_flags (setting, secret, &flags, NULL);
706 if (func (setting, pspec->name, flags, user_data) == TRUE) {
707 g_hash_table_iter_remove (&iter);
713 g_object_notify (G_OBJECT (setting), NM_SETTING_VPN_SECRETS);
719 destroy_one_secret (gpointer data)
721 char *secret = (char *) data;
723 /* Don't leave the secret lying around in memory */
724 memset (secret, 0, strlen (secret));
729 nm_setting_vpn_init (NMSettingVpn *setting)
731 NMSettingVpnPrivate *priv = NM_SETTING_VPN_GET_PRIVATE (setting);
733 priv->data = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
734 priv->secrets = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, destroy_one_secret);
738 finalize (GObject *object)
740 NMSettingVpnPrivate *priv = NM_SETTING_VPN_GET_PRIVATE (object);
742 g_free (priv->service_type);
743 g_free (priv->user_name);
744 g_hash_table_destroy (priv->data);
745 g_hash_table_destroy (priv->secrets);
747 G_OBJECT_CLASS (nm_setting_vpn_parent_class)->finalize (object);
751 set_property (GObject *object, guint prop_id,
752 const GValue *value, GParamSpec *pspec)
754 NMSettingVpnPrivate *priv = NM_SETTING_VPN_GET_PRIVATE (object);
757 case PROP_SERVICE_TYPE:
758 g_free (priv->service_type);
759 priv->service_type = g_value_dup_string (value);
762 g_free (priv->user_name);
763 priv->user_name = g_value_dup_string (value);
765 case PROP_PERSISTENT:
766 priv->persistent = g_value_get_boolean (value);
769 g_hash_table_unref (priv->data);
770 priv->data = _nm_utils_copy_strdict (g_value_get_boxed (value));
773 g_hash_table_unref (priv->secrets);
774 priv->secrets = _nm_utils_copy_strdict (g_value_get_boxed (value));
777 priv->timeout = g_value_get_uint (value);
780 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
786 get_property (GObject *object, guint prop_id,
787 GValue *value, GParamSpec *pspec)
789 NMSettingVpn *setting = NM_SETTING_VPN (object);
790 NMSettingVpnPrivate *priv = NM_SETTING_VPN_GET_PRIVATE (setting);
793 case PROP_SERVICE_TYPE:
794 g_value_set_string (value, nm_setting_vpn_get_service_type (setting));
797 g_value_set_string (value, nm_setting_vpn_get_user_name (setting));
799 case PROP_PERSISTENT:
800 g_value_set_boolean (value, priv->persistent);
803 g_value_take_boxed (value, _nm_utils_copy_strdict (priv->data));
806 g_value_take_boxed (value, _nm_utils_copy_strdict (priv->secrets));
809 g_value_set_uint (value, nm_setting_vpn_get_timeout (setting));
812 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
818 nm_setting_vpn_class_init (NMSettingVpnClass *setting_class)
820 GObjectClass *object_class = G_OBJECT_CLASS (setting_class);
821 NMSettingClass *parent_class = NM_SETTING_CLASS (setting_class);
823 g_type_class_add_private (setting_class, sizeof (NMSettingVpnPrivate));
825 /* virtual methods */
826 object_class->set_property = set_property;
827 object_class->get_property = get_property;
828 object_class->finalize = finalize;
830 parent_class->verify = verify;
831 parent_class->update_one_secret = update_one_secret;
832 parent_class->get_secret_flags = get_secret_flags;
833 parent_class->set_secret_flags = set_secret_flags;
834 parent_class->need_secrets = need_secrets;
835 parent_class->compare_property = compare_property;
836 parent_class->clear_secrets_with_flags = clear_secrets_with_flags;
840 * NMSettingVpn:service-type:
842 * D-Bus service name of the VPN plugin that this setting uses to connect to
843 * its network. i.e. org.freedesktop.NetworkManager.vpnc for the vpnc
846 g_object_class_install_property
847 (object_class, PROP_SERVICE_TYPE,
848 g_param_spec_string (NM_SETTING_VPN_SERVICE_TYPE, "", "",
851 G_PARAM_STATIC_STRINGS));
854 * NMSettingVpn:user-name:
856 * If the VPN connection requires a user name for authentication, that name
857 * should be provided here. If the connection is available to more than one
858 * user, and the VPN requires each user to supply a different name, then
859 * leave this property empty. If this property is empty, NetworkManager
860 * will automatically supply the username of the user which requested the
863 g_object_class_install_property
864 (object_class, PROP_USER_NAME,
865 g_param_spec_string (NM_SETTING_VPN_USER_NAME, "", "",
868 G_PARAM_STATIC_STRINGS));
871 * NMSettingVpn:persistent:
873 * If the VPN service supports persistence, and this property is %TRUE,
874 * the VPN will attempt to stay connected across link changes and outages,
875 * until explicitly disconnected.
877 g_object_class_install_property
878 (object_class, PROP_PERSISTENT,
879 g_param_spec_boolean (NM_SETTING_VPN_PERSISTENT, "", "",
882 G_PARAM_STATIC_STRINGS));
887 * Dictionary of key/value pairs of VPN plugin specific data. Both keys and
888 * values must be strings.
890 * Type: GHashTable(utf8,utf8)
894 * variable: separate variables named after keys of the dictionary
895 * description: The keys of the data dictionary are used as variable names directly
896 * under [vpn] section.
897 * example: remote=ovpn.corp.com cipher=AES-256-CBC username=joe
900 g_object_class_install_property
901 (object_class, PROP_DATA,
902 g_param_spec_boxed (NM_SETTING_VPN_DATA, "", "",
905 G_PARAM_STATIC_STRINGS));
906 _nm_setting_class_transform_property (parent_class, NM_SETTING_VPN_DATA,
907 G_VARIANT_TYPE ("a{ss}"),
908 _nm_utils_strdict_to_dbus,
909 _nm_utils_strdict_from_dbus);
912 * NMSettingVpn:secrets:
914 * Dictionary of key/value pairs of VPN plugin specific secrets like
915 * passwords or private keys. Both keys and values must be strings.
917 * Type: GHashTable(utf8,utf8)
921 * variable: separate variables named after keys of the dictionary
922 * description: The keys of the secrets dictionary are used as variable names directly
923 * under [vpn-secrets] section.
924 * example: password=Popocatepetl
927 g_object_class_install_property
928 (object_class, PROP_SECRETS,
929 g_param_spec_boxed (NM_SETTING_VPN_SECRETS, "", "",
932 NM_SETTING_PARAM_SECRET |
933 G_PARAM_STATIC_STRINGS));
934 _nm_setting_class_transform_property (parent_class, NM_SETTING_VPN_SECRETS,
935 G_VARIANT_TYPE ("a{ss}"),
936 _nm_utils_strdict_to_dbus,
937 _nm_utils_strdict_from_dbus);
940 * NMSettingVpn:timeout:
942 * Timeout for the VPN service to establish the connection. Some services
943 * may take quite a long time to connect.
944 * Value of 0 means a default timeout, which is 60 seconds (unless overriden
945 * by vpn.timeout in configuration file). Values greater than zero mean
946 * timeout in seconds.
950 g_object_class_install_property
951 (object_class, PROP_TIMEOUT,
952 g_param_spec_uint (NM_SETTING_VPN_TIMEOUT, "", "",
955 G_PARAM_STATIC_STRINGS));