View | Details | Raw Unified | Return to bug 205193 | Differences between
and this patch

Collapse All | Expand All

(-)usr.sbin/nfsuserd/nfsuserd.c (-50 / +34 lines)
Lines 35-40 __FBSDID("$FreeBSD: head/usr.sbin/nfsuse Link Here
35
#include <sys/mount.h>
35
#include <sys/mount.h>
36
#include <sys/socket.h>
36
#include <sys/socket.h>
37
#include <sys/socketvar.h>
37
#include <sys/socketvar.h>
38
#include <sys/stat.h>
38
#include <sys/time.h>
39
#include <sys/time.h>
39
#include <sys/ucred.h>
40
#include <sys/ucred.h>
40
#include <sys/vnode.h>
41
#include <sys/vnode.h>
Lines 43-48 __FBSDID("$FreeBSD: head/usr.sbin/nfsuse Link Here
43
#include <nfs/nfssvc.h>
44
#include <nfs/nfssvc.h>
44
45
45
#include <rpc/rpc.h>
46
#include <rpc/rpc.h>
47
#include <rpc/rpc_com.h>
46
48
47
#include <fs/nfs/rpcv2.h>
49
#include <fs/nfs/rpcv2.h>
48
#include <fs/nfs/nfsproto.h>
50
#include <fs/nfs/nfsproto.h>
Lines 73-78 static bool_t xdr_getid(XDR *, caddr_t); Link Here
73
static bool_t	xdr_getname(XDR *, caddr_t);
75
static bool_t	xdr_getname(XDR *, caddr_t);
74
static bool_t	xdr_retval(XDR *, caddr_t);
76
static bool_t	xdr_retval(XDR *, caddr_t);
75
77
78
#ifndef _PATH_NFSUSERDSOCK
79
#define _PATH_NFSUSERDSOCK	"/var/run/nfsuserd.sock"
80
#endif
76
#define	MAXNAME		1024
81
#define	MAXNAME		1024
77
#define	MAXNFSUSERD	20
82
#define	MAXNFSUSERD	20
78
#define	DEFNFSUSERD	4
83
#define	DEFNFSUSERD	4
Lines 103-117 main(int argc, char *argv[]) Link Here
103
	struct nfsd_idargs nid;
108
	struct nfsd_idargs nid;
104
	struct passwd *pwd;
109
	struct passwd *pwd;
105
	struct group *grp;
110
	struct group *grp;
106
	int sock, one = 1;
111
	int oldmask, sock;
107
	SVCXPRT *udptransp;
112
	SVCXPRT *xprt;
108
	u_short portnum;
109
	sigset_t signew;
113
	sigset_t signew;
110
	char hostname[MAXHOSTNAMELEN + 1], *cp;
114
	char hostname[MAXHOSTNAMELEN + 1], *cp;
111
	struct addrinfo *aip, hints;
115
	struct addrinfo *aip, hints;
112
	static uid_t check_dups[MAXUSERMAX];
116
	static uid_t check_dups[MAXUSERMAX];
113
	gid_t grps[NGROUPS];
117
	gid_t grps[NGROUPS];
114
	int ngroup;
118
	int ngroup;
119
	struct sockaddr_un sun;
115
120
116
	if (modfind("nfscommon") < 0) {
121
	if (modfind("nfscommon") < 0) {
117
		/* Not present in kernel, try loading it */
122
		/* Not present in kernel, try loading it */
Lines 245-290 main(int argc, char *argv[]) Link Here
245
	for (i = 0; i < nfsuserdcnt; i++)
250
	for (i = 0; i < nfsuserdcnt; i++)
246
		slaves[i] = (pid_t)-1;
251
		slaves[i] = (pid_t)-1;
247
252
248
	/*
253
	memset(&sun, 0, sizeof sun);
249
	 * Set up the service port to accept requests via UDP from
254
	sun.sun_family = AF_LOCAL;
250
	 * localhost (127.0.0.1).
255
	unlink(_PATH_NFSUSERDSOCK);
251
	 */
256
	strcpy(sun.sun_path, _PATH_NFSUSERDSOCK);
252
	if ((sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0)
257
	sun.sun_len = SUN_LEN(&sun);
253
		err(1, "cannot create udp socket");
258
	sock = socket(AF_LOCAL, SOCK_STREAM, 0);
254
259
	if (sock < 0)
255
	/*
260
		err(1, "Can't create local nfsuserd socket");
256
	 * Not sure what this does, so I'll leave it here for now.
261
	oldmask = umask(S_IXUSR | S_IRWXG | S_IRWXO);
257
	 */
262
	if (bind(sock, (struct sockaddr *)&sun, sun.sun_len) < 0)
258
	setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one));
263
		err(1, "Can't bind local nfsuserd socket");
259
	
264
	umask(oldmask);
260
	if ((udptransp = svcudp_create(sock)) == NULL)
265
	if (listen(sock, SOMAXCONN) < 0)
261
		err(1, "Can't set up socket");
266
		err(1, "Can't listen on local nfsuserd socket");
262
267
	xprt = svc_vc_create(sock, RPC_MAXDATASIZE, RPC_MAXDATASIZE);
263
	/*
268
	if (xprt == NULL)
264
	 * By not specifying a protocol, it is linked into the
269
		err(1, "Can't create transport for local nfsuserd socket");
265
	 * dispatch queue, but not registered with portmapper,
270
	if (!svc_reg(xprt, RPCPROG_NFSUSERD, RPCNFSUSERD_VERS, nfsuserdsrv,
266
	 * which is just what I want.
271
	    NULL))
267
	 */
272
		err(1, "Can't register service for local nfsuserd socket");
268
	if (!svc_register(udptransp, RPCPROG_NFSUSERD, RPCNFSUSERD_VERS,
269
	    nfsuserdsrv, 0))
270
		err(1, "Can't register nfsuserd");
271
273
272
	/*
274
	/*
273
	 * Tell the kernel what my port# is.
275
	 * Tell the kernel what the socket's path is.
274
	 */
276
	 */
275
	portnum = htons(udptransp->xp_port);
276
#ifdef DEBUG
277
#ifdef DEBUG
277
	printf("portnum=0x%x\n", portnum);
278
	printf("sockpath=%s\n", _PATH_NFSUSERDSOCK);
278
#else
279
#else
279
	if (nfssvc(NFSSVC_NFSUSERDPORT, (caddr_t)&portnum) < 0) {
280
	if (nfssvc(NFSSVC_NFSUSERDPORT | NFSSVC_NEWSTRUCT, _PATH_NFSUSERDSOCK)
281
	    < 0) {
280
		if (errno == EPERM) {
282
		if (errno == EPERM) {
281
			fprintf(stderr,
283
			fprintf(stderr,
282
			    "Can't start nfsuserd when already running");
284
			    "Can't start nfsuserd when already running");
283
			fprintf(stderr,
285
			fprintf(stderr,
284
			    " If not running, use the -force option.\n");
286
			    " If not running, use the -force option.\n");
285
		} else {
287
		} else
286
			fprintf(stderr, "Can't do nfssvc() to add port\n");
288
			fprintf(stderr, "Can't do nfssvc() to add socket\n");
287
		}
288
		exit(1);
289
		exit(1);
289
	}
290
	}
290
#endif
291
#endif
Lines 455-482 nfsuserdsrv(struct svc_req *rqstp, SVCXP Link Here
455
	struct passwd *pwd;
456
	struct passwd *pwd;
456
	struct group *grp;
457
	struct group *grp;
457
	int error;
458
	int error;
458
	u_short sport;
459
	struct info info;
459
	struct info info;
460
	struct nfsd_idargs nid;
460
	struct nfsd_idargs nid;
461
	u_int32_t saddr;
462
	gid_t grps[NGROUPS];
461
	gid_t grps[NGROUPS];
463
	int ngroup;
462
	int ngroup;
464
463
465
	/*
466
	 * Only handle requests from 127.0.0.1 on a reserved port number.
467
	 * (Since a reserved port # at localhost implies a client with
468
	 *  local root, there won't be a security breach. This is about
469
	 *  the only case I can think of where a reserved port # means
470
	 *  something.)
471
	 */
472
	sport = ntohs(transp->xp_raddr.sin_port);
473
	saddr = ntohl(transp->xp_raddr.sin_addr.s_addr);
474
	if ((rqstp->rq_proc != NULLPROC && sport >= IPPORT_RESERVED) ||
475
	    saddr != 0x7f000001) {
476
		syslog(LOG_ERR, "req from ip=0x%x port=%d\n", saddr, sport);
477
		svcerr_weakauth(transp);
478
		return;
479
	}
480
	switch (rqstp->rq_proc) {
464
	switch (rqstp->rq_proc) {
481
	case NULLPROC:
465
	case NULLPROC:
482
		if (!svc_sendreply(transp, (xdrproc_t)xdr_void, NULL))
466
		if (!svc_sendreply(transp, (xdrproc_t)xdr_void, NULL))

Return to bug 205193