summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJaromil <jaromil@dyne.org>2017-02-18 19:30:33 (GMT)
committer GitHub <noreply@github.com>2017-02-18 19:30:33 (GMT)
commit1f022d10f1a1fab564ba960679ec1460535d2a4e (patch)
treee0d05d0b509bf6ffbc3239941c8125f119143442
parent2bc7e4319831a64ef46deb79a88e8ac937e09ca4 (diff)
parent70334f58fb254f430d744f94e13db0e3bc656268 (diff)
Merge pull request #248 from mesbahamin/open_read_only
Open non-writable Tomb files with "read only " mount option
-rwxr-xr-xextras/test/runtests31
-rwxr-xr-xtomb3
2 files changed, 30 insertions, 4 deletions
diff --git a/extras/test/runtests b/extras/test/runtests
index b664e9a..4c99a0e 100755
--- a/extras/test/runtests
+++ b/extras/test/runtests
@@ -56,7 +56,7 @@ command -v qrencode > /dev/null || QRENCODE=0
typeset -A results
-tests=(dig forge lock badpass open close passwd chksum bind setkey)
+tests=(dig forge lock badpass open close openro passwd chksum bind setkey)
{ test $RESIZER = 1 } && { tests+=(resize) }
{ test $KDF = 1 } && { tests+=(kdforge kdfpass kdflock kdfopen) }
{ test $STEGHIDE = 1 } && { tests+=(stgin stgout stgopen stgpipe stgimpl) }
@@ -194,7 +194,32 @@ test-regression() {
}
+test-open-read-only() {
+ notice "wiping all testro.tomb* in /tmp"
+ sudo rm -f /tmp/testro.tomb{,.key,.new.key}
+
+ # Create new
+ tt dig -s 20 /tmp/testro.tomb
+ tt forge /tmp/testro.tomb.key \
+ --ignore-swap --unsafe --tomb-pwd ${dummypass} --use-urandom
+ tt lock /tmp/testro.tomb -k /tmp/testro.tomb.key \
+ --ignore-swap --unsafe --tomb-pwd ${dummypass}
+
+ notice "Testing open read only"
+
+ # Remove write privilege on test.tomb
+ chmod -w /tmp/testro.tomb
+
+ # Attempt to open the unwritable tomb with the read-only mount option
+ tt open /tmp/testro.tomb -k /tmp/testro.tomb.key \
+ --ignore-swap --unsafe --tomb-pwd ${dummypass} -o ro,noatime,nodev
+
+ { test $? = 0 } && {
+ results+=(openro SUCCESS)
+ tt close testro
+ }
+}
startloops=(`sudo losetup -a |cut -d: -f1`)
@@ -227,8 +252,8 @@ tt close test
{ test $? = 0 } && { results+=(close SUCCESS) }
-
-
+# isolated function
+test-open-read-only
notice "Testing changing tomb password"
diff --git a/tomb b/tomb
index 82540b3..411c25e 100755
--- a/tomb
+++ b/tomb
@@ -507,7 +507,8 @@ is_valid_tomb() {
_fail=0
# Tomb file must be a readable, writable, non-empty regular file.
- [[ ! -w "$1" ]] && {
+ # If passed the "ro" mount option, the writable check is skipped.
+ [[ ! -w "$1" ]] && [[ $(option_value -o) != *"ro"* ]] && {
_warning "Tomb file is not writable: ::1 tomb file::" $1
_fail=1
}