mountd.c (281699) | mountd.c (282214) |
---|---|
1/* 2 * Copyright (c) 1989, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Herb Hasler and Rick Macklem at The University of Guelph. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 29 unchanged lines hidden (view full) --- 38 39#if 0 40#ifndef lint 41static char sccsid[] = "@(#)mountd.c 8.15 (Berkeley) 5/1/95"; 42#endif /*not lint*/ 43#endif 44 45#include <sys/cdefs.h> | 1/* 2 * Copyright (c) 1989, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Herb Hasler and Rick Macklem at The University of Guelph. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 29 unchanged lines hidden (view full) --- 38 39#if 0 40#ifndef lint 41static char sccsid[] = "@(#)mountd.c 8.15 (Berkeley) 5/1/95"; 42#endif /*not lint*/ 43#endif 44 45#include <sys/cdefs.h> |
46__FBSDID("$FreeBSD: head/usr.sbin/mountd/mountd.c 281699 2015-04-18 19:52:39Z sjg $"); | 46__FBSDID("$FreeBSD: head/usr.sbin/mountd/mountd.c 282214 2015-04-29 12:33:00Z trasz $"); |
47 48#include <sys/param.h> 49#include <sys/fcntl.h> 50#include <sys/linker.h> 51#include <sys/module.h> 52#include <sys/mount.h> 53#include <sys/stat.h> 54#include <sys/sysctl.h> --- 193 unchanged lines hidden (view full) --- 248static int sock_fdpos; 249static int suspend_nfsd = 0; 250 251int opt_flags; 252static int have_v6 = 1; 253 254int v4root_phase = 0; 255char v4root_dirpath[PATH_MAX + 1]; | 47 48#include <sys/param.h> 49#include <sys/fcntl.h> 50#include <sys/linker.h> 51#include <sys/module.h> 52#include <sys/mount.h> 53#include <sys/stat.h> 54#include <sys/sysctl.h> --- 193 unchanged lines hidden (view full) --- 248static int sock_fdpos; 249static int suspend_nfsd = 0; 250 251int opt_flags; 252static int have_v6 = 1; 253 254int v4root_phase = 0; 255char v4root_dirpath[PATH_MAX + 1]; |
256int run_v4server = 1; | |
257int has_publicfh = 0; 258 259struct pidfh *pfh = NULL; 260/* Bits for opt_flags above */ 261#define OP_MAPROOT 0x01 262#define OP_MAPALL 0x02 263/* 0x4 free */ 264#define OP_MASK 0x08 --- 42 unchanged lines hidden (view full) --- 307 } 308 309 s = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP); 310 if (s < 0) 311 have_v6 = 0; 312 else 313 close(s); 314 | 256int has_publicfh = 0; 257 258struct pidfh *pfh = NULL; 259/* Bits for opt_flags above */ 260#define OP_MAPROOT 0x01 261#define OP_MAPALL 0x02 262/* 0x4 free */ 263#define OP_MASK 0x08 --- 42 unchanged lines hidden (view full) --- 306 } 307 308 s = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP); 309 if (s < 0) 310 have_v6 = 0; 311 else 312 close(s); 313 |
315 while ((c = getopt(argc, argv, "2deh:lnop:rS")) != -1) | 314 while ((c = getopt(argc, argv, "2deh:lnp:rS")) != -1) |
316 switch (c) { 317 case '2': 318 force_v2 = 1; 319 break; 320 case 'e': 321 /* now a no-op, since this is the default */ 322 break; 323 case 'n': 324 resvport_only = 0; 325 break; 326 case 'r': 327 dir_only = 0; 328 break; 329 case 'd': 330 debug = debug ? 0 : 1; 331 break; 332 case 'l': 333 dolog = 1; 334 break; | 315 switch (c) { 316 case '2': 317 force_v2 = 1; 318 break; 319 case 'e': 320 /* now a no-op, since this is the default */ 321 break; 322 case 'n': 323 resvport_only = 0; 324 break; 325 case 'r': 326 dir_only = 0; 327 break; 328 case 'd': 329 debug = debug ? 0 : 1; 330 break; 331 case 'l': 332 dolog = 1; 333 break; |
335 case 'o': 336 run_v4server = 0; 337 break; | |
338 case 'p': 339 endptr = NULL; 340 svcport = (in_port_t)strtoul(optarg, &endptr, 10); 341 if (endptr == NULL || *endptr != '\0' || 342 svcport == 0 || svcport >= IPPORT_MAX) 343 usage(); 344 svcport_str = strdup(optarg); 345 break; --- 20 unchanged lines hidden (view full) --- 366 break; 367 case 'S': 368 suspend_nfsd = 1; 369 break; 370 default: 371 usage(); 372 }; 373 | 334 case 'p': 335 endptr = NULL; 336 svcport = (in_port_t)strtoul(optarg, &endptr, 10); 337 if (endptr == NULL || *endptr != '\0' || 338 svcport == 0 || svcport >= IPPORT_MAX) 339 usage(); 340 svcport_str = strdup(optarg); 341 break; --- 20 unchanged lines hidden (view full) --- 362 break; 363 case 'S': 364 suspend_nfsd = 1; 365 break; 366 default: 367 usage(); 368 }; 369 |
374 /* 375 * Unless the "-o" option was specified, try and run "nfsd". 376 * If "-o" was specified, try and run "nfsserver". 377 */ 378 if (run_v4server > 0) { 379 if (modfind("nfsd") < 0) { 380 /* Not present in kernel, try loading it */ 381 if (kldload("nfsd") < 0 || modfind("nfsd") < 0) 382 errx(1, "NFS server is not available"); 383 } 384 } else if (modfind("nfsserver") < 0) { | 370 if (modfind("nfsd") < 0) { |
385 /* Not present in kernel, try loading it */ | 371 /* Not present in kernel, try loading it */ |
386 if (kldload("nfsserver") < 0 || modfind("nfsserver") < 0) | 372 if (kldload("nfsd") < 0 || modfind("nfsd") < 0) |
387 errx(1, "NFS server is not available"); 388 } 389 390 argc -= optind; 391 argv += optind; 392 grphead = (struct grouplist *)NULL; 393 exphead = (struct exportlist *)NULL; 394 mlhead = (struct mountlist *)NULL; --- 1297 unchanged lines hidden (view full) --- 1692 } 1693 grphead = (struct grouplist *)NULL; 1694 1695 /* 1696 * and the old V4 root dir. 1697 */ 1698 bzero(&eargs, sizeof (eargs)); 1699 eargs.export.ex_flags = MNT_DELEXPORT; | 373 errx(1, "NFS server is not available"); 374 } 375 376 argc -= optind; 377 argv += optind; 378 grphead = (struct grouplist *)NULL; 379 exphead = (struct exportlist *)NULL; 380 mlhead = (struct mountlist *)NULL; --- 1297 unchanged lines hidden (view full) --- 1678 } 1679 grphead = (struct grouplist *)NULL; 1680 1681 /* 1682 * and the old V4 root dir. 1683 */ 1684 bzero(&eargs, sizeof (eargs)); 1685 eargs.export.ex_flags = MNT_DELEXPORT; |
1700 if (run_v4server > 0 && 1701 nfssvc(NFSSVC_V4ROOTEXPORT, (caddr_t)&eargs) < 0 && | 1686 if (nfssvc(NFSSVC_V4ROOTEXPORT, (caddr_t)&eargs) < 0 && |
1702 errno != ENOENT) 1703 syslog(LOG_ERR, "Can't delete exports for V4:"); 1704 1705 /* 1706 * and clear flag that notes if a public fh has been exported. 1707 */ 1708 has_publicfh = 0; 1709 --- 88 unchanged lines hidden (view full) --- 1798 if (done == 0) { 1799 syslog(LOG_ERR, "can't open any exports file"); 1800 exit(2); 1801 } 1802 1803 /* 1804 * If there was no public fh, clear any previous one set. 1805 */ | 1687 errno != ENOENT) 1688 syslog(LOG_ERR, "Can't delete exports for V4:"); 1689 1690 /* 1691 * and clear flag that notes if a public fh has been exported. 1692 */ 1693 has_publicfh = 0; 1694 --- 88 unchanged lines hidden (view full) --- 1783 if (done == 0) { 1784 syslog(LOG_ERR, "can't open any exports file"); 1785 exit(2); 1786 } 1787 1788 /* 1789 * If there was no public fh, clear any previous one set. 1790 */ |
1806 if (run_v4server > 0 && has_publicfh == 0) | 1791 if (has_publicfh == 0) |
1807 (void) nfssvc(NFSSVC_NOPUBLICFH, NULL); 1808 1809 /* Resume the nfsd. If they weren't suspended, this is harmless. */ 1810 (void)nfssvc(NFSSVC_RESUMENFSD, NULL); 1811} 1812 1813/* 1814 * Allocate an export list element --- 580 unchanged lines hidden (view full) --- 2395 * the kernel. 2396 */ 2397int 2398do_mount(struct exportlist *ep, struct grouplist *grp, int exflags, 2399 struct xucred *anoncrp, char *dirp, int dirplen, struct statfs *fsb) 2400{ 2401 struct statfs fsb1; 2402 struct addrinfo *ai; | 1792 (void) nfssvc(NFSSVC_NOPUBLICFH, NULL); 1793 1794 /* Resume the nfsd. If they weren't suspended, this is harmless. */ 1795 (void)nfssvc(NFSSVC_RESUMENFSD, NULL); 1796} 1797 1798/* 1799 * Allocate an export list element --- 580 unchanged lines hidden (view full) --- 2380 * the kernel. 2381 */ 2382int 2383do_mount(struct exportlist *ep, struct grouplist *grp, int exflags, 2384 struct xucred *anoncrp, char *dirp, int dirplen, struct statfs *fsb) 2385{ 2386 struct statfs fsb1; 2387 struct addrinfo *ai; |
2403 struct export_args ea, *eap; | 2388 struct export_args *eap; |
2404 char errmsg[255]; 2405 char *cp; 2406 int done; 2407 char savedc; 2408 struct iovec *iov; 2409 int i, iovlen; 2410 int ret; 2411 struct nfsex_args nfsea; 2412 | 2389 char errmsg[255]; 2390 char *cp; 2391 int done; 2392 char savedc; 2393 struct iovec *iov; 2394 int i, iovlen; 2395 int ret; 2396 struct nfsex_args nfsea; 2397 |
2413 if (run_v4server > 0) 2414 eap = &nfsea.export; 2415 else 2416 eap = &ea; | 2398 eap = &nfsea.export; |
2417 2418 cp = NULL; 2419 savedc = '\0'; 2420 iov = NULL; 2421 iovlen = 0; 2422 ret = 0; 2423 2424 bzero(eap, sizeof (struct export_args)); --- 63 unchanged lines hidden (view full) --- 2488 goto error_exit; 2489 }; 2490 2491 /* 2492 * For V4:, use the nfssvc() syscall, instead of mount(). 2493 */ 2494 if (v4root_phase == 2) { 2495 nfsea.fspec = v4root_dirpath; | 2399 2400 cp = NULL; 2401 savedc = '\0'; 2402 iov = NULL; 2403 iovlen = 0; 2404 ret = 0; 2405 2406 bzero(eap, sizeof (struct export_args)); --- 63 unchanged lines hidden (view full) --- 2470 goto error_exit; 2471 }; 2472 2473 /* 2474 * For V4:, use the nfssvc() syscall, instead of mount(). 2475 */ 2476 if (v4root_phase == 2) { 2477 nfsea.fspec = v4root_dirpath; |
2496 if (run_v4server > 0 && 2497 nfssvc(NFSSVC_V4ROOTEXPORT, (caddr_t)&nfsea) < 0) { | 2478 if (nfssvc(NFSSVC_V4ROOTEXPORT, (caddr_t)&nfsea) < 0) { |
2498 syslog(LOG_ERR, "Exporting V4: failed"); 2499 return (2); 2500 } 2501 } else { 2502 /* 2503 * XXX: 2504 * Maybe I should just use the fsb->f_mntonname path 2505 * instead of looping back up the dirp to the mount --- 72 unchanged lines hidden (view full) --- 2578 } 2579 } 2580 2581 /* 2582 * For the experimental server: 2583 * If this is the public directory, get the file handle 2584 * and load it into the kernel via the nfssvc() syscall. 2585 */ | 2479 syslog(LOG_ERR, "Exporting V4: failed"); 2480 return (2); 2481 } 2482 } else { 2483 /* 2484 * XXX: 2485 * Maybe I should just use the fsb->f_mntonname path 2486 * instead of looping back up the dirp to the mount --- 72 unchanged lines hidden (view full) --- 2559 } 2560 } 2561 2562 /* 2563 * For the experimental server: 2564 * If this is the public directory, get the file handle 2565 * and load it into the kernel via the nfssvc() syscall. 2566 */ |
2586 if (run_v4server > 0 && (exflags & MNT_EXPUBLIC) != 0) { | 2567 if ((exflags & MNT_EXPUBLIC) != 0) { |
2587 fhandle_t fh; 2588 char *public_name; 2589 2590 if (eap->ex_indexfile != NULL) 2591 public_name = eap->ex_indexfile; 2592 else 2593 public_name = dirp; 2594 if (getfh(public_name, &fh) < 0) --- 641 unchanged lines hidden --- | 2568 fhandle_t fh; 2569 char *public_name; 2570 2571 if (eap->ex_indexfile != NULL) 2572 public_name = eap->ex_indexfile; 2573 else 2574 public_name = dirp; 2575 if (getfh(public_name, &fh) < 0) --- 641 unchanged lines hidden --- |