annotate modules/ldap/eldap.c @ 373:6240c7796c7a r21-2b2

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