Beispiel #1
0
bool_t
mount_exportall_1_svc(struct svc_req *rqstp, void *argp, exports *resp)
{
	struct sockaddr_in *addr = nfs_getrpccaller_in(rqstp->rq_xprt);

	xlog(D_CALL, "exportall request from %s.", inet_ntoa(addr->sin_addr));
	*resp = get_exportlist();

	return 1;
}
Beispiel #2
0
void
mountd_svc_run(void)
{
	fd_set *fds = NULL;
	int fds_size = 0;
	extern fd_set *__svc_fdset;
	extern int __svc_fdsetsize;

	for (;;) {
		if (gothup) {
			get_exportlist();
			gothup = 0;
		}
		if (gotterm) {
			(void) clnt_broadcast(RPCPROG_MNT, RPCMNT_VER1,
			    RPCMNT_UMNTALL, xdr_void, (caddr_t)0, xdr_void,
			    (caddr_t)0, umntall_each);
			exit(0);
		}
		if (__svc_fdset) {
			int bytes = howmany(__svc_fdsetsize, NFDBITS) *
			    sizeof(fd_mask);
			if (fds_size != __svc_fdsetsize) {
				if (fds)
					free(fds);
				fds = (fd_set *)malloc(bytes);  /* XXX */
				fds_size = __svc_fdsetsize;
			}
			memcpy(fds, __svc_fdset, bytes);
		} else {
			if (fds)
				free(fds);
			fds = NULL;
		}
		switch (select(svc_maxfd+1, fds, 0, 0, (struct timeval *)0)) {
		case -1:
			if (errno == EINTR)
				break;
			perror("mountd_svc_run: - select failed");
			if (fds)
				free(fds);
			return;
		case 0:
			break;
		default:
			svc_getreqset2(fds, svc_maxfd+1);
			break;
		}
	}
}
Beispiel #3
0
/*
 * Mountd server for NFS mount protocol as described in:
 * NFS: Network File System Protocol Specification, RFC1094, Appendix A
 * The optional arguments are the exports file name
 * default: _PATH_EXPORTS
 * "-d" to enable debugging
 * and "-n" to allow nonroot mount.
 */
int
main(int argc, char *argv[])
{
	SVCXPRT *udptransp, *tcptransp;
	FILE *pidfile;
	int c;

	while ((c = getopt(argc, argv, "dnr")) != -1)
		switch (c) {
		case 'd':
			debug = 1;
			break;
		case 'n':
			resvport_only = 0;
			break;
		case 'r':
			/* Compatibility */
			break;
		default:
			fprintf(stderr, "usage: mountd [-dn] [exportsfile]\n");
			exit(1);
		}
	argc -= optind;
	argv += optind;
	grphead = NULL;
	exphead = NULL;
	mlhead = NULL;

	strlcpy(exname, argc == 1? *argv : _PATH_EXPORTS, sizeof(exname));

	openlog("mountd", LOG_PID, LOG_DAEMON);
	if (debug)
		fprintf(stderr, "Getting export list.\n");
	get_exportlist();
	if (debug)
		fprintf(stderr, "Getting mount list.\n");
	get_mountlist();
	if (debug)
		fprintf(stderr, "Here we go.\n");
	if (debug == 0) {
		daemon(0, 0);
		signal(SIGINT, SIG_IGN);
		signal(SIGQUIT, SIG_IGN);
	}
	/* Store pid in file unless mountd is already running */
	pidfile = fopen(_PATH_MOUNTDPID, "r");
	if (pidfile != NULL) {
		if (fscanf(pidfile, "%d\n", &c) > 0 && c > 0) {
			if (kill(c, 0) == 0) {
				syslog(LOG_ERR, "Already running (pid %d)", c);
				exit(1);
			}
		}
		pidfile = freopen(_PATH_MOUNTDPID, "w", pidfile);
	} else {
		pidfile = fopen(_PATH_MOUNTDPID, "w");
	}
	if (pidfile) {
		fprintf(pidfile, "%ld\n", (long)getpid());
		fclose(pidfile);
	}

	signal(SIGHUP, (void (*)(int)) new_exportlist);
	signal(SIGTERM, (void (*)(int)) send_umntall);
	signal(SIGSYS, SIG_IGN);
	if ((udptransp = svcudp_create(RPC_ANYSOCK)) == NULL ||
	    (tcptransp = svctcp_create(RPC_ANYSOCK, 0, 0)) == NULL) {
		syslog(LOG_ERR, "Can't create socket");
		exit(1);
	}
	pmap_unset(RPCPROG_MNT, RPCMNT_VER1);
	pmap_unset(RPCPROG_MNT, RPCMNT_VER3);
	if (!svc_register(udptransp, RPCPROG_MNT, RPCMNT_VER1, mntsrv, IPPROTO_UDP) ||
	    !svc_register(udptransp, RPCPROG_MNT, RPCMNT_VER3, mntsrv, IPPROTO_UDP) ||
	    !svc_register(tcptransp, RPCPROG_MNT, RPCMNT_VER1, mntsrv, IPPROTO_TCP) ||
	    !svc_register(tcptransp, RPCPROG_MNT, RPCMNT_VER3, mntsrv, IPPROTO_TCP)) {
		syslog(LOG_ERR, "Can't register mount");
		exit(1);
	}
	mountd_svc_run();
	syslog(LOG_ERR, "Mountd died");
	exit(1);
}