42
43
uint32_t max_column;
43
const std::string &username;
44
const std::string &password;
45
const std::string &schema;
46
const std::string &_catalog;
49
ClientConsole(const std::string &username_arg,
50
const std::string &password_arg,
51
const std::string &schema_arg,
52
const std::string &catalog_arg) :
56
username(username_arg),
57
password(password_arg),
62
52
virtual void printDebug(const char *message)
65
55
cout << "CONSOLE: " << message << endl;
68
catalog::Instance::shared_ptr catalog()
70
identifier::Catalog identifier(_catalog);
71
catalog::Instance::shared_ptr tmp= plugin::Catalog::getInstance(identifier);
74
std::cerr << "Invalid catalog '" << identifier << "', resorting to 'local' catalog" << std::endl;
79
58
virtual int getFileDescriptor(void)
81
60
printDebug("getFileDescriptor");
115
94
virtual bool authenticate(void)
117
96
printDebug("authenticate");
118
identifier::User::shared_ptr user= identifier::User::make_shared();
119
user->setUser(username);
120
session->setUser(user);
122
return session->checkUser(password, schema);
97
session->getSecurityContext().setUser(username);
98
return session->checkUser(password, strlen(password), db);
125
101
virtual bool readCommand(char **packet, uint32_t *packet_length)
151
127
while (cin.eof() == false && cin.fail() == true);
153
if ((*packet_length == 1 && cin.eof() == true) or
154
not strncasecmp(*packet + 1, "quit", 4) or
155
not strncasecmp(*packet + 1, "exit", 4) or
156
not strncasecmp(*packet + 1, "shutdown", sizeof("shutdown") -1))
129
if ((*packet_length == 1 && cin.eof() == true) ||
130
!strncasecmp(*packet + 1, "quit", 4) ||
131
!strncasecmp(*packet + 1, "exit", 4))
159
134
*packet_length= 1;
160
135
(*packet)[0]= COM_SHUTDOWN;
180
153
printDebug("sendEOF");
183
virtual void sendError(const drizzled::error_t sql_errno, const char *err)
156
virtual void sendError(uint32_t sql_errno, const char *err)
185
cout << "Error: " << static_cast<long>(sql_errno) << " " << err << endl;
158
cout << "Error: " << sql_errno << " " << err << endl;
188
161
virtual bool sendFields(List<Item> *list)
291
264
printDebug("wasAborted");
301
269
class ListenConsole: public plugin::Listen
304
const std::string username;
305
const std::string password;
306
const std::string schema;
307
const std::string _catalog;
310
ListenConsole(const std::string &name_arg,
311
const std::string &username_arg,
312
const std::string &password_arg,
313
const std::string &schema_arg,
314
const std::string &catalog_arg) :
315
plugin::Listen(name_arg),
316
username(username_arg),
317
password(password_arg),
319
_catalog(catalog_arg)
274
ListenConsole(const std::string &name_arg) :
275
plugin::Listen(name_arg)
355
316
assert(read(fd, buffer, 1) == 1);
357
return new ClientConsole(username, password, schema, _catalog);
317
return new ClientConsole;
361
321
static int init(drizzled::module::Context &context)
363
323
const module::option_map &vm= context.getOptions();
364
const string username(vm.count("username") ? vm["username"].as<string>() : "");
365
const string password(vm.count("password") ? vm["password"].as<string>() : "");
366
const string schema(vm.count("schema") ? vm["schema"].as<string>() : "");
368
const std::string catalog(vm.count("catalog") ? vm["catalog"].as<string>() : "LOCAL");
370
context.add(new ListenConsole("console", username, password, schema, catalog));
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"));
345
static DRIZZLE_SYSVAR_BOOL(enable, enabled, PLUGIN_VAR_NOCMDARG,
346
N_("Enable the console."), NULL, NULL, false);
347
static DRIZZLE_SYSVAR_BOOL(debug, debug_enabled, PLUGIN_VAR_NOCMDARG,
348
N_("Turn on extra debugging."), NULL, NULL, false);
350
static DRIZZLE_SYSVAR_STR(username, username, PLUGIN_VAR_READONLY,
351
N_("User to use for auth."), NULL, NULL, NULL);
352
static DRIZZLE_SYSVAR_STR(password, password, PLUGIN_VAR_READONLY,
353
N_("Password to use for auth."), NULL, NULL, NULL);
354
static DRIZZLE_SYSVAR_STR(db, db, PLUGIN_VAR_READONLY,
355
N_("Default database to use."), NULL, NULL, NULL);
375
357
static void init_options(drizzled::module::option_context &context)
377
359
context("enable",
386
368
context("password",
387
369
po::value<string>(),
388
370
N_("Password to use for auth."));
391
N_("Default catalog to use."));
394
N_("Default schema to use."));
373
N_("Default database to use."));
376
static drizzle_sys_var* vars[]= {
377
DRIZZLE_SYSVAR(enable),
378
DRIZZLE_SYSVAR(debug),
379
DRIZZLE_SYSVAR(username),
380
DRIZZLE_SYSVAR(password),
397
385
DRIZZLE_DECLARE_PLUGIN
399
387
DRIZZLE_VERSION_ID,
403
391
"Console Client",
404
392
PLUGIN_LICENSE_BSD,
405
393
init, /* Plugin Init */
394
vars, /* system variables */
407
395
init_options /* config options */
409
397
DRIZZLE_DECLARE_PLUGIN_END;