aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarel Zak <kzak@redhat.com>2012-05-28 11:37:36 +0200
committerKarel Zak <kzak@redhat.com>2012-05-28 11:37:36 +0200
commit3fc480b952aa925710f9f869add09563e2c47787 (patch)
tree71524c75a6f7288f0c39a67dc12bdeca91387685
parentcda4f8f10b174a6417443730af160ba484f6fcb2 (diff)
downloadutil-linux-3fc480b952aa925710f9f869add09563e2c47787.tar.gz
mount: (old) fix encryption= usage
Addresses: https://github.com/karelzak/util-linux/issues/12 Signed-off-by: Karel Zak <kzak@redhat.com>
-rw-r--r--mount/Makefile.am1
-rw-r--r--mount/mount.c30
2 files changed, 26 insertions, 5 deletions
diff --git a/mount/Makefile.am b/mount/Makefile.am
index 40f30f0635..d0514674c0 100644
--- a/mount/Makefile.am
+++ b/mount/Makefile.am
@@ -29,6 +29,7 @@ srcs_mount = \
$(top_srcdir)/lib/loopdev.c \
$(top_srcdir)/lib/mangle.c \
$(top_srcdir)/lib/strutils.c \
+ $(top_srcdir)/lib/xgetpass.c \
$(top_srcdir)/lib/sysfs.c
# generic flags for all programs
diff --git a/mount/mount.c b/mount/mount.c
index 19fe42e7f2..4ebcc1154b 100644
--- a/mount/mount.c
+++ b/mount/mount.c
@@ -42,6 +42,7 @@
#include "blkdev.h"
#include "strutils.h"
#include "closestream.h"
+#include "xgetpass.h"
#define DO_PS_FIDDLING
@@ -1239,6 +1240,8 @@ loop_check(const char **spec, const char **type, int *flags,
int looptype;
uintmax_t offset = 0, sizelimit = 0;
struct loopdev_cxt lc;
+ char *pwd = NULL;
+ int ret = EX_FAIL;
/*
* In the case of a loop mount, either type is of the form lo@/dev/loop5
@@ -1318,8 +1321,18 @@ loop_check(const char **spec, const char **type, int *flags,
return EX_FAIL;
}
+ if (opt_encryption) {
+#ifdef MCL_FUTURE
+ if (mlockall(MCL_CURRENT | MCL_FUTURE)) {
+ error(_("mount: couldn't lock into memory"));
+ return EX_FAIL;
+ }
+#endif
+ pwd = xgetpass(pfd, _("Password: "));
+ }
+
loopcxt_init(&lc, 0);
- /* loopcxt_enable_debug(&lc, 1); */
+ /*loopcxt_enable_debug(&lc, 1);*/
if (*loopdev && **loopdev)
loopcxt_set_device(&lc, *loopdev); /* use loop=<devname> */
@@ -1344,6 +1357,8 @@ loop_check(const char **spec, const char **type, int *flags,
rc = loopcxt_set_offset(&lc, offset);
if (!rc && sizelimit)
rc = loopcxt_set_sizelimit(&lc, sizelimit);
+ if (!rc && opt_encryption && pwd)
+ loopcxt_set_encryption(&lc, opt_encryption, pwd);
if (!rc)
loopcxt_set_flags(&lc, loop_opts);
@@ -1359,8 +1374,7 @@ loop_check(const char **spec, const char **type, int *flags,
break; /* success */
if (rc != -EBUSY) {
- if (verbose)
- printf(_("mount: failed setting up loop device\n"));
+ error(_("mount: %s: failed setting up loop device: %m"), *loopfile);
if (!opt_loopdev) {
my_free(*loopdev);
*loopdev = NULL;
@@ -1400,9 +1414,15 @@ loop_check(const char **spec, const char **type, int *flags,
}
}
- return 0;
+ ret = 0;
err:
- return EX_FAIL;
+ if (pwd) {
+ char *p = pwd;
+ while (*p)
+ *p++ = '\0';
+ free(pwd);
+ }
+ return ret;
}