~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/console/console.cc

  • Committer: Monty Taylor
  • Date: 2010-10-16 11:09:48 UTC
  • mto: (1859.1.3 build)
  • mto: This revision was merged to the branch mainline in revision 1860.
  • Revision ID: mordred@inaugust.com-20101016110948-e308m10lz8gzz9oy
Added string sys_var type.

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;
37
34
 
38
35
 
39
36
class ClientConsole: public plugin::Client
41
38
  bool is_dead;
42
39
  uint32_t column;
43
40
  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():
 
46
  ClientConsole(const std::string &username_arg,
 
47
                const std::string &password_arg,
 
48
                const std::string &db_arg) :
47
49
    is_dead(false),
48
50
    column(0),
49
 
    max_column(0)
 
51
    max_column(0),
 
52
    username(username_arg),
 
53
    password(password_arg),
 
54
    db(db_arg)
50
55
  {}
51
56
 
52
57
  virtual void printDebug(const char *message)
95
100
  {
96
101
    printDebug("authenticate");
97
102
    session->getSecurityContext().setUser(username);
98
 
    return session->checkUser(password, strlen(password), db);
 
103
    return session->checkUser(password, db);
99
104
  }
100
105
 
101
106
  virtual bool readCommand(char **packet, uint32_t *packet_length)
269
274
class ListenConsole: public plugin::Listen
270
275
{
271
276
  int pipe_fds[2];
 
277
  const std::string username;
 
278
  const std::string password;
 
279
  const std::string db;
272
280
 
273
281
public:
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),
 
289
    db(db_arg)
276
290
  {
277
291
    pipe_fds[0]= -1;
278
292
  }
284
298
      close(pipe_fds[0]);
285
299
      close(pipe_fds[1]);
286
300
    }
287
 
 
288
 
    /* Cleanup from the module strdup'ing these below */
289
 
    free(username);
290
 
    free(password);
291
 
    free(db);
292
301
  }
293
302
 
294
303
  virtual bool getFileDescriptors(std::vector<int> &fds)
314
323
  {
315
324
    char buffer[1];
316
325
    assert(read(fd, buffer, 1) == 1);
317
 
    return new ClientConsole;
 
326
    return new ClientConsole(username, password, db);
318
327
  }
319
328
};
320
329
 
321
330
static int init(drizzled::module::Context &context)
322
331
{
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());
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"));
 
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));
347
342
  return 0;
348
343
}
349
344