From cfd16d6e109c3a61bb9558c6f03ce361b6e957b4 Mon Sep 17 00:00:00 2001 From: Frederic Marchal Date: Sun, 21 Apr 2013 17:36:48 +0200 Subject: [PATCH] Per user limit file with IP address As reported by xeus, the per user limit file is only usable if it contains the user's IP address. Recent changes had replaced the IP address by the resolved name. --- html.c | 4 ++-- include/defs.h | 4 +++- log.c | 2 +- redirector.c | 2 +- userinfo.c | 4 +++- 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/html.c b/html.c index 453711a..06eb399 100644 --- a/html.c +++ b/html.c @@ -535,7 +535,7 @@ void htmlrel(void) } while(fgets(tmp6,sizeof(tmp6),fp_usr)!=NULL) { fixendofline(tmp6); - if(strcmp(tmp6,uinfo->label) == 0) { + if(strcmp(tmp6,uinfo->ip) == 0) { limit_flag=1; break; } @@ -548,7 +548,7 @@ void htmlrel(void) debuga(_("(html10) Cannot open file %s\n"),PerUserLimitFile); exit(EXIT_FAILURE); } - fprintf(fp_usr,"%s\n",uinfo->label); + fprintf(fp_usr,"%s\n",uinfo->ip); fclose(fp_usr); if(debug) diff --git a/include/defs.h b/include/defs.h index c9c8a3f..e991750 100755 --- a/include/defs.h +++ b/include/defs.h @@ -43,6 +43,8 @@ struct userinfostruct { //! The ID of the user as found in the input file. char id[MAX_USER_LEN]; + //! The user's IP address. + char ip[30]; //! \c True if the ID is in fact the IP address from which the user connected. bool id_is_ip; //! \c True if the user doesn't have a report file. @@ -224,7 +226,7 @@ void usage(const char *prog); void useragent(void); // userinfo.c -/*@shared@*/struct userinfostruct *userinfo_create(const char *userid); +/*@shared@*/struct userinfostruct *userinfo_create(const char *userid,const char *ip); void userinfo_free(void); /*@shared@*/struct userinfostruct *userinfo_find_from_file(const char *filename); /*@shared@*/struct userinfostruct *userinfo_find_from_id(const char *id); diff --git a/log.c b/log.c index 23ef0e0..213dec6 100644 --- a/log.c +++ b/log.c @@ -1461,7 +1461,7 @@ int main(int argc,char *argv[]) memset(ufile,0,sizeof(*ufile)); ufile->next=first_user_file; first_user_file=ufile; - uinfo=userinfo_create(user); + uinfo=userinfo_create(user,ip); ufile->user=uinfo; uinfo->id_is_ip=id_is_ip; nusers++; diff --git a/redirector.c b/redirector.c index 8004de4..f506fc9 100644 --- a/redirector.c +++ b/redirector.c @@ -203,7 +203,7 @@ static void parse_log(FILE *fp_ou,char *buf) } uinfo=userinfo_find_from_id(user); if (!uinfo) { - uinfo=userinfo_create(user); + uinfo=userinfo_create(user,ip); uinfo->id_is_ip=id_is_ip; uinfo->no_report=true; if(Ip2Name && id_is_ip) ip2name(user,sizeof(user)); diff --git a/userinfo.c b/userinfo.c index c2e82d5..ed761e4 100644 --- a/userinfo.c +++ b/userinfo.c @@ -59,7 +59,7 @@ static struct usergroupstruct *first_user_group=NULL; //! The counter to generate unique user number when ::AnonymousOutputFiles is set. static int AnonymousCounter=0; -struct userinfostruct *userinfo_create(const char *userid) +struct userinfostruct *userinfo_create(const char *userid,const char *ip) { struct usergroupstruct *group, *last; struct userinfostruct *user; @@ -110,6 +110,8 @@ struct userinfostruct *userinfo_create(const char *userid) if (j==0) user->filename[j++]='_'; //don't leave a file name empty flen=j; user->filename[j]='\0'; + strncpy(user->ip,ip,sizeof(user->ip)-1); + user->ip[sizeof(user->ip)-1]='\0'; count=0; for (group=first_user_group ; group ; group=group->next) { -- 2.47.2