1 (in-package :net.quadium.ldap
)
3 (defun ldap-escape (string)
4 (labels ((worker (char-list)
5 (unless (endp char-list
)
6 (let* ((char (car char-list
))
7 (rest (cons char
(worker (cdr char-list
)))))
8 (if (find char
"\\(),!&|<>=")
11 (coerce (worker (coerce string
'list
))
14 (defun compose-ldap-search-arguments (filter attributes
19 ; (password-file *password-file*)
22 (simple-auth-p *simple-auth-p
*)
25 "Helper function to handle arglists common to searching functions."
26 (format nil
"~{~{ ~S~}~}"
30 (list "-y" (namestring (truename password-file
))))
32 (list "-w" password
)); TODO: remove when finished
41 (list "-s" (ecase scope
48 ((zerop (length filter
)) "(objectClass=*)")
49 ((stringp filter
) filter
)
50 ((listp filter
) (convert-search-filter filter
))))
53 (defun ldap-search (&rest args
)
54 "Searches by FILTER and returns matching ATTRIBUTES.
55 FILTER may be a filter string in the form expected by ldap_search(3),
56 or a sexp which will be converted by CONVERT-SEARCH-FILTER. A null
57 FILTER is equivalent to \"(objectClass=*)\". ATTRIBUTES is a list of
58 strings, each string designating the name of an attribute. If
59 ATTRIBUTES is empty, all attributes of a matching record will be
61 (with-input-from-string (ldif (funcall #'trivial-shell
:shell-command
62 (concatenate 'string
*ldapsearch-command
*
63 (apply #'compose-ldap-search-arguments args
))))
64 (ldif:parse-ldif-stream ldif
)))
66 (defun ldap-fetch-by-dn (dn attributes
68 "Fetches the object designated by the distinguished name DN.
69 ATTRIBUTES are handled as by LDAP-SEARCH."
70 (car (apply 'ldap-search
"" attributes
76 (defun compose-ldap-modify-arguments (&key
78 ;(password-file *password-file*)
81 (simple-auth-p *simple-auth-p
*)
84 "Helper function to handle arglists common to modifying functions."
85 (format nil
"~{~{ ~S~}~}"
89 (list "-y" *password-file
*))
91 (list "-w" password
)); TODO: remove when finished
99 (defun ldap-modify (change-records &rest args
)
100 "Transmits CHANGE-RECORDS to the LDAP server for execution."
101 (with-open-stream (ldif (make-string-output-stream))
102 (dolist (record change-records change-records
)
103 (ldif:write-change-record record ldif
)
104 (funcall #'trivial-shell
:shell-command
105 (concatenate 'string
*ldapmodify-command
*
106 (apply #'compose-ldap-modify-arguments args
))
107 :input
(get-output-stream-string ldif
)))))