From 072caae0c9ef2d289be96a16f05c60af658ecfe6 Mon Sep 17 00:00:00 2001 From: SJ Date: Wed, 23 Nov 2011 12:24:21 +0100 Subject: [PATCH] 0.1.7 fixes --- contrib/README | 1 + contrib/mime/mime.types | 688 ++++++++++++++++++++++++++++++++++++++++ src/Makefile.in | 10 +- src/attachment.c | 61 +++- src/config.h | 2 +- src/defs.h | 4 + src/message.c | 12 +- src/parser.c | 21 +- src/rules.c | 56 +++- src/rules.h | 7 +- src/session.c | 4 +- src/test.c | 4 +- util/db-mysql.sql | 8 +- 13 files changed, 842 insertions(+), 36 deletions(-) create mode 100644 contrib/README create mode 100644 contrib/mime/mime.types diff --git a/contrib/README b/contrib/README new file mode 100644 index 00000000..6116c75b --- /dev/null +++ b/contrib/README @@ -0,0 +1 @@ +mime/mime.types: MIME types from the apache 2.2.x distribution diff --git a/contrib/mime/mime.types b/contrib/mime/mime.types new file mode 100644 index 00000000..9c714726 --- /dev/null +++ b/contrib/mime/mime.types @@ -0,0 +1,688 @@ +application/andrew-inset +application/applixware +application/atom+xml +application/atomcat+xml +application/atomsvc+xml +application/ccxml+xml +application/cdmi-capability +application/cdmi-container +application/cdmi-domain +application/cdmi-object +application/cdmi-queue +application/cu-seeme +application/davmount+xml +application/dssc+der +application/dssc+xml +application/ecmascript +application/emma+xml +application/epub+zip +application/exi +application/font-tdpfr +application/hyperstudio +application/ipfix +application/java-archive +application/java-serialized-object +application/java-vm +application/javascript +application/json +application/lost+xml +application/mac-binhex40 +application/mac-compactpro +application/mads+xml +application/marc +application/marcxml+xml +application/mathematica +application/mathml+xml +application/mbox +application/mediaservercontrol+xml +application/metalink4+xml +application/mets+xml +application/mods+xml +application/mp21 +application/mp4 +application/msword +application/mxf +application/octet-stream +application/oda +application/oebps-package+xml +application/ogg +application/onenote +application/patch-ops-error+xml +application/pdf +application/pgp-encrypted +application/pgp-signature +application/pics-rules +application/pkcs10 +application/pkcs7-mime +application/pkcs7-signature +application/pkcs8 +application/pkix-attr-cert +application/pkix-cert +application/pkix-crl +application/pkix-pkipath +application/pkixcmp +application/pls+xml +application/postscript +application/prs.cww +application/pskc+xml +application/rdf+xml +application/reginfo+xml +application/relax-ng-compact-syntax +application/resource-lists+xml +application/resource-lists-diff+xml +application/rls-services+xml +application/rsd+xml +application/rss+xml +application/rtf +application/sbml+xml +application/scvp-cv-request +application/scvp-cv-response +application/scvp-vp-request +application/scvp-vp-response +application/sdp +application/set-payment-initiation +application/set-registration-initiation +application/shf+xml +application/smil+xml +application/sparql-query +application/sparql-results+xml +application/srgs +application/srgs+xml +application/sru+xml +application/ssml+xml +application/tei+xml +application/thraud+xml +application/timestamped-data +application/vnd.3gpp.pic-bw-large +application/vnd.3gpp.pic-bw-small +application/vnd.3gpp.pic-bw-var +application/vnd.3gpp2.tcap +application/vnd.3m.post-it-notes +application/vnd.accpac.simply.aso +application/vnd.accpac.simply.imp +application/vnd.acucobol +application/vnd.acucorp +application/vnd.adobe.air-application-installer-package+zip +application/vnd.adobe.fxp +application/vnd.adobe.xdp+xml +application/vnd.adobe.xfdf +application/vnd.ahead.space +application/vnd.airzip.filesecure.azf +application/vnd.airzip.filesecure.azs +application/vnd.amazon.ebook +application/vnd.americandynamics.acc +application/vnd.amiga.ami +application/vnd.android.package-archive +application/vnd.anser-web-certificate-issue-initiation +application/vnd.anser-web-funds-transfer-initiation +application/vnd.antix.game-component +application/vnd.apple.installer+xml +application/vnd.apple.mpegurl +application/vnd.aristanetworks.swi +application/vnd.audiograph +application/vnd.blueice.multipass +application/vnd.bmi +application/vnd.businessobjects +application/vnd.chemdraw+xml +application/vnd.chipnuts.karaoke-mmd +application/vnd.cinderella +application/vnd.claymore +application/vnd.cloanto.rp9 +application/vnd.clonk.c4group +application/vnd.cluetrust.cartomobile-config +application/vnd.cluetrust.cartomobile-config-pkg +application/vnd.commonspace +application/vnd.contact.cmsg +application/vnd.cosmocaller +application/vnd.crick.clicker +application/vnd.crick.clicker.keyboard +application/vnd.crick.clicker.palette +application/vnd.crick.clicker.template +application/vnd.crick.clicker.wordbank +application/vnd.criticaltools.wbs+xml +application/vnd.ctc-posml +application/vnd.cups-ppd +application/vnd.curl.car +application/vnd.curl.pcurl +application/vnd.data-vision.rdz +application/vnd.dece.data +application/vnd.dece.ttml+xml +application/vnd.dece.unspecified +application/vnd.denovo.fcselayout-link +application/vnd.dna +application/vnd.dolby.mlp +application/vnd.dpgraph +application/vnd.dreamfactory +application/vnd.dvb.ait +application/vnd.dvb.service +application/vnd.dynageo +application/vnd.ecowin.chart +application/vnd.enliven +application/vnd.epson.esf +application/vnd.epson.msf +application/vnd.epson.quickanime +application/vnd.epson.salt +application/vnd.epson.ssf +application/vnd.eszigno3+xml +application/vnd.ezpix-album +application/vnd.ezpix-package +application/vnd.fdf +application/vnd.fdsn.mseed +application/vnd.fdsn.seed +application/vnd.flographit +application/vnd.fluxtime.clip +application/vnd.framemaker +application/vnd.frogans.fnc +application/vnd.frogans.ltf +application/vnd.fsc.weblaunch +application/vnd.fujitsu.oasys +application/vnd.fujitsu.oasys2 +application/vnd.fujitsu.oasys3 +application/vnd.fujitsu.oasysgp +application/vnd.fujitsu.oasysprs +application/vnd.fujixerox.ddd +application/vnd.fujixerox.docuworks +application/vnd.fujixerox.docuworks.binder +application/vnd.fuzzysheet +application/vnd.genomatix.tuxedo +application/vnd.geogebra.file +application/vnd.geogebra.tool +application/vnd.geometry-explorer +application/vnd.geonext +application/vnd.geoplan +application/vnd.geospace +application/vnd.gmx +application/vnd.google-earth.kml+xml +application/vnd.google-earth.kmz +application/vnd.grafeq +application/vnd.groove-account +application/vnd.groove-help +application/vnd.groove-identity-message +application/vnd.groove-injector +application/vnd.groove-tool-message +application/vnd.groove-tool-template +application/vnd.groove-vcard +application/vnd.hal+xml +application/vnd.handheld-entertainment+xml +application/vnd.hbci +application/vnd.hhe.lesson-player +application/vnd.hp-hpgl +application/vnd.hp-hpid +application/vnd.hp-hps +application/vnd.hp-jlyt +application/vnd.hp-pcl +application/vnd.hp-pclxl +application/vnd.hydrostatix.sof-data +application/vnd.hzn-3d-crossword +application/vnd.ibm.minipay +application/vnd.ibm.modcap +application/vnd.ibm.rights-management +application/vnd.ibm.secure-container +application/vnd.iccprofile +application/vnd.igloader +application/vnd.immervision-ivp +application/vnd.immervision-ivu +application/vnd.insors.igm +application/vnd.intercon.formnet +application/vnd.intergeo +application/vnd.intu.qbo +application/vnd.intu.qfx +application/vnd.ipunplugged.rcprofile +application/vnd.irepository.package+xml +application/vnd.is-xpr +application/vnd.isac.fcs +application/vnd.jam +application/vnd.jcp.javame.midlet-rms +application/vnd.jisp +application/vnd.joost.joda-archive +application/vnd.kahootz +application/vnd.kde.karbon +application/vnd.kde.kchart +application/vnd.kde.kformula +application/vnd.kde.kivio +application/vnd.kde.kontour +application/vnd.kde.kpresenter +application/vnd.kde.kspread +application/vnd.kde.kword +application/vnd.kenameaapp +application/vnd.kidspiration +application/vnd.kinar +application/vnd.koan +application/vnd.kodak-descriptor +application/vnd.las.las+xml +application/vnd.llamagraphics.life-balance.desktop +application/vnd.llamagraphics.life-balance.exchange+xml +application/vnd.lotus-1-2-3 +application/vnd.lotus-approach +application/vnd.lotus-freelance +application/vnd.lotus-notes +application/vnd.lotus-organizer +application/vnd.lotus-screencam +application/vnd.lotus-wordpro +application/vnd.macports.portpkg +application/vnd.mcd +application/vnd.medcalcdata +application/vnd.mediastation.cdkey +application/vnd.mfer +application/vnd.mfmp +application/vnd.micrografx.flo +application/vnd.micrografx.igx +application/vnd.mif +application/vnd.mobius.daf +application/vnd.mobius.dis +application/vnd.mobius.mbk +application/vnd.mobius.mqy +application/vnd.mobius.msl +application/vnd.mobius.plc +application/vnd.mobius.txf +application/vnd.mophun.application +application/vnd.mophun.certificate +application/vnd.mozilla.xul+xml +application/vnd.ms-artgalry +application/vnd.ms-cab-compressed +application/vnd.ms-excel +application/vnd.ms-excel.addin.macroenabled.12 +application/vnd.ms-excel.sheet.binary.macroenabled.12 +application/vnd.ms-excel.sheet.macroenabled.12 +application/vnd.ms-excel.template.macroenabled.12 +application/vnd.ms-fontobject +application/vnd.ms-htmlhelp +application/vnd.ms-ims +application/vnd.ms-lrm +application/vnd.ms-officetheme +application/vnd.ms-pki.seccat +application/vnd.ms-pki.stl +application/vnd.ms-powerpoint +application/vnd.ms-powerpoint.addin.macroenabled.12 +application/vnd.ms-powerpoint.presentation.macroenabled.12 +application/vnd.ms-powerpoint.slide.macroenabled.12 +application/vnd.ms-powerpoint.slideshow.macroenabled.12 +application/vnd.ms-powerpoint.template.macroenabled.12 +application/vnd.ms-project +application/vnd.ms-word.document.macroenabled.12 +application/vnd.ms-word.template.macroenabled.12 +application/vnd.ms-works +application/vnd.ms-wpl +application/vnd.ms-xpsdocument +application/vnd.mseq +application/vnd.musician +application/vnd.muvee.style +application/vnd.neurolanguage.nlu +application/vnd.noblenet-directory +application/vnd.noblenet-sealer +application/vnd.noblenet-web +application/vnd.nokia.n-gage.data +application/vnd.nokia.n-gage.symbian.install +application/vnd.nokia.radio-preset +application/vnd.nokia.radio-presets +application/vnd.novadigm.edm +application/vnd.novadigm.edx +application/vnd.novadigm.ext +application/vnd.oasis.opendocument.chart +application/vnd.oasis.opendocument.chart-template +application/vnd.oasis.opendocument.database +application/vnd.oasis.opendocument.formula +application/vnd.oasis.opendocument.formula-template +application/vnd.oasis.opendocument.graphics +application/vnd.oasis.opendocument.graphics-template +application/vnd.oasis.opendocument.image +application/vnd.oasis.opendocument.image-template +application/vnd.oasis.opendocument.presentation +application/vnd.oasis.opendocument.presentation-template +application/vnd.oasis.opendocument.spreadsheet +application/vnd.oasis.opendocument.spreadsheet-template +application/vnd.oasis.opendocument.text +application/vnd.oasis.opendocument.text-master +application/vnd.oasis.opendocument.text-template +application/vnd.oasis.opendocument.text-web +application/vnd.olpc-sugar +application/vnd.oma.dd2+xml +application/vnd.openofficeorg.extension +application/vnd.openxmlformats-officedocument.presentationml.presentation +application/vnd.openxmlformats-officedocument.presentationml.slide +application/vnd.openxmlformats-officedocument.presentationml.slideshow +application/vnd.openxmlformats-officedocument.presentationml.template +application/vnd.openxmlformats-officedocument.spreadsheetml.sheet +application/vnd.openxmlformats-officedocument.spreadsheetml.template +application/vnd.openxmlformats-officedocument.wordprocessingml.document +application/vnd.openxmlformats-officedocument.wordprocessingml.template +application/vnd.osgeo.mapguide.package +application/vnd.osgi.dp +application/vnd.palm +application/vnd.pawaafile +application/vnd.pg.format +application/vnd.pg.osasli +application/vnd.picsel +application/vnd.pmi.widget +application/vnd.pocketlearn +application/vnd.powerbuilder6 +application/vnd.previewsystems.box +application/vnd.proteus.magazine +application/vnd.publishare-delta-tree +application/vnd.pvi.ptid1 +application/vnd.quark.quarkxpress +application/vnd.realvnc.bed +application/vnd.recordare.musicxml +application/vnd.recordare.musicxml+xml +application/vnd.rig.cryptonote +application/vnd.rim.cod +application/vnd.rn-realmedia +application/vnd.route66.link66+xml +application/vnd.sailingtracker.track +application/vnd.seemail +application/vnd.sema +application/vnd.semd +application/vnd.semf +application/vnd.shana.informed.formdata +application/vnd.shana.informed.formtemplate +application/vnd.shana.informed.interchange +application/vnd.shana.informed.package +application/vnd.simtech-mindmapper +application/vnd.smaf +application/vnd.smart.teacher +application/vnd.solent.sdkm+xml +application/vnd.spotfire.dxp +application/vnd.spotfire.sfs +application/vnd.stardivision.calc +application/vnd.stardivision.draw +application/vnd.stardivision.impress +application/vnd.stardivision.math +application/vnd.stardivision.writer +application/vnd.stardivision.writer-global +application/vnd.stepmania.stepchart +application/vnd.sun.xml.calc +application/vnd.sun.xml.calc.template +application/vnd.sun.xml.draw +application/vnd.sun.xml.draw.template +application/vnd.sun.xml.impress +application/vnd.sun.xml.impress.template +application/vnd.sun.xml.math +application/vnd.sun.xml.writer +application/vnd.sun.xml.writer.global +application/vnd.sun.xml.writer.template +application/vnd.sus-calendar +application/vnd.svd +application/vnd.symbian.install +application/vnd.syncml+xml +application/vnd.syncml.dm+wbxml +application/vnd.syncml.dm+xml +application/vnd.tao.intent-module-archive +application/vnd.tmobile-livetv +application/vnd.trid.tpt +application/vnd.triscape.mxs +application/vnd.trueapp +application/vnd.ufdl +application/vnd.uiq.theme +application/vnd.umajin +application/vnd.unity +application/vnd.uoml+xml +application/vnd.vcx +application/vnd.visio +application/vnd.visionary +application/vnd.vsf +application/vnd.wap.wbxml +application/vnd.wap.wmlc +application/vnd.wap.wmlscriptc +application/vnd.webturbo +application/vnd.wolfram.player +application/vnd.wordperfect +application/vnd.wqd +application/vnd.wt.stf +application/vnd.xara +application/vnd.xfdl +application/vnd.yamaha.hv-dic +application/vnd.yamaha.hv-script +application/vnd.yamaha.hv-voice +application/vnd.yamaha.openscoreformat +application/vnd.yamaha.openscoreformat.osfpvg+xml +application/vnd.yamaha.smaf-audio +application/vnd.yamaha.smaf-phrase +application/vnd.yellowriver-custom-menu +application/vnd.zul +application/vnd.zzazz.deck+xml +application/voicexml+xml +application/widget +application/winhlp +application/wsdl+xml +application/wspolicy+xml +application/x-7z-compressed +application/x-abiword +application/x-ace-compressed +application/x-authorware-bin +application/x-authorware-map +application/x-authorware-seg +application/x-bcpio +application/x-bittorrent +application/x-bzip +application/x-bzip2 +application/x-cdlink +application/x-chat +application/x-chess-pgn +application/x-cpio +application/x-csh +application/x-debian-package +application/x-director +application/x-doom +application/x-dtbncx+xml +application/x-dtbook+xml +application/x-dtbresource+xml +application/x-dvi +application/x-font-bdf +application/x-font-ghostscript +application/x-font-linux-psf +application/x-font-otf +application/x-font-pcf +application/x-font-snf +application/x-font-ttf +application/x-font-type1 +application/x-font-woff +application/x-futuresplash +application/x-gnumeric +application/x-gtar +application/x-hdf +application/x-java-jnlp-file +application/x-latex +application/x-mobipocket-ebook +application/x-ms-application +application/x-ms-wmd +application/x-ms-wmz +application/x-ms-xbap +application/x-msaccess +application/x-msbinder +application/x-mscardfile +application/x-msclip +application/x-msdownload +application/x-msmediaview +application/x-msmetafile +application/x-msmoney +application/x-mspublisher +application/x-msschedule +application/x-msterminal +application/x-mswrite +application/x-netcdf +application/x-pkcs12 +application/x-pkcs7-certificates +application/x-pkcs7-certreqresp +application/x-rar-compressed +application/x-sh +application/x-shar +application/x-shockwave-flash +application/x-silverlight-app +application/x-stuffit +application/x-stuffitx +application/x-sv4cpio +application/x-sv4crc +application/x-tar +application/x-tcl +application/x-tex +application/x-tex-tfm +application/x-texinfo +application/x-ustar +application/x-wais-source +application/x-x509-ca-cert +application/x-xfig +application/x-xpinstall +application/xcap-diff+xml +application/xenc+xml +application/xhtml+xml +application/xml +application/xml-dtd +application/xop+xml +application/xslt+xml +application/xspf+xml +application/xv+xml +application/yang +application/yin+xml +application/zip +audio/adpcm +audio/basic +audio/midi +audio/mp4 +audio/mpeg +audio/ogg +audio/vnd.dece.audio +audio/vnd.digital-winds +audio/vnd.dra +audio/vnd.dts +audio/vnd.dts.hd +audio/vnd.lucent.voice +audio/vnd.ms-playready.media.pya +audio/vnd.nuera.ecelp4800 +audio/vnd.nuera.ecelp7470 +audio/vnd.nuera.ecelp9600 +audio/vnd.rip +audio/webm +audio/x-aac +audio/x-aiff +audio/x-mpegurl +audio/x-ms-wax +audio/x-ms-wma +audio/x-pn-realaudio +audio/x-pn-realaudio-plugin +audio/x-wav +chemical/x-cdx +chemical/x-cif +chemical/x-cmdf +chemical/x-cml +chemical/x-csml +chemical/x-xyz +image/bmp +image/cgm +image/g3fax +image/gif +image/ief +image/jpeg +image/ktx +image/png +image/prs.btif +image/svg+xml +image/tiff +image/vnd.adobe.photoshop +image/vnd.dece.graphic +image/vnd.dvb.subtitle +image/vnd.djvu +image/vnd.dwg +image/vnd.dxf +image/vnd.fastbidsheet +image/vnd.fpx +image/vnd.fst +image/vnd.fujixerox.edmics-mmr +image/vnd.fujixerox.edmics-rlc +image/vnd.ms-modi +image/vnd.net-fpx +image/vnd.wap.wbmp +image/vnd.xiff +image/webp +image/x-cmu-raster +image/x-cmx +image/x-freehand +image/x-icon +image/x-pcx +image/x-pict +image/x-portable-anymap +image/x-portable-bitmap +image/x-portable-graymap +image/x-portable-pixmap +image/x-rgb +image/x-xbitmap +image/x-xpixmap +image/x-xwindowdump +message/rfc822 +model/iges +model/mesh +model/vnd.collada+xml +model/vnd.dwf +model/vnd.gdl +model/vnd.gtw +model/vnd.mts +model/vnd.vtu +model/vrml +text/calendar +text/css +text/csv +text/html +text/n3 +text/plain +text/prs.lines.tag +text/richtext +text/sgml +text/tab-separated-values +text/troff +text/turtle +text/uri-list +text/vnd.curl +text/vnd.curl.dcurl +text/vnd.curl.scurl +text/vnd.curl.mcurl +text/vnd.fly +text/vnd.fmi.flexstor +text/vnd.graphviz +text/vnd.in3d.3dml +text/vnd.in3d.spot +text/vnd.sun.j2me.app-descriptor +text/vnd.wap.wml +text/vnd.wap.wmlscript +text/x-asm +text/x-c +text/x-fortran +text/x-pascal +text/x-java-source +text/x-setext +text/x-uuencode +text/x-vcalendar +text/x-vcard +video/3gpp +video/3gpp2 +video/h261 +video/h263 +video/h264 +video/jpeg +video/jpm +video/mj2 +video/mp4 +video/mpeg +video/ogg +video/quicktime +video/vnd.dece.hd +video/vnd.dece.mobile +video/vnd.dece.pd +video/vnd.dece.sd +video/vnd.dece.video +video/vnd.fvt +video/vnd.mpegurl +video/vnd.ms-playready.media.pyv +video/vnd.uvvu.mp4 +video/vnd.vivo +video/webm +video/x-f4v +video/x-fli +video/x-flv +video/x-m4v +video/x-ms-asf +video/x-ms-wm +video/x-ms-wmv +video/x-ms-wmx +video/x-ms-wvx +video/x-msvideo +video/x-sgi-movie +x-conference/x-cooltalk diff --git a/src/Makefile.in b/src/Makefile.in index ece73246..f55cc1ba 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -33,7 +33,7 @@ MAKE = `which make` INSTALL = @INSTALL@ -all: libpiler.a piler pilerconf test +all: libpiler.a piler pilerconf pilerdecrypt test install: install-piler @@ -49,13 +49,13 @@ libpiler.a: $(OBJS) $(MYSQL_OBJS) pilerdecrypt: pilerdecrypt.c cfg.o misc.o tai.o store.o - $(CC) $(CFLAGS) $(INCDIR) $(DEFS) -o $@ $^ $(LIBS) $(LIBDIR) + $(CC) $(CFLAGS) $(INCDIR) $(DEFS) -o $@ $^ -lcrypto -lz $(LIBDIR) pilerconf: pilerconf.c cfg.o misc.o tai.o - $(CC) $(CFLAGS) $(INCDIR) $(DEFS) -o $@ $^ $(LIBS) $(LIBDIR) + $(CC) $(CFLAGS) $(INCDIR) $(DEFS) -o $@ $^ $(LIBDIR) test: - $(CC) $(CFLAGS) $(INCDIR) $(DEFS) -o piletest $(srcdir)/test.c -lpiler $(LIBS) $(LDAP_LIBS) $(LIBDIR) @LDFLAGS@ + $(CC) $(CFLAGS) $(INCDIR) $(DEFS) -o pilertest $(srcdir)/test.c -lpiler $(LIBS) $(LDAP_LIBS) $(LIBDIR) @LDFLAGS@ %.o: $(srcdir)/%.c $(CC) $(CFLAGS) -fPIC $(INCDIR) $(DEFS) -c $< -o $@ @@ -78,7 +78,7 @@ install-piler: $(INSTALL) -m 0755 pilerconf $(DESTDIR)$(sbindir) clean: - rm -f *.o *.a libpiler.so* piler pilerconf piletest + rm -f *.o *.a libpiler.so* piler pilerconf pilertest distclean: clean rm -f Makefile diff --git a/src/attachment.c b/src/attachment.c index e8809fd0..1e3fbccb 100644 --- a/src/attachment.c +++ b/src/attachment.c @@ -23,6 +23,25 @@ int store_attachments(struct session_data *sdata, struct _state *state, struct _ MYSQL_RES *res; MYSQL_ROW row; + MYSQL_STMT *stmt; + MYSQL_BIND bind[6]; + unsigned long len[6]; + + + stmt = mysql_stmt_init(&(sdata->mysql)); + if(!stmt){ + if(cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "%s: %s.mysql_stmt_init() error", sdata->ttmpfile, SQL_ATTACHMENT_TABLE); + return 1; + } + + snprintf(s, sizeof(s)-1, "INSERT INTO %s (`piler_id`,`attachment_id`,`sig`,`type`,`size`,`ptr`) VALUES(?,?,?,?,?,?)", SQL_ATTACHMENT_TABLE); + + if(mysql_stmt_prepare(stmt, s, strlen(s))){ + syslog(LOG_PRIORITY, "%s: %s.mysql_stmt_prepare() error: %s", sdata->ttmpfile, SQL_ATTACHMENT_TABLE, mysql_stmt_error(stmt)); + return 1; + } + + for(i=1; i<=state->n_attachments; i++){ found = 0; id = 0; @@ -53,9 +72,47 @@ int store_attachments(struct session_data *sdata, struct _state *state, struct _ } } - snprintf(s, sizeof(s)-1, "INSERT INTO %s (`piler_id`,`attachment_id`,`sig`,`ptr`) VALUES('%s',%d,'%s',%llu)", SQL_ATTACHMENT_TABLE, sdata->ttmpfile, i, state->attachments[i].digest, id); - if(mysql_real_query(&(sdata->mysql), s, strlen(s))){ + memset(bind, 0, sizeof(bind)); + + bind[0].buffer_type = MYSQL_TYPE_STRING; + bind[0].buffer = sdata->ttmpfile; + bind[0].is_null = 0; + len[0] = strlen(sdata->ttmpfile); bind[0].length = &len[0]; + + bind[1].buffer_type = MYSQL_TYPE_LONG; + bind[1].buffer = (char *)&i; + bind[1].is_null = 0; + bind[1].length = 0; + + bind[2].buffer_type = MYSQL_TYPE_STRING; + bind[2].buffer = state->attachments[i].digest; + bind[2].is_null = 0; + len[2] = strlen(state->attachments[i].digest); bind[2].length = &len[2]; + + bind[3].buffer_type = MYSQL_TYPE_STRING; + bind[3].buffer = state->attachments[i].type; + bind[3].is_null = 0; + len[3] = strlen(state->attachments[i].digest); bind[3].length = &len[3]; + + bind[4].buffer_type = MYSQL_TYPE_LONG; + bind[4].buffer = (char *)&(state->attachments[i].size); + bind[4].is_null = 0; + bind[4].length = 0; + + bind[5].buffer_type = MYSQL_TYPE_LONGLONG; + bind[5].buffer = (char *)&id; + bind[5].is_null = 0; + bind[5].length = 0; + + + if(mysql_stmt_bind_param(stmt, bind)){ + syslog(LOG_PRIORITY, "%s: %s.mysql_stmt_bind_param() error: %s", sdata->ttmpfile, SQL_ATTACHMENT_TABLE, mysql_stmt_error(stmt)); + return 1; + } + + + if(mysql_stmt_execute(stmt)){ syslog(LOG_PRIORITY, "%s attachment sql error: *%s*", sdata->ttmpfile, mysql_error(&(sdata->mysql))); return 1; } diff --git a/src/config.h b/src/config.h index fc66ef12..c434b7fa 100644 --- a/src/config.h +++ b/src/config.h @@ -11,7 +11,7 @@ #define PROGNAME "piler" -#define VERSION "0.1.6" +#define VERSION "0.1.7" #define PROGINFO VERSION ", Janos SUTO \n\n" CONFIGURE_PARAMS "\n\nSend bugs/issues to https://jira.acts.hu:8443/\n" diff --git a/src/defs.h b/src/defs.h index 9ad279fd..077cd493 100644 --- a/src/defs.h +++ b/src/defs.h @@ -70,9 +70,13 @@ struct rule { regex_t from; regex_t to; regex_t subject; + regex_t attachment_type; #endif int size; char _size[4]; + int attachment_size; + char _attachment_size[4]; + char *rulestr; char compiled; struct rule *r; diff --git a/src/message.c b/src/message.c index 098eb9a9..1cfb2e7b 100644 --- a/src/message.c +++ b/src/message.c @@ -247,14 +247,18 @@ int processMessage(struct session_data *sdata, struct _state *state, struct __co */ + /* store base64 encoded file attachments */ - rc = store_attachments(sdata, state, cfg); + if(state->n_attachments > 0){ + rc = store_attachments(sdata, state, cfg); - for(i=1; i<=state->n_attachments; i++){ - unlink(state->attachments[i].internalname); + for(i=1; i<=state->n_attachments; i++){ + unlink(state->attachments[i].internalname); + } + + if(rc) return ERR; } - if(rc) return ERR; rc = store_file(sdata, sdata->tmpframe, 0, 0, cfg); if(rc == 0){ diff --git a/src/parser.c b/src/parser.c index 38357d40..cdb98955 100644 --- a/src/parser.c +++ b/src/parser.c @@ -115,10 +115,25 @@ int parse_line(char *buf, struct _state *state, struct session_data *sdata, stru //printf("DUMP FILE: %s\n", state->attachments[state->n_attachments].internalname); state->fd = open(state->attachments[state->n_attachments].internalname, O_CREAT|O_RDWR, S_IRUSR|S_IWUSR); + if(state->fd == -1){ - snprintf(puf, sizeof(puf)-1, "ATTACHMENT_POINTER_%s.a%d", sdata->ttmpfile, state->n_attachments); - write(state->mfd, puf, strlen(puf)); - //printf("%s", puf); + state->attachments[state->n_attachments].size = 0; + memset(state->attachments[state->n_attachments].type, 0, TINYBUFSIZE); + memset(state->attachments[state->n_attachments].filename, 0, TINYBUFSIZE); + memset(state->attachments[state->n_attachments].internalname, 0, TINYBUFSIZE); + memset(state->attachments[state->n_attachments].digest, 0, 2*DIGEST_LENGTH+1); + + syslog(LOG_PRIORITY, "%s: error opening %s", sdata->ttmpfile, state->attachments[state->n_attachments].internalname); + + state->n_attachments--; + state->has_to_dump = 0; + + } + else { + snprintf(puf, sizeof(puf)-1, "ATTACHMENT_POINTER_%s.a%d", sdata->ttmpfile, state->n_attachments); + write(state->mfd, puf, strlen(puf)); + //printf("%s", puf); + } } else { state->has_to_dump = 0; diff --git a/src/rules.c b/src/rules.c index f8c01812..b2a8c10d 100644 --- a/src/rules.c +++ b/src/rules.c @@ -15,13 +15,13 @@ void load_archiving_rules(struct session_data *sdata, struct rule **rules){ MYSQL_RES *res; MYSQL_ROW row; - snprintf(s, sizeof(s)-1, "SELECT `from`, `to`, `subject`, `_size`, `size` FROM `%s`", SQL_ARCHIVING_RULE_TABLE); + snprintf(s, sizeof(s)-1, "SELECT `from`, `to`, `subject`, `_size`, `size`, `attachment_type`, `_attachment_size`, `attachment_size` FROM `%s`", SQL_ARCHIVING_RULE_TABLE); if(mysql_real_query(&(sdata->mysql), s, strlen(s)) == 0){ res = mysql_store_result(&(sdata->mysql)); if(res != NULL){ while((row = mysql_fetch_row(res))){ - append_rule(rules, (char*)row[0], (char*)row[1], (char*)row[2], (char*)row[3], atoi(row[4])); + append_rule(rules, (char*)row[0], (char*)row[1], (char*)row[2], (char*)row[3], atoi(row[4]), (char*)row[5], (char*)row[6], atoi(row[7])); } mysql_free_result(res); @@ -32,7 +32,7 @@ void load_archiving_rules(struct session_data *sdata, struct rule **rules){ } -int append_rule(struct rule **rule, char *from, char *to, char *subject, char *_size, int size){ +int append_rule(struct rule **rule, char *from, char *to, char *subject, char *_size, int size, char *attachment_type, char *_attachment_size, int attachment_size){ struct rule *q, *t, *u=NULL; q = *rule; @@ -42,7 +42,7 @@ int append_rule(struct rule **rule, char *from, char *to, char *subject, char *_ q = q->r; } - t = create_rule_item(from, to, subject, _size, size); + t = create_rule_item(from, to, subject, _size, size, attachment_type, _attachment_size, attachment_size); if(t){ if(*rule == NULL) *rule = t; @@ -56,7 +56,7 @@ int append_rule(struct rule **rule, char *from, char *to, char *subject, char *_ } -struct rule *create_rule_item(char *from, char *to, char *subject, char *_size, int size){ +struct rule *create_rule_item(char *from, char *to, char *subject, char *_size, int size, char *attachment_type, char *_attachment_size, int attachment_size){ struct rule *h=NULL; char empty = '\0'; int len; @@ -81,10 +81,22 @@ struct rule *create_rule_item(char *from, char *to, char *subject, char *_size, if(!_size) _size = ∅ snprintf(h->_size, 3, "%s", _size); - len = strlen(from)+6 + strlen(to)+4 + strlen(subject)+9 + strlen(_size)+6 + 15; + + if(!attachment_type) attachment_type = ∅ + if(regcomp(&(h->attachment_type), attachment_type, REG_ICASE | REG_EXTENDED)) h->compiled = 0; + + + h->attachment_size = attachment_size; + + if(!_attachment_size) _attachment_size = ∅ + snprintf(h->_attachment_size, 3, "%s", _attachment_size); + + len = strlen(from)+6 + strlen(to)+4 + strlen(subject)+9 + strlen(_size)+6 + strlen(attachment_type)+10 + strlen(_attachment_size)+10 + 15 + 15; h->rulestr = malloc(len); - if(h->rulestr) snprintf(h->rulestr, len-1, "from=%s,to=%s,subject=%s,size%s%d", from, to, subject, _size, size); + + + if(h->rulestr) snprintf(h->rulestr, len-1, "from=%s,to=%s,subject=%s,size%s%d,att.type=%s,att.size%s%d", from, to, subject, _size, size, attachment_type, _attachment_size, attachment_size); else h->compiled = 0; h->r = NULL; @@ -93,7 +105,7 @@ struct rule *create_rule_item(char *from, char *to, char *subject, char *_size, } -char *check_againt_ruleset(struct rule *rule, char *from, char *to, char *subject, int size){ +char *check_againt_ruleset(struct rule *rule, struct _state *state, int size){ size_t nmatch=0; struct rule *p; @@ -103,10 +115,11 @@ char *check_againt_ruleset(struct rule *rule, char *from, char *to, char *subjec if( p->compiled == 1 && - regexec(&(p->from), from, nmatch, NULL, 0) == 0 && - regexec(&(p->to), to, nmatch, NULL, 0) == 0 && - regexec(&(p->subject), subject, nmatch, NULL, 0) == 0 && - check_size_rule(size, p->size, p->_size) == 1 + regexec(&(p->from), state->b_from, nmatch, NULL, 0) == 0 && + regexec(&(p->to), state->b_to, nmatch, NULL, 0) == 0 && + regexec(&(p->subject), state->b_subject, nmatch, NULL, 0) == 0 && + check_size_rule(size, p->size, p->_size) == 1 && + check_attachment_rule(state, p) == 1 ){ return p->rulestr; } @@ -130,6 +143,23 @@ int check_size_rule(int message_size, int size, char *_size){ } +int check_attachment_rule(struct _state *state, struct rule *rule){ + int i; + size_t nmatch=0; + + for(i=1; i<=state->n_attachments; i++){ + if( + regexec(&(rule->attachment_type), state->attachments[i].type, nmatch, NULL, 0) == 0 && + check_size_rule(state->attachments[i].size, rule->attachment_size, rule->_attachment_size) == 1 + ){ + return 1; + } + } + + return 0; +} + + void free_rule(struct rule *rule){ struct rule *p, *q; @@ -141,6 +171,8 @@ void free_rule(struct rule *rule){ if(p){ regfree(&(p->from)); regfree(&(p->to)); + regfree(&(p->attachment_type)); + free(p->rulestr); free(p); diff --git a/src/rules.h b/src/rules.h index 22ede682..0e471b99 100644 --- a/src/rules.h +++ b/src/rules.h @@ -8,10 +8,11 @@ #include "defs.h" void load_archiving_rules(struct session_data *sdata, struct rule **rules); -int append_rule(struct rule **rule, char *from, char *to, char *subject, char *_size, int size); -struct rule *create_rule_item(char *from, char *to, char *subject, char *_size, int size); -char *check_againt_ruleset(struct rule *rule, char *from, char *to, char *subject, int size); +int append_rule(struct rule **rule, char *from, char *to, char *subject, char *_size, int size, char *attachment_type, char *_attachment_size, int attachment_size); +struct rule *create_rule_item(char *from, char *to, char *subject, char *_size, int size, char *attachment_type, char *_attachment_size, int attachment_size); +char *check_againt_ruleset(struct rule *rule, struct _state *state, int size); int check_size_rule(int message_size, int size, char *_size); +int check_attachment_rule(struct _state *state, struct rule *rule); void free_rule(struct rule *rule); #endif /* _RULES_H */ diff --git a/src/session.c b/src/session.c index 58e90d96..7bc14b63 100644 --- a/src/session.c +++ b/src/session.c @@ -189,10 +189,10 @@ void handle_smtp_session(int new_sd, struct __data *data, struct __config *cfg){ /* check message against archiving rules */ - arule = check_againt_ruleset(data->rules, sstate.b_from, sstate.b_to, sstate.b_subject, sdata.tot_len); + arule = check_againt_ruleset(data->rules, &sstate, sdata.tot_len); if(arule){ - syslog(LOG_PRIORITY, "%s: discarding message by policy: *%s*", sdata.ttmpfile, arule); + syslog(LOG_PRIORITY, "%s: discarding message by archiving policy: *%s*", sdata.ttmpfile, arule); inj = OK; } else { diff --git a/src/test.c b/src/test.c index 45ce1240..d6e50e4b 100644 --- a/src/test.c +++ b/src/test.c @@ -71,11 +71,11 @@ int main(int argc, char **argv){ //printf("body: *%s*\n", state.b_body); make_body_digest(&sdata, &cfg); - rule = check_againt_ruleset(data.rules, state.b_from, state.b_to, state.b_subject, st.st_size); + rule = check_againt_ruleset(data.rules, &state, st.st_size); //printf("body digest: %s\n", sdata.bodydigest); - //printf("rules check: %s\n", rule); + printf("rules check: %s\n", rule); mysql_close(&(sdata.mysql)); diff --git a/util/db-mysql.sql b/util/db-mysql.sql index 032cd5d0..059466af 100644 --- a/util/db-mysql.sql +++ b/util/db-mysql.sql @@ -49,7 +49,9 @@ create table `attachment` ( `id` bigint unsigned not null auto_increment, `piler_id` char(36) not null, `attachment_id` int not null, + `type` char(64) default null, `sig` char(64) not null, + `size` int default 0, `ptr` int default 0, primary key (`id`) ) Engine=InnoDB; @@ -65,9 +67,11 @@ create table `archiving_rule` ( `subject` char(255) default null, `_size` char(2) default null, `size` int default 0, + `attachment_type` char(128) default null, + `_attachment_size` char(2) default null, + `attachment_size` int default 0, primary key (`id`) -); - +) ENGINE=InnoDB; drop table if exists `counter`; create table if not exists `counter` (