~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/console/console.cc

Reverted changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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>
21
22
 
22
23
#include <iostream>
23
24
 
 
25
#include <boost/program_options.hpp>
 
26
 
24
27
using namespace std;
25
28
using namespace drizzled;
26
29
 
 
30
namespace po= boost::program_options;
 
31
 
27
32
static bool enabled= false;
28
33
static bool debug_enabled= false;
29
 
static char* user = (char*)"";
30
 
static char* password = (char*)"";
31
 
static char* db = NULL;
 
34
static char* username= NULL;
 
35
static char* password= NULL;
 
36
static char* db= NULL;
32
37
 
33
38
 
34
39
class ClientConsole: public plugin::Client
89
94
  virtual bool authenticate(void)
90
95
  {
91
96
    printDebug("authenticate");
92
 
    session->getSecurityContext().setUser(user);
 
97
    session->getSecurityContext().setUser(username);
93
98
    return session->checkUser(password, strlen(password), db);
94
99
  }
95
100
 
266
271
  int pipe_fds[2];
267
272
 
268
273
public:
269
 
  ListenConsole(std::string name_arg)
270
 
    : plugin::Listen(name_arg)
 
274
  ListenConsole(const std::string &name_arg) :
 
275
    plugin::Listen(name_arg)
271
276
  {
272
277
    pipe_fds[0]= -1;
273
278
  }
279
284
      close(pipe_fds[0]);
280
285
      close(pipe_fds[1]);
281
286
    }
 
287
 
 
288
    /* Cleanup from the module strdup'ing these below */
 
289
    free(username);
 
290
    free(password);
 
291
    free(db);
282
292
  }
283
293
 
284
294
  virtual bool getFileDescriptors(std::vector<int> &fds)
308
318
  }
309
319
};
310
320
 
311
 
static ListenConsole *listen_obj= NULL;
312
 
 
313
 
static int init(drizzled::plugin::Context &context)
 
321
static int init(drizzled::module::Context &context)
314
322
{
315
 
  listen_obj= new ListenConsole("console");
316
 
  context.add(listen_obj);
 
323
  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"));
317
342
  return 0;
318
343
}
319
344
 
320
345
static DRIZZLE_SYSVAR_BOOL(enable, enabled, PLUGIN_VAR_NOCMDARG,
321
346
                           N_("Enable the console."), NULL, NULL, false);
322
 
 
323
347
static DRIZZLE_SYSVAR_BOOL(debug, debug_enabled, PLUGIN_VAR_NOCMDARG,
324
348
                           N_("Turn on extra debugging."), NULL, NULL, false);
325
 
static DRIZZLE_SYSVAR_STR(user, user, PLUGIN_VAR_READONLY,
 
349
 
 
350
static DRIZZLE_SYSVAR_STR(username, username, PLUGIN_VAR_READONLY,
326
351
                          N_("User to use for auth."), NULL, NULL, NULL);
327
352
static DRIZZLE_SYSVAR_STR(password, password, PLUGIN_VAR_READONLY,
328
353
                          N_("Password to use for auth."), NULL, NULL, NULL);
329
354
static DRIZZLE_SYSVAR_STR(db, db, PLUGIN_VAR_READONLY,
330
355
                          N_("Default database to use."), NULL, NULL, NULL);
331
356
 
 
357
static void init_options(drizzled::module::option_context &context)
 
358
{
 
359
  context("enable",
 
360
          po::value<bool>(&enabled)->default_value(false)->zero_tokens(),
 
361
          N_("Enable the console."));
 
362
  context("debug",
 
363
          po::value<bool>(&debug_enabled)->default_value(false)->zero_tokens(),
 
364
          N_("Turn on extra debugging."));
 
365
  context("username",
 
366
          po::value<string>(),
 
367
          N_("User to use for auth."));
 
368
  context("password",
 
369
          po::value<string>(),
 
370
          N_("Password to use for auth."));
 
371
  context("db",
 
372
          po::value<string>(),
 
373
          N_("Default database to use."));
 
374
}
 
375
 
332
376
static drizzle_sys_var* vars[]= {
333
377
  DRIZZLE_SYSVAR(enable),
334
378
  DRIZZLE_SYSVAR(debug),
335
 
  DRIZZLE_SYSVAR(user),
 
379
  DRIZZLE_SYSVAR(username),
336
380
  DRIZZLE_SYSVAR(password),
337
381
  DRIZZLE_SYSVAR(db),
338
382
  NULL
348
392
  PLUGIN_LICENSE_BSD,
349
393
  init,   /* Plugin Init */
350
394
  vars,   /* system variables */
351
 
  NULL    /* config options */
 
395
  init_options    /* config options */
352
396
}
353
397
DRIZZLE_DECLARE_PLUGIN_END;