~ubuntu-branches/ubuntu/trusty/drizzle/trusty

« back to all changes in this revision

Viewing changes to plugin/console/console.cc

  • Committer: Bazaar Package Importer
  • Author(s): Monty Taylor
  • Date: 2010-10-02 14:17:48 UTC
  • mfrom: (1.1.1 upstream)
  • mto: (2.1.17 sid)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20101002141748-m6vbfbfjhrw1153e
Tags: 2010.09.1802-1
* New upstream release.
* Removed pid-file argument hack.
* Updated GPL-2 address to be new address.
* Directly copy in drizzledump.1 since debian doesn't have sphinx 1.0 yet.
* Link to jquery from libjs-jquery. Add it as a depend.
* Add drizzled.8 symlink to the install files.

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::Registry &registry)
314
 
{
315
 
  listen_obj= new ListenConsole("console");
316
 
  registry.add(listen_obj);
317
 
  return 0;
318
 
}
319
 
 
320
 
static int deinit(drizzled::plugin::Registry &registry)
321
 
{
322
 
  registry.remove(listen_obj);
323
 
  delete listen_obj;
 
321
static int init(drizzled::module::Context &context)
 
322
{
 
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"));
324
342
  return 0;
325
343
}
326
344
 
327
345
static DRIZZLE_SYSVAR_BOOL(enable, enabled, PLUGIN_VAR_NOCMDARG,
328
346
                           N_("Enable the console."), NULL, NULL, false);
329
 
 
330
347
static DRIZZLE_SYSVAR_BOOL(debug, debug_enabled, PLUGIN_VAR_NOCMDARG,
331
348
                           N_("Turn on extra debugging."), NULL, NULL, false);
332
 
static DRIZZLE_SYSVAR_STR(user, user, PLUGIN_VAR_READONLY,
 
349
 
 
350
static DRIZZLE_SYSVAR_STR(username, username, PLUGIN_VAR_READONLY,
333
351
                          N_("User to use for auth."), NULL, NULL, NULL);
334
352
static DRIZZLE_SYSVAR_STR(password, password, PLUGIN_VAR_READONLY,
335
353
                          N_("Password to use for auth."), NULL, NULL, NULL);
336
354
static DRIZZLE_SYSVAR_STR(db, db, PLUGIN_VAR_READONLY,
337
355
                          N_("Default database to use."), NULL, NULL, NULL);
338
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
 
339
376
static drizzle_sys_var* vars[]= {
340
377
  DRIZZLE_SYSVAR(enable),
341
378
  DRIZZLE_SYSVAR(debug),
342
 
  DRIZZLE_SYSVAR(user),
 
379
  DRIZZLE_SYSVAR(username),
343
380
  DRIZZLE_SYSVAR(password),
344
381
  DRIZZLE_SYSVAR(db),
345
382
  NULL
354
391
  "Console Client",
355
392
  PLUGIN_LICENSE_BSD,
356
393
  init,   /* Plugin Init */
357
 
  deinit, /* Plugin Deinit */
358
394
  vars,   /* system variables */
359
 
  NULL    /* config options */
 
395
  init_options    /* config options */
360
396
}
361
397
DRIZZLE_DECLARE_PLUGIN_END;