* Variable names, comments, documentation, etc... removed the acronym 'BBS'
[citadel.git] / citadel / chkpwd.c
1 /*
2  * $Id$
3  *
4  * a setuid helper program for machines which use shadow passwords
5  * by Nathan Bryant, March 1999
6  *
7  */
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
18 #include "auth.h"
19 #include "config.h"
20 #include "citadel.h"
21
22 int main(void)
23 {
24   uid_t uid;
25   struct passwd *pw;
26   char buf[SIZ];
27
28   get_config();
29   uid = getuid();
30
31   if (uid != CTDLUID && uid)
32     {
33       pw = getpwuid(uid);
34       openlog("chkpwd", LOG_CONS, LOG_AUTH);
35       syslog(LOG_WARNING, "invoked by %s (uid %u); possible breakin/probe "
36              "attempt", pw != NULL ? pw->pw_name : "?", uid);
37       return 1;
38     }
39
40   if (fgets(buf, sizeof buf, stdin) == NULL)
41     return 1;
42
43   strtok(buf, "\n");
44   uid = atoi(buf);
45
46   if (fgets(buf, sizeof buf, stdin) == NULL)
47     return 1;
48
49   strtok(buf, "\n");
50
51   if (validpw(uid, buf))
52     return 0;
53
54   return 1;
55 }