Исправлено изменение параметра use grub password при переустановке

master-3.5 3.5.2.11
parent f4f2940738
commit b9f5aad68e

@ -58,6 +58,21 @@ class UserHelper(VariableInterface):
return ""
class GrubHelper(VariableInterface):
grub_passwd_file = "/etc/grub.d/07_passwd"
def read_hash_from_passwd(self):
"""
Получить пароль из конфигурационного файла grub
"""
data = readFile(self.grub_passwd_file)
reRootPwd = re.compile("password_pbkdf2 root (\S+)")
pwd = reRootPwd.search(data)
if pwd:
return pwd.group(1)
return ""
class VariableOsInstallScratch(ReadonlyVariable):
"""
Install system in scratch mode
@ -104,7 +119,7 @@ class VariableOsFormatUse(ReadonlyVariable):
return map(self.checkFunc, self.Get('os_format_type'))
class VariableClMigrateRootPwdPlain(UserHelper, Variable):
class VariableClMigrateRootPwdPlain(GrubHelper, UserHelper, Variable):
"""
Root password
"""
@ -112,6 +127,7 @@ class VariableClMigrateRootPwdPlain(UserHelper, Variable):
opt = ["--root-password"]
metavalue = 'PASSWORD'
untrusted = True
check_after = ["cl_grub"]
def get(self):
shadow_pwd = self.Get('cl_migrate_root_shadow_pwd')
@ -126,6 +142,13 @@ class VariableClMigrateRootPwdPlain(UserHelper, Variable):
def check(self, value):
if not value and not self.Get('cl_migrate_root_shadow_pwd'):
raise PasswordError(_("Password for user %s missing") % "root")
# если plain пароля нет (есть только хэш), но требуется установить
# пароль на grub (cl_grub_passwd_set), при этом нет 07_passwd
if (value == self.stub_hash_value and
not self.read_hash_from_passwd() and
self.GetBool('cl_grub_passwd_set')):
raise PasswordError(_("Please specify root password "
"for the grub menu"))
class VariableClMigrateRootPwd(ReadonlyVariable):
@ -166,21 +189,6 @@ class VariableClMigrateRootShadowPwd(ReadonlyVariable):
return rootPasswd or ""
class GrubHelper(VariableInterface):
grub_passwd_file = "/etc/grub.d/07_passwd"
def read_hash_from_passwd(self):
"""
Получить пароль из конфигурационного файла grub
"""
data = readFile(self.grub_passwd_file)
reRootPwd = re.compile("password_pbkdf2 root (\S+)")
pwd = reRootPwd.search(data)
if pwd:
return pwd.group(1)
return ""
class VariableClGrubPasswdSet(GrubHelper, Variable):
"""
Использовать при установке системы пароль root как пароль для grub
@ -193,7 +201,7 @@ class VariableClGrubPasswdSet(GrubHelper, Variable):
self.label = _("Use root password for editing grub menu")
def get(self):
if (path.exists(self.grub_passwd_file) or
if (self.read_hash_from_passwd() or
self.Get('os_root_type_ext') in RootType.Live):
return Variable.On
else:
@ -212,12 +220,15 @@ class VariableClGrubPwd(GrubHelper, Variable):
self.label = _("Grub password")
def get(self):
system_action = self.Get('cl_action') == "system"
if self.GetBool('cl_grub_remove_pwd_set'):
return ""
use_grub_passwd = self.GetBool('cl_grub_passwd_set')
passwd_hash = self.read_hash_from_passwd()
if passwd_hash:
return passwd_hash
if self.GetBool('cl_grub_passwd_set'):
if not system_action or use_grub_passwd:
return passwd_hash
if use_grub_passwd:
value = self.Get('cl_migrate_root_pwd_plain')
if value and value != UserHelper.stub_hash_value:
enc = get_grub_hash()

Loading…
Cancel
Save