Deleted Added
full compact
mountd.c (146187) mountd.c (149433)
1/*
2 * Copyright (c) 1989, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Herb Hasler and Rick Macklem at The University of Guelph.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 29 unchanged lines hidden (view full) ---

38
39#if 0
40#ifndef lint
41static char sccsid[] = "@(#)mountd.c 8.15 (Berkeley) 5/1/95";
42#endif /*not lint*/
43#endif
44
45#include <sys/cdefs.h>
1/*
2 * Copyright (c) 1989, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Herb Hasler and Rick Macklem at The University of Guelph.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 29 unchanged lines hidden (view full) ---

38
39#if 0
40#ifndef lint
41static char sccsid[] = "@(#)mountd.c 8.15 (Berkeley) 5/1/95";
42#endif /*not lint*/
43#endif
44
45#include <sys/cdefs.h>
46__FBSDID("$FreeBSD: head/usr.sbin/mountd/mountd.c 146187 2005-05-13 16:31:11Z ume $");
46__FBSDID("$FreeBSD: head/usr.sbin/mountd/mountd.c 149433 2005-08-24 19:17:06Z pjd $");
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>
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 <libutil.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
77#include <limits.h>
78#include <netdb.h>
79#include <pwd.h>
80#include <signal.h>
81#include <stdio.h>
82#include <stdlib.h>
83#include <string.h>
84#include <unistd.h>
85#include "pathnames.h"
86
87#ifdef DEBUG
88#include <stdarg.h>
89#endif
90
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
91/*
92 * Structures for keeping the mount list and export list
93 */
94struct mountlist {
95 struct mountlist *ml_next;
96 char ml_host[RPCMNT_NAMELEN+1];
97 char ml_dirp[RPCMNT_PATHLEN+1];
98};

--- 121 unchanged lines hidden (view full) ---

220int resvport_only = 1;
221int dir_only = 1;
222int dolog = 0;
223int got_sighup = 0;
224
225int opt_flags;
226static int have_v6 = 1;
227
231int mountdlockfd;
228struct pidfh *pfh = NULL;
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;
229/* Bits for opt_flags above */
230#define OP_MAPROOT 0x01
231#define OP_MAPALL 0x02
232/* 0x4 free */
233#define OP_MASK 0x08
234#define OP_NET 0x10
235#define OP_ALLDIRS 0x40
236#define OP_HAVEMASK 0x80 /* A mask was specified or inferred. */

--- 21 unchanged lines hidden (view full) ---

258 char **argv;
259{
260 fd_set readfds;
261 struct sockaddr_in sin;
262 struct sockaddr_in6 sin6;
263 char *endptr;
264 SVCXPRT *udptransp, *tcptransp, *udp6transp, *tcp6transp;
265 struct netconfig *udpconf, *tcpconf, *udp6conf, *tcp6conf;
266 pid_t otherpid;
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. */
267 int udpsock, tcpsock, udp6sock, tcp6sock;
268 int xcreated = 0, s;
269 int maxrec = RPC_MAXDATASIZE;
270 int one = 1;
271 int c, r;
272 in_port_t svcport = 0;
273
274 udp6conf = tcp6conf = NULL;
275 udp6sock = tcp6sock = 0;
276
277 /* Check that another mountd isn't already running. */
280 if ((mountdlockfd = (open(MOUNTDLOCK, O_RDONLY|O_CREAT, 0444))) == -1)
281 err(1, "%s", MOUNTDLOCK);
278 pfh = pidfile_open(_PATH_MOUNTDPID, 0644, &otherpid);
279 if (pfh == NULL) {
280 if (errno == EEXIST)
281 errx(1, "mountd already running, pid: %d.", otherpid);
282 warn("cannot open or create pidfile");
283 }
282
284
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);
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 }
349
350 pidfile_write(pfh);
351
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{
352 rpcb_unset(RPCPROG_MNT, RPCMNT_VER1, NULL);
353 rpcb_unset(RPCPROG_MNT, RPCMNT_VER3, NULL);
354 udpsock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
355 tcpsock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
356 udpconf = getnetconfigent("udp");
357 tcpconf = getnetconfigent("tcp");
358
359 rpc_control(RPC_SVC_CONNMAXREC_SET, &maxrec);

--- 2163 unchanged lines hidden (view full) ---

2523huphandler(int sig)
2524{
2525 got_sighup = 1;
2526}
2527
2528void terminate(sig)
2529int sig;
2530{
2534 close(mountdlockfd);
2535 unlink(MOUNTDLOCK);
2531 pidfile_remove(pfh);
2536 rpcb_unset(RPCPROG_MNT, RPCMNT_VER1, NULL);
2537 rpcb_unset(RPCPROG_MNT, RPCMNT_VER3, NULL);
2538 exit (0);
2539}
2532 rpcb_unset(RPCPROG_MNT, RPCMNT_VER1, NULL);
2533 rpcb_unset(RPCPROG_MNT, RPCMNT_VER3, NULL);
2534 exit (0);
2535}