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