2019-05-16 13:47:34 +03:00
#!/bin/sh
#
# Test guest authentication
#
# Copyright (C) 2019 Ralph Boehme
#
if [ $# -lt 5 ] ; then
2022-04-22 16:34:09 +03:00
cat <<EOF
2019-05-16 13:47:34 +03:00
Usage: $0 SERVER SMBCLIENT SMBCONTROL NET CONFIGURATION
EOF
2022-04-22 16:34:09 +03:00
exit 1
2019-05-16 13:47:34 +03:00
fi
SERVER = $1
SMBCLIENT = $2
SMBCONTROL = $3
NET = $4
CONFIGURATION = $5
2022-04-22 16:34:09 +03:00
incdir = $( dirname $0 ) /../../../testprogs/blackbox
2019-05-16 13:47:34 +03:00
. $incdir /subunit.sh
failed = 0
SIDS = ""
2022-04-22 16:34:09 +03:00
prepare_empty_builtin_guests( )
{
TMP = $( $NET $CONFIGURATION groupmap listmem S-1-5-32-546 2>& 1)
bg_exists = $?
if [ $bg_exists != 0 ] ; then
printf "Group map for BUILTIN\\Guests must exist for test\n"
return 1
fi
SIDS = $( $NET $CONFIGURATION groupmap listmem S-1-5-32-546)
if [ $? != 0 ] ; then
printf " $NET $CONFIGURATION groupmap listmem S-1-5-32-546 failed. Returned:\n "
printf " $SIDS \n "
return 1
fi
printf " Got S-1-5-32-546 members:\n $SIDS \n "
if [ " $SIDS " != "" ] ; then
for SID in $SIDS ; do
printf " Deleting member $SID from S-1-5-32-546\n "
$NET $CONFIGURATION groupmap delmem S-1-5-32-546 $SID || return 1
done
fi
return 0
2019-05-16 13:47:34 +03:00
}
2022-04-22 16:34:09 +03:00
add_local_guest_to_builtin_guests( )
{
if [ " $SIDS " != "" ] ; then
for SID in $SIDS ; do
printf " Adding $SID as member to S-1-5-32-546\n "
$NET $CONFIGURATION groupmap addmem S-1-5-32-546 $SID || return 1
done
fi
2019-05-16 13:47:34 +03:00
}
2022-04-22 16:34:09 +03:00
test_smbclient( )
{
$SMBCLIENT -U foo%bar //$SERVER /tmpguest -c exit
if [ $? != 0 ] ; then
printf "smbclient failed\n"
return 1
fi
return 0
2019-05-16 13:47:34 +03:00
}
testit "smbclient_guest_at_startup" \
2022-04-22 16:34:09 +03:00
test_smbclient ||
failed = $( expr $failed + 1)
2019-05-16 13:47:34 +03:00
printf "Prepare BUILTIN\\Guests group mapping without members\n"
prepare_empty_builtin_guests || {
2022-04-22 16:34:09 +03:00
printf "Setting up BUILTIN\\Guests without members failed\n"
exit 1
2019-05-16 13:47:34 +03:00
}
$SMBCONTROL $CONFIGURATION smbd reload-config || {
2022-04-22 16:34:09 +03:00
printf "Reloading parent smbd guest info failed\n"
exit 1
2019-05-16 13:47:34 +03:00
}
testit "smbclient_guest_auth_without_members" \
2022-04-22 16:34:09 +03:00
test_smbclient &&
failed = $( expr $failed + 1)
2019-05-16 13:47:34 +03:00
# restore config
add_local_guest_to_builtin_guests
$SMBCONTROL $CONFIGURATION smbd reload-config || {
2022-04-22 16:34:09 +03:00
printf "Reloading parent smbd guest info failed\n"
exit 1
2019-05-16 13:47:34 +03:00
}
testit "smbclient_works_after_restored_setup" \
2022-04-22 16:34:09 +03:00
test_smbclient ||
failed = $( expr $failed + 1)
2019-05-16 13:47:34 +03:00
testok $0 $failed