tomb

the crypto undertaker
git clone git://parazyd.org/tomb.git
Log | Files | Refs | README | LICENSE

commit 36565e2ef4894c996a29d18f49aae2cfc6fd0c61
parent bee816111f2e597e9080ba625de5f489e8ba2cad
Author: Jaromil <jaromil@dyne.org>
Date:   Sun, 16 Jan 2011 23:43:45 +0100

dropped c++ dependency plus various fixes

Diffstat:
Mconfigure.ac | 1-
Msrc/Makefile.am | 14+++++++++-----
Msrc/tomb | 27++++++++++++++++-----------
Rsrc/tomb-notify.cpp -> src/tomb-notify.c | 0
Msrc/tomb-open | 12+++---------
Asrc/tomb-status.c | 220+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dsrc/tomb-status.cpp | 219-------------------------------------------------------------------------------
7 files changed, 248 insertions(+), 245 deletions(-)

diff --git a/configure.ac b/configure.ac @@ -64,7 +64,6 @@ AC_CONFIG_SRCDIR([src/tomb]) dnl Checks for reguired programs. AC_PROG_CC -AC_PROG_CXX AC_PROG_INSTALL AC_CHECK_PROG(have_zsh,zsh,yes,no) diff --git a/src/Makefile.am b/src/Makefile.am @@ -1,15 +1,19 @@ bin_SCRIPTS = tomb tomb-open -bin_PROGRAMS = tomb-status tomb-notify +bin_PROGRAMS = tomb-status tomb-notify tomb-askpass -tomb_status_SOURCES = tomb-status.cpp +tomb_status_SOURCES = tomb-status.c tomb_status_LDADD = @GTK2_LIBS@ @NOTIFY_LIBS@ -tomb_status_CXXFLAGS = @GTK2_CFLAGS@ @NOTIFY_CFLAGS@ +tomb_status_CFLAGS = @GTK2_CFLAGS@ @NOTIFY_CFLAGS@ -tomb_notify_SOURCES = tomb-notify.cpp +tomb_notify_SOURCES = tomb-notify.c tomb_notify_LDADD = @NOTIFY_LIBS@ -tomb_notify_CXXFLAGS = @NOTIFY_CFLAGS@ +tomb_notify_CFLAGS = @NOTIFY_CFLAGS@ + +tomb_askpass_SOURCES = tomb-askpass.c +tomb_askpass_LDADD = @GTK2_LIBS@ +tomb_askpass_CFLAGS = @GTK2_CFLAGS@ EXTRA_DIST = monmort.xpm pixmapdir = $(prefix)/share/pixmaps diff --git a/src/tomb b/src/tomb @@ -43,9 +43,9 @@ fi # which wipe command to use which wipe > /dev/null if [ $? = 0 ]; then - WIPE="wipe -f -s -q" + WIPE=(wipe -f -s -q) else - WIPE="rm -f" + WIPE=(rm -f) fi # usb auto detect using dmesg @@ -96,14 +96,19 @@ ask_usbkey() { # user interface (just to ask the password) ask_password() { - xhost 2>/dev/null + exec_as_user xhost 2>/dev/null if [ $? = 0 ]; then # we have access to the X display - if [ -x /usr/bin/ssh-askpass ]; then # debian has this - export scolopendro="`ssh-askpass "Tomb: provide the password to unlock"`" + exec_as_user which tomb-askpass + if [ $? = 0 ]; then + keyname=`echo $enc_key | cut -d. -f1` + export scolopendro="`exec_as_user tomb-askpass $keyname`" + return + elif [ -x /usr/bin/ssh-askpass ]; then # debian has this + export scolopendro="`exec_as_user ssh-askpass "Tomb: provide the password to unlock"`" return fi - + else # we'll collect the password from commandline act "Tomb: provide the password to unlock" @@ -122,8 +127,7 @@ ask_password() { # drop privileges exec_as_user() { func "executing as user '$SUDO_USER': ${(f)@}" - sudo -u $SUDO_USER ${@} & - disown + sudo -u $SUDO_USER ${@} } @@ -288,7 +292,7 @@ create_tomb() { cryptsetup --key-file ${keytmp} --cipher aes luksOpen ${nstloop} tomb.tmp - ${WIPE} ${keytmp} + ${WIPE[@]} ${keytmp} notice "Your tomb is ready on ${FILE} and secured with key ${FILE}.gpg" act "Would you like to save the key on an external usb device?" @@ -306,7 +310,7 @@ create_tomb() { mkdir -p ${usbkey_mount}/.tomb cp -v ${FILE}.gpg ${usbkey_mount}/.tomb/ chmod -R go-rwx ${usbkey_mount}/.tomb - rm -rf ${FILE}.gpg + ${WIPE[@]} ${FILE}.gpg fi fi # cryptsetup luksDump ${nstloop} @@ -418,7 +422,8 @@ mount_tomb() { mount -o rw,noatime,nodev /dev/mapper/${mapper} ${MOUNT} notice "encrypted storage $FILE succesfully mounted on $MOUNT" - exec_as_user tomb-status ${mapper} ${FILE} ${MOUNT} + exec_as_user tomb-status ${mapper} ${FILE} ${MOUNT} & + disown } umount_tomb() { diff --git a/src/tomb-notify.cpp b/src/tomb-notify.c diff --git a/src/tomb-open b/src/tomb-open @@ -22,13 +22,6 @@ # startup wrapper to open tombs -explore() { - which ${1} > /dev/null - if [ $? = 0 ]; then - ${1} ${2} - exit 0 - fi -} try() { which ${1} > /dev/null @@ -102,7 +95,7 @@ Create a new Tomb the computer you are using. If you will, I'll be your Crypto Undertaker. - Do you want to proceed, Master? (yes/no)" + Do you want to proceed, Master? (y/n)" EOF echo -n "> " read -q @@ -122,7 +115,7 @@ echo " You have commanded the creation of this Tomb:" echo " $filename ( $size MBytes )"; echo echo " Please confirm if you want to proceed now," -echo " digging will take quite some time! (yes/no)" +echo " digging will take quite some time! (y/n)" echo -n "> " read -q if [ $? != 0 ]; then @@ -141,3 +134,4 @@ if ! [ -r /usr/share/applications/tomb.desktop ]; then sudo tomb install fi +exit 0 diff --git a/src/tomb-status.c b/src/tomb-status.c @@ -0,0 +1,220 @@ +/* Tomb - encrypted storage undertaker + * + * (c) Copyright 2007-2011 Denis Roio <jaromil@dyne.org> + * + * This source code is free software; you can redistribute it and/or + * modify it under the terms of the GNU Public License as published + * by the Free Software Foundation; either version 3 of the License, + * or (at your option) any later version. + * + * This source code is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * Please refer to the GNU Public License for more details. + * + * You should have received a copy of the GNU Public License along with + * this source code; if not, write to: + * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <string.h> +#include <libgen.h> + +#include <sys/types.h> +#include <sys/wait.h> + +#include <gtk/gtk.h> +#include <libnotify/notify.h> + +/* The Tomb icon is an artwork by Jordi aka MonMort + a nomadic graffiti artist from Barcelona */ +#include <monmort.xpm> + +GdkPixbuf *pb_monmort; +GtkStatusIcon *status_tomb; +GtkMenu *menu_left, *menu_right; + +NotifyNotification *notice; +GError *error; + +char mapper[256]; +char filename[256]; +char mountpoint[256]; + +// forward declaration of callbacks +gboolean left_click(GtkWidget *w, GdkEvent *e); +gboolean cb_view(GtkWidget *w, GdkEvent *e); +gboolean cb_close(GtkWidget *w, GdkEvent *e); + +gboolean right_click(GtkWidget *w, GdkEvent *e); +gboolean cb_about(GtkWidget *w, GdkEvent *e); + + +int main(int argc, char **argv) { + GtkWidget *item_close, *item_view, *item_about; + gint menu_x, menu_y; + gboolean push_in = TRUE; + + char tomb_file[512]; + char tooltip[256]; + + gtk_set_locale(); + gtk_init(&argc, &argv); + + // get the information from commandline + if(argc<2) { + fprintf(stderr, "error: need at least one argument, the path to a dm-crypt device mapper\n"); + exit(1); + } else { + // TODO: check if mapper really exists + snprintf(mapper,255, "%s", argv[1]); + } + + if(argc<3) sprintf(filename, "unknown"); + else snprintf(filename,255, "%s", argv[2]); + + if(argc<4) sprintf(mountpoint,"unknown"); + else snprintf(mountpoint,255, "%s", argv[3]); + + // libnotify + notify_init(PACKAGE); + + // set and show the status icon + pb_monmort = gdk_pixbuf_new_from_xpm_data(monmort); + status_tomb = gtk_status_icon_new_from_pixbuf(pb_monmort); + // gtk_status_icon_set_name(status_tomb, "tomb"); + gtk_status_icon_set_title(status_tomb, "Tomb"); + + snprintf(tooltip,255,"Tomb in %s",mountpoint); + gtk_status_icon_set_tooltip_text (status_tomb, tooltip); + + // LEFT click menu + menu_left = (GtkMenu*) gtk_menu_new(); + // view + item_view = gtk_menu_item_new_with_label("Explore"); + gtk_menu_attach(menu_left, item_view, 0, 1, 0, 1); + g_signal_connect_swapped(item_view, "activate", G_CALLBACK(cb_view), NULL); + gtk_widget_show(item_view); + // close + item_close = gtk_menu_item_new_with_label("Close"); + gtk_menu_attach(menu_left, item_close, 0, 1, 1, 2); + g_signal_connect_swapped(item_close, "activate", G_CALLBACK(cb_close), NULL); + gtk_widget_show(item_close); + + // connect it + g_signal_connect_swapped(status_tomb, "activate", G_CALLBACK(left_click), menu_left); + + + // RIGHT click menu + menu_right = (GtkMenu*) gtk_menu_new(); + // about + item_about = gtk_menu_item_new_with_label("About"); + gtk_menu_attach(menu_right, item_about, 0, 1, 0, 1); + g_signal_connect_swapped(item_about, "activate", G_CALLBACK(cb_about), NULL); + g_signal_connect_swapped(item_about, "popup-menu", G_CALLBACK(cb_about), NULL); + gtk_widget_show(item_about); + // connect it + g_signal_connect_swapped(status_tomb, "popup-menu", G_CALLBACK(right_click), menu_right); + + // status icon + notice = notify_notification_new_with_status_icon + ("Tomb encrypted undertaker", + "We started digging out bones", + NULL, status_tomb); + notify_notification_set_icon_from_pixbuf(notice, pb_monmort); + + notify_notification_show(notice, &error); + + gtk_main(); + + notify_uninit(); + + exit(0); + +} + +// callbacks left click +gboolean left_click(GtkWidget *w, GdkEvent *e) { + gtk_menu_popup(menu_left, NULL, NULL, + gtk_status_icon_position_menu, status_tomb, + 1, gtk_get_current_event_time()); +} +gboolean cb_view(GtkWidget *w, GdkEvent *e) { + // GtkWidget *dialog = + // gtk_message_dialog_new (NULL, + // GTK_DIALOG_DESTROY_WITH_PARENT, + // GTK_MESSAGE_INFO, + // GTK_BUTTONS_CLOSE, + // "Tomb '%s' open on '%s'\n" + // "device mapper: %s", filename, mountpoint, mapper); + // gtk_dialog_run (GTK_DIALOG (dialog)); + // gtk_widget_destroy (dialog); + pid_t cpid = fork(); + if (cpid == -1) { + fprintf(stderr,"error: problem forking process\n"); + return FALSE; + } + if (cpid == 0) { // Child + execlp("tomb-open", "tomb-open", mountpoint ,(char*)NULL); + exit(1); + } + return TRUE; +} + +gboolean cb_close(GtkWidget *w, GdkEvent *e) { + pid_t cpid = fork(); + int res; + if (cpid == -1) { + fprintf(stderr,"error: problem forking process\n"); + return FALSE; + } + if (cpid == 0) { // Child + execlp("tomb","tomb","-S","umount",mapper,(char*)NULL); + exit(1); + } + waitpid(cpid, &res, 0); + if(res==0) { + gtk_main_quit(); + notify_uninit(); + exit(0); + } + return TRUE; +} + +// callbacks right click +gboolean right_click(GtkWidget *w, GdkEvent *e) { + gtk_menu_popup(menu_right, NULL, NULL, + gtk_status_icon_position_menu, status_tomb, + 1, gtk_get_current_event_time()); +} +gboolean cb_about(GtkWidget *w, GdkEvent *e) { + const gchar *authors[] = {"Denis Roio aka Jaromil - http://jaromil.dyne.org",NULL}; + const gchar *artists[] = {"Jordi aka Món Mort - http://monmort.blogspot.org", + "Asbesto Molesto - http://freaknet.org/asbesto", + NULL}; + GtkWidget *dialog = gtk_about_dialog_new(); + gtk_about_dialog_set_name(GTK_ABOUT_DIALOG(dialog), PACKAGE); + gtk_about_dialog_set_version(GTK_ABOUT_DIALOG(dialog), VERSION); + gtk_about_dialog_set_copyright(GTK_ABOUT_DIALOG(dialog), + "(C)2007-2010 Denis Roio aka Jaromil"); + gtk_about_dialog_set_artists(GTK_ABOUT_DIALOG(dialog), artists); + gtk_about_dialog_set_authors(GTK_ABOUT_DIALOG(dialog), authors); + + gtk_about_dialog_set_comments(GTK_ABOUT_DIALOG(dialog), + "The Crypto Undertaker\n" +"\n" +"This program helps people keeping their bones together by taking care of their private data inside encrypted storage filesystems that are easy to access and transport.\n" +"\n" +"The level of security provided by this program is fairly good: it uses an accelerated AES/SHA256 (cbc-essiv) to access the data on the fly, as if it would be a mounted volume.\n" +"\n" +"To start digging your tomb be ready to get your hands dirty and use the commandline utility 'tomb' from a text terminal." +); + gtk_about_dialog_set_website(GTK_ABOUT_DIALOG(dialog), PACKAGE_URL); + gtk_about_dialog_set_logo(GTK_ABOUT_DIALOG(dialog), pb_monmort); + gtk_dialog_run(GTK_DIALOG (dialog)); + gtk_widget_destroy(dialog); +} + diff --git a/src/tomb-status.cpp b/src/tomb-status.cpp @@ -1,219 +0,0 @@ -/* Tomb - encrypted storage undertaker - * - * (c) Copyright 2007-2011 Denis Roio <jaromil@dyne.org> - * - * This source code is free software; you can redistribute it and/or - * modify it under the terms of the GNU Public License as published - * by the Free Software Foundation; either version 3 of the License, - * or (at your option) any later version. - * - * This source code is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * Please refer to the GNU Public License for more details. - * - * You should have received a copy of the GNU Public License along with - * this source code; if not, write to: - * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <string.h> -#include <libgen.h> - -#include <sys/types.h> -#include <sys/wait.h> - -#include <gtk/gtk.h> -#include <libnotify/notify.h> - -/* The Tomb icon is an artwork by Jordi aka MonMort - a nomadic graffiti artist from Barcelona */ -#include <monmort.xpm> - -GdkPixbuf *pb_monmort; -GtkStatusIcon *status_tomb; -GtkMenu *menu_left, *menu_right; - -NotifyNotification *notice; -GError *error; - -char mapper[256]; -char filename[256]; -char mountpoint[256]; - -// forward declaration of callbacks -gboolean left_click(GtkWidget *w, GdkEvent *e); -gboolean cb_view(GtkWidget *w, GdkEvent *e); -gboolean cb_close(GtkWidget *w, GdkEvent *e); - -gboolean right_click(GtkWidget *w, GdkEvent *e); -gboolean cb_about(GtkWidget *w, GdkEvent *e); - - -int main(int argc, char **argv) { - GtkWidget *item_close, *item_view, *item_about; - gint menu_x, menu_y; - gboolean push_in = true; - - char tomb_file[512]; - char tooltip[256]; - - gtk_set_locale(); - gtk_init(&argc, &argv); - - // get the information from commandline - if(argc<2) { - fprintf(stderr, "error: need at least one argument, the path to a dm-crypt device mapper\n"); - exit(1); - } else { - // TODO: check if mapper really exists - snprintf(mapper,255, "%s", argv[1]); - } - - if(argc<3) sprintf(filename, "unknown"); - else snprintf(filename,255, "%s", argv[2]); - - if(argc<4) sprintf(mountpoint,"unknown"); - else snprintf(mountpoint,255, "%s", argv[3]); - - // libnotify - notify_init(PACKAGE); - - // set and show the status icon - pb_monmort = gdk_pixbuf_new_from_xpm_data(monmort); - status_tomb = gtk_status_icon_new_from_pixbuf(pb_monmort); - // gtk_status_icon_set_name(status_tomb, "tomb"); - gtk_status_icon_set_title(status_tomb, "Tomb"); - - snprintf(tooltip,255,"Tomb in %s",mountpoint); - gtk_status_icon_set_tooltip_text (status_tomb, tooltip); - - // LEFT click menu - menu_left = (GtkMenu*) gtk_menu_new(); - // view - item_view = gtk_menu_item_new_with_label("Explore"); - gtk_menu_attach(menu_left, item_view, 0, 1, 0, 1); - g_signal_connect_swapped(item_view, "activate", G_CALLBACK(cb_view), NULL); - gtk_widget_show(item_view); - // close - item_close = gtk_menu_item_new_with_label("Close"); - gtk_menu_attach(menu_left, item_close, 0, 1, 1, 2); - g_signal_connect_swapped(item_close, "activate", G_CALLBACK(cb_close), NULL); - gtk_widget_show(item_close); - - // connect it - g_signal_connect_swapped(status_tomb, "activate", G_CALLBACK(left_click), menu_left); - - - // RIGHT click menu - menu_right = (GtkMenu*) gtk_menu_new(); - // about - item_about = gtk_menu_item_new_with_label("About"); - gtk_menu_attach(menu_right, item_about, 0, 1, 0, 1); - g_signal_connect_swapped(item_about, "activate", G_CALLBACK(cb_about), NULL); - g_signal_connect_swapped(item_about, "popup-menu", G_CALLBACK(cb_about), NULL); - gtk_widget_show(item_about); - // connect it - g_signal_connect_swapped(status_tomb, "popup-menu", G_CALLBACK(right_click), menu_right); - - // status icon - notice = notify_notification_new_with_status_icon - ("Tomb encrypted undertaker", - "We started digging out bones", - NULL, status_tomb); - notify_notification_set_icon_from_pixbuf(notice, pb_monmort); - - notify_notification_show(notice, &error); - - gtk_main(); - - notify_uninit(); - - exit(0); - -} - -// callbacks left click -gboolean left_click(GtkWidget *w, GdkEvent *e) { - gtk_menu_popup(menu_left, NULL, NULL, - gtk_status_icon_position_menu, status_tomb, - 1, gtk_get_current_event_time()); -} -gboolean cb_view(GtkWidget *w, GdkEvent *e) { - // GtkWidget *dialog = - // gtk_message_dialog_new (NULL, - // GTK_DIALOG_DESTROY_WITH_PARENT, - // GTK_MESSAGE_INFO, - // GTK_BUTTONS_CLOSE, - // "Tomb '%s' open on '%s'\n" - // "device mapper: %s", filename, mountpoint, mapper); - // gtk_dialog_run (GTK_DIALOG (dialog)); - // gtk_widget_destroy (dialog); - pid_t cpid = fork(); - if (cpid == -1) { - fprintf(stderr,"error: problem forking process\n"); - return false; - } - if (cpid == 0) { // Child - execlp("tomb-open", "tomb-open", mountpoint ,(char*)NULL); - exit(1); - } - return true; -} - -gboolean cb_close(GtkWidget *w, GdkEvent *e) { - pid_t cpid = fork(); - int res; - if (cpid == -1) { - fprintf(stderr,"error: problem forking process\n"); - return false; - } - if (cpid == 0) { // Child - execlp("tomb","tomb","-S","umount",mapper,(char*)NULL); - exit(1); - } - waitpid(cpid, &res, 0); - if(res==0) { - gtk_main_quit(); - notify_uninit(); - exit(0); - } -} - -// callbacks right click -gboolean right_click(GtkWidget *w, GdkEvent *e) { - gtk_menu_popup(menu_right, NULL, NULL, - gtk_status_icon_position_menu, status_tomb, - 1, gtk_get_current_event_time()); -} -gboolean cb_about(GtkWidget *w, GdkEvent *e) { - const gchar *authors[] = {"Denis Roio aka Jaromil - http://jaromil.dyne.org",NULL}; - const gchar *artists[] = {"Jordi aka Món Mort - http://monmort.blogspot.org", - "Asbesto Molesto - http://freaknet.org/asbesto", - NULL}; - GtkWidget *dialog = gtk_about_dialog_new(); - gtk_about_dialog_set_name(GTK_ABOUT_DIALOG(dialog), PACKAGE); - gtk_about_dialog_set_version(GTK_ABOUT_DIALOG(dialog), VERSION); - gtk_about_dialog_set_copyright(GTK_ABOUT_DIALOG(dialog), - "(C)2007-2010 Denis Roio aka Jaromil"); - gtk_about_dialog_set_artists(GTK_ABOUT_DIALOG(dialog), artists); - gtk_about_dialog_set_authors(GTK_ABOUT_DIALOG(dialog), authors); - - gtk_about_dialog_set_comments(GTK_ABOUT_DIALOG(dialog), - "The Crypto Undertaker\n" -"\n" -"This program helps people keeping their bones together by taking care of their private data inside encrypted storage filesystems that are easy to access and transport.\n" -"\n" -"The level of security provided by this program is fairly good: it uses an accelerated AES/SHA256 (cbc-essiv) to access the data on the fly, as if it would be a mounted volume.\n" -"\n" -"To start digging your tomb be ready to get your hands dirty and use the commandline utility 'tomb' from a text terminal." -); - gtk_about_dialog_set_website(GTK_ABOUT_DIALOG(dialog), PACKAGE_URL); - gtk_about_dialog_set_logo(GTK_ABOUT_DIALOG(dialog), pb_monmort); - gtk_dialog_run(GTK_DIALOG (dialog)); - gtk_widget_destroy(dialog); -} -