~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/auth_file/auth_file.cc

  • Committer: Stewart Smith
  • Author(s): Marko Mäkelä, Stewart Smith
  • Date: 2010-11-17 05:52:09 UTC
  • mto: (2021.1.2 build)
  • mto: This revision was merged to the branch mainline in revision 1971.
  • Revision ID: stewart@flamingspork.com-20101117055209-69m035q6h7e1txrc
Merge Revision revid:marko.makela@oracle.com-20100629113248-fvl48lnzr44z94gg from MySQL InnoDB

Original revid:marko.makela@oracle.com-20100629113248-fvl48lnzr44z94gg

Original Authors: Marko Mkel <marko.makela@oracle.com>
Original commit message:
Bug#52199 utf32: mbminlen=4, mbmaxlen=4, type->mbminlen=0, type->mbmaxlen=4

Merge and adjust a forgotten change to fix this bug.
rb://393 approved by Jimmy Yang
  ------------------------------------------------------------------------
  r3794 | marko | 2009-01-07 14:14:53 +0000 (Wed, 07 Jan 2009) | 18 lines

  branches/6.0: Allow the minimum length of a multi-byte character to be
  up to 4 bytes. (Bug #35391)

  dtype_t, dict_col_t: Replace mbminlen:2, mbmaxlen:3 with mbminmaxlen:5.
  In this way, the 5 bits can hold two values of 0..4, and the storage size
  of the fields will not cross the 64-bit boundary.  Encode the values as
  DATA_MBMAX * mbmaxlen + mbminlen.  Define the auxiliary macros
  DB_MBMINLEN(mbminmaxlen), DB_MBMAXLEN(mbminmaxlen), and
  DB_MINMAXLEN(mbminlen, mbmaxlen).

  Try to trim and pad UTF-16 and UTF-32 with spaces as appropriate.

  Alexander Barkov suggested the use of cs->cset->fill(cs, buff, len, 0x20).
  ha_innobase::store_key_val_for_row() now does that, but the added function
  row_mysql_pad_col() does not, because it doesn't have the MySQL TABLE object.

  rb://49 approved by Heikki Tuuri
  ------------------------------------------------------------------------

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"
32
 
#include "drizzled/identifier.h"
 
31
#include "drizzled/security_context.h"
33
32
#include "drizzled/util/convert.h"
34
33
#include "drizzled/algorithm/sha1.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.
71
68
  /**
72
69
   * Base class method to check authentication for a user.
73
70
   */
74
 
  bool authenticate(const identifier::User &sctx, const string &password);
 
71
  bool authenticate(const SecurityContext &sctx, const string &password);
75
72
 
76
73
  /**
77
74
   * Verify the local and remote scrambled password match using the MySQL
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: ";
202
198
  return memcmp(local_scrambled_password, scrambled_password_check, SHA1_DIGEST_LENGTH) == 0;
203
199
}
204
200
 
205
 
bool AuthFile::authenticate(const identifier::User &sctx, const string &password)
 
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.username());
 
203
  map<string, string>::const_iterator user = users.find(sctx.getUser());
208
204
  if (user == users.end())
209
205
    return false;
210
206
 
211
 
  if (sctx.getPasswordType() == identifier::User::MYSQL_HASH)
 
207
  if (sctx.getPasswordType() == SecurityContext::MYSQL_HASH)
212
208
    return verifyMySQLHash(user->second, sctx.getPasswordContext(), password);
213
209
 
214
210
  if (password == user->second)
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>()));
225
 
  if (not auth_file->loadFile())
 
220
  AuthFile *auth_file = new AuthFile("auth_file", vm["users"].as<string>());
 
221
  if (!auth_file->loadFile())
226
222
  {
227
 
    errmsg_printf(error::ERROR, _("Could not load auth file: %s\n"),
 
223
    errmsg_printf(ERRMSG_LVL_ERROR, _("Could not load auth file: %s\n"),
228
224
                  auth_file->getError().c_str());
229
225
    delete auth_file;
230
226
    return 1;
232
228
 
233
229
  context.add(auth_file);
234
230
  context.registerVariable(new sys_var_const_string_val("users", vm["users"].as<string>()));
235
 
 
236
231
  return 0;
237
232
}
238
233
 
240
235
static void init_options(drizzled::module::option_context &context)
241
236
{
242
237
  context("users", 
243
 
          po::value<string>()->default_value(DEFAULT_USERS_FILE.string()),
 
238
          po::value<string>()->default_value(DEFAULT_USERS_FILE),
244
239
          N_("File to load for usernames and passwords"));
245
240
}
246
241