Change model of password changing

master3.3
Mike Hiretsky 12 years ago
parent ccc222ccc5
commit 16aeb5db64

@ -746,7 +746,8 @@ class Install(color_print):
# migrate users
self.startTask(_("Migrating users"))
objMigrate = migrate(targetDistr.getDirectory())
if not objMigrate.migrate(self.clVars.Get('cl_migrate_data'),[],[]):
if not objMigrate.migrate(self.clVars.Get('cl_migrate_data'),
self.clVars.Get('cl_migrate_root_pwd'),[],[],):
raise InstallError(_("Failed to migrate users onto the new system"))
self.endTask()

@ -316,13 +316,13 @@ class migrate(color_print):
return True
return False
def addUserToDefaultGroups(self, userName):
def addUserToGroups(self, userName, userGroups):
"""Add users to groups"""
dataGroups = []
for data in self.dataGroups:
groupName = data[0]
if groupName in self.newUserGroups:
if groupName in userGroups:
usersInGroup = data[3].split(',')
if not userName in usersInGroup:
usersInGroup.append(userName)
@ -331,6 +331,11 @@ class migrate(color_print):
self.dataGroups = dataGroups
return self.dataGroups
def addUserToDefaultGroups(self, userName):
"""Add users to default groups"""
return self.addUserToGroups(userName,self.newUserGroups)
def changePassword(self, userName, pwdHash, maxDays="99999", warnDays="7"):
if not filter(lambda x: x[0]==userName, self.dataUsers):
raise MigrationError(_("User %s not found")%userName)
@ -356,7 +361,7 @@ class migrate(color_print):
self.dataShadow[indexFoundUser] = shadowList
return True
def addUser(self, userName, pwdHash):
def addUser(self, userName, userGroups, pwdHash):
"""Add user"""
# find user
if filter(lambda x: x[0]==userName, self.dataUsers):
@ -382,8 +387,8 @@ class migrate(color_print):
# add shadow
if not self.changePassword(userName, pwdHash):
return False
# add user to defaulr groups
self.addUserToDefaultGroups(userName)
# add user to default groups
self.addUserToGroups(userName,userGroups)
return True
def checkPermFiles(self):
@ -419,7 +424,7 @@ class migrate(color_print):
"""Save /etc/passwd /etc/group /etc/shadow to new system"""
listFilesThisSystem = [migrateGroups.fileGroups,migrateUsers.filePasswd,
migrateShadow.fileShadow]
listFiles = map(lambda x:(pathJoin(self.prefixNewSystem,x),
listFiles = map(lambda x:(pathJoin(self.prefixNewSystem,x),
pathJoin(self.prefixNewSystem,x+"-")),
listFilesThisSystem)
listData = [self.dataGroups, self.dataUsers, self.dataShadow]
@ -462,11 +467,13 @@ class migrate(color_print):
raise DistributiveError(
_("Failed to create the user's home directory"))
def migrate(self, addUsersList=[], pwdUsersList=[], existsMigrateUsers=[]):
def migrate(self, addUsersList=[], rootPwd="",
pwdUsersList=[], existsMigrateUsers=[]):
"""Migrate users ang groups to new system"""
if not self.checkPermFiles():
return False
migrateUsers = map(lambda x: x[0], addUsersList + pwdUsersList)
migrateUsers = ["root"]+\
map(lambda x: x[0], addUsersList + pwdUsersList)
for existMigrUser in existsMigrateUsers:
if not existMigrUser in migrateUsers:
migrateUsers.append(existMigrUser)
@ -487,10 +494,10 @@ class migrate(color_print):
maxDays=maxDays,
warnDays=warnDays):
return False
for userName, pwdHash in addUsersList:
for userName, userGroups, pwdHash in [["root",[],rootPwd]]+addUsersList:
#if self.isSystemUser(userName):
# raise MigrationError(_("%s is a system user") %userName)
ret = self.addUser(userName, pwdHash)
ret = self.addUser(userName, userGroups, pwdHash)
if not ret:
return False
elif ret == "EXISTS":

@ -55,6 +55,7 @@ class InstallInfo(ClassSerializer):
os_install_locale_lang = String
os_install_clock_timezone = String
cl_migrate_root_pwd = String
cl_migrate_data = Array(Array(String))
cl_autologin = String
os_install_net_fqdn = String
@ -83,6 +84,7 @@ class InstallInfo(ClassSerializer):
Default = Array(String)
CheckOnly = Boolean
CheckAll = Boolean
class catchExcept:
def __init__(self,f):
@ -128,10 +130,13 @@ class Wsdl:
dv.processRefresh()
if info:
checkonly = info.CheckOnly
checkall = info.CheckAll
else:
checkonly = False
checkall = False
errors = map(lambda x:ReturnedMessage(**x),
dv.checkGroups(info,allvars=not checkonly))
dv.checkGroups(info,allvars=checkall or \
not checkonly))
if errors:
return errors
if checkonly:
@ -191,7 +196,7 @@ class Wsdl:
expert=('os_install_net_dns','os_install_net_dns_search',
'os_install_net_route_data',))
dv.addGroup(_("Users"),
normal=('cl_migrate_data','cl_autologin'),
normal=('cl_migrate_root_pwd','cl_migrate_data','cl_autologin'),
hide=('cl_migrate_data',),
brief=('cl_migrate_user',))
dv.addGroup(_("Video"),

@ -283,7 +283,7 @@ class VariableClImageFilename(Variable,DistroRepository):
return self.getImage(self.Get('os_install_scratch'),
self.Get('os_install_root_type'),
self.Get('cl_image_path'),
arch,shortname,ver,build)
arch,shortname,ver,build) or ""
def check(self,isoimage):
"""Set image file"""

