Subject: open O_NOFOLLOW
To: None <tech-kern@netbsd.org>
From: Charles Blundell <cb@kittenz.org>
List: tech-kern
Date: 08/03/2003 10:59:47
--jRHKVT23PllUwdXP
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Hi.
Currently, the O_NOFOLLOW flag to open(2) is only effective when
O_CREAT is also present.  This does not appear to match the behaviour
of other implementations.  The attached code, I think, corrects
this.

Can anyone see anything wrong/missing from this?

Thanks!


--jRHKVT23PllUwdXP
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=nofollow1

Index: vfs_vnops.c
===================================================================
RCS file: /cvsroot/src/sys/kern/vfs_vnops.c,v
retrieving revision 1.72
diff -b -u -r1.72 vfs_vnops.c
--- vfs_vnops.c	2003/06/29 22:31:35	1.72
+++ vfs_vnops.c	2003/08/02 09:00:34
@@ -144,21 +144,23 @@
 				error = EEXIST;
 				goto bad;
 			}
-			if (ndp->ni_vp->v_type == VLNK) {
-				error = EFTYPE;
-				goto bad;
-			}
 			fmode &= ~O_CREAT;
 		}
 	} else {
 		ndp->ni_cnd.cn_nameiop = LOOKUP;
-		ndp->ni_cnd.cn_flags = FOLLOW | LOCKLEAF;
+		ndp->ni_cnd.cn_flags = LOCKLEAF;
+		if ((fmode & O_NOFOLLOW) == 0)
+			ndp->ni_cnd.cn_flags |= FOLLOW;
 		if ((error = namei(ndp)) != 0)
 			return (error);
 		vp = ndp->ni_vp;
 	}
 	if (vp->v_type == VSOCK) {
 		error = EOPNOTSUPP;
+		goto bad;
+	}
+	if (ndp->ni_vp->v_type == VLNK) {
+		error = EFTYPE;
 		goto bad;
 	}
 

--jRHKVT23PllUwdXP--