From: Frédéric Marchal Date: Sat, 18 Jun 2011 10:32:16 +0000 (+0000) Subject: External sort command delimits the columns only on a tabulation X-Git-Tag: v2.3.2~55 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=eb8433696317cdd9d343536e01b5c216de071380;p=thirdparty%2Fsarg.git External sort command delimits the columns only on a tabulation 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. --- diff --git a/authfail.c b/authfail.c index 79ddc74..f33b76e 100644 --- a/authfail.c +++ b/authfail.c @@ -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)); diff --git a/dansguardian_log.c b/dansguardian_log.c index 081b40b..d1858a0 100644 --- a/dansguardian_log.c +++ b/dansguardian_log.c @@ -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 a6ce824..c600f73 100644 --- 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 5d62d76..2c3a496 100644 --- 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)); diff --git a/lastlog.c b/lastlog.c index c4ded49..f033147 100644 --- 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 4e5d7a1..6dfdd0f 100644 --- 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)); diff --git a/realtime.c b/realtime.c index b357740..907c99b 100755 --- a/realtime.c +++ b/realtime.c @@ -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)); diff --git a/siteuser.c b/siteuser.c index 92630f1..d5d6216 100644 --- a/siteuser.c +++ b/siteuser.c @@ -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)); diff --git a/smartfilter.c b/smartfilter.c index 3830a08..32661da 100644 --- a/smartfilter.c +++ b/smartfilter.c @@ -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 1247c67..b3989af 100644 --- 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); diff --git a/squidguard_log.c b/squidguard_log.c index 325a3ff..2d01a66 100644 --- a/squidguard_log.c +++ b/squidguard_log.c @@ -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)); diff --git a/topsites.c b/topsites.c index 4ff65d6..dd14f6a 100644 --- a/topsites.c +++ b/topsites.c @@ -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)); diff --git a/topuser.c b/topuser.c index c4ee956..463a482 100644 --- 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));