summaryrefslogtreecommitdiff
path: root/session.c
diff options
context:
space:
mode:
authorBen Lindstrom <mouring@eviladmin.org>2001-06-13 04:35:43 +0000
committerBen Lindstrom <mouring@eviladmin.org>2001-06-13 04:35:43 +0000
commit7eaf8e4e266987629ebcb27eff9237fce96bb482 (patch)
treefc36bd7ae54f682c82f66e6ca023e05689558be8 /session.c
parent34a996877eed6e97c73e5af5f5fb3de1919c044c (diff)
- markus@cvs.openbsd.org 2001/06/12 10:58:29
[session.c] merge session_free into session_close() merge pty_cleanup_proc into session_pty_cleanup()
Diffstat (limited to 'session.c')
-rw-r--r--session.c68
1 files changed, 26 insertions, 42 deletions
diff --git a/session.c b/session.c
index 4dfca3575..8999f8c84 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.84 2001/06/11 10:18:24 markus Exp $"); 36RCSID("$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
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(Session *s); 124void session_pty_cleanup(void *session);
125void session_proctitle(Session *s); 125void session_proctitle(Session *s);
126int session_setup_x11fwd(Session *s); 126int session_setup_x11fwd(Session *s);
127void session_close(Session *s); 127void 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 */
238void
239pty_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 */
1867void 1850void
1868session_pty_cleanup(Session *s) 1851session_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
1942void 1929void
1943session_free(Session *s) 1930session_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
1957void
1958session_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