1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301 USA.
19 * Copyright 2007 - 2013 Red Hat, Inc.
20 * Copyright 2007 - 2008 Novell, Inc.
23 #include "nm-default.h"
28 #include "nm-dbus-glib-types.h"
29 #include "nm-param-spec-specialized.h"
30 #include "nm-setting-connection.h"
31 #include "nm-setting-private.h"
34 * SECTION:nm-setting-connection
35 * @short_description: Describes general connection properties
36 * @include: nm-setting-connection.h
38 * The #NMSettingConnection object is a #NMSetting subclass that describes
39 * properties that apply to all #NMConnection objects, regardless of what type
40 * of network connection they describe. Each #NMConnection object must contain
41 * a #NMSettingConnection setting.
45 * nm_setting_connection_error_quark:
47 * Registers an error quark for #NMSettingConnection if necessary.
49 * Returns: the error quark used for #NMSettingConnection errors.
52 nm_setting_connection_error_quark (void)
56 if (G_UNLIKELY (!quark))
57 quark = g_quark_from_static_string ("nm-setting-connection-error-quark");
62 G_DEFINE_TYPE_WITH_CODE (NMSettingConnection, nm_setting_connection, NM_TYPE_SETTING,
63 _nm_register_setting (NM_SETTING_CONNECTION_SETTING_NAME,
66 NM_SETTING_CONNECTION_ERROR))
67 NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_CONNECTION)
69 #define NM_SETTING_CONNECTION_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_CONNECTION, NMSettingConnectionPrivate))
87 GSList *permissions; /* list of Permission structs */
92 GSList *secondaries; /* secondary connections to activate with the base connection */
93 guint gateway_ping_timeout;
94 } NMSettingConnectionPrivate;
110 PROP_GATEWAY_PING_TIMEOUT,
115 /***********************************************************************/
117 #define PERM_USER_PREFIX "user:"
120 permission_new_from_str (const char *str)
123 const char *last_colon;
126 g_return_val_if_fail (strncmp (str, PERM_USER_PREFIX, strlen (PERM_USER_PREFIX)) == 0, NULL);
127 str += strlen (PERM_USER_PREFIX);
129 last_colon = strrchr (str, ':');
131 /* Ensure that somebody didn't pass "user::" */
132 g_return_val_if_fail (last_colon > str, NULL);
134 /* Reject :[detail] for now */
135 g_return_val_if_fail (*(last_colon + 1) == '\0', NULL);
137 /* Make sure we don't include detail in the username */
138 ulen = last_colon - str;
142 /* Sanity check the length of the username */
143 g_return_val_if_fail (ulen < 100, NULL);
145 /* Make sure there's no ':' in the username */
146 for (i = 0; i < ulen; i++)
147 g_return_val_if_fail (str[i] != ':', NULL);
149 /* And the username must be valid UTF-8 */
150 g_return_val_if_fail (g_utf8_validate (str, -1, NULL) == TRUE, NULL);
152 /* Yay, valid... create the new permission */
153 p = g_slice_new0 (Permission);
154 p->ptype = PERM_TYPE_USER;
156 p->item = g_malloc (ulen + 1);
157 memcpy (p->item, str, ulen);
158 p->item[ulen] = '\0';
160 p->item = g_strdup (str);
166 permission_new (const char *uname)
170 g_return_val_if_fail (uname, NULL);
171 g_return_val_if_fail (uname[0] != '\0', NULL);
172 g_return_val_if_fail (strchr (uname, ':') == NULL, NULL);
173 g_return_val_if_fail (g_utf8_validate (uname, -1, NULL) == TRUE, NULL);
175 /* Yay, valid... create the new permission */
176 p = g_slice_new0 (Permission);
177 p->ptype = PERM_TYPE_USER;
178 p->item = g_strdup (uname);
183 permission_to_string (Permission *p)
185 return g_strdup_printf (PERM_USER_PREFIX "%s:", p->item);
189 permission_free (Permission *p)
192 memset (p, 0, sizeof (*p));
193 g_slice_free (Permission, p);
196 /***********************************************************************/
199 * nm_setting_connection_new:
201 * Creates a new #NMSettingConnection object with default values.
203 * Returns: the new empty #NMSettingConnection object
205 NMSetting *nm_setting_connection_new (void)
207 return (NMSetting *) g_object_new (NM_TYPE_SETTING_CONNECTION, NULL);
211 * nm_setting_connection_get_id:
212 * @setting: the #NMSettingConnection
214 * Returns the #NMSettingConnection:id property of the connection.
216 * Returns: the connection ID
219 nm_setting_connection_get_id (NMSettingConnection *setting)
221 g_return_val_if_fail (NM_IS_SETTING_CONNECTION (setting), NULL);
223 return NM_SETTING_CONNECTION_GET_PRIVATE (setting)->id;
227 * nm_setting_connection_get_uuid:
228 * @setting: the #NMSettingConnection
230 * Returns the #NMSettingConnection:uuid property of the connection.
232 * Returns: the connection UUID
235 nm_setting_connection_get_uuid (NMSettingConnection *setting)
237 g_return_val_if_fail (NM_IS_SETTING_CONNECTION (setting), NULL);
239 return NM_SETTING_CONNECTION_GET_PRIVATE (setting)->uuid;
243 * nm_setting_connection_get_interface_name:
244 * @setting: the #NMSettingConnection
246 * Returns the #NMSettingConnection:interface-name property of the connection.
248 * Returns: the connection's interface name
253 nm_setting_connection_get_interface_name (NMSettingConnection *setting)
255 g_return_val_if_fail (NM_IS_SETTING_CONNECTION (setting), NULL);
257 return NM_SETTING_CONNECTION_GET_PRIVATE (setting)->interface_name;
261 * nm_setting_connection_get_connection_type:
262 * @setting: the #NMSettingConnection
264 * Returns the #NMSettingConnection:type property of the connection.
266 * Returns: the connection type
269 nm_setting_connection_get_connection_type (NMSettingConnection *setting)
271 g_return_val_if_fail (NM_IS_SETTING_CONNECTION (setting), NULL);
273 return NM_SETTING_CONNECTION_GET_PRIVATE (setting)->type;
278 * nm_setting_connection_get_num_permissions:
279 * @setting: the #NMSettingConnection
281 * Returns the number of entires in the #NMSettingConnection:permissions
282 * property of this setting.
284 * Returns: the number of permissions entires
287 nm_setting_connection_get_num_permissions (NMSettingConnection *setting)
289 g_return_val_if_fail (NM_IS_SETTING_CONNECTION (setting), 0);
291 return g_slist_length (NM_SETTING_CONNECTION_GET_PRIVATE (setting)->permissions);
295 * nm_setting_connection_get_permission:
296 * @setting: the #NMSettingConnection
297 * @idx: the zero-based index of the permissions entry
298 * @out_ptype: on return, the permission type (at this time, always "user")
299 * @out_pitem: on return, the permission item (formatted accoring to @ptype, see
300 * #NMSettingConnection:permissions for more detail
301 * @out_detail: on return, the permission detail (at this time, always %NULL)
303 * Retrieve one of the entries of the #NMSettingConnection:permissions property
306 * Returns: %TRUE if a permission was returned, %FALSE if @idx was invalid
309 nm_setting_connection_get_permission (NMSettingConnection *setting,
311 const char **out_ptype,
312 const char **out_pitem,
313 const char **out_detail)
315 NMSettingConnectionPrivate *priv;
318 g_return_val_if_fail (NM_IS_SETTING_CONNECTION (setting), FALSE);
320 priv = NM_SETTING_CONNECTION_GET_PRIVATE (setting);
322 g_return_val_if_fail (idx < g_slist_length (priv->permissions), FALSE);
324 p = g_slist_nth_data (priv->permissions, idx);
328 *out_pitem = p->item;
336 * nm_setting_connection_permissions_user_allowed:
337 * @setting: the #NMSettingConnection
338 * @uname: the user name to check permissions for
340 * Checks whether the given username is allowed to view/access this connection.
342 * Returns: %TRUE if the requested user is allowed to view this connection,
343 * %FALSE if the given user is not allowed to view this connection
346 nm_setting_connection_permissions_user_allowed (NMSettingConnection *setting,
349 NMSettingConnectionPrivate *priv;
352 g_return_val_if_fail (NM_IS_SETTING_CONNECTION (setting), FALSE);
353 g_return_val_if_fail (uname != NULL, FALSE);
354 g_return_val_if_fail (*uname != '\0', FALSE);
356 priv = NM_SETTING_CONNECTION_GET_PRIVATE (setting);
358 /* If no permissions, visible to all */
359 if (priv->permissions == NULL)
362 /* Find the username in the permissions list */
363 for (iter = priv->permissions; iter; iter = g_slist_next (iter)) {
364 Permission *p = iter->data;
366 if (strcmp (uname, p->item) == 0)
374 * nm_setting_connection_add_permission:
375 * @setting: the #NMSettingConnection
376 * @ptype: the permission type; at this time only "user" is supported
377 * @pitem: the permission item formatted as required for @ptype
378 * @detail: (allow-none): unused at this time; must be %NULL
380 * Adds a permission to the connection's permission list. At this time, only
381 * the "user" permission type is supported, and @pitem must be a username. See
382 * #NMSettingConnection:permissions: for more details.
384 * Returns: %TRUE if the permission was unique and was successfully added to the
385 * list, %FALSE if @ptype or @pitem was invalid or it the permission was already
386 * present in the list
389 nm_setting_connection_add_permission (NMSettingConnection *setting,
394 NMSettingConnectionPrivate *priv;
398 g_return_val_if_fail (NM_IS_SETTING_CONNECTION (setting), FALSE);
399 g_return_val_if_fail (ptype, FALSE);
400 g_return_val_if_fail (strlen (ptype) > 0, FALSE);
401 g_return_val_if_fail (detail == NULL, FALSE);
403 /* Only "user" for now... */
404 g_return_val_if_fail (strcmp (ptype, "user") == 0, FALSE);
406 priv = NM_SETTING_CONNECTION_GET_PRIVATE (setting);
409 for (iter = priv->permissions; iter; iter = g_slist_next (iter)) {
411 if (strcmp (pitem, p->item) == 0)
415 p = permission_new (pitem);
416 g_return_val_if_fail (p != NULL, FALSE);
417 priv->permissions = g_slist_append (priv->permissions, p);
418 g_object_notify (G_OBJECT (setting), NM_SETTING_CONNECTION_PERMISSIONS);
424 * nm_setting_connection_remove_permission:
425 * @setting: the #NMSettingConnection
426 * @idx: the zero-based index of the permission to remove
428 * Removes the permission at index @idx from the connection.
431 nm_setting_connection_remove_permission (NMSettingConnection *setting,
434 NMSettingConnectionPrivate *priv;
437 g_return_if_fail (NM_IS_SETTING_CONNECTION (setting));
439 priv = NM_SETTING_CONNECTION_GET_PRIVATE (setting);
440 iter = g_slist_nth (priv->permissions, idx);
441 g_return_if_fail (iter != NULL);
443 permission_free ((Permission *) iter->data);
444 priv->permissions = g_slist_delete_link (priv->permissions, iter);
445 g_object_notify (G_OBJECT (setting), NM_SETTING_CONNECTION_PERMISSIONS);
449 * nm_setting_connection_remove_permission_by_value:
450 * @setting: the #NMSettingConnection
451 * @ptype: the permission type; at this time only "user" is supported
452 * @pitem: the permission item formatted as required for @ptype
453 * @detail: (allow-none): unused at this time; must be %NULL
455 * Removes the permission from the connection.
456 * At this time, only the "user" permission type is supported, and @pitem must
457 * be a username. See #NMSettingConnection:permissions: for more details.
459 * Returns: %TRUE if the permission was found and removed; %FALSE if it was not.
464 nm_setting_connection_remove_permission_by_value (NMSettingConnection *setting,
469 NMSettingConnectionPrivate *priv;
473 g_return_val_if_fail (NM_IS_SETTING_CONNECTION (setting), FALSE);
474 g_return_val_if_fail (ptype, FALSE);
475 g_return_val_if_fail (strlen (ptype) > 0, FALSE);
476 g_return_val_if_fail (detail == NULL, FALSE);
478 /* Only "user" for now... */
479 g_return_val_if_fail (strcmp (ptype, "user") == 0, FALSE);
481 priv = NM_SETTING_CONNECTION_GET_PRIVATE (setting);
482 for (iter = priv->permissions; iter; iter = g_slist_next (iter)) {
484 if (strcmp (pitem, p->item) == 0) {
485 permission_free ((Permission *) iter->data);
486 priv->permissions = g_slist_delete_link (priv->permissions, iter);
487 g_object_notify (G_OBJECT (setting), NM_SETTING_CONNECTION_PERMISSIONS);
495 * nm_setting_connection_get_autoconnect:
496 * @setting: the #NMSettingConnection
498 * Returns the #NMSettingConnection:autoconnect property of the connection.
500 * Returns: the connection's autoconnect behavior
503 nm_setting_connection_get_autoconnect (NMSettingConnection *setting)
505 g_return_val_if_fail (NM_IS_SETTING_CONNECTION (setting), FALSE);
507 return NM_SETTING_CONNECTION_GET_PRIVATE (setting)->autoconnect;
511 * nm_setting_connection_get_timestamp:
512 * @setting: the #NMSettingConnection
514 * Returns the #NMSettingConnection:timestamp property of the connection.
516 * Returns: the connection's timestamp
519 nm_setting_connection_get_timestamp (NMSettingConnection *setting)
521 g_return_val_if_fail (NM_IS_SETTING_CONNECTION (setting), 0);
523 return NM_SETTING_CONNECTION_GET_PRIVATE (setting)->timestamp;
527 * nm_setting_connection_get_read_only:
528 * @setting: the #NMSettingConnection
530 * Returns the #NMSettingConnection:read-only property of the connection.
532 * Returns: %TRUE if the connection is read-only, %FALSE if it is not
535 nm_setting_connection_get_read_only (NMSettingConnection *setting)
537 g_return_val_if_fail (NM_IS_SETTING_CONNECTION (setting), TRUE);
539 return NM_SETTING_CONNECTION_GET_PRIVATE (setting)->read_only;
543 * nm_setting_connection_get_zone:
544 * @setting: the #NMSettingConnection
546 * Returns the #NMSettingConnection:zone property of the connection.
548 * Returns: the trust level of a connection
551 nm_setting_connection_get_zone (NMSettingConnection *setting)
553 g_return_val_if_fail (NM_IS_SETTING_CONNECTION (setting), NULL);
555 return NM_SETTING_CONNECTION_GET_PRIVATE (setting)->zone;
559 * nm_setting_connection_get_master:
560 * @setting: the #NMSettingConnection
562 * Returns the #NMSettingConnection:master property of the connection.
564 * Returns: interface name of the master device or UUID of the master
568 nm_setting_connection_get_master (NMSettingConnection *setting)
570 g_return_val_if_fail (NM_IS_SETTING_CONNECTION (setting), NULL);
572 return NM_SETTING_CONNECTION_GET_PRIVATE (setting)->master;
576 * nm_setting_connection_get_slave_type:
577 * @setting: the #NMSettingConnection
579 * Returns the #NMSettingConnection:slave-type property of the connection.
581 * Returns: the type of slave this connection is, if any
584 nm_setting_connection_get_slave_type (NMSettingConnection *setting)
586 g_return_val_if_fail (NM_IS_SETTING_CONNECTION (setting), NULL);
588 return NM_SETTING_CONNECTION_GET_PRIVATE (setting)->slave_type;
592 * nm_setting_connection_is_slave_type:
593 * @setting: the #NMSettingConnection
594 * @type: the setting name (ie #NM_SETTING_BOND_SETTING_NAME) to be matched
595 * against @setting's slave type
597 * Returns: %TRUE if connection is of the given slave @type
600 nm_setting_connection_is_slave_type (NMSettingConnection *setting,
603 g_return_val_if_fail (NM_IS_SETTING_CONNECTION (setting), FALSE);
605 return !g_strcmp0 (NM_SETTING_CONNECTION_GET_PRIVATE (setting)->slave_type, type);
609 * nm_setting_connection_get_num_secondaries:
610 * @setting: the #NMSettingConnection
612 * Returns: the number of configured secondary connection UUIDs
617 nm_setting_connection_get_num_secondaries (NMSettingConnection *setting)
619 g_return_val_if_fail (NM_IS_SETTING_CONNECTION (setting), 0);
621 return g_slist_length (NM_SETTING_CONNECTION_GET_PRIVATE (setting)->secondaries);
625 * nm_setting_connection_get_secondary:
626 * @setting: the #NMSettingConnection
627 * @idx: the zero-based index of the secondary connection UUID entry
629 * Returns: the secondary connection UUID at index @idx
634 nm_setting_connection_get_secondary (NMSettingConnection *setting, guint32 idx)
636 NMSettingConnectionPrivate *priv;
638 g_return_val_if_fail (NM_IS_SETTING_CONNECTION (setting), NULL);
640 priv = NM_SETTING_CONNECTION_GET_PRIVATE (setting);
641 g_return_val_if_fail (idx <= g_slist_length (priv->secondaries), NULL);
643 return (const char *) g_slist_nth_data (priv->secondaries, idx);
647 * nm_setting_connection_add_secondary:
648 * @setting: the #NMSettingConnection
649 * @sec_uuid: the secondary connection UUID to add
651 * Adds a new secondary connetion UUID to the setting.
653 * Returns: %TRUE if the secondary connection UUID was added; %FALSE if the UUID
654 * was already present
659 nm_setting_connection_add_secondary (NMSettingConnection *setting,
660 const char *sec_uuid)
662 NMSettingConnectionPrivate *priv;
665 g_return_val_if_fail (NM_IS_SETTING_CONNECTION (setting), FALSE);
666 g_return_val_if_fail (sec_uuid != NULL, FALSE);
667 g_return_val_if_fail (sec_uuid[0] != '\0', FALSE);
669 priv = NM_SETTING_CONNECTION_GET_PRIVATE (setting);
670 for (iter = priv->secondaries; iter; iter = g_slist_next (iter)) {
671 if (!strcmp (sec_uuid, (char *) iter->data))
675 priv->secondaries = g_slist_append (priv->secondaries, g_strdup (sec_uuid));
676 g_object_notify (G_OBJECT (setting), NM_SETTING_CONNECTION_SECONDARIES);
681 * nm_setting_connection_remove_secondary:
682 * @setting: the #NMSettingConnection
683 * @idx: index number of the secondary connection UUID
685 * Removes the secondary coonnection UUID at index @idx.
690 nm_setting_connection_remove_secondary (NMSettingConnection *setting, guint32 idx)
692 NMSettingConnectionPrivate *priv;
695 g_return_if_fail (NM_IS_SETTING_CONNECTION (setting));
697 priv = NM_SETTING_CONNECTION_GET_PRIVATE (setting);
698 elt = g_slist_nth (priv->secondaries, idx);
699 g_return_if_fail (elt != NULL);
702 priv->secondaries = g_slist_delete_link (priv->secondaries, elt);
703 g_object_notify (G_OBJECT (setting), NM_SETTING_CONNECTION_SECONDARIES);
707 * nm_setting_connection_remove_secondary_by_value:
708 * @setting: the #NMSettingConnection
709 * @sec_uuid: the secondary connection UUID to remove
711 * Removes the secondary coonnection UUID @sec_uuid.
713 * Returns: %TRUE if the secondary connection UUID was found and removed; %FALSE if it was not.
718 nm_setting_connection_remove_secondary_by_value (NMSettingConnection *setting,
719 const char *sec_uuid)
721 NMSettingConnectionPrivate *priv;
724 g_return_val_if_fail (NM_IS_SETTING_CONNECTION (setting), FALSE);
725 g_return_val_if_fail (sec_uuid != NULL, FALSE);
726 g_return_val_if_fail (sec_uuid[0] != '\0', FALSE);
728 priv = NM_SETTING_CONNECTION_GET_PRIVATE (setting);
729 for (iter = priv->secondaries; iter; iter = g_slist_next (iter)) {
730 if (!strcmp (sec_uuid, (char *) iter->data)) {
731 priv->secondaries = g_slist_delete_link (priv->secondaries, iter);
732 g_object_notify (G_OBJECT (setting), NM_SETTING_CONNECTION_SECONDARIES);
740 * nm_setting_connection_get_gateway_ping_timeout:
741 * @setting: the #NMSettingConnection
743 * Returns: the value contained in the #NMSettingConnection:gateway-ping-timeout
749 nm_setting_connection_get_gateway_ping_timeout (NMSettingConnection *setting)
751 g_return_val_if_fail (NM_IS_SETTING_CONNECTION (setting), 0);
753 return NM_SETTING_CONNECTION_GET_PRIVATE (setting)->gateway_ping_timeout;
758 verify (NMSetting *setting, GSList *all_settings, GError **error)
760 NMSettingConnectionPrivate *priv = NM_SETTING_CONNECTION_GET_PRIVATE (setting);
765 g_set_error_literal (error,
766 NM_SETTING_CONNECTION_ERROR,
767 NM_SETTING_CONNECTION_ERROR_MISSING_PROPERTY,
768 _("property is missing"));
769 g_prefix_error (error, "%s.%s: ", NM_SETTING_CONNECTION_SETTING_NAME, NM_SETTING_CONNECTION_ID);
771 } else if (!strlen (priv->id)) {
772 g_set_error_literal (error,
773 NM_SETTING_CONNECTION_ERROR,
774 NM_SETTING_CONNECTION_ERROR_INVALID_PROPERTY,
775 _("property is empty"));
776 g_prefix_error (error, "%s.%s: ", NM_SETTING_CONNECTION_SETTING_NAME, NM_SETTING_CONNECTION_ID);
781 g_set_error_literal (error,
782 NM_SETTING_CONNECTION_ERROR,
783 NM_SETTING_CONNECTION_ERROR_MISSING_PROPERTY,
784 _("property is missing"));
785 g_prefix_error (error, "%s.%s: ", NM_SETTING_CONNECTION_SETTING_NAME, NM_SETTING_CONNECTION_UUID);
787 } else if (!nm_utils_is_uuid (priv->uuid)) {
789 NM_SETTING_CONNECTION_ERROR,
790 NM_SETTING_CONNECTION_ERROR_INVALID_PROPERTY,
791 _("'%s' is not a valid UUID"),
793 g_prefix_error (error, "%s.%s: ", NM_SETTING_CONNECTION_SETTING_NAME, NM_SETTING_CONNECTION_UUID);
797 /* FIXME: previously, verify() set the NMSettingConnection:interface_name property,
798 * thus modifying the setting. verify() should not do this, but keep this not to change
801 if (!priv->interface_name) {
802 for (iter = all_settings; iter; iter = iter->next) {
803 NMSetting *s_current = iter->data;
804 char *virtual_iface_name = NULL;
806 if (NM_IS_SETTING_BOND (s_current))
807 g_object_get (s_current, NM_SETTING_BOND_INTERFACE_NAME, &virtual_iface_name, NULL);
808 else if (NM_IS_SETTING_BRIDGE (s_current))
809 g_object_get (s_current, NM_SETTING_BRIDGE_INTERFACE_NAME, &virtual_iface_name, NULL);
810 else if (NM_IS_SETTING_TEAM (s_current))
811 g_object_get (s_current, NM_SETTING_TEAM_INTERFACE_NAME, &virtual_iface_name, NULL);
812 else if (NM_IS_SETTING_VLAN (s_current))
813 g_object_get (s_current, NM_SETTING_VLAN_INTERFACE_NAME, &virtual_iface_name, NULL);
814 /* For NMSettingInfiniband, virtual_iface_name has no backing field.
815 * No need to set the (unset) interface_name to the default value.
818 if (virtual_iface_name) {
819 if (nm_utils_iface_valid_name (virtual_iface_name)) {
820 /* found a new interface name. */
821 priv->interface_name = virtual_iface_name;
824 g_free (virtual_iface_name);
829 if (priv->interface_name) {
830 if (!nm_utils_iface_valid_name (priv->interface_name)) {
832 NM_SETTING_CONNECTION_ERROR,
833 NM_SETTING_CONNECTION_ERROR_INVALID_PROPERTY,
834 _("'%s' is not a valid interface name"),
835 priv->interface_name);
836 g_prefix_error (error, "%s.%s: ", NM_SETTING_CONNECTION_SETTING_NAME, NM_SETTING_CONNECTION_INTERFACE_NAME);
842 g_set_error_literal (error,
843 NM_SETTING_CONNECTION_ERROR,
844 NM_SETTING_CONNECTION_ERROR_MISSING_PROPERTY,
845 _("property is missing"));
846 g_prefix_error (error, "%s.%s: ", NM_SETTING_CONNECTION_SETTING_NAME, NM_SETTING_CONNECTION_TYPE);
848 } else if (!strlen (priv->type)) {
849 g_set_error_literal (error,
850 NM_SETTING_CONNECTION_ERROR,
851 NM_SETTING_CONNECTION_ERROR_INVALID_PROPERTY,
852 _("property is empty"));
853 g_prefix_error (error, "%s.%s: ", NM_SETTING_CONNECTION_SETTING_NAME, NM_SETTING_CONNECTION_TYPE);
857 /* Make sure the corresponding 'type' item is present */
858 if (all_settings && !nm_setting_find_in_list (all_settings, priv->type)) {
860 NM_SETTING_CONNECTION_ERROR,
861 NM_SETTING_CONNECTION_ERROR_TYPE_SETTING_NOT_FOUND,
862 _("requires presence of '%s' setting in the connection"),
864 g_prefix_error (error, "%s.%s: ", NM_SETTING_CONNECTION_SETTING_NAME, NM_SETTING_CONNECTION_TYPE);
868 is_slave = ( priv->slave_type
869 && ( !strcmp (priv->slave_type, NM_SETTING_BOND_SETTING_NAME)
870 || !strcmp (priv->slave_type, NM_SETTING_BRIDGE_SETTING_NAME)
871 || !strcmp (priv->slave_type, NM_SETTING_TEAM_SETTING_NAME)));
873 if (priv->slave_type && !is_slave) {
875 NM_SETTING_CONNECTION_ERROR,
876 NM_SETTING_CONNECTION_ERROR_INVALID_PROPERTY,
877 _("Unknown slave type '%s'"), priv->slave_type);
878 g_prefix_error (error, "%s.%s: ", NM_SETTING_CONNECTION_SETTING_NAME, NM_SETTING_CONNECTION_SLAVE_TYPE);
879 return NM_SETTING_VERIFY_ERROR;
885 NM_SETTING_CONNECTION_ERROR,
886 NM_SETTING_CONNECTION_ERROR_MISSING_PROPERTY,
887 _("Slave connections need a valid '%s' property"),
888 NM_SETTING_CONNECTION_MASTER);
889 g_prefix_error (error, "%s.%s: ", NM_SETTING_CONNECTION_SETTING_NAME, NM_SETTING_CONNECTION_MASTER);
890 return NM_SETTING_VERIFY_ERROR;
895 NM_SETTING_CONNECTION_ERROR,
896 NM_SETTING_CONNECTION_ERROR_MISSING_PROPERTY,
897 _("Cannot set '%s' without '%s'"),
898 NM_SETTING_CONNECTION_MASTER, NM_SETTING_CONNECTION_SLAVE_TYPE);
899 g_prefix_error (error, "%s.%s: ", NM_SETTING_CONNECTION_SETTING_NAME, NM_SETTING_CONNECTION_SLAVE_TYPE);
900 return NM_SETTING_VERIFY_ERROR;
908 compare_property (NMSetting *setting,
910 const GParamSpec *prop_spec,
911 NMSettingCompareFlags flags)
913 /* Handle ignore ID */
914 if ( (flags & NM_SETTING_COMPARE_FLAG_IGNORE_ID)
915 && g_strcmp0 (prop_spec->name, NM_SETTING_CONNECTION_ID) == 0)
918 /* Otherwise chain up to parent to handle generic compare */
919 return NM_SETTING_CLASS (nm_setting_connection_parent_class)->compare_property (setting, other, prop_spec, flags);
923 nm_setting_connection_init (NMSettingConnection *setting)
928 finalize (GObject *object)
930 NMSettingConnectionPrivate *priv = NM_SETTING_CONNECTION_GET_PRIVATE (object);
934 g_free (priv->interface_name);
937 g_free (priv->master);
938 g_free (priv->slave_type);
939 g_slist_free_full (priv->permissions, (GDestroyNotify) permission_free);
940 g_slist_free_full (priv->secondaries, g_free);
942 G_OBJECT_CLASS (nm_setting_connection_parent_class)->finalize (object);
946 perm_stringlist_to_permlist (GSList *strlist)
948 GSList *list = NULL, *iter;
950 for (iter = strlist; iter; iter = g_slist_next (iter)) {
953 p = permission_new_from_str ((const char *) iter->data);
955 list = g_slist_append (list, p);
962 set_property (GObject *object, guint prop_id,
963 const GValue *value, GParamSpec *pspec)
965 NMSettingConnectionPrivate *priv = NM_SETTING_CONNECTION_GET_PRIVATE (object);
970 priv->id = g_value_dup_string (value);
974 priv->uuid = g_value_dup_string (value);
976 case PROP_INTERFACE_NAME:
977 g_free (priv->interface_name);
978 priv->interface_name = g_value_dup_string (value);
982 priv->type = g_value_dup_string (value);
984 case PROP_PERMISSIONS:
985 g_slist_free_full (priv->permissions, (GDestroyNotify) permission_free);
986 priv->permissions = perm_stringlist_to_permlist (g_value_get_boxed (value));
988 case PROP_AUTOCONNECT:
989 priv->autoconnect = g_value_get_boolean (value);
992 priv->timestamp = g_value_get_uint64 (value);
995 priv->read_only = g_value_get_boolean (value);
999 priv->zone = g_value_dup_string (value);
1002 g_free (priv->master);
1003 priv->master = g_value_dup_string (value);
1005 case PROP_SLAVE_TYPE:
1006 g_free (priv->slave_type);
1007 priv->slave_type = g_value_dup_string (value);
1009 case PROP_SECONDARIES:
1010 g_slist_free_full (priv->secondaries, g_free);
1011 priv->secondaries = g_value_dup_boxed (value);
1013 case PROP_GATEWAY_PING_TIMEOUT:
1014 priv->gateway_ping_timeout = g_value_get_uint (value);
1017 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1023 perm_permlist_to_stringlist (GSList *permlist)
1025 GSList *list = NULL, *iter;
1027 for (iter = permlist; iter; iter = g_slist_next (iter))
1028 list = g_slist_append (list, permission_to_string ((Permission *) iter->data));
1033 get_property (GObject *object, guint prop_id,
1034 GValue *value, GParamSpec *pspec)
1036 NMSettingConnection *setting = NM_SETTING_CONNECTION (object);
1037 NMSettingConnectionPrivate *priv = NM_SETTING_CONNECTION_GET_PRIVATE (setting);
1041 g_value_set_string (value, nm_setting_connection_get_id (setting));
1044 g_value_set_string (value, nm_setting_connection_get_uuid (setting));
1046 case PROP_INTERFACE_NAME:
1047 g_value_set_string (value, nm_setting_connection_get_interface_name (setting));
1050 g_value_set_string (value, nm_setting_connection_get_connection_type (setting));
1052 case PROP_PERMISSIONS:
1053 g_value_take_boxed (value, perm_permlist_to_stringlist (priv->permissions));
1055 case PROP_AUTOCONNECT:
1056 g_value_set_boolean (value, nm_setting_connection_get_autoconnect (setting));
1058 case PROP_TIMESTAMP:
1059 g_value_set_uint64 (value, nm_setting_connection_get_timestamp (setting));
1061 case PROP_READ_ONLY:
1062 g_value_set_boolean (value, nm_setting_connection_get_read_only (setting));
1065 g_value_set_string (value, nm_setting_connection_get_zone (setting));
1068 g_value_set_string (value, nm_setting_connection_get_master (setting));
1070 case PROP_SLAVE_TYPE:
1071 g_value_set_string (value, nm_setting_connection_get_slave_type (setting));
1073 case PROP_SECONDARIES:
1074 g_value_set_boxed (value, priv->secondaries);
1076 case PROP_GATEWAY_PING_TIMEOUT:
1077 g_value_set_uint (value, priv->gateway_ping_timeout);
1080 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1086 nm_setting_connection_class_init (NMSettingConnectionClass *setting_class)
1088 GObjectClass *object_class = G_OBJECT_CLASS (setting_class);
1089 NMSettingClass *parent_class = NM_SETTING_CLASS (setting_class);
1091 g_type_class_add_private (setting_class, sizeof (NMSettingConnectionPrivate));
1093 /* virtual methods */
1094 object_class->set_property = set_property;
1095 object_class->get_property = get_property;
1096 object_class->finalize = finalize;
1097 parent_class->verify = verify;
1098 parent_class->compare_property = compare_property;
1103 * NMSettingConnection:id:
1105 * A human readable unique identifier for the connection, like "Work Wi-Fi"
1108 g_object_class_install_property
1109 (object_class, PROP_ID,
1110 g_param_spec_string (NM_SETTING_CONNECTION_ID, "", "",
1113 NM_SETTING_PARAM_FUZZY_IGNORE |
1114 G_PARAM_STATIC_STRINGS));
1117 * NMSettingConnection:uuid:
1119 * A universally unique identifier for the connection, for example generated
1120 * with libuuid. It should be assigned when the connection is created, and
1121 * never changed as long as the connection still applies to the same
1122 * network. For example, it should not be changed when the
1123 * #NMSettingConnection:id property or #NMSettingIP4Config changes, but
1124 * might need to be re-created when the Wi-Fi SSID, mobile broadband network
1125 * provider, or #NMSettingConnection:type property changes.
1127 * The UUID must be in the format "2815492f-7e56-435e-b2e9-246bd7cdc664"
1128 * (ie, contains only hexadecimal characters and "-"). A suitable UUID may
1129 * be generated by nm_utils_uuid_generate() or
1130 * nm_utils_uuid_generate_from_string().
1132 g_object_class_install_property
1133 (object_class, PROP_UUID,
1134 g_param_spec_string (NM_SETTING_CONNECTION_UUID, "", "",
1137 NM_SETTING_PARAM_FUZZY_IGNORE |
1138 G_PARAM_STATIC_STRINGS));
1141 * NMSettingConnection:interface-name:
1143 * The name of the network interface this connection is bound to. If not
1144 * set, then the connection can be attached to any interface of the
1145 * appropriate type (subject to restrictions imposed by other settings).
1147 * For software devices this specifies the name of the created device.
1149 * For connection types where interface names cannot easily be made
1150 * persistent (e.g. mobile broadband or USB Ethernet), this property should
1151 * not be used. Setting this property restricts the interfaces a connection
1152 * can be used with, and if interface names change or are reordered the
1153 * connection may be applied to the wrong interface.
1157 g_object_class_install_property
1158 (object_class, PROP_INTERFACE_NAME,
1159 g_param_spec_string (NM_SETTING_CONNECTION_INTERFACE_NAME, "", "",
1162 NM_SETTING_PARAM_INFERRABLE |
1163 G_PARAM_STATIC_STRINGS));
1166 * NMSettingConnection:type:
1168 * Base type of the connection. For hardware-dependent connections, should
1169 * contain the setting name of the hardware-type specific setting (ie,
1170 * "802-3-ethernet" or "802-11-wireless" or "bluetooth", etc), and for
1171 * non-hardware dependent connections like VPN or otherwise, should contain
1172 * the setting name of that setting type (ie, "vpn" or "bridge", etc).
1174 g_object_class_install_property
1175 (object_class, PROP_TYPE,
1176 g_param_spec_string (NM_SETTING_CONNECTION_TYPE, "", "",
1179 NM_SETTING_PARAM_INFERRABLE |
1180 G_PARAM_STATIC_STRINGS));
1183 * NMSettingConnection:permissions:
1185 * An array of strings defining what access a given user has to this
1186 * connection. If this is %NULL or empty, all users are allowed to access
1187 * this connection. Otherwise a user is allowed to access this connection
1188 * if and only if they are in this list. Each entry is of the form
1189 * "[type]:[id]:[reserved]"; for example, "user:dcbw:blah".
1191 * At this time only the "user" [type] is allowed. Any other values are
1192 * ignored and reserved for future use. [id] is the username that this
1193 * permission refers to, which may not contain the ":" character. Any
1194 * [reserved] information present must be ignored and is reserved for future
1195 * use. All of [type], [id], and [reserved] must be valid UTF-8.
1197 g_object_class_install_property
1198 (object_class, PROP_PERMISSIONS,
1199 _nm_param_spec_specialized (NM_SETTING_CONNECTION_PERMISSIONS, "", "",
1200 DBUS_TYPE_G_LIST_OF_STRING,
1202 G_PARAM_STATIC_STRINGS));
1205 * NMSettingConnection:autoconnect:
1207 * Whether or not the connection should be automatically connected by
1208 * NetworkManager when the resources for the connection are available.
1209 * %TRUE to automatically activate the connection, %FALSE to require manual
1210 * intervention to activate the connection.
1212 g_object_class_install_property
1213 (object_class, PROP_AUTOCONNECT,
1214 g_param_spec_boolean (NM_SETTING_CONNECTION_AUTOCONNECT, "", "",
1218 NM_SETTING_PARAM_FUZZY_IGNORE |
1219 G_PARAM_STATIC_STRINGS));
1222 * NMSettingConnection:timestamp:
1224 * The time, in seconds since the Unix Epoch, that the connection was last
1225 * _successfully_ fully activated.
1227 * NetworkManager updates the connection timestamp periodically when the
1228 * connection is active to ensure that an active connection has the latest
1229 * timestamp. The property is only meant for reading (changes to this
1230 * property will not be preserved).
1232 g_object_class_install_property
1233 (object_class, PROP_TIMESTAMP,
1234 g_param_spec_uint64 (NM_SETTING_CONNECTION_TIMESTAMP, "", "",
1238 NM_SETTING_PARAM_FUZZY_IGNORE |
1239 G_PARAM_STATIC_STRINGS));
1242 * NMSettingConnection:read-only:
1244 * %FALSE if the connection can be modified using the provided settings
1245 * service's D-Bus interface with the right privileges, or %TRUE if the
1246 * connection is read-only and cannot be modified.
1248 g_object_class_install_property
1249 (object_class, PROP_READ_ONLY,
1250 g_param_spec_boolean (NM_SETTING_CONNECTION_READ_ONLY, "", "",
1254 NM_SETTING_PARAM_FUZZY_IGNORE |
1255 G_PARAM_STATIC_STRINGS));
1258 * NMSettingConnection:zone:
1260 * The trust level of a the connection. Free form case-insensitive string
1261 * (for example "Home", "Work", "Public"). %NULL or unspecified zone means
1262 * the connection will be placed in the default zone as defined by the
1265 g_object_class_install_property
1266 (object_class, PROP_ZONE,
1267 g_param_spec_string (NM_SETTING_CONNECTION_ZONE, "", "",
1271 NM_SETTING_PARAM_FUZZY_IGNORE |
1272 G_PARAM_STATIC_STRINGS));
1275 * NMSettingConnection:master:
1277 * Interface name of the master device or UUID of the master connection.
1279 g_object_class_install_property
1280 (object_class, PROP_MASTER,
1281 g_param_spec_string (NM_SETTING_CONNECTION_MASTER, "", "",
1284 NM_SETTING_PARAM_FUZZY_IGNORE |
1285 NM_SETTING_PARAM_INFERRABLE |
1286 G_PARAM_STATIC_STRINGS));
1289 * NMSettingConnection:slave-type:
1291 * Setting name of the device type of this slave's master connection (eg,
1292 * %NM_SETTING_BOND_SETTING_NAME), or %NULL if this connection is not a
1295 g_object_class_install_property
1296 (object_class, PROP_SLAVE_TYPE,
1297 g_param_spec_string (NM_SETTING_CONNECTION_SLAVE_TYPE, "", "",
1300 NM_SETTING_PARAM_FUZZY_IGNORE |
1301 NM_SETTING_PARAM_INFERRABLE |
1302 G_PARAM_STATIC_STRINGS));
1305 * NMSettingConnection:secondaries:
1307 * List of connection UUIDs that should be activated when the base
1308 * connection itself is activated. Currently only VPN connections are
1313 g_object_class_install_property
1314 (object_class, PROP_SECONDARIES,
1315 _nm_param_spec_specialized (NM_SETTING_CONNECTION_SECONDARIES, "", "",
1316 DBUS_TYPE_G_LIST_OF_STRING,
1318 NM_SETTING_PARAM_FUZZY_IGNORE |
1319 G_PARAM_STATIC_STRINGS));
1322 * NMSettingConnection:gateway-ping-timeout:
1324 * If greater than zero, delay success of IP addressing until either the
1325 * timeout is reached, or an IP gateway replies to a ping.
1329 g_object_class_install_property
1330 (object_class, PROP_GATEWAY_PING_TIMEOUT,
1331 g_param_spec_uint (NM_SETTING_CONNECTION_GATEWAY_PING_TIMEOUT, "", "",
1335 G_PARAM_STATIC_STRINGS));