1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
-*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
3
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2009 Sun Microsystems
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.
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.
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
21
Sections of this were taken/modified from mod_auth_path for Apache
4
Sections of this where taken/modified from mod_auth_path for Apache
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>
32
#include "drizzled/security_context.h"
33
#include "drizzled/plugin/authentication.h"
35
using namespace drizzled;
39
17
const char *password;
101
79
return PAM_SUCCESS;
104
class Auth_pam : public drizzled::plugin::Authentication
82
class Auth_pam : public Authentication
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)
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;
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;
120
retval= pam_start("drizzle", userinfo.name, &conv_info, &pamh);
95
retval= pam_start("check_user", userinfo.name, &conv_info, &pamh);
122
97
if (retval == PAM_SUCCESS)
123
98
retval= pam_authenticate(pamh, PAM_DISALLOW_NULL_AUTHTOK);
135
static Auth_pam *auth= NULL;
137
static int initialize(drizzled::plugin::Context &context)
139
auth= new Auth_pam("auth_pam");
144
DRIZZLE_DECLARE_PLUGIN
110
static Authentication *auth= NULL;
112
static int initialize(drizzled::plugin::Registry ®istry)
114
auth= new Auth_pam();
119
static int finalize(drizzled::plugin::Registry ®istry)
124
registry.remove(auth);
131
drizzle_declare_plugin(auth_pam)
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 */
156
DRIZZLE_DECLARE_PLUGIN_END;
144
drizzle_declare_plugin_end;