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 /* Try to authenticate the user. When the user is successfully authenticated
20 * this function returns 1. When the authentication fails for whatever reason
21 * the function returns 0.
23 int auth(const char *user
) {
27 struct pam_conv pamc
= {
33 pam_status
= pam_start("vlock", user
, &pamc
, &pamh
);
35 if (pam_status
!= PAM_SUCCESS
) {
36 fprintf(stderr
, "vlock-auth: %s\n", pam_strerror(pamh
, pam_status
));
40 /* put the username before the password prompt */
41 fprintf(stderr
, "%s's ", user
); fflush(stderr
);
42 /* authenticate the user */
43 pam_status
= pam_authenticate(pamh
, 0);
45 if (pam_status
!= PAM_SUCCESS
) {
46 fprintf(stderr
, "vlock-auth: %s\n", pam_strerror(pamh
, pam_status
));
51 pam_end_status
= pam_end(pamh
, pam_status
);
53 if (pam_end_status
!= PAM_SUCCESS
) {
54 fprintf(stderr
, "vlock-auth: %s\n", pam_strerror(pamh
, pam_end_status
));
57 return (pam_status
== PAM_SUCCESS
);