comparison svr-chansession.c @ 1840:5c13e765ddbd

Only redirect stderr after the session login. That lets errors get recorded on the server parent side, rather than being sent over a SSH connection.
author Matt Johnston <matt@ucc.asn.au>
date Mon, 18 Oct 2021 23:20:08 +0800
parents 90ac15aeac43
children cba37fe1ddc8
comparison
equal deleted inserted replaced
1839:ce17be95a42a 1840:5c13e765ddbd
839 close(chansess->master); 839 close(chansess->master);
840 840
841 pty_make_controlling_tty(&chansess->slave, chansess->tty); 841 pty_make_controlling_tty(&chansess->slave, chansess->tty);
842 842
843 if ((dup2(chansess->slave, STDIN_FILENO) < 0) || 843 if ((dup2(chansess->slave, STDIN_FILENO) < 0) ||
844 (dup2(chansess->slave, STDERR_FILENO) < 0) ||
845 (dup2(chansess->slave, STDOUT_FILENO) < 0)) { 844 (dup2(chansess->slave, STDOUT_FILENO) < 0)) {
846 TRACE(("leave ptycommand: error redirecting filedesc")) 845 TRACE(("leave ptycommand: error redirecting filedesc"))
847 return DROPBEAR_FAILURE; 846 return DROPBEAR_FAILURE;
848 } 847 }
849 848
850 close(chansess->slave);
851
852 /* write the utmp/wtmp login record - must be after changing the 849 /* write the utmp/wtmp login record - must be after changing the
853 * terminal used for stdout with the dup2 above */ 850 * terminal used for stdout with the dup2 above, otherwise
851 * the wtmp login will not be recorded */
854 li = chansess_login_alloc(chansess); 852 li = chansess_login_alloc(chansess);
855 login_login(li); 853 login_login(li);
854 dropbear_log(LOG_WARNING, "bad thing happened");
856 login_free_entry(li); 855 login_free_entry(li);
856
857 /* Can now dup2 stderr. Messages from login_login() have gone
858 to the parent stderr */
859 if (dup2(chansess->slave, STDERR_FILENO) < 0) {
860 TRACE(("leave ptycommand: error redirecting filedesc"))
861 return DROPBEAR_FAILURE;
862 }
863
864 close(chansess->slave);
857 865
858 #if DO_MOTD 866 #if DO_MOTD
859 if (svr_opts.domotd && !chansess->cmd) { 867 if (svr_opts.domotd && !chansess->cmd) {
860 /* don't show the motd if ~/.hushlogin exists */ 868 /* don't show the motd if ~/.hushlogin exists */
861 869