Skip to content

Commit f56178b

Browse files
committed
Added configuration option to disable referrals.
The options is boolean, header name is 'X-Ldap-DisableReferrals' and the command-line switch is '--disable-referrals', default value is false.
1 parent 732eb15 commit f56178b

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

nginx-ldap-auth-daemon.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ class LDAPAuthHandler(AuthHandler):
149149
'realm': ('X-Ldap-Realm', 'Restricted'),
150150
'url': ('X-Ldap-URL', None),
151151
'starttls': ('X-Ldap-Starttls', 'false'),
152+
'disable_referrals': ('X-Ldap-DisableReferrals', 'false'),
152153
'basedn': ('X-Ldap-BaseDN', None),
153154
'template': ('X-Ldap-Template', '(cn=%(username)s)'),
154155
'binddn': ('X-Ldap-BindDN', ''),
@@ -208,9 +209,9 @@ def do_GET(self):
208209
if ctx['starttls'] == 'true':
209210
ldap_obj.start_tls_s()
210211

211-
# See http://www.python-ldap.org/faq.shtml
212-
# uncomment, if required
213-
# ldap_obj.set_option(ldap.OPT_REFERRALS, 0)
212+
# See https://www.python-ldap.org/en/latest/faq.html
213+
if ctx['disable_referrals'] == 'true':
214+
ldap_obj.set_option(ldap.OPT_REFERRALS, 0)
214215

215216
ctx['action'] = 'binding as search user'
216217
ldap_obj.bind_s(ctx['binddn'], ctx['bindpasswd'], ldap.AUTH_SIMPLE)
@@ -275,6 +276,9 @@ def exit_handler(signal, frame):
275276
group.add_argument('-s', '--starttls', metavar="starttls",
276277
default="false",
277278
help=("Establish a STARTTLS protected session (Default: false)"))
279+
group.add_argument('--disable-referrals', metavar="disable_referrals",
280+
default="false",
281+
help=("Sets ldap.OPT_REFERRALS to zero (Default: false)"))
278282
group.add_argument('-b', metavar="baseDn", dest="basedn", default='',
279283
help="LDAP base dn (Default: unset)")
280284
group.add_argument('-D', metavar="bindDn", dest="binddn", default='',
@@ -298,6 +302,7 @@ def exit_handler(signal, frame):
298302
'realm': ('X-Ldap-Realm', args.realm),
299303
'url': ('X-Ldap-URL', args.url),
300304
'starttls': ('X-Ldap-Starttls', args.starttls),
305+
'disable_referrals': ('X-Ldap-DisableReferrals', args.disable_referrals),
301306
'basedn': ('X-Ldap-BaseDN', args.basedn),
302307
'template': ('X-Ldap-Template', args.filter),
303308
'binddn': ('X-Ldap-BindDN', args.binddn),

nginx-ldap-auth.conf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ http {
103103
# Set the LDAP template by uncommenting the following directive.
104104
#proxy_set_header X-Ldap-Template "(sAMAccountName=%(username)s)";
105105

106+
# (May be required if using Microsoft Active Directory and
107+
# getting "In order to perform this operation a successful bind
108+
# must be completed on the connection." errror)
109+
#proxy_set_header X-Ldap-DisableReferrals "true";
110+
106111
# (Optional if using OpenLDAP as the LDAP server) Set the LDAP
107112
# template by uncommenting the following directive and replacing
108113
# '(cn=%(username)s)' which is the default set in

0 commit comments

Comments
 (0)