INCLUDE(CheckFunctionExists)
INCLUDE(CheckTypeSize)
INCLUDE(CheckSymbolExists)
+INCLUDE(CheckCCompilerFlag)
DEFINE_PROPERTY(GLOBAL PROPERTY enable-htmldir BRIEF_DOCS "--enable-htmldir=htmldir"
FULL_DOCS "Select htmldir as the root of your WWW documents")
ADD_EXECUTABLE(sarg ${SRC})
-SET_TARGET_PROPERTIES(sarg PROPERTIES COMPILE_FLAG "${CFLAGS} -Wall -Wextra -Werror=implicit-function-declaration -Werror=format -Wno-sign-compare -Wno-unused-parameter")
SET_TARGET_PROPERTIES(sarg PROPERTIES VERSION "${sarg_VERSION}.${sarg_REVISION}.${sarg_BUILD}")
+SET_TARGET_PROPERTIES(sarg PROPERTIES COMPILE_FLAGS "${CFLAGS} -Wall -Wextra -Wno-sign-compare -Wno-unused-parameter")
+CHECK_C_COMPILER_FLAG("-Werror=implicit-function-declaration" HAVE_WERROR_IMPLICIT_FUNCTION)
+IF(HAVE_WERROR_IMPLICIT_FUNCTION)
+ GET_TARGET_PROPERTY(TMPCFLAGS sarg COMPILE_FLAGS)
+ SET_TARGET_PROPERTIES(sarg PROPERTIES COMPILE_FLAGS "${TMPCFLAGS} -Werror=implicit-function-declaration")
+ENDIF(HAVE_WERROR_IMPLICIT_FUNCTION)
+
+CHECK_C_COMPILER_FLAG("-Werror=format" HAVE_WERROR_FORMAT)
+IF(HAVE_WERROR_FORMAT)
+ GET_TARGET_PROPERTY(TMPCFLAGS sarg COMPILE_FLAGS)
+ SET_TARGET_PROPERTIES(sarg PROPERTIES COMPILE_FLAGS "${TMPCFLAGS} -Werror=format")
+ENDIF(HAVE_WERROR_FORMAT)
+
# Required header files
CHECK_INCLUDE_FILE(stdio.h HAVE_STDIO_H)
CHECK_INCLUDE_FILE(stdlib.h HAVE_STDLIB_H)
OPTION(ENABLE_EXTRA_PROTECT "Enable compile and runtime extra protections" OFF)
IF(ENABLE_EXTRA_PROTECT)
- SET_TARGET_PROPERTIES(sarg PROPERTIES COMPILE_FLAG "${CFLAGS} -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=2 -Werror")
+ GET_TARGET_PROPERTY(TMPCFLAGS sarg COMPILE_FLAGS)
+ SET_TARGET_PROPERTIES(sarg PROPERTIES COMPILE_FLAGS "${TMPCFLAGS} -fstack-protector -D_FORTIFY_SOURCE=2 -Werror")
+ CHECK_C_COMPILER_FLAG("-Werror=format-security" HAVE_WERROR_FORMAT_SECURITY)
+ IF(HAVE_WERROR_FORMAT_SECURITY)
+ GET_TARGET_PROPERTY(TMPCFLAGS sarg COMPILE_FLAGS)
+ SET_TARGET_PROPERTIES(sarg PROPERTIES COMPILE_FLAGS "${TMPCFLAGS} -Werror=format-security")
+ ENDIF(HAVE_WERROR_FORMAT_SECURITY)
ENDIF(ENABLE_EXTRA_PROTECT)
# Save the configuration for the project
SARG ChangeLog
-Dec-03-2009 Version 2.2.7
+Dec-15-2009 Version 2.2.7
- Extra compile and run time protection (FORTIFY_SOURCE) fixed in configure.
- Use tabulations as columns separator in intermediary files to avoid problems when a field of the log contains a space.
- Input log file type detection partly rewritten to clearly distinguish which type is processed where.
- Read the input log file from standard input if log file name is -.
+ - Use string pointers in getword instead of copying the strings over and over.
Dec-14-2009 Version 2.2.6.1
- Remove unecessary dependency on off_t.
{
char htname[MAXLEN];
FILE *fp_auth;
+ struct getwordstruct gwarea;
if(strncmp(UserAuthentication,"yes",3) !=0 )
return;
exit(1);
}
- strcpy(warea,Require);
- if (getword(buf,sizeof(buf),warea,'%')<0) {
+ getword_start(&gwarea,Require);
+ if (getword(buf,sizeof(buf),&gwarea,'%')<0) {
printf("SARG: The \"Require\" entry of your sarg.conf file is too long for your %s file.\n",htname);
exit(1);
}
int z=0;
int count=0;
int cstatus;
+ struct getwordstruct gwarea;
if(strlen(DataFile) > 0) return;
fprintf(fp_ou,"<tr><th class=\"header\">%s</th><th class=\"header\">%s</th><th class=\"header\">%s</th><th class=\"header\">%s</th></tr>\n",text[98],text[111],text[110],text[91]);
while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
- if (getword(data,sizeof(data),buf,'\t')<0 || getword(hora,sizeof(hora),buf,'\t')<0 ||
- getword(user,sizeof(user),buf,'\t')<0 || getword(ip,sizeof(ip),buf,'\t')<0 ||
- getword(url,sizeof(url),buf,'\t')<0) {
+ getword_start(&gwarea,buf);
+ if (getword(data,sizeof(data),&gwarea,'\t')<0 || getword(hora,sizeof(hora),&gwarea,'\t')<0 ||
+ getword(user,sizeof(user),&gwarea,'\t')<0 || getword(ip,sizeof(ip),&gwarea,'\t')<0 ||
+ getword(url,sizeof(url),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",authfail_in);
exit(1);
}
time_t tt;
int idata=0;
struct tm *t;
+ struct getwordstruct gwarea;
if(arq[0] == '\0')
arq="/var/log/squid/access.log";
}
while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
- if (getword(data,sizeof(data),buf,' ')<0) {
+ getword_start(&gwarea,buf);
+ if (getword(data,sizeof(data),&gwarea,' ')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
exit(1);
}
else
strftime(dia, sizeof(dia), "%m/%d/%Y", t);
- printf("%s %02d:%02d:%02d %s",dia,t->tm_hour,t->tm_min,t->tm_sec,buf);
+ printf("%s %02d:%02d:%02d %s",dia,t->tm_hour,t->tm_min,t->tm_sec,gwarea.current);
}
fclose(fp_in);
char wdata[127];
int idata=0;
int cstatus;
+ struct getwordstruct gwarea;
bzero(day, 3);
bzero(mon, 4);
}
while(fgets(buf,sizeof(buf),fp_guard)!=NULL) {
- if(strstr(buf,"\n") != 0)
- buf[strlen(buf)-1]='\0';
- if(strncmp(buf,"#",1) == 0)
+ fixendofline(buf);
+ if(buf[0]=='#')
continue;
if(strstr(buf,"loglocation ") != 0) {
- if (getword(loglocation,sizeof(loglocation),buf,'\'')<0 || getword(loglocation,sizeof(loglocation),buf,'\'')<0) {
+ getword_start(&gwarea,buf);
+ if (getword_skip(MAXLEN,&gwarea,'\'')<0 || getword(loglocation,sizeof(loglocation),&gwarea,'\'')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",DansGuardianConf);
exit(1);
}
}
if(debug) {
- strcpy(buf,text[7]);
- if (getword(urly,sizeof(urly),buf,' ')<0 || getword(href,sizeof(href),buf,' ')<0) {
+ getword_start(&gwarea,text[7]);
+ if (getword(urly,sizeof(urly),&gwarea,' ')<0 || getword(href,sizeof(href),&gwarea,' ')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s entry.\n",text[7]);
exit(1);
}
- debuga("%s DansGuardian %s: %s",urly,buf,loglocation);
+ debuga("%s DansGuardian %s: %s",urly,gwarea.current,loglocation);
}
if((fp_in=MY_FOPEN(loglocation,"r"))==NULL) {
while(fgets(buf,sizeof(buf),fp_in) != NULL) {
if(strstr(buf," *DENIED* ") == 0)
continue;
- if (getword(year,sizeof(year),buf,'.')<0 || getword(mon,sizeof(mon),buf,'.')<0 ||
- getword(day,sizeof(day),buf,' ')<0 || getword(hour,sizeof(hour),buf,' ')<0 ||
- getword(user,sizeof(user),buf,' ')<0 || getword(ip,sizeof(ip),buf,' ')<0 ||
- getword(url,sizeof(url),buf,'/')<0 || getword(url,sizeof(url),buf,'/')<0 ||
- getword(url,sizeof(url),buf,' ')<0 || getword(code1,sizeof(code1),buf,' ')<0 ||
- getword(code1,sizeof(code1),buf,' ')<0 || getword(code2,sizeof(code2),buf,' ')<0) {
+ getword_start(&gwarea,buf);
+ if (getword(year,sizeof(year),&gwarea,'.')<0 || getword(mon,sizeof(mon),&gwarea,'.')<0 ||
+ getword(day,sizeof(day),&gwarea,' ')<0 || getword(hour,sizeof(hour),&gwarea,' ')<0 ||
+ getword(user,sizeof(user),&gwarea,' ')<0 || getword(ip,sizeof(ip),&gwarea,' ')<0 ||
+ getword_skip(MAXLEN,&gwarea,'/')<0 || getword_skip(MAXLEN,&gwarea,'/')<0 ||
+ getword(url,sizeof(url),&gwarea,' ')<0 || getword_skip(255,&gwarea,' ')<0 ||
+ getword(code1,sizeof(code1),&gwarea,' ')<0 || getword(code2,sizeof(code2),&gwarea,' ')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",loglocation);
exit(1);
}
char *str;
int z=0;
int count=0;
+ struct getwordstruct gwarea;
ouser[0]='\0';
fprintf(fp_ou,"<tr><th class=\"header\">%s</th><th class=\"header\">%s</th><th class=\"header\">%s</th><th class=\"header\">%s</th><th class=\"header\">%s</th></tr>\n",text[98],text[111],text[110],text[91],text[129]);
while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
- if (getword(user,sizeof(user),buf,'\t')<0 || getword(date2,sizeof(date2),buf,'\t')<0 ||
- getword(hour,sizeof(hour),buf,'\t')<0 || getword(ip,sizeof(ip),buf,'\t')<0 ||
- getword(url,sizeof(url),buf,'\t')<0 || getword(rule,sizeof(rule),buf,'\n')<0) {
+ getword_start(&gwarea,buf);
+ if (getword(user,sizeof(user),&gwarea,'\t')<0 || getword(date2,sizeof(date2),&gwarea,'\t')<0 ||
+ getword(hour,sizeof(hour),&gwarea,'\t')<0 || getword(ip,sizeof(ip),&gwarea,'\t')<0 ||
+ getword(url,sizeof(url),&gwarea,'\t')<0 || getword(rule,sizeof(rule),&gwarea,'\n')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",dansguardian_in);
exit(1);
}
char olduser[MAXLEN], oldmsg[50], acccode[50], oldaccelap[10], oldacccode[50];
char ipantes[MAXLEN], nameantes[MAXLEN];
char accsmart[MAXLEN];
- char wcrc[50];
char crc2[50];
char wdname[MAXLEN];
- char wname2[MAXLEN];
+ char *str;
DIR *dirp;
struct dirent *direntp;
long long int nbytes=0;
long long int rtotal=0;
long long int incache=0;
long long int oucache=0;
+ struct getwordstruct gwarea;
ipantes[0]='\0';
nameantes[0]='\0';
while ( (direntp = readdir( dirp )) != NULL ) {
if(strstr(direntp->d_name,".log") == 0)
continue;
- sprintf(tmp3,"%s/%s",tmp,direntp->d_name);
+ if (snprintf(tmp3,sizeof(tmp3),"%s/%s",tmp,direntp->d_name)>=sizeof(tmp3)) {
+ fprintf(stderr,"SARG: (datafile) directory path too long: %s/%s\n",tmp,direntp->d_name);
+ exit(1);
+ }
if((fp_in=MY_FOPEN(tmp3,"r"))==NULL){
fprintf(stderr, "SARG: (datafile) %s: %s\n",text[45],tmp);
exit(1);
}
strcpy(wdname,direntp->d_name);
- if (getword(wname2,sizeof(wname2),wdname,'.')<0) {
- printf("SARG: Maybe you have a broken record or garbage in your %s directory.\n",tmp);
- exit(1);
- }
- strcat(user,wname2);
+ str=strchr(wdname,'.');
+ if (str) *str='\0';
+ strcat(user,wdname);
ttopen=0;
while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
- if (getword(accdia,sizeof(accdia),buf,' ')<0 || getword(acchora,sizeof(acchora),buf,' ')<0 ||
- getword(accuser,sizeof(accuser),buf,' ')<0 || getword(accip,sizeof(accip),buf,' ')<0 ||
- getword(accurl,sizeof(accurl),buf,' ')<0 || getword(accbytes,sizeof(accbytes),buf,' ')<0 ||
- getword(acccode,sizeof(acccode),buf,' ')<0 || getword(accelap,sizeof(accelap),buf,' ')<0 ||
- getword(accsmart,sizeof(accsmart),buf,' ')<0 || getword(accsmart,sizeof(accsmart),buf,'"')<0) {
+ getword_start(&gwarea,buf);
+ if (getword(accdia,sizeof(accdia),&gwarea,' ')<0 || getword(acchora,sizeof(acchora),&gwarea,' ')<0 ||
+ getword(accuser,sizeof(accuser),&gwarea,' ')<0 || getword(accip,sizeof(accip),&gwarea,' ')<0 ||
+ getword(accurl,sizeof(accurl),&gwarea,' ')<0 || getword(accbytes,sizeof(accbytes),&gwarea,' ')<0 ||
+ getword(acccode,sizeof(acccode),&gwarea,' ')<0 || getword(accelap,sizeof(accelap),&gwarea,' ')<0 ||
+ getword_skip(20000,&gwarea,' ')<0 || getword(accsmart,sizeof(accsmart),&gwarea,'"')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",tmp3);
exit(1);
}
nbytes+=my_atoll(accbytes);
nelap+=my_atoll(accelap);
- strcpy(wcrc,acccode);
- if (getword(crc2,sizeof(crc2),wcrc,'/')<0) {
- printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",tmp3);
- exit(1);
- }
+ strcpy(crc2,acccode);
+ str=strchr(crc2,'/');
+ if (str) *str='\0';
if(strstr(crc2,"MISS") != 0) oucache+=my_atoll(accbytes);
else incache+=my_atoll(accbytes);
char *str;
int z=0;
int count=0;
+ struct getwordstruct gwarea;
ouser[0]='\0';
ouser2[0]='\0';
fprintf(fp_ou,"<tr><th class=\"header\">%s</th><th class=\"header\">%s</th><th class=\"header\">%s</th><th class=\"header\">%s</th></tr>\n",text[98],text[111],text[110],text[91]);
while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
- if (getword(data,sizeof(data),buf,'\t')<0 || getword(hora,sizeof(hora),buf,'\t')<0 ||
- getword(user,sizeof(user),buf,'\t')<0 || getword(ip,sizeof(ip),buf,'\t')<0 ||
- getword(url,sizeof(url),buf,'\t')<0) {
+ getword_start(&gwarea,buf);
+ if (getword(data,sizeof(data),&gwarea,'\t')<0 || getword(hora,sizeof(hora),&gwarea,'\t')<0 ||
+ getword(user,sizeof(user),&gwarea,'\t')<0 || getword(ip,sizeof(ip),&gwarea,'\t')<0 ||
+ getword(url,sizeof(url),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",denied_in);
exit(1);
}
continue;
}
- if(strlen(BlockIt) > 0)
+ if(BlockIt[0] != '\0')
sprintf(BlockImage,"<a href=\"%s%s?url=%s\"><img src=\"%s/sarg-squidguard-block.png\" border=\"0\"></a> ",wwwDocumentRoot,BlockIt,url,ImageFile);
else BlockImage[0]='\0';
+/*! \fn void getword_start(struct getwordstruct *gwarea, const char *line)
+Initialize the getword buffer with the given text line.
-/*! \fn int getword(char *word, int limit, char *line, int stop)
+\param gwarea The getword buffer to initialize.
+\param line The text line to use in the getword buffer.
+*/
+
+
+
+
+
+/*! \fn void getword_restart(struct getwordstruct *gwarea)
+Restart the getword buffer from the beginning.
+
+\param gwarea The getword buffer to reset.
+*/
+
+
+
+
+
+/*! \fn int getword(char *word, int limit, struct getwordstruct *gwarea, int stop)
Extract one "word" from the text line and remove it from the text line. The word's boundary is defined
by the \a stop character. If multiple stop characters are found after the word, only the first one is
\param word The buffer to store the extracted word.
\param limit The size of the buffer. If the stop character isn't found before that limit is reached,
the function displays an error message and returns an error code.
-\param line The text line from which the word must be extracted.
+\param gwarea The getword buffer initialized by getword_start().
\param stop The character indicating the end of the word.
\retval 0 The word is extracted.
-/*! \fn int getword_multisep(char *word, int limit, char *line, int stop)
+/*! \fn int getword_multisep(char *word, int limit, struct getwordstruct *gwarea, int stop)
Extract one "word" from the text line and remove it from the text line. The word's boundary is defined
by the \a stop character. All the stop characters following the word are removed too. Therefore, passing
\param word The buffer to store the extracted word.
\param limit The size of the buffer. If the stop character isn't found before that limit is reached,
the function displays an error message and returns an error code.
-\param line The text line from which the word must be extracted.
+\param gwarea The getword buffer initialized by getword_start().
\param stop The character indicating the end of the word.
\retval 0 The word is extracted.
-/*! \fn int getword_skip(int limit, char *line, int stop)
+/*! \fn int getword_skip(int limit, struct getwordstruct *gwarea, int stop)
Skip one "word" from the text line and remove it from the text line. The word's boundary is defined
by the \a stop character.
\param limit The maximum number of characters to skip. If the stop character isn't found before that limit is reached,
the function displays an error message and returns an error code.
-\param line The text line from which the word must be extracted.
+\param gwarea The getword buffer initialized by getword_start().
\param stop The character indicating the end of the word.
\retval 0 The word is skipped.
int z=0;
int count=0;
int i;
+ struct getwordstruct gwarea;
ouser[0]='\0';
ouser2[0]='\0';
fprintf(fp_ou,"<tr><th class=\"header\">%s</th><th class=\"header\">%s</th><th class=\"header\">%s</th><th class=\"header\">%s</th></tr>\n",text[98],text[111],text[110],text[91]);
while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
- if (getword(data,sizeof(data),buf,'\t')<0 || getword(hora,sizeof(hora),buf,'\t')<0 ||
- getword(user,sizeof(user),buf,'\t')<0 || getword(ip,sizeof(ip),buf,'\t')<0 ||
- getword(url,sizeof(url),buf,'\t')<0) {
+ getword_start(&gwarea,buf);
+ if (getword(data,sizeof(data),&gwarea,'\t')<0 || getword(hora,sizeof(hora),&gwarea,'\t')<0 ||
+ getword(user,sizeof(user),&gwarea,'\t')<0 || getword(ip,sizeof(ip),&gwarea,'\t')<0 ||
+ getword(url,sizeof(url),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",report_in);
exit(1);
}
struct tm *local;
int cstatus;
char warea[MAXLEN];
+ struct getwordstruct gwarea;
strcpy(wger,dirname);
strcpy(top1,dirname);
olduser[0]='\0';
totuser=0;
- while(fgets(warea,sizeof(warea),fp_in))
- {
- if (getword(user,sizeof(user),warea,'\t')<0) {
+ while(fgets(warea,sizeof(warea),fp_in)) {
+ getword_start(&gwarea,warea);
+ if (getword(user,sizeof(user),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken user in your %s file.\n",wger);
exit(1);
}
if(strcmp(user,"TOTAL") == 0) {
continue;
}
- if (getword(nacc,sizeof(nacc),warea,'\t')<0) {
+ if (getword(nacc,sizeof(nacc),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken number of access in your %s file.\n",wger);
exit(1);
}
- if (getword(nbytes,sizeof(nbytes),warea,'\t')<0) {
+ if (getword(nbytes,sizeof(nbytes),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken number of bytes in your %s file.\n",wger);
exit(1);
}
- if (getword(url,sizeof(url),warea,'\t')<0) {
+ if (getword(url,sizeof(url),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken url in your %s file.\n",wger);
exit(1);
}
- if (getword(ip,sizeof(ip),warea,'\t')<0) {
+ if (getword(ip,sizeof(ip),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken source IP address in your %s file.\n",wger);
exit(1);
}
- if (getword(hora,sizeof(hora),warea,'\t')<0) {
+ if (getword(hora,sizeof(hora),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken time in your %s file.\n",wger);
exit(1);
}
- if (getword(data,sizeof(data),warea,'\t')<0) {
+ if (getword(data,sizeof(data),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken date in your %s file.\n",wger);
exit(1);
}
- if (getword(elap,sizeof(elap),warea,'\t')<0) {
+ if (getword(elap,sizeof(elap),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken elapsed time in your %s file.\n",wger);
exit(1);
}
- if (getword(incac,sizeof(incac),warea,'\t')<0) {
+ if (getword(incac,sizeof(incac),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken in cache column in your %s file.\n",wger);
exit(1);
}
- if (getword(oucac,sizeof(oucac),warea,0)<0) {
+ if (getword(oucac,sizeof(oucac),&gwarea,0)<0) {
printf("SARG: Maybe you have a broken not in cache column in your %s file.\n",wger);
exit(1);
}
while(fgets(warea,sizeof(warea),fp_top1))
{
- if (getword(user,sizeof(user),warea,'\t')<0) {
+ getword_start(&gwarea,warea);
+ if (getword(user,sizeof(user),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken user in your %s file.\n",top1);
exit(1);
}
- if (getword(nbytes,sizeof(nbytes),warea,'\t')<0) {
+ if (getword(nbytes,sizeof(nbytes),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken number of bytes in your %s file.\n",top1);
exit(1);
}
- if (getword(nacc,sizeof(nacc),warea,'\t')<0) {
+ if (getword(nacc,sizeof(nacc),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken number of access in your %s file.\n",top1);
exit(1);
}
- if (getword(elap,sizeof(elap),warea,'\t')<0) {
+ if (getword(elap,sizeof(elap),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken elapsed time in your %s file.\n",top1);
exit(1);
}
int vhexclude(const char *excludefile, const char *url)
{
- char whost[1024];
+ char *whost;
+ char *whost_next;
+ char *whost_dom;
char *str;
char *wurl;
- int len;
+ char *wurl_dom;
char *port;
- len = strlen(excludefile);
- if((str=(char *) malloc(len+1))==NULL) {
- fprintf(stderr, "SARG: %s (%d):\n",text[59], len);
+ if((str=strdup(excludefile))==NULL) {
+ fprintf(stderr, "SARG: %s (%u):\n",text[59], (unsigned int)(strlen(excludefile)+1));
exit(1);
}
- len = strlen(url);
- if((wurl=(char *) malloc(len+1))==NULL) {
- fprintf(stderr, "SARG: %s (%d):\n",text[59], len);
+ if((wurl=strdup(url))==NULL) {
+ fprintf(stderr, "SARG: %s (%u):\n",text[59], (unsigned int)(strlen(url)+1));
exit(1);
}
- whost[0]='\0';
- strcpy(str,excludefile);
- strcpy(wurl,url);
- if (getword(whost,sizeof(whost),str,' ')<0) {
- printf("SARG: Maybe you have a broken record or garbage in your exclude host file.\n");
- exit(1);
- }
+ whost=str;
+ whost_next=strchr(whost,' ');
+ if (whost_next) *whost_next++ = '\0';
port=strchr(wurl,':');
if(port != NULL) {
// remove the port number at the end of the site's address
*port='\0';
}
+ wurl_dom=strchr(wurl,'.');
while(strcmp(whost,"*END*") != 0) {
if(strcmp(wurl,whost) == 0) {
free(str);
return(0);
}
- if(strchr(whost,'*') != 0) {
- if (getword(warea,sizeof(warea),whost,'.')<0) {
- printf("SARG: Maybe you have a broken record or garbage in your exclude host file.\n");
- exit(1);
- }
- if (getword(warea,sizeof(warea),wurl,'.')<0) {
- printf("SARG: Maybe you have a broken record or garbage in your exclude host file.\n");
- exit(1);
- }
- if(strcmp(wurl,whost) == 0) {
+ if(wurl_dom != NULL && strchr(whost,'*') != 0) {
+ whost_dom=strchr(whost,'.');
+ if (whost_dom != NULL && strcmp(wurl_dom,whost_dom) == 0) {
free(wurl);
free(str);
return(0);
}
}
- if (getword(whost,sizeof(whost),str,' ')<0) {
- printf("SARG: Maybe you have a broken record or garbage in your exclude host file.\n");
- exit(1);
- }
+ if (whost_next == NULL) break;
+ whost=whost_next;
+ whost_next=strchr(whost,' ');
+ if (whost_next) *whost_next++ = '\0';
}
free(wurl);
free(str);
static void parmtest(char *buf)
{
char wbuf[50];
+ struct getwordstruct gwarea;
while (*buf && (unsigned char)*buf<=' ') buf++;
if (getparam_string("max_elapsed",buf,MaxElapsed,sizeof(MaxElapsed))>0) return;
if(strstr(buf,"date_format") != 0) {
- if (getword_multisep(wbuf,sizeof(wbuf),buf,' ')<0) {
+ getword_start(&gwarea,buf);
+ if (getword_multisep(wbuf,sizeof(wbuf),&gwarea,' ')<0) {
printf("SARG: Maybe you have a broken record or garbage in date_format parameter.\n");
exit(1);
}
- strncpy(DateFormat,buf,1);
+ strncpy(DateFormat,gwarea.current,1);
fixnone(DateFormat);
return;
}
}
if(strstr(buf,"byte_cost") != 0) {
- if (getword_multisep(wbuf,sizeof(wbuf),buf,' ')<0) {
+ getword_start(&gwarea,buf);
+ if (getword_multisep(wbuf,sizeof(wbuf),&gwarea,' ')<0) {
printf("SARG: Maybe you have a broken record or garbage in byte_cost parameter.\n");
exit(1);
}
- cost=atol(buf);
- if (getword_multisep(wbuf,sizeof(wbuf),buf,' ')<0) {
+ cost=atol(gwarea.current);
+ if (getword_multisep(wbuf,sizeof(wbuf),&gwarea,' ')<0) {
printf("SARG: Maybe you have a broken record or garbage in byte_cost parameter.\n");
exit(1);
}
- nocost=my_atoll(buf);
+ nocost=my_atoll(gwarea.current);
return;
}
int brect[8];
char wdirname[MAXLEN];
char graph[MAXLEN];
+ char buf[MAXLEN];
char wuser[255];
char csort[255];
char data[20];
struct tm *local;
int cstatus;
char s[15];
+ struct getwordstruct gwarea;
+ struct getwordstruct gwarea1;
if(strcmp(Graphs,"yes") != 0) {
unlink(wdirname);
get_usertab_name(wuser,name,sizeof(name));
while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
- if (getword(data,sizeof(data),buf,'\t')<0 || getword(day,sizeof(day),data,'/')<0) {
+ fixendofline(buf);
+ getword_start(&gwarea,buf);
+ if (getword(data,sizeof(data),&gwarea,'\t')<0) {
+ printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",tmp5);
+ exit(1);
+ }
+ getword_start(&gwarea1,data);
+ if (getword(day,sizeof(day),&gwarea1,'/')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",tmp5);
exit(1);
}
if(strcmp(DateFormat,"u") == 0) {
- if (getword(day,sizeof(day),data,'/')<0) {
+ if (getword(day,sizeof(day),&gwarea1,'/')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",tmp5);
exit(1);
}
strcpy(oday,day);
count++;
}
- if (getword(bytes,sizeof(bytes),buf,'\t')<0 || getword(bytes,sizeof(bytes),buf,'\t')<0) {
+ if (getword(bytes,sizeof(bytes),&gwarea,'\t')<0 || getword(bytes,sizeof(bytes),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",tmp5);
exit(1);
}
- bytes[strlen(bytes)-1]='\0';
if(strcmp(oday,day) != 0) {
strcpy(warea,oday);
char href2[MAXLEN];
char urly[MAXLEN];
char siteind[MAXLEN];
+ struct getwordstruct gwarea;
if(strstr(ReportType,"users_sites") == 0) return;
while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
if(strstr(buf,"TOTAL") == 0) {
- if (getword(wtemp,sizeof(wtemp),buf,'\t')<0) {
+ getword_start(&gwarea,buf);
+ if (getword_skip(MAXLEN,&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arqper);
exit(1);
}
- ttnacc+=my_atoll(buf);
- if (getword(wtemp,sizeof(wtemp),buf,'\t')<0 || getword(wtemp,sizeof(wtemp),buf,'\t')<0) {
+ ttnacc+=my_atoll(gwarea.current);
+ if (getword_skip(MAXLEN,&gwarea,'\t')<0 || getword(wtemp,sizeof(wtemp),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arqper);
exit(1);
}
totbytes+=my_atoll(wtemp);
- if (getword(wtemp,sizeof(wtemp),buf,'\t')<0 || getword(wtemp,sizeof(wtemp),buf,'\t')<0 ||
- getword(wtemp,sizeof(wtemp),buf,'\t')<0 || getword(wtemp,sizeof(wtemp),buf,'\t')<0 ||
- getword(wtemp,sizeof(wtemp),buf,'\t')<0) {
+ if (getword_skip(MAXLEN,&gwarea,'\t')<0 || getword_skip(MAXLEN,&gwarea,'\t')<0 ||
+ getword_skip(MAXLEN,&gwarea,'\t')<0 || getword_skip(MAXLEN,&gwarea,'\t')<0 ||
+ getword(wtemp,sizeof(wtemp),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arqper);
exit(1);
}
}
while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
- if (getword(wtemp,sizeof(wtemp),buf,'\t')<0) {
+ getword_start(&gwarea,buf);
+ if (getword(wtemp,sizeof(wtemp),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arqin);
exit(1);
}
tnacc+=my_atoll(wtemp);
- if (getword(wtemp,sizeof(wtemp),buf,'\t')<0) {
+ if (getword(wtemp,sizeof(wtemp),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arqin);
exit(1);
}
tnbytes+=my_atoll(wtemp);
- if (getword(wtemp,sizeof(wtemp),buf,'\t')<0 || getword(wtemp,sizeof(wtemp),buf,'\t')<0 ||
- getword(wtemp,sizeof(wtemp),buf,'\t')<0) {
+ if (getword_skip(MAXLEN,&gwarea,'\t')<0 || getword_skip(MAXLEN,&gwarea,'\t')<0 ||
+ getword(wtemp,sizeof(wtemp),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arqin);
exit(1);
}
tnelap+=my_atoll(wtemp);
- if (getword(wtemp,sizeof(wtemp),buf,'\t')<0) {
+ if (getword(wtemp,sizeof(wtemp),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arqin);
exit(1);
}
tnincache+=my_atoll(wtemp);
- if (getword(wtemp,sizeof(wtemp),buf,'\t')<0) {
+ if (getword(wtemp,sizeof(wtemp),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arqin);
exit(1);
}
}
while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
- if (getword(nacc,sizeof(nacc),buf,'\t')<0) {
+ getword_start(&gwarea,buf);
+ if (getword(nacc,sizeof(nacc),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken number of access in your %s file.\n",arqin);
exit(1);
}
- if (getword(nbytes,sizeof(nbytes),buf,'\t')<0) {
+ if (getword(nbytes,sizeof(nbytes),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken number of bytes in your %s file.\n",arqin);
exit(1);
}
- if (getword(url,sizeof(url),buf,'\t')<0) {
+ if (getword(url,sizeof(url),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken url in your %s file.\n",arqin);
exit(1);
}
- if (getword(tmsg,sizeof(tmsg),buf,'\t')<0) {
+ if (getword(tmsg,sizeof(tmsg),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken status in your %s file.\n",arqin);
exit(1);
}
- if (getword(nelap,sizeof(nelap),buf,'\t')<0) {
+ if (getword(nelap,sizeof(nelap),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken elapsed time in your %s file.\n",arqin);
exit(1);
}
- if (getword(incac,sizeof(incac),buf,'\t')<0) {
+ if (getword(incac,sizeof(incac),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken in cache column in your %s file.\n",arqin);
exit(1);
}
- if (getword(oucac,sizeof(oucac),buf,'\t')<0) {
+ if (getword(oucac,sizeof(oucac),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken not in cache column in your %s file.\n",arqin);
exit(1);
}
} else {
strcpy(urly,url);
url_module(url, module);
- if (getword(warea,sizeof(warea),url,'/')<0) {
- printf("SARG: Maybe you have a broken record or garbage in the url of the %s file.\n",arqin);
- exit(1);
+ str=strchr(url,'/');
+ if (str){
+ *str='\0';
+ strcat(url,"...");
+ strcat(url,module);
}
- sprintf(url,"%s...%s",warea,module);
}
if(strcmp(Privacy,"yes") == 0)
olduserip[0]='\0';
while(fgets(buf,sizeof(buf),fp_ip)) {
- if (getword(user_ip,sizeof(user_ip),buf,'\t')<0) {
+ getword_start(&gwarea,buf);
+ if (getword(user_ip,sizeof(user_ip),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken user IP in your %s file.\n",tmp3);
exit(1);
}
- if (getword(userurl,sizeof(userurl),buf,'\t')<0) {
+ if (getword(userurl,sizeof(userurl),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken user URL in your %s file.\n",tmp3);
exit(1);
}
- if (getword(userdia,sizeof(userdia),buf,'\t')<0) {
+ if (getword(userdia,sizeof(userdia),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken day in your %s file.\n",tmp3);
exit(1);
}
- if (getword(userhora,sizeof(userhora),buf,'\t')<0) {
+ if (getword(userhora,sizeof(userhora),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken time in your %s file.\n",tmp3);
exit(1);
}
- if (getword(userbytes,sizeof(userbytes),buf,'\t')<0) {
+ if (getword(userbytes,sizeof(userbytes),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken size in your %s file.\n",tmp3);
exit(1);
}
- if (getword(userelap,sizeof(userelap),buf,'\t')<0) {
+ if (getword(userelap,sizeof(userelap),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken elapsed time in your %s file.\n",tmp3);
exit(1);
}
+
+struct getwordstruct
+{
+ const char *current;
+ const char *beginning;
+};
+
// auth.c
void htaccess(const char *name);
void useragent(void);
// util.c
-int getword(char *word, int limit, char *line, int stop);
-int getword_multisep(char *word, int limit, char *line, int stop);
-int getword_skip(int limit, char *line, int stop);
+void getword_start(struct getwordstruct *gwarea, const char *line);
+void getword_restart(struct getwordstruct *gwarea);
+int getword(char *word, int limit, struct getwordstruct *gwarea, int stop);
+int getword_multisep(char *word, int limit, struct getwordstruct *gwarea, int stop);
+int getword_skip(int limit, struct getwordstruct *gwarea, int stop);
void name_month(char *month,int month_len);
void conv_month_name(char *month);
void buildymd(const char *dia, const char *mes, const char *ano, char *wdata);
char media[20];
char ftime[128];
char day[16], mon[16], year[40], hour[10];
- char h[3], m[3], s[3];
+ char *str;
int cstatus;
+ int iyear, imonth, iday, ihour, iminute, isecond;
char y1[5], y2[5];
char d1[3], d2[3];
char m1[4], m2[4];
- int iyear, imonth, iday, ihour, iminute, isecond;
+ struct getwordstruct gwarea;
if(LastLog[0] != '\0') mklastlog(outdir);
if(!isdigit(direntp3->d_name[0]) && !isdigit(direntp3->d_name[1])) continue;
bzero(newname,512);
strcpy(warea,direntp2->d_name);
- if(strstr(warea,"-") != 0) {
- if (getword_multisep(m1,sizeof(m1),warea,'-')<0) {
- printf("SARG: Maybe you have a broken record or garbage in your %s directory.\n",val2);
- exit(1);
- }
- strcpy(m2,warea);
+ if((str = strchr(warea,'-')) != 0) {
+ *str++ = '\0';
+ strcpy(m1,warea);
+ strcpy(m2,str);
conv_month_name(m1);
conv_month_name(m2);
} else {
strcpy(m2,m1);
}
strcpy(warea,direntp3->d_name);
- if(strstr(warea,"-") != 0) {
- if (getword_multisep(d1,sizeof(d1),warea,'-')<0) {
- printf("SARG: Maybe you have a broken record or garbage in your %s directory.\n",val2);
- exit(1);
- }
+ if((str = strchr(warea,'-')) != 0) {
+ *str++ = '\0';
+ strcpy(d1,warea);
strcpy(d2,warea);
} else {
strcpy(d1,warea);
/*
Old code to parse a date stored by sarg before 2.2.6.1 in the sarg-date file of each report directory.
*/
- strcpy(html,data);
- if (getword_multisep(mon,sizeof(mon),html,' ')<0) {
+ getword_start(&gwarea,data);
+ if (getword_multisep(mon,sizeof(mon),&gwarea,' ')<0) {
printf("SARG: Maybe you have a broken week day in your %s%s/sarg-date file.\n",outdir,direntp->d_name);
exit(1);
}
- if (getword_multisep(mon,sizeof(mon),html,' ')<0) {
+ if (getword_multisep(mon,sizeof(mon),&gwarea,' ')<0) {
printf("SARG: Maybe you have a broken month in your %s%s/sarg-date file.\n",outdir,direntp->d_name);
exit(1);
}
- if (getword_multisep(day,sizeof(day),html,' ')<0) {
+ if (getword_multisep(day,sizeof(day),&gwarea,' ')<0) {
printf("SARG: Maybe you have a broken day in your %s%s/sarg-date file.\n",outdir,direntp->d_name);
exit(1);
}
- if (getword_multisep(hour,sizeof(hour),html,' ')<0) {
+ if (getword_multisep(hour,sizeof(hour),&gwarea,' ')<0) {
printf("SARG: Maybe you have a broken time in your %s%s/sarg-date file.\n",outdir,direntp->d_name);
exit(1);
}
do {
- if (getword_multisep(year,sizeof(year),html,' ')<0) {
+ if (getword_multisep(year,sizeof(year),&gwarea,' ')<0) {
printf("SARG: Maybe you have a broken year in your %s%s/sarg-date file.\n",outdir,direntp->d_name);
exit(1);
}
} while (year[0] && !isdigit(year[0])); //skip time zone information with spaces until the year is found
strcpy(html,hour);
- if (getword_multisep(h,sizeof(h),html,':')<0) {
- printf("SARG: Maybe you have a broken hour in your %s%s/sarg-date file.\n",outdir,direntp->d_name);
- exit(1);
- }
- if (getword_multisep(m,sizeof(m),html,':')<0) {
- printf("SARG: Maybe you have a broken minute in your %s%s/sarg-date file.\n",outdir,direntp->d_name);
- exit(1);
- }
- if (getword_multisep(s,sizeof(s),html,0)<0) {
- printf("SARG: Maybe you have a broken second in your %s%s/sarg-date file.\n",outdir,direntp->d_name);
+ if (sscanf(hour,"%d:%d:%d",&ihour,&iminute,&isecond)!=3) {
+ printf("SARG: Maybe you have a broken time in your %s%s/sarg-date file.\n",outdir,direntp->d_name);
exit(1);
}
buildymd(day,mon,year,ftime);
- fprintf(fp_tmp,"%s%s%s%s;%s;%s;%s;%s;%s;%s\n",ftime, h, m, s, direntp->d_name, data, tuser, tbytes, media,newname);
+ fprintf(fp_tmp,"%s%02d%02d%02d;%s;%s;%s;%s;%s;%s\n",ftime, ihour, iminute, isecond, direntp->d_name, data, tuser, tbytes, media,newname);
}
continue;
}
write_html_header(fp_ou, ".");
fprintf(fp_ou,"<tr><th %s>%s</th><th %s>%s</th></tr>\n",hbc1,text[130],hbc1,text[132]);
while(fgets(wwork1,sizeof(wwork1),fp_tmp)!=NULL) {
- if (getword(tmp4,sizeof(tmp4),wwork1,'\t')<0) {
+ getword_start(&gwarea,wwork1);
+ if (getword(tmp4,sizeof(tmp4),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wdir_tmp2);
exit(1);
}
- fprintf(fp_ou,"<tr><td class=\"data2\"><a href=\"%s\">%s</a></td><td class=\"data2\">%s</td></tr>\n",tmp4,tmp4,wwork1);
+ fprintf(fp_ou,"<tr><td class=\"data2\"><a href=\"%s\">%s</a></td><td class=\"data2\">%s</td></tr>\n",tmp4,tmp4,gwarea.current);
sprintf(tmp2,"%s%s",outdir,tmp4);
sprintf(tmp3,"%s%s/index.unsort",outdir,tmp4);
// Year dir
}
write_html_header(fp_ou2,"..");
fprintf(fp_ou2,"<tr><th %s>%s/%s</th></tr>\n",hbc1,text[130],text[131]);
- while(fgets(wwork1,MAXLEN,fp_tmp2)!=NULL) {
- wwork1[strlen(wwork1)-1]='\0';
+ while(fgets(wwork1,sizeof(wwork1),fp_tmp2)!=NULL) {
+ fixendofline(wwork1);
strcpy(tmp5,wwork1);
- if(strstr(tmp5,"-") != 0) {
- if (getword_multisep(warea,sizeof(warea),tmp5,'-')<0) {
- printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wdir_tmp3);
- exit(1);
- }
- name_month(warea,sizeof(warea));
- sprintf(tmp6,"%s-",warea);
+ if((str = strchr(tmp5,'-')) != 0) {
+ *str++ = '\0';
+ strcpy(tmp6,str);
name_month(tmp5,sizeof(tmp5));
- sprintf(nmonth,"%s%s",tmp6,tmp5);
+ name_month(tmp6,sizeof(tmp6));
+ sprintf(nmonth,"%s-%s",tmp5,tmp6);
} else {
strcpy(nmonth,tmp5);
name_month(nmonth,sizeof(nmonth));
}
write_html_header(fp_ou,".");
fprintf(fp_ou,"<tr><th %s>%s</th><th %s>%s</th><th %s>%s</th><th %s>%s</th><th %s>%s</th></tr>\n",hbc1,text[101],hbc1,text[102],hbc1,text[103],hbc1,text[93],hbc1,text[96]);
- while(fgets(buf,MAXLEN,fp_tmp2)!=NULL) {
- if (getword_multisep(period,sizeof(period),buf,';')<0) {
+ while(fgets(buf,sizeof(buf),fp_tmp2)!=NULL) {
+ getword_start(&gwarea,buf);
+ if (getword_multisep(period,sizeof(period),&gwarea,';')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wdir_tmp2);
exit(1);
}
- if (getword_multisep(period,sizeof(period),buf,';')<0) {
+ if (getword_multisep(period,sizeof(period),&gwarea,';')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wdir_tmp2);
exit(1);
}
- if (getword_multisep(data,sizeof(data),buf,';')<0) {
+ if (getword_multisep(data,sizeof(data),&gwarea,';')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wdir_tmp2);
exit(1);
}
- if (getword_multisep(tuser,sizeof(tuser),buf,';')<0) {
+ if (getword_multisep(tuser,sizeof(tuser),&gwarea,';')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wdir_tmp2);
exit(1);
}
- if (getword_multisep(tbytes,sizeof(tbytes),buf,';')<0) {
+ if (getword_multisep(tbytes,sizeof(tbytes),&gwarea,';')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wdir_tmp2);
exit(1);
}
- if (getword_multisep(media,sizeof(media),buf,';')<0) {
+ if (getword_multisep(media,sizeof(media),&gwarea,';')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wdir_tmp2);
exit(1);
}
#include "include/defs.h"
void ip2name(char *ip,int ip_len)
-{
+{
u_long addr;
struct hostent *hp;
char **p;
}
void name2ip(char *name)
-{
+{
struct in_addr ia;
struct hostent *hp;
char *port;
char n2[4];
char n3[4];
char n4[4];
+ struct getwordstruct gwarea;
port=strchr(name,':');
if (port) *port=0;
if((hp=gethostbyname(name))==NULL)
return;
-
+
memcpy(&ia.s_addr,hp->h_addr_list[0],sizeof(ia.s_addr));
ia.s_addr=ntohl(ia.s_addr);
- strcpy(name,inet_ntoa(ia));
- if (getword(n4,sizeof(n4),name,'.')<0 || getword(n3,sizeof(n3),name,'.')<0 ||
- getword(n2,sizeof(n2),name,'.')<0 || getword(n1,sizeof(n1),name,0)<0) {
- printf("SARG: Maybe you have a broken record or garbage in your %s ip address.\n",name);
+ getword_start(&gwarea,inet_ntoa(ia));
+ if (getword(n4,sizeof(n4),&gwarea,'.')<0 || getword(n3,sizeof(n3),&gwarea,'.')<0 ||
+ getword(n2,sizeof(n2),&gwarea,'.')<0 || getword(n1,sizeof(n1),&gwarea,0)<0) {
+ printf("SARG: Maybe you have a broken record or garbage in your %s ip address.\n",gwarea.beginning);
exit(1);
}
sprintf(name,"%s.%s.%s.%s",n1,n2,n3,n4);
return;
-}
+}
char lfile[FILENAME_MAX];
FILE *fp_text;
char buf[MAXLEN];
+ char *begin, *end;
int record=0;
if (snprintf(lfile,sizeof(lfile),LANGDIR"/%s",language)>=sizeof(lfile)) {
printf("Reading language from %s\n",lfile);
while(record<sizeof(text)/sizeof(text[0]) && fgets(buf,sizeof(buf),fp_text)!=NULL) {
- if (getword(warea,sizeof(warea),buf,'"')<0 || getword(warea,sizeof(warea),buf,'"')<0) {
- printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",lfile);
- exit(1);
+ if (buf[0] == '#') {
+ text[record][0] = '\0';
+ } else {
+ begin = strchr(buf,'\"');
+ if (begin == NULL) {
+ printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",lfile);
+ exit(1);
+ }
+ begin++;
+ end = strchr(begin,'\"');
+ if (end) *end = '\0';
+ strcpy(text[record],begin);
}
- strcpy(text[record],warea);
-
if(langcode)
- printf("%d %s\n",record,warea);
+ printf("%d %s\n",record,begin);
record++;
}
struct tm *local;
struct stat statb;
int cstatus;
+ struct getwordstruct gwarea;
if(strcmp(LastLog,"0") == 0)
return;
dirp = opendir(outdir);
while ((direntp = readdir( dirp )) != NULL ){
- if(strstr(direntp->d_name,"-") == 0)
+ if(strchr(direntp->d_name,'-') == 0)
continue;
sprintf(warea,"%s%s",outdir,direntp->d_name);
ftot++;
}
- (void)rewinddir( dirp );
(void)closedir( dirp );
fclose(fp_ou);
exit(1);
}
- while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
- if (getword(warea,sizeof(warea),buf,'\t')<0) {
+ while(ftot>0 && fgets(buf,sizeof(buf),fp_in)!=NULL) {
+ fixendofline(buf);
+ getword_start(&gwarea,buf);
+ if (getword(warea,sizeof(warea),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",temp);
exit(1);
}
- fixendofline(buf);
- if(ftot) {
- if(debug)
- debuga("%s: %s",text[81],buf);
-// sprintf(temp,"%s%s",outdir,buf);
- if (snprintf(temp,sizeof(temp),"rm -r \"%s%s\"",outdir,buf)>=sizeof(temp)) {
- fprintf(stderr,"SARG: Directory name too long: %s%s\n",outdir,buf);
- exit(1);
- }
- cstatus=system(temp);
- if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
- fprintf(stderr, "SARG: command return status %d\n",WEXITSTATUS(cstatus));
- fprintf(stderr, "SARG: command: %s\n",temp);
- exit(1);
- }
- unlink(temp);
- ftot--;
+ if(debug)
+ debuga("%s: %s",text[81],gwarea.current);
+ if (snprintf(temp,sizeof(temp),"rm -r \"%s%s\"",outdir,gwarea.current)>=sizeof(temp)) {
+ fprintf(stderr,"SARG: Directory name too long: %s%s\n",outdir,gwarea.current);
+ exit(1);
+ }
+ cstatus=system(temp);
+ if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
+ fprintf(stderr, "SARG: command return status %d\n",WEXITSTATUS(cstatus));
+ fprintf(stderr, "SARG: command: %s\n",temp);
+ exit(1);
}
+ unlink(temp);
+ ftot--;
}
fclose(fp_in);
extern int optopt;
extern char *optarg;
- char w[MAXLEN];
char data[255];
char elap[255];
- char none[255];
char ip[MAXLEN];
char msg[MAXLEN];
char tam[255];
char arq[255];
char arq_log[255];
char warq[255][255];
- char hm[15], hmf[15], hmr[15], whm[15];
+ char hm[15], hmf[15], hmr[15];
int chm=0;
char uagent[MAXLEN];
char hexclude[MAXLEN];
int download_flag;
char download_url[MAXLEN];
char sz_Last_User[MAXLEN]="";
+ struct getwordstruct gwarea;
BgImage[0]='\0';
LogoImage[0]='\0';
strcpy(hexclude,optarg);
break;
case 'd':
- strcpy(date,optarg);
- strcpy(cduntil,optarg);
- if (getword(cdfrom,sizeof(cdfrom),cduntil,'-')<0) {
+ strncpy(date,optarg,sizeof(date)-1);
+ date[sizeof(date)-1]='\0';
+ getword_start(&gwarea,optarg);
+ if (getword(cdfrom,sizeof(cdfrom),&gwarea,'-')<0 || getword(cduntil,sizeof(cduntil),&gwarea,0)<0) {
printf("SARG: Maybe you have a broken record or garbage in your date range.\n");
exit(1);
}
strcpy(site,optarg);
break;
case 't':
+ {
+ int h,m;
+
if(strstr(optarg,"-") == 0) {
strcpy(hm,optarg);
strcpy(hmf,optarg);
} else {
- if (getword(hm,sizeof(hm),optarg,'-')<0) {
- printf("SARG: Maybe you have a broken record or garbage in your time range.\n");
+ getword_start(&gwarea,optarg);
+ if (getword(hm,sizeof(hm),&gwarea,'-')<0 || getword(hmf,sizeof(hmf),&gwarea,0)<0) {
+ fprintf(stderr,"SARG: Maybe you have a broken record or garbage in your time range.\n");
exit(1);
}
- strcpy(hmf,optarg);
}
- if(strlen(hm) > 5) {
- printf("SARG: time period must be MM or MM:SS. Exit.\n");
+ if(sscanf(hm,"%d:%d",&h,&m)!=2) {
+ fprintf(stderr,"SARG: time period must be MM or MM:SS. Exit.\n");
exit(1);
}
- bzero(whm,15);
- if(strstr(hm,":") != 0) {
- if (getword(warea,sizeof(warea),hm,':')<0) {
- printf("SARG: Maybe you have a broken record or garbage in your time range.\n");
- exit(1);
- }
- sprintf(whm,"%s%s",warea,hm);
- strcpy(hm,whm);
- }
- bzero(whm,15);
- if(strstr(hmf,":") != 0) {
- if (getword(warea,sizeof(warea),hmf,':')<0) {
- printf("SARG: Maybe you have a broken record or garbage in your time range.\n");
- exit(1);
- }
- sprintf(whm,"%s%s",warea,hmf);
- strcpy(hmf,whm);
+ sprintf(hm,"%02d%02d",h,m);
+ if(sscanf(hmf,"%d:%d",&h,&m)!=2) {
+ fprintf(stderr,"SARG: time period must be MM or MM:SS. Exit.\n");
+ exit(1);
}
+ sprintf(hmf,"%02d%02d",h,m);
break;
+ }
case 'u':
strcpy(us,optarg);
break;
}
if(strncmp(bufz,"*** SARG Log ***",16) == 0) {
- if (getword(val2,sizeof(val2),arqtt,'-')<0 || getword(val2,sizeof(val2),arqtt,'_')<0 ||
- getword(val3,sizeof(val3),arqtt,'-')<0 || getword(val3,sizeof(val3),arqtt,'_')<0) {
+ getword_start(&gwarea,arqtt);
+ if (getword(val2,sizeof(val2),&gwarea,'-')<0 || getword(val2,sizeof(val2),&gwarea,'_')<0 ||
+ getword(val3,sizeof(val3),&gwarea,'-')<0 || getword(val3,sizeof(val3),&gwarea,'_')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
exit(1);
}
// exclude_string
exstring=0;
- if(strlen(ExcludeString) > 0) {
+ if(ExcludeString[0] != '\0') {
strcpy(warea,bufz);
- strcpy(html,ExcludeString);
- while(strstr(html,":") != 0) {
- if (getword_multisep(val1,sizeof(val1),html,':')<0) {
+ getword_start(&gwarea,ExcludeString);
+ while(strchr(gwarea.current,':') != 0) {
+ if (getword_multisep(val1,sizeof(val1),&gwarea,':')<0) {
printf("SARG: Maybe you have a broken record or garbage in your exclusion string.\n");
exit(1);
}
if((str=(char *) strstr(warea,val1)) != (char *) NULL )
exstring++;
}
- if((str=(char *) strstr(warea,html)) != (char *) NULL )
+ if((str=(char *) strstr(warea,gwarea.current)) != (char *) NULL )
exstring++;
}
if(exstring) continue;
printf("BUF=%s\n",bufz);
if (ilf==ILF_Squid || ilf==ILF_Common || ilf==ILF_Unknown) {
- if (getword(data,sizeof(data),bufz,' ')<0) {
+ getword_start(&gwarea,bufz);
+ if (getword(data,sizeof(data),&gwarea,' ')<0) {
printf("SARG: Maybe you have a broken record or garbage in your access.log file.\n");
exit(1);
}
strcpy(ip,data);
strcpy(elap,"0");
if(squid24) {
- if (getword(user,sizeof(user),bufz,' ')<0 || getword(none,sizeof(none),bufz,' ')<0) {
+ if (getword(user,sizeof(user),&gwarea,' ')<0 || getword_skip(255,&gwarea,' ')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
exit(1);
}
} else {
- if (getword(none,sizeof(none),bufz,' ')<0 || getword(user,sizeof(user),bufz,' ')<0) {
+ if (getword_skip(255,&gwarea,' ')<0 || getword(user,sizeof(user),&gwarea,' ')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
exit(1);
}
}
- if (getword(data,sizeof(data),bufz,']')<0 || getword(fun,sizeof(fun),bufz,'"')<0 ||
- getword(fun,sizeof(fun),bufz,' ')<0 || getword(url,sizeof(url),bufz,' ')<0 ||
- getword(code2,sizeof(code2),bufz,' ')<0 || getword(code2,sizeof(code2),bufz,' ')<0 ||
- getword(tam,sizeof(tam),bufz,' ')<0) {
+ if (getword(data,sizeof(data),&gwarea,']')<0 || getword_skip(MAXLEN,&gwarea,'"')<0 ||
+ getword(fun,sizeof(fun),&gwarea,' ')<0 || getword(url,sizeof(url),&gwarea,' ')<0 ||
+ getword_skip(MAXLEN,&gwarea,' ')<0 || getword(code2,sizeof(code2),&gwarea,' ')<0 ||
+ getword(tam,sizeof(tam),&gwarea,' ')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
exit(1);
}
- if((str=(char *) strchr(bufz, ' ')) != (char *) NULL ) {
- if (getword(code,sizeof(code),bufz,' ')<0) {
+ if((str=(char *) strchr(gwarea.current, ' ')) != (char *) NULL ) {
+ if (getword(code,sizeof(code),&gwarea,' ')<0) {
+ printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+ exit(1);
+ }
+ } else {
+ if (getword(code,sizeof(code),&gwarea,'\0')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
exit(1);
}
}
- else strcpy(code,bufz);
if ((str = strchr(code, ':')) != NULL)
*str = '/';
}
if(ilf==ILF_Unknown || ilf==ILF_Squid) {
- if (getword(elap,sizeof(elap),bufz,' ')<0) {
+ if (getword(elap,sizeof(elap),&gwarea,' ')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
exit(1);
}
- while(strcmp(elap,"") == 0 && strlen(bufz) > 0)
- if (getword(elap,sizeof(elap),bufz,' ')<0) {
+ while(strcmp(elap,"") == 0 && gwarea.current[0] != '\0')
+ if (getword(elap,sizeof(elap),&gwarea,' ')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
exit(1);
}
if(strlen(elap) < 1) continue;
- if (getword(ip,sizeof(ip),bufz,' ')<0){
+ if (getword(ip,sizeof(ip),&gwarea,' ')<0){
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
exit(1);
}
- if (getword(code,sizeof(code),bufz,' ')<0){
+ if (getword(code,sizeof(code),&gwarea,' ')<0){
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
exit(1);
}
- if (getword(tam,sizeof(tam),bufz,' ')<0){
+ if (getword(tam,sizeof(tam),&gwarea,' ')<0){
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
exit(1);
}
- if (getword(fun,sizeof(fun),bufz,' ')<0){
+ if (getword(fun,sizeof(fun),&gwarea,' ')<0){
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
exit(1);
}
- if (getword(url,sizeof(url),bufz,' ')<0){
+ if (getword(url,sizeof(url),&gwarea,' ')<0){
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
exit(1);
}
// getword(warea,bufz,' ');
// strcat(url,warea);
// }
- if (getword(user,sizeof(user),bufz,' ')<0){
+ if (getword(user,sizeof(user),&gwarea,' ')<0){
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
exit(1);
}
}
}
if (ilf==ILF_Sarg) {
- if (getword(data,sizeof(data),bufz,' ')<0){
+ getword_start(&gwarea,bufz);
+ if (getword(data,sizeof(data),&gwarea,' ')<0){
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
exit(1);
}
- if (getword(hora,sizeof(hora),bufz,' ')<0) {
+ if (getword(hora,sizeof(hora),&gwarea,' ')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
exit(1);
}
- if (getword(user,sizeof(user),bufz,' ')<0) {
+ if (getword(user,sizeof(user),&gwarea,' ')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
exit(1);
}
- if (getword(ip,sizeof(ip),bufz,' ')<0) {
+ if (getword(ip,sizeof(ip),&gwarea,' ')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
exit(1);
}
- if (getword(url,sizeof(url),bufz,' ')<0){
+ if (getword(url,sizeof(url),&gwarea,' ')<0){
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
exit(1);
}
- if (getword(tam,sizeof(tam),bufz,' ')<0){
+ if (getword(tam,sizeof(tam),&gwarea,' ')<0){
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
exit(1);
}
- if (getword(code,sizeof(code),bufz,' ')<0){
+ if (getword(code,sizeof(code),&gwarea,' ')<0){
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
exit(1);
}
- if (getword(elap,sizeof(elap),bufz,' ')<0){
+ if (getword(elap,sizeof(elap),&gwarea,' ')<0){
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
exit(1);
}
- if (getword(smartfilter,sizeof(smartfilter),bufz,' ')<0){
+ if (getword(smartfilter,sizeof(smartfilter),&gwarea,' ')<0){
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
exit(1);
}
int ncols,cols[ISACOL_Last];
fixendofline(bufz);
+ getword_start(&gwarea,bufz);
// remove the #Fields: column at the beginning of the line
- if (getword_skip(1000,bufz,' ')<0){
+ if (getword_skip(1000,&gwarea,' ')<0){
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
exit(1);
}
for (ncols=0 ; ncols<ISACOL_Last ; ncols++) cols[ncols]=-1;
ncols=0;
- while(bufz[0] != '\0') {
- if (getword(val1,sizeof(val1),bufz,'\t')<0){
+ while(gwarea.current[0] != '\0') {
+ if (getword(val1,sizeof(val1),&gwarea,'\t')<0){
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
exit(1);
}
continue;
}
if (!isa_ncols) continue;
+ getword_start(&gwarea,bufz);
for (x=0 ; x<isa_ncols ; x++) {
- if (getword(val1,sizeof(val1),bufz,'\t')<0) {
+ if (getword(val1,sizeof(val1),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
exit(1);
}
sprintf(val1,"DENIED/%s",code);
strcpy(code,val1);
}
- if (getword(ano,sizeof(ano),data,'-')<0){
+ getword_start(&gwarea,data);
+ if (getword(ano,sizeof(ano),&gwarea,'-')<0){
+ printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+ exit(1);
+ }
+ if (getword(mes,sizeof(mes),&gwarea,'-')<0){
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
exit(1);
}
- if (getword(mes,sizeof(mes),data,'-')<0){
+ if (getword(dia,sizeof(dia),&gwarea,'\0')<0){
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
exit(1);
}
- strcpy(dia,data);
conv_month_name(mes);
sprintf(data," %s/%s/%s:%s",dia,mes,ano,hora);
}
*str='\0';
}
- while(strstr(user,"%5c") != 0) {
- if (getword_multisep(w,sizeof(w),user,'%')<0){
- printf("SARG: Maybe you have a broken user in your %s file.\n",arq);
- exit(1);
- }
- strcpy(wuser,user+2);
- sprintf(user,"%s.%s",w,wuser);
+ /*
+ Code prior to 2.2.7 used to replace any %xx by a dot as long as a %5c was
+ found in the user name.
+ */
+ while((str = strstr(user,"%5c")) != NULL) {
+ *str='.';
+ for (x=3 ; str[x] ; x++) str[x-2]=str[x];
}
for(str=user; *str; str++) {
strlow(user);
if(strncmp(NtlmUserFormat,"user",4) == 0) {
- if(strchr(user,'_') != 0)
- if (getword_multisep(warea,sizeof(warea),user,'_')<0){
- printf("SARG: Maybe you have a broken user in your %s file.\n",arq);
- exit(1);
- }
- if(strchr(user,'+') != 0)
- if (getword_multisep(warea,sizeof(warea),user,'+')<0){
- printf("SARG: Maybe you have a broken user in your %s file.\n",arq);
- exit(1);
- }
+ if((str = strchr(user,'_')) != 0) {
+ strcpy(warea,str+1);
+ strcpy(user,warea);
+ }
+ if((str = strchr(user,'+')) != 0) {
+ strcpy(warea,str+1);
+ strcpy(user,warea);
+ }
}
if(strstr(ReportType,"denied") != 0)
download_count++;
}
- if (strchr(url,'/')) {
- // remove any protocol:// at the beginning of the URL
- if (getword(w,sizeof(w),url,'/')<0){
- printf("SARG: Maybe you have a broken url in your %s file.\n",arq);
- exit(1);
- }
- if (getword(w,sizeof(w),url,'/')<0){
- printf("SARG: Maybe you have a broken url in your %s file.\n",arq);
- exit(1);
- }
- /*
- This code rejects any host without a directory. Now it
- doesn't look necessary so it is commented out.
- if (!strchr(url,'/')) {
- if (debugm) printf("URL without directory: %s\n",url);
- totregsx++;
- continue;
- }*/
+ // remove any protocol:// at the beginning of the URL
+ if ((str = strchr(url,'/')) != NULL && str[1] == '/') {
+ int i;
+
+ str+=2;
+ for (i=0 ; str[i] ; i++)
+ url[i]=str[i];
+ url[i]='\0';
}
if(strcmp(LongUrl,"no") == 0) {
strftime(dia, sizeof(dia), "%d/%m/%Y", t);
sprintf(hora,"%02d:%02d:%02d",t->tm_hour,t->tm_min,t->tm_sec);
} else if(ilf==ILF_Common || ilf==ILF_Isa) {
- strcpy(wtemp,data+1);
- if (getword_multisep(data,sizeof(data),wtemp,':')<0){
+ getword_start(&gwarea,data+1);
+ if (getword_multisep(data,sizeof(data),&gwarea,':')<0){
printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
exit(1);
}
- if (getword_multisep(hora,sizeof(hora),wtemp,' ')<0){
+ if (getword_multisep(hora,sizeof(hora),&gwarea,' ')<0){
printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
exit(1);
}
- if (getword_multisep(dia,sizeof(dia),data,'/')<0){
+ getword_start(&gwarea,data);
+ if (getword_multisep(dia,sizeof(dia),&gwarea,'/')<0){
printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
exit(1);
}
- if (getword_multisep(mes,sizeof(mes),data,'/')<0){
+ if (getword_multisep(mes,sizeof(mes),&gwarea,'/')<0){
printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
exit(1);
}
- if (getword_multisep(ano,sizeof(ano),data,'/')<0){
+ if (getword_multisep(ano,sizeof(ano),&gwarea,'/')<0){
printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
exit(1);
}
builddia(dia,mes,ano,df,wdata);
idata=atoi(wdata);
} else if (ilf==ILF_Sarg) {
- if (getword_multisep(mes,sizeof(mes),data,'/')<0){
+ getword_start(&gwarea,data);
+ if (getword_multisep(mes,sizeof(mes),&gwarea,'/')<0){
printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
exit(1);
}
- if (getword_multisep(dia,sizeof(dia),data,'/')<0){
+ if (getword_multisep(dia,sizeof(dia),&gwarea,'/')<0){
printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
exit(1);
}
- if (getword_multisep(ano,sizeof(ano),data,0)<0){
+ if (getword_multisep(ano,sizeof(ano),&gwarea,0)<0){
printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
exit(1);
}
}
if(l){
if(hm[0] != '\0') {
- strcpy(whm,hora);
- bzero(hmr,15);
+ bzero(hmr,sizeof(hmr));
chm++;
+ getword_start(&gwarea,hora);
while(chm) {
- if (getword_multisep(warea,sizeof(warea),whm,':')<0){
+ if (getword_multisep(warea,sizeof(warea),&gwarea,':')<0){
printf("SARG: Maybe you have a broken time in your %s file.\n",arq);
exit(1);
}
strncat(hmr,warea,2);
chm--;
}
- strncat(hmr,whm,2);
+ strncat(hmr,gwarea.current,2);
if(atoi(hmr) >= atoi(hm) && atoi(hmr) <= atoi(hmf))
l=1;else l=0;
if(fp_log != NULL) {
fclose(fp_log);
- strcpy(val1,period);
- if (getword_multisep(val2,sizeof(val2),val1,'-')<0){
+ getword_start(&gwarea,period);
+ if (getword_multisep(val2,sizeof(val2),&gwarea,'-')<0){
+ printf("SARG: Maybe you have a broken date range definition.\n");
+ exit(1);
+ }
+ if (getword_multisep(val1,sizeof(val1),&gwarea,'\0')<0){
printf("SARG: Maybe you have a broken date range definition.\n");
exit(1);
}
- if (getword_multisep(val3,sizeof(val3),per_hour,'-')<0){
+ getword_start(&gwarea,per_hour);
+ if (getword_multisep(val3,sizeof(val3),&gwarea,'-')<0){
printf("SARG: Maybe you have a broken date range definition.\n");
exit(1);
}
- sprintf(val4,"%s/sarg-%s_%s-%s_%s.log",ParsedOutputLog,val2,val3,val1,per_hour);
+ sprintf(val4,"%s/sarg-%s_%s-%s_%s.log",ParsedOutputLog,val2,val3,val1,gwarea.current);
rename(arq_log,val4);
strcpy(arq_log,val4);
time_t tt;
struct tm *t;
char tbuf[128];
+ char warea[MAXLEN];
+ struct getwordstruct gwarea;
- if (getword(dat,sizeof(dat),rec,' ')<0) {
+ getword_start(&gwarea,rec);
+ if (getword(dat,sizeof(dat),&gwarea,' ')<0) {
fprintf(stderr,"SARG: The time stamp at column 1 is too long.\n");
return(-1);
}
- if (getword(warea,sizeof(warea),rec,' ')<0) {
+ if (getword(warea,sizeof(warea),&gwarea,' ')<0) {
fprintf(stderr,"SARG: The connection duration at column 2 is too long.\n");
return(-1);
}
- while(strcmp(warea,"") == 0 && strlen(rec) > 0)
- if (getword(warea,sizeof(warea),rec,' ')<0) {
+ while(strcmp(warea,"") == 0 && gwarea.current[0] != '\0')
+ if (getword(warea,sizeof(warea),&gwarea,' ')<0) {
return(-1);
}
- if (getword(ip,sizeof(ip),rec,' ')<0) {
+ if (getword(ip,sizeof(ip),&gwarea,' ')<0) {
fprintf(stderr,"SARG: The IP address at column 3 is too long.\n");
return(-1);
}
- if (getword(warea,sizeof(warea),rec,' ')<0) {
+ if (getword_skip(MAXLEN,&gwarea,' ')<0) {
fprintf(stderr,"SARG: The status at column 4 is too long.\n");
return(-1);
}
- if (getword(warea,sizeof(warea),rec,' ')<0) {
+ if (getword_skip(MAXLEN,&gwarea,' ')<0) {
fprintf(stderr,"SARG: The size at column 5 is too long.\n");
return(-1);
}
- if (getword(typ,sizeof(typ),rec,' ')<0) {
+ if (getword(typ,sizeof(typ),&gwarea,' ')<0) {
fprintf(stderr,"SARG: The action at column 6 is too long.\n");
return(-1);
}
if(strncmp(typ,"CONNECT",7) == 0) {
- if (getword(url,sizeof(url),rec,' ')<0) {
+ if (getword(url,sizeof(url),&gwarea,' ')<0) {
return(-1);
}
- if (getword(user,sizeof(user),rec,' ')<0) {
+ if (getword(user,sizeof(user),&gwarea,' ')<0) {
return(-1);
}
}else {
- if (getword(url,sizeof(url),rec,'/')<0) {
+ if (getword_skip(MAXLEN,&gwarea,'/')<0) {
fprintf(stderr,"SARG: The URL at column 7 is too long.\n");
return(-1);
}
- if (getword(url,sizeof(url),rec,'/')<0) {
+ if (getword_skip(MAXLEN,&gwarea,'/')<0) {
fprintf(stderr,"SARG: The URL at column 7 is too long.\n");
return(-1);
}
- if (getword(url,sizeof(url),rec,'/')<0) {
+ if (getword(url,sizeof(url),&gwarea,'/')<0) {
fprintf(stderr,"SARG: The URL at column 7 is too long.\n");
return(-1);
}
- if (getword(user,sizeof(user),rec,' ')<0) {
+ if (getword_skip(MAXLEN,&gwarea,' ')<0) {
fprintf(stderr,"SARG: The data at column 8 is too long.\n");
return(-1);
}
- if (getword(user,sizeof(user),rec,' ')<0) {
+ if (getword(user,sizeof(user),&gwarea,' ')<0) {
fprintf(stderr,"SARG: The user at column 9 is too long.\n");
return(-1);
}
{
FILE *fin;
char buf[MAXLEN];
+ struct getwordstruct gwarea;
if((fin=fopen(tmp,"r"))==NULL) {
fprintf(stderr, "SARG: (realtime) open error %s - %s\n",tmp,strerror(errno));
while(fgets(buf, sizeof(buf), fin)) {
fixendofline(buf);
- if (getword(dat,sizeof(dat),buf,'\t')<0) {
+ getword_start(&gwarea,buf);
+ if (getword(dat,sizeof(dat),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",tmp);
exit(1);
}
- if (getword(tim,sizeof(tim),buf,'\t')<0) {
+ if (getword(tim,sizeof(tim),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",tmp);
exit(1);
}
- if (getword(ip,sizeof(ip),buf,'\t')<0) {
+ if (getword(ip,sizeof(ip),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",tmp);
exit(1);
}
- if (getword(user,sizeof(user),buf,'\t')<0) {
+ if (getword(user,sizeof(user),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",tmp);
exit(1);
}
if(strlen(dat) < 3 || strlen(user) < 1) continue;
- if (getword(url,sizeof(url),buf,'\t')<0) {
+ if (getword(url,sizeof(url),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",tmp);
exit(1);
}
- if (getword(typ,sizeof(typ),buf,'\t')<0) {
+ if (getword(typ,sizeof(typ),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",tmp);
exit(1);
}
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L };
long long int tt=0, ttt=0;
int i;
+ struct getwordstruct gwarea;
sprintf(arqout,"%s/%s/d%s.html",dirname,user,user);
sprintf(wdirname,"%s/%s.day",tmp,user);
"<td class=\"header3\">%s<br>%s</td></tr>\n", text[107], html );
while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
- if (getword(data,sizeof(data),buf,'\t')<0) {
+ fixendofline(buf);
+ getword_start(&gwarea,buf);
+ if (getword(data,sizeof(data),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wdirname);
exit(1);
}
count++;
}
- if (getword(hour,sizeof(hour),buf,'\t')<0 || getword(elap,sizeof(elap),buf,'\t')<0) {
+ if (getword(hour,sizeof(hour),&gwarea,'\t')<0 || getword(elap,sizeof(elap),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wdirname);
exit(1);
}
- elap[strlen(elap)-1]='\0';
if(strcmp(data,odata) != 0) {
strcpy(oelap,elap);
char olduser[MAXLEN], oldmsg[50], acccode[MAXLEN/2 - 1], oldaccelap[10], oldacccode[MAXLEN/2 - 1], user[MAXLEN];
char ipantes[MAXLEN], nameantes[MAXLEN];
char accsmart[MAXLEN];
- char wcrc[MAXLEN/2 -1];
char crc2[MAXLEN/2 -1];
long long int nbytes=0;
long long int nelap=0;
long long int rtotal=0;
long long int incache=0;
long long int oucache=0;
- char *s;
+ char *str;
DIR *dirp;
struct dirent *direntp;
const char logext[]=".log";
int dlen;
char siteind[MAXLEN];
+ struct getwordstruct gwarea;
ipantes[0]='\0';
nameantes[0]='\0';
bzero(html_old, MAXLEN);
while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
- if (getword(accdia,sizeof(accdia),buf,'\t')<0 || getword(acchora,sizeof(acchora),buf,'\t')<0 ||
- getword(accuser,sizeof(accuser),buf,'\t')<0 || getword(accip,sizeof(accip),buf,'\t')<0 ||
- getword(accurl,sizeof(accurl),buf,'\t')<0 || getword(accbytes,sizeof(accbytes),buf,'\t')<0 ||
- getword(acccode,sizeof(acccode),buf,'\t')<0) {
+ getword_start(&gwarea,buf);
+ if (getword(accdia,sizeof(accdia),&gwarea,'\t')<0 || getword(acchora,sizeof(acchora),&gwarea,'\t')<0 ||
+ getword(accuser,sizeof(accuser),&gwarea,'\t')<0 || getword(accip,sizeof(accip),&gwarea,'\t')<0 ||
+ getword(accurl,sizeof(accurl),&gwarea,'\t')<0 || getword(accbytes,sizeof(accbytes),&gwarea,'\t')<0 ||
+ getword(acccode,sizeof(acccode),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",tmp3);
exit(1);
}
if(strncmp(acccode,"TCP_DENIED/407",14) == 0) continue;
- if (getword(accelap,sizeof(accelap),buf,'\t')<0 || getword(accsmart,sizeof(accsmart),buf,'\t')<0 ||
- getword(accsmart,sizeof(accsmart),buf,'"')<0) {
+ if (getword(accelap,sizeof(accelap),&gwarea,'\t')<0 || getword_skip(20000,&gwarea,'\t')<0 ||
+ getword(accsmart,sizeof(accsmart),&gwarea,'"')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",tmp3);
exit(1);
}
*/
sprintf(ltext110,"%s",text[110]);
- for(s=ltext110; *s; ++s)
- *s=tolower(*s);
+ for(str=ltext110; *str; ++str)
+ *str=tolower(*str);
fprintf(fp_tt, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<html>\n<head>\n <meta http-equiv=\"Content-Type\" content=\"text/html; charset=%s\">\n",CharSet);
css(fp_tt);
strcpy(html_old, html);
} else bzero(ltext110, 50);
- strcpy(wcrc,acccode);
- if (getword(crc2,sizeof(crc2),wcrc,'/')<0) {
- printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",tmp3);
- exit(1);
- }
+ strcpy(crc2,acccode);
+ str=strchr(crc2,'/');
+ if (str) *str='\0';
if(strstr(crc2,"MISS") != 0)
oucache+=my_atoll(accbytes);
char *users;
long long int llbytes=0;
int cstatus;
+ struct getwordstruct gwarea;
if(strcmp(Privacy,"yes") == 0)
return;
strcpy(users," ");
while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
- if (getword(user,sizeof(user),buf,'\t')<0) {
+ getword_start(&gwarea,buf);
+ if (getword(user,sizeof(user),&gwarea,'\t')<0) {
printf("SARG: Maybe you have an invalid user in the %s file of the siteuser.\n",general2);
exit(1);
}
ip2name(user,sizeof(user));
*/
- if (getword(nacc,sizeof(nacc),buf,'\t')<0){
+ if (getword(nacc,sizeof(nacc),&gwarea,'\t')<0){
printf("SARG: Maybe you have an invalid number of access in your %s file of the siteuser.\n",general2);
exit(1);
}
if (atoi(nacc) > 0) nsitesusers = 1;
- if (getword(nbytes,sizeof(nbytes),buf,'\t')<0){
+ if (getword(nbytes,sizeof(nbytes),&gwarea,'\t')<0){
printf("SARG: Maybe you have an invalid number of bytes in your %s file of the siteuser.\n",general2);
exit(1);
}
- if (getword(url,sizeof(url),buf,'\t')<0) {
+ if (getword(url,sizeof(url),&gwarea,'\t')<0) {
printf("SARG: Maybe you have an invalid url in your %s file of the siteuser.\n",general2);
exit(1);
}
char *str;
int fuser=0;
int cstatus;
+ struct getwordstruct gwarea;
ouser[0]='\0';
fprintf(fp_ou,"<tr><th bgcolor=%s><font size=\"%s\">%s</font></th><th bgcolor=\"%s\"><font size=\"%s\">%s</font></th><th bgcolor=\"%s\"><font size=\"%s\">%s</font></th><th bgcolor=\"%s\"><font size=\"%s\">%s</font></th><th bgcolor=\"%s\"><font size=\"%s\">%s</font></th></tr>\n",HeaderBgColor,FontSize,text[98],HeaderBgColor,FontSize,text[111],HeaderBgColor,FontSize,text[110],HeaderBgColor,FontSize,text[91],HeaderBgColor,FontSize,smartheader);
while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
- if (getword(user,sizeof(user),buf,'\t')<0 || getword(data,sizeof(data),buf,'\t')<0 ||
- getword(hora,sizeof(hora),buf,'\t')<0 || getword(ip,sizeof(ip),buf,'\t')<0 ||
- getword(url,sizeof(url),buf,'\t')<0 || getword(smartcat,sizeof(smartcat),buf,'\n')<0) {
+ getword_start(&gwarea,buf);
+ if (getword(user,sizeof(user),&gwarea,'\t')<0 || getword(data,sizeof(data),&gwarea,'\t')<0 ||
+ getword(hora,sizeof(hora),&gwarea,'\t')<0 || getword(ip,sizeof(ip),&gwarea,'\t')<0 ||
+ getword(url,sizeof(url),&gwarea,'\t')<0 || getword(smartcat,sizeof(smartcat),&gwarea,'\n')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",smart_ou);
exit(1);
}
time_t tt;
int idata=0;
struct tm *t;
+ struct getwordstruct gwarea;
if(arq[0] == '\0')
arq="/var/log/squid/access.log";
}
while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
- if (getword(data,sizeof(data),buf,' ')<0) {
+ getword_start(&gwarea,buf);
+ if (getword(data,sizeof(data),&gwarea,' ')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
exit(1);
}
}
if(strcmp(convert,"onvert") != 0) {
- printf("%s %s",data,buf);
+ printf("%s %s",data,gwarea.current);
continue;
}
else
strftime(dia, sizeof(dia), "%m/%d/%Y", t);
- printf("%s %02d:%02d:%02d %s",dia,t->tm_hour,t->tm_min,t->tm_sec,buf);
+ printf("%s %02d:%02d:%02d %s",dia,t->tm_hour,t->tm_min,t->tm_sec,gwarea.current);
}
fclose(fp_in);
static void read_log(const char *wentp, FILE *fp_ou)
{
FILE *fp_in = NULL;
- char bufbsf[255];
char leks[5], sep[2], res[MAXLEN];
char mon[10], hour[15];
char list[MAXLEN];
int idata=0;
int i;
char *str;
+ struct getwordstruct gwarea;
+ struct getwordstruct gwarea1;
if(debug) {
- strcpy(buf,text[7]);
- if (getword(urly,sizeof(urly),buf,' ')<0 || getword(href,sizeof(href),buf,' ')<0) {
+ getword_start(&gwarea,text[7]);
+ if (getword(urly,sizeof(urly),&gwarea,' ')<0 || getword(href,sizeof(href),&gwarea,' ')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s string.\n",text[7]);
exit(1);
}
- debuga("%s squidGuard %s: %s",urly,buf,wentp);
+ debuga("%s squidGuard %s: %s",urly,gwarea.current,wentp);
}
/* With squidGuard, you can log groups in only one log file.
}
while (fgets(buf,sizeof(buf),fp_in) != NULL) {
- if(strlen(SquidGuardLogFormat) > 0) {
- strcpy(bufbsf,SquidGuardLogFormat);
+ getword_start(&gwarea,buf);
+ if(SquidGuardLogFormat[0] != '\0') {
+ getword_start(&gwarea1,SquidGuardLogFormat);
leks[0]='\0';
- if (getword(leks,sizeof(leks),bufbsf,'#')<0) {
+ if (getword(leks,sizeof(leks),&gwarea1,'#')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wentp);
exit(1);
}
while(strcmp(leks,"end") != 0) {
- if (getword(leks,sizeof(leks),bufbsf,'#')<0 || getword(sep,sizeof(sep),bufbsf,'#')<0) {
+ if (getword(leks,sizeof(leks),&gwarea1,'#')<0 || getword(sep,sizeof(sep),&gwarea1,'#')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wentp);
exit(1);
}
if(strcmp(leks,"end") != 0) {
- if (getword(res,sizeof(res),buf,sep[0])<0) {
+ if (getword(res,sizeof(res),&gwarea,sep[0])<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wentp);
exit(1);
}
}
}
} else {
- if (getword(year,sizeof(year),buf,'-')<0 || getword(mon,sizeof(mon),buf,'-')<0 ||
- getword(day,sizeof(day),buf,' ')<0 || getword(hour,sizeof(hour),buf,' ')<0 ||
- getword(list,sizeof(list),buf,'/')<0 || getword(list,sizeof(list),buf,'/')<0 ||
- getword(tmp5,sizeof(tmp5),buf,'/')<0 || getword(tmp5,sizeof(tmp5),buf,'/')<0 ||
- getword(url,sizeof(url),buf,' ')<0 ||
- getword(ip,sizeof(ip),buf,'/')<0 || getword(user,sizeof(user),buf,' ')<0 ||
- getword(user,sizeof(user),buf,' ')<0) {
+ if (getword(year,sizeof(year),&gwarea,'-')<0 || getword(mon,sizeof(mon),&gwarea,'-')<0 ||
+ getword(day,sizeof(day),&gwarea,' ')<0 || getword(hour,sizeof(hour),&gwarea,' ')<0 ||
+ getword_skip(MAXLEN,&gwarea,'/')<0 || getword(list,sizeof(list),&gwarea,'/')<0 ||
+ getword_skip(MAXLEN,&gwarea,'/')<0 || getword_skip(MAXLEN,&gwarea,'/')<0 ||
+ getword(url,sizeof(url),&gwarea,' ')<0 ||
+ getword(ip,sizeof(ip),&gwarea,'/')<0 || getword_skip(MAXLEN,&gwarea,' ')<0 ||
+ getword(user,sizeof(user),&gwarea,' ')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wentp);
exit(1);
}
if(strlen(SquidGuardConf) < 1 && strlen(SquidGuardLogAlternate) < 1)
return;
- if (strlen(SquidGuardLogAlternate) > 0)
+ if (SquidGuardLogAlternate[0] != '\0')
SquidGuardConf[0]='\0';
sprintf(guard_in,"%s/squidguard.unsort",tmp);
logdir[0]=0;
while(fgets(buf,sizeof(buf),fp_guard)!=NULL) {
- if(strstr(buf,"\n") != 0)
- buf[strlen(buf)-1]='\0';
+ fixendofline(buf);
if((str=get_param_value("logdir",buf))!=NULL) {
- if (getword(logdir,sizeof(logdir),str,' ')<0) {
- printf("SARG: Maybe you have an invalid logdir line in your %s file.\n",SquidGuardConf);
- exit(1);
+ /*
+ We want to tolerate spaces inside the directory name but we must also
+ remove the trailing spaces left by the editor after the directory name.
+ This should not be a problem as nobody use a file name with trailing spaces.
+ */
+ for (y=strlen(str)-1 ; y>=0 && (unsigned char)str[y]<=' ' ; y--);
+ if (y>=sizeof(logdir)-1) y=sizeof(logdir)-2;
+ logdir[y+1] = '\0';
+ while (y>=0) {
+ logdir[y] = str[y];
+ y--;
}
} else if((str=get_param_value("log",buf))!=NULL) {
if((str2=get_param_value("anonymous",str))!=NULL)
char *str;
int z=0;
int count=0;
+ struct getwordstruct gwarea;
ouser[0]='\0';
fprintf(fp_ou,"<tr><th class=\"header\">%s</th><th class=\"header\">%s</th><th class=\"header\">%s</th><th class=\"header\">%s</th><th class=\"header\">%s</th></tr>\n",text[98],text[111],text[110],text[91],text[121]);
while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
- if (getword(user,sizeof(user),buf,'\t')<0 || getword(data2,sizeof(data2),buf,'\t')<0 ||
- getword(hora,sizeof(hora),buf,'\t')<0 || getword(ip,sizeof(ip),buf,'\t')<0 ||
- getword(url,sizeof(url),buf,'\t')<0 || getword(rule,sizeof(rule),buf,'\n')<0) {
+ getword_start(&gwarea,buf);
+ if (getword(user,sizeof(user),&gwarea,'\t')<0 || getword(data2,sizeof(data2),&gwarea,'\t')<0 ||
+ getword(hora,sizeof(hora),&gwarea,'\t')<0 || getword(ip,sizeof(ip),&gwarea,'\t')<0 ||
+ getword(url,sizeof(url),&gwarea,'\t')<0 || getword(rule,sizeof(rule),&gwarea,'\n')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",squidguard_in);
exit(1);
}
long long int twork1=0, twork2=0, twork3=0;
int regs=0;
int cstatus;
+ struct getwordstruct gwarea;
if(strcmp(Privacy,"yes") == 0)
return;
}
while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
- if (getword(url,sizeof(url),buf,'\t')<0) {
+ getword_start(&gwarea,buf);
+ if (getword(url,sizeof(url),&gwarea,'\t')<0) {
printf("SARG: Maybe you have an invalid user in your %s file of the topsites.\n",general2);
exit(1);
}
if(strcmp(url,"TOTAL") == 0) {
- if (getword(ttnacc,sizeof(ttnacc),buf,'\t')<0) {
+ if (getword(ttnacc,sizeof(ttnacc),&gwarea,'\t')<0) {
printf("SARG: Maybe you have an invalid total number of access in your %s file of the topsites.\n",general2);
exit(1);
}
- if (getword(ttnbytes,sizeof(ttnbytes),buf,'\t')<0) {
+ if (getword(ttnbytes,sizeof(ttnbytes),&gwarea,'\t')<0) {
printf("SARG: Maybe you have an invalid total number of bytes in your %s file of the topsites.\n",general2);
exit(1);
}
- if (getword(ttntime,sizeof(ttntime),buf,'\t')<0) {
+ if (getword(ttntime,sizeof(ttntime),&gwarea,'\t')<0) {
printf("SARG: Maybe you have an invalid total time in your %s file of the topsites.\n",general2);
exit(1);
}
continue;
}
- if (getword(nacc,sizeof(nacc),buf,'\t')<0) {
+ if (getword(nacc,sizeof(nacc),&gwarea,'\t')<0) {
printf("SARG: Maybe you have an invalid number of access in your %s file of the topsites.\n",general2);
exit(1);
}
- if (getword(nbytes,sizeof(nbytes),buf,'\t')<0) {
+ if (getword(nbytes,sizeof(nbytes),&gwarea,'\t')<0) {
printf("SARG: Maybe you have an invalid number of bytes in your %s file of the topsites.\n",general2);
exit(1);
}
- if (getword(url,sizeof(url),buf,'\t')<0) {
+ if (getword(url,sizeof(url),&gwarea,'\t')<0) {
printf("SARG: Maybe you have an invalid url in your %s file of the topsites.\n",general2);
exit(1);
}
- if (getword(ntemp,sizeof(ntemp),buf,'\t')<0) {
+ if (getword(ntemp,sizeof(ntemp),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken record or garbage in column 5 in your %s file of the topsites.\n",general2);
exit(1);
}
- if (getword(ntemp,sizeof(ntemp),buf,'\t')<0) {
+ if (getword(ntemp,sizeof(ntemp),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken record or garbage in column 6 in your %s file of the topsites.\n",general2);
exit(1);
}
- if (getword(ntemp,sizeof(ntemp),buf,'\t')<0) {
+ if (getword(ntemp,sizeof(ntemp),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken record or garbage in column 7 in your %s file of the topsites.\n",general2);
exit(1);
}
- if (getword(ntime,sizeof(ntime),buf,'\t')<0) {
+ if (getword(ntime,sizeof(ntime),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken record or garbage in column 8 in your %s file of the topsites.\n",general2);
exit(1);
}
while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
if(regs>atoi(TopSitesNum))
break;
- if (getword(nacc,sizeof(nacc),buf,'\t')<0) {
+ getword_start(&gwarea,buf);
+ if (getword(nacc,sizeof(nacc),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",sites);
exit(1);
}
if (atoi(nacc) == 0) continue;
- if (getword(nbytes,sizeof(nbytes),buf,'\t')<0 ||
- getword(ntime,sizeof(ntime),buf,'\t')<0 || getword(url,sizeof(url),buf,'\t')<0) {
+ if (getword(nbytes,sizeof(nbytes),&gwarea,'\t')<0 ||
+ getword(ntime,sizeof(ntime),&gwarea,'\t')<0 || getword(url,sizeof(url),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",sites);
exit(1);
}
strcpy(wwork2,fixnum(twork2,1));
strcpy(wwork3,fixtime(twork3));
- if(strlen(BlockIt) > 0)
+ if(BlockIt[0] != '\0')
sprintf(BlockImage,"<a href=\"%s%s?url=%s\"><img src=\"../images/sarg-squidguard-block.png\" border=\"0\"></a> ",wwwDocumentRoot,BlockIt,url);
else BlockImage[0]='\0';
char href1end[5];
char href2end[5];
char href3end[5];
+ struct getwordstruct gwarea;
ipantes[0]='\0';
nameantes[0]='\0';
totuser=0;
while(fgets(warea,sizeof(warea),fp_in)) {
- if (getword(user,sizeof(user),warea,'\t')<0) {
+ getword_start(&gwarea,warea);
+ if (getword(user,sizeof(user),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken user in your %s file.\n",wger);
exit(1);
}
if(strcmp(user,"TOTAL") == 0) {
continue;
}
- if (getword(nacc,sizeof(nacc),warea,'\t')<0) {
+ if (getword(nacc,sizeof(nacc),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken number of access in your %s file.\n",wger);
exit(1);
}
- if (getword(nbytes,sizeof(nbytes),warea,'\t')<0) {
+ if (getword(nbytes,sizeof(nbytes),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken number of bytes in your %s file.\n",wger);
exit(1);
}
- if (getword(url,sizeof(url),warea,'\t')<0) {
+ if (getword(url,sizeof(url),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken url in your %s file.\n",wger);
exit(1);
}
- if (getword(ip,sizeof(ip),warea,'\t')<0) {
+ if (getword(ip,sizeof(ip),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken user's IP in your %s file.\n",wger);
exit(1);
}
- if (getword(time,sizeof(time),warea,'\t')<0) {
+ if (getword(time,sizeof(time),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken time in your %s file.\n",wger);
exit(1);
}
- if (getword(date,sizeof(date),warea,'\t')<0) {
+ if (getword(date,sizeof(date),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken date in your %s file.\n",wger);
exit(1);
}
- if (getword(elap,sizeof(elap),warea,'\t')<0) {
+ if (getword(elap,sizeof(elap),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken download duration in your %s file.\n",wger);
exit(1);
}
- if (getword(incac,sizeof(incac),warea,'\t')<0) {
+ if (getword(incac,sizeof(incac),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken in cache download in your %s file.\n",wger);
exit(1);
}
- if (getword(oucac,sizeof(oucac),warea,'\t')<0) {
+ if (getword(oucac,sizeof(oucac),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken not in cache download in your %s file.\n",wger);
exit(1);
}
ntopuser = 0;
while(fgets(warea,sizeof(warea),fp_top1)) {
- if (getword(user,sizeof(user),warea,'\t')<0) {
+ getword_start(&gwarea,warea);
+ if (getword(user,sizeof(user),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken user in your %s file.\n",top1);
exit(1);
}
- if (getword(nbytes,sizeof(nbytes),warea,'\t')<0) {
+ if (getword(nbytes,sizeof(nbytes),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken number of bytes in your %s file.\n",top1);
exit(1);
}
- if (getword(nacc,sizeof(nacc),warea,'\t')<0) {
+ if (getword(nacc,sizeof(nacc),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken number of access in your %s file.\n",top1);
exit(1);
}
- if (getword(elap,sizeof(elap),warea,'\t')<0) {
+ if (getword(elap,sizeof(elap),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken elpased time in your %s file.\n",wger);
exit(1);
}
- if (getword(incac,sizeof(incac),warea,'\t')<0) {
+ if (getword(incac,sizeof(incac),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken in-cache size in your %s file.\n",wger);
exit(1);
}
- if (getword(oucac,sizeof(oucac),warea,'\t')<0) {
+ if (getword(oucac,sizeof(oucac),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken out-of-cache size in your %s file.\n",wger);
exit(1);
}
long long int telap=0;
long long int tused=0;
int cstatus;
+ struct getwordstruct gwarea;
if(indexonly) return;
if(strstr(ReportType,"users_sites") == 0) return;
}
while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
- if(strstr(buf,"\n") != 0)
- buf[strlen(buf)-1]='\0';
-
- if (getword(data,sizeof(data),buf,'\t')<0 || getword(hora,sizeof(hora),buf,':')<0 ||
- getword(min,sizeof(min),buf,':')<0 || getword(elap,sizeof(elap),buf,'\t')<0 ||
- getword(elap,sizeof(elap),buf,0)<0) {
+ fixendofline(buf);
+ getword_start(&gwarea,buf);
+ if (getword(data,sizeof(data),&gwarea,'\t')<0 || getword(hora,sizeof(hora),&gwarea,':')<0 ||
+ getword(min,sizeof(min),&gwarea,':')<0 || getword(elap,sizeof(elap),&gwarea,'\t')<0 ||
+ getword(elap,sizeof(elap),&gwarea,0)<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",sortout);
exit(1);
}
char ip[MAXLEN], hora[9], data[15], elap[16];
char incac[30], oucac[30];
char warea[MAXLEN];
+ struct getwordstruct gwarea;
strcpy(wger,dirname);
strcat(wger,"/sarg-general");
while(fgets(warea,sizeof(warea),fp_in))
{
//printf("%s\n",warea);
- if (getword(user,sizeof(user),warea,'\t')<0) {
+ getword_start(&gwarea,warea);
+ if (getword(user,sizeof(user),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken user in your %s file.\n",wger);
exit(1);
}
- if (getword(nacc,sizeof(nacc),warea,'\t')<0) {
+ if (getword(nacc,sizeof(nacc),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken number of access in your %s file.\n",wger);
exit(1);
}
- if (getword(nbytes,sizeof(nbytes),warea,'\t')<0) {
+ if (getword(nbytes,sizeof(nbytes),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken number of bytes in your %s file.\n",wger);
exit(1);
}
- if (getword(url,sizeof(url),warea,'\t')<0) {
+ if (getword(url,sizeof(url),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken url in your %s file.\n",wger);
exit(1);
}
- if (getword(ip,sizeof(ip),warea,'\t')<0) {
+ if (getword(ip,sizeof(ip),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken source IP address in your %s file.\n",wger);
exit(1);
}
- if (getword(hora,sizeof(hora),warea,'\t')<0) {
+ if (getword(hora,sizeof(hora),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken time in your %s file.\n",wger);
exit(1);
}
- if (getword(data,sizeof(data),warea,'\t')<0) {
+ if (getword(data,sizeof(data),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken date in your %s file.\n",wger);
exit(1);
}
- if (getword(elap,sizeof(elap),warea,'\t')<0) {
+ if (getword(elap,sizeof(elap),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken elapsed time in your %s file.\n",wger);
exit(1);
}
- if (getword(incac,sizeof(incac),warea,'\t')<0) {
+ if (getword(incac,sizeof(incac),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken in cache column in your %s file.\n",wger);
exit(1);
}
- if (getword(oucac,sizeof(oucac),warea,0)<0) {
+ if (getword(oucac,sizeof(oucac),&gwarea,0)<0) {
printf("SARG: Maybe you have a broken not in cache column in your %s file.\n",wger);
exit(1);
}
unsigned long totregsl=0;
int cstatus;
char ftime[128];
+ struct getwordstruct gwarea;
ip[0]='\0';
data[0]='\0';
while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
totregsl++;
- if (getword(ip,sizeof(ip),buf,' ')<0 || getword(data,sizeof(data),buf,'[')<0 ||
- getword(data,sizeof(data),buf,' ')<0) {
+ getword_start(&gwarea,buf);
+ if (getword(ip,sizeof(ip),&gwarea,' ')<0 || getword_skip(MAXLEN,&gwarea,'[')<0 ||
+ getword(data,sizeof(data),&gwarea,' ')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",UserAgentLog);
exit(1);
}
if(totregsl == 1)
strcpy(idate,data);
- if (getword(agent,sizeof(agent),buf,'"')<0 || getword(agent,sizeof(agent),buf,'"')<0) {
+ if (getword_skip(MAXLEN,&gwarea,'"')<0 || getword(agent,sizeof(agent),&gwarea,'"')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",UserAgentLog);
exit(1);
}
if(strstr(warea,"SCRIPT") != 0 || strstr(warea,"ONLOAD") != 0)
baddata();
- if(strlen(buf)) {
- if (getword(user,sizeof(user),buf,' ')<0 || getword(user,sizeof(user),buf,'\n')<0) {
+ if(strlen(gwarea.current)) {
+ if (getword_skip(MAXLEN,&gwarea,' ')<0 || getword(user,sizeof(user),&gwarea,'\n')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",UserAgentLog);
exit(1);
}
fprintf(fp_ou,"<tr><th align=\"left\" bgcolor=\"%s\"><font color=\"%s\">%s</font></th><th bgcolor=\"%s\" align=\"left\"><font color=\"%s\">%s</font></th></tr>\n",HeaderBgColor,HeaderColor,text[98],HeaderBgColor,HeaderColor,text[106]);
while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
- if (getword(ip,sizeof(ip),buf,'\t')<0) {
+ getword_start(&gwarea,buf);
+ if (getword(ip,sizeof(ip),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",tmp2);
exit(1);
}
} else strcpy(ip,namebefore);
}
- if (getword(agent,sizeof(agent),buf,'\t')<0 ||
- getword(user,sizeof(user),buf,'\t')<0) {
+ if (getword(agent,sizeof(agent),&gwarea,'\t')<0 ||
+ getword(user,sizeof(user),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",tmp2);
exit(1);
}
cont=0;
while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
- if (getword(ip,sizeof(ip),buf,'\t')<0 ||
- getword(agent,sizeof(agent),buf,'\t')<0) {
+ getword_start(&gwarea,buf);
+ if (getword(ip,sizeof(ip),&gwarea,'\t')<0 ||
+ getword(agent,sizeof(agent),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",tmp);
exit(1);
}
perc=0.;
while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
fixendofline(buf);
- if (getword(tagent,sizeof(tagent),buf,' ')<0) {
+ getword_start(&gwarea,buf);
+ if (getword(tagent,sizeof(tagent),&gwarea,' ')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",tmp);
exit(1);
}
perc=perc / agentot2;
}
- fprintf(fp_ht,"<tr><td align=\"left\" bgcolor=\"%s\">%s</td><td align=\"right\" bgcolor=\"%s\">%d</td><td align=\"right\" bgcolor=\"%s\">%3.2f</td></tr>\n",TxBgColor,buf,TxBgColor,nagent,TxBgColor,perc);
+ fprintf(fp_ht,"<tr><td align=\"left\" bgcolor=\"%s\">%s</td><td align=\"right\" bgcolor=\"%s\">%d</td><td align=\"right\" bgcolor=\"%s\">%3.2f</td></tr>\n",TxBgColor,gwarea.current,TxBgColor,nagent,TxBgColor,perc);
}
fputs("</table></html>\n",fp_ht);
}
}*/
-int getword(char *word, int limit, char *line, int stop)
+void getword_start(struct getwordstruct *gwarea, const char *line)
{
- int x = 0,y;
+ gwarea->beginning=line;
+ gwarea->current=line;
+}
- /*if(strlen(line) < 3) {
- word[0]='\0';
- return(0);
- }*/
+void getword_restart(struct getwordstruct *gwarea)
+{
+ gwarea->current=gwarea->beginning;
+}
+
+int getword(char *word, int limit, struct getwordstruct *gwarea, int stop)
+{
+ int x;
- for(x=0;((line[x]) && (line[x] != stop ));x++) {
+ for(x=0;((gwarea->current[x]) && (gwarea->current[x] != stop ));x++) {
if(x>=limit) {
printf("SARG: getword loop detected after %d bytes.\n",x);
- printf("SARG: Record=\"%s\"\n",line);
+ printf("SARG: Line=\"%s\"\n",gwarea->beginning);
+ printf("SARG: Record=\"%s\"\n",gwarea->current);
printf("SARG: searching for \'x%x\'\n",stop);
//printf("SARG: Maybe you have a broken record or garbage in your access.log file.\n");
word[(limit>0) ? limit-1 : 0]='\0';
return(-1);
}
- word[x] = line[x];
+ word[x] = gwarea->current[x];
}
word[x] = '\0';
- if (line[x]) ++x;
- y=0;
-
- while((line[y++] = line[x++]));
+ if (gwarea->current[x]) ++x;
+ gwarea->current+=x;
return(0);
}
-int getword_multisep(char *word, int limit, char *line, int stop)
+int getword_multisep(char *word, int limit, struct getwordstruct *gwarea, int stop)
{
- int x = 0,y;
+ int x;
- for(x=0;((line[x]) && (line[x] != stop ));x++) {
+ for(x=0;((gwarea->current[x]) && (gwarea->current[x] != stop ));x++) {
if(x>=limit) {
printf("SARG: getword_multisep loop detected.\n");
- printf("SARG: Record=\"%s\"\n",line);
- printf("SARG: searching for \'x%x\'\n",stop);
+ printf("SARG: Line=\"%s\"\n",gwarea->beginning);
+ printf("SARG: Record=\"%s\"\n",gwarea->current);
printf("SARG: searching for \'x%x\'\n",stop);
//printf("SARG: Maybe you have a broken record or garbage in your access.log file.\n");
if (limit>0) word[limit-1]='\0';
//exit(1);
return(-1);
}
- word[x] = line[x];
+ word[x] = gwarea->current[x];
}
word[x] = '\0';
- while (line[x] && line[x]==stop) ++x;
- y=0;
-
- while((line[y++] = line[x++]));
+ while (gwarea->current[x] && gwarea->current[x]==stop) ++x;
+ gwarea->current+=x;
return(0);
}
-int getword_skip(int limit, char *line, int stop)
+int getword_skip(int limit, struct getwordstruct *gwarea, int stop)
{
- int x,y;
+ int x;
- for(x=0;((line[x]) && (line[x] != stop ));x++) {
+ for(x=0;(gwarea->current[x] && (gwarea->current[x] != stop ));x++) {
if(x>=limit) {
printf("SARG: getword_skip loop detected after %d bytes.\n",x);
- printf("SARG: Record=\"%s\"\n",line);
+ printf("SARG: Line=\"%s\"\n",gwarea->beginning);
+ printf("SARG: Record=\"%s\"\n",gwarea->current);
printf("SARG: searching for \'x%x\'\n",stop);
//printf("SARG: Maybe you have a broken record or garbage in your access.log file.\n");
return(-1);
}
}
- if (line[x]) ++x;
- y=0;
-
- while((line[y++] = line[x++]));
+ if (gwarea->current[x]) ++x;
+ gwarea->current+=x;
return(0);
}
char w0[255];
char w1[255];
char w2[255];
+ struct getwordstruct gwarea;
if(!is_absolute(name)) {
fprintf(stderr,"SARG: Invalid path (%s). Please, use absolute paths only.\n",name);
strcpy(w0,name);
strcpy(w2,"/");
- if (getword_multisep(w1,sizeof(w1),w0,'/')<0) {
+ getword_start(&gwarea,w0);
+ if (getword_multisep(w1,sizeof(w1),&gwarea,'/')<0) {
printf("SARG: Maybe you have a broken record or garbage in the directory name %s.\n",name);
exit(1);
}
- while(strchr(w0,'/')) {
- if (getword_multisep(w1,sizeof(w1),w0,'/')<0) {
+ while(strchr(gwarea.current,'/')) {
+ if (getword_multisep(w1,sizeof(w1),&gwarea,'/')<0) {
printf("SARG: Maybe you have a broken record or garbage in the directory name %s.\n",name);
exit(1);
}
}
strcat(w2,"/");
}
- strcat(w2,w0);
+ strcat(w2,gwarea.current);
if(access(w2, R_OK) != 0) {
if(mkdir(w2,0755)) {
fprintf(stderr,"SARG: mkdir %s %s\n",w2,strerror(errno));
int x, z=atoi(month)-1;
char m[255];
char w[20];
+ struct getwordstruct gwarea;
strcpy(m,text[133]);
+ getword_start(&gwarea,m);
for(x=0; x<z; x++)
- if (getword_multisep(w,sizeof(w),m,',')<0) {
+ if (getword_multisep(w,sizeof(w),&gwarea,',')<0) {
printf("SARG: Maybe you have a broken record or garbage in the names of the months.\n");
exit(1);
}
- if (getword_multisep(month,month_len,m,',')<0) {
+ if (getword_multisep(month,month_len,&gwarea,',')<0) {
printf("SARG: Maybe you have a broken record or garbage in the name of the months.\n");
exit(1);
}
{
FILE *fp_in;
+ char buf[MAXLEN];
char wdir[MAXLEN];
long long int med=0;
long long int wtuser=0;
long long int twork;
+ struct getwordstruct gwarea;
sprintf(wdir,"%s%s/sarg-general",dirname,name);
if ((fp_in = fopen(wdir, "r")) == 0) {
}
while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
- if (getword(warea,sizeof(warea),buf,'\t')<0) {
+ getword_start(&gwarea,buf);
+ if (getword(warea,sizeof(warea),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wdir);
exit(1);
}
if(strcmp(warea,"TOTAL") != 0)
continue;
- if (getword(warea,sizeof(warea),buf,'\t')<0) {
+ if (getword_skip(MAXLEN,&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wdir);
exit(1);
}
- if (getword(warea,sizeof(warea),buf,'\t')<0) {
+ if (getword(warea,sizeof(warea),&gwarea,'\t')<0) {
printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wdir);
exit(1);
}
void strip_latin(char *line)
{
- char buf[255];
- char warea[255];
-
- while(strstr(line,"&") != 0){
- if (getword_multisep(warea,sizeof(warea),line,'&')<0) {
- printf("SARG: Maybe you have a broken record or garbage in a line to strip from HTML entities.\n");
- exit(1);
- }
- strncat(warea,line,1);
- if (getword_multisep(buf,sizeof(buf),line,';')<0) {
- printf("SARG: Maybe you have a broken record or garbage in a line to strip from HTML entities.\n");
- exit(1);
+ int i,j;
+ int skip;
+
+ j=0;
+ skip=0;
+ for (i=0;line[i];i++){
+ if (skip){
+ if (line[i]==';') skip=0;
+ } else {
+ if (line[i]=='&')
+ skip=1;
+ else
+ line[j++]=line[i];
}
- strcat(warea,line);
- strcpy(line,warea);
}
-
+ line[j]='\0';
return;
}
void date_from(char *date, char *dfrom, char *duntil)
{
- char diaf[10];
- char mesf[10];
- char anof[10];
- char diau[10];
- char mesu[10];
- char anou[10];
- static char wdate[50];
+ int diaf;
+ int mesf;
+ int anof;
+ int diau;
+ int mesu;
+ int anou;
+ char wdate[50];
- strcpy(wdate,date);
+ strncpy(wdate,date,sizeof(wdate)-1);
+ wdate[sizeof(wdate)-1]='\0';
if(strchr(wdate,'-') == NULL) {
+ if (strlen(wdate)*2+1>=sizeof(wdate)) {
+ fprintf(stderr,"SARG: Invalid date range passed as argument.\n");
+ exit(1);
+ }
strcat(wdate,"-");
strcat(wdate,date);
strcpy(date,wdate);
}
- if (getword(diaf,sizeof(diaf),wdate,'/')<0 || getword(mesf,sizeof(mesf),wdate,'/')<0 || getword(anof,sizeof(anof),wdate,'-')<0 ||
- getword(diau,sizeof(diau),wdate,'/')<0 || getword(mesu,sizeof(mesu),wdate,'/')<0 || getword(anou,sizeof(anou),wdate,0)<0) {
- printf("SARG: Maybe you have a broken record or garbage in a date.\n");
+ if (sscanf(wdate,"%d/%d/%d-%d/%d/%d",&diaf,&mesf,&anof,&diau,&mesu,&anou)!=6) {
+ fprintf(stderr,"SARG: The date range passed as argument is not formated as dd/mm/yyyy-dd/mm/yyyy.\n");
exit(1);
}
- sprintf(dfrom,"%s%s%s",anof,mesf,diaf);
- sprintf(duntil,"%s%s%s",anou,mesu,diau);
+ sprintf(dfrom,"%04d%02d%02d",anof,mesf,diaf);
+ sprintf(duntil,"%04d%02d%02d",anou,mesu,diau);
return;
}
char *get_size(const char *path, const char *file)
{
FILE *fp;
- char response[255];
+ static char response[255];
char cmd[255];
+ char *ptr;
if (snprintf(cmd,sizeof(cmd),"du -skh %s%s",path,file)>=sizeof(cmd)) {
printf("SARG: Cannot get disk space because the path %s%s is too long.\n",path,file);
fprintf(stderr,"SARG: Cannot get disk size with command %s",cmd);
exit(1);
}
- if (getword_multisep(val5,sizeof(val5),response,'\t')<0) {
- printf("SARG: Maybe the command %s failed.\n",cmd);
+ ptr=strchr(response,'\t');
+ if (ptr==NULL) {
+ fprintf(stderr,"SARG: The command %s failed.\n",cmd);
exit(1);
}
pclose(fp);
+ *ptr='\0';
- return (val5);
+ return (response);
}
void show_info(FILE *fp_ou)
FILE *fp_usr;
long int nreg;
char buf[MAXLEN];
- char bufy[MAXLEN];
int z2;
int z1;
- int i;
- if (UserTabFile[0] != '\0') {
- if(debug) {
- debuga("%s: %s",text[86],UserTabFile);
- }
- if((fp_usr=fopen(UserTabFile,"r"))==NULL) {
- fprintf(stderr, "SARG: (log) %s: %s - %s\n",text[45],UserTabFile,strerror(errno));
- exit(1);
- }
- fseek(fp_usr, 0, SEEK_END);
- nreg = ftell(fp_usr);
- if (nreg<0) {
- printf("SARG: Cannot get the size of file %s",UserTabFile);
- exit(1);
- }
- nreg += 100;
- fseek(fp_usr, 0, SEEK_SET);
- if((userfile=(char *) malloc(nreg))==NULL){
- fprintf(stderr, "SARG ERROR: %s",text[87]);
- exit(1);
- }
- strcpy(userfile,"\t");
- z2=1;
- while(fgets(buf,sizeof(buf),fp_usr)!=NULL) {
- if (buf[0]=='#') continue;
- for (i=strlen(buf)-1 ; i>=0 && (unsigned char)buf[i]<=' ' ; i--) buf[i]=0;
- if (getword_multisep(bufy,sizeof(bufy),buf,' ')<0) {
- printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",UserTabFile);
+ if (UserTabFile[0] == '\0') return;
+ if(debug)
+ debuga("%s: %s",text[86],UserTabFile);
+ if((fp_usr=fopen(UserTabFile,"r"))==NULL) {
+ fprintf(stderr, "SARG: (log) %s: %s - %s\n",text[45],UserTabFile,strerror(errno));
+ exit(1);
+ }
+ fseek(fp_usr, 0, SEEK_END);
+ nreg = ftell(fp_usr);
+ if (nreg<0) {
+ fprintf(stderr,"SARG: Cannot get the size of file %s",UserTabFile);
+ exit(1);
+ }
+ nreg += 100;
+ fseek(fp_usr, 0, SEEK_SET);
+ if((userfile=(char *) malloc(nreg))==NULL){
+ fprintf(stderr, "SARG ERROR: %s",text[87]);
+ exit(1);
+ }
+ userfile[0]='\t';
+ z2=1;
+ while(fgets(buf,sizeof(buf),fp_usr)!=NULL) {
+ if (buf[0]=='#') continue;
+ fixendofline(buf);
+ z1=0;
+ while(buf[z1] && (unsigned char)buf[z1]>' ') {
+ if (z2+3>=nreg) { //need at least 3 additional bytes for the minimum string "\n\t\0"
+ fprintf(stderr,"SARG: The list of the users is too long in your %s file.\n",UserTabFile);
exit(1);
}
- if (z2+strlen(bufy)+strlen(buf)+3>=nreg) {
- printf("SARG: The list of the users is too long in your %s file.\n",UserTabFile);
+ userfile[z2++]=buf[z1++];
+ }
+ while(buf[z1] && (unsigned char)buf[z1]<=' ') z1++;
+ userfile[z2++]='\n';
+ while(buf[z1] && (unsigned char)buf[z1]>' ') {
+ if (z2+2>=nreg) { //need at least 2 additional bytes for "\t\0"
+ fprintf(stderr,"SARG: The list of the users is too long in your %s file.\n",UserTabFile);
exit(1);
}
- for(z1=0; bufy[z1]; z1++)
- userfile[z2++]=bufy[z1];
- userfile[z2++]='\n';
- for(z1=0; buf[z1]; z1++)
- userfile[z2++]=buf[z1];
- userfile[z2++]='\t';
+ userfile[z2++]=buf[z1++];
}
- userfile[z2]=0;
- fclose(fp_usr);
+ userfile[z2++]='\t';
}
+ userfile[z2]='\0';
+ fclose(fp_usr);
}
void get_usertab_name(const char *user,char *name,int namelen)