summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Lindstrom <mouring@eviladmin.org>2001-06-13 04:37:36 +0000
committerBen Lindstrom <mouring@eviladmin.org>2001-06-13 04:37:36 +0000
commit49c126044dcaa4b38dc7553f670f20b084afa6a4 (patch)
treec49df4ea95a765a224e5afe219c4b364f629ebef
parent7eaf8e4e266987629ebcb27eff9237fce96bb482 (diff)
- markus@cvs.openbsd.org 2001/06/12 16:10:38
[session.c] merge ssh1/ssh2 tty msg parse and alloc code
-rw-r--r--ChangeLog5
-rw-r--r--session.c90
2 files changed, 36 insertions, 59 deletions
diff --git a/ChangeLog b/ChangeLog
index 602ef880..93cceb23 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -4,6 +4,9 @@
[session.c]
merge session_free into session_close()
merge pty_cleanup_proc into session_pty_cleanup()
+ - markus@cvs.openbsd.org 2001/06/12 16:10:38
+ [session.c]
+ merge ssh1/ssh2 tty msg parse and alloc code
20010612
- scp.c ID update (upstream synced vfsprintf() from us)
@@ -5623,4 +5626,4 @@
- Wrote replacements for strlcpy and mkdtemp
- Released 1.0pre1
-$Id: ChangeLog,v 1.1281 2001/06/13 04:35:43 mouring Exp $
+$Id: ChangeLog,v 1.1282 2001/06/13 04:37:36 mouring Exp $
diff --git a/session.c b/session.c
index 8999f8c8..0d7b8fa3 100644
--- a/session.c
+++ b/session.c
@@ -33,7 +33,7 @@
*/
#include "includes.h"
-RCSID("$OpenBSD: session.c,v 1.85 2001/06/12 10:58:29 markus Exp $");
+RCSID("$OpenBSD: session.c,v 1.86 2001/06/12 16:10:38 markus Exp $");
#include "ssh.h"
#include "ssh1.h"
@@ -122,6 +122,7 @@ struct Session {
Session *session_new(void);
void session_set_fds(Session *s, int fdin, int fdout, int fderr);
void session_pty_cleanup(void *session);
+int session_pty_req(Session *s);
void session_proctitle(Session *s);
int session_setup_x11fwd(Session *s);
void session_close(Session *s);
@@ -242,7 +243,7 @@ do_authenticated1(Authctxt *authctxt)
{
Session *s;
char *command;
- int success, type, n_bytes, plen, screen_flag, have_pty = 0;
+ int success, type, plen, screen_flag;
int compression_level = 0, enable_compression_after_reply = 0;
u_int proto_len, data_len, dlen;
@@ -275,51 +276,7 @@ do_authenticated1(Authctxt *authctxt)
break;
case SSH_CMSG_REQUEST_PTY:
- if (no_pty_flag) {
- debug("Allocating a pty not permitted for this authentication.");
- break;
- }
- if (have_pty)
- packet_disconnect("Protocol error: you already have a pty.");
-
- debug("Allocating pty.");
-
- /* Allocate a pty and open it. */
- if (!pty_allocate(&s->ptyfd, &s->ttyfd, s->tty,
- sizeof(s->tty))) {
- error("Failed to allocate pty.");
- break;
- }
- fatal_add_cleanup(session_pty_cleanup, (void *)s);
- pty_setowner(s->pw, s->tty);
-
- /* Get TERM from the packet. Note that the value may be of arbitrary length. */
- s->term = packet_get_string(&dlen);
- packet_integrity_check(dlen, strlen(s->term), type);
- /* packet_integrity_check(plen, 4 + dlen + 4*4 + n_bytes, type); */
- /* Remaining bytes */
- n_bytes = plen - (4 + dlen + 4 * 4);
-
- if (strcmp(s->term, "") == 0) {
- xfree(s->term);
- s->term = NULL;
- }
- /* Get window size from the packet. */
- s->row = packet_get_int();
- s->col = packet_get_int();
- s->xpixel = packet_get_int();
- s->ypixel = packet_get_int();
- pty_change_window_size(s->ptyfd, s->row, s->col, s->xpixel, s->ypixel);
-
- /* Get tty modes from the packet. */
- tty_parse_modes(s->ttyfd, &n_bytes);
- packet_integrity_check(plen, 4 + dlen + 4 * 4 + n_bytes, type);
-
- session_proctitle(s);
-
- /* Indicate that we now have a pty. */
- success = 1;
- have_pty = 1;
+ success = session_pty_req(s);
break;
case SSH_CMSG_X11_REQUEST_FORWARDING:
@@ -391,7 +348,7 @@ do_authenticated1(Authctxt *authctxt)
command = forced_command;
debug("Forced command '%.500s'", forced_command);
}
- if (have_pty)
+ if (s->ttyfd != -1)
do_exec_pty(s, command);
else
do_exec_no_pty(s, command);
@@ -1631,13 +1588,24 @@ session_pty_req(Session *s)
u_int len;
int n_bytes;
- if (no_pty_flag)
+ if (no_pty_flag) {
+ debug("Allocating a pty not permitted for this authentication.");
return 0;
- if (s->ttyfd != -1)
+ }
+ if (s->ttyfd != -1) {
+ packet_disconnect("Protocol error: you already have a pty.");
return 0;
+ }
+
s->term = packet_get_string(&len);
- s->col = packet_get_int();
- s->row = packet_get_int();
+
+ if (compat20) {
+ s->col = packet_get_int();
+ s->row = packet_get_int();
+ } else {
+ s->row = packet_get_int();
+ s->col = packet_get_int();
+ }
s->xpixel = packet_get_int();
s->ypixel = packet_get_int();
@@ -1645,9 +1613,12 @@ session_pty_req(Session *s)
xfree(s->term);
s->term = NULL;
}
+
/* Allocate a pty and open it. */
+ debug("Allocating pty.");
if (!pty_allocate(&s->ptyfd, &s->ttyfd, s->tty, sizeof(s->tty))) {
- xfree(s->term);
+ if (s->term)
+ xfree(s->term);
s->term = NULL;
s->ptyfd = -1;
s->ttyfd = -1;
@@ -1655,21 +1626,24 @@ session_pty_req(Session *s)
return 0;
}
debug("session_pty_req: session %d alloc %s", s->self, s->tty);
+
+ /* for SSH1 the tty modes length is not given */
+ if (!compat20)
+ n_bytes = packet_remaining();
+ tty_parse_modes(s->ttyfd, &n_bytes);
+
/*
* Add a cleanup function to clear the utmp entry and record logout
* time in case we call fatal() (e.g., the connection gets closed).
*/
fatal_add_cleanup(session_pty_cleanup, (void *)s);
pty_setowner(s->pw, s->tty);
- /* Get window size from the packet. */
+
+ /* Set window size from the packet. */
pty_change_window_size(s->ptyfd, s->row, s->col, s->xpixel, s->ypixel);
- /* Get tty modes from the packet. */
- tty_parse_modes(s->ttyfd, &n_bytes);
packet_done();
-
session_proctitle(s);
-
return 1;
}