SCRIPT Using LDAP-server for authentication

This section contains scripts that hMailServer has contributed with. hMailServer 5 is needed to use these.
Post Reply
FabulousGee
New user
New user
Posts: 4
Joined: 2020-08-06 01:05

SCRIPT Using LDAP-server for authentication

Post by FabulousGee » 2020-08-06 01:14

First of all: this currently depends on a pull request on GitHub. So it will just work if this pull request gets integrated or you do this yourself! See https://github.com/hmailserver/hmailserver/pull/338 for further details.

If this has happened, then you might find this little snippet useful:

Code: Select all

Sub OnClientValidatePassword(oAccount, sPassword)
	testUserName = "user@example-domain.com"
	testUserPass = "somePassword"
	ldapServer = "192.168.0.1/cn=Users,DC=example-domain,DC=com"
	sRoot = "LDAP://" & ldapServer

	Set dso = GetObject("LDAP:")

	On Error Resume Next
	Set ou = dso.OpenDSObject(sRoot, oAccount.ADUsername, sPassword, 77)
	rem For the last parameter, have a look at:
	rem https://docs.microsoft.com/de-de/windows/win32/api/iads/ne-iads-ads_authentication_enum
	rem Other methods:
	rem Set ou = dso.OpenDSObject(sRoot, testUserName, testUserPass, 77) for testing
	rem Set ou = dso.OpenDSObject(sRoot, oAccount.Address, sPassword, 77) for using email address instead of AD-Username

	If Err.number <> 0 Then
		Result.value = 1
	Else
		Result.value = 0
	End If

	rem Continue using standard auth from hMailServer
	rem Result.value = 2
End Sub
It is not yet tested but should do the job. Feel free to ask if there are any questions regarding this but it should be quite self-explanatory.

Post Reply