2017-07-10 17:20:23 +03:00
#!/bin/sh
#
# Basic testing of id mapping with idmap_ad
#
2019-04-23 02:38:11 +03:00
if [ $# -ne 6 ] ; then
echo Usage: $0 DOMAIN DC_SERVER DC_PASSWORD TRUST_DOMAIN TRUST_SERVER TRUST_PASSWORD
2017-07-10 17:20:23 +03:00
exit 1
fi
DOMAIN = " $1 "
DC_SERVER = " $2 "
DC_PASSWORD = " $3 "
2019-04-23 02:38:11 +03:00
TRUST_DOMAIN = " $4 "
TRUST_SERVER = " $5 "
TRUST_PASSWORD = " $6 "
2017-07-10 17:20:23 +03:00
wbinfo = " $VALGRIND $BINDIR /wbinfo "
ldbmodify = " $VALGRIND $BINDIR /ldbmodify "
ldbsearch = " $VALGRIND $BINDIR /ldbsearch "
failed = 0
2022-02-21 13:20:53 +03:00
. $( dirname $0 ) /../../testprogs/blackbox/subunit.sh
2017-07-10 17:20:23 +03:00
2018-05-07 14:23:42 +03:00
DOMAIN_SID = $( $wbinfo -n " $DOMAIN / " | cut -f 1 -d " " )
2022-02-21 13:20:53 +03:00
if [ $? -ne 0 ] ; then
echo "Could not find domain SID" | subunit_fail_test "test_idmap_ad"
exit 1
2017-07-10 17:20:23 +03:00
fi
2019-04-23 02:41:42 +03:00
TRUST_DOMAIN_SID = $( $wbinfo -n " $TRUST_DOMAIN / " | cut -f 1 -d " " )
2022-02-21 13:20:53 +03:00
if [ $? -ne 0 ] ; then
echo "Could not find trusted domain SID" | subunit_fail_test "test_idmap_ad"
exit 1
2019-04-23 02:41:42 +03:00
fi
2020-12-17 14:25:15 +03:00
BASE_DN = $( $ldbsearch -H ldap://$DC_SERVER -b "" --scope= base defaultNamingContext | awk '/^defaultNamingContext/ {print $2}' )
2022-02-21 13:20:53 +03:00
if [ $? -ne 0 ] ; then
echo "Could not find base DN" | subunit_fail_test "test_idmap_ad"
exit 1
2017-07-10 17:20:23 +03:00
fi
2020-12-17 14:25:15 +03:00
TRUST_BASE_DN = $( $ldbsearch -H ldap://$TRUST_SERVER -b "" --scope= base defaultNamingContext | awk '/^defaultNamingContext/ {print $2}' )
2022-02-21 13:20:53 +03:00
if [ $? -ne 0 ] ; then
echo "Could not find trusted base DN" | subunit_fail_test "test_idmap_ad"
exit 1
2019-04-23 02:41:42 +03:00
fi
2017-07-10 17:20:23 +03:00
#
# Add POSIX ids to AD
#
cat <<EOF | $ldbmodify -H ldap://$DC_SE RVER -U " $DOMAIN \Administrator% $DC_PASSWORD "
dn: CN = Administrator,CN= Users,$BASE_DN
changetype: modify
add: uidNumber
uidNumber: 2000000
2020-08-30 12:45:56 +03:00
add: gidNumber
gidNumber: 2000100
add: unixHomeDirectory
unixHomeDirectory: /home/admin
add: loginShell
loginShell: /bin/tcsh
add: gecos
gecos: Administrator Full Name
2017-07-10 17:20:23 +03:00
EOF
cat <<EOF | $ldbmodify -H ldap://$DC_SE RVER -U " $DOMAIN \Administrator% $DC_PASSWORD "
dn: CN = Domain Users,CN= Users,$BASE_DN
changetype: modify
add: gidNumber
gidNumber: 2000001
EOF
2019-04-23 02:15:20 +03:00
cat <<EOF | $ldbmodify -H ldap://$DC_SE RVER -U " $DOMAIN \Administrator% $DC_PASSWORD "
dn: CN = Domain Admins,CN= Users,$BASE_DN
changetype: modify
add: gidNumber
gidNumber: 2000002
EOF
2019-04-23 02:41:42 +03:00
#
# Add POSIX ids to trusted domain
#
cat <<EOF | $ldbmodify -H ldap://$TRUST_SE RVER \
2022-02-21 13:20:53 +03:00
-U " $TRUST_DOMAIN \Administrator% $TRUST_PASSWORD "
2019-04-23 02:41:42 +03:00
dn: CN = Administrator,CN= Users,$TRUST_BASE_DN
changetype: modify
add: uidNumber
uidNumber: 2500000
EOF
cat <<EOF | $ldbmodify -H ldap://$TRUST_SE RVER \
2022-02-21 13:20:53 +03:00
-U " $TRUST_DOMAIN \Administrator% $TRUST_PASSWORD "
2019-04-23 02:41:42 +03:00
dn: CN = Domain Users,CN= Users,$TRUST_BASE_DN
changetype: modify
add: gidNumber
gidNumber: 2500001
EOF
cat <<EOF | $ldbmodify -H ldap://$TRUST_SE RVER \
2022-02-21 13:20:53 +03:00
-U " $TRUST_DOMAIN \Administrator% $TRUST_PASSWORD "
2019-04-23 02:41:42 +03:00
dn: CN = Domain Admins,CN= Users,$TRUST_BASE_DN
changetype: modify
add: gidNumber
gidNumber: 2500002
EOF
2017-07-10 17:20:23 +03:00
#
# Test 1: Test uid of Administrator, should be 2000000
#
out = " $( $wbinfo -S $DOMAIN_SID -500) "
echo " wbinfo returned: \" $out \", expecting \"2000000\" "
test " $out " = "2000000"
ret = $?
testit "Test uid of Administrator is 2000000" test $ret -eq 0 || failed = $( expr $failed + 1)
#
# Test 2: Test gid of Domain Users, should be 2000001
#
out = " $( $wbinfo -Y $DOMAIN_SID -513) "
echo " wbinfo returned: \" $out \", expecting \"2000001\" "
test " $out " = "2000001"
ret = $?
testit "Test uid of Domain Users is 2000001" test $ret -eq 0 || failed = $( expr $failed + 1)
#
# Test 3: Test get userinfo for Administrator works
#
out = " $( $wbinfo -i $DOMAIN /Administrator) "
2020-08-30 12:45:56 +03:00
echo " wbinfo returned: \" $out \", expecting \" $DOMAIN /administrator:*:2000000:2000100:Administrator Full Name:/home/admin:/bin/tcsh\" "
test " $out " = " $DOMAIN /administrator:*:2000000:2000100:Administrator Full Name:/home/admin:/bin/tcsh "
2017-07-10 17:20:23 +03:00
ret = $?
testit "Test get userinfo for Administrator works" test $ret -eq 0 || failed = $( expr $failed + 1)
2019-04-23 02:15:20 +03:00
#
# Test 4: Test lookup from gid to sid
#
out = " $( $wbinfo -G 2000002) "
echo " wbinfo returned: \" $out \", expecting \" $DOMAIN_SID -512\" "
test " $out " = " $DOMAIN_SID -512 "
ret = $?
testit "Test gid lookup of Domain Admins" test $ret -eq 0 || failed = $( expr $failed + 1)
2019-04-23 02:41:42 +03:00
#
# Trusted domain test 1: Test uid of Administrator, should be 2500000
#
out = " $( $wbinfo -S $TRUST_DOMAIN_SID -500) "
echo " wbinfo returned: \" $out \", expecting \"2500000\" "
test " $out " = "2500000"
ret = $?
testit "Test uid of Administrator in trusted domain is 2500000" test $ret -eq 0 || failed = $( expr $failed + 1)
#
# Trusted domain test 2: Test gid of Domain Users, should be 2500001
#
out = " $( $wbinfo -Y $TRUST_DOMAIN_SID -513) "
echo " wbinfo returned: \" $out \", expecting \"2500001\" "
test " $out " = "2500001"
ret = $?
testit "Test uid of Domain Users in trusted domain is 2500001" test $ret -eq 0 || failed = $( expr $failed + 1)
#
# Trusted domain test 3: Test get userinfo for Administrator works
#
out = " $( $wbinfo -i $TRUST_DOMAIN /Administrator) "
echo " wbinfo returned: \" $out \", expecting \" $TRUST_DOMAIN /administrator:*:2500000:2500001::/home/ $TRUST_DOMAIN /administrator:/bin/false\" "
test " $out " = " $TRUST_DOMAIN /administrator:*:2500000:2500001::/home/ $TRUST_DOMAIN /administrator:/bin/false "
ret = $?
testit "Test get userinfo for Administrator works" test $ret -eq 0 || failed = $( expr $failed + 1)
#
# Trusted domain test 4: Test lookup from gid to sid
#
out = " $( $wbinfo -G 2500002) "
echo " wbinfo returned: \" $out \", expecting \" $TRUST_DOMAIN_SID -512\" "
test " $out " = " $TRUST_DOMAIN_SID -512 "
ret = $?
testit "Test gid lookup of Domain Admins in trusted domain." test $ret -eq 0 || failed = $( expr $failed + 1)
2017-07-10 17:20:23 +03:00
#
# Remove POSIX ids from AD
#
cat <<EOF | $ldbmodify -H ldap://$DC_SE RVER -U " $DOMAIN \Administrator% $DC_PASSWORD "
dn: CN = Administrator,CN= Users,$BASE_DN
changetype: modify
delete: uidNumber
uidNumber: 2000000
2020-08-30 12:45:56 +03:00
delete: gidNumber
gidNumber: 2000100
delete: unixHomeDirectory
unixHomeDirectory: /home/admin
delete: loginShell
loginShell: /bin/tcsh
delete: gecos
gecos: Administrator Full Name
2017-07-10 17:20:23 +03:00
EOF
cat <<EOF | $ldbmodify -H ldap://$DC_SE RVER -U " $DOMAIN \Administrator% $DC_PASSWORD "
dn: CN = Domain Users,CN= Users,$BASE_DN
changetype: modify
delete: gidNumber
gidNumber: 2000001
EOF
2019-04-23 02:15:20 +03:00
cat <<EOF | $ldbmodify -H ldap://$DC_SE RVER -U " $DOMAIN \Administrator% $DC_PASSWORD "
dn: CN = Domain Admins,CN= Users,$BASE_DN
changetype: modify
delete: gidNumber
gidNumber: 2000002
EOF
2019-04-23 02:41:42 +03:00
#
# Remove POSIX ids from trusted domain
#
cat <<EOF | $ldbmodify -H ldap://$TRUST_SE RVER \
2022-02-21 13:20:53 +03:00
-U " $TRUST_DOMAIN \Administrator% $TRUST_PASSWORD "
2019-04-23 02:41:42 +03:00
dn: CN = Administrator,CN= Users,$TRUST_BASE_DN
changetype: modify
delete: uidNumber
uidNumber: 2500000
EOF
cat <<EOF | $ldbmodify -H ldap://$TRUST_SE RVER \
2022-02-21 13:20:53 +03:00
-U " $TRUST_DOMAIN \Administrator% $TRUST_PASSWORD "
2019-04-23 02:41:42 +03:00
dn: CN = Domain Users,CN= Users,$TRUST_BASE_DN
changetype: modify
delete: gidNumber
gidNumber: 2500001
EOF
cat <<EOF | $ldbmodify -H ldap://$TRUST_SE RVER \
2022-02-21 13:20:53 +03:00
-U " $TRUST_DOMAIN \Administrator% $TRUST_PASSWORD "
2019-04-23 02:41:42 +03:00
dn: CN = Domain Admins,CN= Users,$TRUST_BASE_DN
changetype: modify
delete: gidNumber
gidNumber: 2500002
EOF
2017-07-10 17:20:23 +03:00
exit $failed