]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
External sort command delimits the columns only on a tabulation
authorFrédéric Marchal <fmarchal@users.sourceforge.net>
Sat, 18 Jun 2011 10:32:16 +0000 (10:32 +0000)
committerFrédéric Marchal <fmarchal@users.sourceforge.net>
Sat, 18 Jun 2011 10:32:16 +0000 (10:32 +0000)
The default sort command splits the columns on a blank to non blank
transition but our files only use a tabulation as the column separator.

Therefore, the calls to the external sort command explicitly require
that the columns be identified by a tabulation. It prevents problems
when the fields contain spaces.

13 files changed:
authfail.c
dansguardian_log.c
email.c
html.c
lastlog.c
log.c
realtime.c
siteuser.c
smartfilter.c
sort.c
squidguard_log.c
topsites.c
topuser.c

index 79ddc74d3ca20883774c72e73809b4a1804df15b..f33b76e999599b13712d816a4b7316a00c120e3e 100644 (file)
@@ -70,7 +70,7 @@ void authfail_report(void)
        snprintf(authfail_in,sizeof(authfail_in),"%s/authfail.log",tmp);
        snprintf(report,sizeof(report),"%s/authfail.html",outdirname);
 
-       snprintf(csort,sizeof(csort),"sort -b -T \"%s\" -k 3,3 -k 5,5 -o \"%s\" \"%s\"", tmp, authfail_in, tmp4);
+       snprintf(csort,sizeof(csort),"sort -b -t \"\t\" -T \"%s\" -k 3,3 -k 5,5 -o \"%s\" \"%s\"", tmp, authfail_in, tmp4);
        cstatus=system(csort);
        if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
                debuga(_("sort command return status %d\n"),WEXITSTATUS(cstatus));
index 081b40bd5677ce4f891c127541e16257843fafb0..d1858a01c1896621fdabc2e607e75c616c4a36fa 100644 (file)
@@ -132,7 +132,7 @@ void dansguardian_log(void)
        if(debug)
                debuga(_("Sorting file: %s\n"),guard_ou);
 
-       snprintf(tmp6,sizeof(tmp6),"sort -k 1,1 -k 2,2 -k 4,4 \"%s\" -o \"%s\"",guard_in, guard_ou);
+       snprintf(tmp6,sizeof(tmp6),"sort -t \"\t\" -k 1,1 -k 2,2 -k 4,4 \"%s\" -o \"%s\"",guard_in, guard_ou);
        cstatus=system(tmp6);
        if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
                debuga(_("sort command return status %d\n"),WEXITSTATUS(cstatus));
diff --git a/email.c b/email.c
index a6ce824ad819f1f31d7603860a9c2bfd1aff4145..c600f735dc8becee26210f684e6d5c3ed0a7186e 100644 (file)
--- a/email.c
+++ b/email.c
@@ -130,7 +130,7 @@ int geramail(const char *dirname, int debug, const char *outdir, const char *ema
        }
 #endif
 
-       sprintf(csort,"sort -n -T \"%s\" -r -k 2,2 -o \"%s\" \"%s\"", TempDir, top1, top2);
+       sprintf(csort,"sort -n -T \"%s\" -t \"\t\" -r -k 2,2 -o \"%s\" \"%s\"", TempDir, top1, top2);
        cstatus=system(csort);
        if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
                debuga(_("sort command return status %d\n"),WEXITSTATUS(cstatus));
diff --git a/html.c b/html.c
index 5d62d766fc88531894d4170d16b53823fde3c0d3..2c3a496310dd436c089526ab11b55c16c3651bf5 100644 (file)
--- a/html.c
+++ b/html.c
@@ -400,7 +400,7 @@ void htmlrel(void)
                                fclose(fp_ip);
                                fclose(fp_ip2);
 
-                               sprintf(csort,"sort -n -T \"%s\" -k 1,1 -k 2,2 -o \"%s\" \"%s\"",tmp,tmp3,tmp2);
+                               sprintf(csort,"sort -n -t \"\t\" -T \"%s\" -k 1,1 -k 2,2 -o \"%s\" \"%s\"",tmp,tmp3,tmp2);
                                cstatus=system(csort);
                                if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
                                        debuga(_("sort command return status %d\n"),WEXITSTATUS(cstatus));
