76f6c9bb1e5426315417c467bda1e1574eed14a4
[citadel.git] / citadel / chkpwd.c
1 /*
2  * chkpwd.c: a setuid helper program for machines which use shadow passwords
3  * by Nathan Bryant, March 1999
4  *
5  * $Id$
6  */
7
8 #include <pwd.h>
9 #include <stdio.h>
10 #include <limits.h>
11 #include <stdlib.h>
12 #include <string.h>
13 #include <syslog.h>
14 #include <unistd.h>
15 #include <sys/types.h>
16
17 #include "auth.h"
18 #include "config.h"
19 #include "citadel.h"
20
21 int main(void)
22 {
23   uid_t uid;
24   struct passwd *pw;
25   char buf[256];
26
27   get_config();
28   uid = getuid();
29
30   if (uid != BBSUID && uid)
31     {
32       pw = getpwuid(uid);
33       openlog("chkpwd", LOG_CONS, LOG_AUTH);
34       syslog(LOG_WARNING, "invoked by %s (uid %u); possible breakin/probe "
35              "attempt", pw != NULL ? pw->pw_name : "?", uid);
36       return 1;
37     }
38
39   if (fgets(buf, sizeof buf, stdin) == NULL)
40     return 1;
41
42   strtok(buf, "\n");
43   uid = atoi(buf);
44
45   if (fgets(buf, sizeof buf, stdin) == NULL)
46     return 1;
47
48   strtok(buf, "\n");
49
50   if (validpw(uid, buf))
51     return 0;
52
53   return 1;
54 }