File: chroot

package info (click to toggle)
apache2 2.4.62-1~deb11u1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 59,516 kB
  • sloc: ansic: 216,122; python: 15,147; perl: 11,308; sh: 6,449; php: 1,315; javascript: 1,314; awk: 749; makefile: 714; lex: 374; yacc: 161; xml: 2
file content (39 lines) | stat: -rw-r--r-- 1,024 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/sh
set -ex

# Check that ChrootDir works correctly. Written in response to LP: #1251939.
#
# Author: Robie Basak <robie.basak@ubuntu.com>
#
# This test requires:
#  * wget
#  * The dpkg-dev package for the dpkg-architecture command
#
# This is a "breaks-testbed" dep8 test.
#
# This test sets up a minimal environment to exercise ChrootDir. Do not use
# it as an example of how to set up Apache in a secure chroot environment.

sed -i 's_DocumentRoot.*$_DocumentRoot /_' /etc/apache2/sites-available/000-default.conf

LIBGCC_S_PATH=`gcc --print-file-name=libgcc_s.so.1`
cat > /etc/apache2/conf-available/chroot.conf <<EOT
LoadFile $LIBGCC_S_PATH
ChrootDir /var/www
<Directory />
       Options Indexes FollowSymLinks
       AllowOverride None
       Require all granted
</Directory>
EOT
a2enconf chroot

echo "Hello, world!" > /var/www/hello.txt

service apache2 restart

result=`wget -qO- http://localhost/hello.txt`
if [ "$result" != "Hello, world!" ]; then
    echo "Unexpected result from wget" >&2
    exit 1
fi