2019-03-15 03:52:50 +03:00
#!/bin/sh
if [ $# -lt 1 ] ; then
2022-02-23 14:03:50 +03:00
cat <<EOF
2019-03-15 03:52:50 +03:00
Usage: $0 PREFIX
EOF
2022-02-23 14:03:50 +03:00
exit 1
2019-03-15 03:52:50 +03:00
fi
PREFIX = " $1 "
shift 1
2022-02-23 14:03:50 +03:00
. $( dirname $0 ) /../../../testprogs/blackbox/subunit.sh
2019-03-15 03:52:50 +03:00
# selftest sets the umask to zero. Explicitly set it to 022 here,
# which should mean files should never be writable for anyone else
2022-02-23 14:03:50 +03:00
ORIG_UMASK = $( umask )
2019-03-15 03:52:50 +03:00
umask 0022
# checks that the files in the 'private' directory created are not
# world-writable
check_private_file_perms( )
{
2022-02-23 14:03:50 +03:00
target_dir = " $1 /private "
result = 0
2022-06-10 14:29:19 +03:00
for file in " ${ target_dir } " /*; do
2022-02-23 14:03:50 +03:00
# skip directories/sockets for now
2022-06-10 14:29:19 +03:00
if [ ! -f $file ] ; then
2022-02-23 14:03:50 +03:00
continue
fi
# use stat to get the file permissions, i.e. -rw-------
2022-06-10 14:29:19 +03:00
file_perm = $( stat -c "%A" $file )
2022-02-23 14:03:50 +03:00
# then use cut to drop the first 4 chars containing the file type
# and owner permissions. What's left is the group and other users
global_perm = $( echo $file_perm | cut -c4-)
# check the remainder doesn't have write permissions set
if [ -z " ${ global_perm ##*w* } " ] ; then
echo " Error: $file has $file_perm permissions "
result = 1
fi
done
return $result
2019-03-15 03:52:50 +03:00
}
TARGET_DIR = $PREFIX /basic-dc
rm -rf $TARGET_DIR
# create a dummy smb.conf - we need to use fake ACLs for the file system here
# (but passing --option args with spaces in it proved too difficult in bash)
SMB_CONF = $TARGET_DIR /tmp/smb.conf
2022-02-23 14:03:50 +03:00
mkdir -p $( dirname $SMB_CONF )
echo "vfs objects = fake_acls xattr_tdb" >$SMB_CONF
2019-03-15 03:52:50 +03:00
# provision a basic DC
testit "basic-provision" $PYTHON $BINDIR /samba-tool domain provision --server-role= "dc" --domain= FOO --realm= foo.example.com --targetdir= $TARGET_DIR --configfile= $SMB_CONF
# check the file permissions in the 'private' directory really are private
testit "provision-fileperms" check_private_file_perms $TARGET_DIR
rm -rf $TARGET_DIR
umask $ORIG_UMASK
exit $failed