Sunday, 30 August 2015

Beginning last Friday with CommonMark, I'm now working through my CHICKEN Scheme backlog and attempting to release an egg each week. Today, it's a fairly minimal binding to OpenLDAP.


I had originally started this from scratch but fortuitously discovered that Moritz Heidkamp had begun a similar project several years ago. I think originally planned as a complete binding to OpenLDAP, it was never released. I was able to take this well implemented base and update it to the latest APIs. Rather than support all the features of LDAP, this module lets you authenticate a user, and not much else.


The ldap-bind egg is available via the CHICKEN egg index:

chicken-install ldap-bind

You must also install OpenLDAP for the libldap and liblber libraries.


(use ldap-bind)

(define conn
  (ldap-initialize "ldaps://example.com"))

(if (ldap-bind conn "uid=testuser,cn=users,dc=example,dc=com" "password")
    (print "Welcome, authenticated user!")
    (print "Invalid Credentials"))

;; or, using list syntax for a base dn:

(define base-dn
  '((cn "users") (dc "example") (dc "com")))

(if (ldap-bind conn (cons '(uid "testuser") base-dn) "password")
    (print "Welcome, authenticated user!")
    (print "Invalid Credentials"))

(ldap-unbind conn)