Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 22 Nov 1998 20:59:44 +0000
From:      dmlb@ragnet.demon.co.uk
To:        FreeBSD-gnats-submit@FreeBSD.ORG
Cc:        dmlb@ragnet.demon.co.uk
Subject:   kern/8797: Addition to mount_portal
Message-ID:  <E0zhgbg-0000Jz-00@ragnet.demon.co.uk>

next in thread | raw e-mail | index | archive | help

>Number:         8797
>Category:       kern
>Synopsis:       addition of tcplisten namespace to portal FS
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:
>Keywords:
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sun Nov 22 13:10:00 PST 1998
>Last-Modified:
>Originator:     Duncan Barclay
>Organization:
>Release:        FreeBSD 2.2.6-RELEASE i386
>Environment:

	-current and -stable

>Description:

	Adds tcplisten namespace to the portal filesystem. Will
	return a file descriptor to an accept'd socket.
	
	Write servers with /bin/sh

>How-To-Repeat:

	n/a

>Fix:
	
	Three files included in shar archive. All taken from current,
	but should applied to -stable as well.

	I may have overlapped some of these with previous PRs, sorry!

	Apply in src/sbin/mount_portal.

# This is a shell archive.  Save it in a file, remove anything before
# this line, and then unpack it by entering "sh file".  Note, it may
# create directories; files and directories will be owned by you and
# have default permissions.
#
# This archive contains:
#
#	Makefile
#	portald.h
#	pt_conf.c
#	pt_tcplisten.c
#
echo x - Makefile
sed 's/^X//' >Makefile << 'END-of-Makefile'
X#	From: @(#)Makefile	8.3 (Berkeley) 3/27/94
X#	$Id: Makefile,v 1.8 1998/01/20 10:40:04 bde Exp $
X
XPROG=	mount_portal
XSRCS=	mount_portal.c activate.c conf.c getmntopts.c pt_conf.c \
X	pt_exec.c pt_file.c pt_tcp.c pt_tcplisten.c
XMAN8=	mount_portal.8
X
XMOUNT=	${.CURDIR}/../mount
XCFLAGS+= -I${.CURDIR}/../../sys -I${MOUNT}
X.PATH:	${MOUNT}
X
X.include <bsd.prog.mk>
END-of-Makefile
echo x - portald.h
sed 's/^X//' >portald.h << 'END-of-portald.h'
X/*
X * Copyright (c) 1992, 1993
X *	The Regents of the University of California.  All rights reserved.
X * All rights reserved.
X *
X * This code is derived from software donated to Berkeley by
X * Jan-Simon Pendry.
X *
X * Redistribution and use in source and binary forms, with or without
X * modification, are permitted provided that the following conditions
X * are met:
X * 1. Redistributions of source code must retain the above copyright
X *    notice, this list of conditions and the following disclaimer.
X * 2. Redistributions in binary form must reproduce the above copyright
X *    notice, this list of conditions and the following disclaimer in the
X *    documentation and/or other materials provided with the distribution.
X * 3. All advertising materials mentioning features or use of this software
X *    must display the following acknowledgement:
X *	This product includes software developed by the University of
X *	California, Berkeley and its contributors.
X * 4. Neither the name of the University nor the names of its contributors
X *    may be used to endorse or promote products derived from this software
X *    without specific prior written permission.
X *
X * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
X * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
X * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
X * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
X * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
X * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
X * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
X * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
X * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
X * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
X * SUCH DAMAGE.
X *
X *	@(#)portald.h	8.1 (Berkeley) 6/5/93
X *
X * $Id: portald.h,v 1.3 1997/02/22 14:32:55 peter Exp $
X */
X
X#include <sys/cdefs.h>
X#include <miscfs/portal/portal.h>
X
X/*
X * Meta-chars in an RE.  Paths in the config file containing
X * any of these characters will be matched using regexec, other
X * paths will be prefix-matched.
X */
X#define RE_CHARS ".|()[]*+?\\^$"
X
Xtypedef struct qelem qelem;
X
Xstruct qelem {
X	qelem *q_forw;
X	qelem *q_back;
X};
X
Xtypedef struct provider provider;
Xstruct provider {
X	char *pr_match;
X	int (*pr_func) __P((struct portal_cred *,
X				char *key, char **v, int so, int *fdp));
X};
Xextern provider providers[];
X
X/*
X * Portal providers
X */
Xextern int portal_exec __P((struct portal_cred *,
X				char *key, char **v, int so, int *fdp));
Xextern int portal_file __P((struct portal_cred *,
X				char *key, char **v, int so, int *fdp));
Xextern int portal_tcp __P((struct portal_cred *,
X				char *key, char **v, int so, int *fdp));
Xextern int portal_tcplisten __P((struct portal_cred *,
X				char *key, char **v, int so, int *fdp));
X
X/*
X * Global functions
X */
Xextern void activate __P((qelem *q, int so));
Xextern char **conf_match __P((qelem *q, char *key));
Xextern void conf_read __P((qelem *q, char *conf));
END-of-portald.h
echo x - pt_conf.c
sed 's/^X//' >pt_conf.c << 'END-of-pt_conf.c'
X/*
X * Copyright (c) 1992, 1993
X *	The Regents of the University of California.  All rights reserved.
X * All rights reserved.
X *
X * This code is derived from software donated to Berkeley by
X * Jan-Simon Pendry.
X *
X * Redistribution and use in source and binary forms, with or without
X * modification, are permitted provided that the following conditions
X * are met:
X * 1. Redistributions of source code must retain the above copyright
X *    notice, this list of conditions and the following disclaimer.
X * 2. Redistributions in binary form must reproduce the above copyright
X *    notice, this list of conditions and the following disclaimer in the
X *    documentation and/or other materials provided with the distribution.
X * 3. All advertising materials mentioning features or use of this software
X *    must display the following acknowledgement:
X *	This product includes software developed by the University of
X *	California, Berkeley and its contributors.
X * 4. Neither the name of the University nor the names of its contributors
X *    may be used to endorse or promote products derived from this software
X *    without specific prior written permission.
X *
X * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
X * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
X * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
X * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
X * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
X * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
X * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
X * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
X * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
X * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
X * SUCH DAMAGE.
X *
X *	@(#)pt_conf.c	8.1 (Berkeley) 6/5/93
X */
X
X#ifndef lint
Xstatic const char rcsid[] =
X	"$Id: pt_conf.c,v 1.4 1998/07/06 07:19:25 charnier Exp $";
X#endif /* not lint */
X
X#include <sys/types.h>
X#include <sys/param.h>
X#include "portald.h"
X
Xprovider providers[] = {
X	{ "exec",	portal_exec },
X	{ "file",	portal_file },
X	{ "tcp",	portal_tcp },
X	{ "tcplisten",	portal_tcplisten },
X	{ 0, 0 }
X};
END-of-pt_conf.c
echo x - pt_tcplisten.c
sed 's/^X//' >pt_tcplisten.c << 'END-of-pt_tcplisten.c'
X/*
X * Copyright (c) 1992, 1993
X *  The Regents of the University of California.  All rights reserved.
X * All rights reserved.
X *
X * This code is derived from software donated to Berkeley by
X * Jan-Simon Pendry.
X *
X * Modified by Duncan Barclay.
X *
X * Redistribution and use in source and binary forms, with or without
X * modification, are permitted provided that the following conditions
X * are met:
X * 1. Redistributions of source code must retain the above copyright
X *    notice, this list of conditions and the following disclaimer.
X * 2. Redistributions in binary form must reproduce the above copyright
X *    notice, this list of conditions and the following disclaimer in the
X *    documentation and/or other materials provided with the distribution.
X * 3. All advertising materials mentioning features or use of this software
X *    must display the following acknowledgement:
X *  This product includes software developed by the University of
X *  California, Berkeley and its contributors.
X * 4. Neither the name of the University nor the names of its contributors
X *    may be used to endorse or promote products derived from this software
X *    without specific prior written permission.
X *
X * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
X * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
X * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
X * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
X * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
X * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
X * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
X * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
X * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
X * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
X * SUCH DAMAGE.
X *
X *  @(#)pt_tcp.c  8.3 (Berkeley) 3/27/94
X *
X * pt_tcp.c,v 1.1.1.1 1994/05/26 06:34:34 rgrimes Exp
X */
X
X#include <stdio.h>
X#include <unistd.h>
X#include <stdlib.h>
X#include <errno.h>
X#include <strings.h>
X#include <sys/types.h>
X#include <sys/param.h>
X#include <sys/syslog.h>
X#include <sys/socket.h>
X#include <netinet/in.h>
X#include <arpa/inet.h>
X#include <netdb.h>
X
X#include "portald.h"
X
X/*
X * Key will be tcplisten/host/port
X *
X * Create a TCP socket bound to the requested host and port.
X * If the host is "ANY" the receving address will be set to INADDR_ANY.
X * If the port is 0 the caller must find out the returned port number
X * using a call to getsockname.
X *
X */
Xint portal_tcplisten(pcr, key, v, kso, fdp)
X	struct portal_cred *pcr;
X	char *key;
X	char **v;
X	int kso;
X	int *fdp;
X{
X	char host[MAXHOSTNAMELEN];
X	char port[MAXHOSTNAMELEN];
X	char *p = key + (v[1] ? strlen(v[1]) : 0);
X	char *q;
X	struct hostent *hp;
X	struct servent *sp;
X	struct in_addr **ipp;
X	struct in_addr *ip[2];
X	struct in_addr ina;
X	u_short s_port;
X	int any = 0;
X	struct sockaddr_in sain;
X
X	q = strchr(p, '/');
X	if (q == 0 || q - p >= sizeof(host))
X		return (EINVAL);
X	*q = '\0';
X	strcpy(host, p);
X	p = q + 1;
X
X	q = strchr(p, '/');
X	if (q)
X		*q = '\0';
X	if (strlen(p) >= sizeof(port))
X		return (EINVAL);
X	strcpy(port, p);
X
X	if (strcmp(host, "ANY") == 0) {
X		any = 1;
X	} else {
X		hp = gethostbyname(host);
X		if (hp != 0) {
X			ipp = (struct in_addr **) hp->h_addr_list;
X		} else {
X			ina.s_addr = inet_addr(host);
X			if (ina.s_addr == INADDR_NONE)
X				return (EINVAL);
X			ip[0] = &ina;
X			ip[1] = 0;
X			ipp = ip;
X		}
X	}
X#ifdef DEBUG
X	if (any)
X		printf("INADDR_ANY to be used for hostname\n");
X	else
X		printf("inet address for %s is %s\n", host, inet_ntoa(*ipp[0]));
X#endif
X
X	sp = getservbyname(port, "tcp");
X	if (sp != NULL) {
X		s_port = (u_short) sp->s_port;
X        } else {
X		s_port = strtoul(port, &p, 0);
X		if (*p != '\0')
X			return (EINVAL);
X		s_port = htons(s_port);
X	}
X	if ((ntohs(s_port) != 0) &&
X	    (ntohs(s_port) <= IPPORT_RESERVED) &&
X	    (pcr->pcr_uid != 0))
X		return (EPERM);
X#ifdef DEBUG
X	printf("port number for %s is %d\n", port, ntohs(s_port));
X#endif
X
X	memset(&sain, 0, sizeof(sain));
X	sain.sin_len = sizeof(sain);
X	sain.sin_family = AF_INET;
X	sain.sin_port = s_port;
X
X	if (any) {
X		int so;
X		int sock;
X
X		so = socket(AF_INET, SOCK_STREAM, 0);
X		if (so < 0) {
X			syslog(LOG_ERR, "socket: %m");
X			return (errno);
X		}
X
X		sain.sin_addr.s_addr = INADDR_ANY;
X		if (bind(so, (struct sockaddr *) &sain, sizeof(sain)) == 0) {
X			listen(so, 1);
X			if ((sock = accept(so, (struct sockaddr *)0, (int *)0)) == -1) {
X				syslog(LOG_ERR, "accept: %m");
X				(void) close(so);
X				return (errno);
X			}
X			*fdp = sock;
X			(void) close(so);
X			return (0);
X		}
X		syslog(LOG_ERR, "bind: %m");
X		(void) close(so);
X		return (errno);
X	}
X
X	while (ipp[0]) {
X		int so;
X		int sock;
X
X		so = socket(AF_INET, SOCK_STREAM, 0);
X		if (so < 0) {
X			syslog(LOG_ERR, "socket: %m");
X			return (errno);
X		}
X
X		sain.sin_addr = *ipp[0];
X		if (bind(so, (struct sockaddr *) &sain, sizeof(sain)) == 0) {
X			listen(so, 1);
X			if ((sock = accept(so, (struct sockaddr *)0, (int *)0)) == -1) {
X				syslog(LOG_ERR, "accept: %m");
X				(void) close(so);
X				return (errno);
X			}
X			*fdp = sock;
X			(void) close(so);
X			return (0);
X		}
X		(void) close(so);
X
X		ipp++;
X	}
X
X	syslog(LOG_ERR, "bind: %m");
X	return (errno);
X
X}
END-of-pt_tcplisten.c
exit
>Audit-Trail:
>Unformatted:

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?E0zhgbg-0000Jz-00>