FreeBSD Bugzilla – Attachment 158277 Details for
Bug 201300
Let jexec execute shell if no command is issued.
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Allow Jexec command to be empty, and start a shell
jexec.patch (text/plain), 3.73 KB, created by
Willem Jan Withagen
on 2015-07-03 07:24:13 UTC
(
hide
)
Description:
Allow Jexec command to be empty, and start a shell
Filename:
MIME Type:
Creator:
Willem Jan Withagen
Created:
2015-07-03 07:24:13 UTC
Size:
3.73 KB
patch
obsolete
>Index: usr.sbin/jexec/jexec.8 >=================================================================== >--- usr.sbin/jexec/jexec.8 (revision 285060) >+++ usr.sbin/jexec/jexec.8 (working copy) >@@ -34,7 +34,7 @@ > .Sh SYNOPSIS > .Nm > .Op Fl u Ar username | Fl U Ar username >-.Ar jail command ... >+.Ar jail Op Ar command ... > .Sh DESCRIPTION > The > .Nm >@@ -42,7 +42,10 @@ > .Ar command > inside the > .Ar jail >-identified by its jid or name. >+identified by its jid or name. If >+.Ar command >+is not specified then the users shell is used, as specified in the user's environment. >+For root this is always the environment as specified in the jail. > .Pp > The following options are available: > .Bl -tag -width indent >Index: usr.sbin/jexec/jexec.c >=================================================================== >--- usr.sbin/jexec/jexec.c (revision 285060) >+++ usr.sbin/jexec/jexec.c (working copy) >@@ -64,6 +64,7 @@ > err(1, "getgrouplist: %s", username); \ > } while (0) > >+ > int > main(int argc, char *argv[]) > { >@@ -73,10 +74,13 @@ > gid_t *groups = NULL; > int ch, ngroups, uflag, Uflag; > long ngroups_max; >- char *username; >+ const char *username; >+ const char *shell; >+ >+ ch = uflag = Uflag = 0; >+ username = "root"; >+ shell = "/bin/sh"; > >- ch = uflag = Uflag = 0; >- username = NULL; > ngroups_max = sysconf(_SC_NGROUPS_MAX) + 1; > if ((groups = malloc(sizeof(gid_t) * ngroups_max)) == NULL) > err(1, "malloc"); >@@ -100,12 +104,15 @@ > } > argc -= optind; > argv += optind; >- if (argc < 2) >+ if (argc < 1) /* Need at least the jid */ > usage(); > if (uflag && Uflag) > usage(); > if (uflag) >+ /* User info from the host environment */ > GET_USER_INFO; >+ >+ /* go into the jail */ > jid = jail_getid(argv[0]); > if (jid < 0) > errx(1, "%s", jail_errmsg); >@@ -113,20 +120,33 @@ > err(1, "jail_attach(%d)", jid); > if (chdir("/") == -1) > err(1, "chdir(): /"); >- if (username != NULL) { >- if (Uflag) >- GET_USER_INFO; >+ >+ /* Setup user environment */ >+ if (Uflag || (strcmp(username, "root")==0)) >+ /* get user environment from jail */ >+ GET_USER_INFO; >+ if (Uflag) { >+ /* setup the user according the jail environment */ > if (setgroups(ngroups, groups) != 0) > err(1, "setgroups"); > if (setgid(pwd->pw_gid) != 0) > err(1, "setgid"); > if (setusercontext(lcap, pwd, pwd->pw_uid, >- LOGIN_SETALL & ~LOGIN_SETGROUP & ~LOGIN_SETLOGIN) != 0) >- err(1, "setusercontext"); >+ LOGIN_SETALL & ~LOGIN_SETGROUP & ~LOGIN_SETLOGIN) != 0) >+ err(1, "setusercontext"); > login_close(lcap); > } >- if (execvp(argv[1], argv + 1) == -1) >- err(1, "execvp(): %s", argv[1]); >+ if (argc == 1) { >+ /* Get the user shell as command */ >+ if (pwd->pw_shell) { >+ argv[1] = pwd->pw_shell; >+ } else >+ argv[1] = (char*)shell; >+ argv[2] = NULL; >+ } >+ if (execvp(argv[1], argv + 1) == -1) { >+ err(1, "execvp(): %s", argv[1]); >+ } > exit(0); > } > >@@ -135,6 +155,6 @@ > { > > fprintf(stderr, "%s\n", >- "usage: jexec [-u username | -U username] jail command ..."); >+ "usage: jexec [-u username | -U username] jail [command] ..."); > exit(1); > } >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 201300
: 158277 |
158629