2012-12-28 05:36:06 +04:00
#!/bin/sh
# Blackbox test for wbinfo and rfc2307 mappings
if [ $# -lt 4 ] ; then
2022-02-21 13:20:53 +03:00
cat <<EOF
2012-12-28 05:36:06 +04:00
Usage: test_rfc2307_mapping.sh DOMAIN USERNAME PASSWORD SERVER UID_RFC2307TEST GID_RFC2307TEST
EOF
2022-02-21 13:20:53 +03:00
exit 1
2012-12-28 05:36:06 +04:00
fi
DOMAIN = $1
USERNAME = $2
PASSWORD = $3
SERVER = $4
UID_RFC2307TEST = $5
GID_RFC2307TEST = $6
shift 6
failed = 0
samba4bindir = " $BINDIR "
wbinfo = " $VALGRIND $samba4bindir /wbinfo "
samba_tool = " $VALGRIND $samba4bindir /samba-tool "
2022-02-21 13:20:53 +03:00
. $( dirname $0 ) /../../testprogs/blackbox/subunit.sh
2022-12-22 18:54:30 +03:00
. " $( dirname " ${ 0 } " ) /../../testprogs/blackbox/common_test_fns.inc "
ldbmodify = $( system_or_builddir_binary ldbmodify " ${ BINDIR } " )
2012-12-28 05:36:06 +04:00
2022-02-21 13:20:53 +03:00
testfail( )
{
2012-12-28 05:36:06 +04:00
name = " $1 "
shift
cmdline = " $* "
echo " test: $name "
$cmdline
status = $?
2022-02-21 13:20:53 +03:00
if [ x$status = x0 ] ; then
echo " failure: $name "
else
echo " success: $name "
fi
return $status
2012-12-28 05:36:06 +04:00
}
2022-02-21 13:20:53 +03:00
knownfail( )
{
name = " $1 "
shift
cmdline = " $* "
echo " test: $name "
$cmdline
status = $?
if [ x$status = x0 ] ; then
echo " failure: $name [unexpected success] "
status = 1
else
echo " knownfail: $name "
status = 0
fi
return $status
2012-12-28 05:36:06 +04:00
}
# Create new testing account
2022-02-22 19:58:47 +03:00
testit "user add" $PYTHON $samba_tool user create --given-name= "rfc2307" \
--surname= "Tester" --initial= "UT" rfc2307_test_user testp@ssw0Rd " $@ "
2012-12-28 05:36:06 +04:00
#test creation of six different groups
2022-02-22 19:58:47 +03:00
testit "group add" $PYTHON $samba_tool group add $CONFIG \
--group-scope= 'Domain' --group-type= 'Security' rfc2307_test_group " $@ "
2012-12-28 05:36:06 +04:00
# Create new testing group
# Convert name to SID
2022-02-21 13:20:53 +03:00
testit " wbinfo -n against $TARGET " $wbinfo -n " $DOMAIN /rfc2307_test_user " || failed = $( expr $failed + 1)
user_sid = $( $wbinfo -n " $DOMAIN /rfc2307_test_user " | cut -d " " -f1)
2012-12-28 05:36:06 +04:00
echo " $DOMAIN /rfc2307_test_user resolved to $user_sid "
2022-02-21 13:20:53 +03:00
testit " wbinfo -s $user_sid against $TARGET " $wbinfo -s $user_sid || failed = $( expr $failed + 1)
user_name = $( $wbinfo -s $user_sid | cut -d " " -f1 | tr a-z A-Z)
2012-12-28 05:36:06 +04:00
echo " $user_sid resolved to $user_name "
2022-02-21 13:20:53 +03:00
tested_name = $( echo $DOMAIN /rfc2307_test_user | tr a-z A-Z)
2012-12-28 05:36:06 +04:00
# Now check that wbinfo works correctly (sid <=> name)
echo "test: wbinfo -s check for sane mapping"
if test x$user_name != x$tested_name ; then
echo " $user_name does not match $tested_name "
echo "failure: wbinfo -s check for sane mapping"
2022-02-21 13:20:53 +03:00
failed = $( expr $failed + 1)
2012-12-28 05:36:06 +04:00
else
echo "success: wbinfo -s check for sane mapping"
fi
2022-02-21 13:20:53 +03:00
testit " wbinfo -n on the returned name against $TARGET " $wbinfo -n $user_name || failed = $( expr $failed + 1)
test_sid = $( $wbinfo -n $tested_name | cut -d " " -f1)
2012-12-28 05:36:06 +04:00
echo "test: wbinfo -n check for sane mapping"
if test x$user_sid != x$test_sid ; then
echo " $user_sid does not match $test_sid "
echo "failure: wbinfo -n check for sane mapping"
2022-02-21 13:20:53 +03:00
failed = $( expr $failed + 1)
2012-12-28 05:36:06 +04:00
else
echo "success: wbinfo -n check for sane mapping"
fi
2022-02-21 13:20:53 +03:00
testit " wbinfo -n against $TARGET " $wbinfo -n " $DOMAIN /rfc2307_test_group " || failed = $( expr $failed + 1)
group_sid = $( $wbinfo -n " $DOMAIN /rfc2307_test_group " | cut -d " " -f1)
2012-12-28 05:36:06 +04:00
echo " $DOMAIN /rfc2307_test_group resolved to $group_sid "
# Then add a uidNumber to the group record using ldbmodify
2022-02-21 13:20:53 +03:00
cat >$PREFIX /tmpldbmodify <<EOF
2012-12-28 05:36:06 +04:00
dn: <SID = $user_sid >
changetype: modify
add: uidNumber
uidNumber: $UID_RFC2307TEST
EOF
2022-02-22 19:58:47 +03:00
testit "modify gidNumber on group" $VALGRIND $ldbmodify -H ldap://$SERVER \
$PREFIX /tmpldbmodify -U$DOMAIN /$USERNAME %$PASSWORD " $@ " ||
failed = $( expr $failed + 1)
2012-12-28 05:36:06 +04:00
# Then add a gidNumber to the group record using ldbmodify
2022-02-21 13:20:53 +03:00
cat >$PREFIX /tmpldbmodify <<EOF
2012-12-28 05:36:06 +04:00
dn: <SID = $group_sid >
changetype: modify
add: gidNumber
gidNumber: $GID_RFC2307TEST
EOF
2022-02-22 19:58:47 +03:00
testit "modify gidNumber on group" $VALGRIND $ldbmodify -H ldap://$SERVER \
$PREFIX /tmpldbmodify -U$DOMAIN /$USERNAME %$PASSWORD " $@ " ||
failed = $( expr $failed + 1)
2012-12-28 05:36:06 +04:00
rm -f $PREFIX /tmpldbmodify
# Now check we get a correct SID for the UID
2022-02-21 13:20:53 +03:00
testit " wbinfo -U against $TARGET " $wbinfo -U $UID_RFC2307TEST || failed = $( expr $failed + 1)
2012-12-28 05:36:06 +04:00
echo "test: wbinfo -U check for sane mapping"
2022-02-21 13:20:53 +03:00
sid_for_user = $( $wbinfo -U $UID_RFC2307TEST )
2012-12-28 05:36:06 +04:00
if test x" $sid_for_user " != x" $user_sid " ; then
echo " uid $UID_RFC2307TEST mapped to $sid_for_user , not $user_sid "
echo "failure: wbinfo -U check for sane mapping"
2022-02-21 13:20:53 +03:00
failed = $( expr $failed + 1)
2012-12-28 05:36:06 +04:00
else
echo "success: wbinfo -U check for sane mapping"
fi
2022-02-21 13:20:53 +03:00
testit " wbinfo -G against $TARGET " $wbinfo -G $GID_RFC2307TEST || failed = $( expr $failed + 1)
2012-12-28 05:36:06 +04:00
echo "test: wbinfo -G check for sane mapping"
2022-02-21 13:20:53 +03:00
sid_for_group = $( $wbinfo -G $GID_RFC2307TEST )
2012-12-28 05:36:06 +04:00
if test x$sid_for_group != " x $group_sid " ; then
2022-02-21 13:20:53 +03:00
echo " gid $GID_RFC2307TEST mapped to $sid_for_group , not $group_sid "
2012-12-28 05:36:06 +04:00
echo "failure: wbinfo -G check for sane mapping"
2022-02-21 13:20:53 +03:00
failed = $( expr $failed + 1)
2012-12-28 05:36:06 +04:00
else
echo "success: wbinfo -G check for sane mapping"
fi
# Now check we get the right UID from the SID
2022-02-21 13:20:53 +03:00
testit " wbinfo -S against $TARGET " $wbinfo -S " $user_sid " || failed = $( expr $failed + 1)
2012-12-28 05:36:06 +04:00
echo "test: wbinfo -S check for sane mapping"
2022-02-21 13:20:53 +03:00
uid_for_user_sid = $( $wbinfo -S $user_sid )
2012-12-28 05:36:06 +04:00
if test 0$uid_for_user_sid -ne $UID_RFC2307TEST ; then
echo " $user_sid mapped to $uid_for_sid , not $UID_RFC2307TEST "
echo "failure: wbinfo -S check for sane mapping"
2022-02-21 13:20:53 +03:00
failed = $( expr $failed + 1)
2012-12-28 05:36:06 +04:00
else
echo "success: wbinfo -S check for sane mapping"
fi
# Now check we get the right GID from the SID
2022-02-21 13:20:53 +03:00
testit "wbinfo -Y" $wbinfo -Y " $group_sid " || failed = $( expr $failed + 1)
2012-12-28 05:36:06 +04:00
echo "test: wbinfo -Y check for sane mapping"
2022-02-21 13:20:53 +03:00
gid_for_user_sid = $( $wbinfo -Y $group_sid )
2012-12-28 05:36:06 +04:00
if test 0$gid_for_user_sid -ne $GID_RFC2307TEST ; then
echo " $group_sid mapped to $gid_for_sid , not $GID_RFC2307TEST "
echo "failure: wbinfo -Y check for sane mapping"
2022-02-21 13:20:53 +03:00
failed = $( expr $failed + 1)
2012-12-28 05:36:06 +04:00
else
echo "success: wbinfo -Y check for sane mapping"
fi
2022-02-22 19:58:47 +03:00
testit "group delete" $PYTHON $samba_tool group delete rfc2307_test_group " $@ "
testit "user delete" $PYTHON $samba_tool user delete rfc2307_test_user " $@ "
2012-12-28 05:36:06 +04:00
exit $failed