xref: /netbsd-src/external/ibm-public/postfix/dist/examples/chroot-setup/LINUX2 (revision 41fbaed053f8fbfdf9d2a4ee0a7386a3c83f8505)
1*41fbaed0Stron#! /bin/sh
2*41fbaed0Stron
3*41fbaed0Stron# LINUX2 - shell script to set up a Postfix chroot jail for Linux
4*41fbaed0Stron# Tested on SuSE Linux 5.3 (libc5) and 7.0 (glibc2.1)
5*41fbaed0Stron
6*41fbaed0Stron# Other testers reported as working:
7*41fbaed0Stron#
8*41fbaed0Stron# 2001-01-15 Debian sid (unstable)
9*41fbaed0Stron#            Christian Kurz <shorty@getuid.de>
10*41fbaed0Stron
11*41fbaed0Stron# Copyright (c) 2000 - 2001 by Matthias Andree
12*41fbaed0Stron# Redistributable unter the MIT-style license that follows:
13*41fbaed0Stron# Abstract: "do whatever you want except hold somebody liable or change
14*41fbaed0Stron# the copyright information".
15*41fbaed0Stron
16*41fbaed0Stron# Permission is hereby granted, free of charge, to any person obtaining a copy
17*41fbaed0Stron# of this software and associated documentation files (the "Software"), to
18*41fbaed0Stron# deal in the Software without restriction, including without limitation the
19*41fbaed0Stron# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
20*41fbaed0Stron# sell copies of the Software, and to permit persons to whom the Software is
21*41fbaed0Stron# furnished to do so, subject to the following conditions:
22*41fbaed0Stron#
23*41fbaed0Stron# The above copyright notice and this permission notice shall be included in
24*41fbaed0Stron# all copies or substantial portions of the Software.
25*41fbaed0Stron#
26*41fbaed0Stron# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27*41fbaed0Stron# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28*41fbaed0Stron# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
29*41fbaed0Stron# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
30*41fbaed0Stron# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
31*41fbaed0Stron# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
32*41fbaed0Stron# IN THE SOFTWARE.
33*41fbaed0Stron
34*41fbaed0Stron# 2000-09-29
35*41fbaed0Stron# v0.1: initial release
36*41fbaed0Stron
37*41fbaed0Stron# 2000-12-05
38*41fbaed0Stron# v0.2: copy libdb.* for libnss_db.so
39*41fbaed0Stron#       remove /etc/localtime in case it's a broken symlink
40*41fbaed0Stron#       restrict find to maxdepth 1 (faster)
41*41fbaed0Stron
42*41fbaed0Stron# Revision 1.4  2001/01/15 09:36:35  emma
43*41fbaed0Stron# add note it was successfully tested on Debian sid
44*41fbaed0Stron#
45*41fbaed0Stron# 20060101 /lib64 support by Keith Owens.
46*41fbaed0Stron#
47*41fbaed0Stron
48*41fbaed0StronCP="cp -p"
49*41fbaed0Stron
50*41fbaed0Stroncond_copy() {
51*41fbaed0Stron  # find files as per pattern in $1
52*41fbaed0Stron  # if any, copy to directory $2
53*41fbaed0Stron  dir=`dirname "$1"`
54*41fbaed0Stron  pat=`basename "$1"`
55*41fbaed0Stron  lr=`find "$dir" -maxdepth 1 -name "$pat"`
56*41fbaed0Stron  if test ! -d "$2" ; then exit 1 ; fi
57*41fbaed0Stron  if test "x$lr" != "x" ; then $CP $1 "$2" ; fi
58*41fbaed0Stron}
59*41fbaed0Stron
60*41fbaed0Stronset -e
61*41fbaed0Stronumask 022
62*41fbaed0Stron
63*41fbaed0StronPOSTFIX_DIR=${POSTFIX_DIR-/var/spool/postfix}
64*41fbaed0Stroncd ${POSTFIX_DIR}
65*41fbaed0Stron
66*41fbaed0Stronmkdir -p etc lib usr/lib/zoneinfo
67*41fbaed0Strontest -d /lib64 && mkdir -p lib64
68*41fbaed0Stron
69*41fbaed0Stron# find localtime (SuSE 5.3 does not have /etc/localtime)
70*41fbaed0Stronlt=/etc/localtime
71*41fbaed0Stronif test ! -f $lt ; then lt=/usr/lib/zoneinfo/localtime ; fi
72*41fbaed0Stronif test ! -f $lt ; then lt=/usr/share/zoneinfo/localtime ; fi
73*41fbaed0Stronif test ! -f $lt ; then echo "cannot find localtime" ; exit 1 ; fi
74*41fbaed0Stronrm -f etc/localtime
75*41fbaed0Stron
76*41fbaed0Stron# copy localtime and some other system files into the chroot's etc
77*41fbaed0Stron$CP -f $lt /etc/services /etc/resolv.conf /etc/nsswitch.conf etc
78*41fbaed0Stron$CP -f /etc/host.conf /etc/hosts /etc/passwd etc
79*41fbaed0Stronln -s -f /etc/localtime usr/lib/zoneinfo
80*41fbaed0Stron
81*41fbaed0Stron# copy required libraries into the chroot
82*41fbaed0Stroncond_copy '/lib/libnss_*.so*' lib
83*41fbaed0Stroncond_copy '/lib/libresolv.so*' lib
84*41fbaed0Stroncond_copy '/lib/libdb.so*' lib
85*41fbaed0Stronif test -d /lib64; then
86*41fbaed0Stron  cond_copy '/lib64/libnss_*.so*' lib64
87*41fbaed0Stron  cond_copy '/lib64/libresolv.so*' lib64
88*41fbaed0Stron  cond_copy '/lib64/libdb.so*' lib64
89*41fbaed0Stronfi
90*41fbaed0Stron
91*41fbaed0Stronpostfix reload
92