2009-06-27 06:24:04 +00:00
|
|
|
diff -up /dev/null openssh-5.2p1/chrootenv.h
|
|
|
|
--- /dev/null 2009-06-11 17:05:12.257284457 +0200
|
2009-06-29 20:51:17 +00:00
|
|
|
+++ openssh-5.2p1/chrootenv.h 2009-06-29 11:06:19.772277766 +0200
|
|
|
|
@@ -0,0 +1,32 @@
|
2009-06-27 06:24:04 +00:00
|
|
|
+/* $OpenBSD: session.h,v 1.30 2008/05/08 12:21:16 djm Exp $ */
|
|
|
|
+
|
|
|
|
+/*
|
|
|
|
+ * Copyright (c) 2000, 2001 Markus Friedl. All rights reserved.
|
|
|
|
+ *
|
|
|
|
+ * Redistribution and use in source and binary forms, with or without
|
|
|
|
+ * modification, are permitted provided that the following conditions
|
|
|
|
+ * are met:
|
|
|
|
+ * 1. Redistributions of source code must retain the above copyright
|
|
|
|
+ * notice, this list of conditions and the following disclaimer.
|
|
|
|
+ * 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
+ * notice, this list of conditions and the following disclaimer in the
|
|
|
|
+ * documentation and/or other materials provided with the distribution.
|
|
|
|
+ *
|
|
|
|
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
+ */
|
|
|
|
+#ifndef CHROOTENV_H
|
|
|
|
+#define CHROOTENV_H
|
|
|
|
+
|
|
|
|
+extern int chroot_no_tree;
|
|
|
|
+
|
|
|
|
+#endif
|
|
|
|
+
|
2009-06-23 17:59:23 +00:00
|
|
|
diff -up openssh-5.2p1/session.c.homechroot openssh-5.2p1/session.c
|
2009-06-29 20:51:17 +00:00
|
|
|
--- openssh-5.2p1/session.c.homechroot 2009-06-29 10:58:43.715586616 +0200
|
|
|
|
+++ openssh-5.2p1/session.c 2009-06-29 11:04:58.684830462 +0200
|
|
|
|
@@ -119,6 +119,8 @@ void do_child(Session *, const char *);
|
2009-06-27 06:24:04 +00:00
|
|
|
void do_motd(void);
|
|
|
|
int check_quietlogin(Session *, const char *);
|
2009-06-23 17:59:23 +00:00
|
|
|
|
|
|
|
+int chroot_no_tree = 0;
|
|
|
|
+
|
2009-06-27 06:24:04 +00:00
|
|
|
static void do_authenticated1(Authctxt *);
|
|
|
|
static void do_authenticated2(Authctxt *);
|
|
|
|
|
2009-06-29 20:51:17 +00:00
|
|
|
@@ -784,6 +786,11 @@ do_exec(Session *s, const char *command)
|
2009-06-27 06:24:04 +00:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
+ if ((s->is_subsystem != SUBSYSTEM_INT_SFTP) && chroot_no_tree) {
|
|
|
|
+ logit("You aren't welcomed, go away!");
|
|
|
|
+ exit (1);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
if (options.adm_forced_command) {
|
|
|
|
original_command = command;
|
|
|
|
command = options.adm_forced_command;
|
2009-06-29 20:51:17 +00:00
|
|
|
@@ -1408,6 +1415,7 @@ safely_chroot(const char *path, uid_t ui
|
2009-04-03 12:37:30 +00:00
|
|
|
const char *cp;
|
|
|
|
char component[MAXPATHLEN];
|
|
|
|
struct stat st;
|
|
|
|
+ int last;
|
|
|
|
|
|
|
|
if (*path != '/')
|
|
|
|
fatal("chroot path does not begin at root");
|
2009-06-29 20:51:17 +00:00
|
|
|
@@ -1419,7 +1427,7 @@ safely_chroot(const char *path, uid_t ui
|
2009-04-03 12:37:30 +00:00
|
|
|
* root-owned directory with strict permissions.
|
|
|
|
*/
|
|
|
|
for (cp = path; cp != NULL;) {
|
|
|
|
- if ((cp = strchr(cp, '/')) == NULL)
|
|
|
|
+ if (((last = ((cp = strchr(cp, '/')) == NULL))))
|
|
|
|
strlcpy(component, path, sizeof(component));
|
|
|
|
else {
|
|
|
|
cp++;
|
2009-06-29 20:51:17 +00:00
|
|
|
@@ -1432,15 +1440,19 @@ safely_chroot(const char *path, uid_t ui
|
2009-04-03 12:37:30 +00:00
|
|
|
if (stat(component, &st) != 0)
|
|
|
|
fatal("%s: stat(\"%s\"): %s", __func__,
|
|
|
|
component, strerror(errno));
|
|
|
|
- if (st.st_uid != 0 || (st.st_mode & 022) != 0)
|
|
|
|
+ if ((st.st_uid != 0 || (st.st_mode & 022) != 0) && !(last && st.st_uid == uid))
|
|
|
|
fatal("bad ownership or modes for chroot "
|
|
|
|
"directory %s\"%s\"",
|
|
|
|
cp == NULL ? "" : "component ", component);
|
2009-06-23 17:59:23 +00:00
|
|
|
if (!S_ISDIR(st.st_mode))
|
|
|
|
fatal("chroot path %s\"%s\" is not a directory",
|
|
|
|
cp == NULL ? "" : "component ", component);
|
2009-06-29 20:51:17 +00:00
|
|
|
-
|
2009-06-23 17:59:23 +00:00
|
|
|
}
|
2009-06-29 20:51:17 +00:00
|
|
|
+ setenv ("TZ", "/etc/localtime", 0);
|
|
|
|
+ tzset ();
|
|
|
|
+
|
2009-06-27 06:24:04 +00:00
|
|
|
+ if (st.st_uid != uid)
|
|
|
|
+ ++chroot_no_tree;
|
2009-06-29 20:51:17 +00:00
|
|
|
|
2009-06-27 06:24:04 +00:00
|
|
|
if (chdir(path) == -1)
|
|
|
|
fatal("Unable to chdir to chroot path \"%s\": "
|
2009-06-29 20:51:17 +00:00
|
|
|
@@ -1451,6 +1463,10 @@ safely_chroot(const char *path, uid_t ui
|
2009-06-27 06:24:04 +00:00
|
|
|
if (chdir("/") == -1)
|
|
|
|
fatal("%s: chdir(/) after chroot: %s",
|
|
|
|
__func__, strerror(errno));
|
|
|
|
+
|
|
|
|
+ if (access ("/etc/localtime", R_OK) < 0)
|
|
|
|
+ ++chroot_no_tree;
|
|
|
|
+
|
|
|
|
verbose("Changed root directory to \"%s\"", path);
|
|
|
|
}
|
|
|
|
|
|
|
|
diff -up openssh-5.2p1/sftp.c.homechroot openssh-5.2p1/sftp.c
|
|
|
|
--- openssh-5.2p1/sftp.c.homechroot 2009-02-14 06:26:19.000000000 +0100
|
2009-06-29 20:51:17 +00:00
|
|
|
+++ openssh-5.2p1/sftp.c 2009-06-29 11:06:59.610415272 +0200
|
|
|
|
@@ -94,6 +94,8 @@ int remote_glob(struct sftp_conn *, cons
|
2009-06-27 06:24:04 +00:00
|
|
|
|
|
|
|
extern char *__progname;
|
|
|
|
|
|
|
|
+int chroot_no_tree = 0;
|
|
|
|
+
|
|
|
|
/* Separators for interactive commands */
|
|
|
|
#define WHITESPACE " \t\r\n"
|
|
|
|
|
|
|
|
diff -up openssh-5.2p1/sftp-common.c.homechroot openssh-5.2p1/sftp-common.c
|
|
|
|
--- openssh-5.2p1/sftp-common.c.homechroot 2006-08-05 04:39:40.000000000 +0200
|
2009-06-29 20:51:17 +00:00
|
|
|
+++ openssh-5.2p1/sftp-common.c 2009-06-29 11:05:37.180134733 +0200
|
2009-06-27 06:24:04 +00:00
|
|
|
@@ -40,6 +40,7 @@
|
|
|
|
#include "xmalloc.h"
|
|
|
|
#include "buffer.h"
|
|
|
|
#include "log.h"
|
|
|
|
+#include "chrootenv.h"
|
|
|
|
|
|
|
|
#include "sftp.h"
|
|
|
|
#include "sftp-common.h"
|
2009-06-29 20:51:17 +00:00
|
|
|
@@ -194,13 +195,13 @@ ls_file(const char *name, const struct s
|
2009-06-27 06:24:04 +00:00
|
|
|
char buf[1024], mode[11+1], tbuf[12+1], ubuf[11+1], gbuf[11+1];
|
|
|
|
|
|
|
|
strmode(st->st_mode, mode);
|
|
|
|
- if (!remote && (pw = getpwuid(st->st_uid)) != NULL) {
|
|
|
|
+ if (!remote && !chroot_no_tree && (pw = getpwuid(st->st_uid)) != NULL) {
|
|
|
|
user = pw->pw_name;
|
|
|
|
} else {
|
|
|
|
snprintf(ubuf, sizeof ubuf, "%u", (u_int)st->st_uid);
|
|
|
|
user = ubuf;
|
|
|
|
}
|
|
|
|
- if (!remote && (gr = getgrgid(st->st_gid)) != NULL) {
|
|
|
|
+ if (!remote && !chroot_no_tree && (gr = getgrgid(st->st_gid)) != NULL) {
|
|
|
|
group = gr->gr_name;
|
|
|
|
} else {
|
|
|
|
snprintf(gbuf, sizeof gbuf, "%u", (u_int)st->st_gid);
|
2009-06-23 17:59:23 +00:00
|
|
|
diff -up openssh-5.2p1/sftp-server-main.c.homechroot openssh-5.2p1/sftp-server-main.c
|
|
|
|
--- openssh-5.2p1/sftp-server-main.c.homechroot 2009-02-21 22:47:02.000000000 +0100
|
2009-06-29 20:51:17 +00:00
|
|
|
+++ openssh-5.2p1/sftp-server-main.c 2009-06-29 11:07:13.704123635 +0200
|
|
|
|
@@ -22,11 +22,14 @@
|
2009-06-27 06:24:04 +00:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
+#include <time.h>
|
|
|
|
|
|
|
|
#include "log.h"
|
2009-06-23 17:59:23 +00:00
|
|
|
#include "sftp.h"
|
|
|
|
#include "misc.h"
|
|
|
|
|
2009-06-27 06:24:04 +00:00
|
|
|
+int chroot_no_tree = 0;
|
2009-06-23 17:59:23 +00:00
|
|
|
+
|
|
|
|
void
|
|
|
|
cleanup_exit(int i)
|
|
|
|
{
|