diff options
-rw-r--r-- | session.c | 20 |
1 files changed, 12 insertions, 8 deletions
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: session.c,v 1.319 2020/03/13 03:17:07 djm Exp $ */ | 1 | /* $OpenBSD: session.c,v 1.320 2020/06/26 04:45:11 dtucker 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 |
@@ -1206,19 +1206,21 @@ static void | |||
1206 | do_rc_files(struct ssh *ssh, Session *s, const char *shell) | 1206 | do_rc_files(struct ssh *ssh, Session *s, const char *shell) |
1207 | { | 1207 | { |
1208 | FILE *f = NULL; | 1208 | FILE *f = NULL; |
1209 | char cmd[1024]; | 1209 | char *cmd = NULL, *user_rc = NULL; |
1210 | int do_xauth; | 1210 | int do_xauth; |
1211 | struct stat st; | 1211 | struct stat st; |
1212 | 1212 | ||
1213 | do_xauth = | 1213 | do_xauth = |
1214 | s->display != NULL && s->auth_proto != NULL && s->auth_data != NULL; | 1214 | s->display != NULL && s->auth_proto != NULL && s->auth_data != NULL; |
1215 | user_rc = tilde_expand_filename("~/" _PATH_SSH_USER_RC, getuid()); | ||
1215 | 1216 | ||
1216 | /* ignore _PATH_SSH_USER_RC for subsystems and admin forced commands */ | 1217 | /* ignore _PATH_SSH_USER_RC for subsystems and admin forced commands */ |
1217 | if (!s->is_subsystem && options.adm_forced_command == NULL && | 1218 | if (!s->is_subsystem && options.adm_forced_command == NULL && |
1218 | auth_opts->permit_user_rc && options.permit_user_rc && | 1219 | auth_opts->permit_user_rc && options.permit_user_rc && |
1219 | stat(_PATH_SSH_USER_RC, &st) >= 0) { | 1220 | stat(user_rc, &st) >= 0) { |
1220 | snprintf(cmd, sizeof cmd, "%s -c '%s %s'", | 1221 | if (xasprintf(&cmd, "%s -c '%s %s'", shell, _PATH_BSHELL, |
1221 | shell, _PATH_BSHELL, _PATH_SSH_USER_RC); | 1222 | user_rc) == -1) |
1223 | fatal("%s: xasprintf: %s", __func__, strerror(errno)); | ||
1222 | if (debug_flag) | 1224 | if (debug_flag) |
1223 | fprintf(stderr, "Running %s\n", cmd); | 1225 | fprintf(stderr, "Running %s\n", cmd); |
1224 | f = popen(cmd, "w"); | 1226 | f = popen(cmd, "w"); |
@@ -1229,7 +1231,7 @@ do_rc_files(struct ssh *ssh, Session *s, const char *shell) | |||
1229 | pclose(f); | 1231 | pclose(f); |
1230 | } else | 1232 | } else |
1231 | fprintf(stderr, "Could not run %s\n", | 1233 | fprintf(stderr, "Could not run %s\n", |
1232 | _PATH_SSH_USER_RC); | 1234 | user_rc); |
1233 | } else if (stat(_PATH_SSH_SYSTEM_RC, &st) >= 0) { | 1235 | } else if (stat(_PATH_SSH_SYSTEM_RC, &st) >= 0) { |
1234 | if (debug_flag) | 1236 | if (debug_flag) |
1235 | fprintf(stderr, "Running %s %s\n", _PATH_BSHELL, | 1237 | fprintf(stderr, "Running %s %s\n", _PATH_BSHELL, |
@@ -1254,8 +1256,8 @@ do_rc_files(struct ssh *ssh, Session *s, const char *shell) | |||
1254 | options.xauth_location, s->auth_display, | 1256 | options.xauth_location, s->auth_display, |
1255 | s->auth_proto, s->auth_data); | 1257 | s->auth_proto, s->auth_data); |
1256 | } | 1258 | } |
1257 | snprintf(cmd, sizeof cmd, "%s -q -", | 1259 | if (xasprintf(&cmd, "%s -q -", options.xauth_location) == -1) |
1258 | options.xauth_location); | 1260 | fatal("%s: xasprintf: %s", __func__, strerror(errno)); |
1259 | f = popen(cmd, "w"); | 1261 | f = popen(cmd, "w"); |
1260 | if (f) { | 1262 | if (f) { |
1261 | fprintf(f, "remove %s\n", | 1263 | fprintf(f, "remove %s\n", |
@@ -1269,6 +1271,8 @@ do_rc_files(struct ssh *ssh, Session *s, const char *shell) | |||
1269 | cmd); | 1271 | cmd); |
1270 | } | 1272 | } |
1271 | } | 1273 | } |
1274 | free(cmd); | ||
1275 | free(user_rc); | ||
1272 | } | 1276 | } |
1273 | 1277 | ||
1274 | static void | 1278 | static void |