~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/auth_pam/auth_pam.cc

  • Committer: Brian Aker
  • Date: 2009-03-20 18:52:05 UTC
  • mfrom: (950.1.1 mordred)
  • Revision ID: brian@tangent.org-20090320185205-g7o6kq17r25b6odf
Merge Monty

Show diffs side-by-side

added added

removed removed

Lines of Context:
79
79
  return PAM_SUCCESS;
80
80
}
81
81
 
82
 
static bool authenticate(Session *session, const char *password)
 
82
class Auth_pam : public Authentication
83
83
{
84
 
  int retval;
85
 
  auth_pam_userinfo userinfo= { NULL, NULL };
86
 
  struct pam_conv conv_info= { &auth_pam_talker, (void*)&userinfo };
87
 
  pam_handle_t *pamh= NULL;
88
 
 
89
 
  userinfo.name= session->security_ctx.user.c_str();
90
 
  userinfo.password= password;
91
 
 
92
 
  retval= pam_start("check_user", userinfo.name, &conv_info, &pamh);
93
 
 
94
 
  if (retval == PAM_SUCCESS)
95
 
    retval= pam_authenticate(pamh, PAM_DISALLOW_NULL_AUTHTOK);
96
 
 
97
 
  if (retval == PAM_SUCCESS)
98
 
    retval= pam_acct_mgmt(pamh, PAM_DISALLOW_NULL_AUTHTOK);
99
 
 
100
 
  pam_end(pamh, retval);
101
 
 
102
 
  return (retval == PAM_SUCCESS) ? true: false;
103
 
}
 
84
public:
 
85
  virtual bool authenticate(Session *session, const char *password)
 
86
  {
 
87
    int retval;
 
88
    auth_pam_userinfo userinfo= { NULL, NULL };
 
89
    struct pam_conv conv_info= { &auth_pam_talker, (void*)&userinfo };
 
90
    pam_handle_t *pamh= NULL;
 
91
 
 
92
    userinfo.name= session->security_ctx.user.c_str();
 
93
    userinfo.password= password;
 
94
 
 
95
    retval= pam_start("check_user", userinfo.name, &conv_info, &pamh);
 
96
 
 
97
    if (retval == PAM_SUCCESS)
 
98
      retval= pam_authenticate(pamh, PAM_DISALLOW_NULL_AUTHTOK);
 
99
 
 
100
    if (retval == PAM_SUCCESS)
 
101
      retval= pam_acct_mgmt(pamh, PAM_DISALLOW_NULL_AUTHTOK);
 
102
 
 
103
    pam_end(pamh, retval);
 
104
 
 
105
    return (retval == PAM_SUCCESS) ? true: false;
 
106
  }
 
107
};
 
108
 
104
109
 
105
110
static int initialize(void *p)
106
111
{
107
 
  authentication_st *auth= (authentication_st *)p;
 
112
  Authentication **auth= static_cast<Authentication **>(p);
108
113
 
109
 
  auth->authenticate= authenticate;
 
114
  *auth= new Auth_pam();
110
115
 
111
116
  return 0;
112
117
}
113
118
 
114
119
static int finalize(void *p)
115
120
{
116
 
  (void)p;
 
121
  Auth_pam *auth= static_cast<Auth_pam *>(p);
 
122
 
 
123
  if (auth)
 
124
    delete auth;
117
125
 
118
126
  return 0;
119
127
}