Merge: changed legacy code, added modelines

This commit is contained in:
boyska 2012-02-02 23:44:43 +01:00
commit 634720b40c

View File

@ -413,8 +413,8 @@ EOF
# {{{ - HELPERS FOR KEYS # {{{ - HELPERS FOR KEYS
# {{{ - Encode Key # {{{ - Encode Key
encode_key() { encode_key() {
tombkey=$CMD2 tombkey=$1
imagefile=$CMD3 imagefile=$2
file $tombkey | grep PGP > /dev/null file $tombkey | grep PGP > /dev/null
if [ $? != 0 ]; then if [ $? != 0 ]; then
@ -469,8 +469,8 @@ encode_key() {
# }}} # }}}
# {{{ - Decode Key # {{{ - Decode Key
decode_key() { decode_key() {
tombname=$CMD2 tombname=$1
imagefile=$CMD3 imagefile=$2
res=1 res=1
file $imagefile | grep JPEG > /dev/null file $imagefile | grep JPEG > /dev/null
@ -604,18 +604,19 @@ exec_safe_post_hooks() {
# {{{ TOMB SUB-COMMANDS # {{{ TOMB SUB-COMMANDS
# {{{ - Create # {{{ - Create
# $1 is the tomb path
create_tomb() { create_tomb() {
_message "Commanded to create tomb $CMD2" _message "Commanded to create tomb $1"
if ! option_is_set -f; then check_swap; fi if ! option_is_set -f; then check_swap; fi
if ! [ ${CMD2} ]; then if ! [ $1 ]; then
_warning "no tomb name specified for creation" _warning "no tomb name specified for creation"
return 1 return 1
fi fi
tombfile=`basename ${CMD2}` tombfile=`basename $1`
tombdir=`dirname ${CMD2}` tombdir=`dirname $1`
# make sure the file has a .tomb extension # make sure the file has a .tomb extension
tombname=${tombfile%%\.*} tombname=${tombfile%%\.*}
tombfile=${tombname}.tomb tombfile=${tombname}.tomb
@ -779,11 +780,12 @@ create_tomb() {
# }}} # }}}
# {{{ - Open # {{{ - Open
# $1 = tombfile $2(optional) = mountpoint
mount_tomb() { mount_tomb() {
_message "Commanded to open tomb $CMD2" _message "Commanded to open tomb $1"
if ! option_is_set -f; then check_swap; fi if ! option_is_set -f; then check_swap; fi
if ! [ ${CMD2} ]; then if ! [ ${1} ]; then
_warning "no tomb name specified for creation" _warning "no tomb name specified for creation"
return 1 return 1
fi fi
@ -795,12 +797,12 @@ mount_tomb() {
local tombfile local tombfile
local tombdir local tombdir
local tombname local tombname
tombfile=`basename ${CMD2}` tombfile=`basename ${1}`
tombdir=`dirname ${CMD2}` tombdir=`dirname ${1}`
# check file type (if its a Luks fs) # check file type (if its a Luks fs)
file ${tombdir}/${tombfile} | grep -i 'luks encrypted file' 2>&1 >/dev/null file ${tombdir}/${tombfile} | grep -i 'luks encrypted file' 2>&1 >/dev/null
if [ $? != 0 ]; then if [ $? != 0 ]; then
_warning "$CMD2 is not a valid tomb file, operation aborted" _warning "$1 is not a valid tomb file, operation aborted"
return 1 return 1
fi fi
tombname=${tombfile%%\.*} tombname=${tombfile%%\.*}
@ -827,14 +829,14 @@ mount_tomb() {
return 1 return 1
fi fi
if ! [ $CMD3 ]; then if ! [ $2 ]; then
tombmount=/media/${tombfile} tombmount=/media/${tombfile}
_message "mountpoint not specified, using default: $tombmount" _message "mountpoint not specified, using default: $tombmount"
elif ! [ -x $CMD3 ]; then elif ! [ -x $2 ]; then
_warning "mountpoint $CMD3 doesn't exist, operation aborted." _warning "mountpoint $2 doesn't exist, operation aborted."
return 1 return 1
else else
tombmount=${CMD3} tombmount=$2
fi fi
# check if its already open # check if its already open
@ -1118,13 +1120,14 @@ umount_tomb() {
# }}} # }}}
# }}} # }}}
# {{{ - Change Password # {{{ - Change Password
# $1 is the tomb key path
# change tomb key password # change tomb key password
change_passwd() { change_passwd() {
_message "Commanded to change password for tomb key $CMD2" _message "Commanded to change password for tomb key $1"
if ! option_is_set -f; then check_swap; fi if ! option_is_set -f; then check_swap; fi
local keyfile="$CMD2" local keyfile="$1"
# check the keyfile # check the keyfile
if ! [ -r $keyfile ]; then if ! [ -r $keyfile ]; then
@ -1221,17 +1224,18 @@ change_passwd() {
# }}} # }}}
# {{{ - Resize # {{{ - Resize
# resize tomb file size # resize tomb file size
# $1 is tomb path
resize_tomb() { resize_tomb() {
_message "Commanded to resize tomb $CMD2 to $opts[-s] megabytes" _message "Commanded to resize tomb $1 to $opts[-s] megabytes"
if ! [ ${CMD2} ]; then if ! [ $1 ]; then
_failure "No tomb name specified for resizing" _failure "No tomb name specified for resizing"
elif ! [ -r "${CMD2}" ]; then elif ! [ -r "$1" ]; then
_failure "Cannot find ${CMD2}" _failure "Cannot find $1"
fi fi
local c tombpass tombkey local c tombpass tombkey
local tombfile=`basename ${CMD2}` local tombfile=`basename $1`
local tombdir=`dirname ${CMD2}` local tombdir=`dirname $1`
# make sure the file has a .tomb extension # make sure the file has a .tomb extension
local tombname=${tombfile%%\.*} local tombname=${tombfile%%\.*}
tombfile=${tombname}.tomb tombfile=${tombname}.tomb
@ -1258,7 +1262,7 @@ resize_tomb() {
local tmp_resize=`safe_filename tmbrsz` local tmp_resize=`safe_filename tmbrsz`
local newtombsize=$opts[-s] local newtombsize=$opts[-s]
local oldtombsize=`stat -c %s "${CMD2}" 2>/dev/null` local oldtombsize=`stat -c %s "$1" 2>/dev/null`
local mounted_tomb=`mount -l | local mounted_tomb=`mount -l |
awk -vtomb="[$tombname]" '/^\/dev\/mapper\/tomb/ { if($7==tomb) print $1 }'` awk -vtomb="[$tombname]" '/^\/dev\/mapper\/tomb/ { if($7==tomb) print $1 }'`
@ -1291,14 +1295,14 @@ resize_tomb() {
_failure "Error creating the extra resize $tmp_resize, operation aborted." _failure "Error creating the extra resize $tmp_resize, operation aborted."
fi fi
cat "${tmp_resize}" >> "${CMD2}" cat "${tmp_resize}" >> "$1"
${=WIPE} "${tmp_resize}" ${=WIPE} "${tmp_resize}"
local nstloop=`losetup -f` local nstloop=`losetup -f`
if [ $? = 255 ]; then if [ $? = 255 ]; then
_failure "too many tomb opened. Please close any of them to open another tomb" _failure "too many tomb opened. Please close any of them to open another tomb"
fi fi
losetup -f "${CMD2}" losetup -f "$1"
local mapdate=`date +%s` local mapdate=`date +%s`
local mapper="tomb.${tombname}.${mapdate}.`basename $nstloop`" local mapper="tomb.${tombname}.${mapdate}.`basename $nstloop`"
@ -1356,8 +1360,9 @@ resize_tomb() {
# }}} # }}}
# {{{ - List # {{{ - List
# list all tombs mounted in a readable format # list all tombs mounted in a readable format
# $1 is optional, to specify a tomb
list_tombs() { list_tombs() {
if [ $CMD2 ]; then if [ $1 ]; then
# list a specific tomb # list a specific tomb
mounted_tombs=`mount -l | mounted_tombs=`mount -l |
awk -vtomb="[$1]" '/^\/dev\/mapper\/tomb/ { if($7==tomb) print $1 ";" $3 ";" $5 ";" $6 ";" $7 }'` awk -vtomb="[$1]" '/^\/dev\/mapper\/tomb/ { if($7==tomb) print $1 ";" $3 ";" $5 ";" $6 ";" $7 }'`
@ -1374,7 +1379,7 @@ list_tombs() {
if ! [ $mounted_tombs ]; then if ! [ $mounted_tombs ]; then
if [ $1 ]; then if [ $1 ]; then
die "There seems to be no open tomb engraved as [$CMD2]" die "There seems to be no open tomb engraved as [$1]"
else else
die "I can't see any open tomb, may they all rest in peace." die "I can't see any open tomb, may they all rest in peace."
fi fi
@ -1726,35 +1731,31 @@ main() {
autoload colors; colors autoload colors; colors
fi fi
CMD=$subcommand xxx "Tomb command: $subcommand ${PARAM}"
CMD2=$PARAM[1]
CMD3=$PARAM[2]
xxx "Tomb command: $CMD $CMD2 $CMD3"
case "$subcommand" in case "$subcommand" in
create) create)
check_priv check_priv
create_tomb create_tomb $PARAM[1]
;; ;;
mount|open) mount|open)
check_priv check_priv
mount_tomb mount_tomb $PARAM[1] $PARAM[2]
;; ;;
umount|close|slam) umount|close|slam)
check_priv check_priv
[ "$subcommand" = "slam" ] && SLAM=1 [ "$subcommand" = "slam" ] && SLAM=1
umount_tomb ${CMD2} umount_tomb $PARAM[1]
;; ;;
passwd) passwd)
check_priv check_priv
change_passwd ${CMD2} change_passwd $PARAM[1]
;; ;;
list) list)
list_tombs ${CMD2} list_tombs $PARAM[1]
;; ;;
status) status)
launch_status ${CMD2} launch_status $PARAM[1]
;; ;;
help) help)
usage usage
@ -1770,16 +1771,16 @@ main() {
_warning "steghide not installed. Cannot exhume your key" _warning "steghide not installed. Cannot exhume your key"
return 1 return 1
fi fi
decode_key $PARAM[1] decode_key $PARAM[1] $PARAM[2]
;; ;;
resize) resize)
check_priv check_priv
resize_tomb resize_tomb $PARAM[1]
;; ;;
# internal commands useful to developers # internal commands useful to developers
'source') return 0 ;; 'source') return 0 ;;
install) check_priv ; install_tomb ;; install) check_priv ; install_tomb ;;
askpass) ask_password ${CMD2} ${CMD3} ;; askpass) ask_password $PARAM[1] $PARAM[2] ;;
mktemp) safe_dir $PARAM[1] ;; mktemp) safe_dir $PARAM[1] ;;
translate) generate_translatable_strings ;; translate) generate_translatable_strings ;;
check) check_command $PARAM[1] ;; check) check_command $PARAM[1] ;;
@ -1799,7 +1800,7 @@ EOF
usage usage
;; ;;
*) *)
_warning "command \"$CMD\" not recognized" _warning "command \"$subcommand\" not recognized"
_message "try -h for help" _message "try -h for help"
return 1 return 1
;; ;;
@ -1817,3 +1818,5 @@ if [[ $ret != 0 ]]; then #this "if" seems useless, but avoid source tomb source
fi fi
# }}} # }}}
# -*- tab-width: 4; indent-tabs-mode:nil; -*-
# vim: set shiftwidth=4 expandtab: