18
18
#include <drizzled/plugin/listen_tcp.h>
19
19
#include <drizzled/plugin/client.h>
20
20
#include <drizzled/session.h>
21
#include <drizzled/module/option_map.h>
23
22
#include <iostream>
25
#include <boost/program_options.hpp>
27
24
using namespace std;
28
25
using namespace drizzled;
30
namespace po= boost::program_options;
32
27
static bool enabled= false;
33
28
static bool debug_enabled= false;
29
static char* user = (char*)"";
30
static char* password = (char*)"";
31
static char* db = NULL;
36
34
class ClientConsole: public plugin::Client
99
89
virtual bool authenticate(void)
101
91
printDebug("authenticate");
102
session->getSecurityContext().setUser(username);
103
return session->checkUser(password, db);
92
session->getSecurityContext().setUser(user);
93
return session->checkUser(password, strlen(password), db);
106
96
virtual bool readCommand(char **packet, uint32_t *packet_length)
274
264
class ListenConsole: public plugin::Listen
277
const std::string username;
278
const std::string password;
279
const std::string db;
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),
269
ListenConsole(std::string name_arg)
270
: plugin::Listen(name_arg)
325
306
assert(read(fd, buffer, 1) == 1);
326
return new ClientConsole(username, password, db);
307
return new ClientConsole;
311
static ListenConsole *listen_obj= NULL;
330
313
static int init(drizzled::module::Context &context)
332
const module::option_map &vm= context.getOptions();
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>() : "");
336
context.registerVariable(new sys_var_bool_ptr("enable", &enabled));
337
context.registerVariable(new sys_var_bool_ptr("debug_enable", &debug_enabled));
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));
315
listen_obj= new ListenConsole("console");
316
context.add(listen_obj);
345
static void init_options(drizzled::module::option_context &context)
348
po::value<bool>(&enabled)->default_value(false)->zero_tokens(),
349
N_("Enable the console."));
351
po::value<bool>(&debug_enabled)->default_value(false)->zero_tokens(),
352
N_("Turn on extra debugging."));
355
N_("User to use for auth."));
358
N_("Password to use for auth."));
361
N_("Default database to use."));
320
static DRIZZLE_SYSVAR_BOOL(enable, enabled, PLUGIN_VAR_NOCMDARG,
321
N_("Enable the console."), NULL, NULL, false);
323
static DRIZZLE_SYSVAR_BOOL(debug, debug_enabled, PLUGIN_VAR_NOCMDARG,
324
N_("Turn on extra debugging."), NULL, NULL, false);
325
static DRIZZLE_SYSVAR_STR(user, user, PLUGIN_VAR_READONLY,
326
N_("User to use for auth."), NULL, NULL, NULL);
327
static DRIZZLE_SYSVAR_STR(password, password, PLUGIN_VAR_READONLY,
328
N_("Password to use for auth."), NULL, NULL, NULL);
329
static DRIZZLE_SYSVAR_STR(db, db, PLUGIN_VAR_READONLY,
330
N_("Default database to use."), NULL, NULL, NULL);
332
static drizzle_sys_var* vars[]= {
333
DRIZZLE_SYSVAR(enable),
334
DRIZZLE_SYSVAR(debug),
335
DRIZZLE_SYSVAR(user),
336
DRIZZLE_SYSVAR(password),
364
341
DRIZZLE_DECLARE_PLUGIN