mount tmpfs if no config partition is available (Closes: #117)
This commit is contained in:
parent
772d617b73
commit
93e49bf2f2
|
@ -54,6 +54,8 @@ OVERRIDE_FILECHECK = False
|
||||||
|
|
||||||
DEV_TYPES = { "pipe":1, "char":2, "dir":4, "block":6, "file":8, "link":10, "socket":12}
|
DEV_TYPES = { "pipe":1, "char":2, "dir":4, "block":6, "file":8, "link":10, "socket":12}
|
||||||
EVENT_MARKER = '_event_scripts_'
|
EVENT_MARKER = '_event_scripts_'
|
||||||
|
## use this string as device name if you want to mount a ramdisk
|
||||||
|
MAGIC_TMPFS = "_tmpfs_"
|
||||||
|
|
||||||
|
|
||||||
def checkIfFileIsSafe(fname):
|
def checkIfFileIsSafe(fname):
|
||||||
|
@ -274,8 +276,10 @@ def run_mount(args):
|
||||||
del args[0]
|
del args[0]
|
||||||
destination = args[0]
|
destination = args[0]
|
||||||
del args[0]
|
del args[0]
|
||||||
|
## shall we mount a ramdisk?
|
||||||
|
is_tmpfs = (device == MAGIC_TMPFS)
|
||||||
# check permissions for the device
|
# check permissions for the device
|
||||||
if not isWriteable(device, DEV_TYPES["block"]):
|
if (not is_tmpfs) and (not isWriteable(device, DEV_TYPES["block"])):
|
||||||
raise "WrongArguments", "%s is not a writeable block device" % (device, )
|
raise "WrongArguments", "%s is not a writeable block device" % (device, )
|
||||||
## check permissions for the mountpoint
|
## check permissions for the mountpoint
|
||||||
if not isWriteable(destination, DEV_TYPES["dir"]):
|
if not isWriteable(destination, DEV_TYPES["dir"]):
|
||||||
|
@ -296,17 +300,24 @@ def run_mount(args):
|
||||||
## first: get the user/group of the target
|
## first: get the user/group of the target
|
||||||
(trustUserName, trustUID, groupsOfTrustUser) = getUserInfo(savedUID)
|
(trustUserName, trustUID, groupsOfTrustUser) = getUserInfo(savedUID)
|
||||||
trustGID = groupsOfTrustUser[0]
|
trustGID = groupsOfTrustUser[0]
|
||||||
|
if is_tmpfs:
|
||||||
|
fsType = "tmpfs"
|
||||||
|
else:
|
||||||
fsType = getFSType(device)
|
fsType = getFSType(device)
|
||||||
## define arguments
|
## define arguments
|
||||||
if fsType == "vfat":
|
if fsType == "vfat":
|
||||||
## add the "uid/gid" arguments to the mount call
|
## add the "uid/gid" arguments to the mount call
|
||||||
mount_args = [allowedProgs["mount"],
|
mount_args = [ allowedProgs["mount"],
|
||||||
"-o", "uid=%d,gid=%d,umask=0000" % (trustUID, trustGID),
|
"-o", "uid=%d,gid=%d,umask=0000" % (trustUID, trustGID),
|
||||||
device,
|
device,
|
||||||
destination]
|
destination ]
|
||||||
|
elif is_tmpfs:
|
||||||
|
mount_args = [ allowedProgs["mount"],
|
||||||
|
"-t", "tmpfs",
|
||||||
|
"cryptobox-tmpfs", destination ]
|
||||||
else:
|
else:
|
||||||
## all other filesystem types will be handled after mount
|
## all other filesystem types will be handled after mount
|
||||||
mount_args = [allowedProgs["mount"], device, destination]
|
mount_args = [ allowedProgs["mount"], device, destination ]
|
||||||
# execute mount
|
# execute mount
|
||||||
proc = subprocess.Popen(
|
proc = subprocess.Popen(
|
||||||
shell = False,
|
shell = False,
|
||||||
|
|
|
@ -46,6 +46,7 @@ class CryptoBoxSettings:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, config_file=None):
|
def __init__(self, config_file=None):
|
||||||
|
self.__is_initialized = False
|
||||||
self.log = logging.getLogger("CryptoBox")
|
self.log = logging.getLogger("CryptoBox")
|
||||||
config_file = self.__get_config_filename(config_file)
|
config_file = self.__get_config_filename(config_file)
|
||||||
self.log.info("loading config file: %s" % config_file)
|
self.log.info("loading config file: %s" % config_file)
|
||||||
|
@ -59,6 +60,7 @@ class CryptoBoxSettings:
|
||||||
self.user_db = self.__get_user_db()
|
self.user_db = self.__get_user_db()
|
||||||
self.misc_files = []
|
self.misc_files = []
|
||||||
self.reload_misc_files()
|
self.reload_misc_files()
|
||||||
|
self.__is_initialized = True
|
||||||
|
|
||||||
|
|
||||||
def reload_misc_files(self):
|
def reload_misc_files(self):
|
||||||
|
@ -137,6 +139,10 @@ class CryptoBoxSettings:
|
||||||
for line in file("/proc/mounts"):
|
for line in file("/proc/mounts"):
|
||||||
fields = line.split(" ")
|
fields = line.split(" ")
|
||||||
mount_dir = fields[1]
|
mount_dir = fields[1]
|
||||||
|
fs_type = fields[2]
|
||||||
|
if fs_type == "tmpfs":
|
||||||
|
## skip ramdisks - these are not really "active partitions"
|
||||||
|
continue
|
||||||
try:
|
try:
|
||||||
if os.path.samefile(mount_dir, settings_dir):
|
if os.path.samefile(mount_dir, settings_dir):
|
||||||
return fields[0]
|
return fields[0]
|
||||||
|
@ -158,13 +164,40 @@ class CryptoBoxSettings:
|
||||||
+ "mounted - not mounting again")
|
+ "mounted - not mounting again")
|
||||||
return False
|
return False
|
||||||
conf_partitions = self.get_available_partitions()
|
conf_partitions = self.get_available_partitions()
|
||||||
|
mount_dir = self.prefs["Locations"]["SettingsDir"]
|
||||||
if not conf_partitions:
|
if not conf_partitions:
|
||||||
|
## return, if tmpfs is already mounted
|
||||||
|
if os.path.ismount(mount_dir):
|
||||||
|
self.log.info("A ramdisk seems to be already mounted as a config " \
|
||||||
|
+ "partition - doing nothing ...")
|
||||||
|
## return without any actions
|
||||||
|
return True
|
||||||
self.log.warn("no configuration partition found - you have to create "
|
self.log.warn("no configuration partition found - you have to create "
|
||||||
+ "it first")
|
+ "it first")
|
||||||
#TODO: mount tmpfs in settings directory
|
## mount tmpfs instead to provide a place for storing stuff
|
||||||
self.log.info("Ramdisk (tmpfs) mounted as config partition ...")
|
## "_tmpfs_" as parameter for mount is interpreted as a magic word
|
||||||
|
## by CryptoBoxRootActions
|
||||||
|
proc = subprocess.Popen(
|
||||||
|
shell = False,
|
||||||
|
stdout = subprocess.PIPE,
|
||||||
|
stderr = subprocess.PIPE,
|
||||||
|
args = [
|
||||||
|
self.prefs["Programs"]["super"],
|
||||||
|
self.prefs["Programs"]["CryptoBoxRootActions"],
|
||||||
|
"mount",
|
||||||
|
"_tmpfs_",
|
||||||
|
mount_dir ])
|
||||||
|
(stdout, stderr) = proc.communicate()
|
||||||
|
if proc.returncode != 0:
|
||||||
|
self.log.error("Failed to mount a ramdisk for storing settings: %s" \
|
||||||
|
% stderr)
|
||||||
return False
|
return False
|
||||||
|
self.log.info("Ramdisk (tmpfs) mounted as config partition ...")
|
||||||
|
else:
|
||||||
partition = conf_partitions[0]
|
partition = conf_partitions[0]
|
||||||
|
## umount tmpfs in case it is active
|
||||||
|
if os.path.ismount(mount_dir):
|
||||||
|
self.umount_partition()
|
||||||
proc = subprocess.Popen(
|
proc = subprocess.Popen(
|
||||||
shell = False,
|
shell = False,
|
||||||
stdout = subprocess.PIPE,
|
stdout = subprocess.PIPE,
|
||||||
|
@ -174,20 +207,24 @@ class CryptoBoxSettings:
|
||||||
self.prefs["Programs"]["CryptoBoxRootActions"],
|
self.prefs["Programs"]["CryptoBoxRootActions"],
|
||||||
"mount",
|
"mount",
|
||||||
partition,
|
partition,
|
||||||
self.prefs["Locations"]["SettingsDir"]])
|
mount_dir ])
|
||||||
(stdout, stderr) = proc.communicate()
|
(stdout, stderr) = proc.communicate()
|
||||||
if proc.returncode != 0:
|
if proc.returncode != 0:
|
||||||
self.log.error("failed to mount the configuration partition: %s" % partition)
|
self.log.error("Failed to mount the configuration partition (%s): %s" % \
|
||||||
self.log.error("output of mount: %s" % (stderr,))
|
(partition, stderr))
|
||||||
return False
|
return False
|
||||||
self.log.info("configuration partition mounted: %s" % partition)
|
self.log.info("configuration partition mounted: %s" % partition)
|
||||||
|
## write config files (not during first initialization of this object)
|
||||||
|
if self.__is_initialized:
|
||||||
|
self.write()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def umount_partition(self):
|
def umount_partition(self):
|
||||||
"""Umount the currently active configuration partition.
|
"""Umount the currently active configuration partition.
|
||||||
"""
|
"""
|
||||||
if not self.get_active_partition():
|
mount_dir = self.prefs["Locations"]["SettingsDir"]
|
||||||
|
if not os.path.ismount(mount_dir):
|
||||||
self.log.warn("umountConfigPartition: no configuration partition mounted")
|
self.log.warn("umountConfigPartition: no configuration partition mounted")
|
||||||
return False
|
return False
|
||||||
self.reload_misc_files()
|
self.reload_misc_files()
|
||||||
|
@ -199,11 +236,10 @@ class CryptoBoxSettings:
|
||||||
self.prefs["Programs"]["super"],
|
self.prefs["Programs"]["super"],
|
||||||
self.prefs["Programs"]["CryptoBoxRootActions"],
|
self.prefs["Programs"]["CryptoBoxRootActions"],
|
||||||
"umount",
|
"umount",
|
||||||
self.prefs["Locations"]["SettingsDir"]])
|
mount_dir ])
|
||||||
(stdout, stderr) = proc.communicate()
|
(stdout, stderr) = proc.communicate()
|
||||||
if proc.returncode != 0:
|
if proc.returncode != 0:
|
||||||
self.log.error("failed to unmount the configuration partition")
|
self.log.error("Failed to unmount the configuration partition: %s" % stderr)
|
||||||
self.log.error("output of mount: %s" % (stderr,))
|
|
||||||
return False
|
return False
|
||||||
self.log.info("configuration partition unmounted")
|
self.log.info("configuration partition unmounted")
|
||||||
return True
|
return True
|
||||||
|
|
Loading…
Reference in a new issue