Mercurial > hg > xemacs-beta
comparison lisp/ldap.el @ 361:7347b34c275b r21-1-10
Import from CVS: tag r21-1-10
author | cvs |
---|---|
date | Mon, 13 Aug 2007 10:58:40 +0200 |
parents | c6de09ad3017 |
children | cc15677e0335 |
comparison
equal
deleted
inserted
replaced
360:0f00b38cfccb | 361:7347b34c275b |
---|---|
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.8 $ | 8 ;; Version: $Revision: 1.9 $ |
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 (eval-when '(load) |
39 (require 'ldap)) | 39 (if (not (fboundp 'ldap-open)) |
40 (error "No LDAP support compiled in this XEmacs"))) | |
40 | 41 |
41 (defvar ldap-default-host nil | 42 (defgroup ldap nil |
42 "*Default LDAP server.") | 43 "Lightweight Directory Access Protocol" |
44 :group 'comm) | |
43 | 45 |
44 (defvar ldap-host-parameters-alist nil | 46 (defcustom ldap-default-host nil |
45 "*An alist of per host options for LDAP transactions | 47 "*Default LDAP server hostname. |
46 The list elements look like (HOST PROP1 VAL1 PROP2 VAL2 ...) | 48 A TCP port number can be appended to that name using a colon as |
47 HOST is the name of an LDAP server. PROPn and VALn are property/value pairs | 49 a separator." |
48 describing parameters for the server. Valid properties: | 50 :type '(choice (string :tag "Host name") |
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: | |
49 `binddn' is the distinguished name of the user to bind as | 79 `binddn' is the distinguished name of the user to bind as |
50 (in RFC 1779 syntax). | 80 (in RFC 1779 syntax). |
51 `passwd' is the password to use for simple authentication. | 81 `passwd' is the password to use for simple authentication. |
52 `auth' is the authentication method to use. | 82 `auth' is the authentication method to use. |
53 Possible values are: `simple', `krbv41' and `krbv42'. | 83 Possible values are: `simple', `krbv41' and `krbv42'. |
54 `base' is the base for the search as described in RFC 1779. | 84 `base' is the base for the search as described in RFC 1779. |
55 `scope' is one of the three symbols `subtree', `base' or `onelevel'. | 85 `scope' is one of the three symbols `subtree', `base' or `onelevel'. |
56 `deref' is one of the symbols `never', `always', `search' or `find'. | 86 `deref' is one of the symbols `never', `always', `search' or `find'. |
57 `timelimit' is the timeout limit for the connection in seconds. | 87 `timelimit' is the timeout limit for the connection in seconds. |
58 `sizelimit' is the maximum number of matches to return." ) | 88 `sizelimit' is the maximum number of matches to return." |
59 | 89 :type '(repeat :menu-tag "Host parameters" |
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) | |
60 | 151 |
61 (defun ldap-search (filter &optional host attributes attrsonly) | 152 (defun ldap-search (filter &optional host attributes attrsonly) |
62 "Perform an LDAP search. | 153 "Perform an LDAP search. |
63 FILTER is the search filter in RFC1558 syntax | 154 FILTER is the search filter in RFC1558 syntax, i.e., something that |
64 HOST is the LDAP host on which to perform the search | 155 looks like \"(cn=John Smith)\". |
65 ATTRIBUTES is a list of the specific attributes to retrieve, | 156 HOST is the LDAP host on which to perform the search. |
66 nil means retrieve all | 157 ATTRIBUTES is a list of attributes to retrieve; nil means retrieve all. |
67 ATTRSONLY if non nil retrieves the attributes only without | 158 If ATTRSONLY is non nil, the attributes will be retrieved without |
68 the associated values. | 159 the associated values. |
69 Additional search parameters can be specified through | 160 Additional search parameters can be specified through |
70 `ldap-host-parameters-alist' which see." | 161 `ldap-host-parameters-alist' which see." |
71 (interactive "sFilter:") | 162 (interactive "sFilter:") |
72 (let (host-plist res ldap) | 163 (or host |
73 (if (null host) | 164 (setq host ldap-default-host) |
74 (setq host ldap-default-host)) | 165 (error "No LDAP host specified")) |
75 (if (null host) | 166 (let ((host-plist (cdr (assoc host ldap-host-parameters-alist))) |
76 (error "No LDAP host specified")) | 167 ldap |
77 (setq host-plist | 168 res) |
78 (cdr (assoc host ldap-host-parameters-alist))) | |
79 (message "Opening LDAP connection to %s..." host) | 169 (message "Opening LDAP connection to %s..." host) |
80 (setq ldap (ldap-open host host-plist)) | 170 (setq ldap (ldap-open host host-plist)) |
81 (message "Searching with LDAP on %s..." host) | 171 (message "Searching with LDAP on %s..." host) |
82 (setq res (ldap-search-internal ldap filter | 172 (setq res (ldap-search-internal ldap filter |
83 (plist-get host-plist 'base) | 173 (plist-get host-plist 'base) |
84 (plist-get host-plist 'scope) | 174 (plist-get host-plist 'scope) |
85 attributes attrsonly)) | 175 attributes attrsonly)) |
86 (ldap-close ldap) | 176 (ldap-close ldap) |
87 res)) | 177 res)) |
88 | 178 |
89 | |
90 | 179 |
91 (provide 'ldap) | 180 (provide 'ldap) |
92 | 181 |
93 ;;; ldap.el ends here | 182 ;;; ldap.el ends here |