transition to "logging" instead of "CryptoBoxLogger" finished
names of cryptobox.conf settings changed cryptsetup interface for CryptoBoxRootActions implemented
This commit is contained in:
parent
12868beb21
commit
f95f33ba71
5 changed files with 119 additions and 303 deletions
|
@ -5,6 +5,7 @@ except:
|
|||
print "Couldn't import 'subprocess'. You need a python version >= 2.4"
|
||||
import os
|
||||
import re
|
||||
import logging
|
||||
|
||||
"""exceptions:
|
||||
VolumeIsActive
|
||||
|
@ -37,7 +38,7 @@ class CryptoBoxContainer:
|
|||
def __init__(self, device, cbox):
|
||||
self.device = device
|
||||
self.cbox = cbox
|
||||
self.debugMessage = self.cbox.debugMessage
|
||||
self.log = logging.getLogger("CryptoBox")
|
||||
self.Progs = self.cbox.cbxPrefs["Programs"]
|
||||
self.__resetObject()
|
||||
|
||||
|
@ -103,9 +104,7 @@ class CryptoBoxContainer:
|
|||
try:
|
||||
devnull = open(os.devnull, "w")
|
||||
except IOError:
|
||||
self.debugMessage(
|
||||
CryptoBoxLogger.DebugLevels["warn"],
|
||||
"Could not open %s" % (os.devnull, ))
|
||||
self.log.warn("Could not open %s" % (os.devnull, ))
|
||||
"remove any potential open luks mapping"
|
||||
self.__umountLuks()
|
||||
"create the luks header"
|
||||
|
@ -123,7 +122,7 @@ class CryptoBoxContainer:
|
|||
(output, errout) = proc.communicate()
|
||||
if proc.returncode != 0:
|
||||
errorMsg = "Could not add a new luks key: %s - %s" % (output.strip(), errout.strip(), )
|
||||
self.debugMessage(CryptoBoxLogger.DebugLevels["error"], errorMsg)
|
||||
self.log.error(errorMsg)
|
||||
raise "ChangePasswordError", errorMsg
|
||||
keys_found = re.search(r'key slot (\d{1,3}) unlocked', output).groups()
|
||||
if keys_found:
|
||||
|
@ -145,7 +144,7 @@ class CryptoBoxContainer:
|
|||
proc.wait()
|
||||
if proc.returncode != 0:
|
||||
errorMsg = "Could not remove the old luks key: %s" % (proc.stderr.read().strip(), )
|
||||
self.debugMessage(CryptoBoxLogger.DebugLevels["error"], errorMsg)
|
||||
self.log.error(errorMsg)
|
||||
raise "ChangePasswordError", errorMsg
|
||||
|
||||
|
||||
|
@ -190,9 +189,7 @@ class CryptoBoxContainer:
|
|||
try:
|
||||
devnull = open(os.devnull, "w")
|
||||
except IOError:
|
||||
self.debugMessage(
|
||||
CryptoBoxLogger.DebugLevels["warn"],
|
||||
"Could not open %s" % (os.devnull, ))
|
||||
self.warn("Could not open %s" % (os.devnull, ))
|
||||
proc = subprocess.Popen(
|
||||
shell=False,
|
||||
stdin=None,
|
||||
|
@ -207,9 +204,7 @@ class CryptoBoxContainer:
|
|||
proc.wait()
|
||||
result = proc.stdout.read().strip()
|
||||
if proc.returncode != 0:
|
||||
self.debugMessage(
|
||||
CryptoBoxLogger.DebugLevels["warn"],
|
||||
"retrieving of partition type via 'blkid' failed: %s" % (proc.stderr.read().strip(), ))
|
||||
self.log.warn("retrieving of partition type via 'blkid' failed: %s" % (proc.stderr.read().strip(), ))
|
||||
return None
|
||||
devnull.close()
|
||||
if result: return result
|
||||
|
@ -233,9 +228,7 @@ class CryptoBoxContainer:
|
|||
try:
|
||||
devnull = open(os.devnull, "w")
|
||||
except IOError:
|
||||
self.debugMessage(
|
||||
CryptoBoxLogger.DebugLevels["warn"],
|
||||
"Could not open %s" % (os.devnull, ))
|
||||
self.log.warn("Could not open %s" % (os.devnull, ))
|
||||
proc = subprocess.Popen(
|
||||
shell=False,
|
||||
stdin=None,
|
||||
|
@ -250,9 +243,7 @@ class CryptoBoxContainer:
|
|||
proc.wait()
|
||||
output = proc.stdout.read().strip()
|
||||
if proc.returncode != 0:
|
||||
self.debugMessage(
|
||||
CryptoBoxLogger.DebugLevels["warn"],
|
||||
"retrieving of partition type via 'blkid' failed: %s" % (proc.stderr.read().strip(), ))
|
||||
self.log.warn("retrieving of partition type via 'blkid' failed: %s" % (proc.stderr.read().strip(), ))
|
||||
return None
|
||||
devnull.close()
|
||||
return output
|
||||
|
@ -264,9 +255,7 @@ class CryptoBoxContainer:
|
|||
try:
|
||||
devnull = open(os.devnull, "w")
|
||||
except IOError:
|
||||
self.debugMessage(
|
||||
CryptoBoxLogger.DebugLevels["warn"],
|
||||
"Could not open %s" % (os.devnull, ))
|
||||
self.log.warn("Could not open %s" % (os.devnull, ))
|
||||
proc = subprocess.Popen(
|
||||
shell = False,
|
||||
stdin = None,
|
||||
|
@ -296,15 +285,13 @@ class CryptoBoxContainer:
|
|||
try:
|
||||
devnull = open(os.devnull, "w")
|
||||
except IOError:
|
||||
self.debugMessage(
|
||||
CryptoBoxLogger.DebugLevels["warn"],
|
||||
"Could not open %s" % (os.devnull, ))
|
||||
self.log.warn("Could not open %s" % (os.devnull, ))
|
||||
self.__cleanMountDirs()
|
||||
if not os.path.exists(self.__getMountPoint()):
|
||||
os.mkdir(self.__getMountPoint())
|
||||
if not os.path.exists(self.__getMountPoint()):
|
||||
errorMsg = "Could not create mountpoint (%s)" % (self.__getMountPoint(), )
|
||||
self.debugMessage("error", errorMsg)
|
||||
self.log.error(errorMsg)
|
||||
raise "MountError", errorMsg
|
||||
proc = subprocess.Popen(
|
||||
shell = False,
|
||||
|
@ -321,7 +308,7 @@ class CryptoBoxContainer:
|
|||
(output, errout) = proc.communicate()
|
||||
if proc.returncode != 0:
|
||||
errorMsg = "Could not open the luks mapping: %s" % (errout.strip(), )
|
||||
self.debugMessage(CryptoBoxLogger.DebugLevels["warn"], errorMsg)
|
||||
self.log.warn(errorMsg)
|
||||
raise "MountError", errorMsg
|
||||
proc = subprocess.Popen(
|
||||
shell = False,
|
||||
|
@ -335,7 +322,7 @@ class CryptoBoxContainer:
|
|||
proc.wait()
|
||||
if proc.returncode != 0:
|
||||
errorMsg = "Could not mount the filesystem: %s" % (proc.stderr.read().strip(), )
|
||||
self.debugMessage(CryptoBoxLogger.DebugLevels["warn"], errorMsg)
|
||||
self.log.warn(errorMsg)
|
||||
raise "MountError", errorMsg
|
||||
devnull.close()
|
||||
|
||||
|
@ -346,9 +333,7 @@ class CryptoBoxContainer:
|
|||
try:
|
||||
devnull = open(os.devnull, "w")
|
||||
except IOError:
|
||||
self.debugMessage(
|
||||
CryptoBoxLogger.DebugLevels["warn"],
|
||||
"Could not open %s" % (os.devnull, ))
|
||||
self.log.warn("Could not open %s" % (os.devnull, ))
|
||||
if self.isMounted():
|
||||
proc = subprocess.Popen(
|
||||
shell = False,
|
||||
|
@ -359,7 +344,7 @@ class CryptoBoxContainer:
|
|||
proc.wait()
|
||||
if proc.returncode != 0:
|
||||
errorMsg = "Could not umount the filesystem: %s" % (proc.stderr.read().strip(), )
|
||||
self.debugMessage(CryptoBoxLogger.DebugLevels["warn"], errorMsg)
|
||||
self.log.warn(errorMsg)
|
||||
raise "MountError", errorMsg
|
||||
if os.path.exists(os.path.join(self.__dmDir, self.name)):
|
||||
proc = subprocess.Popen(
|
||||
|
@ -375,7 +360,7 @@ class CryptoBoxContainer:
|
|||
proc.wait()
|
||||
if proc.returncode != 0:
|
||||
errorMsg = "Could not remove the luks mapping: %s" % (proc.stderr.read().strip(), )
|
||||
self.debugMessage(CryptoBoxLogger.DebugLevels["warn"], errorMsg)
|
||||
self.log.warn(errorMsg)
|
||||
raise "MountError", errorMsg
|
||||
devnull.close()
|
||||
|
||||
|
@ -387,15 +372,13 @@ class CryptoBoxContainer:
|
|||
try:
|
||||
devnull = open(os.devnull, "w")
|
||||
except IOError:
|
||||
self.debugMessage(
|
||||
CryptoBoxLogger.DebugLevels["warn"],
|
||||
"Could not open %s" % (os.devnull, ))
|
||||
self.log.warn("Could not open %s" % (os.devnull, ))
|
||||
self.__cleanMountDirs()
|
||||
if not os.path.exists(self.__getMountPoint()):
|
||||
os.mkdir(self.__getMountPoint())
|
||||
if not os.path.exists(self.__getMountPoint()):
|
||||
errorMsg = "Could not create mountpoint (%s)" % (self.__getMountPoint(), )
|
||||
self.debugMessage("error", errorMsg)
|
||||
self.log.error(errorMsg)
|
||||
raise "MountError", errorMsg
|
||||
proc = subprocess.Popen(
|
||||
shell = False,
|
||||
|
@ -409,7 +392,7 @@ class CryptoBoxContainer:
|
|||
proc.wait()
|
||||
if proc.returncode != 0:
|
||||
errorMsg = "Could not mount the filesystem: %s" % (proc.stderr.read().strip(), )
|
||||
self.debugMessage(CryptoBoxLogger.DebugLevels["warn"], errorMsg)
|
||||
self.log.warn(errorMsg)
|
||||
raise "MountError", errorMsg
|
||||
devnull.close()
|
||||
|
||||
|
@ -420,9 +403,7 @@ class CryptoBoxContainer:
|
|||
try:
|
||||
devnull = open(os.devnull, "w")
|
||||
except IOError:
|
||||
self.debugMessage(
|
||||
CryptoBoxLogger.DebugLevels["warn"],
|
||||
"Could not open %s" % (os.devnull, ))
|
||||
self.log.warn("Could not open %s" % (os.devnull, ))
|
||||
if self.isMounted():
|
||||
proc = subprocess.Popen(
|
||||
shell = False,
|
||||
|
@ -436,7 +417,7 @@ class CryptoBoxContainer:
|
|||
proc.wait()
|
||||
if proc.returncode != 0:
|
||||
errorMsg = "Could not umount the filesystem: %s" % (proc.stderr.read().strip(), )
|
||||
self.debugMessage(CryptoBoxLogger.DebugLevels["warn"], errorMsg)
|
||||
self.log.warn(errorMsg)
|
||||
raise "MountError", errorMsg
|
||||
devnull.close()
|
||||
|
||||
|
@ -450,9 +431,7 @@ class CryptoBoxContainer:
|
|||
try:
|
||||
devnull = open(os.devnull, "w")
|
||||
except IOError:
|
||||
self.debugMessage(
|
||||
CryptoBoxLogger.DebugLevels["warn"],
|
||||
"Could not open %s" % (os.devnull, ))
|
||||
self.log.warn("Could not open %s" % (os.devnull, ))
|
||||
proc = subprocess.Popen(
|
||||
shell = False,
|
||||
stdin = None,
|
||||
|
@ -464,7 +443,7 @@ class CryptoBoxContainer:
|
|||
proc.wait()
|
||||
if proc.returncode != 0:
|
||||
errorMsg = "Could not create the filesystem: %s" % (proc.stderr.read().strip(), )
|
||||
self.debugMessage(CryptoBoxLogger.DebugLevels["error"], errorMsg)
|
||||
self.log.error(errorMsg)
|
||||
raise "CreateError", errorMsg
|
||||
devnull.close()
|
||||
|
||||
|
@ -480,9 +459,7 @@ class CryptoBoxContainer:
|
|||
try:
|
||||
devnull = open(os.devnull, "w")
|
||||
except IOError:
|
||||
self.debugMessage(
|
||||
CryptoBoxLogger.DebugLevels["warn"],
|
||||
"Could not open %s" % (os.devnull, ))
|
||||
self.log.warn("Could not open %s" % (os.devnull, ))
|
||||
"remove any potential open luks mapping"
|
||||
self.__umountLuks()
|
||||
"create the luks header"
|
||||
|
@ -502,7 +479,7 @@ class CryptoBoxContainer:
|
|||
(output, errout) = proc.communicate()
|
||||
if proc.returncode != 0:
|
||||
errorMsg = "Could not create the luks header: %s" % (errout.strip(), )
|
||||
self.debugMessage("error", errorMsg)
|
||||
self.log.error(errorMsg)
|
||||
raise "CreateError", errorMsg
|
||||
"open the luks container for mkfs"
|
||||
proc = subprocess.Popen(
|
||||
|
@ -520,7 +497,7 @@ class CryptoBoxContainer:
|
|||
(output, errout) = proc.communicate()
|
||||
if proc.returncode != 0:
|
||||
errorMsg = "Could not open the new luks mapping: %s" % (errout.strip(), )
|
||||
self.debugMessage(CryptoBoxLogger.DebugLevels["error"], errorMsg)
|
||||
self.log.error(errorMsg)
|
||||
raise "CreateError", errorMsg
|
||||
"make the filesystem"
|
||||
proc = subprocess.Popen(
|
||||
|
@ -536,7 +513,7 @@ class CryptoBoxContainer:
|
|||
self.__umountLuks()
|
||||
if proc.returncode != 0:
|
||||
errorMsg = "Could not create the filesystem: %s" % (proc.stderr.read().strip(), )
|
||||
self.debugMessage(CryptoBoxLogger.DebugLevels["error"], errorMsg)
|
||||
self.log.error(errorMsg)
|
||||
"remove the luks mapping"
|
||||
raise "CreateError", errorMsg
|
||||
devnull.close()
|
||||
|
@ -548,6 +525,7 @@ class CryptoBoxContainer:
|
|||
subdirs = os.listdir(self.cbox.cbxPrefs["System"]["MountParentDir"])
|
||||
for dir in subdirs:
|
||||
abs_dir = os.path.join(self.cbox.cbxPrefs["System"]["MountParentDir"], dir)
|
||||
if (not os.path.islink(abs_dir)) and os.path.isdir(abs_dir) and (not os.path.ismount(abs_dir)): os.rmdir(abs_dir)
|
||||
if (not os.path.islink(abs_dir)) and os.path.isdir(abs_dir) and (not os.path.ismount(abs_dir)):
|
||||
os.rmdir(abs_dir)
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue