Skip to content

Commit

Permalink
global: Introduce lua_file and lua_settings global settings
Browse files Browse the repository at this point in the history
  • Loading branch information
vmo69 committed Mar 21, 2024
1 parent 73ba91d commit da5bdd5
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,33 +34,45 @@ Initialization

.. dovecotadded:: 2.4.0,3.0.0

When passdb or userdb is initialized, there will be a lookup for initialization function.
This is different from :func:`script_init`` which is called for all Lua scripts. For
passdb, the function is :func:`auth_passdb_init` and for userdb, it is called
:func:`auth_userdb_init`. The function is called with a table containing all parameters
provided in the passdb/userdb args, except file name.
When passdb or userdb is initialized, there will be a lookup for a function to
get the cache_key for the userdb or passdb. These functions are called
func:`auth_passdb_get_cache_key` for passdbs and :func:`auth_userdb_get_cache_key`
for userdbs.

This can be used to pass out initialization parameters from Dovecot.
The global :func:`script_init` function is called for all Lua scripts and can
be used to pass arguments to the script using :dovecot_core:ref:`lua_settings`

These settings can be used to pass out initialization parameters from Dovecot.

Example

.. code:: lua
local password = nil
function auth_passdb_init(args)
function script_init(args)
password = args["password"]
return 0
end
function auth_passdb_lookup(req)
return dovecot.auth.PASSDB_RESULT_OK, { ["password"]=password }
end
function auth_passdb_get_cache_key()
return "%{username}\t%{protocol}"
end
The lua script to be used is given to the passdb using :dovecot_core:ref:`lua_file`
setting.

.. code:: none
passdb lua {
args = file=/etc/dovecot/auth.lua password={PLAIN}test
lua_file = /etc/dovecot/auth.lua
lua_settings {
password = {PLAIN}test
}
}
Expand Down Expand Up @@ -184,7 +196,8 @@ To configure passdb in dovecot, use
.. code-block:: none
passdb lua {
args = file=/path/to/lua blocking=yes # default is yes
lua_file = /path/to/lua
use_worker = yes # default is yes
}
By default, dovecot runs Lua scripts in auth-worker processes. If you do not
Expand Down Expand Up @@ -217,7 +230,8 @@ To configure userdb in dovecot, use
.. code-block:: none
userdb lua {
args = file=/path/to/lua blocking=yes # default is yes
lua_file = /path/to/lua
use_worker = yes # default is yes
}
Examples
Expand Down
10 changes: 8 additions & 2 deletions source/configuration_manual/howto/director_with_lua.rst
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ First, and the most simple, is drop-in replacement for director with no authenti
.. code::
passdb lua {
args = file=/etc/dovecot/director.lua nopassword
lua_file = /etc/dovecot/director.lua
fields {
nopassword = yes
}
# or password=masterpass
# you can include other keys here too, they will be
# included in the response.
Expand All @@ -97,7 +100,10 @@ If you wish to do authentication, you can do
passdb lua {
skip = unauthenticated
args = file=/etc/dovecot/director.lua noauthenticate
lua_file = /etc/dovecot/director.lua
fields {
noauthenticate = yes
}
}
Expand Down
29 changes: 14 additions & 15 deletions source/configuration_manual/push_notification.rst
Original file line number Diff line number Diff line change
Expand Up @@ -240,23 +240,19 @@ Configuration
-------------

Lua push notification handler requires :ref:`mail_lua <plugin-mail-lua>` and
``push_notification_lua`` plugins to be loaded in addition to the plugins
``push_notification_lua`` plugins to be loaded in addition to the plugin
discussed :ref:`above <push_notification-usage>`.

============================== ======== ============= =================================================================
Name Required Type Description
============================== ======== ============= =================================================================
``push_notification_driver`` **YES** :ref:`string` To identify this settings block the driver should get the value
``lua``.
============================== ======== =============== =================================================================
Name Required Type Description
============================== ======== =============== =================================================================
``push_notification_driver`` **YES** :ref:`string` To identify this settings block the driver should get the value
``lua``.

``push_notification_lua_path`` NO :ref:`string` The lua file to execute. If no script is specified,
:dovecot_plugin:ref:`mail_lua_script` will be used by default.

This setting is optional as the driver first checks the
environment ``push_notification_lua_script_path`` and loads it.
This also means that this environment variable takes precedence
over this setting.
============================== ======== ============= =================================================================
``lua_file`` NO :ref:`file` The lua file to execute. See :dovecot_core:ref:`lua_file`.
``lua_settings`` NO :ref:`strlist` Extra parameters to pass to the Lua script_init() function
See :dovecot_core:ref:`lua_settings`.
============================== ======== =============== =================================================================

.. code-block:: none

Expand All @@ -269,7 +265,10 @@ Name Required Type Description

push_notification lua {
push_notification_driver = lua
push_notification_lua_path = /path/to/lua/script
lua_file = /path/to/lua/script
lua_settings {
extra_param = %{userdb:extra_param}
}
}

API Overview
Expand Down
15 changes: 15 additions & 0 deletions source/settings/core.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2255,6 +2255,21 @@ See :ref:`settings` for list of all setting groups.
Except if HAProxy is used, then the original client IP address is used.


.. dovecot_core:setting:: lua_file
:seealso: @lua_settings;dovecot_core
:values: @file

Path to lua script to be used. This is used by
* :ref:`mail_lua <plugin-mail-lua>`
* :ref:`Lua push notifications <lua_push_notifications>`
* :ref:`authentication-lua_based_authentication`

.. dovecot_core:setting:: lua_settings
:seealso: @lua_file;dovecot_core
:values: @strlist

Key-value pairs that are passed as a table to lua script_init() function.

.. dovecot_core:setting:: mail_access_groups
:todo: Describe format; comma-separated list?
:values: @string
Expand Down
19 changes: 12 additions & 7 deletions source/settings/plugin/mail-lua-plugin.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,22 @@ plugins.
Settings
========

.. dovecot_plugin:setting:: mail_lua_script
:added: 2.3.4
.. dovecot_plugin:setting_filter:: mail_lua
:filter: mail_lua
:plugin: mail-lua
:values: @string
:values: @named_filter
:added: 2.4.0,3.0.0

Specify filename to load for user.
Named filter for initializing mail_lua settings
see :dovecot_core:ref:`lua_file` and :dovecot_core:ref:`lua_settings`

Example:

.. code-block:: none
plugin {
mail_lua_script = /etc/dovecot/user.lua
}
mail_lua {
lua_file = /etc/dovecot/user.lua
lua_settings {
extra_param = %{userdb:extra_param}
}
}

0 comments on commit da5bdd5

Please sign in to comment.