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
#include <drizzled/plugin/catalog.h>
22
25
#include <iostream>
27
#include <boost/program_options.hpp>
24
29
using namespace std;
25
30
using namespace drizzled;
32
namespace po= boost::program_options;
27
34
static bool enabled= false;
28
35
static bool debug_enabled= false;
29
static char* user = (char*)"";
30
static char* password = (char*)"";
31
static char* db = NULL;
34
38
class ClientConsole: public plugin::Client
38
42
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),
47
62
virtual void printDebug(const char *message)
89
115
virtual bool authenticate(void)
91
117
printDebug("authenticate");
92
session->getSecurityContext().setUser(user);
93
return session->checkUser(password, strlen(password), db);
118
identifier::User::shared_ptr user= identifier::User::make_shared();
119
user->setUser(username);
120
session->setUser(user);
122
return session->checkUser(password, schema);
96
125
virtual bool readCommand(char **packet, uint32_t *packet_length)
122
151
while (cin.eof() == false && cin.fail() == true);
124
if ((*packet_length == 1 && cin.eof() == true) ||
125
!strncasecmp(*packet + 1, "quit", 4) ||
126
!strncasecmp(*packet + 1, "exit", 4))
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
159
*packet_length= 1;
130
160
(*packet)[0]= COM_SHUTDOWN;
259
291
printDebug("wasAborted");
264
301
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;
269
ListenConsole(std::string name_arg)
270
: plugin::Listen(name_arg)
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)
306
355
assert(read(fd, buffer, 1) == 1);
307
return new ClientConsole;
357
return new ClientConsole(username, password, schema, _catalog);
311
static ListenConsole *listen_obj= NULL;
313
static int init(drizzled::plugin::Context &context)
361
static int init(drizzled::module::Context &context)
315
listen_obj= new ListenConsole("console");
316
context.add(listen_obj);
363
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));
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),
375
static void init_options(drizzled::module::option_context &context)
378
po::value<bool>(&enabled)->default_value(false)->zero_tokens(),
379
N_("Enable the console."));
381
po::value<bool>(&debug_enabled)->default_value(false)->zero_tokens(),
382
N_("Turn on extra debugging."));
385
N_("User to use for auth."));
388
N_("Password to use for auth."));
391
N_("Default catalog to use."));
394
N_("Default schema to use."));
341
397
DRIZZLE_DECLARE_PLUGIN
343
399
DRIZZLE_VERSION_ID,
347
403
"Console Client",
348
404
PLUGIN_LICENSE_BSD,
349
405
init, /* Plugin Init */
350
vars, /* system variables */
351
NULL /* config options */
407
init_options /* config options */
353
409
DRIZZLE_DECLARE_PLUGIN_END;