LDAP
The Lightweight Directory Access Protocol (LDAP) is an application protocol for accessing distributed directory information services. This plugin provide a bridge between the LDAP databases.
Usage
In this example, we will setup the plugin to be used in the SMTP SMTP Receiver service. First, create a connection pool to the LDAP database.
// /etc/vsmtp/smtp-receiver/services/db.rhai
// Import the plugin stored in the `plugins` directory.
import "plugins/libldap_plugin" as ldap;
export const directory = ldap::connect(#{
// Url poiting to the database.
url: "ldap://ds.example.com:1389 ",
// Timeout allowed for each LDAP query.
timeout: "1m",
// Number of connections to open in the pool.
connections: 10,
});
import "services/db" as db;
fn on_rcpt_to(ctx) {
ctx.run([
rule "check recipient in directory" || {
let recipient = ctx.rcpt();
let address = recipient.domain();
let user = recipient.local_part();
let results = db::directory.search(
"ou=People,dc=example,dc=com",
// Search the whole tree.
"sub",
// Match on the user id and address.
`(|(uid=${user})(mail=${address}))`
// Get all attributes from the entries.
["*"]
);
// Use the `results` variable to filter the
// recipient.
}
]);
}