device: allow modifying Managed property
authorThomas Haller <thaller@redhat.com>
Tue, 15 Sep 2015 12:27:31 +0000 (14:27 +0200)
committerThomas Haller <thaller@redhat.com>
Fri, 18 Sep 2015 11:14:23 +0000 (13:14 +0200)
https://bugzilla.redhat.com/show_bug.cgi?id=1114685
https://bugzilla.gnome.org/show_bug.cgi?id=746566
Related: https://bugzilla.gnome.org/show_bug.cgi?id=680909
Related: https://bugzilla.gnome.org/show_bug.cgi?id=731014

Based-on-patch-by: Lubomir Rintel <lkundrak@v3.sk>
introspection/nm-device.xml
src/devices/nm-device.c
src/nm-audit-manager.h
src/nm-manager.c

index ba1a8fa..9092540 100644 (file)
         NM_DEVICE_STATE_ACTIVATED state.
       </tp:docstring>
     </property>
-    <property name="Managed" type="b" access="read">
+    <property name="Managed" type="b" access="readwrite">
       <tp:docstring>
-        Whether or not this device is managed by NetworkManager.
+        Whether or not this device is managed by NetworkManager. Setting this
+        property has a similar effect to configuring the device as unmanaged
+        via the keyfile.unmanaged-devices setting in NetworkManager.conf.
+        Changes to this value are not persistent and lost after NetworkManager
+        restart.
       </tp:docstring>
     </property>
     <property name="Autoconnect" type="b" access="readwrite">
index 83e7c4c..8c68bca 100644 (file)
@@ -215,6 +215,7 @@ typedef struct {
        char *        physical_port_id;
        guint         dev_id;
 
+       gboolean                managed_touched_by_user;
        NMUnmanagedFlags        unmanaged_flags;
        gboolean                is_nm_owned; /* whether the device is a device owned and created by NM */
        DeleteOnDeactivateData *delete_on_deactivate_data; /* data for scheduled cleanup when deleting link (g_idle_add) */
@@ -7768,6 +7769,9 @@ nm_device_set_unmanaged_by_device_spec (NMDevice *self, const GSList *unmanaged_
 
        priv = NM_DEVICE_GET_PRIVATE (self);
 
+       if (priv->managed_touched_by_user)
+               return;
+
        unmanaged = nm_device_spec_match_list (self, unmanaged_specs);
        nm_device_set_unmanaged (self,
                                 NM_UNMANAGED_USER,
@@ -9362,6 +9366,7 @@ set_property (GObject *object, guint prop_id,
        NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
        const char *hw_addr, *p;
        guint count;
+       gboolean val_bool;
 
        switch (prop_id) {
        case PROP_UDI:
@@ -9399,6 +9404,14 @@ set_property (GObject *object, guint prop_id,
        case PROP_IP4_ADDRESS:
                priv->ip4_address = g_value_get_uint (value);
                break;
+       case PROP_MANAGED:
+               val_bool = g_value_get_boolean (value);
+               priv->managed_touched_by_user = TRUE;
+               nm_device_set_unmanaged (self,
+                                        NM_UNMANAGED_USER | (val_bool ? NM_UNMANAGED_DEFAULT : NM_UNMANAGED_NONE),
+                                        !val_bool,
+                                        NM_DEVICE_STATE_REASON_USER_REQUESTED);
+               break;
        case PROP_AUTOCONNECT:
                nm_device_set_autoconnect (self, g_value_get_boolean (value));
                break;
@@ -9750,7 +9763,7 @@ nm_device_class_init (NMDeviceClass *klass)
                (object_class, PROP_MANAGED,
                 g_param_spec_boolean (NM_DEVICE_MANAGED, "", "",
                                       FALSE,
-                                      G_PARAM_READABLE |
+                                      G_PARAM_READWRITE |
                                       G_PARAM_STATIC_STRINGS));
 
        g_object_class_install_property
index 83d969c..0a74dc0 100644 (file)
@@ -60,6 +60,7 @@ typedef struct {
 #define NM_AUDIT_OP_DEVICE_AUTOCONNECT      "device-autoconnect"
 #define NM_AUDIT_OP_DEVICE_DISCONNECT       "device-disconnect"
 #define NM_AUDIT_OP_DEVICE_DELETE           "device-delete"
+#define NM_AUDIT_OP_DEVICE_MANAGED          "device-managed"
 
 GType nm_audit_manager_get_type (void);
 NMAuditManager *nm_audit_manager_get (void);
index 0e13f3b..be5090a 100644 (file)
@@ -4578,6 +4578,10 @@ prop_filter (GDBusConnection *connection,
                        glib_propname = NM_DEVICE_AUTOCONNECT;
                        permission = NM_AUTH_PERMISSION_NETWORK_CONTROL;
                        audit_op = NM_AUDIT_OP_DEVICE_AUTOCONNECT;
+               } else if (!strcmp (propname, "Managed")) {
+                       glib_propname = NM_DEVICE_MANAGED;
+                       permission = NM_AUTH_PERMISSION_NETWORK_CONTROL;
+                       audit_op = NM_AUDIT_OP_DEVICE_MANAGED;
                } else
                        return message;
                interface_type = NMDBUS_TYPE_DEVICE_SKELETON;