* Makefile.in, configure.in, chkpwd.c, acconfig.h: support for
[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
29   if ((uid = getuid()) != BBSUID)
30     {
31       pw = getpwuid(uid);
32       openlog("chkpwd", LOG_CONS, LOG_AUTH);
33       syslog(LOG_WARNING, "invoked by %s (uid %u); possible breakin/probe "
34              "attempt", pw != NULL ? pw->pw_name : "?", uid);
35       return 1;
36     }
37
38   if (fgets(buf, sizeof buf, stdin) == NULL)
39     return 1;
40
41   strtok(buf, "\n");
42   uid = atoi(buf);
43
44   if (fgets(buf, sizeof buf, stdin) == NULL)
45     return 1;
46
47   strtok(buf, "\n");
48
49   if (validpw(uid, buf))
50     return 0;
51
52   return 1;
53 }