|
|
|
@ -65,17 +65,21 @@ class ldapUser(_error):
|
|
|
|
|
# Подключение к LDAP
|
|
|
|
|
conLdap = False
|
|
|
|
|
|
|
|
|
|
def getServerDataUser(self, bindData=False):
|
|
|
|
|
def getDataInLdapConf(self, bindData=False, cache=True):
|
|
|
|
|
"""Получение данных из /etc/ldap.conf"""
|
|
|
|
|
fileName = "/etc/ldap.conf"
|
|
|
|
|
getStrList = lambda x: reduce(lambda x,y: [x,y.upper()],([x]*2))
|
|
|
|
|
data = [("host",'host'),
|
|
|
|
|
("usersDN",'nss_base_passwd'),
|
|
|
|
|
("groupsDN",'nss_base_group')]
|
|
|
|
|
if bindData:
|
|
|
|
|
data += [("bindDn",'binddn'), ("bindPw",'bindpw')]
|
|
|
|
|
workData = map(lambda x: (x[0],getStrList(x[1]),len(x[1])), data)
|
|
|
|
|
namesData = map(lambda x: x[0], data)
|
|
|
|
|
# Данные из кеша, если он есть
|
|
|
|
|
if cache and self._dictData and\
|
|
|
|
|
set(self._dictData.keys())<=set(namesData):
|
|
|
|
|
return self._dictData
|
|
|
|
|
fileName = "/etc/ldap.conf"
|
|
|
|
|
getStrList = lambda x: reduce(lambda x,y: [x,y.upper()],([x]*2))
|
|
|
|
|
workData = map(lambda x: (x[0],getStrList(x[1]),len(x[1])), data)
|
|
|
|
|
dictData = {}
|
|
|
|
|
splList = (" ", "\t")
|
|
|
|
|
try:
|
|
|
|
@ -98,19 +102,20 @@ class ldapUser(_error):
|
|
|
|
|
self.setError(_("Can not open %s")%fileName)
|
|
|
|
|
return False
|
|
|
|
|
if set(dictData.keys()) == set(namesData):
|
|
|
|
|
# Кеширование данных
|
|
|
|
|
if cache:
|
|
|
|
|
self._dictData.clear()
|
|
|
|
|
self._dictData.update(dictData)
|
|
|
|
|
return dictData
|
|
|
|
|
else:
|
|
|
|
|
return {}
|
|
|
|
|
|
|
|
|
|
def getUserLdapInfo(self, userName):
|
|
|
|
|
"""Выдаем информацию о пользователе из LDAP"""
|
|
|
|
|
if not "bindDn" in self._dictData:
|
|
|
|
|
# Получаем информацию из /etc/ldap.conf
|
|
|
|
|
retData = self.getServerDataUser(bindData=True)
|
|
|
|
|
if retData:
|
|
|
|
|
self._dictData = retData
|
|
|
|
|
else:
|
|
|
|
|
return {}
|
|
|
|
|
# Получаем информацию из /etc/ldap.conf
|
|
|
|
|
retData = self.getDataInLdapConf(bindData=True, cache=True)
|
|
|
|
|
if not retData:
|
|
|
|
|
return {}
|
|
|
|
|
bindDn = self._dictData["bindDn"][0]
|
|
|
|
|
bindPw = self._dictData["bindPw"][0]
|
|
|
|
|
host = self._dictData["host"][0]
|
|
|
|
|