~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/auth_pam/auth_pam.cc

  • Committer: Padraig O'Sullivan
  • Date: 2009-09-13 01:03:01 UTC
  • mto: (1126.9.2 captain-20090915-01)
  • mto: This revision was merged to the branch mainline in revision 1133.
  • Revision ID: osullivan.padraig@gmail.com-20090913010301-tcvvezipx1124acy
Added calls to the dtrace delete begin/end probes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
 
1
/*
 
2
 -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
3
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 
 *
4
 
 *  Copyright (C) 2009 Sun Microsystems
5
 
 *
6
 
 *  This program is free software; you can redistribute it and/or modify
7
 
 *  it under the terms of the GNU General Public License as published by
8
 
 *  the Free Software Foundation; version 2 of the License.
9
 
 *
10
 
 *  This program is distributed in the hope that it will be useful,
11
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 *  GNU General Public License for more details.
14
 
 *
15
 
 *  You should have received a copy of the GNU General Public License
16
 
 *  along with this program; if not, write to the Free Software
17
 
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
 
 */
19
 
 
20
 
/*
21
 
  Sections of this were taken/modified from mod_auth_path for Apache
22
 
  @TODO: License?
 
4
  Sections of this where taken/modified from mod_auth_path for Apache
23
5
*/
24
6
 
25
 
#include "config.h"
26
 
 
 
7
#include <drizzled/server_includes.h>
 
8
#include <drizzled/session.h>
 
9
#include <drizzled/plugin/authentication.h>
27
10
#include <security/pam_appl.h>
28
11
#if !defined(__sun) && !defined(__FreeBSD__)
29
12
#include <security/pam_misc.h>
30
13
#endif
31
14
 
32
 
#include "drizzled/security_context.h"
33
 
#include "drizzled/plugin/authentication.h"
34
 
 
35
 
using namespace drizzled;
36
 
 
37
15
typedef struct {
38
16
    const char *name;
39
17
    const char *password;
101
79
  return PAM_SUCCESS;
102
80
}
103
81
 
104
 
class Auth_pam : public drizzled::plugin::Authentication
 
82
class Auth_pam : public Authentication
105
83
{
106
84
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)
 
85
  virtual bool authenticate(Session *session, const char *password)
111
86
  {
112
87
    int retval;
113
88
    auth_pam_userinfo userinfo= { NULL, NULL };
114
89
    struct pam_conv conv_info= { &auth_pam_talker, (void*)&userinfo };
115
90
    pam_handle_t *pamh= NULL;
116
91
 
117
 
    userinfo.name= sctx.getUser().c_str();
118
 
    userinfo.password= password.c_str();
 
92
    userinfo.name= session->security_ctx.user.c_str();
 
93
    userinfo.password= password;
119
94
 
120
 
    retval= pam_start("drizzle", userinfo.name, &conv_info, &pamh);
 
95
    retval= pam_start("check_user", userinfo.name, &conv_info, &pamh);
121
96
 
122
97
    if (retval == PAM_SUCCESS)
123
98
      retval= pam_authenticate(pamh, PAM_DISALLOW_NULL_AUTHTOK);
132
107
};
133
108
 
134
109
 
135
 
static Auth_pam *auth= NULL;
136
 
 
137
 
static int initialize(drizzled::plugin::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,
 
110
static Authentication *auth= NULL;
 
111
 
 
112
static int initialize(drizzled::plugin::Registry &registry)
 
113
{
 
114
  auth= new Auth_pam();
 
115
  registry.add(auth);
 
116
  return 0;
 
117
}
 
118
 
 
119
static int finalize(drizzled::plugin::Registry &registry)
 
120
{
 
121
 
 
122
  if (auth)
 
123
  {
 
124
    registry.remove(auth);
 
125
    delete auth;
 
126
  }
 
127
 
 
128
  return 0;
 
129
}
 
130
 
 
131
drizzle_declare_plugin(auth_pam)
 
132
{
147
133
  "pam",
148
134
  "0.1",
149
135
  "Brian Aker",
150
136
  "PAM based authenication.",
151
137
  PLUGIN_LICENSE_GPL,
152
138
  initialize, /* Plugin Init */
 
139
  finalize, /* Plugin Deinit */
 
140
  NULL,   /* status variables */
153
141
  NULL,   /* system variables */
154
142
  NULL    /* config options */
155
143
}
156
 
DRIZZLE_DECLARE_PLUGIN_END;
 
144
drizzle_declare_plugin_end;