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