2019-11-23 03:40:23 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* Copyright (C) 2019 by John D. Robertson *
|
|
|
|
* john@rrci.com *
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program; if not, write to the *
|
|
|
|
* Free Software Foundation, Inc., *
|
|
|
|
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
|
|
|
***************************************************************************/
|
2019-12-02 03:29:32 +00:00
|
|
|
#ifndef OFFENTRY_H
|
|
|
|
#define OFFENTRY_H
|
2019-11-23 03:40:23 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
#include "map.h"
|
2019-11-30 19:14:42 +00:00
|
|
|
#include "pdns.h"
|
2019-11-23 03:40:23 +00:00
|
|
|
|
|
|
|
/* One of these for each offense found in a log file */
|
2019-12-02 03:29:32 +00:00
|
|
|
typedef struct _OFFENTRY {
|
2019-11-23 03:40:23 +00:00
|
|
|
unsigned logfile_ndx;
|
|
|
|
char addr[46],
|
|
|
|
cntry[3];
|
|
|
|
unsigned count;
|
2019-11-30 19:14:42 +00:00
|
|
|
|
|
|
|
/* This data populated by PDNS_lookup() */
|
|
|
|
struct {
|
|
|
|
enum PDNS_flags flags;
|
|
|
|
char *name;
|
|
|
|
} dns;
|
|
|
|
|
2019-12-02 03:29:32 +00:00
|
|
|
} OFFENTRY;
|
2019-11-23 03:40:23 +00:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2019-12-02 03:29:32 +00:00
|
|
|
#define OFFENTRY_addr_create(p, addr) \
|
|
|
|
((p)=(OFFENTRY_addr_constructor((p)=malloc(sizeof(OFFENTRY)), addr) ? (p) : ( p ? realloc(OFFENTRY_destructor(p),0) : 0 )))
|
|
|
|
OFFENTRY*
|
|
|
|
OFFENTRY_addr_constructor(OFFENTRY *self, const char *addr);
|
2019-11-23 03:40:23 +00:00
|
|
|
/********************************************************
|
|
|
|
* Prepare for use from an address found in a log entry.
|
|
|
|
*/
|
|
|
|
|
2019-12-02 03:29:32 +00:00
|
|
|
#define OFFENTRY_cache_create(p, cacheFileEntry) \
|
|
|
|
((p)=(OFFENTRY_cache_constructor((p)=malloc(sizeof(OFFENTRY)), cacheFileEntry) ? (p) : ( p ? realloc(OFFENTRY_destructor(p),0) : 0 )))
|
|
|
|
OFFENTRY*
|
|
|
|
OFFENTRY_cache_constructor(OFFENTRY *self, const char *cacheFileEntry);
|
2019-11-23 03:40:23 +00:00
|
|
|
/********************************************************
|
|
|
|
* Prepare for use with entry from cache file.
|
|
|
|
*/
|
|
|
|
|
2019-12-02 03:29:32 +00:00
|
|
|
#define OFFENTRY_destroy(s) \
|
|
|
|
{if(OFFENTRY_destructor(s)) {free(s); (s)=0;}}
|
2019-11-23 03:40:23 +00:00
|
|
|
void*
|
2019-12-02 03:29:32 +00:00
|
|
|
OFFENTRY_destructor(OFFENTRY *self);
|
2019-11-23 03:40:23 +00:00
|
|
|
/********************************************************
|
|
|
|
* Free resources.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
2019-12-02 03:29:32 +00:00
|
|
|
OFFENTRY_register(OFFENTRY *self);
|
2019-11-23 03:40:23 +00:00
|
|
|
/********************************************************
|
|
|
|
* Register the current failure try.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
int
|
2019-12-02 03:29:32 +00:00
|
|
|
OFFENTRY_is_blocked_country(const OFFENTRY *self);
|
2019-11-23 03:40:23 +00:00
|
|
|
/********************************************************
|
|
|
|
* Return 1 if the country is blocked, or 0.
|
|
|
|
*/
|
|
|
|
#endif
|
|
|
|
|
|
|
|
int
|
2019-12-02 03:29:32 +00:00
|
|
|
OFFENTRY_cacheWrite(OFFENTRY *self, FILE *fh);
|
2019-11-23 03:40:23 +00:00
|
|
|
/********************************************************
|
|
|
|
* Write to the cache file in a form we can read later.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
2019-12-02 03:29:32 +00:00
|
|
|
OFFENTRY_print(OFFENTRY *self, FILE *fh);
|
2019-11-23 03:40:23 +00:00
|
|
|
/********************************************************
|
|
|
|
* Print a human readable representation of *self.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
2019-12-02 03:29:32 +00:00
|
|
|
OFFENTRY_map_addr(OFFENTRY *self, MAP *h_rtnMap);
|
2019-11-23 03:40:23 +00:00
|
|
|
/********************************************************
|
2019-12-02 03:29:32 +00:00
|
|
|
* Create a map of OFFENTRY objects with composite
|
2019-11-23 03:40:23 +00:00
|
|
|
* counts by address.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
2019-12-02 03:29:32 +00:00
|
|
|
OFFENTRY_offenseCount(OFFENTRY *self, unsigned *h_sum);
|
2019-11-23 03:40:23 +00:00
|
|
|
/********************************************************
|
|
|
|
* Get a count of all offenses for this entry.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|