2
Sections of this where taken/modified from mod_auth_path for Apache
5
#define DRIZZLE_SERVER 1
6
#include <drizzled/server_includes.h>
7
#include <drizzled/plugin_authentication.h>
8
#include <security/pam_appl.h>
10
#include <security/pam_misc.h>
18
static int auth_pam_talker(int num_msg,
20
struct pam_message **msg,
22
const struct pam_message **msg,
24
struct pam_response **resp,
27
auth_pam_userinfo *userinfo = (auth_pam_userinfo*)appdata_ptr;
28
struct pam_response *response = 0;
31
/* parameter sanity checking */
32
if(!resp || !msg || !userinfo)
35
/* allocate memory to store response */
36
response= (struct pam_response*)malloc(num_msg * sizeof(struct pam_response));
41
for(x= 0; x < num_msg; x++)
43
/* initialize to safe values */
44
response[x].resp_retcode= 0;
47
/* select response based on requested output style */
48
switch(msg[x]->msg_style)
50
case PAM_PROMPT_ECHO_ON:
51
/* on memory allocation failure, auth fails */
52
response[x].resp = strdup(userinfo->name);
54
case PAM_PROMPT_ECHO_OFF:
55
response[x].resp = strdup(userinfo->password);
64
/* everything okay, set PAM response values */
70
static bool authenticate(THD *thd, const char *password)
73
auth_pam_userinfo userinfo= { NULL, NULL };
74
struct pam_conv conv_info= { &auth_pam_talker, (void*)&userinfo };
75
pam_handle_t *pamh= NULL;
77
userinfo.name= thd->main_security_ctx.user;
78
userinfo.password= password;
80
retval= pam_start("check_user", userinfo.name, &conv_info, &pamh);
82
if (retval == PAM_SUCCESS)
83
retval= pam_authenticate(pamh, PAM_DISALLOW_NULL_AUTHTOK);
85
if (retval == PAM_SUCCESS)
86
retval= pam_acct_mgmt(pamh, PAM_DISALLOW_NULL_AUTHTOK);
88
pam_end(pamh, retval);
90
return (retval == PAM_SUCCESS) ? true: false;
93
static int initialize(void *p)
95
authentication_st *auth= (authentication_st *)p;
97
auth->authenticate= authenticate;
102
static int finalize(void *p)
109
mysql_declare_plugin(auth_pam)
115
"PAM based authenication.",
117
initialize, /* Plugin Init */
118
finalize, /* Plugin Deinit */
119
NULL, /* status variables */
120
NULL, /* system variables */
121
NULL /* config options */
123
mysql_declare_plugin_end;