21.03.2013 Views

Problem - Kevin Tafuro

Problem - Kevin Tafuro

Problem - Kevin Tafuro

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

c<br />

Pointer to an integer that will receive the PAM error code if an error occurs.<br />

If the user is authenticated successfully, spc_pam_login( ) will return a non-NULL<br />

pointer to a pam_handle_t context object. Otherwise, it will return NULL, and you<br />

should consult the rc argument for the error code.<br />

#include <br />

#include <br />

static struct pam_conv spc_pam_conv = { misc_conv, 0 };<br />

pam_handle_t *spc_pam_login(const char *service, const char *user, int *rc) {<br />

pam_handle_t *hndl;<br />

if (!service || !user || !rc) {<br />

if (rc) *rc = PAM_ABORT;<br />

return 0;<br />

}<br />

if ((*rc = pam_start(service, user, &spc_pam_conv, &hndl)) != PAM_SUCCESS) {<br />

pam_end(hndl, *rc);<br />

return 0;<br />

}<br />

if ((*rc = pam_authenticate(hndl, PAM_DISALLOW_NULL_AUTHTOK)) != PAM_SUCCESS) {<br />

pam_end(hndl, *rc);<br />

return 0;<br />

}<br />

*rc = pam_acct_mgmt(hndl, 0);<br />

if (*rc = = PAM_NEW_AUTHTOK_REQD) {<br />

pam_chauthtok(hndl, PAM_CHANGE_EXPIRED_AUTHTOK);<br />

*rc = pam_acct_mgmt(hndl, 0);<br />

}<br />

if (*rc != PAM_SUCCESS) {<br />

pam_end(hndl, *rc);<br />

return 0;<br />

}<br />

if ((*rc = pam_setcred(hndl, PAM_ESTABLISH_CRED)) != PAM_SUCCESS) {<br />

pam_end(hndl, *rc);<br />

return 0;<br />

}<br />

if ((*rc = pam_open_session(hndl, 0)) != PAM_SUCCESS) {<br />

pam_end(hndl, *rc);<br />

return 0;<br />

}<br />

/* no need to set *rc to PAM_SUCCESS; we wouldn't be here if it weren't */<br />

return hndl;<br />

}<br />

This is the Title of the Book, eMatter Edition<br />

Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.<br />

Authenticating with PAM | 413

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!