From dmlb@ragnet.demon.co.uk  Sun Nov 22 13:05:58 1998
Received: from post.mail.demon.net (post-20.mail.demon.net [194.217.242.27])
          by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id NAA12514
          for <FreeBSD-gnats-submit@freebsd.org>; Sun, 22 Nov 1998 13:05:57 -0800 (PST)
          (envelope-from dmlb@ragnet.demon.co.uk)
Received: from [158.152.46.40] (helo=ragnet.demon.co.uk)
	by post.mail.demon.net with smtp (Exim 2.053 #1)
	id 0zhgh7-0001WG-00
	for FreeBSD-gnats-submit@freebsd.org; Sun, 22 Nov 1998 21:05:21 +0000
Received: from dmlb by ragnet.demon.co.uk with local (Exim 1.82 #1)
	id 0zhgf6-0000N0-00; Sun, 22 Nov 1998 21:03:16 +0000
Message-Id: <E0zhgf6-0000N0-00@ragnet.demon.co.uk>
Date: Sun, 22 Nov 1998 21:03:16 +0000
From: dmlb@ragnet.demon.co.uk
Reply-To: dmlb@ragnet.demon.co.uk
To: FreeBSD-gnats-submit@freebsd.org
Cc: dmlb@ragnet.demon.co.uk
Subject: Addition to /usr/share/examples
X-Send-Pr-Version: 3.2

>Number:         8796
>Category:       misc
>Synopsis:       Additional example directory for /usr/share
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sun Nov 22 13:10:00 PST 1998
>Closed-Date:    Tue Dec 15 11:06:48 PST 1998
>Last-Modified:  Tue Dec 15 11:06:53 PST 1998
>Originator:     Duncan Barclay
>Release:        FreeBSD 2.2.6-RELEASE i386
>Organization:
>Environment:

	Examples documenting how to play with the portal filesystem.

>Description:

>How-To-Repeat:

>Fix:
	
	Shar archive of /usr/share/examples/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:
#
#	portal
#	portal/portal.conf
#	portal/README
#
echo c - portal
mkdir -p portal > /dev/null 2>&1
echo x - portal/portal.conf
sed 's/^X//' >portal/portal.conf << 'END-of-portal/portal.conf'
Xtcp/		tcp tcp/
Xtcplisten/	tcplisten tcplisten/
Xfs/		file fs/
END-of-portal/portal.conf
echo x - portal/README
sed 's/^X//' >portal/README << 'END-of-portal/README'
X
XThis contains a couple of examples for using the portal filing system.
X
XThe portal file system provides a way of obtaining a file descriptor
Xto a filesystem object (i.e. something that is accessed by open(2),
Xpipe(2), socket(2) or socketpair(2)) via the filesystem namespace.
XAt present the only file descriptor supported are TCP sockets and
Xfiles.
X
XFirst off mount the filesystem using something like:
X
X# mount_portal /usr/share/examples/portal/portal.conf /p
X
XThen you should be able to do things like
X# cat /p/tcp/localhost/daytime
XSun Nov 22 17:50:09 1998
X(assuming inetd is running the daytime service, by default it is off)
X
XOr, how about this security hole
X# cat /p/fs/etc/motd
XFreeBSD 2.2.6-RELEASE (COMPUTER) #0: Sat Aug 22 17:11:37 BST 1998
X
XWelcome to FreeBSD!
X
X# mkdir -p /tmp/root
X# cd /tmp/root
X# mkdir bin p
X# cp /bin/sh /bin/cat bin
X# mount_portal /usr/share/examples/portal/portal.conf /tmp/root/p
X# chroot /tmp/root
X# pwd
X/
X# echo *
Xbin p
X# cat /etc/motd
Xcat: /etc/motd: No such file or directory
X# cat /p/fs/etc/motd
XFreeBSD 2.2.6-RELEASE (COMPUTER) #0: Sat Aug 22 17:11:37 BST 1998
X
XWelcome to FreeBSD!
X
XFinally, a very simple example of the listening server is available,
Xfire up two xterms. In the first 
X
Xxterm-1$ cat /p/tcplisten/ANY/6666
X(the ANY is a wildcard just like using INADDR_ANY, any resolvable host
Xcan be used).
X
XIn the second xterm
Xxterm-2$ echo "hello there" >/p/tcp/localhost/6666
X
XYou should see the "hello there" string appear on the first terminal.
X
XUnprivilged users can't create servers on privalged ports.
Xxterm-1$ cat /p/tcplisten/ANY/666         
Xcat: /p/tcplisten/ANY/666: Operation not permitted
X
Xbut root can
Xxterm-1# cat /p/tcplisten/ANY/666
X
XIn the second
Xxterm-2$ echo "hello there" >/p/tcp/localhost/666
Xshould produce the expected response.
X
XYou can also swap the client/server read and write commands etc.
END-of-portal/README
exit

>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: dillon 
State-Changed-When: Tue Dec 15 11:06:48 PST 1998 
State-Changed-Why:  
Committed adjustments to freebsd-current 
>Unformatted:
