vlock 2.0
[vlock.git] / src / auth-pam.c
blob66c09474e491830b9c3883ac5a385cc53488e95b
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
10 * the author.
14 #include <stdio.h>
16 #include <security/pam_appl.h>
17 #include <security/pam_misc.h>
19 int auth(const char *user) {
20 pam_handle_t *pamh;
21 int pam_status;
22 int pam_end_status;
23 struct pam_conv pamc = {
24 &misc_conv,
25 NULL
28 /* initialize pam */
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));
33 goto end;
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));
45 end:
46 /* finish pam */
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);