diff options
Diffstat (limited to 'sys')
-rw-r--r-- | sys/kern/vfs_lookup.c | 20 | ||||
-rw-r--r-- | sys/kern/vfs_syscalls.c | 28 | ||||
-rw-r--r-- | sys/sys/namei.h | 27 |
3 files changed, 56 insertions, 19 deletions
diff --git a/sys/kern/vfs_lookup.c b/sys/kern/vfs_lookup.c index 15286e3ec6f..109e144b36a 100644 --- a/sys/kern/vfs_lookup.c +++ b/sys/kern/vfs_lookup.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vfs_lookup.c,v 1.13 1998/01/09 15:16:20 csapuntz Exp $ */ +/* $OpenBSD: vfs_lookup.c,v 1.14 1998/01/09 16:21:56 csapuntz Exp $ */ /* $NetBSD: vfs_lookup.c,v 1.17 1996/02/09 19:00:59 christos Exp $ */ /* @@ -130,6 +130,24 @@ namei(ndp) ndp->ni_vp = NULL; return (error); } + + /* + * Strip trailing slashes, as requested + */ + if (cnp->cn_flags & STRIPSLASHES) { + char *end = cnp->cn_pnbuf + ndp->ni_pathlen - 2; + + cp = end; + while (cp >= cnp->cn_pnbuf && + (*cp == '/')) cp--; + + /* Still some remaining characters in the buffer */ + if (cp >= cnp->cn_pnbuf) { + ndp->ni_pathlen -= (end - cp); + *(cp + 1) = '\0'; + } + } + ndp->ni_loopcnt = 0; /* diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c index a08db234269..700e50588f6 100644 --- a/sys/kern/vfs_syscalls.c +++ b/sys/kern/vfs_syscalls.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vfs_syscalls.c,v 1.36 1998/01/02 05:42:49 deraadt Exp $ */ +/* $OpenBSD: vfs_syscalls.c,v 1.37 1998/01/09 16:21:55 csapuntz Exp $ */ /* $NetBSD: vfs_syscalls.c,v 1.71 1996/04/23 10:29:02 mycroft Exp $ */ /* @@ -1063,12 +1063,19 @@ sys_link(p, v, retval) register struct vnode *vp; struct nameidata nd; int error; + int flags; NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, SCARG(uap, path), p); if ((error = namei(&nd)) != 0) return (error); vp = nd.ni_vp; - NDINIT(&nd, CREATE, LOCKPARENT, UIO_USERSPACE, SCARG(uap, link), p); + + flags = LOCKPARENT; + if (vp->v_type == VDIR) { + flags |= STRIPSLASHES; + } + + NDINIT(&nd, CREATE, flags, UIO_USERSPACE, SCARG(uap, link), p); if ((error = namei(&nd)) != 0) goto out; if (nd.ni_vp) { @@ -1993,14 +2000,23 @@ sys_rename(p, v, retval) register struct vnode *tvp, *fvp, *tdvp; struct nameidata fromnd, tond; int error; + int flags; NDINIT(&fromnd, DELETE, WANTPARENT | SAVESTART, UIO_USERSPACE, SCARG(uap, from), p); if ((error = namei(&fromnd)) != 0) return (error); fvp = fromnd.ni_vp; - NDINIT(&tond, RENAME, LOCKPARENT | LOCKLEAF | NOCACHE | SAVESTART, - UIO_USERSPACE, SCARG(uap, to), p); + + flags = LOCKPARENT | LOCKLEAF | NOCACHE | SAVESTART; + /* + * rename("foo/", "bar/"); is OK + */ + if (fvp->v_type == VDIR) + flags |= STRIPSLASHES; + + NDINIT(&tond, RENAME, flags, + UIO_USERSPACE, SCARG(uap, to), p); if ((error = namei(&tond)) != 0) { VOP_ABORTOP(fromnd.ni_dvp, &fromnd.ni_cnd); vrele(fromnd.ni_dvp); @@ -2077,7 +2093,9 @@ sys_mkdir(p, v, retval) int error; struct nameidata nd; - NDINIT(&nd, CREATE, LOCKPARENT, UIO_USERSPACE, SCARG(uap, path), p); + + NDINIT(&nd, CREATE, LOCKPARENT | STRIPSLASHES, + UIO_USERSPACE, SCARG(uap, path), p); if ((error = namei(&nd)) != 0) return (error); vp = nd.ni_vp; diff --git a/sys/sys/namei.h b/sys/sys/namei.h index 8f7288e4721..cd6dda51d2b 100644 --- a/sys/sys/namei.h +++ b/sys/sys/namei.h @@ -1,4 +1,4 @@ -/* $OpenBSD: namei.h,v 1.4 1997/06/18 17:37:36 tholo Exp $ */ +/* $OpenBSD: namei.h,v 1.5 1998/01/09 16:21:57 csapuntz Exp $ */ /* $NetBSD: namei.h,v 1.11 1996/02/09 18:25:20 christos Exp $ */ /* @@ -127,18 +127,19 @@ struct nameidata { * name being sought. The caller is responsible for releasing the * buffer and for vrele'ing ni_startdir. */ -#define NOCROSSMOUNT 0x00100 /* do not cross mount points */ -#define RDONLY 0x00200 /* lookup with read-only semantics */ -#define HASBUF 0x00400 /* has allocated pathname buffer */ -#define SAVENAME 0x00800 /* save pathanme buffer */ -#define SAVESTART 0x01000 /* save starting directory */ -#define ISDOTDOT 0x02000 /* current component name is .. */ -#define MAKEENTRY 0x04000 /* entry is to be added to name cache */ -#define ISLASTCN 0x08000 /* this is last component of pathname */ -#define ISSYMLINK 0x10000 /* symlink needs interpretation */ -#define ISWHITEOUT 0x20000 /* found whiteout */ -#define DOWHITEOUT 0x40000 /* do whiteouts */ -#define REQUIREDIR 0x80000 /* must be a directory */ +#define NOCROSSMOUNT 0x000100 /* do not cross mount points */ +#define RDONLY 0x000200 /* lookup with read-only semantics */ +#define HASBUF 0x000400 /* has allocated pathname buffer */ +#define SAVENAME 0x000800 /* save pathanme buffer */ +#define SAVESTART 0x001000 /* save starting directory */ +#define ISDOTDOT 0x002000 /* current component name is .. */ +#define MAKEENTRY 0x004000 /* entry is to be added to name cache */ +#define ISLASTCN 0x008000 /* this is last component of pathname */ +#define ISSYMLINK 0x010000 /* symlink needs interpretation */ +#define ISWHITEOUT 0x020000 /* found whiteout */ +#define DOWHITEOUT 0x040000 /* do whiteouts */ +#define REQUIREDIR 0x080000 /* must be a directory */ +#define STRIPSLASHES 0x100000 /* strip trailing slashes */ #define PARAMASK 0xfff00 /* mask of parameter descriptors */ /* * Initialization of an nameidata structure. |