| 1 |
// Defines the class interface to be implemented by ContentScanner plugins |
| 2 |
|
| 3 |
// For all support, instructions and copyright go to: |
| 4 |
// http://e2guardian.org/ |
| 5 |
// Released under the GPL v2, with the OpenSSL exception described in the README file. |
| 6 |
|
| 7 |
#ifndef __HPP_CONTENTSCANNER |
| 8 |
#define __HPP_CONTENTSCANNER |
| 9 |
|
| 10 |
// INCLUDES |
| 11 |
#include "NaughtyFilter.hpp" |
| 12 |
#include "String.hpp" |
| 13 |
#include "ConfigVar.hpp" |
| 14 |
#include "DataBuffer.hpp" |
| 15 |
#include "Socket.hpp" |
| 16 |
#include "HTTPHeader.hpp" |
| 17 |
#include "ListContainer.hpp" |
| 18 |
#include "Plugin.hpp" |
| 19 |
#include <stdexcept> |
| 20 |
|
| 21 |
// DEFINES |
| 22 |
#define E2CS_OK 0 |
| 23 |
#define E2CS_ERROR -1 |
| 24 |
#define E2CS_WARNING 3 |
| 25 |
|
| 26 |
#define E2CS_NOSCAN 0 |
| 27 |
#define E2CS_NEEDSCAN 1 |
| 28 |
#define E2CS_TESTERROR -1 |
| 29 |
|
| 30 |
#define E2CS_CLEAN 0 |
| 31 |
#define E2CS_SCANERROR -1 |
| 32 |
#define E2CS_INFECTED 1 |
| 33 |
//#define E2CS_CURED 2 // not used |
| 34 |
#define E2CS_BLOCKED 4 |
| 35 |
#define E2CS_MAX 5 // use values above this for custom return codes |
| 36 |
|
| 37 |
// DECLARATIONS |
| 38 |
|
| 39 |
class CSPlugin; |
| 40 |
|
| 41 |
// class factory functions for CS plugins |
| 42 |
typedef CSPlugin *cscreate_t(ConfigVar &); |
| 43 |
|
| 44 |
// CS plugin interface proper - to be implemented by plugins themselves |
| 45 |
class CSPlugin : public Plugin |
| 46 |
{ |
| 47 |
public: |
| 48 |
//constructor with CS plugin configuration passed in |
| 49 |
CSPlugin(ConfigVar &definition); |
| 50 |
|
| 51 |
virtual ~CSPlugin(){}; |
| 52 |
|
| 53 |
// Test for whether or nor a particular ContentScanner is likely to be interested |
| 54 |
// in scanning data associated with the given HTTP request. If "post" is true, |
| 55 |
// the data which will be scanned is outgoing (i.e. POST requests - file uploads & |
| 56 |
// form submissions). If "reconstituted" is true, the data which will be passed |
| 57 |
// in is not exactly as it appeared in the request (i.e. URL-encoded form data, |
| 58 |
// but with form control names and URL encoding stripped away to leave a single |
| 59 |
// block of text). |
| 60 |
virtual int willScanRequest(const String &url, const char *user, FOptionContainer* &foc, |
| 61 |
const char *ip, bool post, bool reconstituted, bool exception, bool bypass); |
| 62 |
|
| 63 |
// Test whether, in addition to the above, a particular ContentScanner is actually |
| 64 |
// interested in the data we have for it. This is split into a separate function |
| 65 |
// because, for incoming data (as opposed to POST data), we do not have the |
| 66 |
// information necessary for this test until the response has been received. |
| 67 |
// Content disposition & MIME type will be empty if not available, and size will be -1 if |
| 68 |
// not known. |
| 69 |
// Will not be called for request/response data where willScanRequest previously |
| 70 |
// returned false. |
| 71 |
virtual int willScanData(const String &url, const char *user, FOptionContainer* &foc, const char *ip, |
| 72 |
bool post, bool reconstituted, bool exception, bool bypass, const String &disposition, |
| 73 |
const String &mimetype, off_t size); |
| 74 |
|
| 75 |
// scanning functions themselves |
| 76 |
// docheader will be NULL if the data is from a POST request, rather than a response |
| 77 |
// disposition & MIME type may be NULL or empty strings, in which case docheader should be checked for them (if it is not NULL itself) |
| 78 |
virtual int scanMemory(HTTPHeader *requestheader, HTTPHeader *docheader, const char *user,FOptionContainer* &foc , const char *ip, |
| 79 |
const char *object, unsigned int objectsize, NaughtyFilter *checkme, const String *disposition = NULL, const String *mimetype = NULL); |
| 80 |
virtual int scanFile(HTTPHeader *requestheader, HTTPHeader *docheader, const char *user, FOptionContainer* &foc , const char *ip, |
| 81 |
const char *filename, NaughtyFilter *checkme, const String *disposition = NULL, const String *mimetype = NULL) |
| 82 |
= 0; |
| 83 |
|
| 84 |
const String &getLastMessage() |
| 85 |
{ |
| 86 |
return lastmessage; |
| 87 |
}; |
| 88 |
const String &getLastVirusName() |
| 89 |
{ |
| 90 |
return lastvirusname; |
| 91 |
}; |
| 92 |
|
| 93 |
// start, restart and stop the plugin |
| 94 |
virtual int init(void *args); |
| 95 |
virtual int quit() |
| 96 |
{ |
| 97 |
return E2CS_OK; |
| 98 |
}; |
| 99 |
|
| 100 |
private: |
| 101 |
// lists of all the various things we may not want to scan |
| 102 |
// ListContainer exceptionvirusmimetypelist; |
| 103 |
// ListContainer exceptionvirusextensionlist; |
| 104 |
// ListContainer exceptionvirussitelist; |
| 105 |
// ListContainer exceptionvirusurllist; |
| 106 |
|
| 107 |
protected: |
| 108 |
ConfigVar cv; |
| 109 |
String lastmessage; |
| 110 |
String lastvirusname; |
| 111 |
|
| 112 |
// whether or not to AV scan POST uploads |
| 113 |
bool scanpost; |
| 114 |
|
| 115 |
void blockFile(std::string *_category, std::string *_message, NaughtyFilter *checkme); |
| 116 |
|
| 117 |
// read in scan exception lists |
| 118 |
bool readStandardLists(); |
| 119 |
// make & write to temp files, primarily for plugins with no direct memory scanning capability (e.g. clamdscan) |
| 120 |
int makeTempFile(String *filename); |
| 121 |
int writeMemoryTempFile(const char *object, unsigned int objectsize, String *filename); |
| 122 |
}; |
| 123 |
|
| 124 |
// Return an instance of the plugin defined in the given configuration file |
| 125 |
CSPlugin *cs_plugin_load(const char *pluginConfigPath); |
| 126 |
|
| 127 |
#endif |