summaryrefslogtreecommitdiff
path: root/opentracker.c
diff options
context:
space:
mode:
Diffstat (limited to 'opentracker.c')
-rw-r--r--opentracker.c68
1 files changed, 43 insertions, 25 deletions
diff --git a/opentracker.c b/opentracker.c
index f39dbdb..4ffde37 100644
--- a/opentracker.c
+++ b/opentracker.c
@@ -38,8 +38,13 @@ static time_t ot_start_time;
38static const size_t SUCCESS_HTTP_HEADER_LENGTH = 80; 38static const size_t SUCCESS_HTTP_HEADER_LENGTH = 80;
39static const size_t SUCCESS_HTTP_SIZE_OFF = 17; 39static const size_t SUCCESS_HTTP_SIZE_OFF = 17;
40static char g_adminip[4] = {0,0,0,0}; 40static char g_adminip[4] = {0,0,0,0};
41#ifdef WANT_BLACKLISTING 41
42static char *blacklist_filename = NULL; 42#if defined ( WANT_BLACKLISTING ) && defined (WANT_CLOSED_TRACKER )
43 #error WANT_BLACKLISTING and WANT_CLOSED_TRACKER are exclusive.
44#endif
45#if defined ( WANT_BLACKLISTING ) || defined (WANT_CLOSED_TRACKER )
46static char *accesslist_filename = NULL;
47#define WANT_ACCESS_CONTROL
43#endif 48#endif
44 49
45/* To always have space for error messages ;) */ 50/* To always have space for error messages ;) */
@@ -493,7 +498,13 @@ static void graceful( int s ) {
493} 498}
494 499
495static void usage( char *name ) { 500static void usage( char *name ) {
496 fprintf( stderr, "Usage: %s [-i ip] [-p port] [-P port] [-d dir] [-A ip]\n", name ); 501 fprintf( stderr, "Usage: %s [-i ip] [-p port] [-P port] [-d dir] [-A ip]"
502#ifdef WANT_BLACKLISTING
503 " [-b blacklistfile]"
504#elif defined ( WANT_CLOSED_TRACKER )
505 " [-w whitelistfile]"
506#endif
507 "\n", name );
497} 508}
498 509
499#define HELPLINE(opt,desc) fprintf(stderr, "\t%-10s%s\n",opt,desc) 510#define HELPLINE(opt,desc) fprintf(stderr, "\t%-10s%s\n",opt,desc)
@@ -507,6 +518,8 @@ static void help( char *name ) {
507 HELPLINE("-A ip","bless an ip address as admin address (e.g. to allow syncs from this address)"); 518 HELPLINE("-A ip","bless an ip address as admin address (e.g. to allow syncs from this address)");
508#ifdef WANT_BLACKLISTING 519#ifdef WANT_BLACKLISTING
509 HELPLINE("-b file","specify blacklist file."); 520 HELPLINE("-b file","specify blacklist file.");
521#elif defined( WANT_CLOSED_TRACKER )
522 HELPLINE("-w file","specify whitelist file.");
510#endif 523#endif
511 524
512 fprintf( stderr, "\nExample: ./opentracker -i 127.0.0.1 -p 6969 -P 6969 -i 10.1.1.23 -p 2710 -p 80\n" ); 525 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 ) {
756 ++ot_sockets_count; 769 ++ot_sockets_count;
757} 770}
758 771
759#ifdef WANT_BLACKLISTING 772#ifdef WANT_ACCESS_CONTROL
760/* Read initial black list */ 773/* Read initial access list */
761void read_blacklist_file( int foo ) { 774void read_accesslist_file( int foo ) {
762 FILE * blacklist_filehandle; 775 FILE * accesslist_filehandle;
763 ot_hash infohash; 776 ot_hash infohash;
764 foo = foo; 777 foo = foo;
765 778
766 signal( SIGHUP, SIG_IGN ); 779 accesslist_filehandle = fopen( accesslist_filename, "r" );
767 blacklist_filehandle = fopen( blacklist_filename, "r" );
768 780
769 /* Free blacklist vector in trackerlogic.c*/ 781 /* Free accesslist vector in trackerlogic.c*/
770 blacklist_reset(); 782 accesslist_reset();
771 783
772 if( blacklist_filehandle == NULL ) { 784 if( accesslist_filehandle == NULL ) {
773 fprintf( stderr, "Warning: Can't open blacklist file: %s (but will try to create it later, if necessary and possible).", blacklist_filename ); 785 fprintf( stderr, "Warning: Can't open accesslist file: %s (but will try to create it later, if necessary and possible).", accesslist_filename );
774 signal( SIGHUP, read_blacklist_file );
775 return; 786 return;
776 } 787 }
777 788
778 /* We do ignore anything that is not of the form "^[:xdigit:]{40}[^:xdigit:].*" */ 789 /* We do ignore anything that is not of the form "^[:xdigit:]{40}[^:xdigit:].*" */
779 while( fgets( static_inbuf, sizeof(static_inbuf), blacklist_filehandle ) ) { 790 while( fgets( static_inbuf, sizeof(static_inbuf), accesslist_filehandle ) ) {
780 int i; 791 int i;
781 for( i=0; i<20; ++i ) { 792 for( i=0; i<20; ++i ) {
782 int eger = 16 * scan_fromhex( static_inbuf[ 2*i ] ) + scan_fromhex( static_inbuf[ 1 + 2*i ] ); 793 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 ) {
787 if( scan_fromhex( static_inbuf[ 40 ] ) >= 0 ) 798 if( scan_fromhex( static_inbuf[ 40 ] ) >= 0 )
788 goto ignore_line; 799 goto ignore_line;
789 800
790 /* Append blacklist to blacklist vector */ 801 /* Append accesslist to accesslist vector */
791 blacklist_addentry( &infohash ); 802 accesslist_addentry( &infohash );
792 803
793ignore_line: 804ignore_line:
794 continue; 805 continue;
795 } 806 }
796 807
797 fclose( blacklist_filehandle ); 808 fclose( accesslist_filehandle );
798 signal( SIGHUP, read_blacklist_file );
799} 809}
800#endif 810#endif
801 811
@@ -806,12 +816,20 @@ int main( int argc, char **argv ) {
806 int scanon = 1; 816 int scanon = 1;
807 817
808 while( scanon ) { 818 while( scanon ) {
809 switch( getopt( argc, argv, ":i:p:A:P:d:b:h" ) ) { 819 switch( getopt( argc, argv, ":i:p:A:P:d:"
820#ifdef WANT_BLACKLISTING
821"b:"
822#elif defined( WANT_CLOSED_TRACKER )
823"w:"
824#endif
825 "h" ) ) {
810 case -1 : scanon = 0; break; 826 case -1 : scanon = 0; break;
811 case 'i': scan_ip4( optarg, serverip ); break; 827 case 'i': scan_ip4( optarg, serverip ); break;
812 case 'A': scan_ip4( optarg, g_adminip ); break; 828 case 'A': scan_ip4( optarg, g_adminip ); break;
813#ifdef WANT_BLACKLISTING 829#ifdef WANT_BLACKLISTING
814 case 'b': blacklist_filename = optarg; break; 830 case 'b': accesslist_filename = optarg; break;
831#elif defined( WANT_CLOSED_TRACKER )
832 case 'w': accesslist_filename = optarg; break;
815#endif 833#endif
816 case 'p': ot_try_bind( serverip, (uint16)atol( optarg ), 1 ); break; 834 case 'p': ot_try_bind( serverip, (uint16)atol( optarg ), 1 ); break;
817 case 'P': ot_try_bind( serverip, (uint16)atol( optarg ), 0 ); break; 835 case 'P': ot_try_bind( serverip, (uint16)atol( optarg ), 0 ); break;
@@ -839,11 +857,11 @@ int main( int argc, char **argv ) {
839 } 857 }
840 endpwent(); 858 endpwent();
841 859
842#ifdef WANT_BLACKLISTING 860#ifdef WANT_ACCESS_CONTROL
843 /* Passing "0" since read_blacklist_file also is SIGHUP handler */ 861 /* Passing "0" since read_blacklist_file also is SIGHUP handler */
844 if( blacklist_filename ) { 862 if( accesslist_filename ) {
845 read_blacklist_file( 0 ); 863 read_accesslist_file( 0 );
846 signal( SIGHUP, read_blacklist_file ); 864 signal( SIGHUP, read_accesslist_file );
847 } 865 }
848#endif 866#endif
849 867