~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/auth_file/auth_file.cc

  • Committer: Monty Taylor
  • Date: 2010-11-25 01:53:19 UTC
  • mto: (1953.1.2 build)
  • mto: This revision was merged to the branch mainline in revision 1955.
  • Revision ID: mordred@inaugust.com-20101125015319-ia85msn25uemopgc
Re-enabled -Wformat and then cleaned up the carnage.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
#include <iostream>
26
26
 
27
27
#include <boost/program_options.hpp>
28
 
#include <boost/filesystem.hpp>
29
28
 
30
29
#include "drizzled/configmake.h"
31
30
#include "drizzled/plugin/authentication.h"
35
34
#include "drizzled/module/option_map.h"
36
35
 
37
36
namespace po= boost::program_options;
38
 
namespace fs= boost::filesystem;
39
 
 
40
37
using namespace std;
41
38
using namespace drizzled;
42
39
 
43
40
namespace auth_file
44
41
{
45
42
 
46
 
static const fs::path DEFAULT_USERS_FILE= SYSCONFDIR "/drizzle.users";
 
43
static const char DEFAULT_USERS_FILE[]= SYSCONFDIR "/drizzle.users";
47
44
 
48
45
class AuthFile: public plugin::Authentication
49
46
{
50
 
  const fs::path users_file;
 
47
  const std::string users_file;
51
48
 
52
49
public:
53
50
 
54
 
  AuthFile(string name_arg, fs::path users_file_arg);
 
51
  AuthFile(string name_arg, string users_file_arg);
55
52
 
56
53
  /**
57
54
   * Retrieve the last error encountered in the class.
93
90
  /**
94
91
   * Cache or username:password entries from the file.
95
92
   */
96
 
  std::map<string, string> users;
 
93
  map<string, string> users;
97
94
};
98
95
 
99
 
AuthFile::AuthFile(string name_arg, fs::path users_file_arg):
 
96
AuthFile::AuthFile(string name_arg, string users_file_arg):
100
97
  plugin::Authentication(name_arg),
101
98
  users_file(users_file_arg),
102
99
  error(),
111
108
 
112
109
bool AuthFile::loadFile(void)
113
110
{
114
 
  ifstream file(users_file.string().c_str());
 
111
  ifstream file(users_file.c_str());
115
112
 
116
113
  if (!file.is_open())
117
114
  {
118
115
    error = "Could not open users file: ";
119
 
    error += users_file.string();
 
116
    error += users_file;
120
117
    return false;
121
118
  }
122
119
 
140
137
      password = string(line, password_offset + 1);
141
138
    }
142
139
 
143
 
    std::pair<std::map<std::string, std::string>::iterator, bool> result=
144
 
      users.insert(std::pair<std::string, std::string>(username, password));
145
 
 
 
140
    pair<map<string, string>::iterator, bool> result=
 
141
      users.insert(pair<string, string>(username, password));
146
142
    if (result.second == false)
147
143
    {
148
144
      error = "Duplicate entry found in users file: ";
204
200
 
205
201
bool AuthFile::authenticate(const SecurityContext &sctx, const string &password)
206
202
{
207
 
  std::map<std::string, std::string>::const_iterator user= users.find(sctx.getUser());
 
203
  map<string, string>::const_iterator user = users.find(sctx.getUser());
208
204
  if (user == users.end())
209
205
    return false;
210
206
 
221
217
{
222
218
  const module::option_map &vm= context.getOptions();
223
219
 
224
 
  AuthFile *auth_file = new AuthFile("auth_file", fs::path(vm["users"].as<string>()));
 
220
  AuthFile *auth_file = new AuthFile("auth_file", vm["users"].as<string>());
225
221
  if (!auth_file->loadFile())
226
222
  {
227
223
    errmsg_printf(ERRMSG_LVL_ERROR, _("Could not load auth file: %s\n"),
239
235
static void init_options(drizzled::module::option_context &context)
240
236
{
241
237
  context("users", 
242
 
          po::value<string>()->default_value(DEFAULT_USERS_FILE.string()),
 
238
          po::value<string>()->default_value(DEFAULT_USERS_FILE),
243
239
          N_("File to load for usernames and passwords"));
244
240
}
245
241