annotate src/eldap.c @ 404:2f8bb876ab1d r21-2-32

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