From 00456a265e2afb5dde93733e339fb8a387e6d933 Mon Sep 17 00:00:00 2001 From: Matthias Huber Date: Fri, 29 Jun 2018 16:12:40 +0200 Subject: [PATCH] add config to convert email to lowercase --- ctldap.example.config | 9 +++++++-- ctldap.js | 14 +++++++++++--- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/ctldap.example.config b/ctldap.example.config index 5a74b3d..c70cbe8 100644 --- a/ctldap.example.config +++ b/ctldap.example.config @@ -1,7 +1,10 @@ ; Add debug infos to log debug=false + ; This is required for clients using lowercase DNs, e.g. ownCloud/nextCloud dn_lower_case=true +; This is required for clients that need lowercase email addresses, e.g. Seafile +email_lower_case=true ; LDAP admin user, can be a "virtual" root user or a ChurchTools user name (virtual root is recommended!) ldap_user=root @@ -37,7 +40,8 @@ cache_lifetime=10000 ; Define the sites here. For each site please enter one section. ; The section title has to be in the format sites., e.g. "sites.foobar", ; where foobar is the organisation, as in the instance foobar.church.tools . -; dn_lower_case is optional. +; dn_lower_case is optional, if not specified, the default value will be taken from the config above +; email_lower_case is optional, if not specified, the default value will be taken from the config above ; If ldap_base_dn is set above, the setting above are treated as an additional site. ;[sites.XXXXXXXXXXXXXXXXXXXX] @@ -45,4 +49,5 @@ cache_lifetime=10000 ;ct_uri=https://XXXXXXXXXXXXXXXXXXXX.church.tools/ ;api_user=XXXXXXXXXXXXXXXXXXXX ;api_password=XXXXXXXXXXXXXXXXXXXX -;dn_lower_case=true \ No newline at end of file +;dn_lower_case=true +;email_lower_case=true \ No newline at end of file diff --git a/ctldap.js b/ctldap.js index 0278f8c..f86fe8b 100644 --- a/ctldap.js +++ b/ctldap.js @@ -15,7 +15,6 @@ var path = require('path'); var config = ini.parse(fs.readFileSync(path.resolve(__dirname, 'ctldap.config'), 'utf-8')); if (config.debug) { console.log("Debug mode enabled, expect lots of output!"); - console.dir(config); } if (config.ldap_base_dn) { @@ -48,6 +47,15 @@ Object.keys(config.sites).map(function(sitename, index) { return s; } } + if (site.email_lower_case || ((site.email_lower_case === undefined) && config.email_lower_case)) { + site.compatTransformEmail = function (s) { + return s ? s.toLowerCase() : s; + } + } else { + site.compatTransformEmail = function (s) { + return s; + } + } if (site.ct_uri.slice(-1) !== "/") { site.ct_uri += "/"; } @@ -204,8 +212,8 @@ function requestUsers (req, res, next) { postalCode: v.plz, l: v.ort, sn: v.name, - email: v.email, - mail: v.email, + email: site.compatTransformEmail(v.email), + mail: site.compatTransformEmail(v.email), objectclass: ['CTPerson'], memberof: (results.userGroups[v.id] || []).map(function (cn) { return site.compatTransform(site.fnGroupDn({ cn: cn }));