conforming to the API defined in RFC 1823.
It has been tested with:
- UMich LDAP 3.3 (http://www.umich.edu/~dirsvcs/ldap/)
- - Netscape's LDAP SDK 1.0 (http://developer.netscape.com) */
+ - OpenLDAP 1.0.3 (http://www.openldap.org/)
+ - Netscape's LDAP SDK 1.0 (http://developer.netscape.com/) */
#include <config.h>
#include "lisp.h"
#include "opaque.h"
#include "sysdep.h"
+#include "buffer.h"
#include <errno.h>
allocate_ldap (void)
{
struct Lisp_LDAP *ldap =
- alloc_lcrecord_type (struct Lisp_LDAP, lrecord_ldap);
+ alloc_lcrecord_type (struct Lisp_LDAP, &lrecord_ldap);
ldap->ld = NULL;
ldap->host = Qnil;
else if (EQ (keyword, Qbinddn))
{
CHECK_STRING (value);
- ldap_binddn = alloca (XSTRING_LENGTH (value) + 1);
- strcpy (ldap_binddn, (char *)XSTRING_DATA (value));
+ GET_C_STRING_OS_DATA_ALLOCA (value, ldap_binddn);
}
/* Password */
else if (EQ (keyword, Qpasswd))
{
CHECK_STRING (value);
- ldap_passwd = alloca (XSTRING_LENGTH (value) + 1);
- strcpy (ldap_passwd, (char *)XSTRING_DATA (value));
+ GET_C_STRING_OS_DATA_ALLOCA (value, ldap_passwd);
}
/* Deref */
else if (EQ (keyword, Qderef))
}
/* Connect to the server and bind */
+ slow_down_interrupts ();
ld = ldap_open ((char *)XSTRING_DATA (host), ldap_port);
+ speed_up_interrupts ();
+
if (ld == NULL )
signal_simple_error_2 ("Failed connecting to host",
host,
struct ldap_unwind_struct
{
LDAPMessage *res;
- char **vals;
+ struct berval **vals;
};
if (unwind->res)
ldap_msgfree (unwind->res);
if (unwind->vals)
- ldap_value_free (unwind->vals);
+ ldap_value_free_len (unwind->vals);
return Qnil;
}
-DEFUN ("ldap-search-internal", Fldap_search_internal, 2, 6, 0, /*
+DEFUN ("ldap-search-internal", Fldap_search_internal, 2, 7, 0, /*
Perform a search on an open LDAP connection.
LDAP is an LDAP connection object created with `ldap-open'.
FILTER is a filter string for the search as described in RFC 1558.
for each matching entry. If nil return all available attributes.
If ATTRSONLY is non-nil then only the attributes are retrieved, not
the associated values.
+If WITHDN is non-nil each entry in the result will be prepennded with
+its distinguished name DN.
The function returns a list of matching entries. Each entry is itself
-an alist of attribute/values.
+an alist of attribute/value pairs optionally preceded by the DN of the
+entry according to the value of WITHDN.
*/
- (ldap, filter, base, scope, attrs, attrsonly))
+ (ldap, filter, base, scope, attrs, attrsonly, withdn))
{
/* This function can GC */
LDAP *ld;
LDAPMessage *e;
BerElement *ptr;
- char *a;
+ char *a, *dn;
int i, rc;
int matches;
struct ldap_unwind_struct unwind;
{
Lisp_Object current = XCAR (attrs);
CHECK_STRING (current);
- ldap_attributes[i] =
- alloca_array (char, 1 + XSTRING_LENGTH (current));
- /* XSTRING_LENGTH is increased by one in order to copy the final 0 */
- memcpy (ldap_attributes[i],
- XSTRING_DATA (current), 1 + XSTRING_LENGTH (current));
+ GET_C_STRING_OS_DATA_ALLOCA (current, ldap_attributes[i]);
++i;
}
ldap_attributes[i] = NULL;
restore the old echo area contents later. */
message ("Parsing ldap results... %d", matches);
entry = Qnil;
+ /* Get the DN if required */
+ if (! NILP (withdn))
+ {
+ dn = ldap_get_dn (ld, e);
+ if (dn == NULL)
+ {
+ signal_ldap_error (ld);
+ }
+ entry = Fcons (build_ext_string (dn, FORMAT_OS), Qnil);
+ }
for (a= ldap_first_attribute (ld, e, &ptr);
a != NULL;
- a= ldap_next_attribute (ld, e, ptr) )
+ a = ldap_next_attribute (ld, e, ptr) )
{
list = Fcons (build_ext_string (a, FORMAT_OS), Qnil);
- unwind.vals = ldap_get_values (ld, e, a);
+ unwind.vals = ldap_get_values_len (ld, e, a);
if (unwind.vals != NULL)
{
for (i = 0; unwind.vals[i] != NULL; i++)
{
- list = Fcons (build_ext_string (unwind.vals[i], FORMAT_OS),
+ list = Fcons (make_ext_string (unwind.vals[i]->bv_val,
+ unwind.vals[i]->bv_len,
+ FORMAT_OS),
list);
}
}
entry = Fcons (Fnreverse (list),
entry);
- ldap_value_free (unwind.vals);
+ ldap_value_free_len (unwind.vals);
unwind.vals = NULL;
}
result = Fcons (Fnreverse (entry),
void
vars_of_eldap (void)
{
- Fprovide (intern ("ldap"));
ldap_default_port = LDAP_PORT;
Vldap_default_base = Qnil;