1 /* auth-shadow.c -- shadow 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
24 #define PWD_BUFFER_SIZE 256
26 int auth(const char *user
) {
27 char buffer
[PWD_BUFFER_SIZE
];
33 /* lock the password buffer */
34 (void) mlock(buffer
, sizeof buffer
);
36 /* write out the prompt */
37 fprintf(stderr
, "%s's Password: ", user
); fflush(stderr
);
39 /* read the password, echo was switched of by vlock-current */
40 if (fgets(buffer
, sizeof buffer
, stdin
) == NULL
)
46 pwlen
= strlen(buffer
);
48 /* strip the newline */
49 if (buffer
[pwlen
-1] == '\n')
50 buffer
[pwlen
-1] = '\0';
52 /* get the shadow password */
53 if ((spw
= getspnam(user
)) == NULL
)
56 /* hash the password */
57 if ((cryptpw
= crypt(buffer
, spw
->sp_pwdp
)) == NULL
) {
58 perror("vlock-auth: crypt()");
62 /* XXX: sp_lstchg, sp_min, sp_inact, sp_expire should also be checked here */
64 result
= strcmp(cryptpw
, spw
->sp_pwdp
) == 0;
67 /* deallocate shadow resources */
71 /* clear the buffer */
72 memset(buffer
, 0, sizeof buffer
);
74 /* unlock the password buffer */
75 (void) munlock(buffer
, sizeof buffer
);