#Users Accounts path
bind_dn = "cn="+user+",ou=" +user[0]+",OU=Useraccounts,OU=Mtp,DC=us,DC=bosch,DC=com" and "cn="+user+",ou=" +user[0]+",OU=Useraccounts,OU=Ca1,DC=br,DC=bosch,DC=com"
bind_pass = password
Если я сделаю «и», он будет искать только во второй папке.
#Users Accounts path
bind_dn = "cn="+user+",ou=" +user[0]+",OU=Useraccounts,OU=Mtp,DC=us,DC=bosch,DC=com" or "cn="+user+",ou=" +user[0]+",OU=Useraccounts,OU=Ca1,DC=br,DC=bosch,DC=com"
bind_pass = password
Когда я это сделаю »или« он будет искать только в первой папке
Это для LDAP аутентификация, в этих папках выполняется поиск имен пользователей, чтобы убедиться, что они существуют. Есть ли функция, которую я могу использовать, чтобы этот bind_dn искал пользователей в обеих папках, а не только в одной или другой.
Функция для подключения LDAP
def connect_ldap (user, password):
#CHANGE TO YOUR LDAP SERVER HERE
#LDAP Server
ldap_server = "bosch.com"
#CHANGE TO YOUR BIND_DN PATH HERE
#Users Accounts path
bind_dn = "cn="+user+",ou=" +user[0]+",OU=Useraccounts,OU=Mtp,DC=us,DC=bosch,DC=com" and "cn="+user+",ou=" +user[0]+",OU=Useraccounts,OU=Ca1,DC=br,DC=bosch,DC=com"
bind_pass = password
#Config the server and connection
server = Server(ldap_server, port=int(636), use_ssl=bool(True))
conn = Connection(server=server, user=bind_dn, password=bind_pass)
#First make a touchbase in the LDAP Server with the credentials to authenticate
connection_status = conn.bind()
print("Status: ",connection_status)
# If the user and pass is correct it will continue the script
if connection_status == True:
#Filter the search to Groups
search_filter = '(objectClass=group)'
try:
#CHANGE TO YOUR GROUP SEARCH HERE
#This search will return a members list of the selected group
conn.search("CN=CI/OSR-NA Staff,OU=Recipients,OU=MAIL34,OU=DL,OU=MSX,DC=us,DC=bosch,DC=com",
search_filter, search_scope=SUBTREE, attributes=['member'])
members = []
#Set the list in a variable
for entry in conn.entries:
members = entry.member.values
print("\nGroup Members: \n\n", members, "\n")
status = "Permission Denied"
#Check if the user is part of the group
for member in members:
#If the user is part of the group it will return "Permission Allowed" and terminate the script.
if user.lower() in member.lower() or user.upper() in member.upper():
status = "Permission Allowed"
return status
#If the user is not part of the group it will return "Permission Denied" and terminate the script.
if status == "Permission Denied":
return status
except Exception as e:
return e
# If the user and pass is incorrect it will return "False" and terminate the script.
elif connection_status == False:
return "Connection error"