diff --git a/pym/cl_fill_install.py b/pym/cl_fill_install.py index ef9b8bb..2b85230 100644 --- a/pym/cl_fill_install.py +++ b/pym/cl_fill_install.py @@ -16,6 +16,7 @@ import os import re +from crypt import crypt import cl_overriding from cl_datavars import glob_attr from os.path import join as pathjoin, exists as pathexists @@ -899,3 +900,52 @@ class fillVars(object, glob_attr): return ("".join(filter(lambda x: not roothd in x, reGrubEntry.findall(grubconf)))).strip() return "" + + def get_cl_migrate_users(self): + """migrate users""" + retList = [] + fileName = "/etc/passwd" + if access(fileName, R_OK): + maxId = 65000 + minId = 500 + reNumb = re.compile("^\d+$") + lenData=7 + userData = filter(lambda x: len(x)==lenData, + map(lambda x: x.rstrip().split(":"), + open(fileName))) + userData = filter(lambda x:\ + reNumb.match(x[2]) and minId<=int(x[2])<=maxId, + userData) + retList = ["root"] +map(lambda x: x[0], userData) + return retList + + def get_cl_migrate_users_change_pwd(self): + retList = [] + fileName = "/etc/shadow" + if access(fileName, R_OK): + migrateusers = self.Get("cl_migrate_users") + lenData=9 + shadowData = filter(lambda x: len(x)==lenData, + map(lambda x: x.rstrip().split(":"), + open(fileName))) + shadowData = filter(lambda x: x[0] in migrateusers, shadowData) + 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("Yes") + else: + retList.append("No") + else: + retList.append("Yes") + else: + if userName in shadowUsers: + retList.append("No") + else: + retList.append("Yes") + return retList diff --git a/pym/cl_migrate_users.py b/pym/cl_migrate_users.py index 2cfb47e..99cf349 100644 --- a/pym/cl_migrate_users.py +++ b/pym/cl_migrate_users.py @@ -433,9 +433,12 @@ class currentUsers(migrate): if not self.checkPermFiles(): return False getDataInFile = _shareData().getDataInFile - self.dataUsers = getDataInFile(fileName=migrateUsers.filePasswd,lenData=7) - self.dataGroups = getDataInFile(fileName=migrateGroups.fileGroups,lenData=4) - self.dataShadow = getDataInFile(fileName=migrateShadow.fileShadow,lenData=9) + self.dataUsers = getDataInFile(fileName=migrateUsers.filePasswd, + lenData=7) + self.dataGroups = getDataInFile(fileName=migrateGroups.fileGroups, + lenData=4) + self.dataShadow = getDataInFile(fileName=migrateShadow.fileShadow, + lenData=9) getHash = encrypt().getHashPasswd for userName, pwd in zip(users_passwd[0::2], users_passwd[1::2]): diff --git a/pym/cl_vars_install.py b/pym/cl_vars_install.py index 5e05d82..3e23c99 100644 --- a/pym/cl_vars_install.py +++ b/pym/cl_vars_install.py @@ -264,3 +264,9 @@ class Data: # current grub os_grub_conf = {} + + # migrate users + cl_migrate_users = {} + + # migrate users who need to change passwords + cl_migrate_users_change_pwd = {}