2 * Copyright (c) 1989, 1993
3 * The Regents of the University of California. All rights reserved.
5 * This code is derived from software contributed to Berkeley by
6 * Rick Macklem at The University of Guelph.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 4. Neither the name of the University nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 #include <sys/cdefs.h>
35 __FBSDID("$FreeBSD$");
38 * nfs version 2, 3 and 4 server calls to vnode ops
39 * - these routines generally have 3 phases
40 * 1 - break down and validate rpc request in mbuf list
41 * 2 - do the vnode ops for the request, usually by calling a nfsvno_XXX()
42 * function in nfsd_port.c
43 * 3 - build the rpc reply in an mbuf list
44 * For nfsv4, these functions are called for each Op within the Compound RPC.
48 #include <fs/nfs/nfsport.h>
51 extern u_int32_t newnfs_false, newnfs_true;
52 extern enum vtype nv34tov_type[8];
53 extern struct timeval nfsboottime;
54 extern int nfs_rootfhset, nfsv4root_set;
55 #endif /* !APPLEKEXT */
58 * This list defines the GSS mechanisms supported.
59 * (Don't ask me how you get these strings from the RFC stuff like
60 * iso(1), org(3)... but someone did it, so I don't need to know.)
62 static struct nfsgss_mechlist nfsgss_mechlist[] = {
63 { 9, "\052\206\110\206\367\022\001\002\002", 11 },
68 static void nfsrvd_symlinksub(struct nfsrv_descript *nd, struct nameidata *ndp,
69 struct nfsvattr *nvap, fhandle_t *fhp, vnode_t *vpp,
70 vnode_t dirp, struct nfsvattr *dirforp, struct nfsvattr *diraftp,
71 int *diraft_retp, nfsattrbit_t *attrbitp,
72 NFSACL_T *aclp, NFSPROC_T *p, struct nfsexstuff *exp, char *pathcp,
74 static void nfsrvd_mkdirsub(struct nfsrv_descript *nd, struct nameidata *ndp,
75 struct nfsvattr *nvap, fhandle_t *fhp, vnode_t *vpp,
76 vnode_t dirp, struct nfsvattr *dirforp, struct nfsvattr *diraftp,
77 int *diraft_retp, nfsattrbit_t *attrbitp, NFSACL_T *aclp,
78 NFSPROC_T *p, struct nfsexstuff *exp);
81 * nfs access service (not a part of NFS V2)
84 nfsrvd_access(struct nfsrv_descript *nd, __unused int isdgram,
85 vnode_t vp, NFSPROC_T *p, struct nfsexstuff *exp)
88 int getret, error = 0;
90 u_int32_t testmode, nfsmode, supported = 0;
93 nfsrv_postopattr(nd, 1, &nva);
96 NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
97 nfsmode = fxdr_unsigned(u_int32_t, *tl);
98 if ((nd->nd_flag & ND_NFSV4) &&
99 (nfsmode & ~(NFSACCESS_READ | NFSACCESS_LOOKUP |
100 NFSACCESS_MODIFY | NFSACCESS_EXTEND | NFSACCESS_DELETE |
101 NFSACCESS_EXECUTE))) {
102 nd->nd_repstat = NFSERR_INVAL;
106 if (nfsmode & NFSACCESS_READ) {
107 supported |= NFSACCESS_READ;
108 if (nfsvno_accchk(vp, NFSV4ACE_READDATA, nd->nd_cred, exp, p,
109 NFSACCCHK_NOOVERRIDE, NFSACCCHK_VPISLOCKED))
110 nfsmode &= ~NFSACCESS_READ;
112 if (nfsmode & NFSACCESS_MODIFY) {
113 supported |= NFSACCESS_MODIFY;
114 if (nfsvno_accchk(vp, NFSV4ACE_WRITEDATA, nd->nd_cred, exp, p,
115 NFSACCCHK_NOOVERRIDE, NFSACCCHK_VPISLOCKED))
116 nfsmode &= ~NFSACCESS_MODIFY;
118 if (nfsmode & NFSACCESS_EXTEND) {
119 supported |= NFSACCESS_EXTEND;
120 if (nfsvno_accchk(vp, NFSV4ACE_APPENDDATA, nd->nd_cred, exp, p,
121 NFSACCCHK_NOOVERRIDE, NFSACCCHK_VPISLOCKED))
122 nfsmode &= ~NFSACCESS_EXTEND;
124 if (nfsmode & NFSACCESS_DELETE) {
125 supported |= NFSACCESS_DELETE;
126 if (nfsvno_accchk(vp, NFSV4ACE_DELETE, nd->nd_cred, exp, p,
127 NFSACCCHK_NOOVERRIDE, NFSACCCHK_VPISLOCKED))
128 nfsmode &= ~NFSACCESS_DELETE;
130 if (vnode_vtype(vp) == VDIR)
131 testmode = NFSACCESS_LOOKUP;
133 testmode = NFSACCESS_EXECUTE;
134 if (nfsmode & testmode) {
135 supported |= (nfsmode & testmode);
136 if (nfsvno_accchk(vp, NFSV4ACE_EXECUTE, nd->nd_cred, exp, p,
137 NFSACCCHK_NOOVERRIDE, NFSACCCHK_VPISLOCKED))
138 nfsmode &= ~testmode;
140 nfsmode &= supported;
141 if (nd->nd_flag & ND_NFSV3) {
142 getret = nfsvno_getattr(vp, &nva, nd->nd_cred, p);
143 nfsrv_postopattr(nd, getret, &nva);
146 if (nd->nd_flag & ND_NFSV4) {
147 NFSM_BUILD(tl, u_int32_t *, 2 * NFSX_UNSIGNED);
148 *tl++ = txdr_unsigned(supported);
150 NFSM_BUILD(tl, u_int32_t *, NFSX_UNSIGNED);
151 *tl = txdr_unsigned(nfsmode);
159 * nfs getattr service
162 nfsrvd_getattr(struct nfsrv_descript *nd, int isdgram,
163 vnode_t vp, NFSPROC_T *p, __unused struct nfsexstuff *exp)
168 struct nfsreferral *refp;
169 nfsattrbit_t attrbits;
173 if (nd->nd_flag & ND_NFSV4) {
174 error = nfsrv_getattrbits(nd, &attrbits, NULL, NULL);
181 * Check for a referral.
183 refp = nfsv4root_getreferral(vp, NULL, 0);
185 (void) nfsrv_putreferralattr(nd, &attrbits, refp, 1,
191 nd->nd_repstat = nfsvno_accchk(vp,
192 NFSV4ACE_READATTRIBUTES,
194 NFSACCCHK_NOOVERRIDE, NFSACCCHK_VPISLOCKED);
197 nd->nd_repstat = nfsvno_getattr(vp, &nva, nd->nd_cred, p);
198 if (!nd->nd_repstat) {
199 if (nd->nd_flag & ND_NFSV4) {
200 if (NFSISSET_ATTRBIT(&attrbits, NFSATTRBIT_FILEHANDLE))
201 nd->nd_repstat = nfsvno_getfh(vp, &fh, p);
203 nd->nd_repstat = nfsrv_checkgetattr(nd, vp,
204 &nva, &attrbits, nd->nd_cred, p);
205 NFSVOPUNLOCK(vp, 0, p);
207 (void) nfsvno_fillattr(nd, vp, &nva, &fh,
208 0, &attrbits, nd->nd_cred, p, isdgram, 1);
211 nfsrv_fillattr(nd, &nva);
221 * nfs setattr service
224 nfsrvd_setattr(struct nfsrv_descript *nd, __unused int isdgram,
225 vnode_t vp, NFSPROC_T *p, struct nfsexstuff *exp)
227 struct nfsvattr nva, nva2;
229 int preat_ret = 1, postat_ret = 1, gcheck = 0, error = 0;
230 struct timespec guard = { 0, 0 };
231 nfsattrbit_t attrbits, retbits;
232 nfsv4stateid_t stateid;
233 NFSACL_T *aclp = NULL;
235 if (nd->nd_repstat) {
236 nfsrv_wcc(nd, preat_ret, &nva2, postat_ret, &nva);
239 #ifdef NFS4_ACL_EXTATTR_NAME
240 aclp = acl_alloc(M_WAITOK);
243 NFSVNO_ATTRINIT(&nva);
244 NFSZERO_ATTRBIT(&retbits);
245 if (nd->nd_flag & ND_NFSV4) {
246 NFSM_DISSECT(tl, u_int32_t *, NFSX_STATEID);
247 stateid.seqid = fxdr_unsigned(u_int32_t, *tl++);
248 NFSBCOPY((caddr_t)tl,(caddr_t)stateid.other,NFSX_STATEIDOTHER);
250 error = nfsrv_sattr(nd, &nva, &attrbits, aclp, p);
253 preat_ret = nfsvno_getattr(vp, &nva2, nd->nd_cred, p);
255 nd->nd_repstat = preat_ret;
256 if (nd->nd_flag & ND_NFSV3) {
257 NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
258 gcheck = fxdr_unsigned(int, *tl);
260 NFSM_DISSECT(tl, u_int32_t *, 2 * NFSX_UNSIGNED);
261 fxdr_nfsv3time(tl, &guard);
263 if (!nd->nd_repstat && gcheck &&
264 (nva2.na_ctime.tv_sec != guard.tv_sec ||
265 nva2.na_ctime.tv_nsec != guard.tv_nsec))
266 nd->nd_repstat = NFSERR_NOT_SYNC;
267 if (nd->nd_repstat) {
269 #ifdef NFS4_ACL_EXTATTR_NAME
272 nfsrv_wcc(nd, preat_ret, &nva2, postat_ret, &nva);
275 } else if (!nd->nd_repstat && (nd->nd_flag & ND_NFSV4))
276 nd->nd_repstat = nfsrv_checkuidgid(nd, &nva);
279 * Now that we have all the fields, lets do it.
280 * If the size is being changed write access is required, otherwise
281 * just check for a read only file system.
283 if (!nd->nd_repstat) {
284 if (NFSVNO_NOTSETSIZE(&nva)) {
285 if (NFSVNO_EXRDONLY(exp) ||
286 (vfs_flags(vnode_mount(vp)) & MNT_RDONLY))
287 nd->nd_repstat = EROFS;
289 if (vnode_vtype(vp) != VREG)
290 nd->nd_repstat = EINVAL;
291 else if (nva2.na_uid != nd->nd_cred->cr_uid ||
292 NFSVNO_EXSTRICTACCESS(exp))
293 nd->nd_repstat = nfsvno_accchk(vp,
294 NFSV4ACE_WRITEDATA, nd->nd_cred, exp, p,
295 NFSACCCHK_NOOVERRIDE,NFSACCCHK_VPISLOCKED);
298 if (!nd->nd_repstat && (nd->nd_flag & ND_NFSV4))
299 nd->nd_repstat = nfsrv_checksetattr(vp, nd, &stateid,
300 &nva, &attrbits, exp, p);
302 if (!nd->nd_repstat && (nd->nd_flag & ND_NFSV4)) {
304 * For V4, try setting the attrbutes in sets, so that the
305 * reply bitmap will be correct for an error case.
307 if (NFSISSET_ATTRBIT(&attrbits, NFSATTRBIT_OWNER) ||
308 NFSISSET_ATTRBIT(&attrbits, NFSATTRBIT_OWNERGROUP)) {
309 NFSVNO_ATTRINIT(&nva2);
310 NFSVNO_SETATTRVAL(&nva2, uid, nva.na_uid);
311 NFSVNO_SETATTRVAL(&nva2, gid, nva.na_gid);
312 nd->nd_repstat = nfsvno_setattr(vp, &nva2, nd->nd_cred, p,
314 if (!nd->nd_repstat) {
315 if (NFSISSET_ATTRBIT(&attrbits, NFSATTRBIT_OWNER))
316 NFSSETBIT_ATTRBIT(&retbits, NFSATTRBIT_OWNER);
317 if (NFSISSET_ATTRBIT(&attrbits, NFSATTRBIT_OWNERGROUP))
318 NFSSETBIT_ATTRBIT(&retbits, NFSATTRBIT_OWNERGROUP);
321 if (!nd->nd_repstat &&
322 NFSISSET_ATTRBIT(&attrbits, NFSATTRBIT_SIZE)) {
323 NFSVNO_ATTRINIT(&nva2);
324 NFSVNO_SETATTRVAL(&nva2, size, nva.na_size);
325 nd->nd_repstat = nfsvno_setattr(vp, &nva2, nd->nd_cred, p,
328 NFSSETBIT_ATTRBIT(&retbits, NFSATTRBIT_SIZE);
330 if (!nd->nd_repstat &&
331 (NFSISSET_ATTRBIT(&attrbits, NFSATTRBIT_TIMEACCESSSET) ||
332 NFSISSET_ATTRBIT(&attrbits, NFSATTRBIT_TIMEMODIFYSET))) {
333 NFSVNO_ATTRINIT(&nva2);
334 NFSVNO_SETATTRVAL(&nva2, atime, nva.na_atime);
335 NFSVNO_SETATTRVAL(&nva2, mtime, nva.na_mtime);
336 if (nva.na_vaflags & VA_UTIMES_NULL) {
337 nva2.na_vaflags |= VA_UTIMES_NULL;
338 NFSVNO_SETACTIVE(&nva2, vaflags);
340 nd->nd_repstat = nfsvno_setattr(vp, &nva2, nd->nd_cred, p,
342 if (!nd->nd_repstat) {
343 if (NFSISSET_ATTRBIT(&attrbits, NFSATTRBIT_TIMEACCESSSET))
344 NFSSETBIT_ATTRBIT(&retbits, NFSATTRBIT_TIMEACCESSSET);
345 if (NFSISSET_ATTRBIT(&attrbits, NFSATTRBIT_TIMEMODIFYSET))
346 NFSSETBIT_ATTRBIT(&retbits, NFSATTRBIT_TIMEMODIFYSET);
349 if (!nd->nd_repstat &&
350 NFSISSET_ATTRBIT(&attrbits, NFSATTRBIT_MODE)) {
351 NFSVNO_ATTRINIT(&nva2);
352 NFSVNO_SETATTRVAL(&nva2, mode, nva.na_mode);
353 nd->nd_repstat = nfsvno_setattr(vp, &nva2, nd->nd_cred, p,
356 NFSSETBIT_ATTRBIT(&retbits, NFSATTRBIT_MODE);
359 #ifdef NFS4_ACL_EXTATTR_NAME
360 if (!nd->nd_repstat && aclp->acl_cnt > 0 &&
361 NFSISSET_ATTRBIT(&attrbits, NFSATTRBIT_ACL)) {
362 nd->nd_repstat = nfsrv_setacl(vp, aclp, nd->nd_cred, p);
364 NFSSETBIT_ATTRBIT(&retbits, NFSATTRBIT_ACL);
367 } else if (!nd->nd_repstat) {
368 nd->nd_repstat = nfsvno_setattr(vp, &nva, nd->nd_cred, p,
371 if (nd->nd_flag & (ND_NFSV2 | ND_NFSV3)) {
372 postat_ret = nfsvno_getattr(vp, &nva, nd->nd_cred, p);
374 nd->nd_repstat = postat_ret;
377 #ifdef NFS4_ACL_EXTATTR_NAME
380 if (nd->nd_flag & ND_NFSV3)
381 nfsrv_wcc(nd, preat_ret, &nva2, postat_ret, &nva);
382 else if (nd->nd_flag & ND_NFSV4)
383 (void) nfsrv_putattrbit(nd, &retbits);
384 else if (!nd->nd_repstat)
385 nfsrv_fillattr(nd, &nva);
389 #ifdef NFS4_ACL_EXTATTR_NAME
392 if (nd->nd_flag & ND_NFSV4) {
394 * For all nd_repstat, the V4 reply includes a bitmap,
395 * even NFSERR_BADXDR, which is what this will end up
398 (void) nfsrv_putattrbit(nd, &retbits);
405 * (Also performs lookup parent for v4)
408 nfsrvd_lookup(struct nfsrv_descript *nd, __unused int isdgram,
409 vnode_t dp, vnode_t *vpp, fhandle_t *fhp, NFSPROC_T *p,
410 __unused struct nfsexstuff *exp)
412 struct nameidata named;
413 vnode_t vp, dirp = NULL;
414 int error, dattr_ret = 1;
415 struct nfsvattr nva, dattr;
419 if (nd->nd_repstat) {
420 nfsrv_postopattr(nd, dattr_ret, &dattr);
425 * For some reason, if dp is a symlink, the error
426 * returned is supposed to be NFSERR_SYMLINK and not NFSERR_NOTDIR.
428 if (dp->v_type == VLNK && (nd->nd_flag & ND_NFSV4)) {
429 nd->nd_repstat = NFSERR_SYMLINK;
434 NFSNAMEICNDSET(&named.ni_cnd, nd->nd_cred, LOOKUP,
435 LOCKLEAF | SAVESTART);
436 nfsvno_setpathbuf(&named, &bufp, &hashp);
437 error = nfsrv_parsename(nd, bufp, hashp, &named.ni_pathlen);
440 nfsvno_relpathbuf(&named);
443 if (!nd->nd_repstat) {
444 nd->nd_repstat = nfsvno_namei(nd, &named, dp, 0, exp, p, &dirp);
447 nfsvno_relpathbuf(&named);
449 if (nd->nd_repstat) {
451 if (nd->nd_flag & ND_NFSV3)
452 dattr_ret = nfsvno_getattr(dirp, &dattr,
456 if (nd->nd_flag & ND_NFSV3)
457 nfsrv_postopattr(nd, dattr_ret, &dattr);
460 if (named.ni_startdir)
461 vrele(named.ni_startdir);
462 nfsvno_relpathbuf(&named);
464 nd->nd_repstat = nfsvno_getfh(vp, fhp, p);
465 if (!(nd->nd_flag & ND_NFSV4) && !nd->nd_repstat)
466 nd->nd_repstat = nfsvno_getattr(vp, &nva, nd->nd_cred, p);
468 NFSVOPUNLOCK(vp, 0, p);
474 if (nd->nd_flag & ND_NFSV3)
475 dattr_ret = nfsvno_getattr(dirp, &dattr, nd->nd_cred,
479 if (nd->nd_repstat) {
480 if (nd->nd_flag & ND_NFSV3)
481 nfsrv_postopattr(nd, dattr_ret, &dattr);
484 if (nd->nd_flag & ND_NFSV2) {
485 (void) nfsm_fhtom(nd, (u_int8_t *)fhp, 0, 0);
486 nfsrv_fillattr(nd, &nva);
487 } else if (nd->nd_flag & ND_NFSV3) {
488 (void) nfsm_fhtom(nd, (u_int8_t *)fhp, 0, 0);
489 nfsrv_postopattr(nd, 0, &nva);
490 nfsrv_postopattr(nd, dattr_ret, &dattr);
496 * nfs readlink service
499 nfsrvd_readlink(struct nfsrv_descript *nd, __unused int isdgram,
500 vnode_t vp, NFSPROC_T *p, __unused struct nfsexstuff *exp)
503 mbuf_t mp = NULL, mpend = NULL;
507 if (nd->nd_repstat) {
508 nfsrv_postopattr(nd, getret, &nva);
511 if (vnode_vtype(vp) != VLNK) {
512 if (nd->nd_flag & ND_NFSV2)
513 nd->nd_repstat = ENXIO;
515 nd->nd_repstat = EINVAL;
518 nd->nd_repstat = nfsvno_readlink(vp, nd->nd_cred, p,
520 if (nd->nd_flag & ND_NFSV3)
521 getret = nfsvno_getattr(vp, &nva, nd->nd_cred, p);
523 if (nd->nd_flag & ND_NFSV3)
524 nfsrv_postopattr(nd, getret, &nva);
527 NFSM_BUILD(tl, u_int32_t *, NFSX_UNSIGNED);
528 *tl = txdr_unsigned(len);
529 mbuf_setnext(nd->nd_mb, mp);
531 nd->nd_bpos = NFSMTOD(mpend, caddr_t) + mbuf_len(mpend);
539 nfsrvd_read(struct nfsrv_descript *nd, __unused int isdgram,
540 vnode_t vp, NFSPROC_T *p, struct nfsexstuff *exp)
543 int error = 0, cnt, len, getret = 1, reqlen, eof = 0;
547 struct nfsstate st, *stp = &st;
548 struct nfslock lo, *lop = &lo;
549 nfsv4stateid_t stateid;
552 if (nd->nd_repstat) {
553 nfsrv_postopattr(nd, getret, &nva);
556 if (nd->nd_flag & ND_NFSV2) {
557 NFSM_DISSECT(tl, u_int32_t *, 2 * NFSX_UNSIGNED);
558 off = (off_t)fxdr_unsigned(u_int32_t, *tl++);
559 reqlen = fxdr_unsigned(int, *tl);
560 } else if (nd->nd_flag & ND_NFSV3) {
561 NFSM_DISSECT(tl, u_int32_t *, 3 * NFSX_UNSIGNED);
562 off = fxdr_hyper(tl);
564 reqlen = fxdr_unsigned(int, *tl);
566 NFSM_DISSECT(tl, u_int32_t *, NFSX_STATEID + 3*NFSX_UNSIGNED);
567 reqlen = fxdr_unsigned(int, *(tl + 6));
569 if (reqlen > NFS_SRVMAXDATA(nd)) {
570 reqlen = NFS_SRVMAXDATA(nd);
571 } else if (reqlen < 0) {
575 if (nd->nd_flag & ND_NFSV4) {
576 stp->ls_flags = (NFSLCK_CHECK | NFSLCK_READACCESS);
577 lop->lo_flags = NFSLCK_READ;
578 stp->ls_ownerlen = 0;
580 stp->ls_uid = nd->nd_cred->cr_uid;
581 stp->ls_stateid.seqid = fxdr_unsigned(u_int32_t, *tl++);
582 clientid.lval[0] = stp->ls_stateid.other[0] = *tl++;
583 clientid.lval[1] = stp->ls_stateid.other[1] = *tl++;
584 if (nd->nd_flag & ND_IMPLIEDCLID) {
585 if (nd->nd_clientid.qval != clientid.qval)
586 printf("EEK! multiple clids\n");
588 nd->nd_flag |= ND_IMPLIEDCLID;
589 nd->nd_clientid.qval = clientid.qval;
591 stp->ls_stateid.other[2] = *tl++;
592 off = fxdr_hyper(tl);
595 lop->lo_end = off + reqlen;
597 * Paranoia, just in case it wraps around.
599 if (lop->lo_end < off)
600 lop->lo_end = NFS64BITSSET;
602 if (vnode_vtype(vp) != VREG) {
603 if (nd->nd_flag & ND_NFSV3)
604 nd->nd_repstat = EINVAL;
606 nd->nd_repstat = (vnode_vtype(vp) == VDIR) ? EISDIR :
609 getret = nfsvno_getattr(vp, &nva, nd->nd_cred, p);
611 nd->nd_repstat = getret;
612 if (!nd->nd_repstat &&
613 (nva.na_uid != nd->nd_cred->cr_uid ||
614 NFSVNO_EXSTRICTACCESS(exp))) {
615 nd->nd_repstat = nfsvno_accchk(vp, NFSV4ACE_READDATA,
617 NFSACCCHK_ALLOWOWNER, NFSACCCHK_VPISLOCKED);
619 nd->nd_repstat = nfsvno_accchk(vp, NFSV4ACE_EXECUTE,
621 NFSACCCHK_ALLOWOWNER, NFSACCCHK_VPISLOCKED);
623 if ((nd->nd_flag & ND_NFSV4) && !nd->nd_repstat)
624 nd->nd_repstat = nfsrv_lockctrl(vp, &stp, &lop, NULL, clientid,
625 &stateid, exp, nd, p);
626 if (nd->nd_repstat) {
628 if (nd->nd_flag & ND_NFSV3)
629 nfsrv_postopattr(nd, getret, &nva);
632 if (off >= nva.na_size) {
635 } else if (reqlen == 0)
637 else if ((off + reqlen) > nva.na_size)
638 cnt = nva.na_size - off;
641 len = NFSM_RNDUP(cnt);
644 nd->nd_repstat = nfsvno_read(vp, off, cnt, nd->nd_cred, p,
646 if (!(nd->nd_flag & ND_NFSV4)) {
647 getret = nfsvno_getattr(vp, &nva, nd->nd_cred, p);
649 nd->nd_repstat = getret;
651 if (nd->nd_repstat) {
655 if (nd->nd_flag & ND_NFSV3)
656 nfsrv_postopattr(nd, getret, &nva);
661 if (nd->nd_flag & ND_NFSV2) {
662 nfsrv_fillattr(nd, &nva);
663 NFSM_BUILD(tl, u_int32_t *, NFSX_UNSIGNED);
665 if (nd->nd_flag & ND_NFSV3) {
666 nfsrv_postopattr(nd, getret, &nva);
667 NFSM_BUILD(tl, u_int32_t *, 3 * NFSX_UNSIGNED);
668 *tl++ = txdr_unsigned(cnt);
670 NFSM_BUILD(tl, u_int32_t *, 2 * NFSX_UNSIGNED);
671 if (len < reqlen || eof)
674 *tl++ = newnfs_false;
676 *tl = txdr_unsigned(cnt);
678 mbuf_setnext(nd->nd_mb, m3);
680 nd->nd_bpos = NFSMTOD(m2, caddr_t) + mbuf_len(m2);
692 nfsrvd_write(struct nfsrv_descript *nd, __unused int isdgram,
693 vnode_t vp, NFSPROC_T *p, struct nfsexstuff *exp)
698 struct nfsvattr nva, forat;
699 int aftat_ret = 1, retlen, len, error = 0, forat_ret = 1;
700 int stable = NFSWRITE_FILESYNC;
702 struct nfsstate st, *stp = &st;
703 struct nfslock lo, *lop = &lo;
704 nfsv4stateid_t stateid;
707 if (nd->nd_repstat) {
708 nfsrv_wcc(nd, forat_ret, &forat, aftat_ret, &nva);
711 if (nd->nd_flag & ND_NFSV2) {
712 NFSM_DISSECT(tl, u_int32_t *, 4 * NFSX_UNSIGNED);
713 off = (off_t)fxdr_unsigned(u_int32_t, *++tl);
715 retlen = len = fxdr_unsigned(int32_t, *tl);
716 } else if (nd->nd_flag & ND_NFSV3) {
717 NFSM_DISSECT(tl, u_int32_t *, 5 * NFSX_UNSIGNED);
718 off = fxdr_hyper(tl);
720 stable = fxdr_unsigned(int, *tl++);
721 retlen = len = fxdr_unsigned(int32_t, *tl);
723 NFSM_DISSECT(tl, u_int32_t *, NFSX_STATEID + 4 * NFSX_UNSIGNED);
724 stp->ls_flags = (NFSLCK_CHECK | NFSLCK_WRITEACCESS);
725 lop->lo_flags = NFSLCK_WRITE;
726 stp->ls_ownerlen = 0;
728 stp->ls_uid = nd->nd_cred->cr_uid;
729 stp->ls_stateid.seqid = fxdr_unsigned(u_int32_t, *tl++);
730 clientid.lval[0] = stp->ls_stateid.other[0] = *tl++;
731 clientid.lval[1] = stp->ls_stateid.other[1] = *tl++;
732 if (nd->nd_flag & ND_IMPLIEDCLID) {
733 if (nd->nd_clientid.qval != clientid.qval)
734 printf("EEK! multiple clids\n");
736 nd->nd_flag |= ND_IMPLIEDCLID;
737 nd->nd_clientid.qval = clientid.qval;
739 stp->ls_stateid.other[2] = *tl++;
740 off = fxdr_hyper(tl);
743 stable = fxdr_unsigned(int, *tl++);
744 retlen = len = fxdr_unsigned(int32_t, *tl);
745 lop->lo_end = off + len;
747 * Paranoia, just in case it wraps around, which shouldn't
748 * ever happen anyhow.
750 if (lop->lo_end < lop->lo_first)
751 lop->lo_end = NFS64BITSSET;
755 * Loop through the mbuf chain, counting how many mbufs are a
756 * part of this write operation, so the iovec size is known.
760 i = NFSMTOD(mp, caddr_t) + mbuf_len(mp) - nd->nd_dpos;
776 if (retlen > NFS_MAXDATA || retlen < 0)
777 nd->nd_repstat = EIO;
778 if (vnode_vtype(vp) != VREG && !nd->nd_repstat) {
779 if (nd->nd_flag & ND_NFSV3)
780 nd->nd_repstat = EINVAL;
782 nd->nd_repstat = (vnode_vtype(vp) == VDIR) ? EISDIR :
785 forat_ret = nfsvno_getattr(vp, &forat, nd->nd_cred, p);
787 nd->nd_repstat = forat_ret;
788 if (!nd->nd_repstat &&
789 (forat.na_uid != nd->nd_cred->cr_uid ||
790 NFSVNO_EXSTRICTACCESS(exp)))
791 nd->nd_repstat = nfsvno_accchk(vp, NFSV4ACE_WRITEDATA,
793 NFSACCCHK_ALLOWOWNER, NFSACCCHK_VPISLOCKED);
794 if ((nd->nd_flag & ND_NFSV4) && !nd->nd_repstat) {
795 nd->nd_repstat = nfsrv_lockctrl(vp, &stp, &lop, NULL, clientid,
796 &stateid, exp, nd, p);
798 if (nd->nd_repstat) {
800 if (nd->nd_flag & ND_NFSV3)
801 nfsrv_wcc(nd, forat_ret, &forat, aftat_ret, &nva);
806 * For NFS Version 2, it is not obvious what a write of zero length
807 * should do, but I might as well be consistent with Version 3,
808 * which is to return ok so long as there are no permission problems.
811 nd->nd_repstat = nfsvno_write(vp, off, retlen, cnt, stable,
812 nd->nd_md, nd->nd_dpos, nd->nd_cred, p);
813 error = nfsm_advance(nd, NFSM_RNDUP(retlen), -1);
815 panic("nfsrv_write mbuf");
817 if (nd->nd_flag & ND_NFSV4)
820 aftat_ret = nfsvno_getattr(vp, &nva, nd->nd_cred, p);
823 nd->nd_repstat = aftat_ret;
824 if (nd->nd_flag & (ND_NFSV3 | ND_NFSV4)) {
825 if (nd->nd_flag & ND_NFSV3)
826 nfsrv_wcc(nd, forat_ret, &forat, aftat_ret, &nva);
829 NFSM_BUILD(tl, u_int32_t *, 4 * NFSX_UNSIGNED);
830 *tl++ = txdr_unsigned(retlen);
831 if (stable == NFSWRITE_UNSTABLE)
832 *tl++ = txdr_unsigned(stable);
834 *tl++ = txdr_unsigned(NFSWRITE_FILESYNC);
836 * Actually, there is no need to txdr these fields,
837 * but it may make the values more human readable,
838 * for debugging purposes.
840 *tl++ = txdr_unsigned(nfsboottime.tv_sec);
841 *tl = txdr_unsigned(nfsboottime.tv_usec);
842 } else if (!nd->nd_repstat)
843 nfsrv_fillattr(nd, &nva);
851 * nfs create service (creates regular files for V2 and V3. Spec. files for V2.)
852 * now does a truncate to 0 length via. setattr if it already exists
853 * The core creation routine has been extracted out into nfsrv_creatsub(),
854 * so it can also be used by nfsrv_open() for V4.
857 nfsrvd_create(struct nfsrv_descript *nd, __unused int isdgram,
858 vnode_t dp, NFSPROC_T *p, struct nfsexstuff *exp)
860 struct nfsvattr nva, dirfor, diraft;
861 struct nfsv2_sattr *sp;
862 struct nameidata named;
864 int error = 0, tsize, dirfor_ret = 1, diraft_ret = 1;
865 int how = NFSCREATE_UNCHECKED, exclusive_flag = 0;
867 vnode_t vp = NULL, dirp = NULL;
868 u_char cverf[NFSX_VERF], *cp;
874 if (nd->nd_repstat) {
875 nfsrv_wcc(nd, dirfor_ret, &dirfor, diraft_ret, &diraft);
878 NFSNAMEICNDSET(&named.ni_cnd, nd->nd_cred, CREATE,
879 LOCKPARENT | LOCKLEAF | SAVESTART);
880 nfsvno_setpathbuf(&named, &bufp, &hashp);
881 error = nfsrv_parsename(nd, bufp, hashp, &named.ni_pathlen);
884 nfsvno_relpathbuf(&named);
887 if (!nd->nd_repstat) {
888 NFSVNO_ATTRINIT(&nva);
889 if (nd->nd_flag & ND_NFSV2) {
890 NFSM_DISSECT(sp, struct nfsv2_sattr *, NFSX_V2SATTR);
891 vtyp = IFTOVT(fxdr_unsigned(u_int32_t, sp->sa_mode));
894 NFSVNO_SETATTRVAL(&nva, type, vtyp);
895 NFSVNO_SETATTRVAL(&nva, mode,
896 nfstov_mode(sp->sa_mode));
897 switch (nva.na_type) {
899 tsize = fxdr_unsigned(int32_t, sp->sa_size);
901 NFSVNO_SETATTRVAL(&nva, size,
907 rdev = fxdr_unsigned(NFSDEV_T, sp->sa_size);
913 NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
914 how = fxdr_unsigned(int, *tl);
916 case NFSCREATE_GUARDED:
917 case NFSCREATE_UNCHECKED:
918 error = nfsrv_sattr(nd, &nva, NULL, NULL, p);
922 case NFSCREATE_EXCLUSIVE:
923 NFSM_DISSECT(cp, u_char *, NFSX_VERF);
924 NFSBCOPY(cp, cverf, NFSX_VERF);
928 NFSVNO_SETATTRVAL(&nva, type, VREG);
931 if (nd->nd_repstat) {
932 nfsvno_relpathbuf(&named);
933 if (nd->nd_flag & ND_NFSV3) {
934 dirfor_ret = nfsvno_getattr(dp, &dirfor, nd->nd_cred,
936 nfsrv_wcc(nd, dirfor_ret, &dirfor, diraft_ret,
943 nd->nd_repstat = nfsvno_namei(nd, &named, dp, 1, exp, p, &dirp);
945 if (nd->nd_flag & ND_NFSV2) {
949 dirfor_ret = nfsvno_getattr(dirp, &dirfor, nd->nd_cred,
953 if (nd->nd_repstat) {
954 if (nd->nd_flag & ND_NFSV3)
955 nfsrv_wcc(nd, dirfor_ret, &dirfor, diraft_ret,
962 if (!(nd->nd_flag & ND_NFSV2)) {
964 case NFSCREATE_GUARDED:
966 nd->nd_repstat = EEXIST;
968 case NFSCREATE_UNCHECKED:
970 case NFSCREATE_EXCLUSIVE:
971 if (named.ni_vp == NULL)
972 NFSVNO_SETATTRVAL(&nva, mode, 0);
978 * Iff doesn't exist, create it
979 * otherwise just truncate to 0 length
980 * should I set the mode too ?
982 nd->nd_repstat = nfsvno_createsub(nd, &named, &vp, &nva,
983 &exclusive_flag, cverf, rdev, p, exp);
985 if (!nd->nd_repstat) {
986 nd->nd_repstat = nfsvno_getfh(vp, &fh, p);
988 nd->nd_repstat = nfsvno_getattr(vp, &nva, nd->nd_cred,
992 if (nd->nd_flag & ND_NFSV2) {
993 if (!nd->nd_repstat) {
994 (void) nfsm_fhtom(nd, (u_int8_t *)&fh, 0, 0);
995 nfsrv_fillattr(nd, &nva);
998 if (exclusive_flag && !nd->nd_repstat &&
999 NFSBCMP(cverf, (caddr_t)&nva.na_atime, NFSX_VERF))
1000 nd->nd_repstat = EEXIST;
1001 diraft_ret = nfsvno_getattr(dirp, &diraft, nd->nd_cred, p);
1003 if (!nd->nd_repstat) {
1004 (void) nfsm_fhtom(nd, (u_int8_t *)&fh, 0, 1);
1005 nfsrv_postopattr(nd, 0, &nva);
1007 nfsrv_wcc(nd, dirfor_ret, &dirfor, diraft_ret, &diraft);
1012 nfsvno_relpathbuf(&named);
1017 * nfs v3 mknod service (and v4 create)
1020 nfsrvd_mknod(struct nfsrv_descript *nd, __unused int isdgram,
1021 vnode_t dp, vnode_t *vpp, fhandle_t *fhp, NFSPROC_T *p,
1022 struct nfsexstuff *exp)
1024 struct nfsvattr nva, dirfor, diraft;
1026 struct nameidata named;
1027 int error = 0, dirfor_ret = 1, diraft_ret = 1, pathlen;
1028 u_int32_t major, minor;
1029 enum vtype vtyp = VNON;
1030 nfstype nfs4type = NFNON;
1031 vnode_t vp, dirp = NULL;
1032 nfsattrbit_t attrbits;
1033 char *bufp = NULL, *pathcp = NULL;
1034 u_long *hashp, cnflags;
1035 NFSACL_T *aclp = NULL;
1037 NFSVNO_ATTRINIT(&nva);
1038 cnflags = (LOCKPARENT | SAVESTART);
1039 if (nd->nd_repstat) {
1040 nfsrv_wcc(nd, dirfor_ret, &dirfor, diraft_ret, &diraft);
1043 #ifdef NFS4_ACL_EXTATTR_NAME
1044 aclp = acl_alloc(M_WAITOK);
1049 * For V4, the creation stuff is here, Yuck!
1051 if (nd->nd_flag & ND_NFSV4) {
1052 NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
1053 vtyp = nfsv34tov_type(*tl);
1054 nfs4type = fxdr_unsigned(nfstype, *tl);
1057 error = nfsvno_getsymlink(nd, &nva, p, &pathcp,
1061 #ifdef NFS4_ACL_EXTATTR_NAME
1069 NFSM_DISSECT(tl, u_int32_t *, 2 * NFSX_UNSIGNED);
1070 major = fxdr_unsigned(u_int32_t, *tl++);
1071 minor = fxdr_unsigned(u_int32_t, *tl);
1072 nva.na_rdev = NFSMAKEDEV(major, minor);
1078 cnflags = LOCKPARENT;
1081 nd->nd_repstat = NFSERR_BADTYPE;
1083 #ifdef NFS4_ACL_EXTATTR_NAME
1089 NFSNAMEICNDSET(&named.ni_cnd, nd->nd_cred, CREATE, cnflags);
1090 nfsvno_setpathbuf(&named, &bufp, &hashp);
1091 error = nfsrv_parsename(nd, bufp, hashp, &named.ni_pathlen);
1094 #ifdef NFS4_ACL_EXTATTR_NAME
1097 nfsvno_relpathbuf(&named);
1099 FREE(pathcp, M_TEMP);
1102 if (!nd->nd_repstat) {
1103 if (nd->nd_flag & ND_NFSV3) {
1104 NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
1105 vtyp = nfsv34tov_type(*tl);
1107 error = nfsrv_sattr(nd, &nva, &attrbits, aclp, p);
1110 #ifdef NFS4_ACL_EXTATTR_NAME
1113 nfsvno_relpathbuf(&named);
1115 FREE(pathcp, M_TEMP);
1119 if (!nd->nd_repstat && (nd->nd_flag & ND_NFSV3) &&
1120 (vtyp == VCHR || vtyp == VBLK)) {
1121 NFSM_DISSECT(tl, u_int32_t *, 2 * NFSX_UNSIGNED);
1122 major = fxdr_unsigned(u_int32_t, *tl++);
1123 minor = fxdr_unsigned(u_int32_t, *tl);
1124 nva.na_rdev = NFSMAKEDEV(major, minor);
1128 dirfor_ret = nfsvno_getattr(dp, &dirfor, nd->nd_cred, p);
1129 if (!nd->nd_repstat && (nd->nd_flag & ND_NFSV4)) {
1130 if (!dirfor_ret && NFSVNO_ISSETGID(&nva) &&
1131 dirfor.na_gid == nva.na_gid)
1132 NFSVNO_UNSET(&nva, gid);
1133 nd->nd_repstat = nfsrv_checkuidgid(nd, &nva);
1135 if (nd->nd_repstat) {
1137 #ifdef NFS4_ACL_EXTATTR_NAME
1140 nfsvno_relpathbuf(&named);
1142 FREE(pathcp, M_TEMP);
1143 if (nd->nd_flag & ND_NFSV3)
1144 nfsrv_wcc(nd, dirfor_ret, &dirfor, diraft_ret,
1150 * Yuck! For V4, mkdir and link are here and some V4 clients don't fill
1151 * in va_mode, so we'll have to set a default here.
1153 if (NFSVNO_NOTSETMODE(&nva)) {
1161 named.ni_cnd.cn_flags |= WILLBEDIR;
1162 nd->nd_repstat = nfsvno_namei(nd, &named, dp, 0, exp, p, &dirp);
1163 if (nd->nd_repstat) {
1165 if (nd->nd_flag & ND_NFSV3)
1166 dirfor_ret = nfsvno_getattr(dirp, &dirfor,
1170 #ifdef NFS4_ACL_EXTATTR_NAME
1173 if (nd->nd_flag & ND_NFSV3)
1174 nfsrv_wcc(nd, dirfor_ret, &dirfor, diraft_ret,
1179 dirfor_ret = nfsvno_getattr(dirp, &dirfor, nd->nd_cred, p);
1181 if ((nd->nd_flag & ND_NFSV4) && (vtyp == VDIR || vtyp == VLNK)) {
1183 nfsrvd_mkdirsub(nd, &named, &nva, fhp, vpp, dirp,
1184 &dirfor, &diraft, &diraft_ret, &attrbits, aclp, p,
1186 #ifdef NFS4_ACL_EXTATTR_NAME
1190 } else if (vtyp == VLNK) {
1191 nfsrvd_symlinksub(nd, &named, &nva, fhp, vpp, dirp,
1192 &dirfor, &diraft, &diraft_ret, &attrbits,
1193 aclp, p, exp, pathcp, pathlen);
1194 #ifdef NFS4_ACL_EXTATTR_NAME
1197 FREE(pathcp, M_TEMP);
1202 nd->nd_repstat = nfsvno_mknod(&named, &nva, nd->nd_cred, p);
1203 if (!nd->nd_repstat) {
1205 nfsrv_fixattr(nd, vp, &nva, aclp, p, &attrbits, exp);
1206 nd->nd_repstat = nfsvno_getfh(vp, fhp, p);
1207 if ((nd->nd_flag & ND_NFSV3) && !nd->nd_repstat)
1208 nd->nd_repstat = nfsvno_getattr(vp, &nva, nd->nd_cred,
1211 NFSVOPUNLOCK(vp, 0, p);
1218 diraft_ret = nfsvno_getattr(dirp, &diraft, nd->nd_cred, p);
1220 if (!nd->nd_repstat) {
1221 if (nd->nd_flag & ND_NFSV3) {
1222 (void) nfsm_fhtom(nd, (u_int8_t *)fhp, 0, 1);
1223 nfsrv_postopattr(nd, 0, &nva);
1225 NFSM_BUILD(tl, u_int32_t *, 5 * NFSX_UNSIGNED);
1226 *tl++ = newnfs_false;
1227 txdr_hyper(dirfor.na_filerev, tl);
1229 txdr_hyper(diraft.na_filerev, tl);
1230 (void) nfsrv_putattrbit(nd, &attrbits);
1233 if (nd->nd_flag & ND_NFSV3)
1234 nfsrv_wcc(nd, dirfor_ret, &dirfor, diraft_ret, &diraft);
1235 #ifdef NFS4_ACL_EXTATTR_NAME
1241 #ifdef NFS4_ACL_EXTATTR_NAME
1245 nfsvno_relpathbuf(&named);
1247 FREE(pathcp, M_TEMP);
1252 * nfs remove service
1255 nfsrvd_remove(struct nfsrv_descript *nd, __unused int isdgram,
1256 vnode_t dp, NFSPROC_T *p, struct nfsexstuff *exp)
1258 struct nameidata named;
1260 int error, dirfor_ret = 1, diraft_ret = 1;
1261 vnode_t dirp = NULL;
1262 struct nfsvattr dirfor, diraft;
1266 if (nd->nd_repstat) {
1267 nfsrv_wcc(nd, dirfor_ret, &dirfor, diraft_ret, &diraft);
1270 NFSNAMEICNDSET(&named.ni_cnd, nd->nd_cred, DELETE,
1271 LOCKPARENT | LOCKLEAF);
1272 nfsvno_setpathbuf(&named, &bufp, &hashp);
1273 error = nfsrv_parsename(nd, bufp, hashp, &named.ni_pathlen);
1276 nfsvno_relpathbuf(&named);
1279 if (!nd->nd_repstat) {
1280 nd->nd_repstat = nfsvno_namei(nd, &named, dp, 1, exp, p, &dirp);
1283 nfsvno_relpathbuf(&named);
1286 if (!(nd->nd_flag & ND_NFSV2)) {
1287 dirfor_ret = nfsvno_getattr(dirp, &dirfor,
1294 if (!nd->nd_repstat) {
1295 if (nd->nd_flag & ND_NFSV4) {
1296 if (vnode_vtype(named.ni_vp) == VDIR)
1297 nd->nd_repstat = nfsvno_rmdirsub(&named, 1,
1298 nd->nd_cred, p, exp);
1300 nd->nd_repstat = nfsvno_removesub(&named, 1,
1301 nd->nd_cred, p, exp);
1302 } else if (nd->nd_procnum == NFSPROC_RMDIR) {
1303 nd->nd_repstat = nfsvno_rmdirsub(&named, 0,
1304 nd->nd_cred, p, exp);
1306 nd->nd_repstat = nfsvno_removesub(&named, 0,
1307 nd->nd_cred, p, exp);
1310 if (!(nd->nd_flag & ND_NFSV2)) {
1312 diraft_ret = nfsvno_getattr(dirp, &diraft, nd->nd_cred,
1316 if (nd->nd_flag & ND_NFSV3) {
1317 nfsrv_wcc(nd, dirfor_ret, &dirfor, diraft_ret,
1319 } else if (!nd->nd_repstat) {
1320 NFSM_BUILD(tl, u_int32_t *, 5 * NFSX_UNSIGNED);
1321 *tl++ = newnfs_false;
1322 txdr_hyper(dirfor.na_filerev, tl);
1324 txdr_hyper(diraft.na_filerev, tl);
1331 * nfs rename service
1334 nfsrvd_rename(struct nfsrv_descript *nd, int isdgram,
1335 vnode_t dp, vnode_t todp, NFSPROC_T *p, struct nfsexstuff *exp,
1336 struct nfsexstuff *toexp)
1339 int error, fdirfor_ret = 1, fdiraft_ret = 1;
1340 int tdirfor_ret = 1, tdiraft_ret = 1;
1341 struct nameidata fromnd, tond;
1342 vnode_t fdirp = NULL, tdirp = NULL, tdp = NULL;
1343 struct nfsvattr fdirfor, fdiraft, tdirfor, tdiraft;
1344 struct nfsexstuff tnes;
1347 char *bufp, *tbufp = NULL;
1350 if (nd->nd_repstat) {
1351 nfsrv_wcc(nd, fdirfor_ret, &fdirfor, fdiraft_ret, &fdiraft);
1352 nfsrv_wcc(nd, tdirfor_ret, &tdirfor, tdiraft_ret, &tdiraft);
1355 if (!(nd->nd_flag & ND_NFSV2))
1356 fdirfor_ret = nfsvno_getattr(dp, &fdirfor, nd->nd_cred, p);
1357 tond.ni_cnd.cn_nameiop = 0;
1358 tond.ni_startdir = NULL;
1359 NFSNAMEICNDSET(&fromnd.ni_cnd, nd->nd_cred, DELETE, WANTPARENT | SAVESTART);
1360 nfsvno_setpathbuf(&fromnd, &bufp, &hashp);
1361 error = nfsrv_parsename(nd, bufp, hashp, &fromnd.ni_pathlen);
1366 nfsvno_relpathbuf(&fromnd);
1369 if (nd->nd_flag & ND_NFSV4) {
1372 tdirfor_ret = nfsvno_getattr(tdp, &tdirfor, nd->nd_cred, p);
1374 error = nfsrv_mtofh(nd, &tfh);
1377 /* todp is always NULL except NFSv4 */
1378 nfsvno_relpathbuf(&fromnd);
1381 nd->nd_cred->cr_uid = nd->nd_saveduid;
1382 /* Won't lock vfs if already locked, mp == NULL */
1383 tnes.nes_vfslocked = exp->nes_vfslocked;
1384 nfsd_fhtovp(nd, &tfh, &tdp, &tnes, &mp, 0, p);
1386 tdirfor_ret = nfsvno_getattr(tdp, &tdirfor, nd->nd_cred,
1388 NFSVOPUNLOCK(tdp, 0, p);
1391 NFSNAMEICNDSET(&tond.ni_cnd, nd->nd_cred, RENAME, LOCKPARENT | LOCKLEAF | NOCACHE | SAVESTART);
1392 nfsvno_setpathbuf(&tond, &tbufp, &hashp);
1393 if (!nd->nd_repstat) {
1394 error = nfsrv_parsename(nd, tbufp, hashp, &tond.ni_pathlen);
1397 if (tnes.nes_vfslocked && !exp->nes_vfslocked &&
1398 !(nd->nd_flag & ND_NFSV4))
1399 nfsvno_unlockvfs(mp);
1403 nfsvno_relpathbuf(&fromnd);
1404 nfsvno_relpathbuf(&tond);
1408 if (nd->nd_repstat) {
1409 if (nd->nd_flag & ND_NFSV3) {
1410 nfsrv_wcc(nd, fdirfor_ret, &fdirfor, fdiraft_ret,
1412 nfsrv_wcc(nd, tdirfor_ret, &tdirfor, tdiraft_ret,
1416 if (tnes.nes_vfslocked && !exp->nes_vfslocked &&
1417 !(nd->nd_flag & ND_NFSV4))
1418 nfsvno_unlockvfs(mp);
1422 nfsvno_relpathbuf(&fromnd);
1423 nfsvno_relpathbuf(&tond);
1428 * Done parsing, now down to business.
1430 nd->nd_repstat = nfsvno_namei(nd, &fromnd, dp, 1, exp, p, &fdirp);
1431 if (nd->nd_repstat) {
1432 if (nd->nd_flag & ND_NFSV3) {
1433 nfsrv_wcc(nd, fdirfor_ret, &fdirfor, fdiraft_ret,
1435 nfsrv_wcc(nd, tdirfor_ret, &tdirfor, tdiraft_ret,
1441 if (tnes.nes_vfslocked && !exp->nes_vfslocked &&
1442 !(nd->nd_flag & ND_NFSV4))
1443 nfsvno_unlockvfs(mp);
1446 nfsvno_relpathbuf(&tond);
1449 if (vnode_vtype(fromnd.ni_vp) == VDIR)
1450 tond.ni_cnd.cn_flags |= WILLBEDIR;
1451 nd->nd_repstat = nfsvno_namei(nd, &tond, tdp, 0, &tnes, p, &tdirp);
1452 nd->nd_repstat = nfsvno_rename(&fromnd, &tond, nd->nd_repstat,
1453 nd->nd_flag, nd->nd_cred, p);
1455 fdiraft_ret = nfsvno_getattr(fdirp, &fdiraft, nd->nd_cred, p);
1457 tdiraft_ret = nfsvno_getattr(tdirp, &tdiraft, nd->nd_cred, p);
1458 if (tnes.nes_vfslocked && !exp->nes_vfslocked &&
1459 !(nd->nd_flag & ND_NFSV4))
1460 nfsvno_unlockvfs(mp);
1465 if (nd->nd_flag & ND_NFSV3) {
1466 nfsrv_wcc(nd, fdirfor_ret, &fdirfor, fdiraft_ret, &fdiraft);
1467 nfsrv_wcc(nd, tdirfor_ret, &tdirfor, tdiraft_ret, &tdiraft);
1468 } else if ((nd->nd_flag & ND_NFSV4) && !nd->nd_repstat) {
1469 NFSM_BUILD(tl, u_int32_t *, 10 * NFSX_UNSIGNED);
1470 *tl++ = newnfs_false;
1471 txdr_hyper(fdirfor.na_filerev, tl);
1473 txdr_hyper(fdiraft.na_filerev, tl);
1475 *tl++ = newnfs_false;
1476 txdr_hyper(tdirfor.na_filerev, tl);
1478 txdr_hyper(tdiraft.na_filerev, tl);
1487 nfsrvd_link(struct nfsrv_descript *nd, int isdgram,
1488 vnode_t vp, vnode_t tovp, NFSPROC_T *p, struct nfsexstuff *exp,
1489 struct nfsexstuff *toexp)
1491 struct nameidata named;
1493 int error = 0, dirfor_ret = 1, diraft_ret = 1, getret = 1;
1494 vnode_t dirp = NULL, dp = NULL;
1495 struct nfsvattr dirfor, diraft, at;
1496 struct nfsexstuff tnes;
1502 if (nd->nd_repstat) {
1503 nfsrv_postopattr(nd, getret, &at);
1504 nfsrv_wcc(nd, dirfor_ret, &dirfor, diraft_ret, &diraft);
1507 NFSVOPUNLOCK(vp, 0, p);
1508 if (vnode_vtype(vp) == VDIR) {
1509 if (nd->nd_flag & ND_NFSV4)
1510 nd->nd_repstat = NFSERR_ISDIR;
1512 nd->nd_repstat = NFSERR_INVAL;
1515 } else if (vnode_vtype(vp) == VLNK) {
1516 if (nd->nd_flag & ND_NFSV2)
1517 nd->nd_repstat = NFSERR_INVAL;
1519 nd->nd_repstat = NFSERR_NOTSUPP;
1523 if (!nd->nd_repstat) {
1524 if (nd->nd_flag & ND_NFSV4) {
1528 error = nfsrv_mtofh(nd, &dfh);
1531 /* tovp is always NULL unless NFSv4 */
1534 /* Won't lock vfs if already locked, mp == NULL */
1535 tnes.nes_vfslocked = exp->nes_vfslocked;
1536 nfsd_fhtovp(nd, &dfh, &dp, &tnes, &mp, 0, p);
1538 NFSVOPUNLOCK(dp, 0, p);
1541 NFSNAMEICNDSET(&named.ni_cnd, nd->nd_cred, CREATE, LOCKPARENT);
1542 if (!nd->nd_repstat) {
1543 nfsvno_setpathbuf(&named, &bufp, &hashp);
1544 error = nfsrv_parsename(nd, bufp, hashp, &named.ni_pathlen);
1548 if (tnes.nes_vfslocked && !exp->nes_vfslocked &&
1549 !(nd->nd_flag & ND_NFSV4))
1550 nfsvno_unlockvfs(mp);
1553 nfsvno_relpathbuf(&named);
1556 if (!nd->nd_repstat) {
1557 nd->nd_repstat = nfsvno_namei(nd, &named, dp, 0, &tnes,
1562 nfsvno_relpathbuf(&named);
1566 if (nd->nd_flag & ND_NFSV2) {
1570 dirfor_ret = nfsvno_getattr(dirp, &dirfor,
1574 if (!nd->nd_repstat)
1575 nd->nd_repstat = nfsvno_link(&named, vp, nd->nd_cred, p, exp);
1576 if (nd->nd_flag & ND_NFSV3)
1577 getret = nfsvno_getattr(vp, &at, nd->nd_cred, p);
1579 diraft_ret = nfsvno_getattr(dirp, &diraft, nd->nd_cred, p);
1582 if (tnes.nes_vfslocked && !exp->nes_vfslocked &&
1583 !(nd->nd_flag & ND_NFSV4))
1584 nfsvno_unlockvfs(mp);
1586 if (nd->nd_flag & ND_NFSV3) {
1587 nfsrv_postopattr(nd, getret, &at);
1588 nfsrv_wcc(nd, dirfor_ret, &dirfor, diraft_ret, &diraft);
1589 } else if ((nd->nd_flag & ND_NFSV4) && !nd->nd_repstat) {
1590 NFSM_BUILD(tl, u_int32_t *, 5 * NFSX_UNSIGNED);
1591 *tl++ = newnfs_false;
1592 txdr_hyper(dirfor.na_filerev, tl);
1594 txdr_hyper(diraft.na_filerev, tl);
1600 * nfs symbolic link service
1603 nfsrvd_symlink(struct nfsrv_descript *nd, __unused int isdgram,
1604 vnode_t dp, vnode_t *vpp, fhandle_t *fhp, NFSPROC_T *p,
1605 struct nfsexstuff *exp)
1607 struct nfsvattr nva, dirfor, diraft;
1608 struct nameidata named;
1609 int error, dirfor_ret = 1, diraft_ret = 1, pathlen;
1610 vnode_t dirp = NULL;
1611 char *bufp, *pathcp = NULL;
1614 if (nd->nd_repstat) {
1615 nfsrv_wcc(nd, dirfor_ret, &dirfor, diraft_ret, &diraft);
1620 NFSVNO_ATTRINIT(&nva);
1621 NFSNAMEICNDSET(&named.ni_cnd, nd->nd_cred, CREATE,
1622 LOCKPARENT | SAVESTART);
1623 nfsvno_setpathbuf(&named, &bufp, &hashp);
1624 error = nfsrv_parsename(nd, bufp, hashp, &named.ni_pathlen);
1625 if (!error && !nd->nd_repstat)
1626 error = nfsvno_getsymlink(nd, &nva, p, &pathcp, &pathlen);
1629 nfsvno_relpathbuf(&named);
1632 if (!nd->nd_repstat) {
1633 nd->nd_repstat = nfsvno_namei(nd, &named, dp, 0, exp, p, &dirp);
1636 nfsvno_relpathbuf(&named);
1638 if (dirp != NULL && !(nd->nd_flag & ND_NFSV3)) {
1644 * And call nfsrvd_symlinksub() to do the common code. It will
1645 * return EBADRPC upon a parsing error, 0 otherwise.
1647 if (!nd->nd_repstat) {
1649 dirfor_ret = nfsvno_getattr(dirp, &dirfor, nd->nd_cred,
1651 nfsrvd_symlinksub(nd, &named, &nva, fhp, vpp, dirp,
1652 &dirfor, &diraft, &diraft_ret, NULL, NULL, p, exp,
1654 } else if (dirp != NULL) {
1655 dirfor_ret = nfsvno_getattr(dirp, &dirfor, nd->nd_cred, p);
1659 FREE(pathcp, M_TEMP);
1661 if (nd->nd_flag & ND_NFSV3) {
1662 if (!nd->nd_repstat) {
1663 (void) nfsm_fhtom(nd, (u_int8_t *)fhp, 0, 1);
1664 nfsrv_postopattr(nd, 0, &nva);
1666 nfsrv_wcc(nd, dirfor_ret, &dirfor, diraft_ret, &diraft);
1672 * Common code for creating a symbolic link.
1675 nfsrvd_symlinksub(struct nfsrv_descript *nd, struct nameidata *ndp,
1676 struct nfsvattr *nvap, fhandle_t *fhp, vnode_t *vpp,
1677 vnode_t dirp, struct nfsvattr *dirforp, struct nfsvattr *diraftp,
1678 int *diraft_retp, nfsattrbit_t *attrbitp,
1679 NFSACL_T *aclp, NFSPROC_T *p, struct nfsexstuff *exp, char *pathcp,
1684 nd->nd_repstat = nfsvno_symlink(ndp, nvap, pathcp, pathlen,
1685 !(nd->nd_flag & ND_NFSV2), nd->nd_saveduid, nd->nd_cred, p, exp);
1686 if (!nd->nd_repstat && !(nd->nd_flag & ND_NFSV2)) {
1687 nfsrv_fixattr(nd, ndp->ni_vp, nvap, aclp, p, attrbitp, exp);
1688 if (nd->nd_flag & ND_NFSV3) {
1689 nd->nd_repstat = nfsvno_getfh(ndp->ni_vp, fhp, p);
1690 if (!nd->nd_repstat)
1691 nd->nd_repstat = nfsvno_getattr(ndp->ni_vp,
1692 nvap, nd->nd_cred, p);
1695 NFSVOPUNLOCK(ndp->ni_vp, 0, p);
1702 *diraft_retp = nfsvno_getattr(dirp, diraftp, nd->nd_cred, p);
1705 if ((nd->nd_flag & ND_NFSV4) && !nd->nd_repstat) {
1706 NFSM_BUILD(tl, u_int32_t *, 5 * NFSX_UNSIGNED);
1707 *tl++ = newnfs_false;
1708 txdr_hyper(dirforp->na_filerev, tl);
1710 txdr_hyper(diraftp->na_filerev, tl);
1711 (void) nfsrv_putattrbit(nd, attrbitp);
1719 nfsrvd_mkdir(struct nfsrv_descript *nd, __unused int isdgram,
1720 vnode_t dp, vnode_t *vpp, fhandle_t *fhp, NFSPROC_T *p,
1721 struct nfsexstuff *exp)
1723 struct nfsvattr nva, dirfor, diraft;
1724 struct nameidata named;
1726 int error, dirfor_ret = 1, diraft_ret = 1;
1727 vnode_t dirp = NULL;
1731 if (nd->nd_repstat) {
1732 nfsrv_wcc(nd, dirfor_ret, &dirfor, diraft_ret, &diraft);
1735 NFSNAMEICNDSET(&named.ni_cnd, nd->nd_cred, CREATE, LOCKPARENT);
1736 nfsvno_setpathbuf(&named, &bufp, &hashp);
1737 error = nfsrv_parsename(nd, bufp, hashp, &named.ni_pathlen);
1740 nfsvno_relpathbuf(&named);
1743 if (!nd->nd_repstat) {
1744 NFSVNO_ATTRINIT(&nva);
1745 if (nd->nd_flag & ND_NFSV3) {
1746 error = nfsrv_sattr(nd, &nva, NULL, NULL, p);
1749 nfsvno_relpathbuf(&named);
1753 NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
1754 nva.na_mode = nfstov_mode(*tl++);
1757 if (!nd->nd_repstat) {
1758 nd->nd_repstat = nfsvno_namei(nd, &named, dp, 0, exp, p, &dirp);
1761 nfsvno_relpathbuf(&named);
1763 if (dirp != NULL && !(nd->nd_flag & ND_NFSV3)) {
1767 if (nd->nd_repstat) {
1769 dirfor_ret = nfsvno_getattr(dirp, &dirfor, nd->nd_cred,
1773 if (nd->nd_flag & ND_NFSV3)
1774 nfsrv_wcc(nd, dirfor_ret, &dirfor, diraft_ret,
1779 dirfor_ret = nfsvno_getattr(dirp, &dirfor, nd->nd_cred, p);
1782 * Call nfsrvd_mkdirsub() for the code common to V4 as well.
1784 nfsrvd_mkdirsub(nd, &named, &nva, fhp, vpp, dirp, &dirfor, &diraft,
1785 &diraft_ret, NULL, NULL, p, exp);
1787 if (nd->nd_flag & ND_NFSV3) {
1788 if (!nd->nd_repstat) {
1789 (void) nfsm_fhtom(nd, (u_int8_t *)fhp, 0, 1);
1790 nfsrv_postopattr(nd, 0, &nva);
1792 nfsrv_wcc(nd, dirfor_ret, &dirfor, diraft_ret, &diraft);
1793 } else if (!nd->nd_repstat) {
1794 (void) nfsm_fhtom(nd, (u_int8_t *)fhp, 0, 0);
1795 nfsrv_fillattr(nd, &nva);
1800 nfsvno_relpathbuf(&named);
1805 * Code common to mkdir for V2,3 and 4.
1808 nfsrvd_mkdirsub(struct nfsrv_descript *nd, struct nameidata *ndp,
1809 struct nfsvattr *nvap, fhandle_t *fhp, vnode_t *vpp,
1810 vnode_t dirp, struct nfsvattr *dirforp, struct nfsvattr *diraftp,
1811 int *diraft_retp, nfsattrbit_t *attrbitp, NFSACL_T *aclp,
1812 NFSPROC_T *p, struct nfsexstuff *exp)
1817 NFSVNO_SETATTRVAL(nvap, type, VDIR);
1818 nd->nd_repstat = nfsvno_mkdir(ndp, nvap, nd->nd_saveduid,
1819 nd->nd_cred, p, exp);
1820 if (!nd->nd_repstat) {
1822 nfsrv_fixattr(nd, vp, nvap, aclp, p, attrbitp, exp);
1823 nd->nd_repstat = nfsvno_getfh(vp, fhp, p);
1824 if (!(nd->nd_flag & ND_NFSV4) && !nd->nd_repstat)
1825 nd->nd_repstat = nfsvno_getattr(vp, nvap, nd->nd_cred,
1827 if (vpp && !nd->nd_repstat) {
1828 NFSVOPUNLOCK(vp, 0, p);
1835 *diraft_retp = nfsvno_getattr(dirp, diraftp, nd->nd_cred, p);
1838 if ((nd->nd_flag & ND_NFSV4) && !nd->nd_repstat) {
1839 NFSM_BUILD(tl, u_int32_t *, 5 * NFSX_UNSIGNED);
1840 *tl++ = newnfs_false;
1841 txdr_hyper(dirforp->na_filerev, tl);
1843 txdr_hyper(diraftp->na_filerev, tl);
1844 (void) nfsrv_putattrbit(nd, attrbitp);
1849 * nfs commit service
1852 nfsrvd_commit(struct nfsrv_descript *nd, __unused int isdgram,
1853 vnode_t vp, NFSPROC_T *p, __unused struct nfsexstuff *exp)
1855 struct nfsvattr bfor, aft;
1857 int error = 0, for_ret = 1, aft_ret = 1, cnt;
1860 if (nd->nd_repstat) {
1861 nfsrv_wcc(nd, for_ret, &bfor, aft_ret, &aft);
1864 NFSM_DISSECT(tl, u_int32_t *, 3 * NFSX_UNSIGNED);
1866 * XXX At this time VOP_FSYNC() does not accept offset and byte
1867 * count parameters, so these arguments are useless (someday maybe).
1869 off = fxdr_hyper(tl);
1871 cnt = fxdr_unsigned(int, *tl);
1872 if (nd->nd_flag & ND_NFSV3)
1873 for_ret = nfsvno_getattr(vp, &bfor, nd->nd_cred, p);
1874 nd->nd_repstat = nfsvno_fsync(vp, off, cnt, nd->nd_cred, p);
1875 if (nd->nd_flag & ND_NFSV3) {
1876 aft_ret = nfsvno_getattr(vp, &aft, nd->nd_cred, p);
1877 nfsrv_wcc(nd, for_ret, &bfor, aft_ret, &aft);
1880 if (!nd->nd_repstat) {
1881 NFSM_BUILD(tl, u_int32_t *, NFSX_VERF);
1882 *tl++ = txdr_unsigned(nfsboottime.tv_sec);
1883 *tl = txdr_unsigned(nfsboottime.tv_usec);
1892 * nfs statfs service
1895 nfsrvd_statfs(struct nfsrv_descript *nd, __unused int isdgram,
1896 vnode_t vp, NFSPROC_T *p, __unused struct nfsexstuff *exp)
1905 if (nd->nd_repstat) {
1906 nfsrv_postopattr(nd, getret, &at);
1910 nd->nd_repstat = nfsvno_statfs(vp, sf);
1911 getret = nfsvno_getattr(vp, &at, nd->nd_cred, p);
1913 if (nd->nd_flag & ND_NFSV3)
1914 nfsrv_postopattr(nd, getret, &at);
1917 if (nd->nd_flag & ND_NFSV2) {
1918 NFSM_BUILD(tl, u_int32_t *, NFSX_V2STATFS);
1919 *tl++ = txdr_unsigned(NFS_V2MAXDATA);
1920 *tl++ = txdr_unsigned(sf->f_bsize);
1921 *tl++ = txdr_unsigned(sf->f_blocks);
1922 *tl++ = txdr_unsigned(sf->f_bfree);
1923 *tl = txdr_unsigned(sf->f_bavail);
1925 NFSM_BUILD(tl, u_int32_t *, NFSX_V3STATFS);
1926 tval = (u_quad_t)sf->f_blocks;
1927 tval *= (u_quad_t)sf->f_bsize;
1928 txdr_hyper(tval, tl); tl += 2;
1929 tval = (u_quad_t)sf->f_bfree;
1930 tval *= (u_quad_t)sf->f_bsize;
1931 txdr_hyper(tval, tl); tl += 2;
1932 tval = (u_quad_t)sf->f_bavail;
1933 tval *= (u_quad_t)sf->f_bsize;
1934 txdr_hyper(tval, tl); tl += 2;
1935 tval = (u_quad_t)sf->f_files;
1936 txdr_hyper(tval, tl); tl += 2;
1937 tval = (u_quad_t)sf->f_ffree;
1938 txdr_hyper(tval, tl); tl += 2;
1939 tval = (u_quad_t)sf->f_ffree;
1940 txdr_hyper(tval, tl); tl += 2;
1947 * nfs fsinfo service
1950 nfsrvd_fsinfo(struct nfsrv_descript *nd, int isdgram,
1951 vnode_t vp, NFSPROC_T *p, __unused struct nfsexstuff *exp)
1954 struct nfsfsinfo fs;
1958 if (nd->nd_repstat) {
1959 nfsrv_postopattr(nd, getret, &at);
1962 getret = nfsvno_getattr(vp, &at, nd->nd_cred, p);
1963 nfsvno_getfs(&fs, isdgram);
1965 nfsrv_postopattr(nd, getret, &at);
1966 NFSM_BUILD(tl, u_int32_t *, NFSX_V3FSINFO);
1967 *tl++ = txdr_unsigned(fs.fs_rtmax);
1968 *tl++ = txdr_unsigned(fs.fs_rtpref);
1969 *tl++ = txdr_unsigned(fs.fs_rtmult);
1970 *tl++ = txdr_unsigned(fs.fs_wtmax);
1971 *tl++ = txdr_unsigned(fs.fs_wtpref);
1972 *tl++ = txdr_unsigned(fs.fs_wtmult);
1973 *tl++ = txdr_unsigned(fs.fs_dtpref);
1974 txdr_hyper(fs.fs_maxfilesize, tl);
1976 txdr_nfsv3time(&fs.fs_timedelta, tl);
1978 *tl = txdr_unsigned(fs.fs_properties);
1983 * nfs pathconf service
1986 nfsrvd_pathconf(struct nfsrv_descript *nd, __unused int isdgram,
1987 vnode_t vp, NFSPROC_T *p, __unused struct nfsexstuff *exp)
1989 struct nfsv3_pathconf *pc;
1991 register_t linkmax, namemax, chownres, notrunc;
1994 if (nd->nd_repstat) {
1995 nfsrv_postopattr(nd, getret, &at);
1998 nd->nd_repstat = nfsvno_pathconf(vp, _PC_LINK_MAX, &linkmax,
2000 if (!nd->nd_repstat)
2001 nd->nd_repstat = nfsvno_pathconf(vp, _PC_NAME_MAX, &namemax,
2003 if (!nd->nd_repstat)
2004 nd->nd_repstat=nfsvno_pathconf(vp, _PC_CHOWN_RESTRICTED,
2005 &chownres, nd->nd_cred, p);
2006 if (!nd->nd_repstat)
2007 nd->nd_repstat = nfsvno_pathconf(vp, _PC_NO_TRUNC, ¬runc,
2009 getret = nfsvno_getattr(vp, &at, nd->nd_cred, p);
2011 nfsrv_postopattr(nd, getret, &at);
2012 if (!nd->nd_repstat) {
2013 NFSM_BUILD(pc, struct nfsv3_pathconf *, NFSX_V3PATHCONF);
2014 pc->pc_linkmax = txdr_unsigned(linkmax);
2015 pc->pc_namemax = txdr_unsigned(namemax);
2016 pc->pc_notrunc = txdr_unsigned(notrunc);
2017 pc->pc_chownrestricted = txdr_unsigned(chownres);
2020 * These should probably be supported by VOP_PATHCONF(), but
2021 * until msdosfs is exportable (why would you want to?), the
2022 * Unix defaults should be ok.
2024 pc->pc_caseinsensitive = newnfs_false;
2025 pc->pc_casepreserving = newnfs_true;
2031 * nfsv4 lock service
2034 nfsrvd_lock(struct nfsrv_descript *nd, __unused int isdgram,
2035 vnode_t vp, NFSPROC_T *p, struct nfsexstuff *exp)
2039 struct nfsstate *stp = NULL;
2040 struct nfslock *lop;
2041 struct nfslockconflict cf;
2043 u_short flags = NFSLCK_LOCK, lflags;
2044 u_int64_t offset, len;
2045 nfsv4stateid_t stateid;
2048 NFSM_DISSECT(tl, u_int32_t *, 7 * NFSX_UNSIGNED);
2049 i = fxdr_unsigned(int, *tl++);
2051 case NFSV4LOCKT_READW:
2052 flags |= NFSLCK_BLOCKING;
2053 case NFSV4LOCKT_READ:
2054 lflags = NFSLCK_READ;
2056 case NFSV4LOCKT_WRITEW:
2057 flags |= NFSLCK_BLOCKING;
2058 case NFSV4LOCKT_WRITE:
2059 lflags = NFSLCK_WRITE;
2062 nd->nd_repstat = NFSERR_BADXDR;
2065 if (*tl++ == newnfs_true)
2066 flags |= NFSLCK_RECLAIM;
2067 offset = fxdr_hyper(tl);
2069 len = fxdr_hyper(tl);
2071 if (*tl == newnfs_true)
2072 flags |= NFSLCK_OPENTOLOCK;
2073 if (flags & NFSLCK_OPENTOLOCK) {
2074 NFSM_DISSECT(tl, u_int32_t *, 5 * NFSX_UNSIGNED + NFSX_STATEID);
2075 i = fxdr_unsigned(int, *(tl+4+(NFSX_STATEID / NFSX_UNSIGNED)));
2076 MALLOC(stp, struct nfsstate *, sizeof (struct nfsstate) + i,
2077 M_NFSDSTATE, M_WAITOK);
2078 stp->ls_ownerlen = i;
2079 stp->ls_op = nd->nd_rp;
2080 stp->ls_seq = fxdr_unsigned(int, *tl++);
2081 stp->ls_stateid.seqid = fxdr_unsigned(u_int32_t, *tl++);
2082 NFSBCOPY((caddr_t)tl, (caddr_t)stp->ls_stateid.other,
2084 tl += (NFSX_STATEIDOTHER / NFSX_UNSIGNED);
2085 stp->ls_opentolockseq = fxdr_unsigned(int, *tl++);
2086 clientid.lval[0] = *tl++;
2087 clientid.lval[1] = *tl++;
2088 if (nd->nd_flag & ND_IMPLIEDCLID) {
2089 if (nd->nd_clientid.qval != clientid.qval)
2090 printf("EEK! multiple clids\n");
2092 nd->nd_flag |= ND_IMPLIEDCLID;
2093 nd->nd_clientid.qval = clientid.qval;
2095 error = nfsrv_mtostr(nd, stp->ls_owner, stp->ls_ownerlen);
2099 NFSM_DISSECT(tl, u_int32_t *, NFSX_STATEID + NFSX_UNSIGNED);
2100 MALLOC(stp, struct nfsstate *, sizeof (struct nfsstate),
2101 M_NFSDSTATE, M_WAITOK);
2102 stp->ls_ownerlen = 0;
2103 stp->ls_op = nd->nd_rp;
2104 stp->ls_stateid.seqid = fxdr_unsigned(u_int32_t, *tl++);
2105 NFSBCOPY((caddr_t)tl, (caddr_t)stp->ls_stateid.other,
2107 tl += (NFSX_STATEIDOTHER / NFSX_UNSIGNED);
2108 stp->ls_seq = fxdr_unsigned(int, *tl);
2109 clientid.lval[0] = stp->ls_stateid.other[0];
2110 clientid.lval[1] = stp->ls_stateid.other[1];
2111 if (nd->nd_flag & ND_IMPLIEDCLID) {
2112 if (nd->nd_clientid.qval != clientid.qval)
2113 printf("EEK! multiple clids\n");
2115 nd->nd_flag |= ND_IMPLIEDCLID;
2116 nd->nd_clientid.qval = clientid.qval;
2119 MALLOC(lop, struct nfslock *, sizeof (struct nfslock),
2120 M_NFSDLOCK, M_WAITOK);
2121 lop->lo_first = offset;
2122 if (len == NFS64BITSSET) {
2123 lop->lo_end = NFS64BITSSET;
2125 lop->lo_end = offset + len;
2126 if (lop->lo_end <= lop->lo_first)
2127 nd->nd_repstat = NFSERR_INVAL;
2129 lop->lo_flags = lflags;
2130 stp->ls_flags = flags;
2131 stp->ls_uid = nd->nd_cred->cr_uid;
2134 * Do basic access checking.
2136 if (!nd->nd_repstat && vnode_vtype(vp) != VREG) {
2137 if (vnode_vtype(vp) == VDIR)
2138 nd->nd_repstat = NFSERR_ISDIR;
2140 nd->nd_repstat = NFSERR_INVAL;
2142 if (!nd->nd_repstat) {
2143 if (lflags & NFSLCK_WRITE) {
2144 nd->nd_repstat = nfsvno_accchk(vp, NFSV4ACE_WRITEDATA,
2145 nd->nd_cred, exp, p, NFSACCCHK_ALLOWOWNER,
2146 NFSACCCHK_VPISLOCKED);
2148 nd->nd_repstat = nfsvno_accchk(vp, NFSV4ACE_READDATA,
2149 nd->nd_cred, exp, p, NFSACCCHK_ALLOWOWNER,
2150 NFSACCCHK_VPISLOCKED);
2152 nd->nd_repstat = nfsvno_accchk(vp, NFSV4ACE_EXECUTE,
2153 nd->nd_cred, exp, p, NFSACCCHK_ALLOWOWNER,
2154 NFSACCCHK_VPISLOCKED);
2159 * We call nfsrv_lockctrl() even if nd_repstat set, so that the
2160 * seqid# gets updated. nfsrv_lockctrl() will return the value
2161 * of nd_repstat, if it gets that far.
2163 nd->nd_repstat = nfsrv_lockctrl(vp, &stp, &lop, &cf, clientid,
2164 &stateid, exp, nd, p);
2166 FREE((caddr_t)lop, M_NFSDLOCK);
2168 FREE((caddr_t)stp, M_NFSDSTATE);
2169 if (!nd->nd_repstat) {
2170 NFSM_BUILD(tl, u_int32_t *, NFSX_STATEID);
2171 *tl++ = txdr_unsigned(stateid.seqid);
2172 NFSBCOPY((caddr_t)stateid.other,(caddr_t)tl,NFSX_STATEIDOTHER);
2173 } else if (nd->nd_repstat == NFSERR_DENIED) {
2174 NFSM_BUILD(tl, u_int32_t *, 7 * NFSX_UNSIGNED);
2175 txdr_hyper(cf.cl_first, tl);
2177 if (cf.cl_end == NFS64BITSSET)
2180 len = cf.cl_end - cf.cl_first;
2181 txdr_hyper(len, tl);
2183 if (cf.cl_flags == NFSLCK_WRITE)
2184 *tl++ = txdr_unsigned(NFSV4LOCKT_WRITE);
2186 *tl++ = txdr_unsigned(NFSV4LOCKT_READ);
2187 *tl++ = stateid.other[0];
2188 *tl = stateid.other[1];
2189 (void) nfsm_strtom(nd, cf.cl_owner, cf.cl_ownerlen);
2196 free((caddr_t)stp, M_NFSDSTATE);
2201 * nfsv4 lock test service
2204 nfsrvd_lockt(struct nfsrv_descript *nd, __unused int isdgram,
2205 vnode_t vp, NFSPROC_T *p, struct nfsexstuff *exp)
2209 struct nfsstate *stp = NULL;
2210 struct nfslock lo, *lop = &lo;
2211 struct nfslockconflict cf;
2213 nfsv4stateid_t stateid;
2217 NFSM_DISSECT(tl, u_int32_t *, 8 * NFSX_UNSIGNED);
2218 i = fxdr_unsigned(int, *(tl + 7));
2219 MALLOC(stp, struct nfsstate *, sizeof (struct nfsstate) + i,
2220 M_NFSDSTATE, M_WAITOK);
2221 stp->ls_ownerlen = i;
2223 stp->ls_flags = NFSLCK_TEST;
2224 stp->ls_uid = nd->nd_cred->cr_uid;
2225 i = fxdr_unsigned(int, *tl++);
2227 case NFSV4LOCKT_READW:
2228 stp->ls_flags |= NFSLCK_BLOCKING;
2229 case NFSV4LOCKT_READ:
2230 lo.lo_flags = NFSLCK_READ;
2232 case NFSV4LOCKT_WRITEW:
2233 stp->ls_flags |= NFSLCK_BLOCKING;
2234 case NFSV4LOCKT_WRITE:
2235 lo.lo_flags = NFSLCK_WRITE;
2238 nd->nd_repstat = NFSERR_BADXDR;
2241 lo.lo_first = fxdr_hyper(tl);
2243 len = fxdr_hyper(tl);
2244 if (len == NFS64BITSSET) {
2245 lo.lo_end = NFS64BITSSET;
2247 lo.lo_end = lo.lo_first + len;
2248 if (lo.lo_end <= lo.lo_first)
2249 nd->nd_repstat = NFSERR_INVAL;
2252 clientid.lval[0] = *tl++;
2253 clientid.lval[1] = *tl;
2254 if (nd->nd_flag & ND_IMPLIEDCLID) {
2255 if (nd->nd_clientid.qval != clientid.qval)
2256 printf("EEK! multiple clids\n");
2258 nd->nd_flag |= ND_IMPLIEDCLID;
2259 nd->nd_clientid.qval = clientid.qval;
2261 error = nfsrv_mtostr(nd, stp->ls_owner, stp->ls_ownerlen);
2264 if (!nd->nd_repstat && vnode_vtype(vp) != VREG) {
2265 if (vnode_vtype(vp) == VDIR)
2266 nd->nd_repstat = NFSERR_ISDIR;
2268 nd->nd_repstat = NFSERR_INVAL;
2270 if (!nd->nd_repstat)
2271 nd->nd_repstat = nfsrv_lockctrl(vp, &stp, &lop, &cf, clientid,
2272 &stateid, exp, nd, p);
2274 FREE((caddr_t)stp, M_NFSDSTATE);
2275 if (nd->nd_repstat) {
2276 if (nd->nd_repstat == NFSERR_DENIED) {
2277 NFSM_BUILD(tl, u_int32_t *, 7 * NFSX_UNSIGNED);
2278 txdr_hyper(cf.cl_first, tl);
2280 if (cf.cl_end == NFS64BITSSET)
2283 len = cf.cl_end - cf.cl_first;
2284 txdr_hyper(len, tl);
2286 if (cf.cl_flags == NFSLCK_WRITE)
2287 *tl++ = txdr_unsigned(NFSV4LOCKT_WRITE);
2289 *tl++ = txdr_unsigned(NFSV4LOCKT_READ);
2290 *tl++ = stp->ls_stateid.other[0];
2291 *tl = stp->ls_stateid.other[1];
2292 (void) nfsm_strtom(nd, cf.cl_owner, cf.cl_ownerlen);
2300 free((caddr_t)stp, M_NFSDSTATE);
2305 * nfsv4 unlock service
2308 nfsrvd_locku(struct nfsrv_descript *nd, __unused int isdgram,
2309 vnode_t vp, NFSPROC_T *p, struct nfsexstuff *exp)
2313 struct nfsstate *stp;
2314 struct nfslock *lop;
2316 nfsv4stateid_t stateid;
2320 NFSM_DISSECT(tl, u_int32_t *, 6 * NFSX_UNSIGNED + NFSX_STATEID);
2321 MALLOC(stp, struct nfsstate *, sizeof (struct nfsstate),
2322 M_NFSDSTATE, M_WAITOK);
2323 MALLOC(lop, struct nfslock *, sizeof (struct nfslock),
2324 M_NFSDLOCK, M_WAITOK);
2325 stp->ls_flags = NFSLCK_UNLOCK;
2326 lop->lo_flags = NFSLCK_UNLOCK;
2327 stp->ls_op = nd->nd_rp;
2328 i = fxdr_unsigned(int, *tl++);
2330 case NFSV4LOCKT_READW:
2331 stp->ls_flags |= NFSLCK_BLOCKING;
2332 case NFSV4LOCKT_READ:
2334 case NFSV4LOCKT_WRITEW:
2335 stp->ls_flags |= NFSLCK_BLOCKING;
2336 case NFSV4LOCKT_WRITE:
2339 nd->nd_repstat = NFSERR_BADXDR;
2342 stp->ls_ownerlen = 0;
2343 stp->ls_uid = nd->nd_cred->cr_uid;
2344 stp->ls_seq = fxdr_unsigned(int, *tl++);
2345 stp->ls_stateid.seqid = fxdr_unsigned(u_int32_t, *tl++);
2346 NFSBCOPY((caddr_t)tl, (caddr_t)stp->ls_stateid.other,
2348 tl += (NFSX_STATEIDOTHER / NFSX_UNSIGNED);
2349 lop->lo_first = fxdr_hyper(tl);
2351 len = fxdr_hyper(tl);
2352 if (len == NFS64BITSSET) {
2353 lop->lo_end = NFS64BITSSET;
2355 lop->lo_end = lop->lo_first + len;
2356 if (lop->lo_end <= lop->lo_first)
2357 nd->nd_repstat = NFSERR_INVAL;
2359 clientid.lval[0] = stp->ls_stateid.other[0];
2360 clientid.lval[1] = stp->ls_stateid.other[1];
2361 if (nd->nd_flag & ND_IMPLIEDCLID) {
2362 if (nd->nd_clientid.qval != clientid.qval)
2363 printf("EEK! multiple clids\n");
2365 nd->nd_flag |= ND_IMPLIEDCLID;
2366 nd->nd_clientid.qval = clientid.qval;
2368 if (!nd->nd_repstat && vnode_vtype(vp) != VREG) {
2369 if (vnode_vtype(vp) == VDIR)
2370 nd->nd_repstat = NFSERR_ISDIR;
2372 nd->nd_repstat = NFSERR_INVAL;
2375 * Call nfsrv_lockctrl() even if nd_repstat is set, so that the
2376 * seqid# gets incremented. nfsrv_lockctrl() will return the
2377 * value of nd_repstat, if it gets that far.
2379 nd->nd_repstat = nfsrv_lockctrl(vp, &stp, &lop, NULL, clientid,
2380 &stateid, exp, nd, p);
2382 FREE((caddr_t)stp, M_NFSDSTATE);
2384 free((caddr_t)lop, M_NFSDLOCK);
2385 if (!nd->nd_repstat) {
2386 NFSM_BUILD(tl, u_int32_t *, NFSX_STATEID);
2387 *tl++ = txdr_unsigned(stateid.seqid);
2388 NFSBCOPY((caddr_t)stateid.other,(caddr_t)tl,NFSX_STATEIDOTHER);
2396 * nfsv4 open service
2399 nfsrvd_open(struct nfsrv_descript *nd, __unused int isdgram,
2400 vnode_t dp, vnode_t *vpp, __unused fhandle_t *fhp, NFSPROC_T *p,
2401 struct nfsexstuff *exp)
2405 struct nfsstate *stp = NULL;
2406 int error = 0, create, claim, exclusive_flag = 0;
2407 u_int32_t rflags = NFSV4OPEN_LOCKTYPEPOSIX, acemask;
2408 int how = NFSCREATE_UNCHECKED;
2409 u_char cverf[NFSX_VERF];
2410 vnode_t vp = NULL, dirp = NULL;
2411 struct nfsvattr nva, dirfor, diraft;
2412 struct nameidata named;
2413 nfsv4stateid_t stateid, delegstateid;
2414 nfsattrbit_t attrbits;
2418 NFSACL_T *aclp = NULL;
2420 #ifdef NFS4_ACL_EXTATTR_NAME
2421 aclp = acl_alloc(M_WAITOK);
2424 NFSZERO_ATTRBIT(&attrbits);
2425 named.ni_startdir = NULL;
2426 named.ni_cnd.cn_nameiop = 0;
2427 NFSM_DISSECT(tl, u_int32_t *, 6 * NFSX_UNSIGNED);
2428 i = fxdr_unsigned(int, *(tl + 5));
2429 MALLOC(stp, struct nfsstate *, sizeof (struct nfsstate) + i,
2430 M_NFSDSTATE, M_WAITOK);
2431 stp->ls_ownerlen = i;
2432 stp->ls_op = nd->nd_rp;
2433 stp->ls_flags = NFSLCK_OPEN;
2434 stp->ls_uid = nd->nd_cred->cr_uid;
2435 stp->ls_seq = fxdr_unsigned(u_int32_t, *tl++);
2436 i = fxdr_unsigned(int, *tl++);
2438 case NFSV4OPEN_ACCESSREAD:
2439 stp->ls_flags |= NFSLCK_READACCESS;
2441 case NFSV4OPEN_ACCESSWRITE:
2442 stp->ls_flags |= NFSLCK_WRITEACCESS;
2444 case NFSV4OPEN_ACCESSBOTH:
2445 stp->ls_flags |= (NFSLCK_READACCESS | NFSLCK_WRITEACCESS);
2448 nd->nd_repstat = NFSERR_INVAL;
2450 i = fxdr_unsigned(int, *tl++);
2452 case NFSV4OPEN_DENYNONE:
2454 case NFSV4OPEN_DENYREAD:
2455 stp->ls_flags |= NFSLCK_READDENY;
2457 case NFSV4OPEN_DENYWRITE:
2458 stp->ls_flags |= NFSLCK_WRITEDENY;
2460 case NFSV4OPEN_DENYBOTH:
2461 stp->ls_flags |= (NFSLCK_READDENY | NFSLCK_WRITEDENY);
2464 nd->nd_repstat = NFSERR_INVAL;
2466 clientid.lval[0] = *tl++;
2467 clientid.lval[1] = *tl;
2468 if (nd->nd_flag & ND_IMPLIEDCLID) {
2469 if (nd->nd_clientid.qval != clientid.qval)
2470 printf("EEK! multiple clids\n");
2472 nd->nd_flag |= ND_IMPLIEDCLID;
2473 nd->nd_clientid.qval = clientid.qval;
2475 error = nfsrv_mtostr(nd, stp->ls_owner, stp->ls_ownerlen);
2478 #ifdef NFS4_ACL_EXTATTR_NAME
2481 FREE((caddr_t)stp, M_NFSDSTATE);
2484 NFSVNO_ATTRINIT(&nva);
2485 NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
2486 create = fxdr_unsigned(int, *tl);
2487 if (!nd->nd_repstat)
2488 nd->nd_repstat = nfsvno_getattr(dp, &dirfor, nd->nd_cred, p);
2489 if (create == NFSV4OPEN_CREATE) {
2492 NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
2493 how = fxdr_unsigned(int, *tl);
2495 case NFSCREATE_UNCHECKED:
2496 case NFSCREATE_GUARDED:
2497 error = nfsv4_sattr(nd, &nva, &attrbits, aclp, p);
2500 #ifdef NFS4_ACL_EXTATTR_NAME
2503 FREE((caddr_t)stp, M_NFSDSTATE);
2507 * If the na_gid being set is the same as that of
2508 * the directory it is going in, clear it, since
2509 * that is what will be set by default. This allows
2510 * a user that isn't in that group to do the create.
2512 if (!nd->nd_repstat && NFSVNO_ISSETGID(&nva) &&
2513 nva.na_gid == dirfor.na_gid)
2514 NFSVNO_UNSET(&nva, gid);
2515 if (!nd->nd_repstat)
2516 nd->nd_repstat = nfsrv_checkuidgid(nd, &nva);
2518 case NFSCREATE_EXCLUSIVE:
2519 NFSM_DISSECT(tl, u_int32_t *, NFSX_VERF);
2520 NFSBCOPY((caddr_t)tl, cverf, NFSX_VERF);
2523 nd->nd_repstat = NFSERR_BADXDR;
2525 #ifdef NFS4_ACL_EXTATTR_NAME
2528 FREE((caddr_t)stp, M_NFSDSTATE);
2531 } else if (create != NFSV4OPEN_NOCREATE) {
2532 nd->nd_repstat = NFSERR_BADXDR;
2534 #ifdef NFS4_ACL_EXTATTR_NAME
2537 FREE((caddr_t)stp, M_NFSDSTATE);
2542 * Now, handle the claim, which usually includes looking up a
2543 * name in the directory referenced by dp. The exception is
2544 * NFSV4OPEN_CLAIMPREVIOUS.
2546 NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
2547 claim = fxdr_unsigned(int, *tl);
2548 if (claim == NFSV4OPEN_CLAIMDELEGATECUR) {
2549 NFSM_DISSECT(tl, u_int32_t *, NFSX_STATEID);
2550 stateid.seqid = fxdr_unsigned(u_int32_t, *tl++);
2551 NFSBCOPY((caddr_t)tl,(caddr_t)stateid.other,NFSX_STATEIDOTHER);
2552 stp->ls_flags |= NFSLCK_DELEGCUR;
2553 } else if (claim == NFSV4OPEN_CLAIMDELEGATEPREV) {
2554 stp->ls_flags |= NFSLCK_DELEGPREV;
2556 if (claim == NFSV4OPEN_CLAIMNULL || claim == NFSV4OPEN_CLAIMDELEGATECUR
2557 || claim == NFSV4OPEN_CLAIMDELEGATEPREV) {
2558 if (!nd->nd_repstat && create == NFSV4OPEN_CREATE &&
2559 claim != NFSV4OPEN_CLAIMNULL)
2560 nd->nd_repstat = NFSERR_INVAL;
2561 if (nd->nd_repstat) {
2562 nd->nd_repstat = nfsrv_opencheck(clientid,
2563 &stateid, stp, NULL, nd, p, nd->nd_repstat);
2565 #ifdef NFS4_ACL_EXTATTR_NAME
2568 FREE((caddr_t)stp, M_NFSDSTATE);
2571 if (create == NFSV4OPEN_CREATE)
2572 NFSNAMEICNDSET(&named.ni_cnd, nd->nd_cred, CREATE,
2573 LOCKPARENT | LOCKLEAF | SAVESTART);
2575 NFSNAMEICNDSET(&named.ni_cnd, nd->nd_cred, LOOKUP,
2576 LOCKLEAF | SAVESTART);
2577 nfsvno_setpathbuf(&named, &bufp, &hashp);
2578 error = nfsrv_parsename(nd, bufp, hashp, &named.ni_pathlen);
2581 #ifdef NFS4_ACL_EXTATTR_NAME
2584 FREE((caddr_t)stp, M_NFSDSTATE);
2585 nfsvno_relpathbuf(&named);
2588 if (!nd->nd_repstat) {
2589 nd->nd_repstat = nfsvno_namei(nd, &named, dp, 0, exp,
2593 nfsvno_relpathbuf(&named);
2595 if (create == NFSV4OPEN_CREATE) {
2597 case NFSCREATE_UNCHECKED:
2600 * Clear the setable attribute bits, except
2601 * for Size, if it is being truncated.
2603 NFSZERO_ATTRBIT(&attrbits);
2604 if (NFSVNO_ISSETSIZE(&nva))
2605 NFSSETBIT_ATTRBIT(&attrbits,
2609 case NFSCREATE_GUARDED:
2610 if (named.ni_vp && !nd->nd_repstat)
2611 nd->nd_repstat = EEXIST;
2613 case NFSCREATE_EXCLUSIVE:
2619 nfsvno_open(nd, &named, clientid, &stateid, stp,
2620 &exclusive_flag, &nva, cverf, create, aclp, &attrbits,
2621 nd->nd_cred, p, exp, &vp);
2622 } else if (claim == NFSV4OPEN_CLAIMPREVIOUS) {
2623 NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
2624 i = fxdr_unsigned(int, *tl);
2626 case NFSV4OPEN_DELEGATEREAD:
2627 stp->ls_flags |= NFSLCK_DELEGREAD;
2629 case NFSV4OPEN_DELEGATEWRITE:
2630 stp->ls_flags |= NFSLCK_DELEGWRITE;
2631 case NFSV4OPEN_DELEGATENONE:
2634 nd->nd_repstat = NFSERR_BADXDR;
2636 #ifdef NFS4_ACL_EXTATTR_NAME
2639 FREE((caddr_t)stp, M_NFSDSTATE);
2642 stp->ls_flags |= NFSLCK_RECLAIM;
2644 NFSVOPLOCK(vp, LK_EXCLUSIVE | LK_RETRY, p);
2645 nd->nd_repstat = nfsrv_opencheck(clientid, &stateid, stp, vp,
2646 nd, p, nd->nd_repstat);
2648 nd->nd_repstat = NFSERR_BADXDR;
2650 #ifdef NFS4_ACL_EXTATTR_NAME
2653 FREE((caddr_t)stp, M_NFSDSTATE);
2658 * Do basic access checking.
2660 if (!nd->nd_repstat && vnode_vtype(vp) != VREG) {
2661 if (vnode_vtype(vp) == VDIR)
2662 nd->nd_repstat = NFSERR_ISDIR;
2663 else if (vnode_vtype(vp) == VLNK)
2664 nd->nd_repstat = NFSERR_SYMLINK;
2666 nd->nd_repstat = NFSERR_INVAL;
2668 if (!nd->nd_repstat && (stp->ls_flags & NFSLCK_WRITEACCESS))
2669 nd->nd_repstat = nfsvno_accchk(vp, NFSV4ACE_WRITEDATA, nd->nd_cred,
2670 exp, p, NFSACCCHK_ALLOWOWNER, NFSACCCHK_VPISLOCKED);
2671 if (!nd->nd_repstat && (stp->ls_flags & NFSLCK_READACCESS)) {
2672 nd->nd_repstat = nfsvno_accchk(vp, NFSV4ACE_READDATA, nd->nd_cred,
2673 exp, p, NFSACCCHK_ALLOWOWNER, NFSACCCHK_VPISLOCKED);
2675 nd->nd_repstat = nfsvno_accchk(vp, NFSV4ACE_EXECUTE,
2676 nd->nd_cred, exp, p, NFSACCCHK_ALLOWOWNER,
2677 NFSACCCHK_VPISLOCKED);
2680 if (!nd->nd_repstat)
2681 nd->nd_repstat = nfsvno_getattr(vp, &nva, nd->nd_cred, p);
2682 if (!nd->nd_repstat && exclusive_flag &&
2683 NFSBCMP(cverf, (caddr_t)&nva.na_atime, NFSX_VERF))
2684 nd->nd_repstat = EEXIST;
2686 * Do the open locking/delegation stuff.
2688 if (!nd->nd_repstat)
2689 nd->nd_repstat = nfsrv_openctrl(nd, vp, &stp, clientid, &stateid,
2690 &delegstateid, &rflags, exp, p, nva.na_filerev);
2693 * vp must be unlocked before the call to nfsvno_getattr(dirp,...)
2694 * below, to avoid a deadlock with the lookup in nfsvno_namei() above.
2695 * (ie: Leave the NFSVOPUNLOCK() about here.)
2698 NFSVOPUNLOCK(vp, 0, p);
2700 FREE((caddr_t)stp, M_NFSDSTATE);
2701 if (!nd->nd_repstat && dirp)
2702 nd->nd_repstat = nfsvno_getattr(dirp, &diraft, nd->nd_cred, p);
2703 if (!nd->nd_repstat) {
2704 NFSM_BUILD(tl, u_int32_t *, NFSX_STATEID + 6 * NFSX_UNSIGNED);
2705 *tl++ = txdr_unsigned(stateid.seqid);
2706 NFSBCOPY((caddr_t)stateid.other,(caddr_t)tl,NFSX_STATEIDOTHER);
2707 tl += (NFSX_STATEIDOTHER / NFSX_UNSIGNED);
2708 if (claim == NFSV4OPEN_CLAIMPREVIOUS) {
2709 *tl++ = newnfs_true;
2715 *tl++ = newnfs_false; /* Since dirp is not locked */
2716 txdr_hyper(dirfor.na_filerev, tl);
2718 txdr_hyper(diraft.na_filerev, tl);
2721 *tl = txdr_unsigned(rflags & NFSV4OPEN_RFLAGS);
2722 (void) nfsrv_putattrbit(nd, &attrbits);
2723 NFSM_BUILD(tl, u_int32_t *, NFSX_UNSIGNED);
2724 if (rflags & NFSV4OPEN_READDELEGATE)
2725 *tl = txdr_unsigned(NFSV4OPEN_DELEGATEREAD);
2726 else if (rflags & NFSV4OPEN_WRITEDELEGATE)
2727 *tl = txdr_unsigned(NFSV4OPEN_DELEGATEWRITE);
2729 *tl = txdr_unsigned(NFSV4OPEN_DELEGATENONE);
2730 if (rflags & (NFSV4OPEN_READDELEGATE|NFSV4OPEN_WRITEDELEGATE)) {
2731 NFSM_BUILD(tl, u_int32_t *, NFSX_STATEID+NFSX_UNSIGNED);
2732 *tl++ = txdr_unsigned(delegstateid.seqid);
2733 NFSBCOPY((caddr_t)delegstateid.other, (caddr_t)tl,
2735 tl += (NFSX_STATEIDOTHER / NFSX_UNSIGNED);
2736 if (rflags & NFSV4OPEN_RECALL)
2740 if (rflags & NFSV4OPEN_WRITEDELEGATE) {
2741 NFSM_BUILD(tl, u_int32_t *, 3 * NFSX_UNSIGNED);
2742 *tl++ = txdr_unsigned(NFSV4OPEN_LIMITSIZE);
2743 txdr_hyper(nva.na_size, tl);
2745 NFSM_BUILD(tl, u_int32_t *, 3 * NFSX_UNSIGNED);
2746 *tl++ = txdr_unsigned(NFSV4ACE_ALLOWEDTYPE);
2747 *tl++ = txdr_unsigned(0x0);
2748 acemask = NFSV4ACE_ALLFILESMASK;
2749 if (nva.na_mode & S_IRUSR)
2750 acemask |= NFSV4ACE_READMASK;
2751 if (nva.na_mode & S_IWUSR)
2752 acemask |= NFSV4ACE_WRITEMASK;
2753 if (nva.na_mode & S_IXUSR)
2754 acemask |= NFSV4ACE_EXECUTEMASK;
2755 *tl = txdr_unsigned(acemask);
2756 (void) nfsm_strtom(nd, "OWNER@", 6);
2764 #ifdef NFS4_ACL_EXTATTR_NAME
2770 #ifdef NFS4_ACL_EXTATTR_NAME
2774 FREE((caddr_t)stp, M_NFSDSTATE);
2779 * nfsv4 close service
2782 nfsrvd_close(struct nfsrv_descript *nd, __unused int isdgram,
2783 vnode_t vp, NFSPROC_T *p, __unused struct nfsexstuff *exp)
2786 struct nfsstate st, *stp = &st;
2788 nfsv4stateid_t stateid;
2791 NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED + NFSX_STATEID);
2792 stp->ls_seq = fxdr_unsigned(u_int32_t, *tl++);
2793 stp->ls_ownerlen = 0;
2794 stp->ls_op = nd->nd_rp;
2795 stp->ls_uid = nd->nd_cred->cr_uid;
2796 stp->ls_stateid.seqid = fxdr_unsigned(u_int32_t, *tl++);
2797 NFSBCOPY((caddr_t)tl, (caddr_t)stp->ls_stateid.other,
2799 stp->ls_flags = NFSLCK_CLOSE;
2800 clientid.lval[0] = stp->ls_stateid.other[0];
2801 clientid.lval[1] = stp->ls_stateid.other[1];
2802 if (nd->nd_flag & ND_IMPLIEDCLID) {
2803 if (nd->nd_clientid.qval != clientid.qval)
2804 printf("EEK! multiple clids\n");
2806 nd->nd_flag |= ND_IMPLIEDCLID;
2807 nd->nd_clientid.qval = clientid.qval;
2809 nd->nd_repstat = nfsrv_openupdate(vp, stp, clientid, &stateid, nd, p);
2811 if (!nd->nd_repstat) {
2812 NFSM_BUILD(tl, u_int32_t *, NFSX_STATEID);
2813 *tl++ = txdr_unsigned(stateid.seqid);
2814 NFSBCOPY((caddr_t)stateid.other,(caddr_t)tl,NFSX_STATEIDOTHER);
2823 * nfsv4 delegpurge service
2826 nfsrvd_delegpurge(struct nfsrv_descript *nd, __unused int isdgram,
2827 __unused vnode_t vp, __unused NFSPROC_T *p, __unused struct nfsexstuff *exp)
2833 if ((!nfs_rootfhset && !nfsv4root_set) ||
2834 nfsd_checkrootexp(nd)) {
2835 nd->nd_repstat = NFSERR_WRONGSEC;
2838 NFSM_DISSECT(tl, u_int32_t *, 2 * NFSX_UNSIGNED);
2839 clientid.lval[0] = *tl++;
2840 clientid.lval[1] = *tl;
2841 if (nd->nd_flag & ND_IMPLIEDCLID) {
2842 if (nd->nd_clientid.qval != clientid.qval)
2843 printf("EEK! multiple clids\n");
2845 nd->nd_flag |= ND_IMPLIEDCLID;
2846 nd->nd_clientid.qval = clientid.qval;
2848 nd->nd_repstat = nfsrv_delegupdate(clientid, NULL, NULL,
2849 NFSV4OP_DELEGPURGE, nd->nd_cred, p);
2855 * nfsv4 delegreturn service
2858 nfsrvd_delegreturn(struct nfsrv_descript *nd, __unused int isdgram,
2859 vnode_t vp, NFSPROC_T *p, __unused struct nfsexstuff *exp)
2863 nfsv4stateid_t stateid;
2866 NFSM_DISSECT(tl, u_int32_t *, NFSX_STATEID);
2867 stateid.seqid = fxdr_unsigned(u_int32_t, *tl++);
2868 NFSBCOPY((caddr_t)tl, (caddr_t)stateid.other, NFSX_STATEIDOTHER);
2869 clientid.lval[0] = stateid.other[0];
2870 clientid.lval[1] = stateid.other[1];
2871 if (nd->nd_flag & ND_IMPLIEDCLID) {
2872 if (nd->nd_clientid.qval != clientid.qval)
2873 printf("EEK! multiple clids\n");
2875 nd->nd_flag |= ND_IMPLIEDCLID;
2876 nd->nd_clientid.qval = clientid.qval;
2878 nd->nd_repstat = nfsrv_delegupdate(clientid, &stateid, vp,
2879 NFSV4OP_DELEGRETURN, nd->nd_cred, p);
2886 * nfsv4 get file handle service
2889 nfsrvd_getfh(struct nfsrv_descript *nd, __unused int isdgram,
2890 vnode_t vp, NFSPROC_T *p, __unused struct nfsexstuff *exp)
2894 nd->nd_repstat = nfsvno_getfh(vp, &fh, p);
2896 if (!nd->nd_repstat)
2897 (void) nfsm_fhtom(nd, (u_int8_t *)&fh, 0, 0);
2902 * nfsv4 open confirm service
2905 nfsrvd_openconfirm(struct nfsrv_descript *nd, __unused int isdgram,
2906 vnode_t vp, NFSPROC_T *p, __unused struct nfsexstuff *exp)
2909 struct nfsstate st, *stp = &st;
2911 nfsv4stateid_t stateid;
2914 NFSM_DISSECT(tl, u_int32_t *, NFSX_STATEID + NFSX_UNSIGNED);
2915 stp->ls_ownerlen = 0;
2916 stp->ls_op = nd->nd_rp;
2917 stp->ls_uid = nd->nd_cred->cr_uid;
2918 stp->ls_stateid.seqid = fxdr_unsigned(u_int32_t, *tl++);
2919 NFSBCOPY((caddr_t)tl, (caddr_t)stp->ls_stateid.other,
2921 tl += (NFSX_STATEIDOTHER / NFSX_UNSIGNED);
2922 stp->ls_seq = fxdr_unsigned(u_int32_t, *tl);
2923 stp->ls_flags = NFSLCK_CONFIRM;
2924 clientid.lval[0] = stp->ls_stateid.other[0];
2925 clientid.lval[1] = stp->ls_stateid.other[1];
2926 if (nd->nd_flag & ND_IMPLIEDCLID) {
2927 if (nd->nd_clientid.qval != clientid.qval)
2928 printf("EEK! multiple clids\n");
2930 nd->nd_flag |= ND_IMPLIEDCLID;
2931 nd->nd_clientid.qval = clientid.qval;
2933 nd->nd_repstat = nfsrv_openupdate(vp, stp, clientid, &stateid, nd, p);
2934 if (!nd->nd_repstat) {
2935 NFSM_BUILD(tl, u_int32_t *, NFSX_STATEID);
2936 *tl++ = txdr_unsigned(stateid.seqid);
2937 NFSBCOPY((caddr_t)stateid.other,(caddr_t)tl,NFSX_STATEIDOTHER);
2945 * nfsv4 open downgrade service
2948 nfsrvd_opendowngrade(struct nfsrv_descript *nd, __unused int isdgram,
2949 vnode_t vp, NFSPROC_T *p, __unused struct nfsexstuff *exp)
2953 struct nfsstate st, *stp = &st;
2955 nfsv4stateid_t stateid;
2958 NFSM_DISSECT(tl, u_int32_t *, NFSX_STATEID + 3 * NFSX_UNSIGNED);
2959 stp->ls_ownerlen = 0;
2960 stp->ls_op = nd->nd_rp;
2961 stp->ls_uid = nd->nd_cred->cr_uid;
2962 stp->ls_stateid.seqid = fxdr_unsigned(u_int32_t, *tl++);
2963 NFSBCOPY((caddr_t)tl, (caddr_t)stp->ls_stateid.other,
2965 tl += (NFSX_STATEIDOTHER / NFSX_UNSIGNED);
2966 stp->ls_seq = fxdr_unsigned(u_int32_t, *tl++);
2967 i = fxdr_unsigned(int, *tl++);
2969 case NFSV4OPEN_ACCESSREAD:
2970 stp->ls_flags = (NFSLCK_READACCESS | NFSLCK_DOWNGRADE);
2972 case NFSV4OPEN_ACCESSWRITE:
2973 stp->ls_flags = (NFSLCK_WRITEACCESS | NFSLCK_DOWNGRADE);
2975 case NFSV4OPEN_ACCESSBOTH:
2976 stp->ls_flags = (NFSLCK_READACCESS | NFSLCK_WRITEACCESS |
2980 nd->nd_repstat = NFSERR_BADXDR;
2982 i = fxdr_unsigned(int, *tl);
2984 case NFSV4OPEN_DENYNONE:
2986 case NFSV4OPEN_DENYREAD:
2987 stp->ls_flags |= NFSLCK_READDENY;
2989 case NFSV4OPEN_DENYWRITE:
2990 stp->ls_flags |= NFSLCK_WRITEDENY;
2992 case NFSV4OPEN_DENYBOTH:
2993 stp->ls_flags |= (NFSLCK_READDENY | NFSLCK_WRITEDENY);
2996 nd->nd_repstat = NFSERR_BADXDR;
2999 clientid.lval[0] = stp->ls_stateid.other[0];
3000 clientid.lval[1] = stp->ls_stateid.other[1];
3001 if (nd->nd_flag & ND_IMPLIEDCLID) {
3002 if (nd->nd_clientid.qval != clientid.qval)
3003 printf("EEK! multiple clids\n");
3005 nd->nd_flag |= ND_IMPLIEDCLID;
3006 nd->nd_clientid.qval = clientid.qval;
3008 if (!nd->nd_repstat)
3009 nd->nd_repstat = nfsrv_openupdate(vp, stp, clientid, &stateid,
3011 if (!nd->nd_repstat) {
3012 NFSM_BUILD(tl, u_int32_t *, NFSX_STATEID);
3013 *tl++ = txdr_unsigned(stateid.seqid);
3014 NFSBCOPY((caddr_t)stateid.other,(caddr_t)tl,NFSX_STATEIDOTHER);
3022 * nfsv4 renew lease service
3025 nfsrvd_renew(struct nfsrv_descript *nd, __unused int isdgram,
3026 __unused vnode_t vp, NFSPROC_T *p, __unused struct nfsexstuff *exp)
3032 if ((!nfs_rootfhset && !nfsv4root_set) ||
3033 nfsd_checkrootexp(nd)) {
3034 nd->nd_repstat = NFSERR_WRONGSEC;
3037 NFSM_DISSECT(tl, u_int32_t *, NFSX_HYPER);
3038 clientid.lval[0] = *tl++;
3039 clientid.lval[1] = *tl;
3040 if (nd->nd_flag & ND_IMPLIEDCLID) {
3041 if (nd->nd_clientid.qval != clientid.qval)
3042 printf("EEK! multiple clids\n");
3044 nd->nd_flag |= ND_IMPLIEDCLID;
3045 nd->nd_clientid.qval = clientid.qval;
3047 nd->nd_repstat = nfsrv_getclient(clientid, (CLOPS_RENEWOP|CLOPS_RENEW),
3048 NULL, (nfsquad_t)((u_quad_t)0), nd, p);
3054 * nfsv4 security info service
3057 nfsrvd_secinfo(struct nfsrv_descript *nd, int isdgram,
3058 vnode_t dp, NFSPROC_T *p, struct nfsexstuff *exp)
3062 struct nameidata named;
3063 vnode_t dirp = NULL, vp;
3065 struct nfsexstuff retnes;
3068 int error, savflag, i;
3073 * All this just to get the export flags for the name.
3075 NFSNAMEICNDSET(&named.ni_cnd, nd->nd_cred, LOOKUP,
3076 LOCKLEAF | SAVESTART);
3077 nfsvno_setpathbuf(&named, &bufp, &hashp);
3078 error = nfsrv_parsename(nd, bufp, hashp, &named.ni_pathlen);
3081 nfsvno_relpathbuf(&named);
3084 if (!nd->nd_repstat) {
3085 nd->nd_repstat = nfsvno_namei(nd, &named, dp, 1, exp, p, &dirp);
3088 nfsvno_relpathbuf(&named);
3094 vrele(named.ni_startdir);
3095 nfsvno_relpathbuf(&named);
3096 fh.nfsrvfh_len = NFSX_MYFH;
3098 nd->nd_repstat = nfsvno_getfh(vp, (fhandle_t *)fh.nfsrvfh_data, p);
3099 mp = vnode_mount(vp); /* so it won't try to re-lock filesys */
3100 retnes.nes_vfslocked = exp->nes_vfslocked;
3102 savflag = nd->nd_flag;
3103 if (!nd->nd_repstat) {
3104 nfsd_fhtovp(nd, &fh, &vp, &retnes, &mp, 0, p);
3108 nd->nd_flag = savflag;
3113 * Finally have the export flags for name, so we can create
3114 * the security info.
3117 NFSM_BUILD(sizp, u_int32_t *, NFSX_UNSIGNED);
3118 for (i = 0; i < retnes.nes_numsecflavor; i++) {
3119 if (retnes.nes_secflavors[i] == AUTH_SYS) {
3120 NFSM_BUILD(tl, u_int32_t *, NFSX_UNSIGNED);
3121 *tl = txdr_unsigned(RPCAUTH_UNIX);
3123 } else if (retnes.nes_secflavors[i] == RPCSEC_GSS_KRB5) {
3124 NFSM_BUILD(tl, u_int32_t *, NFSX_UNSIGNED);
3125 *tl++ = txdr_unsigned(RPCAUTH_GSS);
3126 (void) nfsm_strtom(nd, nfsgss_mechlist[KERBV_MECH].str,
3127 nfsgss_mechlist[KERBV_MECH].len);
3128 NFSM_BUILD(tl, u_int32_t *, 2 * NFSX_UNSIGNED);
3129 *tl++ = txdr_unsigned(GSS_KERBV_QOP);
3130 *tl = txdr_unsigned(RPCAUTHGSS_SVCNONE);
3132 } else if (retnes.nes_secflavors[i] == RPCSEC_GSS_KRB5I) {
3133 NFSM_BUILD(tl, u_int32_t *, NFSX_UNSIGNED);
3134 *tl++ = txdr_unsigned(RPCAUTH_GSS);
3135 (void) nfsm_strtom(nd, nfsgss_mechlist[KERBV_MECH].str,
3136 nfsgss_mechlist[KERBV_MECH].len);
3137 NFSM_BUILD(tl, u_int32_t *, 2 * NFSX_UNSIGNED);
3138 *tl++ = txdr_unsigned(GSS_KERBV_QOP);
3139 *tl = txdr_unsigned(RPCAUTHGSS_SVCINTEGRITY);
3141 } else if (retnes.nes_secflavors[i] == RPCSEC_GSS_KRB5P) {
3142 NFSM_BUILD(tl, u_int32_t *, NFSX_UNSIGNED);
3143 *tl++ = txdr_unsigned(RPCAUTH_GSS);
3144 (void) nfsm_strtom(nd, nfsgss_mechlist[KERBV_MECH].str,
3145 nfsgss_mechlist[KERBV_MECH].len);
3146 NFSM_BUILD(tl, u_int32_t *, 2 * NFSX_UNSIGNED);
3147 *tl++ = txdr_unsigned(GSS_KERBV_QOP);
3148 *tl = txdr_unsigned(RPCAUTHGSS_SVCPRIVACY);
3152 *sizp = txdr_unsigned(len);
3157 * nfsv4 set client id service
3160 nfsrvd_setclientid(struct nfsrv_descript *nd, __unused int isdgram,
3161 __unused vnode_t vp, NFSPROC_T *p, __unused struct nfsexstuff *exp)
3165 int error = 0, idlen;
3166 struct nfsclient *clp = NULL;
3167 struct sockaddr_in *rad;
3168 u_char *verf, *ucp, *ucp2, addrbuf[24];
3169 nfsquad_t clientid, confirm;
3171 if ((!nfs_rootfhset && !nfsv4root_set) ||
3172 nfsd_checkrootexp(nd)) {
3173 nd->nd_repstat = NFSERR_WRONGSEC;
3176 NFSM_DISSECT(tl, u_int32_t *, NFSX_VERF + NFSX_UNSIGNED);
3177 verf = (u_char *)tl;
3178 tl += (NFSX_VERF / NFSX_UNSIGNED);
3179 i = fxdr_unsigned(int, *tl);
3180 if (i > NFSV4_OPAQUELIMIT || i <= 0) {
3181 nd->nd_repstat = NFSERR_BADXDR;
3185 if (nd->nd_flag & ND_GSS)
3186 i += nd->nd_princlen;
3187 MALLOC(clp, struct nfsclient *, sizeof (struct nfsclient) + i,
3188 M_NFSDCLIENT, M_WAITOK);
3189 NFSBZERO((caddr_t)clp, sizeof (struct nfsclient) + i);
3190 NFSINITSOCKMUTEX(&clp->lc_req.nr_mtx);
3191 NFSSOCKADDRALLOC(clp->lc_req.nr_nam);
3192 NFSSOCKADDRSIZE(clp->lc_req.nr_nam, sizeof (struct sockaddr_in));
3193 clp->lc_req.nr_cred = NULL;
3194 NFSBCOPY(verf, clp->lc_verf, NFSX_VERF);
3195 clp->lc_idlen = idlen;
3196 error = nfsrv_mtostr(nd, clp->lc_id, idlen);
3199 if (nd->nd_flag & ND_GSS) {
3200 clp->lc_flags = LCL_GSS;
3201 if (nd->nd_flag & ND_GSSINTEGRITY)
3202 clp->lc_flags |= LCL_GSSINTEGRITY;
3203 else if (nd->nd_flag & ND_GSSPRIVACY)
3204 clp->lc_flags |= LCL_GSSPRIVACY;
3208 if ((nd->nd_flag & ND_GSS) && nd->nd_princlen > 0) {
3209 clp->lc_flags |= LCL_NAME;
3210 clp->lc_namelen = nd->nd_princlen;
3211 clp->lc_name = &clp->lc_id[idlen];
3212 NFSBCOPY(nd->nd_principal, clp->lc_name, clp->lc_namelen);
3214 clp->lc_uid = nd->nd_cred->cr_uid;
3215 clp->lc_gid = nd->nd_cred->cr_gid;
3217 NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
3218 clp->lc_program = fxdr_unsigned(u_int32_t, *tl);
3219 error = nfsrv_getclientipaddr(nd, clp);
3222 NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
3223 clp->lc_callback = fxdr_unsigned(u_int32_t, *tl);
3226 * nfsrv_setclient() does the actual work of adding it to the
3227 * client list. If there is no error, the structure has been
3228 * linked into the client list and clp should no longer be used
3229 * here. When an error is returned, it has not been linked in,
3230 * so it should be free'd.
3232 nd->nd_repstat = nfsrv_setclient(nd, &clp, &clientid, &confirm, p);
3233 if (nd->nd_repstat == NFSERR_CLIDINUSE) {
3234 if (clp->lc_flags & LCL_TCPCALLBACK)
3235 (void) nfsm_strtom(nd, "tcp", 3);
3237 (void) nfsm_strtom(nd, "udp", 3);
3238 rad = NFSSOCKADDR(clp->lc_req.nr_nam, struct sockaddr_in *);
3239 ucp = (u_char *)&rad->sin_addr.s_addr;
3240 ucp2 = (u_char *)&rad->sin_port;
3241 sprintf(addrbuf, "%d.%d.%d.%d.%d.%d", ucp[0] & 0xff,
3242 ucp[1] & 0xff, ucp[2] & 0xff, ucp[3] & 0xff,
3243 ucp2[0] & 0xff, ucp2[1] & 0xff);
3244 (void) nfsm_strtom(nd, addrbuf, strlen(addrbuf));
3247 NFSSOCKADDRFREE(clp->lc_req.nr_nam);
3248 NFSFREEMUTEX(&clp->lc_req.nr_mtx);
3249 free((caddr_t)clp, M_NFSDCLIENT);
3251 if (!nd->nd_repstat) {
3252 NFSM_BUILD(tl, u_int32_t *, 2 * NFSX_HYPER);
3253 *tl++ = clientid.lval[0];
3254 *tl++ = clientid.lval[1];
3255 *tl++ = confirm.lval[0];
3256 *tl = confirm.lval[1];
3261 NFSSOCKADDRFREE(clp->lc_req.nr_nam);
3262 NFSFREEMUTEX(&clp->lc_req.nr_mtx);
3263 free((caddr_t)clp, M_NFSDCLIENT);
3269 * nfsv4 set client id confirm service
3272 nfsrvd_setclientidcfrm(struct nfsrv_descript *nd,
3273 __unused int isdgram, __unused vnode_t vp, NFSPROC_T *p,
3274 __unused struct nfsexstuff *exp)
3278 nfsquad_t clientid, confirm;
3280 if ((!nfs_rootfhset && !nfsv4root_set) ||
3281 nfsd_checkrootexp(nd)) {
3282 nd->nd_repstat = NFSERR_WRONGSEC;
3285 NFSM_DISSECT(tl, u_int32_t *, 2 * NFSX_HYPER);
3286 clientid.lval[0] = *tl++;
3287 clientid.lval[1] = *tl++;
3288 confirm.lval[0] = *tl++;
3289 confirm.lval[1] = *tl;
3292 * nfsrv_getclient() searches the client list for a match and
3293 * returns the appropriate NFSERR status.
3295 nd->nd_repstat = nfsrv_getclient(clientid, (CLOPS_CONFIRM|CLOPS_RENEW),
3296 NULL, confirm, nd, p);
3302 * nfsv4 verify service
3305 nfsrvd_verify(struct nfsrv_descript *nd, int isdgram,
3306 vnode_t vp, NFSPROC_T *p, __unused struct nfsexstuff *exp)
3308 int error = 0, ret, fhsize = NFSX_MYFH;
3309 struct nfsvattr nva;
3311 struct nfsfsinfo fs;
3314 nd->nd_repstat = nfsvno_getattr(vp, &nva, nd->nd_cred, p);
3315 if (!nd->nd_repstat)
3316 nd->nd_repstat = nfsvno_statfs(vp, &sf);
3317 if (!nd->nd_repstat)
3318 nd->nd_repstat = nfsvno_getfh(vp, &fh, p);
3319 if (!nd->nd_repstat) {
3320 nfsvno_getfs(&fs, isdgram);
3321 error = nfsv4_loadattr(nd, vp, &nva, NULL, &fh, fhsize, NULL,
3322 &sf, NULL, &fs, NULL, 1, &ret, NULL, NULL, p, nd->nd_cred);
3324 if (nd->nd_procnum == NFSV4OP_NVERIFY) {
3326 nd->nd_repstat = NFSERR_SAME;
3327 else if (ret != NFSERR_NOTSAME)
3328 nd->nd_repstat = ret;
3330 nd->nd_repstat = ret;
3341 nfsrvd_openattr(struct nfsrv_descript *nd, __unused int isdgram,
3342 vnode_t dp, __unused vnode_t *vpp, __unused fhandle_t *fhp,
3343 __unused NFSPROC_T *p, __unused struct nfsexstuff *exp)
3346 int error = 0, createdir;
3348 NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
3349 createdir = fxdr_unsigned(int, *tl);
3350 nd->nd_repstat = NFSERR_NOTSUPP;
3357 * nfsv4 release lock owner service
3360 nfsrvd_releaselckown(struct nfsrv_descript *nd, __unused int isdgram,
3361 __unused vnode_t vp, NFSPROC_T *p, __unused struct nfsexstuff *exp)
3364 struct nfsstate *stp = NULL;
3368 if ((!nfs_rootfhset && !nfsv4root_set) ||
3369 nfsd_checkrootexp(nd)) {
3370 nd->nd_repstat = NFSERR_WRONGSEC;
3373 NFSM_DISSECT(tl, u_int32_t *, 3 * NFSX_UNSIGNED);
3374 len = fxdr_unsigned(int, *(tl + 2));
3375 MALLOC(stp, struct nfsstate *, sizeof (struct nfsstate) + len,
3376 M_NFSDSTATE, M_WAITOK);
3377 stp->ls_ownerlen = len;
3379 stp->ls_flags = NFSLCK_RELEASE;
3380 stp->ls_uid = nd->nd_cred->cr_uid;
3381 clientid.lval[0] = *tl++;
3382 clientid.lval[1] = *tl;
3383 if (nd->nd_flag & ND_IMPLIEDCLID) {
3384 if (nd->nd_clientid.qval != clientid.qval)
3385 printf("EEK! multiple clids\n");
3387 nd->nd_flag |= ND_IMPLIEDCLID;
3388 nd->nd_clientid.qval = clientid.qval;
3390 error = nfsrv_mtostr(nd, stp->ls_owner, len);
3393 nd->nd_repstat = nfsrv_releaselckown(stp, clientid, p);
3394 FREE((caddr_t)stp, M_NFSDSTATE);
3398 free((caddr_t)stp, M_NFSDSTATE);