X-Git-Url: https://git.decadent.org.uk/gitweb/?p=nfs-utils.git;a=blobdiff_plain;f=utils%2Fmount%2Fmount_libmount.c;h=701d41e42e2e8725d1f8a2bb1c07d1d343a2a8a8;hp=6dd64846470efc9bb3acc55dc0f4a0b598243ae1;hb=b0b342201140530c5b9e00408f12d22258df7c4e;hpb=a99269230a0e77e7bed4fa31c9547f0d61c7f206 diff --git a/utils/mount/mount_libmount.c b/utils/mount/mount_libmount.c index 6dd6484..701d41e 100644 --- a/utils/mount/mount_libmount.c +++ b/utils/mount/mount_libmount.c @@ -15,8 +15,8 @@ * * You should have received a copy of the GNU General Public * License along with this program; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 021110-1307, USA. + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 0211-1301 USA * */ @@ -61,10 +61,19 @@ int nomtab; * managed by libmount at all. We have to use "mount attributes" that are * private for mount. helpers. */ -static void store_mount_options(struct libmnt_fs *fs, const char *opts) +static void store_mount_options(struct libmnt_fs *fs, const char *nfs_opts) { - mnt_fs_set_fs_options(fs, opts); /* for mtab */ - mnt_fs_set_attributes(fs, opts); /* for non-mtab systems */ + char *o = NULL; + + mnt_fs_set_attributes(fs, nfs_opts); /* for non-mtab systems */ + + /* for mtab create a new options list */ + mnt_optstr_append_option(&o, mnt_fs_get_vfs_options(fs), NULL); + mnt_optstr_append_option(&o, nfs_opts, NULL); + mnt_optstr_append_option(&o, mnt_fs_get_user_options(fs), NULL); + + mnt_fs_set_options(fs, o); + free(o); } /* @@ -131,14 +140,14 @@ static int try_mount(struct libmnt_context *cxt, int bg) return ret; } -/* returns: error = -1, success = 0 , unknown = 1 */ +/* returns: error = -1, success = 1 , not vers4 == 0 */ static int is_vers4(struct libmnt_context *cxt) { struct libmnt_fs *fs = mnt_context_get_fs(cxt); struct libmnt_table *tb = NULL; const char *src = mnt_context_get_source(cxt), *tgt = mnt_context_get_target(cxt); - int rc = 1; + int rc = 0; if (!src || !tgt) return -1; @@ -154,7 +163,7 @@ static int is_vers4(struct libmnt_context *cxt) if (fs) { const char *type = mnt_fs_get_fstype(fs); if (type && strcmp(type, "nfs4") == 0) - rc = 0; + rc = 1; } mnt_free_table(tb); return rc; @@ -164,6 +173,7 @@ static int umount_main(struct libmnt_context *cxt, int argc, char **argv) { int rc, c; char *spec = NULL, *opts = NULL; + int ret = EX_FAIL; static const struct option longopts[] = { { "force", 0, 0, 'f' }, @@ -200,8 +210,6 @@ static int umount_main(struct libmnt_context *cxt, int argc, char **argv) if (mnt_context_set_target(cxt, spec)) goto err; - if (mnt_context_set_fstype_pattern(cxt, "nfs,nfs4")) /* restrict filesystems */ - goto err; /* read mtab/fstab, evaluate permissions, etc. */ rc = mnt_context_prepare_umount(cxt); @@ -211,6 +219,14 @@ static int umount_main(struct libmnt_context *cxt, int argc, char **argv) goto err; } + if (mnt_context_get_fstype(cxt) && + !mnt_match_fstype(mnt_context_get_fstype(cxt), "nfs,nfs4")) { + + nfs_error(_("%s: %s: is not an NFS filesystem"), progname, spec); + ret = EX_USAGE; + goto err; + } + opts = retrieve_mount_options(mnt_context_get_fs(cxt)); if (!mnt_context_is_lazy(cxt)) { @@ -235,6 +251,7 @@ static int umount_main(struct libmnt_context *cxt, int argc, char **argv) nfs_umount23(spec, "tcp,v3"); } + ret = EX_FILEIO; rc = mnt_context_do_umount(cxt); /* call umount(2) syscall */ mnt_context_finalize_mount(cxt); /* mtab update */ @@ -243,12 +260,10 @@ static int umount_main(struct libmnt_context *cxt, int argc, char **argv) umount_error(rc, spec); goto err; } - - free(opts); - return EX_SUCCESS; + ret = EX_SUCCESS; err: free(opts); - return EX_FAIL; + return ret; } static int mount_main(struct libmnt_context *cxt, int argc, char **argv) @@ -337,6 +352,21 @@ static int mount_main(struct libmnt_context *cxt, int argc, char **argv) if (chk_mountpoint(mount_point)) goto err; + + /* + * The libmount strictly uses only options from fstab if running in + * restricted mode (suid, non-root user). This is done in + * mnt_context_prepare_mount() by default. + * + * We have to read fstab before nfsmount.conf, otherwise the options + * from nfsmount.conf will be ignored (overwrited). + */ + rc = mnt_context_apply_fstab(cxt); + if (rc) { + nfs_error(_("%s: failed to apply fstab options\n"), progname); + goto err; + } + /* * Concatenate mount options from the configuration file */