diff options
author | Karel Zak | 2012-01-11 16:16:00 +0100 |
---|---|---|
committer | Karel Zak | 2012-01-11 16:16:00 +0100 |
commit | 1a7a421ed74bc8502cdd9d1de46bc78c62b71b7d (patch) | |
tree | 1eb7fc58b8ec2f414246c52d0350fa7b04c01d51 /libmount/src/context_loopdev.c | |
parent | losetup: add note about non-root users to losetup.8 (diff) | |
download | kernel-qcow2-util-linux-1a7a421ed74bc8502cdd9d1de46bc78c62b71b7d.tar.gz kernel-qcow2-util-linux-1a7a421ed74bc8502cdd9d1de46bc78c62b71b7d.tar.xz kernel-qcow2-util-linux-1a7a421ed74bc8502cdd9d1de46bc78c62b71b7d.zip |
libmount: add support for encrypted loopdevs
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libmount/src/context_loopdev.c')
-rw-r--r-- | libmount/src/context_loopdev.c | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/libmount/src/context_loopdev.c b/libmount/src/context_loopdev.c index 6221166ff..d32e70966 100644 --- a/libmount/src/context_loopdev.c +++ b/libmount/src/context_loopdev.c @@ -34,7 +34,8 @@ int mnt_context_is_loopdev(struct libmnt_context *cxt) if (cxt->user_mountflags & (MNT_MS_LOOP | MNT_MS_OFFSET | - MNT_MS_SIZELIMIT)) + MNT_MS_SIZELIMIT | + MNT_MS_ENCRYPTION)) return 1; if (cxt->mountflags & (MS_BIND | MS_MOVE | MS_PROPAGATION)) @@ -64,7 +65,7 @@ int mnt_context_is_loopdev(struct libmnt_context *cxt) int mnt_context_setup_loopdev(struct libmnt_context *cxt) { const char *backing_file, *optstr, *loopdev = NULL; - char *val = NULL; + char *val = NULL, *enc = NULL, *pwd = NULL; size_t len; struct loopdev_cxt lc; int rc = 0, lo_flags = 0; @@ -125,6 +126,20 @@ int mnt_context_setup_loopdev(struct libmnt_context *cxt) DBG(CXT, mnt_debug_h(cxt, "failed to parse sizelimit=")); } + /* + * encryption= + */ + if (rc == 0 && (cxt->user_mountflags & MNT_MS_ENCRYPTION) && + mnt_optstr_get_option(optstr, "encryption", &val, &len) == 0) { + enc = strndup(val, len); + if (val && !enc) + rc = -ENOMEM; + if (enc && cxt->pwd_get_cb) { + DBG(CXT, mnt_debug_h(cxt, "asking for pass")); + pwd = cxt->pwd_get_cb(cxt); + } + } + if (rc) goto done; @@ -156,6 +171,8 @@ int mnt_context_setup_loopdev(struct libmnt_context *cxt) rc = loopcxt_set_offset(&lc, offset); if (!rc && sizelimit) rc = loopcxt_set_sizelimit(&lc, sizelimit); + if (!rc && enc && pwd) + loopcxt_set_encryption(&lc, enc, pwd); if (!rc) loopcxt_set_flags(&lc, lo_flags); if (rc) { @@ -208,6 +225,11 @@ int mnt_context_setup_loopdev(struct libmnt_context *cxt) loopcxt_set_fd(&lc, -1, 0); } done: + free(enc); + if (pwd && cxt->pwd_release_cb) { + DBG(CXT, mnt_debug_h(cxt, "release pass")); + cxt->pwd_release_cb(cxt, pwd); + } loopcxt_deinit(&lc); return rc; } |