annotate modules/ldap/eldap.c @ 996:25e260cb7994

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