summaryrefslogtreecommitdiffstats
path: root/usr.sbin/jail
diff options
context:
space:
mode:
authormaxim <maxim@FreeBSD.org>2004-08-15 08:21:50 +0000
committermaxim <maxim@FreeBSD.org>2004-08-15 08:21:50 +0000
commit4c8376863965f4ffe4c6ba2172be1b880cd66fd2 (patch)
treef8d5c9d7d7b7d450341b1e102658d3378448cb05 /usr.sbin/jail
parentb541de7149881a84a9c99889bb59222751d3bb66 (diff)
downloadFreeBSD-src-4c8376863965f4ffe4c6ba2172be1b880cd66fd2.zip
FreeBSD-src-4c8376863965f4ffe4c6ba2172be1b880cd66fd2.tar.gz
o Add -l option to jail(8) similar to su(1): before running jail'ed
program under specific user's credentials, clean the environment and set only a few variables. PR: bin/70024 Submitted by: demon MFC after: 1 month
Diffstat (limited to 'usr.sbin/jail')
-rw-r--r--usr.sbin/jail/jail.820
-rw-r--r--usr.sbin/jail/jail.c36
2 files changed, 50 insertions, 6 deletions
diff --git a/usr.sbin/jail/jail.8 b/usr.sbin/jail/jail.8
index a3b20d5..51eb5f6 100644
--- a/usr.sbin/jail/jail.8
+++ b/usr.sbin/jail/jail.8
@@ -42,7 +42,7 @@
.Sh SYNOPSIS
.Nm
.Op Fl i
-.Op Fl u Ar username | Fl U Ar username
+.Op Fl l Fl u Ar username | Fl U Ar username
.Ar path hostname ip-number command ...
.Sh DESCRIPTION
The
@@ -53,6 +53,24 @@ The options are as follows:
.Bl -tag -width ".Fl u Ar username"
.It Fl i
Output the jail identifier of the newly created jail.
+.It Fl l
+Run program in the clean environment.
+The environment is discarded except for
+.Ev HOME ,
+.Ev SHELL ,
+.Ev TERM
+and
+.Ev USER .
+.Ev HOME
+and
+.Ev SHELL
+are set to the target login's default values.
+.Ev USER
+is set to the target login.
+.Ev TERM
+is imported from your current environment.
+The environment variables from the login class capability database for the
+target login are also set.
.It Fl u Ar username
The user name from host environment as whom the
.Ar command
diff --git a/usr.sbin/jail/jail.c b/usr.sbin/jail/jail.c
index ab188ee..0f379a7 100644
--- a/usr.sbin/jail/jail.c
+++ b/usr.sbin/jail/jail.c
@@ -20,6 +20,7 @@ __FBSDID("$FreeBSD$");
#include <errno.h>
#include <grp.h>
#include <login_cap.h>
+#include <paths.h>
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
@@ -27,6 +28,7 @@ __FBSDID("$FreeBSD$");
#include <unistd.h>
static void usage(void);
+extern char **environ;
#define GET_USER_INFO do { \
pwd = getpwnam(username); \
@@ -51,13 +53,15 @@ main(int argc, char **argv)
struct jail j;
struct passwd *pwd;
struct in_addr in;
- int ch, groups[NGROUPS], i, iflag, ngroups, uflag, Uflag;
+ int ch, groups[NGROUPS], i, iflag, lflag, ngroups, uflag, Uflag;
char path[PATH_MAX], *username;
+ static char *cleanenv;
+ const char *shell, *p;
- iflag = uflag = Uflag = 0;
- username = NULL;
+ iflag = lflag = uflag = Uflag = 0;
+ username = cleanenv = NULL;
- while ((ch = getopt(argc, argv, "iu:U:")) != -1) {
+ while ((ch = getopt(argc, argv, "ilu:U:")) != -1) {
switch (ch) {
case 'i':
iflag = 1;
@@ -70,6 +74,9 @@ main(int argc, char **argv)
username = optarg;
Uflag = 1;
break;
+ case 'l':
+ lflag = 1;
+ break;
default:
usage();
}
@@ -80,6 +87,8 @@ main(int argc, char **argv)
usage();
if (uflag && Uflag)
usage();
+ if (lflag && username == NULL)
+ usage();
if (uflag)
GET_USER_INFO;
if (realpath(argv[0], path) == NULL)
@@ -103,6 +112,10 @@ main(int argc, char **argv)
if (username != NULL) {
if (Uflag)
GET_USER_INFO;
+ if (lflag) {
+ p = getenv("TERM");
+ environ = &cleanenv;
+ }
if (setgroups(ngroups, groups) != 0)
err(1, "setgroups");
if (setgid(pwd->pw_gid) != 0)
@@ -112,6 +125,19 @@ main(int argc, char **argv)
err(1, "setusercontext");
login_close(lcap);
}
+ if (lflag) {
+ if (*pwd->pw_shell)
+ shell = pwd->pw_shell;
+ else
+ shell = _PATH_BSHELL;
+ if (chdir(pwd->pw_dir) < 0)
+ errx(1, "no home directory");
+ setenv("HOME", pwd->pw_dir, 1);
+ setenv("SHELL", shell, 1);
+ setenv("USER", pwd->pw_name, 1);
+ if (p)
+ setenv("TERM", p, 1);
+ }
if (execv(argv[3], argv + 3) != 0)
err(1, "execv: %s", argv[3]);
exit(0);
@@ -122,7 +148,7 @@ usage(void)
{
(void)fprintf(stderr, "%s%s\n",
- "usage: jail [-i] [-u username | -U username]",
+ "usage: jail [-i] [-l -u username | -U username]",
" path hostname ip-number command ...");
exit(1);
}
OpenPOWER on IntegriCloud