annotate src/eldap.c @ 955:b7fa959034ca

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