From: Frederic Marchal Date: Sun, 26 Jul 2015 08:30:03 +0000 (+0200) Subject: Process users in redirector log as those from the access log X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=11797b20468e9f2e6094920259e27ce3af41a9bb;p=thirdparty%2Fsarg.git Process users in redirector log as those from the access log Users in the redirector log are include, excluded and aliased as those in the access.log. --- diff --git a/redirector.c b/redirector.c index abd1fae..5b1b896 100644 --- a/redirector.c +++ b/redirector.c @@ -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); }