Re: [courier-users] pythonfitler and unix socket

This is a discussion on Re: [courier-users] pythonfitler and unix socket within the Courier-Imap forums, part of the Mail Servers and Related category; This is a multi-part message in MIME format. --------------050807000506040508010209 Content-Type: text/plain; charset=ISO-8859-1; format=flowed ...


Go Back   Usenet Forums > Mail Servers and Related > Courier-Imap

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-04-2008
Jérôme Blion
 
Posts: n/a
Default Re: [courier-users] pythonfitler and unix socket

This is a multi-part message in MIME format.
--------------050807000506040508010209
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8bit

FM a écrit :
> Hello everybody,
>
> To force pythonfilter to use the clamd and clamd.conf config , I remove
> pyclamav.so.
>
> in clamd.conf I have :
> LocalSocket /var/run/clamav/clamd.sock
>
> but I receive these error from pythonfilter :
> (...)
> Jan 4 10:40:20 verona courierfilter: Uncaught exception in "clamav"
> doFilter function: ScanError:Could not reach clamd using unix socket
> (/var/run/clamd)
> Jan 4 10:40:20 verona courierfilter: File
> "/etc/courier/filters/active/pythonfilter", line 194, in processMessage
> Jan 4 10:40:20 verona courierfilter: replyCode = i_filter[1](bodyFile,
> controlFileList)
> Jan 4 10:40:20 verona courierfilter: File
> "/usr/lib/python2.2/site-packages/pythonfilter/clamav.py", line 50, in
> doFilter
> Jan 4 10:40:20 verona courierfilter: return scanMessage(bodyFile)
> Jan 4 10:40:20 verona courierfilter: File
> "/usr/lib/python2.2/site-packages/pythonfilter/clamav.py", line 35, in
> scanMessage
> Jan 4 10:40:20 verona courierfilter: pyclamd.init_unix_socket()
> Jan 4 10:40:20 verona courierfilter: File
> "/usr/lib/python2.2/site-packages/pyclamd.py", line 111, in init_unix_socket
> Jan 4 10:40:20 verona courierfilter: ping()
> Jan 4 10:40:20 verona courierfilter: File
> "/usr/lib/python2.2/site-packages/pyclamd.py", line 167, in ping
> Jan 4 10:40:20 verona courierfilter: s = __init_socket__()
> Jan 4 10:40:20 verona courierfilter: File
> "/usr/lib/python2.2/site-packages/pyclamd.py", line 414, in __init_socket__
> Jan 4 10:40:20 verona courierfilter: raise ScanError, 'Could not reach
> clamd using unix socket (%s)' % (clamd_SOCKET)
> (...)
>
> Is there a way to set the unix socket to /var/run/clamav/clamd.sock
> instead of /var/run/clamd ?
>
> Regards,
>
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2005.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> _______________________________________________
> courier-users mailing list
> courier-users@lists.sourceforge.net
> Unsubscribe: https://lists.sourceforge.net/lists/.../courier-users
>

Which pythonfilter do you use ?
With 1.0, I posted a message some days ago...
Here is a version which allow to use a specific socket...

You have to modify /etc/pythonfilter-modules.conf

Add:

[clamav.py]
LocalSocket = '/var/run/clamav/clamd.sock'

HTH.
Jerome Blion.



--------------050807000506040508010209
Content-Type: text/plain;
name="clamav.py"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="clamav.py"

#!/usr/bin/python
# clamav -- Courier filter which scans messages with ClamAV
# Copyright (C) 2004 Robert Penz <robert@penz.name>
# Copyright (C) 2007 Gordon Messmer <gordon@dragonsdawn.net>
# Copyright (C) 2008 Jerome Blion <jerome@hebergement-pro.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

import sys
import courier.config

LocalSocket = ''

try:
import pyclamav
def scanMessage(bodyFile):
try:
avresult = pyclamav.scanfile(bodyFile)
except Exception, e:
return "554 " + str(e)
if avresult[0]:
return "554 Virus found - Signature is %s" % avresult[1]
return ''
except ImportError:
import pyclamd
def scanMessage(bodyFile):
try:
pyclamd.init_unix_socket(LocalSocket)
avresult = pyclamd.scan_file(bodyFile)
except Exception, e:
return "554 " + str(e)
if avresult != None and avresult.has_key(bodyFile):
return "554 Virus found - Signature is %s" % avresult[bodyFile]
return ''


def initFilter():
courier.config.applyModuleConfig('clamav.py', globals())

# Record in the system log that this filter was initialized.
sys.stderr.write('Initialized the "clamav" python filter\n')

def doFilter(bodyFile, controlFileList):
return scanMessage(bodyFile)


if __name__ == '__main__':
# we only work with 1 parameter
if len(sys.argv) != 2:
print "Usage: clamav.py <message_body_file>"
sys.exit(0)
initFilter()
print doFilter(sys.argv[1], "")

--------------050807000506040508010209
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
--------------050807000506040508010209
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
courier-users mailing list
courier-users@lists.sourceforge.net
Unsubscribe: https://lists.sourceforge.net/lists/.../courier-users

--------------050807000506040508010209--


Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 10:14 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0