annotate modules/ldap/eldap.c @ 616:4f1c7a4ac1e6

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