summaryrefslogtreecommitdiff
path: root/opentracker.c
diff options
context:
space:
mode:
Diffstat (limited to 'opentracker.c')
-rw-r--r--opentracker.c60
1 files changed, 7 insertions, 53 deletions
diff --git a/opentracker.c b/opentracker.c
index 15f4871..3c2aab7 100644
--- a/opentracker.c
+++ b/opentracker.c
@@ -38,6 +38,7 @@
38#include "ot_udp.h" 38#include "ot_udp.h"
39#include "ot_fullscrape.h" 39#include "ot_fullscrape.h"
40#include "ot_iovec.h" 40#include "ot_iovec.h"
41#include "ot_accesslist.h"
41 42
42/* Globals */ 43/* Globals */
43static const size_t SUCCESS_HTTP_HEADER_LENGTH = 80; 44static const size_t SUCCESS_HTTP_HEADER_LENGTH = 80;
@@ -47,14 +48,6 @@ static unsigned int g_adminip_count = 0;
47time_t ot_start_time; 48time_t ot_start_time;
48time_t g_now; 49time_t g_now;
49 50
50#if defined ( WANT_BLACKLISTING ) && defined (WANT_CLOSED_TRACKER )
51 #error WANT_BLACKLISTING and WANT_CLOSED_TRACKER are exclusive.
52#endif
53#if defined ( WANT_BLACKLISTING ) || defined (WANT_CLOSED_TRACKER )
54static char *accesslist_filename = NULL;
55#define WANT_ACCESS_CONTROL
56#endif
57
58#ifndef WANT_TRACKER_SYNC 51#ifndef WANT_TRACKER_SYNC
59#define add_peer_to_torrent(A,B,C) add_peer_to_torrent(A,B) 52#define add_peer_to_torrent(A,B,C) add_peer_to_torrent(A,B)
60#endif 53#endif
@@ -331,12 +324,13 @@ LOG_TO_STDERR( "sync: %d.%d.%d.%d\n", h->ip[0], h->ip[1], h->ip[2], h->ip[3] );
331 } 324 }
332 325
333 if( mode == SYNC_OUT ) { 326 if( mode == SYNC_OUT ) {
327 char *reply;
334 if( !( reply_size = return_changeset_for_tracker( &reply ) ) ) HTTPERROR_500; 328 if( !( reply_size = return_changeset_for_tracker( &reply ) ) ) HTTPERROR_500;
335 return sendmmapdata( s, reply, reply_size ); 329 return sendmmapdata( s, reply, reply_size );
336 } 330 }
337 331
338 /* Simple but proof for now */ 332 /* Simple but proof for now */
339 reply = "OK"; 333 memmove( static_outbuf + SUCCESS_HTTP_HEADER_LENGTH, "OK", 2);
340 reply_size = 2; 334 reply_size = 2;
341 335
342 break; 336 break;
@@ -772,48 +766,14 @@ static void ot_try_bind( char ip[4], uint16 port, int is_tcp ) {
772 ++ot_sockets_count; 766 ++ot_sockets_count;
773} 767}
774 768
775#ifdef WANT_ACCESS_CONTROL
776/* Read initial access list */
777void read_accesslist_file( int foo ) {
778 FILE * accesslist_filehandle;
779 ot_hash infohash;
780 foo = foo;
781
782 accesslist_filehandle = fopen( accesslist_filename, "r" );
783
784 /* Free accesslist vector in trackerlogic.c*/
785 accesslist_reset();
786
787 if( accesslist_filehandle == NULL ) {
788 fprintf( stderr, "Warning: Can't open accesslist file: %s (but will try to create it later, if necessary and possible).", accesslist_filename );
789 return;
790 }
791
792 /* We do ignore anything that is not of the form "^[:xdigit:]{40}[^:xdigit:].*" */
793 while( fgets( static_inbuf, sizeof(static_inbuf), accesslist_filehandle ) ) {
794 int i;
795 for( i=0; i<20; ++i ) {
796 int eger = 16 * scan_fromhex( static_inbuf[ 2*i ] ) + scan_fromhex( static_inbuf[ 1 + 2*i ] );
797 if( eger < 0 )
798 continue;
799 infohash[i] = eger;
800 }
801 if( scan_fromhex( static_inbuf[ 40 ] ) >= 0 )
802 continue;
803
804 /* Append accesslist to accesslist vector */
805 accesslist_addentry( &infohash );
806 }
807
808 fclose( accesslist_filehandle );
809}
810#endif
811
812int main( int argc, char **argv ) { 769int main( int argc, char **argv ) {
813 struct passwd *pws = NULL; 770 struct passwd *pws = NULL;
814 char serverip[4] = {0,0,0,0}; 771 char serverip[4] = {0,0,0,0};
815 char *serverdir = "."; 772 char *serverdir = ".";
816 int scanon = 1; 773 int scanon = 1;
774#ifdef WANT_ACCESS_CONTROL
775 char *accesslist_filename = NULL;
776#endif
817 777
818 while( scanon ) { 778 while( scanon ) {
819 switch( getopt( argc, argv, ":i:p:A:P:d:" 779 switch( getopt( argc, argv, ":i:p:A:P:d:"
@@ -863,13 +823,7 @@ int main( int argc, char **argv ) {
863 } 823 }
864 endpwent(); 824 endpwent();
865 825
866#ifdef WANT_ACCESS_CONTROL 826 accesslist_init( accesslist_filename );
867 /* Passing "0" since read_blacklist_file also is SIGHUP handler */
868 if( accesslist_filename ) {
869 read_accesslist_file( 0 );
870 signal( SIGHUP, read_accesslist_file );
871 }
872#endif
873 827
874 signal( SIGPIPE, SIG_IGN ); 828 signal( SIGPIPE, SIG_IGN );
875 signal( SIGINT, signal_handler ); 829 signal( SIGINT, signal_handler );