diff options
Diffstat (limited to 'session.c')
-rw-r--r-- | session.c | 47 |
1 files changed, 35 insertions, 12 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.282 2016/03/10 11:47:57 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 |
@@ -769,6 +769,7 @@ do_exec_pty(Session *s, const char *command) | |||
769 | static void | 769 | static void |
770 | do_pre_login(Session *s) | 770 | do_pre_login(Session *s) |
771 | { | 771 | { |
772 | struct ssh *ssh = active_state; /* XXX */ | ||
772 | socklen_t fromlen; | 773 | socklen_t fromlen; |
773 | struct sockaddr_storage from; | 774 | struct sockaddr_storage from; |
774 | pid_t pid = getpid(); | 775 | pid_t pid = getpid(); |
@@ -788,7 +789,7 @@ do_pre_login(Session *s) | |||
788 | } | 789 | } |
789 | 790 | ||
790 | record_utmp_only(pid, s->tty, s->pw->pw_name, | 791 | record_utmp_only(pid, s->tty, s->pw->pw_name, |
791 | get_remote_name_or_ip(utmp_len, options.use_dns), | 792 | session_get_remote_name_or_ip(ssh, utmp_len, options.use_dns), |
792 | (struct sockaddr *)&from, fromlen); | 793 | (struct sockaddr *)&from, fromlen); |
793 | } | 794 | } |
794 | #endif | 795 | #endif |
@@ -800,6 +801,7 @@ do_pre_login(Session *s) | |||
800 | int | 801 | int |
801 | do_exec(Session *s, const char *command) | 802 | do_exec(Session *s, const char *command) |
802 | { | 803 | { |
804 | struct ssh *ssh = active_state; /* XXX */ | ||
803 | int ret; | 805 | int ret; |
804 | const char *forced = NULL, *tty = NULL; | 806 | const char *forced = NULL, *tty = NULL; |
805 | char session_type[1024]; | 807 | char session_type[1024]; |
@@ -842,8 +844,8 @@ do_exec(Session *s, const char *command) | |||
842 | tty == NULL ? "" : " on ", | 844 | tty == NULL ? "" : " on ", |
843 | tty == NULL ? "" : tty, | 845 | tty == NULL ? "" : tty, |
844 | s->pw->pw_name, | 846 | s->pw->pw_name, |
845 | get_remote_ipaddr(), | 847 | ssh_remote_ipaddr(ssh), |
846 | get_remote_port(), | 848 | ssh_remote_port(ssh), |
847 | s->self); | 849 | s->self); |
848 | 850 | ||
849 | #ifdef SSH_AUDIT_EVENTS | 851 | #ifdef SSH_AUDIT_EVENTS |
@@ -878,6 +880,7 @@ do_exec(Session *s, const char *command) | |||
878 | void | 880 | void |
879 | do_login(Session *s, const char *command) | 881 | do_login(Session *s, const char *command) |
880 | { | 882 | { |
883 | struct ssh *ssh = active_state; /* XXX */ | ||
881 | socklen_t fromlen; | 884 | socklen_t fromlen; |
882 | struct sockaddr_storage from; | 885 | struct sockaddr_storage from; |
883 | struct passwd * pw = s->pw; | 886 | struct passwd * pw = s->pw; |
@@ -900,7 +903,7 @@ do_login(Session *s, const char *command) | |||
900 | /* Record that there was a login on that tty from the remote host. */ | 903 | /* Record that there was a login on that tty from the remote host. */ |
901 | if (!use_privsep) | 904 | if (!use_privsep) |
902 | record_login(pid, s->tty, pw->pw_name, pw->pw_uid, | 905 | record_login(pid, s->tty, pw->pw_name, pw->pw_uid, |
903 | get_remote_name_or_ip(utmp_len, | 906 | session_get_remote_name_or_ip(ssh, utmp_len, |
904 | options.use_dns), | 907 | options.use_dns), |
905 | (struct sockaddr *)&from, fromlen); | 908 | (struct sockaddr *)&from, fromlen); |
906 | 909 | ||
@@ -1161,6 +1164,7 @@ copy_environment(char **source, char ***env, u_int *envsize) | |||
1161 | static char ** | 1164 | static char ** |
1162 | do_setup_env(Session *s, const char *shell) | 1165 | do_setup_env(Session *s, const char *shell) |
1163 | { | 1166 | { |
1167 | struct ssh *ssh = active_state; /* XXX */ | ||
1164 | char buf[256]; | 1168 | char buf[256]; |
1165 | u_int i, envsize; | 1169 | u_int i, envsize; |
1166 | char **env, *laddr; | 1170 | char **env, *laddr; |
@@ -1262,12 +1266,14 @@ do_setup_env(Session *s, const char *shell) | |||
1262 | 1266 | ||
1263 | /* SSH_CLIENT deprecated */ | 1267 | /* SSH_CLIENT deprecated */ |
1264 | snprintf(buf, sizeof buf, "%.50s %d %d", | 1268 | snprintf(buf, sizeof buf, "%.50s %d %d", |
1265 | get_remote_ipaddr(), get_remote_port(), get_local_port()); | 1269 | ssh_remote_ipaddr(ssh), ssh_remote_port(ssh), |
1270 | ssh_local_port(ssh)); | ||
1266 | child_set_env(&env, &envsize, "SSH_CLIENT", buf); | 1271 | child_set_env(&env, &envsize, "SSH_CLIENT", buf); |
1267 | 1272 | ||
1268 | laddr = get_local_ipaddr(packet_get_connection_in()); | 1273 | laddr = get_local_ipaddr(packet_get_connection_in()); |
1269 | snprintf(buf, sizeof buf, "%.50s %d %.50s %d", | 1274 | snprintf(buf, sizeof buf, "%.50s %d %.50s %d", |
1270 | get_remote_ipaddr(), get_remote_port(), laddr, get_local_port()); | 1275 | ssh_remote_ipaddr(ssh), ssh_remote_port(ssh), |
1276 | laddr, ssh_local_port(ssh)); | ||
1271 | free(laddr); | 1277 | free(laddr); |
1272 | child_set_env(&env, &envsize, "SSH_CONNECTION", buf); | 1278 | child_set_env(&env, &envsize, "SSH_CONNECTION", buf); |
1273 | 1279 | ||
@@ -1317,7 +1323,7 @@ do_setup_env(Session *s, const char *shell) | |||
1317 | * Pull in any environment variables that may have | 1323 | * Pull in any environment variables that may have |
1318 | * been set by PAM. | 1324 | * been set by PAM. |
1319 | */ | 1325 | */ |
1320 | if (options.use_pam) { | 1326 | if (options.use_pam && !options.use_login) { |
1321 | char **p; | 1327 | char **p; |
1322 | 1328 | ||
1323 | p = fetch_pam_child_environment(); | 1329 | p = fetch_pam_child_environment(); |
@@ -1684,6 +1690,7 @@ child_close_fds(void) | |||
1684 | void | 1690 | void |
1685 | do_child(Session *s, const char *command) | 1691 | do_child(Session *s, const char *command) |
1686 | { | 1692 | { |
1693 | struct ssh *ssh = active_state; /* XXX */ | ||
1687 | extern char **environ; | 1694 | extern char **environ; |
1688 | char **env; | 1695 | char **env; |
1689 | char *argv[ARGV_MAX]; | 1696 | char *argv[ARGV_MAX]; |
@@ -1760,14 +1767,14 @@ do_child(Session *s, const char *command) | |||
1760 | 1767 | ||
1761 | /* we have to stash the hostname before we close our socket. */ | 1768 | /* we have to stash the hostname before we close our socket. */ |
1762 | if (options.use_login) | 1769 | if (options.use_login) |
1763 | hostname = get_remote_name_or_ip(utmp_len, | 1770 | hostname = session_get_remote_name_or_ip(ssh, utmp_len, |
1764 | options.use_dns); | 1771 | options.use_dns); |
1765 | /* | 1772 | /* |
1766 | * Close the connection descriptors; note that this is the child, and | 1773 | * Close the connection descriptors; note that this is the child, and |
1767 | * the server will still have the socket open, and it is important | 1774 | * the server will still have the socket open, and it is important |
1768 | * that we do not shutdown it. Note that the descriptors cannot be | 1775 | * that we do not shutdown it. Note that the descriptors cannot be |
1769 | * closed before building the environment, as we call | 1776 | * closed before building the environment, as we call |
1770 | * get_remote_ipaddr there. | 1777 | * ssh_remote_ipaddr there. |
1771 | */ | 1778 | */ |
1772 | child_close_fds(); | 1779 | child_close_fds(); |
1773 | 1780 | ||
@@ -2526,12 +2533,13 @@ session_exit_message(Session *s, int status) | |||
2526 | void | 2533 | void |
2527 | session_close(Session *s) | 2534 | session_close(Session *s) |
2528 | { | 2535 | { |
2536 | struct ssh *ssh = active_state; /* XXX */ | ||
2529 | u_int i; | 2537 | u_int i; |
2530 | 2538 | ||
2531 | verbose("Close session: user %s from %.200s port %d id %d", | 2539 | verbose("Close session: user %s from %.200s port %d id %d", |
2532 | s->pw->pw_name, | 2540 | s->pw->pw_name, |
2533 | get_remote_ipaddr(), | 2541 | ssh_remote_ipaddr(ssh), |
2534 | get_remote_port(), | 2542 | ssh_remote_port(ssh), |
2535 | s->self); | 2543 | s->self); |
2536 | 2544 | ||
2537 | if (s->ttyfd != -1) | 2545 | if (s->ttyfd != -1) |
@@ -2800,3 +2808,18 @@ do_cleanup(Authctxt *authctxt) | |||
2800 | if (!use_privsep || mm_is_monitor()) | 2808 | if (!use_privsep || mm_is_monitor()) |
2801 | session_destroy_all(session_pty_cleanup2); | 2809 | session_destroy_all(session_pty_cleanup2); |
2802 | } | 2810 | } |
2811 | |||
2812 | /* Return a name for the remote host that fits inside utmp_size */ | ||
2813 | |||
2814 | const char * | ||
2815 | session_get_remote_name_or_ip(struct ssh *ssh, u_int utmp_size, int use_dns) | ||
2816 | { | ||
2817 | const char *remote = ""; | ||
2818 | |||
2819 | if (utmp_size > 0) | ||
2820 | remote = auth_get_canonical_hostname(ssh, use_dns); | ||
2821 | if (utmp_size == 0 || strlen(remote) > utmp_size) | ||
2822 | remote = ssh_remote_ipaddr(ssh); | ||
2823 | return remote; | ||
2824 | } | ||
2825 | |||