Module: Rpam::Ext

Defined in:
ext/Rpam/rpam_ext.c

Class Method Summary collapse

Class Method Details

.authpam(username, password, servicename) ⇒ Object

Authenticates a user and returns TRUE on success, FALSE on failure



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'ext/Rpam/rpam_ext.c', line 90

VALUE method_authpam(VALUE self, VALUE username, VALUE password, VALUE servicename) {	
	char* rpam_servicename;
    pam_auth_t userinfo = {NULL, NULL};
	struct pam_conv conv_info = {&auth_pam_talker, (void *) &userinfo};
	pam_handle_t *pamh = NULL;
	int result;

	rpam_servicename = StringValuePtr(servicename);
	userinfo.name =    StringValuePtr(username);
	userinfo.pw =      StringValuePtr(password);
 
	if ((result = pam_start(rpam_servicename, userinfo.name, &conv_info, &pamh)) 
            != PAM_SUCCESS) {
       
        return Qfalse;
    }
    if ((result = pam_authenticate(pamh, PAM_DISALLOW_NULL_AUTHTOK))
           !=  PAM_SUCCESS) {

        pam_end(pamh, PAM_SUCCESS); 
        return Qfalse;
    }

   if ((result = pam_acct_mgmt(pamh, PAM_DISALLOW_NULL_AUTHTOK)) 
           != PAM_SUCCESS) {
       
        pam_end(pamh, PAM_SUCCESS);
        return Qfalse;
   }

    pam_end(pamh, PAM_SUCCESS);
    return Qtrue;
}