summaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
authorpeter <peter@FreeBSD.org>1998-04-06 17:38:43 +0000
committerpeter <peter@FreeBSD.org>1998-04-06 17:38:43 +0000
commitd5ab1c3759352a4180dfc28b7952eeb389bb3261 (patch)
treefa41709ad0ad1c58a76febf3e0062c8b5641df9e /sys
parent7c3222498acb0b317b49cca6311ffb697172d7ca (diff)
downloadFreeBSD-src-d5ab1c3759352a4180dfc28b7952eeb389bb3261.zip
FreeBSD-src-d5ab1c3759352a4180dfc28b7952eeb389bb3261.tar.gz
Implement a new open(2) flag: O_NOFOLLOW. This will instruct open
to not follow symlinks, but to open a handle on the link itself(!). As strange as this might sound, it has several useful applications safe race-free ways of opening files in hostile areas (eg: /tmp, a mode 1777 /var/mail, etc). It also would allow things like fchown() to work on the link rather than having to implement a new syscall specifically for that task. Reviewed by: phk
Diffstat (limited to 'sys')
-rw-r--r--sys/kern/vfs_vnops.c5
-rw-r--r--sys/sys/fcntl.h3
2 files changed, 5 insertions, 3 deletions
diff --git a/sys/kern/vfs_vnops.c b/sys/kern/vfs_vnops.c
index d1e1b65..40a2112 100644
--- a/sys/kern/vfs_vnops.c
+++ b/sys/kern/vfs_vnops.c
@@ -36,7 +36,7 @@
* SUCH DAMAGE.
*
* @(#)vfs_vnops.c 8.2 (Berkeley) 1/21/94
- * $Id: vfs_vnops.c,v 1.49 1998/02/06 12:13:33 eivind Exp $
+ * $Id: vfs_vnops.c,v 1.50 1998/02/25 05:58:47 bde Exp $
*/
#include <sys/param.h>
@@ -118,7 +118,8 @@ vn_open(ndp, fmode, cmode)
}
} else {
ndp->ni_cnd.cn_nameiop = LOOKUP;
- ndp->ni_cnd.cn_flags = FOLLOW | LOCKLEAF;
+ ndp->ni_cnd.cn_flags =
+ ((fmode & O_NOFOLLOW) ? NOFOLLOW : FOLLOW) | LOCKLEAF;
error = namei(ndp);
if (error)
return (error);
diff --git a/sys/sys/fcntl.h b/sys/sys/fcntl.h
index fa44125..7133e17 100644
--- a/sys/sys/fcntl.h
+++ b/sys/sys/fcntl.h
@@ -36,7 +36,7 @@
* SUCH DAMAGE.
*
* @(#)fcntl.h 8.3 (Berkeley) 1/21/94
- * $Id$
+ * $Id: fcntl.h,v 1.6 1997/02/22 09:45:13 peter Exp $
*/
#ifndef _SYS_FCNTL_H_
@@ -84,6 +84,7 @@
#define O_EXLOCK 0x0020 /* open with exclusive file lock */
#define O_ASYNC 0x0040 /* signal pgrp when data ready */
#define O_FSYNC 0x0080 /* synchronous writes */
+#define O_NOFOLLOW 0x0100 /* don't follow symlinks */
#endif
#define O_CREAT 0x0200 /* create if nonexistent */
#define O_TRUNC 0x0400 /* truncate to zero length */
OpenPOWER on IntegriCloud