2008-04-15 19:04:36 +04:00
#!/bin/sh
# Blackbox test for wbinfo
if [ $# -lt 4 ] ; then
2022-02-21 13:20:53 +03:00
cat <<EOF
2008-04-15 19:04:36 +04:00
Usage: test_wbinfo.sh DOMAIN USERNAME PASSWORD TARGET
EOF
2022-02-21 13:20:53 +03:00
exit 1
2008-04-15 19:04:36 +04:00
fi
DOMAIN = $1
USERNAME = $2
PASSWORD = $3
TARGET = $4
shift 4
failed = 0
2011-04-15 06:41:22 +04:00
samba4bindir = " $BINDIR "
2012-01-26 02:42:27 +04:00
wbinfo = " $VALGRIND $samba4bindir /wbinfo "
2008-04-15 19:04:36 +04:00
2022-02-21 13:20:53 +03:00
. $( dirname $0 ) /../../testprogs/blackbox/subunit.sh
2008-04-15 19:04:36 +04:00
2022-02-21 13:20:53 +03:00
testfail( )
{
2008-04-15 19:04:36 +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
2008-04-15 19:04:36 +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
2008-04-15 19:04:36 +04:00
}
2016-09-19 14:27:30 +03:00
KRB5CCNAME_PATH = " $PREFIX /test_wbinfo_krb5ccache "
rm -f $KRB5CCNAME_PATH
KRB5CCNAME = " FILE: $KRB5CCNAME_PATH "
export KRB5CCNAME
2009-01-14 10:25:52 +03:00
# List users
2022-02-21 13:20:53 +03:00
testit " wbinfo -u against $TARGET " $wbinfo -u || failed = $( expr $failed + 1)
2009-01-14 10:25:52 +03:00
# List groups
2022-02-21 13:20:53 +03:00
testit " wbinfo -g against $TARGET " $wbinfo -g || failed = $( expr $failed + 1)
2009-01-14 10:25:52 +03:00
# Convert netbios name to IP
# Does not work yet
2022-02-21 13:20:53 +03:00
testit " wbinfo -N against $TARGET " $wbinfo -N $NETBIOSNAME || failed = $( expr $failed + 1)
2009-01-14 10:25:52 +03:00
# Convert IP to netbios name
# Does not work yet
2022-02-21 13:20:53 +03:00
testit " wbinfo -I against $TARGET " $wbinfo -I $SERVER_IP || failed = $( expr $failed + 1)
2009-01-14 10:25:52 +03:00
# Convert name to SID
2022-02-21 13:20:53 +03:00
testit " wbinfo -n against $TARGET " $wbinfo -n " $DOMAIN / $USERNAME " || failed = $( expr $failed + 1)
admin_sid = $( $wbinfo -n " $DOMAIN / $USERNAME " | cut -d " " -f1)
2008-04-15 19:04:36 +04:00
echo " $DOMAIN / $USERNAME resolved to $admin_sid "
2022-02-21 13:20:53 +03:00
testit " wbinfo -s $admin_sid against $TARGET " $wbinfo -s $admin_sid || failed = $( expr $failed + 1)
admin_name = $( $wbinfo -s $admin_sid | cut -d " " -f1 | tr a-z A-Z)
2008-04-15 19:04:36 +04:00
echo " $admin_sid resolved to $admin_name "
2022-02-21 13:20:53 +03:00
tested_name = $( echo $DOMAIN /$USERNAME | tr a-z A-Z)
2008-04-15 19:04:36 +04:00
echo "test: wbinfo -s check for sane mapping"
if test x$admin_name != x$tested_name ; then
echo " $admin_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)
2008-04-15 19:04:36 +04:00
else
echo "success: wbinfo -s check for sane mapping"
fi
2022-02-21 13:20:53 +03:00
while read SID; do
read NAME
2017-03-31 17:06:18 +03:00
2022-02-21 13:20:53 +03:00
testit " wbinfo -s $SID against $TARGET " $wbinfo -s $SID || failed = $( expr $failed + 1)
2017-03-31 17:06:18 +03:00
2022-02-21 13:20:53 +03:00
RESOLVED_NAME = $( $wbinfo -s $SID | tr a-z A-Z)
echo " $SID resolved to $RESOLVED_NAME "
2017-03-31 17:06:18 +03:00
2022-02-21 13:20:53 +03:00
echo " test: wbinfo -s $SID against $TARGET "
if test x" $RESOLVED_NAME " != x" $NAME " ; then
echo " $RESOLVED_NAME does not match $NAME "
echo " failure: wbinfo -s $SID against $TARGET "
failed = $( expr $failed + 1)
else
echo " success: wbinfo -s $SID against $TARGET "
fi
2017-03-31 17:06:18 +03:00
done <<EOF
S-1-1-0
/EVERYONE 5
S-1-3-1
/CREATOR GROUP 5
S-1-5-1
NT AUTHORITY/DIALUP 5
EOF
2017-03-31 17:06:18 +03:00
2022-02-21 13:20:53 +03:00
testit " wbinfo -n on the returned name against $TARGET " $wbinfo -n $admin_name || failed = $( expr $failed + 1)
test_sid = $( $wbinfo -n $tested_name | cut -d " " -f1)
2008-04-15 19:04:36 +04:00
echo "test: wbinfo -n check for sane mapping"
if test x$admin_sid != x$test_sid ; then
echo " $admin_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)
2008-04-15 19:04:36 +04:00
else
echo "success: wbinfo -n check for sane mapping"
fi
2018-11-27 22:32:09 +03:00
echo "test: wbinfo -n NT Authority/Authenticated Users"
$wbinfo -n "NT Authority/Authenticated Users"
2022-02-21 13:20:53 +03:00
if [ $? -ne 0 ] ; then
echo "failure: wbinfo -n NT Authority/Authenticated Users"
failed = $( expr $failed + 1)
2018-11-27 22:32:09 +03:00
else
2022-02-21 13:20:53 +03:00
echo "success: wbinfo -n NT Authority/Authenticated Users"
2018-11-27 22:32:09 +03:00
fi
echo "test: wbinfo --group-info NT Authority/Authenticated Users"
$wbinfo --group-info "NT Authority/Authenticated Users"
2022-02-21 13:20:53 +03:00
if [ $? -ne 0 ] ; then
echo "failure: wbinfo --group-info NT Authority/Authenticated Users"
failed = $( expr $failed + 1)
2018-11-27 22:32:09 +03:00
else
2022-02-21 13:20:53 +03:00
echo "success: wbinfo --group-info NT Authority/Authenticated Users"
2018-11-27 22:32:09 +03:00
fi
2022-02-21 13:20:53 +03:00
testit " wbinfo -U against $TARGET " $wbinfo -U 30000 || failed = $( expr $failed + 1)
2008-04-15 19:04:36 +04:00
echo "test: wbinfo -U check for sane mapping"
2022-02-21 13:20:53 +03:00
sid_for_30000 = $( $wbinfo -U 30000)
2008-04-15 19:04:36 +04:00
if test x$sid_for_30000 != "xS-1-22-1-30000" ; then
echo " uid 30000 mapped to $sid_for_30000 , not S-1-22-1-30000 "
echo "failure: wbinfo -U check for sane mapping"
2022-02-21 13:20:53 +03:00
failed = $( expr $failed + 1)
2008-04-15 19:04:36 +04:00
else
echo "success: wbinfo -U check for sane mapping"
fi
2022-02-21 13:20:53 +03:00
admin_uid = $( $wbinfo -S $admin_sid )
2008-04-15 19:04:36 +04:00
2022-02-21 13:20:53 +03:00
testit " wbinfo -G against $TARGET " $wbinfo -G 30000 || failed = $( expr $failed + 1)
2008-04-15 19:04:36 +04:00
echo "test: wbinfo -G check for sane mapping"
2022-02-21 13:20:53 +03:00
sid_for_30000 = $( $wbinfo -G 30000)
2008-04-15 19:04:36 +04:00
if test x$sid_for_30000 != "xS-1-22-2-30000" ; then
2022-02-21 13:20:53 +03:00
echo " gid 30000 mapped to $sid_for_30000 , not S-1-22-2-30000 "
2008-04-15 19:04:36 +04:00
echo "failure: wbinfo -G check for sane mapping"
2022-02-21 13:20:53 +03:00
failed = $( expr $failed + 1)
2008-04-15 19:04:36 +04:00
else
echo "success: wbinfo -G check for sane mapping"
fi
2022-02-21 13:20:53 +03:00
testit " wbinfo -S against $TARGET " $wbinfo -S "S-1-22-1-30000" || failed = $( expr $failed + 1)
2008-04-15 19:04:36 +04:00
echo "test: wbinfo -S check for sane mapping"
2022-02-21 13:20:53 +03:00
uid_for_sid = $( $wbinfo -S S-1-22-1-30000)
2008-04-15 19:04:36 +04:00
if test 0$uid_for_sid -ne 30000; then
echo " S-1-22-1-30000 mapped to $uid_for_sid , not 30000 "
echo "failure: wbinfo -S check for sane mapping"
2022-02-21 13:20:53 +03:00
failed = $( expr $failed + 1)
2008-04-15 19:04:36 +04:00
else
echo "success: wbinfo -S check for sane mapping"
fi
2022-02-21 13:20:53 +03:00
testfail " wbinfo -S against $TARGET using invalid SID " $wbinfo -S "S-1-22-2-30000" && failed = $( expr $failed + 1)
2008-04-15 19:04:36 +04:00
2022-02-21 13:20:53 +03:00
testit " wbinfo -Y against $TARGET " $wbinfo -Y "S-1-22-2-30000" || failed = $( expr $failed + 1)
2008-04-15 19:04:36 +04:00
echo "test: wbinfo -Y check for sane mapping"
2022-02-21 13:20:53 +03:00
gid_for_sid = $( $wbinfo -Y S-1-22-2-30000)
2008-04-15 19:04:36 +04:00
if test 0$gid_for_sid -ne 30000; then
echo " S-1-22-2-30000 mapped to $gid_for_sid , not 30000 "
echo "failure: wbinfo -Y check for sane mapping"
2022-02-21 13:20:53 +03:00
failed = $( expr $failed + 1)
2008-04-15 19:04:36 +04:00
else
echo "success: wbinfo -Y check for sane mapping"
fi
2022-02-21 13:20:53 +03:00
testfail " wbinfo -Y against $TARGET using invalid SID " $wbinfo -Y "S-1-22-1-30000" && failed = $( expr $failed + 1)
2008-04-15 19:04:36 +04:00
2022-02-21 13:20:53 +03:00
testit " wbinfo -t against $TARGET " $wbinfo -t || failed = $( expr $failed + 1)
2008-04-15 19:04:36 +04:00
2009-08-18 23:42:37 +04:00
#didn't really work anyway
2022-02-21 13:20:53 +03:00
testit " wbinfo --trusted-domains against $TARGET " $wbinfo --trusted-domains || failed = $( expr $failed + 1)
testit " wbinfo --all-domains against $TARGET " $wbinfo --all-domains || failed = $( expr $failed + 1)
2009-08-18 23:42:37 +04:00
2022-02-21 13:20:53 +03:00
testit " wbinfo --own-domain against $TARGET " $wbinfo --own-domain || failed = $( expr $failed + 1)
2008-04-15 19:04:36 +04:00
echo " test: wbinfo --own-domain against $TARGET check output "
2022-02-21 13:20:53 +03:00
own_domain = $( $wbinfo --own-domain)
2008-04-15 19:04:36 +04:00
if test x$own_domain = x$DOMAIN ; then
echo " success: wbinfo --own-domain against $TARGET check output "
else
echo " Own domain reported as $own_domain instead of $DOMAIN "
echo " failure: wbinfo --own-domain against $TARGET check output "
2022-02-21 13:20:53 +03:00
failed = $( expr $failed + 1)
2008-04-15 19:04:36 +04:00
fi
# this does not work
knownfail " wbinfo --sequence against $TARGET " $wbinfo --sequence
2009-08-18 23:42:37 +04:00
# this is stubbed out now
2022-02-21 13:20:53 +03:00
testit " wbinfo -D against $TARGET " $wbinfo -D $DOMAIN || failed = $( expr $failed + 1)
2008-04-15 19:04:36 +04:00
2022-02-21 13:20:53 +03:00
testit " wbinfo -i against $TARGET " $wbinfo -i " $DOMAIN / $USERNAME " || failed = $( expr $failed + 1)
2008-04-15 19:04:36 +04:00
2010-03-09 15:39:56 +03:00
echo " test: wbinfo --group-info against $TARGET "
2022-02-21 13:20:53 +03:00
gid = $( $wbinfo --group-info " $DOMAIN /Domain users " | cut -d: -f3)
2010-03-09 15:39:56 +03:00
if test x$? = x0; then
echo " success: wbinfo --group-info against $TARGET "
else
echo " failure: wbinfo --group-info against $TARGET "
2022-02-21 13:20:53 +03:00
failed = $( expr $failed + 1)
2010-03-09 15:39:56 +03:00
fi
2014-10-23 07:27:22 +04:00
test_name = " wbinfo -i against $TARGET "
subunit_start_test " $test_name "
2022-02-21 13:20:53 +03:00
passwd_line = $( $wbinfo -i " $DOMAIN / $USERNAME " )
2014-10-23 07:27:22 +04:00
if test x$? = x0; then
subunit_pass_test " $test_name "
else
subunit_fail_test " $test_name "
2022-02-21 13:20:53 +03:00
failed = $( expr $failed + 1)
2014-10-23 07:27:22 +04:00
fi
test_name = " confirm output of wbinfo -i against $TARGET "
subunit_start_test " $test_name "
# The full name (GECOS) is based on name (the RDN, in this case CN)
# and displayName in winbindd_ads, and is based only on displayName in
# winbindd_msrpc and winbindd_rpc. Allow both versions.
2017-03-17 12:04:19 +03:00
if test " $TARGET " = "ad_member" ; then
expected1_line = " $DOMAIN /administrator:*: $admin_uid : $gid :Administrator:/home/ $DOMAIN /Domain Users/administrator:/bin/false "
expected2_line = " $DOMAIN /administrator:*: $admin_uid : $gid ::/home/ $DOMAIN /Domain Users/administrator:/bin/false "
else
expected1_line = " $DOMAIN /administrator:*: $admin_uid : $gid :Administrator:/home/ $DOMAIN /administrator:/bin/false "
expected2_line = " $DOMAIN /administrator:*: $admin_uid : $gid ::/home/ $DOMAIN /administrator:/bin/false "
fi
2014-10-23 07:27:22 +04:00
2017-03-17 12:04:19 +03:00
if test " x $passwd_line " = " x $expected1_line " -o " x $passwd_line " = " x $expected2_line " ; then
2014-10-23 07:27:22 +04:00
subunit_pass_test " $test_name "
else
2017-03-17 12:04:19 +03:00
echo " expected ' $expected1_line ' or ' $expected2_line ' got ' $passwd_line ' " | subunit_fail_test " $test_name "
2022-02-21 13:20:53 +03:00
failed = $( expr $failed + 1)
2014-10-23 07:27:22 +04:00
fi
test_name = " wbinfo --uid-info against $TARGET "
subunit_start_test " $test_name "
2022-02-21 13:20:53 +03:00
passwd_line = $( $wbinfo --uid-info= $admin_uid )
2014-10-23 07:27:22 +04:00
if test x$? = x0; then
subunit_pass_test " $test_name "
else
subunit_fail_test " $test_name "
2022-02-21 13:20:53 +03:00
failed = $( expr $failed + 1)
2014-10-23 07:27:22 +04:00
fi
test_name = " confirm output of wbinfo --uid-info against $TARGET "
subunit_start_test " $test_name "
2017-03-17 12:04:19 +03:00
if test " x $passwd_line " = " x $expected1_line " -o " x $passwd_line " = " x $expected2_line " ; then
2014-10-23 07:27:22 +04:00
subunit_pass_test " $test_name "
else
2017-03-17 12:04:19 +03:00
echo " expected ' $expected1_line ' or ' $expected2_line ' got ' $passwd_line ' " | subunit_fail_test " $test_name "
2022-02-21 13:20:53 +03:00
failed = $( expr $failed + 1)
2014-10-23 07:27:22 +04:00
fi
2022-02-21 13:20:53 +03:00
testfail " wbinfo --group-info against $TARGET with $USERNAME " $wbinfo --group-info $USERNAME && failed = $( expr $failed + 1)
2012-04-23 07:52:17 +04:00
2022-02-21 13:20:53 +03:00
testit " wbinfo --gid-info against $TARGET " $wbinfo --gid-info $gid || failed = $( expr $failed + 1)
2010-03-09 15:35:54 +03:00
2022-02-21 13:20:53 +03:00
testit " wbinfo -r against $TARGET " $wbinfo -r " $DOMAIN / $USERNAME " || failed = $( expr $failed + 1)
2008-04-15 19:04:36 +04:00
2022-02-21 13:20:53 +03:00
testit " wbinfo --user-domgroups against $TARGET " $wbinfo --user-domgroups $admin_sid || failed = $( expr $failed + 1)
2008-04-15 19:04:36 +04:00
2022-02-21 13:20:53 +03:00
testit " wbinfo --user-sids against $TARGET " $wbinfo --user-sids $admin_sid || failed = $( expr $failed + 1)
2008-04-15 19:04:36 +04:00
2022-02-21 13:20:53 +03:00
testit " wbinfo -a against $TARGET with domain creds " $wbinfo -a " $DOMAIN / $USERNAME " %" $PASSWORD " || failed = $( expr $failed + 1)
2008-04-15 19:04:36 +04:00
2022-03-07 22:57:52 +03:00
testit " wbinfo -a against $TARGET with domain upn creds " $wbinfo -a " $USERNAME @ $DOMAIN " %" $PASSWORD " || failed = $( expr $failed + 1)
2009-01-14 15:49:14 +03:00
testit " wbinfo --getdcname against $TARGET " $wbinfo --getdcname= $DOMAIN
2008-04-15 19:04:36 +04:00
2022-02-21 13:20:53 +03:00
testit " wbinfo -p against $TARGET " $wbinfo -p || failed = $( expr $failed + 1)
2008-04-15 19:04:36 +04:00
2022-02-21 13:20:53 +03:00
testit " wbinfo -K against $TARGET with domain creds " $wbinfo --krb5ccname= $KRB5CCNAME --krb5auth= " $DOMAIN / $USERNAME " %" $PASSWORD " || failed = $( expr $failed + 1)
2008-04-15 19:04:36 +04:00
2022-02-21 13:20:53 +03:00
testit " wbinfo --separator against $TARGET " $wbinfo --separator || failed = $( expr $failed + 1)
2008-04-15 19:04:36 +04:00
2017-06-23 17:14:08 +03:00
if test " $TARGET " = "ad_member" ; then
2022-02-21 13:20:53 +03:00
testit " wbinfo --domain-info= $DOMAIN " $wbinfo --domain-info= $DOMAIN || failed = $( expr $failed + 1)
2017-06-23 17:14:08 +03:00
2022-02-21 13:20:53 +03:00
testit " wbinfo --dc-info= $DOMAIN " $wbinfo --dc-info= $DOMAIN || failed = $( expr $failed + 1)
2017-06-23 17:14:08 +03:00
fi
2022-02-21 13:20:53 +03:00
testit_expect_failure " wbinfo -a against $TARGET with invalid password " $wbinfo -a " $DOMAIN / $USERNAME %InvalidPassword " && failed = $( expr $failed + 1)
2017-03-20 14:22:44 +03:00
2022-02-21 13:20:53 +03:00
testit_expect_failure " wbinfo -K against $TARGET with invalid password " $wbinfo -K " $DOMAIN / $USERNAME %InvalidPassword " && failed = $( expr $failed + 1)
2017-03-20 14:22:44 +03:00
2016-09-19 14:27:30 +03:00
rm -f $KRB5CCNAME_PATH
2008-04-15 19:04:36 +04:00
exit $failed