#include <getopt.h>
#include <unistd.h>
#include <sys/types.h>
+#include <sys/mman.h>
#include <libmount.h>
#include "c.h"
#include "env.h"
#include "optutils.h"
+#include "strutils.h"
+#include "xgetpass.h"
/*** TODO: DOCS:
*
- * -p, --pass-fd is unsupported
* --guess-fstype is unsupported
- * -c = --no-canonicalize
*/
/* exit status */
#define EX_FAIL 32 /* mount failure */
#define EX_SOMEOK 64 /* some mount succeeded */
+static int passfd = -1;
+
static void __attribute__((__noreturn__)) exit_non_root(const char *option)
{
const uid_t ruid = getuid();
return 0;
}
+static char *encrypt_pass_get(struct libmnt_context *cxt)
+{
+ if (!cxt)
+ return 0;
+
+#ifdef MCL_FUTURE
+ if (mlockall(MCL_CURRENT | MCL_FUTURE)) {
+ warn(_("couldn't lock into memory"));
+ return NULL;
+ }
+#endif
+ return xgetpass(passfd, _("Password: "));
+}
+
+static void encrypt_pass_release(struct libmnt_context *cxt, char *pwd)
+{
+ char *p = pwd;
+
+ while (p && *p)
+ *p++ = '\0';
+
+ free(pwd);
+ munlockall();
+}
+
static void print_all(struct libmnt_context *cxt, char *pattern, int show_label)
{
struct libmnt_table *tb;
fprintf(out, _(
" -o, --options <list> comma-separated list of mount options\n"
" -O, --test-opts <list> limit the set of filesystems (use with -a)\n"
+ " -p, --pass-fd <num> read the passphrase from file descriptor\n"
" -r, --read-only mount the filesystem read-only (same as -o ro)\n"
" -t, --types <list> limit the set of filesystem types\n"));
fprintf(out, _(
{ "rw", 0, 0, 'w' },
{ "options", 1, 0, 'o' },
{ "test-opts", 1, 0, 'O' },
+ { "pass-fd", 1, 0, 'p' },
{ "types", 1, 0, 't' },
{ "uuid", 1, 0, 'U' },
{ "label", 1, 0, 'L'},
mnt_context_set_tables_errcb(cxt, table_parser_errcb);
- while ((c = getopt_long(argc, argv, "aBcfFhilL:Mno:O:rRsU:vVwt:",
+ while ((c = getopt_long(argc, argv, "aBcfFhilL:Mno:O:p:rRsU:vVwt:",
longopts, NULL)) != -1) {
/* only few options are allowed for non-root users */
- if (mnt_context_is_restricted(cxt) && !strchr("hlLUVv", c))
+ if (mnt_context_is_restricted(cxt) && !strchr("hlLUVvp", c))
exit_non_root(option_to_longopt(c, longopts));
switch(c) {
if (mnt_context_set_options_pattern(cxt, optarg))
err(EX_SYSERR, _("failed to set options pattern"));
break;
+ case 'p':
+ passfd = strtol_or_err(optarg,
+ _("invalid passphrase file descriptor"));
+ break;
case 'L':
case 'U':
if (source)
else if (types)
mnt_context_set_fstype(cxt, types);
+ mnt_context_set_passwd_cb(cxt, encrypt_pass_get, encrypt_pass_release);
+
if (all) {
/*
* A) Mount all