2006-08-23 15:27:25 +02:00
|
|
|
#!/usr/bin/env python2.4
|
|
|
|
|
2006-08-17 12:38:05 +02:00
|
|
|
"""
|
|
|
|
BEWARE: this script may overwrite the data of one of your loop devices. You
|
|
|
|
should restrict the AllowedDevices directive in cryptobox.conf to exclude
|
|
|
|
your precious black devices from being used by this script.
|
|
|
|
|
|
|
|
the following script runs a number of tests for different parts
|
|
|
|
"""
|
|
|
|
|
|
|
|
from CryptoBox import CryptoBoxProps
|
|
|
|
from CryptoBoxContainer import CryptoBoxContainer
|
|
|
|
import sys
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
cb = CryptoBoxProps()
|
|
|
|
|
|
|
|
print "Confguration:"
|
|
|
|
print "\tConfig file:\t\t%s" % (cb.cbxPrefs.filename, )
|
|
|
|
print "\tAllowed devices:\t%s" % (cb.cbxPrefs["Main"]["AllowedDevices"], )
|
|
|
|
|
|
|
|
"""for e in cb.getContainerList(filterType=CryptoBoxContainer.Types["luks"]):"""
|
|
|
|
for e in cb.getContainerList():
|
|
|
|
print "\t\t%d\t\t%s - %s - %d" % (cb.getContainerList().index(e), e.getDevice(), e.getName(), e.getType())
|
|
|
|
|
|
|
|
if not cb.getContainerList():
|
|
|
|
print "no loop devices found for testing"
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
if len(cb.getContainerList()) > 1:
|
|
|
|
print "I found more than one available loop device - I will stop now to avoid risking data loss."
|
|
|
|
print "Please change the 'AllowedDevices' setting in 'cryptobox.conf' to reduce the number of allowed devices to only one."
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
testElement = cb.getContainerList()[0]
|
|
|
|
print "\nRunning some tests now ..."
|
2006-08-21 09:41:03 +02:00
|
|
|
if not plain_tests(testElement):
|
2006-08-17 12:38:05 +02:00
|
|
|
print "some previous tests failed - we should stop now"
|
|
|
|
sys.exit(1)
|
2006-08-21 09:41:03 +02:00
|
|
|
luks_tests(testElement)
|
2006-08-17 12:38:05 +02:00
|
|
|
|
|
|
|
|
|
|
|
" ***************** some functions ******************** "
|
|
|
|
|
2006-08-21 09:41:03 +02:00
|
|
|
def luks_tests(e):
|
2006-08-24 09:36:47 +02:00
|
|
|
# umount if necessary
|
|
|
|
try:
|
|
|
|
e.umount()
|
|
|
|
except "MountError":
|
|
|
|
pass
|
|
|
|
|
2006-08-17 12:38:05 +02:00
|
|
|
e.create(e.Types["luks"], "alt")
|
|
|
|
print "\tluks create:\tok"
|
|
|
|
|
|
|
|
e.changePassword("alt","neu")
|
|
|
|
print "\tluks changepw:\tok"
|
|
|
|
|
|
|
|
e.setName("lalla")
|
|
|
|
print "\tluks setName:\tok"
|
|
|
|
|
|
|
|
try:
|
|
|
|
e.mount("neu")
|
|
|
|
except "MountError":
|
|
|
|
pass
|
|
|
|
if e.isMounted(): print "\tluks mount:\tok"
|
|
|
|
else: print "\tluks mount:\tfailed"
|
|
|
|
|
2006-08-24 09:36:47 +02:00
|
|
|
print "\tCapacity (size, free, used) [MB]:\t%s" % (e.getCapacity(), )
|
|
|
|
|
2006-08-17 12:38:05 +02:00
|
|
|
try:
|
|
|
|
e.umount()
|
|
|
|
except "MountError":
|
|
|
|
pass
|
|
|
|
if e.isMounted(): print "\tluks umount:\tfailed"
|
|
|
|
else: print "\tluks umount:\tok"
|
|
|
|
|
|
|
|
if e.isMounted(): return False
|
|
|
|
else: return True
|
|
|
|
|
|
|
|
|
|
|
|
def plain_tests(e):
|
2006-08-24 09:36:47 +02:00
|
|
|
# umount if necessary
|
|
|
|
try:
|
|
|
|
e.umount()
|
|
|
|
except "MountError":
|
|
|
|
pass
|
|
|
|
|
2006-08-17 12:38:05 +02:00
|
|
|
e.create(e.Types["plain"])
|
|
|
|
print "\tplain create:\tok"
|
|
|
|
|
|
|
|
e.setName("plain-lili")
|
|
|
|
print "\tplain setName:\tok"
|
|
|
|
|
|
|
|
try:
|
|
|
|
e.mount()
|
|
|
|
except "MountError":
|
|
|
|
pass
|
|
|
|
if e.isMounted(): print "\tplain mount:\tok"
|
|
|
|
else: print "\tplain mount:\tfailed"
|
|
|
|
|
2006-08-24 09:36:47 +02:00
|
|
|
print "\tCapacity (size, free, used) [MB]:\t%s" % (e.getCapacity(), )
|
|
|
|
|
2006-08-17 12:38:05 +02:00
|
|
|
try:
|
|
|
|
e.umount()
|
|
|
|
except "MountError":
|
|
|
|
pass
|
|
|
|
if e.isMounted(): print "\tplain umount:\tfailed"
|
|
|
|
else: print "\tplain umount:\tok"
|
|
|
|
|
2006-08-21 09:41:03 +02:00
|
|
|
if e.isMounted(): return False
|
|
|
|
else: return True
|
|
|
|
|
|
|
|
# ************ main ****************
|
|
|
|
|
2006-08-17 12:38:05 +02:00
|
|
|
main()
|