2
Sections of this where taken/modified from mod_auth_path for Apache
6
#include <drizzled/mysql_priv.h>
9
#include <drizzled/plugin.h>
10
#include <drizzled/plugin_authentication.h>
11
#include <security/pam_appl.h>
12
#include <security/pam_misc.h>
20
static int auth_pam_talker(int num_msg,
21
const struct pam_message **msg,
22
struct pam_response **resp,
25
auth_pam_userinfo *userinfo = (auth_pam_userinfo*)appdata_ptr;
26
struct pam_response *response = 0;
29
/* parameter sanity checking */
30
if(!resp || !msg || !userinfo)
33
/* allocate memory to store response */
34
response= (struct pam_response*)malloc(num_msg * sizeof(struct pam_response));
39
for(x= 0; x < num_msg; x++)
41
/* initialize to safe values */
42
response[x].resp_retcode= 0;
45
/* select response based on requested output style */
46
switch(msg[x]->msg_style)
48
case PAM_PROMPT_ECHO_ON:
49
/* on memory allocation failure, auth fails */
50
response[x].resp = strdup(userinfo->name);
52
case PAM_PROMPT_ECHO_OFF:
53
response[x].resp = strdup(userinfo->password);
62
/* everything okay, set PAM response values */
68
static bool authenticate(THD *thd, const char *password)
71
auth_pam_userinfo userinfo= { NULL, NULL };
72
struct pam_conv conv_info= { &auth_pam_talker, (void*)&userinfo };
73
pam_handle_t *pamh= NULL;
75
userinfo.name= thd->main_security_ctx.user;
76
userinfo.password= password;
78
retval= pam_start("check_user", userinfo.name, &conv_info, &pamh);
80
if (retval == PAM_SUCCESS)
81
retval= pam_authenticate(pamh, PAM_DISALLOW_NULL_AUTHTOK);
83
if (retval == PAM_SUCCESS)
84
retval= pam_acct_mgmt(pamh, PAM_DISALLOW_NULL_AUTHTOK);
86
pam_end(pamh, retval);
88
return (retval == PAM_SUCCESS) ? true: false;
91
static int initialize(void *p)
93
authentication_st *auth= (authentication_st *)p;
95
auth->authenticate= authenticate;
100
static int finalize(void *p)
107
mysql_declare_plugin(auth_pam)
113
"PAM based authenication.",
115
initialize, /* Plugin Init */
116
finalize, /* Plugin Deinit */
117
NULL, /* status variables */
118
NULL, /* system variables */
119
NULL /* config options */
121
mysql_declare_plugin_end;