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 602ef8802..93cceb231 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -4,6 +4,9 @@
4 [session.c] 4 [session.c]
5 merge session_free into session_close() 5 merge session_free into session_close()
6 merge pty_cleanup_proc into session_pty_cleanup() 6 merge pty_cleanup_proc into session_pty_cleanup()
7 - markus@cvs.openbsd.org 2001/06/12 16:10:38
8 [session.c]
9 merge ssh1/ssh2 tty msg parse and alloc code
7 10
820010612 1120010612
9 - scp.c ID update (upstream synced vfsprintf() from us) 12 - scp.c ID update (upstream synced vfsprintf() from us)
@@ -5623,4 +5626,4 @@
5623 - Wrote replacements for strlcpy and mkdtemp 5626 - Wrote replacements for strlcpy and mkdtemp
5624 - Released 1.0pre1 5627 - Released 1.0pre1
5625 5628
5626$Id: ChangeLog,v 1.1281 2001/06/13 04:35:43 mouring Exp $ 5629$Id: ChangeLog,v 1.1282 2001/06/13 04:37:36 mouring Exp $
diff --git a/session.c b/session.c
index 8999f8c84..0d7b8fa36 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.85 2001/06/12 10:58:29 markus Exp $"); 36RCSID("$OpenBSD: session.c,v 1.86 2001/06/12 16:10:38 markus Exp $");
37 37
38#include "ssh.h" 38#include "ssh.h"
39#include "ssh1.h" 39#include "ssh1.h"
@@ -122,6 +122,7 @@ struct Session {
122Session *session_new(void); 122Session *session_new(void);
123void session_set_fds(Session *s, int fdin, int fdout, int fderr); 123void session_set_fds(Session *s, int fdin, int fdout, int fderr);
124void session_pty_cleanup(void *session); 124void session_pty_cleanup(void *session);
125int session_pty_req(Session *s);
125void session_proctitle(Session *s); 126void session_proctitle(Session *s);
126int session_setup_x11fwd(Session *s); 127int session_setup_x11fwd(Session *s);
127void session_close(Session *s); 128void session_close(Session *s);
@@ -242,7 +243,7 @@ do_authenticated1(Authctxt *authctxt)
242{ 243{
243 Session *s; 244 Session *s;
244 char *command; 245 char *command;
245 int success, type, n_bytes, plen, screen_flag, have_pty = 0; 246 int success, type, plen, screen_flag;
246 int compression_level = 0, enable_compression_after_reply = 0; 247 int compression_level = 0, enable_compression_after_reply = 0;
247 u_int proto_len, data_len, dlen; 248 u_int proto_len, data_len, dlen;
248 249
@@ -275,51 +276,7 @@ do_authenticated1(Authctxt *authctxt)
275 break; 276 break;
276 277
277 case SSH_CMSG_REQUEST_PTY: 278 case SSH_CMSG_REQUEST_PTY:
278 if (no_pty_flag) { 279 success = session_pty_req(s);
279 debug("Allocating a pty not permitted for this authentication.");
280 break;
281 }
282 if (have_pty)
283 packet_disconnect("Protocol error: you already have a pty.");
284
285 debug("Allocating pty.");
286
287 /* Allocate a pty and open it. */
288 if (!pty_allocate(&s->ptyfd, &s->ttyfd, s->tty,
289 sizeof(s->tty))) {
290 error("Failed to allocate pty.");
291 break;
292 }
293 fatal_add_cleanup(session_pty_cleanup, (void *)s);
294 pty_setowner(s->pw, s->tty);
295
296 /* Get TERM from the packet. Note that the value may be of arbitrary length. */
297 s->term = packet_get_string(&dlen);
298 packet_integrity_check(dlen, strlen(s->term), type);
299 /* packet_integrity_check(plen, 4 + dlen + 4*4 + n_bytes, type); */
300 /* Remaining bytes */
301 n_bytes = plen - (4 + dlen + 4 * 4);
302
303 if (strcmp(s->term, "") == 0) {
304 xfree(s->term);
305 s->term = NULL;
306 }
307 /* Get window size from the packet. */
308 s->row = packet_get_int();
309 s->col = packet_get_int();
310 s->xpixel = packet_get_int();
311 s->ypixel = packet_get_int();
312 pty_change_window_size(s->ptyfd, s->row, s->col, s->xpixel, s->ypixel);
313
314 /* Get tty modes from the packet. */
315 tty_parse_modes(s->ttyfd, &n_bytes);
316 packet_integrity_check(plen, 4 + dlen + 4 * 4 + n_bytes, type);
317
318 session_proctitle(s);
319
320 /* Indicate that we now have a pty. */
321 success = 1;
322 have_pty = 1;
323 break; 280 break;
324 281
325 case SSH_CMSG_X11_REQUEST_FORWARDING: 282 case SSH_CMSG_X11_REQUEST_FORWARDING:
@@ -391,7 +348,7 @@ do_authenticated1(Authctxt *authctxt)
391 command = forced_command; 348 command = forced_command;
392 debug("Forced command '%.500s'", forced_command); 349 debug("Forced command '%.500s'", forced_command);
393 } 350 }
394 if (have_pty) 351 if (s->ttyfd != -1)
395 do_exec_pty(s, command); 352 do_exec_pty(s, command);
396 else 353 else
397 do_exec_no_pty(s, command); 354 do_exec_no_pty(s, command);
@@ -1631,13 +1588,24 @@ session_pty_req(Session *s)
1631 u_int len; 1588 u_int len;
1632 int n_bytes; 1589 int n_bytes;
1633 1590
1634 if (no_pty_flag) 1591 if (no_pty_flag) {
1592 debug("Allocating a pty not permitted for this authentication.");
1635 return 0; 1593 return 0;
1636 if (s->ttyfd != -1) 1594 }
1595 if (s->ttyfd != -1) {
1596 packet_disconnect("Protocol error: you already have a pty.");
1637 return 0; 1597 return 0;
1598 }
1599
1638 s->term = packet_get_string(&len); 1600 s->term = packet_get_string(&len);
1639 s->col = packet_get_int(); 1601
1640 s->row = packet_get_int(); 1602 if (compat20) {
1603 s->col = packet_get_int();
1604 s->row = packet_get_int();
1605 } else {
1606 s->row = packet_get_int();
1607 s->col = packet_get_int();
1608 }
1641 s->xpixel = packet_get_int(); 1609 s->xpixel = packet_get_int();
1642 s->ypixel = packet_get_int(); 1610 s->ypixel = packet_get_int();
1643 1611
@@ -1645,9 +1613,12 @@ session_pty_req(Session *s)
1645 xfree(s->term); 1613 xfree(s->term);
1646 s->term = NULL; 1614 s->term = NULL;
1647 } 1615 }
1616
1648 /* Allocate a pty and open it. */ 1617 /* Allocate a pty and open it. */
1618 debug("Allocating pty.");
1649 if (!pty_allocate(&s->ptyfd, &s->ttyfd, s->tty, sizeof(s->tty))) { 1619 if (!pty_allocate(&s->ptyfd, &s->ttyfd, s->tty, sizeof(s->tty))) {
1650 xfree(s->term); 1620 if (s->term)
1621 xfree(s->term);
1651 s->term = NULL; 1622 s->term = NULL;
1652 s->ptyfd = -1; 1623 s->ptyfd = -1;
1653 s->ttyfd = -1; 1624 s->ttyfd = -1;
@@ -1655,21 +1626,24 @@ session_pty_req(Session *s)
1655 return 0; 1626 return 0;
1656 } 1627 }
1657 debug("session_pty_req: session %d alloc %s", s->self, s->tty); 1628 debug("session_pty_req: session %d alloc %s", s->self, s->tty);
1629
1630 /* for SSH1 the tty modes length is not given */
1631 if (!compat20)
1632 n_bytes = packet_remaining();
1633 tty_parse_modes(s->ttyfd, &n_bytes);
1634
1658 /* 1635 /*
1659 * Add a cleanup function to clear the utmp entry and record logout 1636 * Add a cleanup function to clear the utmp entry and record logout
1660 * time in case we call fatal() (e.g., the connection gets closed). 1637 * time in case we call fatal() (e.g., the connection gets closed).
1661 */ 1638 */
1662 fatal_add_cleanup(session_pty_cleanup, (void *)s); 1639 fatal_add_cleanup(session_pty_cleanup, (void *)s);
1663 pty_setowner(s->pw, s->tty); 1640 pty_setowner(s->pw, s->tty);
1664 /* Get window size from the packet. */ 1641
1642 /* Set window size from the packet. */
1665 pty_change_window_size(s->ptyfd, s->row, s->col, s->xpixel, s->ypixel); 1643 pty_change_window_size(s->ptyfd, s->row, s->col, s->xpixel, s->ypixel);
1666 1644
1667 /* Get tty modes from the packet. */
1668 tty_parse_modes(s->ttyfd, &n_bytes);
1669 packet_done(); 1645 packet_done();
1670
1671 session_proctitle(s); 1646 session_proctitle(s);
1672
1673 return 1; 1647 return 1;
1674} 1648}
1675 1649