version 1.11 | | version 1.12 |
---|
| | |
/* | | /* |
* static char *rcsid_ban_c = | | * static char *rcsid_ban_c = |
* "$Id: ban.c,v 1.11 2005/12/07 19:39:05 akirschbaum Exp $"; | | * "$Id: ban.c,v 1.12 2005/12/07 21:02:24 akirschbaum Exp $"; |
*/ | | */ |
| | |
/* | | /* |
| | |
char log_buf0[160], 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; |
| | |
/* Inverse ban feature: if a line is prefixed by a ~, then we will | | /* Inverse ban feature: if a line is prefixed by a ~, then we will |
* immediately return "check passed" if it matches. This allow to ban | | * immediately return "check passed" if it matches. This allow to ban a |
* a network, but let a part of it still connect. | | * network, but let a part of it still connect. |
*/ | | */ |
int inverse_ban = 0; | | int inverse_ban = 0; |
| | |
while (loop < 2) { /* have to check both ban files now */ | | for (loop = 0; loop < 2; loop++) { /* have to check both ban files now */ |
| | |
/* First time through look for BANFILE */ | | /* First time through look for BANFILE */ |
| | |
if (loop == 0){ | | if (loop == 0){ |
sprintf (buf, "%s/%s", settings.confdir, BANFILE); | | sprintf (buf, "%s/%s", settings.confdir, BANFILE); |
if ((bannedfile = fopen(buf, "r")) == NULL) { | | bannedfile = fopen(buf, "r"); |
| | if (bannedfile == NULL) { |
LOG (llevDebug, "Could not find file Banned file\n"); | | LOG (llevDebug, "Could not find file Banned file\n"); |
loop++; | | loop++; |
} | | } |
| | |
| | |
if (loop == 1){ | | if (loop == 1){ |
sprintf (buf, "%s/%s", settings.localdir, BANISHFILE); | | sprintf (buf, "%s/%s", settings.localdir, BANISHFILE); |
if ((bannedfile = fopen(buf, "r")) == NULL) { | | bannedfile = fopen(buf, "r"); |
| | if (bannedfile == NULL) { |
LOG (llevDebug, "Could not find file Banish file\n"); | | LOG (llevDebug, "Could not find file Banish file\n"); |
return(0); | | return(0); |
} | | } |
| | |
char *log_buf = log_buf0; | | char *log_buf = log_buf0; |
| | |
inverse_ban = 0; | | inverse_ban = 0; |
Hits = 0; | | hits = 0; |
| | |
/* Split line up */ | | /* Split line up */ |
if((*line_buf=='#')||(*line_buf=='\n')) | | if(*line_buf == '#' || *line_buf == '\n') |
continue; | | continue; |
if ((indexpos = (char *) strrchr(line_buf, '@')) == 0) { | | |
| | indexpos = strrchr(line_buf, '@'); |
| | if (indexpos == NULL) { |
LOG (llevDebug, "Bad line in banned file\n"); | | LOG (llevDebug, "Bad line in banned file\n"); |
continue; | | continue; |
} | | } |
| | |
| | /* copy login name into log_buf */ |
num1 = indexpos - line_buf; | | num1 = indexpos - line_buf; |
strncpy(log_buf, line_buf, num1); /* copy login name into log_buf */ | | strncpy(log_buf, line_buf, num1); |
log_buf[num1] = '\0'; | | log_buf[num1] = '\0'; |
strncpy(host_buf, indexpos + 1, 64); /* copy host name into host_buf */ | | |
host_buf[63] = '\0'; | | /* copy host name into host_buf */ |
| | strncpy(host_buf, indexpos+1, sizeof(host_buf)-1); |
| | host_buf[sizeof(host_buf)-1] = '\0'; |
| | |
/* Cut off any extra spaces on the host buffer */ | | /* Cut off any extra spaces on the host buffer */ |
indexpos = host_buf; | | indexpos = host_buf; |
while (!isspace(*indexpos)) | | while (!isspace(*indexpos)) { |
indexpos++; | | indexpos++; |
| | } |
*indexpos = '\0'; | | *indexpos = '\0'; |
| | |
if (*log_buf == '~') { | | if (*log_buf == '~') { |
| | |
*/ | | */ |
| | |
if(*log_buf=='*') | | if(*log_buf=='*') |
| | hits = 1; |
Hits=1; | | |
else if (login != NULL && strcmp(login, log_buf) == 0) | | else if (login != NULL && strcmp(login, log_buf) == 0) |
Hits=1; | | hits = 1; |
if(Hits==1) | | |
{ | | if (hits == 1) { |
if (*host_buf == '*'){ /* Lock out any host */ | | if (*host_buf == '*'){ /* Lock out any host */ |
Hits++; | | hits++; |
break; /* break out now. otherwise Hits will get reset | | |
to one */ | | /* break out now. otherwise hits will get reset to one */ |
| | break; |
} | | } |
else if(strstr(host,host_buf)!=NULL){ /* Lock out subdomains (eg, "*@usc.edu" */ | | else if(strstr(host,host_buf)!=NULL){ /* Lock out subdomains (eg, "*@usc.edu" */ |
Hits++; | | hits++; |
break; /* break out now. otherwise Hits will get reset | | |
to one */ | | /* break out now. otherwise hits will get reset to one */ |
} | | break; |
else if (!strcmp(host, host_buf)){ /* Lock out specific host */ | | } |
Hits++; | | else if (strcmp(host, host_buf) == 0) { /* Lock out specific host */ |
break; /* break out now. otherwise Hits will get reset | | hits++; |
to one */ | | |
| | /* break out now. otherwise hits will get reset to one */ |
| | break; |
} | | } |
} | | } |
} | | } |
fclose(bannedfile); | | fclose(bannedfile); |
if(Hits>=2) | | |
| | if (hits >= 2) { |
return(!inverse_ban); | | return(!inverse_ban); |
| | } |
| | |
loop++; | | loop++; |
} | | } |
| | |
return(0); | | return(0); |
} | | } |