Changeset 231
- Timestamp:
- 09/09/04 11:37:56 (4 years ago)
- Files:
-
- trackerd/trunk/config.h.in (modified) (4 diffs)
- trackerd/trunk/configure (modified) (2 diffs)
- trackerd/trunk/configure.in (modified) (2 diffs)
- trackerd/trunk/trackerd/banlist.c (modified) (5 diffs)
- trackerd/trunk/trackerd/banlist.h (modified) (2 diffs)
- trackerd/trunk/trackerd/commands.c (modified) (23 diffs)
- trackerd/trunk/trackerd/main.c (modified) (14 diffs)
- trackerd/trunk/trackerd/settings.c (modified) (8 diffs)
- trackerd/trunk/trackerd/tracker.c (modified) (32 diffs)
- trackerd/trunk/trackerd/tracker.h (modified) (2 diffs)
- trackerd/trunk/trackerd/utility.c (modified) (4 diffs)
- trackerd/trunk/trackerd/utility.h (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trackerd/trunk/config.h.in
r204 r231 11 11 #undef HAVE_DIRENT_H 12 12 13 /* Define to 1 if you don't have `vprintf' but do have `_doprnt.' */ 14 #undef HAVE_DOPRNT 15 13 16 /* Define to 1 if you have the <errno.h> header file. */ 14 17 #undef HAVE_ERRNO_H … … 16 19 /* Define to 1 if you have the <fcntl.h> header file. */ 17 20 #undef HAVE_FCNTL_H 21 22 /* Define to 1 if fseeko (and presumably ftello) exists and is declared. */ 23 #undef HAVE_FSEEKO 18 24 19 25 /* Define to 1 if you have the `gethostbyaddr' function. */ … … 209 215 #undef HAVE_UNISTD_H 210 216 217 /* Define to 1 if you have the `vprintf' function. */ 218 #undef HAVE_VPRINTF 219 211 220 /* Define to 1 if the system has the type `_Bool'. */ 212 221 #undef HAVE__BOOL … … 270 279 #undef WT_USER 271 280 281 /* Define to 1 to make fseeko visible on some hosts (e.g. glibc 2.2). */ 282 #undef _LARGEFILE_SOURCE 283 272 284 /* Define to empty if `const' does not conform to ANSI C. */ 273 285 #undef const trackerd/trunk/configure
r213 r231 6414 6414 fi 6415 6415 6416 echo "$as_me:$LINENO: checking for _LARGEFILE_SOURCE value needed for large files" >&5 6417 echo $ECHO_N "checking for _LARGEFILE_SOURCE value needed for large files... $ECHO_C" >&6 6418 if test "${ac_cv_sys_largefile_source+set}" = set; then 6419 echo $ECHO_N "(cached) $ECHO_C" >&6 6420 else 6421 while :; do 6422 ac_cv_sys_largefile_source=no 6423 cat >conftest.$ac_ext <<_ACEOF 6424 #line $LINENO "configure" 6425 /* confdefs.h. */ 6426 _ACEOF 6427 cat confdefs.h >>conftest.$ac_ext 6428 cat >>conftest.$ac_ext <<_ACEOF 6429 /* end confdefs.h. */ 6430 #include <stdio.h> 6431 int 6432 main () 6433 { 6434 return !fseeko; 6435 ; 6436 return 0; 6437 } 6438 _ACEOF 6439 rm -f conftest.$ac_objext 6440 if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 6441 (eval $ac_compile) 2>&5 6442 ac_status=$? 6443 echo "$as_me:$LINENO: \$? = $ac_status" >&5 6444 (exit $ac_status); } && 6445 { ac_try='test -s conftest.$ac_objext' 6446 { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 6447 (eval $ac_try) 2>&5 6448 ac_status=$? 6449 echo "$as_me:$LINENO: \$? = $ac_status" >&5 6450 (exit $ac_status); }; }; then 6451 break 6452 else 6453 echo "$as_me: failed program was:" >&5 6454 sed 's/^/| /' conftest.$ac_ext >&5 6455 6456 fi 6457 rm -f conftest.$ac_objext conftest.$ac_ext 6458 cat >conftest.$ac_ext <<_ACEOF 6459 #line $LINENO "configure" 6460 /* confdefs.h. */ 6461 _ACEOF 6462 cat confdefs.h >>conftest.$ac_ext 6463 cat >>conftest.$ac_ext <<_ACEOF 6464 /* end confdefs.h. */ 6465 #define _LARGEFILE_SOURCE 1 6466 #include <stdio.h> 6467 int 6468 main () 6469 { 6470 return !fseeko; 6471 ; 6472 return 0; 6473 } 6474 _ACEOF 6475 rm -f conftest.$ac_objext 6476 if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 6477 (eval $ac_compile) 2>&5 6478 ac_status=$? 6479 echo "$as_me:$LINENO: \$? = $ac_status" >&5 6480 (exit $ac_status); } && 6481 { ac_try='test -s conftest.$ac_objext' 6482 { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 6483 (eval $ac_try) 2>&5 6484 ac_status=$? 6485 echo "$as_me:$LINENO: \$? = $ac_status" >&5 6486 (exit $ac_status); }; }; then 6487 ac_cv_sys_largefile_source=1; break 6488 else 6489 echo "$as_me: failed program was:" >&5 6490 sed 's/^/| /' conftest.$ac_ext >&5 6491 6492 fi 6493 rm -f conftest.$ac_objext conftest.$ac_ext 6494 break 6495 done 6496 fi 6497 echo "$as_me:$LINENO: result: $ac_cv_sys_largefile_source" >&5 6498 echo "${ECHO_T}$ac_cv_sys_largefile_source" >&6 6499 if test "$ac_cv_sys_largefile_source" != no; then 6500 6501 cat >>confdefs.h <<_ACEOF 6502 #define _LARGEFILE_SOURCE $ac_cv_sys_largefile_source 6503 _ACEOF 6504 6505 fi 6506 rm -f conftest* 6507 6508 # We used to try defining _XOPEN_SOURCE=500 too, to work around a bug 6509 # in glibc 2.1.3, but that breaks too many other things. 6510 # If you want fseeko and ftello with glibc, upgrade to a fixed glibc. 6511 echo "$as_me:$LINENO: checking for fseeko" >&5 6512 echo $ECHO_N "checking for fseeko... $ECHO_C" >&6 6513 if test "${ac_cv_func_fseeko+set}" = set; then 6514 echo $ECHO_N "(cached) $ECHO_C" >&6 6515 else 6516 cat >conftest.$ac_ext <<_ACEOF 6517 #line $LINENO "configure" 6518 /* confdefs.h. */ 6519 _ACEOF 6520 cat confdefs.h >>conftest.$ac_ext 6521 cat >>conftest.$ac_ext <<_ACEOF 6522 /* end confdefs.h. */ 6523 #include <stdio.h> 6524 int 6525 main () 6526 { 6527 return fseeko && fseeko (stdin, 0, 0); 6528 ; 6529 return 0; 6530 } 6531 _ACEOF 6532 rm -f conftest.$ac_objext conftest$ac_exeext 6533 if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 6534 (eval $ac_link) 2>&5 6535 ac_status=$? 6536 echo "$as_me:$LINENO: \$? = $ac_status" >&5 6537 (exit $ac_status); } && 6538 { ac_try='test -s conftest$ac_exeext' 6539 { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 6540 (eval $ac_try) 2>&5 6541 ac_status=$? 6542 echo "$as_me:$LINENO: \$? = $ac_status" >&5 6543 (exit $ac_status); }; }; then 6544 ac_cv_func_fseeko=yes 6545 else 6546 echo "$as_me: failed program was:" >&5 6547 sed 's/^/| /' conftest.$ac_ext >&5 6548 6549 ac_cv_func_fseeko=no 6550 fi 6551 rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext 6552 fi 6553 echo "$as_me:$LINENO: result: $ac_cv_func_fseeko" >&5 6554 echo "${ECHO_T}$ac_cv_func_fseeko" >&6 6555 if test $ac_cv_func_fseeko = yes; then 6556 6557 cat >>confdefs.h <<\_ACEOF 6558 #define HAVE_FSEEKO 1 6559 _ACEOF 6560 6561 fi 6562 6416 6563 6417 6564 for ac_header in stdlib.h … … 7473 7620 fi 7474 7621 done 7622 7623 7624 for ac_func in vprintf 7625 do 7626 as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh` 7627 echo "$as_me:$LINENO: checking for $ac_func" >&5 7628 echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6 7629 if eval "test \"\${$as_ac_var+set}\" = set"; then 7630 echo $ECHO_N "(cached) $ECHO_C" >&6 7631 else 7632 cat >conftest.$ac_ext <<_ACEOF 7633 #line $LINENO "configure" 7634 /* confdefs.h. */ 7635 _ACEOF 7636 cat confdefs.h >>conftest.$ac_ext 7637 cat >>conftest.$ac_ext <<_ACEOF 7638 /* end confdefs.h. */ 7639 /* System header to define __stub macros and hopefully few prototypes, 7640 which can conflict with char $ac_func (); below. 7641 Prefer <limits.h> to <assert.h> if __STDC__ is defined, since 7642 <limits.h> exists even on freestanding compilers. */ 7643 #ifdef __STDC__ 7644 # include <limits.h> 7645 #else 7646 # include <assert.h> 7647 #endif 7648 /* Override any gcc2 internal prototype to avoid an error. */ 7649 #ifdef __cplusplus 7650 extern "C" 7651 { 7652 #endif 7653 /* We use char because int might match the return type of a gcc2 7654 builtin and then its argument prototype would still apply. */ 7655 char $ac_func (); 7656 /* The GNU C library defines this for functions which it implements 7657 to always fail with ENOSYS. Some functions are actually named 7658 something starting with __ and the normal name is an alias. */ 7659 #if defined (__stub_$ac_func) || defined (__stub___$ac_func) 7660 choke me 7661 #else 7662 char (*f) () = $ac_func; 7663 #endif 7664 #ifdef __cplusplus 7665 } 7666 #endif 7667 7668 int 7669 main () 7670 { 7671 return f != $ac_func; 7672 ; 7673 return 0; 7674 } 7675 _ACEOF 7676 rm -f conftest.$ac_objext conftest$ac_exeext 7677 if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 7678 (eval $ac_link) 2>&5 7679 ac_status=$? 7680 echo "$as_me:$LINENO: \$? = $ac_status" >&5 7681 (exit $ac_status); } && 7682 { ac_try='test -s conftest$ac_exeext' 7683 { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 7684 (eval $ac_try) 2>&5 7685 ac_status=$? 7686 echo "$as_me:$LINENO: \$? = $ac_status" >&5 7687 (exit $ac_status); }; }; then 7688 eval "$as_ac_var=yes" 7689 else 7690 echo "$as_me: failed program was:" >&5 7691 sed 's/^/| /' conftest.$ac_ext >&5 7692 7693 eval "$as_ac_var=no" 7694 fi 7695 rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext 7696 fi 7697 echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_var'}'`" >&5 7698 echo "${ECHO_T}`eval echo '${'$as_ac_var'}'`" >&6 7699 if test `eval echo '${'$as_ac_var'}'` = yes; then 7700 cat >>confdefs.h <<_ACEOF 7701 #define `echo "HAVE_$ac_func" | $as_tr_cpp` 1 7702 _ACEOF 7703 7704 echo "$as_me:$LINENO: checking for _doprnt" >&5 7705 echo $ECHO_N "checking for _doprnt... $ECHO_C" >&6 7706 if test "${ac_cv_func__doprnt+set}" = set; then 7707 echo $ECHO_N "(cached) $ECHO_C" >&6 7708 else 7709 cat >conftest.$ac_ext <<_ACEOF 7710 #line $LINENO "configure" 7711 /* confdefs.h. */ 7712 _ACEOF 7713 cat confdefs.h >>conftest.$ac_ext 7714 cat >>conftest.$ac_ext <<_ACEOF 7715 /* end confdefs.h. */ 7716 /* System header to define __stub macros and hopefully few prototypes, 7717 which can conflict with char _doprnt (); below. 7718 Prefer <limits.h> to <assert.h> if __STDC__ is defined, since 7719 <limits.h> exists even on freestanding compilers. */ 7720 #ifdef __STDC__ 7721 # include <limits.h> 7722 #else 7723 # include <assert.h> 7724 #endif 7725 /* Override any gcc2 internal prototype to avoid an error. */ 7726 #ifdef __cplusplus 7727 extern "C" 7728 { 7729 #endif 7730 /* We use char because int might match the return type of a gcc2 7731 builtin and then its argument prototype would still apply. */ 7732 char _doprnt (); 7733 /* The GNU C library defines this for functions which it implements 7734 to always fail with ENOSYS. Some functions are actually named 7735 something starting with __ and the normal name is an alias. */ 7736 #if defined (__stub__doprnt) || defined (__stub____doprnt) 7737 choke me 7738 #else 7739 char (*f) () = _doprnt; 7740 #endif 7741 #ifdef __cplusplus 7742 } 7743 #endif 7744 7745 int 7746 main () 7747 { 7748 return f != _doprnt; 7749 ; 7750 return 0; 7751 } 7752 _ACEOF 7753 rm -f conftest.$ac_objext conftest$ac_exeext 7754 if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 7755 (eval $ac_link) 2>&5 7756 ac_status=$? 7757 echo "$as_me:$LINENO: \$? = $ac_status" >&5 7758 (exit $ac_status); } && 7759 { ac_try='test -s conftest$ac_exeext' 7760 { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 7761 (eval $ac_try) 2>&5 7762 ac_status=$? 7763 echo "$as_me:$LINENO: \$? = $ac_status" >&5 7764 (exit $ac_status); }; }; then 7765 ac_cv_func__doprnt=yes 7766 else 7767 echo "$as_me: failed program was:" >&5 7768 sed 's/^/| /' conftest.$ac_ext >&5 7769 7770 ac_cv_func__doprnt=no 7771 fi 7772 rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext 7773 fi 7774 echo "$as_me:$LINENO: result: $ac_cv_func__doprnt" >&5 7775 echo "${ECHO_T}$ac_cv_func__doprnt" >&6 7776 if test $ac_cv_func__doprnt = yes; then 7777 7778 cat >>confdefs.h <<\_ACEOF 7779 #define HAVE_DOPRNT 1 7780 _ACEOF 7781 7782 fi 7783 7784 fi 7785 done 7786 7475 7787 7476 7788 trackerd/trunk/configure.in
r213 r231 317 317 318 318 AC_FUNC_CHOWN 319 AC_FUNC_FSEEKO 319 320 AC_FUNC_MALLOC 320 321 AC_FUNC_LSTAT … … 324 325 AC_FUNC_STAT 325 326 AC_FUNC_STRFTIME 327 AC_FUNC_VPRINTF 326 328 AC_CHECK_FUNCS([ \ 327 329 gethostbyaddr \ trackerd/trunk/trackerd/banlist.c
r209 r231 1 /* $Id: banlist.c,v 1. 3 2004/07/29 20:33:46 morris Exp $ */1 /* $Id: banlist.c,v 1.4 2004/09/09 09:37:56 morris Exp $ */ 2 2 3 3 /* … … 54 54 /* open the banlist file */ 55 55 fp = fopen(wt_settings.banlist, "r"); 56 57 if(!fp) { 58 wt_log_err("Could not open %s: %s", 59 wt_settings.banlist, strerror(errno)); 60 61 goto end; 62 } 56 63 57 if(fp) { 58 while(fgets(buffer, sizeof(buffer), fp) != NULL) { 59 /* remove the linebreak if any */ 60 if((p = strchr(buffer, '\n')) != NULL) 61 *p = '\0'; 62 63 /* ignore comments */ 64 if(buffer[0] == '#' || buffer[0] == '\0') 65 continue; 66 67 if(strchr(buffer, '*')) { 68 /* test wildcard string */ 69 if(wt_ip_matches_wildcard(ip, buffer)) { 70 banned = true; 71 72 break; 73 } 74 } 75 else if(strchr(buffer, '/')) { 76 /* test netmask string */ 77 if(wt_ip_matches_netmask(ip, buffer)) { 78 banned = true; 79 80 break; 81 } 82 } else { 83 /* test absolute string */ 84 if(strcmp(ip, buffer) == 0) { 85 banned = true; 86 87 break; 88 } 64 while(fgets(buffer, sizeof(buffer), fp) != NULL) { 65 /* remove the linebreak if any */ 66 if((p = strchr(buffer, '\n')) != NULL) 67 *p = '\0'; 68 69 /* ignore comments */ 70 if(buffer[0] == '#' || buffer[0] == '\0') 71 continue; 72 73 if(strchr(buffer, '*')) { 74 /* test wildcard string */ 75 if(wt_ip_matches_wildcard(ip, buffer)) { 76 banned = true; 77 78 break; 89 79 } 90 80 } 81 else if(strchr(buffer, '/')) { 82 /* test netmask string */ 83 if(wt_ip_matches_netmask(ip, buffer)) { 84 banned = true; 85 86 break; 87 } 88 } else { 89 /* test absolute string */ 90 if(strcmp(ip, buffer) == 0) { 91 banned = true; 92 93 break; 94 } 95 } 96 } 91 97 92 fclose(fp); 93 } else { 94 wt_log(LOG_WARNING, "Could not open %s: %s", 95 wt_settings.banlist, strerror(errno)); 96 } 98 fclose(fp); 97 99 } 98 100 101 end: 99 102 return banned; 100 103 } … … 105 108 106 109 bool wt_ip_matches_wildcard(char *ip, char *match) { 107 char i[16], m[16]; 108 char *ii, *mm, *p1, *p2; 110 char *i, *ii, *m, *mm, *p1, *p2; 109 111 int matches = 0; 110 112 111 strlcpy(i, ip, sizeof(i)); 112 ii = i; 113 114 strlcpy(m, match, sizeof(m)); 115 mm = m; 113 ii = i = strdup(ip); 114 mm = m = strdup(match); 116 115 117 116 while((p1 = strsep(&ii, ".")) && (p2 = strsep(&mm, "."))) { … … 119 118 matches++; 120 119 } 120 121 free(i); 122 free(m); 121 123 122 124 return matches == 4 ? true : false; … … 126 128 127 129 bool wt_ip_matches_netmask(char *ip, char *match) { 128 char m[32], netmask[16]; 129 char *p; 130 unsigned int ip_u, match_u, netmask_u; 131 132 strlcpy(m, match, sizeof(m)); 133 134 if((p = strchr(m, '/'))) { 135 strlcpy(netmask, p + 1, sizeof(netmask)); 136 137 *p = '\0'; 138 } 139 140 ip_u = wt_iptou(ip); 141 match_u = wt_iptou(m); 142 143 if(strchr(netmask, '.')) 130 char *m, *mm, *block, *netmask; 131 unsigned int ip_u, block_u, netmask_u; 132 unsigned long mask; 133 134 ip_u = wt_iptou(ip); 135 mm = m = strdup(match); 136 block = strsep(&mm, "/"); 137 block_u = wt_iptou(block); 138 netmask = strsep(&mm, "/"); 139 140 if(wt_strtoul(netmask, &mask) > 0) 141 netmask_u = pow(2.0, 32.0) - pow(2.0, 32.0 - mask); 142 else 144 143 netmask_u = wt_iptou(netmask); 145 else 146 netmask_u = pow(2.0, 32.0) - pow(2.0, (float) 32 - strtoul(netmask, NULL, 10));147 148 return ((ip_u & netmask_u) == ( match_u & netmask_u));144 145 free(m); 146 147 return ((ip_u & netmask_u) == (block_u & netmask_u)); 149 148 } 150 151 152 153 unsigned int wt_iptou(char *ip) {154 unsigned int a, b, c, d;155 156 if(sscanf(ip, "%u.%u.%u.%u", &a, &b, &c, &d) == 4)157 return (a << 24) + (b << 16) + (c << 8) + d;158 159 return 0;160 }trackerd/trunk/trackerd/banlist.h
r209 r231 1 /* $Id: banlist.h,v 1. 3 2004/07/29 20:33:46 morris Exp $ */1 /* $Id: banlist.h,v 1.4 2004/09/09 09:37:56 morris Exp $ */ 2 2 3 3 /* … … 39 39 bool wt_ip_matches_wildcard(char *, char *); 40 40 bool wt_ip_matches_netmask(char *, char *); 41 unsigned int wt_iptou(char *);42 41 43 42 #endif /* WT_BANLIST_H */ trackerd/trunk/trackerd/commands.c
r228 r231 1 /* $Id: commands.c,v 1.1 3 2004/08/30 19:28:36 morris Exp $ */1 /* $Id: commands.c,v 1.14 2004/09/09 09:37:56 morris Exp $ */ 2 2 3 3 /* … … 68 68 69 69 void * wt_ctl_thread(void *arg) { 70 wt_client_t *client = (wt_client_t *) arg; 71 struct timeval tv; 72 fd_set rfds; 73 int bytes, pending, state; 74 bool error = false; 70 wt_client_t *client = (wt_client_t *) arg; 71 struct timeval tv; 72 fd_set rfds; 73 char buf[8192]; 74 int bytes, state; 75 bool error = false; 75 76 76 77 /* associate the struct with this thread */ … … 83 84 FD_ZERO(&rfds); 84 85 FD_SET(client->sd, &rfds); 85 tv.tv_sec = 0; 86 tv.tv_usec = 100000; 86 wt_dtotv(0.1, &tv); 87 87 state = select(client->sd + 1, &rfds, NULL, NULL, &tv); 88 88 } while(state == 0 && client->state <= WT_CLIENT_STATE_SAID_HELLO); … … 99 99 } else { 100 100 /* error in TCP communication */ 101 wt_log (LOG_WARNING,"Could not read from %s: %s",101 wt_log_err("Could not read from %s: %s", 102 102 client->ip, strerror(errno)); 103 103 … … 109 109 110 110 /* read from SSL */ 111 bytes = SSL_read(client->ssl, 112 client->buffer + client->buffer_offset, 113 client->buffer_size - client->buffer_offset); 111 bytes = SSL_read(client->ssl, buf, sizeof(buf)); 114 112 115 113 if(bytes == 0) { … … 119 117 else if(bytes < 0) { 120 118 /* error in SSL communication */ 121 wt_log(LOG_WARNING, "Could not read from %s: %s", 122 client->ip, ERR_get_error() != 0 123 ? ERR_reason_error_string(ERR_get_error()) 124 : strerror(errno)); 119 wt_log_err("Could not read from %s: %s", 120 client->ip, wt_ssl_strerror()); 125 121 126 122 error = true; 127 123 break; 128 124 } 129 130 if(client->buffer[client->buffer_offset + bytes - 1] != 4) { 131 /* increase buffer by SSL_pending() bytes or, if we've reached the 16k 132 limit in SSL/TLS, by initial buffer size */ 133 pending = SSL_pending(client->ssl); 134 135 if(pending == 0) 136 pending = WT_BUFFER_SIZE; 137 138 /* increase buffer size and set new offset */ 139 client->buffer_size += pending; 125 126 /* increase buffer size? */ 127 if(client->buffer_offset + bytes >= client->buffer_size && 128 client->buffer_size + bytes < WT_CLIENT_BUFFER_MAX_SIZE) { 129 client->buffer_size += bytes; 140 130 client->buffer = realloc(client->buffer, client->buffer_size); 141 client->buffer_offset += bytes; 142 } else { 131 } 132 133 /* append to buffer */ 134 strlcat(client->buffer + client->buffer_offset, 135 buf, 136 client->buffer_size - client->buffer_offset); 137 client->buffer_offset += bytes; 138 139 if(client->buffer[client->buffer_offset + bytes - 1] == WT_MESSAGE_SEPARATOR) { 143 140 /* chomp separator */ 144 141 client->buffer[client->buffer_offset + bytes - 1] = '\0'; … … 147 144 wt_parse_command(client->buffer); 148 145 149 /* reset offset */ 146 /* reset buffer */ 147 memset(client->buffer, 0, client->buffer_size); 150 148 client->buffer_offset = 0; 151 149 } … … 167 165 /* delete client */ 168 166 if(client) { 169 wt_log (LOG_INFO,"Disconnect from %s", client->ip);167 wt_log_info("Disconnect from %s", client->ip); 170 168 171 169 free(client->buffer); … … 193 191 194 192 /* get command */ 195 command = (char *) malloc( buffer - start + 1);196 memcpy(command, start, buffer - start);193 command = (char *) malloc((size_t) (buffer - start + 1)); 194 memcpy(command, start, (size_t) (buffer - start)); 197 195 command[buffer - start] = '\0'; 198 196 … … 287 285 288 286 if(!fp) { 289 wt_log(LOG_WARNING, "Could not open %s: %s", 287 wt_reply(500, "Command Failed"); 288 wt_log_err("Could not open %s: %s", 290 289 wt_settings.categories, strerror(errno)); 291 wt_reply(500, "Command Failed");292 290 293 291 goto end; … … 346 344 if(wt_ip_is_banned(client->ip)) { 347 345 wt_reply(511, "Banned"); 348 wt_log (LOG_INFO,"Connection from %s denied, host is banned",346 wt_log_err("Connection from %s denied, host is banned", 349 347 client->ip); 350 348 … … 367 365 368 366 /* reply a 200 */ 369 wt_reply(200, "%s% s%s%s%s%s%s%s%s",367 wt_reply(200, "%s%c%s%c%s%c%s%c%s", 370 368 wt_version_string, 371 369 WT_FIELD_SEPARATOR, … … 406 404 if(wt_settings.strictlookup) { 407 405 wt_reply(503, "Syntax Error"); 408 wt_log_ l(LOG_WARNING,"Register from %s as \"%s\" aborted: %s",406 wt_log_warn("Register from %s as \"%s\" aborted: %s", 409 407 client->ip, argv[1], "URL parse failed"); 410 408 … … 427 425 if(wt_settings.strictlookup) { 428 426 wt_reply(516, "Permission Denied"); 429 wt_log_ l(LOG_WARNING,"Register from %s as \"%s\" denied: %s",427 wt_log_warn("Register from %s as \"%s\" denied: %s", 430 428 client->ip, url, "IP mismatch"); 431 429 … … 445 443 if(wt_settings.strictlookup) { 446 444 wt_reply(516, "Permission Denied"); 447 wt_log_ l(LOG_WARNING,"Register from %s as \"%s\" denied: %s",445 wt_log_warn("Register from %s as \"%s\" denied: %s", 448 446 client->ip, url, "Lookup failed"); 449 447 … … 463 461 if(wt_settings.strictlookup) { 464 462 wt_reply(516, "Permission Denied"); 465 wt_log_ l(LOG_WARNING,"Register from %s as \"%s\" denied: %s",463 wt_log_warn("Register from %s as \"%s\" denied: %s", 466 464 client->ip, url, "IP mismatch"); 467 465 … … 482 480 if(wt_settings.strictlookup) { 483 481 wt_reply(516, "Permission Denied"); 484 wt_log_ l(LOG_WARNING,"Register from %s as \"%s\" denied: %s",482 wt_log_warn("Register from %s as \"%s\" denied: %s", 485 483 client->ip, url, "Lookup failed"); 486 484 … … 497 495 if(wt_settings.strictlookup) { 498 496 wt_reply(516, "Permission Denied"); 499 wt_log_ l(LOG_WARNING,"Register from %s as \"%s\" denied: %s",497 wt_log_warn("Register from %s as \"%s\" denied: %s", 500 498 client->ip, url, "Hostname mismatch"); 501 499 … … 516 514 517 515 /* test bandwidth */ 518 bandwidth = strtoul(argv[3], NULL, 10); 516 if(wt_strtoul(argv[3], (unsigned long *) &bandwidth) < 0) { 517 wt_reply(503, "Syntax Error"); 518 519 return; 520 } 519 521 520 522 if(wt_settings.minbandwidth > 0 && bandwidth < wt_settings.minbandwidth) { 521 523 wt_reply(516, "Permission Denied"); 522 wt_log_ l(LOG_WARNING,"Register from %s as \"%s\" denied: Bandwidth too low",524 wt_log_warn("Register from %s as \"%s\" denied: Bandwidth too low", 523 525 client->ip, url); 524 526 … … 528 530 if(wt_settings.maxbandwidth > 0 && bandwidth > wt_settings.maxbandwidth) { 529 531 wt_reply(516, "Permission Denied"); 530 wt_log_ l(LOG_WARNING,"Register from %s as \"%s\" denied: Bandwidth too high",532 wt_log_warn("Register from %s as \"%s\" denied: Bandwidth too high", 531 533 client->ip, url); 532 534 … … 561 563 else if(!wt_settings.allowmultiple) { 562 564 wt_reply(516, "Permission Denied"); 563 wt_log_ l(LOG_WARNING,"Register from %s as \"%s\" denied: No multiple",565 wt_log_warn("Register from %s as \"%s\" denied: No multiple", 564 566 client->ip, url); 565 567 … … 610 612 611 613 /* log */ 612 wt_log (LOG_INFO,"Registered \"%s\"", server->url);614 wt_log_info("Registered \"%s\"", server->url); 613 615 614 616 /* update status */ … … 638 640 WT_LIST_FOREACH(wt_servers, node, server) { 639 641 /* reply 720 */ 640 wt_reply(720, "%s% s%s%s%s%s%u%s%u%s%u%s%u%s%u%s%llu%s%s",642 wt_reply(720, "%s%c%s%c%s%c%u%c%u%c%u%c%u%c%u%c%llu%c%s", 641 643 server->category, 642 644 WT_FIELD_SEPARATOR, trackerd/trunk/trackerd/main.c
r229 r231 1 /* $Id: main.c,v 1.1 1 2004/09/06 08:38:26 morris Exp $ */1 /* $Id: main.c,v 1.12 2004/09/09 09:37:56 morris Exp $ */ 2 2 3 3 /* … … 107 107 108 108 case 'i': 109 wt_log_limit = strtoul(optarg, NULL, 10); 109 if(wt_strtoul(optarg, (unsigned long *) &wt_log_limit) < 0) 110 wt_log_err("%s: Not a number", optarg); 110 111 break; 111 112 … … 157 158 argv += optind; 158 159 159 if(wt_ debug || wt_syslog) {160 if(wt_syslog) { 160 161 /* test facility */ 161 162 if(syslog_flag) { 162 163 wt_syslog = false; 163 wt_log(LOG_ERR, "No such syslog facility '%s'", syslog_flag); 164 wt_log_err("No such syslog facility '%s'", 165 syslog_flag); 164 166 } 165 167 … … 183 185 /* change root directory */ 184 186 if(chroot(wt_root) < 0) { 185 wt_log (LOG_ERR,"Could not change root to %s: %s",187 wt_log_err("Could not change root to %s: %s", 186 188 wt_root, strerror(errno)); 187 189 } … … 225 227 if(!wt_debug) { 226 228 if(daemon(1, 1) < 0) { 227 wt_log (LOG_ERR,"Could not become a daemon: %s",229 wt_log_err("Could not become a daemon: %s", 228 230 strerror(errno)); 229 231 } … … 235 237 /* init server */ 236 238 wt_start_time = time(NULL); 237 wt_log (LOG_INFO,"Starting Wired Tracker version %s", WT_PACKAGE_VERSION);239 wt_log_info("Starting Wired Tracker version %s", WT_PACKAGE_VERSION); 238 240 wt_init_tracker(); 239 wt_log (LOG_INFO,"Listening on %s, port %d",241 wt_log_info("Listening on %s, port %d", 240 242 strlen(wt_settings.address) > 0 241 243 ? inet_ntoa(wt_addr.sin_addr) 242 244 : "all available addresses", 243 wt_settings.port);245 ntohs(wt_addr.sin_port)); 244 246 245 247 /* switch user/group on log file */ … … 247 249 if(chown(wt_log_path, wt_frozen_settings.user->pw_uid, 248 250 wt_frozen_settings.group->gr_gid) < 0) { 249 wt_log (LOG_ERR,"Could not change owner of %s: %s",251 wt_log_err("Could not change owner of %s: %s", 250 252 wt_log_path, strerror(errno)); 251 253 } … … 256 258 if(initgroups(wt_frozen_settings.user->pw_name, 257 259 wt_frozen_settings.group->gr_gid) < 0) { 258 wt_log (LOG_ERR,"Could not set group privileges: %s",260 wt_log_err("Could not set group privileges: %s", 259 261 strerror(errno)); 260 262 } 261 263 262 264 if(setgid(wt_frozen_settings.group->gr_gid) < 0) { 263 &
