Added migrate users to the new system

master3.3
Самоукин Алексей 14 years ago
parent 21b79cde34
commit e6cb929796

@ -44,13 +44,14 @@ from cl_string import tableReport
from time import sleep
from subprocess import Popen,PIPE
from server.utils import dialogYesNo
from cl_migrate_users import migrate
from cl_utils import getUserPassword
from encrypt import encrypt
tr = lang()
tr.setGlobalDomain('cl_install')
tr.setLanguage(sys.modules[__name__])
class InstallError(Exception):
"""Installation Error"""
pass
@ -648,8 +649,8 @@ class cl_install(color_print):
sleep(1)
self.defaultPrint("\b\b \n")
def prepareBoot(self,targetDistr, bootDisk="0"):
self.installBootloader(targetDistr, bootDisk="0")
def prepareBoot(self,targetDistr, grubDisk="0"):
self.installBootloader(targetDistr, grubDisk="0")
def getTargetDistributive(self,disk,fileSystem="reiserfs",isFormat=False):
#if buildermode:
@ -971,8 +972,34 @@ class cl_install(color_print):
self.clVars.Get('os_disk_part'))
return title, headerList, dataList
def installSystem(self, force=False, bootDisk=None):
def getPwdHashUser(self, userName):
cl_overriding.printSUCCESS(_("Enter password for user %s") %userName)
userPwd = getUserPassword()
if userPwd is False:
return False
encryptObj = encrypt()
pwdHash = encryptObj.getHashPasswd(userPwd, "shadow_ssha256")
if pwdHash is False:
return False
return pwdHash
def generateHashUsers(self, users):
"""Generate pwd hash from users"""
listAddUsers = []
for user in users:
hashFuct = lambda x: self.getPwdHashUser(x)
listAddUsers.append((user, hashFuct))
return listAddUsers
def generateHashRoot(self):
"""Generate pwd hash from root"""
hashFuct = lambda x: self.getPwdHashUser(x)
return [("root", hashFuct,"","")]
def installSystem(self, force=False, bootDisk=None, users=[]):
"""install System by current variable enviroment"""
if not users:
users = []
sourceDistr = None
targetDistr = None
error = None
@ -1093,6 +1120,13 @@ the system") + " (yes/no)"
self.applyTemplates(targetDistr.getDirectory())
# mount bind mount points
targetDistr.postinstallMountBind()
# migrate users
self.printSUCCESS(_("Migrate users"))
addUsers = self.generateHashUsers(users)
changePwdUsers = self.generateHashRoot()
objMigrate = migrate(targetDistr.getDirectory())
if not objMigrate.migrate(addUsers, changePwdUsers):
raise InstallError(_("Can not migrate users to new system"))
# change boot config
self.printSUCCESS(_("Prepare system for reboot"))
if bootDiskGrub:

@ -65,6 +65,12 @@ CMD_OPTIONS = [{'shortOption':"T",
'type':'choice',
'choices':['cld','cds','cls','css','cldg','cldx'],
'help':_("select operation system")
},
{'shortOption':"u",
'longOption':"user",
'optVal':"USER",
'action':'append',
'help':_("add user to installed system")
}]
#{'shortOption':"b",
#'longOption':"build",
@ -271,8 +277,9 @@ class install_cmd(cl_install,opt,share_cmd):
else:
return False
def installSystem(self, force=False, bootDisk=None):
if cl_install.installSystem(self, force=force, bootDisk=bootDisk):
def installSystem(self, force=False, bootDisk=None, users=[]):
if cl_install.installSystem(self, force=force, bootDisk=bootDisk,
users=users):
return True
else:
return False

@ -62,7 +62,9 @@ class migrateGroups(_shareData):
"""Get data system groups in new system"""
fileName = pathJoin(self.prefixNewSystem, self.fileGroups)
return filter(lambda x:\
self._reNumb.match(x[2]) and int(x[2])<self.minGid, self.getData(fileName=fileName))
self._reNumb.match(x[2]) and\
(int(x[2])>self.maxGid or int(x[2])<self.minGid),
self.getData(fileName=fileName))
def getNewProcessedData(self):
"""Get processed data migrate groups in new system"""
@ -115,7 +117,8 @@ class migrateUsers(_shareData):
"""Get data system users in new system"""
fileName = pathJoin(self.prefixNewSystem, self.filePasswd)
return filter(lambda x:\
self._reNumb.match(x[2]) and int(x[2])<self.minId, self.getData(fileName=fileName))
self._reNumb.match(x[2]) and\
(int(x[2]>self.maxId) or int(x[2])<self.minId), self.getData(fileName=fileName))
def getNewProcessedData(self):
"""Get processed data migrate groups in new system"""
@ -279,7 +282,10 @@ class migrate(color_print):
if data[0]==userName:
indexFoundUser = i
break
#self.dataShadow = filter(lambda x: x[0]!=userName, self.dataShadow)
if callable(pwdHash):
pwdHash = pwdHash(userName)
if pwdHash is False:
return False
shadowDict = {"user":userName,
"hash":pwdHash,
"days":str(int(time.time()/86400)),
@ -315,9 +321,11 @@ class migrate(color_print):
userList = userline.split(":")
self.dataUsers.append(userList)
# add shadow
self.changePassword(userName, pwdHash)
if not self.changePassword(userName, pwdHash):
return False
# add user to defaulr groups
self.addUserToDefaultGroups(userName)
return True
def checkPermFiles(self):
"""Check permission files"""
@ -362,7 +370,8 @@ class migrate(color_print):
pwdHash = encryptObj.getHashPasswd(pwd, "shadow_ssha256")
if pwdHash is False:
return False
self.addUser("guest", pwdHash)
if not self.addUser("guest", pwdHash):
return False
return True
def migrate(self, addUsersList=[], pwdUsersList=[]):
@ -380,16 +389,17 @@ class migrate(color_print):
self.dataUsers = reduce(lambda x,y: x+y, dataUsers, [])
self.dataShadow = reduce(lambda x,y: x+y, dataShadow, [])
self.addThisUsersToGroups(thisUsers)
for userName, pwdHash in addUsersList:
if self.isSystemUser(userName):
self.printERROR(_("%s is a system user") %userName)
return False
self.addUser(userName, pwdHash)
for userName, pwdHash, maxDays, warnDays in pwdUsersList:
if not self.changePassword(userName, pwdHash,
maxDays=maxDays,
warnDays=warnDays):
return False
for userName, pwdHash in addUsersList:
if self.isSystemUser(userName):
self.printERROR(_("%s is a system user") %userName)
return False
if not self.addUser(userName, pwdHash):
return False
if not addUsersList:
# add user guest
if not self.createUserGuest():

@ -57,7 +57,8 @@ if __name__ == "__main__":
#if not install.applyTemplatesForSystem():
#sys.exit(1)
#else:
if not install.installSystem(force=options.f, bootDisk=options.mbr):
if not install.installSystem(force=options.f, bootDisk=options.mbr,
users=options.u):
sys.exit(1)
if not install.writeVars(options):
sys.exit(1)

Loading…
Cancel
Save