mirror of
https://github.com/sudo-project/sudo.git
synced 2025-08-31 14:25:15 +00:00
The -i and -s flags can now take an optional command.
This commit is contained in:
3
WHATSNEW
3
WHATSNEW
@@ -29,3 +29,6 @@ What's new in Sudo 1.7?
|
|||||||
configurable via sudoers and, optionally, the command line.
|
configurable via sudoers and, optionally, the command line.
|
||||||
|
|
||||||
* Visudo will now warn about aliases that are defined but not used.
|
* Visudo will now warn about aliases that are defined but not used.
|
||||||
|
|
||||||
|
* The -i and -s command line flags now take an optional command
|
||||||
|
to be run via the shell.
|
||||||
|
45
sudo.c
45
sudo.c
@@ -671,22 +671,35 @@ init_vars(sudo_mode, envp)
|
|||||||
* If we were given the '-e', '-i' or '-s' options we need to redo
|
* If we were given the '-e', '-i' or '-s' options we need to redo
|
||||||
* NewArgv and NewArgc.
|
* NewArgv and NewArgc.
|
||||||
*/
|
*/
|
||||||
if ((sudo_mode & (MODE_SHELL | MODE_EDIT))) {
|
if (ISSET(sudo_mode, MODE_EDIT)) {
|
||||||
char **dst, **src = NewArgv;
|
NewArgv--;
|
||||||
|
NewArgc++;
|
||||||
|
NewArgv[0] = "sudoedit";
|
||||||
|
} else if (ISSET(sudo_mode, MODE_SHELL)) {
|
||||||
|
char **av;
|
||||||
|
|
||||||
/* Allocate an extra slot for execve() failure (ENOEXEC). */
|
/* Allocate an extra slot for execve() failure (ENOEXEC). */
|
||||||
NewArgv = (char **) emalloc2((++NewArgc + 2), sizeof(char *));
|
av = (char **) emalloc2(5, sizeof(char *));
|
||||||
NewArgv++;
|
av++;
|
||||||
if (ISSET(sudo_mode, MODE_EDIT))
|
|
||||||
NewArgv[0] = "sudoedit";
|
|
||||||
else if (user_shell && *user_shell)
|
|
||||||
NewArgv[0] = user_shell;
|
|
||||||
else
|
|
||||||
errorx(1, "unable to determine shell");
|
|
||||||
|
|
||||||
/* copy the args from NewArgv */
|
av[0] = user_shell; /* may be updated later */
|
||||||
for (dst = NewArgv + 1; (*dst = *src) != NULL; ++src, ++dst)
|
if (NewArgc > 0) {
|
||||||
continue;
|
size_t size;
|
||||||
|
char *cmnd, *src, *dst, *end;
|
||||||
|
size = (size_t) (NewArgv[NewArgc - 1] - NewArgv[0]) +
|
||||||
|
strlen(NewArgv[NewArgc - 1]) + 1;
|
||||||
|
cmnd = emalloc(size);
|
||||||
|
src = NewArgv[0];
|
||||||
|
dst = cmnd;
|
||||||
|
for (end = src + size - 1; src < end; src++, dst++)
|
||||||
|
*dst = *src == 0 ? ' ' : *src;
|
||||||
|
*dst = '\0';
|
||||||
|
av[1] = "-c";
|
||||||
|
av[2] = cmnd;
|
||||||
|
NewArgc = 2;
|
||||||
|
}
|
||||||
|
av[++NewArgc] = NULL;
|
||||||
|
NewArgv = av;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -725,7 +738,7 @@ set_cmnd(sudo_mode)
|
|||||||
size_t size, n;
|
size_t size, n;
|
||||||
|
|
||||||
/* If we didn't realloc NewArgv it is contiguous so just count. */
|
/* If we didn't realloc NewArgv it is contiguous so just count. */
|
||||||
if (!(sudo_mode & (MODE_SHELL | MODE_EDIT))) {
|
if (!ISSET(sudo_mode, MODE_SHELL)) {
|
||||||
size = (size_t) (NewArgv[NewArgc-1] - NewArgv[1]) +
|
size = (size_t) (NewArgv[NewArgc-1] - NewArgv[1]) +
|
||||||
strlen(NewArgv[NewArgc-1]) + 1;
|
strlen(NewArgv[NewArgc-1]) + 1;
|
||||||
} else {
|
} else {
|
||||||
@@ -779,8 +792,10 @@ parse_args(argc, argv)
|
|||||||
|
|
||||||
while (NewArgc > 0) {
|
while (NewArgc > 0) {
|
||||||
if (NewArgv[0][0] == '-') {
|
if (NewArgv[0][0] == '-') {
|
||||||
if (NewArgv[0][1] != '\0' && NewArgv[0][2] != '\0')
|
if (NewArgv[0][1] != '\0' && NewArgv[0][2] != '\0') {
|
||||||
warningx("please use single character options");
|
warningx("please use single character options");
|
||||||
|
usage(1);
|
||||||
|
}
|
||||||
|
|
||||||
switch (NewArgv[0][1]) {
|
switch (NewArgv[0][1]) {
|
||||||
case 'p':
|
case 'p':
|
||||||
|
29
sudo.pod
29
sudo.pod
@@ -35,8 +35,8 @@ S<[B<-u> I<username>|I<#uid>]> [I<command>]
|
|||||||
|
|
||||||
B<sudo> [B<-bEHPS>] S<[B<-a> I<auth_type>]> S<[B<-C> I<fd>]>
|
B<sudo> [B<-bEHPS>] S<[B<-a> I<auth_type>]> S<[B<-C> I<fd>]>
|
||||||
S<[B<-c> I<class>|I<->]> S<[B<-g> I<groupname>|I<#gid>]> S<[B<-p> I<prompt>]>
|
S<[B<-c> I<class>|I<->]> S<[B<-g> I<groupname>|I<#gid>]> S<[B<-p> I<prompt>]>
|
||||||
S<[B<-u> I<username>|I<#uid>]> S<[B<VAR>=I<value>]>
|
S<[B<-u> I<username>|I<#uid>]> S<[B<VAR>=I<value>]> [S<{B<-i> | B<-s>]
|
||||||
S<{B<-i> | B<-s> | I<command>}>
|
[<I<command>}>]
|
||||||
|
|
||||||
B<sudoedit> [B<-S>] S<[B<-a> I<auth_type>]> S<[B<-C> I<fd>]>
|
B<sudoedit> [B<-S>] S<[B<-a> I<auth_type>]> S<[B<-C> I<fd>]>
|
||||||
S<[B<-c> I<class>|I<->]> S<[B<-g> I<groupname>|I<#gid>]> S<[B<-p> I<prompt>]>
|
S<[B<-c> I<class>|I<->]> S<[B<-g> I<groupname>|I<#gid>]> S<[B<-p> I<prompt>]>
|
||||||
@@ -198,16 +198,18 @@ in passwd(5). By default, B<sudo> does not modify C<HOME>
|
|||||||
|
|
||||||
The B<-h> (I<help>) option causes B<sudo> to print a usage message and exit.
|
The B<-h> (I<help>) option causes B<sudo> to print a usage message and exit.
|
||||||
|
|
||||||
=item -i
|
=item -i [command]
|
||||||
|
|
||||||
The B<-i> (I<simulate initial login>) option runs the shell specified
|
The B<-i> (I<simulate initial login>) option runs the shell specified
|
||||||
in the L<passwd(5)> entry of the user that the command is
|
in the L<passwd(5)> entry of the target user as a login shell. This
|
||||||
being run as. The command name argument given to the shell begins
|
means that login-specific resource files such as C<.profile> or
|
||||||
with a `C<->' to tell the shell to run as a login shell. B<sudo>
|
C<.login> will be read by the shell. If a command is specified,
|
||||||
attempts to change to that user's home directory before running the
|
it is passed to the shell for execution. Otherwise, an interactive
|
||||||
shell. It also initializes the environment, leaving I<DISPLAY>
|
shell is executed. B<sudo> attempts to change to that user's home
|
||||||
and I<TERM> unchanged, setting I<HOME>, I<SHELL>, I<USER>, I<LOGNAME>, and
|
directory before running the shell. It also initializes the
|
||||||
I<PATH>, and unsetting all other environment variables.
|
environment, leaving I<DISPLAY> and I<TERM> unchanged, setting
|
||||||
|
I<HOME>, I<SHELL>, I<USER>, I<LOGNAME>, and I<PATH>, and unsetting
|
||||||
|
all other environment variables.
|
||||||
|
|
||||||
=item -K
|
=item -K
|
||||||
|
|
||||||
@@ -289,11 +291,12 @@ I<passprompt_override> flag is disabled in I<sudoers>.
|
|||||||
The B<-S> (I<stdin>) option causes B<sudo> to read the password from
|
The B<-S> (I<stdin>) option causes B<sudo> to read the password from
|
||||||
the standard input instead of the terminal device.
|
the standard input instead of the terminal device.
|
||||||
|
|
||||||
=item -s
|
=item -s [command]
|
||||||
|
|
||||||
The B<-s> (I<shell>) option runs the shell specified by the I<SHELL>
|
The B<-s> (I<shell>) option runs the shell specified by the I<SHELL>
|
||||||
environment variable if it is set or the shell as specified
|
environment variable if it is set or the shell as specified in
|
||||||
in L<passwd(5)>.
|
L<passwd(5)>. If a command is specified, it is passed to the shell
|
||||||
|
for execution. Otherwise, an interactive shell is executed.
|
||||||
|
|
||||||
=item -U I<user>
|
=item -U I<user>
|
||||||
|
|
||||||
|
@@ -7,7 +7,7 @@
|
|||||||
*/
|
*/
|
||||||
#define SUDO_USAGE1 " -h | -K | -k | -L | -V | -v"
|
#define SUDO_USAGE1 " -h | -K | -k | -L | -V | -v"
|
||||||
#define SUDO_USAGE2 " -l [-g groupname|#gid] [-U username] [-u username|#uid] [-g groupname|#gid] [command]"
|
#define SUDO_USAGE2 " -l [-g groupname|#gid] [-U username] [-u username|#uid] [-g groupname|#gid] [command]"
|
||||||
#define SUDO_USAGE3 " [-bEHPS] @BSDAUTH_USAGE@[-C fd] @LOGINCAP_USAGE@[-g groupname|#gid] [-p prompt] [-u username|#uid] [-g groupname|#gid] [VAR=value] {-i | -s | <command>}"
|
#define SUDO_USAGE3 " [-bEHPS] @BSDAUTH_USAGE@[-C fd] @LOGINCAP_USAGE@[-g groupname|#gid] [-p prompt] [-u username|#uid] [-g groupname|#gid] [VAR=value] [-i|-s] [<command>]"
|
||||||
#define SUDO_USAGE4 " -e [-S] @BSDAUTH_USAGE@[-C fd] @LOGINCAP_USAGE@[-g groupname|#gid] [-p prompt] [-u username|#uid] file ..."
|
#define SUDO_USAGE4 " -e [-S] @BSDAUTH_USAGE@[-C fd] @LOGINCAP_USAGE@[-g groupname|#gid] [-p prompt] [-u username|#uid] file ..."
|
||||||
|
|
||||||
#endif /* _SUDO_USAGE_H */
|
#endif /* _SUDO_USAGE_H */
|
||||||
|
Reference in New Issue
Block a user