annotate src/eldap.c @ 849:503b6a57cf47

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