Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 81 lines (62 sloc) 2.425 kb
c900e15 start off with what was in eighthbit-website
James S authored
1 (defpackage #:nisp.ldap
ab17ba9 move 8b stuff to its own package
James S authored
2 (:use :cl)
3 (:export *connections* #:with-ldap))
c900e15 start off with what was in eighthbit-website
James S authored
4
5 (in-package :nisp.ldap)
6
4410cb0 move while out of my way
James S authored
7 ;;; Needs to be moved to a seperate utility file or something.
8 (defmacro while (test &body body)
9 "While, like in most other languages."
10 `(do ()
11 ((not ,test))
12 ,@body))
13
c900e15 start off with what was in eighthbit-website
James S authored
14
f27e4e7 add *connections* to hold a list of connections for 8b
James S authored
15 (defparameter *connections* '()
16 "Property list of connections to LDAP.")
17
c900e15 start off with what was in eighthbit-website
James S authored
18 ;;; Load an optional config file, the lack of this should not cause this
19 ;;; program to become unusable.
20 (load "config.lisp" :if-does-not-exist nil)
21
a99a82d add make-ldap, given a keyword or an ldap:ldap object, return an
James S authored
22
23 (defun make-ldap (ldap-or-keyword
24 &optional (connections *connections*))
25 "Return an LDAP object, so long as input is an ldap object or a
26 keyword referincing an ldap object."
27 (if (typep ldap-or-keyword 'ldap:ldap)
28 ldap-or-keyword
29 (getf connections ldap-or-keyword)))
30
ab17ba9 move 8b stuff to its own package
James S authored
31
c900e15 start off with what was in eighthbit-website
James S authored
32
abb5d46 fix up with-ldap to make use of make-ldap
James S authored
33 (defmacro with-ldap (ldap-or-keyword &body body)
c900e15 start off with what was in eighthbit-website
James S authored
34 "Execute BODY in the context of LDAP bound to the ldap server."
abb5d46 fix up with-ldap to make use of make-ldap
James S authored
35 ;; I think this is fine to do instead of using gensyms. I'll consult
36 ;; on lisp on this later.
37 (let ((ldap (gensym)))
38 `(let ((,ldap (make-ldap ,ldap-or-keyword)))
39 (prog2
40 (ldap:bind ,ldap)
41 (progn ,@body)
42 (ldap:unbind ,ldap)))))
c900e15 start off with what was in eighthbit-website
James S authored
43
44 (defun strip-newlines (string &optional (replace-char nil))
45 "Given a string, remove all newlines.
46
47 This is very irc specific where lines need to be all on one line.
48
49 Note that the newline is not replaced by a space!"
50 (coerce
51 (loop for char in (coerce string 'list)
52 when (and replace-char (eq char #\Newline)) collect replace-char
53 unless (eq char #\Newline) collect char)
54 'string))
55
775ace2 split print-single-entry up so we have get-single-entry
James S authored
56 (defun get-single-entry (search-string &key (ldap :anon)
57 attrs)
58 "Get a single trivial-ldap:entry object by binding and searching."
59 (with-ldap ldap
60 (ldap:search (make-ldap ldap) search-string
61 :attributes attrs)
62 (ldap:next-search-result (make-ldap ldap))))
63
02adada we should also default to the keyword :anon
James S authored
64 (defun print-single-entry (search-string &key (ldap :anon)
c900e15 start off with what was in eighthbit-website
James S authored
65 attrs)
66 (strip-newlines
67 (ldap:ldif
775ace2 split print-single-entry up so we have get-single-entry
James S authored
68 (get-single-entry search-string :ldap ldap :attrs attrs))
c900e15 start off with what was in eighthbit-website
James S authored
69 #\ ))
70
ab17ba9 move 8b stuff to its own package
James S authored
71 (defun list-search-results (search-string &optional (ldap :anon))
c900e15 start off with what was in eighthbit-website
James S authored
72 "List of entries from a search."
73 (with-ldap ldap
74 (ldap:search ldap search-string))
75 (let (result)
76 (while (ldap:results-pending-p ldap)
77 (push (ldap:next-search-result ldap) result))
23b1f81 fix typo of localhost
James S authored
78 (nreverse (cdr result))))
79
80
Something went wrong with that request. Please try again.