chiark / gitweb /
rm some todos
[inn-innduct.git] / nnrpd / track.c
1 /*  $Revision: 6124 $
2 **
3 **  User and post tracking database.
4 */
5
6 #include "config.h"
7 #include "clibrary.h"
8
9 #include "inn/innconf.h"
10 #include "nnrpd.h"
11
12 #define MAX_LEN 180
13
14 /* TrackClient determines whether or not
15    we are interested in tracking the activities
16    of the currently connected host. We have to
17    rely on an external process to set up the
18    entries in the database though which makes
19    this only as reliable as the process that
20    sets this up...
21 */
22
23 /* Format of the input line is <host>:<username>
24 */
25
26 int TrackClient(char *client, char *user)
27 {
28         int RARTon;
29         FILE *fd;
30         char line[MAX_LEN],*p,*pp,*lp;
31         char *dbfile;
32
33         dbfile = concatpath(innconf->pathetc, "nnrpd.track");
34
35         RARTon=false;
36         strcpy(user, "unknown");
37
38         if ((fd=fopen(dbfile,"r"))!=NULL) {
39                 while((fgets(line,(MAX_LEN - 1),fd))!=NULL) {
40                         if (line[0] == '#' || line[0] == '\n') continue;
41                         if ((p=strchr(line,' ')) != NULL) *p='\0';
42                         if ((p=strchr(line,'\n')) != NULL) *p='\0';
43                         if ((p=strchr(line,':')) != NULL) {
44                                 *p++='\0';
45                         } else {
46                                 p=NULL;
47                         }
48                         pp=line;
49                         if ((lp=strchr(pp,'*')) != NULL) {
50                                 pp=++lp;
51                         }
52                         if (strstr(client,pp)!=NULL) {
53                                 RARTon=true;
54                                 if (p != NULL) 
55                                         strcpy(user,p);
56                                 break;
57                         }
58                 }
59                 fclose(fd);
60         } else {
61                 RARTon=false;
62                 syslog(L_NOTICE, "%s No logging - can't read %s", ClientHost, dbfile);
63         }
64
65         free(dbfile);
66         return RARTon;
67 }