~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/auth_file/auth_file.cc

  • Committer: Brian Aker
  • Date: 2010-10-22 07:16:38 UTC
  • mfrom: (1863.1.11 template-sys-var)
  • Revision ID: brian@tangent.org-20101022071638-pk02309d027gs6zf
Merge Monty

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
#include "drizzled/algorithm/sha1.h"
31
31
#include <boost/program_options.hpp>
32
32
#include <drizzled/module/option_map.h>
 
33
#include <drizzled/set_var.h>
33
34
#include <iostream>
34
35
 
35
36
namespace po= boost::program_options;
39
40
namespace auth_file
40
41
{
41
42
 
42
 
static char* users_file= NULL;
43
43
static const char DEFAULT_USERS_FILE[]= SYSCONFDIR "/drizzle.users";
44
44
 
45
45
class AuthFile: public plugin::Authentication
46
46
{
 
47
  const std::string users_file;
 
48
 
47
49
public:
48
50
 
49
 
  AuthFile(string name_arg);
 
51
  AuthFile(string name_arg, string users_file_arg);
50
52
 
51
53
  /**
52
54
   * Retrieve the last error encountered in the class.
91
93
  map<string, string> users;
92
94
};
93
95
 
94
 
AuthFile::AuthFile(string name_arg):
 
96
AuthFile::AuthFile(string name_arg, string users_file_arg):
95
97
  plugin::Authentication(name_arg),
 
98
  users_file(users_file_arg),
96
99
  error(),
97
100
  users()
98
101
{
105
108
 
106
109
bool AuthFile::loadFile(void)
107
110
{
108
 
  ifstream file(users_file);
 
111
  ifstream file(users_file.c_str());
109
112
 
110
113
  if (!file.is_open())
111
114
  {
214
217
{
215
218
  const module::option_map &vm= context.getOptions();
216
219
 
217
 
  if (vm.count("users"))
218
 
  {
219
 
    users_file= const_cast<char *>(vm["users"].as<string>().c_str());
220
 
  }
221
 
 
222
 
  AuthFile *auth_file = new AuthFile("auth_file");
 
220
  AuthFile *auth_file = new AuthFile("auth_file", vm["users"].as<string>());
223
221
  if (!auth_file->loadFile())
224
222
  {
225
223
    errmsg_printf(ERRMSG_LVL_ERROR, _("Could not load auth file: %s\n"),
229
227
  }
230
228
 
231
229
  context.add(auth_file);
 
230
  context.registerVariable(new sys_var_const_string_val("users", vm["users"].as<string>()));
232
231
  return 0;
233
232
}
234
233
 
235
 
static DRIZZLE_SYSVAR_STR(users,
236
 
                          users_file,
237
 
                          PLUGIN_VAR_READONLY,
238
 
                          N_("File to load for usernames and passwords"),
239
 
                          NULL, /* check func */
240
 
                          NULL, /* update func*/
241
 
                          DEFAULT_USERS_FILE /* default */);
242
 
 
243
 
static drizzle_sys_var* sys_variables[]=
244
 
{
245
 
  DRIZZLE_SYSVAR(users),
246
 
  NULL
247
 
};
248
234
 
249
235
static void init_options(drizzled::module::option_context &context)
250
236
{
255
241
 
256
242
} /* namespace auth_file */
257
243
 
258
 
DRIZZLE_PLUGIN(auth_file::init, auth_file::sys_variables, auth_file::init_options);
 
244
DRIZZLE_PLUGIN(auth_file::init, NULL, auth_file::init_options);