nfs_nfsiod.c revision 44078
1156287Srwatson/* 2156287Srwatson * Copyright (c) 1989, 1993 3156287Srwatson * The Regents of the University of California. All rights reserved. 4156287Srwatson * 5156287Srwatson * This code is derived from software contributed to Berkeley by 6156287Srwatson * Rick Macklem at The University of Guelph. 7156287Srwatson * 8156287Srwatson * Redistribution and use in source and binary forms, with or without 9156287Srwatson * modification, are permitted provided that the following conditions 10156287Srwatson * are met: 11156287Srwatson * 1. Redistributions of source code must retain the above copyright 12156287Srwatson * notice, this list of conditions and the following disclaimer. 13156287Srwatson * 2. Redistributions in binary form must reproduce the above copyright 14156287Srwatson * notice, this list of conditions and the following disclaimer in the 15156287Srwatson * documentation and/or other materials provided with the distribution. 16156287Srwatson * 3. All advertising materials mentioning features or use of this software 17156287Srwatson * must display the following acknowledgement: 18156287Srwatson * This product includes software developed by the University of 19156287Srwatson * California, Berkeley and its contributors. 20156287Srwatson * 4. Neither the name of the University nor the names of its contributors 21156287Srwatson * may be used to endorse or promote products derived from this software 22156287Srwatson * without specific prior written permission. 23156287Srwatson * 24156287Srwatson * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 25156287Srwatson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26156287Srwatson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27156287Srwatson * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 28156287Srwatson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29156287Srwatson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30156287Srwatson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31156287Srwatson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32156287Srwatson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33156287Srwatson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34156287Srwatson * SUCH DAMAGE. 35156287Srwatson * 36156287Srwatson * @(#)nfs_syscalls.c 8.5 (Berkeley) 3/30/95 37156287Srwatson * $Id: nfs_syscalls.c,v 1.45 1999/01/27 22:42:27 dillon Exp $ 38156287Srwatson */ 39156287Srwatson 40156287Srwatson#include <sys/param.h> 41156287Srwatson#include <sys/systm.h> 42156287Srwatson#include <sys/sysproto.h> 43156287Srwatson#include <sys/kernel.h> 44156287Srwatson#include <sys/sysctl.h> 45156287Srwatson#include <sys/file.h> 46156287Srwatson#include <sys/filedesc.h> 47156287Srwatson#include <sys/vnode.h> 48156287Srwatson#include <sys/malloc.h> 49156287Srwatson#include <sys/mount.h> 50156287Srwatson#include <sys/proc.h> 51156287Srwatson#include <sys/buf.h> 52156287Srwatson#include <sys/mbuf.h> 53156287Srwatson#include <sys/socket.h> 54156287Srwatson#include <sys/socketvar.h> 55156287Srwatson#include <sys/domain.h> 56156287Srwatson#include <sys/protosw.h> 57156287Srwatson#include <sys/namei.h> 58156287Srwatson 59156287Srwatson#include <netinet/in.h> 60156287Srwatson#include <netinet/tcp.h> 61156287Srwatson#ifdef ISO 62156287Srwatson#include <netiso/iso.h> 63156287Srwatson#endif 64156287Srwatson#include <nfs/xdr_subs.h> 65156287Srwatson#include <nfs/rpcv2.h> 66156287Srwatson#include <nfs/nfsproto.h> 67156287Srwatson#include <nfs/nfs.h> 68156287Srwatson#include <nfs/nfsm_subs.h> 69156287Srwatson#include <nfs/nfsrvcache.h> 70156287Srwatson#include <nfs/nfsmount.h> 71156287Srwatson#include <nfs/nfsnode.h> 72156287Srwatson#include <nfs/nqnfs.h> 73156287Srwatson#include <nfs/nfsrtt.h> 74156287Srwatson 75156287Srwatsonstatic MALLOC_DEFINE(M_NFSSVC, "NFS srvsock", "Nfs server structure"); 76156287Srwatson 77156287Srwatson/* Global defs. */ 78156287Srwatsonextern int32_t (*nfsrv3_procs[NFS_NPROCS]) __P((struct nfsrv_descript *nd, 79156287Srwatson struct nfssvc_sock *slp, 80156287Srwatson struct proc *procp, 81156287Srwatson struct mbuf **mreqp)); 82156287Srwatsonextern int nfs_numasync; 83156287Srwatsonextern time_t nqnfsstarttime; 84156287Srwatsonextern int nqsrv_writeslack; 85156287Srwatsonextern int nfsrtton; 86156287Srwatsonextern struct nfsstats nfsstats; 87156287Srwatsonextern int nfsrvw_procrastinate; 88156287Srwatsonextern int nfsrvw_procrastinate_v3; 89156287Srwatsonstruct nfssvc_sock *nfs_udpsock, *nfs_cltpsock; 90156287Srwatsonstatic int nuidhash_max = NFS_MAXUIDHASH; 91156287Srwatson 92156287Srwatsonstatic void nfsrv_zapsock __P((struct nfssvc_sock *slp)); 93156287Srwatsonstatic int nfssvc_iod __P((struct proc *)); 94156287Srwatson 95156287Srwatson#define TRUE 1 96156287Srwatson#define FALSE 0 97156287Srwatson 98156287Srwatsonstatic int nfs_asyncdaemon[NFS_MAXASYNCDAEMON]; 99156287Srwatson 100156287Srwatson#ifndef NFS_NOSERVER 101156287Srwatsonint nfsd_waiting = 0; 102156287Srwatsonstatic struct nfsdrt nfsdrt; 103156287Srwatsonstatic int nfs_numnfsd = 0; 104156287Srwatsonstatic int notstarted = 1; 105156287Srwatsonstatic int modify_flag = 0; 106156287Srwatsonstatic void nfsd_rt __P((int sotype, struct nfsrv_descript *nd, 107156287Srwatson int cacherep)); 108156287Srwatsonstatic int nfssvc_addsock __P((struct file *, struct sockaddr *, 109156287Srwatson struct proc *)); 110156287Srwatsonstatic int nfssvc_nfsd __P((struct nfsd_srvargs *,caddr_t,struct proc *)); 111156287Srwatson 112156287SrwatsonSYSCTL_DECL(_vfs_nfs); 113156287Srwatson 114156287Srwatsonstatic int nfs_privport = 0; 115156287SrwatsonSYSCTL_INT(_vfs_nfs, NFS_NFSPRIVPORT, nfs_privport, CTLFLAG_RW, &nfs_privport, 0, ""); 116156287SrwatsonSYSCTL_INT(_vfs_nfs, OID_AUTO, gatherdelay, CTLFLAG_RW, &nfsrvw_procrastinate, 0, ""); 117156287SrwatsonSYSCTL_INT(_vfs_nfs, OID_AUTO, gatherdelay_v3, CTLFLAG_RW, &nfsrvw_procrastinate_v3, 0, ""); 118156287Srwatson 119156287Srwatson/* 120156287Srwatson * NFS server system calls 121156287Srwatson * getfh() lives here too, but maybe should move to kern/vfs_syscalls.c 122156287Srwatson */ 123156287Srwatson 124156287Srwatson/* 125156287Srwatson * Get file handle system call 126156287Srwatson */ 127156287Srwatson#ifndef _SYS_SYSPROTO_H_ 128156287Srwatsonstruct getfh_args { 129156287Srwatson char *fname; 130156287Srwatson fhandle_t *fhp; 131156287Srwatson}; 132156287Srwatson#endif 133156287Srwatsonint 134156287Srwatsongetfh(p, uap) 135156287Srwatson struct proc *p; 136156287Srwatson register struct getfh_args *uap; 137156287Srwatson{ 138156287Srwatson register struct vnode *vp; 139156287Srwatson fhandle_t fh; 140156287Srwatson int error; 141156287Srwatson struct nameidata nd; 142156287Srwatson 143156287Srwatson /* 144156287Srwatson * Must be super user 145156287Srwatson */ 146156287Srwatson error = suser(p->p_ucred, &p->p_acflag); 147156287Srwatson if(error) 148156287Srwatson return (error); 149156287Srwatson NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_USERSPACE, uap->fname, p); 150156287Srwatson error = namei(&nd); 151156287Srwatson if (error) 152156287Srwatson return (error); 153156287Srwatson vp = nd.ni_vp; 154156287Srwatson bzero((caddr_t)&fh, sizeof(fh)); 155156287Srwatson fh.fh_fsid = vp->v_mount->mnt_stat.f_fsid; 156156287Srwatson error = VFS_VPTOFH(vp, &fh.fh_fid); 157156287Srwatson vput(vp); 158156287Srwatson if (error) 159156287Srwatson return (error); 160156287Srwatson error = copyout((caddr_t)&fh, (caddr_t)uap->fhp, sizeof (fh)); 161156287Srwatson return (error); 162156287Srwatson} 163156287Srwatson 164156287Srwatson#endif /* NFS_NOSERVER */ 165156287Srwatson/* 166156287Srwatson * Nfs server psuedo system call for the nfsd's 167156287Srwatson * Based on the flag value it either: 168156287Srwatson * - adds a socket to the selection list 169156287Srwatson * - remains in the kernel as an nfsd 170156287Srwatson * - remains in the kernel as an nfsiod 171156287Srwatson */ 172156287Srwatson#ifndef _SYS_SYSPROTO_H_ 173156287Srwatsonstruct nfssvc_args { 174156287Srwatson int flag; 175156287Srwatson caddr_t argp; 176156287Srwatson}; 177156287Srwatson#endif 178156287Srwatsonint 179156287Srwatsonnfssvc(p, uap) 180156287Srwatson struct proc *p; 181156287Srwatson register struct nfssvc_args *uap; 182156287Srwatson{ 183156287Srwatson#ifndef NFS_NOSERVER 184156287Srwatson struct nameidata nd; 185156287Srwatson struct file *fp; 186156287Srwatson struct sockaddr *nam; 187156287Srwatson struct nfsd_args nfsdarg; 188156287Srwatson struct nfsd_srvargs nfsd_srvargs, *nsd = &nfsd_srvargs; 189156287Srwatson struct nfsd_cargs ncd; 190156287Srwatson struct nfsd *nfsd; 191156287Srwatson struct nfssvc_sock *slp; 192156287Srwatson struct nfsuid *nuidp; 193 struct nfsmount *nmp; 194#endif /* NFS_NOSERVER */ 195 int error; 196 197 /* 198 * Must be super user 199 */ 200 error = suser(p->p_ucred, &p->p_acflag); 201 if(error) 202 return (error); 203 while (nfssvc_sockhead_flag & SLP_INIT) { 204 nfssvc_sockhead_flag |= SLP_WANTINIT; 205 (void) tsleep((caddr_t)&nfssvc_sockhead, PSOCK, "nfsd init", 0); 206 } 207 if (uap->flag & NFSSVC_BIOD) 208 error = nfssvc_iod(p); 209#ifdef NFS_NOSERVER 210 else 211 error = ENXIO; 212#else /* !NFS_NOSERVER */ 213 else if (uap->flag & NFSSVC_MNTD) { 214 error = copyin(uap->argp, (caddr_t)&ncd, sizeof (ncd)); 215 if (error) 216 return (error); 217 NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_USERSPACE, 218 ncd.ncd_dirp, p); 219 error = namei(&nd); 220 if (error) 221 return (error); 222 if ((nd.ni_vp->v_flag & VROOT) == 0) 223 error = EINVAL; 224 nmp = VFSTONFS(nd.ni_vp->v_mount); 225 vput(nd.ni_vp); 226 if (error) 227 return (error); 228 if ((nmp->nm_state & NFSSTA_MNTD) && 229 (uap->flag & NFSSVC_GOTAUTH) == 0) 230 return (0); 231 nmp->nm_state |= NFSSTA_MNTD; 232 error = nqnfs_clientd(nmp, p->p_ucred, &ncd, uap->flag, 233 uap->argp, p); 234 } else if (uap->flag & NFSSVC_ADDSOCK) { 235 error = copyin(uap->argp, (caddr_t)&nfsdarg, sizeof(nfsdarg)); 236 if (error) 237 return (error); 238 error = getsock(p->p_fd, nfsdarg.sock, &fp); 239 if (error) 240 return (error); 241 /* 242 * Get the client address for connected sockets. 243 */ 244 if (nfsdarg.name == NULL || nfsdarg.namelen == 0) 245 nam = (struct sockaddr *)0; 246 else { 247 error = getsockaddr(&nam, nfsdarg.name, 248 nfsdarg.namelen); 249 if (error) 250 return (error); 251 } 252 error = nfssvc_addsock(fp, nam, p); 253 } else { 254 error = copyin(uap->argp, (caddr_t)nsd, sizeof (*nsd)); 255 if (error) 256 return (error); 257 if ((uap->flag & NFSSVC_AUTHIN) && 258 ((nfsd = nsd->nsd_nfsd)) != NULL && 259 (nfsd->nfsd_slp->ns_flag & SLP_VALID)) { 260 slp = nfsd->nfsd_slp; 261 262 /* 263 * First check to see if another nfsd has already 264 * added this credential. 265 */ 266 for (nuidp = NUIDHASH(slp,nsd->nsd_cr.cr_uid)->lh_first; 267 nuidp != 0; nuidp = nuidp->nu_hash.le_next) { 268 if (nuidp->nu_cr.cr_uid == nsd->nsd_cr.cr_uid && 269 (!nfsd->nfsd_nd->nd_nam2 || 270 netaddr_match(NU_NETFAM(nuidp), 271 &nuidp->nu_haddr, nfsd->nfsd_nd->nd_nam2))) 272 break; 273 } 274 if (nuidp) { 275 nfsrv_setcred(&nuidp->nu_cr,&nfsd->nfsd_nd->nd_cr); 276 nfsd->nfsd_nd->nd_flag |= ND_KERBFULL; 277 } else { 278 /* 279 * Nope, so we will. 280 */ 281 if (slp->ns_numuids < nuidhash_max) { 282 slp->ns_numuids++; 283 nuidp = (struct nfsuid *) 284 malloc(sizeof (struct nfsuid), M_NFSUID, 285 M_WAITOK); 286 } else 287 nuidp = (struct nfsuid *)0; 288 if ((slp->ns_flag & SLP_VALID) == 0) { 289 if (nuidp) 290 free((caddr_t)nuidp, M_NFSUID); 291 } else { 292 if (nuidp == (struct nfsuid *)0) { 293 nuidp = slp->ns_uidlruhead.tqh_first; 294 LIST_REMOVE(nuidp, nu_hash); 295 TAILQ_REMOVE(&slp->ns_uidlruhead, nuidp, 296 nu_lru); 297 if (nuidp->nu_flag & NU_NAM) 298 FREE(nuidp->nu_nam, M_SONAME); 299 } 300 nuidp->nu_flag = 0; 301 nuidp->nu_cr = nsd->nsd_cr; 302 if (nuidp->nu_cr.cr_ngroups > NGROUPS) 303 nuidp->nu_cr.cr_ngroups = NGROUPS; 304 nuidp->nu_cr.cr_ref = 1; 305 nuidp->nu_timestamp = nsd->nsd_timestamp; 306 nuidp->nu_expire = time_second + nsd->nsd_ttl; 307 /* 308 * and save the session key in nu_key. 309 */ 310 bcopy(nsd->nsd_key, nuidp->nu_key, 311 sizeof (nsd->nsd_key)); 312 if (nfsd->nfsd_nd->nd_nam2) { 313 struct sockaddr_in *saddr; 314 315 saddr = (struct sockaddr_in *) 316 nfsd->nfsd_nd->nd_nam2; 317 switch (saddr->sin_family) { 318 case AF_INET: 319 nuidp->nu_flag |= NU_INETADDR; 320 nuidp->nu_inetaddr = 321 saddr->sin_addr.s_addr; 322 break; 323 case AF_ISO: 324 default: 325 nuidp->nu_flag |= NU_NAM; 326 nuidp->nu_nam = 327 dup_sockaddr(nfsd->nfsd_nd-> 328 nd_nam2, 1); 329 break; 330 }; 331 } 332 TAILQ_INSERT_TAIL(&slp->ns_uidlruhead, nuidp, 333 nu_lru); 334 LIST_INSERT_HEAD(NUIDHASH(slp, nsd->nsd_uid), 335 nuidp, nu_hash); 336 nfsrv_setcred(&nuidp->nu_cr, 337 &nfsd->nfsd_nd->nd_cr); 338 nfsd->nfsd_nd->nd_flag |= ND_KERBFULL; 339 } 340 } 341 } 342 if ((uap->flag & NFSSVC_AUTHINFAIL) && (nfsd = nsd->nsd_nfsd)) 343 nfsd->nfsd_flag |= NFSD_AUTHFAIL; 344 error = nfssvc_nfsd(nsd, uap->argp, p); 345 } 346#endif /* NFS_NOSERVER */ 347 if (error == EINTR || error == ERESTART) 348 error = 0; 349 return (error); 350} 351 352#ifndef NFS_NOSERVER 353/* 354 * Adds a socket to the list for servicing by nfsds. 355 */ 356static int 357nfssvc_addsock(fp, mynam, p) 358 struct file *fp; 359 struct sockaddr *mynam; 360 struct proc *p; 361{ 362 register int siz; 363 register struct nfssvc_sock *slp; 364 register struct socket *so; 365 struct nfssvc_sock *tslp; 366 int error, s; 367 368 so = (struct socket *)fp->f_data; 369 tslp = (struct nfssvc_sock *)0; 370 /* 371 * Add it to the list, as required. 372 */ 373 if (so->so_proto->pr_protocol == IPPROTO_UDP) { 374 tslp = nfs_udpsock; 375 if (tslp->ns_flag & SLP_VALID) { 376 FREE(mynam, M_SONAME); 377 return (EPERM); 378 } 379#ifdef ISO 380 } else if (so->so_proto->pr_protocol == ISOPROTO_CLTP) { 381 tslp = nfs_cltpsock; 382 if (tslp->ns_flag & SLP_VALID) { 383 FREE(mynam, M_SONAME); 384 return (EPERM); 385 } 386#endif /* ISO */ 387 } 388 if (so->so_type == SOCK_STREAM) 389 siz = NFS_MAXPACKET + sizeof (u_long); 390 else 391 siz = NFS_MAXPACKET; 392 error = soreserve(so, siz, siz); 393 if (error) { 394 FREE(mynam, M_SONAME); 395 return (error); 396 } 397 398 /* 399 * Set protocol specific options { for now TCP only } and 400 * reserve some space. For datagram sockets, this can get called 401 * repeatedly for the same socket, but that isn't harmful. 402 */ 403 if (so->so_type == SOCK_STREAM) { 404 struct sockopt sopt; 405 int val; 406 407 bzero(&sopt, sizeof sopt); 408 sopt.sopt_level = SOL_SOCKET; 409 sopt.sopt_name = SO_KEEPALIVE; 410 sopt.sopt_val = &val; 411 sopt.sopt_valsize = sizeof val; 412 val = 1; 413 sosetopt(so, &sopt); 414 } 415 if (so->so_proto->pr_domain->dom_family == AF_INET && 416 so->so_proto->pr_protocol == IPPROTO_TCP) { 417 struct sockopt sopt; 418 int val; 419 420 bzero(&sopt, sizeof sopt); 421 sopt.sopt_level = IPPROTO_TCP; 422 sopt.sopt_name = TCP_NODELAY; 423 sopt.sopt_val = &val; 424 sopt.sopt_valsize = sizeof val; 425 val = 1; 426 sosetopt(so, &sopt); 427 } 428 so->so_rcv.sb_flags &= ~SB_NOINTR; 429 so->so_rcv.sb_timeo = 0; 430 so->so_snd.sb_flags &= ~SB_NOINTR; 431 so->so_snd.sb_timeo = 0; 432 if (tslp) 433 slp = tslp; 434 else { 435 slp = (struct nfssvc_sock *) 436 malloc(sizeof (struct nfssvc_sock), M_NFSSVC, M_WAITOK); 437 bzero((caddr_t)slp, sizeof (struct nfssvc_sock)); 438 STAILQ_INIT(&slp->ns_rec); 439 TAILQ_INIT(&slp->ns_uidlruhead); 440 TAILQ_INSERT_TAIL(&nfssvc_sockhead, slp, ns_chain); 441 } 442 slp->ns_so = so; 443 slp->ns_nam = mynam; 444 fp->f_count++; 445 slp->ns_fp = fp; 446 s = splnet(); 447 so->so_upcallarg = (caddr_t)slp; 448 so->so_upcall = nfsrv_rcv; 449 so->so_rcv.sb_flags |= SB_UPCALL; 450 slp->ns_flag = (SLP_VALID | SLP_NEEDQ); 451 nfsrv_wakenfsd(slp); 452 splx(s); 453 return (0); 454} 455 456/* 457 * Called by nfssvc() for nfsds. Just loops around servicing rpc requests 458 * until it is killed by a signal. 459 */ 460static int 461nfssvc_nfsd(nsd, argp, p) 462 struct nfsd_srvargs *nsd; 463 caddr_t argp; 464 struct proc *p; 465{ 466 register struct mbuf *m; 467 register int siz; 468 register struct nfssvc_sock *slp; 469 register struct socket *so; 470 register int *solockp; 471 struct nfsd *nfsd = nsd->nsd_nfsd; 472 struct nfsrv_descript *nd = NULL; 473 struct mbuf *mreq; 474 int error = 0, cacherep, s, sotype, writes_todo; 475 int procrastinate; 476 u_quad_t cur_usec; 477 478#ifndef nolint 479 cacherep = RC_DOIT; 480 writes_todo = 0; 481#endif 482 if (nfsd == (struct nfsd *)0) { 483 nsd->nsd_nfsd = nfsd = (struct nfsd *) 484 malloc(sizeof (struct nfsd), M_NFSD, M_WAITOK); 485 bzero((caddr_t)nfsd, sizeof (struct nfsd)); 486 s = splnet(); 487 nfsd->nfsd_procp = p; 488 TAILQ_INSERT_TAIL(&nfsd_head, nfsd, nfsd_chain); 489 nfs_numnfsd++; 490 } else 491 s = splnet(); 492 493 /* 494 * Loop getting rpc requests until SIGKILL. 495 */ 496 for (;;) { 497 if ((nfsd->nfsd_flag & NFSD_REQINPROG) == 0) { 498 while (nfsd->nfsd_slp == (struct nfssvc_sock *)0 && 499 (nfsd_head_flag & NFSD_CHECKSLP) == 0) { 500 nfsd->nfsd_flag |= NFSD_WAITING; 501 nfsd_waiting++; 502 error = tsleep((caddr_t)nfsd, PSOCK | PCATCH, 503 "nfsd", 0); 504 nfsd_waiting--; 505 if (error) 506 goto done; 507 } 508 if (nfsd->nfsd_slp == (struct nfssvc_sock *)0 && 509 (nfsd_head_flag & NFSD_CHECKSLP) != 0) { 510 for (slp = nfssvc_sockhead.tqh_first; slp != 0; 511 slp = slp->ns_chain.tqe_next) { 512 if ((slp->ns_flag & (SLP_VALID | SLP_DOREC)) 513 == (SLP_VALID | SLP_DOREC)) { 514 slp->ns_flag &= ~SLP_DOREC; 515 slp->ns_sref++; 516 nfsd->nfsd_slp = slp; 517 break; 518 } 519 } 520 if (slp == 0) 521 nfsd_head_flag &= ~NFSD_CHECKSLP; 522 } 523 if ((slp = nfsd->nfsd_slp) == (struct nfssvc_sock *)0) 524 continue; 525 if (slp->ns_flag & SLP_VALID) { 526 if (slp->ns_flag & SLP_DISCONN) 527 nfsrv_zapsock(slp); 528 else if (slp->ns_flag & SLP_NEEDQ) { 529 slp->ns_flag &= ~SLP_NEEDQ; 530 (void) nfs_sndlock(&slp->ns_solock, 531 &slp->ns_solock, 532 (struct nfsreq *)0); 533 nfsrv_rcv(slp->ns_so, (caddr_t)slp, 534 M_WAIT); 535 nfs_sndunlock(&slp->ns_solock, 536 &slp->ns_solock); 537 } 538 error = nfsrv_dorec(slp, nfsd, &nd); 539 cur_usec = nfs_curusec(); 540 if (error && slp->ns_tq.lh_first && 541 slp->ns_tq.lh_first->nd_time <= cur_usec) { 542 error = 0; 543 cacherep = RC_DOIT; 544 writes_todo = 1; 545 } else 546 writes_todo = 0; 547 nfsd->nfsd_flag |= NFSD_REQINPROG; 548 } 549 } else { 550 error = 0; 551 slp = nfsd->nfsd_slp; 552 } 553 if (error || (slp->ns_flag & SLP_VALID) == 0) { 554 if (nd) { 555 free((caddr_t)nd, M_NFSRVDESC); 556 nd = NULL; 557 } 558 nfsd->nfsd_slp = (struct nfssvc_sock *)0; 559 nfsd->nfsd_flag &= ~NFSD_REQINPROG; 560 nfsrv_slpderef(slp); 561 continue; 562 } 563 splx(s); 564 so = slp->ns_so; 565 sotype = so->so_type; 566 if (so->so_proto->pr_flags & PR_CONNREQUIRED) 567 solockp = &slp->ns_solock; 568 else 569 solockp = (int *)0; 570 if (nd) { 571 getmicrotime(&nd->nd_starttime); 572 if (nd->nd_nam2) 573 nd->nd_nam = nd->nd_nam2; 574 else 575 nd->nd_nam = slp->ns_nam; 576 577 /* 578 * Check to see if authorization is needed. 579 */ 580 if (nfsd->nfsd_flag & NFSD_NEEDAUTH) { 581 nfsd->nfsd_flag &= ~NFSD_NEEDAUTH; 582 nsd->nsd_haddr = 583 ((struct sockaddr_in *) 584 nd->nd_nam)->sin_addr.s_addr; 585 nsd->nsd_authlen = nfsd->nfsd_authlen; 586 nsd->nsd_verflen = nfsd->nfsd_verflen; 587 if (!copyout(nfsd->nfsd_authstr,nsd->nsd_authstr, 588 nfsd->nfsd_authlen) && 589 !copyout(nfsd->nfsd_verfstr, nsd->nsd_verfstr, 590 nfsd->nfsd_verflen) && 591 !copyout((caddr_t)nsd, argp, sizeof (*nsd))) 592 return (ENEEDAUTH); 593 cacherep = RC_DROPIT; 594 } else 595 cacherep = nfsrv_getcache(nd, slp, &mreq); 596 597 /* 598 * Check for just starting up for NQNFS and send 599 * fake "try again later" replies to the NQNFS clients. 600 */ 601 if (notstarted && nqnfsstarttime <= time_second) { 602 if (modify_flag) { 603 nqnfsstarttime = time_second + nqsrv_writeslack; 604 modify_flag = 0; 605 } else 606 notstarted = 0; 607 } 608 if (notstarted) { 609 if ((nd->nd_flag & ND_NQNFS) == 0) 610 cacherep = RC_DROPIT; 611 else if (nd->nd_procnum != NFSPROC_WRITE) { 612 nd->nd_procnum = NFSPROC_NOOP; 613 nd->nd_repstat = NQNFS_TRYLATER; 614 cacherep = RC_DOIT; 615 } else 616 modify_flag = 1; 617 } else if (nfsd->nfsd_flag & NFSD_AUTHFAIL) { 618 nfsd->nfsd_flag &= ~NFSD_AUTHFAIL; 619 nd->nd_procnum = NFSPROC_NOOP; 620 nd->nd_repstat = (NFSERR_AUTHERR | AUTH_TOOWEAK); 621 cacherep = RC_DOIT; 622 } else if (nfs_privport) { 623 /* Check if source port is privileged */ 624 u_short port; 625 struct sockaddr *nam = nd->nd_nam; 626 struct sockaddr_in *sin; 627 628 sin = (struct sockaddr_in *)nam; 629 port = ntohs(sin->sin_port); 630 if (port >= IPPORT_RESERVED && 631 nd->nd_procnum != NFSPROC_NULL) { 632 nd->nd_procnum = NFSPROC_NOOP; 633 nd->nd_repstat = (NFSERR_AUTHERR | AUTH_TOOWEAK); 634 cacherep = RC_DOIT; 635 printf("NFS request from unprivileged port (%s:%d)\n", 636 inet_ntoa(sin->sin_addr), port); 637 } 638 } 639 640 } 641 642 /* 643 * Loop to get all the write rpc relies that have been 644 * gathered together. 645 */ 646 do { 647 switch (cacherep) { 648 case RC_DOIT: 649 if (nd && (nd->nd_flag & ND_NFSV3)) 650 procrastinate = nfsrvw_procrastinate_v3; 651 else 652 procrastinate = nfsrvw_procrastinate; 653 if (writes_todo || (nd->nd_procnum == NFSPROC_WRITE && 654 procrastinate > 0 && !notstarted)) 655 error = nfsrv_writegather(&nd, slp, 656 nfsd->nfsd_procp, &mreq); 657 else 658 error = (*(nfsrv3_procs[nd->nd_procnum]))(nd, 659 slp, nfsd->nfsd_procp, &mreq); 660 if (mreq == NULL) 661 break; 662 if (error) { 663 if (nd->nd_procnum != NQNFSPROC_VACATED) 664 nfsstats.srv_errs++; 665 nfsrv_updatecache(nd, FALSE, mreq); 666 if (nd->nd_nam2) 667 FREE(nd->nd_nam2, M_SONAME); 668 break; 669 } 670 nfsstats.srvrpccnt[nd->nd_procnum]++; 671 nfsrv_updatecache(nd, TRUE, mreq); 672 nd->nd_mrep = (struct mbuf *)0; 673 case RC_REPLY: 674 m = mreq; 675 siz = 0; 676 while (m) { 677 siz += m->m_len; 678 m = m->m_next; 679 } 680 if (siz <= 0 || siz > NFS_MAXPACKET) { 681 printf("mbuf siz=%d\n",siz); 682 panic("Bad nfs svc reply"); 683 } 684 m = mreq; 685 m->m_pkthdr.len = siz; 686 m->m_pkthdr.rcvif = (struct ifnet *)0; 687 /* 688 * For stream protocols, prepend a Sun RPC 689 * Record Mark. 690 */ 691 if (sotype == SOCK_STREAM) { 692 M_PREPEND(m, NFSX_UNSIGNED, M_WAIT); 693 *mtod(m, u_int32_t *) = htonl(0x80000000 | siz); 694 } 695 if (solockp) 696 (void) nfs_sndlock(solockp, solockp, 697 (struct nfsreq *)0); 698 if (slp->ns_flag & SLP_VALID) 699 error = nfs_send(so, nd->nd_nam2, m, NULL); 700 else { 701 error = EPIPE; 702 m_freem(m); 703 } 704 if (nfsrtton) 705 nfsd_rt(sotype, nd, cacherep); 706 if (nd->nd_nam2) 707 FREE(nd->nd_nam2, M_SONAME); 708 if (nd->nd_mrep) 709 m_freem(nd->nd_mrep); 710 if (error == EPIPE) 711 nfsrv_zapsock(slp); 712 if (solockp) 713 nfs_sndunlock(solockp, solockp); 714 if (error == EINTR || error == ERESTART) { 715 free((caddr_t)nd, M_NFSRVDESC); 716 nfsrv_slpderef(slp); 717 s = splnet(); 718 goto done; 719 } 720 break; 721 case RC_DROPIT: 722 if (nfsrtton) 723 nfsd_rt(sotype, nd, cacherep); 724 m_freem(nd->nd_mrep); 725 if (nd->nd_nam2) 726 FREE(nd->nd_nam2, M_SONAME); 727 break; 728 }; 729 if (nd) { 730 FREE((caddr_t)nd, M_NFSRVDESC); 731 nd = NULL; 732 } 733 734 /* 735 * Check to see if there are outstanding writes that 736 * need to be serviced. 737 */ 738 cur_usec = nfs_curusec(); 739 s = splsoftclock(); 740 if (slp->ns_tq.lh_first && 741 slp->ns_tq.lh_first->nd_time <= cur_usec) { 742 cacherep = RC_DOIT; 743 writes_todo = 1; 744 } else 745 writes_todo = 0; 746 splx(s); 747 } while (writes_todo); 748 s = splnet(); 749 if (nfsrv_dorec(slp, nfsd, &nd)) { 750 nfsd->nfsd_flag &= ~NFSD_REQINPROG; 751 nfsd->nfsd_slp = NULL; 752 nfsrv_slpderef(slp); 753 } 754 } 755done: 756 TAILQ_REMOVE(&nfsd_head, nfsd, nfsd_chain); 757 splx(s); 758 free((caddr_t)nfsd, M_NFSD); 759 nsd->nsd_nfsd = (struct nfsd *)0; 760 if (--nfs_numnfsd == 0) 761 nfsrv_init(TRUE); /* Reinitialize everything */ 762 return (error); 763} 764 765/* 766 * Shut down a socket associated with an nfssvc_sock structure. 767 * Should be called with the send lock set, if required. 768 * The trick here is to increment the sref at the start, so that the nfsds 769 * will stop using it and clear ns_flag at the end so that it will not be 770 * reassigned during cleanup. 771 */ 772static void 773nfsrv_zapsock(slp) 774 register struct nfssvc_sock *slp; 775{ 776 register struct nfsuid *nuidp, *nnuidp; 777 register struct nfsrv_descript *nwp, *nnwp; 778 struct socket *so; 779 struct file *fp; 780 struct nfsrv_rec *rec; 781 int s; 782 783 slp->ns_flag &= ~SLP_ALLFLAGS; 784 fp = slp->ns_fp; 785 if (fp) { 786 slp->ns_fp = (struct file *)0; 787 so = slp->ns_so; 788 so->so_rcv.sb_flags &= ~SB_UPCALL; 789 so->so_upcall = NULL; 790 so->so_upcallarg = NULL; 791 soshutdown(so, 2); 792 closef(fp, (struct proc *)0); 793 if (slp->ns_nam) 794 FREE(slp->ns_nam, M_SONAME); 795 m_freem(slp->ns_raw); 796 while ((rec = STAILQ_FIRST(&slp->ns_rec)) != NULL) { 797 STAILQ_REMOVE_HEAD(&slp->ns_rec, nr_link); 798 if (rec->nr_address) 799 FREE(rec->nr_address, M_SONAME); 800 m_freem(rec->nr_packet); 801 free(rec, M_NFSRVDESC); 802 } 803 for (nuidp = slp->ns_uidlruhead.tqh_first; nuidp != 0; 804 nuidp = nnuidp) { 805 nnuidp = nuidp->nu_lru.tqe_next; 806 LIST_REMOVE(nuidp, nu_hash); 807 TAILQ_REMOVE(&slp->ns_uidlruhead, nuidp, nu_lru); 808 if (nuidp->nu_flag & NU_NAM) 809 FREE(nuidp->nu_nam, M_SONAME); 810 free((caddr_t)nuidp, M_NFSUID); 811 } 812 s = splsoftclock(); 813 for (nwp = slp->ns_tq.lh_first; nwp; nwp = nnwp) { 814 nnwp = nwp->nd_tq.le_next; 815 LIST_REMOVE(nwp, nd_tq); 816 free((caddr_t)nwp, M_NFSRVDESC); 817 } 818 LIST_INIT(&slp->ns_tq); 819 splx(s); 820 } 821} 822 823/* 824 * Derefence a server socket structure. If it has no more references and 825 * is no longer valid, you can throw it away. 826 */ 827void 828nfsrv_slpderef(slp) 829 register struct nfssvc_sock *slp; 830{ 831 if (--(slp->ns_sref) == 0 && (slp->ns_flag & SLP_VALID) == 0) { 832 TAILQ_REMOVE(&nfssvc_sockhead, slp, ns_chain); 833 free((caddr_t)slp, M_NFSSVC); 834 } 835} 836 837/* 838 * Initialize the data structures for the server. 839 * Handshake with any new nfsds starting up to avoid any chance of 840 * corruption. 841 */ 842void 843nfsrv_init(terminating) 844 int terminating; 845{ 846 register struct nfssvc_sock *slp, *nslp; 847 848 if (nfssvc_sockhead_flag & SLP_INIT) 849 panic("nfsd init"); 850 nfssvc_sockhead_flag |= SLP_INIT; 851 if (terminating) { 852 for (slp = nfssvc_sockhead.tqh_first; slp != 0; slp = nslp) { 853 nslp = slp->ns_chain.tqe_next; 854 if (slp->ns_flag & SLP_VALID) 855 nfsrv_zapsock(slp); 856 TAILQ_REMOVE(&nfssvc_sockhead, slp, ns_chain); 857 free((caddr_t)slp, M_NFSSVC); 858 } 859 nfsrv_cleancache(); /* And clear out server cache */ 860 } else 861 nfs_pub.np_valid = 0; 862 863 TAILQ_INIT(&nfssvc_sockhead); 864 nfssvc_sockhead_flag &= ~SLP_INIT; 865 if (nfssvc_sockhead_flag & SLP_WANTINIT) { 866 nfssvc_sockhead_flag &= ~SLP_WANTINIT; 867 wakeup((caddr_t)&nfssvc_sockhead); 868 } 869 870 TAILQ_INIT(&nfsd_head); 871 nfsd_head_flag &= ~NFSD_CHECKSLP; 872 873 nfs_udpsock = (struct nfssvc_sock *) 874 malloc(sizeof (struct nfssvc_sock), M_NFSSVC, M_WAITOK); 875 bzero((caddr_t)nfs_udpsock, sizeof (struct nfssvc_sock)); 876 STAILQ_INIT(&nfs_udpsock->ns_rec); 877 TAILQ_INIT(&nfs_udpsock->ns_uidlruhead); 878 TAILQ_INSERT_HEAD(&nfssvc_sockhead, nfs_udpsock, ns_chain); 879 880 nfs_cltpsock = (struct nfssvc_sock *) 881 malloc(sizeof (struct nfssvc_sock), M_NFSSVC, M_WAITOK); 882 bzero((caddr_t)nfs_cltpsock, sizeof (struct nfssvc_sock)); 883 STAILQ_INIT(&nfs_cltpsock->ns_rec); 884 TAILQ_INIT(&nfs_cltpsock->ns_uidlruhead); 885 TAILQ_INSERT_TAIL(&nfssvc_sockhead, nfs_cltpsock, ns_chain); 886} 887 888/* 889 * Add entries to the server monitor log. 890 */ 891static void 892nfsd_rt(sotype, nd, cacherep) 893 int sotype; 894 register struct nfsrv_descript *nd; 895 int cacherep; 896{ 897 register struct drt *rt; 898 899 rt = &nfsdrt.drt[nfsdrt.pos]; 900 if (cacherep == RC_DOIT) 901 rt->flag = 0; 902 else if (cacherep == RC_REPLY) 903 rt->flag = DRT_CACHEREPLY; 904 else 905 rt->flag = DRT_CACHEDROP; 906 if (sotype == SOCK_STREAM) 907 rt->flag |= DRT_TCP; 908 if (nd->nd_flag & ND_NQNFS) 909 rt->flag |= DRT_NQNFS; 910 else if (nd->nd_flag & ND_NFSV3) 911 rt->flag |= DRT_NFSV3; 912 rt->proc = nd->nd_procnum; 913 if (nd->nd_nam->sa_family == AF_INET) 914 rt->ipadr = ((struct sockaddr_in *)nd->nd_nam)->sin_addr.s_addr; 915 else 916 rt->ipadr = INADDR_ANY; 917 rt->resptime = nfs_curusec() - (nd->nd_starttime.tv_sec * 1000000 + nd->nd_starttime.tv_usec); 918 getmicrotime(&rt->tstamp); 919 nfsdrt.pos = (nfsdrt.pos + 1) % NFSRTTLOGSIZ; 920} 921#endif /* NFS_NOSERVER */ 922 923static int nfs_defect = 0; 924SYSCTL_INT(_vfs_nfs, OID_AUTO, defect, CTLFLAG_RW, &nfs_defect, 0, ""); 925 926/* 927 * Asynchronous I/O daemons for client nfs. 928 * They do read-ahead and write-behind operations on the block I/O cache. 929 * Never returns unless it fails or gets killed. 930 */ 931static int 932nfssvc_iod(p) 933 struct proc *p; 934{ 935 register struct buf *bp; 936 register int i, myiod; 937 struct nfsmount *nmp; 938 int error = 0; 939 940 /* 941 * Assign my position or return error if too many already running 942 */ 943 myiod = -1; 944 for (i = 0; i < NFS_MAXASYNCDAEMON; i++) 945 if (nfs_asyncdaemon[i] == 0) { 946 nfs_asyncdaemon[i]++; 947 myiod = i; 948 break; 949 } 950 if (myiod == -1) 951 return (EBUSY); 952 nfs_numasync++; 953 /* 954 * Just loop around doin our stuff until SIGKILL 955 */ 956 for (;;) { 957 while (((nmp = nfs_iodmount[myiod]) == NULL 958 || nmp->nm_bufq.tqh_first == NULL) 959 && error == 0) { 960 if (nmp) 961 nmp->nm_bufqiods--; 962 nfs_iodwant[myiod] = p; 963 nfs_iodmount[myiod] = NULL; 964 error = tsleep((caddr_t)&nfs_iodwant[myiod], 965 PWAIT | PCATCH, "nfsidl", 0); 966 } 967 if (error) { 968 nfs_asyncdaemon[myiod] = 0; 969 if (nmp) 970 nmp->nm_bufqiods--; 971 nfs_iodwant[myiod] = NULL; 972 nfs_iodmount[myiod] = NULL; 973 nfs_numasync--; 974 return (error); 975 } 976 while ((bp = nmp->nm_bufq.tqh_first) != NULL) { 977 /* Take one off the front of the list */ 978 TAILQ_REMOVE(&nmp->nm_bufq, bp, b_freelist); 979 nmp->nm_bufqlen--; 980 if (nmp->nm_bufqwant && nmp->nm_bufqlen < 2 * nfs_numasync) { 981 nmp->nm_bufqwant = FALSE; 982 wakeup(&nmp->nm_bufq); 983 } 984 if (bp->b_flags & B_READ) 985 (void) nfs_doio(bp, bp->b_rcred, (struct proc *)0); 986 else 987 (void) nfs_doio(bp, bp->b_wcred, (struct proc *)0); 988 /* 989 * If there are more than one iod on this mount, then defect 990 * so that the iods can be shared out fairly between the mounts 991 */ 992 if (nfs_defect && nmp->nm_bufqiods > 1) { 993 NFS_DPF(ASYNCIO, 994 ("nfssvc_iod: iod %d defecting from mount %p\n", 995 myiod, nmp)); 996 nfs_iodmount[myiod] = NULL; 997 nmp->nm_bufqiods--; 998 break; 999 } 1000 } 1001 } 1002} 1003 1004 1005/* 1006 * Get an authorization string for the uid by having the mount_nfs sitting 1007 * on this mount point porpous out of the kernel and do it. 1008 */ 1009int 1010nfs_getauth(nmp, rep, cred, auth_str, auth_len, verf_str, verf_len, key) 1011 register struct nfsmount *nmp; 1012 struct nfsreq *rep; 1013 struct ucred *cred; 1014 char **auth_str; 1015 int *auth_len; 1016 char *verf_str; 1017 int *verf_len; 1018 NFSKERBKEY_T key; /* return session key */ 1019{ 1020 int error = 0; 1021 1022 while ((nmp->nm_state & NFSSTA_WAITAUTH) == 0) { 1023 nmp->nm_state |= NFSSTA_WANTAUTH; 1024 (void) tsleep((caddr_t)&nmp->nm_authtype, PSOCK, 1025 "nfsauth1", 2 * hz); 1026 error = nfs_sigintr(nmp, rep, rep->r_procp); 1027 if (error) { 1028 nmp->nm_state &= ~NFSSTA_WANTAUTH; 1029 return (error); 1030 } 1031 } 1032 nmp->nm_state &= ~(NFSSTA_WAITAUTH | NFSSTA_WANTAUTH); 1033 nmp->nm_authstr = *auth_str = (char *)malloc(RPCAUTH_MAXSIZ, M_TEMP, M_WAITOK); 1034 nmp->nm_authlen = RPCAUTH_MAXSIZ; 1035 nmp->nm_verfstr = verf_str; 1036 nmp->nm_verflen = *verf_len; 1037 nmp->nm_authuid = cred->cr_uid; 1038 wakeup((caddr_t)&nmp->nm_authstr); 1039 1040 /* 1041 * And wait for mount_nfs to do its stuff. 1042 */ 1043 while ((nmp->nm_state & NFSSTA_HASAUTH) == 0 && error == 0) { 1044 (void) tsleep((caddr_t)&nmp->nm_authlen, PSOCK, 1045 "nfsauth2", 2 * hz); 1046 error = nfs_sigintr(nmp, rep, rep->r_procp); 1047 } 1048 if (nmp->nm_state & NFSSTA_AUTHERR) { 1049 nmp->nm_state &= ~NFSSTA_AUTHERR; 1050 error = EAUTH; 1051 } 1052 if (error) 1053 free((caddr_t)*auth_str, M_TEMP); 1054 else { 1055 *auth_len = nmp->nm_authlen; 1056 *verf_len = nmp->nm_verflen; 1057 bcopy((caddr_t)nmp->nm_key, (caddr_t)key, sizeof (key)); 1058 } 1059 nmp->nm_state &= ~NFSSTA_HASAUTH; 1060 nmp->nm_state |= NFSSTA_WAITAUTH; 1061 if (nmp->nm_state & NFSSTA_WANTAUTH) { 1062 nmp->nm_state &= ~NFSSTA_WANTAUTH; 1063 wakeup((caddr_t)&nmp->nm_authtype); 1064 } 1065 return (error); 1066} 1067 1068/* 1069 * Get a nickname authenticator and verifier. 1070 */ 1071int 1072nfs_getnickauth(nmp, cred, auth_str, auth_len, verf_str, verf_len) 1073 struct nfsmount *nmp; 1074 struct ucred *cred; 1075 char **auth_str; 1076 int *auth_len; 1077 char *verf_str; 1078 int verf_len; 1079{ 1080 register struct nfsuid *nuidp; 1081 register u_int32_t *nickp, *verfp; 1082 struct timeval ktvin, ktvout; 1083 1084#ifdef DIAGNOSTIC 1085 if (verf_len < (4 * NFSX_UNSIGNED)) 1086 panic("nfs_getnickauth verf too small"); 1087#endif 1088 for (nuidp = NMUIDHASH(nmp, cred->cr_uid)->lh_first; 1089 nuidp != 0; nuidp = nuidp->nu_hash.le_next) { 1090 if (nuidp->nu_cr.cr_uid == cred->cr_uid) 1091 break; 1092 } 1093 if (!nuidp || nuidp->nu_expire < time_second) 1094 return (EACCES); 1095 1096 /* 1097 * Move to the end of the lru list (end of lru == most recently used). 1098 */ 1099 TAILQ_REMOVE(&nmp->nm_uidlruhead, nuidp, nu_lru); 1100 TAILQ_INSERT_TAIL(&nmp->nm_uidlruhead, nuidp, nu_lru); 1101 1102 nickp = (u_int32_t *)malloc(2 * NFSX_UNSIGNED, M_TEMP, M_WAITOK); 1103 *nickp++ = txdr_unsigned(RPCAKN_NICKNAME); 1104 *nickp = txdr_unsigned(nuidp->nu_nickname); 1105 *auth_str = (char *)nickp; 1106 *auth_len = 2 * NFSX_UNSIGNED; 1107 1108 /* 1109 * Now we must encrypt the verifier and package it up. 1110 */ 1111 verfp = (u_int32_t *)verf_str; 1112 *verfp++ = txdr_unsigned(RPCAKN_NICKNAME); 1113 if (time_second > nuidp->nu_timestamp.tv_sec || 1114 (time_second == nuidp->nu_timestamp.tv_sec && 1115 time_second > nuidp->nu_timestamp.tv_usec)) 1116 getmicrotime(&nuidp->nu_timestamp); 1117 else 1118 nuidp->nu_timestamp.tv_usec++; 1119 ktvin.tv_sec = txdr_unsigned(nuidp->nu_timestamp.tv_sec); 1120 ktvin.tv_usec = txdr_unsigned(nuidp->nu_timestamp.tv_usec); 1121 1122 /* 1123 * Now encrypt the timestamp verifier in ecb mode using the session 1124 * key. 1125 */ 1126#ifdef NFSKERB 1127 XXX 1128#endif 1129 1130 *verfp++ = ktvout.tv_sec; 1131 *verfp++ = ktvout.tv_usec; 1132 *verfp = 0; 1133 return (0); 1134} 1135 1136/* 1137 * Save the current nickname in a hash list entry on the mount point. 1138 */ 1139int 1140nfs_savenickauth(nmp, cred, len, key, mdp, dposp, mrep) 1141 register struct nfsmount *nmp; 1142 struct ucred *cred; 1143 int len; 1144 NFSKERBKEY_T key; 1145 struct mbuf **mdp; 1146 char **dposp; 1147 struct mbuf *mrep; 1148{ 1149 register struct nfsuid *nuidp; 1150 register u_int32_t *tl; 1151 register int32_t t1; 1152 struct mbuf *md = *mdp; 1153 struct timeval ktvin, ktvout; 1154 u_int32_t nick; 1155 char *dpos = *dposp, *cp2; 1156 int deltasec, error = 0; 1157 1158 if (len == (3 * NFSX_UNSIGNED)) { 1159 nfsm_dissect(tl, u_int32_t *, 3 * NFSX_UNSIGNED); 1160 ktvin.tv_sec = *tl++; 1161 ktvin.tv_usec = *tl++; 1162 nick = fxdr_unsigned(u_int32_t, *tl); 1163 1164 /* 1165 * Decrypt the timestamp in ecb mode. 1166 */ 1167#ifdef NFSKERB 1168 XXX 1169#endif 1170 ktvout.tv_sec = fxdr_unsigned(long, ktvout.tv_sec); 1171 ktvout.tv_usec = fxdr_unsigned(long, ktvout.tv_usec); 1172 deltasec = time_second - ktvout.tv_sec; 1173 if (deltasec < 0) 1174 deltasec = -deltasec; 1175 /* 1176 * If ok, add it to the hash list for the mount point. 1177 */ 1178 if (deltasec <= NFS_KERBCLOCKSKEW) { 1179 if (nmp->nm_numuids < nuidhash_max) { 1180 nmp->nm_numuids++; 1181 nuidp = (struct nfsuid *) 1182 malloc(sizeof (struct nfsuid), M_NFSUID, 1183 M_WAITOK); 1184 } else { 1185 nuidp = nmp->nm_uidlruhead.tqh_first; 1186 LIST_REMOVE(nuidp, nu_hash); 1187 TAILQ_REMOVE(&nmp->nm_uidlruhead, nuidp, 1188 nu_lru); 1189 } 1190 nuidp->nu_flag = 0; 1191 nuidp->nu_cr.cr_uid = cred->cr_uid; 1192 nuidp->nu_expire = time_second + NFS_KERBTTL; 1193 nuidp->nu_timestamp = ktvout; 1194 nuidp->nu_nickname = nick; 1195 bcopy(key, nuidp->nu_key, sizeof (key)); 1196 TAILQ_INSERT_TAIL(&nmp->nm_uidlruhead, nuidp, 1197 nu_lru); 1198 LIST_INSERT_HEAD(NMUIDHASH(nmp, cred->cr_uid), 1199 nuidp, nu_hash); 1200 } 1201 } else 1202 nfsm_adv(nfsm_rndup(len)); 1203nfsmout: 1204 *mdp = md; 1205 *dposp = dpos; 1206 return (error); 1207} 1208