xref: /dflybsd-src/sys/vfs/nfs/nfs_kerb.c (revision fcf6efefc03a35111797b109fa4994034ebe39ba)
1e07fef60SMatthew Dillon /*
2e07fef60SMatthew Dillon  * Copyright (c) 1992, 1993
3e07fef60SMatthew Dillon  *	The Regents of the University of California.  All rights reserved.
4e07fef60SMatthew Dillon  *
5e07fef60SMatthew Dillon  * This code is derived from software contributed to Berkeley by
6e07fef60SMatthew Dillon  * Rick Macklem at The University of Guelph.
7e07fef60SMatthew Dillon  *
8e07fef60SMatthew Dillon  * Redistribution and use in source and binary forms, with or without
9e07fef60SMatthew Dillon  * modification, are permitted provided that the following conditions
10e07fef60SMatthew Dillon  * are met:
11e07fef60SMatthew Dillon  * 1. Redistributions of source code must retain the above copyright
12e07fef60SMatthew Dillon  *    notice, this list of conditions and the following disclaimer.
13e07fef60SMatthew Dillon  * 2. Redistributions in binary form must reproduce the above copyright
14e07fef60SMatthew Dillon  *    notice, this list of conditions and the following disclaimer in the
15e07fef60SMatthew Dillon  *    documentation and/or other materials provided with the distribution.
16dc71b7abSJustin C. Sherrill  * 3. Neither the name of the University nor the names of its contributors
17e07fef60SMatthew Dillon  *    may be used to endorse or promote products derived from this software
18e07fef60SMatthew Dillon  *    without specific prior written permission.
19e07fef60SMatthew Dillon  *
20e07fef60SMatthew Dillon  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21e07fef60SMatthew Dillon  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22e07fef60SMatthew Dillon  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23e07fef60SMatthew Dillon  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24e07fef60SMatthew Dillon  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25e07fef60SMatthew Dillon  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26e07fef60SMatthew Dillon  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27e07fef60SMatthew Dillon  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28e07fef60SMatthew Dillon  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29e07fef60SMatthew Dillon  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30e07fef60SMatthew Dillon  * SUCH DAMAGE.
31e07fef60SMatthew Dillon  *
32e07fef60SMatthew Dillon  *	@(#)nfs_nqlease.c	8.9 (Berkeley) 5/20/95
33e07fef60SMatthew Dillon  * $FreeBSD: src/sys/nfs/nfs_nqlease.c,v 1.50 2000/02/13 03:32:05 peter Exp $
34e07fef60SMatthew Dillon  */
35e07fef60SMatthew Dillon 
36e07fef60SMatthew Dillon #include <sys/param.h>
37e07fef60SMatthew Dillon #include <sys/vnode.h>
38e07fef60SMatthew Dillon #include <sys/malloc.h>
39e07fef60SMatthew Dillon #include <sys/mount.h>
40e07fef60SMatthew Dillon #include <sys/kernel.h>
41e07fef60SMatthew Dillon #include <sys/proc.h>
42e07fef60SMatthew Dillon #include <sys/systm.h>
43e07fef60SMatthew Dillon #include <sys/mbuf.h>
44e07fef60SMatthew Dillon #include <sys/socket.h>
45e07fef60SMatthew Dillon #include <sys/socketvar.h>
46e07fef60SMatthew Dillon #include <sys/protosw.h>
47e07fef60SMatthew Dillon 
48e07fef60SMatthew Dillon #include <netinet/in.h>
49e07fef60SMatthew Dillon #include "rpcv2.h"
50e07fef60SMatthew Dillon #include "nfsproto.h"
51e07fef60SMatthew Dillon #include "nfs.h"
52e07fef60SMatthew Dillon #include "nfsm_subs.h"
53e07fef60SMatthew Dillon #include "xdr_subs.h"
54e07fef60SMatthew Dillon #include "nfsmount.h"
55e07fef60SMatthew Dillon #include "nfsnode.h"
56e07fef60SMatthew Dillon 
57e07fef60SMatthew Dillon #define TRUE	1
58e07fef60SMatthew Dillon #define	FALSE	0
59e07fef60SMatthew Dillon 
60e07fef60SMatthew Dillon #ifndef NFS_NOSERVER
61e07fef60SMatthew Dillon 
62e07fef60SMatthew Dillon /*
63e07fef60SMatthew Dillon  * Nqnfs client helper daemon. Runs once a second to expire leases.
64e07fef60SMatthew Dillon  * It also get authorization strings for "kerb" mounts.
65e07fef60SMatthew Dillon  * It must start at the beginning of the list again after any potential
66e07fef60SMatthew Dillon  * "sleep" since nfs_reclaim() called from vclean() can pull a node off
67e07fef60SMatthew Dillon  * the list asynchronously.
68e07fef60SMatthew Dillon  */
69e07fef60SMatthew Dillon int
nfs_clientd(struct nfsmount * nmp,struct ucred * cred,struct nfsd_cargs * ncd,int flag,caddr_t argp,struct thread * td)70e07fef60SMatthew Dillon nfs_clientd(struct nfsmount *nmp, struct ucred *cred, struct nfsd_cargs *ncd,
71e07fef60SMatthew Dillon 	    int flag, caddr_t argp, struct thread *td)
72e07fef60SMatthew Dillon {
73e07fef60SMatthew Dillon 	struct nfsuid *nuidp, *nnuidp;
74e07fef60SMatthew Dillon 	int error = 0;
75e07fef60SMatthew Dillon 
76e07fef60SMatthew Dillon 	/*
77e07fef60SMatthew Dillon 	 * If an authorization string is being passed in, get it.
78e07fef60SMatthew Dillon 	 */
79e07fef60SMatthew Dillon 	if ((flag & NFSSVC_GOTAUTH) &&
80e07fef60SMatthew Dillon 	    (nmp->nm_state & (NFSSTA_WAITAUTH | NFSSTA_DISMNT)) == 0) {
81e07fef60SMatthew Dillon 	    if (nmp->nm_state & NFSSTA_HASAUTH)
82e07fef60SMatthew Dillon 		panic("cld kerb");
83e07fef60SMatthew Dillon 	    if ((flag & NFSSVC_AUTHINFAIL) == 0) {
84e07fef60SMatthew Dillon 		if (ncd->ncd_authlen <= nmp->nm_authlen &&
85e07fef60SMatthew Dillon 		    ncd->ncd_verflen <= nmp->nm_verflen &&
86e07fef60SMatthew Dillon 		    !copyin(ncd->ncd_authstr,nmp->nm_authstr,ncd->ncd_authlen)&&
87e07fef60SMatthew Dillon 		    !copyin(ncd->ncd_verfstr,nmp->nm_verfstr,ncd->ncd_verflen)){
88e07fef60SMatthew Dillon 		    nmp->nm_authtype = ncd->ncd_authtype;
89e07fef60SMatthew Dillon 		    nmp->nm_authlen = ncd->ncd_authlen;
90e07fef60SMatthew Dillon 		    nmp->nm_verflen = ncd->ncd_verflen;
91e07fef60SMatthew Dillon #ifdef NFSKERB
92e07fef60SMatthew Dillon 		    nmp->nm_key = ncd->ncd_key;
93e07fef60SMatthew Dillon #endif
94e07fef60SMatthew Dillon 		} else
95e07fef60SMatthew Dillon 		    nmp->nm_state |= NFSSTA_AUTHERR;
96e07fef60SMatthew Dillon 	    } else
97e07fef60SMatthew Dillon 		nmp->nm_state |= NFSSTA_AUTHERR;
98e07fef60SMatthew Dillon 	    nmp->nm_state |= NFSSTA_HASAUTH;
99e07fef60SMatthew Dillon 	    wakeup((caddr_t)&nmp->nm_authlen);
100e07fef60SMatthew Dillon 	} else
101e07fef60SMatthew Dillon 	    nmp->nm_state |= NFSSTA_WAITAUTH;
102e07fef60SMatthew Dillon 
103e07fef60SMatthew Dillon 	/*
104e07fef60SMatthew Dillon 	 * Loop every second updating queue until there is a termination sig.
105e07fef60SMatthew Dillon 	 */
106e07fef60SMatthew Dillon 	while ((nmp->nm_state & NFSSTA_DISMNT) == 0) {
107e07fef60SMatthew Dillon 	    /*
108e07fef60SMatthew Dillon 	     * Get an authorization string, if required.
109e07fef60SMatthew Dillon 	     */
110e07fef60SMatthew Dillon 	    if ((nmp->nm_state & (NFSSTA_WAITAUTH | NFSSTA_DISMNT | NFSSTA_HASAUTH)) == 0) {
111e07fef60SMatthew Dillon 		ncd->ncd_authuid = nmp->nm_authuid;
112e07fef60SMatthew Dillon 		if (copyout((caddr_t)ncd, argp, sizeof (struct nfsd_cargs)))
113e07fef60SMatthew Dillon 			nmp->nm_state |= NFSSTA_WAITAUTH;
114e07fef60SMatthew Dillon 		else
115e07fef60SMatthew Dillon 			return (ENEEDAUTH);
116e07fef60SMatthew Dillon 	    }
117e07fef60SMatthew Dillon 
118e07fef60SMatthew Dillon 	    /*
119e07fef60SMatthew Dillon 	     * Wait a bit (no pun) and do it again.
120e07fef60SMatthew Dillon 	     */
121e07fef60SMatthew Dillon 	    if ((nmp->nm_state & NFSSTA_DISMNT) == 0 &&
122e07fef60SMatthew Dillon 		(nmp->nm_state & (NFSSTA_WAITAUTH | NFSSTA_HASAUTH))) {
123e07fef60SMatthew Dillon 		    error = tsleep((caddr_t)&nmp->nm_authstr, PCATCH,
124e07fef60SMatthew Dillon 			"nqnfstimr", hz / 3);
125e07fef60SMatthew Dillon 		    if (error == EINTR || error == ERESTART)
126*51a529dbSMatthew Dillon 			(void) dounmount(nmp->nm_mountp, 0, 0);
127e07fef60SMatthew Dillon 	    }
128e07fef60SMatthew Dillon 	}
129e07fef60SMatthew Dillon 
130e07fef60SMatthew Dillon 	/*
131e07fef60SMatthew Dillon 	 * Finally, we can free up the mount structure.
132e07fef60SMatthew Dillon 	 */
133e07fef60SMatthew Dillon 	TAILQ_FOREACH_MUTABLE(nuidp, &nmp->nm_uidlruhead, nu_lru, nnuidp) {
134e07fef60SMatthew Dillon 		LIST_REMOVE(nuidp, nu_hash);
135e07fef60SMatthew Dillon 		TAILQ_REMOVE(&nmp->nm_uidlruhead, nuidp, nu_lru);
136efda3bd0SMatthew Dillon 		kfree((caddr_t)nuidp, M_NFSUID);
137e07fef60SMatthew Dillon 	}
138e07fef60SMatthew Dillon 	nfs_free_mount(nmp);
139e07fef60SMatthew Dillon 	if (error == EWOULDBLOCK)
140e07fef60SMatthew Dillon 		error = 0;
141e07fef60SMatthew Dillon 	return (error);
142e07fef60SMatthew Dillon }
143e07fef60SMatthew Dillon 
144e07fef60SMatthew Dillon #endif /* NFS_NOSERVER */
145e07fef60SMatthew Dillon 
146