//! 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);
+
+ 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) {
+ if (*auser==ALIAS_PREFIX) auser++;//no need for that indicator for a user name
+ user=auser;
+ *IsIp=false;
+ }
+
+ // 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 (user[0]=='\0' || (user[1]=='\0' && (user[0]=='-' || user[0]==' ' || user[0]==':')))
+ return(USERERR_EmptyUser);
+
+ *UserPtr=user;
+ return(USERERR_NoError);
}