Content¶
Parts of the module can be divided into two subcategories - script and API.

Standalone script¶
Script can be found in bin/ folder and it should be automatically put into your path, so you can just simply run edeposit_clamd_init.py from shell.
Initializer script¶
Initialization script used to set necessary settings in ClamAV configuration file and correct permissions.
- edeposit_clamd_init.REQUIRED_SETTINGS = {'MaxThreads': '2', 'LocalSocket': '/var/run/clamav/clamd.ctl', 'AllowSupplementaryGroups': 'true', 'ScanPE': 'true', 'FixStaleSocket': 'true', 'ReadTimeout': '180', 'LocalSocketMode': '666', 'LocalSocketGroup': '$groupname', 'ScanArchive': 'true', 'LogRotate': 'true', 'LogSyslog': 'false', 'User': '$username', 'LogTime': 'true', 'MaxConnectionQueueLength': '3', 'ScanELF': 'true', 'LogFile': '/var/log/clamav/clamav.log', 'PidFile': '/var/run/clamav/clamd.pid'}¶
All required settings is there, rest is not important.
- edeposit_clamd_init.update_configuration(configuration)[source]¶
Set all configuration specified in REQUIRED_SETTINGS.
Parameters: configuration (str) – Configuration file content. Returns: Updated configuration. Return type: str
- edeposit_clamd_init.create_config(cnf_file, uid, overwrite)[source]¶
Creates configuration file and the directory where it should be stored and set correct permissions.
Parameters:
- edeposit_clamd_init.create_log(log_file, uid)[source]¶
Create log file and set necessary permissions.
Parameters:
- edeposit_clamd_init.get_service_name()[source]¶
Return name of the daemon depending on the system type.
- edeposit_clamd_init.main(*args, **kwargs)[source]¶
Create configuration and log file. Restart the daemon when configuration is done.
Parameters:
Usage¶
$ ./edeposit_clamd_init.py -h
usage: edeposit_clamd_init.py [-h] [-v] [-o] [-c CONFIG]
edeposit.amqp.antivirus ClamAV initializer.
optional arguments:
-h, --help show this help message and exit
-v, --verbose Print logging messages.
-o, --overwrite Overwrite default configuration file. Don't worry,
your original file will be stored in backup_.
-c CONFIG, --config CONFIG
Path to the configuration file. Default
/etc/clamav/clamd.conf.
API¶
antivirus package¶
There are two levels of abstraction - AMPQ API and python API.
AQMP API is higlevel API, where you send some structure, something happens in magick box and you get back another structure.
Python API is just collection of “lowlevel” python wrappers over ClamAV.
AMQP API¶
AMQP interface used by edeposit.amqp package.
- antivirus.reactToAMQPMessage(message, send_back)[source]¶
React to given (AMQP) message. message is expected to be collections.namedtuple() structure from structures filled with all necessary data.
Parameters: - message (object) – One of the request objects defined in structures.
- send_back (fn reference) – Reference to function for responding. This is useful for progress monitoring for example. Function takes one parameter, which may be response structure/namedtuple, or string or whatever would be normally returned.
Returns: Response class from structures.
Return type: object
Raises: ValueError – if bad type of message structure is given.
All AMQP communication structures can be found in structures submodule.

