]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Store the user in the structure
authorFrédéric Marchal <fmarchal@users.sourceforge.net>
Tue, 3 Jul 2012 14:42:31 +0000 (16:42 +0200)
committerFrédéric Marchal <fmarchal@users.sourceforge.net>
Tue, 3 Jul 2012 14:42:31 +0000 (16:42 +0200)
Another step to use a structure to be passed around between modules.

readlog.c

index baef44dce9bc9ff23552b377707d817e53ccdf62..79a3e9381de45e6678c1fe69739680d932eb9e24 100644 (file)
--- a/readlog.c
+++ b/readlog.c
@@ -325,6 +325,7 @@ int ReadLogFile(struct ReadLogDataStruct *Filter)
                                                        exit(EXIT_FAILURE);
                                                }
                                        }
+                                       log_entry.User=user;
                                        if (getword(data,sizeof(data),&gwarea,']')<0 || getword_skip(MAXLEN,&gwarea,'"')<0 ||
                                                        getword(fun,sizeof(fun),&gwarea,' ')<0) {
                                                debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq);
@@ -437,6 +438,7 @@ int ReadLogFile(struct ReadLogDataStruct *Filter)
                                                debuga(_("Maybe you have a broken user ID in your %s file\n"),arq);
                                                exit(EXIT_FAILURE);
                                        }
+                                       log_entry.User=user;
                                        ilf=ILF_Squid;
                                        ilf_count[ilf]++;
 
@@ -466,6 +468,7 @@ int ReadLogFile(struct ReadLogDataStruct *Filter)
                                        debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq);
                                        exit(EXIT_FAILURE);
                                }
+                               log_entry.User=user;
                                if (getword(ip,sizeof(ip),&gwarea,'\t')<0) {
                                        debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq);
                                        exit(EXIT_FAILURE);
@@ -568,6 +571,7 @@ int ReadLogFile(struct ReadLogDataStruct *Filter)
                                                        exit(EXIT_FAILURE);
                                                }
                                                strcpy(user,str);