index c4ded49c28dcc3aacedd1e9995ba178d067604e3..f033147737f6cc846929d5c9be8309427b5e5750 100644 (file)
--- a/lastlog.c
+++ b/lastlog.c
@@ -75,7 +75,7 @@ void mklastlog(const char *outdir)
        closedir( dirp );
        fclose(fp_ou);
 
-       snprintf(buf,sizeof(buf),"sort -n -k 1,1 -o \"%slastlog\" \"%s\"",outdir,temp);
+       snprintf(buf,sizeof(buf),"sort -n -t \"\t\" -k 1,1 -o \"%slastlog\" \"%s\"",outdir,temp);
        cstatus=system(buf);
        if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
                debuga(_("sort command return status %d\n"),WEXITSTATUS(cstatus));
diff --git a/log.c b/log.c
index 4e5d7a1d8e91082c6f14e0a2f6efdf0c7b7ce919..6dfdd0ffc96fc53ff0242b2fd12ee4d9e3955c5e 100644 (file)
--- a/log.c
+++ b/log.c
@@ -1661,7 +1661,7 @@ int main(int argc,char *argv[])
        }
 
        if(DataFile[0] == '\0' && (ReportType & REPORT_TYPE_DENIED) != 0) {
-               sprintf(csort,"sort -T \"%s\" -k 3,3 -k 5,5 -o \"%s\" \"%s\"",tmp,denied_sort,denied_unsort);
+               sprintf(csort,"sort -T \"%s\" -t \"\t\" -k 3,3 -k 5,5 -o \"%s\" \"%s\"",tmp,denied_sort,denied_unsort);
                cstatus=system(csort);
                if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
                        debuga(_("sort command return status %d\n"),WEXITSTATUS(cstatus));
index b357740268b9abfdb1b534ee98395de3996b41ba..907c99bf5738fa551d41dece5f9104075993f3ed 100755 (executable)
@@ -79,7 +79,7 @@ static void getlog(void)
        fclose(tmp);
        longline_destroy(&line);
 
-       sprintf(cmd,"sort -r -k 1,1 -k 2,2 -o \"%s\" \"%s\"",template2,template1);
+       sprintf(cmd,"sort -t \"\t\" -r -k 1,1 -k 2,2 -o \"%s\" \"%s\"",template2,template1);
        cstatus=system(cmd);
        if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
                debuga(_("sort command return status %d\n"),WEXITSTATUS(cstatus));
index 92630f1a2d54b4442f58b0bd062496d3bd7ca20b..d5d62164aee51efc9b260b6178a6e24f5d0cc90c 100644 (file)
@@ -59,7 +59,7 @@ void siteuser(void)
        sprintf(general2,"%s/sarg-general2",outdirname);
        sprintf(report,"%s/siteuser.html",outdirname);
 
-       sprintf(csort,"sort -k 4,4 -k 1,1 -o \"%s\" \"%s\"",general2,general);
+       sprintf(csort,"sort -t \"\t\" -k 4,4 -k 1,1 -o \"%s\" \"%s\"",general2,general);
        cstatus=system(csort);
        if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
                debuga(_("sort command return status %d\n"),WEXITSTATUS(cstatus));
index 3830a089723b6b6a875b2179ed49f94b138545af..32661dae29b3afec4bbc867d50cbd6f78843ad46 100644 (file)
@@ -62,7 +62,7 @@ void smartfilter_report(void)
        sprintf(smart_ou,"%s/smartfilter.log",outdirname);
        sprintf(report,"%s/smartfilter.html",outdirname);
 
-       if (snprintf(csort,sizeof(csort),"sort -n -k 1,1 -k 2,2 -k 3,3 -o \"%s\" \"%s\"",smart_ou,smart_in)>=sizeof(csort)) {
+       if (snprintf(csort,sizeof(csort),"sort -n -t \"\t\" -k 1,1 -k 2,2 -k 3,3 -o \"%s\" \"%s\"",smart_ou,smart_in)>=sizeof(csort)) {
                debuga(_("cannot build the sort command to sort file %s\n"),smart_in);
                exit(EXIT_FAILURE);
        }
diff --git a/sort.c b/sort.c
index 1247c6729e6cca0c20abf0fb22ba35f280644b21..b3989af426302d41ee04a23587c6b75f4b0c2d29 100644 (file)
--- a/sort.c
+++ b/sort.c
@@ -79,7 +79,7 @@ void tmpsort(void)
                        debuga(_("Sorting file: %s\n"),arqou);
                }
 
-               sprintf(csort,"sort -n -T \"%s\" %s -k %s -k %s -k %s -o \"%s\" \"%s\"",tmp,order,field1,field2,field3,arqou,arqin);
+               sprintf(csort,"sort -n -T \"%s\" -t \"\t\" %s -k %s -k %s -k %s -o \"%s\" \"%s\"",tmp,order,field1,field2,field3,arqou,arqin);
                cstatus=system(csort);
                if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
                        debuga(_("sort command return status %d\n"),WEXITSTATUS(cstatus));
@@ -133,10 +133,10 @@ void sort_users_log(const char *tmp, int debug)
                }
 
                if(strcmp(direntp->d_name,"download.unsort") == 0)
