~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/auth_pam/auth_pam.cc

Merge Stewart's dead code removal

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2009 Sun Microsystems, Inc.
 
4
 *  Copyright (C) 2009 Sun Microsystems
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
22
22
  @TODO: License?
23
23
*/
24
24
 
25
 
#include "config.h"
26
 
 
 
25
#include <drizzled/server_includes.h>
 
26
#include <drizzled/session.h>
 
27
#include <drizzled/plugin/authentication.h>
27
28
#include <security/pam_appl.h>
28
29
#if !defined(__sun) && !defined(__FreeBSD__)
29
30
#include <security/pam_misc.h>
30
31
#endif
31
32
 
32
 
#include "drizzled/identifier.h"
33
 
#include "drizzled/plugin/authentication.h"
34
 
 
35
 
using namespace drizzled;
36
 
 
37
33
typedef struct {
38
34
    const char *name;
39
35
    const char *password;
106
102
public:
107
103
  Auth_pam(std::string name_arg)
108
104
    : drizzled::plugin::Authentication(name_arg) {}
109
 
  virtual bool authenticate(const identifier::User &sctx,
110
 
                            const std::string &password)
 
105
  virtual bool authenticate(Session *session, const char *password)
111
106
  {
112
107
    int retval;
113
108
    auth_pam_userinfo userinfo= { NULL, NULL };
114
109
    struct pam_conv conv_info= { &auth_pam_talker, (void*)&userinfo };
115
110
    pam_handle_t *pamh= NULL;
116
111
 
117
 
    userinfo.name= sctx.username().c_str();
118
 
    userinfo.password= password.c_str();
 
112
    userinfo.name= session->security_ctx.user.c_str();
 
113
    userinfo.password= password;
119
114
 
120
 
    retval= pam_start("drizzle", userinfo.name, &conv_info, &pamh);
 
115
    retval= pam_start("check_user", userinfo.name, &conv_info, &pamh);
121
116
 
122
117
    if (retval == PAM_SUCCESS)
123
118
      retval= pam_authenticate(pamh, PAM_DISALLOW_NULL_AUTHTOK);
134
129
 
135
130
static Auth_pam *auth= NULL;
136
131
 
137
 
static int initialize(drizzled::module::Context &context)
 
132
static int initialize(drizzled::plugin::Registry &registry)
138
133
{
139
134
  auth= new Auth_pam("auth_pam");
140
 
  context.add(auth);
141
 
  return 0;
142
 
}
143
 
 
144
 
DRIZZLE_DECLARE_PLUGIN
145
 
{
146
 
  DRIZZLE_VERSION_ID,
 
135
  registry.add(auth);
 
136
  return 0;
 
137
}
 
138
 
 
139
static int finalize(drizzled::plugin::Registry &registry)
 
140
{
 
141
 
 
142
  if (auth)
 
143
  {
 
144
    registry.remove(auth);
 
145
    delete auth;
 
146
  }
 
147
 
 
148
  return 0;
 
149
}
 
150
 
 
151
drizzle_declare_plugin(auth_pam)
 
152
{
147
153
  "pam",
148
154
  "0.1",
149
155
  "Brian Aker",
150
156
  "PAM based authenication.",
151
157
  PLUGIN_LICENSE_GPL,
152
158
  initialize, /* Plugin Init */
153
 
  NULL,   /* depends */
 
159
  finalize, /* Plugin Deinit */
 
160
  NULL,   /* status variables */
 
161
  NULL,   /* system variables */
154
162
  NULL    /* config options */
155
163
}
156
 
DRIZZLE_DECLARE_PLUGIN_END;
 
164
drizzle_declare_plugin_end;