From: Frédéric Marchal Date: Sat, 23 Jan 2010 19:29:07 +0000 (+0000) Subject: Ported r208 from branches/v2_2_7 X-Git-Tag: v2.3-pre2~113 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8988b90d78567b2b68740b4364abbce038b99a7b;p=thirdparty%2Fsarg.git Ported r208 from branches/v2_2_7 --- 8988b90d78567b2b68740b4364abbce038b99a7b diff --cc CMakeLists.txt index 8a5356d,bcd3f7f..b43a1c7 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@@ -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 555a0ef,0136d27..4cb249f --- a/ChangeLog +++ 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 - 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 configure.in index 47be0b7,b72186c..3aafcb9 --- a/configure.in +++ b/configure.in @@@ -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 diff --cc grepday.c index 51d1658,736cb21..e17b3ac --- a/grepday.c +++ 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 dcf31e2,66b9120..0c0fb33 --- a/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 83c006d,54be925..30432f3 --- a/include/conf.h +++ b/include/conf.h @@@ -95,12 -94,12 +95,18 @@@ gdPoint points[4] #ifdef HAVE_WINSOCK_H #include #endif +#ifdef HAVE_LDAP_H +#include +#endif +#ifdef HAVE_MATH_H +#include +#endif + #ifdef HAVE_LOCALE_H + #include + #endif + #ifdef HAVE_EXECINFO_H + #include + #endif #if defined(HAVE_FOPEN64) #define _FILE_OFFSET_BITS 64 diff --cc include/config.h.in index 77828b7,f794a3b..58c90d9 --- a/include/config.h.in +++ b/include/config.h.in @@@ -40,6 -40,8 +40,10 @@@ #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 1021e2f,ce6500d..e79a447 --- a/include/defs.h +++ b/include/defs.h @@@ -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 6689d05,841f3c9..f64802d --- a/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'; @@@ -1476,13 -1475,8 +1483,8 @@@ 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 db37740,4180a0f..4e10c81 --- a/realtime.c +++ b/realtime.c @@@ -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 report.c index b83da11,05998e7..2568f66 --- a/report.c +++ 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 topuser.c index 78bc42c,ecf9de7..0bfea87 --- a/topuser.c +++ 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 2e9a255,bb33938..95a0055 --- a/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)