1 /* 2 * Copyright (c) 1992, 1993, 1994 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Rick Macklem at The University of Guelph. 7 * 8 * %sccs.include.redist.c% 9 */ 10 11 #ifndef lint 12 static char copyright[] = 13 "@(#) Copyright (c) 1992, 1993, 1994\n\ 14 The Regents of the University of California. All rights reserved.\n"; 15 #endif /* not lint */ 16 17 #ifndef lint 18 static char sccsid[] = "@(#)mount_nfs.c 8.11 (Berkeley) 05/04/95"; 19 #endif /* not lint */ 20 21 #include <sys/param.h> 22 #include <sys/mount.h> 23 #include <sys/socket.h> 24 #include <sys/socketvar.h> 25 #include <sys/stat.h> 26 #include <sys/syslog.h> 27 28 #include <rpc/rpc.h> 29 #include <rpc/pmap_clnt.h> 30 #include <rpc/pmap_prot.h> 31 32 #ifdef ISO 33 #include <netiso/iso.h> 34 #endif 35 36 #ifdef NFSKERB 37 #include <kerberosIV/des.h> 38 #include <kerberosIV/krb.h> 39 #endif 40 41 #include <nfs/rpcv2.h> 42 #include <nfs/nfsproto.h> 43 #define KERNEL 44 #include <nfs/nfs.h> 45 #undef KERNEL 46 #include <nfs/nqnfs.h> 47 48 #include <arpa/inet.h> 49 50 #include <ctype.h> 51 #include <err.h> 52 #include <errno.h> 53 #include <fcntl.h> 54 #include <netdb.h> 55 #include <signal.h> 56 #include <stdio.h> 57 #include <stdlib.h> 58 #include <strings.h> 59 #include <unistd.h> 60 61 #include "mntopts.h" 62 63 #define ALTF_BG 0x1 64 #define ALTF_NOCONN 0x2 65 #define ALTF_DUMBTIMR 0x4 66 #define ALTF_INTR 0x8 67 #define ALTF_KERB 0x10 68 #define ALTF_NFSV3 0x20 69 #define ALTF_RDIRPLUS 0x40 70 #define ALTF_MNTUDP 0x80 71 #define ALTF_RESVPORT 0x100 72 #define ALTF_SEQPACKET 0x200 73 #define ALTF_NQNFS 0x400 74 #define ALTF_SOFT 0x800 75 #define ALTF_TCP 0x1000 76 77 struct mntopt mopts[] = { 78 MOPT_STDOPTS, 79 MOPT_FORCE, 80 MOPT_UPDATE, 81 { "bg", 0, ALTF_BG, 1 }, 82 { "conn", 1, ALTF_NOCONN, 1 }, 83 { "dumbtimer", 0, ALTF_DUMBTIMR, 1 }, 84 { "intr", 0, ALTF_INTR, 1 }, 85 #ifdef NFSKERB 86 { "kerb", 0, ALTF_KERB, 1 }, 87 #endif 88 { "nfsv3", 0, ALTF_NFSV3, 1 }, 89 { "rdirplus", 0, ALTF_RDIRPLUS, 1 }, 90 { "mntudp", 0, ALTF_MNTUDP, 1 }, 91 { "resvport", 0, ALTF_RESVPORT, 1 }, 92 #ifdef ISO 93 { "seqpacket", 0, ALTF_SEQPACKET, 1 }, 94 #endif 95 { "nqnfs", 0, ALTF_NQNFS, 1 }, 96 { "soft", 0, ALTF_SOFT, 1 }, 97 { "tcp", 0, ALTF_TCP, 1 }, 98 { NULL } 99 }; 100 101 struct nfs_args nfsdefargs = { 102 NFS_ARGSVERSION, 103 (struct sockaddr *)0, 104 sizeof (struct sockaddr_in), 105 SOCK_DGRAM, 106 0, 107 (u_char *)0, 108 0, 109 0, 110 NFS_WSIZE, 111 NFS_RSIZE, 112 NFS_READDIRSIZE, 113 10, 114 NFS_RETRANS, 115 NFS_MAXGRPS, 116 NFS_DEFRAHEAD, 117 NQ_DEFLEASE, 118 NQ_DEADTHRESH, 119 (char *)0, 120 }; 121 122 struct nfhret { 123 u_long stat; 124 long vers; 125 long auth; 126 long fhsize; 127 u_char nfh[NFSX_V3FHMAX]; 128 }; 129 #define DEF_RETRY 10000 130 #define BGRND 1 131 #define ISBGRND 2 132 int retrycnt = DEF_RETRY; 133 int opflags = 0; 134 int nfsproto = IPPROTO_UDP; 135 int mnttcp_ok = 1; 136 137 #ifdef NFSKERB 138 char inst[INST_SZ]; 139 char realm[REALM_SZ]; 140 struct { 141 u_long kind; 142 KTEXT_ST kt; 143 } ktick; 144 struct nfsrpc_nickverf kverf; 145 struct nfsrpc_fullblock kin, kout; 146 NFSKERBKEY_T kivec; 147 CREDENTIALS kcr; 148 struct timeval ktv; 149 NFSKERBKEYSCHED_T kerb_keysched; 150 #endif 151 152 int getnfsargs __P((char *, struct nfs_args *)); 153 #ifdef ISO 154 struct iso_addr *iso_addr __P((const char *)); 155 #endif 156 void set_rpc_maxgrouplist __P((int)); 157 __dead void usage __P((void)); 158 int xdr_dir __P((XDR *, char *)); 159 int xdr_fh __P((XDR *, struct nfhret *)); 160 161 int 162 main(argc, argv) 163 int argc; 164 char *argv[]; 165 { 166 register int c; 167 register struct nfs_args *nfsargsp; 168 struct nfs_args nfsargs; 169 struct nfsd_cargs ncd; 170 int mntflags, altflags, i, nfssvc_flag, num; 171 char *name, *p, *spec; 172 int error = 0; 173 #ifdef NFSKERB 174 uid_t last_ruid; 175 176 last_ruid = -1; 177 (void)strcpy(realm, KRB_REALM); 178 if (sizeof (struct nfsrpc_nickverf) != RPCX_NICKVERF || 179 sizeof (struct nfsrpc_fullblock) != RPCX_FULLBLOCK || 180 ((char *)&ktick.kt) - ((char *)&ktick) != NFSX_UNSIGNED || 181 ((char *)ktick.kt.dat) - ((char *)&ktick) != 2 * NFSX_UNSIGNED) 182 fprintf(stderr, "Yikes! NFSKERB structs not packed!!\n"); 183 #endif /* NFSKERB */ 184 retrycnt = DEF_RETRY; 185 186 mntflags = 0; 187 altflags = 0; 188 nfsargs = nfsdefargs; 189 nfsargsp = &nfsargs; 190 while ((c = getopt(argc, argv, 191 "3a:bcdD:g:I:iKL:lm:o:PpqR:r:sTt:w:x:U")) != EOF) 192 switch (c) { 193 case '3': 194 nfsargsp->flags |= NFSMNT_NFSV3; 195 break; 196 case 'a': 197 num = strtol(optarg, &p, 10); 198 if (*p || num < 0) 199 errx(1, "illegal -a value -- %s", optarg); 200 nfsargsp->readahead = num; 201 nfsargsp->flags |= NFSMNT_READAHEAD; 202 break; 203 case 'b': 204 opflags |= BGRND; 205 break; 206 case 'c': 207 nfsargsp->flags |= NFSMNT_NOCONN; 208 break; 209 case 'D': 210 num = strtol(optarg, &p, 10); 211 if (*p || num <= 0) 212 errx(1, "illegal -D value -- %s", optarg); 213 nfsargsp->deadthresh = num; 214 nfsargsp->flags |= NFSMNT_DEADTHRESH; 215 break; 216 case 'd': 217 nfsargsp->flags |= NFSMNT_DUMBTIMR; 218 break; 219 case 'g': 220 num = strtol(optarg, &p, 10); 221 if (*p || num <= 0) 222 errx(1, "illegal -g value -- %s", optarg); 223 set_rpc_maxgrouplist(num); 224 nfsargsp->maxgrouplist = num; 225 nfsargsp->flags |= NFSMNT_MAXGRPS; 226 break; 227 case 'I': 228 num = strtol(optarg, &p, 10); 229 if (*p || num <= 0) 230 errx(1, "illegal -I value -- %s", optarg); 231 nfsargsp->readdirsize = num; 232 nfsargsp->flags |= NFSMNT_READDIRSIZE; 233 break; 234 case 'i': 235 nfsargsp->flags |= NFSMNT_INT; 236 break; 237 #ifdef NFSKERB 238 case 'K': 239 nfsargsp->flags |= NFSMNT_KERB; 240 break; 241 #endif 242 case 'L': 243 num = strtol(optarg, &p, 10); 244 if (*p || num < 2) 245 errx(1, "illegal -L value -- %s", optarg); 246 nfsargsp->leaseterm = num; 247 nfsargsp->flags |= NFSMNT_LEASETERM; 248 break; 249 case 'l': 250 nfsargsp->flags |= NFSMNT_RDIRPLUS; 251 break; 252 #ifdef NFSKERB 253 case 'm': 254 (void)strncpy(realm, optarg, REALM_SZ - 1); 255 realm[REALM_SZ - 1] = '\0'; 256 break; 257 #endif 258 case 'o': 259 getmntopts(optarg, mopts, &mntflags, &altflags); 260 if(altflags & ALTF_BG) 261 opflags |= BGRND; 262 if(altflags & ALTF_NOCONN) 263 nfsargsp->flags |= NFSMNT_NOCONN; 264 if(altflags & ALTF_DUMBTIMR) 265 nfsargsp->flags |= NFSMNT_DUMBTIMR; 266 if(altflags & ALTF_INTR) 267 nfsargsp->flags |= NFSMNT_INT; 268 #ifdef NFSKERB 269 if(altflags & ALTF_KERB) 270 nfsargsp->flags |= NFSMNT_KERB; 271 #endif 272 if(altflags & ALTF_NFSV3) 273 nfsargsp->flags |= NFSMNT_NFSV3; 274 if(altflags & ALTF_RDIRPLUS) 275 nfsargsp->flags |= NFSMNT_RDIRPLUS; 276 if(altflags & ALTF_MNTUDP) 277 mnttcp_ok = 0; 278 if(altflags & ALTF_RESVPORT) 279 nfsargsp->flags |= NFSMNT_RESVPORT; 280 #ifdef ISO 281 if(altflags & ALTF_SEQPACKET) 282 nfsargsp->sotype = SOCK_SEQPACKET; 283 #endif 284 if(altflags & ALTF_NQNFS) 285 nfsargsp->flags |= (NFSMNT_NQNFS|NFSMNT_NFSV3); 286 if(altflags & ALTF_SOFT) 287 nfsargsp->flags |= NFSMNT_SOFT; 288 if(altflags & ALTF_TCP) { 289 nfsargsp->sotype = SOCK_STREAM; 290 nfsproto = IPPROTO_TCP; 291 } 292 altflags = 0; 293 break; 294 case 'P': 295 nfsargsp->flags |= NFSMNT_RESVPORT; 296 break; 297 #ifdef ISO 298 case 'p': 299 nfsargsp->sotype = SOCK_SEQPACKET; 300 break; 301 #endif 302 case 'q': 303 nfsargsp->flags |= (NFSMNT_NQNFS | NFSMNT_NFSV3); 304 break; 305 case 'R': 306 num = strtol(optarg, &p, 10); 307 if (*p || num <= 0) 308 errx(1, "illegal -R value -- %s", optarg); 309 retrycnt = num; 310 break; 311 case 'r': 312 num = strtol(optarg, &p, 10); 313 if (*p || num <= 0) 314 errx(1, "illegal -r value -- %s", optarg); 315 nfsargsp->rsize = num; 316 nfsargsp->flags |= NFSMNT_RSIZE; 317 break; 318 case 's': 319 nfsargsp->flags |= NFSMNT_SOFT; 320 break; 321 case 'T': 322 nfsargsp->sotype = SOCK_STREAM; 323 nfsproto = IPPROTO_TCP; 324 break; 325 case 't': 326 num = strtol(optarg, &p, 10); 327 if (*p || num <= 0) 328 errx(1, "illegal -t value -- %s", optarg); 329 nfsargsp->timeo = num; 330 nfsargsp->flags |= NFSMNT_TIMEO; 331 break; 332 case 'w': 333 num = strtol(optarg, &p, 10); 334 if (*p || num <= 0) 335 errx(1, "illegal -w value -- %s", optarg); 336 nfsargsp->wsize = num; 337 nfsargsp->flags |= NFSMNT_WSIZE; 338 break; 339 case 'x': 340 num = strtol(optarg, &p, 10); 341 if (*p || num <= 0) 342 errx(1, "illegal -x value -- %s", optarg); 343 nfsargsp->retrans = num; 344 nfsargsp->flags |= NFSMNT_RETRANS; 345 break; 346 case 'U': 347 mnttcp_ok = 0; 348 break; 349 default: 350 usage(); 351 break; 352 } 353 argc -= optind; 354 argv += optind; 355 356 if (argc != 2) { 357 usage(); 358 /* NOTREACHED */ 359 } 360 361 spec = *argv++; 362 name = *argv; 363 364 if (!getnfsargs(spec, nfsargsp)) 365 exit(1); 366 367 if (mount("nfs", name, mntflags, nfsargsp)) 368 err(1, "%s", name); 369 if (nfsargsp->flags & (NFSMNT_NQNFS | NFSMNT_KERB)) { 370 if ((opflags & ISBGRND) == 0) { 371 if (i = fork()) { 372 if (i == -1) 373 err(1, "nqnfs 1"); 374 exit(0); 375 } 376 (void) setsid(); 377 (void) close(STDIN_FILENO); 378 (void) close(STDOUT_FILENO); 379 (void) close(STDERR_FILENO); 380 (void) chdir("/"); 381 } 382 openlog("mount_nfs:", LOG_PID, LOG_DAEMON); 383 nfssvc_flag = NFSSVC_MNTD; 384 ncd.ncd_dirp = name; 385 while (nfssvc(nfssvc_flag, (caddr_t)&ncd) < 0) { 386 if (errno != ENEEDAUTH) { 387 syslog(LOG_ERR, "nfssvc err %m"); 388 continue; 389 } 390 nfssvc_flag = 391 NFSSVC_MNTD | NFSSVC_GOTAUTH | NFSSVC_AUTHINFAIL; 392 #ifdef NFSKERB 393 /* 394 * Set up as ncd_authuid for the kerberos call. 395 * Must set ruid to ncd_authuid and reset the 396 * ticket name iff ncd_authuid is not the same 397 * as last time, so that the right ticket file 398 * is found. 399 * Get the Kerberos credential structure so that 400 * we have the seesion key and get a ticket for 401 * this uid. 402 * For more info see the IETF Draft "Authentication 403 * in ONC RPC". 404 */ 405 if (ncd.ncd_authuid != last_ruid) { 406 krb_set_tkt_string(""); 407 last_ruid = ncd.ncd_authuid; 408 } 409 setreuid(ncd.ncd_authuid, 0); 410 kret = krb_get_cred(NFS_KERBSRV, inst, realm, &kcr); 411 if (kret == RET_NOTKT) { 412 kret = get_ad_tkt(NFS_KERBSRV, inst, realm, 413 DEFAULT_TKT_LIFE); 414 if (kret == KSUCCESS) 415 kret = krb_get_cred(NFS_KERBSRV, inst, realm, 416 &kcr); 417 } 418 if (kret == KSUCCESS) 419 kret = krb_mk_req(&ktick.kt, NFS_KERBSRV, inst, 420 realm, 0); 421 422 /* 423 * Fill in the AKN_FULLNAME authenticator and verfier. 424 * Along with the Kerberos ticket, we need to build 425 * the timestamp verifier and encrypt it in CBC mode. 426 */ 427 if (kret == KSUCCESS && 428 ktick.kt.length <= (RPCAUTH_MAXSIZ-3*NFSX_UNSIGNED) 429 && gettimeofday(&ktv, (struct timezone *)0) == 0) { 430 ncd.ncd_authtype = RPCAUTH_KERB4; 431 ncd.ncd_authstr = (u_char *)&ktick; 432 ncd.ncd_authlen = nfsm_rndup(ktick.kt.length) + 433 3 * NFSX_UNSIGNED; 434 ncd.ncd_verfstr = (u_char *)&kverf; 435 ncd.ncd_verflen = sizeof (kverf); 436 memmove(ncd.ncd_key, kcr.session, 437 sizeof (kcr.session)); 438 kin.t1 = htonl(ktv.tv_sec); 439 kin.t2 = htonl(ktv.tv_usec); 440 kin.w1 = htonl(NFS_KERBTTL); 441 kin.w2 = htonl(NFS_KERBTTL - 1); 442 bzero((caddr_t)kivec, sizeof (kivec)); 443 444 /* 445 * Encrypt kin in CBC mode using the session 446 * key in kcr. 447 */ 448 XXX 449 450 /* 451 * Finally, fill the timestamp verifier into the 452 * authenticator and verifier. 453 */ 454 ktick.kind = htonl(RPCAKN_FULLNAME); 455 kverf.kind = htonl(RPCAKN_FULLNAME); 456 NFS_KERBW1(ktick.kt) = kout.w1; 457 ktick.kt.length = htonl(ktick.kt.length); 458 kverf.verf.t1 = kout.t1; 459 kverf.verf.t2 = kout.t2; 460 kverf.verf.w2 = kout.w2; 461 nfssvc_flag = NFSSVC_MNTD | NFSSVC_GOTAUTH; 462 } 463 setreuid(0, 0); 464 #endif /* NFSKERB */ 465 } 466 } 467 exit(0); 468 } 469 470 int 471 getnfsargs(spec, nfsargsp) 472 char *spec; 473 struct nfs_args *nfsargsp; 474 { 475 register CLIENT *clp; 476 struct hostent *hp; 477 static struct sockaddr_in saddr; 478 #ifdef ISO 479 static struct sockaddr_iso isoaddr; 480 struct iso_addr *isop; 481 int isoflag = 0; 482 #endif 483 struct timeval pertry, try; 484 enum clnt_stat clnt_stat; 485 int so = RPC_ANYSOCK, i, nfsvers, mntvers; 486 char *hostp, *delimp; 487 #ifdef NFSKERB 488 char *cp; 489 #endif 490 u_short tport; 491 static struct nfhret nfhret; 492 static char nam[MNAMELEN + 1]; 493 494 strncpy(nam, spec, MNAMELEN); 495 nam[MNAMELEN] = '\0'; 496 if ((delimp = strchr(spec, '@')) != NULL) { 497 hostp = delimp + 1; 498 } else if ((delimp = strchr(spec, ':')) != NULL) { 499 hostp = spec; 500 spec = delimp + 1; 501 } else { 502 warnx("no <host>:<dirpath> or <dirpath>@<host> spec"); 503 return (0); 504 } 505 *delimp = '\0'; 506 /* 507 * DUMB!! Until the mount protocol works on iso transport, we must 508 * supply both an iso and an inet address for the host. 509 */ 510 #ifdef ISO 511 if (!strncmp(hostp, "iso=", 4)) { 512 u_short isoport; 513 514 hostp += 4; 515 isoflag++; 516 if ((delimp = strchr(hostp, '+')) == NULL) { 517 warnx("no iso+inet address"); 518 return (0); 519 } 520 *delimp = '\0'; 521 if ((isop = iso_addr(hostp)) == NULL) { 522 warnx("bad ISO address"); 523 return (0); 524 } 525 memset(&isoaddr, 0, sizeof (isoaddr)); 526 memmove(&isoaddr.siso_addr, isop, sizeof (struct iso_addr)); 527 isoaddr.siso_len = sizeof (isoaddr); 528 isoaddr.siso_family = AF_ISO; 529 isoaddr.siso_tlen = 2; 530 isoport = htons(NFS_PORT); 531 memmove(TSEL(&isoaddr), &isoport, isoaddr.siso_tlen); 532 hostp = delimp + 1; 533 } 534 #endif /* ISO */ 535 536 /* 537 * Handle an internet host address and reverse resolve it if 538 * doing Kerberos. 539 */ 540 if (isdigit(*hostp)) { 541 if ((saddr.sin_addr.s_addr = inet_addr(hostp)) == -1) { 542 warnx("bad net address %s", hostp); 543 return (0); 544 } 545 } else if ((hp = gethostbyname(hostp)) != NULL) 546 memmove(&saddr.sin_addr, hp->h_addr, hp->h_length); 547 else { 548 warnx("can't get net id for host"); 549 return (0); 550 } 551 #ifdef NFSKERB 552 if ((nfsargsp->flags & NFSMNT_KERB)) { 553 if ((hp = gethostbyaddr((char *)&saddr.sin_addr.s_addr, 554 sizeof (u_long), AF_INET)) == (struct hostent *)0) { 555 warnx("can't reverse resolve net address"); 556 return (0); 557 } 558 memmove(&saddr.sin_addr, hp->h_addr, hp->h_length); 559 strncpy(inst, hp->h_name, INST_SZ); 560 inst[INST_SZ - 1] = '\0'; 561 if (cp = strchr(inst, '.')) 562 *cp = '\0'; 563 } 564 #endif /* NFSKERB */ 565 566 if (nfsargsp->flags & NFSMNT_NFSV3) { 567 nfsvers = 3; 568 mntvers = 3; 569 } else { 570 nfsvers = 2; 571 mntvers = 1; 572 } 573 nfhret.stat = EACCES; /* Mark not yet successful */ 574 while (retrycnt > 0) { 575 saddr.sin_family = AF_INET; 576 saddr.sin_port = htons(PMAPPORT); 577 if ((tport = pmap_getport(&saddr, RPCPROG_NFS, 578 nfsvers, nfsproto)) == 0) { 579 if ((opflags & ISBGRND) == 0) 580 clnt_pcreateerror("NFS Portmap"); 581 } else { 582 saddr.sin_port = 0; 583 pertry.tv_sec = 10; 584 pertry.tv_usec = 0; 585 if (mnttcp_ok && nfsargsp->sotype == SOCK_STREAM) 586 clp = clnttcp_create(&saddr, RPCPROG_MNT, mntvers, 587 &so, 0, 0); 588 else 589 clp = clntudp_create(&saddr, RPCPROG_MNT, mntvers, 590 pertry, &so); 591 if (clp == NULL) { 592 if ((opflags & ISBGRND) == 0) 593 clnt_pcreateerror("Cannot MNT PRC"); 594 } else { 595 clp->cl_auth = authunix_create_default(); 596 try.tv_sec = 10; 597 try.tv_usec = 0; 598 if (nfsargsp->flags & NFSMNT_KERB) 599 nfhret.auth = RPCAUTH_KERB4; 600 else 601 nfhret.auth = RPCAUTH_UNIX; 602 nfhret.vers = mntvers; 603 clnt_stat = clnt_call(clp, RPCMNT_MOUNT, 604 xdr_dir, spec, xdr_fh, &nfhret, try); 605 if (clnt_stat != RPC_SUCCESS) { 606 if ((opflags & ISBGRND) == 0) 607 warnx("%s", clnt_sperror(clp, 608 "bad MNT RPC")); 609 } else { 610 auth_destroy(clp->cl_auth); 611 clnt_destroy(clp); 612 retrycnt = 0; 613 } 614 } 615 } 616 if (--retrycnt > 0) { 617 if (opflags & BGRND) { 618 opflags &= ~BGRND; 619 if (i = fork()) { 620 if (i == -1) 621 err(1, "nqnfs 2"); 622 exit(0); 623 } 624 (void) setsid(); 625 (void) close(STDIN_FILENO); 626 (void) close(STDOUT_FILENO); 627 (void) close(STDERR_FILENO); 628 (void) chdir("/"); 629 opflags |= ISBGRND; 630 } 631 sleep(60); 632 } 633 } 634 if (nfhret.stat) { 635 if (opflags & ISBGRND) 636 exit(1); 637 warnx("can't access %s: %s", spec, strerror(nfhret.stat)); 638 return (0); 639 } 640 saddr.sin_port = htons(tport); 641 #ifdef ISO 642 if (isoflag) { 643 nfsargsp->addr = (struct sockaddr *) &isoaddr; 644 nfsargsp->addrlen = sizeof (isoaddr); 645 } else 646 #endif /* ISO */ 647 { 648 nfsargsp->addr = (struct sockaddr *) &saddr; 649 nfsargsp->addrlen = sizeof (saddr); 650 } 651 nfsargsp->fh = nfhret.nfh; 652 nfsargsp->fhsize = nfhret.fhsize; 653 nfsargsp->hostname = nam; 654 return (1); 655 } 656 657 /* 658 * xdr routines for mount rpc's 659 */ 660 int 661 xdr_dir(xdrsp, dirp) 662 XDR *xdrsp; 663 char *dirp; 664 { 665 return (xdr_string(xdrsp, &dirp, RPCMNT_PATHLEN)); 666 } 667 668 int 669 xdr_fh(xdrsp, np) 670 XDR *xdrsp; 671 register struct nfhret *np; 672 { 673 register int i; 674 long auth, authcnt, authfnd = 0; 675 676 if (!xdr_u_long(xdrsp, &np->stat)) 677 return (0); 678 if (np->stat) 679 return (1); 680 switch (np->vers) { 681 case 1: 682 np->fhsize = NFSX_V2FH; 683 return (xdr_opaque(xdrsp, (caddr_t)np->nfh, NFSX_V2FH)); 684 case 3: 685 if (!xdr_long(xdrsp, &np->fhsize)) 686 return (0); 687 if (np->fhsize <= 0 || np->fhsize > NFSX_V3FHMAX) 688 return (0); 689 if (!xdr_opaque(xdrsp, (caddr_t)np->nfh, np->fhsize)) 690 return (0); 691 if (!xdr_long(xdrsp, &authcnt)) 692 return (0); 693 for (i = 0; i < authcnt; i++) { 694 if (!xdr_long(xdrsp, &auth)) 695 return (0); 696 if (auth == np->auth) 697 authfnd++; 698 } 699 /* 700 * Some servers, such as DEC's OSF/1 return a nil authenticator 701 * list to indicate RPCAUTH_UNIX. 702 */ 703 if (!authfnd && (authcnt > 0 || np->auth != RPCAUTH_UNIX)) 704 np->stat = EAUTH; 705 return (1); 706 }; 707 return (0); 708 } 709 710 __dead void 711 usage() 712 { 713 (void)fprintf(stderr, "usage: mount_nfs %s\n%s\n%s\n%s\n", 714 "[-bcdiKklMPqsT] [-a maxreadahead] [-D deadthresh]", 715 "\t[-g maxgroups] [-L leaseterm] [-m realm] [-o options] [-R retrycnt]", 716 "\t[-r readsize] [-t timeout] [-w writesize] [-x retrans]", 717 "\trhost:path node"); 718 exit(1); 719 } 720