From: Frédéric Marchal Date: Thu, 24 Sep 2009 09:29:14 +0000 (+0000) Subject: Z files are uncompressed by zcat to avoid deleting the original log file. X-Git-Tag: v2_2_6~17 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b008f87f1f77e1e394e26d8c37f1beb5ae85797f;p=thirdparty%2Fsarg.git Z files are uncompressed by zcat to avoid deleting the original log file. Compressed log files are uncompressed in /tmp/sarg to delete the file when the process completes. --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 5b2b3e3..84e4980 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ PROJECT(sarg C) SET(sarg_VERSION 2) SET(sarg_REVISION 2) SET(sarg_BUILD "6rc1") -SET(sarg_BUILDDATE "Sep-23-2009") +SET(sarg_BUILDDATE "Sep-24-2009") INCLUDE(AddFileDependencies) INCLUDE(CheckIncludeFile) diff --git a/ChangeLog b/ChangeLog index fa2164f..cba6bf6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,6 @@ SARG ChangeLog -Sep-23-2009 Version 2.2.6rc1 +Sep-24-2009 Version 2.2.6rc1 - Protection against buffer overflows in getword and friends and report the origin of the error instead of always blaming access.log. - Patch #2224623 applied. - Updated to autoconf 2.61. @@ -66,6 +66,8 @@ Sep-23-2009 Version 2.2.6rc1 - Allow the use of spaces in the temporary directory. - Fixed bug #2863485. - Removed missplaced off_t as suggested in bug #2864425. + - Z files are uncompressed by zcat to avoid deleting the original log file. + - Compressed log files are uncompressed in /tmp/sarg to delete the file when the process completes. Mar-03-2008 Version 2.2.5 - new fix to the script insertion vulnerability via user-agent diff --git a/README_cmake b/README_cmake index c0e26ca..1096597 100644 --- a/README_cmake +++ b/README_cmake @@ -17,9 +17,14 @@ CONFIGURING SARG It is recommended to build sarg out of the source directory. It makes it easier to delete the build directory completely and restart the configuration from -scratch if the first attempt doesn't produce the expected result. To do so, -create a directory at the same level as the sources of sarg and cd into that -directory. +scratch if the first attempt doesn't produce the expected result. + +If you intent to use both cmake and the autotools, then you MUST build sarg out +of the source directory as it will overwrite the original stub config.h in the +source directory and you won't be able to use the autotools afterward. + +To build sarg out of source, create a directory at the same level as the sources +of sarg and cd into that directory. Configure sarg with the command diff --git a/decomp.c b/decomp.c index 573dd25..3583e1c 100644 --- a/decomp.c +++ b/decomp.c @@ -30,15 +30,20 @@ void decomp(char *arq, char *zip, const char *tmp) { char cmd[1024]; int cstatus; + int arqlen; if(access(arq, R_OK) != 0) { debuga("%s: %s",text[64],arq); exit(1); } - if(strstr(arq,".gz") !=0) { - debuga("%s: %s > %s/sarg-file.in (zcat)",text[62],arq,tmp); - sprintf(cmd,"zcat '%s' > '%s/sarg-file.in'",arq,tmp); + arqlen=strlen(arq); + if(arqlen>3 && strcmp(arq+arqlen-3,".gz") == 0) { + debuga("%s: %s > %s/sarg/sarg-file.in (zcat)",text[62],arq,tmp); + if (snprintf(cmd,sizeof(cmd),"zcat '%s' > '%s/sarg/sarg-file.in'",arq,tmp)>=sizeof(cmd)) { + fprintf(stderr,"SARG: decompression command too long for log file %s\n",arq); + exit(1); + } cstatus=system(cmd); if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) { fprintf(stderr, "SARG: command return status %d\n",WEXITSTATUS(cstatus)); @@ -46,13 +51,16 @@ void decomp(char *arq, char *zip, const char *tmp) exit(1); } strcpy(zip,"zcat"); - sprintf(arq,"%s/sarg-file.in",tmp); + sprintf(arq,"%s/sarg/sarg-file.in",tmp); return; } - if(strstr(arq,".bz2") != 0) { - debuga("%s: %s > %s/sarg-file.in (bzcat)",text[62],arq,tmp); - sprintf(cmd,"bzcat '%s' > '%s/sarg-file.in'",arq,tmp); + if(arqlen>4 && strcmp(arq+arqlen-4,".bz2") == 0) { + debuga("%s: %s > %s/sarg/sarg-file.in (bzcat)",text[62],arq,tmp); + if (snprintf(cmd,sizeof(cmd),"bzcat '%s' > '%s/sarg/sarg-file.in'",arq,tmp)>=sizeof(cmd)) { + fprintf(stderr,"SARG: decompression command too long for log file %s\n",arq); + exit(1); + } cstatus=system(cmd); if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) { fprintf(stderr, "SARG: command return status %d\n",WEXITSTATUS(cstatus)); @@ -60,21 +68,24 @@ void decomp(char *arq, char *zip, const char *tmp) exit(1); } strcpy(zip,"zcat"); - sprintf(arq,"%s/sarg-file.in",tmp); + sprintf(arq,"%s/sarg/sarg-file.in",tmp); return; } - if(strstr(arq,".Z")) { + if(arqlen>2 && strcmp(arq+arqlen-2,".Z") == 0) { debuga("%s: %s (uncompress)",text[62],arq); - sprintf(cmd,"uncompress '%s'",arq); + if (snprintf(cmd,sizeof(cmd),"zcat '%s' > '%s/sarg/sarg-file.in'",arq,tmp)>=sizeof(cmd)) { + fprintf(stderr,"SARG: decompression command too long for log file %s\n",arq); + exit(1); + } cstatus=system(cmd); if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) { fprintf(stderr, "SARG: command return status %d\n",WEXITSTATUS(cstatus)); fprintf(stderr, "SARG: command: %s\n",cmd); exit(1); } - arq[strlen(arq)-2]='\0'; - strcpy(zip,"compress"); + strcpy(zip,"zcat"); + sprintf(arq,"%s/sarg/sarg-file.in",tmp); } return; @@ -98,7 +109,10 @@ void recomp(const char *arq, const char *zip) debuga("%s: %s",text[63],arq); - sprintf(cmd,"%s '%s'",zip,arq); + if (snprintf(cmd,sizeof(cmd),"%s '%s'",zip,arq)>=sizeof(cmd)) { + fprintf(stderr,"SARG: compression command too long for log file %s\n",arq); + exit(1); + } cstatus=system(cmd); if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) { fprintf(stderr, "SARG: command return status %d\n",WEXITSTATUS(cstatus)); diff --git a/documentation/decomp.txt b/documentation/decomp.txt new file mode 100644 index 0000000..9a74d38 --- /dev/null +++ b/documentation/decomp.txt @@ -0,0 +1,31 @@ +/*!\file decomp.c +\brief Handle compressed log files. +*/ + +/*! \fn void decomp(char *arq, char *zip, const char *tmp) +Uncompress a compressed log file or does nothing if the file does not end with a known extension. + +Log files compressed with gzip, bzip2 or compress are uncompressed to the file sarg-file.in in the temporary directory and sarg-file.in is deleted with the whole temporary directory when sarg terminates. + +If the log file does not exist, the process terminates with an error message. + +\param arq The log file to process. Upon return it contains the name of the file to read. +\param zip A string to copy the compression program to use to recompress the file. It will determine if and how to recompress the log file. +\param tmp The temporary directory where to create the uncompressed log file if the compression program support it. The suffix "/sarg" is added to the temporary directory to use the same directory layout as the rest of the program. + +\date 2009-09-24 - F Marchal\n +This function used to uncompress .Z files in place using uncompress but that required a write access to the log directory, could conflict with logrotate and could leave the log file uncompressed if sarg crashed. According to the documentation, zcat is capable of uncompressing .Z files so it is now used. +*/ + + + + +/*! \fn void recomp(const char *arq, const char *zip) +Compress the log file uncompressed by decomp(). + +\param arq The log file to compress. +\param zip The program to compress the log file. Only gzip and compress actually compress the log file. Any other string has no effect. + +\date 2009-09-24 - F Marchal\n +This function is not necessary any more because decomp() does not uncompress the log files in place. +*/ diff --git a/include/info.h b/include/info.h index 03b16a6..a6ec0a4 100755 --- a/include/info.h +++ b/include/info.h @@ -1,3 +1,3 @@ -#define VERSION PACKAGE_VERSION" Sep-23-2009" +#define VERSION PACKAGE_VERSION" Sep-24-2009" #define PGM PACKAGE_NAME #define URL "http://sarg.sourceforge.net"