diff --git a/pym/cl_profile.py b/pym/cl_profile.py index b35ec94..9332e0b 100644 --- a/pym/cl_profile.py +++ b/pym/cl_profile.py @@ -2873,7 +2873,18 @@ class profile(_file, _terms, xmlShare): _versionProgram = self.objVar.Get("cl_ver") # имя и версия текущей программы programVersion = "%s %s"%(_nameProgram, _versionProgram) + dirObjsApply = [] for dirObj in dirObjs: + dirInfoFile = os.path.join(dirObj.baseDir, self.profDirNameFile) + ret = self.__getApplyHeadDirRoot(dirInfoFile) + if ret: + dirObjsApply.append(dirObj) + else: + if self.getError(): + self.setError(_("Incorrect profile: " ) +\ + dirInfoFile) + return False + for dirObj in dirObjsApply: # сортируем файлы по названию if dirObj.files: dirObj.files.sort() @@ -3025,7 +3036,7 @@ class profile(_file, _terms, xmlShare): # Изменяем название директории if objHead.params.has_key("name"): nameDir = objHead.params['name'] - if "/" in nameDir: + if "/" in nameDir or nameDir == ".." or nameDir == ".": self.setError (_("False value 'name' in profile: " ) +\ profileDirFile) return (applyDir, False) @@ -3069,8 +3080,18 @@ class profile(_file, _terms, xmlShare): filesApply = [] # Словарь измененных директорий changeDirs = {} - + dirObjsApply = [] for dirObj in dirObjs: + dirInfoFile = os.path.join(dirObj.baseDir, self.profDirNameFile) + ret = self.__getApplyHeadDirRoot(dirInfoFile) + if ret: + dirObjsApply.append(dirObj) + else: + if self.getError(): + self.setError(_("Incorrect profile: " ) +\ + dirInfoFile) + return False + for dirObj in dirObjsApply: # сортируем файлы по названию if dirObj.files: dirObj.files.sort() @@ -3151,6 +3172,63 @@ class profile(_file, _terms, xmlShare): return False return filesApply + def __getApplyHeadDirRoot(self, profileDirFile): + """Будет ли применен профиль корневой директории + + Возвращает True, False + """ + + def function(text): + """Функция обработки функций в заголовке""" + return self.applyFuncProfile(text, newDir, profileDirFile) + + if not os.path.exists(profileDirFile): + return True + try: + FD = open(profileDirFile) + textProfile = FD.read() + FD.close() + except: + self.setError(_("Error open profile#: " ) +\ + profileDirFile) + return False + objHead = dirHeader(textProfile, self.objVar,function) + if not objHead.headerCorrect: + self.setError(_("Incorrect profile: " ) +\ + profileDirFile) + self.setError(objHead.errorMessage) + return False + if not objHead.headerTerm: + if objHead.getError(): + self.setError(_("Incorrect profile: " ) +\ + profileDirFile) + return False + + # Изменяем название директории + if objHead.params.has_key("name"): + self.setError (_("Invalid name 'name' in profile: " ) +\ + profileDirFile) + return False + + # Удаляем директорию + if objHead.typeAppend == "remove": + self.setError (_("Invalid name 'remove' in profile: " ) +\ + profileDirFile) + return False + + # chmod - изменяем права + if objHead.params.has_key("chmod"): + self.setError (_("Invalid name 'chmod' in profile: " ) +\ + profileDirFile) + return False + + # chown - изменяем владельца и группу + if objHead.params.has_key("chown"): + self.setError (_("Invalid name 'chown' in profile: " ) +\ + profileDirFile) + return False + return True + def __getApplyHeadDir(self, newDir, profileDirFile, changeDirs): """Применяет профиль к директории (права, владелец, и.т. д)""" @@ -3207,7 +3285,7 @@ class profile(_file, _terms, xmlShare): # Изменяем название директории if objHead.params.has_key("name"): nameDir = objHead.params['name'] - if "/" in nameDir: + if "/" in nameDir or nameDir == ".." or nameDir == ".": self.setError (_("False value 'name' in profile: " ) +\ profileDirFile) return (applyDir, False) @@ -3317,7 +3395,7 @@ class profile(_file, _terms, xmlShare): # Изменяем путь к оригинальному файлу if objHeadNew.params.has_key("name"): nameFile = objHeadNew.params['name'] - if "/" in nameFile: + if "/" in nameFile or nameFile == ".." or nameFile == ".": self.setError (_("False value 'name' in profile: " ) + newFile) return False pathRel = os.path.split(os.path.abspath(oldFile))[0]