|
|
|
@ -129,6 +129,12 @@ calculate-server"),
|
|
|
|
|
'helpChapter':_("Common options"),
|
|
|
|
|
'help':_("create home directory for the new user account")
|
|
|
|
|
},
|
|
|
|
|
{'progAccess':(1,),
|
|
|
|
|
'longOption':"vars",
|
|
|
|
|
'optVal':_("TYPE_VAR"),
|
|
|
|
|
'helpChapter':_("Common options"),
|
|
|
|
|
'help':_("print variables (TYPE_VAR - all:full var)")
|
|
|
|
|
},
|
|
|
|
|
{'progAccess':(0,),
|
|
|
|
|
'shortOption':"s",
|
|
|
|
|
'longOption':"cl-server",
|
|
|
|
@ -245,6 +251,29 @@ calculate-server"),
|
|
|
|
|
else:
|
|
|
|
|
return ""
|
|
|
|
|
|
|
|
|
|
def searchLineInFile(self, name, fileName, numEl=0):
|
|
|
|
|
"""Ищет строку в которой есть название разделенное ':'
|
|
|
|
|
|
|
|
|
|
в файле похожем на /etc/passwd"""
|
|
|
|
|
if os.path.exists(fileName):
|
|
|
|
|
FD = open(fileName)
|
|
|
|
|
lines = FD.readlines()
|
|
|
|
|
FD.close()
|
|
|
|
|
lineFound = ""
|
|
|
|
|
for line in lines:
|
|
|
|
|
if name == line.split(":")[numEl]:
|
|
|
|
|
lineFound = line
|
|
|
|
|
break
|
|
|
|
|
if lineFound:
|
|
|
|
|
return lineFound
|
|
|
|
|
else:
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
def searchPasswdUser(self, userName):
|
|
|
|
|
"""Ищет пользователей в /etc/passwd"""
|
|
|
|
|
filePasswd = "/etc/passwd"
|
|
|
|
|
return self.searchLineInFile(userName, filePasswd)
|
|
|
|
|
|
|
|
|
|
def getUserUidGid(self, userName):
|
|
|
|
|
"""Выдаем uid и gid пользователя"""
|
|
|
|
|
searchUser = self.searchUnixUser(userName)
|
|
|
|
@ -314,17 +343,29 @@ calculate-server"),
|
|
|
|
|
"""
|
|
|
|
|
return cl_utils.runOsCommand(cmdStrProg, inStr, retFull)
|
|
|
|
|
|
|
|
|
|
#def getUidAndGidUser(self, userName):
|
|
|
|
|
#strRes = self.execProg("id %s" %userName)
|
|
|
|
|
#reFind = re.compile("uid=(\d+)\(.+gid=(\d+)\(")
|
|
|
|
|
#res = reFind.search(strRes)
|
|
|
|
|
#if res:
|
|
|
|
|
#return res.group(1), res.group(2)
|
|
|
|
|
#else:
|
|
|
|
|
#self.printERROR(_("User %s not found")\
|
|
|
|
|
#%str(userName))
|
|
|
|
|
#return False
|
|
|
|
|
|
|
|
|
|
def getUidAndGidUser(self, userName):
|
|
|
|
|
strRes = self.execProg("id %s" %userName)
|
|
|
|
|
reFind = re.compile("uid=(\d+)\(.+gid=(\d+)\(")
|
|
|
|
|
res = reFind.search(strRes)
|
|
|
|
|
if res:
|
|
|
|
|
return res.group(1), res.group(2)
|
|
|
|
|
"""получаем uid и gid пользователя из /etc/passwd"""
|
|
|
|
|
resPasswd = self.searchPasswdUser(userName)
|
|
|
|
|
if resPasswd:
|
|
|
|
|
uid = resPasswd.split(":")[2]
|
|
|
|
|
gid = resPasswd.split(":")[3]
|
|
|
|
|
full_name = resPasswd.split(":")[4]
|
|
|
|
|
return (uid, gid, full_name)
|
|
|
|
|
else:
|
|
|
|
|
self.printERROR(_("User %s not found")\
|
|
|
|
|
%str(userName))
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def createHome(self, userName=False):
|
|
|
|
|
# Подсоединяемся к movie
|
|
|
|
|
#if not self.getLdapObjBind(server):
|
|
|
|
@ -340,13 +381,15 @@ calculate-server"),
|
|
|
|
|
return False
|
|
|
|
|
uid = int(uidGid[0])
|
|
|
|
|
gid = int(uidGid[1])
|
|
|
|
|
fullName = uidGid[2]
|
|
|
|
|
# Создаем пользовательскую директорию
|
|
|
|
|
homeDir = os.path.join("/home",self.userName)
|
|
|
|
|
self.clVars.Set('cl_root_path',homeDir,True)
|
|
|
|
|
if not os.path.exists(homeDir):
|
|
|
|
|
self.createUserDir(uid, gid, homeDir)
|
|
|
|
|
# Записываем переменную логин
|
|
|
|
|
self.clVars.Set('ur_name',self.userName)
|
|
|
|
|
self.clVars.Set('ur_login',self.userName)
|
|
|
|
|
self.clVars.Set('ur_fullname',fullName)
|
|
|
|
|
# Применяем профили для пользователя
|
|
|
|
|
if not self.applyProfilesFromUser():
|
|
|
|
|
self.printERROR(_(" Not apply user profile"))
|
|
|
|
@ -392,10 +435,8 @@ class tsOpt(cl_base.opt):
|
|
|
|
|
if self.params.has_key('user'):
|
|
|
|
|
if len(self.nameParams) != self.__iter:
|
|
|
|
|
self.handlerErrOpt()
|
|
|
|
|
else:
|
|
|
|
|
self.handlerErrOpt()
|
|
|
|
|
# В случае остсутствия опций командной строки
|
|
|
|
|
if notOptError and not self.opt and self.params.has_key('user'):
|
|
|
|
|
# В случае остсутствия опций командной строки и имени пользователя
|
|
|
|
|
if notOptError and not self.opt and not self.params.has_key('user'):
|
|
|
|
|
self.printErrorNotOpt()
|
|
|
|
|
self.flagHelp = True
|
|
|
|
|
|
|
|
|
|