diff options
-rw-r--r-- | opentracker.c | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/opentracker.c b/opentracker.c index 9121103..f69ae70 100644 --- a/opentracker.c +++ b/opentracker.c | |||
@@ -176,7 +176,7 @@ static void httpresponse( const int64 s, struct http_data *h) { | |||
176 | int numwant, tmp, scanon, mode; | 176 | int numwant, tmp, scanon, mode; |
177 | unsigned short port = htons(6881); | 177 | unsigned short port = htons(6881); |
178 | time_t t; | 178 | time_t t; |
179 | size_t reply_size = 0; | 179 | size_t reply_size = 0, reply_off; |
180 | 180 | ||
181 | array_cat0( &h->request ); | 181 | array_cat0( &h->request ); |
182 | c = array_start( &h->request ); | 182 | c = array_start( &h->request ); |
@@ -255,8 +255,10 @@ static void httpresponse( const int64 s, struct http_data *h) { | |||
255 | break; | 255 | break; |
256 | case 6: /* scrape ? */ | 256 | case 6: /* scrape ? */ |
257 | if( byte_diff( data, 6, "scrape") ) HTTPERROR_404; | 257 | if( byte_diff( data, 6, "scrape") ) HTTPERROR_404; |
258 | scanon = 1; | ||
259 | 258 | ||
259 | SCRAPE_WORKAROUND: | ||
260 | |||
261 | scanon = 1; | ||
260 | while( scanon ) { | 262 | while( scanon ) { |
261 | switch( scan_urlencoded_query( &c, data = c, SCAN_SEARCHPATH_PARAM ) ) { | 263 | switch( scan_urlencoded_query( &c, data = c, SCAN_SEARCHPATH_PARAM ) ) { |
262 | case -2: scanon = 0; break; /* TERMINATOR */ | 264 | case -2: scanon = 0; break; /* TERMINATOR */ |
@@ -286,6 +288,8 @@ static void httpresponse( const int64 s, struct http_data *h) { | |||
286 | case 8: | 288 | case 8: |
287 | if( byte_diff(data,8,"announce")) HTTPERROR_404; | 289 | if( byte_diff(data,8,"announce")) HTTPERROR_404; |
288 | 290 | ||
291 | ANNOUNCE_WORKAROUND: | ||
292 | |||
289 | OT_SETIP( &peer, h->ip); | 293 | OT_SETIP( &peer, h->ip); |
290 | OT_SETPORT( &peer, &port ); | 294 | OT_SETPORT( &peer, &port ); |
291 | OT_FLAG( &peer ) = 0; | 295 | OT_FLAG( &peer ) = 0; |
@@ -372,6 +376,9 @@ static void httpresponse( const int64 s, struct http_data *h) { | |||
372 | } | 376 | } |
373 | ot_overall_successfulannounces++; | 377 | ot_overall_successfulannounces++; |
374 | break; | 378 | break; |
379 | case 10: | ||
380 | if( byte_diff(data,10,"scrape.php")) HTTPERROR_404; | ||
381 | goto SCRAPE_WORKAROUND; | ||
375 | case 11: | 382 | case 11: |
376 | if( byte_diff(data,11,"mrtg_scrape")) HTTPERROR_404; | 383 | if( byte_diff(data,11,"mrtg_scrape")) HTTPERROR_404; |
377 | 384 | ||
@@ -380,6 +387,9 @@ static void httpresponse( const int64 s, struct http_data *h) { | |||
380 | "%i\n%i\nUp: %i seconds (%i hours)\nPretuned by german engineers, currently handling %i connections per second.", | 387 | "%i\n%i\nUp: %i seconds (%i hours)\nPretuned by german engineers, currently handling %i connections per second.", |
381 | ot_overall_connections, ot_overall_successfulannounces, (int)t, (int)(t / 3600), (int)ot_overall_connections / ( (int)t ? (int)t : 1 ) ); | 388 | ot_overall_connections, ot_overall_successfulannounces, (int)t, (int)(t / 3600), (int)ot_overall_connections / ( (int)t ? (int)t : 1 ) ); |
382 | break; | 389 | break; |
390 | case 12: | ||
391 | if( byte_diff(data,12,"announce.php")) HTTPERROR_404; | ||
392 | goto ANNOUNCE_WORKAROUND; | ||
383 | default: /* neither *scrape nor announce */ | 393 | default: /* neither *scrape nor announce */ |
384 | HTTPERROR_404; | 394 | HTTPERROR_404; |
385 | } | 395 | } |
@@ -393,7 +403,7 @@ static void httpresponse( const int64 s, struct http_data *h) { | |||
393 | plus dynamic space needed to expand our Content-Length value. We reserve SUCCESS_HTTP_SIZE_OFF for it expansion and calculate | 403 | plus dynamic space needed to expand our Content-Length value. We reserve SUCCESS_HTTP_SIZE_OFF for it expansion and calculate |
394 | the space NOT needed to expand in reply_off | 404 | the space NOT needed to expand in reply_off |
395 | */ | 405 | */ |
396 | size_t reply_off = SUCCESS_HTTP_SIZE_OFF - snprintf( static_scratch, 0, "%zd", reply_size ); | 406 | reply_off = SUCCESS_HTTP_SIZE_OFF - snprintf( static_scratch, 0, "%zd", reply_size ); |
397 | 407 | ||
398 | /* 2. Now we sprintf our header so that sprintf writes its terminating '\0' exactly one byte before content starts. Complete | 408 | /* 2. Now we sprintf our header so that sprintf writes its terminating '\0' exactly one byte before content starts. Complete |
399 | packet size is increased by size of header plus one byte '\n', we will copy over '\0' in next step */ | 409 | packet size is increased by size of header plus one byte '\n', we will copy over '\0' in next step */ |