annotate lisp/ldap.el @ 290:c9fe270a4101 r21-0b43

Import from CVS: tag r21-0b43
author cvs
date Mon, 13 Aug 2007 10:36:47 +0200
parents c42ec1d1cded
children 70ad99077275
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1 ;;; ldap.el --- LDAP support for Emacs
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3 ;; Copyright (C) 1997 Free Software Foundation, Inc.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5 ;; Author: Oscar Figueiredo <Oscar.Figueiredo@di.epfl.ch>
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
6 ;; Maintainer: Oscar Figueiredo <Oscar.Figueiredo@di.epfl.ch>
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
7 ;; Created: Jan 1998
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
8 ;; Version: $Revision: 1.5 $
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
9 ;; Keywords: help comm
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
10
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
11 ;; This file is part of XEmacs
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
12
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
13 ;; XEmacs is free software; you can redistribute it and/or modify it
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
14 ;; under the terms of the GNU General Public License as published by
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
15 ;; the Free Software Foundation; either version 2, or (at your option)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
16 ;; any later version.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
17
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
18 ;; XEmacs is distributed in the hope that it will be useful, but
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
19 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
21 ;; General Public License for more details.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
22
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
23 ;; You should have received a copy of the GNU General Public License
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
24 ;; along with XEmacs; see the file COPYING. If not, write to
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
25 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
26 ;; Boston, MA 02111-1307, USA.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
27
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
28 ;;; Commentary:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
29 ;; This file provides mid-level and user-level functions to access directory
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
30 ;; servers using the LDAP protocol (RFC 1777).
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
31
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
32 ;;; Installation:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
33 ;; LDAP support must have been built into XEmacs.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
34
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
35
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
36 ;;; Code:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
37
261
405dd6d1825b Import from CVS: tag r20-5b29
cvs
parents: 259
diff changeset
38 (eval-when '(load eval)
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 261
diff changeset
39 (require 'ldap))
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 261
diff changeset
40
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 261
diff changeset
41 (defvar ldap-default-host nil
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 261
diff changeset
42 "*Default LDAP server.")
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
43
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
44 (defvar ldap-host-parameters-plist nil
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
45 "*A property list of per host options for LDAP transactions
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
46 The list elements look like (HOST PROP1 VAL1 PROP2 VAL2 ...)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
47 HOST is the name of an LDAP server. PROPn and VALn are property/value pairs
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
48 describing parameters for the server. Valid properties:
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
49 `binddn' is the distinguished name of the user to bind as
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
50 (in RFC 1779 syntax).
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
51 `passwd' is the password to use for simple authentication.
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
52 `auth' is the authentication method to use.
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
53 Possible values are: `simple', `krbv41' and `krbv42'.
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
54 `base' is the base for the search as described in RFC 1779.
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
55 `scope' is one of the three symbols `subtree', `base' or `onelevel'.
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
56 `deref' is one of the symbols `never', `always', `search' or `find'.
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
57 `timelimit' is the timeout limit for the connection in seconds.
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
58 `sizelimit' is the maximum number of matches to return." )
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
59
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
60
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
61 (defun ldap-search (filter &optional host attributes attrsonly)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
62 "Perform an LDAP search.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
63 FILTER is the search filter in RFC1558 syntax
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
64 HOST is the LDAP host on which to perform the search
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
65 ATTRIBUTES is the specific attributes to retrieve, nil means
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
66 retrieve all
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
67 ATTRSONLY if non nil retrieves the attributes only without
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
68 the associated values.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
69 Additional search parameters can be specified through
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
70 `ldap-host-parameters-plist' which see."
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
71 (interactive "sFilter:")
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
72 (let (host-plist res ldap)
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
73 (if (null host)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
74 (setq host ldap-default-host))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
75 (if (null host)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
76 (error "No LDAP host specified"))
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
77 (setq host-plist
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
78 (cdr (assoc host ldap-host-parameters-plist)))
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 261
diff changeset
79 (message "Opening LDAP connection to %s..." host)
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
80 (setq ldap (ldap-open host host-plist))
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 261
diff changeset
81 (message "Searching with LDAP on %s..." host)
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 261
diff changeset
82 (setq res (ldap-search-internal ldap filter
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
83 (plist-get host-plist 'base)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
84 (plist-get host-plist 'scope)
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 261
diff changeset
85 attributes attrsonly))
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 261
diff changeset
86 (ldap-close ldap)
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 261
diff changeset
87 res))
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
88
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
89
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
90
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
91 (provide 'ldap)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
92
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
93 ;;; ldap.el ends here