scsh-ldap/etc/sample.scm

32 lines
940 B
Scheme

;;; ,open ldap-low ldap-types pp
(define (open-anonymous-ldap-v3-session host)
(let ((session (ldap-init host)))
(set-ldap-session-option! (ldap-session-option-value protocol-version) 3 session)
(ldap-simple-bind-anonymous session)
session))
(define (get-value-alist entry)
(let ((attributes (ldap-all-attributes entry)))
(map (lambda (attribute)
(cons (string->symbol attribute)
(ldap-get-values entry attribute)))
attributes)))
(define (find-all-entries host root-dn)
(with-ldap-session
(open-anonymous-ldap-v3-session host)
(lambda ()
(let ((result
(ldap-search
root-dn (ldap-scope-arguments onelevel)
"(objectClass=*)" ldap-attributes-all-user-attributes #f)))
(let lp ((entry (ldap-first-entry result))
(res '()))
(if (not entry)
res
(lp (ldap-next-entry entry)
(cons (ldap-entry-dn entry)
(cons (get-value-alist entry) res)))))))))