diff --git a/etc/sample.scm b/etc/sample.scm new file mode 100644 index 0000000..9dd23b5 --- /dev/null +++ b/etc/sample.scm @@ -0,0 +1,28 @@ +;;; ,open ldap-low ldap-types pp + +(define (open-anonymous-ldap-v3-session host) + (let ((session (ldap-init host))) + (set-ldap-session-option! session (ldap-session-option-value protocol-version) 3) + (ldap-simple-bind-as-nobody session) + session)) + +(define (get-value-alist session entry) + (let ((attributes (ldap-all-attributes session entry))) + (map (lambda (attribute) + (cons (string->symbol attribute) + (ldap-get-values session entry attribute))) + attributes))) + +(define (find-all-entries host root-dn) + (let* ((session (open-anonymous-ldap-v3-session host)) + (entry (ldap-search session root-dn (ldap-scope-arguments onelevel) + "(objectClass=*)" + ldap-attributes-all-user-attributes #f))) + (let lp ((entry (ldap-first-entry session entry)) + (res '())) + (if (not entry) + res + (lp (ldap-next-entry session entry) + (cons (ldap-entry-dn session entry) + (cons (get-value-alist session entry) res))))))) +