From d12ad982cde9266aed8430b2d46c45eada48fa6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-Elliott=20B=C3=A9cue?= Date: Mon, 28 Jan 2013 22:47:19 +0100 Subject: [PATCH 1/5] =?UTF-8?q?=20*=20Quelques=20erreurs,=20maintenant=20?= =?UTF-8?q?=C3=A7a=20marche?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- attributs.py | 4 ++-- crans_utils.py | 3 +++ lc_ldap.py | 3 ++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/attributs.py b/attributs.py index 9bf13c5..b0f1339 100644 --- a/attributs.py +++ b/attributs.py @@ -474,7 +474,7 @@ class ip6HostNumber(Attr): can_modify = [nounou] def parse_value(self, ip, ldif): - ip = ip6_of_mac(ldif['macAddress'][0], ldif['rid'][0]) + ip = ip6_of_mac(ldif['macAddress'][0], int(ldif['rid'][0])) self.value = netaddr.ip.IPAddress(ip) def __unicode__(self): @@ -506,7 +506,7 @@ class rid(Attr): # On veut éviter les rid qui recoupent les ipv4 finissant par # .0 ou .255 - plages = [xrange(rid[a][0], rid[a][1]+1) for a in rid.keys() if 'v6' not in a] + plages = [xrange(config.rid[a][0], config.rid[a][1]+1) for a in config.rid.keys() if 'v6' not in a] for plage in plages: if rid in plage: diff --git a/crans_utils.py b/crans_utils.py index 61d7fe0..922dc1b 100644 --- a/crans_utils.py +++ b/crans_utils.py @@ -60,6 +60,7 @@ def prefixev6_of_rid(rid): Cette fonction retourne l'ip de début de ce sous-réseau. """ + # Au cas où rid = int(rid) for net, plage in config.rid.items(): @@ -75,6 +76,8 @@ def ip6_of_mac(mac, rid): """ Retourne la bonne ipv6 de la machine en fonction de sa mac et de son rid. """ + # Au cas où + rid = int(rid) for net, plage in config.rid.items(): if rid >= plage[0] and rid <= plage[1]: diff --git a/lc_ldap.py b/lc_ldap.py index 28322a4..ee61b6f 100644 --- a/lc_ldap.py +++ b/lc_ldap.py @@ -325,7 +325,8 @@ class lc_ldap(ldap.ldapobject.LDAPObject): if i in nonfree: continue else: - my_id = attrify(i, attr, self, True) + # On crée l'attribut associé, pour parser sa valeur. + my_id = attrify(unicode(i), attr, {}, self, False) if my_id.value != i: continue else: From b578b4a6a748c5bd5faa928b57a14bc60f679eac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-Elliott=20B=C3=A9cue?= Date: Mon, 28 Jan 2013 22:53:38 +0100 Subject: [PATCH 2/5] Pylint says "no". --- lc_ldap.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lc_ldap.py b/lc_ldap.py index ee61b6f..d5af0cb 100644 --- a/lc_ldap.py +++ b/lc_ldap.py @@ -204,15 +204,15 @@ class lc_ldap(ldap.ldapobject.LDAPObject): m = new_cransldapobject(self, dn, ldif = attrs) parent_dn = dn.split(',', 1)[1] if not machines.has_key(parent_dn): - machines[parent_dn]=[] + machines[parent_dn] = [] machines[parent_dn].append(m) - elif (dn.startswith('aid=') or dn.startswith('cid=') or dn==base_dn) and not parent.has_key(dn): - parent[dn]=new_cransldapobject(self, dn, ldif = attrs) - allmachines=[] + elif (dn.startswith('aid=') or dn.startswith('cid=') or dn == base_dn) and not parent.has_key(dn): + parent[dn] = new_cransldapobject(self, dn, ldif = attrs) + allmachines = [] for dn,mlist in machines.items(): # on associe propriétaires et machines - parent[dn]._machines=mlist + parent[dn]._machines = mlist for m in mlist: - m._proprio=parent[dn] + m._proprio = parent[dn] allmachines.append(m) return allmachines,parent.values() # on renvoie la liste des machines et des adherents (dont club et crans) @@ -221,7 +221,7 @@ class lc_ldap(ldap.ldapobject.LDAPObject): s'éxécuter le plus rapidement possible. On dumpe malgré tout toute la base, c'est pour pouvoir aussi rajouter à moindre coût les propriétaires.""" - machines,_=self.allMachinesAdherents() + machines,_ = self.allMachinesAdherents() return machines def allAdherents(self): @@ -229,7 +229,7 @@ class lc_ldap(ldap.ldapobject.LDAPObject): s'éxécuter le plus rapidement possible. On dumpe malgré tout toute la base, c'est pour pouvoir aussi rajouter à moindre coût les machines.""" - _,adherents=self.allMachinesAdherents() + _,adherents = self.allMachinesAdherents() return adherents def newMachine(self, parent, realm, uldif): From c0a877f25bf54e903e54c3b8cccb6eb7772d2e95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-Elliott=20B=C3=A9cue?= Date: Mon, 28 Jan 2013 23:16:51 +0100 Subject: [PATCH 3/5] may_be attend une liste en second argument --- lc_ldap.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lc_ldap.py b/lc_ldap.py index d5af0cb..0cde931 100644 --- a/lc_ldap.py +++ b/lc_ldap.py @@ -283,7 +283,7 @@ class lc_ldap(ldap.ldapobject.LDAPObject): aid = uldif.setdefault('aid', [ unicode(self._find_id('aid')) ]) uldif['objectClass'] = [u'adherent'] adherent = self._create_entity('aid=%s,%s' % (aid[0], base_dn), uldif) - if adherent.may_be(created, self): + if adherent.may_be(created, self.droits): adherent.create() else: raise EnvironmentError("Vous n'avez pas le droit de créer cet adhérent.") @@ -293,7 +293,7 @@ class lc_ldap(ldap.ldapobject.LDAPObject): cid = uldif.setdefault('cid', [ unicode(self._find_id('cid')) ]) uldif['objectClass'] = [u'club'] club = self._create_entity('cid=%s,%s' % (cid[0], base_dn), uldif) - if club.may_be(created, self): + if club.may_be(created, self.droits): club.create() else: raise EnvironmentError("Vous n'avez pas le droit de créer cet adhérent.") @@ -387,6 +387,7 @@ class CransLdapObject(object): """Classe de base des objets CransLdap. Cette classe ne devrait pas être utilisée directement.""" + """ Qui peut faire quoi ? """ can_be_by = { created: [nounou], modified: [nounou], deleted: [nounou], From 4d8cf770191598e6cc7217fa75360bbfafb98dfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-Elliott=20B=C3=A9cue?= Date: Fri, 8 Feb 2013 16:15:30 +0100 Subject: [PATCH 4/5] =?UTF-8?q?[lc=5Fldap]=20Ajout=20d'une=20m=C3=A9thode?= =?UTF-8?q?=20pour=20se=20connecter=20en=20readonly=20=C3=A0=20soi-m=C3=AA?= =?UTF-8?q?me?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- attributs.py | 2 +- lc_ldap.py | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/attributs.py b/attributs.py index b0f1339..7d773f6 100644 --- a/attributs.py +++ b/attributs.py @@ -506,7 +506,7 @@ class rid(Attr): # On veut éviter les rid qui recoupent les ipv4 finissant par # .0 ou .255 - plages = [xrange(config.rid[a][0], config.rid[a][1]+1) for a in config.rid.keys() if 'v6' not in a] + plages = [xrange(config.rid[a][0], config.rid[a][1]+1) for a in config.rid.keys() if ('v6' not in a) and ('special' not in a)] for plage in plages: if rid in plage: diff --git a/lc_ldap.py b/lc_ldap.py index 0cde931..dbf10d9 100644 --- a/lc_ldap.py +++ b/lc_ldap.py @@ -121,7 +121,6 @@ def cldif_to_ldif(cldif): ldif[attr] = [ str(val) for val in vals ] return ldif - def lc_ldap_test(): """Binding LDAP à la base de tests""" return lc_ldap(uri='ldap://vo.adm.crans.org',dn='cn=admin,dc=crans,dc=org', cred='75bdb64f32') @@ -132,6 +131,12 @@ def lc_ldap_admin(): secrets = import_secrets() return lc_ldap(uri='ldap://ldap.adm.crans.org/', dn=secrets.ldap_auth_dn, cred=secrets.ldap_password) +def lc_ldap_self(): + """Binding LDAP en lecture seule sur la base locale. + L'idée est que les machines avec un réplica bossent + avec elles-mêmes pour la lecture, pas avec vert.""" + secrets = import_secrets() + return lc_ldap(uri='ldap://127.0.0.1', dn=secrets.ldap_readonly_auth_dn, cred=secrets.ldap_readonly_password) class lc_ldap(ldap.ldapobject.LDAPObject): """Connexion à la base ldap crans, chaque instance représente une connexion From 4c0da75f9c86efeae95bc365da813a0dd447a32c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-Elliott=20B=C3=A9cue?= Date: Fri, 8 Feb 2013 16:39:37 +0100 Subject: [PATCH 5/5] [lc_ldap] On va rendre la connexion self plus flexible. --- lc_ldap.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lc_ldap.py b/lc_ldap.py index dbf10d9..0ed2844 100644 --- a/lc_ldap.py +++ b/lc_ldap.py @@ -135,8 +135,19 @@ def lc_ldap_self(): """Binding LDAP en lecture seule sur la base locale. L'idée est que les machines avec un réplica bossent avec elles-mêmes pour la lecture, pas avec vert.""" - secrets = import_secrets() - return lc_ldap(uri='ldap://127.0.0.1', dn=secrets.ldap_readonly_auth_dn, cred=secrets.ldap_readonly_password) + if os.path.exists('/var/run//slapd/ldapi'): + ro_uri = 'ldapi://%2fvar%2frun%2fslapd%2fldapi/' + auth_dn = auth_pw = "" + elif os.path.exists('/var/run/ldapi'): + ro_uri = 'ldapi://%2fvar%2frun%2fldapi/' + auth_dn = auth_pw = "" + else: + secrets = import_secrets() + ro_uri = 'ldap://127.0.0.1' + auth_dn = secrets.ldap_readonly_auth_dn + auth_pw = secrets.ldap_readonly_password + + return lc_ldap(uri=ro_uri, dn=auth_dn, cred=auth_pw) class lc_ldap(ldap.ldapobject.LDAPObject): """Connexion à la base ldap crans, chaque instance représente une connexion