2a9c2395f45ce9ba2dd23d4430efb7ae7eee00b9
[citadel.git] / citadel / utils / chkpwd.c
1 // a setuid helper program for machines which use shadow passwords
2 //
3 // Copyright (c) 1987-2022 by Nathan Bryant and the citadel.org team
4 //
5 // This program is open source software.  Use, duplication, or disclosure
6 // is subject to the terms of the GNU General Public License, version 3.
7 // The program is distributed without any warranty, expressed or implied.
8
9 #include <pwd.h>
10 #include <stdio.h>
11 #include <limits.h>
12 #include <stdlib.h>
13 #include <string.h>
14 #include <syslog.h>
15 #include <unistd.h>
16 #include <sys/types.h>
17 #include <libcitadel.h>
18 #include "auth.h"
19 #include "../server/config.h"
20 #include "../server/citadel_dirs.h"
21 #include "../server/citadel.h"
22
23
24 int main(void) {
25         uid_t uid;
26         char buf[SIZ];
27
28         while (1) {
29                 buf[0] = '\0';
30                 read(0, &uid, sizeof(uid_t));   // uid
31                 read(0, buf, 256);              // password
32
33                 if (buf[0] == '\0') {
34                         return (0);
35                 }
36                 if (validate_password(uid, buf)) {
37                         write(1, "PASS", 4);
38                 }
39                 else {
40                         write(1, "FAIL", 4);
41                 }
42         }
43
44         return(0);
45 }