diff options
Diffstat (limited to 'session.c')
-rw-r--r-- | session.c | 42 |
1 files changed, 32 insertions, 10 deletions
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: session.c,v 1.280 2016/02/16 03:37:48 djm Exp $ */ | 1 | /* $OpenBSD: session.c,v 1.281 2016/03/07 19:02:43 djm Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland | 3 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland |
4 | * All rights reserved | 4 | * All rights reserved |
@@ -778,6 +778,7 @@ do_pre_login(Session *s) | |||
778 | int | 778 | int |
779 | do_exec(Session *s, const char *command) | 779 | do_exec(Session *s, const char *command) |
780 | { | 780 | { |
781 | struct ssh *ssh = active_state; /* XXX */ | ||
781 | int ret; | 782 | int ret; |
782 | const char *forced = NULL, *tty = NULL; | 783 | const char *forced = NULL, *tty = NULL; |
783 | char session_type[1024]; | 784 | char session_type[1024]; |
@@ -820,8 +821,8 @@ do_exec(Session *s, const char *command) | |||
820 | tty == NULL ? "" : " on ", | 821 | tty == NULL ? "" : " on ", |
821 | tty == NULL ? "" : tty, | 822 | tty == NULL ? "" : tty, |
822 | s->pw->pw_name, | 823 | s->pw->pw_name, |
823 | get_remote_ipaddr(), | 824 | ssh_remote_ipaddr(ssh), |
824 | get_remote_port(), | 825 | ssh_remote_port(ssh), |
825 | s->self); | 826 | s->self); |
826 | 827 | ||
827 | #ifdef SSH_AUDIT_EVENTS | 828 | #ifdef SSH_AUDIT_EVENTS |
@@ -856,6 +857,7 @@ do_exec(Session *s, const char *command) | |||
856 | void | 857 | void |
857 | do_login(Session *s, const char *command) | 858 | do_login(Session *s, const char *command) |
858 | { | 859 | { |
860 | struct ssh *ssh = active_state; /* XXX */ | ||
859 | socklen_t fromlen; | 861 | socklen_t fromlen; |
860 | struct sockaddr_storage from; | 862 | struct sockaddr_storage from; |
861 | struct passwd * pw = s->pw; | 863 | struct passwd * pw = s->pw; |
@@ -878,7 +880,7 @@ do_login(Session *s, const char *command) | |||
878 | /* Record that there was a login on that tty from the remote host. */ | 880 | /* Record that there was a login on that tty from the remote host. */ |
879 | if (!use_privsep) | 881 | if (!use_privsep) |
880 | record_login(pid, s->tty, pw->pw_name, pw->pw_uid, | 882 | record_login(pid, s->tty, pw->pw_name, pw->pw_uid, |
881 | get_remote_name_or_ip(utmp_len, | 883 | session_get_remote_name_or_ip(ssh, utmp_len, |
882 | options.use_dns), | 884 | options.use_dns), |
883 | (struct sockaddr *)&from, fromlen); | 885 | (struct sockaddr *)&from, fromlen); |
884 | 886 | ||
@@ -1139,6 +1141,7 @@ copy_environment(char **source, char ***env, u_int *envsize) | |||
1139 | static char ** | 1141 | static char ** |
1140 | do_setup_env(Session *s, const char *shell) | 1142 | do_setup_env(Session *s, const char *shell) |
1141 | { | 1143 | { |
1144 | struct ssh *ssh = active_state; /* XXX */ | ||
1142 | char buf[256]; | 1145 | char buf[256]; |
1143 | u_int i, envsize; | 1146 | u_int i, envsize; |
1144 | char **env, *laddr; | 1147 | char **env, *laddr; |
@@ -1240,12 +1243,14 @@ do_setup_env(Session *s, const char *shell) | |||
1240 | 1243 | ||
1241 | /* SSH_CLIENT deprecated */ | 1244 | /* SSH_CLIENT deprecated */ |
1242 | snprintf(buf, sizeof buf, "%.50s %d %d", | 1245 | snprintf(buf, sizeof buf, "%.50s %d %d", |
1243 | get_remote_ipaddr(), get_remote_port(), get_local_port()); | 1246 | ssh_remote_ipaddr(ssh), ssh_remote_port(ssh), |
1247 | ssh_local_port(ssh)); | ||
1244 | child_set_env(&env, &envsize, "SSH_CLIENT", buf); | 1248 | child_set_env(&env, &envsize, "SSH_CLIENT", buf); |
1245 | 1249 | ||
1246 | laddr = get_local_ipaddr(packet_get_connection_in()); | 1250 | laddr = get_local_ipaddr(packet_get_connection_in()); |
1247 | snprintf(buf, sizeof buf, "%.50s %d %.50s %d", | 1251 | snprintf(buf, sizeof buf, "%.50s %d %.50s %d", |
1248 | get_remote_ipaddr(), get_remote_port(), laddr, get_local_port()); | 1252 | ssh_remote_ipaddr(ssh), ssh_remote_port(ssh), |
1253 | laddr, ssh_local_port(ssh)); | ||
1249 | free(laddr); | 1254 | free(laddr); |
1250 | child_set_env(&env, &envsize, "SSH_CONNECTION", buf); | 1255 | child_set_env(&env, &envsize, "SSH_CONNECTION", buf); |
1251 | 1256 | ||
@@ -1662,6 +1667,7 @@ child_close_fds(void) | |||
1662 | void | 1667 | void |
1663 | do_child(Session *s, const char *command) | 1668 | do_child(Session *s, const char *command) |
1664 | { | 1669 | { |
1670 | struct ssh *ssh = active_state; /* XXX */ | ||
1665 | extern char **environ; | 1671 | extern char **environ; |
1666 | char **env; | 1672 | char **env; |
1667 | char *argv[ARGV_MAX]; | 1673 | char *argv[ARGV_MAX]; |
@@ -1738,14 +1744,14 @@ do_child(Session *s, const char *command) | |||
1738 | 1744 | ||
1739 | /* we have to stash the hostname before we close our socket. */ | 1745 | /* we have to stash the hostname before we close our socket. */ |
1740 | if (options.use_login) | 1746 | if (options.use_login) |
1741 | hostname = get_remote_name_or_ip(utmp_len, | 1747 | hostname = session_get_remote_name_or_ip(ssh, utmp_len, |
1742 | options.use_dns); | 1748 | options.use_dns); |
1743 | /* | 1749 | /* |
1744 | * Close the connection descriptors; note that this is the child, and | 1750 | * Close the connection descriptors; note that this is the child, and |
1745 | * the server will still have the socket open, and it is important | 1751 | * the server will still have the socket open, and it is important |
1746 | * that we do not shutdown it. Note that the descriptors cannot be | 1752 | * that we do not shutdown it. Note that the descriptors cannot be |
1747 | * closed before building the environment, as we call | 1753 | * closed before building the environment, as we call |
1748 | * get_remote_ipaddr there. | 1754 | * ssh_remote_ipaddr there. |
1749 | */ | 1755 | */ |
1750 | child_close_fds(); | 1756 | child_close_fds(); |
1751 | 1757 | ||
@@ -2498,12 +2504,13 @@ session_exit_message(Session *s, int status) | |||
2498 | void | 2504 | void |
2499 | session_close(Session *s) | 2505 | session_close(Session *s) |
2500 | { | 2506 | { |
2507 | struct ssh *ssh = active_state; /* XXX */ | ||
2501 | u_int i; | 2508 | u_int i; |
2502 | 2509 | ||
2503 | verbose("Close session: user %s from %.200s port %d id %d", | 2510 | verbose("Close session: user %s from %.200s port %d id %d", |
2504 | s->pw->pw_name, | 2511 | s->pw->pw_name, |
2505 | get_remote_ipaddr(), | 2512 | ssh_remote_ipaddr(ssh), |
2506 | get_remote_port(), | 2513 | ssh_remote_port(ssh), |
2507 | s->self); | 2514 | s->self); |
2508 | 2515 | ||
2509 | if (s->ttyfd != -1) | 2516 | if (s->ttyfd != -1) |
@@ -2772,3 +2779,18 @@ do_cleanup(Authctxt *authctxt) | |||
2772 | if (!use_privsep || mm_is_monitor()) | 2779 | if (!use_privsep || mm_is_monitor()) |
2773 | session_destroy_all(session_pty_cleanup2); | 2780 | session_destroy_all(session_pty_cleanup2); |
2774 | } | 2781 | } |
2782 | |||
2783 | /* Return a name for the remote host that fits inside utmp_size */ | ||
2784 | |||
2785 | const char * | ||
2786 | session_get_remote_name_or_ip(struct ssh *ssh, u_int utmp_size, int use_dns) | ||
2787 | { | ||
2788 | const char *remote = ""; | ||
2789 | |||
2790 | if (utmp_size > 0) | ||
2791 | remote = auth_get_canonical_hostname(ssh, use_dns); | ||
2792 | if (utmp_size == 0 || strlen(remote) > utmp_size) | ||
2793 | remote = ssh_remote_ipaddr(ssh); | ||
2794 | return remote; | ||
2795 | } | ||
2796 | |||