comparison lisp/ldap.el @ 384:bbff43aa5eb7 r21-2-7

Import from CVS: tag r21-2-7
author cvs
date Mon, 13 Aug 2007 11:08:24 +0200
parents cc15677e0335
children aabb7f5b1c81
comparison
equal deleted inserted replaced
383:6a50c6a581a5 384:bbff43aa5eb7
3 ;; Copyright (C) 1997 Free Software Foundation, Inc. 3 ;; Copyright (C) 1997 Free Software Foundation, Inc.
4 4
5 ;; Author: Oscar Figueiredo <Oscar.Figueiredo@di.epfl.ch> 5 ;; Author: Oscar Figueiredo <Oscar.Figueiredo@di.epfl.ch>
6 ;; Maintainer: Oscar Figueiredo <Oscar.Figueiredo@di.epfl.ch> 6 ;; Maintainer: Oscar Figueiredo <Oscar.Figueiredo@di.epfl.ch>
7 ;; Created: Jan 1998 7 ;; Created: Jan 1998
8 ;; Version: $Revision: 1.7.2.1 $ 8 ;; Version: $Revision: 1.7.2.2 $
9 ;; Keywords: help comm 9 ;; Keywords: help comm
10 10
11 ;; This file is part of XEmacs 11 ;; This file is part of XEmacs
12 12
13 ;; XEmacs is free software; you can redistribute it and/or modify it 13 ;; XEmacs is free software; you can redistribute it and/or modify it
33 ;; LDAP support must have been built into XEmacs. 33 ;; LDAP support must have been built into XEmacs.
34 34
35 35
36 ;;; Code: 36 ;;; Code:
37 37
38 (eval-when '(load eval) 38 (require 'ldap)
39 (require 'ldap)) 39 (require 'custom)
40 40
41 (defvar ldap-default-host nil 41 (defgroup ldap nil
42 "*Default LDAP server.") 42 "Lightweight Directory Access Protocol"
43 :group 'comm)
43 44
44 (defvar ldap-host-parameters-alist nil 45 (defcustom ldap-default-host nil
45 "*An alist of per host options for LDAP transactions 46 "*Default LDAP server."
46 The list elements look like (HOST PROP1 VAL1 PROP2 VAL2 ...) 47 :type '(choice (string :tag "Host name")
47 HOST is the name of an LDAP server. PROPn and VALn are property/value pairs 48 (const :tag "Use library default" nil))
48 describing parameters for the server. Valid properties: 49 :group 'ldap)
50
51 (defcustom ldap-default-port nil
52 "*Default TCP port for LDAP connections.
53 Initialized from the LDAP library at build time. Default value is 389."
54 :type '(choice (const :tag "Use library default" nil)
55 (integer :tag "Port number"))
56 :group 'ldap)
57
58 (defcustom ldap-default-base nil
59 "*Default base for LDAP searches.
60 This is a string using the syntax of RFC 1779.
61 For instance, \"o=ACME, c=US\" limits the search to the
62 Acme organization in the United States."
63 :type '(choice (const :tag "Use library default" nil)
64 (string :tag "Search base"))
65 :group 'ldap)
66
67
68 (defcustom ldap-host-parameters-alist nil
69 "*Alist of host-specific options for LDAP transactions.
70 The format of each list element is:
71 \(HOST PROP1 VAL1 PROP2 VAL2 ...)
72 HOST is the name of an LDAP server. PROPn and VALn are property/value
73 pairs describing parameters for the server. Valid properties include:
49 `binddn' is the distinguished name of the user to bind as 74 `binddn' is the distinguished name of the user to bind as
50 (in RFC 1779 syntax). 75 (in RFC 1779 syntax).
51 `passwd' is the password to use for simple authentication. 76 `passwd' is the password to use for simple authentication.
52 `auth' is the authentication method to use. 77 `auth' is the authentication method to use.
53 Possible values are: `simple', `krbv41' and `krbv42'. 78 Possible values are: `simple', `krbv41' and `krbv42'.
54 `base' is the base for the search as described in RFC 1779. 79 `base' is the base for the search as described in RFC 1779.
55 `scope' is one of the three symbols `subtree', `base' or `onelevel'. 80 `scope' is one of the three symbols `subtree', `base' or `onelevel'.
56 `deref' is one of the symbols `never', `always', `search' or `find'. 81 `deref' is one of the symbols `never', `always', `search' or `find'.
57 `timelimit' is the timeout limit for the connection in seconds. 82 `timelimit' is the timeout limit for the connection in seconds.
58 `sizelimit' is the maximum number of matches to return." ) 83 `sizelimit' is the maximum number of matches to return."
84 :type '(repeat :menu-tag "Host parameters"
85 :tag "Host parameters"
86 (list :menu-tag "Host parameters"
87 :tag "Host parameters"
88 :value nil
89 (string :tag "Host name")
90 (checklist :inline t
91 :greedy t
92 (list
93 :tag "Binding DN"
94 :inline t
95 (const :tag "Binding DN" binddn)
96 string)
97 (list
98 :tag "Password"
99 :inline t
100 (const :tag "Password" passwd)
101 string)
102 (list
103 :tag "Authentication Method"
104 :inline t
105 (const :tag "Authentication Method" auth)
106 (choice
107 (const :menu-tag "None" :tag "None" nil)
108 (const :menu-tag "Simple" :tag "Simple" simple)
109 (const :menu-tag "Kerberos 4.1" :tag "Kerberos 4.1" krbv41)
110 (const :menu-tag "Kerberos 4.2" :tag "Kerberos 4.2" krbv42)))
111 (list
112 :tag "Search Base"
113 :inline t
114 (const :tag "Search Base" base)
115 string)
116 (list
117 :tag "Search Scope"
118 :inline t
119 (const :tag "Search Scope" scope)
120 (choice
121 (const :menu-tag "Default" :tag "Default" nil)
122 (const :menu-tag "Subtree" :tag "Subtree" subtree)
123 (const :menu-tag "Base" :tag "Base" base)
124 (const :menu-tag "One Level" :tag "One Level" onelevel)))
125 (list
126 :tag "Dereferencing"
127 :inline t
128 (const :tag "Dereferencing" deref)
129 (choice
130 (const :menu-tag "Default" :tag "Default" nil)
131 (const :menu-tag "Never" :tag "Never" never)
132 (const :menu-tag "Always" :tag "Always" always)
133 (const :menu-tag "When searching" :tag "When searching" search)
134 (const :menu-tag "When locating base" :tag "When locating base" find)))
135 (list
136 :tag "Time Limit"
137 :inline t
138 (const :tag "Time Limit" timelimit)
139 (integer :tag "(in seconds)"))
140 (list
141 :tag "Size Limit"
142 :inline t
143 (const :tag "Size Limit" sizelimit)
144 (integer :tag "(number of records)")))))
145 :group 'ldap)
59 146
60 147
61 (defun ldap-search (filter &optional host attributes attrsonly) 148 (defun ldap-search (filter &optional host attributes attrsonly)
62 "Perform an LDAP search. 149 "Perform an LDAP search.
63 FILTER is the search filter in RFC1558 syntax 150 FILTER is the search filter in RFC1558 syntax, i.e. something that
64 HOST is the LDAP host on which to perform the search 151 looks like \"(cn=John Smith)\".
65 ATTRIBUTES is a list of the specific attributes to retrieve, 152 HOST is the LDAP host on which to perform the search.
66 nil means retrieve all 153 ATTRIBUTES is a list of attributes to retrieve; nil means retrieve all.
67 ATTRSONLY if non nil retrieves the attributes only without 154 If ATTRSONLY is non nil, the attributes will be retrieved without
68 the associated values. 155 the associated values.
69 Additional search parameters can be specified through 156 Additional search parameters can be specified through
70 `ldap-host-parameters-alist' which see." 157 `ldap-host-parameters-alist' which see."
71 (interactive "sFilter:") 158 (interactive "sFilter:")
72 (let (host-plist res ldap) 159 (or host
73 (if (null host) 160 (setq host ldap-default-host))
74 (setq host ldap-default-host)) 161 (or host
75 (if (null host) 162 (error "No LDAP host specified"))
76 (error "No LDAP host specified")) 163 (let ((host-plist (cdr (assoc host ldap-host-parameters-alist)))
77 (setq host-plist 164 ldap)
78 (cdr (assoc host ldap-host-parameters-alist)))
79 (message "Opening LDAP connection to %s..." host) 165 (message "Opening LDAP connection to %s..." host)
80 (setq ldap (ldap-open host host-plist)) 166 (setq ldap (ldap-open host host-plist))
81 (message "Searching with LDAP on %s..." host) 167 (message "Searching with LDAP on %s..." host)
82 (setq res (ldap-search-internal ldap filter 168 (prog1 (ldap-search-internal ldap filter
83 (plist-get host-plist 'base) 169 (plist-get host-plist 'base)
84 (plist-get host-plist 'scope) 170 (plist-get host-plist 'scope)
85 attributes attrsonly)) 171 attributes attrsonly)
86 (ldap-close ldap) 172 (ldap-close ldap))))
87 res))
88
89 173
90
91 (provide 'ldap)
92
93 ;;; ldap.el ends here 174 ;;; ldap.el ends here