//! Length of the suffix to strip from the user name.
int StripSuffixLen=0;
-extern char *userfile;
extern FileListObject AccessLog;
extern const struct ReadLogProcessStruct ReadSquidLog;
char *str;
char hora[30];
char dia[128]="";
- char wuser[MAXLEN];
char tmp3[MAXLEN]="";
char download_url[MAXLEN];
char smartfilter[MAXLEN];
const char *url;
- const char *user;
- char UserBuffer[MAX_USER_LEN];
int OutputNonZero = REPORT_EVERY_X_LINES ;
int idata=0;
int x;
bool download_flag=false;
bool id_is_ip;
enum ReadLogReturnCodeEnum log_entry_status;
+ enum UserProcessError PUser;
struct stat logstat;
struct getwordstruct gwarea;
struct userfilestruct *prev_ufile;
continue;
}
- if (StripSuffixLen>0)
+ PUser=process_user(&log_entry.User,log_entry.Ip,&id_is_ip);
+ switch (PUser)
{
- x=strlen(log_entry.User);
- if (x>StripSuffixLen && strcasecmp(log_entry.User+(x-StripSuffixLen),StripUserSuffix)==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,x-StripSuffixLen+1);
- 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);
- excluded_count[ER_UserNameTooLong]++;
- totregsx++;
- continue;
- }
-
- // include_users
- if(IncludeUsers[0] != '\0') {
- snprintf(val1,sizeof(val1),":%s:",log_entry.User);
- if((str=(char *) strstr(IncludeUsers,val1)) == (char *) NULL ) {
+ case USERERR_NoError:
+ break;
+ case USERERR_NameTooLong:
+ if (debugz>=LogLevel_Process) debuga(__FILE__,__LINE__,_("User ID too long: %s\n"),log_entry.User);
+ excluded_count[ER_UserNameTooLong]++;
+ totregsx++;
+ continue;
+ case USERERR_Excluded:
excluded_count[ER_User]++;
continue;
- }
+ case USERERR_InvalidChar:
+ excluded_count[ER_InvalidUserChar]++;
+ continue;
+ case USERERR_EmptyUser:
+ excluded_count[ER_NoUser]++;
+ continue;
+ case USERERR_SysUser:
+ excluded_count[ER_SysUser]++;
+ continue;
+ case USERERR_Ignored:
+ excluded_count[ER_IgnoredUser]++;
+ totregsx++;
+ continue;
+ case USERERR_Untracked:
+ excluded_count[ER_UntrackedUser]++;
+ continue;
}
if(vercode(log_entry.HttpCode)) {
continue;
}
- if(testvaliduserchar(log_entry.User)) {
- excluded_count[ER_InvalidUserChar]++;
- continue;
- }
-
// replace any tab by a single space
for (str=log_entry.Url ; *str ; str++)
if (*str=='\t') *str=' ';
}
}
- if(UserIp) {
- log_entry.User=log_entry.Ip;
- id_is_ip=true;
- } else {
- log_entry.User=log_entry.User;
- id_is_ip=false;
- if ((log_entry.User[0]=='\0') || (log_entry.User[1]=='\0' && (log_entry.User[0]=='-' || log_entry.User[0]==' '))) {
- if(RecordsWithoutUser == RECORDWITHOUTUSER_IP) {
- log_entry.User=log_entry.Ip;
- id_is_ip=true;
- }
- if(RecordsWithoutUser == RECORDWITHOUTUSER_IGNORE) {
- excluded_count[ER_NoUser]++;
- continue;
- }
- if(RecordsWithoutUser == RECORDWITHOUTUSER_EVERYBODY)
- log_entry.User="everybody";
- } else {
- if(NtlmUserFormat == NTLMUSERFORMAT_USER) {
- 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(log_entry.User,us)!=0) {
- excluded_count[ER_UntrackedUser]++;
- continue;
- }
- }
-
- if(Filter->SysUsers) {
- snprintf(wuser,sizeof(wuser),":%s:",log_entry.User);
- if(strstr(userfile, wuser) == 0) {
- excluded_count[ER_SysUser]++;
- continue;
- }
- }
-
- if(Filter->UserFilter) {
- 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(log_entry.User);
- if (log_entry.User!=user)
- {
- log_entry.User=user;
- id_is_ip=false;
- }
- 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;
- }
-
if (log_entry.DataSize<0) log_entry.DataSize=0;
if (log_entry.ElapsedTime<0) log_entry.ElapsedTime=0;
//! User aliases.
static AliasObject UserAliases=NULL;
+extern struct ReadLogDataStruct ReadFilter;
+extern char StripUserSuffix[MAX_USER_LEN];
+extern int StripSuffixLen;
+extern char *userfile;
+
struct userinfostruct *userinfo_create(const char *userid,const char *ip)
{
struct usergroupstruct *group, *last;
Replace the user's name or ID by an alias if one is defined.
\param user The user's name or ID as extracted from the report.
+
+\retval USERERR_NoError No error.
+\retval USERERR_NameTooLong User name too long.
*/
-const char *process_user(const char *user)
+enum UserProcessError process_user(const char **UserPtr,const char *IpAddress,bool *IsIp)
{
- user=Alias_Replace(UserAliases,user);
- return(user);
+ const char *user=*UserPtr;
+ static char UserBuffer[MAX_USER_LEN];
+ const char *auser;
+
+ if (UserIp) {
+ user=IpAddress;
+ *IsIp=true;
+ } else {
+ *IsIp=false;
+
+ if (StripSuffixLen>0)
+ {
+ int x=strlen(user);
+ if (x>StripSuffixLen && strcasecmp(user+(x-StripSuffixLen),StripUserSuffix)==0)
+ {
+ if (x-StripSuffixLen>=sizeof(UserBuffer))
+ return(USERERR_NameTooLong);
+ safe_strcpy(UserBuffer,user,x-StripSuffixLen+1);
+ user=UserBuffer;
+ }
+ }
+ if (strlen(user)>MAX_USER_LEN)
+ return(USERERR_NameTooLong);
+
+ // include_users
+ if (IncludeUsers[0] != '\0') {
+ char wuser[MAX_USER_LEN+2]=":";
+ char *str;
+
+ strcat(wuser,user);
+ strcat(wuser,":");
+ str=strstr(IncludeUsers,wuser);
+ if (!str)
+ return(USERERR_Excluded);
+ }
+
+ if (testvaliduserchar(user))
+ return(USERERR_InvalidChar);
+
+ if ((user[0]=='\0') || (user[1]=='\0' && (user[0]=='-' || user[0]==' '))) {
+ if(RecordsWithoutUser == RECORDWITHOUTUSER_IP) {
+ user=IpAddress;
+ *IsIp=true;
+ }
+ if (RecordsWithoutUser == RECORDWITHOUTUSER_IGNORE)
+ return(USERERR_EmptyUser);
+ if (RecordsWithoutUser == RECORDWITHOUTUSER_EVERYBODY)
+ user="everybody";
+ } else {
+ if (NtlmUserFormat == NTLMUSERFORMAT_USER) {
+ const char *str;
+ if ((str=strchr(user,'+'))!=NULL || (str=strchr(user,'\\'))!=NULL || (str=strchr(user,'_'))!=NULL) {
+ user=str+1;
+ }
+ }
+ }
+ }
+
+ if (us[0]!='\0' && strcmp(user,us)!=0)
+ return(USERERR_Untracked);
+
+ if (ReadFilter.SysUsers) {
+ char wuser[MAX_USER_LEN+2]=":";
+
+ strcat(wuser,user);
+ strcat(wuser,":");
+ if (strstr(userfile, wuser) == 0)
+ return(USERERR_SysUser);
+ }
+
+ if (ReadFilter.UserFilter) {
+ if (!vuexclude(user)) {
+ if (debugz>=LogLevel_Process) debuga(__FILE__,__LINE__,_("Excluded user: %s\n"),user);
+ return(USERERR_Ignored);
+ }
+ }
+
+ auser=Alias_Replace(UserAliases,user);
+ if (auser!=user) {
+ user=auser;
+ *IsIp=false;
+ }
+
+ if (user[0]=='\0' || (user[1]=='\0' && (user[0]=='-' || user[0]==' ' || user[0]==':')))
+ return(USERERR_EmptyUser);
+
+ *UserPtr=user;
+ return(USERERR_NoError);
}