@ -19,10 +19,11 @@ import sys
import re
from os import path
from calculate.lib.datavars import Variable,VariableError,ReadonlyVariable, \
TableVariable
TableVariable,PasswordError
from calculate.install.fs_manager import FileSystemManager
from calculate.lib.utils.files import readFile,getProgPath,process
from calculate.lib.utils.common import getPasswdUsers
from calculate.lib.utils.files import (readFile,getProgPath,process,
readLinesFile)
from calculate.lib.utils.common import getPasswdUsers,getUserGroups,getGroups
from calculate.lib.utils.portage import isPkgInstalled
from crypt import crypt
from calculate.lib.encrypt import encrypt
@ -102,6 +103,51 @@ class VariableOsFormatUse(ReadonlyVariable):
if path.exists(FileSystemManager.supportFS[x]["format"])
else "no", self.Get('os_format_type'))
class VariableClMigrateRootPwd(UserHelper,Variable):
"""
Root password
"""
type = "password"
opt = ["--root-password"]
metavalue = 'PASSWORD'
untrusted = True
def init(self):
self.help = _("to specify root password")
self.label = _("Root password")
def get(self):
rootPasswd = map(lambda x:x[1],
filter("root".__eq__,
map(lambda x:x.split(':')[0:2],
readLinesFile('/etc/shadow'))))
if rootPasswd:
rootPasswd = rootPasswd[0]
else:
rootPasswd = ""
# if root password is "root"
if rootPasswd:
salt = "".join(rootPasswd.rpartition("$")[:1])
if salt and crypt("root", salt) == rootPasswd:
rootPasswd = ""
return rootPasswd or ""
def set(self,value):
"""
Encrypt password
"""
reCheck = re.compile("^\$[^$]+\$[^$]+\$.*$")
encryptObj = encrypt()
if reCheck.match(value) or not value:
return value
else:
return encryptObj.getHashPasswd(value, "shadow_ssha256")
def check(self,value):
if not value:
raise PasswordError(_("Missed a password for user %s")%"root")
class VariableClMigrateData(UserHelper,TableVariable):
"""
User migrate data table
@ -109,7 +155,8 @@ class VariableClMigrateData(UserHelper,TableVariable):
type = 'table'
opt = ["--users","-u"]
metavalue = 'USERS'
source = ['cl_migrate_user','cl_migrate_user_pwd']
source = ['cl_migrate_user','cl_migrate_user_groups',
'cl_migrate_user_pwd']
untrusted = True
def init(self):
@ -127,9 +174,44 @@ class VariableClMigrateUser(UserHelper,Variable):
def get(self):
"""
Migrating users (root and users above 1000 uid)
Migrating users (users above 1000 uid)
"""
return getPasswdUsers()
return filter("root".__ne__,getPasswdUsers())
class VariableClMigrateUserGroups(UserHelper,Variable):
"""
Migrate users groups
"""
type = 'choice-list-list'
defaultGroupList = ["users","wheel","audio","cdrom","video",
"cdrw","usb","plugdev","games","lp","scanner","uucp"]
def getDefaultGroups(self):
return list(set(self.defaultGroupList)&set(getGroups()))
def init(self):
self.label = _("Groups")
def set(self,value):
value = map(lambda x: x \
if x and any(x) else self.getDefaultGroups(),
value)
return value
def get(self):
"""
User groups
"""
passwdList = getPasswdUsers()
return map(lambda x:getUserGroups(x) \
if x in passwdList else self.getDefaultGroups(),
self.Get('cl_migrate_user'))
def choice(self):
"""
Available groups
"""
return getGroups()
class VariableClMigrateUserPwd(UserHelper,Variable):
"""
@ -157,26 +239,13 @@ class VariableClMigrateUserPwd(UserHelper,Variable):
shadowData = map(lambda x: (x[0], x[1]), shadowData)
shadowUsers = map(lambda x: x[0], shadowData)
for userName in migrateusers:
if userName in ("root",):
if userName in shadowUsers:
userData = filter(lambda x: x[0]==userName,
shadowData)
hashPwd = userData[0][1]
salt = "".join(hashPwd.rpartition("$")[:1])
if salt and crypt(userName, salt) == hashPwd:
retList.append("")
else:
retList.append(hashPwd)
else:
retList.append("")
if userName in shadowUsers:
userData = filter(lambda x: x[0]==userName,
shadowData)
hashPwd = userData[0][1]
retList.append(hashPwd)
else:
if userName in shadowUsers:
userData = filter(lambda x: x[0]==userName,
shadowData)
hashPwd = userData[0][1]
retList.append(hashPwd)
else:
retList.append("")
retList.append("")
return retList
def check(self,value):
@ -185,7 +254,7 @@ class VariableClMigrateUserPwd(UserHelper,Variable):
"""
for user,pwd in zip(self.Get('cl_migrate_user'),value):
if not pwd:
raise VariableError(
raise PasswordError(
_("Missed a password for user %s")%user)
def set(self,value):

Loading…
Cancel
Save