-                       clen=snprintf(csort,sizeof(csort),"sort -T \"%s\" -k 3,3 -k 1,1 -k 2,2 -k 5,5 -o \"%s/%s.log\" \"%s/%s.unsort\"",
+                       clen=snprintf(csort,sizeof(csort),"sort -T \"%s\" -t \"\t\" -k 3,3 -k 1,1 -k 2,2 -k 5,5 -o \"%s/%s.log\" \"%s/%s.unsort\"",
                            tmp, tmp, user, tmp, user);
                else
-                       clen=snprintf(csort,sizeof(csort),"sort -T \"%s\" -k 4,4 -k 1,1 -k 2,2 -o \"%s/%s.log\" \"%s/%s.unsort\"",
+                       clen=snprintf(csort,sizeof(csort),"sort -T \"%s\" -t \"\t\" -k 4,4 -k 1,1 -k 2,2 -o \"%s/%s.log\" \"%s/%s.unsort\"",
                            tmp, tmp, user, tmp, user);
                if (clen>=sizeof(csort)) {
                        debuga(_("user name too long to sort %s\n"),csort);
index 325a3ffd3ba241898b27f1e4df6d29a9acc115c0..2d01a66739fdb22ca9dfa0f814cf6f4138359226 100644 (file)
@@ -379,7 +379,7 @@ void squidguard_log(void)
                debuga(_("Sorting file: %s\n"),guard_ou);
        }
 
-       sprintf(tmp6,"sort -k 1,1 -k 2,2 -k 4,4 \"%s\" -o \"%s\"",guard_in, guard_ou);
+       sprintf(tmp6,"sort -t \"\t\" -k 1,1 -k 2,2 -k 4,4 \"%s\" -o \"%s\"",guard_in, guard_ou);
        cstatus=system(tmp6);
        if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
                debuga(_("sort command return status %d\n"),WEXITSTATUS(cstatus));
index 4ff65d6e3bf7de1b0e923c52c0b362ac68c8bf6b..dd14f6a0661b9d684263f85ef06512178fb76a0a 100644 (file)
@@ -79,7 +79,7 @@ void topsites(void)
        else
                sprintf(report,"%s/topsites.html",outdirname);
 
-       sprintf(csort,"sort -k 4,4 -o \"%s\" \"%s\"",general2,general);
+       sprintf(csort,"sort -t \"\t\" -k 4,4 -o \"%s\" \"%s\"",general2,general);
        cstatus=system(csort);
        if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
                debuga(_("sort command return status %d\n"),WEXITSTATUS(cstatus));
@@ -192,7 +192,7 @@ void topsites(void)
                sortt="";
        }
 
-       sprintf(csort,"sort %s -n %s -o \"%s\" \"%s\"",sortt,sortf,sites,general3);
+       sprintf(csort,"sort -t \"\t\" %s -n %s -o \"%s\" \"%s\"",sortt,sortf,sites,general3);
        cstatus=system(csort);
        if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
                debuga(_("sort command return status %d\n"),WEXITSTATUS(cstatus));
index c4ee9568d337368954b28ee36b9f15f060ee507f..463a4829be72c27c673dca104aa04ecaf3854ec5 100644 (file)
--- a/topuser.c
+++ b/topuser.c
@@ -167,7 +167,7 @@ void topuser(void)
        }
 
        snprintf(top1,sizeof(top1),"%s/top",outdirname);
-       sprintf(csort,"sort -T \"%s\" %s %s -o \"%s\" \"%s\"", tmp, order, sfield, top1, top2);
+       sprintf(csort,"sort -T \"%s\" -t \"\t\" %s %s -o \"%s\" \"%s\"", tmp, order, sfield, top1, top2);
        cstatus=system(csort);
        if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
                debuga(_("sort command return status %d\n"),WEXITSTATUS(cstatus));