X-Git-Url: http://git.ipfire.org/?a=blobdiff_plain;f=authfail.c;h=f0a7fb787fcddbcf0fb10f5ed86119b6c80e8142;hb=9bb2033d3165ef5307c92f4f5ee377ceebe5d480;hp=1d4ccc7073895c8aa04d413999768d2dadbf293c;hpb=720f3529cac925e1fd68e192461cf16554fc07a3;p=thirdparty%2Fsarg.git diff --git a/authfail.c b/authfail.c index 1d4ccc7..f0a7fb7 100644 --- a/authfail.c +++ b/authfail.c @@ -43,17 +43,17 @@ Open a file to store the authentication failure. void authfail_open(void) { if ((ReportType & REPORT_TYPE_AUTH_FAILURES) == 0) { - if (debugz>=LogLevel_Process) debugaz(_("Authentication failures report not produced as it is not requested\n")); + if (debugz>=LogLevel_Process) debugaz(__FILE__,__LINE__,_("Authentication failures report not produced as it is not requested\n")); return; } if (Privacy) { - if (debugz>=LogLevel_Process) debugaz(_("Authentication failures report not produced because privacy option is active\n")); + if (debugz>=LogLevel_Process) debugaz(__FILE__,__LINE__,_("Authentication failures report not produced because privacy option is active\n")); return; } snprintf(authfail_unsort,sizeof(authfail_unsort),"%s/authfail.int_unsort",tmp); if ((fp_authfail=MY_FOPEN(authfail_unsort,"w"))==NULL) { - debuga(_("Cannot open file \"%s\": %s\n"),authfail_unsort,strerror(errno)); + debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),authfail_unsort,strerror(errno)); exit(EXIT_FAILURE); } return; @@ -83,7 +83,7 @@ void authfail_close(void) if (fp_authfail) { if (fclose(fp_authfail)==EOF) { - debuga(_("Write error in \"%s\": %s\n"),authfail_unsort,strerror(errno)); + debuga(__FILE__,__LINE__,_("Write error in \"%s\": %s\n"),authfail_unsort,strerror(errno)); exit(EXIT_FAILURE); } fp_authfail=NULL; @@ -112,7 +112,8 @@ static void show_ignored_auth(FILE *fp_ou,int count) void authfail_report(void) { - FILE *fp_in = NULL, *fp_ou = NULL; + FileObject *fp_in = NULL; + FILE *fp_ou = NULL; char *buf; char *url; @@ -138,14 +139,14 @@ void authfail_report(void) if (!authfail_exists) { if (!KeepTempLog && authfail_unsort[0]!='\0' && unlink(authfail_unsort)) - debuga(_("Failed to delete \"%s\": %s\n"),authfail_unsort,strerror(errno)); + debuga(__FILE__,__LINE__,_("Failed to delete \"%s\": %s\n"),authfail_unsort,strerror(errno)); authfail_unsort[0]='\0'; - if (debugz>=LogLevel_Process) debugaz(_("Authentication failures report not produced because it is empty\n")); + if (debugz>=LogLevel_Process) debugaz(__FILE__,__LINE__,_("Authentication failures report not produced because it is empty\n")); return; } if (debugz>=LogLevel_Process) - debuga(_("Creating authentication failures report...\n")); + debuga(__FILE__,__LINE__,_("Creating authentication failures report...\n")); snprintf(authfail_sort,sizeof(authfail_sort),"%s/authfail.int_log",tmp); snprintf(report,sizeof(report),"%s/authfail.html",outdirname); @@ -153,23 +154,23 @@ void authfail_report(void) snprintf(csort,sizeof(csort),"sort -b -t \"\t\" -T \"%s\" -k 3,3 -k 5,5 -o \"%s\" \"%s\"", tmp, authfail_sort, authfail_unsort); cstatus=system(csort); if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) { - debuga(_("sort command return status %d\n"),WEXITSTATUS(cstatus)); - debuga(_("sort command: %s\n"),csort); + debuga(__FILE__,__LINE__,_("sort command return status %d\n"),WEXITSTATUS(cstatus)); + debuga(__FILE__,__LINE__,_("sort command: %s\n"),csort); exit(EXIT_FAILURE); } - if((fp_in=MY_FOPEN(authfail_sort,"r"))==NULL) { - debuga(_("Cannot open file \"%s\": %s\n"),authfail_sort,strerror(errno)); - debuga(_("sort command: %s\n"),csort); + if((fp_in=FileObject_Open(authfail_sort))==NULL) { + debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),authfail_sort,FileObject_GetLastOpenError()); + debuga(__FILE__,__LINE__,_("sort command: %s\n"),csort); exit(EXIT_FAILURE); } if (!KeepTempLog && unlink(authfail_unsort)) { - debuga(_("Cannot delete \"%s\": %s\n"),authfail_unsort,strerror(errno)); + debuga(__FILE__,__LINE__,_("Cannot delete \"%s\": %s\n"),authfail_unsort,strerror(errno)); exit(EXIT_FAILURE); } authfail_unsort[0]='\0'; if((fp_ou=MY_FOPEN(report,"w"))==NULL) { - debuga(_("Cannot open file \"%s\": %s\n"),report,strerror(errno)); + debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),report,strerror(errno)); exit(EXIT_FAILURE); } @@ -184,30 +185,30 @@ void authfail_report(void) fprintf(fp_ou,"%s%s%s%s\n",_("USERID"),_("IP/NAME"),_("DATE/TIME"),_("ACCESSED SITE")); if ((line=longline_create())==NULL) { - debuga(_("Not enough memory to read file \"%s\"\n"),authfail_sort); + debuga(__FILE__,__LINE__,_("Not enough memory to read file \"%s\"\n"),authfail_sort); exit(EXIT_FAILURE); } while((buf=longline_read(fp_in,line))!=NULL) { getword_start(&gwarea,buf); if (getword(data,sizeof(data),&gwarea,'\t')<0) { - debuga(_("Invalid date in file \"%s\"\n"),authfail_sort); + debuga(__FILE__,__LINE__,_("Invalid date in file \"%s\"\n"),authfail_sort); exit(EXIT_FAILURE); } if (getword(hora,sizeof(hora),&gwarea,'\t')<0) { - debuga(_("Invalid time in file \"%s\"\n"),authfail_sort); + debuga(__FILE__,__LINE__,_("Invalid time in file \"%s\"\n"),authfail_sort); exit(EXIT_FAILURE); } if (getword(user,sizeof(user),&gwarea,'\t')<0) { - debuga(_("Invalid user ID in file \"%s\"\n"),authfail_sort); + debuga(__FILE__,__LINE__,_("Invalid user ID in file \"%s\"\n"),authfail_sort); exit(EXIT_FAILURE); } if (getword(ip,sizeof(ip),&gwarea,'\t')<0) { - debuga(_("Invalid IP address in file \"%s\"\n"),authfail_sort); + debuga(__FILE__,__LINE__,_("Invalid IP address in file \"%s\"\n"),authfail_sort); exit(EXIT_FAILURE); } if (getword_ptr(buf,&url,&gwarea,'\t')<0) { - debuga(_("Invalid url in file \"%s\"\n"),authfail_sort); + debuga(__FILE__,__LINE__,_("Invalid url in file \"%s\"\n"),authfail_sort); exit(EXIT_FAILURE); } if (sscanf(data,"%d/%d/%d",&day,&month,&year)!=3) continue; @@ -216,7 +217,7 @@ void authfail_report(void) uinfo=userinfo_find_from_id(user); if (!uinfo) { - debuga(_("Unknown user ID %s in file \"%s\"\n"),user,authfail_sort); + debuga(__FILE__,__LINE__,_("Unknown user ID %s in file \"%s\"\n"),user,authfail_sort); exit(EXIT_FAILURE); } @@ -264,8 +265,8 @@ void authfail_report(void) output_html_link(fp_ou,url,100); fputs("\n",fp_ou); } - if (fclose(fp_in)==EOF) { - debuga(_("Read error in \"%s\": %s\n"),authfail_sort,strerror(errno)); + if (FileObject_Close(fp_in)) { + debuga(__FILE__,__LINE__,_("Read error in \"%s\": %s\n"),authfail_sort,FileObject_GetLastCloseError()); exit(EXIT_FAILURE); } longline_destroy(&line); @@ -276,12 +277,12 @@ void authfail_report(void) fputs("\n",fp_ou); write_html_trailer(fp_ou); if (fclose(fp_ou)==EOF) { - debuga(_("Write error in \"%s\": %s\n"),report,strerror(errno)); + debuga(__FILE__,__LINE__,_("Write error in \"%s\": %s\n"),report,strerror(errno)); exit(EXIT_FAILURE); } if (!KeepTempLog && unlink(authfail_sort)) { - debuga(_("Cannot delete \"%s\": %s\n"),authfail_sort,strerror(errno)); + debuga(__FILE__,__LINE__,_("Cannot delete \"%s\": %s\n"),authfail_sort,strerror(errno)); exit(EXIT_FAILURE); } @@ -295,13 +296,13 @@ void authfail_cleanup(void) { if (fp_authfail) { if (fclose(fp_authfail)==EOF) { - debuga(_("Write error in \"%s\": %s\n"),authfail_unsort,strerror(errno)); + debuga(__FILE__,__LINE__,_("Write error in \"%s\": %s\n"),authfail_unsort,strerror(errno)); exit(EXIT_FAILURE); } fp_authfail=NULL; } if(authfail_unsort[0]) { if (!KeepTempLog && unlink(authfail_unsort)==-1) - debuga(_("Failed to delete \"%s\": %s\n"),authfail_unsort,strerror(errno)); + debuga(__FILE__,__LINE__,_("Failed to delete \"%s\": %s\n"),authfail_unsort,strerror(errno)); } }