]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Ported r208 from branches/v2_2_7
authorFrédéric Marchal <fmarchal@users.sourceforge.net>
Sat, 23 Jan 2010 19:29:07 +0000 (19:29 +0000)
committerFrédéric Marchal <fmarchal@users.sourceforge.net>
Sat, 23 Jan 2010 19:29:07 +0000 (19:29 +0000)
23 files changed:
1  2 
CMakeLists.txt
ChangeLog
Makefile.in
authfail.c
configure.in
dansguardian_report.c
denied.c
download.c
getconf.c
grepday.c
html.c
include/conf.h
include/config.h.in
include/defs.h
log.c
realtime.c
repday.c
report.c
sarg.conf
siteuser.c
squidguard_report.c
topuser.c
util.c

diff --cc CMakeLists.txt
index 8a5356dcb3c6f956dd26aaeafe7201b805a74791,bcd3f7fae2e9e1d112564850ecf3d6beb65d0ea0..b43a1c7008be4e35134b5aa6b22aa973a91f03c8
@@@ -1,9 -1,9 +1,9 @@@
  CMAKE_MINIMUM_REQUIRED (VERSION 2.6)
  PROJECT(sarg C)
  SET(sarg_VERSION 2)
 -SET(sarg_REVISION 2)
 -SET(sarg_BUILD "7rc1")
 +SET(sarg_REVISION 3)
 +SET(sarg_BUILD "")
- SET(sarg_BUILDDATE "Dec-15-2009")
+ SET(sarg_BUILDDATE "Jan-22-2010")
  
  INCLUDE(AddFileDependencies)
  INCLUDE(CheckIncludeFile)
@@@ -50,7 -52,7 +52,8 @@@ SET(SRC util.c log.c report.c topuser.
         indexonly.c splitlog.c lastlog.c topsites.c siteuser.c css.c
         smartfilter.c denied.c authfail.c language.c charset.c
         squidguard_log.c squidguard_report.c auth.c download.c grepday.c
--       dansguardian_log.c dansguardian_report.c realtime.c)
++       dansguardian_log.c dansguardian_report.c realtime.c btree_cache.c
++       usertab.c)
  
  FOREACH(f ${SRC})
     ADD_FILE_DEPENDENCIES(${f} ${CMAKE_BINARY_DIR}/config.h ${CMAKE_SOURCE_DIR}/include/conf.h ${CMAKE_SOURCE_DIR}/include/info.h ${CMAKE_SOURCE_DIR}/include/defs.h)
@@@ -84,8 -100,13 +101,15 @@@ CHECK_INCLUDE_FILE(sys/wait.h HAVE_SYS_
  CHECK_INCLUDE_FILE(stdarg.h HAVE_STDARG_H)
  CHECK_INCLUDE_FILE(inttypes.h HAVE_INTTYPES_H)
  CHECK_INCLUDE_FILE(limits.h HAVE_LIMITS_H)
++CHECK_INCLUDE_FILE(ldap.h HAVE_LDAP_H)
++CHECK_INCLUDE_FILE(math.h HAVE_MATH_H)
+ CHECK_INCLUDE_FILE(locale.h HAVE_LOCALE_H)
+ CHECK_INCLUDE_FILE(execinfo.h HAVE_EXECINFO_H)
  
  CHECK_FUNCTION_EXISTS(bzero HAVE_BZERO)
+ CHECK_FUNCTION_EXISTS(backtrace HAVE_BACKTRACE)
+ CHECK_FUNCTION_EXISTS(symlink HAVE_SYMLINK)
+ CHECK_FUNCTION_EXISTS(lstat HAVE_LSTAT)
  
  # Find gd
  CHECK_INCLUDE_FILE(gd.h HAVE_GD_H)
diff --cc ChangeLog
index 555a0ef686e0f3571ef78a11d18ccf4cad8f7aae,0136d27f7bdd3957ef7874defc551626d7c87d08..4cb249fc32ab466043a569bad997897bf4c39389
+++ b/ChangeLog
@@@ -1,15 -1,7 +1,13 @@@
  SARG ChangeLog
  
- Dec-12-2009   Version 2.3
++Dec-12-2009 Version 2.3
 +              - LDAP usertab added. 
 +                Now you can have your users in a LDAP Server.
 +                Use these tags in sarg.conf: LDAPHost, LDAPPort, LDAPBindDN, LDAPBindPW,
 +                                             LDAPBaseSearch, LDAPFilterSearch
 +
Dec-03-2009   Version 2.2.7
Jan-22-2010 Version 2.2.7
                - Extra compile and run time protection (FORTIFY_SOURCE) fixed in configure.
-               - Invalid sort field separator in useragent.c
-                       Thanks to Maxim Britov <maxim@office.modum.by>
                - Use tabulations as columns separator in intermediary files to avoid problems when a field of the log contains a space.
                - Input log file type detection partly rewritten to clearly distinguish which type is processed where.
                - Read the input log file from standard input if log file name is -.
diff --cc Makefile.in
Simple merge
diff --cc authfail.c
Simple merge
diff --cc configure.in
index 47be0b764a24f0137c7d77adbc53d2d795d49d32,b72186ccbc335972c2b12f0e232555a19e806dbc..3aafcb9935f458e61cbfc02c67a0a34c22b82896
@@@ -44,12 -63,12 +63,13 @@@ if test -n "$LIBICONV" ; the
  fi
  
  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 stdarg.h inttypes.h limits.h ldap.h math.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 stdarg.h inttypes.h limits.h locale.h \
 -              execinfo.h)
