1
// This program is free software; you can redistribute it and/or modify
2
// it under the terms of the GNU General Public License as published by
3
// the Free Software Foundation; either version 2 of the License, or
4
// (at your option) any later version.
6
// This program is distributed in the hope that it will be useful,
7
// but WITHOUT ANY WARRANTY; without even the implied warranty of
8
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9
// GNU General Public License for more details.
11
// You should have received a copy of the GNU General Public License
12
// along with this program; if not, write to the Free Software
13
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
// based on exim/exiscan patch by Tom Kistner.
19
#include "KAVScan.hpp"
22
extern OptionContainer o;
26
KAV5Engine::KAV5Engine ()
31
KAV5Engine::~KAV5Engine ()
37
KAV5Engine::scanFile (const char *_fname)
40
int infected = AV_CLEAN;
41
struct sockaddr_un server;
44
cout << "Entering KAV5Engine scanFile" << endl;
45
cout << "Before connect" << endl;
48
//open the aveserver socket
49
sock = socket (AF_UNIX, SOCK_STREAM, 0);
53
cout << "socket creation failed" << endl;
55
setErrString ("socket creation failed");
59
server.sun_family = AF_UNIX;
60
strcpy (server.sun_path, o.avesocket.c_str ());
61
if (connect (sock, (struct sockaddr *) &server, sizeof (struct sockaddr_un)) < 0)
65
cout << "socket connect failed" << endl;
67
setErrString ("socket connect failed");
71
/* read aveserver's greeting and see if it is ready (2xx greeting) */
73
recv_line (sock, buf, sizeof (buf));
77
/* aveserver is having problems */
80
cout << "aveserver is unavailable (returned: " << ((buf[0] != 0) ? buf : (char *) "nothing") << ")" << endl;
82
setErrString ("aveserver is unavailable");
86
/* prepare our command */
87
snprintf (buf, 32768, "SCAN bPQRSTUW %s\r\n", _fname);
90
if (send (sock, buf, strlen (buf), 0) < 0)
94
cout << "unable to write to aveserver socket (" << o.avesocket << ")" << endl;
96
setErrString ("unable to write to aveserver socket");
100
/* read response lines, find malware name and final response */
101
while (recv_line (sock, buf, 32768) > 0)
104
cout << "aveserver response: " << buf << endl;
108
if (strncmp (buf, "322", 3) == 0)
110
char *p = strchr (&buf[4], ' ');
112
setVirusName (&buf[4]);
121
/* simple wrapper for reading lines from sockets */
123
KAV5Engine::recv_line (int _sock, char *_buf, int _size)
128
memset (_buf, 0, _size);
131
while (recv (_sock, p, 1, 0) > -1)
133
if ((p - _buf) > (_size - 2))