Added logon a local user if the computer in domain.

master3.3
Самоукин Алексей 14 years ago
parent 29ab338d6f
commit 40b09c2d8e

@ -377,9 +377,8 @@ class client(share, commandServer, encrypt):
def isDomain(self): def isDomain(self):
"""Находится ли компьютер в домене""" """Находится ли компьютер в домене"""
foundMountRemote = isMount("/var/calculate/remote") foundMountRemote = isMount("/var/calculate/remote")
foundMountHome = self.isMountDomainHome()
remoteHost = self.clVars.Get("cl_remote_host") remoteHost = self.clVars.Get("cl_remote_host")
if remoteHost and foundMountRemote and foundMountHome: if remoteHost and foundMountRemote:
return True return True
self.printERROR(_("The computer is not in domain")) self.printERROR(_("The computer is not in domain"))
return False return False
@ -531,17 +530,6 @@ class client(share, commandServer, encrypt):
%x.replace('"',"").replace("'",""), %x.replace('"',"").replace("'",""),
skipPaths + deletePaths)) skipPaths + deletePaths))
if sync == "login": if sync == "login":
# исключаемые пути при синхронизации
# /.local/share/akonadi/db_data
# хранит базу acanadi
# /.mozilla/firefox/calculate.default/urlclassifier3.sqlite
# хранит БД для firefox
# /.local/share/mime/mime.cache
# отключение ошибочного кэширования изображений
# /.kde4/share/apps/nepomuk/repository/main/data
# база nepomuk
# /.VirtualBox
# содержит данные о виртуальных машинах
if os.path.exists(userHome) and\ if os.path.exists(userHome) and\
os.path.exists(homeTemplate): os.path.exists(homeTemplate):
filterPath = " ".join(map(lambda x: '--filter="P /%s"'\ filterPath = " ".join(map(lambda x: '--filter="P /%s"'\
@ -841,6 +829,23 @@ class client(share, commandServer, encrypt):
if not hostAuth or not domain: if not hostAuth or not domain:
self.printSUCCESS(_("To be used local profile")) self.printSUCCESS(_("To be used local profile"))
return True return True
try:
passwdUsers = map(lambda x: x[0],
map(lambda x: x.split(':'),
map(lambda x: x.strip(),
open("/etc/passwd").readlines())))
except:
self.printERROR(_("Can not open /etc/passwd"))
return False
if userName in passwdUsers:
try:
pwd.getpwnam(userName)
except:
self.printERROR(_("Can not found user %s")%userName)
self.umountUserRes()
return False
self.printWARNING(_("We use user information from /etc/passwd"))
return True
# Проверим что компьютер в домене и смонтирован [remote] # Проверим что компьютер в домене и смонтирован [remote]
connectDomain = self.isDomain() connectDomain = self.isDomain()
if not connectDomain: if not connectDomain:
@ -854,7 +859,7 @@ class client(share, commandServer, encrypt):
gid = int(userLdapInfo['gid']) gid = int(userLdapInfo['gid'])
homeDir = userLdapInfo['home'] homeDir = userLdapInfo['home']
else: else:
self.printERROR(_("Can not found user %s in LDAP")%userName) self.printERROR(_("Can not found user %s in LDAP") %userName)
self.umountUserRes() self.umountUserRes()
return False return False
rootPath = self.clVars.Get('cl_root_path') rootPath = self.clVars.Get('cl_root_path')
@ -1389,6 +1394,23 @@ class client(share, commandServer, encrypt):
if not hostAuth or not domain: if not hostAuth or not domain:
self.printSUCCESS(_("To be used local profile")) self.printSUCCESS(_("To be used local profile"))
return True return True
try:
passwdUsers = map(lambda x: x[0],
map(lambda x: x.split(':'),
map(lambda x: x.strip(),
open("/etc/passwd").readlines())))
except:
self.printERROR(_("Can not open /etc/passwd"))
return False
if userName in passwdUsers:
try:
pwd.getpwnam(userName)
except:
self.printERROR(_("Can not found user %s")%userName)
self.umountUserRes()
return False
self.printWARNING(_("We use user information from /etc/passwd"))
return True
connectDomain = self.isDomain() connectDomain = self.isDomain()
if not connectDomain: if not connectDomain:
# Отмонтируем пользовательские ресурсы в случае ошибки # Отмонтируем пользовательские ресурсы в случае ошибки
@ -1545,7 +1567,7 @@ class client(share, commandServer, encrypt):
break break
return ret return ret
def installClient(self): def installProg(self):
"""Наложение шаблонов на систему при инсталяции""" """Наложение шаблонов на систему при инсталяции"""
# Действие выход из домена # Действие выход из домена
self.clVars.Set("cl_action", "install", True) self.clVars.Set("cl_action", "install", True)
@ -1583,7 +1605,7 @@ class client(share, commandServer, encrypt):
splLines = map(lambda x: x[0].strip(), splLines) splLines = map(lambda x: x[0].strip(), splLines)
return splLines return splLines
def uninstallClient(self): def uninstallProg(self):
"""Наложение шаблонов на систему при деинсталяции""" """Наложение шаблонов на систему при деинсталяции"""
# Проверяем на root # Проверяем на root
if not self.isRoot(): if not self.isRoot():
@ -1627,18 +1649,12 @@ class client(share, commandServer, encrypt):
if not self.isRoot(): if not self.isRoot():
return False return False
pathRemote = "/var/calculate/remote" pathRemote = "/var/calculate/remote"
pathHome = "/home"
foundMountRemote = isMount(pathRemote) foundMountRemote = isMount(pathRemote)
foundMountHome = isMount(pathHome)
domain = self.clVars.Get("cl_remote_host") domain = self.clVars.Get("cl_remote_host")
if foundMountRemote: if foundMountRemote:
textLineUmount = self.umountSleepPath(pathRemote) textLineUmount = self.umountSleepPath(pathRemote)
if not textLineUmount: if not textLineUmount:
return False return False
if foundMountHome:
textLineUmount = self.umountSleepPath(pathHome)
if not textLineUmount:
return False
if not domain: if not domain:
self.printWARNING(_("The computer is not in domain")) self.printWARNING(_("The computer is not in domain"))
return True return True
@ -1768,7 +1784,6 @@ you need to remove it from the previous domain"))
return False return False
foundMountRemote = isMount("/var/calculate/remote") foundMountRemote = isMount("/var/calculate/remote")
foundMountHome = self.isMountDomainHome()
if foundMountRemote: if foundMountRemote:
self.printERROR(_("Samba resource [%s] is mount")%\ self.printERROR(_("Samba resource [%s] is mount")%\
"remote" + " ...") "remote" + " ...")
@ -1792,21 +1807,6 @@ you need to remove it from the previous domain"))
" ...") " ...")
self.clVars.Write("cl_remote_host", domain, True, "local") self.clVars.Write("cl_remote_host", domain, True, "local")
self.clVars.Write("cl_remote_pw", userPwd, True, "local") self.clVars.Write("cl_remote_pw", userPwd, True, "local")
pathHome = "/var/calculate/client-home"
if foundMountHome:
self.printWARNING(str(pathHome)+ " " +_("is mount")+
" ...")
else:
if not os.path.exists(pathHome):
os.makedirs(pathHome)
mountStr = "mount -o bind %s /home" %pathHome
textLine = self.execProg(mountStr)
if not (textLine is None):
self.printERROR(_("Can not mount") + " " + str(pathHome) +\
" ...")
return False
self.printSUCCESS(_("Mount") + " " + str(pathHome) + " " +\
" ...")
servDn = self.getInfoService("ldap", "services_dn") servDn = self.getInfoService("ldap", "services_dn")
unixDn = self.getInfoService("unix", "dn") unixDn = self.getInfoService("unix", "dn")
bindDn = self.getInfoService("unix", "bind_dn") bindDn = self.getInfoService("unix", "bind_dn")
@ -1891,12 +1891,8 @@ you need to remove it from the previous domain"))
self.clVars.Delete("os_remote_client") self.clVars.Delete("os_remote_client")
return True return True
def isMountDomainHome(self):
"""Примонтирована ли директория /home для ввода в домен"""
return isMount("/home") == "/var/calculate/client-home"
def mountRemote(self): def mountRemote(self):
"""Монтирование remote и домашней директории если компьютер в домене """Монтирование remote если компьютер в домене
а так-же ввод в домен если найдено имя хоста и пароль для подключения а так-же ввод в домен если найдено имя хоста и пароль для подключения
""" """
@ -1906,29 +1902,22 @@ you need to remove it from the previous domain"))
domain = self.clVars.Get("cl_remote_host") domain = self.clVars.Get("cl_remote_host")
if domain: if domain:
foundMountRemote = isMount("/var/calculate/remote") foundMountRemote = isMount("/var/calculate/remote")
foundMountHome = self.isMountDomainHome()
else: else:
self.printWARNING(_("This computer is not in domain")) self.printWARNING(_("This computer is not in domain"))
# Если шаблоны не актуальны накладываем новую версию шаблонов # Если шаблоны не актуальны накладываем новую версию шаблонов
if not self.applyRelevanceTemplates(): if not self.applyRelevanceTemplates():
return False return False
return True return True
pathHome = "/var/calculate/client-home"
if foundMountRemote: if foundMountRemote:
self.printWARNING(_("Samba resource [%s] is mount")%"remote" + \ self.printWARNING(_("Samba resource [%s] is mount")%"remote" + \
" ...") " ...")
if foundMountHome:
self.printWARNING(str(pathHome) + " " +_("is mount")+
" ...")
if foundMountHome and foundMountRemote:
# Накладываем сетевые шаблоны # Накладываем сетевые шаблоны
if domain: if domain:
self.clVars.flIniFile() self.clVars.flIniFile()
if not self.applyRelevanceTemplates(domain): if not self.applyRelevanceTemplates(domain):
return False return False
return True return True
flagLocalTemplate = False else:
if not foundMountRemote:
pathRemote = "/var/calculate/remote" pathRemote = "/var/calculate/remote"
pwdRemote = self.clVars.Get("cl_remote_pw") pwdRemote = self.clVars.Get("cl_remote_pw")
if not (domain and pwdRemote): if not (domain and pwdRemote):
@ -1943,33 +1932,15 @@ you need to remove it from the previous domain"))
if not (textLine is None): if not (textLine is None):
self.printWARNING(_("Can not mount Samba resource [%s]")%\ self.printWARNING(_("Can not mount Samba resource [%s]")%\
"remote" + " ...") "remote" + " ...")
flagLocalTemplate = True
beforeRemoteAuth = self.clVars.Get('os_remote_auth') beforeRemoteAuth = self.clVars.Get('os_remote_auth')
# Если шаблоны не актуальны накладываем новую версию шаблонов # Если шаблоны не актуальны накладываем новую версию шаблонов
if not self.applyRelevanceTemplates(): if not self.applyRelevanceTemplates():
return False return False
if foundMountHome:
umountStr = "umount /home"
textLine = self.execProg(umountStr)
if not (textLine is None):
self.printERROR(_("Can not unmount") + " /home")
return False
if beforeRemoteAuth != self.clVars.Get('os_remote_auth'): if beforeRemoteAuth != self.clVars.Get('os_remote_auth'):
self.restartDBus() self.restartDBus()
return True return True
self.printSUCCESS(_("Mount Samba resource [%s]") % "remote" +\ self.printSUCCESS(_("Mount Samba resource [%s]") % "remote" +\
" ...") " ...")
if not foundMountHome and not flagLocalTemplate:
if not os.path.exists(pathHome):
os.makedirs(pathHome)
mountStr = "mount -o bind %s /home" %pathHome
textLine = self.execProg(mountStr)
if not (textLine is None):
self.printERROR(_("Can not mount") + " " + str(pathHome) +\
" ...")
return False
self.printSUCCESS(_("Mount") + " " + str(pathHome) + " " +\
" ...")
# Накладываем сетевые шаблоны # Накладываем сетевые шаблоны
if domain: if domain:
self.clVars.flIniFile() self.clVars.flIniFile()

@ -14,10 +14,9 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import os, sys, re, time import os, sys, time
from cl_utils import pathJoin from cl_utils import getModeFile
from cl_print import color_print from cl_print import color_print
from encrypt import encrypt
from cl_ldap import ldapUser from cl_ldap import ldapUser
from cl_lang import lang from cl_lang import lang
@ -26,7 +25,6 @@ lang().setLanguage(sys.modules[__name__])
class _shareData(color_print): class _shareData(color_print):
"""Share class""" """Share class"""
data = [] data = []
#_reNumb = re.compile("^\d+$")
def getDataInFile(self, fileName='', lenData=0): def getDataInFile(self, fileName='', lenData=0):
"""Get data list from file""" """Get data list from file"""
@ -187,6 +185,9 @@ class _shareCache():
self.printERROR(_("Can not create file %s")%self.fileName) self.printERROR(_("Can not create file %s")%self.fileName)
return False return False
if self.getFileAccess(perm="WRITE"): if self.getFileAccess(perm="WRITE"):
modeFile = 0600
if getModeFile(self.fileName, mode=="mode") != modeFile:
os.chmod(self.fileName, modeFile)
buff = "\n".join(map(lambda x: ":".join(x), self.data)) + "\n" buff = "\n".join(map(lambda x: ":".join(x), self.data)) + "\n"
FD = open(self.fileName, "w+") FD = open(self.fileName, "w+")
FD.write(buff) FD.write(buff)

@ -143,7 +143,7 @@ class client_cmd(share_cmd):
def install(self): def install(self):
"""Инсталяция программы""" """Инсталяция программы"""
return self.logicObj.installClient() return self.logicObj.installProg()
def updateEnvFiles(self): def updateEnvFiles(self):
"""Апдейт env файлов до новой версии""" """Апдейт env файлов до новой версии"""
@ -151,4 +151,4 @@ class client_cmd(share_cmd):
def uninstall(self): def uninstall(self):
"""Удаление программы""" """Удаление программы"""
return self.logicObj.uninstallClient() return self.logicObj.uninstallProg()

Loading…
Cancel
Save