annotate src/eldap.c @ 446:1ccc32a20af4 r21-2-38

Import from CVS: tag r21-2-38
author cvs
date Mon, 13 Aug 2007 11:37:21 +0200
parents 576fb035e263
children c33ae14dd6d0
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 with lots of support from Hrvoje Niksic */
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 - OpenLDAP 1.2 (http://www.openldap.org/)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30 - Netscape's LDAP SDK (http://developer.netscape.com/) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31
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 #include <config.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34 #include "lisp.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35 #include "opaque.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
36 #include "sysdep.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37 #include "buffer.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39 #include <errno.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41 #include "eldap.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43 static int ldap_default_port;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 static Lisp_Object Vldap_default_base;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46 /* Needed by the lrecord definition */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47 Lisp_Object Qldapp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49 /* ldap-open plist keywords */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50 static Lisp_Object Qport, Qauth, Qbinddn, Qpasswd, Qderef, Qtimelimit, Qsizelimit;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51 /* Search scope limits */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52 static Lisp_Object Qbase, Qonelevel, Qsubtree;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53 /* Authentication methods */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54 static Lisp_Object Qkrbv41, Qkrbv42;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55 /* Deref policy */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 static Lisp_Object Qnever, Qalways, Qfind;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
57 /* Modification types (Qdelete is defined in general.c) */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
58 static Lisp_Object Qadd, Qreplace;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
59
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 /* Utility Functions */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66 signal_ldap_error (LDAP *ld, LDAPMessage *res, int ldap_err)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 if (ldap_err <= 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 #if defined HAVE_LDAP_PARSE_RESULT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 int err;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72 ldap_err = ldap_parse_result (ld, res,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73 &err,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74 NULL, NULL, NULL, NULL, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 if (ldap_err == LDAP_SUCCESS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76 ldap_err = err;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77 #elif defined HAVE_LDAP_GET_LDERRNO
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78 ldap_err = ldap_get_lderrno (ld, NULL, NULL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 #elif defined HAVE_LDAP_RESULT2ERROR
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80 ldap_err = ldap_result2error (ld, res, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82 ldap_err = ld->ld_errno;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85 signal_simple_error ("LDAP error",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86 build_string (ldap_err2string (ldap_err)));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87 }
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
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 /* ldap lrecord basic functions */
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94 static Lisp_Object
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
95 make_ldap (Lisp_LDAP *ldap)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97 Lisp_Object lisp_ldap;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98 XSETLDAP (lisp_ldap, ldap);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99 return lisp_ldap;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 static Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103 mark_ldap (Lisp_Object obj)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105 return XLDAP (obj)->host;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109 print_ldap (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111 char buf[32];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
113 Lisp_LDAP *ldap = XLDAP (obj);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115 if (print_readably)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116 error ("printing unreadable object #<ldap %s>",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117 XSTRING_DATA (ldap->host));
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 write_c_string ("#<ldap ", printcharfun);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120 print_internal (ldap->host, printcharfun, 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121 if (!ldap->ld)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122 write_c_string ("(dead) ",printcharfun);
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
123 sprintf (buf, " 0x%lx>", (long)ldap);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124 write_c_string (buf, printcharfun);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
127 static Lisp_LDAP *
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128 allocate_ldap (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129 {
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
130 Lisp_LDAP *ldap = alloc_lcrecord_type (Lisp_LDAP, &lrecord_ldap);
428
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 ldap->ld = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
133 ldap->host = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134 return ldap;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138 finalize_ldap (void *header, int for_disksave)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139 {
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
140 Lisp_LDAP *ldap = (Lisp_LDAP *) header;
428
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 (for_disksave)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143 signal_simple_error ("Can't dump an emacs containing LDAP objects",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144 make_ldap (ldap));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
145
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
146 if (ldap->ld)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
147 ldap_unbind (ldap->ld);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
148 ldap->ld = NULL;
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
151 DEFINE_LRECORD_IMPLEMENTATION ("ldap", ldap,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
152 mark_ldap, print_ldap, finalize_ldap,
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
153 NULL, NULL, 0, Lisp_LDAP);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157
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 /* Basic ldap accessors */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160 /************************************************************************/
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 DEFUN ("ldapp", Fldapp, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 Return t if OBJECT is a LDAP connection.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167 return LDAPP (object) ? Qt : Qnil;
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170 DEFUN ("ldap-host", Fldap_host, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171 Return the server host of the connection LDAP, as a string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173 (ldap))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175 CHECK_LDAP (ldap);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176 return (XLDAP (ldap))->host;
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 DEFUN ("ldap-live-p", Fldap_status, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180 Return t if LDAP is an active LDAP connection.
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 (ldap))
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 CHECK_LDAP (ldap);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185 return (XLDAP (ldap))->ld ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189 /* Opening/Closing a LDAP connection */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191
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 DEFUN ("ldap-open", Fldap_open, 1, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194 Open a LDAP connection to HOST.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195 PLIST is a plist containing additional parameters for the connection.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196 Valid keys in that list are:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
197 `port' the TCP port to use for the connection if different from
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198 `ldap-default-port'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199 `auth' is the authentication method to use, possible values depend on
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200 the LDAP library XEmacs was compiled with: `simple', `krbv41' and `krbv42'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
201 `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
202 `passwd' is the password to use for simple authentication.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203 `deref' is one of the symbols `never', `always', `search' or `find'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204 `timelimit' is the timeout limit for the connection in seconds.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205 `sizelimit' is the maximum number of matches to return.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207 (host, plist))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209 /* This function can GC */
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
210 Lisp_LDAP *ldap;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211 LDAP *ld;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212 int ldap_port = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213 int ldap_auth = LDAP_AUTH_SIMPLE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214 char *ldap_binddn = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215 char *ldap_passwd = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216 int ldap_deref = LDAP_DEREF_NEVER;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
217 int ldap_timelimit = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218 int ldap_sizelimit = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219 int err;
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 CHECK_STRING (host);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
223 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
224 EXTERNAL_PROPERTY_LIST_LOOP_3 (keyword, value, plist)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
225 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
226 /* TCP Port */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
227 if (EQ (keyword, Qport))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
228 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
229 CHECK_INT (value);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
230 ldap_port = XINT (value);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
231 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
232 /* Authentication method */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
233 if (EQ (keyword, Qauth))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
234 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
235 if (EQ (value, Qsimple))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
236 ldap_auth = LDAP_AUTH_SIMPLE;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 #ifdef LDAP_AUTH_KRBV41
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
238 else if (EQ (value, Qkrbv41))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
239 ldap_auth = LDAP_AUTH_KRBV41;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241 #ifdef LDAP_AUTH_KRBV42
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
242 else if (EQ (value, Qkrbv42))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
243 ldap_auth = LDAP_AUTH_KRBV42;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244 #endif
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
245 else
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
246 signal_simple_error ("Invalid authentication method", value);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
247 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
248 /* Bind DN */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
249 else if (EQ (keyword, Qbinddn))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
250 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
251 CHECK_STRING (value);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
252 LISP_STRING_TO_EXTERNAL (value, ldap_binddn, Qnative);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
253 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
254 /* Password */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
255 else if (EQ (keyword, Qpasswd))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
256 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
257 CHECK_STRING (value);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
258 LISP_STRING_TO_EXTERNAL (value, ldap_passwd, Qnative);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
259 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
260 /* Deref */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
261 else if (EQ (keyword, Qderef))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
262 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
263 if (EQ (value, Qnever))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
264 ldap_deref = LDAP_DEREF_NEVER;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
265 else if (EQ (value, Qsearch))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
266 ldap_deref = LDAP_DEREF_SEARCHING;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
267 else if (EQ (value, Qfind))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
268 ldap_deref = LDAP_DEREF_FINDING;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
269 else if (EQ (value, Qalways))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
270 ldap_deref = LDAP_DEREF_ALWAYS;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
271 else
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
272 signal_simple_error ("Invalid deref value", value);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
273 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
274 /* Timelimit */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
275 else if (EQ (keyword, Qtimelimit))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
276 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
277 CHECK_INT (value);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
278 ldap_timelimit = XINT (value);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
279 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
280 /* Sizelimit */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
281 else if (EQ (keyword, Qsizelimit))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
282 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
283 CHECK_INT (value);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
284 ldap_sizelimit = XINT (value);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
285 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
286 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
287 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289 if (ldap_port == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291 ldap_port = ldap_default_port;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292 }
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 slow_down_interrupts ();
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
296 ld = ldap_open ((char *) XSTRING_DATA (host), ldap_port);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297 speed_up_interrupts ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299 if (ld == NULL )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
300 signal_simple_error_2 ("Failed connecting to host",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
301 host,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
302 lisp_strerror (errno));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305 #ifdef HAVE_LDAP_SET_OPTION
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306 if ((err = ldap_set_option (ld, LDAP_OPT_DEREF,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
307 (void *)&ldap_deref)) != LDAP_SUCCESS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
308 signal_ldap_error (ld, NULL, err);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309 if ((err = ldap_set_option (ld, LDAP_OPT_TIMELIMIT,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
310 (void *)&ldap_timelimit)) != LDAP_SUCCESS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
311 signal_ldap_error (ld, NULL, err);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312 if ((err = ldap_set_option (ld, LDAP_OPT_SIZELIMIT,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
313 (void *)&ldap_sizelimit)) != LDAP_SUCCESS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
314 signal_ldap_error (ld, NULL, err);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
315 if ((err = ldap_set_option (ld, LDAP_OPT_REFERRALS,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
316 LDAP_OPT_ON)) != LDAP_SUCCESS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
317 signal_ldap_error (ld, NULL, err);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
318 if ((err = ldap_set_option (ld, LDAP_OPT_RESTART,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
319 LDAP_OPT_ON)) != LDAP_SUCCESS)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
320 signal_ldap_error (ld, NULL, err);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
321 #else /* not HAVE_LDAP_SET_OPTION */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
322 ld->ld_deref = ldap_deref;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
323 ld->ld_timelimit = ldap_timelimit;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324 ld->ld_sizelimit = ldap_sizelimit;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325 #ifdef LDAP_REFERRALS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326 ld->ld_options = LDAP_OPT_REFERRALS;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327 #else /* not LDAP_REFERRALS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328 ld->ld_options = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329 #endif /* not LDAP_REFERRALS */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
330 /* XEmacs uses interrupts (SIGIO,SIGALRM), LDAP calls need to ignore them */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
331 ld->ld_options |= LDAP_OPT_RESTART;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332 #endif /* not HAVE_LDAP_SET_OPTION */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334 err = ldap_bind_s (ld, ldap_binddn, ldap_passwd, ldap_auth);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335 if (err != LDAP_SUCCESS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
336 signal_simple_error ("Failed binding to the server",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337 build_string (ldap_err2string (err)));
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 ldap = allocate_ldap ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340 ldap->ld = ld;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341 ldap->host = host;
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 return make_ldap (ldap);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
344 }
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348 DEFUN ("ldap-close", Fldap_close, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
349 Close an LDAP connection.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
351 (ldap))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352 {
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
353 Lisp_LDAP *lldap;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
354 CHECK_LIVE_LDAP (ldap);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
355 lldap = XLDAP (ldap);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
356 ldap_unbind (lldap->ld);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
357 lldap->ld = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
358 return Qnil;
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
361
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 /* Working on a LDAP connection */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
365 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
366 struct ldap_unwind_struct
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 LDAPMessage *res;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
369 struct berval **vals;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
370 };
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 static Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
373 ldap_search_unwind (Lisp_Object unwind_obj)
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 struct ldap_unwind_struct *unwind =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
376 (struct ldap_unwind_struct *) get_opaque_ptr (unwind_obj);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
377 if (unwind->res)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
378 ldap_msgfree (unwind->res);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
379 if (unwind->vals)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
380 ldap_value_free_len (unwind->vals);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
381 return Qnil;
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
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
384 /* The following function is called `ldap-search-basic' instead of */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
385 /* plain `ldap-search' to maintain compatibility with the XEmacs 21.1 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
386 /* API where `ldap-search' was the name of the high-level search */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
387 /* function */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
388
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
389 DEFUN ("ldap-search-basic", Fldap_search_basic, 2, 8, 0, /*
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
390 Perform a search on an open LDAP connection.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391 LDAP is an LDAP connection object created with `ldap-open'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
392 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
393 BASE is the distinguished name at which to start the search.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
394 SCOPE is one of the symbols `base', `onelevel' or `subtree' indicating
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
395 the scope of the search.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
396 ATTRS is a list of strings indicating which attributes to retrieve
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
397 for each matching entry. If nil return all available attributes.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
398 If ATTRSONLY is non-nil then only the attributes are retrieved, not
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
399 the associated values.
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
400 If WITHDN is non-nil each entry in the result will be prepended with
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
401 its distinguished name DN.
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
402 If VERBOSE is non-nil progress messages will be echoed.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
403 The function returns a list of matching entries. Each entry is itself
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
404 an alist of attribute/value pairs optionally preceded by the DN of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
405 entry according to the value of WITHDN.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
406 */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
407 (ldap, filter, base, scope, attrs, attrsonly, withdn, verbose))
428
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 /* This function can GC */
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 /* Vars for query */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
412 LDAP *ld;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
413 LDAPMessage *e;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
414 BerElement *ptr;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
415 char *a, *dn;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
416 int i, rc;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
417 int matches;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
418 struct ldap_unwind_struct unwind;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
419
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
420 int ldap_scope = LDAP_SCOPE_SUBTREE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
421 char **ldap_attributes = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
422
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
423 int speccount = specpdl_depth ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
424
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
425 Lisp_Object list = Qnil;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
426 Lisp_Object entry = Qnil;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
427 Lisp_Object result = Qnil;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
428 struct gcpro gcpro1, gcpro2, gcpro3;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
429
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
430 GCPRO3 (list, entry, result);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
431
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
432 unwind.res = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
433 unwind.vals = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
434
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
435 /* Do all the parameter checking */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
436 CHECK_LIVE_LDAP (ldap);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
437 ld = XLDAP (ldap)->ld;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
438
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
439 /* Filter */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
440 CHECK_STRING (filter);
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 /* Search base */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
443 if (NILP (base))
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 base = Vldap_default_base;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
446 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
447 if (!NILP (base))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
448 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
449 CHECK_STRING (base);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
450 }
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 /* Search scope */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
453 if (!NILP (scope))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
454 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
455 if (EQ (scope, Qbase))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
456 ldap_scope = LDAP_SCOPE_BASE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
457 else if (EQ (scope, Qonelevel))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
458 ldap_scope = LDAP_SCOPE_ONELEVEL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
459 else if (EQ (scope, Qsubtree))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
460 ldap_scope = LDAP_SCOPE_SUBTREE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
461 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
462 signal_simple_error ("Invalid scope", scope);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
463 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
464
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
465 /* Attributes to search */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
466 if (!NILP (attrs))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
467 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
468 CHECK_CONS (attrs);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
469 ldap_attributes = alloca_array (char *, 1 + XINT (Flength (attrs)));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
470
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
471 i = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
472 EXTERNAL_LIST_LOOP (attrs, attrs)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
473 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
474 Lisp_Object current = XCAR (attrs);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
475 CHECK_STRING (current);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
476 LISP_STRING_TO_EXTERNAL (current, ldap_attributes[i], Qnative);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
477 ++i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
478 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
479 ldap_attributes[i] = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
480 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
481
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
482 /* Attributes only ? */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
483 CHECK_SYMBOL (attrsonly);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
484
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
485 /* Perform the search */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
486 if (ldap_search (ld,
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
487 NILP (base) ? (char *) "" : (char *) XSTRING_DATA (base),
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
488 ldap_scope,
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
489 NILP (filter) ? (char *) "" : (char *) XSTRING_DATA (filter),
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
490 ldap_attributes,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
491 NILP (attrsonly) ? 0 : 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
492 == -1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
493 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
494 signal_ldap_error (ld, NULL, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
495 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
496
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
497 /* Ensure we don't exit without cleaning up */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
498 record_unwind_protect (ldap_search_unwind,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
499 make_opaque_ptr (&unwind));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
500
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
501 /* Build the results list */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
502 matches = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
503
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
504 rc = ldap_result (ld, LDAP_RES_ANY, 0, NULL, &unwind.res);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
505
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
506 while (rc == LDAP_RES_SEARCH_ENTRY)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
507 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
508 QUIT;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
509 matches ++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
510 e = ldap_first_entry (ld, unwind.res);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
511 /* #### This call to message() is pretty fascist, because it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
512 destroys the current echo area contents, even when invoked
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
513 from Lisp. It should use echo_area_message() instead, and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
514 restore the old echo area contents later. */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
515 if (! NILP (verbose))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
516 message ("Parsing ldap results... %d", matches);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
517 entry = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
518 /* Get the DN if required */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
519 if (! NILP (withdn))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
520 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
521 dn = ldap_get_dn (ld, e);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
522 if (dn == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
523 signal_ldap_error (ld, e, 0);
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
524 entry = Fcons (build_ext_string (dn, Qnative), Qnil);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
525 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
526 for (a= ldap_first_attribute (ld, e, &ptr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
527 a != NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
528 a = ldap_next_attribute (ld, e, ptr) )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
529 {
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
530 list = Fcons (build_ext_string (a, Qnative), Qnil);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
531 unwind.vals = ldap_get_values_len (ld, e, a);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
532 if (unwind.vals != NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
533 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
534 for (i = 0; unwind.vals[i] != NULL; i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
535 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
536 list = Fcons (make_ext_string ((Extbyte *) unwind.vals[i]->bv_val,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
537 unwind.vals[i]->bv_len,
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
538 Qnative),
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
539 list);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
540 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
541 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
542 entry = Fcons (Fnreverse (list),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
543 entry);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
544 ldap_value_free_len (unwind.vals);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
545 unwind.vals = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
546 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
547 result = Fcons (Fnreverse (entry),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
548 result);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
549 ldap_msgfree (unwind.res);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
550 unwind.res = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
551
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
552 rc = ldap_result (ld, LDAP_RES_ANY, 0, NULL, &(unwind.res));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
553 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
554
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
555 #if defined HAVE_LDAP_PARSE_RESULT
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
556 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
557 int rc2 = ldap_parse_result (ld, unwind.res,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
558 &rc,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
559 NULL, NULL, NULL, NULL, 0);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
560 if (rc2 != LDAP_SUCCESS)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
561 rc = rc2;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
562 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
563 #else
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
564 if (rc == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
565 signal_ldap_error (ld, NULL, LDAP_TIMELIMIT_EXCEEDED);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
566
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
567 if (rc == -1)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
568 signal_ldap_error (ld, unwind.res, (unwind.res==NULL) ? ld->ld_errno : 0);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
569
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
570 #if defined HAVE_LDAP_RESULT2ERROR
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
571 rc = ldap_result2error (ld, unwind.res, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
572 #endif
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
573 #endif
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
574
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
575 if (rc != LDAP_SUCCESS)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
576 signal_ldap_error (ld, NULL, rc);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
577
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
578 ldap_msgfree (unwind.res);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
579 unwind.res = (LDAPMessage *)NULL;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
580
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
581 /* #### See above for calling message(). */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
582 if (! NILP (verbose))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
583 message ("Parsing ldap results... done");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
584
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
585 unbind_to (speccount, Qnil);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
586 UNGCPRO;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
587 return Fnreverse (result);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
588 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
589
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
590 DEFUN ("ldap-add", Fldap_add, 3, 3, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
591 Add an entry to an LDAP directory.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
592 LDAP is an LDAP connection object created with `ldap-open'.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
593 DN is the distinguished name of the entry to add.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
594 ENTRY is an entry specification, i.e., a list of cons cells
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
595 containing attribute/value string pairs.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
596 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
597 (ldap, dn, entry))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
598 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
599 LDAP *ld;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
600 LDAPMod *ldap_mods, **ldap_mods_ptrs;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
601 struct berval *bervals;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
602 int rc;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
603 int i, j;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
604 size_t len;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
605
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
606 Lisp_Object current = Qnil;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
607 Lisp_Object values = Qnil;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
608 struct gcpro gcpro1, gcpro2;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
609
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
610 GCPRO2 (current, values);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
611
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
612 /* Do all the parameter checking */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
613 CHECK_LIVE_LDAP (ldap);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
614 ld = XLDAP (ldap)->ld;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
615
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
616 /* Check the DN */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
617 CHECK_STRING (dn);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
618
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
619 /* Check the entry */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
620 CHECK_CONS (entry);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
621 if (NILP (entry))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
622 signal_simple_error ("Cannot add void entry", entry);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
623
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
624 /* Build the ldap_mods array */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
625 len = XINT (Flength (entry));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
626 ldap_mods = alloca_array (LDAPMod, len);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
627 ldap_mods_ptrs = alloca_array (LDAPMod *, 1 + len);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
628 i = 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
629 EXTERNAL_LIST_LOOP (entry, entry)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
630 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
631 current = XCAR (entry);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
632 CHECK_CONS (current);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
633 CHECK_STRING (XCAR (current));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
634 ldap_mods_ptrs[i] = &(ldap_mods[i]);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
635 LISP_STRING_TO_EXTERNAL (XCAR (current), ldap_mods[i].mod_type, Qnative);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
636 ldap_mods[i].mod_op = LDAP_MOD_ADD | LDAP_MOD_BVALUES;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
637 values = XCDR (current);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
638 if (CONSP (values))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
639 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
640 len = XINT (Flength (values));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
641 bervals = alloca_array (struct berval, len);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
642 ldap_mods[i].mod_vals.modv_bvals =
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
643 alloca_array (struct berval *, 1 + len);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
644 j = 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
645 EXTERNAL_LIST_LOOP (values, values)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
646 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
647 current = XCAR (values);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
648 CHECK_STRING (current);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
649 ldap_mods[i].mod_vals.modv_bvals[j] = &(bervals[j]);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
650 TO_EXTERNAL_FORMAT (LISP_STRING, current,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
651 ALLOCA, (bervals[j].bv_val,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
652 bervals[j].bv_len),
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
653 Qnative);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
654 j++;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
655 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
656 ldap_mods[i].mod_vals.modv_bvals[j] = NULL;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
657 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
658 else
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
659 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
660 CHECK_STRING (values);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
661 bervals = alloca_array (struct berval, 1);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
662 ldap_mods[i].mod_vals.modv_bvals = alloca_array (struct berval *, 2);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
663 ldap_mods[i].mod_vals.modv_bvals[0] = &(bervals[0]);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
664 TO_EXTERNAL_FORMAT (LISP_STRING, values,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
665 ALLOCA, (bervals[0].bv_val,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
666 bervals[0].bv_len),
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
667 Qnative);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
668 ldap_mods[i].mod_vals.modv_bvals[1] = NULL;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
669 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
670 i++;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
671 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
672 ldap_mods_ptrs[i] = NULL;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
673 rc = ldap_add_s (ld, (char *) XSTRING_DATA (dn), ldap_mods_ptrs);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
674 if (rc != LDAP_SUCCESS)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
675 signal_ldap_error (ld, NULL, rc);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
676
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
677 UNGCPRO;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
678 return Qnil;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
679 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
680
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
681 DEFUN ("ldap-modify", Fldap_modify, 3, 3, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
682 Add an entry to an LDAP directory.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
683 LDAP is an LDAP connection object created with `ldap-open'.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
684 DN is the distinguished name of the entry to modify.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
685 MODS is a list of modifications to apply.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
686 A modification is a list of the form (MOD-OP ATTR VALUE1 VALUE2 ...)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
687 MOD-OP and ATTR are mandatory, VALUEs are optional depending on MOD-OP.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
688 MOD-OP is the type of modification, one of the symbols `add', `delete'
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
689 or `replace'. ATTR is the LDAP attribute type to modify.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
690 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
691 (ldap, dn, mods))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
692 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
693 LDAP *ld;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
694 LDAPMod *ldap_mods, **ldap_mods_ptrs;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
695 struct berval *bervals;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
696 int i, j, rc;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
697 Lisp_Object mod_op;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
698 size_t len;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
699
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
700 Lisp_Object current = Qnil;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
701 Lisp_Object values = Qnil;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
702 struct gcpro gcpro1, gcpro2;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
703
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
704 /* Do all the parameter checking */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
705 CHECK_LIVE_LDAP (ldap);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
706 ld = XLDAP (ldap)->ld;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
707
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
708 /* Check the DN */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
709 CHECK_STRING (dn);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
710
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
711 /* Check the entry */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
712 CHECK_CONS (mods);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
713 if (NILP (mods))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
714 return Qnil;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
715
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
716 /* Build the ldap_mods array */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
717 len = XINT (Flength (mods));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
718 ldap_mods = alloca_array (LDAPMod, len);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
719 ldap_mods_ptrs = alloca_array (LDAPMod *, 1 + len);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
720 i = 0;
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
721
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
722 GCPRO2 (current, values);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
723 EXTERNAL_LIST_LOOP (mods, mods)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
724 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
725 current = XCAR (mods);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
726 CHECK_CONS (current);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
727 CHECK_SYMBOL (XCAR (current));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
728 mod_op = XCAR (current);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
729 ldap_mods_ptrs[i] = &(ldap_mods[i]);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
730 ldap_mods[i].mod_op = LDAP_MOD_BVALUES;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
731 if (EQ (mod_op, Qadd))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
732 ldap_mods[i].mod_op |= LDAP_MOD_ADD;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
733 else if (EQ (mod_op, Qdelete))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
734 ldap_mods[i].mod_op |= LDAP_MOD_DELETE;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
735 else if (EQ (mod_op, Qreplace))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
736 ldap_mods[i].mod_op |= LDAP_MOD_REPLACE;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
737 else
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
738 signal_simple_error ("Invalid LDAP modification type", mod_op);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
739 current = XCDR (current);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
740 CHECK_STRING (XCAR (current));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
741 LISP_STRING_TO_EXTERNAL (XCAR (current), ldap_mods[i].mod_type, Qnative);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
742 values = XCDR (current);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
743 len = XINT (Flength (values));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
744 bervals = alloca_array (struct berval, len);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
745 ldap_mods[i].mod_vals.modv_bvals =
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
746 alloca_array (struct berval *, 1 + len);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
747 j = 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
748 EXTERNAL_LIST_LOOP (values, values)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
749 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
750 current = XCAR (values);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
751 CHECK_STRING (current);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
752 ldap_mods[i].mod_vals.modv_bvals[j] = &(bervals[j]);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
753 TO_EXTERNAL_FORMAT (LISP_STRING, current,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
754 ALLOCA, (bervals[j].bv_val,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
755 bervals[j].bv_len),
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
756 Qnative);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
757 j++;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
758 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
759 ldap_mods[i].mod_vals.modv_bvals[j] = NULL;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
760 i++;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
761 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
762 ldap_mods_ptrs[i] = NULL;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
763 rc = ldap_modify_s (ld, (char *) XSTRING_DATA (dn), ldap_mods_ptrs);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
764 if (rc != LDAP_SUCCESS)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
765 signal_ldap_error (ld, NULL, rc);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
766
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
767 UNGCPRO;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
768 return Qnil;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
769 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
770
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
771
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
772 DEFUN ("ldap-delete", Fldap_delete, 2, 2, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
773 Delete an entry to an LDAP directory.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
774 LDAP is an LDAP connection object created with `ldap-open'.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
775 DN is the distinguished name of the entry to delete.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
776 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
777 (ldap, dn))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
778 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
779 LDAP *ld;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
780 int rc;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
781
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
782 /* Check parameters */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
783 CHECK_LIVE_LDAP (ldap);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
784 ld = XLDAP (ldap)->ld;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
785 CHECK_STRING (dn);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
786
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
787 rc = ldap_delete_s (ld, (char *) XSTRING_DATA (dn));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
788 if (rc != LDAP_SUCCESS)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
789 signal_ldap_error (ld, NULL, rc);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
790
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
791 return Qnil;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
792 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
793
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
794 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
795 syms_of_eldap (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
796 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
797 INIT_LRECORD_IMPLEMENTATION (ldap);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
798
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
799 defsymbol (&Qldapp, "ldapp");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
800 defsymbol (&Qport, "port");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
801 defsymbol (&Qauth, "auth");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
802 defsymbol (&Qbinddn, "binddn");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
803 defsymbol (&Qpasswd, "passwd");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
804 defsymbol (&Qderef, "deref");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
805 defsymbol (&Qtimelimit, "timelimit");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
806 defsymbol (&Qsizelimit, "sizelimit");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
807 defsymbol (&Qbase, "base");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
808 defsymbol (&Qonelevel, "onelevel");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
809 defsymbol (&Qsubtree, "subtree");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
810 defsymbol (&Qkrbv41, "krbv41");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
811 defsymbol (&Qkrbv42, "krbv42");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
812 defsymbol (&Qnever, "never");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
813 defsymbol (&Qalways, "always");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
814 defsymbol (&Qfind, "find");
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
815 defsymbol (&Qadd, "add");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
816 defsymbol (&Qreplace, "replace");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
817
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
818 DEFSUBR (Fldapp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
819 DEFSUBR (Fldap_host);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
820 DEFSUBR (Fldap_status);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
821 DEFSUBR (Fldap_open);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
822 DEFSUBR (Fldap_close);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
823 DEFSUBR (Fldap_search_basic);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
824 DEFSUBR (Fldap_add);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
825 DEFSUBR (Fldap_modify);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
826 DEFSUBR (Fldap_delete);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
827 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
828
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
829 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
830 vars_of_eldap (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
831 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
832
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
833 ldap_default_port = LDAP_PORT;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
834 Vldap_default_base = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
835
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
836 DEFVAR_INT ("ldap-default-port", &ldap_default_port /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
837 Default TCP port for LDAP connections.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
838 Initialized from the LDAP library. Default value is 389.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
839 */ );
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
840
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
841 DEFVAR_LISP ("ldap-default-base", &Vldap_default_base /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
842 Default base for LDAP searches.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
843 This is a string using the syntax of RFC 1779.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
844 For instance, "o=ACME, c=US" limits the search to the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
845 Acme organization in the United States.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
846 */ );
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
847
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
848 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
849
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
850