Function debuga format the output string itself, so there is no need to use sprintf.
+
for ac_header in stdio.h stdlib.h string.h strings.h sys/time.h time.h unistd.h sys/dirent.h \
dirent.h sys/socket.h netdb.h arpa/inet.h sys/types.h netinet/in.h sys/stat.h \
ctype.h gd.h gdfontl.h gdfontt.h gdfonts.h gdfontmb.h gdfontg.h iconv.h \
- errno.h sys/resource.h sys/wait.h
+ errno.h sys/resource.h sys/wait.h stdarg.h
do
as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then
AC_CHECK_HEADERS(stdio.h stdlib.h string.h strings.h sys/time.h time.h unistd.h sys/dirent.h \
dirent.h sys/socket.h netdb.h arpa/inet.h sys/types.h netinet/in.h sys/stat.h \
ctype.h gd.h gdfontl.h gdfontt.h gdfonts.h gdfontmb.h gdfontg.h iconv.h \
- errno.h sys/resource.h sys/wait.h)
+ errno.h sys/resource.h sys/wait.h stdarg.h)
AC_CHECK_LIB(gd, gdImagePng,LIBS="-lgd ${LIBS}"; HAVE_GD="yes", HAVE_GD="")
sprintf(guard_ou,"%s/dansguardian.log",tmp);
if(access(DansGuardianConf, R_OK) != 0) {
- sprintf(msg,"Cannot open DansGuardian config file: %s",DansGuardianConf);
- debuga(msg);
+ debuga("Cannot open DansGuardian config file: %s",DansGuardianConf);
exit(1);
}
printf("SARG: Maybe you have a broken record or garbage in your %s entry.\n",text[7]);
exit(1);
}
- sprintf(msg,"%s DansGuardian %s: %s",urly,buf,loglocation);
- debuga(msg);
+ debuga("%s DansGuardian %s: %s",urly,buf,loglocation);
}
if((fp_in=MY_FOPEN(loglocation,"r"))==NULL) {
if(fp_guard) fclose(fp_guard);
if(fp_ou) fclose(fp_ou);
- if(debug) {
- sprintf(msg,"%s: %s",text[54],guard_ou);
- debuga(msg);
- }
+ if(debug)
+ debuga("%s: %s",text[54],guard_ou);
sprintf(tmp6,"sort -k 1,1 -k 2,2 -k 4,4 '%s' -o '%s'",guard_in, guard_ou);
cstatus=system(tmp6);
char olduser[MAXLEN], oldmsg[50], acccode[50], oldaccelap[10], oldacccode[50];
char ipantes[MAXLEN], nameantes[MAXLEN];
char accsmart[MAXLEN];
- char Msg[MAXLEN];
char wcrc[50];
char crc2[50];
char wdname[MAXLEN];
}
(void)closedir( dirp );
- if(debug) {
- sprintf(Msg,"Datafile %s successfully",DataFile);
- debuga(Msg);
- }
+ if(debug)
+ debuga("Datafile %s successfully",DataFile);
}
void saverecs(char *dirname, char *user, long long int nacc, char *url, long long int nbytes, char *ip, char *hora, char *dia, long long int nelap, long long int incache, long long int oucache)
int cstatus;
if(access(arq, R_OK) != 0) {
- sprintf(cmd,"%s: %s",text[64],arq);
- debuga(cmd);
+ debuga("%s: %s",text[64],arq);
exit(1);
}
if(strstr(arq,".gz") !=0) {
- sprintf(cmd,"%s: %s > %s/sarg-file.in (zcat)",text[62],arq,tmp);
- debuga(cmd);
+ debuga("%s: %s > %s/sarg-file.in (zcat)",text[62],arq,tmp);
sprintf(cmd,"zcat %s > %s/sarg-file.in",arq,tmp);
cstatus=system(cmd);
if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
}
if(strstr(arq,".bz2") != 0) {
- sprintf(cmd,"%s: %s > %s/sarg-file.in (bzcat)",text[62],arq,tmp);
- debuga(cmd);
+ debuga("%s: %s > %s/sarg-file.in (bzcat)",text[62],arq,tmp);
sprintf(cmd,"bzcat %s > %s/sarg-file.in",arq,tmp);
cstatus=system(cmd);
if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
}
if(strstr(arq,".Z")) {
- sprintf(cmd,"%s: %s (uncompress)",text[62],arq);
- debuga(cmd);
+ debuga("%s: %s (uncompress)",text[62],arq);
sprintf(cmd,"uncompress %s",arq);
cstatus=system(cmd);
if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
int cstatus;
if(access(arq, R_OK) != 0) {
- sprintf(cmd,"%s: %s",text[64],arq);
- debuga(cmd);
+ debuga("%s: %s",text[64],arq);
exit(1);
}
if((strcmp(zip,"gzip") != 0) &&
(strcmp(zip,"compress") != 0))
return;
-
- sprintf(cmd,"%s: %s",text[63],arq);
- debuga(cmd);
+
+ debuga("%s: %s",text[63],arq);
sprintf(cmd,"%s %s",zip,arq);
cstatus=system(cmd);
FILE *fp_in;
char buf[MAXLEN];
- if(debug) {
- sprintf(Msg,"Loading configuration from: %s",ConfigFile);
- debuga(Msg);
- }
+ if(debug)
+ debuga("Loading configuration from: %s",ConfigFile);
if ((fp_in = fopen(ConfigFile, "r")) == NULL) {
fprintf(stderr, "SARG: (getconf) Cannot open file: %s\n",ConfigFile);
if(userip) {
strcpy(u2,usuario);
fixip(u2);
- sprintf(msg, "%s: %s",text[61],u2);
+ debuga("%s: %s",text[61],u2);
} else
- sprintf(msg, "%s: %s",text[61],usuario);
- debuga(msg);
+ debuga("%s: %s",text[61],usuario);
}
fscanf(fp_in,"%s",nacc);
fprintf(fp_usr,"%s\n",u2);
fclose(fp_usr);
- if(debug) {
- sprintf(msg, "%s %s %s (%s MB). %s %s",text[32],u2,text[74],PerUserLimit,text[75],PerUserLimitFile);
- debuga(msg);
- }
+ if(debug)
+ debuga("%s %s %s (%s MB). %s %s",text[32],u2,text[74],PerUserLimit,text[75],PerUserLimitFile);
}
}
}
#if HAVE_GDFONTG_H
#include <gdfontg.h>
#endif
+#if HAVE_STDARG_H
+#include <stdarg.h>
+#endif
#if HAVE_FOPEN64
#define _FILE_OFFSET_BITS 64
void write_html_trailer(FILE *fp_ou);
char *subs(char *str, char *from, char *to);
void conv_month(char *month);
-void debuga(const char *msg);
+void debuga(const char *msg,...);
void debugaz(const char *head, const char *msg);
void my_lltoa(unsigned long long int n, char s[], int len);
char *get_size(const char *path, const char *file);
return;
}
- if(debug) debuga(text[53]);
+ if(debug) debuga("%s",text[53]);
// Root dir
dirp = opendir(outdir);
buf[strlen(buf)-1]='\0';
if(ftot) {
- if(debug) {
- sprintf(msg,"%s: %s",text[81],buf);
- debuga(msg);
- }
+ if(debug)
+ debuga("%s: %s",text[81],buf);
// sprintf(temp,"%s%s",outdir,buf);
sprintf(temp,"rm -r %s%s",outdir,buf);
system(temp);
if(ConfigFile[0] == '\0') sprintf(ConfigFile,"%s/sarg.conf",SYSCONFDIR);
if(access(ConfigFile, R_OK) != 0) {
- sprintf(msg,"Cannot open config file: %s - %s",ConfigFile,strerror(errno));
- debuga(msg);
+ debuga("Cannot open config file: %s - %s",ConfigFile,strerror(errno));
exit(1);
}
strcpy(hexclude,ExcludeHosts);
if(strlen(hexclude) > 0) {
if(access(hexclude, R_OK) != 0) {
- sprintf(msg,"Cannot open exclude_hosts file: %s - %s",hexclude,strerror(errno));
- debuga(msg);
+ debuga("Cannot open exclude_hosts file: %s - %s",hexclude,strerror(errno));
exit(1);
}
gethexclude(hexclude,debug);
printf("Language=%s\n\n",text[3]);
}
- if(debug){
- sprintf(msg,"sarg %s: %s",text[73],VERSION);
- debuga(msg);
- }
+ if(debug)
+ debuga("sarg %s: %s",text[73],VERSION);
if (strlen(Ulimit) > 0) {
#if defined(RLIMIT_NOFILE)
#elif defined(RLIMIT_OFILE)
if(setrlimit (RLIMIT_OFILE, &rl) == -1) {
#endif
- sprintf(msg,"setrlimit error - %s\n",strerror(errno));
- debuga(msg);
+ debuga("setrlimit error - %s\n",strerror(errno));
}
}
- if(debug) {
- sprintf(msg,"Maximum file descriptor: cur=%ld max=%ld, changed to cur="RLIM_STRING" max="RLIM_STRING,l1,l2,rl.rlim_cur,rl.rlim_max);
- debuga(msg);
- }
+ if(debug)
+ debuga("Maximum file descriptor: cur=%ld max=%ld, changed to cur="RLIM_STRING" max="RLIM_STRING,l1,l2,rl.rlim_cur,rl.rlim_max);
}
read_usertab(UserTabFile);
strcpy(arqtt,arq);
decomp(arq,zip,tmp);
- if(debug) {
- sprintf(msg, "%s: %s",text[7],arq);
- debuga(msg);
- }
+ if(debug)
+ debuga("%s: %s",text[7],arq);
if((fp_in=MY_FOPEN(arq,"r"))==NULL) {
fprintf(stderr, "%s: (log) %s: %s - %s\n",argv[0],text[8],arq,strerror(errno));
tt=atoi(data);
t=localtime(&tt);
- strftime(tbuf2, 127, "%H%M", t);
+ strftime(tbuf2, sizeof(tbuf2), "%H%M", t);
if(strncmp(df,"u",1) == 0)
- strftime(tbuf, 127, "%Y%b%d", t);
+ strftime(tbuf, sizeof(tbuf), "%Y%b%d", t);
if(strncmp(df,"e",1) == 0)
- strftime(tbuf, 127, "%d%b%Y", t);
+ strftime(tbuf, sizeof(tbuf), "%d%b%Y", t);
if(strncmp(df,"w",1) == 0) {
strcpy(IndexTree,"file");
- strftime(tbuf, 127, "%Y.%U", t);
+ strftime(tbuf, sizeof(tbuf), "%Y.%U", t);
}
- strftime(dia, 127, "%d/%m/%Y", t);
- strftime(wdata, 127, "%Y%m%d", t);
+ strftime(dia, sizeof(dia), "%d/%m/%Y", t);
+ strftime(wdata, sizeof(wdata), "%Y%m%d", t);
idata=atoi(wdata);
if(strncmp(df,"u",1)==0)
- strftime(dia, 127, "%m/%d/%Y", t);
+ strftime(dia, sizeof(dia), "%m/%d/%Y", t);
sprintf(hora,"%02d:%02d:%02d",t->tm_hour,t->tm_min,t->tm_sec);
} else {
strcpy(wtemp,data+1);
}
if(strcmp(df,"u") == 0)
- sprintf(tbuf,"%s%s%s",ano,mes,dia);
+ snprintf(tbuf,sizeof(tbuf),"%s%s%s",ano,mes,dia);
if(strcmp(df,"e") == 0)
- sprintf(tbuf,"%s%s%s",dia,mes,ano);
+ snprintf(tbuf,sizeof(tbuf),"%s%s%s",dia,mes,ano);
builddia(dia,mes,ano,df,wdata);
idata=atoi(wdata);
}
fclose (fp_Write_User);
if(debug) {
- sprintf(msg, " %s: %ld, %s: %ld, %s: %ld",text[10],totregsl,text[11],totregsg,text[68],totregsx);
- debuga(msg);
+ debuga(" %s: %ld, %s: %ld, %s: %ld",text[10],totregsl,text[11],totregsg,text[68],totregsx);
if((common_log) && (squid_log))
- debuga(text[12]);
+ debuga("%s",text[12]);
if((common_log) && (!squid_log))
- debuga(text[13]);
+ debuga("%s",text[13]);
if((!common_log) && (squid_log))
- debuga(text[14]);
+ debuga("%s",text[14]);
if(sarglog)
- debuga(text[124]);
+ debuga("%s",text[124]);
if((!common_log) && (!squid_log) && (!sarglog) && (!isalog)) {
if(!totregsg) {
debugaz("period",period);
}
- if(debug){
- sprintf(msg, "%s: %s",text[17],period);
- debuga(msg);
- }
+ if(debug)
+ debuga("%s: %s",text[17],period);
fclose(fp_in);
// fclose(fp_ou);
}
}
- if(debug) {
- sprintf(msg,"%s %s",text[123],arq_log);
- debuga(msg);
- }
+ if(debug)
+ debuga("%s %s",text[123],arq_log);
}
if(strstr(ReportType,"denied") != 0) {
free(excludeuser);
if(debug)
- debuga(text[21]);
+ debuga("%s",text[21]);
exit(0);
FILE *fp_usr;
char buf[255];
- char Msg[255];
char *str;
unsigned long int nreg=0;
- if(debug) {
- sprintf(Msg,"%s: %s",text[60],pwdfile);
- debuga(Msg);
- }
+ if(debug)
+ debuga("%s: %s",text[60],pwdfile);
if ((fp_usr = fopen(pwdfile, "r")) == NULL) {
fprintf(stderr, "SARG: (getusers) %s: %s - %s\n",text[45],pwdfile,strerror(errno));
FILE *fp_ex;
char buf[255];
- char Msg[255];
unsigned long int nreg=0;
- if(debug) {
- sprintf(Msg,"%s: %s",text[67],hexfile);
- debuga(Msg);
- }
+ if(debug)
+ debuga("%s: %s",text[67],hexfile);
if ((fp_ex = fopen(hexfile, "r")) == NULL) {
fprintf(stderr, "SARG: (gethexclude) %s: %s - %s\n",text[45],hexfile,strerror(errno));
FILE *fp_ex;
char buf[255];
- char Msg[255];
unsigned long int nreg=0;
- if(debug) {
- sprintf(Msg,"%s: %s",text[67],uexfile);
- debuga(Msg);
- }
+ if(debug)
+ debuga("%s: %s",text[67],uexfile);
if ((fp_ex = fopen(uexfile, "r")) == NULL) {
fprintf(stderr, "SARG: (gethexclude) %s: %s - %s\n",text[45],uexfile,strerror(errno));
strcat(wdirname,user);
if(debug){
- sprintf(msg,"%s: %s",text[49],wdirname);
- debuga(msg);
+ debuga("%s: %s",text[49],wdirname);
}
strcat(wdirname,".utmp");
strcat(arqin,direntp->d_name);
if(debug) {
- sprintf(msg,"%s: %s",text[54],arqou);
- debuga(msg);
+ debuga("%s: %s",text[54],arqou);
}
strcat(arqou,".txt");
int dlen;
if(debug) {
- sprintf(msg,"%s",text[138]);
- debuga(msg);
+ debuga("%s",text[138]);
}
sprintf(wtmp,"%s/sarg",tmp);
printf("SARG: Maybe you have a broken record or garbage in your %s string.\n",text[7]);
exit(1);
}
- sprintf(msg,"%s squidGuard %s: %s",urly,buf,wentp);
- debuga(msg);
+ debuga("%s squidGuard %s: %s",urly,buf,wentp);
}
/* With squidGuard, you can log groups in only one log file.
if(strlen(SquidGuardConf) > 0) {
if(access(SquidGuardConf, R_OK) != 0) {
- sprintf(msg,"Cannot open squidGuard config file: %s",SquidGuardConf);
- debuga(msg);
+ debuga("Cannot open squidGuard config file: %s",SquidGuardConf);
exit(1);
}
if (fp_ou) fclose(fp_ou);
if(debug) {
- sprintf(msg,"%s: %s",text[54],guard_ou);
- debuga(msg);
+ debuga("%s: %s",text[54],guard_ou);
}
sprintf(tmp6,"sort -k 1,1 -k 2,2 -k 4,4 '%s' -o '%s'",guard_in, guard_ou);
}
if(debug) {
- sprintf(msg,"%s: %s",text[66],UserAgentLog);
- debuga(msg);
+ debuga("%s: %s",text[66],UserAgentLog);
}
while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
strcpy(fdate,data);
if(debug) {
- sprintf(msg, " %s: %ld",text[10],totregsl);
- debuga(msg);
+ debuga(" %s: %ld",text[10],totregsl);
}
fclose(fp_in);
}
if(debug) {
- sprintf(msg,"%s: %s",text[54],tmp2);
- debuga(msg);
+ debuga("%s: %s",text[54],tmp2);
}
sprintf(csort,"sort -n -t '\\' -k 4,4 -k 3,3 -k 2,2 -k 1,1 -o '%s' '%s'",tmp2,tmp3);
}
if(debug)
- debuga(text[72]);
+ debuga("%s",text[72]);
fprintf(fp_ht, "<!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);
fputs("</head>\n",fp_ht);
}
-void debuga(const char *msg)
+void debuga(const char *msg,...)
{
- fprintf(stderr, "SARG: %s\n",msg);
+ va_list ap;
+ fputs("SARG: ",stderr);
+ va_start(ap,msg);
+ vfprintf(stderr,msg,ap);
+ va_end(ap);
+ fputc('\n',stderr);
}
fclose(fp_ou);
if(debug)
- debuga((char *)text[50]);
+ debuga("%s",(char *)text[50]);
return;
return;
if(debug) {
- sprintf(msg,"%s: sarg-general, sarg-period",text[82]);
- debuga(msg);
+ debuga("%s: sarg-general, sarg-period",text[82]);
}
sprintf(warea,"%s/sarg-general",outdir);
if((fp_in=fopen(warea,"r"))==NULL){
if (UserTabFile[0] != '\0') {
if(debug) {
- sprintf(msg,"%s: %s",text[86],UserTabFile);
- debuga(msg);
+ 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));