mirror of
https://github.com/Llewellynvdm/Tomb.git
synced 2024-11-22 12:35:13 +00:00
fix to tomb resize
also included into test script
This commit is contained in:
parent
8f9e9f9d2a
commit
bc3177141d
@ -1,48 +1,46 @@
|
|||||||
#/usr/bin/env zsh
|
#!/usr/bin/zsh
|
||||||
|
|
||||||
T="../../tomb"
|
T="../../tomb"
|
||||||
source utils.sh
|
source utils.sh
|
||||||
|
source ${T} source
|
||||||
|
|
||||||
|
notice() { print; yes "${@}"; print; }
|
||||||
|
error() { _warning " ${@}"; }
|
||||||
|
tt() {
|
||||||
|
start_loops=(`sudo losetup -a |cut -d: -f1`)
|
||||||
|
${T} ${=@}
|
||||||
|
res=$?
|
||||||
|
loops=(`sudo losetup -a |cut -d: -f1`)
|
||||||
|
{ test "${#start_loops}" = "${#loops}" } || { error "loop device limit change to ${#loops}" }
|
||||||
|
print " Tomb command returns $res"
|
||||||
|
return $res
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
rm /tmp/test.tomb{,.key} -f || exit 1
|
rm /tmp/test.tomb{,.key} -f || exit 1
|
||||||
|
|
||||||
sudo -k
|
notice "Testing creation"
|
||||||
|
|
||||||
${T} dig -s 10 /tmp/test.tomb
|
tt dig -s 10 /tmp/test.tomb
|
||||||
|
|
||||||
sudo losetup -a
|
tt --ignore-swap --unsecure-dev-mode --tomb-pwd f00za --use-urandom forge /tmp/test.tomb.key
|
||||||
|
|
||||||
${T} --ignore-swap --unsecure-dev-mode --tomb-pwd f00za --use-urandom \
|
|
||||||
forge /tmp/test.tomb.key
|
|
||||||
|
|
||||||
sudo losetup -a
|
tt --ignore-swap --unsecure-dev-mode --tomb-pwd f00za lock /tmp/test.tomb -k /tmp/test.tomb.key
|
||||||
|
|
||||||
${T} --ignore-swap --unsecure-dev-mode --tomb-pwd f00za \
|
|
||||||
lock /tmp/test.tomb -k /tmp/test.tomb.key
|
|
||||||
|
|
||||||
sudo losetup -a
|
|
||||||
|
|
||||||
# sanity_tomb /tmp/asd.tomb
|
# sanity_tomb /tmp/asd.tomb
|
||||||
echo
|
notice "Testing open with wrong password"
|
||||||
echo trying to open with wrong password
|
|
||||||
echo
|
|
||||||
|
|
||||||
${T} --unsecure-dev-mode --tomb-pwd wrongpassword \
|
tt --unsecure-dev-mode --tomb-pwd wrongpassword open /tmp/test.tomb
|
||||||
open /tmp/test.tomb
|
|
||||||
|
|
||||||
sudo losetup -a
|
notice "Testing open with good password"
|
||||||
|
|
||||||
echo
|
tt --unsecure-dev-mode --tomb-pwd f00za open /tmp/test.tomb
|
||||||
echo trying to open with good password
|
|
||||||
echo
|
|
||||||
|
|
||||||
${T} --unsecure-dev-mode --tomb-pwd f00za \
|
tt --unsecure-dev-mode close test
|
||||||
open /tmp/test.tomb
|
|
||||||
|
|
||||||
sudo losetup -a
|
notice "Testing resize to 20MiB"
|
||||||
|
tt --unsecure-dev-mode --tomb-pwd f00za -k /tmp/test.tomb.key resize /tmp/test.tomb -s 20
|
||||||
${T} --unsecure-dev-mode close test
|
|
||||||
|
|
||||||
sudo losetup -a
|
|
||||||
|
|
||||||
rm /tmp/test.tomb{,.key} -f || exit 1
|
|
||||||
|
|
||||||
|
# rm /tmp/test.tomb{,.key} -f || exit 1
|
||||||
|
27
tomb
27
tomb
@ -214,7 +214,7 @@ EOF
|
|||||||
fi # are we root already
|
fi # are we root already
|
||||||
|
|
||||||
# make sure necessary kernel modules are loaded
|
# make sure necessary kernel modules are loaded
|
||||||
modprobe dm_mod 2>/dev/null
|
modprobe dm_mod 2>/dev/null
|
||||||
modprobe dm_crypt 2>/dev/null
|
modprobe dm_crypt 2>/dev/null
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
@ -495,7 +495,7 @@ ask_key_password() {
|
|||||||
local tombpass=""
|
local tombpass=""
|
||||||
if option_is_set --tomb-pwd; then
|
if option_is_set --tomb-pwd; then
|
||||||
tombpass=`option_value --tomb-pwd`
|
tombpass=`option_value --tomb-pwd`
|
||||||
xxx "ask_key_password takes tombpass from CLI argument: $tombpass"
|
xxx "ask_key_password takes tombpass from CLI argument: $tombpass"
|
||||||
|
|
||||||
get_lukskey "$tombpass" ${tombkey} >/dev/null
|
get_lukskey "$tombpass" ${tombkey} >/dev/null
|
||||||
|
|
||||||
@ -686,7 +686,7 @@ gen_key() {
|
|||||||
done
|
done
|
||||||
else
|
else
|
||||||
tombpass="`option_value --tomb-pwd`"
|
tombpass="`option_value --tomb-pwd`"
|
||||||
xxx "gen_key takes tombpass from CLI argument: $tombpass"
|
xxx "gen_key takes tombpass from CLI argument: $tombpass"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
@ -1221,7 +1221,7 @@ mount_tomb() {
|
|||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
# is it a LUKS encrypted nest? see cryptsetup(1)
|
# is it a LUKS encrypted nest? see cryptsetup(1)
|
||||||
_warning "$tombfile is not a valid Luks encrypted storage file"
|
_warning "$tombfile is not a valid Luks encrypted storage file"
|
||||||
losetup -d ${nstloop}
|
losetup -d ${nstloop}
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
say "this tomb is a valid LUKS encrypted device"
|
say "this tomb is a valid LUKS encrypted device"
|
||||||
@ -1248,7 +1248,7 @@ mount_tomb() {
|
|||||||
|
|
||||||
tombpass=`ask_key_password $tombkey`
|
tombpass=`ask_key_password $tombkey`
|
||||||
{ test $? = 0 } || {
|
{ test $? = 0 } || {
|
||||||
losetup -d ${nstloop}
|
losetup -d ${nstloop}
|
||||||
die "No valid password supplied" }
|
die "No valid password supplied" }
|
||||||
|
|
||||||
get_lukskey "${tombpass}" ${tombkey} | \
|
get_lukskey "${tombpass}" ${tombkey} | \
|
||||||
@ -1648,7 +1648,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 "$1" 2>/dev/null`
|
local oldtombsize=$(( `stat -c %s "$1" 2>/dev/null` / 1048576 ))
|
||||||
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 }'`
|
||||||
|
|
||||||
@ -1656,9 +1656,6 @@ resize_tomb() {
|
|||||||
_failure "the tomb $tombname is open, to resize it it needs to be close."
|
_failure "the tomb $tombname is open, to resize it it needs to be close."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# MB to bytes conversion
|
|
||||||
newtombsize=`expr \( $newtombsize \* 1024 \) \* 1024 2> /dev/null`
|
|
||||||
|
|
||||||
if ! [ "$newtombsize" ] ; then
|
if ! [ "$newtombsize" ] ; then
|
||||||
_failure "You must specify the new size of $tombname"
|
_failure "You must specify the new size of $tombname"
|
||||||
elif [[ $newtombsize != <-> ]]; then
|
elif [[ $newtombsize != <-> ]]; then
|
||||||
@ -1667,12 +1664,12 @@ resize_tomb() {
|
|||||||
_failure "the new size must be greater then old tomb size."
|
_failure "the new size must be greater then old tomb size."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local delta=`expr $newtombsize \- $oldtombsize`
|
delta="$(( $newtombsize - $oldtombsize ))"
|
||||||
|
|
||||||
act "Generating ${tombfile} of ${newtombsize}MiB"
|
act "Generating ${tombfile} of ${newtombsize}MiB"
|
||||||
|
|
||||||
xxx "Data dump using ${DD[1]} from /dev/urandom"
|
xxx "Data dump using ${DD[1]} from /dev/urandom"
|
||||||
${=DD} if=/dev/urandom bs=1048576 count=${tombsize} of="${tmp_resize}"
|
${=DD} if=/dev/urandom bs=1048576 count=${delta} of="${tmp_resize}"
|
||||||
|
|
||||||
if [ $? = 0 -a -e "${tmp_resize}" ]; then
|
if [ $? = 0 -a -e "${tmp_resize}" ]; then
|
||||||
xxx "OK: `ls -lh ${tmp_resize}`"
|
xxx "OK: `ls -lh ${tmp_resize}`"
|
||||||
@ -1680,8 +1677,8 @@ 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}" >> "$1"
|
cat "${tmp_resize}" >> ${tombdir}/${tombfile}
|
||||||
${=WIPE} "${tmp_resize}"
|
rm "${tmp_resize}"
|
||||||
|
|
||||||
|
|
||||||
tombpass=`ask_key_password $tombkey`
|
tombpass=`ask_key_password $tombkey`
|
||||||
@ -1693,7 +1690,7 @@ resize_tomb() {
|
|||||||
_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 "$1"
|
losetup -f ${tombdir}/${tombfile}
|
||||||
|
|
||||||
local mapdate=`date +%s`
|
local mapdate=`date +%s`
|
||||||
local mapper="tomb.${tombname}.${mapdate}.`basename $nstloop`"
|
local mapper="tomb.${tombname}.${mapdate}.`basename $nstloop`"
|
||||||
@ -1919,7 +1916,7 @@ main() {
|
|||||||
subcommands_opts[askpass]=""
|
subcommands_opts[askpass]=""
|
||||||
subcommands_opts[mktemp]=""
|
subcommands_opts[mktemp]=""
|
||||||
subcommands_opts[source]=""
|
subcommands_opts[source]=""
|
||||||
subcommands_opts[resize]="s: -size=s k: -key=k"
|
subcommands_opts[resize]="f -force -ignore-swap s: -size=s k: -key=k -tomb-pwd:"
|
||||||
subcommands_opts[check]="-ignore-swap"
|
subcommands_opts[check]="-ignore-swap"
|
||||||
# subcommands_opts[translate]=""
|
# subcommands_opts[translate]=""
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user