|
|
@ -129,7 +129,7 @@ class _terms(_error):
|
|
|
|
flagError = True
|
|
|
|
flagError = True
|
|
|
|
if function:
|
|
|
|
if function:
|
|
|
|
reFunction = re.compile(\
|
|
|
|
reFunction = re.compile(\
|
|
|
|
"([a-zA-Z0-9\_\-]+)\([a-zA-Z0-9_\-\+\,\*\/\.]+\)")
|
|
|
|
"([a-zA-Z0-9\_\-]+)\([a-zA-Z0-9_\-\+\,\*\/\.\'\"]+\)")
|
|
|
|
searchFunct = reFunction.search(vals[0])
|
|
|
|
searchFunct = reFunction.search(vals[0])
|
|
|
|
if searchFunct:
|
|
|
|
if searchFunct:
|
|
|
|
flagError = False
|
|
|
|
flagError = False
|
|
|
@ -2178,7 +2178,97 @@ class utfBin:
|
|
|
|
resS = reVar.search(textProfileTmp)
|
|
|
|
resS = reVar.search(textProfileTmp)
|
|
|
|
return textProfileTmp
|
|
|
|
return textProfileTmp
|
|
|
|
|
|
|
|
|
|
|
|
class profile(_file, _terms, xmlShare):
|
|
|
|
class ldapProfile():
|
|
|
|
|
|
|
|
"""Работа с LDAP сервером для профилей"""
|
|
|
|
|
|
|
|
# Соединение с LDAP сервером
|
|
|
|
|
|
|
|
conLdap = False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def getLDAPDataInConfig(self):
|
|
|
|
|
|
|
|
"""Получение имени LDAP сервера и DN пользователей под пользователем"""
|
|
|
|
|
|
|
|
fileName = "/etc/ldap.conf"
|
|
|
|
|
|
|
|
serverName = ""
|
|
|
|
|
|
|
|
usersDN = ""
|
|
|
|
|
|
|
|
bindDN = ""
|
|
|
|
|
|
|
|
bindPW = ""
|
|
|
|
|
|
|
|
strServer = ("host","HOST")
|
|
|
|
|
|
|
|
lenStrServer = len(strServer[0])
|
|
|
|
|
|
|
|
strDN = ("nss_base_passwd","NSS_BASE_PASSWD")
|
|
|
|
|
|
|
|
lenStrDN = len(strDN[0])
|
|
|
|
|
|
|
|
strBindDN = ("binddn", "BINDDN")
|
|
|
|
|
|
|
|
lenStrBindDN = len(strBindDN[0])
|
|
|
|
|
|
|
|
strBindPW = ("bindpw", "BINDPW")
|
|
|
|
|
|
|
|
lenStrBindPW = len(strBindPW[0])
|
|
|
|
|
|
|
|
splList = (" ", "\t")
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
for i in open(fileName):
|
|
|
|
|
|
|
|
if not serverName and\
|
|
|
|
|
|
|
|
filter(lambda x: i.startswith(x),strServer) and\
|
|
|
|
|
|
|
|
len(i)>lenStrServer:
|
|
|
|
|
|
|
|
spl = i[lenStrServer]
|
|
|
|
|
|
|
|
if spl in splList:
|
|
|
|
|
|
|
|
serverName = i.rpartition(spl)[2].strip()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if not bindDN and\
|
|
|
|
|
|
|
|
filter(lambda x: i.startswith(x),strBindDN) and\
|
|
|
|
|
|
|
|
len(i)>lenStrBindDN:
|
|
|
|
|
|
|
|
spl = i[lenStrBindDN]
|
|
|
|
|
|
|
|
if spl in splList:
|
|
|
|
|
|
|
|
bindDN = i.rpartition(spl)[2].strip()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if not bindPW and\
|
|
|
|
|
|
|
|
filter(lambda x: i.startswith(x),strBindPW) and\
|
|
|
|
|
|
|
|
len(i)>lenStrBindPW:
|
|
|
|
|
|
|
|
spl = i[lenStrBindPW]
|
|
|
|
|
|
|
|
if spl in splList:
|
|
|
|
|
|
|
|
bindPW = i.rpartition(spl)[2].strip()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if not usersDN and filter(lambda x: i.startswith(x), strDN) and\
|
|
|
|
|
|
|
|
len(i)>lenStrDN:
|
|
|
|
|
|
|
|
spl = i[lenStrDN]
|
|
|
|
|
|
|
|
if spl in splList:
|
|
|
|
|
|
|
|
usersDN = i.rpartition(spl)[2].partition('?')[0].strip()
|
|
|
|
|
|
|
|
if serverName and usersDN and bindDN and bindPW:
|
|
|
|
|
|
|
|
break
|
|
|
|
|
|
|
|
except:
|
|
|
|
|
|
|
|
return ()
|
|
|
|
|
|
|
|
if serverName and usersDN and bindDN and bindPW:
|
|
|
|
|
|
|
|
return (serverName, usersDN, bindDN, bindPW)
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
return ()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def getUserDataInLDAP(self, userName):
|
|
|
|
|
|
|
|
"""Получаем домашнюю директорию пользователя из LDAP"""
|
|
|
|
|
|
|
|
if not self.conLdap:
|
|
|
|
|
|
|
|
import cl_utils2
|
|
|
|
|
|
|
|
data = self.getLDAPDataInConfig()
|
|
|
|
|
|
|
|
if not data:
|
|
|
|
|
|
|
|
return ""
|
|
|
|
|
|
|
|
serverName, usersDN, bindDN, bindPW = data
|
|
|
|
|
|
|
|
# Подключаемся к LDAP
|
|
|
|
|
|
|
|
ldapObj = cl_utils2.ldapFun(bindDN, bindPW, serverName)
|
|
|
|
|
|
|
|
if self.getError():
|
|
|
|
|
|
|
|
return ""
|
|
|
|
|
|
|
|
self.conLdap = ldapObj.conLdap
|
|
|
|
|
|
|
|
searchScope = ldap.SCOPE_ONELEVEL
|
|
|
|
|
|
|
|
searchFilter = "uid=%s" %(userName)
|
|
|
|
|
|
|
|
retrieveAttributes = ["uidNumber",
|
|
|
|
|
|
|
|
"gidNumber"
|
|
|
|
|
|
|
|
"homeDirectory"]
|
|
|
|
|
|
|
|
resSearch = ldapObj.ldapSearch(usersDN, searchScope,
|
|
|
|
|
|
|
|
searchFilter, retrieveAttributes)
|
|
|
|
|
|
|
|
if resSearch:
|
|
|
|
|
|
|
|
if resSearch[0][0][1].has_key('uidNumber'):
|
|
|
|
|
|
|
|
uid = searchUser[0][0][1]['uidNumber'][0]
|
|
|
|
|
|
|
|
if resSearch[0][0][1].has_key('gidNumber'):
|
|
|
|
|
|
|
|
gid = searchUser[0][0][1]['gidNumber'][0]
|
|
|
|
|
|
|
|
if resSearch[0][0][1].has_key('homeDirectory'):
|
|
|
|
|
|
|
|
homeDir = resSearch[0][0][1]['homeDirectory'][0]
|
|
|
|
|
|
|
|
if uid and gid and homeDir:
|
|
|
|
|
|
|
|
return uid, gid, homeDir
|
|
|
|
|
|
|
|
return ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class profile(_file, _terms, xmlShare, ldapProfile):
|
|
|
|
"""Класс для работы с профилями
|
|
|
|
"""Класс для работы с профилями
|
|
|
|
|
|
|
|
|
|
|
|
На вход 2 параметра: объект хранения переменных, имя сервиса - не
|
|
|
|
На вход 2 параметра: объект хранения переменных, имя сервиса - не
|
|
|
@ -2214,13 +2304,13 @@ class profile(_file, _terms, xmlShare):
|
|
|
|
varStart = "#-"
|
|
|
|
varStart = "#-"
|
|
|
|
varEnd = "-#"
|
|
|
|
varEnd = "-#"
|
|
|
|
self._reVar = re.compile(("%s[a-zA-Z0-9_-]+%s")%(varStart,varEnd),re.M)
|
|
|
|
self._reVar = re.compile(("%s[a-zA-Z0-9_-]+%s")%(varStart,varEnd),re.M)
|
|
|
|
self._reFunc = re.compile(("%s[a-zA-Z0-9_\-\+\(\)\, \*\/\.]+%s")\
|
|
|
|
self._reFunc = re.compile(("%s[a-zA-Z0-9_\-\+\(\)\, \*\/\.\'\"]+%s")\
|
|
|
|
%(varStart,varEnd),re.M)
|
|
|
|
%(varStart,varEnd),re.M)
|
|
|
|
self._deltVarStart = len(varStart)
|
|
|
|
self._deltVarStart = len(varStart)
|
|
|
|
self._deltVarEnd = len(varEnd)
|
|
|
|
self._deltVarEnd = len(varEnd)
|
|
|
|
# Условия
|
|
|
|
# Условия
|
|
|
|
self._reTermBloc = re.compile("#\?(?P<rTerm>[a-zA-Z0-9\-_]+)\
|
|
|
|
self._reTermBloc = re.compile("#\?(?P<rTerm>[a-zA-Z0-9\-_]+)\
|
|
|
|
(?P<func>\([a-zA-Z0-9_\-\+\,\*\/\.]+\))?\
|
|
|
|
(?P<func>\([a-zA-Z0-9_\-\+\,\*\/\.\'\"]+\))?\
|
|
|
|
(?P<lTerm>[\>\<\=\!\&\|]+\
|
|
|
|
(?P<lTerm>[\>\<\=\!\&\|]+\
|
|
|
|
[a-zA-Z0-9\>\<\=\!\|\&\-\+\*\/_\.\,\(\)]*)#\
|
|
|
|
[a-zA-Z0-9\>\<\=\!\|\&\-\+\*\/_\.\,\(\)]*)#\
|
|
|
|
\n*(?P<body>.+?)\n*#(?P=rTerm)#(?P<end>[ ,\t]*\n?)",re.M|re.S)
|
|
|
|
\n*(?P<body>.+?)\n*#(?P=rTerm)#(?P<end>[ ,\t]*\n?)",re.M|re.S)
|
|
|
@ -2712,6 +2802,134 @@ class profile(_file, _terms, xmlShare):
|
|
|
|
textProfileTmp[resS.end():]
|
|
|
|
textProfileTmp[resS.end():]
|
|
|
|
return textProfileTmp
|
|
|
|
return textProfileTmp
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def loadVarsIni(iniFileName, localVarsIni, isLoadVarsIni):
|
|
|
|
|
|
|
|
""" Читает файл fileName
|
|
|
|
|
|
|
|
создает и заполняет переменные на основе этого файла
|
|
|
|
|
|
|
|
Используеться совместно c funcIni
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
# получить объект настроенный на ini
|
|
|
|
|
|
|
|
config = cl_base.iniParser(iniFileName)
|
|
|
|
|
|
|
|
# получаем все секции из конфигурационного файла
|
|
|
|
|
|
|
|
allsect = config.getAllSectionNames()
|
|
|
|
|
|
|
|
if not allsect:
|
|
|
|
|
|
|
|
isLoadVarsIni = False
|
|
|
|
|
|
|
|
return isLoadVarsIni
|
|
|
|
|
|
|
|
# Заполняем переменные для funcIni
|
|
|
|
|
|
|
|
for sect in allsect:
|
|
|
|
|
|
|
|
sectVars = config.getAreaVars(sect)
|
|
|
|
|
|
|
|
for name in sectVars.keys():
|
|
|
|
|
|
|
|
nameVar = "%s.%s"%(sect,name)
|
|
|
|
|
|
|
|
valueVar = sectVars[name]
|
|
|
|
|
|
|
|
localVarsIni[nameVar] = valueVar
|
|
|
|
|
|
|
|
if localVarsIni:
|
|
|
|
|
|
|
|
isLoadVarsIni = True
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
isLoadVarsIni = False
|
|
|
|
|
|
|
|
return isLoadVarsIni
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def funcIni(funTxt,resS,localVarsIni,isLoadVarsIni, uid, gid, homeDir,
|
|
|
|
|
|
|
|
textProfileTmp):
|
|
|
|
|
|
|
|
"""локальная функция записывает и считывает значение переменной
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
из ini файла ~./calculate/ini.env
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
# ~/.calculate
|
|
|
|
|
|
|
|
if not homeDir:
|
|
|
|
|
|
|
|
homeDir = ""
|
|
|
|
|
|
|
|
userName = self.objVar.Get("ur_login")
|
|
|
|
|
|
|
|
if not userName:
|
|
|
|
|
|
|
|
print _("error in profile %s")%nameProfile
|
|
|
|
|
|
|
|
print _("error profile term %s")%str(funTxt)
|
|
|
|
|
|
|
|
print _("template variable 'ur_login' is empty")
|
|
|
|
|
|
|
|
cl_base.exit(1)
|
|
|
|
|
|
|
|
import pwd
|
|
|
|
|
|
|
|
flagFoundUser = False
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
pwdObj = pwd.getpwnam(userName)
|
|
|
|
|
|
|
|
uid = pwdObj.pw_uid
|
|
|
|
|
|
|
|
gid = pwdObj.pw_gid
|
|
|
|
|
|
|
|
homeDir = pwdObj.pw_dir
|
|
|
|
|
|
|
|
flagFoundUser = True
|
|
|
|
|
|
|
|
except:
|
|
|
|
|
|
|
|
data = self.getUserDataInLDAP(userName)
|
|
|
|
|
|
|
|
if data:
|
|
|
|
|
|
|
|
uid, gid, homeDir = data
|
|
|
|
|
|
|
|
flagFoundUser = True
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
flagFoundUser = True
|
|
|
|
|
|
|
|
if not flagFoundUser:
|
|
|
|
|
|
|
|
print _("error in profile %s")%nameProfile
|
|
|
|
|
|
|
|
print _("error profile term %s")%str(funTxt)
|
|
|
|
|
|
|
|
print _("Can not found user %s")%str(userName)
|
|
|
|
|
|
|
|
cl_base.exit(1)
|
|
|
|
|
|
|
|
pathConfig = os.path.join(homeDir, ".calculate")
|
|
|
|
|
|
|
|
fileConfig = os.path.join(pathConfig,"ini.env")
|
|
|
|
|
|
|
|
# Создаем директорию
|
|
|
|
|
|
|
|
if not os.path.exists(pathConfig):
|
|
|
|
|
|
|
|
os.makedirs(pathConfig)
|
|
|
|
|
|
|
|
os.chown(pathConfig, int(uid), int(gid))
|
|
|
|
|
|
|
|
termsRaw = funTxt[4:-1].split(",")
|
|
|
|
|
|
|
|
flagFirst = True
|
|
|
|
|
|
|
|
terms = []
|
|
|
|
|
|
|
|
for term in termsRaw:
|
|
|
|
|
|
|
|
if flagFirst:
|
|
|
|
|
|
|
|
terms.append(term.replace(" ",""))
|
|
|
|
|
|
|
|
flagFirst = False
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
val = term.strip()
|
|
|
|
|
|
|
|
# Флаг (не найдены кавычки)
|
|
|
|
|
|
|
|
flagNotFoundQuote = True
|
|
|
|
|
|
|
|
for el in ('"',"'"):
|
|
|
|
|
|
|
|
if val.startswith(el) and val.endswith(el):
|
|
|
|
|
|
|
|
terms.append(val[1:-1])
|
|
|
|
|
|
|
|
flagNotFoundQuote = False
|
|
|
|
|
|
|
|
break
|
|
|
|
|
|
|
|
if flagNotFoundQuote:
|
|
|
|
|
|
|
|
terms.append(val)
|
|
|
|
|
|
|
|
# Название локальной переменной
|
|
|
|
|
|
|
|
nameLocVar = terms[0]
|
|
|
|
|
|
|
|
namesVar = nameLocVar.split(".")
|
|
|
|
|
|
|
|
if len(namesVar) == 1:
|
|
|
|
|
|
|
|
nameLocVar = "main.%s"%nameLocVar
|
|
|
|
|
|
|
|
elif len(namesVar)>2:
|
|
|
|
|
|
|
|
print _("error in profile %s")%nameProfile
|
|
|
|
|
|
|
|
print _("error profile term %s")%str(funTxt)
|
|
|
|
|
|
|
|
cl_base.exit(1)
|
|
|
|
|
|
|
|
replace = ""
|
|
|
|
|
|
|
|
if len(terms) == 1:
|
|
|
|
|
|
|
|
if isLoadVarsIni is None:
|
|
|
|
|
|
|
|
# читаем переменные из файла
|
|
|
|
|
|
|
|
isLoadVarsIni = loadVarsIni(fileConfig, localVarsIni,
|
|
|
|
|
|
|
|
isLoadVarsIni)
|
|
|
|
|
|
|
|
if nameLocVar in localVarsIni.keys():
|
|
|
|
|
|
|
|
replace = localVarsIni[nameLocVar]
|
|
|
|
|
|
|
|
elif len(terms) == 2:
|
|
|
|
|
|
|
|
if isLoadVarsIni is None:
|
|
|
|
|
|
|
|
# читаем переменные из файла
|
|
|
|
|
|
|
|
isLoadVarsIni = loadVarsIni(fileConfig, localVarsIni,
|
|
|
|
|
|
|
|
isLoadVarsIni)
|
|
|
|
|
|
|
|
# Значение локальной переменной
|
|
|
|
|
|
|
|
valueLocVar = terms[1]
|
|
|
|
|
|
|
|
localVarsIni[nameLocVar] = valueLocVar
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
print _("error in profile %s")%nameProfile
|
|
|
|
|
|
|
|
print _("error profile term %s")%str(funTxt)
|
|
|
|
|
|
|
|
cl_base.exit(1)
|
|
|
|
|
|
|
|
textProfileTmp = textProfileTmp[:resS.start()] + replace +\
|
|
|
|
|
|
|
|
textProfileTmp[resS.end():]
|
|
|
|
|
|
|
|
return (isLoadVarsIni, uid, gid, homeDir, textProfileTmp)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Локальные переменные для ini файла
|
|
|
|
|
|
|
|
localVarsIni = {}
|
|
|
|
|
|
|
|
# Был ли прочитан ini файл
|
|
|
|
|
|
|
|
isLoadVarsIni = None
|
|
|
|
|
|
|
|
# uid пользователя
|
|
|
|
|
|
|
|
uid = ""
|
|
|
|
|
|
|
|
# gid пользователя
|
|
|
|
|
|
|
|
gid = ""
|
|
|
|
|
|
|
|
# Путь к домашней директории пользователя
|
|
|
|
|
|
|
|
homeDir = ""
|
|
|
|
|
|
|
|
|
|
|
|
# Локальные переменные
|
|
|
|
# Локальные переменные
|
|
|
|
localVars = {}
|
|
|
|
localVars = {}
|
|
|
|
# Регулярное выражние для сложения
|
|
|
|
# Регулярное выражние для сложения
|
|
|
@ -2746,8 +2964,47 @@ class profile(_file, _terms, xmlShare):
|
|
|
|
elif funTxt[:5] == "push(":
|
|
|
|
elif funTxt[:5] == "push(":
|
|
|
|
textProfileTmp = funcPush(funTxt,resS,localVars,textProfileTmp)
|
|
|
|
textProfileTmp = funcPush(funTxt,resS,localVars,textProfileTmp)
|
|
|
|
resS = self._reFunc.search(textProfileTmp)
|
|
|
|
resS = self._reFunc.search(textProfileTmp)
|
|
|
|
|
|
|
|
elif funTxt[:4] == "ini(":
|
|
|
|
|
|
|
|
isLoadVarsIni, uid, gid, homeDir, textProfileTmp = funcIni(\
|
|
|
|
|
|
|
|
funTxt, resS,
|
|
|
|
|
|
|
|
localVarsIni,
|
|
|
|
|
|
|
|
isLoadVarsIni,
|
|
|
|
|
|
|
|
uid,
|
|
|
|
|
|
|
|
gid,
|
|
|
|
|
|
|
|
homeDir,
|
|
|
|
|
|
|
|
textProfileTmp)
|
|
|
|
|
|
|
|
resS = self._reFunc.search(textProfileTmp)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
resS = False
|
|
|
|
resS = False
|
|
|
|
|
|
|
|
if not isLoadVarsIni is None and localVarsIni and homeDir:
|
|
|
|
|
|
|
|
# Записываем переменные в конфигурационный файл
|
|
|
|
|
|
|
|
pathConfig = os.path.join(homeDir,".calculate","ini.env")
|
|
|
|
|
|
|
|
# Очистка файла
|
|
|
|
|
|
|
|
if os.path.exists(pathConfig):
|
|
|
|
|
|
|
|
FD = open(pathConfig, "r+")
|
|
|
|
|
|
|
|
FD.truncate(0)
|
|
|
|
|
|
|
|
FD.seek(0)
|
|
|
|
|
|
|
|
FD.close()
|
|
|
|
|
|
|
|
# Запись переменных
|
|
|
|
|
|
|
|
# Создание объкта парсера
|
|
|
|
|
|
|
|
config = cl_base.iniParser(pathConfig)
|
|
|
|
|
|
|
|
# секции будущего конфигурационного файла
|
|
|
|
|
|
|
|
sects = list(set(map(lambda x: x.split(".")[0],\
|
|
|
|
|
|
|
|
localVarsIni.keys())))
|
|
|
|
|
|
|
|
for sect in sects:
|
|
|
|
|
|
|
|
dictVar = {}
|
|
|
|
|
|
|
|
for varName in localVarsIni.keys():
|
|
|
|
|
|
|
|
if varName.startswith("%s."%sect):
|
|
|
|
|
|
|
|
nameVar = varName.rpartition(".")[2]
|
|
|
|
|
|
|
|
valueVar = localVarsIni[varName]
|
|
|
|
|
|
|
|
if valueVar:
|
|
|
|
|
|
|
|
dictVar[nameVar] = valueVar
|
|
|
|
|
|
|
|
if dictVar:
|
|
|
|
|
|
|
|
# Запись переменных в секцию
|
|
|
|
|
|
|
|
config.setVar(sect, dictVar)
|
|
|
|
|
|
|
|
# Меняем права
|
|
|
|
|
|
|
|
if os.path.exists(pathConfig) and uid and gid:
|
|
|
|
|
|
|
|
os.chown(pathConfig, int(uid), int(gid))
|
|
|
|
return textProfileTmp
|
|
|
|
return textProfileTmp
|
|
|
|
|
|
|
|
|
|
|
|
def applyTermsProfile(self, textProfile, nameProfile, nameSystemFile=False):
|
|
|
|
def applyTermsProfile(self, textProfile, nameProfile, nameSystemFile=False):
|
|
|
|