summaryrefslogtreecommitdiff
path: root/ot_accesslist.c
diff options
context:
space:
mode:
Diffstat (limited to 'ot_accesslist.c')
-rw-r--r--ot_accesslist.c31
1 files changed, 19 insertions, 12 deletions
diff --git a/ot_accesslist.c b/ot_accesslist.c
index d991c4e..104a414 100644
--- a/ot_accesslist.c
+++ b/ot_accesslist.c
@@ -14,6 +14,7 @@
14#include "byte.h" 14#include "byte.h"
15#include "scan.h" 15#include "scan.h"
16#include "ip6.h" 16#include "ip6.h"
17#include "mmap.h"
17 18
18/* Opentracker */ 19/* Opentracker */
19#include "trackerlogic.h" 20#include "trackerlogic.h"
@@ -48,17 +49,15 @@ static int accesslist_addentry( ot_vector *al, ot_hash infohash ) {
48 49
49/* Read initial access list */ 50/* Read initial access list */
50static void accesslist_readfile( int sig ) { 51static void accesslist_readfile( int sig ) {
51 FILE * accesslist_filehandle;
52 ot_hash infohash; 52 ot_hash infohash;
53 ot_vector accesslist_tmp; 53 ot_vector accesslist_tmp;
54 void *olddata; 54 void *olddata;
55 char inbuf[512]; 55 char *map, *map_end, *read_offs;
56 size_t maplen;
56 57
57 if( sig != SIGHUP ) return; 58 if( sig != SIGHUP ) return;
58
59 accesslist_filehandle = fopen( g_accesslist_filename, "r" );
60 59
61 if( accesslist_filehandle == NULL ) { 60 if( ( map = mmap_read( g_accesslist_filename, &maplen ) ) == NULL ) {
62 char *wd = getcwd( NULL, 0 ); 61 char *wd = getcwd( NULL, 0 );
63 fprintf( stderr, "Warning: Can't open accesslist file: %s (but will try to create it later, if necessary and possible).\nPWD: %s\n", g_accesslist_filename, wd ); 62 fprintf( stderr, "Warning: Can't open accesslist file: %s (but will try to create it later, if necessary and possible).\nPWD: %s\n", g_accesslist_filename, wd );
64 free( wd ); 63 free( wd );
@@ -68,26 +67,34 @@ static void accesslist_readfile( int sig ) {
68 /* Initialise an empty accesslist vector */ 67 /* Initialise an empty accesslist vector */
69 memset( &accesslist_tmp, 0, sizeof(accesslist_tmp)); 68 memset( &accesslist_tmp, 0, sizeof(accesslist_tmp));
70 69
70 /* No use */
71 map_end = map + maplen - 41;
72 read_offs = map;
73
71 /* We do ignore anything that is not of the form "^[:xdigit:]{40}[^:xdigit:].*" */ 74 /* We do ignore anything that is not of the form "^[:xdigit:]{40}[^:xdigit:].*" */
72 while( fgets( inbuf, sizeof(inbuf), accesslist_filehandle ) ) { 75 while( read_offs < map_end ) {
73 int i; 76 int i;
74 for( i=0; i<(int)sizeof(ot_hash); ++i ) { 77 for( i=0; i<(int)sizeof(ot_hash); ++i ) {
75 int eger = 16 * scan_fromhex( inbuf[ 2*i ] ) + scan_fromhex( inbuf[ 1 + 2*i ] ); 78 int eger = 16 * scan_fromhex( read_offs[ 2*i ] ) + scan_fromhex( read_offs[ 1 + 2*i ] );
76 if( eger < 0 ) 79 if( eger < 0 )
77 continue; 80 continue;
78 infohash[i] = eger; 81 infohash[i] = eger;
79 } 82 }
80 if( scan_fromhex( inbuf[ 40 ] ) >= 0 ) 83
81 continue; 84 read_offs += 40;
82 85
83 /* Append accesslist to accesslist vector */ 86 /* Append accesslist to accesslist vector */
84 accesslist_addentry( &accesslist_tmp, infohash ); 87 if( scan_fromhex( *read_offs ) < 0 )
88 accesslist_addentry( &accesslist_tmp, infohash );
89
90 /* Find start of next line */
91 while( read_offs < map_end && *(read_offs++) != '\n' );
85 } 92 }
86#ifdef _DEBUG 93#ifdef _DEBUG
87 fprintf( stderr, "Added %zd info_hashes to accesslist\n", accesslist_tmp.size ); 94 fprintf( stderr, "Added %zd info_hashes to accesslist\n", accesslist_tmp.size );
88#endif 95#endif
89 96
90 fclose( accesslist_filehandle ); 97 mmap_unmap( map, maplen);
91 98
92 /* Now exchange the accesslist vector in the least race condition prone way */ 99 /* Now exchange the accesslist vector in the least race condition prone way */
93 accesslist.size = 0; 100 accesslist.size = 0;
@@ -156,4 +163,4 @@ int accesslist_isblessed( ot_ip6 ip, ot_permissions permissions ) {
156 return 0; 163 return 0;
157} 164}
158 165
159const char *g_version_accesslist_c = "$Source$: $Revision$\n"; \ No newline at end of file 166const char *g_version_accesslist_c = "$Source$: $Revision$\n";