@@ -165,37 +165,28 @@ def doLdapLogin(username, password):
165
165
if LdapServer == None or LdapServer == "" :
166
166
return False
167
167
try :
168
- import ldap
169
- except ImportError :
170
- LogError ("LDAP import not found, run 'sudo apt-get -y install python-ldap'" )
171
- return False
172
-
173
- conn = ldap .initialize (LdapServer )
174
- conn .protocol_version = 3
175
- conn .set_option (ldap .OPT_REFERRALS , 0 )
176
- try :
177
- conn .simple_bind_s (username , password )
178
- except :
179
- LogError ("Invalid login via LDAP: " + username )
168
+ from ldap3 import Server , Connection , ALL , NTLM
169
+ except ImportError as importException :
170
+ LogError ("LDAP3 import not found, run 'sudo pip install ldap3 && sudo pip3 install ldap3'" )
171
+ LogError (importException )
180
172
return False
181
173
182
174
HasAdmin = False
183
175
HasReadOnly = False
184
176
SplitName = username .split ('\\ ' )
177
+ DomainName = SplitName [0 ]
178
+ DomainName = DomainName .strip ()
185
179
AccountName = SplitName [1 ]
186
180
AccountName = AccountName .strip ()
187
- ldap .set_option (ldap .OPT_X_TLS_REQUIRE_CERT , ldap .OPT_X_TLS_NEVER )
188
- search_filter = "(&(objectClass=*)(member=uid=" + AccountName + ",$LdapBase))"
189
- account_filter = "sAMAccountName=" + AccountName
190
- results = conn .search_s (LdapBase , ldap .SCOPE_SUBTREE , account_filter , ['memberOf' ])
191
- for result in results :
192
- if type (result [1 ]) is dict :
193
- for groupList in result [1 ].values ():
194
- for group in groupList :
195
- if group .upper ().find ("CN=" + LdapAdminGroup .upper ()+ "," ) >= 0 :
196
- HasAdmin = True
197
- elif group .upper ().find ("CN=" + LdapReadOnlyGroup .upper ()+ "," ) >= 0 :
198
- HasReadOnly = True
181
+ server = Server (LdapServer , get_info = ALL )
182
+ conn = Connection (server , user = '{}\\ {}' .format (DomainName , AccountName ), password = password , authentication = NTLM , auto_bind = True )
183
+ conn .search ('dc=skipfire,dc=local' , '(&(objectclass=user)(sAMAccountName=' + AccountName + '))' , attributes = ['memberOf' ])
184
+ for user in sorted (conn .entries ):
185
+ for group in user .memberOf :
186
+ if group .upper ().find ("CN=" + LdapAdminGroup .upper ()) >= 0 :
187
+ HasAdmin = True
188
+ elif group .upper ().find ("CN=" + LdapReadOnlyGroup .upper ()) >= 0 :
189
+ HasReadOnly = True
199
190
200
191
session ['logged_in' ] = HasAdmin or HasReadOnly
201
192
session ['write_access' ] = HasAdmin
0 commit comments