diff options
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | session.c | 68 |
2 files changed, 34 insertions, 43 deletions
@@ -1,3 +1,10 @@ | |||
1 | 20010613 | ||
2 | - OpenBSD CVS Sync | ||
3 | - markus@cvs.openbsd.org 2001/06/12 10:58:29 | ||
4 | [session.c] | ||
5 | merge session_free into session_close() | ||
6 | merge pty_cleanup_proc into session_pty_cleanup() | ||
7 | |||
1 | 20010612 | 8 | 20010612 |
2 | - scp.c ID update (upstream synced vfsprintf() from us) | 9 | - scp.c ID update (upstream synced vfsprintf() from us) |
3 | - OpenBSD CVS Sync | 10 | - OpenBSD CVS Sync |
@@ -5616,4 +5623,4 @@ | |||
5616 | - Wrote replacements for strlcpy and mkdtemp | 5623 | - Wrote replacements for strlcpy and mkdtemp |
5617 | - Released 1.0pre1 | 5624 | - Released 1.0pre1 |
5618 | 5625 | ||
5619 | $Id: ChangeLog,v 1.1280 2001/06/12 00:23:12 mouring Exp $ | 5626 | $Id: ChangeLog,v 1.1281 2001/06/13 04:35:43 mouring Exp $ |
@@ -33,7 +33,7 @@ | |||
33 | */ | 33 | */ |
34 | 34 | ||
35 | #include "includes.h" | 35 | #include "includes.h" |
36 | RCSID("$OpenBSD: session.c,v 1.84 2001/06/11 10:18:24 markus Exp $"); | 36 | RCSID("$OpenBSD: session.c,v 1.85 2001/06/12 10:58:29 markus Exp $"); |
37 | 37 | ||
38 | #include "ssh.h" | 38 | #include "ssh.h" |
39 | #include "ssh1.h" | 39 | #include "ssh1.h" |
@@ -121,7 +121,7 @@ struct Session { | |||
121 | 121 | ||
122 | Session *session_new(void); | 122 | Session *session_new(void); |
123 | void session_set_fds(Session *s, int fdin, int fdout, int fderr); | 123 | void session_set_fds(Session *s, int fdin, int fdout, int fderr); |
124 | void session_pty_cleanup(Session *s); | 124 | void session_pty_cleanup(void *session); |
125 | void session_proctitle(Session *s); | 125 | void session_proctitle(Session *s); |
126 | int session_setup_x11fwd(Session *s); | 126 | int session_setup_x11fwd(Session *s); |
127 | void session_close(Session *s); | 127 | void session_close(Session *s); |
@@ -232,27 +232,6 @@ xauthfile_cleanup_proc(void *_pw) | |||
232 | } | 232 | } |
233 | 233 | ||
234 | /* | 234 | /* |
235 | * Function to perform cleanup if we get aborted abnormally (e.g., due to a | ||
236 | * dropped connection). | ||
237 | */ | ||
238 | void | ||
239 | pty_cleanup_proc(void *session) | ||
240 | { | ||
241 | Session *s=session; | ||
242 | if (s == NULL) | ||
243 | fatal("pty_cleanup_proc: no session"); | ||
244 | debug("pty_cleanup_proc: %s", s->tty); | ||
245 | |||
246 | if (s->pid != 0) { | ||
247 | /* Record that the user has logged out. */ | ||
248 | record_logout(s->pid, s->tty); | ||
249 | } | ||
250 | |||
251 | /* Release the pseudo-tty. */ | ||
252 | pty_release(s->tty); | ||
253 | } | ||
254 | |||
255 | /* | ||
256 | * Prepares for an interactive session. This is called after the user has | 235 | * Prepares for an interactive session. This is called after the user has |
257 | * been successfully authenticated. During this message exchange, pseudo | 236 | * been successfully authenticated. During this message exchange, pseudo |
258 | * terminals are allocated, X11, TCP/IP, and authentication agent forwardings | 237 | * terminals are allocated, X11, TCP/IP, and authentication agent forwardings |
@@ -311,7 +290,7 @@ do_authenticated1(Authctxt *authctxt) | |||
311 | error("Failed to allocate pty."); | 290 | error("Failed to allocate pty."); |
312 | break; | 291 | break; |
313 | } | 292 | } |
314 | fatal_add_cleanup(pty_cleanup_proc, (void *)s); | 293 | fatal_add_cleanup(session_pty_cleanup, (void *)s); |
315 | pty_setowner(s->pw, s->tty); | 294 | pty_setowner(s->pw, s->tty); |
316 | 295 | ||
317 | /* Get TERM from the packet. Note that the value may be of arbitrary length. */ | 296 | /* Get TERM from the packet. Note that the value may be of arbitrary length. */ |
@@ -1552,7 +1531,6 @@ session_new(void) | |||
1552 | debug("session_new: init"); | 1531 | debug("session_new: init"); |
1553 | for(i = 0; i < MAX_SESSIONS; i++) { | 1532 | for(i = 0; i < MAX_SESSIONS; i++) { |
1554 | sessions[i].used = 0; | 1533 | sessions[i].used = 0; |
1555 | sessions[i].self = i; | ||
1556 | } | 1534 | } |
1557 | did_init = 1; | 1535 | did_init = 1; |
1558 | } | 1536 | } |
@@ -1564,6 +1542,7 @@ session_new(void) | |||
1564 | s->ptyfd = -1; | 1542 | s->ptyfd = -1; |
1565 | s->ttyfd = -1; | 1543 | s->ttyfd = -1; |
1566 | s->used = 1; | 1544 | s->used = 1; |
1545 | s->self = i; | ||
1567 | debug("session_new: session %d", i); | 1546 | debug("session_new: session %d", i); |
1568 | return s; | 1547 | return s; |
1569 | } | 1548 | } |
@@ -1680,7 +1659,7 @@ session_pty_req(Session *s) | |||
1680 | * Add a cleanup function to clear the utmp entry and record logout | 1659 | * Add a cleanup function to clear the utmp entry and record logout |
1681 | * time in case we call fatal() (e.g., the connection gets closed). | 1660 | * time in case we call fatal() (e.g., the connection gets closed). |
1682 | */ | 1661 | */ |
1683 | fatal_add_cleanup(pty_cleanup_proc, (void *)s); | 1662 | fatal_add_cleanup(session_pty_cleanup, (void *)s); |
1684 | pty_setowner(s->pw, s->tty); | 1663 | pty_setowner(s->pw, s->tty); |
1685 | /* Get window size from the packet. */ | 1664 | /* Get window size from the packet. */ |
1686 | pty_change_window_size(s->ptyfd, s->row, s->col, s->xpixel, s->ypixel); | 1665 | pty_change_window_size(s->ptyfd, s->row, s->col, s->xpixel, s->ypixel); |
@@ -1864,19 +1843,27 @@ session_set_fds(Session *s, int fdin, int fdout, int fderr) | |||
1864 | 1); | 1843 | 1); |
1865 | } | 1844 | } |
1866 | 1845 | ||
1846 | /* | ||
1847 | * Function to perform pty cleanup. Also called if we get aborted abnormally | ||
1848 | * (e.g., due to a dropped connection). | ||
1849 | */ | ||
1867 | void | 1850 | void |
1868 | session_pty_cleanup(Session *s) | 1851 | session_pty_cleanup(void *session) |
1869 | { | 1852 | { |
1870 | if (s == NULL || s->ttyfd == -1) | 1853 | Session *s = session; |
1854 | |||
1855 | if (s == NULL) { | ||
1856 | error("session_pty_cleanup: no session"); | ||
1857 | return; | ||
1858 | } | ||
1859 | if (s->ttyfd == -1) | ||
1871 | return; | 1860 | return; |
1872 | 1861 | ||
1873 | debug("session_pty_cleanup: session %d release %s", s->self, s->tty); | 1862 | debug("session_pty_cleanup: session %d release %s", s->self, s->tty); |
1874 | 1863 | ||
1875 | /* Cancel the cleanup function. */ | ||
1876 | fatal_remove_cleanup(pty_cleanup_proc, (void *)s); | ||
1877 | |||
1878 | /* Record that the user has logged out. */ | 1864 | /* Record that the user has logged out. */ |
1879 | record_logout(s->pid, s->tty); | 1865 | if (s->pid != 0) |
1866 | record_logout(s->pid, s->tty); | ||
1880 | 1867 | ||
1881 | /* Release the pseudo-tty. */ | 1868 | /* Release the pseudo-tty. */ |
1882 | pty_release(s->tty); | 1869 | pty_release(s->tty); |
@@ -1898,7 +1885,7 @@ session_exit_message(Session *s, int status) | |||
1898 | fatal("session_close: no session"); | 1885 | fatal("session_close: no session"); |
1899 | c = channel_lookup(s->chanid); | 1886 | c = channel_lookup(s->chanid); |
1900 | if (c == NULL) | 1887 | if (c == NULL) |
1901 | fatal("session_close: session %d: no channel %d", | 1888 | fatal("session_exit_message: session %d: no channel %d", |
1902 | s->self, s->chanid); | 1889 | s->self, s->chanid); |
1903 | debug("session_exit_message: session %d channel %d pid %d", | 1890 | debug("session_exit_message: session %d channel %d pid %d", |
1904 | s->self, s->chanid, s->pid); | 1891 | s->self, s->chanid, s->pid); |
@@ -1940,9 +1927,13 @@ session_exit_message(Session *s, int status) | |||
1940 | } | 1927 | } |
1941 | 1928 | ||
1942 | void | 1929 | void |
1943 | session_free(Session *s) | 1930 | session_close(Session *s) |
1944 | { | 1931 | { |
1945 | debug("session_free: session %d pid %d", s->self, s->pid); | 1932 | debug("session_close: session %d pid %d", s->self, s->pid); |
1933 | if (s->ttyfd != -1) { | ||
1934 | fatal_remove_cleanup(session_pty_cleanup, (void *)s); | ||
1935 | session_pty_cleanup(s); | ||
1936 | } | ||
1946 | if (s->term) | 1937 | if (s->term) |
1947 | xfree(s->term); | 1938 | xfree(s->term); |
1948 | if (s->display) | 1939 | if (s->display) |
@@ -1952,13 +1943,6 @@ session_free(Session *s) | |||
1952 | if (s->auth_proto) | 1943 | if (s->auth_proto) |
1953 | xfree(s->auth_proto); | 1944 | xfree(s->auth_proto); |
1954 | s->used = 0; | 1945 | s->used = 0; |
1955 | } | ||
1956 | |||
1957 | void | ||
1958 | session_close(Session *s) | ||
1959 | { | ||
1960 | session_pty_cleanup(s); | ||
1961 | session_free(s); | ||
1962 | session_proctitle(s); | 1946 | session_proctitle(s); |
1963 | } | 1947 | } |
1964 | 1948 | ||