~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/auth_pam/auth_pam.cc

  • Committer: Monty Taylor
  • Date: 2009-09-22 23:50:12 UTC
  • mto: This revision was merged to the branch mainline in revision 1184.
  • Revision ID: mordred@inaugust.com-20090922235012-i0a3bs91f6krqduc
Fixed multi_malloc.h include guard.
Added include guard checking script.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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/security_context.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;
104
100
class Auth_pam : public drizzled::plugin::Authentication
105
101
{
106
102
public:
107
 
  Auth_pam(std::string name_arg)
108
 
    : drizzled::plugin::Authentication(name_arg) {}
109
 
  virtual bool authenticate(const SecurityContext &sctx,
110
 
                            const std::string &password)
 
103
  virtual bool authenticate(Session *session, const char *password)
111
104
  {
112
105
    int retval;
113
106
    auth_pam_userinfo userinfo= { NULL, NULL };
114
107
    struct pam_conv conv_info= { &auth_pam_talker, (void*)&userinfo };
115
108
    pam_handle_t *pamh= NULL;
116
109
 
117
 
    userinfo.name= sctx.getUser().c_str();
118
 
    userinfo.password= password.c_str();
 
110
    userinfo.name= session->security_ctx.user.c_str();
 
111
    userinfo.password= password;
119
112
 
120
 
    retval= pam_start("drizzle", userinfo.name, &conv_info, &pamh);
 
113
    retval= pam_start("check_user", userinfo.name, &conv_info, &pamh);
121
114
 
122
115
    if (retval == PAM_SUCCESS)
123
116
      retval= pam_authenticate(pamh, PAM_DISALLOW_NULL_AUTHTOK);
134
127
 
135
128
static Auth_pam *auth= NULL;
136
129
 
137
 
static int initialize(drizzled::module::Context &context)
138
 
{
139
 
  auth= new Auth_pam("auth_pam");
140
 
  context.add(auth);
141
 
  return 0;
142
 
}
143
 
 
144
 
DRIZZLE_DECLARE_PLUGIN
145
 
{
146
 
  DRIZZLE_VERSION_ID,
 
130
static int initialize(drizzled::plugin::Registry &registry)
 
131
{
 
132
  auth= new Auth_pam();
 
133
  registry.authentication.add(auth);
 
134
  return 0;
 
135
}
 
136
 
 
137
static int finalize(drizzled::plugin::Registry &registry)
 
138
{
 
139
 
 
140
  if (auth)
 
141
  {
 
142
    registry.authentication.remove(auth);
 
143
    delete auth;
 
144
  }
 
145
 
 
146
  return 0;
 
147
}
 
148
 
 
149
drizzle_declare_plugin(auth_pam)
 
150
{
147
151
  "pam",
148
152
  "0.1",
149
153
  "Brian Aker",
150
154
  "PAM based authenication.",
151
155
  PLUGIN_LICENSE_GPL,
152
156
  initialize, /* Plugin Init */
 
157
  finalize, /* Plugin Deinit */
 
158
  NULL,   /* status variables */
153
159
  NULL,   /* system variables */
154
160
  NULL    /* config options */
155
161
}
156
 
DRIZZLE_DECLARE_PLUGIN_END;
 
162
drizzle_declare_plugin_end;