annotate src/eldap.c @ 259:11cf20601dec r20-5b28

Import from CVS: tag r20-5b28
author cvs
date Mon, 13 Aug 2007 10:23:02 +0200
parents
children 405dd6d1825b
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 client interface for XEmacs.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2 Copyright (C) ***FIXME***
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4 This file is part of XEmacs.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
6 XEmacs is free software; you can redistribute it and/or modify it
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
7 under the terms of the GNU General Public License as published by the
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
8 Free Software Foundation; either version 2, or (at your option) any
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
9 later version.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
10
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
14 for more details.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
15
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
17 along with XEmacs; see the file COPYING. If not, write to
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
19 Boston, MA 02111-1307, USA. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
20
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
21 /* Synched up with: Not in FSF. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
22
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
23 /* Author: Oscar Figueiredo */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
24
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
25 /* This file provides lisp primitives for access to an LDAP library
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
26 conforming to the API defined in RFC 1823.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
27 It has been tested with:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
28 - UMich LDAP 3.3 (http://www.umich.edu/~dirsvcs/ldap/)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
29 - Netscape's LDAP SDK 1.0 (http://developer.netscape.com) */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
30
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
31
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
32
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
33 #include <config.h>
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
34
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
35 #if defined (HAVE_LDAP)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
36
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
37 /* The entire file is within this conditional */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
38
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
39 #include "lisp.h"
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
40
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
41 #include "eldap.h"
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
42 #include <lber.h>
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
43 #include <ldap.h>
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
44
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
45 #ifdef HAVE_NS_LDAP
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
46 #define HAVE_LDAP_SET_OPTION 1
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
47 #define HAVE_LDAP_GET_ERRNO 1
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
48 #else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
49 #undef HAVE_LDAP_SET_OPTION
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
50 #undef HAVE_LDAP_GET_ERRNO
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
51 #endif
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
52
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
53 static Lisp_Object Vldap_default_base;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
54 static Lisp_Object Vldap_default_host;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
55
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
56 /* ldap-search-internal plist keywords */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
57 static Lisp_Object Qhost, Qfilter, Qattributes, Qattrsonly, Qbase, Qscope,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
58 Qauth, Qbinddn, Qpasswd, Qderef, Qtimelimit, Qsizelimit;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
59 /* Search scope limits */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
60 static Lisp_Object Qbase, Qonelevel, Qsubtree;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
61 /* Authentication methods */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
62 static Lisp_Object Qsimple;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
63 #ifdef LDAP_AUTH_KRBV41
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
64 static Lisp_Object Qkrbv41;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
65 #endif
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
66 #ifdef LDAP_AUTH_KRBV42
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
67 static Lisp_Object Qkrbv42;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
68 #endif
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
69 /* Deref policy */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
70 static Lisp_Object Qnever, Qalways, Qsearch, Qfind;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
71
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
72 DEFUN ("ldap-search-internal", Fldap_search_internal, 1, 1, 0, /*
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
73 Perform a search on a LDAP server.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
74 SEARCH-PLIST is a property list describing the search request.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
75 Valid keys in that list are:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
76 `host' is a string naming one or more (blank separated) LDAP servers to
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
77 to try to connect to. Each host name may optionally be of the form host:port.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
78 `filter' is a filter string for the search as described in RFC 1558
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
79 `attributes' is a list of strings indicating which attributes to retrieve
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
80 for each matching entry. If nil return all available attributes.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
81 `attrsonly' if non-nil indicates that only the attributes are retrieved, not
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
82 the associated values.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
83 `base' is the base for the search as described in RFC 1779.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
84 `scope' is one of the three symbols `subtree', `base' or `onelevel'.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
85 `auth' is the authentication method to use, possible values depend on
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
86 the LDAP library XEmacs was compiled with: `simple', `krbv41' and `krbv42'.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
87 `binddn' is the distinguished name of the user to bind as (in RFC 1779 syntax).
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
88 `passwd' is the password to use for simple authentication.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
89 `deref' is one of the symbols `never', `always', `search' or `find'.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
90 `timelimit' is the timeout limit for the connection in seconds.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
91 `sizelimit' is the maximum number of matches to return.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
92 The function returns a list of matching entries. Each entry is itself
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
93 an alist of attribute/values.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
94 */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
95 (search_plist))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
96 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
97 /* This function calls lisp */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
98
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
99 /* Vars for query */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
100 LDAP *ld;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
101 LDAPMessage *res, *e;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
102 BerElement *ptr;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
103 char *a;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
104 int i, rc, err;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
105
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
106 char *ldap_host = NULL;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
107 char *ldap_filter = NULL;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
108 char **ldap_attributes = NULL;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
109 int ldap_attrsonly = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
110 char *ldap_base = NULL;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
111 int ldap_scope = LDAP_SCOPE_SUBTREE;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
112 int ldap_auth = LDAP_AUTH_SIMPLE;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
113 char *ldap_binddn = NULL;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
114 char *ldap_passwd = NULL;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
115 int ldap_deref = LDAP_DEREF_NEVER;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
116 int ldap_timelimit = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
117 int ldap_sizelimit = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
118
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
119 char **vals = NULL;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
120 int matches;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
121
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
122 Lisp_Object list, entry, result, keyword, value;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
123 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
124
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
125 list = entry = result = keyword = value = Qnil;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
126 GCPRO5 (list, entry, result, keyword, value);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
127
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
128
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
129 EXTERNAL_PROPERTY_LIST_LOOP(list, keyword, value, search_plist)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
130 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
131 /* Host */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
132 if (EQ (keyword, Qhost))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
133 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
134 CHECK_STRING (value);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
135 ldap_host = alloca (XSTRING_LENGTH (value) + 1);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
136 strcpy (ldap_host, (char *)XSTRING_DATA (value));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
137 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
138 /* Filter */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
139 else if (EQ (keyword, Qfilter))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
140 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
141 CHECK_STRING (value);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
142 ldap_filter = alloca (XSTRING_LENGTH (value) + 1);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
143 strcpy (ldap_filter, (char *)XSTRING_DATA (value));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
144 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
145 /* Attributes */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
146 else if (EQ (keyword, Qattributes))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
147 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
148 if (! NILP (value))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
149 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
150 Lisp_Object attr_left = value;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
151 struct gcpro ngcpro1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
152
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
153 NGCPRO1 (attr_left);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
154 CHECK_CONS (value);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
155
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
156 ldap_attributes = alloca ((XINT (Flength (value)) + 1)*sizeof (char *));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
157
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
158 for (i=0; !NILP (attr_left); i++) {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
159 CHECK_STRING (XCAR (attr_left));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
160 ldap_attributes[i] = alloca (XSTRING_LENGTH (XCAR (attr_left)) + 1);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
161 strcpy(ldap_attributes[i],
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
162 (char *)(XSTRING_DATA( XCAR (attr_left))));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
163 attr_left = XCDR (attr_left);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
164 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
165 ldap_attributes[i] = NULL;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
166 NUNGCPRO;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
167 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
168 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
169 /* Attributes Only */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
170 else if (EQ (keyword, Qattrsonly))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
171 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
172 CHECK_SYMBOL (value);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
173 ldap_attrsonly = NILP (value) ? 0 : 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
174 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
175 /* Base */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
176 else if (EQ (keyword, Qbase))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
177 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
178 if (!NILP (value))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
179 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
180 CHECK_STRING (value);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
181 ldap_base = alloca (XSTRING_LENGTH (value) + 1);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
182 strcpy (ldap_base, (char *)XSTRING_DATA (value));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
183 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
184 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
185 /* Scope */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
186 else if (EQ (keyword, Qscope))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
187 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
188 CHECK_SYMBOL (value);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
189
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
190 if (EQ (value, Qbase))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
191 ldap_scope = LDAP_SCOPE_BASE;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
192 else if (EQ (value, Qonelevel))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
193 ldap_scope = LDAP_SCOPE_ONELEVEL;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
194 else if (EQ (value, Qsubtree))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
195 ldap_scope = LDAP_SCOPE_SUBTREE;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
196 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
197 signal_simple_error ("Invalid scope", value);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
198 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
199 /* Authentication method */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
200 else if (EQ (keyword, Qauth))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
201 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
202 CHECK_SYMBOL (value);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
203
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
204 if (EQ (value, Qsimple))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
205 ldap_auth = LDAP_AUTH_SIMPLE;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
206 #ifdef LDAP_AUTH_KRBV41
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
207 else if (EQ (value, Qkrbv41))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
208 ldap_auth = LDAP_AUTH_KRBV41;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
209 #endif
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
210 #ifdef LDAP_AUTH_KRBV42
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
211 else if (EQ (value, Qkrbv42))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
212 ldap_auth = LDAP_AUTH_KRBV42;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
213 #endif
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
214 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
215 signal_simple_error ("Invalid authentication method", value);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
216 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
217 /* Bind DN */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
218 else if (EQ (keyword, Qbinddn))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
219 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
220 if (!NILP (value))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
221 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
222 CHECK_STRING (value);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
223 ldap_binddn = alloca (XSTRING_LENGTH (value) + 1);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
224 strcpy (ldap_binddn, (char *)XSTRING_DATA (value));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
225 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
226 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
227 /* Password */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
228 else if (EQ (keyword, Qpasswd))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
229 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
230 if (!NILP (value))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
231 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
232 CHECK_STRING (value);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
233 ldap_passwd = alloca (XSTRING_LENGTH (value) + 1);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
234 strcpy (ldap_passwd, (char *)XSTRING_DATA (value));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
235 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
236 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
237 /* Deref */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
238 else if (EQ (keyword, Qderef))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
239 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
240 CHECK_SYMBOL (value);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
241 if (EQ (value, Qnever))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
242 ldap_deref = LDAP_DEREF_NEVER;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
243 else if (EQ (value, Qsearch))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
244 ldap_deref = LDAP_DEREF_SEARCHING;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
245 else if (EQ (value, Qfind))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
246 ldap_deref = LDAP_DEREF_FINDING;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
247 else if (EQ (value, Qalways))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
248 ldap_deref = LDAP_DEREF_ALWAYS;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
249 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
250 signal_simple_error ("Invalid deref value", value);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
251 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
252 /* Timelimit */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
253 else if (EQ (keyword, Qtimelimit))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
254 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
255 if (!NILP (value))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
256 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
257 CHECK_INT (value);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
258 ldap_timelimit = XINT (value);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
259 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
260 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
261 /* Sizelimit */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
262 else if (EQ (keyword, Qsizelimit))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
263 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
264 if (!NILP (value))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
265 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
266 CHECK_INT (value);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
267 ldap_sizelimit = XINT (value);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
268 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
269 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
270 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
271
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
272 /* Use ldap-default-base if no default base was given */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
273 if (ldap_base == NULL && !NILP (Vldap_default_base))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
274 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
275 CHECK_STRING (Vldap_default_base);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
276 ldap_base = alloca (XSTRING_LENGTH (Vldap_default_base) + 1);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
277 strcpy (ldap_base, (char *)XSTRING_DATA (Vldap_default_base));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
278 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
279
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
280 /* Use ldap-default-host if no host was given */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
281 if (ldap_host == NULL && !NILP (Vldap_default_host))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
282 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
283 CHECK_STRING (Vldap_default_host);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
284 ldap_host = alloca (XSTRING_LENGTH (Vldap_default_host) + 1);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
285 strcpy (ldap_host, (char *)XSTRING_DATA (Vldap_default_host));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
286 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
287
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
288 if (ldap_filter == NULL)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
289 error ("Empty search filter");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
290
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
291 /* Garbage collect before connecting (if using UMich lib).
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
292 This is ugly, I know, but without this, the UMich LDAP library 3.3
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
293 frequently reports "Can't contact LDAP server". I really need to
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
294 check what happens inside that lib. Anyway this should be harmless to
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
295 XEmacs and makes things work. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
296 #if defined (HAVE_UMICH_LDAP)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
297 Fgarbage_collect ();
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
298 #endif
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
299
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
300 /* Connect to the server and bind */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
301 message ("Connecting to %s...", ldap_host);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
302 if ( (ld = ldap_open (ldap_host, LDAP_PORT)) == NULL )
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
303 signal_simple_error ("Failed connecting to host",
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
304 build_string (ldap_host));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
305
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
306 #if HAVE_LDAP_SET_OPTION
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
307 if (ldap_set_option (ld, LDAP_OPT_DEREF, (void *)&ldap_deref) != LDAP_SUCCESS)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
308 error ("Failed to set deref option");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
309 if (ldap_set_option (ld, LDAP_OPT_TIMELIMIT, (void *)&ldap_timelimit) != LDAP_SUCCESS)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
310 error ("Failed to set timelimit option");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
311 if (ldap_set_option (ld, LDAP_OPT_SIZELIMIT, (void *)&ldap_sizelimit) != LDAP_SUCCESS)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
312 error ("Failed to set sizelimit option");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
313 if (ldap_set_option (ld, LDAP_OPT_REFERRALS, LDAP_OPT_ON) != LDAP_SUCCESS)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
314 error ("Failed to set referral option");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
315 #else /* HAVE_LDAP_SET_OPTION */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
316 ld->ld_deref = ldap_deref;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
317 ld->ld_timelimit = ldap_timelimit;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
318 ld->ld_sizelimit = ldap_sizelimit;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
319 #ifdef LDAP_REFERRALS
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
320 ld->ld_options = LDAP_OPT_REFERRALS;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
321 #else /* LDAP_REFERRALS */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
322 ld->ld_options = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
323 #endif /* LDAP_REFERRALS */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
324 #endif /* HAVE_LDAP_SET_OPTION */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
325
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
326 message ("Binding to %s...", ldap_host);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
327 if ( (err = (ldap_bind_s (ld, ldap_binddn, ldap_passwd, ldap_auth ))) != LDAP_SUCCESS )
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
328 signal_simple_error ("Failed binding to the server",
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
329 build_string (ldap_err2string (err)));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
330
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
331 /* Perform the search */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
332 message ("Searching with LDAP on %s...", ldap_host);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
333 if ( ldap_search (ld, ldap_base, ldap_scope, ldap_filter,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
334 ldap_attributes, ldap_attrsonly) == -1)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
335 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
336 ldap_unbind (ld);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
337 #if HAVE_LDAP_GET_ERRNO
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
338 signal_simple_error ("Error during LDAP search",
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
339 build_string (ldap_err2string (ldap_get_lderrno (ld, NULL, NULL))));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
340 #else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
341 signal_simple_error ("Error during LDAP search",
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
342 build_string (ldap_err2string (ld->ld_errno)));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
343 #endif
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
344 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
345
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
346 /* Build the results list */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
347 matches = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
348
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
349 while ( (rc = ldap_result (ld, LDAP_RES_ANY, 0, NULL, &res))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
350 == LDAP_RES_SEARCH_ENTRY )
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
351 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
352 matches ++;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
353 e = ldap_first_entry (ld, res);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
354 message ("Parsing results... %d", matches);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
355 entry = Qnil;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
356 for (a= ldap_first_attribute (ld, e, &ptr);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
357 a != NULL;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
358 a= ldap_next_attribute (ld, e, ptr) )
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
359 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
360 list = Fcons (build_string (a), Qnil);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
361 vals = ldap_get_values (ld, e, a);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
362 if (vals != NULL)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
363 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
364 for (i=0; vals[i]!=NULL; i++)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
365 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
366 list = Fcons (build_string (vals[i]),
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
367 list);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
368 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
369 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
370 entry = Fcons (Fnreverse (list),
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
371 entry);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
372 ldap_value_free (vals);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
373 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
374 result = Fcons (Fnreverse (entry),
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
375 result);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
376 ldap_msgfree (res);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
377 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
378
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
379 if (rc == -1)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
380 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
381 #if HAVE_LDAP_GET_ERRNO
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
382 signal_simple_error ("Error retrieving result",
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
383 build_string (ldap_err2string (ldap_get_lderrno (ld, NULL, NULL))));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
384 #else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
385 signal_simple_error ("Error retrieving result",
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
386 build_string (ldap_err2string (ld->ld_errno)));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
387 #endif
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
388 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
389
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
390 if ((rc = ldap_result2error (ld, res, 0)) != LDAP_SUCCESS)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
391 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
392 #if HAVE_LDAP_GET_ERRNO
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
393 signal_simple_error ("Error on result",
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
394 build_string (ldap_err2string (ldap_get_lderrno (ld, NULL, NULL))));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
395 #else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
396 signal_simple_error ("Error on result",
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
397 build_string (ldap_err2string (ld->ld_errno)));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
398 #endif
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
399 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
400
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
401 ldap_msgfree (res);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
402 ldap_unbind (ld);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
403 message ("Done.");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
404
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
405 result = Fnreverse (result);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
406 clear_message ();
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
407
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
408 UNGCPRO;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
409 return result;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
410 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
411
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
412
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
413 void
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
414 syms_of_eldap (void)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
415 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
416 DEFSUBR(Fldap_search_internal);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
417
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
418 defsymbol (&Qhost, "host");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
419 defsymbol (&Qfilter, "filter");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
420 defsymbol (&Qattributes, "attributes");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
421 defsymbol (&Qattrsonly, "attrsonly");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
422 defsymbol (&Qbase, "base");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
423 defsymbol (&Qscope, "scope");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
424 defsymbol (&Qauth, "auth");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
425 defsymbol (&Qbinddn, "binddn");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
426 defsymbol (&Qpasswd, "passwd");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
427 defsymbol (&Qderef, "deref");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
428 defsymbol (&Qtimelimit, "timelimit");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
429 defsymbol (&Qsizelimit, "sizelimit");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
430 defsymbol (&Qbase, "base");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
431 defsymbol (&Qonelevel, "onelevel");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
432 defsymbol (&Qsubtree, "subtree");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
433 defsymbol (&Qsimple, "simple");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
434 #ifdef LDAP_AUTH_KRBV41
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
435 defsymbol (&Qkrbv41, "krbv41");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
436 #endif
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
437 #ifdef LDAP_AUTH_KRBV42
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
438 defsymbol (&Qkrbv42, "krbv42");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
439 #endif
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
440 defsymbol (&Qnever, "never");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
441 defsymbol (&Qalways, "always");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
442 defsymbol (&Qsearch, "search");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
443 defsymbol (&Qfind, "find");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
444 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
445
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
446 void
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
447 vars_of_eldap (void)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
448 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
449 Fprovide (intern ("ldap-internal"));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
450
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
451 DEFVAR_LISP ("ldap-default-host", &Vldap_default_host /*
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
452 Default LDAP host.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
453 */ );
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
454
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
455 DEFVAR_LISP ("ldap-default-base", &Vldap_default_base /*
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
456 Default base for LDAP searches.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
457 This is a string using the syntax of RFC 1779.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
458 For instance, "o=ACME, c=US" limits the search to the
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
459 Acme organization in the United States.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
460 */ );
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
461
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
462 Vldap_default_host = Qnil;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
463 Vldap_default_base = Qnil;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
464 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
465
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
466 #endif /* HAVE_LDAP */