32
32
static bool enabled= false;
33
33
static bool debug_enabled= false;
34
static char* username= NULL;
35
static char* password= NULL;
36
static char* db= NULL;
39
36
class ClientConsole: public plugin::Client
43
40
uint32_t max_column;
41
const std::string &username;
42
const std::string &password;
43
const std::string &db;
46
ClientConsole(const std::string &username_arg,
47
const std::string &password_arg,
48
const std::string &db_arg) :
52
username(username_arg),
53
password(password_arg),
52
57
virtual void printDebug(const char *message)
96
101
printDebug("authenticate");
97
102
session->getSecurityContext().setUser(username);
98
return session->checkUser(password, strlen(password), db);
103
return session->checkUser(password, db);
101
106
virtual bool readCommand(char **packet, uint32_t *packet_length)
269
274
class ListenConsole: public plugin::Listen
277
const std::string username;
278
const std::string password;
279
const std::string db;
274
ListenConsole(const std::string &name_arg) :
275
plugin::Listen(name_arg)
282
ListenConsole(const std::string &name_arg,
283
const std::string &username_arg,
284
const std::string &password_arg,
285
const std::string &db_arg) :
286
plugin::Listen(name_arg),
287
username(username_arg),
288
password(password_arg),
316
325
assert(read(fd, buffer, 1) == 1);
317
return new ClientConsole;
326
return new ClientConsole(username, password, db);
321
330
static int init(drizzled::module::Context &context)
323
332
const module::option_map &vm= context.getOptions();
324
/* duplicating these here means they need to be freed. They're global, so
325
we'll just have the ListenConsole object do it in its destructor */
326
if (vm.count("username"))
327
username= strdup(vm["username"].as<string>().c_str());
329
username= strdup("");
331
if (vm.count("password"))
332
password= strdup(vm["password"].as<string>().c_str());
334
password= strdup("");
337
db= strdup(vm["db"].as<string>().c_str());
341
context.add(new ListenConsole("console"));
333
const string username(vm.count("username") ? vm["username"].as<string>() : "");
334
const string password(vm.count("password") ? vm["password"].as<string>() : "");
335
const string db(vm.count("db") ? vm["db"].as<string>() : "");
342
336
context.registerVariable(new sys_var_bool_ptr("enable", &enabled));
343
337
context.registerVariable(new sys_var_bool_ptr("debug_enable", &debug_enabled));
344
context.registerVariable(new sys_var_const_str("username", username));
345
context.registerVariable(new sys_var_const_str("password", password));
346
context.registerVariable(new sys_var_const_str("db", db));
338
context.registerVariable(new sys_var_const_string_val("username", username));
339
context.registerVariable(new sys_var_const_string_val("password", password));
340
context.registerVariable(new sys_var_const_string_val("db", db));
341
context.add(new ListenConsole("console", username, password, db));