~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/auth_file/auth_file.cc

  • Committer: Lee Bieber
  • Date: 2010-11-29 16:28:41 UTC
  • mfrom: (1955.2.1 fix-bug)
  • mto: This revision was merged to the branch mainline in revision 1964.
  • Revision ID: kalebral@gmail.com-20101129162841-fnkzftp29c7lt8te
Merge Vijay - fix bug 664049: users_file in auth_file should be an fs::path     

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>
28
29
 
29
30
#include "drizzled/configmake.h"
30
31
#include "drizzled/plugin/authentication.h"
34
35
#include "drizzled/module/option_map.h"
35
36
 
36
37
namespace po= boost::program_options;
 
38
namespace fs= boost::filesystem;
 
39
 
37
40
using namespace std;
38
41
using namespace drizzled;
39
42
 
40
43
namespace auth_file
41
44
{
42
45
 
43
 
static const char DEFAULT_USERS_FILE[]= SYSCONFDIR "/drizzle.users";
 
46
static const fs::path DEFAULT_USERS_FILE= SYSCONFDIR "/drizzle.users";
44
47
 
45
48
class AuthFile: public plugin::Authentication
46
49
{
47
 
  const std::string users_file;
 
50
  const fs::path users_file;
48
51
 
49
52
public:
50
53
 
51
 
  AuthFile(string name_arg, string users_file_arg);
 
54
  AuthFile(string name_arg, fs::path users_file_arg);
52
55
 
53
56
  /**
54
57
   * Retrieve the last error encountered in the class.
93
96
  map<string, string> users;
94
97
};
95
98
 
96
 
AuthFile::AuthFile(string name_arg, string users_file_arg):
 
99
AuthFile::AuthFile(string name_arg, fs::path users_file_arg):
97
100
  plugin::Authentication(name_arg),
98
101
  users_file(users_file_arg),
99
102
  error(),
108
111
 
109
112
bool AuthFile::loadFile(void)
110
113
{
111
 
  ifstream file(users_file.c_str());
 
114
  ifstream file(users_file.string().c_str());
112
115
 
113
116
  if (!file.is_open())
114
117
  {
115
118
    error = "Could not open users file: ";
116
 
    error += users_file;
 
119
    error += users_file.string();
117
120
    return false;
118
121
  }
119
122
 
217
220
{
218
221
  const module::option_map &vm= context.getOptions();
219
222
 
220
 
  AuthFile *auth_file = new AuthFile("auth_file", vm["users"].as<string>());
 
223
  AuthFile *auth_file = new AuthFile("auth_file", fs::path(vm["users"].as<string>()));
221
224
  if (!auth_file->loadFile())
222
225
  {
223
226
    errmsg_printf(ERRMSG_LVL_ERROR, _("Could not load auth file: %s\n"),
235
238
static void init_options(drizzled::module::option_context &context)
236
239
{
237
240
  context("users", 
238
 
          po::value<string>()->default_value(DEFAULT_USERS_FILE),
 
241
          po::value<string>()->default_value(DEFAULT_USERS_FILE.string()),
239
242
          N_("File to load for usernames and passwords"));
240
243
}
241
244