#!/usr/bin/env python2.4 """ 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.prefs.prefs.filename, ) print "\tAllowed devices:\t%s" % (cb.prefs["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() or len(cb.getContainerList()) < 1: 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 ..." if not plain_tests(testElement): print "some previous tests failed - we should stop now" sys.exit(1) luks_tests(testElement) " ***************** some functions ******************** " def luks_tests(e): # umount if necessary try: e.umount() except "MountError": pass 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" print "\tCapacity (size, free, used) [MB]:\t%s" % (e.getCapacity(), ) 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): # umount if necessary try: e.umount() except "MountError": pass 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" print "\tCapacity (size, free, used) [MB]:\t%s" % (e.getCapacity(), ) try: e.umount() except "MountError": pass if e.isMounted(): print "\tplain umount:\tfailed" else: print "\tplain umount:\tok" if e.isMounted(): return False else: return True # ************ main **************** main()