From 6a735c2c5bfd64b06fd210663c1ebfeac6eef061 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 31 Oct 2019 13:51:29 +0100 Subject: [PATCH] libmount: make sure optsmode is initialized Since 34333e5244167a8f6385faa350938ed5cb6d5c0a we apply fstab options manually by mnt_context_apply_fs() on --all. The function does not work correctly when optsmode is zero. Signed-off-by: Karel Zak --- libmount/src/context.c | 29 ++++++++++++++++++++++------- libmount/src/context_mount.c | 6 ++++-- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/libmount/src/context.c b/libmount/src/context.c index 4b606cffca..977842f7d8 100644 --- a/libmount/src/context.c +++ b/libmount/src/context.c @@ -2284,8 +2284,23 @@ int mnt_context_apply_fs(struct libmnt_context *cxt, struct libmnt_fs *fs) { int rc; + if (!cxt->optsmode) { + if (mnt_context_is_restricted(cxt)) { + DBG(CXT, ul_debugobj(cxt, "force fstab usage for non-root users!")); + cxt->optsmode = MNT_OMODE_USER; + } else { + DBG(CXT, ul_debugobj(cxt, "use default optsmode")); + cxt->optsmode = MNT_OMODE_AUTO; + } + } + DBG(CXT, ul_debugobj(cxt, "apply entry:")); DBG(CXT, mnt_fs_print_debug(fs, stderr)); + DBG(CXT, ul_debugobj(cxt, "OPTSMODE (opt-part): ignore=%d, append=%d, prepend=%d, replace=%d", + cxt->optsmode & MNT_OMODE_IGNORE ? 1 : 0, + cxt->optsmode & MNT_OMODE_APPEND ? 1 : 0, + cxt->optsmode & MNT_OMODE_PREPEND ? 1 : 0, + cxt->optsmode & MNT_OMODE_REPLACE ? 1 : 0)); /* copy from fs to our FS description */ @@ -2300,7 +2315,7 @@ int mnt_context_apply_fs(struct libmnt_context *cxt, struct libmnt_fs *fs) rc = mnt_fs_set_root(cxt->fs, mnt_fs_get_root(fs)); if (rc) - return rc; + goto done; if (cxt->optsmode & MNT_OMODE_IGNORE) ; @@ -2315,6 +2330,11 @@ int mnt_context_apply_fs(struct libmnt_context *cxt, struct libmnt_fs *fs) if (!rc) cxt->flags |= MNT_FL_TAB_APPLIED; + +done: + DBG(CXT, ul_debugobj(cxt, "final entry [rc=%d]:", rc)); + DBG(CXT, mnt_fs_print_debug(cxt->fs, stderr)); + return rc; } @@ -2406,12 +2426,7 @@ int mnt_context_apply_fstab(struct libmnt_context *cxt) tgt = mnt_fs_get_target(cxt->fs); } - DBG(CXT, ul_debugobj(cxt, "OPTSMODE: ignore=%d, append=%d, prepend=%d, " - "replace=%d, force=%d, fstab=%d, mtab=%d", - cxt->optsmode & MNT_OMODE_IGNORE ? 1 : 0, - cxt->optsmode & MNT_OMODE_APPEND ? 1 : 0, - cxt->optsmode & MNT_OMODE_PREPEND ? 1 : 0, - cxt->optsmode & MNT_OMODE_REPLACE ? 1 : 0, + DBG(CXT, ul_debugobj(cxt, "OPTSMODE (file-part): force=%d, fstab=%d, mtab=%d", cxt->optsmode & MNT_OMODE_FORCE ? 1 : 0, cxt->optsmode & MNT_OMODE_FSTAB ? 1 : 0, cxt->optsmode & MNT_OMODE_MTAB ? 1 : 0)); diff --git a/libmount/src/context_mount.c b/libmount/src/context_mount.c index 70a843e89b..aae21d4903 100644 --- a/libmount/src/context_mount.c +++ b/libmount/src/context_mount.c @@ -225,10 +225,12 @@ static int fix_optstr(struct libmnt_context *cxt) if (!cxt->fs || (cxt->flags & MNT_FL_MOUNTOPTS_FIXED)) return 0; - DBG(CXT, ul_debugobj(cxt, "mount: fixing optstr")); - fs = cxt->fs; + DBG(CXT, ul_debugobj(cxt, "mount: fixing options, current " + "vfs: '%s' fs: '%s' user: '%s', optstr: '%s'", + fs->vfs_optstr, fs->fs_optstr, fs->user_optstr, fs->optstr)); + /* * The "user" options is our business (so we can modify the option), * the exception is command line for /sbin/mount. helpers. Let's -- 2.47.2