|
Michal Luscon |
85a6551 |
From a4c0cc75ff9744299f108c259efab1bd30c8007a Mon Sep 17 00:00:00 2001
|
|
Michal Luscon |
85a6551 |
From: Karel Zak <kzak@redhat.com>
|
|
Michal Luscon |
85a6551 |
Date: Mon, 2 Jan 2012 11:08:17 +0100
|
|
Michal Luscon |
85a6551 |
Subject: [PATCH] mount: append inverting options for mount.<type>
|
|
Michal Luscon |
85a6551 |
|
|
Michal Luscon |
85a6551 |
fstab:
|
|
Michal Luscon |
85a6551 |
server://foo /mnt/foo nfs user,exec
|
|
Michal Luscon |
85a6551 |
|
|
Michal Luscon |
85a6551 |
The mount(8) does not append the option "exec" to /sbin/mount.<type>
|
|
Michal Luscon |
85a6551 |
helper's command line. This is no problem when executed by non-root
|
|
Michal Luscon |
85a6551 |
user as it reads the options from fstab only.
|
|
Michal Luscon |
85a6551 |
|
|
Michal Luscon |
85a6551 |
.. but when executed by root (UID=0) then the mount.<type> helper
|
|
Michal Luscon |
85a6551 |
follows the command where the "exec" option is missing. This is bug.
|
|
Michal Luscon |
85a6551 |
|
|
Michal Luscon |
85a6551 |
original version (strace output):
|
|
Michal Luscon |
85a6551 |
|
|
Michal Luscon |
85a6551 |
execve("/sbin/mount.nfs", ["/sbin/mount.nfs",
|
|
Michal Luscon |
85a6551 |
"sr.net.home:/mnt/store", "/mnt/store", "-o",
|
|
Michal Luscon |
85a6551 |
"rw,nosuid,nodev,noauto,user"], [/* 21 vars */]) = 0
|
|
Michal Luscon |
85a6551 |
|
|
Michal Luscon |
85a6551 |
fixed version:
|
|
Michal Luscon |
85a6551 |
|
|
Michal Luscon |
85a6551 |
execve("/sbin/mount.nfs", ["/sbin/mount.nfs",
|
|
Michal Luscon |
85a6551 |
"sr.net.home:/mnt/store", "/mnt/store", "-o",
|
|
Michal Luscon |
85a6551 |
"rw,nosuid,nodev,noauto,user,exec"], [/* 21 vars */]) = 0
|
|
Michal Luscon |
85a6551 |
^^^^^
|
|
Michal Luscon |
85a6551 |
|
|
Michal Luscon |
85a6551 |
Signed-off-by: Karel Zak <kzak@redhat.com>
|
|
Michal Luscon |
85a6551 |
---
|
|
Michal Luscon |
85a6551 |
mount/mount.c | 31 ++++++++++++++++++++++++-------
|
|
Michal Luscon |
85a6551 |
1 files changed, 24 insertions(+), 7 deletions(-)
|
|
Michal Luscon |
85a6551 |
|
|
Michal Luscon |
85a6551 |
diff --git a/mount/mount.c b/mount/mount.c
|
|
Michal Luscon |
85a6551 |
index 9b444c4..a18b2df 100644
|
|
Michal Luscon |
85a6551 |
--- a/mount/mount.c
|
|
Michal Luscon |
85a6551 |
+++ b/mount/mount.c
|
|
Michal Luscon |
85a6551 |
@@ -207,6 +207,8 @@ static const struct opt_map opt_map[] = {
|
|
Michal Luscon |
85a6551 |
|
|
Michal Luscon |
85a6551 |
static int opt_nofail = 0;
|
|
Michal Luscon |
85a6551 |
|
|
Michal Luscon |
85a6551 |
+static int invuser_flags;
|
|
Michal Luscon |
85a6551 |
+
|
|
Michal Luscon |
85a6551 |
static const char *opt_loopdev, *opt_vfstype, *opt_offset, *opt_sizelimit,
|
|
Michal Luscon |
85a6551 |
*opt_encryption, *opt_speed, *opt_comment, *opt_uhelper, *opt_helper;
|
|
Michal Luscon |
85a6551 |
|
|
Michal Luscon |
85a6551 |
@@ -473,7 +475,7 @@ static int has_context_option(char *opts)
|
|
Michal Luscon |
85a6551 |
* For the options uid= and gid= replace user or group name by its value.
|
|
Michal Luscon |
85a6551 |
*/
|
|
Michal Luscon |
85a6551 |
static inline void
|
|
Michal Luscon |
85a6551 |
-parse_opt(char *opt, int *mask, char **extra_opts) {
|
|
Michal Luscon |
85a6551 |
+parse_opt(char *opt, int *mask, int *inv_user, char **extra_opts) {
|
|
Michal Luscon |
85a6551 |
const struct opt_map *om;
|
|
Michal Luscon |
85a6551 |
|
|
Michal Luscon |
85a6551 |
for (om = opt_map; om->opt != NULL; om++)
|
|
Michal Luscon |
85a6551 |
@@ -482,6 +484,9 @@ parse_opt(char *opt, int *mask, char **extra_opts) {
|
|
Michal Luscon |
85a6551 |
*mask &= ~om->mask;
|
|
Michal Luscon |
85a6551 |
else
|
|
Michal Luscon |
85a6551 |
*mask |= om->mask;
|
|
Michal Luscon |
85a6551 |
+ if (om->inv && ((*mask & MS_USER) || (*mask & MS_USERS))
|
|
Michal Luscon |
85a6551 |
+ && (om->mask & MS_SECURE))
|
|
Michal Luscon |
85a6551 |
+ *inv_user |= om->mask;
|
|
Michal Luscon |
85a6551 |
if ((om->mask == MS_USER || om->mask == MS_USERS)
|
|
Michal Luscon |
85a6551 |
&& !om->inv)
|
|
Michal Luscon |
85a6551 |
*mask |= MS_SECURE;
|
|
Michal Luscon |
85a6551 |
@@ -566,7 +571,7 @@ parse_opts (const char *options, int *flags, char **extra_opts) {
|
|
Michal Luscon |
85a6551 |
/* end of option item or last item */
|
|
Michal Luscon |
85a6551 |
if (*p == '\0' || *(p+1) == '\0') {
|
|
Michal Luscon |
85a6551 |
if (!parse_string_opt(opt))
|
|
Michal Luscon |
85a6551 |
- parse_opt(opt, flags, extra_opts);
|
|
Michal Luscon |
85a6551 |
+ parse_opt(opt, flags, &invuser_flags, extra_opts);
|
|
Michal Luscon |
85a6551 |
opt = NULL;
|
|
Michal Luscon |
85a6551 |
}
|
|
Michal Luscon |
85a6551 |
}
|
|
Michal Luscon |
85a6551 |
@@ -587,7 +592,9 @@ parse_opts (const char *options, int *flags, char **extra_opts) {
|
|
Michal Luscon |
85a6551 |
|
|
Michal Luscon |
85a6551 |
/* Try to build a canonical options string. */
|
|
Michal Luscon |
85a6551 |
static char *
|
|
Michal Luscon |
85a6551 |
-fix_opts_string (int flags, const char *extra_opts, const char *user) {
|
|
Michal Luscon |
85a6551 |
+fix_opts_string (int flags, const char *extra_opts,
|
|
Michal Luscon |
85a6551 |
+ const char *user, int inv_user)
|
|
Michal Luscon |
85a6551 |
+{
|
|
Michal Luscon |
85a6551 |
const struct opt_map *om;
|
|
Michal Luscon |
85a6551 |
const struct string_opt_map *m;
|
|
Michal Luscon |
85a6551 |
char *new_opts;
|
|
Michal Luscon |
85a6551 |
@@ -611,6 +618,16 @@ fix_opts_string (int flags, const char *extra_opts, const char *user) {
|
|
Michal Luscon |
85a6551 |
if (user)
|
|
Michal Luscon |
85a6551 |
new_opts = append_opt(new_opts, "user=", user);
|
|
Michal Luscon |
85a6551 |
|
|
Michal Luscon |
85a6551 |
+ if (inv_user) {
|
|
Michal Luscon |
85a6551 |
+ for (om = opt_map; om->opt != NULL; om++) {
|
|
Michal Luscon |
85a6551 |
+ if (om->mask && om->inv
|
|
Michal Luscon |
85a6551 |
+ && (inv_user & om->mask) == om->mask) {
|
|
Michal Luscon |
85a6551 |
+ new_opts = append_opt(new_opts, om->opt, NULL);
|
|
Michal Luscon |
85a6551 |
+ inv_user &= ~om->mask;
|
|
Michal Luscon |
85a6551 |
+ }
|
|
Michal Luscon |
85a6551 |
+ }
|
|
Michal Luscon |
85a6551 |
+ }
|
|
Michal Luscon |
85a6551 |
+
|
|
Michal Luscon |
85a6551 |
return new_opts;
|
|
Michal Luscon |
85a6551 |
}
|
|
Michal Luscon |
85a6551 |
|
|
Michal Luscon |
85a6551 |
@@ -662,7 +679,7 @@ create_mtab (void) {
|
|
Michal Luscon |
85a6551 |
mnt.mnt_dir = "/";
|
|
Michal Luscon |
85a6551 |
mnt.mnt_fsname = spec_to_devname(fstab->m.mnt_fsname);
|
|
Michal Luscon |
85a6551 |
mnt.mnt_type = fstab->m.mnt_type;
|
|
Michal Luscon |
85a6551 |
- mnt.mnt_opts = fix_opts_string (flags, extra_opts, NULL);
|
|
Michal Luscon |
85a6551 |
+ mnt.mnt_opts = fix_opts_string (flags, extra_opts, NULL, 0);
|
|
Michal Luscon |
85a6551 |
mnt.mnt_freq = mnt.mnt_passno = 0;
|
|
Michal Luscon |
85a6551 |
free(extra_opts);
|
|
Michal Luscon |
85a6551 |
|
|
Michal Luscon |
85a6551 |
@@ -787,7 +804,7 @@ check_special_mountprog(const char *spec, const char *node, const char *type, in
|
|
Michal Luscon |
85a6551 |
if (setuid(getuid()) < 0)
|
|
Michal Luscon |
85a6551 |
die(EX_FAIL, _("mount: cannot set user id: %s"), strerror(errno));
|
|
Michal Luscon |
85a6551 |
|
|
Michal Luscon |
85a6551 |
- oo = fix_opts_string (flags, extra_opts, NULL);
|
|
Michal Luscon |
85a6551 |
+ oo = fix_opts_string(flags, extra_opts, NULL, invuser_flags);
|
|
Michal Luscon |
85a6551 |
mountargs[i++] = mountprog; /* 1 */
|
|
Michal Luscon |
85a6551 |
mountargs[i++] = (char *) spec; /* 2 */
|
|
Michal Luscon |
85a6551 |
mountargs[i++] = (char *) node; /* 3 */
|
|
Michal Luscon |
85a6551 |
@@ -1659,7 +1676,7 @@ try_mount_one (const char *spec0, const char *node0, const char *types0,
|
|
Michal Luscon |
85a6551 |
}
|
|
Michal Luscon |
85a6551 |
|
|
Michal Luscon |
85a6551 |
#ifdef HAVE_LIBMOUNT_MOUNT
|
|
Michal Luscon |
85a6551 |
- mtab_opts = fix_opts_string(flags & ~MS_NOMTAB, extra_opts, user);
|
|
Michal Luscon |
85a6551 |
+ mtab_opts = fix_opts_string(flags & ~MS_NOMTAB, extra_opts, user, 0);
|
|
Michal Luscon |
85a6551 |
mtab_flags = flags;
|
|
Michal Luscon |
85a6551 |
|
|
Michal Luscon |
85a6551 |
if (fake)
|
|
Michal Luscon |
85a6551 |
@@ -1703,7 +1720,7 @@ try_mount_one (const char *spec0, const char *node0, const char *types0,
|
|
Michal Luscon |
85a6551 |
}
|
|
Michal Luscon |
85a6551 |
|
|
Michal Luscon |
85a6551 |
if (fake || mnt5_res == 0) {
|
|
Michal Luscon |
85a6551 |
- char *mo = fix_opts_string (flags & ~MS_NOMTAB, extra_opts, user);
|
|
Michal Luscon |
85a6551 |
+ char *mo = fix_opts_string (flags & ~MS_NOMTAB, extra_opts, user, 0);
|
|
Michal Luscon |
85a6551 |
const char *tp = types ? types : "unknown";
|
|
Michal Luscon |
85a6551 |
|
|
Michal Luscon |
85a6551 |
/* Mount succeeded, report this (if verbose) and write mtab entry. */
|
|
Michal Luscon |
85a6551 |
--
|
|
Michal Luscon |
85a6551 |
1.7.7.5
|
|
Michal Luscon |
85a6551 |
|