summaryrefslogtreecommitdiff
path: root/session.c
diff options
context:
space:
mode:
Diffstat (limited to 'session.c')
-rw-r--r--session.c114
1 files changed, 56 insertions, 58 deletions
diff --git a/session.c b/session.c
index 19eaa20c3..d4b57bdfb 100644
--- a/session.c
+++ b/session.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: session.c,v 1.261 2012/12/02 20:46:11 djm Exp $ */ 1/* $OpenBSD: session.c,v 1.266 2013/07/19 07:37:48 markus Exp $ */
2/* 2/*
3 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 3 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
4 * All rights reserved 4 * All rights reserved
@@ -80,6 +80,7 @@
80#include "hostfile.h" 80#include "hostfile.h"
81#include "auth.h" 81#include "auth.h"
82#include "auth-options.h" 82#include "auth-options.h"
83#include "authfd.h"
83#include "pathnames.h" 84#include "pathnames.h"
84#include "log.h" 85#include "log.h"
85#include "servconf.h" 86#include "servconf.h"
@@ -199,7 +200,7 @@ auth_input_request_forwarding(struct passwd * pw)
199 packet_send_debug("Agent forwarding disabled: " 200 packet_send_debug("Agent forwarding disabled: "
200 "mkdtemp() failed: %.100s", strerror(errno)); 201 "mkdtemp() failed: %.100s", strerror(errno));
201 restore_uid(); 202 restore_uid();
202 xfree(auth_sock_dir); 203 free(auth_sock_dir);
203 auth_sock_dir = NULL; 204 auth_sock_dir = NULL;
204 goto authsock_err; 205 goto authsock_err;
205 } 206 }
@@ -244,11 +245,10 @@ auth_input_request_forwarding(struct passwd * pw)
244 return 1; 245 return 1;
245 246
246 authsock_err: 247 authsock_err:
247 if (auth_sock_name != NULL) 248 free(auth_sock_name);
248 xfree(auth_sock_name);
249 if (auth_sock_dir != NULL) { 249 if (auth_sock_dir != NULL) {
250 rmdir(auth_sock_dir); 250 rmdir(auth_sock_dir);
251 xfree(auth_sock_dir); 251 free(auth_sock_dir);
252 } 252 }
253 if (sock != -1) 253 if (sock != -1)
254 close(sock); 254 close(sock);
@@ -364,8 +364,8 @@ do_authenticated1(Authctxt *authctxt)
364 packet_check_eom(); 364 packet_check_eom();
365 success = session_setup_x11fwd(s); 365 success = session_setup_x11fwd(s);
366 if (!success) { 366 if (!success) {
367 xfree(s->auth_proto); 367 free(s->auth_proto);
368 xfree(s->auth_data); 368 free(s->auth_data);
369 s->auth_proto = NULL; 369 s->auth_proto = NULL;
370 s->auth_data = NULL; 370 s->auth_data = NULL;
371 } 371 }
@@ -412,7 +412,7 @@ do_authenticated1(Authctxt *authctxt)
412 if (do_exec(s, command) != 0) 412 if (do_exec(s, command) != 0)
413 packet_disconnect( 413 packet_disconnect(
414 "command execution failed"); 414 "command execution failed");
415 xfree(command); 415 free(command);
416 } else { 416 } else {
417 if (do_exec(s, NULL) != 0) 417 if (do_exec(s, NULL) != 0)
418 packet_disconnect( 418 packet_disconnect(
@@ -977,7 +977,7 @@ child_set_env(char ***envp, u_int *envsizep, const char *name,
977 break; 977 break;
978 if (env[i]) { 978 if (env[i]) {
979 /* Reuse the slot. */ 979 /* Reuse the slot. */
980 xfree(env[i]); 980 free(env[i]);
981 } else { 981 } else {
982 /* New variable. Expand if necessary. */ 982 /* New variable. Expand if necessary. */
983 envsize = *envsizep; 983 envsize = *envsizep;
@@ -1093,8 +1093,8 @@ read_etc_default_login(char ***env, u_int *envsize, uid_t uid)
1093 umask((mode_t)mask); 1093 umask((mode_t)mask);
1094 1094
1095 for (i = 0; tmpenv[i] != NULL; i++) 1095 for (i = 0; tmpenv[i] != NULL; i++)
1096 xfree(tmpenv[i]); 1096 free(tmpenv[i]);
1097 xfree(tmpenv); 1097 free(tmpenv);
1098} 1098}
1099#endif /* HAVE_ETC_DEFAULT_LOGIN */ 1099#endif /* HAVE_ETC_DEFAULT_LOGIN */
1100 1100
@@ -1110,7 +1110,7 @@ copy_environment(char **source, char ***env, u_int *envsize)
1110 for(i = 0; source[i] != NULL; i++) { 1110 for(i = 0; source[i] != NULL; i++) {
1111 var_name = xstrdup(source[i]); 1111 var_name = xstrdup(source[i]);
1112 if ((var_val = strstr(var_name, "=")) == NULL) { 1112 if ((var_val = strstr(var_name, "=")) == NULL) {
1113 xfree(var_name); 1113 free(var_name);
1114 continue; 1114 continue;
1115 } 1115 }
1116 *var_val++ = '\0'; 1116 *var_val++ = '\0';
@@ -1118,7 +1118,7 @@ copy_environment(char **source, char ***env, u_int *envsize)
1118 debug3("Copy environment: %s=%s", var_name, var_val); 1118 debug3("Copy environment: %s=%s", var_name, var_val);
1119 child_set_env(env, envsize, var_name, var_val); 1119 child_set_env(env, envsize, var_name, var_val);
1120 1120
1121 xfree(var_name); 1121 free(var_name);
1122 } 1122 }
1123} 1123}
1124 1124
@@ -1219,8 +1219,8 @@ do_setup_env(Session *s, const char *shell)
1219 child_set_env(&env, &envsize, str, str + i + 1); 1219 child_set_env(&env, &envsize, str, str + i + 1);
1220 } 1220 }
1221 custom_environment = ce->next; 1221 custom_environment = ce->next;
1222 xfree(ce->s); 1222 free(ce->s);
1223 xfree(ce); 1223 free(ce);
1224 } 1224 }
1225 } 1225 }
1226 1226
@@ -1232,7 +1232,7 @@ do_setup_env(Session *s, const char *shell)
1232 laddr = get_local_ipaddr(packet_get_connection_in()); 1232 laddr = get_local_ipaddr(packet_get_connection_in());
1233 snprintf(buf, sizeof buf, "%.50s %d %.50s %d", 1233 snprintf(buf, sizeof buf, "%.50s %d %.50s %d",
1234 get_remote_ipaddr(), get_remote_port(), laddr, get_local_port()); 1234 get_remote_ipaddr(), get_remote_port(), laddr, get_local_port());
1235 xfree(laddr); 1235 free(laddr);
1236 child_set_env(&env, &envsize, "SSH_CONNECTION", buf); 1236 child_set_env(&env, &envsize, "SSH_CONNECTION", buf);
1237 1237
1238 if (s->ttyfd != -1) 1238 if (s->ttyfd != -1)
@@ -1403,7 +1403,7 @@ do_nologin(struct passwd *pw)
1403#endif 1403#endif
1404 if (stat(nl, &sb) == -1) { 1404 if (stat(nl, &sb) == -1) {
1405 if (nl != def_nl) 1405 if (nl != def_nl)
1406 xfree(nl); 1406 free(nl);
1407 return; 1407 return;
1408 } 1408 }
1409 1409
@@ -1513,6 +1513,9 @@ do_setusercontext(struct passwd *pw)
1513 safely_chroot(chroot_path, pw->pw_uid); 1513 safely_chroot(chroot_path, pw->pw_uid);
1514 free(tmp); 1514 free(tmp);
1515 free(chroot_path); 1515 free(chroot_path);
1516 /* Make sure we don't attempt to chroot again */
1517 free(options.chroot_directory);
1518 options.chroot_directory = NULL;
1516 } 1519 }
1517 1520
1518#ifdef HAVE_LOGIN_CAP 1521#ifdef HAVE_LOGIN_CAP
@@ -1529,6 +1532,9 @@ do_setusercontext(struct passwd *pw)
1529 /* Permanently switch to the desired uid. */ 1532 /* Permanently switch to the desired uid. */
1530 permanently_set_uid(pw); 1533 permanently_set_uid(pw);
1531#endif 1534#endif
1535 } else if (options.chroot_directory != NULL &&
1536 strcasecmp(options.chroot_directory, "none") != 0) {
1537 fatal("server lacks privileges to chroot to ChrootDirectory");
1532 } 1538 }
1533 1539
1534 if (getuid() != pw->pw_uid || geteuid() != pw->pw_uid) 1540 if (getuid() != pw->pw_uid || geteuid() != pw->pw_uid)
@@ -1584,6 +1590,13 @@ launch_login(struct passwd *pw, const char *hostname)
1584static void 1590static void
1585child_close_fds(void) 1591child_close_fds(void)
1586{ 1592{
1593 extern AuthenticationConnection *auth_conn;
1594
1595 if (auth_conn) {
1596 ssh_close_authentication_connection(auth_conn);
1597 auth_conn = NULL;
1598 }
1599
1587 if (packet_get_connection_in() == packet_get_connection_out()) 1600 if (packet_get_connection_in() == packet_get_connection_out())
1588 close(packet_get_connection_in()); 1601 close(packet_get_connection_in());
1589 else { 1602 else {
@@ -2048,7 +2061,7 @@ session_pty_req(Session *s)
2048 s->ypixel = packet_get_int(); 2061 s->ypixel = packet_get_int();
2049 2062
2050 if (strcmp(s->term, "") == 0) { 2063 if (strcmp(s->term, "") == 0) {
2051 xfree(s->term); 2064 free(s->term);
2052 s->term = NULL; 2065 s->term = NULL;
2053 } 2066 }
2054 2067
@@ -2056,8 +2069,7 @@ session_pty_req(Session *s)
2056 debug("Allocating pty."); 2069 debug("Allocating pty.");
2057 if (!PRIVSEP(pty_allocate(&s->ptyfd, &s->ttyfd, s->tty, 2070 if (!PRIVSEP(pty_allocate(&s->ptyfd, &s->ttyfd, s->tty,
2058 sizeof(s->tty)))) { 2071 sizeof(s->tty)))) {
2059 if (s->term) 2072 free(s->term);
2060 xfree(s->term);
2061 s->term = NULL; 2073 s->term = NULL;
2062 s->ptyfd = -1; 2074 s->ptyfd = -1;
2063 s->ttyfd = -1; 2075 s->ttyfd = -1;
@@ -2118,7 +2130,7 @@ session_subsystem_req(Session *s)
2118 logit("subsystem request for %.100s failed, subsystem not found", 2130 logit("subsystem request for %.100s failed, subsystem not found",
2119 subsys); 2131 subsys);
2120 2132
2121 xfree(subsys); 2133 free(subsys);
2122 return success; 2134 return success;
2123} 2135}
2124 2136
@@ -2140,8 +2152,8 @@ session_x11_req(Session *s)
2140 2152
2141 success = session_setup_x11fwd(s); 2153 success = session_setup_x11fwd(s);
2142 if (!success) { 2154 if (!success) {
2143 xfree(s->auth_proto); 2155 free(s->auth_proto);
2144 xfree(s->auth_data); 2156 free(s->auth_data);
2145 s->auth_proto = NULL; 2157 s->auth_proto = NULL;
2146 s->auth_data = NULL; 2158 s->auth_data = NULL;
2147 } 2159 }
@@ -2163,7 +2175,7 @@ session_exec_req(Session *s)
2163 char *command = packet_get_string(&len); 2175 char *command = packet_get_string(&len);
2164 packet_check_eom(); 2176 packet_check_eom();
2165 success = do_exec(s, command) == 0; 2177 success = do_exec(s, command) == 0;
2166 xfree(command); 2178 free(command);
2167 return success; 2179 return success;
2168} 2180}
2169 2181
@@ -2209,8 +2221,8 @@ session_env_req(Session *s)
2209 debug2("Ignoring env request %s: disallowed name", name); 2221 debug2("Ignoring env request %s: disallowed name", name);
2210 2222
2211 fail: 2223 fail:
2212 xfree(name); 2224 free(name);
2213 xfree(val); 2225 free(val);
2214 return (0); 2226 return (0);
2215} 2227}
2216 2228
@@ -2392,24 +2404,16 @@ session_close_single_x11(int id, void *arg)
2392 if (s->x11_chanids[i] != id) 2404 if (s->x11_chanids[i] != id)
2393 session_close_x11(s->x11_chanids[i]); 2405 session_close_x11(s->x11_chanids[i]);
2394 } 2406 }
2395 xfree(s->x11_chanids); 2407 free(s->x11_chanids);
2396 s->x11_chanids = NULL; 2408 s->x11_chanids = NULL;
2397 if (s->display) { 2409 free(s->display);
2398 xfree(s->display); 2410 s->display = NULL;
2399 s->display = NULL; 2411 free(s->auth_proto);
2400 } 2412 s->auth_proto = NULL;
2401 if (s->auth_proto) { 2413 free(s->auth_data);
2402 xfree(s->auth_proto); 2414 s->auth_data = NULL;
2403 s->auth_proto = NULL; 2415 free(s->auth_display);
2404 } 2416 s->auth_display = NULL;
2405 if (s->auth_data) {
2406 xfree(s->auth_data);
2407 s->auth_data = NULL;
2408 }
2409 if (s->auth_display) {
2410 xfree(s->auth_display);
2411 s->auth_display = NULL;
2412 }
2413} 2417}
2414 2418
2415static void 2419static void
@@ -2471,24 +2475,18 @@ session_close(Session *s)
2471 debug("session_close: session %d pid %ld", s->self, (long)s->pid); 2475 debug("session_close: session %d pid %ld", s->self, (long)s->pid);
2472 if (s->ttyfd != -1) 2476 if (s->ttyfd != -1)
2473 session_pty_cleanup(s); 2477 session_pty_cleanup(s);
2474 if (s->term) 2478 free(s->term);
2475 xfree(s->term); 2479 free(s->display);
2476 if (s->display) 2480 free(s->x11_chanids);
2477 xfree(s->display); 2481 free(s->auth_display);
2478 if (s->x11_chanids) 2482 free(s->auth_data);
2479 xfree(s->x11_chanids); 2483 free(s->auth_proto);
2480 if (s->auth_display)
2481 xfree(s->auth_display);
2482 if (s->auth_data)
2483 xfree(s->auth_data);
2484 if (s->auth_proto)
2485 xfree(s->auth_proto);
2486 if (s->env != NULL) { 2484 if (s->env != NULL) {
2487 for (i = 0; i < s->num_env; i++) { 2485 for (i = 0; i < s->num_env; i++) {
2488 xfree(s->env[i].name); 2486 free(s->env[i].name);
2489 xfree(s->env[i].val); 2487 free(s->env[i].val);
2490 } 2488 }
2491 xfree(s->env); 2489 free(s->env);
2492 } 2490 }
2493 session_proctitle(s); 2491 session_proctitle(s);
2494 session_unused(s->self); 2492 session_unused(s->self);