]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Z files are uncompressed by zcat to avoid deleting the original log file.
authorFrédéric Marchal <fmarchal@users.sourceforge.net>
Thu, 24 Sep 2009 09:29:14 +0000 (09:29 +0000)
committerFrédéric Marchal <fmarchal@users.sourceforge.net>
Thu, 24 Sep 2009 09:29:14 +0000 (09:29 +0000)
Compressed log files are uncompressed in /tmp/sarg to delete the file when the process completes.

CMakeLists.txt
ChangeLog
README_cmake
decomp.c
documentation/decomp.txt [new file with mode: 0644]
include/info.h

index 5b2b3e376114f8851b2aaf8ec7eea004bb4394d5..84e4980db84c0c1935f48923d055cba7a26151e8 100755 (executable)
@@ -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)
index fa2164fa29fc960ae7e13611573272aa4f89287e..cba6bf65488c848a355dbab2517f671dd5ff2072 100644 (file)
--- 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
index c0e26ca5717c800c9ab8aac16b470e09f7a6a1b5..1096597a1266b735f4b0ef956a619cfaeee31ad2 100644 (file)
@@ -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
 
index 573dd251f8ba2fd2da38bff04c26ec7197a52d77..3583e1c610326bda1d551564675ecf692fb359a9 100644 (file)
--- 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 (file)
index 0000000..9a74d38
--- /dev/null
@@ -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.
+*/
index 03b16a62ff47498e13923b3b28c6134e1f58d07a..a6ec0a4124cec5b3a1807519768b3783ffe400c4 100755 (executable)
@@ -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"