]> git.pld-linux.org Git - packages/openssh.git/blame - openssh-chroot.patch
Release 3 (by relup.sh)
[packages/openssh.git] / openssh-chroot.patch
CommitLineData
730d6499
AM
1diff -urNp -x '*.orig' openssh-8.8p1.org/servconf.c openssh-8.8p1/servconf.c
2--- openssh-8.8p1.org/servconf.c 2021-09-26 16:03:19.000000000 +0200
3+++ openssh-8.8p1/servconf.c 2021-12-09 20:13:16.486586503 +0100
7ae7664a 4@@ -92,7 +92,9 @@ initialize_server_options(ServerOptions
f11993b4
PG
5
6 /* Portable-specific options */
7 options->use_pam = -1;
8-
9+
10+ options->use_chroot = -1;
11+
12 /* Standard Options */
13 options->num_ports = 0;
14 options->ports_from_cmdline = 0;
730d6499 15@@ -279,6 +281,9 @@ fill_default_server_options(ServerOption
f11993b4
PG
16 if (options->use_pam == -1)
17 options->use_pam = 0;
18
19+ if (options->use_chroot == -1)
20+ options->use_chroot = 0;
21+
22 /* Standard Options */
7ae7664a
AM
23 if (options->num_host_key_files == 0) {
24 /* fill default hostkeys for protocols */
730d6499 25@@ -486,6 +491,7 @@ typedef enum {
f11993b4
PG
26 sBadOption, /* == unknown option */
27 /* Portable-specific options */
28 sUsePAM,
29+ sUseChroot,
30 /* Standard Options */
7ae7664a 31 sPort, sHostKeyFile, sLoginGraceTime,
cf41b13a 32 sPermitRootLogin, sLogFacility, sLogLevel, sLogVerbose,
730d6499 33@@ -538,6 +544,11 @@ static struct {
f11993b4
PG
34 #else
35 { "usepam", sUnsupported, SSHCFG_GLOBAL },
36 #endif
37+#ifdef CHROOT
38+ { "usechroot", sUseChroot, SSHCFG_GLOBAL },
39+#else
40+ { "usechroot", sUnsupported, SSHCFG_GLOBAL },
41+#endif /* CHROOT */
42 { "pamauthenticationviakbdint", sDeprecated, SSHCFG_GLOBAL },
43 /* Standard Options */
44 { "port", sPort, SSHCFG_GLOBAL },
730d6499 45@@ -1332,6 +1343,10 @@ process_server_config_line_depth(ServerO
f11993b4
PG
46 intptr = &options->use_pam;
47 goto parse_flag;
48
49+ case sUseChroot:
50+ intptr = &options->use_chroot;
51+ goto parse_flag;
52+
53 /* Standard Options */
54 case sBadOption:
db72af45 55 goto out;
730d6499
AM
56diff -urNp -x '*.orig' openssh-8.8p1.org/servconf.h openssh-8.8p1/servconf.h
57--- openssh-8.8p1.org/servconf.h 2021-09-26 16:03:19.000000000 +0200
58+++ openssh-8.8p1/servconf.h 2021-12-09 20:13:16.486586503 +0100
59@@ -183,6 +183,7 @@ typedef struct {
7ae7664a
AM
60 int max_authtries;
61 int max_sessions;
f11993b4
PG
62 char *banner; /* SSH-2 banner message */
63+ int use_chroot; /* Enable chrooted enviroment support */
64 int use_dns;
65 int client_alive_interval; /*
66 * poke the client this often to
730d6499
AM
67diff -urNp -x '*.orig' openssh-8.8p1.org/session.c openssh-8.8p1/session.c
68--- openssh-8.8p1.org/session.c 2021-09-26 16:03:19.000000000 +0200
69+++ openssh-8.8p1/session.c 2021-12-09 20:13:16.489919836 +0100
70@@ -1359,6 +1359,10 @@ void
f685d17f
JB
71 do_setusercontext(struct passwd *pw)
72 {
c4f5c632 73 char uidstr[32], *chroot_path, *tmp;
f11993b4
PG
74+#ifdef CHROOT
75+ char *user_dir;
76+ char *new_root;
77+#endif /* CHROOT */
78
f6a10c37
AM
79 platform_setusercontext(pw);
80
730d6499 81@@ -1401,6 +1405,29 @@ do_setusercontext(struct passwd *pw)
f685d17f
JB
82 free(options.chroot_directory);
83 options.chroot_directory = NULL;
84 in_chroot = 1;
f11993b4 85+#ifdef CHROOT
f685d17f 86+ } else if (!in_chroot && options.use_chroot) {
f11993b4
PG
87+ user_dir = xstrdup(pw->pw_dir);
88+ new_root = user_dir + 1;
89+
f685d17f 90+ while ((new_root = strchr(new_root, '.')) != NULL) {
f11993b4 91+ new_root--;
f685d17f 92+ if (strncmp(new_root, "/./", 3) == 0) {
f11993b4
PG
93+ *new_root = '\0';
94+ new_root += 2;
95+
f685d17f 96+ if (chroot(user_dir) != 0)
f11993b4 97+ fatal("Couldn't chroot to user directory %s", user_dir);
f685d17f
JB
98+ /* NOTE: session->pw comes from pwcopy(), so replace pw_dir this way (incompatible with plain getpwnam() or getpwnam_r()) */
99+ free(pw->pw_dir);
100+ pw->pw_dir = xstrdup(new_root);
101+ in_chroot = 1;
f11993b4
PG
102+ break;
103+ }
104+ new_root += 2;
105+ }
f685d17f 106+ free(user_dir);
f11993b4
PG
107+#endif /* CHROOT */
108 }
109
08811ee8 110 #ifdef HAVE_LOGIN_CAP
730d6499
AM
111diff -urNp -x '*.orig' openssh-8.8p1.org/sshd_config openssh-8.8p1/sshd_config
112--- openssh-8.8p1.org/sshd_config 2021-12-09 20:13:16.326586503 +0100
113+++ openssh-8.8p1/sshd_config 2021-12-09 20:13:16.489919836 +0100
7ae7664a 114@@ -85,6 +85,10 @@ GSSAPIAuthentication yes
db72af45 115 # and KbdInteractiveAuthentication to 'no'.
15a59314 116 #UsePAM no
f11993b4
PG
117
118+# Set this to 'yes' to enable support for chrooted user environment.
fc8529e5 119+# You must create such environment before you can use this feature.
f11993b4
PG
120+#UseChroot yes
121+
fc8529e5 122 #AllowAgentForwarding yes
730d6499
AM
123 #AllowTcpForwarding yes
124 #GatewayPorts no
125diff -urNp -x '*.orig' openssh-8.8p1.org/sshd_config.0 openssh-8.8p1/sshd_config.0
126--- openssh-8.8p1.org/sshd_config.0 2021-09-26 16:06:42.000000000 +0200
127+++ openssh-8.8p1/sshd_config.0 2021-12-09 20:13:16.489919836 +0100
128@@ -1053,6 +1053,16 @@ DESCRIPTION
ab837ce4
AG
129 open channels. This option may be useful in conjunction with
130 ChannelTimeout.
f11993b4
PG
131
132+ UseChroot
133+ Specifies whether to use chroot-jail environment with ssh/sftp,
134+ i.e. restrict users to a particular area in the filesystem. This
135+ is done by setting user home directory to, for example,
136+ /path/to/chroot/./home/username. sshd looks for a '.' in the
137+ users home directory, then calls chroot(2) to whatever directory
138+ was before the . and continues with the normal ssh functionality.
139+ For this to work properly you have to create special chroot-jail
140+ environment in a /path/to/chroot directory.
141+
f9d8b6a7
AM
142 UseDNS Specifies whether sshd(8) should look up the remote host name,
143 and to check that the resolved host name for the remote IP
144 address maps back to the very same IP address.
730d6499
AM
145diff -urNp -x '*.orig' openssh-8.8p1.org/sshd_config.5 openssh-8.8p1/sshd_config.5
146--- openssh-8.8p1.org/sshd_config.5 2021-09-26 16:03:19.000000000 +0200
147+++ openssh-8.8p1/sshd_config.5 2021-12-09 20:13:16.489919836 +0100
148@@ -1697,6 +1697,16 @@ Gives the facility code that is used whe
f11993b4
PG
149 The possible values are: DAEMON, USER, AUTH, LOCAL0, LOCAL1, LOCAL2,
150 LOCAL3, LOCAL4, LOCAL5, LOCAL6, LOCAL7.
151 The default is AUTH.
152+.It Cm UseChroot
153+Specifies whether to use chroot-jail environment with ssh/sftp, i.e. restrict
154+users to a particular area in the filesystem. This is done by setting user
155+home directory to, for example, /path/to/chroot/./home/username.
156+.Nm sshd
157+looks for a '.' in the users home directory, then calls
158+.Xr chroot 2
159+to whatever directory was before the . and continues with the normal ssh
160+functionality. For this to work properly you have to create special chroot-jail
161+environment in a /path/to/chroot directory.
162 .It Cm TCPKeepAlive
163 Specifies whether the system should send TCP keepalive messages to the
164 other side.
This page took 0.350483 seconds and 4 git commands to generate.