NetBSD/sys/nfs/nfs_syscalls.c

1289 lines
32 KiB
C
Raw Normal View History

2003-05-22 18:14:41 +04:00
/* $NetBSD: nfs_syscalls.c,v 1.63 2003/05/22 14:14:41 yamt Exp $ */
1993-03-21 12:45:37 +03:00
/*
* Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
1993-03-21 12:45:37 +03:00
*
* This code is derived from software contributed to Berkeley by
* Rick Macklem at The University of Guelph.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)nfs_syscalls.c 8.5 (Berkeley) 3/30/95
1993-03-21 12:45:37 +03:00
*/
2001-11-10 13:59:08 +03:00
#include <sys/cdefs.h>
2003-05-22 18:14:41 +04:00
__KERNEL_RCSID(0, "$NetBSD: nfs_syscalls.c,v 1.63 2003/05/22 14:14:41 yamt Exp $");
2001-11-10 13:59:08 +03:00
1998-02-19 03:54:13 +03:00
#include "fs_nfs.h"
#include "opt_nfs.h"
1998-06-26 02:17:36 +04:00
#include "opt_nfsserver.h"
1998-07-05 08:37:35 +04:00
#include "opt_iso.h"
#include "opt_inet.h"
#include "opt_compat_netbsd.h"
1998-02-19 03:54:13 +03:00
1993-12-18 03:40:47 +03:00
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/file.h>
#include <sys/stat.h>
#include <sys/vnode.h>
#include <sys/mount.h>
#include <sys/proc.h>
#include <sys/uio.h>
1993-12-18 03:40:47 +03:00
#include <sys/malloc.h>
#include <sys/buf.h>
#include <sys/mbuf.h>
#include <sys/socket.h>
#include <sys/socketvar.h>
#include <sys/signalvar.h>
1993-12-18 03:40:47 +03:00
#include <sys/domain.h>
#include <sys/protosw.h>
#include <sys/namei.h>
#include <sys/syslog.h>
1996-02-10 00:48:19 +03:00
#include <sys/filedesc.h>
#include <sys/kthread.h>
1993-03-21 12:45:37 +03:00
2003-01-18 11:51:40 +03:00
#include <sys/sa.h>
#include <sys/syscallargs.h>
1993-12-18 03:40:47 +03:00
#include <netinet/in.h>
#include <netinet/tcp.h>
#ifdef ISO
#include <netiso/iso.h>
#endif
#include <nfs/xdr_subs.h>
#include <nfs/rpcv2.h>
#include <nfs/nfsproto.h>
1993-12-18 03:40:47 +03:00
#include <nfs/nfs.h>
#include <nfs/nfsm_subs.h>
1993-12-18 03:40:47 +03:00
#include <nfs/nfsrvcache.h>
#include <nfs/nfsmount.h>
#include <nfs/nfsnode.h>
#include <nfs/nqnfs.h>
#include <nfs/nfsrtt.h>
1996-02-10 00:48:19 +03:00
#include <nfs/nfs_var.h>
1993-03-21 12:45:37 +03:00
/* Global defs. */
extern int32_t (*nfsrv3_procs[NFS_NPROCS]) __P((struct nfsrv_descript *,
struct nfssvc_sock *,
struct proc *, struct mbuf **));
extern time_t nqnfsstarttime;
extern int nfsrvw_procrastinate;
2002-05-13 03:04:35 +04:00
2000-11-25 02:30:02 +03:00
struct nfssvc_sock *nfs_udpsock;
#ifdef ISO
struct nfssvc_sock *nfs_cltpsock;
#endif
#ifdef INET6
struct nfssvc_sock *nfs_udp6sock;
#endif
int nuidhash_max = NFS_MAXUIDHASH;
int nfsd_waiting = 0;
1996-02-10 00:48:19 +03:00
#ifdef NFSSERVER
static int nfs_numnfsd = 0;
static int notstarted = 1;
static int modify_flag = 0;
static struct nfsdrt nfsdrt;
1996-02-10 00:48:19 +03:00
#endif
1993-03-21 12:45:37 +03:00
2002-05-13 03:04:35 +04:00
struct nfssvc_sockhead nfssvc_sockhead;
struct nfsdhead nfsd_head;
int nfssvc_sockhead_flag;
int nfsd_head_flag;
MALLOC_DEFINE(M_NFSUID, "NFS uid", "Nfs uid mapping structure");
1997-01-31 05:58:48 +03:00
#ifdef NFS
2003-04-09 18:22:33 +04:00
struct nfs_iod nfs_asyncdaemon[NFS_MAXASYNCDAEMON];
int nfs_niothreads = -1; /* == "0, and has never been set" */
#endif
1996-02-10 00:48:19 +03:00
#ifdef NFSSERVER
static void nfsd_rt __P((int, struct nfsrv_descript *, int));
1996-02-10 00:48:19 +03:00
#endif
1993-03-21 12:45:37 +03:00
/*
* NFS server system calls
*/
/*
* Nfs server pseudo system call for the nfsd's
* Based on the flag value it either:
* - adds a socket to the selection list
* - remains in the kernel as an nfsd
* - remains in the kernel as an nfsiod
1993-03-21 12:45:37 +03:00
*/
1996-02-10 00:48:19 +03:00
int
2003-01-18 11:51:40 +03:00
sys_nfssvc(l, v, retval)
struct lwp *l;
void *v;
register_t *retval;
{
2000-03-30 16:51:13 +04:00
struct sys_nfssvc_args /* {
syscallarg(int) flag;
syscallarg(caddr_t) argp;
} */ *uap = v;
2003-01-18 11:51:40 +03:00
struct proc *p = l->l_proc;
1996-02-10 00:48:19 +03:00
int error;
1997-01-31 05:58:48 +03:00
#ifdef NFS
struct nameidata nd;
struct nfsmount *nmp;
struct nfsd_cargs ncd;
#endif
1996-02-10 00:48:19 +03:00
#ifdef NFSSERVER
1993-03-21 12:45:37 +03:00
struct file *fp;
struct mbuf *nam;
struct nfsd_args nfsdarg;
struct nfsd_srvargs nfsd_srvargs, *nsd = &nfsd_srvargs;
struct nfsd *nfsd;
struct nfssvc_sock *slp;
1996-02-10 00:48:19 +03:00
struct nfsuid *nuidp;
#endif
1993-03-21 12:45:37 +03:00
/*
* Must be super user
*/
error = suser(p->p_ucred, &p->p_acflag);
if(error)
1993-03-21 12:45:37 +03:00
return (error);
1994-08-17 18:43:47 +04:00
while (nfssvc_sockhead_flag & SLP_INIT) {
nfssvc_sockhead_flag |= SLP_WANTINIT;
(void) tsleep((caddr_t)&nfssvc_sockhead, PSOCK, "nfsd init", 0);
}
if (SCARG(uap, flag) & NFSSVC_BIOD) {
#if defined(NFS) && defined(COMPAT_14)
2003-01-18 11:51:40 +03:00
error = nfssvc_iod(l);
#else
error = ENOSYS;
#endif
} else if (SCARG(uap, flag) & NFSSVC_MNTD) {
1997-01-31 05:58:48 +03:00
#ifndef NFS
error = ENOSYS;
#else
1996-02-10 00:48:19 +03:00
error = copyin(SCARG(uap, argp), (caddr_t)&ncd, sizeof (ncd));
if (error)
return (error);
NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_USERSPACE,
ncd.ncd_dirp, p);
error = namei(&nd);
if (error)
return (error);
if ((nd.ni_vp->v_flag & VROOT) == 0)
error = EINVAL;
nmp = VFSTONFS(nd.ni_vp->v_mount);
vput(nd.ni_vp);
if (error)
return (error);
if ((nmp->nm_iflag & NFSMNT_MNTD) &&
(SCARG(uap, flag) & NFSSVC_GOTAUTH) == 0)
return (0);
nmp->nm_iflag |= NFSMNT_MNTD;
error = nqnfs_clientd(nmp, p->p_ucred, &ncd, SCARG(uap, flag),
2003-01-18 11:51:40 +03:00
SCARG(uap, argp), l);
1997-01-31 05:58:48 +03:00
#endif /* NFS */
} else if (SCARG(uap, flag) & NFSSVC_ADDSOCK) {
#ifndef NFSSERVER
error = ENOSYS;
#else
1996-02-10 00:48:19 +03:00
error = copyin(SCARG(uap, argp), (caddr_t)&nfsdarg,
sizeof(nfsdarg));
1996-02-10 00:48:19 +03:00
if (error)
return (error);
/* getsock() will use the descriptor for us */
error = getsock(p->p_fd, nfsdarg.sock, &fp);
if (error)
return (error);
/*
* Get the client address for connected sockets.
*/
if (nfsdarg.name == NULL || nfsdarg.namelen == 0)
nam = (struct mbuf *)0;
1996-02-10 00:48:19 +03:00
else {
error = sockargs(&nam, nfsdarg.name, nfsdarg.namelen,
MT_SONAME);
if (error) {
FILE_UNUSE(fp, NULL);
1996-02-10 00:48:19 +03:00
return (error);
}
1996-02-10 00:48:19 +03:00
}
error = nfssvc_addsock(fp, nam);
FILE_UNUSE(fp, NULL);
#endif /* !NFSSERVER */
} else {
#ifndef NFSSERVER
error = ENOSYS;
#else
1996-02-10 00:48:19 +03:00
error = copyin(SCARG(uap, argp), (caddr_t)nsd, sizeof (*nsd));
if (error)
return (error);
if ((SCARG(uap, flag) & NFSSVC_AUTHIN) &&
((nfsd = nsd->nsd_nfsd)) != NULL &&
(nfsd->nfsd_slp->ns_flag & SLP_VALID)) {
slp = nfsd->nfsd_slp;
/*
* First check to see if another nfsd has already
* added this credential.
*/
2003-04-02 19:14:19 +04:00
LIST_FOREACH(nuidp, NUIDHASH(slp,nsd->nsd_cr.cr_uid),
nu_hash) {
if (nuidp->nu_cr.cr_uid == nsd->nsd_cr.cr_uid &&
(!nfsd->nfsd_nd->nd_nam2 ||
netaddr_match(NU_NETFAM(nuidp),
&nuidp->nu_haddr, nfsd->nfsd_nd->nd_nam2)))
break;
}
if (nuidp) {
nfsrv_setcred(&nuidp->nu_cr,&nfsd->nfsd_nd->nd_cr);
nfsd->nfsd_nd->nd_flag |= ND_KERBFULL;
} else {
/*
* Nope, so we will.
*/
if (slp->ns_numuids < nuidhash_max) {
slp->ns_numuids++;
nuidp = (struct nfsuid *)
malloc(sizeof (struct nfsuid), M_NFSUID,
M_WAITOK);
} else
nuidp = (struct nfsuid *)0;
if ((slp->ns_flag & SLP_VALID) == 0) {
if (nuidp)
free((caddr_t)nuidp, M_NFSUID);
} else {
if (nuidp == (struct nfsuid *)0) {
2003-04-02 19:14:19 +04:00
nuidp = TAILQ_FIRST(&slp->ns_uidlruhead);
1994-08-17 18:43:47 +04:00
LIST_REMOVE(nuidp, nu_hash);
TAILQ_REMOVE(&slp->ns_uidlruhead, nuidp,
nu_lru);
if (nuidp->nu_flag & NU_NAM)
m_freem(nuidp->nu_nam);
}
nuidp->nu_flag = 0;
2001-11-30 00:23:13 +03:00
crcvt(&nuidp->nu_cr, &nsd->nsd_cr);
if (nuidp->nu_cr.cr_ngroups > NGROUPS)
nuidp->nu_cr.cr_ngroups = NGROUPS;
nuidp->nu_cr.cr_ref = 1;
nuidp->nu_timestamp = nsd->nsd_timestamp;
nuidp->nu_expire = time.tv_sec + nsd->nsd_ttl;
/*
* and save the session key in nu_key.
*/
memcpy(nuidp->nu_key, nsd->nsd_key,
sizeof(nsd->nsd_key));
if (nfsd->nfsd_nd->nd_nam2) {
struct sockaddr_in *saddr;
saddr = mtod(nfsd->nfsd_nd->nd_nam2,
struct sockaddr_in *);
switch (saddr->sin_family) {
case AF_INET:
nuidp->nu_flag |= NU_INETADDR;
nuidp->nu_inetaddr =
saddr->sin_addr.s_addr;
break;
case AF_ISO:
default:
nuidp->nu_flag |= NU_NAM;
nuidp->nu_nam = m_copym(
nfsd->nfsd_nd->nd_nam2, 0,
M_COPYALL, M_WAIT);
break;
};
}
1994-08-17 18:43:47 +04:00
TAILQ_INSERT_TAIL(&slp->ns_uidlruhead, nuidp,
nu_lru);
1994-08-17 18:43:47 +04:00
LIST_INSERT_HEAD(NUIDHASH(slp, nsd->nsd_uid),
nuidp, nu_hash);
nfsrv_setcred(&nuidp->nu_cr,
&nfsd->nfsd_nd->nd_cr);
nfsd->nfsd_nd->nd_flag |= ND_KERBFULL;
}
}
}
if ((SCARG(uap, flag) & NFSSVC_AUTHINFAIL) &&
(nfsd = nsd->nsd_nfsd))
nfsd->nfsd_flag |= NFSD_AUTHFAIL;
2003-01-18 11:51:40 +03:00
error = nfssvc_nfsd(nsd, SCARG(uap, argp), l);
#endif /* !NFSSERVER */
}
if (error == EINTR || error == ERESTART)
error = 0;
return (error);
}
#ifdef NFSSERVER
MALLOC_DEFINE(M_NFSD, "NFS daemon", "Nfs server daemon structure");
MALLOC_DEFINE(M_NFSSVC, "NFS srvsock", "Nfs server structure");
MALLOC_DEFINE(M_NFSRVDESC, "NFS srvdesc", "NFS server descriptor");
/*
* Adds a socket to the list for servicing by nfsds.
*/
1996-02-10 00:48:19 +03:00
int
nfssvc_addsock(fp, mynam)
struct file *fp;
struct mbuf *mynam;
{
2000-03-30 16:51:13 +04:00
struct mbuf *m;
int siz;
struct nfssvc_sock *slp;
struct socket *so;
struct nfssvc_sock *tslp;
int error, s;
1993-03-21 12:45:37 +03:00
so = (struct socket *)fp->f_data;
tslp = (struct nfssvc_sock *)0;
/*
* Add it to the list, as required.
*/
if (so->so_proto->pr_protocol == IPPROTO_UDP) {
#ifdef INET6
if (so->so_proto->pr_domain->dom_family == AF_INET6)
tslp = nfs_udp6sock;
else
#endif
tslp = nfs_udpsock;
if (tslp->ns_flag & SLP_VALID) {
m_freem(mynam);
return (EPERM);
}
#ifdef ISO
} else if (so->so_proto->pr_protocol == ISOPROTO_CLTP) {
tslp = nfs_cltpsock;
if (tslp->ns_flag & SLP_VALID) {
m_freem(mynam);
return (EPERM);
}
#endif /* ISO */
}
if (so->so_type == SOCK_STREAM)
siz = NFS_MAXPACKET + sizeof (u_long);
1993-03-21 12:45:37 +03:00
else
siz = NFS_MAXPACKET;
error = soreserve(so, siz, siz);
if (error) {
m_freem(mynam);
return (error);
}
1993-03-21 12:45:37 +03:00
/*
* Set protocol specific options { for now TCP only } and
* reserve some space. For datagram sockets, this can get called
* repeatedly for the same socket, but that isn't harmful.
*/
if (so->so_type == SOCK_STREAM) {
m = m_get(M_WAIT, MT_SOOPTS);
MCLAIM(m, &nfs_mowner);
*mtod(m, int32_t *) = 1;
m->m_len = sizeof(int32_t);
1993-03-21 12:45:37 +03:00
sosetopt(so, SOL_SOCKET, SO_KEEPALIVE, m);
}
if ((so->so_proto->pr_domain->dom_family == AF_INET
#ifdef INET6
|| so->so_proto->pr_domain->dom_family == AF_INET6
#endif
) &&
so->so_proto->pr_protocol == IPPROTO_TCP) {
m = m_get(M_WAIT, MT_SOOPTS);
MCLAIM(m, &nfs_mowner);
*mtod(m, int32_t *) = 1;
m->m_len = sizeof(int32_t);
1993-03-21 12:45:37 +03:00
sosetopt(so, IPPROTO_TCP, TCP_NODELAY, m);
}
so->so_rcv.sb_flags &= ~SB_NOINTR;
so->so_rcv.sb_timeo = 0;
so->so_snd.sb_flags &= ~SB_NOINTR;
so->so_snd.sb_timeo = 0;
if (tslp)
slp = tslp;
else {
slp = (struct nfssvc_sock *)
malloc(sizeof (struct nfssvc_sock), M_NFSSVC, M_WAITOK);
memset((caddr_t)slp, 0, sizeof (struct nfssvc_sock));
1994-08-17 18:43:47 +04:00
TAILQ_INIT(&slp->ns_uidlruhead);
TAILQ_INSERT_TAIL(&nfssvc_sockhead, slp, ns_chain);
}
slp->ns_so = so;
slp->ns_nam = mynam;
fp->f_count++;
slp->ns_fp = fp;
1995-08-13 03:59:09 +04:00
s = splsoftnet();
so->so_upcallarg = (caddr_t)slp;
so->so_upcall = nfsrv_rcv;
so->so_rcv.sb_flags |= SB_UPCALL;
slp->ns_flag = (SLP_VALID | SLP_NEEDQ);
nfsrv_wakenfsd(slp);
splx(s);
return (0);
}
1993-03-21 12:45:37 +03:00
/*
* Called by nfssvc() for nfsds. Just loops around servicing rpc requests
* until it is killed by a signal.
*/
1996-02-10 00:48:19 +03:00
int
2003-01-18 11:51:40 +03:00
nfssvc_nfsd(nsd, argp, l)
struct nfsd_srvargs *nsd;
caddr_t argp;
2003-01-18 11:51:40 +03:00
struct lwp *l;
{
2000-03-30 16:51:13 +04:00
struct mbuf *m;
int siz;
struct nfssvc_sock *slp;
struct socket *so;
int *solockp;
struct nfsd *nfsd = nsd->nsd_nfsd;
struct nfsrv_descript *nd = NULL;
struct mbuf *mreq;
int error = 0, cacherep, s, sotype, writes_todo;
u_quad_t cur_usec;
2003-01-18 11:51:40 +03:00
struct proc *p = l->l_proc;
#ifndef nolint
cacherep = RC_DOIT;
writes_todo = 0;
#endif
1995-08-13 03:59:09 +04:00
s = splsoftnet();
if (nfsd == (struct nfsd *)0) {
nsd->nsd_nfsd = nfsd = (struct nfsd *)
malloc(sizeof (struct nfsd), M_NFSD, M_WAITOK);
memset((caddr_t)nfsd, 0, sizeof (struct nfsd));
nfsd->nfsd_procp = p;
TAILQ_INSERT_TAIL(&nfsd_head, nfsd, nfsd_chain);
nfs_numnfsd++;
}
2003-01-18 11:51:40 +03:00
PHOLD(l);
1993-03-21 12:45:37 +03:00
/*
* Loop getting rpc requests until SIGKILL.
1993-03-21 12:45:37 +03:00
*/
for (;;) {
if ((nfsd->nfsd_flag & NFSD_REQINPROG) == 0) {
while (nfsd->nfsd_slp == (struct nfssvc_sock *)0 &&
1994-08-17 18:43:47 +04:00
(nfsd_head_flag & NFSD_CHECKSLP) == 0) {
nfsd->nfsd_flag |= NFSD_WAITING;
nfsd_waiting++;
error = tsleep((caddr_t)nfsd, PSOCK | PCATCH,
"nfsd", 0);
nfsd_waiting--;
if (error)
goto done;
1993-03-21 12:45:37 +03:00
}
if (nfsd->nfsd_slp == (struct nfssvc_sock *)0 &&
1994-08-17 18:43:47 +04:00
(nfsd_head_flag & NFSD_CHECKSLP) != 0) {
2003-04-02 19:14:19 +04:00
TAILQ_FOREACH(slp, &nfssvc_sockhead, ns_chain) {
2003-05-22 18:14:41 +04:00
if ((slp->ns_flag &
(SLP_VALID | SLP_DOREC))
== (SLP_VALID | SLP_DOREC)) {
slp->ns_flag &= ~SLP_DOREC;
slp->ns_sref++;
nfsd->nfsd_slp = slp;
break;
}
}
1994-08-17 18:43:47 +04:00
if (slp == 0)
nfsd_head_flag &= ~NFSD_CHECKSLP;
}
if ((slp = nfsd->nfsd_slp) == (struct nfssvc_sock *)0)
continue;
if (slp->ns_flag & SLP_VALID) {
if (slp->ns_flag & SLP_DISCONN)
nfsrv_zapsock(slp);
else if (slp->ns_flag & SLP_NEEDQ) {
slp->ns_flag &= ~SLP_NEEDQ;
(void) nfs_sndlock(&slp->ns_solock,
(struct nfsreq *)0);
nfsrv_rcv(slp->ns_so, (caddr_t)slp,
M_WAIT);
nfs_sndunlock(&slp->ns_solock);
}
error = nfsrv_dorec(slp, nfsd, &nd);
cur_usec = (u_quad_t)time.tv_sec * 1000000 +
(u_quad_t)time.tv_usec;
2003-04-02 19:14:19 +04:00
if (error && LIST_FIRST(&slp->ns_tq) &&
LIST_FIRST(&slp->ns_tq)->nd_time <=
cur_usec) {
error = 0;
cacherep = RC_DOIT;
writes_todo = 1;
} else
writes_todo = 0;
nfsd->nfsd_flag |= NFSD_REQINPROG;
}
} else {
error = 0;
slp = nfsd->nfsd_slp;
}
if (error || (slp->ns_flag & SLP_VALID) == 0) {
if (nd) {
FREE(nd, M_NFSRVDESC);
nd = NULL;
}
nfsd->nfsd_slp = (struct nfssvc_sock *)0;
nfsd->nfsd_flag &= ~NFSD_REQINPROG;
nfsrv_slpderef(slp);
1993-03-21 12:45:37 +03:00
continue;
}
splx(s);
so = slp->ns_so;
sotype = so->so_type;
if (so->so_proto->pr_flags & PR_CONNREQUIRED)
solockp = &slp->ns_solock;
1993-03-21 12:45:37 +03:00
else
solockp = (int *)0;
if (nd) {
2003-05-22 18:14:41 +04:00
nd->nd_starttime = time;
if (nd->nd_nam2)
nd->nd_nam = nd->nd_nam2;
else
nd->nd_nam = slp->ns_nam;
2003-05-22 18:14:41 +04:00
/*
* Check to see if authorization is needed.
*/
if (nfsd->nfsd_flag & NFSD_NEEDAUTH) {
nfsd->nfsd_flag &= ~NFSD_NEEDAUTH;
nsd->nsd_haddr = mtod(nd->nd_nam,
struct sockaddr_in *)->sin_addr.s_addr;
nsd->nsd_authlen = nfsd->nfsd_authlen;
nsd->nsd_verflen = nfsd->nfsd_verflen;
if (!copyout(nfsd->nfsd_authstr,
nsd->nsd_authstr, nfsd->nfsd_authlen) &&
!copyout(nfsd->nfsd_verfstr,
nsd->nsd_verfstr, nfsd->nfsd_verflen) &&
!copyout(nsd, argp, sizeof (*nsd))) {
PRELE(l);
return (ENEEDAUTH);
}
cacherep = RC_DROPIT;
2003-05-22 18:14:41 +04:00
} else
cacherep = nfsrv_getcache(nd, slp, &mreq);
/*
* Check for just starting up for NQNFS and send
* fake "try again later" replies to the NQNFS clients.
*/
if (notstarted && nqnfsstarttime <= time.tv_sec) {
if (modify_flag) {
nqnfsstarttime =
time.tv_sec + nqsrv_writeslack;
modify_flag = 0;
} else
notstarted = 0;
}
if (notstarted) {
if ((nd->nd_flag & ND_NQNFS) == 0)
cacherep = RC_DROPIT;
else if (nd->nd_procnum != NFSPROC_WRITE) {
nd->nd_procnum = NFSPROC_NOOP;
nd->nd_repstat = NQNFS_TRYLATER;
cacherep = RC_DOIT;
} else
modify_flag = 1;
} else if (nfsd->nfsd_flag & NFSD_AUTHFAIL) {
nfsd->nfsd_flag &= ~NFSD_AUTHFAIL;
nd->nd_procnum = NFSPROC_NOOP;
2003-05-22 18:14:41 +04:00
nd->nd_repstat =
(NFSERR_AUTHERR | AUTH_TOOWEAK);
cacherep = RC_DOIT;
2003-05-22 18:14:41 +04:00
}
}
/*
* Loop to get all the write rpc relies that have been
* gathered together.
*/
do {
#ifdef DIAGNOSTIC
2003-05-22 18:14:41 +04:00
int lockcount;
#endif
2003-05-22 18:14:41 +04:00
switch (cacherep) {
case RC_DOIT:
#ifdef DIAGNOSTIC
/*
2003-05-22 18:14:41 +04:00
* NFS server procs should neither release
* locks already held, nor leave things
* locked. Catch this sooner, rather than
* later (when we try to relock something we
* already have locked). Careful inspection
* of the failing routine usually turns up the
* lock leak.. once we know what it is..
*/
2003-05-22 18:14:41 +04:00
lockcount = l->l_locks;
#endif
if (writes_todo || (!(nd->nd_flag & ND_NFSV3) &&
nd->nd_procnum == NFSPROC_WRITE &&
nfsrvw_procrastinate > 0 && !notstarted))
error = nfsrv_writegather(&nd, slp,
nfsd->nfsd_procp, &mreq);
else
error =
(*(nfsrv3_procs[nd->nd_procnum]))
(nd, slp, nfsd->nfsd_procp, &mreq);
#ifdef DIAGNOSTIC
if (l->l_locks != lockcount) {
/*
* If you see this panic, audit
* nfsrv3_procs[nd->nd_procnum] for
* vnode locking errors (usually, it's
* due to forgetting to vput()
* something).
*/
#ifdef DEBUG
2003-05-22 18:14:41 +04:00
extern void printlockedvnodes(void);
printlockedvnodes();
#endif
2003-05-22 18:14:41 +04:00
printf("nfsd: locking botch in op %d"
" (before %d, after %d)\n",
nd ? nd->nd_procnum : -1,
lockcount, l->l_locks);
}
#endif
2003-05-22 18:14:41 +04:00
if (mreq == NULL)
break;
if (error) {
if (nd->nd_procnum != NQNFSPROC_VACATED)
nfsstats.srv_errs++;
nfsrv_updatecache(nd, FALSE, mreq);
if (nd->nd_nam2)
m_freem(nd->nd_nam2);
break;
}
nfsstats.srvrpccnt[nd->nd_procnum]++;
nfsrv_updatecache(nd, TRUE, mreq);
nd->nd_mrep = (struct mbuf *)0;
case RC_REPLY:
m = mreq;
siz = 0;
while (m) {
siz += m->m_len;
m = m->m_next;
}
if (siz <= 0 || siz > NFS_MAXPACKET) {
printf("mbuf siz=%d\n",siz);
panic("Bad nfs svc reply");
}
m = mreq;
m->m_pkthdr.len = siz;
m->m_pkthdr.rcvif = (struct ifnet *)0;
/*
* For stream protocols, prepend a Sun RPC
* Record Mark.
*/
if (sotype == SOCK_STREAM) {
M_PREPEND(m, NFSX_UNSIGNED, M_WAIT);
*mtod(m, u_int32_t *) =
htonl(0x80000000 | siz);
}
if (solockp)
(void) nfs_sndlock(solockp, NULL);
if (slp->ns_flag & SLP_VALID) {
error =
nfs_send(so, nd->nd_nam2, m, NULL);
} else {
error = EPIPE;
m_freem(m);
}
if (nfsrtton)
nfsd_rt(sotype, nd, cacherep);
if (nd->nd_nam2)
2003-05-22 18:14:41 +04:00
m_free(nd->nd_nam2);
if (nd->nd_mrep)
m_freem(nd->nd_mrep);
if (error == EPIPE)
nfsrv_zapsock(slp);
if (solockp)
nfs_sndunlock(solockp);
if (error == EINTR || error == ERESTART) {
FREE(nd, M_NFSRVDESC);
nfsrv_slpderef(slp);
s = splsoftnet();
goto done;
}
1993-03-21 12:45:37 +03:00
break;
2003-05-22 18:14:41 +04:00
case RC_DROPIT:
if (nfsrtton)
nfsd_rt(sotype, nd, cacherep);
m_freem(nd->nd_mrep);
2003-05-22 18:14:41 +04:00
m_freem(nd->nd_nam2);
break;
}
if (nd) {
FREE(nd, M_NFSRVDESC);
2003-05-22 18:14:41 +04:00
nd = NULL;
1993-03-21 12:45:37 +03:00
}
2003-05-22 18:14:41 +04:00
/*
* Check to see if there are outstanding writes that
* need to be serviced.
*/
cur_usec = (u_quad_t)time.tv_sec * 1000000 +
(u_quad_t)time.tv_usec;
s = splsoftclock();
if (LIST_FIRST(&slp->ns_tq) &&
LIST_FIRST(&slp->ns_tq)->nd_time <= cur_usec) {
cacherep = RC_DOIT;
writes_todo = 1;
} else
writes_todo = 0;
splx(s);
} while (writes_todo);
1995-08-13 03:59:09 +04:00
s = splsoftnet();
if (nfsrv_dorec(slp, nfsd, &nd)) {
nfsd->nfsd_flag &= ~NFSD_REQINPROG;
nfsd->nfsd_slp = NULL;
nfsrv_slpderef(slp);
}
1993-03-21 12:45:37 +03:00
}
done:
2003-01-18 11:51:40 +03:00
PRELE(l);
TAILQ_REMOVE(&nfsd_head, nfsd, nfsd_chain);
splx(s);
free((caddr_t)nfsd, M_NFSD);
nsd->nsd_nfsd = (struct nfsd *)0;
if (--nfs_numnfsd == 0)
nfsrv_init(TRUE); /* Reinitialize everything */
1993-03-21 12:45:37 +03:00
return (error);
}
/*
* Shut down a socket associated with an nfssvc_sock structure.
* Should be called with the send lock set, if required.
* The trick here is to increment the sref at the start, so that the nfsds
* will stop using it and clear ns_flag at the end so that it will not be
* reassigned during cleanup.
*/
1996-02-10 00:48:19 +03:00
void
nfsrv_zapsock(slp)
2000-03-30 16:51:13 +04:00
struct nfssvc_sock *slp;
{
2000-03-30 16:51:13 +04:00
struct nfsuid *nuidp, *nnuidp;
struct nfsrv_descript *nwp, *nnwp;
struct socket *so;
struct file *fp;
int s;
slp->ns_flag &= ~SLP_ALLFLAGS;
fp = slp->ns_fp;
if (fp) {
2003-03-31 18:43:59 +04:00
simple_lock(&fp->f_slock);
FILE_USE(fp);
slp->ns_fp = (struct file *)0;
so = slp->ns_so;
so->so_upcall = NULL;
so->so_upcallarg = NULL;
so->so_rcv.sb_flags &= ~SB_UPCALL;
soshutdown(so, 2);
closef(fp, (struct proc *)0);
if (slp->ns_nam)
m_free(slp->ns_nam);
m_freem(slp->ns_raw);
m_freem(slp->ns_rec);
2003-04-02 19:14:19 +04:00
for (nuidp = TAILQ_FIRST(&slp->ns_uidlruhead); nuidp != 0;
1994-08-17 18:43:47 +04:00
nuidp = nnuidp) {
2003-04-02 19:14:19 +04:00
nnuidp = TAILQ_NEXT(nuidp, nu_lru);
1994-08-17 18:43:47 +04:00
LIST_REMOVE(nuidp, nu_hash);
TAILQ_REMOVE(&slp->ns_uidlruhead, nuidp, nu_lru);
if (nuidp->nu_flag & NU_NAM)
m_freem(nuidp->nu_nam);
1994-08-17 18:43:47 +04:00
free((caddr_t)nuidp, M_NFSUID);
}
s = splsoftclock();
2003-04-02 19:14:19 +04:00
for (nwp = LIST_FIRST(&slp->ns_tq); nwp; nwp = nnwp) {
nnwp = LIST_NEXT(nwp, nd_tq);
LIST_REMOVE(nwp, nd_tq);
FREE(nwp, M_NFSRVDESC);
}
LIST_INIT(&slp->ns_tq);
splx(s);
}
}
/*
* Derefence a server socket structure. If it has no more references and
* is no longer valid, you can throw it away.
*/
void
nfsrv_slpderef(slp)
2000-03-30 16:51:13 +04:00
struct nfssvc_sock *slp;
{
if (--(slp->ns_sref) == 0 && (slp->ns_flag & SLP_VALID) == 0) {
1994-08-17 18:43:47 +04:00
TAILQ_REMOVE(&nfssvc_sockhead, slp, ns_chain);
free((caddr_t)slp, M_NFSSVC);
}
}
/*
* Initialize the data structures for the server.
* Handshake with any new nfsds starting up to avoid any chance of
* corruption.
*/
void
nfsrv_init(terminating)
int terminating;
{
2000-03-30 16:51:13 +04:00
struct nfssvc_sock *slp, *nslp;
1994-08-17 18:43:47 +04:00
if (nfssvc_sockhead_flag & SLP_INIT)
panic("nfsd init");
1994-08-17 18:43:47 +04:00
nfssvc_sockhead_flag |= SLP_INIT;
if (terminating) {
2003-04-02 19:14:19 +04:00
for (slp = TAILQ_FIRST(&nfssvc_sockhead); slp != 0;
slp = nslp) {
nslp = TAILQ_NEXT(slp, ns_chain);
if (slp->ns_flag & SLP_VALID)
nfsrv_zapsock(slp);
1994-08-17 18:43:47 +04:00
TAILQ_REMOVE(&nfssvc_sockhead, slp, ns_chain);
free((caddr_t)slp, M_NFSSVC);
}
nfsrv_cleancache(); /* And clear out server cache */
} else
nfs_pub.np_valid = 0;
1994-08-17 18:43:47 +04:00
TAILQ_INIT(&nfssvc_sockhead);
nfssvc_sockhead_flag &= ~SLP_INIT;
if (nfssvc_sockhead_flag & SLP_WANTINIT) {
nfssvc_sockhead_flag &= ~SLP_WANTINIT;
wakeup((caddr_t)&nfssvc_sockhead);
}
TAILQ_INIT(&nfsd_head);
nfsd_head_flag &= ~NFSD_CHECKSLP;
nfs_udpsock = (struct nfssvc_sock *)
malloc(sizeof (struct nfssvc_sock), M_NFSSVC, M_WAITOK);
memset((caddr_t)nfs_udpsock, 0, sizeof (struct nfssvc_sock));
1994-08-17 18:43:47 +04:00
TAILQ_INIT(&nfs_udpsock->ns_uidlruhead);
TAILQ_INSERT_HEAD(&nfssvc_sockhead, nfs_udpsock, ns_chain);
#ifdef INET6
nfs_udp6sock = (struct nfssvc_sock *)
malloc(sizeof (struct nfssvc_sock), M_NFSSVC, M_WAITOK);
memset((caddr_t)nfs_udp6sock, 0, sizeof (struct nfssvc_sock));
TAILQ_INIT(&nfs_udp6sock->ns_uidlruhead);
TAILQ_INSERT_TAIL(&nfssvc_sockhead, nfs_udp6sock, ns_chain);
#endif
2000-11-25 02:30:02 +03:00
#ifdef ISO
nfs_cltpsock = (struct nfssvc_sock *)
malloc(sizeof (struct nfssvc_sock), M_NFSSVC, M_WAITOK);
memset((caddr_t)nfs_cltpsock, 0, sizeof (struct nfssvc_sock));
1994-08-17 18:43:47 +04:00
TAILQ_INIT(&nfs_cltpsock->ns_uidlruhead);
TAILQ_INSERT_TAIL(&nfssvc_sockhead, nfs_cltpsock, ns_chain);
2000-11-25 02:30:02 +03:00
#endif
}
/*
* Add entries to the server monitor log.
*/
static void
nfsd_rt(sotype, nd, cacherep)
int sotype;
2000-03-30 16:51:13 +04:00
struct nfsrv_descript *nd;
int cacherep;
{
2000-03-30 16:51:13 +04:00
struct drt *rt;
rt = &nfsdrt.drt[nfsdrt.pos];
if (cacherep == RC_DOIT)
rt->flag = 0;
else if (cacherep == RC_REPLY)
rt->flag = DRT_CACHEREPLY;
else
rt->flag = DRT_CACHEDROP;
if (sotype == SOCK_STREAM)
rt->flag |= DRT_TCP;
if (nd->nd_flag & ND_NQNFS)
rt->flag |= DRT_NQNFS;
else if (nd->nd_flag & ND_NFSV3)
rt->flag |= DRT_NFSV3;
rt->proc = nd->nd_procnum;
if (mtod(nd->nd_nam, struct sockaddr *)->sa_family == AF_INET)
rt->ipadr = mtod(nd->nd_nam, struct sockaddr_in *)->sin_addr.s_addr;
else
rt->ipadr = INADDR_ANY;
rt->resptime = ((time.tv_sec - nd->nd_starttime.tv_sec) * 1000000) +
(time.tv_usec - nd->nd_starttime.tv_usec);
rt->tstamp = time;
nfsdrt.pos = (nfsdrt.pos + 1) % NFSRTTLOGSIZ;
}
1993-04-11 00:19:19 +04:00
#endif /* NFSSERVER */
1997-01-31 05:58:48 +03:00
#ifdef NFS
int nfs_defect = 0;
1993-03-21 12:45:37 +03:00
/*
* Asynchronous I/O threads for client nfs.
* They do read-ahead and write-behind operations on the block I/O cache.
* Never returns unless it fails or gets killed.
1993-03-21 12:45:37 +03:00
*/
1996-02-10 00:48:19 +03:00
int
2003-01-18 11:51:40 +03:00
nfssvc_iod(l)
struct lwp *l;
1993-03-21 12:45:37 +03:00
{
2000-03-30 16:51:13 +04:00
struct buf *bp;
2003-04-09 18:22:33 +04:00
int i;
struct nfs_iod *myiod;
struct nfsmount *nmp;
int error = 0;
2003-01-18 11:51:40 +03:00
struct proc *p = l->l_proc;
1993-03-21 12:45:37 +03:00
/*
* Assign my position or return error if too many already running
*/
2003-04-09 18:22:33 +04:00
myiod = NULL;
1993-03-21 12:45:37 +03:00
for (i = 0; i < NFS_MAXASYNCDAEMON; i++)
2003-04-09 18:22:33 +04:00
if (nfs_asyncdaemon[i].nid_proc == NULL) {
myiod = &nfs_asyncdaemon[i];
1993-03-21 12:45:37 +03:00
break;
}
2003-04-09 18:22:33 +04:00
if (myiod == NULL)
1993-03-21 12:45:37 +03:00
return (EBUSY);
2003-04-09 18:22:33 +04:00
myiod->nid_proc = p;
1993-03-21 12:45:37 +03:00
nfs_numasync++;
2003-01-18 11:51:40 +03:00
PHOLD(l);
1993-03-21 12:45:37 +03:00
/*
2000-08-24 03:17:14 +04:00
* Just loop around doing our stuff until SIGKILL
1993-03-21 12:45:37 +03:00
*/
for (;;) {
2003-05-07 20:18:53 +04:00
while (/*CONSTCOND*/ TRUE) {
simple_lock(&myiod->nid_slock);
nmp = myiod->nid_mount;
if (nmp) {
simple_lock(&nmp->nm_slock);
if (!TAILQ_EMPTY(&nmp->nm_bufq)) {
simple_unlock(&myiod->nid_slock);
break;
}
2003-05-07 20:18:17 +04:00
nmp->nm_bufqiods--;
2003-05-07 20:18:53 +04:00
simple_unlock(&nmp->nm_slock);
}
2003-05-07 20:18:17 +04:00
myiod->nid_want = p;
myiod->nid_mount = NULL;
2003-05-07 20:18:53 +04:00
error = ltsleep(&myiod->nid_want,
PWAIT | PCATCH | PNORELOCK, "nfsidl", 0,
&myiod->nid_slock);
if (error)
goto quit;
}
2003-05-07 20:18:53 +04:00
while ((bp = TAILQ_FIRST(&nmp->nm_bufq)) != NULL) {
2003-05-07 20:18:17 +04:00
/* Take one off the front of the list */
TAILQ_REMOVE(&nmp->nm_bufq, bp, b_freelist);
nmp->nm_bufqlen--;
if (nmp->nm_bufqwant &&
nmp->nm_bufqlen < 2 * nfs_numasync) {
nmp->nm_bufqwant = FALSE;
wakeup(&nmp->nm_bufq);
}
2003-05-07 20:18:53 +04:00
simple_unlock(&nmp->nm_slock);
2003-05-07 20:18:17 +04:00
(void) nfs_doio(bp, NULL);
2003-05-07 20:18:53 +04:00
simple_lock(&nmp->nm_slock);
2003-05-07 20:18:17 +04:00
/*
* If there are more than one iod on this mount, then defect
* so that the iods can be shared out fairly between the mounts
*/
if (nfs_defect && nmp->nm_bufqiods > 1) {
myiod->nid_mount = NULL;
nmp->nm_bufqiods--;
break;
}
}
2003-05-07 20:18:53 +04:00
simple_unlock(&nmp->nm_slock);
1993-03-21 12:45:37 +03:00
}
2003-05-07 20:18:53 +04:00
quit:
2003-01-18 11:51:40 +03:00
PRELE(l);
if (nmp)
nmp->nm_bufqiods--;
2003-04-09 18:22:33 +04:00
myiod->nid_want = NULL;
myiod->nid_mount = NULL;
myiod->nid_proc = NULL;
nfs_numasync--;
2003-05-07 20:18:53 +04:00
return error;
}
void
nfs_iodinit()
{
int i;
for (i = 0; i < NFS_MAXASYNCDAEMON; i++)
simple_lock_init(&nfs_asyncdaemon[i].nid_slock);
1993-03-21 12:45:37 +03:00
}
1993-04-11 00:19:19 +04:00
void
start_nfsio(arg)
void *arg;
{
2003-01-18 11:51:40 +03:00
nfssvc_iod(curlwp);
kthread_exit(0);
}
void
nfs_getset_niothreads(set)
int set;
{
int i, have, start;
for (have = 0, i = 0; i < NFS_MAXASYNCDAEMON; i++)
2003-04-09 18:22:33 +04:00
if (nfs_asyncdaemon[i].nid_proc != NULL)
have++;
if (set) {
/* clamp to sane range */
nfs_niothreads = max(0, min(nfs_niothreads, NFS_MAXASYNCDAEMON));
start = nfs_niothreads - have;
while (start > 0) {
kthread_create1(start_nfsio, NULL, NULL, "nfsio");
start--;
}
for (i = 0; (start < 0) && (i < NFS_MAXASYNCDAEMON); i++)
2003-04-09 18:22:33 +04:00
if (nfs_asyncdaemon[i].nid_proc != NULL) {
psignal(nfs_asyncdaemon[i].nid_proc, SIGKILL);
start++;
}
} else {
if (nfs_niothreads >= 0)
nfs_niothreads = have;
}
}
/*
* Get an authorization string for the uid by having the mount_nfs sitting
* on this mount point porpous out of the kernel and do it.
*/
1996-02-10 00:48:19 +03:00
int
nfs_getauth(nmp, rep, cred, auth_str, auth_len, verf_str, verf_len, key)
2000-03-30 16:51:13 +04:00
struct nfsmount *nmp;
struct nfsreq *rep;
struct ucred *cred;
char **auth_str;
int *auth_len;
char *verf_str;
int *verf_len;
NFSKERBKEY_T key; /* return session key */
{
int error = 0;
while ((nmp->nm_iflag & NFSMNT_WAITAUTH) == 0) {
nmp->nm_iflag |= NFSMNT_WANTAUTH;
(void) tsleep((caddr_t)&nmp->nm_authtype, PSOCK,
"nfsauth1", 2 * hz);
1996-02-10 00:48:19 +03:00
error = nfs_sigintr(nmp, rep, rep->r_procp);
if (error) {
nmp->nm_iflag &= ~NFSMNT_WANTAUTH;
return (error);
}
}
nmp->nm_iflag &= ~(NFSMNT_WAITAUTH | NFSMNT_WANTAUTH);
nmp->nm_authstr = *auth_str = (char *)malloc(RPCAUTH_MAXSIZ, M_TEMP, M_WAITOK);
nmp->nm_authlen = RPCAUTH_MAXSIZ;
nmp->nm_verfstr = verf_str;
nmp->nm_verflen = *verf_len;
nmp->nm_authuid = cred->cr_uid;
wakeup((caddr_t)&nmp->nm_authstr);
1993-04-11 00:19:19 +04:00
/*
* And wait for mount_nfs to do its stuff.
*/
while ((nmp->nm_iflag & NFSMNT_HASAUTH) == 0 && error == 0) {
(void) tsleep((caddr_t)&nmp->nm_authlen, PSOCK,
"nfsauth2", 2 * hz);
error = nfs_sigintr(nmp, rep, rep->r_procp);
}
if (nmp->nm_iflag & NFSMNT_AUTHERR) {
nmp->nm_iflag &= ~NFSMNT_AUTHERR;
error = EAUTH;
}
if (error)
free((caddr_t)*auth_str, M_TEMP);
else {
*auth_len = nmp->nm_authlen;
*verf_len = nmp->nm_verflen;
memcpy(key, nmp->nm_key, sizeof (NFSKERBKEY_T));
}
nmp->nm_iflag &= ~NFSMNT_HASAUTH;
nmp->nm_iflag |= NFSMNT_WAITAUTH;
if (nmp->nm_iflag & NFSMNT_WANTAUTH) {
nmp->nm_iflag &= ~NFSMNT_WANTAUTH;
wakeup((caddr_t)&nmp->nm_authtype);
}
return (error);
}
/*
* Get a nickname authenticator and verifier.
*/
int
nfs_getnickauth(nmp, cred, auth_str, auth_len, verf_str, verf_len)
struct nfsmount *nmp;
struct ucred *cred;
char **auth_str;
int *auth_len;
char *verf_str;
int verf_len;
{
2000-03-30 16:51:13 +04:00
struct nfsuid *nuidp;
u_int32_t *nickp, *verfp;
struct timeval ktvin, ktvout;
#ifdef DIAGNOSTIC
if (verf_len < (4 * NFSX_UNSIGNED))
panic("nfs_getnickauth verf too small");
#endif
2003-04-02 19:14:19 +04:00
LIST_FOREACH(nuidp, NMUIDHASH(nmp, cred->cr_uid), nu_hash) {
if (nuidp->nu_cr.cr_uid == cred->cr_uid)
break;
}
if (!nuidp || nuidp->nu_expire < time.tv_sec)
return (EACCES);
/*
* Move to the end of the lru list (end of lru == most recently used).
*/
TAILQ_REMOVE(&nmp->nm_uidlruhead, nuidp, nu_lru);
TAILQ_INSERT_TAIL(&nmp->nm_uidlruhead, nuidp, nu_lru);
nickp = (u_int32_t *)malloc(2 * NFSX_UNSIGNED, M_TEMP, M_WAITOK);
*nickp++ = txdr_unsigned(RPCAKN_NICKNAME);
*nickp = txdr_unsigned(nuidp->nu_nickname);
*auth_str = (char *)nickp;
*auth_len = 2 * NFSX_UNSIGNED;
/*
* Now we must encrypt the verifier and package it up.
*/
verfp = (u_int32_t *)verf_str;
*verfp++ = txdr_unsigned(RPCAKN_NICKNAME);
if (time.tv_sec > nuidp->nu_timestamp.tv_sec ||
(time.tv_sec == nuidp->nu_timestamp.tv_sec &&
time.tv_usec > nuidp->nu_timestamp.tv_usec))
nuidp->nu_timestamp = time;
else
nuidp->nu_timestamp.tv_usec++;
ktvin.tv_sec = txdr_unsigned(nuidp->nu_timestamp.tv_sec);
ktvin.tv_usec = txdr_unsigned(nuidp->nu_timestamp.tv_usec);
/*
* Now encrypt the timestamp verifier in ecb mode using the session
* key.
*/
#ifdef NFSKERB
XXX
#endif
*verfp++ = ktvout.tv_sec;
*verfp++ = ktvout.tv_usec;
*verfp = 0;
return (0);
}
/*
* Save the current nickname in a hash list entry on the mount point.
*/
int
nfs_savenickauth(nmp, cred, len, key, mdp, dposp, mrep)
2000-03-30 16:51:13 +04:00
struct nfsmount *nmp;
struct ucred *cred;
int len;
NFSKERBKEY_T key;
struct mbuf **mdp;
char **dposp;
struct mbuf *mrep;
{
2000-03-30 16:51:13 +04:00
struct nfsuid *nuidp;
u_int32_t *tl;
int32_t t1;
struct mbuf *md = *mdp;
struct timeval ktvin, ktvout;
u_int32_t nick;
char *dpos = *dposp, *cp2;
int deltasec, error = 0;
if (len == (3 * NFSX_UNSIGNED)) {
nfsm_dissect(tl, u_int32_t *, 3 * NFSX_UNSIGNED);
ktvin.tv_sec = *tl++;
ktvin.tv_usec = *tl++;
nick = fxdr_unsigned(u_int32_t, *tl);
/*
* Decrypt the timestamp in ecb mode.
*/
#ifdef NFSKERB
XXX
#endif
ktvout.tv_sec = fxdr_unsigned(long, ktvout.tv_sec);
ktvout.tv_usec = fxdr_unsigned(long, ktvout.tv_usec);
deltasec = time.tv_sec - ktvout.tv_sec;
if (deltasec < 0)
deltasec = -deltasec;
/*
* If ok, add it to the hash list for the mount point.
*/
if (deltasec <= NFS_KERBCLOCKSKEW) {
if (nmp->nm_numuids < nuidhash_max) {
nmp->nm_numuids++;
nuidp = (struct nfsuid *)
malloc(sizeof (struct nfsuid), M_NFSUID,
M_WAITOK);
} else {
2003-04-02 19:14:19 +04:00
nuidp = TAILQ_FIRST(&nmp->nm_uidlruhead);
LIST_REMOVE(nuidp, nu_hash);
TAILQ_REMOVE(&nmp->nm_uidlruhead, nuidp,
nu_lru);
}
nuidp->nu_flag = 0;
nuidp->nu_cr.cr_uid = cred->cr_uid;
nuidp->nu_expire = time.tv_sec + NFS_KERBTTL;
nuidp->nu_timestamp = ktvout;
nuidp->nu_nickname = nick;
memcpy(nuidp->nu_key, key, sizeof (NFSKERBKEY_T));
TAILQ_INSERT_TAIL(&nmp->nm_uidlruhead, nuidp,
nu_lru);
LIST_INSERT_HEAD(NMUIDHASH(nmp, cred->cr_uid),
nuidp, nu_hash);
}
} else
nfsm_adv(nfsm_rndup(len));
nfsmout:
*mdp = md;
*dposp = dpos;
return (error);
}
1997-01-31 05:58:48 +03:00
#endif /* NFS */