Browse Source

Fix chown template work with chroot.

develop
Mike Hiretsky 11 years ago
parent
commit
1b09e5effa
  1. 74
      pym/cl_template.py

74
pym/cl_template.py

@ -4265,6 +4265,7 @@ variable 'cl_name'"))
if ":" in owner:
strUid, strGid = owner.split(":")
import pwd
uid = self.getUidFromPasswd(strUid)
try:
uid = pwd.getpwnam(strUid).pw_uid
except:
@ -4272,6 +4273,7 @@ variable 'cl_name'"))
self.setError(_("False value 'chown' in template")+\
": " + templateDirFile)
return ("", False, [])
gid = self.getGidFromGroup(strGid)
try:
import grp
gid = grp.getgrnam(strGid).gr_gid
@ -4321,6 +4323,28 @@ variable 'cl_name'"))
self.autoUpdateDirs.append(applyDir)
return (applyDir, objHead, createdDirs)
def getUidFromPasswd(self,strUid):
"""Get uid by username from chroot passwd file"""
passwdFile = os.path.join(self._baseDir,'etc/passwd')
if os.path.exists(passwdFile):
mapUid = dict(map(lambda x:x.split(':')[0:3:2],
filter(lambda x:not x.startswith('#'),
open(passwdFile,'r'))))
if strUid in mapUid:
return int(mapUid[strUid])
return None
def getGidFromGroup(self,strGid):
"""Get gid by groupname from chroot group file"""
groupFile = os.path.join(self._baseDir,'etc/group')
if os.path.exists(groupFile):
mapGid = dict(map(lambda x:x.split(':')[0:3:2],
filter(lambda x:not x.startswith('#'),
open(groupFile,'r'))))
if strGid in mapGid:
return int(mapGid[strGid])
return None
def getApplyHeadTemplate(self, nameFileTemplate, nameFileConfig,
templateFileType, optFile):
"""Применяет заголовок к шаблону (права, владелец, и.т. д)"""
@ -4612,24 +4636,36 @@ variable 'cl_name'"))
if owner:
if ":" in owner:
strUid, strGid = owner.split(":")
import pwd
try:
uid = pwd.getpwnam(strUid).pw_uid
except:
self.setError(_("Not user in this system: ") + strUid)
self.setError(_("False value 'chown' in template") +\
": "+ nameFileTemplate)
preReturn(pathProg)
return ([], False)
try:
import grp
gid = grp.getgrnam(strGid).gr_gid
except:
self.setError(_("Not group in this system: ")+strGid)
self.setError(_("False value 'chown' in template") +\
": "+ nameFileTemplate)
preReturn(pathProg)
return ([], False)
if strUid.isdigit():
uid = int(strUid)
else:
uid = self.getUidFromPasswd(strUid)
import pwd
try:
if uid is None:
uid = pwd.getpwnam(strUid).pw_uid
except:
self.setError(_("Not user in this system: ") +
strUid)
self.setError(_("False value 'chown' in template") +
": "+ nameFileTemplate)
preReturn(pathProg)
return ([], False)
if strGid.isdigit():
gid = int(strGid)
else:
gid = self.getGidFromGroup(strGid)
try:
if gid is None:
import grp
gid = grp.getgrnam(strGid).gr_gid
except:
self.setError(_("Not group in this system: ") +
strGid)
self.setError(_("False value 'chown' in template") +
": "+ nameFileTemplate)
preReturn(pathProg)
return ([], False)
# Изменяем владельца файла
if not chownConfFile(pathOldFile,uid,gid,nameFileTemplate):
preReturn(pathProg)
@ -4945,7 +4981,7 @@ variable 'cl_name'"))
return False
if objHeadOld and objHeadOld.body:
self.textConfig = objHeadOld.body
if self.textTemplate[-1] == "\n":
if self.textTemplate and self.textTemplate[-1] == "\n":
tmpTemplate = self.textTemplate + self.textConfig
else:
tmpTemplate = self.textTemplate + "\n" + self.textConfig

Loading…
Cancel
Save