Synchro des droits avec Nectaris
darcs-hash:20040912130754-d1718-b51b8db425d756a5649e49bd5083d2aae542cd4e.gz
This commit is contained in:
parent
c366618ae3
commit
7e6904da1b
2 changed files with 116 additions and 35 deletions
|
@ -1,18 +1,21 @@
|
||||||
#! /usr/bin/env python
|
#! /usr/bin/env python
|
||||||
# -*- coding: iso-8859-15 -*-
|
# -*- coding: iso-8859-15 -*-
|
||||||
|
|
||||||
import sys, signal
|
import sys, signal, os
|
||||||
from gen_confs import gen_config, anim, cprint, OK, ERREUR
|
from gen_confs import gen_config, anim, cprint, OK, ERREUR
|
||||||
|
|
||||||
# Imports pour LDAP
|
# Imports pour LDAP
|
||||||
sys.path.append('/usr/scripts/gestion')
|
sys.path.append('/usr/scripts/gestion')
|
||||||
from ldap_crans import crans_ldap, crans, ann_scol, preattr, ldap
|
from ldap_crans import crans_ldap, crans, ann_scol, preattr, ldap
|
||||||
|
|
||||||
# Imports pour mailman
|
from socket import gethostname
|
||||||
sys.path.append('/usr/lib/mailman')
|
|
||||||
from Mailman import MailList
|
if gethostname().split(".")[0] == 'zamok':
|
||||||
from Mailman import Utils
|
# Imports pour mailman
|
||||||
from Mailman.UserDesc import UserDesc
|
sys.path.append('/usr/lib/mailman')
|
||||||
|
from Mailman import MailList
|
||||||
|
from Mailman import Utils
|
||||||
|
from Mailman.UserDesc import UserDesc
|
||||||
|
|
||||||
class droits(crans_ldap,gen_config) :
|
class droits(crans_ldap,gen_config) :
|
||||||
####### Les groupes
|
####### Les groupes
|
||||||
|
@ -70,6 +73,60 @@ class droits(crans_ldap,gen_config) :
|
||||||
modlist = ldap.modlist.modifyModlist(init_data,data)
|
modlist = ldap.modlist.modifyModlist(init_data,data)
|
||||||
self.conn.modify_s(dn,modlist)
|
self.conn.modify_s(dn,modlist)
|
||||||
|
|
||||||
|
def build_master_passwd_group(self) :
|
||||||
|
"""Reconstruit les entrées à ajouter dans master.passwd
|
||||||
|
|
||||||
|
Reconstruit également /etc/group pour le group wheel
|
||||||
|
"""
|
||||||
|
master = ""
|
||||||
|
group = "wheel:0:root"
|
||||||
|
self.anim.iter = 2
|
||||||
|
for fonction in ("Nounou", "Apprenti"):
|
||||||
|
self.anim.cycle()
|
||||||
|
# Qui doit être dans ce groupe ?
|
||||||
|
res = self.search('droits=%s' % fonction)['adherent']
|
||||||
|
for a in res:
|
||||||
|
if fonction == "Nounou":
|
||||||
|
# On rajoute à /etc/group
|
||||||
|
group = "%s,%s" % (group, a._data['uid'][0])
|
||||||
|
# On ajoute dans master
|
||||||
|
master = "%s%s::%s:1000:ldap:0:0:%s:%s:%s\n" % (master,
|
||||||
|
a._data['uid'][0],
|
||||||
|
a._data['uidNumber'][0],
|
||||||
|
a._data['gecos'][0],
|
||||||
|
a._data['homeDirectory'][0],
|
||||||
|
"/bin/zsh")
|
||||||
|
# On crée le home
|
||||||
|
try:
|
||||||
|
os.mkdir("%s" % a._data['homeDirectory'][0])
|
||||||
|
except: # Façon Fred
|
||||||
|
pass
|
||||||
|
|
||||||
|
group = "%s\n" % group
|
||||||
|
# On va réécrire /etc/master.passwd
|
||||||
|
# cf man master.passwd
|
||||||
|
fichier = file("/etc/master.passwd")
|
||||||
|
for line in fichier:
|
||||||
|
if line.split(":")[4].strip() != "ldap":
|
||||||
|
master = "%s%s" % (line,master)
|
||||||
|
fichier.close()
|
||||||
|
# On va écrire par-dessus
|
||||||
|
fichier = file("/etc/master.passwd", "w")
|
||||||
|
fichier.write(master)
|
||||||
|
fichier.close()
|
||||||
|
os.system("pwd_mkdb -p /etc/master.passwd")
|
||||||
|
|
||||||
|
# On réécrit /etc/group
|
||||||
|
fichier = file("/etc/group")
|
||||||
|
for line in fichier:
|
||||||
|
if line.split(":")[0].strip() != "wheel":
|
||||||
|
group = "%s%s" % (group,line)
|
||||||
|
fichier.close()
|
||||||
|
# On va réécrire par-dessus
|
||||||
|
fichier = file("/etc/group", "w")
|
||||||
|
fichier.write(group)
|
||||||
|
fichier.close()
|
||||||
|
|
||||||
|
|
||||||
def sync_ML(self) :
|
def sync_ML(self) :
|
||||||
self.anim.iter = len( self.mailing_listes.keys() )
|
self.anim.iter = len( self.mailing_listes.keys() )
|
||||||
|
@ -125,32 +182,46 @@ class droits(crans_ldap,gen_config) :
|
||||||
self.mlist_to_unlock = None
|
self.mlist_to_unlock = None
|
||||||
|
|
||||||
def gen_conf(self) :
|
def gen_conf(self) :
|
||||||
self.anim = anim('\tconfiguration groupes')
|
if gethostname().split(".")[0] == 'zamok':
|
||||||
try :
|
self.anim = anim('\tconfiguration groupes')
|
||||||
self.build_group()
|
try :
|
||||||
self.anim.reinit()
|
self.build_group()
|
||||||
print OK
|
self.anim.reinit()
|
||||||
except :
|
print OK
|
||||||
self.anim.reinit()
|
except :
|
||||||
print ERREUR
|
self.anim.reinit()
|
||||||
if self.debug :
|
print ERREUR
|
||||||
import traceback
|
if self.debug :
|
||||||
traceback.print_exc()
|
import traceback
|
||||||
|
traceback.print_exc()
|
||||||
|
|
||||||
|
self.anim = anim('\tconfiguration ML Crans')
|
||||||
|
try :
|
||||||
|
self.sync_ML()
|
||||||
|
self.anim.reinit()
|
||||||
|
print OK
|
||||||
|
except :
|
||||||
|
self.anim.reinit()
|
||||||
|
try :
|
||||||
|
# Au cas où...
|
||||||
|
self.mlist_to_unlock.Unlock()
|
||||||
|
except :
|
||||||
|
pass
|
||||||
|
print ERREUR
|
||||||
|
if self.debug :
|
||||||
|
import traceback
|
||||||
|
traceback.print_exc()
|
||||||
|
elif gethostname().split(".")[0] == 'nectaris':
|
||||||
|
self.anim = anim('\tconfiguration master.passwd')
|
||||||
|
try:
|
||||||
|
self.build_master_passwd_group()
|
||||||
|
self.anim.reinit()
|
||||||
|
print OK
|
||||||
|
except:
|
||||||
|
self.anim.reinit()
|
||||||
|
print ERREUR
|
||||||
|
if self.debug :
|
||||||
|
import traceback
|
||||||
|
traceback.print_exc()
|
||||||
|
|
||||||
self.anim = anim('\tconfiguration ML Crans')
|
|
||||||
try :
|
|
||||||
self.sync_ML()
|
|
||||||
self.anim.reinit()
|
|
||||||
print OK
|
|
||||||
except :
|
|
||||||
self.anim.reinit()
|
|
||||||
try :
|
|
||||||
# Au cas où...
|
|
||||||
self.mlist_to_unlock.Unlock()
|
|
||||||
except :
|
|
||||||
pass
|
|
||||||
print ERREUR
|
|
||||||
if self.debug :
|
|
||||||
import traceback
|
|
||||||
traceback.print_exc()
|
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ make_lock('auto_generate')
|
||||||
##### Options fournies ?
|
##### Options fournies ?
|
||||||
try :
|
try :
|
||||||
if len(sys.argv) > 1 :
|
if len(sys.argv) > 1 :
|
||||||
options, arg = getopt.getopt(sys.argv[1:], '', ['quiet', 'home=', 'mail_bienvenue=', 'ML-ENS=', 'droits', 'switch=' , 'dhcp', 'dns', 'firewall', 'conf_wifi', 'bornes_wifi=' , 'del_user='])
|
options, arg = getopt.getopt(sys.argv[1:], '', ['quiet', 'home=', 'mail_bienvenue=', 'ML-ENS=', 'droits', 'switch=' , 'dhcp', 'dns', 'firewall', 'conf_wifi', 'bornes_wifi=' , 'del_user=', 'droits-nectaris'])
|
||||||
else :
|
else :
|
||||||
options, arg = ( [],'')
|
options, arg = ( [],'')
|
||||||
except getopt.error, msg :
|
except getopt.error, msg :
|
||||||
|
@ -275,6 +275,16 @@ elif gethostname().split(".")[0] == 'nectaris':
|
||||||
# Pas terrible : on va redemarrer les bornes qui ont redemarré correctement
|
# Pas terrible : on va redemarrer les bornes qui ont redemarré correctement
|
||||||
if auto : db.services_to_restart('bornes_wifi', to_do['bornes_wifi'])
|
if auto : db.services_to_restart('bornes_wifi', to_do['bornes_wifi'])
|
||||||
raise
|
raise
|
||||||
|
if 'droits-nectaris' in to_do.keys():
|
||||||
|
if auto : db.services_to_restart('-droits-nectaris')
|
||||||
|
try:
|
||||||
|
from gen_confs.droits import droits
|
||||||
|
a = droits()
|
||||||
|
a.debug = debug
|
||||||
|
a.reconfigure()
|
||||||
|
except:
|
||||||
|
if auto : db.services_to_restart('droits-nectaris')
|
||||||
|
raise
|
||||||
|
|
||||||
if debug :
|
if debug :
|
||||||
print 'Non traité ici mais signalé dans la base LDAP : \n\t', db.services_to_restart()
|
print 'Non traité ici mais signalé dans la base LDAP : \n\t', db.services_to_restart()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue