annotate src/eldap.c @ 877:e54d47b2d736

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