]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Process users in redirector log as those from the access log
authorFrederic Marchal <fmarchal@users.sourceforge.net>
Sun, 26 Jul 2015 08:30:03 +0000 (10:30 +0200)
committerFrederic Marchal <fmarchal@users.sourceforge.net>
Sun, 26 Jul 2015 08:30:03 +0000 (10:30 +0200)
Users in the redirector log are include, excluded and aliased as those in
the access.log.

redirector.c

index abd1fae5640f5d3ae11a7aea3cb84ba19ad65607..5b1b896ab266339c179d0764df3ff60da98a36e7 100644 (file)
@@ -45,9 +45,11 @@ static void parse_log(FILE *fp_ou,char *buf,int dfrom,int duntil)
        char source[128], list[128];
        char full_url[MAX_URL_LEN];
        const char *url;
-       char user[MAX_USER_LEN];
+       char UserBuf[MAX_USER_LEN];
+       const char *user;
        char ip[45];
        char userlabel[MAX_USER_LEN];
+       char IpBuf[MAX_USER_LEN];
        long long int lmon, lday, lyear;
        int mon, day, year;
        int  idata=0;
@@ -55,6 +57,7 @@ static void parse_log(FILE *fp_ou,char *buf,int dfrom,int duntil)
        struct getwordstruct gwarea;
        struct getwordstruct gwarea1;
        struct userinfostruct *uinfo;
+       enum UserProcessError PUser;
 
        getword_start(&gwarea,buf);
        if(RedirectorLogFormat[0] != '\0') {
@@ -71,7 +74,7 @@ static void parse_log(FILE *fp_ou,char *buf,int dfrom,int duntil)
                source[0]='\0';
                list[0]='\0';
                ip[0]='\0';
-               user[0]='\0';
+               UserBuf[0]='\0';
                full_url[0]='\0';
                while(strcmp(leks,"end") != 0) {
                        if (getword(leks,sizeof(leks),&gwarea1,'#')<0) {
@@ -123,12 +126,12 @@ static void parse_log(FILE *fp_ou,char *buf,int dfrom,int duntil)
                                        }
                                        strcpy(ip,res);
                                } else if(strcmp(leks,"user") == 0) {
-                                       if (strlen(res)>=sizeof(user)) {
+                                       if (strlen(res)>=sizeof(UserBuf)) {
                                                debuga(__FILE__,__LINE__,_("User ID too long in redirector log file \"%s\"\n"),wentp);
                                                RedirectorErrors++;
                                                return;
                                        }
-                                       strcpy(user,res);
+                                       strcpy(UserBuf,res);
                                } else if(strcmp(leks,"url") == 0) {
                                        /*
                                         * Don't worry about the url being truncated as we only keep the host name
@@ -173,7 +176,7 @@ static void parse_log(FILE *fp_ou,char *buf,int dfrom,int duntil)
                        RedirectorErrors++;
                        return;
                }
-               if (getword_skip(MAXLEN,&gwarea,' ')<0 || getword(user,sizeof(user),&gwarea,' ')<0) {
+               if (getword_skip(MAXLEN,&gwarea,' ')<0 || getword(UserBuf,sizeof(UserBuf),&gwarea,' ')<0) {
                        debuga(__FILE__,__LINE__,_("Invalid user in file \"%s\"\n"),wentp);
                        RedirectorErrors++;
                        return;
@@ -189,33 +192,19 @@ static void parse_log(FILE *fp_ou,char *buf,int dfrom,int duntil)
                        return;
        }
 
-       if (StripSuffixLen>0)
-       {
-               int x=strlen(user);
-               if (x>StripSuffixLen && strcasecmp(user+(x-StripSuffixLen),StripUserSuffix)==0)
-                       user[x-StripSuffixLen]='\0';
-       }
-       if(UserIp) {
-               strcpy(user,ip);
-               id_is_ip=true;
-       } else {
-               id_is_ip=false;
-               if (user[0]=='\0' || (user[1]=='\0' && (user[0]=='-' || user[0]==' '))) {
-                       if(RecordsWithoutUser == RECORDWITHOUTUSER_IP) {
-                               strcpy(user,ip);
-                               id_is_ip=true;
-                       }
-                       if(RecordsWithoutUser == RECORDWITHOUTUSER_IGNORE)
-                               return;
-                       if(RecordsWithoutUser == RECORDWITHOUTUSER_EVERYBODY)
-                               strcpy(user,"everybody");
-               }
-       }
+       user=UserBuf;
+       PUser=process_user(&user,ip,&id_is_ip);
+       if (PUser!=USERERR_NoError) return;
+
        uinfo=userinfo_find_from_id(user);
        if (!uinfo) {
                uinfo=userinfo_create(user,(id_is_ip) ? NULL : ip);
                uinfo->no_report=true;
-               if(Ip2Name && id_is_ip) ip2name(user,sizeof(user));
+               if (Ip2Name && id_is_ip) {
+                       strcpy(IpBuf,user);
+                       ip2name(IpBuf,sizeof(IpBuf));
+                       user=IpBuf;
+               }
                user_find(userlabel,MAX_USER_LEN, user);
                userinfo_label(uinfo,userlabel);
        }