Page MenuHomeFreeBSD

D54660.1789375634.diff
No OneTemporary

Size
2 KB
Referenced Files
None
Subscribers
None

D54660.1789375634.diff

diff --git a/usr.sbin/jexec/jexec.8 b/usr.sbin/jexec/jexec.8
--- a/usr.sbin/jexec/jexec.8
+++ b/usr.sbin/jexec/jexec.8
@@ -23,7 +23,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd March 5, 2025
+.Dd January 11, 2026
.Dt JEXEC 8
.Os
.Sh NAME
@@ -33,6 +33,7 @@
.Nm
.Op Fl l
.Op Fl d Ar working-directory
+.Op Oo Fl e Ar name Ns = Ns Ar value Oc ...
.Op Fl u Ar username | Fl U Ar username
.Ar jail Op Ar command ...
.Sh DESCRIPTION
@@ -66,6 +67,16 @@
and absent the
.Fl d
option, commands are run from that (possibly jailed) user's directory.
+.It Fl e Ar name Ns = Ns Ar value
+Set environment variables.
+.Pp
+This parameter allows arbitrary environment variables that are available to the process
+to be executed inside of the jail, overwriting any previously defined environment variables,
+such as those specified by the
+.Fl l
+parameter.
+.Pp
+This option can be set multiple times.
.It Fl u Ar username
The user name from host environment as whom the
.Ar command
diff --git a/usr.sbin/jexec/jexec.c b/usr.sbin/jexec/jexec.c
--- a/usr.sbin/jexec/jexec.c
+++ b/usr.sbin/jexec/jexec.c
@@ -59,6 +59,8 @@
int jid;
login_cap_t *lcap = NULL;
int ch, clean, dflag, uflag, Uflag;
+ int env_argc = argc;
+ char **env_argv = argv;
char *cleanenv;
const struct passwd *pwd = NULL;
const char *username, *shell, *term;
@@ -68,12 +70,17 @@
username = NULL;
workdir = "/";
- while ((ch = getopt(argc, argv, "d:lnu:U:")) != -1) {
+ while ((ch = getopt(argc, argv, "d:e:lnu:U:")) != -1) {
switch (ch) {
case 'd':
workdir = optarg;
dflag = 1;
break;
+ case 'e':
+ /* Used later. */
+ if (strchr(optarg, '=') == NULL)
+ errx(1, "%s: Invalid environment variable.", optarg);
+ break;
case 'l':
clean = 1;
break;
@@ -140,6 +147,18 @@
endpwent();
}
+ optreset = 1;
+ optind = 1;
+
+ /* Custom environment */
+ while ((ch = getopt(env_argc, env_argv, ":e:")) != -1) {
+ switch (ch) {
+ case 'e':
+ putenv(env_argv[optind - 1]);
+ break;
+ }
+ }
+
/* Run the specified command, or the shell */
if (argc > 1) {
if (execvp(argv[1], argv + 1) < 0)
@@ -192,7 +211,7 @@
{
fprintf(stderr, "%s\n",
- "usage: jexec [-l] [-d working-directory] [-u username | -U username] jail\n"
- " [command ...]");
+ "usage: jexec [-l] [-d working-directory] [[-e name=value] ...]\n"
+ " [-u username | -U username] jail [command ...]");
exit(1);
}

File Metadata

Mime Type
text/plain
Expires
Mon, Sep 14, 8:47 AM (19 h, 52 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
29625230
Default Alt Text
D54660.1789375634.diff (2 KB)

Event Timeline