haraka / Haraka

A fast, highly extensible, and event driven SMTP server
https://haraka.github.io
MIT License
5.02k stars 662 forks source link

How to read and log authenticated username in custom plugin #1600

Closed ajay-psd closed 8 years ago

ajay-psd commented 8 years ago

Hi

When message gets queued successfully I want to log authenticate "username" along with "connection.trasaction.uuid"

I am able to log uuid using hook queue_ok , But not able to username. Any method or global variable is there to capture username in my custom plugin..

Please suggest! Thanks In advance.

darkpixel commented 8 years ago

I don't think all of the authentication plugins log the username. The LDAP plugin for example doesn't seem to store it anywhere: https://github.com/haraka/Haraka/blob/40db0e75a67ed048a2628eb769cfa0d10294dda4/plugins/auth/auth_ldap.js

You could write a patch for your particular plugin to store it somewhere (maybe the transaction notes?), and then read the variable from your plugin.

darkpixel commented 8 years ago

Something like adding a line here: https://github.com/haraka/Haraka/blob/40db0e75a67ed048a2628eb769cfa0d10294dda4/plugins/auth/auth_ldap.js#L54

connection.notes.auth_user = dn;
ajay-psd commented 8 years ago

I tried setting in transaction.header and read in my plugin, but did not worked out.

Thanks for suggestion! I will try use connection.notes, hope it will work!

darkpixel commented 8 years ago

If it works, please consider submitting a pull request for the auth plugin you are using, or even all of the plugins.

smfreegard commented 8 years ago

Sorry - saw this issue late. There already is a suitable note for this, all of the auth plugins inherit from auth_base which sets connection.notes.auth_user:

https://github.com/haraka/Haraka/blob/master/plugins/auth/auth_base.js#L117

darkpixel commented 8 years ago

facepalm I completely ignored the inherits statement. Sorry.

ajay-psd commented 8 years ago

Thank You so much for help, Its working great!

I have one doubt, My haraka conf is at /etc/haraka/ And /etc/haraka/plugin/auth/ directory is empty, there no auth plugin files. But auth process works perfectly when some one tries to connect and send mail.

Is haraka uses global installation directory for plugin script, in case it does not find plugins in local directory??

ajay-psd commented 8 years ago

TXT records added as per config/dkim/mydomain.com/dns file

baudehlo commented 8 years ago

Yes exactly that. It allows you to override core plugins easily by copying them to your local install and editing them.

On Sep 17, 2016, at 2:31 AM, ajay-psd notifications@github.com wrote:

Is haraka uses global installation directory for plugin script, in case it does not find plugins in local directory??