#!/bin/bash

# adapted from: https://forge.univention.org/bugzilla/attachment.cgi?id=6561

eval "$(ucr shell)"

testusername=user2
password=univention
wrong_password=foo

udm users/user create \
	--position "cn=users,$ldap_base" \
	--set username="$testusername" \
	--set lastname=s1 \
	--set password="$password"

samba-tool domain passwordsettings set \
	--account-lockout-duration=1 \
	--account-lockout-threshold=3 \
	--reset-account-lockout-after=2 2>/dev/null

sleep 5
smbclient //localhost/sysvol -U "$testusername"%"$wrong_password" -c quit 2>/dev/null
smbclient //localhost/sysvol -U "$testusername"%"$wrong_password" -c quit 2>/dev/null
smbclient //localhost/sysvol -U "$testusername"%"$wrong_password" -c quit 2>/dev/null

date +%s
echo -e "\nListing with univention-samba-lockedout:"
./univention-samba-lockedout
echo -e "\nListing with univention-samba-lockedout (verbose):"
./univention-samba-lockedout --verbose

echo -e "\nWaiting some time"
sleep 30

date +%s
echo -e "\nListing with univention-samba-lockedout:"
./univention-samba-lockedout
echo -e "\nListing with univention-samba-lockedout (verbose):"
./univention-samba-lockedout --verbose

echo -e "\nWaiting for unlock"
sleep 35

smbclient //localhost/sysvol -U "$testusername"%"$password" -c quit 2>/dev/null && echo "Logon OK"

date +%s
echo -e "\nListing with univention-samba-lockedout:"
./univention-samba-lockedout
echo -e "\nListing with univention-samba-lockedout (verbose):"
./univention-samba-lockedout --verbose

