diff options
Diffstat (limited to 'session.c')
-rw-r--r-- | session.c | 58 |
1 files changed, 30 insertions, 28 deletions
@@ -33,7 +33,7 @@ | |||
33 | */ | 33 | */ |
34 | 34 | ||
35 | #include "includes.h" | 35 | #include "includes.h" |
36 | RCSID("$OpenBSD: session.c,v 1.186 2005/07/25 11:59:40 markus Exp $"); | 36 | RCSID("$OpenBSD: session.c,v 1.191 2005/12/24 02:27:41 djm Exp $"); |
37 | 37 | ||
38 | #include "ssh.h" | 38 | #include "ssh.h" |
39 | #include "ssh1.h" | 39 | #include "ssh1.h" |
@@ -209,15 +209,6 @@ do_authenticated(Authctxt *authctxt) | |||
209 | { | 209 | { |
210 | setproctitle("%s", authctxt->pw->pw_name); | 210 | setproctitle("%s", authctxt->pw->pw_name); |
211 | 211 | ||
212 | /* | ||
213 | * Cancel the alarm we set to limit the time taken for | ||
214 | * authentication. | ||
215 | */ | ||
216 | alarm(0); | ||
217 | if (startup_pipe != -1) { | ||
218 | close(startup_pipe); | ||
219 | startup_pipe = -1; | ||
220 | } | ||
221 | /* setup the channel layer */ | 212 | /* setup the channel layer */ |
222 | if (!no_port_forwarding_flag && options.allow_tcp_forwarding) | 213 | if (!no_port_forwarding_flag && options.allow_tcp_forwarding) |
223 | channel_permit_all_opens(); | 214 | channel_permit_all_opens(); |
@@ -1419,7 +1410,7 @@ child_close_fds(void) | |||
1419 | endpwent(); | 1410 | endpwent(); |
1420 | 1411 | ||
1421 | /* | 1412 | /* |
1422 | * Close any extra open file descriptors so that we don\'t have them | 1413 | * Close any extra open file descriptors so that we don't have them |
1423 | * hanging around in clients. Note that we want to do this after | 1414 | * hanging around in clients. Note that we want to do this after |
1424 | * initgroups, because at least on Solaris 2.3 it leaves file | 1415 | * initgroups, because at least on Solaris 2.3 it leaves file |
1425 | * descriptors open. | 1416 | * descriptors open. |
@@ -1471,7 +1462,9 @@ do_child(Session *s, const char *command) | |||
1471 | if (!check_quietlogin(s, command)) | 1462 | if (!check_quietlogin(s, command)) |
1472 | do_motd(); | 1463 | do_motd(); |
1473 | #else /* HAVE_OSF_SIA */ | 1464 | #else /* HAVE_OSF_SIA */ |
1474 | do_nologin(pw); | 1465 | /* When PAM is enabled we rely on it to do the nologin check */ |
1466 | if (!options.use_pam) | ||
1467 | do_nologin(pw); | ||
1475 | do_setusercontext(pw); | 1468 | do_setusercontext(pw); |
1476 | /* | 1469 | /* |
1477 | * PAM session modules in do_setusercontext may have | 1470 | * PAM session modules in do_setusercontext may have |
@@ -1552,7 +1545,7 @@ do_child(Session *s, const char *command) | |||
1552 | } | 1545 | } |
1553 | #endif | 1546 | #endif |
1554 | 1547 | ||
1555 | /* Change current directory to the user\'s home directory. */ | 1548 | /* Change current directory to the user's home directory. */ |
1556 | if (chdir(pw->pw_dir) < 0) { | 1549 | if (chdir(pw->pw_dir) < 0) { |
1557 | fprintf(stderr, "Could not chdir to home directory %s: %s\n", | 1550 | fprintf(stderr, "Could not chdir to home directory %s: %s\n", |
1558 | pw->pw_dir, strerror(errno)); | 1551 | pw->pw_dir, strerror(errno)); |
@@ -1867,7 +1860,7 @@ session_x11_req(Session *s) | |||
1867 | 1860 | ||
1868 | if (s->auth_proto != NULL || s->auth_data != NULL) { | 1861 | if (s->auth_proto != NULL || s->auth_data != NULL) { |
1869 | error("session_x11_req: session %d: " | 1862 | error("session_x11_req: session %d: " |
1870 | "x11 fowarding already active", s->self); | 1863 | "x11 forwarding already active", s->self); |
1871 | return 0; | 1864 | return 0; |
1872 | } | 1865 | } |
1873 | s->single_connection = packet_get_char(); | 1866 | s->single_connection = packet_get_char(); |
@@ -2099,7 +2092,7 @@ session_close_x11(int id) | |||
2099 | { | 2092 | { |
2100 | Channel *c; | 2093 | Channel *c; |
2101 | 2094 | ||
2102 | if ((c = channel_lookup(id)) == NULL) { | 2095 | if ((c = channel_by_id(id)) == NULL) { |
2103 | debug("session_close_x11: x11 channel %d missing", id); | 2096 | debug("session_close_x11: x11 channel %d missing", id); |
2104 | } else { | 2097 | } else { |
2105 | /* Detach X11 listener */ | 2098 | /* Detach X11 listener */ |
@@ -2154,7 +2147,6 @@ static void | |||
2154 | session_exit_message(Session *s, int status) | 2147 | session_exit_message(Session *s, int status) |
2155 | { | 2148 | { |
2156 | Channel *c; | 2149 | Channel *c; |
2157 | u_int i; | ||
2158 | 2150 | ||
2159 | if ((c = channel_lookup(s->chanid)) == NULL) | 2151 | if ((c = channel_lookup(s->chanid)) == NULL) |
2160 | fatal("session_exit_message: session %d: no channel %d", | 2152 | fatal("session_exit_message: session %d: no channel %d", |
@@ -2184,7 +2176,14 @@ session_exit_message(Session *s, int status) | |||
2184 | 2176 | ||
2185 | /* disconnect channel */ | 2177 | /* disconnect channel */ |
2186 | debug("session_exit_message: release channel %d", s->chanid); | 2178 | debug("session_exit_message: release channel %d", s->chanid); |
2187 | channel_cancel_cleanup(s->chanid); | 2179 | |
2180 | /* | ||
2181 | * Adjust cleanup callback attachment to send close messages when | ||
2182 | * the channel gets EOF. The session will be then be closed | ||
2183 | * by session_close_by_channel when the childs close their fds. | ||
2184 | */ | ||
2185 | channel_register_cleanup(c->self, session_close_by_channel, 1); | ||
2186 | |||
2188 | /* | 2187 | /* |
2189 | * emulate a write failure with 'chan_write_failed', nobody will be | 2188 | * emulate a write failure with 'chan_write_failed', nobody will be |
2190 | * interested in data we write. | 2189 | * interested in data we write. |
@@ -2193,15 +2192,6 @@ session_exit_message(Session *s, int status) | |||
2193 | */ | 2192 | */ |
2194 | if (c->ostate != CHAN_OUTPUT_CLOSED) | 2193 | if (c->ostate != CHAN_OUTPUT_CLOSED) |
2195 | chan_write_failed(c); | 2194 | chan_write_failed(c); |
2196 | s->chanid = -1; | ||
2197 | |||
2198 | /* Close any X11 listeners associated with this session */ | ||
2199 | if (s->x11_chanids != NULL) { | ||
2200 | for (i = 0; s->x11_chanids[i] != -1; i++) { | ||
2201 | session_close_x11(s->x11_chanids[i]); | ||
2202 | s->x11_chanids[i] = -1; | ||
2203 | } | ||
2204 | } | ||
2205 | } | 2195 | } |
2206 | 2196 | ||
2207 | void | 2197 | void |
@@ -2245,7 +2235,9 @@ session_close_by_pid(pid_t pid, int status) | |||
2245 | } | 2235 | } |
2246 | if (s->chanid != -1) | 2236 | if (s->chanid != -1) |
2247 | session_exit_message(s, status); | 2237 | session_exit_message(s, status); |
2248 | session_close(s); | 2238 | if (s->ttyfd != -1) |
2239 | session_pty_cleanup(s); | ||
2240 | s->pid = 0; | ||
2249 | } | 2241 | } |
2250 | 2242 | ||
2251 | /* | 2243 | /* |
@@ -2256,6 +2248,7 @@ void | |||
2256 | session_close_by_channel(int id, void *arg) | 2248 | session_close_by_channel(int id, void *arg) |
2257 | { | 2249 | { |
2258 | Session *s = session_by_channel(id); | 2250 | Session *s = session_by_channel(id); |
2251 | u_int i; | ||
2259 | 2252 | ||
2260 | if (s == NULL) { | 2253 | if (s == NULL) { |
2261 | debug("session_close_by_channel: no session for id %d", id); | 2254 | debug("session_close_by_channel: no session for id %d", id); |
@@ -2275,6 +2268,15 @@ session_close_by_channel(int id, void *arg) | |||
2275 | } | 2268 | } |
2276 | /* detach by removing callback */ | 2269 | /* detach by removing callback */ |
2277 | channel_cancel_cleanup(s->chanid); | 2270 | channel_cancel_cleanup(s->chanid); |
2271 | |||
2272 | /* Close any X11 listeners associated with this session */ | ||
2273 | if (s->x11_chanids != NULL) { | ||
2274 | for (i = 0; s->x11_chanids[i] != -1; i++) { | ||
2275 | session_close_x11(s->x11_chanids[i]); | ||
2276 | s->x11_chanids[i] = -1; | ||
2277 | } | ||
2278 | } | ||
2279 | |||
2278 | s->chanid = -1; | 2280 | s->chanid = -1; |
2279 | session_close(s); | 2281 | session_close(s); |
2280 | } | 2282 | } |
@@ -2369,7 +2371,7 @@ session_setup_x11fwd(Session *s) | |||
2369 | } | 2371 | } |
2370 | for (i = 0; s->x11_chanids[i] != -1; i++) { | 2372 | for (i = 0; s->x11_chanids[i] != -1; i++) { |
2371 | channel_register_cleanup(s->x11_chanids[i], | 2373 | channel_register_cleanup(s->x11_chanids[i], |
2372 | session_close_single_x11); | 2374 | session_close_single_x11, 0); |
2373 | } | 2375 | } |
2374 | 2376 | ||
2375 | /* Set up a suitable value for the DISPLAY variable. */ | 2377 | /* Set up a suitable value for the DISPLAY variable. */ |