Skip to content
Snippets Groups Projects
Commit 249763e8 authored by Andreas Romeyke's avatar Andreas Romeyke
Browse files

- added support to getAgent()

parent f46982d0
No related branches found
No related tags found
No related merge requests found
...@@ -40,6 +40,7 @@ public class SLUBVirusCheckClamAVPlugin implements VirusCheckPlugin { ...@@ -40,6 +40,7 @@ public class SLUBVirusCheckClamAVPlugin implements VirusCheckPlugin {
//private static final ExLogger log = ExLogger.getExLogger(SLUBVirusCheckClamAVPlugin.class); //private static final ExLogger log = ExLogger.getExLogger(SLUBVirusCheckClamAVPlugin.class);
private static final int DEFAULT_CHUNK_SIZE = 2048; private static final int DEFAULT_CHUNK_SIZE = 2048;
private static final byte[] INSTREAM = "zINSTREAM\0".getBytes(); private static final byte[] INSTREAM = "zINSTREAM\0".getBytes();
private static final byte[] VERSION = "zVERSION\0".getBytes();
private static final String RESPONSEOK = "stream: OK"; private static final String RESPONSEOK = "stream: OK";
private static final String FOUND_SUFFIX = "FOUND"; private static final String FOUND_SUFFIX = "FOUND";
private static final String STREAM_PREFIX = "stream: "; private static final String STREAM_PREFIX = "stream: ";
...@@ -144,7 +145,45 @@ public class SLUBVirusCheckClamAVPlugin implements VirusCheckPlugin { ...@@ -144,7 +145,45 @@ public class SLUBVirusCheckClamAVPlugin implements VirusCheckPlugin {
} }
public String getAgent () { public String getAgent () {
return "clamd"; try {
// create a socket
Socket socket = new Socket ();
//socket.connect( new InetSocketAddress(getHost()));
socket.connect( new InetSocketAddress(getHost(), getPort()));
try {
socket.setSoTimeout( getTimeOut() );
} catch (SocketException e) {
System.out.println( "Could not set socket timeout to " + getTimeOut() + "ms " + e);
//log.error( "Could not set socket timeout to " + getTimeOut() + "ms", e);
}
DataOutputStream dos = null;
response = "";
try {
dos = new DataOutputStream(socket.getOutputStream());
dos.write(VERSION);
int read;
byte[] buffer = new byte[DEFAULT_CHUNK_SIZE];
dos.flush();
read = socket.getInputStream().read(buffer);
if (read > 0) response = new String(buffer, 0, read);
} finally {
if (dos != null) try { dos.close(); } catch (IOException e) {
// log.debug("exception closing DOS", e);
System.out.println( "exception closing DOS "+ e );
}
try { socket.close(); } catch (IOException e) {
// log.debug("exception closing socket", e);
System.out.println( "exception closing socket "+ e);
}
}
return response;
} catch (IOException e) {
//log.error("exception creation socket, clamd not available at host=" + host + "port=" + port, e);
System.out.println ("exception creation socket, clamd not available at host=" + host + "port=" + port + " " + e);
setStatus(Status.FAILED);
setSignature("ERROR: clamd not available");
return "ERROR: clamd not available";
}
} }
public boolean isVirusFree() { public boolean isVirusFree() {
...@@ -155,6 +194,7 @@ public class SLUBVirusCheckClamAVPlugin implements VirusCheckPlugin { ...@@ -155,6 +194,7 @@ public class SLUBVirusCheckClamAVPlugin implements VirusCheckPlugin {
// stand alone check // stand alone check
public static void main(String [] args) { public static void main(String [] args) {
SLUBVirusCheckClamAVPlugin plugin = new SLUBVirusCheckClamAVPlugin( "127.0.0.1", 3310, 60); SLUBVirusCheckClamAVPlugin plugin = new SLUBVirusCheckClamAVPlugin( "127.0.0.1", 3310, 60);
System.out.println("Agent: "+ plugin.getAgent() );
for (String file:args) { for (String file:args) {
plugin.scan( file ); plugin.scan( file );
System.out.println("RESULT: " + plugin.isVirusFree() + " SIGNATURE: " + plugin.getOutput()); System.out.println("RESULT: " + plugin.isVirusFree() + " SIGNATURE: " + plugin.getOutput());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment