mirror of
https://erdgeist.org/gitweb/opentracker
synced 2024-05-10 07:54:50 +00:00
Move blessed IP handling code to accesslist objects
This commit is contained in:
@ -12,13 +12,13 @@
|
||||
#include "scan.h"
|
||||
|
||||
/* Opentracker */
|
||||
#include "trackerlogic.h"
|
||||
#include "ot_accesslist.h"
|
||||
|
||||
/* GLOBAL VARIABLES */
|
||||
#ifdef WANT_ACCESS_CONTROL
|
||||
static char *accesslist_filename = NULL;
|
||||
static ot_vector accesslist;
|
||||
static char static_inbuf[8192];
|
||||
|
||||
static void accesslist_reset( void ) {
|
||||
free( accesslist.data );
|
||||
@ -26,8 +26,8 @@ static void accesslist_reset( void ) {
|
||||
}
|
||||
|
||||
static int accesslist_addentry( ot_hash *infohash ) {
|
||||
int em;
|
||||
void *insert = vector_find_or_insert( &accesslist, infohash, OT_HASH_COMPARE_SIZE, OT_HASH_COMPARE_SIZE, &em );
|
||||
int eger;
|
||||
void *insert = vector_find_or_insert( &accesslist, infohash, OT_HASH_COMPARE_SIZE, OT_HASH_COMPARE_SIZE, &eger );
|
||||
|
||||
if( !insert )
|
||||
return -1;
|
||||
@ -41,6 +41,7 @@ static int accesslist_addentry( ot_hash *infohash ) {
|
||||
static void accesslist_readfile( int foo ) {
|
||||
FILE * accesslist_filehandle;
|
||||
ot_hash infohash;
|
||||
char inbuf[512];
|
||||
foo = foo;
|
||||
|
||||
accesslist_filehandle = fopen( accesslist_filename, "r" );
|
||||
@ -54,15 +55,15 @@ static void accesslist_readfile( int foo ) {
|
||||
}
|
||||
|
||||
/* We do ignore anything that is not of the form "^[:xdigit:]{40}[^:xdigit:].*" */
|
||||
while( fgets( static_inbuf, sizeof(static_inbuf), accesslist_filehandle ) ) {
|
||||
while( fgets( inbuf, sizeof(inbuf), accesslist_filehandle ) ) {
|
||||
int i;
|
||||
for( i=0; i<20; ++i ) {
|
||||
int eger = 16 * scan_fromhex( static_inbuf[ 2*i ] ) + scan_fromhex( static_inbuf[ 1 + 2*i ] );
|
||||
int eger = 16 * scan_fromhex( inbuf[ 2*i ] ) + scan_fromhex( inbuf[ 1 + 2*i ] );
|
||||
if( eger < 0 )
|
||||
continue;
|
||||
infohash[i] = eger;
|
||||
}
|
||||
if( scan_fromhex( static_inbuf[ 40 ] ) >= 0 )
|
||||
if( scan_fromhex( inbuf[ 40 ] ) >= 0 )
|
||||
continue;
|
||||
|
||||
/* Append accesslist to accesslist vector */
|
||||
@ -95,3 +96,23 @@ void accesslist_init( char *accesslist_filename_in ) {
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
static uint32_t g_adminip_addresses[OT_ADMINIP_MAX];
|
||||
static ot_permissions g_adminip_permissions[OT_ADMINIP_MAX];
|
||||
static unsigned int g_adminip_count = 0;
|
||||
|
||||
int accesslist_blessip( char *ip, ot_permissions permissions ) {
|
||||
if( g_adminip_count >= OT_ADMINIP_MAX )
|
||||
return -1;
|
||||
memmove( g_adminip_addresses + g_adminip_count, ip, 4 );
|
||||
g_adminip_permissions[ g_adminip_count++ ] = permissions;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int accesslist_isblessed( char *ip, ot_permissions permissions ) {
|
||||
unsigned int i;
|
||||
for( i=0; i<g_adminip_count; ++i )
|
||||
if( !memcmp( g_adminip_addresses + i, ip, 4) && ( g_adminip_permissions[ i ] & permissions ) )
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
@ -4,8 +4,6 @@
|
||||
#ifndef __OT_ACCESSLIST_H__
|
||||
#define __OT_ACCESSLIST_H__
|
||||
|
||||
#include "trackerlogic.h"
|
||||
|
||||
#if defined ( WANT_BLACKLISTING ) && defined (WANT_CLOSED_TRACKER )
|
||||
#error WANT_BLACKLISTING and WANT_CLOSED_TRACKER are exclusive.
|
||||
#endif
|
||||
@ -19,4 +17,13 @@ int accesslist_hashisvalid( ot_hash *hash );
|
||||
#define accesslist_hashisvalid( hash ) 1
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
OT_PERMISSION_MAY_FULLSCRAPE,
|
||||
OT_PERMISSION_MAY_SYNC,
|
||||
OT_PERMISSION_MAY_STAT
|
||||
} ot_permissions;
|
||||
|
||||
int accesslist_blessip( char * ip, ot_permissions permissions );
|
||||
int accesslist_isblessed( char * ip, ot_permissions permissions );
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user