passdb-ldap.c revision ac75cf9b005f0fc574e49cd64b71db9bf5efbee2
/* Copyright (c) 2003-2007 Dovecot authors, see the included COPYING file */
#include "common.h"
#ifdef PASSDB_LDAP
#include "hash.h"
#include "str.h"
#include "var-expand.h"
#include "password-scheme.h"
#include "auth-cache.h"
#include "db-ldap.h"
#include "passdb.h"
#include <ldap.h>
#include <stdlib.h>
struct ldap_passdb_module {
struct passdb_module module;
struct ldap_connection *conn;
};
struct passdb_ldap_request {
struct ldap_request request;
union {
} callback;
};
static LDAPMessage *
struct auth_request *auth_request,
{
enum passdb_result passdb_result;
int ret;
/* LDAP query returned something */
if (ret != LDAP_SUCCESS) {
"ldap_search(%s) failed: %s",
} else {
/* get the reply */
/* success */
return entry;
}
/* no entries returned */
"unknown user");
}
}
} else {
}
return NULL;
}
static void
{
struct db_ldap_result_iterate_context *ldap_iter;
}
}
{
struct passdb_ldap_request *ldap_request =
(struct passdb_ldap_request *)request;
enum passdb_result passdb_result;
int ret;
return;
/* got first LDAP entry */
"No password in reply");
"pass_filter matched multiple objects, aborting");
!auth_request->no_password) {
"Empty password returned without no_password");
} else {
/* passdb_password may change on the way,
so we'll need to strdup. */
}
/* auth_request_set_field() sets scheme */
/* LDAP's RFC2307 specifies the MD5 scheme for what we call PLAIN-MD5.
We can detect this case, because base64 doesn't use '$'. */
"Password doesn't look like MD5-CRYPT, "
"scheme changed to PLAIN-MD5");
scheme = "PLAIN-MD5";
}
} else {
}
}
}
struct ldap_request *ldap_request)
{
struct passdb_ldap_request *passdb_ldap_request =
(struct passdb_ldap_request *)ldap_request;
int msgid;
/* Assume that empty password fails. This is especially
important with Windows 2003 AD, which always returns success
with empty passwords. */
"Login attempt with empty password");
return;
}
/* switch back to the default dn before doing the next search
request */
/* the DN is kept in base variable, a bit ugly.. */
if (msgid == -1) {
"ldap_bind(%s) failed: %s",
return;
}
ldap_request->base);
} else {
}
/* Bind started */
}
static void
{
struct passdb_ldap_request *passdb_ldap_request =
(struct passdb_ldap_request *)ldap_request;
enum passdb_result passdb_result;
int ret;
if (ret == LDAP_SUCCESS)
else if (ret == LDAP_INVALID_CREDENTIALS) {
"invalid credentials");
} else {
"ldap_bind() failed: %s",
}
}
/* reconnected, retry binding */
} else {
}
}
static void
struct ldap_request *ldap_request,
{
struct passdb_ldap_request *passdb_ldap_request =
(struct passdb_ldap_request *)ldap_request;
char *dn;
return;
/* switch the handler to the authenticated bind handler */
}
struct ldap_request *ldap_request)
{
struct ldap_passdb_module *module =
(struct ldap_passdb_module *)_module;
const struct var_expand_table *vars;
str_truncate(str, 0);
"base=%s scope=%s filter=%s fields=%s",
}
static void
struct ldap_request *ldap_request)
{
struct ldap_passdb_module *module =
(struct ldap_passdb_module *)_module;
const struct var_expand_table *vars;
}
static void
struct ldap_request *ldap_request)
{
struct ldap_passdb_module *module =
(struct ldap_passdb_module *)_module;
const struct var_expand_table *vars;
str_truncate(str, 0);
/* we don't need the attributes to perform authentication, but they
may contain some extra parameters. if a password is returned,
it's just ignored. */
"bind search: base=%s filter=%s",
}
static void
const char *password ATTR_UNUSED,
{
struct ldap_passdb_module *module =
(struct ldap_passdb_module *)_module;
struct passdb_ldap_request *ldap_request;
/* reconnect if needed. this is also done by db_ldap_search(), but
with auth binds we'll have to do it ourself */
if (db_ldap_connect(conn)< 0) {
return;
}
else
}
{
struct passdb_ldap_request *ldap_request;
}
static struct passdb_module *
{
struct ldap_passdb_module *module;
struct ldap_connection *conn;
}
const char *args ATTR_UNUSED)
{
struct ldap_passdb_module *module =
(struct ldap_passdb_module *)_module;
/* Credential lookups can't be done with authentication binds */
}
}
{
struct ldap_passdb_module *module =
(struct ldap_passdb_module *)_module;
}
struct passdb_module_interface passdb_ldap = {
"ldap",
};
#endif