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>
52 #include <sys/fcntl.h>
53 #include <sys/fnv_hash.h>
54 #include <sys/linker.h>
55 #include <sys/module.h>
56 #include <sys/mount.h>
57 #include <sys/queue.h>
59 #include <sys/sysctl.h>
60 #include <sys/syslog.h>
63 #include <rpc/rpc_com.h>
64 #include <rpc/pmap_clnt.h>
65 #include <rpc/pmap_prot.h>
66 #include <rpcsvc/mount.h>
67 #include <nfs/nfsproto.h>
68 #include <nfs/nfssvc.h>
69 #include <nfsserver/nfs.h>
71 #include <fs/nfs/nfsport.h>
73 #include <arpa/inet.h>
88 #include "pathnames.h"
96 * Structures for keeping the mount list and export list
99 char ml_host[MNTNAMLEN+1];
100 char ml_dirp[MNTPATHLEN+1];
102 SLIST_ENTRY(mountlist) next;
106 struct dirlist *dp_left;
107 struct dirlist *dp_right;
109 struct hostlist *dp_hosts; /* List of hosts this dir exported to */
113 #define DP_DEFSET 0x1
114 #define DP_HOSTSET 0x2
117 * maproot/mapall credentials.
122 gid_t cr_groups[NGROUPS_MAX + 1];
126 struct dirlist *ex_dirl;
127 struct dirlist *ex_defdir;
128 struct grouplist *ex_grphead;
133 struct expcred ex_defanon;
134 uint64_t ex_defexflags;
135 int ex_numsecflavors;
136 int ex_secflavors[MAXSECFLAVORS];
137 int ex_defnumsecflavors;
138 int ex_defsecflavors[MAXSECFLAVORS];
140 SLIST_ENTRY(exportlist) entries;
143 #define EX_LINKED 0x1
145 #define EX_DEFSET 0x4
146 #define EX_PUBLICFH 0x8
148 SLIST_HEAD(exportlisthead, exportlist);
151 struct sockaddr_storage nt_net;
152 struct sockaddr_storage nt_mask;
157 struct addrinfo *gt_addrinfo;
158 struct netmsk gt_net;
163 union grouptypes gr_ptr;
164 struct grouplist *gr_next;
165 struct expcred gr_anon;
168 int gr_numsecflavors;
169 int gr_secflavors[MAXSECFLAVORS];
175 #define GT_DEFAULT 0x3
176 #define GT_IGNORE 0x5
182 int ht_flag; /* Uses DP_xx bits */
183 struct grouplist *ht_grp;
184 struct hostlist *ht_next;
191 int fhr_numsecflavors;
195 #define GETPORT_MAXTRY 20 /* Max tries to get a port # */
198 * How long to delay a reload of exports when there are RPC request(s)
199 * to process, in usec. Must be less than 1second.
201 #define RELOADDELAY 250000
204 static char *add_expdir(struct dirlist **, char *, int);
205 static void add_dlist(struct dirlist **, struct dirlist *,
206 struct grouplist *, int, struct exportlist *,
207 struct expcred *, uint64_t);
208 static void add_mlist(char *, char *);
209 static int check_dirpath(char *);
210 static int check_options(struct dirlist *);
211 static int checkmask(struct sockaddr *sa);
212 static int chk_host(struct dirlist *, struct sockaddr *, int *, int *,
214 static char *strsep_quote(char **stringp, const char *delim);
215 static int create_service(struct netconfig *nconf);
216 static void complete_service(struct netconfig *nconf, char *port_str);
217 static void clearout_service(void);
218 static void del_mlist(char *hostp, char *dirp);
219 static struct dirlist *dirp_search(struct dirlist *, char *);
220 static int do_export_mount(struct exportlist *, struct statfs *);
221 static int do_mount(struct exportlist *, struct grouplist *, uint64_t,
222 struct expcred *, char *, int, struct statfs *, int, int *);
223 static int do_opt(char **, char **, struct exportlist *,
224 struct grouplist *, int *, uint64_t *, struct expcred *);
225 static struct exportlist *ex_search(fsid_t *, struct exportlisthead *);
226 static struct exportlist *get_exp(void);
227 static void free_dir(struct dirlist *);
228 static void free_exp(struct exportlist *);
229 static void free_grp(struct grouplist *);
230 static void free_host(struct hostlist *);
231 static void free_v4rootexp(void);
232 static void get_exportlist_one(int);
233 static void get_exportlist(int);
234 static void insert_exports(struct exportlist *, struct exportlisthead *);
235 static void free_exports(struct exportlisthead *);
236 static void read_exportfile(int);
237 static int compare_nmount_exportlist(struct iovec *, int, char *);
238 static int compare_export(struct exportlist *, struct exportlist *);
239 static int compare_cred(struct expcred *, struct expcred *);
240 static int compare_secflavor(int *, int *, int);
241 static void delete_export(struct iovec *, int, struct statfs *, char *);
242 static int get_host(char *, struct grouplist *, struct grouplist *);
243 static struct hostlist *get_ht(void);
244 static int get_line(void);
245 static void get_mountlist(void);
246 static int get_net(char *, struct netmsk *, int);
247 static void getexp_err(struct exportlist *, struct grouplist *, const char *);
248 static struct grouplist *get_grp(void);
249 static void hang_dirp(struct dirlist *, struct grouplist *,
250 struct exportlist *, int, struct expcred *, uint64_t);
251 static void huphandler(int sig);
252 static int makemask(struct sockaddr_storage *ssp, int bitlen);
253 static void mntsrv(struct svc_req *, SVCXPRT *);
254 static void nextfield(char **, char **);
255 static void out_of_mem(void);
256 static void parsecred(char *, struct expcred *);
257 static int parsesec(char *, struct exportlist *);
258 static int put_exlist(struct dirlist *, XDR *, struct dirlist *,
260 static void *sa_rawaddr(struct sockaddr *sa, int *nbytes);
261 static int sacmp(struct sockaddr *sa1, struct sockaddr *sa2,
262 struct sockaddr *samask);
263 static int scan_tree(struct dirlist *, struct sockaddr *);
264 static void usage(void);
265 static int xdr_dir(XDR *, char *);
266 static int xdr_explist(XDR *, caddr_t);
267 static int xdr_explist_brief(XDR *, caddr_t);
268 static int xdr_explist_common(XDR *, caddr_t, int);
269 static int xdr_fhs(XDR *, caddr_t);
270 static int xdr_mlist(XDR *, caddr_t);
271 static void terminate(int);
272 static void cp_cred(struct expcred *, struct expcred *);
274 #define EXPHASH(f) (fnv_32_buf((f), sizeof(fsid_t), 0) % exphashsize)
275 static struct exportlisthead *exphead = NULL;
276 static struct exportlisthead *oldexphead = NULL;
277 static int exphashsize = 0;
278 static SLIST_HEAD(, mountlist) mlhead = SLIST_HEAD_INITIALIZER(&mlhead);
279 static char *exnames_default[2] = { _PATH_EXPORTS, NULL };
280 static char **exnames;
281 static char **hosts = NULL;
282 static int force_v2 = 0;
283 static int resvport_only = 1;
284 static int nhosts = 0;
285 static int dir_only = 1;
286 static int dolog = 0;
287 static int got_sighup = 0;
288 static int xcreated = 0;
290 static char *svcport_str = NULL;
291 static int mallocd_svcport = 0;
293 static int sock_fdcnt;
294 static int sock_fdpos;
295 static int suspend_nfsd = 0;
297 static int opt_flags;
298 static int have_v6 = 1;
300 static int v4root_phase = 0;
301 static char v4root_dirpath[PATH_MAX + 1];
302 static struct exportlist *v4root_ep = NULL;
303 static int has_publicfh = 0;
304 static int has_set_publicfh = 0;
306 static struct pidfh *pfh = NULL;
307 /* Bits for opt_flags above */
308 #define OP_MAPROOT 0x01
309 #define OP_MAPALL 0x02
313 #define OP_ALLDIRS 0x40
314 #define OP_HAVEMASK 0x80 /* A mask was specified or inferred. */
315 #define OP_QUIET 0x100
316 #define OP_MASKLEN 0x200
320 static int debug = 1;
321 static void SYSLOG(int, const char *, ...) __printflike(2, 3);
322 #define syslog SYSLOG
324 static int debug = 0;
328 * The LOGDEBUG() syslog() calls are always compiled into the daemon.
329 * To enable them, create a file at _PATH_MOUNTDDEBUG. This file can be empty.
330 * To disable the logging, just delete the file at _PATH_MOUNTDDEBUG.
332 static int logdebug = 0;
333 #define LOGDEBUG(format, ...) \
334 (logdebug ? syslog(LOG_DEBUG, format, ## __VA_ARGS__) : 0)
337 * Similar to strsep(), but it allows for quoted strings
338 * and escaped characters.
340 * It returns the string (or NULL, if *stringp is NULL),
341 * which is a de-quoted version of the string if necessary.
343 * It modifies *stringp in place.
346 strsep_quote(char **stringp, const char *delim)
348 char *srcptr, *dstptr, *retval;
351 if (stringp == NULL || *stringp == NULL)
354 srcptr = dstptr = retval = *stringp;
358 * We're looking for several edge cases here.
359 * First: if we're in quote state (quot != 0),
360 * then we ignore the delim characters, but otherwise
361 * process as normal, unless it is the quote character.
362 * Second: if the current character is a backslash,
363 * we take the next character as-is, without checking
364 * for delim, quote, or backslash. Exception: if the
365 * next character is a NUL, that's the end of the string.
366 * Third: if the character is a quote character, we toggle
368 * Otherwise: check the current character for NUL, or
369 * being in delim, and end the string if either is true.
371 if (*srcptr == '\\') {
374 * The edge case here is if the next character
375 * is NUL, we want to stop processing. But if
376 * it's not NUL, then we simply want to copy it.
379 *dstptr++ = *srcptr++;
383 if (quot == 0 && (*srcptr == '\'' || *srcptr == '"')) {
387 if (quot && *srcptr == quot) {
388 /* End of the quoted part */
393 if (!quot && strchr(delim, *srcptr))
395 *dstptr++ = *srcptr++;
398 *stringp = (*srcptr == '\0') ? NULL : srcptr + 1;
399 *dstptr = 0; /* Terminate the string */
404 * Mountd server for NFS mount protocol as described in:
405 * NFS: Network File System Protocol Specification, RFC1094, Appendix A
406 * The optional arguments are the exports file name
407 * default: _PATH_EXPORTS
408 * and "-n" to allow nonroot mount.
411 main(int argc, char **argv)
414 struct netconfig *nconf;
415 char *endptr, **hosts_bak;
420 int maxrec = RPC_MAXDATASIZE;
421 int attempt_cnt, port_len, port_pos, ret;
423 uint64_t curtime, nexttime;
426 sigset_t sighup_mask;
428 /* Check that another mountd isn't already running. */
429 pfh = pidfile_open(_PATH_MOUNTDPID, 0600, &otherpid);
432 errx(1, "mountd already running, pid: %d.", otherpid);
433 warn("cannot open or create pidfile");
436 s = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
442 while ((c = getopt(argc, argv, "2deh:lnp:rS")) != -1)
448 /* now a no-op, since this is the default */
457 debug = debug ? 0 : 1;
464 svcport = (in_port_t)strtoul(optarg, &endptr, 10);
465 if (endptr == NULL || *endptr != '\0' ||
466 svcport == 0 || svcport >= IPPORT_MAX)
468 svcport_str = strdup(optarg);
473 hosts_bak = realloc(hosts, nhosts * sizeof(char *));
474 if (hosts_bak == NULL) {
476 for (k = 0; k < nhosts; k++)
483 hosts[nhosts - 1] = strdup(optarg);
484 if (hosts[nhosts - 1] == NULL) {
485 for (k = 0; k < (nhosts - 1); k++)
498 if (modfind("nfsd") < 0) {
499 /* Not present in kernel, try loading it */
500 if (kldload("nfsd") < 0 || modfind("nfsd") < 0)
501 errx(1, "NFS server is not available");
509 exnames = exnames_default;
510 openlog("mountd", LOG_PID, LOG_DAEMON);
512 warnx("getting export list");
515 warnx("getting mount list");
521 signal(SIGINT, SIG_IGN);
522 signal(SIGQUIT, SIG_IGN);
524 signal(SIGHUP, huphandler);
525 signal(SIGTERM, terminate);
526 signal(SIGPIPE, SIG_IGN);
530 rpcb_unset(MOUNTPROG, MOUNTVERS, NULL);
531 rpcb_unset(MOUNTPROG, MOUNTVERS3, NULL);
532 rpc_control(RPC_SVC_CONNMAXREC_SET, &maxrec);
534 if (!resvport_only) {
535 if (sysctlbyname("vfs.nfsd.nfs_privport", NULL, NULL,
536 &resvport_only, sizeof(resvport_only)) != 0 &&
538 syslog(LOG_ERR, "sysctl: %m");
544 * If no hosts were specified, add a wildcard entry to bind to
545 * INADDR_ANY. Otherwise make sure 127.0.0.1 and ::1 are added to the
549 hosts = malloc(sizeof(char *));
557 hosts_bak = realloc(hosts, (nhosts + 2) *
559 if (hosts_bak == NULL) {
560 for (k = 0; k < nhosts; k++)
567 hosts[nhosts - 2] = "::1";
569 hosts_bak = realloc(hosts, (nhosts + 1) * sizeof(char *));
570 if (hosts_bak == NULL) {
571 for (k = 0; k < nhosts; k++)
581 hosts[nhosts - 1] = "127.0.0.1";
589 nc_handle = setnetconfig();
590 while ((nconf = getnetconfig(nc_handle))) {
591 if (nconf->nc_flag & NC_VISIBLE) {
592 if (have_v6 == 0 && strcmp(nconf->nc_protofmly,
596 ret = create_service(nconf);
598 /* Ignore this call */
602 * Failed to bind port, so close off
603 * all sockets created and try again
604 * if the port# was dynamically
605 * assigned via bind(2).
608 if (mallocd_svcport != 0 &&
609 attempt_cnt < GETPORT_MAXTRY) {
616 "bindresvport_sa: %m");
620 /* Start over at the first service. */
624 nc_handle = setnetconfig();
626 } else if (mallocd_svcport != 0 &&
627 attempt_cnt == GETPORT_MAXTRY) {
629 * For the last attempt, allow
630 * different port #s for each nconf
631 * by saving the svcport_str and
632 * setting it back to NULL.
634 port_list = realloc(port_list,
635 (port_len + 1) * sizeof(char *));
636 if (port_list == NULL)
638 port_list[port_len++] = svcport_str;
647 * Successfully bound the ports, so call complete_service() to
648 * do the rest of the setup on the service(s).
652 nc_handle = setnetconfig();
653 while ((nconf = getnetconfig(nc_handle))) {
654 if (nconf->nc_flag & NC_VISIBLE) {
655 if (have_v6 == 0 && strcmp(nconf->nc_protofmly,
658 } else if (port_list != NULL) {
659 if (port_pos >= port_len) {
660 syslog(LOG_ERR, "too many port#s");
663 complete_service(nconf, port_list[port_pos++]);
665 complete_service(nconf, svcport_str);
668 endnetconfig(nc_handle);
670 if (port_list != NULL) {
671 for (port_pos = 0; port_pos < port_len; port_pos++)
672 free(port_list[port_pos]);
677 syslog(LOG_ERR, "could not create any services");
681 /* Expand svc_run() here so that we can call get_exportlist(). */
682 curtime = nexttime = 0;
683 sigemptyset(&sighup_mask);
684 sigaddset(&sighup_mask, SIGHUP);
686 clock_gettime(CLOCK_MONOTONIC, &tp);
688 curtime = curtime * 1000000 + tp.tv_nsec / 1000;
689 sigprocmask(SIG_BLOCK, &sighup_mask, NULL);
690 if (got_sighup && curtime >= nexttime) {
692 sigprocmask(SIG_UNBLOCK, &sighup_mask, NULL);
694 clock_gettime(CLOCK_MONOTONIC, &tp);
695 nexttime = tp.tv_sec;
696 nexttime = nexttime * 1000000 + tp.tv_nsec / 1000 +
699 sigprocmask(SIG_UNBLOCK, &sighup_mask, NULL);
702 * If a reload is pending, poll for received request(s),
703 * otherwise set a RELOADDELAY timeout, since a SIGHUP
704 * could be processed between the got_sighup test and
705 * the select() system call.
711 tv.tv_usec = RELOADDELAY;
713 switch (select(svc_maxfd + 1, &readfds, NULL, NULL, &tv)) {
715 if (errno == EINTR) {
716 /* Allow a reload now. */
720 syslog(LOG_ERR, "mountd died: select: %m");
723 /* Allow a reload now. */
727 svc_getreqset(&readfds);
733 * This routine creates and binds sockets on the appropriate
734 * addresses. It gets called one time for each transport.
735 * It returns 0 upon success, 1 for ingore the call and -1 to indicate
736 * bind failed with EADDRINUSE.
737 * Any file descriptors that have been created are stored in sock_fd and
738 * the total count of them is maintained in sock_fdcnt.
741 create_service(struct netconfig *nconf)
743 struct addrinfo hints, *res = NULL;
744 struct sockaddr_in *sin;
745 struct sockaddr_in6 *sin6;
746 struct __rpc_sockinfo si;
752 u_int32_t host_addr[4]; /* IPv4 or IPv6 */
755 if ((nconf->nc_semantics != NC_TPI_CLTS) &&
756 (nconf->nc_semantics != NC_TPI_COTS) &&
757 (nconf->nc_semantics != NC_TPI_COTS_ORD))
758 return (1); /* not my type */
761 * XXX - using RPC library internal functions.
763 if (!__rpc_nconf2sockinfo(nconf, &si)) {
764 syslog(LOG_ERR, "cannot get information for %s",
769 /* Get mountd's address on this transport */
770 memset(&hints, 0, sizeof hints);
771 hints.ai_family = si.si_af;
772 hints.ai_socktype = si.si_socktype;
773 hints.ai_protocol = si.si_proto;
776 * Bind to specific IPs if asked to
779 while (nhostsbak > 0) {
781 sock_fd = realloc(sock_fd, (sock_fdcnt + 1) * sizeof(int));
784 sock_fd[sock_fdcnt++] = -1; /* Set invalid for now. */
787 hints.ai_flags = AI_PASSIVE;
790 * XXX - using RPC library internal functions.
792 if ((fd = __rpc_nconf2fd(nconf)) < 0) {
794 if (errno == EAFNOSUPPORT &&
795 nconf->nc_semantics != NC_TPI_CLTS)
798 syslog(non_fatal ? LOG_DEBUG : LOG_ERR,
799 "cannot create socket for %s", nconf->nc_netid);
805 switch (hints.ai_family) {
807 if (inet_pton(AF_INET, hosts[nhostsbak],
809 hints.ai_flags |= AI_NUMERICHOST;
812 * Skip if we have an AF_INET6 address.
814 if (inet_pton(AF_INET6, hosts[nhostsbak],
822 if (inet_pton(AF_INET6, hosts[nhostsbak],
824 hints.ai_flags |= AI_NUMERICHOST;
827 * Skip if we have an AF_INET address.
829 if (inet_pton(AF_INET, hosts[nhostsbak],
837 * We're doing host-based access checks here, so don't
838 * allow v4-in-v6 to confuse things. The kernel will
839 * disable it by default on NFS sockets too.
841 if (setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &one,
844 "can't disable v4-in-v6 on IPv6 socket");
853 * If no hosts were specified, just bind to INADDR_ANY
855 if (strcmp("*", hosts[nhostsbak]) == 0) {
856 if (svcport_str == NULL) {
857 res = malloc(sizeof(struct addrinfo));
861 res->ai_flags = hints.ai_flags;
862 res->ai_family = hints.ai_family;
863 res->ai_protocol = hints.ai_protocol;
864 switch (res->ai_family) {
866 sin = malloc(sizeof(struct sockaddr_in));
869 sin->sin_family = AF_INET;
870 sin->sin_port = htons(0);
871 sin->sin_addr.s_addr = htonl(INADDR_ANY);
872 res->ai_addr = (struct sockaddr*) sin;
873 res->ai_addrlen = (socklen_t)
874 sizeof(struct sockaddr_in);
877 sin6 = malloc(sizeof(struct sockaddr_in6));
880 sin6->sin6_family = AF_INET6;
881 sin6->sin6_port = htons(0);
882 sin6->sin6_addr = in6addr_any;
883 res->ai_addr = (struct sockaddr*) sin6;
884 res->ai_addrlen = (socklen_t)
885 sizeof(struct sockaddr_in6);
888 syslog(LOG_ERR, "bad addr fam %d",
893 if ((aicode = getaddrinfo(NULL, svcport_str,
894 &hints, &res)) != 0) {
896 "cannot get local address for %s: %s",
898 gai_strerror(aicode));
904 if ((aicode = getaddrinfo(hosts[nhostsbak], svcport_str,
905 &hints, &res)) != 0) {
907 "cannot get local address for %s: %s",
908 nconf->nc_netid, gai_strerror(aicode));
915 sock_fd[sock_fdcnt - 1] = fd;
917 /* Now, attempt the bind. */
918 r = bindresvport_sa(fd, res->ai_addr);
920 if (errno == EADDRINUSE && mallocd_svcport != 0) {
921 if (mallocd_res != 0) {
928 syslog(LOG_ERR, "bindresvport_sa: %m");
932 if (svcport_str == NULL) {
933 svcport_str = malloc(NI_MAXSERV * sizeof(char));
934 if (svcport_str == NULL)
938 if (getnameinfo(res->ai_addr,
939 res->ai_addr->sa_len, NULL, NI_MAXHOST,
940 svcport_str, NI_MAXSERV * sizeof(char),
941 NI_NUMERICHOST | NI_NUMERICSERV))
942 errx(1, "Cannot get port number");
944 if (mallocd_res != 0) {
955 * Called after all the create_service() calls have succeeded, to complete
956 * the setup and registration.
959 complete_service(struct netconfig *nconf, char *port_str)
961 struct addrinfo hints, *res = NULL;
962 struct __rpc_sockinfo si;
963 struct netbuf servaddr;
964 SVCXPRT *transp = NULL;
965 int aicode, fd, nhostsbak;
968 if ((nconf->nc_semantics != NC_TPI_CLTS) &&
969 (nconf->nc_semantics != NC_TPI_COTS) &&
970 (nconf->nc_semantics != NC_TPI_COTS_ORD))
971 return; /* not my type */
974 * XXX - using RPC library internal functions.
976 if (!__rpc_nconf2sockinfo(nconf, &si)) {
977 syslog(LOG_ERR, "cannot get information for %s",
983 while (nhostsbak > 0) {
985 if (sock_fdpos >= sock_fdcnt) {
986 /* Should never happen. */
987 syslog(LOG_ERR, "Ran out of socket fd's");
990 fd = sock_fd[sock_fdpos++];
995 * Using -1 tells listen(2) to use
996 * kern.ipc.soacceptqueue for the backlog.
998 if (nconf->nc_semantics != NC_TPI_CLTS)
1001 if (nconf->nc_semantics == NC_TPI_CLTS )
1002 transp = svc_dg_create(fd, 0, 0);
1004 transp = svc_vc_create(fd, RPC_MAXDATASIZE,
1007 if (transp != (SVCXPRT *) NULL) {
1008 if (!svc_reg(transp, MOUNTPROG, MOUNTVERS, mntsrv,
1011 "can't register %s MOUNTVERS service",
1014 if (!svc_reg(transp, MOUNTPROG, MOUNTVERS3,
1017 "can't register %s MOUNTVERS3 service",
1021 syslog(LOG_WARNING, "can't create %s services",
1024 if (registered == 0) {
1026 memset(&hints, 0, sizeof hints);
1027 hints.ai_flags = AI_PASSIVE;
1028 hints.ai_family = si.si_af;
1029 hints.ai_socktype = si.si_socktype;
1030 hints.ai_protocol = si.si_proto;
1032 if ((aicode = getaddrinfo(NULL, port_str, &hints,
1034 syslog(LOG_ERR, "cannot get local address: %s",
1035 gai_strerror(aicode));
1039 servaddr.buf = malloc(res->ai_addrlen);
1040 memcpy(servaddr.buf, res->ai_addr, res->ai_addrlen);
1041 servaddr.len = res->ai_addrlen;
1043 rpcb_set(MOUNTPROG, MOUNTVERS, nconf, &servaddr);
1044 rpcb_set(MOUNTPROG, MOUNTVERS3, nconf, &servaddr);
1053 * Clear out sockets after a failure to bind one of them, so that the
1054 * cycle of socket creation/binding can start anew.
1057 clearout_service(void)
1061 for (i = 0; i < sock_fdcnt; i++) {
1062 if (sock_fd[i] >= 0) {
1063 shutdown(sock_fd[i], SHUT_RDWR);
1073 "usage: mountd [-2] [-d] [-e] [-l] [-n] [-p <port>] [-r] "
1074 "[-S] [-h <bindip>] [export_file ...]\n");
1079 * The mount rpc service
1082 mntsrv(struct svc_req *rqstp, SVCXPRT *transp)
1084 struct exportlist *ep;
1086 struct fhreturn fhr;
1089 char host[NI_MAXHOST], numerichost[NI_MAXHOST];
1090 int lookup_failed = 1;
1091 struct sockaddr *saddr;
1093 char rpcpath[MNTPATHLEN + 1], dirpath[MAXPATHLEN];
1094 int bad = 0, defset, hostset;
1095 sigset_t sighup_mask;
1096 int numsecflavors, *secflavorsp;
1098 sigemptyset(&sighup_mask);
1099 sigaddset(&sighup_mask, SIGHUP);
1100 saddr = svc_getrpccaller(transp)->buf;
1101 switch (saddr->sa_family) {
1103 sport = ntohs(((struct sockaddr_in6 *)saddr)->sin6_port);
1106 sport = ntohs(((struct sockaddr_in *)saddr)->sin_port);
1109 syslog(LOG_ERR, "request from unknown address family");
1112 switch (rqstp->rq_proc) {
1114 case MOUNTPROC_UMNT:
1115 case MOUNTPROC_UMNTALL:
1116 lookup_failed = getnameinfo(saddr, saddr->sa_len, host,
1117 sizeof host, NULL, 0, 0);
1119 getnameinfo(saddr, saddr->sa_len, numerichost,
1120 sizeof numerichost, NULL, 0, NI_NUMERICHOST);
1121 switch (rqstp->rq_proc) {
1123 if (!svc_sendreply(transp, (xdrproc_t)xdr_void, NULL))
1124 syslog(LOG_ERR, "can't send reply");
1127 if (sport >= IPPORT_RESERVED && resvport_only) {
1129 "mount request from %s from unprivileged port",
1131 svcerr_weakauth(transp);
1134 if (!svc_getargs(transp, (xdrproc_t)xdr_dir, rpcpath)) {
1135 syslog(LOG_NOTICE, "undecodable mount request from %s",
1137 svcerr_decode(transp);
1142 * Get the real pathname and make sure it is a directory
1143 * or a regular file if the -r option was specified
1146 if (realpath(rpcpath, dirpath) == NULL ||
1147 stat(dirpath, &stb) < 0 ||
1148 statfs(dirpath, &fsb) < 0) {
1149 chdir("/"); /* Just in case realpath doesn't */
1151 "mount request from %s for non existent path %s",
1152 numerichost, dirpath);
1154 warnx("stat failed on %s", dirpath);
1155 bad = ENOENT; /* We will send error reply later */
1158 !S_ISDIR(stb.st_mode) &&
1159 (dir_only || !S_ISREG(stb.st_mode))) {
1161 "mount request from %s for non-directory path %s",
1162 numerichost, dirpath);
1164 warnx("mounting non-directory %s", dirpath);
1165 bad = ENOTDIR; /* We will send error reply later */
1168 /* Check in the exports list */
1169 sigprocmask(SIG_BLOCK, &sighup_mask, NULL);
1173 ep = ex_search(&fsb.f_fsid, exphead);
1174 hostset = defset = 0;
1175 if (ep && (chk_host(ep->ex_defdir, saddr, &defset, &hostset,
1176 &numsecflavors, &secflavorsp) ||
1177 ((dp = dirp_search(ep->ex_dirl, dirpath)) &&
1178 chk_host(dp, saddr, &defset, &hostset, &numsecflavors,
1180 (defset && scan_tree(ep->ex_defdir, saddr) == 0 &&
1181 scan_tree(ep->ex_dirl, saddr) == 0))) {
1183 if (!svc_sendreply(transp, (xdrproc_t)xdr_long,
1185 syslog(LOG_ERR, "can't send reply");
1186 sigprocmask(SIG_UNBLOCK, &sighup_mask, NULL);
1189 if (hostset & DP_HOSTSET) {
1190 fhr.fhr_flag = hostset;
1191 fhr.fhr_numsecflavors = numsecflavors;
1192 fhr.fhr_secflavors = secflavorsp;
1194 fhr.fhr_flag = defset;
1195 fhr.fhr_numsecflavors = ep->ex_defnumsecflavors;
1196 fhr.fhr_secflavors = ep->ex_defsecflavors;
1198 fhr.fhr_vers = rqstp->rq_vers;
1199 /* Get the file handle */
1200 memset(&fhr.fhr_fh, 0, sizeof(nfsfh_t));
1201 if (getfh(dirpath, (fhandle_t *)&fhr.fhr_fh) < 0) {
1203 syslog(LOG_ERR, "can't get fh for %s", dirpath);
1204 if (!svc_sendreply(transp, (xdrproc_t)xdr_long,
1206 syslog(LOG_ERR, "can't send reply");
1207 sigprocmask(SIG_UNBLOCK, &sighup_mask, NULL);
1210 if (!svc_sendreply(transp, (xdrproc_t)xdr_fhs,
1212 syslog(LOG_ERR, "can't send reply");
1214 add_mlist(host, dirpath);
1216 add_mlist(numerichost, dirpath);
1218 warnx("mount successful");
1221 "mount request succeeded from %s for %s",
1222 numerichost, dirpath);
1227 "mount request denied from %s for %s",
1228 numerichost, dirpath);
1231 if (bad && !svc_sendreply(transp, (xdrproc_t)xdr_long,
1233 syslog(LOG_ERR, "can't send reply");
1234 sigprocmask(SIG_UNBLOCK, &sighup_mask, NULL);
1236 case MOUNTPROC_DUMP:
1237 if (!svc_sendreply(transp, (xdrproc_t)xdr_mlist, (caddr_t)NULL))
1238 syslog(LOG_ERR, "can't send reply");
1241 "dump request succeeded from %s",
1244 case MOUNTPROC_UMNT:
1245 if (sport >= IPPORT_RESERVED && resvport_only) {
1247 "umount request from %s from unprivileged port",
1249 svcerr_weakauth(transp);
1252 if (!svc_getargs(transp, (xdrproc_t)xdr_dir, rpcpath)) {
1253 syslog(LOG_NOTICE, "undecodable umount request from %s",
1255 svcerr_decode(transp);
1258 if (realpath(rpcpath, dirpath) == NULL) {
1259 syslog(LOG_NOTICE, "umount request from %s "
1260 "for non existent path %s",
1261 numerichost, dirpath);
1263 if (!svc_sendreply(transp, (xdrproc_t)xdr_void, (caddr_t)NULL))
1264 syslog(LOG_ERR, "can't send reply");
1266 del_mlist(host, dirpath);
1267 del_mlist(numerichost, dirpath);
1270 "umount request succeeded from %s for %s",
1271 numerichost, dirpath);
1273 case MOUNTPROC_UMNTALL:
1274 if (sport >= IPPORT_RESERVED && resvport_only) {
1276 "umountall request from %s from unprivileged port",
1278 svcerr_weakauth(transp);
1281 if (!svc_sendreply(transp, (xdrproc_t)xdr_void, (caddr_t)NULL))
1282 syslog(LOG_ERR, "can't send reply");
1284 del_mlist(host, NULL);
1285 del_mlist(numerichost, NULL);
1288 "umountall request succeeded from %s",
1291 case MOUNTPROC_EXPORT:
1292 if (!svc_sendreply(transp, (xdrproc_t)xdr_explist, (caddr_t)NULL))
1293 if (!svc_sendreply(transp, (xdrproc_t)xdr_explist_brief,
1295 syslog(LOG_ERR, "can't send reply");
1298 "export request succeeded from %s",
1302 svcerr_noproc(transp);
1308 * Xdr conversion for a dirpath string
1311 xdr_dir(XDR *xdrsp, char *dirp)
1313 return (xdr_string(xdrsp, &dirp, MNTPATHLEN));
1317 * Xdr routine to generate file handle reply
1320 xdr_fhs(XDR *xdrsp, caddr_t cp)
1322 struct fhreturn *fhrp = (struct fhreturn *)cp;
1323 u_long ok = 0, len, auth;
1326 if (!xdr_long(xdrsp, &ok))
1328 switch (fhrp->fhr_vers) {
1330 return (xdr_opaque(xdrsp, (caddr_t)&fhrp->fhr_fh, NFSX_V2FH));
1333 if (!xdr_long(xdrsp, &len))
1335 if (!xdr_opaque(xdrsp, (caddr_t)&fhrp->fhr_fh, len))
1337 if (fhrp->fhr_numsecflavors) {
1338 if (!xdr_int(xdrsp, &fhrp->fhr_numsecflavors))
1340 for (i = 0; i < fhrp->fhr_numsecflavors; i++)
1341 if (!xdr_int(xdrsp, &fhrp->fhr_secflavors[i]))
1347 if (!xdr_long(xdrsp, &len))
1349 return (xdr_long(xdrsp, &auth));
1356 xdr_mlist(XDR *xdrsp, caddr_t cp __unused)
1358 struct mountlist *mlp;
1363 SLIST_FOREACH(mlp, &mlhead, next) {
1364 if (!xdr_bool(xdrsp, &true))
1366 strp = &mlp->ml_host[0];
1367 if (!xdr_string(xdrsp, &strp, MNTNAMLEN))
1369 strp = &mlp->ml_dirp[0];
1370 if (!xdr_string(xdrsp, &strp, MNTPATHLEN))
1373 if (!xdr_bool(xdrsp, &false))
1379 * Xdr conversion for export list
1382 xdr_explist_common(XDR *xdrsp, caddr_t cp __unused, int brief)
1384 struct exportlist *ep;
1387 sigset_t sighup_mask;
1390 sigemptyset(&sighup_mask);
1391 sigaddset(&sighup_mask, SIGHUP);
1392 sigprocmask(SIG_BLOCK, &sighup_mask, NULL);
1394 for (i = 0; i < exphashsize; i++)
1395 SLIST_FOREACH(ep, &exphead[i], entries) {
1397 if (put_exlist(ep->ex_dirl, xdrsp, ep->ex_defdir,
1400 if (ep->ex_defdir && putdef == 0 &&
1401 put_exlist(ep->ex_defdir, xdrsp, NULL,
1405 sigprocmask(SIG_UNBLOCK, &sighup_mask, NULL);
1406 if (!xdr_bool(xdrsp, &false))
1410 sigprocmask(SIG_UNBLOCK, &sighup_mask, NULL);
1415 * Called from xdr_explist() to traverse the tree and export the
1419 put_exlist(struct dirlist *dp, XDR *xdrsp, struct dirlist *adp, int *putdefp,
1422 struct grouplist *grp;
1423 struct hostlist *hp;
1430 if (put_exlist(dp->dp_left, xdrsp, adp, putdefp, brief))
1432 if (!xdr_bool(xdrsp, &true))
1435 if (!xdr_string(xdrsp, &strp, MNTPATHLEN))
1437 if (adp && !strcmp(dp->dp_dirp, adp->dp_dirp)) {
1442 if (!xdr_bool(xdrsp, &true))
1445 if (!xdr_string(xdrsp, &strp, MNTPATHLEN))
1447 } else if ((dp->dp_flag & DP_DEFSET) == 0 &&
1448 (gotalldir == 0 || (adp->dp_flag & DP_DEFSET) == 0)) {
1452 if (grp->gr_type == GT_HOST) {
1453 if (!xdr_bool(xdrsp, &true))
1455 strp = grp->gr_ptr.gt_addrinfo->ai_canonname;
1456 if (!xdr_string(xdrsp, &strp,
1459 } else if (grp->gr_type == GT_NET) {
1460 if (!xdr_bool(xdrsp, &true))
1462 strp = grp->gr_ptr.gt_net.nt_name;
1463 if (!xdr_string(xdrsp, &strp,
1468 if (gotalldir && hp == (struct hostlist *)NULL) {
1474 if (!xdr_bool(xdrsp, &false))
1476 if (put_exlist(dp->dp_right, xdrsp, adp, putdefp, brief))
1483 xdr_explist(XDR *xdrsp, caddr_t cp)
1486 return xdr_explist_common(xdrsp, cp, 0);
1490 xdr_explist_brief(XDR *xdrsp, caddr_t cp)
1493 return xdr_explist_common(xdrsp, cp, 1);
1497 static size_t linesize;
1498 static FILE *exp_file;
1501 * Get the export list from one, currently open file
1504 get_exportlist_one(int passno)
1506 struct exportlist *ep;
1507 struct grouplist *grp, *tgrp, *savgrp;
1508 struct dirlist *dirhead;
1510 struct expcred anon;
1511 char *cp, *endcp, *dirp, *hst, *usr, *dom, savedc;
1512 int len, has_host, got_nondir, dirplen, netgrp;
1516 dirhead = (struct dirlist *)NULL;
1517 while (get_line()) {
1519 warnx("got line %s", line);
1521 nextfield(&cp, &endcp);
1529 anon.cr_uid = UID_NOBODY;
1530 anon.cr_ngroups = 1;
1531 anon.cr_groups[0] = GID_NOGROUP;
1532 exflags = MNT_EXPORTED;
1535 ep = (struct exportlist *)NULL;
1539 * Handle the V4 root dir.
1541 if (*cp == 'V' && *(cp + 1) == '4' && *(cp + 2) == ':') {
1543 * V4: just indicates that it is the v4 root point,
1544 * so skip over that and set v4root_phase.
1546 if (v4root_phase > 0) {
1547 syslog(LOG_ERR, "V4:duplicate line, ignored");
1552 nextfield(&cp, &endcp);
1556 * Create new exports list entry
1559 tgrp = grp = get_grp();
1561 if (len > MNTNAMLEN) {
1562 getexp_err(ep, tgrp, "mountpoint too long");
1566 if (ep == (struct exportlist *)NULL) {
1567 getexp_err(ep, tgrp,
1568 "flag before export path definition");
1572 warnx("doing opt %s", cp);
1574 if (do_opt(&cp, &endcp, ep, grp, &has_host,
1576 getexp_err(ep, tgrp, NULL);
1579 } else if (*cp == '/') {
1582 if (v4root_phase > 1) {
1584 getexp_err(ep, tgrp, "Multiple V4 dirs");
1588 if (check_dirpath(cp) &&
1589 statfs(cp, &fsb) >= 0) {
1590 if ((fsb.f_flags & MNT_AUTOMOUNTED) != 0)
1591 syslog(LOG_ERR, "Warning: exporting of "
1592 "automounted fs %s not supported", cp);
1594 getexp_err(ep, tgrp, "dirs must be first");
1597 if (v4root_phase == 1) {
1599 getexp_err(ep, tgrp, "Multiple V4 dirs");
1602 if (strlen(v4root_dirpath) == 0) {
1603 strlcpy(v4root_dirpath, cp,
1604 sizeof (v4root_dirpath));
1605 } else if (strcmp(v4root_dirpath, cp)
1608 "different V4 dirpath %s", cp);
1609 getexp_err(ep, tgrp, NULL);
1618 if (fsidcmp(&ep->ex_fs, &fsb.f_fsid)
1620 getexp_err(ep, tgrp,
1626 * See if this directory is already
1629 ep = ex_search(&fsb.f_fsid, exphead);
1630 if (ep == (struct exportlist *)NULL) {
1632 ep->ex_fs = fsb.f_fsid;
1633 ep->ex_fsdir = strdup(fsb.f_mntonname);
1634 if (ep->ex_fsdir == NULL)
1638 "making new ep fs=0x%x,0x%x",
1642 warnx("found ep fs=0x%x,0x%x",
1648 * Add dirpath to export mount point.
1650 dirp = add_expdir(&dirhead, cp, len);
1654 getexp_err(ep, tgrp,
1655 "symbolic link in export path or statfs failed");
1663 if (ep == (struct exportlist *)NULL) {
1664 getexp_err(ep, tgrp,
1665 "host(s) before export path definition");
1670 * Get the host or netgroup.
1673 netgrp = getnetgrent(&hst, &usr, &dom);
1676 grp->gr_next = get_grp();
1682 "null hostname in netgroup %s, skipping", cp);
1683 grp->gr_type = GT_IGNORE;
1684 } else if (get_host(hst, grp, tgrp)) {
1686 "bad host %s in netgroup %s, skipping", hst, cp);
1687 grp->gr_type = GT_IGNORE;
1689 } else if (get_host(cp, grp, tgrp)) {
1690 syslog(LOG_ERR, "bad host %s, skipping", cp);
1691 grp->gr_type = GT_IGNORE;
1694 } while (netgrp && getnetgrent(&hst, &usr, &dom));
1699 nextfield(&cp, &endcp);
1702 if (check_options(dirhead)) {
1703 getexp_err(ep, tgrp, NULL);
1707 grp->gr_type = GT_DEFAULT;
1709 warnx("adding a default entry");
1712 * Don't allow a network export coincide with a list of
1713 * host(s) on the same line.
1715 } else if ((opt_flags & OP_NET) && tgrp->gr_next) {
1716 getexp_err(ep, tgrp, "network/host conflict");
1720 * If an export list was specified on this line, make sure
1721 * that we have at least one valid entry, otherwise skip it.
1725 while (grp && grp->gr_type == GT_IGNORE)
1728 getexp_err(ep, tgrp, "no valid entries");
1733 if (v4root_phase == 1) {
1734 getexp_err(ep, tgrp, "V4:root, no dirp, ignored");
1739 * Loop through hosts, pushing the exports into the kernel.
1740 * After loop, tgrp points to the start of the list and
1741 * grp points to the last entry in the list.
1742 * Do not do the do_mount() for passno == 1, since the
1743 * second pass will do it, as required.
1747 grp->gr_exflags = exflags;
1748 cp_cred(&grp->gr_anon, &anon);
1749 if (v4root_phase == 2 && passno == 0)
1750 LOGDEBUG("do_mount v4root");
1751 if (passno == 0 && do_mount(ep, grp, exflags, &anon,
1752 dirp, dirplen, &fsb, ep->ex_numsecflavors,
1753 ep->ex_secflavors)) {
1754 getexp_err(ep, tgrp, NULL);
1757 } while (grp->gr_next && (grp = grp->gr_next));
1760 * For V4: don't enter in mount lists.
1762 if (v4root_phase > 0 && v4root_phase <= 2) {
1764 * These structures are used for the reload,
1765 * so save them for that case. Otherwise, just
1768 if (passno == 1 && ep != NULL) {
1770 while (tgrp != NULL) {
1772 * Save the security flavors and exflags
1773 * for this host set in the groups.
1775 tgrp->gr_numsecflavors =
1776 ep->ex_numsecflavors;
1777 if (ep->ex_numsecflavors > 0)
1778 memcpy(tgrp->gr_secflavors,
1780 sizeof(ep->ex_secflavors));
1781 tgrp = tgrp->gr_next;
1783 if (v4root_ep == NULL) {
1785 ep = NULL; /* Don't free below. */
1787 grp->gr_next = v4root_ep->ex_grphead;
1788 v4root_ep->ex_grphead = savgrp;
1792 while (tgrp != NULL) {
1794 tgrp = tgrp->gr_next;
1801 * Success. Update the data structures.
1804 hang_dirp(dirhead, tgrp, ep, opt_flags, &anon, exflags);
1805 grp->gr_next = ep->ex_grphead;
1806 ep->ex_grphead = tgrp;
1808 hang_dirp(dirhead, (struct grouplist *)NULL, ep,
1809 opt_flags, &anon, exflags);
1812 dirhead = (struct dirlist *)NULL;
1813 if ((ep->ex_flag & EX_LINKED) == 0) {
1814 insert_exports(ep, exphead);
1816 ep->ex_flag |= EX_LINKED;
1822 dirhead = (struct dirlist *)NULL;
1828 * Get the export list from all specified files
1831 get_exportlist(int passno)
1833 struct export_args export;
1835 struct statfs *mntbufp;
1839 struct nfsex_args eargs;
1842 if ((debug_file = fopen(_PATH_MOUNTDDEBUG, "r")) != NULL) {
1847 LOGDEBUG("passno=%d", passno);
1848 v4root_dirpath[0] = '\0';
1852 * Save the current lists as old ones, so that the new lists
1853 * can be compared with the old ones in the 2nd pass.
1855 for (i = 0; i < exphashsize; i++) {
1856 SLIST_FIRST(&oldexphead[i]) = SLIST_FIRST(&exphead[i]);
1857 SLIST_INIT(&exphead[i]);
1860 /* Note that the public fh has not yet been set. */
1861 has_set_publicfh = 0;
1863 /* Read the export file(s) and process them */
1864 read_exportfile(passno);
1867 * Just make the old lists empty.
1868 * exphashsize == 0 for the first call, before oldexphead
1869 * has been initialized-->loop won't be executed.
1871 for (i = 0; i < exphashsize; i++)
1872 SLIST_INIT(&oldexphead[i]);
1875 bzero(&export, sizeof(export));
1876 export.ex_flags = MNT_DELEXPORT;
1879 bzero(errmsg, sizeof(errmsg));
1881 if (suspend_nfsd != 0)
1882 (void)nfssvc(NFSSVC_SUSPENDNFSD, NULL);
1884 * Delete the old V4 root dir.
1886 bzero(&eargs, sizeof (eargs));
1887 eargs.export.ex_flags = MNT_DELEXPORT;
1888 if (nfssvc(NFSSVC_V4ROOTEXPORT | NFSSVC_NEWSTRUCT, (caddr_t)&eargs) < 0 &&
1890 syslog(LOG_ERR, "Can't delete exports for V4:");
1892 build_iovec(&iov, &iovlen, "fstype", NULL, 0);
1893 build_iovec(&iov, &iovlen, "fspath", NULL, 0);
1894 build_iovec(&iov, &iovlen, "from", NULL, 0);
1895 build_iovec(&iov, &iovlen, "update", NULL, 0);
1896 build_iovec(&iov, &iovlen, "export", &export,
1898 build_iovec(&iov, &iovlen, "errmsg", errmsg,
1902 * For passno == 1, compare the old and new lists updating the kernel
1903 * exports for any cases that have changed.
1904 * This call is doing the second pass through the lists.
1905 * If it fails, fall back on the bulk reload.
1907 if (passno == 1 && compare_nmount_exportlist(iov, iovlen, errmsg) ==
1909 LOGDEBUG("compareok");
1910 /* Free up the old lists. */
1911 free_exports(oldexphead);
1913 LOGDEBUG("doing passno=0");
1915 * Clear flag that notes if a public fh has been exported.
1916 * It is set by do_mount() if MNT_EXPUBLIC is set for the entry.
1920 /* exphead == NULL if not yet allocated (first call). */
1921 if (exphead != NULL) {
1923 * First, get rid of the old lists.
1925 free_exports(exphead);
1926 free_exports(oldexphead);
1930 * And delete exports that are in the kernel for all local
1932 * XXX: Should know how to handle all local exportable
1935 num = getmntinfo(&mntbufp, MNT_NOWAIT);
1937 /* Allocate hash tables, for first call. */
1938 if (exphead == NULL) {
1939 /* Target an average linked list length of 10. */
1940 exphashsize = num / 10;
1941 if (exphashsize < 1)
1943 else if (exphashsize > 100000)
1944 exphashsize = 100000;
1945 exphead = malloc(exphashsize * sizeof(*exphead));
1946 oldexphead = malloc(exphashsize * sizeof(*oldexphead));
1947 if (exphead == NULL || oldexphead == NULL)
1948 errx(1, "Can't malloc hash tables");
1950 for (i = 0; i < exphashsize; i++) {
1951 SLIST_INIT(&exphead[i]);
1952 SLIST_INIT(&oldexphead[i]);
1956 for (i = 0; i < num; i++)
1957 delete_export(iov, iovlen, &mntbufp[i], errmsg);
1960 /* Read the export file(s) and process them */
1965 /* Free strings allocated by strdup() in getmntopts.c */
1966 free(iov[0].iov_base); /* fstype */
1967 free(iov[2].iov_base); /* fspath */
1968 free(iov[4].iov_base); /* from */
1969 free(iov[6].iov_base); /* update */
1970 free(iov[8].iov_base); /* export */
1971 free(iov[10].iov_base); /* errmsg */
1973 /* free iov, allocated by realloc() */
1979 * If there was no public fh, clear any previous one set.
1981 if (has_publicfh == 0) {
1982 LOGDEBUG("clear public fh");
1983 (void) nfssvc(NFSSVC_NOPUBLICFH, NULL);
1986 /* Resume the nfsd. If they weren't suspended, this is harmless. */
1987 (void)nfssvc(NFSSVC_RESUMENFSD, NULL);
1988 LOGDEBUG("eo get_exportlist");
1992 * Insert an export entry in the appropriate list.
1995 insert_exports(struct exportlist *ep, struct exportlisthead *exhp)
1999 i = EXPHASH(&ep->ex_fs);
2000 LOGDEBUG("fs=%s hash=%i", ep->ex_fsdir, i);
2001 SLIST_INSERT_HEAD(&exhp[i], ep, entries);
2005 * Free up the exports lists passed in as arguments.
2008 free_exports(struct exportlisthead *exhp)
2010 struct exportlist *ep, *ep2;
2013 for (i = 0; i < exphashsize; i++) {
2014 SLIST_FOREACH_SAFE(ep, &exhp[i], entries, ep2) {
2015 SLIST_REMOVE(&exhp[i], ep, exportlist, entries);
2018 SLIST_INIT(&exhp[i]);
2023 * Read the exports file(s) and call get_exportlist_one() for each line.
2026 read_exportfile(int passno)
2031 * Read in the exports file and build the list, calling
2032 * nmount() as we go along to push the export rules into the kernel.
2035 for (i = 0; exnames[i] != NULL; i++) {
2037 warnx("reading exports from %s", exnames[i]);
2038 if ((exp_file = fopen(exnames[i], "r")) == NULL) {
2039 syslog(LOG_WARNING, "can't open %s", exnames[i]);
2042 get_exportlist_one(passno);
2047 syslog(LOG_ERR, "can't open any exports file");
2053 * Compare the export lists against the old ones and do nmount() operations
2054 * for any cases that have changed. This avoids doing nmount() for entries
2055 * that have not changed.
2056 * Return 0 upon success, 1 otherwise.
2059 compare_nmount_exportlist(struct iovec *iov, int iovlen, char *errmsg)
2061 struct exportlist *ep, *oep;
2062 struct grouplist *grp;
2063 struct statfs fs, ofs;
2067 * Loop through the current list and look for an entry in the old
2069 * If found, check to see if it the same.
2070 * If it is not the same, delete and re-export.
2071 * Then mark it done on the old list.
2074 * Any entries left in the old list after processing must have their
2077 for (i = 0; i < exphashsize; i++)
2078 SLIST_FOREACH(ep, &exphead[i], entries) {
2079 LOGDEBUG("foreach ep=%s", ep->ex_fsdir);
2080 oep = ex_search(&ep->ex_fs, oldexphead);
2083 * Check the mount paths are the same.
2084 * If not, return 1 so that the reload of the
2085 * exports will be done in bulk, the
2088 LOGDEBUG("found old exp");
2089 if (strcmp(ep->ex_fsdir, oep->ex_fsdir) != 0)
2091 LOGDEBUG("same fsdir");
2093 * Test to see if the entry is the same.
2094 * If not the same delete exports and
2097 if (compare_export(ep, oep) != 0) {
2099 * Clear has_publicfh if if was set
2100 * in the old exports, but only if it
2101 * has not been set during processing of
2102 * the exports for this pass, as
2103 * indicated by has_set_publicfh.
2105 if (has_set_publicfh == 0 &&
2106 (oep->ex_flag & EX_PUBLICFH) != 0)
2109 /* Delete and re-export. */
2110 if (statfs(ep->ex_fsdir, &fs) < 0)
2112 delete_export(iov, iovlen, &fs, errmsg);
2113 ret = do_export_mount(ep, &fs);
2117 oep->ex_flag |= EX_DONE;
2120 LOGDEBUG("not found so export");
2121 /* Not found, so do export. */
2122 if (statfs(ep->ex_fsdir, &fs) < 0)
2124 ret = do_export_mount(ep, &fs);
2130 /* Delete exports not done. */
2131 for (i = 0; i < exphashsize; i++)
2132 SLIST_FOREACH(oep, &oldexphead[i], entries) {
2133 if ((oep->ex_flag & EX_DONE) == 0) {
2134 LOGDEBUG("not done delete=%s", oep->ex_fsdir);
2135 if (statfs(oep->ex_fsdir, &ofs) >= 0 &&
2136 fsidcmp(&oep->ex_fs, &ofs.f_fsid) == 0) {
2137 LOGDEBUG("do delete");
2139 * Clear has_publicfh if if was set
2140 * in the old exports, but only if it
2141 * has not been set during processing of
2142 * the exports for this pass, as
2143 * indicated by has_set_publicfh.
2145 if (has_set_publicfh == 0 &&
2146 (oep->ex_flag & EX_PUBLICFH) != 0)
2149 delete_export(iov, iovlen, &ofs,
2155 /* Do the V4 root exports, as required. */
2157 if (v4root_ep != NULL)
2158 grp = v4root_ep->ex_grphead;
2160 while (v4root_ep != NULL && grp != NULL) {
2161 LOGDEBUG("v4root expath=%s", v4root_dirpath);
2162 ret = do_mount(v4root_ep, grp, grp->gr_exflags, &grp->gr_anon,
2163 v4root_dirpath, strlen(v4root_dirpath), &fs,
2164 grp->gr_numsecflavors, grp->gr_secflavors);
2177 * Compare old and current exportlist entries for the fsid and return 0
2178 * if they are the same, 1 otherwise.
2181 compare_export(struct exportlist *ep, struct exportlist *oep)
2183 struct grouplist *grp, *ogrp;
2185 if (strcmp(ep->ex_fsdir, oep->ex_fsdir) != 0)
2187 if ((ep->ex_flag & EX_DEFSET) != (oep->ex_flag & EX_DEFSET))
2189 if ((ep->ex_defdir != NULL && oep->ex_defdir == NULL) ||
2190 (ep->ex_defdir == NULL && oep->ex_defdir != NULL))
2192 if (ep->ex_defdir != NULL && (ep->ex_defdir->dp_flag & DP_DEFSET) !=
2193 (oep->ex_defdir->dp_flag & DP_DEFSET))
2195 if ((ep->ex_flag & EX_DEFSET) != 0 && (ep->ex_defnumsecflavors !=
2196 oep->ex_defnumsecflavors || ep->ex_defexflags !=
2197 oep->ex_defexflags || compare_cred(&ep->ex_defanon,
2198 &oep->ex_defanon) != 0 || compare_secflavor(ep->ex_defsecflavors,
2199 oep->ex_defsecflavors, ep->ex_defnumsecflavors) != 0))
2202 /* Now, check all the groups. */
2203 for (ogrp = oep->ex_grphead; ogrp != NULL; ogrp = ogrp->gr_next)
2205 for (grp = ep->ex_grphead; grp != NULL; grp = grp->gr_next) {
2206 for (ogrp = oep->ex_grphead; ogrp != NULL; ogrp =
2208 if ((ogrp->gr_flag & GR_FND) == 0 &&
2209 grp->gr_numsecflavors == ogrp->gr_numsecflavors &&
2210 grp->gr_exflags == ogrp->gr_exflags &&
2211 compare_cred(&grp->gr_anon, &ogrp->gr_anon) == 0 &&
2212 compare_secflavor(grp->gr_secflavors,
2213 ogrp->gr_secflavors, grp->gr_numsecflavors) == 0)
2216 ogrp->gr_flag |= GR_FND;
2220 for (ogrp = oep->ex_grphead; ogrp != NULL; ogrp = ogrp->gr_next)
2221 if ((ogrp->gr_flag & GR_FND) == 0)
2227 * This algorithm compares two arrays of "n" items. It returns 0 if they are
2228 * the "same" and 1 otherwise. Although suboptimal, it is always safe to
2229 * return 1, which makes compare_nmount_export() reload the exports entry.
2230 * "same" refers to having the same set of values in the two arrays.
2231 * The arrays are in no particular order and duplicates (multiple entries
2232 * in an array with the same value) is allowed.
2233 * The algorithm is inefficient, but the common case of indentical arrays is
2234 * handled first and "n" is normally fairly small.
2235 * Since the two functions need the same algorithm but for arrays of
2236 * different types (gid_t vs int), this is done as a macro.
2238 #define COMPARE_ARRAYS(a1, a2, n) \
2240 int fnd, fndarray[(n)], i, j; \
2241 /* Handle common case of identical arrays. */ \
2242 for (i = 0; i < (n); i++) \
2243 if ((a1)[i] != (a2)[i]) \
2247 for (i = 0; i < (n); i++) \
2249 for (i = 0; i < (n); i++) { \
2251 for (j = 0; j < (n); j++) { \
2252 if ((a1)[i] == (a2)[j]) { \
2260 for (i = 0; i < (n); i++) \
2261 if (fndarray[i] == 0) \
2267 * Compare two struct expcred's. Return 0 if the same and 1 otherwise.
2270 compare_cred(struct expcred *cr0, struct expcred *cr1)
2273 if (cr0->cr_uid != cr1->cr_uid || cr0->cr_ngroups != cr1->cr_ngroups)
2276 COMPARE_ARRAYS(cr0->cr_groups, cr1->cr_groups, cr0->cr_ngroups);
2280 * Compare two lists of security flavors. Return 0 if the same and 1 otherwise.
2283 compare_secflavor(int *sec1, int *sec2, int nsec)
2286 COMPARE_ARRAYS(sec1, sec2, nsec);
2290 * Delete an exports entry.
2293 delete_export(struct iovec *iov, int iovlen, struct statfs *fsp, char *errmsg)
2295 struct xvfsconf vfc;
2297 if (getvfsbyname(fsp->f_fstypename, &vfc) != 0) {
2298 syslog(LOG_ERR, "getvfsbyname() failed for %s",
2304 * We do not need to delete "export" flag from
2305 * filesystems that do not have it set.
2307 if (!(fsp->f_flags & MNT_EXPORTED))
2310 * Do not delete export for network filesystem by
2311 * passing "export" arg to nmount().
2312 * It only makes sense to do this for local filesystems.
2314 if (vfc.vfc_flags & VFCF_NETWORK)
2317 iov[1].iov_base = fsp->f_fstypename;
2318 iov[1].iov_len = strlen(fsp->f_fstypename) + 1;
2319 iov[3].iov_base = fsp->f_mntonname;
2320 iov[3].iov_len = strlen(fsp->f_mntonname) + 1;
2321 iov[5].iov_base = fsp->f_mntfromname;
2322 iov[5].iov_len = strlen(fsp->f_mntfromname) + 1;
2326 * EXDEV is returned when path exists but is not a
2327 * mount point. May happens if raced with unmount.
2329 if (nmount(iov, iovlen, fsp->f_flags) < 0 && errno != ENOENT &&
2330 errno != ENOTSUP && errno != EXDEV) {
2332 "can't delete exports for %s: %m %s",
2333 fsp->f_mntonname, errmsg);
2338 * Allocate an export list element
2340 static struct exportlist *
2343 struct exportlist *ep;
2345 ep = (struct exportlist *)calloc(1, sizeof (struct exportlist));
2346 if (ep == (struct exportlist *)NULL)
2352 * Allocate a group list element
2354 static struct grouplist *
2357 struct grouplist *gp;
2359 gp = (struct grouplist *)calloc(1, sizeof (struct grouplist));
2360 if (gp == (struct grouplist *)NULL)
2366 * Clean up upon an error in get_exportlist().
2369 getexp_err(struct exportlist *ep, struct grouplist *grp, const char *reason)
2371 struct grouplist *tgrp;
2373 if (!(opt_flags & OP_QUIET)) {
2375 syslog(LOG_ERR, "bad exports list line '%s': %s", line,
2378 syslog(LOG_ERR, "bad exports list line '%s'", line);
2380 if (ep && (ep->ex_flag & EX_LINKED) == 0)
2390 * Search the export list for a matching fs.
2392 static struct exportlist *
2393 ex_search(fsid_t *fsid, struct exportlisthead *exhp)
2395 struct exportlist *ep;
2399 SLIST_FOREACH(ep, &exhp[i], entries) {
2400 if (fsidcmp(&ep->ex_fs, fsid) == 0)
2408 * Add a directory path to the list.
2411 add_expdir(struct dirlist **dpp, char *cp, int len)
2415 dp = malloc(sizeof (struct dirlist));
2416 if (dp == (struct dirlist *)NULL)
2419 dp->dp_right = (struct dirlist *)NULL;
2421 dp->dp_hosts = (struct hostlist *)NULL;
2422 dp->dp_dirp = strndup(cp, len);
2423 if (dp->dp_dirp == NULL)
2426 return (dp->dp_dirp);
2430 * Hang the dir list element off the dirpath binary tree as required
2431 * and update the entry for host.
2434 hang_dirp(struct dirlist *dp, struct grouplist *grp, struct exportlist *ep,
2435 int flags, struct expcred *anoncrp, uint64_t exflags)
2437 struct hostlist *hp;
2438 struct dirlist *dp2;
2440 if (flags & OP_ALLDIRS) {
2445 if (grp == (struct grouplist *)NULL) {
2446 ep->ex_flag |= EX_DEFSET;
2447 ep->ex_defdir->dp_flag |= DP_DEFSET;
2448 /* Save the default security flavors list. */
2449 ep->ex_defnumsecflavors = ep->ex_numsecflavors;
2450 if (ep->ex_numsecflavors > 0)
2451 memcpy(ep->ex_defsecflavors, ep->ex_secflavors,
2452 sizeof(ep->ex_secflavors));
2453 cp_cred(&ep->ex_defanon, anoncrp);
2454 ep->ex_defexflags = exflags;
2455 } else while (grp) {
2458 hp->ht_next = ep->ex_defdir->dp_hosts;
2459 ep->ex_defdir->dp_hosts = hp;
2460 /* Save the security flavors list for this host set. */
2461 grp->gr_numsecflavors = ep->ex_numsecflavors;
2462 if (ep->ex_numsecflavors > 0)
2463 memcpy(grp->gr_secflavors, ep->ex_secflavors,
2464 sizeof(ep->ex_secflavors));
2470 * Loop through the directories adding them to the tree.
2474 add_dlist(&ep->ex_dirl, dp, grp, flags, ep, anoncrp,
2482 * Traverse the binary tree either updating a node that is already there
2483 * for the new directory or adding the new node.
2486 add_dlist(struct dirlist **dpp, struct dirlist *newdp, struct grouplist *grp,
2487 int flags, struct exportlist *ep, struct expcred *anoncrp,
2491 struct hostlist *hp;
2496 cmp = strcmp(dp->dp_dirp, newdp->dp_dirp);
2498 add_dlist(&dp->dp_left, newdp, grp, flags, ep, anoncrp,
2501 } else if (cmp < 0) {
2502 add_dlist(&dp->dp_right, newdp, grp, flags, ep, anoncrp,
2506 free((caddr_t)newdp);
2509 dp->dp_left = (struct dirlist *)NULL;
2515 * Hang all of the host(s) off of the directory point.
2520 hp->ht_next = dp->dp_hosts;
2522 /* Save the security flavors list for this host set. */
2523 grp->gr_numsecflavors = ep->ex_numsecflavors;
2524 if (ep->ex_numsecflavors > 0)
2525 memcpy(grp->gr_secflavors, ep->ex_secflavors,
2526 sizeof(ep->ex_secflavors));
2530 ep->ex_flag |= EX_DEFSET;
2531 dp->dp_flag |= DP_DEFSET;
2532 /* Save the default security flavors list. */
2533 ep->ex_defnumsecflavors = ep->ex_numsecflavors;
2534 if (ep->ex_numsecflavors > 0)
2535 memcpy(ep->ex_defsecflavors, ep->ex_secflavors,
2536 sizeof(ep->ex_secflavors));
2537 cp_cred(&ep->ex_defanon, anoncrp);
2538 ep->ex_defexflags = exflags;
2543 * Search for a dirpath on the export point.
2545 static struct dirlist *
2546 dirp_search(struct dirlist *dp, char *dirp)
2551 cmp = strcmp(dp->dp_dirp, dirp);
2553 return (dirp_search(dp->dp_left, dirp));
2555 return (dirp_search(dp->dp_right, dirp));
2563 * Scan for a host match in a directory tree.
2566 chk_host(struct dirlist *dp, struct sockaddr *saddr, int *defsetp,
2567 int *hostsetp, int *numsecflavors, int **secflavorsp)
2569 struct hostlist *hp;
2570 struct grouplist *grp;
2571 struct addrinfo *ai;
2574 if (dp->dp_flag & DP_DEFSET)
2575 *defsetp = dp->dp_flag;
2579 switch (grp->gr_type) {
2581 ai = grp->gr_ptr.gt_addrinfo;
2582 for (; ai; ai = ai->ai_next) {
2583 if (!sacmp(ai->ai_addr, saddr, NULL)) {
2585 (hp->ht_flag | DP_HOSTSET);
2586 if (numsecflavors != NULL) {
2588 grp->gr_numsecflavors;
2597 if (!sacmp(saddr, (struct sockaddr *)
2598 &grp->gr_ptr.gt_net.nt_net,
2600 &grp->gr_ptr.gt_net.nt_mask)) {
2601 *hostsetp = (hp->ht_flag | DP_HOSTSET);
2602 if (numsecflavors != NULL) {
2604 grp->gr_numsecflavors;
2619 * Scan tree for a host that matches the address.
2622 scan_tree(struct dirlist *dp, struct sockaddr *saddr)
2624 int defset, hostset;
2627 if (scan_tree(dp->dp_left, saddr))
2629 if (chk_host(dp, saddr, &defset, &hostset, NULL, NULL))
2631 if (scan_tree(dp->dp_right, saddr))
2638 * Traverse the dirlist tree and free it up.
2641 free_dir(struct dirlist *dp)
2645 free_dir(dp->dp_left);
2646 free_dir(dp->dp_right);
2647 free_host(dp->dp_hosts);
2654 * Parse a colon separated list of security flavors
2657 parsesec(char *seclist, struct exportlist *ep)
2662 ep->ex_numsecflavors = 0;
2664 cp = strchr(seclist, ':');
2670 if (!strcmp(seclist, "sys"))
2672 else if (!strcmp(seclist, "krb5"))
2673 flavor = RPCSEC_GSS_KRB5;
2674 else if (!strcmp(seclist, "krb5i"))
2675 flavor = RPCSEC_GSS_KRB5I;
2676 else if (!strcmp(seclist, "krb5p"))
2677 flavor = RPCSEC_GSS_KRB5P;
2681 syslog(LOG_ERR, "bad sec flavor: %s", seclist);
2684 if (ep->ex_numsecflavors == MAXSECFLAVORS) {
2687 syslog(LOG_ERR, "too many sec flavors: %s", seclist);
2690 ep->ex_secflavors[ep->ex_numsecflavors] = flavor;
2691 ep->ex_numsecflavors++;
2703 * Parse the option string and update fields.
2704 * Option arguments may either be -<option>=<value> or
2708 do_opt(char **cpp, char **endcpp, struct exportlist *ep, struct grouplist *grp,
2709 int *has_hostp, uint64_t *exflagsp, struct expcred *cr)
2711 char *cpoptarg, *cpoptend;
2712 char *cp, *endcp, *cpopt, savedc, savedc2;
2713 int allflag, usedarg;
2721 while (cpopt && *cpopt) {
2724 if ((cpoptend = strchr(cpopt, ','))) {
2726 if ((cpoptarg = strchr(cpopt, '=')))
2729 if ((cpoptarg = strchr(cpopt, '=')))
2733 nextfield(&cp, &endcp);
2735 if (endcp > cp && *cp != '-') {
2743 if (!strcmp(cpopt, "ro") || !strcmp(cpopt, "o")) {
2744 *exflagsp |= MNT_EXRDONLY;
2745 } else if (cpoptarg && (!strcmp(cpopt, "maproot") ||
2746 !(allflag = strcmp(cpopt, "mapall")) ||
2747 !strcmp(cpopt, "root") || !strcmp(cpopt, "r"))) {
2749 parsecred(cpoptarg, cr);
2751 *exflagsp |= MNT_EXPORTANON;
2752 opt_flags |= OP_MAPALL;
2754 opt_flags |= OP_MAPROOT;
2755 } else if (cpoptarg && (!strcmp(cpopt, "mask") ||
2756 !strcmp(cpopt, "m"))) {
2757 if (get_net(cpoptarg, &grp->gr_ptr.gt_net, 1)) {
2758 syslog(LOG_ERR, "bad mask: %s", cpoptarg);
2762 opt_flags |= OP_MASK;
2763 } else if (cpoptarg && (!strcmp(cpopt, "network") ||
2764 !strcmp(cpopt, "n"))) {
2765 if (strchr(cpoptarg, '/') != NULL) {
2767 fprintf(stderr, "setting OP_MASKLEN\n");
2768 opt_flags |= OP_MASKLEN;
2770 if (grp->gr_type != GT_NULL) {
2771 syslog(LOG_ERR, "network/host conflict");
2773 } else if (get_net(cpoptarg, &grp->gr_ptr.gt_net, 0)) {
2774 syslog(LOG_ERR, "bad net: %s", cpoptarg);
2777 grp->gr_type = GT_NET;
2780 opt_flags |= OP_NET;
2781 } else if (!strcmp(cpopt, "alldirs")) {
2782 opt_flags |= OP_ALLDIRS;
2783 } else if (!strcmp(cpopt, "public")) {
2784 *exflagsp |= MNT_EXPUBLIC;
2785 } else if (!strcmp(cpopt, "webnfs")) {
2786 *exflagsp |= (MNT_EXPUBLIC|MNT_EXRDONLY|MNT_EXPORTANON);
2787 opt_flags |= OP_MAPALL;
2788 } else if (cpoptarg && !strcmp(cpopt, "index")) {
2789 ep->ex_indexfile = strdup(cpoptarg);
2790 } else if (!strcmp(cpopt, "quiet")) {
2791 opt_flags |= OP_QUIET;
2792 } else if (cpoptarg && !strcmp(cpopt, "sec")) {
2793 if (parsesec(cpoptarg, ep))
2795 opt_flags |= OP_SEC;
2798 syslog(LOG_ERR, "bad opt %s", cpopt);
2817 * Translate a character string to the corresponding list of network
2818 * addresses for a hostname.
2821 get_host(char *cp, struct grouplist *grp, struct grouplist *tgrp)
2823 struct grouplist *checkgrp;
2824 struct addrinfo *ai, *tai, hints;
2826 char host[NI_MAXHOST];
2828 if (grp->gr_type != GT_NULL) {
2829 syslog(LOG_ERR, "Bad netgroup type for ip host %s", cp);
2832 memset(&hints, 0, sizeof hints);
2833 hints.ai_flags = AI_CANONNAME;
2834 hints.ai_protocol = IPPROTO_UDP;
2835 ecode = getaddrinfo(cp, NULL, &hints, &ai);
2837 syslog(LOG_ERR,"can't get address info for host %s", cp);
2840 grp->gr_ptr.gt_addrinfo = ai;
2841 while (ai != NULL) {
2842 if (ai->ai_canonname == NULL) {
2843 if (getnameinfo(ai->ai_addr, ai->ai_addrlen, host,
2844 sizeof host, NULL, 0, NI_NUMERICHOST) != 0)
2845 strlcpy(host, "?", sizeof(host));
2846 ai->ai_canonname = strdup(host);
2847 ai->ai_flags |= AI_CANONNAME;
2850 fprintf(stderr, "got host %s\n", ai->ai_canonname);
2852 * Sanity check: make sure we don't already have an entry
2853 * for this host in the grouplist.
2855 for (checkgrp = tgrp; checkgrp != NULL;
2856 checkgrp = checkgrp->gr_next) {
2857 if (checkgrp->gr_type != GT_HOST)
2859 for (tai = checkgrp->gr_ptr.gt_addrinfo; tai != NULL;
2860 tai = tai->ai_next) {
2861 if (sacmp(tai->ai_addr, ai->ai_addr, NULL) != 0)
2865 "ignoring duplicate host %s\n",
2867 grp->gr_type = GT_IGNORE;
2873 grp->gr_type = GT_HOST;
2878 * Free up an exports list component
2881 free_exp(struct exportlist *ep)
2883 struct grouplist *grp, *tgrp;
2885 if (ep->ex_defdir) {
2886 free_host(ep->ex_defdir->dp_hosts);
2887 free((caddr_t)ep->ex_defdir);
2891 if (ep->ex_indexfile)
2892 free(ep->ex_indexfile);
2893 free_dir(ep->ex_dirl);
2894 grp = ep->ex_grphead;
2904 * Free up the v4root exports.
2907 free_v4rootexp(void)
2910 if (v4root_ep != NULL) {
2911 free_exp(v4root_ep);
2920 free_host(struct hostlist *hp)
2922 struct hostlist *hp2;
2931 static struct hostlist *
2934 struct hostlist *hp;
2936 hp = (struct hostlist *)malloc(sizeof (struct hostlist));
2937 if (hp == (struct hostlist *)NULL)
2939 hp->ht_next = (struct hostlist *)NULL;
2945 * Out of memory, fatal
2951 syslog(LOG_ERR, "out of memory");
2956 * Call do_mount() from the struct exportlist, for each case needed.
2959 do_export_mount(struct exportlist *ep, struct statfs *fsp)
2961 struct grouplist *grp, defgrp;
2965 LOGDEBUG("do_export_mount=%s", ep->ex_fsdir);
2966 dirlen = strlen(ep->ex_fsdir);
2967 if ((ep->ex_flag & EX_DEFSET) != 0) {
2968 defgrp.gr_type = GT_DEFAULT;
2969 defgrp.gr_next = NULL;
2970 /* We have an entry for all other hosts/nets. */
2971 LOGDEBUG("ex_defexflags=0x%jx", (uintmax_t)ep->ex_defexflags);
2972 ret = do_mount(ep, &defgrp, ep->ex_defexflags, &ep->ex_defanon,
2973 ep->ex_fsdir, dirlen, fsp, ep->ex_defnumsecflavors,
2974 ep->ex_defsecflavors);
2979 /* Do a mount for each group. */
2980 grp = ep->ex_grphead;
2981 while (grp != NULL) {
2982 LOGDEBUG("do mount gr_type=0x%x gr_exflags=0x%jx",
2983 grp->gr_type, (uintmax_t)grp->gr_exflags);
2984 ret = do_mount(ep, grp, grp->gr_exflags, &grp->gr_anon,
2985 ep->ex_fsdir, dirlen, fsp, grp->gr_numsecflavors,
2986 grp->gr_secflavors);
2995 * Do the nmount() syscall with the update flag to push the export info into
2999 do_mount(struct exportlist *ep, struct grouplist *grp, uint64_t exflags,
3000 struct expcred *anoncrp, char *dirp, int dirplen, struct statfs *fsb,
3001 int numsecflavors, int *secflavors)
3004 struct addrinfo *ai;
3005 struct export_args *eap;
3013 struct nfsex_args nfsea;
3015 eap = &nfsea.export;
3023 bzero(eap, sizeof (struct export_args));
3024 bzero(errmsg, sizeof(errmsg));
3025 eap->ex_flags = exflags;
3026 eap->ex_uid = anoncrp->cr_uid;
3027 eap->ex_ngroups = anoncrp->cr_ngroups;
3028 if (eap->ex_ngroups > 0) {
3029 eap->ex_groups = malloc(eap->ex_ngroups * sizeof(gid_t));
3030 memcpy(eap->ex_groups, anoncrp->cr_groups, eap->ex_ngroups *
3033 LOGDEBUG("do_mount exflags=0x%jx", (uintmax_t)exflags);
3034 eap->ex_indexfile = ep->ex_indexfile;
3035 if (grp->gr_type == GT_HOST)
3036 ai = grp->gr_ptr.gt_addrinfo;
3039 eap->ex_numsecflavors = numsecflavors;
3040 LOGDEBUG("do_mount numsec=%d", numsecflavors);
3041 for (i = 0; i < eap->ex_numsecflavors; i++)
3042 eap->ex_secflavors[i] = secflavors[i];
3043 if (eap->ex_numsecflavors == 0) {
3044 eap->ex_numsecflavors = 1;
3045 eap->ex_secflavors[0] = AUTH_SYS;
3049 if (v4root_phase == 0) {
3050 build_iovec(&iov, &iovlen, "fstype", NULL, 0);
3051 build_iovec(&iov, &iovlen, "fspath", NULL, 0);
3052 build_iovec(&iov, &iovlen, "from", NULL, 0);
3053 build_iovec(&iov, &iovlen, "update", NULL, 0);
3054 build_iovec(&iov, &iovlen, "export", eap,
3055 sizeof (struct export_args));
3056 build_iovec(&iov, &iovlen, "errmsg", errmsg, sizeof(errmsg));
3060 switch (grp->gr_type) {
3062 if (ai->ai_addr->sa_family == AF_INET6 && have_v6 == 0)
3064 eap->ex_addr = ai->ai_addr;
3065 eap->ex_addrlen = ai->ai_addrlen;
3066 eap->ex_masklen = 0;
3069 if (grp->gr_ptr.gt_net.nt_net.ss_family == AF_INET6 &&
3073 (struct sockaddr *)&grp->gr_ptr.gt_net.nt_net;
3075 ((struct sockaddr *)&grp->gr_ptr.gt_net.nt_net)->sa_len;
3077 (struct sockaddr *)&grp->gr_ptr.gt_net.nt_mask;
3078 eap->ex_masklen = ((struct sockaddr *)&grp->gr_ptr.gt_net.nt_mask)->sa_len;
3081 eap->ex_addr = NULL;
3082 eap->ex_addrlen = 0;
3083 eap->ex_mask = NULL;
3084 eap->ex_masklen = 0;
3091 syslog(LOG_ERR, "bad grouptype");
3099 * For V4:, use the nfssvc() syscall, instead of mount().
3101 if (v4root_phase == 2) {
3102 nfsea.fspec = v4root_dirpath;
3103 if (nfssvc(NFSSVC_V4ROOTEXPORT | NFSSVC_NEWSTRUCT,
3104 (caddr_t)&nfsea) < 0) {
3105 syslog(LOG_ERR, "Exporting V4: failed");
3112 * Maybe I should just use the fsb->f_mntonname path
3113 * instead of looping back up the dirp to the mount
3115 * Also, needs to know how to export all types of local
3116 * exportable filesystems and not just "ufs".
3118 iov[1].iov_base = fsb->f_fstypename; /* "fstype" */
3119 iov[1].iov_len = strlen(fsb->f_fstypename) + 1;
3120 iov[3].iov_base = fsb->f_mntonname; /* "fspath" */
3121 iov[3].iov_len = strlen(fsb->f_mntonname) + 1;
3122 iov[5].iov_base = fsb->f_mntfromname; /* "from" */
3123 iov[5].iov_len = strlen(fsb->f_mntfromname) + 1;
3126 while (nmount(iov, iovlen, fsb->f_flags) < 0) {
3130 cp = dirp + dirplen - 1;
3131 if (opt_flags & OP_QUIET) {
3135 if (errno == EPERM) {
3137 warnx("can't change attributes for %s: %s",
3140 "can't change attributes for %s: %s",
3145 if (opt_flags & OP_ALLDIRS) {
3146 if (errno == EINVAL)
3148 "-alldirs requested but %s is not a filesystem mountpoint",
3152 "could not remount %s: %m",
3157 /* back up over the last component */
3158 while (*cp == '/' && cp > dirp)
3160 while (*(cp - 1) != '/' && cp > dirp)
3164 warnx("mnt unsucc");
3165 syslog(LOG_ERR, "can't export %s %s",
3173 * Check that we're still on the same
3176 if (statfs(dirp, &fsb1) != 0 ||
3177 fsidcmp(&fsb1.f_fsid, &fsb->f_fsid) != 0) {
3180 "can't export %s %s", dirp,
3189 * For the experimental server:
3190 * If this is the public directory, get the file handle
3191 * and load it into the kernel via the nfssvc() syscall.
3193 if ((exflags & MNT_EXPUBLIC) != 0) {
3197 if (eap->ex_indexfile != NULL)
3198 public_name = eap->ex_indexfile;
3201 if (getfh(public_name, &fh) < 0)
3203 "Can't get public fh for %s", public_name);
3204 else if (nfssvc(NFSSVC_PUBLICFH, (caddr_t)&fh) < 0)
3206 "Can't set public fh for %s", public_name);
3209 has_set_publicfh = 1;
3210 ep->ex_flag |= EX_PUBLICFH;
3222 free(eap->ex_groups);
3223 /* free strings allocated by strdup() in getmntopts.c */
3225 free(iov[0].iov_base); /* fstype */
3226 free(iov[2].iov_base); /* fspath */
3227 free(iov[4].iov_base); /* from */
3228 free(iov[6].iov_base); /* update */
3229 free(iov[8].iov_base); /* export */
3230 free(iov[10].iov_base); /* errmsg */
3232 /* free iov, allocated by realloc() */
3239 * Translate a net address.
3241 * If `maskflg' is nonzero, then `cp' is a netmask, not a network address.
3244 get_net(char *cp, struct netmsk *net, int maskflg)
3246 struct netent *np = NULL;
3247 char *name, *p, *prefp;
3248 struct sockaddr_in sin;
3249 struct sockaddr *sa = NULL;
3250 struct addrinfo hints, *ai = NULL;
3251 char netname[NI_MAXHOST];
3255 if ((opt_flags & OP_MASKLEN) && !maskflg) {
3256 p = strchr(cp, '/');
3262 * Check for a numeric address first. We wish to avoid
3263 * possible DNS lookups in getnetbyname().
3265 if (isxdigit(*cp) || *cp == ':') {
3266 memset(&hints, 0, sizeof hints);
3267 /* Ensure the mask and the network have the same family. */
3268 if (maskflg && (opt_flags & OP_NET))
3269 hints.ai_family = net->nt_net.ss_family;
3270 else if (!maskflg && (opt_flags & OP_HAVEMASK))
3271 hints.ai_family = net->nt_mask.ss_family;
3273 hints.ai_family = AF_UNSPEC;
3274 hints.ai_flags = AI_NUMERICHOST;
3275 if (getaddrinfo(cp, NULL, &hints, &ai) == 0)
3277 if (sa != NULL && ai->ai_family == AF_INET) {
3279 * The address in `cp' is really a network address, so
3280 * use inet_network() to re-interpret this correctly.
3281 * e.g. "127.1" means 127.1.0.0, not 127.0.0.1.
3283 bzero(&sin, sizeof sin);
3284 sin.sin_family = AF_INET;
3285 sin.sin_len = sizeof sin;
3286 sin.sin_addr = inet_makeaddr(inet_network(cp), 0);
3288 fprintf(stderr, "get_net: v4 addr %s\n",
3289 inet_ntoa(sin.sin_addr));
3290 sa = (struct sockaddr *)&sin;
3293 if (sa == NULL && (np = getnetbyname(cp)) != NULL) {
3294 bzero(&sin, sizeof sin);
3295 sin.sin_family = AF_INET;
3296 sin.sin_len = sizeof sin;
3297 sin.sin_addr = inet_makeaddr(np->n_net, 0);
3298 sa = (struct sockaddr *)&sin;
3304 /* The specified sockaddr is a mask. */
3305 if (checkmask(sa) != 0)
3307 bcopy(sa, &net->nt_mask, sa->sa_len);
3308 opt_flags |= OP_HAVEMASK;
3310 /* The specified sockaddr is a network address. */
3311 bcopy(sa, &net->nt_net, sa->sa_len);
3313 /* Get a network name for the export list. */
3316 } else if (getnameinfo(sa, sa->sa_len, netname, sizeof netname,
3317 NULL, 0, NI_NUMERICHOST) == 0) {
3322 if ((net->nt_name = strdup(name)) == NULL)
3326 * Extract a mask from either a "/<masklen>" suffix, or
3327 * from the class of an IPv4 address.
3329 if (opt_flags & OP_MASKLEN) {
3330 preflen = strtol(prefp, NULL, 10);
3331 if (preflen < 0L || preflen == LONG_MAX)
3333 bcopy(sa, &net->nt_mask, sa->sa_len);
3334 if (makemask(&net->nt_mask, (int)preflen) != 0)
3336 opt_flags |= OP_HAVEMASK;
3338 } else if (sa->sa_family == AF_INET &&
3339 (opt_flags & OP_MASK) == 0) {
3342 addr = ((struct sockaddr_in *)sa)->sin_addr.s_addr;
3343 if (IN_CLASSA(addr))
3345 else if (IN_CLASSB(addr))
3347 else if (IN_CLASSC(addr))
3349 else if (IN_CLASSD(addr))
3352 preflen = 32; /* XXX */
3354 bcopy(sa, &net->nt_mask, sa->sa_len);
3355 makemask(&net->nt_mask, (int)preflen);
3356 opt_flags |= OP_HAVEMASK;
3371 * Parse out the next white space separated field
3374 nextfield(char **cp, char **endcp)
3380 while (*p == ' ' || *p == '\t')
3383 while (*p != '\0') {
3388 if (*p == '\\' && *(p + 1) != '\0')
3390 else if (*p == '\'' || *p == '"')
3392 else if (*p == ' ' || *p == '\t')
3401 * Get an exports file line. Skip over blank lines and handle line
3409 int totlen, cont_line;
3412 * Loop around ignoring blank lines and getting all continuation lines.
3417 if ((p = fgetln(exp_file, &len)) == NULL)
3422 (*cp == ' ' || *cp == '\t' || *cp == '\n' || *cp == '\\')) {
3432 if (linesize < len + totlen + 1) {
3433 linesize = len + totlen + 1;
3434 line = realloc(line, linesize);
3438 memcpy(line + totlen, p, len);
3440 line[totlen] = '\0';
3441 } while (totlen == 0 || cont_line);
3446 * Parse a description of a credential.
3449 parsecred(char *namelist, struct expcred *cr)
3458 * Set up the unprivileged user.
3460 cr->cr_uid = UID_NOBODY;
3461 cr->cr_groups[0] = GID_NOGROUP;
3464 * Get the user's password table entry.
3467 name = strsep_quote(&names, ":");
3468 /* Bug? name could be NULL here */
3469 if (isdigit(*name) || *name == '-')
3470 pw = getpwuid(atoi(name));
3472 pw = getpwnam(name);
3474 * Credentials specified as those of a user.
3476 if (names == NULL) {
3478 syslog(LOG_ERR, "unknown user: %s", name);
3481 cr->cr_uid = pw->pw_uid;
3482 cr->cr_ngroups = NGROUPS_MAX + 1;
3483 if (getgrouplist(pw->pw_name, pw->pw_gid, cr->cr_groups,
3485 syslog(LOG_ERR, "too many groups");
3486 cr->cr_ngroups = NGROUPS_MAX + 1;
3490 * Compress out duplicate.
3492 if (cr->cr_ngroups > 1 && cr->cr_groups[0] ==
3494 for (cnt = 2; cnt < cr->cr_ngroups; cnt++)
3495 cr->cr_groups[cnt - 1] = cr->cr_groups[cnt];
3498 if (cr->cr_ngroups > NGROUPS_MAX)
3499 cr->cr_ngroups = NGROUPS_MAX;
3503 * Explicit credential specified as a colon separated list:
3507 cr->cr_uid = pw->pw_uid;
3508 else if (isdigit(*name) || *name == '-')
3509 cr->cr_uid = atoi(name);
3511 syslog(LOG_ERR, "unknown user: %s", name);
3515 while (names != NULL && *names != '\0' && cr->cr_ngroups < NGROUPS_MAX) {
3516 name = strsep_quote(&names, ":");
3517 if (isdigit(*name) || *name == '-') {
3518 cr->cr_groups[cr->cr_ngroups++] = atoi(name);
3520 if ((gr = getgrnam(name)) == NULL) {
3521 syslog(LOG_ERR, "unknown group: %s", name);
3524 cr->cr_groups[cr->cr_ngroups++] = gr->gr_gid;
3527 if (names != NULL && *names != '\0' && cr->cr_ngroups == NGROUPS_MAX)
3528 syslog(LOG_ERR, "too many groups");
3531 #define STRSIZ (MNTNAMLEN+MNTPATHLEN+50)
3533 * Routines that maintain the remote mounttab
3538 struct mountlist *mlp;
3539 char *host, *dirp, *cp;
3543 if ((mlfile = fopen(_PATH_RMOUNTLIST, "r")) == NULL) {
3544 if (errno == ENOENT)
3547 syslog(LOG_ERR, "can't open %s", _PATH_RMOUNTLIST);
3551 while (fgets(str, STRSIZ, mlfile) != NULL) {
3553 host = strsep(&cp, " \t\n");
3554 dirp = strsep(&cp, " \t\n");
3555 if (host == NULL || dirp == NULL)
3557 mlp = (struct mountlist *)malloc(sizeof (*mlp));
3558 if (mlp == (struct mountlist *)NULL)
3560 strncpy(mlp->ml_host, host, MNTNAMLEN);
3561 mlp->ml_host[MNTNAMLEN] = '\0';
3562 strncpy(mlp->ml_dirp, dirp, MNTPATHLEN);
3563 mlp->ml_dirp[MNTPATHLEN] = '\0';
3565 SLIST_INSERT_HEAD(&mlhead, mlp, next);
3571 del_mlist(char *hostp, char *dirp)
3573 struct mountlist *mlp, *mlp2;
3577 SLIST_FOREACH_SAFE(mlp, &mlhead, next, mlp2) {
3578 if (!strcmp(mlp->ml_host, hostp) &&
3579 (!dirp || !strcmp(mlp->ml_dirp, dirp))) {
3581 SLIST_REMOVE(&mlhead, mlp, mountlist, next);
3586 if ((mlfile = fopen(_PATH_RMOUNTLIST, "w")) == NULL) {
3587 syslog(LOG_ERR,"can't update %s", _PATH_RMOUNTLIST);
3590 SLIST_FOREACH(mlp, &mlhead, next) {
3591 fprintf(mlfile, "%s %s\n", mlp->ml_host, mlp->ml_dirp);
3598 add_mlist(char *hostp, char *dirp)
3600 struct mountlist *mlp;
3603 SLIST_FOREACH(mlp, &mlhead, next) {
3604 if (!strcmp(mlp->ml_host, hostp) && !strcmp(mlp->ml_dirp, dirp))
3608 mlp = (struct mountlist *)malloc(sizeof (*mlp));
3609 if (mlp == (struct mountlist *)NULL)
3611 strncpy(mlp->ml_host, hostp, MNTNAMLEN);
3612 mlp->ml_host[MNTNAMLEN] = '\0';
3613 strncpy(mlp->ml_dirp, dirp, MNTPATHLEN);
3614 mlp->ml_dirp[MNTPATHLEN] = '\0';
3615 SLIST_INSERT_HEAD(&mlhead, mlp, next);
3616 if ((mlfile = fopen(_PATH_RMOUNTLIST, "a")) == NULL) {
3617 syslog(LOG_ERR, "can't update %s", _PATH_RMOUNTLIST);
3620 fprintf(mlfile, "%s %s\n", mlp->ml_host, mlp->ml_dirp);
3625 * Free up a group list.
3628 free_grp(struct grouplist *grp)
3630 if (grp->gr_type == GT_HOST) {
3631 if (grp->gr_ptr.gt_addrinfo != NULL)
3632 freeaddrinfo(grp->gr_ptr.gt_addrinfo);
3633 } else if (grp->gr_type == GT_NET) {
3634 if (grp->gr_ptr.gt_net.nt_name)
3635 free(grp->gr_ptr.gt_net.nt_name);
3642 SYSLOG(int pri, const char *fmt, ...)
3647 vfprintf(stderr, fmt, ap);
3653 * Check options for consistency.
3656 check_options(struct dirlist *dp)
3659 if (v4root_phase == 0 && dp == NULL)
3661 if ((opt_flags & (OP_MAPROOT | OP_MAPALL)) == (OP_MAPROOT | OP_MAPALL)) {
3662 syslog(LOG_ERR, "-mapall and -maproot mutually exclusive");
3665 if ((opt_flags & OP_MASK) && (opt_flags & OP_NET) == 0) {
3666 syslog(LOG_ERR, "-mask requires -network");
3669 if ((opt_flags & OP_NET) && (opt_flags & OP_HAVEMASK) == 0) {
3670 syslog(LOG_ERR, "-network requires mask specification");
3673 if ((opt_flags & OP_MASK) && (opt_flags & OP_MASKLEN)) {
3674 syslog(LOG_ERR, "-mask and /masklen are mutually exclusive");
3677 if (v4root_phase > 0 &&
3679 ~(OP_SEC | OP_MASK | OP_NET | OP_HAVEMASK | OP_MASKLEN)) != 0) {
3680 syslog(LOG_ERR,"only -sec,-net,-mask options allowed on V4:");
3683 if ((opt_flags & OP_ALLDIRS) && dp->dp_left) {
3684 syslog(LOG_ERR, "-alldirs has multiple directories");
3691 * Check an absolute directory path for any symbolic links. Return true
3694 check_dirpath(char *dirp)
3701 while (*cp && ret) {
3704 if (lstat(dirp, &sb) < 0 || !S_ISDIR(sb.st_mode))
3710 if (lstat(dirp, &sb) < 0 || !S_ISDIR(sb.st_mode))
3716 * Make a netmask according to the specified prefix length. The ss_family
3717 * and other non-address fields must be initialised before calling this.
3720 makemask(struct sockaddr_storage *ssp, int bitlen)
3725 if ((p = sa_rawaddr((struct sockaddr *)ssp, &len)) == NULL)
3727 if (bitlen > len * CHAR_BIT)
3730 for (i = 0; i < len; i++) {
3731 bits = MIN(CHAR_BIT, bitlen);
3732 *p++ = (u_char)~0 << (CHAR_BIT - bits);
3739 * Check that the sockaddr is a valid netmask. Returns 0 if the mask
3740 * is acceptable (i.e. of the form 1...10....0).
3743 checkmask(struct sockaddr *sa)
3748 if ((mask = sa_rawaddr(sa, &len)) == NULL)
3751 for (i = 0; i < len; i++)
3752 if (mask[i] != 0xff)
3755 if (~mask[i] & (u_char)(~mask[i] + 1))
3759 for (; i < len; i++)
3766 * Compare two sockaddrs according to a specified mask. Return zero if
3767 * `sa1' matches `sa2' when filtered by the netmask in `samask'.
3768 * If samask is NULL, perform a full comparison.
3771 sacmp(struct sockaddr *sa1, struct sockaddr *sa2, struct sockaddr *samask)
3773 unsigned char *p1, *p2, *mask;
3776 if (sa1->sa_family != sa2->sa_family ||
3777 (p1 = sa_rawaddr(sa1, &len)) == NULL ||
3778 (p2 = sa_rawaddr(sa2, NULL)) == NULL)
3781 switch (sa1->sa_family) {
3783 if (((struct sockaddr_in6 *)sa1)->sin6_scope_id !=
3784 ((struct sockaddr_in6 *)sa2)->sin6_scope_id)
3789 /* Simple binary comparison if no mask specified. */
3791 return (memcmp(p1, p2, len));
3793 /* Set up the mask, and do a mask-based comparison. */
3794 if (sa1->sa_family != samask->sa_family ||
3795 (mask = sa_rawaddr(samask, NULL)) == NULL)
3798 for (i = 0; i < len; i++)
3799 if ((p1[i] & mask[i]) != (p2[i] & mask[i]))
3805 * Return a pointer to the part of the sockaddr that contains the
3806 * raw address, and set *nbytes to its length in bytes. Returns
3807 * NULL if the address family is unknown.
3810 sa_rawaddr(struct sockaddr *sa, int *nbytes) {
3814 switch (sa->sa_family) {
3816 len = sizeof(((struct sockaddr_in *)sa)->sin_addr);
3817 p = &((struct sockaddr_in *)sa)->sin_addr;
3820 len = sizeof(((struct sockaddr_in6 *)sa)->sin6_addr);
3821 p = &((struct sockaddr_in6 *)sa)->sin6_addr;
3834 huphandler(int sig __unused)
3841 terminate(int sig __unused)
3843 pidfile_remove(pfh);
3844 rpcb_unset(MOUNTPROG, MOUNTVERS, NULL);
3845 rpcb_unset(MOUNTPROG, MOUNTVERS3, NULL);
3850 cp_cred(struct expcred *outcr, struct expcred *incr)
3853 outcr->cr_uid = incr->cr_uid;
3854 outcr->cr_ngroups = incr->cr_ngroups;
3855 memcpy(outcr->cr_groups, incr->cr_groups, incr->cr_ngroups *