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