2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (c) 1989, 1993
5 * The Regents of the University of California. All rights reserved.
7 * This code is derived from software contributed to Berkeley by
8 * Herb Hasler and Rick Macklem at The University of Guelph.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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.
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
36 static const char copyright[] =
37 "@(#) Copyright (c) 1989, 1993\n\
38 The Regents of the University of California. All rights reserved.\n";
43 static char sccsid[] = "@(#)mountd.c 8.15 (Berkeley) 5/1/95";
47 #include <sys/cdefs.h>
48 __FBSDID("$FreeBSD$");
50 #include <sys/param.h>
51 #include <sys/fcntl.h>
52 #include <sys/fnv_hash.h>
53 #include <sys/linker.h>
54 #include <sys/module.h>
55 #include <sys/mount.h>
56 #include <sys/queue.h>
58 #include <sys/sysctl.h>
59 #include <sys/syslog.h>
62 #include <rpc/rpc_com.h>
63 #include <rpc/pmap_clnt.h>
64 #include <rpc/pmap_prot.h>
65 #include <rpcsvc/mount.h>
66 #include <nfs/nfsproto.h>
67 #include <nfs/nfssvc.h>
68 #include <nfsserver/nfs.h>
70 #include <fs/nfs/nfsport.h>
72 #include <arpa/inet.h>
87 #include "pathnames.h"
95 * Structures for keeping the mount list and export list
98 char ml_host[MNTNAMLEN+1];
99 char ml_dirp[MNTPATHLEN+1];
101 SLIST_ENTRY(mountlist) next;
105 struct dirlist *dp_left;
106 struct dirlist *dp_right;
108 struct hostlist *dp_hosts; /* List of hosts this dir exported to */
112 #define DP_DEFSET 0x1
113 #define DP_HOSTSET 0x2
116 * maproot/mapall credentials.
121 gid_t cr_groups[NGROUPS_MAX + 1];
125 struct dirlist *ex_dirl;
126 struct dirlist *ex_defdir;
127 struct grouplist *ex_grphead;
132 struct expcred ex_defanon;
133 uint64_t ex_defexflags;
134 int ex_numsecflavors;
135 int ex_secflavors[MAXSECFLAVORS];
136 int ex_defnumsecflavors;
137 int ex_defsecflavors[MAXSECFLAVORS];
139 SLIST_ENTRY(exportlist) entries;
142 #define EX_LINKED 0x1
144 #define EX_DEFSET 0x4
145 #define EX_PUBLICFH 0x8
147 SLIST_HEAD(exportlisthead, exportlist);
150 struct sockaddr_storage nt_net;
151 struct sockaddr_storage nt_mask;
156 struct addrinfo *gt_addrinfo;
157 struct netmsk gt_net;
162 union grouptypes gr_ptr;
163 struct grouplist *gr_next;
164 struct expcred gr_anon;
167 int gr_numsecflavors;
168 int gr_secflavors[MAXSECFLAVORS];
174 #define GT_DEFAULT 0x3
175 #define GT_IGNORE 0x5
181 int ht_flag; /* Uses DP_xx bits */
182 struct grouplist *ht_grp;
183 struct hostlist *ht_next;
190 int fhr_numsecflavors;
194 #define GETPORT_MAXTRY 20 /* Max tries to get a port # */
197 * How long to delay a reload of exports when there are RPC request(s)
198 * to process, in usec. Must be less than 1second.
200 #define RELOADDELAY 250000
203 static char *add_expdir(struct dirlist **, char *, int);
204 static void add_dlist(struct dirlist **, struct dirlist *,
205 struct grouplist *, int, struct exportlist *,
206 struct expcred *, uint64_t);
207 static void add_mlist(char *, char *);
208 static int check_dirpath(char *);
209 static int check_options(struct dirlist *);
210 static int checkmask(struct sockaddr *sa);
211 static int chk_host(struct dirlist *, struct sockaddr *, int *, int *,
213 static char *strsep_quote(char **stringp, const char *delim);
214 static int create_service(struct netconfig *nconf);
215 static void complete_service(struct netconfig *nconf, char *port_str);
216 static void clearout_service(void);
217 static void del_mlist(char *hostp, char *dirp);
218 static struct dirlist *dirp_search(struct dirlist *, char *);
219 static int do_export_mount(struct exportlist *, struct statfs *);
220 static int do_mount(struct exportlist *, struct grouplist *, uint64_t,
221 struct expcred *, char *, int, struct statfs *, int, int *);
222 static int do_opt(char **, char **, struct exportlist *,
223 struct grouplist *, int *, uint64_t *, struct expcred *);
224 static struct exportlist *ex_search(fsid_t *, struct exportlisthead *);
225 static struct exportlist *get_exp(void);
226 static void free_dir(struct dirlist *);
227 static void free_exp(struct exportlist *);
228 static void free_grp(struct grouplist *);
229 static void free_host(struct hostlist *);
230 static void free_v4rootexp(void);
231 static void get_exportlist_one(int);
232 static void get_exportlist(int);
233 static void insert_exports(struct exportlist *, struct exportlisthead *);
234 static void free_exports(struct exportlisthead *);
235 static void read_exportfile(int);
236 static int compare_nmount_exportlist(struct iovec *, int, char *);
237 static int compare_export(struct exportlist *, struct exportlist *);
238 static int compare_cred(struct expcred *, struct expcred *);
239 static int compare_secflavor(int *, int *, int);
240 static void delete_export(struct iovec *, int, struct statfs *, char *);
241 static int get_host(char *, struct grouplist *, struct grouplist *);
242 static struct hostlist *get_ht(void);
243 static int get_line(void);
244 static void get_mountlist(void);
245 static int get_net(char *, struct netmsk *, int);
246 static void getexp_err(struct exportlist *, struct grouplist *, const char *);
247 static struct grouplist *get_grp(void);
248 static void hang_dirp(struct dirlist *, struct grouplist *,
249 struct exportlist *, int, struct expcred *, uint64_t);
250 static void huphandler(int sig);
251 static int makemask(struct sockaddr_storage *ssp, int bitlen);
252 static void mntsrv(struct svc_req *, SVCXPRT *);
253 static void nextfield(char **, char **);
254 static void out_of_mem(void);
255 static void parsecred(char *, struct expcred *);
256 static int parsesec(char *, struct exportlist *);
257 static int put_exlist(struct dirlist *, XDR *, struct dirlist *,
259 static void *sa_rawaddr(struct sockaddr *sa, int *nbytes);
260 static int sacmp(struct sockaddr *sa1, struct sockaddr *sa2,
261 struct sockaddr *samask);
262 static int scan_tree(struct dirlist *, struct sockaddr *);
263 static void usage(void);
264 static int xdr_dir(XDR *, char *);
265 static int xdr_explist(XDR *, caddr_t);
266 static int xdr_explist_brief(XDR *, caddr_t);
267 static int xdr_explist_common(XDR *, caddr_t, int);
268 static int xdr_fhs(XDR *, caddr_t);
269 static int xdr_mlist(XDR *, caddr_t);
270 static void terminate(int);
271 static void cp_cred(struct expcred *, struct expcred *);
273 #define EXPHASH(f) (fnv_32_buf((f), sizeof(fsid_t), 0) % exphashsize)
274 static struct exportlisthead *exphead = NULL;
275 static struct exportlisthead *oldexphead = NULL;
276 static int exphashsize = 0;
277 static SLIST_HEAD(, mountlist) mlhead = SLIST_HEAD_INITIALIZER(&mlhead);
278 static char *exnames_default[2] = { _PATH_EXPORTS, NULL };
279 static char **exnames;
280 static char **hosts = NULL;
281 static int force_v2 = 0;
282 static int resvport_only = 1;
283 static int nhosts = 0;
284 static int dir_only = 1;
285 static int dolog = 0;
286 static int got_sighup = 0;
287 static int xcreated = 0;
289 static char *svcport_str = NULL;
290 static int mallocd_svcport = 0;
292 static int sock_fdcnt;
293 static int sock_fdpos;
294 static int suspend_nfsd = 0;
296 static int opt_flags;
297 static int have_v6 = 1;
299 static int v4root_phase = 0;
300 static char v4root_dirpath[PATH_MAX + 1];
301 static struct exportlist *v4root_ep = NULL;
302 static int has_publicfh = 0;
303 static int has_set_publicfh = 0;
305 static struct pidfh *pfh = NULL;
306 /* Bits for opt_flags above */
307 #define OP_MAPROOT 0x01
308 #define OP_MAPALL 0x02
312 #define OP_ALLDIRS 0x40
313 #define OP_HAVEMASK 0x80 /* A mask was specified or inferred. */
314 #define OP_QUIET 0x100
315 #define OP_MASKLEN 0x200
319 static int debug = 1;
320 static void SYSLOG(int, const char *, ...) __printflike(2, 3);
321 #define syslog SYSLOG
323 static int debug = 0;
327 * The LOGDEBUG() syslog() calls are always compiled into the daemon.
328 * To enable them, create a file at _PATH_MOUNTDDEBUG. This file can be empty.
329 * To disable the logging, just delete the file at _PATH_MOUNTDDEBUG.
331 static int logdebug = 0;
332 #define LOGDEBUG(format, ...) \
333 (logdebug ? syslog(LOG_DEBUG, format, ## __VA_ARGS__) : 0)
336 * Similar to strsep(), but it allows for quoted strings
337 * and escaped characters.
339 * It returns the string (or NULL, if *stringp is NULL),
340 * which is a de-quoted version of the string if necessary.
342 * It modifies *stringp in place.
345 strsep_quote(char **stringp, const char *delim)
347 char *srcptr, *dstptr, *retval;
350 if (stringp == NULL || *stringp == NULL)
353 srcptr = dstptr = retval = *stringp;
357 * We're looking for several edge cases here.
358 * First: if we're in quote state (quot != 0),
359 * then we ignore the delim characters, but otherwise
360 * process as normal, unless it is the quote character.
361 * Second: if the current character is a backslash,
362 * we take the next character as-is, without checking
363 * for delim, quote, or backslash. Exception: if the
364 * next character is a NUL, that's the end of the string.
365 * Third: if the character is a quote character, we toggle
367 * Otherwise: check the current character for NUL, or
368 * being in delim, and end the string if either is true.
370 if (*srcptr == '\\') {
373 * The edge case here is if the next character
374 * is NUL, we want to stop processing. But if
375 * it's not NUL, then we simply want to copy it.
378 *dstptr++ = *srcptr++;
382 if (quot == 0 && (*srcptr == '\'' || *srcptr == '"')) {
386 if (quot && *srcptr == quot) {
387 /* End of the quoted part */
392 if (!quot && strchr(delim, *srcptr))
394 *dstptr++ = *srcptr++;
397 *stringp = (*srcptr == '\0') ? NULL : srcptr + 1;
398 *dstptr = 0; /* Terminate the string */
403 * Mountd server for NFS mount protocol as described in:
404 * NFS: Network File System Protocol Specification, RFC1094, Appendix A
405 * The optional arguments are the exports file name
406 * default: _PATH_EXPORTS
407 * and "-n" to allow nonroot mount.
410 main(int argc, char **argv)
413 struct netconfig *nconf;
414 char *endptr, **hosts_bak;
419 int maxrec = RPC_MAXDATASIZE;
420 int attempt_cnt, port_len, port_pos, ret;
422 uint64_t curtime, nexttime;
425 sigset_t sighup_mask;
427 /* Check that another mountd isn't already running. */
428 pfh = pidfile_open(_PATH_MOUNTDPID, 0600, &otherpid);
431 errx(1, "mountd already running, pid: %d.", otherpid);
432 warn("cannot open or create pidfile");
435 s = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
441 while ((c = getopt(argc, argv, "2deh:lnp:rS")) != -1)
447 /* now a no-op, since this is the default */
456 debug = debug ? 0 : 1;
463 svcport = (in_port_t)strtoul(optarg, &endptr, 10);
464 if (endptr == NULL || *endptr != '\0' ||
465 svcport == 0 || svcport >= IPPORT_MAX)
467 svcport_str = strdup(optarg);
472 hosts_bak = realloc(hosts, nhosts * sizeof(char *));
473 if (hosts_bak == NULL) {
475 for (k = 0; k < nhosts; k++)
482 hosts[nhosts - 1] = strdup(optarg);
483 if (hosts[nhosts - 1] == NULL) {
484 for (k = 0; k < (nhosts - 1); k++)
497 if (modfind("nfsd") < 0) {
498 /* Not present in kernel, try loading it */
499 if (kldload("nfsd") < 0 || modfind("nfsd") < 0)
500 errx(1, "NFS server is not available");
508 exnames = exnames_default;
509 openlog("mountd", LOG_PID, LOG_DAEMON);
511 warnx("getting export list");
514 warnx("getting mount list");
520 signal(SIGINT, SIG_IGN);
521 signal(SIGQUIT, SIG_IGN);
523 signal(SIGHUP, huphandler);
524 signal(SIGTERM, terminate);
525 signal(SIGPIPE, SIG_IGN);
529 rpcb_unset(MOUNTPROG, MOUNTVERS, NULL);
530 rpcb_unset(MOUNTPROG, MOUNTVERS3, NULL);
531 rpc_control(RPC_SVC_CONNMAXREC_SET, &maxrec);
533 if (!resvport_only) {
534 if (sysctlbyname("vfs.nfsd.nfs_privport", NULL, NULL,
535 &resvport_only, sizeof(resvport_only)) != 0 &&
537 syslog(LOG_ERR, "sysctl: %m");
543 * If no hosts were specified, add a wildcard entry to bind to
544 * INADDR_ANY. Otherwise make sure 127.0.0.1 and ::1 are added to the
548 hosts = malloc(sizeof(char *));
556 hosts_bak = realloc(hosts, (nhosts + 2) *
558 if (hosts_bak == NULL) {
559 for (k = 0; k < nhosts; k++)
566 hosts[nhosts - 2] = "::1";
568 hosts_bak = realloc(hosts, (nhosts + 1) * sizeof(char *));
569 if (hosts_bak == NULL) {
570 for (k = 0; k < nhosts; k++)
580 hosts[nhosts - 1] = "127.0.0.1";
588 nc_handle = setnetconfig();
589 while ((nconf = getnetconfig(nc_handle))) {
590 if (nconf->nc_flag & NC_VISIBLE) {
591 if (have_v6 == 0 && strcmp(nconf->nc_protofmly,
595 ret = create_service(nconf);
597 /* Ignore this call */
601 * Failed to bind port, so close off
602 * all sockets created and try again
603 * if the port# was dynamically
604 * assigned via bind(2).
607 if (mallocd_svcport != 0 &&
608 attempt_cnt < GETPORT_MAXTRY) {
615 "bindresvport_sa: %m");
619 /* Start over at the first service. */
623 nc_handle = setnetconfig();
625 } else if (mallocd_svcport != 0 &&
626 attempt_cnt == GETPORT_MAXTRY) {
628 * For the last attempt, allow
629 * different port #s for each nconf
630 * by saving the svcport_str and
631 * setting it back to NULL.
633 port_list = realloc(port_list,
634 (port_len + 1) * sizeof(char *));
635 if (port_list == NULL)
637 port_list[port_len++] = svcport_str;
646 * Successfully bound the ports, so call complete_service() to
647 * do the rest of the setup on the service(s).
651 nc_handle = setnetconfig();
652 while ((nconf = getnetconfig(nc_handle))) {
653 if (nconf->nc_flag & NC_VISIBLE) {
654 if (have_v6 == 0 && strcmp(nconf->nc_protofmly,
657 } else if (port_list != NULL) {
658 if (port_pos >= port_len) {
659 syslog(LOG_ERR, "too many port#s");
662 complete_service(nconf, port_list[port_pos++]);
664 complete_service(nconf, svcport_str);
667 endnetconfig(nc_handle);
669 if (port_list != NULL) {
670 for (port_pos = 0; port_pos < port_len; port_pos++)
671 free(port_list[port_pos]);
676 syslog(LOG_ERR, "could not create any services");
680 /* Expand svc_run() here so that we can call get_exportlist(). */
681 curtime = nexttime = 0;
682 sigemptyset(&sighup_mask);
683 sigaddset(&sighup_mask, SIGHUP);
685 clock_gettime(CLOCK_MONOTONIC, &tp);
687 curtime = curtime * 1000000 + tp.tv_nsec / 1000;
688 sigprocmask(SIG_BLOCK, &sighup_mask, NULL);
689 if (got_sighup && curtime >= nexttime) {
691 sigprocmask(SIG_UNBLOCK, &sighup_mask, NULL);
693 clock_gettime(CLOCK_MONOTONIC, &tp);
694 nexttime = tp.tv_sec;
695 nexttime = nexttime * 1000000 + tp.tv_nsec / 1000 +
698 sigprocmask(SIG_UNBLOCK, &sighup_mask, NULL);
701 * If a reload is pending, poll for received request(s),
702 * otherwise set a RELOADDELAY timeout, since a SIGHUP
703 * could be processed between the got_sighup test and
704 * the select() system call.
710 tv.tv_usec = RELOADDELAY;
712 switch (select(svc_maxfd + 1, &readfds, NULL, NULL, &tv)) {
714 if (errno == EINTR) {
715 /* Allow a reload now. */
719 syslog(LOG_ERR, "mountd died: select: %m");
722 /* Allow a reload now. */
726 svc_getreqset(&readfds);
732 * This routine creates and binds sockets on the appropriate
733 * addresses. It gets called one time for each transport.
734 * It returns 0 upon success, 1 for ingore the call and -1 to indicate
735 * bind failed with EADDRINUSE.
736 * Any file descriptors that have been created are stored in sock_fd and
737 * the total count of them is maintained in sock_fdcnt.
740 create_service(struct netconfig *nconf)
742 struct addrinfo hints, *res = NULL;
743 struct sockaddr_in *sin;
744 struct sockaddr_in6 *sin6;
745 struct __rpc_sockinfo si;
751 u_int32_t host_addr[4]; /* IPv4 or IPv6 */
754 if ((nconf->nc_semantics != NC_TPI_CLTS) &&
755 (nconf->nc_semantics != NC_TPI_COTS) &&
756 (nconf->nc_semantics != NC_TPI_COTS_ORD))
757 return (1); /* not my type */
760 * XXX - using RPC library internal functions.
762 if (!__rpc_nconf2sockinfo(nconf, &si)) {
763 syslog(LOG_ERR, "cannot get information for %s",
768 /* Get mountd's address on this transport */
769 memset(&hints, 0, sizeof hints);
770 hints.ai_family = si.si_af;
771 hints.ai_socktype = si.si_socktype;
772 hints.ai_protocol = si.si_proto;
775 * Bind to specific IPs if asked to
778 while (nhostsbak > 0) {
780 sock_fd = realloc(sock_fd, (sock_fdcnt + 1) * sizeof(int));
783 sock_fd[sock_fdcnt++] = -1; /* Set invalid for now. */
786 hints.ai_flags = AI_PASSIVE;
789 * XXX - using RPC library internal functions.
791 if ((fd = __rpc_nconf2fd(nconf)) < 0) {
793 if (errno == EAFNOSUPPORT &&
794 nconf->nc_semantics != NC_TPI_CLTS)
797 syslog(non_fatal ? LOG_DEBUG : LOG_ERR,
798 "cannot create socket for %s", nconf->nc_netid);
804 switch (hints.ai_family) {
806 if (inet_pton(AF_INET, hosts[nhostsbak],
808 hints.ai_flags |= AI_NUMERICHOST;
811 * Skip if we have an AF_INET6 address.
813 if (inet_pton(AF_INET6, hosts[nhostsbak],
821 if (inet_pton(AF_INET6, hosts[nhostsbak],
823 hints.ai_flags |= AI_NUMERICHOST;
826 * Skip if we have an AF_INET address.
828 if (inet_pton(AF_INET, hosts[nhostsbak],
836 * We're doing host-based access checks here, so don't
837 * allow v4-in-v6 to confuse things. The kernel will
838 * disable it by default on NFS sockets too.
840 if (setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &one,
843 "can't disable v4-in-v6 on IPv6 socket");
852 * If no hosts were specified, just bind to INADDR_ANY
854 if (strcmp("*", hosts[nhostsbak]) == 0) {
855 if (svcport_str == NULL) {
856 res = malloc(sizeof(struct addrinfo));
860 res->ai_flags = hints.ai_flags;
861 res->ai_family = hints.ai_family;
862 res->ai_protocol = hints.ai_protocol;
863 switch (res->ai_family) {
865 sin = malloc(sizeof(struct sockaddr_in));
868 sin->sin_family = AF_INET;
869 sin->sin_port = htons(0);
870 sin->sin_addr.s_addr = htonl(INADDR_ANY);
871 res->ai_addr = (struct sockaddr*) sin;
872 res->ai_addrlen = (socklen_t)
873 sizeof(struct sockaddr_in);
876 sin6 = malloc(sizeof(struct sockaddr_in6));
879 sin6->sin6_family = AF_INET6;
880 sin6->sin6_port = htons(0);
881 sin6->sin6_addr = in6addr_any;
882 res->ai_addr = (struct sockaddr*) sin6;
883 res->ai_addrlen = (socklen_t)
884 sizeof(struct sockaddr_in6);
887 syslog(LOG_ERR, "bad addr fam %d",
892 if ((aicode = getaddrinfo(NULL, svcport_str,
893 &hints, &res)) != 0) {
895 "cannot get local address for %s: %s",
897 gai_strerror(aicode));
903 if ((aicode = getaddrinfo(hosts[nhostsbak], svcport_str,
904 &hints, &res)) != 0) {
906 "cannot get local address for %s: %s",
907 nconf->nc_netid, gai_strerror(aicode));
914 sock_fd[sock_fdcnt - 1] = fd;
916 /* Now, attempt the bind. */
917 r = bindresvport_sa(fd, res->ai_addr);
919 if (errno == EADDRINUSE && mallocd_svcport != 0) {
920 if (mallocd_res != 0) {
927 syslog(LOG_ERR, "bindresvport_sa: %m");
931 if (svcport_str == NULL) {
932 svcport_str = malloc(NI_MAXSERV * sizeof(char));
933 if (svcport_str == NULL)
937 if (getnameinfo(res->ai_addr,
938 res->ai_addr->sa_len, NULL, NI_MAXHOST,
939 svcport_str, NI_MAXSERV * sizeof(char),
940 NI_NUMERICHOST | NI_NUMERICSERV))
941 errx(1, "Cannot get port number");
943 if (mallocd_res != 0) {
954 * Called after all the create_service() calls have succeeded, to complete
955 * the setup and registration.
958 complete_service(struct netconfig *nconf, char *port_str)
960 struct addrinfo hints, *res = NULL;
961 struct __rpc_sockinfo si;
962 struct netbuf servaddr;
963 SVCXPRT *transp = NULL;
964 int aicode, fd, nhostsbak;
967 if ((nconf->nc_semantics != NC_TPI_CLTS) &&
968 (nconf->nc_semantics != NC_TPI_COTS) &&
969 (nconf->nc_semantics != NC_TPI_COTS_ORD))
970 return; /* not my type */
973 * XXX - using RPC library internal functions.
975 if (!__rpc_nconf2sockinfo(nconf, &si)) {
976 syslog(LOG_ERR, "cannot get information for %s",
982 while (nhostsbak > 0) {
984 if (sock_fdpos >= sock_fdcnt) {
985 /* Should never happen. */
986 syslog(LOG_ERR, "Ran out of socket fd's");
989 fd = sock_fd[sock_fdpos++];
994 * Using -1 tells listen(2) to use
995 * kern.ipc.soacceptqueue for the backlog.
997 if (nconf->nc_semantics != NC_TPI_CLTS)
1000 if (nconf->nc_semantics == NC_TPI_CLTS )
1001 transp = svc_dg_create(fd, 0, 0);
1003 transp = svc_vc_create(fd, RPC_MAXDATASIZE,
1006 if (transp != (SVCXPRT *) NULL) {
1007 if (!svc_reg(transp, MOUNTPROG, MOUNTVERS, mntsrv,
1010 "can't register %s MOUNTVERS service",
1013 if (!svc_reg(transp, MOUNTPROG, MOUNTVERS3,
1016 "can't register %s MOUNTVERS3 service",
1020 syslog(LOG_WARNING, "can't create %s services",
1023 if (registered == 0) {
1025 memset(&hints, 0, sizeof hints);
1026 hints.ai_flags = AI_PASSIVE;
1027 hints.ai_family = si.si_af;
1028 hints.ai_socktype = si.si_socktype;
1029 hints.ai_protocol = si.si_proto;
1031 if ((aicode = getaddrinfo(NULL, port_str, &hints,
1033 syslog(LOG_ERR, "cannot get local address: %s",
1034 gai_strerror(aicode));
1038 servaddr.buf = malloc(res->ai_addrlen);
1039 memcpy(servaddr.buf, res->ai_addr, res->ai_addrlen);
1040 servaddr.len = res->ai_addrlen;
1042 rpcb_set(MOUNTPROG, MOUNTVERS, nconf, &servaddr);
1043 rpcb_set(MOUNTPROG, MOUNTVERS3, nconf, &servaddr);
1052 * Clear out sockets after a failure to bind one of them, so that the
1053 * cycle of socket creation/binding can start anew.
1056 clearout_service(void)
1060 for (i = 0; i < sock_fdcnt; i++) {
1061 if (sock_fd[i] >= 0) {
1062 shutdown(sock_fd[i], SHUT_RDWR);
1072 "usage: mountd [-2] [-d] [-e] [-l] [-n] [-p <port>] [-r] "
1073 "[-S] [-h <bindip>] [export_file ...]\n");
1078 * The mount rpc service
1081 mntsrv(struct svc_req *rqstp, SVCXPRT *transp)
1083 struct exportlist *ep;
1085 struct fhreturn fhr;
1088 char host[NI_MAXHOST], numerichost[NI_MAXHOST];
1089 int lookup_failed = 1;
1090 struct sockaddr *saddr;
1092 char rpcpath[MNTPATHLEN + 1], dirpath[MAXPATHLEN];
1093 int bad = 0, defset, hostset;
1094 sigset_t sighup_mask;
1095 int numsecflavors, *secflavorsp;
1097 sigemptyset(&sighup_mask);
1098 sigaddset(&sighup_mask, SIGHUP);
1099 saddr = svc_getrpccaller(transp)->buf;
1100 switch (saddr->sa_family) {
1102 sport = ntohs(((struct sockaddr_in6 *)saddr)->sin6_port);
1105 sport = ntohs(((struct sockaddr_in *)saddr)->sin_port);
1108 syslog(LOG_ERR, "request from unknown address family");
1111 switch (rqstp->rq_proc) {
1113 case MOUNTPROC_UMNT:
1114 case MOUNTPROC_UMNTALL:
1115 lookup_failed = getnameinfo(saddr, saddr->sa_len, host,
1116 sizeof host, NULL, 0, 0);
1118 getnameinfo(saddr, saddr->sa_len, numerichost,
1119 sizeof numerichost, NULL, 0, NI_NUMERICHOST);
1120 switch (rqstp->rq_proc) {
1122 if (!svc_sendreply(transp, (xdrproc_t)xdr_void, NULL))
1123 syslog(LOG_ERR, "can't send reply");
1126 if (sport >= IPPORT_RESERVED && resvport_only) {
1128 "mount request from %s from unprivileged port",
1130 svcerr_weakauth(transp);
1133 if (!svc_getargs(transp, (xdrproc_t)xdr_dir, rpcpath)) {
1134 syslog(LOG_NOTICE, "undecodable mount request from %s",
1136 svcerr_decode(transp);
1141 * Get the real pathname and make sure it is a directory
1142 * or a regular file if the -r option was specified
1145 if (realpath(rpcpath, dirpath) == NULL ||
1146 stat(dirpath, &stb) < 0 ||
1147 statfs(dirpath, &fsb) < 0) {
1148 chdir("/"); /* Just in case realpath doesn't */
1150 "mount request from %s for non existent path %s",
1151 numerichost, dirpath);
1153 warnx("stat failed on %s", dirpath);
1154 bad = ENOENT; /* We will send error reply later */
1157 !S_ISDIR(stb.st_mode) &&
1158 (dir_only || !S_ISREG(stb.st_mode))) {
1160 "mount request from %s for non-directory path %s",
1161 numerichost, dirpath);
1163 warnx("mounting non-directory %s", dirpath);
1164 bad = ENOTDIR; /* We will send error reply later */
1167 /* Check in the exports list */
1168 sigprocmask(SIG_BLOCK, &sighup_mask, NULL);
1172 ep = ex_search(&fsb.f_fsid, exphead);
1173 hostset = defset = 0;
1174 if (ep && (chk_host(ep->ex_defdir, saddr, &defset, &hostset,
1175 &numsecflavors, &secflavorsp) ||
1176 ((dp = dirp_search(ep->ex_dirl, dirpath)) &&
1177 chk_host(dp, saddr, &defset, &hostset, &numsecflavors,
1179 (defset && scan_tree(ep->ex_defdir, saddr) == 0 &&
1180 scan_tree(ep->ex_dirl, saddr) == 0))) {
1182 if (!svc_sendreply(transp, (xdrproc_t)xdr_long,
1184 syslog(LOG_ERR, "can't send reply");
1185 sigprocmask(SIG_UNBLOCK, &sighup_mask, NULL);
1188 if (hostset & DP_HOSTSET) {
1189 fhr.fhr_flag = hostset;
1190 fhr.fhr_numsecflavors = numsecflavors;
1191 fhr.fhr_secflavors = secflavorsp;
1193 fhr.fhr_flag = defset;
1194 fhr.fhr_numsecflavors = ep->ex_defnumsecflavors;
1195 fhr.fhr_secflavors = ep->ex_defsecflavors;
1197 fhr.fhr_vers = rqstp->rq_vers;
1198 /* Get the file handle */
1199 memset(&fhr.fhr_fh, 0, sizeof(nfsfh_t));
1200 if (getfh(dirpath, (fhandle_t *)&fhr.fhr_fh) < 0) {
1202 syslog(LOG_ERR, "can't get fh for %s", dirpath);
1203 if (!svc_sendreply(transp, (xdrproc_t)xdr_long,
1205 syslog(LOG_ERR, "can't send reply");
1206 sigprocmask(SIG_UNBLOCK, &sighup_mask, NULL);
1209 if (!svc_sendreply(transp, (xdrproc_t)xdr_fhs,
1211 syslog(LOG_ERR, "can't send reply");
1213 add_mlist(host, dirpath);
1215 add_mlist(numerichost, dirpath);
1217 warnx("mount successful");
1220 "mount request succeeded from %s for %s",
1221 numerichost, dirpath);
1226 "mount request denied from %s for %s",
1227 numerichost, dirpath);
1230 if (bad && !svc_sendreply(transp, (xdrproc_t)xdr_long,
1232 syslog(LOG_ERR, "can't send reply");
1233 sigprocmask(SIG_UNBLOCK, &sighup_mask, NULL);
1235 case MOUNTPROC_DUMP:
1236 if (!svc_sendreply(transp, (xdrproc_t)xdr_mlist, (caddr_t)NULL))
1237 syslog(LOG_ERR, "can't send reply");
1240 "dump request succeeded from %s",
1243 case MOUNTPROC_UMNT:
1244 if (sport >= IPPORT_RESERVED && resvport_only) {
1246 "umount request from %s from unprivileged port",
1248 svcerr_weakauth(transp);
1251 if (!svc_getargs(transp, (xdrproc_t)xdr_dir, rpcpath)) {
1252 syslog(LOG_NOTICE, "undecodable umount request from %s",
1254 svcerr_decode(transp);
1257 if (realpath(rpcpath, dirpath) == NULL) {
1258 syslog(LOG_NOTICE, "umount request from %s "
1259 "for non existent path %s",
1260 numerichost, dirpath);
1262 if (!svc_sendreply(transp, (xdrproc_t)xdr_void, (caddr_t)NULL))
1263 syslog(LOG_ERR, "can't send reply");
1265 del_mlist(host, dirpath);
1266 del_mlist(numerichost, dirpath);
1269 "umount request succeeded from %s for %s",
1270 numerichost, dirpath);
1272 case MOUNTPROC_UMNTALL:
1273 if (sport >= IPPORT_RESERVED && resvport_only) {
1275 "umountall request from %s from unprivileged port",
1277 svcerr_weakauth(transp);
1280 if (!svc_sendreply(transp, (xdrproc_t)xdr_void, (caddr_t)NULL))
1281 syslog(LOG_ERR, "can't send reply");
1283 del_mlist(host, NULL);
1284 del_mlist(numerichost, NULL);
1287 "umountall request succeeded from %s",
1290 case MOUNTPROC_EXPORT:
1291 if (!svc_sendreply(transp, (xdrproc_t)xdr_explist, (caddr_t)NULL))
1292 if (!svc_sendreply(transp, (xdrproc_t)xdr_explist_brief,
1294 syslog(LOG_ERR, "can't send reply");
1297 "export request succeeded from %s",
1301 svcerr_noproc(transp);
1307 * Xdr conversion for a dirpath string
1310 xdr_dir(XDR *xdrsp, char *dirp)
1312 return (xdr_string(xdrsp, &dirp, MNTPATHLEN));
1316 * Xdr routine to generate file handle reply
1319 xdr_fhs(XDR *xdrsp, caddr_t cp)
1321 struct fhreturn *fhrp = (struct fhreturn *)cp;
1322 u_long ok = 0, len, auth;
1325 if (!xdr_long(xdrsp, &ok))
1327 switch (fhrp->fhr_vers) {
1329 return (xdr_opaque(xdrsp, (caddr_t)&fhrp->fhr_fh, NFSX_V2FH));
1332 if (!xdr_long(xdrsp, &len))
1334 if (!xdr_opaque(xdrsp, (caddr_t)&fhrp->fhr_fh, len))
1336 if (fhrp->fhr_numsecflavors) {
1337 if (!xdr_int(xdrsp, &fhrp->fhr_numsecflavors))
1339 for (i = 0; i < fhrp->fhr_numsecflavors; i++)
1340 if (!xdr_int(xdrsp, &fhrp->fhr_secflavors[i]))
1346 if (!xdr_long(xdrsp, &len))
1348 return (xdr_long(xdrsp, &auth));
1355 xdr_mlist(XDR *xdrsp, caddr_t cp __unused)
1357 struct mountlist *mlp;
1362 SLIST_FOREACH(mlp, &mlhead, next) {
1363 if (!xdr_bool(xdrsp, &true))
1365 strp = &mlp->ml_host[0];
1366 if (!xdr_string(xdrsp, &strp, MNTNAMLEN))
1368 strp = &mlp->ml_dirp[0];
1369 if (!xdr_string(xdrsp, &strp, MNTPATHLEN))
1372 if (!xdr_bool(xdrsp, &false))
1378 * Xdr conversion for export list
1381 xdr_explist_common(XDR *xdrsp, caddr_t cp __unused, int brief)
1383 struct exportlist *ep;
1386 sigset_t sighup_mask;
1389 sigemptyset(&sighup_mask);
1390 sigaddset(&sighup_mask, SIGHUP);
1391 sigprocmask(SIG_BLOCK, &sighup_mask, NULL);
1393 for (i = 0; i < exphashsize; i++)
1394 SLIST_FOREACH(ep, &exphead[i], entries) {
1396 if (put_exlist(ep->ex_dirl, xdrsp, ep->ex_defdir,
1399 if (ep->ex_defdir && putdef == 0 &&
1400 put_exlist(ep->ex_defdir, xdrsp, NULL,
1404 sigprocmask(SIG_UNBLOCK, &sighup_mask, NULL);
1405 if (!xdr_bool(xdrsp, &false))
1409 sigprocmask(SIG_UNBLOCK, &sighup_mask, NULL);
1414 * Called from xdr_explist() to traverse the tree and export the
1418 put_exlist(struct dirlist *dp, XDR *xdrsp, struct dirlist *adp, int *putdefp,
1421 struct grouplist *grp;
1422 struct hostlist *hp;
1429 if (put_exlist(dp->dp_left, xdrsp, adp, putdefp, brief))
1431 if (!xdr_bool(xdrsp, &true))
1434 if (!xdr_string(xdrsp, &strp, MNTPATHLEN))
1436 if (adp && !strcmp(dp->dp_dirp, adp->dp_dirp)) {
1441 if (!xdr_bool(xdrsp, &true))
1444 if (!xdr_string(xdrsp, &strp, MNTPATHLEN))
1446 } else if ((dp->dp_flag & DP_DEFSET) == 0 &&
1447 (gotalldir == 0 || (adp->dp_flag & DP_DEFSET) == 0)) {
1451 if (grp->gr_type == GT_HOST) {
1452 if (!xdr_bool(xdrsp, &true))
1454 strp = grp->gr_ptr.gt_addrinfo->ai_canonname;
1455 if (!xdr_string(xdrsp, &strp,
1458 } else if (grp->gr_type == GT_NET) {
1459 if (!xdr_bool(xdrsp, &true))
1461 strp = grp->gr_ptr.gt_net.nt_name;
1462 if (!xdr_string(xdrsp, &strp,
1467 if (gotalldir && hp == (struct hostlist *)NULL) {
1473 if (!xdr_bool(xdrsp, &false))
1475 if (put_exlist(dp->dp_right, xdrsp, adp, putdefp, brief))
1482 xdr_explist(XDR *xdrsp, caddr_t cp)
1485 return xdr_explist_common(xdrsp, cp, 0);
1489 xdr_explist_brief(XDR *xdrsp, caddr_t cp)
1492 return xdr_explist_common(xdrsp, cp, 1);
1496 static size_t linesize;
1497 static FILE *exp_file;
1500 * Get the export list from one, currently open file
1503 get_exportlist_one(int passno)
1505 struct exportlist *ep;
1506 struct grouplist *grp, *tgrp, *savgrp;
1507 struct dirlist *dirhead;
1509 struct expcred anon;
1510 char *cp, *endcp, *dirp, *hst, *usr, *dom, savedc;
1511 int len, has_host, got_nondir, dirplen, netgrp;
1515 dirhead = (struct dirlist *)NULL;
1516 while (get_line()) {
1518 warnx("got line %s", line);
1520 nextfield(&cp, &endcp);
1528 anon.cr_uid = 65534;
1529 anon.cr_ngroups = 1;
1530 anon.cr_groups[0] = 65533;
1531 exflags = MNT_EXPORTED;
1534 ep = (struct exportlist *)NULL;
1538 * Handle the V4 root dir.
1540 if (*cp == 'V' && *(cp + 1) == '4' && *(cp + 2) == ':') {
1542 * V4: just indicates that it is the v4 root point,
1543 * so skip over that and set v4root_phase.
1545 if (v4root_phase > 0) {
1546 syslog(LOG_ERR, "V4:duplicate line, ignored");
1551 nextfield(&cp, &endcp);
1555 * Create new exports list entry
1558 tgrp = grp = get_grp();
1560 if (len > MNTNAMLEN) {
1561 getexp_err(ep, tgrp, "mountpoint too long");
1565 if (ep == (struct exportlist *)NULL) {
1566 getexp_err(ep, tgrp,
1567 "flag before export path definition");
1571 warnx("doing opt %s", cp);
1573 if (do_opt(&cp, &endcp, ep, grp, &has_host,
1575 getexp_err(ep, tgrp, NULL);
1578 } else if (*cp == '/') {
1581 if (v4root_phase > 1) {
1583 getexp_err(ep, tgrp, "Multiple V4 dirs");
1587 if (check_dirpath(cp) &&
1588 statfs(cp, &fsb) >= 0) {
1589 if ((fsb.f_flags & MNT_AUTOMOUNTED) != 0)
1590 syslog(LOG_ERR, "Warning: exporting of "
1591 "automounted fs %s not supported", cp);
1593 getexp_err(ep, tgrp, "dirs must be first");
1596 if (v4root_phase == 1) {
1598 getexp_err(ep, tgrp, "Multiple V4 dirs");
1601 if (strlen(v4root_dirpath) == 0) {
1602 strlcpy(v4root_dirpath, cp,
1603 sizeof (v4root_dirpath));
1604 } else if (strcmp(v4root_dirpath, cp)
1607 "different V4 dirpath %s", cp);
1608 getexp_err(ep, tgrp, NULL);
1617 if (fsidcmp(&ep->ex_fs, &fsb.f_fsid)
1619 getexp_err(ep, tgrp,
1625 * See if this directory is already
1628 ep = ex_search(&fsb.f_fsid, exphead);
1629 if (ep == (struct exportlist *)NULL) {
1631 ep->ex_fs = fsb.f_fsid;
1632 ep->ex_fsdir = strdup(fsb.f_mntonname);
1633 if (ep->ex_fsdir == NULL)
1637 "making new ep fs=0x%x,0x%x",
1641 warnx("found ep fs=0x%x,0x%x",
1647 * Add dirpath to export mount point.
1649 dirp = add_expdir(&dirhead, cp, len);
1653 getexp_err(ep, tgrp,
1654 "symbolic link in export path or statfs failed");
1662 if (ep == (struct exportlist *)NULL) {
1663 getexp_err(ep, tgrp,
1664 "host(s) before export path definition");
1669 * Get the host or netgroup.
1672 netgrp = getnetgrent(&hst, &usr, &dom);
1675 grp->gr_next = get_grp();
1681 "null hostname in netgroup %s, skipping", cp);
1682 grp->gr_type = GT_IGNORE;
1683 } else if (get_host(hst, grp, tgrp)) {
1685 "bad host %s in netgroup %s, skipping", hst, cp);
1686 grp->gr_type = GT_IGNORE;
1688 } else if (get_host(cp, grp, tgrp)) {
1689 syslog(LOG_ERR, "bad host %s, skipping", cp);
1690 grp->gr_type = GT_IGNORE;
1693 } while (netgrp && getnetgrent(&hst, &usr, &dom));
1698 nextfield(&cp, &endcp);
1701 if (check_options(dirhead)) {
1702 getexp_err(ep, tgrp, NULL);
1706 grp->gr_type = GT_DEFAULT;
1708 warnx("adding a default entry");
1711 * Don't allow a network export coincide with a list of
1712 * host(s) on the same line.
1714 } else if ((opt_flags & OP_NET) && tgrp->gr_next) {
1715 getexp_err(ep, tgrp, "network/host conflict");
1719 * If an export list was specified on this line, make sure
1720 * that we have at least one valid entry, otherwise skip it.
1724 while (grp && grp->gr_type == GT_IGNORE)
1727 getexp_err(ep, tgrp, "no valid entries");
1732 if (v4root_phase == 1) {
1733 getexp_err(ep, tgrp, "V4:root, no dirp, ignored");
1738 * Loop through hosts, pushing the exports into the kernel.
1739 * After loop, tgrp points to the start of the list and
1740 * grp points to the last entry in the list.
1741 * Do not do the do_mount() for passno == 1, since the
1742 * second pass will do it, as required.
1746 grp->gr_exflags = exflags;
1747 cp_cred(&grp->gr_anon, &anon);
1748 if (v4root_phase == 2 && passno == 0)
1749 LOGDEBUG("do_mount v4root");
1750 if (passno == 0 && do_mount(ep, grp, exflags, &anon,
1751 dirp, dirplen, &fsb, ep->ex_numsecflavors,
1752 ep->ex_secflavors)) {
1753 getexp_err(ep, tgrp, NULL);
1756 } while (grp->gr_next && (grp = grp->gr_next));
1759 * For V4: don't enter in mount lists.
1761 if (v4root_phase > 0 && v4root_phase <= 2) {
1763 * These structures are used for the reload,
1764 * so save them for that case. Otherwise, just
1767 if (passno == 1 && ep != NULL) {
1769 while (tgrp != NULL) {
1771 * Save the security flavors and exflags
1772 * for this host set in the groups.
1774 tgrp->gr_numsecflavors =
1775 ep->ex_numsecflavors;
1776 if (ep->ex_numsecflavors > 0)
1777 memcpy(tgrp->gr_secflavors,
1779 sizeof(ep->ex_secflavors));
1780 tgrp = tgrp->gr_next;
1782 if (v4root_ep == NULL) {
1784 ep = NULL; /* Don't free below. */
1786 grp->gr_next = v4root_ep->ex_grphead;
1787 v4root_ep->ex_grphead = savgrp;
1791 while (tgrp != NULL) {
1793 tgrp = tgrp->gr_next;
1800 * Success. Update the data structures.
1803 hang_dirp(dirhead, tgrp, ep, opt_flags, &anon, exflags);
1804 grp->gr_next = ep->ex_grphead;
1805 ep->ex_grphead = tgrp;
1807 hang_dirp(dirhead, (struct grouplist *)NULL, ep,
1808 opt_flags, &anon, exflags);
1811 dirhead = (struct dirlist *)NULL;
1812 if ((ep->ex_flag & EX_LINKED) == 0) {
1813 insert_exports(ep, exphead);
1815 ep->ex_flag |= EX_LINKED;
1821 dirhead = (struct dirlist *)NULL;
1827 * Get the export list from all specified files
1830 get_exportlist(int passno)
1832 struct export_args export;
1834 struct statfs *mntbufp;
1838 struct nfsex_args eargs;
1841 if ((debug_file = fopen(_PATH_MOUNTDDEBUG, "r")) != NULL) {
1846 LOGDEBUG("passno=%d", passno);
1847 v4root_dirpath[0] = '\0';
1851 * Save the current lists as old ones, so that the new lists
1852 * can be compared with the old ones in the 2nd pass.
1854 for (i = 0; i < exphashsize; i++) {
1855 SLIST_FIRST(&oldexphead[i]) = SLIST_FIRST(&exphead[i]);
1856 SLIST_INIT(&exphead[i]);
1859 /* Note that the public fh has not yet been set. */
1860 has_set_publicfh = 0;
1862 /* Read the export file(s) and process them */
1863 read_exportfile(passno);
1866 * Just make the old lists empty.
1867 * exphashsize == 0 for the first call, before oldexphead
1868 * has been initialized-->loop won't be executed.
1870 for (i = 0; i < exphashsize; i++)
1871 SLIST_INIT(&oldexphead[i]);
1874 bzero(&export, sizeof(export));
1875 export.ex_flags = MNT_DELEXPORT;
1878 bzero(errmsg, sizeof(errmsg));
1880 if (suspend_nfsd != 0)
1881 (void)nfssvc(NFSSVC_SUSPENDNFSD, NULL);
1883 * Delete the old V4 root dir.
1885 bzero(&eargs, sizeof (eargs));
1886 eargs.export.ex_flags = MNT_DELEXPORT;
1887 if (nfssvc(NFSSVC_V4ROOTEXPORT | NFSSVC_NEWSTRUCT, (caddr_t)&eargs) < 0 &&
1889 syslog(LOG_ERR, "Can't delete exports for V4:");
1891 build_iovec(&iov, &iovlen, "fstype", NULL, 0);
1892 build_iovec(&iov, &iovlen, "fspath", NULL, 0);
1893 build_iovec(&iov, &iovlen, "from", NULL, 0);
1894 build_iovec(&iov, &iovlen, "update", NULL, 0);
1895 build_iovec(&iov, &iovlen, "export", &export,
1897 build_iovec(&iov, &iovlen, "errmsg", errmsg,
1901 * For passno == 1, compare the old and new lists updating the kernel
1902 * exports for any cases that have changed.
1903 * This call is doing the second pass through the lists.
1904 * If it fails, fall back on the bulk reload.
1906 if (passno == 1 && compare_nmount_exportlist(iov, iovlen, errmsg) ==
1908 LOGDEBUG("compareok");
1909 /* Free up the old lists. */
1910 free_exports(oldexphead);
1912 LOGDEBUG("doing passno=0");
1914 * Clear flag that notes if a public fh has been exported.
1915 * It is set by do_mount() if MNT_EXPUBLIC is set for the entry.
1919 /* exphead == NULL if not yet allocated (first call). */
1920 if (exphead != NULL) {
1922 * First, get rid of the old lists.
1924 free_exports(exphead);
1925 free_exports(oldexphead);
1929 * And delete exports that are in the kernel for all local
1931 * XXX: Should know how to handle all local exportable
1934 num = getmntinfo(&mntbufp, MNT_NOWAIT);
1936 /* Allocate hash tables, for first call. */
1937 if (exphead == NULL) {
1938 /* Target an average linked list length of 10. */
1939 exphashsize = num / 10;
1940 if (exphashsize < 1)
1942 else if (exphashsize > 100000)
1943 exphashsize = 100000;
1944 exphead = malloc(exphashsize * sizeof(*exphead));
1945 oldexphead = malloc(exphashsize * sizeof(*oldexphead));
1946 if (exphead == NULL || oldexphead == NULL)
1947 errx(1, "Can't malloc hash tables");
1949 for (i = 0; i < exphashsize; i++) {
1950 SLIST_INIT(&exphead[i]);
1951 SLIST_INIT(&oldexphead[i]);
1955 for (i = 0; i < num; i++)
1956 delete_export(iov, iovlen, &mntbufp[i], errmsg);
1959 /* Read the export file(s) and process them */
1964 /* Free strings allocated by strdup() in getmntopts.c */
1965 free(iov[0].iov_base); /* fstype */
1966 free(iov[2].iov_base); /* fspath */
1967 free(iov[4].iov_base); /* from */
1968 free(iov[6].iov_base); /* update */
1969 free(iov[8].iov_base); /* export */
1970 free(iov[10].iov_base); /* errmsg */
1972 /* free iov, allocated by realloc() */
1978 * If there was no public fh, clear any previous one set.
1980 if (has_publicfh == 0) {
1981 LOGDEBUG("clear public fh");
1982 (void) nfssvc(NFSSVC_NOPUBLICFH, NULL);
1985 /* Resume the nfsd. If they weren't suspended, this is harmless. */
1986 (void)nfssvc(NFSSVC_RESUMENFSD, NULL);
1987 LOGDEBUG("eo get_exportlist");
1991 * Insert an export entry in the appropriate list.
1994 insert_exports(struct exportlist *ep, struct exportlisthead *exhp)
1998 i = EXPHASH(&ep->ex_fs);
1999 LOGDEBUG("fs=%s hash=%i", ep->ex_fsdir, i);
2000 SLIST_INSERT_HEAD(&exhp[i], ep, entries);
2004 * Free up the exports lists passed in as arguments.
2007 free_exports(struct exportlisthead *exhp)
2009 struct exportlist *ep, *ep2;
2012 for (i = 0; i < exphashsize; i++) {
2013 SLIST_FOREACH_SAFE(ep, &exhp[i], entries, ep2) {
2014 SLIST_REMOVE(&exhp[i], ep, exportlist, entries);
2017 SLIST_INIT(&exhp[i]);
2022 * Read the exports file(s) and call get_exportlist_one() for each line.
2025 read_exportfile(int passno)
2030 * Read in the exports file and build the list, calling
2031 * nmount() as we go along to push the export rules into the kernel.
2034 for (i = 0; exnames[i] != NULL; i++) {
2036 warnx("reading exports from %s", exnames[i]);
2037 if ((exp_file = fopen(exnames[i], "r")) == NULL) {
2038 syslog(LOG_WARNING, "can't open %s", exnames[i]);
2041 get_exportlist_one(passno);
2046 syslog(LOG_ERR, "can't open any exports file");
2052 * Compare the export lists against the old ones and do nmount() operations
2053 * for any cases that have changed. This avoids doing nmount() for entries
2054 * that have not changed.
2055 * Return 0 upon success, 1 otherwise.
2058 compare_nmount_exportlist(struct iovec *iov, int iovlen, char *errmsg)
2060 struct exportlist *ep, *oep;
2061 struct grouplist *grp;
2062 struct statfs fs, ofs;
2066 * Loop through the current list and look for an entry in the old
2068 * If found, check to see if it the same.
2069 * If it is not the same, delete and re-export.
2070 * Then mark it done on the old list.
2073 * Any entries left in the old list after processing must have their
2076 for (i = 0; i < exphashsize; i++)
2077 SLIST_FOREACH(ep, &exphead[i], entries) {
2078 LOGDEBUG("foreach ep=%s", ep->ex_fsdir);
2079 oep = ex_search(&ep->ex_fs, oldexphead);
2082 * Check the mount paths are the same.
2083 * If not, return 1 so that the reload of the
2084 * exports will be done in bulk, the
2087 LOGDEBUG("found old exp");
2088 if (strcmp(ep->ex_fsdir, oep->ex_fsdir) != 0)
2090 LOGDEBUG("same fsdir");
2092 * Test to see if the entry is the same.
2093 * If not the same delete exports and
2096 if (compare_export(ep, oep) != 0) {
2098 * Clear has_publicfh if if was set
2099 * in the old exports, but only if it
2100 * has not been set during processing of
2101 * the exports for this pass, as
2102 * indicated by has_set_publicfh.
2104 if (has_set_publicfh == 0 &&
2105 (oep->ex_flag & EX_PUBLICFH) != 0)
2108 /* Delete and re-export. */
2109 if (statfs(ep->ex_fsdir, &fs) < 0)
2111 delete_export(iov, iovlen, &fs, errmsg);
2112 ret = do_export_mount(ep, &fs);
2116 oep->ex_flag |= EX_DONE;
2119 LOGDEBUG("not found so export");
2120 /* Not found, so do export. */
2121 if (statfs(ep->ex_fsdir, &fs) < 0)
2123 ret = do_export_mount(ep, &fs);
2129 /* Delete exports not done. */
2130 for (i = 0; i < exphashsize; i++)
2131 SLIST_FOREACH(oep, &oldexphead[i], entries) {
2132 if ((oep->ex_flag & EX_DONE) == 0) {
2133 LOGDEBUG("not done delete=%s", oep->ex_fsdir);
2134 if (statfs(oep->ex_fsdir, &ofs) >= 0 &&
2135 fsidcmp(&oep->ex_fs, &ofs.f_fsid) == 0) {
2136 LOGDEBUG("do delete");
2138 * Clear has_publicfh if if was set
2139 * in the old exports, but only if it
2140 * has not been set during processing of
2141 * the exports for this pass, as
2142 * indicated by has_set_publicfh.
2144 if (has_set_publicfh == 0 &&
2145 (oep->ex_flag & EX_PUBLICFH) != 0)
2148 delete_export(iov, iovlen, &ofs,
2154 /* Do the V4 root exports, as required. */
2156 if (v4root_ep != NULL)
2157 grp = v4root_ep->ex_grphead;
2159 while (v4root_ep != NULL && grp != NULL) {
2160 LOGDEBUG("v4root expath=%s", v4root_dirpath);
2161 ret = do_mount(v4root_ep, grp, grp->gr_exflags, &grp->gr_anon,
2162 v4root_dirpath, strlen(v4root_dirpath), &fs,
2163 grp->gr_numsecflavors, grp->gr_secflavors);
2176 * Compare old and current exportlist entries for the fsid and return 0
2177 * if they are the same, 1 otherwise.
2180 compare_export(struct exportlist *ep, struct exportlist *oep)
2182 struct grouplist *grp, *ogrp;
2184 if (strcmp(ep->ex_fsdir, oep->ex_fsdir) != 0)
2186 if ((ep->ex_flag & EX_DEFSET) != (oep->ex_flag & EX_DEFSET))
2188 if ((ep->ex_defdir != NULL && oep->ex_defdir == NULL) ||
2189 (ep->ex_defdir == NULL && oep->ex_defdir != NULL))
2191 if (ep->ex_defdir != NULL && (ep->ex_defdir->dp_flag & DP_DEFSET) !=
2192 (oep->ex_defdir->dp_flag & DP_DEFSET))
2194 if ((ep->ex_flag & EX_DEFSET) != 0 && (ep->ex_defnumsecflavors !=
2195 oep->ex_defnumsecflavors || ep->ex_defexflags !=
2196 oep->ex_defexflags || compare_cred(&ep->ex_defanon,
2197 &oep->ex_defanon) != 0 || compare_secflavor(ep->ex_defsecflavors,
2198 oep->ex_defsecflavors, ep->ex_defnumsecflavors) != 0))
2201 /* Now, check all the groups. */
2202 for (ogrp = oep->ex_grphead; ogrp != NULL; ogrp = ogrp->gr_next)
2204 for (grp = ep->ex_grphead; grp != NULL; grp = grp->gr_next) {
2205 for (ogrp = oep->ex_grphead; ogrp != NULL; ogrp =
2207 if ((ogrp->gr_flag & GR_FND) == 0 &&
2208 grp->gr_numsecflavors == ogrp->gr_numsecflavors &&
2209 grp->gr_exflags == ogrp->gr_exflags &&
2210 compare_cred(&grp->gr_anon, &ogrp->gr_anon) == 0 &&
2211 compare_secflavor(grp->gr_secflavors,
2212 ogrp->gr_secflavors, grp->gr_numsecflavors) == 0)
2215 ogrp->gr_flag |= GR_FND;
2219 for (ogrp = oep->ex_grphead; ogrp != NULL; ogrp = ogrp->gr_next)
2220 if ((ogrp->gr_flag & GR_FND) == 0)
2226 * This algorithm compares two arrays of "n" items. It returns 0 if they are
2227 * the "same" and 1 otherwise. Although suboptimal, it is always safe to
2228 * return 1, which makes compare_nmount_export() reload the exports entry.
2229 * "same" refers to having the same set of values in the two arrays.
2230 * The arrays are in no particular order and duplicates (multiple entries
2231 * in an array with the same value) is allowed.
2232 * The algorithm is inefficient, but the common case of indentical arrays is
2233 * handled first and "n" is normally fairly small.
2234 * Since the two functions need the same algorithm but for arrays of
2235 * different types (gid_t vs int), this is done as a macro.
2237 #define COMPARE_ARRAYS(a1, a2, n) \
2239 int fnd, fndarray[(n)], i, j; \
2240 /* Handle common case of identical arrays. */ \
2241 for (i = 0; i < (n); i++) \
2242 if ((a1)[i] != (a2)[i]) \
2246 for (i = 0; i < (n); i++) \
2248 for (i = 0; i < (n); i++) { \
2250 for (j = 0; j < (n); j++) { \
2251 if ((a1)[i] == (a2)[j]) { \
2259 for (i = 0; i < (n); i++) \
2260 if (fndarray[i] == 0) \
2266 * Compare two struct expcred's. Return 0 if the same and 1 otherwise.
2269 compare_cred(struct expcred *cr0, struct expcred *cr1)
2272 if (cr0->cr_uid != cr1->cr_uid || cr0->cr_ngroups != cr1->cr_ngroups)
2275 COMPARE_ARRAYS(cr0->cr_groups, cr1->cr_groups, cr0->cr_ngroups);
2279 * Compare two lists of security flavors. Return 0 if the same and 1 otherwise.
2282 compare_secflavor(int *sec1, int *sec2, int nsec)
2285 COMPARE_ARRAYS(sec1, sec2, nsec);
2289 * Delete an exports entry.
2292 delete_export(struct iovec *iov, int iovlen, struct statfs *fsp, char *errmsg)
2294 struct xvfsconf vfc;
2296 if (getvfsbyname(fsp->f_fstypename, &vfc) != 0) {
2297 syslog(LOG_ERR, "getvfsbyname() failed for %s",
2303 * We do not need to delete "export" flag from
2304 * filesystems that do not have it set.
2306 if (!(fsp->f_flags & MNT_EXPORTED))
2309 * Do not delete export for network filesystem by
2310 * passing "export" arg to nmount().
2311 * It only makes sense to do this for local filesystems.
2313 if (vfc.vfc_flags & VFCF_NETWORK)
2316 iov[1].iov_base = fsp->f_fstypename;
2317 iov[1].iov_len = strlen(fsp->f_fstypename) + 1;
2318 iov[3].iov_base = fsp->f_mntonname;
2319 iov[3].iov_len = strlen(fsp->f_mntonname) + 1;
2320 iov[5].iov_base = fsp->f_mntfromname;
2321 iov[5].iov_len = strlen(fsp->f_mntfromname) + 1;
2325 * EXDEV is returned when path exists but is not a
2326 * mount point. May happens if raced with unmount.
2328 if (nmount(iov, iovlen, fsp->f_flags) < 0 && errno != ENOENT &&
2329 errno != ENOTSUP && errno != EXDEV) {
2331 "can't delete exports for %s: %m %s",
2332 fsp->f_mntonname, errmsg);
2337 * Allocate an export list element
2339 static struct exportlist *
2342 struct exportlist *ep;
2344 ep = (struct exportlist *)calloc(1, sizeof (struct exportlist));
2345 if (ep == (struct exportlist *)NULL)
2351 * Allocate a group list element
2353 static struct grouplist *
2356 struct grouplist *gp;
2358 gp = (struct grouplist *)calloc(1, sizeof (struct grouplist));
2359 if (gp == (struct grouplist *)NULL)
2365 * Clean up upon an error in get_exportlist().
2368 getexp_err(struct exportlist *ep, struct grouplist *grp, const char *reason)
2370 struct grouplist *tgrp;
2372 if (!(opt_flags & OP_QUIET)) {
2374 syslog(LOG_ERR, "bad exports list line '%s': %s", line,
2377 syslog(LOG_ERR, "bad exports list line '%s'", line);
2379 if (ep && (ep->ex_flag & EX_LINKED) == 0)
2389 * Search the export list for a matching fs.
2391 static struct exportlist *
2392 ex_search(fsid_t *fsid, struct exportlisthead *exhp)
2394 struct exportlist *ep;
2398 SLIST_FOREACH(ep, &exhp[i], entries) {
2399 if (fsidcmp(&ep->ex_fs, fsid) == 0)
2407 * Add a directory path to the list.
2410 add_expdir(struct dirlist **dpp, char *cp, int len)
2414 dp = malloc(sizeof (struct dirlist));
2415 if (dp == (struct dirlist *)NULL)
2418 dp->dp_right = (struct dirlist *)NULL;
2420 dp->dp_hosts = (struct hostlist *)NULL;
2421 dp->dp_dirp = strndup(cp, len);
2422 if (dp->dp_dirp == NULL)
2425 return (dp->dp_dirp);
2429 * Hang the dir list element off the dirpath binary tree as required
2430 * and update the entry for host.
2433 hang_dirp(struct dirlist *dp, struct grouplist *grp, struct exportlist *ep,
2434 int flags, struct expcred *anoncrp, uint64_t exflags)
2436 struct hostlist *hp;
2437 struct dirlist *dp2;
2439 if (flags & OP_ALLDIRS) {
2444 if (grp == (struct grouplist *)NULL) {
2445 ep->ex_flag |= EX_DEFSET;
2446 ep->ex_defdir->dp_flag |= DP_DEFSET;
2447 /* Save the default security flavors list. */
2448 ep->ex_defnumsecflavors = ep->ex_numsecflavors;
2449 if (ep->ex_numsecflavors > 0)
2450 memcpy(ep->ex_defsecflavors, ep->ex_secflavors,
2451 sizeof(ep->ex_secflavors));
2452 cp_cred(&ep->ex_defanon, anoncrp);
2453 ep->ex_defexflags = exflags;
2454 } else while (grp) {
2457 hp->ht_next = ep->ex_defdir->dp_hosts;
2458 ep->ex_defdir->dp_hosts = hp;
2459 /* Save the security flavors list for this host set. */
2460 grp->gr_numsecflavors = ep->ex_numsecflavors;
2461 if (ep->ex_numsecflavors > 0)
2462 memcpy(grp->gr_secflavors, ep->ex_secflavors,
2463 sizeof(ep->ex_secflavors));
2469 * Loop through the directories adding them to the tree.
2473 add_dlist(&ep->ex_dirl, dp, grp, flags, ep, anoncrp,
2481 * Traverse the binary tree either updating a node that is already there
2482 * for the new directory or adding the new node.
2485 add_dlist(struct dirlist **dpp, struct dirlist *newdp, struct grouplist *grp,
2486 int flags, struct exportlist *ep, struct expcred *anoncrp,
2490 struct hostlist *hp;
2495 cmp = strcmp(dp->dp_dirp, newdp->dp_dirp);
2497 add_dlist(&dp->dp_left, newdp, grp, flags, ep, anoncrp,
2500 } else if (cmp < 0) {
2501 add_dlist(&dp->dp_right, newdp, grp, flags, ep, anoncrp,
2505 free((caddr_t)newdp);
2508 dp->dp_left = (struct dirlist *)NULL;
2514 * Hang all of the host(s) off of the directory point.
2519 hp->ht_next = dp->dp_hosts;
2521 /* Save the security flavors list for this host set. */
2522 grp->gr_numsecflavors = ep->ex_numsecflavors;
2523 if (ep->ex_numsecflavors > 0)
2524 memcpy(grp->gr_secflavors, ep->ex_secflavors,
2525 sizeof(ep->ex_secflavors));
2529 ep->ex_flag |= EX_DEFSET;
2530 dp->dp_flag |= DP_DEFSET;
2531 /* Save the default security flavors list. */
2532 ep->ex_defnumsecflavors = ep->ex_numsecflavors;
2533 if (ep->ex_numsecflavors > 0)
2534 memcpy(ep->ex_defsecflavors, ep->ex_secflavors,
2535 sizeof(ep->ex_secflavors));
2536 cp_cred(&ep->ex_defanon, anoncrp);
2537 ep->ex_defexflags = exflags;
2542 * Search for a dirpath on the export point.
2544 static struct dirlist *
2545 dirp_search(struct dirlist *dp, char *dirp)
2550 cmp = strcmp(dp->dp_dirp, dirp);
2552 return (dirp_search(dp->dp_left, dirp));
2554 return (dirp_search(dp->dp_right, dirp));
2562 * Scan for a host match in a directory tree.
2565 chk_host(struct dirlist *dp, struct sockaddr *saddr, int *defsetp,
2566 int *hostsetp, int *numsecflavors, int **secflavorsp)
2568 struct hostlist *hp;
2569 struct grouplist *grp;
2570 struct addrinfo *ai;
2573 if (dp->dp_flag & DP_DEFSET)
2574 *defsetp = dp->dp_flag;
2578 switch (grp->gr_type) {
2580 ai = grp->gr_ptr.gt_addrinfo;
2581 for (; ai; ai = ai->ai_next) {
2582 if (!sacmp(ai->ai_addr, saddr, NULL)) {
2584 (hp->ht_flag | DP_HOSTSET);
2585 if (numsecflavors != NULL) {
2587 grp->gr_numsecflavors;
2596 if (!sacmp(saddr, (struct sockaddr *)
2597 &grp->gr_ptr.gt_net.nt_net,
2599 &grp->gr_ptr.gt_net.nt_mask)) {
2600 *hostsetp = (hp->ht_flag | DP_HOSTSET);
2601 if (numsecflavors != NULL) {
2603 grp->gr_numsecflavors;
2618 * Scan tree for a host that matches the address.
2621 scan_tree(struct dirlist *dp, struct sockaddr *saddr)
2623 int defset, hostset;
2626 if (scan_tree(dp->dp_left, saddr))
2628 if (chk_host(dp, saddr, &defset, &hostset, NULL, NULL))
2630 if (scan_tree(dp->dp_right, saddr))
2637 * Traverse the dirlist tree and free it up.
2640 free_dir(struct dirlist *dp)
2644 free_dir(dp->dp_left);
2645 free_dir(dp->dp_right);
2646 free_host(dp->dp_hosts);
2653 * Parse a colon separated list of security flavors
2656 parsesec(char *seclist, struct exportlist *ep)
2661 ep->ex_numsecflavors = 0;
2663 cp = strchr(seclist, ':');
2669 if (!strcmp(seclist, "sys"))
2671 else if (!strcmp(seclist, "krb5"))
2672 flavor = RPCSEC_GSS_KRB5;
2673 else if (!strcmp(seclist, "krb5i"))
2674 flavor = RPCSEC_GSS_KRB5I;
2675 else if (!strcmp(seclist, "krb5p"))
2676 flavor = RPCSEC_GSS_KRB5P;
2680 syslog(LOG_ERR, "bad sec flavor: %s", seclist);
2683 if (ep->ex_numsecflavors == MAXSECFLAVORS) {
2686 syslog(LOG_ERR, "too many sec flavors: %s", seclist);
2689 ep->ex_secflavors[ep->ex_numsecflavors] = flavor;
2690 ep->ex_numsecflavors++;
2702 * Parse the option string and update fields.
2703 * Option arguments may either be -<option>=<value> or
2707 do_opt(char **cpp, char **endcpp, struct exportlist *ep, struct grouplist *grp,
2708 int *has_hostp, uint64_t *exflagsp, struct expcred *cr)
2710 char *cpoptarg, *cpoptend;
2711 char *cp, *endcp, *cpopt, savedc, savedc2;
2712 int allflag, usedarg;
2720 while (cpopt && *cpopt) {
2723 if ((cpoptend = strchr(cpopt, ','))) {
2725 if ((cpoptarg = strchr(cpopt, '=')))
2728 if ((cpoptarg = strchr(cpopt, '=')))
2732 nextfield(&cp, &endcp);
2734 if (endcp > cp && *cp != '-') {
2742 if (!strcmp(cpopt, "ro") || !strcmp(cpopt, "o")) {
2743 *exflagsp |= MNT_EXRDONLY;
2744 } else if (cpoptarg && (!strcmp(cpopt, "maproot") ||
2745 !(allflag = strcmp(cpopt, "mapall")) ||
2746 !strcmp(cpopt, "root") || !strcmp(cpopt, "r"))) {
2748 parsecred(cpoptarg, cr);
2750 *exflagsp |= MNT_EXPORTANON;
2751 opt_flags |= OP_MAPALL;
2753 opt_flags |= OP_MAPROOT;
2754 } else if (cpoptarg && (!strcmp(cpopt, "mask") ||
2755 !strcmp(cpopt, "m"))) {
2756 if (get_net(cpoptarg, &grp->gr_ptr.gt_net, 1)) {
2757 syslog(LOG_ERR, "bad mask: %s", cpoptarg);
2761 opt_flags |= OP_MASK;
2762 } else if (cpoptarg && (!strcmp(cpopt, "network") ||
2763 !strcmp(cpopt, "n"))) {
2764 if (strchr(cpoptarg, '/') != NULL) {
2766 fprintf(stderr, "setting OP_MASKLEN\n");
2767 opt_flags |= OP_MASKLEN;
2769 if (grp->gr_type != GT_NULL) {
2770 syslog(LOG_ERR, "network/host conflict");
2772 } else if (get_net(cpoptarg, &grp->gr_ptr.gt_net, 0)) {
2773 syslog(LOG_ERR, "bad net: %s", cpoptarg);
2776 grp->gr_type = GT_NET;
2779 opt_flags |= OP_NET;
2780 } else if (!strcmp(cpopt, "alldirs")) {
2781 opt_flags |= OP_ALLDIRS;
2782 } else if (!strcmp(cpopt, "public")) {
2783 *exflagsp |= MNT_EXPUBLIC;
2784 } else if (!strcmp(cpopt, "webnfs")) {
2785 *exflagsp |= (MNT_EXPUBLIC|MNT_EXRDONLY|MNT_EXPORTANON);
2786 opt_flags |= OP_MAPALL;
2787 } else if (cpoptarg && !strcmp(cpopt, "index")) {
2788 ep->ex_indexfile = strdup(cpoptarg);
2789 } else if (!strcmp(cpopt, "quiet")) {
2790 opt_flags |= OP_QUIET;
2791 } else if (cpoptarg && !strcmp(cpopt, "sec")) {
2792 if (parsesec(cpoptarg, ep))
2794 opt_flags |= OP_SEC;
2797 syslog(LOG_ERR, "bad opt %s", cpopt);
2816 * Translate a character string to the corresponding list of network
2817 * addresses for a hostname.
2820 get_host(char *cp, struct grouplist *grp, struct grouplist *tgrp)
2822 struct grouplist *checkgrp;
2823 struct addrinfo *ai, *tai, hints;
2825 char host[NI_MAXHOST];
2827 if (grp->gr_type != GT_NULL) {
2828 syslog(LOG_ERR, "Bad netgroup type for ip host %s", cp);
2831 memset(&hints, 0, sizeof hints);
2832 hints.ai_flags = AI_CANONNAME;
2833 hints.ai_protocol = IPPROTO_UDP;
2834 ecode = getaddrinfo(cp, NULL, &hints, &ai);
2836 syslog(LOG_ERR,"can't get address info for host %s", cp);
2839 grp->gr_ptr.gt_addrinfo = ai;
2840 while (ai != NULL) {
2841 if (ai->ai_canonname == NULL) {
2842 if (getnameinfo(ai->ai_addr, ai->ai_addrlen, host,
2843 sizeof host, NULL, 0, NI_NUMERICHOST) != 0)
2844 strlcpy(host, "?", sizeof(host));
2845 ai->ai_canonname = strdup(host);
2846 ai->ai_flags |= AI_CANONNAME;
2849 fprintf(stderr, "got host %s\n", ai->ai_canonname);
2851 * Sanity check: make sure we don't already have an entry
2852 * for this host in the grouplist.
2854 for (checkgrp = tgrp; checkgrp != NULL;
2855 checkgrp = checkgrp->gr_next) {
2856 if (checkgrp->gr_type != GT_HOST)
2858 for (tai = checkgrp->gr_ptr.gt_addrinfo; tai != NULL;
2859 tai = tai->ai_next) {
2860 if (sacmp(tai->ai_addr, ai->ai_addr, NULL) != 0)
2864 "ignoring duplicate host %s\n",
2866 grp->gr_type = GT_IGNORE;
2872 grp->gr_type = GT_HOST;
2877 * Free up an exports list component
2880 free_exp(struct exportlist *ep)
2882 struct grouplist *grp, *tgrp;
2884 if (ep->ex_defdir) {
2885 free_host(ep->ex_defdir->dp_hosts);
2886 free((caddr_t)ep->ex_defdir);
2890 if (ep->ex_indexfile)
2891 free(ep->ex_indexfile);
2892 free_dir(ep->ex_dirl);
2893 grp = ep->ex_grphead;
2903 * Free up the v4root exports.
2906 free_v4rootexp(void)
2909 if (v4root_ep != NULL) {
2910 free_exp(v4root_ep);
2919 free_host(struct hostlist *hp)
2921 struct hostlist *hp2;
2930 static struct hostlist *
2933 struct hostlist *hp;
2935 hp = (struct hostlist *)malloc(sizeof (struct hostlist));
2936 if (hp == (struct hostlist *)NULL)
2938 hp->ht_next = (struct hostlist *)NULL;
2944 * Out of memory, fatal
2950 syslog(LOG_ERR, "out of memory");
2955 * Call do_mount() from the struct exportlist, for each case needed.
2958 do_export_mount(struct exportlist *ep, struct statfs *fsp)
2960 struct grouplist *grp, defgrp;
2964 LOGDEBUG("do_export_mount=%s", ep->ex_fsdir);
2965 dirlen = strlen(ep->ex_fsdir);
2966 if ((ep->ex_flag & EX_DEFSET) != 0) {
2967 defgrp.gr_type = GT_DEFAULT;
2968 defgrp.gr_next = NULL;
2969 /* We have an entry for all other hosts/nets. */
2970 LOGDEBUG("ex_defexflags=0x%jx", (uintmax_t)ep->ex_defexflags);
2971 ret = do_mount(ep, &defgrp, ep->ex_defexflags, &ep->ex_defanon,
2972 ep->ex_fsdir, dirlen, fsp, ep->ex_defnumsecflavors,
2973 ep->ex_defsecflavors);
2978 /* Do a mount for each group. */
2979 grp = ep->ex_grphead;
2980 while (grp != NULL) {
2981 LOGDEBUG("do mount gr_type=0x%x gr_exflags=0x%jx",
2982 grp->gr_type, (uintmax_t)grp->gr_exflags);
2983 ret = do_mount(ep, grp, grp->gr_exflags, &grp->gr_anon,
2984 ep->ex_fsdir, dirlen, fsp, grp->gr_numsecflavors,
2985 grp->gr_secflavors);
2994 * Do the nmount() syscall with the update flag to push the export info into
2998 do_mount(struct exportlist *ep, struct grouplist *grp, uint64_t exflags,
2999 struct expcred *anoncrp, char *dirp, int dirplen, struct statfs *fsb,
3000 int numsecflavors, int *secflavors)
3003 struct addrinfo *ai;
3004 struct export_args *eap;
3012 struct nfsex_args nfsea;
3014 eap = &nfsea.export;
3022 bzero(eap, sizeof (struct export_args));
3023 bzero(errmsg, sizeof(errmsg));
3024 eap->ex_flags = exflags;
3025 eap->ex_uid = anoncrp->cr_uid;
3026 eap->ex_ngroups = anoncrp->cr_ngroups;
3027 if (eap->ex_ngroups > 0) {
3028 eap->ex_groups = malloc(eap->ex_ngroups * sizeof(gid_t));
3029 memcpy(eap->ex_groups, anoncrp->cr_groups, eap->ex_ngroups *
3032 LOGDEBUG("do_mount exflags=0x%jx", (uintmax_t)exflags);
3033 eap->ex_indexfile = ep->ex_indexfile;
3034 if (grp->gr_type == GT_HOST)
3035 ai = grp->gr_ptr.gt_addrinfo;
3038 eap->ex_numsecflavors = numsecflavors;
3039 LOGDEBUG("do_mount numsec=%d", numsecflavors);
3040 for (i = 0; i < eap->ex_numsecflavors; i++)
3041 eap->ex_secflavors[i] = secflavors[i];
3042 if (eap->ex_numsecflavors == 0) {
3043 eap->ex_numsecflavors = 1;
3044 eap->ex_secflavors[0] = AUTH_SYS;
3048 if (v4root_phase == 0) {
3049 build_iovec(&iov, &iovlen, "fstype", NULL, 0);
3050 build_iovec(&iov, &iovlen, "fspath", NULL, 0);
3051 build_iovec(&iov, &iovlen, "from", NULL, 0);
3052 build_iovec(&iov, &iovlen, "update", NULL, 0);
3053 build_iovec(&iov, &iovlen, "export", eap,
3054 sizeof (struct export_args));
3055 build_iovec(&iov, &iovlen, "errmsg", errmsg, sizeof(errmsg));
3059 switch (grp->gr_type) {
3061 if (ai->ai_addr->sa_family == AF_INET6 && have_v6 == 0)
3063 eap->ex_addr = ai->ai_addr;
3064 eap->ex_addrlen = ai->ai_addrlen;
3065 eap->ex_masklen = 0;
3068 if (grp->gr_ptr.gt_net.nt_net.ss_family == AF_INET6 &&
3072 (struct sockaddr *)&grp->gr_ptr.gt_net.nt_net;
3074 ((struct sockaddr *)&grp->gr_ptr.gt_net.nt_net)->sa_len;
3076 (struct sockaddr *)&grp->gr_ptr.gt_net.nt_mask;
3077 eap->ex_masklen = ((struct sockaddr *)&grp->gr_ptr.gt_net.nt_mask)->sa_len;
3080 eap->ex_addr = NULL;
3081 eap->ex_addrlen = 0;
3082 eap->ex_mask = NULL;
3083 eap->ex_masklen = 0;
3090 syslog(LOG_ERR, "bad grouptype");
3098 * For V4:, use the nfssvc() syscall, instead of mount().
3100 if (v4root_phase == 2) {
3101 nfsea.fspec = v4root_dirpath;
3102 if (nfssvc(NFSSVC_V4ROOTEXPORT | NFSSVC_NEWSTRUCT,
3103 (caddr_t)&nfsea) < 0) {
3104 syslog(LOG_ERR, "Exporting V4: failed");
3111 * Maybe I should just use the fsb->f_mntonname path
3112 * instead of looping back up the dirp to the mount
3114 * Also, needs to know how to export all types of local
3115 * exportable filesystems and not just "ufs".
3117 iov[1].iov_base = fsb->f_fstypename; /* "fstype" */
3118 iov[1].iov_len = strlen(fsb->f_fstypename) + 1;
3119 iov[3].iov_base = fsb->f_mntonname; /* "fspath" */
3120 iov[3].iov_len = strlen(fsb->f_mntonname) + 1;
3121 iov[5].iov_base = fsb->f_mntfromname; /* "from" */
3122 iov[5].iov_len = strlen(fsb->f_mntfromname) + 1;
3125 while (nmount(iov, iovlen, fsb->f_flags) < 0) {
3129 cp = dirp + dirplen - 1;
3130 if (opt_flags & OP_QUIET) {
3134 if (errno == EPERM) {
3136 warnx("can't change attributes for %s: %s",
3139 "can't change attributes for %s: %s",
3144 if (opt_flags & OP_ALLDIRS) {
3145 if (errno == EINVAL)
3147 "-alldirs requested but %s is not a filesystem mountpoint",
3151 "could not remount %s: %m",
3156 /* back up over the last component */
3157 while (*cp == '/' && cp > dirp)
3159 while (*(cp - 1) != '/' && cp > dirp)
3163 warnx("mnt unsucc");
3164 syslog(LOG_ERR, "can't export %s %s",
3172 * Check that we're still on the same
3175 if (statfs(dirp, &fsb1) != 0 ||
3176 fsidcmp(&fsb1.f_fsid, &fsb->f_fsid) != 0) {
3179 "can't export %s %s", dirp,
3188 * For the experimental server:
3189 * If this is the public directory, get the file handle
3190 * and load it into the kernel via the nfssvc() syscall.
3192 if ((exflags & MNT_EXPUBLIC) != 0) {
3196 if (eap->ex_indexfile != NULL)
3197 public_name = eap->ex_indexfile;
3200 if (getfh(public_name, &fh) < 0)
3202 "Can't get public fh for %s", public_name);
3203 else if (nfssvc(NFSSVC_PUBLICFH, (caddr_t)&fh) < 0)
3205 "Can't set public fh for %s", public_name);
3208 has_set_publicfh = 1;
3209 ep->ex_flag |= EX_PUBLICFH;
3221 free(eap->ex_groups);
3222 /* free strings allocated by strdup() in getmntopts.c */
3224 free(iov[0].iov_base); /* fstype */
3225 free(iov[2].iov_base); /* fspath */
3226 free(iov[4].iov_base); /* from */
3227 free(iov[6].iov_base); /* update */
3228 free(iov[8].iov_base); /* export */
3229 free(iov[10].iov_base); /* errmsg */
3231 /* free iov, allocated by realloc() */
3238 * Translate a net address.
3240 * If `maskflg' is nonzero, then `cp' is a netmask, not a network address.
3243 get_net(char *cp, struct netmsk *net, int maskflg)
3245 struct netent *np = NULL;
3246 char *name, *p, *prefp;
3247 struct sockaddr_in sin;
3248 struct sockaddr *sa = NULL;
3249 struct addrinfo hints, *ai = NULL;
3250 char netname[NI_MAXHOST];
3254 if ((opt_flags & OP_MASKLEN) && !maskflg) {
3255 p = strchr(cp, '/');
3261 * Check for a numeric address first. We wish to avoid
3262 * possible DNS lookups in getnetbyname().
3264 if (isxdigit(*cp) || *cp == ':') {
3265 memset(&hints, 0, sizeof hints);
3266 /* Ensure the mask and the network have the same family. */
3267 if (maskflg && (opt_flags & OP_NET))
3268 hints.ai_family = net->nt_net.ss_family;
3269 else if (!maskflg && (opt_flags & OP_HAVEMASK))
3270 hints.ai_family = net->nt_mask.ss_family;
3272 hints.ai_family = AF_UNSPEC;
3273 hints.ai_flags = AI_NUMERICHOST;
3274 if (getaddrinfo(cp, NULL, &hints, &ai) == 0)
3276 if (sa != NULL && ai->ai_family == AF_INET) {
3278 * The address in `cp' is really a network address, so
3279 * use inet_network() to re-interpret this correctly.
3280 * e.g. "127.1" means 127.1.0.0, not 127.0.0.1.
3282 bzero(&sin, sizeof sin);
3283 sin.sin_family = AF_INET;
3284 sin.sin_len = sizeof sin;
3285 sin.sin_addr = inet_makeaddr(inet_network(cp), 0);
3287 fprintf(stderr, "get_net: v4 addr %s\n",
3288 inet_ntoa(sin.sin_addr));
3289 sa = (struct sockaddr *)&sin;
3292 if (sa == NULL && (np = getnetbyname(cp)) != NULL) {
3293 bzero(&sin, sizeof sin);
3294 sin.sin_family = AF_INET;
3295 sin.sin_len = sizeof sin;
3296 sin.sin_addr = inet_makeaddr(np->n_net, 0);
3297 sa = (struct sockaddr *)&sin;
3303 /* The specified sockaddr is a mask. */
3304 if (checkmask(sa) != 0)
3306 bcopy(sa, &net->nt_mask, sa->sa_len);
3307 opt_flags |= OP_HAVEMASK;
3309 /* The specified sockaddr is a network address. */
3310 bcopy(sa, &net->nt_net, sa->sa_len);
3312 /* Get a network name for the export list. */
3315 } else if (getnameinfo(sa, sa->sa_len, netname, sizeof netname,
3316 NULL, 0, NI_NUMERICHOST) == 0) {
3321 if ((net->nt_name = strdup(name)) == NULL)
3325 * Extract a mask from either a "/<masklen>" suffix, or
3326 * from the class of an IPv4 address.
3328 if (opt_flags & OP_MASKLEN) {
3329 preflen = strtol(prefp, NULL, 10);
3330 if (preflen < 0L || preflen == LONG_MAX)
3332 bcopy(sa, &net->nt_mask, sa->sa_len);
3333 if (makemask(&net->nt_mask, (int)preflen) != 0)
3335 opt_flags |= OP_HAVEMASK;
3337 } else if (sa->sa_family == AF_INET &&
3338 (opt_flags & OP_MASK) == 0) {
3341 addr = ((struct sockaddr_in *)sa)->sin_addr.s_addr;
3342 if (IN_CLASSA(addr))
3344 else if (IN_CLASSB(addr))
3346 else if (IN_CLASSC(addr))
3348 else if (IN_CLASSD(addr))
3351 preflen = 32; /* XXX */
3353 bcopy(sa, &net->nt_mask, sa->sa_len);
3354 makemask(&net->nt_mask, (int)preflen);
3355 opt_flags |= OP_HAVEMASK;
3370 * Parse out the next white space separated field
3373 nextfield(char **cp, char **endcp)
3379 while (*p == ' ' || *p == '\t')
3382 while (*p != '\0') {
3387 if (*p == '\\' && *(p + 1) != '\0')
3389 else if (*p == '\'' || *p == '"')
3391 else if (*p == ' ' || *p == '\t')
3400 * Get an exports file line. Skip over blank lines and handle line
3408 int totlen, cont_line;
3411 * Loop around ignoring blank lines and getting all continuation lines.
3416 if ((p = fgetln(exp_file, &len)) == NULL)
3421 (*cp == ' ' || *cp == '\t' || *cp == '\n' || *cp == '\\')) {
3431 if (linesize < len + totlen + 1) {
3432 linesize = len + totlen + 1;
3433 line = realloc(line, linesize);
3437 memcpy(line + totlen, p, len);
3439 line[totlen] = '\0';
3440 } while (totlen == 0 || cont_line);
3445 * Parse a description of a credential.
3448 parsecred(char *namelist, struct expcred *cr)
3457 * Set up the unprivileged user.
3460 cr->cr_groups[0] = 65533;
3463 * Get the user's password table entry.
3466 name = strsep_quote(&names, ":");
3467 /* Bug? name could be NULL here */
3468 if (isdigit(*name) || *name == '-')
3469 pw = getpwuid(atoi(name));
3471 pw = getpwnam(name);
3473 * Credentials specified as those of a user.
3475 if (names == NULL) {
3477 syslog(LOG_ERR, "unknown user: %s", name);
3480 cr->cr_uid = pw->pw_uid;
3481 cr->cr_ngroups = NGROUPS_MAX + 1;
3482 if (getgrouplist(pw->pw_name, pw->pw_gid, cr->cr_groups,
3484 syslog(LOG_ERR, "too many groups");
3485 cr->cr_ngroups = NGROUPS_MAX + 1;
3489 * Compress out duplicate.
3491 if (cr->cr_ngroups > 1 && cr->cr_groups[0] ==
3493 for (cnt = 2; cnt < cr->cr_ngroups; cnt++)
3494 cr->cr_groups[cnt - 1] = cr->cr_groups[cnt];
3497 if (cr->cr_ngroups > NGROUPS_MAX)
3498 cr->cr_ngroups = NGROUPS_MAX;
3502 * Explicit credential specified as a colon separated list:
3506 cr->cr_uid = pw->pw_uid;
3507 else if (isdigit(*name) || *name == '-')
3508 cr->cr_uid = atoi(name);
3510 syslog(LOG_ERR, "unknown user: %s", name);
3514 while (names != NULL && *names != '\0' && cr->cr_ngroups < NGROUPS_MAX) {
3515 name = strsep_quote(&names, ":");
3516 if (isdigit(*name) || *name == '-') {
3517 cr->cr_groups[cr->cr_ngroups++] = atoi(name);
3519 if ((gr = getgrnam(name)) == NULL) {
3520 syslog(LOG_ERR, "unknown group: %s", name);
3523 cr->cr_groups[cr->cr_ngroups++] = gr->gr_gid;
3526 if (names != NULL && *names != '\0' && cr->cr_ngroups == NGROUPS_MAX)
3527 syslog(LOG_ERR, "too many groups");
3530 #define STRSIZ (MNTNAMLEN+MNTPATHLEN+50)
3532 * Routines that maintain the remote mounttab
3537 struct mountlist *mlp;
3538 char *host, *dirp, *cp;
3542 if ((mlfile = fopen(_PATH_RMOUNTLIST, "r")) == NULL) {
3543 if (errno == ENOENT)
3546 syslog(LOG_ERR, "can't open %s", _PATH_RMOUNTLIST);
3550 while (fgets(str, STRSIZ, mlfile) != NULL) {
3552 host = strsep(&cp, " \t\n");
3553 dirp = strsep(&cp, " \t\n");
3554 if (host == NULL || dirp == NULL)
3556 mlp = (struct mountlist *)malloc(sizeof (*mlp));
3557 if (mlp == (struct mountlist *)NULL)
3559 strncpy(mlp->ml_host, host, MNTNAMLEN);
3560 mlp->ml_host[MNTNAMLEN] = '\0';
3561 strncpy(mlp->ml_dirp, dirp, MNTPATHLEN);
3562 mlp->ml_dirp[MNTPATHLEN] = '\0';
3564 SLIST_INSERT_HEAD(&mlhead, mlp, next);
3570 del_mlist(char *hostp, char *dirp)
3572 struct mountlist *mlp, *mlp2;
3576 SLIST_FOREACH_SAFE(mlp, &mlhead, next, mlp2) {
3577 if (!strcmp(mlp->ml_host, hostp) &&
3578 (!dirp || !strcmp(mlp->ml_dirp, dirp))) {
3580 SLIST_REMOVE(&mlhead, mlp, mountlist, next);
3585 if ((mlfile = fopen(_PATH_RMOUNTLIST, "w")) == NULL) {
3586 syslog(LOG_ERR,"can't update %s", _PATH_RMOUNTLIST);
3589 SLIST_FOREACH(mlp, &mlhead, next) {
3590 fprintf(mlfile, "%s %s\n", mlp->ml_host, mlp->ml_dirp);
3597 add_mlist(char *hostp, char *dirp)
3599 struct mountlist *mlp;
3602 SLIST_FOREACH(mlp, &mlhead, next) {
3603 if (!strcmp(mlp->ml_host, hostp) && !strcmp(mlp->ml_dirp, dirp))
3607 mlp = (struct mountlist *)malloc(sizeof (*mlp));
3608 if (mlp == (struct mountlist *)NULL)
3610 strncpy(mlp->ml_host, hostp, MNTNAMLEN);
3611 mlp->ml_host[MNTNAMLEN] = '\0';
3612 strncpy(mlp->ml_dirp, dirp, MNTPATHLEN);
3613 mlp->ml_dirp[MNTPATHLEN] = '\0';
3614 SLIST_INSERT_HEAD(&mlhead, mlp, next);
3615 if ((mlfile = fopen(_PATH_RMOUNTLIST, "a")) == NULL) {
3616 syslog(LOG_ERR, "can't update %s", _PATH_RMOUNTLIST);
3619 fprintf(mlfile, "%s %s\n", mlp->ml_host, mlp->ml_dirp);
3624 * Free up a group list.
3627 free_grp(struct grouplist *grp)
3629 if (grp->gr_type == GT_HOST) {
3630 if (grp->gr_ptr.gt_addrinfo != NULL)
3631 freeaddrinfo(grp->gr_ptr.gt_addrinfo);
3632 } else if (grp->gr_type == GT_NET) {
3633 if (grp->gr_ptr.gt_net.nt_name)
3634 free(grp->gr_ptr.gt_net.nt_name);
3641 SYSLOG(int pri, const char *fmt, ...)
3646 vfprintf(stderr, fmt, ap);
3652 * Check options for consistency.
3655 check_options(struct dirlist *dp)
3658 if (v4root_phase == 0 && dp == NULL)
3660 if ((opt_flags & (OP_MAPROOT | OP_MAPALL)) == (OP_MAPROOT | OP_MAPALL)) {
3661 syslog(LOG_ERR, "-mapall and -maproot mutually exclusive");
3664 if ((opt_flags & OP_MASK) && (opt_flags & OP_NET) == 0) {
3665 syslog(LOG_ERR, "-mask requires -network");
3668 if ((opt_flags & OP_NET) && (opt_flags & OP_HAVEMASK) == 0) {
3669 syslog(LOG_ERR, "-network requires mask specification");
3672 if ((opt_flags & OP_MASK) && (opt_flags & OP_MASKLEN)) {
3673 syslog(LOG_ERR, "-mask and /masklen are mutually exclusive");
3676 if (v4root_phase > 0 &&
3678 ~(OP_SEC | OP_MASK | OP_NET | OP_HAVEMASK | OP_MASKLEN)) != 0) {
3679 syslog(LOG_ERR,"only -sec,-net,-mask options allowed on V4:");
3682 if ((opt_flags & OP_ALLDIRS) && dp->dp_left) {
3683 syslog(LOG_ERR, "-alldirs has multiple directories");
3690 * Check an absolute directory path for any symbolic links. Return true
3693 check_dirpath(char *dirp)
3700 while (*cp && ret) {
3703 if (lstat(dirp, &sb) < 0 || !S_ISDIR(sb.st_mode))
3709 if (lstat(dirp, &sb) < 0 || !S_ISDIR(sb.st_mode))
3715 * Make a netmask according to the specified prefix length. The ss_family
3716 * and other non-address fields must be initialised before calling this.
3719 makemask(struct sockaddr_storage *ssp, int bitlen)
3724 if ((p = sa_rawaddr((struct sockaddr *)ssp, &len)) == NULL)
3726 if (bitlen > len * CHAR_BIT)
3729 for (i = 0; i < len; i++) {
3730 bits = MIN(CHAR_BIT, bitlen);
3731 *p++ = (u_char)~0 << (CHAR_BIT - bits);
3738 * Check that the sockaddr is a valid netmask. Returns 0 if the mask
3739 * is acceptable (i.e. of the form 1...10....0).
3742 checkmask(struct sockaddr *sa)
3747 if ((mask = sa_rawaddr(sa, &len)) == NULL)
3750 for (i = 0; i < len; i++)
3751 if (mask[i] != 0xff)
3754 if (~mask[i] & (u_char)(~mask[i] + 1))
3758 for (; i < len; i++)
3765 * Compare two sockaddrs according to a specified mask. Return zero if
3766 * `sa1' matches `sa2' when filtered by the netmask in `samask'.
3767 * If samask is NULL, perform a full comparison.
3770 sacmp(struct sockaddr *sa1, struct sockaddr *sa2, struct sockaddr *samask)
3772 unsigned char *p1, *p2, *mask;
3775 if (sa1->sa_family != sa2->sa_family ||
3776 (p1 = sa_rawaddr(sa1, &len)) == NULL ||
3777 (p2 = sa_rawaddr(sa2, NULL)) == NULL)
3780 switch (sa1->sa_family) {
3782 if (((struct sockaddr_in6 *)sa1)->sin6_scope_id !=
3783 ((struct sockaddr_in6 *)sa2)->sin6_scope_id)
3788 /* Simple binary comparison if no mask specified. */
3790 return (memcmp(p1, p2, len));
3792 /* Set up the mask, and do a mask-based comparison. */
3793 if (sa1->sa_family != samask->sa_family ||
3794 (mask = sa_rawaddr(samask, NULL)) == NULL)
3797 for (i = 0; i < len; i++)
3798 if ((p1[i] & mask[i]) != (p2[i] & mask[i]))
3804 * Return a pointer to the part of the sockaddr that contains the
3805 * raw address, and set *nbytes to its length in bytes. Returns
3806 * NULL if the address family is unknown.
3809 sa_rawaddr(struct sockaddr *sa, int *nbytes) {
3813 switch (sa->sa_family) {
3815 len = sizeof(((struct sockaddr_in *)sa)->sin_addr);
3816 p = &((struct sockaddr_in *)sa)->sin_addr;
3819 len = sizeof(((struct sockaddr_in6 *)sa)->sin6_addr);
3820 p = &((struct sockaddr_in6 *)sa)->sin6_addr;
3833 huphandler(int sig __unused)
3840 terminate(int sig __unused)
3842 pidfile_remove(pfh);
3843 rpcb_unset(MOUNTPROG, MOUNTVERS, NULL);
3844 rpcb_unset(MOUNTPROG, MOUNTVERS3, NULL);
3849 cp_cred(struct expcred *outcr, struct expcred *incr)
3852 outcr->cr_uid = incr->cr_uid;
3853 outcr->cr_ngroups = incr->cr_ngroups;
3854 memcpy(outcr->cr_groups, incr->cr_groups, incr->cr_ngroups *