~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/auth_ldap/auth_ldap.cc

  • Committer: Brian Aker
  • Date: 2010-12-17 00:08:06 UTC
  • mfrom: (2002.1.4 clean)
  • Revision ID: brian@tangent.org-20101217000806-fa6kmggjnhsl4q85
Rollup for field encapsulation, monty fix for bzrignore, and Andrew bug
fixes.

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
/* This is needed for simple auth, we're not ready for SASL yet. */
23
23
#define LDAP_DEPRECATED 1
28
28
#include <map>
29
29
#include <string>
30
30
 
31
 
#include <drizzled/plugin/authentication.h>
32
 
#include <drizzled/identifier.h>
33
 
#include <drizzled/util/convert.h>
34
 
#include <drizzled/algorithm/sha1.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
35
 
36
36
#include <drizzled/module/option_map.h>
37
37
#include <boost/program_options.hpp>
99
99
  /**
100
100
   * Base class method to check authentication for a user.
101
101
   */
102
 
  bool authenticate(const identifier::User &sctx, const string &password);
 
102
  bool authenticate(const SecurityContext &sctx, const string &password);
103
103
 
104
104
  /**
105
105
   * Lookup a user in LDAP.
200
200
  return error;
201
201
}
202
202
 
203
 
bool AuthLDAP::authenticate(const identifier::User &sctx, const string &password)
 
203
bool AuthLDAP::authenticate(const SecurityContext &sctx, const string &password)
204
204
{
205
205
  /* See if cache should be emptied. */
206
206
  if (cache_timeout > 0)
222
222
 
223
223
  pthread_rwlock_rdlock(&lock);
224
224
 
225
 
  AuthLDAP::UserCache::const_iterator user= users.find(sctx.username());
 
225
  AuthLDAP::UserCache::const_iterator user= users.find(sctx.getUser());
226
226
  if (user == users.end())
227
227
  {
228
228
    pthread_rwlock_unlock(&lock);
230
230
    pthread_rwlock_wrlock(&lock);
231
231
 
232
232
    /* Make sure the user was not added while we unlocked. */
233
 
    user= users.find(sctx.username());
 
233
    user= users.find(sctx.getUser());
234
234
    if (user == users.end())
235
 
      lookupUser(sctx.username());
 
235
      lookupUser(sctx.getUser());
236
236
 
237
237
    pthread_rwlock_unlock(&lock);
238
238
 
239
239
    pthread_rwlock_rdlock(&lock);
240
240
 
241
241
    /* Get user again because map may have changed while unlocked. */
242
 
    user= users.find(sctx.username());
 
242
    user= users.find(sctx.getUser());
243
243
    if (user == users.end())
244
244
    {
245
245
      pthread_rwlock_unlock(&lock);
253
253
    return false;
254
254
  }
255
255
 
256
 
  if (sctx.getPasswordType() == identifier::User::MYSQL_HASH)
 
256
  if (sctx.getPasswordType() == SecurityContext::MYSQL_HASH)
257
257
  {
258
258
    bool allow= verifyMySQLHash(user->second, sctx.getPasswordContext(), password);
259
259
    pthread_rwlock_unlock(&lock);
288
288
    {
289
289
      if (! connect())
290
290
      {
291
 
        errmsg_printf(error::ERROR, _("Reconnect failed: %s\n"),
 
291
        errmsg_printf(ERRMSG_LVL_ERROR, _("Reconnect failed: %s\n"),
292
292
                      getError().c_str());
293
293
        return;
294
294
      }
307
307
                                       &result);
308
308
    if (return_code != LDAP_SUCCESS)
309
309
    {
310
 
      errmsg_printf(error::ERROR, _("ldap_search_ext_s failed: %s\n"),
 
310
      errmsg_printf(ERRMSG_LVL_ERROR, _("ldap_search_ext_s failed: %s\n"),
311
311
                    ldap_err2string(return_code));
312
312
 
313
313
      /* Only try one reconnect per request. */
413
413
  AuthLDAP *auth_ldap= new AuthLDAP("auth_ldap");
414
414
  if (! auth_ldap->initialize())
415
415
  {
416
 
    errmsg_printf(error::ERROR, _("Could not load auth ldap: %s\n"),
 
416
    errmsg_printf(ERRMSG_LVL_ERROR, _("Could not load auth ldap: %s\n"),
417
417
                  auth_ldap->getError().c_str());
418
418
    delete auth_ldap;
419
419
    return 1;