xref: /netbsd-src/sbin/mount_nfs/mount_nfs.c (revision 5b84b3983f71fd20a534cfa5d1556623a8aaa717)
1 /*	$NetBSD: mount_nfs.c,v 1.48 2005/05/15 21:18:34 dsl Exp $	*/
2 
3 /*
4  * Copyright (c) 1992, 1993, 1994
5  *	The Regents of the University of California.  All rights reserved.
6  *
7  * This code is derived from software contributed to Berkeley by
8  * Rick Macklem at The University of Guelph.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. Neither the name of the University nor the names of its contributors
19  *    may be used to endorse or promote products derived from this software
20  *    without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32  * SUCH DAMAGE.
33  */
34 
35 #include <sys/cdefs.h>
36 #ifndef lint
37 __COPYRIGHT("@(#) Copyright (c) 1992, 1993, 1994\n\
38 	The Regents of the University of California.  All rights reserved.\n");
39 #endif /* not lint */
40 
41 #ifndef lint
42 #if 0
43 static char sccsid[] = "@(#)mount_nfs.c	8.11 (Berkeley) 5/4/95";
44 #else
45 __RCSID("$NetBSD: mount_nfs.c,v 1.48 2005/05/15 21:18:34 dsl Exp $");
46 #endif
47 #endif /* not lint */
48 
49 #include <sys/param.h>
50 #include <sys/mount.h>
51 #include <sys/socket.h>
52 #include <sys/stat.h>
53 #include <syslog.h>
54 
55 #ifdef ISO
56 #include <netiso/iso.h>
57 #endif
58 
59 #ifdef NFSKERB
60 #include <des.h>
61 #include <kerberosIV/krb.h>
62 #endif
63 
64 #include <nfs/rpcv2.h>
65 #include <nfs/nfsproto.h>
66 #include <nfs/nfs.h>
67 #include <nfs/nqnfs.h>
68 #include <nfs/nfsmount.h>
69 
70 #include <arpa/inet.h>
71 
72 #include <ctype.h>
73 #include <err.h>
74 #include <errno.h>
75 #include <fcntl.h>
76 #include <netdb.h>
77 #include <signal.h>
78 #include <stdio.h>
79 #include <stdlib.h>
80 #include <string.h>
81 #include <unistd.h>
82 #include <util.h>
83 
84 #include <mntopts.h>
85 
86 #include "mount_nfs.h"
87 
88 #define	ALTF_BG		0x00000001
89 #define ALTF_CONN	0x00000002
90 #define ALTF_DUMBTIMR	0x00000004
91 #define ALTF_INTR	0x00000008
92 #define ALTF_KERB	0x00000010
93 #define ALTF_NFSV3	0x00000020
94 #define ALTF_RDIRPLUS	0x00000040
95 #define	ALTF_MNTUDP	0x00000080
96 #define ALTF_NORESPORT	0x00000100
97 #define ALTF_SEQPACKET	0x00000200
98 #define ALTF_NQNFS	0x00000400
99 #define ALTF_SOFT	0x00000800
100 #define ALTF_TCP	0x00001000
101 #define ALTF_NFSV2	0x00002000
102 #define ALTF_PORT	0x00004000
103 #define ALTF_RSIZE	0x00008000
104 #define ALTF_WSIZE	0x00010000
105 #define ALTF_RDIRSIZE	0x00020000
106 #define ALTF_MAXGRPS	0x00040000
107 #define ALTF_LEASETERM	0x00080000
108 #define ALTF_READAHEAD	0x00100000
109 #define ALTF_DEADTHRESH	0x00200000
110 #define ALTF_TIMEO	0x00400000
111 #define ALTF_RETRANS	0x00800000
112 
113 static const struct mntopt mopts[] = {
114 	MOPT_STDOPTS,
115 	MOPT_FORCE,
116 	MOPT_UPDATE,
117 	MOPT_GETARGS,
118 	{ "bg", 0, ALTF_BG, 1 },
119 	{ "conn", 0, ALTF_CONN, 1 },
120 	{ "dumbtimer", 0, ALTF_DUMBTIMR, 1 },
121 	{ "intr", 0, ALTF_INTR, 1 },
122 #ifdef NFSKERB
123 	{ "kerb", 0, ALTF_KERB, 1 },
124 #endif
125 	{ "nfsv3", 0, ALTF_NFSV3, 1 },
126 	{ "rdirplus", 0, ALTF_RDIRPLUS, 1 },
127 	{ "mntudp", 0, ALTF_MNTUDP, 1 },
128 	{ "noresport", 0, ALTF_NORESPORT, 1 },
129 #ifdef ISO
130 	{ "seqpacket", 0, ALTF_SEQPACKET, 1 },
131 #endif
132 	{ "nqnfs", 0, ALTF_NQNFS, 1 },
133 	{ "soft", 0, ALTF_SOFT, 1 },
134 	{ "tcp", 0, ALTF_TCP, 1 },
135 	{ "nfsv2", 0, ALTF_NFSV2, 1 },
136 	{ "port", 0, ALTF_PORT, 1 },
137 	{ "rsize", 0, ALTF_RSIZE, 1 },
138 	{ "wsize", 0, ALTF_WSIZE, 1 },
139 	{ "rdirsize", 0, ALTF_RDIRSIZE, 1 },
140 	{ "maxgrps", 0, ALTF_MAXGRPS, 1 },
141 	{ "leaseterm", 0, ALTF_LEASETERM, 1 },
142 	{ "readahead", 0, ALTF_READAHEAD, 1 },
143 	{ "deadthresh", 0, ALTF_DEADTHRESH, 1 },
144 	{ "timeo", 0, ALTF_TIMEO, 1 },
145 	{ NULL }
146 
147 };
148 
149 struct nfs_args nfsdefargs = {
150 	NFS_ARGSVERSION,
151 	(struct sockaddr *)0,
152 	sizeof (struct sockaddr_in),
153 	SOCK_DGRAM,
154 	0,
155 	(u_char *)0,
156 	0,
157 	NFSMNT_NFSV3|NFSMNT_NOCONN|NFSMNT_RESVPORT,
158 	NFS_WSIZE,
159 	NFS_RSIZE,
160 	NFS_READDIRSIZE,
161 	10,
162 	NFS_RETRANS,
163 	NFS_MAXGRPS,
164 	NFS_DEFRAHEAD,
165 	NQ_DEFLEASE,
166 	NQ_DEADTHRESH,
167 	(char *)0,
168 };
169 
170 int retrycnt = 0;
171 int opflags = 0;
172 int nfsproto = IPPROTO_UDP;
173 int force2 = 0;
174 int force3 = 0;
175 int mnttcp_ok = 1;
176 int port = 0;
177 
178 #ifdef NFSKERB
179 static char inst[INST_SZ];
180 static char realm[REALM_SZ];
181 static struct {
182 	u_long		kind;
183 	KTEXT_ST	kt;
184 } ktick;
185 static struct nfsrpc_nickverf kverf;
186 static struct nfsrpc_fullblock kin, kout;
187 static NFSKERBKEY_T kivec;
188 static CREDENTIALS kcr;
189 static struct timeval ktv;
190 static NFSKERBKEYSCHED_T kerb_keysched;
191 #endif
192 
193 static void	shownfsargs(const struct nfs_args *);
194 #ifdef ISO
195 static struct	iso_addr *iso_addr(const char *);
196 #endif
197 int	mount_nfs(int argc, char **argv);
198 /* void	set_rpc_maxgrouplist(int); */
199 static void	usage(void);
200 
201 #ifndef MOUNT_NOMAIN
202 int
203 main(int argc, char **argv)
204 {
205 	return mount_nfs(argc, argv);
206 }
207 #endif
208 
209 int
210 mount_nfs(int argc, char *argv[])
211 {
212 	int c, retval;
213 	struct nfs_args *nfsargsp;
214 	struct nfs_args nfsargs;
215 	struct nfsd_cargs ncd;
216 	struct sockaddr_storage sa;
217 	int mntflags, altflags, i, nfssvc_flag, num;
218 	char name[MAXPATHLEN], *p, *spec, *ospec;
219 	mntoptparse_t mp;
220 #ifdef NFSKERB
221 	uid_t last_ruid;
222 
223 	last_ruid = -1;
224 	if (krb_get_lrealm(realm, 0) != KSUCCESS)
225 	    (void)strlcpy(realm, KRB_REALM, sizeof(realm));
226 	if (sizeof (struct nfsrpc_nickverf) != RPCX_NICKVERF ||
227 	    sizeof (struct nfsrpc_fullblock) != RPCX_FULLBLOCK ||
228 	    ((char *)&ktick.kt) - ((char *)&ktick) != NFSX_UNSIGNED ||
229 	    ((char *)ktick.kt.dat) - ((char *)&ktick) != 2 * NFSX_UNSIGNED)
230 		warnx("Yikes! NFSKERB structs not packed!!\n");
231 #endif
232 	retrycnt = DEF_RETRY;
233 
234 	mntflags = 0;
235 	altflags = 0;
236 	nfsargs = nfsdefargs;
237 	nfsargsp = &nfsargs;
238 	while ((c = getopt(argc, argv,
239 	    "23a:bcCdD:g:I:iKL:lm:o:PpqR:r:sTt:w:x:UX")) != -1)
240 		switch (c) {
241 		case '3':
242 			if (force2)
243 				errx(1, "-2 and -3 are mutually exclusive");
244 			force3 = 1;
245 			break;
246 		case '2':
247 			if (force3)
248 				errx(1, "-2 and -3 are mutually exclusive");
249 			force2 = 1;
250 			nfsargsp->flags &= ~NFSMNT_NFSV3;
251 			break;
252 		case 'a':
253 			num = strtol(optarg, &p, 10);
254 			if (*p || num < 0)
255 				errx(1, "illegal -a value -- %s", optarg);
256 			nfsargsp->readahead = num;
257 			nfsargsp->flags |= NFSMNT_READAHEAD;
258 			break;
259 		case 'b':
260 			opflags |= BGRND;
261 			break;
262 		case 'c':
263 			nfsargsp->flags |= NFSMNT_NOCONN;
264 			break;
265 		case 'C':
266 			nfsargsp->flags &= ~NFSMNT_NOCONN;
267 			break;
268 		case 'D':
269 			num = strtol(optarg, &p, 10);
270 			if (*p || num <= 0)
271 				errx(1, "illegal -D value -- %s", optarg);
272 			nfsargsp->deadthresh = num;
273 			nfsargsp->flags |= NFSMNT_DEADTHRESH;
274 			break;
275 		case 'd':
276 			nfsargsp->flags |= NFSMNT_DUMBTIMR;
277 			break;
278 #if 0 /* XXXX */
279 		case 'g':
280 			num = strtol(optarg, &p, 10);
281 			if (*p || num <= 0)
282 				errx(1, "illegal -g value -- %s", optarg);
283 			set_rpc_maxgrouplist(num);
284 			nfsargsp->maxgrouplist = num;
285 			nfsargsp->flags |= NFSMNT_MAXGRPS;
286 			break;
287 #endif
288 		case 'I':
289 			num = strtol(optarg, &p, 10);
290 			if (*p || num <= 0)
291 				errx(1, "illegal -I value -- %s", optarg);
292 			nfsargsp->readdirsize = num;
293 			nfsargsp->flags |= NFSMNT_READDIRSIZE;
294 			break;
295 		case 'i':
296 			nfsargsp->flags |= NFSMNT_INT;
297 			break;
298 #ifdef NFSKERB
299 		case 'K':
300 			nfsargsp->flags |= NFSMNT_KERB;
301 			break;
302 #endif
303 		case 'L':
304 			num = strtol(optarg, &p, 10);
305 			if (*p || num < 2)
306 				errx(1, "illegal -L value -- %s", optarg);
307 			nfsargsp->leaseterm = num;
308 			nfsargsp->flags |= NFSMNT_LEASETERM;
309 			break;
310 		case 'l':
311 			nfsargsp->flags |= NFSMNT_RDIRPLUS;
312 			break;
313 #ifdef NFSKERB
314 		case 'm':
315 			(void)strlcpy(realm, optarg, sizeof(realm));
316 			break;
317 #endif
318 		case 'o':
319 			mp = getmntopts(optarg, mopts, &mntflags, &altflags);
320 			if (mp == NULL)
321 				err(1, NULL);
322 			if (altflags & ALTF_BG)
323 				opflags |= BGRND;
324 			if (altflags & ALTF_CONN)
325 				nfsargsp->flags &= ~NFSMNT_NOCONN;
326 			if (altflags & ALTF_DUMBTIMR)
327 				nfsargsp->flags |= NFSMNT_DUMBTIMR;
328 			if (altflags & ALTF_INTR)
329 				nfsargsp->flags |= NFSMNT_INT;
330 #ifdef NFSKERB
331 			if (altflags & ALTF_KERB)
332 				nfsargsp->flags |= NFSMNT_KERB;
333 #endif
334 			if (altflags & ALTF_NFSV3) {
335 				if (force2)
336 					errx(1, "conflicting version options");
337 				force3 = 1;
338 			}
339 			if (altflags & ALTF_NFSV2) {
340 				if (force3)
341 					errx(1, "conflicting version options");
342 				force2 = 1;
343 				nfsargsp->flags &= ~NFSMNT_NFSV3;
344 			}
345 			if (altflags & ALTF_RDIRPLUS)
346 				nfsargsp->flags |= NFSMNT_RDIRPLUS;
347 			if (altflags & ALTF_MNTUDP)
348 				mnttcp_ok = 0;
349 			if (altflags & ALTF_NORESPORT)
350 				nfsargsp->flags &= ~NFSMNT_RESVPORT;
351 #ifdef ISO
352 			if (altflags & ALTF_SEQPACKET)
353 				nfsargsp->sotype = SOCK_SEQPACKET;
354 #endif
355 			if (altflags & ALTF_NQNFS) {
356 				if (force2)
357 					errx(1, "nqnfs only available with v3");
358 				force3 = 1;
359 				nfsargsp->flags |= NFSMNT_NQNFS;
360 			}
361 			if (altflags & ALTF_SOFT)
362 				nfsargsp->flags |= NFSMNT_SOFT;
363 			if (altflags & ALTF_TCP) {
364 				nfsargsp->sotype = SOCK_STREAM;
365 				nfsproto = IPPROTO_TCP;
366 			}
367 			if (altflags & ALTF_PORT) {
368 				port = getmntoptnum(mp, "port");
369 			}
370 			if (altflags & ALTF_RSIZE) {
371 				nfsargsp->rsize =
372 				    (int)getmntoptnum(mp, "rsize");
373 				nfsargsp->flags |= NFSMNT_RSIZE;
374 			}
375 			if (altflags & ALTF_WSIZE) {
376 				nfsargsp->wsize =
377 				    (int)getmntoptnum(mp, "wsize");
378 				nfsargsp->flags |= NFSMNT_WSIZE;
379 			}
380 			if (altflags & ALTF_RDIRSIZE) {
381 				nfsargsp->rsize =
382 				    (int)getmntoptnum(mp, "rdirsize");
383 				nfsargsp->flags |= NFSMNT_READDIRSIZE;
384 			}
385 #if 0
386 			if (altflags & ALTF_MAXGRPS) {
387 				set_rpc_maxgrouplist(num);
388 				nfsargsp->maxgrouplist =
389 				    (int)getmntoptnum(mp, "maxgrps");
390 				nfsargsp->flags |= NFSMNT_MAXGRPS;
391 			}
392 #endif
393 			if (altflags & ALTF_LEASETERM) {
394 				nfsargsp->leaseterm =
395 				(int)getmntoptnum(mp, "leaseterm");
396 				nfsargsp->flags |= NFSMNT_LEASETERM;
397 			}
398 			if (altflags & ALTF_READAHEAD) {
399 				nfsargsp->readahead =
400 				    (int)getmntoptnum(mp, "readahead");
401 				nfsargsp->flags |= NFSMNT_READAHEAD;
402 			}
403 			if (altflags & ALTF_DEADTHRESH) {
404 				nfsargsp->deadthresh =
405 				    (int)getmntoptnum(mp, "deadthresh");
406 				nfsargsp->flags |= NFSMNT_DEADTHRESH;
407 			}
408 			if (altflags & ALTF_TIMEO) {
409 				nfsargsp->timeo =
410 				    (int)getmntoptnum(mp, "timeo");
411 				nfsargsp->flags |= NFSMNT_TIMEO;
412 			}
413 			if (altflags & ALTF_RETRANS) {
414 				nfsargsp->retrans =
415 				    (int)getmntoptnum(mp, "retrans");
416 				nfsargsp->flags |= NFSMNT_RETRANS;
417 			}
418 			altflags = 0;
419 			freemntopts(mp);
420 			break;
421 		case 'P':
422 			nfsargsp->flags |= NFSMNT_RESVPORT;
423 			break;
424 		case 'p':
425 			nfsargsp->flags &= ~NFSMNT_RESVPORT;
426 			break;
427 		case 'q':
428 			if (force2)
429 				errx(1, "nqnfs only available with v3");
430 			force3 = 1;
431 			nfsargsp->flags |= NFSMNT_NQNFS;
432 			break;
433 		case 'R':
434 			num = strtol(optarg, &p, 10);
435 			if (*p || num <= 0)
436 				errx(1, "illegal -R value -- %s", optarg);
437 			retrycnt = num;
438 			break;
439 		case 'r':
440 			num = strtol(optarg, &p, 10);
441 			if (*p || num <= 0)
442 				errx(1, "illegal -r value -- %s", optarg);
443 			nfsargsp->rsize = num;
444 			nfsargsp->flags |= NFSMNT_RSIZE;
445 			break;
446 #ifdef ISO
447 		case 'S':
448 			nfsargsp->sotype = SOCK_SEQPACKET;
449 			break;
450 #endif
451 		case 's':
452 			nfsargsp->flags |= NFSMNT_SOFT;
453 			break;
454 		case 'T':
455 			nfsargsp->sotype = SOCK_STREAM;
456 			nfsproto = IPPROTO_TCP;
457 			break;
458 		case 't':
459 			num = strtol(optarg, &p, 10);
460 			if (*p || num <= 0)
461 				errx(1, "illegal -t value -- %s", optarg);
462 			nfsargsp->timeo = num;
463 			nfsargsp->flags |= NFSMNT_TIMEO;
464 			break;
465 		case 'w':
466 			num = strtol(optarg, &p, 10);
467 			if (*p || num <= 0)
468 				errx(1, "illegal -w value -- %s", optarg);
469 			nfsargsp->wsize = num;
470 			nfsargsp->flags |= NFSMNT_WSIZE;
471 			break;
472 		case 'x':
473 			num = strtol(optarg, &p, 10);
474 			if (*p || num <= 0)
475 				errx(1, "illegal -x value -- %s", optarg);
476 			nfsargsp->retrans = num;
477 			nfsargsp->flags |= NFSMNT_RETRANS;
478 			break;
479 		case 'X':
480 			nfsargsp->flags |= NFSMNT_XLATECOOKIE;
481 			break;
482 		case 'U':
483 			mnttcp_ok = 0;
484 			break;
485 		default:
486 			usage();
487 			break;
488 		}
489 	argc -= optind;
490 	argv += optind;
491 
492 	if (argc != 2)
493 		usage();
494 
495 	spec = *argv++;
496 	if (realpath(*argv, name) == NULL)           /* Check mounton path */
497 		err(1, "realpath %s", *argv);
498 	if (strncmp(*argv, name, MAXPATHLEN)) {
499 		warnx("\"%s\" is a relative path.", *argv);
500 		warnx("using \"%s\" instead.", name);
501 	}
502 
503 	if ((ospec = strdup(spec)) == NULL) {
504 		err(1, "strdup");
505 	}
506 
507 	if ((mntflags & MNT_GETARGS) != 0) {
508 		memset(&sa, 0, sizeof(sa));
509 		nfsargsp->addr = (struct sockaddr *)&sa;
510 		nfsargsp->addrlen = sizeof(sa);
511 	} else {
512 		if (!getnfsargs(spec, nfsargsp))
513 			exit(1);
514 	}
515 	if ((retval = mount(MOUNT_NFS, name, mntflags, nfsargsp))) {
516 		/* Did we just default to v3 on a v2-only kernel?
517 		 * If so, default to v2 & try again */
518 		if ((errno == EPROGMISMATCH) && !force3) {
519 			nfsargsp->flags &= ~NFSMNT_NFSV3;
520 			retval = mount(MOUNT_NFS, name, mntflags, nfsargsp);
521 		}
522 	}
523 	if (retval)
524 		err(1, "%s on %s", ospec, name);
525 	if (mntflags & MNT_GETARGS) {
526 		shownfsargs(nfsargsp);
527 		return (0);
528 	}
529 
530 	if (nfsargsp->flags & (NFSMNT_NQNFS | NFSMNT_KERB)) {
531 		if ((opflags & ISBGRND) == 0) {
532 			if ((i = fork()) != 0) {
533 				if (i == -1)
534 					err(1, "nqnfs 1");
535 				exit(0);
536 			}
537 			(void) setsid();
538 			(void) close(STDIN_FILENO);
539 			(void) close(STDOUT_FILENO);
540 			(void) close(STDERR_FILENO);
541 			(void) chdir("/");
542 		}
543 		openlog("mount_nfs", LOG_PID, LOG_DAEMON);
544 		nfssvc_flag = NFSSVC_MNTD;
545 		ncd.ncd_dirp = name;
546 		while (nfssvc(nfssvc_flag, (caddr_t)&ncd) < 0) {
547 			if (errno != ENEEDAUTH) {
548 				syslog(LOG_ERR, "nfssvc err %m");
549 				continue;
550 			}
551 			nfssvc_flag =
552 			    NFSSVC_MNTD | NFSSVC_GOTAUTH | NFSSVC_AUTHINFAIL;
553 #ifdef NFSKERB
554 			/*
555 			 * Set up as ncd_authuid for the kerberos call.
556 			 * Must set ruid to ncd_authuid and reset the
557 			 * ticket name iff ncd_authuid is not the same
558 			 * as last time, so that the right ticket file
559 			 * is found.
560 			 * Get the Kerberos credential structure so that
561 			 * we have the seesion key and get a ticket for
562 			 * this uid.
563 			 * For more info see the IETF Draft "Authentication
564 			 * in ONC RPC".
565 			 */
566 			if (ncd.ncd_authuid != last_ruid) {
567 				krb_set_tkt_string("");
568 				last_ruid = ncd.ncd_authuid;
569 			}
570 			setreuid(ncd.ncd_authuid, 0);
571 			kret = krb_get_cred(NFS_KERBSRV, inst, realm, &kcr);
572 			if (kret == RET_NOTKT) {
573 		            kret = get_ad_tkt(NFS_KERBSRV, inst, realm,
574 				DEFAULT_TKT_LIFE);
575 			    if (kret == KSUCCESS)
576 				kret = krb_get_cred(NFS_KERBSRV, inst, realm,
577 				    &kcr);
578 			}
579 			if (kret == KSUCCESS)
580 			    kret = krb_mk_req(&ktick.kt, NFS_KERBSRV, inst,
581 				realm, 0);
582 
583 			/*
584 			 * Fill in the AKN_FULLNAME authenticator and verfier.
585 			 * Along with the Kerberos ticket, we need to build
586 			 * the timestamp verifier and encrypt it in CBC mode.
587 			 */
588 			if (kret == KSUCCESS &&
589 			    ktick.kt.length <= (RPCAUTH_MAXSIZ-3*NFSX_UNSIGNED)
590 			    && gettimeofday(&ktv, (struct timezone *)0) == 0) {
591 			    ncd.ncd_authtype = RPCAUTH_KERB4;
592 			    ncd.ncd_authstr = (u_char *)&ktick;
593 			    ncd.ncd_authlen = nfsm_rndup(ktick.kt.length) +
594 				3 * NFSX_UNSIGNED;
595 			    ncd.ncd_verfstr = (u_char *)&kverf;
596 			    ncd.ncd_verflen = sizeof (kverf);
597 			    memmove(ncd.ncd_key, kcr.session,
598 				sizeof (kcr.session));
599 			    kin.t1 = htonl(ktv.tv_sec);
600 			    kin.t2 = htonl(ktv.tv_usec);
601 			    kin.w1 = htonl(NFS_KERBTTL);
602 			    kin.w2 = htonl(NFS_KERBTTL - 1);
603 			    memset((caddr_t)kivec, 0, sizeof (kivec));
604 
605 			    /*
606 			     * Encrypt kin in CBC mode using the session
607 			     * key in kcr.
608 			     */
609 			    XXX
610 
611 			    /*
612 			     * Finally, fill the timestamp verifier into the
613 			     * authenticator and verifier.
614 			     */
615 			    ktick.kind = htonl(RPCAKN_FULLNAME);
616 			    kverf.kind = htonl(RPCAKN_FULLNAME);
617 			    NFS_KERBW1(ktick.kt) = kout.w1;
618 			    ktick.kt.length = htonl(ktick.kt.length);
619 			    kverf.verf.t1 = kout.t1;
620 			    kverf.verf.t2 = kout.t2;
621 			    kverf.verf.w2 = kout.w2;
622 			    nfssvc_flag = NFSSVC_MNTD | NFSSVC_GOTAUTH;
623 			}
624 			setreuid(0, 0);
625 #endif /* NFSKERB */
626 		}
627 	}
628 	exit(0);
629 }
630 
631 static void
632 shownfsargs(const struct nfs_args *nfsargsp)
633 {
634 	char fbuf[2048];
635 	char host[NI_MAXHOST], serv[NI_MAXSERV];
636 	int error;
637 
638 	(void)snprintb(fbuf, sizeof(fbuf), NFSMNT_BITS, nfsargsp->flags);
639 	if (nfsargsp->addr != NULL) {
640 		error = getnameinfo(nfsargsp->addr, nfsargsp->addrlen, host,
641 		    sizeof(host), serv, sizeof(serv),
642 		    NI_NUMERICHOST | NI_NUMERICSERV);
643 		if (error != 0)
644 			warnx("getnameinfo: %s", gai_strerror(error));
645 	} else
646 		error = -1;
647 
648 	if (error == 0)
649 		printf("addr=%s, port=%s, addrlen=%d, ",
650 		    host, serv, nfsargsp->addrlen);
651 	printf("sotype=%d, proto=%d, fhsize=%d, "
652 	    "flags=%s, wsize=%d, rsize=%d, readdirsize=%d, timeo=%d, "
653 	    "retrans=%d, maxgrouplist=%d, readahead=%d, leaseterm=%d, "
654 	    "deadthresh=%d\n",
655 	    nfsargsp->sotype,
656 	    nfsargsp->proto,
657 	    nfsargsp->fhsize,
658 	    fbuf,
659 	    nfsargsp->wsize,
660 	    nfsargsp->rsize,
661 	    nfsargsp->readdirsize,
662 	    nfsargsp->timeo,
663 	    nfsargsp->retrans,
664 	    nfsargsp->maxgrouplist,
665 	    nfsargsp->readahead,
666 	    nfsargsp->leaseterm,
667 	    nfsargsp->deadthresh);
668 }
669 
670 static void
671 usage(void)
672 {
673 	(void)fprintf(stderr, "usage: mount_nfs %s\n%s\n%s\n%s\n%s\n",
674 "[-23bcCdiKlpPqsTUX] [-a maxreadahead] [-D deadthresh]",
675 "\t[-g maxgroups] [-I readdirsize] [-L leaseterm] [-m realm]",
676 "\t[-o options] [-R retrycnt] [-r readsize] [-t timeout]",
677 "\t[-w writesize] [-x retrans]",
678 "\trhost:path node");
679 	exit(1);
680 }
681