#!/bin/bash

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=5 \
	--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

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

echo -e "\nUnlocking user via samaccountname"
./univention-samba-unlock -UAdministrator%univention $testusername

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

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

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

echo -e "\nUnlocking user via dn"
./univention-samba-unlock -UAdministrator%univention --is-dn CN=user2,CN=Users,DC=loyen,DC=intranet

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