annotate modules/ldap/eldap.c @ 5602:c9e5612f5424

Support the MP library on recent FreeBSD, have it pass relevant tests. src/ChangeLog addition: 2011-11-26 Aidan Kehoe <kehoea@parhasard.net> * number-mp.c (bignum_to_string): Don't overwrite the accumulator we've just set up for this function. * number-mp.c (BIGNUM_TO_TYPE): mp_itom() doesn't necessarily do what this code used to think with negative numbers, it can treat them as unsigned ints. Subtract numbers from bignum_zero instead of multiplying them by -1 to convert them to their negative equivalents. * number-mp.c (bignum_to_int): * number-mp.c (bignum_to_uint): * number-mp.c (bignum_to_long): * number-mp.c (bignum_to_ulong): * number-mp.c (bignum_to_double): Use the changed BIGNUM_TO_TYPE() in these functions. * number-mp.c (bignum_ceil): * number-mp.c (bignum_floor): In these functions, be more careful about rounding to positive and negative infinity, respectively. Don't use the sign of QUOTIENT when working out out whether to add or subtract one, rather use the sign QUOTIENT would have if arbitrary-precision division were done. * number-mp.h: * number-mp.h (MP_GCD): Wrap #include <mp.h> in BEGIN_C_DECLS/END_C_DECLS. * number.c (Fbigfloat_get_precision): * number.c (Fbigfloat_set_precision): Don't attempt to call XBIGFLOAT_GET_PREC if this build doesn't support big floats.
author Aidan Kehoe <kehoea@parhasard.net>
date Sat, 26 Nov 2011 17:59:14 +0000
parents 56144c8593a8
children
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.
5125
Ben Wing <ben@xemacs.org>
parents: 5120 4981
diff changeset
3 Copyright (C) 2004, 2005, 2010 Ben Wing.
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
4
428
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 This file is part of XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7
5402
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5142
diff changeset
8 XEmacs is free software: you can redistribute it and/or modify it
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9 under the terms of the GNU General Public License as published by the
5402
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5142
diff changeset
10 Free Software Foundation, either version 3 of the License, or (at your
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5142
diff changeset
11 option) any later version.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
12
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13 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
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16 for more details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
5402
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5142
diff changeset
19 along with XEmacs. If not, see <http://www.gnu.org/licenses/>. */
428
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 */
1632
64eaceca611d [xemacs-hg @ 2003-08-19 02:07:03 by james]
james
parents: 1270
diff changeset
39 #ifdef HAVE_SHLIB
64eaceca611d [xemacs-hg @ 2003-08-19 02:07:03 by james]
james
parents: 1270
diff changeset
40 # include "emodules.h"
64eaceca611d [xemacs-hg @ 2003-08-19 02:07:03 by james]
james
parents: 1270
diff changeset
41 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
43 #include <errno.h>
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45 #include "eldap.h"
996
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 Fixnum ldap_default_port;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
48 static Lisp_Object Vldap_default_base;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
49
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
50 static Lisp_Object Qeldap;
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 /* Needed by the lrecord definition */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
53 Lisp_Object Qldapp;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
55 /* ldap-open plist keywords */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
56 static Lisp_Object Qport, Qauth, Qbinddn, Qpasswd, Qderef, Qtimelimit, Qsizelimit;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57 /* Search scope limits */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 static Lisp_Object Qbase, Qonelevel, Qsubtree;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59 /* Authentication methods */
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
60 static Lisp_Object Qkrbv41, Qkrbv42;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61 /* Deref policy */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 static Lisp_Object Qnever, Qalways, Qfind;
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
63 /* Modification types (Qdelete is defined in general.c) */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
64 static Lisp_Object Qadd, Qreplace;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65
996
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 /* Utility Functions */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
69 /************************************************************************/
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
70
2268
61855263cb07 [xemacs-hg @ 2004-09-14 14:32:29 by james]
james
parents: 1706
diff changeset
71 static DECLARE_DOESNT_RETURN (signal_ldap_error (LDAP *, LDAPMessage *, int));
61855263cb07 [xemacs-hg @ 2004-09-14 14:32:29 by james]
james
parents: 1706
diff changeset
72
61855263cb07 [xemacs-hg @ 2004-09-14 14:32:29 by james]
james
parents: 1706
diff changeset
73 static DOESNT_RETURN
2286
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 2272
diff changeset
74 signal_ldap_error (LDAP *ld,
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 2272
diff changeset
75 #if defined HAVE_LDAP_PARSE_RESULT || defined HAVE_LDAP_RESULT2ERROR
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 2272
diff changeset
76 LDAPMessage *res,
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 2272
diff changeset
77 #else
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 2272
diff changeset
78 LDAPMessage *UNUSED (res),
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 2272
diff changeset
79 #endif
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 2272
diff changeset
80 int ldap_err)
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
81 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
82 if (ldap_err <= 0)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
83 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
84 #if defined HAVE_LDAP_PARSE_RESULT
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
85 int err;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
86 ldap_err = ldap_parse_result (ld, res,
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
87 &err,
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
88 NULL, NULL, NULL, NULL, 0);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
89 if (ldap_err == LDAP_SUCCESS)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
90 ldap_err = err;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
91 #elif defined HAVE_LDAP_GET_LDERRNO
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
92 ldap_err = ldap_get_lderrno (ld, NULL, NULL);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
93 #elif defined HAVE_LDAP_RESULT2ERROR
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
94 ldap_err = ldap_result2error (ld, res, 0);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
95 #else
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
96 ldap_err = ld->ld_errno;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
97 #endif
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
98 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
99 invalid_operation ("LDAP error",
4953
304aebb79cd3 function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents: 4952
diff changeset
100 build_extstring (ldap_err2string (ldap_err), Qnative));
996
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
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
104 /************************************************************************/
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
105 /* ldap lrecord basic functions */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
106 /************************************************************************/
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 static Lisp_Object
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
109 make_ldap (Lisp_LDAP *ldap)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
110 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
111 return wrap_ldap (ldap);
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
1220
848225013a08 [xemacs-hg @ 2003-01-17 16:59:20 by james]
james
parents: 996
diff changeset
114 static const struct memory_description ldap_description [] = {
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
115 { XD_LISP_OBJECT, offsetof (struct Lisp_LDAP, host) },
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
116 { XD_END }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
117 };
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 static Lisp_Object
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
120 mark_ldap (Lisp_Object obj)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
121 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
122 return XLDAP (obj)->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
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
125 static void
2286
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 2272
diff changeset
126 print_ldap (Lisp_Object obj, Lisp_Object printcharfun, int UNUSED (escapeflag))
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
127 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
128 Lisp_LDAP *ldap = XLDAP (obj);
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 if (print_readably)
5142
f965e31a35f0 reduce lcrecord headers to 2 words, rename printing_unreadable_object
Ben Wing <ben@xemacs.org>
parents: 5141
diff changeset
131 printing_unreadable_object_fmt ("#<ldap %s>", XSTRING_DATA (ldap->host));
996
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 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
134 if (!ldap->ld)
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4824
diff changeset
135 write_ascstring (printcharfun,"(dead) ");
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
136 write_fmt_string (printcharfun, " 0x%lx>", (long)ldap);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
137 }
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 static Lisp_LDAP *
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
140 allocate_ldap (void)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
141 {
5127
a9c41067dd88 more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents: 5125
diff changeset
142 Lisp_LDAP *ldap = XLDAP (ALLOC_NORMAL_LISP_OBJECT (ldap));
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
143
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
144 ldap->ld = NULL;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
145 ldap->host = Qnil;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
146 return ldap;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
147 }
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 static void
5141
0dcd22290039 fix issues with finalizers in number.c, postgresql, ldap
Ben Wing <ben@xemacs.org>
parents: 5127
diff changeset
150 finalize_ldap (Lisp_Object obj)
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
151 {
5141
0dcd22290039 fix issues with finalizers in number.c, postgresql, ldap
Ben Wing <ben@xemacs.org>
parents: 5127
diff changeset
152 Lisp_LDAP *ldap = XLDAP (obj);
996
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 if (ldap->ld)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
155 ldap_unbind (ldap->ld);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
156 ldap->ld = NULL;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
157 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
158
5118
e0db3c197671 merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
parents: 5117 4710
diff changeset
159 DEFINE_NODUMP_LISP_OBJECT ("ldap", ldap, mark_ldap,
e0db3c197671 merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
parents: 5117 4710
diff changeset
160 print_ldap, finalize_ldap,
e0db3c197671 merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
parents: 5117 4710
diff changeset
161 NULL, NULL, ldap_description,
e0db3c197671 merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
parents: 5117 4710
diff changeset
162 Lisp_LDAP);
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
163
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 /* Basic ldap accessors */
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 /* ###autoload */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
169 DEFUN ("ldapp", Fldapp, 1, 1, 0, /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
170 Return t if OBJECT is a LDAP connection.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
171 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
172 (object))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
173 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
174 return LDAPP (object) ? Qt : Qnil;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
175 }
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 DEFUN ("ldap-host", Fldap_host, 1, 1, 0, /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
178 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
179 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
180 (ldap))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
181 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
182 CHECK_LDAP (ldap);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
183 return (XLDAP (ldap))->host;
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
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
186 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
187 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
188 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
189 (ldap))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
190 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
191 CHECK_LDAP (ldap);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
192 return (XLDAP (ldap))->ld ? Qt : Qnil;
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
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
195 /************************************************************************/
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
196 /* Opening/Closing a LDAP connection */
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
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
200 /* ###autoload */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
201 DEFUN ("ldap-open", Fldap_open, 1, 2, 0, /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
202 Open a LDAP connection to HOST.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
203 PLIST is a plist containing additional parameters for the connection.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204 Valid keys in that list are:
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
205 `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
206 `ldap-default-port'.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207 `auth' is the authentication method to use, possible values depend on
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208 the LDAP library XEmacs was compiled with: `simple', `krbv41' and `krbv42'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209 `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
210 `passwd' is the password to use for simple authentication.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211 `deref' is one of the symbols `never', `always', `search' or `find'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212 `timelimit' is the timeout limit for the connection in seconds.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213 `sizelimit' is the maximum number of matches to return.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214 */
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
215 (host, plist))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216 {
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
217 /* This function can GC */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
218 Lisp_LDAP *ldap;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219 LDAP *ld;
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
220 int ldap_port = 0;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221 int ldap_auth = LDAP_AUTH_SIMPLE;
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
222 Extbyte *ldap_binddn = NULL;
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
223 Extbyte *ldap_password = NULL;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224 int ldap_deref = LDAP_DEREF_NEVER;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225 int ldap_timelimit = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
226 int ldap_sizelimit = 0;
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
227 int err;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
229 CHECK_STRING (host);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
231 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
232 EXTERNAL_PROPERTY_LIST_LOOP_3 (keyword, value, plist)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
233 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
234 /* TCP Port */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
235 if (EQ (keyword, Qport))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
236 {
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5402
diff changeset
237 CHECK_FIXNUM (value);
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5402
diff changeset
238 ldap_port = XFIXNUM (value);
996
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 /* Authentication method */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
241 if (EQ (keyword, Qauth))
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 if (EQ (value, Qsimple))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
244 ldap_auth = LDAP_AUTH_SIMPLE;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245 #ifdef LDAP_AUTH_KRBV41
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
246 else if (EQ (value, Qkrbv41))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
247 ldap_auth = LDAP_AUTH_KRBV41;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249 #ifdef LDAP_AUTH_KRBV42
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
250 else if (EQ (value, Qkrbv42))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
251 ldap_auth = LDAP_AUTH_KRBV42;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252 #endif
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
253 else
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
254 invalid_constant ("Invalid authentication method", value);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
255 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
256 /* Bind DN */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
257 else if (EQ (keyword, Qbinddn))
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 CHECK_STRING (value);
4981
4aebb0131297 Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents: 4953
diff changeset
260 ldap_binddn = LISP_STRING_TO_EXTERNAL (value, Qnative);
996
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 /* Password */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
263 else if (EQ (keyword, Qpasswd))
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 CHECK_STRING (value);
4981
4aebb0131297 Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents: 4953
diff changeset
266 ldap_password = LISP_STRING_TO_EXTERNAL (value, Qnative);
996
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 /* Deref */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
269 else if (EQ (keyword, Qderef))
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 if (EQ (value, Qnever))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
272 ldap_deref = LDAP_DEREF_NEVER;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
273 else if (EQ (value, Qsearch))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
274 ldap_deref = LDAP_DEREF_SEARCHING;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
275 else if (EQ (value, Qfind))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
276 ldap_deref = LDAP_DEREF_FINDING;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
277 else if (EQ (value, Qalways))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
278 ldap_deref = LDAP_DEREF_ALWAYS;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
279 else
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
280 invalid_constant ("Invalid deref value", value);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
281 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
282 /* Timelimit */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
283 else if (EQ (keyword, Qtimelimit))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
284 {
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5402
diff changeset
285 CHECK_FIXNUM (value);
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5402
diff changeset
286 ldap_timelimit = XFIXNUM (value);
996
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 /* Sizelimit */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
289 else if (EQ (keyword, Qsizelimit))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
290 {
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5402
diff changeset
291 CHECK_FIXNUM (value);
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5402
diff changeset
292 ldap_sizelimit = XFIXNUM (value);
996
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 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
295 }
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 if (ldap_port == 0)
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 ldap_port = ldap_default_port;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
300 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
301
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
302 /* Connect to the server and bind */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
303 slow_down_interrupts ();
4981
4aebb0131297 Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents: 4953
diff changeset
304 ld = ldap_open (LISP_STRING_TO_EXTERNAL (host, Qnative), ldap_port);
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
305 speed_up_interrupts ();
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
307 if (ld == NULL )
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
308 report_process_error ("Failed connecting to host", host);
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 #ifdef HAVE_LDAP_SET_OPTION
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
311 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
312 (void *)&ldap_deref)) != LDAP_SUCCESS)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
313 signal_ldap_error (ld, NULL, err);
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_TIMELIMIT,
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
315 (void *)&ldap_timelimit)) != 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_SIZELIMIT,
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
318 (void *)&ldap_sizelimit)) != 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_REFERRALS,
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
321 LDAP_OPT_ON)) != 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_RESTART,
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 #else /* not HAVE_LDAP_SET_OPTION */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327 ld->ld_deref = ldap_deref;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328 ld->ld_timelimit = ldap_timelimit;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329 ld->ld_sizelimit = ldap_sizelimit;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330 #ifdef LDAP_REFERRALS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
331 ld->ld_options = LDAP_OPT_REFERRALS;
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
332 #else /* not LDAP_REFERRALS */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333 ld->ld_options = 0;
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
334 #endif /* not LDAP_REFERRALS */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
335 /* 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
336 ld->ld_options |= LDAP_OPT_RESTART;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
337 #endif /* not HAVE_LDAP_SET_OPTION */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
338
2272
4ec724310f33 [xemacs-hg @ 2004-09-14 20:54:29 by james]
james
parents: 2268
diff changeset
339 err = ldap_bind_s (ld, ldap_binddn, ldap_password, ldap_auth);
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
340 if (err != LDAP_SUCCESS)
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 signal_error (Qprocess_error, "Failed binding to the server",
4953
304aebb79cd3 function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents: 4952
diff changeset
343 build_extstring (ldap_err2string (err), Qnative));
996
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
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
346 ldap = allocate_ldap ();
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
347 ldap->ld = ld;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
348 ldap->host = host;
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 return make_ldap (ldap);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
351 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
352
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
353
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 DEFUN ("ldap-close", Fldap_close, 1, 1, 0, /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
356 Close an LDAP connection.
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 (ldap))
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 Lisp_LDAP *lldap;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
361 CHECK_LIVE_LDAP (ldap);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
362 lldap = XLDAP (ldap);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
363 ldap_unbind (lldap->ld);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
364 lldap->ld = NULL;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
365 return Qnil;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
366 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
367
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
368
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
369
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
370 /************************************************************************/
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
371 /* Working on a LDAP connection */
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 struct ldap_unwind_struct
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 LDAPMessage *res;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
376 struct berval **vals;
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
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
379 static Lisp_Object
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
380 ldap_search_unwind (Lisp_Object unwind_obj)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
381 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
382 struct ldap_unwind_struct *unwind =
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
383 (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
384 if (unwind->res)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
385 ldap_msgfree (unwind->res);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
386 if (unwind->vals)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
387 ldap_value_free_len (unwind->vals);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
388 return Qnil;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
389 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
390
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
391 /* 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
392 /* 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
393 /* 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
394 /* function */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
395
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
396 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
397 Perform a search on an open LDAP connection.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
398 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
399 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
400 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
401 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
402 the scope of the search.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
403 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
404 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
405 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
406 the associated values.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
407 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
408 its distinguished name DN.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
409 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
410 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
411 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
412 entry according to the value of WITHDN.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
413 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
414 (ldap, filter, base, scope, attrs, attrsonly, withdn, verbose))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
415 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
416 /* This function can GC */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
417
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
418 /* Vars for query */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
419 LDAP *ld;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
420 LDAPMessage *e;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
421 BerElement *ptr;
4710
3a87551bfeb5 Fixes for a number of minor warnings issued by gcc. See xemacs-patches message
Jerry James <james@xemacs.org>
parents: 3029
diff changeset
422 Extbyte *a, *dn, *bs, *filt;
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
423 int i, rc;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
424 int matches;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
425 struct ldap_unwind_struct unwind;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
426
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
427 int ldap_scope = LDAP_SCOPE_SUBTREE;
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
428 Extbyte **ldap_attributes = NULL;
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
429
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
430 int speccount = specpdl_depth ();
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 Lisp_Object list = Qnil;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
433 Lisp_Object entry = Qnil;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
434 Lisp_Object result = Qnil;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
435 struct gcpro gcpro1, gcpro2, gcpro3;
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 GCPRO3 (list, entry, result);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
438
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
439 unwind.res = NULL;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
440 unwind.vals = NULL;
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 /* Do all the parameter checking */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
443 CHECK_LIVE_LDAP (ldap);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
444 ld = XLDAP (ldap)->ld;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
445
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
446 /* Filter */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
447 CHECK_STRING (filter);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
448
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
449 /* Search base */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
450 if (NILP (base))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
451 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
452 base = Vldap_default_base;
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 if (!NILP (base))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
455 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
456 CHECK_STRING (base);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
457 }
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 /* Search scope */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
460 if (!NILP (scope))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
461 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
462 if (EQ (scope, Qbase))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
463 ldap_scope = LDAP_SCOPE_BASE;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
464 else if (EQ (scope, Qonelevel))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
465 ldap_scope = LDAP_SCOPE_ONELEVEL;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
466 else if (EQ (scope, Qsubtree))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
467 ldap_scope = LDAP_SCOPE_SUBTREE;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
468 else
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
469 invalid_constant ("Invalid scope", scope);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
470 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
471
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
472 /* Attributes to search */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
473 if (!NILP (attrs))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
474 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
475 CHECK_CONS (attrs);
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5402
diff changeset
476 ldap_attributes = alloca_array (char *, 1 + XFIXNUM (Flength (attrs)));
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
477
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
478 i = 0;
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
479 {
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
480 EXTERNAL_LIST_LOOP_2 (current, attrs)
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
481 {
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
482 CHECK_STRING (current);
4981
4aebb0131297 Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents: 4953
diff changeset
483 ldap_attributes[i] = LISP_STRING_TO_EXTERNAL (current, Qnative);
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
484 ++i;
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
485 }
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
486 }
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
487 ldap_attributes[i] = NULL;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
488 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
489
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
490 /* Attributes only ? */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
491 CHECK_SYMBOL (attrsonly);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
492
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
493 /* Perform the search */
4824
c12b646d84ee changes to get things to compile under latest cygwin
Ben Wing <ben@xemacs.org>
parents: 4710
diff changeset
494 bs = NILP (base) ? (Extbyte *) "" :
4981
4aebb0131297 Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents: 4953
diff changeset
495 LISP_STRING_TO_EXTERNAL (base, Qnative);
4824
c12b646d84ee changes to get things to compile under latest cygwin
Ben Wing <ben@xemacs.org>
parents: 4710
diff changeset
496 filt = NILP (filter) ? (Extbyte *) "" :
4981
4aebb0131297 Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents: 4953
diff changeset
497 LISP_STRING_TO_EXTERNAL (filter, Qnative);
4710
3a87551bfeb5 Fixes for a number of minor warnings issued by gcc. See xemacs-patches message
Jerry James <james@xemacs.org>
parents: 3029
diff changeset
498 if (ldap_search (ld, bs, ldap_scope, filt, ldap_attributes,
3a87551bfeb5 Fixes for a number of minor warnings issued by gcc. See xemacs-patches message
Jerry James <james@xemacs.org>
parents: 3029
diff changeset
499 NILP (attrsonly) ? 0 : 1)
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
500 == -1)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
501 {
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
502 signal_ldap_error (ld, NULL, 0);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
503 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
504
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
505 /* Ensure we don't exit without cleaning up */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
506 record_unwind_protect (ldap_search_unwind,
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
507 make_opaque_ptr (&unwind));
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
508
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
509 /* Build the results list */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
510 matches = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
511
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
512 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
513
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
514 while (rc == LDAP_RES_SEARCH_ENTRY)
428
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 QUIT;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
517 matches ++;
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
518 e = ldap_first_entry (ld, unwind.res);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
519 /* #### 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
520 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
521 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
522 restore the old echo area contents later. */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
523 if (! NILP (verbose))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
524 message ("Parsing ldap results... %d", matches);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
525 entry = Qnil;
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
526 /* Get the DN if required */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
527 if (! NILP (withdn))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
528 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
529 dn = ldap_get_dn (ld, e);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
530 if (dn == NULL)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
531 signal_ldap_error (ld, e, 0);
4953
304aebb79cd3 function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents: 4952
diff changeset
532 entry = Fcons (build_extstring (dn, Qnative), Qnil);
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
533 }
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
534 for (a = ldap_first_attribute (ld, e, &ptr);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
535 a != NULL;
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
536 a = ldap_next_attribute (ld, e, ptr))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
537 {
4953
304aebb79cd3 function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents: 4952
diff changeset
538 list = Fcons (build_extstring (a, Qnative), Qnil);
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
539 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
540 if (unwind.vals != NULL)
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 for (i = 0; unwind.vals[i] != NULL; i++)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
543 {
4953
304aebb79cd3 function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents: 4952
diff changeset
544 list = Fcons (make_extstring ((Extbyte *) unwind.vals[i]->bv_val,
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
545 unwind.vals[i]->bv_len,
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
546 Qnative),
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
547 list);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
548 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
549 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
550 entry = Fcons (Fnreverse (list),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
551 entry);
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
552 ldap_value_free_len (unwind.vals);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
553 unwind.vals = NULL;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
554 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
555 result = Fcons (Fnreverse (entry),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
556 result);
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
557 ldap_msgfree (unwind.res);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
558 unwind.res = NULL;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
559
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
560 rc = ldap_result (ld, LDAP_RES_ANY, 0, NULL, &(unwind.res));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
561 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
562
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
563 #if defined HAVE_LDAP_PARSE_RESULT
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
564 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
565 int rc2 = ldap_parse_result (ld, unwind.res,
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
566 &rc,
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
567 NULL, NULL, NULL, NULL, 0);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
568 if (rc2 != LDAP_SUCCESS)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
569 rc = rc2;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
570 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
571 #else
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
572 if (rc == 0)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
573 signal_ldap_error (ld, NULL, LDAP_TIMELIMIT_EXCEEDED);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
574
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
575 if (rc == -1)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
576 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
577
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
578 #if defined HAVE_LDAP_RESULT2ERROR
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
579 rc = ldap_result2error (ld, unwind.res, 0);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
580 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
581 #endif
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
582
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
583 if (rc != LDAP_SUCCESS)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
584 signal_ldap_error (ld, NULL, rc);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
585
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
586 ldap_msgfree (unwind.res);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
587 unwind.res = (LDAPMessage *)NULL;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
588
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
589 /* #### See above for calling message(). */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
590 if (! NILP (verbose))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
591 message ("Parsing ldap results... done");
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 unbind_to (speccount);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
594 UNGCPRO;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
595 return Fnreverse (result);
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
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
598 DEFUN ("ldap-add", Fldap_add, 3, 3, 0, /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
599 Add an entry to an LDAP directory.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
600 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
601 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
602 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
603 containing attribute/value string pairs.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
604 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
605 (ldap, dn, entry))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
606 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
607 LDAP *ld;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
608 LDAPMod *ldap_mods, **ldap_mods_ptrs;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
609 struct berval *bervals;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
610 int rc;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
611 int i, j;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
612 Elemcount len;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
613 Lisp_Object values = Qnil;
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
614 struct gcpro gcpro1;
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
615
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
616 GCPRO1 (values);
996
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 /* Do all the parameter checking */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
619 CHECK_LIVE_LDAP (ldap);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
620 ld = XLDAP (ldap)->ld;
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 /* Check the DN */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
623 CHECK_STRING (dn);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
624
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
625 /* Check the entry */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
626 CHECK_CONS (entry);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
627 if (NILP (entry))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
628 invalid_operation ("Cannot add void entry", entry);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
629
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
630 /* Build the ldap_mods array */
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5402
diff changeset
631 len = (Elemcount) XFIXNUM (Flength (entry));
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
632 ldap_mods = alloca_array (LDAPMod, len);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
633 ldap_mods_ptrs = alloca_array (LDAPMod *, 1 + len);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
634 i = 0;
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
635
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
636 {
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
637 EXTERNAL_LIST_LOOP_2 (current, entry)
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
638 {
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
639 CHECK_CONS (current);
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
640 CHECK_STRING (XCAR (current));
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
641 ldap_mods_ptrs[i] = &(ldap_mods[i]);
4981
4aebb0131297 Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents: 4953
diff changeset
642 ldap_mods[i].mod_type =
4aebb0131297 Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents: 4953
diff changeset
643 LISP_STRING_TO_EXTERNAL (XCAR (current), Qnative);
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
644 ldap_mods[i].mod_op = LDAP_MOD_ADD | LDAP_MOD_BVALUES;
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
645 values = XCDR (current);
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
646 if (CONSP (values))
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
647 {
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5402
diff changeset
648 len = (Elemcount) XFIXNUM (Flength (values));
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
649 bervals = alloca_array (struct berval, len);
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
650 ldap_mods[i].mod_vals.modv_bvals =
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
651 alloca_array (struct berval *, 1 + len);
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
652 j = 0;
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
653 {
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
654 EXTERNAL_LIST_LOOP_2 (cur2, values)
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
655 {
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
656 CHECK_STRING (cur2);
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
657 ldap_mods[i].mod_vals.modv_bvals[j] = &(bervals[j]);
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
658 TO_EXTERNAL_FORMAT (LISP_STRING, cur2,
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
659 ALLOCA, (bervals[j].bv_val,
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
660 bervals[j].bv_len),
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
661 Qnative);
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
662 j++;
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
663 }
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
664 }
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
665 ldap_mods[i].mod_vals.modv_bvals[j] = NULL;
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
666 }
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
667 else
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
668 {
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
669 CHECK_STRING (values);
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
670 bervals = alloca_array (struct berval, 1);
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
671 ldap_mods[i].mod_vals.modv_bvals = alloca_array (struct berval *,
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
672 2);
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
673 ldap_mods[i].mod_vals.modv_bvals[0] = &(bervals[0]);
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
674 TO_EXTERNAL_FORMAT (LISP_STRING, values,
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
675 ALLOCA, (bervals[0].bv_val,
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
676 bervals[0].bv_len),
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
677 Qnative);
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
678 ldap_mods[i].mod_vals.modv_bvals[1] = NULL;
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
679 }
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
680 i++;
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
681 }
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
682 }
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
683 ldap_mods_ptrs[i] = NULL;
4981
4aebb0131297 Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents: 4953
diff changeset
684 rc = ldap_add_s (ld, LISP_STRING_TO_EXTERNAL (dn, Qnative),
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
685 ldap_mods_ptrs);
996
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 Lisp_Object values = Qnil;
3029
986cd22006a9 [xemacs-hg @ 2005-10-26 13:01:37 by stephent]
stephent
parents: 3024
diff changeset
712 struct gcpro gcpro1;
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
713
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
714 /* Do all the parameter checking */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
715 CHECK_LIVE_LDAP (ldap);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
716 ld = XLDAP (ldap)->ld;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
717
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
718 /* Check the DN */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
719 CHECK_STRING (dn);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
720
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
721 /* Check the entry */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
722 CHECK_CONS (mods);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
723 if (NILP (mods))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
724 return Qnil;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
725
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
726 /* Build the ldap_mods array */
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5402
diff changeset
727 len = (Elemcount) XFIXNUM (Flength (mods));
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
728 ldap_mods = alloca_array (LDAPMod, len);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
729 ldap_mods_ptrs = alloca_array (LDAPMod *, 1 + len);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
730 i = 0;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
731
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
732 GCPRO1 (values);
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
733 {
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
734 EXTERNAL_LIST_LOOP_2 (current, mods)
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
735 {
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
736 CHECK_CONS (current);
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
737 CHECK_SYMBOL (XCAR (current));
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
738 mod_op = XCAR (current);
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
739 ldap_mods_ptrs[i] = &(ldap_mods[i]);
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
740 ldap_mods[i].mod_op = LDAP_MOD_BVALUES;
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
741 if (EQ (mod_op, Qadd))
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
742 ldap_mods[i].mod_op |= LDAP_MOD_ADD;
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
743 else if (EQ (mod_op, Qdelete))
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
744 ldap_mods[i].mod_op |= LDAP_MOD_DELETE;
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
745 else if (EQ (mod_op, Qreplace))
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
746 ldap_mods[i].mod_op |= LDAP_MOD_REPLACE;
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
747 else
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
748 invalid_constant ("Invalid LDAP modification type", mod_op);
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
749 current = XCDR (current);
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
750 CHECK_STRING (XCAR (current));
4981
4aebb0131297 Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents: 4953
diff changeset
751 ldap_mods[i].mod_type =
4aebb0131297 Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents: 4953
diff changeset
752 LISP_STRING_TO_EXTERNAL (XCAR (current), Qnative);
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
753 values = XCDR (current);
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5402
diff changeset
754 len = (Elemcount) XFIXNUM (Flength (values));
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
755 bervals = alloca_array (struct berval, len);
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
756 ldap_mods[i].mod_vals.modv_bvals =
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
757 alloca_array (struct berval *, 1 + len);
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
758 j = 0;
2387
7ee6ea4ff5c0 [xemacs-hg @ 2004-11-14 01:43:02 by ben]
ben
parents: 2367
diff changeset
759 {
7ee6ea4ff5c0 [xemacs-hg @ 2004-11-14 01:43:02 by ben]
ben
parents: 2367
diff changeset
760 EXTERNAL_LIST_LOOP_2 (cur2, values)
7ee6ea4ff5c0 [xemacs-hg @ 2004-11-14 01:43:02 by ben]
ben
parents: 2367
diff changeset
761 {
7ee6ea4ff5c0 [xemacs-hg @ 2004-11-14 01:43:02 by ben]
ben
parents: 2367
diff changeset
762 CHECK_STRING (cur2);
7ee6ea4ff5c0 [xemacs-hg @ 2004-11-14 01:43:02 by ben]
ben
parents: 2367
diff changeset
763 ldap_mods[i].mod_vals.modv_bvals[j] = &(bervals[j]);
7ee6ea4ff5c0 [xemacs-hg @ 2004-11-14 01:43:02 by ben]
ben
parents: 2367
diff changeset
764 TO_EXTERNAL_FORMAT (LISP_STRING, cur2,
7ee6ea4ff5c0 [xemacs-hg @ 2004-11-14 01:43:02 by ben]
ben
parents: 2367
diff changeset
765 ALLOCA, (bervals[j].bv_val,
7ee6ea4ff5c0 [xemacs-hg @ 2004-11-14 01:43:02 by ben]
ben
parents: 2367
diff changeset
766 bervals[j].bv_len),
7ee6ea4ff5c0 [xemacs-hg @ 2004-11-14 01:43:02 by ben]
ben
parents: 2367
diff changeset
767 Qnative);
7ee6ea4ff5c0 [xemacs-hg @ 2004-11-14 01:43:02 by ben]
ben
parents: 2367
diff changeset
768 j++;
7ee6ea4ff5c0 [xemacs-hg @ 2004-11-14 01:43:02 by ben]
ben
parents: 2367
diff changeset
769 }
7ee6ea4ff5c0 [xemacs-hg @ 2004-11-14 01:43:02 by ben]
ben
parents: 2367
diff changeset
770 ldap_mods[i].mod_vals.modv_bvals[j] = NULL;
7ee6ea4ff5c0 [xemacs-hg @ 2004-11-14 01:43:02 by ben]
ben
parents: 2367
diff changeset
771 i++;
7ee6ea4ff5c0 [xemacs-hg @ 2004-11-14 01:43:02 by ben]
ben
parents: 2367
diff changeset
772 }
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
773 }
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
774 }
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
775 ldap_mods_ptrs[i] = NULL;
4981
4aebb0131297 Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents: 4953
diff changeset
776 rc = ldap_modify_s (ld, LISP_STRING_TO_EXTERNAL (dn, Qnative),
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
777 ldap_mods_ptrs);
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
778 if (rc != LDAP_SUCCESS)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
779 signal_ldap_error (ld, NULL, rc);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
780
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
781 UNGCPRO;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
782 return Qnil;
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
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
785
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
786 DEFUN ("ldap-delete", Fldap_delete, 2, 2, 0, /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
787 Delete an entry to an LDAP directory.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
788 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
789 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
790 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
791 (ldap, dn))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
792 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
793 LDAP *ld;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
794 int rc;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
795
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
796 /* Check parameters */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
797 CHECK_LIVE_LDAP (ldap);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
798 ld = XLDAP (ldap)->ld;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
799 CHECK_STRING (dn);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
800
4981
4aebb0131297 Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents: 4953
diff changeset
801 rc = ldap_delete_s (ld, LISP_STRING_TO_EXTERNAL (dn, Qnative));
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
802 if (rc != LDAP_SUCCESS)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
803 signal_ldap_error (ld, NULL, rc);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
804
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
805 return Qnil;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
806 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
807
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
808 void
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
809 syms_of_eldap (void)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
810 {
5118
e0db3c197671 merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
parents: 5117 4710
diff changeset
811 INIT_LISP_OBJECT (ldap);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
812
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
813 DEFSYMBOL (Qeldap);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
814 DEFSYMBOL (Qldapp);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
815 DEFSYMBOL (Qport);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
816 DEFSYMBOL (Qauth);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
817 DEFSYMBOL (Qbinddn);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
818 DEFSYMBOL (Qpasswd);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
819 DEFSYMBOL (Qderef);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
820 DEFSYMBOL (Qtimelimit);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
821 DEFSYMBOL (Qsizelimit);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
822 DEFSYMBOL (Qbase);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
823 DEFSYMBOL (Qonelevel);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
824 DEFSYMBOL (Qsubtree);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
825 DEFSYMBOL (Qkrbv41);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
826 DEFSYMBOL (Qkrbv42);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
827 DEFSYMBOL (Qnever);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
828 DEFSYMBOL (Qalways);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
829 DEFSYMBOL (Qfind);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
830 DEFSYMBOL (Qadd);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
831 DEFSYMBOL (Qreplace);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
832
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
833 DEFSUBR (Fldapp);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
834 DEFSUBR (Fldap_host);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
835 DEFSUBR (Fldap_live_p);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
836 DEFSUBR (Fldap_open);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
837 DEFSUBR (Fldap_close);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
838 DEFSUBR (Fldap_search_basic);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
839 DEFSUBR (Fldap_add);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
840 DEFSUBR (Fldap_modify);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
841 DEFSUBR (Fldap_delete);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
842 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
843
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
844 void
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
845 vars_of_eldap (void)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
846 {
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
847
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
848 Fprovide (Qeldap);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
849
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
850 ldap_default_port = LDAP_PORT;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
851 Vldap_default_base = Qnil;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
852
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
853 DEFVAR_INT ("ldap-default-port", &ldap_default_port /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
854 Default TCP port for LDAP connections.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
855 Initialized from the LDAP library. Default value is 389.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
856 */ );
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
857
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
858 DEFVAR_LISP ("ldap-default-base", &Vldap_default_base /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
859 Default base for LDAP searches.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
860 This is a string using the syntax of RFC 1779.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
861 For instance, "o=ACME, c=US" limits the search to the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
862 Acme organization in the United States.
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
865 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
866
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
867 #ifdef HAVE_SHLIB
1706
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
868 EXTERN_C void unload_eldap (void);
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
869 void
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
870 unload_eldap (void)
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 defined types */
5120
d1247f3cc363 latest work on lisp-object workspace;
Ben Wing <ben@xemacs.org>
parents: 5119
diff changeset
873 UNDEF_LISP_OBJECT (ldap);
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
874
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
875 /* Remove staticpro'ing of symbols */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
876 unstaticpro_nodump (&Qeldap);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
877 unstaticpro_nodump (&Qldapp);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
878 unstaticpro_nodump (&Qport);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
879 unstaticpro_nodump (&Qauth);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
880 unstaticpro_nodump (&Qbinddn);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
881 unstaticpro_nodump (&Qpasswd);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
882 unstaticpro_nodump (&Qderef);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
883 unstaticpro_nodump (&Qtimelimit);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
884 unstaticpro_nodump (&Qsizelimit);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
885 unstaticpro_nodump (&Qbase);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
886 unstaticpro_nodump (&Qonelevel);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
887 unstaticpro_nodump (&Qsubtree);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
888 unstaticpro_nodump (&Qkrbv41);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
889 unstaticpro_nodump (&Qkrbv42);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
890 unstaticpro_nodump (&Qnever);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
891 unstaticpro_nodump (&Qalways);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
892 unstaticpro_nodump (&Qfind);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
893 unstaticpro_nodump (&Qadd);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
894 unstaticpro_nodump (&Qreplace);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
895 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents: 428
diff changeset
896 #endif /* HAVE_SHLIB */