nfs_iod.c revision 1.1.8.3 1 1.1.8.3 skrll /* $NetBSD: nfs_iod.c,v 1.1.8.3 2009/04/28 07:37:44 skrll Exp $ */
2 1.1.8.2 skrll
3 1.1.8.2 skrll /*
4 1.1.8.2 skrll * Copyright (c) 1989, 1993
5 1.1.8.2 skrll * The Regents of the University of California. All rights reserved.
6 1.1.8.2 skrll *
7 1.1.8.2 skrll * This code is derived from software contributed to Berkeley by
8 1.1.8.2 skrll * Rick Macklem at The University of Guelph.
9 1.1.8.2 skrll *
10 1.1.8.2 skrll * Redistribution and use in source and binary forms, with or without
11 1.1.8.2 skrll * modification, are permitted provided that the following conditions
12 1.1.8.2 skrll * are met:
13 1.1.8.2 skrll * 1. Redistributions of source code must retain the above copyright
14 1.1.8.2 skrll * notice, this list of conditions and the following disclaimer.
15 1.1.8.2 skrll * 2. Redistributions in binary form must reproduce the above copyright
16 1.1.8.2 skrll * notice, this list of conditions and the following disclaimer in the
17 1.1.8.2 skrll * documentation and/or other materials provided with the distribution.
18 1.1.8.2 skrll * 3. Neither the name of the University nor the names of its contributors
19 1.1.8.2 skrll * may be used to endorse or promote products derived from this software
20 1.1.8.2 skrll * without specific prior written permission.
21 1.1.8.2 skrll *
22 1.1.8.2 skrll * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 1.1.8.2 skrll * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 1.1.8.2 skrll * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 1.1.8.2 skrll * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 1.1.8.2 skrll * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 1.1.8.2 skrll * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 1.1.8.2 skrll * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 1.1.8.2 skrll * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 1.1.8.2 skrll * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 1.1.8.2 skrll * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 1.1.8.2 skrll * SUCH DAMAGE.
33 1.1.8.2 skrll *
34 1.1.8.2 skrll * @(#)nfs_syscalls.c 8.5 (Berkeley) 3/30/95
35 1.1.8.2 skrll */
36 1.1.8.2 skrll
37 1.1.8.2 skrll #include <sys/cdefs.h>
38 1.1.8.3 skrll __KERNEL_RCSID(0, "$NetBSD: nfs_iod.c,v 1.1.8.3 2009/04/28 07:37:44 skrll Exp $");
39 1.1.8.2 skrll
40 1.1.8.2 skrll #include <sys/param.h>
41 1.1.8.2 skrll #include <sys/systm.h>
42 1.1.8.2 skrll #include <sys/kernel.h>
43 1.1.8.2 skrll #include <sys/file.h>
44 1.1.8.2 skrll #include <sys/stat.h>
45 1.1.8.2 skrll #include <sys/vnode.h>
46 1.1.8.2 skrll #include <sys/mount.h>
47 1.1.8.2 skrll #include <sys/proc.h>
48 1.1.8.2 skrll #include <sys/uio.h>
49 1.1.8.2 skrll #include <sys/malloc.h>
50 1.1.8.2 skrll #include <sys/kmem.h>
51 1.1.8.2 skrll #include <sys/buf.h>
52 1.1.8.2 skrll #include <sys/mbuf.h>
53 1.1.8.2 skrll #include <sys/socket.h>
54 1.1.8.2 skrll #include <sys/socketvar.h>
55 1.1.8.2 skrll #include <sys/signalvar.h>
56 1.1.8.2 skrll #include <sys/domain.h>
57 1.1.8.2 skrll #include <sys/protosw.h>
58 1.1.8.2 skrll #include <sys/namei.h>
59 1.1.8.2 skrll #include <sys/syslog.h>
60 1.1.8.2 skrll #include <sys/filedesc.h>
61 1.1.8.2 skrll #include <sys/kthread.h>
62 1.1.8.2 skrll #include <sys/kauth.h>
63 1.1.8.2 skrll #include <sys/syscallargs.h>
64 1.1.8.2 skrll
65 1.1.8.2 skrll #include <netinet/in.h>
66 1.1.8.2 skrll #include <netinet/tcp.h>
67 1.1.8.2 skrll #include <nfs/xdr_subs.h>
68 1.1.8.2 skrll #include <nfs/rpcv2.h>
69 1.1.8.2 skrll #include <nfs/nfsproto.h>
70 1.1.8.2 skrll #include <nfs/nfs.h>
71 1.1.8.2 skrll #include <nfs/nfsm_subs.h>
72 1.1.8.2 skrll #include <nfs/nfsrvcache.h>
73 1.1.8.2 skrll #include <nfs/nfsmount.h>
74 1.1.8.2 skrll #include <nfs/nfsnode.h>
75 1.1.8.2 skrll #include <nfs/nfsrtt.h>
76 1.1.8.2 skrll #include <nfs/nfs_var.h>
77 1.1.8.2 skrll
78 1.1.8.2 skrll int nuidhash_max = NFS_MAXUIDHASH;
79 1.1.8.2 skrll
80 1.1.8.2 skrll /*
81 1.1.8.2 skrll * locking order:
82 1.1.8.2 skrll * nfs_iodlist_lock -> nid_lock -> nm_lock
83 1.1.8.2 skrll */
84 1.1.8.2 skrll kmutex_t nfs_iodlist_lock;
85 1.1.8.2 skrll struct nfs_iodlist nfs_iodlist_idle;
86 1.1.8.2 skrll struct nfs_iodlist nfs_iodlist_all;
87 1.1.8.2 skrll int nfs_niothreads = -1; /* == "0, and has never been set" */
88 1.1.8.2 skrll int nfs_defect = 0;
89 1.1.8.2 skrll
90 1.1.8.2 skrll /*
91 1.1.8.2 skrll * Asynchronous I/O threads for client nfs.
92 1.1.8.2 skrll * They do read-ahead and write-behind operations on the block I/O cache.
93 1.1.8.2 skrll * Never returns unless it fails or gets killed.
94 1.1.8.2 skrll */
95 1.1.8.2 skrll
96 1.1.8.2 skrll static void
97 1.1.8.2 skrll nfssvc_iod(void *arg)
98 1.1.8.2 skrll {
99 1.1.8.2 skrll struct buf *bp;
100 1.1.8.2 skrll struct nfs_iod *myiod;
101 1.1.8.2 skrll struct nfsmount *nmp;
102 1.1.8.2 skrll
103 1.1.8.2 skrll myiod = kmem_alloc(sizeof(*myiod), KM_SLEEP);
104 1.1.8.2 skrll mutex_init(&myiod->nid_lock, MUTEX_DEFAULT, IPL_NONE);
105 1.1.8.2 skrll cv_init(&myiod->nid_cv, "nfsiod");
106 1.1.8.2 skrll myiod->nid_exiting = false;
107 1.1.8.2 skrll myiod->nid_mount = NULL;
108 1.1.8.2 skrll mutex_enter(&nfs_iodlist_lock);
109 1.1.8.2 skrll LIST_INSERT_HEAD(&nfs_iodlist_all, myiod, nid_all);
110 1.1.8.2 skrll mutex_exit(&nfs_iodlist_lock);
111 1.1.8.2 skrll
112 1.1.8.2 skrll for (;;) {
113 1.1.8.2 skrll mutex_enter(&nfs_iodlist_lock);
114 1.1.8.2 skrll LIST_INSERT_HEAD(&nfs_iodlist_idle, myiod, nid_idle);
115 1.1.8.2 skrll mutex_exit(&nfs_iodlist_lock);
116 1.1.8.2 skrll
117 1.1.8.2 skrll mutex_enter(&myiod->nid_lock);
118 1.1.8.2 skrll while (/*CONSTCOND*/ true) {
119 1.1.8.2 skrll nmp = myiod->nid_mount;
120 1.1.8.2 skrll if (nmp) {
121 1.1.8.2 skrll myiod->nid_mount = NULL;
122 1.1.8.2 skrll break;
123 1.1.8.2 skrll }
124 1.1.8.2 skrll if (__predict_false(myiod->nid_exiting)) {
125 1.1.8.2 skrll /*
126 1.1.8.2 skrll * drop nid_lock to preserve locking order.
127 1.1.8.2 skrll */
128 1.1.8.2 skrll mutex_exit(&myiod->nid_lock);
129 1.1.8.2 skrll mutex_enter(&nfs_iodlist_lock);
130 1.1.8.2 skrll mutex_enter(&myiod->nid_lock);
131 1.1.8.2 skrll /*
132 1.1.8.2 skrll * recheck nid_mount because nfs_asyncio can
133 1.1.8.2 skrll * pick us in the meantime as we are still on
134 1.1.8.2 skrll * nfs_iodlist_lock.
135 1.1.8.2 skrll */
136 1.1.8.2 skrll if (myiod->nid_mount != NULL) {
137 1.1.8.2 skrll mutex_exit(&nfs_iodlist_lock);
138 1.1.8.2 skrll continue;
139 1.1.8.2 skrll }
140 1.1.8.2 skrll LIST_REMOVE(myiod, nid_idle);
141 1.1.8.2 skrll mutex_exit(&nfs_iodlist_lock);
142 1.1.8.2 skrll goto quit;
143 1.1.8.2 skrll }
144 1.1.8.2 skrll cv_wait(&myiod->nid_cv, &myiod->nid_lock);
145 1.1.8.2 skrll }
146 1.1.8.2 skrll mutex_exit(&myiod->nid_lock);
147 1.1.8.2 skrll
148 1.1.8.2 skrll mutex_enter(&nmp->nm_lock);
149 1.1.8.2 skrll while ((bp = TAILQ_FIRST(&nmp->nm_bufq)) != NULL) {
150 1.1.8.2 skrll /* Take one off the front of the list */
151 1.1.8.2 skrll TAILQ_REMOVE(&nmp->nm_bufq, bp, b_freelist);
152 1.1.8.2 skrll nmp->nm_bufqlen--;
153 1.1.8.2 skrll if (nmp->nm_bufqlen < 2 * nmp->nm_bufqiods) {
154 1.1.8.2 skrll cv_broadcast(&nmp->nm_aiocv);
155 1.1.8.2 skrll }
156 1.1.8.2 skrll mutex_exit(&nmp->nm_lock);
157 1.1.8.2 skrll KERNEL_LOCK(1, curlwp);
158 1.1.8.2 skrll (void)nfs_doio(bp);
159 1.1.8.2 skrll KERNEL_UNLOCK_LAST(curlwp);
160 1.1.8.2 skrll mutex_enter(&nmp->nm_lock);
161 1.1.8.2 skrll /*
162 1.1.8.2 skrll * If there are more than one iod on this mount,
163 1.1.8.2 skrll * then defect so that the iods can be shared out
164 1.1.8.2 skrll * fairly between the mounts
165 1.1.8.2 skrll */
166 1.1.8.2 skrll if (nfs_defect && nmp->nm_bufqiods > 1) {
167 1.1.8.2 skrll break;
168 1.1.8.2 skrll }
169 1.1.8.2 skrll }
170 1.1.8.2 skrll KASSERT(nmp->nm_bufqiods > 0);
171 1.1.8.2 skrll nmp->nm_bufqiods--;
172 1.1.8.2 skrll mutex_exit(&nmp->nm_lock);
173 1.1.8.2 skrll }
174 1.1.8.2 skrll quit:
175 1.1.8.2 skrll KASSERT(myiod->nid_mount == NULL);
176 1.1.8.2 skrll mutex_exit(&myiod->nid_lock);
177 1.1.8.2 skrll
178 1.1.8.2 skrll cv_destroy(&myiod->nid_cv);
179 1.1.8.2 skrll mutex_destroy(&myiod->nid_lock);
180 1.1.8.2 skrll kmem_free(myiod, sizeof(*myiod));
181 1.1.8.2 skrll
182 1.1.8.2 skrll kthread_exit(0);
183 1.1.8.2 skrll }
184 1.1.8.2 skrll
185 1.1.8.2 skrll void
186 1.1.8.2 skrll nfs_iodinit(void)
187 1.1.8.2 skrll {
188 1.1.8.2 skrll
189 1.1.8.2 skrll mutex_init(&nfs_iodlist_lock, MUTEX_DEFAULT, IPL_NONE);
190 1.1.8.2 skrll LIST_INIT(&nfs_iodlist_all);
191 1.1.8.2 skrll LIST_INIT(&nfs_iodlist_idle);
192 1.1.8.2 skrll }
193 1.1.8.2 skrll
194 1.1.8.2 skrll void
195 1.1.8.2 skrll nfs_iodfini(void)
196 1.1.8.2 skrll {
197 1.1.8.2 skrll int error;
198 1.1.8.2 skrll
199 1.1.8.2 skrll error = nfs_set_niothreads(0);
200 1.1.8.2 skrll KASSERT(error == 0);
201 1.1.8.2 skrll mutex_destroy(&nfs_iodlist_lock);
202 1.1.8.2 skrll }
203 1.1.8.2 skrll
204 1.1.8.2 skrll int
205 1.1.8.2 skrll nfs_set_niothreads(int newval)
206 1.1.8.2 skrll {
207 1.1.8.2 skrll struct nfs_iod *nid;
208 1.1.8.2 skrll int error = 0;
209 1.1.8.2 skrll int hold_count;
210 1.1.8.2 skrll
211 1.1.8.2 skrll KERNEL_UNLOCK_ALL(curlwp, &hold_count);
212 1.1.8.2 skrll
213 1.1.8.2 skrll mutex_enter(&nfs_iodlist_lock);
214 1.1.8.2 skrll /* clamp to sane range */
215 1.1.8.2 skrll nfs_niothreads = max(0, min(newval, NFS_MAXASYNCDAEMON));
216 1.1.8.2 skrll
217 1.1.8.2 skrll while (nfs_numasync != nfs_niothreads && error == 0) {
218 1.1.8.2 skrll while (nfs_numasync < nfs_niothreads) {
219 1.1.8.2 skrll
220 1.1.8.2 skrll /*
221 1.1.8.2 skrll * kthread_create can wait for pagedaemon and
222 1.1.8.2 skrll * pagedaemon can wait for nfsiod which needs to acquire
223 1.1.8.2 skrll * nfs_iodlist_lock.
224 1.1.8.2 skrll */
225 1.1.8.2 skrll
226 1.1.8.2 skrll mutex_exit(&nfs_iodlist_lock);
227 1.1.8.2 skrll error = kthread_create(PRI_NONE, KTHREAD_MPSAFE, NULL,
228 1.1.8.2 skrll nfssvc_iod, NULL, NULL, "nfsio");
229 1.1.8.2 skrll mutex_enter(&nfs_iodlist_lock);
230 1.1.8.2 skrll if (error) {
231 1.1.8.2 skrll /* give up */
232 1.1.8.2 skrll nfs_niothreads = nfs_numasync;
233 1.1.8.2 skrll break;
234 1.1.8.2 skrll }
235 1.1.8.2 skrll nfs_numasync++;
236 1.1.8.2 skrll }
237 1.1.8.2 skrll while (nfs_numasync > nfs_niothreads) {
238 1.1.8.2 skrll nid = LIST_FIRST(&nfs_iodlist_all);
239 1.1.8.2 skrll if (nid == NULL) {
240 1.1.8.2 skrll /* iod has not started yet. */
241 1.1.8.2 skrll kpause("nfsiorm", false, hz, &nfs_iodlist_lock);
242 1.1.8.2 skrll continue;
243 1.1.8.2 skrll }
244 1.1.8.2 skrll LIST_REMOVE(nid, nid_all);
245 1.1.8.2 skrll mutex_enter(&nid->nid_lock);
246 1.1.8.2 skrll KASSERT(!nid->nid_exiting);
247 1.1.8.2 skrll nid->nid_exiting = true;
248 1.1.8.2 skrll cv_signal(&nid->nid_cv);
249 1.1.8.2 skrll mutex_exit(&nid->nid_lock);
250 1.1.8.2 skrll nfs_numasync--;
251 1.1.8.2 skrll }
252 1.1.8.2 skrll }
253 1.1.8.2 skrll mutex_exit(&nfs_iodlist_lock);
254 1.1.8.2 skrll
255 1.1.8.2 skrll KERNEL_LOCK(hold_count, curlwp);
256 1.1.8.2 skrll return error;
257 1.1.8.2 skrll }
258 1.1.8.2 skrll
259 1.1.8.2 skrll /*
260 1.1.8.2 skrll * Get an authorization string for the uid by having the mount_nfs sitting
261 1.1.8.2 skrll * on this mount point porpous out of the kernel and do it.
262 1.1.8.2 skrll */
263 1.1.8.2 skrll int
264 1.1.8.3 skrll nfs_getauth(struct nfsmount *nmp, struct nfsreq *rep, kauth_cred_t cred, char **auth_str, int *auth_len, char *verf_str, int *verf_len, NFSKERBKEY_T key)
265 1.1.8.3 skrll /* key: return session key */
266 1.1.8.2 skrll {
267 1.1.8.2 skrll int error = 0;
268 1.1.8.2 skrll
269 1.1.8.2 skrll while ((nmp->nm_iflag & NFSMNT_WAITAUTH) == 0) {
270 1.1.8.2 skrll nmp->nm_iflag |= NFSMNT_WANTAUTH;
271 1.1.8.2 skrll (void) tsleep((void *)&nmp->nm_authtype, PSOCK,
272 1.1.8.2 skrll "nfsauth1", 2 * hz);
273 1.1.8.2 skrll error = nfs_sigintr(nmp, rep, rep->r_lwp);
274 1.1.8.2 skrll if (error) {
275 1.1.8.2 skrll nmp->nm_iflag &= ~NFSMNT_WANTAUTH;
276 1.1.8.2 skrll return (error);
277 1.1.8.2 skrll }
278 1.1.8.2 skrll }
279 1.1.8.2 skrll nmp->nm_iflag &= ~(NFSMNT_WAITAUTH | NFSMNT_WANTAUTH);
280 1.1.8.2 skrll nmp->nm_authstr = *auth_str = (char *)malloc(RPCAUTH_MAXSIZ, M_TEMP, M_WAITOK);
281 1.1.8.2 skrll nmp->nm_authlen = RPCAUTH_MAXSIZ;
282 1.1.8.2 skrll nmp->nm_verfstr = verf_str;
283 1.1.8.2 skrll nmp->nm_verflen = *verf_len;
284 1.1.8.2 skrll nmp->nm_authuid = kauth_cred_geteuid(cred);
285 1.1.8.2 skrll wakeup((void *)&nmp->nm_authstr);
286 1.1.8.2 skrll
287 1.1.8.2 skrll /*
288 1.1.8.2 skrll * And wait for mount_nfs to do its stuff.
289 1.1.8.2 skrll */
290 1.1.8.2 skrll while ((nmp->nm_iflag & NFSMNT_HASAUTH) == 0 && error == 0) {
291 1.1.8.2 skrll (void) tsleep((void *)&nmp->nm_authlen, PSOCK,
292 1.1.8.2 skrll "nfsauth2", 2 * hz);
293 1.1.8.2 skrll error = nfs_sigintr(nmp, rep, rep->r_lwp);
294 1.1.8.2 skrll }
295 1.1.8.2 skrll if (nmp->nm_iflag & NFSMNT_AUTHERR) {
296 1.1.8.2 skrll nmp->nm_iflag &= ~NFSMNT_AUTHERR;
297 1.1.8.2 skrll error = EAUTH;
298 1.1.8.2 skrll }
299 1.1.8.2 skrll if (error)
300 1.1.8.2 skrll free((void *)*auth_str, M_TEMP);
301 1.1.8.2 skrll else {
302 1.1.8.2 skrll *auth_len = nmp->nm_authlen;
303 1.1.8.2 skrll *verf_len = nmp->nm_verflen;
304 1.1.8.2 skrll memcpy(key, nmp->nm_key, sizeof (NFSKERBKEY_T));
305 1.1.8.2 skrll }
306 1.1.8.2 skrll nmp->nm_iflag &= ~NFSMNT_HASAUTH;
307 1.1.8.2 skrll nmp->nm_iflag |= NFSMNT_WAITAUTH;
308 1.1.8.2 skrll if (nmp->nm_iflag & NFSMNT_WANTAUTH) {
309 1.1.8.2 skrll nmp->nm_iflag &= ~NFSMNT_WANTAUTH;
310 1.1.8.2 skrll wakeup((void *)&nmp->nm_authtype);
311 1.1.8.2 skrll }
312 1.1.8.2 skrll return (error);
313 1.1.8.2 skrll }
314 1.1.8.2 skrll
315 1.1.8.2 skrll /*
316 1.1.8.2 skrll * Get a nickname authenticator and verifier.
317 1.1.8.2 skrll */
318 1.1.8.2 skrll int
319 1.1.8.2 skrll nfs_getnickauth(struct nfsmount *nmp, kauth_cred_t cred, char **auth_str,
320 1.1.8.2 skrll int *auth_len, char *verf_str, int verf_len)
321 1.1.8.2 skrll {
322 1.1.8.2 skrll struct timeval ktvin, ktvout, tv;
323 1.1.8.2 skrll struct nfsuid *nuidp;
324 1.1.8.2 skrll u_int32_t *nickp, *verfp;
325 1.1.8.2 skrll
326 1.1.8.2 skrll memset(&ktvout, 0, sizeof ktvout); /* XXX gcc */
327 1.1.8.2 skrll
328 1.1.8.2 skrll #ifdef DIAGNOSTIC
329 1.1.8.2 skrll if (verf_len < (4 * NFSX_UNSIGNED))
330 1.1.8.2 skrll panic("nfs_getnickauth verf too small");
331 1.1.8.2 skrll #endif
332 1.1.8.2 skrll LIST_FOREACH(nuidp, NMUIDHASH(nmp, kauth_cred_geteuid(cred)), nu_hash) {
333 1.1.8.2 skrll if (kauth_cred_geteuid(nuidp->nu_cr) == kauth_cred_geteuid(cred))
334 1.1.8.2 skrll break;
335 1.1.8.2 skrll }
336 1.1.8.2 skrll if (!nuidp || nuidp->nu_expire < time_second)
337 1.1.8.2 skrll return (EACCES);
338 1.1.8.2 skrll
339 1.1.8.2 skrll /*
340 1.1.8.2 skrll * Move to the end of the lru list (end of lru == most recently used).
341 1.1.8.2 skrll */
342 1.1.8.2 skrll TAILQ_REMOVE(&nmp->nm_uidlruhead, nuidp, nu_lru);
343 1.1.8.2 skrll TAILQ_INSERT_TAIL(&nmp->nm_uidlruhead, nuidp, nu_lru);
344 1.1.8.2 skrll
345 1.1.8.2 skrll nickp = (u_int32_t *)malloc(2 * NFSX_UNSIGNED, M_TEMP, M_WAITOK);
346 1.1.8.2 skrll *nickp++ = txdr_unsigned(RPCAKN_NICKNAME);
347 1.1.8.2 skrll *nickp = txdr_unsigned(nuidp->nu_nickname);
348 1.1.8.2 skrll *auth_str = (char *)nickp;
349 1.1.8.2 skrll *auth_len = 2 * NFSX_UNSIGNED;
350 1.1.8.2 skrll
351 1.1.8.2 skrll /*
352 1.1.8.2 skrll * Now we must encrypt the verifier and package it up.
353 1.1.8.2 skrll */
354 1.1.8.2 skrll verfp = (u_int32_t *)verf_str;
355 1.1.8.2 skrll *verfp++ = txdr_unsigned(RPCAKN_NICKNAME);
356 1.1.8.2 skrll getmicrotime(&tv);
357 1.1.8.2 skrll if (tv.tv_sec > nuidp->nu_timestamp.tv_sec ||
358 1.1.8.2 skrll (tv.tv_sec == nuidp->nu_timestamp.tv_sec &&
359 1.1.8.2 skrll tv.tv_usec > nuidp->nu_timestamp.tv_usec))
360 1.1.8.2 skrll nuidp->nu_timestamp = tv;
361 1.1.8.2 skrll else
362 1.1.8.2 skrll nuidp->nu_timestamp.tv_usec++;
363 1.1.8.2 skrll ktvin.tv_sec = txdr_unsigned(nuidp->nu_timestamp.tv_sec);
364 1.1.8.2 skrll ktvin.tv_usec = txdr_unsigned(nuidp->nu_timestamp.tv_usec);
365 1.1.8.2 skrll
366 1.1.8.2 skrll /*
367 1.1.8.2 skrll * Now encrypt the timestamp verifier in ecb mode using the session
368 1.1.8.2 skrll * key.
369 1.1.8.2 skrll */
370 1.1.8.2 skrll #ifdef NFSKERB
371 1.1.8.2 skrll XXX
372 1.1.8.2 skrll #endif
373 1.1.8.2 skrll
374 1.1.8.2 skrll *verfp++ = ktvout.tv_sec;
375 1.1.8.2 skrll *verfp++ = ktvout.tv_usec;
376 1.1.8.2 skrll *verfp = 0;
377 1.1.8.2 skrll return (0);
378 1.1.8.2 skrll }
379 1.1.8.2 skrll
380 1.1.8.2 skrll /*
381 1.1.8.2 skrll * Save the current nickname in a hash list entry on the mount point.
382 1.1.8.2 skrll */
383 1.1.8.2 skrll int
384 1.1.8.3 skrll nfs_savenickauth(struct nfsmount *nmp, kauth_cred_t cred, int len, NFSKERBKEY_T key, struct mbuf **mdp, char **dposp, struct mbuf *mrep)
385 1.1.8.2 skrll {
386 1.1.8.2 skrll struct nfsuid *nuidp;
387 1.1.8.2 skrll u_int32_t *tl;
388 1.1.8.2 skrll int32_t t1;
389 1.1.8.2 skrll struct mbuf *md = *mdp;
390 1.1.8.2 skrll struct timeval ktvin, ktvout;
391 1.1.8.2 skrll u_int32_t nick;
392 1.1.8.2 skrll char *dpos = *dposp, *cp2;
393 1.1.8.2 skrll int deltasec, error = 0;
394 1.1.8.2 skrll
395 1.1.8.2 skrll memset(&ktvout, 0, sizeof ktvout); /* XXX gcc */
396 1.1.8.2 skrll
397 1.1.8.2 skrll if (len == (3 * NFSX_UNSIGNED)) {
398 1.1.8.2 skrll nfsm_dissect(tl, u_int32_t *, 3 * NFSX_UNSIGNED);
399 1.1.8.2 skrll ktvin.tv_sec = *tl++;
400 1.1.8.2 skrll ktvin.tv_usec = *tl++;
401 1.1.8.2 skrll nick = fxdr_unsigned(u_int32_t, *tl);
402 1.1.8.2 skrll
403 1.1.8.2 skrll /*
404 1.1.8.2 skrll * Decrypt the timestamp in ecb mode.
405 1.1.8.2 skrll */
406 1.1.8.2 skrll #ifdef NFSKERB
407 1.1.8.2 skrll XXX
408 1.1.8.2 skrll #endif
409 1.1.8.2 skrll ktvout.tv_sec = fxdr_unsigned(long, ktvout.tv_sec);
410 1.1.8.2 skrll ktvout.tv_usec = fxdr_unsigned(long, ktvout.tv_usec);
411 1.1.8.2 skrll deltasec = time_second - ktvout.tv_sec;
412 1.1.8.2 skrll if (deltasec < 0)
413 1.1.8.2 skrll deltasec = -deltasec;
414 1.1.8.2 skrll /*
415 1.1.8.2 skrll * If ok, add it to the hash list for the mount point.
416 1.1.8.2 skrll */
417 1.1.8.2 skrll if (deltasec <= NFS_KERBCLOCKSKEW) {
418 1.1.8.2 skrll if (nmp->nm_numuids < nuidhash_max) {
419 1.1.8.2 skrll nmp->nm_numuids++;
420 1.1.8.2 skrll nuidp = kmem_alloc(sizeof(*nuidp), KM_SLEEP);
421 1.1.8.2 skrll } else {
422 1.1.8.2 skrll nuidp = TAILQ_FIRST(&nmp->nm_uidlruhead);
423 1.1.8.2 skrll LIST_REMOVE(nuidp, nu_hash);
424 1.1.8.2 skrll TAILQ_REMOVE(&nmp->nm_uidlruhead, nuidp,
425 1.1.8.2 skrll nu_lru);
426 1.1.8.2 skrll }
427 1.1.8.2 skrll nuidp->nu_flag = 0;
428 1.1.8.2 skrll kauth_cred_seteuid(nuidp->nu_cr, kauth_cred_geteuid(cred));
429 1.1.8.2 skrll nuidp->nu_expire = time_second + NFS_KERBTTL;
430 1.1.8.2 skrll nuidp->nu_timestamp = ktvout;
431 1.1.8.2 skrll nuidp->nu_nickname = nick;
432 1.1.8.2 skrll memcpy(nuidp->nu_key, key, sizeof (NFSKERBKEY_T));
433 1.1.8.2 skrll TAILQ_INSERT_TAIL(&nmp->nm_uidlruhead, nuidp,
434 1.1.8.2 skrll nu_lru);
435 1.1.8.2 skrll LIST_INSERT_HEAD(NMUIDHASH(nmp, kauth_cred_geteuid(cred)),
436 1.1.8.2 skrll nuidp, nu_hash);
437 1.1.8.2 skrll }
438 1.1.8.2 skrll } else
439 1.1.8.2 skrll nfsm_adv(nfsm_rndup(len));
440 1.1.8.2 skrll nfsmout:
441 1.1.8.2 skrll *mdp = md;
442 1.1.8.2 skrll *dposp = dpos;
443 1.1.8.2 skrll return (error);
444 1.1.8.2 skrll }
445