summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorThordur I. Bjornsson <thib@cvs.openbsd.org>2009-01-24 23:25:18 +0000
committerThordur I. Bjornsson <thib@cvs.openbsd.org>2009-01-24 23:25:18 +0000
commitd62304bc585972214cce753b7c807f6da7195dc7 (patch)
tree84a12901db3234afd3f101694cf21c0bcc2e468e /sys
parent05ad4782bfe89cf76f11bf22bc566dc37469d143 (diff)
propagate the O_EXCL flag down to the file systems, by setting
VA_EXCLUSIVE. Handle this in NFS, also in NFS use arc4random() for the create verifier instead of an uninitialized long and the address of the first interface (which is likely to be lo0). Lifted from NetBSD with small tweaks; "looks good", miod@ OK blambert@
Diffstat (limited to 'sys')
-rw-r--r--sys/kern/vfs_vnops.c4
-rw-r--r--sys/nfs/nfs.h7
-rw-r--r--sys/nfs/nfs_vnops.c19
3 files changed, 11 insertions, 19 deletions
diff --git a/sys/kern/vfs_vnops.c b/sys/kern/vfs_vnops.c
index c8f33a561e1..c8fe70db9b1 100644
--- a/sys/kern/vfs_vnops.c
+++ b/sys/kern/vfs_vnops.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vfs_vnops.c,v 1.60 2008/09/19 12:24:55 art Exp $ */
+/* $OpenBSD: vfs_vnops.c,v 1.61 2009/01/24 23:25:17 thib Exp $ */
/* $NetBSD: vfs_vnops.c,v 1.20 1996/02/04 02:18:41 christos Exp $ */
/*
@@ -97,6 +97,8 @@ vn_open(struct nameidata *ndp, int fmode, int cmode)
VATTR_NULL(&va);
va.va_type = VREG;
va.va_mode = cmode;
+ if (fmode & O_EXCL)
+ va.va_vaflags |= VA_EXCLUSIVE;
error = VOP_CREATE(ndp->ni_dvp, &ndp->ni_vp,
&ndp->ni_cnd, &va);
if (error)
diff --git a/sys/nfs/nfs.h b/sys/nfs/nfs.h
index 91ecacd8547..d1f12d525de 100644
--- a/sys/nfs/nfs.h
+++ b/sys/nfs/nfs.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: nfs.h,v 1.36 2009/01/18 21:15:53 blambert Exp $ */
+/* $OpenBSD: nfs.h,v 1.37 2009/01/24 23:25:17 thib Exp $ */
/* $NetBSD: nfs.h,v 1.10.4.1 1996/05/27 11:23:56 fvdl Exp $ */
/*
@@ -89,8 +89,6 @@
/*
* sys/malloc.h needs M_NFSDIROFF, M_NFSRVDESC and M_NFSBIGFH added.
- * The VA_EXCLUSIVE flag should be added for va_vaflags and set for an
- * exclusive create.
*/
#ifndef M_NFSRVDESC
#define M_NFSRVDESC M_TEMP
@@ -101,9 +99,6 @@
#ifndef M_NFSBIGFH
#define M_NFSBIGFH M_TEMP
#endif
-#ifndef VA_EXCLUSIVE
-#define VA_EXCLUSIVE 0
-#endif
/*
* The B_INVAFTERWRITE flag should be set to whatever is required by the
diff --git a/sys/nfs/nfs_vnops.c b/sys/nfs/nfs_vnops.c
index d3edf04eb96..ac5a674e310 100644
--- a/sys/nfs/nfs_vnops.c
+++ b/sys/nfs/nfs_vnops.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: nfs_vnops.c,v 1.108 2009/01/19 23:40:36 thib Exp $ */
+/* $OpenBSD: nfs_vnops.c,v 1.109 2009/01/24 23:25:17 thib Exp $ */
/* $NetBSD: nfs_vnops.c,v 1.62.4.1 1996/07/08 20:26:52 jtc Exp $ */
/*
@@ -79,6 +79,8 @@
#include <netinet/in.h>
#include <netinet/in_var.h>
+#include <dev/rndvar.h>
+
void nfs_cache_enter(struct vnode *, struct vnode *, struct componentname *);
/*
@@ -1251,10 +1253,6 @@ nfs_mknod(v)
return (error);
}
-static u_long create_verf;
-/*
- * nfs file create call
- */
int
nfs_create(v)
void *v;
@@ -1279,10 +1277,9 @@ nfs_create(v)
if (vap->va_type == VSOCK)
return (nfs_mknodrpc(dvp, ap->a_vpp, cnp, vap));
-#ifdef VA_EXCLUSIVE
if (vap->va_vaflags & VA_EXCLUSIVE)
fmode |= O_EXCL;
-#endif
+
again:
nfsstats.rpccnt[NFSPROC_CREATE]++;
mb = mreq = nfsm_reqhead(NFSX_FH(v3) + 2 * NFSX_UNSIGNED +
@@ -1292,13 +1289,11 @@ again:
if (v3) {
tl = nfsm_build(&mb, NFSX_UNSIGNED);
if (fmode & O_EXCL) {
+ printf("%s: O_EXCL!\n", __func__);
*tl = txdr_unsigned(NFSV3CREATE_EXCLUSIVE);
tl = nfsm_build(&mb, NFSX_V3CREATEVERF);
- if (TAILQ_FIRST(&in_ifaddr))
- *tl++ = TAILQ_FIRST(&in_ifaddr)->ia_addr.sin_addr.s_addr;
- else
- *tl++ = create_verf;
- *tl = ++create_verf;
+ *tl++ = arc4random();
+ *tl = arc4random();
} else {
*tl = txdr_unsigned(NFSV3CREATE_UNCHECKED);
nfsm_v3attrbuild(&mb, vap, 0);