1 /* auth-pam.c -- PAM authentification routine for vlock,
2 * the VT locking program for linux
4 * This program is copyright (C) 2007 Frank Benkstein, and is free
5 * software which is freely distributable under the terms of the
6 * GNU General Public License version 2, included as the file COPYING in this
7 * distribution. It is NOT public domain software, and any
8 * redistribution not permitted by the GNU General Public License is
9 * expressly forbidden without prior written permission from
16 #include <security/pam_appl.h>
17 #include <security/pam_misc.h>
19 int auth(const char *user
) {
23 struct pam_conv pamc
= {
29 pam_status
= pam_start("vlock", user
, &pamc
, &pamh
);
31 if (pam_status
!= PAM_SUCCESS
) {
32 fprintf(stderr
, "vlock-auth: %s\n", pam_strerror(pamh
, pam_status
));
36 /* put the username before the password prompt */
37 fprintf(stderr
, "%s's ", user
); fflush(stderr
);
38 /* authenticate the user */
39 pam_status
= pam_authenticate(pamh
, 0);
41 if (pam_status
!= PAM_SUCCESS
) {
42 fprintf(stderr
, "vlock-auth: %s\n", pam_strerror(pamh
, pam_status
));
47 pam_end_status
= pam_end(pamh
, pam_status
);
49 if (pam_end_status
!= PAM_SUCCESS
) {
50 fprintf(stderr
, "vlock-auth: %s\n", pam_strerror(pamh
, pam_end_status
));
53 return (pam_status
== PAM_SUCCESS
);