|
|
|
@ -29,13 +29,15 @@ import cl_utils
|
|
|
|
|
import termios, fcntl, struct
|
|
|
|
|
# Ввод pwd
|
|
|
|
|
import getpass
|
|
|
|
|
# Статистика файла
|
|
|
|
|
import stat
|
|
|
|
|
|
|
|
|
|
Version = "calculate-server 0.0.1"
|
|
|
|
|
|
|
|
|
|
tr = cl_base.lang()
|
|
|
|
|
tr.setLanguage(sys.modules[__name__])
|
|
|
|
|
|
|
|
|
|
CONWIDTH = 80
|
|
|
|
|
CONWIDTH = 79
|
|
|
|
|
pcs = cl_utils.prettyColumnStr
|
|
|
|
|
|
|
|
|
|
def unicList(lst):
|
|
|
|
@ -235,6 +237,12 @@ class cl_ldap(imp_cl_err, imp_cl_xml, imp_cl_par, imp_cl_con):
|
|
|
|
|
#'helpChapter':_("Options"),
|
|
|
|
|
#'help':_("use encrypted password for the new user account")
|
|
|
|
|
#},
|
|
|
|
|
{'progAccess':(3,),
|
|
|
|
|
'shortOption':"m",
|
|
|
|
|
'longOption':"create-home",
|
|
|
|
|
'helpChapter':_("Options"),
|
|
|
|
|
'help':_("create home directory for the new user account")
|
|
|
|
|
},
|
|
|
|
|
{'progAccess':(3,),
|
|
|
|
|
'shortOption':"s",
|
|
|
|
|
'longOption':"shell",
|
|
|
|
@ -635,6 +643,19 @@ LDAP in backup directory")
|
|
|
|
|
Samba in backup directory")
|
|
|
|
|
print "3. " + _("Restart the program")
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
# Установим права 777 на директории
|
|
|
|
|
dirs = ["/var/calculate/winnt/profiles",
|
|
|
|
|
"/var/calculate/share"]
|
|
|
|
|
for mDir in dirs:
|
|
|
|
|
if os.path.exists(mDir):
|
|
|
|
|
fd = os.open(mDir, os.O_RDONLY)
|
|
|
|
|
fst = os.fstat(fd)
|
|
|
|
|
mode = stat.S_IMODE(fst.st_mode)
|
|
|
|
|
os.close(fd)
|
|
|
|
|
if not mode == 0777:
|
|
|
|
|
os.chmod(mDir, 0777)
|
|
|
|
|
|
|
|
|
|
clVars.Write("soft_samba_setup","no")
|
|
|
|
|
# Cоздаем объект профиль устанавливая директорию samba для
|
|
|
|
|
# файлов профилей
|
|
|
|
@ -663,12 +684,53 @@ Samba in backup directory")
|
|
|
|
|
else:
|
|
|
|
|
self.printNotOK(_("Samba start ..."))
|
|
|
|
|
return False
|
|
|
|
|
print _("Enter the ROOT password")
|
|
|
|
|
if not self.addUserSambaServer('root',{},clVars):
|
|
|
|
|
return False
|
|
|
|
|
clVars.Write("soft_samba_setup","yes")
|
|
|
|
|
self.printOK(_("Samba service configured ..."))
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
def addMashineSambaServer(self, machineName, options, clVars=False):
|
|
|
|
|
"""Добавляет Samba машину в LDAP-сервер"""
|
|
|
|
|
if not clVars:
|
|
|
|
|
clVars = cl_base.DataVars()
|
|
|
|
|
clVars.flServer()
|
|
|
|
|
clVars.flIniFile()
|
|
|
|
|
ldapParser = iniLdapParser()
|
|
|
|
|
adminDn = ldapParser.getVar("admin","DN")
|
|
|
|
|
adminPw = ldapParser.getVar("admin","PASS")
|
|
|
|
|
ldapObj = ldapFunction(adminDn, adminPw)
|
|
|
|
|
machineLogin = machineName.replace('$','') + "$"
|
|
|
|
|
res = self.searchLdapUser(machineLogin, ldapObj, clVars,"ou=Computers")
|
|
|
|
|
if res:
|
|
|
|
|
if res[0][0][1].has_key('sambaSID'):
|
|
|
|
|
self.printERROR(_("machine")+" "+machineLogin+" "+\
|
|
|
|
|
"found in LDAP")
|
|
|
|
|
return True
|
|
|
|
|
# добавляем Samba машину
|
|
|
|
|
textLine = self.execProg("smbpasswd -a -m %s" %machineLogin)
|
|
|
|
|
if "Added" in str(textLine):
|
|
|
|
|
self.printSUCCESS(_("Add machine in samba service ..."))
|
|
|
|
|
return True
|
|
|
|
|
else:
|
|
|
|
|
self.printERROR(_("Not add machine ..."))
|
|
|
|
|
return False
|
|
|
|
|
else:
|
|
|
|
|
# добавляем LDAP машину
|
|
|
|
|
if not self.addMashineLdapServer(machineLogin, options, clVars):
|
|
|
|
|
return False
|
|
|
|
|
# добавляем Samba машину
|
|
|
|
|
textLine = self.execProg("smbpasswd -a -m %s" %machineLogin)
|
|
|
|
|
if "Added" in str(textLine):
|
|
|
|
|
self.printSUCCESS(_("Add machine in samba service ..."))
|
|
|
|
|
return True
|
|
|
|
|
else:
|
|
|
|
|
self.printERROR(_("Not add machine ..."))
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
def addMashineLdapServer(self, machineName, options, clVars=False):
|
|
|
|
|
"""Добавляет машину в LDAP-сервер"""
|
|
|
|
|
"""Добавляет LDAP машину в LDAP-сервер"""
|
|
|
|
|
if not clVars:
|
|
|
|
|
clVars = cl_base.DataVars()
|
|
|
|
|
clVars.flServer()
|
|
|
|
@ -758,9 +820,8 @@ Samba in backup directory")
|
|
|
|
|
if options.has_key('b'):
|
|
|
|
|
baseDir = options['b']
|
|
|
|
|
# Устанавливаем базовую домашнюю директорию
|
|
|
|
|
clVars.Set("soft_ldap_user_home",
|
|
|
|
|
os.path.join (baseDir,
|
|
|
|
|
clVars.Get("soft_ldap_user_login")))
|
|
|
|
|
homeDir = os.path.join(baseDir, clVars.Get("soft_ldap_user_login"))
|
|
|
|
|
clVars.Set("soft_ldap_user_home",homeDir)
|
|
|
|
|
|
|
|
|
|
fullNameUser = "CDS user"
|
|
|
|
|
# Полное имя пользователя
|
|
|
|
@ -904,7 +965,11 @@ Samba in backup directory")
|
|
|
|
|
if ldapObj.getError():
|
|
|
|
|
print _("LDAP Error") + ": " + ldapObj.getError()
|
|
|
|
|
return False
|
|
|
|
|
#clVars.Write("soft_ldap_user_id",str(int(userId)+1))
|
|
|
|
|
# Добавим домашнюю директорию
|
|
|
|
|
if options.has_key('m'):
|
|
|
|
|
if not self.createHomeDir(userName, homeDir, ldapObj, clVars):
|
|
|
|
|
self.printERROR (_("ERROR") + ": " + _("create HOME dir"))
|
|
|
|
|
return False
|
|
|
|
|
self.printSUCCESS(_("Add user ..."))
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
@ -1018,10 +1083,9 @@ Samba in backup directory")
|
|
|
|
|
self.printSUCCESS(_("Add group ..."))
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
def searchLdapUser(self, userName, ldapObj, clVars):
|
|
|
|
|
def searchLdapUser(self, userName, ldapObj, clVars, orgUnit="ou=Users"):
|
|
|
|
|
"""Находит пользователя сервиса LDAP"""
|
|
|
|
|
baseDN = "ou=Users,%s"\
|
|
|
|
|
% clVars.Get("soft_ldap_base")
|
|
|
|
|
baseDN = "%s,%s"%(orgUnit,clVars.Get("soft_ldap_base"))
|
|
|
|
|
#searchScope = ldap.SCOPE_SUBTREE
|
|
|
|
|
searchScope = ldap.SCOPE_ONELEVEL
|
|
|
|
|
searchFilter = "uid=%s" %(userName)
|
|
|
|
@ -1221,6 +1285,43 @@ Samba in backup directory")
|
|
|
|
|
break
|
|
|
|
|
return uidMin
|
|
|
|
|
|
|
|
|
|
def createHomeDir(self, userName, homeDir, ldapObj, clVars):
|
|
|
|
|
"""Создаем домашнюю директорию пользователя
|
|
|
|
|
|
|
|
|
|
создание происходит после создания пользователя
|
|
|
|
|
"""
|
|
|
|
|
skelDir = "/etc/skel"
|
|
|
|
|
resLdap = self.searchLdapUser(userName, ldapObj, clVars)
|
|
|
|
|
if resLdap:
|
|
|
|
|
uid = int(resLdap[0][0][1]['uidNumber'][0])
|
|
|
|
|
gid = int(resLdap[0][0][1]['gidNumber'][0])
|
|
|
|
|
else:
|
|
|
|
|
return False
|
|
|
|
|
if not os.path.exists(homeDir):
|
|
|
|
|
# Создаем домашнюю директорию
|
|
|
|
|
os.makedirs(homeDir)
|
|
|
|
|
# Файловый объект
|
|
|
|
|
fileObj = cl_profile._file()
|
|
|
|
|
# Сканируем скелетную директорию
|
|
|
|
|
scanObjs = fileObj.scanDirs([skelDir])
|
|
|
|
|
for dirCreate in scanObjs[0].dirs:
|
|
|
|
|
#создаем в домашней директории директории из /etc/skel
|
|
|
|
|
fileObj.createDir(skelDir, dirCreate, homeDir)
|
|
|
|
|
dirName = homeDir + dirCreate.split(skelDir)[1]
|
|
|
|
|
os.chown(dirName, uid,gid)
|
|
|
|
|
for fileCopy in scanObjs[0].files:
|
|
|
|
|
oldFile = homeDir + fileCopy.split(skelDir)[1]
|
|
|
|
|
#копируем файлы
|
|
|
|
|
fileObj.openFiles(fileCopy, oldFile)
|
|
|
|
|
fileObj.saveOldFile()
|
|
|
|
|
fileObj.oldProfile = False
|
|
|
|
|
fileObj.closeFiles()
|
|
|
|
|
os.chown(oldFile, uid,gid)
|
|
|
|
|
os.chmod(homeDir, 0700)
|
|
|
|
|
os.chown(homeDir, uid,gid)
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def getUidMax(self):
|
|
|
|
|
"""Получаем конечный UID пользователя"""
|
|
|
|
|
fileLogin = "/etc/login.defs"
|
|
|
|
@ -1298,6 +1399,10 @@ Samba in backup directory")
|
|
|
|
|
if resSearch:
|
|
|
|
|
for scope in resSearch:
|
|
|
|
|
if scope[0][1].has_key('gidNumber'):
|
|
|
|
|
# Пропускаем группы компьютеров
|
|
|
|
|
if scope[0][1].has_key('description') and\
|
|
|
|
|
scope[0][1]['description'][0] == "Computer group":
|
|
|
|
|
continue
|
|
|
|
|
gid = int(scope[0][1]['gidNumber'][0])
|
|
|
|
|
if gid<=gidMax and gid>=gidMin:
|
|
|
|
|
gids.append(gid)
|
|
|
|
@ -1358,14 +1463,15 @@ Samba in backup directory")
|
|
|
|
|
else:
|
|
|
|
|
return gidMax+1
|
|
|
|
|
|
|
|
|
|
def addUserSambaServer(self, userName, options):
|
|
|
|
|
def addUserSambaServer(self, userName, options, clVars=False):
|
|
|
|
|
"""Добавляет LDAP пользователя в LDAP-сервер"""
|
|
|
|
|
#print self.getUidMax()
|
|
|
|
|
#print self.getMaxUidPasswd()
|
|
|
|
|
#return False
|
|
|
|
|
clVars = cl_base.DataVars()
|
|
|
|
|
clVars.flServer()
|
|
|
|
|
clVars.flIniFile()
|
|
|
|
|
if not clVars:
|
|
|
|
|
clVars = cl_base.DataVars()
|
|
|
|
|
clVars.flServer()
|
|
|
|
|
clVars.flIniFile()
|
|
|
|
|
# прервать если была неудачная попытка установить новые параметры
|
|
|
|
|
# или были опция вывода на печать
|
|
|
|
|
#if not options['s']:
|
|
|
|
@ -1375,6 +1481,12 @@ Samba in backup directory")
|
|
|
|
|
adminDn = ldapParser.getVar("admin","DN")
|
|
|
|
|
adminPw = ldapParser.getVar("admin","PASS")
|
|
|
|
|
ldapObj = ldapFunction(adminDn, adminPw)
|
|
|
|
|
# Добавление машины samba
|
|
|
|
|
if options.has_key('w'):
|
|
|
|
|
if self.addMashineSambaServer(userName, options, clVars):
|
|
|
|
|
return True
|
|
|
|
|
else:
|
|
|
|
|
return False
|
|
|
|
|
#self.addUserGroupLdap(['root1','test1','test2'],
|
|
|
|
|
#'guest', ldapObj, clVars)
|
|
|
|
|
#print self.getMaxGid(ldapObj, clVars)
|
|
|
|
@ -1402,5 +1514,7 @@ Samba in backup directory")
|
|
|
|
|
"%s\n%s\n" %(userPwd,userPwd))
|
|
|
|
|
if "Added" in str(textLine):
|
|
|
|
|
self.printSUCCESS(_("Add user in samba service ..."))
|
|
|
|
|
return True
|
|
|
|
|
else:
|
|
|
|
|
self.printERROR(_("Not add user ..."))
|
|
|
|
|
return False
|
|
|
|
|