+                                               log_entry.User=user;
                                        } else if (x==isa_cols[ISACOL_Date]) {
                                                if (strlen(str)>=sizeof(data)) {
                                                        debuga(_("Maybe you have a broken date in your %s file\n"),arq);
@@ -640,6 +644,10 @@ int ReadLogFile(struct ReadLogDataStruct *Filter)
                                debuga(_("Unknown input log file format: no IP addresses\n"));
                                break;
                        }
+                       if (log_entry.User==NULL) {
+                               debuga(_("Unknown input log file format: no user\n"));
+                               break;
+                       }
 
                        if(debugm)
                                printf("DATE=%s IDATA=%d DFROM=%d DUNTIL=%d\n",Filter->DateRange,idata,dfrom,duntil);
@@ -656,15 +664,15 @@ int ReadLogFile(struct ReadLogDataStruct *Filter)
                                continue;
 
 
-                       if(strlen(user) > MAX_USER_LEN) {
-                               if (debugm) printf(_("User ID too long: %s\n"),user);
+                       if(strlen(log_entry.User) > MAX_USER_LEN) {
+                               if (debugm) printf(_("User ID too long: %s\n"),log_entry.User);
                                totregsx++;
                                continue;
                        }
 
                        // include_users
                        if(IncludeUsers[0] != '\0') {
-                               snprintf(val1,sizeof(val1),":%s:",user);
+                               snprintf(val1,sizeof(val1),":%s:",log_entry.User);
                                if((str=(char *) strstr(IncludeUsers,val1)) == (char *) NULL )
                                        continue;
                        }
@@ -675,7 +683,7 @@ int ReadLogFile(struct ReadLogDataStruct *Filter)
                                continue;
                        }
 
-                       if(testvaliduserchar(user))
+                       if(testvaliduserchar(log_entry.User))
                                continue;
 
                        // replace any tab by a single space
@@ -721,53 +729,52 @@ int ReadLogFile(struct ReadLogDataStruct *Filter)
                        }
 
                        if(UserIp) {
-                               strcpy(user,log_entry.Ip);
+                               log_entry.User=log_entry.Ip;
                                id_is_ip=true;
                        } else {
                                id_is_ip=false;
-                               if(strcmp(user,"-") == 0 || strcmp(user," ") == 0 || strcmp(user,"") == 0) {
+                               if(strcmp(log_entry.User,"-") == 0 || strcmp(log_entry.User," ") == 0 || strcmp(log_entry.User,"") == 0) {
                                        if(RecordsWithoutUser == RECORDWITHOUTUSER_IP) {
-                                               strcpy(user,log_entry.Ip);
+                                               log_entry.User=log_entry.Ip;
                                                id_is_ip=true;
                                        }
                                        if(RecordsWithoutUser == RECORDWITHOUTUSER_IGNORE)
                                                continue;
                                        if(RecordsWithoutUser == RECORDWITHOUTUSER_EVERYBODY)
-                                               strcpy(user,"everybody");
+                                               log_entry.User="everybody";
                                } else {
-                                       strlow(user);
+                                       strlow(log_entry.User);
                                        if(NtlmUserFormat == NTLMUSERFORMAT_USER) {
-                                               if((str = strchr(user,'_')) != 0) {
-                                                       strcpy(warea,str+1);
-                                                       strcpy(user,warea);
+                                               if((str = strchr(log_entry.User,'_')) != 0) {
+                                                       log_entry.User=str+1;
                                                }
-                                               if((str = strchr(user,'+')) != 0) {
-                                                       strcpy(warea,str+1);
-                                                       strcpy(user,warea);
+                                               if((str = strchr(log_entry.User,'+')) != 0) {
+                                                       log_entry.User=str+1;
                                                }
                                        }
                                }
                        }
 
                        if(us[0] != '\0'){
-                               if(strcmp(user,us)!=0) continue;
+                               if(strcmp(log_entry.User,us)!=0) continue;
                        }
 
                        if(Filter->SysUsers) {
-                               snprintf(wuser,sizeof(wuser),":%s:",user);
+                               snprintf(wuser,sizeof(wuser),":%s:",log_entry.User);
                                if(strstr(userfile, wuser) == 0)
                                        continue;
                        }
 
                        if(Filter->UserFilter) {
-                               if(!vuexclude(user)) {
-                                       if (debugm) printf(_("Excluded user: %s\n"),user);
+                               if(!vuexclude(log_entry.User)) {
+                                       if (debugm) printf(_("Excluded user: %s\n"),log_entry.User);
                                        totregsx++;
                                        continue;
                                }
                        }
 
-                       if(strcmp(user,"-") ==0 || strcmp(user," ") ==0 || strcmp(user,"") ==0 || strcmp(user,":") ==0)
+                       if(strcmp(log_entry.User,"-") ==0 || strcmp(log_entry.User," ") ==0 || 
+                          strcmp(log_entry.User,"") ==0 || strcmp(log_entry.User,":") ==0)
                                continue;
 
                        nbytes=atol(tam);
@@ -786,20 +793,20 @@ int ReadLogFile(struct ReadLogDataStruct *Filter)
 
                        nopen=0;
                        prev_ufile=NULL;
-                       for (ufile=first_user_file ; ufile && strcmp(user,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(_("Not enough memory to store the user %s\n"),user);
+                                       debuga(_("Not enough memory to store the user %s\n"),log_entry.User);
                                        exit(EXIT_FAILURE);
                                }
                                memset(ufile,0,sizeof(*ufile));
                                ufile->next=first_user_file;
                                first_user_file=ufile;
-                               uinfo=userinfo_create(user);
+                               uinfo=userinfo_create(log_entry.User);
                                ufile->user=uinfo;
                                uinfo->id_is_ip=id_is_ip;
                        } else {
@@ -844,12 +851,12 @@ int ReadLogFile(struct ReadLogDataStruct *Filter)
                        strftime(hora,sizeof(hora),"%H:%M:%S",log_entry.EntryTime);
 
                        if (fprintf(ufile->file, "%s\t%s\t%s\t%s\t%ld\t%s\t%ld\t%s\n",dia,hora,log_entry.Ip,url,nbytes,code,elap_time,smartfilter)<=0) {
-                               debuga(_("Write error in the log file of user %s\n"),user);
+                               debuga(_("Write error in the log file of user %s\n"),log_entry.User);
                                exit(EXIT_FAILURE);
                        }
 
                        if(fp_log && ilf!=ILF_Sarg)
-                               fprintf(fp_log, "%s\t%s\t%s\t%s\t%s\t%ld\t%s\t%ld\t%s\n",dia,hora,user,log_entry.Ip,url,nbytes,code,elap_time,smartfilter);
+                               fprintf(fp_log, "%s\t%s\t%s\t%s\t%s\t%ld\t%s\t%ld\t%s\n",dia,hora,log_entry.User,log_entry.Ip,url,nbytes,code,elap_time,smartfilter);
 
                        totregsg++;
 
@@ -862,16 +869,16 @@ int ReadLogFile(struct ReadLogDataStruct *Filter)
                                                exit (1);
                                        }
                                }
-                               fprintf(fp_Download_Unsort,"%s\t%s\t%s\t%s\t%s\n",dia,hora,user,log_entry.Ip,download_url);
+                               fprintf(fp_Download_Unsort,"%s\t%s\t%s\t%s\t%s\n",dia,hora,log_entry.User,log_entry.Ip,download_url);
                        }
 
                        if(fp_denied && strstr(code,"DENIED/403") != 0) {
-                               fprintf(fp_denied, "%s\t%s\t%s\t%s\t%s\n",dia,hora,user,log_entry.Ip,full_url);
+                               fprintf(fp_denied, "%s\t%s\t%s\t%s\t%s\n",dia,hora,log_entry.User,log_entry.Ip,full_url);
                                denied_count++;
                        }
                        if((ReportType & REPORT_TYPE_AUTH_FAILURES) != 0) {
                                if(fp_authfail && (strstr(code,"DENIED/401") != 0 || strstr(code,"DENIED/407") != 0)) {
-                                       fprintf(fp_authfail, "%s\t%s\t%s\t%s\t%s\n",dia,hora,user,log_entry.Ip,full_url);
+                                       fprintf(fp_authfail, "%s\t%s\t%s\t%s\t%s\n",dia,hora,log_entry.User,log_entry.Ip,full_url);
                                        authfail_count++;
                                }
                        }
@@ -891,7 +898,7 @@ int ReadLogFile(struct ReadLogDataStruct *Filter)
 
                        if(debugm){
                                printf("IP=\t%s\n",log_entry.Ip);
-                               printf("USER=\t%s\n",user);
+                               printf("USER=\t%s\n",log_entry.User);
                                printf("ELAP=\t%ld\n",elap_time);
                                printf("DATE=\t%s\n",dia);
                                printf("TIME=\t%s\n",hora);