File: track.c

package info (click to toggle)
inn2 2.6.3-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 13,228 kB
  • sloc: ansic: 96,526; sh: 15,562; perl: 13,281; makefile: 3,700; yacc: 842; python: 309; lex: 262
file content (71 lines) | stat: -rw-r--r-- 1,528 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*  $Id: track.c 8034 2008-09-20 07:13:18Z iulius $
**
**  User and post tracking database.
*/

#include "config.h"
#include "clibrary.h"

#include "inn/innconf.h"
#include "nnrpd.h"

#define MAX_LEN 180

/*
**  TrackClient determines whether or not
**  we are interested in tracking the activities
**  of the currently connected host.  We have to
**  rely on an external process to set up the
**  entries in the database though, which makes
**  this only as reliable as the process that
**  sets this up...
*/

/*
**  Format of the input line is the following one.
**    <host>:<username>
*/

int
TrackClient(char *client, char *user, size_t len)
{
	int RARTon;
	FILE *fd;
	char line[MAX_LEN],*p,*pp,*lp;
        char *dbfile;

        dbfile = concatpath(innconf->pathetc, "nnrpd.track");

	RARTon=false;
	strlcpy(user, "unknown", len);

	if ((fd=fopen(dbfile,"r"))!=NULL) {
		while((fgets(line,(MAX_LEN - 1),fd))!=NULL) {
			if (line[0] == '#' || line[0] == '\n') continue;
			if ((p=strchr(line,' ')) != NULL) *p='\0';
			if ((p=strchr(line,'\n')) != NULL) *p='\0';
			if ((p=strchr(line,':')) != NULL) {
				*p++='\0';
			} else {
				p=NULL;
			}
			pp=line;
			if ((lp=strchr(pp,'*')) != NULL) {
				pp=++lp;
			}
			if (strstr(client,pp)!=NULL) {
				RARTon=true;
				if (p != NULL) 
                                    strlcpy(user,p,len);
				break;
			}
		}
		fclose(fd);
	} else {
		RARTon=false;
		syslog(L_NOTICE, "%s No logging -- can't read %s", Client.host, dbfile);
	}

        free(dbfile);
	return RARTon;
}