3779cd0e7b5a693d036e796223d341f782b69379
[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_dirs.h"
21 #include "citadel.h"
22
23 int main(void)
24 {
25   uid_t uid;
26   struct passwd *pw;
27   char buf[SIZ];
28   int relh=0;
29   int home=0;
30   char relhome[PATH_MAX]="";
31   char ctdldir[PATH_MAX]=CTDLDIR;
32
33   /* TODO: should we be able to calculate relative dirs? */
34   calc_dirs_n_files(relh, home, relhome, ctdldir);
35   get_config();
36   uid = getuid();
37
38   if (uid != CTDLUID && uid)
39     {
40       pw = getpwuid(uid);
41       openlog("chkpwd", LOG_CONS, LOG_AUTH);
42       syslog(LOG_WARNING, "invoked by %s (uid %u); possible breakin/probe "
43              "attempt", pw != NULL ? pw->pw_name : "?", uid);
44       return 1;
45     }
46
47   if (fgets(buf, sizeof buf, stdin) == NULL)
48     return 1;
49
50   strtok(buf, "\n");
51   uid = atoi(buf);
52
53   if (fgets(buf, sizeof buf, stdin) == NULL)
54     return 1;
55
56   strtok(buf, "\n");
57
58   if (validpw(uid, buf))
59     return 0;
60
61   return 1;
62 }