~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/auth_file/auth_file.cc

few updates and modifications to admin commands

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#include <config.h>
 
20
#include "config.h"
21
21
 
22
22
#include <fstream>
23
23
#include <map>
27
27
#include <boost/program_options.hpp>
28
28
#include <boost/filesystem.hpp>
29
29
 
30
 
#include <drizzled/configmake.h>
31
 
#include <drizzled/plugin/authentication.h>
32
 
#include <drizzled/identifier.h>
33
 
#include <drizzled/util/convert.h>
34
 
#include <drizzled/algorithm/sha1.h>
35
 
#include <drizzled/module/option_map.h>
 
30
#include "drizzled/configmake.h"
 
31
#include "drizzled/plugin/authentication.h"
 
32
#include "drizzled/security_context.h"
 
33
#include "drizzled/util/convert.h"
 
34
#include "drizzled/algorithm/sha1.h"
 
35
#include "drizzled/module/option_map.h"
36
36
 
37
37
namespace po= boost::program_options;
38
38
namespace fs= boost::filesystem;
71
71
  /**
72
72
   * Base class method to check authentication for a user.
73
73
   */
74
 
  bool authenticate(const identifier::User &sctx, const string &password);
 
74
  bool authenticate(const SecurityContext &sctx, const string &password);
75
75
 
76
76
  /**
77
77
   * Verify the local and remote scrambled password match using the MySQL
202
202
  return memcmp(local_scrambled_password, scrambled_password_check, SHA1_DIGEST_LENGTH) == 0;
203
203
}
204
204
 
205
 
bool AuthFile::authenticate(const identifier::User &sctx, const string &password)
 
205
bool AuthFile::authenticate(const SecurityContext &sctx, const string &password)
206
206
{
207
 
  std::map<std::string, std::string>::const_iterator user= users.find(sctx.username());
 
207
  std::map<std::string, std::string>::const_iterator user= users.find(sctx.getUser());
208
208
  if (user == users.end())
209
209
    return false;
210
210
 
211
 
  if (sctx.getPasswordType() == identifier::User::MYSQL_HASH)
 
211
  if (sctx.getPasswordType() == SecurityContext::MYSQL_HASH)
212
212
    return verifyMySQLHash(user->second, sctx.getPasswordContext(), password);
213
213
 
214
214
  if (password == user->second)
222
222
  const module::option_map &vm= context.getOptions();
223
223
 
224
224
  AuthFile *auth_file = new AuthFile("auth_file", fs::path(vm["users"].as<string>()));
225
 
  if (not auth_file->loadFile())
 
225
  if (!auth_file->loadFile())
226
226
  {
227
 
    errmsg_printf(error::ERROR, _("Could not load auth file: %s\n"),
 
227
    errmsg_printf(ERRMSG_LVL_ERROR, _("Could not load auth file: %s\n"),
228
228
                  auth_file->getError().c_str());
229
229
    delete auth_file;
230
230
    return 1;
232
232
 
233
233
  context.add(auth_file);
234
234
  context.registerVariable(new sys_var_const_string_val("users", vm["users"].as<string>()));
235
 
 
236
235
  return 0;
237
236
}
238
237