db-ldap.c revision 002bb664e4b88a808e8a07cf595bfbbf1e7194ec
/* Copyright (C) 2003 Timo Sirainen */
#include "config.h"
#if defined(PASSDB_LDAP) || defined(USERDB_LDAP)
#include "common.h"
#include "network.h"
#include "ioloop.h"
#include "hash.h"
#include "str.h"
#include "settings.h"
#include "db-ldap.h"
#include <stddef.h>
#include <stdlib.h>
/* Older versions may require calling ldap_result() twice */
#if LDAP_VENDOR_VERSION <= 20112
# define OPENLDAP_ASYNC_WORKAROUND
#endif
static struct setting_def setting_defs[] = {
};
struct ldap_settings default_ldap_settings = {
};
{
return LDAP_DEREF_NEVER;
return LDAP_DEREF_SEARCHING;
return LDAP_DEREF_FINDING;
return LDAP_DEREF_ALWAYS;
}
{
return LDAP_SCOPE_BASE;
return LDAP_SCOPE_ONELEVEL;
return LDAP_SCOPE_SUBTREE;
}
{
if (ret != LDAP_SUCCESS) {
i_error("LDAP: Can't get error number: %s",
return "??";
}
return ldap_err2string(err);
}
const char *filter, char **attributes,
struct ldap_request *request)
{
int msgid;
if (!ldap_conn_open(conn)) {
return;
}
}
if (msgid == -1) {
i_error("LDAP: ldap_search() failed (filter %s): %s",
return;
}
}
static void ldap_input(void *context)
{
struct ldap_request *request;
#ifdef OPENLDAP_ASYNC_WORKAROUND
if (ret == 0) {
/* try again, there may be another in buffer */
}
#endif
if (ret <= 0) {
if (ret < 0) {
i_error("LDAP: ldap_result() failed: %s",
/* reconnect */
}
return;
}
i_error("LDAP: Reply with unknown msgid %d",
msgid);
} else {
}
}
}
{
return TRUE;
i_fatal("LDAP: ldap_init() failed with hosts: %s",
if (ret != LDAP_SUCCESS) {
i_fatal("LDAP: Can't set deref option: %s",
}
if (ret != LDAP_OPT_SUCCESS) {
i_fatal("LDAP: Can't set protocol version %u: %s",
}
}
/* NOTE: we use blocking connect, we couldn't do anything anyway
until it's done. */
if (ret == LDAP_SERVER_DOWN) {
return FALSE;
}
if (ret != LDAP_SUCCESS) {
i_error("LDAP: ldap_simple_bind_s() failed (dn %s): %s",
return FALSE;
}
/* register LDAP input to ioloop */
if (ret != LDAP_SUCCESS) {
i_fatal("LDAP: Can't get connection fd: %s",
}
return TRUE;
}
{
}
{
}
}
}
unsigned int **attrs, char ***attr_names)
{
const char *const *attr;
i_fatal("Missing uid field in attrs");
/* +1 for terminating NULL */
if (**attr != '\0') {
dest++;
}
}
}
#define IS_LDAP_ESCAPED_CHAR(c) \
((c) == '*' || (c) == '(' || (c) == ')' || (c) == '\\')
const char *ldap_escape(const char *str)
{
const char *p;
for (p = str; *p != '\0'; p++) {
if (IS_LDAP_ESCAPED_CHAR(*p))
break;
}
if (*p == '\0')
return str;
for (; *p != '\0'; p++) {
if (IS_LDAP_ESCAPED_CHAR(*p))
str_append_c(ret, *p);
}
}
void *context)
{
}
{
struct ldap_connection *conn;
return conn;
}
return NULL;
}
{
struct ldap_connection *conn;
/* see if it already exists */
return conn;
}
i_fatal("LDAP: No base given");
(void)ldap_conn_open(conn);
return conn;
}
{
return;
}
#endif