19c97c832763332c383351f891997ad27c1a1188
[citadel.git] / citadel / utils / chkpwd.c
1 /*
2  * a setuid helper program for machines which use shadow passwords
3  * by Nathan Bryant, March 1999
4  *
5  * Copyright (c) 1987-2012 by the citadel.org team
6  *
7  *  This program is open source software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License version 3.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  */
15
16 #include <pwd.h>
17 #include <stdio.h>
18 #include <limits.h>
19 #include <stdlib.h>
20 #include <string.h>
21 #include <syslog.h>
22 #include <unistd.h>
23 #include <sys/types.h>
24
25 #include "auth.h"
26 #include "config.h"
27 #include "citadel_dirs.h"
28 #include "citadel.h"
29
30 int main(void)
31 {
32         uid_t uid;
33         char buf[SIZ];
34
35         while (1) {
36                 buf[0] = '\0';
37                 read(0, &uid, sizeof(uid_t));   /* uid */
38                 read(0, buf, 256);      /* password */
39
40                 if (buf[0] == '\0') 
41                         return (0);
42                 if (validate_password(uid, buf)) {
43                         write(1, "PASS", 4);
44                 }
45                 else {
46                         write(1, "FAIL", 4);
47                 }
48         }
49
50         return(0);
51 }