2018-10-16 16:16:18 +03:00
#!/bin/bash
if [ $# -lt 5 ] ; then
2022-04-22 16:46:05 +03:00
cat <<EOF
2018-10-16 16:16:18 +03:00
Usage: test_primary_group.sh SERVER USERNAME PASSWORD DOMAIN PREFIX_ABS
EOF
2022-04-22 16:46:05 +03:00
exit 1
2018-10-16 16:16:18 +03:00
fi
SERVER = $1
USERNAME = $2
PASSWORD = $3
DOMAIN = $4
PREFIX_ABS = $5
shift 5
failed = 0
2023-04-13 10:41:26 +03:00
TMPDIR = " $PREFIX_ABS / $( basename $0 ) "
export TMPDIR
2022-04-22 16:46:05 +03:00
. $( dirname $0 ) /subunit.sh
. $( dirname $0 ) /common_test_fns.inc
2018-10-16 16:16:18 +03:00
2022-12-22 16:34:00 +03:00
ldbmodify = $( system_or_builddir_binary ldbmodify " ${ BINDIR } " )
ldbsearch = $( system_or_builddir_binary ldbsearch " ${ BINDIR } " )
2022-12-03 19:48:33 +03:00
2018-10-16 16:16:18 +03:00
TZ = UTC
export TZ
N = $( date +%H%M%S)
testuser = " testuser $N "
testgroup = " testgroup $N "
echo " testuser: $testuser "
echo " testgroup: $testgroup "
2022-04-22 16:46:05 +03:00
testit " mkdir -p ' ${ TMPDIR } ' " mkdir -p ${ TMPDIR } || failed = $( expr $failed + 1)
2018-10-16 16:16:18 +03:00
2022-04-22 16:46:05 +03:00
testit " create ' $testuser ' " $VALGRIND $PYTHON $BINDIR /samba-tool user create " $testuser " Password.1 || failed = $( expr $failed + 1)
testit " add ' $testgroup ' " $VALGRIND $PYTHON $BINDIR /samba-tool group add " $testgroup " || failed = $( expr $failed + 1)
testit " addmembers ' $testgroup ' ' $testuser ' " $VALGRIND $PYTHON $BINDIR /samba-tool group addmembers " $testgroup " " $testuser " || failed = $( expr $failed + 1)
2018-10-16 16:16:18 +03:00
2022-12-03 19:48:33 +03:00
testit "search1" ${ ldbsearch } -H ldap://$SERVER_IP -U$USERNAME %$PASSWORD -d0 sAMAccountName = " $testgroup " objectSid || failed = $( expr $failed + 1)
2018-10-16 16:16:18 +03:00
ldif = " ${ TMPDIR } /search1.ldif "
2022-12-03 19:48:33 +03:00
${ ldbsearch } -H ldap://$SERVER_IP -U$USERNAME %$PASSWORD -d0 sAMAccountName = $testgroup objectSid >$ldif
2018-10-16 16:16:18 +03:00
rid = $( cat $ldif | sed -n 's/^objectSid: S-1-5-21-.*-.*-.*-//p' )
2022-12-03 19:48:33 +03:00
testit "search2" ${ ldbsearch } -H ldap://$SERVER_IP -U$USERNAME %$PASSWORD -d0 sAMAccountName = " $testuser " dn || failed = $( expr $failed + 1)
2018-10-16 16:16:18 +03:00
ldif = " ${ TMPDIR } /search2.ldif "
2022-12-03 19:48:33 +03:00
${ ldbsearch } -H ldap://$SERVER_IP -U$USERNAME %$PASSWORD -d0 sAMAccountName = $testuser dn >$ldif
2018-10-16 16:16:18 +03:00
user_dn = $( cat $ldif | sed -n 's/^dn: //p' )
ldif = " ${ TMPDIR } /modify1.ldif "
2022-04-22 16:46:05 +03:00
cat >$ldif <<EOF
2018-10-16 16:16:18 +03:00
dn: $user_dn
changetype: modify
replace: primaryGroupID
primaryGroupID: $rid
EOF
2022-12-03 19:48:33 +03:00
testit " Change primaryGroupID to $rid " ${ ldbmodify } -H ldap://$SERVER_IP -U$USERNAME %$PASSWORD -d0 --verbose <$ldif || failed = $( expr $failed + 1)
2018-10-16 16:16:18 +03:00
2022-04-22 16:46:05 +03:00
testit "dbcheck run1" $VALGRIND $PYTHON $BINDIR /samba-tool dbcheck --attrs= member || failed = $( expr $failed + 1)
2018-10-16 16:16:18 +03:00
ldif = " ${ TMPDIR } /modify2.ldif "
2022-04-22 16:46:05 +03:00
cat >$ldif <<EOF
2018-10-16 16:16:18 +03:00
dn: $user_dn
changetype: modify
replace: primaryGroupID
primaryGroupID: 513
EOF
2022-12-03 19:48:33 +03:00
testit "Change primaryGroupID to 513" ${ ldbmodify } -H ldap://$SERVER_IP -U$USERNAME %$PASSWORD -d0 <$ldif || failed = $( expr $failed + 1)
2018-10-16 16:16:18 +03:00
2022-04-22 16:46:05 +03:00
testit "dbcheck run2" $VALGRIND $PYTHON $BINDIR /samba-tool dbcheck --attrs= member || failed = $( expr $failed + 1)
2018-10-16 16:16:18 +03:00
2022-04-22 16:46:05 +03:00
testit " delete ' $testuser ' " $VALGRIND $PYTHON $BINDIR /samba-tool user delete " $testuser " || failed = $( expr $failed + 1)
testit " delete ' $testgroup ' " $VALGRIND $PYTHON $BINDIR /samba-tool group delete " $testgroup " || failed = $( expr $failed + 1)
2018-10-16 16:16:18 +03:00
#
# As we don't support phantom objects and virtual backlinks
2018-10-30 05:56:43 +03:00
# the deletion of the user prior to the group causes dangling links,
2018-10-16 16:16:18 +03:00
# which are detected like this:
#
# WARNING: target DN is deleted for member in object
#
2018-10-30 05:56:43 +03:00
# Specifically, this happens because after the member link is
# deactivated the memberOf is gone, and so there is no way to find the
# now redundant forward link to clean it up.
#
2022-04-22 16:46:05 +03:00
testit_expect_failure "dbcheck run3" $VALGRIND $PYTHON $BINDIR /samba-tool dbcheck --attrs= member --fix --yes || failed = $( expr $failed + 1)
testit "dbcheck run4" $VALGRIND $PYTHON $BINDIR /samba-tool dbcheck --attrs= member || failed = $( expr $failed + 1)
2018-10-16 16:16:18 +03:00
exit $failed