|
|
@ -12,13 +12,13 @@
|
|
|
|
#include "scan.h"
|
|
|
|
#include "scan.h"
|
|
|
|
|
|
|
|
|
|
|
|
/* Opentracker */
|
|
|
|
/* Opentracker */
|
|
|
|
|
|
|
|
#include "trackerlogic.h"
|
|
|
|
#include "ot_accesslist.h"
|
|
|
|
#include "ot_accesslist.h"
|
|
|
|
|
|
|
|
|
|
|
|
/* GLOBAL VARIABLES */
|
|
|
|
/* GLOBAL VARIABLES */
|
|
|
|
#ifdef WANT_ACCESS_CONTROL
|
|
|
|
#ifdef WANT_ACCESS_CONTROL
|
|
|
|
static char *accesslist_filename = NULL;
|
|
|
|
static char *accesslist_filename = NULL;
|
|
|
|
static ot_vector accesslist;
|
|
|
|
static ot_vector accesslist;
|
|
|
|
static char static_inbuf[8192];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void accesslist_reset( void ) {
|
|
|
|
static void accesslist_reset( void ) {
|
|
|
|
free( accesslist.data );
|
|
|
|
free( accesslist.data );
|
|
|
@ -26,8 +26,8 @@ static void accesslist_reset( void ) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int accesslist_addentry( ot_hash *infohash ) {
|
|
|
|
static int accesslist_addentry( ot_hash *infohash ) {
|
|
|
|
int em;
|
|
|
|
int eger;
|
|
|
|
void *insert = vector_find_or_insert( &accesslist, infohash, OT_HASH_COMPARE_SIZE, OT_HASH_COMPARE_SIZE, &em );
|
|
|
|
void *insert = vector_find_or_insert( &accesslist, infohash, OT_HASH_COMPARE_SIZE, OT_HASH_COMPARE_SIZE, &eger );
|
|
|
|
|
|
|
|
|
|
|
|
if( !insert )
|
|
|
|
if( !insert )
|
|
|
|
return -1;
|
|
|
|
return -1;
|
|
|
@ -41,6 +41,7 @@ static int accesslist_addentry( ot_hash *infohash ) {
|
|
|
|
static void accesslist_readfile( int foo ) {
|
|
|
|
static void accesslist_readfile( int foo ) {
|
|
|
|
FILE * accesslist_filehandle;
|
|
|
|
FILE * accesslist_filehandle;
|
|
|
|
ot_hash infohash;
|
|
|
|
ot_hash infohash;
|
|
|
|
|
|
|
|
char inbuf[512];
|
|
|
|
foo = foo;
|
|
|
|
foo = foo;
|
|
|
|
|
|
|
|
|
|
|
|
accesslist_filehandle = fopen( accesslist_filename, "r" );
|
|
|
|
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:].*" */
|
|
|
|
/* 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;
|
|
|
|
int i;
|
|
|
|
for( i=0; i<20; ++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 )
|
|
|
|
if( eger < 0 )
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
infohash[i] = eger;
|
|
|
|
infohash[i] = eger;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if( scan_fromhex( static_inbuf[ 40 ] ) >= 0 )
|
|
|
|
if( scan_fromhex( inbuf[ 40 ] ) >= 0 )
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
/* Append accesslist to accesslist vector */
|
|
|
|
/* Append accesslist to accesslist vector */
|
|
|
@ -95,3 +96,23 @@ void accesslist_init( char *accesslist_filename_in ) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
#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;
|
|
|
|
|
|
|
|
}
|
|
|
|