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)
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)
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)
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 -.
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
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);
}
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),"_",".");
#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
#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
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);
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();
-
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);
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),"_",".");
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),"_",".");
}
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));
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)