From 3ff1477349faf88a7ce569e318e72028ed03c875 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Klime=C5=A1?= Date: Thu, 19 Jun 2014 12:37:49 +0200 Subject: [PATCH] device: add a new D-Bus 'Delete' method for removing software devices --- introspection/nm-device.xml | 9 ++++++++ src/devices/nm-device.c | 41 +++++++++++++++++++++++++++++++++++++ src/devices/nm-device.h | 1 + 3 files changed, 51 insertions(+) diff --git a/introspection/nm-device.xml b/introspection/nm-device.xml index f459bce4f5..0dca23c37d 100644 --- a/introspection/nm-device.xml +++ b/introspection/nm-device.xml @@ -147,6 +147,15 @@ + + + + + Deletes a software device from NetworkManager and removes the interface from the system. + The method returns an error when called for a hardware device. + + + diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index fcf94b3c32..4750d0b3a8 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -71,6 +71,7 @@ #include "nm-dns-manager.h" static void impl_device_disconnect (NMDevice *device, DBusGMethodInvocation *context); +static void impl_device_delete (NMDevice *device, DBusGMethodInvocation *context); #include "nm-device-glue.h" @@ -4942,6 +4943,46 @@ impl_device_disconnect (NMDevice *device, DBusGMethodInvocation *context) NULL); } +static void +delete_cb (NMDevice *device, + DBusGMethodInvocation *context, + GError *error, + gpointer user_data) +{ + if (error) { + dbus_g_method_return_error (context, error); + return; + } + + /* Authorized */ + nm_platform_link_delete (nm_device_get_ifindex (device)); + dbus_g_method_return (context); +} + +static void +impl_device_delete (NMDevice *device, DBusGMethodInvocation *context) +{ + GError *error = NULL; + + if (!nm_device_is_software (device)) { + error = g_error_new_literal (NM_DEVICE_ERROR, + NM_DEVICE_ERROR_NOT_SOFTWARE, + "This device is not a software device"); + dbus_g_method_return_error (context, error); + g_error_free (error); + return; + } + + /* Ask the manager to authenticate this request for us */ + g_signal_emit (device, signals[AUTH_REQUEST], 0, + context, + NULL, + NM_AUTH_PERMISSION_NETWORK_CONTROL, + TRUE, + delete_cb, + NULL); +} + static void _device_activate (NMDevice *self, NMActRequest *req) { diff --git a/src/devices/nm-device.h b/src/devices/nm-device.h index d034c946dc..e0f5b89d8c 100644 --- a/src/devices/nm-device.h +++ b/src/devices/nm-device.h @@ -95,6 +95,7 @@ typedef enum { NM_DEVICE_ERROR_CONNECTION_INVALID, /*< nick=ConnectionInvalid >*/ NM_DEVICE_ERROR_NOT_ACTIVE, /*< nick=NotActive >*/ NM_DEVICE_ERROR_UNSUPPORTED_DEVICE_TYPE, /*< nick=UnsupportedDeviceType >*/ + NM_DEVICE_ERROR_NOT_SOFTWARE, /*< nick=NotSoftware >*/ } NMDeviceError; struct _NMDevice {