]>
Commit | Line | Data |
---|---|---|
1d080a25 JR |
1 | Index: thunar-volman/tvm-camera-device.h |
2 | =================================================================== | |
3 | --- thunar-volman/tvm-camera-device.h (revision 4898) | |
4 | +++ thunar-volman/tvm-camera-device.h (working copy) | |
5 | @@ -22,7 +22,7 @@ | |
6 | ||
7 | #include <thunar-volman/tvm-device.h> | |
8 | ||
9 | -G_BEGIN_DECLS; | |
10 | +G_BEGIN_DECLS | |
11 | ||
12 | gboolean tvm_camera_device_added (TvmPreferences *preferences, | |
13 | LibHalContext *context, | |
14 | @@ -30,6 +30,6 @@ | |
15 | const gchar *capability, | |
16 | GError **error) G_GNUC_INTERNAL; | |
17 | ||
18 | -G_END_DECLS; | |
19 | +G_END_DECLS | |
20 | ||
21 | #endif /* !__TVM_CAMERA_DEVICE_H__ */ | |
22 | Index: thunar-volman/tvm-block-device.h | |
23 | =================================================================== | |
24 | --- thunar-volman/tvm-block-device.h (revision 4898) | |
25 | +++ thunar-volman/tvm-block-device.h (working copy) | |
26 | @@ -22,7 +22,7 @@ | |
27 | ||
28 | #include <thunar-volman/tvm-device.h> | |
29 | ||
30 | -G_BEGIN_DECLS; | |
31 | +G_BEGIN_DECLS | |
32 | ||
33 | gboolean tvm_block_device_added (TvmPreferences *preferences, | |
34 | LibHalContext *context, | |
35 | @@ -30,6 +30,6 @@ | |
36 | const gchar *capability, | |
37 | GError **error) G_GNUC_INTERNAL; | |
38 | ||
39 | -G_END_DECLS; | |
40 | +G_END_DECLS | |
41 | ||
42 | #endif /* !__TVM_BLOCK_DEVICE_H__ */ | |
43 | Index: thunar-volman/tvm-input-device.h | |
44 | =================================================================== | |
45 | --- thunar-volman/tvm-input-device.h (revision 4898) | |
46 | +++ thunar-volman/tvm-input-device.h (working copy) | |
47 | @@ -22,7 +22,7 @@ | |
48 | ||
49 | #include <thunar-volman/tvm-device.h> | |
50 | ||
51 | -G_BEGIN_DECLS; | |
52 | +G_BEGIN_DECLS | |
53 | ||
54 | gboolean tvm_input_device_added (TvmPreferences *preferences, | |
55 | LibHalContext *context, | |
56 | @@ -30,6 +30,6 @@ | |
57 | const gchar *capability, | |
58 | GError **error) G_GNUC_INTERNAL; | |
59 | ||
60 | -G_END_DECLS; | |
61 | +G_END_DECLS | |
62 | ||
63 | #endif /* !__TVM_INPUT_DEVICE_H__ */ | |
64 | Index: thunar-volman/tvm-preferences-dialog.h | |
65 | =================================================================== | |
66 | --- thunar-volman/tvm-preferences-dialog.h (revision 4898) | |
67 | +++ thunar-volman/tvm-preferences-dialog.h (working copy) | |
68 | @@ -22,7 +22,7 @@ | |
69 | ||
70 | #include <thunar-volman/tvm-preferences.h> | |
71 | ||
72 | -G_BEGIN_DECLS; | |
73 | +G_BEGIN_DECLS | |
74 | ||
75 | typedef struct _TvmPreferencesDialogClass TvmPreferencesDialogClass; | |
76 | typedef struct _TvmPreferencesDialog TvmPreferencesDialog; | |
77 | @@ -38,6 +38,6 @@ | |
78 | ||
79 | GtkWidget *tvm_preferences_dialog_new (void) G_GNUC_INTERNAL G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT; | |
80 | ||
81 | -G_END_DECLS; | |
82 | +G_END_DECLS | |
83 | ||
84 | #endif /* !__TVM_PREFERENCES_DIALOG_H__ */ | |
85 | Index: thunar-volman/tvm-device.h | |
86 | =================================================================== | |
87 | --- thunar-volman/tvm-device.h (revision 4898) | |
88 | +++ thunar-volman/tvm-device.h (working copy) | |
89 | @@ -26,7 +26,7 @@ | |
90 | ||
91 | #include <thunar-volman/tvm-preferences.h> | |
92 | ||
93 | -G_BEGIN_DECLS; | |
94 | +G_BEGIN_DECLS | |
95 | ||
96 | /** | |
97 | * TvmDeviceCallback: | |
98 | @@ -53,6 +53,6 @@ | |
99 | const gchar *udi, | |
100 | GError **error) G_GNUC_INTERNAL; | |
101 | ||
102 | -G_END_DECLS; | |
103 | +G_END_DECLS | |
104 | ||
105 | #endif /* !__TVM_DEVICE_H__ */ | |
106 | Index: thunar-volman/tvm-pda-device.h | |
107 | =================================================================== | |
108 | --- thunar-volman/tvm-pda-device.h (revision 4898) | |
109 | +++ thunar-volman/tvm-pda-device.h (working copy) | |
110 | @@ -22,7 +22,7 @@ | |
111 | ||
112 | #include <thunar-volman/tvm-device.h> | |
113 | ||
114 | -G_BEGIN_DECLS; | |
115 | +G_BEGIN_DECLS | |
116 | ||
117 | gboolean tvm_pda_device_added (TvmPreferences *preferences, | |
118 | LibHalContext *context, | |
119 | @@ -30,6 +30,6 @@ | |
120 | const gchar *capability, | |
121 | GError **error) G_GNUC_INTERNAL; | |
122 | ||
123 | -G_END_DECLS; | |
124 | +G_END_DECLS | |
125 | ||
126 | #endif /* !__TVM_PDA_DEVICE_H__ */ | |
127 | Index: thunar-volman/tvm-command-entry.h | |
128 | =================================================================== | |
129 | --- thunar-volman/tvm-command-entry.h (revision 4898) | |
130 | +++ thunar-volman/tvm-command-entry.h (working copy) | |
131 | @@ -22,7 +22,7 @@ | |
132 | ||
133 | #include <exo/exo.h> | |
134 | ||
135 | -G_BEGIN_DECLS; | |
136 | +G_BEGIN_DECLS | |
137 | ||
138 | typedef struct _TvmCommandEntryClass TvmCommandEntryClass; | |
139 | typedef struct _TvmCommandEntry TvmCommandEntry; | |
140 | @@ -56,6 +56,6 @@ | |
141 | void tvm_command_entry_set_command (TvmCommandEntry *command_entry, | |
142 | const gchar *command) G_GNUC_INTERNAL; | |
143 | ||
144 | -G_END_DECLS; | |
145 | +G_END_DECLS | |
146 | ||
147 | #endif /* !__TVM_COMMAND_ENTRY_H__ */ | |
148 | Index: thunar-volman/xfce-heading.h | |
149 | =================================================================== | |
150 | --- thunar-volman/xfce-heading.h (revision 4898) | |
151 | +++ thunar-volman/xfce-heading.h (working copy) | |
152 | @@ -23,7 +23,7 @@ | |
153 | ||
154 | #include <gtk/gtk.h> | |
155 | ||
156 | -G_BEGIN_DECLS; | |
157 | +G_BEGIN_DECLS | |
158 | ||
159 | typedef struct _XfceHeadingPrivate XfceHeadingPrivate; | |
160 | typedef struct _XfceHeadingClass XfceHeadingClass; | |
161 | @@ -77,6 +77,6 @@ | |
162 | void xfce_heading_set_title (XfceHeading *heading, | |
163 | const gchar *title); | |
164 | ||
165 | -G_END_DECLS; | |
166 | +G_END_DECLS | |
167 | ||
168 | #endif /* !__XFCE_HEADING_H__ */ | |
169 | Index: thunar-volman/tvm-crypto-volume.c | |
170 | =================================================================== | |
171 | --- thunar-volman/tvm-crypto-volume.c (revision 0) | |
172 | +++ thunar-volman/tvm-crypto-volume.c (revision 0) | |
173 | @@ -0,0 +1,483 @@ | |
174 | +/* $Id$ */ | |
175 | +/*- | |
176 | + * Copyright (c) 2008 Benedikt Meurer <benny@xfce.org>. | |
177 | + * Copyright (c) 2008 Colin Leroy <colin@colino.net>. | |
178 | + * | |
179 | + * This program is free software; you can redistribute it and/or modify it | |
180 | + * under the terms of the GNU General Public License as published by the Free | |
181 | + * Software Foundation; either version 2 of the License, or (at your option) | |
182 | + * any later version. | |
183 | + * | |
184 | + * This program is distributed in the hope that it will be useful, but WITHOUT | |
185 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
186 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
187 | + * more details. | |
188 | + * | |
189 | + * You should have received a copy of the GNU General Public License along with | |
190 | + * this program; if not, write to the Free Software Foundation, Inc., 59 Temple | |
191 | + * Place, Suite 330, Boston, MA 02111-1307 USA | |
192 | + */ | |
193 | + | |
194 | +#ifdef HAVE_CONFIG_H | |
195 | +#include <config.h> | |
196 | +#endif | |
197 | + | |
198 | +#ifdef HAVE_SYS_TYPES_H | |
199 | +#include <sys/types.h> | |
200 | +#endif | |
201 | +#ifdef HAVE_SYS_STAT_H | |
202 | +#include <sys/stat.h> | |
203 | +#endif | |
204 | +#ifdef HAVE_SYS_WAIT_H | |
205 | +#include <sys/wait.h> | |
206 | +#endif | |
207 | + | |
208 | +#ifdef HAVE_MEMORY_H | |
209 | +#include <memory.h> | |
210 | +#endif | |
211 | +#include <stdio.h> | |
212 | +#ifdef HAVE_STRING_H | |
213 | +#include <string.h> | |
214 | +#endif | |
215 | +#include <errno.h> | |
216 | + | |
217 | +#include <dbus/dbus-glib-lowlevel.h> | |
218 | +#include <thunar-volman/tvm-block-device.h> | |
219 | +#include <thunar-volman/tvm-crypto-volume.h> | |
220 | +#include <libhal-storage.h> | |
221 | + | |
222 | +static void | |
223 | +tvm_crypto_volume_prompt_update_text (GtkEditable *editable, | |
224 | + gchar *new_text, | |
225 | + gint new_text_len, | |
226 | + gint *position, | |
227 | + gpointer data) | |
228 | +{ | |
229 | + gchar **response = (gchar **)data; | |
230 | + if (response == NULL) | |
231 | + return; | |
232 | + g_free(*response); | |
233 | + *response = gtk_editable_get_chars(editable, 0, -1); | |
234 | +} | |
235 | + | |
236 | +typedef struct _CryptoDialogValidate { | |
237 | + GtkWidget *dialog; | |
238 | + gint response; | |
239 | +} CryptoDialogValidate; | |
240 | + | |
241 | +void | |
242 | +tvm_crypto_volume_prompt_validate_text (GtkEntry *entry, | |
243 | + gpointer data) | |
244 | +{ | |
245 | + CryptoDialogValidate *validate_data = (CryptoDialogValidate *)data; | |
246 | + gtk_dialog_response(GTK_DIALOG(validate_data->dialog), validate_data->response); | |
247 | +} | |
248 | + | |
249 | +static void | |
250 | +tvm_crypto_volume_hal_device_removed (LibHalContext *context, | |
251 | + const gchar *udi) | |
252 | +{ | |
253 | + const gchar *dialog_udi; | |
254 | + GtkWidget *dialog = libhal_ctx_get_user_data (context); | |
255 | + | |
256 | + /* check if the active UDI of the dialog was removed */ | |
257 | + dialog_udi = g_object_get_data (G_OBJECT (dialog), "udi"); | |
258 | + if (exo_str_is_equal (dialog_udi, udi)) | |
259 | + { | |
260 | + /* cancel the dialog */ | |
261 | + gtk_dialog_response (GTK_DIALOG (dialog), GTK_RESPONSE_CANCEL); | |
262 | + } | |
263 | +} | |
264 | + | |
265 | + /** | |
266 | + * tvm_crypto_volume_ask_password: | |
267 | + * @context : a #LibHalContext. | |
268 | + * @udi : the UDI of the device being added, which is watched for removal. | |
269 | + * @icon : the icon or %NULL. | |
270 | + * @title : the prompt title. | |
271 | + * @response_text : the response text. | |
272 | + * @visible : whether text typed should be visible. | |
273 | + * @default_response : Which response to return on Enter. | |
274 | + * @primary_text : the primary prompt text. | |
275 | + * @secondary_text : the secondary prompt text. | |
276 | + * @first_button_text : the first button text. | |
277 | + * @... : %NULL-terminated list of button text, response id pairs. | |
278 | + * | |
279 | + * Return value: the selected response. | |
280 | + **/ | |
281 | +static gint | |
282 | +tvm_crypto_volume_ask_password (LibHalContext *context, | |
283 | + const gchar *udi, | |
284 | + const gchar *icon, | |
285 | + const gchar *title, | |
286 | + gchar **response_text, | |
287 | + gboolean visible, | |
288 | + gint default_response, | |
289 | + const gchar *primary_text, | |
290 | + const gchar *secondary_text, | |
291 | + const gchar *first_button_text, | |
292 | + ...) | |
293 | +{ | |
294 | + GtkWidget *dialog; | |
295 | + GtkWidget *image; | |
296 | + GtkWidget *label; | |
297 | + GtkWidget *hbox; | |
298 | + GtkWidget *vbox; | |
299 | + GtkWidget *entry; | |
300 | + DBusError derror; | |
301 | + va_list args; | |
302 | + gint response; | |
303 | + CryptoDialogValidate validate_data; | |
304 | + | |
305 | + g_return_val_if_fail (exo_hal_udi_validate (udi, -1, NULL), 0); | |
306 | + g_return_val_if_fail (context != NULL, GTK_RESPONSE_CANCEL); | |
307 | + | |
308 | + /* allocate a new dialog */ | |
309 | + dialog = gtk_dialog_new (); | |
310 | + gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE); | |
311 | + gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE); | |
312 | + g_object_set_data_full (G_OBJECT (dialog), "udi", g_strdup (udi), g_free); | |
313 | + gtk_container_set_border_width (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), 6); | |
314 | + gtk_container_set_border_width (GTK_CONTAINER (GTK_DIALOG (dialog)->action_area), 12); | |
315 | + | |
316 | + /* setup the specified title */ | |
317 | + if (G_LIKELY (title != NULL)) | |
318 | + gtk_window_set_title (GTK_WINDOW (dialog), title); | |
319 | + | |
320 | + /* setup the specified buttons */ | |
321 | + if (G_LIKELY (first_button_text != NULL)) | |
322 | + { | |
323 | + va_start (args, first_button_text); | |
324 | + for (response = va_arg (args, gint); first_button_text != NULL; ) | |
325 | + { | |
326 | + /* insert the button */ | |
327 | + gtk_dialog_add_button (GTK_DIALOG (dialog), first_button_text, response); | |
328 | + first_button_text = va_arg (args, const gchar *); | |
329 | + if (G_UNLIKELY (first_button_text == NULL)) | |
330 | + break; | |
331 | + response = va_arg (args, gint); | |
332 | + } | |
333 | + va_end (args); | |
334 | + } | |
335 | + | |
336 | + /* setup the hbox */ | |
337 | + hbox = gtk_hbox_new (FALSE, 12); | |
338 | + gtk_container_set_border_width (GTK_CONTAINER (hbox), 12); | |
339 | + gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), hbox, TRUE, TRUE, 0); | |
340 | + gtk_widget_show (hbox); | |
341 | + | |
342 | + /* setup the specified icon */ | |
343 | + if (G_LIKELY (icon != NULL)) | |
344 | + { | |
345 | + /* setup an image for the icon */ | |
346 | + image = gtk_image_new_from_icon_name (icon, GTK_ICON_SIZE_DIALOG); | |
347 | + gtk_misc_set_alignment (GTK_MISC (image), 0.0f, 0.0f); | |
348 | + gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0); | |
349 | + gtk_widget_show (image); | |
350 | + } | |
351 | + | |
352 | + /* setup the vbox */ | |
353 | + vbox = gtk_vbox_new (FALSE, 0); | |
354 | + gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 0); | |
355 | + gtk_widget_show (vbox); | |
356 | + g_object_set_data(G_OBJECT(dialog), "main_vbox", vbox); | |
357 | + | |
358 | + /* setup the primary text */ | |
359 | + label = gtk_label_new (primary_text); | |
360 | + gtk_label_set_line_wrap (GTK_LABEL (label), TRUE); | |
361 | + gtk_misc_set_alignment (GTK_MISC (label), 0.0f, 0.5f); | |
362 | + gtk_label_set_use_markup (GTK_LABEL (label), TRUE); | |
363 | + gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0); | |
364 | + gtk_widget_show (label); | |
365 | + | |
366 | + /* setup the secondary text */ | |
367 | + if (G_LIKELY (secondary_text != NULL)) | |
368 | + { | |
369 | + label = gtk_label_new (secondary_text); | |
370 | + gtk_label_set_line_wrap (GTK_LABEL (label), TRUE); | |
371 | + gtk_misc_set_alignment (GTK_MISC (label), 0.0f, 0.5f); | |
372 | + gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0); | |
373 | + gtk_widget_show (label); | |
374 | + g_object_set_data(G_OBJECT(dialog), "secondary_text", label); | |
375 | + } | |
376 | + | |
377 | + entry = gtk_entry_new(); | |
378 | + gtk_entry_set_visibility(GTK_ENTRY(entry), visible); | |
379 | + gtk_box_pack_start (GTK_BOX (vbox), entry, FALSE, FALSE, 0); | |
380 | + gtk_widget_show (entry); | |
381 | + g_object_set_data(G_OBJECT(dialog), "pass_entry", entry); | |
382 | + | |
383 | + /* initialize D-Bus error */ | |
384 | + dbus_error_init (&derror); | |
385 | + | |
386 | + /* setup HAL to watch the UDI for removal */ | |
387 | + libhal_ctx_set_user_data (context, dialog); | |
388 | + libhal_ctx_set_device_removed (context, tvm_crypto_volume_hal_device_removed); | |
389 | + libhal_device_property_watch_all (context, &derror); | |
390 | + | |
391 | + /* setup handler for the entered text */ | |
392 | + if (response_text) | |
393 | + *response_text = NULL; | |
394 | + g_signal_connect_after(G_OBJECT(entry), "insert-text", | |
395 | + G_CALLBACK(tvm_crypto_volume_prompt_update_text), | |
396 | + (gpointer) response_text); | |
397 | + validate_data.dialog = dialog; | |
398 | + validate_data.response = default_response; | |
399 | + g_signal_connect(G_OBJECT(entry), "activate", | |
400 | + G_CALLBACK(tvm_crypto_volume_prompt_validate_text), | |
401 | + (gpointer) &validate_data); | |
402 | + | |
403 | + /* run the dialog */ | |
404 | + response = gtk_dialog_run (GTK_DIALOG (dialog)); | |
405 | + gtk_widget_destroy(dialog); | |
406 | + | |
407 | + /* cleanup */ | |
408 | + libhal_ctx_set_device_removed (context, NULL); | |
409 | + libhal_ctx_set_user_data (context, NULL); | |
410 | + dbus_error_free (&derror); | |
411 | + | |
412 | + return response; | |
413 | +} | |
414 | + | |
415 | +static gboolean | |
416 | +progress_pulse(gpointer data) | |
417 | +{ | |
418 | + GtkProgressBar *progress = GTK_PROGRESS_BAR(data); | |
419 | + g_return_val_if_fail(progress != NULL, FALSE); | |
420 | + | |
421 | + gtk_progress_bar_pulse(progress); | |
422 | + | |
423 | + return TRUE; | |
424 | +} | |
425 | + | |
426 | +static void | |
427 | +tvm_crypto_volume_dbus_call_done (DBusPendingCall *call, | |
428 | + void *user_data) | |
429 | +{ | |
430 | + gtk_main_quit(); | |
431 | +} | |
432 | + | |
433 | +static gchar * | |
434 | +tvm_crypto_volume_mount_install_crypto_volume (LibHalContext *context, | |
435 | + const gchar *udi, | |
436 | + LibHalVolume *volume, | |
437 | + const gchar *password, | |
438 | + gboolean *pass_error, | |
439 | + GError **error) | |
440 | +{ | |
441 | + gchar *plain_udi = NULL; | |
442 | + DBusMessage *message = NULL; | |
443 | + DBusMessage *result = NULL; | |
444 | + DBusConnection *dbus_connection = NULL; | |
445 | + DBusPendingCall *call = NULL; | |
446 | + DBusError derror; | |
447 | + dbus_bool_t send_err; | |
448 | + *pass_error = FALSE; | |
449 | + GtkWidget *window = NULL; | |
450 | + GtkWidget *label, *vbox, *hbox; | |
451 | + GtkWidget *wait_progress; | |
452 | + GtkWidget *image; | |
453 | + guint animator_id; | |
454 | + g_clear_error(error); | |
455 | + | |
456 | + window = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
457 | + gtk_container_set_border_width(GTK_CONTAINER(window), 8); | |
458 | + gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER); | |
459 | + gtk_window_set_title(GTK_WINDOW(window), _("Encrypted volume")); | |
460 | + gtk_window_set_modal(GTK_WINDOW(window), TRUE); | |
461 | + gtk_window_set_resizable(GTK_WINDOW(window), FALSE); | |
462 | + | |
463 | + vbox = gtk_vbox_new(FALSE, 6); | |
464 | + hbox = gtk_hbox_new(FALSE, 6); | |
465 | + image = gtk_image_new_from_icon_name ("gtk-dialog-authentication", GTK_ICON_SIZE_DIALOG); | |
466 | + gtk_misc_set_alignment (GTK_MISC (image), 0.0f, 0.0f); | |
467 | + gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0); | |
468 | + gtk_widget_show (image); | |
469 | + | |
470 | + label = gtk_label_new(_("<span weight=\"bold\" size=\"larger\">Mounting encrypted volume...</span>")); | |
471 | + gtk_label_set_use_markup(GTK_LABEL(label), TRUE); | |
472 | + gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
473 | + gtk_box_pack_start(GTK_BOX(vbox), label, TRUE, FALSE, 0); | |
474 | + | |
475 | + label = gtk_label_new(_("Setting up the crypto layer...")); | |
476 | + gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
477 | + gtk_box_pack_start(GTK_BOX(vbox), label, TRUE, FALSE, 0); | |
478 | + | |
479 | + wait_progress = gtk_progress_bar_new(); | |
480 | + gtk_box_pack_start(GTK_BOX(vbox), wait_progress, TRUE, FALSE, 0); | |
481 | + | |
482 | + gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE, FALSE, 0); | |
483 | + | |
484 | + gtk_container_add(GTK_CONTAINER(window), hbox); | |
485 | + gtk_widget_show_all(hbox); | |
486 | + animator_id = g_timeout_add(100, progress_pulse, wait_progress); | |
487 | + | |
488 | + gtk_widget_show_now(window); | |
489 | + | |
490 | + message = dbus_message_new_method_call ("org.freedesktop.Hal", udi, | |
491 | + "org.freedesktop.Hal.Device.Volume.Crypto", | |
492 | + "Setup"); | |
493 | + | |
494 | + if (G_UNLIKELY (message == NULL)) | |
495 | + { | |
496 | + /* out of memory */ | |
497 | +oom: g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_NOMEM, g_strerror (ENOMEM)); | |
498 | + goto out; | |
499 | + } | |
500 | + | |
501 | + if (!dbus_message_append_args (message, | |
502 | + DBUS_TYPE_STRING, &password, | |
503 | + DBUS_TYPE_INVALID)) { | |
504 | + dbus_message_unref (message); | |
505 | + goto oom; | |
506 | + } | |
507 | + | |
508 | + dbus_error_init (&derror); | |
509 | + | |
510 | + dbus_connection = dbus_bus_get (DBUS_BUS_SYSTEM, &derror); | |
511 | + if (G_UNLIKELY (dbus_connection == NULL)) | |
512 | + { | |
513 | + /* propagate the error */ | |
514 | + dbus_set_g_error (error, &derror); | |
515 | + goto out; | |
516 | + } | |
517 | + | |
518 | + send_err = dbus_connection_send_with_reply (dbus_connection, message, &call, -1); | |
519 | + if (G_UNLIKELY (send_err == FALSE)) | |
520 | + { | |
521 | + /* release the result */ | |
522 | + dbus_message_unref (message); | |
523 | + goto out; | |
524 | + } | |
525 | + | |
526 | + dbus_pending_call_set_notify(call, tvm_crypto_volume_dbus_call_done, NULL, NULL); | |
527 | + gtk_main(); | |
528 | + | |
529 | + result = dbus_pending_call_steal_reply(call); | |
530 | + /* release the message */ | |
531 | + dbus_message_unref (message); | |
532 | + | |
533 | + /* release the connection */ | |
534 | + dbus_connection_unref (dbus_connection); | |
535 | + | |
536 | + if (G_UNLIKELY (dbus_set_error_from_message(&derror, result))) | |
537 | + { | |
538 | + /* try to translate the error appropriately */ | |
539 | + if (strcmp (derror.name, "org.freedesktop.Hal.Device.Volume.PermissionDenied") == 0) | |
540 | + { | |
541 | + /* TRANSLATORS: The user tried to setup a crypto layer (LUKS-encrpyted volume) but got Permission denied. */ | |
542 | + g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, _("You are not privileged to setup the crypto layer")); | |
543 | + } | |
544 | + else if (strcmp (derror.name, "org.freedesktop.Hal.Device.Volume.Crypto.SetupPasswordError") == 0) | |
545 | + { | |
546 | + /* TRANSLATORS: The user tried to setup a crypto layer (LUKS-encrpyted volume) and typed the wrong password. */ | |
547 | + g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, _("Wrong password")); | |
548 | + *pass_error = TRUE; | |
549 | + } | |
550 | + else | |
551 | + { | |
552 | + /* no precise error message, use the HAL one */ | |
553 | + dbus_set_g_error (error, &derror); | |
554 | + } | |
555 | + | |
556 | + /* release the DBus error */ | |
557 | + dbus_error_free (&derror); | |
558 | + dbus_message_unref (result); | |
559 | + plain_udi = NULL; | |
560 | + goto out; | |
561 | + } | |
562 | + else | |
563 | + { | |
564 | + dbus_message_unref (result); | |
565 | + plain_udi = libhal_volume_crypto_get_clear_volume_udi (context, volume); | |
566 | + } | |
567 | + | |
568 | +out: | |
569 | + g_source_remove(animator_id); | |
570 | + gtk_widget_destroy(window); | |
571 | + return plain_udi; | |
572 | +} | |
573 | + | |
574 | +/** | |
575 | + * tvm_crypto_volume_setup: | |
576 | + * @preferences : a #TvmPreferences. | |
577 | + * @context : a #LibHalContext. | |
578 | + * @udi : the HAL volume UDI of the newly added crypto volume. | |
579 | + * @error : return location for errors or %NULL. | |
580 | + * | |
581 | + * Tries to setup the crypto layer for the volume with the | |
582 | + * specified @udi. | |
583 | + * | |
584 | + * Return value: %TRUE if handled, %FALSE if not handled or an | |
585 | + * unrecoverable error occurred. | |
586 | + */ | |
587 | +gboolean | |
588 | +tvm_crypto_volume_setup (TvmPreferences *preferences, | |
589 | + LibHalContext *context, | |
590 | + const gchar *udi, | |
591 | + GError **error) | |
592 | +{ | |
593 | + gchar *password = NULL; | |
594 | + gboolean pass_error = FALSE; | |
595 | + gint num_tries = 0; | |
596 | + gchar *plain_udi = NULL; | |
597 | + LibHalVolume *volume = NULL; | |
598 | + gboolean result = FALSE; | |
599 | + | |
600 | + g_return_val_if_fail (exo_hal_udi_validate (udi, -1, NULL), FALSE); | |
601 | + g_return_val_if_fail (TVM_IS_PREFERENCES (preferences), FALSE); | |
602 | + g_return_val_if_fail (error == NULL || *error == NULL, FALSE); | |
603 | + g_return_val_if_fail (context != NULL, FALSE); | |
604 | + | |
605 | + volume = libhal_volume_from_udi (context, udi); | |
606 | + g_return_val_if_fail(volume != NULL, FALSE); | |
607 | + plain_udi = libhal_volume_crypto_get_clear_volume_udi (context, volume); | |
608 | + if (plain_udi != NULL) { | |
609 | + libhal_volume_free(volume); | |
610 | + libhal_free_string(plain_udi); | |
611 | + return TRUE; | |
612 | + } | |
613 | + | |
614 | + for (num_tries = 0; num_tries < 3; num_tries++) { | |
615 | + gint response,len; | |
616 | + response = tvm_crypto_volume_ask_password (context, udi, "gtk-dialog-authentication", _("Encrypted volume"), | |
617 | + &password, FALSE, GTK_RESPONSE_OK, | |
618 | + pass_error? _("<span weight=\"bold\" size=\"larger\">Wrong password.</span>") | |
619 | + :_("<span weight=\"bold\" size=\"larger\">This volume is encrypted.</span>"), | |
620 | + _("Please enter your password to decrypt and mount the volume."), | |
621 | + _("Ig_nore"), GTK_RESPONSE_CANCEL, | |
622 | + _("_Mount"), GTK_RESPONSE_OK, | |
623 | + NULL); | |
624 | + if (response == GTK_RESPONSE_CANCEL || response == GTK_RESPONSE_DELETE_EVENT) { | |
625 | + g_clear_error(error); | |
626 | + num_tries = 3; | |
627 | + } else if (password) { | |
628 | + plain_udi = tvm_crypto_volume_mount_install_crypto_volume(context, udi, volume, password, &pass_error, error); | |
629 | + } | |
630 | + if (password) { | |
631 | + len = strlen(password); | |
632 | + memset(password, 0, len); | |
633 | + g_debug("zeroed password %p", password); | |
634 | + g_free(password); | |
635 | + } | |
636 | + if (*error != NULL && !pass_error) { | |
637 | + /* display an error message to the user (exo-mount won't do it as it won't see the clear device */ | |
638 | + GtkWidget *message = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, | |
639 | + GTK_MESSAGE_ERROR, | |
640 | + GTK_BUTTONS_CLOSE, | |
641 | + "%s.", _("Failed to setup the encrypted volume")); | |
642 | + gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (message), "%s.", (*error)->message); | |
643 | + gtk_dialog_run (GTK_DIALOG (message)); | |
644 | + gtk_widget_destroy (message); | |
645 | + break; | |
646 | + } | |
647 | + if (plain_udi != NULL) { | |
648 | + libhal_free_string(plain_udi); | |
649 | + result = TRUE; | |
650 | + break; | |
651 | + } | |
652 | + } | |
653 | + return result; | |
654 | +} | |
655 | + | |
656 | + | |
657 | Index: thunar-volman/tvm-printer-device.h | |
658 | =================================================================== | |
659 | --- thunar-volman/tvm-printer-device.h (revision 4898) | |
660 | +++ thunar-volman/tvm-printer-device.h (working copy) | |
661 | @@ -22,7 +22,7 @@ | |
662 | ||
663 | #include <thunar-volman/tvm-device.h> | |
664 | ||
665 | -G_BEGIN_DECLS; | |
666 | +G_BEGIN_DECLS | |
667 | ||
668 | gboolean tvm_printer_device_added (TvmPreferences *preferences, | |
669 | LibHalContext *context, | |
670 | @@ -30,6 +30,6 @@ | |
671 | const gchar *capability, | |
672 | GError **error) G_GNUC_INTERNAL; | |
673 | ||
674 | -G_END_DECLS; | |
675 | +G_END_DECLS | |
676 | ||
677 | #endif /* !__TVM_PRINTER_DEVICE_H__ */ | |
678 | Index: thunar-volman/tvm-crypto-volume.h | |
679 | =================================================================== | |
680 | --- thunar-volman/tvm-crypto-volume.h (revision 0) | |
681 | +++ thunar-volman/tvm-crypto-volume.h (revision 0) | |
682 | @@ -0,0 +1,35 @@ | |
683 | +/* $Id$ */ | |
684 | +/*- | |
685 | + * Copyright (c) 2008 Benedikt Meurer <benny@xfce.org>. | |
686 | + * Copyright (c) 2008 Colin Leroy <colin@colino.net>. | |
687 | + * | |
688 | + * This program is free software; you can redistribute it and/or modify it | |
689 | + * under the terms of the GNU General Public License as published by the Free | |
690 | + * Software Foundation; either version 2 of the License, or (at your option) | |
691 | + * any later version. | |
692 | + * | |
693 | + * This program is distributed in the hope that it will be useful, but WITHOUT | |
694 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
695 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
696 | + * more details. | |
697 | + * | |
698 | + * You should have received a copy of the GNU General Public License along with | |
699 | + * this program; if not, write to the Free Software Foundation, Inc., 59 Temple | |
700 | + * Place, Suite 330, Boston, MA 02111-1307 USA | |
701 | + */ | |
702 | + | |
703 | +#ifndef __TVM_CRYPTO_VOLUME_H__ | |
704 | +#define __TVM_CRYPTO_VOLUME_H__ | |
705 | + | |
706 | +#include <thunar-volman/tvm-device.h> | |
707 | + | |
708 | +G_BEGIN_DECLS | |
709 | + | |
710 | +gboolean tvm_crypto_volume_setup (TvmPreferences *preferences, | |
711 | + LibHalContext *context, | |
712 | + const gchar *udi, | |
713 | + GError **error) G_GNUC_INTERNAL; | |
714 | + | |
715 | +G_END_DECLS | |
716 | + | |
717 | +#endif /* !__TVM_CRYPTO_VOLUME_H__ */ | |
718 | Index: thunar-volman/xfce-titled-dialog.h | |
719 | =================================================================== | |
720 | --- thunar-volman/xfce-titled-dialog.h (revision 4898) | |
721 | +++ thunar-volman/xfce-titled-dialog.h (working copy) | |
722 | @@ -23,7 +23,7 @@ | |
723 | ||
724 | #include <gtk/gtk.h> | |
725 | ||
726 | -G_BEGIN_DECLS; | |
727 | +G_BEGIN_DECLS | |
728 | ||
729 | typedef struct _XfceTitledDialogPrivate XfceTitledDialogPrivate; | |
730 | typedef struct _XfceTitledDialogClass XfceTitledDialogClass; | |
731 | @@ -70,6 +70,6 @@ | |
732 | void xfce_titled_dialog_set_subtitle (XfceTitledDialog *titled_dialog, | |
733 | const gchar *subtitle); | |
734 | ||
735 | -G_END_DECLS; | |
736 | +G_END_DECLS | |
737 | ||
738 | #endif /* !__XFCE_TITLED_DIALOG_H__ */ | |
739 | Index: thunar-volman/tvm-preferences.h | |
740 | =================================================================== | |
741 | --- thunar-volman/tvm-preferences.h (revision 4898) | |
742 | +++ thunar-volman/tvm-preferences.h (working copy) | |
743 | @@ -22,7 +22,7 @@ | |
744 | ||
745 | #include <exo/exo.h> | |
746 | ||
747 | -G_BEGIN_DECLS; | |
748 | +G_BEGIN_DECLS | |
749 | ||
750 | typedef struct _TvmPreferencesClass TvmPreferencesClass; | |
751 | typedef struct _TvmPreferences TvmPreferences; | |
752 | @@ -38,6 +38,6 @@ | |
753 | ||
754 | TvmPreferences *tvm_preferences_get (void); | |
755 | ||
756 | -G_END_DECLS; | |
757 | +G_END_DECLS | |
758 | ||
759 | #endif /* !__TVM_PREFERENCES_H__ */ | |
760 | Index: thunar-volman/tvm-pango-extensions.h | |
761 | =================================================================== | |
762 | --- thunar-volman/tvm-pango-extensions.h (revision 4898) | |
763 | +++ thunar-volman/tvm-pango-extensions.h (working copy) | |
764 | @@ -22,7 +22,7 @@ | |
765 | ||
766 | #include <pango/pango.h> | |
767 | ||
768 | -G_BEGIN_DECLS; | |
769 | +G_BEGIN_DECLS | |
770 | ||
771 | PangoAttrList *tvm_pango_attr_list_big (void) G_GNUC_CONST G_GNUC_INTERNAL; | |
772 | PangoAttrList *tvm_pango_attr_list_big_bold (void) G_GNUC_CONST G_GNUC_INTERNAL; | |
773 | @@ -31,6 +31,6 @@ | |
774 | PangoAttrList *tvm_pango_attr_list_small_italic (void) G_GNUC_CONST G_GNUC_INTERNAL; | |
775 | PangoAttrList *tvm_pango_attr_list_underline_single (void) G_GNUC_CONST G_GNUC_INTERNAL; | |
776 | ||
777 | -G_END_DECLS; | |
778 | +G_END_DECLS | |
779 | ||
780 | #endif /* !__TVM_PANGO_EXTENSIONS_H__ */ | |
781 | Index: thunar-volman/tvm-run.h | |
782 | =================================================================== | |
783 | --- thunar-volman/tvm-run.h (revision 4898) | |
784 | +++ thunar-volman/tvm-run.h (working copy) | |
785 | @@ -22,7 +22,7 @@ | |
786 | ||
787 | #include <thunar-volman/tvm-device.h> | |
788 | ||
789 | -G_BEGIN_DECLS; | |
790 | +G_BEGIN_DECLS | |
791 | ||
792 | gboolean tvm_run_cdburner (TvmPreferences *preferences, | |
793 | LibHalContext *context, | |
794 | @@ -41,6 +41,6 @@ | |
795 | const gchar *mount_point, | |
796 | GError **error) G_GNUC_INTERNAL; | |
797 | ||
798 | -G_END_DECLS; | |
799 | +G_END_DECLS | |
800 | ||
801 | #endif /* !__TVM_RUN_H__ */ | |
802 | Index: thunar-volman/Makefile.am | |
803 | =================================================================== | |
804 | --- thunar-volman/Makefile.am (revision 4898) | |
805 | +++ thunar-volman/Makefile.am (working copy) | |
806 | @@ -21,6 +21,8 @@ | |
807 | tvm-camera-device.h \ | |
808 | tvm-command-entry.c \ | |
809 | tvm-command-entry.h \ | |
810 | + tvm-crypto-volume.c \ | |
811 | + tvm-crypto-volume.h \ | |
812 | tvm-device.c \ | |
813 | tvm-device.h \ | |
814 | tvm-input-device.c \ | |
815 | Index: thunar-volman/tvm-prompt.h | |
816 | =================================================================== | |
817 | --- thunar-volman/tvm-prompt.h (revision 4898) | |
818 | +++ thunar-volman/tvm-prompt.h (working copy) | |
819 | @@ -22,7 +22,7 @@ | |
820 | ||
821 | #include <thunar-volman/tvm-device.h> | |
822 | ||
823 | -G_BEGIN_DECLS; | |
824 | +G_BEGIN_DECLS | |
825 | ||
826 | enum | |
827 | { | |
828 | @@ -46,6 +46,6 @@ | |
829 | const gchar *first_button_text, | |
830 | ...) G_GNUC_INTERNAL G_GNUC_NULL_TERMINATED; | |
831 | ||
832 | -G_END_DECLS; | |
833 | +G_END_DECLS | |
834 | ||
835 | #endif /* !__TVM_PROMPT_H__ */ | |
836 | Index: thunar-volman/tvm-block-device.c | |
837 | =================================================================== | |
838 | --- thunar-volman/tvm-block-device.c (revision 4898) | |
839 | +++ thunar-volman/tvm-block-device.c (working copy) | |
840 | @@ -1,6 +1,6 @@ | |
841 | /* $Id$ */ | |
842 | /*- | |
843 | - * Copyright (c) 2007 Benedikt Meurer <benny@xfce.org>. | |
844 | + * Copyright (c) 2007-2008 Benedikt Meurer <benny@xfce.org>. | |
845 | * | |
846 | * This program is free software; you can redistribute it and/or modify it | |
847 | * under the terms of the GNU General Public License as published by the Free | |
848 | @@ -42,6 +42,7 @@ | |
849 | #include <dbus/dbus-glib-lowlevel.h> | |
850 | ||
851 | #include <thunar-volman/tvm-block-device.h> | |
852 | +#include <thunar-volman/tvm-crypto-volume.h> | |
853 | #include <thunar-volman/tvm-prompt.h> | |
854 | #include <thunar-volman/tvm-run.h> | |
855 | ||
856 | @@ -609,6 +610,7 @@ | |
857 | gboolean autoplay; | |
858 | gboolean is_cdrom; | |
859 | gboolean has_filesystem; | |
860 | + gboolean has_crypto; | |
861 | gchar *storage_udi; | |
862 | gchar *drive_type; | |
863 | gchar *fsusage; | |
864 | @@ -749,20 +751,30 @@ | |
865 | libhal_free_string (storage_udi); | |
866 | } | |
867 | ||
868 | - /* make sure the volume has a mountable filesystem */ | |
869 | + /* determine the file system usage of the volume */ | |
870 | fsusage = libhal_device_get_property_string (context, udi, "volume.fsusage", NULL); | |
871 | - has_filesystem = (G_LIKELY (fsusage && strcmp (fsusage, "filesystem") == 0)); | |
872 | + has_crypto = (G_UNLIKELY (fsusage != NULL && strcmp (fsusage, "crypto") == 0)); | |
873 | + has_filesystem = (G_LIKELY (fsusage != NULL && strcmp (fsusage, "filesystem") == 0)); | |
874 | libhal_free_string (fsusage); | |
875 | - if (G_UNLIKELY (!has_filesystem)) | |
876 | - return FALSE; | |
877 | ||
878 | - /* check if we should automount drives, otherwise, we're done here */ | |
879 | - g_object_get (G_OBJECT (preferences), "automount-drives", &automount, NULL); | |
880 | - if (G_UNLIKELY (!automount)) | |
881 | - return FALSE; | |
882 | + /* check if we have a crypto volume to setup here */ | |
883 | + if (G_UNLIKELY (has_crypto)) | |
884 | + { | |
885 | + /* try to setup the crypto volume */ | |
886 | + return tvm_crypto_volume_setup (preferences, context, udi, error); | |
887 | + } | |
888 | + else if (G_LIKELY (has_filesystem)) | |
889 | + { | |
890 | + /* check if we should automount drives, otherwise, we're done here */ | |
891 | + g_object_get (G_OBJECT (preferences), "automount-drives", &automount, NULL); | |
892 | + if (G_UNLIKELY (!automount)) | |
893 | + return FALSE; | |
894 | ||
895 | - /* try to mount the block device */ | |
896 | - return tvm_block_device_mount (preferences, context, udi, error); | |
897 | + /* try to mount the block device */ | |
898 | + return tvm_block_device_mount (preferences, context, udi, error); | |
899 | + } | |
900 | + | |
901 | + return FALSE; | |
902 | } | |
903 | ||
904 |