++              execinfo.h ldap.h math.h)
  
  AC_CHECK_LIB(gd, gdImagePng,LIBS="-lgd ${LIBS}"; HAVE_GD="yes", HAVE_GD="")
 +AC_CHECK_LIB(ldap, ldap_init,LIBS="-lldap ${LIBS}"; HAVE_LDAP="yes", HAVE_LDAP="")
  
  dnl Checks for typedefs, structures, and compiler characteristics.
  AC_C_CONST
Simple merge
diff --cc denied.c
Simple merge
diff --cc download.c
Simple merge
diff --cc getconf.c
Simple merge
diff --cc grepday.c
index 51d165885c4c2337322ccace3b97d1d702d922d8,736cb219542dac2abbbfd52362649cd8cab4f224..e17b3acfe3699b191bfc31aa88e15b05bf00e7cb
+++ b/grepday.c
@@@ -427,11 -443,17 +443,18 @@@ void greport_day(const char *user
              ip2name(wuser,sizeof(wuser));
     }
  
 -   get_usertab_name(wuser,name,sizeof(name));
 +//   get_usertab_name(wuser,name,sizeof(name));
 +   user_find(name, wuser);
  
     while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
-       if (getword(data,sizeof(data),buf,'\t')<0 || getword(day,sizeof(day),data,'/')<0) {
+       fixendofline(buf);
+       getword_start(&gwarea,buf);
+       if (getword(data,sizeof(data),&gwarea,'\t')<0) {
+          printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",tmp5);
+          exit(1);
+       }
+       getword_start(&gwarea1,data);
+       if (getword_atoll(&llday,&gwarea1,'/')<0) {
           printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",tmp5);
           exit(1);
        }
diff --cc html.c
index dcf31e21d71a9ee85a3a782ce2eed7bb411d27a7,66b9120fa23fb49e987ddabe5a492fcb4f8f2036..0c0fb33838c71085db277450533118868b06ec73
--- 1/html.c
--- 2/html.c
+++ b/html.c
@@@ -165,11 -170,10 +170,11 @@@ void htmlrel(void
        strcpy(u2,usuario);
        if(userip)
           fixip(u2);
-       if(strcmp(Ip2Name,"yes") == 0)
+       if(Ip2Name)
           ip2name(u2,sizeof(u2));
  
 -      get_usertab_name(u2,name2,sizeof(name2));
 +//      get_usertab_name(u2,name2,sizeof(name2));
 +      user_find(name2, u2);
  
        if(dotinuser && strchr(name2,'_')) {
           subs(name2,sizeof(name2),"_",".");
diff --cc include/conf.h
index 83c006d6ea17e7598ddd3bae680dba994b64843d,54be925e667b09ee0c4edfb51daef9b266846bce..30432f3c6a1618378e78714687bb4f66f2ca8799
@@@ -95,12 -94,12 +95,18 @@@ gdPoint points[4]
  #ifdef HAVE_WINSOCK_H
  #include <winsock.h>
  #endif
 +#ifdef HAVE_LDAP_H
 +#include <ldap.h>
 +#endif
 +#ifdef HAVE_MATH_H
 +#include <math.h>
 +#endif
+ #ifdef HAVE_LOCALE_H
+ #include <locale.h>
+ #endif
+ #ifdef HAVE_EXECINFO_H
+ #include <execinfo.h>
+ #endif
  
  #if defined(HAVE_FOPEN64)
  #define _FILE_OFFSET_BITS 64
index 77828b7d644becf959ee7cd39839e2484a7f705d,f794a3bfdf33e3ee25ca93389fc5bbf98dcf0bc7..58c90d9df2643472b9532149136d4ba7248f70d9
  #cmakedefine HAVE_LIMITS_H
  #cmakedefine HAVE_WINDOWS_H
  #cmakedefine HAVE_WINSOCK_H
++#cmakedefine HAVE_LDAP_H
++#cmakedefine HAVE_MATH_H
+ #cmakedefine HAVE_LOCALE_H
+ #cmakedefine HAVE_EXECINFO_H
  
  #cmakedefine IBERTY_LIB
  
diff --cc include/defs.h
index 1021e2fa4c8bcb9c1763bc3906ff57b0bf3e0482,ce6500d1450251d5876251a6530a43d914eaa3c0..e79a44752e348b139c8b0be2bfd92d991dfe822a
@@@ -113,10 -127,14 +127,15 @@@ void usage(const char *prog)
  void useragent(void);
  
  // util.c
- int getword(char *word, int limit, char *line, int stop);
- int getword_multisep(char *word, int limit, char *line, int stop);
- int getword_skip(int limit, char *line, int stop);
+ void getword_start(struct getwordstruct *gwarea, const char *line);
+ void getword_restart(struct getwordstruct *gwarea);
+ int getword(char *word, int limit, struct getwordstruct *gwarea, int stop);
+ int getword_multisep(char *word, int limit, struct getwordstruct *gwarea, int stop);
+ int getword_skip(int limit, struct getwordstruct *gwarea, int stop);
+ int getword_atoll(long long int *number, struct getwordstruct *gwarea, int stop);
+ long long int my_atoll (const char *nptr);
+ int is_absolute(const char *path);
 +int getnumlist(char *, numlist *, const int, const int);
  void name_month(char *month,int month_len);
  void conv_month_name(char *month);
  void buildymd(const char *dia, const char *mes, const char *ano, char *wdata);
@@@ -164,16 -184,4 +184,15 @@@ char *get_param_value(const char *param
  void read_usertab(const char *UserTabFile);
  void get_usertab_name(const char *user,char *name,int namelen);
  int compar( const void *, const void * );
- int is_download_suffix(const char *url);
+ void unlinkdir(const char *dir,int contentonly);
 +
 +int ldap_init();
 +int ldap_search();
 +int ldap_search_s();
 +int ldap_unbind();
 +int ldap_simple_bind();
 +int ldap_simple_bind_s();
 +char *ldap_get_values();
 +void init_ldap_usertab();
 +void user_find(char *mappedname, char *userlogin);
 +void close_usertab();
diff --cc log.c
index 6689d058b07cfdb4f4b9f1103852005181f2587b,841f3c9fa0c2614f23895158091682b8d31ebf52..f64802d46f83960f0991faf85ef5fcd9309427b8
--- 1/log.c
--- 2/log.c
+++ b/log.c
@@@ -227,19 -217,12 +217,20 @@@ int main(int argc,char *argv[]
     strcpy(IndexTree,"file");
     strcpy(RealtimeTypes,"GET,PUT,CONNECT");
     strcpy(RealtimeUnauthRec,"show");
-    strcpy(SquidguardIgnoreDate,"off");
-    strcpy(DansguardianIgnoreDate,"off");
+    SquidguardIgnoreDate=0;
+    DansguardianIgnoreDate=0;
     strcpy(DataFileUrl,"ip");
     strcpy(MaxElapsed,"28800000");
-    strcpy(BytesInSitesUsersReport,"no");
+    BytesInSitesUsersReport=0;
+    UserAuthentication=0;
 +   strcpy(LDAPHost,"127.0.0.1");
 +   strcpy(LDAPPort,"389");
 +   strcpy(LDAPProtocolVersion,"3");
 +   LDAPBindDN[0]='\0';
 +   LDAPBindPW[0]='\0';
 +   LDAPBaseSearch[0]='\0';
 +   strcpy(LDAPFilterSearch, "uid=%s");
 +   strcpy(LDAPTargetAttr, "cn");
  
     dia[0]='\0';
     mes[0]='\0';
              fclose(fp_denied);
           if(fp_authfail)
              fclose(fp_authfail);
-          free_excludecodes();
 -         if(userfile)
 -            free(userfile);
 +//         if(userfile)
 +////            free(userfile);
-          if(excludefile)
-             free(excludefile);
-          if(excludeuser)
-             free(excludeuser);
           unlink(tmp4);
           unlink(tmp6);
           unlink(tmp3);
diff --cc realtime.c
index db37740de890a17d329e77a20ad8ae432968402b,4180a0f18fc2c83a46a03aeb8becc6cb148de665..4e10c817568788aa6cba92e5cd4d808a746a332f
@@@ -208,11 -213,12 +213,13 @@@ static void datashow(const char *tmp
        if(strcmp(ouser,user) == 0 && strcmp(ourl,url) == 0)
           continue;
  
+       if(userip)
+          strcpy(user,ip);
        strcpy(u2,user);
-       if(strcmp(Ip2Name,"yes") == 0)
+       if(Ip2Name)
           ip2name(u2,sizeof(u2));
 -      get_usertab_name(u2,name,sizeof(name));
 +//      get_usertab_name(u2,name,sizeof(name));
 +      user_find(name, u2);
  
        if(dotinuser && strchr(name,'_')) {
           subs(name,sizeof(name),"_",".");
diff --cc repday.c
Simple merge
diff --cc report.c
index b83da116a3f0e9db07db490bf2668982a220e6ce,05998e7fbd62be389beb1e85af211cc394d3d7f1..2568f666aa37383183f8a8023d96d3cd4f901034
+++ b/report.c
@@@ -112,10 -117,9 +117,10 @@@ void gerarel(void
        maketmp_hour(user,tmp,indexonly);
  
        strcpy(u2,user);
-       if(strcmp(Ip2Name,"yes") == 0)
+       if(Ip2Name)
           ip2name(u2,sizeof(u2));
 -      get_usertab_name(u2,name,sizeof(name));
 +//      get_usertab_name(u2,name,sizeof(name));
 +      user_find(name, u2);
  
        if(dotinuser && strchr(name,'_')) {
           subs(name,sizeof(name),"_",".");
diff --cc sarg.conf
Simple merge
diff --cc siteuser.c
Simple merge
Simple merge
diff --cc topuser.c
index 78bc42cb912fd0a6ce7846fbb2b2ea34a0647ffb,ecf9de75209c8161025811a28c3ebeb4ec41ef0c..0bfea87d0abdd62024af6c3350de8a65d22d450b
+++ b/topuser.c
@@@ -466,10 -472,9 +472,10 @@@ void topuser(void
        }
  
        if(strcmp(user2,"TOTAL") != 0) {
 -         get_usertab_name(user2,name,sizeof(name));
 +//         get_usertab_name(user2,name,sizeof(name));
 +         user_find(name, user2);
  
-          if((strcmp(Ip2Name,"yes") == 0) &&
+          if(Ip2Name &&
              ((str=(char *) strstr(name, ".")) != (char *) NULL) &&
              ((str=(char *) strstr(str+1, ".")) != (char *) NULL))
              ip2name(name,sizeof(name));
diff --cc util.c
index 2e9a25564988f0bd82ce4160cad6e49093e53620,bb33938181eb33aef2a6cc838f40764a04ca0c4c..95a005591e06cf86a35318ae544befceebc3d239
--- 1/util.c
--- 2/util.c
+++ b/util.c
@@@ -1494,58 -1551,54 +1551,59 @@@ void read_usertab(const char *UserTabFi
     FILE *fp_usr;
     long int nreg;
     char buf[MAXLEN];
-    char bufy[MAXLEN];
     int z2;
     int z1;
-    int i;
  
 -   if (UserTabFile[0] == '\0') return;
 -   if(debug)
 -      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));
 -      exit(1);
 -   }
 -   fseek(fp_usr, 0, SEEK_END);
 -   nreg = ftell(fp_usr);
 -   if (nreg<0) {
 -      fprintf(stderr,"SARG: Cannot get the size of file %s",UserTabFile);
 -      exit(1);
 -   }
 -   nreg += 100;
 -   fseek(fp_usr, 0, SEEK_SET);
 -   if((userfile=(char *) malloc(nreg))==NULL){
 -      fprintf(stderr, "SARG ERROR: %s",text[87]);
 -      exit(1);
 -   }
 -   userfile[0]='\t';
 -   z2=1;
 -   while(fgets(buf,sizeof(buf),fp_usr)!=NULL) {
 -      if (buf[0]=='#') continue;
 -      fixendofline(buf);
 -      z1=0;
 -      while(buf[z1] && (unsigned char)buf[z1]>' ') {
 -         if (z2+3>=nreg) { //need at least 3 additional bytes for the minimum string "\n\t\0"
 -            fprintf(stderr,"SARG: The list of the users is too long in your %s file.\n",UserTabFile);
 -            exit(1);
 -         }
 -         userfile[z2++]=buf[z1++];
 +   if (strcmp(UserTabFile, "ldap") == 0) {
 +      if(debug)
 +         debuga("%s: %s",text[86],UserTabFile);
 +      init_ldap_usertab();
 +   } else if (UserTabFile[0] != '\0') {
-       if(debug) {
++      if(debug)
 +         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));
 +         exit(1);
        }
 -      while(buf[z1] && (unsigned char)buf[z1]<=' ') z1++;
 -      userfile[z2++]='\n';
 -      while(buf[z1] && (unsigned char)buf[z1]>' ') {
 -         if (z2+2>=nreg) { //need at least 2 additional bytes for "\t\0"
 -            fprintf(stderr,"SARG: The list of the users is too long in your %s file.\n",UserTabFile);
 -            exit(1);
 +      fseek(fp_usr, 0, SEEK_END);
 +      nreg = ftell(fp_usr);
 +      if (nreg<0) {
-          printf("SARG: Cannot get the size of file %s",UserTabFile);
++         fprintf(stderr,"SARG: Cannot get the size of file %s",UserTabFile);
 +         exit(1);
 +      }
 +      nreg += 100;
 +      fseek(fp_usr, 0, SEEK_SET);
 +      if((userfile=(char *) malloc(nreg))==NULL){
 +         fprintf(stderr, "SARG ERROR: %s",text[87]);
 +         exit(1);
 +      }
-       strcpy(userfile,"\t");
++      userfile[0]='\t';
 +      z2=1;
 +      while(fgets(buf,sizeof(buf),fp_usr)!=NULL) {
 +         if (buf[0]=='#') continue;
-          for (i=strlen(buf)-1 ; i>=0 && (unsigned char)buf[i]<=' ' ; i--) buf[i]=0;
-          if (getword_multisep(bufy,sizeof(bufy),buf,' ')<0) {
-             printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",UserTabFile);
-             exit(1);
-          }
-          if (z2+strlen(bufy)+strlen(buf)+3>=nreg) {
-             printf("SARG: The list of the users is too long in your %s file.\n",UserTabFile);
-             exit(1);
++         fixendofline(buf);
++         z1=0;
++         while(buf[z1] && (unsigned char)buf[z1]>' ') {
++            if (z2+3>=nreg) { //need at least 3 additional bytes for the minimum string "\n\t\0"
++               fprintf(stderr,"SARG: The list of the users is too long in your %s file.\n",UserTabFile);
++               exit(1);
++            }
++            userfile[z2++]=buf[z1++];
 +         }
-          for(z1=0; bufy[z1]; z1++)
-             userfile[z2++]=bufy[z1];
++         while(buf[z1] && (unsigned char)buf[z1]<=' ') z1++;
 +         userfile[z2++]='\n';
-          for(z1=0; buf[z1]; z1++)
-             userfile[z2++]=buf[z1];
++         while(buf[z1] && (unsigned char)buf[z1]>' ') {
++            if (z2+2>=nreg) { //need at least 2 additional bytes for "\t\0"
++               fprintf(stderr,"SARG: The list of the users is too long in your %s file.\n",UserTabFile);
++               exit(1);
++            }
++            userfile[z2++]=buf[z1++];
+          }
 -         userfile[z2++]=buf[z1++];
 +         userfile[z2++]='\t';
        }
-       userfile[z2]=0;
 -      userfile[z2++]='\t';
++      userfile[z2]='\0';
 +      fclose(fp_usr);
     }
 -   userfile[z2]='\0';
 -   fclose(fp_usr);
  }
  
  void get_usertab_name(const char *user,char *name,int namelen)