From owner-freebsd-bugs@FreeBSD.ORG Fri Jul 29 12:50:21 2005 Return-Path: X-Original-To: freebsd-bugs@hub.freebsd.org Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 9A50F16A41F for ; Fri, 29 Jul 2005 12:50:21 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id C98B543D4C for ; Fri, 29 Jul 2005 12:50:19 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.3/8.13.3) with ESMTP id j6TCoJgj095835 for ; Fri, 29 Jul 2005 12:50:19 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.3/8.13.1/Submit) id j6TCoJdt095834; Fri, 29 Jul 2005 12:50:19 GMT (envelope-from gnats) Resent-Date: Fri, 29 Jul 2005 12:50:19 GMT Resent-Message-Id: <200507291250.j6TCoJdt095834@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Mikolaj Rydzewski Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id AB59416A41F for ; Fri, 29 Jul 2005 12:44:15 +0000 (GMT) (envelope-from miki@ma.krakow.pl) Received: from k2.ma.krakow.pl (k2.ma.krakow.pl [62.121.133.130]) by mx1.FreeBSD.org (Postfix) with ESMTP id 42C5E43D4C for ; Fri, 29 Jul 2005 12:44:12 +0000 (GMT) (envelope-from miki@ma.krakow.pl) Received: from k2.ma.krakow.pl (localhost [127.0.0.1]) by k2.ma.krakow.pl (8.13.4/8.13.4) with ESMTP id j6TChxiP078432 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Fri, 29 Jul 2005 14:43:59 +0200 (CEST) (envelope-from miki@k2.ma.krakow.pl) Received: (from miki@localhost) by k2.ma.krakow.pl (8.13.4/8.13.4/Submit) id j6TChxb7078431; Fri, 29 Jul 2005 14:43:59 +0200 (CEST) (envelope-from miki) Message-Id: <200507291243.j6TChxb7078431@k2.ma.krakow.pl> Date: Fri, 29 Jul 2005 14:43:59 +0200 (CEST) From: Mikolaj Rydzewski To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Cc: Subject: bin/84298: [patch] allow mount(8) to recognize relative pathnames as mountpoints X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Mikolaj Rydzewski List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 29 Jul 2005 12:50:21 -0000 >Number: 84298 >Category: bin >Synopsis: [patch] allow mount(8) to recognize relative pathnames as mountpoints >Confidential: no >Severity: non-critical >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Fri Jul 29 12:50:19 GMT 2005 >Closed-Date: >Last-Modified: >Originator: Mikolaj Rydzewski >Release: FreeBSD 5.4-RELEASE-p5 i386 >Organization: >Environment: System: FreeBSD k2.ma.krakow.pl 5.4-RELEASE-p5 FreeBSD 5.4-RELEASE-p5 #3: Tue Jul 26 13:11:08 CEST 2005 miki@k2.ma.krakow.pl:/usr/src/sys/i386/compile/K2 i386 >Description: Current version of mount(8) requires to specify absolute mountpoint pathname. Let's assume one has some mountpoints located in /mnt: /mnt/cdrom, /mnt/floppy, /mnt/usb It should be possible to call mount(8) like this: mount cdrom (assuming the current directory is /mnt). It has more practical impact when system is configured to allow non-root users to mount (cdroms, usb sticks) to mountpoints in their home directories. It's much more flexible to run mount ~/usb than mount /home//usb. And last but not least ;-) mount(8) is supposed to behave in such way - there's a correct call to realpath(3), but infortunately previous function checks mountpoint validity without using realpath(3) call. So my patch just polishes existing code. >How-To-Repeat: Try to mount a filesystem using non absolute path name - an error will occur. >Fix: Apply attached patch. --- mount_patch begins here --- diff -Nru sbin/mount.old/getmntopts.c sbin/mount/getmntopts.c --- sbin/mount.old/getmntopts.c Fri Jul 29 13:55:33 2005 +++ sbin/mount/getmntopts.c Fri Jul 29 14:08:03 2005 @@ -140,3 +140,18 @@ } else errx(EX_USAGE, "%s: %s", resolved, strerror(errno)); } + +const char * +getrealpath(path, resolved) + const char *path; + char *resolved; +{ + struct stat sb; + + if (realpath(path, resolved) != NULL + && stat(resolved, &sb) == 0 + && S_ISDIR(sb.st_mode)) + return resolved; + + return path; +} diff -Nru sbin/mount.old/mntopts.h sbin/mount/mntopts.h --- sbin/mount.old/mntopts.h Fri Jul 29 13:55:33 2005 +++ sbin/mount/mntopts.h Fri Jul 29 14:07:15 2005 @@ -91,4 +91,5 @@ void getmntopts(const char *, const struct mntopt *, int *, int *); void rmslashes(char *, char *); void checkpath(const char *, char resolved_path[]); +const char* getrealpath(const char *, char resolved_path[]); extern int getmnt_silent; diff -Nru sbin/mount.old/mount.c sbin/mount/mount.c --- sbin/mount.old/mount.c Fri Jul 29 13:55:33 2005 +++ sbin/mount/mount.c Fri Jul 29 14:12:42 2005 @@ -126,13 +126,14 @@ int argc; char * const argv[]; { - const char *mntfromname, **vfslist, *vfstype; + const char *mntfromname, **vfslist, *vfstype, *mntpath_ptr; struct fstab *fs; struct statfs *mntbuf; FILE *mountdfp; pid_t pid; int all, ch, i, init_flags, mntsize, rval, have_fstab; char *cp, *ep, *options; + char mntpath[PATH_MAX]; all = init_flags = 0; options = NULL; @@ -271,8 +272,9 @@ mntbuf->f_mntonname, init_flags, options, 0); break; } - if ((fs = getfsfile(*argv)) == NULL && - (fs = getfsspec(*argv)) == NULL) + mntpath_ptr = getrealpath(*argv, mntpath); + if ((fs = getfsfile(mntpath_ptr)) == NULL && + (fs = getfsspec(mntpath_ptr)) == NULL) errx(1, "%s: unknown special file or file system", *argv); if (BADTYPE(fs->fs_type)) --- mount_patch ends here --- >Release-Note: >Audit-Trail: >Unformatted: