]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: make sure optsmode is initialized
authorKarel Zak <kzak@redhat.com>
Thu, 31 Oct 2019 12:51:29 +0000 (13:51 +0100)
committerKarel Zak <kzak@redhat.com>
Thu, 31 Oct 2019 12:51:29 +0000 (13:51 +0100)
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 <kzak@redhat.com>
libmount/src/context.c
libmount/src/context_mount.c

index 4b606cffca7e508c7f1068600e8c92b8a20a7d1c..977842f7d89af6fd1e406caed503ba58cd12eb2f 100644 (file)
@@ -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));
index 70a843e89b6146ace9722e44bcee2dff0f7bea0b..aae21d49037baf7e917875b4e5c1cd17c5857806 100644 (file)
@@ -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.<type> helpers. Let's