Python API¶
Antivirus wrapper¶
ClamAV wrapper to scan files for malware.
- antivirus.antivirus.scan_file(path)[source]¶
Scan path for viruses using clamd or clamscan (depends on settings.USE_CLAMD.
Parameters: path (str) – Relative or absolute path of file/directory you need to scan.
Returns: {filename: ("FOUND", "virus type")} or blank dict.
Return type: dict
Raises: - ValueError – When the server is not running.
- AssertionError – When the internal file doesn’t exists.
Wrappers¶
This package contains lowlevel wrappers over clamd, clamscan and freshclam.
API for scanning files using clamd daemon.
- antivirus.wrappers.clamd.scan_file(path)[source]¶
Scan path for viruses using clamd antivirus daemon.
Parameters: path (str) – Relative or absolute path of file/directory you need to scan.
Returns: {filename: ("FOUND", "virus type")} or blank dict.
Return type: dict
Raises: - ValueError – When the server is not running.
- AssertionError – When the internal file doesn’t exists.
API for scanning files using clamscan standalone program.
- antivirus.wrappers.clamscan.scan_file(path)[source]¶
Scan path for viruses using clamscan program.
Parameters: path (str) – Relative or absolute path of file/directory you need to scan. Returns: {filename: ("FOUND", "virus type")} or blank dict. Return type: dict Raises: AssertionError – When the internal file doesn’t exists.
API for scanning files using clamd daemon.
- antivirus.wrappers.clamd.scan_file(path)[source]¶
Scan path for viruses using clamd antivirus daemon.
Parameters: path (str) – Relative or absolute path of file/directory you need to scan.
Returns: {filename: ("FOUND", "virus type")} or blank dict.
Return type: dict
Raises: - ValueError – When the server is not running.
- AssertionError – When the internal file doesn’t exists.
API for scanning files using clamscan standalone program.
- antivirus.wrappers.clamscan.scan_file(path)[source]¶
Scan path for viruses using clamscan program.
Parameters: path (str) – Relative or absolute path of file/directory you need to scan. Returns: {filename: ("FOUND", "virus type")} or blank dict. Return type: dict Raises: AssertionError – When the internal file doesn’t exists.
Antivirus wrapper¶
ClamAV wrapper to scan files for malware.
- antivirus.antivirus.scan_file(path)[source]¶
Scan path for viruses using clamd or clamscan (depends on settings.USE_CLAMD.
Parameters: path (str) – Relative or absolute path of file/directory you need to scan.
Returns: {filename: ("FOUND", "virus type")} or blank dict.
Return type: dict
Raises: - ValueError – When the server is not running.
- AssertionError – When the internal file doesn’t exists.
AMQP communication structures¶
Definitions of the communication structures used in edeposit.amqp.antivirus project.
- class antivirus.structures.ScanFile[source]¶
Bases: antivirus.structures.ScanFile
Request to scan file.
Parameters: Returns: Return type: object
- class antivirus.structures.UpdateDatabase[source]¶
Bases: antivirus.structures.UpdateDatabase
Request to update clamav database (= to run freshclam program).
Returns: DatabaseUpdated Return type: object
- class antivirus.structures.ScanResult[source]¶
Bases: antivirus.structures.ScanResult
Result of the file scan.
Parameters: { "local_path": ("RESULT", "TYPE") }
Where RESULT is “FOUND” or string like that and TYPE is name of the malware.
Note
When no malware is found, result is blank dict.
- class antivirus.structures.DatabaseUpdated[source]¶
Bases: antivirus.structures.DatabaseUpdated
Response to UpdateDatabase.
- Attr:
- log (str): Log of the freshclam run.
Settings and configuration¶
Module is containing all necessary global variables for the package.
Module also has the ability to read user-defined data from two paths:
- $HOME/_SETTINGS_PATH
- /etc/_SETTINGS_PATH
See _SETTINGS_PATH for details.
Note
If the first path is found, other is ignored.
Example of the configuration file ($HOME/edeposit/antivirus.json):
{
"USE_CLAMD": false
}
Attributes¶
- antivirus.settings.is_deb_system()[source]¶
Badly written test whether the system is deb/apt based or not.
- antivirus.settings.USE_CLAMD = True¶
True - clamd daemon will be used, False - clamscan will be used. clamscan takes much less memory, but takes a LOT more time to scan. clamd takes huge amouts of memory (500MB min), but scans in fractions of seconds.
- antivirus.settings.DEB_CONF_PATH = '/etc/clamav/'¶
Configuration file directory at debian systems.
- antivirus.settings.SUSE_CONF_PATH = '/etc/'¶
Configuration file directory at suse systems.
- antivirus.settings.CONF_FILE = 'clamd.conf'¶
Name of the configuration file.
- antivirus.settings.CONF_PATH = '/etc/clamav/clamd.conf'¶
Path to the configuration file.
- antivirus.settings.LOCALSOCKET = '/var/run/clamav/clamd.ctl'¶
Path to the local unix socket - don’t change this if you are not sure (it will break things).
- antivirus.settings.PIDFILE = '/var/run/clamav/clamd.pid'¶
Path to the pid file - don’t change this if you are not sure (it will break things).
- antivirus.settings.LOGFILE = '/var/log/clamav/clamav.log'¶
Path to the log file.
- antivirus.settings.get_all_constants()[source]¶
Get list of all uppercase, non-private globals (doesn’t start with _).
Returns: Uppercase names defined in globals() (variables from this module). Return type: list
- antivirus.settings.substitute_globals(config_dict)[source]¶
Set global variables to values defined in config_dict.
Parameters: config_dict (dict) – dictionary with data, which are used to set globals. Note
config_dict have to be dictionary, or it is ignored. Also all variables, that are not already in globals, or are not types defined in _ALLOWED (str, int, float) or starts with _ are silently ignored.
wrappers package¶
This package contains lowlevel wrappers over clamd, clamscan and freshclam.
Submodules¶
clamd wrapper¶
API for scanning files using clamd daemon.
- antivirus.wrappers.clamd.scan_file(path)[source]¶
Scan path for viruses using clamd antivirus daemon.
Parameters: path (str) – Relative or absolute path of file/directory you need to scan.
Returns: {filename: ("FOUND", "virus type")} or blank dict.
Return type: dict
Raises: - ValueError – When the server is not running.
- AssertionError – When the internal file doesn’t exists.
clamscan wrapper¶
API for scanning files using clamscan standalone program.
- antivirus.wrappers.clamscan.scan_file(path)[source]¶
Scan path for viruses using clamscan program.
Parameters: path (str) – Relative or absolute path of file/directory you need to scan. Returns: {filename: ("FOUND", "virus type")} or blank dict. Return type: dict Raises: AssertionError – When the internal file doesn’t exists.