Page MenuHomeFreeBSD

D54660.id169526.diff
No OneTemporary

D54660.id169526.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
@@ -49,6 +49,7 @@
extern char **environ;
+static void putenv_copy(char *env);
static void get_user_info(const char *username, const struct passwd **pwdp,
login_cap_t **lcapp);
static void usage(void);
@@ -59,7 +60,9 @@
int jid;
login_cap_t *lcap = NULL;
int ch, clean, dflag, uflag, Uflag;
+ unsigned int newenvlen = 0;
char *cleanenv;
+ char **newenv = NULL;
const struct passwd *pwd = NULL;
const char *username, *shell, *term;
const char *workdir;
@@ -68,12 +71,20 @@
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':
+ if (++newenvlen >= UINT_MAX)
+ errx(1, "No more memory can be allocated to this environment!");
+ if ((newenv = realloc(newenv, sizeof(char **) * newenvlen)) == NULL)
+ err(1, "realloc");
+ if ((newenv[newenvlen-1] = strdup(optarg)) == NULL)
+ err(1, "strdup");
+ break;
case 'l':
clean = 1;
break;
@@ -140,6 +151,15 @@
endpwent();
}
+ /* Custom environment */
+ while (newenvlen > 0) {
+ putenv_copy(newenv[--newenvlen]);
+ free(newenv[newenvlen]);
+ }
+ if (newenv != NULL) {
+ free(newenv);
+ }
+
/* Run the specified command, or the shell */
if (argc > 1) {
if (execvp(argv[1], argv + 1) < 0)
@@ -153,6 +173,29 @@
exit(0);
}
+static void
+putenv_copy(char *env)
+{
+ size_t name_len;
+ char *sign;
+ char *name, *value;
+
+ if ((sign = strchr(env, '=')) == NULL)
+ errx(1, "%s: Invalid environment variable.", env);
+ name_len = sign - env;
+ if ((name = strndup(env, name_len)) == NULL)
+ err(1, "strdup");
+ if ((value = strdup(sign + 1)) == NULL)
+ err(1, "strdup");
+ if (setenv(name, value, 1) == -1) {
+ free(name);
+ free(value);
+ err(1, "setenv");
+ }
+ free(name);
+ free(value);
+}
+
static void
get_user_info(const char *username, const struct passwd **pwdp,
login_cap_t **lcapp)
@@ -192,7 +235,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
Sun, Apr 12, 11:13 PM (18 m, 8 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
31378957
Default Alt Text
D54660.id169526.diff (3 KB)

Event Timeline