version 1.280, 2016/02/16 03:37:48 |
version 1.281, 2016/03/07 19:02:43 |
|
|
int |
int |
do_exec(Session *s, const char *command) |
do_exec(Session *s, const char *command) |
{ |
{ |
|
struct ssh *ssh = active_state; /* XXX */ |
int ret; |
int ret; |
const char *forced = NULL, *tty = NULL; |
const char *forced = NULL, *tty = NULL; |
char session_type[1024]; |
char session_type[1024]; |
|
|
tty == NULL ? "" : " on ", |
tty == NULL ? "" : " on ", |
tty == NULL ? "" : tty, |
tty == NULL ? "" : tty, |
s->pw->pw_name, |
s->pw->pw_name, |
get_remote_ipaddr(), |
ssh_remote_ipaddr(ssh), |
get_remote_port(), |
ssh_remote_port(ssh), |
s->self); |
s->self); |
|
|
#ifdef GSSAPI |
#ifdef GSSAPI |
|
|
void |
void |
do_login(Session *s, const char *command) |
do_login(Session *s, const char *command) |
{ |
{ |
|
struct ssh *ssh = active_state; /* XXX */ |
socklen_t fromlen; |
socklen_t fromlen; |
struct sockaddr_storage from; |
struct sockaddr_storage from; |
struct passwd * pw = s->pw; |
struct passwd * pw = s->pw; |
|
|
/* Record that there was a login on that tty from the remote host. */ |
/* Record that there was a login on that tty from the remote host. */ |
if (!use_privsep) |
if (!use_privsep) |
record_login(pid, s->tty, pw->pw_name, pw->pw_uid, |
record_login(pid, s->tty, pw->pw_name, pw->pw_uid, |
get_remote_name_or_ip(utmp_len, |
session_get_remote_name_or_ip(ssh, utmp_len, |
options.use_dns), |
options.use_dns), |
(struct sockaddr *)&from, fromlen); |
(struct sockaddr *)&from, fromlen); |
|
|
|
|
static char ** |
static char ** |
do_setup_env(Session *s, const char *shell) |
do_setup_env(Session *s, const char *shell) |
{ |
{ |
|
struct ssh *ssh = active_state; /* XXX */ |
char buf[256]; |
char buf[256]; |
u_int i, envsize; |
u_int i, envsize; |
char **env, *laddr; |
char **env, *laddr; |
|
|
|
|
/* SSH_CLIENT deprecated */ |
/* SSH_CLIENT deprecated */ |
snprintf(buf, sizeof buf, "%.50s %d %d", |
snprintf(buf, sizeof buf, "%.50s %d %d", |
get_remote_ipaddr(), get_remote_port(), get_local_port()); |
ssh_remote_ipaddr(ssh), ssh_remote_port(ssh), |
|
ssh_local_port(ssh)); |
child_set_env(&env, &envsize, "SSH_CLIENT", buf); |
child_set_env(&env, &envsize, "SSH_CLIENT", buf); |
|
|
laddr = get_local_ipaddr(packet_get_connection_in()); |
laddr = get_local_ipaddr(packet_get_connection_in()); |
snprintf(buf, sizeof buf, "%.50s %d %.50s %d", |
snprintf(buf, sizeof buf, "%.50s %d %.50s %d", |
get_remote_ipaddr(), get_remote_port(), laddr, get_local_port()); |
ssh_remote_ipaddr(ssh), ssh_remote_port(ssh), |
|
laddr, ssh_local_port(ssh)); |
free(laddr); |
free(laddr); |
child_set_env(&env, &envsize, "SSH_CONNECTION", buf); |
child_set_env(&env, &envsize, "SSH_CONNECTION", buf); |
|
|
|
|
void |
void |
do_child(Session *s, const char *command) |
do_child(Session *s, const char *command) |
{ |
{ |
|
struct ssh *ssh = active_state; /* XXX */ |
extern char **environ; |
extern char **environ; |
char **env; |
char **env; |
char *argv[ARGV_MAX]; |
char *argv[ARGV_MAX]; |
|
|
|
|
/* we have to stash the hostname before we close our socket. */ |
/* we have to stash the hostname before we close our socket. */ |
if (options.use_login) |
if (options.use_login) |
hostname = get_remote_name_or_ip(utmp_len, |
hostname = session_get_remote_name_or_ip(ssh, utmp_len, |
options.use_dns); |
options.use_dns); |
/* |
/* |
* Close the connection descriptors; note that this is the child, and |
* Close the connection descriptors; note that this is the child, and |
* the server will still have the socket open, and it is important |
* the server will still have the socket open, and it is important |
* that we do not shutdown it. Note that the descriptors cannot be |
* that we do not shutdown it. Note that the descriptors cannot be |
* closed before building the environment, as we call |
* closed before building the environment, as we call |
* get_remote_ipaddr there. |
* ssh_remote_ipaddr there. |
*/ |
*/ |
child_close_fds(); |
child_close_fds(); |
|
|
|
|
void |
void |
session_close(Session *s) |
session_close(Session *s) |
{ |
{ |
|
struct ssh *ssh = active_state; /* XXX */ |
u_int i; |
u_int i; |
|
|
verbose("Close session: user %s from %.200s port %d id %d", |
verbose("Close session: user %s from %.200s port %d id %d", |
s->pw->pw_name, |
s->pw->pw_name, |
get_remote_ipaddr(), |
ssh_remote_ipaddr(ssh), |
get_remote_port(), |
ssh_remote_port(ssh), |
s->self); |
s->self); |
|
|
if (s->ttyfd != -1) |
if (s->ttyfd != -1) |
|
|
if (!use_privsep || mm_is_monitor()) |
if (!use_privsep || mm_is_monitor()) |
session_destroy_all(session_pty_cleanup2); |
session_destroy_all(session_pty_cleanup2); |
} |
} |
|
|
|
/* Return a name for the remote host that fits inside utmp_size */ |
|
|
|
const char * |
|
session_get_remote_name_or_ip(struct ssh *ssh, u_int utmp_size, int use_dns) |
|
{ |
|
const char *remote = ""; |
|
|
|
if (utmp_size > 0) |
|
remote = auth_get_canonical_hostname(ssh, use_dns); |
|
if (utmp_size == 0 || strlen(remote) > utmp_size) |
|
remote = ssh_remote_ipaddr(ssh); |
|
return remote; |
|
} |
|
|