]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Fix an error introduced when stripping the user domain
authorFrederic Marchal <fmarchal@users.sourceforge.net>
Fri, 24 Jul 2015 14:09:20 +0000 (16:09 +0200)
committerFrederic Marchal <fmarchal@users.sourceforge.net>
Fri, 24 Jul 2015 14:09:20 +0000 (16:09 +0200)
Several reports such as the download and authentication reports would
fail with an error about unknown user "-".

It has been fixed by choosing a new method to strip the domain.

The change partially reverts some changes made in commit
36a0b94cbcaa8a9899fcc878639945e8787d0fec that were responsible for the
proper user name not being propagated to the intermediary report files.

Thanks to Yakushev Evgeniy for reporting this bug.

include/readlog.h
readlog.c
readlog_common.c
readlog_extlog.c
readlog_sarg.c
readlog_squid.c

index 0861344a56ebcb006e353f435931d45f6280cd43..a481362292df1dce3eb1290fd7c7e7674214e05d 100644 (file)
@@ -28,7 +28,7 @@ struct ReadLogStruct
        //! The IP address connecting to internet.
        const char *Ip;
        //! The user's name.
-       char *User;
+       const char *User;
        /*!
        The URL of the visited site.
 
index cface7d5bcdb0f669482c350f07073fafcf6bf05..c984b6ea229d8a82d5ed17007a43a99b9bb0c143 100644 (file)
--- a/readlog.c
+++ b/readlog.c
@@ -312,7 +312,7 @@ static void ReadOneLogFile(struct ReadLogDataStruct *Filter,const char *arq)
        char smartfilter[MAXLEN];
        const char *url;
        const char *user;
-       const char *UserPtr;
+       char UserBuffer[MAX_USER_LEN];
        int OutputNonZero = REPORT_EVERY_X_LINES ;
        int idata=0;
        int x;
@@ -533,7 +533,17 @@ static void ReadOneLogFile(struct ReadLogDataStruct *Filter,const char *arq)
                {
                        x=strlen(log_entry.User);
                        if (x>StripSuffixLen && strcasecmp(log_entry.User+(x-StripSuffixLen),StripUserSuffix)==0)
-                               log_entry.User[x-StripSuffixLen]='\0';
+                       {
+                               if (x-StripSuffixLen>=sizeof(UserBuffer)) {
+                                       if (debugz>=LogLevel_Process) debuga(__FILE__,__LINE__,_("User ID too long: %s\n"),log_entry.User);
+                                       excluded_count[ER_UserNameTooLong]++;
+                                       totregsx++;
+                                       continue;
+                               }
+                               safe_strcpy(UserBuffer,log_entry.User,sizeof(UserBuffer));
+                               UserBuffer[x-StripSuffixLen]='\0';
+                               log_entry.User=UserBuffer;
+                       }
                }
                if(strlen(log_entry.User) > MAX_USER_LEN) {
                        if (debugz>=LogLevel_Process) debuga(__FILE__,__LINE__,_("User ID too long: %s\n"),log_entry.User);
@@ -618,14 +628,14 @@ static void ReadOneLogFile(struct ReadLogDataStruct *Filter,const char *arq)
                }
 
                if(UserIp) {
-                       UserPtr=log_entry.Ip;
+                       log_entry.User=log_entry.Ip;
                        id_is_ip=true;
                } else {
-                       UserPtr=log_entry.User;
+                       log_entry.User=log_entry.User;
                        id_is_ip=false;
-                       if ((UserPtr[0]=='\0') || (UserPtr[1]=='\0' && (UserPtr[0]=='-' || UserPtr[0]==' '))) {
+                       if ((log_entry.User[0]=='\0') || (log_entry.User[1]=='\0' && (log_entry.User[0]=='-' || log_entry.User[0]==' '))) {
                                if(RecordsWithoutUser == RECORDWITHOUTUSER_IP) {
-                                       UserPtr=log_entry.Ip;
+                                       log_entry.User=log_entry.Ip;
                                        id_is_ip=true;
                                }
                                if(RecordsWithoutUser == RECORDWITHOUTUSER_IGNORE) {
@@ -633,25 +643,25 @@ static void ReadOneLogFile(struct ReadLogDataStruct *Filter,const char *arq)
                                        continue;
                                }
                                if(RecordsWithoutUser == RECORDWITHOUTUSER_EVERYBODY)
-                                       UserPtr="everybody";
+                                       log_entry.User="everybody";
                        } else {
                                if(NtlmUserFormat == NTLMUSERFORMAT_USER) {
-                                       if ((str=strchr(UserPtr,'+'))!=NULL || (str=strchr(UserPtr,'\\'))!=NULL || (str=strchr(UserPtr,'_'))!=NULL) {
-                                               UserPtr=str+1;
+                                       if ((str=strchr(log_entry.User,'+'))!=NULL || (str=strchr(log_entry.User,'\\'))!=NULL || (str=strchr(log_entry.User,'_'))!=NULL) {
+                                               log_entry.User=str+1;
                                        }
                                }
                        }
                }
 
                if(us[0] != '\0'){
-                       if(strcmp(UserPtr,us)!=0) {
+                       if(strcmp(log_entry.User,us)!=0) {
                                excluded_count[ER_UntrackedUser]++;
                                continue;
                        }
                }
 
                if(Filter->SysUsers) {
-                       snprintf(wuser,sizeof(wuser),":%s:",UserPtr);
+                       snprintf(wuser,sizeof(wuser),":%s:",log_entry.User);
                        if(strstr(userfile, wuser) == 0) {
                                excluded_count[ER_SysUser]++;
                                continue;
@@ -659,21 +669,21 @@ static void ReadOneLogFile(struct ReadLogDataStruct *Filter,const char *arq)
                }
 
                if(Filter->UserFilter) {
-                       if(!vuexclude(UserPtr)) {
-                               if (debugz>=LogLevel_Process) debuga(__FILE__,__LINE__,_("Excluded user: %s\n"),UserPtr);
+                       if(!vuexclude(log_entry.User)) {
+                               if (debugz>=LogLevel_Process) debuga(__FILE__,__LINE__,_("Excluded user: %s\n"),log_entry.User);
                                excluded_count[ER_IgnoredUser]++;
                                totregsx++;
                                continue;
                        }
                }
 
-               user=process_user(UserPtr);
-               if (UserPtr!=user)
+               user=process_user(log_entry.User);
+               if (log_entry.User!=user)
                {
-                       UserPtr=user;
+                       log_entry.User=user;
                        id_is_ip=false;
                }
-               if (UserPtr[0]=='\0' || (UserPtr[1]=='\0' && (UserPtr[0]=='-' || UserPtr[0]==' ' || UserPtr[0]==':'))) {
+               if (log_entry.User[0]=='\0' || (log_entry.User[1]=='\0' && (log_entry.User[0]=='-' || log_entry.User[0]==' ' || log_entry.User[0]==':'))) {
                        excluded_count[ER_NoUser]++;
                        continue;
                }
@@ -692,14 +702,14 @@ static void ReadOneLogFile(struct ReadLogDataStruct *Filter,const char *arq)
 
                nopen=0;
                prev_ufile=NULL;
-               for (ufile=first_user_file ; ufile && strcmp(UserPtr,ufile->user->id)!=0 ; ufile=ufile->next) {
+               for (ufile=first_user_file ; ufile && strcmp(log_entry.User,ufile->user->id)!=0 ; ufile=ufile->next) {
                        prev_ufile=ufile;
                        if (ufile->file) nopen++;
                }
                if (!ufile) {
                        ufile=malloc(sizeof(*ufile));
                        if (!ufile) {
-                               debuga(__FILE__,__LINE__,_("Not enough memory to store the user %s\n"),UserPtr);
+                               debuga(__FILE__,__LINE__,_("Not enough memory to store the user %s\n"),log_entry.User);
                                exit(EXIT_FAILURE);
                        }
                        memset(ufile,0,sizeof(*ufile));
@@ -709,7 +719,7 @@ static void ReadOneLogFile(struct ReadLogDataStruct *Filter,const char *arq)
                         * This id_is_ip stuff is just to store the string only once if the user is
                         * identified by its IP address instead of a distinct ID and IP address.
                         */
