diff options
Diffstat (limited to 'session.c')
-rw-r--r-- | session.c | 63 |
1 files changed, 34 insertions, 29 deletions
@@ -33,7 +33,7 @@ | |||
33 | */ | 33 | */ |
34 | 34 | ||
35 | #include "includes.h" | 35 | #include "includes.h" |
36 | RCSID("$OpenBSD: session.c,v 1.89 2001/06/13 09:10:31 markus Exp $"); | 36 | RCSID("$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); | |||
128 | void session_close(Session *s); | 128 | void session_close(Session *s); |
129 | void do_exec_pty(Session *s, const char *command); | 129 | void do_exec_pty(Session *s, const char *command); |
130 | void do_exec_no_pty(Session *s, const char *command); | 130 | void do_exec_no_pty(Session *s, const char *command); |
131 | void do_exec(Session *s, const char *command); | ||
131 | void do_login(Session *s, const char *command); | 132 | void do_login(Session *s, const char *command); |
132 | #ifdef LOGIN_NEEDS_UTMPX | 133 | #ifdef LOGIN_NEEDS_UTMPX |
133 | void do_pre_login(Session *s); | 134 | void 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 | */ | ||
596 | void | ||
597 | do_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 */ |
602 | void | 622 | void |
603 | do_login(Session *s, const char *command) | 623 | do_login(Session *s, const char *command) |
@@ -1666,13 +1686,8 @@ session_x11_req(Session *s) | |||
1666 | int | 1686 | int |
1667 | session_shell_req(Session *s) | 1687 | session_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 | ||