mount_nfs.c revision 1.35 1 1.35 itojun /* $NetBSD: mount_nfs.c,v 1.35 2002/10/01 03:08:56 itojun Exp $ */
2 1.8 cgd
3 1.1 mycroft /*
4 1.1 mycroft * Copyright (c) 1992, 1993, 1994
5 1.1 mycroft * The Regents of the University of California. All rights reserved.
6 1.1 mycroft *
7 1.1 mycroft * This code is derived from software contributed to Berkeley by
8 1.1 mycroft * Rick Macklem at The University of Guelph.
9 1.1 mycroft *
10 1.1 mycroft * Redistribution and use in source and binary forms, with or without
11 1.1 mycroft * modification, are permitted provided that the following conditions
12 1.1 mycroft * are met:
13 1.1 mycroft * 1. Redistributions of source code must retain the above copyright
14 1.1 mycroft * notice, this list of conditions and the following disclaimer.
15 1.1 mycroft * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 mycroft * notice, this list of conditions and the following disclaimer in the
17 1.1 mycroft * documentation and/or other materials provided with the distribution.
18 1.1 mycroft * 3. All advertising materials mentioning features or use of this software
19 1.1 mycroft * must display the following acknowledgement:
20 1.1 mycroft * This product includes software developed by the University of
21 1.1 mycroft * California, Berkeley and its contributors.
22 1.1 mycroft * 4. Neither the name of the University nor the names of its contributors
23 1.1 mycroft * may be used to endorse or promote products derived from this software
24 1.1 mycroft * without specific prior written permission.
25 1.1 mycroft *
26 1.1 mycroft * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 1.1 mycroft * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 1.1 mycroft * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 1.1 mycroft * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 1.1 mycroft * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 1.1 mycroft * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 1.1 mycroft * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 1.1 mycroft * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 1.1 mycroft * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 1.1 mycroft * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 1.1 mycroft * SUCH DAMAGE.
37 1.1 mycroft */
38 1.1 mycroft
39 1.17 lukem #include <sys/cdefs.h>
40 1.1 mycroft #ifndef lint
41 1.17 lukem __COPYRIGHT("@(#) Copyright (c) 1992, 1993, 1994\n\
42 1.17 lukem The Regents of the University of California. All rights reserved.\n");
43 1.1 mycroft #endif /* not lint */
44 1.1 mycroft
45 1.1 mycroft #ifndef lint
46 1.8 cgd #if 0
47 1.11 fvdl static char sccsid[] = "@(#)mount_nfs.c 8.11 (Berkeley) 5/4/95";
48 1.8 cgd #else
49 1.35 itojun __RCSID("$NetBSD: mount_nfs.c,v 1.35 2002/10/01 03:08:56 itojun Exp $");
50 1.8 cgd #endif
51 1.1 mycroft #endif /* not lint */
52 1.1 mycroft
53 1.1 mycroft #include <sys/param.h>
54 1.1 mycroft #include <sys/mount.h>
55 1.1 mycroft #include <sys/socket.h>
56 1.1 mycroft #include <sys/stat.h>
57 1.9 jtc #include <syslog.h>
58 1.1 mycroft
59 1.1 mycroft #include <rpc/rpc.h>
60 1.1 mycroft #include <rpc/pmap_clnt.h>
61 1.1 mycroft #include <rpc/pmap_prot.h>
62 1.1 mycroft
63 1.1 mycroft #ifdef ISO
64 1.1 mycroft #include <netiso/iso.h>
65 1.1 mycroft #endif
66 1.1 mycroft
67 1.11 fvdl #ifdef NFSKERB
68 1.1 mycroft #include <kerberosIV/des.h>
69 1.1 mycroft #include <kerberosIV/krb.h>
70 1.1 mycroft #endif
71 1.1 mycroft
72 1.1 mycroft #include <nfs/rpcv2.h>
73 1.11 fvdl #include <nfs/nfsproto.h>
74 1.9 jtc #define _KERNEL
75 1.1 mycroft #include <nfs/nfs.h>
76 1.9 jtc #undef _KERNEL
77 1.1 mycroft #include <nfs/nqnfs.h>
78 1.20 fvdl #include <nfs/nfsmount.h>
79 1.1 mycroft
80 1.1 mycroft #include <arpa/inet.h>
81 1.1 mycroft
82 1.1 mycroft #include <ctype.h>
83 1.1 mycroft #include <err.h>
84 1.1 mycroft #include <errno.h>
85 1.1 mycroft #include <fcntl.h>
86 1.1 mycroft #include <netdb.h>
87 1.1 mycroft #include <signal.h>
88 1.1 mycroft #include <stdio.h>
89 1.1 mycroft #include <stdlib.h>
90 1.19 perry #include <string.h>
91 1.1 mycroft #include <unistd.h>
92 1.34 christos #include <util.h>
93 1.1 mycroft
94 1.1 mycroft #include "mntopts.h"
95 1.1 mycroft
96 1.11 fvdl #define ALTF_BG 0x1
97 1.14 christos #define ALTF_CONN 0x2
98 1.11 fvdl #define ALTF_DUMBTIMR 0x4
99 1.11 fvdl #define ALTF_INTR 0x8
100 1.11 fvdl #define ALTF_KERB 0x10
101 1.11 fvdl #define ALTF_NFSV3 0x20
102 1.11 fvdl #define ALTF_RDIRPLUS 0x40
103 1.11 fvdl #define ALTF_MNTUDP 0x80
104 1.15 fvdl #define ALTF_NORESPORT 0x100
105 1.11 fvdl #define ALTF_SEQPACKET 0x200
106 1.11 fvdl #define ALTF_NQNFS 0x400
107 1.11 fvdl #define ALTF_SOFT 0x800
108 1.11 fvdl #define ALTF_TCP 0x1000
109 1.13 fvdl #define ALTF_NFSV2 0x2000
110 1.11 fvdl
111 1.29 jdolecek static const struct mntopt mopts[] = {
112 1.1 mycroft MOPT_STDOPTS,
113 1.1 mycroft MOPT_FORCE,
114 1.1 mycroft MOPT_UPDATE,
115 1.34 christos MOPT_GETARGS,
116 1.11 fvdl { "bg", 0, ALTF_BG, 1 },
117 1.14 christos { "conn", 0, ALTF_CONN, 1 },
118 1.11 fvdl { "dumbtimer", 0, ALTF_DUMBTIMR, 1 },
119 1.11 fvdl { "intr", 0, ALTF_INTR, 1 },
120 1.11 fvdl #ifdef NFSKERB
121 1.11 fvdl { "kerb", 0, ALTF_KERB, 1 },
122 1.11 fvdl #endif
123 1.11 fvdl { "nfsv3", 0, ALTF_NFSV3, 1 },
124 1.11 fvdl { "rdirplus", 0, ALTF_RDIRPLUS, 1 },
125 1.11 fvdl { "mntudp", 0, ALTF_MNTUDP, 1 },
126 1.15 fvdl { "noresport", 0, ALTF_NORESPORT, 1 },
127 1.11 fvdl #ifdef ISO
128 1.11 fvdl { "seqpacket", 0, ALTF_SEQPACKET, 1 },
129 1.11 fvdl #endif
130 1.11 fvdl { "nqnfs", 0, ALTF_NQNFS, 1 },
131 1.11 fvdl { "soft", 0, ALTF_SOFT, 1 },
132 1.11 fvdl { "tcp", 0, ALTF_TCP, 1 },
133 1.13 fvdl { "nfsv2", 0, ALTF_NFSV2, 1 },
134 1.1 mycroft { NULL }
135 1.1 mycroft };
136 1.1 mycroft
137 1.1 mycroft struct nfs_args nfsdefargs = {
138 1.11 fvdl NFS_ARGSVERSION,
139 1.1 mycroft (struct sockaddr *)0,
140 1.1 mycroft sizeof (struct sockaddr_in),
141 1.1 mycroft SOCK_DGRAM,
142 1.1 mycroft 0,
143 1.11 fvdl (u_char *)0,
144 1.1 mycroft 0,
145 1.15 fvdl NFSMNT_NFSV3|NFSMNT_NOCONN|NFSMNT_RESVPORT,
146 1.1 mycroft NFS_WSIZE,
147 1.1 mycroft NFS_RSIZE,
148 1.11 fvdl NFS_READDIRSIZE,
149 1.11 fvdl 10,
150 1.1 mycroft NFS_RETRANS,
151 1.1 mycroft NFS_MAXGRPS,
152 1.1 mycroft NFS_DEFRAHEAD,
153 1.1 mycroft NQ_DEFLEASE,
154 1.1 mycroft NQ_DEADTHRESH,
155 1.1 mycroft (char *)0,
156 1.1 mycroft };
157 1.1 mycroft
158 1.1 mycroft struct nfhret {
159 1.11 fvdl u_long stat;
160 1.11 fvdl long vers;
161 1.11 fvdl long auth;
162 1.11 fvdl long fhsize;
163 1.11 fvdl u_char nfh[NFSX_V3FHMAX];
164 1.1 mycroft };
165 1.1 mycroft #define DEF_RETRY 10000
166 1.1 mycroft #define BGRND 1
167 1.1 mycroft #define ISBGRND 2
168 1.11 fvdl int retrycnt;
169 1.1 mycroft int opflags = 0;
170 1.11 fvdl int nfsproto = IPPROTO_UDP;
171 1.11 fvdl int force2 = 0;
172 1.11 fvdl int force3 = 0;
173 1.25 fvdl int mnttcp_ok = 1;
174 1.1 mycroft
175 1.11 fvdl #ifdef NFSKERB
176 1.29 jdolecek static char inst[INST_SZ];
177 1.29 jdolecek static char realm[REALM_SZ];
178 1.29 jdolecek static struct {
179 1.11 fvdl u_long kind;
180 1.11 fvdl KTEXT_ST kt;
181 1.11 fvdl } ktick;
182 1.29 jdolecek static struct nfsrpc_nickverf kverf;
183 1.29 jdolecek static struct nfsrpc_fullblock kin, kout;
184 1.29 jdolecek static NFSKERBKEY_T kivec;
185 1.29 jdolecek static CREDENTIALS kcr;
186 1.29 jdolecek static struct timeval ktv;
187 1.29 jdolecek static NFSKERBKEYSCHED_T kerb_keysched;
188 1.1 mycroft #endif
189 1.1 mycroft
190 1.34 christos static void shownfsargs __P((const struct nfs_args *));
191 1.29 jdolecek static int getnfsargs __P((char *, struct nfs_args *));
192 1.1 mycroft #ifdef ISO
193 1.29 jdolecek static struct iso_addr *iso_addr __P((const char *));
194 1.1 mycroft #endif
195 1.17 lukem int main __P((int, char *[]));
196 1.29 jdolecek int mount_nfs __P((int argc, char **argv));
197 1.29 jdolecek /* void set_rpc_maxgrouplist __P((int)); */
198 1.29 jdolecek static void usage __P((void));
199 1.29 jdolecek static int xdr_dir __P((XDR *, char *));
200 1.29 jdolecek static int xdr_fh __P((XDR *, struct nfhret *));
201 1.1 mycroft
202 1.29 jdolecek #ifndef MOUNT_NOMAIN
203 1.1 mycroft int
204 1.1 mycroft main(argc, argv)
205 1.1 mycroft int argc;
206 1.29 jdolecek char **argv;
207 1.29 jdolecek {
208 1.29 jdolecek return mount_nfs(argc, argv);
209 1.29 jdolecek }
210 1.29 jdolecek #endif
211 1.29 jdolecek
212 1.29 jdolecek int
213 1.29 jdolecek mount_nfs(argc, argv)
214 1.29 jdolecek int argc;
215 1.1 mycroft char *argv[];
216 1.1 mycroft {
217 1.33 wrstuden int c, retval;
218 1.17 lukem struct nfs_args *nfsargsp;
219 1.1 mycroft struct nfs_args nfsargs;
220 1.1 mycroft struct nfsd_cargs ncd;
221 1.11 fvdl int mntflags, altflags, i, nfssvc_flag, num;
222 1.23 perseant char *name, *p, *spec, *ospec;
223 1.11 fvdl #ifdef NFSKERB
224 1.1 mycroft uid_t last_ruid;
225 1.1 mycroft
226 1.1 mycroft last_ruid = -1;
227 1.3 brezak if (krb_get_lrealm(realm, 0) != KSUCCESS)
228 1.3 brezak (void)strcpy(realm, KRB_REALM);
229 1.11 fvdl if (sizeof (struct nfsrpc_nickverf) != RPCX_NICKVERF ||
230 1.11 fvdl sizeof (struct nfsrpc_fullblock) != RPCX_FULLBLOCK ||
231 1.11 fvdl ((char *)&ktick.kt) - ((char *)&ktick) != NFSX_UNSIGNED ||
232 1.11 fvdl ((char *)ktick.kt.dat) - ((char *)&ktick) != 2 * NFSX_UNSIGNED)
233 1.35 itojun warnx("Yikes! NFSKERB structs not packed!!\n");
234 1.1 mycroft #endif
235 1.1 mycroft retrycnt = DEF_RETRY;
236 1.1 mycroft
237 1.1 mycroft mntflags = 0;
238 1.11 fvdl altflags = 0;
239 1.1 mycroft nfsargs = nfsdefargs;
240 1.1 mycroft nfsargsp = &nfsargs;
241 1.1 mycroft while ((c = getopt(argc, argv,
242 1.18 fvdl "23a:bcCdD:g:I:iKL:lm:o:PpqR:r:sTt:w:x:UX")) != -1)
243 1.1 mycroft switch (c) {
244 1.11 fvdl case '3':
245 1.11 fvdl if (force2)
246 1.11 fvdl errx(1, "-2 and -3 are mutually exclusive");
247 1.11 fvdl force3 = 1;
248 1.11 fvdl break;
249 1.11 fvdl case '2':
250 1.11 fvdl if (force3)
251 1.11 fvdl errx(1, "-2 and -3 are mutually exclusive");
252 1.11 fvdl force2 = 1;
253 1.11 fvdl nfsargsp->flags &= ~NFSMNT_NFSV3;
254 1.11 fvdl break;
255 1.1 mycroft case 'a':
256 1.1 mycroft num = strtol(optarg, &p, 10);
257 1.1 mycroft if (*p || num < 0)
258 1.1 mycroft errx(1, "illegal -a value -- %s", optarg);
259 1.1 mycroft nfsargsp->readahead = num;
260 1.1 mycroft nfsargsp->flags |= NFSMNT_READAHEAD;
261 1.1 mycroft break;
262 1.1 mycroft case 'b':
263 1.1 mycroft opflags |= BGRND;
264 1.1 mycroft break;
265 1.1 mycroft case 'c':
266 1.1 mycroft nfsargsp->flags |= NFSMNT_NOCONN;
267 1.1 mycroft break;
268 1.14 christos case 'C':
269 1.14 christos nfsargsp->flags &= ~NFSMNT_NOCONN;
270 1.14 christos break;
271 1.1 mycroft case 'D':
272 1.1 mycroft num = strtol(optarg, &p, 10);
273 1.1 mycroft if (*p || num <= 0)
274 1.1 mycroft errx(1, "illegal -D value -- %s", optarg);
275 1.1 mycroft nfsargsp->deadthresh = num;
276 1.1 mycroft nfsargsp->flags |= NFSMNT_DEADTHRESH;
277 1.1 mycroft break;
278 1.1 mycroft case 'd':
279 1.1 mycroft nfsargsp->flags |= NFSMNT_DUMBTIMR;
280 1.1 mycroft break;
281 1.1 mycroft #if 0 /* XXXX */
282 1.1 mycroft case 'g':
283 1.1 mycroft num = strtol(optarg, &p, 10);
284 1.1 mycroft if (*p || num <= 0)
285 1.1 mycroft errx(1, "illegal -g value -- %s", optarg);
286 1.1 mycroft set_rpc_maxgrouplist(num);
287 1.1 mycroft nfsargsp->maxgrouplist = num;
288 1.1 mycroft nfsargsp->flags |= NFSMNT_MAXGRPS;
289 1.1 mycroft break;
290 1.1 mycroft #endif
291 1.11 fvdl case 'I':
292 1.11 fvdl num = strtol(optarg, &p, 10);
293 1.11 fvdl if (*p || num <= 0)
294 1.11 fvdl errx(1, "illegal -I value -- %s", optarg);
295 1.11 fvdl nfsargsp->readdirsize = num;
296 1.11 fvdl nfsargsp->flags |= NFSMNT_READDIRSIZE;
297 1.11 fvdl break;
298 1.1 mycroft case 'i':
299 1.1 mycroft nfsargsp->flags |= NFSMNT_INT;
300 1.1 mycroft break;
301 1.11 fvdl #ifdef NFSKERB
302 1.1 mycroft case 'K':
303 1.1 mycroft nfsargsp->flags |= NFSMNT_KERB;
304 1.1 mycroft break;
305 1.1 mycroft #endif
306 1.1 mycroft case 'L':
307 1.1 mycroft num = strtol(optarg, &p, 10);
308 1.1 mycroft if (*p || num < 2)
309 1.1 mycroft errx(1, "illegal -L value -- %s", optarg);
310 1.1 mycroft nfsargsp->leaseterm = num;
311 1.1 mycroft nfsargsp->flags |= NFSMNT_LEASETERM;
312 1.1 mycroft break;
313 1.1 mycroft case 'l':
314 1.11 fvdl nfsargsp->flags |= NFSMNT_RDIRPLUS;
315 1.1 mycroft break;
316 1.11 fvdl #ifdef NFSKERB
317 1.1 mycroft case 'm':
318 1.1 mycroft (void)strncpy(realm, optarg, REALM_SZ - 1);
319 1.1 mycroft realm[REALM_SZ - 1] = '\0';
320 1.1 mycroft break;
321 1.1 mycroft #endif
322 1.1 mycroft case 'o':
323 1.11 fvdl getmntopts(optarg, mopts, &mntflags, &altflags);
324 1.35 itojun if (altflags & ALTF_BG)
325 1.11 fvdl opflags |= BGRND;
326 1.35 itojun if (altflags & ALTF_CONN)
327 1.14 christos nfsargsp->flags &= ~NFSMNT_NOCONN;
328 1.35 itojun if (altflags & ALTF_DUMBTIMR)
329 1.11 fvdl nfsargsp->flags |= NFSMNT_DUMBTIMR;
330 1.35 itojun if (altflags & ALTF_INTR)
331 1.11 fvdl nfsargsp->flags |= NFSMNT_INT;
332 1.11 fvdl #ifdef NFSKERB
333 1.35 itojun if (altflags & ALTF_KERB)
334 1.11 fvdl nfsargsp->flags |= NFSMNT_KERB;
335 1.11 fvdl #endif
336 1.35 itojun if (altflags & ALTF_NFSV3) {
337 1.13 fvdl if (force2)
338 1.35 itojun errx(1, "conflicting version options");
339 1.13 fvdl force3 = 1;
340 1.13 fvdl }
341 1.35 itojun if (altflags & ALTF_NFSV2) {
342 1.13 fvdl if (force3)
343 1.35 itojun errx(1, "conflicting version options");
344 1.13 fvdl force2 = 1;
345 1.13 fvdl nfsargsp->flags &= ~NFSMNT_NFSV3;
346 1.13 fvdl }
347 1.35 itojun if (altflags & ALTF_RDIRPLUS)
348 1.11 fvdl nfsargsp->flags |= NFSMNT_RDIRPLUS;
349 1.35 itojun if (altflags & ALTF_MNTUDP)
350 1.11 fvdl mnttcp_ok = 0;
351 1.35 itojun if (altflags & ALTF_NORESPORT)
352 1.15 fvdl nfsargsp->flags &= ~NFSMNT_RESVPORT;
353 1.11 fvdl #ifdef ISO
354 1.35 itojun if (altflags & ALTF_SEQPACKET)
355 1.11 fvdl nfsargsp->sotype = SOCK_SEQPACKET;
356 1.11 fvdl #endif
357 1.35 itojun if (altflags & ALTF_NQNFS) {
358 1.13 fvdl if (force2)
359 1.35 itojun errx(1, "nqnfs only available with v3");
360 1.13 fvdl force3 = 1;
361 1.13 fvdl nfsargsp->flags |= NFSMNT_NQNFS;
362 1.13 fvdl }
363 1.35 itojun if (altflags & ALTF_SOFT)
364 1.11 fvdl nfsargsp->flags |= NFSMNT_SOFT;
365 1.35 itojun if (altflags & ALTF_TCP) {
366 1.11 fvdl nfsargsp->sotype = SOCK_STREAM;
367 1.11 fvdl nfsproto = IPPROTO_TCP;
368 1.11 fvdl }
369 1.11 fvdl altflags = 0;
370 1.1 mycroft break;
371 1.1 mycroft case 'P':
372 1.1 mycroft nfsargsp->flags |= NFSMNT_RESVPORT;
373 1.1 mycroft break;
374 1.1 mycroft case 'p':
375 1.15 fvdl nfsargsp->flags &= ~NFSMNT_RESVPORT;
376 1.1 mycroft break;
377 1.1 mycroft case 'q':
378 1.13 fvdl if (force2)
379 1.35 itojun errx(1, "nqnfs only available with v3");
380 1.13 fvdl force3 = 1;
381 1.13 fvdl nfsargsp->flags |= NFSMNT_NQNFS;
382 1.1 mycroft break;
383 1.1 mycroft case 'R':
384 1.1 mycroft num = strtol(optarg, &p, 10);
385 1.1 mycroft if (*p || num <= 0)
386 1.1 mycroft errx(1, "illegal -R value -- %s", optarg);
387 1.1 mycroft retrycnt = num;
388 1.1 mycroft break;
389 1.1 mycroft case 'r':
390 1.1 mycroft num = strtol(optarg, &p, 10);
391 1.1 mycroft if (*p || num <= 0)
392 1.1 mycroft errx(1, "illegal -r value -- %s", optarg);
393 1.1 mycroft nfsargsp->rsize = num;
394 1.1 mycroft nfsargsp->flags |= NFSMNT_RSIZE;
395 1.1 mycroft break;
396 1.15 fvdl #ifdef ISO
397 1.15 fvdl case 'S':
398 1.15 fvdl nfsargsp->sotype = SOCK_SEQPACKET;
399 1.15 fvdl break;
400 1.15 fvdl #endif
401 1.1 mycroft case 's':
402 1.1 mycroft nfsargsp->flags |= NFSMNT_SOFT;
403 1.1 mycroft break;
404 1.1 mycroft case 'T':
405 1.1 mycroft nfsargsp->sotype = SOCK_STREAM;
406 1.11 fvdl nfsproto = IPPROTO_TCP;
407 1.1 mycroft break;
408 1.1 mycroft case 't':
409 1.1 mycroft num = strtol(optarg, &p, 10);
410 1.1 mycroft if (*p || num <= 0)
411 1.1 mycroft errx(1, "illegal -t value -- %s", optarg);
412 1.1 mycroft nfsargsp->timeo = num;
413 1.1 mycroft nfsargsp->flags |= NFSMNT_TIMEO;
414 1.1 mycroft break;
415 1.1 mycroft case 'w':
416 1.1 mycroft num = strtol(optarg, &p, 10);
417 1.1 mycroft if (*p || num <= 0)
418 1.1 mycroft errx(1, "illegal -w value -- %s", optarg);
419 1.1 mycroft nfsargsp->wsize = num;
420 1.1 mycroft nfsargsp->flags |= NFSMNT_WSIZE;
421 1.1 mycroft break;
422 1.1 mycroft case 'x':
423 1.1 mycroft num = strtol(optarg, &p, 10);
424 1.1 mycroft if (*p || num <= 0)
425 1.1 mycroft errx(1, "illegal -x value -- %s", optarg);
426 1.1 mycroft nfsargsp->retrans = num;
427 1.1 mycroft nfsargsp->flags |= NFSMNT_RETRANS;
428 1.18 fvdl break;
429 1.18 fvdl case 'X':
430 1.18 fvdl nfsargsp->flags |= NFSMNT_XLATECOOKIE;
431 1.1 mycroft break;
432 1.11 fvdl case 'U':
433 1.11 fvdl mnttcp_ok = 0;
434 1.11 fvdl break;
435 1.1 mycroft default:
436 1.1 mycroft usage();
437 1.1 mycroft break;
438 1.1 mycroft }
439 1.1 mycroft argc -= optind;
440 1.1 mycroft argv += optind;
441 1.1 mycroft
442 1.1 mycroft if (argc != 2)
443 1.7 cgd usage();
444 1.1 mycroft
445 1.1 mycroft spec = *argv++;
446 1.1 mycroft name = *argv;
447 1.35 itojun if ((ospec = strdup(spec)) == NULL) {
448 1.35 itojun err(1, "strdup");
449 1.23 perseant }
450 1.1 mycroft
451 1.34 christos if ((mntflags & MNT_GETARGS) == 0) {
452 1.34 christos if (!getnfsargs(spec, nfsargsp))
453 1.34 christos exit(1);
454 1.34 christos }
455 1.33 wrstuden if ((retval = mount(MOUNT_NFS, name, mntflags, nfsargsp))) {
456 1.33 wrstuden /* Did we just default to v3 on a v2-only kernel?
457 1.33 wrstuden * If so, default to v2 & try again */
458 1.33 wrstuden if ((errno == EPROGMISMATCH) && !force3) {
459 1.33 wrstuden nfsargsp->flags &= ~NFSMNT_NFSV3;
460 1.33 wrstuden retval = mount(MOUNT_NFS, name, mntflags, nfsargsp);
461 1.33 wrstuden }
462 1.33 wrstuden }
463 1.33 wrstuden if (retval)
464 1.23 perseant err(1, "%s on %s", ospec, name);
465 1.34 christos if (mntflags & MNT_GETARGS) {
466 1.34 christos shownfsargs(nfsargsp);
467 1.34 christos return 0;
468 1.34 christos }
469 1.34 christos
470 1.1 mycroft if (nfsargsp->flags & (NFSMNT_NQNFS | NFSMNT_KERB)) {
471 1.1 mycroft if ((opflags & ISBGRND) == 0) {
472 1.17 lukem if ((i = fork()) != 0) {
473 1.1 mycroft if (i == -1)
474 1.1 mycroft err(1, "nqnfs 1");
475 1.1 mycroft exit(0);
476 1.1 mycroft }
477 1.1 mycroft (void) setsid();
478 1.1 mycroft (void) close(STDIN_FILENO);
479 1.1 mycroft (void) close(STDOUT_FILENO);
480 1.1 mycroft (void) close(STDERR_FILENO);
481 1.1 mycroft (void) chdir("/");
482 1.1 mycroft }
483 1.30 lukem openlog("mount_nfs", LOG_PID, LOG_DAEMON);
484 1.1 mycroft nfssvc_flag = NFSSVC_MNTD;
485 1.1 mycroft ncd.ncd_dirp = name;
486 1.1 mycroft while (nfssvc(nfssvc_flag, (caddr_t)&ncd) < 0) {
487 1.1 mycroft if (errno != ENEEDAUTH) {
488 1.1 mycroft syslog(LOG_ERR, "nfssvc err %m");
489 1.1 mycroft continue;
490 1.1 mycroft }
491 1.1 mycroft nfssvc_flag =
492 1.1 mycroft NFSSVC_MNTD | NFSSVC_GOTAUTH | NFSSVC_AUTHINFAIL;
493 1.11 fvdl #ifdef NFSKERB
494 1.1 mycroft /*
495 1.1 mycroft * Set up as ncd_authuid for the kerberos call.
496 1.1 mycroft * Must set ruid to ncd_authuid and reset the
497 1.1 mycroft * ticket name iff ncd_authuid is not the same
498 1.1 mycroft * as last time, so that the right ticket file
499 1.1 mycroft * is found.
500 1.11 fvdl * Get the Kerberos credential structure so that
501 1.11 fvdl * we have the seesion key and get a ticket for
502 1.11 fvdl * this uid.
503 1.11 fvdl * For more info see the IETF Draft "Authentication
504 1.11 fvdl * in ONC RPC".
505 1.1 mycroft */
506 1.1 mycroft if (ncd.ncd_authuid != last_ruid) {
507 1.1 mycroft krb_set_tkt_string("");
508 1.1 mycroft last_ruid = ncd.ncd_authuid;
509 1.1 mycroft }
510 1.1 mycroft setreuid(ncd.ncd_authuid, 0);
511 1.11 fvdl kret = krb_get_cred(NFS_KERBSRV, inst, realm, &kcr);
512 1.11 fvdl if (kret == RET_NOTKT) {
513 1.11 fvdl kret = get_ad_tkt(NFS_KERBSRV, inst, realm,
514 1.11 fvdl DEFAULT_TKT_LIFE);
515 1.11 fvdl if (kret == KSUCCESS)
516 1.11 fvdl kret = krb_get_cred(NFS_KERBSRV, inst, realm,
517 1.11 fvdl &kcr);
518 1.11 fvdl }
519 1.11 fvdl if (kret == KSUCCESS)
520 1.11 fvdl kret = krb_mk_req(&ktick.kt, NFS_KERBSRV, inst,
521 1.11 fvdl realm, 0);
522 1.11 fvdl
523 1.11 fvdl /*
524 1.11 fvdl * Fill in the AKN_FULLNAME authenticator and verfier.
525 1.11 fvdl * Along with the Kerberos ticket, we need to build
526 1.11 fvdl * the timestamp verifier and encrypt it in CBC mode.
527 1.11 fvdl */
528 1.11 fvdl if (kret == KSUCCESS &&
529 1.11 fvdl ktick.kt.length <= (RPCAUTH_MAXSIZ-3*NFSX_UNSIGNED)
530 1.11 fvdl && gettimeofday(&ktv, (struct timezone *)0) == 0) {
531 1.11 fvdl ncd.ncd_authtype = RPCAUTH_KERB4;
532 1.11 fvdl ncd.ncd_authstr = (u_char *)&ktick;
533 1.11 fvdl ncd.ncd_authlen = nfsm_rndup(ktick.kt.length) +
534 1.11 fvdl 3 * NFSX_UNSIGNED;
535 1.11 fvdl ncd.ncd_verfstr = (u_char *)&kverf;
536 1.11 fvdl ncd.ncd_verflen = sizeof (kverf);
537 1.11 fvdl memmove(ncd.ncd_key, kcr.session,
538 1.11 fvdl sizeof (kcr.session));
539 1.11 fvdl kin.t1 = htonl(ktv.tv_sec);
540 1.11 fvdl kin.t2 = htonl(ktv.tv_usec);
541 1.11 fvdl kin.w1 = htonl(NFS_KERBTTL);
542 1.11 fvdl kin.w2 = htonl(NFS_KERBTTL - 1);
543 1.17 lukem memset((caddr_t)kivec, 0, sizeof (kivec));
544 1.11 fvdl
545 1.11 fvdl /*
546 1.11 fvdl * Encrypt kin in CBC mode using the session
547 1.11 fvdl * key in kcr.
548 1.11 fvdl */
549 1.11 fvdl XXX
550 1.11 fvdl
551 1.11 fvdl /*
552 1.11 fvdl * Finally, fill the timestamp verifier into the
553 1.11 fvdl * authenticator and verifier.
554 1.11 fvdl */
555 1.11 fvdl ktick.kind = htonl(RPCAKN_FULLNAME);
556 1.11 fvdl kverf.kind = htonl(RPCAKN_FULLNAME);
557 1.11 fvdl NFS_KERBW1(ktick.kt) = kout.w1;
558 1.11 fvdl ktick.kt.length = htonl(ktick.kt.length);
559 1.11 fvdl kverf.verf.t1 = kout.t1;
560 1.11 fvdl kverf.verf.t2 = kout.t2;
561 1.11 fvdl kverf.verf.w2 = kout.w2;
562 1.11 fvdl nfssvc_flag = NFSSVC_MNTD | NFSSVC_GOTAUTH;
563 1.1 mycroft }
564 1.1 mycroft setreuid(0, 0);
565 1.11 fvdl #endif /* NFSKERB */
566 1.1 mycroft }
567 1.1 mycroft }
568 1.1 mycroft exit(0);
569 1.34 christos }
570 1.34 christos
571 1.34 christos static void
572 1.34 christos shownfsargs(nfsargsp)
573 1.34 christos const struct nfs_args *nfsargsp;
574 1.34 christos {
575 1.34 christos char fbuf[2048];
576 1.34 christos
577 1.34 christos (void)snprintb(fbuf, sizeof(fbuf), NFSMNT_BITS, nfsargsp->flags);
578 1.34 christos printf("version=%d, addrlen=%d, sotype=%d, proto=%d, fhsize=%d, "
579 1.34 christos "flags=%s, wsize=%d, rsize=%d, readdirsize=%d, timeo=%d, "
580 1.34 christos "retrans=%d, maxgrouplist=%d, readahead=%d, leaseterm=%d, "
581 1.34 christos "deadthresh=%d\n",
582 1.34 christos nfsargsp->version,
583 1.34 christos nfsargsp->addrlen,
584 1.34 christos nfsargsp->sotype,
585 1.34 christos nfsargsp->proto,
586 1.34 christos nfsargsp->fhsize,
587 1.34 christos fbuf,
588 1.34 christos nfsargsp->wsize,
589 1.34 christos nfsargsp->rsize,
590 1.34 christos nfsargsp->readdirsize,
591 1.34 christos nfsargsp->timeo,
592 1.34 christos nfsargsp->retrans,
593 1.34 christos nfsargsp->maxgrouplist,
594 1.34 christos nfsargsp->readahead,
595 1.34 christos nfsargsp->leaseterm,
596 1.34 christos nfsargsp->deadthresh);
597 1.1 mycroft }
598 1.1 mycroft
599 1.29 jdolecek static int
600 1.1 mycroft getnfsargs(spec, nfsargsp)
601 1.1 mycroft char *spec;
602 1.1 mycroft struct nfs_args *nfsargsp;
603 1.1 mycroft {
604 1.17 lukem CLIENT *clp;
605 1.25 fvdl struct addrinfo hints, *ai_nfs, *ai;
606 1.25 fvdl int ecode;
607 1.25 fvdl char host[NI_MAXHOST], serv[NI_MAXSERV];
608 1.25 fvdl static struct netbuf nfs_nb;
609 1.25 fvdl static struct sockaddr_storage nfs_ss;
610 1.25 fvdl struct netconfig *nconf;
611 1.25 fvdl char *netid;
612 1.1 mycroft #ifdef ISO
613 1.1 mycroft static struct sockaddr_iso isoaddr;
614 1.1 mycroft struct iso_addr *isop;
615 1.1 mycroft int isoflag = 0;
616 1.1 mycroft #endif
617 1.1 mycroft struct timeval pertry, try;
618 1.1 mycroft enum clnt_stat clnt_stat;
619 1.25 fvdl int i, nfsvers, mntvers, orgcnt;
620 1.1 mycroft char *hostp, *delimp;
621 1.11 fvdl #ifdef NFSKERB
622 1.1 mycroft char *cp;
623 1.1 mycroft #endif
624 1.1 mycroft static struct nfhret nfhret;
625 1.1 mycroft static char nam[MNAMELEN + 1];
626 1.1 mycroft
627 1.1 mycroft strncpy(nam, spec, MNAMELEN);
628 1.1 mycroft nam[MNAMELEN] = '\0';
629 1.1 mycroft if ((delimp = strchr(spec, '@')) != NULL) {
630 1.1 mycroft hostp = delimp + 1;
631 1.25 fvdl } else if ((delimp = strrchr(spec, ':')) != NULL) {
632 1.1 mycroft hostp = spec;
633 1.1 mycroft spec = delimp + 1;
634 1.1 mycroft } else {
635 1.1 mycroft warnx("no <host>:<dirpath> or <dirpath>@<host> spec");
636 1.1 mycroft return (0);
637 1.1 mycroft }
638 1.1 mycroft *delimp = '\0';
639 1.1 mycroft /*
640 1.1 mycroft * DUMB!! Until the mount protocol works on iso transport, we must
641 1.1 mycroft * supply both an iso and an inet address for the host.
642 1.1 mycroft */
643 1.1 mycroft #ifdef ISO
644 1.1 mycroft if (!strncmp(hostp, "iso=", 4)) {
645 1.1 mycroft u_short isoport;
646 1.1 mycroft
647 1.1 mycroft hostp += 4;
648 1.1 mycroft isoflag++;
649 1.1 mycroft if ((delimp = strchr(hostp, '+')) == NULL) {
650 1.1 mycroft warnx("no iso+inet address");
651 1.1 mycroft return (0);
652 1.1 mycroft }
653 1.1 mycroft *delimp = '\0';
654 1.1 mycroft if ((isop = iso_addr(hostp)) == NULL) {
655 1.1 mycroft warnx("bad ISO address");
656 1.1 mycroft return (0);
657 1.1 mycroft }
658 1.6 mycroft memset(&isoaddr, 0, sizeof (isoaddr));
659 1.6 mycroft memcpy(&isoaddr.siso_addr, isop, sizeof (struct iso_addr));
660 1.1 mycroft isoaddr.siso_len = sizeof (isoaddr);
661 1.1 mycroft isoaddr.siso_family = AF_ISO;
662 1.1 mycroft isoaddr.siso_tlen = 2;
663 1.1 mycroft isoport = htons(NFS_PORT);
664 1.6 mycroft memcpy(TSEL(&isoaddr), &isoport, isoaddr.siso_tlen);
665 1.1 mycroft hostp = delimp + 1;
666 1.1 mycroft }
667 1.1 mycroft #endif /* ISO */
668 1.1 mycroft
669 1.1 mycroft /*
670 1.1 mycroft * Handle an internet host address and reverse resolve it if
671 1.1 mycroft * doing Kerberos.
672 1.1 mycroft */
673 1.25 fvdl memset(&hints, 0, sizeof hints);
674 1.25 fvdl hints.ai_flags = AI_NUMERICHOST;
675 1.25 fvdl hints.ai_socktype = nfsargsp->sotype;
676 1.25 fvdl if (getaddrinfo(hostp, "nfs", &hints, &ai_nfs) == 0) {
677 1.10 mycroft if ((nfsargsp->flags & NFSMNT_KERB)) {
678 1.25 fvdl hints.ai_flags = 0;
679 1.25 fvdl if (getnameinfo(ai->ai_addr, ai->ai_addrlen, host,
680 1.25 fvdl sizeof host, serv, sizeof serv, 0) != 0) {
681 1.31 mrg warnx("can't reverse resolve net address for "
682 1.31 mrg "host \"%s\": %s", hostp,
683 1.31 mrg gai_strerror(ecode));
684 1.10 mycroft return (0);
685 1.10 mycroft }
686 1.25 fvdl hostp = host;
687 1.1 mycroft }
688 1.10 mycroft } else {
689 1.25 fvdl hints.ai_flags = 0;
690 1.25 fvdl if ((ecode = getaddrinfo(hostp, "nfs", &hints, &ai_nfs)) != 0) {
691 1.31 mrg warnx("can't get net id for host \"%s\": %s", hostp,
692 1.25 fvdl gai_strerror(ecode));
693 1.1 mycroft return (0);
694 1.1 mycroft }
695 1.10 mycroft }
696 1.11 fvdl #ifdef NFSKERB
697 1.1 mycroft if (nfsargsp->flags & NFSMNT_KERB) {
698 1.1 mycroft strncpy(inst, hp->h_name, INST_SZ);
699 1.1 mycroft inst[INST_SZ - 1] = '\0';
700 1.1 mycroft if (cp = strchr(inst, '.'))
701 1.1 mycroft *cp = '\0';
702 1.1 mycroft }
703 1.11 fvdl #endif /* NFSKERB */
704 1.1 mycroft
705 1.11 fvdl if (force2) {
706 1.11 fvdl nfsvers = NFS_VER2;
707 1.11 fvdl mntvers = RPCMNT_VER1;
708 1.11 fvdl } else {
709 1.11 fvdl nfsvers = NFS_VER3;
710 1.11 fvdl mntvers = RPCMNT_VER3;
711 1.11 fvdl }
712 1.11 fvdl orgcnt = retrycnt;
713 1.25 fvdl nfhret.stat = EACCES; /* Mark not yet successful */
714 1.25 fvdl
715 1.35 itojun for (ai = ai_nfs; ai; ai = ai->ai_next) {
716 1.25 fvdl /*
717 1.25 fvdl * XXX. Nead a generic (family, type, proto) -> nconf interface.
718 1.25 fvdl * __rpc_*2nconf exist, maybe they should be exported.
719 1.25 fvdl */
720 1.25 fvdl if (nfsargsp->sotype == SOCK_STREAM) {
721 1.25 fvdl if (ai->ai_family == AF_INET6)
722 1.25 fvdl netid = "tcp6";
723 1.25 fvdl else
724 1.25 fvdl netid = "tcp";
725 1.25 fvdl } else {
726 1.25 fvdl if (ai->ai_family == AF_INET6)
727 1.25 fvdl netid = "udp6";
728 1.25 fvdl else
729 1.25 fvdl netid = "udp";
730 1.25 fvdl }
731 1.25 fvdl
732 1.25 fvdl nconf = getnetconfigent(netid);
733 1.25 fvdl
734 1.11 fvdl tryagain:
735 1.25 fvdl retrycnt = orgcnt;
736 1.25 fvdl
737 1.1 mycroft while (retrycnt > 0) {
738 1.25 fvdl nfs_nb.buf = &nfs_ss;
739 1.25 fvdl nfs_nb.maxlen = sizeof nfs_ss;
740 1.25 fvdl if (!rpcb_getaddr(RPCPROG_NFS, nfsvers, nconf, &nfs_nb, hostp)){
741 1.26 fvdl if (rpc_createerr.cf_stat == RPC_SYSTEMERROR) {
742 1.26 fvdl nfhret.stat = rpc_createerr.cf_error.re_errno;
743 1.26 fvdl break;
744 1.26 fvdl }
745 1.26 fvdl if (rpc_createerr.cf_stat == RPC_UNKNOWNPROTO) {
746 1.26 fvdl nfhret.stat = EPROTONOSUPPORT;
747 1.26 fvdl break;
748 1.26 fvdl }
749 1.1 mycroft if ((opflags & ISBGRND) == 0)
750 1.25 fvdl clnt_pcreateerror(
751 1.32 cjs "mount_nfs: rpcbind to nfs on server");
752 1.1 mycroft } else {
753 1.1 mycroft pertry.tv_sec = 10;
754 1.1 mycroft pertry.tv_usec = 0;
755 1.25 fvdl /*
756 1.25 fvdl * XXX relies on clnt_tcp_create to bind to a reserved
757 1.25 fvdl * socket.
758 1.25 fvdl */
759 1.25 fvdl clp = clnt_tp_create(hostp, RPCPROG_MNT, mntvers,
760 1.25 fvdl mnttcp_ok ? nconf : getnetconfigent("udp"));
761 1.11 fvdl if (clp == NULL) {
762 1.32 cjs if ((opflags & ISBGRND) == 0) {
763 1.32 cjs clnt_pcreateerror(
764 1.32 cjs "Cannot MNT RPC (mountd)");
765 1.32 cjs }
766 1.1 mycroft } else {
767 1.25 fvdl CLNT_CONTROL(clp, CLSET_RETRY_TIMEOUT,
768 1.25 fvdl (char *)&pertry);
769 1.25 fvdl clp->cl_auth = authsys_create_default();
770 1.1 mycroft try.tv_sec = 10;
771 1.1 mycroft try.tv_usec = 0;
772 1.11 fvdl if (nfsargsp->flags & NFSMNT_KERB)
773 1.11 fvdl nfhret.auth = RPCAUTH_KERB4;
774 1.11 fvdl else
775 1.11 fvdl nfhret.auth = RPCAUTH_UNIX;
776 1.11 fvdl nfhret.vers = mntvers;
777 1.1 mycroft clnt_stat = clnt_call(clp, RPCMNT_MOUNT,
778 1.1 mycroft xdr_dir, spec, xdr_fh, &nfhret, try);
779 1.15 fvdl switch (clnt_stat) {
780 1.15 fvdl case RPC_PROGVERSMISMATCH:
781 1.15 fvdl if (nfsvers == NFS_VER3 && !force3) {
782 1.15 fvdl nfsvers = NFS_VER2;
783 1.15 fvdl mntvers = RPCMNT_VER1;
784 1.15 fvdl nfsargsp->flags &=
785 1.15 fvdl ~NFSMNT_NFSV3;
786 1.15 fvdl goto tryagain;
787 1.15 fvdl } else {
788 1.15 fvdl errx(1, "%s", clnt_sperror(clp,
789 1.15 fvdl "MNT RPC"));
790 1.11 fvdl }
791 1.15 fvdl case RPC_SUCCESS:
792 1.15 fvdl auth_destroy(clp->cl_auth);
793 1.15 fvdl clnt_destroy(clp);
794 1.15 fvdl retrycnt = 0;
795 1.15 fvdl break;
796 1.15 fvdl default:
797 1.15 fvdl /* XXX should give up on some errors */
798 1.1 mycroft if ((opflags & ISBGRND) == 0)
799 1.1 mycroft warnx("%s", clnt_sperror(clp,
800 1.1 mycroft "bad MNT RPC"));
801 1.15 fvdl break;
802 1.1 mycroft }
803 1.1 mycroft }
804 1.1 mycroft }
805 1.1 mycroft if (--retrycnt > 0) {
806 1.1 mycroft if (opflags & BGRND) {
807 1.1 mycroft opflags &= ~BGRND;
808 1.17 lukem if ((i = fork()) != 0) {
809 1.1 mycroft if (i == -1)
810 1.1 mycroft err(1, "nqnfs 2");
811 1.1 mycroft exit(0);
812 1.1 mycroft }
813 1.1 mycroft (void) setsid();
814 1.1 mycroft (void) close(STDIN_FILENO);
815 1.1 mycroft (void) close(STDOUT_FILENO);
816 1.1 mycroft (void) close(STDERR_FILENO);
817 1.1 mycroft (void) chdir("/");
818 1.1 mycroft opflags |= ISBGRND;
819 1.1 mycroft }
820 1.1 mycroft sleep(60);
821 1.1 mycroft }
822 1.28 itojun }
823 1.28 itojun if (nfhret.stat == 0)
824 1.25 fvdl break;
825 1.28 itojun }
826 1.25 fvdl freeaddrinfo(ai_nfs);
827 1.1 mycroft if (nfhret.stat) {
828 1.1 mycroft if (opflags & ISBGRND)
829 1.1 mycroft exit(1);
830 1.4 mycroft errno = nfhret.stat;
831 1.11 fvdl warnx("can't access %s: %s", spec, strerror(nfhret.stat));
832 1.1 mycroft return (0);
833 1.1 mycroft }
834 1.1 mycroft #ifdef ISO
835 1.1 mycroft if (isoflag) {
836 1.1 mycroft nfsargsp->addr = (struct sockaddr *) &isoaddr;
837 1.1 mycroft nfsargsp->addrlen = sizeof (isoaddr);
838 1.1 mycroft } else
839 1.1 mycroft #endif /* ISO */
840 1.1 mycroft {
841 1.25 fvdl nfsargsp->addr = (struct sockaddr *) nfs_nb.buf;
842 1.25 fvdl nfsargsp->addrlen = nfs_nb.len;
843 1.1 mycroft }
844 1.11 fvdl nfsargsp->fh = nfhret.nfh;
845 1.11 fvdl nfsargsp->fhsize = nfhret.fhsize;
846 1.1 mycroft nfsargsp->hostname = nam;
847 1.1 mycroft return (1);
848 1.1 mycroft }
849 1.1 mycroft
850 1.1 mycroft /*
851 1.1 mycroft * xdr routines for mount rpc's
852 1.1 mycroft */
853 1.29 jdolecek static int
854 1.1 mycroft xdr_dir(xdrsp, dirp)
855 1.1 mycroft XDR *xdrsp;
856 1.1 mycroft char *dirp;
857 1.1 mycroft {
858 1.1 mycroft return (xdr_string(xdrsp, &dirp, RPCMNT_PATHLEN));
859 1.1 mycroft }
860 1.1 mycroft
861 1.29 jdolecek static int
862 1.1 mycroft xdr_fh(xdrsp, np)
863 1.1 mycroft XDR *xdrsp;
864 1.17 lukem struct nfhret *np;
865 1.1 mycroft {
866 1.17 lukem int i;
867 1.11 fvdl long auth, authcnt, authfnd = 0;
868 1.11 fvdl
869 1.11 fvdl if (!xdr_u_long(xdrsp, &np->stat))
870 1.1 mycroft return (0);
871 1.1 mycroft if (np->stat)
872 1.1 mycroft return (1);
873 1.11 fvdl switch (np->vers) {
874 1.11 fvdl case 1:
875 1.11 fvdl np->fhsize = NFSX_V2FH;
876 1.11 fvdl return (xdr_opaque(xdrsp, (caddr_t)np->nfh, NFSX_V2FH));
877 1.11 fvdl case 3:
878 1.11 fvdl if (!xdr_long(xdrsp, &np->fhsize))
879 1.11 fvdl return (0);
880 1.11 fvdl if (np->fhsize <= 0 || np->fhsize > NFSX_V3FHMAX)
881 1.11 fvdl return (0);
882 1.11 fvdl if (!xdr_opaque(xdrsp, (caddr_t)np->nfh, np->fhsize))
883 1.11 fvdl return (0);
884 1.11 fvdl if (!xdr_long(xdrsp, &authcnt))
885 1.11 fvdl return (0);
886 1.11 fvdl for (i = 0; i < authcnt; i++) {
887 1.11 fvdl if (!xdr_long(xdrsp, &auth))
888 1.11 fvdl return (0);
889 1.11 fvdl if (auth == np->auth)
890 1.11 fvdl authfnd++;
891 1.11 fvdl }
892 1.11 fvdl /*
893 1.11 fvdl * Some servers, such as DEC's OSF/1 return a nil authenticator
894 1.11 fvdl * list to indicate RPCAUTH_UNIX.
895 1.11 fvdl */
896 1.11 fvdl if (!authfnd && (authcnt > 0 || np->auth != RPCAUTH_UNIX))
897 1.11 fvdl np->stat = EAUTH;
898 1.11 fvdl return (1);
899 1.11 fvdl };
900 1.11 fvdl return (0);
901 1.1 mycroft }
902 1.1 mycroft
903 1.29 jdolecek static void
904 1.1 mycroft usage()
905 1.1 mycroft {
906 1.24 mjl (void)fprintf(stderr, "usage: mount_nfs %s\n%s\n%s\n%s\n%s\n",
907 1.24 mjl "[-23bcCdiKlpPqsTUX] [-a maxreadahead] [-D deadthresh]",
908 1.24 mjl "\t[-g maxgroups] [-I readdirsize] [-L leaseterm] [-m realm]",
909 1.24 mjl "\t[-o options] [-R retrycnt] [-r readsize] [-t timeout]",
910 1.24 mjl "\t[-w writesize] [-x retrans]",
911 1.1 mycroft "\trhost:path node");
912 1.1 mycroft exit(1);
913 1.1 mycroft }
914