Browse Source

do not ignore used loop devices (size > 0)

fixed tests.cryptobox.py
master
lars 14 years ago
parent
commit
a695d37b8c
  1. 4
      src/cryptobox/core/blockdevice.py
  2. 6
      src/cryptobox/tests/test.cryptobox.py

4
src/cryptobox/core/blockdevice.py

@ -166,7 +166,7 @@ class Blockdevice:
if major == MAJOR_DEVNUM_RAM:
return False
## loop devices are ignored
if major == MAJOR_DEVNUM_LOOP:
if (major == MAJOR_DEVNUM_LOOP) and (self.size == 0):
return False
## removable devices are ignored (due to long timeouts)
if self.is_removable():
@ -774,6 +774,8 @@ def get_blockdevice(dev,
## it is an absolute path
if dev.startswith(devnode_dir):
## it is the name of a devicenode (e.g.: '/dev/hda1')
## simplify the path first
dev = os.path.realpath(dev)
found_dev = [ a_dev for a_dev in Blockdevices(
sysblock_dir, devnode_dir).get_devices()
if dev in a_dev.devnodes ]

6
src/cryptobox/tests/test.cryptobox.py

@ -42,13 +42,13 @@ class CryptoBoxDeviceTests(CommonTestClass):
def test_allowed_devices(self):
'''is_device_allowed should accept permitted devices'''
self.assertTrue(self.cb.is_device_allowed("/dev/loop1"))
self.assertTrue(self.cb.is_device_allowed("/dev/usb/../loop1"))
self.assertTrue(self.cb.is_device_allowed("/dev/pts/../loop1"))
def test_denied_devices(self):
'''is_device_allowed should fail with not explicitly allowed devices'''
self.assertFalse(self.cb.is_device_allowed("/dev/hda"))
self.assertFalse(self.cb.is_device_allowed("/dev/loopa/../hda"))
self.assertFalse(self.cb.is_device_allowed("/dev/hdc"))
self.assertFalse(self.cb.is_device_allowed("/dev/loopa/../hdc"))
self.assertFalse(self.cb.is_device_allowed("/"))
## this device does not exist -> no permission check possible
self.assertFalse(self.cb.is_device_allowed("/dev/loop"))

Loading…
Cancel
Save