Add check of the current user password when running the command cl-passwd.

master
Самоукин Алексей 14 years ago
parent 2aba13bced
commit dcc46a3c08

@ -247,6 +247,7 @@ imp_cl_help = cl_utils2.cl_help
# Форматированный вывод
imp_cl_smcon = cl_utils2.cl_smartcon
class cl_client(imp_cl_err, imp_cl_xml, imp_cl_help, imp_cl_smcon):
"""Основной класс для работы клиентских приложений"""
# Пути к профилям объединяемых с системными
@ -436,14 +437,7 @@ if necessary, removes from domain")
'helpChapter':_("Common options"),
'help':_("not synchronize the user preferences, is used in \
conjunction with the 'login' or 'logout'")
},
{'progAccess':(3,),
'shortOption':"P",
'helpChapter':_("Common options"),
'help':_("use password for the user account") +\
" (" + _("from standard input") + ")"
},
}
]
self._cl_help__setParamHelp()
@ -756,6 +750,23 @@ conjunction with the 'login' or 'logout'")
else:
return dirsFiles
def checkUserPwdLDAP(self, server, userDN, password):
"""Проверка пароля Unix пользователя на сервере"""
ldapInit = ldap.initialize("ldap://%s"%server)
errMessage = ""
try:
ldapInit.bind_s(userDN, password)
except ldap.INVALID_CREDENTIALS:
errMessage = _("Your username or password is incorrect.")
return False, errMessage
except ldap.LDAPError, e:
if type(e.message) == dict and e.message.has_key('desc'):
errMessage = e.message['desc']
else:
errMessage = e
return False, errMessage
return True, errMessage
def setUserPasswordToServer(self, options):
"""Установка пароля пользователя на сервере"""
# Проверяем на root
@ -764,12 +775,30 @@ conjunction with the 'login' or 'logout'")
self.printWARNING(\
_("The program can be executed from a non-root user"))
return False
# Создаем объект переменных
# Создаем объект переменных
self.createClVars()
# DNS имя хоста
server = self.clVars.Get("sr_samba_host")
if not server:
self.printERROR(_("The computer is not in domain"))
return False
# Получаем старый пароль пользователя
curPassword = self.getUserPassword(_("Enter current password"))
if not curPassword:
self.printERROR(_("Current password is empty"))
return False
userDN = self.addDN("uid=%s"%os.environ["USER"],
self.relUsersDN,
self.clVars.Get("ld_base_dn"))
# Проверяем в LDAP сервере текущий пароль пользователя
ret, err = self.checkUserPwdLDAP(server, userDN, curPassword)
if not ret:
self.printERROR(err)
return False
optPasswd = options
if not options:
optPasswd = {"p":""}
password = self.getUserPwd(optPasswd, "p", "P")
password = self.getUserPwd(optPasswd, "p", False)
if password == False:
return False
# Записываем пароль пользователя в переменную
@ -784,8 +813,10 @@ conjunction with the 'login' or 'logout'")
for name, value in data:
self.clVars.Write(name, value, True, "default","server")
self.clVars.Set("cl_env_path",oldEnvPath,True)
self.printOK(_("Password changed in user %s")%os.environ["USER"] + \
self.printOK(_("Changed password of user %s")%os.environ["USER"] + \
" ...")
self.printWARNING(_("Password will be changed when you logout from the \
X session"))
return True
def getUserPassword(self, pwDialog=False):

Loading…
Cancel
Save