5 # a function to display a failure message and then exit
11 # "get with default" function
12 # this function prompts the user with a query and default reply
13 # it returns the user reply
17 echo -en "$query [$default]" |
cat >&2
19 if [ x
$response = "x" ]; then
25 # "get yes no" function
26 # this function prompts the user with a query and will continue to do so
27 # until they reply with either "y" or "n"
30 echo -en $query |
cat >&2
32 while [ x
$response != "xy" -a x
$response != "xn" ]; do
33 echo -e "\n'y' or 'n' only please...\n" |
cat >&2
34 echo -en $query |
cat >&2
43 defaultusername
="scponly"
44 defaulthomedirprefix
="/home"
45 defaultwriteabledir
="incoming"
47 osname
=`uname -s | tr ' ' '_'`
48 # pathname to platform/OS specific setup scripts
49 prescript
="build_extras/arch/$osname.pre.sh"
50 postscript
="build_extras/arch/$osname.post.sh"
52 # the following is a list of binaries that will be staged in the target dir
53 BINARIES
=`grep '#define PROG_' config.h | cut -f2 -d\" | grep -v ^cd$`
55 # we set the install path in a variable so the presetup script can overwrite it on systems
57 INSTALL_PATHNAME
="install -c"
59 # attempt a best guess at required libs, we can append things in the presetup script if we need to
62 # default to useradd, not pw
65 if [ x
/usr
/bin
/ldd
= x
]; then
66 echo "this script requires the program ldd to determine which"
67 fail
"shared libraries to copy into your chrooted dir..."
70 if [ x
`uname -s` = "xOpenBSD" ]; then
71 for bin
in $BINARIES; do
72 GREP_LIST
="$GREP_LIST -e $bin"
74 LIB_LIST
=`ldd $BINARIES 2> /dev/null | /usr/bin/tr -s " " | cut -f5 -d" " | /usrgrep -v "^Name" | /usrgrep -v $GREP_LIST | /usr/bin/sort -u`
76 LIB_LIST
=`ldd $BINARIES 2> /dev/null | cut -f2 -d\> | cut -f1 -d\( | grep "^ " | sort -u`
80 # we also need to add some form of ld.so, here are some good guesses.
82 LDSO_LIST
="/lib/ld.so /libexec/ld-elf.so /libexec/ld-elf.so.1 /usr/libexec/ld.so /lib64/ld-linux-x86-64.so.2 /lib/ld-linux-x86-64.so.2 /lib/ld-linux.so.2 /usr/libexec/ld-elf.so.1"
83 for lib
in $LDSO_LIST; do
86 LIB_LIST
="$LIB_LIST $lib"
91 # TODO - i've since forgotten which OS this is for, it should be relocated to a presetup script
93 ls /lib
/libnss_compat
* > /dev
/null
2>&1
95 LIB_LIST
="$LIB_LIST /lib/libnss_compat*"
98 ls /lib
/libnss_files
* > /dev
/null
2>&1
100 LIB_LIST
="$LIB_LIST /lib/libnss_files*"
103 # check that the configure options are correct for chrooted operation:
105 if [ x
/usr
/sbin
/useradd
= x
]; then
107 echo "this script requires the program useradd or pw to add your"
108 fail
"chrooted scponly user."
115 if [ `id -u` != "0" ]; then
116 fail
"you must be root to run this script\n"
120 echo Next we need to
set the home directory
for this scponly user.
121 echo please note that the user
\'s home directory MUST NOT be writeable
122 echo by the scponly user. this is important so that the scponly user
123 echo cannot subvert the .
ssh configuration parameters.
125 echo for this reason
, a writeable subdirectory will be created that
126 echo the scponly user can
write into.
129 if [ "$2" != "" ] ; then
132 targetuser
=`getwd "Username to install" "$defaultusername"`
134 username_collision
=`id $targetuser > /dev/null 2> /dev/null; echo $?`
135 if [ $username_collision -eq 0 ] ; then
136 fail
"the user $targetuser already exists. please remove this user and their home directory and try again."
139 if [ "$1" != "" ] ; then
142 targetdir
=`getwd "home directory you wish to set for this user" "$defaulthomedirprefix/$targetuser"`
145 if [ "$3" != "" ] ; then
148 writeabledir
=`getwd "name of the writeable subdirectory" "$defaultwriteabledir"`
152 # if you would like to overwrite/extend any of the variables above, do so in the system specific
155 if [ -f "$prescript" ]; then
157 # this system has a pre-chroot setup script, lets run it
162 # if neither the presetup script or the best guess could find ld.so, we have to bail here
163 if [ $LDSOFOUND -eq 0 ]; then
164 fail i cant
find your equivalent of ld.so
168 # ACTUAL MODIFICATIONS BEGIN HERE
171 # this part shouldnt strictly be requried, but i'll leave it in until i'm sure of it
172 if [ ! -d $targetdir ]; then
173 $INSTALL_PATHNAME -d $targetdir
177 if [ ! -d $targetdir/etc
]; then
178 $INSTALL_PATHNAME -d $targetdir/etc
179 chown
0:0 $targetdir/etc
180 chmod 755 $targetdir/etc
183 # add all our binaries
184 for bin
in $BINARIES; do
185 $INSTALL_PATHNAME -d $targetdir/`/usr/bin/dirname $bin`
186 $INSTALL_PATHNAME $bin $targetdir$bin
189 # and the libs they require
190 if [ "x$LIB_LIST" != "x" ]; then
191 for lib
in $LIB_LIST; do
192 $INSTALL_PATHNAME -d $targetdir/`/usr/bin/dirname $lib`
193 $INSTALL_PATHNAME $lib $targetdir/$lib
197 # /dev/null is needed inside the chroot
198 mkdir
-p $targetdir/dev
199 mknod
-m 666 $targetdir/dev
/null c
1 3
201 if [ "x$USE_PW" = x0
] ; then
202 /usr
/sbin
/useradd
-d "$targetdir" -s "/usr/sbin/scponlyc" $targetuser
203 if [ $?
-ne 0 ]; then
204 fail
"if this user exists, remove it and try again"
207 useradd
-n $targetuser -s "/usr/sbin/scponlyc" -d "$targetdir"
208 if [ $?
-ne 0 ]; then
209 fail
"if this user exists, remove it and try again"
214 # we must ensure certain directories are root owned.
217 if [ -d $targetdir/.
ssh ]; then
218 chown
0:0 $targetdir/.
ssh
221 if [ ! -d $targetdir/$writeabledir ]; then
222 echo -e "\ncreating $targetdir/$writeabledir directory for uploading files"
223 $INSTALL_PATHNAME -o $targetuser -d $targetdir/$writeabledir
227 # set the perms on the writeable dir so that the new user owns it
229 newuid
=`id -u $targetuser`
230 newgid
=`id -g $targetuser`
231 chown
$newuid:$newgid $targetdir/$writeabledir
233 if [ -f "$postscript" ]; then
235 # this system has a post-chroot setup script, lets run it
240 # otherwise, revert to the old "best guess" system, which sucks
243 echo "Your platform ($osname) does not have a platform specific setup script."
244 echo "This install script will attempt a best guess."
245 echo "If you perform customizations, please consider sending me your changes."
246 echo "Look to the templates in build_extras/arch."
247 echo " - joe at sublimation dot org"
251 # ok we dont have pwd_mkdb, lets improvise:
253 grep $targetuser /etc
/passwd
> $targetdir/etc
/passwd
254 # Debian: copy /etc/group into the jail, for /usr/bin/groups to work
255 cp /etc
/group
$targetdir/etc
/group
259 # this is for systems which do have pwd_mkdb
261 grep $targetuser /etc
/master.passwd
> $targetdir/etc
/master.passwd
262 -d "$targetdir/etc" $targetdir/etc
/master.passwd
263 rm -rf $targetdir/etc
/master.passwd
$targetdir/etc
/spwd.db
268 # the final step is setting the password
270 echo "please set the password for $targetuser:"
273 echo "if you experience a warning with winscp regarding groups, please install"
274 echo "the provided hacked out fake groups program into your chroot, like so:"
275 echo "cp groups $targetdir/bin/groups"