|
|
@ -38,8 +38,13 @@ static time_t ot_start_time; |
|
|
|
static const size_t SUCCESS_HTTP_HEADER_LENGTH = 80; |
|
|
|
static const size_t SUCCESS_HTTP_HEADER_LENGTH = 80; |
|
|
|
static const size_t SUCCESS_HTTP_SIZE_OFF = 17; |
|
|
|
static const size_t SUCCESS_HTTP_SIZE_OFF = 17; |
|
|
|
static char g_adminip[4] = {0,0,0,0}; |
|
|
|
static char g_adminip[4] = {0,0,0,0}; |
|
|
|
#ifdef WANT_BLACKLISTING |
|
|
|
|
|
|
|
static char *blacklist_filename = NULL; |
|
|
|
#if defined ( WANT_BLACKLISTING ) && defined (WANT_CLOSED_TRACKER ) |
|
|
|
|
|
|
|
#error WANT_BLACKLISTING and WANT_CLOSED_TRACKER are exclusive. |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
#if defined ( WANT_BLACKLISTING ) || defined (WANT_CLOSED_TRACKER ) |
|
|
|
|
|
|
|
static char *accesslist_filename = NULL; |
|
|
|
|
|
|
|
#define WANT_ACCESS_CONTROL |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
/* To always have space for error messages ;) */ |
|
|
|
/* To always have space for error messages ;) */ |
|
|
@ -493,7 +498,13 @@ static void graceful( int s ) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void usage( char *name ) { |
|
|
|
static void usage( char *name ) { |
|
|
|
fprintf( stderr, "Usage: %s [-i ip] [-p port] [-P port] [-d dir] [-A ip]\n", name ); |
|
|
|
fprintf( stderr, "Usage: %s [-i ip] [-p port] [-P port] [-d dir] [-A ip]" |
|
|
|
|
|
|
|
#ifdef WANT_BLACKLISTING |
|
|
|
|
|
|
|
" [-b blacklistfile]" |
|
|
|
|
|
|
|
#elif defined ( WANT_CLOSED_TRACKER ) |
|
|
|
|
|
|
|
" [-w whitelistfile]" |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
"\n", name ); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#define HELPLINE(opt,desc) fprintf(stderr, "\t%-10s%s\n",opt,desc) |
|
|
|
#define HELPLINE(opt,desc) fprintf(stderr, "\t%-10s%s\n",opt,desc) |
|
|
@ -507,6 +518,8 @@ static void help( char *name ) { |
|
|
|
HELPLINE("-A ip","bless an ip address as admin address (e.g. to allow syncs from this address)"); |
|
|
|
HELPLINE("-A ip","bless an ip address as admin address (e.g. to allow syncs from this address)"); |
|
|
|
#ifdef WANT_BLACKLISTING |
|
|
|
#ifdef WANT_BLACKLISTING |
|
|
|
HELPLINE("-b file","specify blacklist file."); |
|
|
|
HELPLINE("-b file","specify blacklist file."); |
|
|
|
|
|
|
|
#elif defined( WANT_CLOSED_TRACKER ) |
|
|
|
|
|
|
|
HELPLINE("-w file","specify whitelist file."); |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
fprintf( stderr, "\nExample: ./opentracker -i 127.0.0.1 -p 6969 -P 6969 -i 10.1.1.23 -p 2710 -p 80\n" ); |
|
|
|
fprintf( stderr, "\nExample: ./opentracker -i 127.0.0.1 -p 6969 -P 6969 -i 10.1.1.23 -p 2710 -p 80\n" ); |
|
|
@ -756,27 +769,25 @@ static void ot_try_bind( char ip[4], uint16 port, int is_tcp ) { |
|
|
|
++ot_sockets_count; |
|
|
|
++ot_sockets_count; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#ifdef WANT_BLACKLISTING |
|
|
|
#ifdef WANT_ACCESS_CONTROL |
|
|
|
/* Read initial black list */ |
|
|
|
/* Read initial access list */ |
|
|
|
void read_blacklist_file( int foo ) { |
|
|
|
void read_accesslist_file( int foo ) { |
|
|
|
FILE * blacklist_filehandle; |
|
|
|
FILE * accesslist_filehandle; |
|
|
|
ot_hash infohash; |
|
|
|
ot_hash infohash; |
|
|
|
foo = foo; |
|
|
|
foo = foo; |
|
|
|
|
|
|
|
|
|
|
|
signal( SIGHUP, SIG_IGN ); |
|
|
|
accesslist_filehandle = fopen( accesslist_filename, "r" ); |
|
|
|
blacklist_filehandle = fopen( blacklist_filename, "r" ); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Free blacklist vector in trackerlogic.c*/ |
|
|
|
/* Free accesslist vector in trackerlogic.c*/ |
|
|
|
blacklist_reset(); |
|
|
|
accesslist_reset(); |
|
|
|
|
|
|
|
|
|
|
|
if( blacklist_filehandle == NULL ) { |
|
|
|
if( accesslist_filehandle == NULL ) { |
|
|
|
fprintf( stderr, "Warning: Can't open blacklist file: %s (but will try to create it later, if necessary and possible).", blacklist_filename ); |
|
|
|
fprintf( stderr, "Warning: Can't open accesslist file: %s (but will try to create it later, if necessary and possible).", accesslist_filename ); |
|
|
|
signal( SIGHUP, read_blacklist_file ); |
|
|
|
|
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* 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), blacklist_filehandle ) ) { |
|
|
|
while( fgets( static_inbuf, sizeof(static_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( static_inbuf[ 2*i ] ) + scan_fromhex( static_inbuf[ 1 + 2*i ] ); |
|
|
@ -787,15 +798,14 @@ void read_blacklist_file( int foo ) { |
|
|
|
if( scan_fromhex( static_inbuf[ 40 ] ) >= 0 ) |
|
|
|
if( scan_fromhex( static_inbuf[ 40 ] ) >= 0 ) |
|
|
|
goto ignore_line; |
|
|
|
goto ignore_line; |
|
|
|
|
|
|
|
|
|
|
|
/* Append blacklist to blacklist vector */ |
|
|
|
/* Append accesslist to accesslist vector */ |
|
|
|
blacklist_addentry( &infohash ); |
|
|
|
accesslist_addentry( &infohash ); |
|
|
|
|
|
|
|
|
|
|
|
ignore_line: |
|
|
|
ignore_line: |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fclose( blacklist_filehandle ); |
|
|
|
fclose( accesslist_filehandle ); |
|
|
|
signal( SIGHUP, read_blacklist_file ); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
@ -806,12 +816,20 @@ int main( int argc, char **argv ) { |
|
|
|
int scanon = 1; |
|
|
|
int scanon = 1; |
|
|
|
|
|
|
|
|
|
|
|
while( scanon ) { |
|
|
|
while( scanon ) { |
|
|
|
switch( getopt( argc, argv, ":i:p:A:P:d:b:h" ) ) { |
|
|
|
switch( getopt( argc, argv, ":i:p:A:P:d:" |
|
|
|
|
|
|
|
#ifdef WANT_BLACKLISTING |
|
|
|
|
|
|
|
"b:" |
|
|
|
|
|
|
|
#elif defined( WANT_CLOSED_TRACKER ) |
|
|
|
|
|
|
|
"w:" |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
"h" ) ) { |
|
|
|
case -1 : scanon = 0; break; |
|
|
|
case -1 : scanon = 0; break; |
|
|
|
case 'i': scan_ip4( optarg, serverip ); break; |
|
|
|
case 'i': scan_ip4( optarg, serverip ); break; |
|
|
|
case 'A': scan_ip4( optarg, g_adminip ); break; |
|
|
|
case 'A': scan_ip4( optarg, g_adminip ); break; |
|
|
|
#ifdef WANT_BLACKLISTING |
|
|
|
#ifdef WANT_BLACKLISTING |
|
|
|
case 'b': blacklist_filename = optarg; break; |
|
|
|
case 'b': accesslist_filename = optarg; break; |
|
|
|
|
|
|
|
#elif defined( WANT_CLOSED_TRACKER ) |
|
|
|
|
|
|
|
case 'w': accesslist_filename = optarg; break; |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
case 'p': ot_try_bind( serverip, (uint16)atol( optarg ), 1 ); break; |
|
|
|
case 'p': ot_try_bind( serverip, (uint16)atol( optarg ), 1 ); break; |
|
|
|
case 'P': ot_try_bind( serverip, (uint16)atol( optarg ), 0 ); break; |
|
|
|
case 'P': ot_try_bind( serverip, (uint16)atol( optarg ), 0 ); break; |
|
|
@ -839,11 +857,11 @@ int main( int argc, char **argv ) { |
|
|
|
} |
|
|
|
} |
|
|
|
endpwent(); |
|
|
|
endpwent(); |
|
|
|
|
|
|
|
|
|
|
|
#ifdef WANT_BLACKLISTING |
|
|
|
#ifdef WANT_ACCESS_CONTROL |
|
|
|
/* Passing "0" since read_blacklist_file also is SIGHUP handler */ |
|
|
|
/* Passing "0" since read_blacklist_file also is SIGHUP handler */ |
|
|
|
if( blacklist_filename ) { |
|
|
|
if( accesslist_filename ) { |
|
|
|
read_blacklist_file( 0 ); |
|
|
|
read_accesslist_file( 0 ); |
|
|
|
signal( SIGHUP, read_blacklist_file ); |
|
|
|
signal( SIGHUP, read_accesslist_file ); |
|
|
|
} |
|
|
|
} |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|