From edf4ef493df31c151b14f14754b96f061d86023c Mon Sep 17 00:00:00 2001 From: Simeon Simeonov Date: Thu, 8 Sep 2016 14:51:21 +0200 Subject: Implement support for luks-encrypted files --- cmount.py | 6 ++++++ cumount.py | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/cmount.py b/cmount.py index 341b5a0..edbacc3 100755 --- a/cmount.py +++ b/cmount.py @@ -20,6 +20,12 @@ def main(): config_dict = json.load(fp) cstm_error = 'Invalid / nonexistent mapping: {0}'.format(sys.argv[1]) data = config_dict[sys.argv[1]] + if data.get('type') == 'efile': + cstm_error = 'Unable to create loop device' + data['device'] = subprocess.check_output(['/usr/sbin/losetup', + '--find', + '--show', + data['device']]).strip() cstm_error = 'system() error' subprocess.check_call(['/sbin/cryptsetup', 'luksOpen', diff --git a/cumount.py b/cumount.py index ad9f681..16aa2f3 100755 --- a/cumount.py +++ b/cumount.py @@ -25,6 +25,15 @@ def main(): subprocess.check_call(['/sbin/cryptsetup', 'luksClose', data['mapper_name']]) + if data.get('type') == 'efile': + cstm_error = 'Unable to destroy loop device' + loop_device = subprocess.check_output(['/usr/sbin/losetup', + '--associated', + data['device']]) + loop_device = loop_device.split(':')[0] + subprocess.check_call(['/usr/sbin/losetup', + '-d', + loop_device]) except subprocess.CalledProcessError as e: sys.stderr.write('Execution error: {0}\n'.format(e)) sys.stderr.flush() -- cgit v1.3