summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorDamien Miller <djm@cvs.openbsd.org>2010-01-13 23:47:27 +0000
committerDamien Miller <djm@cvs.openbsd.org>2010-01-13 23:47:27 +0000
commite70bd4089785cd464586e18c7f289768679d78e5 (patch)
treea558a473541ecc4757a884b945630869d4806460 /usr.bin
parent5c04643423e44d47b66d6ca98faf8341ba26daa7 (diff)
when using ChrootDirectory, make sure we test for the existence of the
user's shell inside the chroot; bz #1679, patch from alex AT rtfs.hu; ok dtucker
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/ssh/auth.c26
1 files changed, 23 insertions, 3 deletions
diff --git a/usr.bin/ssh/auth.c b/usr.bin/ssh/auth.c
index 8c30c4dab1f..4901ccc01e1 100644
--- a/usr.bin/ssh/auth.c
+++ b/usr.bin/ssh/auth.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: auth.c,v 1.82 2010/01/13 00:19:04 dtucker Exp $ */
+/* $OpenBSD: auth.c,v 1.83 2010/01/13 23:47:26 djm Exp $ */
/*
* Copyright (c) 2000 Markus Friedl. All rights reserved.
*
@@ -79,7 +79,7 @@ allowed_user(struct passwd * pw)
{
struct stat st;
const char *hostname = NULL, *ipaddr = NULL;
- char *shell;
+ char *shell, *tmp, *chroot_path;
u_int i;
/* Shouldn't be called if pw is NULL, but better safe than sorry... */
@@ -90,20 +90,40 @@ allowed_user(struct passwd * pw)
* Get the shell from the password data. An empty shell field is
* legal, and means /bin/sh.
*/
- shell = (pw->pw_shell[0] == '\0') ? _PATH_BSHELL : pw->pw_shell;
+ shell = xstrdup((pw->pw_shell[0] == '\0') ?
+ _PATH_BSHELL : pw->pw_shell);
+
+ /*
+ * Amend shell if chroot is requested.
+ */
+ if (options.chroot_directory != NULL &&
+ strcasecmp(options.chroot_directory, "none") != 0) {
+ tmp = tilde_expand_filename(options.chroot_directory,
+ pw->pw_uid);
+ chroot_path = percent_expand(tmp, "h", pw->pw_dir,
+ "u", pw->pw_name, (char *)NULL);
+ xfree(tmp);
+ xasprintf(&tmp, "%s/%s", chroot_path, shell);
+ xfree(shell);
+ shell = tmp;
+ free(chroot_path);
+ }
/* deny if shell does not exists or is not executable */
if (stat(shell, &st) != 0) {
logit("User %.100s not allowed because shell %.100s does not exist",
pw->pw_name, shell);
+ xfree(shell);
return 0;
}
if (S_ISREG(st.st_mode) == 0 ||
(st.st_mode & (S_IXOTH|S_IXUSR|S_IXGRP)) == 0) {
logit("User %.100s not allowed because shell %.100s is not executable",
pw->pw_name, shell);
+ xfree(shell);
return 0;
}
+ xfree(shell);
if (options.num_deny_users > 0 || options.num_allow_users > 0 ||
options.num_deny_groups > 0 || options.num_allow_groups > 0) {