]> git.pld-linux.org Git - packages/exo.git/blame - libexo-teardown-crypto-on-eject.patch
- updated to 0.3.100
[packages/exo.git] / libexo-teardown-crypto-on-eject.patch
CommitLineData
b5b385b8
JR
1Index: exo-mount/exo-mount-hal.c
2===================================================================
3--- exo-mount/exo-mount-hal.c (revision 27040)
4+++ exo-mount/exo-mount-hal.c (working copy)
5@@ -547,10 +547,20 @@
6 DBusMessage *message;
7 DBusMessage *result;
8 DBusError derror;
9+ const gchar *backing_udi = NULL;
10
11 g_return_val_if_fail (device != NULL, FALSE);
12 g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
13
14+ /* see if the udi is a crypto fs, in which case we'll have to tear down the crypto layer. */
15+ backing_udi = libhal_volume_crypto_get_backing_volume_udi(device->volume);
16+
17+ if (backing_udi)
18+ {
19+ /* never eject a LUKS-encrypted device */
20+ return exo_mount_hal_device_unmount(device, error);
21+ }
22+
23 /* allocate the D-Bus message for the "Eject" method */
24 message = dbus_message_new_method_call ("org.freedesktop.Hal", device->udi, "org.freedesktop.Hal.Device.Volume", "Eject");
25 if (G_UNLIKELY (message == NULL))
26@@ -873,8 +883,73 @@
27 }
28
29
30+static gboolean
31+exo_mount_teardown_crypto_volume(const gchar *udi, GError **error)
32+{
33+ DBusMessage *message = NULL;
34+ DBusMessage *result = NULL;
35+ DBusError derror;
36
37+ message = dbus_message_new_method_call ("org.freedesktop.Hal", udi,
38+ "org.freedesktop.Hal.Device.Volume.Crypto",
39+ "Teardown");
40
41+ if (G_UNLIKELY (message == NULL))
42+ {
43+ /* out of memory */
44+oom: g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_NOMEM, g_strerror (ENOMEM));
45+ return FALSE;
46+ }
47+
48+ if (!dbus_message_append_args (message,
49+ DBUS_TYPE_INVALID)) {
50+ dbus_message_unref (message);
51+ goto oom;
52+ }
53+
54+ dbus_error_init (&derror);
55+
56+ result = dbus_connection_send_with_reply_and_block (dbus_connection, message, -1, &derror);
57+ if (G_LIKELY (result != NULL))
58+ {
59+ /* check if an error was returned */
60+ if (dbus_message_get_type (result) == DBUS_MESSAGE_TYPE_ERROR)
61+ dbus_set_error_from_message (&derror, result);
62+
63+ /* release the result */
64+ dbus_message_unref (result);
65+ }
66+
67+ /* release the message */
68+ dbus_message_unref (message);
69+
70+ if (G_UNLIKELY (dbus_error_is_set (&derror)))
71+ {
72+ /* try to translate the error appropriately */
73+ if (strcmp (derror.name, "org.freedesktop.Hal.Device.Volume.PermissionDenied") == 0)
74+ {
75+ /* TRANSLATORS: The user tried to eject a device although he's not privileged to do so. */
76+ g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, _("You are not privileged to teardown the crypto layer"));
77+ }
78+ else if (strcmp (derror.name, "org.freedesktop.Hal.Device.Volume.Busy") == 0)
79+ {
80+ /* TRANSLATORS: An application is blocking a mounted volume from being ejected. */
81+ g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, _("An application is preventing the crypto layer from being torn down"));
82+ }
83+ else
84+ {
85+ /* no precise error message, use the HAL one */
86+ exo_mount_hal_propagate_error (error, &derror);
87+ }
88+
89+ /* release the DBus error */
90+ dbus_error_free (&derror);
91+ return FALSE;
92+ }
93+ return TRUE;
94+}
95+
96+
97 /**
98 * exo_mount_hal_device_unmount:
99 * @device : an #ExoMountHalDevice.
100@@ -894,10 +969,14 @@
101 DBusMessage *message;
102 DBusMessage *result;
103 DBusError derror;
104+ const gchar *backing_udi = NULL;
105
106 g_return_val_if_fail (device != NULL, FALSE);
107 g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
108
109+ /* see if the udi is a crypto fs, in which case we'll have to teardown the crypto layer. */
110+ backing_udi = libhal_volume_crypto_get_backing_volume_udi(device->volume);
111+
112 /* allocate the D-Bus message for the "Unmount" method */
113 message = dbus_message_new_method_call ("org.freedesktop.Hal", device->udi, "org.freedesktop.Hal.Device.Volume", "Unmount");
114 if (G_UNLIKELY (message == NULL))
115@@ -955,7 +1034,7 @@
116 {
117 /* Ups, volume not mounted, we succeed! */
118 dbus_error_free (&derror);
119- return TRUE;
120+ goto finish;
121 }
122 else
123 {
124@@ -968,6 +1047,11 @@
125 return FALSE;
126 }
127
128+finish:
129+ if (G_UNLIKELY(backing_udi != NULL))
130+ {
131+ return exo_mount_teardown_crypto_volume(backing_udi, error);
132+ }
133 return TRUE;
134 }
135
This page took 0.059451 seconds and 4 git commands to generate.