31
31
#include "drizzled/plugin/authentication.h"
32
#include "drizzled/identifier.h"
32
#include "drizzled/security_context.h"
33
33
#include "drizzled/util/convert.h"
34
34
#include "drizzled/algorithm/sha1.h"
36
#include <drizzled/module/option_map.h>
37
#include <boost/program_options.hpp>
39
namespace po= boost::program_options;
40
36
using namespace std;
41
37
using namespace drizzled;
43
39
namespace auth_ldap
47
const std::string DEFAULT_URI= "ldap://127.0.0.1/";
49
std::string bind_password;
51
std::string password_attribute;
52
std::string DEFAULT_PASSWORD_ATTRIBUTE= "userPassword";
53
std::string mysql_password_attribute;
54
const std::string DEFAULT_MYSQL_PASSWORD_ATTRIBUTE= "mysqlUserPassword";
42
static char *uri= NULL;
43
static const char DEFAULT_URI[]= "ldap://127.0.0.1/";
44
static char *bind_dn= NULL;
45
static char *bind_password= NULL;
46
static char *base_dn= NULL;
47
static char *password_attribute= NULL;
48
static const char DEFAULT_PASSWORD_ATTRIBUTE[]= "userPassword";
49
static char *mysql_password_attribute= NULL;
50
static const char DEFAULT_MYSQL_PASSWORD_ATTRIBUTE[]= "mysqlUserPassword";
51
static int cache_timeout= 0;
55
52
static const int DEFAULT_CACHE_TIMEOUT= 600;
56
typedef constrained_check<int, DEFAULT_CACHE_TIMEOUT, 0, 2147483647> cachetimeout_constraint;
57
static cachetimeout_constraint cache_timeout= 0;
60
54
class AuthLDAP: public plugin::Authentication
95
typedef std::pair<PasswordType, std::string> PasswordEntry;
96
typedef std::pair<std::string, PasswordEntry> UserEntry;
97
typedef std::map<std::string, PasswordEntry> UserCache;
89
typedef pair<PasswordType, string> PasswordEntry;
90
typedef pair<string, PasswordEntry> UserEntry;
91
typedef map<string, PasswordEntry> UserCache;
100
94
* Base class method to check authentication for a user.
102
bool authenticate(const identifier::User &sctx, const string &password);
96
bool authenticate(const SecurityContext &sctx, const string &password);
105
99
* Lookup a user in LDAP.
413
407
AuthLDAP *auth_ldap= new AuthLDAP("auth_ldap");
414
408
if (! auth_ldap->initialize())
416
errmsg_printf(error::ERROR, _("Could not load auth ldap: %s\n"),
410
errmsg_printf(ERRMSG_LVL_ERROR, _("Could not load auth ldap: %s\n"),
417
411
auth_ldap->getError().c_str());
418
412
delete auth_ldap;
422
context.registerVariable(new sys_var_const_string_val("uri", uri));
423
context.registerVariable(new sys_var_const_string_val("bind-dn", bind_dn));
424
context.registerVariable(new sys_var_const_string_val("bind-password", bind_password));
425
context.registerVariable(new sys_var_const_string_val("base-dn", base_dn));
426
context.registerVariable(new sys_var_const_string_val("password-attribute",password_attribute));
427
context.registerVariable(new sys_var_const_string_val("mysql-password-attribute", mysql_password_attribute));
428
context.registerVariable(new sys_var_constrained_value_readonly<int>("cache-timeout", cache_timeout));
430
416
context.add(auth_ldap);
434
static void init_options(drizzled::module::option_context &context)
420
static DRIZZLE_SYSVAR_STR(uri,
423
N_("URI of the LDAP server to contact"),
424
NULL, /* check func */
425
NULL, /* update func*/
428
static DRIZZLE_SYSVAR_STR(bind_dn,
431
N_("DN to use when binding to the LDAP server"),
432
NULL, /* check func */
433
NULL, /* update func*/
434
NULL); /* default value */
436
static DRIZZLE_SYSVAR_STR(bind_password,
439
N_("Password to use when binding the DN"),
440
NULL, /* check func */
441
NULL, /* update func*/
442
NULL); /* default value */
444
static DRIZZLE_SYSVAR_STR(base_dn,
447
N_("DN to use when searching"),
448
NULL, /* check func */
449
NULL, /* update func*/
450
NULL); /* default value */
452
static DRIZZLE_SYSVAR_STR(password_attribute,
455
N_("Attribute in LDAP with plain text password"),
456
NULL, /* check func */
457
NULL, /* update func*/
458
DEFAULT_PASSWORD_ATTRIBUTE);
460
static DRIZZLE_SYSVAR_STR(mysql_password_attribute,
461
mysql_password_attribute,
463
N_("Attribute in LDAP with MySQL hashed password"),
464
NULL, /* check func */
465
NULL, /* update func*/
466
DEFAULT_MYSQL_PASSWORD_ATTRIBUTE);
468
static DRIZZLE_SYSVAR_INT(cache_timeout,
471
N_("How often to empty the users cache, 0 to disable"),
472
NULL, /* check func */
473
NULL, /* update func */
474
DEFAULT_CACHE_TIMEOUT,
479
static drizzle_sys_var* sys_variables[]=
436
context("uri", po::value<string>(&uri)->default_value(DEFAULT_URI),
437
N_("URI of the LDAP server to contact"));
438
context("bind-db", po::value<string>(&bind_dn)->default_value(""),
439
N_("DN to use when binding to the LDAP server"));
440
context("bind-password", po::value<string>(&bind_password)->default_value(""),
441
N_("Password to use when binding the DN"));
442
context("base-dn", po::value<string>(&base_dn)->default_value(""),
443
N_("DN to use when searching"));
444
context("password-attribute", po::value<string>(&password_attribute)->default_value(DEFAULT_PASSWORD_ATTRIBUTE),
445
N_("Attribute in LDAP with plain text password"));
446
context("mysql-password-attribute", po::value<string>(&mysql_password_attribute)->default_value(DEFAULT_MYSQL_PASSWORD_ATTRIBUTE),
447
N_("Attribute in LDAP with MySQL hashed password"));
448
context("cache-timeout", po::value<cachetimeout_constraint>(&cache_timeout)->default_value(DEFAULT_CACHE_TIMEOUT),
449
N_("How often to empty the users cache, 0 to disable"));
482
DRIZZLE_SYSVAR(bind_dn),
483
DRIZZLE_SYSVAR(bind_password),
484
DRIZZLE_SYSVAR(base_dn),
485
DRIZZLE_SYSVAR(password_attribute),
486
DRIZZLE_SYSVAR(mysql_password_attribute),
487
DRIZZLE_SYSVAR(cache_timeout),
452
491
} /* namespace auth_ldap */
454
DRIZZLE_PLUGIN(auth_ldap::init, NULL, auth_ldap::init_options);
493
DRIZZLE_PLUGIN(auth_ldap::init, auth_ldap::sys_variables, NULL);