]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Per user limit file with IP address
authorFrederic Marchal <fmarchal@users.sourceforge.net>
Sun, 21 Apr 2013 15:36:48 +0000 (17:36 +0200)
committerFrederic Marchal <fmarchal@users.sourceforge.net>
Sun, 21 Apr 2013 15:36:48 +0000 (17:36 +0200)
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
include/defs.h
log.c
redirector.c
userinfo.c

diff --git a/html.c b/html.c
index 453711a576874e2a6691c8ff9b8cebb8bd853ed9..06eb399699dceca236d77d83e95c752cb79f06e7 100644 (file)
--- 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)
index c9c8a3f59f33f3242ac26be7f2466931fd13ad7a..e991750bb08af35fea6ffd30359130898db38ac8 100755 (executable)
@@ -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 23ef0e0fdc19d6d321c9204986e63b245bb49032..213dec618999c9271dd745378ac2d07b2b42f40c 100644 (file)
--- 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++;
index 8004de4c31514509956c68b7f0791264e11b6605..f506fc94593fa550baf5cbead3c3e0b0ce6f2a2b 100644 (file)
@@ -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));
index c2e82d59b8df445765872854e39e79cc673a0db2..ed761e49f782580cfa8bd8069f07c3edd1597e56 100644 (file)
@@ -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) {