version 1.10 | | version 1.11 |
---|
| | |
/* | | /* |
* static char *rcsid_ban_c = | | * static char *rcsid_ban_c = |
* "$Id: ban.c,v 1.10 2005/12/07 18:25:55 akirschbaum Exp $"; | | * "$Id: ban.c,v 1.11 2005/12/07 19:39:05 akirschbaum Exp $"; |
*/ | | */ |
| | |
/* | | /* |
| | |
{ | | { |
FILE *bannedfile; | | FILE *bannedfile; |
char buf[MAX_BUF]; | | char buf[MAX_BUF]; |
char log_buf[64], host_buf[64], line_buf[160]; | | char log_buf0[160], host_buf[64], line_buf[160]; |
char *indexpos; | | char *indexpos; |
int num1; | | int num1; |
int Hits=0; /* Hits==2 means we're banned */ | | int Hits=0; /* Hits==2 means we're banned */ |
int loop=0; | | int loop=0; |
| | |
| | /* Inverse ban feature: if a line is prefixed by a ~, then we will |
| | * immediately return "check passed" if it matches. This allow to ban |
| | * a network, but let a part of it still connect. |
| | */ |
| | int inverse_ban = 0; |
| | |
while (loop < 2) { /* have to check both ban files now */ | | while (loop < 2) { /* have to check both ban files now */ |
| | |
/* First time through look for BANFILE */ | | /* First time through look for BANFILE */ |
| | |
/* Do the actual work here checking for banned IPs */ | | /* Do the actual work here checking for banned IPs */ |
| | |
while(fgets(line_buf, 160, bannedfile) != NULL) { | | while(fgets(line_buf, 160, bannedfile) != NULL) { |
| | char *log_buf = log_buf0; |
| | |
| | inverse_ban = 0; |
| | Hits = 0; |
| | |
/* Split line up */ | | /* Split line up */ |
if((*line_buf=='#')||(*line_buf=='\n')) | | if((*line_buf=='#')||(*line_buf=='\n')) |
continue; | | continue; |
| | |
indexpos++; | | indexpos++; |
*indexpos = '\0'; | | *indexpos = '\0'; |
| | |
| | if (*log_buf == '~') { |
| | log_buf++; |
| | inverse_ban = 1; |
| | } |
| | |
/* | | /* |
LOG (llevDebug, "Login: <%s>; host: <%s>\n", login, host); | | LOG (llevDebug, "Login: <%s>; host: <%s>\n", login, host); |
LOG (llevDebug, " Checking Banned <%s> and <%s>.\n",log_buf,host_buf); | | LOG (llevDebug, " Checking Banned <%s> and <%s>.\n",log_buf,host_buf); |
*/ | | */ |
| | |
if(*log_buf=='*') | | if(*log_buf=='*') |
| | |
Hits=1; | | Hits=1; |
| | |
} | | } |
fclose(bannedfile); | | fclose(bannedfile); |
if(Hits>=2) | | if(Hits>=2) |
return(1); | | return(!inverse_ban); |
loop++; | | loop++; |
} | | } |
return(0); | | return(0); |