summaryrefslogtreecommitdiff
path: root/session.c
diff options
context:
space:
mode:
authorBen Lindstrom <mouring@eviladmin.org>2001-06-21 03:13:10 +0000
committerBen Lindstrom <mouring@eviladmin.org>2001-06-21 03:13:10 +0000
commitc85ab8afab0b1f73cda607859f32f0d9558af594 (patch)
treece62dd0d65e5c1a057de9d11544d603e418fa773 /session.c
parent3af4d4634f66a9325fc76d7c68262bccbb8ce24c (diff)
- markus@cvs.openbsd.org 2001/06/19 12:34:09
[session.c] cleanup forced command handling, from dwd@bell-labs.com
Diffstat (limited to 'session.c')
-rw-r--r--session.c63
1 files changed, 34 insertions, 29 deletions
diff --git a/session.c b/session.c
index 65f6bac15..005f7ab17 100644
--- a/session.c
+++ b/session.c
@@ -33,7 +33,7 @@
33 */ 33 */
34 34
35#include "includes.h" 35#include "includes.h"
36RCSID("$OpenBSD: session.c,v 1.89 2001/06/13 09:10:31 markus Exp $"); 36RCSID("$OpenBSD: session.c,v 1.90 2001/06/19 12:34:09 markus Exp $");
37 37
38#include "ssh.h" 38#include "ssh.h"
39#include "ssh1.h" 39#include "ssh1.h"
@@ -128,6 +128,7 @@ int session_setup_x11fwd(Session *s);
128void session_close(Session *s); 128void session_close(Session *s);
129void do_exec_pty(Session *s, const char *command); 129void do_exec_pty(Session *s, const char *command);
130void do_exec_no_pty(Session *s, const char *command); 130void do_exec_no_pty(Session *s, const char *command);
131void do_exec(Session *s, const char *command);
131void do_login(Session *s, const char *command); 132void do_login(Session *s, const char *command);
132#ifdef LOGIN_NEEDS_UTMPX 133#ifdef LOGIN_NEEDS_UTMPX
133void do_pre_login(Session *s); 134void do_pre_login(Session *s);
@@ -313,17 +314,7 @@ do_authenticated1(Authctxt *authctxt)
313 command = NULL; 314 command = NULL;
314 packet_integrity_check(plen, 0, type); 315 packet_integrity_check(plen, 0, type);
315 } 316 }
316 if (forced_command != NULL) { 317 do_exec(s, command);
317 original_command = command;
318 command = forced_command;
319 debug("Forced command '%.500s'", forced_command);
320 }
321 if (s->ttyfd != -1)
322 do_exec_pty(s, command);
323 else
324 do_exec_no_pty(s, command);
325 if (command != NULL)
326 xfree(command);
327 session_close(s); 318 session_close(s);
328 return; 319 return;
329 320
@@ -598,6 +589,35 @@ do_pre_login(Session *s)
598} 589}
599#endif 590#endif
600 591
592/*
593 * This is called to fork and execute a command. If another command is
594 * to be forced, execute that instead.
595 */
596void
597do_exec(Session *s, const char *command)
598{
599 if (forced_command) {
600 original_command = command;
601 command = forced_command;
602 forced_command = NULL;
603 debug("Forced command '%.900s'", command);
604 }
605
606 if (s->ttyfd != -1)
607 do_exec_pty(s, command);
608 else
609 do_exec_no_pty(s, command);
610
611 if (command != NULL)
612 xfree(command);
613
614 if (original_command != NULL) {
615 xfree(original_command);
616 original_command = NULL;
617 }
618}
619
620
601/* administrative, login(1)-like work */ 621/* administrative, login(1)-like work */
602void 622void
603do_login(Session *s, const char *command) 623do_login(Session *s, const char *command)
@@ -1666,13 +1686,8 @@ session_x11_req(Session *s)
1666int 1686int
1667session_shell_req(Session *s) 1687session_shell_req(Session *s)
1668{ 1688{
1669 /* if forced_command == NULL, the shell is execed */
1670 char *shell = forced_command;
1671 packet_done(); 1689 packet_done();
1672 if (s->ttyfd == -1) 1690 do_exec(s, NULL);
1673 do_exec_no_pty(s, shell);
1674 else
1675 do_exec_pty(s, shell);
1676 return 1; 1691 return 1;
1677} 1692}
1678 1693
@@ -1682,17 +1697,7 @@ session_exec_req(Session *s)
1682 u_int len; 1697 u_int len;
1683 char *command = packet_get_string(&len); 1698 char *command = packet_get_string(&len);
1684 packet_done(); 1699 packet_done();
1685 if (forced_command) { 1700 do_exec(s, command);
1686 original_command = command;
1687 command = forced_command;
1688 debug("Forced command '%.500s'", forced_command);
1689 }
1690 if (s->ttyfd == -1)
1691 do_exec_no_pty(s, command);
1692 else
1693 do_exec_pty(s, command);
1694 if (forced_command == NULL)
1695 xfree(command);
1696 return 1; 1701 return 1;
1697} 1702}
1698 1703