Bug 201300 - Let jexec execute shell if no command is issued.
Summary: Let jexec execute shell if no command is issued.
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 10.1-STABLE
Hardware: Any Any
: --- Affects Only Me
Assignee: Jamie Gritton
URL:
Keywords: patch
Depends on:
Blocks:
 
Reported: 2015-07-03 07:24 UTC by Willem Jan Withagen
Modified: 2015-07-30 04:57 UTC (History)
2 users (show)

See Also:


Attachments
Allow Jexec command to be empty, and start a shell (3.73 KB, patch)
2015-07-03 07:24 UTC, Willem Jan Withagen
no flags Details | Diff
alternate patch, including -l option (5.60 KB, patch)
2015-07-11 22:00 UTC, Jamie Gritton
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Willem Jan Withagen 2015-07-03 07:24:13 UTC
Created attachment 158277 [details]
Allow Jexec command to be empty, and start a shell

jexec does require a command as parameter.
unlike for instance chroot (or sudo if configure so)

This patch adds the same functionality to jexec and allows:
    jexec <jid>

Which gets you a shell in the jail.

--WjW
Comment 1 Jamie Gritton freebsd_committer freebsd_triage 2015-07-11 22:00:37 UTC
Created attachment 158629 [details]
alternate patch, including -l option

I've kept to the spirit of your patch, but reworked it with a few changes.  Instead of hard-coding a username "root", I default to leaving the environment along unless a user (or -l) is specified.  In the absence of a specified user, I run the current environment's shell instead of root's.  I run the shell with the "-i" argument, as chroot does.

I've also added a "-l" argument for a "clean" environment, same as jail(8)'s "exec.clean" parameter.
Comment 2 Willem Jan Withagen 2015-07-12 11:53:12 UTC
(In reply to Jamie Gritton from comment #1)
I like your patch, especially the clean option.
Other parts of the patch look like one of my earlier tries which I considered to much...., including rewriting the macro to a function.
But with the clean-stuff it does make much more sense.
Comment 3 commit-hook freebsd_committer freebsd_triage 2015-07-12 17:04:22 UTC
A commit references this bug:

Author: jamie
Date: Sun Jul 12 17:03:52 UTC 2015
New revision: 285420
URL: https://svnweb.freebsd.org/changeset/base/285420

Log:
  Run a shell in the jail when no command is specified.
  Add a new flag, -l, for a clean environment, same as jail(8) exec.clean.
  Change the GET_USER_INFO macro into a function.

  PR:		201300
  Submitted by:	Willem Jan Withagen
  MFC after:	3 days

Changes:
  head/usr.sbin/jexec/jexec.8
  head/usr.sbin/jexec/jexec.c
Comment 4 commit-hook freebsd_committer freebsd_triage 2015-07-30 04:54:05 UTC
A commit references this bug:

Author: jamie
Date: Thu Jul 30 04:53:54 UTC 2015
New revision: 286064
URL: https://svnweb.freebsd.org/changeset/base/286064

Log:
  MFC r285420:

    Run a shell in the jail when no command is specified.
    Add a new flag, -l, for a clean environment, same as jail(8) exec.clean.
    Change the GET_USER_INFO macro into a function.

  PR:		201300
  Submitted by:	Willem Jan Withagen

Changes:
_U  stable/10/
  stable/10/usr.sbin/jexec/jexec.8
  stable/10/usr.sbin/jexec/jexec.c