aboutsummaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorDiomidis Spinellis <dds@FreeBSD.org>2005-04-10 07:58:05 +0000
committerDiomidis Spinellis <dds@FreeBSD.org>2005-04-10 07:58:05 +0000
commitc82b2d8a1f174f32406f5f2b2995c368272bff8d (patch)
tree75a41ff10f998e6ecef21ac98479b92446f8c38e /usr.sbin
parent2ec3152bc2454e0fcc0bcb54a7eaf590307e9309 (diff)
Notes
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/mount_portalfs/Makefile4
-rw-r--r--usr.sbin/mount_portalfs/mount_portalfs.897
-rw-r--r--usr.sbin/mount_portalfs/mount_portalfs.c6
-rw-r--r--usr.sbin/mount_portalfs/portal.conf2
-rw-r--r--usr.sbin/mount_portalfs/portald.h5
-rw-r--r--usr.sbin/mount_portalfs/pt_conf.c1
-rw-r--r--usr.sbin/mount_portalfs/pt_file.c13
7 files changed, 102 insertions, 26 deletions
diff --git a/usr.sbin/mount_portalfs/Makefile b/usr.sbin/mount_portalfs/Makefile
index 56667f1653dc0..610ac233b5b0e 100644
--- a/usr.sbin/mount_portalfs/Makefile
+++ b/usr.sbin/mount_portalfs/Makefile
@@ -2,8 +2,8 @@
# $FreeBSD$
PROG= mount_portalfs
-SRCS= mount_portalfs.c activate.c conf.c getmntopts.c pt_conf.c \
- pt_exec.c pt_file.c pt_tcp.c pt_tcplisten.c
+SRCS= mount_portalfs.c activate.c conf.c cred.c getmntopts.c pt_conf.c \
+ pt_exec.c pt_file.c pt_pipe.c pt_tcp.c pt_tcplisten.c
MAN= mount_portalfs.8
MOUNT= ${.CURDIR}/../../sbin/mount
diff --git a/usr.sbin/mount_portalfs/mount_portalfs.8 b/usr.sbin/mount_portalfs/mount_portalfs.8
index 99a6d675f4d32..52f41e25dafd8 100644
--- a/usr.sbin/mount_portalfs/mount_portalfs.8
+++ b/usr.sbin/mount_portalfs/mount_portalfs.8
@@ -33,7 +33,7 @@
.\" @(#)mount_portal.8 8.3 (Berkeley) 3/27/94
.\" $FreeBSD$
.\"
-.Dd March 27, 1994
+.Dd April 10, 2005
.Dt MOUNT_PORTALFS 8
.Os
.Sh NAME
@@ -86,10 +86,34 @@ By convention, the portal daemon divides the namespace into sub-namespaces,
each of which handles objects of a particular type.
.Pp
The following sub-namespaces are currently implemented:
-.Pa tcplisten ,
-.Pa tcp
+.Pa fs ,
+.Pa pipe ,
+.Pa tcp ,
and
-.Pa fs .
+.Pa tcplisten .
+.Pp
+The
+.Pa fs
+namespace opens the named file, starting back at the root directory.
+This can be used to provide a controlled escape path from
+a chrooted environment.
+.Pp
+The
+.Pa pipe
+namespace executes the named command, starting back at the root directory.
+The command's arguments can be provided after the command's name,
+by separating them with spaces or tabs.
+Files opened for reading in the
+.Pa pipe
+namespace will receive their input from the command's standard output;
+files opened for writing will send the data of write operations
+to the command's standard input.
+.Pp
+The
+.Pa tcp
+namespace takes a slash separated hostname and a port and
+creates an open TCP/IP connection.
+.Pp
The
.Pa tcplisten
namespace takes a slash separated hostname and port and creates a TCP/IP
@@ -103,15 +127,6 @@ discovered by calling
with the returned file descriptor.
Privileged ports can only be bound to
by the super-user.
-The
-.Pa tcp
-namespace takes a hostname and a port (slash separated) and
-creates an open TCP/IP connection.
-The
-.Pa fs
-namespace opens the named file, starting back at the root directory.
-This can be used to provide a controlled escape path from
-a chrooted environment.
.Sh "CONFIGURATION FILE"
The configuration file contains a list of rules.
Each rule takes one line and consists of two or more
@@ -130,16 +145,72 @@ Subsequent fields are passed to the creation function.
tcplisten/ tcplisten tcplisten/
tcp/ tcp tcp/
fs/ file fs/
+pipe/ pipe pipe/
.Ed
.Sh FILES
.Bl -tag -width /p/* -compact
.It Pa /p/*
.El
+.Sh EXAMPLES
+Display the greeting of the
+.Fx
+.Tn SMTP
+server.
+.Pp
+.Dl "head -1 /p/tcp/mx1.freebsd.org/smtp"
+.Pp
+Implement a (single-threaded) echo server:
+.Pp
+.Bd -unfilled -literal -offset indent
+while :
+do
+ (exec 3<>/p/tcplisten/ANY/echo && cat -u <&3 >&3)
+done
+.Ed
+.Pp
+Gather data from two sources.
+Verify that two remote files are identical:
+.Pp
+.Bd -unfilled -literal -offset indent
+diff -q '/p/pipe/usr/bin/fetch -o - \\
+ ftp://ftp1.freebsd.org/pub/FreeBSD/README.TXT' \\
+ '/p/pipe/usr/bin/fetch -o - \\
+ ftp://ftp2.freebsd.org/pub/FreeBSD/README.TXT'
+.Ed
+.Pp
+Scatter data to two sinks.
+Record a remote
+.Tn CD
+.Tn ISO
+image and calculate its checksum:
+.Pp
+.Bd -unfilled -literal -offset indent
+fetch -o - ftp://ftp5.freebsd.org/.../disc.iso |
+tee '/p/pipe/usr/local/bin/cdrecord -' |
+md5
+.Ed
+.Pp
+Create an
+.Tn XML
+view of the password file:
+.Pp
+.Bd -unfilled -literal -offset indent
+ln -s '/p/pipe/usr/local/bin/passwd2xml /etc/passwd' \\
+ /etc/passwd.xml"
+.Ed
.Sh SEE ALSO
.Xr mount 2 ,
.Xr unmount 2 ,
.Xr fstab 5 ,
.Xr mount 8
+.Rs
+.%A "W. Richard Stevens"
+.%A "Jan-Simon Pendry"
+.%T "Portals in 4.4BSD"
+.%B "USENIX 1995 Technical Conference Proceedings"
+.%C "Berkeley, CA"
+.%E "Peter Honeyman"
+.Re
.Sh CAVEATS
This file system may not be NFS-exported.
.Sh HISTORY
diff --git a/usr.sbin/mount_portalfs/mount_portalfs.c b/usr.sbin/mount_portalfs/mount_portalfs.c
index 49a11d0881cfb..376e82751cf0a 100644
--- a/usr.sbin/mount_portalfs/mount_portalfs.c
+++ b/usr.sbin/mount_portalfs/mount_portalfs.c
@@ -136,6 +136,12 @@ main(argc, argv)
* Get config file and mount point
*/
conf = argv[optind];
+ if (conf[0] != '/') {
+ (void)fprintf(stderr,
+ "The configuration file must be specified"
+ "through an absolute file path.\n");
+ exit(EX_USAGE);
+ }
/* resolve the mountpoint with realpath(3) */
(void)checkpath(argv[optind+1], mountpt);
diff --git a/usr.sbin/mount_portalfs/portal.conf b/usr.sbin/mount_portalfs/portal.conf
index 53a07a92231c5..398cfb29936d2 100644
--- a/usr.sbin/mount_portalfs/portal.conf
+++ b/usr.sbin/mount_portalfs/portal.conf
@@ -3,5 +3,5 @@
tcplisten/ tcplisten tcplisten/
tcp/ tcp tcp/
fs/ file fs/
-pipe/ pipe
+pipe/ pipe pipe/
foo/ exec ./bar bar baz
diff --git a/usr.sbin/mount_portalfs/portald.h b/usr.sbin/mount_portalfs/portald.h
index ceb1a4657bc91..ff4c3fd4451d6 100644
--- a/usr.sbin/mount_portalfs/portald.h
+++ b/usr.sbin/mount_portalfs/portald.h
@@ -67,6 +67,8 @@ extern int portal_exec(struct portal_cred *,
char *key, char **v, int so, int *fdp);
extern int portal_file(struct portal_cred *,
char *key, char **v, int so, int *fdp);
+extern int portal_pipe(struct portal_cred *,
+ char *key, char **v, int so, int *fdp);
extern int portal_tcp(struct portal_cred *,
char *key, char **v, int so, int *fdp);
extern int portal_tcplisten(struct portal_cred *,
@@ -78,3 +80,6 @@ extern int portal_tcplisten(struct portal_cred *,
extern void activate(qelem *q, int so);
extern char **conf_match(qelem *q, char *key);
extern void conf_read(qelem *q, char *conf);
+extern int set_user_credentials(struct portal_cred *user,
+ struct portal_cred *save_area);
+extern int restore_credentials(struct portal_cred *save_area);
diff --git a/usr.sbin/mount_portalfs/pt_conf.c b/usr.sbin/mount_portalfs/pt_conf.c
index a89232d6e0d14..7f1e8175eaba5 100644
--- a/usr.sbin/mount_portalfs/pt_conf.c
+++ b/usr.sbin/mount_portalfs/pt_conf.c
@@ -43,6 +43,7 @@ __FBSDID("$FreeBSD$");
provider providers[] = {
{ "exec", portal_exec },
{ "file", portal_file },
+ { "pipe", portal_pipe },
{ "tcp", portal_tcp },
{ "tcplisten", portal_tcplisten },
{ 0, 0 }
diff --git a/usr.sbin/mount_portalfs/pt_file.c b/usr.sbin/mount_portalfs/pt_file.c
index 153c7337ffffa..e2c396ac6380c 100644
--- a/usr.sbin/mount_portalfs/pt_file.c
+++ b/usr.sbin/mount_portalfs/pt_file.c
@@ -56,7 +56,7 @@ int *fdp;
int fd;
char pbuf[MAXPATHLEN];
int error;
- gid_t gidset[NGROUPS];
+ struct portal_cred save_area;
int i;
pbuf[0] = '/';
@@ -67,13 +67,7 @@ int *fdp;
printf ("fflag = %x, oflag = %x\n", pcr->pcr_flag, (pcr->pcr_flag)-1);
#endif
- for (i = 0; i < pcr->pcr_ngroups; i++)
- gidset[i] = pcr->pcr_groups[i];
-
- if (setgroups(pcr->pcr_ngroups, gidset) < 0)
- return (errno);
-
- if (seteuid(pcr->pcr_uid) < 0)
+ if (set_user_credentials(pcr, &save_area) < 0)
return (errno);
/* dmb convert kernel flags to oflags, see <fcntl.h> */
@@ -83,9 +77,8 @@ int *fdp;
else
error = 0;
- if (seteuid((uid_t) 0) < 0) { /* XXX - should reset gidset too */
+ if (restore_credentials(&save_area) < 0) {
error = errno;
- syslog(LOG_ERR, "setcred: %s", strerror(error));
if (fd >= 0) {
(void) close(fd);
fd = -1;