|
|
|
@ -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):
|
|
|
|
|