-                       uinfo=userinfo_create(UserPtr,(id_is_ip) ? NULL : log_entry.Ip);
+                       uinfo=userinfo_create(log_entry.User,(id_is_ip) ? NULL : log_entry.Ip);
                        ufile->user=uinfo;
                        nusers++;
                } else {
@@ -758,14 +768,14 @@ static void ReadOneLogFile(struct ReadLogDataStruct *Filter,const char *arq)
                if (fprintf(ufile->file, "%s\t%s\t%s\t%s\t%"PRIu64"\t%s\t%ld\t%s\n",dia,hora,
                                                                log_entry.Ip,url,(uint64_t)log_entry.DataSize,
                                                                log_entry.HttpCode,log_entry.ElapsedTime,smartfilter)<=0) {
-                       debuga(__FILE__,__LINE__,_("Write error in the log file of user %s\n"),UserPtr);
+                       debuga(__FILE__,__LINE__,_("Write error in the log file of user %s\n"),log_entry.User);
                        exit(EXIT_FAILURE);
                }
                records_kept++;
 
                if (fp_log && log_line.current_format!=&ReadSargLog) {
                        fprintf(fp_log, "%s\t%s\t%s\t%s\t%s\t%"PRIu64"\t%s\t%ld\t%s\n",dia,hora,
-                                                       UserPtr,log_entry.Ip,url,(uint64_t)log_entry.DataSize,
+                                                       log_entry.User,log_entry.Ip,url,(uint64_t)log_entry.DataSize,
                                                        log_entry.HttpCode,log_entry.ElapsedTime,smartfilter);
                }
 
@@ -788,7 +798,7 @@ static void ReadOneLogFile(struct ReadLogDataStruct *Filter,const char *arq)
 
                if (debugz>=LogLevel_Data){
                        printf("IP=\t%s\n",log_entry.Ip);
-                       printf("USER=\t%s\n",UserPtr);
+                       printf("USER=\t%s\n",log_entry.User);
                        printf("ELAP=\t%ld\n",log_entry.ElapsedTime);
                        printf("DATE=\t%s\n",dia);
                        printf("TIME=\t%s\n",hora);
index e223d01166bcdff6f19383285f8e10fae5274683..b39ee9b9a313c5f8164f25144cd31e8f3223d98f 100644 (file)
@@ -80,6 +80,7 @@ static enum ReadLogReturnCodeEnum Common_ReadEntry(char *Line,struct ReadLogStru
        int Minute;
        int Second;
        char *Ip;
+       char *User;
 
        // get IP address
        Entry->Ip=Ip=Line;
@@ -94,7 +95,7 @@ static enum ReadLogReturnCodeEnum Common_ReadEntry(char *Line,struct ReadLogStru
        }
 
        // the ID of the user or - if the user is unidentified
-       Entry->User=++Line;
+       Entry->User=User=++Line;
        for (UserLen=0 ; *Line && *Line!=' ' ; UserLen++) Line++;
        if (*Line!=' ' || UserLen==0) return(RLRC_Unknown);
 
@@ -195,7 +196,7 @@ static enum ReadLogReturnCodeEnum Common_ReadEntry(char *Line,struct ReadLogStru
        Ip[IpLen]='\0';
        Entry->HttpCode[HttpCodeLen]='\0';
        Entry->Url[UrlLen]='\0';
-       Entry->User[UserLen]='\0';
+       User[UserLen]='\0';
 
        return(RLRC_NoError);
 }
index 9718008b77aadbc58fccbc0b35e0a47565746815..4498497a3cbb3aaa01ac150f3f1537d6dc2cac43 100644 (file)
@@ -480,6 +480,7 @@ static enum ReadLogReturnCodeEnum ExtLog_ReadEntry(char *Line,struct ReadLogStru
        enum ext_col_id col_id;
        char *Ip=NULL;
        char *IpEnd;
+       char *User=NULL;
        char *UserEnd;
        char *UrlEnd;
        char *HttpCodeEnd;
@@ -512,7 +513,7 @@ static enum ReadLogReturnCodeEnum ExtLog_ReadEntry(char *Line,struct ReadLogStru
                                if (!Line) return(RLRC_Unknown);
                                break;
                        case EXTCOL_UserName:
-                               Entry->User=Line;
+                               Entry->User=User=Line;
                                Line=ExtLog_GetString(Line,col,&UserEnd);
                                if (!Line) return(RLRC_Unknown);
                                break;
@@ -588,7 +589,7 @@ static enum ReadLogReturnCodeEnum ExtLog_ReadEntry(char *Line,struct ReadLogStru
        }
 
        ExtLog_FixString(Ip,IpEnd);
-       ExtLog_FixString(Entry->User,UserEnd);
+       ExtLog_FixString(User,UserEnd);
        ExtLog_FixString(Entry->Url,UrlEnd);
        ExtLog_FixString(Entry->HttpCode,HttpCodeEnd);
        if (!Entry->Url)
index 8d429ad3507e2f89d425ee60bec462908f5fd0c4..c60ff285d0f1340b3cefddf778f0b44abf2a9988 100644 (file)
@@ -68,6 +68,7 @@ static enum ReadLogReturnCodeEnum Sarg_ReadEntry(char *Line,struct ReadLogStruct
        int Minute;
        int Second;
        char *Ip;
+       char *User;
 
        if (strncmp(Line,"*** SARG Log ***",16)==0) {
                if (InvalidFileName) {
@@ -119,7 +120,7 @@ static enum ReadLogReturnCodeEnum Sarg_ReadEntry(char *Line,struct ReadLogStruct
        Entry->EntryTime.tm_isdst=-1;
 
        // the ID of the user
-       Entry->User=++Line;
+       Entry->User=User=++Line;
        for (UserLen=0 ; *Line && *Line!='\t' ; UserLen++) Line++;
        if (*Line!='\t' || UserLen==0) return(RLRC_Unknown);
 
@@ -163,7 +164,7 @@ static enum ReadLogReturnCodeEnum Sarg_ReadEntry(char *Line,struct ReadLogStruct
        Ip[IpLen]='\0';
        Entry->HttpCode[HttpCodeLen]='\0';
        Entry->Url[UrlLen]='\0';
-       Entry->User[UserLen]='\0';
+       User[UserLen]='\0';
 
        return(RLRC_NoError);
 }
index 188cb56836083dbcc26751e1c0b4d36fbf2a3adb..529abc9a5290c20e69332c9137fea30d2b6b5bf0 100644 (file)
@@ -56,6 +56,7 @@ static enum ReadLogReturnCodeEnum Squid_ReadEntry(char *Line,struct ReadLogStruc
        int UserLen;
        struct tm *tt;
        char *Ip;
+       char *User;
 
        // get log time.
        Begin=Line;
@@ -120,7 +121,7 @@ static enum ReadLogReturnCodeEnum Squid_ReadEntry(char *Line,struct ReadLogStruc
        if (*Line!=' ' || UrlLen==0) return(RLRC_Unknown);
 
        // the ID of the user or - if the user is unidentified
-       Entry->User=++Line;
+       Entry->User=User=++Line;
        for (UserLen=0 ; *Line && *Line!=' ' ; UserLen++) Line++;
        if (*Line!=' ' || UserLen==0) return(RLRC_Unknown);
 
@@ -137,7 +138,7 @@ static enum ReadLogReturnCodeEnum Squid_ReadEntry(char *Line,struct ReadLogStruc
        Entry->HttpCode[HttpCodeLen]='\0';
        Entry->HttpMethod[HttpMethodLen]='\0';
        Entry->Url[UrlLen]='\0';
-       Entry->User[UserLen]='\0';
+       User[UserLen]='\0';
 
        return(RLRC_NoError);
 }