From f32f278105c343258d9391b620b02e825dcb434a Mon Sep 17 00:00:00 2001 From: kload Date: Tue, 19 Aug 2014 16:01:14 +0200 Subject: [PATCH] [enh] Limit domains per user --- access.lua | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/access.lua b/access.lua index 879b453..b056bf8 100644 --- a/access.lua +++ b/access.lua @@ -485,7 +485,29 @@ function do_edit () end local mail_pattern = "[A-Za-z0-9%.%%%+%-]+@[A-Za-z0-9%.%%%+%-]+%.%w%w%w?%w?" - local domains = conf["domains"] + + -- Limit domains per user + local domains = {} + local ldap = lualdap.open_simple(conf["ldap_host"]) + for dn, attribs in ldap:search { + base = conf["ldap_group"], + scope = "onelevel", + sizelimit = 1, + filter = "(uid="..user..")", + attrs = {"mail"} + } do + for _, domain in ipairs(conf["domains"]) do + for k, mail in ipairs(attribs["mail"]) do + if string.ends(mail, "@"..domain) then + if not is_in_table(domains, domain) then + table.insert(domains, domain) + end + end + end + end + end + ldap:close() + local mails = {} local filter = "(|" table.insert(mailalias, 1, args.mail)