~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/console/console.cc

  • Committer: Monty Taylor
  • Date: 2010-10-13 17:53:36 UTC
  • mto: This revision was merged to the branch mainline in revision 1845.
  • Revision ID: mordred@inaugust.com-20101013175336-amzhjftgztblvua5
Updated pandora-build files to version 0.161

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
 
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;
34
37
 
35
38
 
36
39
class ClientConsole: public plugin::Client
38
41
  bool is_dead;
39
42
  uint32_t column;
40
43
  uint32_t max_column;
41
 
  const std::string &username;
42
 
  const std::string &password;
43
 
  const std::string &db;
44
44
 
45
45
public:
46
 
  ClientConsole(const std::string &username_arg,
47
 
                const std::string &password_arg,
48
 
                const std::string &db_arg) :
 
46
  ClientConsole():
49
47
    is_dead(false),
50
48
    column(0),
51
 
    max_column(0),
52
 
    username(username_arg),
53
 
    password(password_arg),
54
 
    db(db_arg)
 
49
    max_column(0)
55
50
  {}
56
51
 
57
52
  virtual void printDebug(const char *message)
100
95
  {
101
96
    printDebug("authenticate");
102
97
    session->getSecurityContext().setUser(username);
103
 
    return session->checkUser(password, db);
 
98
    return session->checkUser(password, strlen(password), db);
104
99
  }
105
100
 
106
101
  virtual bool readCommand(char **packet, uint32_t *packet_length)
199
194
 
200
195
    char buff[MAX_FIELD_WIDTH];
201
196
    String str(buff, sizeof(buff), &my_charset_bin);
202
 
    from->val_str_internal(&str);
 
197
    from->val_str(&str);
203
198
    return store(str.ptr(), str.length());
204
199
  }
205
200
 
274
269
class ListenConsole: public plugin::Listen
275
270
{
276
271
  int pipe_fds[2];
277
 
  const std::string username;
278
 
  const std::string password;
279
 
  const std::string db;
280
272
 
281
273
public:
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),
289
 
    db(db_arg)
 
274
  ListenConsole(const std::string &name_arg) :
 
275
    plugin::Listen(name_arg)
290
276
  {
291
277
    pipe_fds[0]= -1;
292
278
  }
298
284
      close(pipe_fds[0]);
299
285
      close(pipe_fds[1]);
300
286
    }
 
287
 
 
288
    /* Cleanup from the module strdup'ing these below */
 
289
    free(username);
 
290
    free(password);
 
291
    free(db);
301
292
  }
302
293
 
303
294
  virtual bool getFileDescriptors(std::vector<int> &fds)
305
296
    if (debug_enabled)
306
297
      enabled= true;
307
298
 
308
 
    if (not enabled)
 
299
    if (enabled == false)
309
300
      return false;
310
301
 
311
302
    if (pipe(pipe_fds) == -1)
323
314
  {
324
315
    char buffer[1];
325
316
    assert(read(fd, buffer, 1) == 1);
326
 
    return new ClientConsole(username, password, db);
 
317
    return new ClientConsole;
327
318
  }
328
319
};
329
320
 
330
321
static int init(drizzled::module::Context &context)
331
322
{
332
323
  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));
 
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());
 
328
  else
 
329
    username= strdup("");
 
330
 
 
331
  if (vm.count("password"))
 
332
    password= strdup(vm["password"].as<string>().c_str());
 
333
  else
 
334
    password= strdup("");
 
335
 
 
336
  if (vm.count("db"))
 
337
    db= strdup(vm["db"].as<string>().c_str());
 
338
  else
 
339
    db= strdup("");
 
340
 
 
341
  context.add(new ListenConsole("console"));
342
342
  return 0;
343
343
}
344
344
 
 
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);
 
349
 
 
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);
 
356
 
345
357
static void init_options(drizzled::module::option_context &context)
346
358
{
347
359
  context("enable",
361
373
          N_("Default database to use."));
362
374
}
363
375
 
 
376
static drizzle_sys_var* vars[]= {
 
377
  DRIZZLE_SYSVAR(enable),
 
378
  DRIZZLE_SYSVAR(debug),
 
379
  DRIZZLE_SYSVAR(username),
 
380
  DRIZZLE_SYSVAR(password),
 
381
  DRIZZLE_SYSVAR(db),
 
382
  NULL
 
383
};
 
384
 
364
385
DRIZZLE_DECLARE_PLUGIN
365
386
{
366
387
  DRIZZLE_VERSION_ID,
370
391
  "Console Client",
371
392
  PLUGIN_LICENSE_BSD,
372
393
  init,   /* Plugin Init */
373
 
  NULL,   /* system variables */
 
394
  vars,   /* system variables */
374
395
  init_options    /* config options */
375
396
}
376
397
DRIZZLE_DECLARE_PLUGIN_END;