I've been reading over your API docs and I have some questions about cl_scanbuff. What I'm doing is creating a pop3 email proxy scanner for OpenBSD. I've got things working where it scans the messages when I go to retrieve them, but things "freeze/hang" when I send a virus message through. Any help would be appreciated, here is my code:
#include "pop3-gw.h" #include <clamav.h>
void relay_data(int first_filedes, int second_filedes, int maxwait, int *in, int *out) {
fd_set master, copy;
struct timeval deadline;
int logged_in = TRUE;
unsigned int count;
char buf[MAX_IO_LEN];
/* new stuff for antivirus */
int fd, ret, no = 0;
struct cl_node *root = NULL;
const char **virname;
/* end new stuff for antivirus */
FD_ZERO(&master);
FD_SET(first_filedes, &master);
FD_SET(second_filedes, &master); /* other things added for antivirus stuff */
// load up your non-antivirus PC definition databases
if ((ret = cl_loaddbdir(cl_retdbdir(), &root, &no))) {
printf("cl_loaddbdir: %s\n", cl_perror(ret));
close(fd);
exit(2);
}
// Build the final trie... per the docs, dunno what the hell this is
if((ret = cl_buildtrie(root)))
printf("cl_buildtrie() error: %s\n", cl_strerror(ret));
/* end of other things added for antivirus stuff */
while (logged_in == TRUE) {
syslog(LOG_PRIO, "ANYTHING");
memcpy(©, &master, sizeof(fd_set)); /* select() trashes copy */
deadline.tv_sec = maxwait;
deadline.tv_usec = 0;
if (select(MAX(first_filedes, second_filedes)+1, ©, (fd_set *)NULL, (fd_set *)NULL, &deadline) <= 0) {
#ifdef DEBUG
syslog(LOG_PRIO, "Network timeout signal after %d seconds while relaying data", maxwait);
#endif
logged_in = FALSE;
}
else {
if (FD_ISSET(first_filedes, ©)) {
if ((count = read(first_filedes, buf, sizeof(buf))) <= 0)
logged_in = FALSE;
else
if (writen(second_filedes, buf, count, maxwait) == count)
(*out) += count;
else
logged_in = FALSE;
}
if (FD_ISSET(second_filedes, ©) && logged_in == TRUE) {
if ((count = read(second_filedes, buf, sizeof(buf))) <= 0)
logged_in = FALSE;
else {
/* Virus Scanning Section */
syslog(LOG_PRIO, "Just scanning for virus");
if ((ret = cl_scanbuff(buf, count, virname, root)) == CL_VIRUS)
syslog(LOG_PRIO, "OHMYGO you've got a virus!");
else if (ret == CL_CLEAN) {
syslog(LOG_PRIO, "No sassypool for viruses found");
}
else {
syslog(LOG_PRIO, "We're screwed");
}
/* End Virus Scanning Stuff */
if (writen(first_filedes, buf, count, maxwait) == count)
(*in) += count;
else
logged_in = FALSE;
}
}
}
}
}
Thanks again, Brandon
------------------------------------------------------- This SF.Net email is sponsored by The 2004 JavaOne(SM) Conference Learn from the experts at JavaOne(SM), Sun's Worldwide Java Developer Conference, June 28 - July 1 at the Moscone Center in San Francisco, CA REGISTER AND SAVE! http://java.sun.com/javaone/sf Priority Code NWMGYKND _______________________________________________ Clamav-devel mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/clamav-devel
