Changeset 231

Show
Ignore:
Timestamp:
09/09/04 11:37:56 (4 years ago)
Author:
morris
Message:

sync with wired

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trackerd/trunk/config.h.in

    r204 r231  
    1111#undef HAVE_DIRENT_H 
    1212 
     13/* Define to 1 if you don't have `vprintf' but do have `_doprnt.' */ 
     14#undef HAVE_DOPRNT 
     15 
    1316/* Define to 1 if you have the <errno.h> header file. */ 
    1417#undef HAVE_ERRNO_H 
     
    1619/* Define to 1 if you have the <fcntl.h> header file. */ 
    1720#undef HAVE_FCNTL_H 
     21 
     22/* Define to 1 if fseeko (and presumably ftello) exists and is declared. */ 
     23#undef HAVE_FSEEKO 
    1824 
    1925/* Define to 1 if you have the `gethostbyaddr' function. */ 
     
    209215#undef HAVE_UNISTD_H 
    210216 
     217/* Define to 1 if you have the `vprintf' function. */ 
     218#undef HAVE_VPRINTF 
     219 
    211220/* Define to 1 if the system has the type `_Bool'. */ 
    212221#undef HAVE__BOOL 
     
    270279#undef WT_USER 
    271280 
     281/* Define to 1 to make fseeko visible on some hosts (e.g. glibc 2.2). */ 
     282#undef _LARGEFILE_SOURCE 
     283 
    272284/* Define to empty if `const' does not conform to ANSI C. */ 
    273285#undef const 
  • trackerd/trunk/configure

    r213 r231  
    64146414fi 
    64156415 
     6416echo "$as_me:$LINENO: checking for _LARGEFILE_SOURCE value needed for large files" >&5 
     6417echo $ECHO_N "checking for _LARGEFILE_SOURCE value needed for large files... $ECHO_C" >&6 
     6418if test "${ac_cv_sys_largefile_source+set}" = set; then 
     6419  echo $ECHO_N "(cached) $ECHO_C" >&6 
     6420else 
     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 
     6427cat confdefs.h >>conftest.$ac_ext 
     6428cat >>conftest.$ac_ext <<_ACEOF 
     6429/* end confdefs.h.  */ 
     6430#include <stdio.h> 
     6431int 
     6432main () 
     6433{ 
     6434return !fseeko; 
     6435  ; 
     6436  return 0; 
     6437} 
     6438_ACEOF 
     6439rm -f conftest.$ac_objext 
     6440if { (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 
     6452else 
     6453  echo "$as_me: failed program was:" >&5 
     6454sed 's/^/| /' conftest.$ac_ext >&5 
     6455 
     6456fi 
     6457rm -f conftest.$ac_objext conftest.$ac_ext 
     6458  cat >conftest.$ac_ext <<_ACEOF 
     6459#line $LINENO "configure" 
     6460/* confdefs.h.  */ 
     6461_ACEOF 
     6462cat confdefs.h >>conftest.$ac_ext 
     6463cat >>conftest.$ac_ext <<_ACEOF 
     6464/* end confdefs.h.  */ 
     6465#define _LARGEFILE_SOURCE 1 
     6466#include <stdio.h> 
     6467int 
     6468main () 
     6469{ 
     6470return !fseeko; 
     6471  ; 
     6472  return 0; 
     6473} 
     6474_ACEOF 
     6475rm -f conftest.$ac_objext 
     6476if { (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 
     6488else 
     6489  echo "$as_me: failed program was:" >&5 
     6490sed 's/^/| /' conftest.$ac_ext >&5 
     6491 
     6492fi 
     6493rm -f conftest.$ac_objext conftest.$ac_ext 
     6494  break 
     6495done 
     6496fi 
     6497echo "$as_me:$LINENO: result: $ac_cv_sys_largefile_source" >&5 
     6498echo "${ECHO_T}$ac_cv_sys_largefile_source" >&6 
     6499if test "$ac_cv_sys_largefile_source" != no; then 
     6500 
     6501cat >>confdefs.h <<_ACEOF 
     6502#define _LARGEFILE_SOURCE $ac_cv_sys_largefile_source 
     6503_ACEOF 
     6504 
     6505fi 
     6506rm -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. 
     6511echo "$as_me:$LINENO: checking for fseeko" >&5 
     6512echo $ECHO_N "checking for fseeko... $ECHO_C" >&6 
     6513if test "${ac_cv_func_fseeko+set}" = set; then 
     6514  echo $ECHO_N "(cached) $ECHO_C" >&6 
     6515else 
     6516  cat >conftest.$ac_ext <<_ACEOF 
     6517#line $LINENO "configure" 
     6518/* confdefs.h.  */ 
     6519_ACEOF 
     6520cat confdefs.h >>conftest.$ac_ext 
     6521cat >>conftest.$ac_ext <<_ACEOF 
     6522/* end confdefs.h.  */ 
     6523#include <stdio.h> 
     6524int 
     6525main () 
     6526{ 
     6527return fseeko && fseeko (stdin, 0, 0); 
     6528  ; 
     6529  return 0; 
     6530} 
     6531_ACEOF 
     6532rm -f conftest.$ac_objext conftest$ac_exeext 
     6533if { (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 
     6545else 
     6546  echo "$as_me: failed program was:" >&5 
     6547sed 's/^/| /' conftest.$ac_ext >&5 
     6548 
     6549ac_cv_func_fseeko=no 
     6550fi 
     6551rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext 
     6552fi 
     6553echo "$as_me:$LINENO: result: $ac_cv_func_fseeko" >&5 
     6554echo "${ECHO_T}$ac_cv_func_fseeko" >&6 
     6555if test $ac_cv_func_fseeko = yes; then 
     6556 
     6557cat >>confdefs.h <<\_ACEOF 
     6558#define HAVE_FSEEKO 1 
     6559_ACEOF 
     6560 
     6561fi 
     6562 
    64166563 
    64176564for ac_header in stdlib.h 
     
    74737620fi 
    74747621done 
     7622 
     7623 
     7624for ac_func in vprintf 
     7625do 
     7626as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh` 
     7627echo "$as_me:$LINENO: checking for $ac_func" >&5 
     7628echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6 
     7629if eval "test \"\${$as_ac_var+set}\" = set"; then 
     7630  echo $ECHO_N "(cached) $ECHO_C" >&6 
     7631else 
     7632  cat >conftest.$ac_ext <<_ACEOF 
     7633#line $LINENO "configure" 
     7634/* confdefs.h.  */ 
     7635_ACEOF 
     7636cat confdefs.h >>conftest.$ac_ext 
     7637cat >>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 
     7650extern "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.  */ 
     7655char $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) 
     7660choke me 
     7661#else 
     7662char (*f) () = $ac_func; 
     7663#endif 
     7664#ifdef __cplusplus 
     7665} 
     7666#endif 
     7667 
     7668int 
     7669main () 
     7670{ 
     7671return f != $ac_func; 
     7672  ; 
     7673  return 0; 
     7674} 
     7675_ACEOF 
     7676rm -f conftest.$ac_objext conftest$ac_exeext 
     7677if { (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" 
     7689else 
     7690  echo "$as_me: failed program was:" >&5 
     7691sed 's/^/| /' conftest.$ac_ext >&5 
     7692 
     7693eval "$as_ac_var=no" 
     7694fi 
     7695rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext 
     7696fi 
     7697echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_var'}'`" >&5 
     7698echo "${ECHO_T}`eval echo '${'$as_ac_var'}'`" >&6 
     7699if 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 
     7704echo "$as_me:$LINENO: checking for _doprnt" >&5 
     7705echo $ECHO_N "checking for _doprnt... $ECHO_C" >&6 
     7706if test "${ac_cv_func__doprnt+set}" = set; then 
     7707  echo $ECHO_N "(cached) $ECHO_C" >&6 
     7708else 
     7709  cat >conftest.$ac_ext <<_ACEOF 
     7710#line $LINENO "configure" 
     7711/* confdefs.h.  */ 
     7712_ACEOF 
     7713cat confdefs.h >>conftest.$ac_ext 
     7714cat >>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 
     7727extern "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.  */ 
     7732char _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) 
     7737choke me 
     7738#else 
     7739char (*f) () = _doprnt; 
     7740#endif 
     7741#ifdef __cplusplus 
     7742} 
     7743#endif 
     7744 
     7745int 
     7746main () 
     7747{ 
     7748return f != _doprnt; 
     7749  ; 
     7750  return 0; 
     7751} 
     7752_ACEOF 
     7753rm -f conftest.$ac_objext conftest$ac_exeext 
     7754if { (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 
     7766else 
     7767  echo "$as_me: failed program was:" >&5 
     7768sed 's/^/| /' conftest.$ac_ext >&5 
     7769 
     7770ac_cv_func__doprnt=no 
     7771fi 
     7772rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext 
     7773fi 
     7774echo "$as_me:$LINENO: result: $ac_cv_func__doprnt" >&5 
     7775echo "${ECHO_T}$ac_cv_func__doprnt" >&6 
     7776if test $ac_cv_func__doprnt = yes; then 
     7777 
     7778cat >>confdefs.h <<\_ACEOF 
     7779#define HAVE_DOPRNT 1 
     7780_ACEOF 
     7781 
     7782fi 
     7783 
     7784fi 
     7785done 
     7786 
    74757787 
    74767788 
  • trackerd/trunk/configure.in

    r213 r231  
    317317 
    318318AC_FUNC_CHOWN 
     319AC_FUNC_FSEEKO 
    319320AC_FUNC_MALLOC 
    320321AC_FUNC_LSTAT 
     
    324325AC_FUNC_STAT 
    325326AC_FUNC_STRFTIME 
     327AC_FUNC_VPRINTF 
    326328AC_CHECK_FUNCS([ \ 
    327329        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 $ */ 
    22 
    33/* 
     
    5454                /* open the banlist file */ 
    5555                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                } 
    5663                 
    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; 
    8979                                } 
    9080                        } 
     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                } 
    9197                         
    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); 
    9799        } 
    98100 
     101end: 
    99102        return banned; 
    100103} 
     
    105108 
    106109bool 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; 
    109111        int             matches = 0; 
    110112         
    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); 
    116115         
    117116        while((p1 = strsep(&ii, ".")) && (p2 = strsep(&mm, "."))) { 
     
    119118                        matches++; 
    120119        } 
     120 
     121        free(i); 
     122        free(m); 
    121123 
    122124        return matches == 4 ? true : false; 
     
    126128 
    127129bool 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 
    144143                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)); 
    149148} 
    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 $ */ 
    22 
    33/* 
     
    3939bool                                                    wt_ip_matches_wildcard(char *, char *); 
    4040bool                                                    wt_ip_matches_netmask(char *, char *); 
    41 unsigned int                                    wt_iptou(char *); 
    4241 
    4342#endif /* WT_BANLIST_H */ 
  • trackerd/trunk/trackerd/commands.c

    r228 r231  
    1 /* $Id: commands.c,v 1.13 2004/08/30 19:28:36 morris Exp $ */ 
     1/* $Id: commands.c,v 1.14 2004/09/09 09:37:56 morris Exp $ */ 
    22 
    33/* 
     
    6868 
    6969void * 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; 
    7576 
    7677        /* associate the struct with this thread */ 
     
    8384                                FD_ZERO(&rfds); 
    8485                                FD_SET(client->sd, &rfds); 
    85                                 tv.tv_sec = 0; 
    86                                 tv.tv_usec = 100000; 
     86                                wt_dtotv(0.1, &tv); 
    8787                                state = select(client->sd + 1, &rfds, NULL, NULL, &tv); 
    8888                        } while(state == 0 && client->state <= WT_CLIENT_STATE_SAID_HELLO); 
     
    9999                                } else { 
    100100                                        /* 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", 
    102102                                                client->ip, strerror(errno)); 
    103103         
     
    109109                 
    110110                /* 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)); 
    114112 
    115113                if(bytes == 0) { 
     
    119117                else if(bytes < 0) { 
    120118                        /* 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()); 
    125121 
    126122                        error = true; 
    127123                        break; 
    128124                } 
    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; 
    140130                        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) { 
    143140                        /* chomp separator */ 
    144141                        client->buffer[client->buffer_offset + bytes - 1] = '\0'; 
     
    147144                        wt_parse_command(client->buffer); 
    148145                         
    149                         /* reset offset */ 
     146                        /* reset buffer */ 
     147                        memset(client->buffer, 0, client->buffer_size); 
    150148                        client->buffer_offset = 0; 
    151149                } 
     
    167165        /* delete client */ 
    168166        if(client) { 
    169                 wt_log(LOG_INFO, "Disconnect from %s", client->ip); 
     167                wt_log_info("Disconnect from %s", client->ip); 
    170168 
    171169                free(client->buffer); 
     
    193191         
    194192        /* 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)); 
    197195        command[buffer - start] = '\0'; 
    198196 
     
    287285         
    288286        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", 
    290289                        wt_settings.categories, strerror(errno)); 
    291                 wt_reply(500, "Command Failed"); 
    292290                 
    293291                goto end; 
     
    346344        if(wt_ip_is_banned(client->ip)) { 
    347345                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", 
    349347                        client->ip); 
    350348                 
     
    367365                 
    368366        /* 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", 
    370368                         wt_version_string, 
    371369                         WT_FIELD_SEPARATOR, 
     
    406404                if(wt_settings.strictlookup) { 
    407405                        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", 
    409407                                client->ip, argv[1], "URL parse failed"); 
    410408                         
     
    427425                                if(wt_settings.strictlookup) { 
    428426                                        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", 
    430428                                                client->ip, url, "IP mismatch"); 
    431429                                         
     
    445443                                        if(wt_settings.strictlookup) { 
    446444                                                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",  
    448446                                                        client->ip, url, "Lookup failed"); 
    449447                                                 
     
    463461                                        if(wt_settings.strictlookup) { 
    464462                                                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", 
    466464                                                        client->ip, url, "IP mismatch"); 
    467465                                                 
     
    482480                                        if(wt_settings.strictlookup) { 
    483481                                                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", 
    485483                                                        client->ip, url, "Lookup failed"); 
    486484                                                 
     
    497495                                        if(wt_settings.strictlookup) { 
    498496                                                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",  
    500498                                                        client->ip, url, "Hostname mismatch"); 
    501499                                                 
     
    516514 
    517515        /* 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        } 
    519521         
    520522        if(wt_settings.minbandwidth > 0 && bandwidth < wt_settings.minbandwidth) { 
    521523                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",  
    523525                        client->ip, url); 
    524526                 
     
    528530        if(wt_settings.maxbandwidth > 0 && bandwidth > wt_settings.maxbandwidth) { 
    529531                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", 
    531533                        client->ip, url); 
    532534                 
     
    561563                else if(!wt_settings.allowmultiple) { 
    562564                        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",  
    564566                                client->ip, url); 
    565567                                 
     
    610612         
    611613        /* log */ 
    612         wt_log(LOG_INFO, "Registered \"%s\"", server->url); 
     614        wt_log_info("Registered \"%s\"", server->url); 
    613615 
    614616        /* update status */ 
     
    638640        WT_LIST_FOREACH(wt_servers, node, server) { 
    639641                /* 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", 
    641643                        server->category, 
    642644                        WT_FIELD_SEPARATOR, 
  • trackerd/trunk/trackerd/main.c

    r229 r231  
    1 /* $Id: main.c,v 1.11 2004/09/06 08:38:26 morris Exp $ */ 
     1/* $Id: main.c,v 1.12 2004/09/09 09:37:56 morris Exp $ */ 
    22 
    33/* 
     
    107107                         
    108108                        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); 
    110111                                break; 
    111112                         
     
    157158        argv += optind; 
    158159         
    159         if(wt_debug || wt_syslog) { 
     160        if(wt_syslog) { 
    160161                /* test facility */ 
    161162                if(syslog_flag) { 
    162163                        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); 
    164166                } 
    165167 
     
    183185                /* change root directory */ 
    184186                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", 
    186188                                wt_root, strerror(errno)); 
    187189                } 
     
    225227        if(!wt_debug) { 
    226228                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", 
    228230                                strerror(errno)); 
    229231                } 
     
    235237        /* init server */ 
    236238        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); 
    238240        wt_init_tracker(); 
    239         wt_log(LOG_INFO, "Listening on %s, port %d", 
     241        wt_log_info("Listening on %s, port %d", 
    240242                strlen(wt_settings.address) > 0 
    241243                        ? inet_ntoa(wt_addr.sin_addr) 
    242244                        : "all available addresses", 
    243                 wt_settings.port); 
     245                ntohs(wt_addr.sin_port)); 
    244246 
    245247        /* switch user/group on log file */ 
     
    247249                if(chown(wt_log_path, wt_frozen_settings.user->pw_uid, 
    248250                         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", 
    250252                                wt_log_path, strerror(errno)); 
    251253                } 
     
    256258                if(initgroups(wt_frozen_settings.user->pw_name, 
    257259                                          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", 
    259261                                strerror(errno)); 
    260262                } 
    261263 
    262264                if(setgid(wt_frozen_settings.group->gr_gid) < 0) { 
    263     &