version 1.481, 2018/06/08 03:35:36 |
version 1.482, 2018/07/09 21:03:30 |
|
|
#include "cipher.h" |
#include "cipher.h" |
#include "digest.h" |
#include "digest.h" |
#include "packet.h" |
#include "packet.h" |
#include "buffer.h" |
#include "sshbuf.h" |
#include "channels.h" |
#include "channels.h" |
#include "key.h" |
#include "key.h" |
#include "authfd.h" |
#include "authfd.h" |
|
|
uid_t original_effective_uid; |
uid_t original_effective_uid; |
|
|
/* command to be executed */ |
/* command to be executed */ |
Buffer command; |
struct sshbuf *command; |
|
|
/* Should we execute a command or invoke a subsystem? */ |
/* Should we execute a command or invoke a subsystem? */ |
int subsystem_flag = 0; |
int subsystem_flag = 0; |
|
|
#endif |
#endif |
|
|
/* Initialize the command to execute on remote host. */ |
/* Initialize the command to execute on remote host. */ |
buffer_init(&command); |
if ((command = sshbuf_new()) == NULL) |
|
fatal("sshbuf_new failed"); |
|
|
/* |
/* |
* Save the command to execute on the remote host in a buffer. There |
* Save the command to execute on the remote host in a buffer. There |
|
|
} else { |
} else { |
/* A command has been specified. Store it into the buffer. */ |
/* A command has been specified. Store it into the buffer. */ |
for (i = 0; i < ac; i++) { |
for (i = 0; i < ac; i++) { |
if (i) |
if ((r = sshbuf_putf(command, "%s%s", |
buffer_append(&command, " ", 1); |
i ? " " : "", av[i])) != 0) |
buffer_append(&command, av[i], strlen(av[i])); |
fatal("%s: buffer error: %s", |
|
__func__, ssh_err(r)); |
} |
} |
} |
} |
|
|
|
|
if (original_effective_uid != 0) |
if (original_effective_uid != 0) |
options.use_privileged_port = 0; |
options.use_privileged_port = 0; |
|
|
if (buffer_len(&command) != 0 && options.remote_command != NULL) |
if (sshbuf_len(command) != 0 && options.remote_command != NULL) |
fatal("Cannot execute command-line and remote command."); |
fatal("Cannot execute command-line and remote command."); |
|
|
/* Cannot fork to background if no command. */ |
/* Cannot fork to background if no command. */ |
if (fork_after_authentication_flag && buffer_len(&command) == 0 && |
if (fork_after_authentication_flag && sshbuf_len(command) == 0 && |
options.remote_command == NULL && !no_shell_flag) |
options.remote_command == NULL && !no_shell_flag) |
fatal("Cannot fork into background without a command " |
fatal("Cannot fork into background without a command " |
"to execute."); |
"to execute."); |
|
|
tty_flag = 1; |
tty_flag = 1; |
|
|
/* Allocate a tty by default if no command specified. */ |
/* Allocate a tty by default if no command specified. */ |
if (buffer_len(&command) == 0 && options.remote_command == NULL) |
if (sshbuf_len(command) == 0 && options.remote_command == NULL) |
tty_flag = options.request_tty != REQUEST_TTY_NO; |
tty_flag = options.request_tty != REQUEST_TTY_NO; |
|
|
/* Force no tty */ |
/* Force no tty */ |
|
|
(char *)NULL); |
(char *)NULL); |
debug3("expanded RemoteCommand: %s", options.remote_command); |
debug3("expanded RemoteCommand: %s", options.remote_command); |
free(cp); |
free(cp); |
buffer_append(&command, options.remote_command, |
if ((r = sshbuf_put(command, options.remote_command, |
strlen(options.remote_command)); |
strlen(options.remote_command))) != 0) |
|
fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
} |
} |
|
|
if (options.control_path != NULL) { |
if (options.control_path != NULL) { |
|
|
options.ip_qos_interactive, options.ip_qos_bulk); |
options.ip_qos_interactive, options.ip_qos_bulk); |
|
|
client_session2_setup(ssh, id, tty_flag, subsystem_flag, getenv("TERM"), |
client_session2_setup(ssh, id, tty_flag, subsystem_flag, getenv("TERM"), |
NULL, fileno(stdin), &command, environ); |
NULL, fileno(stdin), command, environ); |
} |
} |
|
|
/* open new channel for a session */ |
/* open new channel for a session */ |