1/*
2 * Copyright (c) 1989, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Herb Hasler and Rick Macklem at The University of Guelph.
7 *
8 * Redistribution and use in source and binary forms, with or without
--- 29 unchanged lines hidden (view full) ---
38
39#if 0
40#ifndef lint
41static char sccsid[] = "@(#)mountd.c 8.15 (Berkeley) 5/1/95";
42#endif /*not lint*/
43#endif
44
45#include <sys/cdefs.h>
46__FBSDID("$FreeBSD: head/usr.sbin/mountd/mountd.c 146187 2005-05-13 16:31:11Z ume $");
47
48#include <sys/param.h>
49#include <sys/mount.h>
50#include <sys/fcntl.h>
51#include <sys/stat.h>
52#include <sys/syslog.h>
53#include <sys/sysctl.h>
54#include <sys/linker.h>
--- 13 unchanged lines hidden (view full) ---
68#include <isofs/cd9660/cd9660_mount.h> /* XXX need isofs in include */
69
70#include <arpa/inet.h>
71
72#include <ctype.h>
73#include <err.h>
74#include <errno.h>
75#include <grp.h>
76#include <limits.h>
77#include <netdb.h>
78#include <pwd.h>
79#include <signal.h>
80#include <stdio.h>
81#include <stdlib.h>
82#include <string.h>
83#include <unistd.h>
84#include "pathnames.h"
85
86#ifdef DEBUG
87#include <stdarg.h>
88#endif
89
90#ifndef MOUNTDLOCK
91#define MOUNTDLOCK "/var/run/mountd.lock"
92#endif
93
94/*
95 * Structures for keeping the mount list and export list
96 */
97struct mountlist {
98 struct mountlist *ml_next;
99 char ml_host[RPCMNT_NAMELEN+1];
100 char ml_dirp[RPCMNT_PATHLEN+1];
101};
--- 121 unchanged lines hidden (view full) ---
223int resvport_only = 1;
224int dir_only = 1;
225int dolog = 0;
226int got_sighup = 0;
227
228int opt_flags;
229static int have_v6 = 1;
230
231int mountdlockfd;
232/* Bits for opt_flags above */
233#define OP_MAPROOT 0x01
234#define OP_MAPALL 0x02
235/* 0x4 free */
236#define OP_MASK 0x08
237#define OP_NET 0x10
238#define OP_ALLDIRS 0x40
239#define OP_HAVEMASK 0x80 /* A mask was specified or inferred. */
--- 21 unchanged lines hidden (view full) ---
261 char **argv;
262{
263 fd_set readfds;
264 struct sockaddr_in sin;
265 struct sockaddr_in6 sin6;
266 char *endptr;
267 SVCXPRT *udptransp, *tcptransp, *udp6transp, *tcp6transp;
268 struct netconfig *udpconf, *tcpconf, *udp6conf, *tcp6conf;
269 int udpsock, tcpsock, udp6sock, tcp6sock;
270 int xcreated = 0, s;
271 int maxrec = RPC_MAXDATASIZE;
272 int one = 1;
273 int c, r;
274 in_port_t svcport = 0;
275
276 udp6conf = tcp6conf = NULL;
277 udp6sock = tcp6sock = 0;
278
279 /* Check that another mountd isn't already running. */
280 if ((mountdlockfd = (open(MOUNTDLOCK, O_RDONLY|O_CREAT, 0444))) == -1)
281 err(1, "%s", MOUNTDLOCK);
282
283 if(flock(mountdlockfd, LOCK_EX|LOCK_NB) == -1 && errno == EWOULDBLOCK)
284 errx(1, "another mountd is already running. Aborting");
285 s = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
286 if (s < 0)
287 have_v6 = 0;
288 else
289 close(s);
290 if (modfind("nfsserver") < 0) {
291 /* Not present in kernel, try loading it */
292 if (kldload("nfsserver") < 0 || modfind("nfsserver") < 0)
--- 48 unchanged lines hidden (view full) ---
341 warnx("here we go");
342 if (debug == 0) {
343 daemon(0, 0);
344 signal(SIGINT, SIG_IGN);
345 signal(SIGQUIT, SIG_IGN);
346 }
347 signal(SIGHUP, huphandler);
348 signal(SIGTERM, terminate);
349 { FILE *pidfile = fopen(_PATH_MOUNTDPID, "w");
350 if (pidfile != NULL) {
351 fprintf(pidfile, "%d\n", getpid());
352 fclose(pidfile);
353 }
354 }
355 rpcb_unset(RPCPROG_MNT, RPCMNT_VER1, NULL);
356 rpcb_unset(RPCPROG_MNT, RPCMNT_VER3, NULL);
357 udpsock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
358 tcpsock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
359 udpconf = getnetconfigent("udp");
360 tcpconf = getnetconfigent("tcp");
361
362 rpc_control(RPC_SVC_CONNMAXREC_SET, &maxrec);
--- 2163 unchanged lines hidden (view full) ---
2526huphandler(int sig)
2527{
2528 got_sighup = 1;
2529}
2530
2531void terminate(sig)
2532int sig;
2533{
2534 close(mountdlockfd);
2535 unlink(MOUNTDLOCK);
2536 rpcb_unset(RPCPROG_MNT, RPCMNT_VER1, NULL);
2537 rpcb_unset(RPCPROG_MNT, RPCMNT_VER3, NULL);
2538 exit (0);
2539}
2 * Copyright (c) 1989, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Herb Hasler and Rick Macklem at The University of Guelph.
7 *
8 * Redistribution and use in source and binary forms, with or without
--- 29 unchanged lines hidden (view full) ---
38
39#if 0
40#ifndef lint
41static char sccsid[] = "@(#)mountd.c 8.15 (Berkeley) 5/1/95";
42#endif /*not lint*/
43#endif
44
45#include <sys/cdefs.h>
46__FBSDID("$FreeBSD: head/usr.sbin/mountd/mountd.c 146187 2005-05-13 16:31:11Z ume $");
47
48#include <sys/param.h>
49#include <sys/mount.h>
50#include <sys/fcntl.h>
51#include <sys/stat.h>
52#include <sys/syslog.h>
53#include <sys/sysctl.h>
54#include <sys/linker.h>
--- 13 unchanged lines hidden (view full) ---
68#include <isofs/cd9660/cd9660_mount.h> /* XXX need isofs in include */
69
70#include <arpa/inet.h>
71
72#include <ctype.h>
73#include <err.h>
74#include <errno.h>
75#include <grp.h>
76#include <limits.h>
77#include <netdb.h>
78#include <pwd.h>
79#include <signal.h>
80#include <stdio.h>
81#include <stdlib.h>
82#include <string.h>
83#include <unistd.h>
84#include "pathnames.h"
85
86#ifdef DEBUG
87#include <stdarg.h>
88#endif
89
90#ifndef MOUNTDLOCK
91#define MOUNTDLOCK "/var/run/mountd.lock"
92#endif
93
94/*
95 * Structures for keeping the mount list and export list
96 */
97struct mountlist {
98 struct mountlist *ml_next;
99 char ml_host[RPCMNT_NAMELEN+1];
100 char ml_dirp[RPCMNT_PATHLEN+1];
101};
--- 121 unchanged lines hidden (view full) ---
223int resvport_only = 1;
224int dir_only = 1;
225int dolog = 0;
226int got_sighup = 0;
227
228int opt_flags;
229static int have_v6 = 1;
230
231int mountdlockfd;
232/* Bits for opt_flags above */
233#define OP_MAPROOT 0x01
234#define OP_MAPALL 0x02
235/* 0x4 free */
236#define OP_MASK 0x08
237#define OP_NET 0x10
238#define OP_ALLDIRS 0x40
239#define OP_HAVEMASK 0x80 /* A mask was specified or inferred. */
--- 21 unchanged lines hidden (view full) ---
261 char **argv;
262{
263 fd_set readfds;
264 struct sockaddr_in sin;
265 struct sockaddr_in6 sin6;
266 char *endptr;
267 SVCXPRT *udptransp, *tcptransp, *udp6transp, *tcp6transp;
268 struct netconfig *udpconf, *tcpconf, *udp6conf, *tcp6conf;
269 int udpsock, tcpsock, udp6sock, tcp6sock;
270 int xcreated = 0, s;
271 int maxrec = RPC_MAXDATASIZE;
272 int one = 1;
273 int c, r;
274 in_port_t svcport = 0;
275
276 udp6conf = tcp6conf = NULL;
277 udp6sock = tcp6sock = 0;
278
279 /* Check that another mountd isn't already running. */
280 if ((mountdlockfd = (open(MOUNTDLOCK, O_RDONLY|O_CREAT, 0444))) == -1)
281 err(1, "%s", MOUNTDLOCK);
282
283 if(flock(mountdlockfd, LOCK_EX|LOCK_NB) == -1 && errno == EWOULDBLOCK)
284 errx(1, "another mountd is already running. Aborting");
285 s = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
286 if (s < 0)
287 have_v6 = 0;
288 else
289 close(s);
290 if (modfind("nfsserver") < 0) {
291 /* Not present in kernel, try loading it */
292 if (kldload("nfsserver") < 0 || modfind("nfsserver") < 0)
--- 48 unchanged lines hidden (view full) ---
341 warnx("here we go");
342 if (debug == 0) {
343 daemon(0, 0);
344 signal(SIGINT, SIG_IGN);
345 signal(SIGQUIT, SIG_IGN);
346 }
347 signal(SIGHUP, huphandler);
348 signal(SIGTERM, terminate);
349 { FILE *pidfile = fopen(_PATH_MOUNTDPID, "w");
350 if (pidfile != NULL) {
351 fprintf(pidfile, "%d\n", getpid());
352 fclose(pidfile);
353 }
354 }
355 rpcb_unset(RPCPROG_MNT, RPCMNT_VER1, NULL);
356 rpcb_unset(RPCPROG_MNT, RPCMNT_VER3, NULL);
357 udpsock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
358 tcpsock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
359 udpconf = getnetconfigent("udp");
360 tcpconf = getnetconfigent("tcp");
361
362 rpc_control(RPC_SVC_CONNMAXREC_SET, &maxrec);
--- 2163 unchanged lines hidden (view full) ---
2526huphandler(int sig)
2527{
2528 got_sighup = 1;
2529}
2530
2531void terminate(sig)
2532int sig;
2533{
2534 close(mountdlockfd);
2535 unlink(MOUNTDLOCK);
2536 rpcb_unset(RPCPROG_MNT, RPCMNT_VER1, NULL);
2537 rpcb_unset(RPCPROG_MNT, RPCMNT_VER3, NULL);
2538 exit (0);
2539}