Again copying code is bad; the second copy of mountd was completely stale.
This commit is contained in:
parent
8e87830d68
commit
2761cda93e
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: mountd.c,v 1.127 2015/08/05 23:23:47 jnemeth Exp $ */
|
||||
/* $NetBSD: mountd.c,v 1.128 2015/11/08 21:03:16 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1989, 1993
|
||||
@ -42,7 +42,7 @@ __COPYRIGHT("@(#) Copyright (c) 1989, 1993\
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)mountd.c 8.15 (Berkeley) 5/1/95";
|
||||
#else
|
||||
__RCSID("$NetBSD: mountd.c,v 1.127 2015/08/05 23:23:47 jnemeth Exp $");
|
||||
__RCSID("$NetBSD: mountd.c,v 1.128 2015/11/08 21:03:16 christos Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -64,6 +64,13 @@ __RCSID("$NetBSD: mountd.c,v 1.127 2015/08/05 23:23:47 jnemeth Exp $");
|
||||
#include <nfs/nfs.h>
|
||||
#include <nfs/nfsmount.h>
|
||||
|
||||
#ifdef MOUNTD_RUMP
|
||||
#include <rump/rump.h>
|
||||
#include <rump/rump_syscalls.h>
|
||||
#include <pthread.h>
|
||||
#include <semaphore.h>
|
||||
#endif
|
||||
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include <ctype.h>
|
||||
@ -91,6 +98,13 @@ __RCSID("$NetBSD: mountd.c,v 1.127 2015/08/05 23:23:47 jnemeth Exp $");
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
#ifdef MOUNTD_RUMP
|
||||
#include "svc_fdset.h"
|
||||
#define DEBUGGING 1
|
||||
#else
|
||||
#define DEBUGGING 0
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Structures for keeping the mount list and export list
|
||||
*/
|
||||
@ -203,7 +217,6 @@ static void parsecred(char *, struct uucred *);
|
||||
static int put_exlist(struct dirlist *, XDR *, struct dirlist *, int *);
|
||||
static int scan_tree(struct dirlist *, struct sockaddr *);
|
||||
__dead static void send_umntall(int);
|
||||
static int umntall_each(caddr_t, struct sockaddr_in *);
|
||||
static int xdr_dir(XDR *, char *);
|
||||
static int xdr_explist(XDR *, caddr_t);
|
||||
static int xdr_fhs(XDR *, caddr_t);
|
||||
@ -242,7 +255,7 @@ static const int ninumeric = NI_NUMERICHOST;
|
||||
#define OP_NORESMNT 0x100
|
||||
#define OP_MASKLEN 0x200
|
||||
|
||||
static int debug = 0;
|
||||
static int debug = DEBUGGING;
|
||||
#if 0
|
||||
static void SYSLOG(int, const char *,...);
|
||||
#endif
|
||||
@ -253,6 +266,82 @@ static void SYSLOG(int, const char *,...);
|
||||
*/
|
||||
static int noprivports;
|
||||
|
||||
#ifdef MOUNTD_RUMP
|
||||
#define C2FD(_c_) ((int)(uintptr_t)(_c_))
|
||||
static int
|
||||
rumpread(void *cookie, char *buf, int count)
|
||||
{
|
||||
|
||||
return rump_sys_read(C2FD(cookie), buf, count);
|
||||
}
|
||||
|
||||
static int
|
||||
rumpwrite(void *cookie, const char *buf, int count)
|
||||
{
|
||||
|
||||
return rump_sys_write(C2FD(cookie), buf, count);
|
||||
}
|
||||
|
||||
static off_t
|
||||
rumpseek(void *cookie, off_t off, int whence)
|
||||
{
|
||||
|
||||
return rump_sys_lseek(C2FD(cookie), off, whence);
|
||||
}
|
||||
|
||||
static int
|
||||
rumpclose(void *cookie)
|
||||
{
|
||||
|
||||
return rump_sys_close(C2FD(cookie));
|
||||
}
|
||||
|
||||
int __sflags(const char *, int *); /* XXX */
|
||||
static FILE *
|
||||
rumpfopen(const char *path, const char *opts)
|
||||
{
|
||||
int fd, oflags;
|
||||
|
||||
__sflags(opts, &oflags);
|
||||
fd = rump_sys_open(path, oflags, 0777);
|
||||
if (fd == -1)
|
||||
return NULL;
|
||||
|
||||
return funopen((void *)(uintptr_t)fd,
|
||||
rumpread, rumpwrite, rumpseek, rumpclose);
|
||||
}
|
||||
|
||||
/*
|
||||
* Make sure mountd signal handler is executed from a thread context
|
||||
* instead of the signal handler. This avoids the signal handler
|
||||
* ruining our kernel context.
|
||||
*/
|
||||
static sem_t exportsem;
|
||||
static void
|
||||
signal_get_exportlist(int sig)
|
||||
{
|
||||
|
||||
sem_post(&exportsem);
|
||||
}
|
||||
|
||||
static void *
|
||||
exportlist_thread(void *arg)
|
||||
{
|
||||
|
||||
for (;;) {
|
||||
sem_wait(&exportsem);
|
||||
get_exportlist(0);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
#define statvfs1(a, b, c) rump_sys_statvfs1((a), (b), (c))
|
||||
#define getfh(a, b, c) rump_sys_getfh((a), (b), (c))
|
||||
#define nfssvc(a, b) rump_sys_nfssvc((a), (b))
|
||||
#define fopen(a, b) rumpfopen((a), (b))
|
||||
#define lstat(a, b) rump_sys_lstat((a), (b))
|
||||
#define stat(a, b) rump_sys_stat((a), (b))
|
||||
|
||||
/*
|
||||
* Mountd server for NFS mount protocol as described in:
|
||||
* NFS: Network File System Protocol Specification, RFC1094, Appendix A
|
||||
@ -261,14 +350,19 @@ static int noprivports;
|
||||
* "-d" to enable debugging
|
||||
* and "-n" to allow nonroot mount.
|
||||
*/
|
||||
void *mountd_main(void *);
|
||||
void *
|
||||
mountd_main(void *arg)
|
||||
#else
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
#endif
|
||||
{
|
||||
SVCXPRT *udptransp, *tcptransp, *udp6transp, *tcp6transp;
|
||||
struct netconfig *udpconf, *tcpconf, *udp6conf, *tcp6conf;
|
||||
int udpsock, tcpsock, udp6sock, tcp6sock;
|
||||
int xcreated = 0, s;
|
||||
int c, one = 1;
|
||||
int xcreated = 0;
|
||||
int one = 1;
|
||||
int maxrec = RPC_MAXDATASIZE;
|
||||
in_port_t forcedport = 0;
|
||||
#ifdef IPSEC
|
||||
@ -277,7 +371,8 @@ main(int argc, char **argv)
|
||||
#else
|
||||
#define ADDOPTS
|
||||
#endif
|
||||
|
||||
#ifndef MOUNTD_RUMP
|
||||
int s, c;
|
||||
while ((c = getopt(argc, argv, "dNnrp:" ADDOPTS)) != -1)
|
||||
switch (c) {
|
||||
#ifdef IPSEC
|
||||
@ -310,21 +405,34 @@ main(int argc, char **argv)
|
||||
};
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
grphead = NULL;
|
||||
exphead = NULL;
|
||||
mlhead = NULL;
|
||||
if (argc == 1)
|
||||
exname = *argv;
|
||||
else
|
||||
exname = _PATH_EXPORTS;
|
||||
openlog("mountd", LOG_PID | (debug ? LOG_PERROR : 0), LOG_DAEMON);
|
||||
(void)signal(SIGSYS, no_nfs);
|
||||
|
||||
s = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
|
||||
if (s < 0)
|
||||
have_v6 = 0;
|
||||
else
|
||||
close(s);
|
||||
(void)signal(SIGHUP, get_exportlist);
|
||||
#else
|
||||
extern sem_t gensem;
|
||||
pthread_t ptdummy;
|
||||
|
||||
svc_fdset_init(SVC_FDSET_MT);
|
||||
|
||||
sem_init(&exportsem, 0, 0);
|
||||
pthread_create(&ptdummy, NULL, exportlist_thread, NULL);
|
||||
exname = _PATH_EXPORTS;
|
||||
have_v6 = 0;
|
||||
(void)signal(SIGHUP, signal_get_exportlist);
|
||||
#endif
|
||||
grphead = NULL;
|
||||
exphead = NULL;
|
||||
mlhead = NULL;
|
||||
openlog("mountd", LOG_PID | (debug ? LOG_PERROR : 0), LOG_DAEMON);
|
||||
(void)signal(SIGSYS, no_nfs);
|
||||
|
||||
if (debug)
|
||||
(void)fprintf(stderr, "Getting export list.\n");
|
||||
@ -334,7 +442,6 @@ main(int argc, char **argv)
|
||||
get_mountlist();
|
||||
if (debug)
|
||||
(void)fprintf(stderr, "Here we go.\n");
|
||||
(void)signal(SIGHUP, get_exportlist);
|
||||
(void)signal(SIGTERM, send_umntall);
|
||||
|
||||
rpcb_unset(RPCPROG_MNT, RPCMNT_VER1, NULL);
|
||||
@ -463,6 +570,9 @@ main(int argc, char **argv)
|
||||
(void)signal(SIGQUIT, SIG_IGN);
|
||||
}
|
||||
pidfile(NULL);
|
||||
#ifdef MOUNTD_RUMP
|
||||
sem_post(&gensem);
|
||||
#endif
|
||||
svc_run();
|
||||
syslog(LOG_ERR, "Mountd died");
|
||||
exit(1);
|
||||
@ -535,10 +645,15 @@ mntsrv(struct svc_req *rqstp, SVCXPRT *transp)
|
||||
* Get the real pathname and make sure it is a file or
|
||||
* directory that exists.
|
||||
*/
|
||||
if (realpath(rpcpath, rdirpath) == 0 ||
|
||||
if (
|
||||
#ifndef MOUNTD_RUMP
|
||||
realpath(rpcpath, rdirpath) == NULL ||
|
||||
#else
|
||||
strcpy(rdirpath, rpcpath) == NULL ||
|
||||
#endif
|
||||
stat(rdirpath, &stb) < 0 ||
|
||||
(!S_ISDIR(stb.st_mode) && !S_ISREG(stb.st_mode)) ||
|
||||
statvfs(rdirpath, &fsb) < 0) {
|
||||
statvfs1(rdirpath, &fsb, ST_WAIT) < 0) {
|
||||
(void)chdir("/"); /* Just in case realpath doesn't */
|
||||
if (debug)
|
||||
(void)fprintf(stderr, "-> stat failed on %s\n",
|
||||
@ -860,7 +975,7 @@ parse_directory(const char *line, size_t lineno, struct grouplist *tgrp,
|
||||
if (!check_dirpath(line, lineno, cp))
|
||||
return 0;
|
||||
|
||||
if (statvfs(cp, fsp) == -1) {
|
||||
if (statvfs1(cp, fsp, ST_WAIT) == -1) {
|
||||
syslog(LOG_ERR, "\"%s\", line %ld: statvfs for `%s' failed: %m",
|
||||
line, (unsigned long)lineno, cp);
|
||||
return 0;
|
||||
@ -1211,6 +1326,9 @@ free_exp_grp(struct exportlist *ep, struct grouplist *grp)
|
||||
static struct exportlist *
|
||||
ex_search(fsid_t *fsid)
|
||||
{
|
||||
#ifdef MOUNTD_RUMP
|
||||
return exphead;
|
||||
#else
|
||||
struct exportlist *ep;
|
||||
|
||||
ep = exphead;
|
||||
@ -1221,6 +1339,7 @@ ex_search(fsid_t *fsid)
|
||||
ep = ep->ex_next;
|
||||
}
|
||||
return (ep);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
@ -2276,6 +2395,14 @@ add_mlist(char *hostp, char *dirp, int flags)
|
||||
(void)fclose(mlfile);
|
||||
}
|
||||
|
||||
#ifndef MOUNTD_RUMP
|
||||
static int
|
||||
umntall_each(caddr_t resultsp, struct sockaddr_in *raddr)
|
||||
{
|
||||
return (1);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* This function is called via. SIGTERM when the system is going down.
|
||||
* It sends a broadcast RPCMNT_UMNTALL.
|
||||
@ -2284,17 +2411,14 @@ add_mlist(char *hostp, char *dirp, int flags)
|
||||
static void
|
||||
send_umntall(int n)
|
||||
{
|
||||
#ifndef MOUNTD_RUMP
|
||||
(void)clnt_broadcast(RPCPROG_MNT, RPCMNT_VER1, RPCMNT_UMNTALL,
|
||||
(xdrproc_t)xdr_void, NULL, (xdrproc_t)xdr_void, NULL,
|
||||
(resultproc_t)umntall_each);
|
||||
#endif
|
||||
exit(0);
|
||||
}
|
||||
|
||||
static int
|
||||
umntall_each(caddr_t resultsp, struct sockaddr_in *raddr)
|
||||
{
|
||||
return (1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Free up a group list.
|
||||
|
Loading…
x
Reference in New Issue
Block a user